Add Ethernet device for i.MX6 SOC
Subsystems (2)
v4 cover Add Ethernet device for i.MX6 SOC
This patch series adds Gb ENET Ethernet device to the i.MX6 SOC.
The ENET device is an evolution of the FEC device present on the i.MX25 SOC and is backward compatible with it.
Therefore the ENET support has been added to the actual Qemu FEC device ( rather than adding a new device).
The Patch has been tested by:
* Booting linux on i.MX25 PDK board emulation and accessing internet
* Booting linux on i.MX6 Sabrelite board emulation and accessing internet
Jean-Christophe Dubois (8):
net: improve UDP/TCP checksum computation.
net: handle optional VLAN header in checksum computation. i.MX: Fix FEC code for MDIO operation selection i.MX: Fix FEC code for MDIO address selection i.MX: Fix FEC code for ECR register reset value. i.MX: move FEC device to a register array structure. Add ENET/Gbps Ethernet support to FEC device
Add ENET device to i.MX6 SOC.
hw/arm/fsl-imx25.c | 3 + hw/arm/fsl-imx6.c | 17 + hw/net/imx_fec.c | 995 ++++++++++++++++++++++++++++++++++------------ include/hw/arm/fsl-imx6.h | 6 +- include/hw/net/imx_fec.h | 248 +++++++++--- net/checksum.c | 121 ++++-- 6 files changed, 1060 insertions(+), 330 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/8 net: improve UDP/TCP checksum computation.
* based on Eth, UDP, TCP struct present in eth.h instead of hardcoded indexes and sizes.
* based on various macros present in eth.h.
---
Changes since v1:
* None
Changes since v2:
* The patch was split in 2 parts:
- a rewrite of the TCP/UDB checksum function (this patch)
- the addition of the support of the VLAN header (next patch).
Changes since v3:
* None
net/checksum.c | 94 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 27 deletions(-)
net/checksum.c +67 -27
@@ -18,9 +18,7 @@#include "qemu/osdep.h" #include "qemu-common.h" #include "net/checksum.h" - -#define PROTO_TCP 6 -#define PROTO_UDP 17 +#include "net/eth.h" uint32_t net_checksum_add_cont (int len,uint8_t *buf,int seq) {
@@ -57,40 +55,82 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,void net_checksum_calculate (uint8_t *data,int length) { -int hlen, plen, proto, csum_offset; -uint16_t csum; +int ip_len; +struct ip_header *ip; + +/* +* Note: We cannot assume "data" is aligned, so the all code uses +* some macros that take care of possible unaligned access for +* struct members (just in case). +*/ /* Ensure data has complete L2 & L3 headers. */ -if (length <14 +20 ) { +if (length < (sizeof (struct eth_header ) +sizeof (struct ip_header ))) {return ; } -if ((data[14 ] &0xf0 ) !=0x40 ) -return ;/* not IPv4 */ - hlen = (data[14 ] &0x0f ) *4 ; - plen = (data[16 ] <<8 | data[17 ]) - hlen; - proto = data[23 ]; - -switch (proto) { -case PROTO_TCP : - csum_offset =16 ; -break ; -case PROTO_UDP : - csum_offset =6 ; -break ; -default : -return ; + ip = (struct ip_header *)(data +sizeof (struct eth_header )); + +if (IP_HEADER_VERSION (ip) !=IP_HEADER_VERSION_4 ) { +return ;/* not IPv4 */ } -if (plen < csum_offset +2 ||14 + hlen + plen > length) { + ip_len =lduw_be_p (&ip->ip_len); + +/* Last, check that we have enough data for the all IP frame */ +if (length < ip_len) {return ; } - data[14 +hlen+csum_offset] =0 ; - data[14 +hlen+csum_offset+1 ] =0 ; - csum =net_checksum_tcpudp (plen, proto, data+14 +12 , data+14 +hlen); - data[14 +hlen+csum_offset] = csum >>8 ; - data[14 +hlen+csum_offset+1 ] = csum &0xff ; + ip_len -=IP_HDR_GET_LEN (ip); + +switch (ip->ip_p) { +case IP_PROTO_TCP : + { +uint16_t csum; +tcp_header *tcp = (tcp_header *)(ip +1 ); + +if (ip_len <sizeof (tcp_header)) { +return ; + } + +/* Set csum to 0 */ +stw_he_p (&tcp->th_sum,0 ); + + csum =net_checksum_tcpudp (ip_len, ip->ip_p, + (uint8_t *)&ip->ip_src, + (uint8_t *)tcp); + +/* Store computed csum */ +stw_be_p (&tcp->th_sum, csum); + +break ; + } +case IP_PROTO_UDP : + { +uint16_t csum; +udp_header *udp = (udp_header *)(ip +1 ); + +if (ip_len <sizeof (udp_header)) { +return ; + } + +/* Set csum to 0 */ +stw_he_p (&udp->uh_sum,0 ); + + csum =net_checksum_tcpudp (ip_len, ip->ip_p, + (uint8_t *)&ip->ip_src, + (uint8_t *)udp); + +/* Store computed csum */ +stw_be_p (&udp->uh_sum, csum); + +break ; + } +default : +/* Can't handle any other protocol */ +break ; + } }uint32_t
Signature · 1 line
2.7.4
PATCH v4 3/8 i.MX: Fix FEC code for MDIO operation selection
In reply to Jean-Christophe DuboisAccording to the FEC chapter of i.MX25 reference manual
When writing the MMFR register, bit 29 and 28 select the requested operation.
* 10 means read operation with valid MII mgmt frame
* 11 means read operation with non compliant MII mgmt frame
* 01 means write operation with valid MII mgmt frame
* 00 means write operation with non compliant MII mgmt frame
So while bit 28 does change beween read/write for valid MII mgmt frame, the mening is inverted for non compliant MII mgmt frame.
Bit 29 on the other hand means read/write whatever the type of mgmt frame involved.
So this patch change the operation selection from bit 28 to bit 29 as it is more generic.
---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Not present on v3
hw/net/imx_fec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +3 -3
@@ -458,10 +458,10 @@ static void imx_fec_write(void *opaque, hwaddr addr,case 0x040 :/* MMFR */ /* store the value */ s->mmfr = value; -if (extract32 (value,28 ,1 )) { -do_phy_write (s,extract32 (value,18 ,9 ),extract32 (value,0 ,16 )); - }else { +if (extract32 (value,29 ,1 )) { s->mmfr =do_phy_read (s,extract32 (value,18 ,9 )); + }else { +do_phy_write (s,extract32 (value,18 ,9 ),extract32 (value,0 ,16 )); }/* raise the interrupt as the PHY operation is done */ s->eir |=FEC_INT_MII ;
Signature · 1 line
2.7.4
PATCH v4 4/8 i.MX: Fix FEC code for MDIO address selection
In reply to Jean-Christophe DuboisAccording to the FEC chapter of i.MX25 reference manual
When writing to MMFR register, the MDIO device and adress are selected by bit 27 to 23 and bit 22 to 18 respectively. This is a total of 10 bits that need to be used by the Phy chip/address decoding function.
This patch fixes the number of bits used from 9 to 10.
---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Not present on v3
hw/net/imx_fec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/net/imx_fec.c +2 -2
@@ -459,9 +459,9 @@ static void imx_fec_write(void *opaque, hwaddr addr,/* store the value */ s->mmfr = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,9 )); + s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); }else { -do_phy_write (s,extract32 (value,18 ,9 ),extract32 (value,0 ,16 )); +do_phy_write (s,extract32 (value,18 ,10 ),extract32 (value,0 ,16 )); }/* raise the interrupt as the PHY operation is done */ s->eir |=FEC_INT_MII ;
Signature · 1 line
2.7.4
PATCH v4 2/8 net: handle optional VLAN header in checksum computation.
In reply to Jean-Christophe Dubois---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* local variable name change.
net/checksum.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-)
net/checksum.c +31 -4
@@ -55,7 +55,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,void net_checksum_calculate (uint8_t *data,int length) { -int ip_len; +int mac_hdr_len, ip_len;struct ip_header *ip;/*
@@ -64,12 +64,39 @@ void net_checksum_calculate(uint8_t *data, int length)* struct members (just in case). */ -/* Ensure data has complete L2 & L3 headers. */ -if (length < (sizeof (struct eth_header ) +sizeof (struct ip_header ))) { +/* Ensure we have at least an Eth header */ +if (length <sizeof (struct eth_header )) {return ; } - ip = (struct ip_header *)(data +sizeof (struct eth_header )); +/* Handle the optionnal VLAN headers */ +switch (lduw_be_p (&PKT_GET_ETH_HDR (data)->h_proto)) { +case ETH_P_VLAN : + mac_hdr_len =sizeof (struct eth_header ) + +sizeof (struct vlan_header ); +break ; +case ETH_P_DVLAN : +if (lduw_be_p (&PKT_GET_VLAN_HDR (data)->h_proto) ==ETH_P_VLAN ) { + mac_hdr_len =sizeof (struct eth_header ) + +2 *sizeof (struct vlan_header ); + }else { + mac_hdr_len =sizeof (struct eth_header ) + +sizeof (struct vlan_header ); + } +break ; +default : + mac_hdr_len =sizeof (struct eth_header ); +break ; + } + + length -= mac_hdr_len; + +/* Now check we have an IP header (with an optionnal VLAN header) */ +if (length <sizeof (struct ip_header )) { +return ; + } + + ip = (struct ip_header *)(data + mac_hdr_len);if (IP_HEADER_VERSION (ip) !=IP_HEADER_VERSION_4 ) {return ;/* not IPv4 */
Signature · 1 line
2.7.4
PATCH v4 5/8 i.MX: Fix FEC code for ECR register reset value.
In reply to Jean-Christophe DuboisAccording to the FEC chapter of i.MX25 reference manual ECR register is initialized at 0xf0000000 at reset time.
We fix the value.
---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Not present on v3
hw/net/imx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +1 -1
@@ -338,7 +338,7 @@ static void imx_fec_reset(DeviceState *d) s->eir =0 ; s->eimr =0 ; s->rx_enabled =0 ; - s->ecr =0 ; + s->ecr =0xf0000000 ; s->mscr =0 ; s->mibc =0xc0000000 ; s->rcr =0x05ee0001 ;
Signature · 1 line
2.7.4
PATCH v4 6/8 i.MX: move FEC device to a register array structure.
In reply to Jean-Christophe DuboisThis is to prepare for the ENET Gb device of the i.MX6.
---
Changes since v1:
* Not present on v1.
Changes since v2:
* The patch was split in 2 parts:
- a "port" to a reg array based device (this patch).
- the addition of the Gb support (next patch).
Changes since v3:
* Small fix patches were extracted from this patch (see previous 3 patches)
* Reset logic through ECR was fixed.
* TDAR/RDAR behavior was fixed.
hw/net/imx_fec.c | 396 ++++++++++++++++++++++++++--------------------- include/hw/net/imx_fec.h | 55 ++++--- 2 files changed, 258 insertions(+), 193 deletions(-)
hw/net/imx_fec.c +222 -174
@@ -52,30 +52,75 @@ } \ }while (0 ) +static const char *imx_fec_reg_name(IMXFECState *s, uint32_t index) +{ +static char tmp[20 ]; + +switch (index) { +case ENET_EIR : +return "EIR" ; +case ENET_EIMR : +return "EIMR" ; +case ENET_RDAR : +return "RDAR" ; +case ENET_TDAR : +return "TDAR" ; +case ENET_ECR : +return "ECR" ; +case ENET_MMFR : +return "MMFR" ; +case ENET_MSCR : +return "MSCR" ; +case ENET_MIBC : +return "MIBC" ; +case ENET_RCR : +return "RCR" ; +case ENET_TCR : +return "TCR" ; +case ENET_PALR : +return "PALR" ; +case ENET_PAUR : +return "PAUR" ; +case ENET_OPD : +return "OPD" ; +case ENET_IAUR : +return "IAUR" ; +case ENET_IALR : +return "IALR" ; +case ENET_GAUR : +return "GAUR" ; +case ENET_GALR : +return "GALR" ; +case ENET_TFWR : +return "TFWR" ; +case ENET_RDSR : +return "RDSR" ; +case ENET_TDSR : +return "TDSR" ; +case ENET_MRBR : +return "MRBR" ; +case ENET_FRBR : +return "FRBR" ; +case ENET_FRSR : +return "FRSR" ; +case ENET_MIIGSK_CFGR : +return "MIIGSK_CFGR" ; +case ENET_MIIGSK_ENR : +return "MIIGSK_ENR" ; +default : +sprintf (tmp,"index %d" , index); +return tmp; + } +} +static const VMStateDescription vmstate_imx_fec = { .name =TYPE_IMX_FEC , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { -VMSTATE_UINT32 (irq_state, IMXFECState), -VMSTATE_UINT32 (eir, IMXFECState), -VMSTATE_UINT32 (eimr, IMXFECState), -VMSTATE_UINT32 (rx_enabled, IMXFECState), +VMSTATE_UINT32_ARRAY (regs, IMXFECState,ENET_MAX ),VMSTATE_UINT32 (rx_descriptor, IMXFECState),VMSTATE_UINT32 (tx_descriptor, IMXFECState), -VMSTATE_UINT32 (ecr, IMXFECState), -VMSTATE_UINT32 (mmfr, IMXFECState), -VMSTATE_UINT32 (mscr, IMXFECState), -VMSTATE_UINT32 (mibc, IMXFECState), -VMSTATE_UINT32 (rcr, IMXFECState), -VMSTATE_UINT32 (tcr, IMXFECState), -VMSTATE_UINT32 (tfwr, IMXFECState), -VMSTATE_UINT32 (frsr, IMXFECState), -VMSTATE_UINT32 (erdsr, IMXFECState), -VMSTATE_UINT32 (etdsr, IMXFECState), -VMSTATE_UINT32 (emrbr, IMXFECState), -VMSTATE_UINT32 (miigsk_cfgr, IMXFECState), -VMSTATE_UINT32 (miigsk_enr, IMXFECState),VMSTATE_UINT32 (phy_status, IMXFECState),VMSTATE_UINT32 (phy_control, IMXFECState),
@@ -251,15 +296,13 @@ static void imx_fec_write_bd(IMXFECBufDesc *bd, dma_addr_t addr)static void imx_fec_update (IMXFECState *s) { -uint32_t active; -uint32_t changed; - - active = s->eir & s->eimr; - changed = active ^ s->irq_state; -if (changed) { -qemu_set_irq (s->irq, active); +if (s->regs[ENET_EIR ] & s->regs[ENET_EIMR ]) { +FEC_PRINTF ("interrupt raised\n" ); +qemu_set_irq (s->irq,1 ); + }else { +FEC_PRINTF ("interrupt lowered\n" ); +qemu_set_irq (s->irq,0 ); } - s->irq_state = active; }static void imx_fec_do_tx (IMXFECState *s)
@@ -283,7 +326,7 @@ static void imx_fec_do_tx(IMXFECState *s) len = bd.length;if (frame_size + len >FEC_MAX_FRAME_SIZE ) { len =FEC_MAX_FRAME_SIZE - frame_size; - s->eir |=FEC_INT_BABT ; + s->regs[ENET_EIR ] |=FEC_INT_BABT ; }dma_memory_read (&address_space_memory, bd.data, ptr, len); ptr += len;
@@ -293,17 +336,17 @@ static void imx_fec_do_tx(IMXFECState *s)qemu_send_packet (qemu_get_queue (s->nic), frame, len); ptr = frame; frame_size =0 ; - s->eir |=FEC_INT_TXF ; + s->regs[ENET_EIR ] |=FEC_INT_TXF ; } - s->eir |=FEC_INT_TXB ; + s->regs[ENET_EIR ] |=FEC_INT_TXB ; bd.flags &= ~FEC_BD_R ;/* Write back the modified descriptor. */ imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->etdsr; + addr = s->regs[ENET_TDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } }
@@ -315,7 +358,7 @@ static void imx_fec_do_tx(IMXFECState *s)static void imx_fec_enable_rx (IMXFECState *s) {IMXFECBufDesc bd; -uint32_t tmp; +bool tmp;imx_fec_read_bd (&bd, s->rx_descriptor);
@@ -323,11 +366,11 @@ static void imx_fec_enable_rx(IMXFECState *s)if (!tmp) {FEC_PRINTF ("RX buffer full\n" ); - }else if (!s->rx_enabled) { + }else if (!s->regs[ENET_RDAR ]) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); } - s->rx_enabled = tmp; + s->regs[ENET_RDAR ] = tmp ?ENET_RDAR_RDAR :0 ; }static void imx_fec_reset (DeviceState *d)
@@ -335,18 +378,26 @@ static void imx_fec_reset(DeviceState *d)IMXFECState *s =IMX_FEC (d);/* Reset the FEC */ - s->eir =0 ; - s->eimr =0 ; - s->rx_enabled =0 ; - s->ecr =0xf0000000 ; - s->mscr =0 ; - s->mibc =0xc0000000 ; - s->rcr =0x05ee0001 ; - s->tcr =0 ; - s->tfwr =0 ; - s->frsr =0x500 ; - s->miigsk_cfgr =0 ; - s->miigsk_enr =0x6 ; +memset (s->regs,0 ,sizeof (s->regs)); + s->regs[ENET_ECR ] =0xf0000000 ; + s->regs[ENET_MIBC ] =0xc0000000 ; + s->regs[ENET_RCR ] =0x05ee0001 ; + s->regs[ENET_OPD ] =0x00010000 ; + + s->regs[ENET_PALR ] = (s->conf.macaddr.a[0 ] <<24 ) + | (s->conf.macaddr.a[1 ] <<16 ) + | (s->conf.macaddr.a[2 ] <<8 ) + | s->conf.macaddr.a[3 ]; + s->regs[ENET_PAUR ] = (s->conf.macaddr.a[4 ] <<24 ) + | (s->conf.macaddr.a[5 ] <<16 ) + |0x8808 ; + + s->regs[ENET_FRBR ] =0x00000600 ; + s->regs[ENET_FRSR ] =0x00000500 ; + s->regs[ENET_MIIGSK_ENR ] =0x00000006 ; + + s->rx_descriptor =0 ; + s->tx_descriptor =0 ;/* We also reset the PHY */ phy_reset (s);
@@ -354,183 +405,180 @@ static void imx_fec_reset(DeviceState *d)static uint64_t imx_fec_read (void *opaque,hwaddr addr,unsigned size) { +uint32_t value =0 ;IMXFECState *s =IMX_FEC (opaque); - -FEC_PRINTF ("reading from @ 0x%" HWADDR_PRIx"\n" , addr); - -switch (addr &0x3ff ) { -case 0x004 : -return s->eir; -case 0x008 : -return s->eimr; -case 0x010 : -return s->rx_enabled ? (1 <<24 ) :0 ;/* RDAR */ -case 0x014 : -return 0 ;/* TDAR */ -case 0x024 : -return s->ecr; -case 0x040 : -return s->mmfr; -case 0x044 : -return s->mscr; -case 0x064 : -return s->mibc;/* MIBC */ -case 0x084 : -return s->rcr; -case 0x0c4 : -return s->tcr; -case 0x0e4 :/* PALR */ -return (s->conf.macaddr.a[0 ] <<24 ) - | (s->conf.macaddr.a[1 ] <<16 ) - | (s->conf.macaddr.a[2 ] <<8 ) - | s->conf.macaddr.a[3 ]; -break ; -case 0x0e8 :/* PAUR */ -return (s->conf.macaddr.a[4 ] <<24 ) - | (s->conf.macaddr.a[5 ] <<16 ) - |0x8808 ; -case 0x0ec : -return 0x10000 ;/* OPD */ -case 0x118 : -return 0 ; -case 0x11c : -return 0 ; -case 0x120 : -return 0 ; -case 0x124 : -return 0 ; -case 0x144 : -return s->tfwr; -case 0x14c : -return 0x600 ; -case 0x150 : -return s->frsr; -case 0x180 : -return s->erdsr; -case 0x184 : -return s->etdsr; -case 0x188 : -return s->emrbr; -case 0x300 : -return s->miigsk_cfgr; -case 0x308 : -return s->miigsk_enr; +uint32_t index = addr >>2 ; + +switch (index) { +case ENET_EIR : +case ENET_EIMR : +case ENET_RDAR : +case ENET_TDAR : +case ENET_ECR : +case ENET_MMFR : +case ENET_MSCR : +case ENET_MIBC : +case ENET_RCR : +case ENET_TCR : +case ENET_PALR : +case ENET_PAUR : +case ENET_OPD : +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR : +case ENET_TFWR : +case ENET_RDSR : +case ENET_TDSR : +case ENET_MRBR : +case ENET_FRBR : +case ENET_FRSR : +case ENET_MIIGSK_CFGR : +case ENET_MIIGSK_ENR : + value = s->regs[index]; +break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad address at offset 0x%" - HWADDR_PRIx"\n" ,TYPE_IMX_FEC , __func__, addr); -return 0 ; +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad register at offset 0x%" + PRIx32"\n" ,TYPE_IMX_FEC , __func__, index *4 ); +break ; } + +FEC_PRINTF ("reg[%s] => 0x%" PRIx32"\n" ,imx_fec_reg_name (s, index), + value); + +return value; }static void imx_fec_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) {IMXFECState *s =IMX_FEC (opaque); +uint32_t index = addr >>2 ; -FEC_PRINTF ("writing 0x%08x @ 0x%" HWADDR_PRIx"\n" , (int )value, addr); +FEC_PRINTF ("reg[%s] <= 0x%" PRIx32"\n" ,imx_fec_reg_name (s, index), + (uint32_t )value); -switch (addr &0x3ff ) { -case 0x004 :/* EIR */ - s->eir &= ~value; +switch (index) { +case ENET_EIR : + s->regs[index] &= ~value;break ; -case 0x008 :/* EIMR */ - s->eimr = value; +case ENET_EIMR : + s->regs[index] = value;break ; -case 0x010 :/* RDAR */ -if ((s->ecr &FEC_EN ) && !s->rx_enabled) { -imx_fec_enable_rx (s); +case ENET_RDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { +if (!s->regs[index]) { + s->regs[index] =ENET_RDAR_RDAR ; +imx_fec_enable_rx (s); + } + }else { + s->regs[index] =0 ; }break ; -case 0x014 :/* TDAR */ -if (s->ecr &FEC_EN ) { +case ENET_TDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { + s->regs[index] =ENET_TDAR_TDAR ;imx_fec_do_tx (s); } + s->regs[index] =0 ;break ; -case 0x024 :/* ECR */ - s->ecr = value; +case ENET_ECR :if (value &FEC_RESET ) { -imx_fec_reset (DEVICE (s)); +return imx_fec_reset (DEVICE (s)); } -if ((s->ecr &FEC_EN ) ==0 ) { - s->rx_enabled =0 ; + s->regs[index] = value; +if ((s->regs[index] &FEC_EN ) ==0 ) { + s->regs[ENET_RDAR ] =0 ; + s->rx_descriptor = s->regs[ENET_RDSR ]; + s->regs[ENET_TDAR ] =0 ; + s->tx_descriptor = s->regs[ENET_TDSR ]; }break ; -case 0x040 :/* MMFR */ -/* store the value */ - s->mmfr = value; +case ENET_MMFR : + s->regs[index] = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); +/* This is a read operation */ + s->regs[ENET_MMFR ] =deposit32 (s->regs[ENET_MMFR ],0 ,16 , +do_phy_read (s, +extract32 (value, +18 ,10 ))); }else { +/* This a write operation */ do_phy_write (s,extract32 (value,18 ,10 ),extract32 (value,0 ,16 )); }/* raise the interrupt as the PHY operation is done */ - s->eir |=FEC_INT_MII ; + s->regs[ENET_EIR ] |=FEC_INT_MII ;break ; -case 0x044 :/* MSCR */ - s->mscr = value &0xfe ; +case ENET_MSCR : + s->regs[index] = value &0xfe ;break ; -case 0x064 :/* MIBC */ +case ENET_MIBC :/* TODO: Implement MIB. */ - s->mibc = (value &0x80000000 ) ?0xc0000000 :0 ; + s->regs[index] = (value &0x80000000 ) ?0xc0000000 :0 ;break ; -case 0x084 :/* RCR */ - s->rcr = value &0x07ff003f ; +case ENET_RCR : + s->regs[index] = value &0x07ff003f ;/* TODO: Implement LOOP mode. */ break ; -case 0x0c4 :/* TCR */ +case ENET_TCR :/* We transmit immediately, so raise GRA immediately. */ - s->tcr = value; + s->regs[index] = value;if (value &1 ) { - s->eir |=FEC_INT_GRA ; + s->regs[ENET_EIR ] |=FEC_INT_GRA ; }break ; -case 0x0e4 :/* PALR */ +case ENET_PALR : + s->regs[index] = value; s->conf.macaddr.a[0 ] = value >>24 ; s->conf.macaddr.a[1 ] = value >>16 ; s->conf.macaddr.a[2 ] = value >>8 ; s->conf.macaddr.a[3 ] = value;break ; -case 0x0e8 :/* PAUR */ +case ENET_PAUR : + s->regs[index] = (value |0x0000ffff ) &0xffff8808 ; s->conf.macaddr.a[4 ] = value >>24 ; s->conf.macaddr.a[5 ] = value >>16 ;break ; -case 0x0ec :/* OPDR */ +case ENET_OPD : + s->regs[index] = (value &0x0000ffff ) |0x00010000 ;break ; -case 0x118 :/* IAUR */ -case 0x11c :/* IALR */ -case 0x120 :/* GAUR */ -case 0x124 :/* GALR */ +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR :/* TODO: implement MAC hash filtering. */ break ; -case 0x144 :/* TFWR */ - s->tfwr = value &3 ; +case ENET_TFWR : + s->regs[index] = value &3 ;break ; -case 0x14c :/* FRBR */ -/* FRBR writes ignored. */ +case ENET_FRBR : +/* FRBR is read only */ +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Register FRBR is read only\n" , +TYPE_IMX_FEC , __func__);break ; -case 0x150 :/* FRSR */ - s->frsr = (value &0x3fc ) |0x400 ; +case ENET_FRSR : + s->regs[index] = (value &0x000003fc ) |0x00000400 ;break ; -case 0x180 :/* ERDSR */ - s->erdsr = value & ~3 ; - s->rx_descriptor = s->erdsr; +case ENET_RDSR : + s->regs[index] = value & ~3 ; + s->rx_descriptor = s->regs[index];break ; -case 0x184 :/* ETDSR */ - s->etdsr = value & ~3 ; - s->tx_descriptor = s->etdsr; +case ENET_TDSR : + s->regs[index] = value & ~3 ; + s->tx_descriptor = s->regs[index];break ; -case 0x188 :/* EMRBR */ - s->emrbr = value &0x7f0 ; +case ENET_MRBR : + s->regs[index] = value &0x000007f0 ;break ; -case 0x300 :/* MIIGSK_CFGR */ - s->miigsk_cfgr = value &0x53 ; +case ENET_MIIGSK_CFGR : + s->regs[index] = value &0x00000053 ;break ; -case 0x308 :/* MIIGSK_ENR */ - s->miigsk_enr = (value &0x2 ) ?0x6 :0 ; +case ENET_MIIGSK_ENR : + s->regs[index] = (value &0x00000002 ) ?0x00000006 :0 ;break ;default :qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad address at offset 0x%" - HWADDR_PRIx"\n" ,TYPE_IMX_FEC , __func__, addr); + PRIx32"\n" ,TYPE_IMX_FEC , __func__, index *4 );break ; }
@@ -541,7 +589,7 @@ static int imx_fec_can_receive(NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc)); -return s->rx_enabled; +return s->regs[ENET_RDAR ] ?1 :0 ; } static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,
@@ -559,7 +607,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,FEC_PRINTF ("len %d\n" , (int )size); -if (!s->rx_enabled) { +if (!s->regs[ENET_RDAR ]) {qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Unexpected packet\n" ,TYPE_IMX_FEC , __func__);return 0 ;
@@ -577,7 +625,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, }/* Frames larger than the user limit just set error flags. */ -if (size > (s->rcr >>16 )) { +if (size > (s->regs[ENET_RCR ] >>16 )) { flags |=FEC_BD_LG ; }
@@ -595,7 +643,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, TYPE_IMX_FEC, __func__);break ; } - buf_len = (size <= s->emrbr) ? size : s->emrbr; + buf_len = (size <= s->regs[ENET_MRBR ]) ? size : s->regs[ENET_MRBR ]; bd.length = buf_len; size -= buf_len;
@@ -618,16 +666,16 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,/* Last buffer in frame. */ bd.flags |= flags |FEC_BD_L ;FEC_PRINTF ("rx frame flags %04x\n" , bd.flags); - s->eir |=FEC_INT_RXF ; + s->regs[ENET_EIR ] |=FEC_INT_RXF ; }else { - s->eir |=FEC_INT_RXB ; + s->regs[ENET_EIR ] |=FEC_INT_RXB ; }imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->erdsr; + addr = s->regs[ENET_RDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } } s->rx_descriptor = addr;
include/hw/net/imx_fec.h +36 -19
75 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 8/8 Add ENET device to i.MX6 SOC.
In reply to Jean-Christophe DuboisThis adds the ENET device to the i.MX6 SOC.
This was tested by booting Linux on an Qemu i.MX6 instance and accessing the internet from the linux guest.
---
Changes since v1:
* Not present on v1
Changes since v2:
* None
Changes since v3:
* switch the 2 Eth interrupt numbers.
hw/arm/fsl-imx6.c | 17 +++++++++++++++++ include/hw/arm/fsl-imx6.h | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
hw/arm/fsl-imx6.c +17 -0
@@ -105,6 +105,10 @@ static void fsl_imx6_init(Object *obj)snprintf (name,NAME_SIZE ,"spi%d" , i +1 );object_property_add_child (obj, name,OBJECT (&s->spi[i]),NULL ); } + +object_initialize (&s->eth,sizeof (s->eth),TYPE_IMX_FEC ); +qdev_set_parent_bus (DEVICE (&s->eth),sysbus_get_default ()); +object_property_add_child (obj,"eth" ,OBJECT (&s->eth),NULL ); }static void fsl_imx6_realize (DeviceState *dev,Error **errp)
@@ -381,6 +385,19 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) spi_table[i].irq)); } +object_property_set_bool (OBJECT (&s->eth), true,"realized" , &err); +if (err) { +error_propagate (errp, err); +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->eth),0 ,FSL_IMX6_ENET_ADDR ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->eth),0 , +qdev_get_gpio_in (DEVICE (&s->a9mpcore), +FSL_IMX6_ENET_MAC_IRQ )); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->eth),1 , +qdev_get_gpio_in (DEVICE (&s->a9mpcore), +FSL_IMX6_ENET_MAC_1588_IRQ )); +/* ROM memory */ memory_region_init_rom_device (&s->rom,NULL ,NULL ,NULL ,"imx6.rom" ,FSL_IMX6_ROM_SIZE , &err);
include/hw/arm/fsl-imx6.h +4 -2
@@ -28,6 +28,7 @@#include "hw/gpio/imx_gpio.h" #include "hw/sd/sdhci.h" #include "hw/ssi/imx_spi.h" +#include "hw/net/imx_fec.h" #include "exec/memory.h" #define TYPE_FSL_IMX6 "fsl,imx6"
@@ -57,6 +58,7 @@ typedef struct FslIMX6State {IMXGPIOState gpio[FSL_IMX6_NUM_GPIOS ];SDHCIState esdhc[FSL_IMX6_NUM_ESDHCS ];IMXSPIState spi[FSL_IMX6_NUM_ECSPIS ]; +IMXFECState eth;MemoryRegion rom;MemoryRegion caam;MemoryRegion ocram;
@@ -435,8 +437,8 @@ typedef struct FslIMX6State {#define FSL_IMX6_HDMI_MASTER_IRQ 115#define FSL_IMX6_HDMI_CEC_IRQ 116#define FSL_IMX6_MLB150_LOW_IRQ 117 -#define FSL_IMX6_ENET_MAC_IRQ 118 -#define FSL_IMX6_ENET_MAC_1588_IRQ 119 +#define FSL_IMX6_ENET_MAC_1588_IRQ 118 +#define FSL_IMX6_ENET_MAC_IRQ 119#define FSL_IMX6_PCIE1_IRQ 120#define FSL_IMX6_PCIE2_IRQ 121#define FSL_IMX6_PCIE3_IRQ 122
Signature · 1 line
2.7.4
PATCH v4 7/8 Add ENET/Gbps Ethernet support to FEC device
In reply to Jean-Christophe DuboisThe ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interrupts
hw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)
hw/arm/fsl-imx25.c +3 -0
@@ -191,6 +191,9 @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp) }qdev_set_nic_properties (DEVICE (&s->fec), &nd_table[0 ]); + +object_property_set_bool (OBJECT (&s->fec), true,"is-fec" , &error_abort); +object_property_set_bool (OBJECT (&s->fec), true,"realized" , &err);if (err) {error_propagate (errp, err);
hw/net/imx_fec.c +582 -131
981 lines not on this page · raw message
include/hw/net/imx_fec.h +160 -35
233 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH v4 6/8] i.MX: move FEC device to a register array structure.
In reply to Jean-Christophe DuboisQuoted 396 lines · Jean-Christophe Dubois
This is to prepare for the ENET Gb device of the i.MX6.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1.Changes since v2:
* The patch was split in 2 parts:
- a "port" to a reg array based device (this patch).
- the addition of the Gb support (next patch).Changes since v3:
* Small fix patches were extracted from this patch (see previous 3 patches)
* Reset logic through ECR was fixed.
* TDAR/RDAR behavior was fixed.hw/net/imx_fec.c | 396 ++++++++++++++++++++++++++--------------------- include/hw/net/imx_fec.h | 55 ++++--- 2 files changed, 258 insertions(+), 193 deletions(-)hw/net/imx_fec.c +158
-124@@ -52,30 +52,75 @@ } \ }while (0 ) +static const char *imx_fec_reg_name(IMXFECState *s, uint32_t index) +{ +static char tmp[20 ]; + +switch (index) { +case ENET_EIR : +return "EIR" ; +case ENET_EIMR : +return "EIMR" ; +case ENET_RDAR : +return "RDAR" ; +case ENET_TDAR : +return "TDAR" ; +case ENET_ECR : +return "ECR" ; +case ENET_MMFR : +return "MMFR" ; +case ENET_MSCR : +return "MSCR" ; +case ENET_MIBC : +return "MIBC" ; +case ENET_RCR : +return "RCR" ; +case ENET_TCR : +return "TCR" ; +case ENET_PALR : +return "PALR" ; +case ENET_PAUR : +return "PAUR" ; +case ENET_OPD : +return "OPD" ; +case ENET_IAUR : +return "IAUR" ; +case ENET_IALR : +return "IALR" ; +case ENET_GAUR : +return "GAUR" ; +case ENET_GALR : +return "GALR" ; +case ENET_TFWR : +return "TFWR" ; +case ENET_RDSR : +return "RDSR" ; +case ENET_TDSR : +return "TDSR" ; +case ENET_MRBR : +return "MRBR" ; +case ENET_FRBR : +return "FRBR" ; +case ENET_FRSR : +return "FRSR" ; +case ENET_MIIGSK_CFGR : +return "MIIGSK_CFGR" ; +case ENET_MIIGSK_ENR : +return "MIIGSK_ENR" ; +default : +sprintf (tmp,"index %d" , index); +return tmp; + } +} +static const VMStateDescription vmstate_imx_fec = { .name =TYPE_IMX_FEC , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { -VMSTATE_UINT32 (irq_state, IMXFECState), -VMSTATE_UINT32 (eir, IMXFECState), -VMSTATE_UINT32 (eimr, IMXFECState), -VMSTATE_UINT32 (rx_enabled, IMXFECState), +VMSTATE_UINT32_ARRAY (regs, IMXFECState,ENET_MAX ),VMSTATE_UINT32 (rx_descriptor, IMXFECState),VMSTATE_UINT32 (tx_descriptor, IMXFECState), -VMSTATE_UINT32 (ecr, IMXFECState), -VMSTATE_UINT32 (mmfr, IMXFECState), -VMSTATE_UINT32 (mscr, IMXFECState), -VMSTATE_UINT32 (mibc, IMXFECState), -VMSTATE_UINT32 (rcr, IMXFECState), -VMSTATE_UINT32 (tcr, IMXFECState), -VMSTATE_UINT32 (tfwr, IMXFECState), -VMSTATE_UINT32 (frsr, IMXFECState), -VMSTATE_UINT32 (erdsr, IMXFECState), -VMSTATE_UINT32 (etdsr, IMXFECState), -VMSTATE_UINT32 (emrbr, IMXFECState), -VMSTATE_UINT32 (miigsk_cfgr, IMXFECState), -VMSTATE_UINT32 (miigsk_enr, IMXFECState),VMSTATE_UINT32 (phy_status, IMXFECState),VMSTATE_UINT32 (phy_control, IMXFECState),@@ -251,15 +296,13 @@ static void imx_fec_write_bd(IMXFECBufDesc *bd, dma_addr_t addr)static void imx_fec_update (IMXFECState *s) { -uint32_t active; -uint32_t changed; - - active = s->eir & s->eimr; - changed = active ^ s->irq_state; -if (changed) { -qemu_set_irq (s->irq, active); +if (s->regs[ENET_EIR ] & s->regs[ENET_EIMR ]) { +FEC_PRINTF ("interrupt raised\n" ); +qemu_set_irq (s->irq,1 ); + }else { +FEC_PRINTF ("interrupt lowered\n" ); +qemu_set_irq (s->irq,0 ); } - s->irq_state = active; }static void imx_fec_do_tx (IMXFECState *s)@@ -283,7 +326,7 @@ static void imx_fec_do_tx(IMXFECState *s) len = bd.length;if (frame_size + len >FEC_MAX_FRAME_SIZE ) { len =FEC_MAX_FRAME_SIZE - frame_size; - s->eir |=FEC_INT_BABT ; + s->regs[ENET_EIR ] |=FEC_INT_BABT ; }dma_memory_read (&address_space_memory, bd.data, ptr, len); ptr += len;@@ -293,17 +336,17 @@ static void imx_fec_do_tx(IMXFECState *s)qemu_send_packet (qemu_get_queue (s->nic), frame, len); ptr = frame; frame_size =0 ; - s->eir |=FEC_INT_TXF ; + s->regs[ENET_EIR ] |=FEC_INT_TXF ; } - s->eir |=FEC_INT_TXB ; + s->regs[ENET_EIR ] |=FEC_INT_TXB ; bd.flags &= ~FEC_BD_R ;/* Write back the modified descriptor. */ imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->etdsr; + addr = s->regs[ENET_TDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } }@@ -315,7 +358,7 @@ static void imx_fec_do_tx(IMXFECState *s)static void imx_fec_enable_rx (IMXFECState *s) {IMXFECBufDesc bd; -uint32_t tmp; +bool tmp;imx_fec_read_bd (&bd, s->rx_descriptor);@@ -323,11 +366,11 @@ static void imx_fec_enable_rx(IMXFECState *s)if (!tmp) {FEC_PRINTF ("RX buffer full\n" ); - }else if (!s->rx_enabled) { + }else if (!s->regs[ENET_RDAR ]) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); } - s->rx_enabled = tmp; + s->regs[ENET_RDAR ] = tmp ?ENET_RDAR_RDAR :0 ; }static void imx_fec_reset (DeviceState *d)@@ -335,18 +378,26 @@ static void imx_fec_reset(DeviceState *d)IMXFECState *s =IMX_FEC (d);/* Reset the FEC */ - s->eir =0 ; - s->eimr =0 ; - s->rx_enabled =0 ; - s->ecr =0xf0000000 ; - s->mscr =0 ; - s->mibc =0xc0000000 ; - s->rcr =0x05ee0001 ; - s->tcr =0 ; - s->tfwr =0 ; - s->frsr =0x500 ; - s->miigsk_cfgr =0 ; - s->miigsk_enr =0x6 ; +memset (s->regs,0 ,sizeof (s->regs)); + s->regs[ENET_ECR ] =0xf0000000 ; + s->regs[ENET_MIBC ] =0xc0000000 ; + s->regs[ENET_RCR ] =0x05ee0001 ; + s->regs[ENET_OPD ] =0x00010000 ; + + s->regs[ENET_PALR ] = (s->conf.macaddr.a[0 ] <<24 ) + | (s->conf.macaddr.a[1 ] <<16 ) + | (s->conf.macaddr.a[2 ] <<8 ) + | s->conf.macaddr.a[3 ]; + s->regs[ENET_PAUR ] = (s->conf.macaddr.a[4 ] <<24 ) + | (s->conf.macaddr.a[5 ] <<16 ) + |0x8808 ; + + s->regs[ENET_FRBR ] =0x00000600 ; + s->regs[ENET_FRSR ] =0x00000500 ; + s->regs[ENET_MIIGSK_ENR ] =0x00000006 ; + + s->rx_descriptor =0 ; + s->tx_descriptor =0 ;/* We also reset the PHY */ phy_reset (s);@@ -354,183 +405,180 @@ static void imx_fec_reset(DeviceState *d)static uint64_t imx_fec_read (void *opaque,hwaddr addr,unsigned size) { +uint32_t value =0 ;IMXFECState *s =IMX_FEC (opaque); - -FEC_PRINTF ("reading from @ 0x%" HWADDR_PRIx"\n" , addr); - -switch (addr &0x3ff ) { -case 0x004 : -return s->eir; -case 0x008 : -return s->eimr; -case 0x010 : -return s->rx_enabled ? (1 <<24 ) :0 ;/* RDAR */ -case 0x014 : -return 0 ;/* TDAR */ -case 0x024 : -return s->ecr; -case 0x040 : -return s->mmfr; -case 0x044 : -return s->mscr; -case 0x064 : -return s->mibc;/* MIBC */ -case 0x084 : -return s->rcr; -case 0x0c4 : -return s->tcr; -case 0x0e4 :/* PALR */ -return (s->conf.macaddr.a[0 ] <<24 ) - | (s->conf.macaddr.a[1 ] <<16 ) - | (s->conf.macaddr.a[2 ] <<8 ) - | s->conf.macaddr.a[3 ]; -break ; -case 0x0e8 :/* PAUR */ -return (s->conf.macaddr.a[4 ] <<24 ) - | (s->conf.macaddr.a[5 ] <<16 ) - |0x8808 ; -case 0x0ec : -return 0x10000 ;/* OPD */ -case 0x118 : -return 0 ; -case 0x11c : -return 0 ; -case 0x120 : -return 0 ; -case 0x124 : -return 0 ; -case 0x144 : -return s->tfwr; -case 0x14c : -return 0x600 ; -case 0x150 : -return s->frsr; -case 0x180 : -return s->erdsr; -case 0x184 : -return s->etdsr; -case 0x188 : -return s->emrbr; -case 0x300 : -return s->miigsk_cfgr; -case 0x308 : -return s->miigsk_enr; +uint32_t index = addr >>2 ; + +switch (index) { +case ENET_EIR : +case ENET_EIMR : +case ENET_RDAR : +case ENET_TDAR : +case ENET_ECR : +case ENET_MMFR : +case ENET_MSCR : +case ENET_MIBC : +case ENET_RCR : +case ENET_TCR : +case ENET_PALR : +case ENET_PAUR : +case ENET_OPD : +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR : +case ENET_TFWR : +case ENET_RDSR : +case ENET_TDSR : +case ENET_MRBR : +case ENET_FRBR : +case ENET_FRSR : +case ENET_MIIGSK_CFGR : +case ENET_MIIGSK_ENR : + value = s->regs[index]; +break ;default : -qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad address at offset 0x%" - HWADDR_PRIx"\n" ,TYPE_IMX_FEC , __func__, addr); -return 0 ; +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad register at offset 0x%" + PRIx32"\n" ,TYPE_IMX_FEC , __func__, index *4 ); +break ; } + +FEC_PRINTF ("reg[%s] => 0x%" PRIx32"\n" ,imx_fec_reg_name (s, index), + value); + +return value; }static void imx_fec_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) {IMXFECState *s =IMX_FEC (opaque); +uint32_t index = addr >>2 ; -FEC_PRINTF ("writing 0x%08x @ 0x%" HWADDR_PRIx"\n" , (int )value, addr); +FEC_PRINTF ("reg[%s] <= 0x%" PRIx32"\n" ,imx_fec_reg_name (s, index), + (uint32_t )value); -switch (addr &0x3ff ) { -case 0x004 :/* EIR */ - s->eir &= ~value; +switch (index) { +case ENET_EIR : + s->regs[index] &= ~value;break ; -case 0x008 :/* EIMR */ - s->eimr = value; +case ENET_EIMR : + s->regs[index] = value;break ; -case 0x010 :/* RDAR */ -if ((s->ecr &FEC_EN ) && !s->rx_enabled) { -imx_fec_enable_rx (s); +case ENET_RDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { +if (!s->regs[index]) { + s->regs[index] =ENET_RDAR_RDAR ; +imx_fec_enable_rx (s); + } + }else { + s->regs[index] =0 ; }break ; -case 0x014 :/* TDAR */ -if (s->ecr &FEC_EN ) { +case ENET_TDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { + s->regs[index] =ENET_TDAR_TDAR ;imx_fec_do_tx (s); } + s->regs[index] =0 ;break ; -case 0x024 :/* ECR */ - s->ecr = value; +case ENET_ECR :if (value &FEC_RESET ) { -imx_fec_reset (DEVICE (s));
hw/net/imx_fec.c static void imx_fec_reset(DeviceState *d) · line 494
Quoted 10 lines
hw/net/imx_fec.c +7
-2+return imx_fec_reset (DEVICE (s)); } -if ((s->ecr &FEC_EN ) ==0 ) { - s->rx_enabled =0 ; + s->regs[index] = value; +if ((s->regs[index] &FEC_EN ) ==0 ) { + s->regs[ENET_RDAR ] =0 ; + s->rx_descriptor = s->regs[ENET_RDSR ]; + s->regs[ENET_TDAR ] =0 ; + s->tx_descriptor = s->regs[ENET_TDSR ];
This seems like a new behavior, is this a bug fix? If yes, better split.
Quoted 46 lines
hw/net/imx_fec.c +17
-14}break ; -case 0x040 :/* MMFR */ -/* store the value */ - s->mmfr = value; +case ENET_MMFR : + s->regs[index] = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); +/* This is a read operation */ + s->regs[ENET_MMFR ] =deposit32 (s->regs[ENET_MMFR ],0 ,16 , +do_phy_read (s, +extract32 (value, +18 ,10 ))); }else { +/* This a write operation */ do_phy_write (s,extract32 (value,18 ,10 ),extract32 (value,0 ,16 )); }/* raise the interrupt as the PHY operation is done */ - s->eir |=FEC_INT_MII ; + s->regs[ENET_EIR ] |=FEC_INT_MII ;break ; -case 0x044 :/* MSCR */ - s->mscr = value &0xfe ; +case ENET_MSCR : + s->regs[index] = value &0xfe ;break ; -case 0x064 :/* MIBC */ +case ENET_MIBC :/* TODO: Implement MIB. */ - s->mibc = (value &0x80000000 ) ?0xc0000000 :0 ; + s->regs[index] = (value &0x80000000 ) ?0xc0000000 :0 ;break ; -case 0x084 :/* RCR */ - s->rcr = value &0x07ff003f ; +case ENET_RCR : + s->regs[index] = value &0x07ff003f ;/* TODO: Implement LOOP mode. */ break ; -case 0x0c4 :/* TCR */ +case ENET_TCR :/* We transmit immediately, so raise GRA immediately. */ - s->tcr = value; + s->regs[index] = value;if (value &1 ) { - s->eir |=FEC_INT_GRA ;
hw/net/imx_fec.c static void imx_fec_reset(DeviceState *d) · line 535
Quoted 10 lines
hw/net/imx_fec.c +3
-1+ s->regs[ENET_EIR ] |=FEC_INT_GRA ; }break ; -case 0x0e4 :/* PALR */ +case ENET_PALR : + s->regs[index] = value; s->conf.macaddr.a[0 ] = value >>24 ; s->conf.macaddr.a[1 ] = value >>16 ; s->conf.macaddr.a[2 ] = value >>8 ; s->conf.macaddr.a[3 ] = value;
I believe we should use stl_be_p() here?
Quoted 155 lines
hw/net/imx_fec.c +37
-33break ; -case 0x0e8 :/* PAUR */ +case ENET_PAUR : + s->regs[index] = (value |0x0000ffff ) &0xffff8808 ; s->conf.macaddr.a[4 ] = value >>24 ; s->conf.macaddr.a[5 ] = value >>16 ;break ; -case 0x0ec :/* OPDR */ +case ENET_OPD : + s->regs[index] = (value &0x0000ffff ) |0x00010000 ;break ; -case 0x118 :/* IAUR */ -case 0x11c :/* IALR */ -case 0x120 :/* GAUR */ -case 0x124 :/* GALR */ +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR :/* TODO: implement MAC hash filtering. */ break ; -case 0x144 :/* TFWR */ - s->tfwr = value &3 ; +case ENET_TFWR : + s->regs[index] = value &3 ;break ; -case 0x14c :/* FRBR */ -/* FRBR writes ignored. */ +case ENET_FRBR : +/* FRBR is read only */ +qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Register FRBR is read only\n" , +TYPE_IMX_FEC , __func__);break ; -case 0x150 :/* FRSR */ - s->frsr = (value &0x3fc ) |0x400 ; +case ENET_FRSR : + s->regs[index] = (value &0x000003fc ) |0x00000400 ;break ; -case 0x180 :/* ERDSR */ - s->erdsr = value & ~3 ; - s->rx_descriptor = s->erdsr; +case ENET_RDSR : + s->regs[index] = value & ~3 ; + s->rx_descriptor = s->regs[index];break ; -case 0x184 :/* ETDSR */ - s->etdsr = value & ~3 ; - s->tx_descriptor = s->etdsr; +case ENET_TDSR : + s->regs[index] = value & ~3 ; + s->tx_descriptor = s->regs[index];break ; -case 0x188 :/* EMRBR */ - s->emrbr = value &0x7f0 ; +case ENET_MRBR : + s->regs[index] = value &0x000007f0 ;break ; -case 0x300 :/* MIIGSK_CFGR */ - s->miigsk_cfgr = value &0x53 ; +case ENET_MIIGSK_CFGR : + s->regs[index] = value &0x00000053 ;break ; -case 0x308 :/* MIIGSK_ENR */ - s->miigsk_enr = (value &0x2 ) ?0x6 :0 ; +case ENET_MIIGSK_ENR : + s->regs[index] = (value &0x00000002 ) ?0x00000006 :0 ;break ;default :qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Bad address at offset 0x%" - HWADDR_PRIx"\n" ,TYPE_IMX_FEC , __func__, addr); + PRIx32"\n" ,TYPE_IMX_FEC , __func__, index *4 );break ; }@@ -541,7 +589,7 @@ static int imx_fec_can_receive(NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc)); -return s->rx_enabled; +return s->regs[ENET_RDAR ] ?1 :0 ; } static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,@@ -559,7 +607,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,FEC_PRINTF ("len %d\n" , (int )size); -if (!s->rx_enabled) { +if (!s->regs[ENET_RDAR ]) {qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Unexpected packet\n" ,TYPE_IMX_FEC , __func__);return 0 ;@@ -577,7 +625,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, }/* Frames larger than the user limit just set error flags. */ -if (size > (s->rcr >>16 )) { +if (size > (s->regs[ENET_RCR ] >>16 )) { flags |=FEC_BD_LG ; }@@ -595,7 +643,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, TYPE_IMX_FEC, __func__);break ; } - buf_len = (size <= s->emrbr) ? size : s->emrbr; + buf_len = (size <= s->regs[ENET_MRBR ]) ? size : s->regs[ENET_MRBR ]; bd.length = buf_len; size -= buf_len;@@ -618,16 +666,16 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,/* Last buffer in frame. */ bd.flags |= flags |FEC_BD_L ;FEC_PRINTF ("rx frame flags %04x\n" , bd.flags); - s->eir |=FEC_INT_RXF ; + s->regs[ENET_EIR ] |=FEC_INT_RXF ; }else { - s->eir |=FEC_INT_RXB ; + s->regs[ENET_EIR ] |=FEC_INT_RXB ; }imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->erdsr; + addr = s->regs[ENET_RDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } } s->rx_descriptor = addr;include/hw/net/imx_fec.h +16
-0@@ -30,6 +30,33 @@#include "hw/sysbus.h" #include "net/net.h" +#define ENET_EIR 1 +#define ENET_EIMR 2 +#define ENET_RDAR 4 +#define ENET_TDAR 5 +#define ENET_ECR 9 +#define ENET_MMFR 16 +#define ENET_MSCR 17 +#define ENET_MIBC 25 +#define ENET_RCR 33 +#define ENET_TCR 49 +#define ENET_PALR 57 +#define ENET_PAUR 58 +#define ENET_OPD 59 +#define ENET_IAUR 70 +#define ENET_IALR 71 +#define ENET_GAUR 72
include/hw/net/imx_fec.h line 58
Quoted 10 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_GALR 73 +#define ENET_TFWR 81 +#define ENET_FRBR 83 +#define ENET_FRSR 84 +#define ENET_RDSR 96 +#define ENET_TDSR 97 +#define ENET_MRBR 98 +#define ENET_MIIGSK_CFGR 192 +#define ENET_MIIGSK_ENR 194 +#define ENET_MAX 400
Is this an arbitrary value or there's a plan to add more register whose index is greater than 192?
Quoted 48 lines
include/hw/net/imx_fec.h +10
-19+#define FEC_MAX_FRAME_SIZE 2032#define FEC_INT_HB (1 << 31)@@ -46,8 +73,14 @@#define FEC_INT_RL (1 << 20)#define FEC_INT_UN (1 << 19) -#define FEC_EN 2 -#define FEC_RESET 1 +/* RDAR */ +#define ENET_RDAR_RDAR (1 << 24) + +/* TDAR */ +#define ENET_TDAR_TDAR (1 << 24) + +#define FEC_EN (1 << 1) +#define FEC_RESET (1 << 0)/* Buffer Descriptor. */ typedef struct {@@ -83,25 +116,9 @@ typedef struct IMXFECState {qemu_irq irq;MemoryRegion iomem; -uint32_t irq_state; -uint32_t eir; -uint32_t eimr; -uint32_t rx_enabled; +uint32_t regs[ENET_MAX ];uint32_t rx_descriptor;uint32_t tx_descriptor; -uint32_t ecr; -uint32_t mmfr; -uint32_t mscr; -uint32_t mibc; -uint32_t rcr; -uint32_t tcr; -uint32_t tfwr; -uint32_t frsr; -uint32_t erdsr; -uint32_t etdsr; -uint32_t emrbr; -uint32_t miigsk_cfgr; -uint32_t miigsk_enr;uint32_t phy_status;uint32_t phy_control;
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
In reply to Jean-Christophe DuboisQuoted 22 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1Changes since v2:
* Not present on v2Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)
[...]
hw/net/imx_fec.c static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, · line 1185
Quoted 7 lines
hw/net/imx_fec.c +2
-1-static Property imx_fec_properties[] = { +static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };
It's ok to decide with "is-fec", but is it better to use a new type for that?
Quoted 105 lines
hw/net/imx_fec.c +13
-13-static void imx_fec_class_init (ObjectClass *klass,void *data) +static void imx_eth_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_imx_fec; - dc->reset = imx_fec_reset; - dc->props = imx_fec_properties; - dc->realize = imx_fec_realize; - dc->desc ="i.MX FEC Ethernet Controller" ; + dc->vmsd = &vmstate_imx_eth; + dc->reset = imx_eth_reset; + dc->props = imx_eth_properties; + dc->realize = imx_eth_realize; + dc->desc ="i.MX FEC/ENET Ethernet Controller" ; } -static const TypeInfo imx_fec_info = { - .name =TYPE_IMX_FEC , - .parent =TYPE_SYS_BUS_DEVICE , +static const TypeInfo imx_eth_info = { + .name =TYPE_IMX_FEC , + .parent =TYPE_SYS_BUS_DEVICE , .instance_size =sizeof (IMXFECState), - .class_init = imx_fec_class_init, + .class_init = imx_eth_class_init, }; -static void imx_fec_register_types (void ) +static void imx_eth_register_types (void ) { -type_register_static (&imx_fec_info); +type_register_static (&imx_eth_info); } -type_init (imx_fec_register_types) +type_init (imx_eth_register_types)include/hw/net/imx_fec.h +34
-16@@ -1,5 +1,5 @@/* -* i.MX Fast Ethernet Controller emulation. +* i.MX FEC/ENET Ethernet Controller emulation. * * Copyright (c) 2013 Jean-Christophe Dubois. <[email protected]> * @@ -53,25 +53,64 @@#define ENET_RDSR 96#define ENET_TDSR 97#define ENET_MRBR 98 +#define ENET_RSFL 100 +#define ENET_RSEM 101 +#define ENET_RAEM 102 +#define ENET_RAFL 103 +#define ENET_TSEM 104 +#define ENET_TAEM 105 +#define ENET_TAFL 106 +#define ENET_TIPG 107 +#define ENET_FTRL 108 +#define ENET_TACC 112 +#define ENET_RACC 113#define ENET_MIIGSK_CFGR 192#define ENET_MIIGSK_ENR 194 +#define ENET_ATCR 256 +#define ENET_ATVR 257 +#define ENET_ATOFF 258 +#define ENET_ATPER 259 +#define ENET_ATCOR 260 +#define ENET_ATINC 261 +#define ENET_ATSTMP 262 +#define ENET_TGSR 385 +#define ENET_TCSR0 386 +#define ENET_TCCR0 387 +#define ENET_TCSR1 388 +#define ENET_TCCR1 389 +#define ENET_TCSR2 390 +#define ENET_TCCR2 391 +#define ENET_TCSR3 392 +#define ENET_TCCR3 393#define ENET_MAX 400 -#define FEC_MAX_FRAME_SIZE 2032 - -#define FEC_INT_HB (1 << 31) -#define FEC_INT_BABR (1 << 30) -#define FEC_INT_BABT (1 << 29) -#define FEC_INT_GRA (1 << 28) -#define FEC_INT_TXF (1 << 27) -#define FEC_INT_TXB (1 << 26) -#define FEC_INT_RXF (1 << 25) -#define FEC_INT_RXB (1 << 24) -#define FEC_INT_MII (1 << 23) -#define FEC_INT_EBERR (1 << 22) -#define FEC_INT_LC (1 << 21) -#define FEC_INT_RL (1 << 20) -#define FEC_INT_UN (1 << 19) +#define ENET_MAX_FRAME_SIZE 2032 + +/* EIR and EIMR */ +#define ENET_INT_HB (1 << 31) +#define ENET_INT_BABR (1 << 30) +#define ENET_INT_BABT (1 << 29)
include/hw/net/imx_fec.h line 102
Quoted 10 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_INT_GRA (1 << 28) +#define ENET_INT_TXF (1 << 27) +#define ENET_INT_TXB (1 << 26) +#define ENET_INT_RXF (1 << 25) +#define ENET_INT_RXB (1 << 24) +#define ENET_INT_MII (1 << 23) +#define ENET_INT_EBERR (1 << 22) +#define ENET_INT_LC (1 << 21) +#define ENET_INT_RL (1 << 20) +#define ENET_INT_UN (1 << 19)
The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
Quoted 166 lines
include/hw/net/imx_fec.h +116
-19+#define ENET_INT_PLR (1 << 18) +#define ENET_INT_WAKEUP (1 << 17) +#define ENET_INT_TS_AVAIL (1 << 16) +#define ENET_INT_TS_TIMER (1 << 15) + +#define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR | ENET_INT_BABT | \ + ENET_INT_GRA | ENET_INT_TXF | ENET_INT_TXB | \ + ENET_INT_RXF | ENET_INT_RXB | ENET_INT_MII | \ + ENET_INT_EBERR | ENET_INT_LC | ENET_INT_RL | \ + ENET_INT_UN | ENET_INT_PLR | ENET_INT_WAKEUP | \ + ENET_INT_TS_AVAIL)/* RDAR */ #define ENET_RDAR_RDAR (1 << 24)@@ -79,8 +118,54 @@/* TDAR */ #define ENET_TDAR_TDAR (1 << 24) -#define FEC_EN (1 << 1) -#define FEC_RESET (1 << 0) +/* ECR */ +#define ENET_ECR_RESET (1 << 0) +#define ENET_ECR_ETHEREN (1 << 1) +#define ENET_ECR_MAGICEN (1 << 2) +#define ENET_ECR_SLEEP (1 << 3) +#define ENET_ECR_EN1588 (1 << 4) +#define ENET_ECR_SPEED (1 << 5) +#define ENET_ECR_DBGEN (1 << 6) +#define ENET_ECR_STOPEN (1 << 7) +#define ENET_ECR_DSBWP (1 << 8) + +/* MIBC */ +#define ENET_MIBC_MIB_DIS (1 << 31) +#define ENET_MIBC_MIB_IDLE (1 << 30) +#define ENET_MIBC_MIB_CLEAR (1 << 29) + +/* RCR */ +#define ENET_RCR_LOOP (1 << 0) +#define ENET_RCR_DRT (1 << 1) +#define ENET_RCR_MII_MODE (1 << 2) +#define ENET_RCR_PROM (1 << 3) +#define ENET_RCR_BC_REJ (1 << 4) +#define ENET_RCR_FCE (1 << 5) +#define ENET_RCR_RGMII_EN (1 << 6) +#define ENET_RCR_RMII_MODE (1 << 8) +#define ENET_RCR_RMII_10T (1 << 9) +#define ENET_RCR_PADEN (1 << 12) +#define ENET_RCR_PAUFWD (1 << 13) +#define ENET_RCR_CRCFWD (1 << 14) +#define ENET_RCR_CFEN (1 << 15) +#define ENET_RCR_MAX_FL_SHIFT (16) +#define ENET_RCR_MAX_FL_LENGTH (14) +#define ENET_RCR_NLC (1 << 30) +#define ENET_RCR_GRS (1 << 31) + +/* TCR */ +#define ENET_TCR_GTS (1 << 0) +#define ENET_TCR_FDEN (1 << 2) +#define ENET_TCR_TFC_PAUSE (1 << 3) +#define ENET_TCR_RFC_PAUSE (1 << 4) +#define ENET_TCR_ADDSEL_SHIFT (5) +#define ENET_TCR_ADDSEL_LENGTH (3) +#define ENET_TCR_CRCFWD (1 << 9) + +/* RDSR */ +#define ENET_TWFR_TFWR_SHIFT (0) +#define ENET_TWFR_TFWR_LENGTH (6) +#define ENET_TWFR_STRFWD (1 << 8)/* Buffer Descriptor. */ typedef struct {@@ -89,22 +174,60 @@ typedef struct {uint32_t data; } IMXFECBufDesc; -#define FEC_BD_R (1 << 15) -#define FEC_BD_E (1 << 15) -#define FEC_BD_O1 (1 << 14) -#define FEC_BD_W (1 << 13) -#define FEC_BD_O2 (1 << 12) -#define FEC_BD_L (1 << 11) -#define FEC_BD_TC (1 << 10) -#define FEC_BD_ABC (1 << 9) -#define FEC_BD_M (1 << 8) -#define FEC_BD_BC (1 << 7) -#define FEC_BD_MC (1 << 6) -#define FEC_BD_LG (1 << 5) -#define FEC_BD_NO (1 << 4) -#define FEC_BD_CR (1 << 2) -#define FEC_BD_OV (1 << 1) -#define FEC_BD_TR (1 << 0) +#define ENET_BD_R (1 << 15) +#define ENET_BD_E (1 << 15) +#define ENET_BD_O1 (1 << 14) +#define ENET_BD_W (1 << 13) +#define ENET_BD_O2 (1 << 12) +#define ENET_BD_L (1 << 11) +#define ENET_BD_TC (1 << 10) +#define ENET_BD_ABC (1 << 9) +#define ENET_BD_M (1 << 8) +#define ENET_BD_BC (1 << 7) +#define ENET_BD_MC (1 << 6) +#define ENET_BD_LG (1 << 5) +#define ENET_BD_NO (1 << 4) +#define ENET_BD_CR (1 << 2) +#define ENET_BD_OV (1 << 1) +#define ENET_BD_TR (1 << 0) + +typedef struct { +uint16_t length; +uint16_t flags; +uint32_t data; +uint16_t status; +uint16_t option; +uint16_t checksum; +uint16_t head_proto; +uint32_t last_buffer; +uint32_t timestamp; +uint32_t reserved[2 ]; +}IMXENETBufDesc ; + +#define ENET_BD_ME (1 << 15) +#define ENET_BD_TX_INT (1 << 14) +#define ENET_BD_TS (1 << 13) +#define ENET_BD_PINS (1 << 12) +#define ENET_BD_IINS (1 << 11) +#define ENET_BD_PE (1 << 10) +#define ENET_BD_CE (1 << 9) +#define ENET_BD_UC (1 << 8) +#define ENET_BD_RX_INT (1 << 7) + +#define ENET_BD_TXE (1 << 15) +#define ENET_BD_UE (1 << 13) +#define ENET_BD_EE (1 << 12) +#define ENET_BD_FE (1 << 11) +#define ENET_BD_LCE (1 << 10) +#define ENET_BD_OE (1 << 9) +#define ENET_BD_TSE (1 << 8) +#define ENET_BD_ICE (1 << 5) +#define ENET_BD_PCR (1 << 4) +#define ENET_BD_VLAN (1 << 2) +#define ENET_BD_IPV6 (1 << 1) +#define ENET_BD_FRAG (1 << 0) + +#define ENET_BD_BDU (1 << 31) typedef struct IMXFECState { /*< private >*/@@ -113,7 +236,7 @@ typedef struct IMXFECState {/*< public >*/ NICState *nic;NICConf conf; -qemu_irq irq; +qemu_irq irq[2 ];MemoryRegion iomem;uint32_t regs[ENET_MAX ];@@ -125,6 +248,8 @@ typedef struct IMXFECState {uint32_t phy_advertise;uint32_t phy_int;uint32_t phy_int_mask; + + bool is_fec; } IMXFECState;#endif
Re: [Qemu-devel] [PATCH v4 6/8] i.MX: move FEC device to a register array structure.
In reply to Jason WangQuoted 395 lines · Jason Wang
Quoted 392 lines · Jean-Christophe Dubois
This is to prepare for the ENET Gb device of the i.MX6.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1.Changes since v2:
* The patch was split in 2 parts:
- a "port" to a reg array based device (this patch).
- the addition of the Gb support (next patch).
Changes since v3:
* Small fix patches were extracted from this patch (see previous 3
patches)
* Reset logic through ECR was fixed.
* TDAR/RDAR behavior was fixed.hw/net/imx_fec.c | 396 ++++++++++++++++++++++++++--------------------- include/hw/net/imx_fec.h | 55 ++++--- 2 files changed, 258 insertions(+), 193 deletions(-)hw/net/imx_fec.c +74
-32@@ -52,30 +52,75 @@ } \ }while (0 ) +static const char *imx_fec_reg_name(IMXFECState *s, uint32_t index) +{ +static char tmp[20 ]; + +switch (index) { +case ENET_EIR : +return "EIR" ; +case ENET_EIMR : +return "EIMR" ; +case ENET_RDAR : +return "RDAR" ; +case ENET_TDAR : +return "TDAR" ; +case ENET_ECR : +return "ECR" ; +case ENET_MMFR : +return "MMFR" ; +case ENET_MSCR : +return "MSCR" ; +case ENET_MIBC : +return "MIBC" ; +case ENET_RCR : +return "RCR" ; +case ENET_TCR : +return "TCR" ; +case ENET_PALR : +return "PALR" ; +case ENET_PAUR : +return "PAUR" ; +case ENET_OPD : +return "OPD" ; +case ENET_IAUR : +return "IAUR" ; +case ENET_IALR : +return "IALR" ; +case ENET_GAUR : +return "GAUR" ; +case ENET_GALR : +return "GALR" ; +case ENET_TFWR : +return "TFWR" ; +case ENET_RDSR : +return "RDSR" ; +case ENET_TDSR : +return "TDSR" ; +case ENET_MRBR : +return "MRBR" ; +case ENET_FRBR : +return "FRBR" ; +case ENET_FRSR : +return "FRSR" ; +case ENET_MIIGSK_CFGR : +return "MIIGSK_CFGR" ; +case ENET_MIIGSK_ENR : +return "MIIGSK_ENR" ; +default : +sprintf (tmp,"index %d" , index); +return tmp; + } +} +static const VMStateDescription vmstate_imx_fec = { .name =TYPE_IMX_FEC , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .fields = (VMStateField []) { -VMSTATE_UINT32 (irq_state, IMXFECState), -VMSTATE_UINT32 (eir, IMXFECState), -VMSTATE_UINT32 (eimr, IMXFECState), -VMSTATE_UINT32 (rx_enabled, IMXFECState), +VMSTATE_UINT32_ARRAY (regs, IMXFECState,ENET_MAX ),VMSTATE_UINT32 (rx_descriptor, IMXFECState),VMSTATE_UINT32 (tx_descriptor, IMXFECState), -VMSTATE_UINT32 (ecr, IMXFECState), -VMSTATE_UINT32 (mmfr, IMXFECState), -VMSTATE_UINT32 (mscr, IMXFECState), -VMSTATE_UINT32 (mibc, IMXFECState), -VMSTATE_UINT32 (rcr, IMXFECState), -VMSTATE_UINT32 (tcr, IMXFECState), -VMSTATE_UINT32 (tfwr, IMXFECState), -VMSTATE_UINT32 (frsr, IMXFECState), -VMSTATE_UINT32 (erdsr, IMXFECState), -VMSTATE_UINT32 (etdsr, IMXFECState), -VMSTATE_UINT32 (emrbr, IMXFECState), -VMSTATE_UINT32 (miigsk_cfgr, IMXFECState), -VMSTATE_UINT32 (miigsk_enr, IMXFECState),VMSTATE_UINT32 (phy_status, IMXFECState),VMSTATE_UINT32 (phy_control, IMXFECState),@@ -251,15 +296,13 @@ static void imx_fec_write_bd(IMXFECBufDesc *bd, dma_addr_t addr)static void imx_fec_update (IMXFECState *s) { -uint32_t active; -uint32_t changed; - - active = s->eir & s->eimr; - changed = active ^ s->irq_state; -if (changed) { -qemu_set_irq (s->irq, active); +if (s->regs[ENET_EIR ] & s->regs[ENET_EIMR ]) { +FEC_PRINTF ("interrupt raised\n" ); +qemu_set_irq (s->irq,1 ); + }else { +FEC_PRINTF ("interrupt lowered\n" ); +qemu_set_irq (s->irq,0 ); } - s->irq_state = active; }static void imx_fec_do_tx (IMXFECState *s)@@ -283,7 +326,7 @@ static void imx_fec_do_tx(IMXFECState *s) len = bd.length;if (frame_size + len >FEC_MAX_FRAME_SIZE ) { len =FEC_MAX_FRAME_SIZE - frame_size; - s->eir |=FEC_INT_BABT ; + s->regs[ENET_EIR ] |=FEC_INT_BABT ; }dma_memory_read (&address_space_memory, bd.data, ptr, len); ptr += len;@@ -293,17 +336,17 @@ static void imx_fec_do_tx(IMXFECState *s)qemu_send_packet (qemu_get_queue (s->nic), frame, len); ptr = frame; frame_size =0 ; - s->eir |=FEC_INT_TXF ; + s->regs[ENET_EIR ] |=FEC_INT_TXF ; } - s->eir |=FEC_INT_TXB ; + s->regs[ENET_EIR ] |=FEC_INT_TXB ; bd.flags &= ~FEC_BD_R ;/* Write back the modified descriptor. */ imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->etdsr; + addr = s->regs[ENET_TDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } } @@ -315,7 +358,7 @@ static void imx_fec_do_tx(IMXFECState *s)static void imx_fec_enable_rx(IMXFECState *s) { IMXFECBufDesc bd;hw/net/imx_fec.c +54
-75-uint32_t tmp; +bool tmp;imx_fec_read_bd (&bd, s->rx_descriptor); @@ -323,11 +366,11 @@ static void imx_fec_enable_rx(IMXFECState *s) if (!tmp) {FEC_PRINTF ("RX buffer full\n" ); - } else if (!s->rx_enabled) { + } else if (!s->regs[ENET_RDAR]) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); } - s->rx_enabled = tmp; + s->regs[ENET_RDAR ] = tmp ?ENET_RDAR_RDAR :0 ; }static void imx_fec_reset (DeviceState *d)@@ -335,18 +378,26 @@ static void imx_fec_reset(DeviceState *d)IMXFECState *s =IMX_FEC (d);/* Reset the FEC */ - s->eir =0 ; - s->eimr =0 ; - s->rx_enabled =0 ; - s->ecr =0xf0000000 ; - s->mscr =0 ; - s->mibc =0xc0000000 ; - s->rcr =0x05ee0001 ; - s->tcr =0 ; - s->tfwr =0 ; - s->frsr =0x500 ; - s->miigsk_cfgr =0 ; - s->miigsk_enr =0x6 ; +memset (s->regs,0 ,sizeof (s->regs)); + s->regs[ENET_ECR ] =0xf0000000 ; + s->regs[ENET_MIBC ] =0xc0000000 ; + s->regs[ENET_RCR ] =0x05ee0001 ; + s->regs[ENET_OPD ] =0x00010000 ; + + s->regs[ENET_PALR ] = (s->conf.macaddr.a[0 ] <<24 ) + | (s->conf.macaddr.a[1 ] <<16 ) + | (s->conf.macaddr.a[2 ] <<8 ) + | s->conf.macaddr.a[3 ]; + s->regs[ENET_PAUR ] = (s->conf.macaddr.a[4 ] <<24 ) + | (s->conf.macaddr.a[5 ] <<16 ) + |0x8808 ; + + s->regs[ENET_FRBR ] =0x00000600 ; + s->regs[ENET_FRSR ] =0x00000500 ; + s->regs[ENET_MIIGSK_ENR ] =0x00000006 ; + + s->rx_descriptor =0 ; + s->tx_descriptor =0 ;/* We also reset the PHY */ phy_reset (s);@@ -354,183 +405,180 @@ static void imx_fec_reset(DeviceState *d)static uint64_t imx_fec_read (void *opaque,hwaddr addr,unsigned size) { +uint32_t value =0 ;IMXFECState *s =IMX_FEC (opaque); - -FEC_PRINTF ("reading from @ 0x%" HWADDR_PRIx"\n" , addr); - -switch (addr &0x3ff ) { -case 0x004 : -return s->eir; -case 0x008 : -return s->eimr; -case 0x010 : -return s->rx_enabled ? (1 <<24 ) :0 ;/* RDAR */ -case 0x014 : -return 0 ;/* TDAR */ -case 0x024 : -return s->ecr; -case 0x040 : -return s->mmfr; -case 0x044 : -return s->mscr; -case 0x064 : -return s->mibc;/* MIBC */ -case 0x084 : -return s->rcr; -case 0x0c4 : -return s->tcr; -case 0x0e4 :/* PALR */ -return (s->conf.macaddr.a[0 ] <<24 ) - | (s->conf.macaddr.a[1 ] <<16 ) - | (s->conf.macaddr.a[2 ] <<8 ) - | s->conf.macaddr.a[3 ]; -break ; -case 0x0e8 :/* PAUR */ -return (s->conf.macaddr.a[4 ] <<24 ) - | (s->conf.macaddr.a[5 ] <<16 ) - |0x8808 ; -case 0x0ec : -return 0x10000 ;/* OPD */ -case 0x118 : -return 0 ; -case 0x11c : -return 0 ; -case 0x120 : -return 0 ; -case 0x124 : -return 0 ; -case 0x144 : -return s->tfwr; -case 0x14c : -return 0x600 ; -case 0x150 : -return s->frsr; -case 0x180 : -return s->erdsr; -case 0x184 : -return s->etdsr; -case 0x188 : -return s->emrbr; -case 0x300 : -return s->miigsk_cfgr; -case 0x308 : -return s->miigsk_enr; +uint32_t index = addr >>2 ; + +switch (index) { +case ENET_EIR : +case ENET_EIMR : +case ENET_RDAR : +case ENET_TDAR : +case ENET_ECR : +case ENET_MMFR : +case ENET_MSCR : +case ENET_MIBC : +case ENET_RCR : +case ENET_TCR : +case ENET_PALR : +case ENET_PAUR : +case ENET_OPD : +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR : +case ENET_TFWR : +case ENET_RDSR : +case ENET_TDSR : +case ENET_MRBR : +case ENET_FRBR : +case ENET_FRSR : +case ENET_MIIGSK_CFGR : +case ENET_MIIGSK_ENR : + value = s->regs[index]; +break ;default : - qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad address atoffset 0x%"
hw/net/imx_fec.c +1
-2- HWADDR_PRIx "\n", TYPE_IMX_FEC, __func__, addr); -return 0 ; + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register atoffset 0x%"
hw/net/imx_fec.c +4
-0+ PRIx32 "\n", TYPE_IMX_FEC, __func__, index * 4); +break ; } + + FEC_PRINTF("reg[%s] => 0x%" PRIx32 "\n", imx_fec_reg_name(s,index),
hw/net/imx_fec.c +4
-0+ value); + +return value; }static void imx_fec_write (void *opaque,hwaddr addr,uint64_t value,unsigned size) {IMXFECState *s =IMX_FEC (opaque); +uint32_t index = addr >>2 ; - FEC_PRINTF("writing 0x%08x @ 0x%" HWADDR_PRIx "\n",(int)value, addr);
+ FEC_PRINTF("reg[%s] <= 0x%" PRIx32 "\n", imx_fec_reg_name(s,
index),hw/net/imx_fec.c +20
-14+ (uint32_t)value); - switch (addr & 0x3ff) { -case 0x004 :/* EIR */ - s->eir &= ~value; +switch (index) { +case ENET_EIR : + s->regs[index] &= ~value;break ; -case 0x008 :/* EIMR */ - s->eimr = value; +case ENET_EIMR : + s->regs[index] = value;break ; -case 0x010 :/* RDAR */ -if ((s->ecr &FEC_EN ) && !s->rx_enabled) { -imx_fec_enable_rx (s); +case ENET_RDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { +if (!s->regs[index]) { + s->regs[index] =ENET_RDAR_RDAR ; +imx_fec_enable_rx (s); + } + }else { + s->regs[index] =0 ; }break ; -case 0x014 :/* TDAR */ -if (s->ecr &FEC_EN ) { +case ENET_TDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { + s->regs[index] =ENET_TDAR_TDAR ;imx_fec_do_tx (s); } + s->regs[index] =0 ;break ; -case 0x024 :/* ECR */ - s->ecr = value; +case ENET_ECR :if (value &FEC_RESET ) { -imx_fec_reset (DEVICE (s)); +return imx_fec_reset (DEVICE (s)); } -if ((s->ecr &FEC_EN ) ==0 ) { - s->rx_enabled =0 ;
Quoted 8 lines
hw/net/imx_fec.c static void imx_fec_reset(DeviceState *d) · line 494
Quoted 6 lines
hw/net/imx_fec.c +6
-0+ s->regs[index] = value; +if ((s->regs[index] &FEC_EN ) ==0 ) { + s->regs[ENET_RDAR ] =0 ; + s->rx_descriptor = s->regs[ENET_RDSR ]; + s->regs[ENET_TDAR ] =0 ; + s->tx_descriptor = s->regs[ENET_TDSR ];This seems like a new behavior, is this a bug fix? If yes, better split.
It is a more correct behavior I think. Note however that our guest OSes (in particular Linux) do not trigger this bit. So it is mostly untested/unused.
Quoted 59 lines
Quoted 48 lines
} break;hw/net/imx_fec.c +8
-4-case 0x040 :/* MMFR */ -/* store the value */ - s->mmfr = value; +case ENET_MMFR : + s->regs[index] = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); +/* This is a read operation */ + s->regs[ENET_MMFR ] =deposit32 (s->regs[ENET_MMFR ],0 ,16 , +do_phy_read (s, +extract32 (value, +18 ,10 ))); }else { +/* This a write operation */ do_phy_write(s, extract32(value, 18, 10),extract32(value, 0, 16)); } /* raise the interrupt as the PHY operation is done */hw/net/imx_fec.c +9
-10- s->eir |=FEC_INT_MII ; + s->regs[ENET_EIR ] |=FEC_INT_MII ;break ; -case 0x044 :/* MSCR */ - s->mscr = value &0xfe ; +case ENET_MSCR : + s->regs[index] = value &0xfe ;break ; -case 0x064 :/* MIBC */ +case ENET_MIBC :/* TODO: Implement MIB. */ - s->mibc = (value &0x80000000 ) ?0xc0000000 :0 ; + s->regs[index] = (value &0x80000000 ) ?0xc0000000 :0 ;break ; -case 0x084 :/* RCR */ - s->rcr = value &0x07ff003f ; +case ENET_RCR : + s->regs[index] = value &0x07ff003f ;/* TODO: Implement LOOP mode. */ break ; -case 0x0c4 :/* TCR */ +case ENET_TCR :/* We transmit immediately, so raise GRA immediately. */ - s->tcr = value; + s->regs[index] = value;if (value &1 ) { - s->eir |=FEC_INT_GRA ;hw/net/imx_fec.c static void imx_fec_reset(DeviceState *d) · line 535
Quoted 10 lines
hw/net/imx_fec.c +3
-1+ s->regs[ENET_EIR ] |=FEC_INT_GRA ; }break ; -case 0x0e4 :/* PALR */ +case ENET_PALR : + s->regs[index] = value; s->conf.macaddr.a[0 ] = value >>24 ; s->conf.macaddr.a[1 ] = value >>16 ; s->conf.macaddr.a[2 ] = value >>8 ; s->conf.macaddr.a[3 ] = value;
Quoted 1 line
I believe we should use
stl_be_p()here?
I didn't change this bit ...
Quoted 159 lines
Quoted 159 lines
break;hw/net/imx_fec.c +13
-10-case 0x0e8 :/* PAUR */ +case ENET_PAUR : + s->regs[index] = (value |0x0000ffff ) &0xffff8808 ; s->conf.macaddr.a[4 ] = value >>24 ; s->conf.macaddr.a[5 ] = value >>16 ;break ; -case 0x0ec :/* OPDR */ +case ENET_OPD : + s->regs[index] = (value &0x0000ffff ) |0x00010000 ;break ; -case 0x118 :/* IAUR */ -case 0x11c :/* IALR */ -case 0x120 :/* GAUR */ -case 0x124 :/* GALR */ +case ENET_IAUR : +case ENET_IALR : +case ENET_GAUR : +case ENET_GALR :/* TODO: implement MAC hash filtering. */ break ; -case 0x144 :/* TFWR */ - s->tfwr = value &3 ; +case ENET_TFWR : + s->regs[index] = value &3 ;break ; -case 0x14c :/* FRBR */ -/* FRBR writes ignored. */ +case ENET_FRBR : +/* FRBR is read only */ + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Register FRBR isread only\n",
hw/net/imx_fec.c +15
-14+ TYPE_IMX_FEC, __func__);break ; -case 0x150 :/* FRSR */ - s->frsr = (value &0x3fc ) |0x400 ; +case ENET_FRSR : + s->regs[index] = (value &0x000003fc ) |0x00000400 ;break ; -case 0x180 :/* ERDSR */ - s->erdsr = value & ~3 ; - s->rx_descriptor = s->erdsr; +case ENET_RDSR : + s->regs[index] = value & ~3 ; + s->rx_descriptor = s->regs[index];break ; -case 0x184 :/* ETDSR */ - s->etdsr = value & ~3 ; - s->tx_descriptor = s->etdsr; +case ENET_TDSR : + s->regs[index] = value & ~3 ; + s->tx_descriptor = s->regs[index];break ; -case 0x188 :/* EMRBR */ - s->emrbr = value &0x7f0 ; +case ENET_MRBR : + s->regs[index] = value &0x000007f0 ;break ; -case 0x300 :/* MIIGSK_CFGR */ - s->miigsk_cfgr = value &0x53 ; +case ENET_MIIGSK_CFGR : + s->regs[index] = value &0x00000053 ;break ; -case 0x308 :/* MIIGSK_ENR */ - s->miigsk_enr = (value &0x2 ) ?0x6 :0 ; +case ENET_MIIGSK_ENR : + s->regs[index] = (value &0x00000002 ) ?0x00000006 :0 ;break ;default : qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad address atoffset 0x%"
hw/net/imx_fec.c +2
-1- HWADDR_PRIx "\n", TYPE_IMX_FEC, __func__, addr); + PRIx32 "\n", TYPE_IMX_FEC, __func__, index * 4);break ; } @@ -541,7 +589,7 @@ static int imx_fec_can_receive(NetClientState *nc) {IMXFECState *s =IMX_FEC (qemu_get_nic_opaque (nc)); - return s->rx_enabled; +return s->regs[ENET_RDAR ] ?1 :0 ; } static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t*buf,
hw/net/imx_fec.c +2
-1@@ -559,7 +607,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,FEC_PRINTF ("len %d\n" , (int )size); - if (!s->rx_enabled) { +if (!s->regs[ENET_RDAR ]) {qemu_log_mask (LOG_GUEST_ERROR ,"[%s]%s: Unexpected packet\n" ,TYPE_IMX_FEC , __func__);return 0 ;@@ -577,7 +625,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, }/* Frames larger than the user limit just set error flags. */ -if (size > (s->rcr >>16 )) { +if (size > (s->regs[ENET_RCR ] >>16 )) { flags |=FEC_BD_LG ; } @@ -595,7 +643,7 @@ static ssize_t imx_fec_receive(NetClientState*nc, const
uint8_t*buf,TYPE_IMX_FEC, __func__); break; }hw/net/imx_fec.c +1
-1- buf_len = (size <= s->emrbr) ? size : s->emrbr; + buf_len = (size <= s->regs[ENET_MRBR]) ? size :s->regs[ENET_MRBR]; bd.length = buf_len; size -= buf_len; @@ -618,16 +666,16 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, /* Last buffer in frame. */ bd.flags |= flags | FEC_BD_L; FEC_PRINTF("rx frame flags %04x\n", bd.flags);hw/net/imx_fec.c +4
-4- s->eir |=FEC_INT_RXF ; + s->regs[ENET_EIR ] |=FEC_INT_RXF ; }else { - s->eir |=FEC_INT_RXB ; + s->regs[ENET_EIR ] |=FEC_INT_RXB ; }imx_fec_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &FEC_BD_W ) !=0 ) { - addr = s->erdsr; + addr = s->regs[ENET_RDSR ]; }else { - addr +=8 ; + addr +=sizeof (bd); } } s->rx_descriptor = addr;include/hw/net/imx_fec.h +19
-0@@ -30,6 +30,33 @@#include "hw/sysbus.h" #include "net/net.h" +#define ENET_EIR 1 +#define ENET_EIMR 2 +#define ENET_RDAR 4 +#define ENET_TDAR 5 +#define ENET_ECR 9 +#define ENET_MMFR 16 +#define ENET_MSCR 17 +#define ENET_MIBC 25 +#define ENET_RCR 33 +#define ENET_TCR 49 +#define ENET_PALR 57 +#define ENET_PAUR 58 +#define ENET_OPD 59 +#define ENET_IAUR 70 +#define ENET_IALR 71 +#define ENET_GAUR 72 +#define ENET_GALR 73 +#define ENET_TFWR 81 +#define ENET_FRBR 83 +#define ENET_FRSR 84
Quoted 8 lines
include/hw/net/imx_fec.h line 58
Quoted 6 lines
include/hw/net/imx_fec.h +6
-0+#define ENET_RDSR 96 +#define ENET_TDSR 97 +#define ENET_MRBR 98 +#define ENET_MIIGSK_CFGR 192 +#define ENET_MIIGSK_ENR 194 +#define ENET_MAX 400Is this an arbitrary value or there's a plan to add more register whose index is greater than 192?
More registers are coming with the ENET device.
Quoted 46 lines
Quoted 44 lines
include/hw/net/imx_fec.h +10
-17+#define FEC_MAX_FRAME_SIZE 2032#define FEC_INT_HB (1 << 31)@@ -46,8 +73,14 @@#define FEC_INT_RL (1 << 20)#define FEC_INT_UN (1 << 19) -#define FEC_EN 2 -#define FEC_RESET 1 +/* RDAR */ +#define ENET_RDAR_RDAR (1 << 24) + +/* TDAR */ +#define ENET_TDAR_TDAR (1 << 24) + +#define FEC_EN (1 << 1) +#define FEC_RESET (1 << 0)/* Buffer Descriptor. */ typedef struct {@@ -83,25 +116,9 @@ typedef struct IMXFECState {qemu_irq irq;MemoryRegion iomem; - uint32_t irq_state; -uint32_t eir; -uint32_t eimr; -uint32_t rx_enabled; +uint32_t regs[ENET_MAX ];uint32_t rx_descriptor;uint32_t tx_descriptor; -uint32_t ecr; -uint32_t mmfr; -uint32_t mscr; -uint32_t mibc; -uint32_t rcr; -uint32_t tcr; -uint32_t tfwr; -uint32_t frsr; -uint32_t erdsr; -uint32_t etdsr; -uint32_t emrbr; -uint32_t miigsk_cfgr; -uint32_t miigsk_enr;uint32_t phy_status;uint32_t phy_control;
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
In reply to Jason WangQuoted 27 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Quoted 8 lines
hw/net/imx_fec.c static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, · line 1185
Quoted 6 lines
-static Property imx_fec_properties[] = {hw/net/imx_fec.c +2
-0+static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };It's ok to decide with "is-fec", but is it better to use a new type for that?
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
Quoted 104 lines
Quoted 104 lines
-static void
imx_fec_class_init(ObjectClass *klass, void *data)hw/net/imx_fec.c +13
-8+static void imx_eth_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_imx_fec; - dc->reset = imx_fec_reset; - dc->props = imx_fec_properties; - dc->realize = imx_fec_realize; - dc->desc ="i.MX FEC Ethernet Controller" ; + dc->vmsd = &vmstate_imx_eth; + dc->reset = imx_eth_reset; + dc->props = imx_eth_properties; + dc->realize = imx_eth_realize; + dc->desc ="i.MX FEC/ENET Ethernet Controller" ; } -static const TypeInfo imx_fec_info = { - .name =TYPE_IMX_FEC , - .parent =TYPE_SYS_BUS_DEVICE , +static const TypeInfo imx_eth_info = { + .name = TYPE_IMX_FEC, + .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(IMXFECState), - .class_init = imx_fec_class_init, + .class_init = imx_eth_class_init, }; -static void imx_fec_register_types(void) +static void imx_eth_register_types(void) { -type_register_static (&imx_fec_info); + type_register_static(&imx_eth_info); } -type_init(imx_fec_register_types) +type_init (imx_eth_register_types)include/hw/net/imx_fec.h +38
-15@@ -1,5 +1,5 @@/* -* i.MX Fast Ethernet Controller emulation. +* i.MX FEC/ENET Ethernet Controller emulation. * * Copyright (c) 2013 Jean-Christophe Dubois. <[email protected]> * @@ -53,25 +53,64 @@#define ENET_RDSR 96#define ENET_TDSR 97#define ENET_MRBR 98 +#define ENET_RSFL 100 +#define ENET_RSEM 101 +#define ENET_RAEM 102 +#define ENET_RAFL 103 +#define ENET_TSEM 104 +#define ENET_TAEM 105 +#define ENET_TAFL 106 +#define ENET_TIPG 107 +#define ENET_FTRL 108 +#define ENET_TACC 112 +#define ENET_RACC 113#define ENET_MIIGSK_CFGR 192#define ENET_MIIGSK_ENR 194 +#define ENET_ATCR 256 +#define ENET_ATVR 257 +#define ENET_ATOFF 258 +#define ENET_ATPER 259 +#define ENET_ATCOR 260 +#define ENET_ATINC 261 +#define ENET_ATSTMP 262 +#define ENET_TGSR 385 +#define ENET_TCSR0 386 +#define ENET_TCCR0 387 +#define ENET_TCSR1 388 +#define ENET_TCCR1 389 +#define ENET_TCSR2 390 +#define ENET_TCCR2 391 +#define ENET_TCSR3 392 +#define ENET_TCCR3 393#define ENET_MAX 400 -#define FEC_MAX_FRAME_SIZE 2032 - -#define FEC_INT_HB (1 << 31) -#define FEC_INT_BABR (1 << 30) -#define FEC_INT_BABT (1 << 29) -#define FEC_INT_GRA (1 << 28) -#define FEC_INT_TXF (1 << 27) -#define FEC_INT_TXB (1 << 26) -#define FEC_INT_RXF (1 << 25) -#define FEC_INT_RXB (1 << 24) -#define FEC_INT_MII (1 << 23) -#define FEC_INT_EBERR (1 << 22) -#define FEC_INT_LC (1 << 21) -#define FEC_INT_RL (1 << 20) -#define FEC_INT_UN (1 << 19) +#define ENET_MAX_FRAME_SIZE 2032 + +/* EIR and EIMR */ +#define ENET_INT_HB (1 << 31) +#define ENET_INT_BABR (1 << 30) +#define ENET_INT_BABT (1 << 29) +#define ENET_INT_GRA (1 << 28) +#define ENET_INT_TXF (1 << 27) +#define ENET_INT_TXB (1 << 26) +#define ENET_INT_RXF (1 << 25)
Quoted 8 lines
include/hw/net/imx_fec.h line 102
Quoted 6 lines
include/hw/net/imx_fec.h +6
-0+#define ENET_INT_RXB (1 << 24) +#define ENET_INT_MII (1 << 23) +#define ENET_INT_EBERR (1 << 22) +#define ENET_INT_LC (1 << 21) +#define ENET_INT_RL (1 << 20) +#define ENET_INT_UN (1 << 19)The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
What do you mean by "after we're sure we are ENET"?
ENET is the evolution of FEC to support Gb interface. FEC is more like a legacy device these days (for ARM9 family). So it seems we are better supporting ENET as default going forward.
Quoted 167 lines
Quoted 165 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_INT_PLR (1 << 18) +#define ENET_INT_WAKEUP (1 << 17) +#define ENET_INT_TS_AVAIL (1 << 16) +#define ENET_INT_TS_TIMER (1 << 15) + +#define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR |ENET_INT_BABT | \ +ENET_INT_GRA |ENET_INT_TXF |ENET_INT_TXB | \ +ENET_INT_RXF |ENET_INT_RXB |ENET_INT_MII | \ +ENET_INT_EBERR |ENET_INT_LC |ENET_INT_RL | \ + ENET_INT_UN | ENET_INT_PLR |
ENET_INT_WAKEUP| \include/hw/net/imx_fec.h +106
-17+ ENET_INT_TS_AVAIL)/* RDAR */ #define ENET_RDAR_RDAR (1 << 24)@@ -79,8 +118,54 @@/* TDAR */ #define ENET_TDAR_TDAR (1 << 24) -#define FEC_EN (1 << 1) -#define FEC_RESET (1 << 0) +/* ECR */ +#define ENET_ECR_RESET (1 << 0) +#define ENET_ECR_ETHEREN (1 << 1) +#define ENET_ECR_MAGICEN (1 << 2) +#define ENET_ECR_SLEEP (1 << 3) +#define ENET_ECR_EN1588 (1 << 4) +#define ENET_ECR_SPEED (1 << 5) +#define ENET_ECR_DBGEN (1 << 6) +#define ENET_ECR_STOPEN (1 << 7) +#define ENET_ECR_DSBWP (1 << 8) + +/* MIBC */ +#define ENET_MIBC_MIB_DIS (1 << 31) +#define ENET_MIBC_MIB_IDLE (1 << 30) +#define ENET_MIBC_MIB_CLEAR (1 << 29) + +/* RCR */ +#define ENET_RCR_LOOP (1 << 0) +#define ENET_RCR_DRT (1 << 1) +#define ENET_RCR_MII_MODE (1 << 2) +#define ENET_RCR_PROM (1 << 3) +#define ENET_RCR_BC_REJ (1 << 4) +#define ENET_RCR_FCE (1 << 5) +#define ENET_RCR_RGMII_EN (1 << 6) +#define ENET_RCR_RMII_MODE (1 << 8) +#define ENET_RCR_RMII_10T (1 << 9) +#define ENET_RCR_PADEN (1 << 12) +#define ENET_RCR_PAUFWD (1 << 13) +#define ENET_RCR_CRCFWD (1 << 14) +#define ENET_RCR_CFEN (1 << 15) +#define ENET_RCR_MAX_FL_SHIFT (16) +#define ENET_RCR_MAX_FL_LENGTH (14) +#define ENET_RCR_NLC (1 << 30) +#define ENET_RCR_GRS (1 << 31) + +/* TCR */ +#define ENET_TCR_GTS (1 << 0) +#define ENET_TCR_FDEN (1 << 2) +#define ENET_TCR_TFC_PAUSE (1 << 3) +#define ENET_TCR_RFC_PAUSE (1 << 4) +#define ENET_TCR_ADDSEL_SHIFT (5) +#define ENET_TCR_ADDSEL_LENGTH (3) +#define ENET_TCR_CRCFWD (1 << 9) + +/* RDSR */ +#define ENET_TWFR_TFWR_SHIFT (0) +#define ENET_TWFR_TFWR_LENGTH (6) +#define ENET_TWFR_STRFWD (1 << 8)/* Buffer Descriptor. */ typedef struct {@@ -89,22 +174,60 @@ typedef struct {uint32_t data; } IMXFECBufDesc; -#define FEC_BD_R (1 << 15) -#define FEC_BD_E (1 << 15) -#define FEC_BD_O1 (1 << 14) -#define FEC_BD_W (1 << 13) -#define FEC_BD_O2 (1 << 12) -#define FEC_BD_L (1 << 11) -#define FEC_BD_TC (1 << 10) -#define FEC_BD_ABC (1 << 9) -#define FEC_BD_M (1 << 8) -#define FEC_BD_BC (1 << 7) -#define FEC_BD_MC (1 << 6) -#define FEC_BD_LG (1 << 5) -#define FEC_BD_NO (1 << 4) -#define FEC_BD_CR (1 << 2) -#define FEC_BD_OV (1 << 1) -#define FEC_BD_TR (1 << 0) +#define ENET_BD_R (1 << 15) +#define ENET_BD_E (1 << 15) +#define ENET_BD_O1 (1 << 14) +#define ENET_BD_W (1 << 13) +#define ENET_BD_O2 (1 << 12) +#define ENET_BD_L (1 << 11) +#define ENET_BD_TC (1 << 10) +#define ENET_BD_ABC (1 << 9) +#define ENET_BD_M (1 << 8) +#define ENET_BD_BC (1 << 7) +#define ENET_BD_MC (1 << 6) +#define ENET_BD_LG (1 << 5) +#define ENET_BD_NO (1 << 4) +#define ENET_BD_CR (1 << 2) +#define ENET_BD_OV (1 << 1) +#define ENET_BD_TR (1 << 0) + +typedef struct { +uint16_t length; +uint16_t flags; +uint32_t data; +uint16_t status; +uint16_t option; +uint16_t checksum; +uint16_t head_proto; +uint32_t last_buffer; +uint32_t timestamp; +uint32_t reserved[2 ]; +}IMXENETBufDesc ; + +#define ENET_BD_ME (1 << 15) +#define ENET_BD_TX_INT (1 << 14) +#define ENET_BD_TS (1 << 13) +#define ENET_BD_PINS (1 << 12) +#define ENET_BD_IINS (1 << 11) +#define ENET_BD_PE (1 << 10) +#define ENET_BD_CE (1 << 9) +#define ENET_BD_UC (1 << 8) +#define ENET_BD_RX_INT (1 << 7) + +#define ENET_BD_TXE (1 << 15) +#define ENET_BD_UE (1 << 13) +#define ENET_BD_EE (1 << 12) +#define ENET_BD_FE (1 << 11) +#define ENET_BD_LCE (1 << 10) +#define ENET_BD_OE (1 << 9) +#define ENET_BD_TSE (1 << 8) +#define ENET_BD_ICE (1 << 5) +#define ENET_BD_PCR (1 << 4) +#define ENET_BD_VLAN (1 << 2) +#define ENET_BD_IPV6 (1 << 1) +#define ENET_BD_FRAG (1 << 0) + +#define ENET_BD_BDU (1 << 31) typedef struct IMXFECState { /*< private >*/@@ -113,7 +236,7 @@ typedef struct IMXFECState {/*< public >*/ NICState *nic;NICConf conf; -qemu_irq irq; +qemu_irq irq[2 ];MemoryRegion iomem;uint32_t regs[ENET_MAX ];@@ -125,6 +248,8 @@ typedef struct IMXFECState {uint32_t phy_advertise;uint32_t phy_int;uint32_t phy_int_mask; + + bool is_fec; } IMXFECState;#endif
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
Quoted 7 lines · Jean-Christophe DUBOIS
Quoted 4 lines · Jason Wang
On 2016年05月19日 06:23, Jean-Christophe Dubois wrote:
It's ok to decide with "is-fec", but is it better to use a new type for that?
Quoted 6 lines
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
Right, but usually we have different device types, even if under the hood it's the same code using a bool to decide what to do (see for instance hw/display/pl110.c, which provides 3 devices which are all pretty similar). This means that the users of your device don't need to care that the FEC is an ENET device with a flag to say "be like an FEC device", they just instantiate the kind of device they want.
Quoted 10 lines
Quoted 3 lines
The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
What do you mean by "after we're sure we are ENET"?
ENET is the evolution of FEC to support Gb interface. FEC is more like a legacy device these days (for ARM9 family). So it seems we are better supporting ENET as default going forward.
I don't mind if we rename the functions, #defines, etc, but if we do can we have a patch which does that renaming and only that renaming, so it's easy to review?
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 6/8] i.MX: move FEC device to a register array structure.
In reply to Jean-Christophe DUBOISQuoted 28 lines · Jean-Christophe DUBOIS
Quoted 27 lines · Jason Wang
Quoted 24 lines · Jean-Christophe Dubois
This is to prepare for the ENET Gb device of the i.MX6.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1.Changes since v2:
* The patch was split in 2 parts:
- a "port" to a reg array based device (this patch).
- the addition of the Gb support (next patch).
Changes since v3:
* Small fix patches were extracted from this patch (see previous 3
patches)
* Reset logic through ECR was fixed.
* TDAR/RDAR behavior was fixed.hw/net/imx_fec.c | 396 ++++++++++++++++++++++++++--------------------- include/hw/net/imx_fec.h | 55 ++++--- 2 files changed, 258 insertions(+), 193 deletions(-)
[...]
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
hw/net/imx_fec.c +12
-7-case 0x014 :/* TDAR */ -if (s->ecr &FEC_EN ) { +case ENET_TDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { + s->regs[index] =ENET_TDAR_TDAR ;imx_fec_do_tx (s); } + s->regs[index] =0 ;break ; -case 0x024 :/* ECR */ - s->ecr = value; +case ENET_ECR :if (value &FEC_RESET ) { -imx_fec_reset (DEVICE (s)); +return imx_fec_reset (DEVICE (s)); } -if ((s->ecr &FEC_EN ) ==0 ) { - s->rx_enabled =0 ; + s->regs[index] = value; +if ((s->regs[index] &FEC_EN ) ==0 ) { + s->regs[ENET_RDAR ] =0 ; + s->rx_descriptor = s->regs[ENET_RDSR ]; + s->regs[ENET_TDAR ] =0 ; + s->tx_descriptor = s->regs[ENET_TDSR ];
Quoted 4 lines
Quoted 1 line
This seems like a new behavior, is this a bug fix? If yes, better split.
It is a more correct behavior I think. Note however that our guest OSes (in particular Linux) do not trigger this bit. So it is mostly untested/unused.
Is this the real hardware or documented behavior? If yes, need a separate patch for this. If not, we'd better not add this.
Quoted 59 lines
Quoted 59 lines
Quoted 58 lines
} break;hw/net/imx_fec.c +8
-4-case 0x040 :/* MMFR */ -/* store the value */ - s->mmfr = value; +case ENET_MMFR : + s->regs[index] = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); +/* This is a read operation */ + s->regs[ENET_MMFR ] =deposit32 (s->regs[ENET_MMFR ],0 ,16 , +do_phy_read (s, +extract32 (value, +18 ,10 ))); }else { +/* This a write operation */ do_phy_write(s, extract32(value, 18, 10),extract32(value, 0, 16)); } /* raise the interrupt as the PHY operation is done */hw/net/imx_fec.c +12
-11- s->eir |=FEC_INT_MII ; + s->regs[ENET_EIR ] |=FEC_INT_MII ;break ; -case 0x044 :/* MSCR */ - s->mscr = value &0xfe ; +case ENET_MSCR : + s->regs[index] = value &0xfe ;break ; -case 0x064 :/* MIBC */ +case ENET_MIBC :/* TODO: Implement MIB. */ - s->mibc = (value &0x80000000 ) ?0xc0000000 :0 ; + s->regs[index] = (value &0x80000000 ) ?0xc0000000 :0 ;break ; -case 0x084 :/* RCR */ - s->rcr = value &0x07ff003f ; +case ENET_RCR : + s->regs[index] = value &0x07ff003f ;/* TODO: Implement LOOP mode. */ break ; -case 0x0c4 :/* TCR */ +case ENET_TCR :/* We transmit immediately, so raise GRA immediately. */ - s->tcr = value; + s->regs[index] = value;if (value &1 ) { - s->eir |=FEC_INT_GRA ; + s->regs[ENET_EIR ] |=FEC_INT_GRA ; }break ; -case 0x0e4 :/* PALR */ +case ENET_PALR : + s->regs[index] = value; s->conf.macaddr.a[0 ] = value >>24 ; s->conf.macaddr.a[1 ] = value >>16 ; s->conf.macaddr.a[2 ] = value >>8 ; s->conf.macaddr.a[3 ] = value;
Quoted 4 lines
Quoted 1 line
I believe we should use
stl_be_p()here?I didn't change this bit ...
Sorry, you are right. I misread the patch.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
break;hw/net/imx_fec.c +2
-2-case 0x0e8 :/* PAUR */ +case ENET_PAUR : + s->regs[index] = (value |0x0000ffff ) &0xffff8808 ; s->conf.macaddr.a[4 ] = value >>24 ; s->conf.macaddr.a[5 ] = value >>16 ;break ; -case 0x0ec :/* OPDR */
[...]
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
include/hw/net/imx_fec.h +19
-0@@ -30,6 +30,33 @@#include "hw/sysbus.h" #include "net/net.h" +#define ENET_EIR 1 +#define ENET_EIMR 2 +#define ENET_RDAR 4 +#define ENET_TDAR 5 +#define ENET_ECR 9 +#define ENET_MMFR 16 +#define ENET_MSCR 17 +#define ENET_MIBC 25 +#define ENET_RCR 33 +#define ENET_TCR 49 +#define ENET_PALR 57 +#define ENET_PAUR 58 +#define ENET_OPD 59 +#define ENET_IAUR 70 +#define ENET_IALR 71 +#define ENET_GAUR 72 +#define ENET_GALR 73 +#define ENET_TFWR 81 +#define ENET_FRBR 83 +#define ENET_FRSR 84Quoted 8 lines
include/hw/net/imx_fec.h line 58
Quoted 6 lines
include/hw/net/imx_fec.h +6
-0+#define ENET_RDSR 96 +#define ENET_TDSR 97 +#define ENET_MRBR 98 +#define ENET_MIIGSK_CFGR 192 +#define ENET_MIIGSK_ENR 194 +#define ENET_MAX 400Is this an arbitrary value or there's a plan to add more register whose index is greater than 192?
Quoted 2 lines
More registers are coming with the ENET device.
Right, I see.
Thanks
Quoted 48 lines
Quoted 46 lines
Quoted 44 lines
include/hw/net/imx_fec.h +10
-17+#define FEC_MAX_FRAME_SIZE 2032#define FEC_INT_HB (1 << 31)@@ -46,8 +73,14 @@#define FEC_INT_RL (1 << 20)#define FEC_INT_UN (1 << 19) -#define FEC_EN 2 -#define FEC_RESET 1 +/* RDAR */ +#define ENET_RDAR_RDAR (1 << 24) + +/* TDAR */ +#define ENET_TDAR_TDAR (1 << 24) + +#define FEC_EN (1 << 1) +#define FEC_RESET (1 << 0)/* Buffer Descriptor. */ typedef struct {@@ -83,25 +116,9 @@ typedef struct IMXFECState {qemu_irq irq;MemoryRegion iomem; - uint32_t irq_state; -uint32_t eir; -uint32_t eimr; -uint32_t rx_enabled; +uint32_t regs[ENET_MAX ];uint32_t rx_descriptor;uint32_t tx_descriptor; -uint32_t ecr; -uint32_t mmfr; -uint32_t mscr; -uint32_t mibc; -uint32_t rcr; -uint32_t tcr; -uint32_t tfwr; -uint32_t frsr; -uint32_t erdsr; -uint32_t etdsr; -uint32_t emrbr; -uint32_t miigsk_cfgr; -uint32_t miigsk_enr;uint32_t phy_status;uint32_t phy_control;
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
In reply to Jean-Christophe DUBOISQuoted 35 lines · Jean-Christophe DUBOIS
Quoted 34 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Quoted 6 lines
-static Property imx_fec_properties[] = {hw/net/imx_fec.c +2
-0+static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };
Quoted 5 lines
Quoted 1 line
It's ok to decide with "is-fec", but is it better to use a new type for that?
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
You can still share almost all the codes. E.g you can have a look at e1000.c which have 3 types of rather similar devices.
Another question not relate to this patch, I saw version were bumped for vmstate version. Is it better to keep the vmstate for FEC and using a new vmstate for ENET (register array).
Quoted 114 lines
Quoted 105 lines
Quoted 105 lines
-static void
imx_fec_class_init(ObjectClass *klass, void *data)hw/net/imx_fec.c +13
-8+static void imx_eth_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_imx_fec; - dc->reset = imx_fec_reset; - dc->props = imx_fec_properties; - dc->realize = imx_fec_realize; - dc->desc ="i.MX FEC Ethernet Controller" ; + dc->vmsd = &vmstate_imx_eth; + dc->reset = imx_eth_reset; + dc->props = imx_eth_properties; + dc->realize = imx_eth_realize; + dc->desc ="i.MX FEC/ENET Ethernet Controller" ; } -static const TypeInfo imx_fec_info = { - .name =TYPE_IMX_FEC , - .parent =TYPE_SYS_BUS_DEVICE , +static const TypeInfo imx_eth_info = { + .name = TYPE_IMX_FEC, + .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(IMXFECState), - .class_init = imx_fec_class_init, + .class_init = imx_eth_class_init, }; -static void imx_fec_register_types(void) +static void imx_eth_register_types(void) { -type_register_static (&imx_fec_info); + type_register_static(&imx_eth_info); } -type_init(imx_fec_register_types) +type_init (imx_eth_register_types)include/hw/net/imx_fec.h +38
-15@@ -1,5 +1,5 @@/* -* i.MX Fast Ethernet Controller emulation. +* i.MX FEC/ENET Ethernet Controller emulation. * * Copyright (c) 2013 Jean-Christophe Dubois. <[email protected]> * @@ -53,25 +53,64 @@#define ENET_RDSR 96#define ENET_TDSR 97#define ENET_MRBR 98 +#define ENET_RSFL 100 +#define ENET_RSEM 101 +#define ENET_RAEM 102 +#define ENET_RAFL 103 +#define ENET_TSEM 104 +#define ENET_TAEM 105 +#define ENET_TAFL 106 +#define ENET_TIPG 107 +#define ENET_FTRL 108 +#define ENET_TACC 112 +#define ENET_RACC 113#define ENET_MIIGSK_CFGR 192#define ENET_MIIGSK_ENR 194 +#define ENET_ATCR 256 +#define ENET_ATVR 257 +#define ENET_ATOFF 258 +#define ENET_ATPER 259 +#define ENET_ATCOR 260 +#define ENET_ATINC 261 +#define ENET_ATSTMP 262 +#define ENET_TGSR 385 +#define ENET_TCSR0 386 +#define ENET_TCCR0 387 +#define ENET_TCSR1 388 +#define ENET_TCCR1 389 +#define ENET_TCSR2 390 +#define ENET_TCCR2 391 +#define ENET_TCSR3 392 +#define ENET_TCCR3 393#define ENET_MAX 400 -#define FEC_MAX_FRAME_SIZE 2032 - -#define FEC_INT_HB (1 << 31) -#define FEC_INT_BABR (1 << 30) -#define FEC_INT_BABT (1 << 29) -#define FEC_INT_GRA (1 << 28) -#define FEC_INT_TXF (1 << 27) -#define FEC_INT_TXB (1 << 26) -#define FEC_INT_RXF (1 << 25) -#define FEC_INT_RXB (1 << 24) -#define FEC_INT_MII (1 << 23) -#define FEC_INT_EBERR (1 << 22) -#define FEC_INT_LC (1 << 21) -#define FEC_INT_RL (1 << 20) -#define FEC_INT_UN (1 << 19) +#define ENET_MAX_FRAME_SIZE 2032 + +/* EIR and EIMR */ +#define ENET_INT_HB (1 << 31) +#define ENET_INT_BABR (1 << 30) +#define ENET_INT_BABT (1 << 29) +#define ENET_INT_GRA (1 << 28) +#define ENET_INT_TXF (1 << 27) +#define ENET_INT_TXB (1 << 26) +#define ENET_INT_RXF (1 << 25)Quoted 8 lines
include/hw/net/imx_fec.h line 102
Quoted 6 lines
include/hw/net/imx_fec.h +6
-0+#define ENET_INT_RXB (1 << 24) +#define ENET_INT_MII (1 << 23) +#define ENET_INT_EBERR (1 << 22) +#define ENET_INT_LC (1 << 21) +#define ENET_INT_RL (1 << 20) +#define ENET_INT_UN (1 << 19)The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
Quoted 1 line
What do you mean by "after we're sure we are ENET"?
I mean "is_fec" is false here.
Quoted 2 lines
ENET is the evolution of FEC to support Gb interface. FEC is more like a legacy device these days (for ARM9 family). So it seems we are better supporting ENET as default going forward.
Since Peter does not care about this, we're ok here.
Thanks
Quoted 169 lines
Quoted 168 lines
Quoted 166 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_INT_PLR (1 << 18) +#define ENET_INT_WAKEUP (1 << 17) +#define ENET_INT_TS_AVAIL (1 << 16) +#define ENET_INT_TS_TIMER (1 << 15) + +#define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR |ENET_INT_BABT | \ +ENET_INT_GRA |ENET_INT_TXF |ENET_INT_TXB | \ +ENET_INT_RXF |ENET_INT_RXB |ENET_INT_MII | \ +ENET_INT_EBERR |ENET_INT_LC |ENET_INT_RL | \ + ENET_INT_UN | ENET_INT_PLR |
ENET_INT_WAKEUP| \include/hw/net/imx_fec.h +106
-17+ ENET_INT_TS_AVAIL)/* RDAR */ #define ENET_RDAR_RDAR (1 << 24)@@ -79,8 +118,54 @@/* TDAR */ #define ENET_TDAR_TDAR (1 << 24) -#define FEC_EN (1 << 1) -#define FEC_RESET (1 << 0) +/* ECR */ +#define ENET_ECR_RESET (1 << 0) +#define ENET_ECR_ETHEREN (1 << 1) +#define ENET_ECR_MAGICEN (1 << 2) +#define ENET_ECR_SLEEP (1 << 3) +#define ENET_ECR_EN1588 (1 << 4) +#define ENET_ECR_SPEED (1 << 5) +#define ENET_ECR_DBGEN (1 << 6) +#define ENET_ECR_STOPEN (1 << 7) +#define ENET_ECR_DSBWP (1 << 8) + +/* MIBC */ +#define ENET_MIBC_MIB_DIS (1 << 31) +#define ENET_MIBC_MIB_IDLE (1 << 30) +#define ENET_MIBC_MIB_CLEAR (1 << 29) + +/* RCR */ +#define ENET_RCR_LOOP (1 << 0) +#define ENET_RCR_DRT (1 << 1) +#define ENET_RCR_MII_MODE (1 << 2) +#define ENET_RCR_PROM (1 << 3) +#define ENET_RCR_BC_REJ (1 << 4) +#define ENET_RCR_FCE (1 << 5) +#define ENET_RCR_RGMII_EN (1 << 6) +#define ENET_RCR_RMII_MODE (1 << 8) +#define ENET_RCR_RMII_10T (1 << 9) +#define ENET_RCR_PADEN (1 << 12) +#define ENET_RCR_PAUFWD (1 << 13) +#define ENET_RCR_CRCFWD (1 << 14) +#define ENET_RCR_CFEN (1 << 15) +#define ENET_RCR_MAX_FL_SHIFT (16) +#define ENET_RCR_MAX_FL_LENGTH (14) +#define ENET_RCR_NLC (1 << 30) +#define ENET_RCR_GRS (1 << 31) + +/* TCR */ +#define ENET_TCR_GTS (1 << 0) +#define ENET_TCR_FDEN (1 << 2) +#define ENET_TCR_TFC_PAUSE (1 << 3) +#define ENET_TCR_RFC_PAUSE (1 << 4) +#define ENET_TCR_ADDSEL_SHIFT (5) +#define ENET_TCR_ADDSEL_LENGTH (3) +#define ENET_TCR_CRCFWD (1 << 9) + +/* RDSR */ +#define ENET_TWFR_TFWR_SHIFT (0) +#define ENET_TWFR_TFWR_LENGTH (6) +#define ENET_TWFR_STRFWD (1 << 8)/* Buffer Descriptor. */ typedef struct {@@ -89,22 +174,60 @@ typedef struct {uint32_t data; } IMXFECBufDesc; -#define FEC_BD_R (1 << 15) -#define FEC_BD_E (1 << 15) -#define FEC_BD_O1 (1 << 14) -#define FEC_BD_W (1 << 13) -#define FEC_BD_O2 (1 << 12) -#define FEC_BD_L (1 << 11) -#define FEC_BD_TC (1 << 10) -#define FEC_BD_ABC (1 << 9) -#define FEC_BD_M (1 << 8) -#define FEC_BD_BC (1 << 7) -#define FEC_BD_MC (1 << 6) -#define FEC_BD_LG (1 << 5) -#define FEC_BD_NO (1 << 4) -#define FEC_BD_CR (1 << 2) -#define FEC_BD_OV (1 << 1) -#define FEC_BD_TR (1 << 0) +#define ENET_BD_R (1 << 15) +#define ENET_BD_E (1 << 15) +#define ENET_BD_O1 (1 << 14) +#define ENET_BD_W (1 << 13) +#define ENET_BD_O2 (1 << 12) +#define ENET_BD_L (1 << 11) +#define ENET_BD_TC (1 << 10) +#define ENET_BD_ABC (1 << 9) +#define ENET_BD_M (1 << 8) +#define ENET_BD_BC (1 << 7) +#define ENET_BD_MC (1 << 6) +#define ENET_BD_LG (1 << 5) +#define ENET_BD_NO (1 << 4) +#define ENET_BD_CR (1 << 2) +#define ENET_BD_OV (1 << 1) +#define ENET_BD_TR (1 << 0) + +typedef struct { +uint16_t length; +uint16_t flags; +uint32_t data; +uint16_t status; +uint16_t option; +uint16_t checksum; +uint16_t head_proto; +uint32_t last_buffer; +uint32_t timestamp; +uint32_t reserved[2 ]; +}IMXENETBufDesc ; + +#define ENET_BD_ME (1 << 15) +#define ENET_BD_TX_INT (1 << 14) +#define ENET_BD_TS (1 << 13) +#define ENET_BD_PINS (1 << 12) +#define ENET_BD_IINS (1 << 11) +#define ENET_BD_PE (1 << 10) +#define ENET_BD_CE (1 << 9) +#define ENET_BD_UC (1 << 8) +#define ENET_BD_RX_INT (1 << 7) + +#define ENET_BD_TXE (1 << 15) +#define ENET_BD_UE (1 << 13) +#define ENET_BD_EE (1 << 12) +#define ENET_BD_FE (1 << 11) +#define ENET_BD_LCE (1 << 10) +#define ENET_BD_OE (1 << 9) +#define ENET_BD_TSE (1 << 8) +#define ENET_BD_ICE (1 << 5) +#define ENET_BD_PCR (1 << 4) +#define ENET_BD_VLAN (1 << 2) +#define ENET_BD_IPV6 (1 << 1) +#define ENET_BD_FRAG (1 << 0) + +#define ENET_BD_BDU (1 << 31) typedef struct IMXFECState { /*< private >*/@@ -113,7 +236,7 @@ typedef struct IMXFECState {/*< public >*/ NICState *nic;NICConf conf; -qemu_irq irq; +qemu_irq irq[2 ];MemoryRegion iomem;uint32_t regs[ENET_MAX ];@@ -125,6 +248,8 @@ typedef struct IMXFECState {uint32_t phy_advertise;uint32_t phy_int;uint32_t phy_int_mask; + + bool is_fec; } IMXFECState;#endif
Re: [Qemu-devel] [PATCH v4 6/8] i.MX: move FEC device to a register array structure.
In reply to Jason WangQuoted 59 lines · Jason Wang
Quoted 28 lines · Jean-Christophe DUBOIS
Quoted 27 lines · Jason Wang
Quoted 24 lines · Jean-Christophe Dubois
This is to prepare for the ENET Gb device of the i.MX6.
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1.Changes since v2:
* The patch was split in 2 parts:
- a "port" to a reg array based device (this patch).
- the addition of the Gb support (next patch).
Changes since v3:
* Small fix patches were extracted from this patch (see previous
3 patches)
* Reset logic through ECR was fixed.
* TDAR/RDAR behavior was fixed.hw/net/imx_fec.c | 396 ++++++++++++++++++++++++++--------------------- include/hw/net/imx_fec.h | 55 ++++--- 2 files changed, 258 insertions(+), 193 deletions(-)[...]
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
hw/net/imx_fec.c +12
-7-case 0x014 :/* TDAR */ -if (s->ecr &FEC_EN ) { +case ENET_TDAR : +if (s->regs[ENET_ECR ] &FEC_EN ) { + s->regs[index] =ENET_TDAR_TDAR ;imx_fec_do_tx (s); } + s->regs[index] =0 ;break ; -case 0x024 :/* ECR */ - s->ecr = value; +case ENET_ECR :if (value &FEC_RESET ) { -imx_fec_reset (DEVICE (s)); +return imx_fec_reset (DEVICE (s)); } -if ((s->ecr &FEC_EN ) ==0 ) { - s->rx_enabled =0 ; + s->regs[index] = value; +if ((s->regs[index] &FEC_EN ) ==0 ) { + s->regs[ENET_RDAR ] =0 ; + s->rx_descriptor = s->regs[ENET_RDSR ]; + s->regs[ENET_TDAR ] =0 ; + s->tx_descriptor = s->regs[ENET_TDSR ];
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
This seems like a new behavior, is this a bug fix? If yes, better split.
It is a more correct behavior I think. Note however that our guest OSes (in particular Linux) do not trigger this bit. So it is mostly untested/unused.
Is this the real hardware or documented behavior? If yes, need a separate patch for this. If not, we'd better not add this.
I'll add a patch.
Quoted 172 lines
Quoted 60 lines
Quoted 60 lines
Quoted 59 lines
} break;hw/net/imx_fec.c +8
-4-case 0x040 :/* MMFR */ -/* store the value */ - s->mmfr = value; +case ENET_MMFR : + s->regs[index] = value;if (extract32 (value,29 ,1 )) { - s->mmfr =do_phy_read (s,extract32 (value,18 ,10 )); +/* This is a read operation */ + s->regs[ENET_MMFR ] =deposit32 (s->regs[ENET_MMFR ],0 ,16 , +do_phy_read (s, +extract32 (value, +18 ,10 ))); }else { +/* This a write operation */ do_phy_write(s, extract32(value, 18, 10),extract32(value, 0, 16)); } /* raise the interrupt as the PHY operation is done */hw/net/imx_fec.c +12
-11- s->eir |=FEC_INT_MII ; + s->regs[ENET_EIR ] |=FEC_INT_MII ;break ; -case 0x044 :/* MSCR */ - s->mscr = value &0xfe ; +case ENET_MSCR : + s->regs[index] = value &0xfe ;break ; -case 0x064 :/* MIBC */ +case ENET_MIBC :/* TODO: Implement MIB. */ - s->mibc = (value &0x80000000 ) ?0xc0000000 :0 ; + s->regs[index] = (value &0x80000000 ) ?0xc0000000 :0 ;break ; -case 0x084 :/* RCR */ - s->rcr = value &0x07ff003f ; +case ENET_RCR : + s->regs[index] = value &0x07ff003f ;/* TODO: Implement LOOP mode. */ break ; -case 0x0c4 :/* TCR */ +case ENET_TCR :/* We transmit immediately, so raise GRA immediately. */ - s->tcr = value; + s->regs[index] = value;if (value &1 ) { - s->eir |=FEC_INT_GRA ; + s->regs[ENET_EIR ] |=FEC_INT_GRA ; }break ; -case 0x0e4 :/* PALR */ +case ENET_PALR : + s->regs[index] = value; s->conf.macaddr.a[0 ] = value >>24 ; s->conf.macaddr.a[1 ] = value >>16 ; s->conf.macaddr.a[2 ] = value >>8 ; s->conf.macaddr.a[3 ] = value;Quoted 4 lines
Quoted 1 line
I believe we should use
stl_be_p()here?I didn't change this bit ...
Sorry, you are right. I misread the patch.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
break;hw/net/imx_fec.c +2
-2-case 0x0e8 :/* PAUR */ +case ENET_PAUR : + s->regs[index] = (value |0x0000ffff ) &0xffff8808 ; s->conf.macaddr.a[4 ] = value >>24 ; s->conf.macaddr.a[5 ] = value >>16 ;break ; -case 0x0ec :/* OPDR */ [...]
Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
include/hw/net/imx_fec.h +19
-0@@ -30,6 +30,33 @@#include "hw/sysbus.h" #include "net/net.h" +#define ENET_EIR 1 +#define ENET_EIMR 2 +#define ENET_RDAR 4 +#define ENET_TDAR 5 +#define ENET_ECR 9 +#define ENET_MMFR 16 +#define ENET_MSCR 17 +#define ENET_MIBC 25 +#define ENET_RCR 33 +#define ENET_TCR 49 +#define ENET_PALR 57 +#define ENET_PAUR 58 +#define ENET_OPD 59 +#define ENET_IAUR 70 +#define ENET_IALR 71 +#define ENET_GAUR 72 +#define ENET_GALR 73 +#define ENET_TFWR 81 +#define ENET_FRBR 83 +#define ENET_FRSR 84Quoted 8 lines
include/hw/net/imx_fec.h line 58
Quoted 6 lines
include/hw/net/imx_fec.h +6
-0+#define ENET_RDSR 96 +#define ENET_TDSR 97 +#define ENET_MRBR 98 +#define ENET_MIIGSK_CFGR 192 +#define ENET_MIIGSK_ENR 194 +#define ENET_MAX 400Is this an arbitrary value or there's a plan to add more register whose index is greater than 192?
Quoted 2 lines
More registers are coming with the ENET device.
Right, I see.
Thanks
Quoted 48 lines
Quoted 46 lines
Quoted 44 lines
include/hw/net/imx_fec.h +10
-17+#define FEC_MAX_FRAME_SIZE 2032#define FEC_INT_HB (1 << 31)@@ -46,8 +73,14 @@#define FEC_INT_RL (1 << 20)#define FEC_INT_UN (1 << 19) -#define FEC_EN 2 -#define FEC_RESET 1 +/* RDAR */ +#define ENET_RDAR_RDAR (1 << 24) + +/* TDAR */ +#define ENET_TDAR_TDAR (1 << 24) + +#define FEC_EN (1 << 1) +#define FEC_RESET (1 << 0)/* Buffer Descriptor. */ typedef struct {@@ -83,25 +116,9 @@ typedef struct IMXFECState {qemu_irq irq;MemoryRegion iomem; - uint32_t irq_state; -uint32_t eir; -uint32_t eimr; -uint32_t rx_enabled; +uint32_t regs[ENET_MAX ];uint32_t rx_descriptor;uint32_t tx_descriptor; -uint32_t ecr; -uint32_t mmfr; -uint32_t mscr; -uint32_t mibc; -uint32_t rcr; -uint32_t tcr; -uint32_t tfwr; -uint32_t frsr; -uint32_t erdsr; -uint32_t etdsr; -uint32_t emrbr; -uint32_t miigsk_cfgr; -uint32_t miigsk_enr;uint32_t phy_status;uint32_t phy_control;
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
In reply to Peter MaydellQuoted 13 lines · Peter Maydell
Quoted 6 lines · Jean-Christophe DUBOIS
Quoted 4 lines · Jason Wang
On 2016年05月19日 06:23, Jean-Christophe Dubois wrote:
It's ok to decide with "is-fec", but is it better to use a new type for that?
Quoted 6 lines
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
Quoted 7 lines
Right, but usually we have different device types, even if under the hood it's the same code using a bool to decide what to do (see for instance
hw/display/pl110.c, which provides 3 devices which are all pretty similar). This means that the users of your device don't need to care that the FEC is an ENET device with a flag to say "be like an FEC device", they just instantiate the kind of device they want.
OK, I'll do that.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
Quoted 8 lines
Quoted 5 lines
What do you mean by "after we're sure we are ENET"?
ENET is the evolution of FEC to support Gb interface. FEC is more like a legacy device these days (for ARM9 family). So it seems we are better supporting ENET as default going forward.
I don't mind if we rename the functions, #defines, etc, but if we do can we have a patch which does that renaming and only that renaming, so it's easy to review?
OK, I'll add a patch for renaming.
Quoted 4 lines
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
In reply to Jason WangQuoted 38 lines · Jason Wang
Quoted 35 lines · Jean-Christophe DUBOIS
Quoted 34 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Quoted 6 lines
-static Property imx_fec_properties[] = {hw/net/imx_fec.c +2
-0+static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
It's ok to decide with "is-fec", but is it better to use a new type for that?
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
You can still share almost all the codes. E.g you can have a look at
e1000.cwhich have 3 types of rather similar devices.
OK, I'll change it in next patch to match the pl110 model as proposed by Peter. No more additional property...
Quoted 2 lines
Another question not relate to this patch, I saw version were bumped for vmstate version. Is it better to keep the vmstate for FEC and using a new vmstate for ENET (register array).
Well, as I moved the FEC to register array, the VMState structure has changed and therefore I believe the vmstate version needs to be bumped.
Am I wrong?
Quoted 115 lines
Quoted 115 lines
Quoted 114 lines
Quoted 102 lines
-static void
imx_fec_class_init(ObjectClass *klass, void *data)hw/net/imx_fec.c +13
-8+static void imx_eth_class_init (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass); - dc->vmsd = &vmstate_imx_fec; - dc->reset = imx_fec_reset; - dc->props = imx_fec_properties; - dc->realize = imx_fec_realize; - dc->desc ="i.MX FEC Ethernet Controller" ; + dc->vmsd = &vmstate_imx_eth; + dc->reset = imx_eth_reset; + dc->props = imx_eth_properties; + dc->realize = imx_eth_realize; + dc->desc ="i.MX FEC/ENET Ethernet Controller" ; } -static const TypeInfo imx_fec_info = { - .name =TYPE_IMX_FEC , - .parent =TYPE_SYS_BUS_DEVICE , +static const TypeInfo imx_eth_info = { + .name = TYPE_IMX_FEC, + .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(IMXFECState), - .class_init = imx_fec_class_init, + .class_init = imx_eth_class_init, }; -static void imx_fec_register_types(void) +static void imx_eth_register_types(void) { -type_register_static (&imx_fec_info); + type_register_static(&imx_eth_info); } -type_init(imx_fec_register_types) +type_init (imx_eth_register_types)include/hw/net/imx_fec.h +34
-15@@ -1,5 +1,5 @@/* -* i.MX Fast Ethernet Controller emulation. +* i.MX FEC/ENET Ethernet Controller emulation. * * Copyright (c) 2013 Jean-Christophe Dubois. <[email protected]> * @@ -53,25 +53,64 @@#define ENET_RDSR 96#define ENET_TDSR 97#define ENET_MRBR 98 +#define ENET_RSFL 100 +#define ENET_RSEM 101 +#define ENET_RAEM 102 +#define ENET_RAFL 103 +#define ENET_TSEM 104 +#define ENET_TAEM 105 +#define ENET_TAFL 106 +#define ENET_TIPG 107 +#define ENET_FTRL 108 +#define ENET_TACC 112 +#define ENET_RACC 113#define ENET_MIIGSK_CFGR 192#define ENET_MIIGSK_ENR 194 +#define ENET_ATCR 256 +#define ENET_ATVR 257 +#define ENET_ATOFF 258 +#define ENET_ATPER 259 +#define ENET_ATCOR 260 +#define ENET_ATINC 261 +#define ENET_ATSTMP 262 +#define ENET_TGSR 385 +#define ENET_TCSR0 386 +#define ENET_TCCR0 387 +#define ENET_TCSR1 388 +#define ENET_TCCR1 389 +#define ENET_TCSR2 390 +#define ENET_TCCR2 391 +#define ENET_TCSR3 392 +#define ENET_TCCR3 393#define ENET_MAX 400 -#define FEC_MAX_FRAME_SIZE 2032 - -#define FEC_INT_HB (1 << 31) -#define FEC_INT_BABR (1 << 30) -#define FEC_INT_BABT (1 << 29) -#define FEC_INT_GRA (1 << 28) -#define FEC_INT_TXF (1 << 27) -#define FEC_INT_TXB (1 << 26) -#define FEC_INT_RXF (1 << 25) -#define FEC_INT_RXB (1 << 24) -#define FEC_INT_MII (1 << 23) -#define FEC_INT_EBERR (1 << 22) -#define FEC_INT_LC (1 << 21) -#define FEC_INT_RL (1 << 20) -#define FEC_INT_UN (1 << 19) +#define ENET_MAX_FRAME_SIZE 2032 + +/* EIR and EIMR */ +#define ENET_INT_HB (1 << 31) +#define ENET_INT_BABR (1 << 30) +#define ENET_INT_BABT (1 << 29)include/hw/net/imx_fec.h line 102
Quoted 10 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_INT_GRA (1 << 28) +#define ENET_INT_TXF (1 << 27) +#define ENET_INT_TXB (1 << 26) +#define ENET_INT_RXF (1 << 25) +#define ENET_INT_RXB (1 << 24) +#define ENET_INT_MII (1 << 23) +#define ENET_INT_EBERR (1 << 22) +#define ENET_INT_LC (1 << 21) +#define ENET_INT_RL (1 << 20) +#define ENET_INT_UN (1 << 19)The above renaming seems cause lots of unnecessary changes above which may brings issue when backporint patches to -stable. Can we just keep this, and all ENET_*** should be used after we're sure we are ENET?
Quoted 8 lines
Quoted 1 line
What do you mean by "after we're sure we are ENET"?
I mean "
is_fec" is false here.Quoted 2 lines
ENET is the evolution of FEC to support Gb interface. FEC is more like a legacy device these days (for ARM9 family). So it seems we are better supporting ENET as default going forward.
Since Peter does not care about this, we're ok here.
I'll make a renaming patch ...
Quoted 174 lines
Thanks
Quoted 169 lines
Quoted 168 lines
Quoted 166 lines
include/hw/net/imx_fec.h +10
-0+#define ENET_INT_PLR (1 << 18) +#define ENET_INT_WAKEUP (1 << 17) +#define ENET_INT_TS_AVAIL (1 << 16) +#define ENET_INT_TS_TIMER (1 << 15) + +#define ENET_INT_MAC (ENET_INT_HB | ENET_INT_BABR |ENET_INT_BABT | \ +ENET_INT_GRA |ENET_INT_TXF |ENET_INT_TXB | \ +ENET_INT_RXF |ENET_INT_RXB |ENET_INT_MII | \ +ENET_INT_EBERR |ENET_INT_LC |ENET_INT_RL | \ + ENET_INT_UN | ENET_INT_PLR |
ENET_INT_WAKEUP| \include/hw/net/imx_fec.h +106
-17+ ENET_INT_TS_AVAIL)/* RDAR */ #define ENET_RDAR_RDAR (1 << 24)@@ -79,8 +118,54 @@/* TDAR */ #define ENET_TDAR_TDAR (1 << 24) -#define FEC_EN (1 << 1) -#define FEC_RESET (1 << 0) +/* ECR */ +#define ENET_ECR_RESET (1 << 0) +#define ENET_ECR_ETHEREN (1 << 1) +#define ENET_ECR_MAGICEN (1 << 2) +#define ENET_ECR_SLEEP (1 << 3) +#define ENET_ECR_EN1588 (1 << 4) +#define ENET_ECR_SPEED (1 << 5) +#define ENET_ECR_DBGEN (1 << 6) +#define ENET_ECR_STOPEN (1 << 7) +#define ENET_ECR_DSBWP (1 << 8) + +/* MIBC */ +#define ENET_MIBC_MIB_DIS (1 << 31) +#define ENET_MIBC_MIB_IDLE (1 << 30) +#define ENET_MIBC_MIB_CLEAR (1 << 29) + +/* RCR */ +#define ENET_RCR_LOOP (1 << 0) +#define ENET_RCR_DRT (1 << 1) +#define ENET_RCR_MII_MODE (1 << 2) +#define ENET_RCR_PROM (1 << 3) +#define ENET_RCR_BC_REJ (1 << 4) +#define ENET_RCR_FCE (1 << 5) +#define ENET_RCR_RGMII_EN (1 << 6) +#define ENET_RCR_RMII_MODE (1 << 8) +#define ENET_RCR_RMII_10T (1 << 9) +#define ENET_RCR_PADEN (1 << 12) +#define ENET_RCR_PAUFWD (1 << 13) +#define ENET_RCR_CRCFWD (1 << 14) +#define ENET_RCR_CFEN (1 << 15) +#define ENET_RCR_MAX_FL_SHIFT (16) +#define ENET_RCR_MAX_FL_LENGTH (14) +#define ENET_RCR_NLC (1 << 30) +#define ENET_RCR_GRS (1 << 31) + +/* TCR */ +#define ENET_TCR_GTS (1 << 0) +#define ENET_TCR_FDEN (1 << 2) +#define ENET_TCR_TFC_PAUSE (1 << 3) +#define ENET_TCR_RFC_PAUSE (1 << 4) +#define ENET_TCR_ADDSEL_SHIFT (5) +#define ENET_TCR_ADDSEL_LENGTH (3) +#define ENET_TCR_CRCFWD (1 << 9) + +/* RDSR */ +#define ENET_TWFR_TFWR_SHIFT (0) +#define ENET_TWFR_TFWR_LENGTH (6) +#define ENET_TWFR_STRFWD (1 << 8)/* Buffer Descriptor. */ typedef struct {@@ -89,22 +174,60 @@ typedef struct {uint32_t data; } IMXFECBufDesc; -#define FEC_BD_R (1 << 15) -#define FEC_BD_E (1 << 15) -#define FEC_BD_O1 (1 << 14) -#define FEC_BD_W (1 << 13) -#define FEC_BD_O2 (1 << 12) -#define FEC_BD_L (1 << 11) -#define FEC_BD_TC (1 << 10) -#define FEC_BD_ABC (1 << 9) -#define FEC_BD_M (1 << 8) -#define FEC_BD_BC (1 << 7) -#define FEC_BD_MC (1 << 6) -#define FEC_BD_LG (1 << 5) -#define FEC_BD_NO (1 << 4) -#define FEC_BD_CR (1 << 2) -#define FEC_BD_OV (1 << 1) -#define FEC_BD_TR (1 << 0) +#define ENET_BD_R (1 << 15) +#define ENET_BD_E (1 << 15) +#define ENET_BD_O1 (1 << 14) +#define ENET_BD_W (1 << 13) +#define ENET_BD_O2 (1 << 12) +#define ENET_BD_L (1 << 11) +#define ENET_BD_TC (1 << 10) +#define ENET_BD_ABC (1 << 9) +#define ENET_BD_M (1 << 8) +#define ENET_BD_BC (1 << 7) +#define ENET_BD_MC (1 << 6) +#define ENET_BD_LG (1 << 5) +#define ENET_BD_NO (1 << 4) +#define ENET_BD_CR (1 << 2) +#define ENET_BD_OV (1 << 1) +#define ENET_BD_TR (1 << 0) + +typedef struct { +uint16_t length; +uint16_t flags; +uint32_t data; +uint16_t status; +uint16_t option; +uint16_t checksum; +uint16_t head_proto; +uint32_t last_buffer; +uint32_t timestamp; +uint32_t reserved[2 ]; +}IMXENETBufDesc ; + +#define ENET_BD_ME (1 << 15) +#define ENET_BD_TX_INT (1 << 14) +#define ENET_BD_TS (1 << 13) +#define ENET_BD_PINS (1 << 12) +#define ENET_BD_IINS (1 << 11) +#define ENET_BD_PE (1 << 10) +#define ENET_BD_CE (1 << 9) +#define ENET_BD_UC (1 << 8) +#define ENET_BD_RX_INT (1 << 7) + +#define ENET_BD_TXE (1 << 15) +#define ENET_BD_UE (1 << 13) +#define ENET_BD_EE (1 << 12) +#define ENET_BD_FE (1 << 11) +#define ENET_BD_LCE (1 << 10) +#define ENET_BD_OE (1 << 9) +#define ENET_BD_TSE (1 << 8) +#define ENET_BD_ICE (1 << 5) +#define ENET_BD_PCR (1 << 4) +#define ENET_BD_VLAN (1 << 2) +#define ENET_BD_IPV6 (1 << 1) +#define ENET_BD_FRAG (1 << 0) + +#define ENET_BD_BDU (1 << 31) typedef struct IMXFECState { /*< private >*/@@ -113,7 +236,7 @@ typedef struct IMXFECState {/*< public >*/ NICState *nic;NICConf conf; -qemu_irq irq; +qemu_irq irq[2 ];MemoryRegion iomem;uint32_t regs[ENET_MAX ];@@ -125,6 +248,8 @@ typedef struct IMXFECState {uint32_t phy_advertise;uint32_t phy_int;uint32_t phy_int_mask; + + bool is_fec; } IMXFECState;#endif
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
Quoted 47 lines · Jean-Christophe DUBOIS
Quoted 38 lines · Jason Wang
Quoted 35 lines · Jean-Christophe DUBOIS
Quoted 34 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Quoted 6 lines
-static Property imx_fec_properties[] = {hw/net/imx_fec.c +2
-0+static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };Quoted 7 lines
Quoted 5 lines
Quoted 1 line
It's ok to decide with "is-fec", but is it better to use a new type for that?
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
You can still share almost all the codes. E.g you can have a look at
e1000.cwhich have 3 types of rather similar devices.
Quoted 8 lines
OK, I'll change it in next patch to match the pl110 model as proposed by Peter. No more additional property...
Quoted 2 lines
Another question not relate to this patch, I saw version were bumped for vmstate version. Is it better to keep the vmstate for FEC and using a new vmstate for ENET (register array).
Well, as I moved the FEC to register array, the VMState structure has changed and therefore I believe the vmstate version needs to be bumped.
Am I wrong?
You're right. But migration to old version does not work in this way, even if there aren't any changes in FEC.
I'm not sure the policy for arm, but we used to do lots of works in the past to make migration to older version works.
You can achieve this by using two different vmstates, and keep the FEC's state (by just use parts of array).
Perter, any thoughts on this? Should we try to keep the migration compatibility here?
Thanks
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
Quoted 59 lines · Jason Wang
Quoted 47 lines · Jean-Christophe DUBOIS
Quoted 38 lines · Jason Wang
Quoted 35 lines · Jean-Christophe DUBOIS
Quoted 34 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Quoted 6 lines
-static Property imx_fec_properties[] = {hw/net/imx_fec.c +2
-0+static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_BOOL ("is-fec" , IMXFECState, is_fec, false),DEFINE_PROP_END_OF_LIST (), };Quoted 7 lines
Quoted 5 lines
Quoted 1 line
It's ok to decide with "is-fec", but is it better to use a new type for that?
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
You can still share almost all the codes. E.g you can have a look at
e1000.cwhich have 3 types of rather similar devices.Quoted 8 lines
OK, I'll change it in next patch to match the pl110 model as proposed by Peter. No more additional property...
Quoted 2 lines
Another question not relate to this patch, I saw version were bumped for vmstate version. Is it better to keep the vmstate for FEC and using a new vmstate for ENET (register array).
Well, as I moved the FEC to register array, the VMState structure has changed and therefore I believe the vmstate version needs to be bumped.
Am I wrong?
Quoted 7 lines
You're right. But migration to old version does not work in this way, even if there aren't any changes in FEC.
I'm not sure the policy for arm, but we used to do lots of works in the past to make migration to older version works.
You can achieve this by using two different vmstates, and keep the FEC's state (by just use parts of array).
Perter, any thoughts on this? Should we try to keep the migration compatibility here?
I was thinking the migration feature was to migrate old VMSTATE (from previous version of Qemu) to the present (or more modern) version.
I certainly understand the intent and it does make a lot of sense when you are migrating live guest image like for example when using KVM and/or Xen for x86.
Now I am not sure it is worth the trouble in this case. FEC is only used by the i.MX25 PDK board (for now) and I would be surprised if anybody had build a guest image using this platform and that they have the need to migrate this guest from one Qemu version to another.
I am not sure KVM/Xen for ARM is mainstream enough yet and in any case it would be surprising they used i.MX25 PDK as an emulated guest. Hopefully it might change someday ...
I might be wrong and you could have another opinion ...
JC
Quoted 3 lines
Thanks
Re: [Qemu-devel] [PATCH v4 7/8] Add ENET/Gbps Ethernet support to FEC device
Quoted 72 lines · Jean-Christophe DUBOIS
Quoted 59 lines · Jason Wang
Quoted 47 lines · Jean-Christophe DUBOIS
Quoted 40 lines · Jason Wang
Quoted 37 lines · Jean-Christophe DUBOIS
Quoted 35 lines · Jason Wang
Quoted 21 lines · Jean-Christophe Dubois
The ENET device (present in i.MX6) is "derived" from FEC and backward compatible with it.
This patch adds the necessary support of the added feature in the ENET device to allow Linux to use it (on supported processors).
Signed-off-by Jean-Christophe Dubois <[email protected]>---
Changes since v1:
* Not present on v1
Changes since v2:
* Not present on v2
Changes since v3:
* Separate and fix the 2 supported interruptshw/arm/fsl-imx25.c | 3 + hw/net/imx_fec.c | 713 ++++++++++++++++++++++++++++++++++++++--------- include/hw/net/imx_fec.h | 195 ++++++++++--- 3 files changed, 745 insertions(+), 166 deletions(-)[...]
Review
Quoted 6 lines
(quoted diff) +2
-1-static Property imx_fec_properties[] = { +static Property imx_eth_properties[] = { DEFINE_NIC_PROPERTIES(IMXFECState, conf), + DEFINE_PROP_BOOL("is-fec", IMXFECState, is_fec, false), DEFINE_PROP_END_OF_LIST(), };It's ok to decide with "is-fec", but is it better to use a new type for that?
Quoted 5 lines
Quoted 3 lines
Well, there is a lot of common code between FEC and ENET because ENET is basically backward compatible with FEC. So most/all of the FEC code needs to go in the ENET device.
I thought this way of doing thing was the best way to avoid duplicating things.
You can still share almost all the codes. E.g you can have a look at
e1000.cwhich have 3 types of rather similar devices.Quoted 8 lines
OK, I'll change it in next patch to match the pl110 model as proposed by Peter. No more additional property...
Quoted 2 lines
Another question not relate to this patch, I saw version were bumped for vmstate version. Is it better to keep the vmstate for FEC and using a new vmstate for ENET (register array).
Well, as I moved the FEC to register array, the VMState structure has changed and therefore I believe the vmstate version needs to be bumped.
Am I wrong?
Quoted 7 lines
You're right. But migration to old version does not work in this way, even if there aren't any changes in FEC.
I'm not sure the policy for arm, but we used to do lots of works in the past to make migration to older version works.
You can achieve this by using two different vmstates, and keep the FEC's state (by just use parts of array).
Perter, any thoughts on this? Should we try to keep the migration compatibility here?
I was thinking the migration feature was to migrate old VMSTATE (from previous version of Qemu) to the present (or more modern) version.
I certainly understand the intent and it does make a lot of sense when you are migrating live guest image like for example when using KVM and/or Xen for x86.
Quoted 7 lines
Now I am not sure it is worth the trouble in this case. FEC is only used by the i.MX25 PDK board (for now) and I would be surprised if anybody had build a guest image using this platform and that they have the need to migrate this guest from one Qemu version to another.
I am not sure KVM/Xen for ARM is mainstream enough yet and in any case it would be surprising they used i.MX25 PDK as an emulated guest. Hopefully it might change someday ...
I might be wrong and you could have another opinion ...
JC
I get the points, then I think there's no need for doing the compatibility stuffs.
Thanks