1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef ETSEC_H
26#define ETSEC_H
27
28#include "hw/sysbus.h"
29#include "net/net.h"
30#include "hw/ptimer.h"
31
32
33
34typedef struct eTSEC_rxtx_bd {
35 uint16_t flags;
36 uint16_t length;
37 uint32_t bufptr;
38} eTSEC_rxtx_bd;
39
40#define BD_WRAP (1 << 13)
41#define BD_INTERRUPT (1 << 12)
42#define BD_LAST (1 << 11)
43
44#define BD_TX_READY (1 << 15)
45#define BD_TX_PADCRC (1 << 14)
46#define BD_TX_TC (1 << 10)
47#define BD_TX_PREDEF (1 << 9)
48#define BD_TX_HFELC (1 << 7)
49#define BD_TX_CFRL (1 << 6)
50#define BD_TX_RC_MASK 0xF
51#define BD_TX_RC_OFFSET 0x2
52#define BD_TX_TOEUN (1 << 1)
53#define BD_TX_TR (1 << 0)
54
55#define BD_RX_EMPTY (1 << 15)
56#define BD_RX_RO1 (1 << 14)
57#define BD_RX_FIRST (1 << 10)
58#define BD_RX_MISS (1 << 8)
59#define BD_RX_BROADCAST (1 << 7)
60#define BD_RX_MULTICAST (1 << 6)
61#define BD_RX_LG (1 << 5)
62#define BD_RX_NO (1 << 4)
63#define BD_RX_SH (1 << 3)
64#define BD_RX_CR (1 << 2)
65#define BD_RX_OV (1 << 1)
66#define BD_RX_TR (1 << 0)
67
68
69#define FCB_TX_VLN (1 << 7)
70#define FCB_TX_IP (1 << 6)
71#define FCB_TX_IP6 (1 << 5)
72#define FCB_TX_TUP (1 << 4)
73#define FCB_TX_UDP (1 << 3)
74#define FCB_TX_CIP (1 << 2)
75#define FCB_TX_CTU (1 << 1)
76#define FCB_TX_NPH (1 << 0)
77
78
79#define MII_SR_EXTENDED_CAPS 0x0001
80#define MII_SR_JABBER_DETECT 0x0002
81#define MII_SR_LINK_STATUS 0x0004
82#define MII_SR_AUTONEG_CAPS 0x0008
83#define MII_SR_REMOTE_FAULT 0x0010
84#define MII_SR_AUTONEG_COMPLETE 0x0020
85#define MII_SR_PREAMBLE_SUPPRESS 0x0040
86#define MII_SR_EXTENDED_STATUS 0x0100
87#define MII_SR_100T2_HD_CAPS 0x0200
88#define MII_SR_100T2_FD_CAPS 0x0400
89#define MII_SR_10T_HD_CAPS 0x0800
90#define MII_SR_10T_FD_CAPS 0x1000
91#define MII_SR_100X_HD_CAPS 0x2000
92#define MII_SR_100X_FD_CAPS 0x4000
93#define MII_SR_100T4_CAPS 0x8000
94
95
96
97
98#define ETSEC_REG_NUMBER 1024
99
100typedef struct eTSEC_Register {
101 const char *name;
102 const char *desc;
103 uint32_t access;
104 uint32_t value;
105} eTSEC_Register;
106
107typedef struct eTSEC {
108 SysBusDevice busdev;
109
110 MemoryRegion io_area;
111
112 eTSEC_Register regs[ETSEC_REG_NUMBER];
113
114 NICState *nic;
115 NICConf conf;
116
117
118
119 uint8_t *tx_buffer;
120 uint32_t tx_buffer_len;
121 eTSEC_rxtx_bd first_bd;
122
123
124
125 uint8_t *rx_buffer;
126 uint32_t rx_buffer_len;
127 uint32_t rx_remaining_data;
128 uint8_t rx_first_in_frame;
129 uint8_t rx_fcb_size;
130 eTSEC_rxtx_bd rx_first_bd;
131 uint8_t rx_fcb[10];
132 uint32_t rx_padding;
133
134
135 qemu_irq tx_irq;
136 qemu_irq rx_irq;
137 qemu_irq err_irq;
138
139
140 uint16_t phy_status;
141 uint16_t phy_control;
142
143
144 struct ptimer_state *ptimer;
145
146
147 bool need_flush;
148} eTSEC;
149
150#define TYPE_ETSEC_COMMON "eTSEC"
151#define ETSEC_COMMON(obj) \
152 OBJECT_CHECK(eTSEC, (obj), TYPE_ETSEC_COMMON)
153
154#define eTSEC_TRANSMIT 1
155#define eTSEC_RECEIVE 2
156
157DeviceState *etsec_create(hwaddr base,
158 MemoryRegion *mr,
159 NICInfo *nd,
160 qemu_irq tx_irq,
161 qemu_irq rx_irq,
162 qemu_irq err_irq);
163
164void etsec_update_irq(eTSEC *etsec);
165
166void etsec_walk_tx_ring(eTSEC *etsec, int ring_nbr);
167void etsec_walk_rx_ring(eTSEC *etsec, int ring_nbr);
168ssize_t etsec_rx_ring_write(eTSEC *etsec, const uint8_t *buf, size_t size);
169
170void etsec_write_miim(eTSEC *etsec,
171 eTSEC_Register *reg,
172 uint32_t reg_index,
173 uint32_t value);
174
175void etsec_miim_link_status(eTSEC *etsec, NetClientState *nc);
176
177#endif
178