root / hw / pcnet.c @ a4c75a21
History | View | Annotate | Download (53.6 kB)
1 | e3c2613f | bellard | /*
|
---|---|---|---|
2 | e3c2613f | bellard | * QEMU AMD PC-Net II (Am79C970A) emulation
|
3 | 5fafdf24 | ths | *
|
4 | e3c2613f | bellard | * Copyright (c) 2004 Antony T Curtis
|
5 | 5fafdf24 | ths | *
|
6 | e3c2613f | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | e3c2613f | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | e3c2613f | bellard | * in the Software without restriction, including without limitation the rights
|
9 | e3c2613f | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | e3c2613f | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | e3c2613f | bellard | * furnished to do so, subject to the following conditions:
|
12 | e3c2613f | bellard | *
|
13 | e3c2613f | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | e3c2613f | bellard | * all copies or substantial portions of the Software.
|
15 | e3c2613f | bellard | *
|
16 | e3c2613f | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | e3c2613f | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | e3c2613f | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | e3c2613f | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | e3c2613f | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | e3c2613f | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | e3c2613f | bellard | * THE SOFTWARE.
|
23 | e3c2613f | bellard | */
|
24 | 5fafdf24 | ths | |
25 | e3c2613f | bellard | /* This software was written to be compatible with the specification:
|
26 | e3c2613f | bellard | * AMD Am79C970A PCnet-PCI II Ethernet Controller Data-Sheet
|
27 | e3c2613f | bellard | * AMD Publication# 19436 Rev:E Amendment/0 Issue Date: June 2000
|
28 | e3c2613f | bellard | */
|
29 | 5fafdf24 | ths | |
30 | 91cc0295 | bellard | /*
|
31 | 91cc0295 | bellard | * On Sparc32, this is the Lance (Am7990) part of chip STP2000 (Master I/O), also
|
32 | 91cc0295 | bellard | * produced as NCR89C100. See
|
33 | 91cc0295 | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C100.txt
|
34 | 91cc0295 | bellard | * and
|
35 | 91cc0295 | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR92C990.txt
|
36 | 91cc0295 | bellard | */
|
37 | 91cc0295 | bellard | |
38 | a4c75a21 | Paul Brook | #include "qdev.h" |
39 | 87ecb68b | pbrook | #include "net.h" |
40 | 87ecb68b | pbrook | #include "qemu-timer.h" |
41 | 841c26a0 | aurel32 | #include "qemu_socket.h" |
42 | e3c2613f | bellard | |
43 | 94e1a912 | Gerd Hoffmann | #include "pcnet.h" |
44 | 94e1a912 | Gerd Hoffmann | |
45 | e3c2613f | bellard | //#define PCNET_DEBUG
|
46 | e3c2613f | bellard | //#define PCNET_DEBUG_IO
|
47 | e3c2613f | bellard | //#define PCNET_DEBUG_BCR
|
48 | e3c2613f | bellard | //#define PCNET_DEBUG_CSR
|
49 | e3c2613f | bellard | //#define PCNET_DEBUG_RMD
|
50 | e3c2613f | bellard | //#define PCNET_DEBUG_TMD
|
51 | e3c2613f | bellard | //#define PCNET_DEBUG_MATCH
|
52 | e3c2613f | bellard | |
53 | e3c2613f | bellard | |
54 | 219fb125 | bellard | struct qemu_ether_header {
|
55 | 219fb125 | bellard | uint8_t ether_dhost[6];
|
56 | 219fb125 | bellard | uint8_t ether_shost[6];
|
57 | 219fb125 | bellard | uint16_t ether_type; |
58 | 219fb125 | bellard | }; |
59 | 219fb125 | bellard | |
60 | e3c2613f | bellard | /* BUS CONFIGURATION REGISTERS */
|
61 | e3c2613f | bellard | #define BCR_MSRDA 0 |
62 | e3c2613f | bellard | #define BCR_MSWRA 1 |
63 | e3c2613f | bellard | #define BCR_MC 2 |
64 | e3c2613f | bellard | #define BCR_LNKST 4 |
65 | e3c2613f | bellard | #define BCR_LED1 5 |
66 | e3c2613f | bellard | #define BCR_LED2 6 |
67 | e3c2613f | bellard | #define BCR_LED3 7 |
68 | e3c2613f | bellard | #define BCR_FDC 9 |
69 | e3c2613f | bellard | #define BCR_BSBC 18 |
70 | e3c2613f | bellard | #define BCR_EECAS 19 |
71 | e3c2613f | bellard | #define BCR_SWS 20 |
72 | e3c2613f | bellard | #define BCR_PLAT 22 |
73 | e3c2613f | bellard | |
74 | e3c2613f | bellard | #define BCR_DWIO(S) !!((S)->bcr[BCR_BSBC] & 0x0080) |
75 | e3c2613f | bellard | #define BCR_SSIZE32(S) !!((S)->bcr[BCR_SWS ] & 0x0100) |
76 | e3c2613f | bellard | #define BCR_SWSTYLE(S) ((S)->bcr[BCR_SWS ] & 0x00FF) |
77 | e3c2613f | bellard | |
78 | e3c2613f | bellard | #define CSR_INIT(S) !!(((S)->csr[0])&0x0001) |
79 | e3c2613f | bellard | #define CSR_STRT(S) !!(((S)->csr[0])&0x0002) |
80 | e3c2613f | bellard | #define CSR_STOP(S) !!(((S)->csr[0])&0x0004) |
81 | e3c2613f | bellard | #define CSR_TDMD(S) !!(((S)->csr[0])&0x0008) |
82 | e3c2613f | bellard | #define CSR_TXON(S) !!(((S)->csr[0])&0x0010) |
83 | e3c2613f | bellard | #define CSR_RXON(S) !!(((S)->csr[0])&0x0020) |
84 | e3c2613f | bellard | #define CSR_INEA(S) !!(((S)->csr[0])&0x0040) |
85 | 9b94dc32 | bellard | #define CSR_BSWP(S) !!(((S)->csr[3])&0x0004) |
86 | e3c2613f | bellard | #define CSR_LAPPEN(S) !!(((S)->csr[3])&0x0020) |
87 | e3c2613f | bellard | #define CSR_DXSUFLO(S) !!(((S)->csr[3])&0x0040) |
88 | e3c2613f | bellard | #define CSR_ASTRP_RCV(S) !!(((S)->csr[4])&0x0800) |
89 | e3c2613f | bellard | #define CSR_DPOLL(S) !!(((S)->csr[4])&0x1000) |
90 | e3c2613f | bellard | #define CSR_SPND(S) !!(((S)->csr[5])&0x0001) |
91 | e3c2613f | bellard | #define CSR_LTINTEN(S) !!(((S)->csr[5])&0x4000) |
92 | e3c2613f | bellard | #define CSR_TOKINTD(S) !!(((S)->csr[5])&0x8000) |
93 | e3c2613f | bellard | #define CSR_DRX(S) !!(((S)->csr[15])&0x0001) |
94 | e3c2613f | bellard | #define CSR_DTX(S) !!(((S)->csr[15])&0x0002) |
95 | e3c2613f | bellard | #define CSR_LOOP(S) !!(((S)->csr[15])&0x0004) |
96 | 89b190a2 | aurel32 | #define CSR_DXMTFCS(S) !!(((S)->csr[15])&0x0008) |
97 | e3c2613f | bellard | #define CSR_DRCVPA(S) !!(((S)->csr[15])&0x2000) |
98 | e3c2613f | bellard | #define CSR_DRCVBC(S) !!(((S)->csr[15])&0x4000) |
99 | e3c2613f | bellard | #define CSR_PROM(S) !!(((S)->csr[15])&0x8000) |
100 | e3c2613f | bellard | |
101 | e3c2613f | bellard | #define CSR_CRBC(S) ((S)->csr[40]) |
102 | e3c2613f | bellard | #define CSR_CRST(S) ((S)->csr[41]) |
103 | e3c2613f | bellard | #define CSR_CXBC(S) ((S)->csr[42]) |
104 | e3c2613f | bellard | #define CSR_CXST(S) ((S)->csr[43]) |
105 | e3c2613f | bellard | #define CSR_NRBC(S) ((S)->csr[44]) |
106 | e3c2613f | bellard | #define CSR_NRST(S) ((S)->csr[45]) |
107 | e3c2613f | bellard | #define CSR_POLL(S) ((S)->csr[46]) |
108 | e3c2613f | bellard | #define CSR_PINT(S) ((S)->csr[47]) |
109 | e3c2613f | bellard | #define CSR_RCVRC(S) ((S)->csr[72]) |
110 | e3c2613f | bellard | #define CSR_XMTRC(S) ((S)->csr[74]) |
111 | e3c2613f | bellard | #define CSR_RCVRL(S) ((S)->csr[76]) |
112 | e3c2613f | bellard | #define CSR_XMTRL(S) ((S)->csr[78]) |
113 | e3c2613f | bellard | #define CSR_MISSC(S) ((S)->csr[112]) |
114 | e3c2613f | bellard | |
115 | e3c2613f | bellard | #define CSR_IADR(S) ((S)->csr[ 1] | ((S)->csr[ 2] << 16)) |
116 | e3c2613f | bellard | #define CSR_CRBA(S) ((S)->csr[18] | ((S)->csr[19] << 16)) |
117 | e3c2613f | bellard | #define CSR_CXBA(S) ((S)->csr[20] | ((S)->csr[21] << 16)) |
118 | e3c2613f | bellard | #define CSR_NRBA(S) ((S)->csr[22] | ((S)->csr[23] << 16)) |
119 | e3c2613f | bellard | #define CSR_BADR(S) ((S)->csr[24] | ((S)->csr[25] << 16)) |
120 | e3c2613f | bellard | #define CSR_NRDA(S) ((S)->csr[26] | ((S)->csr[27] << 16)) |
121 | e3c2613f | bellard | #define CSR_CRDA(S) ((S)->csr[28] | ((S)->csr[29] << 16)) |
122 | e3c2613f | bellard | #define CSR_BADX(S) ((S)->csr[30] | ((S)->csr[31] << 16)) |
123 | e3c2613f | bellard | #define CSR_NXDA(S) ((S)->csr[32] | ((S)->csr[33] << 16)) |
124 | e3c2613f | bellard | #define CSR_CXDA(S) ((S)->csr[34] | ((S)->csr[35] << 16)) |
125 | e3c2613f | bellard | #define CSR_NNRD(S) ((S)->csr[36] | ((S)->csr[37] << 16)) |
126 | e3c2613f | bellard | #define CSR_NNXD(S) ((S)->csr[38] | ((S)->csr[39] << 16)) |
127 | e3c2613f | bellard | #define CSR_PXDA(S) ((S)->csr[60] | ((S)->csr[61] << 16)) |
128 | e3c2613f | bellard | #define CSR_NXBA(S) ((S)->csr[64] | ((S)->csr[65] << 16)) |
129 | e3c2613f | bellard | |
130 | e3c2613f | bellard | #define PHYSADDR(S,A) \
|
131 | e3c2613f | bellard | (BCR_SSIZE32(S) ? (A) : (A) | ((0xff00 & (uint32_t)(s)->csr[2])<<16)) |
132 | e3c2613f | bellard | |
133 | e3c2613f | bellard | struct pcnet_initblk16 {
|
134 | e3c2613f | bellard | uint16_t mode; |
135 | 91cc0295 | bellard | uint16_t padr[3];
|
136 | 91cc0295 | bellard | uint16_t ladrf[4];
|
137 | 91cc0295 | bellard | uint32_t rdra; |
138 | 91cc0295 | bellard | uint32_t tdra; |
139 | e3c2613f | bellard | }; |
140 | e3c2613f | bellard | |
141 | e3c2613f | bellard | struct pcnet_initblk32 {
|
142 | e3c2613f | bellard | uint16_t mode; |
143 | 91cc0295 | bellard | uint8_t rlen; |
144 | 91cc0295 | bellard | uint8_t tlen; |
145 | 91cc0295 | bellard | uint16_t padr[3];
|
146 | e3c2613f | bellard | uint16_t _res; |
147 | 91cc0295 | bellard | uint16_t ladrf[4];
|
148 | e3c2613f | bellard | uint32_t rdra; |
149 | e3c2613f | bellard | uint32_t tdra; |
150 | e3c2613f | bellard | }; |
151 | e3c2613f | bellard | |
152 | e3c2613f | bellard | struct pcnet_TMD {
|
153 | 6d2980f5 | ths | uint32_t tbadr; |
154 | 6d2980f5 | ths | int16_t length; |
155 | 6d2980f5 | ths | int16_t status; |
156 | 6d2980f5 | ths | uint32_t misc; |
157 | 6d2980f5 | ths | uint32_t res; |
158 | e3c2613f | bellard | }; |
159 | e3c2613f | bellard | |
160 | 6d2980f5 | ths | #define TMDL_BCNT_MASK 0x0fff |
161 | 6d2980f5 | ths | #define TMDL_BCNT_SH 0 |
162 | 6d2980f5 | ths | #define TMDL_ONES_MASK 0xf000 |
163 | 6d2980f5 | ths | #define TMDL_ONES_SH 12 |
164 | 6d2980f5 | ths | |
165 | 6d2980f5 | ths | #define TMDS_BPE_MASK 0x0080 |
166 | 6d2980f5 | ths | #define TMDS_BPE_SH 7 |
167 | 6d2980f5 | ths | #define TMDS_ENP_MASK 0x0100 |
168 | 6d2980f5 | ths | #define TMDS_ENP_SH 8 |
169 | 6d2980f5 | ths | #define TMDS_STP_MASK 0x0200 |
170 | 6d2980f5 | ths | #define TMDS_STP_SH 9 |
171 | 6d2980f5 | ths | #define TMDS_DEF_MASK 0x0400 |
172 | 6d2980f5 | ths | #define TMDS_DEF_SH 10 |
173 | 6d2980f5 | ths | #define TMDS_ONE_MASK 0x0800 |
174 | 6d2980f5 | ths | #define TMDS_ONE_SH 11 |
175 | 6d2980f5 | ths | #define TMDS_LTINT_MASK 0x1000 |
176 | 6d2980f5 | ths | #define TMDS_LTINT_SH 12 |
177 | 6d2980f5 | ths | #define TMDS_NOFCS_MASK 0x2000 |
178 | 6d2980f5 | ths | #define TMDS_NOFCS_SH 13 |
179 | 89b190a2 | aurel32 | #define TMDS_ADDFCS_MASK TMDS_NOFCS_MASK
|
180 | 89b190a2 | aurel32 | #define TMDS_ADDFCS_SH TMDS_NOFCS_SH
|
181 | 6d2980f5 | ths | #define TMDS_ERR_MASK 0x4000 |
182 | 6d2980f5 | ths | #define TMDS_ERR_SH 14 |
183 | 6d2980f5 | ths | #define TMDS_OWN_MASK 0x8000 |
184 | 6d2980f5 | ths | #define TMDS_OWN_SH 15 |
185 | 6d2980f5 | ths | |
186 | 6d2980f5 | ths | #define TMDM_TRC_MASK 0x0000000f |
187 | 6d2980f5 | ths | #define TMDM_TRC_SH 0 |
188 | 6d2980f5 | ths | #define TMDM_TDR_MASK 0x03ff0000 |
189 | 6d2980f5 | ths | #define TMDM_TDR_SH 16 |
190 | 6d2980f5 | ths | #define TMDM_RTRY_MASK 0x04000000 |
191 | 6d2980f5 | ths | #define TMDM_RTRY_SH 26 |
192 | 6d2980f5 | ths | #define TMDM_LCAR_MASK 0x08000000 |
193 | 6d2980f5 | ths | #define TMDM_LCAR_SH 27 |
194 | 6d2980f5 | ths | #define TMDM_LCOL_MASK 0x10000000 |
195 | 6d2980f5 | ths | #define TMDM_LCOL_SH 28 |
196 | 6d2980f5 | ths | #define TMDM_EXDEF_MASK 0x20000000 |
197 | 6d2980f5 | ths | #define TMDM_EXDEF_SH 29 |
198 | 6d2980f5 | ths | #define TMDM_UFLO_MASK 0x40000000 |
199 | 6d2980f5 | ths | #define TMDM_UFLO_SH 30 |
200 | 6d2980f5 | ths | #define TMDM_BUFF_MASK 0x80000000 |
201 | 6d2980f5 | ths | #define TMDM_BUFF_SH 31 |
202 | 6d2980f5 | ths | |
203 | e3c2613f | bellard | struct pcnet_RMD {
|
204 | 6d2980f5 | ths | uint32_t rbadr; |
205 | 6d2980f5 | ths | int16_t buf_length; |
206 | 6d2980f5 | ths | int16_t status; |
207 | 6d2980f5 | ths | uint32_t msg_length; |
208 | 6d2980f5 | ths | uint32_t res; |
209 | e3c2613f | bellard | }; |
210 | e3c2613f | bellard | |
211 | 6d2980f5 | ths | #define RMDL_BCNT_MASK 0x0fff |
212 | 6d2980f5 | ths | #define RMDL_BCNT_SH 0 |
213 | 6d2980f5 | ths | #define RMDL_ONES_MASK 0xf000 |
214 | 6d2980f5 | ths | #define RMDL_ONES_SH 12 |
215 | 6d2980f5 | ths | |
216 | 6d2980f5 | ths | #define RMDS_BAM_MASK 0x0010 |
217 | 6d2980f5 | ths | #define RMDS_BAM_SH 4 |
218 | 6d2980f5 | ths | #define RMDS_LFAM_MASK 0x0020 |
219 | 6d2980f5 | ths | #define RMDS_LFAM_SH 5 |
220 | 6d2980f5 | ths | #define RMDS_PAM_MASK 0x0040 |
221 | 6d2980f5 | ths | #define RMDS_PAM_SH 6 |
222 | 6d2980f5 | ths | #define RMDS_BPE_MASK 0x0080 |
223 | 6d2980f5 | ths | #define RMDS_BPE_SH 7 |
224 | 6d2980f5 | ths | #define RMDS_ENP_MASK 0x0100 |
225 | 6d2980f5 | ths | #define RMDS_ENP_SH 8 |
226 | 6d2980f5 | ths | #define RMDS_STP_MASK 0x0200 |
227 | 6d2980f5 | ths | #define RMDS_STP_SH 9 |
228 | 6d2980f5 | ths | #define RMDS_BUFF_MASK 0x0400 |
229 | 6d2980f5 | ths | #define RMDS_BUFF_SH 10 |
230 | 6d2980f5 | ths | #define RMDS_CRC_MASK 0x0800 |
231 | 6d2980f5 | ths | #define RMDS_CRC_SH 11 |
232 | 6d2980f5 | ths | #define RMDS_OFLO_MASK 0x1000 |
233 | 6d2980f5 | ths | #define RMDS_OFLO_SH 12 |
234 | 6d2980f5 | ths | #define RMDS_FRAM_MASK 0x2000 |
235 | 6d2980f5 | ths | #define RMDS_FRAM_SH 13 |
236 | 6d2980f5 | ths | #define RMDS_ERR_MASK 0x4000 |
237 | 6d2980f5 | ths | #define RMDS_ERR_SH 14 |
238 | 6d2980f5 | ths | #define RMDS_OWN_MASK 0x8000 |
239 | 6d2980f5 | ths | #define RMDS_OWN_SH 15 |
240 | 6d2980f5 | ths | |
241 | 6d2980f5 | ths | #define RMDM_MCNT_MASK 0x00000fff |
242 | 6d2980f5 | ths | #define RMDM_MCNT_SH 0 |
243 | 6d2980f5 | ths | #define RMDM_ZEROS_MASK 0x0000f000 |
244 | 6d2980f5 | ths | #define RMDM_ZEROS_SH 12 |
245 | 6d2980f5 | ths | #define RMDM_RPC_MASK 0x00ff0000 |
246 | 6d2980f5 | ths | #define RMDM_RPC_SH 16 |
247 | 6d2980f5 | ths | #define RMDM_RCC_MASK 0xff000000 |
248 | 6d2980f5 | ths | #define RMDM_RCC_SH 24 |
249 | 6d2980f5 | ths | |
250 | 6d2980f5 | ths | #define SET_FIELD(regp, name, field, value) \
|
251 | 6d2980f5 | ths | (*(regp) = (*(regp) & ~(name ## _ ## field ## _MASK)) \ |
252 | 6d2980f5 | ths | | ((value) << name ## _ ## field ## _SH)) |
253 | 6d2980f5 | ths | |
254 | 6d2980f5 | ths | #define GET_FIELD(reg, name, field) \
|
255 | 6d2980f5 | ths | (((reg) & name ## _ ## field ## _MASK) >> name ## _ ## field ## _SH) |
256 | 6d2980f5 | ths | |
257 | 6d2980f5 | ths | #define PRINT_TMD(T) printf( \
|
258 | 6d2980f5 | ths | "TMD0 : TBADR=0x%08x\n" \
|
259 | e3c2613f | bellard | "TMD1 : OWN=%d, ERR=%d, FCS=%d, LTI=%d, " \
|
260 | e3c2613f | bellard | "ONE=%d, DEF=%d, STP=%d, ENP=%d,\n" \
|
261 | e3c2613f | bellard | " BPE=%d, BCNT=%d\n" \
|
262 | e3c2613f | bellard | "TMD2 : BUF=%d, UFL=%d, EXD=%d, LCO=%d, " \
|
263 | e3c2613f | bellard | "LCA=%d, RTR=%d,\n" \
|
264 | e3c2613f | bellard | " TDR=%d, TRC=%d\n", \
|
265 | 6d2980f5 | ths | (T)->tbadr, \ |
266 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, OWN), \ |
267 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, ERR), \ |
268 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, NOFCS), \ |
269 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, LTINT), \ |
270 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, ONE), \ |
271 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, DEF), \ |
272 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, STP), \ |
273 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, ENP), \ |
274 | 6d2980f5 | ths | GET_FIELD((T)->status, TMDS, BPE), \ |
275 | 6d2980f5 | ths | 4096-GET_FIELD((T)->length, TMDL, BCNT), \
|
276 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, BUFF), \ |
277 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, UFLO), \ |
278 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, EXDEF), \ |
279 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, LCOL), \ |
280 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, LCAR), \ |
281 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, RTRY), \ |
282 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, TDR), \ |
283 | 6d2980f5 | ths | GET_FIELD((T)->misc, TMDM, TRC)) |
284 | 6d2980f5 | ths | |
285 | 6d2980f5 | ths | #define PRINT_RMD(R) printf( \
|
286 | 6d2980f5 | ths | "RMD0 : RBADR=0x%08x\n" \
|
287 | e3c2613f | bellard | "RMD1 : OWN=%d, ERR=%d, FRAM=%d, OFLO=%d, " \
|
288 | e3c2613f | bellard | "CRC=%d, BUFF=%d, STP=%d, ENP=%d,\n " \
|
289 | 6d2980f5 | ths | "BPE=%d, PAM=%d, LAFM=%d, BAM=%d, ONES=%d, BCNT=%d\n" \
|
290 | e3c2613f | bellard | "RMD2 : RCC=%d, RPC=%d, MCNT=%d, ZEROS=%d\n", \
|
291 | 6d2980f5 | ths | (R)->rbadr, \ |
292 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, OWN), \ |
293 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, ERR), \ |
294 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, FRAM), \ |
295 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, OFLO), \ |
296 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, CRC), \ |
297 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, BUFF), \ |
298 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, STP), \ |
299 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, ENP), \ |
300 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, BPE), \ |
301 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, PAM), \ |
302 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, LFAM), \ |
303 | 6d2980f5 | ths | GET_FIELD((R)->status, RMDS, BAM), \ |
304 | 6d2980f5 | ths | GET_FIELD((R)->buf_length, RMDL, ONES), \ |
305 | 6d2980f5 | ths | 4096-GET_FIELD((R)->buf_length, RMDL, BCNT), \
|
306 | 6d2980f5 | ths | GET_FIELD((R)->msg_length, RMDM, RCC), \ |
307 | 6d2980f5 | ths | GET_FIELD((R)->msg_length, RMDM, RPC), \ |
308 | 6d2980f5 | ths | GET_FIELD((R)->msg_length, RMDM, MCNT), \ |
309 | 6d2980f5 | ths | GET_FIELD((R)->msg_length, RMDM, ZEROS)) |
310 | 6d2980f5 | ths | |
311 | 6d2980f5 | ths | static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd, |
312 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
313 | e3c2613f | bellard | { |
314 | 6d2980f5 | ths | if (!BCR_SSIZE32(s)) {
|
315 | 6d2980f5 | ths | struct {
|
316 | 6d2980f5 | ths | uint32_t tbadr; |
317 | 6d2980f5 | ths | int16_t length; |
318 | 6d2980f5 | ths | int16_t status; |
319 | 6d2980f5 | ths | } xda; |
320 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); |
321 | 6d2980f5 | ths | tmd->tbadr = le32_to_cpu(xda.tbadr) & 0xffffff;
|
322 | 6d2980f5 | ths | tmd->length = le16_to_cpu(xda.length); |
323 | 6d2980f5 | ths | tmd->status = (le32_to_cpu(xda.tbadr) >> 16) & 0xff00; |
324 | 6d2980f5 | ths | tmd->misc = le16_to_cpu(xda.status) << 16;
|
325 | 6d2980f5 | ths | tmd->res = 0;
|
326 | 03c18475 | bellard | } else {
|
327 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, addr, (void *)tmd, sizeof(*tmd), 0); |
328 | 6d2980f5 | ths | le32_to_cpus(&tmd->tbadr); |
329 | 69b34976 | ths | le16_to_cpus((uint16_t *)&tmd->length); |
330 | 69b34976 | ths | le16_to_cpus((uint16_t *)&tmd->status); |
331 | 6d2980f5 | ths | le32_to_cpus(&tmd->misc); |
332 | 6d2980f5 | ths | le32_to_cpus(&tmd->res); |
333 | 6d2980f5 | ths | if (BCR_SWSTYLE(s) == 3) { |
334 | 6d2980f5 | ths | uint32_t tmp = tmd->tbadr; |
335 | 6d2980f5 | ths | tmd->tbadr = tmd->misc; |
336 | 6d2980f5 | ths | tmd->misc = tmp; |
337 | 03c18475 | bellard | } |
338 | e3c2613f | bellard | } |
339 | e3c2613f | bellard | } |
340 | e3c2613f | bellard | |
341 | 6d2980f5 | ths | static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd, |
342 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
343 | e3c2613f | bellard | { |
344 | 6d2980f5 | ths | if (!BCR_SSIZE32(s)) {
|
345 | 6d2980f5 | ths | struct {
|
346 | 6d2980f5 | ths | uint32_t tbadr; |
347 | 6d2980f5 | ths | int16_t length; |
348 | 6d2980f5 | ths | int16_t status; |
349 | 6d2980f5 | ths | } xda; |
350 | 6d2980f5 | ths | xda.tbadr = cpu_to_le32((tmd->tbadr & 0xffffff) |
|
351 | 6d2980f5 | ths | ((tmd->status & 0xff00) << 16)); |
352 | 6d2980f5 | ths | xda.length = cpu_to_le16(tmd->length); |
353 | 6d2980f5 | ths | xda.status = cpu_to_le16(tmd->misc >> 16);
|
354 | 6d2980f5 | ths | s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); |
355 | 03c18475 | bellard | } else {
|
356 | 6d2980f5 | ths | struct {
|
357 | 6d2980f5 | ths | uint32_t tbadr; |
358 | 6d2980f5 | ths | int16_t length; |
359 | 6d2980f5 | ths | int16_t status; |
360 | 6d2980f5 | ths | uint32_t misc; |
361 | 6d2980f5 | ths | uint32_t res; |
362 | 6d2980f5 | ths | } xda; |
363 | 6d2980f5 | ths | xda.tbadr = cpu_to_le32(tmd->tbadr); |
364 | 6d2980f5 | ths | xda.length = cpu_to_le16(tmd->length); |
365 | 6d2980f5 | ths | xda.status = cpu_to_le16(tmd->status); |
366 | 6d2980f5 | ths | xda.misc = cpu_to_le32(tmd->misc); |
367 | 6d2980f5 | ths | xda.res = cpu_to_le32(tmd->res); |
368 | 6d2980f5 | ths | if (BCR_SWSTYLE(s) == 3) { |
369 | 6d2980f5 | ths | uint32_t tmp = xda.tbadr; |
370 | 6d2980f5 | ths | xda.tbadr = xda.misc; |
371 | 6d2980f5 | ths | xda.misc = tmp; |
372 | 03c18475 | bellard | } |
373 | 6d2980f5 | ths | s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); |
374 | e3c2613f | bellard | } |
375 | e3c2613f | bellard | } |
376 | e3c2613f | bellard | |
377 | 6d2980f5 | ths | static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd, |
378 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
379 | e3c2613f | bellard | { |
380 | 6d2980f5 | ths | if (!BCR_SSIZE32(s)) {
|
381 | 6d2980f5 | ths | struct {
|
382 | 6d2980f5 | ths | uint32_t rbadr; |
383 | 6d2980f5 | ths | int16_t buf_length; |
384 | 6d2980f5 | ths | int16_t msg_length; |
385 | 6d2980f5 | ths | } rda; |
386 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); |
387 | 6d2980f5 | ths | rmd->rbadr = le32_to_cpu(rda.rbadr) & 0xffffff;
|
388 | 6d2980f5 | ths | rmd->buf_length = le16_to_cpu(rda.buf_length); |
389 | 6d2980f5 | ths | rmd->status = (le32_to_cpu(rda.rbadr) >> 16) & 0xff00; |
390 | 6d2980f5 | ths | rmd->msg_length = le16_to_cpu(rda.msg_length); |
391 | 6d2980f5 | ths | rmd->res = 0;
|
392 | 03c18475 | bellard | } else {
|
393 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, addr, (void *)rmd, sizeof(*rmd), 0); |
394 | 6d2980f5 | ths | le32_to_cpus(&rmd->rbadr); |
395 | 69b34976 | ths | le16_to_cpus((uint16_t *)&rmd->buf_length); |
396 | 69b34976 | ths | le16_to_cpus((uint16_t *)&rmd->status); |
397 | 6d2980f5 | ths | le32_to_cpus(&rmd->msg_length); |
398 | 6d2980f5 | ths | le32_to_cpus(&rmd->res); |
399 | 6d2980f5 | ths | if (BCR_SWSTYLE(s) == 3) { |
400 | 6d2980f5 | ths | uint32_t tmp = rmd->rbadr; |
401 | 6d2980f5 | ths | rmd->rbadr = rmd->msg_length; |
402 | 6d2980f5 | ths | rmd->msg_length = tmp; |
403 | 03c18475 | bellard | } |
404 | e3c2613f | bellard | } |
405 | e3c2613f | bellard | } |
406 | e3c2613f | bellard | |
407 | 6d2980f5 | ths | static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd, |
408 | c227f099 | Anthony Liguori | target_phys_addr_t addr) |
409 | e3c2613f | bellard | { |
410 | 6d2980f5 | ths | if (!BCR_SSIZE32(s)) {
|
411 | 6d2980f5 | ths | struct {
|
412 | 6d2980f5 | ths | uint32_t rbadr; |
413 | 6d2980f5 | ths | int16_t buf_length; |
414 | 6d2980f5 | ths | int16_t msg_length; |
415 | 6d2980f5 | ths | } rda; |
416 | 6d2980f5 | ths | rda.rbadr = cpu_to_le32((rmd->rbadr & 0xffffff) |
|
417 | 6d2980f5 | ths | ((rmd->status & 0xff00) << 16)); |
418 | 6d2980f5 | ths | rda.buf_length = cpu_to_le16(rmd->buf_length); |
419 | 6d2980f5 | ths | rda.msg_length = cpu_to_le16(rmd->msg_length); |
420 | 6d2980f5 | ths | s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); |
421 | 03c18475 | bellard | } else {
|
422 | 6d2980f5 | ths | struct {
|
423 | 6d2980f5 | ths | uint32_t rbadr; |
424 | 6d2980f5 | ths | int16_t buf_length; |
425 | 6d2980f5 | ths | int16_t status; |
426 | 6d2980f5 | ths | uint32_t msg_length; |
427 | 6d2980f5 | ths | uint32_t res; |
428 | 6d2980f5 | ths | } rda; |
429 | 6d2980f5 | ths | rda.rbadr = cpu_to_le32(rmd->rbadr); |
430 | 6d2980f5 | ths | rda.buf_length = cpu_to_le16(rmd->buf_length); |
431 | 6d2980f5 | ths | rda.status = cpu_to_le16(rmd->status); |
432 | 6d2980f5 | ths | rda.msg_length = cpu_to_le32(rmd->msg_length); |
433 | 6d2980f5 | ths | rda.res = cpu_to_le32(rmd->res); |
434 | 6d2980f5 | ths | if (BCR_SWSTYLE(s) == 3) { |
435 | 6d2980f5 | ths | uint32_t tmp = rda.rbadr; |
436 | 6d2980f5 | ths | rda.rbadr = rda.msg_length; |
437 | 6d2980f5 | ths | rda.msg_length = tmp; |
438 | e3c2613f | bellard | } |
439 | 6d2980f5 | ths | s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); |
440 | e3c2613f | bellard | } |
441 | e3c2613f | bellard | } |
442 | e3c2613f | bellard | |
443 | e3c2613f | bellard | |
444 | e3c2613f | bellard | #define TMDLOAD(TMD,ADDR) pcnet_tmd_load(s,TMD,ADDR)
|
445 | e3c2613f | bellard | |
446 | e3c2613f | bellard | #define TMDSTORE(TMD,ADDR) pcnet_tmd_store(s,TMD,ADDR)
|
447 | e3c2613f | bellard | |
448 | e3c2613f | bellard | #define RMDLOAD(RMD,ADDR) pcnet_rmd_load(s,RMD,ADDR)
|
449 | e3c2613f | bellard | |
450 | e3c2613f | bellard | #define RMDSTORE(RMD,ADDR) pcnet_rmd_store(s,RMD,ADDR)
|
451 | e3c2613f | bellard | |
452 | e3c2613f | bellard | #if 1 |
453 | e3c2613f | bellard | |
454 | e3c2613f | bellard | #define CHECK_RMD(ADDR,RES) do { \ |
455 | e3c2613f | bellard | struct pcnet_RMD rmd; \
|
456 | e3c2613f | bellard | RMDLOAD(&rmd,(ADDR)); \ |
457 | 6d2980f5 | ths | (RES) |= (GET_FIELD(rmd.buf_length, RMDL, ONES) != 15) \
|
458 | 6d2980f5 | ths | || (GET_FIELD(rmd.msg_length, RMDM, ZEROS) != 0); \
|
459 | e3c2613f | bellard | } while (0) |
460 | e3c2613f | bellard | |
461 | e3c2613f | bellard | #define CHECK_TMD(ADDR,RES) do { \ |
462 | e3c2613f | bellard | struct pcnet_TMD tmd; \
|
463 | e3c2613f | bellard | TMDLOAD(&tmd,(ADDR)); \ |
464 | 6d2980f5 | ths | (RES) |= (GET_FIELD(tmd.length, TMDL, ONES) != 15); \
|
465 | e3c2613f | bellard | } while (0) |
466 | e3c2613f | bellard | |
467 | e3c2613f | bellard | #else
|
468 | e3c2613f | bellard | |
469 | e3c2613f | bellard | #define CHECK_RMD(ADDR,RES) do { \ |
470 | e3c2613f | bellard | switch (BCR_SWSTYLE(s)) { \
|
471 | e3c2613f | bellard | case 0x00: \ |
472 | e3c2613f | bellard | do { \
|
473 | e3c2613f | bellard | uint16_t rda[4]; \
|
474 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, (ADDR), \ |
475 | 6d2980f5 | ths | (void *)&rda[0], sizeof(rda), 0); \ |
476 | e3c2613f | bellard | (RES) |= (rda[2] & 0xf000)!=0xf000; \ |
477 | e3c2613f | bellard | (RES) |= (rda[3] & 0xf000)!=0x0000; \ |
478 | e3c2613f | bellard | } while (0); \ |
479 | e3c2613f | bellard | break; \
|
480 | e3c2613f | bellard | case 0x01: \ |
481 | e3c2613f | bellard | case 0x02: \ |
482 | e3c2613f | bellard | do { \
|
483 | e3c2613f | bellard | uint32_t rda[4]; \
|
484 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, (ADDR), \ |
485 | 9b94dc32 | bellard | (void *)&rda[0], sizeof(rda), 0); \ |
486 | e3c2613f | bellard | (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ |
487 | e3c2613f | bellard | (RES) |= (rda[2] & 0x0000f000L)!=0x00000000L; \ |
488 | e3c2613f | bellard | } while (0); \ |
489 | e3c2613f | bellard | break; \
|
490 | e3c2613f | bellard | case 0x03: \ |
491 | e3c2613f | bellard | do { \
|
492 | e3c2613f | bellard | uint32_t rda[4]; \
|
493 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, (ADDR), \ |
494 | 9b94dc32 | bellard | (void *)&rda[0], sizeof(rda), 0); \ |
495 | e3c2613f | bellard | (RES) |= (rda[0] & 0x0000f000L)!=0x00000000L; \ |
496 | e3c2613f | bellard | (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ |
497 | e3c2613f | bellard | } while (0); \ |
498 | e3c2613f | bellard | break; \
|
499 | e3c2613f | bellard | } \ |
500 | e3c2613f | bellard | } while (0) |
501 | e3c2613f | bellard | |
502 | e3c2613f | bellard | #define CHECK_TMD(ADDR,RES) do { \ |
503 | e3c2613f | bellard | switch (BCR_SWSTYLE(s)) { \
|
504 | e3c2613f | bellard | case 0x00: \ |
505 | e3c2613f | bellard | do { \
|
506 | e3c2613f | bellard | uint16_t xda[4]; \
|
507 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, (ADDR), \ |
508 | 6d2980f5 | ths | (void *)&xda[0], sizeof(xda), 0); \ |
509 | 6d2980f5 | ths | (RES) |= (xda[2] & 0xf000)!=0xf000; \ |
510 | e3c2613f | bellard | } while (0); \ |
511 | e3c2613f | bellard | break; \
|
512 | e3c2613f | bellard | case 0x01: \ |
513 | e3c2613f | bellard | case 0x02: \ |
514 | e3c2613f | bellard | case 0x03: \ |
515 | e3c2613f | bellard | do { \
|
516 | e3c2613f | bellard | uint32_t xda[4]; \
|
517 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, (ADDR), \ |
518 | 6d2980f5 | ths | (void *)&xda[0], sizeof(xda), 0); \ |
519 | e3c2613f | bellard | (RES) |= (xda[1] & 0x0000f000L)!=0x0000f000L; \ |
520 | e3c2613f | bellard | } while (0); \ |
521 | e3c2613f | bellard | break; \
|
522 | e3c2613f | bellard | } \ |
523 | e3c2613f | bellard | } while (0) |
524 | e3c2613f | bellard | |
525 | e3c2613f | bellard | #endif
|
526 | e3c2613f | bellard | |
527 | e3c2613f | bellard | #define PRINT_PKTHDR(BUF) do { \ |
528 | 6d2980f5 | ths | struct qemu_ether_header *hdr = (void *)(BUF); \ |
529 | 6d2980f5 | ths | printf("packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, " \
|
530 | 6d2980f5 | ths | "shost=%02x:%02x:%02x:%02x:%02x:%02x, " \
|
531 | 6d2980f5 | ths | "type=0x%04x\n", \
|
532 | e3c2613f | bellard | hdr->ether_dhost[0],hdr->ether_dhost[1],hdr->ether_dhost[2], \ |
533 | e3c2613f | bellard | hdr->ether_dhost[3],hdr->ether_dhost[4],hdr->ether_dhost[5], \ |
534 | e3c2613f | bellard | hdr->ether_shost[0],hdr->ether_shost[1],hdr->ether_shost[2], \ |
535 | e3c2613f | bellard | hdr->ether_shost[3],hdr->ether_shost[4],hdr->ether_shost[5], \ |
536 | 6d2980f5 | ths | be16_to_cpu(hdr->ether_type)); \ |
537 | e3c2613f | bellard | } while (0) |
538 | e3c2613f | bellard | |
539 | e3c2613f | bellard | #define MULTICAST_FILTER_LEN 8 |
540 | e3c2613f | bellard | |
541 | e3c2613f | bellard | static inline uint32_t lnc_mchash(const uint8_t *ether_addr) |
542 | e3c2613f | bellard | { |
543 | e3c2613f | bellard | #define LNC_POLYNOMIAL 0xEDB88320UL |
544 | e3c2613f | bellard | uint32_t crc = 0xFFFFFFFF;
|
545 | e3c2613f | bellard | int idx, bit;
|
546 | e3c2613f | bellard | uint8_t data; |
547 | e3c2613f | bellard | |
548 | 219fb125 | bellard | for (idx = 0; idx < 6; idx++) { |
549 | e3c2613f | bellard | for (data = *ether_addr++, bit = 0; bit < MULTICAST_FILTER_LEN; bit++) { |
550 | e3c2613f | bellard | crc = (crc >> 1) ^ (((crc ^ data) & 1) ? LNC_POLYNOMIAL : 0); |
551 | e3c2613f | bellard | data >>= 1;
|
552 | e3c2613f | bellard | } |
553 | e3c2613f | bellard | } |
554 | e3c2613f | bellard | return crc;
|
555 | e3c2613f | bellard | #undef LNC_POLYNOMIAL
|
556 | e3c2613f | bellard | } |
557 | e3c2613f | bellard | |
558 | e3c2613f | bellard | #define CRC(crc, ch) (crc = (crc >> 8) ^ crctab[(crc ^ (ch)) & 0xff]) |
559 | e3c2613f | bellard | |
560 | e3c2613f | bellard | /* generated using the AUTODIN II polynomial
|
561 | e3c2613f | bellard | * x^32 + x^26 + x^23 + x^22 + x^16 +
|
562 | e3c2613f | bellard | * x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1
|
563 | e3c2613f | bellard | */
|
564 | e3c2613f | bellard | static const uint32_t crctab[256] = { |
565 | e3c2613f | bellard | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, |
566 | e3c2613f | bellard | 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, |
567 | e3c2613f | bellard | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, |
568 | e3c2613f | bellard | 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, |
569 | e3c2613f | bellard | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, |
570 | e3c2613f | bellard | 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, |
571 | e3c2613f | bellard | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, |
572 | e3c2613f | bellard | 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, |
573 | e3c2613f | bellard | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, |
574 | e3c2613f | bellard | 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, |
575 | e3c2613f | bellard | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, |
576 | e3c2613f | bellard | 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, |
577 | e3c2613f | bellard | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, |
578 | e3c2613f | bellard | 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, |
579 | e3c2613f | bellard | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, |
580 | e3c2613f | bellard | 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, |
581 | e3c2613f | bellard | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, |
582 | e3c2613f | bellard | 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, |
583 | e3c2613f | bellard | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, |
584 | e3c2613f | bellard | 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, |
585 | e3c2613f | bellard | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, |
586 | e3c2613f | bellard | 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, |
587 | e3c2613f | bellard | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, |
588 | e3c2613f | bellard | 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, |
589 | e3c2613f | bellard | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, |
590 | e3c2613f | bellard | 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, |
591 | e3c2613f | bellard | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, |
592 | e3c2613f | bellard | 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, |
593 | e3c2613f | bellard | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, |
594 | e3c2613f | bellard | 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, |
595 | e3c2613f | bellard | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, |
596 | e3c2613f | bellard | 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, |
597 | e3c2613f | bellard | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, |
598 | e3c2613f | bellard | 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, |
599 | e3c2613f | bellard | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, |
600 | e3c2613f | bellard | 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, |
601 | e3c2613f | bellard | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, |
602 | e3c2613f | bellard | 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, |
603 | e3c2613f | bellard | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, |
604 | e3c2613f | bellard | 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, |
605 | e3c2613f | bellard | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, |
606 | e3c2613f | bellard | 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, |
607 | e3c2613f | bellard | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, |
608 | e3c2613f | bellard | 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, |
609 | e3c2613f | bellard | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, |
610 | e3c2613f | bellard | 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, |
611 | e3c2613f | bellard | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, |
612 | e3c2613f | bellard | 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, |
613 | e3c2613f | bellard | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, |
614 | e3c2613f | bellard | 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, |
615 | e3c2613f | bellard | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, |
616 | e3c2613f | bellard | 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, |
617 | e3c2613f | bellard | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, |
618 | e3c2613f | bellard | 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, |
619 | e3c2613f | bellard | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, |
620 | e3c2613f | bellard | 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, |
621 | e3c2613f | bellard | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, |
622 | e3c2613f | bellard | 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, |
623 | e3c2613f | bellard | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, |
624 | e3c2613f | bellard | 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, |
625 | e3c2613f | bellard | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, |
626 | e3c2613f | bellard | 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, |
627 | e3c2613f | bellard | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, |
628 | e3c2613f | bellard | 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, |
629 | e3c2613f | bellard | }; |
630 | e3c2613f | bellard | |
631 | e3c2613f | bellard | static inline int padr_match(PCNetState *s, const uint8_t *buf, int size) |
632 | e3c2613f | bellard | { |
633 | 219fb125 | bellard | struct qemu_ether_header *hdr = (void *)buf; |
634 | 5fafdf24 | ths | uint8_t padr[6] = {
|
635 | e3c2613f | bellard | s->csr[12] & 0xff, s->csr[12] >> 8, |
636 | e3c2613f | bellard | s->csr[13] & 0xff, s->csr[13] >> 8, |
637 | 5fafdf24 | ths | s->csr[14] & 0xff, s->csr[14] >> 8 |
638 | e3c2613f | bellard | }; |
639 | 29b9a345 | bellard | int result = (!CSR_DRCVPA(s)) && !memcmp(hdr->ether_dhost, padr, 6); |
640 | e3c2613f | bellard | #ifdef PCNET_DEBUG_MATCH
|
641 | e3c2613f | bellard | printf("packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, "
|
642 | e3c2613f | bellard | "padr=%02x:%02x:%02x:%02x:%02x:%02x\n",
|
643 | e3c2613f | bellard | hdr->ether_dhost[0],hdr->ether_dhost[1],hdr->ether_dhost[2], |
644 | e3c2613f | bellard | hdr->ether_dhost[3],hdr->ether_dhost[4],hdr->ether_dhost[5], |
645 | e3c2613f | bellard | padr[0],padr[1],padr[2],padr[3],padr[4],padr[5]); |
646 | e3c2613f | bellard | printf("padr_match result=%d\n", result);
|
647 | e3c2613f | bellard | #endif
|
648 | e3c2613f | bellard | return result;
|
649 | e3c2613f | bellard | } |
650 | e3c2613f | bellard | |
651 | e3c2613f | bellard | static inline int padr_bcast(PCNetState *s, const uint8_t *buf, int size) |
652 | e3c2613f | bellard | { |
653 | 9b94dc32 | bellard | static const uint8_t BCAST[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
654 | 219fb125 | bellard | struct qemu_ether_header *hdr = (void *)buf; |
655 | 29b9a345 | bellard | int result = !CSR_DRCVBC(s) && !memcmp(hdr->ether_dhost, BCAST, 6); |
656 | e3c2613f | bellard | #ifdef PCNET_DEBUG_MATCH
|
657 | e3c2613f | bellard | printf("padr_bcast result=%d\n", result);
|
658 | e3c2613f | bellard | #endif
|
659 | e3c2613f | bellard | return result;
|
660 | e3c2613f | bellard | } |
661 | e3c2613f | bellard | |
662 | e3c2613f | bellard | static inline int ladr_match(PCNetState *s, const uint8_t *buf, int size) |
663 | e3c2613f | bellard | { |
664 | 219fb125 | bellard | struct qemu_ether_header *hdr = (void *)buf; |
665 | 5fafdf24 | ths | if ((*(hdr->ether_dhost)&0x01) && |
666 | e3c2613f | bellard | ((uint64_t *)&s->csr[8])[0] != 0LL) { |
667 | 5fafdf24 | ths | uint8_t ladr[8] = {
|
668 | e3c2613f | bellard | s->csr[8] & 0xff, s->csr[8] >> 8, |
669 | e3c2613f | bellard | s->csr[9] & 0xff, s->csr[9] >> 8, |
670 | 5fafdf24 | ths | s->csr[10] & 0xff, s->csr[10] >> 8, |
671 | 5fafdf24 | ths | s->csr[11] & 0xff, s->csr[11] >> 8 |
672 | e3c2613f | bellard | }; |
673 | e3c2613f | bellard | int index = lnc_mchash(hdr->ether_dhost) >> 26; |
674 | e3c2613f | bellard | return !!(ladr[index >> 3] & (1 << (index & 7))); |
675 | e3c2613f | bellard | } |
676 | e3c2613f | bellard | return 0; |
677 | e3c2613f | bellard | } |
678 | e3c2613f | bellard | |
679 | c227f099 | Anthony Liguori | static inline target_phys_addr_t pcnet_rdra_addr(PCNetState *s, int idx) |
680 | e3c2613f | bellard | { |
681 | e3c2613f | bellard | while (idx < 1) idx += CSR_RCVRL(s); |
682 | e3c2613f | bellard | return s->rdra + ((CSR_RCVRL(s) - idx) * (BCR_SWSTYLE(s) ? 16 : 8)); |
683 | e3c2613f | bellard | } |
684 | e3c2613f | bellard | |
685 | e3c2613f | bellard | static inline int64_t pcnet_get_next_poll_time(PCNetState *s, int64_t current_time) |
686 | e3c2613f | bellard | { |
687 | 5fafdf24 | ths | int64_t next_time = current_time + |
688 | 5fafdf24 | ths | muldiv64(65536 - (CSR_SPND(s) ? 0 : CSR_POLL(s)), |
689 | 6ee093c9 | Juan Quintela | get_ticks_per_sec(), 33000000L);
|
690 | e3c2613f | bellard | if (next_time <= current_time)
|
691 | e3c2613f | bellard | next_time = current_time + 1;
|
692 | e3c2613f | bellard | return next_time;
|
693 | e3c2613f | bellard | } |
694 | e3c2613f | bellard | |
695 | e3c2613f | bellard | static void pcnet_poll(PCNetState *s); |
696 | e3c2613f | bellard | static void pcnet_poll_timer(void *opaque); |
697 | e3c2613f | bellard | |
698 | e3c2613f | bellard | static uint32_t pcnet_csr_readw(PCNetState *s, uint32_t rap);
|
699 | e3c2613f | bellard | static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value); |
700 | e3c2613f | bellard | static void pcnet_bcr_writew(PCNetState *s, uint32_t rap, uint32_t val); |
701 | e3c2613f | bellard | |
702 | e3c2613f | bellard | static void pcnet_s_reset(PCNetState *s) |
703 | e3c2613f | bellard | { |
704 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
705 | e3c2613f | bellard | printf("pcnet_s_reset\n");
|
706 | e3c2613f | bellard | #endif
|
707 | e3c2613f | bellard | |
708 | e3c2613f | bellard | s->lnkst = 0x40;
|
709 | e3c2613f | bellard | s->rdra = 0;
|
710 | e3c2613f | bellard | s->tdra = 0;
|
711 | e3c2613f | bellard | s->rap = 0;
|
712 | 3b46e624 | ths | |
713 | e3c2613f | bellard | s->bcr[BCR_BSBC] &= ~0x0080;
|
714 | e3c2613f | bellard | |
715 | e3c2613f | bellard | s->csr[0] = 0x0004; |
716 | e3c2613f | bellard | s->csr[3] = 0x0000; |
717 | e3c2613f | bellard | s->csr[4] = 0x0115; |
718 | e3c2613f | bellard | s->csr[5] = 0x0000; |
719 | e3c2613f | bellard | s->csr[6] = 0x0000; |
720 | e3c2613f | bellard | s->csr[8] = 0; |
721 | e3c2613f | bellard | s->csr[9] = 0; |
722 | e3c2613f | bellard | s->csr[10] = 0; |
723 | e3c2613f | bellard | s->csr[11] = 0; |
724 | e3c2613f | bellard | s->csr[12] = le16_to_cpu(((uint16_t *)&s->prom[0])[0]); |
725 | e3c2613f | bellard | s->csr[13] = le16_to_cpu(((uint16_t *)&s->prom[0])[1]); |
726 | e3c2613f | bellard | s->csr[14] = le16_to_cpu(((uint16_t *)&s->prom[0])[2]); |
727 | e3c2613f | bellard | s->csr[15] &= 0x21c4; |
728 | e3c2613f | bellard | s->csr[72] = 1; |
729 | e3c2613f | bellard | s->csr[74] = 1; |
730 | e3c2613f | bellard | s->csr[76] = 1; |
731 | e3c2613f | bellard | s->csr[78] = 1; |
732 | e3c2613f | bellard | s->csr[80] = 0x1410; |
733 | e3c2613f | bellard | s->csr[88] = 0x1003; |
734 | e3c2613f | bellard | s->csr[89] = 0x0262; |
735 | e3c2613f | bellard | s->csr[94] = 0x0000; |
736 | e3c2613f | bellard | s->csr[100] = 0x0200; |
737 | e3c2613f | bellard | s->csr[103] = 0x0105; |
738 | e3c2613f | bellard | s->csr[103] = 0x0105; |
739 | e3c2613f | bellard | s->csr[112] = 0x0000; |
740 | e3c2613f | bellard | s->csr[114] = 0x0000; |
741 | e3c2613f | bellard | s->csr[122] = 0x0000; |
742 | e3c2613f | bellard | s->csr[124] = 0x0000; |
743 | ec607da7 | bellard | |
744 | ec607da7 | bellard | s->tx_busy = 0;
|
745 | e3c2613f | bellard | } |
746 | e3c2613f | bellard | |
747 | e3c2613f | bellard | static void pcnet_update_irq(PCNetState *s) |
748 | e3c2613f | bellard | { |
749 | e3c2613f | bellard | int isr = 0; |
750 | e3c2613f | bellard | s->csr[0] &= ~0x0080; |
751 | 3b46e624 | ths | |
752 | e3c2613f | bellard | #if 1 |
753 | e3c2613f | bellard | if (((s->csr[0] & ~s->csr[3]) & 0x5f00) || |
754 | e3c2613f | bellard | (((s->csr[4]>>1) & ~s->csr[4]) & 0x0115) || |
755 | e3c2613f | bellard | (((s->csr[5]>>1) & s->csr[5]) & 0x0048)) |
756 | e3c2613f | bellard | #else
|
757 | e3c2613f | bellard | if ((!(s->csr[3] & 0x4000) && !!(s->csr[0] & 0x4000)) /* BABL */ || |
758 | e3c2613f | bellard | (!(s->csr[3] & 0x1000) && !!(s->csr[0] & 0x1000)) /* MISS */ || |
759 | e3c2613f | bellard | (!(s->csr[3] & 0x0100) && !!(s->csr[0] & 0x0100)) /* IDON */ || |
760 | e3c2613f | bellard | (!(s->csr[3] & 0x0200) && !!(s->csr[0] & 0x0200)) /* TINT */ || |
761 | e3c2613f | bellard | (!(s->csr[3] & 0x0400) && !!(s->csr[0] & 0x0400)) /* RINT */ || |
762 | e3c2613f | bellard | (!(s->csr[3] & 0x0800) && !!(s->csr[0] & 0x0800)) /* MERR */ || |
763 | e3c2613f | bellard | (!(s->csr[4] & 0x0001) && !!(s->csr[4] & 0x0002)) /* JAB */ || |
764 | e3c2613f | bellard | (!(s->csr[4] & 0x0004) && !!(s->csr[4] & 0x0008)) /* TXSTRT */ || |
765 | e3c2613f | bellard | (!(s->csr[4] & 0x0010) && !!(s->csr[4] & 0x0020)) /* RCVO */ || |
766 | e3c2613f | bellard | (!(s->csr[4] & 0x0100) && !!(s->csr[4] & 0x0200)) /* MFCO */ || |
767 | e3c2613f | bellard | (!!(s->csr[5] & 0x0040) && !!(s->csr[5] & 0x0080)) /* EXDINT */ || |
768 | e3c2613f | bellard | (!!(s->csr[5] & 0x0008) && !!(s->csr[5] & 0x0010)) /* MPINT */) |
769 | e3c2613f | bellard | #endif
|
770 | e3c2613f | bellard | { |
771 | 3b46e624 | ths | |
772 | e3c2613f | bellard | isr = CSR_INEA(s); |
773 | e3c2613f | bellard | s->csr[0] |= 0x0080; |
774 | e3c2613f | bellard | } |
775 | 3b46e624 | ths | |
776 | e3c2613f | bellard | if (!!(s->csr[4] & 0x0080) && CSR_INEA(s)) { /* UINT */ |
777 | e3c2613f | bellard | s->csr[4] &= ~0x0080; |
778 | e3c2613f | bellard | s->csr[4] |= 0x0040; |
779 | e3c2613f | bellard | s->csr[0] |= 0x0080; |
780 | e3c2613f | bellard | isr = 1;
|
781 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
782 | e3c2613f | bellard | printf("pcnet user int\n");
|
783 | e3c2613f | bellard | #endif
|
784 | e3c2613f | bellard | } |
785 | e3c2613f | bellard | |
786 | e3c2613f | bellard | #if 1 |
787 | 5fafdf24 | ths | if (((s->csr[5]>>1) & s->csr[5]) & 0x0500) |
788 | e3c2613f | bellard | #else
|
789 | e3c2613f | bellard | if ((!!(s->csr[5] & 0x0400) && !!(s->csr[5] & 0x0800)) /* SINT */ || |
790 | e3c2613f | bellard | (!!(s->csr[5] & 0x0100) && !!(s->csr[5] & 0x0200)) /* SLPINT */ ) |
791 | e3c2613f | bellard | #endif
|
792 | e3c2613f | bellard | { |
793 | e3c2613f | bellard | isr = 1;
|
794 | e3c2613f | bellard | s->csr[0] |= 0x0080; |
795 | e3c2613f | bellard | } |
796 | e3c2613f | bellard | |
797 | e3c2613f | bellard | if (isr != s->isr) {
|
798 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
799 | e3c2613f | bellard | printf("pcnet: INTA=%d\n", isr);
|
800 | e3c2613f | bellard | #endif
|
801 | e3c2613f | bellard | } |
802 | d537cf6c | pbrook | qemu_set_irq(s->irq, isr); |
803 | 91cc0295 | bellard | s->isr = isr; |
804 | e3c2613f | bellard | } |
805 | e3c2613f | bellard | |
806 | e3c2613f | bellard | static void pcnet_init(PCNetState *s) |
807 | e3c2613f | bellard | { |
808 | 91cc0295 | bellard | int rlen, tlen;
|
809 | 6d2980f5 | ths | uint16_t padr[3], ladrf[4], mode; |
810 | 91cc0295 | bellard | uint32_t rdra, tdra; |
811 | 91cc0295 | bellard | |
812 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
813 | e3c2613f | bellard | printf("pcnet_init init_addr=0x%08x\n", PHYSADDR(s,CSR_IADR(s)));
|
814 | e3c2613f | bellard | #endif
|
815 | 3b46e624 | ths | |
816 | e3c2613f | bellard | if (BCR_SSIZE32(s)) {
|
817 | e3c2613f | bellard | struct pcnet_initblk32 initblk;
|
818 | 91cc0295 | bellard | s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)), |
819 | 9b94dc32 | bellard | (uint8_t *)&initblk, sizeof(initblk), 0); |
820 | 6d2980f5 | ths | mode = le16_to_cpu(initblk.mode); |
821 | 91cc0295 | bellard | rlen = initblk.rlen >> 4;
|
822 | 91cc0295 | bellard | tlen = initblk.tlen >> 4;
|
823 | 6d2980f5 | ths | ladrf[0] = le16_to_cpu(initblk.ladrf[0]); |
824 | 6d2980f5 | ths | ladrf[1] = le16_to_cpu(initblk.ladrf[1]); |
825 | 6d2980f5 | ths | ladrf[2] = le16_to_cpu(initblk.ladrf[2]); |
826 | 6d2980f5 | ths | ladrf[3] = le16_to_cpu(initblk.ladrf[3]); |
827 | 6d2980f5 | ths | padr[0] = le16_to_cpu(initblk.padr[0]); |
828 | 6d2980f5 | ths | padr[1] = le16_to_cpu(initblk.padr[1]); |
829 | 6d2980f5 | ths | padr[2] = le16_to_cpu(initblk.padr[2]); |
830 | 9b94dc32 | bellard | rdra = le32_to_cpu(initblk.rdra); |
831 | 9b94dc32 | bellard | tdra = le32_to_cpu(initblk.tdra); |
832 | e3c2613f | bellard | } else {
|
833 | e3c2613f | bellard | struct pcnet_initblk16 initblk;
|
834 | 91cc0295 | bellard | s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)), |
835 | 9b94dc32 | bellard | (uint8_t *)&initblk, sizeof(initblk), 0); |
836 | 6d2980f5 | ths | mode = le16_to_cpu(initblk.mode); |
837 | 6d2980f5 | ths | ladrf[0] = le16_to_cpu(initblk.ladrf[0]); |
838 | 6d2980f5 | ths | ladrf[1] = le16_to_cpu(initblk.ladrf[1]); |
839 | 6d2980f5 | ths | ladrf[2] = le16_to_cpu(initblk.ladrf[2]); |
840 | 6d2980f5 | ths | ladrf[3] = le16_to_cpu(initblk.ladrf[3]); |
841 | 6d2980f5 | ths | padr[0] = le16_to_cpu(initblk.padr[0]); |
842 | 6d2980f5 | ths | padr[1] = le16_to_cpu(initblk.padr[1]); |
843 | 6d2980f5 | ths | padr[2] = le16_to_cpu(initblk.padr[2]); |
844 | 9b94dc32 | bellard | rdra = le32_to_cpu(initblk.rdra); |
845 | 9b94dc32 | bellard | tdra = le32_to_cpu(initblk.tdra); |
846 | 91cc0295 | bellard | rlen = rdra >> 29;
|
847 | 91cc0295 | bellard | tlen = tdra >> 29;
|
848 | 91cc0295 | bellard | rdra &= 0x00ffffff;
|
849 | 91cc0295 | bellard | tdra &= 0x00ffffff;
|
850 | 91cc0295 | bellard | } |
851 | 6d2980f5 | ths | |
852 | 91cc0295 | bellard | #if defined(PCNET_DEBUG)
|
853 | 6d2980f5 | ths | printf("rlen=%d tlen=%d\n", rlen, tlen);
|
854 | e3c2613f | bellard | #endif
|
855 | 6d2980f5 | ths | |
856 | 91cc0295 | bellard | CSR_RCVRL(s) = (rlen < 9) ? (1 << rlen) : 512; |
857 | 91cc0295 | bellard | CSR_XMTRL(s) = (tlen < 9) ? (1 << tlen) : 512; |
858 | 91cc0295 | bellard | s->csr[ 6] = (tlen << 12) | (rlen << 8); |
859 | 6d2980f5 | ths | s->csr[15] = mode;
|
860 | 6d2980f5 | ths | s->csr[ 8] = ladrf[0]; |
861 | 6d2980f5 | ths | s->csr[ 9] = ladrf[1]; |
862 | 6d2980f5 | ths | s->csr[10] = ladrf[2]; |
863 | 6d2980f5 | ths | s->csr[11] = ladrf[3]; |
864 | 6d2980f5 | ths | s->csr[12] = padr[0]; |
865 | 6d2980f5 | ths | s->csr[13] = padr[1]; |
866 | 6d2980f5 | ths | s->csr[14] = padr[2]; |
867 | 91cc0295 | bellard | s->rdra = PHYSADDR(s, rdra); |
868 | 91cc0295 | bellard | s->tdra = PHYSADDR(s, tdra); |
869 | e3c2613f | bellard | |
870 | e3c2613f | bellard | CSR_RCVRC(s) = CSR_RCVRL(s); |
871 | e3c2613f | bellard | CSR_XMTRC(s) = CSR_XMTRL(s); |
872 | e3c2613f | bellard | |
873 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
874 | 5fafdf24 | ths | printf("pcnet ss32=%d rdra=0x%08x[%d] tdra=0x%08x[%d]\n",
|
875 | e3c2613f | bellard | BCR_SSIZE32(s), |
876 | e3c2613f | bellard | s->rdra, CSR_RCVRL(s), s->tdra, CSR_XMTRL(s)); |
877 | e3c2613f | bellard | #endif
|
878 | e3c2613f | bellard | |
879 | 3b46e624 | ths | s->csr[0] |= 0x0101; |
880 | e3c2613f | bellard | s->csr[0] &= ~0x0004; /* clear STOP bit */ |
881 | e3c2613f | bellard | } |
882 | e3c2613f | bellard | |
883 | e3c2613f | bellard | static void pcnet_start(PCNetState *s) |
884 | e3c2613f | bellard | { |
885 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
886 | e3c2613f | bellard | printf("pcnet_start\n");
|
887 | e3c2613f | bellard | #endif
|
888 | e3c2613f | bellard | |
889 | e3c2613f | bellard | if (!CSR_DTX(s))
|
890 | e3c2613f | bellard | s->csr[0] |= 0x0010; /* set TXON */ |
891 | 3b46e624 | ths | |
892 | e3c2613f | bellard | if (!CSR_DRX(s))
|
893 | e3c2613f | bellard | s->csr[0] |= 0x0020; /* set RXON */ |
894 | e3c2613f | bellard | |
895 | e3c2613f | bellard | s->csr[0] &= ~0x0004; /* clear STOP bit */ |
896 | e3c2613f | bellard | s->csr[0] |= 0x0002; |
897 | ad323081 | Jan Kiszka | pcnet_poll_timer(s); |
898 | e3c2613f | bellard | } |
899 | e3c2613f | bellard | |
900 | e3c2613f | bellard | static void pcnet_stop(PCNetState *s) |
901 | e3c2613f | bellard | { |
902 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
903 | e3c2613f | bellard | printf("pcnet_stop\n");
|
904 | e3c2613f | bellard | #endif
|
905 | e3c2613f | bellard | s->csr[0] &= ~0x7feb; |
906 | e3c2613f | bellard | s->csr[0] |= 0x0014; |
907 | e3c2613f | bellard | s->csr[4] &= ~0x02c2; |
908 | e3c2613f | bellard | s->csr[5] &= ~0x0011; |
909 | e3c2613f | bellard | pcnet_poll_timer(s); |
910 | e3c2613f | bellard | } |
911 | e3c2613f | bellard | |
912 | e3c2613f | bellard | static void pcnet_rdte_poll(PCNetState *s) |
913 | e3c2613f | bellard | { |
914 | e3c2613f | bellard | s->csr[28] = s->csr[29] = 0; |
915 | e3c2613f | bellard | if (s->rdra) {
|
916 | e3c2613f | bellard | int bad = 0; |
917 | e3c2613f | bellard | #if 1 |
918 | c227f099 | Anthony Liguori | target_phys_addr_t crda = pcnet_rdra_addr(s, CSR_RCVRC(s)); |
919 | c227f099 | Anthony Liguori | target_phys_addr_t nrda = pcnet_rdra_addr(s, -1 + CSR_RCVRC(s));
|
920 | c227f099 | Anthony Liguori | target_phys_addr_t nnrd = pcnet_rdra_addr(s, -2 + CSR_RCVRC(s));
|
921 | e3c2613f | bellard | #else
|
922 | c227f099 | Anthony Liguori | target_phys_addr_t crda = s->rdra + |
923 | e3c2613f | bellard | (CSR_RCVRL(s) - CSR_RCVRC(s)) * |
924 | e3c2613f | bellard | (BCR_SWSTYLE(s) ? 16 : 8 ); |
925 | e3c2613f | bellard | int nrdc = CSR_RCVRC(s)<=1 ? CSR_RCVRL(s) : CSR_RCVRC(s)-1; |
926 | c227f099 | Anthony Liguori | target_phys_addr_t nrda = s->rdra + |
927 | e3c2613f | bellard | (CSR_RCVRL(s) - nrdc) * |
928 | e3c2613f | bellard | (BCR_SWSTYLE(s) ? 16 : 8 ); |
929 | e3c2613f | bellard | int nnrc = nrdc<=1 ? CSR_RCVRL(s) : nrdc-1; |
930 | c227f099 | Anthony Liguori | target_phys_addr_t nnrd = s->rdra + |
931 | e3c2613f | bellard | (CSR_RCVRL(s) - nnrc) * |
932 | e3c2613f | bellard | (BCR_SWSTYLE(s) ? 16 : 8 ); |
933 | e3c2613f | bellard | #endif
|
934 | e3c2613f | bellard | |
935 | f1afe02a | aurel32 | CHECK_RMD(crda, bad); |
936 | e3c2613f | bellard | if (!bad) {
|
937 | f1afe02a | aurel32 | CHECK_RMD(nrda, bad); |
938 | e3c2613f | bellard | if (bad || (nrda == crda)) nrda = 0; |
939 | f1afe02a | aurel32 | CHECK_RMD(nnrd, bad); |
940 | e3c2613f | bellard | if (bad || (nnrd == crda)) nnrd = 0; |
941 | e3c2613f | bellard | |
942 | e3c2613f | bellard | s->csr[28] = crda & 0xffff; |
943 | e3c2613f | bellard | s->csr[29] = crda >> 16; |
944 | e3c2613f | bellard | s->csr[26] = nrda & 0xffff; |
945 | e3c2613f | bellard | s->csr[27] = nrda >> 16; |
946 | e3c2613f | bellard | s->csr[36] = nnrd & 0xffff; |
947 | e3c2613f | bellard | s->csr[37] = nnrd >> 16; |
948 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
949 | e3c2613f | bellard | if (bad) {
|
950 | cb3df91a | blueswir1 | printf("pcnet: BAD RMD RECORDS AFTER 0x" TARGET_FMT_plx "\n", |
951 | f1afe02a | aurel32 | crda); |
952 | e3c2613f | bellard | } |
953 | e3c2613f | bellard | } else {
|
954 | cb3df91a | blueswir1 | printf("pcnet: BAD RMD RDA=0x" TARGET_FMT_plx "\n", |
955 | f1afe02a | aurel32 | crda); |
956 | e3c2613f | bellard | #endif
|
957 | e3c2613f | bellard | } |
958 | e3c2613f | bellard | } |
959 | 3b46e624 | ths | |
960 | e3c2613f | bellard | if (CSR_CRDA(s)) {
|
961 | e3c2613f | bellard | struct pcnet_RMD rmd;
|
962 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,CSR_CRDA(s))); |
963 | 6d2980f5 | ths | CSR_CRBC(s) = GET_FIELD(rmd.buf_length, RMDL, BCNT); |
964 | 6d2980f5 | ths | CSR_CRST(s) = rmd.status; |
965 | e3c2613f | bellard | #ifdef PCNET_DEBUG_RMD_X
|
966 | 6d2980f5 | ths | printf("CRDA=0x%08x CRST=0x%04x RCVRC=%d RMDL=0x%04x RMDS=0x%04x RMDM=0x%08x\n",
|
967 | e3c2613f | bellard | PHYSADDR(s,CSR_CRDA(s)), CSR_CRST(s), CSR_RCVRC(s), |
968 | 6d2980f5 | ths | rmd.buf_length, rmd.status, rmd.msg_length); |
969 | e3c2613f | bellard | PRINT_RMD(&rmd); |
970 | e3c2613f | bellard | #endif
|
971 | e3c2613f | bellard | } else {
|
972 | e3c2613f | bellard | CSR_CRBC(s) = CSR_CRST(s) = 0;
|
973 | e3c2613f | bellard | } |
974 | 3b46e624 | ths | |
975 | e3c2613f | bellard | if (CSR_NRDA(s)) {
|
976 | e3c2613f | bellard | struct pcnet_RMD rmd;
|
977 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,CSR_NRDA(s))); |
978 | 6d2980f5 | ths | CSR_NRBC(s) = GET_FIELD(rmd.buf_length, RMDL, BCNT); |
979 | 6d2980f5 | ths | CSR_NRST(s) = rmd.status; |
980 | e3c2613f | bellard | } else {
|
981 | e3c2613f | bellard | CSR_NRBC(s) = CSR_NRST(s) = 0;
|
982 | e3c2613f | bellard | } |
983 | e3c2613f | bellard | |
984 | e3c2613f | bellard | } |
985 | e3c2613f | bellard | |
986 | e3c2613f | bellard | static int pcnet_tdte_poll(PCNetState *s) |
987 | e3c2613f | bellard | { |
988 | e3c2613f | bellard | s->csr[34] = s->csr[35] = 0; |
989 | e3c2613f | bellard | if (s->tdra) {
|
990 | c227f099 | Anthony Liguori | target_phys_addr_t cxda = s->tdra + |
991 | e3c2613f | bellard | (CSR_XMTRL(s) - CSR_XMTRC(s)) * |
992 | 6d2980f5 | ths | (BCR_SWSTYLE(s) ? 16 : 8); |
993 | e3c2613f | bellard | int bad = 0; |
994 | f1afe02a | aurel32 | CHECK_TMD(cxda, bad); |
995 | e3c2613f | bellard | if (!bad) {
|
996 | e3c2613f | bellard | if (CSR_CXDA(s) != cxda) {
|
997 | e3c2613f | bellard | s->csr[60] = s->csr[34]; |
998 | e3c2613f | bellard | s->csr[61] = s->csr[35]; |
999 | e3c2613f | bellard | s->csr[62] = CSR_CXBC(s);
|
1000 | e3c2613f | bellard | s->csr[63] = CSR_CXST(s);
|
1001 | e3c2613f | bellard | } |
1002 | e3c2613f | bellard | s->csr[34] = cxda & 0xffff; |
1003 | e3c2613f | bellard | s->csr[35] = cxda >> 16; |
1004 | 6d2980f5 | ths | #ifdef PCNET_DEBUG_X
|
1005 | f1afe02a | aurel32 | printf("pcnet: BAD TMD XDA=0x%08x\n", cxda);
|
1006 | e3c2613f | bellard | #endif
|
1007 | e3c2613f | bellard | } |
1008 | e3c2613f | bellard | } |
1009 | e3c2613f | bellard | |
1010 | e3c2613f | bellard | if (CSR_CXDA(s)) {
|
1011 | e3c2613f | bellard | struct pcnet_TMD tmd;
|
1012 | e3c2613f | bellard | |
1013 | 3b46e624 | ths | TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s))); |
1014 | e3c2613f | bellard | |
1015 | 6d2980f5 | ths | CSR_CXBC(s) = GET_FIELD(tmd.length, TMDL, BCNT); |
1016 | 6d2980f5 | ths | CSR_CXST(s) = tmd.status; |
1017 | e3c2613f | bellard | } else {
|
1018 | e3c2613f | bellard | CSR_CXBC(s) = CSR_CXST(s) = 0;
|
1019 | e3c2613f | bellard | } |
1020 | 3b46e624 | ths | |
1021 | e3c2613f | bellard | return !!(CSR_CXST(s) & 0x8000); |
1022 | e3c2613f | bellard | } |
1023 | e3c2613f | bellard | |
1024 | 1fa51482 | Mark McLoughlin | int pcnet_can_receive(VLANClientState *nc)
|
1025 | e3c2613f | bellard | { |
1026 | 1fa51482 | Mark McLoughlin | PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; |
1027 | e3c2613f | bellard | if (CSR_STOP(s) || CSR_SPND(s))
|
1028 | e3c2613f | bellard | return 0; |
1029 | 3b46e624 | ths | |
1030 | e3c2613f | bellard | return sizeof(s->buffer)-16; |
1031 | e3c2613f | bellard | } |
1032 | e3c2613f | bellard | |
1033 | e3c2613f | bellard | #define MIN_BUF_SIZE 60 |
1034 | e3c2613f | bellard | |
1035 | 1fa51482 | Mark McLoughlin | ssize_t pcnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size_)
|
1036 | e3c2613f | bellard | { |
1037 | 1fa51482 | Mark McLoughlin | PCNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; |
1038 | e3c2613f | bellard | int is_padr = 0, is_bcast = 0, is_ladr = 0; |
1039 | e3c2613f | bellard | uint8_t buf1[60];
|
1040 | 89b190a2 | aurel32 | int remaining;
|
1041 | 89b190a2 | aurel32 | int crc_err = 0; |
1042 | 4f1c942b | Mark McLoughlin | int size = size_;
|
1043 | e3c2613f | bellard | |
1044 | c1ded3dc | Jan Kiszka | if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size ||
|
1045 | c1ded3dc | Jan Kiszka | (CSR_LOOP(s) && !s->looptest)) { |
1046 | 4f1c942b | Mark McLoughlin | return -1; |
1047 | c1ded3dc | Jan Kiszka | } |
1048 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
1049 | e3c2613f | bellard | printf("pcnet_receive size=%d\n", size);
|
1050 | e3c2613f | bellard | #endif
|
1051 | e3c2613f | bellard | |
1052 | e3c2613f | bellard | /* if too small buffer, then expand it */
|
1053 | e3c2613f | bellard | if (size < MIN_BUF_SIZE) {
|
1054 | e3c2613f | bellard | memcpy(buf1, buf, size); |
1055 | e3c2613f | bellard | memset(buf1 + size, 0, MIN_BUF_SIZE - size);
|
1056 | e3c2613f | bellard | buf = buf1; |
1057 | e3c2613f | bellard | size = MIN_BUF_SIZE; |
1058 | e3c2613f | bellard | } |
1059 | e3c2613f | bellard | |
1060 | 5fafdf24 | ths | if (CSR_PROM(s)
|
1061 | 5fafdf24 | ths | || (is_padr=padr_match(s, buf, size)) |
1062 | e3c2613f | bellard | || (is_bcast=padr_bcast(s, buf, size)) |
1063 | e3c2613f | bellard | || (is_ladr=ladr_match(s, buf, size))) { |
1064 | e3c2613f | bellard | |
1065 | e3c2613f | bellard | pcnet_rdte_poll(s); |
1066 | e3c2613f | bellard | |
1067 | e3c2613f | bellard | if (!(CSR_CRST(s) & 0x8000) && s->rdra) { |
1068 | e3c2613f | bellard | struct pcnet_RMD rmd;
|
1069 | e3c2613f | bellard | int rcvrc = CSR_RCVRC(s)-1,i; |
1070 | c227f099 | Anthony Liguori | target_phys_addr_t nrda; |
1071 | e3c2613f | bellard | for (i = CSR_RCVRL(s)-1; i > 0; i--, rcvrc--) { |
1072 | e3c2613f | bellard | if (rcvrc <= 1) |
1073 | e3c2613f | bellard | rcvrc = CSR_RCVRL(s); |
1074 | e3c2613f | bellard | nrda = s->rdra + |
1075 | e3c2613f | bellard | (CSR_RCVRL(s) - rcvrc) * |
1076 | e3c2613f | bellard | (BCR_SWSTYLE(s) ? 16 : 8 ); |
1077 | f1afe02a | aurel32 | RMDLOAD(&rmd, nrda); |
1078 | 6d2980f5 | ths | if (GET_FIELD(rmd.status, RMDS, OWN)) {
|
1079 | e3c2613f | bellard | #ifdef PCNET_DEBUG_RMD
|
1080 | 5fafdf24 | ths | printf("pcnet - scan buffer: RCVRC=%d PREV_RCVRC=%d\n",
|
1081 | e3c2613f | bellard | rcvrc, CSR_RCVRC(s)); |
1082 | e3c2613f | bellard | #endif
|
1083 | e3c2613f | bellard | CSR_RCVRC(s) = rcvrc; |
1084 | e3c2613f | bellard | pcnet_rdte_poll(s); |
1085 | e3c2613f | bellard | break;
|
1086 | e3c2613f | bellard | } |
1087 | e3c2613f | bellard | } |
1088 | e3c2613f | bellard | } |
1089 | e3c2613f | bellard | |
1090 | e3c2613f | bellard | if (!(CSR_CRST(s) & 0x8000)) { |
1091 | e3c2613f | bellard | #ifdef PCNET_DEBUG_RMD
|
1092 | e3c2613f | bellard | printf("pcnet - no buffer: RCVRC=%d\n", CSR_RCVRC(s));
|
1093 | e3c2613f | bellard | #endif
|
1094 | e3c2613f | bellard | s->csr[0] |= 0x1000; /* Set MISS flag */ |
1095 | e3c2613f | bellard | CSR_MISSC(s)++; |
1096 | e3c2613f | bellard | } else {
|
1097 | 89b190a2 | aurel32 | uint8_t *src = s->buffer; |
1098 | c227f099 | Anthony Liguori | target_phys_addr_t crda = CSR_CRDA(s); |
1099 | e3c2613f | bellard | struct pcnet_RMD rmd;
|
1100 | e3c2613f | bellard | int pktcount = 0; |
1101 | e3c2613f | bellard | |
1102 | 89b190a2 | aurel32 | if (!s->looptest) {
|
1103 | 89b190a2 | aurel32 | memcpy(src, buf, size); |
1104 | 89b190a2 | aurel32 | /* no need to compute the CRC */
|
1105 | 89b190a2 | aurel32 | src[size] = 0;
|
1106 | 89b190a2 | aurel32 | src[size + 1] = 0; |
1107 | 89b190a2 | aurel32 | src[size + 2] = 0; |
1108 | 89b190a2 | aurel32 | src[size + 3] = 0; |
1109 | 89b190a2 | aurel32 | size += 4;
|
1110 | 89b190a2 | aurel32 | } else if (s->looptest == PCNET_LOOPTEST_CRC || |
1111 | 89b190a2 | aurel32 | !CSR_DXMTFCS(s) || size < MIN_BUF_SIZE+4) {
|
1112 | e3c2613f | bellard | uint32_t fcs = ~0;
|
1113 | e3c2613f | bellard | uint8_t *p = src; |
1114 | e3c2613f | bellard | |
1115 | 89b190a2 | aurel32 | while (p != &src[size])
|
1116 | 89b190a2 | aurel32 | CRC(fcs, *p++); |
1117 | 89b190a2 | aurel32 | *(uint32_t *)p = htonl(fcs); |
1118 | 89b190a2 | aurel32 | size += 4;
|
1119 | 89b190a2 | aurel32 | } else {
|
1120 | 89b190a2 | aurel32 | uint32_t fcs = ~0;
|
1121 | 89b190a2 | aurel32 | uint8_t *p = src; |
1122 | 3b46e624 | ths | |
1123 | 89b190a2 | aurel32 | while (p != &src[size-4]) |
1124 | e3c2613f | bellard | CRC(fcs, *p++); |
1125 | 89b190a2 | aurel32 | crc_err = (*(uint32_t *)p != htonl(fcs)); |
1126 | 89b190a2 | aurel32 | } |
1127 | e3c2613f | bellard | |
1128 | e3c2613f | bellard | #ifdef PCNET_DEBUG_MATCH
|
1129 | e3c2613f | bellard | PRINT_PKTHDR(buf); |
1130 | e3c2613f | bellard | #endif
|
1131 | e3c2613f | bellard | |
1132 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,crda)); |
1133 | e3c2613f | bellard | /*if (!CSR_LAPPEN(s))*/
|
1134 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, STP, 1);
|
1135 | e3c2613f | bellard | |
1136 | e3c2613f | bellard | #define PCNET_RECV_STORE() do { \ |
1137 | 89b190a2 | aurel32 | int count = MIN(4096 - GET_FIELD(rmd.buf_length, RMDL, BCNT),remaining); \ |
1138 | c227f099 | Anthony Liguori | target_phys_addr_t rbadr = PHYSADDR(s, rmd.rbadr); \ |
1139 | 6d2980f5 | ths | s->phys_mem_write(s->dma_opaque, rbadr, src, count, CSR_BSWP(s)); \ |
1140 | 89b190a2 | aurel32 | src += count; remaining -= count; \ |
1141 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, OWN, 0); \
|
1142 | e3c2613f | bellard | RMDSTORE(&rmd, PHYSADDR(s,crda)); \ |
1143 | e3c2613f | bellard | pktcount++; \ |
1144 | e3c2613f | bellard | } while (0) |
1145 | e3c2613f | bellard | |
1146 | 89b190a2 | aurel32 | remaining = size; |
1147 | e3c2613f | bellard | PCNET_RECV_STORE(); |
1148 | 89b190a2 | aurel32 | if ((remaining > 0) && CSR_NRDA(s)) { |
1149 | c227f099 | Anthony Liguori | target_phys_addr_t nrda = CSR_NRDA(s); |
1150 | 89b190a2 | aurel32 | #ifdef PCNET_DEBUG_RMD
|
1151 | 89b190a2 | aurel32 | PRINT_RMD(&rmd); |
1152 | 89b190a2 | aurel32 | #endif
|
1153 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,nrda)); |
1154 | 6d2980f5 | ths | if (GET_FIELD(rmd.status, RMDS, OWN)) {
|
1155 | e3c2613f | bellard | crda = nrda; |
1156 | e3c2613f | bellard | PCNET_RECV_STORE(); |
1157 | 89b190a2 | aurel32 | #ifdef PCNET_DEBUG_RMD
|
1158 | 89b190a2 | aurel32 | PRINT_RMD(&rmd); |
1159 | 89b190a2 | aurel32 | #endif
|
1160 | 89b190a2 | aurel32 | if ((remaining > 0) && (nrda=CSR_NNRD(s))) { |
1161 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,nrda)); |
1162 | 6d2980f5 | ths | if (GET_FIELD(rmd.status, RMDS, OWN)) {
|
1163 | e3c2613f | bellard | crda = nrda; |
1164 | e3c2613f | bellard | PCNET_RECV_STORE(); |
1165 | e3c2613f | bellard | } |
1166 | e3c2613f | bellard | } |
1167 | 3b46e624 | ths | } |
1168 | e3c2613f | bellard | } |
1169 | e3c2613f | bellard | |
1170 | e3c2613f | bellard | #undef PCNET_RECV_STORE
|
1171 | e3c2613f | bellard | |
1172 | e3c2613f | bellard | RMDLOAD(&rmd, PHYSADDR(s,crda)); |
1173 | 89b190a2 | aurel32 | if (remaining == 0) { |
1174 | 89b190a2 | aurel32 | SET_FIELD(&rmd.msg_length, RMDM, MCNT, size); |
1175 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, ENP, 1);
|
1176 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, PAM, !CSR_PROM(s) && is_padr); |
1177 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, LFAM, !CSR_PROM(s) && is_ladr); |
1178 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, BAM, !CSR_PROM(s) && is_bcast); |
1179 | 89b190a2 | aurel32 | if (crc_err) {
|
1180 | 89b190a2 | aurel32 | SET_FIELD(&rmd.status, RMDS, CRC, 1);
|
1181 | 89b190a2 | aurel32 | SET_FIELD(&rmd.status, RMDS, ERR, 1);
|
1182 | 89b190a2 | aurel32 | } |
1183 | e3c2613f | bellard | } else {
|
1184 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, OFLO, 1);
|
1185 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, BUFF, 1);
|
1186 | 6d2980f5 | ths | SET_FIELD(&rmd.status, RMDS, ERR, 1);
|
1187 | e3c2613f | bellard | } |
1188 | e3c2613f | bellard | RMDSTORE(&rmd, PHYSADDR(s,crda)); |
1189 | e3c2613f | bellard | s->csr[0] |= 0x0400; |
1190 | e3c2613f | bellard | |
1191 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
1192 | 5fafdf24 | ths | printf("RCVRC=%d CRDA=0x%08x BLKS=%d\n",
|
1193 | e3c2613f | bellard | CSR_RCVRC(s), PHYSADDR(s,CSR_CRDA(s)), pktcount); |
1194 | e3c2613f | bellard | #endif
|
1195 | e3c2613f | bellard | #ifdef PCNET_DEBUG_RMD
|
1196 | e3c2613f | bellard | PRINT_RMD(&rmd); |
1197 | 3b46e624 | ths | #endif
|
1198 | e3c2613f | bellard | |
1199 | e3c2613f | bellard | while (pktcount--) {
|
1200 | e3c2613f | bellard | if (CSR_RCVRC(s) <= 1) |
1201 | e3c2613f | bellard | CSR_RCVRC(s) = CSR_RCVRL(s); |
1202 | e3c2613f | bellard | else
|
1203 | 3b46e624 | ths | CSR_RCVRC(s)--; |
1204 | e3c2613f | bellard | } |
1205 | 3b46e624 | ths | |
1206 | e3c2613f | bellard | pcnet_rdte_poll(s); |
1207 | e3c2613f | bellard | |
1208 | 3b46e624 | ths | } |
1209 | e3c2613f | bellard | } |
1210 | e3c2613f | bellard | |
1211 | e3c2613f | bellard | pcnet_poll(s); |
1212 | 3b46e624 | ths | pcnet_update_irq(s); |
1213 | 4f1c942b | Mark McLoughlin | |
1214 | 4f1c942b | Mark McLoughlin | return size_;
|
1215 | e3c2613f | bellard | } |
1216 | e3c2613f | bellard | |
1217 | e3c2613f | bellard | static void pcnet_transmit(PCNetState *s) |
1218 | e3c2613f | bellard | { |
1219 | c227f099 | Anthony Liguori | target_phys_addr_t xmit_cxda = 0;
|
1220 | e3c2613f | bellard | int count = CSR_XMTRL(s)-1; |
1221 | 89b190a2 | aurel32 | int add_crc = 0; |
1222 | 89b190a2 | aurel32 | |
1223 | e3c2613f | bellard | s->xmit_pos = -1;
|
1224 | 3b46e624 | ths | |
1225 | e3c2613f | bellard | if (!CSR_TXON(s)) {
|
1226 | e3c2613f | bellard | s->csr[0] &= ~0x0008; |
1227 | e3c2613f | bellard | return;
|
1228 | e3c2613f | bellard | } |
1229 | ec607da7 | bellard | |
1230 | ec607da7 | bellard | s->tx_busy = 1;
|
1231 | ec607da7 | bellard | |
1232 | e3c2613f | bellard | txagain:
|
1233 | e3c2613f | bellard | if (pcnet_tdte_poll(s)) {
|
1234 | e3c2613f | bellard | struct pcnet_TMD tmd;
|
1235 | e3c2613f | bellard | |
1236 | 6d2980f5 | ths | TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s))); |
1237 | e3c2613f | bellard | |
1238 | e3c2613f | bellard | #ifdef PCNET_DEBUG_TMD
|
1239 | e3c2613f | bellard | printf(" TMDLOAD 0x%08x\n", PHYSADDR(s,CSR_CXDA(s)));
|
1240 | e3c2613f | bellard | PRINT_TMD(&tmd); |
1241 | e3c2613f | bellard | #endif
|
1242 | 6d2980f5 | ths | if (GET_FIELD(tmd.status, TMDS, STP)) {
|
1243 | 6d2980f5 | ths | s->xmit_pos = 0;
|
1244 | e3c2613f | bellard | xmit_cxda = PHYSADDR(s,CSR_CXDA(s)); |
1245 | 89b190a2 | aurel32 | if (BCR_SWSTYLE(s) != 1) |
1246 | 89b190a2 | aurel32 | add_crc = GET_FIELD(tmd.status, TMDS, ADDFCS); |
1247 | e3c2613f | bellard | } |
1248 | 9bd0d294 | blueswir1 | if (!GET_FIELD(tmd.status, TMDS, ENP)) {
|
1249 | 9bd0d294 | blueswir1 | int bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT); |
1250 | 9bd0d294 | blueswir1 | s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), |
1251 | 9bd0d294 | blueswir1 | s->buffer + s->xmit_pos, bcnt, CSR_BSWP(s)); |
1252 | 9bd0d294 | blueswir1 | s->xmit_pos += bcnt; |
1253 | 9bd0d294 | blueswir1 | } else if (s->xmit_pos >= 0) { |
1254 | 6d2980f5 | ths | int bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT); |
1255 | 6d2980f5 | ths | s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), |
1256 | 6d2980f5 | ths | s->buffer + s->xmit_pos, bcnt, CSR_BSWP(s)); |
1257 | 6d2980f5 | ths | s->xmit_pos += bcnt; |
1258 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
1259 | e3c2613f | bellard | printf("pcnet_transmit size=%d\n", s->xmit_pos);
|
1260 | 6d2980f5 | ths | #endif
|
1261 | 89b190a2 | aurel32 | if (CSR_LOOP(s)) {
|
1262 | 89b190a2 | aurel32 | if (BCR_SWSTYLE(s) == 1) |
1263 | 89b190a2 | aurel32 | add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); |
1264 | 89b190a2 | aurel32 | s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC; |
1265 | 1fa51482 | Mark McLoughlin | pcnet_receive(&s->nic->nc, s->buffer, s->xmit_pos); |
1266 | 89b190a2 | aurel32 | s->looptest = 0;
|
1267 | 89b190a2 | aurel32 | } else
|
1268 | 1fa51482 | Mark McLoughlin | if (s->nic)
|
1269 | 1fa51482 | Mark McLoughlin | qemu_send_packet(&s->nic->nc, s->buffer, s->xmit_pos); |
1270 | e3c2613f | bellard | |
1271 | e3c2613f | bellard | s->csr[0] &= ~0x0008; /* clear TDMD */ |
1272 | e3c2613f | bellard | s->csr[4] |= 0x0004; /* set TXSTRT */ |
1273 | e3c2613f | bellard | s->xmit_pos = -1;
|
1274 | e3c2613f | bellard | } |
1275 | e3c2613f | bellard | |
1276 | 6d2980f5 | ths | SET_FIELD(&tmd.status, TMDS, OWN, 0);
|
1277 | e3c2613f | bellard | TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s))); |
1278 | 6d2980f5 | ths | if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && GET_FIELD(tmd.status, TMDS, LTINT)))
|
1279 | e3c2613f | bellard | s->csr[0] |= 0x0200; /* set TINT */ |
1280 | e3c2613f | bellard | |
1281 | e3c2613f | bellard | if (CSR_XMTRC(s)<=1) |
1282 | e3c2613f | bellard | CSR_XMTRC(s) = CSR_XMTRL(s); |
1283 | e3c2613f | bellard | else
|
1284 | e3c2613f | bellard | CSR_XMTRC(s)--; |
1285 | e3c2613f | bellard | if (count--)
|
1286 | e3c2613f | bellard | goto txagain;
|
1287 | e3c2613f | bellard | |
1288 | 5fafdf24 | ths | } else
|
1289 | e3c2613f | bellard | if (s->xmit_pos >= 0) { |
1290 | e3c2613f | bellard | struct pcnet_TMD tmd;
|
1291 | f1afe02a | aurel32 | TMDLOAD(&tmd, xmit_cxda); |
1292 | 6d2980f5 | ths | SET_FIELD(&tmd.misc, TMDM, BUFF, 1);
|
1293 | 6d2980f5 | ths | SET_FIELD(&tmd.misc, TMDM, UFLO, 1);
|
1294 | 6d2980f5 | ths | SET_FIELD(&tmd.status, TMDS, ERR, 1);
|
1295 | 6d2980f5 | ths | SET_FIELD(&tmd.status, TMDS, OWN, 0);
|
1296 | f1afe02a | aurel32 | TMDSTORE(&tmd, xmit_cxda); |
1297 | e3c2613f | bellard | s->csr[0] |= 0x0200; /* set TINT */ |
1298 | e3c2613f | bellard | if (!CSR_DXSUFLO(s)) {
|
1299 | e3c2613f | bellard | s->csr[0] &= ~0x0010; |
1300 | e3c2613f | bellard | } else
|
1301 | e3c2613f | bellard | if (count--)
|
1302 | e3c2613f | bellard | goto txagain;
|
1303 | e3c2613f | bellard | } |
1304 | ec607da7 | bellard | |
1305 | ec607da7 | bellard | s->tx_busy = 0;
|
1306 | e3c2613f | bellard | } |
1307 | e3c2613f | bellard | |
1308 | e3c2613f | bellard | static void pcnet_poll(PCNetState *s) |
1309 | e3c2613f | bellard | { |
1310 | e3c2613f | bellard | if (CSR_RXON(s)) {
|
1311 | e3c2613f | bellard | pcnet_rdte_poll(s); |
1312 | e3c2613f | bellard | } |
1313 | e3c2613f | bellard | |
1314 | 5fafdf24 | ths | if (CSR_TDMD(s) ||
|
1315 | e3c2613f | bellard | (CSR_TXON(s) && !CSR_DPOLL(s) && pcnet_tdte_poll(s))) |
1316 | ec607da7 | bellard | { |
1317 | ec607da7 | bellard | /* prevent recursion */
|
1318 | ec607da7 | bellard | if (s->tx_busy)
|
1319 | ec607da7 | bellard | return;
|
1320 | ec607da7 | bellard | |
1321 | e3c2613f | bellard | pcnet_transmit(s); |
1322 | ec607da7 | bellard | } |
1323 | e3c2613f | bellard | } |
1324 | e3c2613f | bellard | |
1325 | e3c2613f | bellard | static void pcnet_poll_timer(void *opaque) |
1326 | e3c2613f | bellard | { |
1327 | e3c2613f | bellard | PCNetState *s = opaque; |
1328 | e3c2613f | bellard | |
1329 | e3c2613f | bellard | qemu_del_timer(s->poll_timer); |
1330 | e3c2613f | bellard | |
1331 | e3c2613f | bellard | if (CSR_TDMD(s)) {
|
1332 | e3c2613f | bellard | pcnet_transmit(s); |
1333 | e3c2613f | bellard | } |
1334 | e3c2613f | bellard | |
1335 | 3b46e624 | ths | pcnet_update_irq(s); |
1336 | e3c2613f | bellard | |
1337 | e3c2613f | bellard | if (!CSR_STOP(s) && !CSR_SPND(s) && !CSR_DPOLL(s)) {
|
1338 | e3c2613f | bellard | uint64_t now = qemu_get_clock(vm_clock) * 33;
|
1339 | e3c2613f | bellard | if (!s->timer || !now)
|
1340 | e3c2613f | bellard | s->timer = now; |
1341 | e3c2613f | bellard | else {
|
1342 | e3c2613f | bellard | uint64_t t = now - s->timer + CSR_POLL(s); |
1343 | e3c2613f | bellard | if (t > 0xffffLL) { |
1344 | e3c2613f | bellard | pcnet_poll(s); |
1345 | e3c2613f | bellard | CSR_POLL(s) = CSR_PINT(s); |
1346 | e3c2613f | bellard | } else
|
1347 | e3c2613f | bellard | CSR_POLL(s) = t; |
1348 | e3c2613f | bellard | } |
1349 | 5fafdf24 | ths | qemu_mod_timer(s->poll_timer, |
1350 | e3c2613f | bellard | pcnet_get_next_poll_time(s,qemu_get_clock(vm_clock))); |
1351 | e3c2613f | bellard | } |
1352 | e3c2613f | bellard | } |
1353 | e3c2613f | bellard | |
1354 | e3c2613f | bellard | |
1355 | e3c2613f | bellard | static void pcnet_csr_writew(PCNetState *s, uint32_t rap, uint32_t new_value) |
1356 | e3c2613f | bellard | { |
1357 | e3c2613f | bellard | uint16_t val = new_value; |
1358 | e3c2613f | bellard | #ifdef PCNET_DEBUG_CSR
|
1359 | e3c2613f | bellard | printf("pcnet_csr_writew rap=%d val=0x%04x\n", rap, val);
|
1360 | e3c2613f | bellard | #endif
|
1361 | e3c2613f | bellard | switch (rap) {
|
1362 | e3c2613f | bellard | case 0: |
1363 | e3c2613f | bellard | s->csr[0] &= ~(val & 0x7f00); /* Clear any interrupt flags */ |
1364 | e3c2613f | bellard | |
1365 | e3c2613f | bellard | s->csr[0] = (s->csr[0] & ~0x0040) | (val & 0x0048); |
1366 | e3c2613f | bellard | |
1367 | e3c2613f | bellard | val = (val & 0x007f) | (s->csr[0] & 0x7f00); |
1368 | e3c2613f | bellard | |
1369 | e3c2613f | bellard | /* IFF STOP, STRT and INIT are set, clear STRT and INIT */
|
1370 | e3c2613f | bellard | if ((val&7) == 7) |
1371 | e3c2613f | bellard | val &= ~3;
|
1372 | e3c2613f | bellard | |
1373 | e3c2613f | bellard | if (!CSR_STOP(s) && (val & 4)) |
1374 | e3c2613f | bellard | pcnet_stop(s); |
1375 | e3c2613f | bellard | |
1376 | e3c2613f | bellard | if (!CSR_INIT(s) && (val & 1)) |
1377 | e3c2613f | bellard | pcnet_init(s); |
1378 | e3c2613f | bellard | |
1379 | e3c2613f | bellard | if (!CSR_STRT(s) && (val & 2)) |
1380 | e3c2613f | bellard | pcnet_start(s); |
1381 | e3c2613f | bellard | |
1382 | 5fafdf24 | ths | if (CSR_TDMD(s))
|
1383 | e3c2613f | bellard | pcnet_transmit(s); |
1384 | e3c2613f | bellard | |
1385 | e3c2613f | bellard | return;
|
1386 | e3c2613f | bellard | case 1: |
1387 | e3c2613f | bellard | case 2: |
1388 | e3c2613f | bellard | case 8: |
1389 | e3c2613f | bellard | case 9: |
1390 | e3c2613f | bellard | case 10: |
1391 | e3c2613f | bellard | case 11: |
1392 | e3c2613f | bellard | case 12: |
1393 | e3c2613f | bellard | case 13: |
1394 | e3c2613f | bellard | case 14: |
1395 | e3c2613f | bellard | case 15: |
1396 | e3c2613f | bellard | case 18: /* CRBAL */ |
1397 | e3c2613f | bellard | case 19: /* CRBAU */ |
1398 | e3c2613f | bellard | case 20: /* CXBAL */ |
1399 | e3c2613f | bellard | case 21: /* CXBAU */ |
1400 | e3c2613f | bellard | case 22: /* NRBAU */ |
1401 | e3c2613f | bellard | case 23: /* NRBAU */ |
1402 | e3c2613f | bellard | case 24: |
1403 | e3c2613f | bellard | case 25: |
1404 | e3c2613f | bellard | case 26: |
1405 | e3c2613f | bellard | case 27: |
1406 | e3c2613f | bellard | case 28: |
1407 | e3c2613f | bellard | case 29: |
1408 | e3c2613f | bellard | case 30: |
1409 | e3c2613f | bellard | case 31: |
1410 | e3c2613f | bellard | case 32: |
1411 | e3c2613f | bellard | case 33: |
1412 | e3c2613f | bellard | case 34: |
1413 | e3c2613f | bellard | case 35: |
1414 | e3c2613f | bellard | case 36: |
1415 | e3c2613f | bellard | case 37: |
1416 | e3c2613f | bellard | case 38: |
1417 | e3c2613f | bellard | case 39: |
1418 | e3c2613f | bellard | case 40: /* CRBC */ |
1419 | e3c2613f | bellard | case 41: |
1420 | e3c2613f | bellard | case 42: /* CXBC */ |
1421 | e3c2613f | bellard | case 43: |
1422 | e3c2613f | bellard | case 44: |
1423 | e3c2613f | bellard | case 45: |
1424 | e3c2613f | bellard | case 46: /* POLL */ |
1425 | e3c2613f | bellard | case 47: /* POLLINT */ |
1426 | e3c2613f | bellard | case 72: |
1427 | e3c2613f | bellard | case 74: |
1428 | e3c2613f | bellard | case 76: /* RCVRL */ |
1429 | e3c2613f | bellard | case 78: /* XMTRL */ |
1430 | e3c2613f | bellard | case 112: |
1431 | e3c2613f | bellard | if (CSR_STOP(s) || CSR_SPND(s))
|
1432 | e3c2613f | bellard | break;
|
1433 | e3c2613f | bellard | return;
|
1434 | e3c2613f | bellard | case 3: |
1435 | e3c2613f | bellard | break;
|
1436 | e3c2613f | bellard | case 4: |
1437 | 5fafdf24 | ths | s->csr[4] &= ~(val & 0x026a); |
1438 | e3c2613f | bellard | val &= ~0x026a; val |= s->csr[4] & 0x026a; |
1439 | e3c2613f | bellard | break;
|
1440 | e3c2613f | bellard | case 5: |
1441 | 5fafdf24 | ths | s->csr[5] &= ~(val & 0x0a90); |
1442 | e3c2613f | bellard | val &= ~0x0a90; val |= s->csr[5] & 0x0a90; |
1443 | e3c2613f | bellard | break;
|
1444 | e3c2613f | bellard | case 16: |
1445 | e3c2613f | bellard | pcnet_csr_writew(s,1,val);
|
1446 | e3c2613f | bellard | return;
|
1447 | e3c2613f | bellard | case 17: |
1448 | e3c2613f | bellard | pcnet_csr_writew(s,2,val);
|
1449 | e3c2613f | bellard | return;
|
1450 | e3c2613f | bellard | case 58: |
1451 | e3c2613f | bellard | pcnet_bcr_writew(s,BCR_SWS,val); |
1452 | e3c2613f | bellard | break;
|
1453 | e3c2613f | bellard | default:
|
1454 | e3c2613f | bellard | return;
|
1455 | e3c2613f | bellard | } |
1456 | e3c2613f | bellard | s->csr[rap] = val; |
1457 | e3c2613f | bellard | } |
1458 | e3c2613f | bellard | |
1459 | e3c2613f | bellard | static uint32_t pcnet_csr_readw(PCNetState *s, uint32_t rap)
|
1460 | e3c2613f | bellard | { |
1461 | e3c2613f | bellard | uint32_t val; |
1462 | e3c2613f | bellard | switch (rap) {
|
1463 | e3c2613f | bellard | case 0: |
1464 | e3c2613f | bellard | pcnet_update_irq(s); |
1465 | e3c2613f | bellard | val = s->csr[0];
|
1466 | e3c2613f | bellard | val |= (val & 0x7800) ? 0x8000 : 0; |
1467 | e3c2613f | bellard | break;
|
1468 | e3c2613f | bellard | case 16: |
1469 | e3c2613f | bellard | return pcnet_csr_readw(s,1); |
1470 | e3c2613f | bellard | case 17: |
1471 | e3c2613f | bellard | return pcnet_csr_readw(s,2); |
1472 | e3c2613f | bellard | case 58: |
1473 | e3c2613f | bellard | return pcnet_bcr_readw(s,BCR_SWS);
|
1474 | e3c2613f | bellard | case 88: |
1475 | e3c2613f | bellard | val = s->csr[89];
|
1476 | e3c2613f | bellard | val <<= 16;
|
1477 | e3c2613f | bellard | val |= s->csr[88];
|
1478 | e3c2613f | bellard | break;
|
1479 | e3c2613f | bellard | default:
|
1480 | e3c2613f | bellard | val = s->csr[rap]; |
1481 | e3c2613f | bellard | } |
1482 | e3c2613f | bellard | #ifdef PCNET_DEBUG_CSR
|
1483 | e3c2613f | bellard | printf("pcnet_csr_readw rap=%d val=0x%04x\n", rap, val);
|
1484 | e3c2613f | bellard | #endif
|
1485 | e3c2613f | bellard | return val;
|
1486 | e3c2613f | bellard | } |
1487 | e3c2613f | bellard | |
1488 | e3c2613f | bellard | static void pcnet_bcr_writew(PCNetState *s, uint32_t rap, uint32_t val) |
1489 | e3c2613f | bellard | { |
1490 | e3c2613f | bellard | rap &= 127;
|
1491 | e3c2613f | bellard | #ifdef PCNET_DEBUG_BCR
|
1492 | e3c2613f | bellard | printf("pcnet_bcr_writew rap=%d val=0x%04x\n", rap, val);
|
1493 | e3c2613f | bellard | #endif
|
1494 | e3c2613f | bellard | switch (rap) {
|
1495 | e3c2613f | bellard | case BCR_SWS:
|
1496 | e3c2613f | bellard | if (!(CSR_STOP(s) || CSR_SPND(s)))
|
1497 | e3c2613f | bellard | return;
|
1498 | e3c2613f | bellard | val &= ~0x0300;
|
1499 | e3c2613f | bellard | switch (val & 0x00ff) { |
1500 | e3c2613f | bellard | case 0: |
1501 | e3c2613f | bellard | val |= 0x0200;
|
1502 | e3c2613f | bellard | break;
|
1503 | e3c2613f | bellard | case 1: |
1504 | e3c2613f | bellard | val |= 0x0100;
|
1505 | e3c2613f | bellard | break;
|
1506 | e3c2613f | bellard | case 2: |
1507 | e3c2613f | bellard | case 3: |
1508 | e3c2613f | bellard | val |= 0x0300;
|
1509 | e3c2613f | bellard | break;
|
1510 | e3c2613f | bellard | default:
|
1511 | e3c2613f | bellard | printf("Bad SWSTYLE=0x%02x\n", val & 0xff); |
1512 | e3c2613f | bellard | val = 0x0200;
|
1513 | e3c2613f | bellard | break;
|
1514 | e3c2613f | bellard | } |
1515 | e3c2613f | bellard | #ifdef PCNET_DEBUG
|
1516 | e3c2613f | bellard | printf("BCR_SWS=0x%04x\n", val);
|
1517 | e3c2613f | bellard | #endif
|
1518 | e3c2613f | bellard | case BCR_LNKST:
|
1519 | e3c2613f | bellard | case BCR_LED1:
|
1520 | e3c2613f | bellard | case BCR_LED2:
|
1521 | e3c2613f | bellard | case BCR_LED3:
|
1522 | e3c2613f | bellard | case BCR_MC:
|
1523 | e3c2613f | bellard | case BCR_FDC:
|
1524 | e3c2613f | bellard | case BCR_BSBC:
|
1525 | e3c2613f | bellard | case BCR_EECAS:
|
1526 | e3c2613f | bellard | case BCR_PLAT:
|
1527 | e3c2613f | bellard | s->bcr[rap] = val; |
1528 | e3c2613f | bellard | break;
|
1529 | e3c2613f | bellard | default:
|
1530 | e3c2613f | bellard | break;
|
1531 | e3c2613f | bellard | } |
1532 | e3c2613f | bellard | } |
1533 | e3c2613f | bellard | |
1534 | a4c75a21 | Paul Brook | uint32_t pcnet_bcr_readw(PCNetState *s, uint32_t rap) |
1535 | e3c2613f | bellard | { |
1536 | e3c2613f | bellard | uint32_t val; |
1537 | e3c2613f | bellard | rap &= 127;
|
1538 | e3c2613f | bellard | switch (rap) {
|
1539 | e3c2613f | bellard | case BCR_LNKST:
|
1540 | e3c2613f | bellard | case BCR_LED1:
|
1541 | e3c2613f | bellard | case BCR_LED2:
|
1542 | e3c2613f | bellard | case BCR_LED3:
|
1543 | e3c2613f | bellard | val = s->bcr[rap] & ~0x8000;
|
1544 | e3c2613f | bellard | val |= (val & 0x017f & s->lnkst) ? 0x8000 : 0; |
1545 | e3c2613f | bellard | break;
|
1546 | e3c2613f | bellard | default:
|
1547 | e3c2613f | bellard | val = rap < 32 ? s->bcr[rap] : 0; |
1548 | e3c2613f | bellard | break;
|
1549 | e3c2613f | bellard | } |
1550 | e3c2613f | bellard | #ifdef PCNET_DEBUG_BCR
|
1551 | e3c2613f | bellard | printf("pcnet_bcr_readw rap=%d val=0x%04x\n", rap, val);
|
1552 | e3c2613f | bellard | #endif
|
1553 | e3c2613f | bellard | return val;
|
1554 | e3c2613f | bellard | } |
1555 | e3c2613f | bellard | |
1556 | 94e1a912 | Gerd Hoffmann | void pcnet_h_reset(void *opaque) |
1557 | e3c2613f | bellard | { |
1558 | 91cc0295 | bellard | PCNetState *s = opaque; |
1559 | e3c2613f | bellard | int i;
|
1560 | e3c2613f | bellard | uint16_t checksum; |
1561 | e3c2613f | bellard | |
1562 | e3c2613f | bellard | /* Initialize the PROM */
|
1563 | e3c2613f | bellard | |
1564 | 76224833 | Gerd Hoffmann | memcpy(s->prom, s->conf.macaddr.a, 6);
|
1565 | e3c2613f | bellard | s->prom[12] = s->prom[13] = 0x00; |
1566 | e3c2613f | bellard | s->prom[14] = s->prom[15] = 0x57; |
1567 | e3c2613f | bellard | |
1568 | e3c2613f | bellard | for (i = 0,checksum = 0; i < 16; i++) |
1569 | e3c2613f | bellard | checksum += s->prom[i]; |
1570 | e3c2613f | bellard | *(uint16_t *)&s->prom[12] = cpu_to_le16(checksum);
|
1571 | e3c2613f | bellard | |
1572 | e3c2613f | bellard | |
1573 | e3c2613f | bellard | s->bcr[BCR_MSRDA] = 0x0005;
|
1574 | e3c2613f | bellard | s->bcr[BCR_MSWRA] = 0x0005;
|
1575 | e3c2613f | bellard | s->bcr[BCR_MC ] = 0x0002;
|
1576 | e3c2613f | bellard | s->bcr[BCR_LNKST] = 0x00c0;
|
1577 | e3c2613f | bellard | s->bcr[BCR_LED1 ] = 0x0084;
|
1578 | e3c2613f | bellard | s->bcr[BCR_LED2 ] = 0x0088;
|
1579 | e3c2613f | bellard | s->bcr[BCR_LED3 ] = 0x0090;
|
1580 | e3c2613f | bellard | s->bcr[BCR_FDC ] = 0x0000;
|
1581 | e3c2613f | bellard | s->bcr[BCR_BSBC ] = 0x9001;
|
1582 | e3c2613f | bellard | s->bcr[BCR_EECAS] = 0x0002;
|
1583 | e3c2613f | bellard | s->bcr[BCR_SWS ] = 0x0200;
|
1584 | e3c2613f | bellard | s->bcr[BCR_PLAT ] = 0xff06;
|
1585 | e3c2613f | bellard | |
1586 | e3c2613f | bellard | pcnet_s_reset(s); |
1587 | de41ac92 | Jan Kiszka | pcnet_update_irq(s); |
1588 | de41ac92 | Jan Kiszka | pcnet_poll_timer(s); |
1589 | e3c2613f | bellard | } |
1590 | e3c2613f | bellard | |
1591 | 94e1a912 | Gerd Hoffmann | void pcnet_ioport_writew(void *opaque, uint32_t addr, uint32_t val) |
1592 | e3c2613f | bellard | { |
1593 | e3c2613f | bellard | PCNetState *s = opaque; |
1594 | e3c2613f | bellard | pcnet_poll_timer(s); |
1595 | e3c2613f | bellard | #ifdef PCNET_DEBUG_IO
|
1596 | e3c2613f | bellard | printf("pcnet_ioport_writew addr=0x%08x val=0x%04x\n", addr, val);
|
1597 | e3c2613f | bellard | #endif
|
1598 | e3c2613f | bellard | if (!BCR_DWIO(s)) {
|
1599 | e3c2613f | bellard | switch (addr & 0x0f) { |
1600 | e3c2613f | bellard | case 0x00: /* RDP */ |
1601 | e3c2613f | bellard | pcnet_csr_writew(s, s->rap, val); |
1602 | e3c2613f | bellard | break;
|
1603 | e3c2613f | bellard | case 0x02: |
1604 | e3c2613f | bellard | s->rap = val & 0x7f;
|
1605 | e3c2613f | bellard | break;
|
1606 | e3c2613f | bellard | case 0x06: |
1607 | e3c2613f | bellard | pcnet_bcr_writew(s, s->rap, val); |
1608 | e3c2613f | bellard | break;
|
1609 | e3c2613f | bellard | } |
1610 | e3c2613f | bellard | } |
1611 | e3c2613f | bellard | pcnet_update_irq(s); |
1612 | e3c2613f | bellard | } |
1613 | e3c2613f | bellard | |
1614 | 94e1a912 | Gerd Hoffmann | uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr)
|
1615 | e3c2613f | bellard | { |
1616 | e3c2613f | bellard | PCNetState *s = opaque; |
1617 | e3c2613f | bellard | uint32_t val = -1;
|
1618 | e3c2613f | bellard | pcnet_poll_timer(s); |
1619 | e3c2613f | bellard | if (!BCR_DWIO(s)) {
|
1620 | e3c2613f | bellard | switch (addr & 0x0f) { |
1621 | e3c2613f | bellard | case 0x00: /* RDP */ |
1622 | e3c2613f | bellard | val = pcnet_csr_readw(s, s->rap); |
1623 | e3c2613f | bellard | break;
|
1624 | e3c2613f | bellard | case 0x02: |
1625 | e3c2613f | bellard | val = s->rap; |
1626 | e3c2613f | bellard | break;
|
1627 | e3c2613f | bellard | case 0x04: |
1628 | e3c2613f | bellard | pcnet_s_reset(s); |
1629 | e3c2613f | bellard | val = 0;
|
1630 | e3c2613f | bellard | break;
|
1631 | e3c2613f | bellard | case 0x06: |
1632 | e3c2613f | bellard | val = pcnet_bcr_readw(s, s->rap); |
1633 | e3c2613f | bellard | break;
|
1634 | e3c2613f | bellard | } |
1635 | e3c2613f | bellard | } |
1636 | e3c2613f | bellard | pcnet_update_irq(s); |
1637 | e3c2613f | bellard | #ifdef PCNET_DEBUG_IO
|
1638 | e3c2613f | bellard | printf("pcnet_ioport_readw addr=0x%08x val=0x%04x\n", addr, val & 0xffff); |
1639 | e3c2613f | bellard | #endif
|
1640 | e3c2613f | bellard | return val;
|
1641 | e3c2613f | bellard | } |
1642 | e3c2613f | bellard | |
1643 | a4c75a21 | Paul Brook | void pcnet_ioport_writel(void *opaque, uint32_t addr, uint32_t val) |
1644 | e3c2613f | bellard | { |
1645 | e3c2613f | bellard | PCNetState *s = opaque; |
1646 | e3c2613f | bellard | pcnet_poll_timer(s); |
1647 | e3c2613f | bellard | #ifdef PCNET_DEBUG_IO
|
1648 | e3c2613f | bellard | printf("pcnet_ioport_writel addr=0x%08x val=0x%08x\n", addr, val);
|
1649 | e3c2613f | bellard | #endif
|
1650 | e3c2613f | bellard | if (BCR_DWIO(s)) {
|
1651 | e3c2613f | bellard | switch (addr & 0x0f) { |
1652 | e3c2613f | bellard | case 0x00: /* RDP */ |
1653 | e3c2613f | bellard | pcnet_csr_writew(s, s->rap, val & 0xffff);
|
1654 | e3c2613f | bellard | break;
|
1655 | e3c2613f | bellard | case 0x04: |
1656 | e3c2613f | bellard | s->rap = val & 0x7f;
|
1657 | e3c2613f | bellard | break;
|
1658 | e3c2613f | bellard | case 0x0c: |
1659 | e3c2613f | bellard | pcnet_bcr_writew(s, s->rap, val & 0xffff);
|
1660 | e3c2613f | bellard | break;
|
1661 | e3c2613f | bellard | } |
1662 | e3c2613f | bellard | } else
|
1663 | e3c2613f | bellard | if ((addr & 0x0f) == 0) { |
1664 | e3c2613f | bellard | /* switch device to dword i/o mode */
|
1665 | e3c2613f | bellard | pcnet_bcr_writew(s, BCR_BSBC, pcnet_bcr_readw(s, BCR_BSBC) | 0x0080);
|
1666 | e3c2613f | bellard | #ifdef PCNET_DEBUG_IO
|
1667 | e3c2613f | bellard | printf("device switched into dword i/o mode\n");
|
1668 | 3b46e624 | ths | #endif
|
1669 | e3c2613f | bellard | } |
1670 | e3c2613f | bellard | pcnet_update_irq(s); |
1671 | e3c2613f | bellard | } |
1672 | e3c2613f | bellard | |
1673 | a4c75a21 | Paul Brook | uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
|
1674 | e3c2613f | bellard | { |
1675 | e3c2613f | bellard | PCNetState *s = opaque; |
1676 | e3c2613f | bellard | uint32_t val = -1;
|
1677 | e3c2613f | bellard | pcnet_poll_timer(s); |
1678 | 3b46e624 | ths | if (BCR_DWIO(s)) {
|
1679 | e3c2613f | bellard | switch (addr & 0x0f) { |
1680 | e3c2613f | bellard | case 0x00: /* RDP */ |
1681 | e3c2613f | bellard | val = pcnet_csr_readw(s, s->rap); |
1682 | e3c2613f | bellard | break;
|
1683 | e3c2613f | bellard | case 0x04: |
1684 | e3c2613f | bellard | val = s->rap; |
1685 | e3c2613f | bellard | break;
|
1686 | e3c2613f | bellard | case 0x08: |
1687 | e3c2613f | bellard | pcnet_s_reset(s); |
1688 | e3c2613f | bellard | val = 0;
|
1689 | e3c2613f | bellard | break;
|
1690 | e3c2613f | bellard | case 0x0c: |
1691 | e3c2613f | bellard | val = pcnet_bcr_readw(s, s->rap); |
1692 | e3c2613f | bellard | break;
|
1693 | e3c2613f | bellard | } |
1694 | e3c2613f | bellard | } |
1695 | e3c2613f | bellard | pcnet_update_irq(s); |
1696 | e3c2613f | bellard | #ifdef PCNET_DEBUG_IO
|
1697 | e3c2613f | bellard | printf("pcnet_ioport_readl addr=0x%08x val=0x%08x\n", addr, val);
|
1698 | e3c2613f | bellard | #endif
|
1699 | e3c2613f | bellard | return val;
|
1700 | e3c2613f | bellard | } |
1701 | e3c2613f | bellard | |
1702 | 3d865059 | Juan Quintela | static bool is_version_2(void *opaque, int version_id) |
1703 | 91cc0295 | bellard | { |
1704 | 3d865059 | Juan Quintela | return version_id == 2; |
1705 | 91cc0295 | bellard | } |
1706 | 91cc0295 | bellard | |
1707 | 3d865059 | Juan Quintela | const VMStateDescription vmstate_pcnet = {
|
1708 | 3d865059 | Juan Quintela | .name = "pcnet",
|
1709 | 3d865059 | Juan Quintela | .version_id = 3,
|
1710 | 3d865059 | Juan Quintela | .minimum_version_id = 2,
|
1711 | 3d865059 | Juan Quintela | .minimum_version_id_old = 2,
|
1712 | 3d865059 | Juan Quintela | .fields = (VMStateField []) { |
1713 | 3d865059 | Juan Quintela | VMSTATE_INT32(rap, PCNetState), |
1714 | 3d865059 | Juan Quintela | VMSTATE_INT32(isr, PCNetState), |
1715 | 3d865059 | Juan Quintela | VMSTATE_INT32(lnkst, PCNetState), |
1716 | 3d865059 | Juan Quintela | VMSTATE_UINT32(rdra, PCNetState), |
1717 | 3d865059 | Juan Quintela | VMSTATE_UINT32(tdra, PCNetState), |
1718 | 3d865059 | Juan Quintela | VMSTATE_BUFFER(prom, PCNetState), |
1719 | 3d865059 | Juan Quintela | VMSTATE_UINT16_ARRAY(csr, PCNetState, 128),
|
1720 | 3d865059 | Juan Quintela | VMSTATE_UINT16_ARRAY(bcr, PCNetState, 32),
|
1721 | 3d865059 | Juan Quintela | VMSTATE_UINT64(timer, PCNetState), |
1722 | 3d865059 | Juan Quintela | VMSTATE_INT32(xmit_pos, PCNetState), |
1723 | 3d865059 | Juan Quintela | VMSTATE_BUFFER(buffer, PCNetState), |
1724 | 3d865059 | Juan Quintela | VMSTATE_UNUSED_TEST(is_version_2, 4),
|
1725 | 3d865059 | Juan Quintela | VMSTATE_INT32(tx_busy, PCNetState), |
1726 | 3d865059 | Juan Quintela | VMSTATE_TIMER(poll_timer, PCNetState), |
1727 | 3d865059 | Juan Quintela | VMSTATE_END_OF_LIST() |
1728 | efb56cf7 | Jan Kiszka | } |
1729 | 3d865059 | Juan Quintela | }; |
1730 | 0abaa7c1 | Juan Quintela | |
1731 | 94e1a912 | Gerd Hoffmann | void pcnet_common_cleanup(PCNetState *d)
|
1732 | b946a153 | aliguori | { |
1733 | 1fa51482 | Mark McLoughlin | d->nic = NULL;
|
1734 | b946a153 | aliguori | } |
1735 | b946a153 | aliguori | |
1736 | 1fa51482 | Mark McLoughlin | int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
|
1737 | 91cc0295 | bellard | { |
1738 | 9d07d757 | Paul Brook | s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s); |
1739 | 9d07d757 | Paul Brook | |
1740 | 76224833 | Gerd Hoffmann | qemu_macaddr_default_if_unset(&s->conf.macaddr); |
1741 | 1fa51482 | Mark McLoughlin | s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s); |
1742 | 1fa51482 | Mark McLoughlin | qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); |
1743 | 81a322d4 | Gerd Hoffmann | return 0; |
1744 | 91cc0295 | bellard | } |