Rev 4470 | Rev 5074 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4470 | Rev 4998 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | ;; See file COPYING for details ;; |
23 | ;; See file COPYING for details ;; |
24 | ;; ;; |
24 | ;; ;; |
25 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
25 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 26... | Line 26... | ||
26 | 26 | ||
- | 27 | ||
Line 27... | Line 28... | ||
27 | 28 | format PE DLL native |
|
28 | format MS COFF |
29 | entry START |
- | 30 | ||
Line 29... | Line 31... | ||
29 | 31 | CURRENT_API = 0x0200 |
|
Line 30... | Line 32... | ||
30 | API_VERSION = 0x01000100 |
32 | COMPATIBLE_API = 0x0100 |
31 | DRIVER_VERSION = 5 |
33 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
Line 40... | Line 42... | ||
40 | __DEBUG_LEVEL__ = 2 |
42 | __DEBUG_LEVEL__ = 2 |
Line 41... | Line 43... | ||
41 | 43 | ||
42 | RX_RING = 4 |
44 | RX_RING = 4 |
Line -... | Line 45... | ||
- | 45 | TX_RING = 4 |
|
- | 46 | ||
- | 47 | section '.flat' readable writable executable |
|
43 | TX_RING = 4 |
48 | |
44 | 49 | include '../proc32.inc' |
|
45 | include '../struct.inc' |
- | |
46 | include '../macros.inc' |
- | |
47 | include '../proc32.inc' |
50 | include '../struct.inc' |
48 | include '../imports.inc' |
51 | include '../macros.inc' |
49 | include '../fdo.inc' |
- | |
50 | include '../netdrv.inc' |
- | |
51 | - | ||
52 | public START |
- | |
Line 53... | Line 52... | ||
53 | public service_proc |
52 | include '../fdo.inc' |
54 | public version |
53 | include '../netdrv_pe.inc' |
55 | 54 | ||
Line 92... | Line 91... | ||
92 | MIIDELAY = 5 |
91 | MIIDELAY = 5 |
Line 93... | Line 92... | ||
93 | 92 | ||
94 | IRQ_RX_ERROR = 0x0001 |
93 | IRQ_RX_ERROR = 0x0001 |
95 | IRQ_RX = 0x0002 |
94 | IRQ_RX = 0x0002 |
- | 95 | IRQ_RX_NOBUF = 0x0004 |
|
96 | IRQ_RX_NOBUF = 0x0004 |
96 | IRQ_TX_ERROR = 0x0008 |
97 | IRQ_LINK = 0x0040 |
97 | IRQ_TX_OK = 0x0010 |
- | 98 | IRQ_TIMER = 0x0020 |
|
- | 99 | IRQ_LINK = 0x0040 |
|
98 | IRQ_TIMER = 0x0020 |
100 | IRQ_RX_FORCED = 0x0080 |
- | 101 | IRQ_TX_FORCED = 0x0100 |
|
- | 102 | IRQ_RECOVER_ERROR = 0x8200 ; |
|
99 | IRQMASK_WANTED_2 = 0x0147 |
103 | IRQMASK_WANTED_2 = IRQ_TX_FORCED + IRQ_LINK + IRQ_RX_ERROR + IRQ_RX + IRQ_TX_OK + IRQ_TX_ERROR |
100 | 104 | ||
101 | IRQ_RX_ALL = IRQ_RX_ERROR or IRQ_RX or IRQ_RX_NOBUF |
105 | IRQ_RX_ALL = IRQ_RX_ERROR or IRQ_RX or IRQ_RX_NOBUF or IRQ_RX_FORCED |
102 | IRQ_TX_ALL = 0 ; ??????????? |
106 | IRQ_TX_ALL = IRQ_TX_ERROR or IRQ_TX_OK or IRQ_TX_FORCED |
Line 103... | Line 107... | ||
103 | IRQ_OTHER_ALL = IRQ_LINK ;or IRQ_TIMER |
107 | IRQ_OTHER = IRQ_LINK or IRQ_TIMER or IRQ_RECOVER_ERROR |
Line 104... | Line 108... | ||
104 | 108 | ||
105 | IRQSTAT_MASK = 0x1ff |
109 | IRQSTAT_MASK = 0x1ff |
Line 221... | Line 225... | ||
221 | ; comparing np->desc_ver with DESC_VER_xy. |
225 | ; comparing np->desc_ver with DESC_VER_xy. |
222 | ; - It contains bits that are forced on when writing to TxRxControl. |
226 | ; - It contains bits that are forced on when writing to TxRxControl. |
223 | DESC_VER_1 = 0x0 |
227 | DESC_VER_1 = 0x0 |
224 | DESC_VER_2 = (0x02100 or TXRXCTL_RXCHECK) |
228 | DESC_VER_2 = (0x02100 or TXRXCTL_RXCHECK) |
Line 225... | Line -... | ||
225 | - | ||
226 | MAC_ADDR_LEN = 6 |
- | |
227 | 229 | ||
228 | NV_TX_LASTPACKET = (1 shl 16) |
230 | NV_TX_LASTPACKET = (1 shl 16) |
229 | NV_TX_RETRYERROR = (1 shl 19) |
231 | NV_TX_RETRYERROR = (1 shl 19) |
230 | NV_TX_LASTPACKET1 = (1 shl 24) |
232 | NV_TX_LASTPACKET1 = (1 shl 24) |
231 | NV_TX_DEFERRED = (1 shl 26) |
233 | NV_TX_DEFERRED = (1 shl 26) |
Line 327... | Line 329... | ||
327 | struct RxDesc |
329 | struct RxDesc |
328 | PacketBuffer dd ? |
330 | PacketBuffer dd ? |
329 | FlagLen dd ? |
331 | FlagLen dd ? |
330 | ends |
332 | ends |
Line 331... | Line -... | ||
331 | - | ||
332 | virtual at ebx |
- | |
333 | 333 | ||
Line -... | Line 334... | ||
- | 334 | struct device ETH_DEVICE |
|
334 | device: |
335 | |
Line -... | Line 336... | ||
- | 336 | pci_bus dd ? |
|
- | 337 | pci_dev dd ? |
|
- | 338 | ||
- | 339 | mmio_addr dd ? |
|
- | 340 | vendor_id dw ? |
|
- | 341 | device_id dw ? |
|
- | 342 | txflags dd ? |
|
- | 343 | desc_ver dd ? |
|
- | 344 | irqmask dd ? |
|
- | 345 | wolenabled dd ? |
|
- | 346 | in_shutdown dd ? |
|
- | 347 | cur_rx dd ? |
|
335 | 348 | cur_tx dd ? |
|
- | 349 | last_tx dd ? |
|
- | 350 | phyaddr dd ? |
|
- | 351 | phy_oui dd ? |
|
- | 352 | gigabit dd ? |
|
336 | ETH_DEVICE |
353 | needs_mac_reset dd ? |
Line 337... | Line -... | ||
337 | - | ||
338 | .pci_bus dd ? |
- | |
339 | .pci_dev dd ? |
- | |
340 | - | ||
341 | .mmio_addr dd ? |
- | |
342 | .vendor_id dw ? |
- | |
343 | .device_id dw ? |
- | |
344 | .txflags dd ? |
- | |
345 | .desc_ver dd ? |
354 | linkspeed dd ? |
346 | .irqmask dd ? |
- | |
347 | .wolenabled dd ? |
- | |
348 | .in_shutdown dd ? |
355 | duplex dd ? |
349 | .cur_rx dd ? |
- | |
350 | .phyaddr dd ? |
- | |
351 | .phy_oui dd ? |
- | |
352 | .gigabit dd ? |
- | |
353 | .needs_mac_reset dd ? |
- | |
Line 354... | Line 356... | ||
354 | .linkspeed dd ? |
356 | nocable dd ? |
355 | .duplex dd ? |
357 | |
Line 356... | Line -... | ||
356 | .next_tx dd ? |
- | |
357 | .nocable dd ? |
- | |
- | 358 | rb 0x100 - ($ and 0xff) |
|
Line 358... | Line -... | ||
358 | - | ||
359 | rb 0x100 - (($ - device) and 0xff) |
- | |
Line 360... | Line 359... | ||
360 | .tx_ring rd (TX_RING * sizeof.TxDesc) /4*2 |
359 | tx_ring rd (TX_RING * sizeof.TxDesc) /4*2 |
361 | 360 | ||
362 | rb 0x100 - (($ - device) and 0xff) |
361 | rb 0x100 - ($ and 0xff) |
Line 437... | Line 436... | ||
437 | virtual at edi + 0x600 |
436 | virtual at edi + 0x600 |
438 | PowerState2 dd ? |
437 | PowerState2 dd ? |
439 | end virtual |
438 | end virtual |
Line 440... | Line -... | ||
440 | - | ||
441 | - | ||
442 | section '.flat' code readable align 16 |
- | |
Line 443... | Line 439... | ||
443 | 439 | ||
444 | 440 | ||
445 | 441 | ||
446 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
442 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
447 | ;; ;; |
443 | ;; ;; |
448 | ;; proc START ;; |
444 | ;; proc START ;; |
Line 449... | Line -... | ||
449 | ;; ;; |
- | |
450 | ;; (standard driver proc) ;; |
445 | ;; ;; |
Line 451... | Line 446... | ||
451 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
446 | ;; (standard driver proc) ;; |
452 | 447 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
Line 453... | Line 448... | ||
453 | align 4 |
448 | |
454 | proc START stdcall, state:dword |
449 | proc START c, reason:dword, cmdline:dword |
455 | 450 | ||
Line 456... | Line 451... | ||
456 | cmp [state], 1 |
451 | cmp [reason], DRV_ENTRY |
457 | jne .exit |
452 | jne .fail |
458 | 453 | ||
Line 459... | Line 454... | ||
459 | DEBUGF 2,"Loading driver\n" |
454 | DEBUGF 2,"Loading driver\n" |
Line 472... | Line 467... | ||
472 | ;; proc SERVICE_PROC ;; |
467 | ;; proc SERVICE_PROC ;; |
473 | ;; ;; |
468 | ;; ;; |
474 | ;; (standard driver proc) ;; |
469 | ;; (standard driver proc) ;; |
475 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
470 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 476... | Line -... | ||
476 | - | ||
477 | align 4 |
471 | |
Line 478... | Line 472... | ||
478 | proc service_proc stdcall, ioctl:dword |
472 | proc service_proc stdcall, ioctl:dword |
479 | 473 | ||
Line 514... | Line 508... | ||
514 | 508 | ||
515 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
509 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
516 | mov ax, [eax+1] |
510 | mov ax, [eax+1] |
517 | .nextdevice: |
511 | .nextdevice: |
518 | mov ebx, [esi] |
512 | mov ebx, [esi] |
519 | cmp al, byte [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) |
513 | cmp al, byte [ebx + device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) |
520 | jne @f |
514 | jne @f |
521 | cmp ah, byte [device.pci_dev] |
515 | cmp ah, byte [ebx + device.pci_dev] |
522 | je .find_devicenum ; Device is already loaded, let's find it's device number |
516 | je .find_devicenum ; Device is already loaded, let's find it's device number |
523 | @@: |
517 | @@: |
524 | add esi, 4 |
518 | add esi, 4 |
Line 528... | Line 522... | ||
528 | ; This device doesnt have its own eth_device structure yet, lets create one |
522 | ; This device doesnt have its own eth_device structure yet, lets create one |
529 | .firstdevice: |
523 | .firstdevice: |
530 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
524 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
531 | jae .fail |
525 | jae .fail |
Line 532... | Line 526... | ||
532 | 526 | ||
Line 533... | Line 527... | ||
533 | allocate_and_clear ebx, sizeof.device_struct, .fail ; Allocate the buffer for device structure |
527 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure |
Line 534... | Line 528... | ||
534 | 528 | ||
535 | ; Fill in the direct call addresses into the struct |
529 | ; Fill in the direct call addresses into the struct |
536 | 530 | ||
537 | mov [device.reset], reset |
531 | mov [ebx + device.reset], reset |
Line 538... | Line 532... | ||
538 | mov [device.transmit], transmit |
532 | mov [ebx + device.transmit], transmit |
Line 539... | Line 533... | ||
539 | mov [device.unload], .fail |
533 | mov [ebx + device.unload], .fail |
540 | mov [device.name], my_service |
534 | mov [ebx + device.name], my_service |
541 | 535 | ||
542 | ; save the pci bus and device numbers |
536 | ; save the pci bus and device numbers |
543 | 537 | ||
Line 544... | Line 538... | ||
544 | mov eax, [edx + IOCTL.input] |
538 | mov eax, [edx + IOCTL.input] |
Line 545... | Line 539... | ||
545 | movzx ecx, byte [eax+1] |
539 | movzx ecx, byte [eax+1] |
546 | mov [device.pci_bus], ecx |
540 | mov [ebx + device.pci_bus], ecx |
547 | movzx ecx, byte [eax+2] |
541 | movzx ecx, byte [eax+2] |
548 | mov [device.pci_dev], ecx |
542 | mov [ebx + device.pci_dev], ecx |
Line 549... | Line 543... | ||
549 | 543 | ||
550 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x\n", [device.pci_dev], [device.pci_bus] |
544 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x\n", [ebx + device.pci_dev], [ebx + device.pci_bus] |
551 | 545 | ||
Line 552... | Line 546... | ||
552 | ; Ok, the eth_device structure is ready, let's probe the device |
546 | ; Ok, the eth_device structure is ready, let's probe the device |
553 | call probe ; this function will output in eax |
547 | call probe ; this function will output in eax |
Line 554... | Line 548... | ||
554 | test eax, eax |
548 | test eax, eax |
555 | jnz .err ; If an error occured, exit |
549 | jnz .err ; If an error occured, exit |
Line 556... | Line 550... | ||
556 | 550 | ||
Line 557... | Line 551... | ||
557 | mov eax, [devices] ; Add the device structure to our device list |
551 | mov eax, [devices] ; Add the device structure to our device list |
Line 558... | Line 552... | ||
558 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
552 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
559 | inc [devices] ; |
553 | inc [devices] ; |
560 | 554 | ||
561 | mov [device.type], NET_TYPE_ETH |
555 | mov [ebx + device.type], NET_TYPE_ETH |
562 | call NetRegDev |
556 | invoke NetRegDev |
563 | 557 | ||
564 | cmp eax, -1 |
558 | cmp eax, -1 |
Line 580... | Line 574... | ||
580 | 574 | ||
581 | .destroy: |
575 | .destroy: |
Line 582... | Line 576... | ||
582 | ; todo: reset device into virgin state |
576 | ; todo: reset device into virgin state |
583 | 577 | ||
584 | .err: |
578 | .err: |
Line 585... | Line 579... | ||
585 | stdcall KernelFree, ebx |
579 | invoke KernelFree, ebx |
Line 586... | Line 580... | ||
586 | .fail: |
580 | .fail: |
Line 610... | Line 604... | ||
610 | align 4 |
604 | align 4 |
611 | probe: |
605 | probe: |
Line 612... | Line 606... | ||
612 | 606 | ||
Line 613... | Line 607... | ||
613 | DEBUGF 1,"probe\n" |
607 | DEBUGF 1,"probe\n" |
Line -... | Line 608... | ||
- | 608 | ||
- | 609 | mov [ebx + device.needs_mac_reset], 0 |
|
- | 610 | ||
- | 611 | ; Make the device a bus master and enable response in I/O space |
|
- | 612 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
|
- | 613 | or al, PCI_CMD_MASTER + PCI_CMD_PIO ; + PCI_CMD_MMIO |
|
- | 614 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
|
614 | 615 | ||
615 | mov [device.needs_mac_reset], 0 |
616 | ; Adjust PCI latency to be at least 32 |
616 | 617 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency |
|
- | 618 | cmp al, 32 |
|
- | 619 | jae @f |
|
Line -... | Line 620... | ||
- | 620 | mov al, 32 |
|
- | 621 | invoke PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax |
|
617 | PCI_make_bus_master |
622 | @@: |
Line -... | Line 623... | ||
- | 623 | ||
618 | PCI_adjust_latency 32 |
624 | ; Now, it's time to find the base mmio addres of the PCI device |
619 | PCI_find_mmio32 |
625 | stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev] ; returns in eax |
620 | 626 | DEBUGF 1,"mmio_addr= 0x%x\n", eax |
|
621 | DEBUGF 1,"mmio_addr= 0x%x\n", [device.mmio_addr]:8 |
627 | |
622 | 628 | ; Create virtual mapping of the physical memory |
|
Line -... | Line 629... | ||
- | 629 | invoke MapIoMem, eax, 10000h, PG_SW + PG_NOCACHE |
|
- | 630 | test eax, eax |
|
- | 631 | jz fail |
|
- | 632 | mov [ebx + device.mmio_addr], eax |
|
623 | stdcall MapIoMem, [device.mmio_addr], 2048, (PG_SW + PG_NOCACHE) |
633 | DEBUGF 1,"mapped mmio_addr= 0x%x\n", eax |
Line 624... | Line 634... | ||
624 | test eax, eax |
634 | |
625 | jz fail |
635 | ; Read PCI vendor/device ID |
626 | mov [device.mmio_addr], eax |
636 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.vendor_id |
627 | mov edi, eax |
637 | mov dword[ebx + device.vendor_id], eax |
628 | 638 | DEBUGF 1,"vendor = 0x%x\n", [ebx + device.vendor_id]:4 |
|
629 | DEBUGF 1,"mapped mmio_addr= 0x%x\n", [device.mmio_addr]:8 |
639 | DEBUGF 1,"device = 0x%x\n", [ebx + device.device_id]:4 |
630 | 640 | ||
631 | ;------------------------------------- |
641 | ;------------------------------------- |
632 | ; handle different descriptor versions |
642 | ; handle different descriptor versions |
633 | mov [device.desc_ver], DESC_VER_1 |
643 | mov [ebx + device.desc_ver], DESC_VER_1 |
634 | movzx eax, [device.device_id] |
644 | mov ax, [ebx + device.device_id] |
635 | cmp eax, PCI_DEVICE_ID_NVIDIA_NVENET_1 |
645 | cmp ax, PCI_DEVICE_ID_NVIDIA_NVENET_1 |
Line 636... | Line 646... | ||
636 | je .ver1 |
646 | je .ver1 |
Line 637... | Line 647... | ||
637 | cmp eax, PCI_DEVICE_ID_NVIDIA_NVENET_2 |
647 | cmp ax, PCI_DEVICE_ID_NVIDIA_NVENET_2 |
638 | je .ver1 |
648 | je .ver1 |
639 | cmp eax, PCI_DEVICE_ID_NVIDIA_NVENET_3 |
649 | cmp ax, PCI_DEVICE_ID_NVIDIA_NVENET_3 |
Line 640... | Line 650... | ||
640 | je .ver1 |
650 | je .ver1 |
641 | mov [device.desc_ver], DESC_VER_2 |
651 | mov [ebx + device.desc_ver], DESC_VER_2 |
642 | .ver1: |
652 | .ver1: |
643 | 653 | ||
644 | call read_mac |
654 | call read_mac |
Line 645... | Line 655... | ||
645 | 655 | ||
Line 646... | Line 656... | ||
646 | ; disable WOL |
656 | ; disable WOL |
647 | mov [WakeUpFlags], 0 |
657 | mov [WakeUpFlags], 0 |
648 | mov [device.wolenabled], 0 |
658 | mov [ebx + device.wolenabled], 0 |
649 | 659 | ||
650 | mov [device.txflags], (NV_TX2_LASTPACKET or NV_TX2_VALID) |
660 | mov [ebx + device.txflags], (NV_TX2_LASTPACKET or NV_TX2_VALID) |
- | 661 | cmp [ebx + device.desc_ver], DESC_VER_1 |
|
Line 651... | Line -... | ||
651 | cmp [device.desc_ver], DESC_VER_1 |
- | |
652 | jne @f |
662 | jne @f |
653 | mov [device.txflags], (NV_TX_LASTPACKET or NV_TX_VALID) |
- | |
654 | @@: |
- | |
655 | 663 | mov [ebx + device.txflags], (NV_TX_LASTPACKET or NV_TX_VALID) |
|
- | 664 | @@: |
|
656 | ; BEGIN of switch (pci->dev_id) |
665 | |
657 | 666 | ; BEGIN of switch (pci->dev_id) |
|
658 | cmp [device.device_id], 0x01C3 |
667 | |
659 | jne .next_0x0066 |
668 | cmp [ebx + device.device_id], 0x01C3 |
660 | ; nforce |
669 | jne .not_0x01c3 |
661 | mov [device.irqmask], 0 ;;;;;;;;;;;;;;;(IRQMASK_WANTED_2 or IRQ_TIMER) |
670 | ; nforce |
662 | jmp .find_phy |
671 | mov [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER) ;;; Was 0 |
663 | 672 | jmp .find_phy |
|
664 | .next_0x0066: |
673 | .not_0x01c3: |
665 | cmp [device.device_id], 0x0066 |
674 | |
- | 675 | cmp [ebx + device.device_id], 0x0066 |
|
Line 666... | Line -... | ||
666 | je @f |
- | |
667 | cmp [device.device_id], 0x00D6 |
676 | je @f |
668 | je @f |
677 | cmp [ebx + device.device_id], 0x00D6 |
669 | jmp .next_0x0086 |
678 | jne .not_0x0066 |
670 | @@: |
679 | @@: |
671 | mov [device.irqmask], 0 ;;;;;;;;;;;;;;;;(IRQMASK_WANTED_2 or IRQ_TIMER) |
680 | mov [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER) ;;;; was 0 |
672 | cmp [device.desc_ver], DESC_VER_1 |
681 | cmp [ebx + device.desc_ver], DESC_VER_1 |
673 | jne @f |
682 | jne @f |
674 | or [device.txflags], NV_TX_LASTPACKET1 |
683 | or [ebx + device.txflags], NV_TX_LASTPACKET1 |
675 | jmp .find_phy |
684 | jmp .find_phy |
676 | @@: |
685 | @@: |
677 | or [device.txflags], NV_TX2_LASTPACKET1 |
686 | or [ebx + device.txflags], NV_TX2_LASTPACKET1 |
678 | jmp .find_phy |
687 | jmp .find_phy |
679 | 688 | .not_0x0066: |
|
680 | .next_0x0086: |
689 | |
681 | cmp [device.device_id], 0x0086 |
690 | cmp [ebx + device.device_id], 0x0086 |
682 | je @f |
- | |
683 | cmp [device.device_id], 0x008c |
691 | je @f |
Line 684... | Line 692... | ||
684 | je @f |
692 | cmp [ebx + device.device_id], 0x008c |
685 | cmp [device.device_id], 0x00e6 |
693 | je @f |
Line 686... | Line 694... | ||
686 | je @f |
694 | cmp [ebx + device.device_id], 0x00e6 |
687 | cmp [device.device_id], 0x00df |
695 | je @f |
688 | je @f |
696 | cmp [ebx + device.device_id], 0x00df |
689 | cmp [device.device_id], 0x0056 |
697 | je @f |
690 | je @f |
698 | cmp [ebx + device.device_id], 0x0056 |
691 | cmp [device.device_id], 0x0057 |
699 | je @f |
692 | je @f |
700 | cmp [ebx + device.device_id], 0x0057 |
- | 701 | je @f |
|
Line 693... | Line -... | ||
693 | cmp [device.device_id], 0x0037 |
- | |
694 | je @f |
702 | cmp [ebx + device.device_id], 0x0037 |
695 | cmp [device.device_id], 0x0038 |
703 | je @f |
696 | je @f |
704 | cmp [ebx + device.device_id], 0x0038 |
697 | jmp .find_phy |
705 | jne .not_0x0086 |
698 | 706 | ||
699 | @@: |
707 | @@: |
700 | mov [device.irqmask], 0 ;;;;;;;;;;;;;;;;(IRQMASK_WANTED_2 or IRQ_TIMER) |
708 | mov [ebx + device.irqmask], (IRQMASK_WANTED_2 or IRQ_TIMER) ;;; was 0 |
701 | 709 | ||
702 | cmp [device.desc_ver], DESC_VER_1 |
710 | cmp [ebx + device.desc_ver], DESC_VER_1 |
703 | jne @f |
711 | jne @f |
704 | or [device.txflags], NV_TX_LASTPACKET1 |
712 | or [ebx + device.txflags], NV_TX_LASTPACKET1 |
705 | jmp .find_phy |
713 | jmp .find_phy |
Line 706... | Line 714... | ||
706 | @@: |
714 | @@: |
707 | or [device.txflags], NV_TX2_LASTPACKET1 |
- | |
708 | jmp .find_phy |
715 | or [ebx + device.txflags], NV_TX2_LASTPACKET1 |
- | 716 | jmp .find_phy |
|
Line 709... | Line 717... | ||
709 | 717 | .not_0x0086: |
|
710 | .next_0x0268: |
718 | |
711 | ; cmp word [device_id], 0x0268 |
719 | ; cmp word [device_id], 0x0268 |
712 | ; je @f |
720 | ; je @f |
713 | ; cmp word [device_id], 0x0269 |
721 | ; cmp word [device_id], 0x0269 |
714 | ; je @f |
722 | ; je @f |
715 | ; cmp word [device_id], 0x0372 |
723 | ; cmp word [device_id], 0x0372 |
- | 724 | ; je @f |
|
716 | ; je @f |
725 | ; cmp word [device_id], 0x0373 |
717 | ; cmp word [device_id], 0x0373 |
726 | ; je @f |
718 | ; je @f |
727 | ; jmp .default_switch |
719 | ; jmp .default_switch |
728 | ;@@: |
720 | ;@@: |
729 | cmp [ebx + device.device_id], 0x0268 |
Line 721... | Line 730... | ||
721 | cmp [device.device_id], 0x0268 |
730 | jb .undefined |
722 | jb .undefined |
731 | |
Line 723... | Line 732... | ||
723 | 732 | ; Get device revision |
|
724 | ; Get device revision |
733 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header.revision_id |
725 | 734 | mov edi, [ebx + device.mmio_addr] ;;;;; |
|
726 | stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REVISION_ID |
735 | |
727 | 736 | ; take phy and nic out of low power mode |
|
- | 737 | mov ecx, [PowerState2] |
|
728 | ; take phy and nic out of low power mode |
738 | and ecx, not POWERSTATE2_POWERUP_MASK |
729 | mov ecx, [PowerState2] |
739 | cmp [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_12 |
730 | and ecx, not POWERSTATE2_POWERUP_MASK |
740 | je @f |
731 | cmp [device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_12 |
741 | cmp [ebx + device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_13 |
732 | jne @f |
742 | jne .set_powerstate |
Line 733... | Line 743... | ||
733 | cmp [device.device_id], PCI_DEVICE_ID_NVIDIA_NVENET_13 |
743 | @@: |
734 | jne @f |
744 | cmp al, 0xA3 |
735 | cmp al, 0xA3 |
745 | jb .set_powerstate |
- | 746 | or ecx, POWERSTATE2_POWERUP_REV_A3 |
|
Line 736... | Line 747... | ||
736 | jb @f |
747 | .set_powerstate: |
737 | or ecx, POWERSTATE2_POWERUP_REV_A3 |
748 | mov [PowerState2], ecx |
Line 738... | Line 749... | ||
738 | @@: |
749 | |
Line 766... | Line 777... | ||
766 | and edx, 0x1f ; phyaddr = i & 0x1f |
777 | and edx, 0x1f ; phyaddr = i & 0x1f |
767 | mov eax, MII_PHYSID1 |
778 | mov eax, MII_PHYSID1 |
768 | mov ecx, MII_READ |
779 | mov ecx, MII_READ |
769 | call mii_rw ; EDX - addr, EAX - miireg, ECX - value |
780 | call mii_rw ; EDX - addr, EAX - miireg, ECX - value |
Line 770... | Line 781... | ||
770 | 781 | ||
771 | cmp eax, 0xffff |
782 | cmp eax, 0x0000ffff |
772 | je .try_next |
783 | je .try_next |
773 | cmp eax, 0 |
784 | test eax, 0x80000000 |
774 | jl .try_next |
785 | jnz .try_next |
Line 775... | Line 786... | ||
775 | mov esi, eax |
786 | mov esi, eax |
776 | 787 | ||
777 | mov eax, MII_PHYSID2 |
788 | mov eax, MII_PHYSID2 |
Line 778... | Line 789... | ||
778 | mov ecx, MII_READ |
789 | mov ecx, MII_READ |
779 | call mii_rw |
790 | call mii_rw |
780 | 791 | ||
781 | cmp eax, 0xffff |
792 | cmp eax, 0x0000ffff |
782 | je .try_next |
793 | je .try_next |
Line 783... | Line 794... | ||
783 | cmp eax, 0 |
794 | test eax, 0x80000000 |
784 | jl .try_next |
795 | jnz .try_next |
785 | jmp .got_it |
796 | jmp .got_it |
Line 786... | Line 797... | ||
786 | 797 | ||
787 | .try_next: |
798 | .try_next: |
Line 788... | Line 799... | ||
788 | test edx, edx |
799 | test edx, edx |
789 | jnz .phy_loop |
800 | jnz .phy_loop |
Line 790... | Line 801... | ||
790 | 801 | ||
791 | ; PHY in isolate mode? No phy attached and user wants to test loopback? |
- | |
792 | ; Very odd, but can be correct. |
802 | ; PHY in isolate mode? No phy attached and user wants to test loopback? |
793 | 803 | ; Very odd, but can be correct. |
|
794 | DEBUGF 1,"Could not find a valid PHY.\n" |
- | |
795 | jmp .no_phy |
804 | |
796 | 805 | DEBUGF 2,"Could not find a valid PHY.\n" |
|
- | 806 | jmp .no_phy |
|
Line -... | Line 807... | ||
- | 807 | ||
797 | .got_it: |
808 | .got_it: |
Line 798... | Line 809... | ||
798 | 809 | and esi, PHYID1_OUI_MASK |
|
799 | and esi, PHYID1_OUI_MASK |
- | |
800 | shl esi, PHYID1_OUI_SHFT |
- | |
Line 801... | Line 810... | ||
801 | 810 | shl esi, PHYID1_OUI_SHFT |
|
Line 802... | Line 811... | ||
802 | and eax, PHYID2_OUI_MASK |
811 | and eax, PHYID2_OUI_MASK |
Line 803... | Line 812... | ||
803 | shr eax, PHYID2_OUI_SHFT |
812 | shr eax, PHYID2_OUI_SHFT |
804 | 813 | or eax, esi |
|
805 | DEBUGF 1,"Found PHY 0x%x:0x%x at address 0x%x\n", esi:8, eax:8, edx |
814 | |
806 | 815 | mov [ebx + device.phyaddr], edx |
|
Line 807... | Line 816... | ||
807 | mov [device.phyaddr], edx |
816 | mov [ebx + device.phy_oui], eax |
Line 828... | Line 837... | ||
828 | ;*************************************************************************** |
837 | ;*************************************************************************** |
829 | reset: |
838 | reset: |
Line 830... | Line 839... | ||
830 | 839 | ||
Line 831... | Line 840... | ||
831 | DEBUGF 1,"Resetting\n" |
840 | DEBUGF 1,"Resetting\n" |
832 | 841 | ||
833 | stdcall PciRead8, [device.pci_bus], [device.pci_dev], PCI_REG_IRQ |
842 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
834 | movzx eax, al |
843 | movzx eax, al |
835 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
844 | invoke AttachIntHandler, eax, int_handler, ebx |
836 | test eax, eax |
845 | test eax, eax |
837 | jnz @f |
846 | jnz @f |
838 | DEBUGF 1,"\nCould not attach int handler!\n" |
847 | DEBUGF 2,"Could not attach int handler!\n" |
839 | ; or eax, -1 |
848 | or eax, -1 |
Line 840... | Line 849... | ||
840 | ; ret |
849 | ret |
Line 841... | Line 850... | ||
841 | @@: |
850 | @@: |
842 | 851 | ||
843 | ; erase previous misconfiguration |
852 | ; erase previous misconfiguration |
844 | 853 | ||
845 | mov edi, [device.mmio_addr] |
854 | mov edi, [ebx + device.mmio_addr] |
846 | mov [MulticastAddrA], MCASTADDRA_FORCE |
855 | mov [MulticastAddrA], MCASTADDRA_FORCE |
Line 860... | Line 869... | ||
860 | mov [UnknownTransmitterReg], 0 |
869 | mov [UnknownTransmitterReg], 0 |
Line 861... | Line 870... | ||
861 | 870 | ||
Line 862... | Line 871... | ||
862 | call txrx_reset |
871 | call txrx_reset |
863 | 872 | ||
Line 864... | Line 873... | ||
864 | mov [UnknownSetupReg6], 0 |
873 | mov [UnknownSetupReg6], 0 |
Line 865... | Line 874... | ||
865 | mov [device.in_shutdown], 0 |
874 | mov [ebx + device.in_shutdown], 0 |
866 | 875 | ||
867 | ; give hw rings |
876 | ; give hw rings |
Line 868... | Line 877... | ||
868 | 877 | ||
869 | lea eax, [device.rx_ring] |
878 | lea eax, [ebx + device.rx_ring] |
870 | GetRealAddr |
879 | invoke GetPhysAddr |
Line 871... | Line 880... | ||
871 | mov [RxRingPhysAddr], eax |
880 | mov [RxRingPhysAddr], eax |
Line 872... | Line 881... | ||
872 | 881 | ||
Line 873... | Line 882... | ||
873 | lea eax, [device.tx_ring] |
882 | lea eax, [ebx + device.tx_ring] |
874 | GetRealAddr |
883 | invoke GetPhysAddr |
875 | mov [TxRingPhysAddr], eax |
884 | mov [TxRingPhysAddr], eax |
876 | 885 | ||
Line 877... | Line 886... | ||
877 | mov [RingSizes], (((RX_RING - 1) shl RINGSZ_RXSHIFT) + ((TX_RING - 1) shl RINGSZ_TXSHIFT)) |
886 | mov [RingSizes], (((RX_RING - 1) shl RINGSZ_RXSHIFT) + ((TX_RING - 1) shl RINGSZ_TXSHIFT)) |
878 | 887 | ||
879 | ; |
888 | ; |
880 | 889 | ||
881 | mov [device.linkspeed], (LINKSPEED_FORCE or LINKSPEED_10) |
890 | mov [ebx + device.linkspeed], (LINKSPEED_FORCE or LINKSPEED_10) |
Line 908... | Line 917... | ||
908 | mov eax, [ReceiverStatus] |
917 | mov eax, [ReceiverStatus] |
909 | mov [ReceiverStatus], eax |
918 | mov [ReceiverStatus], eax |
Line 910... | Line 919... | ||
910 | 919 | ||
911 | ; set random seed |
920 | ; set random seed |
912 | push ebx |
921 | push ebx |
913 | stdcall GetTimerTicks ; bad idea, driver is started at system startup in 90% of cases.. |
922 | invoke GetTimerTicks ; bad idea, driver is started at system startup in 90% of cases.. |
Line 914... | Line 923... | ||
914 | pop ebx |
923 | pop ebx |
Line 915... | Line 924... | ||
915 | 924 | ||
916 | mov edi, [device.mmio_addr] |
925 | mov edi, [ebx + device.mmio_addr] |
917 | 926 | ||
Line 918... | Line 927... | ||
918 | and eax, RNDSEED_MASK |
927 | and eax, RNDSEED_MASK |
919 | or eax, RNDSEED_FORCE |
928 | or eax, RNDSEED_FORCE |
920 | mov [RandomSeed], eax |
929 | mov [RandomSeed], eax |
921 | 930 | ||
Line 922... | Line 931... | ||
922 | mov [UnknownSetupReg1], UNKSETUP1_VAL |
931 | mov [UnknownSetupReg1], UNKSETUP1_VAL |
923 | mov [UnknownSetupReg2], UNKSETUP2_VAL |
932 | mov [UnknownSetupReg2], UNKSETUP2_VAL |
924 | mov [PollingInterval], POLL_DEFAULT |
933 | mov [PollingInterval], POLL_DEFAULT |
925 | mov [UnknownSetupReg6], UNKSETUP6_VAL |
934 | mov [UnknownSetupReg6], UNKSETUP6_VAL |
Line 926... | Line 935... | ||
926 | 935 | ||
Line 935... | Line 944... | ||
935 | 944 | ||
936 | or [PowerState], POWERSTATE_POWEREDUP |
945 | or [PowerState], POWERSTATE_POWEREDUP |
Line 937... | Line 946... | ||
937 | call pci_push |
946 | call pci_push |
938 | 947 | ||
Line 939... | Line 948... | ||
939 | mov esi, 10 |
948 | mov esi, 10 |
940 | call Sleep |
949 | invoke Sleep |
Line 941... | Line 950... | ||
941 | 950 | ||
Line 973... | Line 982... | ||
973 | call update_linkspeed |
982 | call update_linkspeed |
Line 974... | Line 983... | ||
974 | 983 | ||
975 | mov [TransmitterControl], XMITCTL_START ; start TX |
984 | mov [TransmitterControl], XMITCTL_START ; start TX |
Line 976... | Line 985... | ||
976 | call pci_push |
985 | call pci_push |
977 | 986 | ||
978 | mov [device.nocable], 0 |
987 | mov [ebx + device.nocable], 0 |
979 | test eax, eax |
988 | test eax, eax |
980 | jnz .return |
989 | jnz .return |
Line 981... | Line 990... | ||
981 | DEBUGF 1,"no link during initialization.\n" |
990 | DEBUGF 1,"no link during initialization.\n" |
982 | mov [device.nocable], 1 |
991 | mov [ebx + device.nocable], 1 |
983 | 992 | ||
984 | .return: |
- | |
985 | xor eax, eax ; Indicate that we have successfully reset the card |
- | |
986 | mov [device.mtu], 1514 ;;; FIXME |
- | |
987 | - | ||
988 | ; Set link state to unknown |
993 | .return: |
Line 989... | Line 994... | ||
989 | mov [device.state], ETH_LINK_UNKOWN |
994 | xor eax, eax ; Indicate that we have successfully reset the card |
990 | 995 | mov [ebx + device.mtu], 1514 ;;; FIXME |
|
991 | ret |
- | |
992 | 996 | ret |
|
Line 993... | Line 997... | ||
993 | 997 | ||
994 | fail: |
998 | |
995 | or eax, -1 |
999 | fail: |
996 | 1000 | or eax, -1 |
|
997 | ret |
1001 | ret |
998 | 1002 | ||
999 | ;-------------------------------------------------------- |
1003 | ;-------------------------------------------------------- |
1000 | ; |
1004 | ; |
1001 | ; MII_RW |
1005 | ; MII_RW |
1002 | ; |
1006 | ; |
Line 1003... | Line 1007... | ||
1003 | ; read/write a register on the PHY. |
1007 | ; read/write a register on the PHY. |
Line 1004... | Line 1008... | ||
1004 | ; Caller must guarantee serialization |
1008 | ; Caller must guarantee serialization |
Line 1005... | Line 1009... | ||
1005 | ; Input: EAX - miireg, EDX - addr, ECX - value |
1009 | ; Input: EAX - miireg, EDX - phy addr, ECX - value to write (or -1 to read) |
Line 1006... | Line 1010... | ||
1006 | ; Output: EAX - retval |
1010 | ; Output: EAX - retval (lower 16 bits) |
1007 | ; |
- | |
Line -... | Line 1011... | ||
- | 1011 | ; |
|
- | 1012 | ;-------------------------------------------------------- |
|
- | 1013 | ||
1008 | ;-------------------------------------------------------- |
1014 | mii_rw: |
1009 | 1015 | ||
1010 | mii_rw: |
1016 | DEBUGF 1,"mii_rw: 0x%x to reg %d at PHY %d\n", ecx, eax, edx |
Line -... | Line 1017... | ||
- | 1017 | ||
- | 1018 | push edx |
|
1011 | 1019 | ||
1012 | DEBUGF 1,"mii_rw: 0x%x to reg %d at PHY %d\n", ecx, eax, edx |
1020 | mov edi, [ebx + device.mmio_addr] |
- | 1021 | ||
- | 1022 | ; Check if MII interface is busy |
|
1013 | 1023 | mov [MIIStatus], MIISTAT_MASK |
|
Line -... | Line 1024... | ||
- | 1024 | @@: |
|
1014 | push edx |
1025 | test [MIIControl], MIICTL_INUSE |
1015 | 1026 | jz @f |
|
Line -... | Line 1027... | ||
- | 1027 | mov [MIIControl], MIICTL_INUSE |
|
1016 | mov edi, [device.mmio_addr] |
1028 | |
1017 | mov [MIIStatus], MIISTAT_MASK |
1029 | DEBUGF 1,"mii_rw: in use!\n" |
1018 | - | ||
1019 | test [MIIControl], MIICTL_INUSE |
1030 | pusha |
1020 | jz @f |
1031 | mov esi, NV_MIIBUSY_DELAY |
1021 | mov [MIIControl], MIICTL_INUSE |
1032 | invoke Sleep |
- | 1033 | popa |
|
1022 | 1034 | jmp @r |
|
Line -... | Line 1035... | ||
- | 1035 | @@: |
|
1023 | mov esi, NV_MIIBUSY_DELAY |
1036 | |
Line 1024... | Line 1037... | ||
1024 | call Sleep |
1037 | ; Set the address we want to access |
1025 | @@: |
1038 | shl edx, MIICTL_ADDRSHIFT |
1026 | 1039 | or edx, eax |
|
1027 | shl edx, MIICTL_ADDRSHIFT |
1040 | |
1028 | or edx, eax |
1041 | ; When writing, write the data first. |
1029 | - | ||
Line -... | Line 1042... | ||
- | 1042 | cmp ecx, MII_READ |
|
1030 | cmp ecx, MII_READ |
1043 | je @f |
1031 | je @f |
1044 | mov [MIIData], ecx |
1032 | 1045 | or edx, MIICTL_WRITE |
|
1033 | mov [MIIData], ecx |
1046 | @@: |
1034 | or edx, MIICTL_WRITE |
1047 | |
1035 | @@: |
1048 | mov [MIIControl], edx |
1036 | mov [MIIControl], edx |
- | |
Line -... | Line 1049... | ||
- | 1049 | ||
1037 | 1050 | ; Wait for read/write to complete |
|
1038 | stdcall reg_delay, MIIControl-edi, MIICTL_INUSE, 0, NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, 0 |
1051 | stdcall reg_delay, MIIControl-edi, MIICTL_INUSE, 0, NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, 0 |
1039 | 1052 | ||
1040 | test eax, eax |
1053 | test eax, eax |
1041 | jz @f |
1054 | jz @f |
1042 | DEBUGF 1,"mii_rw timed out.\n" |
1055 | DEBUGF 1,"mii_rw timed out.\n" |
1043 | or eax, -1 |
- | |
Line -... | Line 1056... | ||
- | 1056 | or eax, -1 |
|
1044 | jmp .return |
1057 | jmp .return |
1045 | @@: |
1058 | |
Line 1046... | Line 1059... | ||
1046 | 1059 | @@: |
|
1047 | cmp ecx, MII_READ |
1060 | cmp ecx, MII_READ |
Line 1081... | Line 1094... | ||
1081 | push esi |
1094 | push esi |
1082 | call pci_push |
1095 | call pci_push |
Line 1083... | Line 1096... | ||
1083 | 1096 | ||
1084 | .loop: |
1097 | .loop: |
1085 | mov esi, [delay] |
1098 | mov esi, [delay] |
1086 | call Sleep |
1099 | invoke Sleep |
1087 | mov eax, [delaymax] |
1100 | mov eax, [delaymax] |
1088 | sub eax, [delay] |
1101 | sub eax, [delay] |
Line 1089... | Line 1102... | ||
1089 | mov [delaymax], eax |
1102 | mov [delaymax], eax |
Line 1118... | Line 1131... | ||
1118 | phy_init: |
1131 | phy_init: |
Line 1119... | Line 1132... | ||
1119 | 1132 | ||
Line 1120... | Line 1133... | ||
1120 | push ebx ecx |
1133 | push ebx ecx |
1121 | 1134 | ||
1122 | ; set advertise register |
1135 | ; set advertise register |
1123 | mov edx, [device.phyaddr] |
1136 | mov edx, [ebx + device.phyaddr] |
1124 | mov eax, MII_ADVERTISE |
1137 | mov eax, MII_ADVERTISE |
Line 1125... | Line 1138... | ||
1125 | mov ecx, MII_READ |
1138 | mov ecx, MII_READ |
Line 1132... | Line 1145... | ||
1132 | call mii_rw |
1145 | call mii_rw |
Line 1133... | Line 1146... | ||
1133 | 1146 | ||
1134 | test eax, eax |
1147 | test eax, eax |
Line 1135... | Line 1148... | ||
1135 | jz @f |
1148 | jz @f |
Line 1136... | Line 1149... | ||
1136 | 1149 | ||
1137 | DEBUGF 1,"phy write to advertise failed.\n" |
1150 | DEBUGF 2,"phy write to advertise failed.\n" |
1138 | 1151 | ||
Line 1139... | Line 1152... | ||
1139 | mov eax, PHY_ERROR |
1152 | mov eax, PHY_ERROR |
1140 | jmp .return |
1153 | jmp .return |
1141 | @@: |
1154 | @@: |
1142 | 1155 | ||
Line 1143... | Line 1156... | ||
1143 | ; get phy interface type |
1156 | ; get phy interface type |
1144 | mov edi, [device.mmio_addr] |
1157 | mov edi, [ebx + device.mmio_addr] |
1145 | mov eax, [PhyInterface] |
1158 | mov eax, [PhyInterface] |
1146 | DEBUGF 1,"phy interface type = 0x%x\n", eax:8 |
1159 | DEBUGF 1,"phy interface type = 0x%x\n", eax:8 |
Line 1147... | Line 1160... | ||
1147 | 1160 | ||
1148 | ; see if gigabit phy |
1161 | ; see if gigabit phy |
1149 | mov eax, MII_BMSR |
1162 | mov eax, MII_BMSR |
1150 | mov ecx, MII_READ |
1163 | mov ecx, MII_READ |
Line 1151... | Line 1164... | ||
1151 | call mii_rw |
1164 | call mii_rw |
1152 | 1165 | ||
Line 1153... | Line 1166... | ||
1153 | test eax, PHY_GIGABIT |
1166 | test eax, PHY_GIGABIT |
1154 | jnz .gigabit |
1167 | jnz .gigabit |
1155 | mov [device.gigabit], 0 |
1168 | mov [ebx + device.gigabit], 0 |
Line 1178... | Line 1191... | ||
1178 | call mii_rw |
1191 | call mii_rw |
Line 1179... | Line 1192... | ||
1179 | 1192 | ||
1180 | test eax, eax |
1193 | test eax, eax |
Line 1181... | Line 1194... | ||
1181 | jz .next_if |
1194 | jz .next_if |
Line 1182... | Line 1195... | ||
1182 | 1195 | ||
1183 | DEBUGF 1,"phy init failed.\n" |
1196 | DEBUGF 2,"phy init failed.\n" |
Line 1184... | Line 1197... | ||
1184 | 1197 | ||
Line 1185... | Line 1198... | ||
1185 | mov eax, PHY_ERROR |
1198 | mov eax, PHY_ERROR |
1186 | jmp .return |
1199 | jmp .return |
1187 | 1200 | ||
Line 1188... | Line 1201... | ||
1188 | .next_if: |
1201 | .next_if: |
Line 1189... | Line 1202... | ||
1189 | 1202 | ||
1190 | call phy_reset |
1203 | call phy_reset |
1191 | test eax, eax |
1204 | test eax, eax |
Line 1192... | Line 1205... | ||
1192 | jz @f |
1205 | jz @f |
1193 | 1206 | ||
1194 | DEBUGF 1,"phy reset failed.\n" |
1207 | DEBUGF 2,"phy reset failed.\n" |
1195 | 1208 | ||
1196 | mov eax, PHY_ERROR |
1209 | mov eax, PHY_ERROR |
Line 1197... | Line 1210... | ||
1197 | jmp .return |
1210 | jmp .return |
Line 1214... | Line 1227... | ||
1214 | call mii_rw |
1227 | call mii_rw |
Line 1215... | Line 1228... | ||
1215 | 1228 | ||
1216 | test eax, eax |
1229 | test eax, eax |
Line 1217... | Line 1230... | ||
1217 | jz @f |
1230 | jz @f |
Line 1218... | Line 1231... | ||
1218 | 1231 | ||
1219 | DEBUGF 1,"phy init failed.\n" |
1232 | DEBUGF 2,"phy init failed.\n" |
1220 | 1233 | ||
Line 1231... | Line 1244... | ||
1231 | mov eax, MII_NCONFIG |
1244 | mov eax, MII_NCONFIG |
1232 | call mii_rw |
1245 | call mii_rw |
1233 | test eax, eax |
1246 | test eax, eax |
1234 | jz .next_if2 |
1247 | jz .next_if2 |
Line 1235... | Line 1248... | ||
1235 | 1248 | ||
Line 1236... | Line 1249... | ||
1236 | DEBUGF 1,"phy init failed.\n" |
1249 | DEBUGF 2,"phy init failed.\n" |
1237 | 1250 | ||
Line 1238... | Line 1251... | ||
1238 | mov eax, PHY_ERROR |
1251 | mov eax, PHY_ERROR |
Line 1239... | Line 1252... | ||
1239 | jmp .return |
1252 | jmp .return |
1240 | 1253 | ||
Line 1241... | Line 1254... | ||
1241 | 1254 | ||
1242 | 1255 | ||
1243 | .next_if2: |
1256 | .next_if2: |
Line 1254... | Line 1267... | ||
1254 | mov eax, MII_SREVISION |
1267 | mov eax, MII_SREVISION |
1255 | call mii_rw |
1268 | call mii_rw |
1256 | test eax, eax |
1269 | test eax, eax |
1257 | jz .restart |
1270 | jz .restart |
Line 1258... | Line 1271... | ||
1258 | 1271 | ||
Line 1259... | Line 1272... | ||
1259 | DEBUGF 1,"phy init failed.\n" |
1272 | DEBUGF 2,"phy init failed.\n" |
Line 1260... | Line 1273... | ||
1260 | 1273 | ||
1261 | jmp .return |
1274 | jmp .return |
Line 1291... | Line 1304... | ||
1291 | 1304 | ||
Line 1292... | Line 1305... | ||
1292 | DEBUGF 1,"phy_reset\n" |
1305 | DEBUGF 1,"phy_reset\n" |
Line 1293... | Line 1306... | ||
1293 | 1306 | ||
1294 | push ebx ecx edx |
1307 | push ebx ecx edx |
1295 | 1308 | ||
1296 | mov edx, [device.phyaddr] |
1309 | mov edx, [ebx + device.phyaddr] |
Line 1297... | Line 1310... | ||
1297 | mov eax, MII_BMCR |
1310 | mov eax, MII_BMCR |
Line 1313... | Line 1326... | ||
1313 | @@: |
1326 | @@: |
Line 1314... | Line 1327... | ||
1314 | 1327 | ||
Line 1315... | Line 1328... | ||
1315 | pop eax |
1328 | pop eax |
1316 | 1329 | ||
Line 1317... | Line 1330... | ||
1317 | mov esi, 500 |
1330 | mov esi, 500 |
1318 | call Sleep |
1331 | invoke Sleep |
1319 | 1332 | ||
1320 | ; must wait till reset is deasserted |
1333 | ; must wait till reset is deasserted |
1321 | mov esi, 100 ; FIXME: 100 tries seem excessive |
1334 | mov esi, 100 ; FIXME: 100 tries seem excessive |
Line 1322... | Line 1335... | ||
1322 | .while_loop: |
1335 | .while_loop: |
1323 | test eax, BMCR_RESET |
1336 | test eax, BMCR_RESET |
1324 | jz .while_loop_exit |
1337 | jz .while_loop_exit |
1325 | 1338 | ||
Line 1326... | Line 1339... | ||
1326 | push esi |
1339 | push esi |
1327 | mov esi, 10 |
1340 | mov esi, 10 |
1328 | call Sleep |
1341 | invoke Sleep |
Line 1363... | Line 1376... | ||
1363 | 1376 | ||
Line 1364... | Line 1377... | ||
1364 | push esi edi |
1377 | push esi edi |
Line 1365... | Line 1378... | ||
1365 | 1378 | ||
1366 | DEBUGF 1,"mac_reset.\n" |
1379 | DEBUGF 1,"mac_reset.\n" |
1367 | 1380 | ||
1368 | mov edi, [device.mmio_addr] |
1381 | mov edi, [ebx + device.mmio_addr] |
1369 | mov eax, [device.desc_ver] |
1382 | mov eax, [ebx + device.desc_ver] |
Line 1370... | Line 1383... | ||
1370 | or eax, (TXRXCTL_BIT2 or TXRXCTL_RESET) |
1383 | or eax, (TXRXCTL_BIT2 or TXRXCTL_RESET) |
1371 | mov [TxRxControl], eax |
1384 | mov [TxRxControl], eax |
Line 1372... | Line 1385... | ||
1372 | call pci_push |
1385 | call pci_push |
1373 | 1386 | ||
Line 1374... | Line 1387... | ||
1374 | mov [MacReset], MAC_RESET_ASSERT |
1387 | mov [MacReset], MAC_RESET_ASSERT |
1375 | call pci_push |
1388 | call pci_push |
Line 1376... | Line 1389... | ||
1376 | 1389 | ||
1377 | mov esi, NV_MAC_RESET_DELAY |
1390 | mov esi, NV_MAC_RESET_DELAY |
Line 1378... | Line 1391... | ||
1378 | call Sleep |
1391 | invoke Sleep |
1379 | 1392 | ||
1380 | mov [MacReset], 0 |
1393 | mov [MacReset], 0 |
1381 | call pci_push |
1394 | call pci_push |
Line 1382... | Line 1395... | ||
1382 | 1395 | ||
Line 1383... | Line 1396... | ||
1383 | mov esi, NV_MAC_RESET_DELAY |
1396 | mov esi, NV_MAC_RESET_DELAY |
Line 1384... | Line -... | ||
1384 | call Sleep |
- | |
1385 | - | ||
1386 | mov eax, [device.desc_ver] |
1397 | invoke Sleep |
1387 | or eax, TXRXCTL_BIT2 |
1398 | |
Line 1388... | Line 1399... | ||
1388 | mov [TxRxControl], eax |
1399 | mov eax, [ebx + device.desc_ver] |
1389 | call pci_push |
1400 | or eax, TXRXCTL_BIT2 |
Line -... | Line 1401... | ||
- | 1401 | mov [TxRxControl], eax |
|
1390 | 1402 | call pci_push |
|
Line 1391... | Line 1403... | ||
1391 | pop edi esi |
1403 | |
1392 | 1404 | pop edi esi |
|
1393 | ret |
1405 | |
1394 | 1406 | ret |
|
- | 1407 | ||
1395 | 1408 | ||
1396 | 1409 | ||
1397 | 1410 | align 4 |
|
Line -... | Line 1411... | ||
- | 1411 | init_ring: |
|
1398 | 1412 | ||
Line 1399... | Line 1413... | ||
1399 | align 4 |
1413 | DEBUGF 1,"init rings\n" |
1400 | init_ring: |
1414 | push eax esi ecx |
1401 | 1415 | ||
1402 | DEBUGF 1,"init rings\n" |
1416 | mov [ebx + device.cur_tx], 0 |
1403 | push eax esi ecx |
1417 | mov [ebx + device.last_tx], 0 |
1404 | 1418 | ||
1405 | mov [device.next_tx], 0 |
1419 | mov ecx, TX_RING |
1406 | 1420 | lea esi, [ebx + device.tx_ring] |
|
1407 | mov ecx, TX_RING |
1421 | .tx_loop: |
1408 | lea esi, [device.tx_ring] |
1422 | mov [esi + TxDesc.FlagLen], 0 |
1409 | .tx_loop: |
1423 | mov [esi + TxDesc.PacketBuffer], 0 |
1410 | mov [esi + TxDesc.FlagLen], 0 |
1424 | add esi, sizeof.TxDesc |
1411 | add esi, sizeof.TxDesc |
1425 | dec ecx |
Line 1444... | Line 1458... | ||
1444 | 1458 | ||
Line 1445... | Line 1459... | ||
1445 | push eax esi |
1459 | push eax esi |
Line 1446... | Line 1460... | ||
1446 | 1460 | ||
1447 | DEBUGF 1,"txrx_reset\n" |
1461 | DEBUGF 1,"txrx_reset\n" |
1448 | 1462 | ||
1449 | mov edi, [device.mmio_addr] |
1463 | mov edi, [ebx + device.mmio_addr] |
1450 | mov eax, [device.desc_ver] |
1464 | mov eax, [ebx + device.desc_ver] |
Line 1451... | Line 1465... | ||
1451 | or eax, (TXRXCTL_BIT2 or TXRXCTL_RESET) |
1465 | or eax, (TXRXCTL_BIT2 or TXRXCTL_RESET) |
1452 | mov [TxRxControl], eax |
1466 | mov [TxRxControl], eax |
Line 1453... | Line 1467... | ||
1453 | call pci_push |
1467 | call pci_push |
1454 | 1468 | ||
1455 | mov esi, NV_TXRX_RESET_DELAY |
1469 | mov esi, NV_TXRX_RESET_DELAY |
1456 | call Sleep |
1470 | invoke Sleep |
Line 1457... | Line 1471... | ||
1457 | 1471 | ||
Line 1493... | Line 1507... | ||
1493 | ; addr[0] |= MCASTADDRA_FORCE; |
1507 | ; addr[0] |= MCASTADDRA_FORCE; |
1494 | ; pff |= PFF_ALWAYS; |
1508 | ; pff |= PFF_ALWAYS; |
Line 1495... | Line 1509... | ||
1495 | 1509 | ||
Line 1496... | Line 1510... | ||
1496 | call stop_rx |
1510 | call stop_rx |
1497 | 1511 | ||
Line 1498... | Line 1512... | ||
1498 | mov edi, [device.mmio_addr] |
1512 | mov edi, [ebx + device.mmio_addr] |
1499 | mov [MulticastAddrA], MCASTADDRA_FORCE |
1513 | mov [MulticastAddrA], MCASTADDRA_FORCE |
1500 | 1514 | ||
Line 1518... | Line 1532... | ||
1518 | push edi |
1532 | push edi |
Line 1519... | Line 1533... | ||
1519 | 1533 | ||
Line 1520... | Line 1534... | ||
1520 | DEBUGF 1,"start_rx\n" |
1534 | DEBUGF 1,"start_rx\n" |
1521 | 1535 | ||
1522 | ; Already running? Stop it. |
1536 | ; Already running? Stop it. |
1523 | mov edi, [device.mmio_addr] |
1537 | mov edi, [ebx + device.mmio_addr] |
1524 | mov eax, [ReceiverControl] |
1538 | mov eax, [ReceiverControl] |
1525 | test eax, RCVCTL_START |
1539 | test eax, RCVCTL_START |
1526 | jz @f |
1540 | jz @f |
1527 | mov [ReceiverControl], 0 |
1541 | mov [ReceiverControl], 0 |
Line 1528... | Line 1542... | ||
1528 | call pci_push |
1542 | call pci_push |
1529 | @@: |
1543 | @@: |
1530 | 1544 | ||
Line 1531... | Line 1545... | ||
1531 | mov eax, [device.linkspeed] |
1545 | mov eax, [ebx + device.linkspeed] |
1532 | mov [LinkSpeed], eax |
1546 | mov [LinkSpeed], eax |
Line 1548... | Line 1562... | ||
1548 | 1562 | ||
Line 1549... | Line 1563... | ||
1549 | push esi edi |
1563 | push esi edi |
Line 1550... | Line 1564... | ||
1550 | 1564 | ||
1551 | DEBUGF 1,"stop_rx.\n" |
1565 | DEBUGF 1,"stop_rx.\n" |
Line 1552... | Line 1566... | ||
1552 | 1566 | ||
1553 | mov edi, [device.mmio_addr] |
1567 | mov edi, [ebx + device.mmio_addr] |
1554 | mov [ReceiverControl], 0 |
1568 | mov [ReceiverControl], 0 |
Line 1555... | Line 1569... | ||
1555 | 1569 | ||
1556 | push ebx edx edi |
1570 | push ebx edx edi |
Line 1557... | Line 1571... | ||
1557 | stdcall reg_delay, ReceiverStatus-edi, RCVSTAT_BUSY, 0, NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, 0 |
1571 | stdcall reg_delay, ReceiverStatus-edi, RCVSTAT_BUSY, 0, NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, 0 |
Line 1558... | Line 1572... | ||
1558 | pop edi edx ebx |
1572 | pop edi edx ebx |
Line 1575... | Line 1589... | ||
1575 | 1589 | ||
Line 1576... | Line 1590... | ||
1576 | DEBUGF 1,"update linkspeed\n" |
1590 | DEBUGF 1,"update linkspeed\n" |
Line 1577... | Line 1591... | ||
1577 | 1591 | ||
1578 | ; BMSR_LSTATUS is latched, read it twice: we want the current value. |
1592 | ; BMSR_LSTATUS is latched, read it twice: we want the current value. |
1579 | 1593 | ||
1580 | mov edx, [device.phyaddr] |
1594 | mov edx, [ebx + device.phyaddr] |
Line 1581... | Line 1595... | ||
1581 | mov eax, MII_BMSR |
1595 | mov eax, MII_BMSR |
1582 | mov ecx, MII_READ |
1596 | mov ecx, MII_READ |
1583 | call mii_rw |
1597 | call mii_rw |
Line 1584... | Line 1598... | ||
1584 | 1598 | ||
1585 | mov eax, MII_BMSR |
1599 | mov eax, MII_BMSR |
Line -... | Line 1600... | ||
- | 1600 | mov ecx, MII_READ |
|
- | 1601 | call mii_rw |
|
1586 | mov ecx, MII_READ |
1602 | |
1587 | call mii_rw |
1603 | test ax, BMSR_LSTATUS ; Link up? |
Line -... | Line 1604... | ||
- | 1604 | jz .no_link |
|
- | 1605 | ||
1588 | 1606 | DEBUGF 1,"link is up\n" |
|
1589 | test eax, BMSR_LSTATUS ; Link up? |
1607 | |
Line 1590... | Line 1608... | ||
1590 | jz .10mbit_hd |
1608 | test ax, BMSR_ANEGCOMPLETE ; still in autonegotiation? |
1591 | 1609 | jz .10mbit_hd |
|
1592 | test eax, BMSR_ANEGCOMPLETE ; still in autonegotiation? |
1610 | |
1593 | jz .10mbit_hd |
1611 | DEBUGF 1,"autonegotiation is complete\n" |
1594 | 1612 | ||
Line 1595... | Line 1613... | ||
1595 | cmp [device.gigabit], PHY_GIGABIT |
1613 | cmp [ebx + device.gigabit], PHY_GIGABIT |
1596 | jne .no_gigabit |
1614 | jne .no_gigabit |
1597 | 1615 | ||
1598 | ;mov edx, [device.phyaddr] |
1616 | ;mov edx, [ebx + device.phyaddr] |
1599 | mov eax, MII_1000BT_CR |
1617 | mov eax, MII_1000BT_CR |
Line 1611... | Line 1629... | ||
1611 | jz .no_gigabit |
1629 | jz .no_gigabit |
1612 | test ecx, ADVERTISE_1000FULL |
1630 | test ecx, ADVERTISE_1000FULL |
1613 | jz .no_gigabit |
1631 | jz .no_gigabit |
Line 1614... | Line 1632... | ||
1614 | 1632 | ||
- | 1633 | DEBUGF 1,"update_linkspeed: GBit ethernet detected.\n" |
|
1615 | DEBUGF 1,"update_linkspeed: GBit ethernet detected.\n" |
1634 | mov [ebx + device.state], ETH_LINK_1G |
1616 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_1000) |
1635 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_1000) |
1617 | xor eax, eax |
1636 | xor eax, eax |
1618 | inc eax |
1637 | inc eax |
1619 | jmp set_speed |
1638 | jmp set_speed |
Line 1620... | Line 1639... | ||
1620 | .no_gigabit: |
1639 | .no_gigabit: |
1621 | 1640 | ||
1622 | ;mov edx, [device.phyaddr] |
1641 | ;mov edx, [ebx + device.phyaddr] |
1623 | mov eax, MII_ADVERTISE |
1642 | mov eax, MII_ADVERTISE |
1624 | mov ecx, MII_READ |
1643 | mov ecx, MII_READ |
Line 1625... | Line 1644... | ||
1625 | call mii_rw ; adv = eax |
1644 | call mii_rw ; adv = eax |
1626 | push eax |
1645 | push eax |
1627 | 1646 | ||
1628 | ;mov edx, [device.phyaddr] |
1647 | ;mov edx, [ebx + device.phyaddr] |
1629 | mov eax, MII_LPA |
1648 | mov eax, MII_LPA |
Line 1630... | Line 1649... | ||
1630 | mov ecx, MII_READ |
1649 | mov ecx, MII_READ |
1631 | call mii_rw ; lpa = eax |
1650 | call mii_rw ; lpa = eax |
Line 1632... | Line 1651... | ||
1632 | pop ecx |
1651 | pop ecx |
1633 | 1652 | ||
1634 | DEBUGF 1,"PHY advertises 0x%x, lpa 0x%x\n", ecx, eax |
1653 | DEBUGF 1,"PHY advertises 0x%x, lpa 0x%x\n", cx, ax |
- | 1654 | and eax, ecx ; FIXME: handle parallel detection properly, handle gigabit ethernet |
|
1635 | and eax, ecx ; FIXME: handle parallel detection properly, handle gigabit ethernet |
1655 | |
1636 | 1656 | test eax, LPA_100FULL |
|
1637 | test eax, LPA_100FULL |
1657 | jz @f |
1638 | jz @f |
1658 | DEBUGF 1,"update_linkspeed: 100 mbit full duplex\n" |
1639 | DEBUGF 1,"update_linkspeed: 100 mbit full duplex\n" |
1659 | mov [ebx + device.state], ETH_LINK_100M + ETH_LINK_FD |
Line 1640... | Line 1660... | ||
1640 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_100) |
1660 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_100) |
1641 | xor eax, eax |
1661 | xor eax, eax |
1642 | inc eax |
1662 | inc eax |
- | 1663 | jmp set_speed |
|
1643 | jmp set_speed |
1664 | @@: |
1644 | @@: |
1665 | |
1645 | 1666 | test eax, LPA_100HALF |
|
1646 | test eax, LPA_100HALF |
1667 | jz @f |
Line 1647... | Line 1668... | ||
1647 | jz @f |
1668 | DEBUGF 1,"update_linkspeed: 100 mbit half duplex\n" |
1648 | DEBUGF 1,"update_linkspeed: 100 mbit half duplex\n" |
1669 | mov [ebx + device.state], ETH_LINK_100M |
1649 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_100) |
1670 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_100) |
- | 1671 | xor eax, eax |
|
1650 | xor eax, eax |
1672 | jmp set_speed |
1651 | jmp set_speed |
1673 | @@: |
1652 | @@: |
1674 | |
1653 | 1675 | test eax, LPA_10FULL |
|
1654 | test eax, LPA_10FULL |
1676 | jz @f |
Line 1655... | Line 1677... | ||
1655 | jz @f |
1677 | DEBUGF 1,"update_linkspeed: 10 mbit full duplex\n" |
1656 | DEBUGF 1,"update_linkspeed: 10 mbit full duplex\n" |
1678 | mov [ebx + device.state], ETH_LINK_10M + ETH_LINK_FD |
- | 1679 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_10) |
|
- | 1680 | xor eax, eax |
|
- | 1681 | inc eax |
|
- | 1682 | jmp set_speed |
|
- | 1683 | @@: |
|
- | 1684 | ||
- | 1685 | .10mbit_hd: |
|
- | 1686 | DEBUGF 1,"update_linkspeed: 10 mbit half duplex\n" |
|
1657 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_10) |
1687 | mov [ebx + device.state], ETH_LINK_10M |
1658 | xor eax, eax |
1688 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_10) |
1659 | inc eax |
1689 | xor eax, eax |
Line 1660... | Line 1690... | ||
1660 | jmp set_speed |
1690 | jmp set_speed |
1661 | @@: |
1691 | |
Line 1662... | Line 1692... | ||
1662 | 1692 | .no_link: |
|
1663 | .10mbit_hd: |
1693 | DEBUGF 1,"update_linkspeed: link is down\n" |
1664 | DEBUGF 1,"update_linkspeed: 10 mbit half duplex\n" |
1694 | mov [ebx + device.state], ETH_LINK_DOWN |
1665 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_10) |
1695 | mov ecx, (LINKSPEED_FORCE or LINKSPEED_10) |
Line 1666... | Line 1696... | ||
1666 | xor eax, eax |
1696 | xor eax, eax |
Line 1667... | Line 1697... | ||
1667 | jmp set_speed |
1697 | jmp set_speed |
1668 | 1698 | ||
Line 1669... | Line 1699... | ||
1669 | 1699 | ||
1670 | align 4 |
1700 | align 4 |
Line 1671... | Line 1701... | ||
1671 | set_speed: |
1701 | set_speed: |
1672 | 1702 | ||
Line 1673... | Line 1703... | ||
1673 | cmp eax, [device.duplex] |
1703 | cmp eax, [ebx + device.duplex] |
1674 | jne .update |
1704 | jne .update |
Line 1675... | Line 1705... | ||
1675 | cmp ecx, [device.linkspeed] |
1705 | cmp ecx, [ebx + device.linkspeed] |
1676 | jne .update |
1706 | jne .update |
Line 1677... | Line 1707... | ||
1677 | 1707 | ||
1678 | ret |
1708 | ret |
1679 | 1709 | ||
1680 | .update: |
1710 | .update: |
1681 | DEBUGF 1,"update_linkspeed: changing link to 0x%x/XD.\n", ecx |
1711 | DEBUGF 1,"update_linkspeed: changing link to 0x%x/XD.\n", ecx |
1682 | 1712 | ||
Line 1714... | Line 1744... | ||
1714 | .no_gigabit: |
1744 | .no_gigabit: |
Line 1715... | Line 1745... | ||
1715 | 1745 | ||
1716 | mov ecx, [PhyInterface] |
1746 | mov ecx, [PhyInterface] |
Line 1717... | Line 1747... | ||
1717 | and ecx, not (PHY_HALF or PHY_100 or PHY_1000) |
1747 | and ecx, not (PHY_HALF or PHY_100 or PHY_1000) |
1718 | 1748 | ||
1719 | cmp [device.duplex], 0 |
1749 | cmp [ebx + device.duplex], 0 |
1720 | jne @f |
1750 | jne @f |
Line 1721... | Line 1751... | ||
1721 | or ecx, PHY_HALF |
1751 | or ecx, PHY_HALF |
1722 | @@: |
1752 | @@: |
1723 | 1753 | ||
1724 | mov eax, [device.linkspeed] |
1754 | mov eax, [ebx + device.linkspeed] |
1725 | and eax, 0xFFF |
1755 | and eax, 0xFFF |
1726 | cmp eax, LINKSPEED_100 |
1756 | cmp eax, LINKSPEED_100 |
Line 1734... | Line 1764... | ||
1734 | or ecx, PHY_1000 |
1764 | or ecx, PHY_1000 |
Line 1735... | Line 1765... | ||
1735 | 1765 | ||
1736 | .end_if5: |
1766 | .end_if5: |
Line 1737... | Line 1767... | ||
1737 | mov [PhyInterface], ecx |
1767 | mov [PhyInterface], ecx |
1738 | 1768 | ||
1739 | cmp [device.duplex], 0 |
1769 | cmp [ebx + device.duplex], 0 |
1740 | je @f |
1770 | je @f |
1741 | xor ecx, ecx |
1771 | xor ecx, ecx |
Line 1747... | Line 1777... | ||
1747 | or ecx, MISC1_FORCE |
1777 | or ecx, MISC1_FORCE |
1748 | mov [Misc1], ecx |
1778 | mov [Misc1], ecx |
Line 1749... | Line 1779... | ||
1749 | 1779 | ||
Line 1750... | Line 1780... | ||
1750 | call pci_push |
1780 | call pci_push |
1751 | 1781 | ||
Line 1752... | Line 1782... | ||
1752 | mov eax, [device.linkspeed] |
1782 | mov eax, [ebx + device.linkspeed] |
Line 1753... | Line 1783... | ||
1753 | mov [LinkSpeed], eax |
1783 | mov [LinkSpeed], eax |
Line 1762... | Line 1792... | ||
1762 | 1792 | ||
1763 | 1793 | ||
Line 1764... | Line 1794... | ||
1764 | align 4 |
1794 | align 4 |
1765 | read_mac: |
- | |
1766 | 1795 | read_mac: |
|
1767 | mov edi, [device.mmio_addr] |
1796 | |
Line 1768... | Line 1797... | ||
1768 | 1797 | mov edi, [ebx + device.mmio_addr] |
|
1769 | mov eax, [MacAddrA] |
1798 | mov eax, [MacAddrA] |
Line 1770... | Line 1799... | ||
1770 | mov ecx, [MacAddrB] |
1799 | mov ecx, [MacAddrB] |
1771 | 1800 | ||
1772 | mov dword [device.mac], eax |
1801 | mov dword [ebx + device.mac], eax |
1773 | mov word [device.mac + 4], cx |
1802 | mov word [ebx + device.mac + 4], cx |
1774 | 1803 | ||
1775 | cmp [device.device_id], 0x03E5 |
1804 | cmp [ebx + device.device_id], 0x03E5 |
1776 | jae @f |
1805 | jae @f |
Line 1777... | Line 1806... | ||
1777 | bswap eax |
1806 | bswap eax |
1778 | xchg cl, ch |
1807 | xchg cl, ch |
Line 1779... | Line 1808... | ||
1779 | mov dword [device.mac + 2], eax |
1808 | mov dword [ebx + device.mac + 2], eax |
Line 1794... | Line 1823... | ||
1794 | ;; In: buffer pointer in [esp+4] ;; |
1823 | ;; In: buffer pointer in [esp+4] ;; |
1795 | ;; size of buffer in [esp+8] ;; |
1824 | ;; size of buffer in [esp+8] ;; |
1796 | ;; pointer to device structure in ebx ;; |
1825 | ;; pointer to device structure in ebx ;; |
1797 | ;; ;; |
1826 | ;; ;; |
1798 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1827 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | 1828 | ||
- | 1829 | proc transmit stdcall bufferptr, buffersize |
|
- | 1830 | ||
1799 | align 4 |
1831 | pushf |
1800 | transmit: |
1832 | cli |
- | 1833 | ||
1801 | DEBUGF 2,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
1834 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
1802 | mov eax, [esp+4] |
1835 | mov eax, [bufferptr] |
1803 | DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1836 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1804 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1837 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
1805 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1838 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1806 | [eax+13]:2,[eax+12]:2 |
1839 | [eax+13]:2,[eax+12]:2 |
Line 1807... | Line 1840... | ||
1807 | 1840 | ||
1808 | cmp dword [esp + 8], 1514 |
1841 | cmp [buffersize], 1514 |
1809 | ja .fail |
1842 | ja .fail |
1810 | cmp dword [esp + 8], 60 |
1843 | cmp [buffersize], 60 |
Line 1811... | Line 1844... | ||
1811 | jb .fail |
1844 | jb .fail |
1812 | 1845 | ||
1813 | ; get the descriptor address |
1846 | ; get the descriptor address |
1814 | mov eax, [device.next_tx] |
- | |
1815 | mov cl, sizeof.TxDesc |
1847 | mov eax, [ebx + device.cur_tx] |
- | 1848 | shl eax, 3 ; TX descriptor is 8 bytes. |
|
1816 | mul cl |
1849 | lea esi, [ebx + device.tx_ring + eax] |
1817 | lea esi, [device.tx_ring + eax] |
1850 | |
1818 | mov eax, [esp + 4] |
1851 | mov eax, [bufferptr] |
1819 | mov [esi + TX_RING*sizeof.TxDesc], eax |
1852 | mov [esi + TX_RING*sizeof.TxDesc], eax |
Line 1820... | Line 1853... | ||
1820 | GetRealAddr |
1853 | invoke GetPhysAddr ; Does not change esi/ebx :) |
1821 | mov [esi + TxDesc.PacketBuffer], eax |
1854 | mov [esi + TxDesc.PacketBuffer], eax |
1822 | 1855 | ||
Line 1823... | Line 1856... | ||
1823 | mov ecx, [esp + 8] |
1856 | mov eax, [buffersize] |
1824 | or ecx, [device.txflags] |
1857 | or eax, [ebx + device.txflags] |
1825 | mov [esi + TxDesc.FlagLen], eax |
1858 | mov [esi + TxDesc.FlagLen], eax |
1826 | 1859 | ||
Line 1827... | Line 1860... | ||
1827 | mov edi, [device.mmio_addr] |
1860 | mov edi, [ebx + device.mmio_addr] |
Line 1828... | Line 1861... | ||
1828 | mov eax, [device.desc_ver] |
1861 | mov eax, [ebx + device.desc_ver] |
1829 | or eax, TXRXCTL_KICK |
1862 | or eax, TXRXCTL_KICK |
Line 1830... | Line 1863... | ||
1830 | mov [TxRxControl], eax |
1863 | mov [TxRxControl], eax |
1831 | 1864 | ||
1832 | call pci_push |
1865 | call pci_push |
1833 | 1866 | ||
1834 | inc [device.next_tx] |
1867 | inc [ebx + device.cur_tx] |
Line 1835... | Line 1868... | ||
1835 | and [device.next_tx], (TX_RING-1) |
1868 | and [ebx + device.cur_tx], (TX_RING-1) |
- | 1869 | ||
1836 | 1870 | ; Update stats |
|
Line 1837... | Line 1871... | ||
1837 | ; Update stats |
1871 | inc [ebx + device.packets_tx] |
- | 1872 | mov eax, [buffersize] |
|
1838 | inc [device.packets_tx] |
1873 | add dword[ebx + device.bytes_tx], eax |
- | 1874 | adc dword[ebx + device.bytes_tx + 4], 0 |
|
1839 | mov eax, [esp + 8] |
1875 | |
1840 | add dword [device.bytes_tx], eax |
1876 | xor eax, eax |
- | 1877 | popf |
|
- | 1878 | ret |
|
Line 1857... | Line 1895... | ||
1857 | align 4 |
1895 | align 4 |
1858 | int_handler: |
1896 | int_handler: |
Line 1859... | Line 1897... | ||
1859 | 1897 | ||
Line 1860... | Line 1898... | ||
1860 | push ebx esi edi |
1898 | push ebx esi edi |
Line 1861... | Line 1899... | ||
1861 | 1899 | ||
1862 | DEBUGF 2,"INT\n" |
1900 | DEBUGF 1,"INT\n" |
Line 1863... | Line 1901... | ||
1863 | 1901 | ||
Line 1870... | Line 1908... | ||
1870 | jz .fail |
1908 | jz .fail |
1871 | .nextdevice: |
1909 | .nextdevice: |
1872 | mov ebx, dword [esi] |
1910 | mov ebx, dword [esi] |
1873 | add esi, 4 |
1911 | add esi, 4 |
Line 1874... | Line 1912... | ||
1874 | 1912 | ||
1875 | mov edi, [device.mmio_addr] |
1913 | mov edi, [ebx + device.mmio_addr] |
1876 | mov eax, [IrqStatus] |
1914 | mov eax, [IrqStatus] |
1877 | test eax, eax |
1915 | test eax, eax |
1878 | jnz .got_it |
1916 | jnz .got_it |
1879 | dec ecx |
1917 | dec ecx |
Line 1884... | Line 1922... | ||
1884 | 1922 | ||
Line 1885... | Line 1923... | ||
1885 | ret |
1923 | ret |
1886 | 1924 | ||
1887 | .got_it: |
1925 | .got_it: |
Line 1888... | Line 1926... | ||
1888 | mov [IrqStatus], eax |
1926 | mov [IrqStatus], eax |
1889 | DEBUGF 2,"IrqStatus = %x\n", eax |
1927 | DEBUGF 1,"IrqStatus = %x\n", eax |
Line -... | Line 1928... | ||
- | 1928 | ||
1890 | 1929 | test eax, IRQ_RX ;+ IRQ_TIMER ;;;; |
|
- | 1930 | jz .no_rx |
|
1891 | test eax, IRQ_RX |
1931 | |
1892 | jz .no_rx |
1932 | push ebx |
1893 | 1933 | .more_rx: |
|
1894 | .top: |
1934 | pop ebx |
1895 | mov eax, [device.cur_rx] |
1935 | mov eax, [ebx + device.cur_rx] |
Line 1896... | Line 1936... | ||
1896 | mov cx, sizeof.RxDesc |
1936 | mov cx, sizeof.RxDesc |
1897 | mul cx |
1937 | mul cx |
Line 1898... | Line 1938... | ||
1898 | lea esi, [device.rx_ring + eax] |
1938 | lea esi, [ebx + device.rx_ring + eax] |
1899 | mov eax, [esi + RxDesc.FlagLen] |
1939 | mov eax, [esi + RxDesc.FlagLen] |
1900 | 1940 | ||
1901 | test eax, NV_RX_AVAIL ; still owned by hardware |
1941 | test eax, NV_RX_AVAIL ; still owned by hardware |
1902 | jnz .return0 |
1942 | jnz .no_rx |
1903 | 1943 | ||
1904 | cmp [device.desc_ver], DESC_VER_1 |
1944 | cmp [ebx + device.desc_ver], DESC_VER_1 |
1905 | jne @f |
1945 | jne @f |
Line 1906... | Line 1946... | ||
1906 | test eax, NV_RX_DESCRIPTORVALID |
1946 | test eax, NV_RX_DESCRIPTORVALID |
1907 | jz .return0 |
- | |
1908 | jmp .next |
1947 | jz .no_rx |
1909 | @@: |
1948 | jmp .next |
1910 | test eax, NV_RX2_DESCRIPTORVALID |
1949 | @@: |
1911 | jz .return0 |
1950 | test eax, NV_RX2_DESCRIPTORVALID |
1912 | 1951 | jz .no_rx |
|
1913 | .next: |
1952 | |
- | 1953 | .next: |
|
1914 | 1954 | cmp dword[ebx + device.desc_ver], DESC_VER_1 |
|
- | 1955 | jne @f |
|
Line 1915... | Line 1956... | ||
1915 | cmp dword [device.desc_ver], DESC_VER_1 |
1956 | and eax, LEN_MASK_V1 |
1916 | jne @f |
1957 | jmp .next2 |
1917 | and eax, LEN_MASK_V1 |
1958 | @@: |
1918 | jmp .next2 |
1959 | and eax, LEN_MASK_V2 |
Line -... | Line 1960... | ||
- | 1960 | ||
1919 | @@: |
1961 | .next2: |
1920 | and eax, LEN_MASK_V2 |
1962 | DEBUGF 1,"Received %u bytes\n", eax |
Line 1921... | Line 1963... | ||
1921 | .next2: |
1963 | |
- | 1964 | ; Update stats |
|
- | 1965 | add dword[ebx + device.bytes_rx], eax |
|
Line -... | Line 1966... | ||
- | 1966 | adc dword[ebx + device.bytes_rx + 4], 0 |
|
1922 | 1967 | inc dword[ebx + device.packets_rx] |
|
1923 | ; got a valid packet - forward it to the network core |
1968 | |
1924 | push .top |
1969 | ; Prepare to give packet to kernel |
1925 | push eax |
1970 | push ebx |
1926 | push dword [esi + RX_RING*sizeof.RxDesc] |
1971 | push .more_rx |
Line 1927... | Line 1972... | ||
1927 | 1972 | ||
1928 | inc [device.cur_rx] |
- | |
1929 | and [device.cur_rx], (RX_RING-1) |
1973 | push eax |
- | 1974 | push dword[esi + RX_RING*sizeof.RxDesc] |
|
Line -... | Line 1975... | ||
- | 1975 | DEBUGF 1,"packet ptr=0x%x\n", [esi + RX_RING*sizeof.RxDesc] |
|
Line 1930... | Line 1976... | ||
1930 | 1976 | ||
1931 | ; Allocate new buffer |
1977 | ; Allocate new buffer for this descriptor |
1932 | 1978 | invoke KernelAlloc, 4096 shl RBLEN |
|
Line 1933... | Line 1979... | ||
1933 | stdcall KernelAlloc, 4096 shl RBLEN |
1979 | mov [esi + RX_RING*sizeof.RxDesc], eax |
1934 | mov [esi + RX_RING*sizeof.RxDesc], eax |
1980 | invoke GetPhysAddr |
Line 1935... | Line 1981... | ||
1935 | GetRealAddr |
1981 | mov [esi + RxDesc.PacketBuffer], eax |
1936 | mov [esi + RxDesc.PacketBuffer], eax |
1982 | mov [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL) |
1937 | mov [esi + RxDesc.FlagLen], (4096 shl RBLEN or NV_RX_AVAIL) |
1983 | |
1938 | 1984 | ; update current RX descriptor |
|
1939 | jmp Eth_input |
1985 | inc [ebx + device.cur_rx] |
Line 1940... | Line 1986... | ||
1940 | 1986 | and [ebx + device.cur_rx], (RX_RING-1) |
|
Line 1941... | Line 1987... | ||
1941 | .return0: |
1987 | |
1942 | 1988 | jmp [Eth_input] |
|
Line 1943... | Line 1989... | ||
1943 | 1989 | ||
- | 1990 | .no_rx: |
|
- | 1991 | test eax, IRQ_RX_ERROR |
|
- | 1992 | jz .no_rx_err |
|
- | 1993 | ||
- | 1994 | push eax |
|
- | 1995 | DEBUGF 2,"RX error!\n" |
|
- | 1996 | ||
1944 | .no_rx: |
1997 | mov eax, [ebx + device.cur_rx] |
1945 | test eax, IRQ_RX_ERROR |
1998 | mov cx, sizeof.RxDesc |
Line 1946... | Line 1999... | ||
1946 | jz .no_rx_err |
1999 | mul cx |
1947 | 2000 | lea esi, [ebx + device.rx_ring + eax] |
|
1948 | push eax |
2001 | mov eax, [esi + RxDesc.FlagLen] |
Line 1949... | Line 2002... | ||
1949 | DEBUGF 2,"RX error!\n" |
2002 | |
- | 2003 | DEBUGF 1,"Flaglen=%x\n", eax |
|
- | 2004 | ||
- | 2005 | ; TODO: allocate new buff ? |
|
- | 2006 | pop eax |
|
1950 | 2007 | ||
- | 2008 | .no_rx_err: |
|
- | 2009 | test eax, IRQ_TX_ERROR |
|
- | 2010 | jz .no_tx_err |
|
- | 2011 | ||
- | 2012 | DEBUGF 2,"TX error!\n" |
|
- | 2013 | ; TODO |
|
- | 2014 | ||
- | 2015 | .no_tx_err: |
|
- | 2016 | test eax, IRQ_LINK |
|
- | 2017 | jz .no_link |
|
- | 2018 | ||
- | 2019 | push eax |
|
- | 2020 | call update_linkspeed |
|
- | 2021 | pop eax |
|
- | 2022 | ||
- | 2023 | .no_link: |
|
- | 2024 | test eax, IRQ_TX_OK |
|
Line -... | Line 2025... | ||
- | 2025 | jz .no_tx |
|
- | 2026 | ||
- | 2027 | DEBUGF 1, "TX completed\n" |
|
- | 2028 | .loop_tx: |
|
1951 | mov eax, [device.cur_rx] |
2029 | mov esi, [ebx + device.last_tx] |
1952 | mov cx, sizeof.RxDesc |
2030 | shl esi, 3 ; TX descriptor is 8 bytes. |
1953 | mul cx |
2031 | lea esi, [ebx + device.tx_ring + esi] |
Line 1954... | Line 2032... | ||
1954 | lea esi, [device.rx_ring + eax] |
2032 | |
Line 1955... | Line -... | ||
1955 | mov eax, [esi + RxDesc.FlagLen] |
- | |
1956 | - | ||
1957 | DEBUGF 2,"Flaglen=%x\n", eax |
2033 | DEBUGF 1,"Flaglen = 0x%x\n", [esi + TxDesc.FlagLen] |
Line 1958... | Line 2034... | ||
1958 | 2034 | test [esi + TxDesc.FlagLen], NV_TX_VALID |
|
- | 2035 | jnz .no_tx |
|
- | 2036 | cmp dword[esi + TX_RING*sizeof.TxDesc], 0 |
|
1959 | ; TODO: allocate new buff |
2037 | je .no_tx |
Line 1960... | Line -... | ||
1960 | pop eax |
- | |
1961 | - | ||
1962 | .no_rx_err: |
2038 | |
Line 1963... | Line 2039... | ||
1963 | test eax, IRQ_LINK |
2039 | DEBUGF 1,"Freeing buffer 0x%x\n", [esi + TX_RING*sizeof.TxDesc]:8 |
Line -... | Line 2040... | ||
- | 2040 | push dword[esi + TX_RING*sizeof.TxDesc] |
|
- | 2041 | mov dword[esi + TX_RING*sizeof.TxDesc], 0 |
|
1964 | jz .no_link |
2042 | invoke KernelFree |
- | 2043 |