Rev 5562 | Rev 9232 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5562 | Rev 6717 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2016. 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 | ;; i8255x (Intel eepro 100) driver for KolibriOS ;; |
6 | ;; i8255x (Intel eepro 100) driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
Line 41... | Line 41... | ||
41 | include '../struct.inc' |
41 | include '../struct.inc' |
42 | include '../macros.inc' |
42 | include '../macros.inc' |
43 | include '../fdo.inc' |
43 | include '../fdo.inc' |
44 | include '../netdrv.inc' |
44 | include '../netdrv.inc' |
Line -... | Line 45... | ||
- | 45 | ||
- | 46 | ; I/O registers |
|
- | 47 | REG_SCB_STATUS = 0 |
|
- | 48 | REG_SCB_CMD = 2 |
|
- | 49 | REG_SCB_PTR = 4 |
|
- | 50 | REG_PORT = 8 |
|
- | 51 | REG_EEPROM = 14 |
|
- | 52 | REG_MDI_CTRL = 16 |
|
45 | 53 | ||
- | 54 | ; Port commands |
|
- | 55 | PORT_SOFT_RESET = 0x0 |
|
- | 56 | PORT_SELF_TEST = 0x1 |
|
- | 57 | PORT_SELECTIVE_RESET = 0x2 |
|
- | 58 | PORT_DUMP = 0x3 |
|
- | 59 | PORT_DUMP_WAKEUP = 0x7 |
|
Line -... | Line 60... | ||
- | 60 | PORT_PTR_MASK = 0xfffffff0 |
|
46 | ; Serial EEPROM |
61 | |
47 | 62 | ; Serial EEPROM |
|
48 | EE_SK = 1 shl 0 ; serial clock |
63 | EE_SK = 1 shl 0 ; serial clock |
49 | EE_CS = 1 shl 1 ; chip select |
64 | EE_CS = 1 shl 1 ; chip select |
50 | EE_DI = 1 shl 2 ; data in |
65 | EE_DI = 1 shl 2 ; data in |
51 | EE_DO = 1 shl 3 ; data out |
- | |
52 | EE_MASK = EE_SK + EE_CS + EE_DI + EE_DO |
66 | EE_DO = 1 shl 3 ; data out |
53 | 67 | EE_MASK = EE_SK + EE_CS + EE_DI + EE_DO |
|
54 | ; opcodes, first bit is start bit and must be 1 |
68 | ; opcodes, first bit is start bit and must be 1 |
55 | EE_READ = 110b |
69 | EE_READ = 110b |
Line 56... | Line 70... | ||
56 | EE_WRITE = 101b |
70 | EE_WRITE = 101b |
57 | EE_ERASE = 111b |
- | |
58 | 71 | EE_ERASE = 111b |
|
59 | ; The SCB accepts the following controls for the Tx and Rx units: |
72 | |
60 | 73 | ; The SCB accepts the following controls for the Tx and Rx units: |
|
61 | CU_START = 0x0010 |
74 | CU_START = 0x0010 |
62 | CU_RESUME = 0x0020 |
75 | CU_RESUME = 0x0020 |
Line 71... | Line 84... | ||
71 | RX_ADDR_LOAD = 0x0006 |
84 | RX_ADDR_LOAD = 0x0006 |
72 | RX_RESUMENR = 0x0007 |
85 | RX_RESUMENR = 0x0007 |
73 | INT_MASK = 0x0100 |
86 | INT_MASK = 0x0100 |
74 | DRVR_INT = 0x0200 ; Driver generated interrupt |
87 | DRVR_INT = 0x0200 ; Driver generated interrupt |
Line 75... | Line -... | ||
75 | - | ||
76 | REG_SCB_STATUS = 0 |
- | |
77 | REG_SCB_CMD = 2 |
- | |
78 | REG_SCB_PTR = 4 |
- | |
79 | REG_PORT = 8 |
- | |
80 | REG_EEPROM = 14 |
- | |
81 | REG_MDI_CTRL = 16 |
- | |
82 | 88 | ||
83 | PHY_100a = 0x000003E0 |
89 | PHY_100a = 0x000003E0 |
84 | PHY_100c = 0x035002A8 |
90 | PHY_100c = 0x035002A8 |
85 | PHY_82555_tx = 0x015002A8 |
91 | PHY_82555_tx = 0x015002A8 |
86 | PHY_nsc_tx = 0x5C002000 |
92 | PHY_nsc_tx = 0x5C002000 |
Line 316... | Line 322... | ||
316 | ; Fill in the direct call addresses into the struct |
322 | ; Fill in the direct call addresses into the struct |
Line 317... | Line 323... | ||
317 | 323 | ||
318 | mov [ebx + device.reset], reset |
324 | mov [ebx + device.reset], reset |
319 | mov [ebx + device.transmit], transmit |
325 | mov [ebx + device.transmit], transmit |
320 | mov [ebx + device.unload], unload |
326 | mov [ebx + device.unload], unload |
Line 321... | Line 327... | ||
321 | mov [ebx + device.name], my_service |
327 | mov [ebx + device.name], devicename |
Line 322... | Line 328... | ||
322 | 328 | ||
323 | ; save the pci bus and device numbers |
329 | ; save the pci bus and device numbers |
Line 336... | Line 342... | ||
336 | ; We've found the io address, find IRQ now |
342 | ; We've found the io address, find IRQ now |
Line 337... | Line 343... | ||
337 | 343 | ||
338 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
344 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
Line 339... | Line 345... | ||
339 | mov [ebx + device.irq_line], al |
345 | mov [ebx + device.irq_line], al |
340 | 346 | ||
Line 341... | Line 347... | ||
341 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
347 | DEBUGF 1,"Hooking into device, devfn:%x, bus:%x, irq:%x, addr:%x\n",\ |
Line 342... | Line -... | ||
342 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4 |
- | |
343 | - | ||
344 | ; Ok, the eth_device structure is ready, let's probe the device |
- | |
345 | - | ||
346 | pushf |
- | |
347 | cli ; disable ints untilm initialisation is done |
- | |
348 | - | ||
349 | call probe ; this function will output in eax |
348 | [ebx + device.pci_dev]:2,[ebx + device.pci_bus]:2,[ebx + device.irq_line]:2,[ebx + device.io_addr]:4 |
350 | test eax, eax |
349 | |
351 | jnz .err ; If an error occured, exit |
350 | ; Ok, the eth_device structure is ready, let's probe the device |
Line -... | Line 351... | ||
- | 351 | ||
352 | 352 | mov eax, [devices] ; Add the device structure to our device list |
|
- | 353 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
|
Line 353... | Line 354... | ||
353 | mov eax, [devices] ; Add the device structure to our device list |
354 | inc [devices] ; |
354 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
355 | |
Line 355... | Line 356... | ||
355 | inc [devices] ; |
356 | call probe ; this function will output in eax |
Line 373... | Line 374... | ||
373 | mov eax, edi ; Application wants it in eax instead |
374 | mov eax, edi ; Application wants it in eax instead |
374 | DEBUGF 2,"Kernel says: %u\n", eax |
375 | DEBUGF 2,"Kernel says: %u\n", eax |
375 | ret |
376 | ret |
Line 376... | Line 377... | ||
376 | 377 | ||
377 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
- | |
378 | 378 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
|
379 | .err: |
379 | .err: |
Line 380... | Line 380... | ||
380 | invoke KernelFree, ebx |
380 | invoke KernelFree, ebx |
381 | 381 | ||
Line 421... | Line 421... | ||
421 | 421 | ||
Line 422... | Line 422... | ||
422 | DEBUGF 1,"Probing\n" |
422 | DEBUGF 1,"Probing\n" |
423 | 423 | ||
424 | ; Make the device a bus master |
424 | ; Make the device a bus master |
425 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
425 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
Line 426... | Line 426... | ||
426 | or al, PCI_CMD_MASTER |
426 | or al, PCI_CMD_MASTER or PCI_CMD_PIO |
427 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
427 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
Line 450... | Line 450... | ||
450 | or eax, -1 |
450 | or eax, -1 |
451 | ret |
451 | ret |
Line 452... | Line 452... | ||
452 | 452 | ||
Line 453... | Line -... | ||
453 | .found: |
- | |
454 | - | ||
455 | call ee_get_width |
- | |
456 | call MAC_read_eeprom |
- | |
457 | - | ||
Line 458... | Line 453... | ||
458 | ;;; TODO: detect phy |
453 | .found: |
459 | 454 | ||
460 | 455 | ||
Line 478... | Line 473... | ||
478 | ret |
473 | ret |
479 | @@: |
474 | @@: |
Line 480... | Line 475... | ||
480 | 475 | ||
Line 481... | Line 476... | ||
481 | DEBUGF 1,"Resetting\n" |
476 | DEBUGF 1,"Resetting\n" |
482 | 477 | ||
Line 483... | Line 478... | ||
483 | ;--------------- |
478 | ;---------------- |
- | 479 | ; Selective reset |
|
- | 480 | ||
- | 481 | set_io [ebx + device.io_addr], 0 |
|
- | 482 | set_io [ebx + device.io_addr], REG_EEPROM |
|
- | 483 | mov eax, PORT_SELECTIVE_RESET |
|
- | 484 | out dx, eax |
|
- | 485 | ||
- | 486 | mov esi, 1 |
|
- | 487 | invoke Sleep |
|
- | 488 | ||
484 | ; reset the card |
489 | ;----------- |
485 | 490 | ; Soft reset |
|
486 | set_io [ebx + device.io_addr], 0 |
491 | |
Line 487... | Line 492... | ||
487 | set_io [ebx + device.io_addr], REG_PORT |
492 | set_io [ebx + device.io_addr], REG_PORT |
- | 493 | mov eax, PORT_SOFT_RESET |
|
- | 494 | out dx, eax |
|
- | 495 | ||
- | 496 | mov esi, 10 |
|
- | 497 | invoke Sleep |
|
- | 498 | ||
- | 499 | ;------------- |
|
- | 500 | ; Read PHY IDs |
|
488 | xor eax, eax ; Software Reset |
501 | |
- | 502 | mov cx, 1 |
|
- | 503 | mov dx, MII_PHYSID1 |
|
- | 504 | call mdio_read |
|
- | 505 | DEBUGF 1, "PHY ID1: 0x%x\n", ax |
|
- | 506 | ||
- | 507 | mov cx, 1 |
|
- | 508 | mov dx, MII_PHYSID2 |
|
- | 509 | call mdio_read |
|
- | 510 | DEBUGF 1, "PHY ID2: 0x%x\n", ax |
|
- | 511 | ||
- | 512 | ;--------------------- |
|
Line 489... | Line 513... | ||
489 | out dx, eax |
513 | ; Read MAC from eeprom |
490 | 514 | ||
Line 491... | Line 515... | ||
491 | mov esi, 10 |
515 | call ee_get_width |
Line 989... | Line 1013... | ||
989 | or esi, EE_READ shl 29 |
1013 | or esi, EE_READ shl 29 |
Line 990... | Line 1014... | ||
990 | 1014 | ||
991 | movzx ecx, [ebx + device.ee_bus_width] |
1015 | movzx ecx, [ebx + device.ee_bus_width] |
Line 992... | Line 1016... | ||
992 | add ecx, 3 |
1016 | add ecx, 3 |
993 | 1017 | ||
994 | mov al, EE_CS |
1018 | mov ax, 0x4800 + EE_CS |
Line 995... | Line 1019... | ||
995 | out dx, al |
1019 | out dx, ax |
996 | call udelay |
1020 | call udelay |
Line 997... | Line 1021... | ||
997 | 1021 | ||
998 | ;----------------------- |
1022 | ;----------------------- |
999 | ; Write this to the chip |
1023 | ; Write this to the chip |
1000 | 1024 | ||
1001 | .loop: |
1025 | .loop: |
1002 | mov al, EE_CS + EE_SK |
1026 | mov al, EE_CS |
1003 | shl esi, 1 |
1027 | shl esi, 1 |
1004 | jnc @f |
1028 | jnc @f |
Line 1005... | Line 1029... | ||
1005 | or al, EE_DI |
1029 | or al, EE_DI |
1006 | @@: |
1030 | @@: |
1007 | out dx, al |
1031 | out dx, al |
Line 1008... | Line 1032... | ||
1008 | call udelay |
1032 | call udelay |
Line 1019... | Line 1043... | ||
1019 | xor esi, esi |
1043 | xor esi, esi |
1020 | mov ecx, 16 |
1044 | mov ecx, 16 |
Line 1021... | Line 1045... | ||
1021 | 1045 | ||
1022 | .loop2: |
1046 | .loop2: |
1023 | shl esi, 1 |
1047 | shl esi, 1 |
- | 1048 | mov al, EE_CS |
|
- | 1049 | out dx, al |
|
- | 1050 | call udelay |
|
- | 1051 | ||
1024 | mov al, EE_CS + EE_SK |
1052 | or al, EE_SK |
1025 | out dx, al |
1053 | out dx, al |
Line 1026... | Line 1054... | ||
1026 | call udelay |
1054 | call udelay |
1027 | 1055 | ||
1028 | in al, dx |
1056 | in al, dx |
1029 | test al, EE_DO |
1057 | test al, EE_DO |
1030 | jz @f |
1058 | jz @f |
Line 1031... | Line -... | ||
1031 | inc esi |
- | |
1032 | @@: |
- | |
1033 | - | ||
1034 | mov al, EE_CS |
- | |
1035 | out dx, al |
1059 | inc esi |
Line 1036... | Line 1060... | ||
1036 | call udelay |
1060 | @@: |
1037 | 1061 | ||
Line 1038... | Line 1062... | ||
1038 | loop .loop2 |
1062 | loop .loop2 |
1039 | 1063 | ||
1040 | ;----------------------- |
- | |
Line 1041... | Line 1064... | ||
1041 | ; de-activate the eeprom |
1064 | ;----------------------- |
1042 | 1065 | ; de-activate the eeprom |
|
Line 1067... | Line 1090... | ||
1067 | or esi, EE_WRITE shl 29 |
1090 | or esi, EE_WRITE shl 29 |
Line 1068... | Line 1091... | ||
1068 | 1091 | ||
1069 | movzx ecx, [ebx + device.ee_bus_width] |
1092 | movzx ecx, [ebx + device.ee_bus_width] |
Line 1070... | Line 1093... | ||
1070 | add ecx, 3 |
1093 | add ecx, 3 |
1071 | 1094 | ||
Line 1072... | Line 1095... | ||
1072 | mov al, EE_CS ; enable chip |
1095 | mov ax, 0x4800 + EE_CS ; enable chip |
1073 | out dx, al |
1096 | out dx, ax |
Line 1074... | Line 1097... | ||
1074 | 1097 | ||
1075 | ;----------------------- |
1098 | ;----------------------- |
1076 | ; Write this to the chip |
1099 | ; Write this to the chip |
1077 | 1100 | ||
1078 | .loop: |
1101 | .loop: |
1079 | mov al, EE_CS + EE_SK |
1102 | mov al, EE_CS |
1080 | shl esi, 1 |
1103 | shl esi, 1 |
1081 | jnc @f |
1104 | jnc @f |
Line 1082... | Line 1105... | ||
1082 | or al, EE_DI |
1105 | or al, EE_DI |
1083 | @@: |
1106 | @@: |
1084 | out dx, al |
1107 | out dx, al |
Line 1085... | Line 1108... | ||
1085 | call udelay |
1108 | call udelay |
Line 1094... | Line 1117... | ||
1094 | ; Now write the data to eeprom |
1117 | ; Now write the data to eeprom |
Line 1095... | Line 1118... | ||
1095 | 1118 | ||
Line 1096... | Line 1119... | ||
1096 | mov ecx, 16 |
1119 | mov ecx, 16 |
1097 | 1120 | ||
1098 | .loop2: |
1121 | .loop2: |
1099 | mov al, EE_CS + EE_SK |
1122 | mov al, EE_CS |
1100 | shl di, 1 |
1123 | shl di, 1 |
1101 | jnc @f |
1124 | jnc @f |
1102 | or al, EE_DI |
1125 | or al, EE_DI |
1103 | @@: |
1126 | @@: |
Line 1104... | Line 1127... | ||
1104 | out dx, al |
1127 | out dx, al |
1105 | call udelay |
1128 | call udelay |
1106 | 1129 | ||
Line 1107... | Line 1130... | ||
1107 | and al, not EE_SK |
1130 | or al, EE_SK |
Line 1125... | Line 1148... | ||
1125 | ee_get_width: |
1148 | ee_get_width: |
Line 1126... | Line 1149... | ||
1126 | 1149 | ||
1127 | set_io [ebx + device.io_addr], 0 |
1150 | set_io [ebx + device.io_addr], 0 |
Line 1128... | Line 1151... | ||
1128 | set_io [ebx + device.io_addr], REG_EEPROM |
1151 | set_io [ebx + device.io_addr], REG_EEPROM |
1129 | 1152 | ||
1130 | mov al, EE_CS ; activate eeprom |
1153 | mov ax, 0x4800 + EE_CS ; activate eeprom |
Line 1131... | Line 1154... | ||
1131 | out dx, al |
1154 | out dx, ax |
1132 | call udelay |
1155 | call udelay |
1133 | 1156 | ||
1134 | mov si, EE_READ shl 13 |
1157 | mov si, EE_READ shl 13 |
1135 | xor ecx, ecx |
1158 | xor ecx, ecx |
1136 | .loop: |
1159 | .loop: |
1137 | mov al, EE_CS + EE_SK |
1160 | mov al, EE_CS |
1138 | shl si, 1 |
1161 | shl si, 1 |
1139 | jnc @f |
1162 | jnc @f |
1140 | or al, EE_DI |
1163 | or al, EE_DI |
Line 1141... | Line 1164... | ||
1141 | @@: |
1164 | @@: |
1142 | out dx, al |
1165 | out dx, ax |
1143 | call udelay |
1166 | call udelay |
Line 1144... | Line 1167... | ||
1144 | 1167 | ||
Line 1145... | Line 1168... | ||
1145 | and al, not EE_SK |
1168 | or al, EE_SK |
Line 1164... | Line 1187... | ||
1164 | 1187 | ||
Line 1165... | Line 1188... | ||
1165 | ret |
1188 | ret |
1166 | 1189 | ||
1167 | .give_up: |
- | |
1168 | DEBUGF 2, "Eeprom not found!\n" |
1190 | .give_up: |
1169 | 1191 | DEBUGF 2, "Eeprom not found!\n" |
|
Line 1170... | Line 1192... | ||
1170 | xor al, al |
1192 | xor al, al |
Line 1193... | Line 1215... | ||
1193 | mdio_read: |
1215 | mdio_read: |
Line 1194... | Line 1216... | ||
1194 | 1216 | ||
Line 1195... | Line 1217... | ||
1195 | DEBUGF 1,"MDIO read\n" |
1217 | DEBUGF 1,"MDIO read\n" |
1196 | - | ||
1197 | shl ecx, 21 ; PHY addr |
- | |
1198 | shl edx, 16 ; PHY reg addr |
1218 | |
- | 1219 | shl ecx, 21 ; PHY addr |
|
1199 | 1220 | mov eax, ecx |
|
1200 | mov eax, ecx |
1221 | shl edx, 16 ; PHY reg addr |
Line 1201... | Line 1222... | ||
1201 | or eax, edx |
1222 | or eax, edx |
1202 | or eax, 10b shl 26 ; read opcode |
1223 | or eax, 10b shl 26 ; read opcode |
Line 1211... | Line 1232... | ||
1211 | test eax, 1 shl 28 ; ready bit |
1232 | test eax, 1 shl 28 ; ready bit |
1212 | jz .wait |
1233 | jz .wait |
Line 1213... | Line 1234... | ||
1213 | 1234 | ||
Line -... | Line 1235... | ||
- | 1235 | ret |
|
- | 1236 | ||
1214 | ret |
1237 | |
1215 | 1238 | ||
1216 | ; ax = data |
1239 | ; ax = data |
Line 1217... | Line 1240... | ||
1217 | ; cx = phy addr |
1240 | ; cx = phy addr |
Line 1243... | Line 1266... | ||
1243 | test eax, 1 shl 28 ; ready bit |
1266 | test eax, 1 shl 28 ; ready bit |
1244 | jz .wait |
1267 | jz .wait |
Line 1245... | Line 1268... | ||
1245 | 1268 | ||
Line 1246... | Line -... | ||
1246 | ret |
- | |
1247 | - | ||
1248 | read_mac: |
- | |
1249 | - | ||
1250 | ret |
- | |
Line 1251... | Line 1269... | ||
1251 | 1269 | ret |
|
1252 | 1270 | ||
Line 1253... | Line 1271... | ||
1253 | 1271 | ||
1254 | align 4 |
1272 | align 4 |
1255 | MAC_read_eeprom: |
1273 | mac_read_eeprom: |
Line 1268... | Line 1286... | ||
1268 | 1286 | ||
Line 1269... | Line -... | ||
1269 | - | ||
1270 | ret |
- | |
1271 | - | ||
1272 | - | ||
1273 | align 4 |
- | |
1274 | MAC_write: |
- | |
1275 | - | ||
1276 | ;;;; |
- | |
1277 | - | ||
1278 | ret |
- | |
1279 | 1287 | ||
Line 1280... | Line 1288... | ||
1280 | 1288 | ret |
|
1281 | 1289 | ||
Line 1295... | Line 1303... | ||
1295 | db 0, 0x2e, 0, 0x60, 0, 0xf2, 0x48, 0, 0x40, 0xf2 |
1303 | db 0, 0x2e, 0, 0x60, 0, 0xf2, 0x48, 0, 0x40, 0xf2 |
1296 | db 0x80, 0x3f, 0x05 ; 22 bytes total |
1304 | db 0x80, 0x3f, 0x05 ; 22 bytes total |
Line 1297... | Line 1305... | ||
1297 | 1305 | ||
1298 | - | ||
1299 | device_id_list: |
1306 | |
1300 | 1307 | device_id_list: |
|
1301 | dw 0x1029 |
1308 | dw 0x1029 |
1302 | dw 0x1030 |
1309 | dw 0x1030 |
1303 | dw 0x1031 |
1310 | dw 0x1031 |