Subversion Repositories Kolibri OS

Rev

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

Rev 4576 Rev 4580
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
18
 
19
 
-
 
20
        CURRENT_API             = 0x0200
Line 19... Line 21...
19
        API_VERSION             = 0x01000100
21
        COMPATIBLE_API          = 0x0100
Line 20... Line 22...
20
        DRIVER_VERSION          = 5
22
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
21
 
23
 
22
        MAX_DEVICES             = 16
24
        MAX_DEVICES             = 16
Line 23... Line 25...
23
 
25
 
24
        DEBUG                   = 1
26
        DEBUG                   = 1
Line -... Line 27...
-
 
27
        __DEBUG__               = 1
-
 
28
        __DEBUG_LEVEL__         = 2
-
 
29
 
25
        __DEBUG__               = 1
30
        NUM_TX_DESC             = 6
26
        __DEBUG_LEVEL__         = 2
31
        NUM_RX_DESC             = 12
27
 
-
 
28
        NUM_TX_DESC             = 6
-
 
29
        NUM_RX_DESC             = 12
32
 
30
 
33
section '.flat' readable writable executable
31
include '../struct.inc'
-
 
32
include '../macros.inc'
-
 
33
include '../proc32.inc'
-
 
34
include '../imports.inc'
-
 
35
include '../fdo.inc'
-
 
Line 36... Line 34...
36
include '../netdrv.inc'
34
 
Line 37... Line 35...
37
 
35
include '../proc32.inc'
38
public START
36
include '../struct.inc'
Line 247... Line 245...
247
    LinkIsUp       = 0x0004
245
    LinkIsUp       = 0x0004
248
    LinkIsUp2      = 0x00040000
246
    LinkIsUp2      = 0x00040000
Line 249... Line -...
249
 
-
 
250
 
-
 
251
 
247
 
252
virtual at 0
248
 
253
 
249
 
254
        mtd_desc:
250
struct  descriptor
255
        .status                 dd ?
251
        status                  dd ?
256
        .control                dd ?
252
        control                 dd ?
257
        .buffer                 dd ?
253
        buffer                  dd ?
258
        .next_desc              dd ?
254
        next_desc               dd ?
259
 
-
 
260
        .next_desc_logical      dd ?
255
 
261
        .skbuff                 dd ?
256
        next_desc_logical       dd ?
262
 
-
 
263
        .reserved1              dd ?
-
 
264
        .reserved2              dd ?
-
 
265
 
257
        skbuff                  dd ?
266
        .size = $
-
 
267
 
-
 
268
end virtual
-
 
269
 
258
        reserved1               dd ?
270
 
-
 
271
virtual at ebx
259
        reserved2               dd ?
272
 
260
ends
273
        device:
-
 
274
 
-
 
275
        ETH_DEVICE
-
 
276
 
261
 
277
        .tx_desc        rb NUM_TX_DESC*mtd_desc.size
262
 
278
        .rx_desc        rb NUM_RX_DESC*mtd_desc.size
263
struct  device          ETH_DEVICE
279
 
264
 
280
        .io_addr        dd ?
265
        io_addr         dd ?
281
        .pci_bus        dd ?
266
        pci_bus         dd ?
282
        .pci_dev        dd ?
-
 
283
        .irq_line       db ?
267
        pci_dev         dd ?
284
        .dev_id         dw ?
-
 
285
 
268
        irq_line        db ?
286
        .flags          dd ?
269
        dev_id          dw ?
287
 
-
 
288
        .crvalue        dd ?
270
        flags           dd ?
289
        .bcrvalue       dd ?
271
        crvalue         dd ?
290
 
-
 
291
        .cur_rx         dd ?
-
 
292
        .cur_tx         dd ?
-
 
293
 
-
 
294
; These values are keep track of the transceiver/media in use.
-
 
295
 
-
 
296
        .linkok         dd ?
272
        bcrvalue        dd ?
297
        .line_speed     dd ?
273
        cur_rx          dd ?
Line 298... Line 274...
298
        .duplexmode     dd ?
274
        cur_tx          dd ?
-
 
275
        default_port    dd ?
-
 
276
        PHYType         dd ?
Line -... Line 277...
-
 
277
 
-
 
278
; MII transceiver section.
299
        .default_port   dd ?
279
        mii_cnt         dd ?    ; MII device addresses.
300
        .PHYType        dd ?
280
        phys            db ?    ; MII device addresses.
Line 301... Line 281...
301
 
281
 
Line 302... Line -...
302
; MII transceiver section.
-
 
303
 
-
 
304
        .mii_cnt        dd ?    ; MII device addresses.
-
 
305
        .phys           db ?    ; MII device addresses.
-
 
306
 
-
 
Line 307... Line 282...
307
        device_size = $ - device
282
; descriptors
308
 
283
        rb 0x100 - ($ and 0xff) ; align 256
309
end virtual
284
        tx_desc         rb NUM_TX_DESC*sizeof.descriptor
310
 
285
        rx_desc         rb NUM_RX_DESC*sizeof.descriptor
311
 
286
 
312
 
287
ends
Line 313... Line -...
313
section '.flat' code readable align 16
-
 
314
 
288
 
Line 315... Line 289...
315
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
289
 
316
;;                        ;;
290
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
317
;; proc START             ;;
-
 
318
;;                        ;;
-
 
Line 319... Line 291...
319
;; (standard driver proc) ;;
291
;;                        ;;
320
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
292
;; proc START             ;;
321
 
293
;;                        ;;
Line 322... Line 294...
322
align 4
294
;; (standard driver proc) ;;
323
proc START stdcall, state:dword
-
 
324
 
295
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
325
        cmp [state], 1
296
 
Line 326... Line 297...
326
        jne .exit
297
proc START c, reason:dword, cmdline:dword
Line 344... Line 315...
344
;; proc SERVICE_PROC      ;;
315
;; proc SERVICE_PROC      ;;
345
;;                        ;;
316
;;                        ;;
346
;; (standard driver proc) ;;
317
;; (standard driver proc) ;;
347
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
318
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 348... Line -...
348
 
-
 
349
align 4
319
 
Line 350... Line 320...
350
proc service_proc stdcall, ioctl:dword
320
proc service_proc stdcall, ioctl:dword
351
 
321
 
Line 386... Line 356...
386
 
356
 
387
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
357
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
388
        mov     ax, [eax+1]                             ;
358
        mov     ax, [eax+1]                             ;
389
  .nextdevice:
359
  .nextdevice:
390
        mov     ebx, [esi]
360
        mov     ebx, [esi]
391
        cmp     al, byte[device.pci_bus]
361
        cmp     al, byte[ebx + device.pci_bus]
392
        jne     @f
362
        jne     @f
393
        cmp     ah, byte[device.pci_dev]
363
        cmp     ah, byte[ebx + device.pci_dev]
394
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
364
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
395
       @@:
365
       @@:
396
        add     esi, 4
366
        add     esi, 4
Line 400... Line 370...
400
; This device doesnt have its own eth_device structure yet, lets create one
370
; This device doesnt have its own eth_device structure yet, lets create one
401
  .firstdevice:
371
  .firstdevice:
402
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
372
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
403
        jae     .fail
373
        jae     .fail
Line 404... Line 374...
404
 
374
 
Line 405... Line 375...
405
        allocate_and_clear ebx, device_size, .fail
375
        allocate_and_clear ebx, sizeof.device, .fail
Line 406... Line 376...
406
 
376
 
407
; Fill in the direct call addresses into the struct
377
; Fill in the direct call addresses into the struct
408
 
378
 
409
        mov     [device.reset], reset
379
        mov     [ebx + device.reset], reset
Line 410... Line 380...
410
        mov     [device.transmit], transmit
380
        mov     [ebx + device.transmit], transmit
Line 411... Line 381...
411
        mov     [device.unload], unload
381
        mov     [ebx + device.unload], unload
412
        mov     [device.name], my_service
382
        mov     [ebx + device.name], my_service
413
 
383
 
414
; save the pci bus and device numbers
384
; save the pci bus and device numbers
415
 
385
 
Line 416... Line 386...
416
        mov     eax, [edx + IOCTL.input]
386
        mov     eax, [edx + IOCTL.input]
Line -... Line 387...
-
 
387
        movzx   ecx, byte[eax+1]
417
        movzx   ecx, byte[eax+1]
388
        mov     [ebx + device.pci_bus], ecx
Line 418... Line 389...
418
        mov     [device.pci_bus], ecx
389
        movzx   ecx, byte[eax+2]
Line -... Line 390...
-
 
390
        mov     [ebx + device.pci_dev], ecx
419
        movzx   ecx, byte[eax+2]
391
 
Line 420... Line 392...
420
        mov     [device.pci_dev], ecx
392
; Now, it's time to find the base io addres of the PCI device
421
 
393
 
Line 422... Line 394...
422
; Now, it's time to find the base io addres of the PCI device
394
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
423
 
395
        mov     [ebx + device.io_addr], eax
424
        PCI_find_io
396
 
425
 
397
; We've found the io address, find IRQ now
Line 438... Line 410...
438
 
410
 
439
        call    probe                                                   ; this function will output in eax
411
        call    probe                                                   ; this function will output in eax
440
        test    eax, eax
412
        test    eax, eax
Line 441... Line 413...
441
        jnz     .err2                                                   ; If an error occured, exit
413
        jnz     .err2                                                   ; If an error occured, exit
442
 
414
 
Line 443... Line 415...
443
        mov     [device.type], NET_TYPE_ETH
415
        mov     [ebx + device.type], NET_TYPE_ETH
444
        call    NetRegDev
416
        invoke  NetRegDev
Line 445... Line 417...
445
 
417
 
Line 446... Line 418...
446
        cmp     eax, -1
418
        cmp     eax, -1
Line 447... Line 419...
447
        je      .destroy
419
        je      .destroy
448
 
420
 
449
        ret
421
        ret
450
 
422
 
451
; If the device was already loaded, find the device number and return it in eax
423
; If the device was already loaded, find the device number and return it in eax
452
 
424
 
453
  .find_devicenum:
425
  .find_devicenum:
Line 465... Line 437...
465
 
437
 
466
  .err2:
438
  .err2:
467
        dec     [devices]
439
        dec     [devices]
468
  .err:
440
  .err:
469
        DEBUGF  2,"removing device structure\n"
441
        DEBUGF  2,"removing device structure\n"
470
        stdcall KernelFree, ebx
442
        invoke  KernelFree, ebx
471
  .fail:
443
  .fail:
472
        or      eax, -1
444
        or      eax, -1
Line 473... Line 445...
473
        ret
445
        ret
Line 512... Line 484...
512
;
484
;
513
;-------
485
;-------
514
align 4
486
align 4
515
probe:
487
probe:
Line 516... Line 488...
516
 
488
 
Line 517... Line 489...
517
        DEBUGF  2,"Probing device\n"
489
        DEBUGF  1,"Probing\n"
518
 
-
 
519
        PCI_make_bus_master
490
 
-
 
491
; Make the device a bus master
-
 
492
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line -... Line 493...
-
 
493
        or      al, PCI_CMD_MASTER
-
 
494
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
520
 
495
 
521
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], 0
496
; Check vendor/device id's
522
 
497
        invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0
523
        cmp     ax, 0x1516
498
        cmp     ax, 0x1516
524
        jne     .notfound
-
 
525
        shr     eax, 16
499
        jne     .notfound
526
        mov     [device.dev_id], ax
500
        shr     eax, 16
527
 
-
 
528
        cmp     ax, 0x0800
501
        mov     [ebx + device.dev_id], ax
529
        je      .has_mii_xcvr
502
        cmp     ax, 0x0800
530
 
-
 
531
        cmp     ax, 0x0803
503
        je      .mtd800
532
        je      .has_chip_xcvr
504
        cmp     ax, 0x0803
Line 533... Line 505...
533
 
505
        je      .mtd803
534
        cmp     ax, 0x0891
506
        cmp     ax, 0x0891
535
        je      .has_mii_xcvr
507
        je      .mtd891
536
 
508
 
537
  .notfound:
509
  .notfound:
Line 538... Line 510...
538
        DEBUGF  1,"Device not supported!\n"
510
        DEBUGF  2,"Device not supported!\n"
-
 
511
        xor     eax, eax
539
        xor     eax, eax
512
        dec     eax
-
 
513
        ret
Line -... Line 514...
-
 
514
 
-
 
515
  .mtd803:
-
 
516
        mov     [ebx + device.name], sz_mtd803
540
        dec     eax
517
        DEBUGF  1,"Device has chip xcvr\n"
Line 541... Line 518...
541
        ret
518
        jmp     .xcvr_set
542
 
519
 
-
 
520
  .mtd800:
Line 543... Line 521...
543
  .has_chip_xcvr:
521
        DEBUGF  1,"Device has mii xcvr\n"
544
        DEBUGF  1,"Device has chip xcvr\n"
-
 
545
 
522
        mov     [ebx + device.name], sz_mtd800
Line 546... Line 523...
546
        jmp     .xcvr_set
523
        jmp     .xcvr_set
547
 
-
 
548
  .has_mii_xcvr:
524
 
549
        DEBUGF  1,"Device has mii xcvr\n"
525
  .mtd891:
550
 
526
        DEBUGF  1,"Device has mii xcvr\n"
551
  .xcvr_set:
527
        mov     [ebx + device.name], sz_mtd800
552
 
528
 
Line 553... Line 529...
553
        call    read_mac
529
  .xcvr_set:
554
 
-
 
555
; Reset the chip to erase previous misconfiguration.
530
        call    read_mac
556
 
531
 
Line 557... Line 532...
557
        set_io  0
532
; Reset the chip to erase previous misconfiguration.
558
        set_io  BCR
533
        set_io  [ebx + device.io_addr], 0
559
        xor     eax, eax
534
        set_io  [ebx + device.io_addr], BCR
Line 604... Line 579...
604
;        }
579
;        }
Line 605... Line 580...
605
 
580
 
Line 606... Line 581...
606
        jmp     .no_803
581
        jmp     .no_803
607
 
-
 
608
  .is_803:
582
 
Line 609... Line 583...
609
 
583
  .is_803:
610
        mov     [device.phys], 32
584
        mov     [ebx + device.phys], 32
611
 
585
 
612
; get phy type
586
; get phy type
Line 613... Line 587...
613
        set_io  0
587
        set_io  [ebx + device.io_addr], 0
614
        set_io  PHYIDENTIFIER
588
        set_io  [ebx + device.io_addr], PHYIDENTIFIER
615
        in      eax, dx
-
 
616
 
589
        in      eax, dx
617
        cmp     eax, MysonPHYID
590
 
618
        jne     @f
591
        cmp     eax, MysonPHYID
619
 
-
 
620
        mov     [device.PHYType], MysonPHY
592
        jne     @f
621
        DEBUGF  1,"MysonPHY\n"
-
 
622
        jmp     .no_803
-
 
Line -... Line 593...
-
 
593
        mov     [ebx + device.PHYType], MysonPHY
-
 
594
        DEBUGF  1,"Myson PHY\n"
623
 
595
        jmp     .no_803
Line 624... Line 596...
624
       @@:
596
       @@:
625
        mov     [device.PHYType], OtherPHY
597
 
626
        DEBUGF  1,"OtherPHY\n"
598
        mov     [ebx + device.PHYType], OtherPHY
Line 635... Line 607...
635
align 4
607
align 4
636
reset:
608
reset:
Line 637... Line 609...
637
 
609
 
Line 638... Line -...
638
        DEBUGF  1,"Resetting\n"
-
 
639
 
610
        DEBUGF  1,"Resetting\n"
640
;--------------------------------
-
 
641
; insert irq handler on given irq
611
 
642
 
612
; attach irq handler
643
        movzx   eax, [device.irq_line]
613
        movzx   eax, [ebx + device.irq_line]
644
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
614
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
645
        stdcall AttachIntHandler, eax, int_handler, dword 0
615
        invoke  AttachIntHandler, eax, int_handler, ebx
646
        test    eax, eax
616
        test    eax, eax
647
        jnz     @f
617
        jnz     @f
648
        DEBUGF  1,"Could not attach int handler!\n"
618
        DEBUGF  2,"Could not attach int handler!\n"
649
        or      eax, -1
619
        or      eax, -1
Line 650... Line 620...
650
        ret
620
        ret
651
  @@:
-
 
652
 
621
  @@:
653
; Reset the chip to erase previous misconfiguration.
622
 
654
 
623
; Reset the chip to erase previous misconfiguration.
655
        set_io  0
624
        set_io  [ebx + device.io_addr], 0
656
        set_io  BCR
625
        set_io  [ebx + device.io_addr], BCR
Line 657... Line 626...
657
        xor     eax, eax
626
        xor     eax, eax
Line 658... Line 627...
658
        inc     eax
627
        inc     eax
659
        out     dx, eax
628
        out     dx, eax
-
 
629
 
-
 
630
        call    init_ring
Line 660... Line -...
660
 
-
 
661
        call    init_ring
-
 
662
 
-
 
663
; Initialize other registers.
631
 
664
; Configure the PCI bus bursts and FIFO thresholds.
632
; Initialize other registers.
665
 
633
; Configure the PCI bus bursts and FIFO thresholds.
666
        mov     [device.bcrvalue], 0x10         ; little-endian, 8 burst length
634
        mov     [ebx + device.bcrvalue], 0x10         ; little-endian, 8 burst length
667
        mov     [device.crvalue], 0xa00         ; 128 burst length
635
        mov     [ebx + device.crvalue], 0xa00         ; 128 burst length
668
 
-
 
669
        cmp     [device.dev_id], 0x891
636
 
Line 670... Line 637...
670
        jne     @f
637
        cmp     [ebx + device.dev_id], 0x891
Line 671... Line 638...
671
        or      [device.bcrvalue], 0x200       ; set PROG bit
638
        jne     @f
672
        or      [device.crvalue], 0x02000000   ; set enhanced bit
639
        or      [ebx + device.bcrvalue], 0x200       ; set PROG bit
673
       @@:
640
        or      [ebx + device.crvalue], 0x02000000   ; set enhanced bit
674
 
641
       @@:
Line 675... Line 642...
675
        or      [device.crvalue], RxEnable + TxThreshold + TxEnable
642
        or      [ebx + device.crvalue], RxEnable + TxThreshold + TxEnable
676
 
643
 
677
        call    set_rx_mode
644
        call    set_rx_mode
Line 678... Line 645...
678
 
645
 
679
        set_io  0
-
 
Line 680... Line 646...
680
        set_io  BCR
646
        set_io  [ebx + device.io_addr], 0
681
        mov     eax, [device.bcrvalue]
-
 
682
        out     dx, eax
647
        set_io  [ebx + device.io_addr], BCR
683
 
648
        mov     eax, [ebx + device.bcrvalue]
684
        set_io  TCRRCR
649
        out     dx, eax
685
        mov     eax, [device.crvalue]
650
 
Line 686... Line 651...
686
        out     dx, eax
651
        set_io  [ebx + device.io_addr], TCRRCR
687
 
-
 
688
        call    getlinkstatus
-
 
689
        call    getlinktype
652
        mov     eax, [ebx + device.crvalue]
690
 
653
        out     dx, eax
691
; Restart Rx engine if stopped.
654
 
692
 
655
        call    getlinkstatus
693
        set_io  0
656
 
Line 694... Line 657...
694
        set_io  RXPDR
657
; Restart Rx engine if stopped.
695
        xor     eax, eax
-
 
696
        out     dx, eax
658
        set_io  [ebx + device.io_addr], 0
697
 
659
        set_io  [ebx + device.io_addr], RXPDR
698
; Enable interrupts
660
        xor     eax, eax
699
 
661
        out     dx, eax
Line 700... Line 662...
700
        set_io  0
662
 
701
        set_io  ISR
-
 
702
        mov     eax, FBE or TUNF or CNTOVF or RBU or TI or RI
-
 
703
        out     dx, eax
-
 
704
        set_io  IMR
-
 
705
        out     dx, eax
663
; Enable interrupts
706
 
664
        set_io  [ebx + device.io_addr], ISR
Line 726... Line 684...
726
init_ring:
684
init_ring:
Line 727... Line 685...
727
 
685
 
Line 728... Line 686...
728
        DEBUGF  1,"initializing rx and tx ring\n"
686
        DEBUGF  1,"initializing rx and tx ring\n"
729
 
-
 
730
; Initialize all Rx descriptors
687
 
731
 
688
; Initialize all Rx descriptors
732
        lea     esi, [device.rx_desc]
689
        lea     esi, [ebx + device.rx_desc]
733
        mov     [device.cur_rx], esi
690
        mov     [ebx + device.cur_rx], esi
734
        mov     ecx, NUM_RX_DESC
691
        mov     ecx, NUM_RX_DESC
735
  .rx_desc_loop:
692
  .rx_desc_loop:
Line 736... Line 693...
736
        mov     [esi + mtd_desc.status], RXOWN
693
        mov     [esi + descriptor.status], RXOWN
737
        mov     [esi + mtd_desc.control], 1536 shl RBSShift
694
        mov     [esi + descriptor.control], 1536 shl RBSShift
738
 
695
 
739
        lea     eax, [esi + mtd_desc.size]
696
        lea     eax, [esi + sizeof.descriptor]
740
        mov     [esi + mtd_desc.next_desc_logical], eax
697
        mov     [esi + descriptor.next_desc_logical], eax
Line 741... Line 698...
741
        push    ecx esi
698
        push    ecx esi
742
        GetRealAddr
699
        invoke  GetPhysAddr
743
        mov     [esi + mtd_desc.next_desc], eax
700
        mov     [esi + descriptor.next_desc], eax
744
 
701
 
745
        stdcall KernelAlloc, 1536
702
        invoke  KernelAlloc, 1536
746
        pop     esi
703
        pop     esi
747
        push    esi
704
        push    esi
Line 748... Line 705...
748
        mov     [esi + mtd_desc.skbuff], eax
705
        mov     [esi + descriptor.skbuff], eax
749
        call    GetPgAddr
706
        invoke  GetPgAddr
Line 750... Line 707...
750
        pop     esi ecx
707
        pop     esi ecx
751
        mov     [esi + mtd_desc.buffer], eax
-
 
752
 
708
        mov     [esi + descriptor.buffer], eax
753
        add     esi, mtd_desc.size
709
 
754
        loop    .rx_desc_loop
710
        add     esi, sizeof.descriptor
755
 
711
        loop    .rx_desc_loop
756
; Mark the last entry as wrapping the ring.
712
 
757
 
713
; Mark the last entry as wrapping the ring.
Line 758... Line 714...
758
        lea     eax, [device.rx_desc]
714
        lea     eax, [ebx + device.rx_desc]
759
        mov     [esi - mtd_desc.size + mtd_desc.next_desc_logical], eax
715
        mov     [esi - sizeof.descriptor + descriptor.next_desc_logical], eax
760
        push    esi
716
        push    esi
Line 761... Line 717...
761
        GetRealAddr
717
        invoke  GetPhysAddr
762
        pop     esi
-
 
763
        mov     [esi - mtd_desc.size + mtd_desc.next_desc], eax
718
        pop     esi
764
 
719
        mov     [esi - sizeof.descriptor + descriptor.next_desc], eax
765
        set_io  0
720
 
766
        set_io  RXLBA
721
        set_io  [ebx + device.io_addr],   0
767
        out     dx, eax
722
        set_io  [ebx + device.io_addr],   RXLBA
Line 768... Line 723...
768
 
723
        out     dx, eax
769
; Initialize all Tx descriptors
724
 
770
 
725
; Initialize all Tx descriptors
771
        lea     esi, [device.tx_desc]
726
        lea     esi, [ebx + device.tx_desc]
772
        mov     [device.cur_tx], esi
727
        mov     [ebx + device.cur_tx], esi
773
        mov     ecx, NUM_TX_DESC
728
        mov     ecx, NUM_TX_DESC
774
  .tx_desc_loop:
729
  .tx_desc_loop:
775
        mov     [esi + mtd_desc.status], 0
730
        mov     [esi + descriptor.status], 0
776
 
731
 
Line 777... Line 732...
777
        lea     eax, [esi + mtd_desc.size]
732
        lea     eax, [esi + sizeof.descriptor]
778
        mov     [esi + mtd_desc.next_desc_logical], eax
-
 
779
        push    ecx esi
733
        mov     [esi + descriptor.next_desc_logical], eax
780
        GetRealAddr
734
        push    ecx esi
781
        pop     esi ecx
735
        invoke  GetPhysAddr
782
        mov     [esi + mtd_desc.next_desc], eax
736
        pop     esi ecx
783
        mov     [esi + mtd_desc.skbuff], 0
737
        mov     [esi + descriptor.next_desc], eax
784
        add     esi, mtd_desc.size
738
        mov     [esi + descriptor.skbuff], 0
Line 785... Line 739...
785
        loop    .tx_desc_loop
739
        add     esi, sizeof.descriptor
786
 
740
        loop    .tx_desc_loop
787
; Mark the last entry as wrapping the ring.
741
 
Line 788... Line 742...
788
 
742
; Mark the last entry as wrapping the ring.
Line 804... Line 758...
804
set_rx_mode:
758
set_rx_mode:
Line 805... Line 759...
805
 
759
 
Line 806... Line 760...
806
        DEBUGF  1,"Setting RX mode\n"
760
        DEBUGF  1,"Setting RX mode\n"
807
 
-
 
808
; Too many to match, or accept all multicasts.
761
 
809
 
762
; Too many to match, or accept all multicasts.
810
        set_io  0
763
        set_io  [ebx + device.io_addr], 0
811
        set_io  MAR0
764
        set_io  [ebx + device.io_addr], MAR0
812
        xor     eax, eax
765
        xor     eax, eax
813
        not     eax
766
        not     eax
814
        out     dx, eax
767
        out     dx, eax
Line 815... Line 768...
815
        set_io  MAR1
768
        set_io  [ebx + device.io_addr], MAR1
816
        out     dx, eax
769
        out     dx, eax
Line 817... Line 770...
817
 
770
 
Line 818... Line 771...
818
        and     [device.crvalue], not (RxModeMask)
771
        and     [ebx + device.crvalue], not (RxModeMask)
819
        or      [device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys
772
        or      [ebx + device.crvalue], AcceptBroadcast + AcceptMulticast + AcceptMyPhys
Line 820... Line 773...
820
 
773
 
Line 821... Line 774...
821
        ret
774
        ret
Line 822... Line 775...
822
 
775
 
823
 
776
 
824
align 4
-
 
825
getlinkstatus:
777
align 4
826
 
778
getlinkstatus:
827
        DEBUGF  1,"Getting link status\n"
-
 
828
 
-
 
829
        mov     [device.linkok], 0
779
 
830
 
780
        DEBUGF  1,"Getting link status\n"
831
        cmp     [device.PHYType], MysonPHY
781
 
832
        jne     .no_myson_phy
-
 
833
 
-
 
834
        set_io  0
-
 
835
        set_io  BMCRSR
-
 
836
        mov     ecx, 1000
-
 
837
  .loop1:
-
 
838
        in      eax, dx
-
 
839
        test    eax, LinkIsUp2
782
        mov     [ebx + device.state], ETH_LINK_DOWN     ; assume link is dead
Line 840... Line 783...
840
        jnz     .link_ok
783
 
841
 
-
 
842
        push    ecx edx ebx
784
        cmp     [ebx + device.PHYType], MysonPHY
843
        mov     esi, 10
-
 
844
        call    Sleep
785
        jne     .no_myson_phy
845
        pop     ebx edx ecx
786
        set_io  [ebx + device.io_addr], 0
846
        loop    .loop1
-
 
847
 
-
 
848
        ret
-
 
849
 
-
 
850
  .no_myson_phy:
-
 
851
 
-
 
852
;        for (i =   0; i < DelayTime; ++i) {
787
        set_io  [ebx + device.io_addr], BMCRSR
853
;            if (mdio_read(nic, mtdx.phys[0], MII_BMSR) & BMSR_LSTATUS) {
788
        in      eax, dx
854
;                mtdx.linkok =   1;
789
        test    eax, LinkIsUp2
Line 855... Line -...
855
;                return;
-
 
856
;            }
-
 
857
;            m80x_delay(100);
-
 
858
 
-
 
859
        ret
790
        jnz     getlinktype
Line 860... Line 791...
860
 
791
        ret
861
  .link_ok:
-
 
862
        DEBUGF  1,"Link is up\n"
792
 
863
        inc     [device.linkok]
793
  .no_myson_phy:
Line 864... Line 794...
864
        ret
794
        set_io  [ebx + device.io_addr], 0
865
 
-
 
866
 
795
        set_io  [ebx + device.io_addr], BMCRSR
867
 
796
        in      eax, dx
868
 
797
        test    eax, LinkIsUp
869
align 4
-
 
870
getlinktype:
-
 
871
 
798
        jnz     getlinktype
872
        DEBUGF  1,"Getting link type\n"
799
        ret
873
 
800
 
874
        cmp     [device.PHYType], MysonPHY
801
getlinktype:
875
        jne     .no_myson_phy
802
 
876
 
-
 
877
        DEBUGF  1,"myson PHY\n"
-
 
878
 
803
        DEBUGF  1,"Getting link type\n"
879
        set_io  0
804
        cmp     [ebx + device.PHYType], MysonPHY
880
        set_io  TCRRCR
805
        jne     .no_myson_phy
881
        in      eax, dx
806
 
-
 
807
        DEBUGF  1,"myson PHY\n"
882
 
808
        set_io  [ebx + device.io_addr], 0
883
        mov     [device.duplexmode], 1  ; 1 =   half duplex
-
 
-
 
809
        set_io  [ebx + device.io_addr], TCRRCR
-
 
810
        in      eax, dx
884
        test    eax, FD
811
        test    eax, FD
Line 885... Line 812...
885
        jne     @f
812
        jz      @f
886
        DEBUGF  1,"full duplex\n"
-
 
887
        inc     [device.duplexmode]     ; 2 =   full duplex
813
        DEBUGF  1,"full duplex\n"
-
 
814
        or      [ebx + device.state], ETH_LINK_FD
Line 888... Line 815...
888
       @@:
815
       @@:
889
 
816
        test    eax, PS10
890
        mov     [device.line_speed], 1  ; 1 =   10M
817
        jnz     @f
891
        test    eax, PS10
818
        DEBUGF  1,"100mbit\n"
Line 980... Line 907...
980
;            mtdx.crvalue |=   PS10;
907
;            mtdx.crvalue |=   PS10;
981
;        else if (mtdx.line_speed equ=   3)
908
;        else if (mtdx.line_speed equ=   3)
982
;            mtdx.crvalue |=   PS1000;
909
;            mtdx.crvalue |=   PS1000;
983
;        if (mtdx.duplexmode equ=   2)
910
;        if (mtdx.duplexmode equ=   2)
984
;            mtdx.crvalue |=   FD;
911
;            mtdx.crvalue |=   FD;
985
;
-
 
Line 986... Line 912...
986
 
912
 
Line 997... Line 923...
997
;;     size of buffer in [esp+8]           ;;
923
;;     size of buffer in [esp+8]           ;;
998
;;     pointer to device structure in ebx  ;;
924
;;     pointer to device structure in ebx  ;;
999
;;                                         ;;
925
;;                                         ;;
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
926
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 1001... Line -...
1001
 
-
 
1002
align 4
927
 
Line -... Line 928...
-
 
928
proc transmit stdcall bufferptr, buffersize
-
 
929
 
-
 
930
        pushf
1003
transmit:
931
        cli
1004
 
932
 
1005
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
933
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
1006
        mov     eax, [esp+4]
934
        mov     eax, [bufferptr]
1007
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
935
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
1008
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
936
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 1009... Line 937...
1009
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
937
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
1010
        [eax+13]:2,[eax+12]:2
938
        [eax+13]:2,[eax+12]:2
-
 
939
 
-
 
940
        cmp     [buffersize], 1514
Line 1011... Line 941...
1011
 
941
        ja      .fail
Line 1012... Line 942...
1012
        cmp     dword [esp+8], 1514
942
        cmp     [buffersize], 60
1013
        ja      .fail
943
        jb      .fail
Line 1014... Line 944...
1014
 
944
 
1015
        mov     esi, [device.cur_tx]
945
        mov     esi, [ebx + device.cur_tx]
Line 1016... Line 946...
1016
 
946
 
1017
        test    [esi + mtd_desc.status], TXOWN
947
        test    [esi + descriptor.status], TXOWN
1018
        jnz     .fail
948
        jnz     .fail
1019
 
949
 
Line 1020... Line 950...
1020
        push    [esi + mtd_desc.next_desc_logical]
950
        push    [esi + descriptor.next_desc_logical]
1021
        pop     [device.cur_tx]
951
        pop     [ebx + device.cur_tx]
1022
 
952
 
1023
        mov     eax, [esp + 4]
953
        mov     eax, [bufferptr]
1024
        mov     [esi + mtd_desc.skbuff], eax
954
        mov     [esi + descriptor.skbuff], eax
1025
        GetRealAddr
955
        invoke  GetPhysAddr
1026
        mov     [esi + mtd_desc.buffer], eax
956
        mov     [esi + descriptor.buffer], eax
1027
 
957
 
Line 1028... Line 958...
1028
        mov     eax, [esp + 8]
958
        mov     eax, [buffersize]
1029
        mov     ecx, eax
959
        mov     ecx, eax
1030
        shl     eax, PKTSShift               ; packet size
960
        shl     eax, PKTSShift               ; packet size
1031
        shl     ecx, TBSShift
961
        shl     ecx, TBSShift
1032
        or      eax, ecx
962
        or      eax, ecx
Line 1033... Line 963...
1033
        or      eax, TXIC + TXLD + TXFD + CRCEnable + PADEnable
963
        or      eax, TXIC + TXLD + TXFD + CRCEnable + PADEnable
1034
        mov     [esi + mtd_desc.control], eax
964
        mov     [esi + descriptor.control], eax
1035
        mov     [esi + mtd_desc.status], TXOWN
965
        mov     [esi + descriptor.status], TXOWN
1036
 
966
 
1037
; Update stats
967
; Update stats
Line 1038... Line 968...
1038
        inc     [device.packets_tx]
968
        inc     [ebx + device.packets_tx]
-
 
969
        mov     eax, [buffersize]
1039
        mov     eax, [esp+8]
970
        add     dword[ebx + device.bytes_tx], eax
1040
        add     dword [device.bytes_tx], eax
971
        adc     dword[ebx + device.bytes_tx + 4], 0
Line 1041... Line 972...
1041
        adc     dword [device.bytes_tx + 4], 0
972
 
1042
 
973
; TX Poll
1043
; TX Poll
974
        set_io  [ebx + device.io_addr], 0
-
 
975
        set_io  [ebx + device.io_addr], TXPDR
1044
        set_io  0
976
        xor     eax, eax
1045
        set_io  TXPDR
977
        out     dx, eax
-
 
978
 
-
 
979
        DEBUGF  1,"Transmit OK\n"
Line 1046... Line 980...
1046
        xor     eax, eax
980
        popf
1047
        out     dx, eax
981
        xor     eax, eax
Line 1048... Line 982...
1048
 
982
        ret
1049
        DEBUGF  1,"transmit ok\n"
983
 
1050
        xor     eax, eax
984
  .fail:
1051
        ret     8
985
        DEBUGF  2,"Transmit failed\n"
1052
 
986
        invoke  KernelFree, [bufferptr]
1053
  .fail:
987
        popf
1054
        DEBUGF  1,"transmit failed\n"
988
        or      eax, -1
1055
        stdcall KernelFree, [esp + 4]
989
        ret
Line 1056... Line 990...
1056
        or      eax, -1
990
 
Line 1057... Line 991...
1057
        ret     8
991
endp
1058
 
992
 
Line 1099... Line 1033...
1099
        jz      .nothing
1033
        jz      .nothing
1100
        mov     esi, device_list
1034
        mov     esi, device_list
1101
  .nextdevice:
1035
  .nextdevice:
1102
        mov     ebx, [esi]
1036
        mov     ebx, [esi]
Line 1103... Line 1037...
1103
 
1037
 
1104
        set_io  0
1038
        set_io  [ebx + device.io_addr], 0
1105
        set_io  ISR
1039
        set_io  [ebx + device.io_addr], ISR
1106
        in      eax, dx
1040
        in      eax, dx
1107
        out     dx, eax                                 ; send it back to ACK
1041
        out     dx, eax                                 ; send it back to ACK
1108
        test    eax, eax
1042
        test    eax, eax
1109
        jnz     .got_it
1043
        jnz     .got_it
Line 1123... Line 1057...
1123
 
1057
 
1124
        test    ax, RI  ; receive interrupt
1058
        test    ax, RI  ; receive interrupt
1125
        jz      .no_rx
1059
        jz      .no_rx
1126
        push    ax
1060
        push    ax
1127
  .rx_loop:
1061
  .rx_loop:
1128
        mov     esi, [device.cur_rx]
1062
        mov     esi, [ebx + device.cur_rx]
1129
        test    [esi + mtd_desc.status], RXOWN
1063
        test    [esi + descriptor.status], RXOWN
Line 1130... Line 1064...
1130
        jnz     .fail_rx
1064
        jnz     .rx_done
1131
 
1065
 
Line 1132... Line 1066...
1132
        push    ebx
1066
        push    ebx
1133
        push    .rx_complete
1067
        push    .rx_complete
1134
 
1068
 
1135
        mov     ecx, [esi + mtd_desc.status]
1069
        mov     ecx, [esi + descriptor.status]
1136
        shr     ecx, FLNGShift
1070
        shr     ecx, FLNGShift
Line 1137... Line 1071...
1137
        sub     ecx, 4                  ; we dont need CRC
1071
        sub     ecx, 4                  ; we dont need CRC
1138
        push    ecx
1072
        push    ecx
1139
        DEBUGF  1,"Received %u bytes\n", ecx
1073
        DEBUGF  1,"Received %u bytes\n", ecx
1140
 
1074
 
Line 1141... Line 1075...
1141
; Update stats
1075
; Update stats
1142
        add     dword[device.bytes_rx], ecx
1076
        add     dword[ebx + device.bytes_rx], ecx
Line 1143... Line 1077...
1143
        adc     dword[device.bytes_rx + 4], 0
1077
        adc     dword[ebx + device.bytes_rx + 4], 0
1144
        inc     [device.packets_rx]
1078
        inc     [ebx + device.packets_rx]
1145
 
1079
 
1146
        push    [esi + mtd_desc.skbuff]
1080
        push    [esi + descriptor.skbuff]
1147
        jmp     Eth_input
1081
        jmp     [Eth_input]
1148
 
1082
 
1149
  .rx_complete:
1083
  .rx_complete:
1150
        pop     ebx
1084
        pop     ebx
1151
        mov     esi, [device.cur_rx]
1085
        mov     esi, [ebx + device.cur_rx]
1152
        mov     [esi + mtd_desc.control], 1536 shl RBSShift
1086
        mov     [esi + descriptor.control], 1536 shl RBSShift
1153
        push    esi
1087
        push    esi
Line 1154... Line 1088...
1154
        stdcall KernelAlloc, 1536
1088
        invoke  KernelAlloc, 1536
1155
        pop     esi
1089
        pop     esi
Line 1156... Line 1090...
1156
        mov     [esi + mtd_desc.skbuff], eax
1090
        mov     [esi + descriptor.skbuff], eax
1157
        call    GetPgAddr
-
 
1158
        mov     [esi + mtd_desc.buffer], eax
-
 
1159
        mov     [esi + mtd_desc.status], RXOWN
-
 
1160
 
-
 
1161
        push    [esi + mtd_desc.next_desc_logical]
-
 
1162
        pop     [device.cur_rx]
-
 
1163
 
-
 
1164
        jmp     .rx_loop
-
 
1165
;
-
 
Line 1166... Line 1091...
1166
;    while( ( mtdx.cur_rx->status & RXOWN ) == 0 )
1091
        invoke  GetPgAddr
1167
;    {
1092
        mov     [esi + descriptor.buffer], eax
1168
;        mtdx.cur_rx->status = RXOWN;
-
 
Line -... Line 1093...
-
 
1093
        mov     [esi + descriptor.status], RXOWN
-
 
1094
 
-
 
1095
        push    [esi + descriptor.next_desc_logical]
-
 
1096
        pop     [ebx + device.cur_rx]
-
 
1097
 
-
 
1098
        jmp     .rx_loop
-
 
1099
 
1169
;        mtdx.cur_rx = mtdx.cur_rx->next_desc_logical;
1100
  .rx_done:
-
 
1101
        DEBUGF  1,"RX done\n"
1170
;    }
1102
 
1171
;
1103
; Restart Rx engine if stopped.
1172
;    /* Restart Rx engine if stopped. */
1104
        set_io  [ebx + device.io_addr], 0
1173
;    outl(0, mtdx.ioaddr + RXPDR);
1105
        set_io  [ebx + device.io_addr], RXPDR
1174
 
1106
        xor     eax, eax
1175
  .fail_rx:
1107
        out     dx, eax
1176
        DEBUGF  1,"RX done\n"
1108
 
1177
        pop     ax
1109
        pop     ax
1178
 
1110
  .no_rx:
1179
  .no_rx:
1111
 
1180
        test    ax, TI ; transmit interrupt
1112
        test    ax, TI ; transmit interrupt
1181
        jz      .no_tx
1113
        jz      .no_tx
1182
        DEBUGF  1,"TX\n"
1114
        DEBUGF  1,"TX\n"
1183
        push    ax
1115
        push    ax
1184
        lea     esi, [device.tx_desc]
1116
        lea     esi, [ebx + device.tx_desc]
1185
        mov     ecx, NUM_TX_DESC
1117
        mov     ecx, NUM_TX_DESC
1186
  .tx_loop:
1118
  .tx_loop:
1187
        test    [esi + mtd_desc.status], TXOWN
1119
        test    [esi + descriptor.status], TXOWN
1188
        jnz     .skip_this_one
1120
        jnz     .skip_this_one
1189
        mov     eax, [esi + mtd_desc.skbuff]
-
 
1190
        test    eax, eax
1121
        mov     eax, [esi + descriptor.skbuff]
-
 
1122
        test    eax, eax
-
 
1123
        je      .skip_this_one
-
 
1124
        mov     [esi + descriptor.skbuff], 0
-
 
1125
        DEBUGF  1,"freeing buffer: 0x%x\n", eax
-
 
1126
        invoke  KernelFree, eax
-
 
1127
  .skip_this_one:
-
 
1128
        mov     esi, [esi + descriptor.next_desc_logical]
-
 
1129
        loop    .tx_loop
1191
        je      .skip_this_one
1130
        pop     ax
1192
        mov     [esi + mtd_desc.skbuff], 0
1131
  .no_tx:
1193
        DEBUGF  1,"freeing buffer: 0x%x\n", eax
1132
 
1194
        stdcall KernelFree, eax
1133
        test    ax, LSCStatus
Line 1211... Line 1150...
1211
        ret
1150
        ret
Line 1212... Line 1151...
1212
 
1151
 
Line 1213... Line -...
1213
 
-
 
Line 1214... Line 1152...
1214
; End of code
1152
 
1215
 
1153
; End of code
1216
align 4                                         ; Place all initialised data here
-
 
Line -... Line 1154...
-
 
1154
 
Line 1217... Line -...
1217
 
-
 
1218
devices       dd 0
1155
 
1219
version       dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
-
 
Line -... Line 1156...
-
 
1156
data fixups
-
 
1157
end data
-
 
1158
 
Line 1220... Line -...
1220
my_service    db 'mtd80x',0                    ; max 16 chars include zero
-
 
Line 1221... Line 1159...
1221
 
1159
include '../peimport.inc'
Line -... Line 1160...
-
 
1160
 
-
 
1161
my_service      db 'mtd80x',0                   ; max 16 chars include zero
1222
 
1162