Skip to contentSkip to conversation

Sun Fire v100 dmfe driver bug

Bug 9106 David Miller 2 participants 3 messages Jan 22, 2008 – Jan 23, 2008 Network drivers

lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

From: Grant Grundler <[email protected]>
Date: Sun, 6 Jan 2008 01:35:32 -0700

[ Andrew, one of your warning fixes from yesteryear broke
SROM parsing in the DMFE tulip driver, see below. ]

Quoted 3 lines

Thanks! This was the case with the dmfe driver on SPARC. I've attached a patch as comment #6 on:
http://bugzilla.kernel.org/show_bug.cgi?id‘06

If there is no MAC address in the SROM you'll also have to handle the fact that there's almost guarenteed to not be any media mode data there either. Actually, there might be such information there and this could be a clue. See below.

This driver did work on sparc64 to some extent at some point in the past. So something did change over time to subtly break this thing.

The users log with the TX timeouts probably indicates that the chip cannot DMA properly or send to the network for whatever reason. Maybe the media type is wrong.

BTW, I noticed this while reading the DMFE code:

	db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
			TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);

That size looks strange, is this supposed to be:

	(TX_BUF_ALLOC * TX_DESC_CNT) + 4

or:

	TX_BUF_ALLOC * (TX_DESC_CNT + 4)

I think the latter is the intention, but the former is what is actually happening.

Looking through the driver history I definitely see some bugs introduced into the SROM code, for example:

	commit 16b110c3fd760620b4a787db6ed512fe531ab1b5
	Author: Andrew Morton <[email protected]>
	Date:   Mon Jun 20 15:32:59 2005 -0700

	[PATCH] dmfe warning fix

...
This is basically a guess:

drivers/net/tulip/dmfe.c +3 -2
@@ -1802,7 +1802,7 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
 	if ( ( (int) srom[18] & 0xff) = SROM_V41_CODE) {
 		/* SROM V4.01 */
 		/* Get NIC support media mode */
-		db->NIC_capability = le16_to_cpup(srom + 34);
+		db->NIC_capability = le16_to_cpup((__le16 *)srom + 34/2);
 		db->PHY_reg4 = 0;
 		for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
 			switch( db->NIC_capability & tmp_reg ) {
@@ -1814,7 +1814,8 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
 		}
 
 		/* Media Mode Force or not check */
-		dmfe_mode = le32_to_cpup(srom + 34) & le32_to_cpup(srom + 36);
+		dmfe_mode = le32_to_cpup((__le32 *)srom + 34/4) &
+				le32_to_cpup((__le32 *)srom + 36/4);
 		switch(dmfe_mode) {
 		case 0x4: dmfe_media_mode = DMFE_100MHF; break;	/* 100MHF */
 		case 0x2: dmfe_media_mode = DMFE_10MFD; break;	/* 10MFD */

Basically he is trying to deal with the fact that "srom" is a "char *" but the typing requires converting to 16-bit and 32-bit pointers so the offsets have to be adjusted.

But it is totally wrong in the cases where the offsets were not a multiple or 2 or 4, respectively. (hint: (34 % 4) = 2)

It would have been better to use expressions like:

	(__le16 *) (srom + 34)
	(__le32 *) (srom + 34)
	(__le32 *) (srom + 36)

So that change definitely subtly changed how the SROM is accessed and likely is a good explanation for certain bugs, maybe even this one we are discussing.

Thinking about this some more, these accesses are extremely queer. Why would it use 32-bit accesses here to two 32-bit datums which overlap, and "and" them together to figure out the 'dmfe_mode'?

This driver is in a bit of a state of disrepair. Who is Tobias Ringstrom (from MAINTAINERS) and when was the last time he did any maintainence on dmfe? He definitely hasn't done anything in the GIT era as I look through the changelog.

Anyways, here is a fix for the above regression, if that DMA sizing error above is a real one that will need a fix too:

[TULIP] DMFE: Fix SROM parsing regression.

Changeset 16b110c3fd760620b4a787db6ed512fe531ab1b5 (dmfe warning fix) bothed up the offsets read from the SROM so that it doesn't read the same datums it used to.

The change made transformations like turning:

	"srom + 34"

into

	"(__le32 *)srom + 34/4"

which doesn't work because 4 does not divide evenly into 34 so we're using a different pointer offset than in the original code.

I've changed theses cases in dmfe_parse_srom() to consistently use "(type *)(srom + offset)" preserving the offsets from the original code.

drivers/net/tulip/dmfe.c +3 -3
index b4891ca..6562004 100644
@@ -1909,7 +1909,7 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
 	if ( ( (int) srom[18] & 0xff) = SROM_V41_CODE) {
 		/* SROM V4.01 */
 		/* Get NIC support media mode */
-		db->NIC_capability = le16_to_cpup((__le16 *)srom + 34/2);
+		db->NIC_capability = le16_to_cpup((__le16 *) (srom + 34));
 		db->PHY_reg4 = 0;
 		for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
 			switch( db->NIC_capability & tmp_reg ) {
@@ -1921,8 +1921,8 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
 		}
 
 		/* Media Mode Force or not check */
-		dmfe_mode = le32_to_cpup((__le32 *)srom + 34/4) &
-				le32_to_cpup((__le32 *)srom + 36/4);
+		dmfe_mode = (le32_to_cpup((__le32 *) (srom + 34)) &
+			     le32_to_cpup((__le32 *) (srom + 36)));
 		switch(dmfe_mode) {
 		case 0x4: dmfe_media_mode = DMFE_100MHF; break;	/* 100MHF */
 		case 0x2: dmfe_media_mode = DMFE_10MFD; break;	/* 10MFD */
#1 lore raw
Quoted 2 lines · David Miller

This driver did work on sparc64 to some extent at some point in the past. So something did change over time to subtly break this thing.

Good - that gives me some hope it can be made to work again.

Quoted 2 lines

The users log with the TX timeouts probably indicates that the chip cannot DMA properly or send to the network for whatever reason.

Yes - or the interrupts aren't getting generated/delivered.

Quoted 9 lines

Maybe the media type is wrong.

BTW, I noticed this while reading the DMFE code:

	db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
			TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);

That size looks strange, is this supposed to be:

Quoted 8 lines
	(TX_BUF_ALLOC * TX_DESC_CNT) + 4

or:

	TX_BUF_ALLOC * (TX_DESC_CNT + 4)

I think the latter is the intention, but the former is what is actually happening.

Note the same thing is happening in the pci_free_consistent call.

After looking the code a bit, my guess would be the former was intended. I suspect this driver once suffered from alignment issues:
/* pointer for memory physical address */
dma_addr_t buf_pool_dma_ptr; /* Tx buffer pool memory */
dma_addr_t buf_pool_dma_start; /* Tx buffer pool align dword */
...

and I'm going a bit out on a limb here by guessing this line:

	db->buf_pool_dma_start = db->buf_pool_dma_ptr;

might used to read something like:

	db->buf_pool_dma_start = db->buf_pool_dma_ptr & ~3ULL;

or two lines:

        db->buf_pool_dma_start = db->buf_pool_dma_ptr;
        db->buf_pool_dma_ptr &= ~3ULL;

to guarantee the DMA pool had a 4-byte alignment. So I think the +4 can just be dropped.

Quoted 2 lines

Looking through the driver history I definitely see some bugs introduced into the SROM code, for example:

...

Quoted 2 lines

But it is totally wrong in the cases where the offsets were not a multiple or 2 or 4, respectively. (hint: (34 % 4) = 2)

Ouch. Good catch.

Quoted 5 lines

It would have been better to use expressions like:

	(__le16 *) (srom + 34)
	(__le32 *) (srom + 34)
	(__le32 *) (srom + 36)

Yes. This is in fact what the dmfe.c v1.43 driver from Davicom does:

#define DRV_NAME        "dmfe"
#define DRV_VERSION     "1.43"
#define DRV_RELDATE     "2005-07-14"
...
                /* Get NIC support media mode */
                db->NIC_capability = le16_to_cpup((u16 *)(srom + 34));
...
                /* Media Mode Force or not check */
                dmfe_mode = le32_to_cpup((u32 *)(srom + 34)) & le32_to_cpup((u32 *)(srom + 36));

Driver is available from:
http://www.davicom.com.tw/eng/download/Driver/driver_9102a.htm
http://www.davicom.com.tw/big5/download/Driver/dm9102a/dmfe_1.43.tar.gz

Quoted 3 lines

Thinking about this some more, these accesses are extremely queer. Why would it use 32-bit accesses here to two 32-bit datums which overlap, and "and" them together to figure out the 'dmfe_mode'?

Yeah, this looks wierd. But probably happens to work IFF only one bit is set of the 16 bits at offset 0x36 and NONE of the same bits are set at the 16 bits starting at offset 0x38. Given we only care about bits 1-3 (see "switch(dmfe_mode)"), this should be safe to convert to 16 bit accesses.

Quoted 4 lines

This driver is in a bit of a state of disrepair. Who is Tobias Ringstrom (from MAINTAINERS) and when was the last time he did any maintainence on dmfe? He definitely hasn't done anything in the GIT era as I look through the changelog.

http://ringstrom.mine.nu/

and seems to have started a family since 2003 or so :)
http://ringstrom.mine.nu/photo/

Google hasn't seen any contributions since about 2003. Mostly active in 2001 on the kernel.
Maybe time to orphan the driver or find a new maintainer?

Quoted 8 lines

Anyways, here is a fix for the above regression, if that DMA sizing error above is a real one that will need a fix too:

[TULIP] DMFE: Fix SROM parsing regression.

Changeset 16b110c3fd760620b4a787db6ed512fe531ab1b5 (dmfe warning fix) bothed up the offsets read from the SROM so that it doesn't read the same datums it used to.

In case it matters, looks good to me.

thanks,
grant

author maintainer
#2 lore raw
In reply to David Miller

From: Grant Grundler <[email protected]>
Date: Tue, 22 Jan 2008 23:19:50 -0700

Quoted 30 lines · David Miller
Quoted 7 lines

BTW, I noticed this while reading the DMFE code:

	db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
			TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);

That size looks strange, is this supposed to be:

Quoted 8 lines
	(TX_BUF_ALLOC * TX_DESC_CNT) + 4

or:

	TX_BUF_ALLOC * (TX_DESC_CNT + 4)

I think the latter is the intention, but the former is what is actually happening.

Note the same thing is happening in the pci_free_consistent call.

After looking the code a bit, my guess would be the former was intended. I suspect this driver once suffered from alignment issues:
/* pointer for memory physical address */
dma_addr_t buf_pool_dma_ptr; /* Tx buffer pool memory */
dma_addr_t buf_pool_dma_start; /* Tx buffer pool align dword */
...

and I'm going a bit out on a limb here by guessing this line:

	db->buf_pool_dma_start = db->buf_pool_dma_ptr;

might used to read something like:

Quoted 8 lines
	db->buf_pool_dma_start = db->buf_pool_dma_ptr & ~3ULL;

or two lines:

        db->buf_pool_dma_start = db->buf_pool_dma_ptr;
        db->buf_pool_dma_ptr &= ~3ULL;

to guarantee the DMA pool had a 4-byte alignment. So I think the +4 can just be dropped.

Great, since we are guarenteed at least PAGE_SIZE alignment from these allocations.

Quoted 1 line

Maybe time to orphan the driver or find a new maintainer?

It's a simple enough driver that if I had some cards I would be willing to keep an eye on it.

Quoted 10 lines
Quoted 8 lines

Anyways, here is a fix for the above regression, if that DMA sizing error above is a real one that will need a fix too:

[TULIP] DMFE: Fix SROM parsing regression.

Changeset 16b110c3fd760620b4a787db6ed512fe531ab1b5 (dmfe warning fix) bothed up the offsets read from the SROM so that it doesn't read the same datums it used to.

In case it matters, looks good to me.

Thanks for reviewing.