1 #ifndef LINUX_26_29_COMPAT_H
2 #define LINUX_26_29_COMPAT_H
4 #include <linux/version.h>
5 #include <linux/netdevice.h>
6 #include <linux/if_link.h>
9 * I kow this looks odd.. but 2.6.32 added the netdev_tx_t
10 * and we backport that there so inlcude that header first
11 * as we need it for the netdev ops.
13 #include <linux/compat-2.6.32.h>
15 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
17 #include <linux/skbuff.h>
18 #include <linux/usb.h>
19 #include <linux/types.h>
22 defined(CONFIG_ALPHA) || defined(CONFIG_AVR32) || \
23 defined(CONFIG_BLACKFIN) || defined(CONFIG_CRIS) || \
24 defined(CONFIG_H8300) || defined(CONFIG_IA64) || \
25 defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
26 defined(CONFIG_PARISC) || defined(CONFIG_S390) || \
27 defined(CONFIG_PPC64) || defined(CONFIG_PPC32) || \
28 defined(CONFIG_SUPERH) || defined(CONFIG_SPARC) || \
29 defined(CONFIG_FRV) || defined(CONFIG_X86) || \
30 defined(CONFIG_M32R) || defined(CONFIG_M68K) || \
31 defined(CONFIG_MN10300) || defined(CONFIG_XTENSA)
32 #include <asm/atomic.h>
40 volatile long counter;
42 #endif /* CONFIG_64BIT */
46 #define PCI_EXP_LNKCTL_ES 0x0080 /* Extended Synch */
49 * Older kernels do not have struct net_device_ops but what we can
50 * do is just define the data structure and use a caller to let us
51 * set the data structure's routines onto the old netdev, essentially
52 * doing it the old way. This avoids huge deltas on our backports.
56 * This structure defines the management hooks for network devices.
57 * The following hooks can be defined; unless noted otherwise, they are
58 * optional and can be filled with a null pointer.
60 * int (*ndo_init)(struct net_device *dev);
61 * This function is called once when network device is registered.
62 * The network device can use this to any late stage initializaton
63 * or semantic validattion. It can fail with an error code which will
64 * be propogated back to register_netdev
66 * void (*ndo_uninit)(struct net_device *dev);
67 * This function is called when device is unregistered or when registration
68 * fails. It is not called if init fails.
70 * int (*ndo_open)(struct net_device *dev);
71 * This function is called when network device transistions to the up
74 * int (*ndo_stop)(struct net_device *dev);
75 * This function is called when network device transistions to the down
78 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
79 * struct net_device *dev);
80 * Called when a packet needs to be transmitted.
81 * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
82 * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
83 * Required can not be NULL.
85 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb);
86 * Called to decide which queue to when device supports multiple
89 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
90 * This function is called to allow device receiver to make
91 * changes to configuration when multicast or promiscious is enabled.
93 * void (*ndo_set_rx_mode)(struct net_device *dev);
94 * This function is called device changes address list filtering.
96 * void (*ndo_set_multicast_list)(struct net_device *dev);
97 * This function is called when the multicast address list changes.
99 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
100 * This function is called when the Media Access Control address
101 * needs to be changed. If this interface is not defined, the
102 * mac address can not be changed.
104 * int (*ndo_validate_addr)(struct net_device *dev);
105 * Test if Media Access Control address is valid for the device.
107 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
108 * Called when a user request an ioctl which can't be handled by
109 * the generic interface code. If not defined ioctl's return
110 * not supported error code.
112 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
113 * Used to set network devices bus interface parameters. This interface
114 * is retained for legacy reason, new devices should use the bus
115 * interface (PCI) for low level management.
117 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
118 * Called when a user wants to change the Maximum Transfer Unit
119 * of a device. If not defined, any request to change MTU will
120 * will return an error.
122 * void (*ndo_tx_timeout)(struct net_device *dev);
123 * Callback uses when the transmitter has not made any progress
124 * for dev->watchdog ticks.
126 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
127 * Called when a user wants to get the network device usage
128 * statistics. If not defined, the counters in dev->stats will
131 * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
132 * If device support VLAN receive accleration
133 * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called
134 * when vlan groups for the device changes. Note: grp is NULL
135 * if no vlan's groups are being used.
137 * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
138 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
139 * this function is called when a VLAN id is registered.
141 * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
142 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
143 * this function is called when a VLAN id is unregistered.
145 * void (*ndo_poll_controller)(struct net_device *dev);
147 * SR-IOV management functions.
148 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
149 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos);
150 * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate);
151 * int (*ndo_get_vf_config)(struct net_device *dev,
152 * int vf, struct ifla_vf_info *ivf);
154 #define HAVE_NET_DEVICE_OPS
155 struct net_device_ops {
156 int (*ndo_init)(struct net_device *dev);
157 void (*ndo_uninit)(struct net_device *dev);
158 int (*ndo_open)(struct net_device *dev);
159 int (*ndo_stop)(struct net_device *dev);
160 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
161 struct net_device *dev);
162 u16 (*ndo_select_queue)(struct net_device *dev,
163 struct sk_buff *skb);
164 void (*ndo_change_rx_flags)(struct net_device *dev,
166 void (*ndo_set_rx_mode)(struct net_device *dev);
167 void (*ndo_set_multicast_list)(struct net_device *dev);
168 int (*ndo_set_mac_address)(struct net_device *dev,
170 int (*ndo_validate_addr)(struct net_device *dev);
171 int (*ndo_do_ioctl)(struct net_device *dev,
172 struct ifreq *ifr, int cmd);
173 int (*ndo_set_config)(struct net_device *dev,
175 int (*ndo_change_mtu)(struct net_device *dev,
177 int (*ndo_neigh_setup)(struct net_device *dev,
178 struct neigh_parms *);
179 void (*ndo_tx_timeout) (struct net_device *dev);
181 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
183 void (*ndo_vlan_rx_register)(struct net_device *dev,
184 struct vlan_group *grp);
185 void (*ndo_vlan_rx_add_vid)(struct net_device *dev,
187 void (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
189 #ifdef CONFIG_NET_POLL_CONTROLLER
190 void (*ndo_poll_controller)(struct net_device *dev);
192 int (*ndo_set_vf_mac)(struct net_device *dev,
194 int (*ndo_set_vf_vlan)(struct net_device *dev,
195 int queue, u16 vlan, u8 qos);
196 int (*ndo_set_vf_tx_rate)(struct net_device *dev,
199 * The struct ifla_vf_info was added via b280da8d54b8d82b52f368a8703b7ada6c1744d5
200 * on the v2.6.34-rc1~233^2~338 release
202 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
203 int (*ndo_get_vf_config)(struct net_device *dev,
205 struct ifla_vf_info *ivf);
207 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
208 int (*ndo_fcoe_enable)(struct net_device *dev);
209 int (*ndo_fcoe_disable)(struct net_device *dev);
210 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
212 struct scatterlist *sgl,
214 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
216 #define NETDEV_FCOE_WWNN 0
217 #define NETDEV_FCOE_WWPN 1
218 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
223 void netdev_attach_ops(struct net_device *dev,
224 const struct net_device_ops *ops);
227 * skb_queue_is_first - check if skb is the first entry in the queue
231 * Returns true if @skb is the first buffer on the list.
233 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
234 const struct sk_buff *skb)
236 return (skb->prev == (struct sk_buff *) list);
240 * skb_queue_prev - return the prev packet in the queue
242 * @skb: current buffer
244 * Return the prev packet in @list before @skb. It is only valid to
245 * call this if skb_queue_is_first() evaluates to false.
247 static inline struct sk_buff *skb_queue_prev(const struct sk_buff_head *list,
248 const struct sk_buff *skb)
250 /* This BUG_ON may seem severe, but if we just return then we
251 * are going to dereference garbage.
253 BUG_ON(skb_queue_is_first(list, skb));
258 static inline struct net_device_stats *dev_get_stats(struct net_device *dev)
260 return dev->get_stats(dev);
263 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23))
264 #if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
265 extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
266 #endif /* CONFIG_USB */
269 #define DIV_ROUND_CLOSEST(x, divisor)( \
271 typeof(divisor) __divisor = divisor; \
272 (((x) + ((__divisor) / 2)) / (__divisor)); \
276 extern int eth_mac_addr(struct net_device *dev, void *p);
277 extern int eth_change_mtu(struct net_device *dev, int new_mtu);
278 extern int eth_validate_addr(struct net_device *dev);
282 static inline void write_pnet(struct net **pnet, struct net *net)
287 static inline struct net *read_pnet(struct net * const *pnet)
294 #define write_pnet(pnet, net) do { (void)(net);} while (0)
295 #define read_pnet(pnet) (&init_net)
298 * swap - swap value of @a and @b
301 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
305 extern int init_dummy_netdev(struct net_device *dev);
307 #define compat_pci_suspend(fn) \
308 int fn##_compat(struct pci_dev *pdev, pm_message_t state) \
312 r = fn(&pdev->dev); \
316 pci_save_state(pdev); \
317 pci_disable_device(pdev); \
318 pci_set_power_state(pdev, PCI_D3hot); \
323 #define compat_pci_resume(fn) \
324 int fn##_compat(struct pci_dev *pdev) \
328 pci_set_power_state(pdev, PCI_D0); \
329 r = pci_enable_device(pdev); \
332 pci_restore_state(pdev); \
334 return fn(&pdev->dev); \
339 static inline void netdev_attach_ops(struct net_device *dev,
340 const struct net_device_ops *ops)
342 dev->netdev_ops = ops;
345 #define compat_pci_suspend(fn)
346 #define compat_pci_resume(fn)
348 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
350 #endif /* LINUX_26_29_COMPAT_H */