net: fix OF fixed-link property handling on Freescale network device drivers
Subsystems (4)
PATCH 1/1 net: fix OF fixed-link property handling on Freescale network device drivers
From: Grant Likely <[email protected]>
The MDIO rework patches broke the handling of fixed MII links. This patch adds parsing of the fixed-link property to the gianfar, ucc-geth and fs_eth network drivers, and ensures that the MAC will work without a PHY attachment.
Note: This patch does not use the dummy phy approach previously used as I think it is an abuse of the MDIO bus infrastructure and it doesn't account for the possibility of MAC devices using a different binding for the values in the fixed-link property. The current dummy phy setup code (which this patch removes) assumes the same data format for all fixed-link properties which is a bad assumption. fixed-link has not been standardized for use by all Ethernet drivers.
If a generic interface is needed to control xMII speed, then I think it would be better to compartmentalize the link speed interface and adapt both phylib and fixed-link code to use it. That would also provide an interface for non-phy, non-MDIO devices to manipulate the link state without pretending to be something that doesn't exist. I think this would be a simpler and more 'tasteful' structure for handling non-phy cases.
This patch is not perfect, and I'm not sure that I'm programming the speed registers in the best place (at of_phy_connect() time as opposed to phy_start() time), but it does fix the fixed-link handling and keeps the binding properly contained within the driver, so I think it is the right approach for solving the fixed-link regression that I caused in 2.6.31.
---
Anton, can you please review, comment and test? I've tested it on an mpc8349 board, but that is the only hardware that I have. I've also probably made mistakes and it needs to be split up into separate patches, but this is probably a sufficient form for first review. I'll also give it another once over tomorrow when after I've had a decent night sleep.
Cheers,
g.
arch/powerpc/sysdev/fsl_soc.c | 31 -------- drivers/net/fs_enet/fs_enet-main.c | 38 +++++----- drivers/net/gianfar.c | 122 +++++++++++++++++--------------- drivers/net/phy/phy.c | 12 +++ drivers/net/phy/phy_device.c | 3 + drivers/net/ucc_geth.c | 138 +++++++++++++++++++----------------- 6 files changed, 172 insertions(+), 172 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +0 -31
@@ -177,37 +177,6 @@ u32 get_baudrate(void)EXPORT_SYMBOL (get_baudrate);#endif /* CONFIG_CPM2 */ -#ifdef CONFIG_FIXED_PHY -static int __init of_add_fixed_phys (void ) -{ -int ret; -struct device_node *np; -u32 *fixed_link; -struct fixed_phy_status status = {}; - -for_each_node_by_name (np,"ethernet" ) { - fixed_link = (u32 *)of_get_property (np,"fixed-link" ,NULL ); -if (!fixed_link) -continue ; - - status.link =1 ; - status.duplex = fixed_link[1 ]; - status.speed = fixed_link[2 ]; - status.pause = fixed_link[3 ]; - status.asym_pause = fixed_link[4 ]; - - ret =fixed_phy_add (PHY_POLL , fixed_link[0 ], &status); -if (ret) { -of_node_put (np); -return ret; - } - } - -return 0 ; -} -arch_initcall (of_add_fixed_phys); -#endif /* CONFIG_FIXED_PHY */ -static enum fsl_usb2_phy_modes determine_usb_phy (const char *phy_type) {if (!phy_type)
drivers/net/fs_enet/fs_enet-main.c +20 -18
@@ -722,8 +722,6 @@ static void generic_adjust_link(struct net_device *dev) }else if (fep->oldlink) { new_state =1 ; fep->oldlink =0 ; - fep->oldspeed =0 ; - fep->oldduplex =-1 ; }if (new_state &&netif_msg_link (fep))
@@ -749,25 +747,21 @@ static void fs_adjust_link(struct net_device *dev)static int fs_init_phy (struct net_device *dev) {struct fs_enet_private *fep =netdev_priv (dev); -struct phy_device *phydev; - fep->oldlink =0 ; - fep->oldspeed =0 ; - fep->oldduplex =-1 ; +/* If a link is already flagged, then set up initial state */ +if (fep->oldlink) { +netif_carrier_on (dev); + fep->ops->restart (dev); + } +if (fep->fpi->phy_node) - phydev =of_phy_connect (dev, fep->fpi->phy_node, + fep->phydev =of_phy_connect (dev, fep->fpi->phy_node, &fs_adjust_link,0 ,PHY_INTERFACE_MODE_MII ); -else { -printk ("No phy bus ID specified in BSP code\n" ); +if (!fep->phydev && !fep->oldlink) { +dev_err (&dev->dev,"Could not attach to PHY\n" );return -EINVAL ; } -if (IS_ERR (phydev)) { -printk (KERN_ERR "%s: Could not attach to PHY\n" , dev->name); -return PTR_ERR (phydev); - } - - fep->phydev = phydev;return 0 ; }
@@ -990,10 +984,8 @@ static int __devinit fs_enet_probe(struct of_device *ofdev, fpi->rx_copybreak =240 ; fpi->use_napi =1 ; fpi->napi_weight =17 ; + fpi->phy_node =of_parse_phandle (ofdev->node,"phy-handle" ,0 ); -if ((!fpi->phy_node) && (!of_get_property (ofdev->node,"fixed-link" , -NULL ))) - goto out_free_fpi; privsize =sizeof (*fep) + sizeof(struct sk_buff **) *
@@ -1013,6 +1005,16 @@ static int __devinit fs_enet_probe(struct of_device *ofdev, fep->fpi = fpi; fep->ops = match->data; +/* Setup the initial link state */ + data =of_get_property (ofdev->node,"fixed-link" , &len); +if (data && len >=sizeof (*data) *3 ) { + fep->oldlink =1 ; + fep->oldduplex = data[1 ]; + fep->oldspeed = data[2 ]; + } +if (!fpi->phy_node && !fep->oldlink) + goto out_free_dev; + ret = fep->ops->setup_data (ndev);if (ret) goto out_free_dev;
drivers/net/gianfar.c +65 -57
195 lines not on this page · raw message
drivers/net/phy/phy.c +12 -0
@@ -314,6 +314,9 @@ int phy_mii_ioctl(struct phy_device *phydev, {u16 val = mii_data->val_in; +if (!phydev) +return -EOPNOTSUPP ; +switch (cmd) {case SIOCGMIIPHY : mii_data->phy_id = phydev->addr;
@@ -385,6 +388,9 @@ int phy_start_aneg(struct phy_device *phydev) {int err; +if (!phydev) +return -ENODEV ; +mutex_lock (&phydev->lock);if (AUTONEG_DISABLE == phydev->autoneg)
@@ -703,6 +709,9 @@ phy_err:*/ void phy_stop (struct phy_device *phydev) { +if (!phydev) +return ; +mutex_lock (&phydev->lock);if (PHY_HALTED == phydev->state)
@@ -741,6 +750,9 @@ out_unlock:*/ void phy_start (struct phy_device *phydev) { +if (!phydev) +return ; +mutex_lock (&phydev->lock);switch (phydev->state) {
drivers/net/phy/phy_device.c +3 -0
@@ -365,6 +365,9 @@ EXPORT_SYMBOL(phy_connect);*/ void phy_disconnect (struct phy_device *phydev) { +if (!phydev) +return ; +if (phydev->irq >0 )phy_stop_interrupts (phydev);
drivers/net/ucc_geth.c +72 -66
212 lines not on this page · raw message
David Miller
maintainerFrom: Grant Likely <[email protected]>
Date: Fri, 03 Jul 2009 16:20:19 -0600
Quoted 5 lines
Anton, can you please review, comment and test? I've tested it on an mpc8349 board, but that is the only hardware that I have. I've also probably made mistakes and it needs to be split up into separate patches, but this is probably a sufficient form for first review. I'll also give it another once over tomorrow when after I've had a decent night sleep.
Can we get some review and testing of this patch going so we can fix this regression as soon as possible?
Thanks.
Quoted 3 lines · Grant Likely
From: Grant Likely <[email protected]>
The MDIO rework patches broke the handling of fixed MII links.
[...]
Quoted 7 lines
Signed-off-by Grant Likely <[email protected]>---
Anton, can you please review, comment and test? I've tested it on an mpc8349 board, but that is the only hardware that I have. I've also probably made mistakes and it needs to be split up into separate patches, but this is probably a sufficient form for first review. I'll also give it another once over tomorrow when after I've had a decent night sleep.
Did some tests for ucc geth...
Will get to fs_enet a bit later.
Quoted 5 lines
drivers/net/ucc_geth.c +0
-0
drivers/net/ucc_geth.c static int adjust_enet_interface(struct ucc_geth_private *ugeth) · line 1451
Quoted 9 lines
drivers/net/ucc_geth.c +6
-0@@ -1443,6 +1443,53 @@ static int adjust_enet_interface(struct ucc_geth_private *ugeth)return 0 ; } +static void ugeth_set_link (struct net_device *dev) +{ +struct ucc_geth_private *ugeth =netdev_priv (dev); +struct phy_device *phydev = ugeth->phydev; +struct ucc_geth __iomem *ug_regs = ugeth->ug_regs; +struct ucc_fast __iomem *uf_regs = ugeth->uccf->uf_regs;
In fixed-link case you'll call set_link() before ucc_struct_init, so these *_regs are NULL, following oops pops up:
Unable to handle kernel paging request for data at address 0x00000004 Faulting instruction address: 0xc01d6228 Oops: Kernel access of bad area, sig: 11 [#1] [...] NIP [c01d6228] ugeth_set_link+0x20/0x158 LR [c01d723c] init_phy+0xa8/0xdc Call Trace:
[cf831e40] [84042028] 0x84042028 (unreliable)
[cf831e60] [c01d723c] init_phy+0xa8/0xdc
[cf831e80] [c01d8fb8] ucc_geth_open+0x2c/0x2b0
[cf831ea0] [c02040a8] dev_open+0xfc/0x134
[cf831ec0] [c0202670] dev_change_flags+0x84/0x1ac
[cf831ee0] [c03b0cfc] ic_open_devs+0x168/0x2cc
[cf831f20] [c03b20f8] ip_auto_config+0x90/0x2a4
[cf831f60] [c0003894] do_one_initcall+0x34/0x1a8
[cf831fd0] [c03922f8] do_initcalls+0x38/0x58
[cf831fe0] [c0392388] kernel_init+0x38/0x98
[cf831ff0] [c0011b78] kernel_thread+0x4c/0x68
Quoted 2 lines
drivers/net/ucc_geth.c +2
-0+u32 tempval =in_be32 (&ug_regs->maccfg2); +u32 upsmr =in_be32 (&uf_regs->upsmr);
[...]
drivers/net/ucc_geth.c static int adjust_enet_interface(struct ucc_geth_private *ugeth) · line 1485
Quoted 4 lines
drivers/net/ucc_geth.c +4
-0+default : +if (netif_msg_link (ugeth)) +ugeth_warn ("%s: Ack! Speed (%d) is not 10/100/1000!" , + dev->name, phydev->speed);
You may dereference NULL here.
drivers/net/ucc_geth.c static int adjust_enet_interface(struct ucc_geth_private *ugeth) · line 1489
Quoted 4 lines
drivers/net/ucc_geth.c +4
-0+break ; + } + +out_be32 (&ug_regs->maccfg2, tempval);
(while you're at it, maybe s/tempval/maccfg2/ ?)
Quoted 3 lines
drivers/net/ucc_geth.c +3
-0+out_be32 (&uf_regs->upsmr, upsmr); +} +
[...]
Quoted 6 lines
drivers/net/ucc_geth.c +0
-2@@ -3708,15 +3710,19 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma ug_info->uf_info.regs = res.start; ug_info->uf_info.irq =irq_of_parse_and_map (np,0 ); - fixed_link =of_get_property (np,"fixed-link" ,NULL ); -if (fixed_link) {
drivers/net/ucc_geth.c static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma · line 3717
Quoted 10 lines
drivers/net/ucc_geth.c +5
-5- phy =NULL ; - }else { - phy =of_parse_phandle (np,"phy-handle" ,0 ); -if (phy ==NULL ) -return -ENODEV ; + +/* Setup the initial link state */ + prop =of_get_property (np,"fixed-link" , &prop_sz); +if (prop && prop_sz >=sizeof (*prop) *3 ) { + ugeth->oldlink =1 ;
'ugeth' is NULL at this point, causes this:
Unable to handle kernel paging request for data at address 0x000002c4 Faulting instruction address: 0xc01da0d8 Oops: Kernel access of bad area, sig: 11 [#1] [...] NIP [c01da0d8] ucc_geth_probe+0x218/0x530 LR [c01da0c0] ucc_geth_probe+0x200/0x530 Call Trace: [cf831e00] [c01da0c0] ucc_geth_probe+0x200/0x530 (unreliable) [cf831e60] [c01eddc4] of_platform_device_probe+0x5c/0x84 [cf831e80] [c019bfd4] really_probe+0x78/0x1a0 [cf831ea0] [c019c1c4] __driver_attach+0xa4/0xa8 [cf831ec0] [c019b3ec] bus_for_each_dev+0x60/0x9c [cf831ef0] [c019be18] driver_attach+0x24/0x34 [cf831f00] [c019badc] bus_add_driver+0xb4/0x1c4
Quoted 14 lines
drivers/net/ucc_geth.c +7
-1+ ugeth->oldduplex = prop[1 ]; + ugeth->oldspeed = prop[2 ]; } - ug_info->phy_node = phy; + +/* Find the phy. Bail if there is no phy and no initial link speed */ + ug_info->phy_node =of_parse_phandle (np,"phy-handle" ,0 ); +if (!ug_info->phy_node && !ugeth->oldlink) +return -ENODEV ;/* Find the TBI PHY node. If it's not there, we don't support SGMII */ ug_info->tbi_node =of_parse_phandle (np,"tbi-handle" ,0 );
drivers/net/ucc_geth.c static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma · line 3737
Quoted 8 lines
drivers/net/ucc_geth.c +1
-1@@ -3725,7 +3731,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma prop =of_get_property (np,"phy-connection-type" ,NULL );if (!prop) {/* handle interface property present in old trees */ - prop =of_get_property (phy,"interface" ,NULL ); + prop =of_get_property (ug_info->phy_node,"interface" ,NULL );if (prop !=NULL ) { phy_interface = enet_to_phy_interface[*prop]; max_speed = enet_to_speed[*prop];
There is another oops, if interface is down:
# ethtool -S eth1
Unable to handle kernel paging request for data at address 0x00000180
Faulting instruction address: 0xc01da7f4
Oops: Kernel access of bad area, sig: 11 [#1]
[...]
NIP [c01da7f4] uec_get_ethtool_stats+0x3c/0x14c
LR [c0207484] ethtool_get_stats+0xfc/0x23c
Call Trace:
[cfb2ddf0] [c0207464] ethtool_get_stats+0xdc/0x23c (unreliable)
[cfb2de30] [c0207b24] dev_ethtool+0x324/0x5a8
[cfb2de60] [c0204ad4] dev_ioctl+0x290/0x320
[cfb2deb0] [c01ef9ac] sock_ioctl+0x80/0x2f4
[cfb2ded0] [c0090814] vfs_ioctl+0x34/0x98
[cfb2dee0] [c009103c] do_vfs_ioctl+0x84/0x2cc
[cfb2df10] [c00912c4] sys_ioctl+0x40/0x74
[cfb2df40] [c0011d54] ret_from_syscall+0x0/0x38
--- Exception: c01 at 0xff64820
LR = 0xffec848
Instruction dump:
80c901b8 70c00001 41820058 8123004c 7cab2b78 39000000 38000000 38e90180
39200012 7d2903a6 5400103a 7c0004ac <7d27002e> 0c090000 4c00012c 7d2a4b78
---[ end trace 7b7ae7cbafe6f2ba ]---
Segmentation faultAlso, now userspace has no chance to know link speed:
# ifconfig eth1 up
# ethtool eth1
Settings for eth1:
Cannot get device settings: No such device
Current message level: 0x0000003f (63)
Link detected: yes
# (You need to tech *_ethtool.c to report speed/duplex for fixed-link cases).
Thanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
Quoted 3 lines · Grant Likely
From: Grant Likely <[email protected]>
The MDIO rework patches broke the handling of fixed MII links.
[...]
Quoted 7 lines
Signed-off-by Grant Likely <[email protected]>---
Anton, can you please review, comment and test? I've tested it on an mpc8349 board, but that is the only hardware that I have. I've also probably made mistakes and it needs to be split up into separate patches, but this is probably a sufficient form for first review. I'll also give it another once over tomorrow when after I've had a decent night sleep.
fs_enet this time...
[..]
Quoted 16 lines
drivers/net/fs_enet/fs_enet-main.c +0
-2@@ -722,8 +722,6 @@ static void generic_adjust_link(struct net_device *dev) }else if (fep->oldlink) { new_state =1 ; fep->oldlink =0 ; - fep->oldspeed =0 ; - fep->oldduplex =-1 ; }if (new_state &&netif_msg_link (fep))@@ -749,25 +747,21 @@ static void fs_adjust_link(struct net_device *dev)static int fs_init_phy (struct net_device *dev) {
drivers/net/fs_enet/fs_enet-main.c static void fs_adjust_link(struct net_device *dev) · line 754
Quoted 10 lines
drivers/net/fs_enet/fs_enet-main.c +4
-4struct fs_enet_private *fep =netdev_priv (dev); -struct phy_device *phydev; - fep->oldlink =0 ; - fep->oldspeed =0 ; - fep->oldduplex =-1 ; +/* If a link is already flagged, then set up initial state */ +if (fep->oldlink) { +netif_carrier_on (dev); + fep->ops->restart (dev);
->restart() will dereference phydev, which is NULL.
grep for 'phydev' in fs_enet/mac-*.c.
Unable to handle kernel paging request for data at address 0x000000d0 Faulting instruction address: 0xc01842cc Oops: Kernel access of bad area, sig: 11 [#1] [...] NIP [c01842cc] restart+0x3ac/0x434 LR [c0184260] restart+0x340/0x434 Call Trace: [c3825e60] [c0184260] restart+0x340/0x434 (unreliable) [c3825e80] [c018231c] fs_init_phy+0x3c/0xbc [c3825e90] [c01838a4] fs_enet_open+0x110/0x1cc [c3825eb0] [c01b19b0] dev_open+0xcc/0x130 [c3825ed0] [c01b0100] dev_change_flags+0xb8/0x18c [c3825ef0] [c030c4e4] ic_open_devs+0x188/0x284 [c3825f30] [c030d770] ip_auto_config+0x7c/0x278 [c3825f60] [c000393c] do_one_initcall+0x58/0x19c [c3825fd0] [c02f62e4] do_initcalls+0x30/0x50 [c3825fe0] [c02f6374] kernel_init+0x38/0x94 [c3825ff0] [c0010824] kernel_thread+0x4c/0x68 Instruction dump: 901e0004 801c0060 2f800000 419e0020 7c0004ac 801e0004 0c000000 4c00012c 64000002 7c0004ac 901e0004 813d0110 <800900d0> 2f800000 419e0024 7c0004ac ---[ end trace 1ae193a95823d5e4 ]---
And the same comment regarding link speed/duplex reporting for userspace:
# ethtool eth1
Settings for eth1:
Cannot get device settings: No such device
Current message level: 0x00000000 (0)
Link detected: yesThanks,
Signature · 3 lines
Anton Vorontsov email: [email protected] irc://irc.freenode.net/bd2
David Miller
maintainerFrom: Anton Vorontsov <[email protected]>
Date: Tue, 7 Jul 2009 19:12:41 +0400
Quoted 3 lines
->restart() will dereference phydev, which is NULL.
grep for 'phydev' in
fs_enet/mac-*.c.
Ok, so this patch still needs a little bit more work.
Thanks for testing!