1 #ifndef LINUX_26_29_COMPAT_H
2 #define LINUX_26_29_COMPAT_H
4 #include <linux/version.h>
6 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
7 #include <linux/netdevice.h>
8 #include <linux/if_link.h>
10 #include <linux/skbuff.h>
11 #include <linux/usb.h>
12 #include <linux/types.h>
15 static inline void usb_autopm_put_interface_async(struct usb_interface *intf)
17 static inline int usb_autopm_get_interface_async(struct usb_interface *intf)
21 defined(CONFIG_ALPHA) || defined(CONFIG_AVR32) || \
22 defined(CONFIG_BLACKFIN) || defined(CONFIG_CRIS) || \
23 defined(CONFIG_H8300) || defined(CONFIG_IA64) || \
24 defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
25 defined(CONFIG_PARISC) || defined(CONFIG_S390) || \
26 defined(CONFIG_PPC64) || defined(CONFIG_PPC32) || \
27 defined(CONFIG_SUPERH) || defined(CONFIG_SPARC) || \
28 defined(CONFIG_FRV) || defined(CONFIG_X86) || \
29 defined(CONFIG_M32R) || defined(CONFIG_M68K) || \
30 defined(CONFIG_MN10300) || defined(CONFIG_XTENSA)
31 #include <asm/atomic.h>
39 volatile long counter;
41 #endif /* CONFIG_64BIT */
45 #define PCI_EXP_LNKCTL_ES 0x0080 /* Extended Synch */
48 * Older kernels do not have struct net_device_ops but what we can
49 * do is just define the data structure and use a caller to let us
50 * set the data structure's routines onto the old netdev, essentially
51 * doing it the old way. This avoids huge deltas on our backports.
55 * This structure defines the management hooks for network devices.
56 * The following hooks can be defined; unless noted otherwise, they are
57 * optional and can be filled with a null pointer.
59 * int (*ndo_init)(struct net_device *dev);
60 * This function is called once when network device is registered.
61 * The network device can use this to any late stage initializaton
62 * or semantic validattion. It can fail with an error code which will
63 * be propogated back to register_netdev
65 * void (*ndo_uninit)(struct net_device *dev);
66 * This function is called when device is unregistered or when registration
67 * fails. It is not called if init fails.
69 * int (*ndo_open)(struct net_device *dev);
70 * This function is called when network device transistions to the up
73 * int (*ndo_stop)(struct net_device *dev);
74 * This function is called when network device transistions to the down
77 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
78 * struct net_device *dev);
79 * Called when a packet needs to be transmitted.
80 * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
81 * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
82 * Required can not be NULL.
84 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb);
85 * Called to decide which queue to when device supports multiple
88 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
89 * This function is called to allow device receiver to make
90 * changes to configuration when multicast or promiscious is enabled.
92 * void (*ndo_set_rx_mode)(struct net_device *dev);
93 * This function is called device changes address list filtering.
95 * void (*ndo_set_multicast_list)(struct net_device *dev);
96 * This function is called when the multicast address list changes.
98 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
99 * This function is called when the Media Access Control address
100 * needs to be changed. If this interface is not defined, the
101 * mac address can not be changed.
103 * int (*ndo_validate_addr)(struct net_device *dev);
104 * Test if Media Access Control address is valid for the device.
106 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
107 * Called when a user request an ioctl which can't be handled by
108 * the generic interface code. If not defined ioctl's return
109 * not supported error code.
111 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
112 * Used to set network devices bus interface parameters. This interface
113 * is retained for legacy reason, new devices should use the bus
114 * interface (PCI) for low level management.
116 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
117 * Called when a user wants to change the Maximum Transfer Unit
118 * of a device. If not defined, any request to change MTU will
119 * will return an error.
121 * void (*ndo_tx_timeout)(struct net_device *dev);
122 * Callback uses when the transmitter has not made any progress
123 * for dev->watchdog ticks.
125 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
126 * Called when a user wants to get the network device usage
127 * statistics. If not defined, the counters in dev->stats will
130 * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
131 * If device support VLAN receive accleration
132 * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called
133 * when vlan groups for the device changes. Note: grp is NULL
134 * if no vlan's groups are being used.
136 * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
137 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
138 * this function is called when a VLAN id is registered.
140 * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
141 * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
142 * this function is called when a VLAN id is unregistered.
144 * void (*ndo_poll_controller)(struct net_device *dev);
146 * SR-IOV management functions.
147 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
148 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos);
149 * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate);
150 * int (*ndo_get_vf_config)(struct net_device *dev,
151 * int vf, struct ifla_vf_info *ivf);
153 #define HAVE_NET_DEVICE_OPS
154 struct net_device_ops {
155 int (*ndo_init)(struct net_device *dev);
156 void (*ndo_uninit)(struct net_device *dev);
157 int (*ndo_open)(struct net_device *dev);
158 int (*ndo_stop)(struct net_device *dev);
159 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
160 struct net_device *dev);
161 u16 (*ndo_select_queue)(struct net_device *dev,
162 struct sk_buff *skb);
163 void (*ndo_change_rx_flags)(struct net_device *dev,
165 void (*ndo_set_rx_mode)(struct net_device *dev);
166 void (*ndo_set_multicast_list)(struct net_device *dev);
167 int (*ndo_set_mac_address)(struct net_device *dev,
169 int (*ndo_validate_addr)(struct net_device *dev);
170 int (*ndo_do_ioctl)(struct net_device *dev,
171 struct ifreq *ifr, int cmd);
172 int (*ndo_set_config)(struct net_device *dev,
174 int (*ndo_change_mtu)(struct net_device *dev,
176 int (*ndo_neigh_setup)(struct net_device *dev,
177 struct neigh_parms *);
178 void (*ndo_tx_timeout) (struct net_device *dev);
180 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
182 void (*ndo_vlan_rx_register)(struct net_device *dev,
183 struct vlan_group *grp);
184 void (*ndo_vlan_rx_add_vid)(struct net_device *dev,
186 void (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
188 #ifdef CONFIG_NET_POLL_CONTROLLER
189 void (*ndo_poll_controller)(struct net_device *dev);
191 int (*ndo_set_vf_mac)(struct net_device *dev,
193 int (*ndo_set_vf_vlan)(struct net_device *dev,
194 int queue, u16 vlan, u8 qos);
195 int (*ndo_set_vf_tx_rate)(struct net_device *dev,
198 * The struct ifla_vf_info was added via b280da8d54b8d82b52f368a8703b7ada6c1744d5
199 * on the v2.6.34-rc1~233^2~338 release
201 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34))
202 int (*ndo_get_vf_config)(struct net_device *dev,
204 struct ifla_vf_info *ivf);
206 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
207 int (*ndo_fcoe_enable)(struct net_device *dev);
208 int (*ndo_fcoe_disable)(struct net_device *dev);
209 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
211 struct scatterlist *sgl,
213 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
215 #define NETDEV_FCOE_WWNN 0
216 #define NETDEV_FCOE_WWPN 1
217 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
222 static inline int ndo_do_ioctl(struct net_device *dev,
227 return dev->do_ioctl(dev, ifr, cmd);
232 #define netdev_attach_ops LINUX_BACKPORT(netdev_attach_ops)
233 void netdev_attach_ops(struct net_device *dev,
234 const struct net_device_ops *ops);
237 * skb_queue_is_first - check if skb is the first entry in the queue
241 * Returns true if @skb is the first buffer on the list.
243 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
244 const struct sk_buff *skb)
246 return (skb->prev == (struct sk_buff *) list);
250 * skb_queue_prev - return the prev packet in the queue
252 * @skb: current buffer
254 * Return the prev packet in @list before @skb. It is only valid to
255 * call this if skb_queue_is_first() evaluates to false.
257 static inline struct sk_buff *skb_queue_prev(const struct sk_buff_head *list,
258 const struct sk_buff *skb)
260 /* This BUG_ON may seem severe, but if we just return then we
261 * are going to dereference garbage.
263 BUG_ON(skb_queue_is_first(list, skb));
268 static inline struct net_device_stats *dev_get_stats(struct net_device *dev)
270 return dev->get_stats(dev);
273 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23))
274 #if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
275 #define usb_unpoison_anchored_urbs LINUX_BACKPORT(usb_unpoison_anchored_urbs)
276 extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor);
277 #endif /* CONFIG_USB */
280 #define DIV_ROUND_CLOSEST(x, divisor)( \
282 typeof(divisor) __divisor = divisor; \
283 (((x) + ((__divisor) / 2)) / (__divisor)); \
287 #define eth_mac_addr LINUX_BACKPORT(eth_mac_addr)
288 extern int eth_mac_addr(struct net_device *dev, void *p);
289 #define eth_change_mtu LINUX_BACKPORT(eth_change_mtu)
290 extern int eth_change_mtu(struct net_device *dev, int new_mtu);
291 #define eth_validate_addr LINUX_BACKPORT(eth_validate_addr)
292 extern int eth_validate_addr(struct net_device *dev);
296 static inline void write_pnet(struct net **pnet, struct net *net)
301 static inline struct net *read_pnet(struct net * const *pnet)
308 #define write_pnet(pnet, net) do { (void)(net);} while (0)
309 #define read_pnet(pnet) (&init_net)
312 * swap - swap value of @a and @b
315 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
319 #define init_dummy_netdev LINUX_BACKPORT(init_dummy_netdev)
320 extern int init_dummy_netdev(struct net_device *dev);
322 #define compat_pci_suspend(fn) \
323 int fn##_compat(struct pci_dev *pdev, pm_message_t state) \
327 r = fn(&pdev->dev); \
331 pci_save_state(pdev); \
332 pci_disable_device(pdev); \
333 pci_set_power_state(pdev, PCI_D3hot); \
338 #define compat_pci_resume(fn) \
339 int fn##_compat(struct pci_dev *pdev) \
343 pci_set_power_state(pdev, PCI_D0); \
344 r = pci_enable_device(pdev); \
347 pci_restore_state(pdev); \
349 return fn(&pdev->dev); \
352 #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
354 /* Kernels >= 2.6.29 follows */
356 /* XXX: this can probably just go upstream ! */
357 static inline void netdev_attach_ops(struct net_device *dev,
358 const struct net_device_ops *ops)
360 dev->netdev_ops = ops;
363 /* XXX: this can probably just go upstream! */
364 static inline int ndo_do_ioctl(struct net_device *dev,
368 if (dev->netdev_ops && dev->netdev_ops->ndo_do_ioctl)
369 return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd);
373 #define compat_pci_suspend(fn)
374 #define compat_pci_resume(fn)
376 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) */
378 #endif /* LINUX_26_29_COMPAT_H */