spelling fixes
[dpdk.git] / lib / librte_eal / linuxapp / kni / ethtool / igb / kcompat.h
1 /*******************************************************************************
2
3   Intel(R) Gigabit Ethernet Linux driver
4   Copyright(c) 2007-2013 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 #ifdef IS_ENABLED
291 #undef IS_ENABLED
292 #undef __ARG_PLACEHOLDER_1
293 #undef config_enabled
294 #undef _config_enabled
295 #undef __config_enabled
296 #undef ___config_enabled
297 #endif
298
299 #define __ARG_PLACEHOLDER_1 0,
300 #define config_enabled(cfg) _config_enabled(cfg)
301 #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
302 #define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
303 #define ___config_enabled(__ignored, val, ...) val
304
305 #define IS_ENABLED(option) \
306         (config_enabled(option) || config_enabled(option##_MODULE))
307
308 #if !defined(NETIF_F_HW_VLAN_TX) && !defined(NETIF_F_HW_VLAN_CTAG_TX)
309 struct _kc_vlan_ethhdr {
310         unsigned char   h_dest[ETH_ALEN];
311         unsigned char   h_source[ETH_ALEN];
312         __be16          h_vlan_proto;
313         __be16          h_vlan_TCI;
314         __be16          h_vlan_encapsulated_proto;
315 };
316 #define vlan_ethhdr _kc_vlan_ethhdr
317 struct _kc_vlan_hdr {
318         __be16          h_vlan_TCI;
319         __be16          h_vlan_encapsulated_proto;
320 };
321 #define vlan_hdr _kc_vlan_hdr
322 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) )
323 #define vlan_tx_tag_present(_skb) 0
324 #define vlan_tx_tag_get(_skb) 0
325 #endif
326 #endif /* NETIF_F_HW_VLAN_TX && NETIF_F_HW_VLAN_CTAG_TX */
327
328 #ifndef VLAN_PRIO_SHIFT
329 #define VLAN_PRIO_SHIFT 13
330 #endif
331
332
333 #ifndef __GFP_COLD
334 #define __GFP_COLD 0
335 #endif
336
337 #ifndef __GFP_COMP
338 #define __GFP_COMP 0
339 #endif
340
341 /*****************************************************************************/
342 /* Installations with ethtool version without eeprom, adapter id, or statistics
343  * support */
344
345 #ifndef ETH_GSTRING_LEN
346 #define ETH_GSTRING_LEN 32
347 #endif
348
349 #ifndef ETHTOOL_GSTATS
350 #define ETHTOOL_GSTATS 0x1d
351 #undef ethtool_drvinfo
352 #define ethtool_drvinfo k_ethtool_drvinfo
353 struct k_ethtool_drvinfo {
354         u32 cmd;
355         char driver[32];
356         char version[32];
357         char fw_version[32];
358         char bus_info[32];
359         char reserved1[32];
360         char reserved2[16];
361         u32 n_stats;
362         u32 testinfo_len;
363         u32 eedump_len;
364         u32 regdump_len;
365 };
366
367 struct ethtool_stats {
368         u32 cmd;
369         u32 n_stats;
370         u64 data[0];
371 };
372 #endif /* ETHTOOL_GSTATS */
373
374 #ifndef ETHTOOL_PHYS_ID
375 #define ETHTOOL_PHYS_ID 0x1c
376 #endif /* ETHTOOL_PHYS_ID */
377
378 #ifndef ETHTOOL_GSTRINGS
379 #define ETHTOOL_GSTRINGS 0x1b
380 enum ethtool_stringset {
381         ETH_SS_TEST             = 0,
382         ETH_SS_STATS,
383 };
384 struct ethtool_gstrings {
385         u32 cmd;            /* ETHTOOL_GSTRINGS */
386         u32 string_set;     /* string set id e.c. ETH_SS_TEST, etc*/
387         u32 len;            /* number of strings in the string set */
388         u8 data[0];
389 };
390 #endif /* ETHTOOL_GSTRINGS */
391
392 #ifndef ETHTOOL_TEST
393 #define ETHTOOL_TEST 0x1a
394 enum ethtool_test_flags {
395         ETH_TEST_FL_OFFLINE     = (1 << 0),
396         ETH_TEST_FL_FAILED      = (1 << 1),
397 };
398 struct ethtool_test {
399         u32 cmd;
400         u32 flags;
401         u32 reserved;
402         u32 len;
403         u64 data[0];
404 };
405 #endif /* ETHTOOL_TEST */
406
407 #ifndef ETHTOOL_GEEPROM
408 #define ETHTOOL_GEEPROM 0xb
409 #undef ETHTOOL_GREGS
410 struct ethtool_eeprom {
411         u32 cmd;
412         u32 magic;
413         u32 offset;
414         u32 len;
415         u8 data[0];
416 };
417
418 struct ethtool_value {
419         u32 cmd;
420         u32 data;
421 };
422 #endif /* ETHTOOL_GEEPROM */
423
424 #ifndef ETHTOOL_GLINK
425 #define ETHTOOL_GLINK 0xa
426 #endif /* ETHTOOL_GLINK */
427
428 #ifndef ETHTOOL_GWOL
429 #define ETHTOOL_GWOL 0x5
430 #define ETHTOOL_SWOL 0x6
431 #define SOPASS_MAX      6
432 struct ethtool_wolinfo {
433         u32 cmd;
434         u32 supported;
435         u32 wolopts;
436         u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
437 };
438 #endif /* ETHTOOL_GWOL */
439
440 #ifndef ETHTOOL_GREGS
441 #define ETHTOOL_GREGS           0x00000004 /* Get NIC registers */
442 #define ethtool_regs _kc_ethtool_regs
443 /* for passing big chunks of data */
444 struct _kc_ethtool_regs {
445         u32 cmd;
446         u32 version; /* driver-specific, indicates different chips/revs */
447         u32 len; /* bytes */
448         u8 data[0];
449 };
450 #endif /* ETHTOOL_GREGS */
451
452 #ifndef ETHTOOL_GMSGLVL
453 #define ETHTOOL_GMSGLVL         0x00000007 /* Get driver message level */
454 #endif
455 #ifndef ETHTOOL_SMSGLVL
456 #define ETHTOOL_SMSGLVL         0x00000008 /* Set driver msg level, priv. */
457 #endif
458 #ifndef ETHTOOL_NWAY_RST
459 #define ETHTOOL_NWAY_RST        0x00000009 /* Restart autonegotiation, priv */
460 #endif
461 #ifndef ETHTOOL_GLINK
462 #define ETHTOOL_GLINK           0x0000000a /* Get link status */
463 #endif
464 #ifndef ETHTOOL_GEEPROM
465 #define ETHTOOL_GEEPROM         0x0000000b /* Get EEPROM data */
466 #endif
467 #ifndef ETHTOOL_SEEPROM
468 #define ETHTOOL_SEEPROM         0x0000000c /* Set EEPROM data */
469 #endif
470 #ifndef ETHTOOL_GCOALESCE
471 #define ETHTOOL_GCOALESCE       0x0000000e /* Get coalesce config */
472 /* for configuring coalescing parameters of chip */
473 #define ethtool_coalesce _kc_ethtool_coalesce
474 struct _kc_ethtool_coalesce {
475         u32     cmd;    /* ETHTOOL_{G,S}COALESCE */
476
477         /* How many usecs to delay an RX interrupt after
478          * a packet arrives.  If 0, only rx_max_coalesced_frames
479          * is used.
480          */
481         u32     rx_coalesce_usecs;
482
483         /* How many packets to delay an RX interrupt after
484          * a packet arrives.  If 0, only rx_coalesce_usecs is
485          * used.  It is illegal to set both usecs and max frames
486          * to zero as this would cause RX interrupts to never be
487          * generated.
488          */
489         u32     rx_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     rx_coalesce_usecs_irq;
497         u32     rx_max_coalesced_frames_irq;
498
499         /* How many usecs to delay a TX interrupt after
500          * a packet is sent.  If 0, only tx_max_coalesced_frames
501          * is used.
502          */
503         u32     tx_coalesce_usecs;
504
505         /* How many packets to delay a TX interrupt after
506          * a packet is sent.  If 0, only tx_coalesce_usecs is
507          * used.  It is illegal to set both usecs and max frames
508          * to zero as this would cause TX interrupts to never be
509          * generated.
510          */
511         u32     tx_max_coalesced_frames;
512
513         /* Same as above two parameters, except that these values
514          * apply while an IRQ is being serviced by the host.  Not
515          * all cards support this feature and the values are ignored
516          * in that case.
517          */
518         u32     tx_coalesce_usecs_irq;
519         u32     tx_max_coalesced_frames_irq;
520
521         /* How many usecs to delay in-memory statistics
522          * block updates.  Some drivers do not have an in-memory
523          * statistic block, and in such cases this value is ignored.
524          * This value must not be zero.
525          */
526         u32     stats_block_coalesce_usecs;
527
528         /* Adaptive RX/TX coalescing is an algorithm implemented by
529          * some drivers to improve latency under low packet rates and
530          * improve throughput under high packet rates.  Some drivers
531          * only implement one of RX or TX adaptive coalescing.  Anything
532          * not implemented by the driver causes these values to be
533          * silently ignored.
534          */
535         u32     use_adaptive_rx_coalesce;
536         u32     use_adaptive_tx_coalesce;
537
538         /* When the packet rate (measured in packets per second)
539          * is below pkt_rate_low, the {rx,tx}_*_low parameters are
540          * used.
541          */
542         u32     pkt_rate_low;
543         u32     rx_coalesce_usecs_low;
544         u32     rx_max_coalesced_frames_low;
545         u32     tx_coalesce_usecs_low;
546         u32     tx_max_coalesced_frames_low;
547
548         /* When the packet rate is below pkt_rate_high but above
549          * pkt_rate_low (both measured in packets per second) the
550          * normal {rx,tx}_* coalescing parameters are used.
551          */
552
553         /* When the packet rate is (measured in packets per second)
554          * is above pkt_rate_high, the {rx,tx}_*_high parameters are
555          * used.
556          */
557         u32     pkt_rate_high;
558         u32     rx_coalesce_usecs_high;
559         u32     rx_max_coalesced_frames_high;
560         u32     tx_coalesce_usecs_high;
561         u32     tx_max_coalesced_frames_high;
562
563         /* How often to do adaptive coalescing packet rate sampling,
564          * measured in seconds.  Must not be zero.
565          */
566         u32     rate_sample_interval;
567 };
568 #endif /* ETHTOOL_GCOALESCE */
569
570 #ifndef ETHTOOL_SCOALESCE
571 #define ETHTOOL_SCOALESCE       0x0000000f /* Set coalesce config. */
572 #endif
573 #ifndef ETHTOOL_GRINGPARAM
574 #define ETHTOOL_GRINGPARAM      0x00000010 /* Get ring parameters */
575 /* for configuring RX/TX ring parameters */
576 #define ethtool_ringparam _kc_ethtool_ringparam
577 struct _kc_ethtool_ringparam {
578         u32     cmd;    /* ETHTOOL_{G,S}RINGPARAM */
579
580         /* Read only attributes.  These indicate the maximum number
581          * of pending RX/TX ring entries the driver will allow the
582          * user to set.
583          */
584         u32     rx_max_pending;
585         u32     rx_mini_max_pending;
586         u32     rx_jumbo_max_pending;
587         u32     tx_max_pending;
588
589         /* Values changeable by the user.  The valid values are
590          * in the range 1 to the "*_max_pending" counterpart above.
591          */
592         u32     rx_pending;
593         u32     rx_mini_pending;
594         u32     rx_jumbo_pending;
595         u32     tx_pending;
596 };
597 #endif /* ETHTOOL_GRINGPARAM */
598
599 #ifndef ETHTOOL_SRINGPARAM
600 #define ETHTOOL_SRINGPARAM      0x00000011 /* Set ring parameters, priv. */
601 #endif
602 #ifndef ETHTOOL_GPAUSEPARAM
603 #define ETHTOOL_GPAUSEPARAM     0x00000012 /* Get pause parameters */
604 /* for configuring link flow control parameters */
605 #define ethtool_pauseparam _kc_ethtool_pauseparam
606 struct _kc_ethtool_pauseparam {
607         u32     cmd;    /* ETHTOOL_{G,S}PAUSEPARAM */
608
609         /* If the link is being auto-negotiated (via ethtool_cmd.autoneg
610          * being true) the user may set 'autoneg' here non-zero to have the
611          * pause parameters be auto-negotiated too.  In such a case, the
612          * {rx,tx}_pause values below determine what capabilities are
613          * advertised.
614          *
615          * If 'autoneg' is zero or the link is not being auto-negotiated,
616          * then {rx,tx}_pause force the driver to use/not-use pause
617          * flow control.
618          */
619         u32     autoneg;
620         u32     rx_pause;
621         u32     tx_pause;
622 };
623 #endif /* ETHTOOL_GPAUSEPARAM */
624
625 #ifndef ETHTOOL_SPAUSEPARAM
626 #define ETHTOOL_SPAUSEPARAM     0x00000013 /* Set pause parameters. */
627 #endif
628 #ifndef ETHTOOL_GRXCSUM
629 #define ETHTOOL_GRXCSUM         0x00000014 /* Get RX hw csum enable (ethtool_value) */
630 #endif
631 #ifndef ETHTOOL_SRXCSUM
632 #define ETHTOOL_SRXCSUM         0x00000015 /* Set RX hw csum enable (ethtool_value) */
633 #endif
634 #ifndef ETHTOOL_GTXCSUM
635 #define ETHTOOL_GTXCSUM         0x00000016 /* Get TX hw csum enable (ethtool_value) */
636 #endif
637 #ifndef ETHTOOL_STXCSUM
638 #define ETHTOOL_STXCSUM         0x00000017 /* Set TX hw csum enable (ethtool_value) */
639 #endif
640 #ifndef ETHTOOL_GSG
641 #define ETHTOOL_GSG             0x00000018 /* Get scatter-gather enable
642                                             * (ethtool_value) */
643 #endif
644 #ifndef ETHTOOL_SSG
645 #define ETHTOOL_SSG             0x00000019 /* Set scatter-gather enable
646                                             * (ethtool_value). */
647 #endif
648 #ifndef ETHTOOL_TEST
649 #define ETHTOOL_TEST            0x0000001a /* execute NIC self-test, priv. */
650 #endif
651 #ifndef ETHTOOL_GSTRINGS
652 #define ETHTOOL_GSTRINGS        0x0000001b /* get specified string set */
653 #endif
654 #ifndef ETHTOOL_PHYS_ID
655 #define ETHTOOL_PHYS_ID         0x0000001c /* identify the NIC */
656 #endif
657 #ifndef ETHTOOL_GSTATS
658 #define ETHTOOL_GSTATS          0x0000001d /* get NIC-specific statistics */
659 #endif
660 #ifndef ETHTOOL_GTSO
661 #define ETHTOOL_GTSO            0x0000001e /* Get TSO enable (ethtool_value) */
662 #endif
663 #ifndef ETHTOOL_STSO
664 #define ETHTOOL_STSO            0x0000001f /* Set TSO enable (ethtool_value) */
665 #endif
666
667 #ifndef ETHTOOL_BUSINFO_LEN
668 #define ETHTOOL_BUSINFO_LEN     32
669 #endif
670
671 #ifndef RHEL_RELEASE_VERSION
672 #define RHEL_RELEASE_VERSION(a,b) (((a) << 8) + (b))
673 #endif
674 #ifndef AX_RELEASE_VERSION
675 #define AX_RELEASE_VERSION(a,b) (((a) << 8) + (b))
676 #endif
677
678 #ifndef AX_RELEASE_CODE
679 #define AX_RELEASE_CODE 0
680 #endif
681
682 #if (AX_RELEASE_CODE && AX_RELEASE_CODE == AX_RELEASE_VERSION(3,0))
683 #define RHEL_RELEASE_CODE RHEL_RELEASE_VERSION(5,0)
684 #elif (AX_RELEASE_CODE && AX_RELEASE_CODE == AX_RELEASE_VERSION(3,1))
685 #define RHEL_RELEASE_CODE RHEL_RELEASE_VERSION(5,1)
686 #elif (AX_RELEASE_CODE && AX_RELEASE_CODE == AX_RELEASE_VERSION(3,2))
687 #define RHEL_RELEASE_CODE RHEL_RELEASE_VERSION(5,3)
688 #endif
689
690 #ifndef RHEL_RELEASE_CODE
691 /* NOTE: RHEL_RELEASE_* introduced in RHEL4.5 */
692 #define RHEL_RELEASE_CODE 0
693 #endif
694
695 /* SuSE version macro is the same as Linux kernel version */
696 #ifndef SLE_VERSION
697 #define SLE_VERSION(a,b,c) KERNEL_VERSION(a,b,c)
698 #endif
699 #ifdef CONFIG_SUSE_KERNEL
700 #if ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27) )
701 /* SLES11 GA is 2.6.27 based */
702 #define SLE_VERSION_CODE SLE_VERSION(11,0,0)
703 #elif ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32) )
704 /* SLES11 SP1 is 2.6.32 based */
705 #define SLE_VERSION_CODE SLE_VERSION(11,1,0)
706 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,61)) && \
707        (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0)))
708 /* SLES11 SP3 is at least 3.0.61+ based */
709 #define SLE_VERSION_CODE SLE_VERSION(11,3,0)
710 #endif /* LINUX_VERSION_CODE == KERNEL_VERSION(x,y,z) */
711 #endif /* CONFIG_SUSE_KERNEL */
712 #ifndef SLE_VERSION_CODE
713 #define SLE_VERSION_CODE 0
714 #endif /* SLE_VERSION_CODE */
715
716 #ifdef __KLOCWORK__
717 #ifdef ARRAY_SIZE
718 #undef ARRAY_SIZE
719 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
720 #endif
721 #endif /* __KLOCWORK__ */
722
723 /*****************************************************************************/
724 /* 2.4.3 => 2.4.0 */
725 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )
726
727 /**************************************/
728 /* PCI DRIVER API */
729
730 #ifndef pci_set_dma_mask
731 #define pci_set_dma_mask _kc_pci_set_dma_mask
732 extern int _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
733 #endif
734
735 #ifndef pci_request_regions
736 #define pci_request_regions _kc_pci_request_regions
737 extern int _kc_pci_request_regions(struct pci_dev *pdev, char *res_name);
738 #endif
739
740 #ifndef pci_release_regions
741 #define pci_release_regions _kc_pci_release_regions
742 extern void _kc_pci_release_regions(struct pci_dev *pdev);
743 #endif
744
745 /**************************************/
746 /* NETWORK DRIVER API */
747
748 #ifndef alloc_etherdev
749 #define alloc_etherdev _kc_alloc_etherdev
750 extern struct net_device * _kc_alloc_etherdev(int sizeof_priv);
751 #endif
752
753 #ifndef is_valid_ether_addr
754 #define is_valid_ether_addr _kc_is_valid_ether_addr
755 extern int _kc_is_valid_ether_addr(u8 *addr);
756 #endif
757
758 /**************************************/
759 /* MISCELLANEOUS */
760
761 #ifndef INIT_TQUEUE
762 #define INIT_TQUEUE(_tq, _routine, _data)               \
763         do {                                            \
764                 INIT_LIST_HEAD(&(_tq)->list);           \
765                 (_tq)->sync = 0;                        \
766                 (_tq)->routine = _routine;              \
767                 (_tq)->data = _data;                    \
768         } while (0)
769 #endif
770
771 #endif /* 2.4.3 => 2.4.0 */
772
773 /*****************************************************************************/
774 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) )
775 /* Generic MII registers. */
776 #define MII_BMCR            0x00        /* Basic mode control register */
777 #define MII_BMSR            0x01        /* Basic mode status register  */
778 #define MII_PHYSID1         0x02        /* PHYS ID 1                   */
779 #define MII_PHYSID2         0x03        /* PHYS ID 2                   */
780 #define MII_ADVERTISE       0x04        /* Advertisement control reg   */
781 #define MII_LPA             0x05        /* Link partner ability reg    */
782 #define MII_EXPANSION       0x06        /* Expansion register          */
783 /* Basic mode control register. */
784 #define BMCR_FULLDPLX           0x0100  /* Full duplex                 */
785 #define BMCR_ANENABLE           0x1000  /* Enable auto negotiation     */
786 /* Basic mode status register. */
787 #define BMSR_ERCAP              0x0001  /* Ext-reg capability          */
788 #define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
789 #define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
790 #define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
791 #define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
792 #define BMSR_100FULL            0x4000  /* Can do 100mbps, full-duplex */
793 /* Advertisement control register. */
794 #define ADVERTISE_CSMA          0x0001  /* Only selector supported     */
795 #define ADVERTISE_10HALF        0x0020  /* Try for 10mbps half-duplex  */
796 #define ADVERTISE_10FULL        0x0040  /* Try for 10mbps full-duplex  */
797 #define ADVERTISE_100HALF       0x0080  /* Try for 100mbps half-duplex */
798 #define ADVERTISE_100FULL       0x0100  /* Try for 100mbps full-duplex */
799 #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
800                        ADVERTISE_100HALF | ADVERTISE_100FULL)
801 /* Expansion register for auto-negotiation. */
802 #define EXPANSION_ENABLENPAGE   0x0004  /* This enables npage words    */
803 #endif
804
805 /*****************************************************************************/
806 /* 2.4.6 => 2.4.3 */
807 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )
808
809 #ifndef pci_set_power_state
810 #define pci_set_power_state _kc_pci_set_power_state
811 extern int _kc_pci_set_power_state(struct pci_dev *dev, int state);
812 #endif
813
814 #ifndef pci_enable_wake
815 #define pci_enable_wake _kc_pci_enable_wake
816 extern int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable);
817 #endif
818
819 #ifndef pci_disable_device
820 #define pci_disable_device _kc_pci_disable_device
821 extern void _kc_pci_disable_device(struct pci_dev *pdev);
822 #endif
823
824 /* PCI PM entry point syntax changed, so don't support suspend/resume */
825 #undef CONFIG_PM
826
827 #endif /* 2.4.6 => 2.4.3 */
828
829 #ifndef HAVE_PCI_SET_MWI
830 #define pci_set_mwi(X) pci_write_config_word(X, \
831                                PCI_COMMAND, adapter->hw.bus.pci_cmd_word | \
832                                PCI_COMMAND_INVALIDATE);
833 #define pci_clear_mwi(X) pci_write_config_word(X, \
834                                PCI_COMMAND, adapter->hw.bus.pci_cmd_word & \
835                                ~PCI_COMMAND_INVALIDATE);
836 #endif
837
838 /*****************************************************************************/
839 /* 2.4.10 => 2.4.9 */
840 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) )
841
842 /**************************************/
843 /* MODULE API */
844
845 #ifndef MODULE_LICENSE
846         #define MODULE_LICENSE(X)
847 #endif
848
849 /**************************************/
850 /* OTHER */
851
852 #undef min
853 #define min(x,y) ({ \
854         const typeof(x) _x = (x);       \
855         const typeof(y) _y = (y);       \
856         (void) (&_x == &_y);            \
857         _x < _y ? _x : _y; })
858
859 #undef max
860 #define max(x,y) ({ \
861         const typeof(x) _x = (x);       \
862         const typeof(y) _y = (y);       \
863         (void) (&_x == &_y);            \
864         _x > _y ? _x : _y; })
865
866 #define min_t(type,x,y) ({ \
867         type _x = (x); \
868         type _y = (y); \
869         _x < _y ? _x : _y; })
870
871 #define max_t(type,x,y) ({ \
872         type _x = (x); \
873         type _y = (y); \
874         _x > _y ? _x : _y; })
875
876 #ifndef list_for_each_safe
877 #define list_for_each_safe(pos, n, head) \
878         for (pos = (head)->next, n = pos->next; pos != (head); \
879                 pos = n, n = pos->next)
880 #endif
881
882 #ifndef ____cacheline_aligned_in_smp
883 #ifdef CONFIG_SMP
884 #define ____cacheline_aligned_in_smp ____cacheline_aligned
885 #else
886 #define ____cacheline_aligned_in_smp
887 #endif /* CONFIG_SMP */
888 #endif
889
890 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) )
891 extern int _kc_snprintf(char * buf, size_t size, const char *fmt, ...);
892 #define snprintf(buf, size, fmt, args...) _kc_snprintf(buf, size, fmt, ##args)
893 extern int _kc_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
894 #define vsnprintf(buf, size, fmt, args) _kc_vsnprintf(buf, size, fmt, args)
895 #else /* 2.4.8 => 2.4.9 */
896 extern int snprintf(char * buf, size_t size, const char *fmt, ...);
897 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
898 #endif
899 #endif /* 2.4.10 -> 2.4.6 */
900
901
902 /*****************************************************************************/
903 /* 2.4.12 => 2.4.10 */
904 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,12) )
905 #ifndef HAVE_NETIF_MSG
906 #define HAVE_NETIF_MSG 1
907 enum {
908         NETIF_MSG_DRV           = 0x0001,
909         NETIF_MSG_PROBE         = 0x0002,
910         NETIF_MSG_LINK          = 0x0004,
911         NETIF_MSG_TIMER         = 0x0008,
912         NETIF_MSG_IFDOWN        = 0x0010,
913         NETIF_MSG_IFUP          = 0x0020,
914         NETIF_MSG_RX_ERR        = 0x0040,
915         NETIF_MSG_TX_ERR        = 0x0080,
916         NETIF_MSG_TX_QUEUED     = 0x0100,
917         NETIF_MSG_INTR          = 0x0200,
918         NETIF_MSG_TX_DONE       = 0x0400,
919         NETIF_MSG_RX_STATUS     = 0x0800,
920         NETIF_MSG_PKTDATA       = 0x1000,
921         NETIF_MSG_HW            = 0x2000,
922         NETIF_MSG_WOL           = 0x4000,
923 };
924
925 #define netif_msg_drv(p)        ((p)->msg_enable & NETIF_MSG_DRV)
926 #define netif_msg_probe(p)      ((p)->msg_enable & NETIF_MSG_PROBE)
927 #define netif_msg_link(p)       ((p)->msg_enable & NETIF_MSG_LINK)
928 #define netif_msg_timer(p)      ((p)->msg_enable & NETIF_MSG_TIMER)
929 #define netif_msg_ifdown(p)     ((p)->msg_enable & NETIF_MSG_IFDOWN)
930 #define netif_msg_ifup(p)       ((p)->msg_enable & NETIF_MSG_IFUP)
931 #define netif_msg_rx_err(p)     ((p)->msg_enable & NETIF_MSG_RX_ERR)
932 #define netif_msg_tx_err(p)     ((p)->msg_enable & NETIF_MSG_TX_ERR)
933 #define netif_msg_tx_queued(p)  ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
934 #define netif_msg_intr(p)       ((p)->msg_enable & NETIF_MSG_INTR)
935 #define netif_msg_tx_done(p)    ((p)->msg_enable & NETIF_MSG_TX_DONE)
936 #define netif_msg_rx_status(p)  ((p)->msg_enable & NETIF_MSG_RX_STATUS)
937 #define netif_msg_pktdata(p)    ((p)->msg_enable & NETIF_MSG_PKTDATA)
938 #endif /* !HAVE_NETIF_MSG */
939 #endif /* 2.4.12 => 2.4.10 */
940
941 /*****************************************************************************/
942 /* 2.4.13 => 2.4.12 */
943 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )
944
945 /**************************************/
946 /* PCI DMA MAPPING */
947
948 #ifndef virt_to_page
949         #define virt_to_page(v) (mem_map + (virt_to_phys(v) >> PAGE_SHIFT))
950 #endif
951
952 #ifndef pci_map_page
953 #define pci_map_page _kc_pci_map_page
954 extern u64 _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset, size_t size, int direction);
955 #endif
956
957 #ifndef pci_unmap_page
958 #define pci_unmap_page _kc_pci_unmap_page
959 extern void _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size, int direction);
960 #endif
961
962 /* pci_set_dma_mask takes dma_addr_t, which is only 32-bits prior to 2.4.13 */
963
964 #undef DMA_32BIT_MASK
965 #define DMA_32BIT_MASK  0xffffffff
966 #undef DMA_64BIT_MASK
967 #define DMA_64BIT_MASK  0xffffffff
968
969 /**************************************/
970 /* OTHER */
971
972 #ifndef cpu_relax
973 #define cpu_relax()     rep_nop()
974 #endif
975
976 struct vlan_ethhdr {
977         unsigned char h_dest[ETH_ALEN];
978         unsigned char h_source[ETH_ALEN];
979         unsigned short h_vlan_proto;
980         unsigned short h_vlan_TCI;
981         unsigned short h_vlan_encapsulated_proto;
982 };
983 #endif /* 2.4.13 => 2.4.12 */
984
985 /*****************************************************************************/
986 /* 2.4.17 => 2.4.12 */
987 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17) )
988
989 #ifndef __devexit_p
990         #define __devexit_p(x) &(x)
991 #endif
992
993 #else
994         /* For Kernel 3.8 these are not defined - so undefine all */
995         #undef __devexit_p
996         #undef __devexit
997         #undef __devinit
998         #undef __devinitdata
999         #define __devexit_p(x) &(x)
1000         #define __devexit
1001         #define __devinit
1002         #define __devinitdata
1003
1004 #endif /* 2.4.17 => 2.4.13 */
1005
1006 /*****************************************************************************/
1007 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18) )
1008 #define NETIF_MSG_HW    0x2000
1009 #define NETIF_MSG_WOL   0x4000
1010
1011 #ifndef netif_msg_hw
1012 #define netif_msg_hw(p)         ((p)->msg_enable & NETIF_MSG_HW)
1013 #endif
1014 #ifndef netif_msg_wol
1015 #define netif_msg_wol(p)        ((p)->msg_enable & NETIF_MSG_WOL)
1016 #endif
1017 #endif /* 2.4.18 */
1018
1019 /*****************************************************************************/
1020
1021 /*****************************************************************************/
1022 /* 2.4.20 => 2.4.19 */
1023 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20) )
1024
1025 /* we won't support NAPI on less than 2.4.20 */
1026 #ifdef NAPI
1027 #undef NAPI
1028 #endif
1029
1030 #endif /* 2.4.20 => 2.4.19 */
1031
1032 /*****************************************************************************/
1033 /* 2.4.22 => 2.4.17 */
1034 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
1035 #define pci_name(x)     ((x)->slot_name)
1036
1037 #ifndef SUPPORTED_10000baseT_Full
1038 #define SUPPORTED_10000baseT_Full       (1 << 12)
1039 #endif
1040 #ifndef ADVERTISED_10000baseT_Full
1041 #define ADVERTISED_10000baseT_Full      (1 << 12)
1042 #endif
1043 #endif
1044
1045 /*****************************************************************************/
1046 /* 2.4.22 => 2.4.17 */
1047
1048 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
1049 #ifndef IGB_NO_LRO
1050 #define IGB_NO_LRO
1051 #endif
1052 #endif
1053
1054 /*****************************************************************************/
1055 /*****************************************************************************/
1056 /* 2.4.23 => 2.4.22 */
1057 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23) )
1058 /*****************************************************************************/
1059 #ifdef NAPI
1060 #ifndef netif_poll_disable
1061 #define netif_poll_disable(x) _kc_netif_poll_disable(x)
1062 static inline void _kc_netif_poll_disable(struct net_device *netdev)
1063 {
1064         while (test_and_set_bit(__LINK_STATE_RX_SCHED, &netdev->state)) {
1065                 /* No hurry */
1066                 current->state = TASK_INTERRUPTIBLE;
1067                 schedule_timeout(1);
1068         }
1069 }
1070 #endif
1071 #ifndef netif_poll_enable
1072 #define netif_poll_enable(x) _kc_netif_poll_enable(x)
1073 static inline void _kc_netif_poll_enable(struct net_device *netdev)
1074 {
1075         clear_bit(__LINK_STATE_RX_SCHED, &netdev->state);
1076 }
1077 #endif
1078 #endif /* NAPI */
1079 #ifndef netif_tx_disable
1080 #define netif_tx_disable(x) _kc_netif_tx_disable(x)
1081 static inline void _kc_netif_tx_disable(struct net_device *dev)
1082 {
1083         spin_lock_bh(&dev->xmit_lock);
1084         netif_stop_queue(dev);
1085         spin_unlock_bh(&dev->xmit_lock);
1086 }
1087 #endif
1088 #else /* 2.4.23 => 2.4.22 */
1089 #define HAVE_SCTP
1090 #endif /* 2.4.23 => 2.4.22 */
1091
1092 /*****************************************************************************/
1093 /* 2.6.4 => 2.6.0 */
1094 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \
1095     ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1096       LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )
1097 #define ETHTOOL_OPS_COMPAT
1098 #endif /* 2.6.4 => 2.6.0 */
1099
1100 /*****************************************************************************/
1101 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) )
1102 #define __user
1103 #endif /* < 2.4.27 */
1104
1105 /*****************************************************************************/
1106 /* 2.5.71 => 2.4.x */
1107 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71) )
1108 #define sk_protocol protocol
1109 #define pci_get_device pci_find_device
1110 #endif /* 2.5.70 => 2.4.x */
1111
1112 /*****************************************************************************/
1113 /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1114 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) || \
1115     ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1116       LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) ) )
1117
1118 #ifndef netif_msg_init
1119 #define netif_msg_init _kc_netif_msg_init
1120 static inline u32 _kc_netif_msg_init(int debug_value, int default_msg_enable_bits)
1121 {
1122         /* use default */
1123         if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
1124                 return default_msg_enable_bits;
1125         if (debug_value == 0) /* no output */
1126                 return 0;
1127         /* set low N bits */
1128         return (1 << debug_value) -1;
1129 }
1130 #endif
1131
1132 #endif /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1133 /*****************************************************************************/
1134 #if (( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) ) || \
1135      (( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) && \
1136       ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) )))
1137 #define netdev_priv(x) x->priv
1138 #endif
1139
1140 /*****************************************************************************/
1141 /* <= 2.5.0 */
1142 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) )
1143 #include <linux/rtnetlink.h>
1144 #undef pci_register_driver
1145 #define pci_register_driver pci_module_init
1146
1147 /*
1148  * Most of the dma compat code is copied/modifed from the 2.4.37
1149  * /include/linux/libata-compat.h header file
1150  */
1151 /* These definitions mirror those in pci.h, so they can be used
1152  * interchangeably with their PCI_ counterparts */
1153 enum dma_data_direction {
1154         DMA_BIDIRECTIONAL = 0,
1155         DMA_TO_DEVICE = 1,
1156         DMA_FROM_DEVICE = 2,
1157         DMA_NONE = 3,
1158 };
1159
1160 struct device {
1161         struct pci_dev pdev;
1162 };
1163
1164 static inline struct pci_dev *to_pci_dev (struct device *dev)
1165 {
1166         return (struct pci_dev *) dev;
1167 }
1168 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1169 {
1170         return (struct device *) pdev;
1171 }
1172
1173 #define pdev_printk(lvl, pdev, fmt, args...)    \
1174         printk("%s %s: " fmt, lvl, pci_name(pdev), ## args)
1175 #define dev_err(dev, fmt, args...)            \
1176         pdev_printk(KERN_ERR, to_pci_dev(dev), fmt, ## args)
1177 #define dev_info(dev, fmt, args...)            \
1178         pdev_printk(KERN_INFO, to_pci_dev(dev), fmt, ## args)
1179 #define dev_warn(dev, fmt, args...)            \
1180         pdev_printk(KERN_WARNING, to_pci_dev(dev), fmt, ## args)
1181 #define dev_notice(dev, fmt, args...)            \
1182         pdev_printk(KERN_NOTICE, to_pci_dev(dev), fmt, ## args)
1183 #define dev_dbg(dev, fmt, args...) \
1184         pdev_printk(KERN_DEBUG, to_pci_dev(dev), fmt, ## args)
1185
1186 /* NOTE: dangerous! we ignore the 'gfp' argument */
1187 #define dma_alloc_coherent(dev,sz,dma,gfp) \
1188         pci_alloc_consistent(to_pci_dev(dev),(sz),(dma))
1189 #define dma_free_coherent(dev,sz,addr,dma_addr) \
1190         pci_free_consistent(to_pci_dev(dev),(sz),(addr),(dma_addr))
1191
1192 #define dma_map_page(dev,a,b,c,d) \
1193         pci_map_page(to_pci_dev(dev),(a),(b),(c),(d))
1194 #define dma_unmap_page(dev,a,b,c) \
1195         pci_unmap_page(to_pci_dev(dev),(a),(b),(c))
1196
1197 #define dma_map_single(dev,a,b,c) \
1198         pci_map_single(to_pci_dev(dev),(a),(b),(c))
1199 #define dma_unmap_single(dev,a,b,c) \
1200         pci_unmap_single(to_pci_dev(dev),(a),(b),(c))
1201
1202 #define dma_map_sg(dev, sg, nents, dir) \
1203         pci_map_sg(to_pci_dev(dev), (sg), (nents), (dir)
1204 #define dma_unmap_sg(dev, sg, nents, dir) \
1205         pci_unmap_sg(to_pci_dev(dev), (sg), (nents), (dir)
1206
1207 #define dma_sync_single(dev,a,b,c) \
1208         pci_dma_sync_single(to_pci_dev(dev),(a),(b),(c))
1209
1210 /* for range just sync everything, that's all the pci API can do */
1211 #define dma_sync_single_range(dev,addr,off,sz,dir) \
1212         pci_dma_sync_single(to_pci_dev(dev),(addr),(off)+(sz),(dir))
1213
1214 #define dma_set_mask(dev,mask) \
1215         pci_set_dma_mask(to_pci_dev(dev),(mask))
1216
1217 /* hlist_* code - double linked lists */
1218 struct hlist_head {
1219         struct hlist_node *first;
1220 };
1221
1222 struct hlist_node {
1223         struct hlist_node *next, **pprev;
1224 };
1225
1226 static inline void __hlist_del(struct hlist_node *n)
1227 {
1228         struct hlist_node *next = n->next;
1229         struct hlist_node **pprev = n->pprev;
1230         *pprev = next;
1231         if (next)
1232         next->pprev = pprev;
1233 }
1234
1235 static inline void hlist_del(struct hlist_node *n)
1236 {
1237         __hlist_del(n);
1238         n->next = NULL;
1239         n->pprev = NULL;
1240 }
1241
1242 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
1243 {
1244         struct hlist_node *first = h->first;
1245         n->next = first;
1246         if (first)
1247                 first->pprev = &n->next;
1248         h->first = n;
1249         n->pprev = &h->first;
1250 }
1251
1252 static inline int hlist_empty(const struct hlist_head *h)
1253 {
1254         return !h->first;
1255 }
1256 #define HLIST_HEAD_INIT { .first = NULL }
1257 #define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
1258 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
1259 static inline void INIT_HLIST_NODE(struct hlist_node *h)
1260 {
1261         h->next = NULL;
1262         h->pprev = NULL;
1263 }
1264
1265 #ifndef might_sleep
1266 #define might_sleep()
1267 #endif
1268 #else
1269 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1270 {
1271         return &pdev->dev;
1272 }
1273 #endif /* <= 2.5.0 */
1274
1275 /*****************************************************************************/
1276 /* 2.5.28 => 2.4.23 */
1277 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )
1278
1279 #include <linux/tqueue.h>
1280 #define work_struct tq_struct
1281 #undef INIT_WORK
1282 #define INIT_WORK(a,b) INIT_TQUEUE(a,(void (*)(void *))b,a)
1283 #undef container_of
1284 #define container_of list_entry
1285 #define schedule_work schedule_task
1286 #define flush_scheduled_work flush_scheduled_tasks
1287 #define cancel_work_sync(x) flush_scheduled_work()
1288
1289 #endif /* 2.5.28 => 2.4.17 */
1290
1291 /*****************************************************************************/
1292 /* 2.6.0 => 2.5.28 */
1293 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
1294 #ifndef read_barrier_depends
1295 #define read_barrier_depends() rmb()
1296 #endif
1297
1298 #undef get_cpu
1299 #define get_cpu() smp_processor_id()
1300 #undef put_cpu
1301 #define put_cpu() do { } while(0)
1302 #define MODULE_INFO(version, _version)
1303 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1304 #define CONFIG_E1000_DISABLE_PACKET_SPLIT 1
1305 #endif
1306 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
1307 #define CONFIG_IGB_DISABLE_PACKET_SPLIT 1
1308 #endif
1309
1310 #define dma_set_coherent_mask(dev,mask) 1
1311
1312 #undef dev_put
1313 #define dev_put(dev) __dev_put(dev)
1314
1315 #ifndef skb_fill_page_desc
1316 #define skb_fill_page_desc _kc_skb_fill_page_desc
1317 extern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size);
1318 #endif
1319
1320 #undef ALIGN
1321 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
1322
1323 #ifndef page_count
1324 #define page_count(p) atomic_read(&(p)->count)
1325 #endif
1326
1327 #ifdef MAX_NUMNODES
1328 #undef MAX_NUMNODES
1329 #endif
1330 #define MAX_NUMNODES 1
1331
1332 /* find_first_bit and find_next bit are not defined for most
1333  * 2.4 kernels (except for the redhat 2.4.21 kernels
1334  */
1335 #include <linux/bitops.h>
1336 #define BITOP_WORD(nr)          ((nr) / BITS_PER_LONG)
1337 #undef find_next_bit
1338 #define find_next_bit _kc_find_next_bit
1339 extern unsigned long _kc_find_next_bit(const unsigned long *addr,
1340                                        unsigned long size,
1341                                        unsigned long offset);
1342 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
1343
1344
1345 #ifndef netdev_name
1346 static inline const char *_kc_netdev_name(const struct net_device *dev)
1347 {
1348         if (strchr(dev->name, '%'))
1349                 return "(unregistered net_device)";
1350         return dev->name;
1351 }
1352 #define netdev_name(netdev)     _kc_netdev_name(netdev)
1353 #endif /* netdev_name */
1354
1355 #ifndef strlcpy
1356 #define strlcpy _kc_strlcpy
1357 extern size_t _kc_strlcpy(char *dest, const char *src, size_t size);
1358 #endif /* strlcpy */
1359
1360 #ifndef do_div
1361 #if BITS_PER_LONG == 64
1362 # define do_div(n,base) ({                                      \
1363         uint32_t __base = (base);                               \
1364         uint32_t __rem;                                         \
1365         __rem = ((uint64_t)(n)) % __base;                       \
1366         (n) = ((uint64_t)(n)) / __base;                         \
1367         __rem;                                                  \
1368  })
1369 #elif BITS_PER_LONG == 32
1370 extern uint32_t _kc__div64_32(uint64_t *dividend, uint32_t divisor);
1371 # define do_div(n,base) ({                              \
1372         uint32_t __base = (base);                       \
1373         uint32_t __rem;                                 \
1374         if (likely(((n) >> 32) == 0)) {                 \
1375                 __rem = (uint32_t)(n) % __base;         \
1376                 (n) = (uint32_t)(n) / __base;           \
1377         } else                                          \
1378                 __rem = _kc__div64_32(&(n), __base);    \
1379         __rem;                                          \
1380  })
1381 #else /* BITS_PER_LONG == ?? */
1382 # error do_div() does not yet support the C64
1383 #endif /* BITS_PER_LONG */
1384 #endif /* do_div */
1385
1386 #ifndef NSEC_PER_SEC
1387 #define NSEC_PER_SEC    1000000000L
1388 #endif
1389
1390 #undef HAVE_I2C_SUPPORT
1391 #else /* 2.6.0 */
1392 #if IS_ENABLED(CONFIG_I2C_ALGOBIT) && \
1393         (RHEL_RELEASE_CODE && (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,9)))
1394 #define HAVE_I2C_SUPPORT
1395 #endif /* IS_ENABLED(CONFIG_I2C_ALGOBIT) */
1396
1397 #endif /* 2.6.0 => 2.5.28 */
1398 /*****************************************************************************/
1399 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) )
1400 #define dma_pool pci_pool
1401 #define dma_pool_destroy pci_pool_destroy
1402 #define dma_pool_alloc pci_pool_alloc
1403 #define dma_pool_free pci_pool_free
1404
1405 #define dma_pool_create(name,dev,size,align,allocation) \
1406        pci_pool_create((name),to_pci_dev(dev),(size),(align),(allocation))
1407 #endif /* < 2.6.3 */
1408
1409 /*****************************************************************************/
1410 /* 2.6.4 => 2.6.0 */
1411 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1412 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
1413 #endif /* 2.6.4 => 2.6.0 */
1414
1415 /*****************************************************************************/
1416 /* 2.6.5 => 2.6.0 */
1417 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) )
1418 #define dma_sync_single_for_cpu         dma_sync_single
1419 #define dma_sync_single_for_device      dma_sync_single
1420 #define dma_sync_single_range_for_cpu           dma_sync_single_range
1421 #define dma_sync_single_range_for_device        dma_sync_single_range
1422 #ifndef pci_dma_mapping_error
1423 #define pci_dma_mapping_error _kc_pci_dma_mapping_error
1424 static inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr)
1425 {
1426         return dma_addr == 0;
1427 }
1428 #endif
1429 #endif /* 2.6.5 => 2.6.0 */
1430
1431 /*****************************************************************************/
1432 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1433 extern int _kc_scnprintf(char * buf, size_t size, const char *fmt, ...);
1434 #define scnprintf(buf, size, fmt, args...) _kc_scnprintf(buf, size, fmt, ##args)
1435 #endif /* < 2.6.4 */
1436
1437 /*****************************************************************************/
1438 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6) )
1439 /* taken from 2.6 include/linux/bitmap.h */
1440 #undef bitmap_zero
1441 #define bitmap_zero _kc_bitmap_zero
1442 static inline void _kc_bitmap_zero(unsigned long *dst, int nbits)
1443 {
1444         if (nbits <= BITS_PER_LONG)
1445                 *dst = 0UL;
1446         else {
1447                 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
1448                 memset(dst, 0, len);
1449         }
1450 }
1451 #define random_ether_addr _kc_random_ether_addr
1452 static inline void _kc_random_ether_addr(u8 *addr)
1453 {
1454         get_random_bytes(addr, ETH_ALEN);
1455         addr[0] &= 0xfe; /* clear multicast */
1456         addr[0] |= 0x02; /* set local assignment */
1457 }
1458 #define page_to_nid(x) 0
1459
1460 #endif /* < 2.6.6 */
1461
1462 /*****************************************************************************/
1463 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7) )
1464 #undef if_mii
1465 #define if_mii _kc_if_mii
1466 static inline struct mii_ioctl_data *_kc_if_mii(struct ifreq *rq)
1467 {
1468         return (struct mii_ioctl_data *) &rq->ifr_ifru;
1469 }
1470
1471 #ifndef __force
1472 #define __force
1473 #endif
1474 #endif /* < 2.6.7 */
1475
1476 /*****************************************************************************/
1477 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
1478 #ifndef PCI_EXP_DEVCTL
1479 #define PCI_EXP_DEVCTL 8
1480 #endif
1481 #ifndef PCI_EXP_DEVCTL_CERE
1482 #define PCI_EXP_DEVCTL_CERE 0x0001
1483 #endif
1484 #define PCI_EXP_FLAGS           2       /* Capabilities register */
1485 #define PCI_EXP_FLAGS_VERS      0x000f  /* Capability version */
1486 #define PCI_EXP_FLAGS_TYPE      0x00f0  /* Device/Port type */
1487 #define  PCI_EXP_TYPE_ENDPOINT  0x0     /* Express Endpoint */
1488 #define  PCI_EXP_TYPE_LEG_END   0x1     /* Legacy Endpoint */
1489 #define  PCI_EXP_TYPE_ROOT_PORT 0x4     /* Root Port */
1490 #define  PCI_EXP_TYPE_DOWNSTREAM 0x6    /* Downstream Port */
1491 #define PCI_EXP_FLAGS_SLOT      0x0100  /* Slot implemented */
1492 #define PCI_EXP_DEVCAP          4       /* Device capabilities */
1493 #define PCI_EXP_DEVSTA          10      /* Device Status */
1494 #define msleep(x)       do { set_current_state(TASK_UNINTERRUPTIBLE); \
1495                                 schedule_timeout((x * HZ)/1000 + 2); \
1496                         } while (0)
1497
1498 #endif /* < 2.6.8 */
1499
1500 /*****************************************************************************/
1501 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
1502 #include <net/dsfield.h>
1503 #define __iomem
1504
1505 #ifndef kcalloc
1506 #define kcalloc(n, size, flags) _kc_kzalloc(((n) * (size)), flags)
1507 extern void *_kc_kzalloc(size_t size, int flags);
1508 #endif
1509 #define MSEC_PER_SEC    1000L
1510 static inline unsigned int _kc_jiffies_to_msecs(const unsigned long j)
1511 {
1512 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1513         return (MSEC_PER_SEC / HZ) * j;
1514 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1515         return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
1516 #else
1517         return (j * MSEC_PER_SEC) / HZ;
1518 #endif
1519 }
1520 static inline unsigned long _kc_msecs_to_jiffies(const unsigned int m)
1521 {
1522         if (m > _kc_jiffies_to_msecs(MAX_JIFFY_OFFSET))
1523                 return MAX_JIFFY_OFFSET;
1524 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1525         return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
1526 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1527         return m * (HZ / MSEC_PER_SEC);
1528 #else
1529         return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
1530 #endif
1531 }
1532
1533 #define msleep_interruptible _kc_msleep_interruptible
1534 static inline unsigned long _kc_msleep_interruptible(unsigned int msecs)
1535 {
1536         unsigned long timeout = _kc_msecs_to_jiffies(msecs) + 1;
1537
1538         while (timeout && !signal_pending(current)) {
1539                 __set_current_state(TASK_INTERRUPTIBLE);
1540                 timeout = schedule_timeout(timeout);
1541         }
1542         return _kc_jiffies_to_msecs(timeout);
1543 }
1544
1545 /* Basic mode control register. */
1546 #define BMCR_SPEED1000          0x0040  /* MSB of Speed (1000)         */
1547
1548 #ifndef __le16
1549 #define __le16 u16
1550 #endif
1551 #ifndef __le32
1552 #define __le32 u32
1553 #endif
1554 #ifndef __le64
1555 #define __le64 u64
1556 #endif
1557 #ifndef __be16
1558 #define __be16 u16
1559 #endif
1560 #ifndef __be32
1561 #define __be32 u32
1562 #endif
1563 #ifndef __be64
1564 #define __be64 u64
1565 #endif
1566
1567 static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
1568 {
1569         return (struct vlan_ethhdr *)skb->mac.raw;
1570 }
1571
1572 /* Wake-On-Lan options. */
1573 #define WAKE_PHY                (1 << 0)
1574 #define WAKE_UCAST              (1 << 1)
1575 #define WAKE_MCAST              (1 << 2)
1576 #define WAKE_BCAST              (1 << 3)
1577 #define WAKE_ARP                (1 << 4)
1578 #define WAKE_MAGIC              (1 << 5)
1579 #define WAKE_MAGICSECURE        (1 << 6) /* only meaningful if WAKE_MAGIC */
1580
1581 #define skb_header_pointer _kc_skb_header_pointer
1582 static inline void *_kc_skb_header_pointer(const struct sk_buff *skb,
1583                                             int offset, int len, void *buffer)
1584 {
1585         int hlen = skb_headlen(skb);
1586
1587         if (hlen - offset >= len)
1588                 return skb->data + offset;
1589
1590 #ifdef MAX_SKB_FRAGS
1591         if (skb_copy_bits(skb, offset, buffer, len) < 0)
1592                 return NULL;
1593
1594         return buffer;
1595 #else
1596         return NULL;
1597 #endif
1598
1599 #ifndef NETDEV_TX_OK
1600 #define NETDEV_TX_OK 0
1601 #endif
1602 #ifndef NETDEV_TX_BUSY
1603 #define NETDEV_TX_BUSY 1
1604 #endif
1605 #ifndef NETDEV_TX_LOCKED
1606 #define NETDEV_TX_LOCKED -1
1607 #endif
1608 }
1609
1610 #ifndef __bitwise
1611 #define __bitwise
1612 #endif
1613 #endif /* < 2.6.9 */
1614
1615 /*****************************************************************************/
1616 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) )
1617 #ifdef module_param_array_named
1618 #undef module_param_array_named
1619 #define module_param_array_named(name, array, type, nump, perm)          \
1620         static struct kparam_array __param_arr_##name                    \
1621         = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type, \
1622             sizeof(array[0]), array };                                   \
1623         module_param_call(name, param_array_set, param_array_get,        \
1624                           &__param_arr_##name, perm)
1625 #endif /* module_param_array_named */
1626 /*
1627  * num_online is broken for all < 2.6.10 kernels.  This is needed to support
1628  * Node module parameter of ixgbe.
1629  */
1630 #undef num_online_nodes
1631 #define num_online_nodes(n) 1
1632 extern DECLARE_BITMAP(_kcompat_node_online_map, MAX_NUMNODES);
1633 #undef node_online_map
1634 #define node_online_map _kcompat_node_online_map
1635 #define pci_get_class pci_find_class
1636 #endif /* < 2.6.10 */
1637
1638 /*****************************************************************************/
1639 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) )
1640 #define PCI_D0      0
1641 #define PCI_D1      1
1642 #define PCI_D2      2
1643 #define PCI_D3hot   3
1644 #define PCI_D3cold  4
1645 typedef int pci_power_t;
1646 #define pci_choose_state(pdev,state) state
1647 #define PMSG_SUSPEND 3
1648 #define PCI_EXP_LNKCTL  16
1649
1650 #undef NETIF_F_LLTX
1651
1652 #ifndef ARCH_HAS_PREFETCH
1653 #define prefetch(X)
1654 #endif
1655
1656 #ifndef NET_IP_ALIGN
1657 #define NET_IP_ALIGN 2
1658 #endif
1659
1660 #define KC_USEC_PER_SEC 1000000L
1661 #define usecs_to_jiffies _kc_usecs_to_jiffies
1662 static inline unsigned int _kc_jiffies_to_usecs(const unsigned long j)
1663 {
1664 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1665         return (KC_USEC_PER_SEC / HZ) * j;
1666 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1667         return (j + (HZ / KC_USEC_PER_SEC) - 1)/(HZ / KC_USEC_PER_SEC);
1668 #else
1669         return (j * KC_USEC_PER_SEC) / HZ;
1670 #endif
1671 }
1672 static inline unsigned long _kc_usecs_to_jiffies(const unsigned int m)
1673 {
1674         if (m > _kc_jiffies_to_usecs(MAX_JIFFY_OFFSET))
1675                 return MAX_JIFFY_OFFSET;
1676 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1677         return (m + (KC_USEC_PER_SEC / HZ) - 1) / (KC_USEC_PER_SEC / HZ);
1678 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1679         return m * (HZ / KC_USEC_PER_SEC);
1680 #else
1681         return (m * HZ + KC_USEC_PER_SEC - 1) / KC_USEC_PER_SEC;
1682 #endif
1683 }
1684
1685 #define PCI_EXP_LNKCAP          12      /* Link Capabilities */
1686 #define PCI_EXP_LNKSTA          18      /* Link Status */
1687 #define PCI_EXP_SLTCAP          20      /* Slot Capabilities */
1688 #define PCI_EXP_SLTCTL          24      /* Slot Control */
1689 #define PCI_EXP_SLTSTA          26      /* Slot Status */
1690 #define PCI_EXP_RTCTL           28      /* Root Control */
1691 #define PCI_EXP_RTCAP           30      /* Root Capabilities */
1692 #define PCI_EXP_RTSTA           32      /* Root Status */
1693 #endif /* < 2.6.11 */
1694
1695 /*****************************************************************************/
1696 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) )
1697 #include <linux/reboot.h>
1698 #define USE_REBOOT_NOTIFIER
1699
1700 /* Generic MII registers. */
1701 #define MII_CTRL1000        0x09        /* 1000BASE-T control          */
1702 #define MII_STAT1000        0x0a        /* 1000BASE-T status           */
1703 /* Advertisement control register. */
1704 #define ADVERTISE_PAUSE_CAP     0x0400  /* Try for pause               */
1705 #define ADVERTISE_PAUSE_ASYM    0x0800  /* Try for asymmetric pause     */
1706 /* Link partner ability register. */
1707 #define LPA_PAUSE_CAP           0x0400  /* Can pause                   */
1708 #define LPA_PAUSE_ASYM          0x0800  /* Can pause asymetrically     */
1709 /* 1000BASE-T Control register */
1710 #define ADVERTISE_1000FULL      0x0200  /* Advertise 1000BASE-T full duplex */
1711 #define ADVERTISE_1000HALF      0x0100  /* Advertise 1000BASE-T half duplex */
1712 /* 1000BASE-T Status register */
1713 #define LPA_1000LOCALRXOK       0x2000  /* Link partner local receiver status */
1714 #define LPA_1000REMRXOK         0x1000  /* Link partner remote receiver status */
1715
1716 #ifndef is_zero_ether_addr
1717 #define is_zero_ether_addr _kc_is_zero_ether_addr
1718 static inline int _kc_is_zero_ether_addr(const u8 *addr)
1719 {
1720         return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
1721 }
1722 #endif /* is_zero_ether_addr */
1723 #ifndef is_multicast_ether_addr
1724 #define is_multicast_ether_addr _kc_is_multicast_ether_addr
1725 static inline int _kc_is_multicast_ether_addr(const u8 *addr)
1726 {
1727         return addr[0] & 0x01;
1728 }
1729 #endif /* is_multicast_ether_addr */
1730 #endif /* < 2.6.12 */
1731
1732 /*****************************************************************************/
1733 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) )
1734 #ifndef kstrdup
1735 #define kstrdup _kc_kstrdup
1736 extern char *_kc_kstrdup(const char *s, unsigned int gfp);
1737 #endif
1738 #endif /* < 2.6.13 */
1739
1740 /*****************************************************************************/
1741 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) )
1742 #define pm_message_t u32
1743 #ifndef kzalloc
1744 #define kzalloc _kc_kzalloc
1745 extern void *_kc_kzalloc(size_t size, int flags);
1746 #endif
1747
1748 /* Generic MII registers. */
1749 #define MII_ESTATUS         0x0f        /* Extended Status */
1750 /* Basic mode status register. */
1751 #define BMSR_ESTATEN            0x0100  /* Extended Status in R15 */
1752 /* Extended status register. */
1753 #define ESTATUS_1000_TFULL      0x2000  /* Can do 1000BT Full */
1754 #define ESTATUS_1000_THALF      0x1000  /* Can do 1000BT Half */
1755
1756 #define SUPPORTED_Pause         (1 << 13)
1757 #define SUPPORTED_Asym_Pause    (1 << 14)
1758 #define ADVERTISED_Pause        (1 << 13)
1759 #define ADVERTISED_Asym_Pause   (1 << 14)
1760
1761 #if (!(RHEL_RELEASE_CODE && \
1762        (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,3)) && \
1763        (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))))
1764 #if ((LINUX_VERSION_CODE == KERNEL_VERSION(2,6,9)) && !defined(gfp_t))
1765 #define gfp_t unsigned
1766 #else
1767 typedef unsigned gfp_t;
1768 #endif
1769 #endif /* !RHEL4.3->RHEL5.0 */
1770
1771 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9) )
1772 #ifdef CONFIG_X86_64
1773 #define dma_sync_single_range_for_cpu(dev, addr, off, sz, dir)       \
1774         dma_sync_single_for_cpu((dev), (addr), (off) + (sz), (dir))
1775 #define dma_sync_single_range_for_device(dev, addr, off, sz, dir)    \
1776         dma_sync_single_for_device((dev), (addr), (off) + (sz), (dir))
1777 #endif
1778 #endif
1779 #endif /* < 2.6.14 */
1780
1781 /*****************************************************************************/
1782 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) )
1783 #ifndef vmalloc_node
1784 #define vmalloc_node(a,b) vmalloc(a)
1785 #endif /* vmalloc_node*/
1786
1787 #define setup_timer(_timer, _function, _data) \
1788 do { \
1789         (_timer)->function = _function; \
1790         (_timer)->data = _data; \
1791         init_timer(_timer); \
1792 } while (0)
1793 #ifndef device_can_wakeup
1794 #define device_can_wakeup(dev)  (1)
1795 #endif
1796 #ifndef device_set_wakeup_enable
1797 #define device_set_wakeup_enable(dev, val)      do{}while(0)
1798 #endif
1799 #ifndef device_init_wakeup
1800 #define device_init_wakeup(dev,val) do {} while (0)
1801 #endif
1802 static inline unsigned _kc_compare_ether_addr(const u8 *addr1, const u8 *addr2)
1803 {
1804         const u16 *a = (const u16 *) addr1;
1805         const u16 *b = (const u16 *) addr2;
1806
1807         return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
1808 }
1809 #undef compare_ether_addr
1810 #define compare_ether_addr(addr1, addr2) _kc_compare_ether_addr(addr1, addr2)
1811 #endif /* < 2.6.15 */
1812
1813 /*****************************************************************************/
1814 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) )
1815 #undef DEFINE_MUTEX
1816 #define DEFINE_MUTEX(x) DECLARE_MUTEX(x)
1817 #define mutex_lock(x)   down_interruptible(x)
1818 #define mutex_unlock(x) up(x)
1819
1820 #ifndef ____cacheline_internodealigned_in_smp
1821 #ifdef CONFIG_SMP
1822 #define ____cacheline_internodealigned_in_smp ____cacheline_aligned_in_smp
1823 #else
1824 #define ____cacheline_internodealigned_in_smp
1825 #endif /* CONFIG_SMP */
1826 #endif /* ____cacheline_internodealigned_in_smp */
1827 #undef HAVE_PCI_ERS
1828 #else /* 2.6.16 and above */
1829 #undef HAVE_PCI_ERS
1830 #define HAVE_PCI_ERS
1831 #if ( SLE_VERSION_CODE && SLE_VERSION_CODE == SLE_VERSION(10,4,0) )
1832 #ifdef device_can_wakeup
1833 #undef device_can_wakeup
1834 #endif /* device_can_wakeup */
1835 #define device_can_wakeup(dev) 1
1836 #endif /* SLE_VERSION(10,4,0) */
1837 #endif /* < 2.6.16 */
1838
1839 /*****************************************************************************/
1840 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) )
1841 #ifndef dev_notice
1842 #define dev_notice(dev, fmt, args...)            \
1843         dev_printk(KERN_NOTICE, dev, fmt, ## args)
1844 #endif
1845
1846 #ifndef first_online_node
1847 #define first_online_node 0
1848 #endif
1849 #ifndef NET_SKB_PAD
1850 #define NET_SKB_PAD 16
1851 #endif
1852 #endif /* < 2.6.17 */
1853
1854 /*****************************************************************************/
1855 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) )
1856
1857 #ifndef IRQ_HANDLED
1858 #define irqreturn_t void
1859 #define IRQ_HANDLED
1860 #define IRQ_NONE
1861 #endif
1862
1863 #ifndef IRQF_PROBE_SHARED
1864 #ifdef SA_PROBEIRQ
1865 #define IRQF_PROBE_SHARED SA_PROBEIRQ
1866 #else
1867 #define IRQF_PROBE_SHARED 0
1868 #endif
1869 #endif
1870
1871 #ifndef IRQF_SHARED
1872 #define IRQF_SHARED SA_SHIRQ
1873 #endif
1874
1875 #ifndef ARRAY_SIZE
1876 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
1877 #endif
1878
1879 #ifndef FIELD_SIZEOF
1880 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
1881 #endif
1882
1883 #ifndef skb_is_gso
1884 #ifdef NETIF_F_TSO
1885 #define skb_is_gso _kc_skb_is_gso
1886 static inline int _kc_skb_is_gso(const struct sk_buff *skb)
1887 {
1888         return skb_shinfo(skb)->gso_size;
1889 }
1890 #else
1891 #define skb_is_gso(a) 0
1892 #endif
1893 #endif
1894
1895 #ifndef resource_size_t
1896 #define resource_size_t unsigned long
1897 #endif
1898
1899 #ifdef skb_pad
1900 #undef skb_pad
1901 #endif
1902 #define skb_pad(x,y) _kc_skb_pad(x, y)
1903 int _kc_skb_pad(struct sk_buff *skb, int pad);
1904 #ifdef skb_padto
1905 #undef skb_padto
1906 #endif
1907 #define skb_padto(x,y) _kc_skb_padto(x, y)
1908 static inline int _kc_skb_padto(struct sk_buff *skb, unsigned int len)
1909 {
1910         unsigned int size = skb->len;
1911         if(likely(size >= len))
1912                 return 0;
1913         return _kc_skb_pad(skb, len - size);
1914 }
1915
1916 #ifndef DECLARE_PCI_UNMAP_ADDR
1917 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
1918         dma_addr_t ADDR_NAME
1919 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
1920         u32 LEN_NAME
1921 #define pci_unmap_addr(PTR, ADDR_NAME) \
1922         ((PTR)->ADDR_NAME)
1923 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
1924         (((PTR)->ADDR_NAME) = (VAL))
1925 #define pci_unmap_len(PTR, LEN_NAME) \
1926         ((PTR)->LEN_NAME)
1927 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
1928         (((PTR)->LEN_NAME) = (VAL))
1929 #endif /* DECLARE_PCI_UNMAP_ADDR */
1930 #endif /* < 2.6.18 */
1931
1932 /*****************************************************************************/
1933 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) )
1934
1935 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,0)))
1936 #define i_private u.generic_ip
1937 #endif /* >= RHEL 5.0 */
1938
1939 #ifndef DIV_ROUND_UP
1940 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
1941 #endif
1942 #ifndef __ALIGN_MASK
1943 #define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
1944 #endif
1945 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) )
1946 #if (!((RHEL_RELEASE_CODE && \
1947         ((RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,4) && \
1948           RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0)) || \
1949          (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,0))))))
1950 typedef irqreturn_t (*irq_handler_t)(int, void*, struct pt_regs *);
1951 #endif
1952 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
1953 #undef CONFIG_INET_LRO
1954 #undef CONFIG_INET_LRO_MODULE
1955 #ifdef IXGBE_FCOE
1956 #undef CONFIG_FCOE
1957 #undef CONFIG_FCOE_MODULE
1958 #endif /* IXGBE_FCOE */
1959 #endif
1960 typedef irqreturn_t (*new_handler_t)(int, void*);
1961 static inline irqreturn_t _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1962 #else /* 2.4.x */
1963 typedef void (*irq_handler_t)(int, void*, struct pt_regs *);
1964 typedef void (*new_handler_t)(int, void*);
1965 static inline int _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1966 #endif /* >= 2.5.x */
1967 {
1968         irq_handler_t new_handler = (irq_handler_t) handler;
1969         return request_irq(irq, new_handler, flags, devname, dev_id);
1970 }
1971
1972 #undef request_irq
1973 #define request_irq(irq, handler, flags, devname, dev_id) _kc_request_irq((irq), (handler), (flags), (devname), (dev_id))
1974
1975 #define irq_handler_t new_handler_t
1976 /* pci_restore_state and pci_save_state handles MSI/PCIE from 2.6.19 */
1977 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))
1978 #define PCIE_CONFIG_SPACE_LEN 256
1979 #define PCI_CONFIG_SPACE_LEN 64
1980 #define PCIE_LINK_STATUS 0x12
1981 #define pci_config_space_ich8lan() do {} while(0)
1982 #undef pci_save_state
1983 extern int _kc_pci_save_state(struct pci_dev *);
1984 #define pci_save_state(pdev) _kc_pci_save_state(pdev)
1985 #undef pci_restore_state
1986 extern void _kc_pci_restore_state(struct pci_dev *);
1987 #define pci_restore_state(pdev) _kc_pci_restore_state(pdev)
1988 #endif /* !(RHEL_RELEASE_CODE >= RHEL 5.4) */
1989
1990 #ifdef HAVE_PCI_ERS
1991 #undef free_netdev
1992 extern void _kc_free_netdev(struct net_device *);
1993 #define free_netdev(netdev) _kc_free_netdev(netdev)
1994 #endif
1995 static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
1996 {
1997         return 0;
1998 }
1999 #define pci_disable_pcie_error_reporting(dev) do {} while (0)
2000 #define pci_cleanup_aer_uncorrect_error_status(dev) do {} while (0)
2001
2002 extern void *_kc_kmemdup(const void *src, size_t len, unsigned gfp);
2003 #define kmemdup(src, len, gfp) _kc_kmemdup(src, len, gfp)
2004 #ifndef bool
2005 #define bool _Bool
2006 #define true 1
2007 #define false 0
2008 #endif
2009 #else /* 2.6.19 */
2010 #include <linux/aer.h>
2011 #include <linux/string.h>
2012 #endif /* < 2.6.19 */
2013
2014 /*****************************************************************************/
2015 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) )
2016 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28) )
2017 #undef INIT_WORK
2018 #define INIT_WORK(_work, _func) \
2019 do { \
2020         INIT_LIST_HEAD(&(_work)->entry); \
2021         (_work)->pending = 0; \
2022         (_work)->func = (void (*)(void *))_func; \
2023         (_work)->data = _work; \
2024         init_timer(&(_work)->timer); \
2025 } while (0)
2026 #endif
2027
2028 #ifndef PCI_VDEVICE
2029 #define PCI_VDEVICE(ven, dev)        \
2030         PCI_VENDOR_ID_##ven, (dev),  \
2031         PCI_ANY_ID, PCI_ANY_ID, 0, 0
2032 #endif
2033
2034 #ifndef PCI_VENDOR_ID_INTEL
2035 #define PCI_VENDOR_ID_INTEL 0x8086
2036 #endif
2037
2038 #ifndef round_jiffies
2039 #define round_jiffies(x) x
2040 #endif
2041
2042 #define csum_offset csum
2043
2044 #define HAVE_EARLY_VMALLOC_NODE
2045 #define dev_to_node(dev) -1
2046 #undef set_dev_node
2047 /* remove compiler warning with b=b, for unused variable */
2048 #define set_dev_node(a, b) do { (b) = (b); } while(0)
2049
2050 #if (!(RHEL_RELEASE_CODE && \
2051        (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
2052          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
2053         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,6)))) && \
2054      !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
2055 typedef __u16 __bitwise __sum16;
2056 typedef __u32 __bitwise __wsum;
2057 #endif
2058
2059 #if (!(RHEL_RELEASE_CODE && \
2060        (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
2061          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
2062         (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))) && \
2063      !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
2064 static inline __wsum csum_unfold(__sum16 n)
2065 {
2066         return (__force __wsum)n;
2067 }
2068 #endif
2069
2070 #else /* < 2.6.20 */
2071 #define HAVE_DEVICE_NUMA_NODE
2072 #endif /* < 2.6.20 */
2073
2074 /*****************************************************************************/
2075 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
2076 #define to_net_dev(class) container_of(class, struct net_device, class_dev)
2077 #define NETDEV_CLASS_DEV
2078 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)))
2079 #define vlan_group_get_device(vg, id) (vg->vlan_devices[id])
2080 #define vlan_group_set_device(vg, id, dev)              \
2081         do {                                            \
2082                 if (vg) vg->vlan_devices[id] = dev;     \
2083         } while (0)
2084 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)) */
2085 #define pci_channel_offline(pdev) (pdev->error_state && \
2086         pdev->error_state != pci_channel_io_normal)
2087 #define pci_request_selected_regions(pdev, bars, name) \
2088         pci_request_regions(pdev, name)
2089 #define pci_release_selected_regions(pdev, bars) pci_release_regions(pdev);
2090
2091 #ifndef __aligned
2092 #define __aligned(x)                    __attribute__((aligned(x)))
2093 #endif
2094
2095 extern struct pci_dev *_kc_netdev_to_pdev(struct net_device *netdev);
2096 #define netdev_to_dev(netdev)   \
2097         pci_dev_to_dev(_kc_netdev_to_pdev(netdev))
2098 #else
2099 static inline struct device *netdev_to_dev(struct net_device *netdev)
2100 {
2101         return &netdev->dev;
2102 }
2103
2104 #endif /* < 2.6.21 */
2105
2106 /*****************************************************************************/
2107 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
2108 #define tcp_hdr(skb) (skb->h.th)
2109 #define tcp_hdrlen(skb) (skb->h.th->doff << 2)
2110 #define skb_transport_offset(skb) (skb->h.raw - skb->data)
2111 #define skb_transport_header(skb) (skb->h.raw)
2112 #define ipv6_hdr(skb) (skb->nh.ipv6h)
2113 #define ip_hdr(skb) (skb->nh.iph)
2114 #define skb_network_offset(skb) (skb->nh.raw - skb->data)
2115 #define skb_network_header(skb) (skb->nh.raw)
2116 #define skb_tail_pointer(skb) skb->tail
2117 #define skb_reset_tail_pointer(skb) \
2118         do { \
2119                 skb->tail = skb->data; \
2120         } while (0)
2121 #define skb_set_tail_pointer(skb, offset) \
2122         do { \
2123                 skb->tail = skb->data + offset; \
2124         } while (0)
2125 #define skb_copy_to_linear_data(skb, from, len) \
2126                                 memcpy(skb->data, from, len)
2127 #define skb_copy_to_linear_data_offset(skb, offset, from, len) \
2128                                 memcpy(skb->data + offset, from, len)
2129 #define skb_network_header_len(skb) (skb->h.raw - skb->nh.raw)
2130 #define pci_register_driver pci_module_init
2131 #define skb_mac_header(skb) skb->mac.raw
2132
2133 #ifdef NETIF_F_MULTI_QUEUE
2134 #ifndef alloc_etherdev_mq
2135 #define alloc_etherdev_mq(_a, _b) alloc_etherdev(_a)
2136 #endif
2137 #endif /* NETIF_F_MULTI_QUEUE */
2138
2139 #ifndef ETH_FCS_LEN
2140 #define ETH_FCS_LEN 4
2141 #endif
2142 #define cancel_work_sync(x) flush_scheduled_work()
2143 #ifndef udp_hdr
2144 #define udp_hdr _udp_hdr
2145 static inline struct udphdr *_udp_hdr(const struct sk_buff *skb)
2146 {
2147         return (struct udphdr *)skb_transport_header(skb);
2148 }
2149 #endif
2150
2151 #ifdef cpu_to_be16
2152 #undef cpu_to_be16
2153 #endif
2154 #define cpu_to_be16(x) __constant_htons(x)
2155
2156 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)))
2157 enum {
2158         DUMP_PREFIX_NONE,
2159         DUMP_PREFIX_ADDRESS,
2160         DUMP_PREFIX_OFFSET
2161 };
2162 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)) */
2163 #ifndef hex_asc
2164 #define hex_asc(x)      "0123456789abcdef"[x]
2165 #endif
2166 #include <linux/ctype.h>
2167 extern void _kc_print_hex_dump(const char *level, const char *prefix_str,
2168                                int prefix_type, int rowsize, int groupsize,
2169                                const void *buf, size_t len, bool ascii);
2170 #define print_hex_dump(lvl, s, t, r, g, b, l, a) \
2171                 _kc_print_hex_dump(lvl, s, t, r, g, b, l, a)
2172 #ifndef ADVERTISED_2500baseX_Full
2173 #define ADVERTISED_2500baseX_Full (1 << 15)
2174 #endif
2175 #ifndef SUPPORTED_2500baseX_Full
2176 #define SUPPORTED_2500baseX_Full (1 << 15)
2177 #endif
2178
2179 #ifdef HAVE_I2C_SUPPORT
2180 #include <linux/i2c.h>
2181 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)))
2182 struct i2c_board_info {
2183         char    driver_name[KOBJ_NAME_LEN];
2184         char    type[I2C_NAME_SIZE];
2185         unsigned short  flags;
2186         unsigned short  addr;
2187         void            *platform_data;
2188 };
2189 #define I2C_BOARD_INFO(driver, dev_addr) .driver_name = (driver),\
2190                         .addr = (dev_addr)
2191 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)) */
2192 #define i2c_new_device(adap, info) _kc_i2c_new_device(adap, info)
2193 extern struct i2c_client *
2194 _kc_i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
2195 #endif /* HAVE_I2C_SUPPORT */
2196
2197 #else /* 2.6.22 */
2198 #define ETH_TYPE_TRANS_SETS_DEV
2199 #define HAVE_NETDEV_STATS_IN_NETDEV
2200 #endif /* < 2.6.22 */
2201
2202 /*****************************************************************************/
2203 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22) )
2204 #undef SET_MODULE_OWNER
2205 #define SET_MODULE_OWNER(dev) do { } while (0)
2206 #endif /* > 2.6.22 */
2207
2208 /*****************************************************************************/
2209 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) )
2210 #define netif_subqueue_stopped(_a, _b) 0
2211 #ifndef PTR_ALIGN
2212 #define PTR_ALIGN(p, a)         ((typeof(p))ALIGN((unsigned long)(p), (a)))
2213 #endif
2214
2215 #ifndef CONFIG_PM_SLEEP
2216 #define CONFIG_PM_SLEEP CONFIG_PM
2217 #endif
2218
2219 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13) )
2220 #define HAVE_ETHTOOL_GET_PERM_ADDR
2221 #endif /* 2.6.14 through 2.6.22 */
2222 #endif /* < 2.6.23 */
2223
2224 /*****************************************************************************/
2225 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
2226 #ifndef ETH_FLAG_LRO
2227 #define ETH_FLAG_LRO NETIF_F_LRO
2228 #endif
2229
2230 /* if GRO is supported then the napi struct must already exist */
2231 #ifndef NETIF_F_GRO
2232 /* NAPI API changes in 2.6.24 break everything */
2233 struct napi_struct {
2234         /* used to look up the real NAPI polling routine */
2235         int (*poll)(struct napi_struct *, int);
2236         struct net_device *dev;
2237         int weight;
2238 };
2239 #endif
2240
2241 #ifdef NAPI
2242 extern int __kc_adapter_clean(struct net_device *, int *);
2243 extern struct net_device *napi_to_poll_dev(const struct napi_struct *napi);
2244 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2245         do { \
2246                 struct napi_struct *__napi = (_napi); \
2247                 struct net_device *poll_dev = napi_to_poll_dev(__napi); \
2248                 poll_dev->poll = &(__kc_adapter_clean); \
2249                 poll_dev->priv = (_napi); \
2250                 poll_dev->weight = (_weight); \
2251                 set_bit(__LINK_STATE_RX_SCHED, &poll_dev->state); \
2252                 set_bit(__LINK_STATE_START, &poll_dev->state);\
2253                 dev_hold(poll_dev); \
2254                 __napi->poll = &(_poll); \
2255                 __napi->weight = (_weight); \
2256                 __napi->dev = (_netdev); \
2257         } while (0)
2258 #define netif_napi_del(_napi) \
2259         do { \
2260                 struct net_device *poll_dev = napi_to_poll_dev(_napi); \
2261                 WARN_ON(!test_bit(__LINK_STATE_RX_SCHED, &poll_dev->state)); \
2262                 dev_put(poll_dev); \
2263                 memset(poll_dev, 0, sizeof(struct net_device));\
2264         } while (0)
2265 #define napi_schedule_prep(_napi) \
2266         (netif_running((_napi)->dev) && netif_rx_schedule_prep(napi_to_poll_dev(_napi)))
2267 #define napi_schedule(_napi) \
2268         do { \
2269                 if (napi_schedule_prep(_napi)) \
2270                         __netif_rx_schedule(napi_to_poll_dev(_napi)); \
2271         } while (0)
2272 #define napi_enable(_napi) netif_poll_enable(napi_to_poll_dev(_napi))
2273 #define napi_disable(_napi) netif_poll_disable(napi_to_poll_dev(_napi))
2274 #ifdef CONFIG_SMP
2275 static inline void napi_synchronize(const struct napi_struct *n)
2276 {
2277         struct net_device *dev = napi_to_poll_dev(n);
2278
2279         while (test_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
2280                 /* No hurry. */
2281                 msleep(1);
2282         }
2283 }
2284 #else
2285 #define napi_synchronize(n)     barrier()
2286 #endif /* CONFIG_SMP */
2287 #define __napi_schedule(_napi) __netif_rx_schedule(napi_to_poll_dev(_napi))
2288 #ifndef NETIF_F_GRO
2289 #define napi_complete(_napi) netif_rx_complete(napi_to_poll_dev(_napi))
2290 #else
2291 #define napi_complete(_napi) \
2292         do { \
2293                 napi_gro_flush(_napi); \
2294                 netif_rx_complete(napi_to_poll_dev(_napi)); \
2295         } while (0)
2296 #endif /* NETIF_F_GRO */
2297 #else /* NAPI */
2298 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2299         do { \
2300                 struct napi_struct *__napi = _napi; \
2301                 _netdev->poll = &(_poll); \
2302                 _netdev->weight = (_weight); \
2303                 __napi->poll = &(_poll); \
2304                 __napi->weight = (_weight); \
2305                 __napi->dev = (_netdev); \
2306         } while (0)
2307 #define netif_napi_del(_a) do {} while (0)
2308 #endif /* NAPI */
2309
2310 #undef dev_get_by_name
2311 #define dev_get_by_name(_a, _b) dev_get_by_name(_b)
2312 #define __netif_subqueue_stopped(_a, _b) netif_subqueue_stopped(_a, _b)
2313 #ifndef DMA_BIT_MASK
2314 #define DMA_BIT_MASK(n) (((n) == 64) ? DMA_64BIT_MASK : ((1ULL<<(n))-1))
2315 #endif
2316
2317 #ifdef NETIF_F_TSO6
2318 #define skb_is_gso_v6 _kc_skb_is_gso_v6
2319 static inline int _kc_skb_is_gso_v6(const struct sk_buff *skb)
2320 {
2321         return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6;
2322 }
2323 #endif /* NETIF_F_TSO6 */
2324
2325 #ifndef KERN_CONT
2326 #define KERN_CONT       ""
2327 #endif
2328 #ifndef pr_err
2329 #define pr_err(fmt, arg...) \
2330         printk(KERN_ERR fmt, ##arg)
2331 #endif
2332 #else /* < 2.6.24 */
2333 #define HAVE_ETHTOOL_GET_SSET_COUNT
2334 #define HAVE_NETDEV_NAPI_LIST
2335 #endif /* < 2.6.24 */
2336
2337 /*****************************************************************************/
2338 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) )
2339 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2340 #include <linux/pm_qos_params.h>
2341 #else /* >= 3.2.0 */
2342 #include <linux/pm_qos.h>
2343 #endif /* else >= 3.2.0 */
2344 #endif /* > 2.6.24 */
2345
2346 /*****************************************************************************/
2347 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) )
2348 #define PM_QOS_CPU_DMA_LATENCY  1
2349
2350 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18) )
2351 #include <linux/latency.h>
2352 #define PM_QOS_DEFAULT_VALUE    INFINITE_LATENCY
2353 #define pm_qos_add_requirement(pm_qos_class, name, value) \
2354                 set_acceptable_latency(name, value)
2355 #define pm_qos_remove_requirement(pm_qos_class, name) \
2356                 remove_acceptable_latency(name)
2357 #define pm_qos_update_requirement(pm_qos_class, name, value) \
2358                 modify_acceptable_latency(name, value)
2359 #else
2360 #define PM_QOS_DEFAULT_VALUE    -1
2361 #define pm_qos_add_requirement(pm_qos_class, name, value)
2362 #define pm_qos_remove_requirement(pm_qos_class, name)
2363 #define pm_qos_update_requirement(pm_qos_class, name, value) { \
2364         if (value != PM_QOS_DEFAULT_VALUE) { \
2365                 printk(KERN_WARNING "%s: unable to set PM QoS requirement\n", \
2366                         pci_name(adapter->pdev)); \
2367         } \
2368 }
2369
2370 #endif /* > 2.6.18 */
2371
2372 #define pci_enable_device_mem(pdev) pci_enable_device(pdev)
2373
2374 #ifndef DEFINE_PCI_DEVICE_TABLE
2375 #define DEFINE_PCI_DEVICE_TABLE(_table) struct pci_device_id _table[]
2376 #endif /* DEFINE_PCI_DEVICE_TABLE */
2377
2378
2379 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) )
2380 #ifndef IGB_PROCFS
2381 #define IGB_PROCFS
2382 #endif /* IGB_PROCFS */
2383 #endif /* >= 2.6.0 */
2384
2385 #else /* < 2.6.25 */
2386
2387
2388 #if IS_ENABLED(CONFIG_HWMON)
2389 #ifndef IGB_HWMON
2390 #define IGB_HWMON
2391 #endif /* IGB_HWMON */
2392 #endif /* CONFIG_HWMON */
2393
2394 #endif /* < 2.6.25 */
2395
2396 /*****************************************************************************/
2397 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) )
2398 #ifndef clamp_t
2399 #define clamp_t(type, val, min, max) ({         \
2400         type __val = (val);                     \
2401         type __min = (min);                     \
2402         type __max = (max);                     \
2403         __val = __val < __min ? __min : __val;  \
2404         __val > __max ? __max : __val; })
2405 #endif /* clamp_t */
2406 #undef kzalloc_node
2407 #define kzalloc_node(_size, _flags, _node) kzalloc(_size, _flags)
2408
2409 extern void _kc_pci_disable_link_state(struct pci_dev *dev, int state);
2410 #define pci_disable_link_state(p, s) _kc_pci_disable_link_state(p, s)
2411 #else /* < 2.6.26 */
2412 #include <linux/pci-aspm.h>
2413 #define HAVE_NETDEV_VLAN_FEATURES
2414 #ifndef PCI_EXP_LNKCAP_ASPMS
2415 #define PCI_EXP_LNKCAP_ASPMS 0x00000c00 /* ASPM Support */
2416 #endif /* PCI_EXP_LNKCAP_ASPMS */
2417 #endif /* < 2.6.26 */
2418 /*****************************************************************************/
2419 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) )
2420 static inline void _kc_ethtool_cmd_speed_set(struct ethtool_cmd *ep,
2421                                              __u32 speed)
2422 {
2423         ep->speed = (__u16)speed;
2424         /* ep->speed_hi = (__u16)(speed >> 16); */
2425 }
2426 #define ethtool_cmd_speed_set _kc_ethtool_cmd_speed_set
2427
2428 static inline __u32 _kc_ethtool_cmd_speed(struct ethtool_cmd *ep)
2429 {
2430         /* no speed_hi before 2.6.27, and probably no need for it yet */
2431         return (__u32)ep->speed;
2432 }
2433 #define ethtool_cmd_speed _kc_ethtool_cmd_speed
2434
2435 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) )
2436 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)) && defined(CONFIG_PM))
2437 #define ANCIENT_PM 1
2438 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) && \
2439        (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) && \
2440        defined(CONFIG_PM_SLEEP))
2441 #define NEWER_PM 1
2442 #endif
2443 #if defined(ANCIENT_PM) || defined(NEWER_PM)
2444 #undef device_set_wakeup_enable
2445 #define device_set_wakeup_enable(dev, val) \
2446         do { \
2447                 u16 pmc = 0; \
2448                 int pm = pci_find_capability(adapter->pdev, PCI_CAP_ID_PM); \
2449                 if (pm) { \
2450                         pci_read_config_word(adapter->pdev, pm + PCI_PM_PMC, \
2451                                 &pmc); \
2452                 } \
2453                 (dev)->power.can_wakeup = !!(pmc >> 11); \
2454                 (dev)->power.should_wakeup = (val && (pmc >> 11)); \
2455         } while (0)
2456 #endif /* 2.6.15-2.6.22 and CONFIG_PM or 2.6.23-2.6.25 and CONFIG_PM_SLEEP */
2457 #endif /* 2.6.15 through 2.6.27 */
2458 #ifndef netif_napi_del
2459 #define netif_napi_del(_a) do {} while (0)
2460 #ifdef NAPI
2461 #ifdef CONFIG_NETPOLL
2462 #undef netif_napi_del
2463 #define netif_napi_del(_a) list_del(&(_a)->dev_list);
2464 #endif
2465 #endif
2466 #endif /* netif_napi_del */
2467 #ifdef dma_mapping_error
2468 #undef dma_mapping_error
2469 #endif
2470 #define dma_mapping_error(dev, dma_addr) pci_dma_mapping_error(dma_addr)
2471
2472 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2473 #define HAVE_TX_MQ
2474 #endif
2475
2476 #ifdef HAVE_TX_MQ
2477 extern void _kc_netif_tx_stop_all_queues(struct net_device *);
2478 extern void _kc_netif_tx_wake_all_queues(struct net_device *);
2479 extern void _kc_netif_tx_start_all_queues(struct net_device *);
2480 #define netif_tx_stop_all_queues(a) _kc_netif_tx_stop_all_queues(a)
2481 #define netif_tx_wake_all_queues(a) _kc_netif_tx_wake_all_queues(a)
2482 #define netif_tx_start_all_queues(a) _kc_netif_tx_start_all_queues(a)
2483 #undef netif_stop_subqueue
2484 #define netif_stop_subqueue(_ndev,_qi) do { \
2485         if (netif_is_multiqueue((_ndev))) \
2486                 netif_stop_subqueue((_ndev), (_qi)); \
2487         else \
2488                 netif_stop_queue((_ndev)); \
2489         } while (0)
2490 #undef netif_start_subqueue
2491 #define netif_start_subqueue(_ndev,_qi) do { \
2492         if (netif_is_multiqueue((_ndev))) \
2493                 netif_start_subqueue((_ndev), (_qi)); \
2494         else \
2495                 netif_start_queue((_ndev)); \
2496         } while (0)
2497 #else /* HAVE_TX_MQ */
2498 #define netif_tx_stop_all_queues(a) netif_stop_queue(a)
2499 #define netif_tx_wake_all_queues(a) netif_wake_queue(a)
2500 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) )
2501 #define netif_tx_start_all_queues(a) netif_start_queue(a)
2502 #else
2503 #define netif_tx_start_all_queues(a) do {} while (0)
2504 #endif
2505 #define netif_stop_subqueue(_ndev,_qi) netif_stop_queue((_ndev))
2506 #define netif_start_subqueue(_ndev,_qi) netif_start_queue((_ndev))
2507 #endif /* HAVE_TX_MQ */
2508 #ifndef NETIF_F_MULTI_QUEUE
2509 #define NETIF_F_MULTI_QUEUE 0
2510 #define netif_is_multiqueue(a) 0
2511 #define netif_wake_subqueue(a, b)
2512 #endif /* NETIF_F_MULTI_QUEUE */
2513
2514 #ifndef __WARN_printf
2515 extern void __kc_warn_slowpath(const char *file, const int line,
2516                 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
2517 #define __WARN_printf(arg...) __kc_warn_slowpath(__FILE__, __LINE__, arg)
2518 #endif /* __WARN_printf */
2519
2520 #ifndef WARN
2521 #define WARN(condition, format...) ({                                           \
2522         int __ret_warn_on = !!(condition);                              \
2523         if (unlikely(__ret_warn_on))                                    \
2524                 __WARN_printf(format);                                  \
2525         unlikely(__ret_warn_on);                                        \
2526 })
2527 #endif /* WARN */
2528 #undef HAVE_IXGBE_DEBUG_FS
2529 #undef HAVE_IGB_DEBUG_FS
2530 #else /* < 2.6.27 */
2531 #define HAVE_TX_MQ
2532 #define HAVE_NETDEV_SELECT_QUEUE
2533 #ifdef CONFIG_DEBUG_FS
2534 #define HAVE_IXGBE_DEBUG_FS
2535 #define HAVE_IGB_DEBUG_FS
2536 #endif /* CONFIG_DEBUG_FS */
2537 #endif /* < 2.6.27 */
2538
2539 /*****************************************************************************/
2540 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) )
2541 #define pci_ioremap_bar(pdev, bar)      ioremap(pci_resource_start(pdev, bar), \
2542                                                 pci_resource_len(pdev, bar))
2543 #define pci_wake_from_d3 _kc_pci_wake_from_d3
2544 #define pci_prepare_to_sleep _kc_pci_prepare_to_sleep
2545 extern int _kc_pci_wake_from_d3(struct pci_dev *dev, bool enable);
2546 extern int _kc_pci_prepare_to_sleep(struct pci_dev *dev);
2547 #define netdev_alloc_page(a) alloc_page(GFP_ATOMIC)
2548 #ifndef __skb_queue_head_init
2549 static inline void __kc_skb_queue_head_init(struct sk_buff_head *list)
2550 {
2551         list->prev = list->next = (struct sk_buff *)list;
2552         list->qlen = 0;
2553 }
2554 #define __skb_queue_head_init(_q) __kc_skb_queue_head_init(_q)
2555 #endif
2556
2557 #define PCI_EXP_DEVCAP2         36      /* Device Capabilities 2 */
2558 #define PCI_EXP_DEVCTL2         40      /* Device Control 2 */
2559
2560 #endif /* < 2.6.28 */
2561
2562 /*****************************************************************************/
2563 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) )
2564 #ifndef swap
2565 #define swap(a, b) \
2566         do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
2567 #endif
2568 #define pci_request_selected_regions_exclusive(pdev, bars, name) \
2569                 pci_request_selected_regions(pdev, bars, name)
2570 #ifndef CONFIG_NR_CPUS
2571 #define CONFIG_NR_CPUS 1
2572 #endif /* CONFIG_NR_CPUS */
2573 #ifndef pcie_aspm_enabled
2574 #define pcie_aspm_enabled()   (1)
2575 #endif /* pcie_aspm_enabled */
2576
2577 #define  PCI_EXP_SLTSTA_PDS     0x0040  /* Presence Detect State */
2578
2579 #ifndef pci_clear_master
2580 extern void _kc_pci_clear_master(struct pci_dev *dev);
2581 #define pci_clear_master(dev)   _kc_pci_clear_master(dev)
2582 #endif
2583
2584 #ifndef PCI_EXP_LNKCTL_ASPMC
2585 #define  PCI_EXP_LNKCTL_ASPMC   0x0003  /* ASPM Control */
2586 #endif
2587 #else /* < 2.6.29 */
2588 #ifndef HAVE_NET_DEVICE_OPS
2589 #define HAVE_NET_DEVICE_OPS
2590 #endif
2591 #ifdef CONFIG_DCB
2592 #define HAVE_PFC_MODE_ENABLE
2593 #endif /* CONFIG_DCB */
2594 #endif /* < 2.6.29 */
2595
2596 /*****************************************************************************/
2597 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) )
2598 #define skb_rx_queue_recorded(a) false
2599 #define skb_get_rx_queue(a) 0
2600 #define skb_record_rx_queue(a, b) do {} while (0)
2601 #define skb_tx_hash(n, s) ___kc_skb_tx_hash((n), (s), (n)->real_num_tx_queues)
2602 #ifndef CONFIG_PCI_IOV
2603 #undef pci_enable_sriov
2604 #define pci_enable_sriov(a, b) -ENOTSUPP
2605 #undef pci_disable_sriov
2606 #define pci_disable_sriov(a) do {} while (0)
2607 #endif /* CONFIG_PCI_IOV */
2608 #ifndef pr_cont
2609 #define pr_cont(fmt, ...) \
2610         printk(KERN_CONT fmt, ##__VA_ARGS__)
2611 #endif /* pr_cont */
2612 static inline void _kc_synchronize_irq(unsigned int a)
2613 {
2614 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )
2615         synchronize_irq();
2616 #else /* < 2.5.28 */
2617         synchronize_irq(a);
2618 #endif /* < 2.5.28 */
2619 }
2620 #undef synchronize_irq
2621 #define synchronize_irq(a) _kc_synchronize_irq(a)
2622
2623 #define PCI_EXP_LNKCTL2         48      /* Link Control 2 */
2624
2625 #else /* < 2.6.30 */
2626 #define HAVE_ASPM_QUIRKS
2627 #endif /* < 2.6.30 */
2628
2629 /*****************************************************************************/
2630 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) )
2631 #define ETH_P_1588 0x88F7
2632 #define ETH_P_FIP  0x8914
2633 #ifndef netdev_uc_count
2634 #define netdev_uc_count(dev) ((dev)->uc_count)
2635 #endif
2636 #ifndef netdev_for_each_uc_addr
2637 #define netdev_for_each_uc_addr(uclist, dev) \
2638         for (uclist = dev->uc_list; uclist; uclist = uclist->next)
2639 #endif
2640 #ifndef PORT_OTHER
2641 #define PORT_OTHER 0xff
2642 #endif
2643 #ifndef MDIO_PHY_ID_PRTAD
2644 #define MDIO_PHY_ID_PRTAD 0x03e0
2645 #endif
2646 #ifndef MDIO_PHY_ID_DEVAD
2647 #define MDIO_PHY_ID_DEVAD 0x001f
2648 #endif
2649 #ifndef skb_dst
2650 #define skb_dst(s) ((s)->dst)
2651 #endif
2652
2653 #ifndef SUPPORTED_1000baseKX_Full
2654 #define SUPPORTED_1000baseKX_Full       (1 << 17)
2655 #endif
2656 #ifndef SUPPORTED_10000baseKX4_Full
2657 #define SUPPORTED_10000baseKX4_Full     (1 << 18)
2658 #endif
2659 #ifndef SUPPORTED_10000baseKR_Full
2660 #define SUPPORTED_10000baseKR_Full      (1 << 19)
2661 #endif
2662
2663 #ifndef ADVERTISED_1000baseKX_Full
2664 #define ADVERTISED_1000baseKX_Full      (1 << 17)
2665 #endif
2666 #ifndef ADVERTISED_10000baseKX4_Full
2667 #define ADVERTISED_10000baseKX4_Full    (1 << 18)
2668 #endif
2669 #ifndef ADVERTISED_10000baseKR_Full
2670 #define ADVERTISED_10000baseKR_Full     (1 << 19)
2671 #endif
2672
2673 #else /* < 2.6.31 */
2674 #ifndef HAVE_NETDEV_STORAGE_ADDRESS
2675 #define HAVE_NETDEV_STORAGE_ADDRESS
2676 #endif
2677 #ifndef HAVE_NETDEV_HW_ADDR
2678 #define HAVE_NETDEV_HW_ADDR
2679 #endif
2680 #ifndef HAVE_TRANS_START_IN_QUEUE
2681 #define HAVE_TRANS_START_IN_QUEUE
2682 #endif
2683 #ifndef HAVE_INCLUDE_LINUX_MDIO_H
2684 #define HAVE_INCLUDE_LINUX_MDIO_H
2685 #endif
2686 #endif /* < 2.6.31 */
2687
2688 /*****************************************************************************/
2689 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) )
2690 #undef netdev_tx_t
2691 #define netdev_tx_t int
2692 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2693 #ifndef NETIF_F_FCOE_MTU
2694 #define NETIF_F_FCOE_MTU       (1 << 26)
2695 #endif
2696 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2697
2698 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
2699 static inline int _kc_pm_runtime_get_sync()
2700 {
2701         return 1;
2702 }
2703 #define pm_runtime_get_sync(dev)        _kc_pm_runtime_get_sync()
2704 #else /* 2.6.0 => 2.6.32 */
2705 static inline int _kc_pm_runtime_get_sync(struct device *dev)
2706 {
2707         return 1;
2708 }
2709 #ifndef pm_runtime_get_sync
2710 #define pm_runtime_get_sync(dev)        _kc_pm_runtime_get_sync(dev)
2711 #endif
2712 #endif /* 2.6.0 => 2.6.32 */
2713 #ifndef pm_runtime_put
2714 #define pm_runtime_put(dev)             do {} while (0)
2715 #endif
2716 #ifndef pm_runtime_put_sync
2717 #define pm_runtime_put_sync(dev)        do {} while (0)
2718 #endif
2719 #ifndef pm_runtime_resume
2720 #define pm_runtime_resume(dev)          do {} while (0)
2721 #endif
2722 #ifndef pm_schedule_suspend
2723 #define pm_schedule_suspend(dev, t)     do {} while (0)
2724 #endif
2725 #ifndef pm_runtime_set_suspended
2726 #define pm_runtime_set_suspended(dev)   do {} while (0)
2727 #endif
2728 #ifndef pm_runtime_disable
2729 #define pm_runtime_disable(dev)         do {} while (0)
2730 #endif
2731 #ifndef pm_runtime_put_noidle
2732 #define pm_runtime_put_noidle(dev)      do {} while (0)
2733 #endif
2734 #ifndef pm_runtime_set_active
2735 #define pm_runtime_set_active(dev)      do {} while (0)
2736 #endif
2737 #ifndef pm_runtime_enable
2738 #define pm_runtime_enable(dev)  do {} while (0)
2739 #endif
2740 #ifndef pm_runtime_get_noresume
2741 #define pm_runtime_get_noresume(dev)    do {} while (0)
2742 #endif
2743 #else /* < 2.6.32 */
2744 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2745 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2746 #define HAVE_NETDEV_OPS_FCOE_ENABLE
2747 #endif
2748 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2749 #ifdef CONFIG_DCB
2750 #ifndef HAVE_DCBNL_OPS_GETAPP
2751 #define HAVE_DCBNL_OPS_GETAPP
2752 #endif
2753 #endif /* CONFIG_DCB */
2754 #include <linux/pm_runtime.h>
2755 /* IOV bad DMA target work arounds require at least this kernel rev support */
2756 #define HAVE_PCIE_TYPE
2757 #endif /* < 2.6.32 */
2758
2759 /*****************************************************************************/
2760 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) )
2761 #ifndef pci_pcie_cap
2762 #define pci_pcie_cap(pdev) pci_find_capability(pdev, PCI_CAP_ID_EXP)
2763 #endif
2764 #ifndef IPV4_FLOW
2765 #define IPV4_FLOW 0x10
2766 #endif /* IPV4_FLOW */
2767 #ifndef IPV6_FLOW
2768 #define IPV6_FLOW 0x11
2769 #endif /* IPV6_FLOW */
2770 /* Features back-ported to RHEL6 or SLES11 SP1 after 2.6.32 */
2771 #if ( (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)) || \
2772       (SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,1,0)) )
2773 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2774 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2775 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2776 #endif
2777 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2778 #endif /* RHEL6 or SLES11 SP1 */
2779 #ifndef __percpu
2780 #define __percpu
2781 #endif /* __percpu */
2782 #ifndef PORT_DA
2783 #define PORT_DA PORT_OTHER
2784 #endif
2785 #ifndef PORT_NONE
2786 #define PORT_NONE PORT_OTHER
2787 #endif
2788
2789 #if ((RHEL_RELEASE_CODE && \
2790      (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,3)) && \
2791      (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0))))
2792 #if !defined(CONFIG_X86_32) && !defined(CONFIG_NEED_DMA_MAP_STATE)
2793 #undef DEFINE_DMA_UNMAP_ADDR
2794 #define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)        dma_addr_t ADDR_NAME
2795 #undef DEFINE_DMA_UNMAP_LEN
2796 #define DEFINE_DMA_UNMAP_LEN(LEN_NAME)          __u32 LEN_NAME
2797 #undef dma_unmap_addr
2798 #define dma_unmap_addr(PTR, ADDR_NAME)          ((PTR)->ADDR_NAME)
2799 #undef dma_unmap_addr_set
2800 #define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL))
2801 #undef dma_unmap_len
2802 #define dma_unmap_len(PTR, LEN_NAME)            ((PTR)->LEN_NAME)
2803 #undef dma_unmap_len_set
2804 #define dma_unmap_len_set(PTR, LEN_NAME, VAL)   (((PTR)->LEN_NAME) = (VAL))
2805 #endif /* CONFIG_X86_64 && !CONFIG_NEED_DMA_MAP_STATE */
2806 #endif /* RHEL_RELEASE_CODE */
2807
2808 #if (!(RHEL_RELEASE_CODE && \
2809        (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,8)) && \
2810          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))) || \
2811         ((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,1)) && \
2812          (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0))))))
2813 static inline bool pci_is_pcie(struct pci_dev *dev)
2814 {
2815         return !!pci_pcie_cap(dev);
2816 }
2817 #endif /* RHEL_RELEASE_CODE */
2818
2819 #ifndef __always_unused
2820 #define __always_unused __attribute__((__unused__))
2821 #endif
2822 #ifndef __maybe_unused
2823 #define __maybe_unused __attribute__((__unused__))
2824 #endif
2825
2826 #if (!(RHEL_RELEASE_CODE && \
2827       (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,2))))
2828 #define sk_tx_queue_get(_sk) (-1)
2829 #define sk_tx_queue_set(_sk, _tx_queue) do {} while(0)
2830 #endif /* !(RHEL >= 6.2) */
2831
2832 #if (RHEL_RELEASE_CODE && \
2833      (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,4)) && \
2834      (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0)))
2835 #define HAVE_RHEL6_ETHTOOL_OPS_EXT_STRUCT
2836 #define HAVE_ETHTOOL_SET_PHYS_ID
2837 #define HAVE_ETHTOOL_GET_TS_INFO
2838 #endif /* RHEL >= 6.4 && RHEL < 7.0 */
2839
2840 #if (RHEL_RELEASE_CODE && \
2841      (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,5)) && \
2842      (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0)))
2843 #define HAVE_RHEL6_NETDEV_OPS_EXT_FDB
2844 #endif /* RHEL >= 6.5 && RHEL < 7.0 */
2845
2846 #else /* < 2.6.33 */
2847 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2848 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2849 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2850 #endif
2851 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2852 #endif /* < 2.6.33 */
2853
2854 /*****************************************************************************/
2855 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) )
2856 #if (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
2857 #ifndef pci_num_vf
2858 #define pci_num_vf(pdev) _kc_pci_num_vf(pdev)
2859 extern int _kc_pci_num_vf(struct pci_dev *dev);
2860 #endif
2861 #endif /* RHEL_RELEASE_CODE */
2862
2863 #ifndef ETH_FLAG_NTUPLE
2864 #define ETH_FLAG_NTUPLE NETIF_F_NTUPLE
2865 #endif
2866
2867 #ifndef netdev_mc_count
2868 #define netdev_mc_count(dev) ((dev)->mc_count)
2869 #endif
2870 #ifndef netdev_mc_empty
2871 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
2872 #endif
2873 #ifndef netdev_for_each_mc_addr
2874 #define netdev_for_each_mc_addr(mclist, dev) \
2875         for (mclist = dev->mc_list; mclist; mclist = mclist->next)
2876 #endif
2877 #ifndef netdev_uc_count
2878 #define netdev_uc_count(dev) ((dev)->uc.count)
2879 #endif
2880 #ifndef netdev_uc_empty
2881 #define netdev_uc_empty(dev) (netdev_uc_count(dev) == 0)
2882 #endif
2883 #ifndef netdev_for_each_uc_addr
2884 #define netdev_for_each_uc_addr(ha, dev) \
2885         list_for_each_entry(ha, &dev->uc.list, list)
2886 #endif
2887 #ifndef dma_set_coherent_mask
2888 #define dma_set_coherent_mask(dev,mask) \
2889         pci_set_consistent_dma_mask(to_pci_dev(dev),(mask))
2890 #endif
2891 #ifndef pci_dev_run_wake
2892 #define pci_dev_run_wake(pdev)  (0)
2893 #endif
2894
2895 /* netdev logging taken from include/linux/netdevice.h */
2896 #ifndef netdev_name
2897 static inline const char *_kc_netdev_name(const struct net_device *dev)
2898 {
2899         if (dev->reg_state != NETREG_REGISTERED)
2900                 return "(unregistered net_device)";
2901         return dev->name;
2902 }
2903 #define netdev_name(netdev)     _kc_netdev_name(netdev)
2904 #endif /* netdev_name */
2905
2906 #undef netdev_printk
2907 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
2908 #define netdev_printk(level, netdev, format, args...)           \
2909 do {                                                            \
2910         struct pci_dev *pdev = _kc_netdev_to_pdev(netdev);      \
2911         printk(level "%s: " format, pci_name(pdev), ##args);    \
2912 } while(0)
2913 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
2914 #define netdev_printk(level, netdev, format, args...)           \
2915 do {                                                            \
2916         struct pci_dev *pdev = _kc_netdev_to_pdev(netdev);      \
2917         struct device *dev = pci_dev_to_dev(pdev);              \
2918         dev_printk(level, dev, "%s: " format,                   \
2919                    netdev_name(netdev), ##args);                \
2920 } while(0)
2921 #else /* 2.6.21 => 2.6.34 */
2922 #define netdev_printk(level, netdev, format, args...)           \
2923         dev_printk(level, (netdev)->dev.parent,                 \
2924                    "%s: " format,                               \
2925                    netdev_name(netdev), ##args)
2926 #endif /* <2.6.0 <2.6.21 <2.6.34 */
2927 #undef netdev_emerg
2928 #define netdev_emerg(dev, format, args...)                      \
2929         netdev_printk(KERN_EMERG, dev, format, ##args)
2930 #undef netdev_alert
2931 #define netdev_alert(dev, format, args...)                      \
2932         netdev_printk(KERN_ALERT, dev, format, ##args)
2933 #undef netdev_crit
2934 #define netdev_crit(dev, format, args...)                       \
2935         netdev_printk(KERN_CRIT, dev, format, ##args)
2936 #undef netdev_err
2937 #define netdev_err(dev, format, args...)                        \
2938         netdev_printk(KERN_ERR, dev, format, ##args)
2939 #undef netdev_warn
2940 #define netdev_warn(dev, format, args...)                       \
2941         netdev_printk(KERN_WARNING, dev, format, ##args)
2942 #undef netdev_notice
2943 #define netdev_notice(dev, format, args...)                     \
2944         netdev_printk(KERN_NOTICE, dev, format, ##args)
2945 #undef netdev_info
2946 #define netdev_info(dev, format, args...)                       \
2947         netdev_printk(KERN_INFO, dev, format, ##args)
2948 #undef netdev_dbg
2949 #if defined(DEBUG)
2950 #define netdev_dbg(__dev, format, args...)                      \
2951         netdev_printk(KERN_DEBUG, __dev, format, ##args)
2952 #elif defined(CONFIG_DYNAMIC_DEBUG)
2953 #define netdev_dbg(__dev, format, args...)                      \
2954 do {                                                            \
2955         dynamic_dev_dbg((__dev)->dev.parent, "%s: " format,     \
2956                         netdev_name(__dev), ##args);            \
2957 } while (0)
2958 #else /* DEBUG */
2959 #define netdev_dbg(__dev, format, args...)                      \
2960 ({                                                              \
2961         if (0)                                                  \
2962                 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
2963         0;                                                      \
2964 })
2965 #endif /* DEBUG */
2966
2967 #undef netif_printk
2968 #define netif_printk(priv, type, level, dev, fmt, args...)      \
2969 do {                                                            \
2970         if (netif_msg_##type(priv))                             \
2971                 netdev_printk(level, (dev), fmt, ##args);       \
2972 } while (0)
2973
2974 #undef netif_emerg
2975 #define netif_emerg(priv, type, dev, fmt, args...)              \
2976         netif_level(emerg, priv, type, dev, fmt, ##args)
2977 #undef netif_alert
2978 #define netif_alert(priv, type, dev, fmt, args...)              \
2979         netif_level(alert, priv, type, dev, fmt, ##args)
2980 #undef netif_crit
2981 #define netif_crit(priv, type, dev, fmt, args...)               \
2982         netif_level(crit, priv, type, dev, fmt, ##args)
2983 #undef netif_err
2984 #define netif_err(priv, type, dev, fmt, args...)                \
2985         netif_level(err, priv, type, dev, fmt, ##args)
2986 #undef netif_warn
2987 #define netif_warn(priv, type, dev, fmt, args...)               \
2988         netif_level(warn, priv, type, dev, fmt, ##args)
2989 #undef netif_notice
2990 #define netif_notice(priv, type, dev, fmt, args...)             \
2991         netif_level(notice, priv, type, dev, fmt, ##args)
2992 #undef netif_info
2993 #define netif_info(priv, type, dev, fmt, args...)               \
2994         netif_level(info, priv, type, dev, fmt, ##args)
2995 #undef netif_dbg
2996 #define netif_dbg(priv, type, dev, fmt, args...)                \
2997         netif_level(dbg, priv, type, dev, fmt, ##args)
2998
2999 #ifdef SET_SYSTEM_SLEEP_PM_OPS
3000 #define HAVE_SYSTEM_SLEEP_PM_OPS
3001 #endif
3002
3003 #ifndef for_each_set_bit
3004 #define for_each_set_bit(bit, addr, size) \
3005         for ((bit) = find_first_bit((addr), (size)); \
3006                 (bit) < (size); \
3007                 (bit) = find_next_bit((addr), (size), (bit) + 1))
3008 #endif /* for_each_set_bit */
3009
3010 #ifndef DEFINE_DMA_UNMAP_ADDR
3011 #define DEFINE_DMA_UNMAP_ADDR DECLARE_PCI_UNMAP_ADDR
3012 #define DEFINE_DMA_UNMAP_LEN DECLARE_PCI_UNMAP_LEN
3013 #define dma_unmap_addr pci_unmap_addr
3014 #define dma_unmap_addr_set pci_unmap_addr_set
3015 #define dma_unmap_len pci_unmap_len
3016 #define dma_unmap_len_set pci_unmap_len_set
3017 #endif /* DEFINE_DMA_UNMAP_ADDR */
3018
3019 #if (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,3))
3020 #ifdef IGB_HWMON
3021 #ifdef CONFIG_DEBUG_LOCK_ALLOC
3022 #define sysfs_attr_init(attr)                           \
3023         do {                                            \
3024                 static struct lock_class_key __key;     \
3025                 (attr)->key = &__key;                   \
3026         } while (0)
3027 #else
3028 #define sysfs_attr_init(attr) do {} while (0)
3029 #endif /* CONFIG_DEBUG_LOCK_ALLOC */
3030 #endif /* IGB_HWMON */
3031 #endif /* RHEL_RELEASE_CODE */
3032
3033 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
3034 static inline bool _kc_pm_runtime_suspended()
3035 {
3036         return false;
3037 }
3038 #define pm_runtime_suspended(dev)       _kc_pm_runtime_suspended()
3039 #else /* 2.6.0 => 2.6.34 */
3040 static inline bool _kc_pm_runtime_suspended(struct device *dev)
3041 {
3042         return false;
3043 }
3044 #ifndef pm_runtime_suspended
3045 #define pm_runtime_suspended(dev)       _kc_pm_runtime_suspended(dev)
3046 #endif
3047 #endif /* 2.6.0 => 2.6.34 */
3048
3049 #else /* < 2.6.34 */
3050 #define HAVE_SYSTEM_SLEEP_PM_OPS
3051 #ifndef HAVE_SET_RX_MODE
3052 #define HAVE_SET_RX_MODE
3053 #endif
3054
3055 #endif /* < 2.6.34 */
3056
3057 /*****************************************************************************/
3058 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) )
3059
3060 ssize_t _kc_simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
3061                                    const void __user *from, size_t count);
3062 #define simple_write_to_buffer _kc_simple_write_to_buffer
3063
3064 #ifndef numa_node_id
3065 #define numa_node_id() 0
3066 #endif
3067 #ifdef HAVE_TX_MQ
3068 #include <net/sch_generic.h>
3069 #ifndef CONFIG_NETDEVICES_MULTIQUEUE
3070 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)))
3071 void _kc_netif_set_real_num_tx_queues(struct net_device *, unsigned int);
3072 #define netif_set_real_num_tx_queues  _kc_netif_set_real_num_tx_queues
3073 #endif /* !(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)) */
3074 #else /* CONFIG_NETDEVICES_MULTI_QUEUE */
3075 #define netif_set_real_num_tx_queues(_netdev, _count) \
3076         do { \
3077                 (_netdev)->egress_subqueue_count = _count; \
3078         } while (0)
3079 #endif /* CONFIG_NETDEVICES_MULTI_QUEUE */
3080 #else /* HAVE_TX_MQ */
3081 #define netif_set_real_num_tx_queues(_netdev, _count) do {} while(0)
3082 #endif /* HAVE_TX_MQ */
3083 #ifndef ETH_FLAG_RXHASH
3084 #define ETH_FLAG_RXHASH (1<<28)
3085 #endif /* ETH_FLAG_RXHASH */
3086 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0))
3087 #define HAVE_IRQ_AFFINITY_HINT
3088 #endif
3089 #else /* < 2.6.35 */
3090 #define HAVE_PM_QOS_REQUEST_LIST
3091 #define HAVE_IRQ_AFFINITY_HINT
3092 #endif /* < 2.6.35 */
3093
3094 /*****************************************************************************/
3095 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) )
3096 extern int _kc_ethtool_op_set_flags(struct net_device *, u32, u32);
3097 #define ethtool_op_set_flags _kc_ethtool_op_set_flags
3098 extern u32 _kc_ethtool_op_get_flags(struct net_device *);
3099 #define ethtool_op_get_flags _kc_ethtool_op_get_flags
3100
3101 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
3102 #ifdef NET_IP_ALIGN
3103 #undef NET_IP_ALIGN
3104 #endif
3105 #define NET_IP_ALIGN 0
3106 #endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
3107
3108 #ifdef NET_SKB_PAD
3109 #undef NET_SKB_PAD
3110 #endif
3111
3112 #if (L1_CACHE_BYTES > 32)
3113 #define NET_SKB_PAD L1_CACHE_BYTES
3114 #else
3115 #define NET_SKB_PAD 32
3116 #endif
3117
3118 static inline struct sk_buff *_kc_netdev_alloc_skb_ip_align(struct net_device *dev,
3119                                                             unsigned int length)
3120 {
3121         struct sk_buff *skb;
3122
3123         skb = alloc_skb(length + NET_SKB_PAD + NET_IP_ALIGN, GFP_ATOMIC);
3124         if (skb) {
3125 #if (NET_IP_ALIGN + NET_SKB_PAD)
3126                 skb_reserve(skb, NET_IP_ALIGN + NET_SKB_PAD);
3127 #endif
3128                 skb->dev = dev;
3129         }
3130         return skb;
3131 }
3132
3133 #ifdef netdev_alloc_skb_ip_align
3134 #undef netdev_alloc_skb_ip_align
3135 #endif
3136 #define netdev_alloc_skb_ip_align(n, l) _kc_netdev_alloc_skb_ip_align(n, l)
3137
3138 #undef netif_level
3139 #define netif_level(level, priv, type, dev, fmt, args...)       \
3140 do {                                                            \
3141         if (netif_msg_##type(priv))                             \
3142                 netdev_##level(dev, fmt, ##args);               \
3143 } while (0)
3144
3145 #undef usleep_range
3146 #define usleep_range(min, max)  msleep(DIV_ROUND_UP(min, 1000))
3147
3148 #define u64_stats_update_begin(a) do { } while(0)
3149 #define u64_stats_update_end(a) do { } while(0)
3150 #define u64_stats_fetch_begin(a) do { } while(0)
3151 #define u64_stats_fetch_retry_bh(a) (0)
3152 #define u64_stats_fetch_begin_bh(a) (0)
3153
3154 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,1))
3155 #define HAVE_8021P_SUPPORT
3156 #endif
3157
3158 #else /* < 2.6.36 */
3159
3160
3161 #define HAVE_PM_QOS_REQUEST_ACTIVE
3162 #define HAVE_8021P_SUPPORT
3163 #define HAVE_NDO_GET_STATS64
3164 #endif /* < 2.6.36 */
3165
3166 /*****************************************************************************/
3167 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) )
3168 #ifndef netif_set_real_num_rx_queues
3169 static inline int __kc_netif_set_real_num_rx_queues(struct net_device *dev,
3170                                                     unsigned int rxq)
3171 {
3172         return 0;
3173 }
3174 #define netif_set_real_num_rx_queues(dev, rxq) \
3175         __kc_netif_set_real_num_rx_queues((dev), (rxq))
3176 #endif
3177 #ifndef ETHTOOL_RXNTUPLE_ACTION_CLEAR
3178 #define ETHTOOL_RXNTUPLE_ACTION_CLEAR (-2)
3179 #endif
3180 #ifndef VLAN_N_VID
3181 #define VLAN_N_VID      VLAN_GROUP_ARRAY_LEN
3182 #endif /* VLAN_N_VID */
3183 #ifndef ETH_FLAG_TXVLAN
3184 #define ETH_FLAG_TXVLAN (1 << 7)
3185 #endif /* ETH_FLAG_TXVLAN */
3186 #ifndef ETH_FLAG_RXVLAN
3187 #define ETH_FLAG_RXVLAN (1 << 8)
3188 #endif /* ETH_FLAG_RXVLAN */
3189
3190 static inline void _kc_skb_checksum_none_assert(struct sk_buff *skb)
3191 {
3192         WARN_ON(skb->ip_summed != CHECKSUM_NONE);
3193 }
3194 #define skb_checksum_none_assert(skb) _kc_skb_checksum_none_assert(skb)
3195
3196 static inline void *_kc_vzalloc_node(unsigned long size, int node)
3197 {
3198         void *addr = vmalloc_node(size, node);
3199         if (addr)
3200                 memset(addr, 0, size);
3201         return addr;
3202 }
3203 #define vzalloc_node(_size, _node) _kc_vzalloc_node(_size, _node)
3204
3205 static inline void *_kc_vzalloc(unsigned long size)
3206 {
3207         void *addr = vmalloc(size);
3208         if (addr)
3209                 memset(addr, 0, size);
3210         return addr;
3211 }
3212 #define vzalloc(_size) _kc_vzalloc(_size)
3213
3214 #ifndef vlan_get_protocol
3215 static inline __be16 __kc_vlan_get_protocol(const struct sk_buff *skb)
3216 {
3217         if (vlan_tx_tag_present(skb) ||
3218             skb->protocol != cpu_to_be16(ETH_P_8021Q))
3219                 return skb->protocol;
3220
3221         if (skb_headlen(skb) < sizeof(struct vlan_ethhdr))
3222                 return 0;
3223
3224         return ((struct vlan_ethhdr*)skb->data)->h_vlan_encapsulated_proto;
3225 }
3226 #define vlan_get_protocol(_skb) __kc_vlan_get_protocol(_skb)
3227 #endif
3228 #ifdef HAVE_HW_TIME_STAMP
3229 #define SKBTX_HW_TSTAMP (1 << 0)
3230 #define SKBTX_IN_PROGRESS (1 << 2)
3231 #define SKB_SHARED_TX_IS_UNION
3232 #endif
3233
3234 #ifndef device_wakeup_enable
3235 #define device_wakeup_enable(dev)       device_set_wakeup_enable(dev, true)
3236 #endif
3237
3238 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,18) )
3239 #ifndef HAVE_VLAN_RX_REGISTER
3240 #define HAVE_VLAN_RX_REGISTER
3241 #endif
3242 #endif /* > 2.4.18 */
3243 #endif /* < 2.6.37 */
3244
3245 /*****************************************************************************/
3246 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) )
3247 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
3248 #define skb_checksum_start_offset(skb) skb_transport_offset(skb)
3249 #else /* 2.6.22 -> 2.6.37 */
3250 static inline int _kc_skb_checksum_start_offset(const struct sk_buff *skb)
3251 {
3252         return skb->csum_start - skb_headroom(skb);
3253 }
3254 #define skb_checksum_start_offset(skb) _kc_skb_checksum_start_offset(skb)
3255 #endif /* 2.6.22 -> 2.6.37 */
3256 #ifdef CONFIG_DCB
3257 #ifndef IEEE_8021QAZ_MAX_TCS
3258 #define IEEE_8021QAZ_MAX_TCS 8
3259 #endif
3260 #ifndef DCB_CAP_DCBX_HOST
3261 #define DCB_CAP_DCBX_HOST               0x01
3262 #endif
3263 #ifndef DCB_CAP_DCBX_LLD_MANAGED
3264 #define DCB_CAP_DCBX_LLD_MANAGED        0x02
3265 #endif
3266 #ifndef DCB_CAP_DCBX_VER_CEE
3267 #define DCB_CAP_DCBX_VER_CEE            0x04
3268 #endif
3269 #ifndef DCB_CAP_DCBX_VER_IEEE
3270 #define DCB_CAP_DCBX_VER_IEEE           0x08
3271 #endif
3272 #ifndef DCB_CAP_DCBX_STATIC
3273 #define DCB_CAP_DCBX_STATIC             0x10
3274 #endif
3275 #endif /* CONFIG_DCB */
3276 #if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,2))
3277 #define CONFIG_XPS
3278 #endif /* RHEL_RELEASE_VERSION(6,2) */
3279 #endif /* < 2.6.38 */
3280
3281 /*****************************************************************************/
3282 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) )
3283 #ifndef NETIF_F_RXCSUM
3284 #define NETIF_F_RXCSUM          (1 << 29)
3285 #endif
3286 #ifndef skb_queue_reverse_walk_safe
3287 #define skb_queue_reverse_walk_safe(queue, skb, tmp)                            \
3288                 for (skb = (queue)->prev, tmp = skb->prev;                      \
3289                      skb != (struct sk_buff *)(queue);                          \
3290                      skb = tmp, tmp = skb->prev)
3291 #endif
3292 #else /* < 2.6.39 */
3293 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
3294 #ifndef HAVE_NETDEV_OPS_FCOE_DDP_TARGET
3295 #define HAVE_NETDEV_OPS_FCOE_DDP_TARGET
3296 #endif
3297 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
3298 #ifndef HAVE_MQPRIO
3299 #define HAVE_MQPRIO
3300 #endif
3301 #ifndef HAVE_SETUP_TC
3302 #define HAVE_SETUP_TC
3303 #endif
3304 #ifdef CONFIG_DCB
3305 #ifndef HAVE_DCBNL_IEEE
3306 #define HAVE_DCBNL_IEEE
3307 #endif
3308 #endif /* CONFIG_DCB */
3309 #ifndef HAVE_NDO_SET_FEATURES
3310 #define HAVE_NDO_SET_FEATURES
3311 #endif
3312 #endif /* < 2.6.39 */
3313
3314 /*****************************************************************************/
3315 /* use < 2.6.40 because of a Fedora 15 kernel update where they
3316  * updated the kernel version to 2.6.40.x and they back-ported 3.0 features
3317  * like set_phys_id for ethtool.
3318  */
3319 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40) )
3320 #ifdef ETHTOOL_GRXRINGS
3321 #ifndef FLOW_EXT
3322 #define FLOW_EXT        0x80000000
3323 union _kc_ethtool_flow_union {
3324         struct ethtool_tcpip4_spec              tcp_ip4_spec;
3325         struct ethtool_usrip4_spec              usr_ip4_spec;
3326         __u8                                    hdata[60];
3327 };
3328 struct _kc_ethtool_flow_ext {
3329         __be16  vlan_etype;
3330         __be16  vlan_tci;
3331         __be32  data[2];
3332 };
3333 struct _kc_ethtool_rx_flow_spec {
3334         __u32           flow_type;
3335         union _kc_ethtool_flow_union h_u;
3336         struct _kc_ethtool_flow_ext h_ext;
3337         union _kc_ethtool_flow_union m_u;
3338         struct _kc_ethtool_flow_ext m_ext;
3339         __u64           ring_cookie;
3340         __u32           location;
3341 };
3342 #define ethtool_rx_flow_spec _kc_ethtool_rx_flow_spec
3343 #endif /* FLOW_EXT */
3344 #endif
3345
3346 #define pci_disable_link_state_locked pci_disable_link_state
3347
3348 #ifndef PCI_LTR_VALUE_MASK
3349 #define  PCI_LTR_VALUE_MASK     0x000003ff
3350 #endif
3351 #ifndef PCI_LTR_SCALE_MASK
3352 #define  PCI_LTR_SCALE_MASK     0x00001c00
3353 #endif
3354 #ifndef PCI_LTR_SCALE_SHIFT
3355 #define  PCI_LTR_SCALE_SHIFT    10
3356 #endif
3357
3358 #else /* < 2.6.40 */
3359 #define HAVE_ETHTOOL_SET_PHYS_ID
3360 #endif /* < 2.6.40 */
3361
3362 /*****************************************************************************/
3363 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) )
3364 #define USE_LEGACY_PM_SUPPORT
3365 #endif /* < 3.0.0 */
3366
3367 /*****************************************************************************/
3368 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
3369 #ifndef __netdev_alloc_skb_ip_align
3370 #define __netdev_alloc_skb_ip_align(d,l,_g) netdev_alloc_skb_ip_align(d,l)
3371 #endif /* __netdev_alloc_skb_ip_align */
3372 #define dcb_ieee_setapp(dev, app) dcb_setapp(dev, app)
3373 #define dcb_ieee_delapp(dev, app) 0
3374 #define dcb_ieee_getapp_mask(dev, app) (1 << app->priority)
3375
3376 /* 1000BASE-T Control register */
3377 #define CTL1000_AS_MASTER       0x0800
3378 #define CTL1000_ENABLE_MASTER   0x1000
3379
3380 #else /* < 3.1.0 */
3381 #ifndef HAVE_DCBNL_IEEE_DELAPP
3382 #define HAVE_DCBNL_IEEE_DELAPP
3383 #endif
3384 #endif /* < 3.1.0 */
3385
3386 /*****************************************************************************/
3387 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
3388 #ifdef ETHTOOL_GRXRINGS
3389 #define HAVE_ETHTOOL_GET_RXNFC_VOID_RULE_LOCS
3390 #endif /* ETHTOOL_GRXRINGS */
3391
3392 #ifndef skb_frag_size
3393 #define skb_frag_size(frag)     _kc_skb_frag_size(frag)
3394 static inline unsigned int _kc_skb_frag_size(const skb_frag_t *frag)
3395 {
3396         return frag->size;
3397 }
3398 #endif /* skb_frag_size */
3399
3400 #ifndef skb_frag_size_sub
3401 #define skb_frag_size_sub(frag, delta)  _kc_skb_frag_size_sub(frag, delta)
3402 static inline void _kc_skb_frag_size_sub(skb_frag_t *frag, int delta)
3403 {
3404         frag->size -= delta;
3405 }
3406 #endif /* skb_frag_size_sub */
3407
3408 #ifndef skb_frag_page
3409 #define skb_frag_page(frag)     _kc_skb_frag_page(frag)
3410 static inline struct page *_kc_skb_frag_page(const skb_frag_t *frag)
3411 {
3412         return frag->page;
3413 }
3414 #endif /* skb_frag_page */
3415
3416 #ifndef skb_frag_address
3417 #define skb_frag_address(frag)  _kc_skb_frag_address(frag)
3418 static inline void *_kc_skb_frag_address(const skb_frag_t *frag)
3419 {
3420         return page_address(skb_frag_page(frag)) + frag->page_offset;
3421 }
3422 #endif /* skb_frag_address */
3423
3424 #ifndef skb_frag_dma_map
3425 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) )
3426 #include <linux/dma-mapping.h>
3427 #endif
3428 #define skb_frag_dma_map(dev,frag,offset,size,dir) \
3429                 _kc_skb_frag_dma_map(dev,frag,offset,size,dir)
3430 static inline dma_addr_t _kc_skb_frag_dma_map(struct device *dev,
3431                                               const skb_frag_t *frag,
3432                                               size_t offset, size_t size,
3433                                               enum dma_data_direction dir)
3434 {
3435         return dma_map_page(dev, skb_frag_page(frag),
3436                             frag->page_offset + offset, size, dir);
3437 }
3438 #endif /* skb_frag_dma_map */
3439
3440 #ifndef __skb_frag_unref
3441 #define __skb_frag_unref(frag) __kc_skb_frag_unref(frag)
3442 static inline void __kc_skb_frag_unref(skb_frag_t *frag)
3443 {
3444         put_page(skb_frag_page(frag));
3445 }
3446 #endif /* __skb_frag_unref */
3447
3448 #ifndef SPEED_UNKNOWN
3449 #define SPEED_UNKNOWN   -1
3450 #endif
3451 #ifndef DUPLEX_UNKNOWN
3452 #define DUPLEX_UNKNOWN  0xff
3453 #endif
3454 #if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,3))
3455 #ifndef HAVE_PCI_DEV_FLAGS_ASSIGNED
3456 #define HAVE_PCI_DEV_FLAGS_ASSIGNED
3457 #endif
3458 #endif
3459 #else /* < 3.2.0 */
3460 #ifndef HAVE_PCI_DEV_FLAGS_ASSIGNED
3461 #define HAVE_PCI_DEV_FLAGS_ASSIGNED
3462 #define HAVE_VF_SPOOFCHK_CONFIGURE
3463 #endif
3464 #endif /* < 3.2.0 */
3465
3466 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(6,2))
3467 #undef ixgbe_get_netdev_tc_txq
3468 #define ixgbe_get_netdev_tc_txq(dev, tc) (&netdev_extended(dev)->qos_data.tc_to_txq[tc])
3469 #endif
3470 /*****************************************************************************/
3471 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) )
3472 typedef u32 kni_netdev_features_t;
3473 #undef PCI_EXP_TYPE_RC_EC
3474 #define  PCI_EXP_TYPE_RC_EC     0xa     /* Root Complex Event Collector */
3475 #ifndef CONFIG_BQL
3476 #define netdev_tx_completed_queue(_q, _p, _b) do {} while (0)
3477 #define netdev_completed_queue(_n, _p, _b) do {} while (0)
3478 #define netdev_tx_sent_queue(_q, _b) do {} while (0)
3479 #define netdev_sent_queue(_n, _b) do {} while (0)
3480 #define netdev_tx_reset_queue(_q) do {} while (0)
3481 #define netdev_reset_queue(_n) do {} while (0)
3482 #endif
3483 #else /* ! < 3.3.0 */
3484 typedef netdev_features_t kni_netdev_features_t;
3485 #define HAVE_INT_NDO_VLAN_RX_ADD_VID
3486 #ifdef ETHTOOL_SRXNTUPLE
3487 #undef ETHTOOL_SRXNTUPLE
3488 #endif
3489 #endif /* < 3.3.0 */
3490
3491 /*****************************************************************************/
3492 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) )
3493 #ifndef NETIF_F_RXFCS
3494 #define NETIF_F_RXFCS   0
3495 #endif /* NETIF_F_RXFCS */
3496 #ifndef NETIF_F_RXALL
3497 #define NETIF_F_RXALL   0
3498 #endif /* NETIF_F_RXALL */
3499
3500 #if !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0))
3501 #define NUMTCS_RETURNS_U8
3502
3503 int _kc_simple_open(struct inode *inode, struct file *file);
3504 #define simple_open _kc_simple_open
3505 #endif /* !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0)) */
3506
3507
3508 #ifndef skb_add_rx_frag
3509 #define skb_add_rx_frag _kc_skb_add_rx_frag
3510 extern void _kc_skb_add_rx_frag(struct sk_buff *, int, struct page *,
3511                                 int, int, unsigned int);
3512 #endif
3513 #ifdef NET_ADDR_RANDOM
3514 #define eth_hw_addr_random(N) do { \
3515         random_ether_addr(N->dev_addr); \
3516         N->addr_assign_type |= NET_ADDR_RANDOM; \
3517         } while (0)
3518 #else /* NET_ADDR_RANDOM */
3519 #define eth_hw_addr_random(N) random_ether_addr(N->dev_addr)
3520 #endif /* NET_ADDR_RANDOM */
3521 #else /* < 3.4.0 */
3522 #include <linux/kconfig.h>
3523 #endif /* >= 3.4.0 */
3524
3525 /*****************************************************************************/
3526 #if defined(E1000E_PTP) || defined(IGB_PTP) || defined(IXGBE_PTP) || defined(I40E_PTP)
3527 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) ) && IS_ENABLED(CONFIG_PTP_1588_CLOCK)
3528 #define HAVE_PTP_1588_CLOCK
3529 #else
3530 #error Cannot enable PTP Hardware Clock support due to a pre-3.0 kernel version or CONFIG_PTP_1588_CLOCK not enabled in the kernel
3531 #endif /* > 3.0.0 && IS_ENABLED(CONFIG_PTP_1588_CLOCK) */
3532 #endif /* E1000E_PTP || IGB_PTP || IXGBE_PTP || I40E_PTP */
3533
3534 /*****************************************************************************/
3535 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) )
3536 #define skb_tx_timestamp(skb) do {} while (0)
3537 #if !(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,4))
3538 static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2)
3539 {
3540         return !compare_ether_addr(addr1, addr2);
3541 }
3542 #endif
3543 #else
3544 #define HAVE_FDB_OPS
3545 #define HAVE_ETHTOOL_GET_TS_INFO
3546 #endif /* < 3.5.0 */
3547
3548 /*****************************************************************************/
3549 #include <linux/mdio.h>
3550 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) )
3551 #define PCI_EXP_LNKCAP2         44      /* Link Capability 2 */
3552
3553 #ifndef MDIO_EEE_100TX
3554 #define MDIO_EEE_100TX          0x0002  /* 100TX EEE cap */
3555 #endif
3556 #ifndef MDIO_EEE_1000T
3557 #define MDIO_EEE_1000T          0x0004  /* 1000T EEE cap */
3558 #endif
3559 #ifndef MDIO_EEE_10GT
3560 #define MDIO_EEE_10GT           0x0008  /* 10GT EEE cap */
3561 #endif
3562 #ifndef MDIO_EEE_1000KX
3563 #define MDIO_EEE_1000KX         0x0010  /* 1000KX EEE cap */
3564 #endif
3565 #ifndef MDIO_EEE_10GKX4
3566 #define MDIO_EEE_10GKX4         0x0020  /* 10G KX4 EEE cap */
3567 #endif
3568 #ifndef MDIO_EEE_10GKR
3569 #define MDIO_EEE_10GKR          0x0040  /* 10G KR EEE cap */
3570 #endif
3571 #endif /* < 3.6.0 */
3572
3573 /******************************************************************************/
3574 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) )
3575 #ifndef ADVERTISED_40000baseKR4_Full
3576 /* these defines were all added in one commit, so should be safe
3577  * to trigger activiation on one define
3578  */
3579 #define SUPPORTED_40000baseKR4_Full     (1 << 23)
3580 #define SUPPORTED_40000baseCR4_Full     (1 << 24)
3581 #define SUPPORTED_40000baseSR4_Full     (1 << 25)
3582 #define SUPPORTED_40000baseLR4_Full     (1 << 26)
3583 #define ADVERTISED_40000baseKR4_Full    (1 << 23)
3584 #define ADVERTISED_40000baseCR4_Full    (1 << 24)
3585 #define ADVERTISED_40000baseSR4_Full    (1 << 25)
3586 #define ADVERTISED_40000baseLR4_Full    (1 << 26)
3587 #endif
3588
3589 #if !defined(ETHTOOL_GEEE) || (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE <= RHEL_RELEASE_VERSION(6,4))
3590 /**
3591  * mmd_eee_cap_to_ethtool_sup_t
3592  * @eee_cap: value of the MMD EEE Capability register
3593  *
3594  * A small helper function that translates MMD EEE Capability (3.20) bits
3595  * to ethtool supported settings.
3596  */
3597 static inline u32 mmd_eee_cap_to_ethtool_sup_t(u16 eee_cap)
3598 {
3599         u32 supported = 0;
3600
3601         if (eee_cap & MDIO_EEE_100TX)
3602                 supported |= SUPPORTED_100baseT_Full;
3603         if (eee_cap & MDIO_EEE_1000T)
3604                 supported |= SUPPORTED_1000baseT_Full;
3605         if (eee_cap & MDIO_EEE_10GT)
3606                 supported |= SUPPORTED_10000baseT_Full;
3607         if (eee_cap & MDIO_EEE_1000KX)
3608                 supported |= SUPPORTED_1000baseKX_Full;
3609         if (eee_cap & MDIO_EEE_10GKX4)
3610                 supported |= SUPPORTED_10000baseKX4_Full;
3611         if (eee_cap & MDIO_EEE_10GKR)
3612                 supported |= SUPPORTED_10000baseKR_Full;
3613
3614         return supported;
3615 }
3616
3617 /**
3618  * mmd_eee_adv_to_ethtool_adv_t
3619  * @eee_adv: value of the MMD EEE Advertisement/Link Partner Ability registers
3620  *
3621  * A small helper function that translates the MMD EEE Advertisement (7.60)
3622  * and MMD EEE Link Partner Ability (7.61) bits to ethtool advertisement
3623  * settings.
3624  */
3625 static inline u32 mmd_eee_adv_to_ethtool_adv_t(u16 eee_adv)
3626 {
3627         u32 adv = 0;
3628
3629         if (eee_adv & MDIO_EEE_100TX)
3630                 adv |= ADVERTISED_100baseT_Full;
3631         if (eee_adv & MDIO_EEE_1000T)
3632                 adv |= ADVERTISED_1000baseT_Full;
3633         if (eee_adv & MDIO_EEE_10GT)
3634                 adv |= ADVERTISED_10000baseT_Full;
3635         if (eee_adv & MDIO_EEE_1000KX)
3636                 adv |= ADVERTISED_1000baseKX_Full;
3637         if (eee_adv & MDIO_EEE_10GKX4)
3638                 adv |= ADVERTISED_10000baseKX4_Full;
3639         if (eee_adv & MDIO_EEE_10GKR)
3640                 adv |= ADVERTISED_10000baseKR_Full;
3641
3642         return adv;
3643 }
3644
3645 /**
3646  * ethtool_adv_to_mmd_eee_adv_t
3647  * @adv: the ethtool advertisement settings
3648  *
3649  * A small helper function that translates ethtool advertisement settings
3650  * to EEE advertisements for the MMD EEE Advertisement (7.60) and
3651  * MMD EEE Link Partner Ability (7.61) registers.
3652  */
3653 static inline u16 ethtool_adv_to_mmd_eee_adv_t(u32 adv)
3654 {
3655         u16 reg = 0;
3656
3657         if (adv & ADVERTISED_100baseT_Full)
3658                 reg |= MDIO_EEE_100TX;
3659         if (adv & ADVERTISED_1000baseT_Full)
3660                 reg |= MDIO_EEE_1000T;
3661         if (adv & ADVERTISED_10000baseT_Full)
3662                 reg |= MDIO_EEE_10GT;
3663         if (adv & ADVERTISED_1000baseKX_Full)
3664                 reg |= MDIO_EEE_1000KX;
3665         if (adv & ADVERTISED_10000baseKX4_Full)
3666                 reg |= MDIO_EEE_10GKX4;
3667         if (adv & ADVERTISED_10000baseKR_Full)
3668                 reg |= MDIO_EEE_10GKR;
3669
3670         return reg;
3671 }
3672 #endif
3673
3674 #ifndef pci_pcie_type
3675 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
3676 static inline u8 pci_pcie_type(struct pci_dev *pdev)
3677 {
3678         int pos;
3679         u16 reg16;
3680
3681         pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
3682         if (!pos)
3683                 BUG();
3684         pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
3685         return (reg16 & PCI_EXP_FLAGS_TYPE) >> 4;
3686 }
3687 #else /* < 2.6.24 */
3688 #define pci_pcie_type(x)        (x)->pcie_type
3689 #endif /* < 2.6.24 */
3690 #endif /* pci_pcie_type */
3691
3692 #define ptp_clock_register(caps, args...) ptp_clock_register(caps)
3693
3694 #ifndef PCI_EXP_LNKSTA2
3695 int __kc_pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
3696 #define pcie_capability_read_word(d,p,v) __kc_pcie_capability_read_word(d,p,v)
3697 int __kc_pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
3698 #define pcie_capability_write_word(d,p,v) __kc_pcie_capability_write_word(d,p,v)
3699 int __kc_pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
3700                                             u16 clear, u16 set);
3701 #define pcie_capability_clear_and_set_word(d,p,c,s) \
3702         __kc_pcie_capability_clear_and_set_word(d,p,c,s)
3703
3704 #define PCI_EXP_LNKSTA2         50      /* Link Status 2 */
3705
3706 static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
3707                                              u16 clear)
3708 {
3709         return __kc_pcie_capability_clear_and_set_word(dev, pos, clear, 0);
3710 }
3711 #endif /* !PCI_EXP_LNKSTA2 */
3712
3713 #if (SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0))
3714 #define USE_CONST_DEV_UC_CHAR
3715 #endif
3716
3717 #else /* >= 3.7.0 */
3718 #define HAVE_CONST_STRUCT_PCI_ERROR_HANDLERS
3719 #define USE_CONST_DEV_UC_CHAR
3720 #endif /* >= 3.7.0 */
3721
3722 /*****************************************************************************/
3723 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) )
3724 #ifndef PCI_EXP_LNKCTL_ASPM_L0S
3725 #define  PCI_EXP_LNKCTL_ASPM_L0S  0x01  /* L0s Enable */
3726 #endif
3727 #ifndef PCI_EXP_LNKCTL_ASPM_L1
3728 #define  PCI_EXP_LNKCTL_ASPM_L1   0x02  /* L1 Enable */
3729 #endif
3730 #define HAVE_CONFIG_HOTPLUG
3731 /* Reserved Ethernet Addresses per IEEE 802.1Q */
3732 static const u8 eth_reserved_addr_base[ETH_ALEN] __aligned(2) = {
3733         0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
3734 #if !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0)) &&\
3735     !(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,5))
3736 static inline bool is_link_local_ether_addr(const u8 *addr)
3737 {
3738         __be16 *a = (__be16 *)addr;
3739         static const __be16 *b = (const __be16 *)eth_reserved_addr_base;
3740         static const __be16 m = cpu_to_be16(0xfff0);
3741
3742         return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | ((a[2] ^ b[2]) & m)) == 0;
3743 }
3744 #endif /* !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0)) */
3745 #else /* >= 3.8.0 */
3746 #ifndef __devinit
3747 #define __devinit
3748 #define HAVE_ENCAP_CSUM_OFFLOAD
3749 #endif
3750
3751 #ifndef __devinitdata
3752 #define __devinitdata
3753 #endif
3754
3755 #ifndef __devexit
3756 #define __devexit
3757 #endif
3758
3759 #ifndef __devexit_p
3760 #define __devexit_p
3761 #endif
3762
3763 #ifndef HAVE_SRIOV_CONFIGURE
3764 #define HAVE_SRIOV_CONFIGURE
3765 #endif
3766
3767 #define HAVE_BRIDGE_ATTRIBS
3768 #ifndef BRIDGE_MODE_VEB
3769 #define BRIDGE_MODE_VEB         0       /* Default loopback mode */
3770 #endif /* BRIDGE_MODE_VEB */
3771 #ifndef BRIDGE_MODE_VEPA
3772 #define BRIDGE_MODE_VEPA        1       /* 802.1Qbg defined VEPA mode */
3773 #endif /* BRIDGE_MODE_VEPA */
3774 #endif /* >= 3.8.0 */
3775
3776 /*****************************************************************************/
3777 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) )
3778
3779 #undef hlist_entry
3780 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
3781
3782 #undef hlist_entry_safe
3783 #define hlist_entry_safe(ptr, type, member) \
3784         (ptr) ? hlist_entry(ptr, type, member) : NULL
3785
3786 #undef hlist_for_each_entry
3787 #define hlist_for_each_entry(pos, head, member)                             \
3788         for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); \
3789              pos;                                                           \
3790              pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
3791
3792 #undef hlist_for_each_entry_safe
3793 #define hlist_for_each_entry_safe(pos, n, head, member)                     \
3794         for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);   \
3795              pos && ({ n = pos->member.next; 1; });                         \
3796              pos = hlist_entry_safe(n, typeof(*pos), member))
3797
3798 #ifdef CONFIG_XPS
3799 extern int __kc_netif_set_xps_queue(struct net_device *, struct cpumask *, u16);
3800 #define netif_set_xps_queue(_dev, _mask, _idx) __kc_netif_set_xps_queue((_dev), (_mask), (_idx))
3801 #else /* CONFIG_XPS */
3802 #define netif_set_xps_queue(_dev, _mask, _idx) do {} while (0)
3803 #endif /* CONFIG_XPS */
3804
3805 #ifdef HAVE_NETDEV_SELECT_QUEUE
3806 #define _kc_hashrnd 0xd631614b /* not so random hash salt */
3807 extern u16 __kc_netdev_pick_tx(struct net_device *dev, struct sk_buff *skb);
3808 #define __netdev_pick_tx __kc_netdev_pick_tx
3809 #endif /* HAVE_NETDEV_SELECT_QUEUE */
3810 #else
3811 #define HAVE_BRIDGE_FILTER
3812 #define USE_DEFAULT_FDB_DEL_DUMP
3813 #endif /* < 3.9.0 */
3814
3815 /*****************************************************************************/
3816 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) )
3817 #ifdef CONFIG_PCI_IOV
3818 extern int __kc_pci_vfs_assigned(struct pci_dev *dev);
3819 #else
3820 static inline int __kc_pci_vfs_assigned(struct pci_dev *dev)
3821 {
3822         return 0;
3823 }
3824 #endif
3825 #define pci_vfs_assigned(dev) __kc_pci_vfs_assigned(dev)
3826
3827 #ifndef VLAN_TX_COOKIE_MAGIC
3828 static inline struct sk_buff *__kc__vlan_hwaccel_put_tag(struct sk_buff *skb,
3829                                                          u16 vlan_tci)
3830 {
3831 #ifdef VLAN_TAG_PRESENT
3832         vlan_tci |= VLAN_TAG_PRESENT;
3833 #endif
3834         skb->vlan_tci = vlan_tci;
3835         return skb;
3836 }
3837 #define __vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci) \
3838         __kc__vlan_hwaccel_put_tag(skb, vlan_tci)
3839 #endif
3840
3841 #else /* >= 3.10.0 */
3842 #define HAVE_ENCAP_TSO_OFFLOAD
3843 #endif /* >= 3.10.0 */
3844
3845 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0) )
3846 #ifdef NETIF_F_RXHASH
3847 #define PKT_HASH_TYPE_L3 0
3848 static inline void
3849 skb_set_hash(struct sk_buff *skb, __u32 hash, __always_unused int type)
3850 {
3851         skb->rxhash = hash;
3852 }
3853 #endif /* NETIF_F_RXHASH */
3854 #endif /* < 3.14.0 */
3855
3856 #endif /* _KCOMPAT_H_ */