Changeset 0777f4c5 in mainline
- Timestamp:
- 2011-01-06T15:41:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6fc0edd
- Parents:
- 74864ac
- Location:
- uspace/srv/hw/netif/dp8390
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
r74864ac r0777f4c5 478 478 } 479 479 480 /*===========================================================================* 481 * dp_check_ints * 482 *===========================================================================*/ 483 void dp_check_ints(dep, isr) 484 dpeth_t *dep; 485 int isr; 486 { 487 int /*isr,*/ tsr; 480 void dp_check_ints(dpeth_t *dep) 481 { 482 int isr, tsr; 488 483 int size, sendq_tail; 489 490 if (!(dep->de_flags & DEF_ENABLED))484 485 if (!(dep->de_flags & DEF_ENABLED)) 491 486 fprintf(stderr, "dp8390: got premature interrupt\n"); 492 493 for(;;) 494 { 495 // isr = inb_reg0(dep, DP_ISR); 487 488 for (;;) { 489 isr = inb_reg0(dep, DP_ISR); 496 490 if (!isr) 497 491 break; 492 498 493 outb_reg0(dep, DP_ISR, isr); 499 if (isr &(ISR_PTX|ISR_TXE)) 500 { 501 if (isr &ISR_TXE) 502 { 494 495 if (isr & (ISR_PTX | ISR_TXE)) { 496 if (isr & ISR_TXE) 503 497 dep->de_stat.ets_sendErr++; 498 else { 499 tsr = inb_reg0(dep, DP_TSR); 500 501 if (tsr & TSR_PTX) 502 dep->de_stat.ets_packetT++; 503 504 if (tsr & TSR_COL) 505 dep->de_stat.ets_collision++; 506 507 if (tsr & TSR_ABT) 508 dep->de_stat.ets_transAb++; 509 510 if (tsr & TSR_CRS) 511 dep->de_stat.ets_carrSense++; 512 513 if ((tsr & TSR_FU) && (++dep->de_stat.ets_fifoUnder <= 10)) 514 printf("%s: fifo underrun\n", dep->de_name); 515 516 if ((tsr & TSR_CDH) && (++dep->de_stat.ets_CDheartbeat <= 10)) 517 printf("%s: CD heart beat failure\n", dep->de_name); 518 519 if (tsr & TSR_OWC) 520 dep->de_stat.ets_OWC++; 504 521 } 505 else 506 { 507 tsr = inb_reg0(dep, DP_TSR); 508 509 if (tsr &TSR_PTX) dep->de_stat.ets_packetT++; 510 #if 0 /* Reserved in later manuals, should be ignored */ 511 if (!(tsr &TSR_DFR)) 512 { 513 /* In most (all?) implementations of 514 * the dp8390, this bit is set 515 * when the packet is not deferred 516 */ 517 dep->de_stat.ets_transDef++; 518 } 519 #endif 520 if (tsr &TSR_COL) dep->de_stat.ets_collision++; 521 if (tsr &TSR_ABT) dep->de_stat.ets_transAb++; 522 if (tsr &TSR_CRS) dep->de_stat.ets_carrSense++; 523 if (tsr &TSR_FU 524 && ++dep->de_stat.ets_fifoUnder <= 10) 525 { 526 printf("%s: fifo underrun\n", 527 dep->de_name); 528 } 529 if (tsr &TSR_CDH 530 && ++dep->de_stat.ets_CDheartbeat <= 10) 531 { 532 printf("%s: CD heart beat failure\n", 533 dep->de_name); 534 } 535 if (tsr &TSR_OWC) dep->de_stat.ets_OWC++; 536 } 537 sendq_tail= dep->de_sendq_tail; 538 539 if (!(dep->de_sendq[sendq_tail].sq_filled)) 540 { 522 523 sendq_tail = dep->de_sendq_tail; 524 525 if (!(dep->de_sendq[sendq_tail].sq_filled)) { 541 526 /* Software bug? */ 542 527 assert(false); 543 528 544 529 /* Or hardware bug? */ 545 printf( 546 "%s: transmit interrupt, but not sending\n", 547 dep->de_name); 530 printf("%s: transmit interrupt, but not sending\n", dep->de_name); 548 531 continue; 549 532 } 550 dep->de_sendq[sendq_tail].sq_filled= 0; 533 534 dep->de_sendq[sendq_tail].sq_filled = 0; 535 551 536 if (++sendq_tail == dep->de_sendq_nr) 552 sendq_tail= 0; 553 dep->de_sendq_tail= sendq_tail; 554 if (dep->de_sendq[sendq_tail].sq_filled) 555 { 556 size= dep->de_sendq[sendq_tail].sq_size; 537 sendq_tail = 0; 538 539 dep->de_sendq_tail = sendq_tail; 540 541 if (dep->de_sendq[sendq_tail].sq_filled) { 542 size = dep->de_sendq[sendq_tail].sq_size; 557 543 outb_reg0(dep, DP_TPSR, 558 544 dep->de_sendq[sendq_tail].sq_sendpage); 559 545 outb_reg0(dep, DP_TBCR1, size >> 8); 560 outb_reg0(dep, DP_TBCR0, size & 0xff);546 outb_reg0(dep, DP_TBCR0, size & 0xff); 561 547 outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA); 562 548 } 549 563 550 // if (dep->de_flags &DEF_SEND_AVAIL) 564 551 dp_send(dep); 565 552 } 566 567 if (isr &ISR_PRX) 568 { 553 554 if (isr & ISR_PRX) { 569 555 /* Only call dp_recv if there is a read request */ 570 556 // if (dep->de_flags) &DEF_READING) … … 572 558 } 573 559 574 if (isr &ISR_RXE) dep->de_stat.ets_recvErr++; 575 if (isr &ISR_CNT) 576 { 560 if (isr & ISR_RXE) 561 dep->de_stat.ets_recvErr++; 562 563 if (isr & ISR_CNT) { 577 564 dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0); 578 565 dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1); 579 566 dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2); 580 567 } 581 if (isr &ISR_OVW)582 {568 569 if (isr & ISR_OVW) { 583 570 dep->de_stat.ets_OVW++; 584 #if 0 585 {printW(); printf( 586 "%s: got overwrite warning\n", dep->de_name);} 587 #endif 588 /* if (dep->de_flags &DEF_READING) 589 { 590 printf( 591 "dp_check_ints: strange: overwrite warning and pending read request\n"); 571 /* if (dep->de_flags & DEF_READING) { 572 printf("dp_check_ints: strange: overwrite warning and pending read request\n"); 592 573 dp_recv(dep); 593 574 } 594 575 */ } 595 if (isr &ISR_RDC)596 {576 577 if (isr & ISR_RDC) { 597 578 /* Nothing to do */ 598 579 } 599 if (isr &ISR_RST) 600 { 601 /* this means we got an interrupt but the ethernet 580 581 if (isr & ISR_RST) { 582 /* 583 * This means we got an interrupt but the ethernet 602 584 * chip is shutdown. We set the flag DEF_STOPPED, 603 585 * and continue processing arrived packets. When the 604 586 * receive buffer is empty, we reset the dp8390. 605 587 */ 606 #if 0607 {printW(); printf(608 "%s: NIC stopped\n", dep->de_name);}609 #endif610 588 dep->de_flags |= DEF_STOPPED; 611 589 break; 612 590 } 613 isr = inb_reg0(dep, DP_ISR); 614 } 615 // if ((dep->de_flags &(DEF_READING|DEF_STOPPED)) == 616 // (DEF_READING|DEF_STOPPED)) 617 if ((dep->de_flags &DEF_STOPPED) == DEF_STOPPED) 618 { 619 /* The chip is stopped, and all arrived packets are 620 * delivered. 591 } 592 593 // if ((dep->de_flags & (DEF_READING | DEF_STOPPED)) == (DEF_READING | DEF_STOPPED)) 594 if ((dep->de_flags & DEF_STOPPED) == DEF_STOPPED) { 595 /* 596 * The chip is stopped, and all arrived packets 597 * are delivered. 621 598 */ 622 599 dp_reset(dep); -
uspace/srv/hw/netif/dp8390/dp8390_drv.h
r74864ac r0777f4c5 55 55 /** Processes the interrupt. 56 56 * @param[in,out] dep The network interface structure. 57 * @param[in] isr The interrupt status register.58 57 */ 59 void dp_check_ints(dpeth_t *dep , int isr);58 void dp_check_ints(dpeth_t *dep); 60 59 61 60 /** Probes and initializes the network interface. -
uspace/srv/hw/netif/dp8390/dp8390_module.c
r74864ac r0777f4c5 61 61 * @param[in] call The interrupt call. 62 62 */ 63 #define IRQ_GET_DEVICE(call) (device_id_t) IPC_GET_IMETHOD(*call) 64 65 /** Returns the interrupt status register from the interrupt call. 66 * @param[in] call The interrupt call. 67 */ 68 #define IPC_GET_ISR(call) (int) IPC_GET_ARG2(*call) 63 #define IRQ_GET_DEVICE(call) (device_id_t) IPC_GET_IMETHOD(*call) 69 64 70 65 /** DP8390 kernel interrupt command sequence. 71 66 */ 72 static irq_cmd_t dp8390_cmds[] = { 73 { .cmd = CMD_PIO_READ_8, 67 static irq_cmd_t dp8390_cmds[] = { 68 { 69 .cmd = CMD_PIO_READ_8, 74 70 .addr = NULL, 75 71 .dstarg = 2 … … 87 83 /** DP8390 kernel interrupt code. 88 84 */ 89 static irq_code_t 85 static irq_code_t dp8390_code = { 90 86 sizeof(dp8390_cmds) / sizeof(irq_cmd_t), 91 87 dp8390_cmds … … 97 93 * @param[in] call The interrupt message. 98 94 */ 99 static void irq_handler(ipc_callid_t iid, ipc_call_t * 100 { 101 netif_device_t * 102 dpeth_t * 95 static void irq_handler(ipc_callid_t iid, ipc_call_t *call) 96 { 97 netif_device_t *device; 98 dpeth_t *dep; 103 99 packet_t *received; 104 100 device_id_t device_id; 105 101 int phone; 106 102 107 103 device_id = IRQ_GET_DEVICE(call); 108 104 fibril_rwlock_write_lock(&netif_globals.lock); 109 if(find_device(device_id, &device) != EOK){ 105 106 if (find_device(device_id, &device) != EOK) { 110 107 fibril_rwlock_write_unlock(&netif_globals.lock); 111 108 return; 112 109 } 110 113 111 dep = (dpeth_t *) device->specific; 114 if (dep->de_mode != DEM_ENABLED) {112 if (dep->de_mode != DEM_ENABLED) { 115 113 fibril_rwlock_write_unlock(&netif_globals.lock); 116 114 return; 117 115 } 118 assert(dep->de_flags &DEF_ENABLED); 116 117 assert(dep->de_flags & DEF_ENABLED); 118 119 119 dep->de_int_pending = 0; 120 dp_check_ints(dep, IPC_GET_ISR(call)); 121 if(dep->received_queue){ 120 dp_check_ints(dep); 121 122 if (dep->received_queue) { 122 123 received = dep->received_queue; 123 124 phone = device->nil_phone; … … 126 127 fibril_rwlock_write_unlock(&netif_globals.lock); 127 128 nil_received_msg(phone, device_id, received, SERVICE_NONE); 128 } else{129 } else 129 130 fibril_rwlock_write_unlock(&netif_globals.lock); 130 }131 131 } 132 132 … … 136 136 * @returns The new state. 137 137 */ 138 static int change_state(netif_device_t * 138 static int change_state(netif_device_t *device, device_state_t state) 139 139 { 140 140 if (device->state != state) { … … 150 150 } 151 151 152 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){ 152 int netif_specific_message(ipc_callid_t callid, ipc_call_t *call, 153 ipc_call_t *answer, int *answer_count) 154 { 153 155 return ENOTSUP; 154 156 } … … 159 161 eth_stat_t * de_stat; 160 162 int rc; 161 162 if (! stats){163 164 if (!stats) 163 165 return EBADMEM; 164 }166 165 167 rc = find_device(device_id, &device); 166 168 if (rc != EOK) 167 169 return rc; 170 168 171 de_stat = &((dpeth_t *) device->specific)->de_stat; 172 169 173 null_device_stats(stats); 170 174 stats->receive_errors = de_stat->ets_recvErr; … … 180 184 stats->send_heartbeat_errors = de_stat->ets_CDheartbeat; 181 185 stats->send_window_errors = de_stat->ets_OWC; 182 return EOK; 183 } 184 185 int netif_get_addr_message(device_id_t device_id, measured_string_t *address){ 186 netif_device_t * device; 187 int rc; 188 189 if(! address){ 186 187 return EOK; 188 } 189 190 int netif_get_addr_message(device_id_t device_id, measured_string_t *address) 191 { 192 netif_device_t *device; 193 int rc; 194 195 if (!address) 190 196 return EBADMEM; 191 }197 192 198 rc = find_device(device_id, &device); 193 199 if (rc != EOK) 194 200 return rc; 201 195 202 address->value = (char *) (&((dpeth_t *) device->specific)->de_address); 196 203 address->length = sizeof(ether_addr_t); … … 198 205 } 199 206 200 201 202 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){ 203 netif_device_t * device; 204 dpeth_t * dep; 205 int rc; 206 207 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io) 208 { 209 netif_device_t *device; 210 dpeth_t *dep; 211 int rc; 212 207 213 device = (netif_device_t *) malloc(sizeof(netif_device_t)); 208 if (! device){214 if (!device) 209 215 return ENOMEM; 210 }216 211 217 dep = (dpeth_t *) malloc(sizeof(dpeth_t)); 212 if (! dep){218 if (!dep) { 213 219 free(device); 214 220 return ENOMEM; 215 221 } 222 216 223 bzero(device, sizeof(netif_device_t)); 217 224 bzero(dep, sizeof(dpeth_t)); … … 222 229 dep->de_irq = irq; 223 230 dep->de_mode = DEM_DISABLED; 231 224 232 //TODO address? 225 233 rc = pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port); … … 228 236 free(device); 229 237 return rc; 230 } 238 } 239 231 240 rc = do_probe(dep); 232 241 if (rc != EOK) { … … 235 244 return rc; 236 245 } 246 237 247 rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device); 238 if (rc != EOK) {248 if (rc != EOK) { 239 249 free(dep); 240 250 free(device); 241 251 return rc; 242 252 } 243 return EOK; 244 } 245 246 int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender){ 247 netif_device_t * device; 248 dpeth_t * dep; 253 254 return EOK; 255 } 256 257 int netif_send_message(device_id_t device_id, packet_t *packet, 258 services_t sender) 259 { 260 netif_device_t *device; 261 dpeth_t *dep; 249 262 packet_t *next; 250 263 int rc; 251 264 252 265 rc = find_device(device_id, &device); 253 266 if (rc != EOK) 254 267 return rc; 255 if(device->state != NETIF_ACTIVE){ 268 269 if (device->state != NETIF_ACTIVE){ 256 270 netif_pq_release(packet_get_id(packet)); 257 271 return EFORWARD; 258 272 } 273 259 274 dep = (dpeth_t *) device->specific; 260 // process packet queue 261 do{ 275 276 /* Process packet queue */ 277 do { 262 278 next = pq_detach(packet); 263 if(do_pwrite(dep, packet, false) != EBUSY){ 264 netif_pq_release(packet_get_id(packet)); 265 } 279 280 if (do_pwrite(dep, packet, false) != EBUSY) 281 netif_pq_release(packet_get_id(packet));\ 282 266 283 packet = next; 267 }while(packet); 268 return EOK; 269 } 270 271 int netif_start_message(netif_device_t * device){ 272 dpeth_t * dep; 273 int rc; 274 275 if(device->state != NETIF_ACTIVE){ 284 } while(packet); 285 286 return EOK; 287 } 288 289 int netif_start_message(netif_device_t * device) 290 { 291 dpeth_t *dep; 292 int rc; 293 294 if (device->state != NETIF_ACTIVE) { 276 295 dep = (dpeth_t *) device->specific; 277 296 dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR); 278 297 dp8390_cmds[2].addr = dp8390_cmds[0].addr; 298 279 299 rc = ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code); 280 300 if (rc != EOK) 281 301 return rc; 302 282 303 rc = do_init(dep, DL_BROAD_REQ); 283 304 if (rc != EOK) { … … 285 306 return rc; 286 307 } 308 287 309 return change_state(device, NETIF_ACTIVE); 288 310 } 289 return EOK; 290 } 291 292 int netif_stop_message(netif_device_t * device){ 293 dpeth_t * dep; 294 295 if(device->state != NETIF_STOPPED){ 311 312 return EOK; 313 } 314 315 int netif_stop_message(netif_device_t * device) 316 { 317 dpeth_t *dep; 318 319 if (device->state != NETIF_STOPPED) { 296 320 dep = (dpeth_t *) device->specific; 297 321 do_stop(dep); … … 299 323 return change_state(device, NETIF_STOPPED); 300 324 } 301 return EOK; 302 } 303 304 int netif_initialize(void){ 325 326 return EOK; 327 } 328 329 int netif_initialize(void) 330 { 305 331 sysarg_t phonehash; 306 307 332 async_set_interrupt_received(irq_handler); 308 309 333 return ipc_connect_to_me(PHONE_NS, SERVICE_DP8390, 0, 0, &phonehash); 310 334 } … … 316 340 * 317 341 */ 318 static void netif_client_connection(ipc_callid_t iid, ipc_call_t * 342 static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall) 319 343 { 320 344 /* … … 324 348 ipc_answer_0(iid, EOK); 325 349 326 while (true) {350 while (true) { 327 351 ipc_call_t answer; 328 352 int answer_count; … … 348 372 } 349 373 350 /** Start sthe module.374 /** Start the module. 351 375 * 352 376 * @param argc The count of the command line arguments. Ignored parameter. … … 359 383 int main(int argc, char *argv[]) 360 384 { 361 int rc;362 363 385 /* Start the module */ 364 rc = netif_module_start(netif_client_connection); 365 return rc; 386 return netif_module_start(netif_client_connection); 366 387 } 367 388
Note:
See TracChangeset
for help on using the changeset viewer.