Skip to contentSkip to conversation

gianfar ethernet driver

RFR Jeff Garzik 3 participants 5 messages Jul 5, 2004 – Jul 9, 2004 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

(CC to netdev added)

Kumar,

I've merged the gianfar driver into my netdev-2.6 queue. This will get it automatically propagated into the -mm tree, and once some of these comments are resolved/discussed, pushed upstream as well.

Follow-up patches should be incremental to this (your) patch.

Others,

I've attached the patch as Kumar submitted it. Please review.

Comments:

1) Share the knowledge. Please CC comments (and criticisms!) to netdev.

2) I'm strongly pondering vetoing try_fastroute() code in this driver. Surely this should be in core net stack code... if it isn't already? Jamal?

3) delete this

+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,41)
+#define irqreturn_t void
+#define IRQ_HANDLED
+#endif

4) static? const?

+#define DEVICE_NAME "%s: Gianfar Ethernet Controller Version 1.0, " +char gfar_driver_name[] = "Gianfar Ethernet";
+char gfar_driver_version[] = "1.0";

5) Probably want to define DRV_NAME like the other drivers do. It's used in data bus, i/o region reservation, and ethtool ioctls at least.

6) sysfs support: call SET_NETDEV_DEV()

7) ethtool_ops should not be kmalloc'd.

+ dev_ethtool_ops =
+ (struct ethtool_ops *)kmalloc(sizeof(struct ethtool_ops),
+ GFP_KERNEL);

8) I recommend enabling _both_ hardware interrupt coalescing and NAPI, at the same time. Several other Linux net drivers need to be changed to do this, as well

9) in startup_gfar() you kmalloc() then dma-map the descriptors. don't bother -- just alloc consistent/coherent DMA memory.

10) recommend assigning a constant for your phy timer interval

+               init_timer(&priv->phy_info_timer);
+               priv->phy_info_timer.function = &gfar_phy_timer;
+               priv->phy_info_timer.data = (unsigned long) dev;
+               mod_timer(&priv->phy_info_timer, jiffies + 2 * HZ);

rather than open-coding it.

11) this is ugly. do the casting on the other end, in the work function:

+ /* Set up the bottom half queue */
+ INIT_WORK(&priv->tq, (void (*)(void *))gfar_phy_change, dev);

12) the above "bottom half" comment, or the code's intent, is incorrect. bottom halves more closely map to tasklet. however, slow-path phy
manipulation certainly lends itself to process context workqueues.

13) use of a wait queue rxcleanupq is fairly questionable.

14) surely gfar_set_mac_address() needs some sort of synchronization?

15) gfar_change_mtu() synchronization appears absent?

16) in gfar_timeout(), proper behavior is to call netif_wake_queue() unconditionally, if you are assured that your stop/startup_gfar() cleared the TX queue (including dropping any pending skbs).

17) some drivers choose to simply schedule_work() when dev->tx_timeout() is fired, to move the error handling/reset tasks to process context.

18) As Jamal recently noted, no need to test netif_queue_stopped()

19) I think your gfar_poll() needs spin_lock_irqsave(), not spin_lock().

20) You should ALWAYS have a work limit, NAPI or no. Otherwise under heavy load the non-NAPI driver will be doing nothing but sitting (shitting?) in your driver's interrupt handler.

+#ifdef CONFIG_GFAR_NAPI
+#define GFAR_RXDONE() ((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0)) +#else
+#define GFAR_RXDONE() (bdp->status & RXBD_EMPTY)
+#endif

21) a la #12, buggy comment:

+ /* Schedule the bottom half */
+ schedule_work(&priv->tq);

22) use msleep()

+ /* Delay to give the PHY a chance to change the
+ * register state */
+ set_current_state(TASK_UNINTERRUPTIBLE);
+ schedule_timeout(timeout);

23) gfar_set_multi() does not appear to take into account huge multi-cast lists. Drivers usually handle large dev->mc_count by falling back to ALLMULTI behavior.

24) setting IFF_MULTICAST is suspicious at best, possibly wrong:

+       dev->mtu = 1500;
+       dev->set_multicast_list = gfar_set_multi;
+       dev->flags |= IFF_MULTICAST;

+

25) kill this

+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,41)
+#include <linux/workqueue.h>
+#else
+#include <linux/tqueue.h>
+#define work_struct tq_struct
+#define schedule_work schedule_task
+#endif

26) stat_gstrings[] are _not_ human-readable strings, but easily machine-parseable keys. For example,

	"tx&rx 1024-1518B frames"
should be
	"tx-rx-1024-1518-frames"

or somesuch. Kill spaces, punctuation, capital letters, etc. Make it look more like a C identifier.

27) as mentioned in #4/#5, the following is incorrect. The driver name is not an advertisement, it is the short Unix name associated with this driver.

+void gfar_gdrvinfo(struct net_device *dev, struct
+ ethtool_drvinfo *drvinfo)
+{
+ strncpy(drvinfo->driver, gfar_driver_name, GFAR_INFOSTR_LEN);
+ strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);

28) I see you support register dump (good!), now please send the register-pretty-print patch to the ethtool package :)

29) kill gfar_get_link(). you use netif_carrier_{on,off} (good!), so you should use the default ethtool_op_get_link()

30) use include/linux/mii.h where possible. Add GMII-related defines if necessary.

31) infinite loops, particularly on 1-bits, are discouraged:

+ /* Wait for the transaction to finish */
+ while (gfar_read(&regbase->miimind) & (MIIMIND_NOTVALID | MIIMIND_BUSY))
+ cpu_relax();

32) gianfar_phy.c needs to be netdev_priv()-ized like the other parts of the driver

33) merge-stopper: mii_parse_sr(). never wait for autonegotiation to complete. it is an asynchronous operation that could exceed 30 seconds.

34) merge-stopper: dm9161_wait(). same thing as #33.

35) liberally borrow code and ideas from Ben H's sungem_phy.c. Eventually we want to move to a generic phy module.

drivers/net/Kconfig +11 -0
diff -Nru a/drivers/net/Kconfig b/drivers/net/Kconfig
@@ -2111,6 +2111,17 @@
 	  To compile this driver as a module, choose M here: the module
 	  will be called tg3.  This is recommended.
 
+config GIANFAR
+	tristate "Gianfar Ethernet"
+	depends on 85xx
+	help
+	  This driver supports the Gigabit TSEC on the MPC85xx 
+	  family of chips, and the FEC on the 8540
+
+config GFAR_NAPI
+	bool "NAPI Support"
+	depends on GIANFAR
+
 endmenu
 
 #
drivers/net/Makefile +1 -0
diff -Nru a/drivers/net/Makefile b/drivers/net/Makefile
@@ -10,6 +10,7 @@
 obj-$(CONFIG_IBM_EMAC) += ibm_emac/
 obj-$(CONFIG_IXGB) += ixgb/
 obj-$(CONFIG_BONDING) += bonding/
+obj-$(CONFIG_GIANFAR) += gianfar.o gianfar_ethtool.o gianfar_phy.o
 
 #
 # link order important here
drivers/net/gianfar.c new file +1921 -0

1,921 lines not on this page · raw message

drivers/net/gianfar.h new file +537 -0

537 lines not on this page · raw message

drivers/net/gianfar_ethtool.c new file +484 -0

484 lines not on this page · raw message

drivers/net/gianfar_phy.c new file +504 -0

34 lines not on this page · raw message

drivers/net/gianfar_phy.h new file +192 -0

192 lines not on this page · 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.

#2 lore raw
Quoted 11 lines · Jeff Garzik

(CC to netdev added)

Kumar,

I've merged the gianfar driver into my netdev-2.6 queue. This will get it automatically propagated into the -mm tree, and once some of these comments are resolved/discussed, pushed upstream as well.

Follow-up patches should be incremental to this (your) patch.

Quoted 7 lines

Others,

I've attached the patch as Kumar submitted it. Please review.

Comments:

Some pretty good comments there Jeff.

Quoted 4 lines

1) Share the knowledge. Please CC comments (and criticisms!) to netdev.

2) I'm strongly pondering vetoing try_fastroute() code in this driver. Surely this should be in core net stack code... if it isn't already? Jamal?

I hardly know anybody still using this interface - i believe it is not useful after NAPI; maybe this comment would bring out some of the believers out of the woodwork to comment.
Otherwise i would say kill it.

Quoted 3 lines

8) I recommend enabling _both_ hardware interrupt coalescing and NAPI, at the same time. Several other Linux net drivers need to be changed to do this, as well

Under low rates having both helps (by reducing the amount of PCI operations - at the expense of some added latency)

Quoted 2 lines

18) As Jamal recently noted, no need to test netif_queue_stopped()

Since it is a new driver why dont we have him do more work? <evil grin here, should that be followed by a loud eerie muhahahaha?> ;->

1) The check (in gfar_start_xmit()):

Should happen much sooner - i.e before the skb is touched.

if (txbdp == priv->dirty_tx) {
	netif_stop_queue(dev)
	unlock
	return 1;
}

The rest of your code goes here ..

Do this before the skb is touched. Note the return 1. This means dont add it to your priv->tx_skbuff[priv->skb_curtx] = skb before you do this.
Dont understand why you have your own proivate list btw.

2) Also its pretty scary if you are doing:
txbdp->status |= TXBD_INTERRUPT for every packet. Look at other drivers, they try to do this every few packets; or enable tx mitigation to slow the rate of those interupts.

cheers,
jamal

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 3 lines · Christoph Hellwig

Are you sure someone ever tried building this driver modular? The makefile would try to build it into three separate modules, and they'd fail to load due to unresolved cross-depencies..

For embedded drivers isn't not uncommon that it's never used as a module, so it wouldn't surprise me.

#5 lore raw
Quoted 9 lines · Jeff Garzik
Quoted 4 lines · Christoph Hellwig

Are you sure someone ever tried building this driver modular? The makefile
would try to build it into three separate modules, and they'd fail to load due to unresolved cross-depencies..

For embedded drivers isn't not uncommon that it's never used as a module, so it wouldn't surprise me.

then it shouldn't be declare tristate at least. But given that modularizig a netdriver is trivial not doing so counts as a bug to me.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Phy layer notes (was Re: [RFR] gianfar ethernet driver)

Quoted 11 lines · David Woodhouse

Hmmm.

eth0: Running with NAPI disabled
eth0: 64/64 RX/TX BD ring size
eth1: Gianfar Ethernet Controller Version 1.0, 05:e6:9e:c0:05:e6
eth1: Running with NAPI disabled
eth1: 64/64 RX/TX BD ring size eth0: PHY id 2060e1 is not supported!
eth0: No PHY found
IP-Config: Failed to open eth0
IP-Config: Device `eth0' not found

Quoted 6 lines

The PHY is a BCM5421S. Does it really have to give up completely? Isn't there a subset of common MII support it could use?

Is it expected that every NIC driver will include its own version of support for the PHYs which have actually been seen paired with that NIC, or is there some more generic support planned?

David W and I discussed some of this on IRC.

1) most gige phys can be treated with generic GMII code. unfortunately experience shows that phy init can often involve phy-specific magic sequences.

2) we do need a generic phy layer, and I'm looking for volunteers who want to prototype a nice, small, compact one. BenH has a nice template in sungem_phy.c.

3) drivers/net/mii.c and include/linux/mii.h need GMII code and constants. Feel free to add.

4) generic TBI code would be nice, too. (TBI is a standard gige fibre interface)

5) sometimes a MAC+phy pairing is unique enough that you need MAC-specific support for a particular phy. For example, one might wind up with two phy drivers, one a generic Broadcom GMII phy driver (for use by any NIC driver), and one a tg3-specific Broadcom GMII phy driver.