gianfar: prevent resource conflict
PATCH 1/1 gianfar: prevent resource conflict
On eTSEC Ethernet devices, there are three memory regions to map. These regions map registers to control the TSEC interfaces, PHY access and TBI interface.
Depending on the port number and TSEC version, some of these resources may be shared within an instance of the driver or between instances of the driver.
Since dev_request_mem_region returns NULL to avoid resource conflicts if a region is already mapped the TSEC driver fails to initialise when these regions are shared. This patch works around this and makes all three memory regions available to each instance.
Below is a description of TSEC Ethernet port mapping for port 1 to 3. These ports are present in CPUs susch as the mpc8544 and P2020.
Each port has three set of registers:
* region 0 maps the TSEC registers.
* region 1 maps the PHY access registers always through port 1.
* region 2 maps the TBI interface registers.
The tables below shows how registers are mapped.
For instance, for TSEC version 1:
- port 2/register set 1 i.e p2/reg1 is the same region as port 1/register set 1 i.e p1/reg1. That is they share port 1 register set 1 as the same region.
As well is p3/reg1, p1/reg0 and p1/reg2 uses p1/reg1.
- port 2/register set 0 i.e p2/reg0 is not the same region as port 3/register set 0 i.e p3/reg0.
That is p2/r0 and p3/r0 are two different regions. However, port 2/register 2 is the same as port 2/register 0.
TSEC version 1:
ports/registers reg0 reg1 reg2 p1 p1/r1 p1/r1 p1/r1 p2 p2/r0 p1/r1 p2/r0 p3 p3/r0 p1/r1 p3/r0
TSEC version2:
ports/registers reg0 reg1 reg2 p1 p1/r0 p1/r1 p1/r1 p2 p2/r0 p1/r1 p2/r2 p3 p3/r0 p1/r1 p3/r2
--- drivers/net/gianfar.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)
drivers/net/gianfar.c +18 -1
@@ -28,6 +28,8 @@#define RX_BUF_CNT PKTBUFSRX#define BUF_ALIGN 8 +static void __iomem *phyregs; +/* * Initialize required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case,
@@ -481,8 +483,23 @@ static int gfar_probe(struct device_d *dev) edev = &priv->edev; priv->regs =dev_request_mem_region (dev,0 ); - priv->phyregs =dev_request_mem_region (dev,1 ); +if (priv->regs ==NULL ) + priv->regs = phyregs; + +if (phyregs ==NULL ) { + phyregs =dev_request_mem_region (dev,1 ); +if (phyregs ==NULL ) + phyregs = priv->regs; + } + priv->phyregs = phyregs; + priv->phyregs_sgmii =dev_request_mem_region (dev,2 ); +if (priv->phyregs_sgmii ==NULL ) { +if (IS_ENABLED (CONFIG_TSECV2 )) + priv->phyregs_sgmii = priv->phyregs; +else + priv->phyregs_sgmii = priv->regs; + } priv->phyaddr = gfar_info->phyaddr; priv->tbicr = gfar_info->tbicr;
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 64 lines · Renaud Barbier
On eTSEC Ethernet devices, there are three memory regions to map. These regions map registers to control the TSEC interfaces, PHY access and TBI interface.
Depending on the port number and TSEC version, some of these resources may be shared within an instance of the driver or between instances of the driver.
Since
dev_request_mem_regionreturns NULL to avoid resource conflicts if a region is already mapped the TSEC driver fails to initialise when these regions are shared. This patch works around this and makes all three memory regions available to each instance.Below is a description of TSEC Ethernet port mapping for port 1 to 3. These ports are present in CPUs susch as the mpc8544 and P2020.
Each port has three set of registers:
* region 0 maps the TSEC registers.
* region 1 maps the PHY access registers always through port 1.
* region 2 maps the TBI interface registers.The tables below shows how registers are mapped.
For instance, for TSEC version 1:
- port 2/register set 1 i.e p2/reg1 is the same region as port 1/register set 1 i.e p1/reg1. That is they share port 1 register set 1 as the same region.
As well is p3/reg1, p1/reg0 and p1/reg2 uses p1/reg1.- port 2/register set 0 i.e p2/reg0 is not the same region as port 3/register set 0 i.e p3/reg0.
That is p2/r0 and p3/r0 are two different regions. However, port 2/register 2 is the same as port 2/register 0.TSEC version 1:
ports/registers reg0 reg1 reg2 p1 p1/r1 p1/r1 p1/r1 p2 p2/r0 p1/r1 p2/r0 p3 p3/r0 p1/r1 p3/r0TSEC version2:
ports/registers reg0 reg1 reg2 p1 p1/r0 p1/r1 p1/r1 p2 p2/r0 p1/r1 p2/r2 p3 p3/r0 p1/r1 p3/r2Signed-off-by Renaud Barbier <[email protected]>--- drivers/net/gianfar.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)drivers/net/gianfar.c +2
-0@@ -28,6 +28,8 @@#define RX_BUF_CNT PKTBUFSRX#define BUF_ALIGN 8 +static void __iomem *phyregs; +/* * Initialize required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case,
drivers/net/gianfar.c static int gfar_probe(struct device_d *dev) · line 487
Quoted 6 lines
drivers/net/gianfar.c +2
-1@@ -481,8 +483,23 @@ static int gfar_probe(struct device_d *dev) edev = &priv->edev; priv->regs =dev_request_mem_region (dev,0 ); - priv->phyregs =dev_request_mem_region (dev,1 ); +if (priv->regs ==NULL ) + priv->regs = phyregs;
the first resource is for the ethernet registers and no phy registers, right?
Quoted 5 lines
drivers/net/gianfar.c +5
-0+ +if (phyregs ==NULL ) { + phyregs =dev_request_mem_region (dev,1 ); +if (phyregs ==NULL ) + phyregs = priv->regs;
drivers/net/gianfar.c static int gfar_probe(struct device_d *dev) · line 502
Quoted 10 lines
drivers/net/gianfar.c +9
-0+ } + priv->phyregs = phyregs; + priv->phyregs_sgmii =dev_request_mem_region (dev,2 ); +if (priv->phyregs_sgmii ==NULL ) { +if (IS_ENABLED (CONFIG_TSECV2 )) + priv->phyregs_sgmii = priv->phyregs; +else + priv->phyregs_sgmii = priv->regs; + }
I think you should really register the mdio buses as separate devices since it's the mdio buses that are shared between the different instances, not the registers. The following may be a starting point (untested)
From 480a54380c42d56e1b5f16fb718fe2c4a1a38ab0 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <[email protected]>
Date: Sat, 1 Jun 2013 11:16:37 +0200
Subject: [PATCH] net: gfar: register mdio buses as separate devices
--- arch/ppc/boards/freescale-p2020rdb/p2020rdb.c | 2 + arch/ppc/mach-mpc85xx/eth-devices.c | 32 +++---- arch/ppc/mach-mpc85xx/include/mach/gianfar.h | 2 + drivers/net/gianfar.c | 117 ++++++++++++++++++-------- drivers/net/gianfar.h | 5 +- 5 files changed, 103 insertions(+), 55 deletions(-)
arch/ppc/boards/freescale-p2020rdb/p2020rdb.c +2 -0
@@ -65,6 +65,8 @@ static struct gfar_info_struct gfar_info[] = { .phyaddr = 1, .tbiana = 0, .tbicr = 0, + .mdiobus = -1, /* FIXME */ + .mdiobus_sgmii = -1, /* FIXME */ }, };
arch/ppc/mach-mpc85xx/eth-devices.c +16 -16
@@ -22,28 +22,28 @@#include <common.h> #include <driver.h> +#include <init.h> #include <mach/immap_85xx.h> #include <mach/gianfar.h> -int fsl_eth_init (int num,struct gfar_info_struct *gf) +static int fsl_phy_init (void ) { -struct resource *res; +int i; + +for (i =0 ; i <4 ; i++) +add_generic_device ("gfar-phy" , i,NULL , +MDIO_BASE_ADDR + i *0x1000 ,0x1000 , +IORESOURCE_MEM ,NULL ); +return 0 ; +} - res =xzalloc (3 *sizeof (struct resource )); -/* TSEC interface registers */ - res[0 ].start =GFAR_BASE_ADDR + ((num -1 ) *0x1000 ); - res[0 ].end = res[0 ].start +0x1000 -1 ; - res[0 ].flags =IORESOURCE_MEM ; -/* External PHY access always through eTSEC1 */ - res[1 ].start =MDIO_BASE_ADDR ; - res[1 ].end = res[1 ].start +0x1000 -1 ; - res[1 ].flags =IORESOURCE_MEM ; -/* Access to TBI/RTBI interface. */ - res[2 ].start =MDIO_BASE_ADDR + ((num -1 ) *0x1000 ); - res[2 ].end = res[2 ].start +0x1000 -1 ; - res[2 ].flags =IORESOURCE_MEM ; +coredevice_initcall (fsl_phy_init); -add_generic_device_res ("gfar" ,DEVICE_ID_DYNAMIC , res,3 , gf); +int fsl_eth_init (int num,struct gfar_info_struct *gf) +{ +add_generic_device ("gfar" , num -1 ,NULL , +GFAR_BASE_ADDR + (num -1 ) *0x1000 ,0x1000 , +IORESOURCE_MEM , gf);return 0 ; }
arch/ppc/mach-mpc85xx/include/mach/gianfar.h +2 -0
@@ -26,6 +26,8 @@ struct gfar_info_struct {unsigned int phyaddr;unsigned int tbiana;unsigned int tbicr; +unsigned int mdiobus;/* mdio bus number (0..3) */ +unsigned int mdiobus_sgmii;/* mdio bus number for sgmii (0..3) */ };int fsl_eth_init (int num,struct gfar_info_struct *gf);
drivers/net/gianfar.c +81 -36
234 lines not on this page · raw message
drivers/net/gianfar.h +2 -3
@@ -266,10 +266,9 @@ struct rxbd8 {struct gfar_private {struct eth_device edev;void __iomem *regs; -void __iomem *phyregs; -void __iomem *phyregs_sgmii; +int mdiobus; +int mdiobus_sgmii;struct phy_info *phyinfo; -struct mii_bus miibus;volatile struct txbd8 *txbd;volatile struct rxbd8 *rxbd;uint txidx;
Signature · 12 lines
1.8.2.rc2 -- 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
Quoted 21 lines
Quoted 21 lines
--- drivers/net/gianfar.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-)drivers/net/gianfar.c +2
-0@@ -28,6 +28,8 @@#define RX_BUF_CNT PKTBUFSRX#define BUF_ALIGN 8 +static void __iomem *phyregs; +/* * Initialize required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case, @@ -481,8 +483,23 @@ static int gfar_probe(struct device_d *dev) edev = &priv->edev;
Quoted 7 lines
drivers/net/gianfar.c static int gfar_probe(struct device_d *dev)
Quoted 4 lines
drivers/net/gianfar.c +2
-1priv->regs =dev_request_mem_region (dev,0 ); - priv->phyregs =dev_request_mem_region (dev,1 ); +if (priv->regs ==NULL ) + priv->regs = phyregs;the first resource is for the ethernet registers and no phy registers, right?
Indeed
Quoted 13 lines
Quoted 13 lines
drivers/net/gianfar.c +11
-0+ +if (phyregs ==NULL ) { + phyregs =dev_request_mem_region (dev,1 ); +if (phyregs ==NULL ) + phyregs = priv->regs; + } + priv->phyregs = phyregs; + priv->phyregs_sgmii =dev_request_mem_region (dev,2 ); +if (priv->phyregs_sgmii ==NULL ) { +if (IS_ENABLED (CONFIG_TSECV2 )) + priv->phyregs_sgmii = priv->phyregs;
Quoted 9 lines
drivers/net/gianfar.c static int gfar_probe(struct device_d *dev) · line 502
Quoted 3 lines
drivers/net/gianfar.c +3
-0+else + priv->phyregs_sgmii = priv->regs; + }I think you should really register the mdio buses as separate devices since it's the mdio buses that are shared between the different instances, not the registers. The following may be a starting point (untested)
Thanks.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Hello Sacha,
I applied your patch and try it on our mpc8544 based board with a few modification.
This board uses eTSEC1. This means all 3 regions have the same base address.
I just did the following update to your patch. It only maps the eTSEC registers and mdio bus registers.
static int fsl_phy_init(void)
{
add_generic_device("gfar-phy", 0, NULL, MDIO_BASE_ADDR, 0x1000,
IORESOURCE_MEM, NULL);
return 0;}
coredevice_initcall(fsl_phy_init);
int fsl_eth_init(int num, struct gfar_info_struct *gf)
{
printf("FSL_ETH_INIT: num = %d, 0x%x\n", num - 1,
GFAR_BASE_ADDR + (num - 1) * 0x1000);
add_generic_device("gfar", num - 1, NULL,
GFAR_BASE_ADDR + (num - 1) * 0x1000, 0x1000,
IORESOURCE_MEM, gf);
return 0;}
I added a few debug messages in request_region and got:
barebox 2013.05.0-00706-g87df6ec-dirty #13 Tue Jun 4 17:17:34 BST 2013
Board: DA923RC
dev_request_mem_region:got resource
request_region:name = gfar-phy0, parent = 1ffa6494 request_region ok: 0xe0024000:0xe0024fff gfar_phy_probe:phy->regs= e0024000, 0gfar_phy_probe: id = 0mdio_bus: miibus0: probed
...FSL_ETH_INIT: num = 0, 0xe0024000
dev_request_mem_region:got resource
request_region:name = gfar0, parent = 1ffa6494request_region: 0xe0024000:0xe0024fff conflicts with 0xe0024000:0xe0024fff gfar_probe:priv->regs 00000000, 0
gfar_halt:regs = 00000000
Even though, two devices have been added, both have the same parent iomem and the same region is compared. A conflict is then detected. When gfar_probe requests its Ethernet register region, NULL is returned.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 5 lines · Renaud Barbier
Hello Sacha,
I applied your patch and try it on our mpc8544 based board with a few modification.
This board uses eTSEC1. This means all 3 regions have the same base address.
I think I misunderstood the situation. I thought that the mdio register space is separate from the network interface register space. So in reality the mdio register space is inside the network register (the TSEC) space, but one TSEC instance needs the mdio bus from the other one, right?
If that's the case then it's probably best to register a phy driver for each phy in a coredevice_initcall like I suggested and then use dev_get_mem_region in the phy driver instead of dev_request_mem_region.
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
Quoted 7 lines · Sascha Hauer
Quoted 5 lines · Renaud Barbier
Hello Sacha,
I applied your patch and try it on our mpc8544 based board with a few modification.
This board uses eTSEC1. This means all 3 regions have the same base address.
Quoted 5 lines
I think I misunderstood the situation. I thought that the mdio register space is separate from the network interface register space. So in reality the mdio register space is inside the network register (the TSEC) space, but one TSEC instance needs the mdio bus from the other one, right?
Yes.
All eTSEC uses the eTSEC1 region to access the mdio bus for external PHYs. Port eTSEC1 3 regions (Ethernet reg, External phy access, TBI interface) are in fact just one region.
For eTSEC2, the Ethernet registers and TBI interface are mapped by the same region but are not the same as the other port regions. The same applies for eTSEC3.
For TSEC version 2, the mapping is a bit different.
I will implement your suggestions below.
Quoted 7 lines
If that's the case then it's probably best to register a phy driver for each phy in a
coredevice_initcalllike I suggested and then usedev_get_mem_regionin the phy driver instead ofdev_request_mem_region.Sascha
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
v2 cover gianfar: prevent resource conflict
In reply to Renaud BarbierThis patch v2 avoids resource conflicts between the gianfar port instances by substituting dev_request_mem_region for dev_get_mem_region.
In addition, it separates the MDIO buses from their Ethernet device by creating MDIO bus devices to access the external bus and TBI interfaces.
This patch is tested on the P2020RDB for which there are 3 MDIO buses:
- The main MDIO bus "gfar-mdio", linked to port eTSEC1 is used to connect external PHYs for all ports and map the internal TBI interface of eTSEC1.
- The MDIO buses "gfar-tpiphy" map TBI interface registers on all remaining ports.
Renaud Barbier (2):
ppc: gianfar MDIO buses
P2020RDB: update build configuration
arch/ppc/boards/freescale-p2020rdb/p2020rdb.c | 13 ++- arch/ppc/configs/p2020rdb_defconfig | 4 +- arch/ppc/mach-mpc85xx/eth-devices.c | 44 +++++--- arch/ppc/mach-mpc85xx/include/mach/gianfar.h | 4 + drivers/net/gianfar.c | 146 +++++++++++++++++++------ drivers/net/gianfar.h | 13 ++- 6 files changed, 165 insertions(+), 59 deletions(-)
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v2 1/2 ppc: gianfar MDIO buses
In reply to Renaud BarbierThis commit creates MDIO bus devices to separate the MDIO bus abstraction from the Ethernet device initialisation.
It also updates the configuration of the P2020RDB ports.
--- arch/ppc/boards/freescale-p2020rdb/p2020rdb.c | 13 ++- arch/ppc/mach-mpc85xx/eth-devices.c | 44 +++++--- arch/ppc/mach-mpc85xx/include/mach/gianfar.h | 4 + drivers/net/gianfar.c | 146 +++++++++++++++++++------ drivers/net/gianfar.h | 13 ++- 5 files changed, 162 insertions(+), 58 deletions(-)
arch/ppc/boards/freescale-p2020rdb/p2020rdb.c +10 -3
@@ -59,12 +59,19 @@#define SYSCLK_50 50000000#define SYSCLK_100 100000000 -/* Ethernet. Use eTSEC3 */ +/* Define attributes for eTSEC2 and eTSEC3 */ static struct gfar_info_struct gfar_info[] = { { + .phyaddr =0 , + .tbiana =0x1a0 , + .tbicr =0x9140 , + .mdiobus_tbi =1 , + }, + { .phyaddr =1 , .tbiana =0 , .tbicr =0 , + .mdiobus_tbi =2 , }, };
@@ -82,8 +89,8 @@ static int devices_init(void)add_generic_device ("i2c-fsl" ,1 ,NULL ,I2C2_BASE_ADDR ,0x100 ,IORESOURCE_MEM , &i2cplat); -/* eTSEC3 */ -fsl_eth_init (3 , &gfar_info[0 ]); +fsl_eth_init (2 , &gfar_info[0 ]); +fsl_eth_init (3 , &gfar_info[1 ]);devfs_add_partition ("nor0" ,0xf80000 ,0x80000 ,DEVFS_PARTITION_FIXED ,"self0" );
arch/ppc/mach-mpc85xx/eth-devices.c +28 -16
56 lines not on this page · raw message
arch/ppc/mach-mpc85xx/include/mach/gianfar.h +4 -0
@@ -22,10 +22,14 @@* Platform data for the Motorola Triple Speed Ethernet Controller */ +#define GFAR_TBIPA_OFFSET 0x030/* TBI PHY address */ +#define GFAR_TBIPA_END 0x1f/* Last valid PHY address */ +struct gfar_info_struct {unsigned int phyaddr;unsigned int tbiana;unsigned int tbicr; +unsigned int mdiobus_tbi; };int fsl_eth_init (int num,struct gfar_info_struct *gf);
drivers/net/gianfar.c +111 -35
232 lines not on this page · raw message
drivers/net/gianfar.h +9 -4
@@ -205,7 +205,6 @@ struct rxbd8 {#define GFAR_ECNTRL_OFFSET 0x020/* Ethernet Control */ #define GFAR_MINFLR_OFFSET 0x024/* Minimum Frame Length */ #define GFAR_DMACTRL_OFFSET 0x02c/* DMA Control */ -#define GFAR_TBIPA_OFFSET 0x030/* TBI PHY address */ /* eTSEC transmit control and status register */ #define GFAR_TSTAT_OFFSET 0x104/* transmit status register */
@@ -263,13 +262,19 @@ struct rxbd8 {#define GFAR_ATTR_OFFSET 0xbf8/* Default Attribute Register */ #define GFAR_ATTRELI_OFFSET 0xbfc/* Default Attribute Extract Len/Idx */ +struct gfar_phy { +void __iomem *regs; +struct device_d *dev; +struct mii_bus miibus; +}; +struct gfar_private {struct eth_device edev;void __iomem *regs; -void __iomem *phyregs; -void __iomem *phyregs_sgmii; +int mdiobus_tbi; +struct gfar_phy *gfar_mdio; +struct gfar_phy *gfar_tbi;struct phy_info *phyinfo; -struct mii_bus miibus;volatile struct txbd8 *txbd;volatile struct rxbd8 *rxbd;uint txidx;
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedRe: [PATCH 1/2] ppc: gianfar MDIO buses
Quoted 6 lines · Renaud Barbier
This commit creates MDIO bus devices to separate the MDIO bus abstraction from the Ethernet device initialisation.
It also updates the configuration of the P2020RDB ports.
Signed-off-by Renaud Barbier <[email protected]>
Applied, thanks
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
PATCH v2 2/2 P2020RDB: update build configuration
In reply to Renaud BarbierUpdate the P2020RDB build configuration to enable useful development commands.
--- arch/ppc/configs/p2020rdb_defconfig | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
arch/ppc/configs/p2020rdb_defconfig +3 -1
@@ -24,9 +24,11 @@ CONFIG_RELOCATABLE=y CONFIG_DRIVER_NET_GIANFAR=y CONFIG_NET=y CONFIG_NET_PING=y +CONFIG_FS_TFTP=y CONFIG_NET_TFTP=y +CONFIG_CMD_TFTP=y CONFIG_PING=y -CONFIG_TFTP=y CONFIG_I2C=y CONFIG_I2C_IMX=y CONFIG_CMD_I2C=y +CONFIG_CMD_MIITOOL=y
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox