/******************************************************************************* Intel PRO/1000 Linux driver Copyright(c) 1999 - 2006 Intel Corporation. This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called "COPYING". Contact Information: Linux NICS e1000-devel Mailing List Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 *******************************************************************************/ #ifndef _KCOMPAT_H_ #define _KCOMPAT_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include /* general compatibility flags unclassified per kernel */ #ifndef PMSG_SUSPEND #define PMSG_SUSPEND 3 #endif #ifndef module_param #define module_param(v,t,p) MODULE_PARM(v, "i"); #endif #ifndef DMA_64BIT_MASK #define DMA_64BIT_MASK 0xffffffffffffffffULL #endif #ifndef DMA_32BIT_MASK #define DMA_32BIT_MASK 0x00000000ffffffffULL #endif #ifndef PCI_CAP_ID_EXP #define PCI_CAP_ID_EXP 0x10 #endif #ifndef mmiowb #ifdef CONFIG_IA64 #define mmiowb() asm volatile ("mf.a" ::: "memory") #else #define mmiowb() #endif #endif #ifndef IRQ_HANDLED #define irqreturn_t void #define IRQ_HANDLED #define IRQ_NONE #endif #ifndef SET_NETDEV_DEV #define SET_NETDEV_DEV(net, pdev) #endif #ifndef HAVE_FREE_NETDEV #define free_netdev(x) kfree(x) #endif #ifdef HAVE_POLL_CONTROLLER #define CONFIG_NET_POLL_CONTROLLER #endif #ifndef NETDEV_TX_OK #define NETDEV_TX_OK 0 #endif #ifndef NETDEV_TX_BUSY #define NETDEV_TX_BUSY 1 #endif #ifndef NETDEV_TX_LOCKED #define NETDEV_TX_LOCKED -1 #endif #ifndef SKB_DATAREF_SHIFT /* if we do not have the infrastructure to detect if skb_header is cloned just return false in all cases */ #define skb_header_cloned(x) 0 #endif #ifndef NETIF_F_GSO #define gso_size tso_size #define gso_segs tso_segs #endif #ifndef CHECKSUM_PARTIAL #define CHECKSUM_PARTIAL CHECKSUM_HW #define CHECKSUM_COMPLETE CHECKSUM_HW #endif #ifndef __read_mostly #define __read_mostly #endif #ifndef HAVE_NETIF_MSG #define HAVE_NETIF_MSG 1 enum { NETIF_MSG_DRV = 0x0001, NETIF_MSG_PROBE = 0x0002, NETIF_MSG_LINK = 0x0004, NETIF_MSG_TIMER = 0x0008, NETIF_MSG_IFDOWN = 0x0010, NETIF_MSG_IFUP = 0x0020, NETIF_MSG_RX_ERR = 0x0040, NETIF_MSG_TX_ERR = 0x0080, NETIF_MSG_TX_QUEUED = 0x0100, NETIF_MSG_INTR = 0x0200, NETIF_MSG_TX_DONE = 0x0400, NETIF_MSG_RX_STATUS = 0x0800, NETIF_MSG_PKTDATA = 0x1000, NETIF_MSG_HW = 0x2000, NETIF_MSG_WOL = 0x4000, }; #else #define NETIF_MSG_HW 0x2000 #define NETIF_MSG_WOL 0x4000 #endif /* HAVE_NETIF_MSG */ #ifndef MII_RESV1 #define MII_RESV1 0x17 /* Reserved... */ #endif #ifndef unlikely #define unlikely(_x) _x #define likely(_x) _x #endif #ifndef WARN_ON #define WARN_ON(x) #endif #ifndef PCI_DEVICE #define PCI_DEVICE(vend,dev) \ .vendor = (vend), .device = (dev), \ .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID #endif /*****************************************************************************/ /* 2.5.28 => 2.4.23 */ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,5,28) ) static inline void _kc_synchronize_irq(void) { synchronize_irq(); } #undef synchronize_irq #define synchronize_irq(X) _kc_synchronize_irq() #include #define work_struct tq_struct #define INIT_WORK INIT_TQUEUE #define schedule_work schedule_task #define flush_scheduled_work flush_scheduled_tasks #endif /* 2.5.28 => 2.4.17 */ /*****************************************************************************/ /* 2.6.0 => 2.5.28 */ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) ) #define MODULE_INFO(version, _version) #define pci_set_consistent_dma_mask(dev,mask) 1 #undef dev_put #define dev_put(dev) __dev_put(dev) #ifndef skb_fill_page_desc #define skb_fill_page_desc _kc_skb_fill_page_desc extern void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page, int off, int size); #endif #ifndef pci_dma_mapping_error #define pci_dma_mapping_error _kc_pci_dma_mapping_error static inline int _kc_pci_dma_mapping_error(dma_addr_t dma_addr) { return dma_addr == 0; } #endif #endif /* 2.6.0 => 2.5.28 */ /*****************************************************************************/ /* 2.6.4 => 2.6.0 */ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) #define MODULE_VERSION(_version) MODULE_INFO(version, _version) #endif /* 2.6.4 => 2.6.0 */ /*****************************************************************************/ /* 2.6.5 => 2.6.0 */ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5) ) #define pci_dma_sync_single_for_cpu pci_dma_sync_single #define pci_dma_sync_single_for_device pci_dma_sync_single_for_cpu #endif /* 2.6.5 => 2.6.0 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7) ) #undef if_mii #define if_mii _kc_if_mii static inline struct mii_ioctl_data *_kc_if_mii(struct ifreq *rq) { return (struct mii_ioctl_data *) &rq->ifr_ifru; } #endif /* < 2.6.7 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8) ) #define msleep(x) do { set_current_state(TASK_UNINTERRUPTIBLE); \ schedule_timeout((x * HZ)/1000 + 2); \ } while (0) #endif /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)) #define __iomem #define MSEC_PER_SEC 1000L static inline unsigned int _kc_jiffies_to_msecs(const unsigned long j) { #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) return (MSEC_PER_SEC / HZ) * j; #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC); #else return (j * MSEC_PER_SEC) / HZ; #endif } static inline unsigned long _kc_msecs_to_jiffies(const unsigned int m) { if (m > _kc_jiffies_to_msecs(MAX_JIFFY_OFFSET)) return MAX_JIFFY_OFFSET; #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ) return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ); #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC) return m * (HZ / MSEC_PER_SEC); #else return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC; #endif } #define msleep_interruptible _kc_msleep_interruptible static unsigned inline long _kc_msleep_interruptible(unsigned int msecs) { unsigned long timeout = _kc_msecs_to_jiffies(msecs) + 1; while (timeout && !signal_pending(current)) { __set_current_state(TASK_INTERRUPTIBLE); timeout = schedule_timeout(timeout); } return _kc_jiffies_to_msecs(timeout); } #endif /* < 2.6.9 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,6) && \ LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) ) #ifdef pci_save_state #undef pci_save_state #endif #define pci_save_state(X) { \ int i; \ if (adapter->pci_state) { \ for (i = 0; i < 16; i++) { \ pci_read_config_dword((X), \ i * 4, \ &adapter->pci_state[i]); \ } \ } \ } #ifdef pci_restore_state #undef pci_restore_state #endif #define pci_restore_state(X) { \ int i; \ if (adapter->pci_state) { \ for (i = 0; i < 16; i++) { \ pci_write_config_dword((X), \ i * 4, \ adapter->pci_state[i]); \ } \ } else { \ for (i = 0; i < 6; i++) { \ pci_write_config_dword((X), \ PCI_BASE_ADDRESS_0 + (i * 4), \ (X)->resource[i].start); \ } \ } \ } #endif /* 2.4.6 <= x < 2.6.10 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) ) #ifdef module_param_array_named #undef module_param_array_named #define module_param_array_named(name, array, type, nump, perm) \ static struct kparam_array __param_arr_##name \ = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type, \ sizeof(array[0]), array }; \ module_param_call(name, param_array_set, param_array_get, \ &__param_arr_##name, perm) #endif /* module_param_array_named */ #endif /* < 2.6.10 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11) ) #define PCI_D0 0 #define PCI_D1 1 #define PCI_D2 2 #define PCI_D3hot 3 #define PCI_D3cold 4 #define pci_choose_state(pdev,state) state #define PMSG_SUSPEND 3 #undef NETIF_F_LLTX #ifndef ARCH_HAS_PREFETCH #define prefetch(X) #endif #ifndef NET_IP_ALIGN #define NET_IP_ALIGN 2 #endif #endif /* < 2.6.11 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) ) #define pm_message_t u32 #ifndef kzalloc #define kzalloc _kc_kzalloc extern void *_kc_kzalloc(size_t size, int flags); #endif #endif /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) ) #ifndef IRQF_PROBE_SHARED #ifdef SA_PROBEIRQ #define IRQF_PROBE_SHARED SA_PROBEIRQ #else #define IRQF_PROBE_SHARED 0 #endif #endif #ifndef IRQF_SHARED #define IRQF_SHARED SA_SHIRQ #endif #ifndef netdev_alloc_skb #define netdev_alloc_skb _kc_netdev_alloc_skb extern struct sk_buff *_kc_netdev_alloc_skb(struct net_device *dev, unsigned int length); #endif #endif /* < 2.6.18 */ /*****************************************************************************/ #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) ) typedef void (*irq_handler_t)(int, void*, struct pt_regs *); typedef void (*new_handler_t)(int, void*); static inline int _kc_request_irq(unsigned int irq, new_handler_t handler, unsigned long flags, const char *devname, void *dev_id) { irq_handler_t new_handler = (irq_handler_t) handler; return request_irq(irq, new_handler, flags, devname, dev_id); } #undef request_irq #define request_irq(irq, handler, flags, devname, dev_id) _kc_request_irq((irq), (handler), (flags), (devname), (dev_id)) #endif /* < 2.6.19 */ /*****************************************************************************/ #endif /* _KCOMPAT_H_ */