dfb750ee36dd3adcd7f8c5d6db9c0306798b2896
[linux-2.6.git] / drivers / xen / netback / common.h
1 /******************************************************************************
2  * arch/xen/drivers/netif/backend/common.h
3  */
4
5 #ifndef __NETIF__BACKEND__COMMON_H__
6 #define __NETIF__BACKEND__COMMON_H__
7
8 #include <linux/config.h>
9 #include <linux/version.h>
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/slab.h>
13 #include <linux/ip.h>
14 #include <linux/in.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <asm-xen/ctrl_if.h>
18 #include <asm-xen/xen-public/io/netif.h>
19 #include <asm/io.h>
20 #include <asm/pgalloc.h>
21
22 #if 0
23 #define ASSERT(_p) \
24     if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
25     __LINE__, __FILE__); *(int*)0=0; }
26 #define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
27                            __FILE__ , __LINE__ , ## _a )
28 #else
29 #define ASSERT(_p) ((void)0)
30 #define DPRINTK(_f, _a...) ((void)0)
31 #endif
32
33 typedef struct netif_st {
34     /* Unique identifier for this interface. */
35     domid_t          domid;
36     unsigned int     handle;
37
38     u8               fe_dev_addr[6];
39
40     /* Physical parameters of the comms window. */
41     unsigned long    tx_shmem_frame;
42     unsigned long    rx_shmem_frame;
43     unsigned int     evtchn;
44     int              irq;
45
46     /* The shared rings and indexes. */
47     netif_tx_interface_t *tx;
48     netif_rx_interface_t *rx;
49
50     /* Private indexes into shared ring. */
51     NETIF_RING_IDX rx_req_cons;
52     NETIF_RING_IDX rx_resp_prod; /* private version of shared variable */
53     NETIF_RING_IDX tx_req_cons;
54     NETIF_RING_IDX tx_resp_prod; /* private version of shared variable */
55
56     /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
57     unsigned long   credit_bytes;
58     unsigned long   credit_usec;
59     unsigned long   remaining_credit;
60     struct timer_list credit_timeout;
61
62     /* Miscellaneous private stuff. */
63     enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
64     int active;
65     /*
66      * DISCONNECT response is deferred until pending requests are ack'ed.
67      * We therefore need to store the id from the original request.
68      */
69     u8               disconnect_rspid;
70     struct netif_st *hash_next;
71     struct list_head list;  /* scheduling list */
72     atomic_t         refcnt;
73     struct net_device *dev;
74     struct net_device_stats stats;
75
76     struct work_struct work;
77 } netif_t;
78
79 void netif_create(netif_be_create_t *create);
80 void netif_destroy(netif_be_destroy_t *destroy);
81 void netif_creditlimit(netif_be_creditlimit_t *creditlimit);
82 void netif_connect(netif_be_connect_t *connect);
83 int  netif_disconnect(netif_be_disconnect_t *disconnect, u8 rsp_id);
84 void netif_disconnect_complete(netif_t *netif);
85 netif_t *netif_find_by_handle(domid_t domid, unsigned int handle);
86 #define netif_get(_b) (atomic_inc(&(_b)->refcnt))
87 #define netif_put(_b)                             \
88     do {                                          \
89         if ( atomic_dec_and_test(&(_b)->refcnt) ) \
90             netif_disconnect_complete(_b);        \
91     } while (0)
92
93 void netif_interface_init(void);
94 void netif_ctrlif_init(void);
95
96 void netif_schedule_work(netif_t *netif);
97 void netif_deschedule_work(netif_t *netif);
98
99 int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev);
100 struct net_device_stats *netif_be_get_stats(struct net_device *dev);
101 irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs);
102
103 #endif /* __NETIF__BACKEND__COMMON_H__ */