Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Fri, 7 Dec 2007, Vitaly Bordug wrote: With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] Acked-by: Jeff Garzik [EMAIL PROTECTED] --- drivers/net/phy/Kconfig | 32 +-- drivers/net/phy/fixed.c | 445 + include/linux/phy_fixed.h | 51 ++--- 3 files changed, 195 insertions(+), 333 deletions(-) applied. - k ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
[PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] Acked-by: Jeff Garzik [EMAIL PROTECTED] --- drivers/net/phy/Kconfig | 32 +-- drivers/net/phy/fixed.c | 445 + include/linux/phy_fixed.h | 51 ++--- 3 files changed, 195 insertions(+), 333 deletions(-) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 54b2ba9..7fe03ce 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -61,34 +61,12 @@ config ICPLUS_PHY Currently supports the IP175C PHY. config FIXED_PHY - tristate Drivers for PHY emulation on fixed speed/link + bool Driver for MDIO Bus/PHY emulation with fixed speed/link PHYs ---help--- - Adds the driver to PHY layer to cover the boards that do not have any PHY bound, - but with the ability to manipulate the speed/link in software. The relevant MII - speed/duplex parameters could be effectively handled in a user-specified function. - Currently tested with mpc866ads. - -config FIXED_MII_10_FDX - bool Emulation for 10M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_100_FDX - bool Emulation for 100M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_1000_FDX - bool Emulation for 1000M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_AMNT -int Number of emulated PHYs to allocate -depends on FIXED_PHY -default 1 ----help--- -Sometimes it is required to have several independent emulated -PHYs on the bus (in case of multi-eth but phy-less HW for instance). -This control will have specified number allocated for each fixed -PHY type enabled. + Adds the platform fixed MDIO Bus to cover the boards that use + PHYs that are not connected to the real MDIO bus. + + Currently tested with mpc866ads and mpc8349e-mitx. config MDIO_BITBANG tristate Support for bitbanged MDIO buses diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 5619182..73b6d39 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -1,362 +1,253 @@ /* - * drivers/net/phy/fixed.c + * Fixed MDIO bus (MDIO bus emulation with fixed PHYs) * - * Driver for fixed PHYs, when transceiver is able to operate in one fixed mode. + * Author: Vitaly Bordug [EMAIL PROTECTED] + * Anton Vorontsov [EMAIL PROTECTED] * - * Author: Vitaly Bordug - * - * Copyright (c) 2006 MontaVista Software, Inc. + * Copyright (c) 2006-2007 MontaVista Software, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. - * */ + #include linux/kernel.h -#include linux/string.h -#include linux/errno.h -#include linux/unistd.h -#include linux/slab.h -#include linux/interrupt.h -#include linux/init.h -#include linux/delay.h -#include linux/netdevice.h -#include linux/etherdevice.h -#include linux/skbuff.h -#include linux/spinlock.h -#include linux/mm.h #include linux/module.h +#include linux/platform_device.h +#include linux/list.h #include linux/mii.h -#include linux/ethtool.h #include linux/phy.h #include linux/phy_fixed.h -#include asm/io.h -#include asm/irq.h -#include asm/uaccess.h +#define MII_REGS_NUM 29 -/* we need to track the allocated pointers in order to free them on exit */ -static struct fixed_info *fixed_phy_ptrs[CONFIG_FIXED_MII_AMNT*MAX_PHY_AMNT]; - -/*- - * If something weird is required to be done with link/speed, - * network driver is able to assign a function to implement this. - * May be useful for PHY's that need to be software-driven. - *-*/ -int fixed_mdio_set_link_update(struct phy_device *phydev, - int (*link_update) (struct net_device *, - struct fixed_phy_status *)) -{ - struct fixed_info *fixed; - - if (link_update == NULL) - return -EINVAL; - - if (phydev) { - if (phydev-bus) { - fixed = phydev-bus-priv; - fixed-link_update = link_update; - return 0; -
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
Vitaly Bordug wrote: With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] ACK, I presume this will go via the ppc tree? ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Tue, 04 Dec 2007 15:07:49 -0500 Jeff Garzik wrote: Vitaly Bordug wrote: With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] ACK, I presume this will go via the ppc tree? Yes, I'll add your ack in next respin and will ask Paul to consider it, if you don't mind. -- Sincerely, Vitaly ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Sat, 01 Dec 2007 14:48:54 +0100 Jochen Friedrich wrote: Hi Vitaly, With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. If i understand your code correctly, you seem to rely on the fact that fixed_phy_add() is called before the fixed MDIO bus is scanned for devices. How is this supposed to work for modules or for the PPC_CPM_NEW_BINDING mode where the device tree is no longer scanned during fs_soc initialization but during device initialization? Well, this is kind of known issue - to work it around for now, place PHY lib after fs_enet in Makefile. This way it works for me for _NEW_BINDING and mpc866ads. I tried to add fixed-phy support to fs_enet, but the fixed phy is not found this way. The point is I have the code and it works now(for fs_enet etc.), but I need to find the way for the fixed phy pinning to work in either order with phylib. If you have ideas, please go ahead :) --- a/drivers/net/fs_enet/fs_enet-main.c +++ b/drivers/net/fs_enet/fs_enet-main.c @@ -36,6 +36,7 @@ #include linux/fs.h #include linux/platform_device.h #include linux/phy.h +#include linux/phy_fixed.h #include linux/vmalloc.h #include asm/pgtable.h @@ -1174,8 +1175,24 @@ static int __devinit find_phy(struct device_node *np, struct device_node *phynode, *mdionode; struct resource res; int ret = 0, len; + const u32 *data; + struct fixed_phy_status status = {}; + + data = of_get_property(np, fixed-link, NULL); + if (data) { + status.link = 1; + status.duplex = data[1]; + status.speed = data[2]; + + ret = fixed_phy_add(PHY_POLL, data[0], status); + if (ret) + return ret; + + snprintf(fpi-bus_id, 16, PHY_ID_FMT, 0, *data); + return 0; + } - const u32 *data = of_get_property(np, phy-handle, len); + data = of_get_property(np, phy-handle, len); if (!data || len != 4) return -EINVAL; Thanks, Jochen -- Sincerely, Vitaly ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Sat, Dec 01, 2007 at 02:48:54PM +0100, Jochen Friedrich wrote: Hi Vitaly, With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. If i understand your code correctly, you seem to rely on the fact that fixed_phy_add() is called before the fixed MDIO bus is scanned for devices. Yes, indeed. The other name of fixed phys are platform phys or platform MDIO bus on which virtual PHYs are placed. That is, these phys supposed to be created by the platform setup code (arch/). The rationale here is: we do hardware emulation, thus to make drivers actually see that hardware, we have to create it early. I tried to add fixed-phy support to fs_enet, but the fixed phy is not found this way. --- a/drivers/net/fs_enet/fs_enet-main.c +++ b/drivers/net/fs_enet/fs_enet-main.c @@ -36,6 +36,7 @@ #include linux/fs.h #include linux/platform_device.h #include linux/phy.h +#include linux/phy_fixed.h #include linux/vmalloc.h #include asm/pgtable.h @@ -1174,8 +1175,24 @@ static int __devinit find_phy(struct device_node *np, struct device_node *phynode, *mdionode; struct resource res; int ret = 0, len; + const u32 *data; + struct fixed_phy_status status = {}; + + data = of_get_property(np, fixed-link, NULL); + if (data) { + status.link = 1; + status.duplex = data[1]; + status.speed = data[2]; + + ret = fixed_phy_add(PHY_POLL, data[0], status); + if (ret) + return ret; + + snprintf(fpi-bus_id, 16, PHY_ID_FMT, 0, *data); + return 0; + } - const u32 *data = of_get_property(np, phy-handle, len); + data = of_get_property(np, phy-handle, len); if (!data || len != 4) return -EINVAL; ^^ the correct solution is to implement arch_initcall function which will create fixed PHYs, and then leave only snprintf(fpi-bus_id, 16, PHY_ID_FMT, 0, *data); part in the fs_enet's find_phy(). Try add something like this to the fsl_soc.c (compile untested): - - - - static int __init of_add_fixed_phys(void) { struct device_node *np; const u32 *prop; struct fixed_phy_status status = {}; while ((np = of_find_node_by_name(NULL, ethernet))) { data = of_get_property(np, fixed-link, NULL); if (!data) continue; status.link = 1; status.duplex = data[1]; status.speed = data[2]; ret = fixed_phy_add(PHY_POLL, data[0], status); if (ret) return ret; } return 0; } arch_initcall(of_add_fixed_phys); - - - - And remove fixed_phy_add() from the fs_enet. This should work nicely and also should be ideologically correct. ;-) How is this supposed to work for modules or for the PPC_CPM_NEW_BINDING mode where the device tree is no longer scanned during fs_soc initialization but during device initialization? We should mark fixed.c as bool. Fake/virtual/fixed/platform PHYs creation is architecture code anyway, can't be =m. -- Anton Vorontsov email: [EMAIL PROTECTED] backup email: [EMAIL PROTECTED] irc://irc.freenode.net/bd2 ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
Vitaly Bordug wrote: With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] what's the context of this patchset? 2.6.25? it's late for 2.6.24-rc, IMO. Do I have the latest version (sent Nov 26 @ 9:29am)? Jeff ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Sat, 01 Dec 2007 16:59:52 -0500 Jeff Garzik wrote: Vitaly Bordug wrote: With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] what's the context of this patchset? 2.6.25? Fine with it. it's late for 2.6.24-rc, IMO. Do I have the latest version (sent Nov 26 @ 9:29am)? yes, that's it. -- Sincerely, Vitaly ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
On Sun, 2 Dec 2007 00:34:03 +0300 Anton Vorontsov wrote: If i understand your code correctly, you seem to rely on the fact that fixed_phy_add() is called before the fixed MDIO bus is scanned for devices. Yes, indeed. The other name of fixed phys are platform phys or platform MDIO bus on which virtual PHYs are placed. That is, these phys supposed to be created by the platform setup code (arch/). The rationale here is: we do hardware emulation, thus to make drivers actually see that hardware, we have to create it early. well that was the intention but... The point is - as device is emulated, (nearly) everything is doable, and the only tradeoff to consider, is how far will we go with that emulation. IOW, PHYlib could be tricked to do the right thing, and I thought about adding module flexibility... But thinking more about it, it seems that BSP-code-phy-creation just sucks less and is clear enough yet flexible. -- Sincerely, Vitaly ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
Just a little reminder ... On Sun, 2 Dec 2007 00:34:03 +0300 Anton Vorontsov [EMAIL PROTECTED] wrote: static int __init of_add_fixed_phys(void) { struct device_node *np; const u32 *prop; struct fixed_phy_status status = {}; while ((np = of_find_node_by_name(NULL, ethernet))) { for_each_node_by_name(np, ethernet) { (this probably does what you want instead of finding just the first ethernet over and over again. :-)) data = of_get_property(np, fixed-link, NULL); if (!data) continue; status.link = 1; status.duplex = data[1]; status.speed = data[2]; ret = fixed_phy_add(PHY_POLL, data[0], status); if (ret) return ret; if (ret) { of_put_node(np); retun ret; } } -- Cheers, Stephen Rothwell[EMAIL PROTECTED] http://www.canb.auug.org.au/~sfr/ pgpE1oEuKHybY.pgp Description: PGP signature ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
[PATCH 1/3] [NET] phy/fixed.c: rework to not duplicate PHY layer functionality
With that patch fixed.c now fully emulates MDIO bus, thus no need to duplicate PHY layer functionality. That, in turn, drastically simplifies the code, and drops down line count. As an additional bonus, now there is no need to register MDIO bus for each PHY, all emulated PHYs placed on the platform fixed MDIO bus. There is also no more need to pre-allocate PHYs via .config option, this is all now handled dynamically. p.s. Don't even try to understand patch content! Better: apply patch and look into resulting drivers/net/phy/fixed.c. Signed-off-by: Anton Vorontsov [EMAIL PROTECTED] Signed-off-by: Vitaly Bordug [EMAIL PROTECTED] --- drivers/net/phy/Kconfig | 32 +-- drivers/net/phy/fixed.c | 427 - include/linux/phy_fixed.h | 49 ++--- 3 files changed, 176 insertions(+), 332 deletions(-) diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 54b2ba9..a05c614 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -61,34 +61,12 @@ config ICPLUS_PHY Currently supports the IP175C PHY. config FIXED_PHY - tristate Drivers for PHY emulation on fixed speed/link + tristate Drivers for MDIO Bus/PHY emulation on fixed speed/link ---help--- - Adds the driver to PHY layer to cover the boards that do not have any PHY bound, - but with the ability to manipulate the speed/link in software. The relevant MII - speed/duplex parameters could be effectively handled in a user-specified function. - Currently tested with mpc866ads. - -config FIXED_MII_10_FDX - bool Emulation for 10M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_100_FDX - bool Emulation for 100M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_1000_FDX - bool Emulation for 1000M Fdx fixed PHY behavior - depends on FIXED_PHY - -config FIXED_MII_AMNT -int Number of emulated PHYs to allocate -depends on FIXED_PHY -default 1 ----help--- -Sometimes it is required to have several independent emulated -PHYs on the bus (in case of multi-eth but phy-less HW for instance). -This control will have specified number allocated for each fixed -PHY type enabled. + Adds the platform fixed MDIO Bus to cover the boards that use + PHYs that are not connected to the real MDIO bus. + + Currently tested with mpc866ads and mpc8349e-mitx. config MDIO_BITBANG tristate Support for bitbanged MDIO buses diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c index 5619182..31719b3 100644 --- a/drivers/net/phy/fixed.c +++ b/drivers/net/phy/fixed.c @@ -1,362 +1,237 @@ /* - * drivers/net/phy/fixed.c + * Fixed MDIO bus (MDIO bus emulation with fixed PHYs) * - * Driver for fixed PHYs, when transceiver is able to operate in one fixed mode. + * Author: Vitaly Bordug [EMAIL PROTECTED] + * Anton Vorontsov [EMAIL PROTECTED] * - * Author: Vitaly Bordug - * - * Copyright (c) 2006 MontaVista Software, Inc. + * Copyright (c) 2006-2007 MontaVista Software, Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. - * */ + #include linux/kernel.h -#include linux/string.h -#include linux/errno.h -#include linux/unistd.h -#include linux/slab.h -#include linux/interrupt.h -#include linux/init.h -#include linux/delay.h -#include linux/netdevice.h -#include linux/etherdevice.h -#include linux/skbuff.h -#include linux/spinlock.h -#include linux/mm.h #include linux/module.h +#include linux/platform_device.h +#include linux/list.h #include linux/mii.h -#include linux/ethtool.h #include linux/phy.h #include linux/phy_fixed.h -#include asm/io.h -#include asm/irq.h -#include asm/uaccess.h - -/* we need to track the allocated pointers in order to free them on exit */ -static struct fixed_info *fixed_phy_ptrs[CONFIG_FIXED_MII_AMNT*MAX_PHY_AMNT]; - -/*- - * If something weird is required to be done with link/speed, - * network driver is able to assign a function to implement this. - * May be useful for PHY's that need to be software-driven. - *-*/ -int fixed_mdio_set_link_update(struct phy_device *phydev, - int (*link_update) (struct net_device *, - struct fixed_phy_status *)) -{ - struct fixed_info *fixed; - - if (link_update == NULL) - return -EINVAL; - - if (phydev) { - if (phydev-bus) { - fixed = phydev-bus-priv; - fixed-link_update =