aboutsummaryrefslogtreecommitdiffstats
path: root/xenolinux-2.4.26-sparse/arch/xen/drivers/netif/backend/common.h
blob: 88881cdf66882af46726d61ab3ed49f6a2c63a72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/******************************************************************************
 * arch/xen/drivers/netif/backend/common.h
 */

#ifndef __NETIF__BACKEND__COMMON_H__
#define __NETIF__BACKEND__COMMON_H__

#include <linux/config.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <asm/ctrl_if.h>
#include <asm/io.h>
#include "../netif.h"
#include "../../../../../net/bridge/br_private.h"

#ifndef NDEBUG
#define ASSERT(_p) \
    if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
    __LINE__, __FILE__); *(int*)0=0; }
#define DPRINTK(_f, _a...) printk("(file=%s, line=%d) " _f, \
                           __FILE__ , __LINE__ , ## _a )
#else
#define ASSERT(_p) ((void)0)
#define DPRINTK(_f, _a...) ((void)0)
#endif

typedef struct netif_st {
    /* Unique identifier for this interface. */
    domid_t          domid;
    unsigned int     handle;

    /* Physical parameters of the comms window. */
    unsigned long    tx_shmem_frame;
    unsigned long    rx_shmem_frame;
    unsigned int     evtchn;
    int              irq;

    /* The shared rings and indexes. */
    netif_tx_interface_t *tx;
    netif_rx_interface_t *rx;

    /* Private indexes into shared ring. */
    NETIF_RING_IDX rx_req_cons;
    NETIF_RING_IDX rx_resp_prod; /* private version of shared variable */
    NETIF_RING_IDX tx_req_cons;
    NETIF_RING_IDX tx_resp_prod; /* private version of shared variable */

    /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
    unsigned long   credit_bytes;
    unsigned long   credit_usec;
    unsigned long   remaining_credit;
    struct timer_list credit_timeout;

    /* Miscellaneous private stuff. */
    enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
    /*
     * DISCONNECT response is deferred until pending requests are ack'ed.
     * We therefore need to store the id from the original request.
     */
    u8               disconnect_rspid;
    struct netif_st *hash_next;
    struct list_head list;  /* scheduling list */
    atomic_t         refcnt;
    spinlock_t       rx_lock, tx_lock;
    struct net_device *dev;
    struct net_device_stats stats;
} netif_t;

void netif_create(netif_be_create_t *create);
void netif_destroy(netif_be_destroy_t *destroy);
void netif_connect(netif_be_connect_t *connect);
int  netif_disconnect(netif_be_disconnect_t *disconnect, u8 rsp_id);
void __netif_disconnect_complete(netif_t *netif);
netif_t *netif_find_by_handle(domid_t domid, unsigned int handle);
#define netif_get(_b) (atomic_inc(&(_b)->refcnt))
#define netif_put(_b)                             \
    do {                                          \
        if ( atomic_dec_and_test(&(_b)->refcnt) ) \
            __netif_disconnect_complete(_b);      \
    } while (0)

void netif_interface_init(void);
void netif_ctrlif_init(void);

void netif_deschedule(netif_t *netif);

int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev);
struct net_device_stats *netif_be_get_stats(struct net_device *dev);
void netif_be_int(int irq, void *dev_id, struct pt_regs *regs);

#endif /* __NETIF__BACKEND__COMMON_H__ */