Rev 2434 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
261 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2465 | Serge | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
431 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
261 | hidnplayr | 6 | ;; RTL8029.INC ;; |
7 | ;; ;; |
||
8 | ;; Ethernet driver for Menuet OS ;; |
||
9 | ;; ;; |
||
10 | ;; Version 0.2 31 July 2002 ;; |
||
11 | ;; ;; |
||
12 | ;; This driver is based on the ns8390 driver from ;; |
||
13 | ;; the etherboot 5.0.6 project. The copyright statement is ;; |
||
14 | ;; ;; |
||
15 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
16 | ;; Version 2, June 1991 ;; |
||
17 | ;; ;; |
||
18 | ;; remaining parts Copyright 2002 Mike Hibbett, ;; |
||
19 | ;; mikeh@oceanfree.net ;; |
||
20 | ;; ;; |
||
21 | ;; See file COPYING for details ;; |
||
22 | ;; ;; |
||
23 | ;; While this implementation handles only PCI bus RTL8029 ;; |
||
24 | ;; hardware, it can be easily adapted to other NE2000 clone ;; |
||
25 | ;; products. I just dont have any to try! ;; |
||
26 | ;; ;; |
||
27 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
28 | |||
593 | mikedld | 29 | $Revision: 2465 $ |
261 | hidnplayr | 30 | |
31 | |||
32 | ;******************************************************************** |
||
33 | ; Interface |
||
34 | ; rtl8029_reset |
||
35 | ; rtl8029_probe |
||
36 | ; rtl8029_poll |
||
37 | ; rtl8029_transmit |
||
38 | ; |
||
39 | ;******************************************************************** |
||
40 | |||
41 | |||
42 | |||
43 | |||
44 | ;************************************************************************** |
||
45 | ; 8390 Register Definitions |
||
46 | ;************************************************************************** |
||
47 | D8390_P0_COMMAND equ 0x00 |
||
48 | D8390_P0_PSTART equ 0x01 |
||
49 | D8390_P0_PSTOP equ 0x02 |
||
50 | D8390_P0_BOUND equ 0x03 |
||
51 | D8390_P0_TSR equ 0x04 |
||
52 | D8390_P0_TPSR equ 0x04 |
||
53 | D8390_P0_TBCR0 equ 0x05 |
||
54 | D8390_P0_TBCR1 equ 0x06 |
||
55 | D8390_P0_ISR equ 0x07 |
||
56 | D8390_P0_RSAR0 equ 0x08 |
||
57 | D8390_P0_RSAR1 equ 0x09 |
||
58 | D8390_P0_RBCR0 equ 0x0A |
||
59 | D8390_P0_RBCR1 equ 0x0B |
||
60 | D8390_P0_RSR equ 0x0C |
||
61 | D8390_P0_RCR equ 0x0C |
||
62 | D8390_P0_TCR equ 0x0D |
||
63 | D8390_P0_DCR equ 0x0E |
||
64 | D8390_P0_IMR equ 0x0F |
||
65 | D8390_P1_COMMAND equ 0x00 |
||
66 | D8390_P1_PAR0 equ 0x01 |
||
67 | D8390_P1_PAR1 equ 0x02 |
||
68 | D8390_P1_PAR2 equ 0x03 |
||
69 | D8390_P1_PAR3 equ 0x04 |
||
70 | D8390_P1_PAR4 equ 0x05 |
||
71 | D8390_P1_PAR5 equ 0x06 |
||
72 | D8390_P1_CURR equ 0x07 |
||
73 | D8390_P1_MAR0 equ 0x08 |
||
74 | |||
75 | D8390_COMMAND_PS0 equ 0x0 ; Page 0 select |
||
76 | D8390_COMMAND_PS1 equ 0x40 ; Page 1 select |
||
77 | D8390_COMMAND_PS2 equ 0x80 ; Page 2 select |
||
78 | D8390_COMMAND_RD2 equ 0x20 ; Remote DMA control |
||
79 | D8390_COMMAND_RD1 equ 0x10 |
||
80 | D8390_COMMAND_RD0 equ 0x08 |
||
81 | D8390_COMMAND_TXP equ 0x04 ; transmit packet |
||
82 | D8390_COMMAND_STA equ 0x02 ; start |
||
83 | D8390_COMMAND_STP equ 0x01 ; stop |
||
84 | |||
85 | D8390_COMMAND_RD2_STA equ 0x22 |
||
86 | D8390_COMMAND_RD2_STP equ 0x21 |
||
87 | D8390_COMMAND_RD1_STA equ 0x12 |
||
88 | D8390_COMMAND_RD0_STA equ 0x0A |
||
89 | D8390_COMMAND_PS0_RD2_STP equ 0x21 |
||
90 | D8390_COMMAND_PS1_RD2_STP equ 0x61 |
||
91 | D8390_COMMAND_PS0_RD2_STA equ 0x22 |
||
92 | D8390_COMMAND_PS0_TXP_RD2_STA equ 0x26 |
||
93 | |||
94 | D8390_RCR_MON equ 0x20 ; monitor mode |
||
95 | |||
96 | D8390_DCR_FT1 equ 0x40 |
||
97 | D8390_DCR_LS equ 0x08 ; Loopback select |
||
98 | D8390_DCR_WTS equ 0x01 ; Word transfer select |
||
99 | |||
100 | D8390_DCR_FT1_LS equ 0x48 |
||
101 | D8390_DCR_WTS_FT1_LS equ 0x49 |
||
102 | |||
103 | D8390_ISR_PRX equ 0x01 ; successful recv |
||
104 | D8390_ISR_PTX equ 0x02 ; successful xmit |
||
105 | D8390_ISR_RXE equ 0x04 ; receive error |
||
106 | D8390_ISR_TXE equ 0x08 ; transmit error |
||
107 | D8390_ISR_OVW equ 0x10 ; Overflow |
||
108 | D8390_ISR_CNT equ 0x20 ; Counter overflow |
||
109 | D8390_ISR_RDC equ 0x40 ; Remote DMA complete |
||
110 | D8390_ISR_RST equ 0x80 ; reset |
||
111 | |||
112 | D8390_RSTAT_PRX equ 0x01 ; successful recv |
||
113 | D8390_RSTAT_CRC equ 0x02 ; CRC error |
||
114 | D8390_RSTAT_FAE equ 0x04 ; Frame alignment error |
||
115 | D8390_RSTAT_OVER equ 0x08 ; FIFO overrun |
||
116 | |||
117 | D8390_TXBUF_SIZE equ 6 |
||
118 | D8390_RXBUF_END equ 32 |
||
119 | D8390_PAGE_SIZE equ 256 |
||
120 | |||
121 | ETH_ALEN equ 6 |
||
122 | ETH_HLEN equ 14 |
||
123 | ETH_ZLEN equ 60 |
||
124 | ETH_FRAME_LEN equ 1514 |
||
125 | |||
126 | FLAG_PIO equ 0x01 |
||
127 | FLAG_16BIT equ 0x02 |
||
128 | ASIC_PIO equ 0 |
||
129 | |||
130 | VENDOR_NONE equ 0 |
||
131 | VENDOR_WD equ 1 |
||
132 | VENDOR_NOVELL equ 2 |
||
133 | VENDOR_3COM equ 3 |
||
134 | |||
135 | NE_ASIC_OFFSET equ 0x10 |
||
136 | NE_RESET equ 0x0F ; Used to reset card |
||
137 | NE_DATA equ 0x00 ; Used to read/write NIC mem |
||
138 | |||
139 | MEM_8192 equ 32 |
||
140 | MEM_16384 equ 64 |
||
141 | MEM_32768 equ 128 |
||
142 | |||
143 | ISA_MAX_ADDR equ 0x400 |
||
144 | |||
145 | uglobal |
||
2434 | Serge | 146 | eth_flags: |
147 | db 0 |
||
148 | eth_vendor: |
||
149 | db 0 |
||
150 | eth_nic_base: |
||
151 | dw 0 |
||
152 | eth_asic_base: |
||
153 | dw 0 |
||
154 | eth_memsize: |
||
155 | db 0 |
||
156 | eth_rx_start: |
||
157 | db 0 |
||
158 | eth_tx_start: |
||
159 | db 0 |
||
160 | eth_bmem: |
||
161 | dd 0 |
||
162 | eth_rmem: |
||
163 | dd 0 |
||
164 | romdata: |
||
165 | db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
||
261 | hidnplayr | 166 | endg |
167 | |||
168 | iglobal |
||
2434 | Serge | 169 | test_data: |
170 | db 'NE*000 memory',0 |
||
171 | test_buffer: |
||
172 | db ' ',0 |
||
261 | hidnplayr | 173 | endg |
174 | |||
175 | uglobal |
||
2434 | Serge | 176 | eth_type: |
177 | dw 0 |
||
178 | pkthdr: |
||
179 | db 0,0,0,0 ; status, next, (short) len |
||
180 | pktoff: |
||
181 | dw 0 |
||
182 | eth_rx_data_ptr: |
||
183 | dd 0 |
||
184 | eth_tmp_len: |
||
185 | dw 0 |
||
261 | hidnplayr | 186 | endg |
187 | |||
188 | |||
189 | |||
190 | ;*************************************************************************** |
||
191 | ; Function |
||
192 | ; eth_pio_read |
||
193 | ; |
||
194 | ; Description |
||
195 | ; Read a frame from the ethernet card via Programmed I/O |
||
196 | ; src in ebx |
||
197 | ; cnt in ecx |
||
198 | ; dst in edi |
||
199 | ;*************************************************************************** |
||
200 | eth_pio_read: |
||
2434 | Serge | 201 | mov al, [eth_flags] |
202 | and al, FLAG_16BIT |
||
203 | cmp al, 0 |
||
204 | je epr_001 |
||
261 | hidnplayr | 205 | |
2434 | Serge | 206 | inc ecx |
207 | and ecx, 0xFFFFFFFE |
||
261 | hidnplayr | 208 | |
209 | epr_001: |
||
2434 | Serge | 210 | mov al, D8390_COMMAND_RD2_STA |
211 | mov dx, [eth_nic_base] |
||
212 | add dx, D8390_P0_COMMAND |
||
213 | out dx, al |
||
261 | hidnplayr | 214 | |
2434 | Serge | 215 | mov al, cl |
216 | mov dx, [eth_nic_base] |
||
217 | add dx, D8390_P0_RBCR0 |
||
218 | out dx, al |
||
261 | hidnplayr | 219 | |
2434 | Serge | 220 | mov al, ch |
221 | mov dx, [eth_nic_base] |
||
222 | add dx, D8390_P0_RBCR1 |
||
223 | out dx, al |
||
261 | hidnplayr | 224 | |
2434 | Serge | 225 | mov al, bl |
226 | mov dx, [eth_nic_base] |
||
227 | add dx, D8390_P0_RSAR0 |
||
228 | out dx, al |
||
261 | hidnplayr | 229 | |
2434 | Serge | 230 | mov al, bh |
231 | mov dx, [eth_nic_base] |
||
232 | add dx, D8390_P0_RSAR1 |
||
233 | out dx, al |
||
261 | hidnplayr | 234 | |
2434 | Serge | 235 | mov al, D8390_COMMAND_RD0_STA |
236 | mov dx, [eth_nic_base] |
||
237 | add dx, D8390_P0_COMMAND |
||
238 | out dx, al |
||
261 | hidnplayr | 239 | |
2434 | Serge | 240 | mov dx, [eth_asic_base] |
241 | add dx, ASIC_PIO |
||
261 | hidnplayr | 242 | |
2434 | Serge | 243 | mov al, [eth_flags] |
244 | and al, FLAG_16BIT |
||
245 | cmp al, 0 |
||
246 | je epr_003 |
||
261 | hidnplayr | 247 | |
2434 | Serge | 248 | shr ecx, 1 |
261 | hidnplayr | 249 | |
250 | epr_002: |
||
251 | ; 2 bytes at a time |
||
2434 | Serge | 252 | in ax, dx |
253 | mov [edi], ax |
||
254 | add edi, 2 |
||
255 | loop epr_002 |
||
256 | ret |
||
261 | hidnplayr | 257 | |
258 | epr_003: |
||
259 | ; 1 byte at a time |
||
2434 | Serge | 260 | in al, dx |
261 | mov [edi], al |
||
262 | inc edi |
||
263 | loop epr_003 |
||
264 | ret |
||
261 | hidnplayr | 265 | |
266 | |||
267 | |||
268 | |||
269 | ;*************************************************************************** |
||
270 | ; Function |
||
271 | ; eth_pio_write |
||
272 | ; |
||
273 | ; Description |
||
274 | ; writes a frame to the ethernet card via Programmed I/O |
||
275 | ; dst in ebx |
||
276 | ; cnt in ecx |
||
277 | ; src in esi |
||
278 | ;*************************************************************************** |
||
279 | eth_pio_write: |
||
2434 | Serge | 280 | mov al, [eth_flags] |
281 | and al, FLAG_16BIT |
||
282 | cmp al, 0 |
||
283 | je epw_001 |
||
261 | hidnplayr | 284 | |
2434 | Serge | 285 | inc ecx |
286 | and ecx, 0xFFFFFFFE |
||
261 | hidnplayr | 287 | |
288 | epw_001: |
||
2434 | Serge | 289 | mov al, D8390_COMMAND_RD2_STA |
290 | mov dx, [eth_nic_base] |
||
291 | add dx, D8390_P0_COMMAND |
||
292 | out dx, al |
||
261 | hidnplayr | 293 | |
2434 | Serge | 294 | mov al, D8390_ISR_RDC |
295 | mov dx, [eth_nic_base] |
||
296 | add dx, D8390_P0_ISR |
||
297 | out dx, al |
||
261 | hidnplayr | 298 | |
299 | |||
2434 | Serge | 300 | mov al, cl |
301 | mov dx, [eth_nic_base] |
||
302 | add dx, D8390_P0_RBCR0 |
||
303 | out dx, al |
||
261 | hidnplayr | 304 | |
2434 | Serge | 305 | mov al, ch |
306 | mov dx, [eth_nic_base] |
||
307 | add dx, D8390_P0_RBCR1 |
||
308 | out dx, al |
||
261 | hidnplayr | 309 | |
2434 | Serge | 310 | mov al, bl |
311 | mov dx, [eth_nic_base] |
||
312 | add dx, D8390_P0_RSAR0 |
||
313 | out dx, al |
||
261 | hidnplayr | 314 | |
2434 | Serge | 315 | mov al, bh |
316 | mov dx, [eth_nic_base] |
||
317 | add dx, D8390_P0_RSAR1 |
||
318 | out dx, al |
||
261 | hidnplayr | 319 | |
2434 | Serge | 320 | mov al, D8390_COMMAND_RD1_STA |
321 | mov dx, [eth_nic_base] |
||
322 | add dx, D8390_P0_COMMAND |
||
323 | out dx, al |
||
261 | hidnplayr | 324 | |
2434 | Serge | 325 | mov dx, [eth_asic_base] |
326 | add dx, ASIC_PIO |
||
261 | hidnplayr | 327 | |
2434 | Serge | 328 | mov al, [eth_flags] |
329 | and al, FLAG_16BIT |
||
330 | cmp al, 0 |
||
331 | je epw_003 |
||
261 | hidnplayr | 332 | |
2434 | Serge | 333 | shr ecx, 1 |
261 | hidnplayr | 334 | |
335 | epw_002: |
||
336 | ; 2 bytes at a time |
||
2434 | Serge | 337 | mov ax, [esi] |
338 | add esi, 2 |
||
339 | out dx, ax |
||
261 | hidnplayr | 340 | |
2434 | Serge | 341 | loop epw_002 |
342 | jmp epw_004 |
||
261 | hidnplayr | 343 | |
344 | epw_003: |
||
345 | ; 1 byte at a time |
||
2434 | Serge | 346 | mov al, [esi] |
347 | inc esi |
||
348 | out dx, al |
||
349 | loop epw_003 |
||
261 | hidnplayr | 350 | |
351 | epw_004: |
||
2434 | Serge | 352 | mov dx, [eth_nic_base] |
353 | add dx, D8390_P0_ISR |
||
261 | hidnplayr | 354 | |
355 | epw_005: |
||
2434 | Serge | 356 | in al, dx |
357 | and al, D8390_ISR_RDC |
||
358 | cmp al, D8390_ISR_RDC |
||
359 | jne epw_005 |
||
261 | hidnplayr | 360 | |
2434 | Serge | 361 | ret |
261 | hidnplayr | 362 | |
363 | |||
364 | |||
365 | ;*************************************************************************** |
||
366 | ; Function |
||
367 | ; rtl8029_reset |
||
368 | ; Description |
||
369 | ; Place the chip (ie, the ethernet card) into a virgin state |
||
370 | ; No inputs |
||
371 | ; All registers destroyed |
||
372 | ; |
||
373 | ;*************************************************************************** |
||
374 | rtl8029_reset: |
||
2434 | Serge | 375 | mov bx, [eth_nic_base] |
261 | hidnplayr | 376 | |
2434 | Serge | 377 | mov dx, bx |
378 | add dx, D8390_P0_COMMAND |
||
379 | mov al, D8390_COMMAND_PS0_RD2_STP |
||
380 | out dx, al |
||
261 | hidnplayr | 381 | |
2434 | Serge | 382 | mov dx, bx |
383 | add dx, D8390_P0_DCR |
||
384 | mov al, [eth_flags] |
||
385 | and al, FLAG_16BIT |
||
386 | cmp al, FLAG_16BIT |
||
387 | jne nsr_001 |
||
261 | hidnplayr | 388 | |
2434 | Serge | 389 | mov al, 0x49 |
390 | jmp nsr_002 |
||
261 | hidnplayr | 391 | |
392 | nsr_001: |
||
2434 | Serge | 393 | mov al, 0x48 |
261 | hidnplayr | 394 | |
395 | nsr_002: |
||
2434 | Serge | 396 | out dx, al |
261 | hidnplayr | 397 | |
2434 | Serge | 398 | xor al, al |
261 | hidnplayr | 399 | |
2434 | Serge | 400 | mov dx, bx |
401 | add dx, D8390_P0_RBCR0 |
||
402 | out dx, al |
||
261 | hidnplayr | 403 | |
2434 | Serge | 404 | mov dx, bx |
405 | add dx, D8390_P0_RBCR1 |
||
406 | out dx, al |
||
261 | hidnplayr | 407 | |
2434 | Serge | 408 | mov dx, bx |
409 | add dx, D8390_P0_RCR |
||
410 | mov al, 0x20 |
||
411 | out dx, al |
||
261 | hidnplayr | 412 | |
2434 | Serge | 413 | mov dx, bx |
414 | add dx, D8390_P0_TCR |
||
415 | mov al, 2 |
||
416 | out dx, al |
||
261 | hidnplayr | 417 | |
2434 | Serge | 418 | mov dx, bx |
419 | add dx, D8390_P0_TPSR |
||
420 | mov al, [eth_tx_start] |
||
421 | out dx, al |
||
261 | hidnplayr | 422 | |
2434 | Serge | 423 | mov dx, bx |
424 | add dx, D8390_P0_PSTART |
||
425 | mov al, [eth_rx_start] |
||
426 | out dx, al |
||
261 | hidnplayr | 427 | |
2434 | Serge | 428 | mov dx, bx |
429 | add dx, D8390_P0_PSTOP |
||
430 | mov al, [eth_memsize] |
||
431 | out dx, al |
||
261 | hidnplayr | 432 | |
2434 | Serge | 433 | mov dx, bx |
434 | add dx, D8390_P0_BOUND |
||
435 | mov al, [eth_memsize] |
||
436 | dec al |
||
437 | out dx, al |
||
261 | hidnplayr | 438 | |
2434 | Serge | 439 | mov dx, bx |
440 | add dx, D8390_P0_ISR |
||
441 | mov al, 0xff |
||
442 | out dx, al |
||
261 | hidnplayr | 443 | |
2434 | Serge | 444 | mov dx, bx |
445 | add dx, D8390_P0_IMR |
||
446 | xor al, al |
||
447 | out dx, al |
||
261 | hidnplayr | 448 | |
2434 | Serge | 449 | mov dx, bx |
450 | add dx, D8390_P0_COMMAND |
||
451 | mov al, D8390_COMMAND_PS1_RD2_STP |
||
452 | out dx, al |
||
261 | hidnplayr | 453 | |
2434 | Serge | 454 | mov dx, bx |
455 | add dx, D8390_P1_PAR0 |
||
456 | mov esi, node_addr |
||
457 | mov ecx, ETH_ALEN |
||
261 | hidnplayr | 458 | |
459 | nsr_003: |
||
2434 | Serge | 460 | mov al, [esi] |
461 | out dx, al |
||
261 | hidnplayr | 462 | |
2434 | Serge | 463 | inc esi |
464 | inc dx |
||
465 | loop nsr_003 |
||
261 | hidnplayr | 466 | |
2434 | Serge | 467 | mov dx, bx |
468 | add dx, D8390_P1_MAR0 |
||
469 | mov ecx, ETH_ALEN |
||
261 | hidnplayr | 470 | |
2434 | Serge | 471 | mov al, 0xff |
261 | hidnplayr | 472 | |
473 | nsr_004: |
||
2434 | Serge | 474 | out dx, al |
475 | inc dx |
||
476 | loop nsr_004 |
||
261 | hidnplayr | 477 | |
2434 | Serge | 478 | mov dx, bx |
479 | add dx, D8390_P1_CURR |
||
480 | mov al, [eth_rx_start] |
||
481 | out dx, al |
||
261 | hidnplayr | 482 | |
2434 | Serge | 483 | mov dx, bx |
484 | add dx, D8390_P0_COMMAND |
||
485 | mov al, D8390_COMMAND_PS0_RD2_STA |
||
486 | out dx, al |
||
261 | hidnplayr | 487 | |
2434 | Serge | 488 | mov dx, bx |
489 | add dx, D8390_P0_ISR |
||
490 | mov al, 0xff |
||
491 | out dx, al |
||
261 | hidnplayr | 492 | |
2434 | Serge | 493 | mov dx, bx |
494 | add dx, D8390_P0_TCR |
||
495 | mov al, 0 |
||
496 | out dx, al |
||
261 | hidnplayr | 497 | |
2434 | Serge | 498 | mov dx, bx |
499 | add dx, D8390_P0_RCR |
||
500 | mov al, 4 |
||
501 | out dx, al |
||
261 | hidnplayr | 502 | |
2434 | Serge | 503 | ret |
261 | hidnplayr | 504 | |
505 | |||
506 | |||
507 | ;*************************************************************************** |
||
508 | ; Function |
||
509 | ; rtl8029_probe |
||
510 | ; Description |
||
511 | ; Searches for an ethernet card, enables it and clears the rx buffer |
||
512 | ; If a card was found, it enables the ethernet -> TCPIP link |
||
513 | ; |
||
514 | ;*************************************************************************** |
||
515 | rtl8029_probe: |
||
2434 | Serge | 516 | mov eax, [io_addr] |
517 | mov [eth_nic_base], ax ; The IO address space is 16 bit only |
||
261 | hidnplayr | 518 | |
2434 | Serge | 519 | mov al, VENDOR_NONE |
520 | mov [eth_vendor], al |
||
261 | hidnplayr | 521 | |
2434 | Serge | 522 | mov al, [eth_vendor] |
523 | cmp al, VENDOR_NONE |
||
261 | hidnplayr | 524 | |
2434 | Serge | 525 | jne ep_check_have_vendor |
526 | xor eax, eax |
||
527 | mov [eth_bmem], eax |
||
261 | hidnplayr | 528 | |
2434 | Serge | 529 | mov al, FLAG_PIO |
530 | mov [eth_flags], al |
||
261 | hidnplayr | 531 | |
2434 | Serge | 532 | mov ax, [eth_nic_base] |
533 | add ax, NE_ASIC_OFFSET |
||
534 | mov [eth_asic_base], ax |
||
261 | hidnplayr | 535 | |
2434 | Serge | 536 | mov al, MEM_16384 |
537 | mov [eth_memsize], al |
||
261 | hidnplayr | 538 | |
2434 | Serge | 539 | mov al, 32 |
540 | mov [eth_tx_start], al |
||
261 | hidnplayr | 541 | |
2434 | Serge | 542 | add al, D8390_TXBUF_SIZE |
543 | mov [eth_rx_start], al |
||
261 | hidnplayr | 544 | |
2434 | Serge | 545 | mov dx, [eth_asic_base] |
546 | add dx, NE_RESET |
||
261 | hidnplayr | 547 | |
2434 | Serge | 548 | in al, dx |
549 | out dx, al |
||
261 | hidnplayr | 550 | |
2434 | Serge | 551 | in al, 0x84 |
261 | hidnplayr | 552 | |
2434 | Serge | 553 | mov bx, [eth_nic_base] |
261 | hidnplayr | 554 | |
2434 | Serge | 555 | mov dx, bx |
556 | add dx, D8390_P0_COMMAND |
||
557 | mov al, D8390_COMMAND_RD2_STP |
||
558 | out dx, al |
||
261 | hidnplayr | 559 | |
2434 | Serge | 560 | mov dx, bx |
561 | add dx, D8390_P0_RCR |
||
562 | mov al, D8390_RCR_MON |
||
563 | out dx, al |
||
261 | hidnplayr | 564 | |
2434 | Serge | 565 | mov dx, bx |
566 | add dx, D8390_P0_DCR |
||
567 | mov al, D8390_DCR_FT1_LS |
||
568 | out dx, al |
||
261 | hidnplayr | 569 | |
2434 | Serge | 570 | mov dx, bx |
571 | add dx, D8390_P0_PSTART |
||
572 | mov al, MEM_8192 |
||
573 | out dx, al |
||
261 | hidnplayr | 574 | |
2434 | Serge | 575 | mov dx, bx |
576 | add dx, D8390_P0_PSTOP |
||
577 | mov al, MEM_16384 |
||
578 | out dx, al |
||
261 | hidnplayr | 579 | |
2434 | Serge | 580 | mov esi, test_data |
581 | mov ebx, 8192 |
||
582 | mov ecx, 14 |
||
583 | call eth_pio_write |
||
261 | hidnplayr | 584 | |
2434 | Serge | 585 | mov ebx, 8192 |
586 | mov ecx, 14 |
||
587 | mov edi, test_buffer |
||
588 | call eth_pio_read |
||
261 | hidnplayr | 589 | |
2434 | Serge | 590 | mov esi, test_buffer |
591 | mov edi, test_data |
||
592 | mov ecx, 13 |
||
593 | cld |
||
594 | rep cmpsb |
||
261 | hidnplayr | 595 | |
2434 | Serge | 596 | je ep_set_vendor |
261 | hidnplayr | 597 | |
2434 | Serge | 598 | mov al, [eth_flags] |
599 | or al, FLAG_16BIT |
||
600 | mov [eth_flags], al |
||
261 | hidnplayr | 601 | |
2434 | Serge | 602 | mov al, MEM_32768 |
603 | mov [eth_memsize], al |
||
261 | hidnplayr | 604 | |
2434 | Serge | 605 | mov al, 64 |
606 | mov [eth_tx_start], al |
||
261 | hidnplayr | 607 | |
2434 | Serge | 608 | add al, D8390_TXBUF_SIZE |
609 | mov [eth_rx_start], al |
||
261 | hidnplayr | 610 | |
2434 | Serge | 611 | mov bx, [eth_nic_base] |
261 | hidnplayr | 612 | |
2434 | Serge | 613 | mov dx, bx |
614 | add dx, D8390_P0_DCR |
||
615 | mov al, D8390_DCR_WTS_FT1_LS |
||
616 | out dx, al |
||
261 | hidnplayr | 617 | |
2434 | Serge | 618 | mov dx, bx |
619 | add dx, D8390_P0_PSTART |
||
620 | mov al, MEM_16384 |
||
621 | out dx, al |
||
261 | hidnplayr | 622 | |
2434 | Serge | 623 | mov dx, bx |
624 | add dx, D8390_P0_PSTOP |
||
625 | mov al, MEM_32768 |
||
626 | out dx, al |
||
261 | hidnplayr | 627 | |
2434 | Serge | 628 | mov esi, test_data |
629 | mov ebx, 16384 |
||
630 | mov ecx, 14 |
||
631 | call eth_pio_write |
||
261 | hidnplayr | 632 | |
2434 | Serge | 633 | mov ebx, 16384 |
634 | mov ecx, 14 |
||
635 | mov edi, test_buffer |
||
636 | call eth_pio_read |
||
261 | hidnplayr | 637 | |
2434 | Serge | 638 | mov esi, test_buffer |
639 | mov edi, test_data |
||
640 | mov ecx, 13 |
||
641 | cld |
||
642 | rep cmpsb |
||
261 | hidnplayr | 643 | |
644 | ep_set_vendor: |
||
645 | ; this bit is odd - probably left over from my hacking |
||
2434 | Serge | 646 | mov ax, [eth_nic_base] |
647 | cmp ax, 0 |
||
648 | je rtl8029_exit |
||
649 | cmp ax, ISA_MAX_ADDR |
||
650 | jbe ep_001 |
||
651 | mov al, [eth_flags] |
||
652 | or al, FLAG_16BIT |
||
653 | mov [eth_flags], al |
||
261 | hidnplayr | 654 | |
655 | ep_001: |
||
2434 | Serge | 656 | mov al, VENDOR_NOVELL |
657 | mov [eth_vendor], al |
||
261 | hidnplayr | 658 | |
2434 | Serge | 659 | mov ebx, 0 |
660 | mov ecx, 16 |
||
661 | mov edi, romdata |
||
662 | call eth_pio_read |
||
261 | hidnplayr | 663 | |
664 | |||
2434 | Serge | 665 | mov ecx, ETH_ALEN |
666 | mov esi, romdata |
||
667 | mov edi, node_addr |
||
261 | hidnplayr | 668 | |
2434 | Serge | 669 | mov bl, [eth_flags] |
670 | and bl, FLAG_16BIT |
||
261 | hidnplayr | 671 | |
672 | ep_002: |
||
2434 | Serge | 673 | mov al, [esi] |
674 | mov [edi], al |
||
261 | hidnplayr | 675 | |
2434 | Serge | 676 | inc edi |
677 | inc esi |
||
678 | cmp bl, FLAG_16BIT |
||
679 | jne ep_003 |
||
261 | hidnplayr | 680 | |
2434 | Serge | 681 | inc esi |
261 | hidnplayr | 682 | |
683 | ep_003: |
||
2434 | Serge | 684 | loop ep_002 |
261 | hidnplayr | 685 | |
686 | ep_check_have_vendor: |
||
2434 | Serge | 687 | mov al, [eth_vendor] |
688 | cmp al, VENDOR_NONE |
||
689 | je rtl8029_exit |
||
261 | hidnplayr | 690 | |
2434 | Serge | 691 | cmp al, VENDOR_3COM |
692 | je ep_reset_card |
||
261 | hidnplayr | 693 | |
2434 | Serge | 694 | mov eax, [eth_bmem] |
695 | mov [eth_rmem], eax |
||
261 | hidnplayr | 696 | |
697 | ep_reset_card: |
||
698 | ; Reset the card |
||
2434 | Serge | 699 | call rtl8029_reset |
261 | hidnplayr | 700 | |
701 | ; Indicate that we have successfully reset the card |
||
2434 | Serge | 702 | mov eax, [pci_data] |
703 | mov [eth_status], eax |
||
261 | hidnplayr | 704 | |
705 | rtl8029_exit: |
||
2434 | Serge | 706 | ret |
261 | hidnplayr | 707 | |
708 | |||
709 | |||
710 | ;*************************************************************************** |
||
711 | ; Function |
||
712 | ; rtl8029_poll |
||
713 | ; |
||
714 | ; Description |
||
715 | ; Polls the ethernet card for a received packet |
||
716 | ; Received data, if any, ends up in Ether_buffer |
||
717 | ; |
||
718 | ;*************************************************************************** |
||
719 | rtl8029_poll: |
||
2434 | Serge | 720 | mov eax, Ether_buffer |
721 | mov [eth_rx_data_ptr], eax |
||
261 | hidnplayr | 722 | |
2434 | Serge | 723 | mov bx, [eth_nic_base] |
261 | hidnplayr | 724 | |
2434 | Serge | 725 | mov dx, bx |
726 | add dx, D8390_P0_RSR |
||
727 | in al, dx |
||
261 | hidnplayr | 728 | |
2434 | Serge | 729 | and al, D8390_RSTAT_PRX |
730 | cmp al, D8390_RSTAT_PRX |
||
731 | jne nsp_exit |
||
261 | hidnplayr | 732 | |
2434 | Serge | 733 | mov dx, bx |
734 | add dx, D8390_P0_BOUND |
||
735 | in al, dx |
||
736 | inc al |
||
261 | hidnplayr | 737 | |
2434 | Serge | 738 | cmp al, [eth_memsize] |
739 | jb nsp_001 |
||
261 | hidnplayr | 740 | |
2434 | Serge | 741 | mov al, [eth_rx_start] |
261 | hidnplayr | 742 | |
743 | nsp_001: |
||
2434 | Serge | 744 | mov ch, al |
261 | hidnplayr | 745 | |
2434 | Serge | 746 | mov dx, bx |
747 | add dx, D8390_P0_COMMAND |
||
748 | mov al, D8390_COMMAND_PS1 |
||
749 | out dx, al |
||
261 | hidnplayr | 750 | |
2434 | Serge | 751 | mov dx, bx |
752 | add dx, D8390_P1_CURR |
||
753 | in al, dx ; get current page |
||
754 | mov cl, al |
||
261 | hidnplayr | 755 | |
2434 | Serge | 756 | mov dx, bx |
757 | add dx, D8390_P0_COMMAND |
||
758 | mov al, D8390_COMMAND_PS0 |
||
759 | out dx, al |
||
261 | hidnplayr | 760 | |
2434 | Serge | 761 | cmp cl, [eth_memsize] |
762 | jb nsp_002 |
||
261 | hidnplayr | 763 | |
2434 | Serge | 764 | mov cl, [eth_rx_start] |
261 | hidnplayr | 765 | |
766 | nsp_002: |
||
2434 | Serge | 767 | cmp cl, ch |
768 | je nsp_exit |
||
261 | hidnplayr | 769 | |
2434 | Serge | 770 | xor ax, ax |
771 | mov ah, ch |
||
261 | hidnplayr | 772 | |
2434 | Serge | 773 | mov [pktoff], ax |
261 | hidnplayr | 774 | |
2434 | Serge | 775 | mov al, [eth_flags] |
776 | and al, FLAG_PIO |
||
777 | cmp al, FLAG_PIO |
||
778 | jne nsp_003 |
||
261 | hidnplayr | 779 | |
2434 | Serge | 780 | movzx ebx, word [pktoff] |
781 | mov edi, pkthdr |
||
782 | mov ecx, 4 |
||
783 | call eth_pio_read |
||
784 | jmp nsp_004 |
||
261 | hidnplayr | 785 | |
786 | nsp_003: |
||
2434 | Serge | 787 | mov edi, [eth_rmem] |
788 | movzx eax, word [pktoff] |
||
789 | add edi, eax |
||
790 | mov eax, [edi] |
||
791 | mov [pkthdr], eax |
||
261 | hidnplayr | 792 | |
793 | nsp_004: |
||
2434 | Serge | 794 | mov ax, [pktoff] |
795 | add ax, 4 |
||
796 | mov [pktoff], ax |
||
261 | hidnplayr | 797 | |
2434 | Serge | 798 | mov ax, [pkthdr + 2] |
799 | sub ax, 4 |
||
261 | hidnplayr | 800 | |
2434 | Serge | 801 | mov [eth_tmp_len], ax |
261 | hidnplayr | 802 | |
2434 | Serge | 803 | cmp ax, ETH_ZLEN |
804 | jb nsp_exit |
||
261 | hidnplayr | 805 | |
2434 | Serge | 806 | cmp ax, ETH_FRAME_LEN |
807 | ja nsp_exit |
||
261 | hidnplayr | 808 | |
2434 | Serge | 809 | mov al, [pkthdr] |
810 | and al, D8390_RSTAT_PRX |
||
811 | cmp al, D8390_RSTAT_PRX |
||
812 | jne nsp_exit |
||
261 | hidnplayr | 813 | |
814 | ; Right, we can now get the data |
||
815 | |||
2434 | Serge | 816 | mov ax, [eth_tmp_len] |
817 | mov [eth_rx_data_len], ax |
||
261 | hidnplayr | 818 | |
2434 | Serge | 819 | xor ebx, ebx |
820 | mov bh, [eth_memsize] |
||
821 | sub bx, [pktoff] |
||
261 | hidnplayr | 822 | |
2434 | Serge | 823 | cmp [eth_tmp_len], bx |
824 | jbe nsp_005 |
||
261 | hidnplayr | 825 | |
2434 | Serge | 826 | mov al, [eth_flags] |
827 | and al, FLAG_PIO |
||
828 | cmp al, FLAG_PIO |
||
829 | jne nsp_006 |
||
261 | hidnplayr | 830 | |
2434 | Serge | 831 | push ebx |
832 | mov ecx, ebx |
||
833 | xor ebx, ebx |
||
834 | mov bx, [pktoff] |
||
835 | mov edi, [eth_rx_data_ptr] |
||
836 | call eth_pio_read |
||
837 | pop ebx |
||
838 | jmp nsp_007 |
||
261 | hidnplayr | 839 | |
840 | nsp_006: |
||
841 | ; Not implemented, as we are using PIO mode on this card |
||
842 | |||
843 | nsp_007: |
||
2434 | Serge | 844 | xor ax, ax |
845 | mov ah, [eth_rx_start] |
||
846 | mov [pktoff], ax |
||
261 | hidnplayr | 847 | |
2434 | Serge | 848 | mov eax, [eth_rx_data_ptr] |
849 | add eax, ebx |
||
850 | mov [eth_rx_data_ptr], eax |
||
261 | hidnplayr | 851 | |
2434 | Serge | 852 | mov ax, [eth_tmp_len] |
853 | sub ax, bx |
||
854 | mov [eth_tmp_len], ax |
||
261 | hidnplayr | 855 | |
856 | nsp_005: |
||
2434 | Serge | 857 | mov al, [eth_flags] |
858 | and al, FLAG_PIO |
||
859 | cmp al, FLAG_PIO |
||
860 | jne nsp_008 |
||
261 | hidnplayr | 861 | |
2434 | Serge | 862 | xor ebx, ebx |
863 | mov bx, [pktoff] |
||
864 | xor ecx, ecx |
||
865 | mov cx, [eth_tmp_len] |
||
866 | mov edi, [eth_rx_data_ptr] |
||
867 | call eth_pio_read |
||
868 | jmp nsp_009 |
||
261 | hidnplayr | 869 | |
870 | nsp_008: |
||
871 | ; Not implemented, as we are using PIO mode on this card |
||
872 | |||
873 | nsp_009: |
||
2434 | Serge | 874 | mov al, [pkthdr+1] |
875 | cmp al, [eth_rx_start] |
||
876 | jne nsp_010 |
||
261 | hidnplayr | 877 | |
2434 | Serge | 878 | mov al, [eth_memsize] |
261 | hidnplayr | 879 | |
880 | nsp_010: |
||
2434 | Serge | 881 | mov dx, [eth_nic_base] |
882 | add dx, D8390_P0_BOUND |
||
883 | dec al |
||
884 | out dx, al |
||
261 | hidnplayr | 885 | |
886 | nsp_exit: |
||
2434 | Serge | 887 | ret |
261 | hidnplayr | 888 | |
889 | |||
890 | |||
891 | ;*************************************************************************** |
||
892 | ; Function |
||
893 | ; rtl8029_transmit |
||
894 | ; |
||
895 | ; Description |
||
896 | ; Transmits a packet of data via the ethernet card |
||
897 | ; Pointer to 48 bit destination address in edi |
||
898 | ; Type of packet in bx |
||
899 | ; size of packet in ecx |
||
900 | ; pointer to packet data in esi |
||
901 | ; |
||
902 | ;*************************************************************************** |
||
903 | rtl8029_transmit: |
||
2434 | Serge | 904 | mov [eth_type], bx |
261 | hidnplayr | 905 | |
2434 | Serge | 906 | pusha |
261 | hidnplayr | 907 | |
2434 | Serge | 908 | mov esi, edi |
909 | xor bx, bx |
||
910 | mov bh, [eth_tx_start] |
||
911 | mov ecx, ETH_ALEN |
||
912 | call eth_pio_write |
||
261 | hidnplayr | 913 | |
2434 | Serge | 914 | mov esi, node_addr |
915 | xor bx, bx |
||
916 | mov bh, [eth_tx_start] |
||
917 | add bx, ETH_ALEN |
||
918 | mov ecx, ETH_ALEN |
||
919 | call eth_pio_write |
||
261 | hidnplayr | 920 | |
2434 | Serge | 921 | mov esi, eth_type |
922 | xor bx, bx |
||
923 | mov bh, [eth_tx_start] |
||
924 | add bx, ETH_ALEN |
||
925 | add bx, ETH_ALEN |
||
926 | mov ecx, 2 |
||
927 | call eth_pio_write |
||
261 | hidnplayr | 928 | |
2434 | Serge | 929 | popa |
261 | hidnplayr | 930 | |
2434 | Serge | 931 | xor bx, bx |
932 | mov bh, [eth_tx_start] |
||
933 | add bx, ETH_HLEN |
||
934 | push ecx |
||
935 | call eth_pio_write |
||
936 | pop ecx |
||
261 | hidnplayr | 937 | |
2434 | Serge | 938 | add ecx, ETH_HLEN |
939 | cmp ecx, ETH_ZLEN |
||
940 | jae nst_001 |
||
261 | hidnplayr | 941 | |
2434 | Serge | 942 | mov ecx, ETH_ZLEN |
261 | hidnplayr | 943 | |
944 | nst_001: |
||
2434 | Serge | 945 | push ecx |
261 | hidnplayr | 946 | |
2434 | Serge | 947 | mov bx, [eth_nic_base] |
261 | hidnplayr | 948 | |
2434 | Serge | 949 | mov dx, bx |
950 | add dx, D8390_P0_COMMAND |
||
951 | mov al, D8390_COMMAND_PS0_RD2_STA |
||
952 | out dx, al |
||
261 | hidnplayr | 953 | |
2434 | Serge | 954 | mov dx, bx |
955 | add dx, D8390_P0_TPSR |
||
956 | mov al, [eth_tx_start] |
||
957 | out dx, al |
||
261 | hidnplayr | 958 | |
2434 | Serge | 959 | pop ecx |
261 | hidnplayr | 960 | |
2434 | Serge | 961 | mov dx, bx |
962 | add dx, D8390_P0_TBCR0 |
||
963 | mov al, cl |
||
964 | out dx, al |
||
261 | hidnplayr | 965 | |
2434 | Serge | 966 | mov dx, bx |
967 | add dx, D8390_P0_TBCR1 |
||
968 | mov al, ch |
||
969 | out dx, al |
||
261 | hidnplayr | 970 | |
2434 | Serge | 971 | mov dx, bx |
972 | add dx, D8390_P0_COMMAND |
||
973 | mov al, D8390_COMMAND_PS0_TXP_RD2_STA |
||
974 | out dx, al |
||
261 | hidnplayr | 975 | |
2434 | Serge | 976 | ret |