Skip to contentSkip to conversation

DM9000 updates for 2.6.25

PATCH In review Ben Dooks 8 participants 39 messages Feb 5, 2008 – Feb 7, 2008

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

cover DM9000 updates for 2.6.25

This patch set is a series of updates for the DM9000 driver, to tidy-up some of the source, stop the accesses to the PHY and EEPROM sitting and spinning with locks held, and to add ethtool support.

This set includes a pair of patches from Laurent Pinchart for addition platform-data based configuration, please apply these from this if you can attribute these correctly to Laurent, otherwise ask Laurent to resubmit. I have signed-off-by both these patches, but would be equally happy acking them.

The only missing item in this series is to replace the old timer based polling code. This series has been sitting long enough on my own trees, and having MII link status reports is not a driver-threatening bug.

Hopefully this series meets up to everyone's approval and can be applied whilst the current merge window is upon us.

Signature · 1 line
Ben
author
#1 lore raw

PATCH 1/24 DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

This patch splits the receive status in 8bit wide fields and convert the packet length from little endian to CPU byte order.

drivers/net/dm9000.c +7 -6
Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================
@@ -867,7 +867,8 @@ dm9000_timer(unsigned long data)
 }
 
 struct dm9000_rxhdr {
-	u16	RxStatus;
+	u8	RxPktReady;
+	u8	RxStatus;
 	u16	RxLen;
 } __attribute__((__packed__));
 
@@ -908,7 +909,7 @@ dm9000_rx(struct net_device *dev)
 
 		(db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr));
 
-		RxLen = rxhdr.RxLen;
+		RxLen = le16_to_cpu(rxhdr.RxLen);
 
 		/* Packet Status check */
 		if (RxLen < 0x40) {
@@ -920,17 +921,17 @@ dm9000_rx(struct net_device *dev)
 			PRINTK1("RST: RX Len:%x\n", RxLen);
 		}
 
-		if (rxhdr.RxStatus & 0xbf00) {
+		if (rxhdr.RxStatus & 0xbf) {
 			GoodPacket = false;
-			if (rxhdr.RxStatus & 0x100) {
+			if (rxhdr.RxStatus & 0x01) {
 				PRINTK1("fifo error\n");
 				dev->stats.rx_fifo_errors++;
 			}
-			if (rxhdr.RxStatus & 0x200) {
+			if (rxhdr.RxStatus & 0x02) {
 				PRINTK1("crc error\n");
 				dev->stats.rx_crc_errors++;
 			}
-			if (rxhdr.RxStatus & 0x8000) {
+			if (rxhdr.RxStatus & 0x80) {
 				PRINTK1("length error\n");
 				dev->stats.rx_length_errors++;
 			}
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#2 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses.

On Tue, Feb 05, 2008 at 12:02:00AM +0000, Ben Dooks wrote:

This should have been:
Patch From: Laurent Pinchart <[email protected]>

This patch splits the receive status in 8bit wide fields and convert the packet length from little endian to CPU byte order.

Quoted 54 lines

Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c +7 -6
@@ -867,7 +867,8 @@ dm9000_timer(unsigned long data)
 }
 
 struct dm9000_rxhdr {
-	u16	RxStatus;
+	u8	RxPktReady;
+	u8	RxStatus;
 	u16	RxLen;
 } __attribute__((__packed__));
 
@@ -908,7 +909,7 @@ dm9000_rx(struct net_device *dev)
 
 		(db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr));
 
-		RxLen = rxhdr.RxLen;
+		RxLen = le16_to_cpu(rxhdr.RxLen);
 
 		/* Packet Status check */
 		if (RxLen < 0x40) {
@@ -920,17 +921,17 @@ dm9000_rx(struct net_device *dev)
 			PRINTK1("RST: RX Len:%x\n", RxLen);
 		}
 
-		if (rxhdr.RxStatus & 0xbf00) {
+		if (rxhdr.RxStatus & 0xbf) {
 			GoodPacket = false;
-			if (rxhdr.RxStatus & 0x100) {
+			if (rxhdr.RxStatus & 0x01) {
 				PRINTK1("fifo error\n");
 				dev->stats.rx_fifo_errors++;
 			}
-			if (rxhdr.RxStatus & 0x200) {
+			if (rxhdr.RxStatus & 0x02) {
 				PRINTK1("crc error\n");
 				dev->stats.rx_crc_errors++;
 			}
-			if (rxhdr.RxStatus & 0x8000) {
+			if (rxhdr.RxStatus & 0x80) {
 				PRINTK1("length error\n");
 				dev->stats.rx_length_errors++;
 			}
Signature · 8 lines
-- 
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#3 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

In reply to Ben Dooks

Ben Dooks <[email protected]> :

Quoted 11 lines

This patch splits the receive status in 8bit wide fields and convert the packet length from little endian to CPU byte order.

Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c dm9000_timer(unsigned long data) · line 872

Quoted 7 lines
drivers/net/dm9000.c +2 -1
@@ -867,7 +867,8 @@ dm9000_timer(unsigned long data)
 }
 
 struct dm9000_rxhdr {
-	u16	RxStatus;
+	u8	RxPktReady;
+	u8	RxStatus;
 	u16	RxLen;

Given the description of the patch, you could s/u16/__le16/

Al regularly pushes endianness fixes. You can save him some work.

Signature · 1 line
Ueimor
#4 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

In reply to Ben Dooks

two comments:

1) you should be using __le16 type

2) seems like you should do the same for RxStatus, rather than splitting it

#5 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

Quoted 5 lines · Jeff Garzik

two comments:

1) you should be using __le16 type

2) seems like you should do the same for RxStatus, rather than splitting it

The DM9000 datasheet (or rather the application notes) describes two distinct fields, even though they both contain some kind of status information.

Signature · 9 lines
Laurent Pinchart
CSE Semaphore Belgium

Chaussée de Bruxelles, 732A
B-1410 Waterloo
Belgium

T +32 (2) 387 42 59
F +32 (2) 387 42 75
#6 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

Quoted 8 lines · Laurent Pinchart
Quoted 5 lines · Jeff Garzik

two comments:

1) you should be using __le16 type

2) seems like you should do the same for RxStatus, rather than splitting it

The DM9000 datasheet (or rather the application notes) describes two distinct fields, even though they both contain some kind of status information.

Sure, there are plenty of distinct fields, just like with every chipset.
That doesn't mean byte instructions are the best choice.

Jeff

#7 lore raw

Re: [PATCH 01/24 for-2.6.25] DM9000: Fix endian-ness of data accesses. Patch from: Laurent Pinchart <[email protected]>

In reply to Ben Dooks
Quoted 11 lines · Ben Dooks

This patch splits the receive status in 8bit wide fields and convert the packet length from little endian to CPU byte order.

Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c dm9000_timer(unsigned long data) · line 872

Quoted 7 lines
drivers/net/dm9000.c +2 -1
@@ -867,7 +867,8 @@ dm9000_timer(unsigned long data)
 }
 
 struct dm9000_rxhdr {
-	u16	RxStatus;
+	u8	RxPktReady;
+	u8	RxStatus;
 	u16	RxLen;

thgis should be __le16. Also please install sparse and do a

	make C=2 CHECKFLAGS="-D__CHECK_ENDIAN__"

run over the driver to make sure all hw structures are properly annotated and you do byteswaps consistantly.

author
#8 lore raw

PATCH 2/24 DM9000: Add platform data to specify external phy Patch from: Laurent Pinchart <[email protected]>

In reply to Ben Dooks

This patch adds a flag to the DM9000 platform data which, when set, configures the device to use an external PHY.

drivers/net/dm9000.c +6 -0
Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================
@@ -137,6 +137,7 @@ typedef struct board_info {
 	u16 dbug_cnt;
 	u8 io_mode;		/* 0:word, 2:byte */
 	u8 phy_addr;
+	unsigned int flags;
 
 	void (*inblk)(void __iomem *port, void *data, int length);
 	void (*outblk)(void __iomem *port, void *data, int length);
@@ -525,6 +526,8 @@ dm9000_probe(struct platform_device *pde
 
 		if (pdata->dumpblk != NULL)
 			db->dumpblk = pdata->dumpblk;
+
+		db->flags = pdata->flags;
 	}
 
 	dm9000_reset(db);
@@ -665,6 +668,9 @@ dm9000_init_dm9000(struct net_device *de
 	iow(db, DM9000_GPCR, GPCR_GEP_CNTL);	/* Let GPIO0 output */
 	iow(db, DM9000_GPR, 0);	/* Enable PHY */
 
+	if (db->flags & DM9000_PLATF_EXT_PHY)
+		iow(db, DM9000_NCR, NCR_EXT_PHY);
+
 	/* Program operating register */
 	iow(db, DM9000_TCR, 0);	        /* TX Polling clear */
 	iow(db, DM9000_BPTR, 0x3f);	/* Less 3Kb, 200us */
include/linux/dm9000.h +1 -0
Index: linux-2.6.24-git5-dm9k/include/linux/dm9000.h
===================================================================
@@ -19,6 +19,7 @@
 #define DM9000_PLATF_8BITONLY	(0x0001)
 #define DM9000_PLATF_16BITONLY	(0x0002)
 #define DM9000_PLATF_32BITONLY	(0x0004)
+#define DM9000_PLATF_EXT_PHY	(0x0008)
 
 /* platfrom data for platfrom device structure's platfrom_data field */
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#9 lore raw

Re: [PATCH 02/24 for-2.6.25] DM9000: Add platform data to specify external phy

This should have been:

Patch from: Laurent Pinchart <[email protected]>

This patch adds a flag to the DM9000 platform data which, when set, configures the device to use an external PHY.

Quoted 52 lines

Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c +6 -0
@@ -137,6 +137,7 @@ typedef struct board_info {
 	u16 dbug_cnt;
 	u8 io_mode;		/* 0:word, 2:byte */
 	u8 phy_addr;
+	unsigned int flags;
 
 	void (*inblk)(void __iomem *port, void *data, int length);
 	void (*outblk)(void __iomem *port, void *data, int length);
@@ -525,6 +526,8 @@ dm9000_probe(struct platform_device *pde
 
 		if (pdata->dumpblk != NULL)
 			db->dumpblk = pdata->dumpblk;
+
+		db->flags = pdata->flags;
 	}
 
 	dm9000_reset(db);
@@ -665,6 +668,9 @@ dm9000_init_dm9000(struct net_device *de
 	iow(db, DM9000_GPCR, GPCR_GEP_CNTL);	/* Let GPIO0 output */
 	iow(db, DM9000_GPR, 0);	/* Enable PHY */
 
+	if (db->flags & DM9000_PLATF_EXT_PHY)
+		iow(db, DM9000_NCR, NCR_EXT_PHY);
+
 	/* Program operating register */
 	iow(db, DM9000_TCR, 0);	        /* TX Polling clear */
 	iow(db, DM9000_BPTR, 0x3f);	/* Less 3Kb, 200us */

Index: linux-2.6.24-git5-dm9k/include/linux/dm9000.h
===================================================================

include/linux/dm9000.h +1 -0
@@ -19,6 +19,7 @@
 #define DM9000_PLATF_8BITONLY	(0x0001)
 #define DM9000_PLATF_16BITONLY	(0x0002)
 #define DM9000_PLATF_32BITONLY	(0x0004)
+#define DM9000_PLATF_EXT_PHY	(0x0008)
 
 /* platfrom data for platfrom device structure's platfrom_data field */
 
Signature · 8 lines
-- 
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#10 lore raw

PATCH 3/24 DM9000 use dev_xxx() instead of printk for output.

In reply to Ben Dooks

Move to using dev_dbg() and friends for the output of information to the user.

drivers/net/dm9000.c +28 -28
Index: linux-2.6.24-git5-dm9k/drivers/net/dm9000.c
===================================================================
@@ -143,6 +143,8 @@ typedef struct board_info {
 	void (*outblk)(void __iomem *port, void *data, int length);
 	void (*dumpblk)(void __iomem *port, int length);
 
+	struct device	*dev;	     /* parent device */
+
 	struct resource	*addr_res;   /* resources found */
 	struct resource *data_res;
 	struct resource	*addr_req;   /* resources requested */
@@ -185,7 +187,8 @@ static void program_eeprom(board_info_t 
 static void
 dm9000_reset(board_info_t * db)
 {
-	PRINTK1("dm9000x: resetting\n");
+	dev_dbg(db->dev, "resetting device\n");
+
 	/* RESET device */
 	writeb(DM9000_NCR, db->io_addr);
 	udelay(200);
@@ -301,14 +304,10 @@ static void dm9000_set_io(struct board_i
 		db->inblk   = dm9000_inblk_8bit;
 		break;
 
-	case 2:
-		db->dumpblk = dm9000_dumpblk_16bit;
-		db->outblk  = dm9000_outblk_16bit;
-		db->inblk   = dm9000_inblk_16bit;
-		break;
 
 	case 3:
-		printk(KERN_ERR PFX ": 3 byte IO, falling back to 16bit\n");
+		dev_dbg(db->dev, ": 3 byte IO, falling back to 16bit\n");
+	case 2:
 		db->dumpblk = dm9000_dumpblk_16bit;
 		db->outblk  = dm9000_outblk_16bit;
 		db->inblk   = dm9000_inblk_16bit;
@@ -411,18 +410,20 @@ dm9000_probe(struct platform_device *pde
 	/* Init network device */
 	ndev = alloc_etherdev(sizeof (struct board_info));
 	if (!ndev) {
-		printk("%s: could not allocate device.\n", CARDNAME);
+		dev_err(&pdev->dev, "could not allocate device.\n");
 		return -ENOMEM;
 	}
 
 	SET_NETDEV_DEV(ndev, &pdev->dev);
 
-	PRINTK2("dm9000_probe()");
+	dev_dbg(&pdev->dev, "dm9000_probe()");
 
 	/* setup board info structure */
 	db = (struct board_info *) ndev->priv;
 	memset(db, 0, sizeof (*db));
 
+	db->dev = &pdev->dev;
+
 	spin_lock_init(&db->lock);
 
 	if (pdev->num_resources < 2) {
@@ -451,7 +452,7 @@ dm9000_probe(struct platform_device *pde
 
 		if (db->addr_res == NULL || db->data_res == NULL ||
 		    db->irq_res == NULL) {
-			printk(KERN_ERR PFX "insufficient resources\n");
+			dev_err(db->dev, "insufficient resources\n");
 			ret = -ENOENT;
 			goto out;
 		}
@@ -461,7 +462,7 @@ dm9000_probe(struct platform_device *pde
 						  pdev->name);
 
 		if (db->addr_req == NULL) {
-			printk(KERN_ERR PFX "cannot claim address reg area\n");
+			dev_err(db->dev, "cannot claim address reg area\n");
 			ret = -EIO;
 			goto out;
 		}
@@ -469,7 +470,7 @@ dm9000_probe(struct platform_device *pde
 		db->io_addr = ioremap(db->addr_res->start, i);
 
 		if (db->io_addr == NULL) {
-			printk(KERN_ERR "failed to ioremap address reg\n");
+			dev_err(db->dev, "failed to ioremap address reg\n");
 			ret = -EINVAL;
 			goto out;
 		}
@@ -479,7 +480,7 @@ dm9000_probe(struct platform_device *pde
 						  pdev->name);
 
 		if (db->data_req == NULL) {
-			printk(KERN_ERR PFX "cannot claim data reg area\n");
+			dev_err(db->dev, "cannot claim data reg area\n");
 			ret = -EIO;
 			goto out;
 		}
@@ -487,7 +488,7 @@ dm9000_probe(struct platform_device *pde
 		db->io_data = ioremap(db->data_res->start, iosize);
 
 		if (db->io_data == NULL) {
-			printk(KERN_ERR "failed to ioremap data reg\n");
+			dev_err(db->dev,"failed to ioremap data reg\n");
 			ret = -EINVAL;
 			goto out;
 		}
@@ -541,11 +542,11 @@ dm9000_probe(struct platform_device *pde
 
 		if (id_val == DM9000_ID)
 			break;
-		printk("%s: read wrong id 0x%08x\n", CARDNAME, id_val);
+		dev_err(db->dev, "read wrong id 0x%08x\n", id_val);
 	}
 
 	if (id_val != DM9000_ID) {
-		printk("%s: wrong id: 0x%08x\n", CARDNAME, id_val);
+		dev_err(db->dev, "wrong id: 0x%08x\n", id_val);
 		ret = -ENODEV;
 		goto out;
 	}
@@ -593,8 +594,8 @@ dm9000_probe(struct platform_device *pde
 	}
 
 	if (!is_valid_ether_addr(ndev->dev_addr))
-		printk("%s: Invalid ethernet MAC address.  Please "
-		       "set using ifconfig\n", ndev->name);
+		dev_warn(db->dev, "%s: Invalid ethernet MAC address. Please "
+			 "set using ifconfig\n", ndev->name);
 
 	platform_set_drvdata(pdev, ndev);
 	ret = register_netdev(ndev);
@@ -608,7 +609,7 @@ dm9000_probe(struct platform_device *pde
 	return 0;
 
 out:
-	printk("%s: not found (%d).\n", CARDNAME, ret);
+	dev_err(db->dev, "not found (%d).\n", ret);
 
 	dm9000_release_board(pdev, db);
 	free_netdev(ndev);
@@ -625,7 +626,7 @@ dm9000_open(struct net_device *dev)
 {
 	board_info_t *db = (board_info_t *) dev->priv;
 
-	PRINTK2("entering dm9000_open\n");
+	dev_dbg(db->dev, "entering %s\n", __func__);
 
 	if (request_irq(dev->irq, &dm9000_interrupt, DM9000_IRQ_FLAGS, dev->name, dev))
 		return -EAGAIN;
@@ -900,7 +901,7 @@ dm9000_rx(struct net_device *dev)
 
 		/* Status check: this byte must be 0 or 1 */
 		if (rxbyte > DM9000_PKT_RDY) {
-			printk("status check failed: %d\n", rxbyte);
+			dev_warn(db->dev, "status check fail: %d\n", rxbyte);
 			iow(db, DM9000_RCR, 0x00);	/* Stop Device */
 			iow(db, DM9000_ISR, IMR_PAR);	/* Stop INT request */
 			return;
@@ -920,25 +921,25 @@ dm9000_rx(struct net_device *dev)
 		/* Packet Status check */
 		if (RxLen < 0x40) {
 			GoodPacket = false;
-			PRINTK1("Bad Packet received (runt)\n");
+			dev_dbg(db->dev, "Bad Packet received (runt)\n");
 		}
 
 		if (RxLen > DM9000_PKT_MAX) {
-			PRINTK1("RST: RX Len:%x\n", RxLen);
+			dev_dbg(db->dev, "RST: RX Len:%x\n", RxLen);
 		}
 
 		if (rxhdr.RxStatus & 0xbf) {
 			GoodPacket = false;
 			if (rxhdr.RxStatus & 0x01) {
-				PRINTK1("fifo error\n");
+				dev_dbg(db->dev, "fifo error\n");
 				dev->stats.rx_fifo_errors++;
 			}
 			if (rxhdr.RxStatus & 0x02) {
-				PRINTK1("crc error\n");
+				dev_dbg(db->dev, "crc error\n");
 				dev->stats.rx_crc_errors++;
 			}
 			if (rxhdr.RxStatus & 0x80) {
-				PRINTK1("length error\n");
+				dev_dbg(db->dev, "length error\n");
 				dev->stats.rx_length_errors++;
 			}
 		}
@@ -1187,8 +1188,7 @@ dm9000_drv_remove(struct platform_device
 	dm9000_release_board(pdev, (board_info_t *) ndev->priv);
 	free_netdev(ndev);		/* free device structure */
 
-	PRINTK1("clean_module() exit\n");
-
+	dev_dbg(&pdev->dev, "released and freed device\n");
 	return 0;
 }
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#11 lore raw

PATCH 4/24 DM9000 update debugging macros to use debug level

In reply to Ben Dooks

Change the debug macros to use the compiler to elide any unnecessary debug level, and to allow device configurable debug control.

drivers/net/Kconfig +8 -0
Index: linux-2.6.24-git5-dm9k/drivers/net/Kconfig
===================================================================
@@ -912,6 +912,14 @@ config DM9000
 	  To compile this driver as a module, choose M here.  The module
 	  will be called dm9000.
 
+config DM9000_DEBUGLEVEL
+	int "DM9000 maximum debug level"
+	depends on DM9000
+	default 4
+	help
+	  The maximum level of debugging code compiled into the DM9000
+	  driver.
+
 config SMC911X
 	tristate "SMSC LAN911[5678] support"
 	select CRC32
drivers/net/dm9000.c +19 -35

113 lines not on this page · raw message

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#12 lore raw

PATCH 5/24 DM9000: Pass IRQ flags via platform resources

In reply to Ben Dooks

Use the flags in the IRQ resource to specify the type of IRQ being requested, so that systems which do not have level-based interrupts, or change the interrupt in some other way can specify this without making an #ifdef mess in the driver.

This is specifically designed to undo the change in commit 4e4fc05a2b6e7bd2e0facd96e0c18dceb34d9349 which hardwires the type for everyone but blackfin to IRQT_RISING, which breaks all a number of Simtec boards which use (and setup in the bootloader) active low IRQs.

Note, although there where originally objections due to the use of IORESOURCE_IRQ and IRQT_ flags not sharing the same definition, at least <include/linux/interrupt.h> notes these are the same.

CC Daniel Mack <[email protected]>
CC Bryan Wu <[email protected]>
CC Alex Landau <[email protected]>
drivers/net/dm9000.c +14 -3
Index: linux-2.6.24-quilt2/drivers/net/dm9000.c
===================================================================
@@ -90,9 +90,9 @@
 #define writesb	outsb
 #define writesw	outsw
 #define writesl	outsl
-#define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQF_TRIGGER_HIGH)
+#define DEFAULT_TRIGGER IRQF_TRIGGER_HIGH
 #else
-#define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQT_RISING)
+#define DEFAULT_TRIGGER (0)
 #endif
 
 /*
@@ -614,10 +614,21 @@ static int
 dm9000_open(struct net_device *dev)
 {
 	board_info_t *db = (board_info_t *) dev->priv;
+	unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK;
 
 	dev_dbg(db->dev, "entering %s\n", __func__);
 
-	if (request_irq(dev->irq, &dm9000_interrupt, DM9000_IRQ_FLAGS, dev->name, dev))
+	/* If there is no IRQ type specified, default to something that
+	 * may work, and tell the user that this is a problem */
+
+	if (irqflags == IRQF_TRIGGER_NONE) {
+		dev_warn(db->dev, "WARNING: no IRQ resource flags set.\n");
+		irqflags = DEFAULT_TRIGGER;
+	}
+	
+	irqflags |= IRQF_SHARED;
+
+	if (request_irq(dev->irq, &dm9000_interrupt, irqflags, dev->name, dev))
 		return -EAGAIN;
 
 	/* Initialize DM9000 board */
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#13 lore raw

PATCH 6/24 DM9000: Remove old timer based poll routines

In reply to Ben Dooks

Remove the timer based MII phy polling, as this is currently broken with the new EEPROM code that now uses mutexes to protect the phy access.

This will need to be replaced in the future by some form of mutex safe mechanism for reading the MII phy status.

The replacement has not been done here as changing this patch, which is early in the sequence has quite a knock-on effect. Once this series is merged, then a new presentation of an patch to poll the MII link status can be added.

drivers/net/dm9000.c +0 -34
Index: linux-2.6.24-quilt2/drivers/net/dm9000.c
===================================================================
@@ -81,8 +81,6 @@
 #define CARDNAME "dm9000"
 #define PFX CARDNAME ": "
 
-#define DM9000_TIMER_WUT  jiffies+(HZ*2)	/* timer wakeup time : 2 second */
-
 #ifdef CONFIG_BLACKFIN
 #define readsb	insb
 #define readsw	insw
@@ -131,7 +129,6 @@ typedef struct board_info {
 	struct resource *data_req;
 	struct resource *irq_res;
 
-	struct timer_list timer;
 	unsigned char srom[128];
 	spinlock_t lock;
 
@@ -154,8 +151,6 @@ static int dm9000_open(struct net_device
 static int dm9000_start_xmit(struct sk_buff *, struct net_device *);
 static int dm9000_stop(struct net_device *);
 
-
-static void dm9000_timer(unsigned long);
 static void dm9000_init_dm9000(struct net_device *);
 
 static irqreturn_t dm9000_interrupt(int, void *);
@@ -638,13 +633,6 @@ dm9000_open(struct net_device *dev)
 	/* Init driver variable */
 	db->dbug_cnt = 0;
 
-	/* set and active a timer process */
-	init_timer(&db->timer);
-	db->timer.expires  = DM9000_TIMER_WUT;
-	db->timer.data     = (unsigned long) dev;
-	db->timer.function = &dm9000_timer;
-	add_timer(&db->timer);
-
 	mii_check_media(&db->mii, netif_msg_link(db), 1);
 	netif_start_queue(dev);
 
@@ -766,9 +754,6 @@ dm9000_stop(struct net_device *ndev)
 
 	dm9000_dbg(db, 1, "entering %s\n", __func__);
 
-	/* deleted timer */
-	del_timer(&db->timer);
-
 	netif_stop_queue(ndev);
 	netif_carrier_off(ndev);
 
@@ -849,25 +834,6 @@ dm9000_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-/*
- *  A periodic timer routine
- *  Dynamic media sense, allocated Rx buffer...
- */
-static void
-dm9000_timer(unsigned long data)
-{
-	struct net_device *dev = (struct net_device *) data;
-	board_info_t *db = (board_info_t *) dev->priv;
-
-	dm9000_dbg(db, 3, "entering %s\n", __func__);
-
-	mii_check_media(&db->mii, netif_msg_link(db), 0);
-
-	/* Set timer again */
-	db->timer.expires = DM9000_TIMER_WUT;
-	add_timer(&db->timer);
-}
-
 struct dm9000_rxhdr {
 	u8	RxPktReady;
 	u8	RxStatus;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#14 lore raw

PATCH 7/24 DM9000: Add initial ethtool support

In reply to Ben Dooks

Add support for ethtool operations for the DM9000.

drivers/net/dm9000.c +68 -1
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -63,6 +63,7 @@
 #include <linux/spinlock.h>
 #include <linux/crc32.h>
 #include <linux/mii.h>
+#include <linux/ethtool.h>
 #include <linux/dm9000.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
@@ -80,6 +81,7 @@
 
 #define CARDNAME "dm9000"
 #define PFX CARDNAME ": "
+#define DRV_VERSION	"1.30"
 
 #ifdef CONFIG_BLACKFIN
 #define readsb	insb
@@ -145,6 +147,11 @@ typedef struct board_info {
 	}						\
 } while (0)
 
+static inline board_info_t *to_dm9000_board(struct net_device *dev)
+{
+	return dev->priv;
+}
+
 /* function declaration ------------------------------------- */
 static int dm9000_probe(struct platform_device *);
 static int dm9000_open(struct net_device *);
@@ -342,6 +349,64 @@ static void dm9000_poll_controller(struc
 }
 #endif
 
+/* ethtool ops */
+
+static void dm9000_get_drvinfo(struct net_device *dev,
+			       struct ethtool_drvinfo *info)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+
+	strcpy(info->driver, CARDNAME);
+	strcpy(info->version, DRV_VERSION);
+	strcpy(info->bus_info, to_platform_device(dm->dev)->name);
+}
+
+static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	unsigned long flags;
+
+	spin_lock_irqsave(&dm->lock, flags);
+	mii_ethtool_gset(&dm->mii, cmd);
+	spin_lock_irqsave(&dm->lock, flags);
+
+	return 0;
+}
+
+static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	unsigned long flags;
+	int rc;
+
+	spin_lock_irqsave(&dm->lock, flags);
+	rc = mii_ethtool_sset(&dm->mii, cmd);
+	spin_lock_irqsave(&dm->lock, flags);
+
+	return rc;
+}
+
+static int dm9000_nway_reset(struct net_device *dev)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	return mii_nway_restart(&dm->mii);
+}
+
+static u32 dm9000_get_link(struct net_device *dev)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	return mii_link_ok(&dm->mii);
+}
+
+static const struct ethtool_ops dm9000_ethtool_ops = {
+	.get_drvinfo		= dm9000_get_drvinfo,
+	.get_settings		= dm9000_get_settings,
+	.set_settings		= dm9000_set_settings,
+	.nway_reset		= dm9000_nway_reset,
+	.get_link		= dm9000_get_link,
+};
+
+
 /* dm9000_release_board
  *
  * release a board, and any mapped resources
@@ -546,6 +611,8 @@ dm9000_probe(struct platform_device *pde
 	ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
 	ndev->stop		 = &dm9000_stop;
 	ndev->set_multicast_list = &dm9000_hash_table;
+	ndev->ethtool_ops	 = &dm9000_ethtool_ops;
+
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	ndev->poll_controller	 = &dm9000_poll_controller;
 #endif
@@ -1170,7 +1237,7 @@ static struct platform_driver dm9000_dri
 static int __init
 dm9000_init(void)
 {
-	printk(KERN_INFO "%s Ethernet Driver\n", CARDNAME);
+	printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);
 
 	return platform_driver_register(&dm9000_driver);	/* search board and register */
 }
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#15 lore raw

Re: [PATCH 07/24 for-2.6.25] DM9000: Add initial ethtool support

Ben Dooks <[email protected]> :

Quoted 8 lines

Add support for ethtool operations for the DM9000.

Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c +0 -0

[...]

drivers/net/dm9000.c static void dm9000_poll_controller(struc · line 370

Quoted 7 lines
drivers/net/dm9000.c +7 -0
+static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	unsigned long flags;
+
+	spin_lock_irqsave(&dm->lock, flags);
+	mii_ethtool_gset(&dm->mii, cmd);

drivers/net/mii.c::mii_ethtool_gset
[...]

        advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);

drivers/net/dm9000.c::dm9000_probe
[...]

        db->mii.mdio_read    = dm9000_phy_read;

drivers/net/dm9000.c::dm9000_phy_read
[...]

        board_info_t *db = (board_info_t *) dev->priv;
        unsigned long flags;
        unsigned int reg_save;
        int ret;

        spin_lock_irqsave(&db->lock,flags);

-> deadlock

Signature · 1 line
Ueimor
#16 lore raw

Re: [PATCH 07/24 for-2.6.25] DM9000: Add initial ethtool support

Quoted 28 lines · Francois Romieu

Ben Dooks <[email protected]> :

Quoted 8 lines

Add support for ethtool operations for the DM9000.

Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================

drivers/net/dm9000.c +0 -0

[...]

drivers/net/dm9000.c static void dm9000_poll_controller(struc · line 370

Quoted 7 lines
drivers/net/dm9000.c +7 -0
+static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	unsigned long flags;
+
+	spin_lock_irqsave(&dm->lock, flags);
+	mii_ethtool_gset(&dm->mii, cmd);

drivers/net/mii.c::mii_ethtool_gset
[...]

        advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);

drivers/net/dm9000.c::dm9000_probe
[...]

        db->mii.mdio_read    = dm9000_phy_read;

drivers/net/dm9000.c::dm9000_phy_read
[...]

Quoted 8 lines
        board_info_t *db = (board_info_t *) dev->priv;
        unsigned long flags;
        unsigned int reg_save;
        int ret;

        spin_lock_irqsave(&db->lock,flags);

-> deadlock

The next patch in the series changes the locking.

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#17 lore raw

Re: [PATCH 07/24 for-2.6.25] DM9000: Add initial ethtool support

Ben Dooks <[email protected]> :
[...]

Quoted 1 line

The next patch in the series changes the locking.

Do you mean patch #08 ?

If so it does not fix this bug: the very first line in dm9000_phy_read includes a spinlock statement.

Signature · 1 line
Ueimor
#18 lore raw

Re: [PATCH 07/24 for-2.6.25] DM9000: Add initial ethtool support

Quoted 5 lines · Francois Romieu

Ben Dooks <[email protected]> :
[...]

Quoted 1 line

The next patch in the series changes the locking.

Do you mean patch #08 ?

Sorry, looked at the wrong patch, it is #11 which changes the locking for address register accesses.

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#19 lore raw

PATCH 8/24 DM9000: Do not sleep with spinlock and IRQs held

In reply to Ben Dooks

The phy read and write routines call udelay() with the board lock held, and with the posibility of IRQs being disabled. Since these delays can be up to 500usec, and are only required as we have to save the chip's address register.

To improve the behaviour, hold the lock whilst we are writing and then restore the state before the delay and then repeat the process once the delay has happened.

drivers/net/dm9000.c +16 -1
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -1130,7 +1130,15 @@ dm9000_phy_read(struct net_device *dev, 
 	iow(db, DM9000_EPAR, DM9000_PHY | reg);
 
 	iow(db, DM9000_EPCR, 0xc);	/* Issue phyxcer read command */
+
+	writeb(reg_save, db->io_addr);
+	spin_unlock_irqrestore(&db->lock,flags);
+
 	udelay(100);		/* Wait read complete */
+
+	spin_lock_irqsave(&db->lock,flags);
+	reg_save = readb(db->io_addr);
+
 	iow(db, DM9000_EPCR, 0x0);	/* Clear phyxcer read command */
 
 	/* The read data keeps on REG_0D & REG_0E */
@@ -1138,7 +1146,6 @@ dm9000_phy_read(struct net_device *dev, 
 
 	/* restore the previous address */
 	writeb(reg_save, db->io_addr);
-
 	spin_unlock_irqrestore(&db->lock,flags);
 
 	return ret;
@@ -1167,7 +1174,15 @@ dm9000_phy_write(struct net_device *dev,
 	iow(db, DM9000_EPDRH, ((value >> 8) & 0xff));
 
 	iow(db, DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
+
+	writeb(reg_save, db->io_addr);
+	spin_unlock_irqrestore(&db->lock,flags);
+
 	udelay(500);		/* Wait write complete */
+
+	spin_lock_irqsave(&db->lock,flags);
+	reg_save = readb(db->io_addr);
+
 	iow(db, DM9000_EPCR, 0x0);	/* Clear phyxcer write command */
 
 	/* restore the previous address */
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#20 lore raw

PATCH 9/24 DM9000: Use msleep() instead of udelay()

In reply to Ben Dooks

We can use sleeping functions when reading and writing the PHY registers, so let us sleep instead of busy waiting for the PHY.

Note, this also fixes a bug reading the PHY where only 100uS was being used instead of 150uS

drivers/net/dm9000.c +21 -2
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -116,6 +116,7 @@ typedef struct board_info {
 	u8 io_mode;		/* 0:word, 2:byte */
 	u8 phy_addr;
 	unsigned int flags;
+	unsigned int in_suspend :1;
 
 	int debug_level;
 
@@ -1111,6 +1112,18 @@ dm9000_hash_table(struct net_device *dev
 
 
 /*
+ * Sleep, either by using msleep() or if we are suspending, then
+ * use mdelay() to sleep.
+ */
+static void dm9000_msleep(board_info_t *db, unsigned int ms)
+{
+	if (db->in_suspend)
+		mdelay(ms);
+	else
+		msleep(ms);
+}
+
+/*
  *   Read a word from phyxcer
  */
 static int
@@ -1134,7 +1147,7 @@ dm9000_phy_read(struct net_device *dev, 
 	writeb(reg_save, db->io_addr);
 	spin_unlock_irqrestore(&db->lock,flags);
 
-	udelay(100);		/* Wait read complete */
+	dm9000_msleep(db, 1);		/* Wait read complete */
 
 	spin_lock_irqsave(&db->lock,flags);
 	reg_save = readb(db->io_addr);
@@ -1178,7 +1191,7 @@ dm9000_phy_write(struct net_device *dev,
 	writeb(reg_save, db->io_addr);
 	spin_unlock_irqrestore(&db->lock,flags);
 
-	udelay(500);		/* Wait write complete */
+	dm9000_msleep(db, 1);		/* Wait write complete */
 
 	spin_lock_irqsave(&db->lock,flags);
 	reg_save = readb(db->io_addr);
@@ -1195,8 +1208,12 @@ static int
 dm9000_drv_suspend(struct platform_device *dev, pm_message_t state)
 {
 	struct net_device *ndev = platform_get_drvdata(dev);
+	board_info_t *db;
 
 	if (ndev) {
+		db = (board_info_t *) ndev->priv;
+		db->in_suspend = 1;
+
 		if (netif_running(ndev)) {
 			netif_device_detach(ndev);
 			dm9000_shutdown(ndev);
@@ -1219,6 +1236,8 @@ dm9000_drv_resume(struct platform_device
 
 			netif_device_attach(ndev);
 		}
+
+		db->in_suspend = 0;
 	}
 	return 0;
 }
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#21 lore raw

PATCH 10/24 DM9000: Remove barely used SROM array read.

In reply to Ben Dooks

The srom array in the board data is only being used in the device probe routines. The probe also only uses the first 6 bytes of an array we spend 512ms reading 128 bytes from. Change to reading the MAC area directly to the MAC address structure.

As a side product, we rename the read_srom_word to dm9000_read_eeprom to bring it into line with the rest of the driver. No change is made to the delay in this function, which will be dealt with in a later patch.

drivers/net/dm9000.c +11 -13
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -132,7 +132,6 @@ typedef struct board_info {
 	struct resource *data_req;
 	struct resource *irq_res;
 
-	unsigned char srom[128];
 	spinlock_t lock;
 
 	struct mii_if_info mii;
@@ -166,7 +165,8 @@ static irqreturn_t dm9000_interrupt(int,
 static int dm9000_phy_read(struct net_device *dev, int phyaddr_unsused, int reg);
 static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg,
 			   int value);
-static u16 read_srom_word(board_info_t *, int);
+
+static void dm9000_read_eeprom(board_info_t *, int addr, unsigned char *to);
 static void dm9000_rx(struct net_device *);
 static void dm9000_hash_table(struct net_device *);
 
@@ -630,13 +630,9 @@ dm9000_probe(struct platform_device *pde
 	db->mii.mdio_read    = dm9000_phy_read;
 	db->mii.mdio_write   = dm9000_phy_write;
 
-	/* Read SROM content */
-	for (i = 0; i < 64; i++)
-		((u16 *) db->srom)[i] = read_srom_word(db, i);
-
-	/* Set Node Address */
-	for (i = 0; i < 6; i++)
-		ndev->dev_addr[i] = db->srom[i];
+	/* try reading the node address from the attached EEPROM */
+	for (i = 0; i < 6; i += 2)
+		dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
 
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
 		/* try reading from mac */
@@ -1001,17 +997,19 @@ dm9000_rx(struct net_device *dev)
 }
 
 /*
- *  Read a word data from SROM
+ *  Read a word data from EEPROM
  */
-static u16
-read_srom_word(board_info_t * db, int offset)
+static void
+dm9000_read_eeprom(board_info_t * db, int offset, unsigned char *to)
 {
 	iow(db, DM9000_EPAR, offset);
 	iow(db, DM9000_EPCR, EPCR_ERPRR);
 	mdelay(8);		/* according to the datasheet 200us should be enough,
 				   but it doesn't work */
 	iow(db, DM9000_EPCR, 0x0);
-	return (ior(db, DM9000_EPDRL) + (ior(db, DM9000_EPDRH) << 8));
+
+	to[0] = ior(db, DM9000_EPDRL);
+	to[1] = ior(db, DM9000_EPDRH);
 }
 
 #ifdef DM9000_PROGRAM_EEPROM
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#22 lore raw

PATCH 11/24 DM9000: Add mutex to protect access

In reply to Ben Dooks

Add a mutex to serialise access to the chip functions from entries such as the ethtool and the MII code. This should reduce the amount of time the spinlock is held to protect the address register.

drivers/net/dm9000.c +39 -14
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -102,6 +102,24 @@ static int watchdog = 5000;
 module_param(watchdog, int, 0400);
 MODULE_PARM_DESC(watchdog, "transmit timeout in milliseconds");
 
+/* DM9000 register address locking.
+ *
+ * The DM9000 uses an address register to control where data written
+ * to the data register goes. This means that the address register
+ * must be preserved over interrupts or similar calls.
+ *
+ * During interrupt and other critical calls, a spinlock is used to
+ * protect the system, but the calls themselves save the address
+ * in the address register in case they are interrupting another
+ * access to the device.
+ *
+ * For general accesses a lock is provided so that calls which are
+ * allowed to sleep are serialised so that the address register does
+ * not need to be saved. This lock also serves to serialise access
+ * to the EEPROM and PHY access registers which are shared between
+ * these two devices.
+ */
+
 /* Structure/enum declaration ------------------------------- */
 typedef struct board_info {
 
@@ -132,6 +150,8 @@ typedef struct board_info {
 	struct resource *data_req;
 	struct resource *irq_res;
 
+	struct mutex	 addr_lock;	/* phy and eeprom access lock */
+
 	spinlock_t lock;
 
 	struct mii_if_info mii;
@@ -365,26 +385,16 @@ static void dm9000_get_drvinfo(struct ne
 static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	board_info_t *dm = to_dm9000_board(dev);
-	unsigned long flags;
 
-	spin_lock_irqsave(&dm->lock, flags);
 	mii_ethtool_gset(&dm->mii, cmd);
-	spin_lock_irqsave(&dm->lock, flags);
-
 	return 0;
 }
 
 static int dm9000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	board_info_t *dm = to_dm9000_board(dev);
-	unsigned long flags;
-	int rc;
-
-	spin_lock_irqsave(&dm->lock, flags);
-	rc = mii_ethtool_sset(&dm->mii, cmd);
-	spin_lock_irqsave(&dm->lock, flags);
 
-	return rc;
+	return mii_ethtool_sset(&dm->mii, cmd);
 }
 
 static int dm9000_nway_reset(struct net_device *dev)
@@ -475,6 +485,7 @@ dm9000_probe(struct platform_device *pde
 	db->dev = &pdev->dev;
 
 	spin_lock_init(&db->lock);
+	mutex_init(&db->addr_lock);
 
 	if (pdev->num_resources < 2) {
 		ret = -ENODEV;
@@ -1000,8 +1011,10 @@ dm9000_rx(struct net_device *dev)
  *  Read a word data from EEPROM
  */
 static void
-dm9000_read_eeprom(board_info_t * db, int offset, unsigned char *to)
+dm9000_read_eeprom(board_info_t *db, int offset, unsigned char *to)
 {
+	mutex_lock(&db->addr_lock);
+
 	iow(db, DM9000_EPAR, offset);
 	iow(db, DM9000_EPCR, EPCR_ERPRR);
 	mdelay(8);		/* according to the datasheet 200us should be enough,
@@ -1010,6 +1023,8 @@ dm9000_read_eeprom(board_info_t * db, in
 
 	to[0] = ior(db, DM9000_EPDRL);
 	to[1] = ior(db, DM9000_EPDRH);
+
+	mutex_unlock(&db->addr_lock);
 }
 
 #ifdef DM9000_PROGRAM_EEPROM
@@ -1019,12 +1034,16 @@ dm9000_read_eeprom(board_info_t * db, in
 static void
 write_srom_word(board_info_t * db, int offset, u16 val)
 {
+	mutex_lock(&db->addr_lock);
+
 	iow(db, DM9000_EPAR, offset);
 	iow(db, DM9000_EPDRH, ((val >> 8) & 0xff));
 	iow(db, DM9000_EPDRL, (val & 0xff));
 	iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
 	mdelay(8);		/* same shit */
 	iow(db, DM9000_EPCR, 0);
+
+	mutex_unlock(&db->addr_lock);
 }
 
 /*
@@ -1132,6 +1151,8 @@ dm9000_phy_read(struct net_device *dev, 
 	unsigned int reg_save;
 	int ret;
 
+	mutex_lock(&db->addr_lock);
+
 	spin_lock_irqsave(&db->lock,flags);
 
 	/* Save previous register address */
@@ -1159,6 +1180,7 @@ dm9000_phy_read(struct net_device *dev, 
 	writeb(reg_save, db->io_addr);
 	spin_unlock_irqrestore(&db->lock,flags);
 
+	mutex_unlock(&db->addr_lock);
 	return ret;
 }
 
@@ -1172,6 +1194,8 @@ dm9000_phy_write(struct net_device *dev,
 	unsigned long flags;
 	unsigned long reg_save;
 
+	mutex_lock(&db->addr_lock);
+
 	spin_lock_irqsave(&db->lock,flags);
 
 	/* Save previous register address */
@@ -1187,7 +1211,7 @@ dm9000_phy_write(struct net_device *dev,
 	iow(db, DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 
 	writeb(reg_save, db->io_addr);
-	spin_unlock_irqrestore(&db->lock,flags);
+	spin_unlock_irqrestore(&db->lock, flags);
 
 	dm9000_msleep(db, 1);		/* Wait write complete */
 
@@ -1199,7 +1223,8 @@ dm9000_phy_write(struct net_device *dev,
 	/* restore the previous address */
 	writeb(reg_save, db->io_addr);
 
-	spin_unlock_irqrestore(&db->lock,flags);
+	spin_unlock_irqrestore(&db->lock, flags);
+	mutex_unlock(&db->addr_lock);
 }
 
 static int
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#23 lore raw

PATCH 12/24 DM9000: Add ethtool support for reading and writing EEPROM

In reply to Ben Dooks

Add ethtool support to access the configuration EEPROM connected to the DM9000.

drivers/net/dm9000.c +60 -6
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -186,7 +186,8 @@ static int dm9000_phy_read(struct net_de
 static void dm9000_phy_write(struct net_device *dev, int phyaddr_unused, int reg,
 			   int value);
 
-static void dm9000_read_eeprom(board_info_t *, int addr, unsigned char *to);
+static void dm9000_read_eeprom(board_info_t *, int addr, u8 *to);
+static void dm9000_write_eeprom(board_info_t *, int addr, u8 *dp);
 static void dm9000_rx(struct net_device *);
 static void dm9000_hash_table(struct net_device *);
 
@@ -409,12 +410,65 @@ static u32 dm9000_get_link(struct net_de
 	return mii_link_ok(&dm->mii);
 }
 
+#define DM_EEPROM_MAGIC		(0x444D394B)
+
+static int dm9000_get_eeprom_len(struct net_device *dev)
+{
+	return 128;
+}
+
+static int dm9000_get_eeprom(struct net_device *dev,
+			     struct ethtool_eeprom *ee, u8 *data)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	int offset = ee->offset;
+	int len = ee->len;
+	int i;
+
+	/* EEPROM access is aligned to two bytes */
+
+	if ((len & 1) != 0 || (offset & 1) != 0)
+		return -EINVAL;
+
+	ee->magic = DM_EEPROM_MAGIC;
+
+	for (i = 0; i < len; i += 2)
+		dm9000_read_eeprom(dm, (offset + i) / 2, data + i);
+
+	return 0;
+}
+
+static int dm9000_set_eeprom(struct net_device *dev,
+			     struct ethtool_eeprom *ee, u8 *data)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+	int offset = ee->offset;
+	int len = ee->len;
+	int i;
+
+	/* EEPROM access is aligned to two bytes */
+
+	if ((len & 1) != 0 || (offset & 1) != 0)
+		return -EINVAL;
+
+	if (ee->magic != DM_EEPROM_MAGIC)
+		return -EINVAL;
+
+	for (i = 0; i < len; i += 2)
+		dm9000_write_eeprom(dm, (offset + i) / 2, data + i);
+
+	return 0;
+}
+
 static const struct ethtool_ops dm9000_ethtool_ops = {
 	.get_drvinfo		= dm9000_get_drvinfo,
 	.get_settings		= dm9000_get_settings,
 	.set_settings		= dm9000_set_settings,
 	.nway_reset		= dm9000_nway_reset,
 	.get_link		= dm9000_get_link,
+ 	.get_eeprom_len		= dm9000_get_eeprom_len,
+ 	.get_eeprom		= dm9000_get_eeprom,
+ 	.set_eeprom		= dm9000_set_eeprom,
 };
 
 
@@ -1011,7 +1065,7 @@ dm9000_rx(struct net_device *dev)
  *  Read a word data from EEPROM
  */
 static void
-dm9000_read_eeprom(board_info_t *db, int offset, unsigned char *to)
+dm9000_read_eeprom(board_info_t *db, int offset, u8 *to)
 {
 	mutex_lock(&db->addr_lock);
 
@@ -1027,18 +1081,17 @@ dm9000_read_eeprom(board_info_t *db, int
 	mutex_unlock(&db->addr_lock);
 }
 
-#ifdef DM9000_PROGRAM_EEPROM
 /*
  * Write a word data to SROM
  */
 static void
-write_srom_word(board_info_t * db, int offset, u16 val)
+dm9000_write_eeprom(board_info_t *db, int offset, u8 *data)
 {
 	mutex_lock(&db->addr_lock);
 
 	iow(db, DM9000_EPAR, offset);
-	iow(db, DM9000_EPDRH, ((val >> 8) & 0xff));
-	iow(db, DM9000_EPDRL, (val & 0xff));
+	iow(db, DM9000_EPDRH, data[1]);
+	iow(db, DM9000_EPDRL, data[0]);
 	iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
 	mdelay(8);		/* same shit */
 	iow(db, DM9000_EPCR, 0);
@@ -1046,6 +1099,7 @@ write_srom_word(board_info_t * db, int o
 	mutex_unlock(&db->addr_lock);
 }
 
+#ifdef DM9000_PROGRAM_EEPROM
 /*
  * Only for development:
  * Here we write static data to the eeprom in case
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#24 lore raw

PATCH 13/24 DM9000: Add ethtool control of msg_enable value

In reply to Ben Dooks

Allow the msg_enable value to be read and written by the ethtool interface.

drivers/net/dm9000.c +16 -0
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -383,6 +383,20 @@ static void dm9000_get_drvinfo(struct ne
 	strcpy(info->bus_info, to_platform_device(dm->dev)->name);
 }
 
+static u32 dm9000_get_msglevel(struct net_device *dev)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+
+	return dm->msg_enable;
+}
+
+static void dm9000_set_msglevel(struct net_device *dev, u32 value)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+
+	dm->msg_enable = value;
+}
+
 static int dm9000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	board_info_t *dm = to_dm9000_board(dev);
@@ -464,6 +478,8 @@ static const struct ethtool_ops dm9000_e
 	.get_drvinfo		= dm9000_get_drvinfo,
 	.get_settings		= dm9000_get_settings,
 	.set_settings		= dm9000_set_settings,
+	.get_msglevel		= dm9000_get_msglevel,
+	.set_msglevel		= dm9000_set_msglevel,
 	.nway_reset		= dm9000_nway_reset,
 	.get_link		= dm9000_get_link,
  	.get_eeprom_len		= dm9000_get_eeprom_len,
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#25 lore raw

PATCH 14/24 DM9000: Remove EEPROM initialisation code.

In reply to Ben Dooks

Remove the old hack to program an initial EEPROM setting into the DM9000 as we now have ethtool support for reading and writing the EEPROM.

drivers/net/dm9000.c +0 -29
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -191,10 +191,6 @@ static void dm9000_write_eeprom(board_in
 static void dm9000_rx(struct net_device *);
 static void dm9000_hash_table(struct net_device *);
 
-//#define DM9000_PROGRAM_EEPROM
-#ifdef DM9000_PROGRAM_EEPROM
-static void program_eeprom(board_info_t * db);
-#endif
 /* DM9000 network board routine ---------------------------- */
 
 static void
@@ -699,9 +695,6 @@ dm9000_probe(struct platform_device *pde
 	ndev->poll_controller	 = &dm9000_poll_controller;
 #endif
 
-#ifdef DM9000_PROGRAM_EEPROM
-	program_eeprom(db);
-#endif
 	db->msg_enable       = NETIF_MSG_LINK;
 	db->mii.phy_id_mask  = 0x1f;
 	db->mii.reg_num_mask = 0x1f;
@@ -1115,28 +1108,6 @@ dm9000_write_eeprom(board_info_t *db, in
 	mutex_unlock(&db->addr_lock);
 }
 
-#ifdef DM9000_PROGRAM_EEPROM
-/*
- * Only for development:
- * Here we write static data to the eeprom in case
- * we don't have valid content on a new board
- */
-static void
-program_eeprom(board_info_t * db)
-{
-	u16 eeprom[] = { 0x0c00, 0x007f, 0x1300,	/* MAC Address */
-		0x0000,		/* Autoload: accept nothing */
-		0x0a46, 0x9000,	/* Vendor / Product ID */
-		0x0000,		/* pin control */
-		0x0000,
-	};			/* Wake-up mode control */
-	int i;
-	for (i = 0; i < 8; i++)
-		write_srom_word(db, i, eeprom[i]);
-}
-#endif
-
-
 /*
  *  Calculate the CRC valude of the Rx packet
  *  flag = 1 : return the reverse CRC (for the received packet CRC)
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#26 lore raw

PATCH 15/24 DM9000: Ensure spinlock held whilst accessing EEPROM registers

In reply to Ben Dooks

Ensure we hold the spinlock whilst the registers and being modified even though we hold the overall lock. This should protect against an interrupt happening whilst we are using the device.

drivers/net/dm9000.c +20 -0
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -1076,17 +1076,29 @@ dm9000_rx(struct net_device *dev)
 static void
 dm9000_read_eeprom(board_info_t *db, int offset, u8 *to)
 {
+	unsigned long flags;
+
 	mutex_lock(&db->addr_lock);
 
+	spin_lock_irqsave(&db->lock, flags);
+
 	iow(db, DM9000_EPAR, offset);
 	iow(db, DM9000_EPCR, EPCR_ERPRR);
+
+	spin_unlock_irqrestore(&db->lock, flags);
+
 	mdelay(8);		/* according to the datasheet 200us should be enough,
 				   but it doesn't work */
+
+	spin_lock_irqsave(&db->lock, flags);
+
 	iow(db, DM9000_EPCR, 0x0);
 
 	to[0] = ior(db, DM9000_EPDRL);
 	to[1] = ior(db, DM9000_EPDRH);
 
+	spin_unlock_irqrestore(&db->lock, flags);
+
 	mutex_unlock(&db->addr_lock);
 }
 
@@ -1096,14 +1108,22 @@ dm9000_read_eeprom(board_info_t *db, int
 static void
 dm9000_write_eeprom(board_info_t *db, int offset, u8 *data)
 {
+	unsigned long flags;
+
 	mutex_lock(&db->addr_lock);
 
+	spin_lock_irqsave(&db->lock, flags);
 	iow(db, DM9000_EPAR, offset);
 	iow(db, DM9000_EPDRH, data[1]);
 	iow(db, DM9000_EPDRL, data[0]);
 	iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
+	spin_unlock_irqrestore(&db->lock, flags);
+
 	mdelay(8);		/* same shit */
+
+	spin_lock_irqsave(&db->lock, flags);
 	iow(db, DM9000_EPCR, 0);
+	spin_unlock_irqrestore(&db->lock, flags);
 
 	mutex_unlock(&db->addr_lock);
 }
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#27 lore raw

PATCH 16/24 DM9000: Remove unnecessary changelog in header comment

In reply to Ben Dooks

We have a perfectly good version control system, so we do not need to duplicate change comments in the header for this code.

drivers/net/dm9000.c +5 -40
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -1,7 +1,5 @@
 /*
- *   dm9000.c: Version 1.2 03/18/2003
- *
- *         A Davicom DM9000 ISA NIC fast Ethernet driver for Linux.
+ *      Davicom DM9000 Fast Ethernet driver for Linux.
  * 	Copyright (C) 1997  Sten Wang
  *
  * 	This program is free software; you can redistribute it and/or
@@ -14,44 +12,11 @@
  * 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * 	GNU General Public License for more details.
  *
- *   (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
- *
- * V0.11	06/20/2001	REG_0A bit3=1, default enable BP with DA match
- * 	06/22/2001 	Support DM9801 progrmming
- * 	 	 	E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000
- * 		 	E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200
- * 		     		R17 = (R17 & 0xfff0) | NF + 3
- * 		 	E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200
- * 		     		R17 = (R17 & 0xfff0) | NF
- *
- * v1.00               	modify by simon 2001.9.5
- *                         change for kernel 2.4.x
- *
- * v1.1   11/09/2001      	fix force mode bug
- *
- * v1.2   03/18/2003       Weilun Huang <[email protected]>:
- * 			Fixed phy reset.
- * 			Added tx/rx 32 bit mode.
- * 			Cleaned up for kernel merge.
- *
- *        03/03/2004    Sascha Hauer <[email protected]>
- *                      Port to 2.6 kernel
- *
- *	  24-Sep-2004   Ben Dooks <[email protected]>
- *			Cleanup of code to remove ifdefs
- *			Allowed platform device data to influence access width
- *			Reformatting areas of code
- *
- *        17-Mar-2005   Sascha Hauer <[email protected]>
- *                      * removed 2.4 style module parameters
- *                      * removed removed unused stat counter and fixed
- *                        net_device_stats
- *                      * introduced tx_timeout function
- *                      * reworked locking
+ * (C) Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
  *
- *	  01-Jul-2005   Ben Dooks <[email protected]>
- *			* fixed spinlock call without pointer
- *			* ensure spinlock is initialised
+ * Additional updates, Copyright:
+ *	Ben Dooks <[email protected]>
+ *	Sascha Hauer <[email protected]>
  */
 
 #include <linux/module.h>
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#28 lore raw

PATCH 17/24 DM9000: Use netif_msg to enable debugging options

In reply to Ben Dooks

Use the netif_msg_*() macros to enable the debugging based on the board's msg_enable field. The output still goes via the dev_dbg() macros, so will be tagged and output as appropriate.

drivers/net/dm9000.c +22 -6
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -714,7 +714,8 @@ dm9000_open(struct net_device *dev)
 	board_info_t *db = (board_info_t *) dev->priv;
 	unsigned long irqflags = db->irq_res->flags & IRQF_TRIGGER_MASK;
 
-	dev_dbg(db->dev, "entering %s\n", __func__);
+	if (netif_msg_ifup(db))
+		dev_dbg(db->dev, "enabling %s\n", dev->name);
 
 	/* If there is no IRQ type specified, default to something that
 	 * may work, and tell the user that this is a problem */
@@ -858,7 +859,8 @@ dm9000_stop(struct net_device *ndev)
 {
 	board_info_t *db = (board_info_t *) ndev->priv;
 
-	dm9000_dbg(db, 1, "entering %s\n", __func__);
+	if (netif_msg_ifdown(db))
+		dev_dbg(db->dev, "shutting down %s\n", ndev->name);
 
 	netif_stop_queue(ndev);
 	netif_carrier_off(ndev);
@@ -886,6 +888,9 @@ dm9000_tx_done(struct net_device *dev, b
 		db->tx_pkt_cnt--;
 		dev->stats.tx_packets++;
 
+		if (netif_msg_tx_done(db))
+			dev_dbg(db->dev, "tx done, NSR %02x\n", tx_status);
+
 		/* Queue packet check & send */
 		if (db->tx_pkt_cnt > 0) {
 			iow(db, DM9000_TXPLL, db->queue_pkt_len & 0xff);
@@ -921,6 +926,9 @@ dm9000_interrupt(int irq, void *dev_id)
 	int_status = ior(db, DM9000_ISR);	/* Got ISR */
 	iow(db, DM9000_ISR, int_status);	/* Clear ISR status */
 
+	if (netif_msg_intr(db))
+		dev_dbg(db->dev, "interrupt status %02x\n", int_status);
+
 	/* Received the coming packet */
 	if (int_status & ISR_PRS)
 		dm9000_rx(dev);
@@ -985,10 +993,15 @@ dm9000_rx(struct net_device *dev)
 
 		RxLen = le16_to_cpu(rxhdr.RxLen);
 
+		if (netif_msg_rx_status(db))
+			dev_dbg(db->dev, "RX: status %02x, length %04x\n",
+				rxhdr.RxStatus, RxLen);
+
 		/* Packet Status check */
 		if (RxLen < 0x40) {
 			GoodPacket = false;
-			dev_dbg(db->dev, "Bad Packet received (runt)\n");
+			if (netif_msg_rx_err(db))
+				dev_dbg(db->dev, "RX: Bad Packet (runt)\n");
 		}
 
 		if (RxLen > DM9000_PKT_MAX) {
@@ -998,15 +1011,18 @@ dm9000_rx(struct net_device *dev)
 		if (rxhdr.RxStatus & 0xbf) {
 			GoodPacket = false;
 			if (rxhdr.RxStatus & 0x01) {
-				dev_dbg(db->dev, "fifo error\n");
+				if (netif_msg_rx_err(db))
+					dev_dbg(db->dev, "fifo error\n");
 				dev->stats.rx_fifo_errors++;
 			}
 			if (rxhdr.RxStatus & 0x02) {
-				dev_dbg(db->dev, "crc error\n");
+				if (netif_msg_rx_err(db))
+					dev_dbg(db->dev, "crc error\n");
 				dev->stats.rx_crc_errors++;
 			}
 			if (rxhdr.RxStatus & 0x80) {
-				dev_dbg(db->dev, "length error\n");
+				if (netif_msg_rx_err(db))
+					dev_dbg(db->dev, "length error\n");
 				dev->stats.rx_length_errors++;
 			}
 		}
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#29 lore raw

PATCH 18/24 DM9000: Fix delays used by EEPROM read and write

In reply to Ben Dooks

The code was using a delay of 8ms, when it should have been using the EEPROM status flag from the device to indicate the EEPROM transaction had finished.

drivers/net/dm9000.c +51 -3
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -1051,6 +1051,50 @@ dm9000_rx(struct net_device *dev)
 	} while (rxbyte == DM9000_PKT_RDY);
 }
 
+static unsigned int
+dm9000_read_locked(board_info_t *db, int reg)
+{
+	unsigned long flags;
+	unsigned int ret;
+
+	spin_lock_irqsave(&db->lock, flags);
+	ret = ior(db, reg);
+	spin_unlock_irqrestore(&db->lock, flags);
+
+	return ret;
+}
+
+static int dm9000_wait_eeprom(board_info_t *db)
+{
+	unsigned int status;
+	int timeout = 8;	/* wait max 8msec */
+
+	/* The DM9000 data sheets say we should be able to
+	 * poll the ERRE bit in EPCR to wait for the EEPROM
+	 * operation. From testing several chips, this bit
+	 * does not seem to work. 
+	 *
+	 * We attempt to use the bit, but fall back to the
+	 * timeout (which is why we do not return an error
+	 * on expiry) to say that the EEPROM operation has
+	 * completed.
+	 */
+
+	while (1) {
+		status = dm9000_read_locked(db, DM9000_EPCR);
+
+		if ((status & EPCR_ERRE) == 0)
+			break;
+
+		if (timeout-- < 0) {
+			dev_dbg(db->dev, "timeout waiting EEPROM\n");
+			break;
+		}
+	}
+
+	return 0;
+}
+
 /*
  *  Read a word data from EEPROM
  */
@@ -1068,8 +1112,10 @@ dm9000_read_eeprom(board_info_t *db, int
 
 	spin_unlock_irqrestore(&db->lock, flags);
 
-	mdelay(8);		/* according to the datasheet 200us should be enough,
-				   but it doesn't work */
+	dm9000_wait_eeprom(db);
+
+	/* delay for at-least 150uS */
+	msleep(1);
 
 	spin_lock_irqsave(&db->lock, flags);
 
@@ -1100,7 +1146,9 @@ dm9000_write_eeprom(board_info_t *db, in
 	iow(db, DM9000_EPCR, EPCR_WEP | EPCR_ERPRW);
 	spin_unlock_irqrestore(&db->lock, flags);
 
-	mdelay(8);		/* same shit */
+	dm9000_wait_eeprom(db);
+
+	mdelay(1);	/* wait at least 150uS to clear */
 
 	spin_lock_irqsave(&db->lock, flags);
 	iow(db, DM9000_EPCR, 0);
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#30 lore raw

PATCH 19/24 DM9000: Remove cal_CRC() and use ether_crc_le instead

In reply to Ben Dooks

Remove the cal_CRC as this is basically wrappering the ether_crc_le function, and is only being used by the multicast hash table functions.

drivers/net/dm9000.c +9 -26
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -1158,24 +1158,6 @@ dm9000_write_eeprom(board_info_t *db, in
 }
 
 /*
- *  Calculate the CRC valude of the Rx packet
- *  flag = 1 : return the reverse CRC (for the received packet CRC)
- *         0 : return the normal CRC (for Hash Table index)
- */
-
-static unsigned long
-cal_CRC(unsigned char *Data, unsigned int Len, u8 flag)
-{
-
-       u32 crc = ether_crc_le(Len, Data);
-
-       if (flag)
-               return ~crc;
-
-       return crc;
-}
-
-/*
  *  Set DM9000 multicast address
  */
 static void
@@ -1184,15 +1166,16 @@ dm9000_hash_table(struct net_device *dev
 	board_info_t *db = (board_info_t *) dev->priv;
 	struct dev_mc_list *mcptr = dev->mc_list;
 	int mc_cnt = dev->mc_count;
+	int i, oft;
 	u32 hash_val;
-	u16 i, oft, hash_table[4];
+	u16 hash_table[4];
 	unsigned long flags;
 
 	dm9000_dbg(db, 1, "entering %s\n", __func__);
 
-	spin_lock_irqsave(&db->lock,flags);
+	spin_lock_irqsave(&db->lock, flags);
 
-	for (i = 0, oft = 0x10; i < 6; i++, oft++)
+	for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
 		iow(db, oft, dev->dev_addr[i]);
 
 	/* Clear Hash Table */
@@ -1204,17 +1187,17 @@ dm9000_hash_table(struct net_device *dev
 
 	/* the multicast address in Hash Table : 64 bits */
 	for (i = 0; i < mc_cnt; i++, mcptr = mcptr->next) {
-		hash_val = cal_CRC((char *) mcptr->dmi_addr, 6, 0) & 0x3f;
+		hash_val = ether_crc_le(6, mcptr->dmi_addr) & 0x3f;
 		hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
 	}
 
 	/* Write the hash table to MAC MD table */
-	for (i = 0, oft = 0x16; i < 4; i++) {
-		iow(db, oft++, hash_table[i] & 0xff);
-		iow(db, oft++, (hash_table[i] >> 8) & 0xff);
+	for (i = 0, oft = DM9000_MAR; i < 4; i++) {
+		iow(db, oft++, hash_table[i]);
+		iow(db, oft++, hash_table[i] >> 8);
 	}
 
-	spin_unlock_irqrestore(&db->lock,flags);
+	spin_unlock_irqrestore(&db->lock, flags);
 }
 
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#31 lore raw

PATCH 20/24 DM9000: Remove redudant use of "& 0xff"

In reply to Ben Dooks

The writing of the data should implicitly truncate the data to 8bits, so do not bother with the ands in the code.

drivers/net/dm9000.c +6 -6
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -817,8 +817,8 @@ dm9000_start_xmit(struct sk_buff *skb, s
 	/* TX control: First packet immediately send, second packet queue */
 	if (db->tx_pkt_cnt == 1) {
 		/* Set TX length to DM9000 */
-		iow(db, DM9000_TXPLL, skb->len & 0xff);
-		iow(db, DM9000_TXPLH, (skb->len >> 8) & 0xff);
+		iow(db, DM9000_TXPLL, skb->len);
+		iow(db, DM9000_TXPLH, skb->len >> 8);
 
 		/* Issue TX polling command */
 		iow(db, DM9000_TCR, TCR_TXREQ);	/* Cleared after TX complete */
@@ -893,8 +893,8 @@ dm9000_tx_done(struct net_device *dev, b
 
 		/* Queue packet check & send */
 		if (db->tx_pkt_cnt > 0) {
-			iow(db, DM9000_TXPLL, db->queue_pkt_len & 0xff);
-			iow(db, DM9000_TXPLH, (db->queue_pkt_len >> 8) & 0xff);
+			iow(db, DM9000_TXPLL, db->queue_pkt_len);
+			iow(db, DM9000_TXPLH, db->queue_pkt_len >> 8);
 			iow(db, DM9000_TCR, TCR_TXREQ);
 			dev->trans_start = jiffies;
 		}
@@ -1278,8 +1278,8 @@ dm9000_phy_write(struct net_device *dev,
 	iow(db, DM9000_EPAR, DM9000_PHY | reg);
 
 	/* Fill the written data into REG_0D & REG_0E */
-	iow(db, DM9000_EPDRL, (value & 0xff));
-	iow(db, DM9000_EPDRH, ((value >> 8) & 0xff));
+	iow(db, DM9000_EPDRL, value);
+	iow(db, DM9000_EPDRH, value >> 8);
 
 	iow(db, DM9000_EPCR, 0xa);	/* Issue phyxcer write command */
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#32 lore raw

PATCH 21/24 DM9000: Add platform flag for no attached EEPROM

In reply to Ben Dooks

Allow the platform data to specify to the DM9000 driver that there is no posibility of an attached EEPROM on the device, so default all reads to 0xff and ignore any write operations.

drivers/net/dm9000.c +15 -0
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -405,6 +405,9 @@ static int dm9000_get_eeprom(struct net_
 	if ((len & 1) != 0 || (offset & 1) != 0)
 		return -EINVAL;
 
+	if (dm->flags & DM9000_PLATF_NO_EEPROM)
+		return -ENOENT;
+
 	ee->magic = DM_EEPROM_MAGIC;
 
 	for (i = 0; i < len; i += 2)
@@ -426,6 +429,9 @@ static int dm9000_set_eeprom(struct net_
 	if ((len & 1) != 0 || (offset & 1) != 0)
 		return -EINVAL;
 
+	if (dm->flags & DM9000_PLATF_NO_EEPROM)
+		return -ENOENT;
+
 	if (ee->magic != DM_EEPROM_MAGIC)
 		return -EINVAL;
 
@@ -1103,6 +1109,12 @@ dm9000_read_eeprom(board_info_t *db, int
 {
 	unsigned long flags;
 
+	if (db->flags & DM9000_PLATF_NO_EEPROM) {
+		to[0] = 0xff;
+		to[1] = 0xff;
+		return;
+	}
+
 	mutex_lock(&db->addr_lock);
 
 	spin_lock_irqsave(&db->lock, flags);
@@ -1137,6 +1149,9 @@ dm9000_write_eeprom(board_info_t *db, in
 {
 	unsigned long flags;
 
+	if (db->flags & DM9000_PLATF_NO_EEPROM)
+		return;
+
 	mutex_lock(&db->addr_lock);
 
 	spin_lock_irqsave(&db->lock, flags);
include/linux/dm9000.h +1 -0
Index: linux-2.6.24-quilt3/include/linux/dm9000.h
===================================================================
@@ -20,6 +20,7 @@
 #define DM9000_PLATF_16BITONLY	(0x0002)
 #define DM9000_PLATF_32BITONLY	(0x0004)
 #define DM9000_PLATF_EXT_PHY	(0x0008)
+#define DM9000_PLATF_NO_EEPROM	(0x0010)
 
 /* platfrom data for platfrom device structure's platfrom_data field */
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#33 lore raw

PATCH 22/24 DM9000: Add support for MII ioctl() calls

In reply to Ben Dooks

Add entry to handle the MII ioctl() calls via the
generic_mii_ioctl call.

drivers/net/dm9000.c +12 -0
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -142,6 +142,7 @@ static int dm9000_probe(struct platform_
 static int dm9000_open(struct net_device *);
 static int dm9000_start_xmit(struct sk_buff *, struct net_device *);
 static int dm9000_stop(struct net_device *);
+static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd);
 
 static void dm9000_init_dm9000(struct net_device *);
 
@@ -332,6 +333,16 @@ static void dm9000_poll_controller(struc
 }
 #endif
 
+static int dm9000_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
+{
+	board_info_t *dm = to_dm9000_board(dev);
+
+	if (!netif_running(dev))
+		return -EINVAL;
+
+	return generic_mii_ioctl(&dm->mii, if_mii(req), cmd, NULL);
+}
+
 /* ethtool ops */
 
 static void dm9000_get_drvinfo(struct net_device *dev,
@@ -661,6 +672,7 @@ dm9000_probe(struct platform_device *pde
 	ndev->stop		 = &dm9000_stop;
 	ndev->set_multicast_list = &dm9000_hash_table;
 	ndev->ethtool_ops	 = &dm9000_ethtool_ops;
+	ndev->do_ioctl		 = &dm9000_ioctl;
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
 	ndev->poll_controller	 = &dm9000_poll_controller;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#34 lore raw

PATCH 23/24 DM9000: Update retry count whilst identifying chip

In reply to Ben Dooks

Reading the ID register does not always return the correct ID from the device, so we retry several times to see if we get a correct value.

These failures seem to be excaserbated by the speed of the access to the chip (possibly time between issuing the address and then the data cycle).

drivers/net/dm9000.c +1 -1
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -643,7 +643,7 @@ dm9000_probe(struct platform_device *pde
 	dm9000_reset(db);
 
 	/* try two times, DM9000 sometimes gets the first read wrong */
-	for (i = 0; i < 2; i++) {
+	for (i = 0; i < 8; i++) {
 		id_val  = ior(db, DM9000_VIDL);
 		id_val |= (u32)ior(db, DM9000_VIDH) << 8;
 		id_val |= (u32)ior(db, DM9000_PIDL) << 16;
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
author
#35 lore raw

PATCH 24/24 DM9000: Show the MAC address source after printing MAC

In reply to Ben Dooks

Show whether the MAC address was read from the EEPROM or the onboard PAR registers.

drivers/net/dm9000.c +7 -3
Index: linux-2.6.24-quilt3/drivers/net/dm9000.c
===================================================================
@@ -509,6 +509,7 @@ dm9000_probe(struct platform_device *pde
 	struct dm9000_plat_data *pdata = pdev->dev.platform_data;
 	struct board_info *db;	/* Point a board information structure */
 	struct net_device *ndev;
+	const unsigned char *mac_src;
 	unsigned long base;
 	int ret = 0;
 	int iosize;
@@ -687,13 +688,16 @@ dm9000_probe(struct platform_device *pde
 	db->mii.mdio_read    = dm9000_phy_read;
 	db->mii.mdio_write   = dm9000_phy_write;
 
+	mac_src = "eeprom";
+
 	/* try reading the node address from the attached EEPROM */
 	for (i = 0; i < 6; i += 2)
 		dm9000_read_eeprom(db, i / 2, ndev->dev_addr+i);
 
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
 		/* try reading from mac */
-
+		
+		mac_src = "chip";
 		for (i = 0; i < 6; i++)
 			ndev->dev_addr[i] = ior(db, i+DM9000_PAR);
 	}
@@ -707,9 +711,9 @@ dm9000_probe(struct platform_device *pde
 
 	if (ret == 0) {
 		DECLARE_MAC_BUF(mac);
-		printk("%s: dm9000 at %p,%p IRQ %d MAC: %s\n",
+		printk("%s: dm9000 at %p,%p IRQ %d MAC: %s (%s)\n",
 		       ndev->name,  db->io_addr, db->io_data, ndev->irq,
-		       print_mac(mac, ndev->dev_addr));
+		       print_mac(mac, ndev->dev_addr), mac_src);
 	}
 	return 0;
 
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#36 lore raw
In reply to Ben Dooks
Quoted 1 line · On Tue, 05 Feb 2008 00:01:59 +0000 Ben Dooks <[email protected]> wrote:

Subject: [PATCH 00/24 for-2.6.25] DM9000 updates for 2.6.25

Holy cow.

Quoted 4 lines

This patch set is a series of updates for the DM9000 driver, to tidy-up some of the source, stop the accesses to the PHY and EEPROM sitting and spinning with locks held, and to add ethtool support.

Jeff, the immediate issue is that the driver doesn't compile on mips. I have the below lameo fix for it, but it appears to be wrong. Or at least suboptimal.

So if you're unprepared to chew on this lot (and 24 patches two weeks into the merge window is one hell of a chew) then we do need to get that regression fixed, at least.

From: Andrew Morton <[email protected]>

mips:

drivers/net/dm9000.c: In function `dm9000_open':
drivers/net/dm9000.c:627: error: `IRQT_RISING' undeclared (first use in this function) drivers/net/dm9000.c:627: error: (Each undeclared identifier is reported only once drivers/net/dm9000.c:627: error: for each function it appears in.)

Cc Daniel Mack <[email protected]>
Cc Russell King <[email protected]>

---

 drivers/net/dm9000.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/dm9000.c renamed from drivers/net/dm9000.c~drivers-net-dm9000c-vague-probably-wrong-build-fix +3 -1
diff -puN drivers/net/dm9000.c~drivers-net-dm9000c-vague-probably-wrong-build-fix drivers/net/dm9000.c
@@ -113,8 +113,10 @@
 #define writesw	outsw
 #define writesl	outsl
 #define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQF_TRIGGER_HIGH)
-#else
+#elif defined(ARM)
 #define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQT_RISING)
+#else
+#define DM9000_IRQ_FLAGS	(IRQF_SHARED)
 #endif
 
 /*

_

#37 lore raw
Quoted 12 lines · Andrew Morton
Quoted 1 line · On Tue, 05 Feb 2008 00:01:59 +0000 Ben Dooks <[email protected]> wrote:

Subject: [PATCH 00/24 for-2.6.25] DM9000 updates for 2.6.25

Holy cow.

Quoted 4 lines

This patch set is a series of updates for the DM9000 driver, to tidy-up some of the source, stop the accesses to the PHY and EEPROM sitting and spinning with locks held, and to add ethtool support.

Quoted 7 lines

Jeff, the immediate issue is that the driver doesn't compile on mips. I have the below lameo fix for it, but it appears to be wrong. Or at least suboptimal.

So if you're unprepared to chew on this lot (and 24 patches two weeks into the merge window is one hell of a chew) then we do need to get that regression fixed, at least.

To be fair, jeff has already acked most of these patches, this set is a repost hopefully without the offending patches.

Quoted 40 lines

From: Andrew Morton <[email protected]>

mips:

drivers/net/dm9000.c: In function `dm9000_open':
drivers/net/dm9000.c:627: error: `IRQT_RISING' undeclared (first use in this function) drivers/net/dm9000.c:627: error: (Each undeclared identifier is reported only once drivers/net/dm9000.c:627: error: for each function it appears in.)

Cc Daniel Mack <[email protected]>
Cc Russell King <[email protected]>

---

 drivers/net/dm9000.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff -puN drivers/net/dm9000.c~drivers-net-dm9000c-vague-probably-wrong-build-fix drivers/net/dm9000.c

drivers/net/dm9000.c renamed from drivers/net/dm9000.c~drivers-net-dm9000c-vague-probably-wrong-build-fix +3 -1
@@ -113,8 +113,10 @@
 #define writesw	outsw
 #define writesl	outsl
 #define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQF_TRIGGER_HIGH)
-#else
+#elif defined(ARM)
 #define DM9000_IRQ_FLAGS	(IRQF_SHARED | IRQT_RISING)
+#else
+#define DM9000_IRQ_FLAGS	(IRQF_SHARED)
 #endif
 
 /*

_

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#38 lore raw
In reply to Ben Dooks
Quoted 11 lines · Ben Dooks

This patch set is a series of updates for the DM9000 driver, to tidy-up some of the source, stop the accesses to the PHY and EEPROM sitting and spinning with locks held, and to add ethtool support.

This set includes a pair of patches from Laurent Pinchart for addition platform-data based configuration, please apply these from this if you can attribute these correctly to Laurent, otherwise ask Laurent to resubmit. I have signed-off-by both these patches, but would be equally happy acking them.

If you can apply the patches without a resubmission that's of course less work for me :-) Otherwise I can resubmit them.

Quoted 7 lines

The only missing item in this series is to replace the old timer based polling code. This series has been sitting long enough on my own trees, and having MII link status reports is not a driver-threatening bug.

Hopefully this series meets up to everyone's approval and can be applied whilst the current merge window is upon us.

Signature · 9 lines
Laurent Pinchart
CSE Semaphore Belgium

Chaussée de Bruxelles, 732A
B-1410 Waterloo
Belgium

T +32 (2) 387 42 59
F +32 (2) 387 42 75