ibm: emac: more cleanups
Subsystems (2)
v6 cover ibm: emac: more cleanups
Tested on Cisco MX60W.
v2: fixed build errors. Also added extra commits to clean the driver up further.
v3: Added tested message. Removed bad alloc_netdev_dummy commit.
v4: removed modules changes from patchset. Added fix for if MAC not found.
v5: added of_find_matching_node commit.
v6: resend after net-next merge.
Rosen Penev (7):
net: ibm: emac: use netif_receive_skb_list
net: ibm: emac: remove custom init/exit functions
net: ibm: emac: use devm_platform_ioremap_resource
net: ibm: emac: use platform_get_irq
net: ibm: emac: use devm for mutex_init
net: ibm: emac: generate random MAC if not found
net: ibm: emac: use of_find_matching_node
drivers/net/ethernet/ibm/emac/core.c | 91 ++++++++------------------- drivers/net/ethernet/ibm/emac/mal.c | 10 +-- drivers/net/ethernet/ibm/emac/mal.h | 4 -- drivers/net/ethernet/ibm/emac/rgmii.c | 10 +-- drivers/net/ethernet/ibm/emac/rgmii.h | 4 -- drivers/net/ethernet/ibm/emac/tah.c | 10 +-- drivers/net/ethernet/ibm/emac/tah.h | 4 -- drivers/net/ethernet/ibm/emac/zmii.c | 10 +-- drivers/net/ethernet/ibm/emac/zmii.h | 4 -- 9 files changed, 30 insertions(+), 117 deletions(-)
Signature · 1 line
2.47.0
PATCH v6 1/7 net: ibm: emac: use netif_receive_skb_list
Small rx improvement. Would use napi_gro_receive instead but that's a lot more involved than netif_receive_skb_list because of how the function is implemented.
Before:
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 51556 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 559 MBytes 467 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 48228 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.03 sec 558 MBytes 467 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 47600 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 557 MBytes 466 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 37252 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 559 MBytes 467 Mbits/sec
After:
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 40786 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 572 MBytes 478 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 52482 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 571 MBytes 477 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 48370 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 572 MBytes 478 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 46086 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.05 sec 571 MBytes 476 Mbits/sec
Quoted 1 line
iperf -c 192.168.1.1
------------------------------------------------------------
Client connecting to 192.168.1.1, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 1] local 192.168.1.101 port 46062 connected with 192.168.1.1 port 5001
[ ID] Interval Transfer Bandwidth
[ 1] 0.00-10.04 sec 572 MBytes 478 Mbits/sec
--- drivers/net/ethernet/ibm/emac/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +4 -2
@@ -1727,6 +1727,7 @@ static inline int emac_rx_sg_append(struct emac_instance *dev, int slot)/* NAPI poll context */ static int emac_poll_rx (void *param,int budget) { +LIST_HEAD (rx_list);struct emac_instance *dev = param;int slot = dev->rx_slot, received =0 ;
@@ -1783,8 +1784,7 @@ static int emac_poll_rx(void *param, int budget) skb->protocol =eth_type_trans (skb, dev->ndev);emac_rx_csum (dev, skb, ctrl); -if (unlikely (netif_receive_skb (skb) ==NET_RX_DROP )) - ++dev->estats.rx_dropped_stack; +list_add_tail (&skb->list, &rx_list); next: ++dev->stats.rx_packets; skip:
@@ -1828,6 +1828,8 @@ static int emac_poll_rx(void *param, int budget) goto next; } +netif_receive_skb_list (&rx_list); +if (received) {DBG2 (dev,"rx %d BDs" NL , received); dev->rx_slot = slot;
Signature · 1 line
2.47.0
Re: [PATCHv6 net-next 1/7] net: ibm: emac: use netif_receive_skb_list
Quoted 3 lines · Rosen Penev
Small rx improvement. Would use
napi_gro_receiveinstead but that's a lot more involved thannetif_receive_skb_listbecause of how the function is implemented.
...
Quoted 1 line
Signed-off-by Rosen Penev <[email protected]>
PATCH v6 2/7 net: ibm: emac: remove custom init/exit functions
In reply to Rosen Penevc092d0be38f4f754cdbdc76dc6df628ca48ac0eb introduced EPROBE_DEFER support. Because of that, we can defer initialization until all modules are ready instead of handling it explicitly with custom init/exit functions.
As a consequence of removing explicit module initialization and deferring probe until everything is ready, there's no need for custom init and exit functions.
There are now module_init and module_exit calls but no real change in functionality as these init and exit functions are no longer directly called by core.
--- drivers/net/ethernet/ibm/emac/core.c | 39 +-------------------------- drivers/net/ethernet/ibm/emac/mal.c | 10 +------ drivers/net/ethernet/ibm/emac/mal.h | 4 --- drivers/net/ethernet/ibm/emac/rgmii.c | 10 +------ drivers/net/ethernet/ibm/emac/rgmii.h | 4 --- drivers/net/ethernet/ibm/emac/tah.c | 10 +------ drivers/net/ethernet/ibm/emac/tah.h | 4 --- drivers/net/ethernet/ibm/emac/zmii.c | 10 +------ drivers/net/ethernet/ibm/emac/zmii.h | 4 --- 9 files changed, 5 insertions(+), 90 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +1 -38
@@ -3283,42 +3283,10 @@ static void __init emac_make_bootlist(void)static int __init emac_init (void ) { -int rc; - - printk(KERN_INFO DRV_DESC ", version " DRV_VERSION "\n"); -/* Build EMAC boot list */ emac_make_bootlist (); -/* Init submodules */ - rc =mal_init (); -if (rc) - goto err; - rc =zmii_init (); -if (rc) - goto err_mal; - rc =rgmii_init (); -if (rc) - goto err_zmii; - rc =tah_init (); -if (rc) - goto err_rgmii; - rc =platform_driver_register (&emac_driver); -if (rc) - goto err_tah; - -return 0 ; - - err_tah: -tah_exit (); - err_rgmii: -rgmii_exit (); - err_zmii: -zmii_exit (); - err_mal: -mal_exit (); - err: -return rc; +return platform_driver_register (&emac_driver); } static void __exit emac_exit(void)
@@ -3327,11 +3295,6 @@ static void __exit emac_exit(void)platform_driver_unregister (&emac_driver); -tah_exit (); -rgmii_exit (); -zmii_exit (); -mal_exit (); -/* Destroy EMAC boot list */ for (i =0 ; i <EMAC_BOOT_LIST_SIZE ; i++)of_node_put (emac_boot_list[i]);
drivers/net/ethernet/ibm/emac/mal.c +1 -9
@@ -781,12 +781,4 @@ static struct platform_driver mal_of_driver = { .remove = mal_remove, }; -int __init mal_init (void ) -{ -return platform_driver_register (&mal_of_driver); -} - -void mal_exit (void ) -{ -platform_driver_unregister (&mal_of_driver); -} +module_platform_driver (mal_of_driver);
drivers/net/ethernet/ibm/emac/mal.h +0 -4
@@ -252,10 +252,6 @@ static inline int mal_has_feature(struct mal_instance *dev, (MAL_FTRS_POSSIBLE & dev->features & feature); } -/* Register MAL devices */ -int mal_init (void ); -void mal_exit (void ); -int mal_register_commac (struct mal_instance *mal,struct mal_commac *commac); void mal_unregister_commac(struct mal_instance *mal,
drivers/net/ethernet/ibm/emac/rgmii.c +1 -9
@@ -303,12 +303,4 @@ static struct platform_driver rgmii_driver = { .remove = rgmii_remove, }; -int __init rgmii_init (void ) -{ -return platform_driver_register (&rgmii_driver); -} - -void rgmii_exit (void ) -{ -platform_driver_unregister (&rgmii_driver); -} +module_platform_driver (rgmii_driver);
drivers/net/ethernet/ibm/emac/rgmii.h +0 -4
@@ -52,8 +52,6 @@ struct rgmii_instance {#ifdef CONFIG_IBM_EMAC_RGMII -int rgmii_init (void ); -void rgmii_exit (void );int rgmii_attach (struct platform_device *ofdev,int input,int mode);void rgmii_detach (struct platform_device *ofdev,int input);void rgmii_get_mdio (struct platform_device *ofdev,int input);
@@ -64,8 +62,6 @@ void *rgmii_dump_regs(struct platform_device *ofdev, void *buf);#else -# define rgmii_init () 0 -# define rgmii_exit () do { } while(0)# define rgmii_attach (x,y,z) (-ENXIO)# define rgmii_detach (x,y) do { } while(0)# define rgmii_get_mdio (o,i) do { } while (0)
drivers/net/ethernet/ibm/emac/tah.c +1 -9
@@ -161,12 +161,4 @@ static struct platform_driver tah_driver = { .remove = tah_remove, }; -int __init tah_init (void ) -{ -return platform_driver_register (&tah_driver); -} - -void tah_exit (void ) -{ -platform_driver_unregister (&tah_driver); -} +module_platform_driver (tah_driver);
drivers/net/ethernet/ibm/emac/tah.h +0 -4
@@ -68,8 +68,6 @@ struct tah_instance {#ifdef CONFIG_IBM_EMAC_TAH -int tah_init (void ); -void tah_exit (void );int tah_attach (struct platform_device *ofdev,int channel);void tah_detach (struct platform_device *ofdev,int channel);void tah_reset (struct platform_device *ofdev);
@@ -78,8 +76,6 @@ void *tah_dump_regs(struct platform_device *ofdev, void *buf);#else -# define tah_init () 0 -# define tah_exit () do { } while(0)# define tah_attach (x,y) (-ENXIO)# define tah_detach (x,y) do { } while(0)# define tah_reset (x) do { } while(0)
drivers/net/ethernet/ibm/emac/zmii.c +1 -9
@@ -309,12 +309,4 @@ static struct platform_driver zmii_driver = { .remove = zmii_remove, }; -int __init zmii_init (void ) -{ -return platform_driver_register (&zmii_driver); -} - -void zmii_exit (void ) -{ -platform_driver_unregister (&zmii_driver); -} +module_platform_driver (zmii_driver);
drivers/net/ethernet/ibm/emac/zmii.h +0 -4
@@ -48,8 +48,6 @@ struct zmii_instance {#ifdef CONFIG_IBM_EMAC_ZMII -int zmii_init (void ); -void zmii_exit (void );int zmii_attach (struct platform_device *ofdev,int input,phy_interface_t *mode);void zmii_detach (struct platform_device *ofdev,int input);
@@ -60,8 +58,6 @@ int zmii_get_regs_len(struct platform_device *ocpdev);void *zmii_dump_regs (struct platform_device *ofdev,void *buf);#else -# define zmii_init () 0 -# define zmii_exit () do { } while(0)# define zmii_attach (x,y,z) (-ENXIO)# define zmii_detach (x,y) do { } while(0)# define zmii_get_mdio (x,y) do { } while(0)
Signature · 1 line
2.47.0
Simon Horman
reviewerRe: [PATCHv6 net-next 2/7] net: ibm: emac: remove custom init/exit functions
Quoted 1 line · Rosen Penev
c092d0be38f4f754cdbdc76dc6df628ca48ac0ebintroducedEPROBE_DEFER
The preferred way to cite commits in patch descriptions is like this:
commit c092d0be38f4 ("net: ibm: emac: remove all waiting code")
Something like this in gitconfig can be helpful.
[core]
abbrev = 12 [pretty] quote = commit %h (\"%s\") [alias] quote = log -1 --pretty=quote
Then the following should work:
$ git quote c092d0be38f4f754cdbdc76dc6df628ca48ac0eb
commit 71eb7f699755 ("net: ibm: emac: use netif_receive_skb_list")Quoted 8 lines
support. Because of that, we can defer initialization until all modules are ready instead of handling it explicitly with custom init/exit functions.
As a consequence of removing explicit module initialization and deferring probe until everything is ready, there's no need for custom init and exit functions.
Quoted 5 lines
There are now
module_initandmodule_exitcalls but no real change in functionality as these init and exit functions are no longer directly called by core.Signed-off-by Rosen Penev <[email protected]>
Otherwise, LGTM.
PATCH v6 3/7 net: ibm: emac: use devm_platform_ioremap_resource
In reply to Rosen PenevNo need to have a struct resource. Gets rid of the TODO.
--- drivers/net/ethernet/ibm/emac/core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +3 -5
@@ -3050,12 +3050,10 @@ static int emac_probe(struct platform_device *ofdev) ndev->irq = dev->emac_irq; -/* Map EMAC regs */ -// TODO : platform_get_resource() and devm_ioremap_resource() - dev->emacp =devm_of_iomap (&ofdev->dev, np,0 ,NULL ); -if (!dev->emacp) { + dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (dev->emacp)) {dev_err (&ofdev->dev,"can't map device registers" ); - err = -ENOMEM ; + err =PTR_ERR (dev->emacp); goto err_gone; }
Signature · 1 line
2.47.0
Re: [PATCHv6 net-next 3/7] net: ibm: emac: use devm_platform_ioremap_resource
Quoted 3 lines · Rosen Penev
No need to have a struct resource. Gets rid of the TODO.
Signed-off-by Rosen Penev <[email protected]>
PATCH v6 4/7 net: ibm: emac: use platform_get_irq
In reply to Rosen PenevNo need for irq_of_parse_and_map since we have platform_device.
--- drivers/net/ethernet/ibm/emac/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +1 -8
@@ -3031,15 +3031,8 @@ static int emac_probe(struct platform_device *ofdev)if (err) goto err_gone; -/* Get interrupts. EMAC irq is mandatory */ - dev->emac_irq =irq_of_parse_and_map (np,0 ); -if (!dev->emac_irq) { -printk (KERN_ERR "%pOF: Can't map main interrupt\n" , np); - err = -ENODEV ; - goto err_gone; - } -/* Setup error IRQ handler */ + dev->emac_irq =platform_get_irq (ofdev,0 ); err =devm_request_irq (&ofdev->dev, dev->emac_irq, emac_irq,0 ,"EMAC" , dev);if (err) {
Signature · 1 line
2.47.0
Re: [PATCHv6 net-next 4/7] net: ibm: emac: use platform_get_irq
Quoted 3 lines · Rosen Penev
No need for
irq_of_parse_and_mapsince we haveplatform_device.Signed-off-by Rosen Penev <[email protected]>
PATCH v6 5/7 net: ibm: emac: use devm for mutex_init
In reply to Rosen PenevIt seems since inception that mutex_destroy was never called for these in _remove. Instead of handling this manually, just use devm for simplicity.
--- drivers/net/ethernet/ibm/emac/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +8 -2
@@ -3021,8 +3021,14 @@ static int emac_probe(struct platform_device *ofdev)SET_NETDEV_DEV (ndev, &ofdev->dev);/* Initialize some embedded data structures */ -mutex_init (&dev->mdio_lock); -mutex_init (&dev->link_lock); + err =devm_mutex_init (&ofdev->dev, &dev->mdio_lock); +if (err) +return err; + + err =devm_mutex_init (&ofdev->dev, &dev->link_lock); +if (err) +return err; +spin_lock_init (&dev->lock);INIT_WORK (&dev->reset_work, emac_reset_work);
Signature · 1 line
2.47.0
Simon Horman
reviewerRe: [PATCHv6 net-next 5/7] net: ibm: emac: use devm for mutex_init
Quoted 14 lines · Rosen Penev
It seems since inception that
mutex_destroywas never called for these in_remove. Instead of handling this manually, just use devm for simplicity.Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/net/ethernet/ibm/emac/core.c +0
-0
drivers/net/ethernet/ibm/emac/core.c static int emac_probe(struct platform_device *ofdev) · line 3026
Quoted 8 lines
drivers/net/ethernet/ibm/emac/core.c +3
-2@@ -3021,8 +3021,14 @@ static int emac_probe(struct platform_device *ofdev)SET_NETDEV_DEV (ndev, &ofdev->dev);/* Initialize some embedded data structures */ -mutex_init (&dev->mdio_lock); -mutex_init (&dev->link_lock); + err =devm_mutex_init (&ofdev->dev, &dev->mdio_lock); +if (err) +return err;
Hi Rosen,
It looks like this should be:
goto err_gone;
drivers/net/ethernet/ibm/emac/core.c static int emac_probe(struct platform_device *ofdev) · line 3030
Quoted 4 lines
drivers/net/ethernet/ibm/emac/core.c +4
-0+ + err =devm_mutex_init (&ofdev->dev, &dev->link_lock); +if (err) +return err;
Ditto.
Quoted 3 lines
drivers/net/ethernet/ibm/emac/core.c +1
-0+spin_lock_init (&dev->lock);INIT_WORK (&dev->reset_work, emac_reset_work);
Signature · 1 line
pw-bot: cr
PATCH v6 6/7 net: ibm: emac: generate random MAC if not found
In reply to Rosen PenevOn this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.
In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.
Match behavior with other drivers to have a working ethernet interface.
--- drivers/net/ethernet/ibm/emac/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +6 -3
@@ -2937,9 +2937,12 @@ static int emac_init_config(struct emac_instance *dev)/* Read MAC-address */ err =of_get_ethdev_address (np, dev->ndev); -if (err) -return dev_err_probe (&dev->ofdev->dev, err, -"Can't get valid [local-]mac-address from OF !\n" ); +if (err == -EPROBE_DEFER ) +return err; +if (err) { +dev_warn (&dev->ofdev->dev,"Can't get valid mac-address. Generating random." ); +eth_hw_addr_random (dev->ndev); + }/* IAHT and GAHT filter parameterization */ if (emac_has_feature (dev,EMAC_FTR_EMAC4SYNC )) {
Signature · 1 line
2.47.0
Simon Horman
reviewerRe: [PATCHv6 net-next 6/7] net: ibm: emac: generate random MAC if not found
Quoted 21 lines · Rosen Penev
On this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.
In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.
Match behavior with other drivers to have a working ethernet interface.
Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/net/ethernet/ibm/emac/core.c +0
-0@@ -2937,9 +2937,12 @@ static int emac_init_config(struct emac_instance *dev)/* Read MAC-address */
drivers/net/ethernet/ibm/emac/core.c static int emac_init_config(struct emac_instance *dev) · line 2945
Quoted 10 lines
drivers/net/ethernet/ibm/emac/core.c +6
-3err =of_get_ethdev_address (np, dev->ndev); -if (err) -return dev_err_probe (&dev->ofdev->dev, err, -"Can't get valid [local-]mac-address from OF !\n" ); +if (err == -EPROBE_DEFER ) +return err; +if (err) { +dev_warn (&dev->ofdev->dev,"Can't get valid mac-address. Generating random." ); +eth_hw_addr_random (dev->ndev); + }
The above seems to take the random path for all errors other than -EPROBE_DEFER. That seems too broad to me, and perhaps it would be better to be more specific. Assuming the case that needs
to be covered is -EINVAL (a guess on my part), perhaps something like this would work? (Completely untested!)
err = of_get_ethdev_address(np, dev->ndev);
if (err == -EINVAL) {
/* An explanation should go here, mentioning Cisco MX60W
* Maybe the logic should even be specific to that hw?
*/
dev_warn(&dev->ofdev->dev, "Can't get valid mac-address. Generating random.");
eth_hw_addr_random(dev->ndev);
} else if (err) {
return dev_err_probe(&dev->ofdev->dev, err,
"Can't get valid [local-]mac-address from OF !\n");
}Also, should this be a bug fix with a Fixes tag for net?
Quoted 6 lines
drivers/net/ethernet/ibm/emac/core.c +0
-0/* IAHT and GAHT filter parameterization */ if (emac_has_feature (dev,EMAC_FTR_EMAC4SYNC )) {Signature · 1 line
2.47.0
Re: [PATCHv6 net-next 6/7] net: ibm: emac: generate random MAC if not found
Quoted 40 lines · Simon Horman
Quoted 21 lines · Rosen Penev
On this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.
In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.
Match behavior with other drivers to have a working ethernet interface.
Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/net/ethernet/ibm/emac/core.c +0
-0@@ -2937,9 +2937,12 @@ static int emac_init_config(struct emac_instance *dev)/* Read MAC-address */ drivers/net/ethernet/ibm/emac/core.c static int emac_init_config(struct emac_instance *dev) · line 2945
Quoted 10 lines
drivers/net/ethernet/ibm/emac/core.c +6
-3err =of_get_ethdev_address (np, dev->ndev); -if (err) -return dev_err_probe (&dev->ofdev->dev, err, -"Can't get valid [local-]mac-address from OF !\n" ); +if (err == -EPROBE_DEFER ) +return err; +if (err) { +dev_warn (&dev->ofdev->dev,"Can't get valid mac-address. Generating random." ); +eth_hw_addr_random (dev->ndev); + }The above seems to take the random path for all errors other than -EPROBE_DEFER. That seems too broad to me, and perhaps it would be better to be more specific. Assuming the case that needs
to be covered is-EINVAL(a guess on my part), perhaps something like this would work? (Completely untested!)
Quoted 11 lines
err = of_get_ethdev_address(np, dev->ndev);
if (err == -EINVAL) {
/* An explanation should go here, mentioning Cisco MX60W
* Maybe the logic should even be specific to that hw?
*/
dev_warn(&dev->ofdev->dev, "Can't get valid mac-address. Generating random.");
eth_hw_addr_random(dev->ndev);
} else if (err) {
return dev_err_probe(&dev->ofdev->dev, err,
"Can't get valid [local-]mac-address from OF !\n");
}That's just yak shaving. besides 0 and EPROBE_DEFER, of_get_ethdev_address returns ENODEV, EINVAL, and maybe something else. I don't see a good enough reason to diverge from convention here. This same pattern is present in other drivers.
Quoted 2 lines
Also, should this be a bug fix with a Fixes tag for net?
No. It's more of a feature honestly.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/ibm/emac/core.c +0
-1/* IAHT and GAHT filter parameterization */ if (emac_has_feature (dev,EMAC_FTR_EMAC4SYNC )) { --2.47.0
Simon Horman
reviewerRe: [PATCHv6 net-next 6/7] net: ibm: emac: generate random MAC if not found
Quoted 52 lines · Rosen Penev
Quoted 40 lines · Simon Horman
Quoted 21 lines · Rosen Penev
On this Cisco MX60W, u-boot sets the local-mac-address property. Unfortunately by default, the MAC is wrong and is actually located on a UBI partition. Which means nvmem needs to be used to grab it.
In the case where that fails, EMAC fails to initialize instead of generating a random MAC as many other drivers do.
Match behavior with other drivers to have a working ethernet interface.
Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)drivers/net/ethernet/ibm/emac/core.c +0
-0@@ -2937,9 +2937,12 @@ static int emac_init_config(struct emac_instance *dev)/* Read MAC-address */ drivers/net/ethernet/ibm/emac/core.c static int emac_init_config(struct emac_instance *dev) · line 2945
Quoted 10 lines
drivers/net/ethernet/ibm/emac/core.c +6
-3err =of_get_ethdev_address (np, dev->ndev); -if (err) -return dev_err_probe (&dev->ofdev->dev, err, -"Can't get valid [local-]mac-address from OF !\n" ); +if (err == -EPROBE_DEFER ) +return err; +if (err) { +dev_warn (&dev->ofdev->dev,"Can't get valid mac-address. Generating random." ); +eth_hw_addr_random (dev->ndev); + }The above seems to take the random path for all errors other than -EPROBE_DEFER. That seems too broad to me, and perhaps it would be better to be more specific. Assuming the case that needs
to be covered is-EINVAL(a guess on my part), perhaps something like this would work? (Completely untested!)Quoted 11 lines
err = of_get_ethdev_address(np, dev->ndev); if (err == -EINVAL) { /* An explanation should go here, mentioning Cisco MX60W * Maybe the logic should even be specific to that hw? */ dev_warn(&dev->ofdev->dev, "Can't get valid mac-address. Generating random."); eth_hw_addr_random(dev->ndev); } else if (err) { return dev_err_probe(&dev->ofdev->dev, err, "Can't get valid [local-]mac-address from OF !\n"); }
Quoted 4 lines
That's just yak shaving. besides 0 and
EPROBE_DEFER,of_get_ethdev_addressreturns ENODEV, EINVAL, and maybe something else. I don't see a good enough reason to diverge from convention here. This same pattern is present in other drivers.
I assumed that more specific error detection would be appropriate, because it seemed to be a rather specific case. But if the pattern is present in other drivers, then that is fine.
Quoted 11 lines
Quoted 2 lines
Also, should this be a bug fix with a Fixes tag for net?
No. It's more of a feature honestly.
Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/ibm/emac/core.c +0
-1/* IAHT and GAHT filter parameterization */ if (emac_has_feature (dev,EMAC_FTR_EMAC4SYNC )) { --2.47.0
PATCH v6 7/7 net: ibm: emac: use of_find_matching_node
In reply to Rosen PenevCleaner than using of_find_all_nodes and then of_match_node.
Also modified EMAC_BOOT_LIST_SIZE check to run before of_node_get to avoid having to call of_node_put on failure.
--- drivers/net/ethernet/ibm/emac/core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +3 -7
@@ -3253,21 +3253,17 @@ static void __init emac_make_bootlist(void)int cell_indices[EMAC_BOOT_LIST_SIZE ];/* Collect EMACs */ -while ((np =of_find_all_nodes (np)) !=NULL ) { +while ((np =of_find_matching_node (np, emac_match))) {u32 idx; -if (of_match_node (emac_match, np) ==NULL ) -continue ;if (of_property_read_bool (np,"unused" ))continue ;if (of_property_read_u32 (np,"cell-index" , &idx))continue ; cell_indices[i] = idx; - emac_boot_list[i++] =of_node_get (np); -if (i >=EMAC_BOOT_LIST_SIZE ) { -of_node_put (np); +if (i >=EMAC_BOOT_LIST_SIZE )break ; - } + emac_boot_list[i++] =of_node_get (np); } max = i;
Signature · 1 line
2.47.0
Simon Horman
reviewerRe: [PATCHv6 net-next 7/7] net: ibm: emac: use of_find_matching_node
Quoted 26 lines · Rosen Penev
Cleaner than using
of_find_all_nodesand thenof_match_node.Also modified
EMAC_BOOT_LIST_SIZEcheck to run beforeof_node_getto avoid having to callof_node_puton failure.Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/net/ethernet/ibm/emac/core.c +1
-3@@ -3253,21 +3253,17 @@ static void __init emac_make_bootlist(void)int cell_indices[EMAC_BOOT_LIST_SIZE ];/* Collect EMACs */ -while ((np =of_find_all_nodes (np)) !=NULL ) { +while ((np =of_find_matching_node (np, emac_match))) {u32 idx; -if (of_match_node (emac_match, np) ==NULL ) -continue ;if (of_property_read_bool (np,"unused" ))continue ;
drivers/net/ethernet/ibm/emac/core.c static void __init emac_make_bootlist(void) · line 3266
Quoted 10 lines
drivers/net/ethernet/ibm/emac/core.c +2
-4if (of_property_read_u32 (np,"cell-index" , &idx))continue ; cell_indices[i] = idx; - emac_boot_list[i++] =of_node_get (np); -if (i >=EMAC_BOOT_LIST_SIZE ) { -of_node_put (np); +if (i >=EMAC_BOOT_LIST_SIZE )break ; - } + emac_boot_list[i++] =of_node_get (np);
Reading the Kernel doc for of_find_matching_node() it seems that of_node_put() needs to called each time it (and thus of_find_matching_node() returns a np. But that doesn't seem to be the case here. Am I mistaken?
Quoted 6 lines
drivers/net/ethernet/ibm/emac/core.c +0
-0} max = i;Signature · 1 line
2.47.0
Re: [PATCHv6 net-next 7/7] net: ibm: emac: use of_find_matching_node
Quoted 35 lines · Simon Horman
Quoted 33 lines · Rosen Penev
Cleaner than using
of_find_all_nodesand thenof_match_node.Also modified
EMAC_BOOT_LIST_SIZEcheck to run beforeof_node_getto avoid having to callof_node_puton failure.Signed-off-by Rosen Penev <[email protected]>--- drivers/net/ethernet/ibm/emac/core.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)drivers/net/ethernet/ibm/emac/core.c +2
-6@@ -3253,21 +3253,17 @@ static void __init emac_make_bootlist(void)int cell_indices[EMAC_BOOT_LIST_SIZE ];/* Collect EMACs */ -while ((np =of_find_all_nodes (np)) !=NULL ) { +while ((np =of_find_matching_node (np, emac_match))) {u32 idx; -if (of_match_node (emac_match, np) ==NULL ) -continue ;if (of_property_read_bool (np,"unused" ))continue ;if (of_property_read_u32 (np,"cell-index" , &idx))continue ; cell_indices[i] = idx; - emac_boot_list[i++] =of_node_get (np); -if (i >=EMAC_BOOT_LIST_SIZE ) { -of_node_put (np); +if (i >=EMAC_BOOT_LIST_SIZE )
Quoted 8 lines
drivers/net/ethernet/ibm/emac/core.c static void __init emac_make_bootlist(void) · line 3266
Quoted 3 lines
drivers/net/ethernet/ibm/emac/core.c +1
-1break ; - } + emac_boot_list[i++] =of_node_get (np);Reading the Kernel doc for
of_find_matching_node()it seems thatof_node_put()needs to called each time it (and thusof_find_matching_node()returns a np. But that doesn't seem to be the case here. Am I mistaken?
Bad change. Will remove.
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/ibm/emac/core.c +0
-1} max = i; --2.47.0