Subversion Repositories Kolibri OS

Rev

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

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