Changeset b590c21 in mainline
- Timestamp:
- 2011-01-06T16:48:33Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d3a0af7
- Parents:
- 6fc0edd
- Location:
- uspace/srv/hw/netif/dp8390
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/netif/dp8390/dp8390.c
r6fc0edd rb590c21 79 79 } 80 80 81 void dp8390_dump(dpeth_t *dep)82 {83 // dpeth_t *dep;84 int /*i,*/ isr;85 86 // printf("\n");87 // for (i= 0, dep = &de_table[0]; i<DE_PORT_NR; i++, dep++)88 // {89 #if XXX90 if (dep->de_mode == DEM_DISABLED)91 printf("dp8390 port %d is disabled\n", i);92 else if (dep->de_mode == DEM_SINK)93 printf("dp8390 port %d is in sink mode\n", i);94 #endif95 96 if (dep->de_mode != DEM_ENABLED)97 // continue;98 return;99 100 // printf("dp8390 statistics of port %d:\n", i);101 102 printf("recvErr :%8ld\t", dep->de_stat.ets_recvErr);103 printf("sendErr :%8ld\t", dep->de_stat.ets_sendErr);104 printf("OVW :%8ld\n", dep->de_stat.ets_OVW);105 106 printf("CRCerr :%8ld\t", dep->de_stat.ets_CRCerr);107 printf("frameAll :%8ld\t", dep->de_stat.ets_frameAll);108 printf("missedP :%8ld\n", dep->de_stat.ets_missedP);109 110 printf("packetR :%8ld\t", dep->de_stat.ets_packetR);111 printf("packetT :%8ld\t", dep->de_stat.ets_packetT);112 printf("transDef :%8ld\n", dep->de_stat.ets_transDef);113 114 printf("collision :%8ld\t", dep->de_stat.ets_collision);115 printf("transAb :%8ld\t", dep->de_stat.ets_transAb);116 printf("carrSense :%8ld\n", dep->de_stat.ets_carrSense);117 118 printf("fifoUnder :%8ld\t", dep->de_stat.ets_fifoUnder);119 printf("fifoOver :%8ld\t", dep->de_stat.ets_fifoOver);120 printf("CDheartbeat:%8ld\n", dep->de_stat.ets_CDheartbeat);121 122 printf("OWC :%8ld\t", dep->de_stat.ets_OWC);123 124 isr= inb_reg0(dep, DP_ISR);125 printf("dp_isr = 0x%x + 0x%x, de_flags = 0x%x\n", isr,126 inb_reg0(dep, DP_ISR), dep->de_flags);127 // }128 }129 130 81 int do_init(dpeth_t *dep, int mode) 131 82 { … … 427 378 } 428 379 429 static void dp_reinit(dep) 430 dpeth_t *dep; 380 static void dp_reinit(dpeth_t *dep) 431 381 { 432 382 int dp_rcr_reg; 433 383 434 384 outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); 435 385 436 386 dp_rcr_reg = 0; 437 if (dep->de_flags &DEF_PROMISC) 387 388 if (dep->de_flags & DEF_PROMISC) 438 389 dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; 439 if (dep->de_flags &DEF_BROAD) 390 391 if (dep->de_flags & DEF_BROAD) 440 392 dp_rcr_reg |= RCR_AB; 441 if (dep->de_flags &DEF_MULTI) 393 394 if (dep->de_flags & DEF_MULTI) 442 395 dp_rcr_reg |= RCR_AM; 396 443 397 outb_reg0(dep, DP_RCR, dp_rcr_reg); 444 398 } 445 399 446 /*===========================================================================* 447 * dp_reset * 448 *===========================================================================*/ 449 static void dp_reset(dep) 450 dpeth_t *dep; 400 static void dp_reset(dpeth_t *dep) 451 401 { 452 402 int i; 453 403 454 404 /* Stop chip */ 455 405 outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT); 456 406 outb_reg0(dep, DP_RBCR0, 0); 457 407 outb_reg0(dep, DP_RBCR1, 0); 458 for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++) 408 409 for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++) 459 410 ; /* Do nothing */ 460 outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST); 461 outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT); 411 412 outb_reg0(dep, DP_TCR, TCR_1EXTERNAL | TCR_OFST); 413 outb_reg0(dep, DP_CR, CR_STA | CR_DM_ABORT); 462 414 outb_reg0(dep, DP_TCR, TCR_NORMAL); 463 464 /* Acknowledge the ISR_RDC (remote dma) interrupt. */465 for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RDC) == 0); i++)415 416 /* Acknowledge the ISR_RDC (remote DMA) interrupt. */ 417 for (i = 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RDC) == 0); i++) 466 418 ; /* Do nothing */ 467 outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) &~ISR_RDC); 468 469 /* Reset the transmit ring. If we were transmitting a packet, we 419 420 outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) & ~ISR_RDC); 421 422 /* 423 * Reset the transmit ring. If we were transmitting a packet, we 470 424 * pretend that the packet is processed. Higher layers will 471 425 * retransmit if the packet wasn't actually sent. 472 426 */ 473 dep->de_sendq_head= dep->de_sendq_tail= 0; 474 for (i= 0; i<dep->de_sendq_nr; i++) 475 dep->de_sendq[i].sq_filled= 0; 427 dep->de_sendq_head = 0; 428 dep->de_sendq_tail = 0; 429 430 for (i = 0; i < dep->de_sendq_nr; i++) 431 dep->de_sendq[i].sq_filled = 0; 432 476 433 dp_send(dep); 477 434 dep->de_flags &= ~DEF_STOPPED; … … 602 559 int packet_processed, r; 603 560 uint16_t eth_type; 604 561 605 562 packet_processed = false; 606 563 pageno = inb_reg0(dep, DP_BNRY) + 1; 607 if (pageno == dep->de_stoppage) pageno = dep->de_startpage;608 609 do610 {564 if (pageno == dep->de_stoppage) 565 pageno = dep->de_startpage; 566 567 do { 611 568 outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA); 612 569 curr = inb_reg1(dep, DP_CURR); 613 570 outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); 614 615 if (curr == pageno) break; 616 617 (dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header), 618 &header); 619 (dep->de_getblockf)(dep, pageno, sizeof(header) + 620 2*sizeof(ether_addr_t), sizeof(eth_type), ð_type); 621 622 length = (header.dr_rbcl | (header.dr_rbch << 8)) - 623 sizeof(dp_rcvhdr_t); 571 572 if (curr == pageno) 573 break; 574 575 (dep->de_getblockf)(dep, pageno, (size_t) 0, sizeof(header), &header); 576 (dep->de_getblockf)(dep, pageno, sizeof(header) + 2 * sizeof(ether_addr_t), sizeof(eth_type), ð_type); 577 578 length = (header.dr_rbcl | (header.dr_rbch << 8)) - sizeof(dp_rcvhdr_t); 624 579 next = header.dr_next; 625 if (length < ETH_MIN_PACK_SIZE || 626 length > ETH_MAX_PACK_SIZE_TAGGED) 627 { 628 printf("%s: packet with strange length arrived: %d\n", 629 dep->de_name, (int) length); 580 if ((length < ETH_MIN_PACK_SIZE) || (length > ETH_MAX_PACK_SIZE_TAGGED)) { 581 printf("%s: packet with strange length arrived: %d\n", dep->de_name, (int) length); 630 582 next= curr; 631 } 632 else if (next < dep->de_startpage || next >= dep->de_stoppage) 633 { 583 } else if ((next < dep->de_startpage) || (next >= dep->de_stoppage)) { 634 584 printf("%s: strange next page\n", dep->de_name); 635 585 next= curr; 636 } 637 /* else if (eth_type == eth_ign_proto) 638 { 639 */ /* Hack: ignore packets of a given protocol, useful 640 * if you share a net with 80 computers sending 641 * Amoeba FLIP broadcasts. (Protocol 0x8146.) 586 } else if (header.dr_status & RSR_FO) { 587 /* 588 * This is very serious, so we issue a warning and 589 * reset the buffers 642 590 */ 643 /* static int first= 1; 644 if (first) 645 { 646 first= 0; 647 printf("%s: dropping proto 0x%04x packets\n", 648 dep->de_name, 649 ntohs(eth_ign_proto)); 650 } 651 dep->de_stat.ets_packetR++; 652 } 653 */ else if (header.dr_status &RSR_FO) 654 { 655 /* This is very serious, so we issue a warning and 656 * reset the buffers */ 657 printf("%s: fifo overrun, resetting receive buffer\n", 658 dep->de_name); 591 printf("%s: fifo overrun, resetting receive buffer\n", dep->de_name); 659 592 dep->de_stat.ets_fifoOver++; 660 593 next = curr; 661 } 662 else if ((header.dr_status &RSR_PRX) && 663 (dep->de_flags &DEF_ENABLED)) 664 { 665 // if (dep->de_safecopy_read) 666 // r = dp_pkt2user_s(dep, pageno, length); 667 // else 668 r = dp_pkt2user(dep, pageno, length); 594 } else if ((header.dr_status & RSR_PRX) && (dep->de_flags & DEF_ENABLED)) { 595 r = dp_pkt2user(dep, pageno, length); 669 596 if (r != EOK) 670 597 return; 671 598 672 599 packet_processed = true; 673 600 dep->de_stat.ets_packetR++; 674 601 } 602 675 603 if (next == dep->de_startpage) 676 604 outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1); 677 605 else 678 606 outb_reg0(dep, DP_BNRY, next - 1); 679 607 680 608 pageno = next; 681 } 682 while (!packet_processed); 683 } 684 685 /*===========================================================================* 686 * dp_send * 687 *===========================================================================*/ 688 static void dp_send(dep) 689 dpeth_t *dep; 609 } while (!packet_processed); 610 } 611 612 static void dp_send(dpeth_t *dep) 690 613 { 691 614 packet_t *packet; 692 615 693 616 // if (!(dep->de_flags &DEF_SEND_AVAIL)) 694 617 // return; 695 696 if (dep->packet_queue){618 619 if (dep->packet_queue) { 697 620 packet = dep->packet_queue; 698 621 dep->packet_queue = pq_detach(packet); 699 622 do_pwrite(dep, packet, true); 700 623 netif_pq_release(packet_get_id(packet)); 701 -- dep->packet_count; 702 } 703 // if(! dep->packet_queue){ 624 --dep->packet_count; 625 } 626 627 // if (!dep->packet_queue) 704 628 // dep->de_flags &= ~DEF_SEND_AVAIL; 705 // } 706 /* switch(dep->de_sendmsg.m_type) 707 { 708 case DL_WRITE: do_vwrite(&dep->de_sendmsg, true, false); break; 709 case DL_WRITEV: do_vwrite(&dep->de_sendmsg, true, true); break; 710 case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, true); break; 629 630 /* switch (dep->de_sendmsg.m_type) { 631 case DL_WRITE: 632 do_vwrite(&dep->de_sendmsg, true, false); 633 break; 634 case DL_WRITEV: 635 do_vwrite(&dep->de_sendmsg, true, true); 636 break; 637 case DL_WRITEV_S: 638 do_vwrite_s(&dep->de_sendmsg, true); 639 break; 711 640 default: 712 641 fprintf(stderr, "dp8390: wrong type\n"); … … 716 645 } 717 646 718 /*===========================================================================* 719 * dp_pio8_getblock * 720 *===========================================================================*/ 721 static void dp_pio8_getblock(dep, page, offset, size, dst) 722 dpeth_t *dep; 723 int page; 724 size_t offset; 725 size_t size; 726 void *dst; 647 static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 727 648 { 728 649 offset = page * DP_PAGESIZE + offset; … … 732 653 outb_reg0(dep, DP_RSAR1, offset >> 8); 733 654 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 734 655 735 656 insb(dep->de_data_port, dst, size); 736 657 } 737 658 738 /*===========================================================================* 739 * dp_pio16_getblock * 740 *===========================================================================*/ 741 static void dp_pio16_getblock(dep, page, offset, size, dst) 742 dpeth_t *dep; 743 int page; 744 size_t offset; 745 size_t size; 746 void *dst; 659 static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst) 747 660 { 748 661 offset = page * DP_PAGESIZE + offset; … … 752 665 outb_reg0(dep, DP_RSAR1, offset >> 8); 753 666 outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); 754 755 assert (!(size &1)); 667 668 assert(!(size & 1)); 669 756 670 insw(dep->de_data_port, dst, size); 757 671 } 758 672 759 /*===========================================================================* 760 * dp_pkt2user * 761 *===========================================================================*/ 762 static int dp_pkt2user(dep, page, length) 763 dpeth_t *dep; 764 int page, length; 673 static int dp_pkt2user(dpeth_t *dep, int page, int length) 765 674 { 766 675 int last, count; 767 676 packet_t *packet; 768 769 // if (!(dep->de_flags & DEF_READING))677 678 // if (!(dep->de_flags & DEF_READING)) 770 679 // return EGENERIC; 771 680 772 681 packet = netif_packet_get_1(length); 773 if (! packet){682 if (!packet) 774 683 return ENOMEM; 775 }684 776 685 dep->de_read_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_suffix(packet, length); 777 686 dep->de_read_iovec.iod_iovec[0].iov_size = length; 778 687 dep->de_read_iovec.iod_iovec_s = 1; 779 688 dep->de_read_iovec.iod_iovec_addr = (uintptr_t) NULL; 780 689 781 690 last = page + (length - 1) / DP_PAGESIZE; 782 if (last >= dep->de_stoppage) 783 { 784 count = (dep->de_stoppage - page) * DP_PAGESIZE - 785 sizeof(dp_rcvhdr_t); 786 691 if (last >= dep->de_stoppage) { 692 count = (dep->de_stoppage - page) * DP_PAGESIZE - sizeof(dp_rcvhdr_t); 693 787 694 /* Save read_iovec since we need it twice. */ 788 695 dep->de_tmp_iovec = dep->de_read_iovec; 789 696 (dep->de_nic2userf)(dep, page * DP_PAGESIZE + 790 sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count); 791 (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE, 792 &dep->de_read_iovec, count, length - count); 793 } 794 else 795 { 697 sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count); 698 (dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE, 699 &dep->de_read_iovec, count, length - count); 700 } else { 796 701 (dep->de_nic2userf)(dep, page * DP_PAGESIZE + 797 798 } 799 702 sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length); 703 } 704 800 705 dep->de_read_s = length; 801 706 dep->de_flags |= DEF_PACK_RECV; 802 707 // dep->de_flags &= ~DEF_READING; 803 804 if (dep->received_count >= MAX_PACKETS){708 709 if (dep->received_count >= MAX_PACKETS) { 805 710 netif_pq_release(packet_get_id(packet)); 806 711 return ELIMIT; 807 } else{808 if (pq_add(&dep->received_queue, packet, 0, 0) == EOK){809 ++ 810 }else{712 } else { 713 if (pq_add(&dep->received_queue, packet, 0, 0) == EOK) 714 ++dep->received_count; 715 else 811 716 netif_pq_release(packet_get_id(packet)); 812 813 }717 } 718 814 719 return EOK; 815 720 } 816 721 817 /*===========================================================================* 818 * dp_pio8_user2nic * 819 *===========================================================================*/ 820 static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count) 821 dpeth_t *dep; 822 iovec_dat_t *iovp; 823 vir_bytes offset; 824 int nic_addr; 825 vir_bytes count; 722 static void dp_pio8_user2nic(dpeth_t *dep, iovec_dat_t *iovp, vir_bytes offset, int nic_addr, vir_bytes count) 826 723 { 827 724 // phys_bytes phys_user; -
uspace/srv/hw/netif/dp8390/dp8390_drv.h
r6fc0edd rb590c21 73 73 int do_pwrite(dpeth_t * dep, packet_t *packet, int from_int); 74 74 75 /** Prints out network interface information.76 * @param[in] dep The network interface structure.77 */78 void dp8390_dump(dpeth_t * dep);79 80 75 #endif 81 76
Note:
See TracChangeset
for help on using the changeset viewer.