Rev 4470 | Rev 4582 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4470 | Rev 4581 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. 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 ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
11 | ;; Version 2, June 1991 ;; |
11 | ;; Version 2, June 1991 ;; |
12 | ;; ;; |
12 | ;; ;; |
13 | ;; Some parts of this driver are based on the code of eepro100.c ;; |
13 | ;; Some parts of this driver are based on the code of eepro100.c ;; |
14 | ;; from linux. ;; |
14 | ;; from linux. ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;; Intel's programming manual for i8255x: ;; |
16 | ;; Intel's programming manual for i8255x: ;; |
17 | ;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm ;; |
17 | ;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm ;; |
18 | ;; ;; |
18 | ;; ;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
20 | 20 | ||
21 | ; TODO: use separate descriptors in memory instead of placing them in front of packets! |
21 | ; TODO: use separate descriptors in memory instead of placing them in front of packets! |
22 | 22 | ||
23 | 23 | ||
- | 24 | format PE DLL native |
|
24 | format MS COFF |
25 | entry START |
25 | 26 | ||
- | 27 | CURRENT_API = 0x0200 |
|
26 | API_VERSION = 0x01000100 |
28 | COMPATIBLE_API = 0x0100 |
27 | DRIVER_VERSION = 5 |
29 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
28 | 30 | ||
29 | MAX_DEVICES = 16 |
31 | MAX_DEVICES = 16 |
30 | 32 | ||
31 | DEBUG = 1 |
33 | DEBUG = 1 |
32 | __DEBUG__ = 1 |
34 | __DEBUG__ = 1 |
33 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
35 | __DEBUG_LEVEL__ = 1 ; 1 = verbose, 2 = errors only |
- | 36 | ||
- | 37 | section '.flat' readable writable executable |
|
- | 38 | ||
34 | 39 | include '../proc32.inc' |
|
35 | include '../struct.inc' |
40 | include '../struct.inc' |
36 | include '../macros.inc' |
- | |
37 | include '../proc32.inc' |
- | |
38 | include '../imports.inc' |
41 | include '../macros.inc' |
39 | include '../fdo.inc' |
42 | include '../fdo.inc' |
40 | include '../netdrv.inc' |
- | |
41 | - | ||
42 | public START |
- | |
43 | public service_proc |
- | |
44 | public version |
- | |
45 | - | ||
46 | virtual at ebx |
- | |
47 | - | ||
48 | device: |
- | |
49 | - | ||
50 | ETH_DEVICE |
- | |
51 | - | ||
52 | .io_addr dd ? |
- | |
53 | .pci_bus dd ? |
- | |
54 | .pci_dev dd ? |
- | |
55 | .irq_line db ? |
- | |
56 | - | ||
57 | .rx_desc dd ? |
- | |
58 | - | ||
59 | .ee_bus_width db ? |
- | |
60 | - | ||
61 | rb 0x100 - (($ - device) and 0xff) |
- | |
62 | - | ||
63 | txfd: |
- | |
64 | .status dw ? |
- | |
65 | .command dw ? |
- | |
66 | .link dd ? |
- | |
67 | .tx_desc_addr dd ? |
- | |
68 | .count dd ? |
- | |
69 | - | ||
70 | .tx_buf_addr0 dd ? |
- | |
71 | .tx_buf_size0 dd ? |
- | |
72 | - | ||
73 | rb 0x100 - (($ - device) and 0xff) |
- | |
74 | - | ||
75 | confcmd: |
- | |
76 | .status dw ? |
- | |
77 | .command dw ? |
- | |
78 | .link dd ? |
- | |
79 | .data rb 64 |
- | |
80 | - | ||
81 | rb 0x100 - (($ - device) and 0xff) |
- | |
82 | - | ||
83 | lstats: |
- | |
84 | tx_good_frames dd ? |
- | |
85 | tx_coll16_errs dd ? |
- | |
86 | tx_late_colls dd ? |
- | |
87 | tx_underruns dd ? |
- | |
88 | tx_lost_carrier dd ? |
- | |
89 | tx_deferred dd ? |
- | |
90 | tx_one_colls dd ? |
- | |
91 | tx_multi_colls dd ? |
- | |
92 | tx_total_colls dd ? |
- | |
93 | - | ||
94 | rx_good_frames dd ? |
- | |
95 | rx_crc_errs dd ? |
- | |
96 | rx_align_errs dd ? |
- | |
97 | rx_resource_errs dd ? |
- | |
98 | rx_overrun_errs dd ? |
- | |
99 | rx_colls_errs dd ? |
- | |
100 | rx_runt_errs dd ? |
- | |
101 | - | ||
102 | last_tx_buffer dd ? ;;; fixme |
- | |
103 | - | ||
104 | sizeof.device_struct = $ - device |
- | |
105 | - | ||
106 | end virtual |
- | |
107 | - | ||
108 | - | ||
109 | virtual at 0 |
- | |
110 | - | ||
111 | rxfd: |
- | |
112 | .status dw ? |
- | |
113 | .command dw ? |
- | |
114 | .link dd ? |
- | |
115 | .rx_buf_addr dd ? |
- | |
116 | .count dw ? |
- | |
117 | .size dw ? |
- | |
118 | .packet: |
- | |
119 | - | ||
120 | end virtual |
- | |
121 | 43 | include '../netdrv_pe.inc' |
|
122 | 44 | ||
123 | ; Serial EEPROM |
45 | ; Serial EEPROM |
124 | 46 | ||
125 | EE_SK = 1 shl 0 ; serial clock |
47 | EE_SK = 1 shl 0 ; serial clock |
126 | EE_CS = 1 shl 1 ; chip select |
48 | EE_CS = 1 shl 1 ; chip select |
127 | EE_DI = 1 shl 2 ; data in |
49 | EE_DI = 1 shl 2 ; data in |
128 | EE_DO = 1 shl 3 ; data out |
50 | EE_DO = 1 shl 3 ; data out |
129 | EE_MASK = EE_SK + EE_CS + EE_DI + EE_DO |
51 | EE_MASK = EE_SK + EE_CS + EE_DI + EE_DO |
130 | 52 | ||
131 | ; opcodes, first bit is start bit and must be 1 |
53 | ; opcodes, first bit is start bit and must be 1 |
132 | EE_READ = 110b |
54 | EE_READ = 110b |
133 | EE_WRITE = 101b |
55 | EE_WRITE = 101b |
134 | EE_ERASE = 111b |
56 | EE_ERASE = 111b |
135 | 57 | ||
136 | ; The SCB accepts the following controls for the Tx and Rx units: |
58 | ; The SCB accepts the following controls for the Tx and Rx units: |
137 | 59 | ||
138 | CU_START = 0x0010 |
60 | CU_START = 0x0010 |
139 | CU_RESUME = 0x0020 |
61 | CU_RESUME = 0x0020 |
140 | CU_STATSADDR = 0x0040 |
62 | CU_STATSADDR = 0x0040 |
141 | CU_SHOWSTATS = 0x0050 ; Dump statistics counters. |
63 | CU_SHOWSTATS = 0x0050 ; Dump statistics counters. |
142 | CU_CMD_BASE = 0x0060 ; Base address to add CU commands. |
64 | CU_CMD_BASE = 0x0060 ; Base address to add CU commands. |
143 | CU_DUMPSTATS = 0x0070 ; Dump then reset stats counters. |
65 | CU_DUMPSTATS = 0x0070 ; Dump then reset stats counters. |
144 | 66 | ||
145 | RX_START = 0x0001 |
67 | RX_START = 0x0001 |
146 | RX_RESUME = 0x0002 |
68 | RX_RESUME = 0x0002 |
147 | RX_ABORT = 0x0004 |
69 | RX_ABORT = 0x0004 |
148 | RX_ADDR_LOAD = 0x0006 |
70 | RX_ADDR_LOAD = 0x0006 |
149 | RX_RESUMENR = 0x0007 |
71 | RX_RESUMENR = 0x0007 |
150 | INT_MASK = 0x0100 |
72 | INT_MASK = 0x0100 |
151 | DRVR_INT = 0x0200 ; Driver generated interrupt |
73 | DRVR_INT = 0x0200 ; Driver generated interrupt |
152 | 74 | ||
153 | CmdIASetup = 0x0001 |
75 | CmdIASetup = 0x0001 |
154 | CmdConfigure = 0x0002 |
76 | CmdConfigure = 0x0002 |
155 | CmdTx = 0x0004 |
77 | CmdTx = 0x0004 |
156 | CmdTxFlex = 0x0008 |
78 | CmdTxFlex = 0x0008 |
157 | Cmdsuspend = 0x4000 |
79 | Cmdsuspend = 0x4000 |
158 | - | ||
159 | 80 | ||
160 | reg_scb_status = 0 |
81 | reg_scb_status = 0 |
161 | reg_scb_cmd = 2 |
82 | reg_scb_cmd = 2 |
162 | reg_scb_ptr = 4 |
83 | reg_scb_ptr = 4 |
163 | reg_port = 8 |
84 | reg_port = 8 |
164 | reg_eeprom = 14 |
85 | reg_eeprom = 14 |
165 | reg_mdi_ctrl = 16 |
86 | reg_mdi_ctrl = 16 |
- | 87 | ||
- | 88 | phy_100a = 0x000003E0 |
|
- | 89 | phy_100c = 0x035002A8 |
|
- | 90 | phy_82555_tx = 0x015002A8 |
|
- | 91 | phy_nsc_tx = 0x5C002000 |
|
- | 92 | phy_82562_et = 0x033002A8 |
|
- | 93 | phy_82562_em = 0x032002A8 |
|
- | 94 | phy_82562_ek = 0x031002A8 |
|
- | 95 | phy_82562_eh = 0x017002A8 |
|
- | 96 | phy_82552_v = 0xd061004d |
|
- | 97 | phy_unknown = 0xFFFFFFFF |
|
- | 98 | ||
- | 99 | mac_82557_D100_A = 0 |
|
- | 100 | mac_82557_D100_B = 1 |
|
- | 101 | mac_82557_D100_C = 2 |
|
- | 102 | mac_82558_D101_A4 = 4 |
|
- | 103 | mac_82558_D101_B0 = 5 |
|
- | 104 | mac_82559_D101M = 8 |
|
- | 105 | mac_82559_D101S = 9 |
|
- | 106 | mac_82550_D102 = 12 |
|
- | 107 | mac_82550_D102_C = 13 |
|
- | 108 | mac_82551_E = 14 |
|
- | 109 | mac_82551_F = 15 |
|
- | 110 | mac_82551_10 = 16 |
|
- | 111 | mac_unknown = 0xFF |
|
- | 112 | ||
- | 113 | struct rxfd |
|
- | 114 | ||
- | 115 | status dw ? |
|
- | 116 | command dw ? |
|
- | 117 | link dd ? |
|
- | 118 | rx_buf_addr dd ? |
|
- | 119 | count dw ? |
|
- | 120 | size dw ? |
|
- | 121 | packet rb 1500 |
|
- | 122 | ||
- | 123 | ends |
|
- | 124 | ||
- | 125 | struc txfd { |
|
- | 126 | ||
- | 127 | .status dw ? |
|
- | 128 | .command dw ? |
|
- | 129 | .link dd ? |
|
- | 130 | .desc_addr dd ? |
|
- | 131 | .count dd ? |
|
- | 132 | ||
- | 133 | .buf_addr0 dd ? |
|
- | 134 | .buf_size0 dd ? |
|
- | 135 | ||
- | 136 | } |
|
- | 137 | ||
- | 138 | struc confcmd { |
|
- | 139 | ||
- | 140 | .status dw ? |
|
- | 141 | .command dw ? |
|
- | 142 | .link dd ? |
|
- | 143 | .data rb 64 |
|
- | 144 | ||
- | 145 | } |
|
- | 146 | ||
- | 147 | struc lstats { |
|
- | 148 | ||
- | 149 | .tx_good_frames dd ? |
|
- | 150 | .tx_coll16_errs dd ? |
|
- | 151 | .tx_late_colls dd ? |
|
- | 152 | .tx_underruns dd ? |
|
- | 153 | .tx_lost_carrier dd ? |
|
- | 154 | .tx_deferred dd ? |
|
- | 155 | .tx_one_colls dd ? |
|
- | 156 | .tx_multi_colls dd ? |
|
- | 157 | .tx_total_colls dd ? |
|
- | 158 | ||
- | 159 | .rx_good_frames dd ? |
|
- | 160 | .rx_crc_errs dd ? |
|
- | 161 | .rx_align_errs dd ? |
|
- | 162 | .rx_resource_errs dd ? |
|
- | 163 | .rx_overrun_errs dd ? |
|
- | 164 | .rx_colls_errs dd ? |
|
- | 165 | .rx_runt_errs dd ? |
|
- | 166 | ||
- | 167 | } |
|
- | 168 | ||
- | 169 | struct device ETH_DEVICE |
|
- | 170 | ||
- | 171 | io_addr dd ? |
|
- | 172 | pci_bus dd ? |
|
- | 173 | pci_dev dd ? |
|
- | 174 | rx_desc dd ? |
|
- | 175 | last_tx_buffer dd ? |
|
- | 176 | ee_bus_width db ? |
|
- | 177 | irq_line db ? |
|
- | 178 | ||
- | 179 | rb 0x100 - ($ and 0xff) ; align 256 |
|
- | 180 | txfd txfd |
|
- | 181 | ||
- | 182 | rb 0x100 - ($ and 0xff) ; align 256 |
|
- | 183 | confcmd confcmd |
|
- | 184 | ||
- | 185 | rb 0x100 - ($ and 0xff) ; align 256 |
|
- | 186 | lstats lstats |
|
- | 187 | ||
166 | 188 | ends |
|
167 | 189 | ||
168 | macro delay { |
190 | macro delay { |
169 | push eax |
191 | push eax |
170 | in ax, dx |
192 | in ax, dx |
171 | in ax, dx |
193 | in ax, dx |
172 | in ax, dx |
194 | in ax, dx |
173 | in ax, dx |
195 | in ax, dx |
174 | in ax, dx |
196 | in ax, dx |
175 | in ax, dx |
197 | in ax, dx |
176 | in ax, dx |
198 | in ax, dx |
177 | in ax, dx |
199 | in ax, dx |
178 | in ax, dx |
200 | in ax, dx |
179 | in ax, dx |
201 | in ax, dx |
180 | pop eax |
202 | pop eax |
181 | } |
203 | } |
182 | - | ||
183 | section '.flat' code readable align 16 |
- | |
184 | 204 | ||
185 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
205 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
186 | ;; ;; |
206 | ;; ;; |
187 | ;; proc START ;; |
207 | ;; proc START ;; |
188 | ;; ;; |
208 | ;; ;; |
189 | ;; (standard driver proc) ;; |
209 | ;; (standard driver proc) ;; |
190 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
210 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
191 | 211 | ||
192 | proc START stdcall, state:dword |
212 | proc START c, state:dword |
193 | 213 | ||
194 | cmp [state], 1 |
214 | cmp [state], 1 |
195 | jne .exit |
215 | jne .exit |
196 | 216 | ||
197 | .entry: |
217 | .entry: |
198 | 218 | ||
199 | DEBUGF 1,"Loading driver\n" |
219 | DEBUGF 1,"Loading driver\n" |
200 | stdcall RegService, my_service, service_proc |
220 | invoke RegService, my_service, service_proc |
201 | ret |
221 | ret |
202 | 222 | ||
203 | .fail: |
223 | .fail: |
204 | .exit: |
224 | .exit: |
205 | xor eax, eax |
225 | xor eax, eax |
206 | ret |
226 | ret |
207 | 227 | ||
208 | endp |
228 | endp |
209 | 229 | ||
210 | 230 | ||
211 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
231 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
212 | ;; ;; |
232 | ;; ;; |
213 | ;; proc SERVICE_PROC ;; |
233 | ;; proc SERVICE_PROC ;; |
214 | ;; ;; |
234 | ;; ;; |
215 | ;; (standard driver proc) ;; |
235 | ;; (standard driver proc) ;; |
216 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
236 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
217 | 237 | ||
218 | align 4 |
238 | align 4 |
219 | proc service_proc stdcall, ioctl:dword |
239 | proc service_proc stdcall, ioctl:dword |
220 | 240 | ||
221 | mov edx, [ioctl] |
241 | mov edx, [ioctl] |
222 | mov eax, [edx + IOCTL.io_code] |
242 | mov eax, [edx + IOCTL.io_code] |
223 | 243 | ||
224 | ;------------------------------------------------------ |
244 | ;------------------------------------------------------ |
225 | 245 | ||
226 | cmp eax, 0 ;SRV_GETVERSION |
246 | cmp eax, 0 ;SRV_GETVERSION |
227 | jne @F |
247 | jne @F |
228 | 248 | ||
229 | cmp [edx + IOCTL.out_size], 4 |
249 | cmp [edx + IOCTL.out_size], 4 |
230 | jb .fail |
250 | jb .fail |
231 | mov eax, [edx + IOCTL.output] |
251 | mov eax, [edx + IOCTL.output] |
232 | mov [eax], dword API_VERSION |
252 | mov [eax], dword API_VERSION |
233 | 253 | ||
234 | xor eax, eax |
254 | xor eax, eax |
235 | ret |
255 | ret |
236 | 256 | ||
237 | ;------------------------------------------------------ |
257 | ;------------------------------------------------------ |
238 | @@: |
258 | @@: |
239 | cmp eax, 1 ;SRV_HOOK |
259 | cmp eax, 1 ;SRV_HOOK |
240 | jne .fail |
260 | jne .fail |
241 | 261 | ||
242 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
262 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
243 | jb .fail |
263 | jb .fail |
244 | 264 | ||
245 | mov eax, [edx + IOCTL.input] |
265 | mov eax, [edx + IOCTL.input] |
246 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
266 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
247 | jne .fail ; other types arent supported for this card yet |
267 | jne .fail ; other types arent supported for this card yet |
248 | 268 | ||
249 | ; check if the device is already listed |
269 | ; check if the device is already listed |
250 | 270 | ||
251 | mov esi, device_list |
271 | mov esi, device_list |
252 | mov ecx, [devices] |
272 | mov ecx, [devices] |
253 | test ecx, ecx |
273 | test ecx, ecx |
254 | jz .firstdevice |
274 | jz .firstdevice |
255 | 275 | ||
256 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
276 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
257 | mov ax , [eax+1] ; |
277 | mov ax , [eax+1] ; |
258 | .nextdevice: |
278 | .nextdevice: |
259 | mov ebx, [esi] |
279 | mov ebx, [esi] |
260 | cmp al, byte[device.pci_bus] |
280 | cmp al, byte[ebx + device.pci_bus] |
261 | jne @f |
281 | jne @f |
262 | cmp ah, byte[device.pci_dev] |
282 | cmp ah, byte[ebx + device.pci_dev] |
263 | je .find_devicenum ; Device is already loaded, let's find it's device number |
283 | je .find_devicenum ; Device is already loaded, let's find it's device number |
264 | @@: |
284 | @@: |
265 | add esi, 4 |
285 | add esi, 4 |
266 | loop .nextdevice |
286 | loop .nextdevice |
267 | 287 | ||
268 | 288 | ||
269 | ; This device doesnt have its own eth_device structure yet, lets create one |
289 | ; This device doesnt have its own eth_device structure yet, lets create one |
270 | .firstdevice: |
290 | .firstdevice: |
271 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
291 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
272 | jae .fail |
292 | jae .fail |
273 | 293 | ||
274 | allocate_and_clear ebx, sizeof.device_struct, .fail ; Allocate the buffer for device structure |
294 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure |
275 | 295 | ||
276 | ; Fill in the direct call addresses into the struct |
296 | ; Fill in the direct call addresses into the struct |
277 | 297 | ||
278 | mov [device.reset], reset |
298 | mov [ebx + device.reset], reset |
279 | mov [device.transmit], transmit |
299 | mov [ebx + device.transmit], transmit |
280 | mov [device.unload], unload |
300 | mov [ebx + device.unload], unload |
281 | mov [device.name], my_service |
301 | mov [ebx + device.name], my_service |
282 | 302 | ||
283 | ; save the pci bus and device numbers |
303 | ; save the pci bus and device numbers |
284 | 304 | ||
285 | mov eax, [edx + IOCTL.input] |
305 | mov eax, [edx + IOCTL.input] |
286 | movzx ecx, byte[eax+1] |
306 | movzx ecx, byte[eax+1] |
287 | mov [device.pci_bus], ecx |
307 | mov [ebx + device.pci_bus], ecx |
288 | movzx ecx, byte[eax+2] |
308 | movzx ecx, byte[eax+2] |
289 | mov [device.pci_dev], ecx |
309 | mov [ebx + device.pci_dev], ecx |
290 | 310 | ||
291 | ; Now, it's time to find the base io addres of the PCI device |
311 | ; Now, it's time to find the base io addres of the PCI device |
- | 312 | ||
292 | 313 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
|
293 | PCI_find_io |
314 | mov [ebx + device.io_addr], eax |
294 | 315 | ||
295 | ; We've found the io address, find IRQ now |
316 | ; We've found the io address, find IRQ now |
- | 317 | ||
296 | 318 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
|
297 | PCI_find_irq |
319 | mov [ebx + device.irq_line], al |
298 | 320 | ||
299 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
321 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
300 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 |
322 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4 |
301 | 323 | ||
302 | ; Ok, the eth_device structure is ready, let's probe the device |
324 | ; Ok, the eth_device structure is ready, let's probe the device |
303 | 325 | ||
304 | pushf |
326 | pushf |
305 | cli ; disable ints until initialisation is done |
327 | cli ; disable ints untilm initialisation is done |
306 | 328 | ||
307 | call probe ; this function will output in eax |
329 | call probe ; this function will output in eax |
308 | test eax, eax |
330 | test eax, eax |
309 | jnz .err ; If an error occured, exit |
331 | jnz .err ; If an error occured, exit |
310 | 332 | ||
311 | mov eax, [devices] ; Add the device structure to our device list |
333 | mov eax, [devices] ; Add the device structure to our device list |
312 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
334 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
313 | inc [devices] ; |
335 | inc [devices] ; |
314 | 336 | ||
315 | popf |
337 | popf |
316 | 338 | ||
317 | mov [device.type], NET_TYPE_ETH |
339 | mov [ebx + device.type], NET_TYPE_ETH |
318 | call NetRegDev |
340 | invoke NetRegDev |
319 | 341 | ||
320 | cmp eax, -1 |
342 | cmp eax, -1 |
321 | je .err |
343 | je .err |
322 | 344 | ||
323 | ret |
345 | ret |
324 | 346 | ||
325 | ; If the device was already loaded, find the device number and return it in eax |
347 | ; If the device was already loaded, find the device number and return it in eax |
326 | 348 | ||
327 | .find_devicenum: |
349 | .find_devicenum: |
328 | DEBUGF 2,"Trying to find device number of already registered device\n" |
350 | DEBUGF 2,"Trying to find device number of already registered device\n" |
329 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
351 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
330 | ; into a device number in edi |
352 | ; into a device number in edi |
331 | mov eax, edi ; Application wants it in eax instead |
353 | mov eax, edi ; Application wants it in eax instead |
332 | DEBUGF 2,"Kernel says: %u\n", eax |
354 | DEBUGF 2,"Kernel says: %u\n", eax |
333 | ret |
355 | ret |
334 | 356 | ||
335 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
357 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
336 | 358 | ||
337 | .err: |
359 | .err: |
338 | stdcall KernelFree, ebx |
360 | invoke KernelFree, ebx |
339 | 361 | ||
340 | .fail: |
362 | .fail: |
341 | or eax, -1 |
363 | or eax, -1 |
342 | ret |
364 | ret |
343 | 365 | ||
344 | ;------------------------------------------------------ |
366 | ;------------------------------------------------------ |
345 | endp |
367 | endp |
346 | 368 | ||
347 | 369 | ||
348 | 370 | ||
349 | 371 | ||
350 | 372 | ||
351 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
373 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
352 | ;; ;; |
374 | ;; ;; |
353 | ;; Actual Hardware dependent code starts here ;; |
375 | ;; Actual Hardware dependent code starts here ;; |
354 | ;; ;; |
376 | ;; ;; |
355 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
377 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
356 | 378 | ||
357 | 379 | ||
358 | unload: |
380 | unload: |
359 | ; TODO: (in this particular order) |
381 | ; TODO: (in this particular order) |
360 | ; |
382 | ; |
361 | ; - Stop the device |
383 | ; - Stop the device |
362 | ; - Detach int handler |
384 | ; - Detach int handler |
363 | ; - Remove device from local list (device_list) |
385 | ; - Remove device from local list (device_list) |
364 | ; - call unregister function in kernel |
386 | ; - call unregister function in kernel |
365 | ; - Remove all allocated structures and buffers the card used |
387 | ; - Remove all allocated structures and buffers the card used |
366 | 388 | ||
367 | or eax,-1 |
389 | or eax,-1 |
368 | 390 | ||
369 | ret |
391 | ret |
370 | 392 | ||
371 | 393 | ||
372 | ;------------- |
394 | ;------------- |
373 | ; |
395 | ; |
374 | ; Probe |
396 | ; Probe |
375 | ; |
397 | ; |
376 | ;------------- |
398 | ;------------- |
377 | 399 | ||
378 | align 4 |
400 | align 4 |
379 | probe: |
401 | probe: |
380 | 402 | ||
381 | DEBUGF 1,"Probing\n" |
403 | DEBUGF 1,"Probing\n" |
382 | 404 | ||
- | 405 | ; Make the device a bus master |
|
- | 406 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
|
- | 407 | or al, PCI_CMD_MASTER |
|
383 | PCI_make_bus_master |
408 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
384 | 409 | ||
385 | ;--------------------------- |
410 | ;--------------------------- |
386 | ; First, identify the device |
411 | ; First, identify the device |
387 | 412 | ||
388 | stdcall PciRead32, [device.pci_bus], [device.pci_dev], PCI_VENDOR_ID ; get device/vendor id |
413 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header.vendor_id ; get device/vendor id |
389 | 414 | ||
390 | DEBUGF 1,"Vendor_id=0x%x\n", ax |
415 | DEBUGF 1,"Vendor_id=0x%x\n", ax |
391 | 416 | ||
392 | cmp ax, 0x8086 |
417 | cmp ax, 0x8086 |
393 | jne .notfound |
418 | jne .notfound |
394 | shr eax, 16 |
419 | shr eax, 16 |
395 | 420 | ||
396 | DEBUGF 1,"Device_id=0x%x\n", ax |
421 | DEBUGF 1,"Device_id=0x%x\n", ax |
397 | 422 | ||
398 | mov ecx, DEVICE_IDs |
423 | mov ecx, DEVICE_IDs |
399 | mov edi, device_id_list |
424 | mov edi, device_id_list |
400 | repne scasw |
425 | repne scasw |
401 | jne .notfound |
426 | jne .notfound |
402 | jmp .found |
427 | jmp .found |
403 | 428 | ||
404 | .notfound: |
429 | .notfound: |
405 | DEBUGF 2,"Unsupported device!\n" |
430 | DEBUGF 2,"Unsupported device!\n" |
406 | or eax, -1 |
431 | or eax, -1 |
407 | ret |
432 | ret |
408 | 433 | ||
409 | .found: |
434 | .found: |
410 | 435 | ||
411 | call ee_get_width |
436 | call ee_get_width |
412 | call MAC_read_eeprom |
437 | call MAC_read_eeprom |
413 | 438 | ||
414 | ;;; TODO: detect phy |
439 | ;;; TODO: detect phy |
415 | 440 | ||
416 | 441 | ||
417 | 442 | ||
418 | ;---------- |
443 | ;---------- |
419 | ; |
444 | ; |
420 | ; Reset |
445 | ; Reset |
421 | ; |
446 | ; |
422 | ;---------- |
447 | ;---------- |
423 | 448 | ||
424 | align 4 |
449 | align 4 |
425 | reset: |
450 | reset: |
426 | 451 | ||
427 | movzx eax, [device.irq_line] |
452 | movzx eax, [ebx + device.irq_line] |
428 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
453 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
429 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
454 | invoke AttachIntHandler, eax, int_handler, ebx |
430 | test eax, eax |
455 | test eax, eax |
431 | jnz @f |
456 | jnz @f |
432 | DEBUGF 2,"Could not attach int handler!\n" |
457 | DEBUGF 2,"Could not attach int handler!\n" |
433 | ; or eax, -1 |
458 | or eax, -1 |
434 | ; ret |
459 | ret |
435 | @@: |
460 | @@: |
436 | 461 | ||
437 | DEBUGF 1,"Resetting\n" |
462 | DEBUGF 1,"Resetting\n" |
438 | 463 | ||
439 | ;--------------- |
464 | ;--------------- |
440 | ; reset the card |
465 | ; reset the card |
441 | 466 | ||
442 | set_io 0 |
467 | set_io [ebx + device.io_addr], 0 |
443 | set_io reg_port |
468 | set_io [ebx + device.io_addr], reg_port |
444 | xor eax, eax ; Software Reset |
469 | xor eax, eax ; Software Reset |
445 | out dx, eax |
470 | out dx, eax |
446 | 471 | ||
447 | mov esi, 10 |
472 | mov esi, 10 |
448 | call Sleep ; Give the card time to warm up. |
473 | invoke Sleep ; Give the card time to warm up. |
449 | 474 | ||
450 | ;--------------------------------- |
475 | ;--------------------------------- |
451 | ; Tell device where to store stats |
476 | ; Tell device where to store stats |
452 | 477 | ||
453 | lea eax, [lstats] |
478 | lea eax, [ebx + device.lstats.tx_good_frames] ; lstats |
454 | GetRealAddr |
479 | invoke GetPhysAddr |
455 | set_io 0 |
480 | set_io [ebx + device.io_addr], 0 |
456 | set_io reg_scb_ptr |
481 | set_io [ebx + device.io_addr], reg_scb_ptr |
457 | out dx, eax |
482 | out dx, eax |
458 | 483 | ||
459 | mov ax, INT_MASK + CU_STATSADDR |
484 | mov ax, INT_MASK + CU_STATSADDR |
460 | set_io reg_scb_cmd |
485 | set_io [ebx + device.io_addr], reg_scb_cmd |
461 | out dx, ax |
486 | out dx, ax |
462 | call cmd_wait |
487 | call cmd_wait |
463 | 488 | ||
464 | ;----------------- |
489 | ;----------------- |
465 | ; setup RX |
490 | ; setup RX |
466 | 491 | ||
467 | set_io reg_scb_ptr |
492 | set_io [ebx + device.io_addr], reg_scb_ptr |
468 | xor eax, eax |
493 | xor eax, eax |
469 | out dx, eax |
494 | out dx, eax |
470 | 495 | ||
471 | set_io reg_scb_cmd |
496 | set_io [ebx + device.io_addr], reg_scb_cmd |
472 | mov ax, INT_MASK + RX_ADDR_LOAD |
497 | mov ax, INT_MASK + RX_ADDR_LOAD |
473 | out dx, ax |
498 | out dx, ax |
474 | call cmd_wait |
499 | call cmd_wait |
475 | 500 | ||
476 | ;----------------------------- |
501 | ;----------------------------- |
477 | ; Create RX and TX descriptors |
502 | ; Create RX and TX descriptors |
478 | 503 | ||
479 | call create_ring |
504 | call create_ring |
480 | 505 | ||
481 | ; RX start |
506 | ; RX start |
482 | 507 | ||
483 | set_io 0 |
508 | set_io [ebx + device.io_addr], 0 |
484 | set_io reg_scb_ptr |
509 | set_io [ebx + device.io_addr], reg_scb_ptr |
485 | mov eax, [device.rx_desc] |
510 | mov eax, [ebx + device.rx_desc] |
486 | GetRealAddr |
511 | invoke GetPhysAddr |
487 | out dx, eax |
512 | out dx, eax |
488 | 513 | ||
489 | mov ax, INT_MASK + RX_START |
514 | mov ax, INT_MASK + RX_START |
490 | set_io reg_scb_cmd |
515 | set_io [ebx + device.io_addr], reg_scb_cmd |
491 | out dx, ax |
516 | out dx, ax |
492 | call cmd_wait |
517 | call cmd_wait |
493 | 518 | ||
494 | ; Set-up TX |
519 | ; Set-up TX |
495 | 520 | ||
496 | set_io reg_scb_ptr |
521 | set_io [ebx + device.io_addr], reg_scb_ptr |
497 | xor eax, eax |
522 | xor eax, eax |
498 | out dx, eax |
523 | out dx, eax |
499 | 524 | ||
500 | set_io reg_scb_cmd |
525 | set_io [ebx + device.io_addr], reg_scb_cmd |
501 | mov ax, INT_MASK + CU_CMD_BASE |
526 | mov ax, INT_MASK + CU_CMD_BASE |
502 | out dx, ax |
527 | out dx, ax |
503 | call cmd_wait |
528 | call cmd_wait |
504 | 529 | ||
505 | ; -------------------- |
530 | ; -------------------- |
506 | 531 | ||
507 | mov [confcmd.command], CmdConfigure + Cmdsuspend |
532 | mov [ebx + device.confcmd.command], CmdConfigure + Cmdsuspend |
508 | mov [confcmd.status], 0 |
533 | mov [ebx + device.confcmd.status], 0 |
509 | lea eax, [txfd] |
534 | lea eax, [ebx + device.txfd.status] |
510 | GetRealAddr |
535 | invoke GetPhysAddr |
511 | mov [confcmd.link], eax |
536 | mov [ebx + device.confcmd.link], eax |
512 | 537 | ||
513 | mov esi, confcmd_data |
538 | mov esi, confcmd_data |
514 | lea edi, [confcmd.data] |
539 | lea edi, [ebx + device.confcmd.data] |
515 | mov ecx, 22 |
540 | mov ecx, 22 |
516 | rep movsb |
541 | rep movsb |
517 | 542 | ||
518 | mov byte[confcmd.data + 1], 0x88 ; fifo of 8 each |
543 | mov byte[ebx + device.confcmd.data + 1], 0x88 ; fifo of 8 each |
519 | mov byte[confcmd.data + 4], 0 |
544 | mov byte[ebx + device.confcmd.data + 4], 0 |
520 | mov byte[confcmd.data + 5], 0x80 |
545 | mov byte[ebx + device.confcmd.data + 5], 0x80 |
521 | mov byte[confcmd.data + 15], 0x48 |
546 | mov byte[ebx + device.confcmd.data + 15], 0x48 |
522 | mov byte[confcmd.data + 19], 0x80 |
547 | mov byte[ebx + device.confcmd.data + 19], 0x80 |
523 | mov byte[confcmd.data + 21], 0x05 |
548 | mov byte[ebx + device.confcmd.data + 21], 0x05 |
524 | 549 | ||
525 | mov [txfd.command], CmdIASetup |
550 | mov [ebx + device.txfd.command], CmdIASetup |
526 | mov [txfd.status], 0 |
551 | mov [ebx + device.txfd.status], 0 |
527 | lea eax, [confcmd] |
552 | lea eax, [ebx + device.confcmd.status] |
528 | GetRealAddr |
553 | invoke GetPhysAddr |
529 | mov [txfd.link], eax |
554 | mov [ebx + device.txfd.link], eax |
530 | 555 | ||
531 | ;;; copy in our MAC |
556 | ;;; copy in our MAC |
532 | 557 | ||
533 | lea edi, [txfd.tx_desc_addr] |
558 | lea edi, [ebx + device.txfd.desc_addr] |
534 | lea esi, [device.mac] |
559 | lea esi, [ebx + device.mac] |
535 | movsd |
560 | movsd |
536 | movsw |
561 | movsw |
537 | 562 | ||
538 | set_io reg_scb_ptr |
563 | set_io [ebx + device.io_addr], reg_scb_ptr |
539 | lea eax, [txfd] |
564 | lea eax, [ebx + device.txfd.status] |
540 | GetRealAddr |
565 | invoke GetPhysAddr |
541 | out dx, eax |
566 | out dx, eax |
542 | 567 | ||
543 | ; Start CU & enable ints |
568 | ; Start CU & enable ints |
544 | 569 | ||
545 | set_io reg_scb_cmd |
570 | set_io [ebx + device.io_addr], reg_scb_cmd |
546 | mov ax, CU_START |
571 | mov ax, CU_START |
547 | out dx, ax |
572 | out dx, ax |
548 | call cmd_wait |
573 | call cmd_wait |
549 | 574 | ||
550 | ;----------------------- |
575 | ;----------------------- |
551 | ; build txfd structure (again!) |
576 | ; build txfd structure (again!) |
552 | 577 | ||
553 | lea eax, [txfd] |
578 | lea eax, [ebx + device.txfd.status] |
554 | GetRealAddr |
579 | invoke GetPhysAddr |
555 | mov [txfd.link], eax |
580 | mov [ebx + device.txfd.link], eax |
556 | mov [txfd.count], 0x02208000 |
581 | mov [ebx + device.txfd.count], 0x02208000 |
557 | lea eax, [txfd.tx_buf_addr0] |
582 | lea eax, [ebx + device.txfd.buf_addr0] |
558 | GetRealAddr |
583 | invoke GetPhysAddr |
559 | mov [txfd.tx_desc_addr], eax |
584 | mov [ebx + device.txfd.desc_addr], eax |
560 | 585 | ||
561 | ; Indicate that we have successfully reset the card |
586 | ; Indicate that we have successfully reset the card |
562 | 587 | ||
563 | DEBUGF 1,"Reset complete\n" |
588 | DEBUGF 1,"Reset complete\n" |
564 | 589 | ||
565 | mov [device.mtu], 1514 |
590 | mov [ebx + device.mtu], 1514 |
566 | 591 | ||
567 | ; Set link state to unknown |
592 | ; Set link state to unknown |
568 | mov [device.state], ETH_LINK_UNKOWN |
593 | mov [ebx + device.state], ETH_LINK_UNKNOWN |
569 | 594 | ||
570 | xor eax, eax ; indicate that we have successfully reset the card |
595 | xor eax, eax ; indicate that we have successfully reset the card |
571 | ret |
596 | ret |
572 | 597 | ||
573 | 598 | ||
574 | align 4 |
599 | align 4 |
575 | create_ring: |
600 | create_ring: |
576 | 601 | ||
577 | DEBUGF 1,"Creating ring\n" |
602 | DEBUGF 1,"Creating ring\n" |
578 | 603 | ||
579 | ;--------------------- |
604 | ;--------------------- |
580 | ; build rxfd structure |
605 | ; build rxfd structure |
581 | 606 | ||
582 | stdcall KernelAlloc, 2000 |
607 | invoke KernelAlloc, 2000 |
583 | mov [device.rx_desc], eax |
608 | mov [ebx + device.rx_desc], eax |
584 | mov esi, eax |
609 | mov esi, eax |
585 | GetRealAddr |
610 | invoke GetPhysAddr |
586 | mov [esi + rxfd.status], 0x0000 |
611 | mov [esi + rxfd.status], 0x0000 |
587 | mov [esi + rxfd.command], 0x0000 |
612 | mov [esi + rxfd.command], 0x0000 |
588 | mov [esi + rxfd.link], eax |
613 | mov [esi + rxfd.link], eax |
589 | mov [esi + rxfd.count], 0 |
614 | mov [esi + rxfd.count], 0 |
590 | mov [esi + rxfd.size], 1528 |
615 | mov [esi + rxfd.size], 1528 |
591 | 616 | ||
592 | ;----------------------- |
617 | ;----------------------- |
593 | ; build txfd structure |
618 | ; build txfd structure |
594 | 619 | ||
595 | lea eax, [txfd] |
620 | lea eax, [ebx + device.txfd.status] |
596 | GetRealAddr |
621 | invoke GetPhysAddr |
597 | mov [txfd.link], eax |
622 | mov [ebx + device.txfd.link], eax |
598 | mov [txfd.count], 0x02208000 |
623 | mov [ebx + device.txfd.count], 0x02208000 |
599 | lea eax, [txfd.tx_buf_addr0] |
624 | lea eax, [ebx + device.txfd.buf_addr0] |
600 | GetRealAddr |
625 | invoke GetPhysAddr |
601 | mov [txfd.tx_desc_addr], eax |
626 | mov [ebx + device.txfd.desc_addr], eax |
602 | 627 | ||
603 | ret |
628 | ret |
604 | 629 | ||
605 | 630 | ||
606 | - | ||
607 | - | ||
608 | 631 | ||
609 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
632 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
610 | ;; ;; |
633 | ;; ;; |
611 | ;; Transmit ;; |
634 | ;; Transmit ;; |
612 | ;; ;; |
635 | ;; ;; |
613 | ;; In: buffer pointer in [esp+4] ;; |
- | |
614 | ;; size of buffer in [esp+8] ;; |
- | |
615 | ;; pointer to device structure in ebx ;; |
636 | ;; In: pointer to device structure in ebx ;; |
616 | ;; ;; |
637 | ;; ;; |
617 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
638 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
618 | - | ||
619 | align 4 |
639 | |
- | 640 | proc transmit stdcall bufferptr, buffersize |
|
- | 641 | ||
- | 642 | pushf |
|
620 | transmit: |
643 | cli |
621 | 644 | ||
622 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
645 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
623 | mov eax, [esp+4] |
646 | mov eax, [bufferptr] |
624 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
647 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
625 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
648 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
626 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
649 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
627 | [eax+13]:2,[eax+12]:2 |
650 | [eax+13]:2,[eax+12]:2 |
628 | 651 | ||
629 | cmp dword [esp+8], 1514 |
652 | cmp [buffersize], 1514 |
630 | ja .error ; packet is too long |
653 | ja .fail |
631 | cmp dword [esp+8], 60 |
654 | cmp [buffersize], 60 |
632 | jb .error ; packet is too short |
655 | jb .fail |
633 | 656 | ||
634 | ;;; TODO: check if current descriptor is in use |
657 | ;;; TODO: check if current descriptor is in use |
635 | ; fill in buffer address and size |
658 | ; fill in buffer address and size |
636 | mov eax, [esp+4] |
- | |
637 | mov [last_tx_buffer], eax ;;; FIXME |
659 | mov [ebx + device.last_tx_buffer], eax |
638 | GetRealAddr |
660 | invoke GetPhysAddr |
639 | mov [txfd.tx_buf_addr0], eax |
661 | mov [ebx + device.txfd.buf_addr0], eax |
640 | mov eax, [esp+8] |
662 | mov ecx, [buffersize] |
641 | mov [txfd.tx_buf_size0], eax |
663 | mov [ebx + device.txfd.buf_size0], ecx |
642 | - | ||
643 | mov [txfd.status], 0 |
- | |
644 | mov [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + 1 shl 15 ;;; EL bit |
- | |
- | 664 | ||
- | 665 | mov [ebx + device.txfd.status], 0 |
|
645 | 666 | mov [ebx + device.txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + 1 shl 15 ;;; EL bit |
|
646 | ; mov [txfd.count], 0x02208000 ;;;;;;;;;;; |
667 | ; mov [txfd.count], 0x02208000 ;;;;;;;;;;; |
647 | 668 | ||
648 | ; Inform device of the new/updated transmit descriptor |
669 | ; Inform device of the new/updated transmit descriptor |
649 | lea eax, [txfd] |
670 | lea eax, [ebx + device.txfd.status] |
650 | GetRealAddr |
671 | invoke GetPhysAddr |
651 | set_io 0 |
672 | set_io [ebx + device.io_addr], 0 |
652 | set_io reg_scb_ptr |
673 | set_io [ebx + device.io_addr], reg_scb_ptr |
653 | out dx, eax |
674 | out dx, eax |
654 | 675 | ||
655 | ; Start the transmit |
676 | ; Start the transmit |
656 | mov ax, CU_START |
677 | mov ax, CU_START |
657 | set_io reg_scb_cmd |
678 | set_io [ebx + device.io_addr], reg_scb_cmd |
658 | out dx, ax |
679 | out dx, ax |
659 | call cmd_wait |
680 | call cmd_wait |
660 | - | ||
661 | ; set_io 0 ;; why? |
- | |
662 | ; in ax, dx ;; |
- | |
663 | ; |
- | |
664 | ; @@: |
- | |
665 | ; cmp [txfd.status], 0 ; wait for completion? dont seems a good idea to me.. |
- | |
666 | ; je @r |
- | |
667 | ; |
- | |
668 | ; set_io 0 ;; why? |
- | |
669 | ; in ax, dx ;; |
- | |
670 | 681 | ||
671 | ; Update stats |
682 | ; Update stats |
672 | inc [device.packets_tx] |
683 | inc [ebx + device.packets_tx] |
673 | mov eax, [esp + 8] |
684 | mov ecx, [buffersize] |
674 | add dword [device.bytes_tx], eax |
685 | add dword[ebx + device.bytes_tx], ecx |
675 | adc dword [device.bytes_tx + 4], 0 |
686 | adc dword[ebx + device.bytes_tx + 4], 0 |
676 | 687 | ||
677 | DEBUGF 1,"Transmit OK\n" |
688 | DEBUGF 1,"Transmit OK\n" |
678 | 689 | popf |
|
679 | xor eax, eax |
690 | xor eax, eax |
680 | ret 8 |
691 | ret |
- | 692 | ||
681 | 693 | .fail: |
|
682 | .error: |
694 | invoke KernelFree, [bufferptr] |
- | 695 | popf |
|
- | 696 | or eax, -1 |
|
- | 697 | ret |
|
683 | stdcall KernelFree, [esp+4] |
698 | |
684 | or eax, -1 |
699 | endp |
685 | ret 8 |
700 | |
686 | 701 | ||
687 | ;;;;;;;;;;;;;;;;;;;;;;; |
702 | ;;;;;;;;;;;;;;;;;;;;;;; |
688 | ;; ;; |
703 | ;; ;; |
689 | ;; Interrupt handler ;; |
704 | ;; Interrupt handler ;; |
690 | ;; ;; |
705 | ;; ;; |
691 | ;;;;;;;;;;;;;;;;;;;;;;; |
706 | ;;;;;;;;;;;;;;;;;;;;;;; |
692 | 707 | ||
693 | align 4 |
708 | align 4 |
694 | int_handler: |
709 | int_handler: |
695 | 710 | ||
696 | push ebx esi edi |
711 | push ebx esi edi |
697 | 712 | ||
698 | DEBUGF 1,"INT\n" |
713 | DEBUGF 1,"INT\n" |
699 | 714 | ||
700 | ; find pointer of device wich made IRQ occur |
715 | ; find pointer of device wich made IRQ occur |
701 | 716 | ||
702 | mov ecx, [devices] |
717 | mov ecx, [devices] |
703 | test ecx, ecx |
718 | test ecx, ecx |
704 | jz .nothing |
719 | jz .nothing |
705 | mov esi, device_list |
720 | mov esi, device_list |
706 | .nextdevice: |
721 | .nextdevice: |
707 | mov ebx, [esi] |
722 | mov ebx, [esi] |
708 | 723 | ||
709 | ; set_io 0 ; reg_scb_status = 0 |
724 | ; set_io [ebx + device.io_addr], 0 ; reg_scb_status = 0 |
710 | set_io reg_scb_status |
725 | set_io [ebx + device.io_addr], reg_scb_status |
711 | in ax, dx |
726 | in ax, dx |
712 | out dx, ax ; send it back to ACK |
727 | out dx, ax ; send it back to ACK |
713 | test ax, ax |
728 | test ax, ax |
714 | jnz .got_it |
729 | jnz .got_it |
715 | .continue: |
730 | .continue: |
716 | add esi, 4 |
731 | add esi, 4 |
717 | dec ecx |
732 | dec ecx |
718 | jnz .nextdevice |
733 | jnz .nextdevice |
719 | .nothing: |
734 | .nothing: |
720 | pop edi esi ebx |
735 | pop edi esi ebx |
721 | xor eax, eax |
736 | xor eax, eax |
722 | 737 | ||
723 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
738 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
724 | 739 | ||
725 | .got_it: |
740 | .got_it: |
726 | 741 | ||
727 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
742 | DEBUGF 1,"Device: %x Status: %x\n", ebx, ax |
728 | 743 | ||
729 | test ax, 1 shl 14 ; did we receive a frame? |
744 | test ax, 1 shl 14 ; did we receive a frame? |
730 | jz .no_rx |
745 | jz .no_rx |
731 | 746 | ||
732 | push ax |
747 | push ax |
733 | 748 | ||
734 | DEBUGF 1,"Receiving\n" |
749 | DEBUGF 1,"Receiving\n" |
735 | 750 | ||
736 | push ebx |
751 | push ebx |
737 | .rx_loop: |
752 | .rx_loop: |
738 | pop ebx |
753 | pop ebx |
739 | 754 | ||
740 | mov esi, [device.rx_desc] |
755 | mov esi, [ebx + device.rx_desc] |
741 | cmp [esi + rxfd.status], 0 ; we could also check bits C and OK (bit 15 and 13) |
756 | cmp [esi + rxfd.status], 0 ; we could also check bits C and OK (bit 15 and 13) |
742 | je .nodata |
757 | je .nodata |
743 | 758 | ||
744 | DEBUGF 1,"rxfd status=0x%x\n", [esi + rxfd.status]:4 |
759 | DEBUGF 1,"rxfd status=0x%x\n", [esi + rxfd.status]:4 |
745 | 760 | ||
746 | movzx ecx, [esi + rxfd.count] |
761 | movzx ecx, [esi + rxfd.count] |
747 | and ecx, 0x3fff |
762 | and ecx, 0x3fff |
748 | 763 | ||
749 | push ebx |
764 | push ebx |
750 | push .rx_loop |
765 | push .rx_loop |
751 | push ecx |
766 | push ecx |
752 | add esi, rxfd.packet |
767 | add esi, rxfd.packet |
753 | push esi |
768 | push esi |
754 | 769 | ||
755 | ; Update stats |
770 | ; Update stats |
756 | add dword [device.bytes_rx], ecx |
771 | add dword [ebx + device.bytes_rx], ecx |
757 | adc dword [device.bytes_rx + 4], 0 |
772 | adc dword [ebx + device.bytes_rx + 4], 0 |
758 | inc dword [device.packets_rx] |
773 | inc dword [ebx + device.packets_rx] |
759 | 774 | ||
760 | ; allocate new descriptor |
775 | ; allocate new descriptor |
761 | 776 | ||
762 | stdcall KernelAlloc, 2000 |
777 | invoke KernelAlloc, 2000 |
763 | mov [device.rx_desc], eax |
778 | mov [ebx + device.rx_desc], eax |
764 | mov esi, eax |
779 | mov esi, eax |
765 | GetRealAddr |
780 | invoke GetPhysAddr |
766 | mov [esi + rxfd.status], 0x0000 |
781 | mov [esi + rxfd.status], 0x0000 |
767 | mov [esi + rxfd.command], 0xc000 ; End of list + Suspend |
782 | mov [esi + rxfd.command], 0xc000 ; End of list + Suspend |
768 | mov [esi + rxfd.link], eax |
783 | mov [esi + rxfd.link], eax |
769 | mov [esi + rxfd.count], 0 |
784 | mov [esi + rxfd.count], 0 |
770 | mov [esi + rxfd.size], 1528 |
785 | mov [esi + rxfd.size], 1528 |
771 | 786 | ||
772 | ; restart RX |
787 | ; restart RX |
773 | 788 | ||
774 | set_io 0 |
789 | set_io [ebx + device.io_addr], 0 |
775 | set_io reg_scb_ptr |
790 | set_io [ebx + device.io_addr], reg_scb_ptr |
776 | ; lea eax, [device.rx_desc] |
791 | ; lea eax, [ebx + device.rx_desc] |
777 | ; GetRealAddr |
792 | ; invoke GetPhysAddr |
778 | out dx, eax |
793 | out dx, eax |
779 | 794 | ||
780 | set_io reg_scb_cmd |
795 | set_io [ebx + device.io_addr], reg_scb_cmd |
781 | mov ax, RX_START |
796 | mov ax, RX_START |
782 | out dx, ax |
797 | out dx, ax |
783 | call cmd_wait |
798 | call cmd_wait |
784 | 799 | ||
785 | ; And give packet to kernel |
800 | ; And give packet to kernel |
786 | - | ||
787 | jmp Eth_input |
801 | jmp [Eth_input] |
788 | 802 | ||
789 | .nodata: |
803 | .nodata: |
790 | DEBUGF 1, "no more data\n" |
804 | DEBUGF 1, "no more data\n" |
791 | pop ax |
805 | pop ax |
792 | 806 | ||
793 | .no_rx: |
807 | .no_rx: |
794 | 808 | ||
795 | ; Cleanup after TX |
809 | ; Cleanup after TX |
796 | cmp [txfd.status], 0 |
810 | cmp [ebx + device.txfd.status], 0 |
797 | je .done |
811 | je .done |
798 | cmp [last_tx_buffer], 0 |
812 | cmp [ebx + device.last_tx_buffer], 0 |
799 | je .done |
813 | je .done |
800 | push ax |
814 | push ax |
801 | DEBUGF 1, "Removing packet 0x%x from RAM!\n", [last_tx_buffer] |
815 | DEBUGF 1, "Removing packet 0x%x from RAM!\n", [ebx + device.last_tx_buffer] |
802 | stdcall KernelFree, [last_tx_buffer] |
816 | invoke KernelFree, [ebx + device.last_tx_buffer] |
803 | mov [last_tx_buffer], 0 |
817 | mov [ebx + device.last_tx_buffer], 0 |
804 | pop ax |
818 | pop ax |
805 | 819 | ||
806 | .done: |
820 | .done: |
807 | and ax, 00111100b |
821 | and ax, 00111100b |
808 | cmp ax, 00001000b |
822 | cmp ax, 00001000b |
809 | jne .fail |
823 | jne .fail |
810 | 824 | ||
811 | DEBUGF 1, "out of resources!\n" |
825 | DEBUGF 1, "out of resources!\n" |
812 | ; Restart the RX |
826 | ; Restart the RX |
813 | 827 | ||
814 | ; allocate new descriptor |
828 | ; allocate new descriptor |
815 | 829 | ||
816 | stdcall KernelAlloc, 2000 |
830 | invoke KernelAlloc, 2000 |
817 | mov [device.rx_desc], eax |
831 | mov [ebx + device.rx_desc], eax |
818 | mov esi, eax |
832 | mov esi, eax |
819 | GetRealAddr |
833 | invoke GetPhysAddr |
820 | mov [esi + rxfd.status], 0x0000 |
834 | mov [esi + rxfd.status], 0x0000 |
821 | mov [esi + rxfd.command], 0xc000 ; End of list + Suspend |
835 | mov [esi + rxfd.command], 0xc000 ; End of list + Suspend |
822 | mov [esi + rxfd.link], eax |
836 | mov [esi + rxfd.link], eax |
823 | mov [esi + rxfd.count], 0 |
837 | mov [esi + rxfd.count], 0 |
824 | mov [esi + rxfd.size], 1528 |
838 | mov [esi + rxfd.size], 1528 |
825 | 839 | ||
826 | ; restart RX |
840 | ; restart RX |
827 | 841 | ||
828 | set_io 0 |
842 | set_io [ebx + device.io_addr], 0 |
829 | set_io reg_scb_ptr |
843 | set_io [ebx + device.io_addr], reg_scb_ptr |
830 | ; lea eax, [device.rx_desc] |
844 | ; lea eax, [ebx + device.rx_desc] |
831 | ; GetRealAddr |
845 | ; invoke GetPhysAddr |
832 | out dx, eax |
846 | out dx, eax |
833 | 847 | ||
834 | set_io reg_scb_cmd |
848 | set_io [ebx + device.io_addr], reg_scb_cmd |
835 | mov ax, RX_START |
849 | mov ax, RX_START |
836 | out dx, ax |
850 | out dx, ax |
837 | call cmd_wait |
851 | call cmd_wait |
838 | 852 | ||
839 | .fail: |
853 | .fail: |
840 | pop edi esi ebx |
854 | pop edi esi ebx |
841 | xor eax, eax |
855 | xor eax, eax |
842 | inc eax |
856 | inc eax |
843 | 857 | ||
844 | ret |
858 | ret |
845 | 859 | ||
846 | 860 | ||
847 | 861 | ||
848 | 862 | ||
849 | align 4 |
863 | align 4 |
850 | cmd_wait: |
864 | cmd_wait: |
851 | 865 | ||
852 | in al, dx |
866 | in al, dx |
853 | test al, al |
867 | test al, al |
854 | jnz cmd_wait |
868 | jnz cmd_wait |
855 | 869 | ||
856 | ret |
870 | ret |
857 | 871 | ||
858 | 872 | ||
859 | 873 | ||
860 | 874 | ||
861 | 875 | ||
862 | 876 | ||
863 | align 4 |
877 | align 4 |
864 | ee_read: ; esi = address to read |
878 | ee_read: ; esi = address to read |
865 | 879 | ||
866 | DEBUGF 1,"Eeprom read from 0x%x\n", esi |
880 | DEBUGF 1,"Eeprom read from 0x%x\n", esi |
867 | 881 | ||
868 | set_io 0 |
882 | set_io [ebx + device.io_addr], 0 |
869 | set_io reg_eeprom |
883 | set_io [ebx + device.io_addr], reg_eeprom |
870 | 884 | ||
871 | ;----------------------------------------------------- |
885 | ;----------------------------------------------------- |
872 | ; Prepend start bit + read opcode to the address field |
886 | ; Prepend start bit + read opcode to the address field |
873 | ; and shift it to the very left bits of esi |
887 | ; and shift it to the very left bits of esi |
874 | 888 | ||
875 | mov cl, 29 |
889 | mov cl, 29 |
876 | sub cl, [device.ee_bus_width] |
890 | sub cl, [ebx + device.ee_bus_width] |
877 | shl esi, cl |
891 | shl esi, cl |
878 | or esi, EE_READ shl 29 |
892 | or esi, EE_READ shl 29 |
879 | 893 | ||
880 | movzx ecx, [device.ee_bus_width] |
894 | movzx ecx, [ebx + device.ee_bus_width] |
881 | add ecx, 3 |
895 | add ecx, 3 |
882 | 896 | ||
883 | mov al, EE_CS |
897 | mov al, EE_CS |
884 | out dx, al |
898 | out dx, al |
885 | delay |
899 | delay |
886 | 900 | ||
887 | ;----------------------- |
901 | ;----------------------- |
888 | ; Write this to the chip |
902 | ; Write this to the chip |
889 | 903 | ||
890 | .loop: |
904 | .loop: |
891 | mov al, EE_CS + EE_SK |
905 | mov al, EE_CS + EE_SK |
892 | shl esi, 1 |
906 | shl esi, 1 |
893 | jnc @f |
907 | jnc @f |
894 | or al, EE_DI |
908 | or al, EE_DI |
895 | @@: |
909 | @@: |
896 | out dx, al |
910 | out dx, al |
897 | delay |
911 | delay |
898 | 912 | ||
899 | and al, not EE_SK |
913 | and al, not EE_SK |
900 | out dx, al |
914 | out dx, al |
901 | delay |
915 | delay |
902 | 916 | ||
903 | loop .loop |
917 | loop .loop |
904 | 918 | ||
905 | ;------------------------------ |
919 | ;------------------------------ |
906 | ; Now read the data from eeprom |
920 | ; Now read the data from eeprom |
907 | 921 | ||
908 | xor esi, esi |
922 | xor esi, esi |
909 | mov ecx, 16 |
923 | mov ecx, 16 |
910 | 924 | ||
911 | .loop2: |
925 | .loop2: |
912 | shl esi, 1 |
926 | shl esi, 1 |
913 | mov al, EE_CS + EE_SK |
927 | mov al, EE_CS + EE_SK |
914 | out dx, al |
928 | out dx, al |
915 | delay |
929 | delay |
916 | 930 | ||
917 | in al, dx |
931 | in al, dx |
918 | test al, EE_DO |
932 | test al, EE_DO |
919 | jz @f |
933 | jz @f |
920 | inc esi |
934 | inc esi |
921 | @@: |
935 | @@: |
922 | 936 | ||
923 | mov al, EE_CS |
937 | mov al, EE_CS |
924 | out dx, al |
938 | out dx, al |
925 | delay |
939 | delay |
926 | 940 | ||
927 | loop .loop2 |
941 | loop .loop2 |
928 | 942 | ||
929 | ;----------------------- |
943 | ;----------------------- |
930 | ; de-activate the eeprom |
944 | ; de-activate the eeprom |
931 | 945 | ||
932 | xor ax, ax |
946 | xor ax, ax |
933 | out dx, ax |
947 | out dx, ax |
934 | 948 | ||
935 | 949 | ||
936 | DEBUGF 1,"0x%x\n", esi:4 |
950 | DEBUGF 1,"0x%x\n", esi:4 |
937 | ret |
951 | ret |
938 | 952 | ||
939 | 953 | ||
940 | 954 | ||
941 | align 4 |
955 | align 4 |
942 | ee_write: ; esi = address to write to, di = data |
956 | ee_write: ; esi = address to write to, di = data |
943 | 957 | ||
944 | DEBUGF 1,"Eeprom write 0x%x to 0x%x\n", di, esi |
958 | DEBUGF 1,"Eeprom write 0x%x to 0x%x\n", di, esi |
945 | 959 | ||
946 | set_io 0 |
960 | set_io [ebx + device.io_addr], 0 |
947 | set_io reg_eeprom |
961 | set_io [ebx + device.io_addr], reg_eeprom |
948 | 962 | ||
949 | ;----------------------------------------------------- |
963 | ;----------------------------------------------------- |
950 | ; Prepend start bit + write opcode to the address field |
964 | ; Prepend start bit + write opcode to the address field |
951 | ; and shift it to the very left bits of esi |
965 | ; and shift it to the very left bits of esi |
952 | 966 | ||
953 | mov cl, 29 |
967 | mov cl, 29 |
954 | sub cl, [device.ee_bus_width] |
968 | sub cl, [ebx + device.ee_bus_width] |
955 | shl esi, cl |
969 | shl esi, cl |
956 | or esi, EE_WRITE shl 29 |
970 | or esi, EE_WRITE shl 29 |
957 | 971 | ||
958 | movzx ecx, [device.ee_bus_width] |
972 | movzx ecx, [ebx + device.ee_bus_width] |
959 | add ecx, 3 |
973 | add ecx, 3 |
960 | 974 | ||
961 | mov al, EE_CS ; enable chip |
975 | mov al, EE_CS ; enable chip |
962 | out dx, al |
976 | out dx, al |
963 | 977 | ||
964 | ;----------------------- |
978 | ;----------------------- |
965 | ; Write this to the chip |
979 | ; Write this to the chip |
966 | 980 | ||
967 | .loop: |
981 | .loop: |
968 | mov al, EE_CS + EE_SK |
982 | mov al, EE_CS + EE_SK |
969 | shl esi, 1 |
983 | shl esi, 1 |
970 | jnc @f |
984 | jnc @f |
971 | or al, EE_DI |
985 | or al, EE_DI |
972 | @@: |
986 | @@: |
973 | out dx, al |
987 | out dx, al |
974 | delay |
988 | delay |
975 | 989 | ||
976 | and al, not EE_SK |
990 | and al, not EE_SK |
977 | out dx, al |
991 | out dx, al |
978 | delay |
992 | delay |
979 | 993 | ||
980 | loop .loop |
994 | loop .loop |
981 | 995 | ||
982 | ;----------------------------- |
996 | ;----------------------------- |
983 | ; Now write the data to eeprom |
997 | ; Now write the data to eeprom |
984 | 998 | ||
985 | mov ecx, 16 |
999 | mov ecx, 16 |
986 | 1000 | ||
987 | .loop2: |
1001 | .loop2: |
988 | mov al, EE_CS + EE_SK |
1002 | mov al, EE_CS + EE_SK |
989 | shl di, 1 |
1003 | shl di, 1 |
990 | jnc @f |
1004 | jnc @f |
991 | or al, EE_DI |
1005 | or al, EE_DI |
992 | @@: |
1006 | @@: |
993 | out dx, al |
1007 | out dx, al |
994 | delay |
1008 | delay |
995 | 1009 | ||
996 | and al, not EE_SK |
1010 | and al, not EE_SK |
997 | out dx, al |
1011 | out dx, al |
998 | delay |
1012 | delay |
999 | 1013 | ||
1000 | loop .loop2 |
1014 | loop .loop2 |
1001 | 1015 | ||
1002 | ;----------------------- |
1016 | ;----------------------- |
1003 | ; de-activate the eeprom |
1017 | ; de-activate the eeprom |
1004 | 1018 | ||
1005 | xor al, al |
1019 | xor al, al |
1006 | out dx, al |
1020 | out dx, al |
1007 | 1021 | ||
1008 | 1022 | ||
1009 | ret |
1023 | ret |
1010 | 1024 | ||
1011 | 1025 | ||
1012 | 1026 | ||
1013 | align 4 |
1027 | align 4 |
1014 | ee_get_width: |
1028 | ee_get_width: |
1015 | 1029 | ||
1016 | set_io 0 |
1030 | set_io [ebx + device.io_addr], 0 |
1017 | set_io reg_eeprom |
1031 | set_io [ebx + device.io_addr], reg_eeprom |
1018 | 1032 | ||
1019 | mov al, EE_CS ; activate eeprom |
1033 | mov al, EE_CS ; activate eeprom |
1020 | out dx, al |
1034 | out dx, al |
1021 | delay |
1035 | delay |
1022 | 1036 | ||
1023 | mov si, EE_READ shl 13 |
1037 | mov si, EE_READ shl 13 |
1024 | xor ecx, ecx |
1038 | xor ecx, ecx |
1025 | .loop: |
1039 | .loop: |
1026 | mov al, EE_CS + EE_SK |
1040 | mov al, EE_CS + EE_SK |
1027 | shl si, 1 |
1041 | shl si, 1 |
1028 | jnc @f |
1042 | jnc @f |
1029 | or al, EE_DI |
1043 | or al, EE_DI |
1030 | @@: |
1044 | @@: |
1031 | out dx, al |
1045 | out dx, al |
1032 | delay |
1046 | delay |
1033 | 1047 | ||
1034 | and al, not EE_SK |
1048 | and al, not EE_SK |
1035 | out dx, al |
1049 | out dx, al |
1036 | delay |
1050 | delay |
1037 | 1051 | ||
1038 | inc ecx |
1052 | inc ecx |
1039 | 1053 | ||
1040 | cmp ecx, 15 |
1054 | cmp ecx, 15 |
1041 | jae .give_up |
1055 | jae .give_up |
1042 | 1056 | ||
1043 | in al, dx |
1057 | in al, dx |
1044 | test al, EE_DO |
1058 | test al, EE_DO |
1045 | jnz .loop |
1059 | jnz .loop |
1046 | 1060 | ||
1047 | xor al, al |
1061 | xor al, al |
1048 | out dx, al ; de-activate eeprom |
1062 | out dx, al ; de-activate eeprom |
1049 | 1063 | ||
1050 | sub cl, 3 ; dont count the opcode bits |
1064 | sub cl, 3 ; dont count the opcode bits |
1051 | mov [device.ee_bus_width], cl |
1065 | mov [ebx + device.ee_bus_width], cl |
1052 | DEBUGF 1, "Eeprom width=%u bit\n", ecx |
1066 | DEBUGF 1, "Eeprom width=%u bit\n", ecx |
1053 | 1067 | ||
1054 | ret |
1068 | ret |
1055 | 1069 | ||
1056 | .give_up: |
1070 | .give_up: |
1057 | DEBUGF 2, "Eeprom not found!\n" |
1071 | DEBUGF 2, "Eeprom not found!\n" |
1058 | 1072 | ||
1059 | xor al, al |
1073 | xor al, al |
1060 | out dx, al ; de-activate eeprom |
1074 | out dx, al ; de-activate eeprom |
1061 | 1075 | ||
1062 | ret |
1076 | ret |
1063 | 1077 | ||
1064 | 1078 | ||
1065 | 1079 | ||
1066 | ; cx = phy addr |
1080 | ; cx = phy addr |
1067 | ; dx = phy reg addr |
1081 | ; dx = phy reg addr |
1068 | 1082 | ||
1069 | ; ax = data |
1083 | ; ax = data |
1070 | 1084 | ||
1071 | align 4 |
1085 | align 4 |
1072 | mdio_read: |
1086 | mdio_read: |
1073 | 1087 | ||
1074 | DEBUGF 1,"MDIO read\n" |
1088 | DEBUGF 1,"MDIO read\n" |
1075 | 1089 | ||
1076 | shl ecx, 21 ; PHY addr |
1090 | shl ecx, 21 ; PHY addr |
1077 | shl edx, 16 ; PHY reg addr |
1091 | shl edx, 16 ; PHY reg addr |
1078 | 1092 | ||
1079 | mov eax, ecx |
1093 | mov eax, ecx |
1080 | or eax, edx |
1094 | or eax, edx |
1081 | or eax, 10b shl 26 ; read opcode |
1095 | or eax, 10b shl 26 ; read opcode |
1082 | 1096 | ||
1083 | set_io 0 |
1097 | set_io [ebx + device.io_addr], 0 |
1084 | set_io reg_mdi_ctrl |
1098 | set_io [ebx + device.io_addr], reg_mdi_ctrl |
1085 | out dx, eax |
1099 | out dx, eax |
1086 | 1100 | ||
1087 | .wait: |
1101 | .wait: |
1088 | delay |
1102 | delay |
1089 | in eax, dx |
1103 | in eax, dx |
1090 | test eax, 1 shl 28 ; ready bit |
1104 | test eax, 1 shl 28 ; ready bit |
1091 | jz .wait |
1105 | jz .wait |
1092 | 1106 | ||
1093 | ret |
1107 | ret |
1094 | 1108 | ||
1095 | ; ax = data |
1109 | ; ax = data |
1096 | ; cx = phy addr |
1110 | ; cx = phy addr |
1097 | ; dx = phy reg addr |
1111 | ; dx = phy reg addr |
1098 | 1112 | ||
1099 | ; ax = data |
1113 | ; ax = data |
1100 | 1114 | ||
1101 | align 4 |
1115 | align 4 |
1102 | mdio_write: |
1116 | mdio_write: |
1103 | 1117 | ||
1104 | DEBUGF 1,"MDIO write\n" |
1118 | DEBUGF 1,"MDIO write\n" |
1105 | 1119 | ||
1106 | and eax, 0xffff |
1120 | and eax, 0xffff |
1107 | 1121 | ||
1108 | shl ecx, 21 ; PHY addr |
1122 | shl ecx, 21 ; PHY addr |
1109 | shl edx, 16 ; PHY reg addr |
1123 | shl edx, 16 ; PHY reg addr |
1110 | 1124 | ||
1111 | or eax, ecx |
1125 | or eax, ecx |
1112 | or eax, edx |
1126 | or eax, edx |
1113 | or eax, 01b shl 26 ; write opcode |
1127 | or eax, 01b shl 26 ; write opcode |
1114 | 1128 | ||
1115 | set_io 0 |
1129 | set_io [ebx + device.io_addr], 0 |
1116 | set_io reg_mdi_ctrl |
1130 | set_io [ebx + device.io_addr], reg_mdi_ctrl |
1117 | out dx, eax |
1131 | out dx, eax |
1118 | 1132 | ||
1119 | .wait: |
1133 | .wait: |
1120 | delay |
1134 | delay |
1121 | in eax, dx |
1135 | in eax, dx |
1122 | test eax, 1 shl 28 ; ready bit |
1136 | test eax, 1 shl 28 ; ready bit |
1123 | jz .wait |
1137 | jz .wait |
1124 | 1138 | ||
1125 | ret |
1139 | ret |
1126 | 1140 | ||
1127 | read_mac: |
1141 | read_mac: |
1128 | 1142 | ||
1129 | ret |
1143 | ret |
1130 | 1144 | ||
1131 | 1145 | ||
1132 | 1146 | ||
1133 | align 4 |
1147 | align 4 |
1134 | MAC_read_eeprom: |
1148 | MAC_read_eeprom: |
1135 | 1149 | ||
1136 | mov esi, 0 |
1150 | mov esi, 0 |
1137 | call ee_read |
1151 | call ee_read |
1138 | mov word[device.mac], si |
1152 | mov word[ebx + device.mac], si |
1139 | 1153 | ||
1140 | mov esi, 1 |
1154 | mov esi, 1 |
1141 | call ee_read |
1155 | call ee_read |
1142 | mov word[device.mac+2], si |
1156 | mov word[ebx + device.mac+2], si |
1143 | 1157 | ||
1144 | mov esi, 2 |
1158 | mov esi, 2 |
1145 | call ee_read |
1159 | call ee_read |
1146 | mov word[device.mac+4], si |
1160 | mov word[ebx + device.mac+4], si |
1147 | 1161 | ||
1148 | 1162 | ||
1149 | ret |
1163 | ret |
1150 | 1164 | ||
1151 | 1165 | ||
1152 | align 4 |
1166 | align 4 |
1153 | MAC_write: |
1167 | MAC_write: |
1154 | 1168 | ||
1155 | ;;;; |
1169 | ;;;; |
1156 | 1170 | ||
1157 | ret |
1171 | ret |
1158 | 1172 | ||
1159 | 1173 | ||
1160 | 1174 | ||
1161 | 1175 | ||
1162 | ; End of code |
1176 | ; End of code |
1163 | - | ||
1164 | align 4 ; Place all initialised data here |
- | |
- | 1177 | ||
- | 1178 | ||
- | 1179 | data fixups |
|
1165 | 1180 | end data |
|
- | 1181 | ||
1166 | devices dd 0 ; number of currently running devices |
1182 | include '../peimport.inc' |
1167 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
1183 | |
1168 | my_service db 'i8255x', 0 ; max 16 chars include zero |
1184 | my_service db 'i8255x', 0 ; max 16 chars include zero |
1169 | devicename db 'Intel Etherexpress pro/100', 0 |
1185 | devicename db 'Intel Etherexpress pro/100', 0 |
1170 | 1186 | ||
1171 | confcmd_data db 22, 0x08, 0, 0, 0, 0x80, 0x32, 0x03, 1 |
1187 | confcmd_data db 22, 0x08, 0, 0, 0, 0x80, 0x32, 0x03, 1 |
1172 | db 0, 0x2e, 0, 0x60, 0, 0xf2, 0x48, 0, 0x40, 0xf2 |
1188 | db 0, 0x2e, 0, 0x60, 0, 0xf2, 0x48, 0, 0x40, 0xf2 |
1173 | db 0x80, 0x3f, 0x05 ; 22 bytes total |
1189 | db 0x80, 0x3f, 0x05 ; 22 bytes total |
1174 | 1190 | ||
1175 | 1191 | ||
1176 | device_id_list: |
1192 | device_id_list: |
1177 | 1193 | ||
1178 | dw 0x1029 |
1194 | dw 0x1029 |
1179 | dw 0x1030 |
1195 | dw 0x1030 |
1180 | dw 0x1031 |
1196 | dw 0x1031 |
1181 | dw 0x1032 |
1197 | dw 0x1032 |
1182 | dw 0x1033 |
1198 | dw 0x1033 |
1183 | dw 0x1034 |
1199 | dw 0x1034 |
1184 | dw 0x1038 |
1200 | dw 0x1038 |
1185 | dw 0x1039 |
1201 | dw 0x1039 |
1186 | dw 0x103A |
1202 | dw 0x103A |
1187 | dw 0x103B |
1203 | dw 0x103B |
1188 | dw 0x103C |
1204 | dw 0x103C |
1189 | dw 0x103D |
1205 | dw 0x103D |
1190 | dw 0x103E |
1206 | dw 0x103E |
1191 | dw 0x1050 |
1207 | dw 0x1050 |
1192 | dw 0x1051 |
1208 | dw 0x1051 |
1193 | dw 0x1052 |
1209 | dw 0x1052 |
1194 | dw 0x1053 |
1210 | dw 0x1053 |
1195 | dw 0x1054 |
1211 | dw 0x1054 |
1196 | dw 0x1055 |
1212 | dw 0x1055 |
1197 | dw 0x1056 |
1213 | dw 0x1056 |
1198 | dw 0x1057 |
1214 | dw 0x1057 |
1199 | dw 0x1059 |
1215 | dw 0x1059 |
1200 | dw 0x1064 |
1216 | dw 0x1064 |
1201 | dw 0x1065 |
1217 | dw 0x1065 |
1202 | dw 0x1066 |
1218 | dw 0x1066 |
1203 | dw 0x1067 |
1219 | dw 0x1067 |
1204 | dw 0x1068 |
1220 | dw 0x1068 |
1205 | dw 0x1069 |
1221 | dw 0x1069 |
1206 | dw 0x106A |
1222 | dw 0x106A |
1207 | dw 0x106B |
1223 | dw 0x106B |
1208 | dw 0x1091 |
1224 | dw 0x1091 |
1209 | dw 0x1092 |
1225 | dw 0x1092 |
1210 | dw 0x1093 |
1226 | dw 0x1093 |
1211 | dw 0x1094 |
1227 | dw 0x1094 |
1212 | dw 0x1095 |
1228 | dw 0x1095 |
1213 | dw 0x10fe |
1229 | dw 0x10fe |
1214 | dw 0x1209 |
1230 | dw 0x1209 |
1215 | dw 0x1229 |
1231 | dw 0x1229 |
1216 | dw 0x2449 |
1232 | dw 0x2449 |
1217 | dw 0x2459 |
1233 | dw 0x2459 |
1218 | dw 0x245D |
1234 | dw 0x245D |
1219 | dw 0x27DC |
1235 | dw 0x27DC |
1220 | 1236 | ||
1221 | DEVICE_IDs = ($ - device_id_list) / 2 |
1237 | DEVICE_IDs = ($ - device_id_list) / 2 |
1222 | - | ||
1223 | mac_82557_D100_A = 0 |
- | |
1224 | mac_82557_D100_B = 1 |
- | |
1225 | mac_82557_D100_C = 2 |
- | |
1226 | mac_82558_D101_A4 = 4 |
- | |
1227 | mac_82558_D101_B0 = 5 |
- | |
1228 | mac_82559_D101M = 8 |
- | |
1229 | mac_82559_D101S = 9 |
- | |
1230 | mac_82550_D102 = 12 |
- | |
1231 | mac_82550_D102_C = 13 |
- | |
1232 | mac_82551_E = 14 |
- | |
1233 | mac_82551_F = 15 |
- | |
1234 | mac_82551_10 = 16 |
- | |
1235 | mac_unknown = 0xFF |
- | |
1236 | - | ||
1237 | phy_100a = 0x000003E0 |
- | |
1238 | phy_100c = 0x035002A8 |
- | |
1239 | phy_82555_tx = 0x015002A8 |
- | |
1240 | phy_nsc_tx = 0x5C002000 |
- | |
1241 | phy_82562_et = 0x033002A8 |
- | |
1242 | phy_82562_em = 0x032002A8 |
- | |
1243 | phy_82562_ek = 0x031002A8 |
- | |
1244 | phy_82562_eh = 0x017002A8 |
- | |
1245 | phy_82552_v = 0xd061004d |
- | |
1246 | phy_unknown = 0xFFFFFFFF |
- | |
1247 | - | ||
1248 | 1238 | ||
- | 1239 | include_debug_strings ; All data wich FDO uses will be included here |
|
1249 | include_debug_strings ; All data wich FDO uses will be included here |
1240 | |
1250 | - | ||
1251 | section '.data' data readable writable align 16 ; place all uninitialized data place here |
1241 | align 4 |
1252 | 1242 | devices dd 0 ; number of currently running devices |
|
1253 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |
1243 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |