1 /*******************************************************************************
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2012 Intel Corporation.
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.
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
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
31 #ifndef LINUX_VERSION_CODE
32 #include <linux/version.h>
34 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
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>
51 #include <linux/udp.h>
52 #include <linux/mii.h>
53 #include <linux/vmalloc.h>
55 #include <linux/ethtool.h>
56 #include <linux/if_vlan.h>
58 /* NAPI enable/disable flags here */
61 #define adapter_struct igb_adapter
62 #define adapter_q_vector igb_q_vector
65 /* and finally set defines so that the code sees the changes */
70 /* packet split disable/enable */
71 #ifdef DISABLE_PACKET_SPLIT
72 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
73 #define CONFIG_IGB_DISABLE_PACKET_SPLIT
75 #endif /* DISABLE_PACKET_SPLIT */
77 /* MSI compatibility code for all kernels and drivers */
78 #ifdef DISABLE_PCI_MSI
81 #ifndef CONFIG_PCI_MSI
82 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
84 u16 vector; /* kernel uses to write allocated vector */
85 u16 entry; /* driver uses to specify entry, OS writes */
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 */
102 #ifdef DISABLE_NET_POLL_CONTROLLER
103 #undef CONFIG_NET_POLL_CONTROLLER
107 #define PMSG_SUSPEND 3
110 /* generic boolean compatibility */
116 #if ( GCC_VERSION < 3000 )
123 /* kernels less than 2.4.14 don't have this */
125 #define ETH_P_8021Q 0x8100
129 #define module_param(v,t,p) MODULE_PARM(v, "i");
132 #ifndef DMA_64BIT_MASK
133 #define DMA_64BIT_MASK 0xffffffffffffffffULL
136 #ifndef DMA_32BIT_MASK
137 #define DMA_32BIT_MASK 0x00000000ffffffffULL
140 #ifndef PCI_CAP_ID_EXP
141 #define PCI_CAP_ID_EXP 0x10
144 #ifndef PCIE_LINK_STATE_L0S
145 #define PCIE_LINK_STATE_L0S 1
147 #ifndef PCIE_LINK_STATE_L1
148 #define PCIE_LINK_STATE_L1 2
153 #define mmiowb() asm volatile ("mf.a" ::: "memory")
159 #ifndef SET_NETDEV_DEV
160 #define SET_NETDEV_DEV(net, pdev)
163 #if !defined(HAVE_FREE_NETDEV) && ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
164 #define free_netdev(x) kfree(x)
167 #ifdef HAVE_POLL_CONTROLLER
168 #define CONFIG_NET_POLL_CONTROLLER
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
178 #define gso_size tso_size
179 #define gso_segs tso_segs
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)
188 #ifndef NETIF_F_SCTP_CSUM
189 #define NETIF_F_SCTP_CSUM 0
193 #define NETIF_F_LRO (1 << 15)
196 #ifndef NETIF_F_NTUPLE
197 #define NETIF_F_NTUPLE (1 << 27)
201 #define IPPROTO_SCTP 132
204 #ifndef CHECKSUM_PARTIAL
205 #define CHECKSUM_PARTIAL CHECKSUM_HW
206 #define CHECKSUM_COMPLETE CHECKSUM_HW
209 #ifndef __read_mostly
210 #define __read_mostly
214 #define MII_RESV1 0x17 /* Reserved... */
218 #define unlikely(_x) _x
219 #define likely(_x) _x
227 #define PCI_DEVICE(vend,dev) \
228 .vendor = (vend), .device = (dev), \
229 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
233 #define node_online(node) ((node) == 0)
236 #ifndef num_online_cpus
237 #define num_online_cpus() smp_num_cpus
241 #define cpu_online(cpuid) test_bit((cpuid), &cpu_online_map)
244 #ifndef _LINUX_RANDOM_H
245 #include <linux/random.h>
248 #ifndef DECLARE_BITMAP
249 #ifndef BITS_TO_LONGS
250 #define BITS_TO_LONGS(bits) (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
252 #define DECLARE_BITMAP(name,bits) long name[BITS_TO_LONGS(bits)]
259 #ifndef VLAN_ETH_HLEN
260 #define VLAN_ETH_HLEN 18
263 #ifndef VLAN_ETH_FRAME_LEN
264 #define VLAN_ETH_FRAME_LEN 1518
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
275 #ifndef DCA_GET_TAG_TWO_ARGS
276 #define dca3_get_tag(a,b) dca_get_tag(b)
279 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
280 #if defined(__i386__) || defined(__x86_64__)
281 #define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
285 /* taken from 2.6.24 definition in linux/kernel.h */
287 #define IS_ALIGNED(x,a) (((x) % ((typeof(x))(a))) == 0)
290 #ifndef NETIF_F_HW_VLAN_TX
291 struct _kc_vlan_ethhdr {
292 unsigned char h_dest[ETH_ALEN];
293 unsigned char h_source[ETH_ALEN];
296 __be16 h_vlan_encapsulated_proto;
298 #define vlan_ethhdr _kc_vlan_ethhdr
299 struct _kc_vlan_hdr {
301 __be16 h_vlan_encapsulated_proto;
303 #define vlan_hdr _kc_vlan_hdr
304 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) )
305 #define vlan_tx_tag_present(_skb) 0
306 #define vlan_tx_tag_get(_skb) 0
310 #ifndef VLAN_PRIO_SHIFT
311 #define VLAN_PRIO_SHIFT 13
319 /*****************************************************************************/
320 /* Installations with ethtool version without eeprom, adapter id, or statistics
323 #ifndef ETH_GSTRING_LEN
324 #define ETH_GSTRING_LEN 32
327 #ifndef ETHTOOL_GSTATS
328 #define ETHTOOL_GSTATS 0x1d
329 #undef ethtool_drvinfo
330 #define ethtool_drvinfo k_ethtool_drvinfo
331 struct k_ethtool_drvinfo {
345 struct ethtool_stats {
350 #endif /* ETHTOOL_GSTATS */
352 #ifndef ETHTOOL_PHYS_ID
353 #define ETHTOOL_PHYS_ID 0x1c
354 #endif /* ETHTOOL_PHYS_ID */
356 #ifndef ETHTOOL_GSTRINGS
357 #define ETHTOOL_GSTRINGS 0x1b
358 enum ethtool_stringset {
362 struct ethtool_gstrings {
363 u32 cmd; /* ETHTOOL_GSTRINGS */
364 u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/
365 u32 len; /* number of strings in the string set */
368 #endif /* ETHTOOL_GSTRINGS */
371 #define ETHTOOL_TEST 0x1a
372 enum ethtool_test_flags {
373 ETH_TEST_FL_OFFLINE = (1 << 0),
374 ETH_TEST_FL_FAILED = (1 << 1),
376 struct ethtool_test {
383 #endif /* ETHTOOL_TEST */
385 #ifndef ETHTOOL_GEEPROM
386 #define ETHTOOL_GEEPROM 0xb
388 struct ethtool_eeprom {
396 struct ethtool_value {
400 #endif /* ETHTOOL_GEEPROM */
402 #ifndef ETHTOOL_GLINK
403 #define ETHTOOL_GLINK 0xa
404 #endif /* ETHTOOL_GLINK */
407 #define ETHTOOL_GWOL 0x5
408 #define ETHTOOL_SWOL 0x6
410 struct ethtool_wolinfo {
414 u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
416 #endif /* ETHTOOL_GWOL */
418 #ifndef ETHTOOL_GREGS
419 #define ETHTOOL_GREGS 0x00000004 /* Get NIC registers */
420 #define ethtool_regs _kc_ethtool_regs
421 /* for passing big chunks of data */
422 struct _kc_ethtool_regs {
424 u32 version; /* driver-specific, indicates different chips/revs */
428 #endif /* ETHTOOL_GREGS */
430 #ifndef ETHTOOL_GMSGLVL
431 #define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */
433 #ifndef ETHTOOL_SMSGLVL
434 #define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level, priv. */
436 #ifndef ETHTOOL_NWAY_RST
437 #define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation, priv */
439 #ifndef ETHTOOL_GLINK
440 #define ETHTOOL_GLINK 0x0000000a /* Get link status */
442 #ifndef ETHTOOL_GEEPROM
443 #define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
445 #ifndef ETHTOOL_SEEPROM
446 #define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */
448 #ifndef ETHTOOL_GCOALESCE
449 #define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */
450 /* for configuring coalescing parameters of chip */
451 #define ethtool_coalesce _kc_ethtool_coalesce
452 struct _kc_ethtool_coalesce {
453 u32 cmd; /* ETHTOOL_{G,S}COALESCE */
455 /* How many usecs to delay an RX interrupt after
456 * a packet arrives. If 0, only rx_max_coalesced_frames
459 u32 rx_coalesce_usecs;
461 /* How many packets to delay an RX interrupt after
462 * a packet arrives. If 0, only rx_coalesce_usecs is
463 * used. It is illegal to set both usecs and max frames
464 * to zero as this would cause RX interrupts to never be
467 u32 rx_max_coalesced_frames;
469 /* Same as above two parameters, except that these values
470 * apply while an IRQ is being serviced by the host. Not
471 * all cards support this feature and the values are ignored
474 u32 rx_coalesce_usecs_irq;
475 u32 rx_max_coalesced_frames_irq;
477 /* How many usecs to delay a TX interrupt after
478 * a packet is sent. If 0, only tx_max_coalesced_frames
481 u32 tx_coalesce_usecs;
483 /* How many packets to delay a TX interrupt after
484 * a packet is sent. If 0, only tx_coalesce_usecs is
485 * used. It is illegal to set both usecs and max frames
486 * to zero as this would cause TX interrupts to never be
489 u32 tx_max_coalesced_frames;
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
496 u32 tx_coalesce_usecs_irq;
497 u32 tx_max_coalesced_frames_irq;
499 /* How many usecs to delay in-memory statistics
500 * block updates. Some drivers do not have an in-memory
501 * statistic block, and in such cases this value is ignored.
502 * This value must not be zero.
504 u32 stats_block_coalesce_usecs;
506 /* Adaptive RX/TX coalescing is an algorithm implemented by
507 * some drivers to improve latency under low packet rates and
508 * improve throughput under high packet rates. Some drivers
509 * only implement one of RX or TX adaptive coalescing. Anything
510 * not implemented by the driver causes these values to be
513 u32 use_adaptive_rx_coalesce;
514 u32 use_adaptive_tx_coalesce;
516 /* When the packet rate (measured in packets per second)
517 * is below pkt_rate_low, the {rx,tx}_*_low parameters are
521 u32 rx_coalesce_usecs_low;
522 u32 rx_max_coalesced_frames_low;
523 u32 tx_coalesce_usecs_low;
524 u32 tx_max_coalesced_frames_low;
526 /* When the packet rate is below pkt_rate_high but above
527 * pkt_rate_low (both measured in packets per second) the
528 * normal {rx,tx}_* coalescing parameters are used.
531 /* When the packet rate is (measured in packets per second)
532 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
536 u32 rx_coalesce_usecs_high;
537 u32 rx_max_coalesced_frames_high;
538 u32 tx_coalesce_usecs_high;
539 u32 tx_max_coalesced_frames_high;
541 /* How often to do adaptive coalescing packet rate sampling,
542 * measured in seconds. Must not be zero.
544 u32 rate_sample_interval;
546 #endif /* ETHTOOL_GCOALESCE */
548 #ifndef ETHTOOL_SCOALESCE
549 #define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config. */
551 #ifndef ETHTOOL_GRINGPARAM
552 #define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */
553 /* for configuring RX/TX ring parameters */
554 #define ethtool_ringparam _kc_ethtool_ringparam
555 struct _kc_ethtool_ringparam {
556 u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */
558 /* Read only attributes. These indicate the maximum number
559 * of pending RX/TX ring entries the driver will allow the
563 u32 rx_mini_max_pending;
564 u32 rx_jumbo_max_pending;
567 /* Values changeable by the user. The valid values are
568 * in the range 1 to the "*_max_pending" counterpart above.
572 u32 rx_jumbo_pending;
575 #endif /* ETHTOOL_GRINGPARAM */
577 #ifndef ETHTOOL_SRINGPARAM
578 #define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters, priv. */
580 #ifndef ETHTOOL_GPAUSEPARAM
581 #define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */
582 /* for configuring link flow control parameters */
583 #define ethtool_pauseparam _kc_ethtool_pauseparam
584 struct _kc_ethtool_pauseparam {
585 u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */
587 /* If the link is being auto-negotiated (via ethtool_cmd.autoneg
588 * being true) the user may set 'autoneg' here non-zero to have the
589 * pause parameters be auto-negotiated too. In such a case, the
590 * {rx,tx}_pause values below determine what capabilities are
593 * If 'autoneg' is zero or the link is not being auto-negotiated,
594 * then {rx,tx}_pause force the driver to use/not-use pause
601 #endif /* ETHTOOL_GPAUSEPARAM */
603 #ifndef ETHTOOL_SPAUSEPARAM
604 #define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters. */
606 #ifndef ETHTOOL_GRXCSUM
607 #define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */
609 #ifndef ETHTOOL_SRXCSUM
610 #define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */
612 #ifndef ETHTOOL_GTXCSUM
613 #define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */
615 #ifndef ETHTOOL_STXCSUM
616 #define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */
619 #define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable
623 #define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable
624 * (ethtool_value). */
627 #define ETHTOOL_TEST 0x0000001a /* execute NIC self-test, priv. */
629 #ifndef ETHTOOL_GSTRINGS
630 #define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */
632 #ifndef ETHTOOL_PHYS_ID
633 #define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */
635 #ifndef ETHTOOL_GSTATS
636 #define ETHTOOL_GSTATS 0x0000001d /* get NIC-specific statistics */
639 #define ETHTOOL_GTSO 0x0000001e /* Get TSO enable (ethtool_value) */
642 #define ETHTOOL_STSO 0x0000001f /* Set TSO enable (ethtool_value) */
645 #ifndef ETHTOOL_BUSINFO_LEN
646 #define ETHTOOL_BUSINFO_LEN 32
649 #ifndef RHEL_RELEASE_CODE
650 /* NOTE: RHEL_RELEASE_* introduced in RHEL4.5 */
651 #define RHEL_RELEASE_CODE 0
653 #ifndef RHEL_RELEASE_VERSION
654 #define RHEL_RELEASE_VERSION(a,b) (((a) << 8) + (b))
656 #ifndef AX_RELEASE_CODE
657 #define AX_RELEASE_CODE 0
659 #ifndef AX_RELEASE_VERSION
660 #define AX_RELEASE_VERSION(a,b) (((a) << 8) + (b))
663 /* SuSE version macro is the same as Linux kernel version */
665 #define SLE_VERSION(a,b,c) KERNEL_VERSION(a,b,c)
667 #ifndef SLE_VERSION_CODE
668 #ifdef CONFIG_SUSE_KERNEL
669 /* SLES11 GA is 2.6.27 based */
670 #if ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27) )
671 #define SLE_VERSION_CODE SLE_VERSION(11,0,0)
672 #elif ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32) )
673 /* SLES11 SP1 is 2.6.32 based */
674 #define SLE_VERSION_CODE SLE_VERSION(11,1,0)
676 #define SLE_VERSION_CODE 0
678 #else /* CONFIG_SUSE_KERNEL */
679 #define SLE_VERSION_CODE 0
680 #endif /* CONFIG_SUSE_KERNEL */
681 #endif /* SLE_VERSION_CODE */
686 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
688 #endif /* __KLOCWORK__ */
690 /*****************************************************************************/
692 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )
694 /**************************************/
697 #ifndef pci_set_dma_mask
698 #define pci_set_dma_mask _kc_pci_set_dma_mask
699 extern int _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
702 #ifndef pci_request_regions
703 #define pci_request_regions _kc_pci_request_regions
704 extern int _kc_pci_request_regions(struct pci_dev *pdev, char *res_name);
707 #ifndef pci_release_regions
708 #define pci_release_regions _kc_pci_release_regions
709 extern void _kc_pci_release_regions(struct pci_dev *pdev);
712 /**************************************/
713 /* NETWORK DRIVER API */
715 #ifndef alloc_etherdev
716 #define alloc_etherdev _kc_alloc_etherdev
717 extern struct net_device * _kc_alloc_etherdev(int sizeof_priv);
720 #ifndef is_valid_ether_addr
721 #define is_valid_ether_addr _kc_is_valid_ether_addr
722 extern int _kc_is_valid_ether_addr(u8 *addr);
725 /**************************************/
729 #define INIT_TQUEUE(_tq, _routine, _data) \
731 INIT_LIST_HEAD(&(_tq)->list); \
733 (_tq)->routine = _routine; \
734 (_tq)->data = _data; \
738 #endif /* 2.4.3 => 2.4.0 */
740 /*****************************************************************************/
741 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) )
742 /* Generic MII registers. */
743 #define MII_BMCR 0x00 /* Basic mode control register */
744 #define MII_BMSR 0x01 /* Basic mode status register */
745 #define MII_PHYSID1 0x02 /* PHYS ID 1 */
746 #define MII_PHYSID2 0x03 /* PHYS ID 2 */
747 #define MII_ADVERTISE 0x04 /* Advertisement control reg */
748 #define MII_LPA 0x05 /* Link partner ability reg */
749 #define MII_EXPANSION 0x06 /* Expansion register */
750 /* Basic mode control register. */
751 #define BMCR_FULLDPLX 0x0100 /* Full duplex */
752 #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
753 /* Basic mode status register. */
754 #define BMSR_ERCAP 0x0001 /* Ext-reg capability */
755 #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
756 #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
757 #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
758 #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
759 #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
760 /* Advertisement control register. */
761 #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
762 #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
763 #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
764 #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
765 #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
766 #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
767 ADVERTISE_100HALF | ADVERTISE_100FULL)
768 /* Expansion register for auto-negotiation. */
769 #define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */
772 /*****************************************************************************/
774 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )
776 #ifndef pci_set_power_state
777 #define pci_set_power_state _kc_pci_set_power_state
778 extern int _kc_pci_set_power_state(struct pci_dev *dev, int state);
781 #ifndef pci_enable_wake
782 #define pci_enable_wake _kc_pci_enable_wake
783 extern int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable);
786 #ifndef pci_disable_device
787 #define pci_disable_device _kc_pci_disable_device
788 extern void _kc_pci_disable_device(struct pci_dev *pdev);
791 /* PCI PM entry point syntax changed, so don't support suspend/resume */
794 #endif /* 2.4.6 => 2.4.3 */
796 #ifndef HAVE_PCI_SET_MWI
797 #define pci_set_mwi(X) pci_write_config_word(X, \
798 PCI_COMMAND, adapter->hw.bus.pci_cmd_word | \
799 PCI_COMMAND_INVALIDATE);
800 #define pci_clear_mwi(X) pci_write_config_word(X, \
801 PCI_COMMAND, adapter->hw.bus.pci_cmd_word & \
802 ~PCI_COMMAND_INVALIDATE);
805 /*****************************************************************************/
806 /* 2.4.10 => 2.4.9 */
807 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) )
809 /**************************************/
812 #ifndef MODULE_LICENSE
813 #define MODULE_LICENSE(X)
816 /**************************************/
820 #define min(x,y) ({ \
821 const typeof(x) _x = (x); \
822 const typeof(y) _y = (y); \
823 (void) (&_x == &_y); \
824 _x < _y ? _x : _y; })
827 #define max(x,y) ({ \
828 const typeof(x) _x = (x); \
829 const typeof(y) _y = (y); \
830 (void) (&_x == &_y); \
831 _x > _y ? _x : _y; })
833 #define min_t(type,x,y) ({ \
836 _x < _y ? _x : _y; })
838 #define max_t(type,x,y) ({ \
841 _x > _y ? _x : _y; })
843 #ifndef list_for_each_safe
844 #define list_for_each_safe(pos, n, head) \
845 for (pos = (head)->next, n = pos->next; pos != (head); \
846 pos = n, n = pos->next)
849 #ifndef ____cacheline_aligned_in_smp
851 #define ____cacheline_aligned_in_smp ____cacheline_aligned
853 #define ____cacheline_aligned_in_smp
854 #endif /* CONFIG_SMP */
857 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) )
858 extern int _kc_snprintf(char * buf, size_t size, const char *fmt, ...);
859 #define snprintf(buf, size, fmt, args...) _kc_snprintf(buf, size, fmt, ##args)
860 extern int _kc_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
861 #define vsnprintf(buf, size, fmt, args) _kc_vsnprintf(buf, size, fmt, args)
862 #else /* 2.4.8 => 2.4.9 */
863 extern int snprintf(char * buf, size_t size, const char *fmt, ...);
864 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
866 #endif /* 2.4.10 -> 2.4.6 */
869 /*****************************************************************************/
870 /* 2.4.12 => 2.4.10 */
871 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,12) )
872 #ifndef HAVE_NETIF_MSG
873 #define HAVE_NETIF_MSG 1
875 NETIF_MSG_DRV = 0x0001,
876 NETIF_MSG_PROBE = 0x0002,
877 NETIF_MSG_LINK = 0x0004,
878 NETIF_MSG_TIMER = 0x0008,
879 NETIF_MSG_IFDOWN = 0x0010,
880 NETIF_MSG_IFUP = 0x0020,
881 NETIF_MSG_RX_ERR = 0x0040,
882 NETIF_MSG_TX_ERR = 0x0080,
883 NETIF_MSG_TX_QUEUED = 0x0100,
884 NETIF_MSG_INTR = 0x0200,
885 NETIF_MSG_TX_DONE = 0x0400,
886 NETIF_MSG_RX_STATUS = 0x0800,
887 NETIF_MSG_PKTDATA = 0x1000,
888 NETIF_MSG_HW = 0x2000,
889 NETIF_MSG_WOL = 0x4000,
892 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
893 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
894 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
895 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
896 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
897 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
898 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
899 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
900 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
901 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
902 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
903 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
904 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
905 #endif /* !HAVE_NETIF_MSG */
906 #endif /* 2.4.12 => 2.4.10 */
908 /*****************************************************************************/
909 /* 2.4.13 => 2.4.12 */
910 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )
912 /**************************************/
913 /* PCI DMA MAPPING */
916 #define virt_to_page(v) (mem_map + (virt_to_phys(v) >> PAGE_SHIFT))
920 #define pci_map_page _kc_pci_map_page
921 extern u64 _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset, size_t size, int direction);
924 #ifndef pci_unmap_page
925 #define pci_unmap_page _kc_pci_unmap_page
926 extern void _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size, int direction);
929 /* pci_set_dma_mask takes dma_addr_t, which is only 32-bits prior to 2.4.13 */
931 #undef DMA_32BIT_MASK
932 #define DMA_32BIT_MASK 0xffffffff
933 #undef DMA_64BIT_MASK
934 #define DMA_64BIT_MASK 0xffffffff
936 /**************************************/
940 #define cpu_relax() rep_nop()
944 unsigned char h_dest[ETH_ALEN];
945 unsigned char h_source[ETH_ALEN];
946 unsigned short h_vlan_proto;
947 unsigned short h_vlan_TCI;
948 unsigned short h_vlan_encapsulated_proto;
950 #endif /* 2.4.13 => 2.4.12 */
952 /*****************************************************************************/
953 /* 2.4.17 => 2.4.12 */
954 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17) )
957 #define __devexit_p(x) &(x)
961 /* For Kernel 3.8 these are not defined - so undefine all */
966 #define __devexit_p(x) &(x)
969 #define __devinitdata
970 #endif /* 2.4.17 => 2.4.13 */
972 /*****************************************************************************/
973 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18) )
974 #define NETIF_MSG_HW 0x2000
975 #define NETIF_MSG_WOL 0x4000
978 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
980 #ifndef netif_msg_wol
981 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
985 /*****************************************************************************/
987 /*****************************************************************************/
988 /* 2.4.20 => 2.4.19 */
989 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20) )
991 /* we won't support NAPI on less than 2.4.20 */
996 #endif /* 2.4.20 => 2.4.19 */
998 /*****************************************************************************/
999 /* 2.4.22 => 2.4.17 */
1000 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
1001 #define pci_name(x) ((x)->slot_name)
1004 /*****************************************************************************/
1005 /* 2.4.22 => 2.4.17 */
1007 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
1013 /*****************************************************************************/
1014 /*****************************************************************************/
1015 /* 2.4.23 => 2.4.22 */
1016 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23) )
1017 /*****************************************************************************/
1019 #ifndef netif_poll_disable
1020 #define netif_poll_disable(x) _kc_netif_poll_disable(x)
1021 static inline void _kc_netif_poll_disable(struct net_device *netdev)
1023 while (test_and_set_bit(__LINK_STATE_RX_SCHED, &netdev->state)) {
1025 current->state = TASK_INTERRUPTIBLE;
1026 schedule_timeout(1);
1030 #ifndef netif_poll_enable
1031 #define netif_poll_enable(x) _kc_netif_poll_enable(x)
1032 static inline void _kc_netif_poll_enable(struct net_device *netdev)
1034 clear_bit(__LINK_STATE_RX_SCHED, &netdev->state);
1038 #ifndef netif_tx_disable
1039 #define netif_tx_disable(x) _kc_netif_tx_disable(x)
1040 static inline void _kc_netif_tx_disable(struct net_device *dev)
1042 spin_lock_bh(&dev->xmit_lock);
1043 netif_stop_queue(dev);
1044 spin_unlock_bh(&dev->xmit_lock);
1047 #else /* 2.4.23 => 2.4.22 */
1049 #endif /* 2.4.23 => 2.4.22 */
1051 /*****************************************************************************/
1052 /* 2.6.4 => 2.6.0 */
1053 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \
1054 ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1055 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )
1056 #define ETHTOOL_OPS_COMPAT
1057 #endif /* 2.6.4 => 2.6.0 */
1059 /*****************************************************************************/
1060 /* 2.5.71 => 2.4.x */
1061 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71) )
1062 #define sk_protocol protocol
1063 #define pci_get_device pci_find_device
1064 #endif /* 2.5.70 => 2.4.x */
1066 /*****************************************************************************/
1067 /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1068 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) || \
1069 ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1070 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) ) )
1072 #ifndef netif_msg_init
1073 #define netif_msg_init _kc_netif_msg_init
1074 static inline u32 _kc_netif_msg_init(int debug_value, int default_msg_enable_bits)
1077 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
1078 return default_msg_enable_bits;
1079 if (debug_value == 0) /* no output */
1081 /* set low N bits */
1082 return (1 << debug_value) -1;
1086 #endif /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1087 /*****************************************************************************/
1088 #if (( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) ) || \
1089 (( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) && \
1090 ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) )))
1091 #define netdev_priv(x) x->priv
1094 /*****************************************************************************/
1096 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) )
1097 #include <linux/rtnetlink.h>
1098 #undef pci_register_driver
1099 #define pci_register_driver pci_module_init
1102 * Most of the dma compat code is copied/modifed from the 2.4.37
1103 * /include/linux/libata-compat.h header file
1105 /* These definitions mirror those in pci.h, so they can be used
1106 * interchangeably with their PCI_ counterparts */
1107 enum dma_data_direction {
1108 DMA_BIDIRECTIONAL = 0,
1110 DMA_FROM_DEVICE = 2,
1115 struct pci_dev pdev;
1118 static inline struct pci_dev *to_pci_dev (struct device *dev)
1120 return (struct pci_dev *) dev;
1122 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1124 return (struct device *) pdev;
1127 #define pdev_printk(lvl, pdev, fmt, args...) \
1128 printk("%s %s: " fmt, lvl, pci_name(pdev), ## args)
1129 #define dev_err(dev, fmt, args...) \
1130 pdev_printk(KERN_ERR, to_pci_dev(dev), fmt, ## args)
1131 #define dev_info(dev, fmt, args...) \
1132 pdev_printk(KERN_INFO, to_pci_dev(dev), fmt, ## args)
1133 #define dev_warn(dev, fmt, args...) \
1134 pdev_printk(KERN_WARNING, to_pci_dev(dev), fmt, ## args)
1136 /* NOTE: dangerous! we ignore the 'gfp' argument */
1137 #define dma_alloc_coherent(dev,sz,dma,gfp) \
1138 pci_alloc_consistent(to_pci_dev(dev),(sz),(dma))
1139 #define dma_free_coherent(dev,sz,addr,dma_addr) \
1140 pci_free_consistent(to_pci_dev(dev),(sz),(addr),(dma_addr))
1142 #define dma_map_page(dev,a,b,c,d) \
1143 pci_map_page(to_pci_dev(dev),(a),(b),(c),(d))
1144 #define dma_unmap_page(dev,a,b,c) \
1145 pci_unmap_page(to_pci_dev(dev),(a),(b),(c))
1147 #define dma_map_single(dev,a,b,c) \
1148 pci_map_single(to_pci_dev(dev),(a),(b),(c))
1149 #define dma_unmap_single(dev,a,b,c) \
1150 pci_unmap_single(to_pci_dev(dev),(a),(b),(c))
1152 #define dma_sync_single(dev,a,b,c) \
1153 pci_dma_sync_single(to_pci_dev(dev),(a),(b),(c))
1155 /* for range just sync everything, that's all the pci API can do */
1156 #define dma_sync_single_range(dev,addr,off,sz,dir) \
1157 pci_dma_sync_single(to_pci_dev(dev),(addr),(off)+(sz),(dir))
1159 #define dma_set_mask(dev,mask) \
1160 pci_set_dma_mask(to_pci_dev(dev),(mask))
1162 /* hlist_* code - double linked lists */
1164 struct hlist_node *first;
1168 struct hlist_node *next, **pprev;
1171 static inline void __hlist_del(struct hlist_node *n)
1173 struct hlist_node *next = n->next;
1174 struct hlist_node **pprev = n->pprev;
1177 next->pprev = pprev;
1180 static inline void hlist_del(struct hlist_node *n)
1187 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
1189 struct hlist_node *first = h->first;
1192 first->pprev = &n->next;
1194 n->pprev = &h->first;
1197 static inline int hlist_empty(const struct hlist_head *h)
1201 #define HLIST_HEAD_INIT { .first = NULL }
1202 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
1203 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
1204 static inline void INIT_HLIST_NODE(struct hlist_node *h)
1209 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
1211 #define hlist_for_each_entry(tpos, pos, head, member) \
1212 for (pos = (head)->first; \
1213 pos && ({ prefetch(pos->next); 1;}) && \
1214 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1217 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
1218 for (pos = (head)->first; \
1219 pos && ({ n = pos->next; 1; }) && \
1220 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1224 #define might_sleep()
1227 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1231 #endif /* <= 2.5.0 */
1233 /*****************************************************************************/
1234 /* 2.5.28 => 2.4.23 */
1235 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )
1237 static inline void _kc_synchronize_irq(void)
1241 #undef synchronize_irq
1242 #define synchronize_irq(X) _kc_synchronize_irq()
1244 #include <linux/tqueue.h>
1245 #define work_struct tq_struct
1247 #define INIT_WORK(a,b) INIT_TQUEUE(a,(void (*)(void *))b,a)
1249 #define container_of list_entry
1250 #define schedule_work schedule_task
1251 #define flush_scheduled_work flush_scheduled_tasks
1252 #define cancel_work_sync(x) flush_scheduled_work()
1254 #endif /* 2.5.28 => 2.4.17 */
1256 /*****************************************************************************/
1257 /* 2.6.0 => 2.5.28 */
1258 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
1260 #define get_cpu() smp_processor_id()
1262 #define put_cpu() do { } while(0)
1263 #define MODULE_INFO(version, _version)
1264 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1265 #define CONFIG_E1000_DISABLE_PACKET_SPLIT 1
1267 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
1268 #define CONFIG_IGB_DISABLE_PACKET_SPLIT 1
1271 #define dma_set_coherent_mask(dev,mask) 1
1274 #define dev_put(dev) __dev_put(dev)
1276 #ifndef skb_fill_page_desc
1277 #define skb_fill_page_desc _kc_skb_fill_page_desc
1278 extern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size);
1282 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
1285 #define page_count(p) atomic_read(&(p)->count)
1291 #define MAX_NUMNODES 1
1293 /* find_first_bit and find_next bit are not defined for most
1294 * 2.4 kernels (except for the redhat 2.4.21 kernels
1296 #include <linux/bitops.h>
1297 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
1298 #undef find_next_bit
1299 #define find_next_bit _kc_find_next_bit
1300 extern unsigned long _kc_find_next_bit(const unsigned long *addr,
1302 unsigned long offset);
1303 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
1307 static inline const char *_kc_netdev_name(const struct net_device *dev)
1309 if (strchr(dev->name, '%'))
1310 return "(unregistered net_device)";
1313 #define netdev_name(netdev) _kc_netdev_name(netdev)
1314 #endif /* netdev_name */
1317 #define strlcpy _kc_strlcpy
1318 extern size_t _kc_strlcpy(char *dest, const char *src, size_t size);
1319 #endif /* strlcpy */
1321 #endif /* 2.6.0 => 2.5.28 */
1323 /*****************************************************************************/
1324 /* 2.6.4 => 2.6.0 */
1325 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1326 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
1327 #endif /* 2.6.4 => 2.6.0 */
1329 /*****************************************************************************/
1330 /* 2.6.5 => 2.6.0 */
1331 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) )
1332 #define dma_sync_single_for_cpu dma_sync_single
1333 #define dma_sync_single_for_device dma_sync_single
1334 #define dma_sync_single_range_for_cpu dma_sync_single_range
1335 #define dma_sync_single_range_for_device dma_sync_single_range
1336 #ifndef pci_dma_mapping_error
1337 #define pci_dma_mapping_error _kc_pci_dma_mapping_error
1338 static inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr)
1340 return dma_addr == 0;
1343 #endif /* 2.6.5 => 2.6.0 */
1345 /*****************************************************************************/
1346 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1347 extern int _kc_scnprintf(char * buf, size_t size, const char *fmt, ...);
1348 #define scnprintf(buf, size, fmt, args...) _kc_scnprintf(buf, size, fmt, ##args)
1349 #endif /* < 2.6.4 */
1351 /*****************************************************************************/
1352 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6) )
1353 /* taken from 2.6 include/linux/bitmap.h */
1355 #define bitmap_zero _kc_bitmap_zero
1356 static inline void _kc_bitmap_zero(unsigned long *dst, int nbits)
1358 if (nbits <= BITS_PER_LONG)
1361 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
1362 memset(dst, 0, len);
1365 #define random_ether_addr _kc_random_ether_addr
1366 static inline void _kc_random_ether_addr(u8 *addr)
1368 get_random_bytes(addr, ETH_ALEN);
1369 addr[0] &= 0xfe; /* clear multicast */
1370 addr[0] |= 0x02; /* set local assignment */
1372 #define page_to_nid(x) 0
1374 #endif /* < 2.6.6 */
1376 /*****************************************************************************/
1377 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7) )
1379 #define if_mii _kc_if_mii
1380 static inline struct mii_ioctl_data *_kc_if_mii(struct ifreq *rq)
1382 return (struct mii_ioctl_data *) &rq->ifr_ifru;
1388 #endif /* < 2.6.7 */
1390 /*****************************************************************************/
1391 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
1392 #ifndef PCI_EXP_DEVCTL
1393 #define PCI_EXP_DEVCTL 8
1395 #ifndef PCI_EXP_DEVCTL_CERE
1396 #define PCI_EXP_DEVCTL_CERE 0x0001
1398 #define msleep(x) do { set_current_state(TASK_UNINTERRUPTIBLE); \
1399 schedule_timeout((x * HZ)/1000 + 2); \
1402 #endif /* < 2.6.8 */
1404 /*****************************************************************************/
1405 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
1406 #include <net/dsfield.h>
1410 #define kcalloc(n, size, flags) _kc_kzalloc(((n) * (size)), flags)
1411 extern void *_kc_kzalloc(size_t size, int flags);
1413 #define MSEC_PER_SEC 1000L
1414 static inline unsigned int _kc_jiffies_to_msecs(const unsigned long j)
1416 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1417 return (MSEC_PER_SEC / HZ) * j;
1418 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1419 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
1421 return (j * MSEC_PER_SEC) / HZ;
1424 static inline unsigned long _kc_msecs_to_jiffies(const unsigned int m)
1426 if (m > _kc_jiffies_to_msecs(MAX_JIFFY_OFFSET))
1427 return MAX_JIFFY_OFFSET;
1428 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1429 return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
1430 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1431 return m * (HZ / MSEC_PER_SEC);
1433 return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
1437 #define msleep_interruptible _kc_msleep_interruptible
1438 static inline unsigned long _kc_msleep_interruptible(unsigned int msecs)
1440 unsigned long timeout = _kc_msecs_to_jiffies(msecs) + 1;
1442 while (timeout && !signal_pending(current)) {
1443 __set_current_state(TASK_INTERRUPTIBLE);
1444 timeout = schedule_timeout(timeout);
1446 return _kc_jiffies_to_msecs(timeout);
1449 /* Basic mode control register. */
1450 #define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
1471 static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
1473 return (struct vlan_ethhdr *)skb->mac.raw;
1476 /* Wake-On-Lan options. */
1477 #define WAKE_PHY (1 << 0)
1478 #define WAKE_UCAST (1 << 1)
1479 #define WAKE_MCAST (1 << 2)
1480 #define WAKE_BCAST (1 << 3)
1481 #define WAKE_ARP (1 << 4)
1482 #define WAKE_MAGIC (1 << 5)
1483 #define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
1485 #define skb_header_pointer _kc_skb_header_pointer
1486 static inline void *_kc_skb_header_pointer(const struct sk_buff *skb,
1487 int offset, int len, void *buffer)
1489 int hlen = skb_headlen(skb);
1491 if (hlen - offset >= len)
1492 return skb->data + offset;
1494 #ifdef MAX_SKB_FRAGS
1495 if (skb_copy_bits(skb, offset, buffer, len) < 0)
1503 #ifndef NETDEV_TX_OK
1504 #define NETDEV_TX_OK 0
1506 #ifndef NETDEV_TX_BUSY
1507 #define NETDEV_TX_BUSY 1
1509 #ifndef NETDEV_TX_LOCKED
1510 #define NETDEV_TX_LOCKED -1
1517 #endif /* < 2.6.9 */
1519 /*****************************************************************************/
1520 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) )
1521 #ifdef module_param_array_named
1522 #undef module_param_array_named
1523 #define module_param_array_named(name, array, type, nump, perm) \
1524 static struct kparam_array __param_arr_##name \
1525 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type, \
1526 sizeof(array[0]), array }; \
1527 module_param_call(name, param_array_set, param_array_get, \
1528 &__param_arr_##name, perm)
1529 #endif /* module_param_array_named */
1531 * num_online is broken for all < 2.6.10 kernels. This is needed to support
1532 * Node module parameter of ixgbe.
1534 #undef num_online_nodes
1535 #define num_online_nodes(n) 1
1536 extern DECLARE_BITMAP(_kcompat_node_online_map, MAX_NUMNODES);
1537 #undef node_online_map
1538 #define node_online_map _kcompat_node_online_map
1539 #endif /* < 2.6.10 */
1541 /*****************************************************************************/
1542 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) )
1547 #define PCI_D3cold 4
1548 typedef int pci_power_t;
1549 #define pci_choose_state(pdev,state) state
1550 #define PMSG_SUSPEND 3
1551 #define PCI_EXP_LNKCTL 16
1555 #ifndef ARCH_HAS_PREFETCH
1559 #ifndef NET_IP_ALIGN
1560 #define NET_IP_ALIGN 2
1563 #define KC_USEC_PER_SEC 1000000L
1564 #define usecs_to_jiffies _kc_usecs_to_jiffies
1565 static inline unsigned int _kc_jiffies_to_usecs(const unsigned long j)
1567 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1568 return (KC_USEC_PER_SEC / HZ) * j;
1569 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1570 return (j + (HZ / KC_USEC_PER_SEC) - 1)/(HZ / KC_USEC_PER_SEC);
1572 return (j * KC_USEC_PER_SEC) / HZ;
1575 static inline unsigned long _kc_usecs_to_jiffies(const unsigned int m)
1577 if (m > _kc_jiffies_to_usecs(MAX_JIFFY_OFFSET))
1578 return MAX_JIFFY_OFFSET;
1579 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1580 return (m + (KC_USEC_PER_SEC / HZ) - 1) / (KC_USEC_PER_SEC / HZ);
1581 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1582 return m * (HZ / KC_USEC_PER_SEC);
1584 return (m * HZ + KC_USEC_PER_SEC - 1) / KC_USEC_PER_SEC;
1587 #endif /* < 2.6.11 */
1589 /*****************************************************************************/
1590 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) )
1591 #include <linux/reboot.h>
1592 #define USE_REBOOT_NOTIFIER
1594 /* Generic MII registers. */
1595 #define MII_CTRL1000 0x09 /* 1000BASE-T control */
1596 #define MII_STAT1000 0x0a /* 1000BASE-T status */
1597 /* Advertisement control register. */
1598 #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
1599 #define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymmetric pause */
1600 /* 1000BASE-T Control register */
1601 #define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
1602 #ifndef is_zero_ether_addr
1603 #define is_zero_ether_addr _kc_is_zero_ether_addr
1604 static inline int _kc_is_zero_ether_addr(const u8 *addr)
1606 return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
1608 #endif /* is_zero_ether_addr */
1609 #ifndef is_multicast_ether_addr
1610 #define is_multicast_ether_addr _kc_is_multicast_ether_addr
1611 static inline int _kc_is_multicast_ether_addr(const u8 *addr)
1613 return addr[0] & 0x01;
1615 #endif /* is_multicast_ether_addr */
1616 #endif /* < 2.6.12 */
1618 /*****************************************************************************/
1619 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) )
1621 #define kstrdup _kc_kstrdup
1622 extern char *_kc_kstrdup(const char *s, unsigned int gfp);
1624 #endif /* < 2.6.13 */
1626 /*****************************************************************************/
1627 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) )
1628 #define pm_message_t u32
1630 #define kzalloc _kc_kzalloc
1631 extern void *_kc_kzalloc(size_t size, int flags);
1634 /* Generic MII registers. */
1635 #define MII_ESTATUS 0x0f /* Extended Status */
1636 /* Basic mode status register. */
1637 #define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
1638 /* Extended status register. */
1639 #define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */
1640 #define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */
1642 #define ADVERTISED_Pause (1 << 13)
1643 #define ADVERTISED_Asym_Pause (1 << 14)
1645 #if (!(RHEL_RELEASE_CODE && \
1646 (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,3)) && \
1647 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))))
1648 #if ((LINUX_VERSION_CODE == KERNEL_VERSION(2,6,9)) && !defined(gfp_t))
1649 #define gfp_t unsigned
1651 typedef unsigned gfp_t;
1653 #endif /* !RHEL4.3->RHEL5.0 */
1655 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9) )
1656 #ifdef CONFIG_X86_64
1657 #define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir) \
1658 dma_sync_single_for_cpu(dev, dma_handle, size, dir)
1659 #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir) \
1660 dma_sync_single_for_device(dev, dma_handle, size, dir)
1663 #endif /* < 2.6.14 */
1665 /*****************************************************************************/
1666 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) )
1667 #ifndef vmalloc_node
1668 #define vmalloc_node(a,b) vmalloc(a)
1669 #endif /* vmalloc_node*/
1671 #define setup_timer(_timer, _function, _data) \
1673 (_timer)->function = _function; \
1674 (_timer)->data = _data; \
1675 init_timer(_timer); \
1677 #ifndef device_can_wakeup
1678 #define device_can_wakeup(dev) (1)
1680 #ifndef device_set_wakeup_enable
1681 #define device_set_wakeup_enable(dev, val) do{}while(0)
1683 #ifndef device_init_wakeup
1684 #define device_init_wakeup(dev,val) do {} while (0)
1686 static inline unsigned _kc_compare_ether_addr(const u8 *addr1, const u8 *addr2)
1688 const u16 *a = (const u16 *) addr1;
1689 const u16 *b = (const u16 *) addr2;
1691 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
1693 #undef compare_ether_addr
1694 #define compare_ether_addr(addr1, addr2) _kc_compare_ether_addr(addr1, addr2)
1695 #endif /* < 2.6.15 */
1697 /*****************************************************************************/
1698 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) )
1700 #define DEFINE_MUTEX(x) DECLARE_MUTEX(x)
1701 #define mutex_lock(x) down_interruptible(x)
1702 #define mutex_unlock(x) up(x)
1704 #ifndef ____cacheline_internodealigned_in_smp
1706 #define ____cacheline_internodealigned_in_smp ____cacheline_aligned_in_smp
1708 #define ____cacheline_internodealigned_in_smp
1709 #endif /* CONFIG_SMP */
1710 #endif /* ____cacheline_internodealigned_in_smp */
1712 #else /* 2.6.16 and above */
1714 #define HAVE_PCI_ERS
1715 #endif /* < 2.6.16 */
1717 /*****************************************************************************/
1718 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) )
1719 #ifndef first_online_node
1720 #define first_online_node 0
1723 #define NET_SKB_PAD 16
1725 #endif /* < 2.6.17 */
1727 /*****************************************************************************/
1728 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) )
1731 #define irqreturn_t void
1736 #ifndef IRQF_PROBE_SHARED
1738 #define IRQF_PROBE_SHARED SA_PROBEIRQ
1740 #define IRQF_PROBE_SHARED 0
1745 #define IRQF_SHARED SA_SHIRQ
1749 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
1752 #ifndef FIELD_SIZEOF
1753 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
1758 #define skb_is_gso _kc_skb_is_gso
1759 static inline int _kc_skb_is_gso(const struct sk_buff *skb)
1761 return skb_shinfo(skb)->gso_size;
1764 #define skb_is_gso(a) 0
1768 #ifndef resource_size_t
1769 #define resource_size_t unsigned long
1775 #define skb_pad(x,y) _kc_skb_pad(x, y)
1776 int _kc_skb_pad(struct sk_buff *skb, int pad);
1780 #define skb_padto(x,y) _kc_skb_padto(x, y)
1781 static inline int _kc_skb_padto(struct sk_buff *skb, unsigned int len)
1783 unsigned int size = skb->len;
1784 if(likely(size >= len))
1786 return _kc_skb_pad(skb, len - size);
1789 #ifndef DECLARE_PCI_UNMAP_ADDR
1790 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
1791 dma_addr_t ADDR_NAME
1792 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
1794 #define pci_unmap_addr(PTR, ADDR_NAME) \
1796 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
1797 (((PTR)->ADDR_NAME) = (VAL))
1798 #define pci_unmap_len(PTR, LEN_NAME) \
1800 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
1801 (((PTR)->LEN_NAME) = (VAL))
1802 #endif /* DECLARE_PCI_UNMAP_ADDR */
1803 #endif /* < 2.6.18 */
1805 /*****************************************************************************/
1806 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) )
1808 #ifndef DIV_ROUND_UP
1809 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
1811 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) )
1812 #if (!((RHEL_RELEASE_CODE && \
1813 ((RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,4) && \
1814 RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0)) || \
1815 (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,0)))) || \
1816 (AX_RELEASE_CODE && AX_RELEASE_CODE > AX_RELEASE_VERSION(3,0))))
1817 typedef irqreturn_t (*irq_handler_t)(int, void*, struct pt_regs *);
1819 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
1820 #undef CONFIG_INET_LRO
1821 #undef CONFIG_INET_LRO_MODULE
1824 #undef CONFIG_FCOE_MODULE
1825 #endif /* IXGBE_FCOE */
1827 typedef irqreturn_t (*new_handler_t)(int, void*);
1828 static inline irqreturn_t _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1830 typedef void (*irq_handler_t)(int, void*, struct pt_regs *);
1831 typedef void (*new_handler_t)(int, void*);
1832 static inline int _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1833 #endif /* >= 2.5.x */
1835 irq_handler_t new_handler = (irq_handler_t) handler;
1836 return request_irq(irq, new_handler, flags, devname, dev_id);
1840 #define request_irq(irq, handler, flags, devname, dev_id) _kc_request_irq((irq), (handler), (flags), (devname), (dev_id))
1842 #define irq_handler_t new_handler_t
1843 /* pci_restore_state and pci_save_state handles MSI/PCIE from 2.6.19 */
1844 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))
1845 #define PCIE_CONFIG_SPACE_LEN 256
1846 #define PCI_CONFIG_SPACE_LEN 64
1847 #define PCIE_LINK_STATUS 0x12
1848 #define pci_config_space_ich8lan() do {} while(0)
1849 #undef pci_save_state
1850 extern int _kc_pci_save_state(struct pci_dev *);
1851 #define pci_save_state(pdev) _kc_pci_save_state(pdev)
1852 #undef pci_restore_state
1853 extern void _kc_pci_restore_state(struct pci_dev *);
1854 #define pci_restore_state(pdev) _kc_pci_restore_state(pdev)
1855 #endif /* !(RHEL_RELEASE_CODE >= RHEL 5.4) */
1859 extern void _kc_free_netdev(struct net_device *);
1860 #define free_netdev(netdev) _kc_free_netdev(netdev)
1862 static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
1866 #define pci_disable_pcie_error_reporting(dev) do {} while (0)
1867 #define pci_cleanup_aer_uncorrect_error_status(dev) do {} while (0)
1869 extern void *_kc_kmemdup(const void *src, size_t len, unsigned gfp);
1870 #define kmemdup(src, len, gfp) _kc_kmemdup(src, len, gfp)
1877 #include <linux/aer.h>
1878 #include <linux/string.h>
1879 #endif /* < 2.6.19 */
1881 /*****************************************************************************/
1882 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) )
1883 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28) )
1885 #define INIT_WORK(_work, _func) \
1887 INIT_LIST_HEAD(&(_work)->entry); \
1888 (_work)->pending = 0; \
1889 (_work)->func = (void (*)(void *))_func; \
1890 (_work)->data = _work; \
1891 init_timer(&(_work)->timer); \
1896 #define PCI_VDEVICE(ven, dev) \
1897 PCI_VENDOR_ID_##ven, (dev), \
1898 PCI_ANY_ID, PCI_ANY_ID, 0, 0
1901 #ifndef round_jiffies
1902 #define round_jiffies(x) x
1905 #define csum_offset csum
1907 #define HAVE_EARLY_VMALLOC_NODE
1908 #define dev_to_node(dev) -1
1910 /* remove compiler warning with b=b, for unused variable */
1911 #define set_dev_node(a, b) do { (b) = (b); } while(0)
1913 #if (!(RHEL_RELEASE_CODE && \
1914 (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1915 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1916 (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,6)))) && \
1917 !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1918 typedef __u16 __bitwise __sum16;
1919 typedef __u32 __bitwise __wsum;
1922 #if (!(RHEL_RELEASE_CODE && \
1923 (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1924 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1925 (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))) && \
1926 !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1927 static inline __wsum csum_unfold(__sum16 n)
1929 return (__force __wsum)n;
1933 #else /* < 2.6.20 */
1934 #define HAVE_DEVICE_NUMA_NODE
1935 #endif /* < 2.6.20 */
1937 /*****************************************************************************/
1938 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
1939 #define to_net_dev(class) container_of(class, struct net_device, class_dev)
1940 #define NETDEV_CLASS_DEV
1941 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)))
1942 #define vlan_group_get_device(vg, id) (vg->vlan_devices[id])
1943 #define vlan_group_set_device(vg, id, dev) \
1945 if (vg) vg->vlan_devices[id] = dev; \
1947 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)) */
1948 #define pci_channel_offline(pdev) (pdev->error_state && \
1949 pdev->error_state != pci_channel_io_normal)
1950 #define pci_request_selected_regions(pdev, bars, name) \
1951 pci_request_regions(pdev, name)
1952 #define pci_release_selected_regions(pdev, bars) pci_release_regions(pdev);
1953 #endif /* < 2.6.21 */
1955 /*****************************************************************************/
1956 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
1957 #define tcp_hdr(skb) (skb->h.th)
1958 #define tcp_hdrlen(skb) (skb->h.th->doff << 2)
1959 #define skb_transport_offset(skb) (skb->h.raw - skb->data)
1960 #define skb_transport_header(skb) (skb->h.raw)
1961 #define ipv6_hdr(skb) (skb->nh.ipv6h)
1962 #define ip_hdr(skb) (skb->nh.iph)
1963 #define skb_network_offset(skb) (skb->nh.raw - skb->data)
1964 #define skb_network_header(skb) (skb->nh.raw)
1965 #define skb_tail_pointer(skb) skb->tail
1966 #define skb_reset_tail_pointer(skb) \
1968 skb->tail = skb->data; \
1970 #define skb_copy_to_linear_data(skb, from, len) \
1971 memcpy(skb->data, from, len)
1972 #define skb_copy_to_linear_data_offset(skb, offset, from, len) \
1973 memcpy(skb->data + offset, from, len)
1974 #define skb_network_header_len(skb) (skb->h.raw - skb->nh.raw)
1975 #define pci_register_driver pci_module_init
1976 #define skb_mac_header(skb) skb->mac.raw
1978 #ifdef NETIF_F_MULTI_QUEUE
1979 #ifndef alloc_etherdev_mq
1980 #define alloc_etherdev_mq(_a, _b) alloc_etherdev(_a)
1982 #endif /* NETIF_F_MULTI_QUEUE */
1985 #define ETH_FCS_LEN 4
1987 #define cancel_work_sync(x) flush_scheduled_work()
1989 #define udp_hdr _udp_hdr
1990 static inline struct udphdr *_udp_hdr(const struct sk_buff *skb)
1992 return (struct udphdr *)skb_transport_header(skb);
1999 #define cpu_to_be16(x) __constant_htons(x)
2001 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)))
2004 DUMP_PREFIX_ADDRESS,
2007 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)) */
2009 #define hex_asc(x) "0123456789abcdef"[x]
2011 #include <linux/ctype.h>
2012 extern void _kc_print_hex_dump(const char *level, const char *prefix_str,
2013 int prefix_type, int rowsize, int groupsize,
2014 const void *buf, size_t len, bool ascii);
2015 #define print_hex_dump(lvl, s, t, r, g, b, l, a) \
2016 _kc_print_hex_dump(lvl, s, t, r, g, b, l, a)
2018 #define ETH_TYPE_TRANS_SETS_DEV
2019 #define HAVE_NETDEV_STATS_IN_NETDEV
2020 #endif /* < 2.6.22 */
2022 /*****************************************************************************/
2023 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22) )
2024 #undef SET_MODULE_OWNER
2025 #define SET_MODULE_OWNER(dev) do { } while (0)
2026 #endif /* > 2.6.22 */
2028 /*****************************************************************************/
2029 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) )
2030 #define netif_subqueue_stopped(_a, _b) 0
2032 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
2035 #ifndef CONFIG_PM_SLEEP
2036 #define CONFIG_PM_SLEEP CONFIG_PM
2039 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13) )
2040 #define HAVE_ETHTOOL_GET_PERM_ADDR
2041 #endif /* 2.6.14 through 2.6.22 */
2042 #endif /* < 2.6.23 */
2044 /*****************************************************************************/
2045 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
2046 #ifndef ETH_FLAG_LRO
2047 #define ETH_FLAG_LRO NETIF_F_LRO
2050 /* if GRO is supported then the napi struct must already exist */
2052 /* NAPI API changes in 2.6.24 break everything */
2053 struct napi_struct {
2054 /* used to look up the real NAPI polling routine */
2055 int (*poll)(struct napi_struct *, int);
2056 struct net_device *dev;
2062 extern int __kc_adapter_clean(struct net_device *, int *);
2063 extern struct net_device *napi_to_poll_dev(struct napi_struct *napi);
2064 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2066 struct napi_struct *__napi = (_napi); \
2067 struct net_device *poll_dev = napi_to_poll_dev(__napi); \
2068 poll_dev->poll = &(__kc_adapter_clean); \
2069 poll_dev->priv = (_napi); \
2070 poll_dev->weight = (_weight); \
2071 set_bit(__LINK_STATE_RX_SCHED, &poll_dev->state); \
2072 set_bit(__LINK_STATE_START, &poll_dev->state);\
2073 dev_hold(poll_dev); \
2074 __napi->poll = &(_poll); \
2075 __napi->weight = (_weight); \
2076 __napi->dev = (_netdev); \
2078 #define netif_napi_del(_napi) \
2080 struct net_device *poll_dev = napi_to_poll_dev(_napi); \
2081 WARN_ON(!test_bit(__LINK_STATE_RX_SCHED, &poll_dev->state)); \
2082 dev_put(poll_dev); \
2083 memset(poll_dev, 0, sizeof(struct net_device));\
2085 #define napi_schedule_prep(_napi) \
2086 (netif_running((_napi)->dev) && netif_rx_schedule_prep(napi_to_poll_dev(_napi)))
2087 #define napi_schedule(_napi) \
2089 if (napi_schedule_prep(_napi)) \
2090 __netif_rx_schedule(napi_to_poll_dev(_napi)); \
2092 #define napi_enable(_napi) netif_poll_enable(napi_to_poll_dev(_napi))
2093 #define napi_disable(_napi) netif_poll_disable(napi_to_poll_dev(_napi))
2094 #define __napi_schedule(_napi) __netif_rx_schedule(napi_to_poll_dev(_napi))
2096 #define napi_complete(_napi) netif_rx_complete(napi_to_poll_dev(_napi))
2098 #define napi_complete(_napi) \
2100 napi_gro_flush(_napi); \
2101 netif_rx_complete(napi_to_poll_dev(_napi)); \
2103 #endif /* NETIF_F_GRO */
2105 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2107 struct napi_struct *__napi = _napi; \
2108 _netdev->poll = &(_poll); \
2109 _netdev->weight = (_weight); \
2110 __napi->poll = &(_poll); \
2111 __napi->weight = (_weight); \
2112 __napi->dev = (_netdev); \
2114 #define netif_napi_del(_a) do {} while (0)
2117 #undef dev_get_by_name
2118 #define dev_get_by_name(_a, _b) dev_get_by_name(_b)
2119 #define __netif_subqueue_stopped(_a, _b) netif_subqueue_stopped(_a, _b)
2120 #ifndef DMA_BIT_MASK
2121 #define DMA_BIT_MASK(n) (((n) == 64) ? DMA_64BIT_MASK : ((1ULL<<(n))-1))
2125 #define skb_is_gso_v6 _kc_skb_is_gso_v6
2126 static inline int _kc_skb_is_gso_v6(const struct sk_buff *skb)
2128 return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6;
2130 #endif /* NETIF_F_TSO6 */
2133 #define KERN_CONT ""
2135 #else /* < 2.6.24 */
2136 #define HAVE_ETHTOOL_GET_SSET_COUNT
2137 #define HAVE_NETDEV_NAPI_LIST
2138 #endif /* < 2.6.24 */
2140 /*****************************************************************************/
2141 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) )
2142 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2143 #include <linux/pm_qos_params.h>
2144 #else /* >= 3.2.0 */
2145 #include <linux/pm_qos.h>
2146 #endif /* else >= 3.2.0 */
2147 #endif /* > 2.6.24 */
2149 /*****************************************************************************/
2150 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) )
2151 #define PM_QOS_CPU_DMA_LATENCY 1
2153 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18) )
2154 #include <linux/latency.h>
2155 #define PM_QOS_DEFAULT_VALUE INFINITE_LATENCY
2156 #define pm_qos_add_requirement(pm_qos_class, name, value) \
2157 set_acceptable_latency(name, value)
2158 #define pm_qos_remove_requirement(pm_qos_class, name) \
2159 remove_acceptable_latency(name)
2160 #define pm_qos_update_requirement(pm_qos_class, name, value) \
2161 modify_acceptable_latency(name, value)
2163 #define PM_QOS_DEFAULT_VALUE -1
2164 #define pm_qos_add_requirement(pm_qos_class, name, value)
2165 #define pm_qos_remove_requirement(pm_qos_class, name)
2166 #define pm_qos_update_requirement(pm_qos_class, name, value) { \
2167 if (value != PM_QOS_DEFAULT_VALUE) { \
2168 printk(KERN_WARNING "%s: unable to set PM QoS requirement\n", \
2169 pci_name(adapter->pdev)); \
2173 #endif /* > 2.6.18 */
2175 #define pci_enable_device_mem(pdev) pci_enable_device(pdev)
2177 #ifndef DEFINE_PCI_DEVICE_TABLE
2178 #define DEFINE_PCI_DEVICE_TABLE(_table) struct pci_device_id _table[]
2179 #endif /* DEFINE_PCI_DEVICE_TABLE */
2184 #endif /* IGB_PROCFS */
2186 #else /* < 2.6.25 */
2191 #endif /* IGB_SYSFS */
2193 #endif /* < 2.6.25 */
2195 /*****************************************************************************/
2196 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) )
2198 #define clamp_t(type, val, min, max) ({ \
2199 type __val = (val); \
2200 type __min = (min); \
2201 type __max = (max); \
2202 __val = __val < __min ? __min : __val; \
2203 __val > __max ? __max : __val; })
2204 #endif /* clamp_t */
2206 #define kzalloc_node(_size, _flags, _node) kzalloc(_size, _flags)
2208 extern void _kc_pci_disable_link_state(struct pci_dev *dev, int state);
2209 #define pci_disable_link_state(p, s) _kc_pci_disable_link_state(p, s)
2210 #else /* < 2.6.26 */
2211 #include <linux/pci-aspm.h>
2212 #define HAVE_NETDEV_VLAN_FEATURES
2213 #endif /* < 2.6.26 */
2214 /*****************************************************************************/
2215 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) )
2216 static inline void _kc_ethtool_cmd_speed_set(struct ethtool_cmd *ep,
2219 ep->speed = (__u16)speed;
2220 /* ep->speed_hi = (__u16)(speed >> 16); */
2222 #define ethtool_cmd_speed_set _kc_ethtool_cmd_speed_set
2224 static inline __u32 _kc_ethtool_cmd_speed(struct ethtool_cmd *ep)
2226 /* no speed_hi before 2.6.27, and probably no need for it yet */
2227 return (__u32)ep->speed;
2229 #define ethtool_cmd_speed _kc_ethtool_cmd_speed
2231 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) )
2232 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)) && defined(CONFIG_PM))
2233 #define ANCIENT_PM 1
2234 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) && \
2235 (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) && \
2236 defined(CONFIG_PM_SLEEP))
2239 #if defined(ANCIENT_PM) || defined(NEWER_PM)
2240 #undef device_set_wakeup_enable
2241 #define device_set_wakeup_enable(dev, val) \
2244 int pm = pci_find_capability(adapter->pdev, PCI_CAP_ID_PM); \
2246 pci_read_config_word(adapter->pdev, pm + PCI_PM_PMC, \
2249 (dev)->power.can_wakeup = !!(pmc >> 11); \
2250 (dev)->power.should_wakeup = (val && (pmc >> 11)); \
2252 #endif /* 2.6.15-2.6.22 and CONFIG_PM or 2.6.23-2.6.25 and CONFIG_PM_SLEEP */
2253 #endif /* 2.6.15 through 2.6.27 */
2254 #ifndef netif_napi_del
2255 #define netif_napi_del(_a) do {} while (0)
2257 #ifdef CONFIG_NETPOLL
2258 #undef netif_napi_del
2259 #define netif_napi_del(_a) list_del(&(_a)->dev_list);
2262 #endif /* netif_napi_del */
2263 #ifdef dma_mapping_error
2264 #undef dma_mapping_error
2266 #define dma_mapping_error(dev, dma_addr) pci_dma_mapping_error(dma_addr)
2268 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2273 extern void _kc_netif_tx_stop_all_queues(struct net_device *);
2274 extern void _kc_netif_tx_wake_all_queues(struct net_device *);
2275 extern void _kc_netif_tx_start_all_queues(struct net_device *);
2276 #define netif_tx_stop_all_queues(a) _kc_netif_tx_stop_all_queues(a)
2277 #define netif_tx_wake_all_queues(a) _kc_netif_tx_wake_all_queues(a)
2278 #define netif_tx_start_all_queues(a) _kc_netif_tx_start_all_queues(a)
2279 #undef netif_stop_subqueue
2280 #define netif_stop_subqueue(_ndev,_qi) do { \
2281 if (netif_is_multiqueue((_ndev))) \
2282 netif_stop_subqueue((_ndev), (_qi)); \
2284 netif_stop_queue((_ndev)); \
2286 #undef netif_start_subqueue
2287 #define netif_start_subqueue(_ndev,_qi) do { \
2288 if (netif_is_multiqueue((_ndev))) \
2289 netif_start_subqueue((_ndev), (_qi)); \
2291 netif_start_queue((_ndev)); \
2293 #else /* HAVE_TX_MQ */
2294 #define netif_tx_stop_all_queues(a) netif_stop_queue(a)
2295 #define netif_tx_wake_all_queues(a) netif_wake_queue(a)
2296 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) )
2297 #define netif_tx_start_all_queues(a) netif_start_queue(a)
2299 #define netif_tx_start_all_queues(a) do {} while (0)
2301 #define netif_stop_subqueue(_ndev,_qi) netif_stop_queue((_ndev))
2302 #define netif_start_subqueue(_ndev,_qi) netif_start_queue((_ndev))
2303 #endif /* HAVE_TX_MQ */
2304 #ifndef NETIF_F_MULTI_QUEUE
2305 #define NETIF_F_MULTI_QUEUE 0
2306 #define netif_is_multiqueue(a) 0
2307 #define netif_wake_subqueue(a, b)
2308 #endif /* NETIF_F_MULTI_QUEUE */
2310 #ifndef __WARN_printf
2311 extern void __kc_warn_slowpath(const char *file, const int line,
2312 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
2313 #define __WARN_printf(arg...) __kc_warn_slowpath(__FILE__, __LINE__, arg)
2314 #endif /* __WARN_printf */
2317 #define WARN(condition, format...) ({ \
2318 int __ret_warn_on = !!(condition); \
2319 if (unlikely(__ret_warn_on)) \
2320 __WARN_printf(format); \
2321 unlikely(__ret_warn_on); \
2324 #else /* < 2.6.27 */
2326 #define HAVE_NETDEV_SELECT_QUEUE
2327 #endif /* < 2.6.27 */
2329 /*****************************************************************************/
2330 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) )
2331 #define pci_ioremap_bar(pdev, bar) ioremap(pci_resource_start(pdev, bar), \
2332 pci_resource_len(pdev, bar))
2333 #define pci_wake_from_d3 _kc_pci_wake_from_d3
2334 #define pci_prepare_to_sleep _kc_pci_prepare_to_sleep
2335 extern int _kc_pci_wake_from_d3(struct pci_dev *dev, bool enable);
2336 extern int _kc_pci_prepare_to_sleep(struct pci_dev *dev);
2337 #define netdev_alloc_page(a) alloc_page(GFP_ATOMIC)
2338 #ifndef __skb_queue_head_init
2339 static inline void __kc_skb_queue_head_init(struct sk_buff_head *list)
2341 list->prev = list->next = (struct sk_buff *)list;
2344 #define __skb_queue_head_init(_q) __kc_skb_queue_head_init(_q)
2346 #ifndef skb_add_rx_frag
2347 #define skb_add_rx_frag _kc_skb_add_rx_frag
2348 extern void _kc_skb_add_rx_frag(struct sk_buff *, int, struct page *, int, int);
2350 #endif /* < 2.6.28 */
2352 /*****************************************************************************/
2353 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) )
2355 #define swap(a, b) \
2356 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
2358 #define pci_request_selected_regions_exclusive(pdev, bars, name) \
2359 pci_request_selected_regions(pdev, bars, name)
2360 #ifndef CONFIG_NR_CPUS
2361 #define CONFIG_NR_CPUS 1
2362 #endif /* CONFIG_NR_CPUS */
2363 #ifndef pcie_aspm_enabled
2364 #define pcie_aspm_enabled() (1)
2365 #endif /* pcie_aspm_enabled */
2366 #else /* < 2.6.29 */
2367 #ifndef HAVE_NET_DEVICE_OPS
2368 #define HAVE_NET_DEVICE_OPS
2371 #define HAVE_PFC_MODE_ENABLE
2372 #endif /* CONFIG_DCB */
2373 #endif /* < 2.6.29 */
2375 /*****************************************************************************/
2376 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) )
2377 #define skb_rx_queue_recorded(a) false
2378 #define skb_get_rx_queue(a) 0
2379 #define skb_record_rx_queue(a, b) do {} while (0)
2380 #define skb_tx_hash(n, s) ___kc_skb_tx_hash((n), (s), (n)->real_num_tx_queues)
2383 #undef CONFIG_FCOE_MODULE
2384 #endif /* IXGBE_FCOE */
2385 #ifndef CONFIG_PCI_IOV
2386 #undef pci_enable_sriov
2387 #define pci_enable_sriov(a, b) -ENOTSUPP
2388 #undef pci_disable_sriov
2389 #define pci_disable_sriov(a) do {} while (0)
2390 #endif /* CONFIG_PCI_IOV */
2392 #define pr_cont(fmt, ...) \
2393 printk(KERN_CONT fmt, ##__VA_ARGS__)
2394 #endif /* pr_cont */
2396 #define HAVE_ASPM_QUIRKS
2397 #endif /* < 2.6.30 */
2399 /*****************************************************************************/
2400 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) )
2401 #define ETH_P_1588 0x88F7
2402 #define ETH_P_FIP 0x8914
2403 #ifndef netdev_uc_count
2404 #define netdev_uc_count(dev) ((dev)->uc_count)
2406 #ifndef netdev_for_each_uc_addr
2407 #define netdev_for_each_uc_addr(uclist, dev) \
2408 for (uclist = dev->uc_list; uclist; uclist = uclist->next)
2411 #ifndef HAVE_NETDEV_STORAGE_ADDRESS
2412 #define HAVE_NETDEV_STORAGE_ADDRESS
2414 #ifndef HAVE_NETDEV_HW_ADDR
2415 #define HAVE_NETDEV_HW_ADDR
2417 #ifndef HAVE_TRANS_START_IN_QUEUE
2418 #define HAVE_TRANS_START_IN_QUEUE
2420 #endif /* < 2.6.31 */
2422 /*****************************************************************************/
2423 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) )
2425 #define netdev_tx_t int
2426 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2427 #ifndef NETIF_F_FCOE_MTU
2428 #define NETIF_F_FCOE_MTU (1 << 26)
2430 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2432 #ifndef pm_runtime_get_sync
2433 #define pm_runtime_get_sync(dev) do {} while (0)
2435 #ifndef pm_runtime_put
2436 #define pm_runtime_put(dev) do {} while (0)
2438 #ifndef pm_runtime_put_sync
2439 #define pm_runtime_put_sync(dev) do {} while (0)
2441 #ifndef pm_runtime_resume
2442 #define pm_runtime_resume(dev) do {} while (0)
2444 #ifndef pm_schedule_suspend
2445 #define pm_schedule_suspend(dev, t) do {} while (0)
2447 #ifndef pm_runtime_set_suspended
2448 #define pm_runtime_set_suspended(dev) do {} while (0)
2450 #ifndef pm_runtime_disable
2451 #define pm_runtime_disable(dev) do {} while (0)
2453 #ifndef pm_runtime_put_noidle
2454 #define pm_runtime_put_noidle(dev) do {} while (0)
2456 #ifndef pm_runtime_set_active
2457 #define pm_runtime_set_active(dev) do {} while (0)
2459 #ifndef pm_runtime_enable
2460 #define pm_runtime_enable(dev) do {} while (0)
2462 #ifndef pm_runtime_get_noresume
2463 #define pm_runtime_get_noresume(dev) do {} while (0)
2465 #else /* < 2.6.32 */
2466 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2467 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2468 #define HAVE_NETDEV_OPS_FCOE_ENABLE
2470 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2472 #ifndef HAVE_DCBNL_OPS_GETAPP
2473 #define HAVE_DCBNL_OPS_GETAPP
2475 #endif /* CONFIG_DCB */
2476 #include <linux/pm_runtime.h>
2477 /* IOV bad DMA target work arounds require at least this kernel rev support */
2478 #define HAVE_PCIE_TYPE
2479 #endif /* < 2.6.32 */
2481 /*****************************************************************************/
2482 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) )
2483 #ifndef pci_pcie_cap
2484 #define pci_pcie_cap(pdev) pci_find_capability(pdev, PCI_CAP_ID_EXP)
2487 #define IPV4_FLOW 0x10
2488 #endif /* IPV4_FLOW */
2490 #define IPV6_FLOW 0x11
2491 #endif /* IPV6_FLOW */
2492 /* Features back-ported to RHEL6 or SLES11 SP1 after 2.6.32 */
2493 #if ( (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)) || \
2494 (SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,1,0)) )
2495 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2496 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2497 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2499 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2500 #endif /* RHEL6 or SLES11 SP1 */
2503 #endif /* __percpu */
2504 #else /* < 2.6.33 */
2505 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2506 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2507 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2509 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2510 #define HAVE_ETHTOOL_SFP_DISPLAY_PORT
2511 #endif /* < 2.6.33 */
2513 /*****************************************************************************/
2514 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) )
2515 #ifndef ETH_FLAG_NTUPLE
2516 #define ETH_FLAG_NTUPLE NETIF_F_NTUPLE
2519 #ifndef netdev_mc_count
2520 #define netdev_mc_count(dev) ((dev)->mc_count)
2522 #ifndef netdev_mc_empty
2523 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
2525 #ifndef netdev_for_each_mc_addr
2526 #define netdev_for_each_mc_addr(mclist, dev) \
2527 for (mclist = dev->mc_list; mclist; mclist = mclist->next)
2529 #ifndef netdev_uc_count
2530 #define netdev_uc_count(dev) ((dev)->uc.count)
2532 #ifndef netdev_uc_empty
2533 #define netdev_uc_empty(dev) (netdev_uc_count(dev) == 0)
2535 #ifndef netdev_for_each_uc_addr
2536 #define netdev_for_each_uc_addr(ha, dev) \
2537 list_for_each_entry(ha, &dev->uc.list, list)
2539 #ifndef dma_set_coherent_mask
2540 #define dma_set_coherent_mask(dev,mask) \
2541 pci_set_consistent_dma_mask(to_pci_dev(dev),(mask))
2543 #ifndef pci_dev_run_wake
2544 #define pci_dev_run_wake(pdev) (0)
2547 /* netdev logging taken from include/linux/netdevice.h */
2549 static inline const char *_kc_netdev_name(const struct net_device *dev)
2551 if (dev->reg_state != NETREG_REGISTERED)
2552 return "(unregistered net_device)";
2555 #define netdev_name(netdev) _kc_netdev_name(netdev)
2556 #endif /* netdev_name */
2558 #undef netdev_printk
2559 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
2560 #define netdev_printk(level, netdev, format, args...) \
2562 struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2563 struct pci_dev *pdev = kc_adapter->pdev; \
2564 printk("%s %s: " format, level, pci_name(pdev), \
2567 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
2568 #define netdev_printk(level, netdev, format, args...) \
2570 struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2571 struct pci_dev *pdev = kc_adapter->pdev; \
2572 struct device *dev = pci_dev_to_dev(pdev); \
2573 dev_printk(level, dev, "%s: " format, \
2574 netdev_name(netdev), ##args); \
2576 #else /* 2.6.21 => 2.6.34 */
2577 #define netdev_printk(level, netdev, format, args...) \
2578 dev_printk(level, (netdev)->dev.parent, \
2580 netdev_name(netdev), ##args)
2581 #endif /* <2.6.0 <2.6.21 <2.6.34 */
2583 #define netdev_emerg(dev, format, args...) \
2584 netdev_printk(KERN_EMERG, dev, format, ##args)
2586 #define netdev_alert(dev, format, args...) \
2587 netdev_printk(KERN_ALERT, dev, format, ##args)
2589 #define netdev_crit(dev, format, args...) \
2590 netdev_printk(KERN_CRIT, dev, format, ##args)
2592 #define netdev_err(dev, format, args...) \
2593 netdev_printk(KERN_ERR, dev, format, ##args)
2595 #define netdev_warn(dev, format, args...) \
2596 netdev_printk(KERN_WARNING, dev, format, ##args)
2597 #undef netdev_notice
2598 #define netdev_notice(dev, format, args...) \
2599 netdev_printk(KERN_NOTICE, dev, format, ##args)
2601 #define netdev_info(dev, format, args...) \
2602 netdev_printk(KERN_INFO, dev, format, ##args)
2604 #if defined(CONFIG_DYNAMIC_DEBUG)
2605 #define netdev_dbg(__dev, format, args...) \
2607 dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \
2608 netdev_name(__dev), ##args); \
2611 #define netdev_dbg(__dev, format, args...) \
2614 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
2620 #define netif_printk(priv, type, level, dev, fmt, args...) \
2622 if (netif_msg_##type(priv)) \
2623 netdev_printk(level, (dev), fmt, ##args); \
2627 #define netif_emerg(priv, type, dev, fmt, args...) \
2628 netif_level(emerg, priv, type, dev, fmt, ##args)
2630 #define netif_alert(priv, type, dev, fmt, args...) \
2631 netif_level(alert, priv, type, dev, fmt, ##args)
2633 #define netif_crit(priv, type, dev, fmt, args...) \
2634 netif_level(crit, priv, type, dev, fmt, ##args)
2636 #define netif_err(priv, type, dev, fmt, args...) \
2637 netif_level(err, priv, type, dev, fmt, ##args)
2639 #define netif_warn(priv, type, dev, fmt, args...) \
2640 netif_level(warn, priv, type, dev, fmt, ##args)
2642 #define netif_notice(priv, type, dev, fmt, args...) \
2643 netif_level(notice, priv, type, dev, fmt, ##args)
2645 #define netif_info(priv, type, dev, fmt, args...) \
2646 netif_level(info, priv, type, dev, fmt, ##args)
2648 #ifdef SET_SYSTEM_SLEEP_PM_OPS
2649 #define HAVE_SYSTEM_SLEEP_PM_OPS
2652 #ifndef for_each_set_bit
2653 #define for_each_set_bit(bit, addr, size) \
2654 for ((bit) = find_first_bit((addr), (size)); \
2656 (bit) = find_next_bit((addr), (size), (bit) + 1))
2657 #endif /* for_each_set_bit */
2659 #ifndef DEFINE_DMA_UNMAP_ADDR
2660 #define DEFINE_DMA_UNMAP_ADDR DECLARE_PCI_UNMAP_ADDR
2661 #define DEFINE_DMA_UNMAP_LEN DECLARE_PCI_UNMAP_LEN
2662 #define dma_unmap_addr pci_unmap_addr
2663 #define dma_unmap_addr_set pci_unmap_addr_set
2664 #define dma_unmap_len pci_unmap_len
2665 #define dma_unmap_len_set pci_unmap_len_set
2666 #endif /* DEFINE_DMA_UNMAP_ADDR */
2667 #else /* < 2.6.34 */
2668 #define HAVE_SYSTEM_SLEEP_PM_OPS
2669 #ifndef HAVE_SET_RX_MODE
2670 #define HAVE_SET_RX_MODE
2673 #endif /* < 2.6.34 */
2675 /*****************************************************************************/
2676 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) )
2677 #ifndef numa_node_id
2678 #define numa_node_id() 0
2681 #include <net/sch_generic.h>
2682 #ifndef CONFIG_NETDEVICES_MULTIQUEUE
2683 void _kc_netif_set_real_num_tx_queues(struct net_device *, unsigned int);
2684 #define netif_set_real_num_tx_queues _kc_netif_set_real_num_tx_queues
2685 #else /* CONFIG_NETDEVICES_MULTI_QUEUE */
2686 #define netif_set_real_num_tx_queues(_netdev, _count) \
2688 (_netdev)->egress_subqueue_count = _count; \
2690 #endif /* CONFIG_NETDEVICES_MULTI_QUEUE */
2692 #define netif_set_real_num_tx_queues(_netdev, _count) do {} while(0)
2693 #endif /* HAVE_TX_MQ */
2694 #ifndef ETH_FLAG_RXHASH
2695 #define ETH_FLAG_RXHASH (1<<28)
2696 #endif /* ETH_FLAG_RXHASH */
2697 #else /* < 2.6.35 */
2698 #define HAVE_PM_QOS_REQUEST_LIST
2699 #define HAVE_IRQ_AFFINITY_HINT
2700 #endif /* < 2.6.35 */
2702 /*****************************************************************************/
2703 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) )
2704 extern int _kc_ethtool_op_set_flags(struct net_device *, u32, u32);
2705 #define ethtool_op_set_flags _kc_ethtool_op_set_flags
2706 extern u32 _kc_ethtool_op_get_flags(struct net_device *);
2707 #define ethtool_op_get_flags _kc_ethtool_op_get_flags
2709 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2713 #define NET_IP_ALIGN 0
2714 #endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
2720 #if (L1_CACHE_BYTES > 32)
2721 #define NET_SKB_PAD L1_CACHE_BYTES
2723 #define NET_SKB_PAD 32
2726 static inline struct sk_buff *_kc_netdev_alloc_skb_ip_align(struct net_device *dev,
2727 unsigned int length)
2729 struct sk_buff *skb;
2731 skb = alloc_skb(length + NET_SKB_PAD + NET_IP_ALIGN, GFP_ATOMIC);
2733 #if (NET_IP_ALIGN + NET_SKB_PAD)
2734 skb_reserve(skb, NET_IP_ALIGN + NET_SKB_PAD);
2741 #ifdef netdev_alloc_skb_ip_align
2742 #undef netdev_alloc_skb_ip_align
2744 #define netdev_alloc_skb_ip_align(n, l) _kc_netdev_alloc_skb_ip_align(n, l)
2747 #define netif_level(level, priv, type, dev, fmt, args...) \
2749 if (netif_msg_##type(priv)) \
2750 netdev_##level(dev, fmt, ##args); \
2754 #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
2756 #else /* < 2.6.36 */
2757 #define HAVE_PM_QOS_REQUEST_ACTIVE
2758 #define HAVE_8021P_SUPPORT
2759 #define HAVE_NDO_GET_STATS64
2760 #endif /* < 2.6.36 */
2762 /*****************************************************************************/
2763 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) )
2764 #ifndef ETHTOOL_RXNTUPLE_ACTION_CLEAR
2765 #define ETHTOOL_RXNTUPLE_ACTION_CLEAR (-2)
2768 #define VLAN_N_VID VLAN_GROUP_ARRAY_LEN
2769 #endif /* VLAN_N_VID */
2770 #ifndef ETH_FLAG_TXVLAN
2771 #define ETH_FLAG_TXVLAN (1 << 7)
2772 #endif /* ETH_FLAG_TXVLAN */
2773 #ifndef ETH_FLAG_RXVLAN
2774 #define ETH_FLAG_RXVLAN (1 << 8)
2775 #endif /* ETH_FLAG_RXVLAN */
2777 static inline void _kc_skb_checksum_none_assert(struct sk_buff *skb)
2779 WARN_ON(skb->ip_summed != CHECKSUM_NONE);
2781 #define skb_checksum_none_assert(skb) _kc_skb_checksum_none_assert(skb)
2783 static inline void *_kc_vzalloc_node(unsigned long size, int node)
2785 void *addr = vmalloc_node(size, node);
2787 memset(addr, 0, size);
2790 #define vzalloc_node(_size, _node) _kc_vzalloc_node(_size, _node)
2792 static inline void *_kc_vzalloc(unsigned long size)
2794 void *addr = vmalloc(size);
2796 memset(addr, 0, size);
2799 #define vzalloc(_size) _kc_vzalloc(_size)
2801 #ifndef vlan_get_protocol
2802 static inline __be16 __kc_vlan_get_protocol(const struct sk_buff *skb)
2804 if (vlan_tx_tag_present(skb) ||
2805 skb->protocol != cpu_to_be16(ETH_P_8021Q))
2806 return skb->protocol;
2808 if (skb_headlen(skb) < sizeof(struct vlan_ethhdr))
2811 return ((struct vlan_ethhdr*)skb->data)->h_vlan_encapsulated_proto;
2813 #define vlan_get_protocol(_skb) __kc_vlan_get_protocol(_skb)
2815 #ifdef HAVE_HW_TIME_STAMP
2816 #define SKBTX_HW_TSTAMP (1 << 0)
2817 #define SKBTX_IN_PROGRESS (1 << 2)
2818 #define SKB_SHARED_TX_IS_UNION
2820 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,18) )
2821 #ifndef HAVE_VLAN_RX_REGISTER
2822 #define HAVE_VLAN_RX_REGISTER
2824 #endif /* > 2.4.18 */
2825 #endif /* < 2.6.37 */
2827 /*****************************************************************************/
2828 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) )
2829 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
2830 #define skb_checksum_start_offset(skb) skb_transport_offset(skb)
2831 #else /* 2.6.22 -> 2.6.37 */
2832 static inline int _kc_skb_checksum_start_offset(const struct sk_buff *skb)
2834 return skb->csum_start - skb_headroom(skb);
2836 #define skb_checksum_start_offset(skb) _kc_skb_checksum_start_offset(skb)
2837 #endif /* 2.6.22 -> 2.6.37 */
2839 #ifndef IEEE_8021QAZ_MAX_TCS
2840 #define IEEE_8021QAZ_MAX_TCS 8
2842 #ifndef DCB_CAP_DCBX_HOST
2843 #define DCB_CAP_DCBX_HOST 0x01
2845 #ifndef DCB_CAP_DCBX_LLD_MANAGED
2846 #define DCB_CAP_DCBX_LLD_MANAGED 0x02
2848 #ifndef DCB_CAP_DCBX_VER_CEE
2849 #define DCB_CAP_DCBX_VER_CEE 0x04
2851 #ifndef DCB_CAP_DCBX_VER_IEEE
2852 #define DCB_CAP_DCBX_VER_IEEE 0x08
2854 #ifndef DCB_CAP_DCBX_STATIC
2855 #define DCB_CAP_DCBX_STATIC 0x10
2857 #endif /* CONFIG_DCB */
2858 extern u16 ___kc_skb_tx_hash(struct net_device *, const struct sk_buff *, u16);
2859 #define __skb_tx_hash(n, s, q) ___kc_skb_tx_hash((n), (s), (q))
2860 #else /* < 2.6.38 */
2861 #endif /* < 2.6.38 */
2863 /*****************************************************************************/
2864 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) )
2865 #ifndef skb_queue_reverse_walk_safe
2866 #define skb_queue_reverse_walk_safe(queue, skb, tmp) \
2867 for (skb = (queue)->prev, tmp = skb->prev; \
2868 skb != (struct sk_buff *)(queue); \
2869 skb = tmp, tmp = skb->prev)
2871 #else /* < 2.6.39 */
2872 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2873 #ifndef HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2874 #define HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2876 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2880 #ifndef HAVE_SETUP_TC
2881 #define HAVE_SETUP_TC
2884 #ifndef HAVE_DCBNL_IEEE
2885 #define HAVE_DCBNL_IEEE
2887 #endif /* CONFIG_DCB */
2888 #ifndef HAVE_NDO_SET_FEATURES
2889 #define HAVE_NDO_SET_FEATURES
2891 #endif /* < 2.6.39 */
2893 /*****************************************************************************/
2894 /* use < 2.6.40 because of a Fedora 15 kernel update where they
2895 * updated the kernel version to 2.6.40.x and they back-ported 3.0 features
2896 * like set_phys_id for ethtool.
2898 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40) )
2899 #ifdef ETHTOOL_GRXRINGS
2901 #define FLOW_EXT 0x80000000
2902 union _kc_ethtool_flow_union {
2903 struct ethtool_tcpip4_spec tcp_ip4_spec;
2904 struct ethtool_usrip4_spec usr_ip4_spec;
2907 struct _kc_ethtool_flow_ext {
2912 struct _kc_ethtool_rx_flow_spec {
2914 union _kc_ethtool_flow_union h_u;
2915 struct _kc_ethtool_flow_ext h_ext;
2916 union _kc_ethtool_flow_union m_u;
2917 struct _kc_ethtool_flow_ext m_ext;
2921 #define ethtool_rx_flow_spec _kc_ethtool_rx_flow_spec
2922 #endif /* FLOW_EXT */
2925 #define pci_disable_link_state_locked pci_disable_link_state
2927 #ifndef PCI_LTR_VALUE_MASK
2928 #define PCI_LTR_VALUE_MASK 0x000003ff
2930 #ifndef PCI_LTR_SCALE_MASK
2931 #define PCI_LTR_SCALE_MASK 0x00001c00
2933 #ifndef PCI_LTR_SCALE_SHIFT
2934 #define PCI_LTR_SCALE_SHIFT 10
2937 #else /* < 2.6.40 */
2938 #define HAVE_ETHTOOL_SET_PHYS_ID
2939 #endif /* < 2.6.40 */
2941 /*****************************************************************************/
2942 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
2943 #ifndef __netdev_alloc_skb_ip_align
2944 #define __netdev_alloc_skb_ip_align(d,l,_g) netdev_alloc_skb_ip_align(d,l)
2945 #endif /* __netdev_alloc_skb_ip_align */
2946 #define dcb_ieee_setapp(dev, app) dcb_setapp(dev, app)
2947 #define dcb_ieee_delapp(dev, app) 0
2948 #define dcb_ieee_getapp_mask(dev, app) (1 << app->priority)
2950 #ifndef HAVE_DCBNL_IEEE_DELAPP
2951 #define HAVE_DCBNL_IEEE_DELAPP
2953 #endif /* < 3.1.0 */
2955 /*****************************************************************************/
2956 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2957 #ifdef ETHTOOL_GRXRINGS
2958 #define HAVE_ETHTOOL_GET_RXNFC_VOID_RULE_LOCS
2959 #endif /* ETHTOOL_GRXRINGS */
2961 #ifndef skb_frag_size
2962 #define skb_frag_size(frag) _kc_skb_frag_size(frag)
2963 static inline unsigned int _kc_skb_frag_size(const skb_frag_t *frag)
2967 #endif /* skb_frag_size */
2969 #ifndef skb_frag_size_sub
2970 #define skb_frag_size_sub(frag, delta) _kc_skb_frag_size_sub(frag, delta)
2971 static inline void _kc_skb_frag_size_sub(skb_frag_t *frag, int delta)
2973 frag->size -= delta;
2975 #endif /* skb_frag_size_sub */
2977 #ifndef skb_frag_page
2978 #define skb_frag_page(frag) _kc_skb_frag_page(frag)
2979 static inline struct page *_kc_skb_frag_page(const skb_frag_t *frag)
2983 #endif /* skb_frag_page */
2985 #ifndef skb_frag_address
2986 #define skb_frag_address(frag) _kc_skb_frag_address(frag)
2987 static inline void *_kc_skb_frag_address(const skb_frag_t *frag)
2989 return page_address(skb_frag_page(frag)) + frag->page_offset;
2991 #endif /* skb_frag_address */
2993 #ifndef skb_frag_dma_map
2994 #define skb_frag_dma_map(dev,frag,offset,size,dir) \
2995 _kc_skb_frag_dma_map(dev,frag,offset,size,dir)
2996 static inline dma_addr_t _kc_skb_frag_dma_map(struct device *dev,
2997 const skb_frag_t *frag,
2998 size_t offset, size_t size,
2999 enum dma_data_direction dir)
3001 return dma_map_page(dev, skb_frag_page(frag),
3002 frag->page_offset + offset, size, dir);
3004 #endif /* skb_frag_dma_map */
3006 #ifndef __skb_frag_unref
3007 #define __skb_frag_unref(frag) __kc_skb_frag_unref(frag)
3008 static inline void __kc_skb_frag_unref(skb_frag_t *frag)
3010 put_page(skb_frag_page(frag));
3012 #endif /* __skb_frag_unref */
3014 #ifndef HAVE_PCI_DEV_FLAGS_ASSIGNED
3015 #define HAVE_PCI_DEV_FLAGS_ASSIGNED
3016 #define HAVE_VF_SPOOFCHK_CONFIGURE
3018 #endif /* < 3.2.0 */
3020 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(6,2))
3021 #undef ixgbe_get_netdev_tc_txq
3022 #define ixgbe_get_netdev_tc_txq(dev, tc) (&netdev_extended(dev)->qos_data.tc_to_txq[tc])
3025 /*****************************************************************************/
3026 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) )
3027 typedef u32 netdev_features_t;
3028 #else /* ! < 3.3.0 */
3029 #define HAVE_INT_NDO_VLAN_RX_ADD_VID
3030 #ifdef ETHTOOL_SRXNTUPLE
3031 #undef ETHTOOL_SRXNTUPLE
3033 #endif /* < 3.3.0 */
3035 /*****************************************************************************/
3036 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) )
3037 #ifndef NETIF_F_RXFCS
3038 #define NETIF_F_RXFCS 0
3039 #endif /* NETIF_F_RXFCS */
3040 #ifndef NETIF_F_RXALL
3041 #define NETIF_F_RXALL 0
3042 #endif /* NETIF_F_RXALL */
3044 #define NUMTCS_RETURNS_U8
3047 #endif /* < 3.4.0 */
3049 /*****************************************************************************/
3050 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) )
3052 #define HAVE_FDB_OPS
3053 #endif /* < 3.5.0 */
3055 /*****************************************************************************/
3056 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) )
3057 #define NETIF_F_HW_VLAN_TX NETIF_F_HW_VLAN_CTAG_TX
3058 #define NETIF_F_HW_VLAN_RX NETIF_F_HW_VLAN_CTAG_RX
3059 #define NETIF_F_HW_VLAN_FILTER NETIF_F_HW_VLAN_CTAG_FILTER
3060 #define HAVE_VLAN_PROTOCOL
3061 #endif /* >= 3.10.0 */
3063 #endif /* _KCOMPAT_H_ */