Allow to specify the PHY number to use with a specific i.MX FEC/ENET Ethernet device
cover Allow to specify the PHY number to use with a specific i.MX FEC/ENET Ethernet device
The PHY device associated to a specific i.MX Ethernet device is not necessarily at address 0 on the MDIO bus.
This patch series adds the ability to set the PHY number on the MDIO bus for any i.MX6UL based board.
Jean-Christophe Dubois (3):
Add a phy-num property to the i.MX FEC emulator
Add the ability to select a different PHY for each i.MX6UL FEC
interface
Select MDIO device 2 and 1 as PHY devices for i.MW6UL EVK board.
hw/arm/fsl-imx6ul.c | 10 ++++++++++ hw/arm/mcimx6ul-evk.c | 2 ++ hw/net/imx_fec.c | 24 +++++++++++++++++------- hw/net/trace-events | 4 ++-- include/hw/arm/fsl-imx6ul.h | 2 ++ include/hw/net/imx_fec.h | 1 + 6 files changed, 34 insertions(+), 9 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 Add a phy-num property to the i.MX FEC emulator
We need a solution to use an Ethernet PHY that is not the first device on the MDIO bus (device 0 on MDIO bus).
As an example with the i.MX6UL the NXP SOC has 2 Ethernet devices but only one MDIO bus on which the 2 related PHY are connected but at unique addresses.
--- hw/net/imx_fec.c | 24 +++++++++++++++++------- hw/net/trace-events | 4 ++-- include/hw/net/imx_fec.h | 1 + 3 files changed, 20 insertions(+), 9 deletions(-)
hw/net/imx_fec.c +17 -7
@@ -280,12 +280,16 @@ static void imx_phy_reset(IMXFECState *s)static uint32_t imx_phy_read (IMXFECState *s,int reg) {uint32_t val; +uint32_t phy = reg /32 ; -if (reg >31 ) { -/* we only advertise one phy */ +if (phy != s->phy_num) { +qemu_log_mask (LOG_GUEST_ERROR ,"[%s.phy]%s: Bad phy num %u\n" , +TYPE_IMX_FEC , __func__, phy);return 0 ; } + reg %=32 ; +switch (reg) {case 0 :/* Basic Control */ val = s->phy_control;
@@ -331,20 +335,25 @@ static uint32_t imx_phy_read(IMXFECState *s, int reg)break ; } -trace_imx_phy_read (val, reg); +trace_imx_phy_read (val, phy, reg);return val; }static void imx_phy_write (IMXFECState *s,int reg,uint32_t val) { -trace_imx_phy_write (val, reg); +uint32_t phy = reg /32 ; -if (reg >31 ) { -/* we only advertise one phy */ +if (phy != s->phy_num) { +qemu_log_mask (LOG_GUEST_ERROR ,"[%s.phy]%s: Bad phy num %u\n" , +TYPE_IMX_FEC , __func__, phy);return ; } + reg %=32 ; + +trace_imx_phy_write (val, phy, reg); +switch (reg) {case 0 :/* Basic Control */ if (val &0x8000 ) {
@@ -926,7 +935,7 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,extract32 (value, 18, 10))); }else { -/* This a write operation */ +/* This is a write operation */ imx_phy_write (s,extract32 (value,18 ,10 ),extract32 (value,0 ,16 )); }/* raise the interrupt as the PHY operation is done */
@@ -1315,6 +1324,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf),DEFINE_PROP_UINT32 ("tx-ring-num" , IMXFECState, tx_ring_num,1 ), +DEFINE_PROP_UINT32 ("phy-num" , IMXFECState, phy_num,0 ),DEFINE_PROP_END_OF_LIST (), };
hw/net/trace-events +2 -2
@@ -413,8 +413,8 @@ i82596_set_multicast(uint16_t count) "Added %d multicast entries" i82596_channel_attention(void *s) "%p: Received CHANNEL ATTENTION" # imx_fec.c -imx_phy_read(uint32_t val, int reg) "0x%04"PRIx32" <= reg[%d]" -imx_phy_write(uint32_t val, int reg) "0x%04"PRIx32" => reg[%d]" +imx_phy_read(uint32_t val, int phy, int reg) "0x%04"PRIx32" <= phy[%d].reg[%d]" +imx_phy_write(uint32_t val, int phy, int reg) "0x%04"PRIx32" => phy[%d].reg[%d]" imx_phy_update_link(const char *s) "%s" imx_phy_reset(void) "" imx_fec_read_bd(uint64_t addr, int flags, int len, int data) "tx_bd 0x%"PRIx64" flags 0x%04x len %d data 0x%08x"
include/hw/net/imx_fec.h +1 -0
@@ -268,6 +268,7 @@ typedef struct IMXFECState {uint32_t phy_advertise;uint32_t phy_int;uint32_t phy_int_mask; +uint32_t phy_num;bool is_fec;
Signature · 1 line
2.25.1
PATCH 2/3 Add the ability to select a different PHY for each i.MX6UL FEC interface
In reply to Jean-Christophe DuboisAdd properties to the i.MX6UL processor to be able to select a particular PHY on the MDIO bus for each FEC device.
--- hw/arm/fsl-imx6ul.c | 10 ++++++++++ include/hw/arm/fsl-imx6ul.h | 2 ++ 2 files changed, 12 insertions(+)
hw/arm/fsl-imx6ul.c +10 -0
@@ -427,6 +427,9 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp)FSL_IMX6UL_ENET2_TIMER_IRQ , }; +object_property_set_uint (OBJECT (&s->eth[i]), + s->phy_num[i], +"phy-num" , &error_abort);object_property_set_uint (OBJECT (&s->eth[i]),FSL_IMX6UL_ETH_NUM_TX_RINGS ,"tx-ring-num" , &error_abort);
@@ -607,10 +610,17 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) FSL_IMX6UL_OCRAM_ALIAS_ADDR, &s->ocram_alias); } +static Property fsl_imx6ul_properties[] = { +DEFINE_PROP_UINT32 ("fec1-phy-num" , FslIMX6ULState, phy_num[0 ],0 ), +DEFINE_PROP_UINT32 ("fec2-phy-num" , FslIMX6ULState, phy_num[1 ],1 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void fsl_imx6ul_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc); +device_class_set_props (dc, fsl_imx6ul_properties); dc->realize = fsl_imx6ul_realize; dc->desc ="i.MX6UL SOC" ;/* Reason: Uses serial_hds and nd_table in realize() directly */
include/hw/arm/fsl-imx6ul.h +2 -0
@@ -87,6 +87,8 @@ typedef struct FslIMX6ULState {MemoryRegion caam;MemoryRegion ocram;MemoryRegion ocram_alias; + +uint32_t phy_num[FSL_IMX6UL_NUM_ETHS ]; } FslIMX6ULState;enum FslIMX6ULMemoryMap {
Signature · 1 line
2.25.1
PATCH 3/3 Select MDIO device 2 and 1 as PHY devices for i.MX6UL EVK board.
In reply to Jean-Christophe DuboisThe i.MX6UL EVK 14x14 board uses:
- PHY 2 for FEC 1
- PHY 1 for FEC 2
--- hw/arm/mcimx6ul-evk.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/mcimx6ul-evk.c +2 -0
@@ -40,6 +40,8 @@ static void mcimx6ul_evk_init(MachineState *machine) s =FSL_IMX6UL (object_new (TYPE_FSL_IMX6UL ));object_property_add_child (OBJECT (machine),"soc" ,OBJECT (s)); +object_property_set_uint (OBJECT (s),2 ,"fec1-phy-num" , &error_fatal); +object_property_set_uint (OBJECT (s),1 ,"fec2-phy-num" , &error_fatal);qdev_realize (DEVICE (s),NULL , &error_fatal); memory_region_add_subregion(get_system_memory(), FSL_IMX6UL_MMDC_ADDR,
Signature · 1 line
2.25.1
Peter Maydell
AppliedQuoted 4 lines · Jean-Christophe Dubois
The PHY device associated to a specific i.MX Ethernet device is not necessarily at address 0 on the MDIO bus.
Quoted 8 lines
This patch series adds the ability to set the PHY number on the MDIO bus for any i.MX6UL based board.
Jean-Christophe Dubois (3):
Add a phy-num property to the i.MX FEC emulator
Add the ability to select a different PHY for each i.MX6UL FEC
interface
Select MDIO device 2 and 1 as PHY devices for i.MW6UL EVK board.
Applied to target-arm.next, thanks.
-- PMM