ia64/linux-2.6.18-xen.hg

annotate drivers/xen/netback/common.h @ 26:a533be77c572

Imported linux-2.6-xen-sparse from xen-unstable.hg 15200:bd3d6b4c52ec
author Ian Campbell <ian.campbell@xensource.com>
date Mon Jun 04 10:05:28 2007 +0100 (2007-06-04)
parents
children 45dfe4cfc5ef
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>
ian@26 48
ian@26 49 #define DPRINTK(_f, _a...) \
ian@26 50 pr_debug("(file=%s, line=%d) " _f, \
ian@26 51 __FILE__ , __LINE__ , ## _a )
ian@26 52 #define IPRINTK(fmt, args...) \
ian@26 53 printk(KERN_INFO "xen_net: " fmt, ##args)
ian@26 54 #define WPRINTK(fmt, args...) \
ian@26 55 printk(KERN_WARNING "xen_net: " fmt, ##args)
ian@26 56
ian@26 57 typedef struct netif_st {
ian@26 58 /* Unique identifier for this interface. */
ian@26 59 domid_t domid;
ian@26 60 unsigned int handle;
ian@26 61
ian@26 62 u8 fe_dev_addr[6];
ian@26 63
ian@26 64 /* Physical parameters of the comms window. */
ian@26 65 grant_handle_t tx_shmem_handle;
ian@26 66 grant_ref_t tx_shmem_ref;
ian@26 67 grant_handle_t rx_shmem_handle;
ian@26 68 grant_ref_t rx_shmem_ref;
ian@26 69 unsigned int irq;
ian@26 70
ian@26 71 /* The shared rings and indexes. */
ian@26 72 netif_tx_back_ring_t tx;
ian@26 73 netif_rx_back_ring_t rx;
ian@26 74 struct vm_struct *tx_comms_area;
ian@26 75 struct vm_struct *rx_comms_area;
ian@26 76
ian@26 77 /* Set of features that can be turned on in dev->features. */
ian@26 78 int features;
ian@26 79
ian@26 80 /* Internal feature information. */
ian@26 81 int can_queue:1; /* can queue packets for receiver? */
ian@26 82 int copying_receiver:1; /* copy packets to receiver? */
ian@26 83
ian@26 84 /* Allow netif_be_start_xmit() to peek ahead in the rx request ring. */
ian@26 85 RING_IDX rx_req_cons_peek;
ian@26 86
ian@26 87 /* Transmit shaping: allow 'credit_bytes' every 'credit_usec'. */
ian@26 88 unsigned long credit_bytes;
ian@26 89 unsigned long credit_usec;
ian@26 90 unsigned long remaining_credit;
ian@26 91 struct timer_list credit_timeout;
ian@26 92
ian@26 93 /* Enforce draining of the transmit queue. */
ian@26 94 struct timer_list tx_queue_timeout;
ian@26 95
ian@26 96 /* Miscellaneous private stuff. */
ian@26 97 struct list_head list; /* scheduling list */
ian@26 98 atomic_t refcnt;
ian@26 99 struct net_device *dev;
ian@26 100 struct net_device_stats stats;
ian@26 101
ian@26 102 unsigned int carrier;
ian@26 103
ian@26 104 wait_queue_head_t waiting_to_free;
ian@26 105 } netif_t;
ian@26 106
ian@26 107 /*
ian@26 108 * Implement our own carrier flag: the network stack's version causes delays
ian@26 109 * when the carrier is re-enabled (in particular, dev_activate() may not
ian@26 110 * immediately be called, which can cause packet loss; also the etherbridge
ian@26 111 * can be rather lazy in activating its port).
ian@26 112 */
ian@26 113 #define netback_carrier_on(netif) ((netif)->carrier = 1)
ian@26 114 #define netback_carrier_off(netif) ((netif)->carrier = 0)
ian@26 115 #define netback_carrier_ok(netif) ((netif)->carrier)
ian@26 116
ian@26 117 enum {
ian@26 118 NETBK_DONT_COPY_SKB,
ian@26 119 NETBK_DELAYED_COPY_SKB,
ian@26 120 NETBK_ALWAYS_COPY_SKB,
ian@26 121 };
ian@26 122
ian@26 123 extern int netbk_copy_skb_mode;
ian@26 124
ian@26 125 #define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGE_SIZE)
ian@26 126 #define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGE_SIZE)
ian@26 127
ian@26 128 void netif_disconnect(netif_t *netif);
ian@26 129
ian@26 130 netif_t *netif_alloc(domid_t domid, unsigned int handle);
ian@26 131 int netif_map(netif_t *netif, unsigned long tx_ring_ref,
ian@26 132 unsigned long rx_ring_ref, unsigned int evtchn);
ian@26 133
ian@26 134 #define netif_get(_b) (atomic_inc(&(_b)->refcnt))
ian@26 135 #define netif_put(_b) \
ian@26 136 do { \
ian@26 137 if ( atomic_dec_and_test(&(_b)->refcnt) ) \
ian@26 138 wake_up(&(_b)->waiting_to_free); \
ian@26 139 } while (0)
ian@26 140
ian@26 141 void netif_xenbus_init(void);
ian@26 142
ian@26 143 #define netif_schedulable(netif) \
ian@26 144 (netif_running((netif)->dev) && netback_carrier_ok(netif))
ian@26 145
ian@26 146 void netif_schedule_work(netif_t *netif);
ian@26 147 void netif_deschedule_work(netif_t *netif);
ian@26 148
ian@26 149 int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev);
ian@26 150 struct net_device_stats *netif_be_get_stats(struct net_device *dev);
ian@26 151 irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs);
ian@26 152
ian@26 153 static inline int netbk_can_queue(struct net_device *dev)
ian@26 154 {
ian@26 155 netif_t *netif = netdev_priv(dev);
ian@26 156 return netif->can_queue;
ian@26 157 }
ian@26 158
ian@26 159 static inline int netbk_can_sg(struct net_device *dev)
ian@26 160 {
ian@26 161 netif_t *netif = netdev_priv(dev);
ian@26 162 return netif->features & NETIF_F_SG;
ian@26 163 }
ian@26 164
ian@26 165 #endif /* __NETIF__BACKEND__COMMON_H__ */