root / hw / stellaris_enet.c @ 00dbbb03
History | View | Annotate | Download (11.5 kB)
1 | eea589cc | pbrook | /*
|
---|---|---|---|
2 | eea589cc | pbrook | * Luminary Micro Stellaris Ethernet Controller
|
3 | eea589cc | pbrook | *
|
4 | eea589cc | pbrook | * Copyright (c) 2007 CodeSourcery.
|
5 | eea589cc | pbrook | * Written by Paul Brook
|
6 | eea589cc | pbrook | *
|
7 | eea589cc | pbrook | * This code is licenced under the GPL.
|
8 | eea589cc | pbrook | */
|
9 | eea589cc | pbrook | #include "hw.h" |
10 | eea589cc | pbrook | #include "arm-misc.h" |
11 | eea589cc | pbrook | #include "net.h" |
12 | eea589cc | pbrook | #include <zlib.h> |
13 | eea589cc | pbrook | |
14 | eea589cc | pbrook | //#define DEBUG_STELLARIS_ENET 1
|
15 | eea589cc | pbrook | |
16 | eea589cc | pbrook | #ifdef DEBUG_STELLARIS_ENET
|
17 | eea589cc | pbrook | #define DPRINTF(fmt, args...) \
|
18 | eea589cc | pbrook | do { printf("stellaris_enet: " fmt , ##args); } while (0) |
19 | eea589cc | pbrook | #define BADF(fmt, args...) \
|
20 | eea589cc | pbrook | do { fprintf(stderr, "stellaris_enet: error: " fmt , ##args); exit(1);} while (0) |
21 | eea589cc | pbrook | #else
|
22 | eea589cc | pbrook | #define DPRINTF(fmt, args...) do {} while(0) |
23 | eea589cc | pbrook | #define BADF(fmt, args...) \
|
24 | eea589cc | pbrook | do { fprintf(stderr, "stellaris_enet: error: " fmt , ##args);} while (0) |
25 | eea589cc | pbrook | #endif
|
26 | eea589cc | pbrook | |
27 | eea589cc | pbrook | #define SE_INT_RX 0x01 |
28 | eea589cc | pbrook | #define SE_INT_TXER 0x02 |
29 | eea589cc | pbrook | #define SE_INT_TXEMP 0x04 |
30 | eea589cc | pbrook | #define SE_INT_FOV 0x08 |
31 | eea589cc | pbrook | #define SE_INT_RXER 0x10 |
32 | eea589cc | pbrook | #define SE_INT_MD 0x20 |
33 | eea589cc | pbrook | #define SE_INT_PHY 0x40 |
34 | eea589cc | pbrook | |
35 | eea589cc | pbrook | #define SE_RCTL_RXEN 0x01 |
36 | eea589cc | pbrook | #define SE_RCTL_AMUL 0x02 |
37 | eea589cc | pbrook | #define SE_RCTL_PRMS 0x04 |
38 | eea589cc | pbrook | #define SE_RCTL_BADCRC 0x08 |
39 | eea589cc | pbrook | #define SE_RCTL_RSTFIFO 0x10 |
40 | eea589cc | pbrook | |
41 | eea589cc | pbrook | #define SE_TCTL_TXEN 0x01 |
42 | eea589cc | pbrook | #define SE_TCTL_PADEN 0x02 |
43 | eea589cc | pbrook | #define SE_TCTL_CRC 0x04 |
44 | eea589cc | pbrook | #define SE_TCTL_DUPLEX 0x08 |
45 | eea589cc | pbrook | |
46 | eea589cc | pbrook | typedef struct { |
47 | eea589cc | pbrook | uint32_t base; |
48 | eea589cc | pbrook | uint32_t ris; |
49 | eea589cc | pbrook | uint32_t im; |
50 | eea589cc | pbrook | uint32_t rctl; |
51 | eea589cc | pbrook | uint32_t tctl; |
52 | eea589cc | pbrook | uint32_t thr; |
53 | eea589cc | pbrook | uint32_t mctl; |
54 | eea589cc | pbrook | uint32_t mdv; |
55 | eea589cc | pbrook | uint32_t mtxd; |
56 | eea589cc | pbrook | uint32_t mrxd; |
57 | eea589cc | pbrook | uint32_t np; |
58 | eea589cc | pbrook | int tx_frame_len;
|
59 | eea589cc | pbrook | int tx_fifo_len;
|
60 | eea589cc | pbrook | uint8_t tx_fifo[2048];
|
61 | eea589cc | pbrook | /* Real hardware has a 2k fifo, which works out to be at most 31 packets.
|
62 | eea589cc | pbrook | We implement a full 31 packet fifo. */
|
63 | eea589cc | pbrook | struct {
|
64 | eea589cc | pbrook | uint8_t data[2048];
|
65 | eea589cc | pbrook | int len;
|
66 | eea589cc | pbrook | } rx[31];
|
67 | eea589cc | pbrook | uint8_t *rx_fifo; |
68 | eea589cc | pbrook | int rx_fifo_len;
|
69 | eea589cc | pbrook | int next_packet;
|
70 | eea589cc | pbrook | VLANClientState *vc; |
71 | eea589cc | pbrook | qemu_irq irq; |
72 | eea589cc | pbrook | uint8_t macaddr[6];
|
73 | eea589cc | pbrook | } stellaris_enet_state; |
74 | eea589cc | pbrook | |
75 | eea589cc | pbrook | static void stellaris_enet_update(stellaris_enet_state *s) |
76 | eea589cc | pbrook | { |
77 | eea589cc | pbrook | qemu_set_irq(s->irq, (s->ris & s->im) != 0);
|
78 | eea589cc | pbrook | } |
79 | eea589cc | pbrook | |
80 | eea589cc | pbrook | /* TODO: Implement MAC address filtering. */
|
81 | eea589cc | pbrook | static void stellaris_enet_receive(void *opaque, const uint8_t *buf, int size) |
82 | eea589cc | pbrook | { |
83 | eea589cc | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
84 | eea589cc | pbrook | int n;
|
85 | eea589cc | pbrook | uint8_t *p; |
86 | eea589cc | pbrook | uint32_t crc; |
87 | eea589cc | pbrook | |
88 | eea589cc | pbrook | if ((s->rctl & SE_RCTL_RXEN) == 0) |
89 | eea589cc | pbrook | return;
|
90 | eea589cc | pbrook | if (s->np >= 31) { |
91 | eea589cc | pbrook | DPRINTF("Packet dropped\n");
|
92 | eea589cc | pbrook | return;
|
93 | eea589cc | pbrook | } |
94 | eea589cc | pbrook | |
95 | eea589cc | pbrook | DPRINTF("Received packet len=%d\n", size);
|
96 | eea589cc | pbrook | n = s->next_packet + s->np; |
97 | eea589cc | pbrook | if (n >= 31) |
98 | eea589cc | pbrook | n -= 31;
|
99 | eea589cc | pbrook | s->np++; |
100 | eea589cc | pbrook | |
101 | eea589cc | pbrook | s->rx[n].len = size + 6;
|
102 | eea589cc | pbrook | p = s->rx[n].data; |
103 | eea589cc | pbrook | *(p++) = (size + 6);
|
104 | eea589cc | pbrook | *(p++) = (size + 6) >> 8; |
105 | eea589cc | pbrook | memcpy (p, buf, size); |
106 | eea589cc | pbrook | p += size; |
107 | eea589cc | pbrook | crc = crc32(~0, buf, size);
|
108 | eea589cc | pbrook | *(p++) = crc; |
109 | eea589cc | pbrook | *(p++) = crc >> 8;
|
110 | eea589cc | pbrook | *(p++) = crc >> 16;
|
111 | eea589cc | pbrook | *(p++) = crc >> 24;
|
112 | eea589cc | pbrook | /* Clear the remaining bytes in the last word. */
|
113 | eea589cc | pbrook | if ((size & 3) != 2) { |
114 | eea589cc | pbrook | memset(p, 0, (6 - size) & 3); |
115 | eea589cc | pbrook | } |
116 | eea589cc | pbrook | |
117 | eea589cc | pbrook | s->ris |= SE_INT_RX; |
118 | eea589cc | pbrook | stellaris_enet_update(s); |
119 | eea589cc | pbrook | } |
120 | eea589cc | pbrook | |
121 | eea589cc | pbrook | static int stellaris_enet_can_receive(void *opaque) |
122 | eea589cc | pbrook | { |
123 | eea589cc | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
124 | eea589cc | pbrook | |
125 | eea589cc | pbrook | if ((s->rctl & SE_RCTL_RXEN) == 0) |
126 | eea589cc | pbrook | return 1; |
127 | eea589cc | pbrook | |
128 | eea589cc | pbrook | return (s->np < 31); |
129 | eea589cc | pbrook | } |
130 | eea589cc | pbrook | |
131 | eea589cc | pbrook | static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset) |
132 | eea589cc | pbrook | { |
133 | eea589cc | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
134 | eea589cc | pbrook | uint32_t val; |
135 | eea589cc | pbrook | |
136 | eea589cc | pbrook | offset -= s->base; |
137 | eea589cc | pbrook | switch (offset) {
|
138 | eea589cc | pbrook | case 0x00: /* RIS */ |
139 | eea589cc | pbrook | DPRINTF("IRQ status %02x\n", s->ris);
|
140 | eea589cc | pbrook | return s->ris;
|
141 | eea589cc | pbrook | case 0x04: /* IM */ |
142 | eea589cc | pbrook | return s->im;
|
143 | eea589cc | pbrook | case 0x08: /* RCTL */ |
144 | eea589cc | pbrook | return s->rctl;
|
145 | eea589cc | pbrook | case 0x0c: /* TCTL */ |
146 | eea589cc | pbrook | return s->tctl;
|
147 | eea589cc | pbrook | case 0x10: /* DATA */ |
148 | eea589cc | pbrook | if (s->rx_fifo_len == 0) { |
149 | eea589cc | pbrook | if (s->np == 0) { |
150 | eea589cc | pbrook | BADF("RX underflow\n");
|
151 | eea589cc | pbrook | return 0; |
152 | eea589cc | pbrook | } |
153 | eea589cc | pbrook | s->rx_fifo_len = s->rx[s->next_packet].len; |
154 | eea589cc | pbrook | s->rx_fifo = s->rx[s->next_packet].data; |
155 | eea589cc | pbrook | DPRINTF("RX FIFO start packet len=%d\n", s->rx_fifo_len);
|
156 | eea589cc | pbrook | } |
157 | eea589cc | pbrook | val = s->rx_fifo[0] | (s->rx_fifo[1] << 8) | (s->rx_fifo[2] << 16) |
158 | eea589cc | pbrook | | (s->rx_fifo[3] << 24); |
159 | eea589cc | pbrook | s->rx_fifo += 4;
|
160 | eea589cc | pbrook | s->rx_fifo_len -= 4;
|
161 | eea589cc | pbrook | if (s->rx_fifo_len <= 0) { |
162 | eea589cc | pbrook | s->rx_fifo_len = 0;
|
163 | eea589cc | pbrook | s->next_packet++; |
164 | eea589cc | pbrook | if (s->next_packet >= 31) |
165 | eea589cc | pbrook | s->next_packet = 0;
|
166 | eea589cc | pbrook | s->np--; |
167 | eea589cc | pbrook | DPRINTF("RX done np=%d\n", s->np);
|
168 | eea589cc | pbrook | } |
169 | eea589cc | pbrook | return val;
|
170 | eea589cc | pbrook | case 0x14: /* IA0 */ |
171 | eea589cc | pbrook | return s->macaddr[0] | (s->macaddr[1] << 8) |
172 | eea589cc | pbrook | | (s->macaddr[2] << 16) | (s->macaddr[3] << 24); |
173 | eea589cc | pbrook | case 0x18: /* IA1 */ |
174 | eea589cc | pbrook | return s->macaddr[4] | (s->macaddr[5] << 8); |
175 | eea589cc | pbrook | case 0x1c: /* THR */ |
176 | eea589cc | pbrook | return s->thr;
|
177 | eea589cc | pbrook | case 0x20: /* MCTL */ |
178 | eea589cc | pbrook | return s->mctl;
|
179 | eea589cc | pbrook | case 0x24: /* MDV */ |
180 | eea589cc | pbrook | return s->mdv;
|
181 | eea589cc | pbrook | case 0x28: /* MADD */ |
182 | eea589cc | pbrook | return 0; |
183 | eea589cc | pbrook | case 0x2c: /* MTXD */ |
184 | eea589cc | pbrook | return s->mtxd;
|
185 | eea589cc | pbrook | case 0x30: /* MRXD */ |
186 | eea589cc | pbrook | return s->mrxd;
|
187 | eea589cc | pbrook | case 0x34: /* NP */ |
188 | eea589cc | pbrook | return s->np;
|
189 | eea589cc | pbrook | case 0x38: /* TR */ |
190 | eea589cc | pbrook | return 0; |
191 | eea589cc | pbrook | case 0x3c: /* Undocuented: Timestamp? */ |
192 | eea589cc | pbrook | return 0; |
193 | eea589cc | pbrook | default:
|
194 | eea589cc | pbrook | cpu_abort (cpu_single_env, "stellaris_enet_read: Bad offset %x\n",
|
195 | eea589cc | pbrook | (int)offset);
|
196 | eea589cc | pbrook | return 0; |
197 | eea589cc | pbrook | } |
198 | eea589cc | pbrook | } |
199 | eea589cc | pbrook | |
200 | eea589cc | pbrook | static void stellaris_enet_write(void *opaque, target_phys_addr_t offset, |
201 | eea589cc | pbrook | uint32_t value) |
202 | eea589cc | pbrook | { |
203 | eea589cc | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
204 | eea589cc | pbrook | |
205 | eea589cc | pbrook | offset -= s->base; |
206 | eea589cc | pbrook | switch (offset) {
|
207 | eea589cc | pbrook | case 0x00: /* IACK */ |
208 | eea589cc | pbrook | s->ris &= ~value; |
209 | eea589cc | pbrook | DPRINTF("IRQ ack %02x/%02x\n", value, s->ris);
|
210 | eea589cc | pbrook | stellaris_enet_update(s); |
211 | eea589cc | pbrook | /* Clearing TXER also resets the TX fifo. */
|
212 | eea589cc | pbrook | if (value & SE_INT_TXER)
|
213 | eea589cc | pbrook | s->tx_frame_len = -1;
|
214 | eea589cc | pbrook | break;
|
215 | eea589cc | pbrook | case 0x04: /* IM */ |
216 | eea589cc | pbrook | DPRINTF("IRQ mask %02x/%02x\n", value, s->ris);
|
217 | eea589cc | pbrook | s->im = value; |
218 | eea589cc | pbrook | stellaris_enet_update(s); |
219 | eea589cc | pbrook | break;
|
220 | eea589cc | pbrook | case 0x08: /* RCTL */ |
221 | eea589cc | pbrook | s->rctl = value; |
222 | eea589cc | pbrook | if (value & SE_RCTL_RSTFIFO) {
|
223 | eea589cc | pbrook | s->rx_fifo_len = 0;
|
224 | eea589cc | pbrook | s->np = 0;
|
225 | eea589cc | pbrook | stellaris_enet_update(s); |
226 | eea589cc | pbrook | } |
227 | eea589cc | pbrook | break;
|
228 | eea589cc | pbrook | case 0x0c: /* TCTL */ |
229 | eea589cc | pbrook | s->tctl = value; |
230 | eea589cc | pbrook | break;
|
231 | eea589cc | pbrook | case 0x10: /* DATA */ |
232 | eea589cc | pbrook | if (s->tx_frame_len == -1) { |
233 | eea589cc | pbrook | s->tx_frame_len = value & 0xffff;
|
234 | eea589cc | pbrook | if (s->tx_frame_len > 2032) { |
235 | eea589cc | pbrook | DPRINTF("TX frame too long (%d)\n", s->tx_frame_len);
|
236 | eea589cc | pbrook | s->tx_frame_len = 0;
|
237 | eea589cc | pbrook | s->ris |= SE_INT_TXER; |
238 | eea589cc | pbrook | stellaris_enet_update(s); |
239 | eea589cc | pbrook | } else {
|
240 | eea589cc | pbrook | DPRINTF("Start TX frame len=%d\n", s->tx_frame_len);
|
241 | eea589cc | pbrook | /* The value written does not include the ethernet header. */
|
242 | eea589cc | pbrook | s->tx_frame_len += 14;
|
243 | eea589cc | pbrook | if ((s->tctl & SE_TCTL_CRC) == 0) |
244 | eea589cc | pbrook | s->tx_frame_len += 4;
|
245 | eea589cc | pbrook | s->tx_fifo_len = 0;
|
246 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value >> 16;
|
247 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value >> 24;
|
248 | eea589cc | pbrook | } |
249 | eea589cc | pbrook | } else {
|
250 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value; |
251 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value >> 8;
|
252 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value >> 16;
|
253 | eea589cc | pbrook | s->tx_fifo[s->tx_fifo_len++] = value >> 24;
|
254 | eea589cc | pbrook | if (s->tx_fifo_len >= s->tx_frame_len) {
|
255 | eea589cc | pbrook | /* We don't implement explicit CRC, so just chop it off. */
|
256 | eea589cc | pbrook | if ((s->tctl & SE_TCTL_CRC) == 0) |
257 | eea589cc | pbrook | s->tx_frame_len -= 4;
|
258 | eea589cc | pbrook | if ((s->tctl & SE_TCTL_PADEN) && s->tx_frame_len < 60) { |
259 | eea589cc | pbrook | memset(&s->tx_fifo[s->tx_frame_len], 0, 60 - s->tx_frame_len); |
260 | eea589cc | pbrook | s->tx_fifo_len = 60;
|
261 | eea589cc | pbrook | } |
262 | eea589cc | pbrook | qemu_send_packet(s->vc, s->tx_fifo, s->tx_frame_len); |
263 | eea589cc | pbrook | s->tx_frame_len = -1;
|
264 | eea589cc | pbrook | s->ris |= SE_INT_TXEMP; |
265 | eea589cc | pbrook | stellaris_enet_update(s); |
266 | eea589cc | pbrook | DPRINTF("Done TX\n");
|
267 | eea589cc | pbrook | } |
268 | eea589cc | pbrook | } |
269 | eea589cc | pbrook | break;
|
270 | eea589cc | pbrook | case 0x14: /* IA0 */ |
271 | eea589cc | pbrook | s->macaddr[0] = value;
|
272 | eea589cc | pbrook | s->macaddr[1] = value >> 8; |
273 | eea589cc | pbrook | s->macaddr[2] = value >> 16; |
274 | eea589cc | pbrook | s->macaddr[3] = value >> 24; |
275 | eea589cc | pbrook | break;
|
276 | eea589cc | pbrook | case 0x18: /* IA1 */ |
277 | eea589cc | pbrook | s->macaddr[4] = value;
|
278 | eea589cc | pbrook | s->macaddr[5] = value >> 8; |
279 | eea589cc | pbrook | break;
|
280 | eea589cc | pbrook | case 0x1c: /* THR */ |
281 | eea589cc | pbrook | s->thr = value; |
282 | eea589cc | pbrook | break;
|
283 | eea589cc | pbrook | case 0x20: /* MCTL */ |
284 | eea589cc | pbrook | s->mctl = value; |
285 | eea589cc | pbrook | break;
|
286 | eea589cc | pbrook | case 0x24: /* MDV */ |
287 | eea589cc | pbrook | s->mdv = value; |
288 | eea589cc | pbrook | break;
|
289 | eea589cc | pbrook | case 0x28: /* MADD */ |
290 | eea589cc | pbrook | /* ignored. */
|
291 | eea589cc | pbrook | break;
|
292 | eea589cc | pbrook | case 0x2c: /* MTXD */ |
293 | eea589cc | pbrook | s->mtxd = value & 0xff;
|
294 | eea589cc | pbrook | break;
|
295 | eea589cc | pbrook | case 0x30: /* MRXD */ |
296 | eea589cc | pbrook | case 0x34: /* NP */ |
297 | eea589cc | pbrook | case 0x38: /* TR */ |
298 | eea589cc | pbrook | /* Ignored. */
|
299 | eea589cc | pbrook | case 0x3c: /* Undocuented: Timestamp? */ |
300 | eea589cc | pbrook | /* Ignored. */
|
301 | eea589cc | pbrook | break;
|
302 | eea589cc | pbrook | default:
|
303 | eea589cc | pbrook | cpu_abort (cpu_single_env, "stellaris_enet_write: Bad offset %x\n",
|
304 | eea589cc | pbrook | (int)offset);
|
305 | eea589cc | pbrook | } |
306 | eea589cc | pbrook | } |
307 | eea589cc | pbrook | |
308 | eea589cc | pbrook | static CPUReadMemoryFunc *stellaris_enet_readfn[] = {
|
309 | eea589cc | pbrook | stellaris_enet_read, |
310 | eea589cc | pbrook | stellaris_enet_read, |
311 | eea589cc | pbrook | stellaris_enet_read |
312 | eea589cc | pbrook | }; |
313 | eea589cc | pbrook | |
314 | eea589cc | pbrook | static CPUWriteMemoryFunc *stellaris_enet_writefn[] = {
|
315 | eea589cc | pbrook | stellaris_enet_write, |
316 | eea589cc | pbrook | stellaris_enet_write, |
317 | eea589cc | pbrook | stellaris_enet_write |
318 | eea589cc | pbrook | }; |
319 | eea589cc | pbrook | static void stellaris_enet_reset(stellaris_enet_state *s) |
320 | eea589cc | pbrook | { |
321 | eea589cc | pbrook | s->mdv = 0x80;
|
322 | eea589cc | pbrook | s->rctl = SE_RCTL_BADCRC; |
323 | eea589cc | pbrook | s->im = SE_INT_PHY | SE_INT_MD | SE_INT_RXER | SE_INT_FOV | SE_INT_TXEMP |
324 | eea589cc | pbrook | | SE_INT_TXER | SE_INT_RX; |
325 | eea589cc | pbrook | s->thr = 0x3f;
|
326 | eea589cc | pbrook | s->tx_frame_len = -1;
|
327 | eea589cc | pbrook | } |
328 | eea589cc | pbrook | |
329 | 23e39294 | pbrook | static void stellaris_enet_save(QEMUFile *f, void *opaque) |
330 | 23e39294 | pbrook | { |
331 | 23e39294 | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
332 | 23e39294 | pbrook | int i;
|
333 | 23e39294 | pbrook | |
334 | 23e39294 | pbrook | qemu_put_be32(f, s->ris); |
335 | 23e39294 | pbrook | qemu_put_be32(f, s->im); |
336 | 23e39294 | pbrook | qemu_put_be32(f, s->rctl); |
337 | 23e39294 | pbrook | qemu_put_be32(f, s->tctl); |
338 | 23e39294 | pbrook | qemu_put_be32(f, s->thr); |
339 | 23e39294 | pbrook | qemu_put_be32(f, s->mctl); |
340 | 23e39294 | pbrook | qemu_put_be32(f, s->mdv); |
341 | 23e39294 | pbrook | qemu_put_be32(f, s->mtxd); |
342 | 23e39294 | pbrook | qemu_put_be32(f, s->mrxd); |
343 | 23e39294 | pbrook | qemu_put_be32(f, s->np); |
344 | 23e39294 | pbrook | qemu_put_be32(f, s->tx_frame_len); |
345 | 23e39294 | pbrook | qemu_put_be32(f, s->tx_fifo_len); |
346 | 23e39294 | pbrook | qemu_put_buffer(f, s->tx_fifo, sizeof(s->tx_fifo));
|
347 | 23e39294 | pbrook | for (i = 0; i < 31; i++) { |
348 | 23e39294 | pbrook | qemu_put_be32(f, s->rx[i].len); |
349 | 23e39294 | pbrook | qemu_put_buffer(f, s->rx[i].data, sizeof(s->rx[i].data));
|
350 | 23e39294 | pbrook | |
351 | 23e39294 | pbrook | } |
352 | 23e39294 | pbrook | qemu_put_be32(f, s->next_packet); |
353 | 23e39294 | pbrook | qemu_put_be32(f, s->rx_fifo - s->rx[s->next_packet].data); |
354 | 23e39294 | pbrook | qemu_put_be32(f, s->rx_fifo_len); |
355 | 23e39294 | pbrook | } |
356 | 23e39294 | pbrook | |
357 | 23e39294 | pbrook | static int stellaris_enet_load(QEMUFile *f, void *opaque, int version_id) |
358 | 23e39294 | pbrook | { |
359 | 23e39294 | pbrook | stellaris_enet_state *s = (stellaris_enet_state *)opaque; |
360 | 23e39294 | pbrook | int i;
|
361 | 23e39294 | pbrook | |
362 | 23e39294 | pbrook | if (version_id != 1) |
363 | 23e39294 | pbrook | return -EINVAL;
|
364 | 23e39294 | pbrook | |
365 | 23e39294 | pbrook | s->ris = qemu_get_be32(f); |
366 | 23e39294 | pbrook | s->im = qemu_get_be32(f); |
367 | 23e39294 | pbrook | s->rctl = qemu_get_be32(f); |
368 | 23e39294 | pbrook | s->tctl = qemu_get_be32(f); |
369 | 23e39294 | pbrook | s->thr = qemu_get_be32(f); |
370 | 23e39294 | pbrook | s->mctl = qemu_get_be32(f); |
371 | 23e39294 | pbrook | s->mdv = qemu_get_be32(f); |
372 | 23e39294 | pbrook | s->mtxd = qemu_get_be32(f); |
373 | 23e39294 | pbrook | s->mrxd = qemu_get_be32(f); |
374 | 23e39294 | pbrook | s->np = qemu_get_be32(f); |
375 | 23e39294 | pbrook | s->tx_frame_len = qemu_get_be32(f); |
376 | 23e39294 | pbrook | s->tx_fifo_len = qemu_get_be32(f); |
377 | 23e39294 | pbrook | qemu_get_buffer(f, s->tx_fifo, sizeof(s->tx_fifo));
|
378 | 23e39294 | pbrook | for (i = 0; i < 31; i++) { |
379 | 23e39294 | pbrook | s->rx[i].len = qemu_get_be32(f); |
380 | 23e39294 | pbrook | qemu_get_buffer(f, s->rx[i].data, sizeof(s->rx[i].data));
|
381 | 23e39294 | pbrook | |
382 | 23e39294 | pbrook | } |
383 | 23e39294 | pbrook | s->next_packet = qemu_get_be32(f); |
384 | 23e39294 | pbrook | s->rx_fifo = s->rx[s->next_packet].data + qemu_get_be32(f); |
385 | 23e39294 | pbrook | s->rx_fifo_len = qemu_get_be32(f); |
386 | 23e39294 | pbrook | |
387 | 23e39294 | pbrook | return 0; |
388 | 23e39294 | pbrook | } |
389 | 23e39294 | pbrook | |
390 | eea589cc | pbrook | void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
|
391 | eea589cc | pbrook | { |
392 | eea589cc | pbrook | stellaris_enet_state *s; |
393 | eea589cc | pbrook | int iomemtype;
|
394 | eea589cc | pbrook | |
395 | eea589cc | pbrook | s = (stellaris_enet_state *)qemu_mallocz(sizeof(stellaris_enet_state));
|
396 | eea589cc | pbrook | iomemtype = cpu_register_io_memory(0, stellaris_enet_readfn,
|
397 | eea589cc | pbrook | stellaris_enet_writefn, s); |
398 | eea589cc | pbrook | cpu_register_physical_memory(base, 0x00001000, iomemtype);
|
399 | eea589cc | pbrook | s->base = base; |
400 | eea589cc | pbrook | s->irq = irq; |
401 | eea589cc | pbrook | memcpy(s->macaddr, nd->macaddr, 6);
|
402 | eea589cc | pbrook | |
403 | eea589cc | pbrook | if (nd->vlan)
|
404 | eea589cc | pbrook | s->vc = qemu_new_vlan_client(nd->vlan, stellaris_enet_receive, |
405 | eea589cc | pbrook | stellaris_enet_can_receive, s); |
406 | eea589cc | pbrook | |
407 | eea589cc | pbrook | stellaris_enet_reset(s); |
408 | 23e39294 | pbrook | register_savevm("stellaris_enet", -1, 1, |
409 | 23e39294 | pbrook | stellaris_enet_save, stellaris_enet_load, s); |
410 | eea589cc | pbrook | } |