Subversion Repositories Kolibri OS

Rev

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

Rev 4803 Rev 5050
Line 16... Line 16...
16
;;          GNU GENERAL PUBLIC LICENSE                             ;;
16
;;          GNU GENERAL PUBLIC LICENSE                             ;;
17
;;             Version 2, June 1991                                ;;
17
;;             Version 2, June 1991                                ;;
18
;;                                                                 ;;
18
;;                                                                 ;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 20... Line 20...
20
 
20
 
-
 
21
format PE DLL native
Line 21... Line 22...
21
format MS COFF
22
entry START
22
 
23
 
-
 
24
        CURRENT_API             = 0x0200
Line 23... Line 25...
23
        API_VERSION             = 0x01000100
25
        COMPATIBLE_API          = 0x0100
Line 24... Line -...
24
        DRIVER_VERSION          = 5
-
 
25
 
26
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
26
        MAX_DEVICES             = 16
27
 
Line 27... Line 28...
27
 
28
        MAX_DEVICES             = 16
28
        DEBUG                   = 1
29
 
Line -... Line 30...
-
 
30
        __DEBUG__               = 1
-
 
31
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
-
 
32
 
29
        __DEBUG__               = 1
33
        NUM_TX_DESC             = 4
30
        __DEBUG_LEVEL__         = 2
34
        NUM_RX_DESC             = 4
31
 
-
 
32
        NUM_TX_DESC             = 4
-
 
33
        NUM_RX_DESC             = 4
35
 
34
 
36
section '.flat' readable writable executable
35
include '../struct.inc'
-
 
36
include '../macros.inc'
-
 
37
include '../proc32.inc'
-
 
38
include '../imports.inc'
-
 
39
include '../fdo.inc'
-
 
Line 40... Line 37...
40
include '../netdrv.inc'
37
 
41
 
38
include '../proc32.inc'
42
public START
39
include '../struct.inc'
43
public service_proc
40
include '../macros.inc'
Line 226... Line 223...
226
 
223
 
227
        PCFG_METHOD_1           = 0x01          ; PHY Reg 0x03 bit0-3 == 0x0000
224
        PCFG_METHOD_1           = 0x01          ; PHY Reg 0x03 bit0-3 == 0x0000
228
        PCFG_METHOD_2           = 0x02          ; PHY Reg 0x03 bit0-3 == 0x0001
225
        PCFG_METHOD_2           = 0x02          ; PHY Reg 0x03 bit0-3 == 0x0001
Line 229... Line -...
229
        PCFG_METHOD_3           = 0x03          ; PHY Reg 0x03 bit0-3 == 0x0002
-
 
230
 
226
        PCFG_METHOD_3           = 0x03          ; PHY Reg 0x03 bit0-3 == 0x0002
231
virtual at 0
227
 
232
  tx_desc:
228
struct  tx_desc
233
  .status    dd ?
229
        status    dd ?
234
  .vlan_tag  dd ?
230
        vlan_tag  dd ?
235
  .buf_addr  dq ?
231
        buf_addr  dq ?
236
  .size = $
-
 
237
  rb    (NUM_TX_DESC-1)*tx_desc.size
-
 
238
  .buf_soft_addr        dd ?
232
ends
239
end virtual
-
 
240
 
233
        tx_desc.buf_soft_addr = NUM_TX_DESC*sizeof.tx_desc
241
virtual at 0
234
 
242
  rx_desc:
235
struct  rx_desc
243
  .status    dd ?
236
        status    dd ?
244
  .vlan_tag  dd ?
237
        vlan_tag  dd ?
245
  .buf_addr  dq ?
238
        buf_addr  dq ?
246
  .size = $
-
 
247
  rb    (NUM_RX_DESC-1)*rx_desc.size
-
 
248
  .buf_soft_addr        dd ?
-
 
249
end virtual
-
 
250
 
-
 
251
virtual at ebx
-
 
252
 
239
ends
253
        device:
240
        rx_desc.buf_soft_addr = NUM_RX_DESC*sizeof.rx_desc
254
 
241
 
255
        ETH_DEVICE
242
struct  device          ETH_DEVICE
256
 
243
 
257
        .io_addr        dd ?
244
        io_addr         dd ?
258
        .pci_bus        dd ?
245
        pci_bus         dd ?
259
        .pci_dev        dd ?
-
 
260
        .irq_line       db ?
-
 
261
 
-
 
262
        rb 256-(($ - device) and 255)              ;        align 256
-
 
263
        .tx_ring rb NUM_TX_DESC * tx_desc.size * 2
246
        pci_dev         dd ?
264
 
-
 
265
        rb 256-(($ - device) and 255)              ;        align 256
-
 
266
        .rx_ring rb NUM_RX_DESC * rx_desc.size * 2
-
 
267
 
247
        irq_line        db ?
268
        tpc:
248
                        rb 3 ; align 4
269
        .mmio_addr      dd ? ; memory map physical address
249
        mmio_addr       dd ? ; memory map physical address
270
        .chipset        dd ?
250
        chipset         dd ?
271
        .pcfg           dd ?
251
        pcfg            dd ?
272
        .mcfg           dd ?
252
        mcfg            dd ?
273
        .cur_rx         dd ? ; Index into the Rx descriptor buffer of next Rx pkt
253
        cur_rx          dd ? ; Index into the Rx descriptor buffer of next Rx pkt
274
        .cur_tx         dd ? ; Index into the Tx descriptor buffer of next Rx pkt
254
        cur_tx          dd ? ; Index into the Tx descriptor buffer of next Rx pkt
275
        .TxDescArrays   dd ? ; Index of Tx Descriptor buffer
255
        TxDescArrays    dd ? ; Index of Tx Descriptor buffer
276
        .RxDescArrays   dd ? ; Index of Rx Descriptor buffer
256
        RxDescArrays    dd ? ; Index of Rx Descriptor buffer
-
 
257
        TxDescArray     dd ? ; Index of 256-alignment Tx Descriptor buffer
-
 
258
        RxDescArray     dd ? ; Index of 256-alignment Rx Descriptor buffer
-
 
259
 
Line 277... Line 260...
277
        .TxDescArray    dd ? ; Index of 256-alignment Tx Descriptor buffer
260
        rb 0x100-($ and 0xff)   ; align 256
-
 
261
        tx_ring         rb NUM_TX_DESC * sizeof.tx_desc * 2
Line 278... Line 262...
278
        .RxDescArray    dd ? ; Index of 256-alignment Rx Descriptor buffer
262
 
Line 279... Line 263...
279
 
263
        rb 0x100-($ and 0xff)   ; align 256
280
        device_size = $ - device
264
        rx_ring         rb NUM_RX_DESC * sizeof.rx_desc * 2
Line 281... Line 265...
281
 
265
 
Line 282... Line 266...
282
end virtual
266
ends
283
 
267
 
284
        intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK
268
        intr_mask = ISB_LinkChg or ISB_RxOverflow or ISB_RxFIFOOver or ISB_TxErr or ISB_TxOK or ISB_RxErr or ISB_RxOK
285
        rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E
269
        rx_config = (RX_FIFO_THRESH shl RXC_FIFOShift) or (RX_DMA_BURST shl RXC_DMAShift) or 0x0000000E
Line 286... Line 270...
286
 
270
 
Line 287... Line 271...
287
 
271
 
Line 288... Line 272...
288
macro   udelay msec {
272
macro   udelay msec {
289
 
273
 
290
        push    esi ecx
274
        push    esi ecx
291
        mov     esi, msec
275
        mov     esi, msec
292
        call    Sleep
276
        invoke  Sleep
293
        pop     ecx esi
277
        pop     ecx esi
Line 310... Line 294...
310
 
294
 
Line 311... Line 295...
311
macro   READ_GMII_REG  RegAddr {
295
macro   READ_GMII_REG  RegAddr {
Line 312... Line 296...
312
 
296
 
313
local   .error, .done
297
local   .error, .done
314
 
298
 
Line 315... Line 299...
315
        set_io  REG_PHYAR
299
        set_io  [ebx + device.io_addr], REG_PHYAR
316
        mov     eax, RegAddr shl 16
300
        mov     eax, RegAddr shl 16
Line 364... Line 348...
364
        pop     ecx
348
        pop     ecx
365
        ret
349
        ret
Line 366... Line -...
366
 
-
 
367
 
-
 
368
 
350
 
369
section '.flat' code readable align 16
351
 
370
 
352
 
371
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
353
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
372
;;                        ;;
354
;;                        ;;
373
;; proc START             ;;
355
;; proc START             ;;
Line 374... Line -...
374
;;                        ;;
-
 
375
;; (standard driver proc) ;;
356
;;                        ;;
376
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
377
 
-
 
378
align 4
-
 
Line -... Line 357...
-
 
357
;; (standard driver proc) ;;
379
proc START stdcall, state:dword
358
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 380... Line 359...
380
 
359
 
381
        cmp [state], 1
360
proc START c, reason:dword, cmdline:dword
382
        jne .exit
361
 
Line 383... Line 362...
383
 
362
        cmp     [reason], DRV_ENTRY
384
  .entry:
-
 
385
 
363
        jne     .fail
386
        DEBUGF  2,"Loading %s driver\n", my_service
364
 
Line 387... Line 365...
387
        stdcall RegService, my_service, service_proc
365
        DEBUGF  2,"Loading driver\n"
Line 400... Line 378...
400
;; proc SERVICE_PROC      ;;
378
;; proc SERVICE_PROC      ;;
401
;;                        ;;
379
;;                        ;;
402
;; (standard driver proc) ;;
380
;; (standard driver proc) ;;
403
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
381
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 404... Line -...
404
 
-
 
405
align 4
382
 
Line 406... Line 383...
406
proc service_proc stdcall, ioctl:dword
383
proc service_proc stdcall, ioctl:dword
407
 
384
 
Line 442... Line 419...
442
 
419
 
443
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
420
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
444
        mov     ax, [eax+1]                             ;
421
        mov     ax, [eax+1]                             ;
445
  .nextdevice:
422
  .nextdevice:
446
        mov     ebx, [esi]
423
        mov     ebx, [esi]
447
        cmp     al, byte[device.pci_bus]
424
        cmp     al, byte[ebx + device.pci_bus]
448
        jne     @f
425
        jne     @f
449
        cmp     ah, byte[device.pci_dev]
426
        cmp     ah, byte[ebx + device.pci_dev]
450
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
427
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
451
       @@:
428
       @@:
452
        add     esi, 4
429
        add     esi, 4
Line 456... Line 433...
456
; This device doesnt have its own eth_device structure yet, lets create one
433
; This device doesnt have its own eth_device structure yet, lets create one
457
  .firstdevice:
434
  .firstdevice:
458
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
435
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
459
        jae     .fail
436
        jae     .fail
Line 460... Line 437...
460
 
437
 
Line 461... Line 438...
461
        allocate_and_clear ebx, device_size, .fail      ; Allocate memory to put the device structure in
438
        allocate_and_clear ebx, sizeof.device, .fail    ; Allocate memory to put the device structure in
Line 462... Line 439...
462
 
439
 
463
; Fill in the direct call addresses into the struct
440
; Fill in the direct call addresses into the struct
464
 
441
 
465
        mov     [device.reset], reset
442
        mov     [ebx + device.reset], reset
Line 466... Line 443...
466
        mov     [device.transmit], transmit
443
        mov     [ebx + device.transmit], transmit
Line 467... Line 444...
467
        mov     [device.unload], unload
444
        mov     [ebx + device.unload], unload
468
        mov     [device.name], my_service
445
        mov     [ebx + device.name], my_service
469
 
446
 
470
; save the pci bus and device numbers
447
; save the pci bus and device numbers
471
 
448
 
Line 472... Line 449...
472
        mov     eax, [edx + IOCTL.input]
449
        mov     eax, [edx + IOCTL.input]
Line 473... Line 450...
473
        movzx   ecx, byte[eax+1]
450
        movzx   ecx, byte[eax+1]
474
        mov     [device.pci_bus], ecx
451
        mov     [ebx + device.pci_bus], ecx
Line 475... Line 452...
475
        movzx   ecx, byte[eax+2]
452
        movzx   ecx, byte[eax+2]
Line -... Line 453...
-
 
453
        mov     [ebx + device.pci_dev], ecx
476
        mov     [device.pci_dev], ecx
454
 
Line 477... Line 455...
477
 
455
; Now, it's time to find the base io addres of the PCI device
478
; Now, it's time to find the base io addres of the PCI device
456
 
Line 479... Line 457...
479
 
457
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
480
        PCI_find_io
458
        mov     [ebx + device.io_addr], eax
481
        mov     [tpc.mmio_addr], eax    ; CHECKME
459
 
482
 
460
; We've found the io address, find IRQ now
Line 495... Line 473...
495
 
473
 
496
        call    probe                                                   ; this function will output in eax
474
        call    probe                                                   ; this function will output in eax
497
        test    eax, eax
475
        test    eax, eax
Line 498... Line 476...
498
        jnz     .err2                                                   ; If an error occured, exit
476
        jnz     .err2                                                   ; If an error occured, exit
499
 
477
 
Line 500... Line 478...
500
        mov     [device.type], NET_TYPE_ETH
478
        mov     [ebx + device.type], NET_TYPE_ETH
501
        call    NetRegDev
479
        invoke  NetRegDev
Line 502... Line 480...
502
 
480
 
Line 503... Line 481...
503
        cmp     eax, -1
481
        cmp     eax, -1
Line 504... Line 482...
504
        je      .destroy
482
        je      .destroy
505
 
483
 
506
        ret
484
        ret
507
 
485
 
508
; If the device was already loaded, find the device number and return it in eax
486
; If the device was already loaded, find the device number and return it in eax
509
 
487
 
510
  .find_devicenum:
488
  .find_devicenum:
Line 522... Line 500...
522
 
500
 
523
  .err2:
501
  .err2:
524
        dec     [devices]
502
        dec     [devices]
525
  .err:
503
  .err:
526
        DEBUGF  2,"removing device structure\n"
504
        DEBUGF  2,"removing device structure\n"
527
        stdcall KernelFree, ebx
505
        invoke  KernelFree, ebx
528
  .fail:
506
  .fail:
529
        or      eax, -1
507
        or      eax, -1
Line 530... Line 508...
530
        ret
508
        ret
Line 542... Line 520...
542
align 4
520
align 4
543
init_board:
521
init_board:
Line 544... Line 522...
544
 
522
 
Line 545... Line 523...
545
        DEBUGF  1,"init_board\n"
523
        DEBUGF  1,"init_board\n"
-
 
524
 
-
 
525
; Make the device a bus master
-
 
526
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line 546... Line 527...
546
 
527
        or      al, PCI_CMD_MASTER
547
        PCI_make_bus_master
528
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
548
 
529
 
549
        ; Soft reset the chip
530
        ; Soft reset the chip
550
        set_io  0
531
        set_io  [ebx + device.io_addr], 0
Line 551... Line 532...
551
        set_io  REG_ChipCmd
532
        set_io  [ebx + device.io_addr], REG_ChipCmd
552
        mov     al, CMD_Reset
533
        mov     al, CMD_Reset
553
        out     dx, al
534
        out     dx, al
554
 
535
 
555
        ; Check that the chip has finished the reset
536
        ; Check that the chip has finished the reset
556
        mov     ecx, 1000
537
        mov     ecx, 1000
557
        set_io  REG_ChipCmd
538
        set_io  [ebx + device.io_addr], REG_ChipCmd
558
    @@: in      al, dx
539
    @@: in      al, dx
559
        test    al, CMD_Reset
540
        test    al, CMD_Reset
560
        jz      @f
541
        jz      @f
561
        udelay  10
542
        udelay  10
562
        loop    @b
543
        loop    @b
563
    @@:
544
    @@:
564
        ; identify config method
545
        ; identify config method
565
        set_io  REG_TxConfig
546
        set_io  [ebx + device.io_addr], REG_TxConfig
566
        in      eax, dx
547
        in      eax, dx
567
        and     eax, 0x7c800000
548
        and     eax, 0x7c800000
568
        DEBUGF  1,"init_board: TxConfig & 0x7c800000 = 0x%x\n", eax
549
        DEBUGF  1,"init_board: TxConfig & 0x7c800000 = 0x%x\n", eax
569
        mov     esi, mac_info-8
550
        mov     esi, mac_info-8
570
    @@: add     esi, 8
551
    @@: add     esi, 8
571
        mov     ecx, eax
552
        mov     ecx, eax
572
        and     ecx, [esi]
553
        and     ecx, [esi]
Line 573... Line 554...
573
        cmp     ecx, [esi]
554
        cmp     ecx, [esi]
574
        jne     @b
555
        jne     @b
575
        mov     eax, [esi+4]
556
        mov     eax, [esi+4]
576
        mov     [tpc.mcfg], eax
557
        mov     [ebx + device.mcfg], eax
577
 
558
 
578
        mov     [tpc.pcfg], PCFG_METHOD_3
559
        mov     [ebx + device.pcfg], PCFG_METHOD_3
579
        READ_GMII_REG 3
560
        READ_GMII_REG 3
580
        and     al, 0x0f
561
        and     al, 0x0f
581
        or      al, al
562
        or      al, al
582
        jnz     @f
563
        jnz     @f
583
        mov     [tpc.pcfg], PCFG_METHOD_1
564
        mov     [ebx + device.pcfg], PCFG_METHOD_1
Line 584... Line 565...
584
        jmp     .pconf
565
        jmp     .pconf
585
    @@: dec     al
566
    @@: dec     al
586
        jnz     .pconf
567
        jnz     .pconf
587
        mov     [tpc.pcfg], PCFG_METHOD_2
568
        mov     [ebx + device.pcfg], PCFG_METHOD_2
588
  .pconf:
569
  .pconf:
589
 
570
 
590
        ; identify chip attached to board
571
        ; identify chip attached to board
591
        mov     ecx, 10
572
        mov     ecx, 10
592
        mov     eax, [tpc.mcfg]
573
        mov     eax, [ebx + device.mcfg]
593
    @@: dec     ecx
574
    @@: dec     ecx
594
        js      @f
575
        js      @f
595
        cmp     eax, [rtl_chip_info + ecx*8]
576
        cmp     eax, [rtl_chip_info + ecx*8]
596
        jne     @b
577
        jne     @b
597
        mov     [tpc.chipset], ecx
578
        mov     [ebx + device.chipset], ecx
598
        jmp     .match
579
        jmp     .match
Line 599... Line 580...
599
    @@:
580
    @@:
Line 600... Line 581...
600
        ; if unknown chip, assume array element #0, original RTL-8169 in this case
581
        ; if unknown chip, assume array element #0, original RTL-8169 in this case
601
        DEBUGF  1,"init_board: PCI device: unknown chip version, assuming RTL-8169\n"
582
        DEBUGF  1,"init_board: PCI device: unknown chip version, assuming RTL-8169\n"
602
        set_io  REG_TxConfig
583
        set_io  [ebx + device.io_addr], REG_TxConfig
Line 634... Line 615...
634
        call    init_board
615
        call    init_board
635
        call    read_mac
616
        call    read_mac
636
        call    PHY_config
617
        call    PHY_config
Line 637... Line 618...
637
 
618
 
638
        DEBUGF  1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
619
        DEBUGF  1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
639
        set_io  0
620
        set_io  [ebx + device.io_addr], 0
640
        set_io  0x82
621
        set_io  [ebx + device.io_addr], 0x82
641
        mov     al, 0x01
622
        mov     al, 0x01
642
        out     dx, al
623
        out     dx, al
643
        cmp     [tpc.mcfg], MCFG_METHOD_03
624
        cmp     [ebx + device.mcfg], MCFG_METHOD_03
644
        jae     @f
625
        jae     @f
-
 
626
        DEBUGF  1,"Set PCI Latency=0x40\n"
-
 
627
; Adjust PCI latency to be at least 64
-
 
628
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency
-
 
629
        cmp     al, 64
645
        DEBUGF  1,"Set PCI Latency=0x40\n"
630
        jae     @f
-
 
631
        mov     al, 64
646
        PCI_adjust_latency 0x40
632
        invoke  PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax
647
   @@:
633
  @@:
648
        cmp     [tpc.mcfg], MCFG_METHOD_02
634
        cmp     [ebx + device.mcfg], MCFG_METHOD_02
649
        jne     @f
635
        jne     @f
650
        DEBUGF  1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
636
        DEBUGF  1,"Set MAC Reg C+CR Offset 0x82h = 0x01h\n"
651
        set_io  0
637
        set_io  [ebx + device.io_addr], 0
652
        set_io  0x82
638
        set_io  [ebx + device.io_addr], 0x82
653
        mov     al, 0x01
639
        mov     al, 0x01
654
        out     dx, al
640
        out     dx, al
655
        DEBUGF  1,"Set PHY Reg 0x0bh = 0x00h\n"
641
        DEBUGF  1,"Set PHY Reg 0x0bh = 0x00h\n"
656
        WRITE_GMII_REG 0x0b, 0x0000      ; w 0x0b 15 0 0
642
        WRITE_GMII_REG 0x0b, 0x0000      ; w 0x0b 15 0 0
657
    @@:
643
    @@:
658
        ; if TBI is not enabled
644
        ; if TBI is not enabled
659
        set_io  0
645
        set_io  [ebx + device.io_addr], 0
660
        set_io  REG_PHYstatus
646
        set_io  [ebx + device.io_addr], REG_PHYstatus
661
        in      al, dx
647
        in      al, dx
662
        test    al, PHYS_TBI_Enable
648
        test    al, PHYS_TBI_Enable
663
        jz      .tbi_dis
649
        jz      .tbi_dis
Line 678... Line 664...
678
        mov     ecx, 200                ; 10000
664
        mov     ecx, 200                ; 10000
679
        DEBUGF  1, "Waiting for auto-negotiation to complete\n"
665
        DEBUGF  1, "Waiting for auto-negotiation to complete\n"
680
        ; wait for auto-negotiation process
666
        ; wait for auto-negotiation process
681
    @@: dec     ecx
667
    @@: dec     ecx
682
        jz      @f
668
        jz      @f
683
        set_io  0
669
        set_io  [ebx + device.io_addr], 0
684
        READ_GMII_REG PHY_STAT_REG
670
        READ_GMII_REG PHY_STAT_REG
685
        udelay  1                       ; 100
671
        udelay  1                       ; 100
686
        test    eax, PHY_Auto_Neco_Comp
672
        test    eax, PHY_Auto_Neco_Comp
687
        jz      @b
673
        jz      @b
688
        set_io  REG_PHYstatus
674
        set_io  [ebx + device.io_addr], REG_PHYstatus
689
        in      al, dx
675
        in      al, dx
690
        jmp     @f
676
        jmp     @f
691
  .tbi_dis:
677
  .tbi_dis:
692
        udelay  1                       ; 100
678
        udelay  1                       ; 100
693
    @@:
679
    @@:
Line 705... Line 691...
705
align 4
691
align 4
706
reset:
692
reset:
Line 707... Line 693...
707
 
693
 
Line 708... Line 694...
708
        DEBUGF  1,"resetting\n"
694
        DEBUGF  1,"resetting\n"
709
 
695
 
710
        lea     eax, [device.tx_ring]
696
        lea     eax, [ebx + device.tx_ring]
711
        mov     [tpc.TxDescArrays], eax
697
        mov     [ebx + device.TxDescArrays], eax
712
        mov     [tpc.TxDescArray], eax
698
        mov     [ebx + device.TxDescArray], eax
713
 
699
 
714
        lea     eax, [device.rx_ring]
700
        lea     eax, [ebx + device.rx_ring]
Line 715... Line 701...
715
        mov     [tpc.RxDescArrays], eax
701
        mov     [ebx + device.RxDescArrays], eax
716
        mov     [tpc.RxDescArray], eax
702
        mov     [ebx + device.RxDescArray], eax
Line 717... Line 703...
717
 
703
 
Line 718... Line 704...
718
        call    init_ring
704
        call    init_ring
719
        call    hw_start
705
        call    hw_start
720
 
706
 
721
; clear packet/byte counters
707
; clear packet/byte counters
Line 722... Line 708...
722
 
708
 
Line 723... Line 709...
723
        xor     eax, eax
709
        xor     eax, eax
724
        lea     edi, [device.bytes_tx]
710
        lea     edi, [ebx + device.bytes_tx]
Line 725... Line 711...
725
        mov     ecx, 6
711
        mov     ecx, 6
726
        rep     stosd
712
        rep     stosd
727
 
713
 
Line 739... Line 725...
739
 
725
 
740
 
726
 
Line 741... Line 727...
741
align 4
727
align 4
Line 742... Line 728...
742
PHY_config:
728
PHY_config:
743
 
729
 
744
        DEBUGF  1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n", [tpc.mcfg], [tpc.pcfg]
730
        DEBUGF  1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n", [ebx + device.mcfg], [ebx + device.pcfg]
745
 
731
 
746
        cmp     [tpc.mcfg], MCFG_METHOD_04
732
        cmp     [ebx + device.mcfg], MCFG_METHOD_04
747
        jne     .not_4
733
        jne     .not_4
748
        set_io  0
734
        set_io  [ebx + device.io_addr], 0
749
;       WRITE_GMII_REG 0x1F, 0x0001
735
;       WRITE_GMII_REG 0x1F, 0x0001
750
;       WRITE_GMII_REG 0x1b, 0x841e
736
;       WRITE_GMII_REG 0x1b, 0x841e
751
;       WRITE_GMII_REG 0x0e, 0x7bfb
737
;       WRITE_GMII_REG 0x0e, 0x7bfb
752
;       WRITE_GMII_REG 0x09, 0x273a
738
;       WRITE_GMII_REG 0x09, 0x273a
753
        WRITE_GMII_REG 0x1F, 0x0002
739
        WRITE_GMII_REG 0x1F, 0x0002
754
        WRITE_GMII_REG 0x01, 0x90D0
740
        WRITE_GMII_REG 0x01, 0x90D0
755
        WRITE_GMII_REG 0x1F, 0x0000
741
        WRITE_GMII_REG 0x1F, 0x0000
756
        jmp     .exit
742
        jmp     .exit
757
  .not_4:
743
  .not_4:
758
        cmp     [tpc.mcfg], MCFG_METHOD_02
744
        cmp     [ebx + device.mcfg], MCFG_METHOD_02
759
        je      @f
745
        je      @f
760
        cmp     [tpc.mcfg], MCFG_METHOD_03
746
        cmp     [ebx + device.mcfg], MCFG_METHOD_03
761
        jne     .not_2_or_3
747
        jne     .not_2_or_3
762
    @@:
748
    @@:
763
        set_io  0
749
        set_io  [ebx + device.io_addr], 0
764
        WRITE_GMII_REG 0x1F, 0x0001
750
        WRITE_GMII_REG 0x1F, 0x0001
Line 802... Line 788...
802
        WRITE_GMII_REG 0x04, 0x0000
788
        WRITE_GMII_REG 0x04, 0x0000
803
        WRITE_GMII_REG 0x1F, 0x0000
789
        WRITE_GMII_REG 0x1F, 0x0000
804
        WRITE_GMII_REG 0x0B, 0x0000
790
        WRITE_GMII_REG 0x0B, 0x0000
805
        jmp     .exit
791
        jmp     .exit
806
  .not_2_or_3:
792
  .not_2_or_3:
807
        DEBUGF  1,"tpc.mcfg=%d, discard hw PHY config\n", [tpc.mcfg]
793
        DEBUGF  1,"mcfg=%d, discard hw PHY config\n", [ebx + device.mcfg]
808
  .exit:
794
  .exit:
809
        ret
795
        ret
Line 815... Line 801...
815
 
801
 
Line 816... Line 802...
816
        DEBUGF  1,"set_rx_mode\n"
802
        DEBUGF  1,"set_rx_mode\n"
817
 
803
 
818
        ; IFF_ALLMULTI
804
        ; IFF_ALLMULTI
819
        ; Too many to filter perfectly -- accept all multicasts
805
        ; Too many to filter perfectly -- accept all multicasts
820
        set_io  0
806
        set_io  [ebx + device.io_addr], 0
821
        set_io  REG_RxConfig
807
        set_io  [ebx + device.io_addr], REG_RxConfig
822
        in      eax, dx
808
        in      eax, dx
823
        mov     ecx, [tpc.chipset]
809
        mov     ecx, [ebx + device.chipset]
824
        and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
810
        and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
Line 825... Line 811...
825
        or      eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys)
811
        or      eax, rx_config or (RXM_AcceptBroadcast or RXM_AcceptMulticast or RXM_AcceptMyPhys)
826
        out     dx, eax
812
        out     dx, eax
827
 
813
 
828
        ; Multicast hash filter
814
        ; Multicast hash filter
829
        set_io  REG_MAR0 + 0
815
        set_io  [ebx + device.io_addr], REG_MAR0 + 0
830
        or      eax, -1
816
        or      eax, -1
Line 831... Line 817...
831
        out     dx, eax
817
        out     dx, eax
Line 839... Line 825...
839
init_ring:
825
init_ring:
Line 840... Line 826...
840
 
826
 
Line 841... Line 827...
841
        DEBUGF  1,"init_ring\n"
827
        DEBUGF  1,"init_ring\n"
842
 
828
 
843
        xor     eax, eax
829
        xor     eax, eax
Line 844... Line 830...
844
        mov     [tpc.cur_rx], eax
830
        mov     [ebx + device.cur_rx], eax
845
        mov     [tpc.cur_tx], eax
831
        mov     [ebx + device.cur_tx], eax
846
 
832
 
Line 847... Line 833...
847
        lea     edi, [device.tx_ring]
833
        lea     edi, [ebx + device.tx_ring]
848
        mov     ecx, (NUM_TX_DESC * tx_desc.size) / 4
834
        mov     ecx, (NUM_TX_DESC * sizeof.tx_desc) / 4
849
        rep     stosd
835
        rep     stosd
Line 850... Line 836...
850
 
836
 
851
        lea     edi, [device.rx_ring]
837
        lea     edi, [ebx + device.rx_ring]
852
        mov     ecx, (NUM_RX_DESC * rx_desc.size) / 4
838
        mov     ecx, (NUM_RX_DESC * sizeof.rx_desc) / 4
853
        rep     stosd
839
        rep     stosd
854
 
840
 
855
        mov     edi, [tpc.RxDescArray]
841
        mov     edi, [ebx + device.RxDescArray]
856
        mov     ecx, NUM_RX_DESC
842
        mov     ecx, NUM_RX_DESC
857
  .loop:
843
  .loop:
858
        push    ecx
844
        push    ecx
859
        stdcall KernelAlloc, RX_BUF_SIZE
845
        invoke  KernelAlloc, RX_BUF_SIZE
860
        mov     [edi + rx_desc.buf_soft_addr], eax
846
        mov     dword [edi + rx_desc.buf_soft_addr], eax
-
 
847
        invoke  GetPgAddr
861
        call    GetPgAddr
848
        mov     dword [edi + rx_desc.buf_addr], eax
862
        mov     dword [edi + rx_desc.buf_addr], eax
849
        mov     [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
Line 863... Line 850...
863
        mov     [edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
850
        add     edi, sizeof.rx_desc
Line 864... Line 851...
864
        add     edi, rx_desc.size
851
        pop     ecx
865
        pop     ecx
852
        dec     ecx
Line 866... Line 853...
866
        loop    .loop
853
        jnz     .loop
Line 867... Line 854...
867
        or      [edi - rx_desc.size + rx_desc.status], DSB_EORbit
854
        or      [edi - sizeof.rx_desc + rx_desc.status], DSB_EORbit
868
 
855
 
869
        ret
856
        ret
870
 
857
 
-
 
858
 
-
 
859
align 4
-
 
860
hw_start:
-
 
861
 
-
 
862
        DEBUGF  1,"hw_start\n"
-
 
863
 
Line 871... Line 864...
871
 
864
; attach int handler
872
align 4
865
        movzx   eax, [ebx + device.irq_line]
873
hw_start:
866
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
874
 
867
        invoke  AttachIntHandler, eax, int_handler, ebx
875
        DEBUGF  1,"hw_start\n"
868
        test    eax, eax
Line 876... Line 869...
876
 
869
        jnz     @f
877
; attach int handler
870
        DEBUGF  2,"Could not attach int handler!\n"
878
        movzx   eax, [device.irq_line]
871
        or      eax, -1
879
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
872
        ret
880
        stdcall AttachIntHandler, eax, int_handler, dword 0
873
       @@:
881
 
874
 
882
        ; Soft reset the chip
875
        ; Soft reset the chip
883
        set_io  0
876
        set_io  [ebx + device.io_addr], 0
884
        set_io  REG_ChipCmd
877
        set_io  [ebx + device.io_addr], REG_ChipCmd
885
        mov     al, CMD_Reset
878
        mov     al, CMD_Reset
886
        out     dx, al
879
        out     dx, al
Line 887... Line 880...
887
 
880
 
888
        DEBUGF  1,"Waiting for chip to reset... "
881
        DEBUGF  1,"Waiting for chip to reset... "
889
        ; Check that the chip has finished the reset
882
        ; Check that the chip has finished the reset
Line 890... Line 883...
890
        mov     ecx, 1000
883
        mov     ecx, 1000
891
        set_io  REG_ChipCmd
884
        set_io  [ebx + device.io_addr], REG_ChipCmd
892
    @@: in      al, dx
885
    @@: in      al, dx
Line 893... Line 886...
893
        test    al, CMD_Reset
886
        test    al, CMD_Reset
894
        jz      @f
887
        jz      @f
895
        udelay  10
888
        udelay  10
Line 896... Line 889...
896
        loop    @b
889
        loop    @b
897
    @@:
890
    @@:
898
        DEBUGF  1,"done!\n"
891
        DEBUGF  1,"done!\n"
899
 
892
 
Line 900... Line 893...
900
        set_io  REG_Cfg9346
893
        set_io  [ebx + device.io_addr], REG_Cfg9346
901
        mov     al, CFG_9346_Unlock
894
        mov     al, CFG_9346_Unlock
902
        out     dx, al
895
        out     dx, al
903
 
896
 
904
        set_io  REG_ChipCmd
897
        set_io  [ebx + device.io_addr], REG_ChipCmd
905
        mov     al, CMD_TxEnb or CMD_RxEnb
898
        mov     al, CMD_TxEnb or CMD_RxEnb
906
        out     dx, al
899
        out     dx, al
Line 907... Line 900...
907
 
900
 
908
        set_io  REG_ETThReg
901
        set_io  [ebx + device.io_addr], REG_ETThReg
909
        mov     al, ETTh
902
        mov     al, ETTh
910
        out     dx, al
903
        out     dx, al
Line 911... Line 904...
911
 
904
 
912
        ; For gigabit rtl8169
905
        ; For gigabit rtl8169
913
        set_io  REG_RxMaxSize
906
        set_io  [ebx + device.io_addr], REG_RxMaxSize
Line 914... Line 907...
914
        mov     ax, RxPacketMaxSize
907
        mov     ax, RxPacketMaxSize
915
        out     dx, ax
908
        out     dx, ax
916
 
909
 
917
        ; Set Rx Config register
910
        ; Set Rx Config register
918
        set_io  REG_RxConfig
911
        set_io  [ebx + device.io_addr], REG_RxConfig
919
        in      ax, dx
912
        in      ax, dx
920
        mov     ecx, [tpc.chipset]
913
        mov     ecx, [ebx + device.chipset]
921
        and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
914
        and     eax, [rtl_chip_info + ecx * 8 + 4] ; RxConfigMask
922
        or      eax, rx_config
915
        or      eax, rx_config
923
        out     dx, eax
916
        out     dx, eax
924
 
917
 
925
        ; Set DMA burst size and Interframe Gap Time
918
        ; Set DMA burst size and Interframe Gap Time
926
        set_io  REG_TxConfig
919
        set_io  [ebx + device.io_addr], REG_TxConfig
927
        mov     eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift)
920
        mov     eax, (TX_DMA_BURST shl TXC_DMAShift) or (InterFrameGap shl TXC_InterFrameGapShift)
Line 928... Line 921...
928
        out     dx, eax
921
        out     dx, eax
929
 
922
 
930
        set_io  REG_CPlusCmd
923
        set_io  [ebx + device.io_addr], REG_CPlusCmd
931
        in      ax, dx
924
        in      ax, dx
932
        out     dx, ax
925
        out     dx, ax
933
 
926
 
934
        in      ax, dx
927
        in      ax, dx
935
        or      ax, 1 shl 3
928
        or      ax, 1 shl 3
936
        cmp     [tpc.mcfg], MCFG_METHOD_02
929
        cmp     [ebx + device.mcfg], MCFG_METHOD_02
Line 937... Line 930...
937
        jne     @f
930
        jne     @f
938
        cmp     [tpc.mcfg], MCFG_METHOD_03
931
        cmp     [ebx + device.mcfg], MCFG_METHOD_03
939
        jne     @f
932
        jne     @f
940
        or      ax,1 shl 14
933
        or      ax,1 shl 14
941
        DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
934
        DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3 and bit-14\n"
942
        jmp     .set
935
        jmp     .set
943
    @@:
936
    @@:
944
        DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n"
937
        DEBUGF  1,"Set MAC Reg C+CR Offset 0xE0: bit-3\n"
945
  .set:
938
  .set:
Line 946... Line 939...
946
        set_io  REG_CPlusCmd
939
        set_io  [ebx + device.io_addr], REG_CPlusCmd
947
        out     dx, ax
940
        out     dx, ax
948
 
941
 
949
        set_io  0xE2
942
        set_io  [ebx + device.io_addr], 0xE2
950
;        mov     ax, 0x1517
943
;        mov     ax, 0x1517
951
;        out     dx, ax
944
;        out     dx, ax
952
;        mov     ax, 0x152a
945
;        mov     ax, 0x152a
Line 953... Line 946...
953
;        out     dx, ax
946
;        out     dx, ax
954
;        mov     ax, 0x282a
947
;        mov     ax, 0x282a
955
;        out     dx, ax
948
;        out     dx, ax
Line 956... Line 949...
956
        xor     ax, ax
949
        xor     ax, ax
Line 957... Line 950...
957
        out     dx, ax
950
        out     dx, ax
958
 
951
 
959
        xor     eax, eax
952
        xor     eax, eax
Line 960... Line 953...
960
        mov     [tpc.cur_rx], eax
953
        mov     [ebx + device.cur_rx], eax
Line 961... Line 954...
961
        lea     eax, [device.tx_ring]
954
        lea     eax, [ebx + device.tx_ring]
962
        GetRealAddr
955
        invoke  GetPhysAddr
963
        set_io  REG_TxDescStartAddr
956
        set_io  [ebx + device.io_addr], REG_TxDescStartAddr
964
        out     dx, eax
957
        out     dx, eax
965
        set_io  REG_TxDescStartAddr + 4
958
        set_io  [ebx + device.io_addr], REG_TxDescStartAddr + 4
966
        xor     eax, eax
959
        xor     eax, eax
Line 967... Line 960...
967
        out     dx, eax
960
        out     dx, eax
968
 
961
 
969
        lea     eax, [device.rx_ring]
962
        lea     eax, [ebx + device.rx_ring]
970
        GetRealAddr
963
        invoke  GetPhysAddr
Line 971... Line 964...
971
        set_io  REG_RxDescStartAddr
964
        set_io  [ebx + device.io_addr], REG_RxDescStartAddr
972
        out     dx, eax
965
        out     dx, eax
Line 973... Line 966...
973
        xor     eax, eax
966
        xor     eax, eax
974
        set_io  REG_RxDescStartAddr + 4
967
        set_io  [ebx + device.io_addr], REG_RxDescStartAddr + 4
Line 975... Line 968...
975
        out     dx, eax
968
        out     dx, eax
976
 
969
 
977
        set_io  REG_Cfg9346
970
        set_io  [ebx + device.io_addr], REG_Cfg9346
978
        mov     al, CFG_9346_Lock
971
        mov     al, CFG_9346_Lock
979
        out     dx, al
972
        out     dx, al
Line 980... Line 973...
980
 
973
 
981
        udelay  10
974
        udelay  10
982
 
975
 
983
        xor     eax, eax
976
        xor     eax, eax
984
        set_io  REG_RxMissed
977
        set_io  [ebx + device.io_addr], REG_RxMissed
Line 985... Line 978...
985
        out     dx, eax
978
        out     dx, eax
986
 
979
 
Line 987... Line 980...
987
        call    set_rx_mode
980
        call    set_rx_mode
Line 988... Line 981...
988
 
981
 
989
        set_io  0
982
        set_io  [ebx + device.io_addr], 0
Line 990... Line 983...
990
        ; no early-rx interrupts
983
        ; no early-rx interrupts
Line 991... Line -...
991
        set_io  REG_MultiIntr
-
 
992
        in      ax, dx
-
 
993
        and     ax, 0xF000
-
 
994
        out     dx, ax
984
        set_io  [ebx + device.io_addr], REG_MultiIntr
995
 
985
        in      ax, dx
996
        ; set interrupt mask
986
        and     ax, 0xF000
997
        set_io  REG_IntrMask
987
        out     dx, ax
998
        mov     ax, intr_mask
988
 
999
        out     dx, ax
989
        ; set interrupt mask
1000
 
990
        set_io  [ebx + device.io_addr], REG_IntrMask
1001
        xor     eax, eax
991
        mov     ax, intr_mask
1002
        ret
992
        out     dx, ax
1003
 
993
 
1004
 
-
 
1005
align 4
-
 
Line -... Line 994...
-
 
994
        xor     eax, eax
-
 
995
        ret
-
 
996
 
-
 
997
 
-
 
998
align 4
1006
read_mac:
999
read_mac:
1007
 
1000
 
1008
        set_io  0
1001
        set_io  [ebx + device.io_addr], 0
1009
        set_io  REG_MAC0
1002
        set_io  [ebx + device.io_addr], REG_MAC0
1010
        xor     ecx, ecx
1003
        xor     ecx, ecx
1011
        lea     edi, [device.mac]
1004
        lea     edi, [ebx + device.mac]
Line 1012... Line 1005...
1012
        mov     ecx, 6
1005
        mov     ecx, 6
1013
 
1006
 
-
 
1007
        ; Get MAC address. FIXME: read EEPROM
-
 
1008
    @@: in      al, dx
Line 1014... Line 1009...
1014
        ; Get MAC address. FIXME: read EEPROM
1009
        stosb
1015
    @@: in      al, dx
1010
        inc     edx
Line 1016... Line 1011...
1016
        stosb
1011
        loop    @r
1017
        inc     edx
1012
 
1018
        loop    @r
1013
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n",\
Line 1019... Line 1014...
1019
 
1014
        [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
Line 1020... Line 1015...
1020
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n",\
1015
 
1021
        [device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
1016
        ret
Line 1022... Line 1017...
1022
 
1017
 
1023
        ret
1018
align 4
1024
 
1019
write_mac:
1025
align 4
1020
 
Line 1026... Line 1021...
1026
write_mac:
1021
        ret     6
1027
 
1022
 
Line 1028... Line 1023...
1028
        ret     6
1023
 
1029
 
1024
;***************************************************************************
1030
 
1025
;   Function
1031
 
1026
;      transmit
1032
 
1027
;   Description
1033
 
1028
;      Transmits a packet of data via the ethernet card
Line 1034... Line 1029...
1034
;***************************************************************************
1029
;
1035
;   Function
1030
;   Destroyed registers
Line 1036... Line 1031...
1036
;      transmit
1031
;      eax, edx, esi, edi
1037
;   Description
1032
;
1038
;      Transmits a packet of data via the ethernet card
1033
;***************************************************************************
1039
;
1034
 
Line 1040... Line 1035...
1040
;   Destroyed registers
1035
proc transmit stdcall bufferptr, buffersize
1041
;      eax, edx, esi, edi
1036
 
Line 1042... Line 1037...
1042
;
1037
        pushf
1043
;***************************************************************************
1038
        cli
Line 1044... Line 1039...
1044
align 4
1039
 
1045
transmit:
1040
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
Line 1046... Line 1041...
1046
 
1041
        mov     eax, [bufferptr]
1047
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
1042
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1048
        mov     eax, [esp+4]
1043
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1049
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1044
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
Line 1050... Line 1045...
1050
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
1045
        [eax+13]:2,[eax+12]:2
-
 
1046
 
1051
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1047
        cmp     [buffersize], 1514
Line 1052... Line 1048...
1052
        [eax+13]:2,[eax+12]:2
1048
        ja      .fail
1053
 
1049
        cmp     [buffersize], 60
1054
        cmp     dword [esp+8], MAX_ETH_FRAME_SIZE
1050
        jb      .fail
-
 
1051
 
1055
        ja      .fail
1052
;----------------------------------
1056
 
1053
; Find currentTX descriptor address
-
 
1054
 
-
 
1055
        mov     eax, sizeof.tx_desc
Line 1057... Line 1056...
1057
;----------------------------------
1056
        mul     [ebx + device.cur_tx]
Line 1136... Line 1135...
1136
        jz      .nothing
1135
        jz      .nothing
1137
        mov     esi, device_list
1136
        mov     esi, device_list
1138
  .nextdevice:
1137
  .nextdevice:
1139
        mov     ebx, [esi]
1138
        mov     ebx, [esi]
Line 1140... Line 1139...
1140
 
1139
 
1141
        set_io  0
1140
        set_io  [ebx + device.io_addr], 0
1142
        set_io  REG_IntrStatus
1141
        set_io  [ebx + device.io_addr], REG_IntrStatus
1143
        in      ax, dx
1142
        in      ax, dx
1144
        test    ax, ax
1143
        test    ax, ax
1145
        jnz     .got_it
1144
        jnz     .got_it
1146
  .continue:
1145
  .continue:
Line 1153... Line 1152...
1153
 
1152
 
Line 1154... Line 1153...
1154
        ret                                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
1153
        ret                                             ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
Line 1155... Line 1154...
1155
 
1154
 
Line 1156... Line 1155...
1156
  .got_it:
1155
  .got_it:
1157
 
1156
 
Line 1158... Line 1157...
1158
        DEBUGF  1,"Device: %x Status: %x ", ebx, ax
1157
        DEBUGF  1,"Device: %x Status: %x\n", ebx, ax
Line 1169... Line 1168...
1169
        push    ax
1168
        push    ax
1170
        push    ebx
1169
        push    ebx
Line 1171... Line 1170...
1171
 
1170
 
1172
  .check_more:
1171
  .check_more:
1173
        pop     ebx
-
 
1174
        DEBUGF  1,"ebx = 0x%x\n", ebx
1172
        pop     ebx
1175
        mov     eax, rx_desc.size
1173
        mov     eax, sizeof.rx_desc
1176
        mul     [tpc.cur_rx]
1174
        mul     [ebx + device.cur_rx]
Line 1177... Line 1175...
1177
        lea     esi, [eax + device.rx_ring]
1175
        lea     esi, [ebx + device.rx_ring + eax]
1178
 
-
 
1179
        DEBUGF  1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
1176
 
1180
 
1177
        DEBUGF  1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
1181
        mov     eax, [esi + rx_desc.status]
1178
        mov     eax, [esi + rx_desc.status]
Line 1182... Line 1179...
1182
        test    eax, DSB_OWNbit ;;;
1179
        test    eax, DSB_OWNbit ;;;
Line 1183... Line 1180...
1183
        jnz     .rx_return
1180
        jnz     .rx_return
1184
 
1181
 
Line 1185... Line 1182...
1185
        DEBUGF  1,"tpc.cur_rx = %u\n", [tpc.cur_rx]
1182
        DEBUGF  1,"cur_rx = %u\n", [ebx + device.cur_rx]
Line 1195... Line 1192...
1195
        DEBUGF  1,"data length = %u\n", ax
1192
        DEBUGF  1,"data length = %u\n", ax
Line 1196... Line 1193...
1196
 
1193
 
1197
;-------------
1194
;-------------
Line 1198... Line 1195...
1198
; Update stats
1195
; Update stats
1199
 
1196
 
1200
        add     dword [device.bytes_rx], eax
1197
        add     dword [ebx + device.bytes_rx], eax
Line 1201... Line 1198...
1201
        adc     dword [device.bytes_rx + 4], 0
1198
        adc     dword [ebx + device.bytes_rx + 4], 0
Line 1202... Line 1199...
1202
        inc     dword [device.packets_rx]
1199
        inc     [ebx + device.packets_rx]
1203
 
1200
 
Line 1204... Line 1201...
1204
        push    [esi + rx_desc.buf_soft_addr]
1201
        pushd   [esi + rx_desc.buf_soft_addr]
1205
 
1202
 
1206
;----------------------
1203
;----------------------
1207
; Allocate a new buffer
1204
; Allocate a new buffer
Line 1208... Line 1205...
1208
 
1205
 
1209
        stdcall KernelAlloc, RX_BUF_SIZE
1206
        invoke  KernelAlloc, RX_BUF_SIZE
Line 1210... Line 1207...
1210
        mov     [esi + rx_desc.buf_soft_addr], eax
1207
        mov     [esi + rx_desc.buf_soft_addr], eax
1211
        GetRealAddr
1208
        invoke  GetPhysAddr
1212
        mov     dword [esi + rx_desc.buf_addr], eax
1209
        mov     dword [esi + rx_desc.buf_addr], eax
1213
 
1210
 
-
 
1211
;---------------
1214
;---------------
1212
; re set OWN bit
Line 1215... Line 1213...
1215
; re set OWN bit
1213
 
1216
 
1214
        mov     eax, DSB_OWNbit or RX_BUF_SIZE
Line 1217... Line 1215...
1217
        mov     eax, DSB_OWNbit or RX_BUF_SIZE
1215
        cmp     [ebx + device.cur_rx], NUM_RX_DESC - 1
1218
        cmp     [tpc.cur_rx], NUM_RX_DESC - 1
1216
        jne     @f
Line 1219... Line 1217...
1219
        jne     @f
1217
        or      eax, DSB_EORbit
1220
        or      eax, DSB_EORbit
1218
    @@:
Line 1221... Line 1219...
1221
    @@: mov     [esi + rx_desc.status], eax
1219
        mov     [esi + rx_desc.status], eax
1222
 
1220
 
Line 1240... Line 1238...
1240
        push    ax
1238
        push    ax
Line 1241... Line 1239...
1241
 
1239
 
Line 1242... Line 1240...
1242
        DEBUGF  1,"TX ok!\n"
1240
        DEBUGF  1,"TX ok!\n"
1243
 
1241
 
1244
        mov     ecx, NUM_TX_DESC
1242
        mov     ecx, NUM_TX_DESC
1245
        lea     esi, [device.tx_ring]
1243
        lea     esi, [ebx + device.tx_ring]
1246
  .txloop:
1244
  .txloop:
Line 1247... Line 1245...
1247
        cmp     [esi + tx_desc.buf_soft_addr], 0
1245
        cmp     dword [esi + tx_desc.buf_soft_addr], 0
1248
        jz      .maybenext
1246
        jz      .maybenext
Line 1249... Line 1247...
1249
 
1247
 
1250
        test    [esi + tx_desc.status], DSB_OWNbit
1248
        test    [esi + tx_desc.status], DSB_OWNbit
1251
        jnz     .maybenext
1249
        jnz     .maybenext
1252
 
1250
 
1253
        push    ecx
1251
        push    ecx
Line 1254... Line 1252...
1254
        DEBUGF  1,"Freeing up TX desc: %x\n", esi
1252
        DEBUGF  1,"Freeing up TX desc: %x\n", esi
1255
        stdcall KernelFree, [esi + tx_desc.buf_soft_addr]
1253
        invoke  KernelFree, [esi + tx_desc.buf_soft_addr]
1256
        pop     ecx
1254
        pop     ecx
1257
        and     [esi + tx_desc.buf_soft_addr], 0
1255
        and     dword [esi + tx_desc.buf_soft_addr], 0
Line 1258... Line 1256...
1258
 
1256
 
1259
  .maybenext:
1257
  .maybenext:
Line 1260... Line 1258...
1260
        add     esi, tx_desc.size
1258
        add     esi, sizeof.tx_desc
1261
        dec     ecx
1259
        dec     ecx
Line 1262... Line 1260...
1262
        jnz     .txloop
1260
        jnz     .txloop
1263
 
1261
 
1264
        pop     ax
1262
        pop     ax
Line 1265... Line 1263...
1265
  .no_tx:
1263
  .no_tx:
1266
 
1264
 
1267
;-------
1265
;-------
Line 1278... Line 1276...
1278
 
1276
 
Line -... Line 1277...
-
 
1277
        ret
Line -... Line 1278...
-
 
1278
 
-
 
1279
 
Line -... Line 1280...
-
 
1280
 
Line 1279... Line -...
1279
        ret
-
 
1280
 
-
 
1281
 
-
 
1282
 
-
 
1283
 
-
 
1284
 
-
 
1285
 
-
 
1286
 
-
 
1287
 
1281
; End of code
Line 1288... Line 1282...
1288
 
1282
 
Line 1289... Line 1283...
1289
; End of code
1283
data fixups
Line 1325... Line 1319...
1325
name_05         db "RTL8169sc/8110sc", 0
1319
name_05         db "RTL8169sc/8110sc", 0
1326
name_11_12      db "RTL8168b/8111b", 0  ; PCI-E
1320
name_11_12      db "RTL8168b/8111b", 0  ; PCI-E
1327
name_13         db "RTL8101e", 0        ; PCI-E 8139
1321
name_13         db "RTL8101e", 0        ; PCI-E 8139
1328
name_14_15      db "RTL8100e", 0        ; PCI-E 8139
1322
name_14_15      db "RTL8100e", 0        ; PCI-E 8139
Line 1329... Line 1323...
1329
 
1323
 
1330
 
1324
align 4
1331
section '.data' data readable writable align 16 ; place all uninitialized data place here
-
 
1332
 
1325
devices         dd 0