Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
3545 hidnplayr 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
4467 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
3545 hidnplayr 4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
6
;; i8255x (Intel eepro 100) driver for KolibriOS                   ;;
7
;;                                                                 ;;
8
;;    Written by hidnplayr@kolibrios.org                           ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
13
;; Some parts of this driver are based on the code of eepro100.c   ;;
14
;;  from linux.                                                    ;;
15
;;                                                                 ;;
16
;; Intel's programming manual for i8255x:                          ;;
17
;; http://www.intel.com/design/network/manuals/8255x_opensdm.htm   ;;
18
;;                                                                 ;;
19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20
 
21
; TODO: use separate descriptors in memory instead of placing them in front of packets!
22
 
23
 
4581 hidnplayr 24
format PE DLL native
25
entry START
3545 hidnplayr 26
 
4581 hidnplayr 27
        CURRENT_API             = 0x0200
28
        COMPATIBLE_API          = 0x0100
29
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
3545 hidnplayr 30
 
31
        MAX_DEVICES             = 16
32
 
33
        DEBUG                   = 1
34
        __DEBUG__               = 1
4582 hidnplayr 35
        __DEBUG_LEVEL__         = 2             ; 1 = verbose, 2 = errors only
3545 hidnplayr 36
 
4581 hidnplayr 37
section '.flat' readable writable executable
38
 
39
include '../proc32.inc'
4467 hidnplayr 40
include '../struct.inc'
41
include '../macros.inc'
3545 hidnplayr 42
include '../fdo.inc'
4581 hidnplayr 43
include '../netdrv_pe.inc'
3545 hidnplayr 44
 
45
; Serial EEPROM
46
 
47
EE_SK           = 1 shl 0      ; serial clock
48
EE_CS           = 1 shl 1      ; chip select
49
EE_DI           = 1 shl 2      ; data in
50
EE_DO           = 1 shl 3      ; data out
51
EE_MASK         = EE_SK + EE_CS + EE_DI + EE_DO
52
 
53
; opcodes, first bit is start bit and must be 1
54
EE_READ         = 110b
55
EE_WRITE        = 101b
56
EE_ERASE        = 111b
57
 
58
; The SCB accepts the following controls for the Tx and Rx units:
59
 
60
CU_START        = 0x0010
61
CU_RESUME       = 0x0020
62
CU_STATSADDR    = 0x0040
63
CU_SHOWSTATS    = 0x0050        ; Dump statistics counters.
64
CU_CMD_BASE     = 0x0060        ; Base address to add CU commands.
65
CU_DUMPSTATS    = 0x0070        ; Dump then reset stats counters.
66
 
67
RX_START        = 0x0001
68
RX_RESUME       = 0x0002
69
RX_ABORT        = 0x0004
70
RX_ADDR_LOAD    = 0x0006
71
RX_RESUMENR     = 0x0007
72
INT_MASK        = 0x0100
73
DRVR_INT        = 0x0200        ; Driver generated interrupt
74
 
75
CmdIASetup      = 0x0001
76
CmdConfigure    = 0x0002
77
CmdTx           = 0x0004
78
CmdTxFlex       = 0x0008
79
Cmdsuspend      = 0x4000
80
 
81
reg_scb_status  = 0
82
reg_scb_cmd     = 2
83
reg_scb_ptr     = 4
84
reg_port        = 8
85
reg_eeprom      = 14
86
reg_mdi_ctrl    = 16
87
 
4581 hidnplayr 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
3545 hidnplayr 98
 
4581 hidnplayr 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
187
 
188
ends
189
 
3545 hidnplayr 190
macro delay {
191
        push    eax
192
        in      ax, dx
193
        in      ax, dx
194
        in      ax, dx
195
        in      ax, dx
196
        in      ax, dx
197
        in      ax, dx
198
        in      ax, dx
199
        in      ax, dx
200
        in      ax, dx
201
        in      ax, dx
202
        pop     eax
203
}
204
 
205
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
206
;;                        ;;
207
;; proc START             ;;
208
;;                        ;;
209
;; (standard driver proc) ;;
210
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
211
 
4581 hidnplayr 212
proc START c, state:dword
3545 hidnplayr 213
 
214
        cmp [state], 1
215
        jne .exit
216
 
217
  .entry:
218
 
3845 hidnplayr 219
        DEBUGF 1,"Loading driver\n"
4581 hidnplayr 220
        invoke  RegService, my_service, service_proc
3545 hidnplayr 221
        ret
222
 
223
  .fail:
224
  .exit:
225
        xor eax, eax
226
        ret
227
 
228
endp
229
 
230
 
231
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
232
;;                        ;;
233
;; proc SERVICE_PROC      ;;
234
;;                        ;;
235
;; (standard driver proc) ;;
236
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
237
 
238
align 4
239
proc service_proc stdcall, ioctl:dword
240
 
241
        mov     edx, [ioctl]
4470 hidnplayr 242
        mov     eax, [edx + IOCTL.io_code]
3545 hidnplayr 243
 
244
;------------------------------------------------------
245
 
246
        cmp     eax, 0 ;SRV_GETVERSION
247
        jne     @F
248
 
4470 hidnplayr 249
        cmp     [edx + IOCTL.out_size], 4
3545 hidnplayr 250
        jb      .fail
4470 hidnplayr 251
        mov     eax, [edx + IOCTL.output]