Skip to content

Commit

Permalink
hw/net/lan9118: Replace magic '2048' value by MIL_TXFIFO_SIZE definition
Browse files Browse the repository at this point in the history
The magic 2048 is explained in the LAN9211 datasheet (DS00002414A)
in chapter 1.4, "10/100 Ethernet MAC":

  The MAC Interface Layer (MIL), within the MAC, contains a
  2K Byte transmit and a 128 Byte receive FIFO which is separate
  from the TX and RX FIFOs. [...]

Note, the use of the constant in lan9118_receive() reveals that
our implementation is using the same buffer for both tx and rx.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-Id: <20240409133801.23503-2-philmd@linaro.org>
(cherry picked from commit a452234)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
philmd authored and Michael Tokarev committed Apr 10, 2024
1 parent cd7beea commit f313079
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hw/net/lan9118.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ do { fprintf(stderr, "lan9118: error: " fmt , ## __VA_ARGS__);} while (0)

#define GPT_TIMER_EN 0x20000000

/*
* The MAC Interface Layer (MIL), within the MAC, contains a 2K Byte transmit
* and a 128 Byte receive FIFO which is separate from the TX and RX FIFOs.
*/
#define MIL_TXFIFO_SIZE 2048

enum tx_state {
TX_IDLE,
TX_B,
Expand All @@ -171,7 +177,7 @@ typedef struct {
int32_t pad;
int32_t fifo_used;
int32_t len;
uint8_t data[2048];
uint8_t data[MIL_TXFIFO_SIZE];
} LAN9118Packet;

static const VMStateDescription vmstate_lan9118_packet = {
Expand All @@ -187,7 +193,7 @@ static const VMStateDescription vmstate_lan9118_packet = {
VMSTATE_INT32(pad, LAN9118Packet),
VMSTATE_INT32(fifo_used, LAN9118Packet),
VMSTATE_INT32(len, LAN9118Packet),
VMSTATE_UINT8_ARRAY(data, LAN9118Packet, 2048),
VMSTATE_UINT8_ARRAY(data, LAN9118Packet, MIL_TXFIFO_SIZE),
VMSTATE_END_OF_LIST()
}
};
Expand Down Expand Up @@ -549,7 +555,7 @@ static ssize_t lan9118_receive(NetClientState *nc, const uint8_t *buf,
return -1;
}

if (size >= 2048 || size < 14) {
if (size >= MIL_TXFIFO_SIZE || size < 14) {
return -1;
}

Expand Down

0 comments on commit f313079

Please sign in to comment.