ia64/linux-2.6.18-xen.hg

annotate drivers/xen/netback/common.h @ 792:db9857bb0320

netback: add ethtool stat to track copied skbs.

Copied skbs should be rare but we have no way of verifying that.

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