Skip to contentSkip to conversation

natsemi: make cable length magic configurable

PATCH In review Jean Delvare 4 participants 9 messages Nov 24, 2011 – Jul 17, 2012

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

PATCH 1/1 natsemi: make cable length magic configurable

From: Olaf Kirch <[email protected]>

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

The patch adds a module parameter named "no_cable_magic" that does two things:

- Unconditionally set the DSPCFG register to the
fixed value. Without this change, the chip apparently never completes autonegotiation in the tested configuration.

This has been an unconditional assignment for a long time, until this was changed in 2.6.11 (there's an interesting explanation in the ChangeLog, subject is
"[PATCH] natsemi long cable fix", bk commit is 5871b81bf2b5cf188deab0d414dce104fcb69ca6, git commit in tglx/history tree is c0d51c67f9c398279a95c5a7df387f2d9a586c98.

- Skip the bit banging in {,un}do_cable_magic. It seems that
if we write the DSPCFG register as above, a rev D chip will report all cables as "short cables", which do_cable_magic detects, and trying to be helpful it will "fix" the attenuation coefficient.

I admit the use of a module parameter is ugly, but I didn't find a sane way to fix this - especially since the magic registers we're changing are undocumented.

---
We have been including this patch in the SLES kernels since January 2007, and some POS customers still need that today.

 drivers/net/natsemi.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/net/ethernet/natsemi/natsemi.c +10 -3
@@ -83,6 +83,9 @@ static int rx_copybreak;
 
 static int dspcfg_workaround = 1;
 
+/* Set to disable cable magic - needed for very long cables on some chips */
+static int no_cable_magic;
+
 /* Used to pass the media type, etc.
    Both 'options[]' and 'full_duplex[]' should exist for driver
    interoperability.
@@ -141,6 +144,7 @@ module_param(mtu, int, 0);
 module_param(debug, int, 0);
 module_param(rx_copybreak, int, 0);
 module_param(dspcfg_workaround, int, 0);
+module_param(no_cable_magic, int, 0);
 module_param_array(options, int, NULL, 0);
 module_param_array(full_duplex, int, NULL, 0);
 MODULE_PARM_DESC(mtu, "DP8381x MTU (all boards)");
@@ -148,6 +152,9 @@ MODULE_PARM_DESC(debug, "DP8381x default
 MODULE_PARM_DESC(rx_copybreak,
 	"DP8381x copy breakpoint for copy-only-tiny-frames");
 MODULE_PARM_DESC(dspcfg_workaround, "DP8381x: control DspCfg workaround");
+MODULE_PARM_DESC(no_cable_magic,
+	"DP8381x: set to 1 to disable magic workaround for short cables "
+	"(may help with long cables");
 MODULE_PARM_DESC(options,
 	"DP8381x: Bits 0-3: media type, bit 17: full duplex");
 MODULE_PARM_DESC(full_duplex, "DP8381x full duplex setting(s) (1)");
@@ -1221,7 +1228,7 @@ static void init_phy_fixup(struct net_de
 		writew(1, ioaddr + PGSEL);
 		writew(PMDCSR_VAL, ioaddr + PMDCSR);
 		writew(TSTDAT_VAL, ioaddr + TSTDAT);
-		np->dspcfg = (np->srr <= SRR_DP83815_C)?
+		np->dspcfg = (np->srr <= SRR_DP83815_C || no_cable_magic) ?
 			DSPCFG_VAL : (DSPCFG_COEF | readw(ioaddr + DSPCFG));
 		writew(np->dspcfg, ioaddr + DSPCFG);
 		writew(SDCFG_VAL, ioaddr + SDCFG);
@@ -1587,7 +1594,7 @@ static void do_cable_magic(struct net_de
 	if (dev->if_port != PORT_TP)
 		return;
 
-	if (np->srr >= SRR_DP83816_A5)
+	if (np->srr >= SRR_DP83816_A5 || no_cable_magic)
 		return;
 
 	/*
@@ -1632,7 +1639,7 @@ static void undo_cable_magic(struct net_
 	if (dev->if_port != PORT_TP)
 		return;
 
-	if (np->srr >= SRR_DP83816_A5)
+	if (np->srr >= SRR_DP83816_A5 || no_cable_magic)
 		return;
 
 	writew(1, ioaddr + PGSEL);
Signature · 2 lines
Jean Delvare
Suse L3
#1 lore raw
Quoted 21 lines · Jean Delvare

From: Olaf Kirch <[email protected]>

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

The patch adds a module parameter named "no_cable_magic" that does two things:

- Unconditionally set the DSPCFG register to the
fixed value. Without this change, the chip apparently never completes autonegotiation in the tested configuration.

This has been an unconditional assignment for a long time, until this was changed in 2.6.11 (there's an interesting explanation in the ChangeLog, subject is
"[PATCH] natsemi long cable fix", bk commit is 5871b81bf2b5cf188deab0d414dce104fcb69ca6, git commit in tglx/history tree is c0d51c67f9c398279a95c5a7df387f2d9a586c98.

Quoted 8 lines

- Skip the bit banging in {,un}do_cable_magic. It seems that
if we write the DSPCFG register as above, a rev D chip will report all cables as "short cables", which do_cable_magic detects, and trying to be helpful it will "fix" the attenuation coefficient.

I admit the use of a module parameter is ugly, but I didn't find a sane way to fix this - especially since the magic registers we're changing are undocumented.

[...]

This could be implemented as an ethtool 'private flag'. However, the ethtool utility currently does not provide an interface to them. Perhaps you could implement both the private flag and the module parameter for now, and then drop the module parameter some time after the utility has been updated.

You would need to:
1. Number the flags starting from 0. Well, that was easy.
2. Implement {get,set}_priv_flags() operations to access all flags as a bitmask.
3. Expose the flag names as string set ETH_SS_PRIV_FLAGS accessed by get_sset_count() and get_strings() operations.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw

Hi Ben,

Thanks for you fast reply and sorry for my very slow one.

Quoted 30 lines · Ben Hutchings
Quoted 21 lines · Jean Delvare

From: Olaf Kirch <[email protected]>

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

The patch adds a module parameter named "no_cable_magic" that does two things:

- Unconditionally set the DSPCFG register to the
fixed value. Without this change, the chip apparently never completes autonegotiation in the tested configuration.

This has been an unconditional assignment for a long time, until this was changed in 2.6.11 (there's an interesting explanation in the ChangeLog, subject is
"[PATCH] natsemi long cable fix", bk commit is 5871b81bf2b5cf188deab0d414dce104fcb69ca6, git commit in tglx/history tree is c0d51c67f9c398279a95c5a7df387f2d9a586c98.

Quoted 8 lines

- Skip the bit banging in {,un}do_cable_magic. It seems that
if we write the DSPCFG register as above, a rev D chip will report all cables as "short cables", which do_cable_magic detects, and trying to be helpful it will "fix" the attenuation coefficient.

I admit the use of a module parameter is ugly, but I didn't find a sane way to fix this - especially since the magic registers we're changing are undocumented.

Quoted 7 lines

[...]

This could be implemented as an ethtool 'private flag'. However, the ethtool utility currently does not provide an interface to them. Perhaps you could implement both the private flag and the module parameter for now, and then drop the module parameter some time after the utility has been updated.

I see that you updated the ethtool utility meanwhile, thanks for doing that.

Quoted 6 lines

You would need to:
1. Number the flags starting from 0. Well, that was easy.
2. Implement {get,set}_priv_flags() operations to access all flags as a bitmask.
3. Expose the flag names as string set ETH_SS_PRIV_FLAGS accessed by get_sset_count() and get_strings() operations.

I was looking for an example, but there doesn't seem to be any driver implementing private flags at the moment?

I am also unsure if a private flag is a suitable solution to the problem at hand. I am a little worried about the timing, as the non-default value can't be set before the network device is available, I'm afraid the network initialization scripts may kick in before one has a chance to set the flag with ethtool. I suppose this could be problematic, but then again I don't know much about network device drivers, I don't even know for sure when method .ndo_open is called...

Furthermore I don't quite get why we can't just go with the module parameter. As I understand it, this is a crappy driver for crappy, rare hardware. The driver already has a module parameter to work around a hardware bug (dspcfg_workaround), I don't quite see why adding a second one would be a problem. At least it is consistent.

Thanks,

Signature · 2 lines
Jean Delvare
Suse L3
#3 lore raw

On Mon, 2012-07-16 at 14:26 +0200, Jean Delvare wrote:
[...]

Quoted 9 lines
Quoted 6 lines

You would need to:
1. Number the flags starting from 0. Well, that was easy.
2. Implement {get,set}_priv_flags() operations to access all flags as a bitmask.
3. Expose the flag names as string set ETH_SS_PRIV_FLAGS accessed by get_sset_count() and get_strings() operations.

I was looking for an example, but there doesn't seem to be any driver implementing private flags at the moment?

No.

Quoted 7 lines

I am also unsure if a private flag is a suitable solution to the problem at hand. I am a little worried about the timing, as the non-default value can't be set before the network device is available, I'm afraid the network initialization scripts may kick in before one has a chance to set the flag with ethtool. I suppose this could be problematic, but then again I don't know much about network device drivers, I don't even know for sure when method .ndo_open is called...

It's called when the interface is brought up (ifconfig up, ip link set up, start NetworkManager...). Some distributions provide a configuration option(s) to run ethtool while bringing an interface up.

Quoted 5 lines

Furthermore I don't quite get why we can't just go with the module parameter. As I understand it, this is a crappy driver for crappy, rare hardware. The driver already has a module parameter to work around a hardware bug (dspcfg_workaround), I don't quite see why adding a second one would be a problem. At least it is consistent.

David can be quite insistent about finding an alternative to module parameters.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw
Quoted 10 lines · Ben Hutchings
Quoted 5 lines · Jean Delvare

Furthermore I don't quite get why we can't just go with the module parameter. As I understand it, this is a crappy driver for crappy, rare hardware. The driver already has a module parameter to work around a hardware bug (dspcfg_workaround), I don't quite see why adding a second one would be a problem. At least it is consistent.

David can be quite insistent about finding an alternative to module parameters.

The hardware isn't that rare or bad - it's pretty widely deployed in 100Mbit systems (including lots of embedded ones) and performs well for the systems it's targetting. You'd not use it for a modern server but if what you need is 100M it's a fairly good part.

The dspcfg_workaround change was added for one specific board, I'd be really surprised if it were useful for anything other than the board it was originally developed for, I'd not be surprised to learn that it's a hardware issue in that board. It disables a documented erratum workaround to give a performance improvement, it was done for one board that for some reason triggered the erratum a lot but with less severe consequences than normal.

maintainer
#5 lore raw

From: Mark Brown <[email protected]>
Date: Mon, 16 Jul 2012 14:57:40 +0100

Quoted 9 lines · Ben Hutchings
Quoted 7 lines · Jean Delvare
Quoted 6 lines

Furthermore I don't quite get why we can't just go with the module parameter. As I understand it, this is a crappy driver for crappy, rare hardware. The driver already has a module parameter to work around a hardware bug (dspcfg_workaround), I don't quite see why adding a second one would be a problem. At least it is consistent.

Quoted 7 lines
Quoted 2 lines

David can be quite insistent about finding an alternative to module parameters.

The hardware isn't that rare or bad - it's pretty widely deployed in 100Mbit systems (including lots of embedded ones) and performs well for the systems it's targetting. You'd not use it for a modern server but if what you need is 100M it's a fairly good part.

I don't want to hear any excuses for not implementing a configuration interface properly. I'm sure if I allowed it, everyone would be able to come up with a special set of circumstances which justified the module parameter.

Sorry, no.

maintainer
#6 lore raw
In reply to Jean Delvare

From: Jean Delvare <[email protected]>
Date: Thu, 24 Nov 2011 14:43:59 +0100

Quoted 4 lines

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

Please do not add new private device driver module knobs.

Instead, add generic flags to the ethtool interface or similar to control device behavior.

#7 lore raw
Quoted 8 lines · David Miller

From: Jean Delvare <[email protected]>
Date: Thu, 24 Nov 2011 14:43:59 +0100

Quoted 4 lines

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

Quoted 4 lines

Please do not add new private device driver module knobs.

Instead, add generic flags to the ethtool interface or similar to control device behavior.

This isn't a generic flag; it seems to be a workaround for a specific bug that unfortunately can't be automatic.

That's why I suggested an ethtool private flag.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
maintainer
#8 lore raw

From: Ben Hutchings <[email protected]>
Date: Mon, 28 Nov 2011 17:51:04 +0000

Quoted 11 lines · David Miller
Quoted 10 lines

From: Jean Delvare <[email protected]>
Date: Thu, 24 Nov 2011 14:43:59 +0100

Quoted 4 lines

We had a customer report concerning problems with a Natsemi DP83815-D and long cables. With 100m cables, the network would be essentially dead, not a single packet would get through either way. We had to apply the patch below to make it work.

Please do not add new private device driver module knobs.

Quoted 7 lines
Quoted 2 lines

Instead, add generic flags to the ethtool interface or similar to control device behavior.

This isn't a generic flag; it seems to be a workaround for a specific bug that unfortunately can't be automatic.

That's why I suggested an ethtool private flag.

Fair enough.