Skip to content

Commit a452234

Browse files
committed
hw/net/lan9118: Replace magic '2048' value by MIL_TXFIFO_SIZE definition
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é <[email protected]> Reviewed-by: Peter Maydell <[email protected]> Message-Id: <[email protected]>
1 parent eaf2bd2 commit a452234

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

hw/net/lan9118.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ do { printf("lan9118: " fmt , ## __VA_ARGS__); } while (0)
150150

151151
#define GPT_TIMER_EN 0x20000000
152152

153+
/*
154+
* The MAC Interface Layer (MIL), within the MAC, contains a 2K Byte transmit
155+
* and a 128 Byte receive FIFO which is separate from the TX and RX FIFOs.
156+
*/
157+
#define MIL_TXFIFO_SIZE 2048
158+
153159
enum tx_state {
154160
TX_IDLE,
155161
TX_B,
@@ -166,7 +172,7 @@ typedef struct {
166172
int32_t pad;
167173
int32_t fifo_used;
168174
int32_t len;
169-
uint8_t data[2048];
175+
uint8_t data[MIL_TXFIFO_SIZE];
170176
} LAN9118Packet;
171177

172178
static const VMStateDescription vmstate_lan9118_packet = {
@@ -182,7 +188,7 @@ static const VMStateDescription vmstate_lan9118_packet = {
182188
VMSTATE_INT32(pad, LAN9118Packet),
183189
VMSTATE_INT32(fifo_used, LAN9118Packet),
184190
VMSTATE_INT32(len, LAN9118Packet),
185-
VMSTATE_UINT8_ARRAY(data, LAN9118Packet, 2048),
191+
VMSTATE_UINT8_ARRAY(data, LAN9118Packet, MIL_TXFIFO_SIZE),
186192
VMSTATE_END_OF_LIST()
187193
}
188194
};
@@ -544,7 +550,7 @@ static ssize_t lan9118_receive(NetClientState *nc, const uint8_t *buf,
544550
return -1;
545551
}
546552

547-
if (size >= 2048 || size < 14) {
553+
if (size >= MIL_TXFIFO_SIZE || size < 14) {
548554
return -1;
549555
}
550556

0 commit comments

Comments
 (0)