Subversion Repositories Kolibri OS

Rev

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

Rev 4470 Rev 4581
Line 19... Line 19...
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 20... Line 20...
20
 
20
 
Line 21... Line 21...
21
; TODO: use separate descriptors in memory instead of placing them in front of packets!
21
; TODO: use separate descriptors in memory instead of placing them in front of packets!
-
 
22
 
Line 22... Line 23...
22
 
23
 
23
 
24
format PE DLL native
-
 
25
entry START
Line 24... Line 26...
24
format MS COFF
26
 
Line 25... Line 27...
25
 
27
        CURRENT_API             = 0x0200
26
        API_VERSION             = 0x01000100
28
        COMPATIBLE_API          = 0x0100
27
        DRIVER_VERSION          = 5
29
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
Line -... Line 30...
-
 
30
 
-
 
31
        MAX_DEVICES             = 16
-
 
32
 
28
 
33
        DEBUG                   = 1
29
        MAX_DEVICES             = 16
34
        __DEBUG__               = 1
30
 
-
 
31
        DEBUG                   = 1
-
 
32
        __DEBUG__               = 1
35
        __DEBUG_LEVEL__         = 1             ; 1 = verbose, 2 = errors only
33
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
36
 
34
 
-
 
35
include '../struct.inc'
-
 
36
include '../macros.inc'
-
 
37
include '../proc32.inc'
-
 
38
include '../imports.inc'
-
 
39
include '../fdo.inc'
-
 
40
include '../netdrv.inc'
-
 
41
 
-
 
42
public START
-
 
43
public service_proc
-
 
44
public version
-
 
45
 
-
 
46
virtual at ebx
-
 
47
 
-
 
48
        device:
-
 
49
 
-
 
50
        ETH_DEVICE
-
 
51
 
-
 
52
        .io_addr        dd ?
-
 
53
        .pci_bus        dd ?
-
 
54
        .pci_dev        dd ?
-
 
55
        .irq_line       db ?
-
 
56
 
-
 
57
        .rx_desc        dd ?
-
 
58
 
-
 
59
        .ee_bus_width   db ?
-
 
60
 
-
 
61
                        rb 0x100 - (($ - device) and 0xff)
-
 
62
 
-
 
63
        txfd:
-
 
64
        .status         dw ?
-
 
65
        .command        dw ?
-
 
66
        .link           dd ?
-
 
67
        .tx_desc_addr   dd ?
-
 
68
        .count          dd ?
-
 
69
 
-
 
70
        .tx_buf_addr0   dd ?
-
 
71
        .tx_buf_size0   dd ?
-
 
72
 
-
 
73
                        rb 0x100 - (($ - device) and 0xff)
-
 
74
 
-
 
75
        confcmd:
-
 
76
        .status         dw ?
-
 
77
        .command        dw ?
-
 
78
        .link           dd ?
-
 
79
        .data           rb 64
-
 
80
 
-
 
81
                        rb 0x100 - (($ - device) and 0xff)
-
 
82
 
-
 
83
        lstats:
-
 
84
        tx_good_frames          dd ?
-
 
85
        tx_coll16_errs          dd ?
-
 
86
        tx_late_colls           dd ?
-
 
87
        tx_underruns            dd ?
-
 
88
        tx_lost_carrier         dd ?
-
 
89
        tx_deferred             dd ?
-
 
90
        tx_one_colls            dd ?
-
 
91
        tx_multi_colls          dd ?
-
 
92
        tx_total_colls          dd ?
-
 
93
 
-
 
94
        rx_good_frames          dd ?
-
 
95
        rx_crc_errs             dd ?
-
 
96
        rx_align_errs           dd ?
-
 
97
        rx_resource_errs        dd ?
-
 
98
        rx_overrun_errs         dd ?
-
 
99
        rx_colls_errs           dd ?
-
 
100
        rx_runt_errs            dd ?
-
 
101
 
-
 
102
        last_tx_buffer          dd ?    ;;; fixme
-
 
103
 
-
 
104
        sizeof.device_struct = $ - device
-
 
105
 
-
 
106
end virtual
-
 
107
 
-
 
108
 
-
 
109
virtual at 0
-
 
110
 
-
 
111
        rxfd:
-
 
112
        .status         dw ?
-
 
113
        .command        dw ?
-
 
114
        .link           dd ?
-
 
Line 115... Line 37...
115
        .rx_buf_addr    dd ?
37
section '.flat' readable writable executable
Line 116... Line 38...
116
        .count          dw ?
38
 
117
        .size           dw ?
39
include '../proc32.inc'
Line 154... Line 76...
154
CmdConfigure    = 0x0002
76
CmdConfigure    = 0x0002
155
CmdTx           = 0x0004
77
CmdTx           = 0x0004
156
CmdTxFlex       = 0x0008
78
CmdTxFlex       = 0x0008
157
Cmdsuspend      = 0x4000
79
Cmdsuspend      = 0x4000
Line 158... Line -...
158
 
-
 
159
 
80
 
160
reg_scb_status  = 0
81
reg_scb_status  = 0
161
reg_scb_cmd     = 2
82
reg_scb_cmd     = 2
162
reg_scb_ptr     = 4
83
reg_scb_ptr     = 4
163
reg_port        = 8
84
reg_port        = 8
164
reg_eeprom      = 14
85
reg_eeprom      = 14
Line -... Line 86...
-
 
86
reg_mdi_ctrl    = 16
-
 
87
 
-
 
88
phy_100a        = 0x000003E0
-
 
89
phy_100c        = 0x035002A8
-
 
90
phy_82555_tx    = 0x015002A8
-
 
91
phy_nsc_tx      = 0x5C002000
-
 
92
phy_82562_et    = 0x033002A8
-
 
93
phy_82562_em    = 0x032002A8
-
 
94
phy_82562_ek    = 0x031002A8
-
 
95
phy_82562_eh    = 0x017002A8
-
 
96
phy_82552_v     = 0xd061004d
-
 
97
phy_unknown     = 0xFFFFFFFF
-
 
98
 
-
 
99
mac_82557_D100_A        = 0
-
 
100
mac_82557_D100_B        = 1     
-
 
101
mac_82557_D100_C        = 2     
-
 
102
mac_82558_D101_A4       = 4     
-
 
103
mac_82558_D101_B0       = 5     
-
 
104
mac_82559_D101M         = 8     
-
 
105
mac_82559_D101S         = 9     
-
 
106
mac_82550_D102          = 12    
-
 
107
mac_82550_D102_C        = 13    
-
 
108
mac_82551_E             = 14    
-
 
109
mac_82551_F             = 15    
-
 
110
mac_82551_10            = 16    
-
 
111
mac_unknown             = 0xFF
-
 
112
 
-
 
113
struct  rxfd
-
 
114
 
-
 
115
        status          dw ?
-
 
116
        command         dw ?
-
 
117
        link            dd ?
-
 
118
        rx_buf_addr     dd ?
-
 
119
        count           dw ?
-
 
120
        size            dw ?
-
 
121
        packet          rb 1500
-
 
122
 
-
 
123
ends
-
 
124
 
-
 
125
struc   txfd {
-
 
126
 
-
 
127
        .status         dw ?
-
 
128
        .command        dw ?
-
 
129
        .link           dd ?
-
 
130
        .desc_addr      dd ?
-
 
131
        .count          dd ?
-
 
132
 
-
 
133
        .buf_addr0      dd ?
-
 
134
        .buf_size0      dd ?
-
 
135
 
-
 
136
}
-
 
137
 
-
 
138
struc   confcmd {
-
 
139
 
-
 
140
        .status         dw ?
-
 
141
        .command        dw ?
-
 
142
        .link           dd ?
-
 
143
        .data           rb 64
-
 
144
 
-
 
145
}
-
 
146
 
-
 
147
struc   lstats {
-
 
148
 
-
 
149
        .tx_good_frames         dd ?
-
 
150
        .tx_coll16_errs         dd ?
-
 
151
        .tx_late_colls          dd ?
-
 
152
        .tx_underruns           dd ?
-
 
153
        .tx_lost_carrier        dd ?
-
 
154
        .tx_deferred            dd ?
-
 
155
        .tx_one_colls           dd ?
-
 
156
        .tx_multi_colls         dd ?
-
 
157
        .tx_total_colls         dd ?
-
 
158
 
-
 
159
        .rx_good_frames         dd ?
-
 
160
        .rx_crc_errs            dd ?
-
 
161
        .rx_align_errs          dd ?
-
 
162
        .rx_resource_errs       dd ?
-
 
163
        .rx_overrun_errs        dd ?
-
 
164
        .rx_colls_errs          dd ?
-
 
165
        .rx_runt_errs           dd ?
-
 
166
 
-
 
167
}
-
 
168
 
-
 
169
struct  device          ETH_DEVICE
-
 
170
 
-
 
171
        io_addr         dd ?
-
 
172
        pci_bus         dd ?
-
 
173
        pci_dev         dd ?
-
 
174
        rx_desc         dd ?
-
 
175
        last_tx_buffer  dd ?
-
 
176
        ee_bus_width    db ?
-
 
177
        irq_line        db ?
-
 
178
 
-
 
179
        rb 0x100 - ($ and 0xff) ; align 256
-
 
180
        txfd            txfd
-
 
181
 
-
 
182
        rb 0x100 - ($ and 0xff) ; align 256
-
 
183
        confcmd         confcmd
-
 
184
 
-
 
185
        rb 0x100 - ($ and 0xff) ; align 256
-
 
186
        lstats          lstats
Line 165... Line 187...
165
reg_mdi_ctrl    = 16
187
 
166
 
188
ends
167
 
189
 
168
macro delay {
190
macro delay {
Line 178... Line 200...
178
        in      ax, dx
200
        in      ax, dx
179
        in      ax, dx
201
        in      ax, dx
180
        pop     eax
202
        pop     eax
181
}
203
}
Line 182... Line -...
182
 
-
 
183
section '.flat' code readable align 16
-
 
184
 
204
 
185
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
205
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
186
;;                        ;;
206
;;                        ;;
187
;; proc START             ;;
207
;; proc START             ;;
188
;;                        ;;
208
;;                        ;;
189
;; (standard driver proc) ;;
209
;; (standard driver proc) ;;
Line 190... Line 210...
190
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
210
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 191... Line 211...
191
 
211
 
192
proc START stdcall, state:dword
212
proc START c, state:dword
Line 193... Line 213...
193
 
213
 
Line 194... Line 214...
194
        cmp [state], 1
214
        cmp [state], 1
195
        jne .exit
215
        jne .exit
196
 
216
 
Line 197... Line 217...
197
  .entry:
217
  .entry:
198
 
218
 
199
        DEBUGF 1,"Loading driver\n"
219
        DEBUGF 1,"Loading driver\n"
Line 255... Line 275...
255
 
275
 
256
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
276
;        mov     eax, [edx + IOCTL.input]                ; get the pci bus and device numbers
257
        mov     ax , [eax+1]                            ;
277
        mov     ax , [eax+1]                            ;
258
  .nextdevice:
278
  .nextdevice:
259
        mov     ebx, [esi]
279
        mov     ebx, [esi]
260
        cmp     al, byte[device.pci_bus]
280
        cmp     al, byte[ebx + device.pci_bus]
261
        jne     @f
281
        jne     @f
262
        cmp     ah, byte[device.pci_dev]
282
        cmp     ah, byte[ebx + device.pci_dev]
263
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
283
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
264
       @@:
284
       @@:
265
        add     esi, 4
285
        add     esi, 4
Line 269... Line 289...
269
; This device doesnt have its own eth_device structure yet, lets create one
289
; This device doesnt have its own eth_device structure yet, lets create one
270
  .firstdevice:
290
  .firstdevice:
271
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
291
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
272
        jae     .fail
292
        jae     .fail
Line 273... Line 293...
273
 
293
 
Line 274... Line 294...
274
        allocate_and_clear ebx, sizeof.device_struct, .fail      ; Allocate the buffer for device structure
294
        allocate_and_clear ebx, sizeof.device, .fail      ; Allocate the buffer for device structure
Line 275... Line 295...
275
 
295
 
276
; Fill in the direct call addresses into the struct
296
; Fill in the direct call addresses into the struct
277
 
297
 
278
        mov     [device.reset], reset
298
        mov     [ebx + device.reset], reset
Line 279... Line 299...
279
        mov     [device.transmit], transmit
299
        mov     [ebx + device.transmit], transmit
Line 280... Line 300...
280
        mov     [device.unload], unload
300
        mov     [ebx + device.unload], unload
281
        mov     [device.name], my_service
301
        mov     [ebx + device.name], my_service
282
 
302
 
283
; save the pci bus and device numbers
303
; save the pci bus and device numbers
284
 
304
 
Line 285... Line 305...
285
        mov     eax, [edx + IOCTL.input]
305
        mov     eax, [edx + IOCTL.input]
Line -... Line 306...
-
 
306
        movzx   ecx, byte[eax+1]
286
        movzx   ecx, byte[eax+1]
307
        mov     [ebx + device.pci_bus], ecx
Line 287... Line 308...
287
        mov     [device.pci_bus], ecx
308
        movzx   ecx, byte[eax+2]
Line -... Line 309...
-
 
309
        mov     [ebx + device.pci_dev], ecx
288
        movzx   ecx, byte[eax+2]
310
 
Line 289... Line 311...
289
        mov     [device.pci_dev], ecx
311
; Now, it's time to find the base io addres of the PCI device
290
 
312
 
Line 291... Line 313...
291
; Now, it's time to find the base io addres of the PCI device
313
        stdcall PCI_find_io, [ebx + device.pci_bus], [ebx + device.pci_dev]
Line 292... Line 314...
292
 
314
        mov     [ebx + device.io_addr], eax
293
        PCI_find_io
315
 
Line 294... Line 316...
294
 
316
; We've found the io address, find IRQ now
295
; We've found the io address, find IRQ now
317
 
296
 
318
        invoke  PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line
Line 312... Line 334...
312
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
334
        mov     [device_list+4*eax], ebx                                ; (IRQ handler uses this list to find device)
313
        inc     [devices]                                               ;
335
        inc     [devices]                                               ;
Line 314... Line 336...
314
 
336
 
Line 315... Line 337...
315
        popf
337
        popf
316
 
338
 
Line 317... Line 339...
317
        mov     [device.type], NET_TYPE_ETH
339
        mov     [ebx + device.type], NET_TYPE_ETH
318
        call    NetRegDev
340
        invoke  NetRegDev
Line 319... Line 341...
319
 
341
 
Line 320... Line 342...
320
        cmp     eax, -1
342
        cmp     eax, -1
Line 321... Line 343...
321
        je      .err
343
        je      .err
322
 
344
 
323
        ret
345
        ret
324
 
346
 
325
; If the device was already loaded, find the device number and return it in eax
347
; If the device was already loaded, find the device number and return it in eax
326
 
348
 
327
  .find_devicenum:
349
  .find_devicenum:
Line 328... Line 350...
328
        DEBUGF  2,"Trying to find device number of already registered device\n"
350
        DEBUGF  2,"Trying to find device number of already registered device\n"
Line 329... Line 351...
329
        call    NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
351
        invoke  NetPtrToNum                                             ; This kernel procedure converts a pointer to device struct in ebx
330
                                                                        ; into a device number in edi
352
                                                                        ; into a device number in edi
Line 331... Line 353...
331
        mov     eax, edi                                                ; Application wants it in eax instead
353
        mov     eax, edi                                                ; Application wants it in eax instead
332
        DEBUGF  2,"Kernel says: %u\n", eax
354
        DEBUGF  2,"Kernel says: %u\n", eax
333
        ret
355
        ret
Line 378... Line 400...
378
align 4
400
align 4
379
probe:
401
probe:
Line 380... Line 402...
380
 
402
 
Line 381... Line 403...
381
        DEBUGF  1,"Probing\n"
403
        DEBUGF  1,"Probing\n"
-
 
404
 
-
 
405
; Make the device a bus master
-
 
406
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line 382... Line 407...
382
 
407
        or      al, PCI_CMD_MASTER
383
        PCI_make_bus_master
408
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
Line 384... Line 409...
384
 
409
 
Line 385... Line 410...
385
;---------------------------
410
;---------------------------
Line 386... Line 411...
386
; First, identify the device
411
; First, identify the device
387
 
412
 
Line 422... Line 447...
422
;----------
447
;----------
Line 423... Line 448...
423
 
448
 
424
align 4
449
align 4
Line 425... Line 450...
425
reset:
450
reset:
426
 
451
 
427
        movzx   eax, [device.irq_line]
452
        movzx   eax, [ebx + device.irq_line]
428
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
453
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
429
        stdcall AttachIntHandler, eax, int_handler, dword 0
454
        invoke  AttachIntHandler, eax, int_handler, ebx
430
        test    eax, eax
455
        test    eax, eax
431
        jnz     @f
456
        jnz     @f
432
        DEBUGF  2,"Could not attach int handler!\n"
457
        DEBUGF  2,"Could not attach int handler!\n"
433
;        or      eax, -1
458
        or      eax, -1
Line 434... Line 459...
434
;        ret
459
        ret
Line 435... Line 460...
435
  @@:
460
  @@:
436
 
461
 
Line 437... Line 462...
437
        DEBUGF  1,"Resetting\n"
462
        DEBUGF  1,"Resetting\n"
438
 
463
 
439
;---------------
464
;---------------
440
; reset the card
465
; reset the card
Line 441... Line 466...
441
 
466
 
442
        set_io  0
467
        set_io  [ebx + device.io_addr], 0
Line 443... Line 468...
443
        set_io  reg_port
468
        set_io  [ebx + device.io_addr], reg_port
444
        xor     eax, eax        ; Software Reset
469
        xor     eax, eax        ; Software Reset
Line 445... Line 470...
445
        out     dx, eax
470
        out     dx, eax
446
 
471
 
447
        mov     esi, 10
472
        mov     esi, 10
448
        call    Sleep           ; Give the card time to warm up.
473
        invoke  Sleep           ; Give the card time to warm up.
449
 
474
 
Line 450... Line 475...
450
;---------------------------------
475
;---------------------------------
451
; Tell device where to store stats
476
; Tell device where to store stats
452
 
477
 
453
        lea     eax, [lstats]
478
        lea     eax, [ebx + device.lstats.tx_good_frames]      ; lstats
Line 454... Line 479...
454
        GetRealAddr
479
        invoke  GetPhysAddr
455
        set_io  0
480
        set_io  [ebx + device.io_addr], 0
Line 456... Line 481...
456
        set_io  reg_scb_ptr
481
        set_io  [ebx + device.io_addr], reg_scb_ptr
457
        out     dx, eax
482
        out     dx, eax
458
 
483
 
Line 459... Line 484...
459
        mov     ax, INT_MASK + CU_STATSADDR
484
        mov     ax, INT_MASK + CU_STATSADDR
460
        set_io  reg_scb_cmd
485
        set_io  [ebx + device.io_addr], reg_scb_cmd
461
        out     dx, ax
486
        out     dx, ax
462
        call    cmd_wait
487
        call    cmd_wait
Line 463... Line 488...
463
 
488
 
Line 478... Line 503...
478
 
503
 
Line 479... Line 504...
479
        call    create_ring
504
        call    create_ring
Line 480... Line 505...
480
 
505
 
481
; RX start
506
; RX start
482
 
507
 
483
        set_io  0
508
        set_io  [ebx + device.io_addr], 0
484
        set_io  reg_scb_ptr
509
        set_io  [ebx + device.io_addr], reg_scb_ptr
Line 485... Line 510...
485
        mov     eax, [device.rx_desc]
510
        mov     eax, [ebx + device.rx_desc]
486
        GetRealAddr
511
        invoke  GetPhysAddr
487
        out     dx, eax
512
        out     dx, eax
488
 
513
 
Line 489... Line 514...
489
        mov     ax, INT_MASK + RX_START
514
        mov     ax, INT_MASK + RX_START
Line 490... Line 515...
490
        set_io  reg_scb_cmd
515
        set_io  [ebx + device.io_addr], reg_scb_cmd
491
        out     dx, ax
516
        out     dx, ax
492
        call    cmd_wait
517
        call    cmd_wait
Line 493... Line 518...
493
 
518
 
494
; Set-up TX
519
; Set-up TX
495
 
520
 
496
        set_io  reg_scb_ptr
521
        set_io  [ebx + device.io_addr], reg_scb_ptr
Line 497... Line 522...
497
        xor     eax, eax
522
        xor     eax, eax
Line 498... Line 523...
498
        out     dx, eax
523
        out     dx, eax
499
 
524
 
500
        set_io  reg_scb_cmd
525
        set_io  [ebx + device.io_addr], reg_scb_cmd
501
        mov     ax, INT_MASK + CU_CMD_BASE
526
        mov     ax, INT_MASK + CU_CMD_BASE
502
        out     dx, ax
527
        out     dx, ax
Line 503... Line 528...
503
        call    cmd_wait
528
        call    cmd_wait
504
 
529
 
505
;  --------------------
530
;  --------------------
506
 
531
 
Line 507... Line 532...
507
        mov     [confcmd.command], CmdConfigure + Cmdsuspend
532
        mov     [ebx + device.confcmd.command], CmdConfigure + Cmdsuspend
508
        mov     [confcmd.status], 0
533
        mov     [ebx + device.confcmd.status], 0
509
        lea     eax, [txfd]
534
        lea     eax, [ebx + device.txfd.status]
510
        GetRealAddr
535
        invoke  GetPhysAddr
511
        mov     [confcmd.link], eax
536
        mov     [ebx + device.confcmd.link], eax
512
 
537
 
513
        mov     esi, confcmd_data
538
        mov     esi, confcmd_data
514
        lea     edi, [confcmd.data]
539
        lea     edi, [ebx + device.confcmd.data]
515
        mov     ecx, 22
540
        mov     ecx, 22
516
        rep     movsb
541
        rep     movsb
517
 
542
 
518
        mov     byte[confcmd.data + 1], 0x88  ; fifo of 8 each
543
        mov     byte[ebx + device.confcmd.data + 1], 0x88  ; fifo of 8 each
Line 519... Line 544...
519
        mov     byte[confcmd.data + 4], 0
544
        mov     byte[ebx + device.confcmd.data + 4], 0
Line 520... Line 545...
520
        mov     byte[confcmd.data + 5], 0x80
545
        mov     byte[ebx + device.confcmd.data + 5], 0x80
521
        mov     byte[confcmd.data + 15], 0x48
546
        mov     byte[ebx + device.confcmd.data + 15], 0x48
522
        mov     byte[confcmd.data + 19], 0x80
547
        mov     byte[ebx + device.confcmd.data + 19], 0x80
523
        mov     byte[confcmd.data + 21], 0x05
548
        mov     byte[ebx + device.confcmd.data + 21], 0x05
Line 524... Line 549...
524
 
549
 
525
        mov     [txfd.command], CmdIASetup
550
        mov     [ebx + device.txfd.command], CmdIASetup
526
        mov     [txfd.status], 0
551
        mov     [ebx + device.txfd.status], 0
527
        lea     eax, [confcmd]
552
        lea     eax, [ebx + device.confcmd.status]
Line 528... Line 553...
528
        GetRealAddr
553
        invoke  GetPhysAddr
Line 529... Line 554...
529
        mov     [txfd.link], eax
554
        mov     [ebx + device.txfd.link], eax
530
 
555
 
531
;;; copy in our MAC
556
;;; copy in our MAC
532
 
557
 
Line 533... Line 558...
533
        lea     edi, [txfd.tx_desc_addr]
558
        lea     edi, [ebx + device.txfd.desc_addr]
534
        lea     esi, [device.mac]
559
        lea     esi, [ebx + device.mac]
Line 535... Line 560...
535
        movsd
560
        movsd
536
        movsw
561
        movsw
537
 
562
 
538
        set_io  reg_scb_ptr
563
        set_io  [ebx + device.io_addr], reg_scb_ptr
539
        lea     eax, [txfd]
564
        lea     eax, [ebx + device.txfd.status]
540
        GetRealAddr
565
        invoke  GetPhysAddr
541
        out     dx, eax
566
        out     dx, eax
Line 542... Line 567...
542
 
567
 
Line 543... Line 568...
543
; Start CU & enable ints
568
; Start CU & enable ints
Line 544... Line 569...
544
 
569
 
Line 545... Line 570...
545
        set_io  reg_scb_cmd
570
        set_io  [ebx + device.io_addr], reg_scb_cmd
546
        mov     ax, CU_START
571
        mov     ax, CU_START
Line 547... Line 572...
547
        out     dx, ax
572
        out     dx, ax
548
        call    cmd_wait
573
        call    cmd_wait
Line 577... Line 602...
577
        DEBUGF  1,"Creating ring\n"
602
        DEBUGF  1,"Creating ring\n"
Line 578... Line 603...
578
 
603
 
579
;---------------------
604
;---------------------
Line 580... Line 605...
580
; build rxfd structure
605
; build rxfd structure
581
 
606
 
582
        stdcall KernelAlloc, 2000
607
        invoke  KernelAlloc, 2000
583
        mov     [device.rx_desc], eax
608
        mov     [ebx + device.rx_desc], eax
584
        mov     esi, eax
609
        mov     esi, eax
585
        GetRealAddr
610
        invoke  GetPhysAddr
586
        mov     [esi + rxfd.status], 0x0000
611
        mov     [esi + rxfd.status], 0x0000
587
        mov     [esi + rxfd.command], 0x0000
612
        mov     [esi + rxfd.command], 0x0000
588
        mov     [esi + rxfd.link], eax
613
        mov     [esi + rxfd.link], eax
Line 589... Line 614...
589
        mov     [esi + rxfd.count], 0
614
        mov     [esi + rxfd.count], 0
590
        mov     [esi + rxfd.size], 1528
615
        mov     [esi + rxfd.size], 1528
Line 591... Line 616...
591
 
616
 
592
;-----------------------
617
;-----------------------
593
; build txfd structure
618
; build txfd structure
594
 
619
 
595
        lea     eax, [txfd]
620
        lea     eax, [ebx + device.txfd.status]
596
        GetRealAddr
621
        invoke  GetPhysAddr
597
        mov     [txfd.link], eax
622
        mov     [ebx + device.txfd.link], eax
Line 598... Line 623...
598
        mov     [txfd.count], 0x02208000
623
        mov     [ebx + device.txfd.count], 0x02208000
Line 599... Line -...
599
        lea     eax, [txfd.tx_buf_addr0]
-
 
600
        GetRealAddr
-
 
601
        mov     [txfd.tx_desc_addr], eax
624
        lea     eax, [ebx + device.txfd.buf_addr0]
602
 
625
        invoke  GetPhysAddr
603
        ret
626
        mov     [ebx + device.txfd.desc_addr], eax
604
 
627
 
605
 
-
 
606
 
-
 
607
 
628
        ret
608
 
629
 
609
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
630
 
Line 610... Line -...
610
;;                                         ;;
-
 
611
;; Transmit                                ;;
631
 
Line -... Line 632...
-
 
632
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
633
;;                                         ;;
-
 
634
;; Transmit                                ;;
612
;;                                         ;;
635
;;                                         ;;
613
;; In: buffer pointer in [esp+4]           ;;
636
;; In: pointer to device structure in ebx  ;;
614
;;     size of buffer in [esp+8]           ;;
637
;;                                         ;;
615
;;     pointer to device structure in ebx  ;;
638
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616
;;                                         ;;
639
 
617
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
640
proc transmit stdcall bufferptr, buffersize
Line 618... Line 641...
618
 
641
 
619
align 4
642
        pushf
620
transmit:
643
        cli
621
 
644
 
Line 622... Line 645...
622
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
645
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize]
623
        mov     eax, [esp+4]
646
        mov     eax, [bufferptr]
624
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
-
 
625
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
647
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
626
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
648
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
627
        [eax+13]:2,[eax+12]:2
649
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
628
 
650
        [eax+13]:2,[eax+12]:2
629
        cmp     dword [esp+8], 1514
651
 
630
        ja      .error                          ; packet is too long
-
 
631
        cmp     dword [esp+8], 60
-
 
632
        jb      .error                          ; packet is too short
-
 
Line -... Line 652...
-
 
652
        cmp     [buffersize], 1514
-
 
653
        ja      .fail
633
 
654
        cmp     [buffersize], 60
Line 634... Line 655...
634
        ;;; TODO: check if current descriptor is in use
655
        jb      .fail
635
        ; fill in buffer address and size
656
 
636
        mov     eax, [esp+4]
657
        ;;; TODO: check if current descriptor is in use
637
        mov     [last_tx_buffer], eax   ;;; FIXME
658
        ; fill in buffer address and size
638
        GetRealAddr
659
        mov     [ebx + device.last_tx_buffer], eax
639
        mov     [txfd.tx_buf_addr0], eax
660
        invoke  GetPhysAddr
Line 640... Line 661...
640
        mov     eax, [esp+8]
661
        mov     [ebx + device.txfd.buf_addr0], eax
641
        mov     [txfd.tx_buf_size0], eax
662
        mov     ecx, [buffersize]
642
 
663
        mov     [ebx + device.txfd.buf_size0], ecx
643
        mov     [txfd.status], 0
664
 
644
        mov     [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + 1 shl 15 ;;; EL bit
665
        mov     [ebx + device.txfd.status], 0
Line 645... Line -...
645
 
-
 
646
 ;       mov     [txfd.count], 0x02208000   ;;;;;;;;;;;
-
 
647
 
-
 
648
        ; Inform device of the new/updated transmit descriptor
-
 
649
        lea     eax, [txfd]
-
 
650
        GetRealAddr
-
 
651
        set_io  0
-
 
652
        set_io  reg_scb_ptr
-
 
653
        out     dx, eax
-
 
654
 
-
 
655
        ; Start the transmit
666
        mov     [ebx + device.txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + 1 shl 15 ;;; EL bit
656
        mov     ax, CU_START
667
 ;       mov     [txfd.count], 0x02208000   ;;;;;;;;;;;
657
        set_io  reg_scb_cmd
668
 
658
        out     dx, ax
669
        ; Inform device of the new/updated transmit descriptor
659
        call    cmd_wait
670
        lea     eax, [ebx + device.txfd.status]
Line 660... Line 671...
660
 
671
        invoke  GetPhysAddr
661
;        set_io  0               ;; why?
672
        set_io  [ebx + device.io_addr], 0
662
;        in      ax, dx          ;;
673
        set_io  [ebx + device.io_addr], reg_scb_ptr
663
;
674
        out     dx, eax
Line 664... Line 675...
664
;  @@:
675
 
665
;        cmp     [txfd.status], 0  ; wait for completion? dont seems a good idea to me..
676
        ; Start the transmit
-
 
677
        mov     ax, CU_START
666
;        je      @r
678
        set_io  [ebx + device.io_addr], reg_scb_cmd
667
;
679
        out     dx, ax
-
 
680
        call    cmd_wait
-
 
681
 
-
 
682
; Update stats
Line 668... Line 683...
668
;        set_io  0               ;; why?
683
        inc     [ebx + device.packets_tx]
669
;        in      ax, dx          ;;
684
        mov     ecx, [buffersize]
670
 
685
        add     dword[ebx + device.bytes_tx], ecx
671
; Update stats
686
        adc     dword[ebx + device.bytes_tx + 4], 0
Line 704... Line 719...
704
        jz      .nothing
719
        jz      .nothing
705
        mov     esi, device_list
720
        mov     esi, device_list
706
  .nextdevice:
721
  .nextdevice:
707
        mov     ebx, [esi]
722
        mov     ebx, [esi]
Line 708... Line 723...
708
 
723
 
709
;        set_io  0              ; reg_scb_status = 0
724
;        set_io  [ebx + device.io_addr], 0              ; reg_scb_status = 0
710
        set_io  reg_scb_status
725
        set_io  [ebx + device.io_addr], reg_scb_status
711
        in      ax, dx
726
        in      ax, dx
712
        out     dx, ax                              ; send it back to ACK
727
        out     dx, ax                              ; send it back to ACK
713
        test    ax, ax
728
        test    ax, ax
714
        jnz     .got_it
729
        jnz     .got_it
Line 735... Line 750...
735
 
750
 
736
        push    ebx
751
        push    ebx
737
  .rx_loop:
752
  .rx_loop:
Line 738... Line 753...
738
        pop     ebx
753
        pop     ebx
739
 
754
 
740
        mov     esi, [device.rx_desc]
755
        mov     esi, [ebx + device.rx_desc]
Line 741... Line 756...
741
        cmp     [esi + rxfd.status], 0        ; we could also check bits C and OK (bit 15 and 13)
756
        cmp     [esi + rxfd.status], 0        ; we could also check bits C and OK (bit 15 and 13)
Line 751... Line 766...
751
        push    ecx
766
        push    ecx
752
        add     esi, rxfd.packet
767
        add     esi, rxfd.packet
753
        push    esi
768
        push    esi
Line 754... Line 769...
754
 
769
 
755
; Update stats
770
; Update stats
756
        add     dword [device.bytes_rx], ecx
771
        add     dword [ebx + device.bytes_rx], ecx
757
        adc     dword [device.bytes_rx + 4], 0
772
        adc     dword [ebx + device.bytes_rx + 4], 0
Line 758... Line 773...
758
        inc     dword [device.packets_rx]
773
        inc     dword [ebx + device.packets_rx]
Line 759... Line 774...
759
 
774
 
760
; allocate new descriptor
775
; allocate new descriptor
761
 
776
 
762
        stdcall KernelAlloc, 2000
777
        invoke  KernelAlloc, 2000
763
        mov     [device.rx_desc], eax
778
        mov     [ebx + device.rx_desc], eax
764
        mov     esi, eax
779
        mov     esi, eax
765
        GetRealAddr
780
        invoke  GetPhysAddr
766
        mov     [esi + rxfd.status], 0x0000
781
        mov     [esi + rxfd.status], 0x0000
767
        mov     [esi + rxfd.command], 0xc000    ; End of list + Suspend
782
        mov     [esi + rxfd.command], 0xc000    ; End of list + Suspend
Line 768... Line 783...
768
        mov     [esi + rxfd.link], eax
783
        mov     [esi + rxfd.link], eax
Line 769... Line 784...
769
        mov     [esi + rxfd.count], 0
784
        mov     [esi + rxfd.count], 0
770
        mov     [esi + rxfd.size], 1528
785
        mov     [esi + rxfd.size], 1528
771
 
786
 
772
; restart RX
787
; restart RX
773
 
788
 
Line 774... Line 789...
774
        set_io  0
789
        set_io  [ebx + device.io_addr], 0
775
        set_io  reg_scb_ptr
790
        set_io  [ebx + device.io_addr], reg_scb_ptr
776
;        lea     eax, [device.rx_desc]
791
;        lea     eax, [ebx + device.rx_desc]
777
;        GetRealAddr
792
;        invoke  GetPhysAddr
Line 778... Line 793...
778
        out     dx, eax
793
        out     dx, eax
779
 
-
 
780
        set_io  reg_scb_cmd
794
 
Line 781... Line 795...
781
        mov     ax, RX_START
795
        set_io  [ebx + device.io_addr], reg_scb_cmd
782
        out     dx, ax
796
        mov     ax, RX_START
783
        call    cmd_wait
797
        out     dx, ax
Line 784... Line 798...
784
 
798
        call    cmd_wait
Line 785... Line 799...
785
; And give packet to kernel
799
 
786
 
800
; And give packet to kernel
787
        jmp     Eth_input
801
        jmp     [Eth_input]
788
 
802
 
789
  .nodata:
803
  .nodata:
790
        DEBUGF  1, "no more data\n"
804
        DEBUGF  1, "no more data\n"
791
        pop     ax
805
        pop     ax
792
 
806
 
793
  .no_rx:
807
  .no_rx:
794
 
808
 
Line 795... Line 809...
795
; Cleanup after TX
809
; Cleanup after TX
796
        cmp     [txfd.status], 0
810
        cmp     [ebx + device.txfd.status], 0
797
        je      .done
811
        je      .done
Line 811... Line 825...
811
        DEBUGF  1, "out of resources!\n"
825
        DEBUGF  1, "out of resources!\n"
812
; Restart the RX
826
; Restart the RX
Line 813... Line 827...
813
 
827
 
Line 814... Line 828...
814
; allocate new descriptor
828
; allocate new descriptor
815
 
829
 
816
        stdcall KernelAlloc, 2000
830
        invoke  KernelAlloc, 2000
817
        mov     [device.rx_desc], eax
831
        mov     [ebx + device.rx_desc], eax
818
        mov     esi, eax
832
        mov     esi, eax
819
        GetRealAddr
833
        invoke  GetPhysAddr
820
        mov     [esi + rxfd.status], 0x0000
834
        mov     [esi + rxfd.status], 0x0000
821
        mov     [esi + rxfd.command], 0xc000    ; End of list + Suspend
835
        mov     [esi + rxfd.command], 0xc000    ; End of list + Suspend
822
        mov     [esi + rxfd.link], eax
836
        mov     [esi + rxfd.link], eax
Line 823... Line 837...
823
        mov     [esi + rxfd.count], 0
837
        mov     [esi + rxfd.count], 0
Line 824... Line 838...
824
        mov     [esi + rxfd.size], 1528
838
        mov     [esi + rxfd.size], 1528
825
 
839
 
826
; restart RX
840
; restart RX
827
 
841
 
828
        set_io  0
842
        set_io  [ebx + device.io_addr], 0
Line 829... Line 843...
829
        set_io  reg_scb_ptr
843
        set_io  [ebx + device.io_addr], reg_scb_ptr
830
;        lea     eax, [device.rx_desc]
844
;        lea     eax, [ebx + device.rx_desc]
831
;        GetRealAddr
845
;        invoke  GetPhysAddr
832
        out     dx, eax
846
        out     dx, eax
Line 833... Line 847...
833
 
847
 
Line 863... Line 877...
863
align 4
877
align 4
864
ee_read:        ; esi = address to read
878
ee_read:        ; esi = address to read
Line 865... Line 879...
865
 
879
 
Line 866... Line 880...
866
        DEBUGF  1,"Eeprom read from 0x%x\n", esi
880
        DEBUGF  1,"Eeprom read from 0x%x\n", esi
867
 
881
 
Line 868... Line 882...
868
        set_io  0
882
        set_io  [ebx + device.io_addr], 0
869
        set_io  reg_eeprom
883
        set_io  [ebx + device.io_addr], reg_eeprom
870
 
884
 
Line 871... Line 885...
871
;-----------------------------------------------------
885
;-----------------------------------------------------
872
; Prepend start bit + read opcode to the address field
886
; Prepend start bit + read opcode to the address field
873
; and shift it to the very left bits of esi
887
; and shift it to the very left bits of esi
874
 
888
 
Line 875... Line 889...
875
        mov     cl, 29
889
        mov     cl, 29
876
        sub     cl, [device.ee_bus_width]
890
        sub     cl, [ebx + device.ee_bus_width]
Line 877... Line 891...
877
        shl     esi, cl
891
        shl     esi, cl
878
        or      esi, EE_READ shl 29
892
        or      esi, EE_READ shl 29
879
 
893
 
Line 941... Line 955...
941
align 4
955
align 4
942
ee_write:       ; esi = address to write to, di = data
956
ee_write:       ; esi = address to write to, di = data
Line 943... Line 957...
943
 
957
 
Line 944... Line 958...
944
        DEBUGF  1,"Eeprom write 0x%x to 0x%x\n", di, esi
958
        DEBUGF  1,"Eeprom write 0x%x to 0x%x\n", di, esi
945
 
959
 
Line 946... Line 960...
946
        set_io  0
960
        set_io  [ebx + device.io_addr], 0
947
        set_io  reg_eeprom
961
        set_io  [ebx + device.io_addr], reg_eeprom
948
 
962
 
Line 949... Line 963...
949
;-----------------------------------------------------
963
;-----------------------------------------------------
950
; Prepend start bit + write opcode to the address field
964
; Prepend start bit + write opcode to the address field
951
; and shift it to the very left bits of esi
965
; and shift it to the very left bits of esi
952
 
966
 
Line 953... Line 967...
953
        mov     cl, 29
967
        mov     cl, 29
954
        sub     cl, [device.ee_bus_width]
968
        sub     cl, [ebx + device.ee_bus_width]
Line 955... Line 969...
955
        shl     esi, cl
969
        shl     esi, cl
956
        or      esi, EE_WRITE shl 29
970
        or      esi, EE_WRITE shl 29
Line 1011... Line 1025...
1011
 
1025
 
1012
 
1026
 
Line 1013... Line 1027...
1013
align 4
1027
align 4
1014
ee_get_width:
1028
ee_get_width:
Line 1015... Line 1029...
1015
 
1029
 
1016
        set_io  0
1030
        set_io  [ebx + device.io_addr], 0
1017
        set_io  reg_eeprom
1031
        set_io  [ebx + device.io_addr], reg_eeprom
Line 1046... Line 1060...
1046
 
1060
 
1047
        xor     al, al
1061
        xor     al, al
Line 1048... Line 1062...
1048
        out     dx, al          ; de-activate eeprom
1062
        out     dx, al          ; de-activate eeprom
1049
 
1063
 
1050
        sub     cl, 3           ; dont count the opcode bits
1064
        sub     cl, 3           ; dont count the opcode bits
Line 1051... Line 1065...
1051
        mov     [device.ee_bus_width], cl
1065
        mov     [ebx + device.ee_bus_width], cl
Line 1052... Line 1066...
1052
        DEBUGF  1, "Eeprom width=%u bit\n", ecx
1066
        DEBUGF  1, "Eeprom width=%u bit\n", ecx
Line 1078... Line 1092...
1078
 
1092
 
1079
        mov     eax, ecx
1093
        mov     eax, ecx
1080
        or      eax, edx
1094
        or      eax, edx
Line 1081... Line 1095...
1081
        or      eax, 10b shl 26         ; read opcode
1095
        or      eax, 10b shl 26         ; read opcode
1082
 
1096
 
1083
        set_io  0
1097
        set_io  [ebx + device.io_addr], 0
Line 1084... Line 1098...
1084
        set_io  reg_mdi_ctrl
1098
        set_io  [ebx + device.io_addr], reg_mdi_ctrl
1085
        out     dx, eax
1099
        out     dx, eax
1086
 
1100
 
Line 1110... Line 1124...
1110
 
1124
 
1111
        or      eax, ecx
1125
        or      eax, ecx
1112
        or      eax, edx
1126
        or      eax, edx
Line 1113... Line 1127...
1113
        or      eax, 01b shl 26         ; write opcode
1127
        or      eax, 01b shl 26         ; write opcode
1114
 
1128
 
1115
        set_io  0
1129
        set_io  [ebx + device.io_addr], 0
Line 1116... Line 1130...
1116
        set_io  reg_mdi_ctrl
1130
        set_io  [ebx + device.io_addr], reg_mdi_ctrl
1117
        out     dx, eax
1131
        out     dx, eax
1118
 
1132
 
Line 1133... Line 1147...
1133
align 4
1147
align 4
1134
MAC_read_eeprom:
1148
MAC_read_eeprom:
Line 1135... Line 1149...
1135
 
1149
 
1136
        mov     esi, 0
1150
        mov     esi, 0
1137
        call    ee_read
1151
        call    ee_read
Line 1138... Line 1152...
1138
        mov     word[device.mac], si
1152
        mov     word[ebx + device.mac], si
1139
 
1153
 
1140
        mov     esi, 1
1154
        mov     esi, 1
Line 1141... Line 1155...
1141
        call    ee_read
1155
        call    ee_read
1142
        mov     word[device.mac+2], si
1156
        mov     word[ebx + device.mac+2], si
1143
 
1157
 
Line 1144... Line 1158...
1144
        mov     esi, 2
1158
        mov     esi, 2
Line 1159... Line 1173...
1159
 
1173
 
Line 1160... Line -...
1160
 
-
 
Line 1161... Line -...
1161
 
-
 
-
 
1174
 
-
 
1175
 
-
 
1176
; End of code
1162
; End of code
1177
 
-
 
1178
 
1163
 
1179
data fixups
1164
align 4                                         ; Place all initialised data here
1180
end data
Line 1165... Line 1181...
1165
 
1181
 
1166
devices         dd 0                              ; number of currently running devices
1182
include '../peimport.inc'
Line 1218... Line 1234...
1218
        dw 0x245D
1234
        dw 0x245D
1219
        dw 0x27DC
1235
        dw 0x27DC
Line 1220... Line 1236...
1220
 
1236
 
Line 1221... Line -...
1221
DEVICE_IDs = ($ - device_id_list) / 2
-
 
1222
 
-
 
1223
mac_82557_D100_A  = 0
-
 
1224
mac_82557_D100_B  = 1
-
 
1225
mac_82557_D100_C  = 2
-
 
1226
mac_82558_D101_A4 = 4
-
 
1227
mac_82558_D101_B0 = 5
-
 
1228
mac_82559_D101M   = 8
-
 
1229
mac_82559_D101S   = 9
-
 
1230
mac_82550_D102    = 12
-
 
1231
mac_82550_D102_C  = 13
-
 
1232
mac_82551_E       = 14
-
 
1233
mac_82551_F       = 15
-
 
1234
mac_82551_10      = 16
-
 
1235
mac_unknown       = 0xFF
-
 
1236
 
-
 
1237
phy_100a     = 0x000003E0
-
 
1238
phy_100c     = 0x035002A8
-
 
1239
phy_82555_tx = 0x015002A8
-
 
1240
phy_nsc_tx   = 0x5C002000
-
 
1241
phy_82562_et = 0x033002A8
-
 
1242
phy_82562_em = 0x032002A8
-
 
1243
phy_82562_ek = 0x031002A8
-
 
1244
phy_82562_eh = 0x017002A8
-
 
1245
phy_82552_v  = 0xd061004d
-
 
1246
phy_unknown  = 0xFFFFFFFF
-
 
1247
 
1237
DEVICE_IDs = ($ - device_id_list) / 2
Line -... Line 1238...
-
 
1238
 
1248
 
1239
include_debug_strings                           ; All data wich FDO uses will be included here
1249
include_debug_strings                           ; All data wich FDO uses will be included here
-
 
1250
 
1240