Commit 6d2980f515c005091de0b9f4fe526e749f62c380
1 parent
94fc95cd
Fix unportable bitfields use which broke pcnet for big endian hosts.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2469 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
339 additions
and
269 deletions
hw/pcnet.c
| ... | ... | @@ -77,14 +77,6 @@ struct PCNetState_st { |
| 77 | 77 | void *dma_opaque; |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | -/* XXX: using bitfields for target memory structures is almost surely | |
| 81 | - not portable, so it should be suppressed ASAP */ | |
| 82 | -#ifdef __GNUC__ | |
| 83 | -#define PACKED_FIELD(A) A __attribute__ ((packed)) | |
| 84 | -#else | |
| 85 | -#error FixMe | |
| 86 | -#endif | |
| 87 | - | |
| 88 | 80 | struct qemu_ether_header { |
| 89 | 81 | uint8_t ether_dhost[6]; |
| 90 | 82 | uint8_t ether_shost[6]; |
| ... | ... | @@ -183,223 +175,291 @@ struct pcnet_initblk32 { |
| 183 | 175 | }; |
| 184 | 176 | |
| 185 | 177 | struct pcnet_TMD { |
| 186 | - struct { | |
| 187 | - unsigned tbadr:32; | |
| 188 | - } tmd0; | |
| 189 | - struct { | |
| 190 | - unsigned PACKED_FIELD(bcnt:12), PACKED_FIELD(ones:4), PACKED_FIELD(res:7), PACKED_FIELD(bpe:1); | |
| 191 | - unsigned PACKED_FIELD(enp:1), PACKED_FIELD(stp:1), PACKED_FIELD(def:1), PACKED_FIELD(one:1); | |
| 192 | - unsigned PACKED_FIELD(ltint:1), PACKED_FIELD(nofcs:1), PACKED_FIELD(err:1), PACKED_FIELD(own:1); | |
| 193 | - } tmd1; | |
| 194 | - struct { | |
| 195 | - unsigned PACKED_FIELD(trc:4), PACKED_FIELD(res:12); | |
| 196 | - unsigned PACKED_FIELD(tdr:10), PACKED_FIELD(rtry:1), PACKED_FIELD(lcar:1); | |
| 197 | - unsigned PACKED_FIELD(lcol:1), PACKED_FIELD(exdef:1), PACKED_FIELD(uflo:1), PACKED_FIELD(buff:1); | |
| 198 | - } tmd2; | |
| 199 | - struct { | |
| 200 | - unsigned res:32; | |
| 201 | - } tmd3; | |
| 178 | + uint32_t tbadr; | |
| 179 | + int16_t length; | |
| 180 | + int16_t status; | |
| 181 | + uint32_t misc; | |
| 182 | + uint32_t res; | |
| 202 | 183 | }; |
| 203 | 184 | |
| 185 | +#define TMDL_BCNT_MASK 0x0fff | |
| 186 | +#define TMDL_BCNT_SH 0 | |
| 187 | +#define TMDL_ONES_MASK 0xf000 | |
| 188 | +#define TMDL_ONES_SH 12 | |
| 189 | + | |
| 190 | +#define TMDS_BPE_MASK 0x0080 | |
| 191 | +#define TMDS_BPE_SH 7 | |
| 192 | +#define TMDS_ENP_MASK 0x0100 | |
| 193 | +#define TMDS_ENP_SH 8 | |
| 194 | +#define TMDS_STP_MASK 0x0200 | |
| 195 | +#define TMDS_STP_SH 9 | |
| 196 | +#define TMDS_DEF_MASK 0x0400 | |
| 197 | +#define TMDS_DEF_SH 10 | |
| 198 | +#define TMDS_ONE_MASK 0x0800 | |
| 199 | +#define TMDS_ONE_SH 11 | |
| 200 | +#define TMDS_LTINT_MASK 0x1000 | |
| 201 | +#define TMDS_LTINT_SH 12 | |
| 202 | +#define TMDS_NOFCS_MASK 0x2000 | |
| 203 | +#define TMDS_NOFCS_SH 13 | |
| 204 | +#define TMDS_ERR_MASK 0x4000 | |
| 205 | +#define TMDS_ERR_SH 14 | |
| 206 | +#define TMDS_OWN_MASK 0x8000 | |
| 207 | +#define TMDS_OWN_SH 15 | |
| 208 | + | |
| 209 | +#define TMDM_TRC_MASK 0x0000000f | |
| 210 | +#define TMDM_TRC_SH 0 | |
| 211 | +#define TMDM_TDR_MASK 0x03ff0000 | |
| 212 | +#define TMDM_TDR_SH 16 | |
| 213 | +#define TMDM_RTRY_MASK 0x04000000 | |
| 214 | +#define TMDM_RTRY_SH 26 | |
| 215 | +#define TMDM_LCAR_MASK 0x08000000 | |
| 216 | +#define TMDM_LCAR_SH 27 | |
| 217 | +#define TMDM_LCOL_MASK 0x10000000 | |
| 218 | +#define TMDM_LCOL_SH 28 | |
| 219 | +#define TMDM_EXDEF_MASK 0x20000000 | |
| 220 | +#define TMDM_EXDEF_SH 29 | |
| 221 | +#define TMDM_UFLO_MASK 0x40000000 | |
| 222 | +#define TMDM_UFLO_SH 30 | |
| 223 | +#define TMDM_BUFF_MASK 0x80000000 | |
| 224 | +#define TMDM_BUFF_SH 31 | |
| 225 | + | |
| 204 | 226 | struct pcnet_RMD { |
| 205 | - struct { | |
| 206 | - unsigned rbadr:32; | |
| 207 | - } rmd0; | |
| 208 | - struct { | |
| 209 | - unsigned PACKED_FIELD(bcnt:12), PACKED_FIELD(ones:4), PACKED_FIELD(res:4); | |
| 210 | - unsigned PACKED_FIELD(bam:1), PACKED_FIELD(lafm:1), PACKED_FIELD(pam:1), PACKED_FIELD(bpe:1); | |
| 211 | - unsigned PACKED_FIELD(enp:1), PACKED_FIELD(stp:1), PACKED_FIELD(buff:1), PACKED_FIELD(crc:1); | |
| 212 | - unsigned PACKED_FIELD(oflo:1), PACKED_FIELD(fram:1), PACKED_FIELD(err:1), PACKED_FIELD(own:1); | |
| 213 | - } rmd1; | |
| 214 | - struct { | |
| 215 | - unsigned PACKED_FIELD(mcnt:12), PACKED_FIELD(zeros:4); | |
| 216 | - unsigned PACKED_FIELD(rpc:8), PACKED_FIELD(rcc:8); | |
| 217 | - } rmd2; | |
| 218 | - struct { | |
| 219 | - unsigned res:32; | |
| 220 | - } rmd3; | |
| 227 | + uint32_t rbadr; | |
| 228 | + int16_t buf_length; | |
| 229 | + int16_t status; | |
| 230 | + uint32_t msg_length; | |
| 231 | + uint32_t res; | |
| 221 | 232 | }; |
| 222 | 233 | |
| 223 | - | |
| 224 | -#define PRINT_TMD(T) printf( \ | |
| 225 | - "TMD0 : TBADR=0x%08x\n" \ | |
| 234 | +#define RMDL_BCNT_MASK 0x0fff | |
| 235 | +#define RMDL_BCNT_SH 0 | |
| 236 | +#define RMDL_ONES_MASK 0xf000 | |
| 237 | +#define RMDL_ONES_SH 12 | |
| 238 | + | |
| 239 | +#define RMDS_BAM_MASK 0x0010 | |
| 240 | +#define RMDS_BAM_SH 4 | |
| 241 | +#define RMDS_LFAM_MASK 0x0020 | |
| 242 | +#define RMDS_LFAM_SH 5 | |
| 243 | +#define RMDS_PAM_MASK 0x0040 | |
| 244 | +#define RMDS_PAM_SH 6 | |
| 245 | +#define RMDS_BPE_MASK 0x0080 | |
| 246 | +#define RMDS_BPE_SH 7 | |
| 247 | +#define RMDS_ENP_MASK 0x0100 | |
| 248 | +#define RMDS_ENP_SH 8 | |
| 249 | +#define RMDS_STP_MASK 0x0200 | |
| 250 | +#define RMDS_STP_SH 9 | |
| 251 | +#define RMDS_BUFF_MASK 0x0400 | |
| 252 | +#define RMDS_BUFF_SH 10 | |
| 253 | +#define RMDS_CRC_MASK 0x0800 | |
| 254 | +#define RMDS_CRC_SH 11 | |
| 255 | +#define RMDS_OFLO_MASK 0x1000 | |
| 256 | +#define RMDS_OFLO_SH 12 | |
| 257 | +#define RMDS_FRAM_MASK 0x2000 | |
| 258 | +#define RMDS_FRAM_SH 13 | |
| 259 | +#define RMDS_ERR_MASK 0x4000 | |
| 260 | +#define RMDS_ERR_SH 14 | |
| 261 | +#define RMDS_OWN_MASK 0x8000 | |
| 262 | +#define RMDS_OWN_SH 15 | |
| 263 | + | |
| 264 | +#define RMDM_MCNT_MASK 0x00000fff | |
| 265 | +#define RMDM_MCNT_SH 0 | |
| 266 | +#define RMDM_ZEROS_MASK 0x0000f000 | |
| 267 | +#define RMDM_ZEROS_SH 12 | |
| 268 | +#define RMDM_RPC_MASK 0x00ff0000 | |
| 269 | +#define RMDM_RPC_SH 16 | |
| 270 | +#define RMDM_RCC_MASK 0xff000000 | |
| 271 | +#define RMDM_RCC_SH 24 | |
| 272 | + | |
| 273 | +#define SET_FIELD(regp, name, field, value) \ | |
| 274 | + (*(regp) = (*(regp) & ~(name ## _ ## field ## _MASK)) \ | |
| 275 | + | ((value) << name ## _ ## field ## _SH)) | |
| 276 | + | |
| 277 | +#define GET_FIELD(reg, name, field) \ | |
| 278 | + (((reg) & name ## _ ## field ## _MASK) >> name ## _ ## field ## _SH) | |
| 279 | + | |
| 280 | +#define PRINT_TMD(T) printf( \ | |
| 281 | + "TMD0 : TBADR=0x%08x\n" \ | |
| 226 | 282 | "TMD1 : OWN=%d, ERR=%d, FCS=%d, LTI=%d, " \ |
| 227 | 283 | "ONE=%d, DEF=%d, STP=%d, ENP=%d,\n" \ |
| 228 | 284 | " BPE=%d, BCNT=%d\n" \ |
| 229 | 285 | "TMD2 : BUF=%d, UFL=%d, EXD=%d, LCO=%d, " \ |
| 230 | 286 | "LCA=%d, RTR=%d,\n" \ |
| 231 | 287 | " TDR=%d, TRC=%d\n", \ |
| 232 | - (T)->tmd0.tbadr, \ | |
| 233 | - (T)->tmd1.own, (T)->tmd1.err, (T)->tmd1.nofcs, \ | |
| 234 | - (T)->tmd1.ltint, (T)->tmd1.one, (T)->tmd1.def, \ | |
| 235 | - (T)->tmd1.stp, (T)->tmd1.enp, (T)->tmd1.bpe, \ | |
| 236 | - 4096-(T)->tmd1.bcnt, \ | |
| 237 | - (T)->tmd2.buff, (T)->tmd2.uflo, (T)->tmd2.exdef,\ | |
| 238 | - (T)->tmd2.lcol, (T)->tmd2.lcar, (T)->tmd2.rtry, \ | |
| 239 | - (T)->tmd2.tdr, (T)->tmd2.trc) | |
| 240 | - | |
| 241 | -#define PRINT_RMD(R) printf( \ | |
| 242 | - "RMD0 : RBADR=0x%08x\n" \ | |
| 288 | + (T)->tbadr, \ | |
| 289 | + GET_FIELD((T)->status, TMDS, OWN), \ | |
| 290 | + GET_FIELD((T)->status, TMDS, ERR), \ | |
| 291 | + GET_FIELD((T)->status, TMDS, NOFCS), \ | |
| 292 | + GET_FIELD((T)->status, TMDS, LTINT), \ | |
| 293 | + GET_FIELD((T)->status, TMDS, ONE), \ | |
| 294 | + GET_FIELD((T)->status, TMDS, DEF), \ | |
| 295 | + GET_FIELD((T)->status, TMDS, STP), \ | |
| 296 | + GET_FIELD((T)->status, TMDS, ENP), \ | |
| 297 | + GET_FIELD((T)->status, TMDS, BPE), \ | |
| 298 | + 4096-GET_FIELD((T)->length, TMDL, BCNT), \ | |
| 299 | + GET_FIELD((T)->misc, TMDM, BUFF), \ | |
| 300 | + GET_FIELD((T)->misc, TMDM, UFLO), \ | |
| 301 | + GET_FIELD((T)->misc, TMDM, EXDEF), \ | |
| 302 | + GET_FIELD((T)->misc, TMDM, LCOL), \ | |
| 303 | + GET_FIELD((T)->misc, TMDM, LCAR), \ | |
| 304 | + GET_FIELD((T)->misc, TMDM, RTRY), \ | |
| 305 | + GET_FIELD((T)->misc, TMDM, TDR), \ | |
| 306 | + GET_FIELD((T)->misc, TMDM, TRC)) | |
| 307 | + | |
| 308 | +#define PRINT_RMD(R) printf( \ | |
| 309 | + "RMD0 : RBADR=0x%08x\n" \ | |
| 243 | 310 | "RMD1 : OWN=%d, ERR=%d, FRAM=%d, OFLO=%d, " \ |
| 244 | 311 | "CRC=%d, BUFF=%d, STP=%d, ENP=%d,\n " \ |
| 245 | - "BPE=%d, PAM=%d, LAFM=%d, BAM=%d, ONES=%d, BCNT=%d\n" \ | |
| 312 | + "BPE=%d, PAM=%d, LAFM=%d, BAM=%d, ONES=%d, BCNT=%d\n" \ | |
| 246 | 313 | "RMD2 : RCC=%d, RPC=%d, MCNT=%d, ZEROS=%d\n", \ |
| 247 | - (R)->rmd0.rbadr, \ | |
| 248 | - (R)->rmd1.own, (R)->rmd1.err, (R)->rmd1.fram, \ | |
| 249 | - (R)->rmd1.oflo, (R)->rmd1.crc, (R)->rmd1.buff, \ | |
| 250 | - (R)->rmd1.stp, (R)->rmd1.enp, (R)->rmd1.bpe, \ | |
| 251 | - (R)->rmd1.pam, (R)->rmd1.lafm, (R)->rmd1.bam, \ | |
| 252 | - (R)->rmd1.ones, 4096-(R)->rmd1.bcnt, \ | |
| 253 | - (R)->rmd2.rcc, (R)->rmd2.rpc, (R)->rmd2.mcnt, \ | |
| 254 | - (R)->rmd2.zeros) | |
| 255 | - | |
| 256 | -static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd1, | |
| 314 | + (R)->rbadr, \ | |
| 315 | + GET_FIELD((R)->status, RMDS, OWN), \ | |
| 316 | + GET_FIELD((R)->status, RMDS, ERR), \ | |
| 317 | + GET_FIELD((R)->status, RMDS, FRAM), \ | |
| 318 | + GET_FIELD((R)->status, RMDS, OFLO), \ | |
| 319 | + GET_FIELD((R)->status, RMDS, CRC), \ | |
| 320 | + GET_FIELD((R)->status, RMDS, BUFF), \ | |
| 321 | + GET_FIELD((R)->status, RMDS, STP), \ | |
| 322 | + GET_FIELD((R)->status, RMDS, ENP), \ | |
| 323 | + GET_FIELD((R)->status, RMDS, BPE), \ | |
| 324 | + GET_FIELD((R)->status, RMDS, PAM), \ | |
| 325 | + GET_FIELD((R)->status, RMDS, LFAM), \ | |
| 326 | + GET_FIELD((R)->status, RMDS, BAM), \ | |
| 327 | + GET_FIELD((R)->buf_length, RMDL, ONES), \ | |
| 328 | + 4096-GET_FIELD((R)->buf_length, RMDL, BCNT), \ | |
| 329 | + GET_FIELD((R)->msg_length, RMDM, RCC), \ | |
| 330 | + GET_FIELD((R)->msg_length, RMDM, RPC), \ | |
| 331 | + GET_FIELD((R)->msg_length, RMDM, MCNT), \ | |
| 332 | + GET_FIELD((R)->msg_length, RMDM, ZEROS)) | |
| 333 | + | |
| 334 | +static inline void pcnet_tmd_load(PCNetState *s, struct pcnet_TMD *tmd, | |
| 257 | 335 | target_phys_addr_t addr) |
| 258 | 336 | { |
| 259 | - uint32_t *tmd = (uint32_t *)tmd1; | |
| 260 | - | |
| 261 | - if (!BCR_SWSTYLE(s)) { | |
| 262 | - uint16_t xda[4]; | |
| 263 | - s->phys_mem_read(s->dma_opaque, addr, | |
| 264 | - (void *)&xda[0], sizeof(xda), 0); | |
| 265 | - le16_to_cpus(&xda[0]); | |
| 266 | - le16_to_cpus(&xda[1]); | |
| 267 | - le16_to_cpus(&xda[2]); | |
| 268 | - le16_to_cpus(&xda[3]); | |
| 269 | - tmd[0] = (xda[0]&0xffff) | | |
| 270 | - ((xda[1]&0x00ff) << 16); | |
| 271 | - tmd[1] = (xda[2]&0xffff)| | |
| 272 | - ((xda[1] & 0xff00) << 16); | |
| 273 | - tmd[2] = | |
| 274 | - (xda[3] & 0xffff) << 16; | |
| 275 | - tmd[3] = 0; | |
| 337 | + if (!BCR_SSIZE32(s)) { | |
| 338 | + struct { | |
| 339 | + uint32_t tbadr; | |
| 340 | + int16_t length; | |
| 341 | + int16_t status; | |
| 342 | + } xda; | |
| 343 | + s->phys_mem_read(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); | |
| 344 | + tmd->tbadr = le32_to_cpu(xda.tbadr) & 0xffffff; | |
| 345 | + tmd->length = le16_to_cpu(xda.length); | |
| 346 | + tmd->status = (le32_to_cpu(xda.tbadr) >> 16) & 0xff00; | |
| 347 | + tmd->misc = le16_to_cpu(xda.status) << 16; | |
| 348 | + tmd->res = 0; | |
| 276 | 349 | } else { |
| 277 | - uint32_t xda[4]; | |
| 278 | - s->phys_mem_read(s->dma_opaque, addr, | |
| 279 | - (void *)&xda[0], sizeof(xda), 0); | |
| 280 | - le32_to_cpus(&xda[0]); | |
| 281 | - le32_to_cpus(&xda[1]); | |
| 282 | - le32_to_cpus(&xda[2]); | |
| 283 | - le32_to_cpus(&xda[3]); | |
| 284 | - if (BCR_SWSTYLE(s) != 3) { | |
| 285 | - memcpy(tmd, xda, sizeof(xda)); | |
| 286 | - } else { | |
| 287 | - tmd[0] = xda[2]; | |
| 288 | - tmd[1] = xda[1]; | |
| 289 | - tmd[2] = xda[0]; | |
| 290 | - tmd[3] = xda[3]; | |
| 350 | + s->phys_mem_read(s->dma_opaque, addr, (void *)tmd, sizeof(*tmd), 0); | |
| 351 | + le32_to_cpus(&tmd->tbadr); | |
| 352 | + le16_to_cpus(&tmd->length); | |
| 353 | + le16_to_cpus(&tmd->status); | |
| 354 | + le32_to_cpus(&tmd->misc); | |
| 355 | + le32_to_cpus(&tmd->res); | |
| 356 | + if (BCR_SWSTYLE(s) == 3) { | |
| 357 | + uint32_t tmp = tmd->tbadr; | |
| 358 | + tmd->tbadr = tmd->misc; | |
| 359 | + tmd->misc = tmp; | |
| 291 | 360 | } |
| 292 | 361 | } |
| 293 | 362 | } |
| 294 | 363 | |
| 295 | -static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd1, | |
| 364 | +static inline void pcnet_tmd_store(PCNetState *s, const struct pcnet_TMD *tmd, | |
| 296 | 365 | target_phys_addr_t addr) |
| 297 | 366 | { |
| 298 | - const uint32_t *tmd = (const uint32_t *)tmd1; | |
| 299 | - if (!BCR_SWSTYLE(s)) { | |
| 300 | - uint16_t xda[4]; | |
| 301 | - xda[0] = tmd[0] & 0xffff; | |
| 302 | - xda[1] = ((tmd[0]>>16)&0x00ff) | | |
| 303 | - ((tmd[1]>>16)&0xff00); | |
| 304 | - xda[2] = tmd[1] & 0xffff; | |
| 305 | - xda[3] = tmd[2] >> 16; | |
| 306 | - cpu_to_le16s(&xda[0]); | |
| 307 | - cpu_to_le16s(&xda[1]); | |
| 308 | - cpu_to_le16s(&xda[2]); | |
| 309 | - cpu_to_le16s(&xda[3]); | |
| 310 | - s->phys_mem_write(s->dma_opaque, addr, | |
| 311 | - (void *)&xda[0], sizeof(xda), 0); | |
| 367 | + if (!BCR_SSIZE32(s)) { | |
| 368 | + struct { | |
| 369 | + uint32_t tbadr; | |
| 370 | + int16_t length; | |
| 371 | + int16_t status; | |
| 372 | + } xda; | |
| 373 | + xda.tbadr = cpu_to_le32((tmd->tbadr & 0xffffff) | | |
| 374 | + ((tmd->status & 0xff00) << 16)); | |
| 375 | + xda.length = cpu_to_le16(tmd->length); | |
| 376 | + xda.status = cpu_to_le16(tmd->misc >> 16); | |
| 377 | + s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); | |
| 312 | 378 | } else { |
| 313 | - uint32_t xda[4]; | |
| 314 | - if (BCR_SWSTYLE(s) != 3) { | |
| 315 | - memcpy(xda, tmd, sizeof(xda)); | |
| 316 | - } else { | |
| 317 | - xda[0] = tmd[2]; | |
| 318 | - xda[1] = tmd[1]; | |
| 319 | - xda[2] = tmd[0]; | |
| 320 | - xda[3] = tmd[3]; | |
| 379 | + struct { | |
| 380 | + uint32_t tbadr; | |
| 381 | + int16_t length; | |
| 382 | + int16_t status; | |
| 383 | + uint32_t misc; | |
| 384 | + uint32_t res; | |
| 385 | + } xda; | |
| 386 | + xda.tbadr = cpu_to_le32(tmd->tbadr); | |
| 387 | + xda.length = cpu_to_le16(tmd->length); | |
| 388 | + xda.status = cpu_to_le16(tmd->status); | |
| 389 | + xda.misc = cpu_to_le32(tmd->misc); | |
| 390 | + xda.res = cpu_to_le32(tmd->res); | |
| 391 | + if (BCR_SWSTYLE(s) == 3) { | |
| 392 | + uint32_t tmp = xda.tbadr; | |
| 393 | + xda.tbadr = xda.misc; | |
| 394 | + xda.misc = tmp; | |
| 321 | 395 | } |
| 322 | - cpu_to_le32s(&xda[0]); | |
| 323 | - cpu_to_le32s(&xda[1]); | |
| 324 | - cpu_to_le32s(&xda[2]); | |
| 325 | - cpu_to_le32s(&xda[3]); | |
| 326 | - s->phys_mem_write(s->dma_opaque, addr, | |
| 327 | - (void *)&xda[0], sizeof(xda), 0); | |
| 396 | + s->phys_mem_write(s->dma_opaque, addr, (void *)&xda, sizeof(xda), 0); | |
| 328 | 397 | } |
| 329 | 398 | } |
| 330 | 399 | |
| 331 | -static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd1, | |
| 400 | +static inline void pcnet_rmd_load(PCNetState *s, struct pcnet_RMD *rmd, | |
| 332 | 401 | target_phys_addr_t addr) |
| 333 | 402 | { |
| 334 | - uint32_t *rmd = (uint32_t *)rmd1; | |
| 335 | - | |
| 336 | - if (!BCR_SWSTYLE(s)) { | |
| 337 | - uint16_t rda[4]; | |
| 338 | - s->phys_mem_read(s->dma_opaque, addr, | |
| 339 | - (void *)&rda[0], sizeof(rda), 0); | |
| 340 | - le16_to_cpus(&rda[0]); | |
| 341 | - le16_to_cpus(&rda[1]); | |
| 342 | - le16_to_cpus(&rda[2]); | |
| 343 | - le16_to_cpus(&rda[3]); | |
| 344 | - rmd[0] = (rda[0]&0xffff)| | |
| 345 | - ((rda[1] & 0x00ff) << 16); | |
| 346 | - rmd[1] = (rda[2]&0xffff)| | |
| 347 | - ((rda[1] & 0xff00) << 16); | |
| 348 | - rmd[2] = rda[3] & 0xffff; | |
| 349 | - rmd[3] = 0; | |
| 403 | + if (!BCR_SSIZE32(s)) { | |
| 404 | + struct { | |
| 405 | + uint32_t rbadr; | |
| 406 | + int16_t buf_length; | |
| 407 | + int16_t msg_length; | |
| 408 | + } rda; | |
| 409 | + s->phys_mem_read(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); | |
| 410 | + rmd->rbadr = le32_to_cpu(rda.rbadr) & 0xffffff; | |
| 411 | + rmd->buf_length = le16_to_cpu(rda.buf_length); | |
| 412 | + rmd->status = (le32_to_cpu(rda.rbadr) >> 16) & 0xff00; | |
| 413 | + rmd->msg_length = le16_to_cpu(rda.msg_length); | |
| 414 | + rmd->res = 0; | |
| 350 | 415 | } else { |
| 351 | - uint32_t rda[4]; | |
| 352 | - s->phys_mem_read(s->dma_opaque, addr, | |
| 353 | - (void *)&rda[0], sizeof(rda), 0); | |
| 354 | - le32_to_cpus(&rda[0]); | |
| 355 | - le32_to_cpus(&rda[1]); | |
| 356 | - le32_to_cpus(&rda[2]); | |
| 357 | - le32_to_cpus(&rda[3]); | |
| 358 | - if (BCR_SWSTYLE(s) != 3) { | |
| 359 | - memcpy(rmd, rda, sizeof(rda)); | |
| 360 | - } else { | |
| 361 | - rmd[0] = rda[2]; | |
| 362 | - rmd[1] = rda[1]; | |
| 363 | - rmd[2] = rda[0]; | |
| 364 | - rmd[3] = rda[3]; | |
| 416 | + s->phys_mem_read(s->dma_opaque, addr, (void *)rmd, sizeof(*rmd), 0); | |
| 417 | + le32_to_cpus(&rmd->rbadr); | |
| 418 | + le16_to_cpus(&rmd->buf_length); | |
| 419 | + le16_to_cpus(&rmd->status); | |
| 420 | + le32_to_cpus(&rmd->msg_length); | |
| 421 | + le32_to_cpus(&rmd->res); | |
| 422 | + if (BCR_SWSTYLE(s) == 3) { | |
| 423 | + uint32_t tmp = rmd->rbadr; | |
| 424 | + rmd->rbadr = rmd->msg_length; | |
| 425 | + rmd->msg_length = tmp; | |
| 365 | 426 | } |
| 366 | 427 | } |
| 367 | 428 | } |
| 368 | 429 | |
| 369 | -static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, | |
| 430 | +static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd, | |
| 370 | 431 | target_phys_addr_t addr) |
| 371 | 432 | { |
| 372 | - const uint32_t *rmd = (const uint32_t *)rmd1; | |
| 373 | - | |
| 374 | - if (!BCR_SWSTYLE(s)) { | |
| 375 | - uint16_t rda[4]; | |
| 376 | - rda[0] = rmd[0] & 0xffff; | |
| 377 | - rda[1] = ((rmd[0]>>16)&0xff)| | |
| 378 | - ((rmd[1]>>16)&0xff00); | |
| 379 | - rda[2] = rmd[1] & 0xffff; | |
| 380 | - rda[3] = rmd[2] & 0xffff; | |
| 381 | - cpu_to_le16s(&rda[0]); | |
| 382 | - cpu_to_le16s(&rda[1]); | |
| 383 | - cpu_to_le16s(&rda[2]); | |
| 384 | - cpu_to_le16s(&rda[3]); | |
| 385 | - s->phys_mem_write(s->dma_opaque, addr, | |
| 386 | - (void *)&rda[0], sizeof(rda), 0); | |
| 433 | + if (!BCR_SSIZE32(s)) { | |
| 434 | + struct { | |
| 435 | + uint32_t rbadr; | |
| 436 | + int16_t buf_length; | |
| 437 | + int16_t msg_length; | |
| 438 | + } rda; | |
| 439 | + rda.rbadr = cpu_to_le32((rmd->rbadr & 0xffffff) | | |
| 440 | + ((rmd->status & 0xff00) << 16)); | |
| 441 | + rda.buf_length = cpu_to_le16(rmd->buf_length); | |
| 442 | + rda.msg_length = cpu_to_le16(rmd->msg_length); | |
| 443 | + s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); | |
| 387 | 444 | } else { |
| 388 | - uint32_t rda[4]; | |
| 389 | - if (BCR_SWSTYLE(s) != 3) { | |
| 390 | - memcpy(rda, rmd, sizeof(rda)); | |
| 391 | - } else { | |
| 392 | - rda[0] = rmd[2]; | |
| 393 | - rda[1] = rmd[1]; | |
| 394 | - rda[2] = rmd[0]; | |
| 395 | - rda[3] = rmd[3]; | |
| 445 | + struct { | |
| 446 | + uint32_t rbadr; | |
| 447 | + int16_t buf_length; | |
| 448 | + int16_t status; | |
| 449 | + uint32_t msg_length; | |
| 450 | + uint32_t res; | |
| 451 | + } rda; | |
| 452 | + rda.rbadr = cpu_to_le32(rmd->rbadr); | |
| 453 | + rda.buf_length = cpu_to_le16(rmd->buf_length); | |
| 454 | + rda.status = cpu_to_le16(rmd->status); | |
| 455 | + rda.msg_length = cpu_to_le32(rmd->msg_length); | |
| 456 | + rda.res = cpu_to_le32(rmd->res); | |
| 457 | + if (BCR_SWSTYLE(s) == 3) { | |
| 458 | + uint32_t tmp = rda.rbadr; | |
| 459 | + rda.rbadr = rda.msg_length; | |
| 460 | + rda.msg_length = tmp; | |
| 396 | 461 | } |
| 397 | - cpu_to_le32s(&rda[0]); | |
| 398 | - cpu_to_le32s(&rda[1]); | |
| 399 | - cpu_to_le32s(&rda[2]); | |
| 400 | - cpu_to_le32s(&rda[3]); | |
| 401 | - s->phys_mem_write(s->dma_opaque, addr, | |
| 402 | - (void *)&rda[0], sizeof(rda), 0); | |
| 462 | + s->phys_mem_write(s->dma_opaque, addr, (void *)&rda, sizeof(rda), 0); | |
| 403 | 463 | } |
| 404 | 464 | } |
| 405 | 465 | |
| ... | ... | @@ -417,14 +477,14 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 417 | 477 | #define CHECK_RMD(ADDR,RES) do { \ |
| 418 | 478 | struct pcnet_RMD rmd; \ |
| 419 | 479 | RMDLOAD(&rmd,(ADDR)); \ |
| 420 | - (RES) |= (rmd.rmd1.ones != 15) \ | |
| 421 | - || (rmd.rmd2.zeros != 0); \ | |
| 480 | + (RES) |= (GET_FIELD(rmd.buf_length, RMDL, ONES) != 15) \ | |
| 481 | + || (GET_FIELD(rmd.msg_length, RMDM, ZEROS) != 0); \ | |
| 422 | 482 | } while (0) |
| 423 | 483 | |
| 424 | 484 | #define CHECK_TMD(ADDR,RES) do { \ |
| 425 | 485 | struct pcnet_TMD tmd; \ |
| 426 | 486 | TMDLOAD(&tmd,(ADDR)); \ |
| 427 | - (RES) |= (tmd.tmd1.ones != 15); \ | |
| 487 | + (RES) |= (GET_FIELD(tmd.length, TMDL, ONES) != 15); \ | |
| 428 | 488 | } while (0) |
| 429 | 489 | |
| 430 | 490 | #else |
| ... | ... | @@ -434,8 +494,8 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 434 | 494 | case 0x00: \ |
| 435 | 495 | do { \ |
| 436 | 496 | uint16_t rda[4]; \ |
| 437 | - s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 438 | - (void *)&rda[0], sizeof(rda), 0); \ | |
| 497 | + s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 498 | + (void *)&rda[0], sizeof(rda), 0); \ | |
| 439 | 499 | (RES) |= (rda[2] & 0xf000)!=0xf000; \ |
| 440 | 500 | (RES) |= (rda[3] & 0xf000)!=0x0000; \ |
| 441 | 501 | } while (0); \ |
| ... | ... | @@ -444,7 +504,7 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 444 | 504 | case 0x02: \ |
| 445 | 505 | do { \ |
| 446 | 506 | uint32_t rda[4]; \ |
| 447 | - s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 507 | + s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 448 | 508 | (void *)&rda[0], sizeof(rda), 0); \ |
| 449 | 509 | (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ |
| 450 | 510 | (RES) |= (rda[2] & 0x0000f000L)!=0x00000000L; \ |
| ... | ... | @@ -453,7 +513,7 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 453 | 513 | case 0x03: \ |
| 454 | 514 | do { \ |
| 455 | 515 | uint32_t rda[4]; \ |
| 456 | - s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 516 | + s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 457 | 517 | (void *)&rda[0], sizeof(rda), 0); \ |
| 458 | 518 | (RES) |= (rda[0] & 0x0000f000L)!=0x00000000L; \ |
| 459 | 519 | (RES) |= (rda[1] & 0x0000f000L)!=0x0000f000L; \ |
| ... | ... | @@ -467,9 +527,9 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 467 | 527 | case 0x00: \ |
| 468 | 528 | do { \ |
| 469 | 529 | uint16_t xda[4]; \ |
| 470 | - s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 471 | - (void *)&xda[0], sizeof(xda), 0); \ | |
| 472 | - (RES) |= (xda[2] & 0xf000)!=0xf000;\ | |
| 530 | + s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 531 | + (void *)&xda[0], sizeof(xda), 0); \ | |
| 532 | + (RES) |= (xda[2] & 0xf000)!=0xf000; \ | |
| 473 | 533 | } while (0); \ |
| 474 | 534 | break; \ |
| 475 | 535 | case 0x01: \ |
| ... | ... | @@ -477,8 +537,8 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 477 | 537 | case 0x03: \ |
| 478 | 538 | do { \ |
| 479 | 539 | uint32_t xda[4]; \ |
| 480 | - s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 481 | - (void *)&xda[0], sizeof(xda), 0); \ | |
| 540 | + s->phys_mem_read(s->dma_opaque, (ADDR), \ | |
| 541 | + (void *)&xda[0], sizeof(xda), 0); \ | |
| 482 | 542 | (RES) |= (xda[1] & 0x0000f000L)!=0x0000f000L; \ |
| 483 | 543 | } while (0); \ |
| 484 | 544 | break; \ |
| ... | ... | @@ -488,15 +548,15 @@ static inline void pcnet_rmd_store(PCNetState *s, struct pcnet_RMD *rmd1, |
| 488 | 548 | #endif |
| 489 | 549 | |
| 490 | 550 | #define PRINT_PKTHDR(BUF) do { \ |
| 491 | - struct qemu_ether_header *hdr = (void *)(BUF); \ | |
| 492 | - printf("packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, " \ | |
| 493 | - "shost=%02x:%02x:%02x:%02x:%02x:%02x, " \ | |
| 494 | - "type=0x%04x\n", \ | |
| 551 | + struct qemu_ether_header *hdr = (void *)(BUF); \ | |
| 552 | + printf("packet dhost=%02x:%02x:%02x:%02x:%02x:%02x, " \ | |
| 553 | + "shost=%02x:%02x:%02x:%02x:%02x:%02x, " \ | |
| 554 | + "type=0x%04x\n", \ | |
| 495 | 555 | hdr->ether_dhost[0],hdr->ether_dhost[1],hdr->ether_dhost[2], \ |
| 496 | 556 | hdr->ether_dhost[3],hdr->ether_dhost[4],hdr->ether_dhost[5], \ |
| 497 | 557 | hdr->ether_shost[0],hdr->ether_shost[1],hdr->ether_shost[2], \ |
| 498 | 558 | hdr->ether_shost[3],hdr->ether_shost[4],hdr->ether_shost[5], \ |
| 499 | - be16_to_cpu(hdr->ether_type)); \ | |
| 559 | + be16_to_cpu(hdr->ether_type)); \ | |
| 500 | 560 | } while (0) |
| 501 | 561 | |
| 502 | 562 | #define MULTICAST_FILTER_LEN 8 |
| ... | ... | @@ -770,7 +830,7 @@ static void pcnet_update_irq(PCNetState *s) |
| 770 | 830 | static void pcnet_init(PCNetState *s) |
| 771 | 831 | { |
| 772 | 832 | int rlen, tlen; |
| 773 | - uint16_t *padr, *ladrf, mode; | |
| 833 | + uint16_t padr[3], ladrf[4], mode; | |
| 774 | 834 | uint32_t rdra, tdra; |
| 775 | 835 | |
| 776 | 836 | #ifdef PCNET_DEBUG |
| ... | ... | @@ -781,22 +841,30 @@ static void pcnet_init(PCNetState *s) |
| 781 | 841 | struct pcnet_initblk32 initblk; |
| 782 | 842 | s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)), |
| 783 | 843 | (uint8_t *)&initblk, sizeof(initblk), 0); |
| 784 | - mode = initblk.mode; | |
| 844 | + mode = le16_to_cpu(initblk.mode); | |
| 785 | 845 | rlen = initblk.rlen >> 4; |
| 786 | 846 | tlen = initblk.tlen >> 4; |
| 787 | - ladrf = initblk.ladrf; | |
| 788 | - padr = initblk.padr; | |
| 847 | + ladrf[0] = le16_to_cpu(initblk.ladrf[0]); | |
| 848 | + ladrf[1] = le16_to_cpu(initblk.ladrf[1]); | |
| 849 | + ladrf[2] = le16_to_cpu(initblk.ladrf[2]); | |
| 850 | + ladrf[3] = le16_to_cpu(initblk.ladrf[3]); | |
| 851 | + padr[0] = le16_to_cpu(initblk.padr[0]); | |
| 852 | + padr[1] = le16_to_cpu(initblk.padr[1]); | |
| 853 | + padr[2] = le16_to_cpu(initblk.padr[2]); | |
| 789 | 854 | rdra = le32_to_cpu(initblk.rdra); |
| 790 | 855 | tdra = le32_to_cpu(initblk.tdra); |
| 791 | - s->rdra = PHYSADDR(s,initblk.rdra); | |
| 792 | - s->tdra = PHYSADDR(s,initblk.tdra); | |
| 793 | 856 | } else { |
| 794 | 857 | struct pcnet_initblk16 initblk; |
| 795 | 858 | s->phys_mem_read(s->dma_opaque, PHYSADDR(s,CSR_IADR(s)), |
| 796 | 859 | (uint8_t *)&initblk, sizeof(initblk), 0); |
| 797 | - mode = initblk.mode; | |
| 798 | - ladrf = initblk.ladrf; | |
| 799 | - padr = initblk.padr; | |
| 860 | + mode = le16_to_cpu(initblk.mode); | |
| 861 | + ladrf[0] = le16_to_cpu(initblk.ladrf[0]); | |
| 862 | + ladrf[1] = le16_to_cpu(initblk.ladrf[1]); | |
| 863 | + ladrf[2] = le16_to_cpu(initblk.ladrf[2]); | |
| 864 | + ladrf[3] = le16_to_cpu(initblk.ladrf[3]); | |
| 865 | + padr[0] = le16_to_cpu(initblk.padr[0]); | |
| 866 | + padr[1] = le16_to_cpu(initblk.padr[1]); | |
| 867 | + padr[2] = le16_to_cpu(initblk.padr[2]); | |
| 800 | 868 | rdra = le32_to_cpu(initblk.rdra); |
| 801 | 869 | tdra = le32_to_cpu(initblk.tdra); |
| 802 | 870 | rlen = rdra >> 29; |
| ... | ... | @@ -804,22 +872,22 @@ static void pcnet_init(PCNetState *s) |
| 804 | 872 | rdra &= 0x00ffffff; |
| 805 | 873 | tdra &= 0x00ffffff; |
| 806 | 874 | } |
| 807 | - | |
| 875 | + | |
| 808 | 876 | #if defined(PCNET_DEBUG) |
| 809 | - printf("rlen=%d tlen=%d\n", | |
| 810 | - rlen, tlen); | |
| 877 | + printf("rlen=%d tlen=%d\n", rlen, tlen); | |
| 811 | 878 | #endif |
| 879 | + | |
| 812 | 880 | CSR_RCVRL(s) = (rlen < 9) ? (1 << rlen) : 512; |
| 813 | 881 | CSR_XMTRL(s) = (tlen < 9) ? (1 << tlen) : 512; |
| 814 | 882 | s->csr[ 6] = (tlen << 12) | (rlen << 8); |
| 815 | - s->csr[15] = le16_to_cpu(mode); | |
| 816 | - s->csr[ 8] = le16_to_cpu(ladrf[0]); | |
| 817 | - s->csr[ 9] = le16_to_cpu(ladrf[1]); | |
| 818 | - s->csr[10] = le16_to_cpu(ladrf[2]); | |
| 819 | - s->csr[11] = le16_to_cpu(ladrf[3]); | |
| 820 | - s->csr[12] = le16_to_cpu(padr[0]); | |
| 821 | - s->csr[13] = le16_to_cpu(padr[1]); | |
| 822 | - s->csr[14] = le16_to_cpu(padr[2]); | |
| 883 | + s->csr[15] = mode; | |
| 884 | + s->csr[ 8] = ladrf[0]; | |
| 885 | + s->csr[ 9] = ladrf[1]; | |
| 886 | + s->csr[10] = ladrf[2]; | |
| 887 | + s->csr[11] = ladrf[3]; | |
| 888 | + s->csr[12] = padr[0]; | |
| 889 | + s->csr[13] = padr[1]; | |
| 890 | + s->csr[14] = padr[2]; | |
| 823 | 891 | s->rdra = PHYSADDR(s, rdra); |
| 824 | 892 | s->tdra = PHYSADDR(s, tdra); |
| 825 | 893 | |
| ... | ... | @@ -914,12 +982,12 @@ static void pcnet_rdte_poll(PCNetState *s) |
| 914 | 982 | if (CSR_CRDA(s)) { |
| 915 | 983 | struct pcnet_RMD rmd; |
| 916 | 984 | RMDLOAD(&rmd, PHYSADDR(s,CSR_CRDA(s))); |
| 917 | - CSR_CRBC(s) = rmd.rmd1.bcnt; | |
| 918 | - CSR_CRST(s) = ((uint32_t *)&rmd)[1] >> 16; | |
| 985 | + CSR_CRBC(s) = GET_FIELD(rmd.buf_length, RMDL, BCNT); | |
| 986 | + CSR_CRST(s) = rmd.status; | |
| 919 | 987 | #ifdef PCNET_DEBUG_RMD_X |
| 920 | - printf("CRDA=0x%08x CRST=0x%04x RCVRC=%d RMD1=0x%08x RMD2=0x%08x\n", | |
| 988 | + printf("CRDA=0x%08x CRST=0x%04x RCVRC=%d RMDL=0x%04x RMDS=0x%04x RMDM=0x%08x\n", | |
| 921 | 989 | PHYSADDR(s,CSR_CRDA(s)), CSR_CRST(s), CSR_RCVRC(s), |
| 922 | - ((uint32_t *)&rmd)[1], ((uint32_t *)&rmd)[2]); | |
| 990 | + rmd.buf_length, rmd.status, rmd.msg_length); | |
| 923 | 991 | PRINT_RMD(&rmd); |
| 924 | 992 | #endif |
| 925 | 993 | } else { |
| ... | ... | @@ -929,8 +997,8 @@ static void pcnet_rdte_poll(PCNetState *s) |
| 929 | 997 | if (CSR_NRDA(s)) { |
| 930 | 998 | struct pcnet_RMD rmd; |
| 931 | 999 | RMDLOAD(&rmd, PHYSADDR(s,CSR_NRDA(s))); |
| 932 | - CSR_NRBC(s) = rmd.rmd1.bcnt; | |
| 933 | - CSR_NRST(s) = ((uint32_t *)&rmd)[1] >> 16; | |
| 1000 | + CSR_NRBC(s) = GET_FIELD(rmd.buf_length, RMDL, BCNT); | |
| 1001 | + CSR_NRST(s) = rmd.status; | |
| 934 | 1002 | } else { |
| 935 | 1003 | CSR_NRBC(s) = CSR_NRST(s) = 0; |
| 936 | 1004 | } |
| ... | ... | @@ -943,7 +1011,7 @@ static int pcnet_tdte_poll(PCNetState *s) |
| 943 | 1011 | if (s->tdra) { |
| 944 | 1012 | target_phys_addr_t cxda = s->tdra + |
| 945 | 1013 | (CSR_XMTRL(s) - CSR_XMTRC(s)) * |
| 946 | - (BCR_SWSTYLE(s) ? 16 : 8 ); | |
| 1014 | + (BCR_SWSTYLE(s) ? 16 : 8); | |
| 947 | 1015 | int bad = 0; |
| 948 | 1016 | CHECK_TMD(PHYSADDR(s, cxda),bad); |
| 949 | 1017 | if (!bad) { |
| ... | ... | @@ -955,8 +1023,7 @@ static int pcnet_tdte_poll(PCNetState *s) |
| 955 | 1023 | } |
| 956 | 1024 | s->csr[34] = cxda & 0xffff; |
| 957 | 1025 | s->csr[35] = cxda >> 16; |
| 958 | -#ifdef PCNET_DEBUG | |
| 959 | - } else { | |
| 1026 | +#ifdef PCNET_DEBUG_X | |
| 960 | 1027 | printf("pcnet: BAD TMD XDA=0x%08x\n", PHYSADDR(s,cxda)); |
| 961 | 1028 | #endif |
| 962 | 1029 | } |
| ... | ... | @@ -967,8 +1034,8 @@ static int pcnet_tdte_poll(PCNetState *s) |
| 967 | 1034 | |
| 968 | 1035 | TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s))); |
| 969 | 1036 | |
| 970 | - CSR_CXBC(s) = tmd.tmd1.bcnt; | |
| 971 | - CSR_CXST(s) = ((uint32_t *)&tmd)[1] >> 16; | |
| 1037 | + CSR_CXBC(s) = GET_FIELD(tmd.length, TMDL, BCNT); | |
| 1038 | + CSR_CXST(s) = tmd.status; | |
| 972 | 1039 | } else { |
| 973 | 1040 | CSR_CXBC(s) = CSR_CXST(s) = 0; |
| 974 | 1041 | } |
| ... | ... | @@ -1029,7 +1096,7 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size) |
| 1029 | 1096 | (CSR_RCVRL(s) - rcvrc) * |
| 1030 | 1097 | (BCR_SWSTYLE(s) ? 16 : 8 ); |
| 1031 | 1098 | RMDLOAD(&rmd, PHYSADDR(s,nrda)); |
| 1032 | - if (rmd.rmd1.own) { | |
| 1099 | + if (GET_FIELD(rmd.status, RMDS, OWN)) { | |
| 1033 | 1100 | #ifdef PCNET_DEBUG_RMD |
| 1034 | 1101 | printf("pcnet - scan buffer: RCVRC=%d PREV_RCVRC=%d\n", |
| 1035 | 1102 | rcvrc, CSR_RCVRC(s)); |
| ... | ... | @@ -1086,14 +1153,15 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size) |
| 1086 | 1153 | |
| 1087 | 1154 | RMDLOAD(&rmd, PHYSADDR(s,crda)); |
| 1088 | 1155 | /*if (!CSR_LAPPEN(s))*/ |
| 1089 | - rmd.rmd1.stp = 1; | |
| 1156 | + SET_FIELD(&rmd.status, RMDS, STP, 1); | |
| 1090 | 1157 | |
| 1091 | 1158 | #define PCNET_RECV_STORE() do { \ |
| 1092 | - int count = MIN(4096 - rmd.rmd1.bcnt,size); \ | |
| 1093 | - target_phys_addr_t rbadr = PHYSADDR(s, rmd.rmd0.rbadr); \ | |
| 1094 | - s->phys_mem_write(s->dma_opaque, rbadr, src, count, CSR_BSWP(s)); \ | |
| 1159 | + int count = MIN(4096 - GET_FIELD(rmd.buf_length, RMDL, BCNT),size); \ | |
| 1160 | + target_phys_addr_t rbadr = PHYSADDR(s, rmd.rbadr); \ | |
| 1161 | + s->phys_mem_write(s->dma_opaque, rbadr, src, count, CSR_BSWP(s)); \ | |
| 1095 | 1162 | src += count; size -= count; \ |
| 1096 | - rmd.rmd2.mcnt = count; rmd.rmd1.own = 0; \ | |
| 1163 | + SET_FIELD(&rmd.msg_length, RMDM, MCNT, count); \ | |
| 1164 | + SET_FIELD(&rmd.status, RMDS, OWN, 0); \ | |
| 1097 | 1165 | RMDSTORE(&rmd, PHYSADDR(s,crda)); \ |
| 1098 | 1166 | pktcount++; \ |
| 1099 | 1167 | } while (0) |
| ... | ... | @@ -1102,12 +1170,12 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size) |
| 1102 | 1170 | if ((size > 0) && CSR_NRDA(s)) { |
| 1103 | 1171 | target_phys_addr_t nrda = CSR_NRDA(s); |
| 1104 | 1172 | RMDLOAD(&rmd, PHYSADDR(s,nrda)); |
| 1105 | - if (rmd.rmd1.own) { | |
| 1173 | + if (GET_FIELD(rmd.status, RMDS, OWN)) { | |
| 1106 | 1174 | crda = nrda; |
| 1107 | 1175 | PCNET_RECV_STORE(); |
| 1108 | 1176 | if ((size > 0) && (nrda=CSR_NNRD(s))) { |
| 1109 | 1177 | RMDLOAD(&rmd, PHYSADDR(s,nrda)); |
| 1110 | - if (rmd.rmd1.own) { | |
| 1178 | + if (GET_FIELD(rmd.status, RMDS, OWN)) { | |
| 1111 | 1179 | crda = nrda; |
| 1112 | 1180 | PCNET_RECV_STORE(); |
| 1113 | 1181 | } |
| ... | ... | @@ -1119,14 +1187,14 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size) |
| 1119 | 1187 | |
| 1120 | 1188 | RMDLOAD(&rmd, PHYSADDR(s,crda)); |
| 1121 | 1189 | if (size == 0) { |
| 1122 | - rmd.rmd1.enp = 1; | |
| 1123 | - rmd.rmd1.pam = !CSR_PROM(s) && is_padr; | |
| 1124 | - rmd.rmd1.lafm = !CSR_PROM(s) && is_ladr; | |
| 1125 | - rmd.rmd1.bam = !CSR_PROM(s) && is_bcast; | |
| 1190 | + SET_FIELD(&rmd.status, RMDS, ENP, 1); | |
| 1191 | + SET_FIELD(&rmd.status, RMDS, PAM, !CSR_PROM(s) && is_padr); | |
| 1192 | + SET_FIELD(&rmd.status, RMDS, LFAM, !CSR_PROM(s) && is_ladr); | |
| 1193 | + SET_FIELD(&rmd.status, RMDS, BAM, !CSR_PROM(s) && is_bcast); | |
| 1126 | 1194 | } else { |
| 1127 | - rmd.rmd1.oflo = 1; | |
| 1128 | - rmd.rmd1.buff = 1; | |
| 1129 | - rmd.rmd1.err = 1; | |
| 1195 | + SET_FIELD(&rmd.status, RMDS, OFLO, 1); | |
| 1196 | + SET_FIELD(&rmd.status, RMDS, BUFF, 1); | |
| 1197 | + SET_FIELD(&rmd.status, RMDS, ERR, 1); | |
| 1130 | 1198 | } |
| 1131 | 1199 | RMDSTORE(&rmd, PHYSADDR(s,crda)); |
| 1132 | 1200 | s->csr[0] |= 0x0400; |
| ... | ... | @@ -1172,30 +1240,30 @@ static void pcnet_transmit(PCNetState *s) |
| 1172 | 1240 | if (pcnet_tdte_poll(s)) { |
| 1173 | 1241 | struct pcnet_TMD tmd; |
| 1174 | 1242 | |
| 1175 | - TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s))); | |
| 1243 | + TMDLOAD(&tmd, PHYSADDR(s,CSR_CXDA(s))); | |
| 1176 | 1244 | |
| 1177 | 1245 | #ifdef PCNET_DEBUG_TMD |
| 1178 | 1246 | printf(" TMDLOAD 0x%08x\n", PHYSADDR(s,CSR_CXDA(s))); |
| 1179 | 1247 | PRINT_TMD(&tmd); |
| 1180 | 1248 | #endif |
| 1181 | - if (tmd.tmd1.stp) { | |
| 1182 | - s->xmit_pos = 0; | |
| 1183 | - if (!tmd.tmd1.enp) { | |
| 1184 | - s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tmd0.tbadr), | |
| 1185 | - s->buffer, 4096 - tmd.tmd1.bcnt, | |
| 1186 | - CSR_BSWP(s)); | |
| 1187 | - s->xmit_pos += 4096 - tmd.tmd1.bcnt; | |
| 1188 | - } | |
| 1249 | + if (GET_FIELD(tmd.status, TMDS, STP)) { | |
| 1250 | + s->xmit_pos = 0; | |
| 1251 | + if (!GET_FIELD(tmd.status, TMDS, ENP)) { | |
| 1252 | + int bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT); | |
| 1253 | + s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), | |
| 1254 | + s->buffer, bcnt, CSR_BSWP(s)); | |
| 1255 | + s->xmit_pos += bcnt; | |
| 1256 | + } | |
| 1189 | 1257 | xmit_cxda = PHYSADDR(s,CSR_CXDA(s)); |
| 1190 | 1258 | } |
| 1191 | - if (tmd.tmd1.enp && (s->xmit_pos >= 0)) { | |
| 1192 | - s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tmd0.tbadr), | |
| 1193 | - s->buffer + s->xmit_pos, 4096 - tmd.tmd1.bcnt, | |
| 1194 | - CSR_BSWP(s)); | |
| 1195 | - s->xmit_pos += 4096 - tmd.tmd1.bcnt; | |
| 1259 | + if (GET_FIELD(tmd.status, TMDS, ENP) && (s->xmit_pos >= 0)) { | |
| 1260 | + int bcnt = 4096 - GET_FIELD(tmd.length, TMDL, BCNT); | |
| 1261 | + s->phys_mem_read(s->dma_opaque, PHYSADDR(s, tmd.tbadr), | |
| 1262 | + s->buffer + s->xmit_pos, bcnt, CSR_BSWP(s)); | |
| 1263 | + s->xmit_pos += bcnt; | |
| 1196 | 1264 | #ifdef PCNET_DEBUG |
| 1197 | 1265 | printf("pcnet_transmit size=%d\n", s->xmit_pos); |
| 1198 | -#endif | |
| 1266 | +#endif | |
| 1199 | 1267 | if (CSR_LOOP(s)) |
| 1200 | 1268 | pcnet_receive(s, s->buffer, s->xmit_pos); |
| 1201 | 1269 | else |
| ... | ... | @@ -1206,9 +1274,9 @@ static void pcnet_transmit(PCNetState *s) |
| 1206 | 1274 | s->xmit_pos = -1; |
| 1207 | 1275 | } |
| 1208 | 1276 | |
| 1209 | - tmd.tmd1.own = 0; | |
| 1277 | + SET_FIELD(&tmd.status, TMDS, OWN, 0); | |
| 1210 | 1278 | TMDSTORE(&tmd, PHYSADDR(s,CSR_CXDA(s))); |
| 1211 | - if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && tmd.tmd1.ltint)) | |
| 1279 | + if (!CSR_TOKINTD(s) || (CSR_LTINTEN(s) && GET_FIELD(tmd.status, TMDS, LTINT))) | |
| 1212 | 1280 | s->csr[0] |= 0x0200; /* set TINT */ |
| 1213 | 1281 | |
| 1214 | 1282 | if (CSR_XMTRC(s)<=1) |
| ... | ... | @@ -1221,9 +1289,11 @@ static void pcnet_transmit(PCNetState *s) |
| 1221 | 1289 | } else |
| 1222 | 1290 | if (s->xmit_pos >= 0) { |
| 1223 | 1291 | struct pcnet_TMD tmd; |
| 1224 | - TMDLOAD(&tmd, PHYSADDR(s,xmit_cxda)); | |
| 1225 | - tmd.tmd2.buff = tmd.tmd2.uflo = tmd.tmd1.err = 1; | |
| 1226 | - tmd.tmd1.own = 0; | |
| 1292 | + TMDLOAD(&tmd, PHYSADDR(s,xmit_cxda)); | |
| 1293 | + SET_FIELD(&tmd.misc, TMDM, BUFF, 1); | |
| 1294 | + SET_FIELD(&tmd.misc, TMDM, UFLO, 1); | |
| 1295 | + SET_FIELD(&tmd.status, TMDS, ERR, 1); | |
| 1296 | + SET_FIELD(&tmd.status, TMDS, OWN, 0); | |
| 1227 | 1297 | TMDSTORE(&tmd, PHYSADDR(s,xmit_cxda)); |
| 1228 | 1298 | s->csr[0] |= 0x0200; /* set TINT */ |
| 1229 | 1299 | if (!CSR_DXSUFLO(s)) { | ... | ... |