Subversion Repositories Kolibri OS

Rev

Rev 5522 | Rev 6229 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
6227 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved.    ;;
3545 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;;  Realtek 8139 driver for KolibriOS                              ;;
7
;;                                                                 ;;
8
;;  based on RTL8139.asm driver for menuetos                       ;;
9
;;  and realtek8139.asm for SolarOS by Eugen Brasoveanu            ;;
10
;;                                                                 ;;
11
;;    Written by hidnplayr@kolibrios.org                           ;;
12
;;                                                                 ;;
13
;;          GNU GENERAL PUBLIC LICENSE                             ;;
14
;;             Version 2, June 1991                                ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17
 
5045 hidnplayr 18
format PE DLL native
19
entry START
3545 hidnplayr 20
 
5045 hidnplayr 21
        CURRENT_API             = 0x0200
22
        COMPATIBLE_API          = 0x0100
23
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
3545 hidnplayr 24
 
25
        MAX_DEVICES             = 16
26
 
5045 hidnplayr 27
        RBLEN                   = 3     ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
3545 hidnplayr 28
 
5045 hidnplayr 29
        TXRR                    = 8     ; total retries = 16+(TXRR*16)
30
        TX_MXDMA                = 6     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=2048
31
        ERTXTH                  = 8     ; in unit of 32 bytes e.g:(8*32)=256
32
        RX_MXDMA                = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=unlimited
33
        RXFTH                   = 7     ; 0=16 1=32 2=64 3=128 4=256 5=512 6=1024 7=no threshold
3857 hidnplayr 34
 
3545 hidnplayr 35
        __DEBUG__               = 1
5045 hidnplayr 36
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
3545 hidnplayr 37
 
5045 hidnplayr 38
section '.flat' readable writable executable
39
 
40
include '../proc32.inc'
4467 hidnplayr 41
include '../struct.inc'
42
include '../macros.inc'
3545 hidnplayr 43
include '../fdo.inc'
5074 hidnplayr 44
include '../netdrv.inc'
3545 hidnplayr 45
 
46
        REG_IDR0                = 0x00
47
        REG_MAR0                = 0x08 ; multicast filter register 0
48
        REG_MAR4                = 0x0c ; multicast filter register 4
49
        REG_TSD0                = 0x10 ; transmit status of descriptor
50
        REG_TSAD0               = 0x20 ; transmit start address of descriptor
51
        REG_RBSTART             = 0x30 ; RxBuffer start address
52
        REG_COMMAND             = 0x37 ; command register
53
        REG_CAPR                = 0x38 ; current address of packet read (word) R/W
54
        REG_IMR                 = 0x3c ; interrupt mask register
55
        REG_ISR                 = 0x3e ; interrupt status register
56
        REG_TXCONFIG            = 0x40 ; transmit configuration register
57
        REG_RXCONFIG            = 0x44 ; receive configuration register 0
58
        REG_MPC                 = 0x4c ; missed packet counter
59
        REG_9346CR              = 0x50 ; serial eeprom 93C46 command register
60
        REG_CONFIG1             = 0x52 ; configuration register 1
6227 hidnplayr 61
        REG_MSR                 = 0x58 ; Media Status register
3545 hidnplayr 62
        REG_CONFIG4             = 0x5a ; configuration register 4
63
        REG_HLTCLK              = 0x5b ; undocumented halt clock register
64
        REG_BMCR                = 0x62 ; basic mode control register
65
        REG_ANAR                = 0x66 ; auto negotiation advertisement register
66
        REG_9346CR_WE           = 11b shl 6
67
 
68
        BIT_RUNT                = 4 ; total packet length < 64 bytes
69
        BIT_LONG                = 3 ; total packet length > 4k
70
        BIT_CRC                 = 2 ; crc error occured
71
        BIT_FAE                 = 1 ; frame alignment error occured
72
        BIT_ROK                 = 0 ; received packet is ok
73
 
74
        BIT_RST                 = 4 ; reset bit
75
        BIT_RE                  = 3 ; receiver enabled
76
        BIT_TE                  = 2 ; transmitter enabled
77
        BUFE                    = 1 ; rx buffer is empty, no packet stored
78
 
79
        BIT_ISR_TOK             = 2 ; transmit ok
80
        BIT_ISR_RER             = 1 ; receive error interrupt
81
        BIT_ISR_ROK             = 0 ; receive ok
82
 
83
        BIT_TX_MXDMA            = 8 ; Max DMA burst size per Tx DMA burst
84
        BIT_TXRR                = 4 ; Tx Retry count 16+(TXRR*16)
85
 
86
        BIT_RXFTH               = 13 ; Rx fifo threshold
87
        BIT_RBLEN               = 11 ; Ring buffer length indicator
88
        BIT_RX_MXDMA            = 8 ; Max DMA burst size per Rx DMA burst
89
        BIT_NOWRAP              = 7 ; transfered data wrapping
90
        BIT_9356SEL             = 6 ; eeprom selector 9346/9356
91
        BIT_AER                 = 5 ; accept error packets
92
        BIT_AR                  = 4 ; accept runt packets
93
        BIT_AB                  = 3 ; accept broadcast packets
94
        BIT_AM                  = 2 ; accept multicast packets
95
        BIT_APM                 = 1 ; accept physical match packets
96
        BIT_AAP                 = 0 ; accept all packets
97
 
98
        BIT_93C46_EEM1          = 7 ; RTL8139 eeprom operating mode1
99
        BIT_93C46_EEM0          = 6 ; RTL8139 eeprom operating mode0
100
        BIT_93C46_EECS          = 3 ; chip select
101
        BIT_93C46_EESK          = 2 ; serial data clock
102
        BIT_93C46_EEDI          = 1 ; serial data input
103
        BIT_93C46_EEDO          = 0 ; serial data output
104
 
105
        BIT_LWACT               = 4 ; see REG_CONFIG1
106
        BIT_SLEEP               = 1 ; sleep bit at older chips
107
        BIT_PWRDWN              = 0 ; power down bit at older chips
108
        BIT_PMEn                = 0 ; power management enabled
109
 
110
        BIT_LWPTN               = 2 ; see REG_CONFIG4
111
 
112
        BIT_ERTXTH              = 16 ; early TX threshold
113
        BIT_TOK                 = 15 ; transmit ok
114
        BIT_OWN                 = 13 ; tx DMA operation is completed
115
 
116
        BIT_ANE                 = 12 ; auto negotiation enable
117
 
118
        BIT_TXFD                = 8 ; 100base-T full duplex
119
        BIT_TX                  = 7 ; 100base-T
120
        BIT_10FD                = 6 ; 10base-T full duplex
121
        BIT_10                  = 5 ; 10base-T
122
        BIT_SELECTOR            = 0 ; binary encoded selector CSMA/CD=00001
123
 
124
        BIT_IFG1                = 25
125
        BIT_IFG0                = 24
126
 
127
        RX_CONFIG               = (RBLEN shl BIT_RBLEN) or \
128
                                  (RX_MXDMA shl BIT_RX_MXDMA) or \
129
                                  (1 shl BIT_NOWRAP) or \
130
                                  (RXFTH shl BIT_RXFTH) or\
3857 hidnplayr 131
                                  (1 shl BIT_AB) or \                   ; Accept broadcast packets
132
                                  (1 shl BIT_APM) or \                  ; Accept physical match packets
133
                                  (1 shl BIT_AER) or \                  ; Accept error packets
134
                                  (1 shl BIT_AR) or \                   ; Accept Runt packets (smaller then 64 bytes)
135
                                  (1 shl BIT_AM)                        ; Accept multicast packets
3545 hidnplayr 136
 
3857 hidnplayr 137
        RX_BUFFER_SIZE          = (8192 shl RBLEN);+16+1500
138
        NUM_TX_DESC             = 4                                     ; not user selectable
3545 hidnplayr 139
 
140
        EE_93C46_REG_ETH_ID     = 7 ; MAC offset
141
        EE_93C46_READ_CMD       = (6 shl 6) ; 110b + 6bit address
142
        EE_93C56_READ_CMD       = (6 shl 8) ; 110b + 8bit address
143
        EE_93C46_CMD_LENGTH     = 9  ; start bit + cmd + 6bit address
144
        EE_93C56_CMD_LENGTH     = 11 ; start bit + cmd + 8bit ddress
145
 
6227 hidnplayr 146
; See chapter "5.7 Transmit Configuration Register" of RTL8139D(L).pdf
3545 hidnplayr 147
        VER_RTL8139             = 1100000b
148
        VER_RTL8139A            = 1110000b
149
        VER_RTL8139AG           = 1110100b
150
        VER_RTL8139B            = 1111000b
151
        VER_RTL8130             = VER_RTL8139B
152
        VER_RTL8139C            = 1110100b
153
        VER_RTL8100             = 1111010b
154
        VER_RTL8100B            = 1110101b
155
        VER_RTL8139D            = VER_RTL8100B
156
        VER_RTL8139CP           = 1110110b
157
        VER_RTL8101             = 1110111b
158
 
159
        IDX_RTL8139             = 0
160
        IDX_RTL8139A            = 1
161
        IDX_RTL8139B            = 2
162
        IDX_RTL8139C            = 3
163
        IDX_RTL8100             = 4
164
        IDX_RTL8139D            = 5
165
        IDX_RTL8139D            = 6
166
        IDX_RTL8101             = 7
167
 
168
        ISR_SERR                = 1 shl 15
169
        ISR_TIMEOUT             = 1 shl 14
170
        ISR_LENCHG              = 1 shl 13
171
        ISR_FIFOOVW             = 1 shl 6
172
        ISR_PUN                 = 1 shl 5
173
        ISR_RXOVW               = 1 shl 4
174
        ISR_TER                 = 1 shl 3
175
        ISR_TOK                 = 1 shl 2
176
        ISR_RER                 = 1 shl 1
177
        ISR_ROK                 = 1 shl 0
178
 
179
        INTERRUPT_MASK          = ISR_ROK or \
3857 hidnplayr 180
                                  ISR_RER or \
181
                                  ISR_TOK or \
182
                                  ISR_TER or \
3545 hidnplayr 183
                                  ISR_RXOVW or \
184
                                  ISR_PUN or \
185
                                  ISR_FIFOOVW or \
186
                                  ISR_LENCHG or \
3857 hidnplayr 187
                                  ISR_TIMEOUT or \
188
                                  ISR_SERR
3545 hidnplayr 189
 
190
        TSR_OWN                 = 1 shl 13
191
        TSR_TUN                 = 1 shl 14
192
        TSR_TOK                 = 1 shl 15
193
 
194
        TSR_CDH                 = 1 shl 28
195
        TSR_OWC                 = 1 shl 29
196
        TSR_TABT                = 1 shl 30
197
        TSR_CRS                 = 1 shl 31
198
 
199
 
5045 hidnplayr 200
struct  device          ETH_DEVICE
3545 hidnplayr 201
 
5045 hidnplayr 202
        io_addr         dd ?
203
        pci_bus         dd ?
204
        pci_dev         dd ?
205
        irq_line        db ?
206
                        rb 3    ; align 4
3545 hidnplayr 207
 
5045 hidnplayr 208
        rx_buffer       dd ?
209
        rx_data_offset  dd ?
210
        curr_tx_desc    db ?
211
        hw_ver_id       db ?
212
                        rb 2    ; align 4
3545 hidnplayr 213
 
5045 hidnplayr 214
        TX_DESC         rd NUM_TX_DESC
3545 hidnplayr 215
 
5045 hidnplayr 216
ends
3545 hidnplayr 217
 
218
 
219
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220
;;                        ;;
221
;; proc START             ;;
222
;;                        ;;
223
;; (standard driver proc) ;;
224
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
225
 
5045 hidnplayr 226
proc START c, reason:dword, cmdline:dword
3545 hidnplayr 227
 
5045 hidnplayr 228
        cmp     [reason], DRV_ENTRY
229
        jne     .fail
3545 hidnplayr 230
 
5045 hidnplayr 231
        DEBUGF  2,"Loading driver\n"
232
        invoke  RegService, my_service, service_proc
3545 hidnplayr 233
        ret
234
 
235
  .fail:
236
        xor     eax, eax
237
        ret
238
 
239
endp
240
 
241
 
242
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
243
;;                        ;;
244
;; proc SERVICE_PROC      ;;
245
;;                        ;;
246
;; (standard driver proc) ;;
247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
248
 
249
proc service_proc stdcall, ioctl:dword
250
 
251
        mov     edx, [ioctl]
4470 hidnplayr 252
        mov     eax, [edx + IOCTL.io_code]
3545 hidnplayr 253
 
254
;------------------------------------------------------
255
 
256
        cmp     eax, 0 ;SRV_GETVERSION
257
        jne     @F
258
 
4470 hidnplayr 259
        cmp     [edx + IOCTL.out_size], 4
3545 hidnplayr 260
        jb      .fail
4470 hidnplayr 261
        mov     eax, [edx + IOCTL.output]
3545 hidnplayr 262
        mov     [eax], dword API_VERSION
263
 
264
        xor     eax, eax
265
        ret
266
 
267
;------------------------------------------------------
268
  @@:
269
        cmp     eax, 1 ;SRV_HOOK
270
        jne     .fail
271
 
4470 hidnplayr 272
        cmp     [edx + IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
3545 hidnplayr 273
        jb      .fail
274
 
4470 hidnplayr 275
        mov     eax, [edx + IOCTL.input]
3545 hidnplayr 276
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
277
        jne     .fail                                   ; other types arent supported for this card yet
278
 
279
; check if the device is already listed
280
 
281
        mov     esi, device_list
282
        mov     ecx, [devices]
283
        test    ecx, ecx
284
        jz      .firstdevice
285
 
286
        mov     ax, [eax+1]                             ; get the pci bus and device numbers
287
  .nextdevice:
288
        mov     ebx, [esi]
5045 hidnplayr 289
        cmp     al, byte[ebx + device.pci_bus]
3545 hidnplayr 290
        jne     @f
5045 hidnplayr 291
        cmp     ah, byte[ebx + device.pci_dev]
3545 hidnplayr 292
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
293
       @@:
294
        add     esi, 4
295
        loop    .nextdevice
296
 
297
 
298
; This device doesnt have its own eth_device structure yet, lets create one
299
  .firstdevice:
300
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
301
        jae     .fail
302
 
5045 hidnplayr 303
        allocate_and_clear ebx, sizeof.device, .fail      ; Allocate the buffer for device structure
3545 hidnplayr 304
 
305
; Fill in the direct call addresses into the struct
306
 
5045 hidnplayr 307
        mov     [ebx + device.reset], reset
308
        mov     [ebx + device.transmit], transmit
309
        mov     [ebx + device.unload], unload
310
        mov     [ebx + device.name], my_service
3545 hidnplayr 311
 
312
; save the pci bus and device numbers
313
 
4470 hidnplayr 314
        mov     eax, [edx + IOCTL.input]
3545 hidnplayr 315
        movzx   ecx, byte[eax+1]
5045 hidnplayr 316
        mov     [ebx + device.pci_bus], ecx
3545 hidnplayr 317
        movzx   ecx, byte[eax+2]
5045 hidnplayr 318
        mov     [ebx + device.pci_dev], ecx
3545 hidnplayr 319
 
320
; Now, it's time to find the base io addres of the PCI device
321
 
5045 hidnplayr 322
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
323
        mov     [ebx + device.io_addr], eax
3545 hidnplayr 324
 
325
; We've found the io address, find IRQ now
326
 
5045 hidnplayr 327
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
328
        mov     [ebx + device.irq_line], al
3545 hidnplayr 329
 
3856 hidnplayr 330
        DEBUGF  1, "Hooking into device, dev:%x, bus:%x, irq:%x, I/O addr:%x\n",\
5045 hidnplayr 331
        [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4
3545 hidnplayr 332
 
333
; Allocate the receive buffer
334
 
5045 hidnplayr 335
        invoke  CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW
3545 hidnplayr 336
        test    eax, eax
337
        jz      .err
5045 hidnplayr 338
        mov     [ebx + device.rx_buffer], eax
3545 hidnplayr 339
 
340
; Ok, the eth_device structure is ready, let's probe the device
341
 
342
        call    probe                                                   ; this function will output in eax
343
        test    eax, eax
344
        jnz     .err                                                    ; If an error occured, exit
345
 
346
        mov     eax, [devices]                                          ; Add the device structure to our device list
347
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
348
        inc     [devices]                                               ;
349
 
3685 hidnplayr 350
        call    reset
351
        test    eax, eax
352
        jnz     .destroy
353
 
5045 hidnplayr 354
        mov     [ebx + device.type], NET_TYPE_ETH
355
        invoke  NetRegDev
3545 hidnplayr 356
 
357
        cmp     eax, -1
358
        je      .destroy
359
 
360
        ret
361
 
362
; If the device was already loaded, find the device number and return it in eax
363
 
364
  .find_devicenum:
3856 hidnplayr 365
        DEBUGF  1, "Trying to find device number of already registered device\n"
5045 hidnplayr 366
        invoke  NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
3545 hidnplayr 367
                                                                        ; into a device number in edi
368
        mov     eax, edi                                                ; Application wants it in eax instead
3856 hidnplayr 369
        DEBUGF  1, "Kernel says: %u\n", eax
3545 hidnplayr 370
        ret
371
 
372
; If an error occured, remove all allocated data and exit (returning -1 in eax)
373
 
374
  .destroy:
3685 hidnplayr 375
        ; todo: unregister device from device_list
3545 hidnplayr 376
        ; todo: reset device into virgin state
377
 
378
  .err:
3856 hidnplayr 379
        DEBUGF  2, "Error, removing all data !\n"
5045 hidnplayr 380
        invoke  KernelFree, [ebx + device.rx_buffer]
381
        invoke  KernelFree, ebx
3545 hidnplayr 382
 
383
  .fail:
384
        or      eax, -1
385
        ret
386
 
387
;------------------------------------------------------
388
endp
389
 
390
 
391
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
392
;;                                                                        ;;
393
;;        Actual Hardware dependent code starts here                      ;;
394
;;                                                                        ;;
395
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
396
 
397
align 4
398
unload:
399
        ; TODO: (in this particular order)
400
        ;
401
        ; - Stop the device
402
        ; - Detach int handler
403
        ; - Remove device from local list (RTL8139_LIST)
404
        ; - call unregister function in kernel
405
        ; - Remove all allocated structures and buffers the card used
406
 
407
        or      eax, -1
5522 hidnplayr 408
        ret
3545 hidnplayr 409
 
410
 
411
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412
;;
413
;;  probe: enables the device (if it really is RTL8139)
414
;;
415
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
416
 
417
align 4
418
probe:
3856 hidnplayr 419
        DEBUGF  1, "Probing\n"
3545 hidnplayr 420
 
5045 hidnplayr 421
; Make the device a bus master
422
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
423
        or      al, PCI_CMD_MASTER
424
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
3545 hidnplayr 425
 
426
; get chip version
5045 hidnplayr 427
        set_io  [ebx + device.io_addr], 0
428
        set_io  [ebx + device.io_addr], REG_TXCONFIG + 2
3545 hidnplayr 429
        in      ax, dx
430
        shr     ah, 2
431
        shr     ax, 6
432
        and     al, 01111111b
433
 
434
; now find it in our array
435
        mov     ecx, HW_VER_ARRAY_SIZE-1
436
  .chip_ver_loop:
437
        cmp     al, [hw_ver_array + ecx]
438
        je      .chip_ver_found
439
        dec     ecx
440
        jns     .chip_ver_loop
441
  .unknown:
442
        mov     ecx, 8
443
  .chip_ver_found:
444
        cmp     ecx, 8
445
        ja      .unknown
446
 
5045 hidnplayr 447
        mov     [ebx + device.hw_ver_id], cl
3545 hidnplayr 448
 
449
        mov     ecx, [crosslist+ecx*4]
5045 hidnplayr 450
        mov     [ebx + device.name], ecx
3545 hidnplayr 451
 
3856 hidnplayr 452
        DEBUGF  1, "Chip version: %s\n", ecx
3545 hidnplayr 453
 
454
; wake up the chip
5045 hidnplayr 455
        set_io  [ebx + device.io_addr], 0
456
        set_io  [ebx + device.io_addr], REG_HLTCLK
3545 hidnplayr 457
        mov     al, 'R'         ; run the clock
458
        out     dx, al
459
 
460
; unlock config and BMCR registers
5045 hidnplayr 461
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 462
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
463
        out     dx, al
464
 
465
; enable power management
5045 hidnplayr 466
        set_io  [ebx + device.io_addr], REG_CONFIG1
3545 hidnplayr 467
        in      al, dx
5045 hidnplayr 468
        cmp     [ebx + device.hw_ver_id], IDX_RTL8139B
3545 hidnplayr 469
        jae     .new_chip
470
; wake up older chips
471
        and     al, not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN))
472
        out     dx, al
473
        jmp     .finish_wake_up
474
 
475
; set LWAKE pin to active high (default value).
476
; it is for Wake-On-LAN functionality of some motherboards.
477
; this signal is used to inform the motherboard to execute a wake-up process.
478
; only at newer chips.
479
  .new_chip:
480
        or      al, (1 shl BIT_PMEn)
481
        and     al, not (1 shl BIT_LWACT)
482
        out     dx, al
483
 
5045 hidnplayr 484
        set_io  [ebx + device.io_addr], REG_CONFIG4
3545 hidnplayr 485
        in      al, dx
486
        and     al, not (1 shl BIT_LWPTN)
487
        out     dx, al
488
 
489
; lock config and BMCR registers
490
  .finish_wake_up:
491
        xor     al, al
5045 hidnplayr 492
        set_io  [ebx + device.io_addr], 0
493
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 494
        out     dx, al
3856 hidnplayr 495
        DEBUGF  1, "probing done!\n"
3545 hidnplayr 496
 
3685 hidnplayr 497
        xor     eax, eax
3545 hidnplayr 498
 
3685 hidnplayr 499
        ret
500
 
501
 
3545 hidnplayr 502
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
503
;;
504
;;   reset: Set up all registers and descriptors, clear some values
505
;;
506
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
507
 
508
reset:
3856 hidnplayr 509
        DEBUGF  1, "Reset\n"
3545 hidnplayr 510
 
511
; attach int handler
5045 hidnplayr 512
        movzx   eax, [ebx + device.irq_line]
3545 hidnplayr 513
        DEBUGF  1, "Attaching int handler to irq %x\n", eax:1
5045 hidnplayr 514
        invoke  AttachIntHandler, eax, int_handler, ebx
3545 hidnplayr 515
        test    eax, eax
516
        jnz     @f
3856 hidnplayr 517
        DEBUGF  2, "Could not attach int handler!\n"
5045 hidnplayr 518
        or      eax, -1
519
        ret
3545 hidnplayr 520
       @@:
521
 
522
; reset chip
523
        DEBUGF  1, "Resetting chip\n"
5045 hidnplayr 524
        set_io  [ebx + device.io_addr], 0
525
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 526
        mov     al, 1 shl BIT_RST
527
        out     dx, al
528
        mov     cx, 1000                ; wait no longer for the reset
529
  .wait_for_reset:
530
        in      al, dx
531
        test    al, 1 shl BIT_RST
532
        jz      .reset_completed        ; RST remains 1 during reset
533
        dec     cx
534
        jns     .wait_for_reset
3856 hidnplayr 535
        DEBUGF  2, "Reset timeout!\n"
3545 hidnplayr 536
  .reset_completed:
537
 
3858 hidnplayr 538
; Read MAC address
539
        call    read_mac
540
 
3545 hidnplayr 541
; unlock config and BMCR registers
5045 hidnplayr 542
        set_io  [ebx + device.io_addr], 0
543
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 544
        mov     al, (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
545
        out     dx, al
546
 
547
; initialize multicast registers (no filtering)
548
        mov     eax, 0xffffffff
5045 hidnplayr 549
        set_io  [ebx + device.io_addr], REG_MAR0
3545 hidnplayr 550
        out     dx, eax
5045 hidnplayr 551
        set_io  [ebx + device.io_addr], REG_MAR4
3545 hidnplayr 552
        out     dx, eax
553
 
554
; enable Rx/Tx
555
        mov     al, (1 shl BIT_RE) or (1 shl BIT_TE)
5045 hidnplayr 556
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 557
        out     dx, al
558
 
559
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
560
; accept broadcast packets, accept physical match packets
3858 hidnplayr 561
        mov     eax, RX_CONFIG
5045 hidnplayr 562
        set_io  [ebx + device.io_addr], REG_RXCONFIG
3858 hidnplayr 563
        out     dx, eax
3545 hidnplayr 564
 
565
; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144
566
        mov     eax, (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0
5045 hidnplayr 567
        set_io  [ebx + device.io_addr], REG_TXCONFIG
3545 hidnplayr 568
        out     dx, eax
569
 
570
; enable auto negotiation
5045 hidnplayr 571
        set_io  [ebx + device.io_addr], REG_BMCR
3545 hidnplayr 572
        in      ax, dx
573
        or      ax, (1 shl BIT_ANE)
574
        out     dx, ax
575
 
576
; set auto negotiation advertisement
5045 hidnplayr 577
        set_io  [ebx + device.io_addr], REG_ANAR
3545 hidnplayr 578
        in      ax, dx
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)
580
        out     dx, ax
581
 
582
; lock config and BMCR registers
583
        xor     eax, eax
5045 hidnplayr 584
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 585
        out     dx, al
586
 
587
; init RX/TX pointers
5045 hidnplayr 588
        mov     [ebx + device.rx_data_offset], eax
589
        mov     [ebx + device.curr_tx_desc], al
590
;        set_io  [ebx + device.io_addr], REG_CAPR
3545 hidnplayr 591
;        out     dx, ax
592
 
593
; clear packet/byte counters
5045 hidnplayr 594
        lea     edi, [ebx + device.bytes_tx]
3545 hidnplayr 595
        mov     ecx, 6
596
        rep     stosd
597
 
598
; clear missing packet counter
5045 hidnplayr 599
        set_io  [ebx + device.io_addr], REG_MPC
3545 hidnplayr 600
        out     dx, eax
601
 
602
; set RxBuffer address, init RX buffer offset
5045 hidnplayr 603
        mov     eax, [ebx + device.rx_buffer]
3545 hidnplayr 604
        mov     dword[eax], 0                   ; clear receive flags for first packet (really needed??)
3685 hidnplayr 605
        DEBUGF  1, "RX buffer virtual addr=0x%x\n", eax
5045 hidnplayr 606
        invoke  GetPhysAddr
3857 hidnplayr 607
        DEBUGF  1, "RX buffer physical addr=0x%x\n", eax
5045 hidnplayr 608
        set_io  [ebx + device.io_addr], REG_RBSTART
3545 hidnplayr 609
        out     dx, eax
610
 
611
; enable interrupts
5045 hidnplayr 612
        set_io  [ebx + device.io_addr], 0
613
        set_io  [ebx + device.io_addr], REG_IMR
3545 hidnplayr 614
        mov     ax, INTERRUPT_MASK
615
        out     dx, ax
616
 
617
; Set the mtu, kernel will be able to send now
5045 hidnplayr 618
        mov     [ebx + device.mtu], 1514
3545 hidnplayr 619
 
6227 hidnplayr 620
        call    link
3545 hidnplayr 621
 
622
; Indicate that we have successfully reset the card
623
        xor     eax, eax
624
        ret
625
 
626
 
627
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
628
;;                                         ;;
629
;; Transmit                                ;;
630
;;                                         ;;
5522 hidnplayr 631
;; In: pointer to device structure in ebx  ;;
3545 hidnplayr 632
;;                                         ;;
633
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5045 hidnplayr 634
 
5522 hidnplayr 635
proc transmit stdcall bufferptr
5045 hidnplayr 636
 
637
        pushf
638
        cli
639
 
5522 hidnplayr 640
        mov     esi, [bufferptr]
641
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
642
        lea     eax, [esi + NET_BUFF.data]
5045 hidnplayr 643
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
3545 hidnplayr 644
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
645
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
646
        [eax+13]:2,[eax+12]:2
647
 
5522 hidnplayr 648
        cmp     [esi + NET_BUFF.length], 1514
3545 hidnplayr 649
        ja      .fail
5522 hidnplayr 650
        cmp     [esi + NET_BUFF.length], 60
3545 hidnplayr 651
        jb      .fail
652
 
653
; check if we own the current discriptor
5045 hidnplayr 654
        set_io  [ebx + device.io_addr], 0
655
        set_io  [ebx + device.io_addr], REG_TSD0
656
        movzx   ecx, [ebx + device.curr_tx_desc]
3545 hidnplayr 657
        shl     ecx, 2
658
        add     edx, ecx
659
        in      eax, dx
660
        test    eax, (1 shl BIT_OWN)
661
        jz      .wait_to_send
662
 
663
  .send_packet:
664
; Set the buffer address
5045 hidnplayr 665
        set_io  [ebx + device.io_addr], REG_TSAD0
5522 hidnplayr 666
        mov     [ebx + device.TX_DESC+ecx], esi
667
        mov     eax, esi
668
        add     eax, [eax + NET_BUFF.offset]
5045 hidnplayr 669
        invoke  GetPhysAddr
3545 hidnplayr 670
        out     dx, eax
671
 
672
; And the size of the buffer
5045 hidnplayr 673
        set_io  [ebx + device.io_addr], REG_TSD0
5522 hidnplayr 674
        mov     eax, [esi + NET_BUFF.length]
3545 hidnplayr 675
        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
676
        out     dx, eax
677
 
5522 hidnplayr 678
; get next descriptor
679
        inc     [ebx + device.curr_tx_desc]
680
        and     [ebx + device.curr_tx_desc], NUM_TX_DESC-1
681
 
682
; Update stats
683
        inc     [ebx + device.packets_tx]
684
        mov     ecx, [esi + NET_BUFF.length]
685
        add     dword [ebx + device.bytes_tx], ecx
686
        adc     dword [ebx + device.bytes_tx+4], 0
687
 
3545 hidnplayr 688
        DEBUGF  1, "Packet Sent!\n"
5127 hidnplayr 689
        popf
3545 hidnplayr 690
        xor     eax, eax
5045 hidnplayr 691
        ret
3545 hidnplayr 692
 
693
  .wait_to_send:
694
        DEBUGF  1, "Waiting for timeout\n"
695
 
696
        push    edx
697
        mov     esi, 30
5045 hidnplayr 698
        invoke  Sleep
3545 hidnplayr 699
        pop     edx
700
 
701
        in      ax, dx
702
        test    ax, (1 shl BIT_OWN)
703
        jnz     .send_packet
704
 
705
        pusha
706
        call    reset                            ; if chip hung, reset it
707
        popa
708
 
709
        jmp     .send_packet
710
 
711
  .fail:
3856 hidnplayr 712
        DEBUGF  2, "transmit failed!\n"
5522 hidnplayr 713
        invoke  NetFree, [bufferptr]
5045 hidnplayr 714
        popf
3545 hidnplayr 715
        or      eax, -1
5045 hidnplayr 716
        ret
3545 hidnplayr 717
 
5045 hidnplayr 718
endp
3545 hidnplayr 719
 
720
 
721
 
722
 
5045 hidnplayr 723
 
3545 hidnplayr 724
;;;;;;;;;;;;;;;;;;;;;;;
725
;;                   ;;
726
;; Interrupt handler ;;
727
;;                   ;;
728
;;;;;;;;;;;;;;;;;;;;;;;
729
 
730
align 4
731
int_handler:
732
 
733
        push    ebx esi edi
734
 
3856 hidnplayr 735
        DEBUGF  1, "INT\n"
3545 hidnplayr 736
 
737
; find pointer of device wich made IRQ occur
738
        mov     ecx, [devices]
739
        test    ecx, ecx
740
        jz      .nothing
741
        mov     esi, device_list
742
  .nextdevice:
743
        mov     ebx, [esi]
744
 
5045 hidnplayr 745
        set_io  [ebx + device.io_addr], 0
746
        set_io  [ebx + device.io_addr], REG_ISR
3545 hidnplayr 747
        in      ax, dx                          ; Get interrupt status
748
        out     dx, ax                          ; send it back to ACK
749
        test    ax, ax
750
        jnz     .got_it
751
  .continue:
752
        add     esi, 4
753
        dec     ecx
754
        jnz     .nextdevice
755
  .nothing:
756
        pop     edi esi ebx
757
        xor     eax, eax
758
 
759
        ret                                     ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
760
 
761
  .got_it:
762
 
763
        DEBUGF  1, "Device: %x Status: %x\n", ebx, ax
764
 
765
;----------------------------------------------------
766
; Received packet ok?
767
 
768
        test    ax, ISR_ROK
769
        jz      @f
770
        push    ax
771
 
772
  .receive:
5045 hidnplayr 773
        set_io  [ebx + device.io_addr], 0
774
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 775
        in      al, dx
776
        test    al, BUFE                        ; test if RX buffer is empty
777
        jnz     .finish
778
 
3856 hidnplayr 779
        DEBUGF  1, "RX:\n"
3545 hidnplayr 780
 
5045 hidnplayr 781
        mov     eax, [ebx + device.rx_buffer]
782
        add     eax, [ebx + device.rx_data_offset]
3545 hidnplayr 783
        test    byte [eax], (1 shl BIT_ROK)     ; check if packet is ok
784
        jz      .reset_rx
785
 
786
; packet is ok, copy it
787
        movzx   ecx, word [eax+2]               ; packet length
788
        sub     cx, 4                           ; don't copy CRC
789
 
790
; Update stats
5045 hidnplayr 791
        add     dword [ebx + device.bytes_rx], ecx
792
        adc     dword [ebx + device.bytes_rx + 4], 0
793
        inc     [ebx + device.packets_rx]
3545 hidnplayr 794
 
795
        DEBUGF  1, "Received %u bytes\n", ecx
796
 
797
        push    ebx eax ecx
5522 hidnplayr 798
        add     ecx, NET_BUFF.data
799
        invoke  NetAlloc, ecx                   ; Allocate a buffer to put packet into
3545 hidnplayr 800
        pop     ecx
801
        test    eax, eax                        ; Test if we allocated succesfully
802
        jz      .abort
5522 hidnplayr 803
        mov     [eax + NET_BUFF.length], ecx
804
        mov     [eax + NET_BUFF.device], ebx
805
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
3545 hidnplayr 806
 
5522 hidnplayr 807
        lea     edi, [eax + NET_BUFF.data]      ; Where we will copy too
3545 hidnplayr 808
        mov     esi, [esp]                      ; The buffer we will copy from
809
        add     esi, 4                          ; Dont copy CRC
810
 
5522 hidnplayr 811
        push    .abort                          ; return addr for Eth_input
812
        push    eax                             ; buffer ptr for Eth_input
3545 hidnplayr 813
 
814
  .copy:
815
        shr     ecx, 1
816
        jnc     .nb
817
        movsb
818
  .nb:
819
        shr     ecx, 1
820
        jnc     .nw
821
        movsw
822
  .nw:
823
        jz      .nd
824
        rep     movsd
825
  .nd:
826
 
5522 hidnplayr 827
        jmp     [EthInput]                      ; Send it to kernel
3545 hidnplayr 828
 
829
  .abort:
830
        pop     eax ebx
831
                                                ; update eth_data_start_offset
832
        movzx   eax, word [eax+2]               ; packet length
5045 hidnplayr 833
        add     eax, [ebx + device.rx_data_offset]
3545 hidnplayr 834
        add     eax, 4+3                        ; packet header is 4 bytes long + dword alignment
835
        and     eax, not 3                      ; dword alignment
836
 
837
        cmp     eax, RX_BUFFER_SIZE
838
        jb      .no_wrap
3856 hidnplayr 839
        DEBUGF  1, "Wrapping\n"
3545 hidnplayr 840
        sub     eax, RX_BUFFER_SIZE
841
  .no_wrap:
5045 hidnplayr 842
        mov     [ebx + device.rx_data_offset], eax
3545 hidnplayr 843
        DEBUGF  1, "New RX ptr: %d\n", eax
844
 
5045 hidnplayr 845
        set_io  [ebx + device.io_addr], 0
846
        set_io  [ebx + device.io_addr], REG_CAPR                        ; update 'Current Address of Packet Read register'
3545 hidnplayr 847
        sub     eax, 0x10                       ; value 0x10 is a constant for CAPR
3857 hidnplayr 848
        out     dx, ax
3545 hidnplayr 849
 
850
        jmp     .receive                        ; check for multiple packets
851
 
852
  .reset_rx:
853
        test    byte [eax], (1 shl BIT_CRC)
854
        jz      .no_crc_error
3856 hidnplayr 855
        DEBUGF  2, "RX: CRC error!\n"
3545 hidnplayr 856
 
857
  .no_crc_error:
858
        test    byte [eax], (1 shl BIT_FAE)
859
        jz      .no_fae_error
3856 hidnplayr 860
        DEBUGF  2, "RX: Frame alignment error!\n"
3545 hidnplayr 861
 
862
  .no_fae_error:
863
        DEBUGF  1, "Reset RX\n"
864
        in      al, dx                          ; read command register
865
        push    ax
866
        and     al, not (1 shl BIT_RE)          ; Clear the RE bit
867
        out     dx, al
868
        pop     ax
869
        out     dx, al                          ; write original command back
870
 
871
        add     edx, REG_RXCONFIG - REG_COMMAND         ; Restore RX configuration
872
        mov     ax, RX_CONFIG
873
        out     dx, ax
874
 
875
  .finish:
876
        pop     ax
877
 
878
;----------------------------------------------------
879
; Transmit ok / Transmit error
880
  @@:
881
        test    ax, ISR_TOK + ISR_TER
882
        jz      @f
883
 
3857 hidnplayr 884
        DEBUGF  1, "Transmit done!\n"
885
 
3545 hidnplayr 886
        push    ax
887
        mov     ecx, (NUM_TX_DESC-1)*4
888
  .txdescloop:
5045 hidnplayr 889
        set_io  [ebx + device.io_addr], 0
890
        set_io  [ebx + device.io_addr], REG_TSD0
3545 hidnplayr 891
        add     edx, ecx
892
        in      eax, dx
893
 
894
        test    eax, TSR_OWN                    ; DMA operation completed
895
        jz      .notthisone
896
 
5045 hidnplayr 897
        cmp     [ebx + device.TX_DESC+ecx], 0
3545 hidnplayr 898
        je      .notthisone
899
 
3857 hidnplayr 900
        DEBUGF  1, "TSD: 0x%x\n", eax
3545 hidnplayr 901
 
3857 hidnplayr 902
        test    eax, TSR_TUN
903
        jz      .no_bun
904
        DEBUGF  2, "TX: FIFO Buffer underrun!\n"
905
 
906
  .no_bun:
907
        test    eax, TSR_OWC
908
        jz      .no_owc
909
        DEBUGF  2, "TX: OWC!\n"
910
 
911
  .no_owc:
912
        test    eax, TSR_TABT
913
        jz      .no_tabt
914
        DEBUGF  2, "TX: TABT!\n"
915
 
916
  .no_tabt:
917
        test    eax, TSR_CRS
918
        jz      .no_csl
919
        DEBUGF  2, "TX: Carrier Sense Lost!\n"
920
 
921
  .no_csl:
922
        test    eax, TSR_TOK
923
        jz      .no_tok
924
        DEBUGF  1, "TX: Transmit OK!\n"
925
 
926
  .no_tok:
5045 hidnplayr 927
        DEBUGF  1, "free transmit buffer 0x%x\n", [ebx + device.TX_DESC+ecx]:8
3545 hidnplayr 928
        push    ecx ebx
5522 hidnplayr 929
        invoke  NetFree, [ebx + device.TX_DESC+ecx]
3545 hidnplayr 930
        pop     ebx ecx
5045 hidnplayr 931
        mov     [ebx + device.TX_DESC+ecx], 0
3545 hidnplayr 932
 
933
  .notthisone:
934
        sub     ecx, 4
3857 hidnplayr 935
        jae     .txdescloop
3545 hidnplayr 936
        pop     ax
937
 
938
;----------------------------------------------------
939
; Rx buffer overflow ?
940
  @@:
941
        test    ax, ISR_RXOVW
942
        jz      @f
943
 
944
        push    ax
3856 hidnplayr 945
        DEBUGF  2, "RX:buffer overflow!\n"
3545 hidnplayr 946
 
5045 hidnplayr 947
        set_io  [ebx + device.io_addr], 0
948
        set_io  [ebx + device.io_addr], REG_ISR
6227 hidnplayr 949
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
3545 hidnplayr 950
        out     dx, ax
951
        pop     ax
952
 
953
;----------------------------------------------------
954
; Packet underrun?
955
  @@:
956
        test    ax, ISR_PUN
957
        jz      @f
958
 
4449 hidnplayr 959
        DEBUGF  1, "Packet underrun or link changed!\n"
3545 hidnplayr 960
 
6227 hidnplayr 961
        call    link
4449 hidnplayr 962
 
3545 hidnplayr 963
;----------------------------------------------------
964
; Receive FIFO overflow ?
965
  @@:
966
        test    ax, ISR_FIFOOVW
967
        jz      @f
968
 
969
        push    ax
4449 hidnplayr 970
        DEBUGF  2, "RX fifo overflow!\n"
3545 hidnplayr 971
 
5045 hidnplayr 972
        set_io  [ebx + device.io_addr], 0
973
        set_io  [ebx + device.io_addr], REG_ISR
6227 hidnplayr 974
        mov     ax, ISR_FIFOOVW or ISR_RXOVW or ISR_ROK
3545 hidnplayr 975
        out     dx, ax
976
        pop     ax
977
 
978
;----------------------------------------------------
4449 hidnplayr 979
; cable length changed ?
3545 hidnplayr 980
  @@:
981
        test    ax, ISR_LENCHG
982
        jz      .fail
983
 
4449 hidnplayr 984
        DEBUGF  2, "Cable length changed!\n"
985
 
6227 hidnplayr 986
        call    link
3545 hidnplayr 987
 
988
  .fail:
989
        pop     edi esi ebx
990
        xor     eax, eax
991
        inc     eax
992
 
993
        ret
994
 
995
 
996
 
997
 
6227 hidnplayr 998
;;;;;;;;;;;;;;;;;;;;;;;
999
;;                   ;;
1000
;; Check link status ;;
1001
;;                   ;;
1002
;;;;;;;;;;;;;;;;;;;;;;;
3545 hidnplayr 1003
 
1004
align 4
6227 hidnplayr 1005
link:
3857 hidnplayr 1006
        DEBUGF  1, "Checking link status:\n"
3545 hidnplayr 1007
 
5045 hidnplayr 1008
        set_io  [ebx + device.io_addr], 0
1009
        set_io  [ebx + device.io_addr], REG_MSR
6227 hidnplayr 1010
        in      ax, dx
3545 hidnplayr 1011
 
1012
        test    al, 1 shl 2             ; 0 = link ok 1 = link fail
1013
        jnz     .notconnected
1014
 
6227 hidnplayr 1015
        mov     ecx, ETH_LINK_10M
3545 hidnplayr 1016
        test    al, 1 shl 3             ; 0 = 100 Mbps 1 = 10 Mbps
6227 hidnplayr 1017
        jnz     @f
1018
        mov     ecx, ETH_LINK_100M
1019
  @@:
3545 hidnplayr 1020
 
6227 hidnplayr 1021
        set_io  [ebx + device.io_addr], REG_BMCR
1022
        in      ax, dx
1023
        test    ax, 1 shl 8             ; Duplex mode
1024
        jz      @f
1025
        or      ecx, ETH_LINK_FD
1026
  @@:
3545 hidnplayr 1027
 
6227 hidnplayr 1028
        mov     [ebx + device.state], ecx
5045 hidnplayr 1029
        invoke  NetLinkChanged
6227 hidnplayr 1030
        DEBUGF  2, "link is up\n"
3545 hidnplayr 1031
        ret
1032
 
1033
  .notconnected:
5045 hidnplayr 1034
        mov     [ebx + device.state], ETH_LINK_DOWN
1035
        invoke  NetLinkChanged
6227 hidnplayr 1036
        DEBUGF  2, "link is down\n"
3545 hidnplayr 1037
        ret
1038
 
1039
 
1040
 
1041
;;;;;;;;;;;;;;;;;;;;;;;
1042
;;                   ;;
1043
;; Write MAC address ;;
1044
;;                   ;;
1045
;;;;;;;;;;;;;;;;;;;;;;;
1046
 
1047
align 4
1048
write_mac:      ; in: mac pushed onto stack (as 3 words)
1049
 
3856 hidnplayr 1050
        DEBUGF  1, "Writing MAC\n"
3545 hidnplayr 1051
 
1052
; disable all in command registers
5045 hidnplayr 1053
        set_io  [ebx + device.io_addr], 0
1054
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 1055
        xor     eax, eax
1056
        out     dx, al
1057
 
5045 hidnplayr 1058
        set_io  [ebx + device.io_addr], REG_IMR
3545 hidnplayr 1059
        xor     eax, eax
1060
        out     dx, ax
1061
 
5045 hidnplayr 1062
        set_io  [ebx + device.io_addr], REG_ISR
3545 hidnplayr 1063
        mov     eax, -1
1064
        out     dx, ax
1065
 
1066
; enable writing
5045 hidnplayr 1067
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 1068
        mov     eax, REG_9346CR_WE
1069
        out     dx, al
1070
 
1071
 ; write the mac ...
5045 hidnplayr 1072
        set_io  [ebx + device.io_addr], REG_IDR0
3545 hidnplayr 1073
        pop     eax
1074
        out     dx, eax
1075
 
5045 hidnplayr 1076
        set_io  [ebx + device.io_addr], REG_IDR0+4
3545 hidnplayr 1077
        xor     eax, eax
1078
        pop     ax
1079
        out     dx, eax
1080
 
1081
; disable writing
5045 hidnplayr 1082
        set_io  [ebx + device.io_addr], REG_9346CR
3545 hidnplayr 1083
        xor     eax, eax
1084
        out     dx, al
1085
 
3856 hidnplayr 1086
        DEBUGF  1, "MAC write ok!\n"
3545 hidnplayr 1087
 
1088
; Notice this procedure does not ret, but continues to read_mac instead.
1089
 
1090
 
1091
;;;;;;;;;;;;;;;;;;;;;;
1092
;;                  ;;
1093
;; Read MAC address ;;
1094
;;                  ;;
1095
;;;;;;;;;;;;;;;;;;;;;;
1096
 
1097
read_mac:
3857 hidnplayr 1098
        DEBUGF  1, "Reading MAC:\n"
3545 hidnplayr 1099
 
5045 hidnplayr 1100
        set_io  [ebx + device.io_addr], 0
1101
        lea     edi, [ebx + device.mac]
3545 hidnplayr 1102
        in      eax, dx
1103
        stosd
1104
        add     edx, 4
1105
        in      ax, dx
1106
        stosw
1107
 
3857 hidnplayr 1108
        DEBUGF  1, "%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2
3545 hidnplayr 1109
 
1110
        ret
1111
 
1112
 
1113
; End of code
1114
 
5045 hidnplayr 1115
data fixups
1116
end data
3545 hidnplayr 1117
 
5045 hidnplayr 1118
include '../peimport.inc'
1119
 
3545 hidnplayr 1120
my_service      db 'RTL8139',0                    ; max 16 chars include zero
1121
 
1122
device_1        db 'Realtek 8139',0
1123
device_2        db 'Realtek 8139A',0
1124
device_3        db 'Realtek 8139B',0
1125
device_4        db 'Realtek 8139C',0
1126
device_5        db 'Realtek 8100',0
1127
device_6        db 'Realtek 8139D',0
1128
device_7        db 'Realtek 8139CP',0
1129
device_8        db 'Realtek 8101',0
1130
device_unknown  db 'Unknown RTL8139 clone', 0
1131
 
1132
crosslist:
1133
        dd device_1
1134
        dd device_2
1135
        dd device_3
1136
        dd device_4
1137
        dd device_5
1138
        dd device_6
1139
        dd device_7
1140
        dd device_8
1141
        dd device_unknown
1142
 
1143
hw_ver_array:                    ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with
1144
        db VER_RTL8139
1145
        db VER_RTL8139A
1146
        db VER_RTL8139B
1147
        db VER_RTL8139C
1148
        db VER_RTL8100
1149
        db VER_RTL8139D
1150
        db VER_RTL8139CP
1151
        db VER_RTL8101
1152
        db 0
1153
 
1154
HW_VER_ARRAY_SIZE = $-hw_ver_array
1155
 
1156
include_debug_strings                           ; All data wich FDO uses will be included here
1157
 
5045 hidnplayr 1158
align 4
1159
devices         dd 0
3545 hidnplayr 1160
device_list     rd MAX_DEVICES                   ; This list contains all pointers to device structures the driver is handling
1161