net: check error and introduce phylib
Subsystems (11)
v3 cover net: check error and introduce phylib
HI,
v3:
- fix comment
- add phy_driver probe and remove
- renambe phydev.h to phy.h and phylib.c to phy.c as in linux
please pull
The following changes since commit 8b3bf5971afbdf1acc5becabb6f15ba4b2a5559d:
tap: fix missing parent setting on eth_device (2012-09-12 17:26:26 +0200)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git tags/net_phylib
for you to fetch changes up to 4b7293febd1176262e3bfe2a3ecf37c0298675d8:
net: move the eth_dev status detection at driver level (2012-09-14 15:34:03 +0800)
----------------------------------------------------------------
net: check error and introduce phylib
Adapt phylib from linux
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready or down fail on open
Same behaviour as in linux and will allow to share code and simplify porting.
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (3):
net: introduce phylib
net: catch error on eth_send
net: move the eth_dev status detection at driver level
drivers/net/Kconfig | 2 + drivers/net/Makefile | 2 +- drivers/net/altera_tse.c | 18 ++--- drivers/net/altera_tse.h | 1 + drivers/net/at91_ether.c | 26 +++---- drivers/net/cs8900.c | 1 + drivers/net/designware.c | 40 ++++++----- drivers/net/dm9k.c | 9 +-- drivers/net/ep93xx.c | 7 +- drivers/net/fec_imx.c | 45 ++++++------ drivers/net/fec_imx.h | 1 + drivers/net/fec_mpc5200.c | 9 +-- drivers/net/gianfar.c | 30 ++++---- drivers/net/ks8851_mll.c | 11 ++- drivers/net/macb.c | 40 +++++++---- drivers/net/miidev.c | 206 ++++--------------------------------------------------- drivers/net/netx_eth.c | 7 +- drivers/net/phy/Kconfig | 17 +++++ drivers/net/phy/Makefile | 2 + drivers/net/phy/generic.c | 36 ++++++++++ drivers/net/phy/phy.c | 624 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/smc91111.c | 20 ++---- drivers/net/smc911x.c | 12 ++-- drivers/net/tap.c | 1 + drivers/net/usb/asix.c | 2 +- drivers/net/usb/smsc95xx.c | 2 +- drivers/net/usb/usbnet.c | 11 +-- include/linux/ethtool.h | 114 ++++++++++++++++++++++++++++++ include/linux/mii.h | 421 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- include/miidev.h | 13 +--- include/phy.h | 146 +++++++++++++++++++++++++++++++++++++++ include/usb/usbnet.h | 1 + net/eth.c | 4 +- net/net.c | 18 +++-- 34 files changed, 1443 insertions(+), 456 deletions(-) create mode 100644 drivers/net/phy/Kconfig create mode 100644 drivers/net/phy/Makefile create mode 100644 drivers/net/phy/generic.c create mode 100644 drivers/net/phy/phy.c create mode 100644 include/linux/ethtool.h create mode 100644 include/phy.h
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 1/3 net: introduce phylib
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on open
Same behaviour as in linux and will allow to share code and simplify porting.
--- drivers/net/Kconfig | 2 + drivers/net/Makefile | 2 +- drivers/net/altera_tse.c | 17 +- drivers/net/altera_tse.h | 1 + drivers/net/at91_ether.c | 24 +- drivers/net/designware.c | 38 +-- drivers/net/dm9k.c | 9 +- drivers/net/ep93xx.c | 7 +- drivers/net/fec_imx.c | 43 ++- drivers/net/fec_imx.h | 1 + drivers/net/fec_mpc5200.c | 9 +- drivers/net/gianfar.c | 28 +- drivers/net/ks8851_mll.c | 11 +- drivers/net/macb.c | 38 ++- drivers/net/miidev.c | 476 ++++++++++--------------------- drivers/net/netx_eth.c | 7 +- drivers/net/phy/Kconfig | 17 ++ drivers/net/phy/Makefile | 2 + drivers/net/phy/generic.c | 36 +++ drivers/net/phy/phy.c | 624 ++++++++++++++++++++++++++++++++++++++++ drivers/net/smc91111.c | 20 +- drivers/net/smc911x.c | 12 +- drivers/net/usb/asix.c | 2 +- drivers/net/usb/smsc95xx.c | 2 +- drivers/net/usb/usbnet.c | 10 +- include/linux/ethtool.h | 114 ++++++++ include/linux/mii.h | 675 +++++++++++++++++++++++++++++--------------- include/miidev.h | 12 +- include/phy.h | 146 ++++++++++ include/usb/usbnet.h | 1 + 30 files changed, 1671 insertions(+), 715 deletions(-) rewrite drivers/net/miidev.c (60%) create mode 100644 drivers/net/phy/Kconfig create mode 100644 drivers/net/phy/Makefile create mode 100644 drivers/net/phy/generic.c create mode 100644 drivers/net/phy/phy.c create mode 100644 include/linux/ethtool.h rewrite include/linux/mii.h (70%) create mode 100644 include/phy.h
drivers/net/Kconfig +2 -0
@@ -25,6 +25,8 @@ config MIIDEV menu "Network drivers " depends on NET +source "drivers/net/phy/Kconfig" + config DRIVER_NET_CS8900 bool "cs8900 ethernet driver" depends on HAS_CS8900
drivers/net/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-$(CONFIG_DRIVER_NET_FEC_IMX) += fec_imx.o obj-$(CONFIG_DRIVER_NET_EP93XX) += ep93xx.o obj-$(CONFIG_DRIVER_NET_MACB) += macb.o obj-$(CONFIG_DRIVER_NET_TAP) += tap.o -obj-$(CONFIG_MIIDEV) += miidev.o +obj-$(CONFIG_MIIDEV) += miidev.o phy/ obj-$(CONFIG_NET_USB) += usb/ obj-$(CONFIG_DRIVER_NET_TSE) += altera_tse.o obj-$(CONFIG_DRIVER_NET_KS8851_MLL) += ks8851_mll.o
drivers/net/altera_tse.c +8 -9
@@ -30,6 +30,7 @@#include <init.h> #include <clock.h> #include <linux/mii.h> +#include <phy.h> #include <io.h> #include <asm/dma-mapping.h>
@@ -347,9 +348,11 @@ static void tse_reset(struct eth_device *edev)static int tse_eth_open (struct eth_device *edev) {struct altera_tse_priv *priv = edev->priv; +int ret; -miidev_wait_aneg (priv->miidev); -miidev_print_status (priv->miidev); + ret =phy_device_connect (priv->miidev, priv->phy_addr,NULL ); +if (ret) +return ret;return 0 ; }
@@ -488,8 +491,6 @@ static int tse_init_dev(struct eth_device *edev)/* enable MAC */ writel (ALTERA_TSE_CMD_TX_ENA_MSK |ALTERA_TSE_CMD_RX_ENA_MSK , &mac_dev->command_config); -miidev_restart_aneg (priv->miidev); -return 0 ; }
@@ -550,11 +551,9 @@ static int tse_probe(struct device_d *dev) miidev->parent = dev;if (dev->platform_data !=NULL ) - miidev->address = *((int8_t *)(dev->platform_data)); -else { -printf ("No PHY address specified.\n" ); -return -ENODEV ; - } + priv->phy_addr = *((int8_t *)(dev->platform_data)); +else + priv->phy_addr =-1 ;mii_register (miidev);
drivers/net/altera_tse.h +1 -0
@@ -292,6 +292,7 @@ struct altera_tse_priv {void __iomem *sgdma_tx_regs;void __iomem *rx_desc;void __iomem *tx_desc; +int phy_addr;struct mii_device *miidev; };
drivers/net/at91_ether.c +12 -12
@@ -40,18 +40,17 @@#include <linux/mii.h> #include <errno.h> #include <asm/mmu.h> +#include <phy.h> #include "at91_ether.h" -#define SPEED_100 1 -#define DUPLEX_FULL 1 -struct ether_device {struct eth_device netdev;struct mii_device miidev;struct rbf_t *rbfp;struct rbf_t *rbfdt;unsigned char *rbf_framebuf; +int phy_addr; };#define to_ether (_nd) container_of(_nd, struct ether_device, netdev)
@@ -136,19 +135,19 @@ static int at91_ether_mii_write(struct mii_device *dev, int addr, int reg, int vreturn ret; } -static void update_linkspeed (struct mii_device *dev,int speed,int duplex) +static void update_linkspeed (struct mii_device *mdev) {unsigned int mac_cfg;/* Update the MAC */ mac_cfg =at91_emac_read (AT91_EMAC_CFG ) & ~(AT91_EMAC_SPD |AT91_EMAC_FD ); -if (speed ==SPEED_100 ) { -if (duplex ==DUPLEX_FULL )/* 100 Full Duplex */ +if (mdev->phydev->speed ==SPEED_100 ) { +if (mdev->phydev->duplex) mac_cfg |=AT91_EMAC_SPD |AT91_EMAC_FD ;else /* 100 Half Duplex */ mac_cfg |=AT91_EMAC_SPD ; }else { -if (duplex ==DUPLEX_FULL )/* 10 Full Duplex */ +if (mdev->phydev->duplex) mac_cfg |=AT91_EMAC_FD ;else {}/* 10 Half Duplex */ }
@@ -161,11 +160,12 @@ static int at91_ether_open(struct eth_device *edev)unsigned long ctl;struct ether_device *etdev =to_ether (edev);unsigned char *rbf_framebuf = etdev->rbf_framebuf; +int ret; -miidev_wait_aneg (&etdev->miidev); -miidev_print_status (&etdev->miidev); - -update_linkspeed (&etdev->miidev,SPEED_100 ,DUPLEX_FULL ); + ret =phy_device_connect (&etdev->miidev, etdev->phy_addr, + update_linkspeed); +if (ret) +return ret;/* Clear internal statistics */ ctl =at91_emac_read (AT91_EMAC_CTL );
@@ -327,7 +327,7 @@ static int at91_ether_probe(struct device_d *dev) ether_dev->rbf_framebuf =dma_alloc_coherent (MAX_RX_DESCR *MAX_RBUFF_SZ ); ether_dev->rbfdt =dma_alloc_coherent (sizeof (struct rbf_t ) *MAX_RX_DESCR ); - miidev->address = pdata->phy_addr; + ether_dev->phy_addr = pdata->phy_addr; miidev->read = at91_ether_mii_read; miidev->write = at91_ether_mii_write; miidev->edev = edev;
drivers/net/designware.c +22 -16
@@ -32,6 +32,7 @@#include <miidev.h> #include <asm/mmu.h> #include <net/designware.h> +#include <phy.h> #include "designware.h"
@@ -52,6 +53,7 @@ struct dw_eth_dev {struct eth_mac_regs *mac_regs_p;struct eth_dma_regs *dma_regs_p; +int phy_addr; };/* Speed specific definitions */
@@ -222,34 +224,38 @@ static int dwc_ether_init(struct eth_device *dev)return 0 ; } -static int dwc_ether_open (struct eth_device *dev) +static void dwc_update_linkspeed (struct mii_device *mdev) { +struct eth_device *edev = mdev->edev;struct dw_eth_dev *priv = dev->priv; -struct eth_mac_regs *mac_p = priv->mac_regs_p; -struct eth_dma_regs *dma_p = priv->dma_regs_p;u32 conf; -int link, speed; -miidev_wait_aneg (&priv->miidev); -miidev_print_status (&priv->miidev); - link =miidev_get_status (&priv->miidev); - -if (priv->fix_mac_speed) { - speed = link &MIIDEV_STATUS_IS_1000MBIT ?1000 : - (link &MIIDEV_STATUS_IS_100MBIT ?100 :10 ); - priv->fix_mac_speed (speed); - } +if (priv->fix_mac_speed) + priv->fix_mac_speed (mdev->phydev->speed); conf =readl (&mac_p->conf); -if (link &MIIDEV_STATUS_IS_FULL_DUPLEX ) +if (mdev->phydev->duplex) conf |=FULLDPLXMODE ;else conf &= ~FULLDPLXMODE ; -if (link &MIIDEV_STATUS_IS_1000MBIT ) +if (mdev->phydev->speed ==SPEED_1000 ) conf &= ~MII_PORTSELECT ;else conf |=MII_PORTSELECT ;writel (conf, &mac_p->conf); +} + +static int dwc_ether_open (struct eth_device *dev) +{ +struct dw_eth_dev *priv = dev->priv; +struct eth_mac_regs *mac_p = priv->mac_regs_p; +struct eth_dma_regs *dma_p = priv->dma_regs_p; +int ret; + + ret =phy_device_connect (&priv->miidev, priv->phy_addr, + dwc_update_linkspeed); +if (ret) +return ret;descs_init (dev);
@@ -408,7 +414,7 @@ static int dwc_ether_probe(struct device_d *dev) edev->get_ethaddr = dwc_ether_get_ethaddr; edev->set_ethaddr = dwc_ether_set_ethaddr; - miidev->address = pdata->phy_addr; + priv->phy_addr = pdata->phy_addr; miidev->read = dwc_ether_mii_read; miidev->write = dwc_ether_mii_write; miidev->edev = edev;
drivers/net/dm9k.c +2 -7
@@ -32,6 +32,7 @@#include <xfuncs.h> #include <dm9000.h> #include <errno.h> +#include <phy.h> #define DM9K_ID 0x90000A46#define CHIPR_DM9000A 0x19
@@ -472,9 +473,7 @@ static int dm9k_eth_open(struct eth_device *edev) {struct dm9k *priv = (struct dm9k *)edev->priv; -miidev_wait_aneg (&priv->miidev); -miidev_print_status (&priv->miidev); -return 0 ; +return phy_device_connect (&priv->miidev,0 ,NULL ); }static void dm9k_write_length (struct dm9k *priv,unsigned length)
@@ -696,9 +695,6 @@ static int dm9k_set_ethaddr(struct eth_device *edev, unsigned char *adr)static int dm9k_init_dev (struct eth_device *edev) { -struct dm9k *priv = (struct dm9k *)edev->priv; - -miidev_restart_aneg (&priv->miidev);return 0 ; }
@@ -742,7 +738,6 @@ static int dm9k_probe(struct device_d *dev) priv->miidev.read = dm9k_phy_read; priv->miidev.write = dm9k_phy_write; - priv->miidev.address =0 ; priv->miidev.flags =0 ; priv->miidev.edev = edev; priv->miidev.parent = dev;
drivers/net/ep93xx.c +6 -1
@@ -38,6 +38,7 @@#include <io.h> #include <linux/types.h> #include <mach/ep93xx-regs.h> +#include <phy.h> #include "ep93xx.h" #define EP93XX_MAX_PKT_SIZE 1536
@@ -199,9 +200,14 @@ static int ep93xx_eth_open(struct eth_device *edev)struct ep93xx_eth_priv *priv =ep93xx_get_priv (edev);struct mac_regs *regs =ep93xx_get_regs (edev);int i; +int ret;pr_debug ("+ep93xx_eth_open\n" ); + ret =phy_device_connect (&priv->miidev,0 ,NULL ); +if (ret) +return ret; +ep93xx_eth_reset (edev);/* Reset the descriptor queues' current and end address values */
@@ -500,7 +506,6 @@ static int ep93xx_eth_probe(struct device_d *dev) priv->miidev.read = ep93xx_phy_read; priv->miidev.write = ep93xx_phy_write; - priv->miidev.address =0 ; priv->miidev.flags =0 ; priv->miidev.parent = dev;
drivers/net/fec_imx.c +21 -22
76 lines not on this page · raw message
drivers/net/fec_imx.h +1 -0
@@ -137,6 +137,7 @@ struct fec_priv {int rbd_index;/* next receive BD to read */ struct buffer_descriptor __iomem *tbd_base;/* TBD ring */ int tbd_index;/* next transmit BD to write */ +int phy_addr;struct mii_device miidev; };
drivers/net/fec_mpc5200.c +3 -6
@@ -17,6 +17,7 @@#include <mach/fec.h> #include <mach/clocks.h> #include <miidev.h> +#include <phy.h> #include "fec_mpc5200.h" #define CONFIG_PHY_ADDR 1/* FIXME */
@@ -381,9 +382,6 @@ static int mpc5xxx_fec_init(struct eth_device *dev)debug ("mpc5xxx_fec_init... Done \n" ); -if (fec->xcv_type !=SEVENWIRE ) -miidev_restart_aneg (&fec->miidev); -return 0 ; }
@@ -413,8 +411,8 @@ static int mpc5xxx_fec_open(struct eth_device *edev)SDMA_TASK_ENABLE (FEC_RECV_TASK_NO );if (fec->xcv_type !=SEVENWIRE ) { -miidev_wait_aneg (&fec->miidev); -miidev_print_status (&fec->miidev); +return phy_device_connect (&fec->miidev,CONFIG_PHY_ADDR , +NULL ); }return 0 ;
@@ -685,7 +683,6 @@ int mpc5xxx_fec_probe(struct device_d *dev)if (fec->xcv_type !=SEVENWIRE ) { fec->miidev.read = fec5xxx_miidev_read; fec->miidev.write = fec5xxx_miidev_write; - fec->miidev.address =CONFIG_PHY_ADDR ; fec->miidev.flags = pdata->xcv_type ==MII10 ?MIIDEV_FORCE_10 :0 ; fec->miidev.edev = edev; fec->miidev.parent = dev;
drivers/net/gianfar.c +13 -15
@@ -21,6 +21,7 @@#include <command.h> #include <errno.h> #include <asm/io.h> +#include <phy.h> #include "gianfar.h" /* 2 seems to be the minimum number of TX descriptors to make it work. */
@@ -77,25 +78,21 @@ static void gfar_init_registers(void __iomem *regs)* Configure maccfg2 based on negotiated speed and duplex * reported by PHY handling code */ -static void gfar_adjust_link (struct eth_device *edev) +static void gfar_adjust_link (struct mii_device *mdev) { +struct eth_device *edev = mdev->edev;struct gfar_private *priv = edev->priv;struct device_d *mdev = priv->miidev.parent;void __iomem *regs = priv->regs;u32 ecntrl, maccfg2;uint32_t status; - status =miidev_get_status (&priv->miidev); - - priv->link = status &MIIDEV_STATUS_IS_UP ; -if (status &MIIDEV_STATUS_IS_FULL_DUPLEX ) - priv->duplexity =1 ; -else - priv->duplexity =0 ; + priv->link = mdev->phydev->link; + priv->duplexity = mdev->phydev->duplex; -if (status &MIIDEV_STATUS_IS_1000MBIT ) +if (mdev->phydev->speed ==SPEED_1000 ) priv->speed =1000 ; -else if (status &MIIDEV_STATUS_IS_100MBIT ) +if (mdev->phydev->speed ==SPEED_100 ) priv->speed =100 ;else priv->speed =10 ;
@@ -184,8 +181,6 @@ static int gfar_init(struct eth_device *edev)gfar_init_registers (regs); -miidev_restart_aneg (&priv->miidev); -return 0 ; }
@@ -194,6 +189,12 @@ static int gfar_open(struct eth_device *edev)int ix;struct gfar_private *priv = edev->priv;void __iomem *regs = priv->regs; +int ret; + + ret =phy_device_connect (&priv->miidev, priv->phy_addr, + gfar_adjust_link); +if (ret) +return ret;/* Point to the buffer descriptors */ out_be32 (regs +GFAR_TBASE0_OFFSET , (unsigned int )priv->txbd);
@@ -215,9 +216,6 @@ static int gfar_open(struct eth_device *edev) } priv->txbd[TX_BUF_CNT -1 ].status |=TXBD_WRAP ; -miidev_wait_aneg (&priv->miidev); -gfar_adjust_link (edev); -/* Enable Transmit and Receive */ setbits_be32 (regs +GFAR_MACCFG1_OFFSET ,GFAR_MACCFG1_RX_EN |GFAR_MACCFG1_TX_EN );
drivers/net/ks8851_mll.c +5 -6
@@ -33,6 +33,7 @@#include <errno.h> #include <clock.h> #include <io.h> +#include <phy.h> #define MAX_RECV_FRAMES 32#define MAX_BUF_SIZE 2048
@@ -783,11 +784,13 @@ static int ks8851_eth_open(struct eth_device *edev) {struct ks_net *priv = (struct ks_net *)edev->priv;struct device_d *dev = &edev->dev; +int ret;ks_enable_qmu (priv); -miidev_wait_aneg (&priv->miidev); -miidev_print_status (&priv->miidev); + ret =phy_device_connect (&priv->miidev,1 ,NULL ); +if (ret) +return ret;dev_dbg (dev,"eth_open\n" );
@@ -796,9 +799,6 @@ static int ks8851_eth_open(struct eth_device *edev)static int ks8851_init_dev (struct eth_device *edev) { -struct ks_net *priv = (struct ks_net *)edev->priv; - -miidev_restart_aneg (&priv->miidev);return 0 ; }
@@ -844,7 +844,6 @@ static int ks8851_probe(struct device_d *dev)/* setup mii state */ ks->miidev.read = ks_phy_read; ks->miidev.write = ks_phy_write; - ks->miidev.address =1 ; ks->miidev.flags =0 ; ks->miidev.edev = edev; ks->miidev.parent = dev;
drivers/net/macb.c +25 -13
@@ -51,6 +51,7 @@#include <linux/clk.h> #include <linux/err.h> #include <asm/mmu.h> +#include <phy.h> #include "macb.h"
@@ -97,6 +98,8 @@ struct macb_device {struct macb_dma_desc *rx_ring;struct macb_dma_desc *tx_ring; +int phy_addr; +const struct device *dev;struct eth_device netdev;
@@ -214,24 +217,33 @@ static int macb_recv(struct eth_device *edev)return 0 ; } +static void macb_adjust_link (struct mii_device *mdev) +{ +struct eth_device *edev = mdev->edev; +struct macb_device *macb = edev->priv; +u32 reg; + + reg =readl (macb->regs +MACB_NCFGR ); + reg &= ~(MACB_BIT (SPD ) |MACB_BIT (FD )); + +if (mdev->phydev->duplex) + reg |=MACB_BIT (FD ); +if (mdev->phydev->speed ==SPEED_100 ) + reg |=MACB_BIT (SPD ); + +writel (reg, macb->regs +MACB_NCFGR ); +} +static int macb_open (struct eth_device *edev) {struct macb_device *macb = edev->priv; -int duplex =1 , speed =1 ; -u32 ncfgr;debug ("%s\n" , __func__); -miidev_wait_aneg (&macb->miidev); -miidev_print_status (&macb->miidev); - - ncfgr =readl (macb->regs +MACB_NCFGR ); - ncfgr &= ~(MACB_BIT (SPD ) |MACB_BIT (FD )); -if (speed) - ncfgr |=MACB_BIT (SPD ); -if (duplex) - ncfgr |=MACB_BIT (FD ); -writel (ncfgr, macb->regs +MACB_NCFGR ); +/* Obtain the PHY's address/id */ +if (phy_device_connect (&macb->miidev, macb->phy_addr, + macb_adjust_link) <0 ) +return -1 ;return 0 ; }
@@ -430,7 +442,7 @@ static int macb_probe(struct device_d *dev) macb->miidev.read = macb_phy_read; macb->miidev.write = macb_phy_write; - macb->miidev.address = pdata->phy_addr; + macb->phy_addr = pdata->phy_addr; macb->miidev.flags = pdata->flags &AT91SAM_ETHER_FORCE_LINK ?MIIDEV_FORCE_LINK :0 ; macb->miidev.edev = edev;
drivers/net/miidev.c +145 -331
476 lines not on this page · raw message
drivers/net/netx_eth.c +4 -3
@@ -9,6 +9,7 @@#include <xfuncs.h> #include <init.h> #include <driver.h> +#include <phy.h> #define ETH_MAC_LOCAL_CONFIG 0x1560#define ETH_MAC_4321 0x1564
@@ -189,13 +190,14 @@ static int netx_eth_init_dev(struct eth_device *edev)for (i =2 ; i <=18 ; i++)PFIFO_REG (PFIFO_BASE (EMPTY_PTR_FIFO (xcno)) ) =FIFO_PTR_FRAMENO (i) |FIFO_PTR_SEGMENT (xcno); -miidev_restart_aneg (&priv->miidev);return 0 ; }static int netx_eth_open (struct eth_device *edev) { -return 0 ; +struct netx_eth_priv *priv = (struct netx_eth_priv *)edev->priv; + +return phy_device_connect (&priv->miidev,0 ,NULL ); }static void netx_eth_halt (struct eth_device *edev)
@@ -261,7 +263,6 @@ static int netx_eth_probe(struct device_d *dev) priv->miidev.read = netx_miidev_read; priv->miidev.write = netx_miidev_write; - priv->miidev.address =0 ; priv->miidev.flags =0 ; priv->miidev.parent = dev;
drivers/net/phy/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# +# PHY Layer Configuration +# + +menu "phylib " + +if MIIDEV + +comment "MII PHY device drivers" + +config GENERIC_PHY + bool "Drivers for the Generic PHYs" + default y + +endif + +endmenu
drivers/net/phy/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-y += phy.o +obj-$(CONFIG_GENERIC_PHY) += generic.o
drivers/net/phy/generic.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (c) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +* +*/ + +#include <common.h> +#include <phy.h> +#include <init.h> + +static struct phy_driver generic_phy = { + .drv.name ="Generic PHY" , + .phy_id =PHY_ANY_UID , + .phy_id_mask =PHY_ANY_UID , + .features =0 , +}; + +static int generic_phy_register (void ) +{ +return phy_driver_register (&generic_phy); +} +device_initcall (generic_phy_register);
drivers/net/phy/phy.c new file +624 -0
624 lines not on this page · raw message
drivers/net/smc91111.c +7 -13
@@ -74,6 +74,7 @@#include <errno.h> #include <clock.h> #include <io.h> +#include <phy.h> /*--------------------------------------------------------------- .
@@ -892,12 +893,14 @@ static void smc91c111_enable(struct eth_device *edev)static int smc91c111_eth_open (struct eth_device *edev) {struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv; -smc91c111_enable (edev); -miidev_wait_aneg (&priv->miidev); -miidev_print_status (&priv->miidev); +/* Configure the Receive/Phy Control register */ +SMC_SELECT_BANK (priv,0 ); +SMC_outw (priv,RPC_DEFAULT ,RPC_REG ); -return 0 ; +smc91c111_enable (edev); + +return phy_device_connect (&priv->miidev,0 ,NULL ); } static int smc91c111_eth_send(struct eth_device *edev, void *packet,
@@ -1279,14 +1282,6 @@ static void print_packet( unsigned char * buf, int length )static int smc91c111_init_dev (struct eth_device *edev) { -struct smc91c111_priv *priv = (struct smc91c111_priv *)edev->priv; - -/* Configure the Receive/Phy Control register */ -SMC_SELECT_BANK (priv,0 ); -SMC_outw (priv,RPC_DEFAULT ,RPC_REG ); - -miidev_restart_aneg (&priv->miidev); -return 0 ; }
@@ -1314,7 +1309,6 @@ static int smc91c111_probe(struct device_d *dev) priv->miidev.read = smc91c111_phy_read; priv->miidev.write = smc91c111_phy_write; - priv->miidev.address =0 ; priv->miidev.flags =0 ; priv->miidev.edev = edev; priv->miidev.parent = dev;
drivers/net/smc911x.c +5 -7
@@ -38,6 +38,7 @@#include <clock.h> #include <io.h> #include <smc911x.h> +#include <phy.h> #include "smc911x.h"
@@ -308,9 +309,11 @@ static void smc911x_enable(struct eth_device *edev)static int smc911x_eth_open (struct eth_device *edev) {struct smc911x_priv *priv = (struct smc911x_priv *)edev->priv; +int ret; -miidev_wait_aneg (&priv->miidev); -miidev_print_status (&priv->miidev); + ret =phy_device_connect (&priv->miidev,1 ,NULL ); +if (ret) +return ret;/* Turn on Tx + Rx */ smc911x_enable (edev);
@@ -405,13 +408,9 @@ static int smc911x_eth_rx(struct eth_device *edev)static int smc911x_init_dev (struct eth_device *edev) { -struct smc911x_priv *priv = (struct smc911x_priv *)edev->priv; -smc911x_set_mac_csr (edev,MAC_CR ,MAC_CR_TXEN |MAC_CR_RXEN |MAC_CR_HBDIS ); -miidev_restart_aneg (&priv->miidev); -return 0 ; }
@@ -538,7 +537,6 @@ static int smc911x_probe(struct device_d *dev) priv->miidev.read = smc911x_phy_read; priv->miidev.write = smc911x_phy_write; - priv->miidev.address =1 ; priv->miidev.flags =0 ; priv->miidev.edev = edev; priv->miidev.parent = dev;
drivers/net/usb/asix.c +1 -1
@@ -471,7 +471,7 @@ static int asix_init_mii(struct usbnet *dev) { dev->miidev.read = asix_mdio_read; dev->miidev.write = asix_mdio_write; - dev->miidev.address =asix_get_phy_addr (dev); + dev->phy_addr =asix_get_phy_addr (dev); dev->miidev.flags =0 ; dev->miidev.edev = &dev->edev; dev->miidev.parent = &dev->udev->dev;
drivers/net/usb/smsc95xx.c +1 -1
@@ -441,7 +441,7 @@ static int smsc95xx_phy_initialize(struct usbnet *dev)/* Initialize MII structure */ dev->miidev.read = smsc95xx_mdio_read; dev->miidev.write = smsc95xx_mdio_write; - dev->miidev.address =1 ;/* FIXME: asix_get_phy_addr(dev); */ + dev->phy_addr =1 ;/* FIXME: asix_get_phy_addr(dev); */ dev->miidev.flags =0 ; dev->miidev.edev = &dev->edev; dev->miidev.parent = &dev->udev->dev;
drivers/net/usb/usbnet.c +2 -8
@@ -4,6 +4,7 @@#include <asm/byteorder.h> #include <errno.h> #include <malloc.h> +#include <phy.h> static inline int usb_endpoint_dir_in (const struct usb_endpoint_descriptor *epd) {
@@ -160,8 +161,6 @@ static int usbnet_init(struct eth_device *edev)return ret; } -miidev_restart_aneg (&dev->miidev); -return 0 ; }
@@ -171,12 +170,7 @@ static int usbnet_open(struct eth_device *edev)dev_dbg (&edev->dev,"%s\n" ,__func__); -if (miidev_wait_aneg (&dev->miidev)) -return -1 ; - -miidev_print_status (&dev->miidev); - -return 0 ; +return phy_device_connect (&dev->miidev, dev->phy_addr,NULL ); }static void usbnet_halt (struct eth_device *edev)
include/linux/ethtool.h new file +114 -0
114 lines not on this page · raw message
include/linux/mii.h +443 -232
675 lines not on this page · raw message
include/miidev.h +1 -11
@@ -37,13 +37,12 @@ struct mii_device {struct device_d dev;struct device_d *parent; -int address;/* The address the phy has on the bus */ int (*read) (struct mii_device *dev,int addr,int reg);int (*write) (struct mii_device *dev,int addr,int reg,int value);int flags; -int capabilities; +struct phy_device *phydev;struct eth_device *edev;struct cdev cdev;struct list_head list;
@@ -51,15 +50,6 @@ struct mii_device {int mii_register (struct mii_device *dev);void mii_unregister (struct mii_device *mdev); -int miidev_restart_aneg (struct mii_device *mdev); -int miidev_wait_aneg (struct mii_device *mdev); -int miidev_get_status (struct mii_device *mdev); -#define MIIDEV_STATUS_IS_UP (1 << 0) -#define MIIDEV_STATUS_IS_FULL_DUPLEX (1 << 1) -#define MIIDEV_STATUS_IS_10MBIT (1 << 2) -#define MIIDEV_STATUS_IS_100MBIT (1 << 3) -#define MIIDEV_STATUS_IS_1000MBIT (1 << 4) -int miidev_print_status (struct mii_device *mdev);static int inline mii_write (struct mii_device *dev,int addr,int reg,int value) {
include/phy.h new file +146 -0
146 lines not on this page · raw message
include/usb/usbnet.h +1 -0
@@ -41,6 +41,7 @@ struct usbnet {/* protocol/interface state */ struct eth_device edev;struct mii_device miidev; +int phy_addr;int msg_enable;unsigned long data [5 ];
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/3 net: catch error on eth_send
--- net/net.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
net/net.c +11 -7
@@ -219,6 +219,7 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)static char *arp_packet;struct ethernet *et;unsigned retries =0 ; +int ret;if (!arp_packet) { arp_packet =net_alloc_packet ();
@@ -262,7 +263,9 @@ static int arp_request(IPaddr_t dest, unsigned char *ether) arp_ether = ether; -eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); +if (ret) +return ret; arp_start =get_time_ns ();while (arp_wait_ip) {
@@ -272,7 +275,9 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)if (is_timeout (arp_start,3 *SECOND )) {printf ("T " ); arp_start =get_time_ns (); -eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); +if (ret) +return ret; retries++; }
@@ -454,9 +459,7 @@ static int net_ip_send(struct net_connection *con, int len) con->ip->check =0 ; con->ip->check = ~net_checksum ((unsigned char *)con->ip,sizeof (struct iphdr )); -eth_send (con->packet,ETHER_HDR_SIZE +sizeof (struct iphdr ) + len); - -return 0 ; +return eth_send (con->packet,ETHER_HDR_SIZE +sizeof (struct iphdr ) + len); }int net_udp_send (struct net_connection *con,int len)
@@ -480,6 +483,7 @@ static int net_answer_arp(unsigned char *pkt, int len)struct arprequest *arp = (struct arprequest *)(pkt +ETHER_HDR_SIZE );struct ethernet *et = (struct ethernet *)pkt;unsigned char *packet; +int ret;debug ("%s\n" , __func__);
@@ -497,10 +501,10 @@ static int net_answer_arp(unsigned char *pkt, int len)if (!packet)return 0 ;memcpy (packet, pkt,ETHER_HDR_SIZE +ARP_HDR_SIZE ); -eth_send (packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (packet,ETHER_HDR_SIZE +ARP_HDR_SIZE );free (packet); -return 0 ; +return ret; }static void net_bad_packet (unsigned char *pkt,int len)
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/3] net: catch error on eth_send
Quoted 3 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
can you apply this one so I can just resent the phylib
master as it's a fix?
Best Regards,
J.
Quoted 72 lines
net/net.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)net/net.c +11
-7@@ -219,6 +219,7 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)static char *arp_packet;struct ethernet *et;unsigned retries =0 ; +int ret;if (!arp_packet) { arp_packet =net_alloc_packet ();@@ -262,7 +263,9 @@ static int arp_request(IPaddr_t dest, unsigned char *ether) arp_ether = ether; -eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); +if (ret) +return ret; arp_start =get_time_ns ();while (arp_wait_ip) {@@ -272,7 +275,9 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)if (is_timeout (arp_start,3 *SECOND )) {printf ("T " ); arp_start =get_time_ns (); -eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (arp_packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); +if (ret) +return ret; retries++; }@@ -454,9 +459,7 @@ static int net_ip_send(struct net_connection *con, int len) con->ip->check =0 ; con->ip->check = ~net_checksum ((unsigned char *)con->ip,sizeof (struct iphdr )); -eth_send (con->packet,ETHER_HDR_SIZE +sizeof (struct iphdr ) + len); - -return 0 ; +return eth_send (con->packet,ETHER_HDR_SIZE +sizeof (struct iphdr ) + len); }int net_udp_send (struct net_connection *con,int len)@@ -480,6 +483,7 @@ static int net_answer_arp(unsigned char *pkt, int len)struct arprequest *arp = (struct arprequest *)(pkt +ETHER_HDR_SIZE );struct ethernet *et = (struct ethernet *)pkt;unsigned char *packet; +int ret;debug ("%s\n" , __func__);@@ -497,10 +501,10 @@ static int net_answer_arp(unsigned char *pkt, int len)if (!packet)return 0 ;memcpy (packet, pkt,ETHER_HDR_SIZE +ARP_HDR_SIZE ); -eth_send (packet,ETHER_HDR_SIZE +ARP_HDR_SIZE ); + ret =eth_send (packet,ETHER_HDR_SIZE +ARP_HDR_SIZE );free (packet); -return 0 ; +return ret; }static void net_bad_packet (unsigned char *pkt,int len)Signature · 1 line
1.7.10.4
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/3 net: move the eth_dev status detection at driver level
In reply to Jean-Christophe PLAGNIOL-VILLARDas this is depend on the phy link status
If not phylib used force active
--- drivers/net/altera_tse.c | 3 ++- drivers/net/at91_ether.c | 2 ++ drivers/net/cs8900.c | 1 + drivers/net/designware.c | 2 ++ drivers/net/dm9k.c | 2 +- drivers/net/ep93xx.c | 2 +- drivers/net/fec_imx.c | 2 ++ drivers/net/fec_mpc5200.c | 2 +- drivers/net/gianfar.c | 2 ++ drivers/net/ks8851_mll.c | 2 +- drivers/net/macb.c | 2 ++ drivers/net/miidev.c | 10 ++++++++++ drivers/net/netx_eth.c | 2 +- drivers/net/smc91111.c | 2 +- drivers/net/smc911x.c | 2 +- drivers/net/tap.c | 1 + drivers/net/usb/usbnet.c | 3 ++- include/miidev.h | 1 + net/eth.c | 4 +++- 19 files changed, 37 insertions(+), 10 deletions(-)
drivers/net/altera_tse.c +2 -1
@@ -350,7 +350,8 @@ static int tse_eth_open(struct eth_device *edev)struct altera_tse_priv *priv = edev->priv;int ret; - ret =phy_device_connect (priv->miidev, priv->phy_addr,NULL ); + ret =phy_device_connect (priv->miidev, priv->phy_addr, + mii_generic_update_link);if (ret)return ret;
drivers/net/at91_ether.c +2 -0
@@ -152,6 +152,8 @@ static void update_linkspeed(struct mii_device *mdev)else {}/* 10 Half Duplex */ }at91_emac_write (AT91_EMAC_CFG , mac_cfg); + + edev->active = mdev->phydev->link; }static int at91_ether_open (struct eth_device *edev)
drivers/net/cs8900.c +1 -0
@@ -255,6 +255,7 @@ static int cs8900_open(struct eth_device *dev)struct cs8900_priv *priv = (struct cs8900_priv *)dev->priv;cs8900_reset (priv);cs8900_reginit (priv); + edev->active =1 ;return 0 ; }
drivers/net/designware.c +2 -0
@@ -243,6 +243,8 @@ static void dwc_update_linkspeed(struct mii_device *mdev)else conf |=MII_PORTSELECT ;writel (conf, &mac_p->conf); + + edev->active = mdev->phydev->link; }static int dwc_ether_open (struct eth_device *dev)
drivers/net/dm9k.c +1 -1
@@ -473,7 +473,7 @@ static int dm9k_eth_open(struct eth_device *edev) {struct dm9k *priv = (struct dm9k *)edev->priv; -return phy_device_connect (&priv->miidev,0 ,NULL ); +return phy_device_connect (&priv->miidev,0 , mii_generic_update_link); }static void dm9k_write_length (struct dm9k *priv,unsigned length)
drivers/net/ep93xx.c +1 -1
@@ -204,7 +204,7 @@ static int ep93xx_eth_open(struct eth_device *edev)pr_debug ("+ep93xx_eth_open\n" ); - ret =phy_device_connect (&priv->miidev,0 ,NULL ); + ret =phy_device_connect (&priv->miidev,0 , mii_generic_update_link);if (ret)return ret;
drivers/net/fec_imx.c +2 -0
@@ -361,6 +361,8 @@ static void fec_update_linkspeed(struct mii_device *mdev) rcntl |=FEC_R_CNTRL_RMII_10T ;writel (rcntl, fec->regs +FEC_R_CNTRL ); } + + edev->active = mdev->phydev->link; }/**
drivers/net/fec_mpc5200.c +1 -1
@@ -412,7 +412,7 @@ static int mpc5xxx_fec_open(struct eth_device *edev)if (fec->xcv_type !=SEVENWIRE ) {return phy_device_connect (&fec->miidev,CONFIG_PHY_ADDR , -NULL ); + mii_generic_update_link); }return 0 ;
drivers/net/gianfar.c +2 -0
@@ -97,6 +97,8 @@ static void gfar_adjust_link(struct mii_device *mdev)else priv->speed =10 ; + edev->active = mdev->phydev->link; +if (priv->link) {/* clear all bits relative with interface mode */ ecntrl =in_be32 (regs +GFAR_ECNTRL_OFFSET );
drivers/net/ks8851_mll.c +1 -1
@@ -788,7 +788,7 @@ static int ks8851_eth_open(struct eth_device *edev)ks_enable_qmu (priv); - ret =phy_device_connect (&priv->miidev,1 ,NULL ); + ret =phy_device_connect (&priv->miidev,1 , mii_generic_update_link);if (ret)return ret;
drivers/net/macb.c +2 -0
@@ -232,6 +232,8 @@ static void macb_adjust_link(struct mii_device *mdev) reg |=MACB_BIT (SPD );writel (reg, macb->regs +MACB_NCFGR ); + + edev->active = mdev->phydev->link; }static int macb_open (struct eth_device *edev)
drivers/net/miidev.c +10 -0
@@ -31,6 +31,16 @@static LIST_HEAD (miidev_list); +void mii_generic_update_link (struct mii_device *bus) +{ +struct eth_device *edev = bus->edev; + +if (!bus->phydev) + edev->active =1 ; +else + edev->active = bus->phydev->link; +} +static ssize_t miidev_read (struct cdev *cdev,void *_buf,size_t count,loff_t offset,ulong flags) {int i = count;
drivers/net/netx_eth.c +1 -1
@@ -197,7 +197,7 @@ static int netx_eth_open(struct eth_device *edev) {struct netx_eth_priv *priv = (struct netx_eth_priv *)edev->priv; -return phy_device_connect (&priv->miidev,0 ,NULL ); +return phy_device_connect (&priv->miidev,0 , mii_generic_update_link); }static void netx_eth_halt (struct eth_device *edev)
drivers/net/smc91111.c +1 -1
@@ -900,7 +900,7 @@ static int smc91c111_eth_open(struct eth_device *edev)smc91c111_enable (edev); -return phy_device_connect (&priv->miidev,0 ,NULL ); +return phy_device_connect (&priv->miidev,0 , mii_generic_update_link); } static int smc91c111_eth_send(struct eth_device *edev, void *packet,
drivers/net/smc911x.c +1 -1
@@ -311,7 +311,7 @@ static int smc911x_eth_open(struct eth_device *edev)struct smc911x_priv *priv = (struct smc911x_priv *)edev->priv;int ret; - ret =phy_device_connect (&priv->miidev,1 ,NULL ); + ret =phy_device_connect (&priv->miidev,1 , mii_generic_update_link);if (ret)return ret;
drivers/net/tap.c +1 -0
@@ -55,6 +55,7 @@ int tap_eth_rx (struct eth_device *edev)int tap_eth_open (struct eth_device *edev) { + edev->active =1 ;return 0 ; }
drivers/net/usb/usbnet.c +2 -1
@@ -170,7 +170,8 @@ static int usbnet_open(struct eth_device *edev)dev_dbg (&edev->dev,"%s\n" ,__func__); -return phy_device_connect (&dev->miidev, dev->phy_addr,NULL ); +return phy_device_connect (&dev->miidev, dev->phy_addr, + mii_generic_update_link); }static void usbnet_halt (struct eth_device *edev)
include/miidev.h +1 -0
@@ -50,6 +50,7 @@ struct mii_device {int mii_register (struct mii_device *dev);void mii_unregister (struct mii_device *mdev); +void mii_generic_update_link (struct mii_device *bus);static int inline mii_write (struct mii_device *dev,int addr,int reg,int value) {
net/eth.c +3 -1
@@ -139,9 +139,11 @@ int eth_send(void *packet, int length) ret = eth_current->open (eth_current);if (ret)return ret; - eth_current->active =1 ; } +if (!eth_current->active) +return -ENETDOWN ; +led_trigger_network (LED_TRIGGER_NET_TX );return eth_current->send (eth_current, packet, length);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 3/3] net: move the eth_dev status detection at driver level
Quoted 19 lines · Jean-Christophe PLAGNIOL-VILLARD
as this is depend on the phy link status
If not phylib used force active
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- drivers/net/altera_tse.c | 3 ++- drivers/net/at91_ether.c | 2 ++ drivers/net/cs8900.c | 1 + drivers/net/designware.c | 2 ++ drivers/net/dm9k.c | 2 +- drivers/net/ep93xx.c | 2 +- drivers/net/fec_imx.c | 2 ++ drivers/net/fec_mpc5200.c | 2 +- drivers/net/gianfar.c | 2 ++ drivers/net/ks8851_mll.c | 2 +- drivers/net/macb.c | 2 ++ drivers/net/miidev.c | 10 ++++++++++
Quoted 8 lines
drivers/net/netx_eth.c | 2 +- drivers/net/smc91111.c | 2 +- drivers/net/smc911x.c | 2 +- drivers/net/tap.c | 1 + drivers/net/usb/usbnet.c | 3 ++- include/miidev.h | 1 + net/eth.c | 4 +++- 19 files changed, 37 insertions(+), 10 deletions(-)
Had to squash the following into this patch to make it compile:
drivers/net/at91_ether.c +1 -1
@@ -153,7 +153,7 @@ static void update_linkspeed(struct mii_device *mdev) }at91_emac_write (AT91_EMAC_CFG , mac_cfg); - edev->active = mdev->phydev->link; + mdev->edev->active = mdev->phydev->link; }static int at91_ether_open (struct eth_device *edev)
drivers/net/cs8900.c +2 -2
@@ -250,9 +250,9 @@ static int cs8900_dev_init(struct eth_device *dev)return 0 ; } -static int cs8900_open (struct eth_device *dev) +static int cs8900_open (struct eth_device *edev) { -struct cs8900_priv *priv = (struct cs8900_priv *)dev->priv; +struct cs8900_priv *priv = (struct cs8900_priv *)edev->priv;cs8900_reset (priv);cs8900_reginit (priv); edev->active =1 ;
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 1/3] net: introduce phylib
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on open
Quoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
Had to squash the following in to fix compile breakage on i.MX6 boards.
Overall it seems there is enough room for cleanup still. We used to have a struct mii_device which was a combination of a mii_bus and a phy_device. Now we have a dedicated phy_device, but struct mii_device still has a single phy and a single cdev. I think we should move the struct cdev to struct phy_device and make the struct phy_device member of struct mii_device a list of phy_devices. Anyway, this can be done later.
For now I merged this series with the below changes.
Sascha
arch/arm/boards/freescale-mx6-arm2/board.c +21 -9
@@ -31,6 +31,7 @@#include <asm/mmu.h> #include <mach/generic.h> #include <sizes.h> +#include <phy.h> #include <mach/imx6.h> #include <mach/devices-imx6.h> #include <mach/iomux-mx6.h>
@@ -112,7 +113,9 @@ static struct fec_platform_data fec_info = {static int mx6_rgmii_rework (void ) {struct mii_device *mdev; +struct phy_device *pdev;u16 val; +int ret; mdev =mii_open ("phy0" );if (!mdev) {
@@ -120,26 +123,35 @@ static int mx6_rgmii_rework(void)return -ENODEV ; } + pdev = mdev->phydev; +if (!pdev) { +printf ("phy0 has no phydev\n" ); + ret = -ENODEV ; + goto out; + } +/* To enable AR8031 ouput a 125MHz clk from CLK_25M */ -mii_write (mdev, mdev->address,0xd ,0x7 ); -mii_write (mdev, mdev->address,0xe ,0x8016 ); -mii_write (mdev, mdev->address,0xd ,0x4007 ); +phy_write (pdev,0xd ,0x7 ); +phy_write (pdev,0xe ,0x8016 ); +phy_write (pdev,0xd ,0x4007 ); - val =mii_read (mdev, mdev->address,0xe ); + val =phy_read (pdev,0xe ); val &=0xffe3 ; val |=0x18 ; -mii_write (mdev, mdev->address,0xe , val); +phy_write (pdev,0xe , val);/* introduce tx clock delay */ -mii_write (mdev, mdev->address,0x1d ,0x5 ); +phy_write (pdev,0x1d ,0x5 ); - val =mii_read (mdev, mdev->address,0x1e ); + val =phy_read (pdev,0x1e ); val |=0x0100 ; -mii_write (mdev, mdev->address,0x1e , val); +phy_write (pdev,0x1e , val); + ret =0 ; +out:mii_close (mdev); -return 0 ; +return ret; }static int arm2_devices_init (void )
arch/arm/boards/freescale-mx6-sabrelite/board.c +19 -7
@@ -40,6 +40,7 @@#include <mach/gpio.h> #include <spi/spi.h> #include <mach/spi.h> +#include <phy.h> #define SABRELITE_SD3_WP IMX_GPIO_NR(7, 1)#define SABRELITE_SD3_CD IMX_GPIO_NR(7, 0)
@@ -143,6 +144,8 @@ static struct fec_platform_data fec_info = {int mx6_rgmii_rework (void ) {struct mii_device *mdev; +struct phy_device *pdev; +int ret; mdev =mii_open ("phy0" );if (!mdev) {
@@ -150,21 +153,30 @@ int mx6_rgmii_rework(void)return -ENODEV ; } -mii_write (mdev, mdev->address,0x09 ,0x0f00 ); + pdev = mdev->phydev; +if (!pdev) { +printf ("phy0 has no phydev\n" ); + ret = -ENODEV ; + goto out; + } + +phy_write (pdev,0x09 ,0x0f00 );/* do same as linux kernel */ /* min rx data delay */ -mii_write (mdev, mdev->address,0x0b ,0x8105 ); -mii_write (mdev, mdev->address,0x0c ,0x0000 ); +phy_write (pdev,0x0b ,0x8105 ); +phy_write (pdev,0x0c ,0x0000 );/* max rx/tx clock delay, min rx/tx control delay */ -mii_write (mdev, mdev->address,0x0b ,0x8104 ); -mii_write (mdev, mdev->address,0x0c ,0xf0f0 ); -mii_write (mdev, mdev->address,0x0b ,0x104 ); +phy_write (pdev,0x0b ,0x8104 ); +phy_write (pdev,0x0c ,0xf0f0 ); +phy_write (pdev,0x0b ,0x104 ); + ret =0 ; +out:mii_close (mdev); -return 0 ; +return ret; }static int sabrelite_ksz9021rn_setup (void )
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 1/3] net: introduce phylib
In reply to Jean-Christophe PLAGNIOL-VILLARDQuoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on open
Quoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))
The prototype of adjust_link seems wrong. A mii_device is a mii bus with potentially multiple phys. adjust_link should work on the phy_device. With the above, when a mii_device has multiple phys, a network driver has no way to figure out which phy has an updated link.
This probably bites Renaud who has a single mii bus for multiple network devices.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/3] net: introduce phylib
Quoted 28 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on openQuoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))The prototype of
adjust_linkseems wrong. Amii_deviceis a mii bus with potentially multiple phys.adjust_linkshould work on thephy_device. With the above, when amii_devicehas multiple phys, a network driver has no way to figure out which phy has an updated link.
Quoted 2 lines
This probably bites Renaud who has a single mii bus for multiple network devices.
not really as the phydev have a bus field so will be the same
but I guess we wil have to do like in linux attacehd the phydev to the eth_device
Best Regars,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 1/3] net: introduce phylib
Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 28 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on openQuoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))The prototype of
adjust_linkseems wrong. Amii_deviceis a mii bus with potentially multiple phys.adjust_linkshould work on thephy_device. With the above, when amii_devicehas multiple phys, a network driver has no way to figure out which phy has an updated link.
Quoted 3 lines
Quoted 2 lines
This probably bites Renaud who has a single mii bus for multiple network devices.
not really as the phydev have a bus field so will be the same
Renaud has two phys on the same mii bus, so when he is passed a struct mii_device, how can he get a pointer to his network device? He can't.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/3] net: introduce phylib
Quoted 30 lines · Sascha Hauer
Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 28 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on openQuoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))The prototype of
adjust_linkseems wrong. Amii_deviceis a mii bus with potentially multiple phys.adjust_linkshould work on thephy_device. With the above, when amii_devicehas multiple phys, a network driver has no way to figure out which phy has an updated link.
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
This probably bites Renaud who has a single mii bus for multiple network devices.
not really as the phydev have a bus field so will be the same
Renaud has two phys on the same mii bus, so when he is passed a struct
mii_device, how can he get a pointer to his network device? He can't.
as I said just after we should attached the phy to eth_device not mii_device
so he will have one phy per eth_device
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
maintainerRe: [PATCH 1/3] net: introduce phylib
Quoted 31 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 30 lines · Sascha Hauer
Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 28 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on openQuoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))The prototype of
adjust_linkseems wrong. Amii_deviceis a mii bus with potentially multiple phys.adjust_linkshould work on thephy_device. With the above, when amii_devicehas multiple phys, a network driver has no way to figure out which phy has an updated link.
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
This probably bites Renaud who has a single mii bus for multiple network devices.
not really as the phydev have a bus field so will be the same
Renaud has two phys on the same mii bus, so when he is passed a struct
mii_device, how can he get a pointer to his network device? He can't.as I said just after we should attached the phy to
eth_devicenotmii_device
Once again:
from fec_imx.c:
static void fec_update_linkspeed(struct mii_device *mdev)
{
struct eth_device *edev = mdev->edev;
...
}How will you get a pointer to edev once a mii_device has multiple phys, potentially connected to different network devices?
Quoted 2 lines
so he will have one phy per
eth_device
Yes, but multiple eth_devices per mii_device.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 1/3] net: introduce phylib
Quoted 50 lines · Sascha Hauer
Quoted 31 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 30 lines · Sascha Hauer
Quoted 29 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 28 lines · Sascha Hauer
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Adapt phylib from linux
switch all the driver to it
This will allow to have
- phy drivers
- to only connect the phy at then opening of the device
- if the phy is not ready fail on openQuoted 4 lines
Same behaviour as in linux and will allow to share code and simplify porting.
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>---
[...]
+
drivers/net/phy/phy.c line 124
Quoted 3 lines
drivers/net/phy/phy.c new file +3
-0+/* Automatically gets and returns the PHY device */ +int phy_device_connect (struct mii_device *bus,int addr, +void (*adjust_link) (struct mii_device *miidev))The prototype of
adjust_linkseems wrong. Amii_deviceis a mii bus with potentially multiple phys.adjust_linkshould work on thephy_device. With the above, when amii_devicehas multiple phys, a network driver has no way to figure out which phy has an updated link.Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
This probably bites Renaud who has a single mii bus for multiple network devices.
not really as the phydev have a bus field so will be the same
Renaud has two phys on the same mii bus, so when he is passed a struct
mii_device, how can he get a pointer to his network device? He can't.as I said just after we should attached the phy to
eth_devicenotmii_deviceOnce again:
from
fec_imx.c:static void
fec_update_linkspeed(struct mii_device *mdev){ struct eth_device *edev = mdev->edev; ... }
Quoted 7 lines
How will you get a pointer to edev once a
mii_devicehas multiple phys, potentially connected to different network devices?Quoted 2 lines
so he will have one phy per
eth_deviceYes, but multiple
eth_devicespermii_device.
no phydev at eth_device wait a few I send a patch
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox