Fix some dubious code in the Renesas Ethernet drivers
Subsystems (3)
cover Fix some dubious code in the Renesas Ethernet drivers
Hello.
Here's a set of 2 patches against DaveM's 'net.git' repo. While initializing
EMAC the code tries to respect the duplex mode both programmed into ECMR and stored in its own private data -- this just can't be right.
[1/2] ravb: stop reading ECMR in ravb_emac_init() [2/2] sh_eth: stop reading ECMR in sh_eth_dev_init()
MBR, Sergei
PATCH 1/2 ravb: stop reading ECMR in ravb_emac_init()
The code in ravb_emac_init() twiddling the ECMR bits always looked a bit strange to me: if one intends to respect 'priv->duplex', why save old value
of the ECMR.DM bit? As all the other bits are zeroed anyway, we don't
really need to read ECMR before writing to it.
--- drivers/net/ethernet/renesas/ravb_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Index: net/drivers/net/ethernet/renesas/ravb_main.c =================================--- net.orig/drivers/net/ethernet/renesas/ravb_main.c +++ net/drivers/net/ethernet/renesas/ravb_main.c
@@ -338,16 +338,13 @@ error:
static void ravb_emac_init(struct net_device *ndev)
{
struct ravb_private *priv = netdev_priv(ndev);
- u32 ecmr;
/* Receive frame limit set register */
ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR);
/* PAUSE prohibition */
- ecmr = ravb_read(ndev, ECMR);
- ecmr &= ECMR_DM;
- ecmr |= ECMR_ZPF | (priv->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
- ravb_write(ndev, ecmr, ECMR);
+ ravb_write(ndev, ECMR_ZPF | (priv->duplex ? ECMR_DM : 0) |
+ ECMR_TE | ECMR_RE, ECMR);
ravb_set_rate(ndev);
PATCH 2/2 sh_eth: stop reading ECMR in sh_eth_dev_init()
In reply to Sergei ShtylyovThe code in sh_eth_dev_init() twiddling the ECMR bits always looked a bit strange to me: if one intends to respect 'mdp->duplex', why save old value of the ECMR.DM bit? As all the other bits are zeroed anyway, we don't really need to read ECMR before writing to it.
--- drivers/net/ethernet/renesas/sh_eth.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Index: net/drivers/net/ethernet/renesas/sh_eth.c =================================--- net.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net/drivers/net/ethernet/renesas/sh_eth.c
@@ -1289,7 +1289,6 @@ static int sh_eth_dev_init(struct net_de
{
int ret = 0;
struct sh_eth_private *mdp = netdev_priv(ndev);
- u32 val;
/* Soft Reset */
ret = sh_eth_reset(ndev);
@@ -1342,10 +1341,8 @@ static int sh_eth_dev_init(struct net_de
}
/* PAUSE Prohibition */
- val = (sh_eth_read(ndev, ECMR) & ECMR_DM) |
- ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE;
-
- sh_eth_write(ndev, val, ECMR);
+ sh_eth_write(ndev, ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) |
+ ECMR_TE | ECMR_RE, ECMR);
if (mdp->cd->set_rate)
mdp->cd->set_rate(ndev);
Re: [PATCH 1/2] ravb: stop reading ECMR in ravb_emac_init()
In reply to Sergei ShtylyovHi Sergei,
Quoted 4 lines · Sergei Shtylyov
The code in
ravb_emac_init()twiddling the ECMR bits always looked a bit strange to me: if one intends to respect 'priv->duplex', why save old value
of the ECMR.DM bit? As all the other bits are zeroed anyway, we don't
really need to read ECMR before writing to it.
Just an observation, I don't know about correctness: priv->duplex wasn't respected if ECMR_DM was already set before.
Same comment for the second patch.
Quoted 11 lines
Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/ethernet/renesas/ravb_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)Index:
net/drivers/net/ethernet/renesas/ravb_main.c=================================> ---net.orig/drivers/net/ethernet/renesas/ravb_main.c+++net/drivers/net/ethernet/renesas/ravb_main.c(quoted diff) +0
-0@@ -338,16 +338,13 @@ error: static void ravb_emac_init(struct net_device *ndev)
Review error: · line 348
Quoted 10 lines
(quoted diff) +0
-3{ struct ravb_private *priv = netdev_priv(ndev); - u32 ecmr; /* Receive frame limit set register */ ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR); /* PAUSE prohibition */ - ecmr = ravb_read(ndev, ECMR); - ecmr &= ECMR_DM;
Perhaps you misread as "ecmr &= ~ECMR_DM"?
Review error: · line 347
Quoted 4 lines
(quoted diff) +2
-2- ecmr |= ECMR_ZPF | (priv->duplex ? ECMR_DM : 0) | ECMR_TE | ECMR_RE; - ravb_write(ndev, ecmr, ECMR); + ravb_write(ndev, ECMR_ZPF | (priv->duplex ? ECMR_DM : 0) | + ECMR_TE | ECMR_RE, ECMR);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 1/2] ravb: stop reading ECMR in ravb_emac_init()
Hello.
Quoted 11 lines · Geert Uytterhoeven
Quoted 4 lines · Sergei Shtylyov
The code in
ravb_emac_init()twiddling the ECMR bits always looked a bit strange to me: if one intends to respect 'priv->duplex', why save old value
of the ECMR.DM bit? As all the other bits are zeroed anyway, we don't
really need to read ECMR before writing to it.Just an observation, I don't know about correctness:
priv->duplexwasn't respected ifECMR_DMwas already set before.Same comment for the second patch.
That's what the patches try to fix. Perhaps the description was too terse?
Quoted 15 lines
Quoted 15 lines
Signed-off-by Sergei Shtylyov <[email protected]>--- drivers/net/ethernet/renesas/ravb_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)Index:
net/drivers/net/ethernet/renesas/ravb_main.c=================================>> ---net.orig/drivers/net/ethernet/renesas/ravb_main.c+++net/drivers/net/ethernet/renesas/ravb_main.c(quoted diff) +0
-1@@ -338,16 +338,13 @@ error: static void ravb_emac_init(struct net_device *ndev) { struct ravb_private *priv = netdev_priv(ndev); - u32 ecmr;
Quoted 8 lines
Review error: · line 348
Quoted 6 lines
(quoted diff) +0
-2/* Receive frame limit set register */ ravb_write(ndev, ndev->mtu + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN, RFLR); /* PAUSE prohibition */ - ecmr = ravb_read(ndev, ECMR); - ecmr &= ECMR_DM;Perhaps you misread as "ecmr &= ~ECMR_DM"?
If it was so, there would be no point in patching...
[...]
Quoted 3 lines
Gr{oetje,eeting}s,
Geert
MBR, Sergei
David Miller
maintainerFrom: Sergei Shtylyov <[email protected]>
Date: Mon, 11 Jan 2016 00:26:07 +0300
Quoted 6 lines
Here's a set of 2 patches against DaveM's 'net.git' repo. While initializing
EMAC the code tries to respect the duplex mode both programmed into ECMR and stored in its own private data -- this just can't be right.[1/2] ravb: stop reading ECMR in
ravb_emac_init()[2/2]sh_eth: stop reading ECMR insh_eth_dev_init()
Series applied, thanks.