Changeset 7922dea in mainline for uspace/srv/hw/netif/dp8390/dp8390.c
- Timestamp:
- 2011-01-06T23:46:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3d5e190
- Parents:
- 66b628a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
r66b628a r7922dea 87 87 static void dp_reset(dpeth_t *dep); 88 88 static void dp_recv(int nil_phone, device_id_t device_id, dpeth_t *dep); 89 static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst);90 static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst);91 89 static int dp_pkt2user(int nil_phone, device_id_t device_id, dpeth_t *dep, int page, int length); 92 static void dp_pio8_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size);93 static void dp_pio16_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size);94 static void dp_pio8_nic2user(dpeth_t *dep, int nic_addr, void *buf, size_t offset, size_t size);95 static void dp_pio16_nic2user(dpeth_t *dep, int nic_addr, void *buf, size_t offset, size_t size);96 90 static void conf_hw(dpeth_t *dep); 97 91 static void insb(port_t port, void *buf, size_t size); … … 137 131 if ((dep->up) && (dep->enabled)) { 138 132 outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT); 139 (dep->de_stopf)(dep); 133 ne_stop(dep); 134 140 135 dep->enabled = false; 141 136 dep->stopped = false; … … 143 138 dep->send_avail = false; 144 139 } 140 } 141 142 static void dp_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size) 143 { 144 size_t ecount = size & ~1; 145 146 outb_reg0(dep, DP_ISR, ISR_RDC); 147 148 if (dep->de_16bit) { 149 outb_reg0(dep, DP_RBCR0, ecount & 0xff); 150 outb_reg0(dep, DP_RBCR1, ecount >> 8); 151 } else { 152 outb_reg0(dep, DP_RBCR0, size & 0xff); 153 outb_reg0(dep, DP_RBCR1, size >> 8); 154 } 155 156 outb_reg0(dep, DP_RSAR0, nic_addr & 0xff); 157 outb_reg0(dep, DP_RSAR1, nic_addr >> 8); 158 outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); 159 160 if (dep->de_16bit) { 161 void *ptr = buf + offset; 162 163 if (ecount != 0) { 164 outsw(dep->de_data_port, ptr, ecount); 165 size -= ecount; 166 offset += ecount; 167 ptr += ecount; 168 } 169 170 if (size) { 171 assert(size == 1); 172 173 uint16_t two_bytes; 174 175 memcpy(&(((uint8_t *) &two_bytes)[0]), ptr, 1); 176 outw(dep->de_data_port, two_bytes); 177 } 178 } else 179 outsb(dep->de_data_port, buf + offset, size); 180 181 unsigned int i; 182 for (i = 0; i < 100; i++) { 183 if (inb_reg0(dep, DP_ISR) & ISR_RDC) 184 break; 185 } 186 187 if (i == 100) 188 fprintf(stderr, "Remote DMA failed to complete\n"); 145 189 } 146 190 … … 178 222 } 179 223 180 (dep->de_user2nicf)(dep, buf, 0,181 dep->de_sendq[sendq_head].sq_sendpage* DP_PAGESIZE, size);224 dp_user2nic(dep, buf, 0, dep->de_sendq[sendq_head].sq_sendpage 225 * DP_PAGESIZE, size); 182 226 dep->de_sendq[sendq_head].sq_filled = true; 183 227 … … 215 259 dep->sending = false; 216 260 dep->send_avail = false; 217 (*dep->de_initf)(dep);261 ne_init(dep); 218 262 219 263 printf("Ethernet address "); … … 298 342 dep->de_sendq_head = 0; 299 343 dep->de_sendq_tail = 0; 300 301 if (dep->de_16bit) {302 dep->de_user2nicf= dp_pio16_user2nic;303 dep->de_nic2userf= dp_pio16_nic2user;304 dep->de_getblockf= dp_pio16_getblock;305 } else {306 dep->de_user2nicf= dp_pio8_user2nic;307 dep->de_nic2userf= dp_pio8_nic2user;308 dep->de_getblockf= dp_pio8_getblock;309 }310 344 } 311 345 … … 470 504 } 471 505 506 static void dp_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 507 { 508 offset = page * DP_PAGESIZE + offset; 509 510 outb_reg0(dep, DP_RBCR0, size & 0xff); 511 outb_reg0(dep, DP_RBCR1, size >> 8); 512 outb_reg0(dep, DP_RSAR0, offset & 0xff); 513 outb_reg0(dep, DP_RSAR1, offset >> 8); 514 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 515 516 if (dep->de_16bit) { 517 assert((size % 2) == 0); 518 insw(dep->de_data_port, dst, size); 519 } else 520 insb(dep->de_data_port, dst, size); 521 } 522 472 523 static void dp_recv(int nil_phone, device_id_t device_id, dpeth_t *dep) 473 524 { … … 491 542 break; 492 543 493 (dep->de_getblockf)(dep, pageno, (size_t) 0, sizeof(header), &header); 494 (dep->de_getblockf)(dep, pageno, sizeof(header) + 2 * sizeof(ether_addr_t), sizeof(eth_type), ð_type); 544 dp_getblock(dep, pageno, (size_t) 0, sizeof(header), &header); 545 dp_getblock(dep, pageno, sizeof(header) + 546 2 * sizeof(ether_addr_t), sizeof(eth_type), ð_type); 495 547 496 548 length = (header.dr_rbcl | (header.dr_rbch << 8)) - sizeof(dp_rcvhdr_t); … … 528 580 } 529 581 530 static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 531 { 532 offset = page * DP_PAGESIZE + offset; 533 outb_reg0(dep, DP_RBCR0, size &0xFF); 534 outb_reg0(dep, DP_RBCR1, size >> 8); 535 outb_reg0(dep, DP_RSAR0, offset &0xFF); 536 outb_reg0(dep, DP_RSAR1, offset >> 8); 582 static void dp_nic2user(dpeth_t *dep, int nic_addr, void *buf, size_t offset, size_t size) 583 { 584 size_t ecount = size & ~1; 585 586 if (dep->de_16bit) { 587 outb_reg0(dep, DP_RBCR0, ecount & 0xFF); 588 outb_reg0(dep, DP_RBCR1, ecount >> 8); 589 } else { 590 outb_reg0(dep, DP_RBCR0, size & 0xff); 591 outb_reg0(dep, DP_RBCR1, size >> 8); 592 } 593 594 outb_reg0(dep, DP_RSAR0, nic_addr & 0xff); 595 outb_reg0(dep, DP_RSAR1, nic_addr >> 8); 537 596 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 538 597 539 insb(dep->de_data_port, dst, size); 540 } 541 542 static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 543 { 544 offset = page * DP_PAGESIZE + offset; 545 outb_reg0(dep, DP_RBCR0, size &0xFF); 546 outb_reg0(dep, DP_RBCR1, size >> 8); 547 outb_reg0(dep, DP_RSAR0, offset &0xFF); 548 outb_reg0(dep, DP_RSAR1, offset >> 8); 549 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 550 551 assert(!(size & 1)); 552 553 insw(dep->de_data_port, dst, size); 598 if (dep->de_16bit) { 599 void *ptr = buf + offset; 600 601 if (ecount != 0) { 602 insw(dep->de_data_port, ptr, ecount); 603 size -= ecount; 604 offset += ecount; 605 ptr += ecount; 606 } 607 608 if (size) { 609 assert(size == 1); 610 611 uint16_t two_bytes = inw(dep->de_data_port); 612 memcpy(ptr, &(((uint8_t *) &two_bytes)[0]), 1); 613 } 614 } else 615 insb(dep->de_data_port, buf + offset, size); 554 616 } 555 617 … … 569 631 count = (dep->de_stoppage - page) * DP_PAGESIZE - sizeof(dp_rcvhdr_t); 570 632 571 (dep->de_nic2userf)(dep, page * DP_PAGESIZE +572 sizeof(dp_rcvhdr_t),buf, 0, count);573 (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE,633 dp_nic2user(dep, page * DP_PAGESIZE + sizeof(dp_rcvhdr_t), 634 buf, 0, count); 635 dp_nic2user(dep, dep->de_startpage * DP_PAGESIZE, 574 636 buf, count, length - count); 575 637 } else { 576 (dep->de_nic2userf)(dep, page * DP_PAGESIZE +577 sizeof(dp_rcvhdr_t),buf, 0, length);638 dp_nic2user(dep, page * DP_PAGESIZE + sizeof(dp_rcvhdr_t), 639 buf, 0, length); 578 640 } 579 641 … … 581 643 582 644 return EOK; 583 }584 585 static void dp_pio8_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size)586 {587 outb_reg0(dep, DP_ISR, ISR_RDC);588 589 outb_reg0(dep, DP_RBCR0, size & 0xFF);590 outb_reg0(dep, DP_RBCR1, size >> 8);591 outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);592 outb_reg0(dep, DP_RSAR1, nic_addr >> 8);593 outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);594 595 outsb(dep->de_data_port, buf + offset, size);596 597 unsigned int i;598 for (i = 0; i < 100; i++) {599 if (inb_reg0(dep, DP_ISR) & ISR_RDC)600 break;601 }602 603 if (i == 100)604 fprintf(stderr, "dp8390: remote DMA failed to complete\n");605 }606 607 static void dp_pio16_user2nic(dpeth_t *dep, void *buf, size_t offset, int nic_addr, size_t size)608 {609 void *vir_user;610 size_t ecount;611 uint16_t two_bytes;612 613 ecount = size & ~1;614 615 outb_reg0(dep, DP_ISR, ISR_RDC);616 outb_reg0(dep, DP_RBCR0, ecount & 0xFF);617 outb_reg0(dep, DP_RBCR1, ecount >> 8);618 outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);619 outb_reg0(dep, DP_RSAR1, nic_addr >> 8);620 outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);621 622 vir_user = buf + offset;623 if (ecount != 0) {624 outsw(dep->de_data_port, vir_user, ecount);625 size -= ecount;626 offset += ecount;627 vir_user += ecount;628 }629 630 if (size) {631 assert(size == 1);632 633 memcpy(&(((uint8_t *) &two_bytes)[0]), vir_user, 1);634 outw(dep->de_data_port, two_bytes);635 }636 637 unsigned int i;638 for (i = 0; i < 100; i++) {639 if (inb_reg0(dep, DP_ISR) & ISR_RDC)640 break;641 }642 643 if (i == 100)644 fprintf(stderr, "dp8390: remote dma failed to complete\n");645 }646 647 static void dp_pio8_nic2user(dpeth_t *dep, int nic_addr, void *buf, size_t offset, size_t size)648 {649 outb_reg0(dep, DP_RBCR0, size & 0xFF);650 outb_reg0(dep, DP_RBCR1, size >> 8);651 outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);652 outb_reg0(dep, DP_RSAR1, nic_addr >> 8);653 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);654 655 insb(dep->de_data_port, buf + offset, size);656 }657 658 static void dp_pio16_nic2user(dpeth_t *dep, int nic_addr, void *buf, size_t offset, size_t size)659 {660 void *vir_user;661 size_t ecount;662 uint16_t two_bytes;663 664 ecount = size & ~1;665 666 outb_reg0(dep, DP_RBCR0, ecount & 0xFF);667 outb_reg0(dep, DP_RBCR1, ecount >> 8);668 outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);669 outb_reg0(dep, DP_RSAR1, nic_addr >> 8);670 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);671 672 vir_user = buf + offset;673 if (ecount != 0) {674 insw(dep->de_data_port, vir_user, ecount);675 size -= ecount;676 offset += ecount;677 vir_user += ecount;678 }679 680 if (size) {681 assert(size == 1);682 683 two_bytes = inw(dep->de_data_port);684 memcpy(vir_user, &(((uint8_t *) &two_bytes)[0]), 1);685 }686 645 } 687 646
Note:
See TracChangeset
for help on using the changeset viewer.