Subversion Repositories Kolibri OS

Rev

Rev 4439 | Rev 4467 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4439 Rev 4450
Line 196... Line 196...
196
        .io_addr        dd ?
196
        .io_addr        dd ?
Line 197... Line 197...
197
 
197
 
198
        .cur_rx         dw ?
198
        .cur_rx         dw ?
199
        .cur_tx         dw ?
199
        .cur_tx         dw ?
200
        .last_tx        dw ?
200
        .last_tx        dw ?
201
        .phy_addr       dw ?
201
        .phy_addr       dd ?
202
        .phy_mode       dw ?
202
        .phy_mode       dw ?
203
        .mcr0           dw ?
203
        .mcr0           dw ?
204
        .mcr1           dw ?
204
        .mcr1           dw ?
Line 205... Line 205...
205
        .switch_sig     dw ?
205
        .switch_sig     dw ?
206
 
206
 
207
        .pci_bus        dd ?
207
        .pci_bus        dd ?
Line 208... Line 208...
208
        .pci_dev        dd ?
208
        .pci_dev        dd ?
Line 209... Line 209...
209
        .irq_line       db ?
209
        .irq_line       db ?
210
 
210
 
Line 211... Line 211...
211
        rb 3            ; dword alignment
211
        rb 1            ; dword alignment
Line 393... Line 393...
393
;;        Actual Hardware dependent code starts here                      ;;
393
;;        Actual Hardware dependent code starts here                      ;;
394
;;                                                                        ;;
394
;;                                                                        ;;
395
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
395
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
Line 396... Line 396...
396
 
396
 
397
 
397
 
398
macro mdio_write reg, val {
398
;mdio_read:
-
 
399
;        stdcall phy_read, [device.io_addr], [device.phy_addr], ecx
399
        stdcall phy_read, [device.io_addr], [device.phy_addr], reg
400
 
400
}
401
;        ret
401
 
402
 
402
macro mdio_write reg, val {
403
;mdio_write:
-
 
404
;        stdcall phy_write, [device.io_addr], [device.phy_addr], ecx, eax
Line 403... Line 405...
403
        stdcall phy_write, [device.io_addr], [devce.phy_addr], reg, val
405
 
404
}
406
;        ret
405
 
407
 
Line 419... Line 421...
419
ret
421
ret
Line 420... Line 422...
420
 
422
 
421
 
423
 
422
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
424
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
423
;;
425
;;
424
;;  probe: enables the device (if it really is RTL8139)
426
;;  probe: enables the device (if it really is R6040)
Line 425... Line 427...
425
;;
427
;;
426
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 453... Line 455...
453
        DEBUGF  2, "MAC address not initialized!\n"
455
        DEBUGF  2, "MAC address not initialized!\n"
Line 454... Line 456...
454
 
456
 
455
     @@:
457
     @@:
456
        ; Init RDC private data
458
        ; Init RDC private data
457
        mov     [device.mcr0], MCR0_XMTEN or MCR0_RCVEN
459
        mov     [device.mcr0], MCR0_XMTEN or MCR0_RCVEN
458
        ;mov     [private.phy_addr], 1 ; Asper: Only one network card is supported now.
460
        mov     [device.phy_addr], PHY1_ADDR
Line 459... Line 461...
459
        mov     [device.switch_sig], 0
461
        mov     [device.switch_sig], 0
460
 
462
 
461
        ; Check the vendor ID on the PHY, if 0xFFFF assume none attached
463
        ; Check the vendor ID on the PHY, if 0xFFFF assume none attached
462
        stdcall phy_read, 1, 2
464
        stdcall phy_read, [device.phy_addr], 2
463
        cmp     ax, 0xFFFF
465
        cmp     ax, 0xFFFF
464
        jne     @f
466
        jne     @f
465
        DEBUGF  2, "Failed to detect an attached PHY\n" ;, generating random"
467
        DEBUGF  2, "Failed to detect an attached PHY!\n"
466
        mov     eax, -1
468
        mov     eax, -1
Line 467... Line 469...
467
        ret
469
        ret
Line 483... Line 485...
483
        stdcall phy_write, 29, 31, 0x175C ; Enable registers
485
        stdcall phy_write, 29, 31, 0x175C ; Enable registers
484
        jmp     .phy_readen
486
        jmp     .phy_readen
485
      @@:
487
      @@:
Line 486... Line 488...
486
 
488
 
487
        ; PHY Mode Check
-
 
488
        movzx   eax, [device.phy_addr]
489
        ; PHY Mode Check
489
        stdcall phy_write, eax, 4, PHY_CAP
490
        stdcall phy_write, [device.phy_addr], 4, PHY_CAP
Line 490... Line 491...
490
        stdcall phy_write, eax, 0, PHY_MODE
491
        stdcall phy_write, [device.phy_addr], 0, PHY_MODE
491
 
492
 
492
      if PHY_MODE = 0x3100
493
      if PHY_MODE = 0x3100
493
        call    phy_mode_chk
494
        call    phy_mode_chk
Line 710... Line 711...
710
phy_mode_chk:
711
phy_mode_chk:
Line 711... Line 712...
711
 
712
 
Line 712... Line 713...
712
        DEBUGF  1,"Checking PHY mode\n"
713
        DEBUGF  1,"Checking PHY mode\n"
713
 
714
 
714
        ; PHY Link Status Check
-
 
715
        movzx   eax, [device.phy_addr]
715
        ; PHY Link Status Check
716
        stdcall phy_read, eax, 1
716
        stdcall phy_read, [device.phy_addr], MII_BMSR
Line 717... Line 717...
717
        test    eax, 0x4
717
        test    ax, BMSR_LSTATUS
718
        jz      .ret_0x8000
-
 
719
 
-
 
720
        ; PHY Chip Auto-Negotiation Status
718
        jz      .ret_0x8000
721
        movzx   eax, [device.phy_addr]
719
 
Line 722... Line 720...
722
        stdcall phy_read, eax, 1
720
        ; PHY Chip Auto-Negotiation Status
723
        test    eax, 0x0020
721
        test    ax, BMSR_ANEGCOMPLETE
724
        jnz     .auto_nego
-
 
725
 
722
        jnz     .auto_nego
726
        ; Force Mode
723
 
Line 727... Line 724...
727
        movzx   eax, [device.phy_addr]
724
        ; Force Mode
728
        stdcall phy_read, eax, 0
725
        stdcall phy_read, [device.phy_addr], MII_BMCR
729
        test    eax, 0x100
726
        test    ax, BMCR_FULLDPLX
730
        jnz     .ret_0x8000
-
 
731
 
727
        jnz     .ret_0x8000
732
  .auto_nego:
728
 
733
        ; Auto Negotiation Mode
-
 
734
        movzx   eax, [device.phy_addr]
729
  .auto_nego:
735
        stdcall phy_read, eax, 5
730
        ; Auto Negotiation Mode
736
        mov     ecx, eax
731
        stdcall phy_read, [device.phy_addr], MII_LPA
Line 737... Line 732...
737
        movzx   eax, [device.phy_addr]
732
        mov     cx, ax
738
        stdcall phy_read, eax, 4
733
        stdcall phy_read, [device.phy_addr], MII_ADVERTISE
Line 801... Line 796...
801
        set_io  MTPR
796
        set_io  MTPR
802
        out     dx, ax
797
        out     dx, ax
Line 803... Line 798...
803
 
798
 
804
        inc     [device.cur_tx]
799
        inc     [device.cur_tx]
805
        and     [device.cur_tx], TX_RING_SIZE - 1
-
 
Line 806... Line 800...
806
        xor     eax, eax
800
        and     [device.cur_tx], TX_RING_SIZE - 1
807
 
801
 
808
; Update stats
802
; Update stats
809
        inc     [device.packets_tx]
803
        inc     [device.packets_tx]
810
        mov     eax, [esp+8]
804
        mov     eax, [esp+8]
Line -... Line 805...
-
 
805
        add     dword [device.bytes_tx], eax
811
        add     dword [device.bytes_tx], eax
806
        adc     dword [device.bytes_tx + 4], 0
Line 812... Line 807...
812
        adc     dword [device.bytes_tx + 4], 0
807
 
Line 813... Line 808...
813
 
808
        xor     eax, eax
Line 987... Line 982...
987
 
982
 
988
  .no_rxfifo:
983
  .no_rxfifo:
989
        test    word[esp], RX_EARLY
984
        test    word[esp], RX_EARLY
Line 990... Line 985...
990
        jz      .no_rxearly
985
        jz      .no_rxearly
Line 991... Line 986...
991
 
986
 
992
        DEBUGF  1, "RX early\n"
987
        DEBUGF  2, "RX early\n"
993
 
988
 
Line 994... Line 989...
994
  .no_rxearly:
989
  .no_rxearly:
Line 995... Line 990...
995
        test    word[esp], TX_EARLY
990
        test    word[esp], TX_EARLY
996
        jz      .no_txearly
991
        jz      .no_txearly
997
 
992
 
Line 1005... Line 1000...
1005
 
1000
 
1006
  .no_ovrfl:
1001
  .no_ovrfl:
1007
        test    word[esp], LINK_CHANGED
1002
        test    word[esp], LINK_CHANGED
Line 1008... Line 1003...
1008
        jz      .no_link
1003
        jz      .no_link
Line 1009... Line 1004...
1009
 
1004
 
1010
        DEBUGF  1, "Link changed\n"
1005
        DEBUGF  2, "Link changed\n"
Line 1011... Line 1006...
1011
 
1006
 
Line 1095... Line 1090...
1095
        set_io  0
1090
        set_io  0
1096
        set_io  MMWD
1091
        set_io  MMWD
1097
        out     dx, ax
1092
        out     dx, ax
Line 1098... Line 1093...
1098
 
1093
 
1099
        ;Write the command to the MDIO bus
-
 
1100
 
1094
        ;Write the command to the MDIO bus
1101
        mov     eax, [phy_addr]
1095
        mov     eax, [phy_addr]
1102
        shl     eax, 8
1096
        shl     eax, 8
1103
        add     eax, [reg]
1097
        add     eax, [reg]
1104
        add     eax, MDIO_WRITE
1098
        add     eax, MDIO_WRITE
Line 1123... Line 1117...
1123
 
1117
 
1124
 
1118
 
Line 1125... Line 1119...
1125
align 4
1119
align 4
Line 1126... Line 1120...
1126
read_mac:
1120
read_mac:
1127
 
1121
 
1128
        DEBUGF  1,"Reading MAC: "
1122
        DEBUGF  1,"Reading MAC:\n"
1129
 
1123