Subversion Repositories Kolibri OS

Rev

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

Rev 4470 Rev 5046
Line 14... Line 14...
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;          GNU GENERAL PUBLIC LICENSE                             ;;
15
;;             Version 2, June 1991                                ;;
15
;;             Version 2, June 1991                                ;;
16
;;                                                                 ;;
16
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 18...
18
 
18
 
-
 
19
format PE DLL native
Line 19... Line 20...
19
format MS COFF
20
entry START
20
 
21
 
-
 
22
        CURRENT_API             = 0x0200
Line 21... Line 23...
21
        API_VERSION             = 0x01000100
23
        COMPATIBLE_API          = 0x0100
Line 22... Line 24...
22
        DRIVER_VERSION          = 5
24
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
23
 
25
 
Line 24... Line 26...
24
        MAX_DEVICES             = 16
26
        MAX_DEVICES             = 16
25
 
27
 
Line 26... Line -...
26
        RX_DES_COUNT            = 4     ; no of RX descriptors, must be power of 2
-
 
27
        RX_BUFF_SIZE            = 2048  ; size of buffer for each descriptor, must be multiple of 4 and <= 2048 TDES1_TBS1_MASK
-
 
28
 
28
        RX_DES_COUNT            = 4     ; no of RX descriptors, must be power of 2
29
        TX_DES_COUNT            = 4     ; no of TX descriptors, must be power of 2
29
        RX_BUFF_SIZE            = 2048  ; size of buffer for each descriptor, must be multiple of 4 and <= 2048 TDES1_TBS1_MASK
-
 
30
 
-
 
31
        TX_DES_COUNT            = 4     ; no of TX descriptors, must be power of 2
Line -... Line 32...
-
 
32
        TX_BUFF_SIZE            = 2048  ; size of buffer for each descriptor, used for memory allocation only
30
        TX_BUFF_SIZE            = 2048  ; size of buffer for each descriptor, used for memory allocation only
33
 
31
 
34
        __DEBUG__               = 1
32
 
-
 
33
        DEBUG                   = 1
-
 
34
        __DEBUG__               = 1
35
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
35
        __DEBUG_LEVEL__         = 2
36
 
36
 
-
 
37
include '../struct.inc'
-
 
38
include '../macros.inc'
-
 
39
include '../proc32.inc'
-
 
40
include '../imports.inc'
-
 
41
include '../fdo.inc'
-
 
42
include '../netdrv.inc'
-
 
43
 
-
 
44
public START
-
 
45
public service_proc
-
 
46
public version
-
 
47
 
-
 
48
virtual at ebx
-
 
49
 
-
 
50
        device:
-
 
51
 
-
 
52
        ETH_DEVICE
-
 
53
 
-
 
54
        .rx_p_des         dd ?  ; descriptors ring with received packets
-
 
55
        .tx_p_des         dd ?  ; descriptors ring with 'to transmit' packets
-
 
56
        .tx_free_des      dd ?  ; Tx descriptors available
-
 
57
        .tx_wr_des        dd ?  ; Tx current descriptor to write data to
-
 
58
        .tx_rd_des        dd ?  ; Tx current descriptor to read TX completion
-
 
59
        .rx_crt_des       dd ?  ; Rx current descriptor
-
 
60
 
-
 
61
        .io_addr          dd ?
-
 
Line 62... Line 37...
62
        .pci_bus          dd ?
37
section '.flat' readable writable executable
63
        .pci_dev          dd ?
38
 
64
        .irq_line         db ?
39
include '../proc32.inc'
65
 
40
include '../struct.inc'
Line 181... Line 156...
181
CSR7_AI                 = 1 shl 15      ; Abnormal Interrupt Summary Enable (enables CSR5<0,3,7,8,9,10,13>)
156
CSR7_AI                 = 1 shl 15      ; Abnormal Interrupt Summary Enable (enables CSR5<0,3,7,8,9,10,13>)
182
CSR7_NI                 = 1 shl 16      ; Normal Interrup Enable (enables CSR5<0,2,6,11,14>)
157
CSR7_NI                 = 1 shl 16      ; Normal Interrup Enable (enables CSR5<0,2,6,11,14>)
Line 183... Line 158...
183
 
158
 
184
CSR7_DEFAULT            = CSR7_TI + CSR7_TS + CSR7_RI + CSR7_RS + CSR7_TU + CSR7_TJ + CSR7_UN + \
159
CSR7_DEFAULT            = CSR7_TI + CSR7_TS + CSR7_RI + CSR7_RS + CSR7_TU + CSR7_TJ + CSR7_UN + \
185
                                        CSR7_RU + CSR7_RW + CSR7_FBE + CSR7_AI + CSR7_NI
-
 
186
 
-
 
187
;----------- descriptor structure ---------------------
-
 
188
struc   DES {
-
 
189
        .status         dd ?    ; bit 31 is 'own' and rest is 'status'
-
 
190
        .length         dd ?    ; control bits + bytes-count buffer 1 + bytes-count buffer 2
-
 
191
        .buffer1        dd ?    ; pointer to buffer1
-
 
192
        .buffer2        dd ?    ; pointer to buffer2 or in this case to next descriptor, as we use a chained structure
-
 
193
        .virtaddr       dd ?
-
 
194
        .size = 64              ; 64, for alignment purposes
-
 
195
}
-
 
196
 
-
 
197
virtual at 0
-
 
198
        DES DES
-
 
199
end virtual
-
 
200
 
160
                                        CSR7_RU + CSR7_RW + CSR7_FBE + CSR7_AI + CSR7_NI
201
;common to Rx and Tx
161
;common to Rx and Tx
Line 202... Line 162...
202
DES0_OWN                = 1 shl 31              ; if set, the NIC controls the descriptor, otherwise driver 'owns' the descriptors
162
DES0_OWN                = 1 shl 31              ; if set, the NIC controls the descriptor, otherwise driver 'owns' the descriptors
203
 
163
 
Line 255... Line 215...
255
TDES1_FT1               = 1 shl 28              ; Filtering type 1
215
TDES1_FT1               = 1 shl 28              ; Filtering type 1
256
TDES1_FS                = 1 shl 29              ; First segment - buffer is first segment of frame
216
TDES1_FS                = 1 shl 29              ; First segment - buffer is first segment of frame
257
TDES1_LS                = 1 shl 30              ; Last segment
217
TDES1_LS                = 1 shl 30              ; Last segment
258
TDES1_IC                = 1 shl 31              ; Interupt on completion (CSR5<0>=1) valid when TDES1<30>=1
218
TDES1_IC                = 1 shl 31              ; Interupt on completion (CSR5<0>=1) valid when TDES1<30>=1
Line -... Line 219...
-
 
219
 
259
 
220
RX_MEM_TOTAL_SIZE       = RX_DES_COUNT*(sizeof.DES+RX_BUFF_SIZE)
-
 
221
TX_MEM_TOTAL_SIZE       = TX_DES_COUNT*(sizeof.DES+TX_BUFF_SIZE)
Line -... Line 222...
-
 
222
 
-
 
223
 
-
 
224
struct  device          ETH_DEVICE
-
 
225
 
-
 
226
        rx_p_des        dd ?    ; descriptors ring with received packets
260
MAX_ETH_FRAME_SIZE      = 1514
227
        tx_p_des        dd ?    ; descriptors ring with 'to transmit' packets
261
 
228
        tx_free_des     dd ?    ; Tx descriptors available
-
 
229
        tx_wr_des       dd ?    ; Tx current descriptor to write data to
-
 
230
        tx_rd_des       dd ?    ; Tx current descriptor to read TX completion
-
 
231
        rx_crt_des      dd ?    ; Rx current descriptor
-
 
232
 
-
 
233
        io_addr         dd ?
-
 
234
        pci_bus         dd ?
-
 
235
        pci_dev         dd ?
-
 
236
        irq_line        db ?
-
 
237
 
-
 
238
ends
-
 
239
 
-
 
240
;----------- descriptor structure ---------------------
-
 
241
struct  DES
-
 
242
        status          dd ?    ; bit 31 is 'own' and rest is 'status'
-
 
243
        length          dd ?    ; control bits + bytes-count buffer 1 + bytes-count buffer 2
-
 
244
        buffer1         dd ?    ; pointer to buffer1
-
 
245
        buffer2         dd ?    ; pointer to buffer2 or in this case to next descriptor, as we use a chained structure
-
 
246
        virtaddr        dd ?
-
 
247
 
Line 262... Line 248...
262
RX_MEM_TOTAL_SIZE       = RX_DES_COUNT*(DES.size+RX_BUFF_SIZE)
248
        rb 0x40 - ($ and 0x3f)  ; align 64
263
TX_MEM_TOTAL_SIZE       = TX_DES_COUNT*(DES.size+TX_BUFF_SIZE)
249
ends
264
 
250
 
265
;=============================================================================
251
;=============================================================================
Line 306... Line 292...
306
        and     eax, not (a_bit)
292
        and     eax, not (a_bit)
307
        out     dx, eax
293
        out     dx, eax
308
}
294
}
Line 309... Line -...
309
 
-
 
310
 
-
 
311
section '.flat' code readable align 16
295
 
312
 
296
 
313
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
297
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
314
;;                        ;;
298
;;                        ;;
315
;; proc START             ;;
299
;; proc START             ;;
316
;;                        ;;
300
;;                        ;;
Line 317... Line -...
317
;; (standard driver proc) ;;
-
 
318
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
301
;; (standard driver proc) ;;
319
 
-
 
320
align 4
-
 
321
proc START stdcall, state:dword
-
 
Line -... Line 302...
-
 
302
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322
 
303
 
Line 323... Line 304...
323
        cmp [state], 1
304
proc START c, reason:dword, cmdline:dword
324
        jne .exit
305
 
325
 
306
        cmp     [reason], DRV_ENTRY
Line 326... Line 307...
326
  .entry:
307
        jne     .fail
327
 
-
 
328
        DEBUGF  2,"Loading %s driver\n", my_service
308
 
329
        stdcall RegService, my_service, service_proc
309
        DEBUGF  2,"Loading driver\n"
Line 330... Line 310...
330
        ret
310
        invoke  RegService, my_service, service_proc
Line 384... Line 364...
384
 
364
 
385
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
365
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
386
        mov     ax, [eax+1]                             ;
366
        mov     ax, [eax+1]                             ;
387
  .nextdevice:
367
  .nextdevice:
388
        mov     ebx, [esi]
368
        mov     ebx, [esi]
389
        cmp     al, byte[device.pci_bus]
369
        cmp     al, byte[ebx + device.pci_bus]
390
        jne     @f
370
        jne     @f
391
        cmp     ah, byte[device.pci_dev]
371
        cmp     ah, byte[ebx + device.pci_dev]
392
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
372
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
393
       @@:
373
       @@:
394
        add     esi, 4
374
        add     esi, 4
Line 399... Line 379...
399
  .firstdevice:
379
  .firstdevice:
400
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
380
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
401
        jae     .fail
381
        jae     .fail
Line 402... Line 382...
402
 
382
 
403
        push    edx
383
        push    edx
404
        stdcall KernelAlloc, dword device.size          ; Allocate the buffer for eth_device structure
384
        invoke  KernelAlloc, sizeof.device              ; Allocate the buffer for eth_device structure
405
        pop     edx
385
        pop     edx
406
        test    eax, eax
386
        test    eax, eax
407
        jz      .fail
387
        jz      .fail
Line 408... Line 388...
408
        mov     ebx, eax                                ; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
388
        mov     ebx, eax                                ; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
Line 409... Line 389...
409
 
389
 
410
; Fill in the direct call addresses into the struct
390
; Fill in the direct call addresses into the struct
411
 
391
 
412
        mov     [device.reset], reset
392
        mov     [ebx + device.reset], reset
Line 413... Line 393...
413
        mov     [device.transmit], transmit
393
        mov     [ebx + device.transmit], transmit
Line 414... Line 394...
414
        mov     [device.unload], unload
394
        mov     [ebx + device.unload], unload
415
        mov     [device.name], my_service
395
        mov     [ebx + device.name], my_service
416
 
396
 
417
; save the pci bus and device numbers
397
; save the pci bus and device numbers
418
 
398
 
Line 419... Line 399...
419
        mov     eax, [edx + IOCTL.input]
399
        mov     eax, [edx + IOCTL.input]
Line -... Line 400...
-
 
400
        movzx   ecx, byte[eax+1]
420
        movzx   ecx, byte[eax+1]
401
        mov     [ebx + device.pci_bus], ecx
Line 421... Line 402...
421
        mov     [device.pci_bus], ecx
402
        movzx   ecx, byte[eax+2]
Line -... Line 403...
-
 
403
        mov     [ebx + device.pci_dev], ecx
422
        movzx   ecx, byte[eax+2]
404
 
Line 423... Line 405...
423
        mov     [device.pci_dev], ecx
405
; Now, it's time to find the base io addres of the PCI device
424
 
406
 
Line 425... Line 407...
425
; Now, it's time to find the base io addres of the PCI device
407
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
426
 
408
        mov     [ebx + device.io_addr], eax
Line 427... Line 409...
427
        PCI_find_io
409
 
428
 
410
; We've found the io address, find IRQ now
429
; We've found the io address, find IRQ now
411
 
430
 
412
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
Line 445... Line 427...
445
        call    probe                                                   ; this function will output in eax
427
        call    probe                                                   ; this function will output in eax
446
        test    eax, eax
428
        test    eax, eax
447
        jnz     .err2                                                   ; If an error occured, exit
429
        jnz     .err2                                                   ; If an error occured, exit
Line 448... Line 430...
448
 
430
 
449
 
431
 
Line 450... Line 432...
450
        mov     [device.type], NET_TYPE_ETH
432
        mov     [ebx + device.type], NET_TYPE_ETH
451
        call    NetRegDev
433
        invoke  NetRegDev
Line 452... Line 434...
452
 
434
 
Line 453... Line 435...
453
        cmp     eax, -1
435
        cmp     eax, -1
Line 454... Line 436...
454
        je      .destroy
436
        je      .destroy
455
 
437
 
456
        ret
438
        ret
457
 
439
 
458
; If the device was already loaded, find the device number and return it in eax
440
; If the device was already loaded, find the device number and return it in eax
459
 
441
 
460
  .find_devicenum:
442
  .find_devicenum:
Line 472... Line 454...
472
 
454
 
473
  .err2:
455
  .err2:
474
        dec     [devices]
456
        dec     [devices]
475
  .err:
457
  .err:
476
        DEBUGF  2,"removing device structure\n"
458
        DEBUGF  2,"removing device structure\n"
477
        stdcall KernelFree, [device.rx_p_des]
459
        invoke  KernelFree, [ebx + device.rx_p_des]
478
        stdcall KernelFree, [device.tx_p_des]
460
        invoke  KernelFree, [ebx + device.tx_p_des]
Line 479... Line 461...
479
        stdcall KernelFree, ebx
461
        invoke  KernelFree, ebx
480
 
462
 
481
 
463
 
Line 509... Line 491...
509
 
491
 
Line 510... Line 492...
510
ret
492
ret
511
 
493
 
512
 
494
 
513
macro status {
495
macro status {
514
        set_io  CSR5
496
        set_io  [ebx + device.io_addr], CSR5
Line 526... Line 508...
526
align 4
508
align 4
527
probe:
509
probe:
Line 528... Line 510...
528
 
510
 
Line 529... Line 511...
529
        DEBUGF  2,"Probing dec21x4x device: "
511
        DEBUGF  2,"Probing dec21x4x device: "
-
 
512
 
-
 
513
; Make the device a bus master
-
 
514
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line -... Line 515...
-
 
515
        or      al, PCI_CMD_MASTER
530
 
516
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
531
        PCI_make_bus_master
517
 
Line 532... Line 518...
532
 
518
; Check the vendor/device ID
533
        stdcall PciRead32, [device.pci_bus], [device.pci_dev], 0                                ; get device/vendor id
519
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0                                ; get device/vendor id
534
        DEBUGF  1,"Vendor id: 0x%x\n", ax
520
        DEBUGF  1,"Vendor id: 0x%x\n", ax
Line 564... Line 550...
564
  .supported_device2:
550
  .supported_device2:
Line 565... Line 551...
565
 
551
 
Line 566... Line 552...
566
        ; wake up the 21143
552
        ; wake up the 21143
567
 
553
 
Line 568... Line 554...
568
        xor     eax, eax
554
        xor     eax, eax
569
        stdcall PciWrite32, [device.pci_bus], [device.pci_dev], 0x40, eax
555
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0x40, eax
570
 
556
 
Line 585... Line 571...
585
        DEBUGF  2,"Resetting dec21x4x\n"
571
        DEBUGF  2,"Resetting dec21x4x\n"
Line 586... Line 572...
586
 
572
 
587
;-----------------------------------------------------------
573
;-----------------------------------------------------------
Line 588... Line 574...
588
; board software reset - if fails, dont do nothing else
574
; board software reset - if fails, dont do nothing else
589
 
575
 
590
        set_io  0
576
        set_io  [ebx + device.io_addr], 0
591
        status
577
        status
592
        set_io  CSR0
578
        set_io  [ebx + device.io_addr], CSR0
Line 593... Line 579...
593
        mov     eax, CSR0_RESET
579
        mov     eax, CSR0_RESET
594
        out     dx, eax
580
        out     dx, eax
595
 
581
 
Line 596... Line 582...
596
; wait at least 50 PCI cycles
582
; wait at least 50 PCI cycles
597
        mov     esi, 1000
583
        mov     esi, 1000
Line 598... Line 584...
598
        call    Sleep
584
        invoke  Sleep
599
 
585
 
600
;-----------
586
;-----------
601
; setup CSR0
587
; setup CSR0
602
 
588
 
Line 603... Line 589...
603
        set_io  0
589
        set_io  [ebx + device.io_addr], 0
604
        status
590
        status
605
        set_io  CSR0
591
        set_io  [ebx + device.io_addr], CSR0
Line 606... Line 592...
606
        mov     eax, CSR0_DEFAULT
592
        mov     eax, CSR0_DEFAULT
607
        out     dx, eax
593
        out     dx, eax
Line 608... Line 594...
608
 
594
 
Line 609... Line 595...
609
 
595
 
610
; wait at least 50 PCI cycles
596
; wait at least 50 PCI cycles
Line 611... Line 597...
611
        mov     esi, 1000
597
        mov     esi, 1000
612
        call    Sleep
598
        invoke  Sleep
613
 
599
 
614
;-----------------------------------
600
;-----------------------------------
615
; Read mac from eeprom to driver ram
601
; Read mac from eeprom to driver ram
616
 
602
 
617
        call    read_mac_eeprom
603
        call    read_mac_eeprom
618
 
604
 
619
;--------------------------------
605
;--------------------------------
Line 620... Line 606...
620
; insert irq handler on given irq
606
; insert irq handler on given irq
621
 
607
 
Line 622... Line 608...
622
        movzx   eax, [device.irq_line]
608
        movzx   eax, [ebx + device.irq_line]
Line 623... Line 609...
623
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
609
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
624
        stdcall AttachIntHandler, eax, int_handler, dword 0
610
        invoke  AttachIntHandler, eax, int_handler, ebx
Line 625... Line 611...
625
        test    eax, eax
611
        test    eax, eax
626
        jnz     @f
612
        jnz     @f
627
        DEBUGF  2,"Could not attach int handler!\n"
613
        DEBUGF  2,"Could not attach int handler!\n"
628
;        or      eax, -1
614
        or      eax, -1
629
;        ret
615
        ret
630
  @@:
616
  @@:
631
 
617
 
Line 632... Line 618...
632
        set_io  0
618
        set_io  [ebx + device.io_addr], 0
633
        status
619
        status
634
 
620
 
635
        call    init_ring
621
        call    init_ring
636
 
622
 
Line 637... Line 623...
637
;--------------------------------------------
623
;--------------------------------------------
638
; setup CSR3 & CSR4 (pointers to descriptors)
624
; setup CSR3 & CSR4 (pointers to descriptors)
Line 639... Line 625...
639
 
625
 
640
        set_io  0
626
        set_io  [ebx + device.io_addr], 0
641
        status
627
        status
642
        set_io  CSR3
628
        set_io  [ebx + device.io_addr], CSR3
643
        mov     eax, [device.rx_p_des]
629
        mov     eax, [ebx + device.rx_p_des]
644
        GetRealAddr
630
        invoke  GetPhysAddr
Line 645... Line 631...
645
        DEBUGF  1,"RX descriptor base address: %x\n", eax
631
        DEBUGF  1,"RX descriptor base address: %x\n", eax
646
        out     dx, eax
632
        out     dx, eax
Line 647... Line 633...
647
 
633
 
648
        set_io  CSR4
634
        set_io  [ebx + device.io_addr], CSR4
649
        mov     eax, [device.tx_p_des]
635
        mov     eax, [ebx + device.tx_p_des]
Line 650... Line 636...
650
        GetRealAddr
636
        invoke  GetPhysAddr
651
        DEBUGF  1,"TX descriptor base address: %x\n", eax
637
        DEBUGF  1,"TX descriptor base address: %x\n", eax
652
        out     dx, eax
638
        out     dx, eax
Line 653... Line 639...
653
 
639
 
Line 654... Line 640...
654
;-------------------------------------------------------
640
;-------------------------------------------------------
Line 655... Line 641...
655
; setup interrupt mask register -expect IRQs from now on
641
; setup interrupt mask register -expect IRQs from now on
656
 
642
 
657
        status
643
        status
Line 658... Line 644...
658
        DEBUGF  1,"Enabling interrupts\n"
644
        DEBUGF  1,"Enabling interrupts\n"
659
        set_io  CSR7
645
        set_io  [ebx + device.io_addr], CSR7
Line 660... Line 646...
660
        mov     eax, CSR7_DEFAULT
646
        mov     eax, CSR7_DEFAULT
Line 661... Line 647...
661
        out     dx, eax
647
        out     dx, eax
662
        status
648
        status
Line 663... Line 649...
663
 
649
 
664
;----------
650
;----------
665
; enable RX
651
; enable RX
Line 666... Line 652...
666
 
652
 
667
        set_io  0
653
        set_io  [ebx + device.io_addr], 0
Line 668... Line 654...
668
        status
654
        status
669
        DEBUGF  1,"Enable RX\n"
655
        DEBUGF  1,"Enable RX\n"
Line 670... Line 656...
670
 
656
 
Line 671... Line 657...
671
        set_io  CSR6
657
        set_io  [ebx + device.io_addr], CSR6
Line 708... Line 694...
708
init_ring:
694
init_ring:
Line 709... Line 695...
709
 
695
 
710
;------------------------------------------
696
;------------------------------------------
Line 711... Line 697...
711
; Setup RX descriptors (use chained method)
697
; Setup RX descriptors (use chained method)
712
 
698
 
713
        mov     eax, [device.rx_p_des]
699
        mov     eax, [ebx + device.rx_p_des]
714
        GetRealAddr
700
        invoke  GetPhysAddr
715
        mov     edx, eax
701
        mov     edx, eax
716
        push    eax
702
        push    eax
717
        lea     esi, [eax + RX_DES_COUNT*(DES.size)]    ; jump over RX descriptors
703
        lea     esi, [eax + RX_DES_COUNT*(sizeof.DES)]  ; jump over RX descriptors
718
        mov     eax, [device.rx_p_des]
704
        mov     eax, [ebx + device.rx_p_des]
719
        add     eax, RX_DES_COUNT*(DES.size)            ; jump over RX descriptors
705
        add     eax, RX_DES_COUNT*(sizeof.DES)          ; jump over RX descriptors
720
        mov     edi, [device.rx_p_des]
706
        mov     edi, [ebx + device.rx_p_des]
721
        mov     ecx, RX_DES_COUNT
707
        mov     ecx, RX_DES_COUNT
722
  .loop_rx_des:
708
  .loop_rx_des:
723
        add     edx, DES.size
709
        add     edx, sizeof.DES
724
        mov     [edi + DES.status], DES0_OWN            ; hardware owns buffer
710
        mov     [edi + DES.status], DES0_OWN            ; hardware owns buffer
725
        mov     [edi + DES.length], 1984 + RDES1_RCH    ; only size of first buffer, chained buffers
711
        mov     [edi + DES.length], 1984 + RDES1_RCH    ; only size of first buffer, chained buffers
726
        mov     [edi + DES.buffer1], esi                ; hw buffer address
712
        mov     [edi + DES.buffer1], esi                ; hw buffer address
727
        mov     [edi + DES.buffer2], edx                ; pointer to next descriptor
713
        mov     [edi + DES.buffer2], edx                ; pointer to next descriptor
Line 728... Line 714...
728
        mov     [edi + DES.virtaddr], eax               ; virtual buffer address
714
        mov     [edi + DES.virtaddr], eax               ; virtual buffer address
729
        DEBUGF  1,"RX desc: buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", esi, edx, eax, edi
715
        DEBUGF  1,"RX desc: buff addr: %x, next desc: %x, real buff addr: %x, real descr addr: %x \n", esi, edx, eax, edi
730
 
716
 
731
        add     esi, RX_BUFF_SIZE
717
        add     esi, RX_BUFF_SIZE
732
        add     eax, RX_BUFF_SIZE
718
        add     eax, RX_BUFF_SIZE
Line 733... Line 719...
733
        add     edi, DES.size
719
        add     edi, sizeof.DES
734
        dec     ecx
-
 
735
        jnz     .loop_rx_des
720
        dec     ecx
736
 
721
        jnz     .loop_rx_des
Line 737... Line 722...
737
; set last descriptor as LAST
722
 
738
        sub     edi, DES.size
723
; set last descriptor as LAST
Line 739... Line 724...
739
        or      [edi + DES.length], RDES1_RER           ; EndOfRing
724
        or      [edi - sizeof.DES + DES.length], RDES1_RER      ; EndOfRing
740
        pop     [edi + DES.buffer2]                     ; point it to the first descriptor
725
        pop     [edi - sizeof.DES + DES.buffer2]                ; point it to the first descriptor
741
 
726
 
742
;---------------------
727
;---------------------
743
; Setup TX descriptors
728
; Setup TX descriptors
744
 
729
 
745
        mov     eax, [device.tx_p_des]
730
        mov     eax, [ebx + device.tx_p_des]
746
        GetRealAddr
731
        invoke  GetPhysAddr
747
        mov     edx, eax
732
        mov     edx, eax
748
        push    eax
733
        push    eax
749
        lea     esi, [eax + TX_DES_COUNT*(DES.size)]    ; jump over TX descriptors
734
        lea     esi, [eax + TX_DES_COUNT*(sizeof.DES)]  ; jump over TX descriptors
750
        mov     eax, [device.tx_p_des]
735
        mov     eax, [ebx + device.tx_p_des]
751
        add     eax, TX_DES_COUNT*(DES.size)            ; jump over TX descriptors
736
        add     eax, TX_DES_COUNT*(sizeof.DES)          ; jump over TX descriptors
752
        mov     edi, [device.tx_p_des]
737
        mov     edi, [ebx + device.tx_p_des]
753
        mov     ecx, TX_DES_COUNT
738
        mov     ecx, TX_DES_COUNT
754
  .loop_tx_des:
739
  .loop_tx_des:
755
        add     edx, DES.size
740
        add     edx, sizeof.DES
Line 756... Line 741...
756
        mov     [edi + DES.status], 0                   ; owned by driver
741
        mov     [edi + DES.status], 0                   ; owned by driver
757
        mov     [edi + DES.length], TDES1_TCH           ; chained method
742
        mov     [edi + DES.length], TDES1_TCH           ; chained method
758
        mov     [edi + DES.buffer1], esi                ; pointer to buffer
743
        mov     [edi + DES.buffer1], esi                ; pointer to buffer
759
        mov     [edi + DES.buffer2], edx                ; pointer to next descr
744
        mov     [edi + DES.buffer2], edx                ; pointer to next descr
760
        mov     [edi + DES.virtaddr], eax
745
        mov     [edi + DES.virtaddr], eax
Line 761... Line 746...
761
        DEBUGF  1,"TX desc: buff addr: %x, next desc: %x, virt buff addr: %x, virt descr addr: %x \n", esi, edx, eax, edi
746
        DEBUGF  1,"TX desc: buff addr: %x, next desc: %x, virt buff addr: %x, virt descr addr: %x \n", esi, edx, eax, edi
762
 
-
 
763
        add     esi, TX_BUFF_SIZE
747
 
764
        add     eax, TX_BUFF_SIZE
748
        add     esi, TX_BUFF_SIZE
Line 765... Line 749...
765
        add     edi, DES.size
749
        add     eax, TX_BUFF_SIZE
766
        dec     ecx
750
        add     edi, sizeof.DES
Line 767... Line 751...
767
        jnz     .loop_tx_des
751
        dec     ecx
768
        
752
        jnz     .loop_tx_des
769
; set last descriptor as LAST
753
        
770
        sub     edi, DES.size
754
; set last descriptor as LAST
Line 771... Line 755...
771
        or      [edi + DES.length], TDES1_TER           ; EndOfRing
755
        or      [edi - sizeof.DES + DES.length], TDES1_TER      ; EndOfRing
Line 772... Line 756...
772
        pop     [edi + DES.buffer2]                     ; point it to the first descriptor
756
        pop     [edi - sizeof.DES + DES.buffer2]                ; point it to the first descriptor
Line 803... Line 787...
803
        DEBUGF  1,"Sending setup packet\n"
787
        DEBUGF  1,"Sending setup packet\n"
Line 804... Line 788...
804
 
788
 
805
; if no descriptors available, out
789
; if no descriptors available, out
806
        mov     ecx, 1000
790
        mov     ecx, 1000
807
@@loop_wait_desc:
791
@@loop_wait_desc:
808
        cmp     [device.tx_free_des], 0
792
        cmp     [ebx + device.tx_free_des], 0
Line 809... Line 793...
809
        jne     @f
793
        jne     @f
810
 
794
 
Line 811... Line 795...
811
        dec     ecx
795
        dec     ecx
812
        jnz     @@loop_wait_desc
796
        jnz     @@loop_wait_desc
813
 
797
 
Line 814... Line 798...
814
        mov     eax, -1
798
        mov     eax, -1
815
        ret
799
        ret
816
      @@:
800
      @@:
817
 
801
 
818
; go to current send descriptor
802
; go to current send descriptor
819
        mov     edi, [device.tx_p_des]
803
        mov     edi, [ebx + device.tx_p_des]
820
        mov     eax, [device.tx_wr_des]
804
        mov     eax, [ebx + device.tx_wr_des]
821
        DEBUGF  1,"Got free descriptor: %u (%x)", eax, edi
805
        DEBUGF  1,"Got free descriptor: %u (%x)", eax, edi
Line 822... Line 806...
822
        mov     edx, DES.size
806
        mov     edx, sizeof.DES
823
        mul     edx
807
        mul     edx
Line 824... Line 808...
824
        add     edi, eax
808
        add     edi, eax
825
        DEBUGF  1,"=>%x\n",  edi
809
        DEBUGF  1,"=>%x\n",  edi
826
 
810
 
827
; if NOT sending FIRST setup packet, must set current descriptor to 0 size for both buffers,
811
; if NOT sending FIRST setup packet, must set current descriptor to 0 size for both buffers,
828
;  and go to next descriptor for real setup packet...            ;; TODO: check if 2 descriptors are available
812
;  and go to next descriptor for real setup packet...            ;; TODO: check if 2 descriptors are available
829
 
813
 
830
;       cmp     [device.tx_packets], 0
814
;       cmp     [ebx + device.tx_packets], 0
831
;       je      .first
815
;       je      .first
832
;               
816
;               
833
;       and     [edi+DES.des1], 0
817
;       and     [edi+DES.des1], 0
834
;       mov     [edi+DES.des0], DES0_OWN
818
;       mov     [edi+DES.des0], DES0_OWN
835
;               
819
;               
836
; go to next descriptor
820
; go to next descriptor
837
;        inc     [device.tx_wr_des]
821
;        inc     [ebx + device.tx_wr_des]
838
;        and     [device.tx_wr_des], TX_DES_COUNT-1
822
;        and     [ebx + device.tx_wr_des], TX_DES_COUNT-1
839
;
823
;
840
; dec free descriptors count
824
; dec free descriptors count
841
;        cmp     [device.tx_free_des], 0
825
;        cmp     [ebx + device.tx_free_des], 0
842
;        jz      @f
826
;        jz      @f
843
;        dec     [device.tx_free_des]
827
;        dec     [ebx + device.tx_free_des]
844
;       @@:
828
;       @@:
845
;
829
;
Line 846... Line 830...
846
;       ; recompute pointer to current descriptor
830
;       ; recompute pointer to current descriptor
Line 847... Line 831...
847
;       mov     edi, [device.tx_p_des]
831
;       mov     edi, [ebx + device.tx_p_des]
848
;       mov     eax, [device.tx_wr_des]
832
;       mov     eax, [ebx + device.tx_wr_des]
849
;       mov     edx, DES.size
833
;       mov     edx, DES.size
850
;       mul     edx
834
;       mul     edx
851
;       add     edi, eax
835
;       add     edi, eax
852
 
836
 
853
  .first:
837
  .first:
854
 
838
 
855
        push    edi
839
        push    edi
856
; copy setup packet to current descriptor
840
; copy setup packet to current descriptor
Line 885... Line 869...
885
        DEBUGF  1,"length: %x\n", [edi + DES.length]:8
869
        DEBUGF  1,"length: %x\n", [edi + DES.length]:8
886
        DEBUGF  1,"buffer1: %x\n", [edi + DES.buffer1]:8
870
        DEBUGF  1,"buffer1: %x\n", [edi + DES.buffer1]:8
887
        DEBUGF  1,"buffer2: %x\n", [edi + DES.buffer2]:8
871
        DEBUGF  1,"buffer2: %x\n", [edi + DES.buffer2]:8
Line 888... Line 872...
888
 
872
 
889
; go to next descriptor
873
; go to next descriptor
890
        inc     [device.tx_wr_des]
874
        inc     [ebx + device.tx_wr_des]
Line 891... Line 875...
891
        and     [device.tx_wr_des], TX_DES_COUNT-1
875
        and     [ebx + device.tx_wr_des], TX_DES_COUNT-1
892
 
876
 
893
; dec free descriptors count
877
; dec free descriptors count
894
        cmp     [device.tx_free_des], 0
878
        cmp     [ebx + device.tx_free_des], 0
895
        jz      @f
879
        jz      @f
Line 896... Line 880...
896
        dec     [device.tx_free_des]
880
        dec     [ebx + device.tx_free_des]
897
       @@:
881
       @@:
898
 
882
 
899
; start tx
883
; start tx
900
        set_io  0
884
        set_io  [ebx + device.io_addr], 0
901
        status
885
        status
902
        set_io  CSR6
886
        set_io  [ebx + device.io_addr], CSR6
903
        in      eax, dx
887
        in      eax, dx
904
        test    eax, CSR6_ST            ; if NOT started, start now
888
        test    eax, CSR6_ST            ; if NOT started, start now
905
        jnz     .already_started
889
        jnz     .already_started
906
        or      eax, CSR6_ST
890
        or      eax, CSR6_ST
907
        DEBUGF  1,"Starting TX\n"
891
        DEBUGF  1,"Starting TX\n"
908
        jmp     .do_it
892
        jmp     .do_it
909
  .already_started:
893
  .already_started:
910
                                        ; if already started, issue a Transmit Poll command
894
                                        ; if already started, issue a Transmit Poll command
911
        set_io  CSR1
895
        set_io  [ebx + device.io_addr], CSR1
912
        xor     eax, eax
896
        xor     eax, eax
913
        DEBUGF  1,"Issuing transmit poll command\n"
897
        DEBUGF  1,"Issuing transmit poll command\n"
Line 929... Line 913...
929
;;     size of buffer in [esp+8]           ;;
913
;;     size of buffer in [esp+8]           ;;
930
;;     pointer to device structure in ebx  ;;
914
;;     pointer to device structure in ebx  ;;
931
;;                                         ;;
915
;;                                         ;;
932
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
916
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line -... Line 917...
-
 
917
 
-
 
918
proc transmit stdcall bufferptr, buffersize
933
 
919
 
934
align 4
920
        pushf
Line 935... Line 921...
935
transmit:
921
        cli
936
 
922
 
937
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
923
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
938
        mov     eax, [esp+4]
924
        mov     eax, [bufferptr]
939
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
925
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
940
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
926
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 941... Line 927...
941
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
927
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
942
        [eax+13]:2,[eax+12]:2
928
        [eax+13]:2,[eax+12]:2
943
 
-
 
944
        cmp     dword [esp+8], MAX_ETH_FRAME_SIZE
929
 
945
        ja      .fail
930
        cmp     [buffersize], 1514
Line 946... Line 931...
946
 
931
        ja      .fail
947
        cmp     [device.tx_free_des], 0
932
        cmp     [buffersize], 60
Line 948... Line 933...
948
        je      .fail
933
        jb      .fail
949
 
934
 
950
;--------------------------
935
;--------------------------
951
; copy packet to crt buffer
936
; copy packet to crt buffer
952
        
937
        
953
        mov     eax, [device.tx_wr_des]
938
        mov     eax, [ebx + device.tx_wr_des]
954
        mov     edx, DES.size
939
        mov     edx, sizeof.DES
955
        mul     edx
940
        mul     edx
956
        add     eax, [device.tx_p_des]
941
        add     eax, [ebx + device.tx_p_des]
Line 957... Line 942...
957
        mov     edi, [eax + DES.virtaddr]                 ; pointer to buffer
942
        mov     edi, [eax + DES.virtaddr]               ; pointer to buffer
958
        mov     esi, [esp+4]
943
        mov     esi, [bufferptr]
959
        mov     ecx, [esp+8]
944
        mov     ecx, [buffersize]
960
        DEBUGF  1,"copying %u bytes from %x to %x\n", ecx, esi, edi
945
        DEBUGF  1,"copying %u bytes from %x to %x\n", ecx, esi, edi
961
        rep     movsb
946
        rep     movsb
962
 
947
 
Line 963... Line 948...
963
; set packet size
948
; set packet size
964
        mov     ecx, [eax+DES.length]
949
        mov     ecx, [eax+DES.length]
Line 965... Line 950...
965
        and     ecx, TDES1_TER                          ; preserve 'End of Ring' bit
950
        and     ecx, TDES1_TER                          ; preserve 'End of Ring' bit
966
        or      ecx, [esp+8]                            ; set size
951
        or      ecx, [buffersize]                       ; set size
967
        or      ecx, TDES1_FS or TDES1_LS or TDES1_IC or TDES1_TCH    ; first descr, last descr, interrupt on complete, chained modus
952
        or      ecx, TDES1_FS or TDES1_LS or TDES1_IC or TDES1_TCH    ; first descr, last descr, interrupt on complete, chained modus
968
        mov     [eax+DES.length], ecx
953
        mov     [eax + DES.length], ecx
969
 
954
 
970
; set descriptor info
955
; set descriptor info
971
        mov     [eax+DES.status], DES0_OWN                ; say it is now owned by the 21x4x
956
        mov     [eax + DES.status], DES0_OWN            ; say it is now owned by the 21x4x
972
 
957
 
973
; start tx
958
; start tx
974
        set_io  0
959
        set_io  [ebx + device.io_addr], 0
975
        status
960
        status
976
        set_io  CSR6
961
        set_io  [ebx + device.io_addr], CSR6
977
        in      eax, dx
962
        in      eax, dx
978
        test    eax, CSR6_ST            ; if NOT started, start now
963
        test    eax, CSR6_ST            ; if NOT started, start now
979
        jnz     .already_started
964
        jnz     .already_started
980
        or      eax, CSR6_ST
965
        or      eax, CSR6_ST
Line 981... Line 966...
981
        DEBUGF  1,"Starting TX\n"
966
        DEBUGF  1,"Starting TX\n"
982
        jmp     .do_it
-
 
983
  .already_started:
967
        jmp     .do_it
984
                                        ; if already started, issues a Transmit Poll command
968
  .already_started:
985
        set_io  CSR1
969
                                        ; if already started, issues a Transmit Poll command
986
        mov     eax, -1
970
        set_io  [ebx + device.io_addr], CSR1
Line 987... Line 971...
987
  .do_it:
971
        mov     eax, -1
988
        out     dx , eax
972
  .do_it:
989
 
973
        out     dx , eax
Line 990... Line 974...
990
; Update stats
974
 
991
 
975
; Update stats
992
        inc     [device.packets_tx]
976
        inc     [ebx + device.packets_tx]
993
        mov     eax, [esp+8]
977
        mov     eax, [buffersize]
994
        add     dword [device.bytes_tx], eax
978
        add     dword [ebx + device.bytes_tx], eax
995
        adc     dword [device.bytes_tx + 4], 0
979
        adc     dword [ebx + device.bytes_tx + 4], 0
Line 996... Line 980...
996
 
980
 
-
 
981
; go to next descriptor
-
 
982
        inc     [ebx + device.tx_wr_des]
997
; go to next descriptor
983
        and     [ebx + device.tx_wr_des], TX_DES_COUNT-1
998
        inc     [device.tx_wr_des]
-
 
999
        and     [device.tx_wr_des], TX_DES_COUNT-1
984
 
Line 1000... Line 985...
1000
 
985
; dec free descriptors count
1001
; dec free descriptors count
986
        test    [ebx + device.tx_free_des], -1
1002
        test    [device.tx_free_des], -1
987
        jz      .end
-
 
988
        dec     [ebx + device.tx_free_des]
1003
        jz      .end
989
  .end:
1004
        dec     [device.tx_free_des]
990
        status
Line -... Line 991...
-
 
991
 
Line 1005... Line 992...
1005
  .end:
992
        DEBUGF  1,"transmit ok\n"
1006
        status
993
        invoke  KernelFree, [bufferptr]
1007
 
994
        popf
1008
        DEBUGF  1,"transmit ok\n"
995
        xor     eax, eax
Line 1037... Line 1024...
1037
        jz      .nothing
1024
        jz      .nothing
1038
        mov     esi, device_list
1025
        mov     esi, device_list
1039
  .nextdevice:
1026
  .nextdevice:
1040
        mov     ebx, [esi]
1027
        mov     ebx, [esi]
Line 1041... Line 1028...
1041
 
1028
 
1042
        set_io  0
1029
        set_io  [ebx + device.io_addr], 0
1043
        set_io  CSR5
1030
        set_io  [ebx + device.io_addr], CSR5
1044
        in      ax, dx
1031
        in      ax, dx
1045
        test    ax, ax
1032
        test    ax, ax
1046
        out     dx, ax                                  ; send it back to ACK
1033
        out     dx, ax                                  ; send it back to ACK
1047
        jnz     .got_it
1034
        jnz     .got_it
Line 1067... Line 1054...
1067
        push    ax esi ecx
1054
        push    ax esi ecx
Line 1068... Line 1055...
1068
 
1055
 
Line 1069... Line 1056...
1069
        DEBUGF 1,"TX ok!\n"
1056
        DEBUGF 1,"TX ok!\n"
1070
                
1057
                
Line 1071... Line 1058...
1071
        ; go to current descriptor
1058
        ; go to current descriptor
1072
        mov     edi, [device.tx_p_des]
1059
        mov     edi, [ebx + device.tx_p_des]
1073
 
1060
 
1074
        mov     eax, [device.tx_rd_des]
1061
        mov     eax, [ebx + device.tx_rd_des]
Line 1075... Line 1062...
1075
        mov     edx, DES.size
1062
        mov     edx, sizeof.DES
Line 1076... Line 1063...
1076
        mul     edx
1063
        mul     edx
1077
        add     edi, eax
1064
        add     edi, eax
1078
                
1065
                
Line 1079... Line 1066...
1079
      .loop_tx:
1066
      .loop_tx:
Line 1080... Line 1067...
1080
                
1067
                
Line 1095... Line 1082...
1095
      .not_setup_packet:
1082
      .not_setup_packet:
Line 1096... Line 1083...
1096
 
1083
 
Line 1097... Line 1084...
1097
        DEBUGF  1,"packet status: %x\n", eax
1084
        DEBUGF  1,"packet status: %x\n", eax
1098
 
1085
 
1099
        ; next descriptor
1086
        ; next descriptor
1100
        add     edi, DES.size
1087
        add     edi, sizeof.DES
Line 1101... Line 1088...
1101
        inc     [device.tx_rd_des]
1088
        inc     [ebx + device.tx_rd_des]
1102
        and     [device.tx_rd_des], TX_DES_COUNT-1
1089
        and     [ebx + device.tx_rd_des], TX_DES_COUNT-1
1103
 
1090
 
1104
        ; inc free desc
1091
        ; inc free desc
1105
        inc     [device.tx_free_des]
1092
        inc     [ebx + device.tx_free_des]
1106
        cmp     [device.tx_free_des], TX_DES_COUNT
1093
        cmp     [ebx + device.tx_free_des], TX_DES_COUNT
Line 1107... Line 1094...
1107
        jbe     @f
1094
        jbe     @f
1108
        mov     [device.tx_free_des], TX_DES_COUNT
1095
        mov     [ebx + device.tx_free_des], TX_DES_COUNT
Line 1129... Line 1116...
1129
        push    ebx
1116
        push    ebx
1130
  .rx_loop:
1117
  .rx_loop:
1131
        pop     ebx
1118
        pop     ebx
Line 1132... Line 1119...
1132
 
1119
 
1133
        ; get current descriptor
1120
        ; get current descriptor
1134
        mov     edi, [device.rx_p_des]
1121
        mov     edi, [ebx + device.rx_p_des]
1135
        mov     eax, [device.rx_crt_des]
1122
        mov     eax, [ebx + device.rx_crt_des]
1136
        mov     edx, DES.size
1123
        mov     edx, sizeof.DES
1137
        mul     edx
1124
        mul     edx
Line 1138... Line 1125...
1138
        add     edi, eax
1125
        add     edi, eax
1139
 
1126
 
Line 1159... Line 1146...
1159
        sub     ecx, 4                                  ; crc, we dont need it
1146
        sub     ecx, 4                                  ; crc, we dont need it
Line 1160... Line 1147...
1160
 
1147
 
Line 1161... Line 1148...
1161
        DEBUGF  1,"Received packet!, size=%u, addr:%x\n", ecx, esi
1148
        DEBUGF  1,"Received packet!, size=%u, addr:%x\n", ecx, esi
1162
 
1149
 
1163
        push    esi edi ecx
1150
        push    esi edi ecx
1164
        stdcall KernelAlloc, ecx                        ; Allocate a buffer to put packet into
1151
        invoke  KernelAlloc, ecx                        ; Allocate a buffer to put packet into
1165
        pop     ecx edi esi
1152
        pop     ecx edi esi
Line 1166... Line 1153...
1166
        test    eax, eax
1153
        test    eax, eax
1167
        jz      .fail
1154
        jz      .fail
1168
 
1155
 
1169
        push    ebx
1156
        push    ebx
Line 1170... Line 1157...
1170
        push    dword .rx_loop
1157
        push    dword .rx_loop
1171
        push    ecx eax
1158
        push    ecx eax
1172
        mov     edi, eax
1159
        mov     edi, eax
1173
 
1160
 
Line 1174... Line 1161...
1174
; update statistics
1161
; update statistics
1175
        inc     [device.packets_rx]
1162
        inc     [ebx + device.packets_rx]
1176
        add     dword [device.bytes_rx], ecx
1163
        add     dword [ebx + device.bytes_rx], ecx
1177
        adc     dword [device.bytes_rx + 4], 0
1164
        adc     dword [ebx + device.bytes_rx + 4], 0
Line 1187... Line 1174...
1187
  .nw:
1174
  .nw:
1188
        rep     movsd
1175
        rep     movsd
Line 1189... Line 1176...
1189
 
1176
 
Line 1190... Line 1177...
1190
        mov     [edi + DES.status], DES0_OWN            ; free descriptor
1177
        mov     [edi + DES.status], DES0_OWN            ; free descriptor
1191
                
1178
                
Line 1192... Line 1179...
1192
        inc     [device.rx_crt_des]                     ; next descriptor
1179
        inc     [ebx + device.rx_crt_des]                     ; next descriptor
Line 1193... Line 1180...
1193
        and     [device.rx_crt_des], RX_DES_COUNT-1
1180
        and     [ebx + device.rx_crt_des], RX_DES_COUNT-1
1194
 
1181
 
1195
        jmp     Eth_input
1182
        jmp     [Eth_input]
1196
 
1183
 
Line 1209... Line 1196...
1209
 
1196
 
Line 1210... Line 1197...
1210
        DEBUGF  2,"Writing MAC: "
1197
        DEBUGF  2,"Writing MAC: "
1211
 
1198
 
1212
; write data into driver cache
1199
; write data into driver cache
1213
        mov     esi, esp
1200
        mov     esi, esp
1214
        lea     edi, [device.mac]
1201
        lea     edi, [ebx + device.mac]
1215
        movsd
1202
        movsd
Line 1216... Line 1203...
1216
        movsw
1203
        movsw
Line 1231... Line 1218...
1231
align 4
1218
align 4
1232
read_mac_eeprom:
1219
read_mac_eeprom:
Line 1233... Line 1220...
1233
 
1220
 
Line 1234... Line 1221...
1234
        DEBUGF 1,"Read_mac_eeprom\n"
1221
        DEBUGF 1,"Read_mac_eeprom\n"
1235
 
1222
 
1236
        lea     edi, [device.mac]
1223
        lea     edi, [ebx + device.mac]
1237
        mov     esi, 20/2               ; read words, start address is 20
1224
        mov     esi, 20/2               ; read words, start address is 20
1238
     .loop:
1225
     .loop:
1239
        push    esi edi
1226
        push    esi edi
Line 1262... Line 1249...
1262
        DEBUGF 1,"SROM_GetWidth\n"
1249
        DEBUGF 1,"SROM_GetWidth\n"
Line 1263... Line 1250...
1263
 
1250
 
1264
        call    SROM_Idle
1251
        call    SROM_Idle
Line 1265... Line 1252...
1265
        call    SROM_EnterAccessMode
1252
        call    SROM_EnterAccessMode
1266
 
1253
 
Line 1267... Line 1254...
1267
;        set_io  0
1254
;        set_io  [ebx + device.io_addr], 0
Line 1268... Line 1255...
1268
;        set_io  CSR9
1255
;        set_io  [ebx + device.io_addr], CSR9
1269
 
1256
 
Line 1329... Line 1316...
1329
align 4
1316
align 4
1330
SROM_EnterAccessMode:
1317
SROM_EnterAccessMode:
Line 1331... Line 1318...
1331
 
1318
 
Line 1332... Line 1319...
1332
        DEBUGF 1,"SROM_EnterAccessMode\n"
1319
        DEBUGF 1,"SROM_EnterAccessMode\n"
1333
 
1320
 
1334
        set_io  0
1321
        set_io  [ebx + device.io_addr], 0
1335
        set_io  CSR9
1322
        set_io  [ebx + device.io_addr], CSR9
1336
        mov     eax, CSR9_SR
1323
        mov     eax, CSR9_SR
Line 1337... Line 1324...
1337
        out     dx, eax
1324
        out     dx, eax
Line 1355... Line 1342...
1355
 
1342
 
Line 1356... Line 1343...
1356
        DEBUGF 1,"SROM_Idle\n"
1343
        DEBUGF 1,"SROM_Idle\n"
Line 1357... Line 1344...
1357
 
1344
 
1358
        call    SROM_EnterAccessMode
1345
        call    SROM_EnterAccessMode
Line 1359... Line 1346...
1359
        
1346
        
1360
;        set_io  0
1347
;        set_io  [ebx + device.io_addr], 0
Line 1361... Line 1348...
1361
;        set_io  CSR9
1348
;        set_io  [ebx + device.io_addr], CSR9
Line 1394... Line 1381...
1394
align 4
1381
align 4
1395
SROM_Read_Word:
1382
SROM_Read_Word:
Line 1396... Line 1383...
1396
 
1383
 
Line 1397... Line 1384...
1397
        DEBUGF 1,"SROM_Read_word at: %x result: ", esi
1384
        DEBUGF 1,"SROM_Read_word at: %x result: ", esi
1398
 
1385
 
Line 1399... Line 1386...
1399
        set_io  0
1386
        set_io  [ebx + device.io_addr], 0
1400
        set_io  CSR9
1387
        set_io  [ebx + device.io_addr], CSR9
1401
 
1388
 
1402
; enter access mode
1389
; enter access mode
Line 1502... Line 1489...
1502
 
1489
 
1503
        shl     edx, 5
1490
        shl     edx, 5
1504
        or      esi, edx
1491
        or      esi, edx
Line 1505... Line 1492...
1505
        or      esi, 0xf6 shl 10
1492
        or      esi, 0xf6 shl 10
1506
 
1493
 
Line 1507... Line 1494...
1507
        set_io  0
1494
        set_io  [ebx + device.io_addr], 0
1508
        set_io  CSR9
1495
        set_io  [ebx + device.io_addr], CSR9
1509
 
1496
 
1510
;    if (tp->chip_id == LC82C168) {
1497
;    if (tp->chip_id == LC82C168) {
Line 1608... Line 1595...
1608
        or      edi, 0x5002 shl 16
1595
        or      edi, 0x5002 shl 16
1609
        shl     edx, 23
1596
        shl     edx, 23
1610
        or      edi, edx
1597
        or      edi, edx
1611
        mov     di, ax
1598
        mov     di, ax
Line 1612... Line 1599...
1612
 
1599
 
1613
        set_io  0
1600
        set_io  [ebx + device.io_addr], 0
Line 1614... Line 1601...
1614
        set_io  CSR9
1601
        set_io  [ebx + device.io_addr], CSR9
1615
 
1602
 
1616
;    if (tp->chip_id == LC82C168) {
1603
;    if (tp->chip_id == LC82C168) {
1617
;        int i = 1000;
1604
;        int i = 1000;
Line 1689... Line 1676...
1689
 
1676
 
Line 1690... Line 1677...
1690
        ret
1677
        ret
1691
 
-
 
Line 1692... Line 1678...
1692
 
1678
 
-
 
1679
 
-
 
1680
; End of code
1693
; End of code
1681
 
-
 
1682
data fixups
1694
align 4                                         ; Place all initialised data here
1683
end data
Line 1695... Line 1684...
1695
 
1684
 
Line 1696... Line -...
1696
devices       dd 0
-
 
1697
version       dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1685
include '../peimport.inc'
-
 
1686
 
1698
my_service    db 'DEC21X4X',0                    ; max 16 chars include zero
1687
my_service    db 'DEC21X4X',0                    ; max 16 chars include zero
Line 1699... Line -...
1699
 
-