Skip to contentSkip to conversation

net: introduce phylib

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 4 messages Sep 22, 2012 – Sep 23, 2012

Subsystems (10)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover net: introduce phylib

HI,

v6:
- probe phy at mdiobus_register
- reimplement the mdiobuss support

v5:
- drop edev in mii_device

v4:
- move phy_dev attachement to eth_device instead of mii_device this will allow multiple phy_device per mii bus
- move phy cdev to phy_device
- add interface type support (so phy driver can configure themselves if MII/RMII/RGMII etc...
- manage link status at framework level
- mx6 update to fixup the phy at device opening

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 0b3c3e77945243c262f9ff1275479e6d8ea1d5c3:

net: catch error on eth_send (2012-09-16 20:39:07 +0800)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git tags/net_phylib

for you to fetch changes up to c63381861263795d452b8acd1732163a728d8bc5:

net: introduce phylib (2012-09-22 13:16:11 +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 (1):
net: introduce phylib

 arch/arm/boards/freescale-mx6-arm2/board.c      |   43 +++++--------
 arch/arm/boards/freescale-mx6-sabrelite/board.c |   40 +++++--------
 arch/arm/configs/phycard_a_l1_defconfig         |    2 +-
 arch/arm/configs/tx51stk5_defconfig             |    2 +-
 drivers/net/Kconfig                             |   30 +++++-----
 drivers/net/Makefile                            |    2 +-
 drivers/net/altera_tse.c                        |   48 +++++++--------
 drivers/net/altera_tse.h                        |    3 +-
 drivers/net/at91_ether.c                        |   49 ++++++++-------
 drivers/net/designware.c                        |   62 ++++++++++---------
 drivers/net/dm9k.c                              |   50 +++++++---------
 drivers/net/ep93xx.c                            |   35 ++++++-----
 drivers/net/ep93xx.h                            |    2 +-
 drivers/net/fec_imx.c                           |   89 +++++++++++++++------------
 drivers/net/fec_imx.h                           |    6 +-
 drivers/net/fec_mpc5200.c                       |   54 ++++++++++-------
 drivers/net/fec_mpc5200.h                       |    4 +-
 drivers/net/gianfar.c                           |   61 ++++++++-----------
 drivers/net/gianfar.h                           |    2 +-
 drivers/net/ks8851_mll.c                        |   36 +++++------
 drivers/net/macb.c                              |   79 ++++++++++++++----------
 drivers/net/miidev.c                            |  316 ------------------------------------------------------------------------------------------------
 drivers/net/netx_eth.c                          |   26 ++++----
 drivers/net/phy/Kconfig                         |   17 ++++++
 drivers/net/phy/Makefile                        |    2 +
 drivers/net/phy/generic.c                       |   36 +++++++++++
 drivers/net/phy/mdio_bus.c                      |  250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c                           |  568 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/net/smc91111.c                          |   47 ++++++---------
 drivers/net/smc911x.c                           |   37 ++++++------
 drivers/net/usb/Kconfig                         |    4 +-
 drivers/net/usb/asix.c                          |   29 ++++-----
 drivers/net/usb/smsc95xx.c                      |   41 ++++++-------
 drivers/net/usb/usbnet.c                        |   11 +---
 include/fec.h                                   |    3 +
 include/linux/ethtool.h                         |  114 +++++++++++++++++++++++++++++++++++
 include/linux/mii.h                             |  421 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
 include/linux/phy.h                             |  266 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/miidev.h                                |   51 +++-------------
 include/net.h                                   |    4 ++
 include/usb/usbnet.h                            |    5 +-
 net/eth.c                                       |    8 ++-
 42 files changed, 2034 insertions(+), 921 deletions(-)
 delete mode 100644 drivers/net/miidev.c
 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/mdio_bus.c
 create mode 100644 drivers/net/phy/phy.c
 create mode 100644 include/linux/ethtool.h
 create mode 100644 include/linux/phy.h

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH v6 1/1 net: introduce phylib

Adapt phylib from linux

switch all the driver to it
reimplement mii bus

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 not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

---
 arch/arm/boards/freescale-mx6-arm2/board.c      |   43 +-
 arch/arm/boards/freescale-mx6-sabrelite/board.c |   40 +-
 arch/arm/configs/phycard_a_l1_defconfig         |    2 +-
 arch/arm/configs/tx51stk5_defconfig             |    2 +-
 drivers/net/Kconfig                             |   30 +-
 drivers/net/Makefile                            |    2 +-
 drivers/net/altera_tse.c                        |   48 +-
 drivers/net/altera_tse.h                        |    3 +-
 drivers/net/at91_ether.c                        |   49 +-
 drivers/net/designware.c                        |   62 ++-
 drivers/net/dm9k.c                              |   50 +-
 drivers/net/ep93xx.c                            |   35 +-
 drivers/net/ep93xx.h                            |    2 +-
 drivers/net/fec_imx.c                           |   89 +--
 drivers/net/fec_imx.h                           |    6 +-
 drivers/net/fec_mpc5200.c                       |   54 +-
 drivers/net/fec_mpc5200.h                       |    4 +-
 drivers/net/gianfar.c                           |   61 +-
 drivers/net/gianfar.h                           |    2 +-
 drivers/net/ks8851_mll.c                        |   36 +-
 drivers/net/macb.c                              |   79 +--
 drivers/net/miidev.c                            |  316 -----------
 drivers/net/netx_eth.c                          |   26 +-
 drivers/net/phy/Kconfig                         |   17 +
 drivers/net/phy/Makefile                        |    2 +
 include/fec.h => drivers/net/phy/generic.c      |   43 +-
 drivers/net/phy/mdio_bus.c                      |  250 +++++++++
 drivers/net/phy/phy.c                           |  568 +++++++++++++++++++
 drivers/net/smc91111.c                          |   47 +-
 drivers/net/smc911x.c                           |   37 +-
 drivers/net/usb/Kconfig                         |    4 +-
 drivers/net/usb/asix.c                          |   29 +-
 drivers/net/usb/smsc95xx.c                      |   41 +-
 drivers/net/usb/usbnet.c                        |   11 +-
 include/fec.h                                   |    3 +
 include/linux/ethtool.h                         |  114 ++++
 include/linux/mii.h                             |  675 +++++++++++++++--------
 include/linux/phy.h                             |  266 +++++++++
 include/miidev.h                                |   51 +-
 include/net.h                                   |    4 +
 include/usb/usbnet.h                            |    5 +-
 net/eth.c                                       |    8 +-
 42 files changed, 2140 insertions(+), 1076 deletions(-)
 delete mode 100644 drivers/net/miidev.c
 create mode 100644 drivers/net/phy/Kconfig
 create mode 100644 drivers/net/phy/Makefile
 copy include/fec.h => drivers/net/phy/generic.c (53%)
 create mode 100644 drivers/net/phy/mdio_bus.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/linux/phy.h
arch/arm/boards/freescale-mx6-arm2/board.c +16 -27
index e4a9a49..0e853a6 100644
@@ -26,7 +26,7 @@
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
 #include <partition.h>
-#include <miidev.h>
+#include <linux/phy.h>
 #include <asm/io.h>
 #include <asm/mmu.h>
 #include <mach/generic.h>
@@ -104,50 +104,39 @@ static int arm2_mem_init(void)
 }
 mem_initcall(arm2_mem_init);
 
-static struct fec_platform_data fec_info = {
-	.xcv_type = RGMII,
-	.phy_addr = 0,
-};
-
-static int mx6_rgmii_rework(void)
+static void mx6_rgmii_rework(struct phy_device *dev)
 {
-	struct mii_device *mdev;
 	u16 val;
 
-	mdev = mii_open("phy0");
-	if (!mdev) {
-		printf("unable to open phy0\n");
-		return -ENODEV;
-	}
-
 	/* 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(dev, 0xd, 0x7);
+	phy_write(dev, 0xe, 0x8016);
+	phy_write(dev, 0xd, 0x4007);
 
-	val = mii_read(mdev, mdev->address, 0xe);
+	val = phy_read(dev, 0xe);
 	val &= 0xffe3;
 	val |= 0x18;
-	mii_write(mdev, mdev->address, 0xe, val);
+	phy_write(dev, 0xe, val);
 
 	/* introduce tx clock delay */
-	mii_write(mdev, mdev->address, 0x1d, 0x5);
+	phy_write(dev, 0x1d, 0x5);
 
-	val = mii_read(mdev, mdev->address, 0x1e);
+	val = phy_read(dev, 0x1e);
 	val |= 0x0100;
-	mii_write(mdev, mdev->address, 0x1e, val);
-
-	mii_close(mdev);
-
-	return 0;
+	phy_write(dev, 0x1e, val);
 }
 
+static struct fec_platform_data fec_info = {
+	.xcv_type = RGMII,
+	.phy_init = mx6_rgmii_rework,
+	.phy_addr = 0,
+};
+
 static int arm2_devices_init(void)
 {
 	imx6_add_mmc3(NULL);
 
 	imx6_add_fec(&fec_info);
-	mx6_rgmii_rework();
 
 	armlinux_set_bootparams((void *)0x10000100);
 	armlinux_set_architecture(3837);
arch/arm/boards/freescale-mx6-sabrelite/board.c +14 -26
index c5bcf8b..6070e2e 100644
@@ -28,7 +28,7 @@
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
 #include <partition.h>
-#include <miidev.h>
+#include <linux/phy.h>
 #include <asm/io.h>
 #include <asm/mmu.h>
 #include <mach/generic.h>
@@ -136,38 +136,27 @@ static int sabrelite_mem_init(void)
 }
 mem_initcall(sabrelite_mem_init);
 
-static struct fec_platform_data fec_info = {
-	.xcv_type = RGMII,
-	.phy_addr = 6,
-};
-
-int mx6_rgmii_rework(void)
+static void mx6_rgmii_rework(struct phy_device *dev)
 {
-	struct mii_device *mdev;
-
-	mdev = mii_open("phy0");
-	if (!mdev) {
-		printf("unable to open phy0\n");
-		return -ENODEV;
-	}
-
-	mii_write(mdev, mdev->address, 0x09, 0x0f00);
+	phy_write(dev, 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(dev, 0x0b, 0x8105);
+	phy_write(dev, 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);
-
-	mii_close(mdev);
-
-	return 0;
+	phy_write(dev, 0x0b, 0x8104);
+	phy_write(dev, 0x0c, 0xf0f0);
+	phy_write(dev, 0x0b, 0x104);
 }
 
+static struct fec_platform_data fec_info = {
+	.xcv_type = RGMII,
+	.phy_init = mx6_rgmii_rework,
+	.phy_addr = 6,
+};
+
 static int sabrelite_ksz9021rn_setup(void)
 {
 	mxc_iomux_v3_setup_multiple_pads(sabrelite_enet_pads, ARRAY_SIZE(sabrelite_enet_pads));
@@ -266,7 +255,6 @@ static int sabrelite_devices_init(void)
 	sabrelite_ksz9021rn_setup();
 	imx6_iim_register_fec_ethaddr();
 	imx6_add_fec(&fec_info);
-	mx6_rgmii_rework();
 
 	sabrelite_ehci_init();
 
arch/arm/configs/phycard_a_l1_defconfig +1 -1
index cf980f7..4cf2d21 100644
@@ -134,7 +134,7 @@ CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_SERIAL_NS16550_OMAP_EXTENSIONS=y
-CONFIG_MIIDEV=y
+CONFIG_PHYLIB=y
 CONFIG_DRIVER_NET_SMC911X=y
 CONFIG_DRIVER_NET_SMC911X_ADDRESS_SHIFT=0
 CONFIG_SPI=n
arch/arm/configs/tx51stk5_defconfig +1 -1
index 7fff0f0..2c83189 100644
@@ -110,7 +110,7 @@ CONFIG_NET_TFTP=y
 CONFIG_NET_TFTP_PUSH=y
 CONFIG_DRIVER_SERIAL_IMX=y
 CONFIG_ARCH_HAS_FEC_IMX=y
-CONFIG_MIIDEV=y
+CONFIG_PHYLIB=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 CONFIG_DRIVER_SPI_IMX_2_3=y
 CONFIG_MTD=y
drivers/net/Kconfig +16 -14
index 3c5f729..99757d3 100644
@@ -19,26 +19,28 @@ config HAS_DESIGNWARE_ETH
 config ARCH_HAS_FEC_IMX
 	bool
 
-config MIIDEV
+config PHYLIB
 	bool
 
 menu "Network drivers               "
 	depends on NET
 
+source "drivers/net/phy/Kconfig"
+
 config DRIVER_NET_CS8900
 	bool "cs8900 ethernet driver"
 	depends on HAS_CS8900
 
 config DRIVER_NET_SMC911X
 	bool "smc911x ethernet driver"
-	select MIIDEV
+	select PHYLIB
 	help
 	  This option enables support for the SMSC LAN9[12]1[567]
 	  ethernet chip.
 
 config DRIVER_NET_SMC91111
 	bool "smc91111 ethernet driver"
-	select MIIDEV
+	select PHYLIB
 	help
 	  This option enables support for the SMSC LAN91C111
 	  ethernet chip.
@@ -46,37 +48,37 @@ config DRIVER_NET_SMC91111
 config DRIVER_NET_DM9K
 	bool "Davicom dm9k[E|A|B] ethernet driver"
 	depends on HAS_DM9000
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_NETX
 	bool "Hilscher Netx ethernet driver"
 	depends on HAS_NETX_ETHER
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_AT91_ETHER
 	bool "at91 ethernet driver"
 	depends on HAS_AT91_ETHER
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_MPC5200
 	bool "MPC5200 Ethernet driver"
 	depends on ARCH_MPC5200
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_FEC_IMX
 	bool "i.MX FEC Ethernet driver"
 	depends on ARCH_HAS_FEC_IMX
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_EP93XX
 	bool "EP93xx Ethernet driver"
 	depends on ARCH_EP93XX
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_MACB
 	bool "macb Ethernet driver"
 	depends on HAS_MACB
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_TAP
 	bool "tap Ethernet driver"
@@ -85,7 +87,7 @@ config DRIVER_NET_TAP
 config DRIVER_NET_TSE
 	depends on NIOS2
 	bool "Altera TSE ethernet driver"
-	select MIIDEV
+	select PHYLIB
 	help
 	  This option enables support for the Altera TSE MAC.
 
@@ -100,14 +102,14 @@ config TSE_USE_DEDICATED_DESC_MEM
 
 config DRIVER_NET_KS8851_MLL
 	bool "ks8851 mll ethernet driver"
-	select MIIDEV
+	select PHYLIB
 	help
 	  This option enables support for the Micrel KS8851 MLL
 	  ethernet chip.
 
 config DRIVER_NET_DESIGNWARE
 	bool "Designware Universal MAC ethernet driver"
-	select MIIDEV
+	select PHYLIB
 	depends on HAS_DESIGNWARE_ETH
 	help
 	  This option enables support for the Synopsys
@@ -121,7 +123,7 @@ config DRIVER_NET_DESIGNWARE_ALTDESCRIPTOR
 config DRIVER_NET_GIANFAR
 	bool "Gianfar Ethernet"
 	depends on ARCH_MPC85XX
-	select MIIDEV
+	select PHYLIB
 
 source "drivers/net/usb/Kconfig"
 
drivers/net/Makefile +1 -1
index 4d960e8..4939b7f 100644
@@ -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_PHYLIB)			+= 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 +22 -26

112 lines not on this page · raw message

drivers/net/altera_tse.h +2 -1
index 866dbce..5a66a7d 100644
@@ -292,7 +292,8 @@ struct altera_tse_priv {
 	void __iomem *sgdma_tx_regs;
 	void __iomem *rx_desc;
 	void __iomem *tx_desc;
-	struct mii_device *miidev;
+	int phy_addr;
+	struct mii_bus *miibus;
 };
 
 #endif /* _ALTERA_TSE_H_ */
drivers/net/at91_ether.c +26 -23

131 lines not on this page · raw message

drivers/net/designware.c +33 -29

132 lines not on this page · raw message

drivers/net/dm9k.c +21 -29

142 lines not on this page · raw message

drivers/net/ep93xx.c +20 -15
index c28fb79..a14c0ea 100644
@@ -34,17 +34,17 @@
 #include <command.h>
 #include <init.h>
 #include <malloc.h>
-#include <miidev.h>
 #include <io.h>
 #include <linux/types.h>
 #include <mach/ep93xx-regs.h>
+#include <linux/phy.h>
 #include "ep93xx.h"
 
 #define EP93XX_MAX_PKT_SIZE    1536
 
-static int ep93xx_phy_read(struct mii_device *mdev, int phy_addr, int phy_reg);
-static int ep93xx_phy_write(struct mii_device *mdev, int phy_addr, int phy_reg,
-			    int value);
+static int ep93xx_phy_read(struct mii_bus *bus, int phy_addr, int phy_reg);
+static int ep93xx_phy_write(struct mii_bus *bus, int phy_addr, int phy_reg,
+			    u16 value);
 
 static inline struct ep93xx_eth_priv *ep93xx_get_priv(struct eth_device *edev)
 {
@@ -199,9 +199,15 @@ 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(edev, &priv->miibus, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
+
 	ep93xx_eth_reset(edev);
 
 	/* Reset the descriptor queues' current and end address values */
@@ -498,11 +504,10 @@ static int ep93xx_eth_probe(struct device_d *dev)
 	edev->set_ethaddr = ep93xx_eth_set_ethaddr;
 	edev->parent = 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;
+	priv->miibus.read = ep93xx_phy_read;
+	priv->miibus.write = ep93xx_phy_write;
+	priv->miibus.parent = dev;
+	priv->miibus.priv = edev;
 
 	priv->tx_dq.base = calloc(NUMTXDESC,
 				sizeof(struct tx_descriptor));
@@ -532,7 +537,7 @@ static int ep93xx_eth_probe(struct device_d *dev)
 		goto eth_probe_failed_3;
 	}
 
-	mii_register(&priv->miidev);
+	mdiobus_register(&priv->miibus);
 	eth_register(edev);
 
 	ret = 0;
@@ -575,9 +580,9 @@ eth_probe_done:
 /**
  * Read a 16-bit value from an MII register.
  */
-static int ep93xx_phy_read(struct mii_device *mdev, int phy_addr, int phy_reg)
+static int ep93xx_phy_read(struct mii_bus *bus, int phy_addr, int phy_reg)
 {
-	struct mac_regs *regs = ep93xx_get_regs(mdev->edev);
+	struct mac_regs *regs = ep93xx_get_regs(bus->priv);
 	int value = -1;
 	uint32_t self_ctl;
 
@@ -618,10 +623,10 @@ static int ep93xx_phy_read(struct mii_device *mdev, int phy_addr, int phy_reg)
 /**
  * Write a 16-bit value to an MII register.
  */
-static int ep93xx_phy_write(struct mii_device *mdev, int phy_addr,
-			int phy_reg, int value)
+static int ep93xx_phy_write(struct mii_bus *bus, int phy_addr,
+			int phy_reg, u16 value)
 {
-	struct mac_regs *regs = ep93xx_get_regs(mdev->edev);
+	struct mac_regs *regs = ep93xx_get_regs(bus->priv);
 	uint32_t self_ctl;
 
 	pr_debug("+ep93xx_phy_write\n");
drivers/net/ep93xx.h +1 -1
index 875715f..4d50f70 100644
@@ -141,7 +141,7 @@ struct ep93xx_eth_priv {
 	struct tx_descriptor_queue	tx_dq;
 	struct tx_status_queue		tx_sq;
 
-	struct mii_device miidev;
+	struct mii_bus miibus;
 };
 
 #endif
drivers/net/fec_imx.c +52 -37

140 lines not on this page · raw message

drivers/net/fec_imx.h +5 -1
index b75b4d6..c8e758b 100644
@@ -137,7 +137,11 @@ 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 */
-	struct mii_device miidev;
+	int phy_addr;
+	phy_interface_t interface;
+	u32 phy_flags;
+	struct mii_bus miibus;
+	void (*phy_init)(struct phy_device *dev);
 };
 
 /**
drivers/net/fec_mpc5200.c +31 -23

102 lines not on this page · raw message

drivers/net/fec_mpc5200.h +3 -1
index f6da3e5..20ac607 100644
@@ -260,7 +260,9 @@ typedef struct {
 	uint16_t usedTbdIndex;		/* next transmit BD to clean */
 	uint16_t cleanTbdNum;		/* the number of available transmit BDs */
 
-	struct mii_device miidev;
+	phy_interface_t interface;
+	u32 phy_flags;
+	struct mii_bus miibus;
 } mpc5xxx_fec_priv;
 
 /* Ethernet parameter area */
drivers/net/gianfar.c +26 -35

138 lines not on this page · raw message

drivers/net/gianfar.h +1 -1
index a4ad99e..b52cc5a 100644
@@ -269,7 +269,7 @@ struct gfar_private {
 	void __iomem *phyregs;
 	void __iomem *phyregs_sgmii;
 	struct phy_info *phyinfo;
-	struct mii_device miidev;
+	struct mii_bus miibus;
 	volatile struct txbd8 *txbd;
 	volatile struct rxbd8 *rxbd;
 	uint txidx;
drivers/net/ks8851_mll.c +16 -20
index 71391cc..926c433 100644
@@ -26,13 +26,13 @@
 
 #include <command.h>
 #include <net.h>
-#include <miidev.h>
 #include <malloc.h>
 #include <init.h>
 #include <xfuncs.h>
 #include <errno.h>
 #include <clock.h>
 #include <io.h>
+#include <linux/phy.h>
 
 #define MAX_RECV_FRAMES			32
 #define MAX_BUF_SIZE			2048
@@ -372,7 +372,7 @@
 
 struct ks_net {
 	struct eth_device	edev;
-	struct mii_device	miidev;
+	struct mii_bus	miibus;
 	void __iomem		*hw_addr;
 	void __iomem		*hw_addr_cmd;
 	struct platform_device	*pdev;
@@ -536,10 +536,9 @@ static int ks_phy_reg(int reg)
  * caller. The mii-tool that the driver was tested with takes any -ve error
  * as real PHY capabilities, thus displaying incorrect data to the user.
  */
-static int ks_phy_read(struct mii_device *mdev, int addr, int reg)
+static int ks_phy_read(struct mii_bus *bus, int addr, int reg)
 {
-	struct eth_device *edev = mdev->edev;
-	struct ks_net *priv = (struct ks_net *)edev->priv;
+	struct ks_net *priv = (struct ks_net *)bus->priv;
 	int ksreg;
 	int result;
 
@@ -552,10 +551,9 @@ static int ks_phy_read(struct mii_device *mdev, int addr, int reg)
 	return result;
 }
 
-static int ks_phy_write(struct mii_device *mdev, int addr, int reg, int val)
+static int ks_phy_write(struct mii_bus *bus, int addr, int reg, u16 val)
 {
-	struct eth_device *edev = mdev->edev;
-	struct ks_net *priv = (struct ks_net *)edev->priv;
+	struct ks_net *priv = (struct ks_net *)bus->priv;
 	int ksreg;
 
 	ksreg = ks_phy_reg(reg);
@@ -783,11 +781,14 @@ 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(edev, &priv->miibus, 1, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	if (ret)
+		return ret;
 
 	dev_dbg(dev, "eth_open\n");
 
@@ -796,9 +797,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;
 }
 
@@ -842,12 +840,10 @@ static int ks8851_probe(struct device_d *dev)
 	edev->parent = 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;
+	ks->miibus.read = ks_phy_read;
+	ks->miibus.write = ks_phy_write;
+	ks->miibus.priv = ks;
+	ks->miibus.parent = dev;
 
 	/* simple check for a valid chip being connected to the bus */
 
@@ -868,7 +864,7 @@ static int ks8851_probe(struct device_d *dev)
 	ks_soft_reset(ks, GRR_GSR);
 	ks_setup(ks);
 
-	mii_register(&ks->miidev);
+	mdiobus_register(&ks->miibus);
 	eth_register(edev);
 	dev_dbg(dev, "%s MARL 0x%04x MARM 0x%04x MARH 0x%04x\n", __func__,
 		ks_rdreg16(ks, KS_MARL), ks_rdreg16(ks, KS_MARM),
drivers/net/macb.c +46 -33

145 lines not on this page · raw message

drivers/net/miidev.c deleted +0 -316

316 lines not on this page · raw message

drivers/net/netx_eth.c +13 -13
index 2d92a2e..a476425 100644
@@ -2,13 +2,13 @@
 #include <command.h>
 #include <net.h>
 #include <io.h>
-#include <miidev.h>
 #include <mach/netx-xc.h>
 #include <mach/netx-eth.h>
 #include <mach/netx-regs.h>
 #include <xfuncs.h>
 #include <init.h>
 #include <driver.h>
+#include <linux/phy.h>
 
 #define ETH_MAC_LOCAL_CONFIG 0x1560
 #define ETH_MAC_4321         0x1564
@@ -47,7 +47,7 @@
 #define CON_FIFO_PORT_LO(xcno)  (6 + ((xcno) << 3))    /* Index of the FIFO where sent Data packages are confirmed */
 
 struct netx_eth_priv {
-	struct mii_device miidev;
+	struct mii_bus miibus;
 	int xcno;
 };
 
@@ -118,7 +118,7 @@ static int netx_eth_rx (struct eth_device *edev)
 	return 0;
 }
 
-static int netx_miidev_read(struct mii_device *mdev, int phy_addr, int reg)
+static int netx_miibus_read(struct mii_bus *bus, int phy_addr, int reg)
 {
 	int value;
 
@@ -135,8 +135,8 @@ static int netx_miidev_read(struct mii_device *mdev, int phy_addr, int reg)
 	return value;
 }
 
-static int netx_miidev_write(struct mii_device *mdev, int phy_addr,
-	int reg, int val)
+static int netx_miibus_write(struct mii_bus *bus, int phy_addr,
+	int reg, u16 val)
 {
 	debug("%s: addr: 0x%02x reg: 0x%02x val: 0x%04x\n",__func__,
 	      phy_addr, reg, val);
@@ -189,13 +189,15 @@ 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(edev, &priv->miibus, 0, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
 }
 
 static void netx_eth_halt (struct eth_device *edev)
@@ -259,14 +261,12 @@ static int netx_eth_probe(struct device_d *dev)
 	edev->set_ethaddr = netx_eth_set_ethaddr;
 	edev->parent = 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;
+	priv->miibus.read = netx_miibus_read;
+	priv->miibus.write = netx_miibus_write;
+	priv->miibus.parent = dev;
 
 	netx_eth_init_phy();
-	mii_register(&priv->miidev);
+	mdiobus_register(&priv->miibus);
 	eth_register(edev);
 
         return 0;
drivers/net/phy/Kconfig new file +17 -0
new file mode 100644
index 0000000..b66261a
@@ -0,0 +1,17 @@
+#
+# PHY Layer Configuration
+#
+
+menu "phylib                       "
+
+if PHYLIB
+
+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
new file mode 100644
index 0000000..82e90d4
@@ -0,0 +1,2 @@
+obj-y += phy.o mdio_bus.o
+obj-$(CONFIG_GENERIC_PHY) += generic.o
drivers/net/phy/generic.c renamed from include/fec.h +15 -28

55 lines not on this page · raw message

drivers/net/phy/mdio_bus.c new file +250 -0

250 lines not on this page · raw message

drivers/net/phy/phy.c new file +568 -0

568 lines not on this page · raw message

drivers/net/smc91111.c +19 -28

103 lines not on this page · raw message

drivers/net/smc911x.c +17 -20
index f697608..c58ea72 100644
@@ -30,7 +30,6 @@
 
 #include <command.h>
 #include <net.h>
-#include <miidev.h>
 #include <malloc.h>
 #include <init.h>
 #include <xfuncs.h>
@@ -38,12 +37,13 @@
 #include <clock.h>
 #include <io.h>
 #include <smc911x.h>
+#include <linux/phy.h>
 
 #include "smc911x.h"
 
 struct smc911x_priv {
 	struct eth_device edev;
-	struct mii_device miidev;
+	struct mii_bus miibus;
 	void __iomem *base;
 
 	int shift;
@@ -198,9 +198,9 @@ static int smc911x_set_ethaddr(struct eth_device *edev, unsigned char *m)
 	return 0;
 }
 
-static int smc911x_phy_read(struct mii_device *mdev, int phy_addr, int reg)
+static int smc911x_phy_read(struct mii_bus *bus, int phy_addr, int reg)
 {
-	struct eth_device *edev = mdev->edev;
+	struct eth_device *edev = bus->priv;
 
 	while (smc911x_get_mac_csr(edev, MII_ACC) & MII_ACC_MII_BUSY);
 
@@ -212,10 +212,10 @@ static int smc911x_phy_read(struct mii_device *mdev, int phy_addr, int reg)
 	return smc911x_get_mac_csr(edev, MII_DATA);
 }
 
-static int smc911x_phy_write(struct mii_device *mdev, int phy_addr,
-	int reg, int val)
+static int smc911x_phy_write(struct mii_bus *bus, int phy_addr,
+	int reg, u16 val)
 {
-	struct eth_device *edev = mdev->edev;
+	struct eth_device *edev = bus->priv;
 
 	while (smc911x_get_mac_csr(edev, MII_ACC) & MII_ACC_MII_BUSY);
 
@@ -308,9 +308,12 @@ 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(edev, &priv->miibus, 1, NULL,
+				 0, PHY_INTERFACE_MODE_NA);
+	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;
 }
 
@@ -536,17 +535,15 @@ static int smc911x_probe(struct device_d *dev)
 	edev->set_ethaddr = smc911x_set_ethaddr;
 	edev->parent = dev;
 
-	priv->miidev.read = smc911x_phy_read;
-	priv->miidev.write = smc911x_phy_write;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

drivers/net/usb/Kconfig +2 -2
index b53dcc7..adb1b0b 100644

Lines of this file are not shown. View the raw message.

drivers/net/usb/asix.c +13 -16
index be5a170..97680cf 100644

Lines of this file are not shown. View the raw message.

drivers/net/usb/smsc95xx.c +19 -22

41 lines not on this page · raw message

drivers/net/usb/usbnet.c +3 -8
index c7e3606..80b4ae7 100644

Lines of this file are not shown. View the raw message.

include/fec.h +3 -0
index f56b023..6e1e1cd 100644

Lines of this file are not shown. View the raw message.

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/linux/phy.h new file +266 -0

266 lines not on this page · raw message

include/miidev.h +9 -42

51 lines not on this page · raw message

include/net.h +4 -0
index 9152943..39fad12 100644

Lines of this file are not shown. View the raw message.

include/usb/usbnet.h +3 -2
index 1609b2e..cb8ff03 100644

Lines of this file are not shown. View the raw message.

net/eth.c +6 -2
index c034eaa..6cfe4f2 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Part of the diff is not shown here. View the raw message.

maintainer
#2 lore raw
Quoted 20 lines · Jean-Christophe PLAGNIOL-VILLARD

Adapt phylib from linux

switch all the driver to it
reimplement mii bus

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 not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

+ * get_phy_id - reads the specified addr for its ID.
+ * @bus: the target MII bus
+ * @addr: PHY address on the MII bus
+ * @phy_id: where to store the ID retrieved.
+ *
+ * Description: Reads the ID registers of the PHY at @addr on the
+ * @bus, stores it in @phy_id and returns zero on success.
+ */

drivers/net/phy/phy.c line 79

Quoted 10 lines
drivers/net/phy/phy.c new file +10 -0
+int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id)
+{
+	int phy_reg;
+
+	/* Grab the bits from PHYIR1, and put them
+	 * in the upper half */
+	phy_reg = mdiobus_read(bus, addr, MII_PHYSID1);
+
+	io (phy_reg < 0)
+		return -EIO;

Which gcc version do you use? Mine doesn't understand 'io'

Please also fix this:

config: ppc pcm030_defconfig
drivers/net/fec_mpc5200.c: In function 'mpc5xxx_fec_probe':
drivers/net/fec_mpc5200.c:683:8: error: 'RMII' undeclared (first use in this function) drivers/net/fec_mpc5200.c:683:8: note: each undeclared identifier is reported only once for each function it appears in drivers/net/fec_mpc5200.c:686:8: error: 'RGMII' undeclared (first use inthis function)
make[2]: *** [drivers/net/fec_mpc5200.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [drivers/net] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [drivers] Error 2
make: *** Waiting for unfinished jobs....

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
#3 lore raw
Quoted 25 lines · Sascha Hauer
Quoted 24 lines · Jean-Christophe PLAGNIOL-VILLARD

Adapt phylib from linux

switch all the driver to it
reimplement mii bus

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 not up fail on open

Same behaviour as in linux and will allow to share code and simplify porting.

+ * get_phy_id - reads the specified addr for its ID.
+ * @bus: the target MII bus
+ * @addr: PHY address on the MII bus
+ * @phy_id: where to store the ID retrieved.
+ *
+ * Description: Reads the ID registers of the PHY at @addr on the
+ * @bus, stores it in @phy_id and returns zero on success.
+ */

drivers/net/phy/phy.c new file +4 -0
+int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id)
+{
+	int phy_reg;
+
Quoted 8 lines

drivers/net/phy/phy.c line 79

Quoted 6 lines
drivers/net/phy/phy.c new file +6 -0
+	/* Grab the bits from PHYIR1, and put them
+	 * in the upper half */
+	phy_reg = mdiobus_read(bus, addr, MII_PHYSID1);
+
+	io (phy_reg < 0)
+		return -EIO;

Which gcc version do you use? Mine doesn't understand 'io'

edit patch by mistake when checking it

the tag should be ok

Quoted 14 lines

Please also fix this:

config: ppc pcm030_defconfig
drivers/net/fec_mpc5200.c: In function 'mpc5xxx_fec_probe':
drivers/net/fec_mpc5200.c:683:8: error: 'RMII' undeclared (first use in this function) drivers/net/fec_mpc5200.c:683:8: note: each undeclared identifier is reported only once for each function it appears in drivers/net/fec_mpc5200.c:686:8: error: 'RGMII' undeclared (first use inthis function)
make[2]: *** [drivers/net/fec_mpc5200.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [drivers/net] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [drivers] Error 2
make: *** Waiting for unfinished jobs....

this freescale driver is piss me off with it's copy and paste

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox