Rev 1519 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1159 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
1514 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;; |
1159 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
1519 | hidnplayr | 6 | ;; Realtek 8139 driver for KolibriOS ;; |
1159 | hidnplayr | 7 | ;; ;; |
1519 | hidnplayr | 8 | ;; based on RTL8139.asm driver for menuetos ;; |
9 | ;; and realtek8139.asm for SolarOS by Eugen Brasoveanu ;; |
||
10 | ;; ;; |
||
1159 | hidnplayr | 11 | ;; Written by hidnplayr@kolibrios.org ;; |
12 | ;; ;; |
||
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
14 | ;; Version 2, June 1991 ;; |
||
15 | ;; ;; |
||
16 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
17 | |||
18 | format MS COFF |
||
19 | |||
20 | API_VERSION equ 0x01000100 |
||
1519 | hidnplayr | 21 | DRIVER_VERSION equ 5 |
1159 | hidnplayr | 22 | |
1519 | hidnplayr | 23 | MAX_DEVICES equ 16 |
24 | |||
1159 | hidnplayr | 25 | DEBUG equ 1 |
26 | __DEBUG__ equ 1 |
||
1472 | hidnplayr | 27 | __DEBUG_LEVEL__ equ 2 |
1159 | hidnplayr | 28 | |
29 | include 'proc32.inc' |
||
30 | include 'imports.inc' |
||
31 | include 'fdo.inc' |
||
1472 | hidnplayr | 32 | include 'netdrv.inc' |
1159 | hidnplayr | 33 | |
34 | public START |
||
35 | public service_proc |
||
36 | public version |
||
37 | |||
38 | REG_IDR0 equ 0x00 |
||
39 | REG_MAR0 equ 0x08 ; multicast filter register 0 |
||
40 | REG_MAR4 equ 0x0c ; multicast filter register 4 |
||
41 | REG_TSD0 equ 0x10 ; transmit status of descriptor |
||
42 | REG_TSAD0 equ 0x20 ; transmit start address of descriptor |
||
43 | REG_RBSTART equ 0x30 ; RxBuffer start address |
||
44 | REG_COMMAND equ 0x37 ; command register |
||
45 | REG_CAPR equ 0x38 ; current address of packet read (word) R/W |
||
46 | REG_IMR equ 0x3c ; interrupt mask register |
||
47 | REG_ISR equ 0x3e ; interrupt status register |
||
48 | REG_TXCONFIG equ 0x40 ; transmit configuration register |
||
49 | REG_RXCONFIG equ 0x44 ; receive configuration register 0 |
||
50 | REG_MPC equ 0x4c ; missed packet counter |
||
51 | REG_9346CR equ 0x50 ; serial eeprom 93C46 command register |
||
52 | REG_CONFIG1 equ 0x52 ; configuration register 1 |
||
53 | REG_MSR equ 0x58 |
||
54 | REG_CONFIG4 equ 0x5a ; configuration register 4 |
||
55 | REG_HLTCLK equ 0x5b ; undocumented halt clock register |
||
56 | REG_BMCR equ 0x62 ; basic mode control register |
||
57 | REG_ANAR equ 0x66 ; auto negotiation advertisement register |
||
58 | REG_9346CR_WE equ 11b SHL 6 |
||
59 | |||
60 | BIT_RUNT equ 4 ; total packet length < 64 bytes |
||
61 | BIT_LONG equ 3 ; total packet length > 4k |
||
62 | BIT_CRC equ 2 ; crc error occured |
||
63 | BIT_FAE equ 1 ; frame alignment error occured |
||
64 | BIT_ROK equ 0 ; received packet is ok |
||
65 | |||
66 | BIT_RST equ 4 ; reset bit |
||
67 | BIT_RE equ 3 ; receiver enabled |
||
68 | BIT_TE equ 2 ; transmitter enabled |
||
69 | BUFE equ 1 ; rx buffer is empty, no packet stored |
||
70 | |||
71 | BIT_ISR_TOK equ 2 ; transmit ok |
||
72 | BIT_ISR_RER equ 1 ; receive error interrupt |
||
73 | BIT_ISR_ROK equ 0 ; receive ok |
||
74 | |||
75 | BIT_TX_MXDMA equ 8 ; Max DMA burst size per Tx DMA burst |
||
76 | BIT_TXRR equ 4 ; Tx Retry count 16+(TXRR*16) |
||
77 | |||
78 | BIT_RXFTH equ 13 ; Rx fifo threshold |
||
79 | BIT_RBLEN equ 11 ; Ring buffer length indicator |
||
80 | BIT_RX_MXDMA equ 8 ; Max DMA burst size per Rx DMA burst |
||
81 | BIT_NOWRAP equ 7 ; transfered data wrapping |
||
82 | BIT_9356SEL equ 6 ; eeprom selector 9346/9356 |
||
83 | BIT_AER equ 5 ; accept error packets |
||
84 | BIT_AR equ 4 ; accept runt packets |
||
85 | BIT_AB equ 3 ; accept broadcast packets |
||
86 | BIT_AM equ 2 ; accept multicast packets |
||
87 | BIT_APM equ 1 ; accept physical match packets |
||
88 | BIT_AAP equ 0 ; accept all packets |
||
89 | |||
90 | BIT_93C46_EEM1 equ 7 ; RTL8139 eeprom operating mode1 |
||
91 | BIT_93C46_EEM0 equ 6 ; RTL8139 eeprom operating mode0 |
||
92 | BIT_93C46_EECS equ 3 ; chip select |
||
93 | BIT_93C46_EESK equ 2 ; serial data clock |
||
94 | BIT_93C46_EEDI equ 1 ; serial data input |
||
95 | BIT_93C46_EEDO equ 0 ; serial data output |
||
96 | |||
97 | BIT_LWACT equ 4 ; see REG_CONFIG1 |
||
98 | BIT_SLEEP equ 1 ; sleep bit at older chips |
||
99 | BIT_PWRDWN equ 0 ; power down bit at older chips |
||
100 | BIT_PMEn equ 0 ; power management enabled |
||
101 | |||
102 | BIT_LWPTN equ 2 ; see REG_CONFIG4 |
||
103 | |||
104 | BIT_ERTXTH equ 16 ; early TX threshold |
||
105 | BIT_TOK equ 15 ; transmit ok |
||
106 | BIT_OWN equ 13 ; tx DMA operation is completed |
||
107 | |||
108 | BIT_ANE equ 12 ; auto negotiation enable |
||
109 | |||
110 | BIT_TXFD equ 8 ; 100base-T full duplex |
||
111 | BIT_TX equ 7 ; 100base-T |
||
112 | BIT_10FD equ 6 ; 10base-T full duplex |
||
113 | BIT_10 equ 5 ; 10base-T |
||
114 | BIT_SELECTOR equ 0 ; binary encoded selector CSMA/CD=00001 |
||
115 | |||
116 | BIT_IFG1 equ 25 |
||
117 | BIT_IFG0 equ 24 |
||
118 | |||
119 | RBLEN equ 2 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k |
||
120 | TXRR equ 8 ; total retries = 16+(TXRR*16) |
||
121 | TX_MXDMA equ 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048 |
||
122 | ERTXTH equ 8 ; in unit of 32 bytes e.g:(8*32)=256 |
||
123 | RX_MXDMA equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited |
||
124 | RXFTH equ 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold |
||
125 | |||
126 | RX_CONFIG equ (RBLEN shl BIT_RBLEN) or \ |
||
127 | (RX_MXDMA shl BIT_RX_MXDMA) or \ |
||
128 | (1 shl BIT_NOWRAP) or \ |
||
129 | (RXFTH shl BIT_RXFTH) or\ |
||
1472 | hidnplayr | 130 | (1 shl BIT_AB) or \ ; Accept broadcast packets |
131 | (1 shl BIT_APM) or \ ; Accept physical match packets |
||
132 | (1 shl BIT_AER) or \ ; Accept error packets |
||
133 | (1 shl BIT_AR) or \ ; Accept Runt packets (smaller then 64 bytes) |
||
134 | (1 shl BIT_AM) ; Accept multicast packets |
||
1159 | hidnplayr | 135 | |
1472 | hidnplayr | 136 | RX_BUFFER_SIZE equ (8192 shl RBLEN);+16 |
1159 | hidnplayr | 137 | MAX_ETH_FRAME_SIZE equ 1516 ; exactly 1514 wthout CRC |
1519 | hidnplayr | 138 | |
1159 | hidnplayr | 139 | NUM_TX_DESC equ 4 |
140 | |||
141 | EE_93C46_REG_ETH_ID equ 7 ; MAC offset |
||
142 | EE_93C46_READ_CMD equ (6 shl 6) ; 110b + 6bit address |
||
143 | EE_93C56_READ_CMD equ (6 shl 8) ; 110b + 8bit address |
||
144 | EE_93C46_CMD_LENGTH equ 9 ; start bit + cmd + 6bit address |
||
145 | EE_93C56_CMD_LENGTH equ 11 ; start bit + cmd + 8bit ddress |
||
146 | |||
147 | VER_RTL8139 equ 1100000b |
||
148 | VER_RTL8139A equ 1110000b |
||
149 | VER_RTL8139AG equ 1110100b |
||
150 | VER_RTL8139B equ 1111000b |
||
151 | VER_RTL8130 equ VER_RTL8139B |
||
152 | VER_RTL8139C equ 1110100b |
||
153 | VER_RTL8100 equ 1111010b |
||
154 | VER_RTL8100B equ 1110101b |
||
155 | VER_RTL8139D equ VER_RTL8100B |
||
156 | VER_RTL8139CP equ 1110110b |
||
157 | VER_RTL8101 equ 1110111b |
||
158 | |||
159 | IDX_RTL8139 equ 0 |
||
160 | IDX_RTL8139A equ 1 |
||
161 | IDX_RTL8139B equ 2 |
||
162 | IDX_RTL8139C equ 3 |
||
163 | IDX_RTL8100 equ 4 |
||
164 | IDX_RTL8139D equ 5 |
||
165 | IDX_RTL8139D equ 6 |
||
166 | IDX_RTL8101 equ 7 |
||
167 | |||
168 | ISR_SERR equ 1 SHL 15 |
||
169 | ISR_TIMEOUT equ 1 SHL 14 |
||
170 | ISR_LENCHG equ 1 SHL 13 |
||
171 | ISR_FIFOOVW equ 1 SHL 6 |
||
172 | ISR_PUN equ 1 SHL 5 |
||
173 | ISR_RXOVW equ 1 SHL 4 |
||
174 | ISR_TER equ 1 SHL 3 |
||
175 | ISR_TOK equ 1 SHL 2 |
||
176 | ISR_RER equ 1 SHL 1 |
||
177 | ISR_ROK equ 1 SHL 0 |
||
178 | |||
179 | INTERRUPT_MASK equ ISR_ROK or \ |
||
180 | ISR_RXOVW or \ |
||
181 | ISR_PUN or \ |
||
182 | ISR_FIFOOVW or \ |
||
183 | ISR_LENCHG or \ |
||
184 | ISR_TOK or \ |
||
185 | ISR_TER |
||
186 | |||
187 | TSR_OWN equ 1 SHL 13 |
||
188 | TSR_TUN equ 1 SHL 14 |
||
189 | TSR_TOK equ 1 SHL 15 |
||
190 | |||
191 | TSR_CDH equ 1 SHL 28 |
||
192 | TSR_OWC equ 1 SHL 29 |
||
193 | TSR_TABT equ 1 SHL 30 |
||
194 | TSR_CRS equ 1 SHL 31 |
||
195 | |||
196 | |||
1519 | hidnplayr | 197 | virtual at ebx |
1159 | hidnplayr | 198 | |
1519 | hidnplayr | 199 | device: |
200 | |||
201 | ETH_DEVICE |
||
202 | |||
203 | .rx_buffer dd ? |
||
204 | .tx_buffer dd ? |
||
205 | .rx_data_offset dd ? |
||
206 | .io_addr dd ? |
||
207 | .curr_tx_desc db ? |
||
208 | .last_tx_desc db ? |
||
209 | .pci_bus db ? |
||
210 | .pci_dev db ? |
||
211 | .irq_line db ? |
||
212 | .hw_ver_id db ? |
||
213 | |||
214 | .TX_DESC rd NUM_TX_DESC |
||
215 | |||
216 | .size = $ - device |
||
217 | |||
218 | end virtual |
||
219 | |||
220 | |||
221 | |||
1159 | hidnplayr | 222 | section '.flat' code readable align 16 |
223 | |||
224 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
225 | ;; ;; |
||
226 | ;; proc START ;; |
||
227 | ;; ;; |
||
228 | ;; (standard driver proc) ;; |
||
229 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
230 | |||
231 | align 4 |
||
232 | proc START stdcall, state:dword |
||
233 | |||
234 | cmp [state], 1 |
||
235 | jne .exit |
||
236 | |||
237 | .entry: |
||
238 | |||
1472 | hidnplayr | 239 | DEBUGF 2,"Loading rtl8139 driver\n" |
1159 | hidnplayr | 240 | stdcall RegService, my_service, service_proc |
241 | ret |
||
242 | |||
243 | .fail: |
||
244 | .exit: |
||
245 | xor eax, eax |
||
246 | ret |
||
247 | |||
248 | endp |
||
249 | |||
250 | |||
251 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
252 | ;; ;; |
||
253 | ;; proc SERVICE_PROC ;; |
||
254 | ;; ;; |
||
255 | ;; (standard driver proc) ;; |
||
256 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
257 | |||
258 | align 4 |
||
259 | proc service_proc stdcall, ioctl:dword |
||
260 | |||
261 | mov edx, [ioctl] |
||
1472 | hidnplayr | 262 | mov eax, [IOCTL.io_code] |
1159 | hidnplayr | 263 | |
264 | ;------------------------------------------------------ |
||
265 | |||
266 | cmp eax, 0 ;SRV_GETVERSION |
||
267 | jne @F |
||
268 | |||
1472 | hidnplayr | 269 | cmp [IOCTL.out_size], 4 |
1159 | hidnplayr | 270 | jl .fail |
1472 | hidnplayr | 271 | mov eax, [IOCTL.output] |
1159 | hidnplayr | 272 | mov [eax], dword API_VERSION |
273 | |||
274 | xor eax, eax |
||
275 | ret |
||
276 | |||
277 | ;------------------------------------------------------ |
||
278 | @@: |
||
279 | cmp eax, 1 ;SRV_HOOK |
||
280 | jne .fail |
||
281 | |||
1472 | hidnplayr | 282 | cmp [IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
1159 | hidnplayr | 283 | jl .fail |
284 | |||
1472 | hidnplayr | 285 | mov eax, [IOCTL.input] |
1159 | hidnplayr | 286 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
287 | jne .fail ; other types arent supported for this card yet |
||
288 | |||
289 | ; check if the device is already listed |
||
290 | |||
1519 | hidnplayr | 291 | mov esi, device_list |
292 | mov ecx, [devices] |
||
1159 | hidnplayr | 293 | test ecx, ecx |
294 | jz .firstdevice |
||
1472 | hidnplayr | 295 | |
296 | ; mov eax, [IOCTL.input] ; get the pci bus and device numbers |
||
297 | mov ax , [eax+1] ; |
||
1159 | hidnplayr | 298 | .nextdevice: |
1472 | hidnplayr | 299 | mov ebx, [esi] |
300 | cmp ax , word [device.pci_bus] ; compare with pci and device num in device list (notice the usage of word instead of byte) |
||
1159 | hidnplayr | 301 | je .find_devicenum ; Device is already loaded, let's find it's device number |
1472 | hidnplayr | 302 | add esi, 4 |
1159 | hidnplayr | 303 | loop .nextdevice |
304 | |||
1472 | hidnplayr | 305 | |
1159 | hidnplayr | 306 | ; This device doesnt have its own eth_device structure yet, lets create one |
307 | .firstdevice: |
||
1519 | hidnplayr | 308 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
1159 | hidnplayr | 309 | jge .fail |
310 | |||
1541 | hidnplayr | 311 | allocate_and_clear ebx, device.size, .fail ; Allocate the buffer for device structure |
1159 | hidnplayr | 312 | |
313 | ; Fill in the direct call addresses into the struct |
||
314 | |||
1486 | hidnplayr | 315 | mov [device.reset], reset |
316 | mov [device.transmit], transmit |
||
317 | mov [device.get_MAC], read_mac |
||
318 | mov [device.set_MAC], write_mac |
||
319 | mov [device.unload], unload |
||
320 | mov [device.name], my_service |
||
1159 | hidnplayr | 321 | |
322 | ; save the pci bus and device numbers |
||
323 | |||
1472 | hidnplayr | 324 | mov eax, [IOCTL.input] |
1159 | hidnplayr | 325 | mov cl , [eax+1] |
1472 | hidnplayr | 326 | mov [device.pci_bus], cl |
1159 | hidnplayr | 327 | mov cl , [eax+2] |
1472 | hidnplayr | 328 | mov [device.pci_dev], cl |
1159 | hidnplayr | 329 | |
330 | ; Now, it's time to find the base io addres of the PCI device |
||
331 | |||
1472 | hidnplayr | 332 | find_io [device.pci_bus], [device.pci_dev], [device.io_addr] |
1159 | hidnplayr | 333 | |
334 | ; We've found the io address, find IRQ now |
||
335 | |||
1492 | hidnplayr | 336 | find_irq [device.pci_bus], [device.pci_dev], [device.irq_line] |
1159 | hidnplayr | 337 | |
1472 | hidnplayr | 338 | DEBUGF 2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
339 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4 |
||
1159 | hidnplayr | 340 | |
341 | |||
1472 | hidnplayr | 342 | allocate_and_clear [device.rx_buffer], (RX_BUFFER_SIZE+MAX_ETH_FRAME_SIZE), .err |
1519 | hidnplayr | 343 | ;; allocate_and_clear [device.tx_buffer], (TX_BUF_SIZE*NUM_TX_DESC), .err |
1159 | hidnplayr | 344 | |
345 | ; Ok, the eth_device structure is ready, let's probe the device |
||
346 | |||
347 | call probe ; this function will output in eax |
||
348 | test eax, eax |
||
349 | jnz .err ; If an error occured, exit |
||
350 | |||
1519 | hidnplayr | 351 | mov eax, [devices] ; Add the device structure to our device list |
352 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
||
353 | inc [devices] ; |
||
1159 | hidnplayr | 354 | |
1514 | hidnplayr | 355 | mov [device.type], NET_TYPE_ETH |
356 | call NetRegDev |
||
357 | |||
1159 | hidnplayr | 358 | cmp eax, -1 |
359 | je .destroy |
||
360 | |||
361 | ret |
||
362 | |||
363 | ; If the device was already loaded, find the device number and return it in eax |
||
364 | |||
365 | .find_devicenum: |
||
1472 | hidnplayr | 366 | DEBUGF 2,"Trying to find device number of already registered device\n" |
1514 | hidnplayr | 367 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
1159 | hidnplayr | 368 | ; into a device number in edi |
369 | mov eax, edi ; Application wants it in eax instead |
||
1472 | hidnplayr | 370 | DEBUGF 2,"Kernel says: %u\n", eax |
1159 | hidnplayr | 371 | ret |
372 | |||
373 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
||
374 | |||
375 | .destroy: |
||
376 | ; todo: reset device into virgin state |
||
377 | |||
378 | .err: |
||
1472 | hidnplayr | 379 | stdcall KernelFree, dword [device.rx_buffer] |
1519 | hidnplayr | 380 | ;; stdcall KernelFree, dword [device.tx_buffer] |
1159 | hidnplayr | 381 | stdcall KernelFree, ebx |
382 | |||
383 | |||
384 | .fail: |
||
385 | or eax, -1 |
||
386 | ret |
||
387 | |||
388 | ;------------------------------------------------------ |
||
389 | endp |
||
390 | |||
391 | |||
392 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
||
393 | ;; ;; |
||
394 | ;; Actual Hardware dependent code starts here ;; |
||
395 | ;; ;; |
||
396 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
||
397 | |||
398 | align 4 |
||
399 | unload: |
||
400 | ; TODO: (in this particular order) |
||
401 | ; |
||
402 | ; - Stop the device |
||
403 | ; - Detach int handler |
||
404 | ; - Remove device from local list (RTL8139_LIST) |
||
405 | ; - call unregister function in kernel |
||
406 | ; - Remove all allocated structures and buffers the card used |
||
407 | |||
408 | or eax,-1 |
||
409 | |||
410 | ret |
||
411 | |||
412 | |||
413 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
414 | ;; |
||
415 | ;; probe: enables the device (if it really is RTL8139) |
||
416 | ;; |
||
417 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
418 | |||
419 | align 4 |
||
420 | probe: |
||
421 | DEBUGF 2,"Probing rtl8139 device: " |
||
422 | |||
1472 | hidnplayr | 423 | make_bus_master [device.pci_bus], [device.pci_dev] |
1159 | hidnplayr | 424 | |
425 | ; get chip version |
||
426 | |||
1472 | hidnplayr | 427 | set_io 0 |
428 | set_io REG_TXCONFIG + 2 |
||
1159 | hidnplayr | 429 | in ax , dx |
430 | shr ah , 2 |
||
431 | shr ax , 6 |
||
432 | and al , 01111111b |
||
1514 | hidnplayr | 433 | |
1159 | hidnplayr | 434 | mov ecx, HW_VER_ARRAY_SIZE-1 |
435 | .chip_ver_loop: |
||
1514 | hidnplayr | 436 | cmp al , [hw_ver_array + ecx] |
1159 | hidnplayr | 437 | je .chip_ver_found |
438 | dec ecx |
||
439 | jns .chip_ver_loop |
||
1514 | hidnplayr | 440 | .unknown: |
441 | mov ecx, 8 |
||
1159 | hidnplayr | 442 | .chip_ver_found: |
1514 | hidnplayr | 443 | cmp ecx, 8 |
444 | jg .unknown |
||
445 | |||
1472 | hidnplayr | 446 | mov [device.hw_ver_id], cl |
1159 | hidnplayr | 447 | |
1514 | hidnplayr | 448 | mov ecx, [crosslist + ecx*4] |
1472 | hidnplayr | 449 | mov [device.name], ecx |
1178 | hidnplayr | 450 | |
1514 | hidnplayr | 451 | DEBUGF 2,"Chip version: %s\n", ecx |
1178 | hidnplayr | 452 | |
1159 | hidnplayr | 453 | ; wake up the chip |
454 | |||
1472 | hidnplayr | 455 | set_io 0 |
456 | set_io REG_HLTCLK |
||
1159 | hidnplayr | 457 | mov al , 'R' ; run the clock |
458 | out dx , al |
||
459 | |||
460 | ; unlock config and BMCR registers |
||
461 | |||
1472 | hidnplayr | 462 | set_io REG_9346CR |
1159 | hidnplayr | 463 | mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) |
464 | out dx , al |
||
465 | |||
466 | ; enable power management |
||
467 | |||
1472 | hidnplayr | 468 | set_io REG_CONFIG1 |
1159 | hidnplayr | 469 | in al , dx |
1472 | hidnplayr | 470 | cmp [device.hw_ver_id], IDX_RTL8139B |
1159 | hidnplayr | 471 | jl .old_chip |
472 | |||
473 | ; set LWAKE pin to active high (default value). |
||
474 | ; it is for Wake-On-LAN functionality of some motherboards. |
||
475 | ; this signal is used to inform the motherboard to execute a wake-up process. |
||
476 | ; only at newer chips. |
||
477 | |||
478 | or al , (1 shl BIT_PMEn) |
||
479 | and al , not (1 shl BIT_LWACT) |
||
480 | out dx , al |
||
1472 | hidnplayr | 481 | |
482 | set_io REG_CONFIG4 |
||
1159 | hidnplayr | 483 | in al , dx |
484 | and al , not (1 shl BIT_LWPTN) |
||
485 | out dx , al |
||
1472 | hidnplayr | 486 | |
1159 | hidnplayr | 487 | jmp .finish_wake_up |
488 | .old_chip: |
||
489 | |||
490 | ; wake up older chips |
||
491 | |||
492 | and al , not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN)) |
||
493 | out dx , al |
||
494 | .finish_wake_up: |
||
495 | |||
496 | ; lock config and BMCR registers |
||
497 | |||
498 | xor al , al |
||
1472 | hidnplayr | 499 | set_io 0 |
500 | set_io REG_9346CR |
||
1159 | hidnplayr | 501 | out dx , al |
502 | DEBUGF 2,"done!\n" |
||
503 | |||
504 | |||
505 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
506 | ;; |
||
507 | ;; reset: Set up all registers and descriptors, clear some values |
||
508 | ;; |
||
509 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
510 | |||
511 | reset: |
||
512 | DEBUGF 2,"Resetting rtl8139: " |
||
513 | |||
514 | ; attach int handler |
||
515 | |||
1472 | hidnplayr | 516 | movzx eax, [device.irq_line] |
1159 | hidnplayr | 517 | DEBUGF 1,"Attaching int handler to irq %x, ",eax:1 |
518 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
||
519 | test eax, eax |
||
520 | jnz @f |
||
521 | DEBUGF 1,"\nCould not attach int handler!\n" |
||
522 | ; or eax, -1 |
||
523 | ; ret |
||
1519 | hidnplayr | 524 | @@: |
1159 | hidnplayr | 525 | |
526 | ; reset chip |
||
527 | |||
528 | DEBUGF 1,"Resetting chip\n" |
||
1472 | hidnplayr | 529 | set_io 0 |
530 | set_io REG_COMMAND |
||
1159 | hidnplayr | 531 | mov al , 1 shl BIT_RST |
532 | out dx , al |
||
533 | mov cx , 1000 ; wait no longer for the reset |
||
534 | .wait_for_reset: |
||
535 | in al , dx |
||
536 | test al , 1 shl BIT_RST |
||
537 | jz .reset_completed ; RST remains 1 during reset |
||
538 | dec cx |
||
539 | jns .wait_for_reset |
||
540 | .reset_completed: |
||
541 | |||
542 | ; unlock config and BMCR registers |
||
543 | |||
1472 | hidnplayr | 544 | set_io REG_9346CR |
1159 | hidnplayr | 545 | mov al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0) |
546 | out dx , al |
||
547 | |||
548 | ; initialize multicast registers (no filtering) |
||
549 | |||
550 | mov eax, 0xffffffff |
||
1472 | hidnplayr | 551 | set_io REG_MAR0 |
1159 | hidnplayr | 552 | out dx , eax |
1472 | hidnplayr | 553 | set_io REG_MAR4 |
1159 | hidnplayr | 554 | out dx , eax |
555 | |||
556 | ; enable Rx/Tx |
||
557 | |||
558 | mov al , (1 shl BIT_RE) or (1 shl BIT_TE) |
||
1472 | hidnplayr | 559 | set_io REG_COMMAND |
1159 | hidnplayr | 560 | out dx , al |
561 | |||
562 | ; 32k Rxbuffer, unlimited dma burst, no wrapping, no rx threshold |
||
563 | ; accept broadcast packets, accept physical match packets |
||
564 | |||
565 | mov ax , RX_CONFIG |
||
1472 | hidnplayr | 566 | set_io REG_RXCONFIG |
1159 | hidnplayr | 567 | out dx , ax |
568 | |||
1472 | hidnplayr | 569 | |
1159 | hidnplayr | 570 | ; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144 |
571 | |||
572 | mov eax , (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0 |
||
1472 | hidnplayr | 573 | set_io REG_TXCONFIG |
1159 | hidnplayr | 574 | out dx , eax |
575 | |||
576 | ; enable auto negotiation |
||
577 | |||
1472 | hidnplayr | 578 | set_io REG_BMCR |
1159 | hidnplayr | 579 | in ax , dx |
580 | or ax , (1 shl BIT_ANE) |
||
581 | out dx , ax |
||
582 | |||
583 | ; set auto negotiation advertisement |
||
584 | |||
1472 | hidnplayr | 585 | set_io REG_ANAR |
1159 | hidnplayr | 586 | in ax , dx |
587 | or ax , (1 shl BIT_SELECTOR) or (1 shl BIT_10) or (1 shl BIT_10FD) or (1 shl BIT_TX) or (1 shl BIT_TXFD) |
||
588 | out dx , ax |
||
589 | |||
590 | ; lock config and BMCR registers |
||
591 | |||
592 | xor eax, eax |
||
1472 | hidnplayr | 593 | set_io REG_9346CR |
1159 | hidnplayr | 594 | out dx , al |
595 | |||
596 | ; init RX/TX pointers |
||
597 | |||
1472 | hidnplayr | 598 | mov [device.rx_data_offset], eax |
599 | mov [device.curr_tx_desc], al |
||
1519 | hidnplayr | 600 | mov [device.last_tx_desc], al |
1159 | hidnplayr | 601 | |
1171 | hidnplayr | 602 | ; clear packet/byte counters |
603 | |||
1472 | hidnplayr | 604 | lea edi, [device.bytes_tx] |
1171 | hidnplayr | 605 | mov ecx, 6 |
606 | rep stosd |
||
607 | |||
1159 | hidnplayr | 608 | ; clear missing packet counter |
609 | |||
1472 | hidnplayr | 610 | set_io REG_MPC |
1159 | hidnplayr | 611 | out dx , eax |
612 | |||
1472 | hidnplayr | 613 | ; set RxBuffer address, init RX buffer offset |
1159 | hidnplayr | 614 | |
1472 | hidnplayr | 615 | mov eax, [device.rx_buffer] |
1159 | hidnplayr | 616 | call GetPgAddr |
1541 | hidnplayr | 617 | ; set_io 0 |
1472 | hidnplayr | 618 | set_io REG_RBSTART |
1159 | hidnplayr | 619 | out dx , eax |
620 | |||
1541 | hidnplayr | 621 | ; Read MAC address |
622 | |||
623 | call read_mac |
||
624 | |||
1159 | hidnplayr | 625 | ; enable interrupts |
626 | |||
1541 | hidnplayr | 627 | set_io 0 |
628 | set_io REG_IMR |
||
1159 | hidnplayr | 629 | mov eax, INTERRUPT_MASK |
630 | out dx , ax |
||
631 | |||
1519 | hidnplayr | 632 | ; Set the mtu, kernel will be able to send now |
633 | mov [device.mtu], 1514 |
||
634 | |||
1159 | hidnplayr | 635 | ; Indicate that we have successfully reset the card |
636 | |||
637 | DEBUGF 2,"Done!\n" |
||
638 | xor eax, eax |
||
639 | |||
640 | ret |
||
641 | |||
642 | |||
643 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
644 | ;; ;; |
||
645 | ;; Transmit ;; |
||
646 | ;; ;; |
||
1254 | hidnplayr | 647 | ;; In: buffer pointer in [esp+4] ;; |
648 | ;; size of buffer in [esp+8] ;; |
||
1159 | hidnplayr | 649 | ;; pointer to device structure in ebx ;; |
650 | ;; ;; |
||
651 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
652 | align 4 |
||
653 | transmit: |
||
1254 | hidnplayr | 654 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8] |
655 | mov eax, [esp+4] |
||
1159 | hidnplayr | 656 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
657 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
||
658 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
||
659 | [eax+13]:2,[eax+12]:2 |
||
660 | |||
1254 | hidnplayr | 661 | cmp dword [esp+8], MAX_ETH_FRAME_SIZE |
1519 | hidnplayr | 662 | jg .fail |
1254 | hidnplayr | 663 | cmp dword [esp+8], 60 |
1519 | hidnplayr | 664 | jl .fail |
1159 | hidnplayr | 665 | |
1519 | hidnplayr | 666 | ; check if we own the discriptor |
667 | set_io 0 |
||
1472 | hidnplayr | 668 | movzx ecx, [device.curr_tx_desc] |
1519 | hidnplayr | 669 | shl ecx, 2 |
670 | lea edx, [edx+ecx+REG_TSD0] |
||
1159 | hidnplayr | 671 | in ax, dx |
1519 | hidnplayr | 672 | test ax, (1 shl BIT_OWN) |
673 | jz .wait_to_send |
||
1159 | hidnplayr | 674 | |
1519 | hidnplayr | 675 | .send_packet: |
676 | ; Set the buffer address |
||
677 | set_io 0 |
||
678 | lea edx, [edx+ecx+REG_TSAD0] |
||
679 | mov eax, [esp+4] |
||
680 | mov [device.TX_DESC+ecx], eax |
||
681 | GetRealAddr |
||
682 | out dx, eax |
||
1159 | hidnplayr | 683 | |
1519 | hidnplayr | 684 | ; And the size of the buffer |
685 | set_io 0 |
||
686 | lea edx, [edx+ecx+REG_TSD0] |
||
687 | mov eax, [esp+8] |
||
688 | ; or eax, (ERTXTH shl BIT_ERTXTH) ; Early threshold |
||
689 | out dx , eax |
||
1159 | hidnplayr | 690 | |
1519 | hidnplayr | 691 | ; Update stats |
692 | inc [device.packets_tx] |
||
1472 | hidnplayr | 693 | add dword [device.bytes_tx], eax |
694 | adc dword [device.bytes_tx + 4], 0 |
||
1159 | hidnplayr | 695 | |
1519 | hidnplayr | 696 | ; get next descriptor |
1472 | hidnplayr | 697 | inc [device.curr_tx_desc] |
698 | and [device.curr_tx_desc], 3 |
||
1159 | hidnplayr | 699 | |
1519 | hidnplayr | 700 | DEBUGF 1,"Packet Sent! " |
701 | xor eax, eax |
||
702 | ret 8 |
||
1159 | hidnplayr | 703 | |
1519 | hidnplayr | 704 | .wait_to_send: |
1159 | hidnplayr | 705 | |
1519 | hidnplayr | 706 | DEBUGF 1,"Waiting for timeout\n" |
1159 | hidnplayr | 707 | |
1519 | hidnplayr | 708 | mov esi, 30 |
709 | stdcall Sleep |
||
1159 | hidnplayr | 710 | |
1519 | hidnplayr | 711 | in ax, dx |
712 | test ax, (1 shl BIT_OWN) |
||
713 | jnz .send_packet |
||
1159 | hidnplayr | 714 | |
1519 | hidnplayr | 715 | pusha |
716 | call reset ; if chip hung, reset it |
||
717 | popa |
||
718 | |||
719 | jmp .send_packet |
||
720 | |||
721 | .fail: |
||
722 | DEBUGF 1,"failed!\n" |
||
1541 | hidnplayr | 723 | stdcall KernelFree, [esp+4] |
1519 | hidnplayr | 724 | ret 8 |
725 | |||
726 | |||
727 | |||
728 | |||
729 | |||
1159 | hidnplayr | 730 | ;;;;;;;;;;;;;;;;;;;;;;; |
731 | ;; ;; |
||
732 | ;; Interrupt handler ;; |
||
733 | ;; ;; |
||
734 | ;;;;;;;;;;;;;;;;;;;;;;; |
||
735 | align 4 |
||
736 | int_handler: |
||
737 | |||
1519 | hidnplayr | 738 | DEBUGF 1,"IRQ %x\n", eax:2 ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO |
1159 | hidnplayr | 739 | |
740 | ; find pointer of device wich made IRQ occur |
||
741 | |||
1519 | hidnplayr | 742 | mov esi, device_list |
743 | mov ecx, [devices] |
||
1486 | hidnplayr | 744 | test ecx, ecx |
745 | jz .fail |
||
1159 | hidnplayr | 746 | .nextdevice: |
747 | mov ebx, dword [esi] |
||
748 | |||
1472 | hidnplayr | 749 | set_io 0 |
750 | set_io REG_ISR |
||
1159 | hidnplayr | 751 | in ax , dx |
752 | out dx , ax ; send it back to ACK |
||
753 | |||
754 | add esi, 4 |
||
755 | |||
756 | test ax , ax |
||
757 | jnz .got_it |
||
758 | |||
1486 | hidnplayr | 759 | dec ecx |
760 | jnz .nextdevice |
||
1159 | hidnplayr | 761 | |
762 | ret ; If no device was found, abort (The irq was probably for a device, not registered to this driver) |
||
763 | |||
764 | .got_it: |
||
765 | |||
766 | ; looks like we've found it! |
||
767 | |||
768 | ; Lets found out why the irq occured then.. |
||
769 | |||
770 | ;---------------------------------------------------- |
||
771 | ; Received packet ok? |
||
772 | test ax, ISR_ROK |
||
773 | jz @f |
||
774 | push ax |
||
775 | |||
776 | .receive: |
||
1472 | hidnplayr | 777 | set_io 0 |
778 | set_io REG_COMMAND |
||
779 | in al , dx |
||
1159 | hidnplayr | 780 | test al , BUFE ; test if RX buffer is empty |
781 | jnz .finish ; |
||
782 | |||
1472 | hidnplayr | 783 | DEBUGF 1,"RX: " |
1159 | hidnplayr | 784 | |
1472 | hidnplayr | 785 | mov eax, [device.rx_buffer] |
786 | add eax, [device.rx_data_offset] |
||
1159 | hidnplayr | 787 | test byte [eax], (1 shl BIT_ROK) ; check if packet is ok |
788 | jz .reset_rx |
||
1472 | hidnplayr | 789 | |
790 | ; packet is ok, copy it |
||
1159 | hidnplayr | 791 | movzx ecx, word [eax+2] ; packet length |
1472 | hidnplayr | 792 | |
793 | ; Update stats |
||
794 | add dword [device.bytes_rx], ecx |
||
795 | adc dword [device.bytes_rx + 4], 0 |
||
796 | inc dword [device.packets_rx] |
||
797 | |||
1159 | hidnplayr | 798 | sub ecx, 4 ; don't copy CRC |
1472 | hidnplayr | 799 | |
1159 | hidnplayr | 800 | DEBUGF 1,"Received %u bytes\n", ecx |
801 | |||
802 | push ebx eax ecx |
||
803 | stdcall KernelAlloc, ecx ; Allocate a buffer to put packet into |
||
804 | pop ecx |
||
805 | test eax, eax ; Test if we allocated succesfully |
||
1472 | hidnplayr | 806 | jz .abort |
1159 | hidnplayr | 807 | |
1472 | hidnplayr | 808 | mov edi, eax ; Where we will copy too |
809 | |||
810 | mov esi, [esp] ; The buffer we will copy from |
||
1159 | hidnplayr | 811 | add esi, 4 ; Dont copy CRC |
812 | |||
813 | push dword .abort ; Kernel will return to this address after EthReceiver |
||
814 | push ecx edi ; Save buffer pointer and size, to pass to kernel |
||
815 | |||
1472 | hidnplayr | 816 | .copy: |
817 | shr ecx, 1 |
||
818 | jnc .nb |
||
819 | movsb |
||
820 | .nb: |
||
821 | shr ecx, 1 |
||
822 | jnc .nw |
||
823 | movsw |
||
824 | .nw: |
||
825 | jz .nd |
||
826 | rep movsd |
||
827 | .nd: |
||
1159 | hidnplayr | 828 | |
829 | jmp EthReceiver ; Send it to kernel |
||
830 | |||
1472 | hidnplayr | 831 | |
1159 | hidnplayr | 832 | .abort: |
833 | pop eax ebx |
||
834 | ; update eth_data_start_offset |
||
835 | movzx eax, word [eax+2] ; packet length |
||
1472 | hidnplayr | 836 | add eax, [device.rx_data_offset] |
1159 | hidnplayr | 837 | add eax, 4+3 ; packet header is 4 bytes long + dword alignment |
838 | and eax, not 3 ; dword alignment |
||
1472 | hidnplayr | 839 | |
1159 | hidnplayr | 840 | cmp eax, RX_BUFFER_SIZE |
841 | jl .no_wrap |
||
1472 | hidnplayr | 842 | DEBUGF 2,"Wrapping" |
1159 | hidnplayr | 843 | sub eax, RX_BUFFER_SIZE |
844 | .no_wrap: |
||
1472 | hidnplayr | 845 | mov [device.rx_data_offset], eax |
846 | DEBUGF 1,"New RX ptr: %d ", eax |
||
1159 | hidnplayr | 847 | |
1472 | hidnplayr | 848 | set_io 0 |
849 | set_io REG_CAPR ; update 'Current Address of Packet Read register' |
||
1159 | hidnplayr | 850 | sub eax, 0x10 ; value 0x10 is a constant for CAPR |
851 | out dx , ax |
||
852 | |||
853 | jmp .receive ; check for multiple packets |
||
854 | |||
855 | .reset_rx: |
||
856 | test byte [eax], (1 shl BIT_CRC) |
||
857 | jz .no_crc_error |
||
858 | DEBUGF 2,"\nCRC error!\n" |
||
859 | |||
860 | .no_crc_error: |
||
861 | test byte [eax], (1 shl BIT_FAE) |
||
862 | jz .no_fae_error |
||
863 | DEBUGF 1,"\nFrame alignment error!\n" |
||
864 | |||
865 | .no_fae_error: |
||
866 | DEBUGF 1,"Reset RX\n" |
||
867 | in al , dx ; read command register |
||
868 | push ax |
||
869 | |||
870 | and al , not (1 shl BIT_RE) ; Clear the RE bit |
||
871 | out dx , al |
||
872 | |||
873 | pop ax |
||
874 | out dx , al ; write original command back |
||
875 | |||
876 | add edx, REG_RXCONFIG - REG_COMMAND ; Restore RX configuration |
||
877 | mov ax , RX_CONFIG |
||
878 | out dx , ax |
||
879 | |||
880 | .finish: |
||
881 | pop ax |
||
882 | |||
883 | ;---------------------------------------------------- |
||
884 | ; Transmit error ? |
||
885 | @@: |
||
886 | test ax, ISR_TER |
||
887 | jz @f |
||
888 | |||
1541 | hidnplayr | 889 | DEBUGF 1,"Transmit error\n" |
890 | |||
1519 | hidnplayr | 891 | ; push ax |
892 | ; cmp [device.curr_tx_desc], 4 |
||
893 | ; jz .notxd |
||
894 | ; |
||
895 | ; set_io 0 |
||
896 | ; movzx ecx, [device.curr_tx_desc] |
||
897 | ; lea edx, [edx+ecx*4+REG_TSD0] |
||
898 | ; in eax, dx |
||
899 | ; |
||
900 | ; .notxd: |
||
901 | ; test eax, TSR_TUN |
||
902 | ; jz .nobun |
||
903 | ; DEBUGF 2, "TX: FIFO Buffer underrun!\n" |
||
904 | ; |
||
905 | ; .nobun: |
||
906 | ; test eax, TSR_OWC |
||
907 | ; jz .noowc |
||
908 | ; DEBUGF 2, "TX: OWC!\n" |
||
909 | ; |
||
910 | ; .noowc: |
||
911 | ; test eax, TSR_TABT |
||
912 | ; jz .notabt |
||
913 | ; DEBUGF 2, "TX: TABT!\n" |
||
914 | ; |
||
915 | ; .notabt: |
||
916 | ; test eax, TSR_CRS |
||
917 | ; jz .nocsl |
||
918 | ; DEBUGF 2, "TX: Carrier Sense Lost!\n" |
||
919 | ; |
||
920 | ; .nocsl: |
||
921 | ; pop ax |
||
922 | |||
923 | ;---------------------------------------------------- |
||
924 | ; Transmit ok ? |
||
925 | @@: |
||
926 | test ax, ISR_TOK |
||
927 | jz @f |
||
928 | |||
1159 | hidnplayr | 929 | push ax |
1519 | hidnplayr | 930 | mov si, 4 |
931 | .txdesloop: |
||
932 | movzx ecx, [device.last_tx_desc] |
||
933 | shl ecx, 2 |
||
1159 | hidnplayr | 934 | |
1472 | hidnplayr | 935 | set_io 0 |
1519 | hidnplayr | 936 | set_io REG_TSD0 |
937 | add edx, ecx |
||
1159 | hidnplayr | 938 | in eax, dx |
939 | |||
1519 | hidnplayr | 940 | test eax, TSR_TOK |
941 | jz .notthisone |
||
942 | mov eax, TSR_OWN |
||
943 | out dx , eax |
||
944 | DEBUGF 1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8 |
||
945 | stdcall KernelFree, [device.TX_DESC+ecx] |
||
946 | .notthisone: |
||
1159 | hidnplayr | 947 | |
1519 | hidnplayr | 948 | inc [device.last_tx_desc] |
949 | and [device.last_tx_desc], 3 |
||
1159 | hidnplayr | 950 | |
1519 | hidnplayr | 951 | dec si |
952 | jnz .txdesloop |
||
1159 | hidnplayr | 953 | |
1519 | hidnplayr | 954 | .done: |
1159 | hidnplayr | 955 | pop ax |
956 | |||
957 | ;---------------------------------------------------- |
||
958 | ; Rx buffer overflow ? |
||
959 | @@: |
||
960 | test ax, ISR_RXOVW |
||
961 | jz @f |
||
962 | |||
963 | push ax |
||
1472 | hidnplayr | 964 | DEBUGF 2,"RX-buffer overflow!\n" |
1159 | hidnplayr | 965 | |
1519 | hidnplayr | 966 | set_io 0 |
967 | set_io REG_ISR |
||
1159 | hidnplayr | 968 | mov ax , ISR_FIFOOVW or ISR_RXOVW |
969 | out dx , ax |
||
970 | pop ax |
||
971 | |||
972 | ;---------------------------------------------------- |
||
1519 | hidnplayr | 973 | ; Packet underrun? |
1159 | hidnplayr | 974 | @@: |
975 | test ax, ISR_PUN |
||
976 | jz @f |
||
977 | |||
1472 | hidnplayr | 978 | DEBUGF 2,"Packet underrun!\n" |
1159 | hidnplayr | 979 | |
980 | ;---------------------------------------------------- |
||
981 | ; Receive FIFO overflow ? |
||
982 | @@: |
||
983 | test ax, ISR_FIFOOVW |
||
984 | jz @f |
||
985 | |||
986 | push ax |
||
1519 | hidnplayr | 987 | DEBUGF 2,"RX fifo overflow!\n" |
1159 | hidnplayr | 988 | |
1519 | hidnplayr | 989 | set_io 0 |
990 | set_io REG_ISR |
||
1159 | hidnplayr | 991 | mov ax , ISR_FIFOOVW or ISR_RXOVW |
992 | out dx , ax |
||
993 | pop ax |
||
994 | |||
995 | ;---------------------------------------------------- |
||
996 | ; Something about Cable changed ? |
||
997 | @@: |
||
998 | test ax, ISR_LENCHG |
||
999 | jz .fail |
||
1000 | |||
1001 | DEBUGF 2,"Cable changed!\n" |
||
1002 | call cable |
||
1003 | |||
1004 | .fail: |
||
1005 | ret |
||
1006 | |||
1007 | |||
1008 | |||
1009 | |||
1010 | ;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1011 | ;; ;; |
||
1012 | ;; Update Cable status ;; |
||
1013 | ;; ;; |
||
1014 | ;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1015 | |||
1016 | align 4 |
||
1017 | cable: |
||
1018 | DEBUGF 1,"Checking Cable status: " |
||
1019 | |||
1472 | hidnplayr | 1020 | mov edx, dword [device.io_addr] |
1159 | hidnplayr | 1021 | add edx, REG_MSR |
1022 | in al , dx |
||
1023 | |||
1024 | ; test al , 1 SHL 2 ; 0 = link ok 1 = link fail |
||
1025 | ; jnz .notconnected |
||
1026 | |||
1027 | ; test al , 1 SHL 3 ; 0 = 100 Mbps 1 = 10 Mbps |
||
1028 | ; jnz .10mbps |
||
1029 | |||
1030 | shr al, 2 |
||
1031 | and al, 3 |
||
1032 | |||
1472 | hidnplayr | 1033 | mov byte [device.mode+3], al |
1159 | hidnplayr | 1034 | DEBUGF 1,"Done!\n" |
1035 | ret |
||
1036 | |||
1037 | |||
1038 | |||
1039 | ;;;;;;;;;;;;;;;;;;;;;;; |
||
1040 | ;; ;; |
||
1041 | ;; Write MAC address ;; |
||
1042 | ;; ;; |
||
1043 | ;;;;;;;;;;;;;;;;;;;;;;; |
||
1044 | |||
1045 | align 4 |
||
1046 | write_mac: ; in: mac pushed onto stack (as 3 words) |
||
1047 | |||
1472 | hidnplayr | 1048 | DEBUGF 2,"Writing MAC: " |
1159 | hidnplayr | 1049 | |
1050 | ; disable all in command registers |
||
1051 | |||
1472 | hidnplayr | 1052 | set_io 0 |
1053 | set_io REG_9346CR |
||
1159 | hidnplayr | 1054 | xor eax, eax |
1055 | out dx , al |
||
1056 | |||
1472 | hidnplayr | 1057 | set_io REG_IMR |
1159 | hidnplayr | 1058 | xor eax, eax |
1059 | out dx , ax |
||
1060 | |||
1472 | hidnplayr | 1061 | set_io REG_ISR |
1159 | hidnplayr | 1062 | mov eax, -1 |
1063 | out dx , ax |
||
1064 | |||
1065 | ; enable writing |
||
1066 | |||
1472 | hidnplayr | 1067 | set_io REG_9346CR |
1159 | hidnplayr | 1068 | mov eax, REG_9346CR_WE |
1069 | out dx , al |
||
1070 | |||
1071 | ; write the mac ... |
||
1072 | |||
1472 | hidnplayr | 1073 | set_io REG_IDR0 |
1159 | hidnplayr | 1074 | pop eax |
1075 | out dx , eax |
||
1076 | |||
1472 | hidnplayr | 1077 | set_io REG_IDR0+4 |
1159 | hidnplayr | 1078 | xor eax, eax |
1079 | pop ax |
||
1080 | out dx , eax |
||
1081 | |||
1082 | ; disable writing |
||
1083 | |||
1472 | hidnplayr | 1084 | set_io REG_9346CR |
1159 | hidnplayr | 1085 | xor eax, eax |
1086 | out dx , al |
||
1087 | |||
1472 | hidnplayr | 1088 | DEBUGF 2,"ok!\n" |
1159 | hidnplayr | 1089 | |
1090 | ; Notice this procedure does not ret, but continues to read_mac instead. |
||
1091 | |||
1092 | |||
1093 | ;;;;;;;;;;;;;;;;;;;;;; |
||
1094 | ;; ;; |
||
1095 | ;; Read MAC address ;; |
||
1096 | ;; ;; |
||
1097 | ;;;;;;;;;;;;;;;;;;;;;; |
||
1098 | |||
1099 | read_mac: |
||
1472 | hidnplayr | 1100 | DEBUGF 2,"Reading MAC: " |
1159 | hidnplayr | 1101 | |
1472 | hidnplayr | 1102 | set_io 0 |
1103 | lea edi, [device.mac] |
||
1177 | clevermous | 1104 | in eax, dx |
1159 | hidnplayr | 1105 | stosd |
1177 | clevermous | 1106 | add edx, 4 |
1173 | clevermous | 1107 | in ax, dx |
1159 | hidnplayr | 1108 | stosw |
1109 | |||
1472 | hidnplayr | 1110 | DEBUGF 2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2 |
1173 | clevermous | 1111 | |
1159 | hidnplayr | 1112 | ret |
1113 | |||
1114 | |||
1115 | ; End of code |
||
1116 | |||
1519 | hidnplayr | 1117 | section '.data' data readable writable align 16 ; place all uninitialized data place here |
1159 | hidnplayr | 1118 | align 4 ; Place all initialised data here |
1119 | |||
1519 | hidnplayr | 1120 | devices dd 0 |
1121 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
||
1122 | my_service db 'RTL8139',0 ; max 16 chars include zero |
||
1159 | hidnplayr | 1123 | |
1519 | hidnplayr | 1124 | device_1 db 'Realtek 8139',0 |
1125 | device_2 db 'Realtek 8139A',0 |
||
1126 | device_3 db 'Realtek 8139B',0 |
||
1127 | device_4 db 'Realtek 8139C',0 |
||
1128 | device_5 db 'Realtek 8100',0 |
||
1129 | device_6 db 'Realtek 8139D',0 |
||
1130 | device_7 db 'Realtek 8139CP',0 |
||
1131 | device_8 db 'Realtek 8101',0 |
||
1132 | device_unknown db 'Unknown RTL8139 clone', 0 |
||
1178 | hidnplayr | 1133 | |
1519 | hidnplayr | 1134 | crosslist: |
1135 | dd device_1 |
||
1136 | dd device_2 |
||
1137 | dd device_3 |
||
1138 | dd device_4 |
||
1139 | dd device_5 |
||
1140 | dd device_6 |
||
1141 | dd device_7 |
||
1142 | dd device_8 |
||
1143 | dd device_unknown |
||
1178 | hidnplayr | 1144 | |
1519 | hidnplayr | 1145 | hw_ver_array: ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with |
1146 | db VER_RTL8139 |
||
1147 | db VER_RTL8139A |
||
1148 | db VER_RTL8139B |
||
1149 | db VER_RTL8139C |
||
1150 | db VER_RTL8100 |
||
1151 | db VER_RTL8139D |
||
1152 | db VER_RTL8139CP |
||
1153 | db VER_RTL8101 |
||
1154 | db 0 |
||
1159 | hidnplayr | 1155 | |
1156 | HW_VER_ARRAY_SIZE = $-hw_ver_array |
||
1157 | |||
1158 | include_debug_strings ; All data wich FDO uses will be included here |
||
1159 | |||
1519 | hidnplayr | 1160 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling> |
1159 | hidnplayr | 1161 |