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 #define vlan_tx_tag_present(_skb) 0
305 #define vlan_tx_tag_get(_skb) 0
308 #ifndef VLAN_PRIO_SHIFT
309 #define VLAN_PRIO_SHIFT 13
317 /*****************************************************************************/
318 /* Installations with ethtool version without eeprom, adapter id, or statistics
321 #ifndef ETH_GSTRING_LEN
322 #define ETH_GSTRING_LEN 32
325 #ifndef ETHTOOL_GSTATS
326 #define ETHTOOL_GSTATS 0x1d
327 #undef ethtool_drvinfo
328 #define ethtool_drvinfo k_ethtool_drvinfo
329 struct k_ethtool_drvinfo {
343 struct ethtool_stats {
348 #endif /* ETHTOOL_GSTATS */
350 #ifndef ETHTOOL_PHYS_ID
351 #define ETHTOOL_PHYS_ID 0x1c
352 #endif /* ETHTOOL_PHYS_ID */
354 #ifndef ETHTOOL_GSTRINGS
355 #define ETHTOOL_GSTRINGS 0x1b
356 enum ethtool_stringset {
360 struct ethtool_gstrings {
361 u32 cmd; /* ETHTOOL_GSTRINGS */
362 u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/
363 u32 len; /* number of strings in the string set */
366 #endif /* ETHTOOL_GSTRINGS */
369 #define ETHTOOL_TEST 0x1a
370 enum ethtool_test_flags {
371 ETH_TEST_FL_OFFLINE = (1 << 0),
372 ETH_TEST_FL_FAILED = (1 << 1),
374 struct ethtool_test {
381 #endif /* ETHTOOL_TEST */
383 #ifndef ETHTOOL_GEEPROM
384 #define ETHTOOL_GEEPROM 0xb
386 struct ethtool_eeprom {
394 struct ethtool_value {
398 #endif /* ETHTOOL_GEEPROM */
400 #ifndef ETHTOOL_GLINK
401 #define ETHTOOL_GLINK 0xa
402 #endif /* ETHTOOL_GLINK */
405 #define ETHTOOL_GWOL 0x5
406 #define ETHTOOL_SWOL 0x6
408 struct ethtool_wolinfo {
412 u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */
414 #endif /* ETHTOOL_GWOL */
416 #ifndef ETHTOOL_GREGS
417 #define ETHTOOL_GREGS 0x00000004 /* Get NIC registers */
418 #define ethtool_regs _kc_ethtool_regs
419 /* for passing big chunks of data */
420 struct _kc_ethtool_regs {
422 u32 version; /* driver-specific, indicates different chips/revs */
426 #endif /* ETHTOOL_GREGS */
428 #ifndef ETHTOOL_GMSGLVL
429 #define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */
431 #ifndef ETHTOOL_SMSGLVL
432 #define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level, priv. */
434 #ifndef ETHTOOL_NWAY_RST
435 #define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation, priv */
437 #ifndef ETHTOOL_GLINK
438 #define ETHTOOL_GLINK 0x0000000a /* Get link status */
440 #ifndef ETHTOOL_GEEPROM
441 #define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
443 #ifndef ETHTOOL_SEEPROM
444 #define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */
446 #ifndef ETHTOOL_GCOALESCE
447 #define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */
448 /* for configuring coalescing parameters of chip */
449 #define ethtool_coalesce _kc_ethtool_coalesce
450 struct _kc_ethtool_coalesce {
451 u32 cmd; /* ETHTOOL_{G,S}COALESCE */
453 /* How many usecs to delay an RX interrupt after
454 * a packet arrives. If 0, only rx_max_coalesced_frames
457 u32 rx_coalesce_usecs;
459 /* How many packets to delay an RX interrupt after
460 * a packet arrives. If 0, only rx_coalesce_usecs is
461 * used. It is illegal to set both usecs and max frames
462 * to zero as this would cause RX interrupts to never be
465 u32 rx_max_coalesced_frames;
467 /* Same as above two parameters, except that these values
468 * apply while an IRQ is being serviced by the host. Not
469 * all cards support this feature and the values are ignored
472 u32 rx_coalesce_usecs_irq;
473 u32 rx_max_coalesced_frames_irq;
475 /* How many usecs to delay a TX interrupt after
476 * a packet is sent. If 0, only tx_max_coalesced_frames
479 u32 tx_coalesce_usecs;
481 /* How many packets to delay a TX interrupt after
482 * a packet is sent. If 0, only tx_coalesce_usecs is
483 * used. It is illegal to set both usecs and max frames
484 * to zero as this would cause TX interrupts to never be
487 u32 tx_max_coalesced_frames;
489 /* Same as above two parameters, except that these values
490 * apply while an IRQ is being serviced by the host. Not
491 * all cards support this feature and the values are ignored
494 u32 tx_coalesce_usecs_irq;
495 u32 tx_max_coalesced_frames_irq;
497 /* How many usecs to delay in-memory statistics
498 * block updates. Some drivers do not have an in-memory
499 * statistic block, and in such cases this value is ignored.
500 * This value must not be zero.
502 u32 stats_block_coalesce_usecs;
504 /* Adaptive RX/TX coalescing is an algorithm implemented by
505 * some drivers to improve latency under low packet rates and
506 * improve throughput under high packet rates. Some drivers
507 * only implement one of RX or TX adaptive coalescing. Anything
508 * not implemented by the driver causes these values to be
511 u32 use_adaptive_rx_coalesce;
512 u32 use_adaptive_tx_coalesce;
514 /* When the packet rate (measured in packets per second)
515 * is below pkt_rate_low, the {rx,tx}_*_low parameters are
519 u32 rx_coalesce_usecs_low;
520 u32 rx_max_coalesced_frames_low;
521 u32 tx_coalesce_usecs_low;
522 u32 tx_max_coalesced_frames_low;
524 /* When the packet rate is below pkt_rate_high but above
525 * pkt_rate_low (both measured in packets per second) the
526 * normal {rx,tx}_* coalescing parameters are used.
529 /* When the packet rate is (measured in packets per second)
530 * is above pkt_rate_high, the {rx,tx}_*_high parameters are
534 u32 rx_coalesce_usecs_high;
535 u32 rx_max_coalesced_frames_high;
536 u32 tx_coalesce_usecs_high;
537 u32 tx_max_coalesced_frames_high;
539 /* How often to do adaptive coalescing packet rate sampling,
540 * measured in seconds. Must not be zero.
542 u32 rate_sample_interval;
544 #endif /* ETHTOOL_GCOALESCE */
546 #ifndef ETHTOOL_SCOALESCE
547 #define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config. */
549 #ifndef ETHTOOL_GRINGPARAM
550 #define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */
551 /* for configuring RX/TX ring parameters */
552 #define ethtool_ringparam _kc_ethtool_ringparam
553 struct _kc_ethtool_ringparam {
554 u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */
556 /* Read only attributes. These indicate the maximum number
557 * of pending RX/TX ring entries the driver will allow the
561 u32 rx_mini_max_pending;
562 u32 rx_jumbo_max_pending;
565 /* Values changeable by the user. The valid values are
566 * in the range 1 to the "*_max_pending" counterpart above.
570 u32 rx_jumbo_pending;
573 #endif /* ETHTOOL_GRINGPARAM */
575 #ifndef ETHTOOL_SRINGPARAM
576 #define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters, priv. */
578 #ifndef ETHTOOL_GPAUSEPARAM
579 #define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */
580 /* for configuring link flow control parameters */
581 #define ethtool_pauseparam _kc_ethtool_pauseparam
582 struct _kc_ethtool_pauseparam {
583 u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */
585 /* If the link is being auto-negotiated (via ethtool_cmd.autoneg
586 * being true) the user may set 'autoneg' here non-zero to have the
587 * pause parameters be auto-negotiated too. In such a case, the
588 * {rx,tx}_pause values below determine what capabilities are
591 * If 'autoneg' is zero or the link is not being auto-negotiated,
592 * then {rx,tx}_pause force the driver to use/not-use pause
599 #endif /* ETHTOOL_GPAUSEPARAM */
601 #ifndef ETHTOOL_SPAUSEPARAM
602 #define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters. */
604 #ifndef ETHTOOL_GRXCSUM
605 #define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */
607 #ifndef ETHTOOL_SRXCSUM
608 #define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */
610 #ifndef ETHTOOL_GTXCSUM
611 #define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */
613 #ifndef ETHTOOL_STXCSUM
614 #define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */
617 #define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable
621 #define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable
622 * (ethtool_value). */
625 #define ETHTOOL_TEST 0x0000001a /* execute NIC self-test, priv. */
627 #ifndef ETHTOOL_GSTRINGS
628 #define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */
630 #ifndef ETHTOOL_PHYS_ID
631 #define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */
633 #ifndef ETHTOOL_GSTATS
634 #define ETHTOOL_GSTATS 0x0000001d /* get NIC-specific statistics */
637 #define ETHTOOL_GTSO 0x0000001e /* Get TSO enable (ethtool_value) */
640 #define ETHTOOL_STSO 0x0000001f /* Set TSO enable (ethtool_value) */
643 #ifndef ETHTOOL_BUSINFO_LEN
644 #define ETHTOOL_BUSINFO_LEN 32
647 #ifndef RHEL_RELEASE_CODE
648 /* NOTE: RHEL_RELEASE_* introduced in RHEL4.5 */
649 #define RHEL_RELEASE_CODE 0
651 #ifndef RHEL_RELEASE_VERSION
652 #define RHEL_RELEASE_VERSION(a,b) (((a) << 8) + (b))
654 #ifndef AX_RELEASE_CODE
655 #define AX_RELEASE_CODE 0
657 #ifndef AX_RELEASE_VERSION
658 #define AX_RELEASE_VERSION(a,b) (((a) << 8) + (b))
661 /* SuSE version macro is the same as Linux kernel version */
663 #define SLE_VERSION(a,b,c) KERNEL_VERSION(a,b,c)
665 #ifndef SLE_VERSION_CODE
666 #ifdef CONFIG_SUSE_KERNEL
667 /* SLES11 GA is 2.6.27 based */
668 #if ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,27) )
669 #define SLE_VERSION_CODE SLE_VERSION(11,0,0)
670 #elif ( LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32) )
671 /* SLES11 SP1 is 2.6.32 based */
672 #define SLE_VERSION_CODE SLE_VERSION(11,1,0)
674 #define SLE_VERSION_CODE 0
676 #else /* CONFIG_SUSE_KERNEL */
677 #define SLE_VERSION_CODE 0
678 #endif /* CONFIG_SUSE_KERNEL */
679 #endif /* SLE_VERSION_CODE */
684 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
686 #endif /* __KLOCWORK__ */
688 /*****************************************************************************/
690 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )
692 /**************************************/
695 #ifndef pci_set_dma_mask
696 #define pci_set_dma_mask _kc_pci_set_dma_mask
697 extern int _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask);
700 #ifndef pci_request_regions
701 #define pci_request_regions _kc_pci_request_regions
702 extern int _kc_pci_request_regions(struct pci_dev *pdev, char *res_name);
705 #ifndef pci_release_regions
706 #define pci_release_regions _kc_pci_release_regions
707 extern void _kc_pci_release_regions(struct pci_dev *pdev);
710 /**************************************/
711 /* NETWORK DRIVER API */
713 #ifndef alloc_etherdev
714 #define alloc_etherdev _kc_alloc_etherdev
715 extern struct net_device * _kc_alloc_etherdev(int sizeof_priv);
718 #ifndef is_valid_ether_addr
719 #define is_valid_ether_addr _kc_is_valid_ether_addr
720 extern int _kc_is_valid_ether_addr(u8 *addr);
723 /**************************************/
727 #define INIT_TQUEUE(_tq, _routine, _data) \
729 INIT_LIST_HEAD(&(_tq)->list); \
731 (_tq)->routine = _routine; \
732 (_tq)->data = _data; \
736 #endif /* 2.4.3 => 2.4.0 */
738 /*****************************************************************************/
739 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) )
740 /* Generic MII registers. */
741 #define MII_BMCR 0x00 /* Basic mode control register */
742 #define MII_BMSR 0x01 /* Basic mode status register */
743 #define MII_PHYSID1 0x02 /* PHYS ID 1 */
744 #define MII_PHYSID2 0x03 /* PHYS ID 2 */
745 #define MII_ADVERTISE 0x04 /* Advertisement control reg */
746 #define MII_LPA 0x05 /* Link partner ability reg */
747 #define MII_EXPANSION 0x06 /* Expansion register */
748 /* Basic mode control register. */
749 #define BMCR_FULLDPLX 0x0100 /* Full duplex */
750 #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */
751 /* Basic mode status register. */
752 #define BMSR_ERCAP 0x0001 /* Ext-reg capability */
753 #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */
754 #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */
755 #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */
756 #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */
757 #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */
758 /* Advertisement control register. */
759 #define ADVERTISE_CSMA 0x0001 /* Only selector supported */
760 #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
761 #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
762 #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
763 #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
764 #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
765 ADVERTISE_100HALF | ADVERTISE_100FULL)
766 /* Expansion register for auto-negotiation. */
767 #define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */
770 /*****************************************************************************/
772 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )
774 #ifndef pci_set_power_state
775 #define pci_set_power_state _kc_pci_set_power_state
776 extern int _kc_pci_set_power_state(struct pci_dev *dev, int state);
779 #ifndef pci_enable_wake
780 #define pci_enable_wake _kc_pci_enable_wake
781 extern int _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable);
784 #ifndef pci_disable_device
785 #define pci_disable_device _kc_pci_disable_device
786 extern void _kc_pci_disable_device(struct pci_dev *pdev);
789 /* PCI PM entry point syntax changed, so don't support suspend/resume */
792 #endif /* 2.4.6 => 2.4.3 */
794 #ifndef HAVE_PCI_SET_MWI
795 #define pci_set_mwi(X) pci_write_config_word(X, \
796 PCI_COMMAND, adapter->hw.bus.pci_cmd_word | \
797 PCI_COMMAND_INVALIDATE);
798 #define pci_clear_mwi(X) pci_write_config_word(X, \
799 PCI_COMMAND, adapter->hw.bus.pci_cmd_word & \
800 ~PCI_COMMAND_INVALIDATE);
803 /*****************************************************************************/
804 /* 2.4.10 => 2.4.9 */
805 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10) )
807 /**************************************/
810 #ifndef MODULE_LICENSE
811 #define MODULE_LICENSE(X)
814 /**************************************/
818 #define min(x,y) ({ \
819 const typeof(x) _x = (x); \
820 const typeof(y) _y = (y); \
821 (void) (&_x == &_y); \
822 _x < _y ? _x : _y; })
825 #define max(x,y) ({ \
826 const typeof(x) _x = (x); \
827 const typeof(y) _y = (y); \
828 (void) (&_x == &_y); \
829 _x > _y ? _x : _y; })
831 #define min_t(type,x,y) ({ \
834 _x < _y ? _x : _y; })
836 #define max_t(type,x,y) ({ \
839 _x > _y ? _x : _y; })
841 #ifndef list_for_each_safe
842 #define list_for_each_safe(pos, n, head) \
843 for (pos = (head)->next, n = pos->next; pos != (head); \
844 pos = n, n = pos->next)
847 #ifndef ____cacheline_aligned_in_smp
849 #define ____cacheline_aligned_in_smp ____cacheline_aligned
851 #define ____cacheline_aligned_in_smp
852 #endif /* CONFIG_SMP */
855 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) )
856 extern int _kc_snprintf(char * buf, size_t size, const char *fmt, ...);
857 #define snprintf(buf, size, fmt, args...) _kc_snprintf(buf, size, fmt, ##args)
858 extern int _kc_vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
859 #define vsnprintf(buf, size, fmt, args) _kc_vsnprintf(buf, size, fmt, args)
860 #else /* 2.4.8 => 2.4.9 */
861 extern int snprintf(char * buf, size_t size, const char *fmt, ...);
862 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
864 #endif /* 2.4.10 -> 2.4.6 */
867 /*****************************************************************************/
868 /* 2.4.12 => 2.4.10 */
869 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,12) )
870 #ifndef HAVE_NETIF_MSG
871 #define HAVE_NETIF_MSG 1
873 NETIF_MSG_DRV = 0x0001,
874 NETIF_MSG_PROBE = 0x0002,
875 NETIF_MSG_LINK = 0x0004,
876 NETIF_MSG_TIMER = 0x0008,
877 NETIF_MSG_IFDOWN = 0x0010,
878 NETIF_MSG_IFUP = 0x0020,
879 NETIF_MSG_RX_ERR = 0x0040,
880 NETIF_MSG_TX_ERR = 0x0080,
881 NETIF_MSG_TX_QUEUED = 0x0100,
882 NETIF_MSG_INTR = 0x0200,
883 NETIF_MSG_TX_DONE = 0x0400,
884 NETIF_MSG_RX_STATUS = 0x0800,
885 NETIF_MSG_PKTDATA = 0x1000,
886 NETIF_MSG_HW = 0x2000,
887 NETIF_MSG_WOL = 0x4000,
890 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
891 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
892 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
893 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
894 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
895 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
896 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
897 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
898 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
899 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
900 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
901 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
902 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
903 #endif /* !HAVE_NETIF_MSG */
904 #endif /* 2.4.12 => 2.4.10 */
906 /*****************************************************************************/
907 /* 2.4.13 => 2.4.12 */
908 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )
910 /**************************************/
911 /* PCI DMA MAPPING */
914 #define virt_to_page(v) (mem_map + (virt_to_phys(v) >> PAGE_SHIFT))
918 #define pci_map_page _kc_pci_map_page
919 extern u64 _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset, size_t size, int direction);
922 #ifndef pci_unmap_page
923 #define pci_unmap_page _kc_pci_unmap_page
924 extern void _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size, int direction);
927 /* pci_set_dma_mask takes dma_addr_t, which is only 32-bits prior to 2.4.13 */
929 #undef DMA_32BIT_MASK
930 #define DMA_32BIT_MASK 0xffffffff
931 #undef DMA_64BIT_MASK
932 #define DMA_64BIT_MASK 0xffffffff
934 /**************************************/
938 #define cpu_relax() rep_nop()
942 unsigned char h_dest[ETH_ALEN];
943 unsigned char h_source[ETH_ALEN];
944 unsigned short h_vlan_proto;
945 unsigned short h_vlan_TCI;
946 unsigned short h_vlan_encapsulated_proto;
948 #endif /* 2.4.13 => 2.4.12 */
950 /*****************************************************************************/
951 /* 2.4.17 => 2.4.12 */
952 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,17) )
955 #define __devexit_p(x) &(x)
958 #endif /* 2.4.17 => 2.4.13 */
960 /*****************************************************************************/
961 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18) )
962 #define NETIF_MSG_HW 0x2000
963 #define NETIF_MSG_WOL 0x4000
966 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
968 #ifndef netif_msg_wol
969 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
973 /*****************************************************************************/
975 /*****************************************************************************/
976 /* 2.4.20 => 2.4.19 */
977 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20) )
979 /* we won't support NAPI on less than 2.4.20 */
984 #endif /* 2.4.20 => 2.4.19 */
986 /*****************************************************************************/
987 /* 2.4.22 => 2.4.17 */
988 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
989 #define pci_name(x) ((x)->slot_name)
992 /*****************************************************************************/
993 /* 2.4.22 => 2.4.17 */
995 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,22) )
1001 /*****************************************************************************/
1002 /*****************************************************************************/
1003 /* 2.4.23 => 2.4.22 */
1004 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,23) )
1005 /*****************************************************************************/
1007 #ifndef netif_poll_disable
1008 #define netif_poll_disable(x) _kc_netif_poll_disable(x)
1009 static inline void _kc_netif_poll_disable(struct net_device *netdev)
1011 while (test_and_set_bit(__LINK_STATE_RX_SCHED, &netdev->state)) {
1013 current->state = TASK_INTERRUPTIBLE;
1014 schedule_timeout(1);
1018 #ifndef netif_poll_enable
1019 #define netif_poll_enable(x) _kc_netif_poll_enable(x)
1020 static inline void _kc_netif_poll_enable(struct net_device *netdev)
1022 clear_bit(__LINK_STATE_RX_SCHED, &netdev->state);
1026 #ifndef netif_tx_disable
1027 #define netif_tx_disable(x) _kc_netif_tx_disable(x)
1028 static inline void _kc_netif_tx_disable(struct net_device *dev)
1030 spin_lock_bh(&dev->xmit_lock);
1031 netif_stop_queue(dev);
1032 spin_unlock_bh(&dev->xmit_lock);
1035 #else /* 2.4.23 => 2.4.22 */
1037 #endif /* 2.4.23 => 2.4.22 */
1039 /*****************************************************************************/
1040 /* 2.6.4 => 2.6.0 */
1041 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \
1042 ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1043 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )
1044 #define ETHTOOL_OPS_COMPAT
1045 #endif /* 2.6.4 => 2.6.0 */
1047 /*****************************************************************************/
1048 /* 2.5.71 => 2.4.x */
1049 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,71) )
1050 #define sk_protocol protocol
1051 #define pci_get_device pci_find_device
1052 #endif /* 2.5.70 => 2.4.x */
1054 /*****************************************************************************/
1055 /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1056 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) || \
1057 ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
1058 LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) ) )
1060 #ifndef netif_msg_init
1061 #define netif_msg_init _kc_netif_msg_init
1062 static inline u32 _kc_netif_msg_init(int debug_value, int default_msg_enable_bits)
1065 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
1066 return default_msg_enable_bits;
1067 if (debug_value == 0) /* no output */
1069 /* set low N bits */
1070 return (1 << debug_value) -1;
1074 #endif /* < 2.4.27 or 2.6.0 <= 2.6.5 */
1075 /*****************************************************************************/
1076 #if (( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,27) ) || \
1077 (( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) ) && \
1078 ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3) )))
1079 #define netdev_priv(x) x->priv
1082 /*****************************************************************************/
1084 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) )
1085 #include <linux/rtnetlink.h>
1086 #undef pci_register_driver
1087 #define pci_register_driver pci_module_init
1090 * Most of the dma compat code is copied/modifed from the 2.4.37
1091 * /include/linux/libata-compat.h header file
1093 /* These definitions mirror those in pci.h, so they can be used
1094 * interchangeably with their PCI_ counterparts */
1095 enum dma_data_direction {
1096 DMA_BIDIRECTIONAL = 0,
1098 DMA_FROM_DEVICE = 2,
1103 struct pci_dev pdev;
1106 static inline struct pci_dev *to_pci_dev (struct device *dev)
1108 return (struct pci_dev *) dev;
1110 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1112 return (struct device *) pdev;
1115 #define pdev_printk(lvl, pdev, fmt, args...) \
1116 printk("%s %s: " fmt, lvl, pci_name(pdev), ## args)
1117 #define dev_err(dev, fmt, args...) \
1118 pdev_printk(KERN_ERR, to_pci_dev(dev), fmt, ## args)
1119 #define dev_info(dev, fmt, args...) \
1120 pdev_printk(KERN_INFO, to_pci_dev(dev), fmt, ## args)
1121 #define dev_warn(dev, fmt, args...) \
1122 pdev_printk(KERN_WARNING, to_pci_dev(dev), fmt, ## args)
1124 /* NOTE: dangerous! we ignore the 'gfp' argument */
1125 #define dma_alloc_coherent(dev,sz,dma,gfp) \
1126 pci_alloc_consistent(to_pci_dev(dev),(sz),(dma))
1127 #define dma_free_coherent(dev,sz,addr,dma_addr) \
1128 pci_free_consistent(to_pci_dev(dev),(sz),(addr),(dma_addr))
1130 #define dma_map_page(dev,a,b,c,d) \
1131 pci_map_page(to_pci_dev(dev),(a),(b),(c),(d))
1132 #define dma_unmap_page(dev,a,b,c) \
1133 pci_unmap_page(to_pci_dev(dev),(a),(b),(c))
1135 #define dma_map_single(dev,a,b,c) \
1136 pci_map_single(to_pci_dev(dev),(a),(b),(c))
1137 #define dma_unmap_single(dev,a,b,c) \
1138 pci_unmap_single(to_pci_dev(dev),(a),(b),(c))
1140 #define dma_sync_single(dev,a,b,c) \
1141 pci_dma_sync_single(to_pci_dev(dev),(a),(b),(c))
1143 /* for range just sync everything, that's all the pci API can do */
1144 #define dma_sync_single_range(dev,addr,off,sz,dir) \
1145 pci_dma_sync_single(to_pci_dev(dev),(addr),(off)+(sz),(dir))
1147 #define dma_set_mask(dev,mask) \
1148 pci_set_dma_mask(to_pci_dev(dev),(mask))
1150 /* hlist_* code - double linked lists */
1152 struct hlist_node *first;
1156 struct hlist_node *next, **pprev;
1159 static inline void __hlist_del(struct hlist_node *n)
1161 struct hlist_node *next = n->next;
1162 struct hlist_node **pprev = n->pprev;
1165 next->pprev = pprev;
1168 static inline void hlist_del(struct hlist_node *n)
1175 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
1177 struct hlist_node *first = h->first;
1180 first->pprev = &n->next;
1182 n->pprev = &h->first;
1185 static inline int hlist_empty(const struct hlist_head *h)
1189 #define HLIST_HEAD_INIT { .first = NULL }
1190 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
1191 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
1192 static inline void INIT_HLIST_NODE(struct hlist_node *h)
1197 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
1199 #define hlist_for_each_entry(tpos, pos, head, member) \
1200 for (pos = (head)->first; \
1201 pos && ({ prefetch(pos->next); 1;}) && \
1202 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1205 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
1206 for (pos = (head)->first; \
1207 pos && ({ n = pos->next; 1; }) && \
1208 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
1212 #define might_sleep()
1215 static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
1219 #endif /* <= 2.5.0 */
1221 /*****************************************************************************/
1222 /* 2.5.28 => 2.4.23 */
1223 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) )
1225 static inline void _kc_synchronize_irq(void)
1229 #undef synchronize_irq
1230 #define synchronize_irq(X) _kc_synchronize_irq()
1232 #include <linux/tqueue.h>
1233 #define work_struct tq_struct
1235 #define INIT_WORK(a,b) INIT_TQUEUE(a,(void (*)(void *))b,a)
1237 #define container_of list_entry
1238 #define schedule_work schedule_task
1239 #define flush_scheduled_work flush_scheduled_tasks
1240 #define cancel_work_sync(x) flush_scheduled_work()
1242 #endif /* 2.5.28 => 2.4.17 */
1244 /*****************************************************************************/
1245 /* 2.6.0 => 2.5.28 */
1246 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
1248 #define get_cpu() smp_processor_id()
1250 #define put_cpu() do { } while(0)
1251 #define MODULE_INFO(version, _version)
1252 #ifndef CONFIG_E1000_DISABLE_PACKET_SPLIT
1253 #define CONFIG_E1000_DISABLE_PACKET_SPLIT 1
1255 #ifndef CONFIG_IGB_DISABLE_PACKET_SPLIT
1256 #define CONFIG_IGB_DISABLE_PACKET_SPLIT 1
1259 #define dma_set_coherent_mask(dev,mask) 1
1262 #define dev_put(dev) __dev_put(dev)
1264 #ifndef skb_fill_page_desc
1265 #define skb_fill_page_desc _kc_skb_fill_page_desc
1266 extern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size);
1270 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
1273 #define page_count(p) atomic_read(&(p)->count)
1279 #define MAX_NUMNODES 1
1281 /* find_first_bit and find_next bit are not defined for most
1282 * 2.4 kernels (except for the redhat 2.4.21 kernels
1284 #include <linux/bitops.h>
1285 #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG)
1286 #undef find_next_bit
1287 #define find_next_bit _kc_find_next_bit
1288 extern unsigned long _kc_find_next_bit(const unsigned long *addr,
1290 unsigned long offset);
1291 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
1295 static inline const char *_kc_netdev_name(const struct net_device *dev)
1297 if (strchr(dev->name, '%'))
1298 return "(unregistered net_device)";
1301 #define netdev_name(netdev) _kc_netdev_name(netdev)
1302 #endif /* netdev_name */
1305 #define strlcpy _kc_strlcpy
1306 extern size_t _kc_strlcpy(char *dest, const char *src, size_t size);
1307 #endif /* strlcpy */
1309 #endif /* 2.6.0 => 2.5.28 */
1311 /*****************************************************************************/
1312 /* 2.6.4 => 2.6.0 */
1313 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1314 #define MODULE_VERSION(_version) MODULE_INFO(version, _version)
1315 #endif /* 2.6.4 => 2.6.0 */
1317 /*****************************************************************************/
1318 /* 2.6.5 => 2.6.0 */
1319 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) )
1320 #define dma_sync_single_for_cpu dma_sync_single
1321 #define dma_sync_single_for_device dma_sync_single
1322 #define dma_sync_single_range_for_cpu dma_sync_single_range
1323 #define dma_sync_single_range_for_device dma_sync_single_range
1324 #ifndef pci_dma_mapping_error
1325 #define pci_dma_mapping_error _kc_pci_dma_mapping_error
1326 static inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr)
1328 return dma_addr == 0;
1331 #endif /* 2.6.5 => 2.6.0 */
1333 /*****************************************************************************/
1334 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
1335 extern int _kc_scnprintf(char * buf, size_t size, const char *fmt, ...);
1336 #define scnprintf(buf, size, fmt, args...) _kc_scnprintf(buf, size, fmt, ##args)
1337 #endif /* < 2.6.4 */
1339 /*****************************************************************************/
1340 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,6) )
1341 /* taken from 2.6 include/linux/bitmap.h */
1343 #define bitmap_zero _kc_bitmap_zero
1344 static inline void _kc_bitmap_zero(unsigned long *dst, int nbits)
1346 if (nbits <= BITS_PER_LONG)
1349 int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
1350 memset(dst, 0, len);
1353 #define random_ether_addr _kc_random_ether_addr
1354 static inline void _kc_random_ether_addr(u8 *addr)
1356 get_random_bytes(addr, ETH_ALEN);
1357 addr[0] &= 0xfe; /* clear multicast */
1358 addr[0] |= 0x02; /* set local assignment */
1360 #define page_to_nid(x) 0
1362 #endif /* < 2.6.6 */
1364 /*****************************************************************************/
1365 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7) )
1367 #define if_mii _kc_if_mii
1368 static inline struct mii_ioctl_data *_kc_if_mii(struct ifreq *rq)
1370 return (struct mii_ioctl_data *) &rq->ifr_ifru;
1376 #endif /* < 2.6.7 */
1378 /*****************************************************************************/
1379 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) )
1380 #ifndef PCI_EXP_DEVCTL
1381 #define PCI_EXP_DEVCTL 8
1383 #ifndef PCI_EXP_DEVCTL_CERE
1384 #define PCI_EXP_DEVCTL_CERE 0x0001
1386 #define msleep(x) do { set_current_state(TASK_UNINTERRUPTIBLE); \
1387 schedule_timeout((x * HZ)/1000 + 2); \
1390 #endif /* < 2.6.8 */
1392 /*****************************************************************************/
1393 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
1394 #include <net/dsfield.h>
1398 #define kcalloc(n, size, flags) _kc_kzalloc(((n) * (size)), flags)
1399 extern void *_kc_kzalloc(size_t size, int flags);
1401 #define MSEC_PER_SEC 1000L
1402 static inline unsigned int _kc_jiffies_to_msecs(const unsigned long j)
1404 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1405 return (MSEC_PER_SEC / HZ) * j;
1406 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1407 return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
1409 return (j * MSEC_PER_SEC) / HZ;
1412 static inline unsigned long _kc_msecs_to_jiffies(const unsigned int m)
1414 if (m > _kc_jiffies_to_msecs(MAX_JIFFY_OFFSET))
1415 return MAX_JIFFY_OFFSET;
1416 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
1417 return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
1418 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
1419 return m * (HZ / MSEC_PER_SEC);
1421 return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
1425 #define msleep_interruptible _kc_msleep_interruptible
1426 static inline unsigned long _kc_msleep_interruptible(unsigned int msecs)
1428 unsigned long timeout = _kc_msecs_to_jiffies(msecs) + 1;
1430 while (timeout && !signal_pending(current)) {
1431 __set_current_state(TASK_INTERRUPTIBLE);
1432 timeout = schedule_timeout(timeout);
1434 return _kc_jiffies_to_msecs(timeout);
1437 /* Basic mode control register. */
1438 #define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */
1459 static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
1461 return (struct vlan_ethhdr *)skb->mac.raw;
1464 /* Wake-On-Lan options. */
1465 #define WAKE_PHY (1 << 0)
1466 #define WAKE_UCAST (1 << 1)
1467 #define WAKE_MCAST (1 << 2)
1468 #define WAKE_BCAST (1 << 3)
1469 #define WAKE_ARP (1 << 4)
1470 #define WAKE_MAGIC (1 << 5)
1471 #define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
1473 #define skb_header_pointer _kc_skb_header_pointer
1474 static inline void *_kc_skb_header_pointer(const struct sk_buff *skb,
1475 int offset, int len, void *buffer)
1477 int hlen = skb_headlen(skb);
1479 if (hlen - offset >= len)
1480 return skb->data + offset;
1482 #ifdef MAX_SKB_FRAGS
1483 if (skb_copy_bits(skb, offset, buffer, len) < 0)
1491 #ifndef NETDEV_TX_OK
1492 #define NETDEV_TX_OK 0
1494 #ifndef NETDEV_TX_BUSY
1495 #define NETDEV_TX_BUSY 1
1497 #ifndef NETDEV_TX_LOCKED
1498 #define NETDEV_TX_LOCKED -1
1505 #endif /* < 2.6.9 */
1507 /*****************************************************************************/
1508 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) )
1509 #ifdef module_param_array_named
1510 #undef module_param_array_named
1511 #define module_param_array_named(name, array, type, nump, perm) \
1512 static struct kparam_array __param_arr_##name \
1513 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type, \
1514 sizeof(array[0]), array }; \
1515 module_param_call(name, param_array_set, param_array_get, \
1516 &__param_arr_##name, perm)
1517 #endif /* module_param_array_named */
1519 * num_online is broken for all < 2.6.10 kernels. This is needed to support
1520 * Node module parameter of ixgbe.
1522 #undef num_online_nodes
1523 #define num_online_nodes(n) 1
1524 extern DECLARE_BITMAP(_kcompat_node_online_map, MAX_NUMNODES);
1525 #undef node_online_map
1526 #define node_online_map _kcompat_node_online_map
1527 #endif /* < 2.6.10 */
1529 /*****************************************************************************/
1530 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) )
1535 #define PCI_D3cold 4
1536 typedef int pci_power_t;
1537 #define pci_choose_state(pdev,state) state
1538 #define PMSG_SUSPEND 3
1539 #define PCI_EXP_LNKCTL 16
1543 #ifndef ARCH_HAS_PREFETCH
1547 #ifndef NET_IP_ALIGN
1548 #define NET_IP_ALIGN 2
1551 #define KC_USEC_PER_SEC 1000000L
1552 #define usecs_to_jiffies _kc_usecs_to_jiffies
1553 static inline unsigned int _kc_jiffies_to_usecs(const unsigned long j)
1555 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1556 return (KC_USEC_PER_SEC / HZ) * j;
1557 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1558 return (j + (HZ / KC_USEC_PER_SEC) - 1)/(HZ / KC_USEC_PER_SEC);
1560 return (j * KC_USEC_PER_SEC) / HZ;
1563 static inline unsigned long _kc_usecs_to_jiffies(const unsigned int m)
1565 if (m > _kc_jiffies_to_usecs(MAX_JIFFY_OFFSET))
1566 return MAX_JIFFY_OFFSET;
1567 #if HZ <= KC_USEC_PER_SEC && !(KC_USEC_PER_SEC % HZ)
1568 return (m + (KC_USEC_PER_SEC / HZ) - 1) / (KC_USEC_PER_SEC / HZ);
1569 #elif HZ > KC_USEC_PER_SEC && !(HZ % KC_USEC_PER_SEC)
1570 return m * (HZ / KC_USEC_PER_SEC);
1572 return (m * HZ + KC_USEC_PER_SEC - 1) / KC_USEC_PER_SEC;
1575 #endif /* < 2.6.11 */
1577 /*****************************************************************************/
1578 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) )
1579 #include <linux/reboot.h>
1580 #define USE_REBOOT_NOTIFIER
1582 /* Generic MII registers. */
1583 #define MII_CTRL1000 0x09 /* 1000BASE-T control */
1584 #define MII_STAT1000 0x0a /* 1000BASE-T status */
1585 /* Advertisement control register. */
1586 #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */
1587 #define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymmetric pause */
1588 /* 1000BASE-T Control register */
1589 #define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */
1590 #ifndef is_zero_ether_addr
1591 #define is_zero_ether_addr _kc_is_zero_ether_addr
1592 static inline int _kc_is_zero_ether_addr(const u8 *addr)
1594 return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]);
1596 #endif /* is_zero_ether_addr */
1597 #ifndef is_multicast_ether_addr
1598 #define is_multicast_ether_addr _kc_is_multicast_ether_addr
1599 static inline int _kc_is_multicast_ether_addr(const u8 *addr)
1601 return addr[0] & 0x01;
1603 #endif /* is_multicast_ether_addr */
1604 #endif /* < 2.6.12 */
1606 /*****************************************************************************/
1607 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) )
1609 #define kstrdup _kc_kstrdup
1610 extern char *_kc_kstrdup(const char *s, unsigned int gfp);
1612 #endif /* < 2.6.13 */
1614 /*****************************************************************************/
1615 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) )
1616 #define pm_message_t u32
1618 #define kzalloc _kc_kzalloc
1619 extern void *_kc_kzalloc(size_t size, int flags);
1622 /* Generic MII registers. */
1623 #define MII_ESTATUS 0x0f /* Extended Status */
1624 /* Basic mode status register. */
1625 #define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */
1626 /* Extended status register. */
1627 #define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */
1628 #define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */
1630 #define ADVERTISED_Pause (1 << 13)
1631 #define ADVERTISED_Asym_Pause (1 << 14)
1633 #if (!(RHEL_RELEASE_CODE && \
1634 (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,3)) && \
1635 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))))
1636 #if ((LINUX_VERSION_CODE == KERNEL_VERSION(2,6,9)) && !defined(gfp_t))
1637 #define gfp_t unsigned
1639 typedef unsigned gfp_t;
1641 #endif /* !RHEL4.3->RHEL5.0 */
1643 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9) )
1644 #ifdef CONFIG_X86_64
1645 #define dma_sync_single_range_for_cpu(dev, dma_handle, offset, size, dir) \
1646 dma_sync_single_for_cpu(dev, dma_handle, size, dir)
1647 #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir) \
1648 dma_sync_single_for_device(dev, dma_handle, size, dir)
1651 #endif /* < 2.6.14 */
1653 /*****************************************************************************/
1654 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) )
1655 #ifndef vmalloc_node
1656 #define vmalloc_node(a,b) vmalloc(a)
1657 #endif /* vmalloc_node*/
1659 #define setup_timer(_timer, _function, _data) \
1661 (_timer)->function = _function; \
1662 (_timer)->data = _data; \
1663 init_timer(_timer); \
1665 #ifndef device_can_wakeup
1666 #define device_can_wakeup(dev) (1)
1668 #ifndef device_set_wakeup_enable
1669 #define device_set_wakeup_enable(dev, val) do{}while(0)
1671 #ifndef device_init_wakeup
1672 #define device_init_wakeup(dev,val) do {} while (0)
1674 static inline unsigned _kc_compare_ether_addr(const u8 *addr1, const u8 *addr2)
1676 const u16 *a = (const u16 *) addr1;
1677 const u16 *b = (const u16 *) addr2;
1679 return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2])) != 0;
1681 #undef compare_ether_addr
1682 #define compare_ether_addr(addr1, addr2) _kc_compare_ether_addr(addr1, addr2)
1683 #endif /* < 2.6.15 */
1685 /*****************************************************************************/
1686 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16) )
1688 #define DEFINE_MUTEX(x) DECLARE_MUTEX(x)
1689 #define mutex_lock(x) down_interruptible(x)
1690 #define mutex_unlock(x) up(x)
1692 #ifndef ____cacheline_internodealigned_in_smp
1694 #define ____cacheline_internodealigned_in_smp ____cacheline_aligned_in_smp
1696 #define ____cacheline_internodealigned_in_smp
1697 #endif /* CONFIG_SMP */
1698 #endif /* ____cacheline_internodealigned_in_smp */
1700 #else /* 2.6.16 and above */
1702 #define HAVE_PCI_ERS
1703 #endif /* < 2.6.16 */
1705 /*****************************************************************************/
1706 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) )
1707 #ifndef first_online_node
1708 #define first_online_node 0
1711 #define NET_SKB_PAD 16
1713 #endif /* < 2.6.17 */
1715 /*****************************************************************************/
1716 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) )
1719 #define irqreturn_t void
1724 #ifndef IRQF_PROBE_SHARED
1726 #define IRQF_PROBE_SHARED SA_PROBEIRQ
1728 #define IRQF_PROBE_SHARED 0
1733 #define IRQF_SHARED SA_SHIRQ
1737 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
1740 #ifndef FIELD_SIZEOF
1741 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
1746 #define skb_is_gso _kc_skb_is_gso
1747 static inline int _kc_skb_is_gso(const struct sk_buff *skb)
1749 return skb_shinfo(skb)->gso_size;
1752 #define skb_is_gso(a) 0
1756 #ifndef resource_size_t
1757 #define resource_size_t unsigned long
1763 #define skb_pad(x,y) _kc_skb_pad(x, y)
1764 int _kc_skb_pad(struct sk_buff *skb, int pad);
1768 #define skb_padto(x,y) _kc_skb_padto(x, y)
1769 static inline int _kc_skb_padto(struct sk_buff *skb, unsigned int len)
1771 unsigned int size = skb->len;
1772 if(likely(size >= len))
1774 return _kc_skb_pad(skb, len - size);
1777 #ifndef DECLARE_PCI_UNMAP_ADDR
1778 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
1779 dma_addr_t ADDR_NAME
1780 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
1782 #define pci_unmap_addr(PTR, ADDR_NAME) \
1784 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
1785 (((PTR)->ADDR_NAME) = (VAL))
1786 #define pci_unmap_len(PTR, LEN_NAME) \
1788 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
1789 (((PTR)->LEN_NAME) = (VAL))
1790 #endif /* DECLARE_PCI_UNMAP_ADDR */
1791 #endif /* < 2.6.18 */
1793 /*****************************************************************************/
1794 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) )
1796 #ifndef DIV_ROUND_UP
1797 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
1799 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) )
1800 #if (!((RHEL_RELEASE_CODE && \
1801 ((RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(4,4) && \
1802 RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0)) || \
1803 (RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,0)))) || \
1804 (AX_RELEASE_CODE && AX_RELEASE_CODE > AX_RELEASE_VERSION(3,0))))
1805 typedef irqreturn_t (*irq_handler_t)(int, void*, struct pt_regs *);
1807 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
1808 #undef CONFIG_INET_LRO
1809 #undef CONFIG_INET_LRO_MODULE
1812 #undef CONFIG_FCOE_MODULE
1813 #endif /* IXGBE_FCOE */
1815 typedef irqreturn_t (*new_handler_t)(int, void*);
1816 static inline irqreturn_t _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1818 typedef void (*irq_handler_t)(int, void*, struct pt_regs *);
1819 typedef void (*new_handler_t)(int, void*);
1820 static inline int _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id)
1821 #endif /* >= 2.5.x */
1823 irq_handler_t new_handler = (irq_handler_t) handler;
1824 return request_irq(irq, new_handler, flags, devname, dev_id);
1828 #define request_irq(irq, handler, flags, devname, dev_id) _kc_request_irq((irq), (handler), (flags), (devname), (dev_id))
1830 #define irq_handler_t new_handler_t
1831 /* pci_restore_state and pci_save_state handles MSI/PCIE from 2.6.19 */
1832 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))
1833 #define PCIE_CONFIG_SPACE_LEN 256
1834 #define PCI_CONFIG_SPACE_LEN 64
1835 #define PCIE_LINK_STATUS 0x12
1836 #define pci_config_space_ich8lan() do {} while(0)
1837 #undef pci_save_state
1838 extern int _kc_pci_save_state(struct pci_dev *);
1839 #define pci_save_state(pdev) _kc_pci_save_state(pdev)
1840 #undef pci_restore_state
1841 extern void _kc_pci_restore_state(struct pci_dev *);
1842 #define pci_restore_state(pdev) _kc_pci_restore_state(pdev)
1843 #endif /* !(RHEL_RELEASE_CODE >= RHEL 5.4) */
1847 extern void _kc_free_netdev(struct net_device *);
1848 #define free_netdev(netdev) _kc_free_netdev(netdev)
1850 static inline int pci_enable_pcie_error_reporting(struct pci_dev *dev)
1854 #define pci_disable_pcie_error_reporting(dev) do {} while (0)
1855 #define pci_cleanup_aer_uncorrect_error_status(dev) do {} while (0)
1857 extern void *_kc_kmemdup(const void *src, size_t len, unsigned gfp);
1858 #define kmemdup(src, len, gfp) _kc_kmemdup(src, len, gfp)
1865 #include <linux/aer.h>
1866 #include <linux/string.h>
1867 #endif /* < 2.6.19 */
1869 /*****************************************************************************/
1870 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) )
1871 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,28) )
1873 #define INIT_WORK(_work, _func) \
1875 INIT_LIST_HEAD(&(_work)->entry); \
1876 (_work)->pending = 0; \
1877 (_work)->func = (void (*)(void *))_func; \
1878 (_work)->data = _work; \
1879 init_timer(&(_work)->timer); \
1884 #define PCI_VDEVICE(ven, dev) \
1885 PCI_VENDOR_ID_##ven, (dev), \
1886 PCI_ANY_ID, PCI_ANY_ID, 0, 0
1889 #ifndef round_jiffies
1890 #define round_jiffies(x) x
1893 #define csum_offset csum
1895 #define HAVE_EARLY_VMALLOC_NODE
1896 #define dev_to_node(dev) -1
1898 /* remove compiler warning with b=b, for unused variable */
1899 #define set_dev_node(a, b) do { (b) = (b); } while(0)
1901 #if (!(RHEL_RELEASE_CODE && \
1902 (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1903 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1904 (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,6)))) && \
1905 !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1906 typedef __u16 __bitwise __sum16;
1907 typedef __u32 __bitwise __wsum;
1910 #if (!(RHEL_RELEASE_CODE && \
1911 (((RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(4,7)) && \
1912 (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(5,0))) || \
1913 (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))) && \
1914 !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(10,2,0)))
1915 static inline __wsum csum_unfold(__sum16 n)
1917 return (__force __wsum)n;
1921 #else /* < 2.6.20 */
1922 #define HAVE_DEVICE_NUMA_NODE
1923 #endif /* < 2.6.20 */
1925 /*****************************************************************************/
1926 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
1927 #define to_net_dev(class) container_of(class, struct net_device, class_dev)
1928 #define NETDEV_CLASS_DEV
1929 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)))
1930 #define vlan_group_get_device(vg, id) (vg->vlan_devices[id])
1931 #define vlan_group_set_device(vg, id, dev) \
1933 if (vg) vg->vlan_devices[id] = dev; \
1935 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,5)) */
1936 #define pci_channel_offline(pdev) (pdev->error_state && \
1937 pdev->error_state != pci_channel_io_normal)
1938 #define pci_request_selected_regions(pdev, bars, name) \
1939 pci_request_regions(pdev, name)
1940 #define pci_release_selected_regions(pdev, bars) pci_release_regions(pdev);
1941 #endif /* < 2.6.21 */
1943 /*****************************************************************************/
1944 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
1945 #define tcp_hdr(skb) (skb->h.th)
1946 #define tcp_hdrlen(skb) (skb->h.th->doff << 2)
1947 #define skb_transport_offset(skb) (skb->h.raw - skb->data)
1948 #define skb_transport_header(skb) (skb->h.raw)
1949 #define ipv6_hdr(skb) (skb->nh.ipv6h)
1950 #define ip_hdr(skb) (skb->nh.iph)
1951 #define skb_network_offset(skb) (skb->nh.raw - skb->data)
1952 #define skb_network_header(skb) (skb->nh.raw)
1953 #define skb_tail_pointer(skb) skb->tail
1954 #define skb_reset_tail_pointer(skb) \
1956 skb->tail = skb->data; \
1958 #define skb_copy_to_linear_data(skb, from, len) \
1959 memcpy(skb->data, from, len)
1960 #define skb_copy_to_linear_data_offset(skb, offset, from, len) \
1961 memcpy(skb->data + offset, from, len)
1962 #define skb_network_header_len(skb) (skb->h.raw - skb->nh.raw)
1963 #define pci_register_driver pci_module_init
1964 #define skb_mac_header(skb) skb->mac.raw
1966 #ifdef NETIF_F_MULTI_QUEUE
1967 #ifndef alloc_etherdev_mq
1968 #define alloc_etherdev_mq(_a, _b) alloc_etherdev(_a)
1970 #endif /* NETIF_F_MULTI_QUEUE */
1973 #define ETH_FCS_LEN 4
1975 #define cancel_work_sync(x) flush_scheduled_work()
1977 #define udp_hdr _udp_hdr
1978 static inline struct udphdr *_udp_hdr(const struct sk_buff *skb)
1980 return (struct udphdr *)skb_transport_header(skb);
1987 #define cpu_to_be16(x) __constant_htons(x)
1989 #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)))
1992 DUMP_PREFIX_ADDRESS,
1995 #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(5,1)) */
1997 #define hex_asc(x) "0123456789abcdef"[x]
1999 #include <linux/ctype.h>
2000 extern void _kc_print_hex_dump(const char *level, const char *prefix_str,
2001 int prefix_type, int rowsize, int groupsize,
2002 const void *buf, size_t len, bool ascii);
2003 #define print_hex_dump(lvl, s, t, r, g, b, l, a) \
2004 _kc_print_hex_dump(lvl, s, t, r, g, b, l, a)
2006 #define ETH_TYPE_TRANS_SETS_DEV
2007 #define HAVE_NETDEV_STATS_IN_NETDEV
2008 #endif /* < 2.6.22 */
2010 /*****************************************************************************/
2011 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22) )
2012 #undef SET_MODULE_OWNER
2013 #define SET_MODULE_OWNER(dev) do { } while (0)
2014 #endif /* > 2.6.22 */
2016 /*****************************************************************************/
2017 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) )
2018 #define netif_subqueue_stopped(_a, _b) 0
2020 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
2023 #ifndef CONFIG_PM_SLEEP
2024 #define CONFIG_PM_SLEEP CONFIG_PM
2027 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13) )
2028 #define HAVE_ETHTOOL_GET_PERM_ADDR
2029 #endif /* 2.6.14 through 2.6.22 */
2030 #endif /* < 2.6.23 */
2032 /*****************************************************************************/
2033 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
2034 #ifndef ETH_FLAG_LRO
2035 #define ETH_FLAG_LRO NETIF_F_LRO
2038 /* if GRO is supported then the napi struct must already exist */
2040 /* NAPI API changes in 2.6.24 break everything */
2041 struct napi_struct {
2042 /* used to look up the real NAPI polling routine */
2043 int (*poll)(struct napi_struct *, int);
2044 struct net_device *dev;
2050 extern int __kc_adapter_clean(struct net_device *, int *);
2051 extern struct net_device *napi_to_poll_dev(struct napi_struct *napi);
2052 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2054 struct napi_struct *__napi = (_napi); \
2055 struct net_device *poll_dev = napi_to_poll_dev(__napi); \
2056 poll_dev->poll = &(__kc_adapter_clean); \
2057 poll_dev->priv = (_napi); \
2058 poll_dev->weight = (_weight); \
2059 set_bit(__LINK_STATE_RX_SCHED, &poll_dev->state); \
2060 set_bit(__LINK_STATE_START, &poll_dev->state);\
2061 dev_hold(poll_dev); \
2062 __napi->poll = &(_poll); \
2063 __napi->weight = (_weight); \
2064 __napi->dev = (_netdev); \
2066 #define netif_napi_del(_napi) \
2068 struct net_device *poll_dev = napi_to_poll_dev(_napi); \
2069 WARN_ON(!test_bit(__LINK_STATE_RX_SCHED, &poll_dev->state)); \
2070 dev_put(poll_dev); \
2071 memset(poll_dev, 0, sizeof(struct net_device));\
2073 #define napi_schedule_prep(_napi) \
2074 (netif_running((_napi)->dev) && netif_rx_schedule_prep(napi_to_poll_dev(_napi)))
2075 #define napi_schedule(_napi) \
2077 if (napi_schedule_prep(_napi)) \
2078 __netif_rx_schedule(napi_to_poll_dev(_napi)); \
2080 #define napi_enable(_napi) netif_poll_enable(napi_to_poll_dev(_napi))
2081 #define napi_disable(_napi) netif_poll_disable(napi_to_poll_dev(_napi))
2082 #define __napi_schedule(_napi) __netif_rx_schedule(napi_to_poll_dev(_napi))
2084 #define napi_complete(_napi) netif_rx_complete(napi_to_poll_dev(_napi))
2086 #define napi_complete(_napi) \
2088 napi_gro_flush(_napi); \
2089 netif_rx_complete(napi_to_poll_dev(_napi)); \
2091 #endif /* NETIF_F_GRO */
2093 #define netif_napi_add(_netdev, _napi, _poll, _weight) \
2095 struct napi_struct *__napi = _napi; \
2096 _netdev->poll = &(_poll); \
2097 _netdev->weight = (_weight); \
2098 __napi->poll = &(_poll); \
2099 __napi->weight = (_weight); \
2100 __napi->dev = (_netdev); \
2102 #define netif_napi_del(_a) do {} while (0)
2105 #undef dev_get_by_name
2106 #define dev_get_by_name(_a, _b) dev_get_by_name(_b)
2107 #define __netif_subqueue_stopped(_a, _b) netif_subqueue_stopped(_a, _b)
2108 #ifndef DMA_BIT_MASK
2109 #define DMA_BIT_MASK(n) (((n) == 64) ? DMA_64BIT_MASK : ((1ULL<<(n))-1))
2113 #define skb_is_gso_v6 _kc_skb_is_gso_v6
2114 static inline int _kc_skb_is_gso_v6(const struct sk_buff *skb)
2116 return skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6;
2118 #endif /* NETIF_F_TSO6 */
2121 #define KERN_CONT ""
2123 #else /* < 2.6.24 */
2124 #define HAVE_ETHTOOL_GET_SSET_COUNT
2125 #define HAVE_NETDEV_NAPI_LIST
2126 #endif /* < 2.6.24 */
2128 /*****************************************************************************/
2129 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24) )
2130 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2131 #include <linux/pm_qos_params.h>
2132 #else /* >= 3.2.0 */
2133 #include <linux/pm_qos.h>
2134 #endif /* else >= 3.2.0 */
2135 #endif /* > 2.6.24 */
2137 /*****************************************************************************/
2138 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) )
2139 #define PM_QOS_CPU_DMA_LATENCY 1
2141 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18) )
2142 #include <linux/latency.h>
2143 #define PM_QOS_DEFAULT_VALUE INFINITE_LATENCY
2144 #define pm_qos_add_requirement(pm_qos_class, name, value) \
2145 set_acceptable_latency(name, value)
2146 #define pm_qos_remove_requirement(pm_qos_class, name) \
2147 remove_acceptable_latency(name)
2148 #define pm_qos_update_requirement(pm_qos_class, name, value) \
2149 modify_acceptable_latency(name, value)
2151 #define PM_QOS_DEFAULT_VALUE -1
2152 #define pm_qos_add_requirement(pm_qos_class, name, value)
2153 #define pm_qos_remove_requirement(pm_qos_class, name)
2154 #define pm_qos_update_requirement(pm_qos_class, name, value) { \
2155 if (value != PM_QOS_DEFAULT_VALUE) { \
2156 printk(KERN_WARNING "%s: unable to set PM QoS requirement\n", \
2157 pci_name(adapter->pdev)); \
2161 #endif /* > 2.6.18 */
2163 #define pci_enable_device_mem(pdev) pci_enable_device(pdev)
2165 #ifndef DEFINE_PCI_DEVICE_TABLE
2166 #define DEFINE_PCI_DEVICE_TABLE(_table) struct pci_device_id _table[]
2167 #endif /* DEFINE_PCI_DEVICE_TABLE */
2172 #endif /* IGB_PROCFS */
2174 #else /* < 2.6.25 */
2179 #endif /* IGB_SYSFS */
2181 #endif /* < 2.6.25 */
2183 /*****************************************************************************/
2184 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) )
2186 #define clamp_t(type, val, min, max) ({ \
2187 type __val = (val); \
2188 type __min = (min); \
2189 type __max = (max); \
2190 __val = __val < __min ? __min : __val; \
2191 __val > __max ? __max : __val; })
2192 #endif /* clamp_t */
2194 #define kzalloc_node(_size, _flags, _node) kzalloc(_size, _flags)
2196 extern void _kc_pci_disable_link_state(struct pci_dev *dev, int state);
2197 #define pci_disable_link_state(p, s) _kc_pci_disable_link_state(p, s)
2198 #else /* < 2.6.26 */
2199 #include <linux/pci-aspm.h>
2200 #define HAVE_NETDEV_VLAN_FEATURES
2201 #endif /* < 2.6.26 */
2202 /*****************************************************************************/
2203 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) )
2204 static inline void _kc_ethtool_cmd_speed_set(struct ethtool_cmd *ep,
2207 ep->speed = (__u16)speed;
2208 /* ep->speed_hi = (__u16)(speed >> 16); */
2210 #define ethtool_cmd_speed_set _kc_ethtool_cmd_speed_set
2212 static inline __u32 _kc_ethtool_cmd_speed(struct ethtool_cmd *ep)
2214 /* no speed_hi before 2.6.27, and probably no need for it yet */
2215 return (__u32)ep->speed;
2217 #define ethtool_cmd_speed _kc_ethtool_cmd_speed
2219 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15) )
2220 #if ((LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)) && defined(CONFIG_PM))
2221 #define ANCIENT_PM 1
2222 #elif ((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) && \
2223 (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)) && \
2224 defined(CONFIG_PM_SLEEP))
2227 #if defined(ANCIENT_PM) || defined(NEWER_PM)
2228 #undef device_set_wakeup_enable
2229 #define device_set_wakeup_enable(dev, val) \
2232 int pm = pci_find_capability(adapter->pdev, PCI_CAP_ID_PM); \
2234 pci_read_config_word(adapter->pdev, pm + PCI_PM_PMC, \
2237 (dev)->power.can_wakeup = !!(pmc >> 11); \
2238 (dev)->power.should_wakeup = (val && (pmc >> 11)); \
2240 #endif /* 2.6.15-2.6.22 and CONFIG_PM or 2.6.23-2.6.25 and CONFIG_PM_SLEEP */
2241 #endif /* 2.6.15 through 2.6.27 */
2242 #ifndef netif_napi_del
2243 #define netif_napi_del(_a) do {} while (0)
2245 #ifdef CONFIG_NETPOLL
2246 #undef netif_napi_del
2247 #define netif_napi_del(_a) list_del(&(_a)->dev_list);
2250 #endif /* netif_napi_del */
2251 #ifdef dma_mapping_error
2252 #undef dma_mapping_error
2254 #define dma_mapping_error(dev, dma_addr) pci_dma_mapping_error(dma_addr)
2256 #ifdef CONFIG_NETDEVICES_MULTIQUEUE
2261 extern void _kc_netif_tx_stop_all_queues(struct net_device *);
2262 extern void _kc_netif_tx_wake_all_queues(struct net_device *);
2263 extern void _kc_netif_tx_start_all_queues(struct net_device *);
2264 #define netif_tx_stop_all_queues(a) _kc_netif_tx_stop_all_queues(a)
2265 #define netif_tx_wake_all_queues(a) _kc_netif_tx_wake_all_queues(a)
2266 #define netif_tx_start_all_queues(a) _kc_netif_tx_start_all_queues(a)
2267 #undef netif_stop_subqueue
2268 #define netif_stop_subqueue(_ndev,_qi) do { \
2269 if (netif_is_multiqueue((_ndev))) \
2270 netif_stop_subqueue((_ndev), (_qi)); \
2272 netif_stop_queue((_ndev)); \
2274 #undef netif_start_subqueue
2275 #define netif_start_subqueue(_ndev,_qi) do { \
2276 if (netif_is_multiqueue((_ndev))) \
2277 netif_start_subqueue((_ndev), (_qi)); \
2279 netif_start_queue((_ndev)); \
2281 #else /* HAVE_TX_MQ */
2282 #define netif_tx_stop_all_queues(a) netif_stop_queue(a)
2283 #define netif_tx_wake_all_queues(a) netif_wake_queue(a)
2284 #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12) )
2285 #define netif_tx_start_all_queues(a) netif_start_queue(a)
2287 #define netif_tx_start_all_queues(a) do {} while (0)
2289 #define netif_stop_subqueue(_ndev,_qi) netif_stop_queue((_ndev))
2290 #define netif_start_subqueue(_ndev,_qi) netif_start_queue((_ndev))
2291 #endif /* HAVE_TX_MQ */
2292 #ifndef NETIF_F_MULTI_QUEUE
2293 #define NETIF_F_MULTI_QUEUE 0
2294 #define netif_is_multiqueue(a) 0
2295 #define netif_wake_subqueue(a, b)
2296 #endif /* NETIF_F_MULTI_QUEUE */
2298 #ifndef __WARN_printf
2299 extern void __kc_warn_slowpath(const char *file, const int line,
2300 const char *fmt, ...) __attribute__((format(printf, 3, 4)));
2301 #define __WARN_printf(arg...) __kc_warn_slowpath(__FILE__, __LINE__, arg)
2302 #endif /* __WARN_printf */
2305 #define WARN(condition, format...) ({ \
2306 int __ret_warn_on = !!(condition); \
2307 if (unlikely(__ret_warn_on)) \
2308 __WARN_printf(format); \
2309 unlikely(__ret_warn_on); \
2312 #else /* < 2.6.27 */
2314 #define HAVE_NETDEV_SELECT_QUEUE
2315 #endif /* < 2.6.27 */
2317 /*****************************************************************************/
2318 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) )
2319 #define pci_ioremap_bar(pdev, bar) ioremap(pci_resource_start(pdev, bar), \
2320 pci_resource_len(pdev, bar))
2321 #define pci_wake_from_d3 _kc_pci_wake_from_d3
2322 #define pci_prepare_to_sleep _kc_pci_prepare_to_sleep
2323 extern int _kc_pci_wake_from_d3(struct pci_dev *dev, bool enable);
2324 extern int _kc_pci_prepare_to_sleep(struct pci_dev *dev);
2325 #define netdev_alloc_page(a) alloc_page(GFP_ATOMIC)
2326 #ifndef __skb_queue_head_init
2327 static inline void __kc_skb_queue_head_init(struct sk_buff_head *list)
2329 list->prev = list->next = (struct sk_buff *)list;
2332 #define __skb_queue_head_init(_q) __kc_skb_queue_head_init(_q)
2334 #ifndef skb_add_rx_frag
2335 #define skb_add_rx_frag _kc_skb_add_rx_frag
2336 extern void _kc_skb_add_rx_frag(struct sk_buff *, int, struct page *, int, int);
2338 #endif /* < 2.6.28 */
2340 /*****************************************************************************/
2341 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) )
2343 #define swap(a, b) \
2344 do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
2346 #define pci_request_selected_regions_exclusive(pdev, bars, name) \
2347 pci_request_selected_regions(pdev, bars, name)
2348 #ifndef CONFIG_NR_CPUS
2349 #define CONFIG_NR_CPUS 1
2350 #endif /* CONFIG_NR_CPUS */
2351 #ifndef pcie_aspm_enabled
2352 #define pcie_aspm_enabled() (1)
2353 #endif /* pcie_aspm_enabled */
2354 #else /* < 2.6.29 */
2355 #ifndef HAVE_NET_DEVICE_OPS
2356 #define HAVE_NET_DEVICE_OPS
2359 #define HAVE_PFC_MODE_ENABLE
2360 #endif /* CONFIG_DCB */
2361 #endif /* < 2.6.29 */
2363 /*****************************************************************************/
2364 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) )
2365 #define skb_rx_queue_recorded(a) false
2366 #define skb_get_rx_queue(a) 0
2367 #define skb_record_rx_queue(a, b) do {} while (0)
2368 #define skb_tx_hash(n, s) ___kc_skb_tx_hash((n), (s), (n)->real_num_tx_queues)
2371 #undef CONFIG_FCOE_MODULE
2372 #endif /* IXGBE_FCOE */
2373 #ifndef CONFIG_PCI_IOV
2374 #undef pci_enable_sriov
2375 #define pci_enable_sriov(a, b) -ENOTSUPP
2376 #undef pci_disable_sriov
2377 #define pci_disable_sriov(a) do {} while (0)
2378 #endif /* CONFIG_PCI_IOV */
2380 #define pr_cont(fmt, ...) \
2381 printk(KERN_CONT fmt, ##__VA_ARGS__)
2382 #endif /* pr_cont */
2384 #define HAVE_ASPM_QUIRKS
2385 #endif /* < 2.6.30 */
2387 /*****************************************************************************/
2388 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) )
2389 #define ETH_P_1588 0x88F7
2390 #define ETH_P_FIP 0x8914
2391 #ifndef netdev_uc_count
2392 #define netdev_uc_count(dev) ((dev)->uc_count)
2394 #ifndef netdev_for_each_uc_addr
2395 #define netdev_for_each_uc_addr(uclist, dev) \
2396 for (uclist = dev->uc_list; uclist; uclist = uclist->next)
2399 #ifndef HAVE_NETDEV_STORAGE_ADDRESS
2400 #define HAVE_NETDEV_STORAGE_ADDRESS
2402 #ifndef HAVE_NETDEV_HW_ADDR
2403 #define HAVE_NETDEV_HW_ADDR
2405 #ifndef HAVE_TRANS_START_IN_QUEUE
2406 #define HAVE_TRANS_START_IN_QUEUE
2408 #endif /* < 2.6.31 */
2410 /*****************************************************************************/
2411 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) )
2413 #define netdev_tx_t int
2414 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2415 #ifndef NETIF_F_FCOE_MTU
2416 #define NETIF_F_FCOE_MTU (1 << 26)
2418 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2420 #ifndef pm_runtime_get_sync
2421 #define pm_runtime_get_sync(dev) do {} while (0)
2423 #ifndef pm_runtime_put
2424 #define pm_runtime_put(dev) do {} while (0)
2426 #ifndef pm_runtime_put_sync
2427 #define pm_runtime_put_sync(dev) do {} while (0)
2429 #ifndef pm_runtime_resume
2430 #define pm_runtime_resume(dev) do {} while (0)
2432 #ifndef pm_schedule_suspend
2433 #define pm_schedule_suspend(dev, t) do {} while (0)
2435 #ifndef pm_runtime_set_suspended
2436 #define pm_runtime_set_suspended(dev) do {} while (0)
2438 #ifndef pm_runtime_disable
2439 #define pm_runtime_disable(dev) do {} while (0)
2441 #ifndef pm_runtime_put_noidle
2442 #define pm_runtime_put_noidle(dev) do {} while (0)
2444 #ifndef pm_runtime_set_active
2445 #define pm_runtime_set_active(dev) do {} while (0)
2447 #ifndef pm_runtime_enable
2448 #define pm_runtime_enable(dev) do {} while (0)
2450 #ifndef pm_runtime_get_noresume
2451 #define pm_runtime_get_noresume(dev) do {} while (0)
2453 #else /* < 2.6.32 */
2454 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2455 #ifndef HAVE_NETDEV_OPS_FCOE_ENABLE
2456 #define HAVE_NETDEV_OPS_FCOE_ENABLE
2458 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2460 #ifndef HAVE_DCBNL_OPS_GETAPP
2461 #define HAVE_DCBNL_OPS_GETAPP
2463 #endif /* CONFIG_DCB */
2464 #include <linux/pm_runtime.h>
2465 /* IOV bad DMA target work arounds require at least this kernel rev support */
2466 #define HAVE_PCIE_TYPE
2467 #endif /* < 2.6.32 */
2469 /*****************************************************************************/
2470 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) )
2471 #ifndef pci_pcie_cap
2472 #define pci_pcie_cap(pdev) pci_find_capability(pdev, PCI_CAP_ID_EXP)
2475 #define IPV4_FLOW 0x10
2476 #endif /* IPV4_FLOW */
2478 #define IPV6_FLOW 0x11
2479 #endif /* IPV6_FLOW */
2480 /* Features back-ported to RHEL6 or SLES11 SP1 after 2.6.32 */
2481 #if ( (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(6,0)) || \
2482 (SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,1,0)) )
2483 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2484 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2485 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2487 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2488 #endif /* RHEL6 or SLES11 SP1 */
2491 #endif /* __percpu */
2492 #else /* < 2.6.33 */
2493 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2494 #ifndef HAVE_NETDEV_OPS_FCOE_GETWWN
2495 #define HAVE_NETDEV_OPS_FCOE_GETWWN
2497 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2498 #define HAVE_ETHTOOL_SFP_DISPLAY_PORT
2499 #endif /* < 2.6.33 */
2501 /*****************************************************************************/
2502 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) )
2503 #ifndef ETH_FLAG_NTUPLE
2504 #define ETH_FLAG_NTUPLE NETIF_F_NTUPLE
2507 #ifndef netdev_mc_count
2508 #define netdev_mc_count(dev) ((dev)->mc_count)
2510 #ifndef netdev_mc_empty
2511 #define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0)
2513 #ifndef netdev_for_each_mc_addr
2514 #define netdev_for_each_mc_addr(mclist, dev) \
2515 for (mclist = dev->mc_list; mclist; mclist = mclist->next)
2517 #ifndef netdev_uc_count
2518 #define netdev_uc_count(dev) ((dev)->uc.count)
2520 #ifndef netdev_uc_empty
2521 #define netdev_uc_empty(dev) (netdev_uc_count(dev) == 0)
2523 #ifndef netdev_for_each_uc_addr
2524 #define netdev_for_each_uc_addr(ha, dev) \
2525 list_for_each_entry(ha, &dev->uc.list, list)
2527 #ifndef dma_set_coherent_mask
2528 #define dma_set_coherent_mask(dev,mask) \
2529 pci_set_consistent_dma_mask(to_pci_dev(dev),(mask))
2531 #ifndef pci_dev_run_wake
2532 #define pci_dev_run_wake(pdev) (0)
2535 /* netdev logging taken from include/linux/netdevice.h */
2537 static inline const char *_kc_netdev_name(const struct net_device *dev)
2539 if (dev->reg_state != NETREG_REGISTERED)
2540 return "(unregistered net_device)";
2543 #define netdev_name(netdev) _kc_netdev_name(netdev)
2544 #endif /* netdev_name */
2546 #undef netdev_printk
2547 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
2548 #define netdev_printk(level, netdev, format, args...) \
2550 struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2551 struct pci_dev *pdev = kc_adapter->pdev; \
2552 printk("%s %s: " format, level, pci_name(pdev), \
2555 #elif ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
2556 #define netdev_printk(level, netdev, format, args...) \
2558 struct adapter_struct *kc_adapter = netdev_priv(netdev);\
2559 struct pci_dev *pdev = kc_adapter->pdev; \
2560 struct device *dev = pci_dev_to_dev(pdev); \
2561 dev_printk(level, dev, "%s: " format, \
2562 netdev_name(netdev), ##args); \
2564 #else /* 2.6.21 => 2.6.34 */
2565 #define netdev_printk(level, netdev, format, args...) \
2566 dev_printk(level, (netdev)->dev.parent, \
2568 netdev_name(netdev), ##args)
2569 #endif /* <2.6.0 <2.6.21 <2.6.34 */
2571 #define netdev_emerg(dev, format, args...) \
2572 netdev_printk(KERN_EMERG, dev, format, ##args)
2574 #define netdev_alert(dev, format, args...) \
2575 netdev_printk(KERN_ALERT, dev, format, ##args)
2577 #define netdev_crit(dev, format, args...) \
2578 netdev_printk(KERN_CRIT, dev, format, ##args)
2580 #define netdev_err(dev, format, args...) \
2581 netdev_printk(KERN_ERR, dev, format, ##args)
2583 #define netdev_warn(dev, format, args...) \
2584 netdev_printk(KERN_WARNING, dev, format, ##args)
2585 #undef netdev_notice
2586 #define netdev_notice(dev, format, args...) \
2587 netdev_printk(KERN_NOTICE, dev, format, ##args)
2589 #define netdev_info(dev, format, args...) \
2590 netdev_printk(KERN_INFO, dev, format, ##args)
2592 #if defined(CONFIG_DYNAMIC_DEBUG)
2593 #define netdev_dbg(__dev, format, args...) \
2595 dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \
2596 netdev_name(__dev), ##args); \
2599 #define netdev_dbg(__dev, format, args...) \
2602 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
2608 #define netif_printk(priv, type, level, dev, fmt, args...) \
2610 if (netif_msg_##type(priv)) \
2611 netdev_printk(level, (dev), fmt, ##args); \
2615 #define netif_emerg(priv, type, dev, fmt, args...) \
2616 netif_level(emerg, priv, type, dev, fmt, ##args)
2618 #define netif_alert(priv, type, dev, fmt, args...) \
2619 netif_level(alert, priv, type, dev, fmt, ##args)
2621 #define netif_crit(priv, type, dev, fmt, args...) \
2622 netif_level(crit, priv, type, dev, fmt, ##args)
2624 #define netif_err(priv, type, dev, fmt, args...) \
2625 netif_level(err, priv, type, dev, fmt, ##args)
2627 #define netif_warn(priv, type, dev, fmt, args...) \
2628 netif_level(warn, priv, type, dev, fmt, ##args)
2630 #define netif_notice(priv, type, dev, fmt, args...) \
2631 netif_level(notice, priv, type, dev, fmt, ##args)
2633 #define netif_info(priv, type, dev, fmt, args...) \
2634 netif_level(info, priv, type, dev, fmt, ##args)
2636 #ifdef SET_SYSTEM_SLEEP_PM_OPS
2637 #define HAVE_SYSTEM_SLEEP_PM_OPS
2640 #ifndef for_each_set_bit
2641 #define for_each_set_bit(bit, addr, size) \
2642 for ((bit) = find_first_bit((addr), (size)); \
2644 (bit) = find_next_bit((addr), (size), (bit) + 1))
2645 #endif /* for_each_set_bit */
2647 #ifndef DEFINE_DMA_UNMAP_ADDR
2648 #define DEFINE_DMA_UNMAP_ADDR DECLARE_PCI_UNMAP_ADDR
2649 #define DEFINE_DMA_UNMAP_LEN DECLARE_PCI_UNMAP_LEN
2650 #define dma_unmap_addr pci_unmap_addr
2651 #define dma_unmap_addr_set pci_unmap_addr_set
2652 #define dma_unmap_len pci_unmap_len
2653 #define dma_unmap_len_set pci_unmap_len_set
2654 #endif /* DEFINE_DMA_UNMAP_ADDR */
2655 #else /* < 2.6.34 */
2656 #define HAVE_SYSTEM_SLEEP_PM_OPS
2657 #ifndef HAVE_SET_RX_MODE
2658 #define HAVE_SET_RX_MODE
2661 #endif /* < 2.6.34 */
2663 /*****************************************************************************/
2664 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) )
2665 #ifndef numa_node_id
2666 #define numa_node_id() 0
2669 #include <net/sch_generic.h>
2670 #ifndef CONFIG_NETDEVICES_MULTIQUEUE
2671 void _kc_netif_set_real_num_tx_queues(struct net_device *, unsigned int);
2672 #define netif_set_real_num_tx_queues _kc_netif_set_real_num_tx_queues
2673 #else /* CONFIG_NETDEVICES_MULTI_QUEUE */
2674 #define netif_set_real_num_tx_queues(_netdev, _count) \
2676 (_netdev)->egress_subqueue_count = _count; \
2678 #endif /* CONFIG_NETDEVICES_MULTI_QUEUE */
2680 #define netif_set_real_num_tx_queues(_netdev, _count) do {} while(0)
2681 #endif /* HAVE_TX_MQ */
2682 #ifndef ETH_FLAG_RXHASH
2683 #define ETH_FLAG_RXHASH (1<<28)
2684 #endif /* ETH_FLAG_RXHASH */
2685 #else /* < 2.6.35 */
2686 #define HAVE_PM_QOS_REQUEST_LIST
2687 #define HAVE_IRQ_AFFINITY_HINT
2688 #endif /* < 2.6.35 */
2690 /*****************************************************************************/
2691 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) )
2692 extern int _kc_ethtool_op_set_flags(struct net_device *, u32, u32);
2693 #define ethtool_op_set_flags _kc_ethtool_op_set_flags
2694 extern u32 _kc_ethtool_op_get_flags(struct net_device *);
2695 #define ethtool_op_get_flags _kc_ethtool_op_get_flags
2697 #ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2701 #define NET_IP_ALIGN 0
2702 #endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */
2708 #if (L1_CACHE_BYTES > 32)
2709 #define NET_SKB_PAD L1_CACHE_BYTES
2711 #define NET_SKB_PAD 32
2714 static inline struct sk_buff *_kc_netdev_alloc_skb_ip_align(struct net_device *dev,
2715 unsigned int length)
2717 struct sk_buff *skb;
2719 skb = alloc_skb(length + NET_SKB_PAD + NET_IP_ALIGN, GFP_ATOMIC);
2721 #if (NET_IP_ALIGN + NET_SKB_PAD)
2722 skb_reserve(skb, NET_IP_ALIGN + NET_SKB_PAD);
2729 #ifdef netdev_alloc_skb_ip_align
2730 #undef netdev_alloc_skb_ip_align
2732 #define netdev_alloc_skb_ip_align(n, l) _kc_netdev_alloc_skb_ip_align(n, l)
2735 #define netif_level(level, priv, type, dev, fmt, args...) \
2737 if (netif_msg_##type(priv)) \
2738 netdev_##level(dev, fmt, ##args); \
2742 #define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
2744 #else /* < 2.6.36 */
2745 #define HAVE_PM_QOS_REQUEST_ACTIVE
2746 #define HAVE_8021P_SUPPORT
2747 #define HAVE_NDO_GET_STATS64
2748 #endif /* < 2.6.36 */
2750 /*****************************************************************************/
2751 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) )
2752 #ifndef ETHTOOL_RXNTUPLE_ACTION_CLEAR
2753 #define ETHTOOL_RXNTUPLE_ACTION_CLEAR (-2)
2756 #define VLAN_N_VID VLAN_GROUP_ARRAY_LEN
2757 #endif /* VLAN_N_VID */
2758 #ifndef ETH_FLAG_TXVLAN
2759 #define ETH_FLAG_TXVLAN (1 << 7)
2760 #endif /* ETH_FLAG_TXVLAN */
2761 #ifndef ETH_FLAG_RXVLAN
2762 #define ETH_FLAG_RXVLAN (1 << 8)
2763 #endif /* ETH_FLAG_RXVLAN */
2765 static inline void _kc_skb_checksum_none_assert(struct sk_buff *skb)
2767 WARN_ON(skb->ip_summed != CHECKSUM_NONE);
2769 #define skb_checksum_none_assert(skb) _kc_skb_checksum_none_assert(skb)
2771 static inline void *_kc_vzalloc_node(unsigned long size, int node)
2773 void *addr = vmalloc_node(size, node);
2775 memset(addr, 0, size);
2778 #define vzalloc_node(_size, _node) _kc_vzalloc_node(_size, _node)
2780 static inline void *_kc_vzalloc(unsigned long size)
2782 void *addr = vmalloc(size);
2784 memset(addr, 0, size);
2787 #define vzalloc(_size) _kc_vzalloc(_size)
2789 #ifndef vlan_get_protocol
2790 static inline __be16 __kc_vlan_get_protocol(const struct sk_buff *skb)
2792 if (vlan_tx_tag_present(skb) ||
2793 skb->protocol != cpu_to_be16(ETH_P_8021Q))
2794 return skb->protocol;
2796 if (skb_headlen(skb) < sizeof(struct vlan_ethhdr))
2799 return ((struct vlan_ethhdr*)skb->data)->h_vlan_encapsulated_proto;
2801 #define vlan_get_protocol(_skb) __kc_vlan_get_protocol(_skb)
2803 #ifdef HAVE_HW_TIME_STAMP
2804 #define SKBTX_HW_TSTAMP (1 << 0)
2805 #define SKBTX_IN_PROGRESS (1 << 2)
2806 #define SKB_SHARED_TX_IS_UNION
2808 #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,18) )
2809 #ifndef HAVE_VLAN_RX_REGISTER
2810 #define HAVE_VLAN_RX_REGISTER
2812 #endif /* > 2.4.18 */
2813 #endif /* < 2.6.37 */
2815 /*****************************************************************************/
2816 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) )
2817 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
2818 #define skb_checksum_start_offset(skb) skb_transport_offset(skb)
2819 #else /* 2.6.22 -> 2.6.37 */
2820 static inline int _kc_skb_checksum_start_offset(const struct sk_buff *skb)
2822 return skb->csum_start - skb_headroom(skb);
2824 #define skb_checksum_start_offset(skb) _kc_skb_checksum_start_offset(skb)
2825 #endif /* 2.6.22 -> 2.6.37 */
2827 #ifndef IEEE_8021QAZ_MAX_TCS
2828 #define IEEE_8021QAZ_MAX_TCS 8
2830 #ifndef DCB_CAP_DCBX_HOST
2831 #define DCB_CAP_DCBX_HOST 0x01
2833 #ifndef DCB_CAP_DCBX_LLD_MANAGED
2834 #define DCB_CAP_DCBX_LLD_MANAGED 0x02
2836 #ifndef DCB_CAP_DCBX_VER_CEE
2837 #define DCB_CAP_DCBX_VER_CEE 0x04
2839 #ifndef DCB_CAP_DCBX_VER_IEEE
2840 #define DCB_CAP_DCBX_VER_IEEE 0x08
2842 #ifndef DCB_CAP_DCBX_STATIC
2843 #define DCB_CAP_DCBX_STATIC 0x10
2845 #endif /* CONFIG_DCB */
2846 extern u16 ___kc_skb_tx_hash(struct net_device *, const struct sk_buff *, u16);
2847 #define __skb_tx_hash(n, s, q) ___kc_skb_tx_hash((n), (s), (q))
2848 #else /* < 2.6.38 */
2849 #endif /* < 2.6.38 */
2851 /*****************************************************************************/
2852 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) )
2853 #ifndef skb_queue_reverse_walk_safe
2854 #define skb_queue_reverse_walk_safe(queue, skb, tmp) \
2855 for (skb = (queue)->prev, tmp = skb->prev; \
2856 skb != (struct sk_buff *)(queue); \
2857 skb = tmp, tmp = skb->prev)
2859 #else /* < 2.6.39 */
2860 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
2861 #ifndef HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2862 #define HAVE_NETDEV_OPS_FCOE_DDP_TARGET
2864 #endif /* CONFIG_FCOE || CONFIG_FCOE_MODULE */
2868 #ifndef HAVE_SETUP_TC
2869 #define HAVE_SETUP_TC
2872 #ifndef HAVE_DCBNL_IEEE
2873 #define HAVE_DCBNL_IEEE
2875 #endif /* CONFIG_DCB */
2876 #ifndef HAVE_NDO_SET_FEATURES
2877 #define HAVE_NDO_SET_FEATURES
2879 #endif /* < 2.6.39 */
2881 /*****************************************************************************/
2882 /* use < 2.6.40 because of a Fedora 15 kernel update where they
2883 * updated the kernel version to 2.6.40.x and they back-ported 3.0 features
2884 * like set_phys_id for ethtool.
2886 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,40) )
2887 #ifdef ETHTOOL_GRXRINGS
2889 #define FLOW_EXT 0x80000000
2890 union _kc_ethtool_flow_union {
2891 struct ethtool_tcpip4_spec tcp_ip4_spec;
2892 struct ethtool_usrip4_spec usr_ip4_spec;
2895 struct _kc_ethtool_flow_ext {
2900 struct _kc_ethtool_rx_flow_spec {
2902 union _kc_ethtool_flow_union h_u;
2903 struct _kc_ethtool_flow_ext h_ext;
2904 union _kc_ethtool_flow_union m_u;
2905 struct _kc_ethtool_flow_ext m_ext;
2909 #define ethtool_rx_flow_spec _kc_ethtool_rx_flow_spec
2910 #endif /* FLOW_EXT */
2913 #define pci_disable_link_state_locked pci_disable_link_state
2915 #ifndef PCI_LTR_VALUE_MASK
2916 #define PCI_LTR_VALUE_MASK 0x000003ff
2918 #ifndef PCI_LTR_SCALE_MASK
2919 #define PCI_LTR_SCALE_MASK 0x00001c00
2921 #ifndef PCI_LTR_SCALE_SHIFT
2922 #define PCI_LTR_SCALE_SHIFT 10
2925 #else /* < 2.6.40 */
2926 #define HAVE_ETHTOOL_SET_PHYS_ID
2927 #endif /* < 2.6.40 */
2929 /*****************************************************************************/
2930 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) )
2931 #ifndef __netdev_alloc_skb_ip_align
2932 #define __netdev_alloc_skb_ip_align(d,l,_g) netdev_alloc_skb_ip_align(d,l)
2933 #endif /* __netdev_alloc_skb_ip_align */
2934 #define dcb_ieee_setapp(dev, app) dcb_setapp(dev, app)
2935 #define dcb_ieee_delapp(dev, app) 0
2936 #define dcb_ieee_getapp_mask(dev, app) (1 << app->priority)
2938 #ifndef HAVE_DCBNL_IEEE_DELAPP
2939 #define HAVE_DCBNL_IEEE_DELAPP
2941 #endif /* < 3.1.0 */
2943 /*****************************************************************************/
2944 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) )
2945 #ifdef ETHTOOL_GRXRINGS
2946 #define HAVE_ETHTOOL_GET_RXNFC_VOID_RULE_LOCS
2947 #endif /* ETHTOOL_GRXRINGS */
2949 #ifndef skb_frag_size
2950 #define skb_frag_size(frag) _kc_skb_frag_size(frag)
2951 static inline unsigned int _kc_skb_frag_size(const skb_frag_t *frag)
2955 #endif /* skb_frag_size */
2957 #ifndef skb_frag_size_sub
2958 #define skb_frag_size_sub(frag, delta) _kc_skb_frag_size_sub(frag, delta)
2959 static inline void _kc_skb_frag_size_sub(skb_frag_t *frag, int delta)
2961 frag->size -= delta;
2963 #endif /* skb_frag_size_sub */
2965 #ifndef skb_frag_page
2966 #define skb_frag_page(frag) _kc_skb_frag_page(frag)
2967 static inline struct page *_kc_skb_frag_page(const skb_frag_t *frag)
2971 #endif /* skb_frag_page */
2973 #ifndef skb_frag_address
2974 #define skb_frag_address(frag) _kc_skb_frag_address(frag)
2975 static inline void *_kc_skb_frag_address(const skb_frag_t *frag)
2977 return page_address(skb_frag_page(frag)) + frag->page_offset;
2979 #endif /* skb_frag_address */
2981 #ifndef skb_frag_dma_map
2982 #define skb_frag_dma_map(dev,frag,offset,size,dir) \
2983 _kc_skb_frag_dma_map(dev,frag,offset,size,dir)
2984 static inline dma_addr_t _kc_skb_frag_dma_map(struct device *dev,
2985 const skb_frag_t *frag,
2986 size_t offset, size_t size,
2987 enum dma_data_direction dir)
2989 return dma_map_page(dev, skb_frag_page(frag),
2990 frag->page_offset + offset, size, dir);
2992 #endif /* skb_frag_dma_map */
2994 #ifndef __skb_frag_unref
2995 #define __skb_frag_unref(frag) __kc_skb_frag_unref(frag)
2996 static inline void __kc_skb_frag_unref(skb_frag_t *frag)
2998 put_page(skb_frag_page(frag));
3000 #endif /* __skb_frag_unref */
3002 #ifndef HAVE_PCI_DEV_FLAGS_ASSIGNED
3003 #define HAVE_PCI_DEV_FLAGS_ASSIGNED
3004 #define HAVE_VF_SPOOFCHK_CONFIGURE
3006 #endif /* < 3.2.0 */
3008 #if (RHEL_RELEASE_CODE && RHEL_RELEASE_CODE == RHEL_RELEASE_VERSION(6,2))
3009 #undef ixgbe_get_netdev_tc_txq
3010 #define ixgbe_get_netdev_tc_txq(dev, tc) (&netdev_extended(dev)->qos_data.tc_to_txq[tc])
3013 /*****************************************************************************/
3014 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) )
3015 typedef u32 netdev_features_t;
3016 #else /* ! < 3.3.0 */
3017 #define HAVE_INT_NDO_VLAN_RX_ADD_VID
3018 #ifdef ETHTOOL_SRXNTUPLE
3019 #undef ETHTOOL_SRXNTUPLE
3021 #endif /* < 3.3.0 */
3023 /*****************************************************************************/
3024 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) )
3025 #ifndef NETIF_F_RXFCS
3026 #define NETIF_F_RXFCS 0
3027 #endif /* NETIF_F_RXFCS */
3028 #ifndef NETIF_F_RXALL
3029 #define NETIF_F_RXALL 0
3030 #endif /* NETIF_F_RXALL */
3032 #define NUMTCS_RETURNS_U8
3035 #endif /* < 3.4.0 */
3037 /*****************************************************************************/
3038 #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) )
3040 #define HAVE_FDB_OPS
3041 #endif /* < 3.5.0 */
3042 #endif /* _KCOMPAT_H_ */