Rev 4470 | Rev 4580 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4470 | Rev 4532 | ||
---|---|---|---|
Line 12... | Line 12... | ||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; Version 2, June 1991 ;; |
13 | ;; Version 2, June 1991 ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 16... | Line 16... | ||
16 | 16 | ||
- | 17 | format PE DLL native |
|
Line 17... | Line 18... | ||
17 | format MS COFF |
18 | entry START |
- | 19 | ||
- | 20 | CURRENT_API = 0x0200 |
|
Line 18... | Line -... | ||
18 | - | ||
19 | API_VERSION = 0x01000100 |
21 | COMPATIBLE_API = 0x0100 |
20 | - | ||
Line 21... | Line 22... | ||
21 | DEBUG = 1 |
22 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
22 | __DEBUG__ = 1 |
23 | |
Line 23... | Line 24... | ||
23 | __DEBUG_LEVEL__ = 2 ; 1 = verbose, 2 = errors only |
24 | MAX_DEVICES = 16 |
24 | 25 | ||
Line -... | Line 26... | ||
- | 26 | __DEBUG__ = 1 |
|
- | 27 | __DEBUG_LEVEL__ = 1 ; 1 = verbose, 2 = errors only |
|
25 | MAX_DEVICES = 4 |
28 | |
26 | MAX_ETH_FRAME_SIZE = 1514 |
29 | TX_RING_SIZE = 4 |
27 | 30 | RX_RING_SIZE = 4 |
|
28 | TX_RING_SIZE = 4 |
- | |
29 | RX_RING_SIZE = 4 |
31 | |
30 | 32 | section '.flat' readable writable executable |
|
31 | include '../struct.inc' |
- | |
32 | include '../macros.inc' |
- | |
33 | include '../proc32.inc' |
- | |
34 | include '../imports.inc' |
- | |
Line 35... | Line 33... | ||
35 | include '../fdo.inc' |
33 | |
36 | include '../netdrv.inc' |
34 | include '../struct.inc' |
37 | 35 | include '../macros.inc' |
|
Line 277... | Line 275... | ||
277 | TXCTL_BPE = 0x0080 |
275 | TXCTL_BPE = 0x0080 |
Line 278... | Line 276... | ||
278 | 276 | ||
279 | TXCTL_MBO = 0x0000F000 |
277 | TXCTL_MBO = 0x0000F000 |
Line 280... | Line -... | ||
280 | TXCTL_BUFSZ = 0x00000FFF |
- | |
281 | - | ||
282 | ; |
278 | TXCTL_BUFSZ = 0x00000FFF |
Line 283... | Line -... | ||
283 | - | ||
284 | MAX_PHYS = 32 |
- | |
285 | - | ||
286 | - | ||
287 | virtual at ebx |
279 | |
288 | - | ||
289 | device: |
- | |
290 | - | ||
291 | ETH_DEVICE |
- | |
292 | - | ||
293 | ; device specific |
- | |
294 | - | ||
295 | rb 0x100-(($ - device) and 0xff) ; align 256 |
- | |
296 | .private: |
- | |
297 | .mode_ dw ? |
- | |
298 | .tlen_rlen dw ? |
- | |
299 | .phys_addr dp ? |
- | |
300 | .reserved dw ? |
- | |
301 | .filter dq ? |
- | |
302 | .rx_ring_phys dd ? |
- | |
303 | .tx_ring_phys dd ? |
- | |
304 | - | ||
305 | rb 0x100-(($ - device) and 0xff) ; align 256 |
- | |
306 | .rx_ring rb RX_RING_SIZE * descriptor.size |
- | |
307 | - | ||
308 | rb 0x100-(($ - device) and 0xff) ; align 256 |
- | |
309 | .tx_ring rb TX_RING_SIZE * descriptor.size |
- | |
310 | - | ||
311 | .cur_rx db ? |
- | |
312 | .cur_tx db ? |
- | |
313 | .last_tx db ? |
- | |
314 | .options dd ? |
- | |
315 | .full_duplex db ? |
- | |
316 | .chip_version dw ? |
- | |
317 | .mii db ? |
- | |
318 | .ltint db ? |
- | |
319 | .dxsuflo db ? |
- | |
320 | .fset db ? |
- | |
321 | .fdx db ? |
- | |
322 | - | ||
Line 323... | Line 280... | ||
323 | .io_addr dd ? |
280 | MAX_PHYS = 32 |
Line -... | Line 281... | ||
- | 281 | ||
- | 282 | ||
- | 283 | struct device ETH_DEVICE |
|
- | 284 | ||
- | 285 | rb 0x100-($ and 0xff) ; align 256 |
|
- | 286 | ||
- | 287 | ; Pcnet configuration structure |
|
- | 288 | mode dw ? |
|
- | 289 | tlen_rlen dw ? |
|
- | 290 | phys_addr dp ? |
|
- | 291 | reserved dw ? |
|
- | 292 | filter dq ? |
|
- | 293 | rx_ring_phys dd ? |
|
- | 294 | tx_ring_phys dd ? |
|
- | 295 | ; end of pcnet config struct |
|
- | 296 | ||
- | 297 | rb 0x100-($ and 0xff) ; align 256 |
|
- | 298 | ||
- | 299 | rx_ring rb RX_RING_SIZE * sizeof.descriptor |
|
- | 300 | ||
- | 301 | rb 0x100-($ and 0xff) ; align 256 |
|
- | 302 | ||
- | 303 | tx_ring rb TX_RING_SIZE * sizeof.descriptor |
|
- | 304 | ||
- | 305 | cur_rx db ? |
|
- | 306 | cur_tx db ? |
|
- | 307 | last_tx db ? |
|
- | 308 | options dd ? |
|
- | 309 | full_duplex db ? |
|
- | 310 | chip_version dw ? |
|
- | 311 | mii db ? |
|
- | 312 | ltint db ? |
|
- | 313 | dxsuflo db ? |
|
- | 314 | fset db ? |
|
- | 315 | fdx db ? |
|
- | 316 | ||
- | 317 | io_addr dd ? |
|
324 | .irq_line db ? |
318 | irq_line db ? |
325 | .pci_bus dd ? |
319 | pci_bus dd ? |
326 | .pci_dev dd ? |
320 | pci_dev dd ? |
327 | 321 | ||
328 | .phy dw ? |
322 | phy dw ? |
329 | 323 | ||
330 | .read_csr dd ? |
324 | read_csr dd ? |
- | 325 | write_csr dd ? |
|
- | 326 | read_bcr dd ? |
|
- | 327 | write_bcr dd ? |
|
- | 328 | read_rap dd ? |
|
- | 329 | write_rap dd ? |
|
- | 330 | sw_reset dd ? |
|
- | 331 | ||
- | 332 | ends |
|
- | 333 | ||
- | 334 | struct descriptor |
|
- | 335 | ||
Line 331... | Line 336... | ||
331 | .write_csr dd ? |
336 | base dd ? |
Line 332... | Line -... | ||
332 | .read_bcr dd ? |
- | |
333 | .write_bcr dd ? |
- | |
334 | .read_rap dd ? |
- | |
335 | .write_rap dd ? |
- | |
336 | .sw_reset dd ? |
- | |
337 | - | ||
338 | device_size = $ - device |
- | |
339 | - | ||
340 | end virtual |
- | |
341 | - | ||
342 | struc descriptor { |
- | |
343 | .base dd ? |
- | |
344 | .length dw ? |
- | |
345 | .status dw ? |
- | |
346 | .msg_length dw ? |
- | |
347 | .misc dw ? |
- | |
348 | .virtual dd ? |
- | |
349 | - | ||
350 | .size: |
- | |
351 | } |
- | |
352 | - | ||
Line 353... | Line 337... | ||
353 | virtual at 0 |
337 | length dw ? |
354 | descriptor descriptor |
338 | status dw ? |
355 | end virtual |
339 | msg_length dw ? |
356 | 340 | misc dw ? |
|
357 | 341 | virtual dd ? |
|
358 | 342 | ||
Line 359... | Line 343... | ||
359 | 343 | ends |
|
Line 360... | Line 344... | ||
360 | section '.flat' code readable align 16 |
344 | |
361 | 345 | ||
362 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | |
363 | ;; ;; |
- | |
Line 364... | Line 346... | ||
364 | ;; proc START ;; |
346 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
365 | ;; ;; |
347 | ;; ;; |
366 | ;; (standard driver proc) ;; |
348 | ;; proc START ;; |
Line 367... | Line 349... | ||
367 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
349 | ;; ;; |
368 | - | ||
369 | proc START stdcall, state:dword |
350 | ;; (standard driver proc) ;; |
370 | 351 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
Line 371... | Line 352... | ||
371 | cmp [state], 1 |
352 | |
Line 432... | Line 413... | ||
432 | mov esi, device_list |
413 | mov esi, device_list |
433 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
414 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
434 | mov ax, [eax+1] ; |
415 | mov ax, [eax+1] ; |
435 | .nextdevice: |
416 | .nextdevice: |
436 | mov ebx, [esi] |
417 | mov ebx, [esi] |
437 | cmp al, byte[device.pci_bus] |
418 | cmp al, byte[ebx + device.pci_bus] |
438 | jne @f |
419 | jne @f |
439 | cmp ah, byte[device.pci_dev] |
420 | cmp ah, byte[ebx + device.pci_dev] |
440 | je .find_devicenum ; Device is already loaded, let's find it's device number |
421 | je .find_devicenum ; Device is already loaded, let's find it's device number |
441 | @@: |
422 | @@: |
442 | add esi, 4 |
423 | add esi, 4 |
443 | loop .nextdevice |
424 | loop .nextdevice |
Line 446... | Line 427... | ||
446 | 427 | ||
447 | .firstdevice: |
428 | .firstdevice: |
448 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
429 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
Line 449... | Line 430... | ||
449 | jae .fail |
430 | jae .fail |
Line 450... | Line 431... | ||
450 | 431 | ||
Line 451... | Line 432... | ||
451 | allocate_and_clear ebx, device_size, .fail |
432 | allocate_and_clear ebx, sizeof.device, .fail |
452 | 433 | ||
453 | ; Fill in the direct call addresses into the struct |
434 | ; Fill in the direct call addresses into the struct |
454 | 435 | ||
Line 455... | Line 436... | ||
455 | mov [device.reset], reset |
436 | mov [ebx + device.reset], reset |
Line 456... | Line 437... | ||
456 | mov [device.transmit], transmit |
437 | mov [ebx + device.transmit], transmit |
457 | mov [device.unload], unload |
438 | mov [ebx + device.unload], unload |
458 | mov [device.name], my_service |
439 | mov [ebx + device.name], my_service |
459 | 440 | ||
460 | ; save the pci bus and device numbers |
441 | ; save the pci bus and device numbers |
Line 461... | Line 442... | ||
461 | 442 | ||
Line -... | Line 443... | ||
- | 443 | mov eax, [edx + IOCTL.input] |
|
462 | mov eax, [edx + IOCTL.input] |
444 | movzx ecx, byte[eax+1] |
Line 463... | Line 445... | ||
463 | movzx ecx, byte[eax+1] |
445 | mov [ebx + device.pci_bus], ecx |
Line -... | Line 446... | ||
- | 446 | movzx ecx, byte[eax+2] |
|
464 | mov [device.pci_bus], ecx |
447 | mov [ebx + device.pci_dev], ecx |
Line 465... | Line 448... | ||
465 | movzx ecx, byte[eax+2] |
448 | |
466 | mov [device.pci_dev], ecx |
449 | ; Now, it's time to find the base io addres of the PCI device |
Line 467... | Line 450... | ||
467 | 450 | ||
468 | ; Now, it's time to find the base io addres of the PCI device |
451 | stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev] |
469 | 452 | mov [ebx + device.io_addr], eax |
|
470 | PCI_find_io |
453 | |
Line 484... | Line 467... | ||
484 | 467 | ||
485 | call probe ; this function will output in eax |
468 | call probe ; this function will output in eax |
486 | test eax, eax |
469 | test eax, eax |
Line 487... | Line 470... | ||
487 | jnz .destroy ; If an error occured, exit |
470 | jnz .destroy ; If an error occured, exit |
488 | 471 | ||
489 | mov [device.type], NET_TYPE_ETH |
472 | mov [ebx + device.type], NET_TYPE_ETH |
490 | call NetRegDev |
473 | invoke NetRegDev |
Line 491... | Line 474... | ||
491 | cmp eax, -1 |
474 | cmp eax, -1 |
Line 492... | Line 475... | ||
492 | je .destroy |
475 | je .destroy |
Line 493... | Line 476... | ||
493 | 476 | ||
494 | ret |
477 | ret |
495 | 478 | ||
496 | ; If the device was already loaded, find the device number and return it in eax |
479 | ; If the device was already loaded, find the device number and return it in eax |
497 | 480 | ||
498 | .find_devicenum: |
481 | .find_devicenum: |
499 | DEBUGF 1,"Trying to find device number of already registered device\n" |
482 | DEBUGF 1,"Trying to find device number of already registered device\n" |
Line 509... | Line 492... | ||
509 | ; todo: reset device into virgin state |
492 | ; todo: reset device into virgin state |
Line 510... | Line 493... | ||
510 | 493 | ||
511 | dec [devices] |
494 | dec [devices] |
512 | .err: |
495 | .err: |
513 | DEBUGF 2,"Error, removing all data !\n" |
496 | DEBUGF 2,"Error, removing all data !\n" |
Line 514... | Line 497... | ||
514 | stdcall KernelFree, ebx |
497 | invoke KernelFree, ebx |
515 | 498 | ||
516 | .fail: |
499 | .fail: |
Line 531... | Line 514... | ||
531 | unload: |
514 | unload: |
532 | ; TODO: (in this particular order) |
515 | ; TODO: (in this particular order) |
533 | ; |
516 | ; |
534 | ; - Stop the device |
517 | ; - Stop the device |
535 | ; - Detach int handler |
518 | ; - Detach int handler |
536 | ; - Remove device from local list (RTL8139_LIST) |
519 | ; - Remove device from local list (device_list) |
537 | ; - call unregister function in kernel |
520 | ; - call unregister function in kernel |
538 | ; - Remove all allocated structures and buffers the card used |
521 | ; - Remove all allocated structures and buffers the card used |
Line 539... | Line 522... | ||
539 | 522 | ||
Line 549... | Line 532... | ||
549 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
532 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 550... | Line 533... | ||
550 | 533 | ||
551 | align 4 |
534 | align 4 |
Line 552... | Line 535... | ||
552 | probe: |
535 | probe: |
Line 553... | Line 536... | ||
553 | 536 | ||
Line 554... | Line 537... | ||
554 | mov edx, [device.io_addr] |
537 | mov edx, [ebx + device.io_addr] |
555 | 538 | ||
Line 598... | Line 581... | ||
598 | call switch_to_dwio |
581 | call switch_to_dwio |
Line 599... | Line 582... | ||
599 | 582 | ||
Line 600... | Line 583... | ||
600 | jmp .L1 |
583 | jmp .L1 |
601 | 584 | ||
602 | .no_dev: |
585 | .no_dev: |
603 | DEBUGF 1,"device not found!\n" |
586 | DEBUGF 2,"device not found!\n" |
Line 604... | Line 587... | ||
604 | mov eax, 1 |
587 | mov eax, 1 |
605 | ret |
588 | ret |
606 | 589 | ||
Line 607... | Line 590... | ||
607 | .L1: |
590 | .L1: |
608 | mov ecx, CSR_CHIPID0 |
591 | mov ecx, CSR_CHIPID0 |
Line 609... | Line 592... | ||
609 | call [device.read_csr] |
592 | call [ebx + device.read_csr] |
610 | 593 | ||
611 | mov esi, eax |
594 | mov esi, eax |
Line 612... | Line 595... | ||
612 | shr esi, 12 |
595 | shr esi, 12 |
613 | 596 | ||
614 | and ax, 0xfff |
597 | and ax, 0xfff |
615 | cmp ax, 3 |
598 | cmp ax, 3 |
616 | jne .no_dev |
599 | jne .no_dev |
Line 617... | Line 600... | ||
617 | 600 | ||
618 | mov ecx, CSR_CHIPID1 |
601 | mov ecx, CSR_CHIPID1 |
619 | call [device.read_csr] |
602 | call [ebx + device.read_csr] |
620 | shl eax, 4 |
603 | shl eax, 4 |
621 | or eax, esi |
604 | or eax, esi |
Line 622... | Line 605... | ||
622 | mov [device.chip_version], ax |
605 | mov [ebx + device.chip_version], ax |
623 | 606 | ||
624 | mov [device.fdx], 0 |
607 | mov [ebx + device.fdx], 0 |
625 | mov [device.mii], 0 |
608 | mov [ebx + device.mii], 0 |
Line 626... | Line 609... | ||
626 | mov [device.fset], 0 |
609 | mov [ebx + device.fset], 0 |
Line 627... | Line 610... | ||
627 | mov [device.dxsuflo], 0 |
610 | mov [ebx + device.dxsuflo], 0 |
628 | mov [device.ltint], 0 |
611 | mov [ebx + device.ltint], 0 |
629 | 612 | ||
630 | cmp ax, 0x2420 |
613 | cmp ax, 0x2420 |
Line 648... | Line 631... | ||
648 | je .L9 |
631 | je .L9 |
Line 649... | Line 632... | ||
649 | 632 | ||
650 | DEBUGF 1,"Invalid chip rev\n" |
633 | DEBUGF 1,"Invalid chip rev\n" |
651 | jmp .no_dev |
634 | jmp .no_dev |
652 | .L2: |
635 | .L2: |
653 | mov [device.name], device_l2 |
636 | mov [ebx + device.name], device_l2 |
654 | jmp .L10 |
637 | jmp .L10 |
655 | .L4: |
638 | .L4: |
656 | mov [device.name], device_l4 |
639 | mov [ebx + device.name], device_l4 |
657 | ; mov [device.fdx], 1 |
640 | ; mov [ebx + device.fdx], 1 |
658 | jmp .L10 |
641 | jmp .L10 |
659 | .L5: |
642 | .L5: |
660 | mov [device.name], device_l5 |
643 | mov [ebx + device.name], device_l5 |
661 | ; mov [device.fdx], 1 |
644 | ; mov [ebx + device.fdx], 1 |
662 | mov [device.mii], 1 |
645 | mov [ebx + device.mii], 1 |
663 | mov [device.fset], 1 |
646 | mov [ebx + device.fset], 1 |
664 | mov [device.ltint], 1 |
647 | mov [ebx + device.ltint], 1 |
665 | jmp .L10 |
648 | jmp .L10 |
666 | .L6: |
649 | .L6: |
667 | mov [device.name], device_l6 |
650 | mov [ebx + device.name], device_l6 |
668 | ; mov [device.fdx], 1 |
651 | ; mov [ebx + device.fdx], 1 |
669 | mov [device.mii], 1 |
652 | mov [ebx + device.mii], 1 |
670 | mov [device.fset], 1 |
653 | mov [ebx + device.fset], 1 |
671 | jmp .L10 |
654 | jmp .L10 |
672 | .L7: |
655 | .L7: |
673 | mov [device.name], device_l7 |
656 | mov [ebx + device.name], device_l7 |
674 | ; mov [device.fdx], 1 |
657 | ; mov [ebx + device.fdx], 1 |
675 | mov [device.mii], 1 |
658 | mov [ebx + device.mii], 1 |
676 | jmp .L10 |
659 | jmp .L10 |
677 | .L8: |
660 | .L8: |
678 | mov [device.name], device_l8 |
661 | mov [ebx + device.name], device_l8 |
679 | ; mov [device.fdx], 1 |
662 | ; mov [ebx + device.fdx], 1 |
680 | mov ecx, CSR_RXPOLL |
663 | mov ecx, CSR_RXPOLL |
681 | call dword [device.read_bcr] |
664 | call dword [ebx + device.read_bcr] |
682 | call dword [device.write_bcr] |
665 | call dword [ebx + device.write_bcr] |
683 | jmp .L10 |
666 | jmp .L10 |
684 | .L9: |
667 | .L9: |
685 | mov [device.name], device_l9 |
668 | mov [ebx + device.name], device_l9 |
686 | ; mov [device.fdx], 1 |
669 | ; mov [ebx + device.fdx], 1 |
687 | mov [device.mii], 1 |
670 | mov [ebx + device.mii], 1 |
688 | .L10: |
671 | .L10: |
Line 689... | Line 672... | ||
689 | DEBUGF 1,"device name: %s\n", [device.name] |
672 | DEBUGF 1,"device name: %s\n", [ebx + device.name] |
690 | 673 | ||
691 | cmp [device.fset], 1 |
674 | cmp [ebx + device.fset], 1 |
692 | jne .L11 |
675 | jne .L11 |
693 | mov ecx, BCR_BUSCTL |
676 | mov ecx, BCR_BUSCTL |
694 | call [device.read_bcr] |
677 | call [ebx + device.read_bcr] |
Line 695... | Line 678... | ||
695 | or eax, 0x800 |
678 | or eax, 0x800 |
696 | call [device.write_bcr] |
679 | call [ebx + device.write_bcr] |
697 | 680 | ||
698 | mov ecx, CSR_DMACTL |
681 | mov ecx, CSR_DMACTL |
699 | call [device.read_csr] |
682 | call [ebx + device.read_csr] |
700 | ; and eax, 0xc00 |
683 | ; and eax, 0xc00 |
Line 701... | Line 684... | ||
701 | ; or eax, 0xc00 |
684 | ; or eax, 0xc00 |
702 | mov eax, 0xc00 |
685 | mov eax, 0xc00 |
703 | call [device.write_csr] |
686 | call [ebx + device.write_csr] |
Line 704... | Line 687... | ||
704 | 687 | ||
- | 688 | mov [ebx + device.dxsuflo],1 |
|
- | 689 | mov [ebx + device.ltint],1 |
|
- | 690 | .L11: |
|
- | 691 | ||
- | 692 | ; Make the device a bus master |
|
- | 693 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
|
- | 694 | or al, PCI_CMD_MASTER |
|
Line 705... | Line -... | ||
705 | mov [device.dxsuflo],1 |
- | |
706 | mov [device.ltint],1 |
- | |
707 | .L11: |
- | |
708 | - | ||
709 | PCI_make_bus_master |
695 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
710 | 696 | ||
Line 711... | Line 697... | ||
711 | mov [device.options], PORT_ASEL |
697 | mov [ebx + device.options], PORT_ASEL |
712 | mov [device.mode_], MODE_RXD + MODE_TXD ; disable receive and transmit |
698 | mov [ebx + device.mode], MODE_RXD + MODE_TXD ; disable receive and transmit |
Line 713... | Line 699... | ||
713 | mov [device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS) |
699 | mov [ebx + device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS) |
Line 714... | Line 700... | ||
714 | 700 | ||
715 | mov dword [device.filter], 0 |
701 | mov dword[ebx + device.filter], 0 |
716 | mov dword [device.filter+4], 0 |
702 | mov dword[ebx + device.filter+4], 0 |
717 | 703 | ||
718 | align 4 |
704 | align 4 |
719 | reset: |
705 | reset: |
720 | 706 | ||
721 | ; attach int handler |
707 | ; attach int handler |
722 | 708 | ||
Line 723... | Line 709... | ||
723 | movzx eax, [device.irq_line] |
709 | movzx eax, [ebx + device.irq_line] |
724 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
- | |
725 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
710 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
Line 726... | Line 711... | ||
726 | test eax, eax |
711 | invoke AttachIntHandler, eax, int_handler, ebx |
727 | jnz @f |
712 | test eax, eax |
728 | DEBUGF 2,"Could not attach int handler!\n" |
713 | jnz @f |
729 | ; or eax, -1 |
714 | DEBUGF 2,"Could not attach int handler!\n" |
Line 730... | Line 715... | ||
730 | ; ret |
715 | or eax, -1 |
731 | @@: |
716 | ret |
732 | 717 | @@: |
|
733 | mov edx, [device.io_addr] |
718 | |
734 | 719 | mov edx, [ebx + device.io_addr] |
|
735 | call [device.sw_reset] |
720 | call [ebx + device.sw_reset] |
736 | 721 | ||
737 | ; Switch pcnet32 to 32bit mode |
722 | ; Switch pcnet32 to 32bit mode |
738 | mov ecx, BCR_SSTYLE |
723 | mov ecx, BCR_SSTYLE |
Line 739... | Line 724... | ||
739 | mov eax, 2 |
724 | mov eax, 2 |
740 | call [device.write_bcr] |
725 | call [ebx + device.write_bcr] |
741 | 726 | ||
742 | ; set/reset autoselect bit |
727 | ; set/reset autoselect bit |
743 | mov ecx, BCR_MISCCFG |
728 | mov ecx, BCR_MISCCFG |
744 | call [device.read_bcr] |
729 | call [ebx + device.read_bcr] |
745 | and eax, not 2 |
730 | and eax, not 2 |
746 | test [device.options], PORT_ASEL |
731 | test [ebx + device.options], PORT_ASEL |
747 | jz @f |
732 | jz @f |
748 | or eax, 2 |
733 | or eax, 2 |
749 | @@: |
734 | @@: |
750 | call [device.write_bcr] |
735 | call [ebx + device.write_bcr] |
751 | 736 | ||
752 | ; Handle full duplex setting |
737 | ; Handle full duplex setting |
753 | cmp byte [device.full_duplex], 0 |
738 | cmp byte [ebx + device.full_duplex], 0 |
754 | je .duplex_ok |
739 | je .duplex_ok |
755 | mov ecx, BCR_DUPLEX |
740 | mov ecx, BCR_DUPLEX |
756 | call [device.read_bcr] |
741 | call [ebx + device.read_bcr] |
757 | and eax, not 3 |
742 | and eax, not 3 |
758 | test [device.options], PORT_FD |
743 | test [ebx + device.options], PORT_FD |
759 | jz @f |
744 | jz @f |
760 | or eax, 1 |
745 | or eax, 1 |
761 | cmp [device.options], PORT_FD or PORT_AUI |
746 | cmp [ebx + device.options], PORT_FD or PORT_AUI |
Line 762... | Line 747... | ||
762 | jne .set_duplex |
747 | jne .set_duplex |
763 | or eax, 2 |
748 | or eax, 2 |
764 | jmp .set_duplex |
749 | jmp .set_duplex |
765 | @@: |
750 | @@: |
766 | test [device.options], PORT_ASEL |
751 | test [ebx + device.options], PORT_ASEL |
767 | jz .set_duplex |
752 | jz .set_duplex |
768 | cmp [device.chip_version], 0x2627 |
753 | cmp [ebx + device.chip_version], 0x2627 |
769 | jne .set_duplex |
754 | jne .set_duplex |
770 | or eax, 3 |
755 | or eax, 3 |
771 | .set_duplex: |
756 | .set_duplex: |
772 | mov ecx, BCR_DUPLEX |
757 | mov ecx, BCR_DUPLEX |
773 | call [device.write_bcr] |
758 | call [ebx + device.write_bcr] |
774 | .duplex_ok: |
759 | .duplex_ok: |
775 | 760 | ||
776 | ; set/reset GPSI bit in test register |
761 | ; set/reset GPSI bit in test register |
777 | mov ecx, 124 |
762 | mov ecx, 124 |
778 | call [device.read_csr] |
763 | call [ebx + device.read_csr] |
779 | mov ecx, [device.options] |
764 | mov ecx, [ebx + device.options] |
780 | and ecx, PORT_PORTSEL |
765 | and ecx, PORT_PORTSEL |
781 | cmp ecx, PORT_GPSI |
766 | cmp ecx, PORT_GPSI |
782 | jne @f |
767 | jne @f |
783 | or eax, 0x10 |
768 | or eax, 0x10 |
784 | @@: |
769 | @@: |
785 | call [device.write_csr] |
770 | call [ebx + device.write_csr] |
786 | cmp [device.mii], 0 |
771 | cmp [ebx + device.mii], 0 |
787 | je .L6 |
772 | je .L6 |
788 | test [device.options], PORT_ASEL |
773 | test [ebx + device.options], PORT_ASEL |
789 | jnz .L6 |
774 | jnz .L6 |
790 | mov ecx, BCR_MIICTL |
775 | mov ecx, BCR_MIICTL |
791 | call [device.read_bcr] |
776 | call [ebx + device.read_bcr] |
792 | and eax, not 0x38 |
777 | and eax, not 0x38 |
793 | test [device.options], PORT_FD |
778 | test [ebx + device.options], PORT_FD |
794 | jz @f |
779 | jz @f |
795 | or eax, 0x10 |
780 | or eax, 0x10 |
796 | @@: |
781 | @@: |
797 | test [device.options], PORT_100 |
782 | test [ebx + device.options], PORT_100 |
798 | jz @f |
783 | jz @f |
799 | or eax, 0x08 |
784 | or eax, 0x08 |
800 | @@: |
785 | @@: |
801 | call [device.write_bcr] |
786 | call [ebx + device.write_bcr] |
802 | jmp .L9 |
787 | jmp .L9 |
803 | .L6: |
788 | .L6: |
804 | test [device.options], PORT_ASEL |
789 | test [ebx + device.options], PORT_ASEL |
805 | jz .L9 |
790 | jz .L9 |
806 | mov ecx, BCR_MIICTL |
791 | mov ecx, BCR_MIICTL |
807 | DEBUGF 1,"ASEL, enable auto-negotiation\n" |
792 | DEBUGF 1,"ASEL, enable auto-negotiation\n" |
808 | call [device.read_bcr] |
793 | call [ebx + device.read_bcr] |
809 | and eax, not 0x98 |
794 | and eax, not 0x98 |
810 | or eax, 0x20 |
795 | or eax, 0x20 |
811 | call [device.write_bcr] |
796 | call [ebx + device.write_bcr] |
Line 812... | Line 797... | ||
812 | .L9: |
797 | .L9: |
Line 813... | Line 798... | ||
813 | cmp [device.ltint], 0 |
798 | cmp [ebx + device.ltint], 0 |
814 | je @f |
799 | je @f |
Line 815... | Line 800... | ||
815 | mov ecx, 5 |
800 | mov ecx, 5 |
Line 816... | Line 801... | ||
816 | call [device.read_csr] |
801 | call [ebx + device.read_csr] |
817 | or eax, (1 shl 14) |
802 | or eax, (1 shl 14) |
818 | call [device.write_csr] |
803 | call [ebx + device.write_csr] |
819 | @@: |
804 | @@: |
Line 848... | Line 833... | ||
848 | 833 | ||
Line 849... | Line 834... | ||
849 | DEBUGF 1, "0x%x\n", ax |
834 | DEBUGF 1, "0x%x\n", ax |
Line 850... | Line 835... | ||
850 | 835 | ||
851 | jmp .got_phy |
836 | jmp .got_phy |
852 | 837 | ||
853 | cmp [device.phy], 31 |
838 | cmp [ebx + device.phy], 31 |
854 | jne .next |
839 | jne .next |
855 | mov ax, [device.chip_version] |
840 | mov ax, [ebx + device.chip_version] |
856 | inc ax |
841 | inc ax |
Line 857... | Line 842... | ||
857 | and ax, 0xfffe |
842 | and ax, 0xfffe |
858 | cmp ax, 0x2624 ; 79c971 & 79c972 have phantom phy at id 31 |
843 | cmp ax, 0x2624 ; 79c971 & 79c972 have phantom phy at id 31 |
859 | je .got_phy |
844 | je .got_phy |
860 | 845 | ||
Line 861... | Line 846... | ||
861 | .next: |
846 | .next: |
862 | inc [device.phy] |
- | |
863 | cmp [device.phy], MAX_PHYS |
847 | inc [ebx + device.phy] |
864 | jb .mii_loop |
848 | cmp [ebx + device.phy], MAX_PHYS |
Line 865... | Line 849... | ||
865 | 849 | jb .mii_loop |
|
866 | DEBUGF 2, "No PHY found!\n" |
850 | |
Line 867... | Line 851... | ||
867 | 851 | DEBUGF 2, "No PHY found!\n" |
|
Line 868... | Line 852... | ||
868 | or eax, -1 |
852 | or eax, -1 |
Line 869... | Line 853... | ||
869 | ret |
853 | ret |
Line 870... | Line 854... | ||
870 | 854 | ||
871 | .got_phy: |
855 | .got_phy: |
872 | DEBUGF 1, "Found PHY at 0x%x\n", [device.phy]:4 |
856 | DEBUGF 1, "Found PHY at 0x%x\n", [ebx + device.phy]:4 |
873 | 857 | ||
Line 874... | Line 858... | ||
874 | .no_mii: |
858 | .no_mii: |
Line 875... | Line 859... | ||
875 | 859 | ||
Line 876... | Line 860... | ||
876 | ;----------------------------------------------- |
860 | ;----------------------------------------------- |
877 | 861 | ||
878 | call read_mac |
862 | call read_mac |
879 | 863 | ||
880 | lea esi, [device.mac] |
864 | lea esi, [ebx + device.mac] |
881 | lea edi, [device.phys_addr] |
865 | lea edi, [ebx + device.phys_addr] |
882 | movsd |
866 | movsd |
883 | movsw |
867 | movsw |
884 | 868 | ||
885 | call init_ring |
869 | call init_ring |
Line 886... | Line 870... | ||
886 | 870 | ||
887 | mov edx, [device.io_addr] ; init ring destroys edx |
871 | mov edx, [ebx + device.io_addr] ; init ring destroys edx |
888 | 872 | ||
Line 889... | Line 873... | ||
889 | lea eax, [device.private] |
873 | lea eax, [ebx + device.mode] |
890 | GetRealAddr |
874 | invoke GetPhysAddr |
891 | push eax |
875 | push eax |
892 | and eax, 0xffff |
876 | and eax, 0xffff |
Line 893... | Line 877... | ||
893 | mov ecx, 1 |
877 | mov ecx, 1 |
894 | call [device.write_csr] |
878 | call [ebx + device.write_csr] |
895 | pop eax |
879 | pop eax |
896 | shr eax, 16 |
880 | shr eax, 16 |
Line 897... | Line 881... | ||
897 | mov ecx, 2 |
881 | mov ecx, 2 |
898 | call [device.write_csr] |
882 | call [ebx + device.write_csr] |
899 | 883 | ||
900 | mov ecx, 4 |
884 | mov ecx, 4 |
901 | mov eax, 0x0915 |
885 | mov eax, 0x0915 |
902 | call [device.write_csr] |
886 | call [ebx + device.write_csr] |
Line 903... | Line 887... | ||
903 | 887 | ||
904 | ; Set the interrupt mask |
888 | ; Set the interrupt mask |
Line 924... | Line 908... | ||
924 | @@: |
908 | @@: |
Line 925... | Line 909... | ||
925 | 909 | ||
926 | ; Start the device and enable interrupts |
910 | ; Start the device and enable interrupts |
927 | xor ecx, ecx |
911 | xor ecx, ecx |
928 | mov eax, CSR_START + CSR_INTEN |
912 | mov eax, CSR_START + CSR_INTEN |
Line 929... | Line 913... | ||
929 | call [device.write_csr] |
913 | call [ebx + device.write_csr] |
930 | 914 | ||
Line 931... | Line 915... | ||
931 | ; Set the mtu, kernel will be able to send now |
915 | ; Set the mtu, kernel will be able to send now |
932 | mov [device.mtu], 1514 |
916 | mov [ebx + device.mtu], 1514 |
Line 933... | Line 917... | ||
933 | 917 | ||
Line 934... | Line 918... | ||
934 | ; get link status |
918 | ; get link status |
935 | mov [device.state], ETH_LINK_UNKOWN |
919 | mov [ebx + device.state], ETH_LINK_UNKOWN |
Line 944... | Line 928... | ||
944 | align 4 |
928 | align 4 |
945 | init_ring: |
929 | init_ring: |
Line 946... | Line 930... | ||
946 | 930 | ||
Line 947... | Line 931... | ||
947 | DEBUGF 1,"init ring\n" |
931 | DEBUGF 1,"init ring\n" |
948 | 932 | ||
949 | lea edi, [device.rx_ring] |
933 | lea edi, [ebx + device.rx_ring] |
950 | mov eax, edi |
934 | mov eax, edi |
951 | GetRealAddr |
935 | invoke GetPhysAddr |
952 | mov [device.rx_ring_phys], eax |
936 | mov [ebx + device.rx_ring_phys], eax |
953 | mov ecx, RX_RING_SIZE |
937 | mov ecx, RX_RING_SIZE |
954 | .rx_init: |
938 | .rx_init: |
955 | push ecx |
939 | push ecx |
956 | stdcall KernelAlloc, PKT_BUF_SZ |
940 | invoke KernelAlloc, PKT_BUF_SZ |
957 | pop ecx |
941 | pop ecx |
958 | mov [edi + descriptor.virtual], eax |
942 | mov [edi + descriptor.virtual], eax |
959 | GetRealAddr |
943 | invoke GetPhysAddr |
960 | mov [edi + descriptor.base], eax |
944 | mov [edi + descriptor.base], eax |
961 | mov [edi + descriptor.length], - PKT_BUF_SZ |
945 | mov [edi + descriptor.length], - PKT_BUF_SZ |
962 | mov [edi + descriptor.status], RXSTAT_OWN |
946 | mov [edi + descriptor.status], RXSTAT_OWN |
963 | mov dword [edi + descriptor.msg_length], 0 ; also clears misc field |
947 | mov dword[edi + descriptor.msg_length], 0 ; also clears misc field |
964 | add edi, descriptor.size |
948 | add edi, sizeof.descriptor |
Line 965... | Line 949... | ||
965 | dec ecx |
949 | dec ecx |
966 | jnz .rx_init |
950 | jnz .rx_init |
967 | 951 | ||
968 | lea edi, [device.tx_ring] |
952 | lea edi, [ebx + device.tx_ring] |
969 | mov eax, edi |
953 | mov eax, edi |
970 | GetRealAddr |
954 | invoke GetPhysAddr |
971 | mov [device.tx_ring_phys], eax |
955 | mov [ebx + device.tx_ring_phys], eax |
972 | mov ecx, TX_RING_SIZE |
956 | mov ecx, TX_RING_SIZE |
973 | .tx_init: |
957 | .tx_init: |
974 | mov [edi + descriptor.status], 0 |
958 | mov [edi + descriptor.status], 0 |
Line 975... | Line 959... | ||
975 | add edi, descriptor.size |
959 | add edi, sizeof.descriptor |
Line 976... | Line 960... | ||
976 | dec ecx |
960 | dec ecx |
977 | jnz .tx_init |
961 | jnz .tx_init |
978 | 962 | ||
Line 979... | Line 963... | ||
979 | mov [device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS) |
963 | mov [ebx + device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS) |
Line 980... | Line 964... | ||
980 | 964 | ||
981 | mov [device.cur_tx], 0 |
965 | mov [ebx + device.cur_tx], 0 |
982 | mov [device.last_tx], 0 |
966 | mov [ebx + device.last_tx], 0 |
983 | mov [device.cur_rx], 0 |
967 | mov [ebx + device.cur_rx], 0 |
984 | - | ||
985 | ret |
- | |
986 | 968 | ||
987 | 969 | ret |
|
988 | 970 | ||
Line -... | Line 971... | ||
- | 971 | ||
- | 972 | ||
989 | 973 | ||
990 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
974 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | 975 | ;; ;; |
|
991 | ;; ;; |
976 | ;; Transmit ;; |
992 | ;; Transmit ;; |
977 | ;; ;; |
993 | ;; ;; |
978 | ;; In: pointer to device structure in ebx ;; |
994 | ;; In: buffer pointer in [esp+4] ;; |
979 | ;; ;; |
995 | ;; size of buffer in [esp+8] ;; |
980 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
996 | ;; pointer to device structure in ebx ;; |
981 | |
Line 997... | Line 982... | ||
997 | ;; ;; |
982 | proc transmit stdcall bufferptr, buffersize |
998 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
983 | |
999 | 984 | pushf |
|
1000 | align 4 |
985 | cli |
Line 1001... | Line 986... | ||
1001 | transmit: |
986 | |
1002 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
987 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
1003 | mov eax, [esp+4] |
988 | mov eax, [bufferptr] |
1004 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
989 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
1005 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
990 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
Line 1006... | Line 991... | ||
1006 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
991 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
1007 | [eax+13]:2,[eax+12]:2 |
992 | [eax+13]:2,[eax+12]:2 |
1008 | 993 | ||
1009 | cmp dword [esp+8], 1514 |
994 | cmp [buffersize], 1514 |
1010 | ja .nospace ; packet is too long |
995 | ja .fail |
1011 | cmp dword [esp+8], 60 |
996 | cmp [buffersize], 60 |
1012 | jb .nospace ; packet is too short |
997 | jb .fail |
1013 | 998 | ||
1014 | ; check descriptor |
999 | ; check descriptor |
1015 | lea edi, [device.tx_ring] |
1000 | lea edi, [ebx + device.tx_ring] |
1016 | movzx eax, [device.cur_tx] |
1001 | movzx eax, [ebx + device.cur_tx] |
1017 | shl eax, 4 |
1002 | shl eax, 4 |
1018 | add edi, eax |
1003 | add edi, eax |
Line 1019... | Line 1004... | ||
1019 | 1004 | ||
1020 | test [edi + descriptor.status], TXCTL_OWN |
1005 | test [edi + descriptor.status], TXCTL_OWN |
1021 | jnz .nospace |
1006 | jnz .fail |
1022 | ; descriptor is free, use it |
1007 | ; descriptor is free, use it |
1023 | mov eax, [esp+4] |
1008 | mov eax, [bufferptr] |
1024 | mov [edi + descriptor.virtual], eax |
1009 | mov [edi + descriptor.virtual], eax |
Line 1025... | Line 1010... | ||
1025 | GetRealAddr |
1010 | invoke GetPhysAddr |
1026 | mov [edi + descriptor.base], eax |
1011 | mov [edi + descriptor.base], eax |
1027 | ; set length |
1012 | ; set length |
Line 1028... | Line 1013... | ||
1028 | mov eax, [esp+8] |
1013 | mov eax, [buffersize] |
1029 | neg eax |
1014 | neg eax |
1030 | mov [edi + descriptor.length], ax |
1015 | mov [edi + descriptor.length], ax |
1031 | ; put to transfer queue |
1016 | ; put to transfer queue |
1032 | mov [edi + descriptor.status], TXCTL_OWN + TXCTL_STP + TXCTL_ENP |
1017 | mov [edi + descriptor.status], TXCTL_OWN + TXCTL_STP + TXCTL_ENP |
Line 1033... | Line 1018... | ||
1033 | 1018 | ||
1034 | ; trigger an immediate send |
1019 | ; trigger an immediate send |
1035 | mov edx, [device.io_addr] |
1020 | mov edx, [ebx + device.io_addr] |
1036 | xor ecx, ecx ; CSR0 |
1021 | xor ecx, ecx ; CSR0 |
Line 1037... | Line 1022... | ||
1037 | call [device.read_csr] |
1022 | call [ebx + device.read_csr] |
1038 | or eax, CSR_TX |
1023 | or eax, CSR_TX |
1039 | call [device.write_csr] |
1024 | call [ebx + device.write_csr] |
- | 1025 | ||
1040 | 1026 | ; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ... |
|
1041 | ; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ... |
1027 | inc [ebx + device.cur_tx] |
Line -... | Line 1028... | ||
- | 1028 | and [ebx + device.cur_tx], TX_RING_SIZE - 1 |
|
Line 1042... | Line 1029... | ||
1042 | inc [device.cur_tx] |
1029 | |
1043 | and [device.cur_tx], TX_RING_SIZE - 1 |
1030 | ; Update stats |
1044 | 1031 | inc [ebx + device.packets_tx] |
|
Line 1080... | Line 1067... | ||
1080 | test ecx, ecx |
1067 | test ecx, ecx |
1081 | jz .nothing |
1068 | jz .nothing |
1082 | mov esi, device_list |
1069 | mov esi, device_list |
1083 | .nextdevice: |
1070 | .nextdevice: |
1084 | mov ebx, [esi] |
1071 | mov ebx, [esi] |
1085 | - | ||
1086 | mov edx, [device.io_addr] |
1072 | mov edx, [ebx + device.io_addr] |
1087 | push ecx |
1073 | push ecx |
1088 | xor ecx, ecx ; CSR0 |
1074 | xor ecx, ecx ; CSR0 |
1089 | call [device.read_csr] ; get IRQ reason |
1075 | call [ebx + device.read_csr] ; get IRQ reason |
1090 | call [device.write_csr] ; write it back to ACK |
1076 | call [ebx + device.write_csr] ; write it back to ACK |
1091 | pop ecx |
1077 | pop ecx |
1092 | and ax, CSR_RINT or CSR_TINT |
1078 | and ax, CSR_RINT or CSR_TINT |
1093 | jnz .got_it |
1079 | jnz .got_it |
1094 | .continue: |
1080 | .continue: |
1095 | add esi, 4 |
1081 | add esi, 4 |
Line 1100... | Line 1086... | ||
1100 | xor eax, eax |
1086 | xor eax, eax |
Line 1101... | Line 1087... | ||
1101 | 1087 | ||
Line 1102... | Line 1088... | ||
1102 | ret |
1088 | ret |
1103 | 1089 | ||
Line 1104... | Line 1090... | ||
1104 | .got_it: |
1090 | .got_it: |
1105 | DEBUGF 1,"Device: %x status: %x\n", ebx, eax:2 |
1091 | DEBUGF 1,"Device: %x status: %x\n", ebx, eax:4 |
1106 | 1092 | ||
Line 1107... | Line 1093... | ||
1107 | push ax |
1093 | push ax |
1108 | test ax, CSR_RINT |
1094 | test ax, CSR_RINT |
1109 | jz .not_receive |
1095 | jz .not_receive |
1110 | 1096 | ||
1111 | push ebx |
1097 | push ebx |
1112 | .rx_loop: |
1098 | .rx_loop: |
1113 | pop ebx |
1099 | pop ebx |
Line 1114... | Line 1100... | ||
1114 | movzx eax, [device.cur_rx] |
1100 | movzx eax, [ebx + device.cur_rx] |
1115 | shl eax, 4 |
1101 | shl eax, 4 |
Line 1127... | Line 1113... | ||
1127 | 1113 | ||
1128 | test ax, RXSTAT_STP |
1114 | test ax, RXSTAT_STP |
Line 1129... | Line 1115... | ||
1129 | jz .not_receive |
1115 | jz .not_receive |
1130 | 1116 | ||
- | 1117 | movzx ecx, [edi + descriptor.msg_length] ; get packet length in ecx |
|
Line 1131... | Line 1118... | ||
1131 | movzx ecx, [edi + descriptor.msg_length] ; get packet length in ecx |
1118 | sub ecx, 4 ; We dont need the CRC |
1132 | sub ecx, 4 ; |
1119 | DEBUGF 1,"Got %u bytes\n", ecx |
Line 1133... | Line 1120... | ||
1133 | 1120 | ||
1134 | ; Set pointers for ETH_input |
1121 | ; Set pointers for ETH_input |
1135 | push ebx |
1122 | push ebx |
Line 1136... | Line 1123... | ||
1136 | 1123 | ||
1137 | push .rx_loop ; return address |
1124 | push .rx_loop ; return address |
1138 | push ecx ; packet size |
1125 | push ecx ; packet size |
1139 | push [edi + descriptor.virtual] ; packet address |
1126 | push [edi + descriptor.virtual] ; packet address |
Line 1140... | Line 1127... | ||
1140 | 1127 | ||
1141 | ; Update stats |
1128 | ; Update stats |
1142 | add dword [device.bytes_rx], ecx |
1129 | add dword[ebx + device.bytes_rx], ecx |
1143 | adc dword [device.bytes_rx + 4], 0 |
1130 | adc dword[ebx + device.bytes_rx + 4], 0 |
1144 | inc [device.packets_rx] |
1131 | inc [ebx + device.packets_rx] |
1145 | - | ||
1146 | ; now allocate a new buffer |
- | |
1147 | stdcall KernelAlloc, PKT_BUF_SZ ; Allocate a buffer for the next packet |
1132 | |
Line 1148... | Line 1133... | ||
1148 | mov [edi + descriptor.virtual], eax ; set virtual address |
1133 | ; now allocate a new buffer |
1149 | GetRealAddr |
1134 | invoke KernelAlloc, PKT_BUF_SZ ; Allocate a buffer for the next packet |
Line 1150... | Line 1135... | ||
1150 | mov [edi + descriptor.base], eax ; and real address |
1135 | mov [edi + descriptor.virtual], eax ; set virtual address |
Line 1151... | Line 1136... | ||
1151 | 1136 | invoke GetPhysAddr |
|
1152 | ; mov word [edi + descriptor.length], - PKT_BUF_SZ |
1137 | mov [edi + descriptor.base], eax ; and physical address |
Line 1153... | Line 1138... | ||
1153 | mov [edi + descriptor.status], RXSTAT_OWN ; give it back to PCnet controller |
1138 | mov [edi + descriptor.status], RXSTAT_OWN ; give it back to PCnet controller |
1154 | 1139 | ||
Line 1155... | Line 1140... | ||
1155 | inc [device.cur_rx] ; set next receive descriptor |
1140 | inc [ebx + device.cur_rx] ; set next receive descriptor |
1156 | and [device.cur_rx], RX_RING_SIZE - 1 |
1141 | and [ebx + device.cur_rx], RX_RING_SIZE - 1 |
1157 | 1142 | ||
1158 | jmp Eth_input |
1143 | jmp [Eth_input] |
1159 | 1144 | ||
Line 1160... | Line 1145... | ||
1160 | .not_receive: |
1145 | .not_receive: |
1161 | pop ax |
1146 | pop ax |
Line 1178... | Line 1163... | ||
1178 | 1163 | ||
Line 1179... | Line 1164... | ||
1179 | mov [edi + descriptor.virtual], 0 |
1164 | mov [edi + descriptor.virtual], 0 |
Line 1180... | Line 1165... | ||
1180 | 1165 | ||
Line 1181... | Line 1166... | ||
1181 | DEBUGF 1,"Removing packet %x from memory\n", eax |
1166 | DEBUGF 1,"Removing packet %x from memory\n", eax |
1182 | 1167 | ||
1183 | stdcall KernelFree, eax |
1168 | invoke KernelFree, eax |
Line 1184... | Line 1169... | ||
1184 | 1169 | ||
1185 | inc [device.last_tx] |
1170 | inc [ebx + device.last_tx] |
1186 | and [device.last_tx], TX_RING_SIZE - 1 |
1171 | and [ebx + device.last_tx], TX_RING_SIZE - 1 |
Line 1203... | Line 1188... | ||
1203 | ;;;;;;;;;;;;;;;;;;;;;;; |
1188 | ;;;;;;;;;;;;;;;;;;;;;;; |
Line 1204... | Line 1189... | ||
1204 | 1189 | ||
1205 | align 4 |
1190 | align 4 |
Line -... | Line 1191... | ||
- | 1191 | write_mac: ; in: mac pushed onto stack (as 3 words) |
|
1206 | write_mac: ; in: mac pushed onto stack (as 3 words) |
1192 | |
Line 1207... | Line 1193... | ||
1207 | 1193 | DEBUGF 1,"Writing MAC: %x-%x-%x-%x-%x-%x\n",\ |
|
1208 | DEBUGF 1,"Writing MAC: %x-%x-%x-%x-%x-%x",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 |
1194 | [esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 |
1209 | 1195 | ||
Line 1210... | Line 1196... | ||
1210 | mov edx, [device.io_addr] |
1196 | mov edx, [ebx + device.io_addr] |
1211 | add dx, 2 |
1197 | add dx, 2 |
1212 | xor eax, eax |
1198 | xor eax, eax |
1213 | 1199 | ||
1214 | mov ecx, CSR_PAR0 |
- | |
1215 | @@: |
1200 | mov ecx, CSR_PAR0 |
1216 | pop ax |
1201 | @@: |
1217 | call [device.write_csr] |
1202 | pop ax |
Line 1218... | Line -... | ||
1218 | DEBUGF 1,"." |
- | |
1219 | inc ecx |
- | |
1220 | cmp ecx, CSR_PAR2 |
1203 | call [ebx + device.write_csr] |
Line 1221... | Line 1204... | ||
1221 | jb @r |
1204 | inc ecx |
1222 | 1205 | cmp ecx, CSR_PAR2 |
|
1223 | DEBUGF 1,"\n" |
1206 | jb @r |
1224 | 1207 | ||
1225 | ; Notice this procedure does not ret, but continues to read_mac instead. |
1208 | ; Notice this procedure does not ret, but continues to read_mac instead. |
1226 | 1209 | ||
1227 | ;;;;;;;;;;;;;;;;;;;;;; |
1210 | ;;;;;;;;;;;;;;;;;;;;;; |
1228 | ;; ;; |
1211 | ;; ;; |
Line 1229... | Line 1212... | ||
1229 | ;; Read MAC address ;; |
1212 | ;; Read MAC address ;; |
1230 | ;; ;; |
1213 | ;; ;; |
1231 | ;;;;;;;;;;;;;;;;;;;;;; |
- | |
1232 | align 4 |
- | |
1233 | read_mac: |
- | |
1234 | DEBUGF 1,"Reading MAC:\n" |
1214 | ;;;;;;;;;;;;;;;;;;;;;; |
1235 | - | ||
1236 | mov edx, [device.io_addr] |
- | |
1237 | add dx, 6 |
- | |
1238 | @@: |
- | |
1239 | dec dx |
- | |
1240 | dec dx |
- | |
1241 | in ax, dx |
- | |
1242 | push ax |
- | |
1243 | cmp edx, [device.io_addr] |
1215 | align 4 |
- | 1216 | read_mac: |
|
- | 1217 | DEBUGF 1,"Reading MAC\n" |
|
1244 | ja @r |
1218 | |
- | 1219 | mov edx, [ebx + device.io_addr] |
|
1245 | 1220 | lea edi, [ebx + device.mac] |
|
- | 1221 | in ax, dx |
|
- | 1222 | stosw |
|
1246 | DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2 |
1223 | |
- | 1224 | inc dx |
|
1247 | 1225 | inc dx |
|
Line -... | Line 1226... | ||
- | 1226 | in ax, dx |
|
- | 1227 | stosw |
|
- | 1228 | ||
- | 1229 | inc dx |
|
1248 | lea edi, [device.mac] |
1230 | inc dx |
Line 1249... | Line 1231... | ||
1249 | pop ax |
1231 | in ax, dx |
1250 | stosw |
1232 | stosw |
Line 1251... | Line 1233... | ||
1251 | pop ax |
1233 | |
Line 1252... | Line 1234... | ||
1252 | stosw |
1234 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
1253 | pop ax |
1235 | [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,\ |
1254 | stosw |
1236 | [ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2 |
1255 | 1237 | ||
1256 | ret |
1238 | ret |
1257 | 1239 | ||
1258 | align 4 |
1240 | align 4 |
Line 1259... | Line 1241... | ||
1259 | switch_to_wio: |
1241 | switch_to_wio: |
Line 1260... | Line 1242... | ||
1260 | 1242 | ||
1261 | DEBUGF 1,"Switching to 16-bit mode\n" |
1243 | DEBUGF 1,"Switching to 16-bit mode\n" |
Line 1262... | Line 1244... | ||
1262 | 1244 | ||
Line 1263... | Line 1245... | ||
1263 | mov [device.read_csr], wio_read_csr |
1245 | mov [ebx + device.read_csr], wio_read_csr |
1264 | mov [device.write_csr], wio_write_csr |
1246 | mov [ebx + device.write_csr], wio_write_csr |
1265 | mov [device.read_bcr], wio_read_bcr |
1247 | mov [ebx + device.read_bcr], wio_read_bcr |
1266 | mov [device.write_bcr], wio_write_bcr |
1248 | mov [ebx + device.write_bcr], wio_write_bcr |
1267 | mov [device.read_rap], wio_read_rap |
1249 | mov [ebx + device.read_rap], wio_read_rap |
1268 | mov [device.write_rap], wio_write_rap |
1250 | mov [ebx + device.write_rap], wio_write_rap |
1269 | mov [device.sw_reset], wio_reset |
1251 | mov [ebx + device.sw_reset], wio_reset |
Line 1270... | Line 1252... | ||
1270 | 1252 | ||
Line 1271... | Line 1253... | ||
1271 | ret |
1253 | ret |
Line 1483... | Line 1465... | ||
1483 | 1465 | ||
1484 | align 4 |
1466 | align 4 |
Line 1485... | Line 1467... | ||
1485 | mdio_read: |
1467 | mdio_read: |
1486 | 1468 | ||
1487 | and ecx, 0x1f |
1469 | and ecx, 0x1f |
1488 | mov ax, [device.phy] |
1470 | mov ax, [ebx + device.phy] |
1489 | and ax, 0x1f |
1471 | and ax, 0x1f |
Line 1490... | Line 1472... | ||
1490 | shl ax, 5 |
1472 | shl ax, 5 |
1491 | or ax, cx |
1473 | or ax, cx |
Line 1492... | Line 1474... | ||
1492 | 1474 | ||
1493 | mov ecx, BCR_MIIADDR |
1475 | mov ecx, BCR_MIIADDR |
Line 1494... | Line 1476... | ||
1494 | call [device.write_bcr] |
1476 | call [ebx + device.write_bcr] |
Line 1495... | Line 1477... | ||
1495 | 1477 | ||
1496 | mov ecx, BCR_MIIDATA |
1478 | mov ecx, BCR_MIIDATA |
Line 1497... | Line 1479... | ||
1497 | call [device.read_bcr] |
1479 | call [ebx + device.read_bcr] |
1498 | 1480 | ||
1499 | ret |
1481 | ret |
1500 | 1482 | ||
1501 | 1483 | ||
1502 | align 4 |
1484 | align 4 |
Line 1503... | Line 1485... | ||
1503 | mdio_write: |
1485 | mdio_write: |
1504 | 1486 | ||
Line 1505... | Line 1487... | ||
1505 | push eax |
1487 | push eax |
1506 | and ecx, 0x1f |
1488 | and ecx, 0x1f |
1507 | mov ax, [device.phy] |
1489 | mov ax, [ebx + device.phy] |
Line 1508... | Line 1490... | ||
1508 | and ax, 0x1f |
1490 | and ax, 0x1f |
Line 1509... | Line 1491... | ||
1509 | shl ax, 5 |
1491 | shl ax, 5 |
1510 | or ax, cx |
1492 | or ax, cx |
Line 1511... | Line 1493... | ||
1511 | 1493 | ||
Line 1512... | Line 1494... | ||
1512 | mov ecx, BCR_MIIADDR |
1494 | mov ecx, BCR_MIIADDR |
1513 | call [device.write_bcr] |
1495 | call [ebx + device.write_bcr] |
Line 1514... | Line 1496... | ||
1514 | 1496 | ||
1515 | pop eax |
1497 | pop eax |
1516 | mov ecx, BCR_MIIDATA |
1498 | mov ecx, BCR_MIIDATA |
Line 1517... | Line 1499... | ||
1517 | call [device.write_bcr] |
1499 | call [ebx + device.write_bcr] |
Line 1518... | Line 1500... | ||
1518 | 1500 | ||
Line 1519... | Line 1501... | ||
1519 | ret |
1501 | ret |
Line 1520... | Line -... | ||
1520 | - | ||
Line 1521... | Line 1502... | ||
1521 | 1502 | ||
- | 1503 | ||
- | 1504 | align 4 |
|
1522 | align 4 |
1505 | check_media: |
- | 1506 | ||
1523 | check_media: |
1507 | DEBUGF 1, "check_media\n" |
Line 1524... | Line 1508... | ||
1524 | 1508 | ||
1525 | DEBUGF 1, "check_media\n" |
1509 | test [ebx + device.mii], 1 |
1526 | 1510 | jnz mii_link_ok |
|
Line 1571... | Line 1555... | ||
1571 | dd PORT_MII or PORT_100 or PORT_FD ; 14 MII 100BaseTx-FD |
1555 | dd PORT_MII or PORT_100 or PORT_FD ; 14 MII 100BaseTx-FD |
1572 | dd PORT_ASEL ; 15 not supported |
1556 | dd PORT_ASEL ; 15 not supported |
Line 1573... | Line 1557... | ||
1573 | 1557 | ||
Line 1574... | Line -... | ||
1574 | include_debug_strings ; All data wich FDO uses will be included here |
- | |
Line -... | Line 1558... | ||
- | 1558 | include_debug_strings ; All data wich FDO uses will be included here |
|
- | 1559 | ||
1575 | 1560 |