Rev 5522 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5522 | Rev 9188 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;; 3Com network driver for KolibriOS ;; |
6 | ;; 3Com network driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Ported to KolibriOS net-branch by hidnplayr ;; |
8 | ;; Ported to KolibriOS net-branch by hidnplayr ;; |
Line 88... | Line 88... | ||
88 | 88 | ||
89 | CURRENT_API = 0x0200 |
89 | CURRENT_API = 0x0200 |
90 | COMPATIBLE_API = 0x0100 |
90 | COMPATIBLE_API = 0x0100 |
Line -... | Line 91... | ||
- | 91 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
|
- | 92 | ||
91 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
93 | ; configureable area |
- | 94 | ||
92 | 95 | MAX_DEVICES = 16 ; Maximum number of devices this driver may handle |
|
Line 93... | Line 96... | ||
93 | MAX_DEVICES = 16 |
96 | |
94 | FORCE_FD = 0 ; forcing full duplex mode makes sense at some cards and link types |
97 | FORCE_FD = 0 ; forcing full duplex mode makes sense at some cards and link types |
Line 95... | Line 98... | ||
95 | 98 | ||
96 | NUM_RX_DESC = 4 ; a power of 2 number |
99 | NUM_RX_DESC = 32 ; Number of receive descriptors (must be power of 2) |
Line -... | Line 100... | ||
- | 100 | NUM_TX_DESC = 16 ; Number of transmit descriptors (must be power of 2) |
|
- | 101 | ||
97 | NUM_TX_DESC = 4 ; a power of 2 number |
102 | __DEBUG__ = 1 ; 1 = on, 0 = off |
Line 98... | Line 103... | ||
98 | 103 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
|
99 | __DEBUG__ = 1 |
104 | |
100 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
105 | ; end configureable area |
101 | 106 | ||
102 | section '.flat' readable writable executable |
107 | section '.flat' readable writable executable |
Line -... | Line 108... | ||
- | 108 | ||
- | 109 | include '../proc32.inc' |
|
- | 110 | include '../struct.inc' |
|
- | 111 | include '../macros.inc' |
|
- | 112 | include '../fdo.inc' |
|
- | 113 | include '../netdrv.inc' |
|
- | 114 | ||
- | 115 | ||
- | 116 | if (bsr NUM_RX_DESC)>(bsf NUM_RX_DESC) |
|
- | 117 | display 'NUM_RX_DESC must be a power of two' |
|
- | 118 | err |
|
103 | 119 | end if |
|
104 | include '../proc32.inc' |
120 | |
105 | include '../struct.inc' |
121 | if (bsr NUM_TX_DESC)>(bsf NUM_TX_DESC) |
106 | include '../macros.inc' |
122 | display 'NUM_TX_DESC must be a power of two' |
107 | include '../fdo.inc' |
123 | err |
Line 400... | Line 416... | ||
400 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
416 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
401 | jne .fail ; other types of this hardware dont exist |
417 | jne .fail ; other types of this hardware dont exist |
Line 402... | Line 418... | ||
402 | 418 | ||
Line 403... | Line 419... | ||
403 | ; check if the device is already listed |
419 | ; check if the device is already listed |
404 | 420 | ||
405 | mov ecx, [vortex_devices] |
421 | mov ecx, [devices] |
Line 406... | Line 422... | ||
406 | test ecx, ecx |
422 | test ecx, ecx |
407 | jz .maybeboomerang |
423 | jz .firstdevice |
408 | 424 | ||
409 | mov esi, vortex_list |
425 | mov esi, device_list |
410 | mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
426 | mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
411 | mov ax , [eax+1] ; |
427 | mov ax , [eax+1] ; |
Line 417... | Line 433... | ||
417 | je .find_devicenum ; Device is already loaded, let's find it's device number |
433 | je .find_devicenum ; Device is already loaded, let's find it's device number |
418 | @@: |
434 | @@: |
419 | add esi, 4 |
435 | add esi, 4 |
420 | loop .nextdevice |
436 | loop .nextdevice |
Line 421... | Line -... | ||
421 | - | ||
422 | - | ||
423 | .maybeboomerang: |
- | |
424 | mov ecx, [boomerang_devices] |
- | |
425 | test ecx, ecx |
- | |
426 | jz .firstdevice |
- | |
427 | - | ||
428 | mov esi, boomerang_list |
- | |
429 | mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
- | |
430 | mov ax, [eax+1] ; |
- | |
431 | .nextdevice2: |
- | |
432 | mov ebx, [esi] |
- | |
433 | cmp al, byte[ebx + device.pci_bus] |
- | |
434 | jne @f |
- | |
435 | cmp ah, byte[ebx + device.pci_dev] |
- | |
436 | je .find_devicenum ; Device is already loaded, let's find it's device number |
- | |
437 | @@: |
- | |
438 | add esi, 4 |
- | |
439 | loop .nextdevice2 |
- | |
440 | - | ||
441 | 437 | ||
442 | ; This device doesnt have its own eth_device structure yet, lets create one |
438 | ; This device doesnt have its own eth_device structure yet, lets create one |
443 | .firstdevice: |
- | |
444 | mov ecx, [boomerang_devices] |
- | |
445 | add ecx, [vortex_devices] |
439 | .firstdevice: |
446 | cmp ecx, MAX_DEVICES ; First check if the driver can handle one more card |
440 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
Line 447... | Line 441... | ||
447 | jae .fail |
441 | jae .fail |
Line 448... | Line 442... | ||
448 | 442 | ||
Line 479... | Line 473... | ||
479 | ; Ok, the eth_device structure is ready, let's probe the device |
473 | ; Ok, the eth_device structure is ready, let's probe the device |
480 | call probe ; this function will output in eax |
474 | call probe ; this function will output in eax |
481 | test eax, eax |
475 | test eax, eax |
482 | jnz .err ; If an error occured, exit |
476 | jnz .err ; If an error occured, exit |
Line 483... | Line -... | ||
483 | - | ||
484 | - | ||
485 | movzx ecx, [ebx + device.ver_id] |
- | |
486 | test word [hw_versions+2+ecx*4], IS_VORTEX |
- | |
487 | jz .not_vortex |
- | |
488 | 477 | ||
489 | mov eax, [vortex_devices] ; Add the device structure to our device list |
478 | mov eax, [devices] ; Add the device structure to our device list |
490 | mov [vortex_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
479 | mov [device_list+4*eax], ebx ; |
Line 491... | Line 480... | ||
491 | inc [vortex_devices] ; |
480 | inc [devices] ; |
492 | 481 | ||
493 | .register: |
482 | .register: |
Line 498... | Line 487... | ||
498 | je .destroy |
487 | je .destroy |
Line 499... | Line 488... | ||
499 | 488 | ||
500 | call start_device |
489 | call start_device |
Line 501... | Line -... | ||
501 | ret |
- | |
502 | - | ||
503 | .not_vortex: |
- | |
504 | mov eax, [boomerang_devices] ; Add the device structure to our device list |
- | |
505 | mov [boomerang_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
- | |
506 | inc [boomerang_devices] |
- | |
507 | - | ||
508 | jmp .register |
490 | ret |
Line 509... | Line 491... | ||
509 | 491 | ||
510 | ; If the device was already loaded, find the device number and return it in eax |
492 | ; If the device was already loaded, find the device number and return it in eax |
511 | 493 | ||
Line 695... | Line 677... | ||
695 | set_io [ebx + device.io_addr], REG_COMMAND |
677 | set_io [ebx + device.io_addr], REG_COMMAND |
696 | xor eax, eax |
678 | xor eax, eax |
697 | ; or al, 0x14 |
679 | ; or al, 0x14 |
698 | out dx, ax |
680 | out dx, ax |
699 | ; wait for GlobalReset to complete |
681 | ; wait for GlobalReset to complete |
700 | mov ecx, 64000 |
682 | mov ecx, 2000 |
701 | .rsloop: |
683 | .rsloop: |
702 | in ax , dx |
684 | in ax, dx |
703 | test ah , 10000b ; CmdInProgress |
685 | test ah, 10000b ; CmdInProgress |
- | 686 | ||
- | 687 | pusha |
|
- | 688 | mov esi, 1 |
|
- | 689 | invoke Sleep |
|
- | 690 | popa |
|
- | 691 | ||
704 | loopz .rsloop |
692 | loopz .rsloop |
Line 705... | Line 693... | ||
705 | 693 | ||
706 | DEBUGF 1,"Waiting for nic to boot..\n" |
694 | DEBUGF 1,"Waiting for NIC to boot..\n" |
707 | ; wait for 2 seconds for NIC to boot |
695 | ; wait for 2 seconds for NIC to boot |
708 | mov esi, 2000 ; WTF? FIXME |
696 | mov esi, 2000 ; WTF? FIXME |
Line 709... | Line 697... | ||
709 | invoke Sleep ; 2 seconds |
697 | invoke Sleep ; 2 seconds |
Line 1138... | Line 1126... | ||
1138 | DEBUGF 1,"PHY=%u\n", ah |
1126 | DEBUGF 1,"PHY=%u\n", ah |
1139 | DEBUGF 1,"Detecting if device is auto-negotiation capable\n" |
1127 | DEBUGF 1,"Detecting if device is auto-negotiation capable\n" |
Line 1140... | Line 1128... | ||
1140 | 1128 | ||
1141 | mov al, MII_BMCR |
1129 | mov al, MII_BMCR |
1142 | push eax |
1130 | push eax |
1143 | call mdio_read ; returns with window #4 |
1131 | call mdio_read |
1144 | or ah, 0x80 ; software reset |
1132 | or ax, BMCR_RESET |
1145 | mov esi, eax |
1133 | mov esi, eax |
1146 | mov eax, [esp] |
1134 | mov eax, [esp] |
Line 1147... | Line 1135... | ||
1147 | call mdio_write ; returns with window #4 |
1135 | call mdio_write |
1148 | 1136 | ||
1149 | ; wait for reset to complete |
1137 | ; wait for reset to complete |
- | 1138 | mov esi, 2000 |
|
1150 | mov esi, 2000 |
1139 | invoke Sleep ; 2s FIXME |
- | 1140 | ||
1151 | invoke Sleep ; 2s FIXME |
1141 | mov eax, [esp] |
1152 | mov eax, [esp] |
1142 | mov al, MII_BMCR |
1153 | call mdio_read ; returns with window #4 |
1143 | call mdio_read |
1154 | test ah, 0x80 |
- | |
Line 1155... | Line 1144... | ||
1155 | jnz .fail1 |
1144 | test ax, BMCR_RESET |
1156 | mov eax, [esp] |
1145 | jnz .fail1 |
1157 | 1146 | ||
- | 1147 | ; wait for a while after reset |
|
1158 | ; wait for a while after reset |
1148 | mov esi, 20 |
1159 | mov esi, 20 |
1149 | invoke Sleep ; 20ms |
1160 | invoke Sleep ; 20ms |
1150 | |
1161 | mov eax, [esp] |
1151 | mov eax, [esp] |
1162 | mov al , MII_BMSR |
1152 | mov al, MII_BMSR |
1163 | call mdio_read ; returns with window #4 |
1153 | call mdio_read |
1164 | test al, 1 ; extended capability supported? |
- | |
1165 | jz .fail2 |
- | |
1166 | DEBUGF 1,"Extended capability supported\n" |
1154 | test al, BMSR_ERCAP |
1167 | 1155 | jz .fail2 |
|
1168 | ; auto-neg capable? |
1156 | DEBUGF 1,"Extended capability supported\n" |
1169 | test al , 1000b |
- | |
1170 | jz .fail2 ; not auto-negotiation capable |
- | |
1171 | DEBUGF 1,"Auto-negotiation capable\n" |
1157 | test al, BMSR_ANEGCAPABLE |
1172 | 1158 | jz .fail2 |
|
1173 | ; auto-neg complete? |
1159 | DEBUGF 1,"Auto-negotiation capable\n" |
Line 1174... | Line 1160... | ||
1174 | test al , 100000b |
1160 | test al, BMSR_ANEGCOMPLETE |
1175 | jnz .auto_neg_ok |
1161 | jnz .auto_neg_ok |
1176 | DEBUGF 1,"Restarting auto-negotiation\n" |
1162 | DEBUGF 1,"Restarting auto-negotiation\n" |
1177 | 1163 | ||
1178 | ; restart auto-negotiation |
1164 | ; restart auto-negotiation |
1179 | mov eax, [esp] |
1165 | mov eax, [esp] |
1180 | mov al, MII_ADVERTISE |
1166 | mov al, MII_ADVERTISE |
1181 | push eax |
1167 | push eax |
1182 | call mdio_read ; returns with window #4 |
1168 | call mdio_read ; returns with window #4 |
1183 | or ax , 1111b shl 5; advertise only 10base-T and 100base-TX |
1169 |