Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
5363 yogev_ezra 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
3545 hidnplayr 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;  3Com network driver for KolibriOS                           ;;
7
;;                                                              ;;
5073 hidnplayr 8
;;  Ported to KolibriOS net-branch by hidnplayr                 ;;
3545 hidnplayr 9
;;                                                              ;;
10
;;  Thanks to: scrap metal recyclers, whom provide me with      ;;
11
;;                         loads of hardware                    ;;
12
;;             diamond: who makes me understand KolibriOS       ;;
13
;;                                                              ;;
14
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5073 hidnplayr 15
;;
16
;; Original copyright from menuetos driver:
17
;;
3545 hidnplayr 18
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;                                                                         ;;
20
;;  3C59X.INC                                                              ;;
21
;;                                                                         ;;
22
;;  Ethernet driver for Menuet OS                                          ;;
23
;;                                                                         ;;
24
;;  Driver for 3Com fast etherlink 3c59x and                               ;;
25
;;         etherlink XL 3c900 and 3c905 cards                              ;;
26
;;  References:                                                            ;;
27
;;    www.3Com.com - data sheets                                           ;;
28
;;    DP83840A.pdf - ethernet physical layer                               ;;
29
;;    3c59x.c - linux driver                                               ;;
30
;;    ethernet driver template by Mike Hibbett                             ;;
31
;;                                                                         ;;
32
;;  Credits                                                                ;;
33
;;   Mike Hibbett,                                                         ;;
34
;;         who kindly supplied me with a 3Com905C-TX-M card                ;;
35
;;                                                                         ;;
36
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
37
;;
38
;; Copyright (c) 2004, Endre Kozma 
39
;; All rights reserved.
40
;;
41
;; Redistribution  and  use  in  source  and  binary  forms, with or without
42
;; modification, are permitted provided  that  the following  conditions are
43
;; met:
44
;;
45
;; 1. Redistributions of source code must retain the above  copyright notice,
46
;;    this list of conditions and the following disclaimer.
47
;;
48
;; 2. Redistributions  in  binary form  must  reproduce  the above copyright
49
;;    notice, this  list of conditions  and the  following disclaimer in the
50
;;    documentation and/or other  materials  provided with  the distribution.
51
;;
52
;; 3. The name of the author may not be used to  endorse or promote products
53
;;    derived from this software without  specific prior  written permission.
54
;;
55
;; THIS SOFTWARE IS  PROVIDED  BY  THE  AUTHOR  ``AS IS'' AND ANY EXPRESS OR
56
;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
57
;; OF  MERCHANTABILITY AND FITNESS  FOR A PARTICULAR  PURPOSE ARE DISCLAIMED.
58
;; IN  NO  EVENT  SHALL  THE  AUTHOR  BE  LIABLE  FOR  ANY  DIRECT, INDIRECT,
59
;; INCIDENTAL, SPECIAL, EXEMPLARY, OR  CONSEQUENTIAL DAMAGES (INCLUDING, BUT
60
;; NOT LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61
;; DATA, OR  PROFITS; OR  BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON ANY
62
;; THEORY OF  LIABILITY, WHETHER IN  CONTRACT,  STRICT  LIABILITY,  OR  TORT
63
;; (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY WAY OUT OF THE USE OF
64
;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65
;;
66
;;  History
67
;;  =======
68
;;  $Log: 3C59X.INC,v $
69
;;  Revision 1.3  2004/07/11 12:21:12  kozma
70
;;  Support of vortex chips (3c59x) added.
71
;;  Support of 3c920 and 3c982 added.
72
;;  Corrections.
73
;;
74
;;  Revision 1.2  2004/06/12 19:40:20  kozma
75
;;  Function e3c59x_set_available_media added in order to set
76
;;  the default media in case auto detection finds no valid link.
77
;;  Incorrect mii check removed (3c900 Cyclone works now).
78
;;  Cleanups.
79
;;
80
;;  Revision 1.1  2004/06/12 18:27:15  kozma
81
;;  Initial revision
82
;;
83
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
84
 
85
 
5073 hidnplayr 86
format PE DLL native
87
entry START
3545 hidnplayr 88
 
5073 hidnplayr 89
        CURRENT_API             = 0x0200
90
        COMPATIBLE_API          = 0x0100
91
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
92
 
3545 hidnplayr 93
        MAX_DEVICES             = 16
94
        FORCE_FD                = 0     ; forcing full duplex mode makes sense at some cards and link types
95
 
5073 hidnplayr 96
        NUM_RX_DESC             = 4     ; a power of 2 number
97
        NUM_TX_DESC             = 4     ; a power of 2 number
98
 
3545 hidnplayr 99
        __DEBUG__               = 1
5073 hidnplayr 100
        __DEBUG_LEVEL__         = 2     ; 1 = verbose, 2 = errors only
3545 hidnplayr 101
 
5073 hidnplayr 102
section '.flat' readable writable executable
103
 
104
include '../proc32.inc'
4467 hidnplayr 105
include '../struct.inc'
106
include '../macros.inc'
3545 hidnplayr 107
include '../fdo.inc'
5074 hidnplayr 108
include '../netdrv.inc'
3545 hidnplayr 109
 
110
; Registers
111
        REG_POWER_MGMT_CTRL     = 0x7c
112
        REG_UP_LIST_PTR         = 0x38
113
        REG_UP_PKT_STATUS       = 0x30
114
        REG_TX_FREE_THRESH      = 0x2f
115
        REG_DN_LIST_PTR         = 0x24
116
        REG_DMA_CTRL            = 0x20
117
        REG_TX_STATUS           = 0x1b
118
        REG_RX_STATUS           = 0x18
119
        REG_TX_DATA             = 0x10
120
 
121
; Common window registers
122
        REG_INT_STATUS          = 0xe
123
        REG_COMMAND             = 0xe
124
 
125
; Register window 7
126
        REG_MASTER_STATUS       = 0xc
127
        REG_POWER_MGMT_EVENT    = 0xc
128
        REG_MASTER_LEN          = 0x6
129
        REG_VLAN_ETHER_TYPE     = 0x4
130
        REG_VLAN_MASK           = 0x0
131
        REG_MASTER_ADDRESS      = 0x0
132
 
133
; Register window 6
134
        REG_BYTES_XMITTED_OK    = 0xc
135
        REG_BYTES_RCVD_OK       = 0xa
136
        REG_UPPER_FRAMES_OK     = 0x9
137
        REG_FRAMES_DEFERRED     = 0x8
138
        REG_FRAMES_RCVD_OK      = 0x7
139
        REG_FRAMES_XMITTED_OK   = 0x6
140
        REG_RX_OVERRUNS         = 0x5
141
        REG_LATE_COLLISIONS     = 0x4
142
        REG_SINGLE_COLLISIONS   = 0x3
143
        REG_MULTIPLE_COLLISIONS = 0x2
144
        REG_SQE_ERRORS          = 0x1
145
        REG_CARRIER_LOST        = 0x0
146
 
147
; Register window 5
148
        REG_INDICATION_ENABLE   = 0xc
149
        REG_INTERRUPT_ENABLE    = 0xa
150
        REG_TX_RECLAIM_THRESH   = 0x9
151
        REG_RX_FILTER           = 0x8
152
        REG_RX_EARLY_THRESH     = 0x6
153
        REG_TX_START_THRESH     = 0x0
154
 
155
; Register window 4
156
        REG_UPPER_BYTES_OK      = 0xe
157
        REG_BAD_SSD             = 0xc
158
        REG_MEDIA_STATUS        = 0xa
159
        REG_PHYSICAL_MGMT       = 0x8
160
        REG_NETWORK_DIAGNOSTIC  = 0x6
161
        REG_FIFO_DIAGNOSTIC     = 0x4
162
        REG_VCO_DIAGNOSTIC      = 0x2   ; may not supported
163
 
164
; Bits in register window 4
165
        BIT_AUTOSELECT          = 24
166
 
167
; Register window 3
168
        REG_TX_FREE             = 0xc
169
        REG_RX_FREE             = 0xa
170
        REG_MEDIA_OPTIONS       = 0x8
171
        REG_MAC_CONTROL         = 0x6
172
        REG_MAX_PKT_SIZE        = 0x4
173
        REG_INTERNAL_CONFIG     = 0x0
174
 
175
; Register window 2
176
        REG_RESET_OPTIONS       = 0xc
177
        REG_STATION_MASK_HI     = 0xa
178
        REG_STATION_MASK_MID    = 0x8
179
        REG_STATION_MASK_LO     = 0x6
180
        REG_STATION_ADDRESS_HI  = 0x4
181
        REG_STATION_ADDRESS_MID = 0x2
182
        REG_STATION_ADDRESS_LO  = 0x0
183
 
184
; Register window 1
185
        REG_TRIGGER_BITS        = 0xc
186
        REG_SOS_BITS            = 0xa
187
        REG_WAKE_ON_TIMER       = 0x8
188
        REG_SMB_RXBYTES         = 0x7
189
        REG_SMB_DIAG            = 0x5
190
        REG_SMB_ARB             = 0x4
191
        REG_SMB_STATUS          = 0x2
192
        REG_SMB_ADDRESS         = 0x1
193
        REG_SMB_FIFO_DATA       = 0x0
194
 
195
; Register window 0
196
        REG_EEPROM_DATA         = 0xc
197
        REG_EEPROM_COMMAND      = 0xa
198
        REG_BIOS_ROM_DATA       = 0x8
199
        REG_BIOS_ROM_ADDR       = 0x4
200
 
201
; Physical management bits
202
        BIT_MGMT_DIR            = 2     ; drive with the data written in mgmtData
203
        BIT_MGMT_DATA           = 1     ; MII management data bit
204
        BIT_MGMT_CLK            = 0     ; MII management clock
205
 
206
; MII commands
207
        MII_CMD_MASK            = (1111b shl 10)
208
        MII_CMD_READ            = (0110b shl 10)
209
        MII_CMD_WRITE           = (0101b shl 10)
210
 
211
; eeprom bits and commands
212
        EEPROM_CMD_READ         = 0x80
213
        EEPROM_BIT_BUSY         = 15
214
 
215
; eeprom registers
216
        EEPROM_REG_OEM_NODE_ADDR= 0xa
217
        EEPROM_REG_CAPABILITIES = 0x10
218
 
219
; Commands for command register
220
        SELECT_REGISTER_WINDOW  = (1 shl 11)
221
 
5073 hidnplayr 222
; Hw capabilities bitflags
223
        IS_VORTEX               = 0x0001
224
        IS_BOOMERANG            = 0x0002
225
        IS_CYCLONE              = 0x0004
226
        IS_TORNADO              = 0x0008
227
        EEPROM_8BIT             = 0x0010
228
        HAS_PWR_CTRL            = 0x0020
229
        HAS_MII                 = 0x0040
230
        HAS_NWAY                = 0x0080
231
        HAS_CB_FNS              = 0x0100
232
        INVERT_MII_PWR          = 0x0200
233
        INVERT_LED_PWR          = 0x0400
234
        MAX_COLLISION_RESET     = 0x0800
3545 hidnplayr 235
        EEPROM_OFFSET           = 0x1000
236
        HAS_HWCKSM              = 0x2000
237
        EXTRA_PREAMBLE          = 0x4000
238
 
239
; Status
240
        IntLatch                = 0x0001
241
        HostError               = 0x0002
242
        TxComplete              = 0x0004
243
        TxAvailable             = 0x0008
244
        RxComplete              = 0x0010
245
        RxEarly                 = 0x0020
246
        IntReq                  = 0x0040
247
        StatsFull               = 0x0080
248
        DMADone                 = 0x0100
249
        DownComplete            = 0x0200
250
        UpComplete              = 0x0400
251
        DMAInProgress           = 0x0800        ; 1 shl 11  (DMA controller is still busy)
252
        CmdInProgress           = 0x1000        ; 1 shl 12  (EL3_CMD is still busy)
253
 
5073 hidnplayr 254
        S_5_INTS                = HostError + RxEarly + UpComplete + DownComplete + StatsFull ;+ TxComplete + RxComplete  + TxAvailable
3545 hidnplayr 255
 
256
; Commands
257
        TotalReset              = 0 shl 11
258
        SelectWindow            = 1 shl 11
259
        StartCoax               = 2 shl 11
260
        RxDisable               = 3 shl 11
261
        RxEnable                = 4 shl 11
262
        RxReset                 = 5 shl 11
263
        UpStall                 = 6 shl 11
264
        UpUnstall               = (6 shl 11)+1
265
        DownStall               = (6 shl 11)+2
266
        DownUnstall             = (6 shl 11)+3
267
        RxDiscard               = 8 shl 11
268
        TxEnable                = 9 shl 11
269
        TxDisable               = 10 shl 11
270
        TxReset                 = 11 shl 11
271
        FakeIntr                = 12 shl 11
272
        AckIntr                 = 13 shl 11
273
        SetIntrEnb              = 14 shl 11
274
        SetStatusEnb            = 15 shl 11
275
        SetRxFilter             = 16 shl 11
276
        SetRxThreshold          = 17 shl 11
277
        SetTxThreshold          = 18 shl 11
278
        SetTxStart              = 19 shl 11
279
        StartDMAUp              = 20 shl 11
280
        StartDMADown            = (20 shl 11)+1
281
        StatsEnable             = 21 shl 11
282
        StatsDisable            = 22 shl 11
283
        StopCoax                = 23 shl 11
284
        SetFilterBit            = 25 shl 11
285
 
286
; Rx mode bits
287
        RxStation               = 1
288
        RxMulticast             = 2
289
        RxBroadcast             = 4
290
        RxProm                  = 8
291
 
5522 hidnplayr 292
        MAX_ETH_FRAME_SIZE      = 1514
3545 hidnplayr 293
 
294
 
5073 hidnplayr 295
struct  tx_desc
3545 hidnplayr 296
 
5073 hidnplayr 297
        next_ptr                dd ?
298
        frame_start_hdr         dd ?
299
        frag_addr               dd ?    ; for packet data
300
        frag_len                dd ?    ; for packet data
301
        realaddr                dd ?
302
                                rd 3    ; align 32
303
ends
3545 hidnplayr 304
 
305
 
5073 hidnplayr 306
struct  rx_desc
3545 hidnplayr 307
 
5073 hidnplayr 308
        next_ptr                dd ?
309
        pkt_status              dd ?
310
        frag_addr               dd ?
311
        frag_len                dd ?    ; for packet data
312
        realaddr                dd ?
313
                                rd 3    ; align 32
314
ends
3545 hidnplayr 315
 
316
 
5073 hidnplayr 317
struct  device                  ETH_DEVICE
3545 hidnplayr 318
 
5073 hidnplayr 319
        io_addr                 dd ?
320
        pci_bus                 dd ?
321
        pci_dev                 dd ?
322
        irq_line                db ?
323
                                rb 3    ; alignment
3545 hidnplayr 324
 
5073 hidnplayr 325
        curr_tx                 dd ?
326
        curr_rx                 dd ?
327
        prev_tx_frame           dd ?
328
        ver_id                  db ?
329
        full_bus_master         db ?
330
        has_hwcksm              db ?
331
        preamble                db ?
332
        dn_list_ptr_cleared     db ?
333
        internal_link           dd ?    ; link state (to be used only internally by driver)
334
 
335
        rb 0x100 - ($ and 0xff) ; align 256
336
        tx_desc_buffer          rd (sizeof.tx_desc*NUM_TX_DESC)/4
337
        rx_desc_buffer          rd (sizeof.rx_desc*NUM_RX_DESC)/4
338
 
339
ends
340
 
341
 
3545 hidnplayr 342
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
343
;;                        ;;
344
;; proc START             ;;
345
;;                        ;;
346
;; (standard driver proc) ;;
347
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
348
 
5073 hidnplayr 349
proc START c, reason:dword, cmdline:dword
3545 hidnplayr 350
 
5073 hidnplayr 351
        cmp     [reason], DRV_ENTRY
352
        jne     .fail
3545 hidnplayr 353
 
5073 hidnplayr 354
        DEBUGF  2,"Loading driver\n"
355
        invoke  RegService, my_service, service_proc
3545 hidnplayr 356
        ret
357
 
358
  .fail:
5073 hidnplayr 359
        xor     eax, eax
3545 hidnplayr 360
        ret
361
 
362
endp
363
 
364
 
365
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
366
;;                        ;;
367
;; proc SERVICE_PROC      ;;
368
;;                        ;;
369
;; (standard driver proc) ;;
370
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371
 
372
align 4
373
proc service_proc stdcall, ioctl:dword
374
 
375
        mov     edx, [ioctl]
4470 hidnplayr 376
        mov     eax, [edx + IOCTL.io_code]
3545 hidnplayr 377
 
378
;------------------------------------------------------
379
 
380
        cmp     eax, 0 ;SRV_GETVERSION
381
        jne     @F
382
 
4470 hidnplayr 383
        cmp     [edx + IOCTL.out_size], 4
3545 hidnplayr 384
        jb      .fail
4470 hidnplayr 385
        mov     eax, [edx + IOCTL.output]
3545 hidnplayr 386
        mov     [eax], dword API_VERSION
387
 
388
        xor     eax, eax
389
        ret
390
 
391
;------------------------------------------------------
392
  @@:
393
        cmp     eax, 1 ;SRV_HOOK
394
        jne     .fail
395
 
4470 hidnplayr 396
        cmp     [edx + IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
3545 hidnplayr 397
        jb      .fail
398
 
4470 hidnplayr 399
        mov     eax, [edx + IOCTL.input]
3545 hidnplayr 400
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
401
        jne     .fail                                   ; other types of this hardware dont exist
402
 
403
; check if the device is already listed
404
 
5073 hidnplayr 405
        mov     ecx, [vortex_devices]
3545 hidnplayr 406
        test    ecx, ecx
407
        jz      .maybeboomerang
408
 
5073 hidnplayr 409
        mov     esi, vortex_list
4470 hidnplayr 410
        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
3545 hidnplayr 411
        mov     ax , [eax+1]                            ;
412
  .nextdevice:
413
        mov     ebx, [esi]
5073 hidnplayr 414
        cmp     al, byte[ebx + device.pci_bus]
3545 hidnplayr 415
        jne     @f
5073 hidnplayr 416
        cmp     ah, byte[ebx + device.pci_dev]
3545 hidnplayr 417
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
418
       @@:
419
        add     esi, 4
420
        loop    .nextdevice
421
 
422
 
423
  .maybeboomerang:
5073 hidnplayr 424
        mov     ecx, [boomerang_devices]
3545 hidnplayr 425
        test    ecx, ecx
426
        jz      .firstdevice
427
 
5073 hidnplayr 428
        mov     esi, boomerang_list
4470 hidnplayr 429
        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
430
        mov     ax, [eax+1]                             ;
3545 hidnplayr 431
  .nextdevice2:
432
        mov     ebx, [esi]
5073 hidnplayr 433
        cmp     al, byte[ebx + device.pci_bus]
3545 hidnplayr 434
        jne     @f
5073 hidnplayr 435
        cmp     ah, byte[ebx + device.pci_dev]
3545 hidnplayr 436
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
437
       @@:
438
        add     esi, 4
439
        loop    .nextdevice2
440
 
441
 
442
; This device doesnt have its own eth_device structure yet, lets create one
443
  .firstdevice:
5073 hidnplayr 444
        mov     ecx, [boomerang_devices]
445
        add     ecx, [vortex_devices]
3545 hidnplayr 446
        cmp     ecx, MAX_DEVICES                        ; First check if the driver can handle one more card
447
        jae     .fail
448
 
5073 hidnplayr 449
        allocate_and_clear ebx, sizeof.device, .fail    ; Allocate the buffer for device structure
3545 hidnplayr 450
 
451
; Fill in the direct call addresses into the struct
452
 
5073 hidnplayr 453
        mov     [ebx + device.reset], reset
454
        mov     [ebx + device.transmit], null_op
455
        mov     [ebx + device.unload], null_op
456
        mov     [ebx + device.name], my_service
3545 hidnplayr 457
 
458
; save the pci bus and device numbers
459
 
4470 hidnplayr 460
        mov     eax, [edx + IOCTL.input]
3545 hidnplayr 461
        movzx   ecx, byte[eax+1]
5073 hidnplayr 462
        mov     [ebx + device.pci_bus], ecx
3545 hidnplayr 463
        movzx   ecx, byte[eax+2]
5073 hidnplayr 464
        mov     [ebx + device.pci_dev], ecx
3545 hidnplayr 465
 
466
; Now, it's time to find the base io addres of the PCI device
467
 
5073 hidnplayr 468
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
469
        mov     [ebx + device.io_addr], eax
470
 
3545 hidnplayr 471
; We've found the io address, find IRQ now
472
 
5073 hidnplayr 473
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
474
        mov     [ebx + device.irq_line], al
475
 
3545 hidnplayr 476
        DEBUGF  1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
5073 hidnplayr 477
        [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.io_addr]:4
3545 hidnplayr 478
 
479
; Ok, the eth_device structure is ready, let's probe the device
480
        call    probe                                                   ; this function will output in eax
481
        test    eax, eax
482
        jnz     .err                                                    ; If an error occured, exit
483
 
484
 
5073 hidnplayr 485
        movzx   ecx, [ebx + device.ver_id]
3545 hidnplayr 486
        test    word [hw_versions+2+ecx*4], IS_VORTEX
487
        jz      .not_vortex
488
 
5073 hidnplayr 489
        mov     eax, [vortex_devices]                                   ; Add the device structure to our device list
490
        mov     [vortex_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
491
        inc     [vortex_devices]                                        ;
3545 hidnplayr 492
 
493
  .register:
5073 hidnplayr 494
        mov     [ebx + device.type], NET_TYPE_ETH
495
        invoke  NetRegDev
3545 hidnplayr 496
 
497
        cmp     eax, -1
498
        je      .destroy
499
 
500
        call    start_device
501
        ret
502
 
503
  .not_vortex:
5073 hidnplayr 504
        mov     eax, [boomerang_devices]                                ; Add the device structure to our device list
505
        mov     [boomerang_list+4*eax], ebx                             ; (IRQ handler uses this list to find device)
506
        inc     [boomerang_devices]
3545 hidnplayr 507
 
508
        jmp     .register
509
 
510
; If the device was already loaded, find the device number and return it in eax
511
 
512
  .find_devicenum:
5073 hidnplayr 513
        DEBUGF  2,"Trying to find device number of already registered device\n"
514
        invoke  NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
3545 hidnplayr 515
                                                                        ; into a device number in edi
516
        mov     eax, edi                                                ; Application wants it in eax instead
5073 hidnplayr 517
        DEBUGF  2,"Kernel says: %u\n", eax
3545 hidnplayr 518
        ret
519
 
520
; If an error occured, remove all allocated data and exit (returning -1 in eax)
521
 
522
  .destroy:
523
        ; todo: reset device into virgin state
524
 
525
  .err:
5073 hidnplayr 526
        invoke  KernelFree, ebx
3545 hidnplayr 527
  .fail:
5073 hidnplayr 528
        DEBUGF  2, "Failed to load\n"
3545 hidnplayr 529
        or      eax, -1
530
        ret
531
 
532
;------------------------------------------------------
533
endp
534
 
535
 
536
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
537
;;                                                                        ;;
538
;;        Actual Hardware dependent code starts here                      ;;
539
;;                                                                        ;;
540
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
541
 
542
 
5073 hidnplayr 543
align 4
544
null_op:
3545 hidnplayr 545
 
5073 hidnplayr 546
        ret
3545 hidnplayr 547
 
548
 
5073 hidnplayr 549
 
3545 hidnplayr 550
;***************************************************************************
551
;   Function
552
;      probe
553
;   Description
554
;      Searches for an ethernet card, enables it and clears the rx buffer
555
;   Destroyed registers
556
;      eax, ebx, ecx, edx, edi, esi
557
;
558
;***************************************************************************
559
 
560
align 4
561
probe:
562
 
563
        DEBUGF  1,"Probing 3com card\n"
564
 
5073 hidnplayr 565
; Make the device a bus master
566
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
567
        or      al, PCI_CMD_MASTER
568
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
3545 hidnplayr 569
 
570
; wake up the card
5073 hidnplayr 571
        DEBUGF 1,"Checking if the device is awake\n"
3545 hidnplayr 572
 
5073 hidnplayr 573
; wake up - we directly do it by programming PCI
574
; check if the device is power management capable
575
        invoke  PciRead16, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.status
576
        test    al, PCI_STATUS_CAPA     ; is there "new capabilities" linked list?
577
        jz      .device_awake
3545 hidnplayr 578
 
5073 hidnplayr 579
; search for power management register
580
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.cap_ptr
581
        and     al, not 3
582
        cmp     al, 0x3f
583
        jbe     .device_awake           ; invalid pointer if less then PCI header size
584
 
585
; traverse the list
586
        movzx   esi, al
587
  .pm_loop:
588
        invoke  PciRead16, [ebx + device.pci_bus], [ebx + device.pci_dev], esi
589
        cmp     al, 1
590
        je      .set_pm_state
591
        movzx   esi, ah                 ; load address of next capability
592
        test    ah, ah                  ; 0 if none left
593
        jnz     .pm_loop
594
        jmp     .device_awake
595
 
596
; wake up the device if necessary
597
  .set_pm_state:
598
        DEBUGF 1,"Waking up the device\n"
599
        add     esi, 4                  ; offset for power management
600
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], esi
601
        test    al, 11b
602
        jz      .device_awake
603
        and     al, not 11b             ; set state to D0
604
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], esi, eax
605
 
606
  .device_awake:
607
        DEBUGF 1,"Device is awake\n"
608
 
609
; Check device/vendor ID
610
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], 0
611
 
3545 hidnplayr 612
        DEBUGF  1,"Vendor id: 0x%x\n", ax
613
 
614
        cmp     ax, 0x10B7
615
        jne     .notfound
616
        shr     eax, 16
617
 
618
        DEBUGF  1,"Vendor ok!, device id: 0x%x\n", ax
619
 
620
; get chip version
621
        mov     ecx, HW_VERSIONS_SIZE/4-1
622
  .loop:
623
        cmp     ax, [hw_versions+ecx*4]
624
        jz      .found
625
        loop    .loop
626
  .notfound:
3880 hidnplayr 627
        DEBUGF  2,"Device id not found in list!\n"
3545 hidnplayr 628
        or      eax, -1
629
        ret
630
  .found:
631
        mov     esi, [hw_str+ecx*4]
632
        DEBUGF  1,"Hardware type: %s\n", esi
5073 hidnplayr 633
        mov     [ebx + device.name], esi
3545 hidnplayr 634
 
5073 hidnplayr 635
        mov     [ebx + device.ver_id], cl
3545 hidnplayr 636
        test    word [hw_versions+2+ecx*4], HAS_HWCKSM
5073 hidnplayr 637
        setnz   [ebx + device.has_hwcksm]
3545 hidnplayr 638
; set pci latency for vortex cards
639
        test    word [hw_versions+2+ecx*4], IS_VORTEX
640
        jz      .not_vortex
641
 
5073 hidnplayr 642
        mov     al, 11111000b ; 248 = max latency
643
        invoke  PciWrite8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.max_latency, eax
3545 hidnplayr 644
 
645
  .not_vortex:
646
; set RX/TX functions
647
        mov     ax, EEPROM_REG_CAPABILITIES
648
        call    read_eeprom
649
        test    al, 100000b ; full bus master?
5073 hidnplayr 650
        setnz   [ebx + device.full_bus_master]
3545 hidnplayr 651
        jnz     .boomerang_func
5073 hidnplayr 652
        mov     [ebx + device.transmit], vortex_transmit
3880 hidnplayr 653
        DEBUGF  2,"Device is a vortex type\n"
654
        DEBUGF  2,"I'm sorry but vortex code hasnt been tested yet\n"
655
        DEBUGF  2,"Please contact me on hidnplayr@kolibrios.org\n"
656
        DEBUGF  2,"If you can help me finish it!\n"
3545 hidnplayr 657
        or      eax, -1
658
        ret
659
        jmp     @f
660
  .boomerang_func: ; full bus master, so use boomerang functions
5073 hidnplayr 661
        mov     [ebx + device.transmit], boomerang_transmit
3545 hidnplayr 662
        DEBUGF  1,"Device is a boomerang type\n"
663
       @@:
664
        call    read_mac_eeprom
665
 
5073 hidnplayr 666
        test    byte [ebx + device.full_bus_master], 0xff
3545 hidnplayr 667
        jz      .set_preamble
668
; switch to register window 2
5073 hidnplayr 669
        set_io  [ebx + device.io_addr], 0
670
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 671
        mov     ax, SELECT_REGISTER_WINDOW+2
672
        out     dx, ax
673
; activate xcvr by setting some magic bits
5073 hidnplayr 674
        set_io  [ebx + device.io_addr], REG_RESET_OPTIONS
3545 hidnplayr 675
        in      ax, dx
676
        and     ax, not 0x4010
5073 hidnplayr 677
        movzx   ecx, [ebx + device.ver_id]
3545 hidnplayr 678
        test    word [ecx*4+hw_versions+2], INVERT_LED_PWR
679
        jz      @f
680
        or      al, 0x10
681
       @@:
682
        test    word [ecx*4+hw_versions+2], INVERT_MII_PWR
683
        jz      @f
684
        or      ah, 0x40
685
       @@:
686
        out     dx, ax
687
  .set_preamble:
688
; use preamble as default
5073 hidnplayr 689
        mov     byte [ebx + device.preamble], 1 ; enable preamble
3545 hidnplayr 690
 
5073 hidnplayr 691
        DEBUGF 1,"Global reset..\n"
3545 hidnplayr 692
 
5073 hidnplayr 693
; GlobalReset
694
        set_io  [ebx + device.io_addr], 0
695
        set_io  [ebx + device.io_addr], REG_COMMAND
696
        xor     eax, eax
697
;       or      al, 0x14
698
        out     dx, ax
699
; wait for GlobalReset to complete
700
        mov     ecx, 64000
701
  .rsloop:
702
        in      ax , dx
703
        test    ah , 10000b             ; CmdInProgress
704
        loopz   .rsloop
705
 
706
        DEBUGF 1,"Waiting for nic to boot..\n"
707
; wait for 2 seconds for NIC to boot
708
        mov     esi, 2000               ; WTF? FIXME
709
        invoke  Sleep ; 2 seconds
710
 
711
        DEBUGF 1,"Ok!\n"
712
 
713
 
3545 hidnplayr 714
;--------------------------
5073 hidnplayr 715
;
3545 hidnplayr 716
; RESET
5073 hidnplayr 717
;
718
;--------------------------
3545 hidnplayr 719
 
720
reset:
721
 
5073 hidnplayr 722
        movzx   eax, [ebx + device.irq_line]
723
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
3545 hidnplayr 724
 
5073 hidnplayr 725
        movzx   ecx, [ebx + device.ver_id]
3545 hidnplayr 726
        test    word [hw_versions+2+ecx*4], IS_VORTEX
727
        jz      .not_vortex
728
        mov     esi, int_vortex
729
        jmp     .reg_int
5073 hidnplayr 730
  .not_vortex:
3545 hidnplayr 731
        mov     esi, int_boomerang
5073 hidnplayr 732
  .reg_int:
733
        invoke  AttachIntHandler, eax, esi, ebx
3545 hidnplayr 734
        test    eax, eax
735
        jnz     @f
3880 hidnplayr 736
        DEBUGF  2,"Could not attach int handler!\n"
5073 hidnplayr 737
        or      eax, -1
738
        ret
3545 hidnplayr 739
  @@:
740
 
5073 hidnplayr 741
        set_io  [ebx + device.io_addr], 0
742
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 743
        mov     ax, SELECT_REGISTER_WINDOW + 0
744
        out     dx, ax
745
 
746
        mov     ax, StopCoax
747
        out     dx, ax                        ; stop transceiver
748
 
749
        mov     ax, SELECT_REGISTER_WINDOW + 4
750
        out     dx, ax                        ; disable UTP
751
 
5073 hidnplayr 752
        set_io  [ebx + device.io_addr], REG_MEDIA_STATUS
3545 hidnplayr 753
        mov     ax, 0x0
754
 
5073 hidnplayr 755
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 756
        mov     ax, SELECT_REGISTER_WINDOW + 0
757
        out     dx, ax
758
 
5073 hidnplayr 759
        set_io  [ebx + device.io_addr], REG_FIFO_DIAGNOSTIC
3545 hidnplayr 760
        mov     ax, 0
761
        out     dx, ax                        ; disable card
762
 
763
        mov     ax, 1
764
        out     dx, ax                        ; enable card
765
 
766
        call    write_mac
767
 
5073 hidnplayr 768
        set_io  [ebx + device.io_addr], 0
769
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 770
        mov     ax, SELECT_REGISTER_WINDOW + 1
771
        out     dx, ax
772
 
773
        mov     ecx, 32
5073 hidnplayr 774
        set_io  [ebx + device.io_addr], 0x0b
3545 hidnplayr 775
  .loop:
776
        in      al, dx
777
        loop    .loop
778
 
779
; Get rid of stray ints
5073 hidnplayr 780
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 781
        mov     ax, AckIntr + 0xff
782
        out     dx, ax
783
 
784
        mov     ax, SetStatusEnb + S_5_INTS
785
        out     dx, ax
786
 
787
        mov     ax, SetIntrEnb + S_5_INTS
788
        out     dx, ax
789
 
5073 hidnplayr 790
        DEBUGF  1,"Setting RX mode\n"
791
 
792
        set_io  [ebx + device.io_addr], 0
793
        set_io  [ebx + device.io_addr], REG_COMMAND
794
 
795
if      defined PROMISCIOUS
796
        mov     ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast + RxProm
797
else if  defined ALLMULTI
798
        mov     ax, SetRxFilter + RxStation + RxMulticast + RxBroadcast
799
else
800
        mov     ax, SetRxFilter + RxStation + RxBroadcast
801
end if
802
        out     dx, ax
803
 
3545 hidnplayr 804
        call    set_active_port
805
 
806
        call    create_rx_ring
5522 hidnplayr 807
        test    eax, eax
808
        jnz     .err
809
 
3545 hidnplayr 810
        call    rx_reset
811
        call    tx_reset
812
 
813
        xor     eax, eax
814
; clear packet/byte counters
815
 
5073 hidnplayr 816
        lea     edi, [ebx + device.bytes_tx]
3545 hidnplayr 817
        mov     ecx, 6
818
        rep     stosd
819
 
5522 hidnplayr 820
        xor     eax, eax
821
        ret
3545 hidnplayr 822
 
5522 hidnplayr 823
  .err:
824
        DEBUGF  2,"reset failed\n"
825
        or      eax, -1
3545 hidnplayr 826
        ret
827
 
828
 
829
align 4
830
start_device:
831
        DEBUGF  1,"Starting the device\n"
832
 
5073 hidnplayr 833
        set_io  [ebx + device.io_addr], 0
834
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 835
        mov     ax, SetTxThreshold + 60 ;2047 ; recommended by the manual :)
836
        out     dx, ax
837
 
838
        call    check_tx_status
839
 
5073 hidnplayr 840
        set_io  [ebx + device.io_addr], 0
841
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 842
; switch to register window 4
843
        mov     ax, SELECT_REGISTER_WINDOW+4
844
        out     dx, ax
845
 
846
; wait for linkDetect
5073 hidnplayr 847
        set_io  [ebx + device.io_addr], REG_MEDIA_STATUS
848
        mov     ecx, 20         ; wait for max 2s
3545 hidnplayr 849
  .link_detect_loop:
850
        mov     esi, 100
5073 hidnplayr 851
        invoke  Sleep           ; 100 ms
3545 hidnplayr 852
        in      ax, dx
5073 hidnplayr 853
        test    ah, 1000b       ; linkDetect
3545 hidnplayr 854
        jnz     @f
855
        loop    .link_detect_loop
3880 hidnplayr 856
        DEBUGF  2,"Link detect timed-out!\n"
3545 hidnplayr 857
       @@:
858
 
859
; print link type
860
        xor     eax, eax
5073 hidnplayr 861
        bsr     ax, word[ebx + device.internal_link]
3545 hidnplayr 862
        jz      @f
5073 hidnplayr 863
        sub     ax, 5
3545 hidnplayr 864
       @@:
865
 
866
        mov     esi, [link_str+eax*4]
867
        DEBUGF  1,"Established Link type: %s\n", esi
868
 
869
; enable interrupts
5073 hidnplayr 870
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 871
        mov     ax, SELECT_REGISTER_WINDOW + 1
872
        out     dx, ax
873
 
874
        mov     ax, AckIntr + 0xff
875
        out     dx, ax
876
 
877
        mov     ax, SetStatusEnb + S_5_INTS
878
        out     dx, ax
879
 
880
        mov     ax, SetIntrEnb + S_5_INTS
881
        out     dx, ax
882
 
883
; Start RX/TX
884
 
5073 hidnplayr 885
        set_io  [ebx + device.io_addr], 0
886
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 887
        mov     ax, RxEnable
888
        out     dx, ax
889
 
890
        mov     ax, TxEnable
891
        out     dx, ax
892
 
5073 hidnplayr 893
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 894
        mov     ax, SetRxThreshold + 208
895
        out     dx, ax
896
 
897
        mov     ax, SetTxThreshold + 60 ;16 ; recommended by the manual :)
898
        out     dx, ax
899
 
900
        mov     ax, SELECT_REGISTER_WINDOW + 1
901
        out     dx, ax
902
 
5073 hidnplayr 903
; Set the mtu, kernel will be able to send now
904
        mov     [ebx + device.mtu], 1514
3545 hidnplayr 905
 
5073 hidnplayr 906
; Set link state to unknown
5522 hidnplayr 907
        mov     [ebx + device.state], ETH_LINK_UNKNOWN
908
        xor     eax, eax
3545 hidnplayr 909
 
910
        ret
911
 
912
 
913
 
914
;***************************************************************************
915
;   Function
916
;      tx_reset
917
;   Description
918
;      resets and enables transmitter engine
919
;
920
;***************************************************************************
921
 
922
align 4
923
tx_reset:
924
        DEBUGF 1,"tx reset\n"
925
 
926
; TxReset
5073 hidnplayr 927
        set_io  [ebx + device.io_addr], 0
928
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 929
        mov     ax, TxReset
930
        out     dx, ax
931
; Wait for TxReset to complete
932
        mov     ecx, 200000
5073 hidnplayr 933
  .tx_reset_loop:
3545 hidnplayr 934
        in      ax, dx
935
        test    ah, 10000b ; check CmdInProgress
936
        jz      .tx_set_prev
937
        dec     ecx
938
        jnz     .tx_reset_loop
5073 hidnplayr 939
  .tx_set_prev:
940
; init last TX descriptor
941
        lea     eax, [ebx + device.tx_desc_buffer + (NUM_TX_DESC-1)*sizeof.tx_desc]
942
        mov     [ebx + device.curr_tx], eax
3545 hidnplayr 943
 
5073 hidnplayr 944
  .tx_enable:
3545 hidnplayr 945
        ret
946
 
947
 
948
 
949
;***************************************************************************
950
;   Function
951
;      rx_reset
952
;   Description
953
;      resets and enables receiver engine
954
;
955
;***************************************************************************
956
 
957
align 4
958
rx_reset:
959
 
960
        DEBUGF 1,"rx reset\n"
961
 
5073 hidnplayr 962
        set_io  [ebx + device.io_addr], 0
963
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 964
        mov     ax, RxReset or 0x4
965
        out     dx, ax
966
 
967
; wait for RxReset to complete
968
        mov     ecx, 200000
969
  .loop:
970
        in      ax, dx
971
        test    ah, 10000b ; check CmdInProgress
972
        jz      .done
973
        dec     ecx
974
        jnz     .loop
975
  .done:
976
 
5073 hidnplayr 977
        lea     eax, [ebx + device.rx_desc_buffer]
978
        mov     [ebx + device.curr_rx], eax
979
        invoke  GetPhysAddr
980
        set_io  [ebx + device.io_addr], 0
981
        set_io  [ebx + device.io_addr], REG_UP_LIST_PTR
3545 hidnplayr 982
        out     dx, eax
983
 
984
  .rx_enable:
985
        ret
986
 
987
 
5073 hidnplayr 988
 
3545 hidnplayr 989
align 4
990
create_rx_ring:
5073 hidnplayr 991
; create rx descriptor ring
992
        lea     eax, [ebx + device.rx_desc_buffer]
993
        invoke  GetPhysAddr
3545 hidnplayr 994
        mov     edi, eax                                                ; real addr of first descr
995
 
5073 hidnplayr 996
        lea     esi, [ebx + device.rx_desc_buffer]                          ; ptr to first descr
997
        lea     edx, [ebx + device.rx_desc_buffer + (NUM_RX_DESC-1)*sizeof.rx_desc]     ; ptr to last descr
3545 hidnplayr 998
 
999
        mov     ecx, NUM_RX_DESC
5073 hidnplayr 1000
  .loop:
1001
        mov     [edx + rx_desc.next_ptr], edi
3545 hidnplayr 1002
 
1003
        push    ecx edx
5522 hidnplayr 1004
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE+NET_BUFF.data
3545 hidnplayr 1005
        pop     edx ecx
5522 hidnplayr 1006
        test    eax, eax
1007
        jz      .out_of_mem
5073 hidnplayr 1008
        mov     [esi + rx_desc.realaddr], eax
5522 hidnplayr 1009
        invoke  GetPhysAddr
1010
        add     eax, NET_BUFF.data
5073 hidnplayr 1011
        mov     [esi + rx_desc.frag_addr], eax
1012
        and     [esi + rx_desc.pkt_status], 0
1013
        mov     [esi + rx_desc.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31)
3545 hidnplayr 1014
 
5073 hidnplayr 1015
        DEBUGF  1,"rx_desc: lin=%x phys=%x len=%x next ptr=%x\n", [esi+rx_desc.realaddr]:8, [esi+rx_desc.frag_addr]:8, [esi+rx_desc.frag_len]:8, edi
1016
        DEBUGF  1,"rx_desc: cur=%x prev=%x\n", esi, edx
3545 hidnplayr 1017
 
1018
        mov     edx, esi
5073 hidnplayr 1019
        add     esi, sizeof.rx_desc
1020
        add     edi, sizeof.rx_desc
3545 hidnplayr 1021
        dec     ecx
5073 hidnplayr 1022
        jnz     .loop
3545 hidnplayr 1023
 
5522 hidnplayr 1024
        xor     eax, eax
3545 hidnplayr 1025
        ret
1026
 
5522 hidnplayr 1027
  .out_of_mem:
1028
        or      eax, -1
1029
        ret
3545 hidnplayr 1030
 
1031
 
5522 hidnplayr 1032
 
3545 hidnplayr 1033
;---------------------------------------------------------------------------
1034
;   Function
1035
;      try_link_detect
1036
;   Description
1037
;      try_link_detect checks if link exists
1038
;   Parameters
1039
;      ebx = device structure
1040
;   Return value
1041
;      al - 0 ; no link detected
1042
;      al - 1 ; link detected
1043
;   Destroyed registers
1044
;      eax, ebx, ecx, edx, edi, esi
1045
;
1046
;---------------------------------------------------------------------------
1047
 
1048
align 4
1049
try_link_detect:
1050
 
5073 hidnplayr 1051
        DEBUGF  1,"Trying to detect link\n"
3545 hidnplayr 1052
 
1053
; create self-directed packet
5522 hidnplayr 1054
        invoke  NetAlloc, 20+NET_BUFF.data     ; create a buffer for the self-directed packet
3545 hidnplayr 1055
        test    eax, eax
1056
        jz      .fail
1057
 
5522 hidnplayr 1058
        push    eax
1059
        mov     [eax + NET_BUFF.length], 20
3545 hidnplayr 1060
 
5522 hidnplayr 1061
        lea     edi, [eax + NET_BUFF.data]
5073 hidnplayr 1062
        lea     esi, [ebx + device.mac]
3545 hidnplayr 1063
        movsw
1064
        movsd
1065
        sub     esi, 6
1066
        movsw
1067
        movsd
1068
        mov     ax , 0x0608
1069
        stosw
1070
 
1071
; download self-directed packet
5073 hidnplayr 1072
        call    [ebx + device.transmit]
3545 hidnplayr 1073
 
1074
; switch to register window 4
5073 hidnplayr 1075
        set_io  [ebx + device.io_addr], 0
1076
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1077
        mov     ax, SELECT_REGISTER_WINDOW+4
1078
        out     dx, ax
1079
 
1080
; See if we have received the packet by now..
5073 hidnplayr 1081
        cmp     [ebx + device.packets_rx], 0
3545 hidnplayr 1082
        jnz     .link_detected
1083
 
1084
; switch to register window 4
5073 hidnplayr 1085
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1086
        mov     ax, SELECT_REGISTER_WINDOW+4
1087
        out     dx, ax
1088
 
1089
; read linkbeatdetect
5073 hidnplayr 1090
        set_io  [ebx + device.io_addr], REG_MEDIA_STATUS
3545 hidnplayr 1091
        in      ax, dx
1092
        test    ah, 1000b ; test linkBeatDetect
1093
        jnz     .link_detected
1094
        xor     al, al
1095
        jmp     .finish
1096
 
1097
  .link_detected:
5073 hidnplayr 1098
        DEBUGF  1,"Link detected!\n"
3545 hidnplayr 1099
        setb    al
1100
 
1101
  .finish:
1102
        test    al, al
1103
        jz      @f
5073 hidnplayr 1104
        or      byte [ebx + device.internal_link+1], 100b
3545 hidnplayr 1105
       @@:
5522 hidnplayr 1106
        xor     eax, eax
3545 hidnplayr 1107
        ret
1108
 
1109
  .fail:
5073 hidnplayr 1110
        DEBUGF  1,"No link detected!\n"
5522 hidnplayr 1111
        or      eax, -1
3545 hidnplayr 1112
        ret
1113
 
1114
 
1115
 
1116
;***************************************************************************
1117
;   Function
1118
;      try_phy
1119
;   Description
1120
;      try_phy checks the auto-negotiation function
1121
;      in the PHY at PHY index. It can also be extended to
1122
;      include link detection for non-IEEE 802.3u
1123
;      auto-negotiation devices, for instance the BCM5000.              ; TODO: BCM5000
1124
;   Parameters
1125
;       ah - PHY index
1126
;       ebx - device stucture
1127
;   Return value
1128
;      al - 0 link is auto-negotiated
1129
;      al - 1 no link is auto-negotiated
1130
;   Destroyed registers
1131
;       eax, ebx, ecx, edx, esi
1132
;
1133
;***************************************************************************
1134
 
1135
align 4
1136
try_phy:
1137
 
1138
        DEBUGF 1,"PHY=%u\n", ah
1139
        DEBUGF 1,"Detecting if device is auto-negotiation capable\n"
1140
 
5073 hidnplayr 1141
        mov     al, MII_BMCR
3545 hidnplayr 1142
        push    eax
1143
        call    mdio_read       ; returns with window #4
5073 hidnplayr 1144
        or      ah, 0x80        ; software reset
3545 hidnplayr 1145
        mov     esi, eax
5073 hidnplayr 1146
        mov     eax, [esp]
3545 hidnplayr 1147
        call    mdio_write      ; returns with window #4
1148
 
1149
; wait for reset to complete
1150
        mov     esi, 2000
5522 hidnplayr 1151
        invoke  Sleep           ; 2s FIXME
3545 hidnplayr 1152
        mov     eax, [esp]
1153
        call    mdio_read       ; returns with window #4
5073 hidnplayr 1154
        test    ah, 0x80
3545 hidnplayr 1155
        jnz     .fail1
1156
        mov     eax, [esp]
1157
 
1158
; wait for a while after reset
1159
        mov     esi, 20
5522 hidnplayr 1160
        invoke  Sleep           ; 20ms
3545 hidnplayr 1161
        mov     eax, [esp]
5073 hidnplayr 1162
        mov     al , MII_BMSR
3545 hidnplayr 1163
        call    mdio_read        ; returns with window #4
5073 hidnplayr 1164
        test    al, 1            ; extended capability supported?
3545 hidnplayr 1165
        jz      .fail2
5073 hidnplayr 1166
        DEBUGF  1,"Extended capability supported\n"
3545 hidnplayr 1167
 
1168
; auto-neg capable?
1169
        test    al , 1000b
1170
        jz      .fail2           ; not auto-negotiation capable
5073 hidnplayr 1171
        DEBUGF  1,"Auto-negotiation capable\n"
3545 hidnplayr 1172
 
1173
; auto-neg complete?
1174
        test    al , 100000b
1175
        jnz     .auto_neg_ok
1176
        DEBUGF  1,"Restarting auto-negotiation\n"
1177
 
1178
; restart auto-negotiation
1179
        mov     eax, [esp]
5073 hidnplayr 1180
        mov     al, MII_ADVERTISE
3545 hidnplayr 1181
        push    eax
1182
        call    mdio_read       ; returns with window #4
1183
        or      ax , 1111b shl 5; advertise only 10base-T and 100base-TX
1184
        mov     esi, eax
1185
        pop     eax
1186
        call    mdio_write      ; returns with window #4
1187
        mov     eax, [esp]
1188
        call    mdio_read       ; returns with window #4
1189
        mov     esi, eax
1190
        or      bh , 10010b     ; restart auto-negotiation
1191
        mov     eax, [esp]
1192
        call    mdio_write      ; returns with window #4
1193
        mov     esi, 4000
5073 hidnplayr 1194
        invoke  Sleep  ; 4 seconds
3545 hidnplayr 1195
        mov     eax, [esp]
5073 hidnplayr 1196
        mov     al , MII_BMSR
3545 hidnplayr 1197
        call    mdio_read ; returns with window #4
1198
        test    al , 100000b ; auto-neg complete?
1199
        jnz     .auto_neg_ok
1200
        jmp     .fail3
1201
  .auto_neg_ok:
1202
        DEBUGF  1,"Auto-negotiation complete\n"
1203
 
1204
; compare advertisement and link partner ability registers
1205
        mov     eax, [esp]
5073 hidnplayr 1206
        mov     al, MII_ADVERTISE
1207
        call    mdio_read               ; returns with window #4
3545 hidnplayr 1208
        xchg    eax, [esp]
5073 hidnplayr 1209
        mov     al, MII_LPA
1210
        call    mdio_read               ; returns with window #4
3545 hidnplayr 1211
        pop     esi
1212
        and     eax, esi
5073 hidnplayr 1213
        and     eax, 11111100000b       ; Mask off
3545 hidnplayr 1214
        push    eax
5073 hidnplayr 1215
        mov     word[ebx + device.internal_link+2], ax
3545 hidnplayr 1216
 
1217
; switch to register window 3
5073 hidnplayr 1218
        set_io  [ebx + device.io_addr], 0
1219
        set_io  [ebx + device.io_addr], REG_COMMAND
1220
        mov     ax, SELECT_REGISTER_WINDOW+3
1221
        out     dx, ax
3545 hidnplayr 1222
 
1223
; set full-duplex mode
5073 hidnplayr 1224
        set_io  [ebx + device.io_addr], REG_MAC_CONTROL
1225
        in      ax, dx
1226
        and     ax, not 0x120           ; clear full duplex and flow control
3545 hidnplayr 1227
        pop     esi
5073 hidnplayr 1228
        test    esi, 1010b shl 5        ; check for full-duplex
3545 hidnplayr 1229
        jz      .half_duplex
5073 hidnplayr 1230
        or      ax, 0x120               ; set full duplex and flow control
3545 hidnplayr 1231
  .half_duplex:
1232
        DEBUGF 1,"Using half-duplex\n"
5073 hidnplayr 1233
        out     dx, ax
1234
        mov     al, 1
3545 hidnplayr 1235
        ret
1236
 
1237
  .fail1:
3880 hidnplayr 1238
        DEBUGF  2,"reset failed!\n"
3545 hidnplayr 1239
        pop     eax
1240
        xor     al, al
1241
        ret
1242
 
1243
  .fail2:
3880 hidnplayr 1244
        DEBUGF  2,"This device is not auto-negotiation capable!\n"
3545 hidnplayr 1245
        pop     eax
1246
        xor     al, al
1247
        ret
1248
 
1249
  .fail3:
5073 hidnplayr 1250
        DEBUGF  2,"Auto-negotiation reset failed!\n"
3545 hidnplayr 1251
        pop     eax
1252
        xor     al, al
1253
        ret
1254
 
1255
 
1256
 
1257
;***************************************************************************
1258
;   Function
1259
;      try_mii
1260
;   Description
1261
;      try_MII checks the on-chip auto-negotiation logic
1262
;      or an off-chip MII PHY, depending upon what is set in
1263
;      xcvrSelect by the caller.
1264
;      It exits when it finds the first device with a good link.
1265
;   Parameters
3880 hidnplayr 1266
;
3545 hidnplayr 1267
;   Return value
1268
;      al - 0
1269
;      al - 1
1270
;   Destroyed registers
1271
;      eax, ebx, ecx, edx, esi
1272
;
1273
;***************************************************************************
1274
 
1275
align 4
1276
try_mii:
1277
 
5073 hidnplayr 1278
        DEBUGF  1,"Trying to find MII PHY\n"
3545 hidnplayr 1279
 
1280
; switch to register window 3
5073 hidnplayr 1281
        set_io  [ebx + device.io_addr], 0
1282
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1283
        mov     ax, SELECT_REGISTER_WINDOW+3
1284
        out     dx, ax
5073 hidnplayr 1285
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1286
        in      eax, dx
1287
        and     eax, (1111b shl 20)
1288
        cmp     eax, (1000b shl 20) ; is auto-negotiation set?
1289
        jne     .mii_device
1290
 
5073 hidnplayr 1291
        DEBUGF  1,"Auto-negotiation is set\n"
3545 hidnplayr 1292
; switch to register window 4
5073 hidnplayr 1293
        set_io  [ebx + device.io_addr], REG_COMMAND
1294
        mov     ax, SELECT_REGISTER_WINDOW+4
1295
        out     dx, ax
3545 hidnplayr 1296
 
1297
; PHY==24 is the on-chip auto-negotiation logic
1298
; it supports only 10base-T and 100base-TX
5073 hidnplayr 1299
        mov     ah, 24
3545 hidnplayr 1300
        call    try_phy
5073 hidnplayr 1301
        test    al, al
1302
        jz      .fail
3545 hidnplayr 1303
 
5073 hidnplayr 1304
        mov     cl, 24
3545 hidnplayr 1305
        jmp     .check_preamble
1306
 
1307
  .mii_device:
1308
        cmp     eax, (0110b shl 20)
5073 hidnplayr 1309
        jne     .fail
3545 hidnplayr 1310
 
5073 hidnplayr 1311
        set_io  [ebx + device.io_addr], 0
1312
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1313
        mov     ax , SELECT_REGISTER_WINDOW+4
1314
        out     dx , ax
1315
 
5073 hidnplayr 1316
        set_io  [ebx + device.io_addr], REG_PHYSICAL_MGMT
3545 hidnplayr 1317
        in      ax , dx
1318
        and     al , (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_DATA)
1319
        cmp     al , (1 shl BIT_MGMT_DATA)
1320
        je      .search_for_phy
1321
 
5073 hidnplayr 1322
        xor     al, al
3545 hidnplayr 1323
        ret
1324
 
1325
  .search_for_phy:
1326
; search for PHY
5073 hidnplayr 1327
        mov     cx, 31
3545 hidnplayr 1328
  .search_phy_loop:
5073 hidnplayr 1329
        DEBUGF  1,"Searching for the PHY\n"
1330
        cmp     cx, 24
3545 hidnplayr 1331
        je      .next_phy
5073 hidnplayr 1332
        mov     ah, cl                  ; ah = phy
1333
        mov     al, MII_BMSR            ; al = Basic Mode Status Register       ; BUGFIX HERE! :):)
3545 hidnplayr 1334
        push    cx
1335
        call    mdio_read
1336
        pop     cx
5073 hidnplayr 1337
        test    ax, ax
3545 hidnplayr 1338
        jz      .next_phy
5073 hidnplayr 1339
        cmp     ax, 0xffff
3545 hidnplayr 1340
        je      .next_phy
5073 hidnplayr 1341
        mov     ah, cl                  ; ah = phy
3545 hidnplayr 1342
        push    cx
1343
        call    try_phy
1344
        pop     cx
5073 hidnplayr 1345
        test    al, al
3545 hidnplayr 1346
        jnz     .check_preamble
1347
  .next_phy:
1348
        loopw   .search_phy_loop
1349
 
5073 hidnplayr 1350
  .fail:
1351
        DEBUGF  1,"PHY not found\n"
3545 hidnplayr 1352
        xor     al, al
1353
        ret
1354
 
1355
; epilog
1356
  .check_preamble:
1357
        DEBUGF  1,"Using PHY: %u\nChecking PreAmble\n", cl
1358
        push    eax ; eax contains the return value of try_phy
1359
; check hard coded preamble forcing
5073 hidnplayr 1360
        movzx   eax, [ebx + device.ver_id]
3545 hidnplayr 1361
        test    word [eax*4+hw_versions+2], EXTRA_PREAMBLE
5073 hidnplayr 1362
        setnz   [ebx + device.preamble] ; force preamble
3545 hidnplayr 1363
        jnz     .finish
1364
 
1365
; check mii for preamble suppression
1366
        mov     ah, cl
5073 hidnplayr 1367
        mov     al, MII_BMSR
3545 hidnplayr 1368
        call    mdio_read
1369
        test    al, 1000000b ; preamble suppression?
5073 hidnplayr 1370
        setz    [ebx + device.preamble] ; no
3545 hidnplayr 1371
 
1372
  .finish:
1373
        pop     eax
1374
        ret
1375
 
1376
 
1377
 
1378
;***************************************************************************
1379
;   Function
1380
;      test_packet
1381
;   Description
1382
;      try_loopback try a loopback packet for 10BASE2 or AUI port
1383
;   Parameters
1384
;      ebx = device structure
1385
;
1386
;***************************************************************************
1387
 
1388
align 4
1389
test_packet:
1390
 
5073 hidnplayr 1391
        DEBUGF 1,"Sending test packet\n"
3545 hidnplayr 1392
 
1393
; switch to register window 3
5073 hidnplayr 1394
        set_io  [ebx + device.io_addr], 0
1395
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1396
        mov     ax, SELECT_REGISTER_WINDOW+3
1397
        out     dx, ax
1398
 
1399
; set fullDuplexEnable in MacControl register
5073 hidnplayr 1400
        set_io  [ebx + device.io_addr], REG_MAC_CONTROL
3545 hidnplayr 1401
        in      ax, dx
1402
        or      ax, 0x120
1403
        out     dx, ax
1404
 
1405
; switch to register window 5
5073 hidnplayr 1406
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1407
        mov     ax, SELECT_REGISTER_WINDOW+5
1408
        out     dx, ax
1409
 
1410
; set RxFilter to enable individual address matches
1411
        mov     ax, (10000b shl 11)
5073 hidnplayr 1412
        set_io  [ebx + device.io_addr], REG_RX_FILTER
3545 hidnplayr 1413
        in      al, dx
1414
        or      al, 1
5073 hidnplayr 1415
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1416
        out     dx, ax
1417
 
1418
; issue RxEnable and TxEnable
1419
        call    rx_reset
1420
        call    tx_reset
1421
 
1422
; create self-directed packet
5522 hidnplayr 1423
        invoke  NetAlloc, 20 + NET_BUFF.data   ; create a buffer for the self-directed packet
3545 hidnplayr 1424
        test    eax, eax
1425
        jz      .fail
1426
 
5522 hidnplayr 1427
        push    eax
1428
        mov     [eax + NET_BUFF.length], 20
1429
;        mov     [eax + NET_BUFF.device], ebx
3545 hidnplayr 1430
 
5522 hidnplayr 1431
        lea     edi, [eax + NET_BUFF.data]
5073 hidnplayr 1432
        lea     esi, [ebx + device.mac]
3545 hidnplayr 1433
        movsw
1434
        movsd
1435
        sub     esi, 6
1436
        movsw
1437
        movsd
5073 hidnplayr 1438
        mov     ax, 0x0608
3545 hidnplayr 1439
        stosw
1440
 
1441
; download self-directed packet
5073 hidnplayr 1442
        call    [ebx + device.transmit]
3545 hidnplayr 1443
 
1444
; wait for 2s
5522 hidnplayr 1445
        mov     esi, 2000       ; FIXME
5073 hidnplayr 1446
        invoke  Sleep
3545 hidnplayr 1447
 
1448
; check if self-directed packet is received
5073 hidnplayr 1449
        mov     eax, [ebx + device.packets_rx]
3545 hidnplayr 1450
        test    eax, eax
1451
        jnz     .finish
1452
 
1453
; switch to register window 3
5073 hidnplayr 1454
        set_io  [ebx + device.io_addr], 0
1455
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1456
        mov     ax, SELECT_REGISTER_WINDOW+3
1457
        out     dx, ax
1458
 
1459
; clear fullDuplexEnable in MacControl register
5073 hidnplayr 1460
        set_io  [ebx + device.io_addr], REG_MAC_CONTROL
1461
        in      ax, dx
1462
        and     ax, not 0x120
1463
        out     dx, ax
3545 hidnplayr 1464
  .fail:
1465
        xor     eax, eax
1466
 
1467
  .finish:
1468
        ret
1469
 
1470
 
1471
 
1472
;***************************************************************************
1473
;   Function
1474
;      try_loopback
1475
;   Description
1476
;      tries a loopback packet for 10BASE2 or AUI port
1477
;   Parameters
1478
;      al -  0: 10Mbps AUI connector
1479
;            1: 10BASE-2
3880 hidnplayr 1480
;
3545 hidnplayr 1481
;   Return value
1482
;      al - 0
1483
;      al - 1
1484
;   Destroyed registers
1485
;      eax, ebx, ecx, edx, edi, esi
1486
;
1487
;***************************************************************************
1488
 
1489
align 4
1490
try_loopback:
1491
 
1492
        DEBUGF 1,"trying loopback\n"
1493
 
1494
        push    eax
1495
; switch to register window 3
5073 hidnplayr 1496
        set_io  [ebx + device.io_addr], 0
1497
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1498
        mov     ax, SELECT_REGISTER_WINDOW+3
1499
        out     dx, ax
1500
        mov     eax, [esp]
1501
 
1502
        mov     cl, al
1503
        inc     cl
1504
        shl     cl, 3
5073 hidnplayr 1505
        or      byte [ebx + device.internal_link+1], cl
3545 hidnplayr 1506
 
1507
        test    al, al ; aui or coax?
1508
        jz      .complete_loopback
1509
; enable 100BASE-2 DC-DC converter
1510
        mov     ax, (10b shl 11) ; EnableDcConverter
1511
        out     dx, ax
1512
  .complete_loopback:
1513
 
1514
        mov     cx, 2 ; give a port 3 chances to complete a loopback
1515
  .next_try:
1516
        push    ecx
1517
        call    test_packet
1518
        pop     ecx
1519
        test    eax, eax
1520
        loopzw  .next_try
1521
 
1522
  .finish:
1523
        xchg    eax, [esp]
1524
        test    al, al
1525
        jz      .aui_finish
1526
 
1527
; issue DisableDcConverter command
5073 hidnplayr 1528
        set_io  [ebx + device.io_addr], 0
1529
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1530
        mov     ax, (10111b shl 11)
1531
        out     dx, ax
1532
  .aui_finish:
1533
        pop     eax ; al contains the result of operation
1534
 
1535
        test    al, al
1536
        jnz     @f
5073 hidnplayr 1537
        and     byte [ebx + device.internal_link+1], not 11000b
3545 hidnplayr 1538
       @@:
1539
 
1540
        ret
1541
 
1542
 
1543
;***************************************************************************
1544
;   Function
1545
;      set_active_port
1546
;   Description
1547
;      It selects the media port (transceiver) to be used
1548
;   Return value:
1549
;   Destroyed registers
1550
;      eax, ebx, ecx, edx, edi, esi
1551
;
1552
;***************************************************************************
1553
 
1554
align 4
1555
set_active_port:
1556
 
1557
        DEBUGF 1,"Trying to find the active port\n"
1558
 
1559
; switch to register window 3
5073 hidnplayr 1560
        set_io  [ebx + device.io_addr], 0
1561
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1562
        mov     ax, SELECT_REGISTER_WINDOW + 3
1563
        out     dx, ax
1564
 
5073 hidnplayr 1565
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1566
        in      eax, dx
1567
        test    eax, (1 shl 24) ; check if autoselect enable
1568
        jz      .set_first_available_media
1569
 
1570
; check 100BASE-TX and 10BASE-T
5073 hidnplayr 1571
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1572
        in      ax, dx
1573
        test    al, 1010b       ; check whether 100BASE-TX or 10BASE-T available
1574
        jz      .mii_device     ; they are not available
1575
 
1576
; set auto-negotiation
5073 hidnplayr 1577
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1578
        in      eax, dx
1579
        and     eax, not (1111b shl 20)
1580
        or      eax, (1000b shl 20)
1581
        out     dx, eax
1582
        call    try_mii
1583
        test    al, al
1584
        jz      .mii_device
1585
        DEBUGF 1,"Using auto negotiation\n"
1586
        ret
1587
 
1588
  .mii_device:
1589
; switch to register window 3
5073 hidnplayr 1590
        set_io  [ebx + device.io_addr], 0
3545 hidnplayr 1591
; check for off-chip mii device
5073 hidnplayr 1592
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1593
        in      ax, dx
1594
        test    al, 1000000b ; check miiDevice
1595
        jz      .base_fx
5073 hidnplayr 1596
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1597
        in      eax, dx
1598
        and     eax, not (1111b shl 20)
1599
        or      eax, (0110b shl 20) ; set MIIDevice
1600
        out     dx, eax
1601
        call    try_mii
1602
        test    al, al
1603
        jz      .base_fx
1604
        DEBUGF 1,"Using off-chip mii device\n"
1605
        ret
1606
 
1607
  .base_fx:
1608
; switch to register window 3
5073 hidnplayr 1609
        set_io  [ebx + device.io_addr], 0
3545 hidnplayr 1610
; check for 100BASE-FX
5073 hidnplayr 1611
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1612
        in      ax, dx ; read media option register
1613
        test    al, 100b ; check 100BASE-FX
1614
        jz      .aui_enable
5073 hidnplayr 1615
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1616
        in      eax, dx
1617
        and     eax, not (1111b shl 20)
1618
        or      eax, (0101b shl 20) ; set 100base-FX
1619
        out     dx, eax
1620
        call    try_link_detect
1621
        test    al, al
1622
        jz      .aui_enable
1623
        DEBUGF 1,"Using 100Base-FX\n"
1624
        ret
1625
 
1626
  .aui_enable:
1627
; switch to register window 3
5073 hidnplayr 1628
        set_io  [ebx + device.io_addr], 0
3545 hidnplayr 1629
; check for 10Mbps AUI connector
5073 hidnplayr 1630
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1631
        in      ax, dx ; read media option register
1632
        test    al, 100000b ; check 10Mbps AUI connector
1633
        jz      .coax_available
5073 hidnplayr 1634
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1635
        in      eax, dx
1636
        and     eax, not (1111b shl 20)
1637
        or      eax, (0001b shl 20) ; set 10Mbps AUI connector
1638
        out     dx, eax
1639
        xor     al, al ; try 10Mbps AUI connector
1640
        call    try_loopback
1641
        test    al, al
1642
        jz      .coax_available
1643
        DEBUGF 1,"Using 10Mbps aui\n"
1644
        ret
1645
 
1646
  .coax_available:
1647
; switch to register window 3
5073 hidnplayr 1648
        set_io  [ebx + device.io_addr], 0
3545 hidnplayr 1649
; check for coaxial 10BASE-2 port
5073 hidnplayr 1650
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1651
        in      ax, dx ; read media option register
1652
        test    al, 10000b ; check 10BASE-2
1653
        jz      .set_first_available_media
1654
 
5073 hidnplayr 1655
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1656
        in      eax, dx
1657
        and     eax, not (1111b shl 20)
1658
        or      eax, (0011b shl 20) ; set 10BASE-2
1659
        out     dx, eax
1660
        mov     al, 1
1661
        call    try_loopback
1662
        test    al, al
1663
        jz      .set_first_available_media
1664
        DEBUGF 1,"Using 10BASE-2 port\n"
1665
        ret
1666
 
1667
  .set_first_available_media:
1668
        DEBUGF  1,"Using the first available media\n"
1669
 
1670
;***************************************************************************
1671
;   Function
1672
;      set_available_media
1673
;   Description
1674
;      sets the first available media
1675
;   Parameters
1676
;      ebx - ptr to device struct
1677
;   Return value
1678
;      al - 0
1679
;      al - 1
1680
;   Destroyed registers
1681
;      eax, edx
1682
;
1683
;***************************************************************************
1684
 
1685
align 4
1686
set_available_media:
1687
 
1688
        DEBUGF  1,"Setting the available media\n"
1689
; switch to register window 3
5073 hidnplayr 1690
        set_io  [ebx + device.io_addr], 0
1691
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1692
        mov     ax, SELECT_REGISTER_WINDOW+3
1693
        out     dx, ax
1694
 
5073 hidnplayr 1695
        set_io  [ebx + device.io_addr], REG_MEDIA_OPTIONS
3545 hidnplayr 1696
        in      ax, dx
1697
        DEBUGF  1,"available media:%x\n", al
1698
        mov     cl, al
1699
 
5073 hidnplayr 1700
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1701
        in      eax, dx
1702
        and     eax, not (1111b shl 20) ; these bits hold the 'transceiver select' value
1703
 
1704
        test    cl, 10b         ; baseTXAvailable
1705
        jz      @f
1706
 
1707
        DEBUGF  1,"base TX is available\n"
1708
        or      eax, (100b shl 20)
5073 hidnplayr 1709
if FORCE_FD
1710
        mov     word [ebx + device.internal_link], (1 shl 8)
3545 hidnplayr 1711
else
5073 hidnplayr 1712
        mov     word [ebx + device.internal_link], (1 shl 7)
3545 hidnplayr 1713
end if
1714
        jmp     .set_media
1715
       @@:
1716
 
1717
        test    cl, 100b        ; baseFXAvailable
1718
        jz      @f
1719
 
1720
        DEBUGF  1,"base FX is available\n"
1721
        or      eax, (101b shl 20)
5073 hidnplayr 1722
        mov     word [ebx + device.internal_link], (1 shl 10)
3545 hidnplayr 1723
        jmp     .set_media
1724
       @@:
1725
 
1726
        test    cl, 1000000b    ; miiDevice
1727
        jz      @f
1728
 
1729
        DEBUGF  1,"mii-device is available\n"
1730
        or      eax, (0110b shl 20)
5073 hidnplayr 1731
        mov     word [ebx + device.internal_link], (1 shl 13)
3545 hidnplayr 1732
        jmp     .set_media
1733
       @@:
1734
 
1735
        test    cl, 1000b       ; 10bTAvailable
1736
        jz      @f
1737
 
1738
        DEBUGF  1,"10base-T is available\n"
1739
  .set_default:
1740
if FORCE_FD
5073 hidnplayr 1741
        mov     word [ebx + device.internal_link], (1 shl 6)
3545 hidnplayr 1742
else
5073 hidnplayr 1743
        mov     word [ebx + device.internal_link], (1 shl 5)
3545 hidnplayr 1744
end if
1745
        jmp     .set_media
1746
       @@:
1747
 
1748
        test    cl, 10000b      ; coaxAvailable
1749
        jz      @f
1750
 
1751
        DEBUGF  1,"coax is available\n"
1752
        push    eax
5073 hidnplayr 1753
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1754
        mov     ax, (10b shl 11) ; EnableDcConverter
1755
        out     dx, ax
1756
        pop     eax
1757
 
1758
        or      eax, (11b shl 20)
5073 hidnplayr 1759
        mov     word [ebx + device.internal_link], (1 shl 12)
3545 hidnplayr 1760
        jmp     .set_media
1761
       @@:
1762
 
1763
        test    cl, 10000b      ; auiAvailable
1764
        jz      .set_default
1765
 
1766
        DEBUGF  1,"AUI is available\n"
1767
        or      eax, (1 shl 20)
5073 hidnplayr 1768
        mov     word [ebx + device.internal_link], (1 shl 11)
3545 hidnplayr 1769
 
1770
  .set_media:
5073 hidnplayr 1771
        set_io  [ebx + device.io_addr], 0
1772
        set_io  [ebx + device.io_addr], REG_INTERNAL_CONFIG
3545 hidnplayr 1773
        out     dx, eax
1774
 
1775
if FORCE_FD
1776
        DEBUGF  1,"Forcing full duplex\n"
5073 hidnplayr 1777
        set_io  [ebx + device.io_addr], REG_MAC_CONTROL
3545 hidnplayr 1778
        in      ax, dx
1779
        or      ax, 0x120
1780
        out     dx, ax
1781
end if
1782
 
1783
        mov     al, 1
1784
        ret
1785
 
1786
;***************************************************************************
1787
;   Function
1788
;      write_eeprom
1789
;   Description
1790
;      reads eeprom
1791
;      Note : the caller must switch to the register window 0
1792
;             before calling this function
1793
;   Parameters:
1794
;      ax - register to be read (only the first 63 words can be read)
1795
;      cx - value to be read into the register
1796
;   Return value:
1797
;      ax - word read
1798
;   Destroyed registers
1799
;      ax, ebx, edx
1800
;
1801
;***************************************************************************
1802
;       align 4
1803
;write_eeprom:
1804
;       mov     edx, [io_addr]
1805
;       add     edx, REG_EEPROM_COMMAND
1806
;       cmp     ah, 11b
1807
;       ja      .finish ; address may have a value of maximal 1023
1808
;       shl     ax, 2
1809
;       shr     al, 2
1810
;       push    eax
1811
;; wait for busy
1812
;       mov     ebx, 0xffff
1813
;@@:
1814
;       in      ax, dx
1815
;       test    ah, 0x80
1816
;       jz      .write_enable
1817
;       dec     ebx
1818
;       jns     @r
1819
;; write enable
1820
;.write_enable:
1821
;       xor     eax, eax
1822
;       mov     eax, (11b shl 4)
1823
;       out     dx, ax
1824
;; wait for busy
1825
;       mov     ebx, 0xffff
1826
;@@:
1827
;       in      ax, dx
1828
;       test    ah, 0x80
1829
;       jz      .erase_loop
1830
;       dec     ebx
1831
;       jns     @r
1832
;.erase_loop:
1833
;       pop     eax
1834
;       push    eax
1835
;       or      ax, (11b shl 6) ; erase register
1836
;       out     dx, ax
1837
;       mov     ebx, 0xffff
1838
;@@:
1839
;       in      ax, dx
1840
;       test    ah, 0x80
1841
;       jz      .write_reg
1842
;       dec     ebx
1843
;       jns     @r
1844
;.write_reg:
1845
;       add     edx, REG_EEPROM_DATA-REG_EEPROM_COMMAND
1846
;       mov     eax, ecx
1847
;       out     dx, ax
1848
;; write enable
1849
;       add     edx, REG_EEPROM_COMMAND-REG_EEPROM_DATA
1850
;       xor     eax, eax
1851
;       mov     eax, (11b shl 4)
1852
;       out     dx, ax
1853
; wait for busy
1854
;       mov     ebx, 0xffff
1855
;@@:
1856
;       in      ax, dx
1857
;       test    ah, 0x80
1858
;       jz      .issue_write_reg
1859
;       dec     ebx
1860
;       jns     @r
1861
;.issue_write_reg:
1862
;       pop     eax
1863
;       or      ax, 01b shl 6
1864
;       out     dx, ax
1865
;.finish:
1866
;       ret
1867
 
1868
 
1869
;***************************************************************************
1870
;   Function
1871
;      read_eeprom
1872
;   Description
1873
;      reads eeprom
1874
;   Parameters:
1875
;       ax - register to be read (only the first 63 words can be read)
1876
;      ebx = driver structure
1877
;   Return value:
1878
;      ax - word read
1879
;   Destroyed registers
1880
;      ax, ebx, edx
1881
;
1882
;***************************************************************************
1883
 
1884
align 4
1885
read_eeprom:
1886
 
1887
        DEBUGF 1,"Reading from eeprom.. "
1888
 
1889
        push    eax
1890
; switch to register window 0
5073 hidnplayr 1891
        set_io  [ebx + device.io_addr], 0
1892
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1893
        mov     ax, SELECT_REGISTER_WINDOW+0
1894
        out     dx, ax
1895
        pop     eax
1896
        and     ax, 111111b ; take only the first 6 bits into account
5073 hidnplayr 1897
        movzx   esi, [ebx + device.ver_id]
3545 hidnplayr 1898
 
1899
        test    word [esi*4+hw_versions+2], EEPROM_8BIT
1900
        jz      @f
1901
        add     ax, 0x230 ; hardware constant
1902
        jmp     .read
1903
@@:
1904
 
1905
        add     ax, EEPROM_CMD_READ
1906
        test    word [esi*4+hw_versions+2], EEPROM_OFFSET
1907
        jz      .read
1908
        add     ax, 0x30
1909
.read:
1910
 
5073 hidnplayr 1911
        set_io  [ebx + device.io_addr], REG_EEPROM_COMMAND
3545 hidnplayr 1912
        out     dx, ax
1913
        mov     ecx, 0xffff ; duration of about 162 us ;-)
1914
.wait_for_reading:
1915
        in      ax, dx
1916
        test    ah, 0x80 ; check bit eepromBusy
1917
        jz      .read_data
1918
        loop    .wait_for_reading
1919
.read_data:
5073 hidnplayr 1920
        set_io  [ebx + device.io_addr], REG_EEPROM_DATA
3545 hidnplayr 1921
        in      ax, dx
1922
 
1923
        DEBUGF 1,"ok!\n"
1924
 
1925
        ret
1926
 
1927
;***************************************************************************
1928
;   Function
1929
;      mdio_sync
1930
;   Description
1931
;      initial synchronization
1932
;   Parameters
3880 hidnplayr 1933
;
3545 hidnplayr 1934
;   Return value
1935
;   Destroyed registers
1936
;      ax, edx, cl
1937
;
1938
;***************************************************************************
1939
 
1940
align 4
1941
mdio_sync:
1942
 
1943
        DEBUGF 1,"syncing mdio\n"
1944
 
1945
; switch to register window 4
5073 hidnplayr 1946
        set_io  [ebx + device.io_addr], 0
1947
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 1948
        mov     ax, SELECT_REGISTER_WINDOW+4
1949
        out     dx, ax
5073 hidnplayr 1950
        cmp     [ebx + device.preamble], 0
3545 hidnplayr 1951
        je      .no_preamble
1952
; send 32 logic ones
5073 hidnplayr 1953
        set_io  [ebx + device.io_addr], REG_PHYSICAL_MGMT
3545 hidnplayr 1954
        mov     ecx, 31
1955
  .loop:
1956
        mov     ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR)
1957
        out     dx, ax
1958
        in      ax, dx ; delay
1959
        mov     ax, (1 shl BIT_MGMT_DATA) or (1 shl BIT_MGMT_DIR) or (1 shl BIT_MGMT_CLK)
1960
        out     dx, ax
1961
        in      ax, dx ; delay
1962
        loop    .loop
1963
  .no_preamble:
1964
 
1965
        ret
1966
 
1967
;***************************************************************************
1968
;   Function
1969
;      mdio_read
1970
;   Description
1971
;      read MII register
1972
;      see page 16 in D83840A.pdf
1973
;   Parameters
1974
;       ah - PHY addr
1975
;       al - register addr
1976
;      ebx = device structure
1977
;   Return value
1978
;      ax - register read
1979
;
1980
;***************************************************************************
1981
 
1982
align 4
1983
mdio_read:
1984
 
1985
        DEBUGF 1,"Reading MII registers\n"
1986
 
1987
        push    eax
1988
        call    mdio_sync ; returns with window #4
1989
        pop     eax
5073 hidnplayr 1990
        set_io  [ebx + device.io_addr], 0
1991
        set_io  [ebx + device.io_addr], REG_PHYSICAL_MGMT
3545 hidnplayr 1992
        shl     al, 3
1993
        shr     ax, 3
1994
        and     ax, not MII_CMD_MASK
1995
        or      ax, MII_CMD_READ
1996
 
1997
        mov     esi, eax
1998
        mov     ecx, 13
1999
  .cmd_loop:
2000
        mov     ax, (1 shl BIT_MGMT_DIR) ; write mii
2001
        bt      esi, ecx
2002
        jnc     .zero_bit
2003
        or      al, (1 shl BIT_MGMT_DATA)
2004
 
2005
  .zero_bit:
2006
        out     dx, ax
2007
        push    ax
2008
        in      ax, dx ; delay
2009
        pop     ax
2010
        or      al, (1 shl BIT_MGMT_CLK) ; write
2011
        out     dx, ax
2012
        in      ax, dx ; delay
2013
        loop    .cmd_loop
2014
 
2015
; read data (18 bits with the two transition bits)
2016
        mov     ecx, 17
2017
        xor     esi, esi
2018
  .read_loop:
2019
        shl     esi, 1
2020
        xor     eax, eax ; read comand
2021
        out     dx, ax
2022
        in      ax, dx ; delay
2023
        in      ax, dx
2024
        test    al, (1 shl BIT_MGMT_DATA)
2025
        jz      .dont_set
2026
        inc     esi
2027
  .dont_set:
2028
        mov     ax, (1 shl BIT_MGMT_CLK)
2029
        out     dx, ax
2030
        in      ax, dx ; delay
2031
        loop    .read_loop
2032
        mov     eax, esi
2033
 
2034
        ret
2035
 
2036
 
2037
 
2038
;***************************************************************************
2039
;   Function
2040
;      mdio_write
2041
;   Description
2042
;      write MII register
2043
;      see page 16 in D83840A.pdf
2044
;   Parameters
2045
;       ah - PHY addr
2046
;       al - register addr
2047
;       si - word to be written
2048
;   Return value
2049
;      ax - register read
2050
;
2051
;***************************************************************************
2052
 
2053
align 4
2054
mdio_write:
2055
 
2056
        DEBUGF 1,"Writing MII registers\n"
2057
 
2058
        push    eax
2059
        call    mdio_sync
2060
        pop     eax
5073 hidnplayr 2061
        set_io  [ebx + device.io_addr], 0
2062
        set_io  [ebx + device.io_addr], REG_PHYSICAL_MGMT
3545 hidnplayr 2063
        shl     al, 3
2064
        shr     ax, 3
2065
        and     ax, not MII_CMD_MASK
2066
        or      ax, MII_CMD_WRITE
2067
        shl     eax, 2
2068
        or      eax, 10b ; transition bits
2069
        shl     eax, 16
2070
        mov     ax, si
2071
        mov     esi, eax
2072
        mov     ecx, 31
2073
 
2074
  .cmd_loop:
2075
        mov     ax, (1 shl BIT_MGMT_DIR) ; write mii
2076
        bt      esi, ecx
2077
        jnc     @f
2078
        or      al, (1 shl BIT_MGMT_DATA)
2079
       @@:
2080
        out     dx, ax
2081
        push    eax
2082
        in      ax, dx ; delay
2083
        pop     eax
2084
        or      al, (1 shl BIT_MGMT_CLK) ; write
2085
        out     dx, ax
2086
        in      ax, dx ; delay
2087
        loop    .cmd_loop
2088
 
2089
        ret
2090
 
2091
 
2092
;***************************************************************************
2093
;   Function
2094
;      check_tx_status
2095
;   Description
2096
;      Checks TxStatus queue.
2097
;   Return value
2098
;      al - 0 no error was found
2099
;      al - 1 error was found TxReset was needed
2100
;   Destroyed registers
3880 hidnplayr 2101
;      eax, ecx, edx
3545 hidnplayr 2102
;
2103
;***************************************************************************
2104
 
2105
align 4
2106
check_tx_status:
2107
 
2108
        DEBUGF 1,"Checking TX status\n"
2109
 
2110
; clear TxStatus queue
5073 hidnplayr 2111
        set_io  [ebx + device.io_addr], 0
2112
        set_io  [ebx + device.io_addr], REG_TX_STATUS
3545 hidnplayr 2113
        mov     ecx, 31 ; max number of queue entries
2114
 
2115
  .tx_status_loop:
2116
        in      al, dx
2117
        test    al, al
2118
        jz      .finish ; no error
2119
        test    al, 0x3f
2120
        jnz     .error
2121
  .no_error_found:
2122
; clear current TxStatus entry which advances the next one
2123
        xor     al, al
2124
        out     dx, al
2125
        loop    .tx_status_loop
2126
 
2127
  .finish:
2128
        ret
2129
 
2130
  .error:
2131
        call    tx_reset
2132
        ret
2133
 
2134
 
2135
 
2136
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2137
;;                                         ;;
2138
;; Transmit (vortex)                       ;;
2139
;;                                         ;;
2140
;; In: buffer pointer in [esp+4]           ;;
2141
;;     pointer to device structure in ebx  ;;
2142
;;                                         ;;
2143
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2144
 
5522 hidnplayr 2145
proc vortex_transmit stdcall bufferptr
3545 hidnplayr 2146
 
5073 hidnplayr 2147
        pushf
2148
        cli
3545 hidnplayr 2149
 
5522 hidnplayr 2150
        mov     esi, [bufferptr]
2151
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
2152
        lea     eax, [esi + NET_BUFF.data]
5073 hidnplayr 2153
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
2154
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2155
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2156
        [eax+13]:2,[eax+12]:2
3545 hidnplayr 2157
 
5522 hidnplayr 2158
        cmp     [esi + NET_BUFF.length], 1514
5073 hidnplayr 2159
        ja      .fail
5522 hidnplayr 2160
        cmp     [esi + NET_BUFF.length], 60
5073 hidnplayr 2161
        jb      .fail
2162
 
3545 hidnplayr 2163
        call    check_tx_status
2164
 
2165
; switch to register window 7
5073 hidnplayr 2166
        set_io  [ebx + device.io_addr], 0
2167
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2168
        mov     ax, SELECT_REGISTER_WINDOW+7
2169
        out     dx, ax
5522 hidnplayr 2170
 
3545 hidnplayr 2171
; check for master operation in progress
5073 hidnplayr 2172
        set_io  [ebx + device.io_addr], REG_MASTER_STATUS
3545 hidnplayr 2173
        in      ax, dx
2174
        test    ah, 0x80
4334 hidnplayr 2175
        jnz     .fail ; no DMA for sending
5522 hidnplayr 2176
 
3545 hidnplayr 2177
; program frame address to be sent
5073 hidnplayr 2178
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
5522 hidnplayr 2179
        mov     eax, esi
2180
        add     eax, [eax + NET_BUFF.offset]
5073 hidnplayr 2181
        invoke  GetPhysAddr
3545 hidnplayr 2182
        out     dx, eax
5522 hidnplayr 2183
 
3545 hidnplayr 2184
; program frame length
5073 hidnplayr 2185
        set_io  [ebx + device.io_addr], REG_MASTER_LEN
5522 hidnplayr 2186
        mov     eax, [esi + NET_BUFF.length]
3545 hidnplayr 2187
        out     dx, ax
5522 hidnplayr 2188
 
3545 hidnplayr 2189
; start DMA Down
5073 hidnplayr 2190
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2191
        mov     ax, (10100b shl 11) + 1 ; StartDMADown
2192
        out     dx, ax
4334 hidnplayr 2193
  .finish:
5073 hidnplayr 2194
        popf
4334 hidnplayr 2195
        xor     eax, eax
5073 hidnplayr 2196
        ret
3545 hidnplayr 2197
 
4334 hidnplayr 2198
  .fail:
5073 hidnplayr 2199
        DEBUGF  2,"Send failed\n"
5522 hidnplayr 2200
        invoke  NetFree, [bufferptr]
5073 hidnplayr 2201
        popf
4334 hidnplayr 2202
        or      eax, -1
5073 hidnplayr 2203
        ret
3545 hidnplayr 2204
 
5073 hidnplayr 2205
endp
2206
 
3545 hidnplayr 2207
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2208
;;                                         ;;
2209
;; Transmit (boomerang)                    ;;
2210
;;                                         ;;
2211
;; In: buffer pointer in [esp+4]           ;;
2212
;;     pointer to device structure in ebx  ;;
2213
;;                                         ;;
2214
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2215
 
5522 hidnplayr 2216
proc boomerang_transmit stdcall bufferptr
3545 hidnplayr 2217
 
5073 hidnplayr 2218
        pushf
2219
        cli
2220
 
5522 hidnplayr 2221
        mov     esi, [bufferptr]
2222
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length]
2223
        lea     eax, [esi + NET_BUFF.data]
3545 hidnplayr 2224
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
2225
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
2226
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
2227
        [eax+13]:2,[eax+12]:2
2228
 
5522 hidnplayr 2229
        cmp     [esi + NET_BUFF.length], 1514
3545 hidnplayr 2230
        ja      .fail
5522 hidnplayr 2231
        cmp     [esi + NET_BUFF.length], 60
5073 hidnplayr 2232
        jb      .fail
3545 hidnplayr 2233
 
5073 hidnplayr 2234
        call    check_tx_status                         ; Reset TX engine if needed
3545 hidnplayr 2235
 
2236
; calculate descriptor address
5522 hidnplayr 2237
        mov     edi, [ebx + device.curr_tx]
2238
        DEBUGF  1,"Previous TX desc: %x\n", edi
2239
        add     edi, sizeof.tx_desc
5073 hidnplayr 2240
        lea     ecx, [ebx + device.tx_desc_buffer + (NUM_TX_DESC)*sizeof.tx_desc]
5522 hidnplayr 2241
        cmp     edi, ecx
3545 hidnplayr 2242
        jb      @f
5522 hidnplayr 2243
        lea     edi, [ebx + device.tx_desc_buffer]      ; Wrap if needed
3545 hidnplayr 2244
       @@:
5073 hidnplayr 2245
        DEBUGF  1,"Using TX desc: %x\n", esi
3545 hidnplayr 2246
 
2247
; check DnListPtr
5073 hidnplayr 2248
        set_io  [ebx + device.io_addr], 0
2249
        set_io  [ebx + device.io_addr], REG_DN_LIST_PTR
3545 hidnplayr 2250
        in      eax, dx
2251
; mark if Dn_List_Ptr is cleared
2252
        test    eax, eax
5073 hidnplayr 2253
        setz    [ebx + device.dn_list_ptr_cleared]
3545 hidnplayr 2254
 
2255
; finish if no more free descriptor is available - FIXME!
2256
;        cmp     eax, esi
2257
;        jz      .finish
2258
 
2259
; update statistics
5073 hidnplayr 2260
        inc     [ebx + device.packets_tx]
5522 hidnplayr 2261
        mov     ecx, [esi + NET_BUFF.length]
5073 hidnplayr 2262
        add     dword [ebx + device.bytes_tx], ecx
2263
        adc     dword [ebx + device.bytes_tx + 4], 0
3545 hidnplayr 2264
 
2265
; program DPD
5522 hidnplayr 2266
        and     [edi + tx_desc.next_ptr], 0
5073 hidnplayr 2267
        mov     eax, [bufferptr]
5522 hidnplayr 2268
        mov     [edi + tx_desc.realaddr], eax
2269
        add     eax, [eax + NET_BUFF.offset]
5073 hidnplayr 2270
        invoke  GetPhysAddr
5522 hidnplayr 2271
        mov     [edi + tx_desc.frag_addr], eax
2272
;;;        mov     ecx, [buffersize]
5073 hidnplayr 2273
        or      ecx, 0x80000000         ; last fragment flag
5522 hidnplayr 2274
        mov     [edi + tx_desc.frag_len], ecx
3545 hidnplayr 2275
 
5522 hidnplayr 2276
;;;        mov     ecx, [buffersize]       ; packet size
5073 hidnplayr 2277
        or      ecx, 0x80008000         ; set OWN bit + transmission complete notification flag
2278
;        test    byte [ebx + device.has_hwcksm], 0xff
3545 hidnplayr 2279
;        jz      @f
2280
;        or      ecx, (1 shl 26)         ; set AddTcpChecksum
2281
;@@:
5522 hidnplayr 2282
        mov     [edi + tx_desc.frame_start_hdr], ecx
2283
        DEBUGF  1,"TX desc: lin=%x phys=%x len=%x start hdr=%x\n", [edi+tx_desc.realaddr]:8, [edi+tx_desc.frag_addr]:8, [edi+tx_desc.frag_len]:8, [edi+tx_desc.frame_start_hdr]:8
3545 hidnplayr 2284
 
5073 hidnplayr 2285
; calculate physical address of tx descriptor
5522 hidnplayr 2286
        mov     eax, edi
5073 hidnplayr 2287
        invoke  GetPhysAddr
2288
        cmp     [ebx + device.dn_list_ptr_cleared], 0
2289
        je      .add_to_list
3545 hidnplayr 2290
 
2291
; write Dn_List_Ptr
5073 hidnplayr 2292
        DEBUGF  1,"TX desc phys addr=%x\n", eax
2293
        set_io  [ebx + device.io_addr], 0
2294
        set_io  [ebx + device.io_addr], REG_DN_LIST_PTR
3545 hidnplayr 2295
        out     dx, eax
2296
        jmp     .finish
2297
 
2298
  .add_to_list:
2299
        DEBUGF  1,"Adding To list\n"
2300
        push    eax
2301
; DnStall
5073 hidnplayr 2302
        set_io  [ebx + device.io_addr], 0
2303
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2304
        mov     ax, ((110b shl 11)+2)
2305
        out     dx, ax
2306
 
2307
; wait for DnStall to complete
2308
        DEBUGF  1,"Waiting for DnStall\n"
2309
        mov     ecx, 6000
2310
  .wait_for_stall:
2311
        in      ax, dx                  ; read REG_INT_STATUS
2312
        test    ah, 10000b
2313
        jz      .dnstall_ok
2314
        dec     ecx
2315
        jnz     .wait_for_stall
2316
 
2317
  .dnstall_ok:
2318
        DEBUGF  1,"DnStall ok!\n"
5073 hidnplayr 2319
        mov     ecx, [ebx + device.curr_tx]
2320
        mov     [ecx + tx_desc.next_ptr], eax
3545 hidnplayr 2321
 
5073 hidnplayr 2322
        set_io  [ebx + device.io_addr], 0
2323
        set_io  [ebx + device.io_addr], REG_DN_LIST_PTR
3545 hidnplayr 2324
        in      eax, dx
2325
        test    eax, eax
2326
        pop     eax
2327
        jnz     .dnunstall
2328
 
2329
; if Dn_List_Ptr has been cleared fill it up
2330
        DEBUGF  1,"DnList Ptr has been cleared\n"
2331
        out     dx, eax
2332
 
2333
  .dnunstall:
2334
; DnUnStall
5073 hidnplayr 2335
        set_io  [ebx + device.io_addr], 0
2336
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2337
        mov     ax, ((110b shl 11)+3)
2338
        out     dx, ax
2339
 
2340
  .finish:
5522 hidnplayr 2341
        mov     [ebx + device.curr_tx], edi
5073 hidnplayr 2342
        popf
3545 hidnplayr 2343
        xor     eax, eax
5073 hidnplayr 2344
        ret
3545 hidnplayr 2345
 
2346
  .fail:
5073 hidnplayr 2347
        DEBUGF  2,"Send failed\n"
5522 hidnplayr 2348
        invoke  NetFree, [bufferptr]
5073 hidnplayr 2349
        popf
3545 hidnplayr 2350
        or      eax, -1
5073 hidnplayr 2351
        ret
3545 hidnplayr 2352
 
5073 hidnplayr 2353
endp
3545 hidnplayr 2354
 
5073 hidnplayr 2355
 
2356
 
3545 hidnplayr 2357
;---------------------------------
2358
; Write MAC
2359
 
2360
align 4
2361
write_mac:
2362
 
2363
        DEBUGF 1,"Writing mac\n"
2364
 
5073 hidnplayr 2365
        set_io  [ebx + device.io_addr], 0
2366
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2367
 
2368
; switch to register window 2
2369
        mov     ax, SELECT_REGISTER_WINDOW+2
2370
        out     dx, ax
2371
 
2372
; write MAC addres back into the station address registers
5073 hidnplayr 2373
        set_io  [ebx + device.io_addr], REG_STATION_ADDRESS_LO
2374
        lea     esi, [ebx + device.mac]
3545 hidnplayr 2375
        outsw
2376
        inc     dx
2377
        inc     dx
2378
        outsw
2379
        inc     dx
2380
        inc     dx
2381
        outsw
2382
 
2383
 
2384
;----------------------------
2385
; Read MAC
2386
 
2387
align 4
2388
read_mac:
2389
 
5073 hidnplayr 2390
        DEBUGF 1,"Reading MAC\n"
3545 hidnplayr 2391
 
5073 hidnplayr 2392
        set_io  [ebx + device.io_addr], 0
2393
        set_io  [ebx + device.io_addr], REG_COMMAND
2394
 
3545 hidnplayr 2395
; switch to register window 2
2396
        mov     ax, SELECT_REGISTER_WINDOW+2
2397
        out     dx, ax
2398
 
5073 hidnplayr 2399
; Read the MAC and write it to device.mac
2400
        set_io  [ebx + device.io_addr], REG_STATION_ADDRESS_LO
2401
        lea     edi, [ebx + device.mac]
3545 hidnplayr 2402
        insw
2403
        inc     dx
2404
        inc     dx
2405
        insw
2406
        inc     dx
2407
        inc     dx
2408
        insw
2409
 
5073 hidnplayr 2410
        DEBUGF 1,"%x-%x-%x-%x-%x-%x\n", \
2411
        [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,\
2412
        [ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
3545 hidnplayr 2413
 
2414
        ret
2415
 
2416
 
2417
;------------------------------------
2418
; Read MAC from eeprom
2419
 
2420
align 4
5073 hidnplayr 2421
read_mac_eeprom:
3545 hidnplayr 2422
 
5073 hidnplayr 2423
        DEBUGF 1,"Reading MAC from eeprom\n"
3545 hidnplayr 2424
 
5073 hidnplayr 2425
; read MAC from eeprom and write it to device.mac
3545 hidnplayr 2426
        mov     ecx, 3
2427
  .mac_loop:
2428
        lea     ax, [EEPROM_REG_OEM_NODE_ADDR+ecx-1]
2429
        push    ecx
2430
        call    read_eeprom
2431
        pop     ecx
5073 hidnplayr 2432
        xchg    ah, al
2433
        mov     word [ebx + device.mac+ecx*2-2], ax
3545 hidnplayr 2434
        loop    .mac_loop
2435
 
5073 hidnplayr 2436
        DEBUGF 1,"%x-%x-%x-%x-%x-%x\n",\
2437
        [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,\
2438
        [ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2
3545 hidnplayr 2439
 
2440
        ret
2441
 
2442
 
2443
 
2444
 
2445
 
2446
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2447
;;                          ;;
2448
;; Vortex Interrupt handler ;;
2449
;;                          ;;
2450
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2451
 
2452
align 4
2453
int_vortex:
2454
 
2455
        push    ebx esi edi
2456
 
3880 hidnplayr 2457
        DEBUGF  1,"INT\n"
3545 hidnplayr 2458
 
2459
; find pointer of device wich made IRQ occur
2460
 
5073 hidnplayr 2461
        mov     ecx, [vortex_devices]
3545 hidnplayr 2462
        test    ecx, ecx
2463
        jz      .nothing
5073 hidnplayr 2464
        mov     esi, vortex_list
3545 hidnplayr 2465
  .nextdevice:
5073 hidnplayr 2466
        mov     ebx, [esi]
3545 hidnplayr 2467
 
2468
 
5073 hidnplayr 2469
        set_io  [ebx + device.io_addr], 0
2470
        set_io  [ebx + device.io_addr], REG_INT_STATUS
3545 hidnplayr 2471
        in      ax, dx
2472
        and     ax, S_5_INTS
2473
        jnz     .nothing
2474
 
2475
        add     esi, 4
2476
 
2477
        test    ax , ax
2478
        jnz     .got_it
2479
        loop    .nextdevice
2480
 
2481
  .nothing:
2482
        pop     edi esi ebx
2483
        xor     eax, eax
2484
 
2485
        ret
2486
 
2487
.got_it:
2488
 
5073 hidnplayr 2489
        DEBUGF  1,"Device: %x Status: %x\n", ebx, eax:4
3545 hidnplayr 2490
 
2491
        test    ax, RxComplete
2492
        jz      .noRX
2493
 
5073 hidnplayr 2494
        set_io  [ebx + device.io_addr], 0
3545 hidnplayr 2495
  .rx_status_loop:
2496
; examine RxStatus
5073 hidnplayr 2497
        set_io  [ebx + device.io_addr], REG_RX_STATUS
3545 hidnplayr 2498
        in      ax, dx
2499
        test    ax, ax
2500
        jz      .finish
2501
 
2502
        test    ah, 0x80 ; rxIncomplete
2503
        jnz     .finish
2504
 
2505
        test    ah, 0x40
2506
        jz      .check_length
2507
 
2508
; discard the top frame received advancing the next one
5073 hidnplayr 2509
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2510
        mov     ax, (01000b shl 11)
2511
        out     dx, ax
2512
        jmp     .rx_status_loop
2513
 
2514
  .check_length:
2515
        and     eax, 0x1fff
5522 hidnplayr 2516
        cmp     eax, MAX_ETH_FRAME_SIZE
3545 hidnplayr 2517
        ja      .discard_frame ; frame is too long discard it
2518
 
2519
  .check_dma:
2520
        mov     ecx, eax
2521
; switch to register window 7
5073 hidnplayr 2522
        set_io  [ebx + device.io_addr], 0
2523
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2524
        mov     ax, SELECT_REGISTER_WINDOW+7
2525
        out     dx, ax
2526
; check for master operation in progress
5073 hidnplayr 2527
        set_io  [ebx + device.io_addr], REG_MASTER_STATUS
3545 hidnplayr 2528
        in      ax, dx
2529
 
2530
        test    ah, 0x80
2531
        jnz     .finish
2532
 
2533
  .read_frame:
2534
; program buffer address to read in
2535
        push    ecx
5522 hidnplayr 2536
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE + NET_BUFF.data
3545 hidnplayr 2537
        pop     ecx
2538
        test    eax, eax
2539
        jz      .finish
2540
 
2541
        push    .discard_frame
2542
        push    eax
5522 hidnplayr 2543
        mov     [eax + NET_BUFF.length], ecx
2544
        mov     [eax + NET_BUFF.device], ebx
2545
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
2546
        invoke  GetPhysAddr
2547
        add     eax, NET_BUFF.data
5073 hidnplayr 2548
        set_io  [ebx + device.io_addr], REG_MASTER_ADDRESS
3545 hidnplayr 2549
        out     dx, eax
2550
 
2551
; program frame length
5073 hidnplayr 2552
        set_io  [ebx + device.io_addr], REG_MASTER_LEN
3545 hidnplayr 2553
        mov     ax, 1560
2554
        out     dx, ax
2555
 
2556
; start DMA Up
5073 hidnplayr 2557
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2558
        mov     ax, (10100b shl 11) ; StartDMAUp
2559
        out     dx, ax
2560
 
2561
; check for master operation in progress
5073 hidnplayr 2562
        set_io  [ebx + device.io_addr], REG_MASTER_STATUS   ; TODO: use timeout and reset after timeout expired
3545 hidnplayr 2563
  .dma_loop:
2564
        in      ax, dx
2565
        test    ah, 0x80
2566
        jnz     .dma_loop
2567
 
2568
; registrate the received packet to kernel
5522 hidnplayr 2569
        jmp     [EthInput]
3545 hidnplayr 2570
 
2571
; discard the top frame received
2572
  .discard_frame:
5073 hidnplayr 2573
        set_io  [ebx + device.io_addr], 0
2574
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2575
        mov     ax, (01000b shl 11)
2576
        out     dx, ax
2577
 
2578
  .finish:
2579
 
2580
 
5522 hidnplayr 2581
  .noRX:
3545 hidnplayr 2582
 
2583
        test    ax, DMADone
2584
        jz      .noDMA
2585
 
2586
        push    ax
2587
 
5073 hidnplayr 2588
        set_io  [ebx + device.io_addr], 0
2589
        set_io  [ebx + device.io_addr], 12
3545 hidnplayr 2590
        in      ax, dx
2591
        test    ax, 0x1000
2592
        jz      .nodmaclear
2593
 
2594
        mov     ax, 0x1000
2595
        out     dx, ax
2596
 
2597
  .nodmaclear:
2598
 
2599
        pop     ax
2600
 
2601
        DEBUGF  1, "DMA Done!\n", cx
2602
 
2603
 
2604
 
5522 hidnplayr 2605
  .noDMA:
3545 hidnplayr 2606
 
2607
 
2608
 
5522 hidnplayr 2609
  .ACK:
5073 hidnplayr 2610
        set_io  [ebx + device.io_addr], 0
2611
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2612
        mov     ax, AckIntr + IntReq + IntLatch
2613
        out     dx, ax
2614
 
2615
        pop     edi esi ebx
2616
 
2617
        ret
2618
 
2619
 
2620
 
2621
 
2622
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2623
;;                             ;;
2624
;; Boomerang Interrupt handler ;;
2625
;;                             ;;
2626
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2627
 
2628
align 4
2629
int_boomerang:
2630
 
2631
        push    ebx esi edi
2632
 
3880 hidnplayr 2633
        DEBUGF  1,"INT\n"
3545 hidnplayr 2634
 
2635
; find pointer of device wich made IRQ occur
2636
 
5073 hidnplayr 2637
        mov     ecx, [boomerang_devices]
3545 hidnplayr 2638
        test    ecx, ecx
2639
        jz      .nothing
5073 hidnplayr 2640
        mov     esi, boomerang_list
3545 hidnplayr 2641
  .nextdevice:
2642
        mov     ebx, [esi]
2643
 
5073 hidnplayr 2644
        set_io  [ebx + device.io_addr], 0
2645
        set_io  [ebx + device.io_addr], REG_INT_STATUS
3545 hidnplayr 2646
        in      ax, dx
5073 hidnplayr 2647
        test    ax, S_5_INTS
3545 hidnplayr 2648
        jnz     .got_it
2649
  .continue:
2650
        add     esi, 4
2651
        dec     ecx
2652
        jnz     .nextdevice
2653
  .nothing:
2654
        pop     edi esi ebx
2655
        xor     eax, eax
2656
 
2657
        ret
2658
 
2659
  .got_it:
2660
 
5073 hidnplayr 2661
        DEBUGF  1,"Device: %x Status: %x\n", ebx, ax
3545 hidnplayr 2662
        push    ax
2663
 
2664
; disable all INTS
2665
 
5073 hidnplayr 2666
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2667
        mov     ax, SetIntrEnb
2668
        out     dx, ax
2669
 
2670
;--------------------------------------------------------------------------
2671
        test    word[esp], UpComplete
2672
        jz      .noRX
2673
 
2674
        push    ebx
2675
 
2676
  .receive:
2677
        DEBUGF  1,"UpComplete\n"
2678
 
2679
; check if packet is uploaded
5073 hidnplayr 2680
        mov     esi, [ebx + device.curr_rx]
2681
        test    byte [esi+rx_desc.pkt_status+1], 0x80 ; upPktComplete
3545 hidnplayr 2682
        jz      .finish
5073 hidnplayr 2683
        DEBUGF  1, "Current RX desc: %x\n", esi
3545 hidnplayr 2684
; packet is uploaded check for any error
2685
  .check_error:
5073 hidnplayr 2686
        test    byte [esi + rx_desc.pkt_status+1], 0x40 ; upError
3545 hidnplayr 2687
        jz      .copy_packet_length
2688
        DEBUGF  1,"Error in packet\n"
5073 hidnplayr 2689
        and     [esi + rx_desc.pkt_status], 0           ; mark packet as read
3545 hidnplayr 2690
        jmp     .finish
2691
  .copy_packet_length:
5073 hidnplayr 2692
        mov     ecx, [esi + rx_desc.pkt_status]
3545 hidnplayr 2693
        and     ecx, 0x1fff
2694
 
2695
;        cmp     ecx, MAX_ETH_PKT_SIZE
2696
;        jbe     .copy_packet
5073 hidnplayr 2697
;        and     [esi+rx_desc.pkt_status], 0
3545 hidnplayr 2698
;        jmp     .finish
2699
;  .copy_packet:
2700
 
5073 hidnplayr 2701
        DEBUGF  1, "Received %u bytes in buffer %x\n", ecx, [esi + rx_desc.realaddr]:8
3545 hidnplayr 2702
 
2703
        push    dword .loop ;.finish
5522 hidnplayr 2704
        mov     eax, [esi + rx_desc.realaddr]
2705
        push    eax
2706
        mov     [eax + NET_BUFF.length], ecx
2707
        mov     [eax + NET_BUFF.device], ebx
2708
        mov     [eax + NET_BUFF.offset], NET_BUFF.data
3545 hidnplayr 2709
 
2710
; update statistics
5073 hidnplayr 2711
        inc     [ebx + device.packets_rx]
2712
        add     dword [ebx + device.bytes_rx], ecx
2713
        adc     dword [ebx + device.bytes_rx + 4], 0
3545 hidnplayr 2714
 
5073 hidnplayr 2715
; update rx descriptor (Alloc new buffer for next packet)
5522 hidnplayr 2716
        invoke  NetAlloc, MAX_ETH_FRAME_SIZE + NET_BUFF.data
5073 hidnplayr 2717
        mov     [esi + rx_desc.realaddr], eax
2718
        invoke  GetPhysAddr
5522 hidnplayr 2719
        add     eax, NET_BUFF.data
5073 hidnplayr 2720
        mov     [esi + rx_desc.frag_addr], eax
2721
        and     [esi + rx_desc.pkt_status], 0
2722
        mov     [esi + rx_desc.frag_len], MAX_ETH_FRAME_SIZE or (1 shl 31)
3545 hidnplayr 2723
 
5073 hidnplayr 2724
; Update rx descriptor pointer
2725
        add     esi, sizeof.rx_desc
2726
        lea     ecx, [ebx + device.rx_desc_buffer+(NUM_RX_DESC)*sizeof.rx_desc]
3545 hidnplayr 2727
        cmp     esi, ecx
2728
        jb      @f
5073 hidnplayr 2729
        lea     esi, [ebx + device.rx_desc_buffer]
3545 hidnplayr 2730
       @@:
5073 hidnplayr 2731
        mov     [ebx + device.curr_rx], esi
2732
        DEBUGF  1, "Next RX desc: %x\n", esi
3545 hidnplayr 2733
 
5522 hidnplayr 2734
        jmp     [EthInput]
3545 hidnplayr 2735
  .loop:
2736
 
2737
        mov     ebx, [esp]
2738
        jmp     .receive
2739
 
2740
  .finish:
2741
        pop     ebx
2742
 
2743
; check if the NIC is in the upStall state
5073 hidnplayr 2744
        set_io  [ebx + device.io_addr], 0
2745
        set_io  [ebx + device.io_addr], REG_UP_PKT_STATUS
3545 hidnplayr 2746
        in      eax, dx
2747
        test    ah, 0x20             ; UpStalled
2748
        jz      .noUpUnStall
2749
 
2750
        DEBUGF  1, "upUnStalling\n"
2751
; issue upUnStall command
5073 hidnplayr 2752
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2753
        mov     ax, ((11b shl 12)+1) ; upUnStall
2754
        out     dx, ax
2755
 
2756
        ;;;; FIXME: make upunstall work
2757
 
2758
  .noUpUnStall:
2759
.noRX:
2760
        test    word[esp], DownComplete
2761
        jz      .noTX
2762
        DEBUGF  1, "Downcomplete!\n"
2763
 
2764
        mov     ecx, NUM_TX_DESC
5073 hidnplayr 2765
        lea     esi, [ebx + device.tx_desc_buffer]
3545 hidnplayr 2766
  .txloop:
5073 hidnplayr 2767
        test    [esi+tx_desc.frame_start_hdr], 1 shl 31
3545 hidnplayr 2768
        jz      .maybenext
2769
 
5073 hidnplayr 2770
        and     [esi+tx_desc.frame_start_hdr], 0
3545 hidnplayr 2771
        push    ecx
5522 hidnplayr 2772
        invoke  NetFree, [esi+tx_desc.realaddr]
3545 hidnplayr 2773
        pop     ecx
2774
 
2775
  .maybenext:
5073 hidnplayr 2776
        add     esi, sizeof.tx_desc
3545 hidnplayr 2777
        dec     ecx
2778
        jnz     .txloop
2779
 
2780
.noTX:
2781
        pop     ax
2782
 
5073 hidnplayr 2783
        set_io  [ebx + device.io_addr], 0
2784
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2785
        or      ax, AckIntr
2786
        out     dx, ax
2787
 
5073 hidnplayr 2788
        set_io  [ebx + device.io_addr], REG_INT_STATUS
3545 hidnplayr 2789
        in      ax, dx
2790
        test    ax, S_5_INTS
2791
        jnz     .got_it
2792
 
2793
;re-enable ints
5073 hidnplayr 2794
        set_io  [ebx + device.io_addr], REG_COMMAND
3545 hidnplayr 2795
        mov     ax, SetIntrEnb + S_5_INTS
2796
        out     dx, ax
2797
 
2798
        pop     edi esi ebx
2799
 
2800
        ret
2801
 
2802
 
2803
 
2804
 
2805
; End of code
2806
 
5073 hidnplayr 2807
data fixups
2808
end data
2809
 
2810
include '../peimport.inc'
2811
 
2812
my_service           db '3C59X',0                    ; max 16 chars include zero
2813
 
3545 hidnplayr 2814
macro strtbl name, [string]
2815
{
2816
common
2817
        label name dword
2818
forward
2819
        local label
2820
        dd label
2821
forward
2822
        label db string, 0
2823
}
2824
 
2825
strtbl link_str, \
2826
        "No valid link type detected", \
2827
        "10BASE-T half duplex", \
2828
        "10BASE-T full-duplex", \
2829
        "100BASE-TX half duplex", \
2830
        "100BASE-TX full duplex", \
2831
        "100BASE-T4", \
2832
        "100BASE-FX", \
2833
        "10Mbps AUI", \
2834
        "10Mbps COAX (BNC)", \
2835
        "miiDevice - not supported"
2836
 
2837
strtbl hw_str, \
2838
        "3c590 Vortex 10Mbps", \
2839
        "3c592 EISA 10Mbps Demon/Vortex", \
2840
        "3c597 EISA Fast Demon/Vortex", \
2841
        "3c595 Vortex 100baseTx", \
2842
        "3c595 Vortex 100baseT4", \
2843
        "3c595 Vortex 100base-MII", \
2844
        "3c900 Boomerang 10baseT", \
2845
        "3c900 Boomerang 10Mbps Combo", \
2846
        "3c900 Cyclone 10Mbps TPO", \
2847
        "3c900 Cyclone 10Mbps Combo", \
2848
        "3c900 Cyclone 10Mbps TPC", \
2849
        "3c900B-FL Cyclone 10base-FL", \
2850
        "3c905 Boomerang 100baseTx", \
2851
        "3c905 Boomerang 100baseT4", \
2852
        "3c905B Cyclone 100baseTx", \
2853
        "3c905B Cyclone 10/100/BNC", \
2854
        "3c905B-FX Cyclone 100baseFx", \
2855
        "3c905C Tornado", \
2856
        "3c980 Cyclone", \
2857
        "3c982 Dual Port Server Cyclone", \
2858
        "3cSOHO100-TX Hurricane", \
2859
        "3c555 Laptop Hurricane", \
2860
        "3c556 Laptop Tornado", \
2861
        "3c556B Laptop Hurricane", \
2862
        "3c575 [Megahertz] 10/100 LAN CardBus", \
2863
        "3c575 Boomerang CardBus", \
2864
        "3CCFE575BT Cyclone CardBus", \
2865
        "3CCFE575CT Tornado CardBus", \
2866
        "3CCFE656 Cyclone CardBus", \
2867
        "3CCFEM656B Cyclone+Winmodem CardBus", \
2868
        "3CXFEM656C Tornado+Winmodem CardBus", \
2869
        "3c450 HomePNA Tornado", \
2870
        "3c920 Tornado", \
2871
        "3c982 Hydra Dual Port A", \
2872
        "3c982 Hydra Dual Port B", \
2873
        "3c905B-T4", \
2874
        "3c920B-EMB-WNM Tornado"
2875
 
2876
 
2877
 
2878
align 4
2879
hw_versions:
2880
dw 0x5900, IS_VORTEX                                                                                                            ; 3c590 Vortex 10Mbps
2881
dw 0x5920, IS_VORTEX                                                                                                            ; 3c592 EISA 10Mbps Demon/Vortex
2882
dw 0x5970, IS_VORTEX                                                                                                            ; 3c597 EISA Fast Demon/Vortex
2883
dw 0x5950, IS_VORTEX                                                                                                            ; 3c595 Vortex 100baseTx
2884
dw 0x5951, IS_VORTEX                                                                                                            ; 3c595 Vortex 100baseT4
2885
dw 0x5952, IS_VORTEX                                                                                                            ; 3c595 Vortex 100base-MII
2886
dw 0x9000, IS_BOOMERANG                                                                                                         ; 3c900 Boomerang 10baseT
2887
dw 0x9001, IS_BOOMERANG                                                                                                         ; 3c900 Boomerang 10Mbps Combo
2888
dw 0x9004, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c900 Cyclone 10Mbps TPO
2889
dw 0x9005, IS_CYCLONE or HAS_HWCKSM                                                                                             ; 3c900 Cyclone 10Mbps Combo
2890
dw 0x9006, IS_CYCLONE or HAS_HWCKSM                                                                                             ; 3c900 Cyclone 10Mbps TPC
2891
dw 0x900A, IS_CYCLONE or HAS_HWCKSM                                                                                             ; 3c900B-FL Cyclone 10base-FL
2892
dw 0x9050, IS_BOOMERANG or HAS_MII                                                                                              ; 3c905 Boomerang 100baseTx
2893
dw 0x9051, IS_BOOMERANG or HAS_MII                                                                                              ; 3c905 Boomerang 100baseT4
2894
dw 0x9055, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM or EXTRA_PREAMBLE                                                               ; 3c905B Cyclone 100baseTx
2895
dw 0x9058, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c905B Cyclone 10/100/BNC
2896
dw 0x905A, IS_CYCLONE or HAS_HWCKSM                                                                                             ; 3c905B-FX Cyclone 100baseFx
2897
dw 0x9200, IS_TORNADO or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c905C Tornado
2898
dw 0x9800, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c980 Cyclone
2899
dw 0x9805, IS_TORNADO or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c982 Dual Port Server Cyclone
2900
dw 0x7646, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3cSOHO100-TX Hurricane
2901
dw 0x5055, IS_CYCLONE or EEPROM_8BIT or HAS_HWCKSM                                                                              ; 3c555 Laptop Hurricane
2902
dw 0x6055, IS_TORNADO or HAS_NWAY or EEPROM_8BIT or HAS_CB_FNS or INVERT_MII_PWR or HAS_HWCKSM                                  ; 3c556 Laptop Tornado
2903
dw 0x6056, IS_TORNADO or HAS_NWAY or EEPROM_OFFSET or HAS_CB_FNS or INVERT_MII_PWR or HAS_HWCKSM                                ; 3c556B Laptop Hurricane
2904
dw 0x5b57, IS_BOOMERANG or HAS_MII or EEPROM_8BIT                                                                               ; 3c575 [Megahertz] 10/100 LAN CardBus
2905
dw 0x5057, IS_BOOMERANG or HAS_MII or EEPROM_8BIT                                                                               ; 3c575 Boomerang CardBus
2906
dw 0x5157, IS_CYCLONE or HAS_NWAY or HAS_CB_FNS or EEPROM_8BIT or INVERT_LED_PWR or HAS_HWCKSM                                  ; 3CCFE575BT Cyclone CardBus
2907
dw 0x5257, IS_TORNADO or HAS_NWAY or HAS_CB_FNS or EEPROM_8BIT or INVERT_MII_PWR or MAX_COLLISION_RESET or HAS_HWCKSM           ; 3CCFE575CT Tornado CardBus
2908
dw 0x6560, IS_CYCLONE or HAS_NWAY or HAS_CB_FNS or EEPROM_8BIT or INVERT_MII_PWR or INVERT_LED_PWR or HAS_HWCKSM                ; 3CCFE656 Cyclone CardBus
2909
dw 0x6562, IS_CYCLONE or HAS_NWAY or HAS_CB_FNS or EEPROM_8BIT or INVERT_MII_PWR or INVERT_LED_PWR or HAS_HWCKSM                ; 3CCFEM656B Cyclone+Winmodem CardBus
2910
dw 0x6564, IS_TORNADO or HAS_NWAY or HAS_CB_FNS or EEPROM_8BIT or INVERT_MII_PWR or MAX_COLLISION_RESET or HAS_HWCKSM           ; 3CXFEM656C Tornado+Winmodem CardBus
2911
dw 0x4500, IS_TORNADO or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c450 HomePNA Tornado
2912
dw 0x9201, IS_TORNADO or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c920 Tornado
2913
dw 0x1201, IS_TORNADO or HAS_HWCKSM or HAS_NWAY                                                                                 ; 3c982 Hydra Dual Port A
2914
dw 0x1202, IS_TORNADO or HAS_HWCKSM or HAS_NWAY                                                                                 ; 3c982 Hydra Dual Port B
2915
dw 0x9056, IS_CYCLONE or HAS_NWAY or HAS_HWCKSM or EXTRA_PREAMBLE                                                               ; 3c905B-T4
2916
dw 0x9210, IS_TORNADO or HAS_NWAY or HAS_HWCKSM                                                                                 ; 3c920B-EMB-WNM Tornado
2917
HW_VERSIONS_SIZE = $ - hw_versions
2918
 
2919
include_debug_strings                           ; All data wich FDO uses will be included here
2920
 
5073 hidnplayr 2921
align 4
2922
vortex_devices          dd 0
2923
boomerang_devices       dd 0
2924
vortex_list             rd MAX_DEVICES
2925
boomerang_list          rd MAX_DEVICES
3545 hidnplayr 2926