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