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 static inline void usb_autopm_put_interface_async(struct usb_interface *intf)
24 static inline int usb_autopm_get_interface_async(struct usb_interface *intf)
28 defined(CONFIG_ALPHA) || defined(CONFIG_AVR32) || \
29 defined(CONFIG_BLACKFIN) || defined(CONFIG_CRIS) || \
30 defined(CONFIG_H8300) || defined(CONFIG_IA64) || \
31 defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
32 defined(CONFIG_PARISC) || defined(CONFIG_S390) || \
33 defined(CONFIG_PPC64) || defined(CONFIG_PPC32) || \
34 defined(CONFIG_SUPERH) || defined(CONFIG_SPARC) || \
35 defined(CONFIG_FRV) || defined(CONFIG_X86) || \
36 defined(CONFIG_M32R) || defined(CONFIG_M68K) || \
37 defined(CONFIG_MN10300) || defined(CONFIG_XTENSA)
38 #include <asm/atomic.h>
46 volatile long counter;
48 #endif /* CONFIG_64BIT */
52 #define PCI_EXP_LNKCTL_ES 0x0080 /* Extended Synch */
55 * Older kernels do not have struct net_device_ops but what we can
56 * do is just define the data structure and use a caller to let us
57 * set the data structure's routines onto the old netdev, essentially
58 * doing it the old way. This avoids huge deltas on our backports.
62 * This structure defines the management hooks for network devices.
63 * The following hooks can be defined; unless noted otherwise, they are
64 * optional and can be filled with a null pointer.
66 * int (*ndo_init)(struct net_device *dev);
67 * This function is called once when network device is registered.
68 * The network device can use this to any late stage initializaton
69 * or semantic validattion. It can fail with an error code which will
70 * be propogated back to register_netdev
72 * void (*ndo_uninit)(struct net_device *dev);
73 * This function is called when device is unregistered or when registration
74 * fails. It is not called if init fails.
76 * int (*ndo_open)(struct net_device *dev);
77 * This function is called when network device transistions to the up
80 * int (*ndo_stop)(struct net_device *dev);
81 * This function is called when network device transistions to the down
84 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
85 * struct net_device *dev);
86 * Called when a packet needs to be transmitted.
87 * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
88 * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
89 * Required can not be NULL.
91 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb);
92 * Called to decide which queue to when device supports multiple
95 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
96 * This function is called to allow device receiver to make
97 * changes to configuration when multicast or promiscious is enabled.
99 * void (*ndo_set_rx_mode)(struct net_device *dev);
100 * This function is called device changes address list filtering.
102 * void (*ndo_set_multicast_list)(struct net_device *dev);
103 * This function is called when the multicast address list changes.
105 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
106 * This function is called when the Media Access Control address
107 * needs to be changed. If this interface is not defined, the
108 * mac address can not be changed.
110 * int (*ndo_validate_addr)(struct net_device *dev);
111 * Test if Media Access Control address is valid for the device.
113 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
114 * Called when a user request an ioctl which can't be handled by
115 * the generic interface code. If not defined ioctl's return
116 * not supported error code.
118 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
119 * Used to set network devices bus interface parameters. This interface
120 * is retained for legacy reason, new devices should use the bus
121 * interface (PCI) for low level management.
123 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
124 * Called when a user wants to change the Maximum Transfer Unit
125 * of a device. If not defined, any request to change MTU will
126 * will return an error.
128 * void (*ndo_tx_timeout)(struct net_device *dev);
129 * Callback uses when the transmitter has not made any progress
130 * for dev->watchdog ticks.
132 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
133 * Called when a user wants to get the network device usage
134 * statistics. If not defined, the counters in dev->stats will
137 * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
138 * If device support VLAN receive accleration
139 * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called
140 * when vlan groups for the device changes. Note: grp is NULL
141 * if no vlan's groups are being used.
143 * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
144 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
145 * this function is called when a VLAN id is registered.
147 * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
148 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
149 * this function is called when a VLAN id is unregistered.
151 * void (*ndo_poll_controller)(struct net_device *dev);
153 * SR-IOV management functions.
154 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
155 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos);
156 * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate);
157 * int (*ndo_get_vf_config)(struct net_device *dev,
158 * int vf, struct ifla_vf_info *ivf);
160 #define HAVE_NET_DEVICE_OPS
161 struct net_device_ops {
162 int (*ndo_init)(struct net_device *dev);
163 void (*ndo_uninit)(struct net_device *dev);
164 int (*ndo_open)(struct net_device *dev);
165 int (*ndo_stop)(struct net_device *dev);
166 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
167 struct net_device *dev);
168 u16 (*ndo_select_queue)(struct net_device *dev,
169 struct sk_buff *skb);
170 void (*ndo_change_rx_flags)(struct net_device *dev,
172 void (*ndo_set_rx_mode)(struct net_device *dev);
173 void (*ndo_set_multicast_list)(struct net_device *dev);
174 int (*ndo_set_mac_address)(struct net_device *dev,
176 int (*ndo_validate_addr)(struct net_device *dev);
177 int (*ndo_do_ioctl)(struct net_device *dev,
178 struct ifreq *ifr, int cmd);
179 int (*ndo_set_config)(struct net_device *dev,
181 int (*ndo_change_mtu)(struct net_device *dev,
183 int (*ndo_neigh_setup)(struct net_device *dev,
184 struct neigh_parms *);
185 void (*ndo_tx_timeout) (struct net_device *dev);
187 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
189 void (*ndo_vlan_rx_register)(struct net_device *dev,
190 struct vlan_group *grp);
191 void (*ndo_vlan_rx_add_vid)(struct net_device *dev,
193 void (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
195 #ifdef CONFIG_NET_POLL_CONTROLLER
196 void (*ndo_poll_controller)(struct net_device *dev);
198 int (*ndo_set_vf_mac)(struct net_device *dev,
200 int (*ndo_set_vf_vlan)(struct net_device *dev,
201 int queue, u16 vlan, u8 qos);
202 int (*ndo_set_vf_tx_rate)(struct net_device *dev,
205 * The struct ifla_vf_info was added via b280da8d54b8d82b52f368a8703b7ada6c1744d5
206 * on the v2.6.34-rc1~233^2~338 release
208 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
209 int (*ndo_get_vf_config)(struct net_device *dev,
211 struct ifla_vf_info *ivf);
213 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
214 int (*ndo_fcoe_enable)(struct net_device *dev);
215 int (*ndo_fcoe_disable)(struct net_device *dev);
216 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
218 struct scatterlist *sgl,
220 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
222 #define NETDEV_FCOE_WWNN 0
223 #define NETDEV_FCOE_WWPN 1
224 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
229 static inline int ndo_do_ioctl(struct net_device *dev,
234 return dev->do_ioctl(dev, ifr, cmd);
239 #define netdev_attach_ops LINUX_BACKPORT(netdev_attach_ops)
240 void netdev_attach_ops(struct net_device *dev,
241 const struct net_device_ops *ops);
244 * skb_queue_is_first - check if skb is the first entry in the queue
248 * Returns true if @skb is the first buffer on the list.
250 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
251 const struct sk_buff *skb)
253 return (skb->prev == (struct sk_buff *) list);
257 * skb_queue_prev - return the prev packet in the queue
259 * @skb: current buffer
261 * Return the prev packet in @list before @skb. It is only valid to
262 * call this if skb_queue_is_first() evaluates to false.
264 static inline struct sk_buff *skb_queue_prev(const struct sk_buff_head *list,
265 const struct sk_buff *skb)
267 /* This BUG_ON may seem severe, but if we just return then we
268 * are going to dereference garbage.
270 BUG_ON(skb_queue_is_first(list, skb));
275 static inline struct net_device_stats *dev_get_stats(struct net_device *dev)
277 return dev->get_stats(dev);
280 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23))
281 #if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
282 #define usb_unpoison_anchored_urbs LINUX_BACKPORT(usb_unpoison_anchored_urbs)
283 extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
284 #endif /* CONFIG_USB */
287 #define DIV_ROUND_CLOSEST(x, divisor)( \
289 typeof(divisor) __divisor = divisor; \
290 (((x) + ((__divisor) / 2)) / (__divisor)); \
294 #define eth_mac_addr LINUX_BACKPORT(eth_mac_addr)
295 extern int eth_mac_addr(struct net_device *dev, void *p);
296 #define eth_change_mtu LINUX_BACKPORT(eth_change_mtu)
297 extern int eth_change_mtu(struct net_device *dev, int new_mtu);
298 #define eth_validate_addr LINUX_BACKPORT(eth_validate_addr)
299 extern int eth_validate_addr(struct net_device *dev);
303 static inline void write_pnet(struct net **pnet, struct net *net)
308 static inline struct net *read_pnet(struct net * const *pnet)
315 #define write_pnet(pnet, net) do { (void)(net);} while (0)
316 #define read_pnet(pnet) (&init_net)
319 * swap - swap value of @a and @b
322 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
326 #define init_dummy_netdev LINUX_BACKPORT(init_dummy_netdev)
327 extern int init_dummy_netdev(struct net_device *dev);
329 #define compat_pci_suspend(fn) \
330 int fn##_compat(struct pci_dev *pdev, pm_message_t state) \
334 r = fn(&pdev->dev); \
338 pci_save_state(pdev); \
339 pci_disable_device(pdev); \
340 pci_set_power_state(pdev, PCI_D3hot); \
345 #define compat_pci_resume(fn) \
346 int fn##_compat(struct pci_dev *pdev) \
350 pci_set_power_state(pdev, PCI_D0); \
351 r = pci_enable_device(pdev); \
354 pci_restore_state(pdev); \
356 return fn(&pdev->dev); \
359 #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
361 /* Kernels >= 2.6.29 follows */
363 /* XXX: this can probably just go upstream ! */
364 static inline void netdev_attach_ops(struct net_device *dev,
365 const struct net_device_ops *ops)
367 dev->netdev_ops = ops;
370 /* XXX: this can probably just go upstream! */
371 static inline int ndo_do_ioctl(struct net_device *dev,
375 if (dev->netdev_ops && dev->netdev_ops->ndo_do_ioctl)
376 return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd);
380 #define compat_pci_suspend(fn)
381 #define compat_pci_resume(fn)
383 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
385 #endif /* LINUX_26_29_COMPAT_H */