root / hw / ne2000.c @ 50132156
History | View | Annotate | Download (23.1 kB)
1 | 80cabfad | bellard | /*
|
---|---|---|---|
2 | 80cabfad | bellard | * QEMU NE2000 emulation
|
3 | 5fafdf24 | ths | *
|
4 | 80cabfad | bellard | * Copyright (c) 2003-2004 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 80cabfad | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 80cabfad | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 80cabfad | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 80cabfad | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 80cabfad | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 80cabfad | bellard | * furnished to do so, subject to the following conditions:
|
12 | 80cabfad | bellard | *
|
13 | 80cabfad | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 80cabfad | bellard | * all copies or substantial portions of the Software.
|
15 | 80cabfad | bellard | *
|
16 | 80cabfad | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 80cabfad | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 80cabfad | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 80cabfad | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 80cabfad | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 80cabfad | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 80cabfad | bellard | * THE SOFTWARE.
|
23 | 80cabfad | bellard | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "pci.h" |
26 | 87ecb68b | pbrook | #include "net.h" |
27 | 9453c5bc | Gerd Hoffmann | #include "ne2000.h" |
28 | a783cc3e | Gerd Hoffmann | #include "loader.h" |
29 | 80cabfad | bellard | |
30 | 80cabfad | bellard | /* debug NE2000 card */
|
31 | 80cabfad | bellard | //#define DEBUG_NE2000
|
32 | 80cabfad | bellard | |
33 | b41a2cd1 | bellard | #define MAX_ETH_FRAME_SIZE 1514 |
34 | 80cabfad | bellard | |
35 | 80cabfad | bellard | #define E8390_CMD 0x00 /* The command register (for all pages) */ |
36 | 80cabfad | bellard | /* Page 0 register offsets. */
|
37 | 80cabfad | bellard | #define EN0_CLDALO 0x01 /* Low byte of current local dma addr RD */ |
38 | 80cabfad | bellard | #define EN0_STARTPG 0x01 /* Starting page of ring bfr WR */ |
39 | 80cabfad | bellard | #define EN0_CLDAHI 0x02 /* High byte of current local dma addr RD */ |
40 | 80cabfad | bellard | #define EN0_STOPPG 0x02 /* Ending page +1 of ring bfr WR */ |
41 | 80cabfad | bellard | #define EN0_BOUNDARY 0x03 /* Boundary page of ring bfr RD WR */ |
42 | 80cabfad | bellard | #define EN0_TSR 0x04 /* Transmit status reg RD */ |
43 | 80cabfad | bellard | #define EN0_TPSR 0x04 /* Transmit starting page WR */ |
44 | 80cabfad | bellard | #define EN0_NCR 0x05 /* Number of collision reg RD */ |
45 | 80cabfad | bellard | #define EN0_TCNTLO 0x05 /* Low byte of tx byte count WR */ |
46 | 80cabfad | bellard | #define EN0_FIFO 0x06 /* FIFO RD */ |
47 | 80cabfad | bellard | #define EN0_TCNTHI 0x06 /* High byte of tx byte count WR */ |
48 | 80cabfad | bellard | #define EN0_ISR 0x07 /* Interrupt status reg RD WR */ |
49 | 80cabfad | bellard | #define EN0_CRDALO 0x08 /* low byte of current remote dma address RD */ |
50 | 80cabfad | bellard | #define EN0_RSARLO 0x08 /* Remote start address reg 0 */ |
51 | 80cabfad | bellard | #define EN0_CRDAHI 0x09 /* high byte, current remote dma address RD */ |
52 | 80cabfad | bellard | #define EN0_RSARHI 0x09 /* Remote start address reg 1 */ |
53 | 80cabfad | bellard | #define EN0_RCNTLO 0x0a /* Remote byte count reg WR */ |
54 | 089af991 | bellard | #define EN0_RTL8029ID0 0x0a /* Realtek ID byte #1 RD */ |
55 | 80cabfad | bellard | #define EN0_RCNTHI 0x0b /* Remote byte count reg WR */ |
56 | 089af991 | bellard | #define EN0_RTL8029ID1 0x0b /* Realtek ID byte #2 RD */ |
57 | 80cabfad | bellard | #define EN0_RSR 0x0c /* rx status reg RD */ |
58 | 80cabfad | bellard | #define EN0_RXCR 0x0c /* RX configuration reg WR */ |
59 | 80cabfad | bellard | #define EN0_TXCR 0x0d /* TX configuration reg WR */ |
60 | 80cabfad | bellard | #define EN0_COUNTER0 0x0d /* Rcv alignment error counter RD */ |
61 | 80cabfad | bellard | #define EN0_DCFG 0x0e /* Data configuration reg WR */ |
62 | 80cabfad | bellard | #define EN0_COUNTER1 0x0e /* Rcv CRC error counter RD */ |
63 | 80cabfad | bellard | #define EN0_IMR 0x0f /* Interrupt mask reg WR */ |
64 | 80cabfad | bellard | #define EN0_COUNTER2 0x0f /* Rcv missed frame error counter RD */ |
65 | 80cabfad | bellard | |
66 | 80cabfad | bellard | #define EN1_PHYS 0x11 |
67 | 80cabfad | bellard | #define EN1_CURPAG 0x17 |
68 | 80cabfad | bellard | #define EN1_MULT 0x18 |
69 | 80cabfad | bellard | |
70 | a343df16 | bellard | #define EN2_STARTPG 0x21 /* Starting page of ring bfr RD */ |
71 | a343df16 | bellard | #define EN2_STOPPG 0x22 /* Ending page +1 of ring bfr RD */ |
72 | a343df16 | bellard | |
73 | 089af991 | bellard | #define EN3_CONFIG0 0x33 |
74 | 089af991 | bellard | #define EN3_CONFIG1 0x34 |
75 | 089af991 | bellard | #define EN3_CONFIG2 0x35 |
76 | 089af991 | bellard | #define EN3_CONFIG3 0x36 |
77 | 089af991 | bellard | |
78 | 80cabfad | bellard | /* Register accessed at EN_CMD, the 8390 base addr. */
|
79 | 80cabfad | bellard | #define E8390_STOP 0x01 /* Stop and reset the chip */ |
80 | 80cabfad | bellard | #define E8390_START 0x02 /* Start the chip, clear reset */ |
81 | 80cabfad | bellard | #define E8390_TRANS 0x04 /* Transmit a frame */ |
82 | 80cabfad | bellard | #define E8390_RREAD 0x08 /* Remote read */ |
83 | 80cabfad | bellard | #define E8390_RWRITE 0x10 /* Remote write */ |
84 | 80cabfad | bellard | #define E8390_NODMA 0x20 /* Remote DMA */ |
85 | 80cabfad | bellard | #define E8390_PAGE0 0x00 /* Select page chip registers */ |
86 | 80cabfad | bellard | #define E8390_PAGE1 0x40 /* using the two high-order bits */ |
87 | 80cabfad | bellard | #define E8390_PAGE2 0x80 /* Page 3 is invalid. */ |
88 | 80cabfad | bellard | |
89 | 80cabfad | bellard | /* Bits in EN0_ISR - Interrupt status register */
|
90 | 80cabfad | bellard | #define ENISR_RX 0x01 /* Receiver, no error */ |
91 | 80cabfad | bellard | #define ENISR_TX 0x02 /* Transmitter, no error */ |
92 | 80cabfad | bellard | #define ENISR_RX_ERR 0x04 /* Receiver, with error */ |
93 | 80cabfad | bellard | #define ENISR_TX_ERR 0x08 /* Transmitter, with error */ |
94 | 80cabfad | bellard | #define ENISR_OVER 0x10 /* Receiver overwrote the ring */ |
95 | 80cabfad | bellard | #define ENISR_COUNTERS 0x20 /* Counters need emptying */ |
96 | 80cabfad | bellard | #define ENISR_RDC 0x40 /* remote dma complete */ |
97 | 80cabfad | bellard | #define ENISR_RESET 0x80 /* Reset completed */ |
98 | 80cabfad | bellard | #define ENISR_ALL 0x3f /* Interrupts we will enable */ |
99 | 80cabfad | bellard | |
100 | 80cabfad | bellard | /* Bits in received packet status byte and EN0_RSR*/
|
101 | 80cabfad | bellard | #define ENRSR_RXOK 0x01 /* Received a good packet */ |
102 | 80cabfad | bellard | #define ENRSR_CRC 0x02 /* CRC error */ |
103 | 80cabfad | bellard | #define ENRSR_FAE 0x04 /* frame alignment error */ |
104 | 80cabfad | bellard | #define ENRSR_FO 0x08 /* FIFO overrun */ |
105 | 80cabfad | bellard | #define ENRSR_MPA 0x10 /* missed pkt */ |
106 | 80cabfad | bellard | #define ENRSR_PHY 0x20 /* physical/multicast address */ |
107 | 80cabfad | bellard | #define ENRSR_DIS 0x40 /* receiver disable. set in monitor mode */ |
108 | 80cabfad | bellard | #define ENRSR_DEF 0x80 /* deferring */ |
109 | 80cabfad | bellard | |
110 | 80cabfad | bellard | /* Transmitted packet status, EN0_TSR. */
|
111 | 80cabfad | bellard | #define ENTSR_PTX 0x01 /* Packet transmitted without error */ |
112 | 80cabfad | bellard | #define ENTSR_ND 0x02 /* The transmit wasn't deferred. */ |
113 | 80cabfad | bellard | #define ENTSR_COL 0x04 /* The transmit collided at least once. */ |
114 | 80cabfad | bellard | #define ENTSR_ABT 0x08 /* The transmit collided 16 times, and was deferred. */ |
115 | 80cabfad | bellard | #define ENTSR_CRS 0x10 /* The carrier sense was lost. */ |
116 | 80cabfad | bellard | #define ENTSR_FU 0x20 /* A "FIFO underrun" occurred during transmit. */ |
117 | 80cabfad | bellard | #define ENTSR_CDH 0x40 /* The collision detect "heartbeat" signal was lost. */ |
118 | 80cabfad | bellard | #define ENTSR_OWC 0x80 /* There was an out-of-window collision. */ |
119 | 80cabfad | bellard | |
120 | 2b7a050a | Juan Quintela | typedef struct PCINE2000State { |
121 | 2b7a050a | Juan Quintela | PCIDevice dev; |
122 | 2b7a050a | Juan Quintela | NE2000State ne2000; |
123 | 2b7a050a | Juan Quintela | } PCINE2000State; |
124 | 2b7a050a | Juan Quintela | |
125 | 9453c5bc | Gerd Hoffmann | void ne2000_reset(NE2000State *s)
|
126 | 80cabfad | bellard | { |
127 | 80cabfad | bellard | int i;
|
128 | 80cabfad | bellard | |
129 | 80cabfad | bellard | s->isr = ENISR_RESET; |
130 | 93db6685 | Gerd Hoffmann | memcpy(s->mem, &s->c.macaddr, 6);
|
131 | 80cabfad | bellard | s->mem[14] = 0x57; |
132 | 80cabfad | bellard | s->mem[15] = 0x57; |
133 | 80cabfad | bellard | |
134 | 80cabfad | bellard | /* duplicate prom data */
|
135 | 80cabfad | bellard | for(i = 15;i >= 0; i--) { |
136 | 80cabfad | bellard | s->mem[2 * i] = s->mem[i];
|
137 | 80cabfad | bellard | s->mem[2 * i + 1] = s->mem[i]; |
138 | 80cabfad | bellard | } |
139 | 80cabfad | bellard | } |
140 | 80cabfad | bellard | |
141 | 80cabfad | bellard | static void ne2000_update_irq(NE2000State *s) |
142 | 80cabfad | bellard | { |
143 | 80cabfad | bellard | int isr;
|
144 | a343df16 | bellard | isr = (s->isr & s->imr) & 0x7f;
|
145 | a541f297 | bellard | #if defined(DEBUG_NE2000)
|
146 | d537cf6c | pbrook | printf("NE2000: Set IRQ to %d (%02x %02x)\n",
|
147 | d537cf6c | pbrook | isr ? 1 : 0, s->isr, s->imr); |
148 | a541f297 | bellard | #endif
|
149 | d537cf6c | pbrook | qemu_set_irq(s->irq, (isr != 0));
|
150 | 80cabfad | bellard | } |
151 | 80cabfad | bellard | |
152 | 7c9d8e07 | bellard | #define POLYNOMIAL 0x04c11db6 |
153 | 7c9d8e07 | bellard | |
154 | 7c9d8e07 | bellard | /* From FreeBSD */
|
155 | 7c9d8e07 | bellard | /* XXX: optimize */
|
156 | 7c9d8e07 | bellard | static int compute_mcast_idx(const uint8_t *ep) |
157 | 7c9d8e07 | bellard | { |
158 | 7c9d8e07 | bellard | uint32_t crc; |
159 | 7c9d8e07 | bellard | int carry, i, j;
|
160 | 7c9d8e07 | bellard | uint8_t b; |
161 | 7c9d8e07 | bellard | |
162 | 7c9d8e07 | bellard | crc = 0xffffffff;
|
163 | 7c9d8e07 | bellard | for (i = 0; i < 6; i++) { |
164 | 7c9d8e07 | bellard | b = *ep++; |
165 | 7c9d8e07 | bellard | for (j = 0; j < 8; j++) { |
166 | 7c9d8e07 | bellard | carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01); |
167 | 7c9d8e07 | bellard | crc <<= 1;
|
168 | 7c9d8e07 | bellard | b >>= 1;
|
169 | 7c9d8e07 | bellard | if (carry)
|
170 | 7c9d8e07 | bellard | crc = ((crc ^ POLYNOMIAL) | carry); |
171 | 7c9d8e07 | bellard | } |
172 | 7c9d8e07 | bellard | } |
173 | 7c9d8e07 | bellard | return (crc >> 26); |
174 | 7c9d8e07 | bellard | } |
175 | 7c9d8e07 | bellard | |
176 | d861b05e | pbrook | static int ne2000_buffer_full(NE2000State *s) |
177 | 80cabfad | bellard | { |
178 | 80cabfad | bellard | int avail, index, boundary;
|
179 | d861b05e | pbrook | |
180 | 80cabfad | bellard | index = s->curpag << 8;
|
181 | 80cabfad | bellard | boundary = s->boundary << 8;
|
182 | 28c1c656 | ths | if (index < boundary)
|
183 | 80cabfad | bellard | avail = boundary - index; |
184 | 80cabfad | bellard | else
|
185 | 80cabfad | bellard | avail = (s->stop - s->start) - (index - boundary); |
186 | 80cabfad | bellard | if (avail < (MAX_ETH_FRAME_SIZE + 4)) |
187 | d861b05e | pbrook | return 1; |
188 | d861b05e | pbrook | return 0; |
189 | d861b05e | pbrook | } |
190 | d861b05e | pbrook | |
191 | 9453c5bc | Gerd Hoffmann | int ne2000_can_receive(VLANClientState *vc)
|
192 | d861b05e | pbrook | { |
193 | e3f5ec2b | Mark McLoughlin | NE2000State *s = vc->opaque; |
194 | 3b46e624 | ths | |
195 | d861b05e | pbrook | if (s->cmd & E8390_STOP)
|
196 | e89f00e6 | aurel32 | return 1; |
197 | d861b05e | pbrook | return !ne2000_buffer_full(s);
|
198 | 80cabfad | bellard | } |
199 | 80cabfad | bellard | |
200 | b41a2cd1 | bellard | #define MIN_BUF_SIZE 60 |
201 | b41a2cd1 | bellard | |
202 | 9453c5bc | Gerd Hoffmann | ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
|
203 | 80cabfad | bellard | { |
204 | e3f5ec2b | Mark McLoughlin | NE2000State *s = vc->opaque; |
205 | 4f1c942b | Mark McLoughlin | int size = size_;
|
206 | 80cabfad | bellard | uint8_t *p; |
207 | 0ae045ae | ths | unsigned int total_len, next, avail, len, index, mcast_idx; |
208 | b41a2cd1 | bellard | uint8_t buf1[60];
|
209 | 5fafdf24 | ths | static const uint8_t broadcast_macaddr[6] = |
210 | 7c9d8e07 | bellard | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
211 | 3b46e624 | ths | |
212 | 80cabfad | bellard | #if defined(DEBUG_NE2000)
|
213 | 80cabfad | bellard | printf("NE2000: received len=%d\n", size);
|
214 | 80cabfad | bellard | #endif
|
215 | 80cabfad | bellard | |
216 | d861b05e | pbrook | if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
|
217 | 4f1c942b | Mark McLoughlin | return -1; |
218 | 3b46e624 | ths | |
219 | 7c9d8e07 | bellard | /* XXX: check this */
|
220 | 7c9d8e07 | bellard | if (s->rxcr & 0x10) { |
221 | 7c9d8e07 | bellard | /* promiscuous: receive all */
|
222 | 7c9d8e07 | bellard | } else {
|
223 | 7c9d8e07 | bellard | if (!memcmp(buf, broadcast_macaddr, 6)) { |
224 | 7c9d8e07 | bellard | /* broadcast address */
|
225 | 7c9d8e07 | bellard | if (!(s->rxcr & 0x04)) |
226 | 4f1c942b | Mark McLoughlin | return size;
|
227 | 7c9d8e07 | bellard | } else if (buf[0] & 0x01) { |
228 | 7c9d8e07 | bellard | /* multicast */
|
229 | 7c9d8e07 | bellard | if (!(s->rxcr & 0x08)) |
230 | 4f1c942b | Mark McLoughlin | return size;
|
231 | 7c9d8e07 | bellard | mcast_idx = compute_mcast_idx(buf); |
232 | 7c9d8e07 | bellard | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) |
233 | 4f1c942b | Mark McLoughlin | return size;
|
234 | 7c9d8e07 | bellard | } else if (s->mem[0] == buf[0] && |
235 | 3b46e624 | ths | s->mem[2] == buf[1] && |
236 | 3b46e624 | ths | s->mem[4] == buf[2] && |
237 | 3b46e624 | ths | s->mem[6] == buf[3] && |
238 | 3b46e624 | ths | s->mem[8] == buf[4] && |
239 | 7c9d8e07 | bellard | s->mem[10] == buf[5]) { |
240 | 7c9d8e07 | bellard | /* match */
|
241 | 7c9d8e07 | bellard | } else {
|
242 | 4f1c942b | Mark McLoughlin | return size;
|
243 | 7c9d8e07 | bellard | } |
244 | 7c9d8e07 | bellard | } |
245 | 7c9d8e07 | bellard | |
246 | 7c9d8e07 | bellard | |
247 | b41a2cd1 | bellard | /* if too small buffer, then expand it */
|
248 | b41a2cd1 | bellard | if (size < MIN_BUF_SIZE) {
|
249 | b41a2cd1 | bellard | memcpy(buf1, buf, size); |
250 | b41a2cd1 | bellard | memset(buf1 + size, 0, MIN_BUF_SIZE - size);
|
251 | b41a2cd1 | bellard | buf = buf1; |
252 | b41a2cd1 | bellard | size = MIN_BUF_SIZE; |
253 | b41a2cd1 | bellard | } |
254 | b41a2cd1 | bellard | |
255 | 80cabfad | bellard | index = s->curpag << 8;
|
256 | 80cabfad | bellard | /* 4 bytes for header */
|
257 | 80cabfad | bellard | total_len = size + 4;
|
258 | 80cabfad | bellard | /* address for next packet (4 bytes for CRC) */
|
259 | 80cabfad | bellard | next = index + ((total_len + 4 + 255) & ~0xff); |
260 | 80cabfad | bellard | if (next >= s->stop)
|
261 | 80cabfad | bellard | next -= (s->stop - s->start); |
262 | 80cabfad | bellard | /* prepare packet header */
|
263 | 80cabfad | bellard | p = s->mem + index; |
264 | 8d6c7eb8 | bellard | s->rsr = ENRSR_RXOK; /* receive status */
|
265 | 8d6c7eb8 | bellard | /* XXX: check this */
|
266 | 8d6c7eb8 | bellard | if (buf[0] & 0x01) |
267 | 8d6c7eb8 | bellard | s->rsr |= ENRSR_PHY; |
268 | 8d6c7eb8 | bellard | p[0] = s->rsr;
|
269 | 80cabfad | bellard | p[1] = next >> 8; |
270 | 80cabfad | bellard | p[2] = total_len;
|
271 | 80cabfad | bellard | p[3] = total_len >> 8; |
272 | 80cabfad | bellard | index += 4;
|
273 | 80cabfad | bellard | |
274 | 80cabfad | bellard | /* write packet data */
|
275 | 80cabfad | bellard | while (size > 0) { |
276 | 0ae045ae | ths | if (index <= s->stop)
|
277 | 0ae045ae | ths | avail = s->stop - index; |
278 | 0ae045ae | ths | else
|
279 | 0ae045ae | ths | avail = 0;
|
280 | 80cabfad | bellard | len = size; |
281 | 80cabfad | bellard | if (len > avail)
|
282 | 80cabfad | bellard | len = avail; |
283 | 80cabfad | bellard | memcpy(s->mem + index, buf, len); |
284 | 80cabfad | bellard | buf += len; |
285 | 80cabfad | bellard | index += len; |
286 | 80cabfad | bellard | if (index == s->stop)
|
287 | 80cabfad | bellard | index = s->start; |
288 | 80cabfad | bellard | size -= len; |
289 | 80cabfad | bellard | } |
290 | 80cabfad | bellard | s->curpag = next >> 8;
|
291 | 8d6c7eb8 | bellard | |
292 | 9f083493 | ths | /* now we can signal we have received something */
|
293 | 80cabfad | bellard | s->isr |= ENISR_RX; |
294 | 80cabfad | bellard | ne2000_update_irq(s); |
295 | 4f1c942b | Mark McLoughlin | |
296 | 4f1c942b | Mark McLoughlin | return size_;
|
297 | 80cabfad | bellard | } |
298 | 80cabfad | bellard | |
299 | 9453c5bc | Gerd Hoffmann | void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
300 | 80cabfad | bellard | { |
301 | b41a2cd1 | bellard | NE2000State *s = opaque; |
302 | 40545f84 | bellard | int offset, page, index;
|
303 | 80cabfad | bellard | |
304 | 80cabfad | bellard | addr &= 0xf;
|
305 | 80cabfad | bellard | #ifdef DEBUG_NE2000
|
306 | 80cabfad | bellard | printf("NE2000: write addr=0x%x val=0x%02x\n", addr, val);
|
307 | 80cabfad | bellard | #endif
|
308 | 80cabfad | bellard | if (addr == E8390_CMD) {
|
309 | 80cabfad | bellard | /* control register */
|
310 | 80cabfad | bellard | s->cmd = val; |
311 | a343df16 | bellard | if (!(val & E8390_STOP)) { /* START bit makes no sense on RTL8029... */ |
312 | ee9dbb29 | bellard | s->isr &= ~ENISR_RESET; |
313 | e91c8a77 | ths | /* test specific case: zero length transfer */
|
314 | 80cabfad | bellard | if ((val & (E8390_RREAD | E8390_RWRITE)) &&
|
315 | 80cabfad | bellard | s->rcnt == 0) {
|
316 | 80cabfad | bellard | s->isr |= ENISR_RDC; |
317 | 80cabfad | bellard | ne2000_update_irq(s); |
318 | 80cabfad | bellard | } |
319 | 80cabfad | bellard | if (val & E8390_TRANS) {
|
320 | 40545f84 | bellard | index = (s->tpsr << 8);
|
321 | 5fafdf24 | ths | /* XXX: next 2 lines are a hack to make netware 3.11 work */
|
322 | 40545f84 | bellard | if (index >= NE2000_PMEM_END)
|
323 | 40545f84 | bellard | index -= NE2000_PMEM_SIZE; |
324 | 40545f84 | bellard | /* fail safe: check range on the transmitted length */
|
325 | 40545f84 | bellard | if (index + s->tcnt <= NE2000_PMEM_END) {
|
326 | 7c9d8e07 | bellard | qemu_send_packet(s->vc, s->mem + index, s->tcnt); |
327 | 40545f84 | bellard | } |
328 | e91c8a77 | ths | /* signal end of transfer */
|
329 | 80cabfad | bellard | s->tsr = ENTSR_PTX; |
330 | 80cabfad | bellard | s->isr |= ENISR_TX; |
331 | 5fafdf24 | ths | s->cmd &= ~E8390_TRANS; |
332 | 80cabfad | bellard | ne2000_update_irq(s); |
333 | 80cabfad | bellard | } |
334 | 80cabfad | bellard | } |
335 | 80cabfad | bellard | } else {
|
336 | 80cabfad | bellard | page = s->cmd >> 6;
|
337 | 80cabfad | bellard | offset = addr | (page << 4);
|
338 | 80cabfad | bellard | switch(offset) {
|
339 | 80cabfad | bellard | case EN0_STARTPG:
|
340 | 80cabfad | bellard | s->start = val << 8;
|
341 | 80cabfad | bellard | break;
|
342 | 80cabfad | bellard | case EN0_STOPPG:
|
343 | 80cabfad | bellard | s->stop = val << 8;
|
344 | 80cabfad | bellard | break;
|
345 | 80cabfad | bellard | case EN0_BOUNDARY:
|
346 | 80cabfad | bellard | s->boundary = val; |
347 | 80cabfad | bellard | break;
|
348 | 80cabfad | bellard | case EN0_IMR:
|
349 | 80cabfad | bellard | s->imr = val; |
350 | 80cabfad | bellard | ne2000_update_irq(s); |
351 | 80cabfad | bellard | break;
|
352 | 80cabfad | bellard | case EN0_TPSR:
|
353 | 80cabfad | bellard | s->tpsr = val; |
354 | 80cabfad | bellard | break;
|
355 | 80cabfad | bellard | case EN0_TCNTLO:
|
356 | 80cabfad | bellard | s->tcnt = (s->tcnt & 0xff00) | val;
|
357 | 80cabfad | bellard | break;
|
358 | 80cabfad | bellard | case EN0_TCNTHI:
|
359 | 80cabfad | bellard | s->tcnt = (s->tcnt & 0x00ff) | (val << 8); |
360 | 80cabfad | bellard | break;
|
361 | 80cabfad | bellard | case EN0_RSARLO:
|
362 | 80cabfad | bellard | s->rsar = (s->rsar & 0xff00) | val;
|
363 | 80cabfad | bellard | break;
|
364 | 80cabfad | bellard | case EN0_RSARHI:
|
365 | 80cabfad | bellard | s->rsar = (s->rsar & 0x00ff) | (val << 8); |
366 | 80cabfad | bellard | break;
|
367 | 80cabfad | bellard | case EN0_RCNTLO:
|
368 | 80cabfad | bellard | s->rcnt = (s->rcnt & 0xff00) | val;
|
369 | 80cabfad | bellard | break;
|
370 | 80cabfad | bellard | case EN0_RCNTHI:
|
371 | 80cabfad | bellard | s->rcnt = (s->rcnt & 0x00ff) | (val << 8); |
372 | 80cabfad | bellard | break;
|
373 | 7c9d8e07 | bellard | case EN0_RXCR:
|
374 | 7c9d8e07 | bellard | s->rxcr = val; |
375 | 7c9d8e07 | bellard | break;
|
376 | 80cabfad | bellard | case EN0_DCFG:
|
377 | 80cabfad | bellard | s->dcfg = val; |
378 | 80cabfad | bellard | break;
|
379 | 80cabfad | bellard | case EN0_ISR:
|
380 | ee9dbb29 | bellard | s->isr &= ~(val & 0x7f);
|
381 | 80cabfad | bellard | ne2000_update_irq(s); |
382 | 80cabfad | bellard | break;
|
383 | 80cabfad | bellard | case EN1_PHYS ... EN1_PHYS + 5: |
384 | 80cabfad | bellard | s->phys[offset - EN1_PHYS] = val; |
385 | 80cabfad | bellard | break;
|
386 | 80cabfad | bellard | case EN1_CURPAG:
|
387 | 80cabfad | bellard | s->curpag = val; |
388 | 80cabfad | bellard | break;
|
389 | 80cabfad | bellard | case EN1_MULT ... EN1_MULT + 7: |
390 | 80cabfad | bellard | s->mult[offset - EN1_MULT] = val; |
391 | 80cabfad | bellard | break;
|
392 | 80cabfad | bellard | } |
393 | 80cabfad | bellard | } |
394 | 80cabfad | bellard | } |
395 | 80cabfad | bellard | |
396 | 9453c5bc | Gerd Hoffmann | uint32_t ne2000_ioport_read(void *opaque, uint32_t addr)
|
397 | 80cabfad | bellard | { |
398 | b41a2cd1 | bellard | NE2000State *s = opaque; |
399 | 80cabfad | bellard | int offset, page, ret;
|
400 | 80cabfad | bellard | |
401 | 80cabfad | bellard | addr &= 0xf;
|
402 | 80cabfad | bellard | if (addr == E8390_CMD) {
|
403 | 80cabfad | bellard | ret = s->cmd; |
404 | 80cabfad | bellard | } else {
|
405 | 80cabfad | bellard | page = s->cmd >> 6;
|
406 | 80cabfad | bellard | offset = addr | (page << 4);
|
407 | 80cabfad | bellard | switch(offset) {
|
408 | 80cabfad | bellard | case EN0_TSR:
|
409 | 80cabfad | bellard | ret = s->tsr; |
410 | 80cabfad | bellard | break;
|
411 | 80cabfad | bellard | case EN0_BOUNDARY:
|
412 | 80cabfad | bellard | ret = s->boundary; |
413 | 80cabfad | bellard | break;
|
414 | 80cabfad | bellard | case EN0_ISR:
|
415 | 80cabfad | bellard | ret = s->isr; |
416 | 80cabfad | bellard | break;
|
417 | ee9dbb29 | bellard | case EN0_RSARLO:
|
418 | ee9dbb29 | bellard | ret = s->rsar & 0x00ff;
|
419 | ee9dbb29 | bellard | break;
|
420 | ee9dbb29 | bellard | case EN0_RSARHI:
|
421 | ee9dbb29 | bellard | ret = s->rsar >> 8;
|
422 | ee9dbb29 | bellard | break;
|
423 | 80cabfad | bellard | case EN1_PHYS ... EN1_PHYS + 5: |
424 | 80cabfad | bellard | ret = s->phys[offset - EN1_PHYS]; |
425 | 80cabfad | bellard | break;
|
426 | 80cabfad | bellard | case EN1_CURPAG:
|
427 | 80cabfad | bellard | ret = s->curpag; |
428 | 80cabfad | bellard | break;
|
429 | 80cabfad | bellard | case EN1_MULT ... EN1_MULT + 7: |
430 | 80cabfad | bellard | ret = s->mult[offset - EN1_MULT]; |
431 | 80cabfad | bellard | break;
|
432 | 8d6c7eb8 | bellard | case EN0_RSR:
|
433 | 8d6c7eb8 | bellard | ret = s->rsr; |
434 | 8d6c7eb8 | bellard | break;
|
435 | a343df16 | bellard | case EN2_STARTPG:
|
436 | a343df16 | bellard | ret = s->start >> 8;
|
437 | a343df16 | bellard | break;
|
438 | a343df16 | bellard | case EN2_STOPPG:
|
439 | a343df16 | bellard | ret = s->stop >> 8;
|
440 | a343df16 | bellard | break;
|
441 | 089af991 | bellard | case EN0_RTL8029ID0:
|
442 | 089af991 | bellard | ret = 0x50;
|
443 | 089af991 | bellard | break;
|
444 | 089af991 | bellard | case EN0_RTL8029ID1:
|
445 | 089af991 | bellard | ret = 0x43;
|
446 | 089af991 | bellard | break;
|
447 | 089af991 | bellard | case EN3_CONFIG0:
|
448 | 089af991 | bellard | ret = 0; /* 10baseT media */ |
449 | 089af991 | bellard | break;
|
450 | 089af991 | bellard | case EN3_CONFIG2:
|
451 | 089af991 | bellard | ret = 0x40; /* 10baseT active */ |
452 | 089af991 | bellard | break;
|
453 | 089af991 | bellard | case EN3_CONFIG3:
|
454 | 089af991 | bellard | ret = 0x40; /* Full duplex */ |
455 | 089af991 | bellard | break;
|
456 | 80cabfad | bellard | default:
|
457 | 80cabfad | bellard | ret = 0x00;
|
458 | 80cabfad | bellard | break;
|
459 | 80cabfad | bellard | } |
460 | 80cabfad | bellard | } |
461 | 80cabfad | bellard | #ifdef DEBUG_NE2000
|
462 | 80cabfad | bellard | printf("NE2000: read addr=0x%x val=%02x\n", addr, ret);
|
463 | 80cabfad | bellard | #endif
|
464 | 80cabfad | bellard | return ret;
|
465 | 80cabfad | bellard | } |
466 | 80cabfad | bellard | |
467 | 5fafdf24 | ths | static inline void ne2000_mem_writeb(NE2000State *s, uint32_t addr, |
468 | 69b91039 | bellard | uint32_t val) |
469 | ee9dbb29 | bellard | { |
470 | 5fafdf24 | ths | if (addr < 32 || |
471 | ee9dbb29 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
472 | ee9dbb29 | bellard | s->mem[addr] = val; |
473 | ee9dbb29 | bellard | } |
474 | ee9dbb29 | bellard | } |
475 | ee9dbb29 | bellard | |
476 | 5fafdf24 | ths | static inline void ne2000_mem_writew(NE2000State *s, uint32_t addr, |
477 | ee9dbb29 | bellard | uint32_t val) |
478 | ee9dbb29 | bellard | { |
479 | ee9dbb29 | bellard | addr &= ~1; /* XXX: check exact behaviour if not even */ |
480 | 5fafdf24 | ths | if (addr < 32 || |
481 | ee9dbb29 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
482 | 69b91039 | bellard | *(uint16_t *)(s->mem + addr) = cpu_to_le16(val); |
483 | 69b91039 | bellard | } |
484 | 69b91039 | bellard | } |
485 | 69b91039 | bellard | |
486 | 5fafdf24 | ths | static inline void ne2000_mem_writel(NE2000State *s, uint32_t addr, |
487 | 69b91039 | bellard | uint32_t val) |
488 | 69b91039 | bellard | { |
489 | 57ccbabe | bellard | addr &= ~1; /* XXX: check exact behaviour if not even */ |
490 | 5fafdf24 | ths | if (addr < 32 || |
491 | 69b91039 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
492 | 57ccbabe | bellard | cpu_to_le32wu((uint32_t *)(s->mem + addr), val); |
493 | ee9dbb29 | bellard | } |
494 | ee9dbb29 | bellard | } |
495 | ee9dbb29 | bellard | |
496 | ee9dbb29 | bellard | static inline uint32_t ne2000_mem_readb(NE2000State *s, uint32_t addr) |
497 | ee9dbb29 | bellard | { |
498 | 5fafdf24 | ths | if (addr < 32 || |
499 | ee9dbb29 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
500 | ee9dbb29 | bellard | return s->mem[addr];
|
501 | ee9dbb29 | bellard | } else {
|
502 | ee9dbb29 | bellard | return 0xff; |
503 | ee9dbb29 | bellard | } |
504 | ee9dbb29 | bellard | } |
505 | ee9dbb29 | bellard | |
506 | ee9dbb29 | bellard | static inline uint32_t ne2000_mem_readw(NE2000State *s, uint32_t addr) |
507 | ee9dbb29 | bellard | { |
508 | ee9dbb29 | bellard | addr &= ~1; /* XXX: check exact behaviour if not even */ |
509 | 5fafdf24 | ths | if (addr < 32 || |
510 | ee9dbb29 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
511 | 69b91039 | bellard | return le16_to_cpu(*(uint16_t *)(s->mem + addr));
|
512 | ee9dbb29 | bellard | } else {
|
513 | ee9dbb29 | bellard | return 0xffff; |
514 | ee9dbb29 | bellard | } |
515 | ee9dbb29 | bellard | } |
516 | ee9dbb29 | bellard | |
517 | 69b91039 | bellard | static inline uint32_t ne2000_mem_readl(NE2000State *s, uint32_t addr) |
518 | 69b91039 | bellard | { |
519 | 57ccbabe | bellard | addr &= ~1; /* XXX: check exact behaviour if not even */ |
520 | 5fafdf24 | ths | if (addr < 32 || |
521 | 69b91039 | bellard | (addr >= NE2000_PMEM_START && addr < NE2000_MEM_SIZE)) { |
522 | 57ccbabe | bellard | return le32_to_cpupu((uint32_t *)(s->mem + addr));
|
523 | 69b91039 | bellard | } else {
|
524 | 69b91039 | bellard | return 0xffffffff; |
525 | 69b91039 | bellard | } |
526 | 69b91039 | bellard | } |
527 | 69b91039 | bellard | |
528 | 3df3f6fd | bellard | static inline void ne2000_dma_update(NE2000State *s, int len) |
529 | 3df3f6fd | bellard | { |
530 | 3df3f6fd | bellard | s->rsar += len; |
531 | 3df3f6fd | bellard | /* wrap */
|
532 | 3df3f6fd | bellard | /* XXX: check what to do if rsar > stop */
|
533 | 3df3f6fd | bellard | if (s->rsar == s->stop)
|
534 | 3df3f6fd | bellard | s->rsar = s->start; |
535 | 3df3f6fd | bellard | |
536 | 3df3f6fd | bellard | if (s->rcnt <= len) {
|
537 | 3df3f6fd | bellard | s->rcnt = 0;
|
538 | e91c8a77 | ths | /* signal end of transfer */
|
539 | 3df3f6fd | bellard | s->isr |= ENISR_RDC; |
540 | 3df3f6fd | bellard | ne2000_update_irq(s); |
541 | 3df3f6fd | bellard | } else {
|
542 | 3df3f6fd | bellard | s->rcnt -= len; |
543 | 3df3f6fd | bellard | } |
544 | 3df3f6fd | bellard | } |
545 | 3df3f6fd | bellard | |
546 | 9453c5bc | Gerd Hoffmann | void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
547 | 80cabfad | bellard | { |
548 | b41a2cd1 | bellard | NE2000State *s = opaque; |
549 | 80cabfad | bellard | |
550 | 80cabfad | bellard | #ifdef DEBUG_NE2000
|
551 | 80cabfad | bellard | printf("NE2000: asic write val=0x%04x\n", val);
|
552 | 80cabfad | bellard | #endif
|
553 | ee9dbb29 | bellard | if (s->rcnt == 0) |
554 | 3df3f6fd | bellard | return;
|
555 | 80cabfad | bellard | if (s->dcfg & 0x01) { |
556 | 80cabfad | bellard | /* 16 bit access */
|
557 | ee9dbb29 | bellard | ne2000_mem_writew(s, s->rsar, val); |
558 | 3df3f6fd | bellard | ne2000_dma_update(s, 2);
|
559 | 80cabfad | bellard | } else {
|
560 | 80cabfad | bellard | /* 8 bit access */
|
561 | ee9dbb29 | bellard | ne2000_mem_writeb(s, s->rsar, val); |
562 | 3df3f6fd | bellard | ne2000_dma_update(s, 1);
|
563 | 80cabfad | bellard | } |
564 | 80cabfad | bellard | } |
565 | 80cabfad | bellard | |
566 | 9453c5bc | Gerd Hoffmann | uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr)
|
567 | 80cabfad | bellard | { |
568 | b41a2cd1 | bellard | NE2000State *s = opaque; |
569 | 80cabfad | bellard | int ret;
|
570 | 80cabfad | bellard | |
571 | 80cabfad | bellard | if (s->dcfg & 0x01) { |
572 | 80cabfad | bellard | /* 16 bit access */
|
573 | ee9dbb29 | bellard | ret = ne2000_mem_readw(s, s->rsar); |
574 | 3df3f6fd | bellard | ne2000_dma_update(s, 2);
|
575 | 80cabfad | bellard | } else {
|
576 | 80cabfad | bellard | /* 8 bit access */
|
577 | ee9dbb29 | bellard | ret = ne2000_mem_readb(s, s->rsar); |
578 | 3df3f6fd | bellard | ne2000_dma_update(s, 1);
|
579 | 80cabfad | bellard | } |
580 | 80cabfad | bellard | #ifdef DEBUG_NE2000
|
581 | 80cabfad | bellard | printf("NE2000: asic read val=0x%04x\n", ret);
|
582 | 80cabfad | bellard | #endif
|
583 | 80cabfad | bellard | return ret;
|
584 | 80cabfad | bellard | } |
585 | 80cabfad | bellard | |
586 | 69b91039 | bellard | static void ne2000_asic_ioport_writel(void *opaque, uint32_t addr, uint32_t val) |
587 | 69b91039 | bellard | { |
588 | 69b91039 | bellard | NE2000State *s = opaque; |
589 | 69b91039 | bellard | |
590 | 69b91039 | bellard | #ifdef DEBUG_NE2000
|
591 | 69b91039 | bellard | printf("NE2000: asic writel val=0x%04x\n", val);
|
592 | 69b91039 | bellard | #endif
|
593 | 69b91039 | bellard | if (s->rcnt == 0) |
594 | 3df3f6fd | bellard | return;
|
595 | 69b91039 | bellard | /* 32 bit access */
|
596 | 69b91039 | bellard | ne2000_mem_writel(s, s->rsar, val); |
597 | 3df3f6fd | bellard | ne2000_dma_update(s, 4);
|
598 | 69b91039 | bellard | } |
599 | 69b91039 | bellard | |
600 | 69b91039 | bellard | static uint32_t ne2000_asic_ioport_readl(void *opaque, uint32_t addr) |
601 | 69b91039 | bellard | { |
602 | 69b91039 | bellard | NE2000State *s = opaque; |
603 | 69b91039 | bellard | int ret;
|
604 | 69b91039 | bellard | |
605 | 69b91039 | bellard | /* 32 bit access */
|
606 | 69b91039 | bellard | ret = ne2000_mem_readl(s, s->rsar); |
607 | 3df3f6fd | bellard | ne2000_dma_update(s, 4);
|
608 | 69b91039 | bellard | #ifdef DEBUG_NE2000
|
609 | 69b91039 | bellard | printf("NE2000: asic readl val=0x%04x\n", ret);
|
610 | 69b91039 | bellard | #endif
|
611 | 69b91039 | bellard | return ret;
|
612 | 69b91039 | bellard | } |
613 | 69b91039 | bellard | |
614 | 9453c5bc | Gerd Hoffmann | void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
615 | 80cabfad | bellard | { |
616 | 80cabfad | bellard | /* nothing to do (end of reset pulse) */
|
617 | 80cabfad | bellard | } |
618 | 80cabfad | bellard | |
619 | 9453c5bc | Gerd Hoffmann | uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
|
620 | 80cabfad | bellard | { |
621 | b41a2cd1 | bellard | NE2000State *s = opaque; |
622 | 80cabfad | bellard | ne2000_reset(s); |
623 | 80cabfad | bellard | return 0; |
624 | 80cabfad | bellard | } |
625 | 80cabfad | bellard | |
626 | 9453c5bc | Gerd Hoffmann | void ne2000_save(QEMUFile* f, void* opaque) |
627 | 30ca2aab | bellard | { |
628 | a10fcec6 | Juan Quintela | NE2000State* s = opaque; |
629 | 60fe76f3 | ths | uint32_t tmp; |
630 | 30ca2aab | bellard | |
631 | acff9df6 | bellard | qemu_put_8s(f, &s->rxcr); |
632 | acff9df6 | bellard | |
633 | 30ca2aab | bellard | qemu_put_8s(f, &s->cmd); |
634 | 30ca2aab | bellard | qemu_put_be32s(f, &s->start); |
635 | 30ca2aab | bellard | qemu_put_be32s(f, &s->stop); |
636 | 30ca2aab | bellard | qemu_put_8s(f, &s->boundary); |
637 | 30ca2aab | bellard | qemu_put_8s(f, &s->tsr); |
638 | 30ca2aab | bellard | qemu_put_8s(f, &s->tpsr); |
639 | 30ca2aab | bellard | qemu_put_be16s(f, &s->tcnt); |
640 | 30ca2aab | bellard | qemu_put_be16s(f, &s->rcnt); |
641 | 30ca2aab | bellard | qemu_put_be32s(f, &s->rsar); |
642 | 30ca2aab | bellard | qemu_put_8s(f, &s->rsr); |
643 | 30ca2aab | bellard | qemu_put_8s(f, &s->isr); |
644 | 30ca2aab | bellard | qemu_put_8s(f, &s->dcfg); |
645 | 30ca2aab | bellard | qemu_put_8s(f, &s->imr); |
646 | 30ca2aab | bellard | qemu_put_buffer(f, s->phys, 6);
|
647 | 30ca2aab | bellard | qemu_put_8s(f, &s->curpag); |
648 | 30ca2aab | bellard | qemu_put_buffer(f, s->mult, 8);
|
649 | d537cf6c | pbrook | tmp = 0;
|
650 | d537cf6c | pbrook | qemu_put_be32s(f, &tmp); /* ignored, was irq */
|
651 | 30ca2aab | bellard | qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE); |
652 | 30ca2aab | bellard | } |
653 | 30ca2aab | bellard | |
654 | 9453c5bc | Gerd Hoffmann | int ne2000_load(QEMUFile* f, void* opaque, int version_id) |
655 | 30ca2aab | bellard | { |
656 | a10fcec6 | Juan Quintela | NE2000State* s = opaque; |
657 | 60fe76f3 | ths | uint32_t tmp; |
658 | 1941d19c | bellard | |
659 | 1941d19c | bellard | if (version_id > 3) |
660 | 1941d19c | bellard | return -EINVAL;
|
661 | 1941d19c | bellard | |
662 | 1941d19c | bellard | if (version_id >= 2) { |
663 | acff9df6 | bellard | qemu_get_8s(f, &s->rxcr); |
664 | acff9df6 | bellard | } else {
|
665 | 1941d19c | bellard | s->rxcr = 0x0c;
|
666 | acff9df6 | bellard | } |
667 | 30ca2aab | bellard | |
668 | 30ca2aab | bellard | qemu_get_8s(f, &s->cmd); |
669 | 30ca2aab | bellard | qemu_get_be32s(f, &s->start); |
670 | 30ca2aab | bellard | qemu_get_be32s(f, &s->stop); |
671 | 30ca2aab | bellard | qemu_get_8s(f, &s->boundary); |
672 | 30ca2aab | bellard | qemu_get_8s(f, &s->tsr); |
673 | 30ca2aab | bellard | qemu_get_8s(f, &s->tpsr); |
674 | 30ca2aab | bellard | qemu_get_be16s(f, &s->tcnt); |
675 | 30ca2aab | bellard | qemu_get_be16s(f, &s->rcnt); |
676 | 30ca2aab | bellard | qemu_get_be32s(f, &s->rsar); |
677 | 30ca2aab | bellard | qemu_get_8s(f, &s->rsr); |
678 | 30ca2aab | bellard | qemu_get_8s(f, &s->isr); |
679 | 30ca2aab | bellard | qemu_get_8s(f, &s->dcfg); |
680 | 30ca2aab | bellard | qemu_get_8s(f, &s->imr); |
681 | 30ca2aab | bellard | qemu_get_buffer(f, s->phys, 6);
|
682 | 30ca2aab | bellard | qemu_get_8s(f, &s->curpag); |
683 | 30ca2aab | bellard | qemu_get_buffer(f, s->mult, 8);
|
684 | d537cf6c | pbrook | qemu_get_be32s(f, &tmp); /* ignored */
|
685 | 30ca2aab | bellard | qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE); |
686 | 30ca2aab | bellard | |
687 | 30ca2aab | bellard | return 0; |
688 | 30ca2aab | bellard | } |
689 | 30ca2aab | bellard | |
690 | a60380a5 | Juan Quintela | static void pci_ne2000_save(QEMUFile* f, void* opaque) |
691 | a60380a5 | Juan Quintela | { |
692 | a60380a5 | Juan Quintela | PCINE2000State* s = opaque; |
693 | a60380a5 | Juan Quintela | |
694 | a60380a5 | Juan Quintela | pci_device_save(&s->dev, f); |
695 | a60380a5 | Juan Quintela | ne2000_save(f, &s->ne2000); |
696 | a60380a5 | Juan Quintela | } |
697 | a60380a5 | Juan Quintela | |
698 | a60380a5 | Juan Quintela | static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id) |
699 | a60380a5 | Juan Quintela | { |
700 | a60380a5 | Juan Quintela | PCINE2000State* s = opaque; |
701 | a60380a5 | Juan Quintela | int ret;
|
702 | a60380a5 | Juan Quintela | |
703 | a60380a5 | Juan Quintela | if (version_id > 3) |
704 | a60380a5 | Juan Quintela | return -EINVAL;
|
705 | a60380a5 | Juan Quintela | |
706 | a60380a5 | Juan Quintela | if (version_id >= 3) { |
707 | a60380a5 | Juan Quintela | ret = pci_device_load(&s->dev, f); |
708 | a60380a5 | Juan Quintela | if (ret < 0) |
709 | a60380a5 | Juan Quintela | return ret;
|
710 | a60380a5 | Juan Quintela | } |
711 | a60380a5 | Juan Quintela | |
712 | a60380a5 | Juan Quintela | return ne2000_load(f, &s->ne2000, version_id);
|
713 | a60380a5 | Juan Quintela | } |
714 | a60380a5 | Juan Quintela | |
715 | 69b91039 | bellard | /***********************************************************/
|
716 | 69b91039 | bellard | /* PCI NE2000 definitions */
|
717 | 69b91039 | bellard | |
718 | 5fafdf24 | ths | static void ne2000_map(PCIDevice *pci_dev, int region_num, |
719 | 69b91039 | bellard | uint32_t addr, uint32_t size, int type)
|
720 | 69b91039 | bellard | { |
721 | 377a7f06 | Juan Quintela | PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev); |
722 | 69b91039 | bellard | NE2000State *s = &d->ne2000; |
723 | 69b91039 | bellard | |
724 | 69b91039 | bellard | register_ioport_write(addr, 16, 1, ne2000_ioport_write, s); |
725 | 69b91039 | bellard | register_ioport_read(addr, 16, 1, ne2000_ioport_read, s); |
726 | 69b91039 | bellard | |
727 | 69b91039 | bellard | register_ioport_write(addr + 0x10, 1, 1, ne2000_asic_ioport_write, s); |
728 | 69b91039 | bellard | register_ioport_read(addr + 0x10, 1, 1, ne2000_asic_ioport_read, s); |
729 | 69b91039 | bellard | register_ioport_write(addr + 0x10, 2, 2, ne2000_asic_ioport_write, s); |
730 | 69b91039 | bellard | register_ioport_read(addr + 0x10, 2, 2, ne2000_asic_ioport_read, s); |
731 | 69b91039 | bellard | register_ioport_write(addr + 0x10, 4, 4, ne2000_asic_ioport_writel, s); |
732 | 69b91039 | bellard | register_ioport_read(addr + 0x10, 4, 4, ne2000_asic_ioport_readl, s); |
733 | 69b91039 | bellard | |
734 | 69b91039 | bellard | register_ioport_write(addr + 0x1f, 1, 1, ne2000_reset_ioport_write, s); |
735 | 69b91039 | bellard | register_ioport_read(addr + 0x1f, 1, 1, ne2000_reset_ioport_read, s); |
736 | 69b91039 | bellard | } |
737 | 69b91039 | bellard | |
738 | b946a153 | aliguori | static void ne2000_cleanup(VLANClientState *vc) |
739 | b946a153 | aliguori | { |
740 | b946a153 | aliguori | NE2000State *s = vc->opaque; |
741 | b946a153 | aliguori | |
742 | a783cc3e | Gerd Hoffmann | s->vc = NULL;
|
743 | b946a153 | aliguori | } |
744 | b946a153 | aliguori | |
745 | 81a322d4 | Gerd Hoffmann | static int pci_ne2000_init(PCIDevice *pci_dev) |
746 | 69b91039 | bellard | { |
747 | 377a7f06 | Juan Quintela | PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev); |
748 | 69b91039 | bellard | NE2000State *s; |
749 | 69b91039 | bellard | uint8_t *pci_conf; |
750 | 3b46e624 | ths | |
751 | 69b91039 | bellard | pci_conf = d->dev.config; |
752 | deb54399 | aliguori | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK); |
753 | a770dc7e | aliguori | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029); |
754 | 173a543b | blueswir1 | pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET); |
755 | 6407f373 | Isaku Yamahata | pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
756 | 4a9c9687 | bellard | pci_conf[0x3d] = 1; // interrupt pin 0 |
757 | 3b46e624 | ths | |
758 | 28c2c264 | Avi Kivity | pci_register_bar(&d->dev, 0, 0x100, |
759 | 69b91039 | bellard | PCI_ADDRESS_SPACE_IO, ne2000_map); |
760 | 69b91039 | bellard | s = &d->ne2000; |
761 | d537cf6c | pbrook | s->irq = d->dev.irq[0];
|
762 | a783cc3e | Gerd Hoffmann | |
763 | a783cc3e | Gerd Hoffmann | qemu_macaddr_default_if_unset(&s->c.macaddr); |
764 | 69b91039 | bellard | ne2000_reset(s); |
765 | a783cc3e | Gerd Hoffmann | s->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, s->c.vlan, s->c.peer, |
766 | a783cc3e | Gerd Hoffmann | pci_dev->qdev.info->name, pci_dev->qdev.id, |
767 | 463af534 | Mark McLoughlin | ne2000_can_receive, ne2000_receive, NULL,
|
768 | a783cc3e | Gerd Hoffmann | NULL, ne2000_cleanup, s);
|
769 | 93db6685 | Gerd Hoffmann | qemu_format_nic_info_str(s->vc, s->c.macaddr.a); |
770 | 3b46e624 | ths | |
771 | a783cc3e | Gerd Hoffmann | if (!pci_dev->qdev.hotplugged) {
|
772 | a783cc3e | Gerd Hoffmann | static int loaded = 0; |
773 | a783cc3e | Gerd Hoffmann | if (!loaded) {
|
774 | a783cc3e | Gerd Hoffmann | rom_add_option("pxe-ne2k_pci.bin");
|
775 | a783cc3e | Gerd Hoffmann | loaded = 1;
|
776 | a783cc3e | Gerd Hoffmann | } |
777 | a783cc3e | Gerd Hoffmann | } |
778 | a783cc3e | Gerd Hoffmann | |
779 | a60380a5 | Juan Quintela | register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d); |
780 | 81a322d4 | Gerd Hoffmann | return 0; |
781 | 9d07d757 | Paul Brook | } |
782 | 72da4208 | aliguori | |
783 | a783cc3e | Gerd Hoffmann | static int pci_ne2000_exit(PCIDevice *pci_dev) |
784 | a783cc3e | Gerd Hoffmann | { |
785 | a783cc3e | Gerd Hoffmann | PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev); |
786 | a783cc3e | Gerd Hoffmann | NE2000State *s = &d->ne2000; |
787 | a783cc3e | Gerd Hoffmann | |
788 | a783cc3e | Gerd Hoffmann | unregister_savevm("ne2000", s);
|
789 | a783cc3e | Gerd Hoffmann | qemu_del_vlan_client(s->vc); |
790 | a783cc3e | Gerd Hoffmann | return 0; |
791 | a783cc3e | Gerd Hoffmann | } |
792 | a783cc3e | Gerd Hoffmann | |
793 | 0aab0d3a | Gerd Hoffmann | static PCIDeviceInfo ne2000_info = {
|
794 | a783cc3e | Gerd Hoffmann | .qdev.name = "ne2k_pci",
|
795 | a783cc3e | Gerd Hoffmann | .qdev.size = sizeof(PCINE2000State),
|
796 | a783cc3e | Gerd Hoffmann | .init = pci_ne2000_init, |
797 | a783cc3e | Gerd Hoffmann | .exit = pci_ne2000_exit, |
798 | a783cc3e | Gerd Hoffmann | .qdev.props = (Property[]) { |
799 | a783cc3e | Gerd Hoffmann | DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c), |
800 | a783cc3e | Gerd Hoffmann | DEFINE_PROP_END_OF_LIST(), |
801 | a783cc3e | Gerd Hoffmann | } |
802 | 0aab0d3a | Gerd Hoffmann | }; |
803 | 0aab0d3a | Gerd Hoffmann | |
804 | 9d07d757 | Paul Brook | static void ne2000_register_devices(void) |
805 | 9d07d757 | Paul Brook | { |
806 | 0aab0d3a | Gerd Hoffmann | pci_qdev_register(&ne2000_info); |
807 | 69b91039 | bellard | } |
808 | 9d07d757 | Paul Brook | |
809 | 9d07d757 | Paul Brook | device_init(ne2000_register_devices) |