kni: initial import
[dpdk.git] / lib / librte_eal / linuxapp / kni / ethtool / igb / kcompat.h
1 /*******************************************************************************
2
3   Intel(R) Gigabit Ethernet Linux driver
4   Copyright(c) 2007-2012 Intel Corporation.
5
6   This program is free software; you can redistribute it and/or modify it
7   under the terms and conditions of the GNU General Public License,
8   version 2, as published by the Free Software Foundation.
9
10   This program is distributed in the hope it will be useful, but WITHOUT
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13   more details.
14
15   You should have received a copy of the GNU General Public License along with
16   this program; if not, write to the Free Software Foundation, Inc.,
17   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19   The full GNU General Public License is included in this distribution in
20   the file called "COPYING".
21
22   Contact Information:
23   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26 *******************************************************************************/
27
28 #ifndef _KCOMPAT_H_
29 #define _KCOMPAT_H_
30
31 #ifndef LINUX_VERSION_CODE
32 #include <linux/version.h>
33 #else
34 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
35 #endif
36 #include <linux/init.h>
37 #include <linux/types.h>
38 #include <linux/errno.h>
39 #include <linux/module.h>
40 #include <linux/pci.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/ioport.h>
45 #include <linux/slab.h>
46 #include <linux/list.h>
47 #include <linux/delay.h>
48 #include <linux/sched.h>
49 #include <linux/in.h>
50 #include <linux/ip.h>
51 #include <linux/udp.h>
52 #include <linux/mii.h>
53 #include <linux/vmalloc.h>
54 #include <asm/io.h>
55 #include <linux/ethtool.h>
56 #include <linux/if_vlan.h>
57
58 /* NAPI enable/disable flags here */
59 #define NAPI
60
61 #define adapter_struct igb_adapter
62 #define adapter_q_vector igb_q_vector
63 #define NAPI
64
65 /* and finally set defines so that the code sees the changes */
66 #ifdef NAPI
67 #else
68 #endif /* NAPI */
69
70 /* packet split disable/enable */
71 #ifdef DISABLE_PACKET_SPLIT
72 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
73 #define CONFIG_IGB_DISABLE_PACKET_SPLIT
74 #endif
75 #endif /* DISABLE_PACKET_SPLIT */
76
77 /* MSI compatibility code for all kernels and drivers */
78 #ifdef DISABLE_PCI_MSI
79 #undef CONFIG_PCI_MSI
80 #endif
81 #ifndef CONFIG_PCI_MSI
82 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
83 struct msix_entry {
84         u16 vector; /* kernel uses to write allocated vector */
85         u16 entry;  /* driver uses to specify entry, OS writes */
86 };
87 #endif
88 #undef pci_enable_msi
89 #define pci_enable_msi(a) -ENOTSUPP
90 #undef pci_disable_msi
91 #define pci_disable_msi(a) do {} while (0)
92 #undef pci_enable_msix
93 #define pci_enable_msix(a, b, c) -ENOTSUPP
94 #undef pci_disable_msix
95 #define pci_disable_msix(a) do {} while (0)
96 #define msi_remove_pci_irq_vectors(a) do {} while (0)
97 #endif /* CONFIG_PCI_MSI */
98 #ifdef DISABLE_PM
99 #undef CONFIG_PM
100 #endif
101
102 #ifdef DISABLE_NET_POLL_CONTROLLER
103 #undef CONFIG_NET_POLL_CONTROLLER
104 #endif
105
106 #ifndef PMSG_SUSPEND
107 #define PMSG_SUSPEND 3
108 #endif
109
110 /* generic boolean compatibility */
111 #undef TRUE
112 #undef FALSE
113 #define TRUE true
114 #define FALSE false
115 #ifdef GCC_VERSION
116 #if ( GCC_VERSION < 3000 )
117 #define _Bool char
118 #endif
119 #else
120 #define _Bool char
121 #endif
122
123 /* kernels less than 2.4.14 don't have this */
124 #ifndef ETH_P_8021Q
125 #define ETH_P_8021Q 0x8100
126 #endif
127
128 #ifndef module_param
129 #define module_param(v,t,p) MODULE_PARM(v, "i");
130 #endif
131
132 #ifndef DMA_64BIT_MASK
133 #define DMA_64BIT_MASK  0xffffffffffffffffULL
134 #endif
135
136 #ifndef DMA_32BIT_MASK
137 #define DMA_32BIT_MASK  0x00000000ffffffffULL
138 #endif
139
140 #ifndef PCI_CAP_ID_EXP
141 #define PCI_CAP_ID_EXP 0x10
142 #endif
143
144 #ifndef PCIE_LINK_STATE_L0S
145 #define PCIE_LINK_STATE_L0S 1
146 #endif
147 #ifndef PCIE_LINK_STATE_L1
148 #define PCIE_LINK_STATE_L1 2
149 #endif
150
151 #ifndef mmiowb
152 #ifdef CONFIG_IA64
153 #define mmiowb() asm volatile ("mf.a" ::: "memory")
154 #else
155 #define mmiowb()
156 #endif
157 #endif
158
159 #ifndef SET_NETDEV_DEV
160 #define SET_NETDEV_DEV(net, pdev)
161 #endif
162
163 #if !defined(HAVE_FREE_NETDEV) && ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
164 #define free_netdev(x)  kfree(x)
165 #endif
166
167 #ifdef HAVE_POLL_CONTROLLER
168 #define CONFIG_NET_POLL_CONTROLLER
169 #endif
170
171 #ifndef SKB_DATAREF_SHIFT
172 /* if we do not have the infrastructure to detect if skb_header is cloned
173    just return false in all cases */
174 #define skb_header_cloned(x) 0
175 #endif
176
177 #ifndef NETIF_F_GSO
178 #define gso_size tso_size
179 #define gso_segs tso_segs
180 #endif
181
182 #ifndef NETIF_F_GRO
183 #define vlan_gro_receive(_napi, _vlgrp, _vlan, _skb) \
184                 vlan_hwaccel_receive_skb(_skb, _vlgrp, _vlan)
185 #define napi_gro_receive(_napi, _skb) netif_receive_skb(_skb)
186 #endif
187
188 #ifndef NETIF_F_SCTP_CSUM
189 #define NETIF_F_SCTP_CSUM 0
190 #endif
191
192 #ifndef NETIF_F_LRO
193 #define NETIF_F_LRO (1 << 15)
194 #endif
195
196 #ifndef NETIF_F_NTUPLE
197 #define NETIF_F_NTUPLE (1 << 27)
198 #endif
199
200 #ifndef IPPROTO_SCTP
201 #define IPPROTO_SCTP 132
202 #endif
203
204 #ifndef CHECKSUM_PARTIAL
205 #define CHECKSUM_PARTIAL CHECKSUM_HW
206 #define CHECKSUM_COMPLETE CHECKSUM_HW
207 #endif
208
209 #ifndef __read_mostly
210 #define __read_mostly
211 #endif
212
213 #ifndef MII_RESV1
214 #define MII_RESV1               0x17            /* Reserved...          */
215 #endif
216
217 #ifndef unlikely
218 #define unlikely(_x) _x
219 #define likely(_x) _x
220 #endif
221
222 #ifndef WARN_ON
223 #define WARN_ON(x)
224 #endif
225
226 #ifndef PCI_DEVICE
227 #define PCI_DEVICE(vend,dev) \
228         .vendor = (vend), .device = (dev), \
229         .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
230 #endif
231
232 #ifndef node_online
233 #define node_online(node) ((node) == 0)
234 #endif
235
236 #ifndef num_online_cpus
237 #define num_online_cpus() smp_num_cpus
238 #endif
239
240 #ifndef cpu_online
241 #define cpu_online(cpuid) test_bit((cpuid), &cpu_online_map)
242 #endif
243
244 #ifndef _LINUX_RANDOM_H
245 #include <linux/random.h>
246 #endif
247
248 #ifndef DECLARE_BITMAP
249 #ifndef BITS_TO_LONGS
250 #define BITS_TO_LONGS(bits) (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
251 #endif
252 #define DECLARE_BITMAP(name,bits) long name[BITS_TO_LONGS(bits)]
253 #endif
254
255 #ifndef VLAN_HLEN
256 #define VLAN_HLEN 4
257 #endif
258
259 #ifndef VLAN_ETH_HLEN
260 #define VLAN_ETH_HLEN 18
261 #endif
262
263 #ifndef VLAN_ETH_FRAME_LEN
264 #define VLAN_ETH_FRAME_LEN 1518
265 #endif
266
267 #if !defined(IXGBE_DCA) && !defined(IGB_DCA)
268 #define dca_get_tag(b) 0
269 #define dca_add_requester(a) -1
270 #define dca_remove_requester(b) do { } while(0) 
271 #define DCA_PROVIDER_ADD     0x0001
272 #define DCA_PROVIDER_REMOVE  0x0002
273 #endif
274
275 #ifndef DCA_GET_TAG_TWO_ARGS
276 #define dca3_get_tag(a,b) dca_get_tag(b)
277 #endif
278
279 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
280 #if defined(__i386__) || defined(__x86_64__)
281 #define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
282 #endif
283 #endif
284
285 /* taken from 2.6.24 definition in linux/kernel.h */
286 #ifndef IS_ALIGNED
287 #define IS_ALIGNED(x,a)         (((x) % ((typeof(x))(a))) == 0)
288 #endif
289
290 #ifndef NETIF_F_HW_VLAN_TX
291 struct _kc_vlan_ethhdr {
292         unsigned char   h_dest[ETH_ALEN];
293         unsigned char   h_source[ETH_ALEN];
294         __be16          h_vlan_proto;
295         __be16          h_vlan_TCI;
296         __be16          h_vlan_encapsulated_proto;
297 };
298 #define vlan_ethhdr _kc_vlan_ethhdr
299 struct _kc_vlan_hdr {
300         __be16          h_vlan_TCI;
301         __be16          h_vlan_encapsulated_proto;
302 };
303 #define vlan_hdr _kc_vlan_hdr
304 #define vlan_tx_tag_present(_skb) 0
305 #define vlan_tx_tag_get(_skb) 0
306 #endif
307
308 #ifndef VLAN_PRIO_SHIFT
309 #define VLAN_PRIO_SHIFT 13
310 #endif
311
312
313 #ifndef __GFP_COLD
314 #define __GFP_COLD 0
315 #endif
316
317 /*****************************************************************************/
318 /* Installations with ethtool version without eeprom, adapter id, or statistics
319  * support */
320
321 #ifndef ETH_GSTRING_LEN
322 #define ETH_GSTRING_LEN 32
323 #endif
324
325 #ifndef ETHTOOL_GSTATS
326 #define ETHTOOL_GSTATS 0x1d
327 #undef ethtool_drvinfo
328 #define ethtool_drvinfo k_ethtool_drvinfo
329 struct k_ethtool_drvinfo {
330         u32 cmd;
331         char driver[32];
332         char version[32];
333         char fw_version[32];
334         char bus_info[32];
335         char reserved1[32];
336         char reserved2[16];
337         u32 n_stats;
338         u32 testinfo_len;
339         u32 eedump_len;
340         u32 regdump_len;
341 };
342
343 struct ethtool_stats {
344         u32 cmd;
345         u32 n_stats;
346         u64 data[0];
347 };
348 #endif /* ETHTOOL_GSTATS */
349
350 #ifndef ETHTOOL_PHYS_ID
351 #define ETHTOOL_PHYS_ID 0x1c
352 #endif /* ETHTOOL_PHYS_ID */
353
354 #ifndef ETHTOOL_GSTRINGS
355 #define ETHTOOL_GSTRINGS 0x1b
356 enum ethtool_stringset {
357         ETH_SS_TEST             = 0,
358         ETH_SS_STATS,
359 };
360 struct ethtool_gstrings {
361         u32 cmd;            /* ETHTOOL_GSTRINGS */
362         u32 string_set;     /* string set id e.c. ETH_SS_TEST, etc*/
363         u32 len;            /* number of strings in the string set */
364         u8 data[0];
365 };
366 #endif /* ETHTOOL_GSTRINGS */
367
368 #ifndef ETHTOOL_TEST
369 #define ETHTOOL_TEST 0x1a
370 enum ethtool_test_flags {
371         ETH_TEST_FL_OFFLINE     = (1 << 0),
372         ETH_TEST_FL_FAILED      = (1 << 1),
373 };
374 struct ethtool_test {
375         u32 cmd;
376         u32 flags;
377         u32 reserved;
378         u32 len;
379         u64 data[0];
380 };
381 #endif /* ETHTOOL_TEST */
382
383 #ifndef ETHTOOL_GEEPROM
384 #define ETHTOOL_GEEPROM 0xb
385 #undef ETHTOOL_GREGS
386 struct ethtool_eeprom {
387         u32 cmd;
388         u32 magic;
389         u32 offset;
390         u32 len;
391         u8 data[0];
392 };
393
394 struct ethtool_value {
395         u32 cmd;
396         u32 data;
397 };
398 #endif /* ETHTOOL_GEEPROM */
399
400 #ifndef ETHTOOL_GLINK
401 #define ETHTOOL_GLINK 0xa
402 #endif /* ETHTOOL_GLINK */
403
404 #ifndef ETHTOOL_GWOL
405 #define ETHTOOL_GWOL 0x5
406 #define ETHTOOL_SWOL 0x6
407 #define SOPASS_MAX      6
408 struct ethtool_wolinfo {
409         u32 cmd;
410         u32 supported;
411         u32 wolopts;
412         u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
413 };
414 #endif /* ETHTOOL_GWOL */
415
416 #ifndef ETHTOOL_GREGS
417 #define ETHTOOL_GREGS           0x00000004 /* Get NIC registers */
418 #define ethtool_regs _kc_ethtool_regs
419 /* for passing big chunks of data */
420 struct _kc_ethtool_regs {
421         u32 cmd;
422         u32 version; /* driver-specific, indicates different chips/revs */
423         u32 len; /* bytes */
424         u8 data[0];
425 };
426 #endif /* ETHTOOL_GREGS */
427
428 #ifndef ETHTOOL_GMSGLVL
429 #define ETHTOOL_GMSGLVL         0x00000007 /* Get driver message level */
430 #endif
431 #ifndef ETHTOOL_SMSGLVL
432 #define ETHTOOL_SMSGLVL         0x00000008 /* Set driver msg level, priv. */
433 #endif
434 #ifndef ETHTOOL_NWAY_RST
435 #define ETHTOOL_NWAY_RST        0x00000009 /* Restart autonegotiation, priv */
436 #endif
437 #ifndef ETHTOOL_GLINK
438 #define ETHTOOL_GLINK           0x0000000a /* Get link status */
439 #endif
440 #ifndef ETHTOOL_GEEPROM
441 #define ETHTOOL_GEEPROM         0x0000000b /* Get EEPROM data */
442 #endif
443 #ifndef ETHTOOL_SEEPROM
444 #define ETHTOOL_SEEPROM         0x0000000c /* Set EEPROM data */
445 #endif
446 #ifndef ETHTOOL_GCOALESCE
447 #define ETHTOOL_GCOALESCE       0x0000000e /* Get coalesce config */
448 /* for configuring coalescing parameters of chip */
449 #define ethtool_coalesce _kc_ethtool_coalesce
450 struct _kc_ethtool_coalesce {
451         u32     cmd;    /* ETHTOOL_{G,S}COALESCE */
452
453         /* How many usecs to delay an RX interrupt after
454          * a packet arrives.  If 0, only rx_max_coalesced_frames
455          * is used.
456          */
457         u32     rx_coalesce_usecs;
458
459         /* How many packets to delay an RX interrupt after
460          * a packet arrives.  If 0, only rx_coalesce_usecs is
461          * used.  It is illegal to set both usecs and max frames
462          * to zero as this would cause RX interrupts to never be
463          * generated.
464          */
465         u32     rx_max_coalesced_frames;
466
467         /* Same as above two parameters, except that these values
468          * apply while an IRQ is being serviced by the host.  Not
469          * all cards support this feature and the values are ignored
470          * in that case.
471          */
472         u32     rx_coalesce_usecs_irq;
473         u32     rx_max_coalesced_frames_irq;
474
475         /* How many usecs to delay a TX interrupt after
476          * a packet is sent.  If 0, only tx_max_coalesced_frames
477          * is used.
478          */
479         u32     tx_coalesce_usecs;
480
481         /* How many packets to delay a TX interrupt after
482          * a packet is sent.  If 0, only tx_coalesce_usecs is
483          * used.  It is illegal to set both usecs and max frames
484          * to zero as this would cause TX interrupts to never be
485          * generated.
486          */
487         u32     tx_max_coalesced_frames;
488
489         /* Same as above two parameters, except that these values
490          * apply while an IRQ is being serviced by the host.  Not
491          * all cards support this feature and the values are ignored
492          * in that case.
493          */
494         u32     tx_coalesce_usecs_irq;
495         u32     tx_max_coalesced_frames_irq;
496
497         /* How many usecs to delay in-memory statistics
498          * block updates.  Some drivers do not have an in-memory
499          * statistic block, and in such cases this value is ignored.
500          * This value must not be zero.
501          */
502         u32     stats_block_coalesce_usecs;
503
504         /* Adaptive RX/TX coalescing is an algorithm implemented by
505          * some drivers to improve latency under low packet rates and
506          * improve throughput under high packet rates.  Some drivers
507          * only implement one of RX or TX adaptive coalescing.  Anything
508          * not implemented by the driver causes these values to be
509          * silently ignored.
510          */
511         u32     use_adaptive_rx_coalesce;
512         u32     use_adaptive_tx_coalesce;
513
514         /* When the packet rate (measured in packets per second)
515          * is below pkt_rate_low, the {rx,tx}_*_low parameters are
516          * used.
517          */
518         u32     pkt_rate_low;
519         u32     rx_coalesce_usecs_low;
520         u32     rx_max_coalesced_frames_low;
521         u32     tx_coalesce_usecs_low;
522         u32     tx_max_coalesced_frames_low;
523
524         /* When the packet rate is below pkt_rate_high but above
525          * pkt_rate_low (both measured in packets per second) the
526          * normal {rx,tx}_* coalescing parameters are used.
527          */
528
529         /* When the packet rate is (measured in packets per second)
530          * is above pkt_rate_high, the {rx,tx}_*_high parameters are
531          * used.
532          */
533         u32     pkt_rate_high;
534         u32     rx_coalesce_usecs_high;
535         u32     rx_max_coalesced_frames_high;
536         u32     tx_coalesce_usecs_high;
537         u32     tx_max_coalesced_frames_high;
538
539         /* How often to do adaptive coalescing packet rate sampling,
540          * measured in seconds.  Must not be zero.
541          */
542         u32     rate_sample_interval;
543 };
544 #endif /* ETHTOOL_GCOALESCE */
545
546 #ifndef ETHTOOL_SCOALESCE
547 #define ETHTOOL_SCOALESCE       0x0000000f /* Set coalesce config. */
548 #endif
549 #ifndef ETHTOOL_GRINGPARAM
550 #define ETHTOOL_GRINGPARAM      0x00000010 /* Get ring parameters */
551 /* for configuring RX/TX ring parameters */
552 #define ethtool_ringparam _kc_ethtool_ringparam
553 struct _kc_ethtool_ringparam {
554         u32     cmd;    /* ETHTOOL_{G,S}RINGPARAM */
555
556         /* Read only attributes.  These indicate the maximum number
557          * of pending RX/TX ring entries the driver will allow the
558          * user to set.
559          */
560         u32     rx_max_pending;
561         u32     rx_mini_max_pending;
562         u32     rx_jumbo_max_pending;
563         u32     tx_max_pending;
564
565         /* Values changeable by the user.  The valid values are
566          * in the range 1 to the "*_max_pending" counterpart above.
567          */
568         u32     rx_pending;
569         u32     rx_mini_pending;
570         u32     rx_jumbo_pending;
571         u32     tx_pending;
572 };
573 #endif /* ETHTOOL_GRINGPARAM */
574
575 #ifndef ETHTOOL_SRINGPARAM
576 #define ETHTOOL_SRINGPARAM      0x00000011 /* Set ring parameters, priv. */
577 #endif
578 #ifndef ETHTOOL_GPAUSEPARAM
579 #define ETHTOOL_GPAUSEPARAM     0x00000012 /* Get pause parameters */
580 /* for configuring link flow control parameters */
581 #define ethtool_pauseparam _kc_ethtool_pauseparam
582 struct _kc_ethtool_pauseparam {
583         u32     cmd;    /* ETHTOOL_{G,S}PAUSEPARAM */
584
585         /* If the link is being auto-negotiated (via ethtool_cmd.autoneg
586          * being true) the user may set 'autoneg' here non-zero to have the
587          * pause parameters be auto-negotiated too.  In such a case, the
588          * {rx,tx}_pause values below determine what capabilities are
589          * advertised.
590          *
591          * If 'autoneg' is zero or the link is not being auto-negotiated,
592          * then {rx,tx}_pause force the driver to use/not-use pause
593          * flow control.
594          */
595         u32     autoneg;
596         u32     rx_pause;
597         u32     tx_pause;
598 };
599 #endif /* ETHTOOL_GPAUSEPARAM */
600
601 #ifndef ETHTOOL_SPAUSEPARAM
602 #define ETHTOOL_SPAUSEPARAM     0x00000013 /* Set pause parameters. */
603 #endif
604 #ifndef ETHTOOL_GRXCSUM
605 #define ETHTOOL_GRXCSUM         0x00000014 /* Get RX hw csum enable (ethtool_value) */
606 #endif
607 #ifndef ETHTOOL_SRXCSUM
608 #define ETHTOOL_SRXCSUM         0x00000015 /* Set RX hw csum enable (ethtool_value) */
609 #endif
610 #ifndef ETHTOOL_GTXCSUM
611 #define ETHTOOL_GTXCSUM         0x00000016 /* Get TX hw csum enable (ethtool_value) */
612 #endif
613 #ifndef ETHTOOL_STXCSUM
614 #define ETHTOOL_STXCSUM         0x00000017 /* Set TX hw csum enable (ethtool_value) */
615 #endif
616 #ifndef ETHTOOL_GSG
617 #define ETHTOOL_GSG             0x00000018 /* Get scatter-gather enable
618                                             * (ethtool_value) */
619 #endif
620 #ifndef ETHTOOL_SSG
621 #define ETHTOOL_SSG             0x00000019 /* Set scatter-gather enable
622                                             * (ethtool_value). */
623 #endif
624 #ifndef ETHTOOL_TEST
625 #define ETHTOOL_TEST            0x0000001a /* execute NIC self-test, priv. */
626 #endif
627 #ifndef ETHTOOL_GSTRINGS
628 #define ETHTOOL_GSTRINGS        0x0000001b /* get specified string set */
629 #endif
630 #ifndef ETHTOOL_PHYS_ID
631 #define ETHTOOL_PHYS_ID         0x0000001c /* identify the NIC */
632 #endif
633 #ifndef ETHTOOL_GSTATS
634 #define ETHTOOL_GSTATS          0x0000001d /* get NIC-specific statistics */
635 #endif
636 #ifndef ETHTOOL_GTSO
637 #define ETHTOOL_GTSO            0x0000001e /* Get TSO enable (ethtool_value) */
638 #endif
639 #ifndef ETHTOOL_STSO
640 #define ETHTOOL_STSO            0x0000001f /* Set TSO enable (ethtool_value) */
641 #endif
642
643 #ifndef ETHTOOL_BUSINFO_LEN
644 #define ETHTOOL_BUSINFO_LEN     32
645 #endif
646
647 #ifndef RHEL_RELEASE_CODE
648 /* NOTE: RHEL_RELEASE_* introduced in RHEL4.5 */
649 #define RHEL_RELEASE_CODE 0
650 #endif
651 #ifndef RHEL_RELEASE_VERSION
652 #define RHEL_RELEASE_VERSION(a,b) (((a) << 8) + (b))
653 #endif
654 #ifndef AX_RELEASE_CODE
655 #define AX_RELEASE_CODE 0
656 #endif
657 #ifndef AX_RELEASE_VERSION
658 #define AX_RELEASE_VERSION(a,b) (((a) << 8) + (b))
659 #endif
660
661 /* SuSE version macro is the same as Linux kernel version */
662 #ifndef SLE_VERSION
663 #define SLE_VERSION(a,b,c) KERNEL_VERSION(a,b,c)
664 #endif
665 #ifndef SLE_VERSION_CODE
666 #ifdef CONFIG_SUSE_KERNEL
667 /* SLES11 GA is 2.6.27 based */
668 #if ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27) )
669 #define SLE_VERSION_CODE SLE_VERSION(11,0,0)
670 #elif ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32) )
671 /* SLES11 SP1 is 2.6.32 based */
672 #define SLE_VERSION_CODE SLE_VERSION(11,1,0)
673 #else
674 #define SLE_VERSION_CODE 0
675 #endif
676 #else /* CONFIG_SUSE_KERNEL */
677 #define SLE_VERSION_CODE 0
678 #endif /* CONFIG_SUSE_KERNEL */
679 #endif /* SLE_VERSION_CODE */
680
681 #ifdef __KLOCWORK__
682 #ifdef ARRAY_SIZE
683 #undef ARRAY_SIZE
684 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
685 #endif
686 #endif /* __KLOCWORK__ */
687
688 /*****************************************************************************/
689 /* 2.4.3 => 2.4.0 */
690 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )
691
692 /**************************************/
693 /* PCI DRIVER API */
694
695 #ifndef pci_set_dma_mask
696 #define pci_set_dma_mask _kc_pci_set_dma_mask
697 extern int _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
698 #endif
699
700 #ifndef pci_request_regions
701 #define pci_request_regions _kc_pci_request_regions
702 extern int _kc_pci_request_regions(struct pci_dev *pdev, char *res_name);
703 #endif
704
705 #ifndef pci_release_regions
706 #define pci_release_regions _kc_pci_release_regions
707 extern void _kc_pci_release_regions(struct pci_dev *pdev);
708 #endif
709
710 /**************************************/
711 /* NETWORK DRIVER API */
712
713 #ifndef alloc_etherdev
714 #define alloc_etherdev _kc_alloc_etherdev
715 extern struct net_device * _kc_alloc_etherdev(int sizeof_priv);
716 #endif
717
718 #ifndef is_valid_ether_addr
719 #define is_valid_ether_addr _kc_is_valid_ether_addr
720 extern int _kc_is_valid_ether_addr(u8 *addr);
721 #endif
722
723 /**************************************/
724 /* MISCELLANEOUS */
725
726 #ifndef INIT_TQUEUE
727 #define INIT_TQUEUE(_tq, _routine, _data)               \
728         do {                                            \
729                 INIT_LIST_HEAD(&(_tq)->list);           \
730                 (_tq)->sync = 0;                        \
731                 (_tq)->routine = _routine;              \
732                 (_tq)->data = _data;                    \
733         } while (0)
734 #endif
735
736 #endif /* 2.4.3 => 2.4.0 */
737
738 /*****************************************************************************/
739 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) )
740 /* Generic MII registers. */
741 #define MII_BMCR            0x00        /* Basic mode control register */
742 #define MII_BMSR            0x01        /* Basic mode status register  */
743 #define MII_PHYSID1         0x02        /* PHYS ID 1                   */
744 #define MII_PHYSID2         0x03        /* PHYS ID 2                   */
745 #define MII_ADVERTISE       0x04        /* Advertisement control reg   */
746 #define MII_LPA             0x05        /* Link partner ability reg    */
747 #define MII_EXPANSION       0x06        /* Expansion register          */
748 /* Basic mode control register. */
749 #define BMCR_FULLDPLX           0x0100  /* Full duplex                 */
750 #define BMCR_ANENABLE           0x1000  /* Enable auto negotiation     */
751 /* Basic mode status register. */
752 #define BMSR_ERCAP              0x0001  /* Ext-reg capability          */
753 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
754 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
755 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
756 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
757 #define BMSR_100FULL            0x4000  /* Can do 100mbps, full-duplex */
758 /* Advertisement control register. */
759 #define ADVERTISE_CSMA          0x0001  /* Only selector supported     */
760 #define ADVERTISE_10HALF        0x0020  /* Try for 10mbps half-duplex  */
761 #define ADVERTISE_10FULL        0x0040  /* Try for 10mbps full-duplex  */
762 #define ADVERTISE_100HALF       0x0080  /* Try for 100mbps half-duplex */
763 #define ADVERTISE_100FULL       0x0100  /* Try for 100mbps full-duplex */
764 #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
765                        ADVERTISE_100HALF | ADVERTISE_100FULL)
766 /* Expansion register for auto-negotiation. */
767 #define EXPANSION_ENABLENPAGE   0x0004  /* This enables npage words    */
768 #endif
769
770 /*****************************************************************************/
771 /* 2.4.6 => 2.4.3 */
772 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )
773
774 #ifndef pci_set_power_state
775 #define pci_set_power_state _kc_pci_set_power_state
776 extern int _kc_pci_set_power_state(struct pci_dev *dev, int state);
777 #endif
778
779 #ifndef pci_enable_wake
780 #define pci_enable_wake _kc_pci_enable_wake
781 extern int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable);
782 #endif
783
784 #ifndef pci_disable_device
785 #define pci_disable_device _kc_pci_disable_device
786 extern void _kc_pci_disable_device(struct pci_dev *pdev);
787 #endif
788
789 /* PCI PM entry point syntax changed, so don't support suspend/resume */
790 #undef CONFIG_PM
791
792 #endif /* 2.4.6 => 2.4.3 */
793
794 #ifndef HAVE_PCI_SET_MWI
795 #define pci_set_mwi(X) pci_write_config_word(X, \
796                                PCI_COMMAND, adapter->hw.bus.pci_cmd_word | \
797                                PCI_COMMAND_INVALIDATE);
798 #define pci_clear_mwi(X) pci_write_config_word(X, \
799                                PCI_COMMAND, adapter->hw.bus.pci_cmd_word & \
800                                ~PCI_COMMAND_INVALIDATE);
801 #endif
802
803 /*****************************************************************************/
804 /* 2.4.10 => 2.4.9 */
805 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) )
806
807 /**************************************/
808 /* MODULE API */
809
810 #ifndef MODULE_LICENSE
811         #define MODULE_LICENSE(X)
812 #endif
813
814 /**************************************/
815 /* OTHER */
816
817 #undef min
818 #define min(x,y) ({ \
819         const typeof(x) _x = (x);       \
820         const typeof(y) _y = (y);       \
821         (void) (&_x == &_y);            \
822         _x < _y ? _x : _y; })
823
824 #undef max
825 #define max(x,y) ({ \
826         const typeof(x) _x = (x);       \
827         const typeof(y) _y = (y);       \
828         (void) (&_x == &_y);            \
829         _x > _y ? _x : _y; })
830
831 #define min_t(type,x,y) ({ \
832         type _x = (x); \
833         type _y = (y); \
834         _x < _y ? _x : _y; })
835
836 #define max_t(type,x,y) ({ \
837         type _x = (x); \
838         type _y = (y); \
839         _x > _y ? _x : _y; })
840
841 #ifndef list_for_each_safe
842 #define list_for_each_safe(pos, n, head) \
843         for (pos = (head)->next, n = pos->next; pos != (head); \
844                 pos = n, n = pos->next)
845 #endif
846
847 #ifndef ____cacheline_aligned_in_smp
848 #ifdef CONFIG_SMP
849 #define ____cacheline_aligned_in_smp ____cacheline_aligned
850 #else
851 #define ____cacheline_aligned_in_smp
852 #endif /* CONFIG_SMP */
853 #endif
854
855 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) )
856 extern int _kc_snprintf(char * buf, size_t size, const char *fmt, ...);
857 #define snprintf(buf, size, fmt, args...) _kc_snprintf(buf, size, fmt, ##args)
858 extern int _kc_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
859 #define vsnprintf(buf, size, fmt, args) _kc_vsnprintf(buf, size, fmt, args)
860 #else /* 2.4.8 => 2.4.9 */
861 extern int snprintf(char * buf, size_t size, const char *fmt, ...);
862 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
863 #endif
864 #endif /* 2.4.10 -> 2.4.6 */
865
866
867 /*****************************************************************************/
868 /* 2.4.12 => 2.4.10 */
869 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,12) )
870 #ifndef HAVE_NETIF_MSG
871 #define HAVE_NETIF_MSG 1
872 enum {
873         NETIF_MSG_DRV           = 0x0001,
874         NETIF_MSG_PROBE         = 0x0002,
875         NETIF_MSG_LINK          = 0x0004,
876         NETIF_MSG_TIMER         = 0x0008,
877         NETIF_MSG_IFDOWN        = 0x0010,
878         NETIF_MSG_IFUP          = 0x0020,
879         NETIF_MSG_RX_ERR        = 0x0040,
880         NETIF_MSG_TX_ERR        = 0x0080,
881         NETIF_MSG_TX_QUEUED     = 0x0100,
882         NETIF_MSG_INTR          = 0x0200,
883         NETIF_MSG_TX_DONE       = 0x0400,
884         NETIF_MSG_RX_STATUS     = 0x0800,
885         NETIF_MSG_PKTDATA       = 0x1000,
886         NETIF_MSG_HW            = 0x2000,
887         NETIF_MSG_WOL           = 0x4000,
888 };
889
890 #define netif_msg_drv(p)        ((p)->msg_enable & NETIF_MSG_DRV)
891 #define netif_msg_probe(p)      ((p)->msg_enable & NETIF_MSG_PROBE)
892 #define netif_msg_link(p)       ((p)->msg_enable & NETIF_MSG_LINK)
893 #define netif_msg_timer(p)      ((p)->msg_enable & NETIF_MSG_TIMER)
894 #define netif_msg_ifdown(p)     ((p)->msg_enable & NETIF_MSG_IFDOWN)
895 #define netif_msg_ifup(p)       ((p)->msg_enable & NETIF_MSG_IFUP)
896 #define netif_msg_rx_err(p)     ((p)->msg_enable & NETIF_MSG_RX_ERR)
897 #define netif_msg_tx_err(p)     ((p)->msg_enable & NETIF_MSG_TX_ERR)
898 #define netif_msg_tx_queued(p)  ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
899 #define netif_msg_intr(p)       ((p)->msg_enable & NETIF_MSG_INTR)
900 #define netif_msg_tx_done(p)    ((p)->msg_enable & NETIF_MSG_TX_DONE)
901 #define netif_msg_rx_status(p)  ((p)->msg_enable & NETIF_MSG_RX_STATUS)
902 #define netif_msg_pktdata(p)    ((p)->msg_enable & NETIF_MSG_PKTDATA)
903 #endif /* !HAVE_NETIF_MSG */
904 #endif /* 2.4.12 => 2.4.10 */
905
906 /*****************************************************************************/
907 /* 2.4.13 => 2.4.12 */
908 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )
909
910 /**************************************/
911 /* PCI DMA MAPPING */
912
913 #ifndef virt_to_page
914         #define virt_to_page(v) (mem_map + (virt_to_phys(v) >> PAGE_SHIFT))
915 #endif
916
917 #ifndef pci_map_page
918 #define pci_map_page _kc_pci_map_page
919 extern u64 _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset, size_t size, int direction);
920 #endif
921
922 #ifndef pci_unmap_page
923 #define pci_unmap_page _kc_pci_unmap_page
924 extern void _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size, int direction);
925 #endif
926
927 /* pci_set_dma_mask takes dma_addr_t, which is only 32-bits prior to 2.4.13 */
928
929 #undef DMA_32BIT_MASK
930 #define DMA_32BIT_MASK  0xffffffff
931 #undef DMA_64BIT_MASK
932 #define DMA_64BIT_MASK  0xffffffff
933
934 /**************************************/
935 /* OTHER */
936
937 #ifndef cpu_relax
938 #define cpu_relax()     rep_nop()
939 #endif
940
941 struct vlan_ethhdr {
942         unsigned char h_dest[ETH_ALEN];
943         unsigned char h_source[ETH_ALEN];
944         unsigned short h_vlan_proto;
945         unsigned short h_vlan_TCI;
946         unsigned short h_vlan_encapsulated_proto;
947 };
948 #endif /* 2.4.13 => 2.4.12 */
949
950 /*****************************************************************************/
951 /* 2.4.17 => 2.4.12 */
952 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17) )
953
954 #ifndef __devexit_p
955         #define __devexit_p(x) &(x)
956 #endif
957
958 #endif /* 2.4.17 => 2.4.13 */
959
960 /*****************************************************************************/
961 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18) )
962 #define NETIF_MSG_HW    0x2000
963 #define NETIF_MSG_WOL   0x4000
964
965 #ifndef netif_msg_hw
966 #define netif_msg_hw(p)         ((p)->msg_enable & NETIF_MSG_HW)
967 #endif
968 #ifndef netif_msg_wol
969 #define netif_msg_wol(p)        ((p)->msg_enable & NETIF_MSG_WOL)
970 #endif
971 #endif /* 2.4.18 */
972
973 /*****************************************************************************/
974
975 /*****************************************************************************/
976 /* 2.4.20 => 2.4.19 */
977 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20) )
978
979 /* we won't support NAPI on less than 2.4.20 */
980 #ifdef NAPI
981 #undef NAPI
982 #endif
983
984 #endif /* 2.4.20 => 2.4.19 */
985
986 /*****************************************************************************/
987 /* 2.4.22 => 2.4.17 */
988 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
989 #define pci_name(x)     ((x)->slot_name)
990 #endif
991
992 /*****************************************************************************/
993 /* 2.4.22 => 2.4.17 */
994
995 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
996 #ifndef IGB_NO_LRO
997 #define IGB_NO_LRO
998 #endif
999 #endif
1000
1001 /*****************************************************************************/
1002 /*****************************************************************************/
1003 /* 2.4.23 => 2.4.22 */
1004 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23) )
1005 /*****************************************************************************/
1006 #ifdef NAPI
1007 #ifndef netif_poll_disable
1008 #define netif_poll_disable(x) _kc_netif_poll_disable(x)
1009 static inline void _kc_netif_poll_disable(struct net_device *netdev)
1010 {
1011         while (test_and_set_bit(__LINK_STATE_RX_SCHED, &netdev->state)) {
1012                 /* No hurry */
1013                 current->state = TASK_INTERRUPTIBLE;
1014                 schedule_timeout(1);
1015         }
1016 }
1017 #endif
1018 #ifndef netif_poll_enable
1019 #define netif_poll_enable(x) _kc_netif_poll_enable(x)
1020 static inline void _kc_netif_poll_enable(struct net_device *netdev)
1021 {
1022         clear_bit(__LINK_STATE_RX_SCHED, &netdev->state);
1023 }
1024 #endif
1025 #endif /* NAPI */
1026 #ifndef netif_tx_disable
1027 #define netif_tx_disable(x) _kc_netif_tx_disable(x)
1028 static inline void _kc_netif_tx_disable(struct net_device *dev)
1029 {
1030         spin_lock_bh(&dev->xmit_lock);
1031         netif_stop_queue(dev);
1032         spin_unlock_bh(&dev->xmit_lock);
1033 }
1034 #endif
1035 #else /* 2.4.23 => 2.4.22 */
1036 #define HAVE_SCTP
1037 #endif /* 2.4.23 => 2.4.22 */
1038
1039 /*****************************************************************************/
1040 /* 2.6.4 => 2.6.0 */
1041 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \
1042     ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1043       LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )
1044 #define ETHTOOL_OPS_COMPAT
1045 #endif /* 2.6.4 => 2.6.0 */
1046
1047 /*****************************************************************************/
1048 /* 2.5.71 => 2.4.x */
1049 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71) )
1050 #define sk_protocol protocol
1051 #define pci_get_device pci_find_device
1052 #endif /* 2.5.70 => 2.4.x */
1053
1054 /*****************************************************************************/
1055 /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1056 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) || \
1057     ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1058       LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) ) )
1059
1060 #ifndef netif_msg_init
1061 #define netif_msg_init _kc_netif_msg_init
1062 static inline u32 _kc_netif_msg_init(int debug_value, int default_msg_enable_bits)
1063 {
1064         /* use default */
1065         if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
1066                 return default_msg_enable_bits;
1067         if (debug_value == 0) /* no output */
1068                 return 0;
1069         /* set low N bits */
1070         return (1 << debug_value) -1;
1071 }
1072 #endif
1073
1074 #endif /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1075 /*****************************************************************************/
1076 #if (( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) ) || \
1077      (( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) && \
1078       ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) )))
1079 #define netdev_priv(x) x->priv
1080 #endif
1081
1082 /*****************************************************************************/
1083 /* <= 2.5.0 */
1084 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) )
1085 #include <linux/rtnetlink.h>
1086 #undef pci_register_driver
1087 #define pci_register_driver pci_module_init
1088
1089 /*
1090  * Most of the dma compat code is copied/modifed from the 2.4.37
1091  * /include/linux/libata-compat.h header file
1092  */
1093 /* These definitions mirror those in pci.h, so they can be used
1094  * interchangeably with their PCI_ counterparts */
1095 enum dma_data_direction {
1096         DMA_BIDIRECTIONAL = 0,
1097         DMA_TO_DEVICE = 1,
1098         DMA_FROM_DEVICE = 2,
1099         DMA_NONE = 3,
1100 };
1101
1102 struct device {
1103         struct pci_dev pdev;
1104 };
1105
1106 static inline struct pci_dev *to_pci_dev (struct device *dev)
1107 {
1108         return (struct pci_dev *) dev;
1109 }
1110 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1111 {
1112         return (struct device *) pdev;
1113 }
1114
1115 #define pdev_printk(lvl, pdev, fmt, args...)    \
1116         printk("%s %s: " fmt, lvl, pci_name(pdev), ## args)
1117 #define dev_err(dev, fmt, args...)            \
1118         pdev_printk(KERN_ERR, to_pci_dev(dev), fmt, ## args)
1119 #define dev_info(dev, fmt, args...)            \
1120         pdev_printk(KERN_INFO, to_pci_dev(dev), fmt, ## args)
1121 #define dev_warn(dev, fmt, args...)            \
1122         pdev_printk(KERN_WARNING, to_pci_dev(dev), fmt, ## args)
1123
1124 /* NOTE: dangerous! we ignore the 'gfp' argument */
1125 #define dma_alloc_coherent(dev,sz,dma,gfp) \
1126         pci_alloc_consistent(to_pci_dev(dev),(sz),(dma))
1127 #define dma_free_coherent(dev,sz,addr,dma_addr) \
1128         pci_free_consistent(to_pci_dev(dev),(sz),(addr),(dma_addr))
1129
1130 #define dma_map_page(dev,a,b,c,d) \
1131         pci_map_page(to_pci_dev(dev),(a),(b),(c),(d))
1132 #define dma_unmap_page(dev,a,b,c) \
1133         pci_unmap_page(to_pci_dev(dev),(a),(b),(c))
1134
1135 #define dma_map_single(dev,a,b,c) \
1136         pci_map_single(to_pci_dev(dev),(a),(b),(c))
1137 #define dma_unmap_single(dev,a,b,c) \
1138         pci_unmap_single(to_pci_dev(dev),(a),(b),(c))
1139
1140 #define dma_sync_single(dev,a,b,c) \
1141         pci_dma_sync_single(to_pci_dev(dev),(a),(b),(c))
1142
1143 /* for range just sync everything, that's all the pci API can do */
1144 #define dma_sync_single_range(dev,addr,off,sz,dir) \
1145         pci_dma_sync_single(to_pci_dev(dev),(addr),(off)+(sz),(dir))
1146
1147 #define dma_set_mask(dev,mask) \
1148         pci_set_dma_mask(to_pci_dev(dev),(mask))
1149
1150 /* hlist_* code - double linked lists */
1151 struct hlist_head {
1152         struct hlist_node *first;
1153 };
1154
1155 struct hlist_node {
1156         struct hlist_node *next, **pprev;
1157 };
1158
1159 static inline void __hlist_del(struct hlist_node *n)
1160 {
1161         struct hlist_node *next = n->next;
1162         struct hlist_node **pprev = n->pprev;
1163         *pprev = next;
1164         if (next)
1165         next->pprev = pprev;
1166 }
1167
1168 static inline void hlist_del(struct hlist_node *n)
1169 {
1170         __hlist_del(n);
1171         n->next = NULL;
1172         n->pprev = NULL;
1173 }
1174
1175 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
1176 {
1177         struct hlist_node *first = h->first;
1178         n->next = first;
1179         if (first)
1180                 first->pprev = &n->next;
1181         h->first = n;
1182         n->pprev = &h->first;
1183 }
1184
1185 static inline int hlist_empty(const struct hlist_head *h)
1186 {
1187         return !h->first;
1188 }
1189 #define HLIST_HEAD_INIT { .first = NULL }
1190 #define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
1191 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
1192 static inline void INIT_HLIST_NODE(struct hlist_node *h)
1193 {
1194         h->next = NULL;
1195         h->pprev = NULL;
1196 }
1197 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
1198
1199 #define hlist_for_each_entry(tpos, pos, head, member)                    \
1200         for (pos = (head)->first;                                        \
1201              pos && ({ prefetch(pos->next); 1;}) &&                      \
1202                 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1203              pos = pos->next)
1204
1205 #define hlist_for_each_entry_safe(tpos, pos, n, head, member)            \
1206         for (pos = (head)->first;                                        \
1207              pos && ({ n = pos->next; 1; }) &&                           \
1208                 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1209              pos = n)
1210
1211 #ifndef might_sleep
1212 #define might_sleep()
1213 #endif
1214 #else
1215 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1216 {
1217         return &pdev->dev;
1218 }
1219 #endif /* <= 2.5.0 */
1220
1221 /*****************************************************************************/
1222 /* 2.5.28 => 2.4.23 */
1223 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )
1224
1225 static inline void _kc_synchronize_irq(void)
1226 {
1227         synchronize_irq();
1228 }
1229 #undef synchronize_irq
1230 #define synchronize_irq(X) _kc_synchronize_irq()
1231
1232 #include <linux/tqueue.h>
1233 #define work_struct tq_struct
1234 #undef INIT_WORK
1235 #define INIT_WORK(a,b) INIT_TQUEUE(a,(void (*)(void *))b,a)
1236 #undef container_of
1237 #define container_of list_entry
1238 #define schedule_work schedule_task
1239 #define flush_scheduled_work flush_scheduled_tasks
1240 #define cancel_work_sync(x) flush_scheduled_work()
1241
1242 #endif /* 2.5.28 => 2.4.17 */
1243
1244 /*****************************************************************************/
1245 /* 2.6.0 => 2.5.28 */
1246 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
1247 #undef get_cpu
1248 #define get_cpu() smp_processor_id()
1249 #undef put_cpu
1250 #define put_cpu() do { } while(0)
1251 #define MODULE_INFO(version, _version)
1252 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1253 #define CONFIG_E1000_DISABLE_PACKET_SPLIT 1
1254 #endif
1255 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
1256 #define CONFIG_IGB_DISABLE_PACKET_SPLIT 1
1257 #endif
1258
1259 #define dma_set_coherent_mask(dev,mask) 1
1260
1261 #undef dev_put
1262 #define dev_put(dev) __dev_put(dev)
1263
1264 #ifndef skb_fill_page_desc
1265 #define skb_fill_page_desc _kc_skb_fill_page_desc
1266 extern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size);
1267 #endif
1268
1269 #undef ALIGN
1270 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
1271
1272 #ifndef page_count
1273 #define page_count(p) atomic_read(&(p)->count)
1274 #endif
1275
1276 #ifdef MAX_NUMNODES
1277 #undef MAX_NUMNODES
1278 #endif
1279 #define MAX_NUMNODES 1
1280
1281 /* find_first_bit and find_next bit are not defined for most
1282  * 2.4 kernels (except for the redhat 2.4.21 kernels
1283  */
1284 #include <linux/bitops.h>
1285 #define BITOP_WORD(nr)          ((nr) / BITS_PER_LONG)
1286 #undef find_next_bit
1287 #define find_next_bit _kc_find_next_bit
1288 extern unsigned long _kc_find_next_bit(const unsigned long *addr,
1289                                        unsigned long size,
1290                                        unsigned long offset);
1291 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
1292
1293
1294 #ifndef netdev_name
1295 static inline const char *_kc_netdev_name(const struct net_device *dev)
1296 {
1297         if (strchr(dev->name, '%'))
1298                 return "(unregistered net_device)";
1299         return dev->name;
1300 }
1301 #define netdev_name(netdev)     _kc_netdev_name(netdev)
1302 #endif /* netdev_name */
1303
1304 #ifndef strlcpy
1305 #define strlcpy _kc_strlcpy
1306 extern size_t _kc_strlcpy(char *dest, const char *src, size_t size);
1307 #endif /* strlcpy */
1308
1309 #endif /* 2.6.0 => 2.5.28 */
1310
1311 /*****************************************************************************/
1312 /* 2.6.4 => 2.6.0 */
1313 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1314 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
1315 #endif /* 2.6.4 => 2.6.0 */
1316
1317 /*****************************************************************************/
1318 /* 2.6.5 => 2.6.0 */
1319 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) )
1320 #define dma_sync_single_for_cpu         dma_sync_single
1321 #define dma_sync_single_for_device      dma_sync_single
1322 #define dma_sync_single_range_for_cpu           dma_sync_single_range
1323 #define dma_sync_single_range_for_device        dma_sync_single_range
1324 #ifndef pci_dma_mapping_error
1325 #define pci_dma_mapping_error _kc_pci_dma_mapping_error
1326 static inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr)
1327 {
1328         return dma_addr == 0;
1329 }
1330 #endif
1331 #endif /* 2.6.5 => 2.6.0 */
1332
1333 /*****************************************************************************/
1334 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1335 extern int _kc_scnprintf(char * buf, size_t size, const char *fmt, ...);
1336 #define scnprintf(buf, size, fmt, args...) _kc_scnprintf(buf, size, fmt, ##args)
1337 #endif /* < 2.6.4 */
1338
1339 /*****************************************************************************/
1340 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6) )
1341 /* taken from 2.6 include/linux/bitmap.h */
1342 #undef bitmap_zero
1343 #define bitmap_zero _kc_bitmap_zero
1344 static inline void _kc_bitmap_zero(unsigned long *dst, int nbits)
1345 {
1346         if (nbits <= BITS_PER_LONG)
1347                 *dst = 0UL;
1348         else {
1349                 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
1350                 memset(dst, 0, len);
1351         }
1352 }
1353 #define random_ether_addr _kc_random_ether_addr
1354 static inline void _kc_random_ether_addr(u8 *addr)
1355 {
1356         get_random_bytes(addr, ETH_ALEN);
1357         addr[0] &= 0xfe; /* clear multicast */
1358         addr[0] |= 0x02; /* set local assignment */
1359 }
1360 #define page_to_nid(x) 0
1361
1362 #endif /* < 2.6.6 */
1363
1364 /*****************************************************************************/
1365 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7) )
1366 #undef if_mii
1367 #define if_mii _kc_if_mii
1368 static inline struct mii_ioctl_data *_kc_if_mii(struct ifreq *rq)
1369 {
1370         return (struct mii_ioctl_data *) &rq->ifr_ifru;
1371 }
1372
1373 #ifndef __force
1374 #define __force
1375 #endif
1376 #endif /* < 2.6.7 */
1377
1378 /*****************************************************************************/
1379 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
1380 #ifndef PCI_EXP_DEVCTL
1381 #define PCI_EXP_DEVCTL 8
1382 #endif
1383 #ifndef PCI_EXP_DEVCTL_CERE
1384 #define PCI_EXP_DEVCTL_CERE 0x0001
1385 #endif
1386 #define msleep(x)       do { set_current_state(TASK_UNINTERRUPTIBLE); \
1387                                 schedule_timeout((x * HZ)/1000 + 2); \
1388                         } while (0)
1389
1390 #endif /* < 2.6.8 */
1391
1392 /*****************************************************************************/
1393 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
1394 #include <net/dsfield.h>
1395 #define __iomem
1396
1397 #ifndef kcalloc
1398 #define kcalloc(n, size, flags) _kc_kzalloc(((n) * (size)), flags)
1399 extern void *_kc_kzalloc(size_t size, int flags);
1400 #endif
1401 #define MSEC_PER_SEC    1000L
1402 static inline unsigned int _kc_jiffies_to_msecs(const unsigned long j)
1403 {
1404 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1405         return (MSEC_PER_SEC / HZ) * j;
1406 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1407         return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
1408 #else
1409         return (j * MSEC_PER_SEC) / HZ;
1410 #endif
1411 }
1412 static inline unsigned long _kc_msecs_to_jiffies(const unsigned int m)
1413 {
1414         if (m > _kc_jiffies_to_msecs(MAX_JIFFY_OFFSET))
1415                 return MAX_JIFFY_OFFSET;
1416 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1417         return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
1418 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1419         return m * (HZ / MSEC_PER_SEC);
1420 #else
1421         return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
1422 #endif
1423 }
1424
1425 #define msleep_interruptible _kc_msleep_interruptible
1426 static inline unsigned long _kc_msleep_interruptible(unsigned int msecs)
1427 {
1428         unsigned long timeout = _kc_msecs_to_jiffies(msecs) + 1;
1429
1430         while (timeout && !signal_pending(current)) {
1431                 __set_current_state(TASK_INTERRUPTIBLE);
1432                 timeout = schedule_timeout(timeout);
1433         }
1434         return _kc_jiffies_to_msecs(timeout);
1435 }
1436
1437 /* Basic mode control register. */
1438 #define BMCR_SPEED1000          0x0040  /* MSB of Speed (1000)         */
1439
1440 #ifndef __le16
1441 #define __le16 u16
1442 #endif
1443 #ifndef __le32
1444 #define __le32 u32
1445 #endif
1446 #ifndef __le64
1447 #define __le64 u64
1448 #endif
1449 #ifndef __be16
1450 #define __be16 u16
1451 #endif
1452 #ifndef __be32
1453 #define __be32 u32
1454 #endif
1455 #ifndef __be64
1456 #define __be64 u64
1457 #endif
1458
1459 static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
1460 {
1461         return (struct vlan_ethhdr *)skb->mac.raw;
1462 }
1463
1464 /* Wake-On-Lan options. */
1465 #define WAKE_PHY                (1 << 0)
1466 #define WAKE_UCAST              (1 << 1)
1467 #define WAKE_MCAST              (1 << 2)
1468 #define WAKE_BCAST              (1 << 3)
1469 #define WAKE_ARP                (1 << 4)
1470 #define WAKE_MAGIC              (1 << 5)
1471 #define WAKE_MAGICSECURE        (1 << 6) /* only meaningful if WAKE_MAGIC */
1472
1473 #define skb_header_pointer _kc_skb_header_pointer
1474 static inline void *_kc_skb_header_pointer(const struct sk_buff *skb,
1475                                             int offset, int len, void *buffer)
1476 {
1477         int hlen = skb_headlen(skb);
1478
1479         if (hlen - offset >= len)
1480                 return skb->data + offset;
1481
1482 #ifdef MAX_SKB_FRAGS
1483         if (skb_copy_bits(skb, offset, buffer, len) < 0)
1484                 return NULL;
1485
1486         return buffer;
1487 #else
1488         return NULL;
1489 #endif
1490
1491 #ifndef NETDEV_TX_OK
1492 #define NETDEV_TX_OK 0
1493 #endif
1494 #ifndef NETDEV_TX_BUSY
1495 #define NETDEV_TX_BUSY 1
1496 #endif
1497 #ifndef NETDEV_TX_LOCKED
1498 #define NETDEV_TX_LOCKED -1
1499 #endif
1500 }
1501
1502 #ifndef __bitwise
1503 #define __bitwise
1504 #endif
1505 #endif /* < 2.6.9 */
1506
1507 /*****************************************************************************/
1508 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) )
1509 #ifdef module_param_array_named
1510 #undef module_param_array_named
1511 #define module_param_array_named(name, array, type, nump, perm)          \
1512         static struct kparam_array __param_arr_##name                    \
1513         = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type, \
1514             sizeof(array[0]), array };                                   \
1515         module_param_call(name, param_array_set, param_array_get,        \
1516                           &__param_arr_##name, perm)
1517 #endif /* module_param_array_named */
1518 /*
1519  * num_online is broken for all < 2.6.10 kernels.  This is needed to support
1520  * Node module parameter of ixgbe.
1521  */
1522 #undef num_online_nodes
1523 #define num_online_nodes(n) 1
1524 extern DECLARE_BITMAP(_kcompat_node_online_map, MAX_NUMNODES);
1525 #undef node_online_map
1526 #define node_online_map _kcompat_node_online_map
1527 #endif /* < 2.6.10 */
1528
1529 /*****************************************************************************/
1530 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) )
1531 #define PCI_D0      0
1532 #define PCI_D1      1
1533 #define PCI_D2      2
1534 #define PCI_D3hot   3
1535 #define PCI_D3cold  4
1536 typedef int pci_power_t;
1537 #define pci_choose_state(pdev,state) state
1538 #define PMSG_SUSPEND 3
1539 #define PCI_EXP_LNKCTL  16
1540
1541 #undef NETIF_F_LLTX
1542
1543 #ifndef ARCH_HAS_PREFETCH
1544 #define prefetch(X)
1545 #endif
1546
1547 #ifndef NET_IP_ALIGN
1548 #define NET_IP_ALIGN 2
1549 #endif
1550
1551 #define KC_USEC_PER_SEC 1000000L
1552 #define usecs_to_jiffies _kc_usecs_to_jiffies
1553 static inline unsigned int _kc_jiffies_to_usecs(const unsigned long j)
1554 {
1555 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1556         return (KC_USEC_PER_SEC / HZ) * j;
1557 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1558         return (j + (HZ / KC_USEC_PER_SEC) - 1)/(HZ / KC_USEC_PER_SEC);
1559 #else
1560         return (j * KC_USEC_PER_SEC) / HZ;
1561 #endif
1562 }
1563 static inline unsigned long _kc_usecs_to_jiffies(const unsigned int m)
1564 {
1565         if (m > _kc_jiffies_to_usecs(MAX_JIFFY_OFFSET))
1566                 return MAX_JIFFY_OFFSET;
1567 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1568         return (m + (KC_USEC_PER_SEC / HZ) - 1) / (KC_USEC_PER_SEC / HZ);
1569 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1570         return m * (HZ / KC_USEC_PER_SEC);
1571 #else
1572         return (m * HZ + KC_USEC_PER_SEC - 1) / KC_USEC_PER_SEC;
1573 #endif
1574 }
1575 #endif /* < 2.6.11 */
1576
1577 /*****************************************************************************/
1578 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) )
1579 #include <linux/reboot.h>
1580 #define USE_REBOOT_NOTIFIER
1581
1582 /* Generic MII registers. */
1583 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
1584 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
1585 /* Advertisement control register. */
1586 #define ADVERTISE_PAUSE_CAP     0x0400  /* Try for pause               */
1587 #define ADVERTISE_PAUSE_ASYM    0x0800  /* Try for asymmetric pause     */
1588 /* 1000BASE-T Control register */
1589 #define ADVERTISE_1000FULL      0x0200  /* Advertise 1000BASE-T full duplex */
1590 #ifndef is_zero_ether_addr
1591 #define is_zero_ether_addr _kc_is_zero_ether_addr
1592 static inline int _kc_is_zero_ether_addr(const u8 *addr)
1593 {
1594         return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
1595 }
1596 #endif /* is_zero_ether_addr */
1597 #ifndef is_multicast_ether_addr
1598 #define is_multicast_ether_addr _kc_is_multicast_ether_addr
1599 static inline int _kc_is_multicast_ether_addr(const u8 *addr)
1600 {
1601         return addr[0] & 0x01;
1602 }
1603 #endif /* is_multicast_ether_addr */
1604 #endif /* < 2.6.12 */
1605
1606 /*****************************************************************************/
1607 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) )
1608 #ifndef kstrdup
1609 #define kstrdup _kc_kstrdup
1610 extern char *_kc_kstrdup(const char *s, unsigned int gfp);
1611 #endif
1612 #endif /* < 2.6.13 */
1613
1614 /*****************************************************************************/
1615 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) )
1616 #define pm_message_t u32
1617 #ifndef kzalloc
1618 #define kzalloc _kc_kzalloc
1619 extern void *_kc_kzalloc(size_t size, int flags);
1620 #endif
1621
1622 /* Generic MII registers. */
1623 #define MII_ESTATUS         0x0f        /* Extended Status */
1624 /* Basic mode status register. */
1625 #define BMSR_ESTATEN            0x0100  /* Extended Status in R15 */
1626 /* Extended status register. */
1627 #define ESTATUS_1000_TFULL      0x2000  /* Can do 1000BT Full */
1628 #define ESTATUS_1000_THALF      0x1000  /* Can do 1000BT Half */
1629
1630 #define ADVERTISED_Pause        (1 << 13)
1631 #define ADVERTISED_Asym_Pause   (1 << 14)
1632
1633 #if (!(RHEL_RELEASE_CODE && \
1634        (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,3)) && \
1635        (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))))
1636 #if ((LINUX_VERSION_CODE == KERNEL_VERSION(2,6,9)) && !defined(gfp_t))
1637 #define gfp_t unsigned
1638 #else
1639 typedef unsigned gfp_t;
1640 #endif
1641 #endif /* !RHEL4.3->RHEL5.0 */
1642
1643 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9) )
1644 #ifdef CONFIG_X86_64
1645 #define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir)       \
1646         dma_sync_single_for_cpu(dev, dma_handle, size, dir)
1647 #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir)    \
1648         dma_sync_single_for_device(dev, dma_handle, size, dir)
1649 #endif
1650 #endif
1651 #endif /* < 2.6.14 */
1652
1653 /*****************************************************************************/
1654 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) )
1655 #ifndef vmalloc_node
1656 #define vmalloc_node(a,b) vmalloc(a)
1657 #endif /* vmalloc_node*/
1658
1659 #define setup_timer(_timer, _function, _data) \
1660 do { \
1661         (_timer)->function = _function; \
1662         (_timer)->data = _data; \
1663         init_timer(_timer); \
1664 } while (0)
1665 #ifndef device_can_wakeup
1666 #define device_can_wakeup(dev)  (1)
1667 #endif
1668 #ifndef device_set_wakeup_enable
1669 #define device_set_wakeup_enable(dev, val)      do{}while(0)
1670 #endif
1671 #ifndef device_init_wakeup
1672 #define device_init_wakeup(dev,val) do {} while (0)
1673 #endif
1674 static inline unsigned _kc_compare_ether_addr(const u8 *addr1, const u8 *addr2)
1675 {
1676         const u16 *a = (const u16 *) addr1;
1677         const u16 *b = (const u16 *) addr2;
1678
1679         return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
1680 }
1681 #undef compare_ether_addr
1682 #define compare_ether_addr(addr1, addr2) _kc_compare_ether_addr(addr1, addr2)
1683 #endif /* < 2.6.15 */
1684
1685 /*****************************************************************************/
1686 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) )
1687 #undef DEFINE_MUTEX
1688 #define DEFINE_MUTEX(x) DECLARE_MUTEX(x)
1689 #define mutex_lock(x)   down_interruptible(x)
1690 #define mutex_unlock(x) up(x)
1691
1692 #ifndef ____cacheline_internodealigned_in_smp
1693 #ifdef CONFIG_SMP
1694 #define ____cacheline_internodealigned_in_smp ____cacheline_aligned_in_smp
1695 #else
1696 #define ____cacheline_internodealigned_in_smp
1697 #endif /* CONFIG_SMP */
1698 #endif /* ____cacheline_internodealigned_in_smp */
1699 #undef HAVE_PCI_ERS
1700 #else /* 2.6.16 and above */
1701 #undef HAVE_PCI_ERS
1702 #define HAVE_PCI_ERS
1703 #endif /* < 2.6.16 */
1704
1705 /*****************************************************************************/
1706 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) )
1707 #ifndef first_online_node
1708 #define first_online_node 0
1709 #endif
1710 #ifndef NET_SKB_PAD
1711 #define NET_SKB_PAD 16
1712 #endif
1713 #endif /* < 2.6.17 */
1714
1715 /*****************************************************************************/
1716 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) )
1717
1718 #ifndef IRQ_HANDLED
1719 #define irqreturn_t void
1720 #define IRQ_HANDLED
1721 #define IRQ_NONE
1722 #endif
1723
1724 #ifndef IRQF_PROBE_SHARED
1725 #ifdef SA_PROBEIRQ
1726 #define IRQF_PROBE_SHARED SA_PROBEIRQ
1727 #else
1728 #define IRQF_PROBE_SHARED 0
1729 #endif
1730 #endif
1731
1732 #ifndef IRQF_SHARED
1733 #define IRQF_SHARED SA_SHIRQ
1734 #endif
1735
1736 #ifndef ARRAY_SIZE
1737 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
1738 #endif
1739
1740 #ifndef FIELD_SIZEOF
1741 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
1742 #endif
1743
1744 #ifndef skb_is_gso
1745 #ifdef NETIF_F_TSO
1746 #define skb_is_gso _kc_skb_is_gso
1747 static inline int _kc_skb_is_gso(const struct sk_buff *skb)
1748 {
1749         return skb_shinfo(skb)->gso_size;
1750 }
1751 #else
1752 #define skb_is_gso(a) 0
1753 #endif
1754 #endif
1755
1756 #ifndef resource_size_t
1757 #define resource_size_t unsigned long
1758 #endif
1759
1760 #ifdef skb_pad
1761 #undef skb_pad
1762 #endif
1763 #define skb_pad(x,y) _kc_skb_pad(x, y)
1764 int _kc_skb_pad(struct sk_buff *skb, int pad);
1765 #ifdef skb_padto
1766 #undef skb_padto
1767 #endif
1768 #define skb_padto(x,y) _kc_skb_padto(x, y)
1769 static inline int _kc_skb_padto(struct sk_buff *skb, unsigned int len)
1770 {
1771         unsigned int size = skb->len;
1772         if(likely(size >= len))
1773                 return 0;
1774         return _kc_skb_pad(skb, len - size);
1775 }
1776
1777 #ifndef DECLARE_PCI_UNMAP_ADDR
1778 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
1779         dma_addr_t ADDR_NAME
1780 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
1781         u32 LEN_NAME
1782 #define pci_unmap_addr(PTR, ADDR_NAME) \
1783         ((PTR)->ADDR_NAME)
1784 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
1785         (((PTR)->ADDR_NAME) = (VAL))
1786 #define pci_unmap_len(PTR, LEN_NAME) \
1787         ((PTR)->LEN_NAME)
1788 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
1789         (((PTR)->LEN_NAME) = (VAL))
1790 #endif /* DECLARE_PCI_UNMAP_ADDR */
1791 #endif /* < 2.6.18 */
1792
1793 /*****************************************************************************/
1794 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) )
1795
1796 #ifndef DIV_ROUND_UP
1797 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
1798 #endif
1799 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) )
1800 #if (!((RHEL_RELEASE_CODE && \
1801         ((RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,4) && \
1802           RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0)) || \
1803          (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,0)))) || \
1804        (AX_RELEASE_CODE && AX_RELEASE_CODE > AX_RELEASE_VERSION(3,0))))
1805 typedef irqreturn_t (*irq_handler_t)(int, void*, struct pt_regs *);
1806 #endif
1807 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
1808 #undef CONFIG_INET_LRO
1809 #undef CONFIG_INET_LRO_MODULE
1810 #ifdef IXGBE_FCOE
1811 #undef CONFIG_FCOE
1812 #undef CONFIG_FCOE_MODULE
1813 #endif /* IXGBE_FCOE */
1814 #endif
1815 typedef irqreturn_t (*new_handler_t)(int, void*);
1816 static inline irqreturn_t _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1817 #else /* 2.4.x */
1818 typedef void (*irq_handler_t)(int, void*, struct pt_regs *);
1819 typedef void (*new_handler_t)(int, void*);
1820 static inline int _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1821 #endif /* >= 2.5.x */
1822 {
1823         irq_handler_t new_handler = (irq_handler_t) handler;
1824         return request_irq(irq, new_handler, flags, devname, dev_id);
1825 }
1826
1827 #undef request_irq
1828 #define request_irq(irq, handler, flags, devname, dev_id) _kc_request_irq((irq), (handler), (flags), (devname), (dev_id))
1829
1830 #define irq_handler_t new_handler_t
1831 /* pci_restore_state and pci_save_state handles MSI/PCIE from 2.6.19 */
1832 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))
1833 #define PCIE_CONFIG_SPACE_LEN 256
1834 #define PCI_CONFIG_SPACE_LEN 64
1835 #define PCIE_LINK_STATUS 0x12
1836 #define pci_config_space_ich8lan() do {} while(0)
1837 #undef pci_save_state
1838 extern int _kc_pci_save_state(struct pci_dev *);
1839 #define pci_save_state(pdev) _kc_pci_save_state(pdev)
1840 #undef pci_restore_state
1841 extern void _kc_pci_restore_state(struct pci_dev *);
1842 #define pci_restore_state(pdev) _kc_pci_restore_state(pdev)
1843 #endif /* !(RHEL_RELEASE_CODE >= RHEL 5.4) */
1844
1845 #ifdef HAVE_PCI_ERS
1846 #undef free_netdev
1847 extern void _kc_free_netdev(struct net_device *);
1848 #define free_netdev(netdev) _kc_free_netdev(netdev)
1849 #endif
1850 static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
1851 {
1852         return 0;
1853 }
1854 #define pci_disable_pcie_error_reporting(dev) do {} while (0)
1855 #define pci_cleanup_aer_uncorrect_error_status(dev) do {} while (0)
1856
1857 extern void *_kc_kmemdup(const void *src, size_t len, unsigned gfp);
1858 #define kmemdup(src, len, gfp) _kc_kmemdup(src, len, gfp)
1859 #ifndef bool
1860 #define bool _Bool
1861 #define true 1
1862 #define false 0
1863 #endif
1864 #else /* 2.6.19 */
1865 #include <linux/aer.h>
1866 #include <linux/string.h>
1867 #endif /* < 2.6.19 */
1868
1869 /*****************************************************************************/
1870 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) )
1871 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28) )
1872 #undef INIT_WORK
1873 #define INIT_WORK(_work, _func) \
1874 do { \
1875         INIT_LIST_HEAD(&(_work)->entry); \
1876         (_work)->pending = 0; \
1877         (_work)->func = (void (*)(void *))_func; \
1878         (_work)->data = _work; \
1879         init_timer(&(_work)->timer); \
1880 } while (0)
1881 #endif
1882
1883 #ifndef PCI_VDEVICE
1884 #define PCI_VDEVICE(ven, dev)        \
1885         PCI_VENDOR_ID_##ven, (dev),  \
1886         PCI_ANY_ID, PCI_ANY_ID, 0, 0
1887 #endif
1888
1889 #ifndef round_jiffies
1890 #define round_jiffies(x) x
1891 #endif
1892
1893 #define csum_offset csum
1894
1895 #define HAVE_EARLY_VMALLOC_NODE
1896 #define dev_to_node(dev) -1
1897 #undef set_dev_node
1898 /* remove compiler warning with b=b, for unused variable */
1899 #define set_dev_node(a, b) do { (b) = (b); } while(0)
1900
1901 #if (!(RHEL_RELEASE_CODE && \
1902        (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1903          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1904         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,6)))) && \
1905      !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1906 typedef __u16 __bitwise __sum16;
1907 typedef __u32 __bitwise __wsum;
1908 #endif
1909
1910 #if (!(RHEL_RELEASE_CODE && \
1911        (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1912          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1913         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))) && \
1914      !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1915 static inline __wsum csum_unfold(__sum16 n)
1916 {
1917         return (__force __wsum)n;
1918 }
1919 #endif
1920
1921 #else /* < 2.6.20 */
1922 #define HAVE_DEVICE_NUMA_NODE
1923 #endif /* < 2.6.20 */
1924
1925 /*****************************************************************************/
1926 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
1927 #define to_net_dev(class) container_of(class, struct net_device, class_dev)
1928 #define NETDEV_CLASS_DEV
1929 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)))
1930 #define vlan_group_get_device(vg, id) (vg->vlan_devices[id])
1931 #define vlan_group_set_device(vg, id, dev)              \
1932         do {                                            \
1933                 if (vg) vg->vlan_devices[id] = dev;     \
1934         } while (0)
1935 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)) */
1936 #define pci_channel_offline(pdev) (pdev->error_state && \
1937         pdev->error_state != pci_channel_io_normal)
1938 #define pci_request_selected_regions(pdev, bars, name) \
1939         pci_request_regions(pdev, name)
1940 #define pci_release_selected_regions(pdev, bars) pci_release_regions(pdev);
1941 #endif /* < 2.6.21 */
1942
1943 /*****************************************************************************/
1944 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
1945 #define tcp_hdr(skb) (skb->h.th)
1946 #define tcp_hdrlen(skb) (skb->h.th->doff << 2)
1947 #define skb_transport_offset(skb) (skb->h.raw - skb->data)
1948 #define skb_transport_header(skb) (skb->h.raw)
1949 #define ipv6_hdr(skb) (skb->nh.ipv6h)
1950 #define ip_hdr(skb) (skb->nh.iph)
1951 #define skb_network_offset(skb) (skb->nh.raw - skb->data)
1952 #define skb_network_header(skb) (skb->nh.raw)
1953 #define skb_tail_pointer(skb) skb->tail
1954 #define skb_reset_tail_pointer(skb) \
1955         do { \
1956                 skb->tail = skb->data; \
1957         } while (0)
1958 #define skb_copy_to_linear_data(skb, from, len) \
1959                                 memcpy(skb->data, from, len)
1960 #define skb_copy_to_linear_data_offset(skb, offset, from, len) \
1961                                 memcpy(skb->data + offset, from, len)
1962 #define skb_network_header_len(skb) (skb->h.raw - skb->nh.raw)
1963 #define pci_register_driver pci_module_init
1964 #define skb_mac_header(skb) skb->mac.raw
1965
1966 #ifdef NETIF_F_MULTI_QUEUE
1967 #ifndef alloc_etherdev_mq
1968 #define alloc_etherdev_mq(_a, _b) alloc_etherdev(_a)
1969 #endif
1970 #endif /* NETIF_F_MULTI_QUEUE */
1971
1972 #ifndef ETH_FCS_LEN
1973 #define ETH_FCS_LEN 4
1974 #endif
1975 #define cancel_work_sync(x) flush_scheduled_work()
1976 #ifndef udp_hdr
1977 #define udp_hdr _udp_hdr
1978 static inline struct udphdr *_udp_hdr(const struct sk_buff *skb)
1979 {
1980         return (struct udphdr *)skb_transport_header(skb);
1981 }
1982 #endif
1983
1984 #ifdef cpu_to_be16
1985 #undef cpu_to_be16
1986 #endif
1987 #define cpu_to_be16(x) __constant_htons(x)
1988
1989 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)))
1990 enum {
1991         DUMP_PREFIX_NONE,
1992         DUMP_PREFIX_ADDRESS,
1993         DUMP_PREFIX_OFFSET
1994 };
1995 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)) */
1996 #ifndef hex_asc
1997 #define hex_asc(x)      "0123456789abcdef"[x]
1998 #endif
1999 #include <linux/ctype.h>
2000 extern void _kc_print_hex_dump(const char *level, const char *prefix_str,
2001                                int prefix_type, int rowsize, int groupsize,
2002                                const void *buf, size_t len, bool ascii);
2003 #define print_hex_dump(lvl, s, t, r, g, b, l, a) \
2004                 _kc_print_hex_dump(lvl, s, t, r, g, b, l, a)
2005 #else /* 2.6.22 */
2006 #define ETH_TYPE_TRANS_SETS_DEV
2007 #define HAVE_NETDEV_STATS_IN_NETDEV
2008 #endif /* < 2.6.22 */
2009
2010 /*****************************************************************************/
2011 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22) )
2012 #undef SET_MODULE_OWNER
2013 #define SET_MODULE_OWNER(dev) do { } while (0)
2014 #endif /* > 2.6.22 */
2015
2016 /*****************************************************************************/
2017 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) )
2018 #define netif_subqueue_stopped(_a, _b) 0
2019 #ifndef PTR_ALIGN
2020 #define PTR_ALIGN(p, a)         ((typeof(p))ALIGN((unsigned long)(p), (a)))
2021 #endif
2022
2023 #ifndef CONFIG_PM_SLEEP
2024 #define CONFIG_PM_SLEEP CONFIG_PM
2025 #endif
2026
2027 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13) )
2028 #define HAVE_ETHTOOL_GET_PERM_ADDR
2029 #endif /* 2.6.14 through 2.6.22 */
2030 #endif /* < 2.6.23 */
2031
2032 /*****************************************************************************/
2033 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
2034 #ifndef ETH_FLAG_LRO
2035 #define ETH_FLAG_LRO NETIF_F_LRO
2036 #endif
2037
2038 /* if GRO is supported then the napi struct must already exist */
2039 #ifndef NETIF_F_GRO
2040 /* NAPI API changes in 2.6.24 break everything */
2041 struct napi_struct {
2042         /* used to look up the real NAPI polling routine */
2043         int (*poll)(struct napi_struct *, int);
2044         struct net_device *dev;
2045         int weight;
2046 };
2047 #endif
2048
2049 #ifdef NAPI
2050 extern int __kc_adapter_clean(struct net_device *, int *);
2051 extern struct net_device *napi_to_poll_dev(struct napi_struct *napi);
2052 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2053         do { \
2054                 struct napi_struct *__napi = (_napi); \
2055                 struct net_device *poll_dev = napi_to_poll_dev(__napi); \
2056                 poll_dev->poll = &(__kc_adapter_clean); \
2057                 poll_dev->priv = (_napi); \
2058                 poll_dev->weight = (_weight); \
2059                 set_bit(__LINK_STATE_RX_SCHED, &poll_dev->state); \
2060                 set_bit(__LINK_STATE_START, &poll_dev->state);\
2061                 dev_hold(poll_dev); \
2062                 __napi->poll = &(_poll); \
2063                 __napi->weight = (_weight); \
2064                 __napi->dev = (_netdev); \
2065         } while (0)
2066 #define netif_napi_del(_napi) \
2067         do { \
2068                 struct net_device *poll_dev = napi_to_poll_dev(_napi); \
2069                 WARN_ON(!test_bit(__LINK_STATE_RX_SCHED, &poll_dev->state)); \
2070                 dev_put(poll_dev); \
2071                 memset(poll_dev, 0, sizeof(struct net_device));\
2072         } while (0)
2073 #define napi_schedule_prep(_napi) \
2074         (netif_running((_napi)->dev) && netif_rx_schedule_prep(napi_to_poll_dev(_napi)))
2075 #define napi_schedule(_napi) \
2076         do { \
2077                 if (napi_schedule_prep(_napi)) \
2078                         __netif_rx_schedule(napi_to_poll_dev(_napi)); \
2079         } while (0)
2080 #define napi_enable(_napi) netif_poll_enable(napi_to_poll_dev(_napi))
2081 #define napi_disable(_napi) netif_poll_disable(napi_to_poll_dev(_napi))
2082 #define __napi_schedule(_napi) __netif_rx_schedule(napi_to_poll_dev(_napi))
2083 #ifndef NETIF_F_GRO
2084 #define napi_complete(_napi) netif_rx_complete(napi_to_poll_dev(_napi))
2085 #else
2086 #define napi_complete(_napi) \
2087         do { \
2088                 napi_gro_flush(_napi); \
2089                 netif_rx_complete(napi_to_poll_dev(_napi)); \
2090         } while (0)
2091 #endif /* NETIF_F_GRO */
2092 #else /* NAPI */
2093 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2094         do { \
2095                 struct napi_struct *__napi = _napi; \
2096                 _netdev->poll = &(_poll); \
2097                 _netdev->weight = (_weight); \
2098                 __napi->poll = &(_poll); \
2099                 __napi->weight = (_weight); \
2100                 __napi->dev = (_netdev); \
2101         } while (0)
2102 #define netif_napi_del(_a) do {} while (0)
2103 #endif /* NAPI */
2104
2105 #undef dev_get_by_name
2106 #define dev_get_by_name(_a, _b) dev_get_by_name(_b)
2107 #define __netif_subqueue_stopped(_a, _b) netif_subqueue_stopped(_a, _b)
2108 #ifndef DMA_BIT_MASK
2109 #define DMA_BIT_MASK(n) (((n) == 64) ? DMA_64BIT_MASK : ((1ULL<<(n))-1))
2110 #endif
2111
2112 #ifdef NETIF_F_TSO6
2113 #define skb_is_gso_v6 _kc_skb_is_gso_v6
2114 static inline int _kc_skb_is_gso_v6(const struct sk_buff *skb)
2115 {
2116         return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6;
2117 }
2118 #endif /* NETIF_F_TSO6 */
2119
2120 #ifndef KERN_CONT
2121 #define KERN_CONT       ""
2122 #endif
2123 #else /* < 2.6.24 */
2124 #define HAVE_ETHTOOL_GET_SSET_COUNT
2125 #define HAVE_NETDEV_NAPI_LIST
2126 #endif /* < 2.6.24 */
2127
2128 /*****************************************************************************/
2129 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) )
2130 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2131 #include <linux/pm_qos_params.h>
2132 #else /* >= 3.2.0 */
2133 #include <linux/pm_qos.h>
2134 #endif /* else >= 3.2.0 */
2135 #endif /* > 2.6.24 */
2136
2137 /*****************************************************************************/
2138 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) )
2139 #define PM_QOS_CPU_DMA_LATENCY  1
2140
2141 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18) )
2142 #include <linux/latency.h>
2143 #define PM_QOS_DEFAULT_VALUE    INFINITE_LATENCY
2144 #define pm_qos_add_requirement(pm_qos_class, name, value) \
2145                 set_acceptable_latency(name, value)
2146 #define pm_qos_remove_requirement(pm_qos_class, name) \
2147                 remove_acceptable_latency(name)
2148 #define pm_qos_update_requirement(pm_qos_class, name, value) \
2149                 modify_acceptable_latency(name, value)
2150 #else
2151 #define PM_QOS_DEFAULT_VALUE    -1
2152 #define pm_qos_add_requirement(pm_qos_class, name, value)
2153 #define pm_qos_remove_requirement(pm_qos_class, name)
2154 #define pm_qos_update_requirement(pm_qos_class, name, value) { \
2155         if (value != PM_QOS_DEFAULT_VALUE) { \
2156                 printk(KERN_WARNING "%s: unable to set PM QoS requirement\n", \
2157                         pci_name(adapter->pdev)); \
2158         } \
2159 }
2160
2161 #endif /* > 2.6.18 */
2162
2163 #define pci_enable_device_mem(pdev) pci_enable_device(pdev)
2164
2165 #ifndef DEFINE_PCI_DEVICE_TABLE
2166 #define DEFINE_PCI_DEVICE_TABLE(_table) struct pci_device_id _table[]
2167 #endif /* DEFINE_PCI_DEVICE_TABLE */
2168
2169
2170 #ifndef IGB_PROCFS
2171 #define IGB_PROCFS
2172 #endif /* IGB_PROCFS */
2173
2174 #else /* < 2.6.25 */
2175
2176
2177 #ifndef IGB_SYSFS
2178 #define IGB_SYSFS
2179 #endif /* IGB_SYSFS */
2180
2181 #endif /* < 2.6.25 */
2182
2183 /*****************************************************************************/
2184 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) )
2185 #ifndef clamp_t
2186 #define clamp_t(type, val, min, max) ({         \
2187         type __val = (val);                     \
2188         type __min = (min);                     \
2189         type __max = (max);                     \
2190         __val = __val < __min ? __min : __val;  \
2191         __val > __max ? __max : __val; })
2192 #endif /* clamp_t */
2193 #undef kzalloc_node
2194 #define kzalloc_node(_size, _flags, _node) kzalloc(_size, _flags)
2195
2196 extern void _kc_pci_disable_link_state(struct pci_dev *dev, int state);
2197 #define pci_disable_link_state(p, s) _kc_pci_disable_link_state(p, s)
2198 #else /* < 2.6.26 */
2199 #include <linux/pci-aspm.h>
2200 #define HAVE_NETDEV_VLAN_FEATURES
2201 #endif /* < 2.6.26 */
2202 /*****************************************************************************/
2203 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) )
2204 static inline void _kc_ethtool_cmd_speed_set(struct ethtool_cmd *ep,
2205                                              __u32 speed)
2206 {
2207         ep->speed = (__u16)speed;
2208         /* ep->speed_hi = (__u16)(speed >> 16); */
2209 }
2210 #define ethtool_cmd_speed_set _kc_ethtool_cmd_speed_set
2211
2212 static inline __u32 _kc_ethtool_cmd_speed(struct ethtool_cmd *ep)
2213 {
2214         /* no speed_hi before 2.6.27, and probably no need for it yet */
2215         return (__u32)ep->speed;
2216 }
2217 #define ethtool_cmd_speed _kc_ethtool_cmd_speed
2218
2219 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) )
2220 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)) && defined(CONFIG_PM))
2221 #define ANCIENT_PM 1
2222 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) && \
2223        (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) && \
2224        defined(CONFIG_PM_SLEEP))
2225 #define NEWER_PM 1
2226 #endif
2227 #if defined(ANCIENT_PM) || defined(NEWER_PM)
2228 #undef device_set_wakeup_enable
2229 #define device_set_wakeup_enable(dev, val) \
2230         do { \
2231                 u16 pmc = 0; \
2232                 int pm = pci_find_capability(adapter->pdev, PCI_CAP_ID_PM); \
2233                 if (pm) { \
2234                         pci_read_config_word(adapter->pdev, pm + PCI_PM_PMC, \
2235                                 &pmc); \
2236                 } \
2237                 (dev)->power.can_wakeup = !!(pmc >> 11); \
2238                 (dev)->power.should_wakeup = (val && (pmc >> 11)); \
2239         } while (0)
2240 #endif /* 2.6.15-2.6.22 and CONFIG_PM or 2.6.23-2.6.25 and CONFIG_PM_SLEEP */
2241 #endif /* 2.6.15 through 2.6.27 */
2242 #ifndef netif_napi_del
2243 #define netif_napi_del(_a) do {} while (0)
2244 #ifdef NAPI
2245 #ifdef CONFIG_NETPOLL
2246 #undef netif_napi_del
2247 #define netif_napi_del(_a) list_del(&(_a)->dev_list);
2248 #endif
2249 #endif
2250 #endif /* netif_napi_del */
2251 #ifdef dma_mapping_error
2252 #undef dma_mapping_error
2253 #endif
2254 #define dma_mapping_error(dev, dma_addr) pci_dma_mapping_error(dma_addr)
2255
2256 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2257 #define HAVE_TX_MQ
2258 #endif
2259
2260 #ifdef HAVE_TX_MQ
2261 extern void _kc_netif_tx_stop_all_queues(struct net_device *);
2262 extern void _kc_netif_tx_wake_all_queues(struct net_device *);
2263 extern void _kc_netif_tx_start_all_queues(struct net_device *);
2264 #define netif_tx_stop_all_queues(a) _kc_netif_tx_stop_all_queues(a)
2265 #define netif_tx_wake_all_queues(a) _kc_netif_tx_wake_all_queues(a)
2266 #define netif_tx_start_all_queues(a) _kc_netif_tx_start_all_queues(a)
2267 #undef netif_stop_subqueue
2268 #define netif_stop_subqueue(_ndev,_qi) do { \
2269         if (netif_is_multiqueue((_ndev))) \
2270                 netif_stop_subqueue((_ndev), (_qi)); \
2271         else \
2272                 netif_stop_queue((_ndev)); \
2273         } while (0)
2274 #undef netif_start_subqueue
2275 #define netif_start_subqueue(_ndev,_qi) do { \
2276         if (netif_is_multiqueue((_ndev))) \
2277                 netif_start_subqueue((_ndev), (_qi)); \
2278         else \
2279                 netif_start_queue((_ndev)); \
2280         } while (0)
2281 #else /* HAVE_TX_MQ */
2282 #define netif_tx_stop_all_queues(a) netif_stop_queue(a)
2283 #define netif_tx_wake_all_queues(a) netif_wake_queue(a)
2284 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) )
2285 #define netif_tx_start_all_queues(a) netif_start_queue(a)
2286 #else
2287 #define netif_tx_start_all_queues(a) do {} while (0)
2288 #endif
2289 #define netif_stop_subqueue(_ndev,_qi) netif_stop_queue((_ndev))
2290 #define netif_start_subqueue(_ndev,_qi) netif_start_queue((_ndev))
2291 #endif /* HAVE_TX_MQ */
2292 #ifndef NETIF_F_MULTI_QUEUE
2293 #define NETIF_F_MULTI_QUEUE 0
2294 #define netif_is_multiqueue(a) 0
2295 #define netif_wake_subqueue(a, b)
2296 #endif /* NETIF_F_MULTI_QUEUE */
2297
2298 #ifndef __WARN_printf
2299 extern void __kc_warn_slowpath(const char *file, const int line,
2300                 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
2301 #define __WARN_printf(arg...) __kc_warn_slowpath(__FILE__, __LINE__, arg)
2302 #endif /* __WARN_printf */
2303
2304 #ifndef WARN
2305 #define WARN(condition, format...) ({                                           \
2306         int __ret_warn_on = !!(condition);                              \
2307         if (unlikely(__ret_warn_on))                                    \
2308                 __WARN_printf(format);                                  \
2309         unlikely(__ret_warn_on);                                        \
2310 })
2311 #endif /* WARN */
2312 #else /* < 2.6.27 */
2313 #define HAVE_TX_MQ
2314 #define HAVE_NETDEV_SELECT_QUEUE
2315 #endif /* < 2.6.27 */
2316
2317 /*****************************************************************************/
2318 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) )
2319 #define pci_ioremap_bar(pdev, bar)      ioremap(pci_resource_start(pdev, bar), \
2320                                                 pci_resource_len(pdev, bar))
2321 #define pci_wake_from_d3 _kc_pci_wake_from_d3
2322 #define pci_prepare_to_sleep _kc_pci_prepare_to_sleep
2323 extern int _kc_pci_wake_from_d3(struct pci_dev *dev, bool enable);
2324 extern int _kc_pci_prepare_to_sleep(struct pci_dev *dev);
2325 #define netdev_alloc_page(a) alloc_page(GFP_ATOMIC)
2326 #ifndef __skb_queue_head_init
2327 static inline void __kc_skb_queue_head_init(struct sk_buff_head *list)
2328 {
2329         list->prev = list->next = (struct sk_buff *)list;
2330         list->qlen = 0;
2331 }
2332 #define __skb_queue_head_init(_q) __kc_skb_queue_head_init(_q)
2333 #endif
2334 #ifndef skb_add_rx_frag
2335 #define skb_add_rx_frag _kc_skb_add_rx_frag
2336 extern void _kc_skb_add_rx_frag(struct sk_buff *, int, struct page *, int, int);
2337 #endif
2338 #endif /* < 2.6.28 */
2339
2340 /*****************************************************************************/
2341 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) )
2342 #ifndef swap
2343 #define swap(a, b) \
2344         do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
2345 #endif
2346 #define pci_request_selected_regions_exclusive(pdev, bars, name) \
2347                 pci_request_selected_regions(pdev, bars, name)
2348 #ifndef CONFIG_NR_CPUS
2349 #define CONFIG_NR_CPUS 1
2350 #endif /* CONFIG_NR_CPUS */
2351 #ifndef pcie_aspm_enabled
2352 #define pcie_aspm_enabled()   (1)
2353 #endif /* pcie_aspm_enabled */
2354 #else /* < 2.6.29 */
2355 #ifndef HAVE_NET_DEVICE_OPS
2356 #define HAVE_NET_DEVICE_OPS
2357 #endif
2358 #ifdef CONFIG_DCB
2359 #define HAVE_PFC_MODE_ENABLE
2360 #endif /* CONFIG_DCB */
2361 #endif /* < 2.6.29 */
2362
2363 /*****************************************************************************/
2364 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) )
2365 #define skb_rx_queue_recorded(a) false
2366 #define skb_get_rx_queue(a) 0
2367 #define skb_record_rx_queue(a, b) do {} while (0)
2368 #define skb_tx_hash(n, s) ___kc_skb_tx_hash((n), (s), (n)->real_num_tx_queues)
2369 #ifdef IXGBE_FCOE
2370 #undef CONFIG_FCOE
2371 #undef CONFIG_FCOE_MODULE
2372 #endif /* IXGBE_FCOE */
2373 #ifndef CONFIG_PCI_IOV
2374 #undef pci_enable_sriov
2375 #define pci_enable_sriov(a, b) -ENOTSUPP
2376 #undef pci_disable_sriov
2377 #define pci_disable_sriov(a) do {} while (0)
2378 #endif /* CONFIG_PCI_IOV */
2379 #ifndef pr_cont
2380 #define pr_cont(fmt, ...) \
2381         printk(KERN_CONT fmt, ##__VA_ARGS__)
2382 #endif /* pr_cont */
2383 #else
2384 #define HAVE_ASPM_QUIRKS
2385 #endif /* < 2.6.30 */
2386
2387 /*****************************************************************************/
2388 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) )
2389 #define ETH_P_1588 0x88F7
2390 #define ETH_P_FIP  0x8914
2391 #ifndef netdev_uc_count
2392 #define netdev_uc_count(dev) ((dev)->uc_count)
2393 #endif
2394 #ifndef netdev_for_each_uc_addr
2395 #define netdev_for_each_uc_addr(uclist, dev) \
2396         for (uclist = dev->uc_list; uclist; uclist = uclist->next)
2397 #endif
2398 #else
2399 #ifndef HAVE_NETDEV_STORAGE_ADDRESS
2400 #define HAVE_NETDEV_STORAGE_ADDRESS
2401 #endif
2402 #ifndef HAVE_NETDEV_HW_ADDR
2403 #define HAVE_NETDEV_HW_ADDR
2404 #endif
2405 #ifndef HAVE_TRANS_START_IN_QUEUE
2406 #define HAVE_TRANS_START_IN_QUEUE
2407 #endif
2408 #endif /* < 2.6.31 */
2409
2410 /*****************************************************************************/
2411 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) )
2412 #undef netdev_tx_t
2413 #define netdev_tx_t int
2414 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2415 #ifndef NETIF_F_FCOE_MTU
2416 #define NETIF_F_FCOE_MTU       (1 << 26)
2417 #endif
2418 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2419
2420 #ifndef pm_runtime_get_sync
2421 #define pm_runtime_get_sync(dev)        do {} while (0)
2422 #endif
2423 #ifndef pm_runtime_put
2424 #define pm_runtime_put(dev)             do {} while (0)
2425 #endif
2426 #ifndef pm_runtime_put_sync
2427 #define pm_runtime_put_sync(dev)        do {} while (0)
2428 #endif
2429 #ifndef pm_runtime_resume
2430 #define pm_runtime_resume(dev)          do {} while (0)
2431 #endif
2432 #ifndef pm_schedule_suspend
2433 #define pm_schedule_suspend(dev, t)     do {} while (0)
2434 #endif
2435 #ifndef pm_runtime_set_suspended
2436 #define pm_runtime_set_suspended(dev)   do {} while (0)
2437 #endif
2438 #ifndef pm_runtime_disable
2439 #define pm_runtime_disable(dev)         do {} while (0)
2440 #endif
2441 #ifndef pm_runtime_put_noidle
2442 #define pm_runtime_put_noidle(dev)      do {} while (0)
2443 #endif
2444 #ifndef pm_runtime_set_active
2445 #define pm_runtime_set_active(dev)      do {} while (0)
2446 #endif
2447 #ifndef pm_runtime_enable
2448 #define pm_runtime_enable(dev)  do {} while (0)
2449 #endif
2450 #ifndef pm_runtime_get_noresume
2451 #define pm_runtime_get_noresume(dev)    do {} while (0)
2452 #endif
2453 #else /* < 2.6.32 */
2454 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2455 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2456 #define HAVE_NETDEV_OPS_FCOE_ENABLE
2457 #endif
2458 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2459 #ifdef CONFIG_DCB
2460 #ifndef HAVE_DCBNL_OPS_GETAPP
2461 #define HAVE_DCBNL_OPS_GETAPP
2462 #endif
2463 #endif /* CONFIG_DCB */
2464 #include <linux/pm_runtime.h>
2465 /* IOV bad DMA target work arounds require at least this kernel rev support */
2466 #define HAVE_PCIE_TYPE
2467 #endif /* < 2.6.32 */
2468
2469 /*****************************************************************************/
2470 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) )
2471 #ifndef pci_pcie_cap
2472 #define pci_pcie_cap(pdev) pci_find_capability(pdev, PCI_CAP_ID_EXP)
2473 #endif
2474 #ifndef IPV4_FLOW
2475 #define IPV4_FLOW 0x10
2476 #endif /* IPV4_FLOW */
2477 #ifndef IPV6_FLOW
2478 #define IPV6_FLOW 0x11
2479 #endif /* IPV6_FLOW */
2480 /* Features back-ported to RHEL6 or SLES11 SP1 after 2.6.32 */
2481 #if ( (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)) || \
2482       (SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,1,0)) )
2483 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2484 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2485 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2486 #endif
2487 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2488 #endif /* RHEL6 or SLES11 SP1 */
2489 #ifndef __percpu
2490 #define __percpu
2491 #endif /* __percpu */
2492 #else /* < 2.6.33 */
2493 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2494 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2495 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2496 #endif
2497 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2498 #define HAVE_ETHTOOL_SFP_DISPLAY_PORT
2499 #endif /* < 2.6.33 */
2500
2501 /*****************************************************************************/
2502 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) )
2503 #ifndef ETH_FLAG_NTUPLE
2504 #define ETH_FLAG_NTUPLE NETIF_F_NTUPLE
2505 #endif
2506
2507 #ifndef netdev_mc_count
2508 #define netdev_mc_count(dev) ((dev)->mc_count)
2509 #endif
2510 #ifndef netdev_mc_empty
2511 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
2512 #endif
2513 #ifndef netdev_for_each_mc_addr
2514 #define netdev_for_each_mc_addr(mclist, dev) \
2515         for (mclist = dev->mc_list; mclist; mclist = mclist->next)
2516 #endif
2517 #ifndef netdev_uc_count
2518 #define netdev_uc_count(dev) ((dev)->uc.count)
2519 #endif
2520 #ifndef netdev_uc_empty
2521 #define netdev_uc_empty(dev) (netdev_uc_count(dev) == 0)
2522 #endif
2523 #ifndef netdev_for_each_uc_addr
2524 #define netdev_for_each_uc_addr(ha, dev) \
2525         list_for_each_entry(ha, &dev->uc.list, list)
2526 #endif
2527 #ifndef dma_set_coherent_mask
2528 #define dma_set_coherent_mask(dev,mask) \
2529         pci_set_consistent_dma_mask(to_pci_dev(dev),(mask))
2530 #endif
2531 #ifndef pci_dev_run_wake
2532 #define pci_dev_run_wake(pdev)  (0)
2533 #endif
2534
2535 /* netdev logging taken from include/linux/netdevice.h */
2536 #ifndef netdev_name
2537 static inline const char *_kc_netdev_name(const struct net_device *dev)
2538 {
2539         if (dev->reg_state != NETREG_REGISTERED)
2540                 return "(unregistered net_device)";
2541         return dev->name;
2542 }
2543 #define netdev_name(netdev)     _kc_netdev_name(netdev)
2544 #endif /* netdev_name */
2545
2546 #undef netdev_printk
2547 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
2548 #define netdev_printk(level, netdev, format, args...)           \
2549 do {                                                            \
2550         struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2551         struct pci_dev *pdev = kc_adapter->pdev;                \
2552         printk("%s %s: " format, level, pci_name(pdev),         \
2553                ##args);                                         \
2554 } while(0)
2555 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
2556 #define netdev_printk(level, netdev, format, args...)           \
2557 do {                                                            \
2558         struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2559         struct pci_dev *pdev = kc_adapter->pdev;                \
2560         struct device *dev = pci_dev_to_dev(pdev);              \
2561         dev_printk(level, dev, "%s: " format,                   \
2562                    netdev_name(netdev), ##args);                \
2563 } while(0)
2564 #else /* 2.6.21 => 2.6.34 */
2565 #define netdev_printk(level, netdev, format, args...)           \
2566         dev_printk(level, (netdev)->dev.parent,                 \
2567                    "%s: " format,                               \
2568                    netdev_name(netdev), ##args)
2569 #endif /* <2.6.0 <2.6.21 <2.6.34 */
2570 #undef netdev_emerg
2571 #define netdev_emerg(dev, format, args...)                      \
2572         netdev_printk(KERN_EMERG, dev, format, ##args)
2573 #undef netdev_alert
2574 #define netdev_alert(dev, format, args...)                      \
2575         netdev_printk(KERN_ALERT, dev, format, ##args)
2576 #undef netdev_crit
2577 #define netdev_crit(dev, format, args...)                       \
2578         netdev_printk(KERN_CRIT, dev, format, ##args)
2579 #undef netdev_err
2580 #define netdev_err(dev, format, args...)                        \
2581         netdev_printk(KERN_ERR, dev, format, ##args)
2582 #undef netdev_warn
2583 #define netdev_warn(dev, format, args...)                       \
2584         netdev_printk(KERN_WARNING, dev, format, ##args)
2585 #undef netdev_notice
2586 #define netdev_notice(dev, format, args...)                     \
2587         netdev_printk(KERN_NOTICE, dev, format, ##args)
2588 #undef netdev_info
2589 #define netdev_info(dev, format, args...)                       \
2590         netdev_printk(KERN_INFO, dev, format, ##args)
2591 #undef netdev_dbg
2592 #if   defined(CONFIG_DYNAMIC_DEBUG)
2593 #define netdev_dbg(__dev, format, args...)                      \
2594 do {                                                            \
2595         dynamic_dev_dbg((__dev)->dev.parent, "%s: " format,     \
2596                         netdev_name(__dev), ##args);            \
2597 } while (0)
2598 #else /* DEBUG */
2599 #define netdev_dbg(__dev, format, args...)                      \
2600 ({                                                              \
2601         if (0)                                                  \
2602                 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
2603         0;                                                      \
2604 })
2605 #endif /* DEBUG */
2606
2607 #undef netif_printk
2608 #define netif_printk(priv, type, level, dev, fmt, args...)      \
2609 do {                                                            \
2610         if (netif_msg_##type(priv))                             \
2611                 netdev_printk(level, (dev), fmt, ##args);       \
2612 } while (0)
2613
2614 #undef netif_emerg
2615 #define netif_emerg(priv, type, dev, fmt, args...)              \
2616         netif_level(emerg, priv, type, dev, fmt, ##args)
2617 #undef netif_alert
2618 #define netif_alert(priv, type, dev, fmt, args...)              \
2619         netif_level(alert, priv, type, dev, fmt, ##args)
2620 #undef netif_crit
2621 #define netif_crit(priv, type, dev, fmt, args...)               \
2622         netif_level(crit, priv, type, dev, fmt, ##args)
2623 #undef netif_err
2624 #define netif_err(priv, type, dev, fmt, args...)                \
2625         netif_level(err, priv, type, dev, fmt, ##args)
2626 #undef netif_warn
2627 #define netif_warn(priv, type, dev, fmt, args...)               \
2628         netif_level(warn, priv, type, dev, fmt, ##args)
2629 #undef netif_notice
2630 #define netif_notice(priv, type, dev, fmt, args...)             \
2631         netif_level(notice, priv, type, dev, fmt, ##args)
2632 #undef netif_info
2633 #define netif_info(priv, type, dev, fmt, args...)               \
2634         netif_level(info, priv, type, dev, fmt, ##args)
2635
2636 #ifdef SET_SYSTEM_SLEEP_PM_OPS
2637 #define HAVE_SYSTEM_SLEEP_PM_OPS
2638 #endif
2639
2640 #ifndef for_each_set_bit
2641 #define for_each_set_bit(bit, addr, size) \
2642         for ((bit) = find_first_bit((addr), (size)); \
2643                 (bit) < (size); \
2644                 (bit) = find_next_bit((addr), (size), (bit) + 1))
2645 #endif /* for_each_set_bit */
2646
2647 #ifndef DEFINE_DMA_UNMAP_ADDR
2648 #define DEFINE_DMA_UNMAP_ADDR DECLARE_PCI_UNMAP_ADDR 
2649 #define DEFINE_DMA_UNMAP_LEN DECLARE_PCI_UNMAP_LEN
2650 #define dma_unmap_addr pci_unmap_addr
2651 #define dma_unmap_addr_set pci_unmap_addr_set
2652 #define dma_unmap_len pci_unmap_len
2653 #define dma_unmap_len_set pci_unmap_len_set
2654 #endif /* DEFINE_DMA_UNMAP_ADDR */
2655 #else /* < 2.6.34 */
2656 #define HAVE_SYSTEM_SLEEP_PM_OPS
2657 #ifndef HAVE_SET_RX_MODE
2658 #define HAVE_SET_RX_MODE
2659 #endif
2660
2661 #endif /* < 2.6.34 */
2662
2663 /*****************************************************************************/
2664 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) )
2665 #ifndef numa_node_id
2666 #define numa_node_id() 0
2667 #endif
2668 #ifdef HAVE_TX_MQ
2669 #include <net/sch_generic.h>
2670 #ifndef CONFIG_NETDEVICES_MULTIQUEUE
2671 void _kc_netif_set_real_num_tx_queues(struct net_device *, unsigned int);
2672 #define netif_set_real_num_tx_queues  _kc_netif_set_real_num_tx_queues
2673 #else /* CONFIG_NETDEVICES_MULTI_QUEUE */
2674 #define netif_set_real_num_tx_queues(_netdev, _count) \
2675         do { \
2676                 (_netdev)->egress_subqueue_count = _count; \
2677         } while (0)
2678 #endif /* CONFIG_NETDEVICES_MULTI_QUEUE */
2679 #else
2680 #define netif_set_real_num_tx_queues(_netdev, _count) do {} while(0)
2681 #endif /* HAVE_TX_MQ */
2682 #ifndef ETH_FLAG_RXHASH
2683 #define ETH_FLAG_RXHASH (1<<28)
2684 #endif /* ETH_FLAG_RXHASH */
2685 #else /* < 2.6.35 */
2686 #define HAVE_PM_QOS_REQUEST_LIST
2687 #define HAVE_IRQ_AFFINITY_HINT
2688 #endif /* < 2.6.35 */
2689
2690 /*****************************************************************************/
2691 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) )
2692 extern int _kc_ethtool_op_set_flags(struct net_device *, u32, u32);
2693 #define ethtool_op_set_flags _kc_ethtool_op_set_flags
2694 extern u32 _kc_ethtool_op_get_flags(struct net_device *);
2695 #define ethtool_op_get_flags _kc_ethtool_op_get_flags
2696
2697 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2698 #ifdef NET_IP_ALIGN
2699 #undef NET_IP_ALIGN
2700 #endif
2701 #define NET_IP_ALIGN 0
2702 #endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
2703
2704 #ifdef NET_SKB_PAD
2705 #undef NET_SKB_PAD
2706 #endif
2707
2708 #if (L1_CACHE_BYTES > 32)
2709 #define NET_SKB_PAD L1_CACHE_BYTES
2710 #else
2711 #define NET_SKB_PAD 32
2712 #endif
2713
2714 static inline struct sk_buff *_kc_netdev_alloc_skb_ip_align(struct net_device *dev,
2715                                                             unsigned int length)
2716 {
2717         struct sk_buff *skb;
2718
2719         skb = alloc_skb(length + NET_SKB_PAD + NET_IP_ALIGN, GFP_ATOMIC);
2720         if (skb) {
2721 #if (NET_IP_ALIGN + NET_SKB_PAD)
2722                 skb_reserve(skb, NET_IP_ALIGN + NET_SKB_PAD);
2723 #endif
2724                 skb->dev = dev;
2725         }
2726         return skb;
2727 }
2728
2729 #ifdef netdev_alloc_skb_ip_align
2730 #undef netdev_alloc_skb_ip_align
2731 #endif
2732 #define netdev_alloc_skb_ip_align(n, l) _kc_netdev_alloc_skb_ip_align(n, l)
2733
2734 #undef netif_level
2735 #define netif_level(level, priv, type, dev, fmt, args...)       \
2736 do {                                                            \
2737         if (netif_msg_##type(priv))                             \
2738                 netdev_##level(dev, fmt, ##args);               \
2739 } while (0)
2740
2741 #undef usleep_range
2742 #define usleep_range(min, max)  msleep(DIV_ROUND_UP(min, 1000)) 
2743
2744 #else /* < 2.6.36 */
2745 #define HAVE_PM_QOS_REQUEST_ACTIVE
2746 #define HAVE_8021P_SUPPORT
2747 #define HAVE_NDO_GET_STATS64
2748 #endif /* < 2.6.36 */
2749
2750 /*****************************************************************************/
2751 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) )
2752 #ifndef ETHTOOL_RXNTUPLE_ACTION_CLEAR
2753 #define ETHTOOL_RXNTUPLE_ACTION_CLEAR (-2)
2754 #endif
2755 #ifndef VLAN_N_VID
2756 #define VLAN_N_VID      VLAN_GROUP_ARRAY_LEN
2757 #endif /* VLAN_N_VID */
2758 #ifndef ETH_FLAG_TXVLAN
2759 #define ETH_FLAG_TXVLAN (1 << 7)
2760 #endif /* ETH_FLAG_TXVLAN */
2761 #ifndef ETH_FLAG_RXVLAN
2762 #define ETH_FLAG_RXVLAN (1 << 8)
2763 #endif /* ETH_FLAG_RXVLAN */
2764
2765 static inline void _kc_skb_checksum_none_assert(struct sk_buff *skb)
2766 {
2767         WARN_ON(skb->ip_summed != CHECKSUM_NONE);
2768 }
2769 #define skb_checksum_none_assert(skb) _kc_skb_checksum_none_assert(skb)
2770
2771 static inline void *_kc_vzalloc_node(unsigned long size, int node)
2772 {
2773         void *addr = vmalloc_node(size, node);
2774         if (addr)
2775                 memset(addr, 0, size);
2776         return addr;
2777 }
2778 #define vzalloc_node(_size, _node) _kc_vzalloc_node(_size, _node)
2779
2780 static inline void *_kc_vzalloc(unsigned long size)
2781 {
2782         void *addr = vmalloc(size);
2783         if (addr)
2784                 memset(addr, 0, size);
2785         return addr;
2786 }
2787 #define vzalloc(_size) _kc_vzalloc(_size)
2788
2789 #ifndef vlan_get_protocol
2790 static inline __be16 __kc_vlan_get_protocol(const struct sk_buff *skb)
2791 {
2792         if (vlan_tx_tag_present(skb) ||
2793             skb->protocol != cpu_to_be16(ETH_P_8021Q))
2794                 return skb->protocol;
2795
2796         if (skb_headlen(skb) < sizeof(struct vlan_ethhdr))
2797                 return 0;
2798
2799         return ((struct vlan_ethhdr*)skb->data)->h_vlan_encapsulated_proto;
2800 }
2801 #define vlan_get_protocol(_skb) __kc_vlan_get_protocol(_skb)
2802 #endif
2803 #ifdef HAVE_HW_TIME_STAMP
2804 #define SKBTX_HW_TSTAMP (1 << 0)
2805 #define SKBTX_IN_PROGRESS (1 << 2)
2806 #define SKB_SHARED_TX_IS_UNION
2807 #endif
2808 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,18) )
2809 #ifndef HAVE_VLAN_RX_REGISTER
2810 #define HAVE_VLAN_RX_REGISTER
2811 #endif
2812 #endif /* > 2.4.18 */
2813 #endif /* < 2.6.37 */
2814
2815 /*****************************************************************************/
2816 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) )
2817 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
2818 #define skb_checksum_start_offset(skb) skb_transport_offset(skb)
2819 #else /* 2.6.22 -> 2.6.37 */
2820 static inline int _kc_skb_checksum_start_offset(const struct sk_buff *skb)
2821 {
2822         return skb->csum_start - skb_headroom(skb);
2823 }
2824 #define skb_checksum_start_offset(skb) _kc_skb_checksum_start_offset(skb)
2825 #endif /* 2.6.22 -> 2.6.37 */
2826 #ifdef CONFIG_DCB
2827 #ifndef IEEE_8021QAZ_MAX_TCS
2828 #define IEEE_8021QAZ_MAX_TCS 8
2829 #endif
2830 #ifndef DCB_CAP_DCBX_HOST
2831 #define DCB_CAP_DCBX_HOST               0x01
2832 #endif
2833 #ifndef DCB_CAP_DCBX_LLD_MANAGED
2834 #define DCB_CAP_DCBX_LLD_MANAGED        0x02
2835 #endif
2836 #ifndef DCB_CAP_DCBX_VER_CEE
2837 #define DCB_CAP_DCBX_VER_CEE            0x04
2838 #endif
2839 #ifndef DCB_CAP_DCBX_VER_IEEE
2840 #define DCB_CAP_DCBX_VER_IEEE           0x08
2841 #endif
2842 #ifndef DCB_CAP_DCBX_STATIC
2843 #define DCB_CAP_DCBX_STATIC             0x10
2844 #endif
2845 #endif /* CONFIG_DCB */
2846 extern u16 ___kc_skb_tx_hash(struct net_device *, const struct sk_buff *, u16);
2847 #define __skb_tx_hash(n, s, q) ___kc_skb_tx_hash((n), (s), (q))
2848 #else /* < 2.6.38 */
2849 #endif /* < 2.6.38 */
2850
2851 /*****************************************************************************/
2852 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) )
2853 #ifndef skb_queue_reverse_walk_safe
2854 #define skb_queue_reverse_walk_safe(queue, skb, tmp)                            \
2855                 for (skb = (queue)->prev, tmp = skb->prev;                      \
2856                      skb != (struct sk_buff *)(queue);                          \
2857                      skb = tmp, tmp = skb->prev)
2858 #endif
2859 #else /* < 2.6.39 */
2860 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2861 #ifndef HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2862 #define HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2863 #endif
2864 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2865 #ifndef HAVE_MQPRIO
2866 #define HAVE_MQPRIO
2867 #endif
2868 #ifndef HAVE_SETUP_TC
2869 #define HAVE_SETUP_TC
2870 #endif
2871 #ifdef CONFIG_DCB
2872 #ifndef HAVE_DCBNL_IEEE
2873 #define HAVE_DCBNL_IEEE
2874 #endif
2875 #endif /* CONFIG_DCB */
2876 #ifndef HAVE_NDO_SET_FEATURES
2877 #define HAVE_NDO_SET_FEATURES
2878 #endif
2879 #endif /* < 2.6.39 */
2880
2881 /*****************************************************************************/
2882 /* use < 2.6.40 because of a Fedora 15 kernel update where they
2883  * updated the kernel version to 2.6.40.x and they back-ported 3.0 features
2884  * like set_phys_id for ethtool.
2885  */ 
2886 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40) )
2887 #ifdef ETHTOOL_GRXRINGS
2888 #ifndef FLOW_EXT
2889 #define FLOW_EXT        0x80000000
2890 union _kc_ethtool_flow_union {
2891         struct ethtool_tcpip4_spec              tcp_ip4_spec;
2892         struct ethtool_usrip4_spec              usr_ip4_spec;
2893         __u8                                    hdata[60];
2894 };
2895 struct _kc_ethtool_flow_ext {
2896         __be16  vlan_etype;
2897         __be16  vlan_tci;
2898         __be32  data[2];
2899 };
2900 struct _kc_ethtool_rx_flow_spec {
2901         __u32           flow_type;
2902         union _kc_ethtool_flow_union h_u;
2903         struct _kc_ethtool_flow_ext h_ext;
2904         union _kc_ethtool_flow_union m_u;
2905         struct _kc_ethtool_flow_ext m_ext;
2906         __u64           ring_cookie;
2907         __u32           location;
2908 };
2909 #define ethtool_rx_flow_spec _kc_ethtool_rx_flow_spec
2910 #endif /* FLOW_EXT */
2911 #endif
2912
2913 #define pci_disable_link_state_locked pci_disable_link_state
2914
2915 #ifndef PCI_LTR_VALUE_MASK
2916 #define  PCI_LTR_VALUE_MASK     0x000003ff
2917 #endif
2918 #ifndef PCI_LTR_SCALE_MASK
2919 #define  PCI_LTR_SCALE_MASK     0x00001c00
2920 #endif
2921 #ifndef PCI_LTR_SCALE_SHIFT
2922 #define  PCI_LTR_SCALE_SHIFT    10
2923 #endif
2924
2925 #else /* < 2.6.40 */
2926 #define HAVE_ETHTOOL_SET_PHYS_ID
2927 #endif /* < 2.6.40 */
2928
2929 /*****************************************************************************/
2930 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
2931 #ifndef __netdev_alloc_skb_ip_align
2932 #define __netdev_alloc_skb_ip_align(d,l,_g) netdev_alloc_skb_ip_align(d,l)
2933 #endif /* __netdev_alloc_skb_ip_align */
2934 #define dcb_ieee_setapp(dev, app) dcb_setapp(dev, app)
2935 #define dcb_ieee_delapp(dev, app) 0
2936 #define dcb_ieee_getapp_mask(dev, app) (1 << app->priority)
2937 #else /* < 3.1.0 */
2938 #ifndef HAVE_DCBNL_IEEE_DELAPP
2939 #define HAVE_DCBNL_IEEE_DELAPP
2940 #endif
2941 #endif /* < 3.1.0 */
2942
2943 /*****************************************************************************/
2944 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2945 #ifdef ETHTOOL_GRXRINGS
2946 #define HAVE_ETHTOOL_GET_RXNFC_VOID_RULE_LOCS
2947 #endif /* ETHTOOL_GRXRINGS */
2948
2949 #ifndef skb_frag_size
2950 #define skb_frag_size(frag)     _kc_skb_frag_size(frag)
2951 static inline unsigned int _kc_skb_frag_size(const skb_frag_t *frag)
2952 {
2953         return frag->size;
2954 }
2955 #endif /* skb_frag_size */
2956
2957 #ifndef skb_frag_size_sub
2958 #define skb_frag_size_sub(frag, delta)  _kc_skb_frag_size_sub(frag, delta)
2959 static inline void _kc_skb_frag_size_sub(skb_frag_t *frag, int delta)
2960 {
2961         frag->size -= delta;
2962 }
2963 #endif /* skb_frag_size_sub */
2964
2965 #ifndef skb_frag_page
2966 #define skb_frag_page(frag)     _kc_skb_frag_page(frag)
2967 static inline struct page *_kc_skb_frag_page(const skb_frag_t *frag)
2968 {
2969         return frag->page;
2970 }
2971 #endif /* skb_frag_page */
2972
2973 #ifndef skb_frag_address
2974 #define skb_frag_address(frag)  _kc_skb_frag_address(frag)
2975 static inline void *_kc_skb_frag_address(const skb_frag_t *frag)
2976 {
2977         return page_address(skb_frag_page(frag)) + frag->page_offset;
2978 }
2979 #endif /* skb_frag_address */
2980
2981 #ifndef skb_frag_dma_map
2982 #define skb_frag_dma_map(dev,frag,offset,size,dir) \
2983                 _kc_skb_frag_dma_map(dev,frag,offset,size,dir)
2984 static inline dma_addr_t _kc_skb_frag_dma_map(struct device *dev,
2985                                               const skb_frag_t *frag,
2986                                               size_t offset, size_t size,
2987                                               enum dma_data_direction dir)
2988 {
2989         return dma_map_page(dev, skb_frag_page(frag),
2990                             frag->page_offset + offset, size, dir);
2991 }
2992 #endif /* skb_frag_dma_map */
2993
2994 #ifndef __skb_frag_unref
2995 #define __skb_frag_unref(frag) __kc_skb_frag_unref(frag)
2996 static inline void __kc_skb_frag_unref(skb_frag_t *frag)
2997 {
2998         put_page(skb_frag_page(frag));
2999 }
3000 #endif /* __skb_frag_unref */
3001 #else /* < 3.2.0 */
3002 #ifndef HAVE_PCI_DEV_FLAGS_ASSIGNED
3003 #define HAVE_PCI_DEV_FLAGS_ASSIGNED
3004 #define HAVE_VF_SPOOFCHK_CONFIGURE
3005 #endif
3006 #endif /* < 3.2.0 */
3007
3008 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(6,2))
3009 #undef ixgbe_get_netdev_tc_txq
3010 #define ixgbe_get_netdev_tc_txq(dev, tc) (&netdev_extended(dev)->qos_data.tc_to_txq[tc])
3011 #endif
3012
3013 /*****************************************************************************/
3014 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) )
3015 typedef u32 netdev_features_t;
3016 #else /* ! < 3.3.0 */
3017 #define HAVE_INT_NDO_VLAN_RX_ADD_VID
3018 #ifdef ETHTOOL_SRXNTUPLE
3019 #undef ETHTOOL_SRXNTUPLE
3020 #endif
3021 #endif /* < 3.3.0 */
3022
3023 /*****************************************************************************/
3024 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) )
3025 #ifndef NETIF_F_RXFCS
3026 #define NETIF_F_RXFCS   0
3027 #endif /* NETIF_F_RXFCS */
3028 #ifndef NETIF_F_RXALL
3029 #define NETIF_F_RXALL   0
3030 #endif /* NETIF_F_RXALL */
3031
3032 #define NUMTCS_RETURNS_U8
3033
3034
3035 #endif /* < 3.4.0 */
3036
3037 /*****************************************************************************/
3038 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) )
3039 #else
3040 #define HAVE_FDB_OPS
3041 #endif /* < 3.5.0 */
3042 #endif /* _KCOMPAT_H_ */