- patches.rt/0001-sched-count-of-queued-RT-tasks.patch: Delete.
[linux-flexiantxendom0-3.2.10.git] / drivers / xen / netback / common.h
1 /******************************************************************************
2  * arch/xen/drivers/netif/backend/common.h
3  * 
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation; or, when distributed
7  * separately from the Linux kernel or incorporated into other
8  * software packages, subject to the following license:
9  * 
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this source file (the "Software"), to deal in the Software without
12  * restriction, including without limitation the rights to use, copy, modify,
13  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
14  * and to permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  */
28
29 #ifndef __NETIF__BACKEND__COMMON_H__
30 #define __NETIF__BACKEND__COMMON_H__
31
32 #include <linux/version.h>
33 #include <linux/module.h>
34 #include <linux/interrupt.h>
35 #include <linux/slab.h>
36 #include <linux/ip.h>
37 #include <linux/in.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/wait.h>
41 #include <xen/evtchn.h>
42 #include <xen/interface/io/netif.h>
43 #include <asm/io.h>
44 #include <asm/pgalloc.h>
45 #include <xen/interface/grant_table.h>
46 #include <xen/gnttab.h>
47 #include <xen/driver_util.h>
48 #include <xen/xenbus.h>
49
50 #define DPRINTK(_f, _a...)                      \
51         pr_debug("(file=%s, line=%d) " _f,      \
52                  __FILE__ , __LINE__ , ## _a )
53 #define IPRINTK(fmt, args...)                           \
54         printk(KERN_INFO "xen_net: " fmt, ##args)
55 #define WPRINTK(fmt, args...)                           \
56         printk(KERN_WARNING "xen_net: " fmt, ##args)
57
58 typedef struct netif_st {
59         /* Unique identifier for this interface. */
60         domid_t          domid;
61         unsigned int     handle;
62
63         u8               fe_dev_addr[6];
64
65         /* Physical parameters of the comms window. */
66         grant_handle_t   tx_shmem_handle;
67         grant_ref_t      tx_shmem_ref;
68         grant_handle_t   rx_shmem_handle;
69         grant_ref_t      rx_shmem_ref;
70         unsigned int     irq;
71
72         /* The shared rings and indexes. */
73         netif_tx_back_ring_t tx;
74         netif_rx_back_ring_t rx;
75         struct vm_struct *tx_comms_area;
76         struct vm_struct *rx_comms_area;
77
78         /* Set of features that can be turned on in dev->features. */
79         int features;
80
81         /* Internal feature information. */
82         u8 can_queue:1; /* can queue packets for receiver? */
83         u8 copying_receiver:1;  /* copy packets to receiver?       */
84
85         /* Allow netif_be_start_xmit() to peek ahead in the rx request ring. */
86         RING_IDX rx_req_cons_peek;
87
88         /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
89         unsigned long   credit_bytes;
90         unsigned long   credit_usec;
91         unsigned long   remaining_credit;
92         struct timer_list credit_timeout;
93
94         /* Enforce draining of the transmit queue. */
95         struct timer_list tx_queue_timeout;
96
97         /* Miscellaneous private stuff. */
98         struct list_head list;  /* scheduling list */
99         atomic_t         refcnt;
100         struct net_device *dev;
101         struct net_device_stats stats;
102
103         unsigned int carrier;
104
105         wait_queue_head_t waiting_to_free;
106 } netif_t;
107
108 /*
109  * Implement our own carrier flag: the network stack's version causes delays
110  * when the carrier is re-enabled (in particular, dev_activate() may not
111  * immediately be called, which can cause packet loss; also the etherbridge
112  * can be rather lazy in activating its port).
113  */
114 #define netback_carrier_on(netif)       ((netif)->carrier = 1)
115 #define netback_carrier_off(netif)      ((netif)->carrier = 0)
116 #define netback_carrier_ok(netif)       ((netif)->carrier)
117
118 enum {
119         NETBK_DONT_COPY_SKB,
120         NETBK_DELAYED_COPY_SKB,
121         NETBK_ALWAYS_COPY_SKB,
122 };
123
124 extern int netbk_copy_skb_mode;
125
126 /* Function pointers into netback accelerator plugin modules */
127 struct netback_accel_hooks {
128         struct module *owner;
129         int  (*probe)(struct xenbus_device *dev);
130         int (*remove)(struct xenbus_device *dev);
131 };
132
133 /* Structure to track the state of a netback accelerator plugin */
134 struct netback_accelerator {
135         struct list_head link;
136         int id;
137         char *eth_name;
138         atomic_t use_count;
139         struct netback_accel_hooks *hooks;
140 };
141
142 struct backend_info {
143         struct xenbus_device *dev;
144         netif_t *netif;
145         enum xenbus_state frontend_state;
146
147         /* State relating to the netback accelerator */
148         void *netback_accel_priv;
149         /* The accelerator that this backend is currently using */
150         struct netback_accelerator *accelerator;
151 };
152
153 #define NETBACK_ACCEL_VERSION 0x00010001
154
155 /* 
156  * Connect an accelerator plugin module to netback.  Returns zero on
157  * success, < 0 on error, > 0 (with highest version number supported)
158  * if version mismatch.
159  */
160 extern int netback_connect_accelerator(unsigned version,
161                                        int id, const char *eth_name, 
162                                        struct netback_accel_hooks *hooks);
163 /* Disconnect a previously connected accelerator plugin module */
164 extern void netback_disconnect_accelerator(int id, const char *eth_name);
165
166
167 extern
168 void netback_probe_accelerators(struct backend_info *be,
169                                 struct xenbus_device *dev);
170 extern
171 void netback_remove_accelerators(struct backend_info *be,
172                                  struct xenbus_device *dev);
173 extern
174 void netif_accel_init(void);
175
176
177 #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
178 #define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
179
180 void netif_disconnect(netif_t *netif);
181
182 netif_t *netif_alloc(domid_t domid, unsigned int handle);
183 int netif_map(netif_t *netif, unsigned long tx_ring_ref,
184               unsigned long rx_ring_ref, unsigned int evtchn);
185
186 #define netif_get(_b) (atomic_inc(&(_b)->refcnt))
187 #define netif_put(_b)                                           \
188         do {                                                    \
189                 if ( atomic_dec_and_test(&(_b)->refcnt) )       \
190                         wake_up(&(_b)->waiting_to_free);        \
191         } while (0)
192
193 void netif_xenbus_init(void);
194
195 #define netif_schedulable(netif)                                \
196         (netif_running((netif)->dev) && netback_carrier_ok(netif))
197
198 void netif_schedule_work(netif_t *netif);
199 void netif_deschedule_work(netif_t *netif);
200
201 int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev);
202 struct net_device_stats *netif_be_get_stats(struct net_device *dev);
203 irqreturn_t netif_be_int(int irq, void *dev_id);
204
205 static inline int netbk_can_queue(struct net_device *dev)
206 {
207         netif_t *netif = netdev_priv(dev);
208         return netif->can_queue;
209 }
210
211 static inline int netbk_can_sg(struct net_device *dev)
212 {
213         netif_t *netif = netdev_priv(dev);
214         return netif->features & NETIF_F_SG;
215 }
216
217 #endif /* __NETIF__BACKEND__COMMON_H__ */