PAL: Support of the fixed PHY
Subsystems (2)
PATCH 1/2 PAL: Support of the fixed PHY
This makes it possible for HW PHY-less boards to utilize PAL goodies. Generic routines to connect to fixed PHY are provided, as well as ability to specify software callback that fills up link, speed, etc. information into PHY descriptor (the latter feature not tested so far).
---
drivers/net/phy/Kconfig | 17 ++ drivers/net/phy/Makefile | 1 drivers/net/phy/fixed.c | 356 ++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/mdio_bus.c | 2 drivers/net/phy/phy_device.c | 53 ++++-- include/linux/phy.h | 1 6 files changed, 407 insertions(+), 23 deletions(-)
drivers/net/phy/Kconfig +17 -0
@@ -45,5 +45,22 @@ config CICADA_PHY ---help--- Currently supports the cis8204 +config FIXED_PHY + tristate "Drivers for PHY emulation on fixed speed/link" + depends on PHYLIB + ---help--- + Adds the driver to PHY layer to cover the boards that do not have any PHY bound, + but with the ability to manipulate with speed/link in software. The relavant MII + speed/duplex parameters could be effectively handled in user-specified fuction. + 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 + endmenu
drivers/net/phy/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_DAVICOM_PHY) += davicom.o obj-$(CONFIG_CICADA_PHY) += cicada.o obj-$(CONFIG_LXT_PHY) += lxt.o obj-$(CONFIG_QSEMI_PHY) += qsemi.o +obj-$(CONFIG_FIXED_PHY) += fixed.o
drivers/net/phy/fixed.c new file +356 -0
356 lines not on this page · raw message
drivers/net/phy/mdio_bus.c +1 -1
@@ -66,7 +66,7 @@ int mdiobus_register(struct mii_bus *bus phydev =get_phy_device (bus, i);if (IS_ERR (phydev)) -return PTR_ERR (phydev); +continue ;/* There's a PHY at this address * We need to set:
drivers/net/phy/phy_device.c +31 -22
65 lines not on this page · raw message
include/linux/phy.h +1 -0
@@ -378,6 +378,7 @@ int phy_mii_ioctl(struct phy_device *phy struct mii_ioctl_data *mii_data, int cmd);int phy_start_interrupts (struct phy_device *phydev);void phy_print_status (struct phy_device *phydev); +struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id);extern struct bus_type mdio_bus_type;#endif /* __PHY_H */
PATCH 2/2 FS_ENET: use PAL for mii management
This patch should update the fs_enet infrastructure to utilize Phy Abstraction Layer subsystem. Inside there are generic driver rehaul, board-specific portion to respect driver changes (for 8272ads and 866ads).
---
arch/ppc/platforms/mpc8272ads_setup.c | 29 ++ arch/ppc/platforms/mpc866ads_setup.c | 37 +- arch/ppc/syslib/mpc8xx_devices.c | 8 + arch/ppc/syslib/mpc8xx_sys.c | 3 arch/ppc/syslib/pq2_devices.c | 5 arch/ppc/syslib/pq2_sys.c | 4 drivers/net/fs_enet/Makefile | 6 drivers/net/fs_enet/fec.h | 42 +++ drivers/net/fs_enet/fs_enet-main.c | 198 ++++++++----- drivers/net/fs_enet/fs_enet-mii.c | 507 --------------------------------- drivers/net/fs_enet/fs_enet.h | 29 ++ drivers/net/fs_enet/mac-fcc.c | 10 - drivers/net/fs_enet/mac-fec.c | 131 +-------- drivers/net/fs_enet/mac-scc.c | 4 drivers/net/fs_enet/mii-bitbang.c | 335 ++++++++++++++-------- drivers/net/fs_enet/mii-fec.c | 245 ++++++++++++++++ drivers/net/fs_enet/mii-fixed.c | 92 ------ include/asm-ppc/mpc8260.h | 1 include/asm-ppc/mpc8xx.h | 1 include/linux/fs_enet_pd.h | 42 +-- 20 files changed, 760 insertions(+), 969 deletions(-)
arch/ppc/platforms/mpc8272ads_setup.c +28 -1
@@ -44,6 +44,14 @@ static struct fs_mii_bus_info mii_bus_in }, }; +static struct fs_mii_bb_platform_info m82xx_mii_bb_pdata = { + .mdio_port = fsiop_portc, + .mdio_bit =18 , + .mdc_port = fsiop_portc, + .mdc_bit =19 , + .delay =1 , +}; +static struct fs_platform_info mpc82xx_fcc1_pdata = { .fs_no = fsid_fcc1, .cp_page =CPM_CR_FCC1_PAGE ,
@@ -66,6 +74,7 @@ static struct fs_platform_info mpc82xx_f .rx_copybreak = 240, .use_napi = 0, .napi_weight = 17, + .bus_id = "0:00", };static struct fs_platform_info mpc82xx_fcc2_pdata = {
@@ -90,6 +99,7 @@ static struct fs_platform_info mpc82xx_f .rx_copybreak = 240, .use_napi = 0, .napi_weight = 17, + .bus_id = "0:03", };static void init_fcc1_ioports (void )
@@ -201,6 +211,18 @@ static void __init mpc8272ads_fixup_enet } } +static void __init mpc8272ads_fixup_mdio_pdata (struct platform_device *pdev, +int idx) +{ + m82xx_mii_bb_pdata.irq[0 ] =PHY_INTERRUPT ; + m82xx_mii_bb_pdata.irq[1 ] =-1 ; + m82xx_mii_bb_pdata.irq[2 ] =-1 ; + m82xx_mii_bb_pdata.irq[3 ] =PHY_INTERRUPT ; + m82xx_mii_bb_pdata.irq[31 ] =-1 ; + + pdev->dev.platform_data = &m82xx_mii_bb_pdata; +} +static int mpc8272ads_platform_notify (struct device *dev) {static const struct platform_notify_dev_map dev_map[] = {
@@ -209,6 +231,10 @@ static int mpc8272ads_platform_notify(st .rtn = mpc8272ads_fixup_enet_pdata }, { + .bus_id = "fsl-bb-mdio", + .rtn = mpc8272ads_fixup_mdio_pdata + }, + { .bus_id = NULL } };
@@ -229,7 +255,8 @@ int __init mpc8272ads_init(void)ppc_sys_device_disable_all ();ppc_sys_device_enable (MPC82xx_CPM_FCC1);ppc_sys_device_enable (MPC82xx_CPM_FCC2); - +ppc_sys_device_enable (MPC82xx_MDIO_BB); +return 0 ; }
arch/ppc/platforms/mpc866ads_setup.c +18 -19
@@ -4,7 +4,7 @@* * Vitaly Bordug <[email protected]> * -* Copyright 2005 MontaVista Software Inc. +* Copyright 2005-2006 MontaVista Software Inc. * * This file is licensed under the terms of the GNU General Public License * version 2. This program is licensed "as is" without any warranty of any
@@ -36,18 +36,7 @@#include <asm/mpc8xx.h> extern unsigned char __res[]; - -static struct fs_mii_bus_info fec_mii_bus_info = { - .method = fsmii_fec, - .id =0 , -}; - -static struct fs_mii_bus_info scc_mii_bus_info = { - .method = fsmii_fixed, - .id =0 , - .i.fixed.speed =10 , - .i.fixed.duplex =0 , -}; +static struct fs_mii_fec_platform_info mpc8xx_mdio_fec_pdata;static struct fs_platform_info mpc8xx_fec_pdata[] = { {
@@ -62,8 +51,8 @@ static struct fs_platform_info mpc8xx_fe .phy_irq = -1, .use_rmii = 0, - - .bus_info = &fec_mii_bus_info, + .bus_id = "0:0f", + .has_phy = 1, } };
@@ -77,8 +66,7 @@ static struct fs_platform_info mpc8xx_sc .phy_addr = -1, .phy_irq = -1, - - .bus_info = &scc_mii_bus_info, + .bus_id = "fixed@100:1", };void __init board_init (void )
@@ -210,7 +198,6 @@ static void mpc866ads_fixup_enet_pdata(s fpi->macaddr[i] = *e++; fpi->macaddr[5 - pdev->id]++; - } static void mpc866ads_fixup_fec_enet_pdata(struct platform_device *pdev,
@@ -255,6 +242,9 @@ static int mpc866ads_platform_notify(strint __init mpc866ads_init (void ) { +bd_t *bd = (bd_t *) __res; +struct fs_mii_fec_platform_info * fmpi; +printk (KERN_NOTICE "mpc866ads: Init\n" ); platform_notify = mpc866ads_platform_notify;
@@ -262,11 +252,20 @@ int __init mpc866ads_init(void)ppc_sys_device_initfunc ();ppc_sys_device_disable_all (); -#ifdef MPC8xx_SECOND_ETH_SCC1 +#ifdef CONFIG_MPC8xx_SECOND_ETH_SCC1ppc_sys_device_enable (MPC8xx_CPM_SCC1);#endif ppc_sys_device_enable (MPC8xx_CPM_FEC1); +ppc_sys_device_enable (MPC8xx_MDIO_FEC); + + fmpi = ppc_sys_platform_devices[MPC8xx_MDIO_FEC].dev.platform_data = + &mpc8xx_mdio_fec_pdata; + + fmpi->mii_speed = ((((bd->bi_intfreq +4999999 ) /2500000 ) /2 ) &0x3F ) <<1 ; +/* No PHY interrupt line here */ + fmpi->irq[0xf ] =-1 ; +return 0 ; }
arch/ppc/syslib/mpc8xx_devices.c +8 -0
@@ -207,6 +207,14 @@ struct platform_device ppc_sys_platform_ }, }, }, + + [MPC8xx_MDIO_FEC] = { + .name ="fsl-cpm-fec-mdio" , + .id =0 , + .num_resources =0 , + + }, + };static int __init mach_mpc8xx_fixup (struct platform_device *pdev)
arch/ppc/syslib/mpc8xx_sys.c +2 -1
@@ -24,7 +24,7 @@ struct ppc_sys_spec ppc_sys_specs[] = { .ppc_sys_name = "MPC86X", .mask = 0xFFFFFFFF, .value = 0x00000000, - .num_devices = 7, + .num_devices = 8, .device_list = (enum ppc_sys_devices []) { MPC8xx_CPM_FEC1,
@@ -34,6 +34,7 @@ struct ppc_sys_spec ppc_sys_specs[] = { MPC8xx_CPM_SCC4, MPC8xx_CPM_SMC1, MPC8xx_CPM_SMC2, + MPC8xx_MDIO_FEC, }, }, {
arch/ppc/syslib/pq2_devices.c +5 -0
@@ -371,6 +371,11 @@ struct platform_device ppc_sys_platform_ }, }, }, + [MPC82xx_MDIO_BB] = { + .name ="fsl-bb-mdio" , + .id =0 , + .num_resources =0 , + }, };static int __init mach_mpc82xx_fixup (struct platform_device *pdev)
arch/ppc/syslib/pq2_sys.c +2 -2
@@ -141,13 +141,13 @@ struct ppc_sys_spec ppc_sys_specs[] = { .ppc_sys_name = "8272", .mask = 0x0000ff00, .value = 0x00000c00, - .num_devices = 11, + .num_devices = 12, .device_list = (enum ppc_sys_devices []) { MPC82xx_CPM_FCC1, MPC82xx_CPM_FCC2, MPC82xx_CPM_SCC1, MPC82xx_CPM_SCC2, MPC82xx_CPM_SCC3, MPC82xx_CPM_SMC1, MPC82xx_CPM_SMC2, MPC82xx_CPM_SPI, MPC82xx_CPM_I2C, - MPC82xx_CPM_USB, MPC82xx_SEC1, + MPC82xx_CPM_USB, MPC82xx_SEC1, MPC82xx_MDIO_BB, }, },/* below is a list of the 8280 family of processors */
drivers/net/fs_enet/Makefile +3 -3
@@ -4,7 +4,7 @@ obj-$(CONFIG_FS_ENET) += fs_enet.o -obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o -obj-$(CONFIG_8260) += mac-fcc.o +obj-$(CONFIG_8xx) += mac-fec.o mac-scc.o mii-fec.o +obj-$(CONFIG_CPM2) += mac-fcc.o mii-bitbang.o -fs_enet-objs := fs_enet-main.o fs_enet-mii.o mii-bitbang.o mii-fixed.o +fs_enet-objs := fs_enet-main.o
drivers/net/fs_enet/fec.h new file +42 -0
42 lines not on this page · raw message
drivers/net/fs_enet/fs_enet-main.c +122 -76
294 lines not on this page · raw message
drivers/net/fs_enet/fs_enet-mii.c deleted +0 -507
507 lines not on this page · raw message
drivers/net/fs_enet/fs_enet.h +26 -3
@@ -5,6 +5,7 @@#include <linux/netdevice.h> #include <linux/types.h> #include <linux/list.h> +#include <linux/phy.h> #include <linux/fs_enet_pd.h>
@@ -18,6 +19,26 @@#include <asm/cpm2.h> #endif +/* This is used to operate with pins. +Note that the actual port size may +be different; cpm(s) handle it OK */ +struct bb_info { +u8 mdio_msk; +u8 *mdio_dir; +u8 *mdio_dat; +u8 mdc_msk; +u8 *mdc_dir; +u8 *mdc_dat; +int delay; +}; + + +struct fec_info { +fec_t * fecp; +u32 mii_speed; +}; + +/* hw driver ops */ struct fs_ops {int (*setup_data)(struct net_device *dev);
@@ -25,6 +46,7 @@ struct fs_ops {void (*free_bd)(struct net_device *dev);void (*cleanup_data)(struct net_device *dev);void (*set_multicast_list)(struct net_device *dev); +void (*adjust_link)(struct net_device *dev);void (*restart)(struct net_device *dev);void (*stop)(struct net_device *dev);void (*pre_request_irq)(struct net_device *dev,int irq);
@@ -100,9 +122,8 @@ struct fs_enet_mii_bus { }; }; -int fs_mii_bitbang_init (struct fs_enet_mii_bus *bus); +int fs_enet_mdio_bb_init (void );int fs_mii_fixed_init (struct fs_enet_mii_bus *bus); -int fs_mii_fec_init (struct fs_enet_mii_bus *bus);struct fs_enet_private {struct device *dev;/* pointer back to the device (must be initialized first) */
@@ -130,7 +151,9 @@ struct fs_enet_private {struct fs_enet_mii_bus *mii_bus;int interrupt; -int duplex, speed;/* current settings */ +u32 dpram_offset; +struct phy_device *phydev; +int oldduplex, oldspeed, oldlink;/* current settings */ /* event masks */ u32 ev_napi_rx;/* mask of NAPI rx events */
drivers/net/fs_enet/mac-fcc.c +7 -3
@@ -35,6 +35,7 @@#include <linux/bitops.h> #include <linux/fs.h> #include <linux/platform_device.h> +#include <linux/phy.h> #include <asm/immap_cpm2.h> #include <asm/mpc8260.h>
@@ -393,7 +394,7 @@ static void restart(struct net_device *d/* adjust to speed (for RMII mode) */ if (fpi->use_rmii) { -if (fep->speed ==100 ) +if (fep->phydev->speed ==100 )C8 (fcccp, fcc_gfemr,0x20 );else S8 (fcccp, fcc_gfemr,0x20 );
@@ -419,7 +420,7 @@ static void restart(struct net_device *dS32 (fccp, fcc_fpsmr,FCC_PSMR_RMII );/* adjust to duplex mode */ -if (fep->duplex) +if (fep->phydev->duplex)S32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );else C32 (fccp, fcc_fpsmr,FCC_PSMR_FDE |FCC_PSMR_LPB );
@@ -485,7 +486,10 @@ static void rx_bd_done(struct net_devicestatic void tx_kickstart (struct net_device *dev) { -/* nothing */ +struct fs_enet_private *fep =netdev_priv (dev); +fcc_t *fccp = fep->fcc.fccp; + +S32 (fccp, fcc_ftodr,0x80 ); }static u32 get_int_events (struct net_device *dev)
drivers/net/fs_enet/mac-fec.c +13 -118
189 lines not on this page · raw message
drivers/net/fs_enet/mac-scc.c +3 -1
@@ -368,7 +368,7 @@ static void restart(struct net_device *dW16 (sccp, scc_psmr,SCC_PSMR_ENCRC |SCC_PSMR_NIB22 );/* Set full duplex mode if needed */ -if (fep->duplex) +if (fep->phydev->duplex)S16 (sccp, scc_psmr,SCC_PSMR_LPB |SCC_PSMR_FDE );S32 (sccp, scc_gsmrl,SCC_GSMRL_ENR |SCC_GSMRL_ENT );
@@ -499,6 +499,8 @@ static void tx_restart(struct net_devicescc_cr_cmd (fep,CPM_CR_RESTART_TX ); } + +/*************************************************************************/ const struct fs_ops fs_scc_ops = {
drivers/net/fs_enet/mii-bitbang.c +221 -114
461 lines not on this page · raw message
drivers/net/fs_enet/mii-fec.c new file +245 -0
245 lines not on this page · raw message
drivers/net/fs_enet/mii-fixed.c deleted +0 -92
92 lines not on this page · raw message
include/asm-ppc/mpc8260.h +1 -0
@@ -83,6 +83,7 @@ enum ppc_sys_devices { MPC82xx_CPM_SMC2, MPC82xx_CPM_USB, MPC82xx_SEC1, + MPC82xx_MDIO_BB, NUM_PPC_SYS_DEVS, };
include/asm-ppc/mpc8xx.h +1 -0
@@ -111,6 +111,7 @@ enum ppc_sys_devices { MPC8xx_CPM_SMC1, MPC8xx_CPM_SMC2, MPC8xx_CPM_USB, + MPC8xx_MDIO_FEC, NUM_PPC_SYS_DEVS, };
include/linux/fs_enet_pd.h +13 -29
59 lines not on this page · raw message
What happened to this patch? It doesn't seem to have been applied to any trees. Well, I'm gonna give it a little review now, since I have some time.
Quoted 8 lines · Vitaly Bordug
This makes it possible for HW PHY-less boards to utilize PAL goodies. Generic routines to connect to fixed PHY are provided, as well as ability to specify software callback that fills up link, speed, etc. information into PHY descriptor (the latter feature not tested so far).
Signed-off-by Vitaly Bordug <[email protected]>---
[snip]
Quoted 19 lines
+/
*---------------------------------------------------------------------
--------
+ * This func is used to create all the necessary stuff, bind
+ * the fixed phy driver and register all it on themdio_bus_type.
+ * speed is either 10 or 100, duplex is boolean.
+ * number is used to create multiple fixed PHYs, so that several devices can
+ * utilize them simultaneously.
+
*---------------------------------------------------------------------
--------*/
+static intfixed_mdio_register_device(int number, int speed, int duplex)drivers/net/phy/fixed.c new file +5
-0+{ +struct mii_bus *new_bus; +struct fixed_info *fixed; +struct phy_device *phydev; +int err =0 ;
drivers/net/phy/fixed.c line 221
Quoted 10 lines
drivers/net/phy/fixed.c new file +10
-0+ +struct device * dev =kzalloc (sizeof (struct device ),GFP_KERNEL ); + +if (NULL == dev) +return -EINVAL ; + + new_bus =kzalloc (sizeof (struct mii_bus ),GFP_KERNEL ); + +if (NULL == new_bus) +return -ENOMEM ;
You don't free dev, here
drivers/net/phy/fixed.c line 228
Quoted 7 lines
drivers/net/phy/fixed.c new file +7
-0+ + fixed =kzalloc (sizeof (struct fixed_info ),GFP_KERNEL ); + +if (NULL == fixed) { +kfree (new_bus); +return -ENOMEM ; + }
And dev
Review
Quoted 2 lines
(quoted diff) +2
-0+ + fixed->regs = kzalloc(MII_REGS_NUM*sizeof(int), GFP_KERNEL);
You don't check for failure for regs's allocation.
[snip]
Quoted 8 lines
drivers/net/phy/fixed.c new file +5
-0+/* create phy_device and register it on the mdio bus */ + phydev =phy_device_create (new_bus,0 ,0 ); + +/* +Put the phydev pointer into the fixed pack so that bus read/ write code could be able
(quoted diff) +1
-0+ to access for instance attached netdev. Well it doesn't have todo so, only in case
drivers/net/phy/fixed.c line 261
Quoted 8 lines
drivers/net/phy/fixed.c new file +8
-0+of utilizing user-specified link-update... +*/ + fixed->phydev = phydev; + +if (NULL == phydev) { + err = -ENOMEM ; + goto bus_register_fail; + }
You're going to need to change this, because phydev isn't guaranteed to be NULL in the event of a failure to allocate. it will be ERR_PTR(-ENOMEM). I know you changed this in phy_device_create(), but I have more on that later. You should do:
if (IS_ERR(phydev)) {
err = PTR_ERR(-ENOMEM);
goto bus_register_fail;
}[snip]
drivers/net/phy/fixed.c line 302
Quoted 5 lines
drivers/net/phy/fixed.c new file +5
-0+ +return 0 ; + +bus_register_fail: +kfree (new_bus);
You need to free regs and dev, too
drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus · line 69
Quoted 10 lines
drivers/net/phy/mdio_bus.c +1
-1@@ -66,7 +66,7 @@ int mdiobus_register(struct mii_bus *bus phydev =get_phy_device (bus, i);if (IS_ERR (phydev)) -return PTR_ERR (phydev); +continue ;
No. Why'd you change that? Now mdiobus_register doesn't return an error if memory runs out. Here's how the system works: get_phy_device() can return one of three things:
1) A pointer to a newly allocated phy_device
2) a NULL pointer, indicating that there is no PHY at that address (indicated by the bus returning all Fs)
3) an error (due to bus read failure, or to memory allocation failure, as indicated by PTR_ERR(phydev)
This change has several issues:
1) due to the change below, IS_ERR(phydev) is never true
2) If you continue, mdiobus_register() will not inform its caller that it failed.
Quoted 8 lines
drivers/net/phy/phy_device.c +0
-0@@ -46,6 +46,35 @@ static struct phy_driver genphy_driver;extern int mdio_bus_init (void );extern void mdio_bus_exit (void );
drivers/net/phy/phy_device.c static struct phy_driver genphy_driver; · line 58
Quoted 10 lines
drivers/net/phy/phy_device.c +9
-0+struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id) +{ +struct phy_device *dev; +/* We allocate the device, and initialize the +* default values */ + dev =kcalloc (1 ,sizeof (*dev),GFP_KERNEL ); + +if (NULL == dev) +return NULL ;
Here's the other change which breaks get_phy_device(). Now it doesn't return an error when it fails to allocate memory, it returns NULL. Which mdiobus_register doesn't interpret as an error (because it isn't. Not every PHY address has a device on it).
Quoted 9 lines
drivers/net/phy/phy_device.c +9
-0+ + dev->speed =0 ; + dev->duplex =-1 ; + dev->pause = dev->asym_pause =0 ; + dev->link =1 ; + + dev->autoneg =AUTONEG_ENABLE ; + + dev->addr = addr;
drivers/net/phy/phy_device.c static struct phy_driver genphy_driver; · line 76
Quoted 10 lines
drivers/net/phy/phy_device.c +10
-0+ dev->phy_id = phy_id; + dev->bus = bus; + + dev->state =PHY_DOWN ; + +spin_lock_init (&dev->lock); + +return dev; +} +EXPORT_SYMBOL (phy_device_create);
Also, as a side note, I'm not completely convinced you need to go through this degree of effort to circumvent the PHY Layer's normal operation. I think it should be possible to make it simpler. With the right implementation, it should even be possible to do really "clever" things, like allow users to change the PHY settings with ethtool. However, this code exists and works (I'm assuming), and that's good enough for now. I'll be glad to have this capability next time someone asks me to boot linux on a simulator.
Andy Fleming
Quoted 4 lines · On Thu, 4 May 2006 19:21:12 -0500 Andy Fleming <[email protected]> wrote:
What happened to this patch? It doesn't seem to have been applied to any trees. Well, I'm gonna give it a little review now, since I have some time.
Under final review/updates, gonna to push uptodated shortly...
Quoted 58 lines · Vitaly Bordug
Quoted 11 lines
This makes it possible for HW PHY-less boards to utilize PAL goodies. Generic routines to connect to fixed PHY are provided, as well as ability
to specify software callback that fills up link, speed, etc. information
into PHY descriptor (the latter feature not tested so far).Signed-off-by Vitaly Bordug <[email protected]>---
[snip]
Quoted 19 lines
+/
*---------------------------------------------------------------------
--------
+ * This func is used to create all the necessary stuff, bind
+ * the fixed phy driver and register all it on themdio_bus_type.
+ * speed is either 10 or 100, duplex is boolean.
+ * number is used to create multiple fixed PHYs, so that several devices can
+ * utilize them simultaneously.
+
*---------------------------------------------------------------------
--------*/
+static intfixed_mdio_register_device(int number, int speed, int duplex)drivers/net/phy/fixed.c new file +5
-0+{ +struct mii_bus *new_bus; +struct fixed_info *fixed; +struct phy_device *phydev; +int err =0 ;drivers/net/phy/fixed.c line 221
Quoted 10 lines
drivers/net/phy/fixed.c new file +10
-0+ +struct device * dev =kzalloc (sizeof (struct device ),GFP_KERNEL ); + +if (NULL == dev) +return -EINVAL ; + + new_bus =kzalloc (sizeof (struct mii_bus ),GFP_KERNEL ); + +if (NULL == new_bus) +return -ENOMEM ;You don't free dev, here
drivers/net/phy/fixed.c line 228
Quoted 7 lines
drivers/net/phy/fixed.c new file +7
-0+ + fixed =kzalloc (sizeof (struct fixed_info ),GFP_KERNEL ); + +if (NULL == fixed) { +kfree (new_bus); +return -ENOMEM ; + }And dev
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + fixed->regs = kzalloc(MII_REGS_NUM*sizeof(int), GFP_KERNEL);You don't check for failure for regs's allocation.
As to upper notes, OK.
Quoted 24 lines
[snip]
Quoted 8 lines
drivers/net/phy/fixed.c new file +5
-0+/* create phy_device and register it on the mdio bus */ + phydev =phy_device_create (new_bus,0 ,0 ); + +/* +Put the phydev pointer into the fixed pack so that bus read/ write code could be able
(quoted diff) +1
-0+ to access for instance attached netdev. Well it doesn't have todo so, only in case
drivers/net/phy/fixed.c line 261
Quoted 8 lines
drivers/net/phy/fixed.c new file +8
-0+of utilizing user-specified link-update... +*/ + fixed->phydev = phydev; + +if (NULL == phydev) { + err = -ENOMEM ; + goto bus_register_fail; + }You're going to need to change this, because phydev isn't guaranteed to be NULL in the event of a failure to allocate. it will be
ERR_PTR(-ENOMEM). I know you changed this inphy_device_create(), but I have more on that later. You should do:
Quoted 5 lines
if (IS_ERR(phydev)) {
err = PTR_ERR(-ENOMEM);
goto bus_register_fail;
}Assuming IS_ERR will shoot on NULL too, the code is not quite right(see below) :) But I agree this check is odd - will fix.
Quoted 11 lines
[snip]
drivers/net/phy/fixed.c line 302
Quoted 5 lines
drivers/net/phy/fixed.c new file +5
-0+ +return 0 ; + +bus_register_fail: +kfree (new_bus);You need to free regs and dev, too
ok
Quoted 23 lines
drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus · line 69
Quoted 11 lines
drivers/net/phy/mdio_bus.c +1
-1@@ -66,7 +66,7 @@ int mdiobus_register(struct mii_bus *bus phydev =get_phy_device (bus, i);if (IS_ERR (phydev)) -return PTR_ERR (phydev); +continue ;No. Why'd you change that? Now
mdiobus_registerdoesn't return an error if memory runs out. Here's how the system works:get_phy_device()can return one of three things:1) A pointer to a newly allocated
phy_device
2) a NULL pointer, indicating that there is no PHY at that address (indicated by the bus returning all Fs)
3) an error (due to bus read failure, or to memory allocation failure, as indicated byPTR_ERR(phydev)
Quoted 5 lines
This change has several issues:
1) due to the change below,IS_ERR(phydev)is never true
2) If you continue,mdiobus_register()will not inform its caller that it failed.
I am not really stick to this change, but it simply does not work otherwise.
I want the whole bus to be scanned, and the code scans until first fail, and returns error when there's no phy. Hereby, having phy's on 0 and 3 I end up with only 0 registered on bus. So maybe check for NULL and continue, check for err and return... Will inquire and fix - no big deal.
Quoted 9 lines
Quoted 9 lines
drivers/net/phy/ renamed from drivers/net/phy/phy_device.c +0
-0
phy_device.c
index 7da0e3d..0dffecf 100644drivers/net/phy/phy_device.c +0
-0@@ -46,6 +46,35 @@ static struct phy_driver genphy_driver;extern int mdio_bus_init (void );extern void mdio_bus_exit (void );
Quoted 16 lines
drivers/net/phy/phy_device.c static struct phy_driver genphy_driver; · line 57
Quoted 10 lines
drivers/net/phy/phy_device.c +9
-0+struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id) +{ +struct phy_device *dev; +/* We allocate the device, and initialize the +* default values */ + dev =kcalloc (1 ,sizeof (*dev),GFP_KERNEL ); + +if (NULL == dev) +return NULL ;Here's the other change which breaks
get_phy_device(). Now it doesn't return an error when it fails to allocate memory, it returns NULL. Whichmdiobus_registerdoesn't interpret as an error (because it isn't. Not every PHY address has a device on it).
OK, this part definitely needs a bit attention and a rework. So, phy_device_create should return PTR_ERR if it fail to allocate memory, and we need to keep get_phy_device() return as it was, right?
Quoted 20 lines
Quoted 9 lines
drivers/net/phy/phy_device.c +9
-0+ + dev->speed =0 ; + dev->duplex =-1 ; + dev->pause = dev->asym_pause =0 ; + dev->link =1 ; + + dev->autoneg =AUTONEG_ENABLE ; + + dev->addr = addr;drivers/net/phy/phy_device.c static struct phy_driver genphy_driver; · line 76
Quoted 10 lines
drivers/net/phy/phy_device.c +10
-0+ dev->phy_id = phy_id; + dev->bus = bus; + + dev->state =PHY_DOWN ; + +spin_lock_init (&dev->lock); + +return dev; +} +EXPORT_SYMBOL (phy_device_create);
Quoted 9 lines
Also, as a side note, I'm not completely convinced you need to go through this degree of effort to circumvent the PHY Layer's normal operation. I think it should be possible to make it simpler. With the right implementation, it should even be possible to do really "clever" things, like allow users to change the PHY settings with ethtool. However, this code exists and works (I'm assuming), and that's good enough for now. I'll be glad to have this capability next time someone asks me to boot linux on a simulator.
I made it as it is not that complex as it seemed at the first sight,
and may be a proving ground to some incoming PAL feature. Also, if there is fixed PHY, it often does not mean it is really "fixed" - it may be just far too weird to suite into any known form, but still able to control the link etc.
So, the main aim is to do: if PAL doesn't know PHY, use fixed phy. If you do not want it fixed and wanna to control the link - ok, just implement the link update callback, pass it to emulated PHY, and here we go...
Signature · 2 lines
Sincerely, Vitaly
Quoted 27 lines · Vitaly Bordug
Quoted 24 lines · On Thu, 4 May 2006 19:21:12 -0500 Andy Fleming <[email protected]> wrote:
[snip]
Quoted 8 lines
drivers/net/phy/fixed.c new file +5
-0+/* create phy_device and register it on the mdio bus */ + phydev =phy_device_create (new_bus,0 ,0 ); + +/* +Put the phydev pointer into the fixed pack so that bus read/ write code could be able
(quoted diff) +1
-0+ to access for instance attached netdev. Well it doesn't have todo so, only in case
drivers/net/phy/fixed.c line 261
Quoted 8 lines
drivers/net/phy/fixed.c new file +8
-0+of utilizing user-specified link-update... +*/ + fixed->phydev = phydev; + +if (NULL == phydev) { + err = -ENOMEM ; + goto bus_register_fail; + }You're going to need to change this, because phydev isn't guaranteed to be NULL in the event of a failure to allocate. it will be
ERR_PTR(-ENOMEM). I know you changed this inphy_device_create(), but I have more on that later. You should do:
Quoted 8 lines
Quoted 5 lines
if (IS_ERR(phydev)) { err = PTR_ERR(-ENOMEM); goto bus_register_fail; }Assuming
IS_ERRwill shoot on NULL too, the code is not quite right(see below) :) But I agree this check is odd - will fix.
IS_ERR should be 0 if phydev is NULL. At least, that is my interpretation of the code:
#define IS_ERR_VALUE(x) unlikely((x) > (unsigned long)-1000L) static inline long IS_ERR(const void *ptr)
{
return IS_ERR_VALUE((unsigned long)ptr);
}Quoted 37 lines
Quoted 4 lines
[snip]
Quoted 9 lines
drivers/net/phy/fixed.c line 302
Quoted 5 lines
drivers/net/phy/fixed.c new file +5
-0+ +return 0 ; + +bus_register_fail: +kfree (new_bus);You need to free regs and dev, too
ok
Quoted 23 lines
drivers/net/phy/mdio_bus.c int mdiobus_register(struct mii_bus *bus · line 69
Quoted 11 lines
drivers/net/phy/mdio_bus.c +1
-1@@ -66,7 +66,7 @@ int mdiobus_register(struct mii_bus *bus phydev =get_phy_device (bus, i);if (IS_ERR (phydev)) -return PTR_ERR (phydev); +continue ;No. Why'd you change that? Now
mdiobus_registerdoesn't return an error if memory runs out. Here's how the system works:get_phy_device()can return one of three things:1) A pointer to a newly allocated
phy_device
2) a NULL pointer, indicating that there is no PHY at that address (indicated by the bus returning all Fs)
3) an error (due to bus read failure, or to memory allocation failure, as indicated byPTR_ERR(phydev)
Quoted 8 lines
Quoted 5 lines
This change has several issues:
1) due to the change below,IS_ERR(phydev)is never true
2) If you continue,mdiobus_register()will not inform its caller that it failed.I am not really stick to this change, but it simply does not work otherwise.
I want the whole bus to be scanned, and the code scans until first fail, and returns error when there's no phy. Hereby, having phy's on 0 and 3 I end up with only 0 registered on bus. So maybe check for NULL and continue, check for err and return... Will inquire and fix - no big deal.
I don't think you've understood the code. Was this happening to you? Because mdiobus_register scans every PHY. If get_phy_device returns an error, it means that it failed to allocate memory, or it failed to manipulate the bus. Both are terminal errors, since it means that either you can't allocate a device, or you can't actually read from the bus. And that means mdiobus_register() needs to return failure. Actually, it looks like there's a memory leak if that happens.
The behavior you suggest is what happens: If there is an error, the loop terminates. If it returned NULL, then the rest of the loop doesn't execute (except for setting bus->phymap[i];
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
drivers/net/phy/ renamed from drivers/net/phy/phy_device.c +0
-0
phy_device.c
index 7da0e3d..0dffecf 100644drivers/net/phy/phy_device.c +0
-0@@ -46,6 +46,35 @@ static struct phy_driver genphy_driver;extern int mdio_bus_init (void );extern void mdio_bus_exit (void );Quoted 16 lines
drivers/net/phy/phy_device.c static struct phy_driver genphy_driver; · line 57
Quoted 10 lines
drivers/net/phy/phy_device.c +9
-0+struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id) +{ +struct phy_device *dev; +/* We allocate the device, and initialize the +* default values */ + dev =kcalloc (1 ,sizeof (*dev),GFP_KERNEL ); + +if (NULL == dev) +return NULL ;Here's the other change which breaks
get_phy_device(). Now it doesn't return an error when it fails to allocate memory, it returns NULL. Whichmdiobus_registerdoesn't interpret as an error (because it isn't. Not every PHY address has a device on it).
Quoted 1 line
OK, this part definitely needs a bit attention and a rework. So,
phy_device_createshould returnPTR_ERRif it fail to allocate memory, and we need to keepget_phy_device()return as it was, right?
Were you having problems with the code the old way? Because I believe it should all just work as you want the way it was. If not, we need to look into why NULL pointers were triggering IS_ERR() checks.
Andy