i.MX FEC changes
v3 cover i.MX FEC changes
Hi everyone,
This patchset is v3 of a spin-off from original i.MX7 support submission found here [1], containing all of the patchest that are more or less agreed upon and are ready (hopefully!) for inclusion.
Changes since [v2]:
- All SD related patches are dropped from this series (to be re-submitted once Philippe's work lands upstream). Note that "Implement write method of ACMD12ERRSTS register" has been incorporated into Philippe's submission
- Collected Reviewed-by for patch 2 from Philippe
Changes since [v1]:
- Collected Reviewed-by tags from Peter
- Implemented forgotten feedback from Peter for "sdhci: Add i.MX specific subtype of SDHCI"
- "imx_fec: Move Tx frame buffer away from the stack" sent out properly (fingers crossed)
- Added trivial patch to swith i.MX6 over to TYPE_IMX_USDHC
- Added "sd: Check for READ_MULTIPLE_BLOCK size limit violation first" to address a small problem I was seeing when tesiting SD against latest vanilla kernel
Changes since [1]:
- Rx buffer in FEC was moved from stack to heap to allow worry-free expansion to 16K limit.
- Added more comments explaining rather convoluted bit-moving in eSHDC emuation code
- Triple Tx ring DMA "VMState" code was changed to follow Peter's recommendations (avoiding the need to incrememnt the version_id)
- FSL_IMX25_FEC_SIZE is used as a size of FEC's register file
- Removed leftover code from "imx_fec: Change queue flushing heuristics"
[v2] https://lists.gnu.org/archive/html/qemu-arm/2017-12/msg00175.html
[v1] https://lists.gnu.org/archive/html/qemu-arm/2017-12/msg00085.html
[1] https://lists.gnu.org/archive/html/qemu-arm/2017-11/msg00045.html
Andrey Smirnov (11):
imx_fec: Do not link to netdev
imx_fec: Refactor imx_eth_enable_rx()
imx_fec: Change queue flushing heuristics
imx_fec: Move Tx frame buffer away from the stack
imx_fec: Use ENET_FTRL to determine truncation length
imx_fec: Use MIN instead of explicit ternary operator
imx_fec: Emulate SHIFT16 in ENETx_RACC
imx_fec: Add support for multiple Tx DMA rings
imx_fec: Use correct length for packet size
imx_fec: Fix a typo in imx_enet_receive()
imx_fec: Reserve full FSL_IMX25_FEC_SIZE page for the register file
hw/arm/fsl-imx6.c | 1 + hw/net/imx_fec.c | 210 +++++++++++++++++++++++++++++++++++---------- include/hw/arm/fsl-imx25.h | 1 - include/hw/net/imx_fec.h | 27 +++++- 4 files changed, 188 insertions(+), 51 deletions(-)
Signature · 1 line
2.14.3
PATCH v3 1/11 imx_fec: Do not link to netdev
Binding to a particular netdev doesn't seem to belong to this layer and should probably be done as a part of board or SoC specific code.
Convert all of the users of this IP block to useqdev_set_nic_properties() instead.
--- hw/arm/fsl-imx6.c | 1 + hw/net/imx_fec.c | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-)
hw/arm/fsl-imx6.c +1 -0
@@ -385,6 +385,7 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp) spi_table[i].irq)); } +qdev_set_nic_properties (DEVICE (&s->eth), &nd_table[0 ]);object_property_set_bool (OBJECT (&s->eth), true,"realized" , &err);if (err) {error_propagate (errp, err);
hw/net/imx_fec.c +0 -2
@@ -1171,8 +1171,6 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)qemu_macaddr_default_if_unset (&s->conf.macaddr); - s->conf.peers.ncs[0 ] = nd_table[0 ].netdev; - s->nic =qemu_new_nic (&imx_eth_net_info, &s->conf,object_get_typename (OBJECT (dev)),DEVICE (dev)->id, s);
Signature · 1 line
2.14.3
PATCH v3 2/11 imx_fec: Refactor imx_eth_enable_rx()
In reply to Andrey SmirnovRefactor imx_eth_enable_rx() to have more meaningfull variable name than 'tmp' and to reduce number of logical negations done.
--- hw/net/imx_fec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/net/imx_fec.c +4 -4
@@ -536,19 +536,19 @@ static void imx_eth_do_tx(IMXFECState *s)static void imx_eth_enable_rx (IMXFECState *s) {IMXFECBufDesc bd; -bool tmp; +bool rx_ring_full;imx_fec_read_bd (&bd, s->rx_descriptor); - tmp = ((bd.flags &ENET_BD_E ) !=0 ); + rx_ring_full = !(bd.flags &ENET_BD_E ); -if (!tmp) { +if (rx_ring_full) {FEC_PRINTF ("RX buffer full\n" ); }else if (!s->regs[ENET_RDAR ]) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); } - s->regs[ENET_RDAR ] = tmp ?ENET_RDAR_RDAR :0 ; + s->regs[ENET_RDAR ] = rx_ring_full ?0 :ENET_RDAR_RDAR ; }static void imx_eth_reset (DeviceState *d)
Signature · 1 line
2.14.3
PATCH v3 3/11 imx_fec: Change queue flushing heuristics
In reply to Andrey SmirnovIn current implementation, packet queue flushing logic seem to suffer from a deadlock like scenario if a packet is received by the interface before before Rx ring is initialized by Guest's driver. Consider the following sequence of events:
1. A QEMU instance is started against a TAP device on Linux host, running Linux guest, e. g., something to the effect of:
qemu-system-arm \
-net nic,model=imx.fec,netdev=lan0 \
netdev tap,id=lan0,ifname=tap0,script=no,downscript=no \
... rest of the arguments ...
2. Once QEMU starts, but before guest reaches the point where FEC deriver is done initializing the HW, Guest, via TAP interface, receives a number of multicast MDNS packets from Host (not necessarily true for every OS, but it happens at least on Fedora 25)
3. Recieving a packet in such a state results in imx_eth_can_receive() returning '0', which in turn causes tap_send() to disable corresponding event (tap.c:203)
4. Once Guest's driver reaches the point where it is ready to recieve packets it prepares Rx ring descriptors and writes ENET_RDAR_RDAR to ENET_RDAR register to indicate to HW that more descriptors are ready. And at this points emulation layer does this:
s->regs[index] = ENET_RDAR_RDAR;
imx_eth_enable_rx(s);
which, combined with:
if (!s->regs[ENET_RDAR]) {
qemu_flush_queued_packets(qemu_get_queue(s->nic));
}
results in Rx queue never being flushed and corresponding I/O event beign disabled.
To prevent the problem, change the code to always flush packet queue when ENET_RDAR transitions 0 -> ENET_RDAR_RDAR.
--- hw/net/imx_fec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/net/imx_fec.c +6 -6
@@ -533,7 +533,7 @@ static void imx_eth_do_tx(IMXFECState *s) } } -static void imx_eth_enable_rx (IMXFECState *s) +static void imx_eth_enable_rx (IMXFECState *s,bool flush) {IMXFECBufDesc bd;bool rx_ring_full;
@@ -544,7 +544,7 @@ static void imx_eth_enable_rx(IMXFECState *s)if (rx_ring_full) {FEC_PRINTF ("RX buffer full\n" ); - }else if (!s->regs[ENET_RDAR ]) { + }else if (flush) {qemu_flush_queued_packets (qemu_get_queue (s->nic)); }
@@ -807,7 +807,7 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,if (s->regs[ENET_ECR ] &ENET_ECR_ETHEREN ) {if (!s->regs[index]) { s->regs[index] =ENET_RDAR_RDAR ; -imx_eth_enable_rx (s); +imx_eth_enable_rx (s, true); } }else { s->regs[index] =0 ;
@@ -930,7 +930,7 @@ static int imx_eth_can_receive(NetClientState *nc)FEC_PRINTF ("\n" ); -return s->regs[ENET_RDAR ] ?1 :0 ; +return !!s->regs[ENET_RDAR ]; } static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf,
@@ -1020,7 +1020,7 @@ static ssize_t imx_fec_receive(NetClientState *nc, const uint8_t *buf, } } s->rx_descriptor = addr; -imx_eth_enable_rx (s); +imx_eth_enable_rx (s, false);imx_eth_update (s);return len; }
@@ -1116,7 +1116,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, } } s->rx_descriptor = addr; -imx_eth_enable_rx (s); +imx_eth_enable_rx (s, false);imx_eth_update (s);return len; }
Signature · 1 line
2.14.3
PATCH v3 4/11 imx_fec: Move Tx frame buffer away from the stack
In reply to Andrey SmirnovMake Tx frame assembly buffer to be a paort of IMXFECState structure to avoid a concern about having large data buffer on the stack.
--- hw/net/imx_fec.c | 22 +++++++++++----------- include/hw/net/imx_fec.h | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-)
hw/net/imx_fec.c +11 -11
@@ -405,8 +405,7 @@ static void imx_eth_update(IMXFECState *s)static void imx_fec_do_tx (IMXFECState *s) {int frame_size =0 , descnt =0 ; -uint8_t frame[ENET_MAX_FRAME_SIZE ]; -uint8_t *ptr = frame; +uint8_t *ptr = s->frame;uint32_t addr = s->tx_descriptor;while (descnt++ <IMX_MAX_DESC ) {
@@ -431,8 +430,8 @@ static void imx_fec_do_tx(IMXFECState *s) frame_size += len;if (bd.flags &ENET_BD_L ) {/* Last buffer in frame. */ -qemu_send_packet (qemu_get_queue (s->nic), frame, frame_size); - ptr = frame; +qemu_send_packet (qemu_get_queue (s->nic), s->frame, frame_size); + ptr = s->frame; frame_size =0 ; s->regs[ENET_EIR ] |=ENET_INT_TXF ; }
@@ -456,8 +455,7 @@ static void imx_fec_do_tx(IMXFECState *s)static void imx_enet_do_tx (IMXFECState *s) {int frame_size =0 , descnt =0 ; -uint8_t frame[ENET_MAX_FRAME_SIZE ]; -uint8_t *ptr = frame; +uint8_t *ptr = s->frame;uint32_t addr = s->tx_descriptor;while (descnt++ <IMX_MAX_DESC ) {
@@ -482,13 +480,13 @@ static void imx_enet_do_tx(IMXFECState *s) frame_size += len;if (bd.flags &ENET_BD_L ) {if (bd.option &ENET_BD_PINS ) { -struct ip_header *ip_hd =PKT_GET_IP_HDR (frame); +struct ip_header *ip_hd =PKT_GET_IP_HDR (s->frame);if (IP_HEADER_VERSION (ip_hd) ==4 ) { -net_checksum_calculate (frame, frame_size); +net_checksum_calculate (s->frame, frame_size); } }if (bd.option &ENET_BD_IINS ) { -struct ip_header *ip_hd =PKT_GET_IP_HDR (frame); +struct ip_header *ip_hd =PKT_GET_IP_HDR (s->frame);/* We compute checksum only for IPv4 frames */ if (IP_HEADER_VERSION (ip_hd) ==4 ) {uint16_t csum;
@@ -498,8 +496,10 @@ static void imx_enet_do_tx(IMXFECState *s) } }/* Last buffer in frame. */ -qemu_send_packet (qemu_get_queue (s->nic), frame, len); - ptr = frame; + +qemu_send_packet (qemu_get_queue (s->nic), s->frame, len); + ptr = s->frame; + frame_size =0 ;if (bd.option &ENET_BD_TX_INT ) { s->regs[ENET_EIR ] |=ENET_INT_TXF ;
include/hw/net/imx_fec.h +3 -0
@@ -252,6 +252,9 @@ typedef struct IMXFECState {uint32_t phy_int_mask;bool is_fec; + +/* Buffer used to assemble a Tx frame */ + uint8_t frame[ENET_MAX_FRAME_SIZE]; } IMXFECState;#endif
Signature · 1 line
2.14.3
Re: [Qemu-arm] [PATCH v3 04/11] imx_fec: Move Tx frame buffer away from the stack
Quoted 10 lines · Andrey Smirnov
Make Tx frame assembly buffer to be a paort of IMXFECState structure to avoid a concern about having large data buffer on the stack.
Cc Peter Maydell <[email protected]>Cc Jason Wang <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
thanks
-- PMM
PATCH v3 5/11 imx_fec: Use ENET_FTRL to determine truncation length
In reply to Andrey SmirnovFrame truncation length, TRUNC_FL, is determined by the contents of ENET_FTRL register, so convert the code to use it instead of a hardcoded constant.
To avoid the case where TRUNC_FL is greater that ENET_MAX_FRAME_SIZE, increase the value of the latter to its theoretical maximum of 16K.
--- hw/net/imx_fec.c | 4 ++-- include/hw/net/imx_fec.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-)
hw/net/imx_fec.c +2 -2
@@ -1052,8 +1052,8 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, crc_ptr = (uint8_t *) &crc;/* Huge frames are truncted. */ -if (size >ENET_MAX_FRAME_SIZE ) { - size =ENET_MAX_FRAME_SIZE ; +if (size > s->regs[ENET_FTRL ]) { + size = s->regs[ENET_FTRL ]; flags |=ENET_BD_TR |ENET_BD_LG ; }
include/hw/net/imx_fec.h +2 -1
@@ -86,7 +86,6 @@#define ENET_TCCR3 393#define ENET_MAX 400 -#define ENET_MAX_FRAME_SIZE 2032/* EIR and EIMR */ #define ENET_INT_HB (1 << 31)
@@ -155,6 +154,8 @@#define ENET_RCR_NLC (1 << 30)#define ENET_RCR_GRS (1 << 31) +#define ENET_MAX_FRAME_SIZE (1 << ENET_RCR_MAX_FL_LENGTH) +/* TCR */ #define ENET_TCR_GTS (1 << 0)#define ENET_TCR_FDEN (1 << 2)
Signature · 1 line
2.14.3
Re: [Qemu-arm] [PATCH v3 05/11] imx_fec: Use ENET_FTRL to determine truncation length
Quoted 7 lines · Andrey Smirnov
Frame truncation length,
TRUNC_FL, is determined by the contents ofENET_FTRLregister, so convert the code to use it instead of a hardcoded constant.To avoid the case where
TRUNC_FLis greater thatENET_MAX_FRAME_SIZE, increase the value of the latter to its theoretical maximum of 16K.
Quoted 7 lines
Cc Peter Maydell <[email protected]>Cc Jason Wang <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Signed-off-by Andrey Smirnov <[email protected]>
thanks
-- PMM
PATCH v3 6/11 imx_fec: Use MIN instead of explicit ternary operator
In reply to Andrey Smirnov--- hw/net/imx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +1 -1
@@ -1076,7 +1076,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, TYPE_IMX_FEC, __func__);break ; } - buf_len = (size <= s->regs[ENET_MRBR ]) ? size : s->regs[ENET_MRBR ]; + buf_len =MIN (size, s->regs[ENET_MRBR ]); bd.length = buf_len; size -= buf_len;
Signature · 1 line
2.14.3
PATCH v3 7/11 imx_fec: Emulate SHIFT16 in ENETx_RACC
In reply to Andrey SmirnovNeeded to support latest Linux kernel driver which relies on that functionality.
--- hw/net/imx_fec.c | 23 +++++++++++++++++++++++ include/hw/net/imx_fec.h | 2 ++ 2 files changed, 25 insertions(+)
hw/net/imx_fec.c +23 -0
@@ -1037,6 +1037,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf,uint8_t *crc_ptr;unsigned int buf_len;size_t size = len; +bool shift16 = s->regs[ENET_RACC ] &ENET_RACC_SHIFT16 ;FEC_PRINTF ("len %d\n" , (int )size);
@@ -1051,6 +1052,10 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, crc =cpu_to_be32 (crc32 (~0 , buf, size)); crc_ptr = (uint8_t *) &crc; +if (shift16) { + size +=2 ; + } +/* Huge frames are truncted. */ if (size > s->regs[ENET_FTRL ]) { size = s->regs[ENET_FTRL ];
@@ -1087,6 +1092,24 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, buf_len += size -4 ; } buf_addr = bd.data; + +if (shift16) { +/* +* If SHIFT16 bit of ENETx_RACC register is set we need to +* align the payload to 4-byte boundary. +*/ +const uint8_t zeros[2 ] = {0 }; + +dma_memory_write (&address_space_memory, buf_addr, + zeros,sizeof (zeros)); + + buf_addr +=sizeof (zeros); + buf_len -=sizeof (zeros); + +/* We only do this once per Ethernet frame */ + shift16 = false; + } +dma_memory_write (&address_space_memory, buf_addr, buf, buf_len); buf += buf_len;if (size <4 ) {
include/hw/net/imx_fec.h +2 -0
@@ -170,6 +170,8 @@#define ENET_TWFR_TFWR_LENGTH (6)#define ENET_TWFR_STRFWD (1 << 8) +#define ENET_RACC_SHIFT16 BIT(7) +/* Buffer Descriptor. */ typedef struct { uint16_t length;
Signature · 1 line
2.14.3
PATCH v3 8/11 imx_fec: Add support for multiple Tx DMA rings
In reply to Andrey SmirnovMore recent version of the IP block support more than one Tx DMA ring, so add the code implementing that feature.
--- hw/net/imx_fec.c | 133 ++++++++++++++++++++++++++++++++++++++++------- include/hw/net/imx_fec.h | 18 ++++++- 2 files changed, 130 insertions(+), 21 deletions(-)
hw/net/imx_fec.c +114 -19
@@ -196,6 +196,31 @@ static const char *imx_eth_reg_name(IMXFECState *s, uint32_t index) } } +/* +* Versions of this device with more than one TX descriptor save the +* 2nd and 3rd descriptors in a subsection, to maintain migration +* compatibility with previous versions of the device that only +* supported a single descriptor. +*/ +static bool imx_eth_is_multi_tx_ring (void *opaque) +{ +IMXFECState *s =IMX_FEC (opaque); + +return s->tx_ring_num >1 ; +} + +static const VMStateDescription vmstate_imx_eth_txdescs = { + .name ="imx.fec/txdescs" , + .version_id =1 , + .minimum_version_id =1 , + .needed = imx_eth_is_multi_tx_ring, + .fields = (VMStateField []) { +VMSTATE_UINT32 (tx_descriptor[1 ], IMXFECState), +VMSTATE_UINT32 (tx_descriptor[2 ], IMXFECState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_imx_eth = { .name =TYPE_IMX_FEC , .version_id =2 ,
@@ -203,15 +228,18 @@ static const VMStateDescription vmstate_imx_eth = { .fields = (VMStateField[]) {VMSTATE_UINT32_ARRAY (regs, IMXFECState,ENET_MAX ),VMSTATE_UINT32 (rx_descriptor, IMXFECState), -VMSTATE_UINT32 (tx_descriptor, IMXFECState), - +VMSTATE_UINT32 (tx_descriptor[0 ], IMXFECState),VMSTATE_UINT32 (phy_status, IMXFECState),VMSTATE_UINT32 (phy_control, IMXFECState),VMSTATE_UINT32 (phy_advertise, IMXFECState),VMSTATE_UINT32 (phy_int, IMXFECState),VMSTATE_UINT32 (phy_int_mask, IMXFECState),VMSTATE_END_OF_LIST () - } + }, + .subsections = (const VMStateDescription * []) { + &vmstate_imx_eth_txdescs, +NULL + }, };#define PHY_INT_ENERGYON (1 << 7)
@@ -406,7 +434,7 @@ static void imx_fec_do_tx(IMXFECState *s) {int frame_size =0 , descnt =0 ;uint8_t *ptr = s->frame; -uint32_t addr = s->tx_descriptor; +uint32_t addr = s->tx_descriptor[0 ];while (descnt++ <IMX_MAX_DESC ) {IMXFECBufDesc bd;
@@ -447,16 +475,47 @@ static void imx_fec_do_tx(IMXFECState *s) } } - s->tx_descriptor = addr; + s->tx_descriptor[0 ] = addr;imx_eth_update (s); } -static void imx_enet_do_tx (IMXFECState *s) +static void imx_enet_do_tx (IMXFECState *s,uint32_t index) {int frame_size =0 , descnt =0 ; +uint8_t *ptr = s->frame; -uint32_t addr = s->tx_descriptor; +uint32_t addr, int_txb, int_txf, tdsr; +size_t ring; + +switch (index) { +case ENET_TDAR : + ring =0 ; + int_txb =ENET_INT_TXB ; + int_txf =ENET_INT_TXF ; + tdsr =ENET_TDSR ; +break ; +case ENET_TDAR1 : + ring =1 ; + int_txb =ENET_INT_TXB1 ; + int_txf =ENET_INT_TXF1 ; + tdsr =ENET_TDSR1 ; +break ; +case ENET_TDAR2 : + ring =2 ; + int_txb =ENET_INT_TXB2 ; + int_txf =ENET_INT_TXF2 ; + tdsr =ENET_TDSR2 ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"%s: bogus value for index %x\n" , + __func__, index); +abort (); +break ; + } + + addr = s->tx_descriptor[ring];while (descnt++ <IMX_MAX_DESC ) {IMXENETBufDesc bd;
@@ -502,32 +561,32 @@ static void imx_enet_do_tx(IMXFECState *s) frame_size =0 ;if (bd.option &ENET_BD_TX_INT ) { - s->regs[ENET_EIR ] |=ENET_INT_TXF ; + s->regs[ENET_EIR ] |= int_txf; } }if (bd.option &ENET_BD_TX_INT ) { - s->regs[ENET_EIR ] |=ENET_INT_TXB ; + s->regs[ENET_EIR ] |= int_txb; } bd.flags &= ~ENET_BD_R ;/* Write back the modified descriptor. */ imx_enet_write_bd (&bd, addr);/* Advance to the next descriptor. */ if ((bd.flags &ENET_BD_W ) !=0 ) { - addr = s->regs[ENET_TDSR ]; + addr = s->regs[tdsr]; }else { addr +=sizeof (bd); } } - s->tx_descriptor = addr; + s->tx_descriptor[ring] = addr;imx_eth_update (s); } -static void imx_eth_do_tx (IMXFECState *s) +static void imx_eth_do_tx (IMXFECState *s,uint32_t index) {if (!s->is_fec && (s->regs[ENET_ECR ] &ENET_ECR_EN1588 )) { -imx_enet_do_tx (s); +imx_enet_do_tx (s, index); }else {imx_fec_do_tx (s); }
@@ -585,7 +644,7 @@ static void imx_eth_reset(DeviceState *d) } s->rx_descriptor =0 ; - s->tx_descriptor =0 ; +memset (s->tx_descriptor,0 ,sizeof (s->tx_descriptor));/* We also reset the PHY */ phy_reset (s);
@@ -791,6 +850,7 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) {IMXFECState *s =IMX_FEC (opaque); +const bool single_tx_ring = !imx_eth_is_multi_tx_ring (s);uint32_t index = offset >>2 ; FEC_PRINTF("reg[%s] <= 0x%" PRIx32 "\n", imx_eth_reg_name(s, index),
@@ -813,10 +873,18 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, s->regs[index] =0 ; }break ; -case ENET_TDAR : +case ENET_TDAR1 :/* FALLTHROUGH */ +case ENET_TDAR2 :/* FALLTHROUGH */ +if (unlikely (single_tx_ring)) { +qemu_log_mask (LOG_GUEST_ERROR , +"[%s]%s: trying to access TDAR2 or TDAR1\n" , +TYPE_IMX_FEC , __func__); +return ; + } +case ENET_TDAR :/* FALLTHROUGH */ if (s->regs[ENET_ECR ] &ENET_ECR_ETHEREN ) { s->regs[index] =ENET_TDAR_TDAR ; -imx_eth_do_tx (s); +imx_eth_do_tx (s, index); } s->regs[index] =0 ;break ;
@@ -828,8 +896,12 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value,if ((s->regs[index] &ENET_ECR_ETHEREN ) ==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 ]; + s->regs[ENET_TDAR ] =0 ; + s->regs[ENET_TDAR1 ] =0 ; + s->regs[ENET_TDAR2 ] =0 ; + s->tx_descriptor[0 ] = s->regs[ENET_TDSR ]; + s->tx_descriptor[1 ] = s->regs[ENET_TDSR1 ]; + s->tx_descriptor[2 ] = s->regs[ENET_TDSR2 ]; }break ;case ENET_MMFR :
@@ -907,7 +979,29 @@ static void imx_eth_write(void *opaque, hwaddr offset, uint64_t value, }else { s->regs[index] = value & ~7 ; } - s->tx_descriptor = s->regs[index]; + s->tx_descriptor[0 ] = s->regs[index]; +break ; +case ENET_TDSR1 : +if (unlikely (single_tx_ring)) { +qemu_log_mask (LOG_GUEST_ERROR , +"[%s]%s: trying to access TDSR1\n" , +TYPE_IMX_FEC , __func__); +return ; + } + + s->regs[index] = value & ~7 ; + s->tx_descriptor[1 ] = s->regs[index]; +break ; +case ENET_TDSR2 : +if (unlikely (single_tx_ring)) { +qemu_log_mask (LOG_GUEST_ERROR , +"[%s]%s: trying to access TDSR2\n" , +TYPE_IMX_FEC , __func__); +return ; + } + + s->regs[index] = value & ~7 ; + s->tx_descriptor[2 ] = s->regs[index];break ;case ENET_MRBR : s->regs[index] = value &0x00003ff0 ;
@@ -1203,6 +1297,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)static Property imx_eth_properties[] = {DEFINE_NIC_PROPERTIES (IMXFECState, conf), +DEFINE_PROP_UINT32 ("tx-ring-num" , IMXFECState, tx_ring_num,1 ),DEFINE_PROP_END_OF_LIST (), };
include/hw/net/imx_fec.h +16 -2
@@ -52,6 +52,8 @@#define ENET_TFWR 81#define ENET_FRBR 83#define ENET_FRSR 84 +#define ENET_TDSR1 89 +#define ENET_TDSR2 92#define ENET_RDSR 96#define ENET_TDSR 97#define ENET_MRBR 98
@@ -66,6 +68,8 @@#define ENET_FTRL 108#define ENET_TACC 112#define ENET_RACC 113 +#define ENET_TDAR1 121 +#define ENET_TDAR2 123#define ENET_MIIGSK_CFGR 192#define ENET_MIIGSK_ENR 194#define ENET_ATCR 256
@@ -105,13 +109,18 @@#define ENET_INT_WAKEUP (1 << 17)#define ENET_INT_TS_AVAIL (1 << 16)#define ENET_INT_TS_TIMER (1 << 15) +#define ENET_INT_TXF2 (1 << 7) +#define ENET_INT_TXB2 (1 << 6) +#define ENET_INT_TXF1 (1 << 3) +#define ENET_INT_TXB1 (1 << 2)#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) + ENET_INT_TS_AVAIL | ENET_INT_TXF1 | \ + ENET_INT_TXB1 | ENET_INT_TXF2 | ENET_INT_TXB2)/* RDAR */ #define ENET_RDAR_RDAR (1 << 24)
@@ -234,6 +243,9 @@ typedef struct {#define ENET_BD_BDU (1 << 31) +#define ENET_TX_RING_NUM 3 + + typedef struct IMXFECState { /*< private >*/ SysBusDevice parent_obj;
@@ -246,7 +258,9 @@ typedef struct IMXFECState {uint32_t regs[ENET_MAX ];uint32_t rx_descriptor; -uint32_t tx_descriptor; + +uint32_t tx_descriptor[ENET_TX_RING_NUM ]; +uint32_t tx_ring_num;uint32_t phy_status;uint32_t phy_control;
Signature · 1 line
2.14.3
PATCH v3 9/11 imx_fec: Use correct length for packet size
In reply to Andrey SmirnovUse 'frame_size' instead of 'len' when calling qemu_send_packet(), failing to do so results in malformed packets send in case when that packed is fragmented into multiple DMA transactions.
--- hw/net/imx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +1 -1
@@ -556,7 +556,7 @@ static void imx_enet_do_tx(IMXFECState *s, uint32_t index) }/* Last buffer in frame. */ -qemu_send_packet (qemu_get_queue (s->nic), s->frame, len); +qemu_send_packet (qemu_get_queue (s->nic), s->frame, frame_size); ptr = s->frame; frame_size =0 ;
Signature · 1 line
2.14.3
PATCH v3 10/11 imx_fec: Fix a typo in imx_enet_receive()
In reply to Andrey Smirnov--- hw/net/imx_fec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/imx_fec.c +1 -1
@@ -1150,7 +1150,7 @@ static ssize_t imx_enet_receive(NetClientState *nc, const uint8_t *buf, size +=2 ; } -/* Huge frames are truncted. */ +/* Huge frames are truncated. */ if (size > s->regs[ENET_FTRL ]) { size = s->regs[ENET_FTRL ]; flags |=ENET_BD_TR |ENET_BD_LG ;
Signature · 1 line
2.14.3
PATCH v3 11/11 imx_fec: Reserve full FSL_IMX25_FEC_SIZE page for the register file
In reply to Andrey SmirnovSome i.MX SoCs (e.g. i.MX7) have FEC registers going as far as offset 0x614, so to avoid getting aborts when accessing those on QEMU, extend the register file to cover FSL_IMX25_FEC_SIZE(16K) of address space instead of just 1K.
--- hw/net/imx_fec.c | 2 +- include/hw/arm/fsl-imx25.h | 1 - include/hw/net/imx_fec.h | 1 + 3 files changed, 2 insertions(+), 2 deletions(-)
hw/net/imx_fec.c +1 -1
@@ -1281,7 +1281,7 @@ static void imx_eth_realize(DeviceState *dev, Error **errp)SysBusDevice *sbd =SYS_BUS_DEVICE (dev);memory_region_init_io (&s->iomem,OBJECT (dev), &imx_eth_ops, s, -TYPE_IMX_FEC ,0x400 ); +TYPE_IMX_FEC ,FSL_IMX25_FEC_SIZE );sysbus_init_mmio (sbd, &s->iomem);sysbus_init_irq (sbd, &s->irq[0 ]);sysbus_init_irq (sbd, &s->irq[1 ]);
include/hw/arm/fsl-imx25.h +0 -1
@@ -192,7 +192,6 @@ typedef struct FslIMX25State {#define FSL_IMX25_UART5_ADDR 0x5002C000#define FSL_IMX25_UART5_SIZE 0x4000#define FSL_IMX25_FEC_ADDR 0x50038000 -#define FSL_IMX25_FEC_SIZE 0x4000#define FSL_IMX25_CCM_ADDR 0x53F80000#define FSL_IMX25_CCM_SIZE 0x4000#define FSL_IMX25_GPT4_ADDR 0x53F84000
include/hw/net/imx_fec.h +1 -0
@@ -245,6 +245,7 @@ typedef struct {#define ENET_TX_RING_NUM 3 +#define FSL_IMX25_FEC_SIZE 0x4000 typedef struct IMXFECState { /*< private >*/
Signature · 1 line
2.14.3
Quoted 5 lines · Andrey Smirnov
Hi everyone,
This patchset is v3 of a spin-off from original i.MX7 support submission found here [1], containing all of the patchest that are more or less agreed upon and are ready (hopefully!) for inclusion.
Thanks for the respin -- I've applied it to target-arm.next.
-- PMM