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 5045
Line 13... Line 13...
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;             Version 2, June 1991                                ;;
14
;;             Version 2, June 1991                                ;;
15
;;                                                                 ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 17... Line 17...
17
 
17
 
-
 
18
format PE DLL native
Line 18... Line 19...
18
format MS COFF
19
entry START
19
 
20
 
-
 
21
        CURRENT_API             = 0x0200
Line 20... Line 22...
20
        API_VERSION             = 0x01000100
22
        COMPATIBLE_API          = 0x0100
Line 21... Line 23...
21
        DRIVER_VERSION          = 5
23
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
Line 28... Line 30...
28
        TX_MXDMA                = 6 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048
30
        TX_MXDMA                = 6     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048
29
        ERTXTH                  = 8 ; in unit of 32 bytes e.g:(8*32)=256
31
        ERTXTH                  = 8     ; in unit of 32 bytes e.g:(8*32)=256
30
        RX_MXDMA                = 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited
32
        RX_MXDMA                = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited
31
        RXFTH                   = 7 ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold
33
        RXFTH                   = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold
Line 32... Line -...
32
 
-
 
33
        DEBUG                   = 1
34
 
34
        __DEBUG__               = 1
35
        __DEBUG__               = 1
Line -... Line 36...
-
 
36
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
-
 
37
 
-
 
38
section '.flat' readable writable executable
35
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
39
 
36
 
40
include '../proc32.inc'
37
include '../struct.inc'
-
 
38
include '../macros.inc'
-
 
39
include '../proc32.inc'
41
include '../struct.inc'
40
include '../imports.inc'
42
include '../macros.inc'
41
include '../fdo.inc'
-
 
42
include '../netdrv.inc'
-
 
43
 
-
 
44
public START
-
 
Line 45... Line 43...
45
public service_proc
43
include '../fdo.inc'
46
public version
44
include '../netdrv_pe.inc'
47
 
45
 
48
        REG_IDR0                = 0x00
46
        REG_IDR0                = 0x00
Line 135... Line 133...
135
                                  (1 shl BIT_AER) or \                  ; Accept error packets
133
                                  (1 shl BIT_AER) or \                  ; Accept error packets
136
                                  (1 shl BIT_AR) or \                   ; Accept Runt packets (smaller then 64 bytes)
134
                                  (1 shl BIT_AR) or \                   ; Accept Runt packets (smaller then 64 bytes)
137
                                  (1 shl BIT_AM)                        ; Accept multicast packets
135
                                  (1 shl BIT_AM)                        ; Accept multicast packets
Line 138... Line 136...
138
 
136
 
139
        RX_BUFFER_SIZE          = (8192 shl RBLEN);+16+1500
-
 
140
        MAX_ETH_FRAME_SIZE      = 1514
137
        RX_BUFFER_SIZE          = (8192 shl RBLEN);+16+1500
Line 141... Line 138...
141
        NUM_TX_DESC             = 4                                     ; not user selectable
138
        NUM_TX_DESC             = 4                                     ; not user selectable
142
 
139
 
143
        EE_93C46_REG_ETH_ID     = 7 ; MAC offset
140
        EE_93C46_REG_ETH_ID     = 7 ; MAC offset
Line 187... Line 184...
187
                                  ISR_FIFOOVW or \
184
                                  ISR_FIFOOVW or \
188
                                  ISR_LENCHG or \
185
                                  ISR_LENCHG or \
189
                                  ISR_TIMEOUT or \
186
                                  ISR_TIMEOUT or \
190
                                  ISR_SERR
187
                                  ISR_SERR
Line 191... Line -...
191
 
-
 
192
 
-
 
193
 
188
 
194
        TSR_OWN                 = 1 shl 13
189
        TSR_OWN                 = 1 shl 13
195
        TSR_TUN                 = 1 shl 14
190
        TSR_TUN                 = 1 shl 14
Line 196... Line 191...
196
        TSR_TOK                 = 1 shl 15
191
        TSR_TOK                 = 1 shl 15
197
 
192
 
198
        TSR_CDH                 = 1 shl 28
193
        TSR_CDH                 = 1 shl 28
199
        TSR_OWC                 = 1 shl 29
194
        TSR_OWC                 = 1 shl 29
Line 200... Line -...
200
        TSR_TABT                = 1 shl 30
-
 
201
        TSR_CRS                 = 1 shl 31
-
 
202
 
-
 
203
 
-
 
204
virtual at ebx
195
        TSR_TABT                = 1 shl 30
Line -... Line 196...
-
 
196
        TSR_CRS                 = 1 shl 31
-
 
197
 
-
 
198
 
-
 
199
struct  device          ETH_DEVICE
-
 
200
 
-
 
201
        io_addr         dd ?
205
 
202
        pci_bus         dd ?
-
 
203
        pci_dev         dd ?
-
 
204
        irq_line        db ?
-
 
205
                        rb 3    ; align 4
-
 
206
 
Line 206... Line -...
206
        device:
-
 
207
 
207
        rx_buffer       dd ?
Line 208... Line -...
208
        ETH_DEVICE
-
 
209
 
-
 
210
        .rx_buffer      dd ?
-
 
211
 
-
 
212
        .rx_data_offset dd ?
208
        rx_data_offset  dd ?
Line 213... Line -...
213
        .io_addr        dd ?
-
 
214
 
-
 
215
        .curr_tx_desc   db ?
-
 
216
        .pci_bus        dd ?
-
 
217
        .pci_dev        dd ?
-
 
218
        .irq_line       db ?
-
 
219
        .hw_ver_id      db ?
-
 
220
 
-
 
221
                        db ?    ; align 4
-
 
222
        .TX_DESC        rd NUM_TX_DESC
-
 
Line 223... Line 209...
223
 
209
        curr_tx_desc    db ?
224
        .size = $ - device
210
        hw_ver_id       db ?
225
 
211
                        rb 2    ; align 4
226
end virtual
212
 
227
 
213
        TX_DESC         rd NUM_TX_DESC
228
 
214
 
Line 229... Line -...
229
 
-
 
230
section '.flat' code readable align 16
215
ends
231
 
-
 
232
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
233
;;                        ;;
-
 
Line -... Line 216...
-
 
216
 
234
;; proc START             ;;
217
 
Line 235... Line 218...
235
;;                        ;;
218
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
236
;; (standard driver proc) ;;
219
;;                        ;;
237
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220
;; proc START             ;;
Line 238... Line 221...
238
 
221
;;                        ;;
239
align 4
-
 
240
proc START stdcall, state:dword
222
;; (standard driver proc) ;;
241
 
223
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 242... Line 224...
242
        cmp     [state], 1
224
 
Line 261... Line 243...
261
;; proc SERVICE_PROC      ;;
243
;; proc SERVICE_PROC      ;;
262
;;                        ;;
244
;;                        ;;
263
;; (standard driver proc) ;;
245
;; (standard driver proc) ;;
264
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 265... Line -...
265
 
-
 
266
align 4
247
 
Line 267... Line 248...
267
proc service_proc stdcall, ioctl:dword
248
proc service_proc stdcall, ioctl:dword
268
 
249
 
Line 302... Line 283...
302
        jz      .firstdevice
283
        jz      .firstdevice
Line 303... Line 284...
303
 
284
 
304
        mov     ax, [eax+1]                             ; get the pci bus and device numbers
285
        mov     ax, [eax+1]                             ; get the pci bus and device numbers
305
  .nextdevice:
286
  .nextdevice:
306
        mov     ebx, [esi]
287
        mov     ebx, [esi]
307
        cmp     al, byte[device.pci_bus]
288
        cmp     al, byte[ebx + device.pci_bus]
308
        jne     @f
289
        jne     @f
309
        cmp     ah, byte[device.pci_dev]
290
        cmp     ah, byte[ebx + device.pci_dev]
310
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
291
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
311
       @@:
292
       @@:
312
        add     esi, 4
293
        add     esi, 4
Line 316... Line 297...
316
; This device doesnt have its own eth_device structure yet, lets create one
297
; This device doesnt have its own eth_device structure yet, lets create one
317
  .firstdevice:
298
  .firstdevice:
318
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
299
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
319
        jae     .fail
300
        jae     .fail
Line 320... Line 301...
320
 
301
 
Line 321... Line 302...
321
        allocate_and_clear ebx, device.size, .fail      ; Allocate the buffer for device structure
302
        allocate_and_clear ebx, sizeof.device, .fail      ; Allocate the buffer for device structure
Line 322... Line 303...
322
 
303
 
323
; Fill in the direct call addresses into the struct
304
; Fill in the direct call addresses into the struct
324
 
305
 
325
        mov     [device.reset], reset
306
        mov     [ebx + device.reset], reset
Line 326... Line 307...
326
        mov     [device.transmit], transmit
307
        mov     [ebx + device.transmit], transmit
Line 327... Line 308...
327
        mov     [device.unload], unload
308
        mov     [ebx + device.unload], unload
328
        mov     [device.name], my_service
309
        mov     [ebx + device.name], my_service
329
 
310
 
330
; save the pci bus and device numbers
311
; save the pci bus and device numbers
331
 
312
 
Line 332... Line 313...
332
        mov     eax, [edx + IOCTL.input]
313
        mov     eax, [edx + IOCTL.input]
Line -... Line 314...
-
 
314
        movzx   ecx, byte[eax+1]
333
        movzx   ecx, byte[eax+1]
315
        mov     [ebx + device.pci_bus], ecx
Line 334... Line 316...
334
        mov     [device.pci_bus], ecx
316
        movzx   ecx, byte[eax+2]
Line -... Line 317...
-
 
317
        mov     [ebx + device.pci_dev], ecx
335
        movzx   ecx, byte[eax+2]
318
 
Line 336... Line 319...
336
        mov     [device.pci_dev], ecx
319
; Now, it's time to find the base io addres of the PCI device
337
 
320
 
Line 338... Line 321...
338
; Now, it's time to find the base io addres of the PCI device
321
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
Line 339... Line 322...
339
 
322
        mov     [ebx + device.io_addr], eax
340
        PCI_find_io
323
 
341
 
324
; We've found the io address, find IRQ now
342
; We've found the io address, find IRQ now
325
 
Line 343... Line 326...
343
 
326
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
Line 344... Line 327...
344
        PCI_find_irq
327
        mov     [ebx + device.irq_line], al
345
 
328
 
Line 365... Line 348...
365
 
348
 
366
        call    reset
349
        call    reset
367
        test    eax, eax
350
        test    eax, eax
Line 368... Line 351...
368
        jnz     .destroy
351
        jnz     .destroy
369
 
352
 
Line 370... Line 353...
370
        mov     [device.type], NET_TYPE_ETH
353
        mov     [ebx + device.type], NET_TYPE_ETH
371
        call    NetRegDev
354
        invoke  NetRegDev
Line 372... Line 355...
372
 
355
 
Line 373... Line 356...
373
        cmp     eax, -1
356
        cmp     eax, -1
Line 374... Line 357...
374
        je      .destroy
357
        je      .destroy
375
 
358
 
376
        ret
359
        ret
377
 
360
 
378
; If the device was already loaded, find the device number and return it in eax
361
; If the device was already loaded, find the device number and return it in eax
379
 
362
 
380
  .find_devicenum:
363
  .find_devicenum:
Line 391... Line 374...
391
        ; todo: unregister device from device_list
374
        ; todo: unregister device from device_list
392
        ; todo: reset device into virgin state
375
        ; todo: reset device into virgin state
Line 393... Line 376...
393
 
376
 
394
  .err:
377
  .err:
395
        DEBUGF  2, "Error, removing all data !\n"
378
        DEBUGF  2, "Error, removing all data !\n"
396
        stdcall KernelFree, [device.rx_buffer]
379
        invoke  KernelFree, [ebx + device.rx_buffer]
Line 397... Line 380...
397
        stdcall KernelFree, ebx
380
        invoke  KernelFree, ebx
398
 
381
 
399
  .fail:
382
  .fail:
Line 433... Line 416...
433
 
416
 
434
align 4
417
align 4
435
probe:
418
probe:
Line 436... Line 419...
436
        DEBUGF  1, "Probing\n"
419
        DEBUGF  1, "Probing\n"
-
 
420
 
-
 
421
; Make the device a bus master
-
 
422
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line 437... Line 423...
437
 
423
        or      al, PCI_CMD_MASTER
438
        PCI_make_bus_master
424
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
439
 
425
 
440
; get chip version
426
; get chip version
441
        set_io  0
427
        set_io  [ebx + device.io_addr], 0
442
        set_io  REG_TXCONFIG + 2
428
        set_io  [ebx + device.io_addr], REG_TXCONFIG + 2
443
        in      ax, dx
429
        in      ax, dx
Line 456... Line 442...
456
        mov     ecx, 8
442
        mov     ecx, 8
457
  .chip_ver_found:
443
  .chip_ver_found:
458
        cmp     ecx, 8
444
        cmp     ecx, 8
459
        ja      .unknown
445
        ja      .unknown
Line 460... Line 446...
460
 
446
 
Line 461... Line 447...
461
        mov     [device.hw_ver_id], cl
447
        mov     [ebx + device.hw_ver_id], cl
462
 
448
 
Line 463... Line 449...
463
        mov     ecx, [crosslist+ecx*4]
449
        mov     ecx, [crosslist+ecx*4]
Line 464... Line 450...
464
        mov     [device.name], ecx
450
        mov     [ebx + device.name], ecx
465
 
451
 
466
        DEBUGF  1, "Chip version: %s\n", ecx
452
        DEBUGF  1, "Chip version: %s\n", ecx
467
 
453
 
468
; wake up the chip
454
; wake up the chip
Line 469... Line 455...
469
        set_io  0
455
        set_io  [ebx + device.io_addr], 0
470
        set_io  REG_HLTCLK
456
        set_io  [ebx + device.io_addr], REG_HLTCLK
471
        mov     al, 'R'         ; run the clock
457
        mov     al, 'R'         ; run the clock
472
        out     dx, al
458
        out     dx, al
Line 473... Line 459...
473
 
459
 
474
; unlock config and BMCR registers
460
; unlock config and BMCR registers
475
        set_io  REG_9346CR
461
        set_io  [ebx + device.io_addr], REG_9346CR
476
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
462
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
477
        out     dx, al
463
        out     dx, al
478
 
464
 
479
; enable power management
465
; enable power management
480
        set_io  REG_CONFIG1
466
        set_io  [ebx + device.io_addr], REG_CONFIG1
481
        in      al, dx
467
        in      al, dx
Line 493... Line 479...
493
  .new_chip:
479
  .new_chip:
494
        or      al, (1 shl BIT_PMEn)
480
        or      al, (1 shl BIT_PMEn)
495
        and     al, not (1 shl BIT_LWACT)
481
        and     al, not (1 shl BIT_LWACT)
496
        out     dx, al
482
        out     dx, al
Line 497... Line 483...
497
 
483
 
498
        set_io  REG_CONFIG4
484
        set_io  [ebx + device.io_addr], REG_CONFIG4
499
        in      al, dx
485
        in      al, dx
500
        and     al, not (1 shl BIT_LWPTN)
486
        and     al, not (1 shl BIT_LWPTN)
Line 501... Line 487...
501
        out     dx, al
487
        out     dx, al
502
 
488
 
503
; lock config and BMCR registers
489
; lock config and BMCR registers
504
  .finish_wake_up:
490
  .finish_wake_up:
505
        xor     al, al
491
        xor     al, al
506
        set_io  0
492
        set_io  [ebx + device.io_addr], 0
507
        set_io  REG_9346CR
493
        set_io  [ebx + device.io_addr], REG_9346CR
Line 508... Line 494...
508
        out     dx, al
494
        out     dx, al
Line 521... Line 507...
521
 
507
 
522
reset:
508
reset:
Line 523... Line 509...
523
        DEBUGF  1, "Reset\n"
509
        DEBUGF  1, "Reset\n"
524
 
510
 
525
; attach int handler
511
; attach int handler
526
        movzx   eax, [device.irq_line]
512
        movzx   eax, [ebx + device.irq_line]
527
        DEBUGF  1, "Attaching int handler to irq %x\n", eax:1
513
        DEBUGF  1, "Attaching int handler to irq %x\n", eax:1
528
        stdcall AttachIntHandler, eax, int_handler, dword 0
514
        invoke  AttachIntHandler, eax, int_handler, ebx
529
        test    eax, eax
515
        test    eax, eax
530
        jnz     @f
516
        jnz     @f
531
        DEBUGF  2, "Could not attach int handler!\n"
517
        DEBUGF  2, "Could not attach int handler!\n"
532
;        or      eax, -1
518
        or      eax, -1
Line 533... Line 519...
533
;        ret
519
        ret
534
       @@:
520
       @@:
535
 
521
 
536
; reset chip
522
; reset chip
537
        DEBUGF  1, "Resetting chip\n"
523
        DEBUGF  1, "Resetting chip\n"
538
        set_io  0
524
        set_io  [ebx + device.io_addr], 0
539
        set_io  REG_COMMAND
525
        set_io  [ebx + device.io_addr], REG_COMMAND
540
        mov     al, 1 shl BIT_RST
526
        mov     al, 1 shl BIT_RST
541
        out     dx, al
527
        out     dx, al
Line 551... Line 537...
551
 
537
 
552
; Read MAC address
538
; Read MAC address
Line 553... Line 539...
553
        call    read_mac
539
        call    read_mac
554
 
540
 
555
; unlock config and BMCR registers
541
; unlock config and BMCR registers
556
        set_io  0
542
        set_io  [ebx + device.io_addr], 0
557
        set_io  REG_9346CR
543
        set_io  [ebx + device.io_addr], REG_9346CR
Line 558... Line 544...
558
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
544
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
559
        out     dx, al
545
        out     dx, al
560
 
546
 
561
; initialize multicast registers (no filtering)
547
; initialize multicast registers (no filtering)
562
        mov     eax, 0xffffffff
548
        mov     eax, 0xffffffff
563
        set_io  REG_MAR0
549
        set_io  [ebx + device.io_addr], REG_MAR0
Line 564... Line 550...
564
        out     dx, eax
550
        out     dx, eax
565
        set_io  REG_MAR4
551
        set_io  [ebx + device.io_addr], REG_MAR4
566
        out     dx, eax
552
        out     dx, eax
567
 
553
 
Line 568... Line 554...
568
; enable Rx/Tx
554
; enable Rx/Tx
569
        mov     al, (1 shl BIT_RE) or (1 shl BIT_TE)
555
        mov     al, (1 shl BIT_RE) or (1 shl BIT_TE)
570
        set_io  REG_COMMAND
556
        set_io  [ebx + device.io_addr], REG_COMMAND
571
        out     dx, al
557
        out     dx, al
572
 
558
 
Line 573... Line 559...
573
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
559
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
574
; accept broadcast packets, accept physical match packets
560
; accept broadcast packets, accept physical match packets
575
        mov     eax, RX_CONFIG
561
        mov     eax, RX_CONFIG
576
        set_io  REG_RXCONFIG
562
        set_io  [ebx + device.io_addr], REG_RXCONFIG
Line 577... Line 563...
577
        out     dx, eax
563
        out     dx, eax
578
 
564
 
579
; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144
565
; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144
580
        mov     eax, (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0
566
        mov     eax, (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0
581
        set_io  REG_TXCONFIG
567
        set_io  [ebx + device.io_addr], REG_TXCONFIG
Line 582... Line 568...
582
        out     dx, eax
568
        out     dx, eax
583
 
569
 
584
; enable auto negotiation
570
; enable auto negotiation
585
        set_io  REG_BMCR
571
        set_io  [ebx + device.io_addr], REG_BMCR
586
        in      ax, dx
572
        in      ax, dx
Line 587... Line 573...
587
        or      ax, (1 shl BIT_ANE)
573
        or      ax, (1 shl BIT_ANE)
588
        out     dx, ax
574
        out     dx, ax
589
 
575
 
590
; set auto negotiation advertisement
576
; set auto negotiation advertisement
Line 591... Line 577...
591
        set_io  REG_ANAR
577
        set_io  [ebx + device.io_addr], REG_ANAR
592
        in      ax, dx
578
        in      ax, dx
593
        or      ax, (1 shl BIT_SELECTOR) or (1 shl BIT_10) or (1 shl BIT_10FD) or (1 shl BIT_TX) or (1 shl BIT_TXFD)
579
        or      ax, (1 shl BIT_SELECTOR) or (1 shl BIT_10) or (1 shl BIT_10FD) or (1 shl BIT_TX) or (1 shl BIT_TXFD)
594
        out     dx, ax
580
        out     dx, ax
595
 
581
 
Line 596... Line 582...
596
; lock config and BMCR registers
582
; lock config and BMCR registers
597
        xor     eax, eax
583
        xor     eax, eax
598
        set_io  REG_9346CR
584
        set_io  [ebx + device.io_addr], REG_9346CR
599
        out     dx, al
585
        out     dx, al
Line 600... Line 586...
600
 
586
 
601
; init RX/TX pointers
587
; init RX/TX pointers
602
        mov     [device.rx_data_offset], eax
588
        mov     [ebx + device.rx_data_offset], eax
Line 603... Line 589...
603
        mov     [device.curr_tx_desc], al
589
        mov     [ebx + device.curr_tx_desc], al
604
;        set_io  REG_CAPR
590
;        set_io  [ebx + device.io_addr], REG_CAPR
605
;        out     dx, ax
591
;        out     dx, ax
606
 
592
 
607
; clear packet/byte counters
593
; clear packet/byte counters
608
        lea     edi, [device.bytes_tx]
594
        lea     edi, [ebx + device.bytes_tx]
609
        mov     ecx, 6
595
        mov     ecx, 6
610
        rep     stosd
596
        rep     stosd
Line 611... Line 597...
611
 
597
 
612
; clear missing packet counter
598
; clear missing packet counter
613
        set_io  REG_MPC
599
        set_io  [ebx + device.io_addr], REG_MPC
614
        out     dx, eax
600
        out     dx, eax
615
 
601
 
Line 616... Line 602...
616
; set RxBuffer address, init RX buffer offset
602
; set RxBuffer address, init RX buffer offset
617
        mov     eax, [device.rx_buffer]
603
        mov     eax, [ebx + device.rx_buffer]
Line 618... Line 604...
618
        mov     dword[eax], 0                   ; clear receive flags for first packet (really needed??)
604
        mov     dword[eax], 0                   ; clear receive flags for first packet (really needed??)
Line 619... Line 605...
619
        DEBUGF  1, "RX buffer virtual addr=0x%x\n", eax
605
        DEBUGF  1, "RX buffer virtual addr=0x%x\n", eax
620
        GetRealAddr
606
        invoke  GetPhysAddr
Line 645... Line 631...
645
;; In: buffer pointer in [esp+4]           ;;
631
;; In: buffer pointer in [esp+4]           ;;
646
;;     size of buffer in [esp+8]           ;;
632
;;     size of buffer in [esp+8]           ;;
647
;;     pointer to device structure in ebx  ;;
633
;;     pointer to device structure in ebx  ;;
648
;;                                         ;;
634
;;                                         ;;
649
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
635
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
636
 
-
 
637
proc transmit stdcall bufferptr, buffersize
-
 
638
 
650
align 4
639
        pushf
651
transmit:
640
        cli
-
 
641
 
652
        DEBUGF  1, "Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
642
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
653
        mov     eax, [esp+4]
643
        mov     eax, [bufferptr]
654
        DEBUGF  1, "To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
644
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
655
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
645
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
656
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
646
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
657
        [eax+13]:2,[eax+12]:2
647
        [eax+13]:2,[eax+12]:2
Line 658... Line 648...
658
 
648
 
659
        cmp     dword [esp+8], MAX_ETH_FRAME_SIZE
649
        cmp     [buffersize], 1514
660
        ja      .fail
650
        ja      .fail
661
        cmp     dword [esp+8], 60
651
        cmp     [buffersize], 60
Line 662... Line 652...
662
        jb      .fail
652
        jb      .fail
663
 
653
 
664
; check if we own the current discriptor
654
; check if we own the current discriptor
665
        set_io  0
655
        set_io  [ebx + device.io_addr], 0
666
        set_io  REG_TSD0
656
        set_io  [ebx + device.io_addr], REG_TSD0
667
        movzx   ecx, [device.curr_tx_desc]
657
        movzx   ecx, [ebx + device.curr_tx_desc]
668
        shl     ecx, 2
658
        shl     ecx, 2
669
        add     edx, ecx
659
        add     edx, ecx
670
        in      eax, dx
660
        in      eax, dx
Line 671... Line 661...
671
        test    eax, (1 shl BIT_OWN)
661
        test    eax, (1 shl BIT_OWN)
672
        jz      .wait_to_send
662
        jz      .wait_to_send
673
 
663
 
674
  .send_packet:
664
  .send_packet:
Line 675... Line 665...
675
; get next descriptor
665
; get next descriptor
676
        inc     [device.curr_tx_desc]
666
        inc     [ebx + device.curr_tx_desc]
677
        and     [device.curr_tx_desc], NUM_TX_DESC-1
667
        and     [ebx + device.curr_tx_desc], NUM_TX_DESC-1
678
 
668
 
679
; Update stats
669
; Update stats
Line 680... Line 670...
680
        inc     [device.packets_tx]
670
        inc     [ebx + device.packets_tx]
681
        mov     eax, [esp+8]
671
        mov     eax, [buffersize]
682
        add     dword [device.bytes_tx], eax
672
        add     dword [ebx + device.bytes_tx], eax
683
        adc     dword [device.bytes_tx+4], 0
673
        adc     dword [ebx + device.bytes_tx+4], 0
684
 
674
 
685
; Set the buffer address
675
; Set the buffer address
Line 686... Line 676...
686
        set_io  REG_TSAD0
676
        set_io  [ebx + device.io_addr], REG_TSAD0
687
        mov     eax, [esp+4]
677
        mov     eax, [bufferptr]
688
        mov     [device.TX_DESC+ecx], eax
678
        mov     [ebx + device.TX_DESC+ecx], eax
689
        GetRealAddr
679
        invoke  GetPhysAddr
690
        out     dx, eax
680
        out     dx, eax
Line 691... Line 681...
691
 
681
 
692
; And the size of the buffer
682
; And the size of the buffer
-
 
683
        set_io  [ebx + device.io_addr], REG_TSD0
693
        set_io  REG_TSD0
684
        mov     eax, [buffersize]
Line 694... Line 685...
694
        mov     eax, [esp+8]
685
        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
695
        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
686
        out     dx, eax
Line 696... Line 687...
696
        out     dx, eax
687
 
697
 
688
        DEBUGF  1, "Packet Sent!\n"
698
        DEBUGF  1, "Packet Sent!\n"
689
        xor     eax, eax
699
        xor     eax, eax
690
        popf
Line 700... Line 691...
700
        ret     8
691
        ret
701
 
692
 
702
  .wait_to_send:
693
  .wait_to_send:
Line 717... Line 708...
717
 
708
 
Line 718... Line 709...
718
        jmp     .send_packet
709
        jmp     .send_packet
719
 
710
 
720
  .fail:
711
  .fail:
-
 
712
        DEBUGF  2, "transmit failed!\n"
721
        DEBUGF  2, "transmit failed!\n"
713
        invoke  KernelFree, [bufferptr]
722
        stdcall KernelFree, [esp+4]
714
        popf
-
 
715
        or      eax, -1
-
 
716
        ret
Line 746... Line 740...
746
        jz      .nothing
740
        jz      .nothing
747
        mov     esi, device_list
741
        mov     esi, device_list
748
  .nextdevice:
742
  .nextdevice:
749
        mov     ebx, [esi]
743
        mov     ebx, [esi]
Line 750... Line 744...
750
 
744
 
751
        set_io  0
745
        set_io  [ebx + device.io_addr], 0
752
        set_io  REG_ISR
746
        set_io  [ebx + device.io_addr], REG_ISR
753
        in      ax, dx                          ; Get interrupt status
747
        in      ax, dx                          ; Get interrupt status
754
        out     dx, ax                          ; send it back to ACK
748
        out     dx, ax                          ; send it back to ACK
755
        test    ax, ax
749
        test    ax, ax
756
        jnz     .got_it
750
        jnz     .got_it
Line 774... Line 768...
774
        test    ax, ISR_ROK
768
        test    ax, ISR_ROK
775
        jz      @f
769
        jz      @f
776
        push    ax
770
        push    ax
Line 777... Line 771...
777
 
771
 
778
  .receive:
772
  .receive:
779
        set_io  0
773
        set_io  [ebx + device.io_addr], 0
780
        set_io  REG_COMMAND
774
        set_io  [ebx + device.io_addr], REG_COMMAND
781
        in      al, dx
775
        in      al, dx
782
        test    al, BUFE                        ; test if RX buffer is empty
776
        test    al, BUFE                        ; test if RX buffer is empty
Line 783... Line 777...
783
        jnz     .finish
777
        jnz     .finish
Line 784... Line 778...
784
 
778
 
785
        DEBUGF  1, "RX:\n"
779
        DEBUGF  1, "RX:\n"
786
 
780
 
787
        mov     eax, [device.rx_buffer]
781
        mov     eax, [ebx + device.rx_buffer]
Line 788... Line 782...
788
        add     eax, [device.rx_data_offset]
782
        add     eax, [ebx + device.rx_data_offset]
789
        test    byte [eax], (1 shl BIT_ROK)     ; check if packet is ok
783
        test    byte [eax], (1 shl BIT_ROK)     ; check if packet is ok
790
        jz      .reset_rx
784
        jz      .reset_rx
Line 791... Line 785...
791
 
785
 
792
; packet is ok, copy it
786
; packet is ok, copy it
793
        movzx   ecx, word [eax+2]               ; packet length
787
        movzx   ecx, word [eax+2]               ; packet length
794
        sub     cx, 4                           ; don't copy CRC
788
        sub     cx, 4                           ; don't copy CRC
Line 795... Line 789...
795
 
789
 
Line 796... Line 790...
796
; Update stats
790
; Update stats
797
        add     dword [device.bytes_rx], ecx
791
        add     dword [ebx + device.bytes_rx], ecx
798
        adc     dword [device.bytes_rx + 4], 0
792
        adc     dword [ebx + device.bytes_rx + 4], 0
799
        inc     [device.packets_rx]
793
        inc     [ebx + device.packets_rx]
800
 
794
 
Line 801... Line 795...
801
        DEBUGF  1, "Received %u bytes\n", ecx
795
        DEBUGF  1, "Received %u bytes\n", ecx
Line 825... Line 819...
825
  .nw:
819
  .nw:
826
        jz      .nd
820
        jz      .nd
827
        rep     movsd
821
        rep     movsd
828
  .nd:
822
  .nd:
Line 829... Line 823...
829
 
823
 
Line 830... Line 824...
830
        jmp     Eth_input                       ; Send it to kernel
824
        jmp     [Eth_input]                     ; Send it to kernel
831
 
825
 
832
  .abort:
826
  .abort:
833
        pop     eax ebx
827
        pop     eax ebx
834
                                                ; update eth_data_start_offset
828
                                                ; update eth_data_start_offset
835
        movzx   eax, word [eax+2]               ; packet length
829
        movzx   eax, word [eax+2]               ; packet length
836
        add     eax, [device.rx_data_offset]
830
        add     eax, [ebx + device.rx_data_offset]
Line 837... Line 831...
837
        add     eax, 4+3                        ; packet header is 4 bytes long + dword alignment
831
        add     eax, 4+3                        ; packet header is 4 bytes long + dword alignment
838
        and     eax, not 3                      ; dword alignment
832
        and     eax, not 3                      ; dword alignment
839
 
833
 
840
        cmp     eax, RX_BUFFER_SIZE
834
        cmp     eax, RX_BUFFER_SIZE
841
        jb      .no_wrap
835
        jb      .no_wrap
842
        DEBUGF  1, "Wrapping\n"
836
        DEBUGF  1, "Wrapping\n"
843
        sub     eax, RX_BUFFER_SIZE
837
        sub     eax, RX_BUFFER_SIZE
Line 844... Line 838...
844
  .no_wrap:
838
  .no_wrap:
845
        mov     [device.rx_data_offset], eax
839
        mov     [ebx + device.rx_data_offset], eax
846
        DEBUGF  1, "New RX ptr: %d\n", eax
840
        DEBUGF  1, "New RX ptr: %d\n", eax
847
 
841
 
Line 848... Line 842...
848
        set_io  0
842
        set_io  [ebx + device.io_addr], 0
Line 887... Line 881...
887
        DEBUGF  1, "Transmit done!\n"
881
        DEBUGF  1, "Transmit done!\n"
Line 888... Line 882...
888
 
882
 
889
        push    ax
883
        push    ax
890
        mov     ecx, (NUM_TX_DESC-1)*4
884
        mov     ecx, (NUM_TX_DESC-1)*4
891
  .txdescloop:
885
  .txdescloop:
892
        set_io  0
886
        set_io  [ebx + device.io_addr], 0
893
        set_io  REG_TSD0
887
        set_io  [ebx + device.io_addr], REG_TSD0
894
        add     edx, ecx
888
        add     edx, ecx
Line 895... Line 889...
895
        in      eax, dx
889
        in      eax, dx
896
 
890
 
Line 897... Line 891...
897
        test    eax, TSR_OWN                    ; DMA operation completed
891
        test    eax, TSR_OWN                    ; DMA operation completed
898
        jz      .notthisone
892
        jz      .notthisone
Line 899... Line 893...
899
 
893
 
Line 900... Line 894...
900
        cmp     [device.TX_DESC+ecx], 0
894
        cmp     [ebx + device.TX_DESC+ecx], 0
Line 925... Line 919...
925
        test    eax, TSR_TOK
919
        test    eax, TSR_TOK
926
        jz      .no_tok
920
        jz      .no_tok
927
        DEBUGF  1, "TX: Transmit OK!\n"
921
        DEBUGF  1, "TX: Transmit OK!\n"
Line 928... Line 922...
928
 
922
 
929
  .no_tok:
923
  .no_tok:
930
        DEBUGF  1, "free transmit buffer 0x%x\n", [device.TX_DESC+ecx]:8
924
        DEBUGF  1, "free transmit buffer 0x%x\n", [ebx + device.TX_DESC+ecx]:8
931
        push    ecx ebx
925
        push    ecx ebx
932
        stdcall KernelFree, [device.TX_DESC+ecx]
926
        invoke  KernelFree, [ebx + device.TX_DESC+ecx]
933
        pop     ebx ecx
927
        pop     ebx ecx
Line 934... Line 928...
934
        mov     [device.TX_DESC+ecx], 0
928
        mov     [ebx + device.TX_DESC+ecx], 0
935
 
929
 
936
  .notthisone:
930
  .notthisone:
937
        sub     ecx, 4
931
        sub     ecx, 4
Line 945... Line 939...
945
        jz      @f
939
        jz      @f
Line 946... Line 940...
946
 
940
 
947
        push    ax
941
        push    ax
Line 948... Line 942...
948
        DEBUGF  2, "RX:buffer overflow!\n"
942
        DEBUGF  2, "RX:buffer overflow!\n"
949
 
943
 
950
        set_io  0
944
        set_io  [ebx + device.io_addr], 0
951
        set_io  REG_ISR
945
        set_io  [ebx + device.io_addr], REG_ISR
952
        mov     ax, ISR_FIFOOVW or ISR_RXOVW
946
        mov     ax, ISR_FIFOOVW or ISR_RXOVW
Line 953... Line 947...
953
        out     dx, ax
947
        out     dx, ax
Line 970... Line 964...
970
        jz      @f
964
        jz      @f
Line 971... Line 965...
971
 
965
 
972
        push    ax
966
        push    ax
Line 973... Line 967...
973
        DEBUGF  2, "RX fifo overflow!\n"
967
        DEBUGF  2, "RX fifo overflow!\n"
974
 
968
 
975
        set_io  0
969
        set_io  [ebx + device.io_addr], 0
976
        set_io  REG_ISR
970
        set_io  [ebx + device.io_addr], REG_ISR
977
        mov     ax, ISR_FIFOOVW or ISR_RXOVW
971
        mov     ax, ISR_FIFOOVW or ISR_RXOVW
Line 978... Line 972...
978
        out     dx, ax
972
        out     dx, ax
Line 1006... Line 1000...
1006
 
1000
 
1007
align 4
1001
align 4
1008
cable:
1002
cable:
Line 1009... Line 1003...
1009
        DEBUGF  1, "Checking link status:\n"
1003
        DEBUGF  1, "Checking link status:\n"
1010
 
1004
 
1011
        set_io  0
1005
        set_io  [ebx + device.io_addr], 0
Line 1012... Line 1006...
1012
        set_io  REG_MSR
1006
        set_io  [ebx + device.io_addr], REG_MSR
1013
        in      al, dx
1007
        in      al, dx
Line 1014... Line 1008...
1014
 
1008
 
1015
        test    al, 1 shl 2             ; 0 = link ok 1 = link fail
1009
        test    al, 1 shl 2             ; 0 = link ok 1 = link fail
Line 1016... Line 1010...
1016
        jnz     .notconnected
1010
        jnz     .notconnected
1017
 
1011
 
1018
        test    al, 1 shl 3             ; 0 = 100 Mbps 1 = 10 Mbps
1012
        test    al, 1 shl 3             ; 0 = 100 Mbps 1 = 10 Mbps
1019
        jnz     .10mbps
1013
        jnz     .10mbps
Line 1020... Line 1014...
1020
 
1014
 
Line 1021... Line 1015...
1021
  .100mbps:
1015
  .100mbps:
1022
        mov     [device.state], ETH_LINK_100M
1016
        mov     [ebx + device.state], ETH_LINK_100M
1023
        call    NetLinkChanged
1017
        invoke  NetLinkChanged
1024
        DEBUGF  2, "link changed to 100 mbit\n"
1018
        DEBUGF  2, "link changed to 100 mbit\n"
Line 1025... Line 1019...
1025
 
1019
 
Line 1026... Line 1020...
1026
        ret
1020
        ret
1027
 
1021
 
1028
  .10mbps:
1022
  .10mbps:
1029
        mov     [device.state], ETH_LINK_10M
1023
        mov     [ebx + device.state], ETH_LINK_10M
Line 1030... Line 1024...
1030
        call    NetLinkChanged
1024
        invoke  NetLinkChanged
Line 1051... Line 1045...
1051
write_mac:      ; in: mac pushed onto stack (as 3 words)
1045
write_mac:      ; in: mac pushed onto stack (as 3 words)
Line 1052... Line 1046...
1052
 
1046
 
Line 1053... Line 1047...
1053
        DEBUGF  1, "Writing MAC\n"
1047
        DEBUGF  1, "Writing MAC\n"
1054
 
1048
 
1055
; disable all in command registers
1049
; disable all in command registers
1056
        set_io  0
1050
        set_io  [ebx + device.io_addr], 0
1057
        set_io  REG_9346CR
1051
        set_io  [ebx + device.io_addr], REG_9346CR
Line 1058... Line 1052...
1058
        xor     eax, eax
1052
        xor     eax, eax
1059
        out     dx, al
1053
        out     dx, al
1060
 
1054
 
Line 1061... Line 1055...
1061
        set_io  REG_IMR
1055
        set_io  [ebx + device.io_addr], REG_IMR
1062
        xor     eax, eax
1056
        xor     eax, eax
1063
        out     dx, ax
1057
        out     dx, ax
Line 1064... Line 1058...
1064
 
1058
 
1065
        set_io  REG_ISR
1059
        set_io  [ebx + device.io_addr], REG_ISR
1066
        mov     eax, -1
1060
        mov     eax, -1
1067
        out     dx, ax
1061
        out     dx, ax
Line 1068... Line 1062...
1068
 
1062
 
1069
; enable writing
1063
; enable writing
1070
        set_io  REG_9346CR
1064
        set_io  [ebx + device.io_addr], REG_9346CR
1071
        mov     eax, REG_9346CR_WE
1065
        mov     eax, REG_9346CR_WE
Line 1072... Line 1066...
1072
        out     dx, al
1066
        out     dx, al
1073
 
1067
 
1074
 ; write the mac ...
1068
 ; write the mac ...
1075
        set_io  REG_IDR0
1069
        set_io  [ebx + device.io_addr], REG_IDR0
Line 1076... Line 1070...
1076
        pop     eax
1070
        pop     eax
1077
        out     dx, eax
1071
        out     dx, eax
1078
 
1072
 
1079
        set_io  REG_IDR0+4
1073
        set_io  [ebx + device.io_addr], REG_IDR0+4
Line 1080... Line 1074...
1080
        xor     eax, eax
1074
        xor     eax, eax
Line 1098... Line 1092...
1098
;;;;;;;;;;;;;;;;;;;;;;
1092
;;;;;;;;;;;;;;;;;;;;;;
Line 1099... Line 1093...
1099
 
1093
 
1100
read_mac:
1094
read_mac:
Line 1101... Line 1095...
1101
        DEBUGF  1, "Reading MAC:\n"
1095
        DEBUGF  1, "Reading MAC:\n"
1102
 
1096
 
1103
        set_io  0
1097
        set_io  [ebx + device.io_addr], 0
1104
        lea     edi, [device.mac]
1098
        lea     edi, [ebx + device.mac]
1105
        in      eax, dx
1099
        in      eax, dx
1106
        stosd
1100
        stosd
1107
        add     edx, 4
1101
        add     edx, 4
Line 1113... Line 1107...
1113
        ret
1107
        ret
Line 1114... Line 1108...
1114
 
1108
 
Line 1115... Line 1109...
1115
 
1109
 
-
 
1110
; End of code
-
 
1111
 
1116
; End of code
1112
data fixups
Line 1117... Line -...
1117
 
-
 
1118
section '.data' data readable writable align 16 ; place all uninitialized data place here
-
 
1119
align 4                                         ; Place all initialised data here
1113
end data
Line 1120... Line 1114...
1120
 
1114
 
1121
devices         dd 0
1115
include '../peimport.inc'
1122
version         dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1116
 
Line 1156... Line 1150...
1156
 
1150
 
Line 1157... Line 1151...
1157
HW_VER_ARRAY_SIZE = $-hw_ver_array
1151
HW_VER_ARRAY_SIZE = $-hw_ver_array
Line -... Line 1152...
-
 
1152
 
-
 
1153
include_debug_strings                           ; All data wich FDO uses will be included here
1158
 
1154