Subversion Repositories Kolibri OS

Rev

Rev 3155 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3155 Rev 3206
Line 8... Line 8...
8
;;    Written by hidnplayr@kolibrios.org                           ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
12
;;                                                                 ;;
-
 
13
;; Some parts of this driver are based on the code of eepro100.c   ;;
-
 
14
;;  from linux.                                                    ;;
13
;;                                                                 ;;
15
;;                                                                 ;;
14
;; Good read about how to program this family of devices:          ;;
16
;; Intel's programming manual for i8255x:                          ;;
15
;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm   ;;
17
;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm   ;;
16
;;                                                                 ;;
18
;;                                                                 ;;
17
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 18... Line 20...
18
 
20
 
Line 19... Line 21...
19
 
21
 
20
format MS COFF
22
format MS COFF
Line 21... Line 23...
21
 
23
 
Line 22... Line 24...
22
        API_VERSION             =   0x01000100
24
        API_VERSION             = 0x01000100
23
        DRIVER_VERSION          =   5
25
        DRIVER_VERSION          = 5
24
 
26
 
Line 25... Line 27...
25
        MAX_DEVICES             =   16
27
        MAX_DEVICES             = 16
26
 
28
 
27
        DEBUG                   =   1
29
        DEBUG                   = 1
28
        __DEBUG__               =   1
30
        __DEBUG__               = 1
Line 42... Line 44...
42
        device:
44
        device:
Line 43... Line 45...
43
 
45
 
Line 44... Line 46...
44
        ETH_DEVICE
46
        ETH_DEVICE
45
 
47
 
46
        .io_addr        dd ?
48
        .io_addr        dd ?
47
        .pci_bus        db ?
49
        .pci_bus        dd ?
Line 48... Line 50...
48
        .pci_dev        db ?
50
        .pci_dev        dd ?
49
        .irq_line       db ?
-
 
Line 50... Line 51...
50
 
51
        .irq_line       db ?
51
        .rx_buffer      dd ?
-
 
52
        .tx_buffer      dd ?
-
 
53
 
-
 
54
        .ee_bus_width   dd ?
-
 
55
 
-
 
56
                        rb 0x100 - (($ - device) and 0xff)
-
 
57
 
-
 
58
        rxfd:
-
 
59
        .status         dw ?
-
 
60
        .command        dw ?
-
 
61
        .link           dd ?
-
 
Line 62... Line 52...
62
        .rx_buf_addr    dd ?
52
 
Line 63... Line 53...
63
        .count          dw ?
53
        .rx_desc        dd ?
64
        .size           dw ?
54
 
65
        .packet         dd ?
55
        .ee_bus_width   db ?
66
 
56
 
67
                        rb 0x100 - (($ - device) and 0xff)
57
                        rb 0x100 - (($ - device) and 0xff)
68
 
58
 
-
 
59
        txfd:
69
        txfd:
60
        .status         dw ?
70
        .status         dw ?
61
        .command        dw ?
71
        .command        dw ?
-
 
72
        .link           dd ?
-
 
Line 73... Line 62...
73
        .tx_desc_addr   dd ?
62
        .link           dd ?
Line 74... Line 63...
74
        .count          dd ?
63
        .tx_desc_addr   dd ?
75
        .tx_buf_addr0   dd ?
64
        .count          dd ?
76
        .tx_buf_size0   dd ?
65
 
77
        .tx_buf_addr1   dd ?
66
        .tx_buf_addr0   dd ?
78
        .tx_buf_size1   dd ?
67
        .tx_buf_size0   dd ?
Line 79... Line 68...
79
 
68
 
Line 80... Line 69...
80
                        rb 0x100 - (($ - device) and 0xff)
69
                        rb 0x100 - (($ - device) and 0xff)
Line 104... Line 93...
104
        rx_resource_errs        dd ?
93
        rx_resource_errs        dd ?
105
        rx_overrun_errs         dd ?
94
        rx_overrun_errs         dd ?
106
        rx_colls_errs           dd ?
95
        rx_colls_errs           dd ?
107
        rx_runt_errs            dd ?
96
        rx_runt_errs            dd ?
Line -... Line 97...
-
 
97
 
-
 
98
        last_tx_buffer          dd ?    ;;; fixme
108
 
99
 
Line 109... Line 100...
109
        sizeof.device_struct = $ - device
100
        sizeof.device_struct = $ - device
Line -... Line 101...
-
 
101
 
-
 
102
end virtual
-
 
103
 
-
 
104
 
-
 
105
virtual at 0
-
 
106
 
-
 
107
        rxfd:
-
 
108
        .status         dw ?
-
 
109
        .command        dw ?
-
 
110
        .link           dd ?
-
 
111
        .rx_buf_addr    dd ?
-
 
112
        .count          dw ?
-
 
113
        .size           dw ?
-
 
114
        .packet:
110
 
115
 
Line 111... Line 116...
111
end virtual
116
end virtual
112
 
117
 
113
 
118
 
114
; Serial EEPROM
119
; Serial EEPROM
-
 
120
 
115
 
121
EE_SK           = 1 shl 0      ; serial clock
-
 
122
EE_CS           = 1 shl 1      ; chip select
116
EE_SK           =   1 shl 0   ; serial clock
123
EE_DI           = 1 shl 2      ; data in
117
EE_CS           =   1 shl 1   ; chip select
124
EE_DO           = 1 shl 3      ; data out
118
EE_DI           =   1 shl 2   ; data in
125
EE_MASK         = EE_SK + EE_CS + EE_DI + EE_DO
Line 119... Line 126...
119
EE_DO           =   1 shl 3   ; data out
126
 
Line 120... Line 127...
120
 
127
; opcodes, first bit is start bit and must be 1
121
EE_READ         =   110b
128
EE_READ         = 110b
122
EE_WRITE        =   101b
129
EE_WRITE        = 101b
123
EE_ERASE        =   111b
130
EE_ERASE        = 111b
124
 
131
 
125
; The SCB accepts the following controls for the Tx and Rx units:
132
; The SCB accepts the following controls for the Tx and Rx units:
126
 
133
 
127
CU_START        =   0x0010
134
CU_START        = 0x0010
128
CU_RESUME       =   0x0020
135
CU_RESUME       = 0x0020
129
CU_STATSADDR    =   0x0040
136
CU_STATSADDR    = 0x0040
130
CU_SHOWSTATS    =   0x0050   ; Dump statistics counters.
137
CU_SHOWSTATS    = 0x0050        ; Dump statistics counters.
131
CU_CMD_BASE     =   0x0060   ; Base address to add to add CU commands.
138
CU_CMD_BASE     = 0x0060        ; Base address to add CU commands.
132
CU_DUMPSTATS    =   0x0070   ; Dump then reset stats counters.
139
CU_DUMPSTATS    = 0x0070        ; Dump then reset stats counters.
133
 
140
 
134
RX_START        =   0x0001
141
RX_START        = 0x0001
135
RX_RESUME       =   0x0002
142
RX_RESUME       = 0x0002
136
RX_ABORT        =   0x0004
143
RX_ABORT        = 0x0004
137
RX_ADDR_LOAD    =   0x0006
144
RX_ADDR_LOAD    = 0x0006
138
RX_RESUMENR     =   0x0007
145
RX_RESUMENR     = 0x0007
139
INT_MASK        =   0x0100
146
INT_MASK        = 0x0100
140
DRVR_INT        =   0x0200   ; Driver generated interrupt
147
DRVR_INT        = 0x0200        ; Driver generated interrupt
141
 
148
 
142
CmdIASetup      =   0x0001
149
CmdIASetup      = 0x0001
143
CmdConfigure    =   0x0002
150
CmdConfigure    = 0x0002
144
CmdTx           =   0x0004 ;;;;
151
CmdTx           = 0x0004
145
CmdTxFlex       =   0x0008 ;;;
152
CmdTxFlex       = 0x0008
146
Cmdsuspend      =   0x4000
-
 
147
 
153
Cmdsuspend      = 0x4000
148
 
154
 
Line 149... Line 155...
149
reg_scb_status  =   0
155
 
150
reg_scb_cmd     =   2
156
reg_scb_status  = 0
151
reg_scb_ptr     =   4
157
reg_scb_cmd     = 2
152
reg_port        =   8
158
reg_scb_ptr     = 4
153
reg_eeprom_ctrl =   12
159
reg_port        = 8
154
reg_eeprom      =   14
160
reg_eeprom      = 14
155
reg_mdi_ctrl    =   16
161
reg_mdi_ctrl    = 16
156
 
162
 
157
 
163
 
158
macro delay {
164
macro delay {
159
        push    eax
165
        push    eax
160
        in      eax, dx
166
        in      ax, dx
161
        in      eax, dx
167
        in      ax, dx
162
        in      eax, dx
168
        in      ax, dx
Line 163... Line 169...
163
        in      eax, dx
169
        in      ax, dx
Line 245... Line 251...
245
 
251
 
246
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
252
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
247
        mov     ax , [eax+1]                            ;
253
        mov     ax , [eax+1]                            ;
248
  .nextdevice:
254
  .nextdevice:
249
        mov     ebx, [esi]
255
        mov     ebx, [esi]
-
 
256
        cmp     al, byte[device.pci_bus]
-
 
257
        jne     @f
250
        cmp     ax , word [device.pci_bus]              ; compare with pci and device num in device list (notice the usage of word instead of byte)
258
        cmp     ah, byte[device.pci_dev]
-
 
259
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
251
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
260
       @@:
252
        add     esi, 4
261
        add     esi, 4
Line 253... Line 262...
253
        loop    .nextdevice
262
        loop    .nextdevice
Line 270... Line 279...
270
        mov     [device.name], my_service
279
        mov     [device.name], my_service
Line 271... Line 280...
271
 
280
 
Line 272... Line 281...
272
; save the pci bus and device numbers
281
; save the pci bus and device numbers
273
 
282
 
274
        mov     eax, [IOCTL.input]
283
        mov     eax, [IOCTL.input]
275
        mov     cl, [eax+1]
284
        movzx   ecx, byte[eax+1]
276
        mov     [device.pci_bus], cl
285
        mov     [device.pci_bus], ecx
Line 277... Line 286...
277
        mov     cl, [eax+2]
286
        movzx   ecx, byte[eax+2]
Line 278... Line 287...
278
        mov     [device.pci_dev], cl
287
        mov     [device.pci_dev], ecx
Line 279... Line 288...
279
 
288
 
Line 280... Line 289...
280
; Now, it's time to find the base io addres of the PCI device
289
; Now, it's time to find the base io addres of the PCI device
Line 281... Line 290...
281
 
290
 
282
        find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
291
        PCI_find_io
Line 283... Line -...
283
 
-
 
284
; We've found the io address, find IRQ now
-
 
285
 
-
 
286
        find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
292
 
Line -... Line 293...
-
 
293
; We've found the io address, find IRQ now
-
 
294
 
-
 
295
        PCI_find_irq
287
 
296
 
288
        DEBUGF  2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
297
        DEBUGF  2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
289
        [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
298
        [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
Line 290... Line 299...
290
 
299
 
291
        allocate_and_clear [device.rx_buffer], (4096), .err
300
; Ok, the eth_device structure is ready, let's probe the device
292
        allocate_and_clear [device.tx_buffer], (4096), .err
301
 
Line -... Line 302...
-
 
302
        pushf
Line 293... Line 303...
293
 
303
        cli                     ; disable ints until initialisation is done
294
; Ok, the eth_device structure is ready, let's probe the device
304
 
Line 295... Line 305...
295
 
305
        call    probe                                                   ; this function will output in eax
Line 321... Line 331...
321
        ret
331
        ret
Line 322... Line 332...
322
 
332
 
Line 323... Line 333...
323
; If an error occured, remove all allocated data and exit (returning -1 in eax)
333
; If an error occured, remove all allocated data and exit (returning -1 in eax)
324
 
-
 
325
  .err:
-
 
326
        stdcall KernelFree, [device.rx_buffer]
334
 
Line 327... Line 335...
327
        stdcall KernelFree, [device.tx_buffer]
335
  .err:
328
        stdcall KernelFree, ebx
336
        stdcall KernelFree, ebx
329
 
337
 
Line 368... Line 376...
368
align 4
376
align 4
369
probe:
377
probe:
Line 370... Line 378...
370
 
378
 
Line 371... Line 379...
371
        DEBUGF  1,"Probing i8255x\n"
379
        DEBUGF  1,"Probing i8255x\n"
Line 372... Line 380...
372
 
380
 
373
        make_bus_master [device.pci_bus], [device.pci_dev]
381
        PCI_make_bus_master
Line 374... Line -...
374
 
-
 
375
;---------------------------
-
 
376
; First, identify the device
382
 
Line 377... Line 383...
377
 
383
;---------------------------
Line 378... Line 384...
378
        movzx   ecx, [device.pci_bus]
384
; First, identify the device
379
        movzx   edx, [device.pci_dev]
385
 
Line 414... Line 420...
414
;----------
420
;----------
Line 415... Line 421...
415
 
421
 
416
align 4
422
align 4
Line -... Line 423...
-
 
423
reset:
-
 
424
 
-
 
425
        movzx   eax, [device.irq_line]
-
 
426
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
-
 
427
        stdcall AttachIntHandler, eax, int_handler, dword 0
-
 
428
        test    eax, eax
-
 
429
        jnz     @f
-
 
430
        DEBUGF  1,"\nCould not attach int handler!\n"
-
 
431
;        or      eax, -1
-
 
432
;        ret
-
 
433
  @@:
-
 
434
 
417
reset:
435
        DEBUGF  1,"Resetting %s\n", my_service
418
 
436
 
Line 419... Line 437...
419
;---------------
437
;---------------
420
; reset the card
438
; reset the card
Line 430... Line 448...
430
;---------------------------------
448
;---------------------------------
431
; Tell device where to store stats
449
; Tell device where to store stats
Line 432... Line 450...
432
 
450
 
433
        lea     eax, [lstats]
451
        lea     eax, [lstats]
-
 
452
        GetRealAddr
434
        GetRealAddr
453
        set_io  0
435
        set_io  reg_scb_ptr
454
        set_io  reg_scb_ptr
Line 436... Line 455...
436
        out     dx, eax
455
        out     dx, eax
437
 
456
 
438
        mov     ax, INT_MASK + CU_STATSADDR
457
        mov     ax, INT_MASK + CU_STATSADDR
439
        set_io  reg_scb_cmd
458
        set_io  reg_scb_cmd
Line 440... Line 459...
440
        out     dx, ax
459
        out     dx, ax
441
        call    cmd_wait
460
        call    cmd_wait
Line 442... Line -...
442
 
-
 
443
;-----------------
461
 
-
 
462
;-----------------
444
; Set CU base to 0
463
; setup RX
Line 445... Line -...
445
 
-
 
446
        xor     eax, eax
464
 
-
 
465
        set_io  reg_scb_ptr
447
        set_io  reg_scb_ptr
466
        xor     eax, eax
448
        out     dx, eax
467
        out     dx, eax
Line 449... Line 468...
449
 
468
 
450
        mov     ax, INT_MASK + RX_ADDR_LOAD
469
        set_io  reg_scb_cmd
451
        set_io  reg_scb_cmd
-
 
452
        out     dx, ax
-
 
453
        call    cmd_wait
-
 
454
 
-
 
455
;---------------------
-
 
456
; build rxfd structure
-
 
457
 
-
 
458
        mov     ax, 0x0001
-
 
459
        mov     [rxfd.status], ax
-
 
460
        mov     ax, 0x0000
-
 
461
        mov     [rxfd.command], ax
-
 
462
 
-
 
463
        lea     eax, [rxfd.status]
-
 
464
        GetRealAddr
-
 
465
        mov     [rxfd.link], eax
-
 
466
 
-
 
Line 467... Line 470...
467
        lea     eax, [device.rx_buffer]
470
        mov     ax, INT_MASK + RX_ADDR_LOAD
468
        GetRealAddr
-
 
Line 469... Line -...
469
        mov     [rxfd.rx_buf_addr], eax
-
 
470
 
471
        out     dx, ax
Line -... Line 472...
-
 
472
        call    cmd_wait
471
        xor     ax, ax
473
 
472
        mov     [rxfd.count], ax
474
;-----------------------------
473
 
475
; Create RX and TX descriptors
474
        mov     ax, 1528
476
 
Line 475... Line -...
475
        mov     [rxfd.size], ax
-
 
476
 
477
        call    create_ring
477
;-------------------------------
-
 
478
; Set ptr to first command block
-
 
479
 
-
 
480
        set_io  reg_scb_ptr
-
 
481
        lea     eax, [rxfd]
-
 
482
        GetRealAddr
-
 
483
        out     dx, eax
-
 
484
 
-
 
485
        set_io  reg_scb_cmd
-
 
486
        mov     ax, INT_MASK + RX_START
-
 
487
        out     dx, ax
-
 
488
        call    cmd_wait
-
 
489
 
-
 
490
;-------------------
-
 
491
; start the receiver
478
 
492
 
-
 
493
        mov     [rxfd.status], 0
479
; RX start
494
        mov     [rxfd.command], 0xc000
480
 
Line 495... Line -...
495
 
-
 
496
        set_io  reg_scb_ptr
481
        set_io  0
Line 497... Line 482...
497
        lea     eax, [rxfd]
482
        set_io  reg_scb_ptr
498
        GetRealAddr
483
        mov     eax, [device.rx_desc]
499
        out     dx, eax
484
        GetRealAddr
Line 500... Line 485...
500
 
485
        out     dx, eax
501
        set_io  reg_scb_cmd
486
 
502
        mov     ax, INT_MASK + RX_START
487
        mov     ax, INT_MASK + RX_START
503
        out     dx, ax
488
        set_io  reg_scb_cmd
Line 504... Line 489...
504
        call    cmd_wait
489
        out     dx, ax
505
 
-
 
Line -... Line 490...
-
 
490
        call    cmd_wait
506
;-----------------
491
 
-
 
492
; Set-up TX
-
 
493
 
-
 
494
        set_io  reg_scb_ptr
-
 
495
        xor     eax, eax
-
 
496
        out     dx, eax
-
 
497
 
-
 
498
        set_io  reg_scb_cmd
-
 
499
        mov     ax, INT_MASK + CU_CMD_BASE
-
 
500
        out     dx, ax
-
 
501
        call    cmd_wait
-
 
502
 
-
 
503
;  --------------------
-
 
504
 
-
 
505
        mov     [confcmd.command], CmdConfigure + Cmdsuspend
-
 
506
        mov     [confcmd.status], 0
Line 507... Line 507...
507
; set CU base to 0
507
        lea     eax, [txfd]
508
 
508
        GetRealAddr
509
        set_io  reg_scb_ptr
509
        mov     [confcmd.link], eax
510
        xor     eax, eax
510
 
511
        out     dx, eax
511
        mov     esi, confcmd_data
Line 512... Line -...
512
 
-
 
513
        set_io  reg_scb_cmd
-
 
514
        mov     ax, INT_MASK + CU_CMD_BASE
-
 
515
        out     dx, ax
512
        lea     edi, [confcmd.data]
516
        call    cmd_wait
-
 
517
 
-
 
518
;--------------------
-
 
519
; Set TX Base address
-
 
520
 
-
 
521
; First, set up confcmd values
-
 
522
 
-
 
523
        mov     [txfd.command], CmdIASetup
-
 
524
        mov     [txfd.status], 0
-
 
Line -... Line 513...
-
 
513
        mov     ecx, 22
-
 
514
        rep     movsb
-
 
515
 
525
        lea     eax, [confcmd]
516
        mov     byte[confcmd.data + 1], 0x88  ; fifo of 8 each
Line 526... Line -...
526
        GetRealAddr
-
 
527
        mov     [txfd.link], eax
-
 
528
 
-
 
529
        mov     word [confcmd.command], Cmdsuspend + CmdConfigure
517
        mov     byte[confcmd.data + 4], 0
-
 
518
        mov     byte[confcmd.data + 5], 0x80
-
 
519
        mov     byte[confcmd.data + 15], 0x48
530
        mov     word [confcmd.status], 0
520
        mov     byte[confcmd.data + 19], 0x80
Line 531... Line 521...
531
        lea     eax, [txfd]
521
        mov     byte[confcmd.data + 21], 0x05
-
 
522
 
532
        GetRealAddr
523
        mov     [txfd.command], CmdIASetup
-
 
524
        mov     [txfd.status], 0
533
        mov     [confcmd.link], eax
525
        lea     eax, [confcmd]
534
 
526
        GetRealAddr
Line -... Line 527...
-
 
527
        mov     [txfd.link], eax
535
        mov     byte [confcmd.data + 1], 0x88  ; fifo of 8 each
528
 
Line -... Line 529...
-
 
529
;;; copy in our MAC
536
        mov     byte [confcmd.data + 4], 0
530
 
537
        mov     byte [confcmd.data + 5], 0x80
-
 
538
        mov     byte [confcmd.data + 15], 0x48
531
        lea     edi, [txfd.tx_desc_addr]
-
 
532
        lea     esi, [device.mac]
-
 
533
        movsd
539
        mov     byte [confcmd.data + 19], 0x80
534
        movsw
-
 
535
 
Line 540... Line 536...
540
        mov     byte [confcmd.data + 21], 0x05
536
        set_io  reg_scb_ptr
Line -... Line 537...
-
 
537
        lea     eax, [txfd]
Line 541... Line 538...
541
 
538
        GetRealAddr
-
 
539
        out     dx, eax
Line -... Line 540...
-
 
540
 
-
 
541
; Start CU & enable ints
-
 
542
 
-
 
543
        set_io  reg_scb_cmd
-
 
544
        mov     ax, CU_START
-
 
545
        out     dx, ax
-
 
546
        call    cmd_wait
-
 
547
 
-
 
548
;-----------------------
-
 
549
; build txfd structure (again!)
-
 
550
 
-
 
551
        lea     eax, [txfd]
-
 
552
        GetRealAddr
542
 
553
        mov     [txfd.link], eax
-
 
554
        mov     [txfd.count], 0x02208000
-
 
555
        lea     eax, [txfd.tx_buf_addr0]
-
 
556
        GetRealAddr
-
 
557
        mov     [txfd.tx_desc_addr], eax
-
 
558
 
-
 
559
; Indicate that we have successfully reset the card
-
 
560
 
-
 
561
        DEBUGF  1,"Resetting %s complete\n", my_service
-
 
562
 
-
 
563
        mov     [device.mtu], 1514
-
 
564
        xor     eax, eax        ; indicate that we have successfully reset the card
-
 
565
 
-
 
566
        ret
-
 
567
 
-
 
568
 
-
 
569
align 4
-
 
570
create_ring:
Line 543... Line 571...
543
; CU start
571
 
Line 584... Line 612...
584
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
612
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 585... Line 613...
585
 
613
 
586
align 4
614
align 4
Line 587... Line 615...
587
transmit:
615
transmit:
588
 
616
 
589
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
617
        DEBUGF  1,"Transmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8]
590
        mov     eax, [esp+4]
618
        mov     eax, [esp+4]
591
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
619
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
592
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
620
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
Line 593... Line 621...
593
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
621
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
594
        [eax+13]:2,[eax+12]:2
622
        [eax+13]:2,[eax+12]:2
595
 
623
 
596
        cmp     dword [esp+8], 1500
624
        cmp     dword [esp+8], 1514
Line 597... Line -...
597
        ja      .error                          ; packet is too long
-
 
598
        cmp     dword [esp+8], 60
-
 
599
        jb      .error                          ; packet is too short
-
 
600
 
-
 
601
        set_io  0
-
 
602
        in      ax, dx
-
 
603
        and     ax, 0xfc00
625
        ja      .error                          ; packet is too long
604
        out     dx, ax
-
 
605
 
-
 
606
        mov     [txfd.status], 0
-
 
607
        mov     [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex
-
 
608
        lea     eax, [txfd]
-
 
609
        GetRealAddr
-
 
610
        mov     [txfd.link], eax
626
        cmp     dword [esp+8], 60
611
        mov     [txfd.count], 0x02208000
-
 
612
        lea     eax, [txfd.tx_buf_addr0]
627
        jb      .error                          ; packet is too short
-
 
628
 
-
 
629
        ;;; TODO: check if current descriptor is in use
613
        GetRealAddr
630
        ; fill in buffer address and size
614
        mov     [txfd.tx_desc_addr], eax
631
        mov     eax, [esp+4]
615
 
632
        mov     [last_tx_buffer], eax   ;;; FIXME
Line 616... Line 633...
616
        mov     eax, [esp+4]
633
        GetRealAddr
617
        mov     [txfd.tx_buf_addr0], eax
634
        mov     [txfd.tx_buf_addr0], eax
-
 
635
        mov     eax, [esp+8]
618
        mov     eax, [esp+8]
636
        mov     [txfd.tx_buf_size0], eax
Line -... Line 637...
-
 
637
 
619
        mov     [txfd.tx_buf_size0], eax
638
        mov     [txfd.status], 0
620
 
639
        mov     [txfd.command], Cmdsuspend + CmdTx + CmdTxFlex + 1 shl 15 ;;; EL bit
-
 
640
 
621
        ; Copy the buffer address and size in
641
 ;       mov     [txfd.count], 0x02208000   ;;;;;;;;;;;
622
        mov     [txfd.tx_buf_addr1], 0
642
 
Line -... Line 643...
-
 
643
        ; Inform device of the new/updated transmit descriptor
623
        mov     [txfd.tx_buf_size1], 0
644
        lea     eax, [txfd]
624
 
645
        GetRealAddr
625
        lea     eax, [txfd]
646
        set_io  0
626
        GetRealAddr
-
 
627
        set_io  reg_scb_ptr
647
        set_io  reg_scb_ptr
Line -... Line 648...
-
 
648
        out     dx, eax
-
 
649
 
-
 
650
        ; Start the transmit
-
 
651
        mov     ax, CU_START
-
 
652
        set_io  reg_scb_cmd
628
        out     dx, eax
653
        out     dx, ax
-
 
654
        call    cmd_wait
-
 
655
 
-
 
656
;        set_io  0               ;; why?
Line 629... Line 657...
629
 
657
;        in      ax, dx          ;;
630
        mov     ax, INT_MASK + CU_START
658
;
631
        set_io  reg_scb_cmd
659
;  @@:
-
 
660
;        cmp     [txfd.status], 0  ; wait for completion? dont seems a good idea to me..
-
 
661
;        je      @r
Line 632... Line -...
632
        out     dx, ax
-
 
633
 
-
 
634
        call    cmd_wait
-
 
635
 
662
;
636
        in      ax, dx
663
;        set_io  0               ;; why?
Line 637... Line 664...
637
 
664
;        in      ax, dx          ;;
638
  .I8t_001:
665
 
Line 668... Line 695...
668
        jz      .nothing
695
        jz      .nothing
669
        mov     esi, device_list
696
        mov     esi, device_list
670
  .nextdevice:
697
  .nextdevice:
671
        mov     ebx, [esi]
698
        mov     ebx, [esi]
Line 672... Line 699...
672
 
699
 
673
        set_io  0
700
;        set_io  0              ; reg_scb_status = 0
674
        set_io  reg_scb_status
701
        set_io  reg_scb_status
675
        in      ax, dx
702
        in      ax, dx
676
        out     dx, ax                              ; send it back to ACK
703
        out     dx, ax                              ; send it back to ACK
677
        test    ax, ax
704
        test    ax, ax
Line 683... Line 710...
683
  .nothing:
710
  .nothing:
684
        ret                                         ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
711
        ret                                         ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
Line 685... Line 712...
685
 
712
 
Line 686... Line 713...
686
  .got_it:
713
  .got_it:
-
 
714
 
-
 
715
        DEBUGF  1,"Device: %x Status: %x\n", ebx, ax
-
 
716
 
Line 687... Line 717...
687
 
717
        test    ax, 1 shl 14    ; did we receive a frame?
Line -... Line 718...
-
 
718
        jz      .no_rx
-
 
719
 
-
 
720
        push    ax
-
 
721
 
688
        DEBUGF  1,"Device: %x Status: %x ", ebx, ax
722
        DEBUGF  1,"Receiving\n"
-
 
723
 
-
 
724
        push    ebx
-
 
725
  .rx_loop:
689
 
726
        pop     ebx
Line 690... Line 727...
690
       ;;; receive
727
 
691
 
-
 
Line -... Line 728...
-
 
728
        mov     esi, [device.rx_desc]
-
 
729
        cmp     [esi + rxfd.status], 0        ; we could also check bits C and OK (bit 15 and 13)
-
 
730
        je      .nodata
-
 
731
 
692
        cmp     [rxfd.status], 0
732
        DEBUGF  1,"rxfd status=0x%x\n", [esi + rxfd.status]:4
-
 
733
 
693
        je      .nodata
734
        movzx   ecx, [esi + rxfd.count]
-
 
735
        and     ecx, 0x3fff
-
 
736
 
-
 
737
        push    ebx
-
 
738
        push    .rx_loop
-
 
739
        push    ecx
-
 
740
        add     esi, rxfd.packet
-
 
741
        push    esi
-
 
742
 
-
 
743
; Update stats
-
 
744
        add     dword [device.bytes_rx], ecx
-
 
745
        adc     dword [device.bytes_rx + 4], 0
-
 
746
        inc     dword [device.packets_rx]
694
 
747
 
-
 
748
; allocate new descriptor
-
 
749
 
-
 
750
        stdcall KernelAlloc, 2000
-
 
751
        mov     [device.rx_desc], eax
-
 
752
        mov     esi, eax
-
 
753
        GetRealAddr
-
 
754
        mov     [esi + rxfd.status], 0x0000
-
 
755
        mov     [esi + rxfd.command], 0xc000    ; End of list + Suspend
-
 
756
        mov     [esi + rxfd.link], eax
-
 
757
        mov     [esi + rxfd.count], 0
-
 
758
        mov     [esi + rxfd.size], 1528
-
 
759
 
695
        mov     [rxfd.status], 0
760
; restart RX
Line 696... Line 761...
696
        mov     [rxfd.command], 0xc000
761
 
697
 
762
        set_io  0
698
        set_io  reg_scb_ptr
763
        set_io  reg_scb_ptr
699
        lea     eax, [rxfd.status]
-
 
700
        GetRealAddr
764
;        lea     eax, [device.rx_desc]
Line 701... Line -...
701
        out     dx, eax
-
 
702
 
765
;        GetRealAddr
Line 703... Line -...
703
        set_io  reg_scb_cmd
-
 
704
        mov     ax, INT_MASK + RX_START
-
 
705
        out     dx, ax
766
        out     dx, eax
Line -... Line 767...
-
 
767
 
706
 
768
        set_io  reg_scb_cmd
-
 
769
        mov     ax, RX_START
Line 707... Line 770...
707
        call    cmd_wait
770
        out     dx, ax
708
 
-
 
709
        movzx   ecx, [rxfd.count]
-
 
710
        and     ecx, 0x3fff
-
 
711
 
-
 
712
        stdcall KernelAlloc, ecx        ; Allocate a buffer to put packet into
-
 
713
        push    ecx
-
 
714
        push    eax
-
 
715
 
-
 
716
        lea     esi, [device.rx_buffer]
-
 
717
 
-
 
718
  .copy:
-
 
Line 719... Line 771...
719
        shr     ecx, 1
771
        call    cmd_wait
Line -... Line 772...
-
 
772
 
-
 
773
; And give packet to kernel
-
 
774
 
-
 
775
        jmp     Eth_input
-
 
776
 
720
        jnc     .nb
777
  .nodata:
721
        movsb
778
        DEBUGF  1, "no more data\n"
Line 722... Line 779...
722
  .nb:
779
        pop     ax
Line 753... Line 810...
753
 
810
 
754
 
811
 
Line -... Line 812...
-
 
812
align 4
-
 
813
ee_read:        ; esi = address to read
755
align 4
814
 
756
ee_read:        ; esi = address to read
815
        DEBUGF  1,"Eeprom read from 0x%x", esi
Line 757... Line 816...
757
 
816
 
758
        set_io  0
817
        set_io  0
759
        set_io  reg_eeprom
818
        set_io  reg_eeprom
Line 760... Line 819...
760
 
819
 
761
;-----------------------------------------------------
820
;-----------------------------------------------------
762
; Prepend start bit + read opcode to the address field
821
; Prepend start bit + read opcode to the address field
763
; and shift it to the very left bits of esi
822
; and shift it to the very left bits of esi
Line 764... Line 823...
764
 
823
 
765
        mov     ecx, 32
824
        mov     cl, 29
Line -... Line 825...
-
 
825
        sub     cl, [device.ee_bus_width]
-
 
826
        shl     esi, cl
-
 
827
        or      esi, EE_READ shl 29
-
 
828
 
766
        sub     ecx, [device.ee_bus_width]
829
        movzx   ecx, [device.ee_bus_width]
767
        shl     esi, cl
830
        add     ecx, 3
Line 768... Line 831...
768
        or      esi, EE_READ shl 28
831
 
769
 
832
        mov     al, EE_CS
770
        mov     ecx, [device.ee_bus_width]
833
        out     dx, al
771
        add     ecx, 3
834
        delay
772
 
835
 
773
;-----------------------
836
;-----------------------
774
; Write this to the chip
837
; Write this to the chip
775
 
838
 
Line 776... Line 839...
776
  .loop:
839
  .loop:
777
        mov     eax, EE_CS
840
        mov     al, EE_CS + EE_SK
778
        shl     esi, 1
841
        shl     esi, 1
Line 779... Line 842...
779
        jnc     @f
842
        jnc     @f
Line 780... Line 843...
780
        or      eax, EE_DI
843
        or      al, EE_DI
Line 793... Line 856...
793
 
856
 
794
        xor     esi, esi
857
        xor     esi, esi
Line 795... Line 858...
795
        mov     ecx, 16
858
        mov     ecx, 16
-
 
859
 
796
 
860
  .loop2:
797
  .loop2:
861
        shl     esi, 1
798
        mov     eax, EE_CS + EE_SK
862
        mov     al, EE_CS + EE_SK
Line 799... Line 863...
799
        out     dx , eax
863
        out     dx, al
800
        delay
864
        delay
801
 
865
 
802
        in      eax, dx
866
        in      al, dx
803
        test    eax, EE_DO
867
        test    al, EE_DO
804
        jz      @f
-
 
Line 805... Line 868...
805
        inc     esi
868
        jz      @f
806
       @@:
869
        inc     esi
807
        shl     esi, 1
870
       @@:
Line 808... Line 871...
808
 
871
 
Line 809... Line 872...
809
        mov     eax, EE_CS
872
        mov     al, EE_CS
810
        out     dx , eax
873
        out     dx, al
Line 811... Line 874...
811
        delay
874
        delay
812
 
875
 
Line 813... Line 876...
813
        loop    .loop2
876
        loop    .loop2
814
 
877
 
Line 815... Line 878...
815
;-----------------------
878
;-----------------------
816
; de-activate the eeprom
879
; de-activate the eeprom
Line -... Line 880...
-
 
880
 
-
 
881
        xor     ax, ax
817
 
882
        out     dx, ax
818
        xor     eax, eax
883
 
Line 819... Line 884...
819
        out     dx, eax
884
 
820
 
885
        DEBUGF  1,"=0x%x\n", esi:4
821
 
886
        ret
Line 822... Line 887...
822
        DEBUGF  1,"data=%x\n", esi
887
 
823
        ret
888
 
824
 
889
 
825
 
890
align 4
Line 826... Line 891...
826
 
891
ee_write:       ; esi = address to write to, di = data
827
align 4
892
 
Line -... Line 893...
-
 
893
        DEBUGF  1,"Eeprom write 0x%x to 0x%x\n", di, esi
-
 
894
 
-
 
895
        set_io  0
828
ee_write:       ; esi = address to write to, di = data
896
        set_io  reg_eeprom
829
 
897
 
Line 830... Line 898...
830
        set_io  0
898
;-----------------------------------------------------
831
        set_io  reg_eeprom
899
; Prepend start bit + write opcode to the address field
832
 
900
; and shift it to the very left bits of esi
833
;-----------------------------------------------------
901
 
834
; Prepend start bit + write opcode to the address field
902
        mov     cl, 29
835
; and shift it to the very left bits of esi
903
        sub     cl, [device.ee_bus_width]
836
 
904
        shl     esi, cl
837
        mov     ecx, 32
905
        or      esi, EE_WRITE shl 29
Line 838... Line 906...
838
        sub     ecx, [device.ee_bus_width]
906
 
839
        shl     esi, cl
907
        movzx   ecx, [device.ee_bus_width]
840
        or      esi, EE_WRITE shl 28
908
        add     ecx, 3
Line 841... Line 909...
841
 
909
 
Line 842... Line 910...
842
        mov     ecx, [device.ee_bus_width]
910
        mov     al, EE_CS       ; enable chip
843
        add     ecx, 3
911
        out     dx, al
Line 844... Line 912...
844
 
912
 
Line 845... Line 913...
845
;-----------------------
913
;-----------------------
846
; Write this to the chip
914
; Write this to the chip
847
 
915
 
848
  .loop:
916
  .loop:
849
        mov     eax, EE_CS
917
        mov     al, EE_CS + EE_SK
850
        shl     esi, 1
918
        shl     esi, 1
851
        jnc     @f
919
        jnc     @f
852
        or      eax, EE_DI
920
        or      al, EE_DI
Line 853... Line 921...
853
       @@:
921
       @@:
854
        out     dx , eax
922
        out     dx, al
855
        delay
923
        delay
Line 856... Line 924...
856
 
924
 
Line 857... Line 925...
857
        or      eax, EE_SK
925
        and     al, not EE_SK
858
        out     dx , eax
926
        out     dx, al
Line 859... Line 927...
859
        delay
927
        delay
860
 
928
 
Line 861... Line 929...
861
        loop    .loop
929
        loop    .loop
Line 862... Line 930...
862
 
930
 
863
;-----------------------------
931
;-----------------------------
Line -... Line 932...
-
 
932
; Now write the data to eeprom
-
 
933
 
864
; Now write the data to eeprom
934
        mov     ecx, 16
865
 
935
 
Line -... Line 936...
-
 
936
  .loop2:
-
 
937
        mov     al, EE_CS + EE_SK
-
 
938
        shl     di, 1
-
 
939
        jnc     @f
866
        mov     ecx, 16
940
        or      al, EE_DI
867
 
941
       @@:
868
  .loop2:
942
        out     dx, al
-
 
943
        delay
-
 
944
 
-
 
945
        and     al, not EE_SK
869
        mov     eax, EE_CS
946
        out     dx, al
-
 
947
        delay
870
        shl     di , 1
948
 
871
        jnc     @f
949
        loop    .loop2
Line 872... Line 950...
872
        or      eax, EE_DI
950
 
873
       @@:
951
;-----------------------
874
        out     dx , eax
952
; de-activate the eeprom
Line 875... Line 953...
875
        delay
953
 
Line -... Line 954...
-
 
954
        xor     al, al
-
 
955
        out     dx, al
-
 
956
 
876
 
957
 
877
        or      eax, EE_SK
958
        ret
878
        out     dx , eax
959
 
Line -... Line 960...
-
 
960
 
-
 
961
 
-
 
962
align 4
-
 
963
ee_get_width:
-
 
964
 
-
 
965
;        DEBUGF  1,"Eeprom get width\n"
879
        delay
966
 
880
 
967
        set_io  0
Line 881... Line 968...
881
        loop    .loop2
968
        set_io  reg_eeprom
882
 
969
 
Line 934... Line 1021...
934
; ax = data
1021
; ax = data
Line 935... Line 1022...
935
 
1022
 
936
align 4
1023
align 4
Line -... Line 1024...
-
 
1024
mdio_read:
-
 
1025
 
937
mdio_read:
1026
        DEBUGF  1,"MDIO read\n"
938
 
1027
 
Line 939... Line 1028...
939
        shl     ecx, 21                 ; PHY addr
1028
        shl     ecx, 21                 ; PHY addr
940
        shl     edx, 16                 ; PHY reg addr
1029
        shl     edx, 16                 ; PHY reg addr
Line 962... Line 1051...
962
; ax = data
1051
; ax = data
Line 963... Line 1052...
963
 
1052
 
964
align 4
1053
align 4
Line -... Line 1054...
-
 
1054
mdio_write:
-
 
1055
 
965
mdio_write:
1056
        DEBUGF  1,"MDIO write\n"
Line 966... Line 1057...
966
 
1057
 
967
        and     eax, 0xffff
1058
        and     eax, 0xffff
Line 994... Line 1085...
994
align 4
1085
align 4
995
MAC_read_eeprom:
1086
MAC_read_eeprom:
Line 996... Line 1087...
996
 
1087
 
997
        mov     esi, 0
1088
        mov     esi, 0
-
 
1089
        call    ee_read
Line 998... Line 1090...
998
        call    ee_read
1090
        mov     word[device.mac], si
999
 
1091
 
-
 
1092
        mov     esi, 1
Line 1000... Line -...
1000
        mov     esi, 1
-
 
1001
        call    ee_read
-
 
1002
 
-
 
1003
        mov     esi, 14
1093
        call    ee_read
1004
        call    ee_read
1094
        mov     word[device.mac+2], si
-
 
1095
 
Line 1005... Line 1096...
1005
 
1096
        mov     esi, 2
Line 1022... Line 1113...
1022
 
1113
 
Line 1023... Line 1114...
1023
; End of code
1114
; End of code
Line 1024... Line 1115...
1024
 
1115
 
1025
align 4                                         ; Place all initialised data here
1116
align 4                                         ; Place all initialised data here
1026
 
1117
 
1027
devices       dd 0                              ; number of currently running devices
1118
devices         dd 0                              ; number of currently running devices
-
 
1119
version         dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
-
 
1120
my_service      db 'i8255x', 0                    ; max 16 chars include zero
-
 
1121
devicename      db 'Intel Etherexpress pro/100', 0
-
 
1122
 
Line 1028... Line 1123...
1028
version       dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1123
confcmd_data    db 22, 0x08, 0, 0, 0, 0x80, 0x32, 0x03, 1
Line 1029... Line 1124...
1029
my_service    db 'i8255x',0                     ; max 16 chars include zero
1124
                db 0, 0x2e, 0, 0x60, 0, 0xf2, 0x48, 0, 0x40, 0xf2