Rev 5522 | Rev 5560 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5522 | Rev 5525 | ||
---|---|---|---|
Line 26... | Line 26... | ||
26 | COMPATIBLE_API = 0x0100 |
26 | COMPATIBLE_API = 0x0100 |
27 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
27 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
Line 28... | Line 28... | ||
28 | 28 | ||
Line -... | Line 29... | ||
- | 29 | MAX_DEVICES = 16 |
|
- | 30 | ||
29 | MAX_DEVICES = 16 |
31 | TX_RING_SIZE = 16 |
30 | 32 | ||
31 | DEBUG = 1 |
33 | DEBUG = 1 |
Line 32... | Line 34... | ||
32 | __DEBUG__ = 1 |
34 | __DEBUG__ = 1 |
Line 120... | Line 122... | ||
120 | size dw ? |
122 | size dw ? |
121 | packet rb 1500 |
123 | packet rb 1500 |
Line 122... | Line 124... | ||
122 | 124 | ||
Line 123... | Line 125... | ||
123 | ends |
125 | ends |
Line 124... | Line 126... | ||
124 | 126 | ||
125 | struc txfd { |
127 | struct txfd |
126 | 128 | ||
127 | .status dw ? |
129 | status dw ? |
128 | .command dw ? |
130 | command dw ? |
Line 129... | Line 131... | ||
129 | .link dd ? |
131 | link dd ? |
130 | .desc_addr dd ? |
132 | desc_addr dd ? |
- | 133 | count dd ? |
|
- | 134 | ||
Line 131... | Line 135... | ||
131 | .count dd ? |
135 | buf_addr dd ? |
Line 132... | Line 136... | ||
132 | 136 | buf_size dd ? |
|
Line 133... | Line 137... | ||
133 | .buf_addr0 dd ? |
137 | virt_addr dd ? |
134 | .buf_size0 dd ? |
138 | dd ? ; alignment |
Line 170... | Line 174... | ||
170 | 174 | ||
171 | io_addr dd ? |
175 | io_addr dd ? |
172 | pci_bus dd ? |
176 | pci_bus dd ? |
173 | pci_dev dd ? |
177 | pci_dev dd ? |
- | 178 | rx_desc dd ? |
|
174 | rx_desc dd ? |
179 | cur_tx dd ? |
175 | last_tx_buffer dd ? |
180 | last_tx dd ? |
176 | ee_bus_width db ? |
181 | ee_bus_width db ? |
Line 177... | Line 182... | ||
177 | irq_line db ? |
182 | irq_line db ? |
178 | 183 | ||
Line 179... | Line 184... | ||
179 | rb 0x100 - ($ and 0xff) ; align 256 |
184 | rb 0x100 - ($ and 0xff) ; align 256 |
180 | txfd txfd |
185 | tx_ring rb TX_RING_SIZE*sizeof.txfd |
Line 181... | Line 186... | ||
181 | 186 | ||
Line 464... | Line 469... | ||
464 | invoke GetPhysAddr |
469 | invoke GetPhysAddr |
465 | set_io [ebx + device.io_addr], 0 |
470 | set_io [ebx + device.io_addr], 0 |
466 | set_io [ebx + device.io_addr], reg_scb_ptr |
471 | set_io [ebx + device.io_addr], reg_scb_ptr |
467 | out dx, eax |
472 | out dx, eax |
Line 468... | Line -... | ||
468 | - | ||
469 | mov ax, INT_MASK + CU_STATSADDR |
473 | |
- | 474 | set_io [ebx + device.io_addr], reg_scb_cmd |
|
470 | set_io [ebx + device.io_addr], reg_scb_cmd |
475 | mov ax, CU_STATSADDR or INT_MASK |
471 | out dx, ax |
476 | out dx, ax |
Line 472... | Line 477... | ||
472 | call cmd_wait |
477 | call cmd_wait |
473 | 478 | ||
Line 474... | Line 479... | ||
474 | ;----------------- |
479 | ;------------------------ |
475 | ; setup RX |
480 | ; setup RX base addr to 0 |
476 | 481 | ||
Line 477... | Line 482... | ||
477 | set_io [ebx + device.io_addr], reg_scb_ptr |
482 | set_io [ebx + device.io_addr], reg_scb_ptr |
478 | xor eax, eax |
483 | xor eax, eax |
479 | out dx, eax |
484 | out dx, eax |
480 | 485 | ||
Line 481... | Line 486... | ||
481 | set_io [ebx + device.io_addr], reg_scb_cmd |
486 | set_io [ebx + device.io_addr], reg_scb_cmd |
482 | mov ax, INT_MASK + RX_ADDR_LOAD |
487 | mov ax, RX_ADDR_LOAD or INT_MASK |
Line 483... | Line 488... | ||
483 | out dx, ax |
488 | out dx, ax |
484 | call cmd_wait |
489 | call cmd_wait |
485 | 490 | ||
Line -... | Line 491... | ||
- | 491 | ;----------------------------- |
|
- | 492 | ; Create RX and TX descriptors |
|
- | 493 | ||
- | 494 | call init_rx_ring |
|
486 | ;----------------------------- |
495 | test eax, eax |
- | 496 | jz .error |
|
- | 497 | ||
Line 487... | Line 498... | ||
487 | ; Create RX and TX descriptors |
498 | call init_tx_ring |
488 | 499 | ||
489 | call create_ring |
500 | |
490 | test eax, eax |
501 | ;--------- |
491 | jz .error |
502 | ; Start RX |
492 | 503 | ||
Line 493... | Line -... | ||
493 | ; RX start |
- | |
494 | 504 | DEBUGF 1, "Starting RX" |
|
- | 505 | ||
495 | set_io [ebx + device.io_addr], 0 |
506 | set_io [ebx + device.io_addr], 0 |
496 | set_io [ebx + device.io_addr], reg_scb_ptr |
507 | set_io [ebx + device.io_addr], reg_scb_ptr |
Line -... | Line 508... | ||
- | 508 | mov eax, [ebx + device.rx_desc] |
|
497 | mov eax, [ebx + device.rx_desc] |
509 | invoke GetPhysAddr |
Line 498... | Line 510... | ||
498 | invoke GetPhysAddr |
510 | add eax, NET_BUFF.data |
499 | add eax, NET_BUFF.data |
511 | out dx, eax |
500 | out dx, eax |
512 | |
Line 501... | Line 513... | ||
501 | 513 | set_io [ebx + device.io_addr], reg_scb_cmd |
|
- | 514 | mov ax, RX_START or INT_MASK |
|
- | 515 | out dx, ax |
|
- | 516 | call cmd_wait |
|
- | 517 | ||
- | 518 | ;---------- |
|
- | 519 | ; Set-up TX |
|
- | 520 | ||
- | 521 | set_io [ebx + device.io_addr], reg_scb_ptr |
|
- | 522 | xor eax, eax |
|
- | 523 | out dx, eax |
|
- | 524 | ||
- | 525 | set_io [ebx + device.io_addr], reg_scb_cmd |
|
- | 526 | mov ax, CU_CMD_BASE or INT_MASK |
|
- | 527 | out dx, ax |
|
- | 528 | call cmd_wait |
|
- | 529 | ||
- | 530 | ;------------------------- |
|
- | 531 | ; Individual address setup |
|
- | 532 | ||
- | 533 | mov [ebx + device.confcmd.command], CmdIASetup + Cmdsuspend |
|
- | 534 | mov [ebx + device.confcmd.status], 0 |
|
- | 535 | lea eax, [ebx + device.tx_ring] |
|
- | 536 | invoke GetPhysAddr |
|
502 | mov ax, INT_MASK + RX_START |
537 | mov [ebx + device.confcmd.link], eax |
503 | set_io [ebx + device.io_addr], reg_scb_cmd |
538 | lea edi, [ebx + device.confcmd.data] |
504 | out dx, ax |
539 | lea esi, [ebx + device.mac] |
Line 505... | Line 540... | ||
505 | call cmd_wait |
540 | movsd |
- | 541 | movsw |
|
Line 506... | Line 542... | ||
506 | 542 | ||
507 | ; Set-up TX |
543 | set_io [ebx + device.io_addr], reg_scb_ptr |
508 | 544 | lea eax, [ebx + device.confcmd.status] |
|
509 | set_io [ebx + device.io_addr], reg_scb_ptr |
545 | invoke GetPhysAddr |
510 | xor eax, eax |
546 | out dx, eax |
Line 511... | Line 547... | ||
511 | out dx, eax |
547 | |
512 | 548 | set_io [ebx + device.io_addr], reg_scb_cmd |
|
Line 533... | Line 569... | ||
533 | mov byte[ebx + device.confcmd.data + 5], 0x80 |
569 | mov byte[ebx + device.confcmd.data + 5], 0x80 |
534 | mov byte[ebx + device.confcmd.data + 15], 0x48 |
570 | mov byte[ebx + device.confcmd.data + 15], 0x48 |
535 | mov byte[ebx + device.confcmd.data + 19], 0x80 |
571 | mov byte[ebx + device.confcmd.data + 19], 0x80 |
536 | mov byte[ebx + device.confcmd.data + 21], 0x05 |
572 | mov byte[ebx + device.confcmd.data + 21], 0x05 |
Line 537... | Line -... | ||
537 | - | ||
538 | mov [ebx + device.txfd.command], CmdIASetup |
- | |
539 | mov [ebx + device.txfd.status], 0 |
- | |
540 | lea eax, [ebx + device.confcmd.status] |
- | |
541 | invoke GetPhysAddr |
- | |
542 | mov [ebx + device.txfd.link], eax |
- | |
543 | - | ||
544 | ;;; copy in our MAC |
- | |
545 | - | ||
546 | lea edi, [ebx + device.txfd.desc_addr] |
- | |
547 | lea esi, [ebx + device.mac] |
- | |
548 | movsd |
- | |
549 | movsw |
- | |
550 | 573 | ||
551 | set_io [ebx + device.io_addr], reg_scb_ptr |
574 | set_io [ebx + device.io_addr], reg_scb_ptr |
552 | lea eax, [ebx + device.txfd.status] |
575 | lea eax, [ebx + device.confcmd.status] |
553 | invoke GetPhysAddr |
576 | invoke GetPhysAddr |
Line 554... | Line -... | ||
554 | out dx, eax |
- | |
555 | - | ||
556 | ; Start CU & enable ints |
577 | out dx, eax |
557 | 578 | ||
558 | set_io [ebx + device.io_addr], reg_scb_cmd |
579 | set_io [ebx + device.io_addr], reg_scb_cmd |
559 | mov ax, CU_START |
580 | mov ax, CU_START ; expect Interrupts from now on |
Line 560... | Line -... | ||
560 | out dx, ax |
- | |
561 | call cmd_wait |
- | |
562 | - | ||
563 | ;----------------------- |
- | |
564 | ; build txfd structure (again!) |
- | |
565 | - | ||
566 | lea eax, [ebx + device.txfd.status] |
- | |
567 | invoke GetPhysAddr |
- | |
568 | mov [ebx + device.txfd.link], eax |
- | |
569 | mov [ebx + device.txfd.count], 0x02208000 |
- | |
570 | lea eax, [ebx + device.txfd.buf_addr0] |
- | |
571 | invoke GetPhysAddr |
- | |
572 | mov [ebx + device.txfd.desc_addr], eax |
- | |
573 | 581 | out dx, ax |
|
574 | ; Indicate that we have successfully reset the card |
- | |
575 | 582 | call cmd_wait |
|
Line 576... | Line 583... | ||
576 | DEBUGF 1,"Reset complete\n" |
583 | |
577 | 584 | DEBUGF 1,"Reset complete\n" |
|
Line 587... | Line 594... | ||
587 | or eax, -1 |
594 | or eax, -1 |
588 | ret |
595 | ret |
Line 589... | Line 596... | ||
589 | 596 | ||
590 | 597 | ||
Line 591... | Line 598... | ||
591 | align 4 |
598 | align 4 |
Line 592... | Line 599... | ||
592 | create_ring: |
599 | init_rx_ring: |
593 | 600 | ||
Line 607... | Line 614... | ||
607 | mov [esi + sizeof.NET_BUFF + rxfd.command], 0x0000 |
614 | mov [esi + sizeof.NET_BUFF + rxfd.command], 0x0000 |
608 | mov [esi + sizeof.NET_BUFF + rxfd.link], eax |
615 | mov [esi + sizeof.NET_BUFF + rxfd.link], eax |
609 | mov [esi + sizeof.NET_BUFF + rxfd.count], 0 |
616 | mov [esi + sizeof.NET_BUFF + rxfd.count], 0 |
610 | mov [esi + sizeof.NET_BUFF + rxfd.size], 1528 |
617 | mov [esi + sizeof.NET_BUFF + rxfd.size], 1528 |
Line -... | Line 618... | ||
- | 618 | ||
- | 619 | ret |
|
611 | 620 | ||
- | 621 | .out_of_mem: |
|
612 | ;----------------------- |
622 | |
- | 623 | ret |
|
- | 624 | ||
Line -... | Line 625... | ||
- | 625 | ||
- | 626 | ||
- | 627 | ||
- | 628 | align 4 |
|
- | 629 | init_tx_ring: |
|
- | 630 | ||
613 | ; build txfd structure |
631 | DEBUGF 1,"Creating TX ring\n" |
- | 632 | ||
614 | 633 | lea esi, [ebx + device.tx_ring] |
|
- | 634 | mov eax, esi |
|
- | 635 | invoke GetPhysAddr |
|
615 | lea eax, [ebx + device.txfd.status] |
636 | mov ecx, TX_RING_SIZE |
616 | invoke GetPhysAddr |
637 | .next_desc: |
617 | mov [ebx + device.txfd.link], eax |
638 | mov [esi + txfd.status], 0 |
- | 639 | mov [esi + txfd.command], 0 |
|
- | 640 | lea edx, [eax + txfd.buf_addr] |
|
- | 641 | mov [esi + txfd.desc_addr], edx |
|
- | 642 | add eax, sizeof.txfd |
|
- | 643 | mov [esi + txfd.link], eax |
|
- | 644 | mov [esi + txfd.count], 0x01208000 ; One buffer, 0x20 bytes of transmit threshold, end of frame |
|
- | 645 | add esi, sizeof.txfd |
|
- | 646 | dec ecx |
|
- | 647 | jnz .next_desc |
|
618 | mov [ebx + device.txfd.count], 0x01208000 |
648 | |
619 | lea eax, [ebx + device.txfd.buf_addr0] |
649 | lea eax, [ebx + device.tx_ring] |
Line 620... | Line 650... | ||
620 | invoke GetPhysAddr |
650 | invoke GetPhysAddr |
- | 651 | mov dword[ebx + device.tx_ring + sizeof.txfd*(TX_RING_SIZE-1) + txfd.link], eax |
|
Line 621... | Line 652... | ||
621 | mov [ebx + device.txfd.desc_addr], eax |
652 | |
Line 622... | Line -... | ||
622 | - | ||
623 | .out_of_mem: |
653 | mov [ebx + device.cur_tx], 0 |
624 | 654 | mov [ebx + device.last_tx], 0 |
|
625 | ret |
655 | |
626 | 656 | ret |
|
627 | 657 | ||
Line 650... | Line 680... | ||
650 | cmp [esi + NET_BUFF.length], 1514 |
680 | cmp [esi + NET_BUFF.length], 1514 |
651 | ja .fail |
681 | ja .fail |
652 | cmp [esi + NET_BUFF.length], 60 |
682 | cmp [esi + NET_BUFF.length], 60 |
653 | jb .fail |
683 | jb .fail |
Line 654... | Line 684... | ||
654 | 684 | ||
655 | ;;; TODO: check if current descriptor is in use |
685 | ; Get current TX descriptor |
656 | ; fill in buffer address and size |
686 | mov edi, [ebx + device.cur_tx] |
- | 687 | mov eax, sizeof.txfd |
|
657 | mov eax, [bufferptr] |
688 | mul edi |
- | 689 | lea edi, [ebx + device.tx_ring + eax] |
|
- | 690 | ||
658 | mov [ebx + device.last_tx_buffer], eax |
691 | ; Check if current descriptor is free or still in use |
659 | add eax, [eax + NET_BUFF.offset] |
692 | cmp [edi + txfd.status], 0 |
- | 693 | jne .fail |
|
660 | invoke GetPhysAddr |
694 | |
661 | mov [ebx + device.txfd.buf_addr0], eax |
695 | ; Fill in status and command values |
662 | mov ecx, [bufferptr] |
696 | mov [edi + txfd.status], 0 |
663 | mov ecx, [ecx + NET_BUFF.length] |
697 | mov [edi + txfd.command], Cmdsuspend + CmdTx + CmdTxFlex ;;;+ 1 shl 15 ;;; EL bit |
664 | mov [ebx + device.txfd.buf_size0], ecx |
698 | mov [edi + txfd.count], 0x01208000 |
- | 699 | ||
665 | 700 | ; Fill in buffer address and size |
|
- | 701 | mov [edi + txfd.virt_addr], esi |
|
- | 702 | mov eax, esi |
|
- | 703 | add eax, [esi + NET_BUFF.offset] |
|
- | 704 | push edi |
|
- | 705 | invoke GetPhysAddr |
|
666 | mov [ebx + device.txfd.status], 0 |
706 | pop edi |
- | 707 | mov [edi + txfd.buf_addr], eax |
|
667 | mov [ebx + device.txfd.command], Cmdsuspend + CmdTx + CmdTxFlex ;+ 1 shl 15 ;;; EL bit |
708 | mov ecx, [esi + NET_BUFF.length] |
Line 668... | Line 709... | ||
668 | ; mov [txfd.count], 0x02208000 ;;;;;;;;;;; |
709 | mov [edi + txfd.buf_size], ecx |
669 | 710 | ||
670 | ; Inform device of the new/updated transmit descriptor |
711 | ; Inform device of the new/updated transmit descriptor |
671 | lea eax, [ebx + device.txfd.status] |
712 | mov eax, edi |
672 | invoke GetPhysAddr |
713 | invoke GetPhysAddr |
673 | set_io [ebx + device.io_addr], 0 |
714 | set_io [ebx + device.io_addr], 0 |
Line 674... | Line 715... | ||
674 | set_io [ebx + device.io_addr], reg_scb_ptr |
715 | set_io [ebx + device.io_addr], reg_scb_ptr |
675 | out dx, eax |
- | |
676 | 716 | out dx, eax |
|
- | 717 | ||
677 | ; Start the transmit |
718 | ; Start the transmit |
678 | mov ax, CU_START |
- | |
Line 679... | Line 719... | ||
679 | set_io [ebx + device.io_addr], reg_scb_cmd |
719 | set_io [ebx + device.io_addr], reg_scb_cmd |
680 | out dx, ax |
720 | mov ax, CU_START |
681 | call cmd_wait |
721 | out dx, ax |
682 | 722 | ||
Line -... | Line 723... | ||
- | 723 | ; Update stats |
|
- | 724 | inc [ebx + device.packets_tx] |
|
- | 725 | add dword[ebx + device.bytes_tx], ecx |
|
- | 726 | adc dword[ebx + device.bytes_tx + 4], 0 |
|
- | 727 | ||
- | 728 | ; Wait for command to complete |
|
683 | ; Update stats |
729 | call cmd_wait |
684 | inc [ebx + device.packets_tx] |
730 | |
685 | add dword[ebx + device.bytes_tx], ecx |
731 | inc [ebx + device.cur_tx] |
686 | adc dword[ebx + device.bytes_tx + 4], 0 |
732 | and [ebx + device.cur_tx], TX_RING_SIZE - 1 |
Line 687... | Line 733... | ||
687 | 733 | ||
- | 734 | DEBUGF 1,"Transmit OK\n" |
|
688 | DEBUGF 1,"Transmit OK\n" |
735 | popf |
689 | popf |
736 | xor eax, eax |
690 | xor eax, eax |
737 | ret |
691 | ret |
738 | |
Line 806... | Line 853... | ||
806 | DEBUGF 1, "no more data\n" |
853 | DEBUGF 1, "no more data\n" |
807 | pop ax |
854 | pop ax |
Line 808... | Line 855... | ||
808 | 855 | ||
Line -... | Line 856... | ||
- | 856 | .no_rx: |
|
- | 857 | ||
- | 858 | test ax, 1 shl 13 |
|
- | 859 | jz .no_tx |
|
809 | .no_rx: |
860 | DEBUGF 1, "Command completed\n" |
- | 861 | ||
810 | 862 | push eax |
|
- | 863 | .loop_tx: |
|
811 | ; Cleanup after TX |
864 | mov edi, [ebx + device.last_tx] |
- | 865 | mov eax, sizeof.txfd |
|
- | 866 | mul eax |
|
812 | cmp [ebx + device.txfd.status], 0 |
867 | lea edi, [ebx + device.tx_ring + eax] |
813 | je .done |
868 | |
- | 869 | cmp [edi + txfd.status], 0 |
|
- | 870 | je .tx_done |
|
814 | cmp [ebx + device.last_tx_buffer], 0 |
871 | |
- | 872 | cmp [edi + txfd.virt_addr], 0 |
|
815 | je .done |
873 | je .tx_done |
- | 874 | ||
- | 875 | DEBUGF 1,"Freeing buffer 0x%x\n", [edi + txfd.virt_addr] |
|
- | 876 | ||
- | 877 | push [edi + txfd.virt_addr] |
|
- | 878 | mov [edi + txfd.virt_addr], 0 |
|
816 | push ax |
879 | invoke NetFree |
817 | DEBUGF 1, "Removing packet 0x%x from RAM!\n", [ebx + device.last_tx_buffer] |
880 | |
- | 881 | inc [ebx + device.last_tx] |
|
- | 882 | and [ebx + device.last_tx], TX_RING_SIZE - 1 |
|
- | 883 | ||
818 | invoke KernelFree, [ebx + device.last_tx_buffer] |
884 | jmp .loop_tx |
- | 885 | .tx_done: |
|
Line 819... | Line -... | ||
819 | mov [ebx + device.last_tx_buffer], 0 |
- | |
820 | pop ax |
886 | pop eax |
821 | 887 | .no_tx: |
|
822 | .done: |
888 | |
Line 823... | Line 889... | ||
823 | and ax, 00111100b |
889 | and ax, 00111100b |