Subversion Repositories Kolibri OS

Rev

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

Rev 1514 Rev 1519
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                  ;;
2
;;                                                                  ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved.     ;;
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.     ;;
4
;; Distributed under terms of the GNU General Public License        ;;
4
;; Distributed under terms of the GNU General Public License        ;;
5
;;                                                                  ;;
5
;;                                                                  ;;
-
 
6
;;  PCnet32 driver for KolibriOS                                    ;;
-
 
7
;;                                                                  ;;
-
 
8
;;  Based on the PCnet32 driver for MenuetOS, by Jarek Pelczar      ;;
-
 
9
;;                                                                  ;;
6
;;          GNU GENERAL PUBLIC LICENSE                              ;;
10
;;          GNU GENERAL PUBLIC LICENSE                              ;;
7
;;             Version 2, June 1991                                 ;;
11
;;             Version 2, June 1991                                 ;;
8
;;                                                                  ;;
12
;;                                                                  ;;
9
;; Status: under construction                                       ;;
-
 
10
;;                                                                  ;;
-
 
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 12... Line -...
12
 
-
 
13
; $Revision: 1514 $
-
 
14
 
14
 
Line 15... Line 15...
15
format MS COFF
15
format MS COFF
-
 
16
 
-
 
17
	API_VERSION		equ 0x01000100
-
 
18
	DRIVER_VERSION		equ 5
Line 16... Line 19...
16
 
19
 
17
	API_VERSION		equ 0x01000100
20
	MAX_DEVICES		equ 16
18
 
21
 
Line 19... Line -...
19
	DEBUG			equ 1
-
 
20
	__DEBUG__		equ 1
-
 
Line 21... Line 22...
21
	__DEBUG_LEVEL__ 	equ 1
22
	DEBUG			equ 1
22
 
23
	__DEBUG__		equ 1
23
MAX_PCNET equ 4
24
	__DEBUG_LEVEL__ 	equ 1
24
MAX_ETH_FRAME_SIZE equ 1514
25
 
Line 25... Line -...
25
 
-
 
26
include 'proc32.inc'
-
 
27
include 'imports.inc'
-
 
28
include 'fdo.inc'
-
 
29
include 'netdrv.inc'
-
 
30
 
26
 
31
 
27
include 'proc32.inc'
32
OS_BASE 	equ 0
28
include 'imports.inc'
Line 152... Line 148...
152
end virtual
148
end virtual
Line 153... Line 149...
153
 
149
 
Line 154... Line -...
154
 
-
 
155
; PCI Bus defines
-
 
156
 
-
 
157
	PCI_HEADER_TYPE 	      equ 0x0e	;8 bit
-
 
158
	PCI_BASE_ADDRESS_0	      equ 0x10	;32 bit
-
 
159
	PCI_BASE_ADDRESS_5	      equ 0x24	;32 bits
-
 
160
	PCI_BASE_ADDRESS_SPACE_IO     equ 0x01
-
 
161
	PCI_VENDOR_ID		      equ 0x00	;16 bit
150
 
162
	PCI_BASE_ADDRESS_IO_MASK      equ 0xFFFFFFFC
151
; PCI Bus defines
163
 
152
 
164
	PCNET_PORT_AUI		      equ 0x00
153
	PORT_AUI		equ 0x00
165
	PCNET_PORT_10BT 	      equ 0x01
154
	PORT_10BT		equ 0x01
166
	PCNET_PORT_GPSI 	      equ 0x02
155
	PORT_GPSI		equ 0x02
167
	PCNET_PORT_MII		      equ 0x03
156
	PORT_MII		equ 0x03
168
	PCNET_PORT_PORTSEL	      equ 0x03
157
	PORT_PORTSEL		equ 0x03
169
	PCNET_PORT_ASEL 	      equ 0x04
158
	PORT_ASEL		equ 0x04
170
	PCNET_PORT_100		      equ 0x40
159
	PORT_100		equ 0x40
171
	PCNET_PORT_FD		      equ 0x80
160
	PORT_FD 		equ 0x80
172
 
161
 
173
	PCNET_DMA_MASK		      equ 0xffffffff
162
	DMA_MASK		equ 0xffffffff
174
 
163
 
175
	PCNET_LOG_TX_BUFFERS	      equ 2
164
	LOG_TX_BUFFERS		equ 2
176
	PCNET_LOG_RX_BUFFERS	      equ 2
165
	LOG_RX_BUFFERS		equ 2
177
 
166
 
178
	PCNET_TX_RING_SIZE	      equ 4
167
	TX_RING_SIZE		equ 4
179
	PCNET_TX_RING_MOD_MASK	      equ (PCNET_TX_RING_SIZE-1)
168
	TX_RING_MOD_MASK	equ (TX_RING_SIZE-1)
180
	PCNET_TX_RING_LEN_BITS	      equ (PCNET_LOG_TX_BUFFERS shl 12)
169
	TX_RING_LEN_BITS	equ (LOG_TX_BUFFERS shl 12)
181
 
170
 
182
	PCNET_RX_RING_SIZE	      equ 4
171
	RX_RING_SIZE		equ 4
183
	PCNET_RX_RING_MOD_MASK	      equ (PCNET_RX_RING_SIZE-1)
172
	RX_RING_MOD_MASK	equ (RX_RING_SIZE-1)
184
	PCNET_RX_RING_LEN_BITS	      equ (PCNET_LOG_RX_BUFFERS shl 4)
173
	RX_RING_LEN_BITS	equ (LOG_RX_BUFFERS shl 4)
185
 
174
 
186
	PCNET_PKT_BUF_SZ	      equ 1544
175
	PKT_BUF_SZ		equ 1544
187
	PCNET_PKT_BUF_SZ_NEG	      equ 0xf9f8
176
	PKT_BUF_SZ_NEG		equ 0xf9f8
188
 
177
 
189
	PCNET_WIO_RDP		      equ 0x10
178
	WIO_RDP 		equ 0x10
190
	PCNET_WIO_RAP		      equ 0x12
179
	WIO_RAP 		equ 0x12
191
	PCNET_WIO_RESET 	      equ 0x14
180
	WIO_RESET		equ 0x14
192
	PCNET_WIO_BDP		      equ 0x16
181
	WIO_BDP 		equ 0x16
193
	PCNET_DWIO_RDP		      equ 0x10
182
	DWIO_RDP		equ 0x10
194
	PCNET_DWIO_RAP		      equ 0x14
183
	DWIO_RAP		equ 0x14
Line 195... Line 184...
195
	PCNET_DWIO_RESET	      equ 0x18
184
	DWIO_RESET		equ 0x18
Line 196... Line 185...
196
	PCNET_DWIO_BDP		      equ 0x1C
185
	DWIO_BDP		equ 0x1C
197
	PCNET_TOTAL_SIZE	      equ 0x20
186
	TOTAL_SIZE		equ 0x20
198
 
187
 
199
; CSR registers
188
; CSR registers
200
 
189
 
201
	PCNET_CSR_CSR		      equ 0x00
190
	CSR_CSR 		equ 0x00
202
	PCNET_CSR_IAB0		      equ 0x01
191
	CSR_IAB0		equ 0x01
203
	PCNET_CSR_IAB1		      equ 0x02
192
	CSR_IAB1		equ 0x02
204
	PCNET_CSR_IMR		      equ 0x03
193
	CSR_IMR 		equ 0x03
205
	PCNET_CSR_TFEAT 	      equ 0x04
194
	CSR_TFEAT		equ 0x04
206
	PCNET_CSR_EXTCTL1	      equ 0x05
195
	CSR_EXTCTL1		equ 0x05
207
	PCNET_CSR_DTBLLEN	      equ 0x06
196
	CSR_DTBLLEN		equ 0x06
208
	PCNET_CSR_EXTCTL2	      equ 0x07
197
	CSR_EXTCTL2		equ 0x07
209
	PCNET_CSR_MAR0		      equ 0x08
198
	CSR_MAR0		equ 0x08
210
	PCNET_CSR_MAR1		      equ 0x09
199
	CSR_MAR1		equ 0x09
211
	PCNET_CSR_MAR2		      equ 0x0A
200
	CSR_MAR2		equ 0x0A
212
	PCNET_CSR_MAR3		      equ 0x0B
201
	CSR_MAR3		equ 0x0B
213
	PCNET_CSR_PAR0		      equ 0x0C
202
	CSR_PAR0		equ 0x0C
214
	PCNET_CSR_PAR1		      equ 0x0D
203
	CSR_PAR1		equ 0x0D
215
	PCNET_CSR_PAR2		      equ 0x0E
204
	CSR_PAR2		equ 0x0E
216
	PCNET_CSR_MODE		      equ 0x0F
205
	CSR_MODE		equ 0x0F
217
	PCNET_CSR_RXADDR0	      equ 0x18
206
	CSR_RXADDR0		equ 0x18
218
	PCNET_CSR_RXADDR1	      equ 0x19
207
	CSR_RXADDR1		equ 0x19
219
	PCNET_CSR_TXADDR0	      equ 0x1E
208
	CSR_TXADDR0		equ 0x1E
220
	PCNET_CSR_TXADDR1	      equ 0x1F
209
	CSR_TXADDR1		equ 0x1F
221
	PCNET_CSR_TXPOLL	      equ 0x2F
210
	CSR_TXPOLL		equ 0x2F
222
	PCNET_CSR_RXPOLL	      equ 0x31
211
	CSR_RXPOLL		equ 0x31
223
	PCNET_CSR_RXRINGLEN	      equ 0x4C
212
	CSR_RXRINGLEN		equ 0x4C
224
	PCNET_CSR_TXRINGLEN	      equ 0x4E
213
	CSR_TXRINGLEN		equ 0x4E
225
	PCNET_CSR_DMACTL	      equ 0x50
214
	CSR_DMACTL		equ 0x50
226
	PCNET_CSR_BUSTIMER	      equ 0x52
215
	CSR_BUSTIMER		equ 0x52
227
	PCNET_CSR_MEMERRTIMEO	      equ 0x64
216
	CSR_MEMERRTIMEO 	equ 0x64
Line 228... Line 217...
228
	PCNET_CSR_ONNOWMISC	      equ 0x74
217
	CSR_ONNOWMISC		equ 0x74
Line 229... Line 218...
229
	PCNET_CSR_ADVFEAT	      equ 0x7A
218
	CSR_ADVFEAT		equ 0x7A
230
	PCNET_CSR_MACCFG	      equ 0x7D
219
	CSR_MACCFG		equ 0x7D
231
	PCNET_CSR_CHIPID0	      equ 0x58
220
	CSR_CHIPID0		equ 0x58
232
	PCNET_CSR_CHIPID1	      equ 0x59
221
	CSR_CHIPID1		equ 0x59
233
 
222
 
234
; Control and Status Register (CSR0)
223
; Control and Status Register (CSR0)
235
 
224
 
236
	PCNET_CSR_INIT		      equ 1 shl 0
225
	CSR_INIT		equ 1 shl 0
237
	PCNET_CSR_START 	      equ 1 shl 1
226
	CSR_START		equ 1 shl 1
238
	PCNET_CSR_STOP		      equ 1 shl 2
227
	CSR_STOP		equ 1 shl 2
239
	PCNET_CSR_TX		      equ 1 shl 3
228
	CSR_TX			equ 1 shl 3
240
	PCNET_CSR_TXON		      equ 1 shl 4
229
	CSR_TXON		equ 1 shl 4
241
	PCNET_CSR_RXON		      equ 1 shl 5
230
	CSR_RXON		equ 1 shl 5
242
	PCNET_CSR_INTEN 	      equ 1 shl 6
231
	CSR_INTEN		equ 1 shl 6
Line 243... Line 232...
243
	PCNET_CSR_INTR		      equ 1 shl 7
232
	CSR_INTR		equ 1 shl 7
Line 244... Line 233...
244
	PCNET_CSR_IDONE 	      equ 1 shl 8
233
	CSR_IDONE		equ 1 shl 8
245
	PCNET_CSR_TINT		      equ 1 shl 9
234
	CSR_TINT		equ 1 shl 9
246
	PCNET_CSR_RINT		      equ 1 shl 10
235
	CSR_RINT		equ 1 shl 10
247
	PCNET_CSR_MERR		      equ 1 shl 11
236
	CSR_MERR		equ 1 shl 11
248
	PCNET_CSR_MISS		      equ 1 shl 12
237
	CSR_MISS		equ 1 shl 12
249
	PCNET_CSR_CERR		      equ 1 shl 13
238
	CSR_CERR		equ 1 shl 13
250
 
239
 
251
; Interrupt masks and deferral control (CSR3)
240
; Interrupt masks and deferral control (CSR3)
252
 
241
 
253
	PCNET_IMR_BSWAP 	      equ 0x0004
242
	IMR_BSWAP		equ 0x0004
Line 254... Line 243...
254
	PCNET_IMR_ENMBA 	      equ 0x0008  ; enable modified backoff alg
243
	IMR_ENMBA		equ 0x0008  ; enable modified backoff alg
Line 255... Line 244...
255
	PCNET_IMR_DXMT2PD	      equ 0x0010
244
	IMR_DXMT2PD		equ 0x0010
Line 256... Line 245...
256
	PCNET_IMR_LAPPEN	      equ 0x0020  ; lookahead packet processing enb
245
	IMR_LAPPEN		equ 0x0020  ; lookahead packet processing enb
257
	PCNET_IMR_DXSUFLO	      equ 0x0040  ; disable TX stop on underflow
246
	IMR_DXSUFLO		equ 0x0040  ; disable TX stop on underflow
258
	PCNET_IMR_IDONE 	      equ 0x0100
247
	IMR_IDONE		equ 0x0100
259
	PCNET_IMR_TINT		      equ 0x0200
248
	IMR_TINT		equ 0x0200
260
	PCNET_IMR_RINT		      equ 0x0400
249
	IMR_RINT		equ 0x0400
261
	PCNET_IMR_MERR		      equ 0x0800
250
	IMR_MERR		equ 0x0800
262
	PCNET_IMR_MISS		      equ 0x1000
251
	IMR_MISS		equ 0x1000
263
 
252
 
264
	PCNET_IMR		      equ PCNET_IMR_TINT+PCNET_IMR_RINT+PCNET_IMR_IDONE+PCNET_IMR_MERR+PCNET_IMR_MISS
253
	IMR			equ IMR_TINT+IMR_RINT+IMR_IDONE+IMR_MERR+IMR_MISS
265
 
254
 
266
; Test and features control (CSR4)
255
; Test and features control (CSR4)
267
 
256
 
Line 268... Line 257...
268
	PCNET_TFEAT_TXSTRTMASK	      equ 0x0004
257
	TFEAT_TXSTRTMASK	equ 0x0004
Line 269... Line 258...
269
	PCNET_TFEAT_TXSTRT	      equ 0x0008
258
	TFEAT_TXSTRT		equ 0x0008
270
	PCNET_TFEAT_RXCCOFLOWM	      equ 0x0010  ; Rx collision counter oflow
259
	TFEAT_RXCCOFLOWM	equ 0x0010  ; Rx collision counter oflow
271
	PCNET_TFEAT_RXCCOFLOW	      equ 0x0020
260
	TFEAT_RXCCOFLOW 	equ 0x0020
272
	PCNET_TFEAT_UINT	      equ 0x0040
261
	TFEAT_UINT		equ 0x0040
273
	PCNET_TFEAT_UINTREQ	      equ 0x0080
262
	TFEAT_UINTREQ		equ 0x0080
274
	PCNET_TFEAT_MISSOFLOWM	      equ 0x0100
263
	TFEAT_MISSOFLOWM	equ 0x0100
275
	PCNET_TFEAT_MISSOFLOW	      equ 0x0200
264
	TFEAT_MISSOFLOW 	equ 0x0200
276
	PCNET_TFEAT_STRIP_FCS	      equ 0x0400
265
	TFEAT_STRIP_FCS 	equ 0x0400
277
	PCNET_TFEAT_PAD_TX	      equ 0x0800
266
	TFEAT_PAD_TX		equ 0x0800
278
	PCNET_TFEAT_TXDPOLL	      equ 0x1000
267
	TFEAT_TXDPOLL		equ 0x1000
279
	PCNET_TFEAT_DMAPLUS	      equ 0x4000
268
	TFEAT_DMAPLUS		equ 0x4000
280
 
269
 
Line 281... Line 270...
281
; Extended control and interrupt 1 (CSR5)
270
; Extended control and interrupt 1 (CSR5)
Line 282... Line 271...
282
 
271
 
283
	PCNET_EXTCTL1_SPND	      equ 0x0001  ; suspend
272
	EXTCTL1_SPND		equ 0x0001  ; suspend
Line 284... Line 273...
284
	PCNET_EXTCTL1_MPMODE	      equ 0x0002  ; magic packet mode
273
	EXTCTL1_MPMODE		equ 0x0002  ; magic packet mode
Line 285... Line 274...
285
	PCNET_EXTCTL1_MPENB	      equ 0x0004  ; magic packet enable
274
	EXTCTL1_MPENB		equ 0x0004  ; magic packet enable
286
	PCNET_EXTCTL1_MPINTEN	      equ 0x0008  ; magic packet interrupt enable
275
	EXTCTL1_MPINTEN 	equ 0x0008  ; magic packet interrupt enable
287
	PCNET_EXTCTL1_MPINT	      equ 0x0010  ; magic packet interrupt
276
	EXTCTL1_MPINT		equ 0x0010  ; magic packet interrupt
288
	PCNET_EXTCTL1_MPPLBA	      equ 0x0020  ; magic packet phys. logical bcast
277
	EXTCTL1_MPPLBA		equ 0x0020  ; magic packet phys. logical bcast
289
	PCNET_EXTCTL1_EXDEFEN	      equ 0x0040  ; excessive deferral interrupt enb.
278
	EXTCTL1_EXDEFEN 	equ 0x0040  ; excessive deferral interrupt enb.
290
	PCNET_EXTCTL1_EXDEF	      equ 0x0080  ; excessive deferral interrupt
279
	EXTCTL1_EXDEF		equ 0x0080  ; excessive deferral interrupt
291
	PCNET_EXTCTL1_SINTEN	      equ 0x0400  ; system interrupt enable
280
	EXTCTL1_SINTEN		equ 0x0400  ; system interrupt enable
292
	PCNET_EXTCTL1_SINT	      equ 0x0800  ; system interrupt
281
	EXTCTL1_SINT		equ 0x0800  ; system interrupt
293
	PCNET_EXTCTL1_LTINTEN	      equ 0x4000  ; last TX interrupt enb
282
	EXTCTL1_LTINTEN 	equ 0x4000  ; last TX interrupt enb
294
	PCNET_EXTCTL1_TXOKINTD	      equ 0x8000  ; TX OK interrupt disable
283
	EXTCTL1_TXOKINTD	equ 0x8000  ; TX OK interrupt disable
295
 
284
 
296
; RX/TX descriptor len (CSR6)
285
; RX/TX descriptor len (CSR6)
297
 
286
 
298
	PCNET_DTBLLEN_RLEN	      equ 0x0F00
287
	DTBLLEN_RLEN		equ 0x0F00
299
	PCNET_DTBLLEN_TLEN	      equ 0xF000
288
	DTBLLEN_TLEN		equ 0xF000
300
 
289
 
Line 301... Line 290...
301
; Extended control and interrupt 2 (CSR7)
290
; Extended control and interrupt 2 (CSR7)
Line 302... Line 291...
302
 
291
 
303
	PCNET_EXTCTL2_MIIPDTINTE      equ 0x0001
292
	EXTCTL2_MIIPDTINTE	equ 0x0001
304
	PCNET_EXTCTL2_MIIPDTINT       equ 0x0002
293
	EXTCTL2_MIIPDTINT	equ 0x0002
305
	PCNET_EXTCTL2_MCCIINTE	      equ 0x0004
294
	EXTCTL2_MCCIINTE	equ 0x0004
306
	PCNET_EXTCTL2_MCCIINT	      equ 0x0008
295
	EXTCTL2_MCCIINT 	equ 0x0008
307
	PCNET_EXTCTL2_MCCINTE	      equ 0x0010
296
	EXTCTL2_MCCINTE 	equ 0x0010
308
	PCNET_EXTCTL2_MCCINT	      equ 0x0020
297
	EXTCTL2_MCCINT		equ 0x0020
309
	PCNET_EXTCTL2_MAPINTE	      equ 0x0040
298
	EXTCTL2_MAPINTE 	equ 0x0040
310
	PCNET_EXTCTL2_MAPINT	      equ 0x0080
299
	EXTCTL2_MAPINT		equ 0x0080
311
	PCNET_EXTCTL2_MREINTE	      equ 0x0100
300
	EXTCTL2_MREINTE 	equ 0x0100
312
	PCNET_EXTCTL2_MREINT	      equ 0x0200
301
	EXTCTL2_MREINT		equ 0x0200
Line 313... Line 302...
313
	PCNET_EXTCTL2_STINTE	      equ 0x0400
302
	EXTCTL2_STINTE		equ 0x0400
Line 314... Line 303...
314
	PCNET_EXTCTL2_STINT	      equ 0x0800
303
	EXTCTL2_STINT		equ 0x0800
315
	PCNET_EXTCTL2_RXDPOLL	      equ 0x1000
304
	EXTCTL2_RXDPOLL 	equ 0x1000
316
	PCNET_EXTCTL2_RDMD	      equ 0x2000
305
	EXTCTL2_RDMD		equ 0x2000
317
	PCNET_EXTCTL2_RXFRTG	      equ 0x4000
306
	EXTCTL2_RXFRTG		equ 0x4000
318
	PCNET_EXTCTL2_FASTSPNDE       equ 0x8000
307
	EXTCTL2_FASTSPNDE	equ 0x8000
319
 
308
 
320
; Mode (CSR15)
309
; Mode (CSR15)
321
 
310
 
322
	PCNET_MODE_RXD		      equ 0x0001  ; RX disable
311
	MODE_RXD		equ 0x0001  ; RX disable
323
	PCNET_MODE_TXD		      equ 0x0002  ; TX disable
312
	MODE_TXD		equ 0x0002  ; TX disable
324
	PCNET_MODE_LOOP 	      equ 0x0004  ; loopback enable
313
	MODE_LOOP		equ 0x0004  ; loopback enable
325
	PCNET_MODE_TXCRCD	      equ 0x0008
314
	MODE_TXCRCD		equ 0x0008
326
	PCNET_MODE_FORCECOLL	      equ 0x0010
315
	MODE_FORCECOLL		equ 0x0010
327
	PCNET_MODE_RETRYD	      equ 0x0020
316
	MODE_RETRYD		equ 0x0020
328
	PCNET_MODE_INTLOOP	      equ 0x0040
317
	MODE_INTLOOP		equ 0x0040
329
	PCNET_MODE_PORTSEL	      equ 0x0180
318
	MODE_PORTSEL		equ 0x0180
330
	PCNET_MODE_RXVPAD	      equ 0x2000
319
	MODE_RXVPAD		equ 0x2000
331
	PCNET_MODE_RXNOBROAD	      equ 0x4000
320
	MODE_RXNOBROAD		equ 0x4000
332
	PCNET_MODE_PROMISC	      equ 0x8000
321
	MODE_PROMISC		equ 0x8000
333
 
322
 
334
; BCR (Bus Control Registers)
323
; BCR (Bus Control Registers)
335
 
324
 
336
	PCNET_BCR_MMRA		      equ 0x00	  ; Master Mode Read Active
325
	BCR_MMRA		equ 0x00    ; Master Mode Read Active
337
	PCNET_BCR_MMW		      equ 0x01	  ; Master Mode Write Active
326
	BCR_MMW 		equ 0x01    ; Master Mode Write Active
338
	PCNET_BCR_MISCCFG	      equ 0x02
327
	BCR_MISCCFG		equ 0x02
339
	PCNET_BCR_LED0		      equ 0x04
328
	BCR_LED0		equ 0x04
340
	PCNET_BCR_LED1		      equ 0x05
329
	BCR_LED1		equ 0x05
341
	PCNET_BCR_LED2		      equ 0x06
330
	BCR_LED2		equ 0x06
342
	PCNET_BCR_LED3		      equ 0x07
331
	BCR_LED3		equ 0x07
343
	PCNET_BCR_DUPLEX	      equ 0x09
332
	BCR_DUPLEX		equ 0x09
344
	PCNET_BCR_BUSCTL	      equ 0x12
333
	BCR_BUSCTL		equ 0x12
345
	PCNET_BCR_EECTL 	      equ 0x13
334
	BCR_EECTL		equ 0x13
346
	PCNET_BCR_SSTYLE	      equ 0x14
335
	BCR_SSTYLE		equ 0x14
347
	PCNET_BCR_PCILAT	      equ 0x16
336
	BCR_PCILAT		equ 0x16
Line 348... Line 337...
348
	PCNET_BCR_PCISUBVENID	      equ 0x17
337
	BCR_PCISUBVENID 	equ 0x17
Line 349... Line 338...
349
	PCNET_BCR_PCISUBSYSID	      equ 0x18
338
	BCR_PCISUBSYSID 	equ 0x18
350
	PCNET_BCR_SRAMSIZE	      equ 0x19
339
	BCR_SRAMSIZE		equ 0x19
351
	PCNET_BCR_SRAMBOUND	      equ 0x1A
340
	BCR_SRAMBOUND		equ 0x1A
352
	PCNET_BCR_SRAMCTL	      equ 0x1B
341
	BCR_SRAMCTL		equ 0x1B
353
	PCNET_BCR_MIICTL	      equ 0x20
342
	BCR_MIICTL		equ 0x20
354
	PCNET_BCR_MIIADDR	      equ 0x21
343
	BCR_MIIADDR		equ 0x21
355
	PCNET_BCR_MIIDATA	      equ 0x22
344
	BCR_MIIDATA		equ 0x22
356
	PCNET_BCR_PCIVENID	      equ 0x23
345
	BCR_PCIVENID		equ 0x23
357
	PCNET_BCR_PCIPCAP	      equ 0x24
346
	BCR_PCIPCAP		equ 0x24
Line 358... Line 347...
358
	PCNET_BCR_DATA0 	      equ 0x25
347
	BCR_DATA0		equ 0x25
Line 359... Line 348...
359
	PCNET_BCR_DATA1 	      equ 0x26
348
	BCR_DATA1		equ 0x26
360
	PCNET_BCR_DATA2 	      equ 0x27
349
	BCR_DATA2		equ 0x27
361
	PCNET_BCR_DATA3 	      equ 0x28
350
	BCR_DATA3		equ 0x28
362
	PCNET_BCR_DATA4 	      equ 0x29
351
	BCR_DATA4		equ 0x29
363
	PCNET_BCR_DATA5 	      equ 0x2A
352
	BCR_DATA5		equ 0x2A
364
	PCNET_BCR_DATA6 	      equ 0x2B
353
	BCR_DATA6		equ 0x2B
365
	PCNET_BCR_DATA7 	      equ 0x2C
354
	BCR_DATA7		equ 0x2C
366
	PCNET_BCR_ONNOWPAT0	      equ 0x2D
355
	BCR_ONNOWPAT0		equ 0x2D
367
	PCNET_BCR_ONNOWPAT1	      equ 0x2E
356
	BCR_ONNOWPAT1		equ 0x2E
368
	PCNET_BCR_ONNOWPAT2	      equ 0x2F
357
	BCR_ONNOWPAT2		equ 0x2F
369
	PCNET_BCR_PHYSEL	      equ 0x31
358
	BCR_PHYSEL		equ 0x31
370
 
359
 
371
; RX status register
360
; RX status register
372
 
361
 
373
	PCNET_RXSTAT_BPE	      equ 0x0080  ; bus parity error
362
	RXSTAT_BPE		equ 0x0080  ; bus parity error
374
	PCNET_RXSTAT_ENP	      equ 0x0100  ; end of packet
363
	RXSTAT_ENP		equ 0x0100  ; end of packet
375
	PCNET_RXSTAT_STP	      equ 0x0200  ; start of packet
364
	RXSTAT_STP		equ 0x0200  ; start of packet
376
	PCNET_RXSTAT_BUFF	      equ 0x0400  ; buffer error
365
	RXSTAT_BUFF		equ 0x0400  ; buffer error
377
	PCNET_RXSTAT_CRC	      equ 0x0800  ; CRC error
366
	RXSTAT_CRC		equ 0x0800  ; CRC error
378
	PCNET_RXSTAT_OFLOW	      equ 0x1000  ; rx overrun
-
 
Line -... Line 367...
-
 
367
	RXSTAT_OFLOW		equ 0x1000  ; rx overrun
Line 379... Line 368...
379
	PCNET_RXSTAT_FRAM	      equ 0x2000  ; framing error
368
	RXSTAT_FRAM		equ 0x2000  ; framing error
Line 380... Line 369...
380
	PCNET_RXSTAT_ERR	      equ 0x4000  ; error summary
369
	RXSTAT_ERR		equ 0x4000  ; error summary
Line 472... Line 461...
472
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
461
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
473
	jne	.fail					; other types arent supported for this card yet
462
	jne	.fail					; other types arent supported for this card yet
Line 474... Line 463...
474
 
463
 
Line 475... Line 464...
475
; check if the device is already listed
464
; check if the device is already listed
476
 
465
 
477
	mov	ecx, [PCNET_DEV]
466
	mov	ecx, [devices]
Line 478... Line 467...
478
	test	ecx, ecx
467
	test	ecx, ecx
479
	jz	.firstdevice
468
	jz	.firstdevice
480
 
469
 
481
	mov	esi, PCNET_LIST
470
	mov	esi, device_list
482
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
471
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
483
	mov	ax , [eax+1]				;
472
	mov	ax , [eax+1]				;
Line 489... Line 478...
489
	loop	.nextdevice
478
	loop	.nextdevice
Line 490... Line 479...
490
 
479
 
Line 491... Line 480...
491
; This device doesnt have its own eth_device structure yet, lets create one
480
; This device doesnt have its own eth_device structure yet, lets create one
492
 
481
 
493
  .firstdevice:
482
  .firstdevice:
Line 494... Line 483...
494
	cmp	[PCNET_DEV], MAX_PCNET			; First check if the driver can handle one more card
483
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
495
	jge	.fail
484
	jge	.fail
496
 
485
 
Line 527... Line 516...
527
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
516
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
Line 528... Line 517...
528
 
517
 
529
	DEBUGF	1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
518
	DEBUGF	1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
Line 530... Line 519...
530
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
519
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
531
 
520
 
532
	allocate_and_clear [device.tx_buffer], (PCNET_RX_RING_SIZE * PCNET_PKT_BUF_SZ), .err
521
;;;        allocate_and_clear [device.tx_buffer], (RX_RING_SIZE * PKT_BUF_SZ), .err
Line 533... Line 522...
533
	allocate_and_clear [device.rx_buffer], (PCNET_TX_RING_SIZE * PCNET_PKT_BUF_SZ), .err
522
	allocate_and_clear [device.rx_buffer], (TX_RING_SIZE * PKT_BUF_SZ), .err
534
	allocate_and_clear [device.rx_ring], (PCNET_RX_RING_SIZE * buf_head.size), .err
523
	allocate_and_clear [device.rx_ring], (RX_RING_SIZE * buf_head.size), .err
535
 
524
 
Line 536... Line 525...
536
	mov	eax, [device.rx_ring]
525
	mov	eax, [device.rx_ring]
Line 537... Line 526...
537
	call	GetPgAddr
526
	call	GetPgAddr
538
	mov	[device.rx_ring_phys], eax
527
	mov	[device.rx_ring_phys], eax
539
 
528
 
Line 540... Line 529...
540
	allocate_and_clear [device.tx_ring], (PCNET_TX_RING_SIZE * buf_head.size), .err
529
	allocate_and_clear [device.tx_ring], (TX_RING_SIZE * buf_head.size), .err
541
 
530
 
542
	mov	eax, [device.tx_ring]
531
	mov	eax, [device.tx_ring]
543
	call	GetPgAddr
532
	call	GetPgAddr
544
	mov	[device.tx_ring_phys], eax
533
	mov	[device.tx_ring_phys], eax
Line 545... Line 534...
545
 
534
 
546
; Ok, the eth_device structure is ready, let's probe the device
535
; Ok, the eth_device structure is ready, let's probe the device
547
; Because initialization fires IRQ, IRQ handler must be aware of this device
536
; Because initialization fires IRQ, IRQ handler must be aware of this device
Line 574... Line 563...
574
 
563
 
Line 575... Line 564...
575
; If an error occured, remove all allocated data and exit (returning -1 in eax)
564
; If an error occured, remove all allocated data and exit (returning -1 in eax)
576
 
565
 
577
  .destroy:
566
  .destroy:
578
	; todo: reset device into virgin state
567
	; todo: reset device into virgin state
579
	dec	[PCNET_DEV]
568
	dec	[devices]
580
  .err:
569
  .err:
581
	DEBUGF	1,"Error, removing all data !\n"
570
	DEBUGF	1,"Error, removing all data !\n"
582
	stdcall KernelFree, [device.rx_buffer]
571
	stdcall KernelFree, [device.rx_buffer]
Line 583... Line 572...
583
	stdcall KernelFree, [device.tx_buffer]
572
;;;        stdcall KernelFree, [device.tx_buffer]
584
	stdcall KernelFree, ebx
573
	stdcall KernelFree, ebx
585
 
574
 
Line 624... Line 613...
624
	make_bus_master [device.pci_bus], [device.pci_dev]
613
	make_bus_master [device.pci_bus], [device.pci_dev]
Line 625... Line 614...
625
 
614
 
Line 626... Line 615...
626
; first, fill in some of the structure variables
615
; first, fill in some of the structure variables
627
 
616
 
628
	mov	edi, [device.rx_ring]
617
	mov	edi, [device.rx_ring]
629
	mov	ecx, PCNET_RX_RING_SIZE
618
	mov	ecx, RX_RING_SIZE
630
	mov	eax, [device.rx_buffer]
619
	mov	eax, [device.rx_buffer]
631
	call	GetPgAddr
620
	call	GetPgAddr
632
  .rx_init:
621
  .rx_init:
633
	mov	[edi + buf_head.base], eax
622
	mov	[edi + buf_head.base], eax
634
	mov	[edi + buf_head.length], PCNET_PKT_BUF_SZ_NEG
623
	mov	[edi + buf_head.length], PKT_BUF_SZ_NEG
635
	mov	[edi + buf_head.status], 0x8000
624
	mov	[edi + buf_head.status], 0x8000
636
	and	dword [edi + buf_head.msg_length], 0
625
	and	dword [edi + buf_head.msg_length], 0
637
	and	dword [edi + buf_head.reserved], 0
626
	and	dword [edi + buf_head.reserved], 0
638
	add	eax, PCNET_PKT_BUF_SZ
627
	add	eax, PKT_BUF_SZ
639
;        inc     eax
628
;        inc     eax
Line 640... Line 629...
640
	add	 edi, buf_head.size
629
	add	 edi, buf_head.size
641
	loop	 .rx_init
630
	loop	 .rx_init
642
 
631
 
643
	mov	edi, [device.tx_ring]
632
	mov	edi, [device.tx_ring]
644
	mov	ecx, PCNET_TX_RING_SIZE
633
	mov	ecx, TX_RING_SIZE
645
	mov	eax, [device.tx_buffer]
634
	mov	eax, [device.tx_buffer]
646
	call	GetPgAddr
635
	call	GetPgAddr
647
  .tx_init:
636
  .tx_init:
648
	mov	[edi + buf_head.base], eax
637
	mov	[edi + buf_head.base], eax
649
	and	dword [edi + buf_head.length], 0
638
	and	dword [edi + buf_head.length], 0
650
	and	dword [edi + buf_head.msg_length], 0
639
	and	dword [edi + buf_head.msg_length], 0
651
	and	dword [edi + buf_head.reserved], 0
640
	and	dword [edi + buf_head.reserved], 0
Line 652... Line 641...
652
	add	eax, PCNET_PKT_BUF_SZ
641
	add	eax, PKT_BUF_SZ
Line 653... Line 642...
653
	add	edi, buf_head.size
642
	add	edi, buf_head.size
654
	loop	.tx_init
643
	loop	.tx_init
655
 
644
 
656
	mov	[device.tlen_rlen], (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS)
645
	mov	[device.tlen_rlen], (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
Line 665... Line 654...
665
	cmp	eax, 4
654
	cmp	eax, 4
666
	jne	.try_dwio
655
	jne	.try_dwio
Line 667... Line 656...
667
 
656
 
668
	; Try Word I/O
657
	; Try Word I/O
669
	mov	ax , 88
658
	mov	ax , 88
670
	add	edx, PCNET_WIO_RAP
659
	add	edx, WIO_RAP
671
	out	dx , ax
660
	out	dx , ax
672
	nop
661
	nop
673
	nop
662
	nop
674
	in	ax , dx
663
	in	ax , dx
675
	sub	edx, PCNET_WIO_RAP
664
	sub	edx, WIO_RAP
676
	cmp	ax , 88
665
	cmp	ax , 88
Line 677... Line 666...
677
	jne	.try_dwio
666
	jne	.try_dwio
Line 690... Line 679...
690
	call	dwio_read_csr
679
	call	dwio_read_csr
691
	cmp	eax, 4
680
	cmp	eax, 4
692
	jne	.no_dev
681
	jne	.no_dev
Line 693... Line 682...
693
 
682
 
694
	; Try Dword I/O
683
	; Try Dword I/O
695
	set_io	PCNET_DWIO_RAP
684
	set_io	DWIO_RAP
696
	mov	eax, 88
685
	mov	eax, 88
697
	out	dx , eax
686
	out	dx , eax
698
	nop
687
	nop
699
	nop
688
	nop
Line 713... Line 702...
713
	DEBUGF 1,"PCnet device not found!\n"
702
	DEBUGF 1,"PCnet device not found!\n"
714
	mov	eax, 1
703
	mov	eax, 1
715
	ret
704
	ret
716
  .L1:
705
  .L1:
Line 717... Line 706...
717
 
706
 
718
	mov	ecx, PCNET_CSR_CHIPID0
707
	mov	ecx, CSR_CHIPID0
719
	call	[device.access_read_csr]
708
	call	[device.access_read_csr]
Line 720... Line 709...
720
	mov	esi, eax
709
	mov	esi, eax
721
 
710
 
722
	mov	ecx, PCNET_CSR_CHIPID1
711
	mov	ecx, CSR_CHIPID1
723
	call	[device.access_read_csr]
712
	call	[device.access_read_csr]
Line 724... Line 713...
724
	shl	eax, 16
713
	shl	eax, 16
Line 788... Line 777...
788
	mov	[device.mii], 1
777
	mov	[device.mii], 1
789
	jmp	.L10
778
	jmp	.L10
790
  .L8:
779
  .L8:
791
	mov	[device.name], device_l8
780
	mov	[device.name], device_l8
792
;        mov     [device.fdx], 1
781
;        mov     [device.fdx], 1
793
	mov	ecx, PCNET_CSR_RXPOLL
782
	mov	ecx, CSR_RXPOLL
794
	call	[device.access_read_bcr]
783
	call	[device.access_read_bcr]
795
	call	[device.access_write_bcr]
784
	call	[device.access_write_bcr]
796
	jmp	.L10
785
	jmp	.L10
797
  .L9:
786
  .L9:
798
	mov	[device.name], device_l9
787
	mov	[device.name], device_l9
Line 801... Line 790...
801
  .L10:
790
  .L10:
802
	DEBUGF 1,"device name: %s\n",[device.name]
791
	DEBUGF 1,"device name: %s\n",[device.name]
Line 803... Line 792...
803
 
792
 
804
	cmp	[device.fset], 1
793
	cmp	[device.fset], 1
805
	jne	.L11
794
	jne	.L11
806
	mov	ecx, PCNET_BCR_BUSCTL
795
	mov	ecx, BCR_BUSCTL
807
	call	[device.access_read_bcr]
796
	call	[device.access_read_bcr]
808
	or	eax, 0x800
797
	or	eax, 0x800
Line 809... Line 798...
809
	call	[device.access_write_bcr]
798
	call	[device.access_write_bcr]
810
 
799
 
811
	mov	ecx, PCNET_CSR_DMACTL
800
	mov	ecx, CSR_DMACTL
812
	call	[device.access_read_csr]
801
	call	[device.access_read_csr]
813
;        and     eax, 0xc00
802
;        and     eax, 0xc00
814
;        or      eax, 0xc00
803
;        or      eax, 0xc00
Line 818... Line 807...
818
	mov	[device.dxsuflo],1
807
	mov	[device.dxsuflo],1
819
	mov	[device.ltint],1
808
	mov	[device.ltint],1
820
  .L11:
809
  .L11:
Line 821... Line 810...
821
 
810
 
822
	DEBUGF 1,"PCI done\n"
811
	DEBUGF 1,"PCI done\n"
823
	mov	eax, PCNET_PORT_ASEL
812
	mov	eax, PORT_ASEL
824
	mov	[device.options], eax
813
	mov	[device.options], eax
825
	mov	[device.mode_], word 0x0003
814
	mov	[device.mode_], word 0x0003
Line 826... Line 815...
826
	mov	[device.tlen_rlen], word (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS)
815
	mov	[device.tlen_rlen], word (TX_RING_LEN_BITS or RX_RING_LEN_BITS)
827
 
816
 
Line 828... Line 817...
828
	mov	dword [device.filter], 0
817
	mov	dword [device.filter], 0
829
	mov	dword [device.filter+4], 0
818
	mov	dword [device.filter+4], 0
830
 
819
 
Line 856... Line 845...
856
 
845
 
Line 857... Line 846...
857
; Switch to dword operations
846
; Switch to dword operations
Line 858... Line 847...
858
 
847
 
859
	DEBUGF 1,"Switching to 32-bit mode\n"
848
	DEBUGF 1,"Switching to 32-bit mode\n"
860
 
849
 
Line 861... Line 850...
861
	mov	ecx, PCNET_DWIO_RDP
850
	mov	ecx, DWIO_RDP
Line 862... Line 851...
862
	mov	eax, 0
851
	mov	eax, 0
Line 863... Line 852...
863
	call	wio_write_csr
852
	call	wio_write_csr
864
 
853
 
865
	call	switch_to_dwio
854
	call	switch_to_dwio
866
 
855
 
867
; Lets find out if we are really in 32-bit mode now..
856
; Lets find out if we are really in 32-bit mode now..
868
 
857
 
869
	set_io	0
858
	set_io	0
Line 883... Line 872...
883
	call	[device.access_reset]
872
	call	[device.access_reset]
Line 884... Line 873...
884
 
873
 
Line 885... Line 874...
885
  .yes_dwio:
874
  .yes_dwio:
886
 
875
 
887
	; set/reset autoselect bit
876
	; set/reset autoselect bit
888
	mov	ecx, PCNET_BCR_MISCCFG
877
	mov	ecx, BCR_MISCCFG
889
	call	[device.access_read_bcr]
878
	call	[device.access_read_bcr]
890
	and	eax,not 2
879
	and	eax,not 2
891
	test	[device.options], PCNET_PORT_ASEL
880
	test	[device.options], PORT_ASEL
892
	jz	.L1
881
	jz	.L1
893
	or	eax, 2
882
	or	eax, 2
Line 894... Line 883...
894
  .L1:
883
  .L1:
895
	call	[device.access_write_bcr]
884
	call	[device.access_write_bcr]
896
 
885
 
897
 
886
 
898
	; Handle full duplex setting
887
	; Handle full duplex setting
899
	cmp	byte [device.full_duplex], 0
888
	cmp	byte [device.full_duplex], 0
900
	je	.L2
889
	je	.L2
901
	mov	ecx, PCNET_BCR_DUPLEX
890
	mov	ecx, BCR_DUPLEX
902
	call	[device.access_read_bcr]
891
	call	[device.access_read_bcr]
903
	and	eax, not 3
892
	and	eax, not 3
904
	test	[device.options], PCNET_PORT_FD
893
	test	[device.options], PORT_FD
905
	jz	.L3
894
	jz	.L3
906
	or	eax, 1
895
	or	eax, 1
907
	cmp	[device.options], PCNET_PORT_FD or PCNET_PORT_AUI
896
	cmp	[device.options], PORT_FD or PORT_AUI
908
	jne	.L4
897
	jne	.L4
909
	or	eax, 2
898
	or	eax, 2
910
	jmp	.L4
899
	jmp	.L4
911
  .L3:
900
  .L3:
912
	test	[device.options], PCNET_PORT_ASEL
901
	test	[device.options], PORT_ASEL
913
	jz	.L4
902
	jz	.L4
914
	cmp	[device.chip_version], 0x2627
903
	cmp	[device.chip_version], 0x2627
915
	jne	.L4
904
	jne	.L4
916
	or	eax, 3
905
	or	eax, 3
Line 917... Line 906...
917
  .L4:
906
  .L4:
918
	mov	ecx, PCNET_BCR_DUPLEX
907
	mov	ecx, BCR_DUPLEX
919
	call	[device.access_write_bcr]
908
	call	[device.access_write_bcr]
920
  .L2:
909
  .L2:
921
 
910
 
922
 
911
 
923
	; set/reset GPSI bit in test register
912
	; set/reset GPSI bit in test register
924
	mov	ecx, 124
913
	mov	ecx, 124
925
	call	[device.access_read_csr]
914
	call	[device.access_read_csr]
926
	mov	ecx, [device.options]
915
	mov	ecx, [device.options]
927
	and	ecx, PCNET_PORT_PORTSEL
916
	and	ecx, PORT_PORTSEL
928
	cmp	ecx, PCNET_PORT_GPSI
917
	cmp	ecx, PORT_GPSI
929
	jne	.L5
918
	jne	.L5
930
	or	eax, 0x10
919
	or	eax, 0x10
931
  .L5:
920
  .L5:
932
	call	[device.access_write_csr]
921
	call	[device.access_write_csr]
933
	cmp	[device.mii], 0
922
	cmp	[device.mii], 0
934
	je	.L6
923
	je	.L6
935
	test	[device.options], PCNET_PORT_ASEL
924
	test	[device.options], PORT_ASEL
936
	jnz	.L6
925
	jnz	.L6
937
	mov	ecx, PCNET_BCR_MIICTL
926
	mov	ecx, BCR_MIICTL
938
	call	[device.access_read_bcr]
927
	call	[device.access_read_bcr]
939
	and	eax,not 0x38
928
	and	eax,not 0x38
940
	test	[device.options], PCNET_PORT_FD
929
	test	[device.options], PORT_FD
941
	jz	.L7
930
	jz	.L7
942
	or	eax, 0x10
931
	or	eax, 0x10
943
  .L7:
932
  .L7:
944
	test	[device.options], PCNET_PORT_100
933
	test	[device.options], PORT_100
945
	jz	.L8
934
	jz	.L8
946
	or	eax, 0x08
935
	or	eax, 0x08
947
  .L8:
936
  .L8:
948
	call	[device.access_write_bcr]
937
	call	[device.access_write_bcr]
949
	jmp	.L9
938
	jmp	.L9
950
.L6:
939
.L6:
951
	test	[device.options], PCNET_PORT_ASEL
940
	test	[device.options], PORT_ASEL
952
	jz	.L9
941
	jz	.L9
Line 963... Line 952...
963
	call	[device.access_read_csr]
952
	call	[device.access_read_csr]
964
	or	eax,(1 shl 14)
953
	or	eax,(1 shl 14)
965
	call	[device.access_write_csr]
954
	call	[device.access_write_csr]
966
.L10:
955
.L10:
967
	mov	eax, [device.options]
956
	mov	eax, [device.options]
968
	and	eax, PCNET_PORT_PORTSEL
957
	and	eax, PORT_PORTSEL
969
	shl	eax, 7
958
	shl	eax, 7
970
	mov	[device.mode_], ax
959
	mov	[device.mode_], ax
971
	mov	dword [device.filter], -1
960
	mov	dword [device.filter], -1
972
	mov	dword [device.filter+4], -1
961
	mov	dword [device.filter+4], -1
Line 1025... Line 1014...
1025
 
1014
 
1026
	xor	ecx, ecx
1015
	xor	ecx, ecx
Line 1027... Line 1016...
1027
	call	[device.access_read_csr]
1016
	call	[device.access_read_csr]
1028
 
1017
 
1029
	xor	ecx, ecx
1018
	xor	ecx, ecx
Line 1030... Line 1019...
1030
	mov	eax, PCNET_CSR_INTEN or PCNET_CSR_START
1019
	mov	eax, CSR_INTEN or CSR_START
1031
	call	[device.access_write_csr]
1020
	call	[device.access_write_csr]
1032
 
1021
 
1033
	DEBUGF 1,"PCNET reset complete\n"
1022
	DEBUGF 1,"PCNET reset complete\n"
1034
	xor	eax, eax
1023
	xor	eax, eax
1035
; clear packet/byte counters
1024
; clear packet/byte counters
Line -... Line 1025...
-
 
1025
	lea	edi, [device.bytes_tx]
-
 
1026
	mov	ecx, 6
-
 
1027
	rep	stosd
1036
	lea	edi, [device.bytes_tx]
1028
 
Line 1066... Line 1058...
1066
	cmp	dword [esp+8], 60
1058
	cmp	dword [esp+8], 60
1067
	jl	.finish 			; packet is too short
1059
	jl	.finish 			; packet is too short
Line 1068... Line 1060...
1068
 
1060
 
1069
; check descriptor
1061
; check descriptor
1070
	movzx	eax, [device.cur_tx]
1062
	movzx	eax, [device.cur_tx]
1071
	imul	edi, eax, PCNET_PKT_BUF_SZ
1063
	imul	edi, eax, PKT_BUF_SZ
1072
	shl	eax, 4
1064
	shl	eax, 4
1073
	add	edi, [device.tx_buffer]
1065
	add	edi, [device.tx_buffer]
1074
	add	eax, [device.tx_ring]
1066
	add	eax, [device.tx_ring]
1075
	test	byte [eax + buf_head.status + 1], 80h
1067
	test	byte [eax + buf_head.status + 1], 80h
-
 
1068
	jnz	.nospace
1076
	jnz	.nospace
1069
 
1077
; descriptor is free, copy data
1070
; descriptor is free, copy data
1078
	mov	esi, [esp+4]
1071
	mov	esi, [esp+4]
1079
	mov	ecx, [esp+8]
1072
	mov	ecx, [esp+8]
1080
	mov	edx, ecx
1073
	mov	edx, ecx
1081
	shr	ecx, 2
1074
	shr	ecx, 2
1082
	and	edx, 3
1075
	and	edx, 3
1083
	rep	movsd
1076
	rep	movsd
1084
	mov	ecx, edx
1077
	mov	ecx, edx
-
 
1078
	rep	movsb
1085
	rep	movsb
1079
 
1086
; set length
1080
; set length
1087
	mov	ecx, [esp+8]
1081
	mov	ecx, [esp+8]
1088
	neg	ecx
1082
	neg	ecx
1089
	mov	[eax + buf_head.length], cx
1083
	mov	[eax + buf_head.length], cx
1090
; put to transfer queue
1084
; put to transfer queue
Line 1091... Line 1085...
1091
	mov	[eax + buf_head.status], 0x8300
1085
	mov	[eax + buf_head.status], 0x8300
1092
 
1086
 
1093
; trigger an immediate send
1087
; trigger an immediate send
1094
	xor	ecx, ecx	 ; CSR0
1088
	xor	ecx, ecx	 ; CSR0
1095
	call	[device.access_read_csr]
1089
	call	[device.access_read_csr]
Line 1096... Line 1090...
1096
	or	eax, PCNET_CSR_TX
1090
	or	eax, CSR_TX
1097
	call	[device.access_write_csr]
1091
	call	[device.access_write_csr]
1098
 
1092
 
Line 1107... Line 1101...
1107
 
1101
 
1108
	mov	ecx, [esp+8]
1102
	mov	ecx, [esp+8]
1109
	add	dword [device.bytes_tx], ecx
1103
	add	dword [device.bytes_tx], ecx
1110
	adc	dword [device.bytes_tx + 4], 0
1104
	adc	dword [device.bytes_tx + 4], 0
-
 
1105
	DEBUGF	2," - Done!\n"
-
 
1106
 
-
 
1107
	call	Kernelfree
1111
	DEBUGF	2," - Done!\n"
1108
	add	esp, 4
Line 1112... Line 1109...
1112
	ret
1109
	ret
1113
 
1110
 
1114
.nospace:
1111
.nospace:
-
 
1112
	DEBUGF	1, 'ERROR: no free transmit descriptors\n'
-
 
1113
; todo: maybe somehow notify the kernel about the error?
-
 
1114
 
1115
	DEBUGF	1, 'ERROR: no free transmit descriptors\n'
1115
	call	Kernelfree
Line 1116... Line 1116...
1116
; todo: maybe somehow notify the kernel about the error?
1116
	add	esp, 4
Line 1129... Line 1129...
1129
 
1129
 
Line 1130... Line 1130...
1130
	DEBUGF	1,"IRQ %x ", eax:2		; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
1130
	DEBUGF	1,"IRQ %x ", eax:2		; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
Line 1131... Line 1131...
1131
 
1131
 
1132
; find pointer of device wich made IRQ occur
1132
; find pointer of device wich made IRQ occur
1133
 
1133
 
1134
	mov	esi, PCNET_LIST
1134
	mov	esi, device_list
1135
	mov	ecx, [PCNET_DEV]
1135
	mov	ecx, [devices]
1136
	test	ecx, ecx
1136
	test	ecx, ecx
1137
	jz	.abort
1137
	jz	.abort
Line 1165... Line 1165...
1165
; to two or more reasons in one IRQ.
1165
; to two or more reasons in one IRQ.
1166
	xor	ecx, ecx
1166
	xor	ecx, ecx
1167
	call	[device.access_write_csr]
1167
	call	[device.access_write_csr]
1168
; Received packet ok?
1168
; Received packet ok?
Line 1169... Line 1169...
1169
 
1169
 
1170
	test	ax, PCNET_CSR_RINT
1170
	test	ax, CSR_RINT
Line 1171... Line 1171...
1171
	jz	@f
1171
	jz	@f
1172
 
1172
 
1173
.receiver_test_loop:
1173
.receiver_test_loop:
1174
	movzx	eax, [device.cur_rx]
1174
	movzx	eax, [device.cur_rx]
Line 1175... Line 1175...
1175
;        and     eax, PCNET_RX_RING_MOD_MASK
1175
;        and     eax, RX_RING_MOD_MASK
1176
	mov	edi, eax
1176
	mov	edi, eax
Line 1177... Line 1177...
1177
 
1177
 
1178
	imul	esi, eax, PCNET_PKT_BUF_SZ	;
1178
	imul	esi, eax, PKT_BUF_SZ	  ;
Line 1179... Line 1179...
1179
	add	esi, [device.rx_buffer] 	; esi now points to rx buffer
1179
	add	esi, [device.rx_buffer] 	; esi now points to rx buffer
Line 1180... Line 1180...
1180
 
1180
 
1181
	shl	edi, 4				; desc * 16 (16 is size of one ring entry)
1181
	shl	edi, 4				; desc * 16 (16 is size of one ring entry)
Line 1182... Line 1182...
1182
	add	edi, [device.rx_ring]		; edi now points to current rx ring entry
1182
	add	edi, [device.rx_ring]		; edi now points to current rx ring entry
1183
 
1183
 
Line 1184... Line 1184...
1184
	mov	cx , [edi + buf_head.status]
1184
	mov	cx , [edi + buf_head.status]
1185
 
1185
 
Line 1186... Line 1186...
1186
	test	cx , PCNET_RXSTAT_OWN		; If this bit is set, the controller OWN's the packet, if not, we do
1186
	test	cx , RXSTAT_OWN 	  ; If this bit is set, the controller OWN's the packet, if not, we do
1187
	jnz	.abort
1187
	jnz	.abort
Line 1222... Line 1222...
1222
	jnc	.nw
1222
	jnc	.nw
1223
	movsw
1223
	movsw
1224
  .nw:
1224
  .nw:
1225
	rep	movsd
1225
	rep	movsd
Line 1226... Line 1226...
1226
 
1226
 
1227
;       mov     word [eax + buf_head.length], PCNET_PKT_BUF_SZ_NEG
1227
;       mov     word [eax + buf_head.length], PKT_BUF_SZ_NEG
Line 1228... Line 1228...
1228
	mov	word [eax + buf_head.status], PCNET_RXSTAT_OWN	    ; Set OWN bit back to 1 (controller may write to tx-buffer again now)
1228
	mov	word [eax + buf_head.status], RXSTAT_OWN      ; Set OWN bit back to 1 (controller may write to tx-buffer again now)
1229
 
1229
 
Line 1230... Line 1230...
1230
	inc	[device.cur_rx] 	  ; update descriptor
1230
	inc	[device.cur_rx] 	  ; update descriptor
Line 1255... Line 1255...
1255
 
1255
 
1256
	mov	edx, [device.io_addr]
1256
	mov	edx, [device.io_addr]
1257
	add	edx, 2
1257
	add	edx, 2
Line 1258... Line 1258...
1258
	xor	eax, eax
1258
	xor	eax, eax
1259
 
1259
 
1260
	mov	ecx, PCNET_CSR_PAR0
1260
	mov	ecx, CSR_PAR0
1261
       @@:
1261
       @@:
1262
	pop	ax
1262
	pop	ax
1263
	call	[device.access_write_csr]
1263
	call	[device.access_write_csr]
1264
	DEBUGF	1,"."
1264
	DEBUGF	1,"."
1265
	inc	ecx
1265
	inc	ecx
Line 1266... Line 1266...
1266
	cmp	ecx, PCNET_CSR_PAR2
1266
	cmp	ecx, CSR_PAR2
Line 1267... Line 1267...
1267
	jl	@r
1267
	jl	@r
Line 1336... Line 1336...
1336
; ecx - index
1336
; ecx - index
1337
; return:
1337
; return:
1338
; eax - data
1338
; eax - data
1339
wio_read_csr:
1339
wio_read_csr:
Line 1340... Line 1340...
1340
 
1340
 
1341
	add	edx, PCNET_WIO_RAP
1341
	add	edx, WIO_RAP
1342
	mov	ax , cx
1342
	mov	ax , cx
1343
	out	dx , ax
1343
	out	dx , ax
1344
	add	edx, PCNET_WIO_RDP - PCNET_WIO_RAP
1344
	add	edx, WIO_RDP - WIO_RAP
1345
	in	ax , dx
1345
	in	ax , dx
1346
	and	eax, 0xffff
1346
	and	eax, 0xffff
Line 1347... Line 1347...
1347
	sub	edx, PCNET_WIO_RDP
1347
	sub	edx, WIO_RDP
Line 1348... Line 1348...
1348
 
1348
 
1349
	ret
1349
	ret
1350
 
1350
 
Line 1351... Line 1351...
1351
 
1351
 
1352
; eax - data
1352
; eax - data
1353
; ecx - index
1353
; ecx - index
1354
wio_write_csr:
1354
wio_write_csr:
1355
 
1355
 
1356
	add	edx, PCNET_WIO_RAP
1356
	add	edx, WIO_RAP
1357
	xchg	eax, ecx
1357
	xchg	eax, ecx
Line 1358... Line 1358...
1358
	out	dx , ax
1358
	out	dx , ax
Line 1359... Line 1359...
1359
	xchg	eax, ecx
1359
	xchg	eax, ecx
1360
	add	edx, PCNET_WIO_RDP - PCNET_WIO_RAP
1360
	add	edx, WIO_RDP - WIO_RAP
1361
	out	dx , ax
1361
	out	dx , ax
1362
	sub	edx, PCNET_WIO_RDP
1362
	sub	edx, WIO_RDP
Line 1363... Line 1363...
1363
 
1363
 
1364
	ret
1364
	ret
1365
 
1365
 
1366
 
1366
 
1367
; ecx - index
1367
; ecx - index
1368
; return:
1368
; return:
1369
; eax - data
1369
; eax - data
Line 1370... Line 1370...
1370
wio_read_bcr:
1370
wio_read_bcr:
Line 1371... Line 1371...
1371
 
1371
 
1372
	add	edx, PCNET_WIO_RAP
1372
	add	edx, WIO_RAP
1373
	mov	ax , cx
1373
	mov	ax , cx
Line 1374... Line 1374...
1374
	out	dx , ax
1374
	out	dx , ax
1375
	add	edx, PCNET_WIO_BDP - PCNET_WIO_RAP
1375
	add	edx, WIO_BDP - WIO_RAP
1376
	in	ax , dx
1376
	in	ax , dx
1377
	and	eax, 0xffff
1377
	and	eax, 0xffff
1378
	sub	edx, PCNET_WIO_BDP
1378
	sub	edx, WIO_BDP
1379
 
1379
 
1380
	ret
1380
	ret
Line 1381... Line 1381...
1381
 
1381
 
Line 1382... Line 1382...
1382
 
1382
 
Line 1383... Line 1383...
1383
; eax - data
1383
; eax - data
1384
; ecx - index
1384
; ecx - index
1385
wio_write_bcr:
1385
wio_write_bcr:
1386
 
1386
 
Line 1387... Line 1387...
1387
	add	edx, PCNET_WIO_RAP
1387
	add	edx, WIO_RAP
Line 1388... Line 1388...
1388
	xchg	eax, ecx
1388
	xchg	eax, ecx
1389
	out	dx , ax
1389
	out	dx , ax
Line 1390... Line 1390...
1390
	xchg	eax, ecx
1390
	xchg	eax, ecx
1391
	add	edx, PCNET_WIO_BDP - PCNET_WIO_RAP
1391
	add	edx, WIO_BDP - WIO_RAP
1392
	out	dx , ax
1392
	out	dx , ax
Line 1393... Line 1393...
1393
	sub	edx, PCNET_WIO_BDP
1393
	sub	edx, WIO_BDP
Line 1394... Line 1394...
1394
 
1394
 
Line 1395... Line 1395...
1395
	ret
1395
	ret
1396
 
1396
 
1397
 
1397
 
1398
wio_read_rap:
1398
wio_read_rap:
1399
 
1399
 
Line 1400... Line 1400...
1400
	add	edx, PCNET_WIO_RAP
1400
	add	edx, WIO_RAP
Line 1401... Line 1401...
1401
	in	ax , dx
1401
	in	ax , dx
1402
	and	eax, 0xffff
1402
	and	eax, 0xffff
1403
	sub	edx, PCNET_WIO_RAP
1403
	sub	edx, WIO_RAP
1404
 
1404
 
Line 1405... Line 1405...
1405
	ret
1405
	ret
1406
 
1406
 
1407
; eax - val
1407
; eax - val
1408
wio_write_rap:
1408
wio_write_rap:
1409
 
1409
 
1410
	add	edx, PCNET_WIO_RAP
1410
	add	edx, WIO_RAP
1411
	out	dx , ax
1411
	out	dx , ax
Line 1412... Line 1412...
1412
	sub	edx, PCNET_WIO_RAP
1412
	sub	edx, WIO_RAP
Line 1413... Line 1413...
1413
 
1413
 
1414
	ret
1414
	ret
1415
 
1415
 
Line 1416... Line 1416...
1416
wio_reset:
1416
wio_reset:
1417
 
1417
 
1418
	push	eax
1418
	push	eax
1419
	add	edx, PCNET_WIO_RESET
1419
	add	edx, WIO_RESET
1420
	in	ax , dx
1420
	in	ax , dx
1421
	pop	eax
1421
	pop	eax
1422
	sub	edx, PCNET_WIO_RESET
1422
	sub	edx, WIO_RESET
Line 1423... Line 1423...
1423
 
1423
 
Line 1424... Line 1424...
1424
	ret
1424
	ret
1425
 
1425
 
1426
 
1426
 
1427
; ecx - index
1427
; ecx - index
Line 1428... Line 1428...
1428
; return:
1428
; return:
1429
; eax - data
1429
; eax - data
1430
dwio_read_csr:
1430
dwio_read_csr:
1431
 
1431
 
1432
	add	edx, PCNET_DWIO_RAP
1432
	add	edx, DWIO_RAP
1433
	mov	eax, ecx
1433
	mov	eax, ecx
1434
	out	dx , eax
1434
	out	dx , eax
Line 1435... Line 1435...
1435
	add	edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP
1435
	add	edx, DWIO_RDP - DWIO_RAP
Line 1436... Line 1436...
1436
	in	eax, dx
1436
	in	eax, dx
1437
	and	eax, 0xffff
1437
	and	eax, 0xffff
1438
	sub	edx, PCNET_DWIO_RDP
1438
	sub	edx, DWIO_RDP
Line 1439... Line 1439...
1439
 
1439
 
1440
	ret
1440
	ret
1441
 
1441
 
1442
 
1442
 
1443
; ecx - index
1443
; ecx - index
1444
; eax - data
1444
; eax - data
1445
dwio_write_csr:
1445
dwio_write_csr:
Line 1446... Line 1446...
1446
 
1446
 
Line 1447... Line 1447...
1447
	add	edx, PCNET_DWIO_RAP
1447
	add	edx, DWIO_RAP
Line 1448... Line 1448...
1448
	xchg	eax, ecx
1448
	xchg	eax, ecx
1449
	out	dx , eax
1449
	out	dx , eax
1450
	add	edx, PCNET_DWIO_RDP - PCNET_DWIO_RAP
1450
	add	edx, DWIO_RDP - DWIO_RAP
1451
	xchg	eax, ecx
1451
	xchg	eax, ecx
Line 1452... Line 1452...
1452
	out	dx , eax
1452
	out	dx , eax
Line 1453... Line 1453...
1453
	sub	edx, PCNET_DWIO_RDP
1453
	sub	edx, DWIO_RDP
1454
 
1454
 
Line 1455... Line 1455...
1455
	ret
1455
	ret
1456
 
1456
 
1457
; ecx - index
1457
; ecx - index
Line 1458... Line 1458...
1458
; return:
1458
; return:
Line 1459... Line 1459...
1459
; eax - data
1459
; eax - data
Line 1460... Line 1460...
1460
dwio_read_bcr:
1460
dwio_read_bcr:
1461
 
1461
 
1462
	add	edx, PCNET_DWIO_RAP
1462
	add	edx, DWIO_RAP
1463
	mov	eax, ecx
1463
	mov	eax, ecx
1464
	out	dx , eax
1464
	out	dx , eax
Line 1465... Line 1465...
1465
	add	edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP
1465
	add	edx, DWIO_BDP - DWIO_RAP
Line 1466... Line 1466...
1466
	in	eax, dx
1466
	in	eax, dx
1467
	and	eax, 0xffff
-
 
1468
	sub	edx, PCNET_DWIO_BDP
1467
	and	eax, 0xffff
Line 1469... Line 1468...
1469
 
1468
	sub	edx, DWIO_BDP
1470
	ret
1469
 
1471
 
1470
	ret
Line 1472... Line 1471...
1472
 
1471
 
1473
; ecx - index
1472
 
1474
; eax - data
1473
; ecx - index
1475
dwio_write_bcr:
1474
; eax - data
1476
 
1475
dwio_write_bcr:
1477
	add	edx, PCNET_DWIO_RAP
1476
 
1478
	xchg	eax, ecx
1477
	add	edx, DWIO_RAP
Line 1479... Line 1478...
1479
	out	dx , eax
1478
	xchg	eax, ecx
1480
	add	edx, PCNET_DWIO_BDP - PCNET_DWIO_RAP
1479
	out	dx , eax
1481
	xchg	eax, ecx
1480
	add	edx, DWIO_BDP - DWIO_RAP
1482
	out	dx , eax
1481
	xchg	eax, ecx
1483
	sub	edx, PCNET_DWIO_BDP
1482
	out	dx , eax
1484
 
1483
	sub	edx, DWIO_BDP
1485
	ret
1484
 
1486
 
1485
	ret
1487
 
1486
 
1488
dwio_read_rap:
1487
 
1489
 
1488
dwio_read_rap:
1490
	add	edx, PCNET_DWIO_RAP
1489
 
1491
	in	eax, dx
1490
	add	edx, DWIO_RAP
1492
	and	eax, 0xffff
1491
	in	eax, dx
1493
	sub	edx, PCNET_DWIO_RAP
1492
	and	eax, 0xffff
1494
 
1493
	sub	edx, DWIO_RAP
1495
	ret
1494
 
Line 1496... Line 1495...
1496
 
1495
	ret
Line 1497... Line 1496...
1497
 
1496
 
Line 1498... Line 1497...
1498
; eax - val
1497