Skip to contentSkip to conversation

tehuti: driver for Tehuti 10GbE network adapters

PATCH In review Andy Gospodarek 5 participants 11 messages Sep 11, 2007 – Sep 19, 2007

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tehuti: driver for Tehuti 10GbE network adapters

This introduces support for a line of 10GbE adapters made by Tehuti Networks. An attempt to get this included was made a few months ago and since the driver has been re-factored based on Jeff's suggestions.

You can download a patch against Jeff's netdev-2.6#upstream tree here:

http://git.greyhouse.net/gospo/tehuti-netdev-26-upstream.patch

and I setup a git tree last night based off Linus' tree. You can sync with that here if you like:

http://git.greyhouse.net/gospo/tehuti-2.6.git

This driver is in good enough shape to go into at least Jeff's tree and we can make fixes as they are needed. I'm not convinced all endian issues are completely flushed out and there are few more ethtool ops that could be implemented, but they don't seem to prevent basic card functionality on my systems.

#1 lore raw
Quoted 5 lines · Andy Gospodarek

This introduces support for a line of 10GbE adapters made by Tehuti Networks. An attempt to get this included was made a few months ago and since the driver has been re-factored based on Jeff's suggestions.

Quoted 9 lines

You can download a patch against Jeff's netdev-2.6#upstream tree here:

http://git.greyhouse.net/gospo/tehuti-netdev-26-upstream.patch

and I setup a git tree last night based off Linus' tree. You can sync with that here if you like:

http://git.greyhouse.net/gospo/tehuti-2.6.git

I moved this to:

git://git.greyhouse.net/gospo/tehuti-2.6.git

since I got some complaints that the http-based git tree wasn't working well.

#2 lore raw
Quoted 15 lines · Andy Gospodarek
Quoted 4 lines · Andy Gospodarek

This introduces support for a line of 10GbE adapters made by Tehuti Networks. An attempt to get this included was made a few months ago and since the driver has been re-factored based on Jeff's suggestions.

Quoted 9 lines

You can download a patch against Jeff's netdev-2.6#upstream tree here:

http://git.greyhouse.net/gospo/tehuti-netdev-26-upstream.patch

and I setup a git tree last night based off Linus' tree. You can sync with that here if you like:

http://git.greyhouse.net/gospo/tehuti-2.6.git

Quoted 6 lines

I moved this to:

git://git.greyhouse.net/gospo/tehuti-2.6.git

since I got some complaints that the http-based git tree wasn't working well.

Maybe you forgot git-update-server-info, after pushing ?

Jeff

#3 lore raw
In reply to Andy Gospodarek

erp, changes in the net-2.6.24 tree breaks this.

drivers/net/tehuti.c: In function 'bdx_isr_napi':
drivers/net/tehuti.c:268: error: too few arguments to function 'netif_rx_schedule_prep' drivers/net/tehuti.c:269: error: too few arguments to function '__netif_rx_schedule' drivers/net/tehuti.c: In function 'bdx_poll':
drivers/net/tehuti.c:302: error: too few arguments to function 'netif_rx_complete' drivers/net/tehuti.c: In function 'bdx_hw_start':
drivers/net/tehuti.c:414: error: implicit declaration of function 'netif_poll_enable' drivers/net/tehuti.c: In function 'bdx_hw_stop':
drivers/net/tehuti.c:428: error: implicit declaration of function 'netif_poll_disable' drivers/net/tehuti.c: In function 'bdx_rx_receive':
drivers/net/tehuti.c:1219: error: 'struct net_device' has no member named 'quota' drivers/net/tehuti.c:1219: warning: type defaults to 'int' in declaration of '_y' drivers/net/tehuti.c:1219: error: 'struct net_device' has no member named 'quota' drivers/net/tehuti.c:1311: error: 'struct net_device' has no member named 'quota' drivers/net/tehuti.c: In function 'bdx_probe':
drivers/net/tehuti.c:1994: error: 'struct net_device' has no member named 'poll' drivers/net/tehuti.c:1995: error: 'struct net_device' has no member named 'weight' drivers/net/tehuti.c:2058: error: implicit declaration of function 'SET_MODULE_OWNER'

There's a lot of churn in networking at present and I don't have time/inclination to fix this one up, sorry.

#4 lore raw

Andrew,

Please try following patches which should be compatible with net-2.6.24 tree.
Full patch is against net-2.6.24 tree.
Diff patch is delta from previous submission.

Please let us know how it works for you.

Thank you,
Alexander Indenbaum

Quoted 41 lines

-----Original Message-----
From: Andrew Morton [mailto:[email protected]]
Sent: Sunday, September 16, 2007 11:15 PM
To: Andy Gospodarek
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] tehuti: driver for Tehuti 10GbE network adapters

erp, changes in the net-2.6.24 tree breaks this.

drivers/net/tehuti.c: In function 'bdx_isr_napi':
drivers/net/tehuti.c:268: error: too few arguments to function 'netif_rx_schedule_prep'
drivers/net/tehuti.c:269: error: too few arguments to function '__netif_rx_schedule'
drivers/net/tehuti.c: In function 'bdx_poll':
drivers/net/tehuti.c:302: error: too few arguments to function 'netif_rx_complete'
drivers/net/tehuti.c: In function 'bdx_hw_start':
drivers/net/tehuti.c:414: error: implicit declaration of function 'netif_poll_enable'
drivers/net/tehuti.c: In function 'bdx_hw_stop':
drivers/net/tehuti.c:428: error: implicit declaration of function 'netif_poll_disable'
drivers/net/tehuti.c: In function 'bdx_rx_receive':
drivers/net/tehuti.c:1219: error: 'struct net_device' has no member named 'quota'
drivers/net/tehuti.c:1219: warning: type defaults to 'int' in declaration of '_y'
drivers/net/tehuti.c:1219: error: 'struct net_device' has no member named 'quota'
drivers/net/tehuti.c:1311: error: 'struct net_device' has no member named 'quota'
drivers/net/tehuti.c: In function 'bdx_probe':
drivers/net/tehuti.c:1994: error: 'struct net_device' has no member named 'poll'
drivers/net/tehuti.c:1995: error: 'struct net_device' has no member named 'weight'
drivers/net/tehuti.c:2058: error: implicit declaration of function 'SET_MODULE_OWNER'

Quoted 3 lines

There's a lot of churn in networking at present and I don't have time/inclination
to fix this one up, sorry.

tehuti.c +20 -21
Index: tehuti.c
===================================================================
@@ -77,7 +77,7 @@
 /* Definitions needed by ISR or NAPI functions */
 static void bdx_rx_alloc_skbs(struct bdx_priv *priv, struct rxf_fifo *f);
 static void bdx_tx_cleanup(struct bdx_priv *priv);
-static int bdx_rx_receive(struct bdx_priv *priv, struct rxd_fifo *f, int *budget);
+static int bdx_rx_receive(struct bdx_priv *priv, struct rxd_fifo *f, int budget);
 
 /* Definitions needed by FW loading */
 static void bdx_tx_push_desc_safe(struct bdx_priv *priv, void *data, int size);
@@ -85,6 +85,8 @@
 /* Definitions needed by hw_start */
 static int bdx_tx_init(struct bdx_priv *priv);
 static int bdx_rx_init(struct bdx_priv *priv);
+static void bdx_setmulti(struct net_device *ndev);
+static void bdx_reload_vlan(struct net_device *ndev);
 
 /* Definitions needed by bdx_close */
 static void bdx_rx_free(struct bdx_priv *priv);
@@ -265,8 +267,8 @@
 		bdx_isr_extra(priv, isr);
 
 	if (isr & (IR_RX_DESC_0 | IR_TX_FREE_0)) {
-		if (likely(netif_rx_schedule_prep(ndev))) {
-			__netif_rx_schedule(ndev);
+		if (likely(netif_rx_schedule_prep(ndev, &priv->napi))) {
+			__netif_rx_schedule(ndev, &priv->napi);
 			RET(IRQ_HANDLED);
 		} else {
 			/* NOTE: we get here if intr has slipped into window
@@ -286,24 +288,26 @@
 	RET(IRQ_HANDLED);
 }
 
-static int bdx_poll(struct net_device *ndev, int *budget)
+static int bdx_poll(struct napi_struct *napi, int budget)
 {
-	struct bdx_priv *priv = ndev->priv;
+	struct bdx_priv *priv = container_of(napi, struct bdx_priv, napi);
+	struct net_device *ndev = priv->ndev;
+	int work_done = 0;
 	ENTER;
 	bdx_tx_cleanup(priv);
-	if (!bdx_rx_receive(priv, &priv->rxd_fifo0, budget)
-	    || (priv->napi_stop++ >= 30)) {
+	work_done = bdx_rx_receive(priv, &priv->rxd_fifo0, budget);
+	if ((work_done == 0) || (priv->napi_stop++ >= 30)) {
 		DBG("rx poll is done. backing to isr-driven\n");
 
 		/* from time to time we exit to let NAPI layer release
 		 * device lock and allow waiting tasks (eg rmmod) to advance) */
 		priv->napi_stop = 0;
 
-		netif_rx_complete(ndev);
+		netif_rx_complete(ndev, napi);
 		bdx_enable_interrupts(priv);
 		return 0;
 	}
-	return 1;
+	return work_done;
 }
 
 /* bdx_fw_load - loads firmware to NIC
@@ -413,7 +417,7 @@
 		goto err_irq;
 	bdx_enable_interrupts(priv);
 
-	netif_poll_enable(priv->ndev);
+	napi_enable(&priv->napi);
 
 	RET(0);
 
@@ -427,7 +431,7 @@
 	bdx_disable_interrupts(priv);
 	free_irq(priv->pdev->irq, priv->ndev);
 
-	netif_poll_disable(priv->ndev);
+	napi_disable(&priv->napi);
 	netif_carrier_off(priv->ndev);
 	netif_stop_queue(priv->ndev);
 
@@ -1231,7 +1235,7 @@
 
 /* TBD: replace memcpy func call by explicite inline asm */
 
-static int bdx_rx_receive(struct bdx_priv *priv, struct rxd_fifo *f, int *budget)
+static int bdx_rx_receive(struct bdx_priv *priv, struct rxd_fifo *f, int budget)
 {
 	struct sk_buff *skb, *skb2;
 	struct rxd_desc *rxdd;
@@ -1239,7 +1243,6 @@
 	struct rxf_fifo *rxf_fifo;
 	int tmp_len, size;
 	int done = 0;
-	int max_done = BDX_MAX_RX_DONE;
 	struct rxdb *db = NULL;
 	/* Unmarshalled descriptor - copy of descriptor in host order */
 	u32 rxd_val1;
@@ -1247,7 +1250,6 @@
 	u16 rxd_vlan;
 
 	ENTER;
-	max_done = min(*budget, priv->ndev->quota);
 
 	priv->ndev->last_rx = jiffies;
 	f->m.wptr = READ_REG(priv, f->m.reg_WPTR) & TXF_WPTR_WR_PTR;
@@ -1327,7 +1329,7 @@
 
 		NETIF_RX_MUX(priv, rxd_val1, rxd_vlan, skb);
 
-		if (++done >= max_done)
+		if (++done >= budget)
 			break;
 	}
 
@@ -1338,9 +1340,7 @@
 
 	bdx_rx_alloc_skbs(priv, &priv->rxf_fifo0);
 
-	*budget -= done;
-	priv->ndev->quota -= done;
-	RET(done == max_done);
+	return done;
 }
 
 /*************************************************************************
@@ -2022,8 +2022,6 @@
 		ndev->vlan_rx_register = bdx_vlan_rx_register;
 		ndev->vlan_rx_add_vid = bdx_vlan_rx_add_vid;
 		ndev->vlan_rx_kill_vid = bdx_vlan_rx_kill_vid;
-		ndev->poll = bdx_poll;
-		ndev->weight = 64;
 
 		bdx_ethtool_ops(ndev);	/* ethtool interface */
 
@@ -2081,12 +2079,13 @@
 #endif
 		spin_lock_init(&priv->tx_lock);
 
+		netif_napi_add(ndev, &priv->napi, bdx_poll, 64);
+
 		/*bdx_hw_reset(priv); */
 		if (bdx_read_mac(priv)) {
 			printk(KERN_ERR "tehuti: load MAC address failed\n");
 			goto err_out_iomap;
 		}
-		SET_MODULE_OWNER(ndev);
 		SET_NETDEV_DEV(ndev, &pdev->dev);
 		if ((err = register_netdev(ndev))) {
 			printk(KERN_ERR "tehuti: register_netdev failed\n");
tehuti.h +1 -0
Index: tehuti.h
===================================================================
@@ -251,6 +251,7 @@
 	void __iomem *pBdxRegs;
 	struct net_device *ndev;
 
+	struct napi_struct		napi;
 	/* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
 	struct rxd_fifo rxd_fifo0;
 	struct rxf_fifo rxf_fifo0;
MAINTAINERS +8 -0
index 5f26583..36baa9c 100644
@@ -3620,6 +3620,14 @@ M:	[email protected]
 W:	http://tcp-lp-mod.sourceforge.net/
 S:	Maintained
 
+TEHUTI ETHERNET DRIVER
+P:	Alexander Indenbaum
+M:	[email protected]
+P:	Andy Gospodarek
+M:	[email protected]
+L:	[email protected]
+S:	Supported
+
 TI FLASH MEDIA INTERFACE DRIVER
 P:      Alex Dubov
 M:      [email protected]
drivers/net/Kconfig +6 -0
index 1c8ef44..a8f7600 100644
@@ -2565,6 +2565,12 @@ config MLX4_DEBUG
 	  debug_level module parameter (which can also be set after
 	  the driver is loaded through sysfs).
 
+config TEHUTI
+	tristate "Tehuti Networks 10G Ethernet"
+	depends on PCI
+	help
+	  Tehuti Networks 10G Ethernet NIC
+
 endif # NETDEV_10000
 
 source "drivers/net/tokenring/Kconfig"
drivers/net/Makefile +1 -0
index ff4dbca..6c381ba 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_E1000E) += e1000e/
 obj-$(CONFIG_IBM_EMAC) += ibm_emac/
 obj-$(CONFIG_IXGBE) += ixgbe/
 obj-$(CONFIG_IXGB) += ixgb/
+obj-$(CONFIG_TEHUTI) += tehuti/
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
drivers/net/tehuti/tehuti.c new file +2542 -0

2,542 lines not on this page · raw message

drivers/net/tehuti/tehuti.h new file +563 -0

282 lines not on this page · raw message

drivers/net/tehuti/tehuti_fw.h new file +10712 -0

10,712 lines not on this page · raw message

include/linux/pci_ids.h +5 -0
index 55f307f..785c4d8 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#5 lore raw
In reply to Andy Gospodarek

Some comment from looking at the driver in the -mm tree:

- please kill the CPU_CHIP_SWAP macros and use the normal linux cpu_to_le*/le*_to_cpu and verify them using sparse. See Documentation/sparse.txt on how to do that
- please include the linux header in the .c file, not the .h
- please don't redefine the dma mask constants
- please use the firmware loader instead of mebedding a firmware image
- please don't invent your own debugging macros but use dev_dbg and friends
- please kill the ENTER/RET macros
- please kill BDX_ASSERT
- the unregister_netdev directly followed by free_netdev in bdx_remove look buggy, but I'm not entirely sure how to handle multi-port devices properly here.
- please declare bdx_ethtool_ops on file-scope and kill bdx_ethtool_ops
- please don't put assignments into conditionals ala

	if ((err = pci_request_regions(pdev, BDX_DRV_NAME)))
		goto err_dma;

but rather write

	err = pci_request_regions(pdev, BDX_DRV_NAME);
	if (err)
		goto err_dma;
#6 lore raw

Christoph,

Thank you for reviewing the driver and giving us this feedback. Our goal is the driver which is in full accordance with all Linux kernel style guidelines. Please note the fist Tehuti driver submission to netdev was by Andy on Mars 15 and since the driver has been heavily re-factored based on Jeff's suggestions. I agree with most of your style remarks and we'll release the patch soon.

Meanwhile let me ask clarification about two of your remarks bellow that I'm not sure I fully understand.

Quoted 11 lines

-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Tuesday, September 18, 2007 11:47 AM
To: Andy Gospodarek
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] tehuti: driver for Tehuti 10GbE network adapters

Some comment from looking at the driver in the -mm tree:

Quoted 7 lines

- please kill the CPU_CHIP_SWAP macros and use the normal linux cpu_to_le*/le*_to_cpu and verify them using sparse. See Documentation/sparse.txt on how to do that
- please include the linux header in the .c file, not the .h
- please don't redefine the dma mask constants
- please use the firmware loader instead of mebedding a firmware image

Could you give us some pointers to docs and examples of "firmware loader"? I'm not sure I'm familiar with such mechanism in Linux kernel.

Quoted 7 lines

- please don't invent your own debugging macros but use dev_dbg and friends
- please kill the ENTER/RET macros
- please kill BDX_ASSERT
- the unregister_netdev directly followed by free_netdev in bdx_remove look buggy, but I'm not entirely sure how to handle multi-port devices properly here.

Putting dual-port issue aside, could you elaborate what is the problem in your opinion in bdx_remove() implementation? What is wrong with calling free_netdev() right after unregister_netdev()? Could you provide pointers for docs and examples to correct PCI network device remove interface implementation?

Quoted 4 lines

- please declare bdx_ethtool_ops on file-scope and kill bdx_ethtool_ops
- please don't put assignments into conditionals ala

Quoted 8 lines
	if ((err = pci_request_regions(pdev, BDX_DRV_NAME)))
		goto err_dma;
   but rather write

	err = pci_request_regions(pdev, BDX_DRV_NAME);
	if (err)
		goto err_dma;

Thank you again for your help,
Alexander Indenbaum

#7 lore raw
Quoted 6 lines · Alexander Indenbaum
Quoted 3 lines

- please don't redefine the dma mask constants
- please use the firmware loader instead of mebedding a firmware image

Could you give us some pointers to docs and examples of "firmware loader"? I'm not sure I'm familiar with such mechanism in Linux kernel.

Documentation/firmware_class/ in the kernel tree has the documentation for it. Grep the kernel tree for request_firmware to find various users.

Quoted 5 lines

Putting dual-port issue aside, could you elaborate what is the problem in your opinion in bdx_remove() implementation? What is wrong with calling free_netdev() right after unregister_netdev()? Could you provide pointers for docs and examples to correct PCI network device remove interface implementation?

free_netdev can only be called if you're sure you don't reference your netdevice anymore. Most notably that means you need to call free_irq first.

#8 lore raw
Quoted 8 lines

-----Original Message-----
From: 'Christoph Hellwig' [mailto:[email protected]]
Sent: Wednesday, September 19, 2007 5:53 PM

Quoted 1 line

Putting dual-port issue aside, could you elaborate what is the problem

in

Quoted 2 lines

your opinion in bdx_remove() implementation? What is wrong with calling free_netdev() right after unregister_netdev()? Could you provide

Quoted 7 lines

pointers

Quoted 2 lines

for docs and examples to correct PCI network device remove interface implementation?

free_netdev can only be called if you're sure you don't reference your netdevice anymore. Most notably that means you need to call free_irq first.

In my understanding unregister_netdev(), in case netdev is still IFF_UP and holds irq, will call dev_close() which will call netdev->stop(), bdx_close() in our case. bdx_close() releases all netdev resources among others calls free_irq().

That's why I'm pretty sure that we do not hold any reference to netdev after unregister_netdev() finishes and we can free_netdev() without any worry :)

What do you think, does it still look fishy?

Alexander Indenbaum

#9 lore raw
Quoted 9 lines · Alexander Indenbaum

In my understanding unregister_netdev(), in case netdev is still IFF_UP and holds irq, will call dev_close() which will call netdev->stop(), bdx_close() in our case. bdx_close() releases all netdev resources among others calls free_irq().

That's why I'm pretty sure that we do not hold any reference to netdev after unregister_netdev() finishes and we can free_netdev() without any worry :)

What do you think, does it still look fishy?

Ok, so you do irq acquire/release in open/close so that bit is fine. The code might actually work as is, sorry for the noise.

#10 lore raw
Quoted 3 lines

Ok, so you do irq acquire/release in open/close so that bit is fine. The code might actually work as is, sorry for the noise.

It is no noise at all. Thank you for your feedback.