From: Kieran Mansley <kmansley@solarflare.com>
Subject: sync Solarflare accelerator headers
References: bnc#489105

Sync the headers used by sfc_netback and sfc_netutil with those in the
sfc_resource driver to give a consistent view of cross-module APIs.

Update sfc_netback to use efx_vi_alloc() as defined by the version of
sfc_resource module in SLES11.  It now takes a net driver interface
index rather than a NIC index.

efx_vi_hw_resource_get_phys() no longer returns a version.

Set efhw_arch field of device type.

Acked-by: jbeulich@novell.com

--- head-2009-04-07.orig/drivers/net/sfc/sfc_resource/ci/efhw/common.h	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/net/sfc/sfc_resource/ci/efhw/common.h	2009-04-07 15:02:05.000000000 +0200
@@ -41,6 +41,10 @@
 
 #include <ci/efhw/common_sysdep.h>
 
+enum efhw_arch {
+	EFHW_ARCH_FALCON,
+};
+
 typedef uint32_t efhw_buffer_addr_t;
 #define EFHW_BUFFER_ADDR_FMT	"[ba:%"PRIx32"]"
 
--- head-2009-04-07.orig/drivers/net/sfc/sfc_resource/nic.c	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/net/sfc/sfc_resource/nic.c	2009-04-07 15:02:05.000000000 +0200
@@ -47,6 +47,7 @@ int efhw_device_type_init(struct efhw_de
 	switch (device_id) {
 	case 0x0703:
 	case 0x6703:
+		dt->arch = EFHW_ARCH_FALCON;
 		dt->variant = 'A';
 		switch (class_revision) {
 		case 0:
@@ -60,6 +61,7 @@ int efhw_device_type_init(struct efhw_de
 		}
 		break;
 	case 0x0710:
+		dt->arch = EFHW_ARCH_FALCON;
 		dt->variant = 'B';
 		switch (class_revision) {
 		case 2:
--- head-2009-04-07.orig/drivers/xen/sfc_netback/accel.h	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/accel.h	2009-04-07 15:02:05.000000000 +0200
@@ -123,8 +123,6 @@ struct netback_accel {
 	enum net_accel_hw_type hw_type;
 	/*! State of allocation */	       
 	int hw_state;
-	/*! Index into ci_driver.nics[] for this interface */
-	int nic_index;
 	/*! How to set up the acceleration for this hardware */
 	int (*accel_setup)(struct netback_accel *); 
 	/*! And how to stop it. */
--- head-2009-04-07.orig/drivers/xen/sfc_netback/accel_solarflare.c	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/accel_solarflare.c	2009-04-07 15:03:41.000000000 +0200
@@ -87,7 +87,6 @@ struct driverlink_port {
 	enum net_accel_hw_type type;
 	struct net_device *net_dev;
 	struct efx_dl_device *efx_dl_dev;
-	int nic_index;
 	void *fwd_priv;
 };
 
@@ -164,25 +163,6 @@ static struct netback_accel_hooks accel_
 };
 
 
-/*
- * Handy helper which given an efx_dl_device works out which
- * efab_nic_t index into efrm_nic_table.nics[] it corresponds to 
- */
-static int efx_device_to_efab_nic_index(struct efx_dl_device *efx_dl_dev) 
-{
-	int i, rc = -1;
-	struct efhw_nic *nic;
-
-	EFRM_FOR_EACH_NIC(i, nic) {
-		if (nic != NULL && nic->net_driver_dev != NULL &&
-		    nic->net_driver_dev->pci_dev == efx_dl_dev->pci_dev)
-			rc = i;
-	}
-
-	return rc;
-}
-
-
 /* Driver link probe - register our callbacks */
 static int bend_dl_probe(struct efx_dl_device *efx_dl_dev,
 			 const struct net_device *net_dev,
@@ -216,17 +196,6 @@ static int bend_dl_probe(struct efx_dl_d
 	port->efx_dl_dev = efx_dl_dev;
 	efx_dl_dev->priv = port;
 
-	port->nic_index = efx_device_to_efab_nic_index(efx_dl_dev);
-	if (port->nic_index < 0) {
-		/*
-		 * This can happen in theory if the resource driver
-		 * failed to initialise properly
-		 */
-		EPRINTK("%s: nic structure not found\n", __FUNCTION__);
-		rc = -EINVAL;
-		goto fail2;
-	}
-
 	port->fwd_priv = netback_accel_init_fwd_port();
 	if (port->fwd_priv == NULL) {
 		EPRINTK("%s: failed to set up forwarding for port\n",
@@ -368,8 +337,6 @@ int netback_accel_sf_hwtype(struct netba
 			bend->accel_setup = netback_accel_setup_vnic_hw;
 			bend->accel_shutdown = netback_accel_shutdown_vnic_hw;
 			bend->fwd_priv = port->fwd_priv;
-			/* This is just needed to pass to efx_vi_alloc */
-			bend->nic_index = port->nic_index;
 			bend->net_dev = port->net_dev;
 			mutex_unlock(&accel_mutex);
 			return 0;
@@ -496,7 +463,7 @@ static int ef_get_vnic(struct netback_ac
 
 	accel_hw_priv = bend->accel_hw_priv;
 
-	rc = efx_vi_alloc(&accel_hw_priv->efx_vih, bend->nic_index);
+	rc = efx_vi_alloc(&accel_hw_priv->efx_vih, bend->net_dev->ifindex);
 	if (rc != 0) {
 		EPRINTK("%s: efx_vi_alloc failed %d\n", __FUNCTION__, rc);
 		free_page_state(bend);
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/driver/resource/efx_vi.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/driver/resource/efx_vi.h	2009-04-07 15:02:05.000000000 +0200
@@ -49,11 +49,11 @@ struct efx_vi_state;
  * Allocate an efx_vi, including event queue and pt_endpoint
  *
  * \param vih_out Pointer to a handle that is set on success
- * \param nic_index Index of NIC to apply this resource to
+ * \param ifindex Index of the network interface desired
  * \return Zero on success (and vih_out set), non-zero on failure.
  */
 extern int
-efx_vi_alloc(struct efx_vi_state **vih_out, int nic_index);
+efx_vi_alloc(struct efx_vi_state **vih_out, int ifindex);
 
 /*!
  * Free a previously allocated efx_vi
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/common.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/common.h	2009-04-07 15:07:31.000000000 +0200
@@ -43,7 +43,6 @@
 
 enum efhw_arch {
 	EFHW_ARCH_FALCON,
-	EFHW_ARCH_SIENA,
 };
 
 typedef uint32_t efhw_buffer_addr_t;
@@ -59,18 +58,18 @@ typedef union {
 } efhw_event_t;
 
 /* Flags for TX/RX queues */
-#define EFHW_VI_JUMBO_EN           0x01  /*! scatter RX over multiple desc */
-#define EFHW_VI_ISCSI_RX_HDIG_EN   0x02  /*! iscsi rx header digest */
-#define EFHW_VI_ISCSI_TX_HDIG_EN   0x04  /*! iscsi tx header digest */
-#define EFHW_VI_ISCSI_RX_DDIG_EN   0x08  /*! iscsi rx data digest */
-#define EFHW_VI_ISCSI_TX_DDIG_EN   0x10  /*! iscsi tx data digest */
-#define EFHW_VI_TX_PHYS_ADDR_EN    0x20  /*! TX physical address mode */
-#define EFHW_VI_RX_PHYS_ADDR_EN    0x40  /*! RX physical address mode */
-#define EFHW_VI_RM_WITH_INTERRUPT  0x80  /*! VI with an interrupt */
-#define EFHW_VI_TX_IP_CSUM_DIS     0x100 /*! enable ip checksum generation */
-#define EFHW_VI_TX_TCPUDP_CSUM_DIS 0x200 /*! enable tcp/udp checksum
-					   generation */
-#define EFHW_VI_TX_TCPUDP_ONLY     0x400 /*! drop non-tcp/udp packets */
+#define EFHW_VI_JUMBO_EN           0x01    /*! scatter RX over multiple desc */
+#define EFHW_VI_ISCSI_RX_HDIG_EN   0x02    /*! iscsi rx header digest */
+#define EFHW_VI_ISCSI_TX_HDIG_EN   0x04    /*! iscsi tx header digest */
+#define EFHW_VI_ISCSI_RX_DDIG_EN   0x08    /*! iscsi rx data digest */
+#define EFHW_VI_ISCSI_TX_DDIG_EN   0x10    /*! iscsi tx data digest */
+#define EFHW_VI_TX_PHYS_ADDR_EN    0x20    /*! TX physical address mode */
+#define EFHW_VI_RX_PHYS_ADDR_EN    0x40    /*! RX physical address mode */
+#define EFHW_VI_RM_WITH_INTERRUPT  0x80    /*! VI with an interrupt */
+#define EFHW_VI_TX_IP_CSUM_DIS     0x100   /*! enable ip checksum generation */
+#define EFHW_VI_TX_TCPUDP_CSUM_DIS 0x200   /*! enable tcp/udp checksum
+					       generation */
+#define EFHW_VI_TX_TCPUDP_ONLY     0x400   /*! drop non-tcp/udp packets */
 
 /* Types of hardware filter */
 /* Each of these values implicitly selects scatter filters on B0 - or in
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/common_sysdep.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/common_sysdep.h	2009-04-07 15:26:24.000000000 +0200
@@ -41,7 +41,6 @@
 #define __CI_EFHW_COMMON_LINUX_H__
 
 #include <linux/types.h>
-#include <linux/version.h>
 
 /* Dirty hack, but Linux kernel does not provide DMA_ADDR_T_FMT */
 #if BITS_PER_LONG == 64 || defined(CONFIG_HIGHMEM64G)
@@ -52,20 +51,11 @@
 
 /* Linux kernel also does not provide PRIx32... Sigh. */
 #define PRIx32 "x"
- 
+
 #ifdef __ia64__
 # define PRIx64 "lx"
 #else
 # define PRIx64 "llx"
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-enum {
-	false = 0,
-	true = 1
-};
-
-typedef _Bool bool;
-#endif /* LINUX_VERSION_CODE < 2.6.19 */
-
 #endif /* __CI_EFHW_COMMON_LINUX_H__ */
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/efhw_types.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/efhw_types.h	2009-04-07 15:14:23.000000000 +0200
@@ -86,6 +86,37 @@ struct efhw_keventq {
 	struct efhw_ev_handler *ev_handlers;
 };
 
+/*--------------------------------------------------------------------
+ *
+ * filters
+ *
+ *--------------------------------------------------------------------*/
+
+struct efhw_filter_spec {
+	uint dmaq_id;
+	uint32_t saddr_le32;
+	uint32_t daddr_le32;
+	uint16_t sport_le16;
+	uint16_t dport_le16;
+	unsigned tcp     : 1;
+	unsigned full    : 1;
+	unsigned rss     : 1;  /* not supported on A1 */
+	unsigned scatter : 1;  /* not supported on A1 */
+};
+
+struct efhw_filter_depth {
+	unsigned needed;
+	unsigned max;
+};
+
+struct efhw_filter_search_limits {
+	unsigned tcp_full;
+	unsigned tcp_wild;
+	unsigned udp_full;
+	unsigned udp_wild;
+};
+
+
 /**********************************************************************
  * Portable HW interface. ***************************************
  **********************************************************************/
@@ -131,7 +162,7 @@ struct efhw_func_ops {
 	/*! Set interrupt moderation strategy for the given IRQ unit
 	 ** val is in usec
 	 */
-	void (*set_interrupt_moderation)(struct efhw_nic *nic,
+	void (*set_interrupt_moderation)(struct efhw_nic *nic, int evq,
 					 uint val);
 
   /*-------------- Event support  ------------ */
@@ -144,7 +175,8 @@ struct efhw_func_ops {
 	void (*event_queue_enable) (struct efhw_nic *nic,
 				    uint evq,	/* evnt queue index */
 				    uint evq_size,	/* units of #entries */
-				    dma_addr_t q_base_addr, uint buf_base_id);
+				    dma_addr_t q_base_addr, uint buf_base_id,
+				    int interrupting);
 
 	/*! Disable the given event queue (and any associated timer) */
 	void (*event_queue_disable) (struct efhw_nic *nic, uint evq,
@@ -157,7 +189,7 @@ struct efhw_func_ops {
 	/*! Push a SW event on a given eventQ */
 	void (*sw_event) (struct efhw_nic *nic, int data, int evq);
 
-  /*-------------- Filter support  ------------ */
+  /*-------------- IP Filter API  ------------ */
 
 	/*! Setup a given filter - The software can request a filter_i,
 	 * but some EtherFabric implementations will override with
@@ -168,13 +200,6 @@ struct efhw_func_ops {
 			     unsigned saddr_be32, unsigned sport_be16,
 			     unsigned daddr_be32, unsigned dport_be16);
 
-	/*! Attach a given filter to a DMAQ */
-	void (*ipfilter_attach) (struct efhw_nic *nic, int filter_idx,
-				 int dmaq_idx);
-
-	/*! Detach a filter from its DMAQ */
-	void (*ipfilter_detach) (struct efhw_nic *nic, int filter_idx);
-
 	/*! Clear down a given filter */
 	void (*ipfilter_clear) (struct efhw_nic *nic, int filter_idx);
 
@@ -223,6 +248,14 @@ struct efhw_func_ops {
 	/*! Commit a buffer table update  */
 	void (*buffer_table_commit) (struct efhw_nic *nic);
 
+  /*-------------- New filter API ------------ */
+
+	/*! Set a given filter */
+	int (*filter_set) (struct efhw_nic *nic, struct efhw_filter_spec *spec,
+			   int *filter_idx_out);
+
+	/*! Clear a given filter */
+	void (*filter_clear) (struct efhw_nic *nic, int filter_idx);
 };
 
 
@@ -250,9 +283,7 @@ struct efhw_nic {
 	/*! zero base index in efrm_nic_tablep->nic array */
 	int index;
 	int ifindex;		/*!< OS level nic index */
-#ifdef HAS_NET_NAMESPACE
 	struct net *nd_net;
-#endif
 
 	struct efhw_device_type devtype;
 
@@ -268,7 +299,6 @@ struct efhw_nic {
 # define NIC_FLAG_TRY_MSI               0x02
 # define NIC_FLAG_MSI                   0x04
 # define NIC_FLAG_OS_IRQ_EN             0x08
-# define NIC_FLAG_10G                   0x10
 
 	unsigned mtu;		/*!< MAC MTU (includes MAC hdr) */
 
@@ -287,9 +317,6 @@ struct efhw_nic {
 	/*! EtherFabric Functional Units -- functions */
 	const struct efhw_func_ops *efhw_func;
 
-	/* Value read from FPGA version register.  Zero for asic. */
-	unsigned fpga_version;
-
 	/*! This lock protects a number of misc NIC resources.  It should
 	 * only be used for things that can be at the bottom of the lock
 	 * order.  ie. You mustn't attempt to grab any other lock while
@@ -326,8 +353,26 @@ struct efhw_nic {
 	unsigned rxq_sizes;
 	unsigned txq_sizes;
 
-	/* Size of filter table (including odd and even banks). */
-	unsigned filter_tbl_size;
+	/* Size of filter table. */
+	unsigned ip_filter_tbl_size;
+
+	/* Number of filters currently used */
+	unsigned ip_filter_tbl_used;
+
+	/* Dynamically allocated filter state. */
+	uint8_t *filter_in_use;
+	struct efhw_filter_spec *filter_spec_cache;
+
+	/* Currently required and maximum filter table search depths. */
+	struct efhw_filter_depth tcp_full_srch;
+	struct efhw_filter_depth tcp_wild_srch;
+	struct efhw_filter_depth udp_full_srch;
+	struct efhw_filter_depth udp_wild_srch;
+
+	/* Number of event queues, DMA queues and timers. */
+	unsigned num_evqs;
+	unsigned num_dmaqs;
+	unsigned num_timers;
 };
 
 
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/hardware_sysdep.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/hardware_sysdep.h	2009-04-07 15:16:30.000000000 +0200
@@ -40,7 +40,7 @@
 #ifndef __CI_EFHW_HARDWARE_LINUX_H__
 #define __CI_EFHW_HARDWARE_LINUX_H__
 
-#include <asm/io.h>
+#include <linux/io.h>
 
 #ifdef __LITTLE_ENDIAN
 #define EFHW_IS_LITTLE_ENDIAN
@@ -50,23 +50,6 @@
 #error Unknown endianness
 #endif
 
-#ifndef __iomem
-#define __iomem
-#endif
-
-#ifndef mmiowb
-	#if defined(__i386__) || defined(__x86_64__)
-		#define mmiowb()
-	#elif defined(__ia64__)
-		#ifndef ia64_mfa
-			#define ia64_mfa() asm volatile ("mf.a" ::: "memory")
-		#endif
-	#define mmiowb ia64_mfa
-	#else
-	#error "Need definition for mmiowb()"
-	#endif
-#endif
-
 #ifndef readq
 static inline uint64_t __readq(volatile void __iomem *addr)
 {
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/iopage_types.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/iopage_types.h	2009-04-07 15:27:46.000000000 +0200
@@ -39,13 +39,8 @@
 #ifndef __CI_EFHW_IOPAGE_LINUX_H__
 #define __CI_EFHW_IOPAGE_LINUX_H__
 
-#include <linux/version.h>
 #include <linux/gfp.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
 #include <linux/hardirq.h>
-#else
-#include <asm/hardirq.h>
-#endif
 #include <linux/errno.h>
 #include <ci/efhw/debug.h>
 
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/public.h	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/public.h	2009-04-07 15:02:05.000000000 +0200
@@ -70,11 +70,32 @@ int efhw_nic_event_queue_alloc_iobuffer(
 extern void falcon_nic_set_rx_usr_buf_size(struct efhw_nic *,
 					   int rx_usr_buf_size);
 
+/*! Get RX filter search limits from RX_FILTER_CTL_REG.
+ *  use_raw_values = 0 to get actual depth of search, or 1 to get raw values
+ *  from register.
+ */
+extern void
+falcon_nic_get_rx_filter_search_limits(struct efhw_nic *nic,
+				       struct efhw_filter_search_limits *lim,
+				       int use_raw_values);
+
+/*! Set RX filter search limits in RX_FILTER_CTL_REG.
+ *  use_raw_values = 0 if specifying actual depth of search, or 1 if specifying
+ *  raw values to write to the register.
+ */
+extern void
+falcon_nic_set_rx_filter_search_limits(struct efhw_nic *nic,
+				       struct efhw_filter_search_limits *lim,
+				       int use_raw_values);
+
+
+/*! Legacy RX IP filter search depth control interface */
 extern void
 falcon_nic_rx_filter_ctl_set(struct efhw_nic *nic, uint32_t tcp_full,
 			     uint32_t tcp_wild,
 			     uint32_t udp_full, uint32_t udp_wild);
 
+/*! Legacy RX IP filter search depth control interface */
 extern void
 falcon_nic_rx_filter_ctl_get(struct efhw_nic *nic, uint32_t *tcp_full,
 			     uint32_t *tcp_wild,
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efhw/sysdep.h	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efhw/sysdep.h	2009-04-07 15:02:05.000000000 +0200
@@ -39,34 +39,17 @@
 #ifndef __CI_EFHW_SYSDEP_LINUX_H__
 #define __CI_EFHW_SYSDEP_LINUX_H__
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include <linux/delay.h>
+#include <linux/vmalloc.h>
 #include <linux/if_ether.h>
 
 #include <linux/netdevice.h> /* necessary for etherdevice.h on some kernels */
 #include <linux/etherdevice.h>
 
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21)
-static inline int is_local_ether_addr(const u8 *addr)
-{
-	return (0x02 & addr[0]);
-}
-#endif
-
 typedef unsigned long irq_flags_t;
 
 #define spin_lock_destroy(l_)  do {} while (0)
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
-#define HAS_NET_NAMESPACE
-#endif
-
-/* Funny, but linux has round_up for x86 only, defined in
- * x86-specific header */
-#ifndef round_up
-#define round_up(x, y) (((x) + (y) - 1) & ~((y)-1))
-#endif
-
 #endif /* __CI_EFHW_SYSDEP_LINUX_H__ */
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efrm/nic_table.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efrm/nic_table.h	2009-04-07 15:28:15.000000000 +0200
@@ -76,7 +76,7 @@ static inline void efrm_nic_table_rele(v
 
 static inline int efrm_nic_table_held(void)
 {
-	return (atomic_read(&efrm_nic_tablep->ref_count) != 0);
+	return atomic_read(&efrm_nic_tablep->ref_count) != 0;
 }
 
 /* Run code block _x multiple times with variable nic set to each
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efrm/sysdep.h	2009-04-07 14:39:57.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efrm/sysdep.h	2009-04-07 15:02:05.000000000 +0200
@@ -41,14 +41,6 @@
 /* Spinlocks are defined in efhw/sysdep.h */
 #include <ci/efhw/sysdep.h>
 
-#if defined(__linux__) && defined(__KERNEL__)
-
-# include <ci/efrm/sysdep_linux.h>
-
-#else
-
-# include <ci/efrm/sysdep_ci2linux.h>
-
-#endif
+#include <ci/efrm/sysdep_linux.h>
 
 #endif /* __CI_EFRM_SYSDEP_H__ */
--- head-2009-04-07.orig/drivers/xen/sfc_netback/ci/efrm/sysdep_linux.h	2009-04-07 13:58:48.000000000 +0200
+++ head-2009-04-07/drivers/xen/sfc_netback/ci/efrm/sysdep_linux.h	2009-04-07 15:28:24.000000000 +0200
@@ -42,7 +42,6 @@
 #ifndef __CI_EFRM_SYSDEP_LINUX_H__
 #define __CI_EFRM_SYSDEP_LINUX_H__
 
-#include <linux/version.h>
 #include <linux/list.h>
 #include <linux/vmalloc.h>
 #include <linux/errno.h>
@@ -50,34 +49,13 @@
 #include <linux/workqueue.h>
 #include <linux/gfp.h>
 #include <linux/slab.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,9)
 #include <linux/hardirq.h>
-#else
-#include <asm/hardirq.h>
-#endif
 #include <linux/kernel.h>
 #include <linux/if_ether.h>
 #include <linux/completion.h>
 #include <linux/in.h>
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
-/* get roundup_pow_of_two(), which was in kernel.h in early kernel versions */
 #include <linux/log2.h>
-#endif
-
-
-/********************************************************************
- *
- * Utility functions
- *
- ********************************************************************/
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
-static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x)
-{
-        return (1UL << fls(x - 1));
-}
-#endif
+#include <linux/kfifo.h>
 
 
 /********************************************************************
@@ -85,17 +63,6 @@ static inline unsigned long __attribute_
  * List API
  *
  ********************************************************************/
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
-static inline void
-list_replace_init(struct list_head *old, struct list_head *new)
-{
-	new->next = old->next;
-	new->next->prev = new;
-	new->prev = old->prev;
-	new->prev->next = new;
-	INIT_LIST_HEAD(old);
-}
-#endif
 
 static inline struct list_head *list_pop(struct list_head *list)
 {
@@ -113,151 +80,10 @@ static inline struct list_head *list_pop
 
 /********************************************************************
  *
- * Workqueue API
- *
- ********************************************************************/
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
-#define NEED_OLD_WORK_API
-
-/**
- * The old and new work function prototypes just change
- * the type of the pointer in the only argument, so it's
- * safe to cast one function type to the other
- */
-typedef void (*efrm_old_work_func_t) (void *p);
-
-#undef INIT_WORK
-#define INIT_WORK(_work, _func)					\
-	do {							\
-		INIT_LIST_HEAD(&(_work)->entry);		\
-		(_work)->pending = 0;				\
-		PREPARE_WORK((_work),				\
-			     (efrm_old_work_func_t) (_func),	\
-			     (_work));				\
-	} while (0)
-
-#endif
-
-/********************************************************************
- *
  * Kfifo API
  *
  ********************************************************************/
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
-
-#if !defined(RHEL_RELEASE_CODE) || (RHEL_RELEASE_CODE < 1029)
-typedef unsigned gfp_t;
-#endif
-
-#define HAS_NO_KFIFO
-
-struct kfifo {
-	unsigned char *buffer;	/* the buffer holding the data */
-	unsigned int size;	/* the size of the allocated buffer */
-	unsigned int in;	/* data is added at offset (in % size) */
-	unsigned int out;	/* data is extracted from off. (out % size) */
-	spinlock_t *lock;	/* protects concurrent modifications */
-};
-
-extern struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size,
-				gfp_t gfp_mask, spinlock_t *lock);
-extern struct kfifo *kfifo_alloc(unsigned int size, gfp_t gfp_mask,
-				 spinlock_t *lock);
-extern void kfifo_free(struct kfifo *fifo);
-extern unsigned int __kfifo_put(struct kfifo *fifo,
-				unsigned char *buffer, unsigned int len);
-extern unsigned int __kfifo_get(struct kfifo *fifo,
-				unsigned char *buffer, unsigned int len);
-
-/**
- * kfifo_put - puts some data into the FIFO
- * @fifo: the fifo to be used.
- * @buffer: the data to be added.
- * @len: the length of the data to be added.
- *
- * This function copies at most @len bytes from the @buffer into
- * the FIFO depending on the free space, and returns the number of
- * bytes copied.
- */
-static inline unsigned int
-kfifo_put(struct kfifo *fifo, unsigned char *buffer, unsigned int len)
-{
-	unsigned long flags;
-	unsigned int ret;
-
-	spin_lock_irqsave(fifo->lock, flags);
-
-	ret = __kfifo_put(fifo, buffer, len);
-
-	spin_unlock_irqrestore(fifo->lock, flags);
-
-	return ret;
-}
-
-/**
- * kfifo_get - gets some data from the FIFO
- * @fifo: the fifo to be used.
- * @buffer: where the data must be copied.
- * @len: the size of the destination buffer.
- *
- * This function copies at most @len bytes from the FIFO into the
- * @buffer and returns the number of copied bytes.
- */
-static inline unsigned int
-kfifo_get(struct kfifo *fifo, unsigned char *buffer, unsigned int len)
-{
-	unsigned long flags;
-	unsigned int ret;
-
-	spin_lock_irqsave(fifo->lock, flags);
-
-	ret = __kfifo_get(fifo, buffer, len);
-
-	/*
-	 * optimization: if the FIFO is empty, set the indices to 0
-	 * so we don't wrap the next time
-	 */
-	if (fifo->in == fifo->out)
-		fifo->in = fifo->out = 0;
-
-	spin_unlock_irqrestore(fifo->lock, flags);
-
-	return ret;
-}
-
-/**
- * __kfifo_len - returns the number of bytes available in the FIFO, no locking version
- * @fifo: the fifo to be used.
- */
-static inline unsigned int __kfifo_len(struct kfifo *fifo)
-{
-	return fifo->in - fifo->out;
-}
-
-/**
- * kfifo_len - returns the number of bytes available in the FIFO
- * @fifo: the fifo to be used.
- */
-static inline unsigned int kfifo_len(struct kfifo *fifo)
-{
-	unsigned long flags;
-	unsigned int ret;
-
-	spin_lock_irqsave(fifo->lock, flags);
-
-	ret = __kfifo_len(fifo);
-
-	spin_unlock_irqrestore(fifo->lock, flags);
-
-	return ret;
-}
-
-#else
-#include <linux/kfifo.h>
-#endif
-
 static inline void kfifo_vfree(struct kfifo *fifo)
 {
 	vfree(fifo->buffer);
