Subversion Repositories Kolibri OS

Rev

Rev 735 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 735 Rev 1237
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                    ;;
2
;;                                                                    ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved.       ;;
3
;; Copyright (C) KolibriOS team 2004-2009. 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
;;  SIS900.INC                                                        ;;
-
 
7
;;                                                                    ;;
-
 
8
;;  Ethernet driver for Menuet OS                                     ;;
6
;;  Ethernet driver for KolibriOS                                     ;;
9
;;                                                                    ;;
7
;;  This is an adaptation of MenuetOS driver with minimal changes.    ;;
10
;;  Version 0.4  26 April 2004                                        ;;
8
;;  Changes were made by CleverMouse. Original copyright follows.     ;;
11
;;                                                                    ;;
9
;;                                                                    ;;
12
;;  This driver is based on the SIS900 driver from                    ;;
10
;;  This driver is based on the SIS900 driver from                    ;;
13
;;  the etherboot 5.0.6 project. The copyright statement is           ;;
11
;;  the etherboot 5.0.6 project. The copyright statement is           ;;
14
;;                                                                    ;;
12
;;                                                                    ;;
15
;;          GNU GENERAL PUBLIC LICENSE                                ;;
13
;;          GNU GENERAL PUBLIC LICENSE                                ;;
16
;;             Version 2, June 1991                                   ;;
14
;;             Version 2, June 1991                                   ;;
17
;;                                                                    ;;
15
;;                                                                    ;;
18
;;  remaining parts Copyright 2004 Jason Delozier,                    ;;
16
;;  remaining parts Copyright 2004 Jason Delozier,                    ;;
19
;;   cordata51@hotmail.com                                            ;;
17
;;   cordata51@hotmail.com                                            ;;
20
;;                                                                    ;;
18
;;                                                                    ;;
21
;;  See file COPYING for details                                      ;;
19
;;  See file COPYING for details                                      ;;
22
;;                                                                    ;;
20
;;                                                                    ;;
23
;;  Updates:                                                          ;;
21
;;  Updates:                                                          ;;
24
;;    Revision Look up table and SIS635 Mac Address by Jarek Pelczar  ;;
22
;;    Revision Look up table and SIS635 Mac Address by Jarek Pelczar  ;;
25
;;                                                                    ;;
23
;;                                                                    ;;
26
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27
 
25
 
-
 
26
; $Revision: 1237 $
-
 
27
 
-
 
28
format MS COFF
-
 
29
 
-
 
30
	API_VERSION		equ 0x01000100
-
 
31
 
-
 
32
	DEBUG			equ 1
-
 
33
	__DEBUG__		equ 1
-
 
34
	__DEBUG_LEVEL__ 	equ 1
-
 
35
 
-
 
36
include 'proc32.inc'
-
 
37
include 'imports.inc'
-
 
38
include 'fdo.inc'
-
 
39
 
-
 
40
public START
-
 
41
public version
-
 
42
 
-
 
43
struc IOCTL {
-
 
44
      .handle		dd ?
-
 
45
      .io_code		dd ?
-
 
46
      .input		dd ?
-
 
47
      .inp_size 	dd ?
-
 
48
      .output		dd ?
-
 
49
      .out_size 	dd ?
-
 
50
}
-
 
51
 
-
 
52
virtual at 0
-
 
53
  IOCTL IOCTL
-
 
54
end virtual
-
 
55
 
-
 
56
NUM_RX_DESC    equ    4               ;* Number of RX descriptors *
-
 
57
NUM_TX_DESC    equ    1               ;* Number of TX descriptors *
-
 
58
RX_BUFF_SZ          equ    1520            ;* Buffer size for each Rx buffer *
-
 
59
TX_BUFF_SZ          equ    1516            ;* Buffer size for each Tx buffer *
-
 
60
MAX_ETH_FRAME_SIZE  equ    1516
-
 
61
 
-
 
62
TOTAL_BUFFERS_SIZE equ NUM_RX_DESC*RX_BUFF_SZ + NUM_TX_DESC*TX_BUFF_SZ
-
 
63
 
-
 
64
struc ETH_DEVICE {
-
 
65
; pointers to procedures
-
 
66
      .unload		dd ?
-
 
67
      .reset		dd ?
-
 
68
      .transmit 	dd ?
-
 
69
      .set_MAC		dd ?
-
 
70
      .get_MAC		dd ?
-
 
71
      .set_mode 	dd ?
-
 
72
      .get_mode 	dd ?
-
 
73
; status & variables
-
 
74
      .bytes_tx 	dq ?
-
 
75
      .bytes_rx 	dq ?
-
 
76
      .packets_tx	dd ?
-
 
77
      .packets_rx	dd ?
-
 
78
      .mode		dd ?  ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
-
 
79
      .name		dd ?
-
 
80
      .mac		dp ?
-
 
81
; device specific
-
 
82
      .io_addr		dd ?
-
 
83
      .pci_bus		db ?
-
 
84
      .pci_dev		db ?
-
 
85
      .irq_line 	db ?
-
 
86
      .cur_rx		db ?
-
 
87
      .pci_revision     db ?
-
 
88
      .table_entries:   db ?
-
 
89
align 4
-
 
90
      .special_func:    dd 0
-
 
91
      .txd: times (3 * NUM_TX_DESC) dd 0
-
 
92
      .rxd: times (3 * NUM_RX_DESC) dd 0
-
 
93
      .size:
-
 
94
}
-
 
95
 
-
 
96
; First page is designated to ETH_DEVICE, buffers start from second
-
 
97
ALLOCATION_SIZE = ((device.size+0FFFh) and not 0FFFh) + TOTAL_BUFFERS_SIZE
-
 
98
; Note that buffers must be contiguous in the physical memory;
-
 
99
; because KernelAlloc allocates contiguous physical pages only in 8-pages blocks,
-
 
100
; align ALLOCATION_SIZE up to 8*(page size) = 8000h
-
 
101
ALLOCATION_SIZE = (ALLOCATION_SIZE + 7FFFh) and not 7FFFh
-
 
102
 
-
 
103
MAX_DEVICES = 16	; maximum number of devices which this driver can handle
-
 
104
 
-
 
105
virtual at 0
-
 
106
  device ETH_DEVICE
-
 
107
end virtual
-
 
108
 
-
 
109
	PCI_HEADER_TYPE 	      equ 0x0e	;8 bit
-
 
110
	PCI_BASE_ADDRESS_0	      equ 0x10	;32 bit
-
 
111
	PCI_BASE_ADDRESS_5	      equ 0x24	;32 bits
-
 
112
	PCI_BASE_ADDRESS_SPACE_IO     equ 0x01
-
 
113
	PCI_VENDOR_ID		      equ 0x00	;16 bit
-
 
114
	PCI_BASE_ADDRESS_IO_MASK      equ 0xFFFFFFFC
-
 
115
 
-
 
116
section '.flat' code readable align 16
-
 
117
 
-
 
118
; Driver entry point - register our service when the driver is loading.
-
 
119
; TODO: add needed operations when unloading
-
 
120
START:
-
 
121
	cmp	dword [esp+4], 1
-
 
122
	jne	.exit
-
 
123
	stdcall	RegService, my_service, service_proc
-
 
124
	ret	4
-
 
125
.exit:
-
 
126
	xor	eax, eax
-
 
127
	ret	4
-
 
128
 
-
 
129
; Service procedure for the driver - handle all I/O requests for the driver.
-
 
130
; Currently handled requests are: SRV_GETVERSION = 0 and SRV_HOOK = 1.
-
 
131
service_proc:
-
 
132
; 1. Get parameter from the stack: [esp+4] is the first parameter,
-
 
133
;	pointer to IOCTL structure.
-
 
134
	mov	edx, [esp+4]	; edx -> IOCTL
-
 
135
; 2. Get request code and select a handler for the code.
-
 
136
	mov	eax, [ebx+IOCTL.io_code]
-
 
137
	test	eax, eax	; check for SRV_GETVERSION
-
 
138
	jnz	@f
-
 
139
; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION.
-
 
140
; 3a. Output size must be at least 4 bytes.
-
 
141
	cmp	[edx+IOCTL.out_size], 4
-
 
142
	jl	.fail
-
 
143
; 3b. Write result to the output buffer.
-
 
144
	mov	eax, [edx+IOCTL.output]
-
 
145
	mov	[eax], dword API_VERSION
-
 
146
; 3c. Return success.
-
 
147
	xor	eax, eax
-
 
148
	ret	4
-
 
149
@@:
-
 
150
	dec	eax	; check for SRV_HOOK
-
 
151
	jnz	.fail
-
 
152
; 4. This is SRV_HOOK request, input defines the device to hook, no output.
-
 
153
; 4a. The driver works only with PCI devices,
-
 
154
;	so input must be at least 3 bytes long.
-
 
155
	cmp	[edx + IOCTL.inp_size], 3
-
 
156
	jl	.fail
-
 
157
; 4b. First byte of input is bus type, 1 stands for PCI.
-
 
158
	mov	eax, [edx + IOCTL.input]
-
 
159
	cmp	byte [eax], 1
-
 
160
	jne	.fail
-
 
161
; 4c. Second and third bytes of the input define the device: bus and dev.
-
 
162
;	Word in bx holds both bytes.
-
 
163
	mov	bx, [eax+1]
-
 
164
; 4d. Check if the device was already hooked,
-
 
165
;	scan through the list of known devices.
-
 
166
	mov	esi, DEV_LIST
-
 
167
	mov	ecx, [NUM_DEV]
-
 
168
	test	ecx, ecx
-
 
169
	jz	.firstdevice
-
 
170
  .nextdevice:
-
 
171
	lodsd
-
 
172
	cmp	bx, word [eax + device.pci_bus]
-
 
173
	je	.find_devicenum
-
 
174
	loop	.nextdevice
-
 
175
; 4e. This device doesn't have its own eth_device structure yet, let's create one
-
 
176
  .firstdevice:
-
 
177
; 4f. Check that we have place for new device.
-
 
178
	cmp	[NUM_DEV], MAX_DEVICES
-
 
179
	jge	.fail
-
 
180
; 4g. Allocate memory for device descriptor and receive+transmit buffers.
-
 
181
	stdcall KernelAlloc, ALLOCATION_SIZE
-
 
182
	test	eax, eax
-
 
183
	jz	.fail
-
 
184
; 4h. Zero the structure.
-
 
185
	push	eax
-
 
186
	mov	edi, eax
-
 
187
	mov	ecx, (device.size + 3) shr 2
-
 
188
	xor	eax, eax
-
 
189
	rep	stosd
-
 
190
	pop	eax
-
 
191
; 4i. Save PCI coordinates, loaded to bx at 4c.
-
 
192
	mov	word [eax+device.pci_bus], bx
-
 
193
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
-
 
194
; 4j. Fill in the direct call addresses into the struct.
-
 
195
; Note that get_MAC pointer is filled in initialization by SIS900_probe.
-
 
196
	mov	dword [ebx+device.reset], sis900_init
-
 
197
	mov	dword [ebx+device.transmit], transmit
-
 
198
;	mov	dword [ebx+device.get_MAC], read_mac
-
 
199
	mov	dword [ebx+device.set_MAC], write_mac
-
 
200
	mov	dword [ebx+device.unload], unload
-
 
201
	mov	dword [ebx+device.name], my_service
-
 
202
 
-
 
203
; 4k. Now, it's time to find the base io addres of the PCI device
-
 
204
; TODO: implement check if bus and dev exist on this machine
-
 
205
 
-
 
206
	mov	edx, PCI_BASE_ADDRESS_0
-
 
207
.reg_check:
-
 
208
	push	edx
-
 
209
	stdcall	PciRead16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], edx
-
 
210
	pop	edx
-
 
211
	test	al, PCI_BASE_ADDRESS_SPACE_IO
-
 
212
	jz	.inc_reg
-
 
213
	and	eax, PCI_BASE_ADDRESS_IO_MASK
-
 
214
	jnz	.got_io
-
 
215
 
-
 
216
  .inc_reg:
-
 
217
	add	edx, 4
-
 
218
	cmp	edx, PCI_BASE_ADDRESS_5
-
 
219
	jbe	.reg_check
-
 
220
	jmp	.fail
-
 
221
 
-
 
222
  .got_io:
-
 
223
	mov	[ebx+device.io_addr], eax
-
 
224
 
-
 
225
; 4l. We've found the io address, find IRQ now
-
 
226
	stdcall	PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x3c
-
 
227
	mov	byte [ebx+device.irq_line], al
-
 
228
 
-
 
229
; 4m. Add new device to the list (required for int_handler).
-
 
230
	mov	eax, [NUM_DEV]
-
 
231
	mov	[DEV_LIST+4*eax], ebx
-
 
232
	inc	[NUM_DEV]
-
 
233
 
-
 
234
; 4m. Ok, the eth_device structure is ready, let's probe the device
-
 
235
 
-
 
236
	call	SIS900_probe
-
 
237
	test	eax, eax
-
 
238
	jnz	.destroy
-
 
239
; 4n. If device was successfully initialized, register it for the kernel.
-
 
240
 
-
 
241
	call	EthRegDev
-
 
242
	cmp	eax, -1
-
 
243
	je	.destroy
-
 
244
 
-
 
245
	ret	4
-
 
246
 
-
 
247
; 5. If the device was already loaded, find the device number and return it in eax
-
 
248
 
-
 
249
  .find_devicenum:
-
 
250
	mov	ebx, eax
-
 
251
	call	EthStruc2Dev						; This kernel procedure converts a pointer to device struct in ebx
-
 
252
									; into a device number in edi
-
 
253
	mov	eax, edi						; Application wants it in eax instead
-
 
254
	ret	4
-
 
255
 
-
 
256
; If an error occured, remove all allocated data and exit (returning -1 in eax)
-
 
257
 
-
 
258
  .destroy:
-
 
259
	dec	[NUM_DEV]
-
 
260
	; todo: reset device into virgin state
-
 
261
 
-
 
262
  .err:
-
 
263
	stdcall KernelFree, ebx
-
 
264
 
-
 
265
 
-
 
266
  .fail:
-
 
267
	xor	eax, eax
-
 
268
	ret	4
-
 
269
 
-
 
270
 
-
 
271
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
-
 
272
;;                                                                        ;;
-
 
273
;;        Actual Hardware dependent code starts here                      ;;
-
 
274
;;                                                                        ;;
-
 
275
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
-
 
276
 
-
 
277
unload:
-
 
278
	; TODO: (in this particular order)
-
 
279
	;
-
 
280
	; - Stop the device
-
 
281
	; - Detach int handler
-
 
282
	; - Remove device from local list
-
 
283
	; - call unregister function in kernel
-
 
284
	; - Remove all allocated structures and buffers the card used
-
 
285
 
-
 
286
	or	eax,-1
28
$Revision: 735 $
287
 
29
 
288
ret
30
 
289
 
31
;********************************************************************
290
;********************************************************************
32
;   Interface
291
;   Interface
33
;      SIS900_reset
292
;      SIS900_reset
34
;      SIS900_probe
293
;      SIS900_probe
35
;      SIS900_poll
294
;      SIS900_poll
36
;      SIS900_transmit
295
;      SIS900_transmit
37
;
296
;
38
;********************************************************************
297
;********************************************************************
39
;********************************************************************
298
;********************************************************************
40
;  Comments:
299
;  Comments:
41
;    Known to work with the following SIS900 ethernet cards:
300
;    Known to work with the following SIS900 ethernet cards:
42
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x91
301
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x91
43
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x90
302
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x90
44
;
303
;
45
;    If your card is not listed, try it and let me know if it
304
;    If your card is not listed, try it and let me know if it
46
;    functions properly and it will be aded to the list.  If not
305
;    functions properly and it will be aded to the list.  If not
47
;    we may be able to add support for it.
306
;    we may be able to add support for it.
48
;
307
;
49
;  How To Use:
-
 
50
;    Add the following lines to Ethernet.inc in their appropriate locations
-
 
51
;
-
 
52
;         include "Sis900.INC"
-
 
53
;         dd  0x09001039, SIS900_probe, SIS900_reset, SIS900_poll,
-
 
54
; SIS900_transmit
-
 
55
;         dd  0x70161039, SIS900_probe, SIS900_reset, SIS900_poll,
-
 
56
; SIS900_transmit   ;untested
-
 
57
;
-
 
58
;  ToDo:
308
;  ToDo:
59
;     -  Enable MII interface for reading speed
309
;     -  Enable MII interface for reading speed
60
;        and duplex settings.
310
;        and duplex settings.
61
;
311
;
62
;     -  Update Poll routine to support packet fragmentation.
312
;     -  Update Poll routine to support packet fragmentation.
63
;
313
;
64
;     -  Add additional support for other sis900 based cards
314
;     -  Add additional support for other sis900 based cards
65
;
315
;
66
;********************************************************************
316
;********************************************************************
67
 
317
 
68
; comment the next line out if you don't want debug info printed
318
; comment the next line out if you don't want debug info printed
69
; on the debug board. This option adds a lot of bytes to the driver
319
; on the debug board. This option adds a lot of bytes to the driver
70
; so it's worth to comment it out.
320
; so it's worth to comment it out.
71
;        SIS900_DEBUG equ 1
321
;        SIS900_DEBUG equ 1
72
 
-
 
73
 
-
 
74
;* buffers and descriptors
-
 
75
cur_rx  db  0
-
 
76
NUM_RX_DESC    equ    4               ;* Number of RX descriptors *
-
 
77
NUM_TX_DESC    equ    1               ;* Number of TX descriptors *
-
 
78
RX_BUFF_SZ          equ    1520            ;* Buffer size for each Rx buffer *
-
 
79
TX_BUFF_SZ          equ    1516            ;* Buffer size for each Tx buffer *
-
 
80
 
-
 
81
uglobal
-
 
82
align   4
-
 
83
txd: times (3 * NUM_TX_DESC) dd 0
-
 
84
rxd: times (3 * NUM_RX_DESC) dd 0
-
 
85
endg
-
 
86
 
-
 
87
txb equ eth_data_start
-
 
88
rxb equ txb + (NUM_TX_DESC * TX_BUFF_SZ)
322
 
89
SIS900_ETH_ALEN equ     6       ;* Size of Ethernet address *
323
SIS900_ETH_ALEN equ     6       ;* Size of Ethernet address *
90
SIS900_ETH_HLEN equ     14      ;* Size of ethernet header *
324
SIS900_ETH_HLEN equ     14      ;* Size of ethernet header *
91
SIS900_ETH_ZLEN equ     60      ;* Minimum packet length *
325
SIS900_ETH_ZLEN equ     60      ;* Minimum packet length *
92
SIS900_DSIZE equ 0x00000fff
326
SIS900_DSIZE equ 0x00000fff
93
SIS900_CRC_SIZE equ 4
327
SIS900_CRC_SIZE equ 4
94
SIS900_RFADDR_shift equ 16
328
SIS900_RFADDR_shift equ 16
95
;SIS900 Symbolic offsets to registers.
329
;SIS900 Symbolic offsets to registers.
96
    SIS900_cr           equ     0x0               ; Command Register
330
    SIS900_cr           equ     0x0               ; Command Register
97
    SIS900_cfg          equ     0x4       ; Configuration Register
331
    SIS900_cfg          equ     0x4       ; Configuration Register
98
    SIS900_mear     equ     0x8       ; EEPROM Access Register
332
    SIS900_mear     equ     0x8       ; EEPROM Access Register
99
    SIS900_ptscr    equ     0xc       ; PCI Test Control Register
333
    SIS900_ptscr    equ     0xc       ; PCI Test Control Register
100
    SIS900_isr          equ     0x10      ; Interrupt Status Register
334
    SIS900_isr          equ     0x10      ; Interrupt Status Register
101
    SIS900_imr          equ     0x14      ; Interrupt Mask Register
335
    SIS900_imr          equ     0x14      ; Interrupt Mask Register
102
    SIS900_ier          equ     0x18      ; Interrupt Enable Register
336
    SIS900_ier          equ     0x18      ; Interrupt Enable Register
103
    SIS900_epar         equ     0x18      ; Enhanced PHY Access Register
337
    SIS900_epar         equ     0x18      ; Enhanced PHY Access Register
104
    SIS900_txdp     equ     0x20      ; Transmit Descriptor Pointer Register
338
    SIS900_txdp     equ     0x20      ; Transmit Descriptor Pointer Register
105
    SIS900_txcfg    equ     0x24      ; Transmit Configuration Register
339
    SIS900_txcfg    equ     0x24      ; Transmit Configuration Register
106
    SIS900_rxdp     equ     0x30      ; Receive Descriptor Pointer Register
340
    SIS900_rxdp     equ     0x30      ; Receive Descriptor Pointer Register
107
    SIS900_rxcfg    equ     0x34      ; Receive Configuration Register
341
    SIS900_rxcfg    equ     0x34      ; Receive Configuration Register
108
    SIS900_flctrl   equ     0x38      ; Flow Control Register
342
    SIS900_flctrl   equ     0x38      ; Flow Control Register
109
    SIS900_rxlen    equ     0x3c      ; Receive Packet Length Register
343
    SIS900_rxlen    equ     0x3c      ; Receive Packet Length Register
110
    SIS900_rfcr     equ     0x48      ; Receive Filter Control Register
344
    SIS900_rfcr     equ     0x48      ; Receive Filter Control Register
111
    SIS900_rfdr     equ     0x4C      ; Receive Filter Data Register
345
    SIS900_rfdr     equ     0x4C      ; Receive Filter Data Register
112
    SIS900_pmctrl   equ     0xB0      ; Power Management Control Register
346
    SIS900_pmctrl   equ     0xB0      ; Power Management Control Register
113
    SIS900_pmer         equ     0xB4      ; Power Management Wake-up Event Register
347
    SIS900_pmer         equ     0xB4      ; Power Management Wake-up Event Register
114
;SIS900 Command Register Bits
348
;SIS900 Command Register Bits
115
    SIS900_RELOAD       equ      0x00000400
349
    SIS900_RELOAD       equ      0x00000400
116
    SIS900_ACCESSMODE   equ      0x00000200
350
    SIS900_ACCESSMODE   equ      0x00000200
117
    SIS900_RESET        equ      0x00000100
351
    SIS900_RESET        equ      0x00000100
118
    SIS900_SWI          equ      0x00000080
352
    SIS900_SWI          equ      0x00000080
119
    SIS900_RxRESET      equ      0x00000020
353
    SIS900_RxRESET      equ      0x00000020
120
    SIS900_TxRESET      equ      0x00000010
354
    SIS900_TxRESET      equ      0x00000010
121
    SIS900_RxDIS        equ      0x00000008
355
    SIS900_RxDIS        equ      0x00000008
122
    SIS900_RxENA        equ      0x00000004
356
    SIS900_RxENA        equ      0x00000004
123
    SIS900_TxDIS        equ      0x00000002
357
    SIS900_TxDIS        equ      0x00000002
124
    SIS900_TxENA        equ      0x00000001
358
    SIS900_TxENA        equ      0x00000001
125
;SIS900 Configuration Register Bits
359
;SIS900 Configuration Register Bits
126
    SIS900_DESCRFMT      equ    0x00000100 ; 7016 specific
360
    SIS900_DESCRFMT      equ    0x00000100 ; 7016 specific
127
    SIS900_REQALG        equ    0x00000080
361
    SIS900_REQALG        equ    0x00000080
128
    SIS900_SB            equ    0x00000040
362
    SIS900_SB            equ    0x00000040
129
    SIS900_POW           equ    0x00000020
363
    SIS900_POW           equ    0x00000020
130
    SIS900_EXD           equ    0x00000010
364
    SIS900_EXD           equ    0x00000010
131
    SIS900_PESEL         equ    0x00000008
365
    SIS900_PESEL         equ    0x00000008
132
    SIS900_LPM           equ    0x00000004
366
    SIS900_LPM           equ    0x00000004
133
    SIS900_BEM           equ    0x00000001
367
    SIS900_BEM           equ    0x00000001
134
    SIS900_RND_CNT       equ    0x00000400
368
    SIS900_RND_CNT       equ    0x00000400
135
    SIS900_FAIR_BACKOFF  equ    0x00000200
369
    SIS900_FAIR_BACKOFF  equ    0x00000200
136
    SIS900_EDB_MASTER_EN equ    0x00002000
370
    SIS900_EDB_MASTER_EN equ    0x00002000
137
;SIS900 Eeprom Access Reigster Bits
371
;SIS900 Eeprom Access Reigster Bits
138
    SIS900_MDC        equ      0x00000040
372
    SIS900_MDC        equ      0x00000040
139
    SIS900_MDDIR      equ      0x00000020
373
    SIS900_MDDIR      equ      0x00000020
140
    SIS900_MDIO       equ      0x00000010  ; 7016 specific
374
    SIS900_MDIO       equ      0x00000010  ; 7016 specific
141
    SIS900_EECS       equ      0x00000008
375
    SIS900_EECS       equ      0x00000008
142
    SIS900_EECLK      equ      0x00000004
376
    SIS900_EECLK      equ      0x00000004
143
    SIS900_EEDO       equ      0x00000002
377
    SIS900_EEDO       equ      0x00000002
144
    SIS900_EEDI       equ      0x00000001
378
    SIS900_EEDI       equ      0x00000001
145
;SIS900 TX Configuration Register Bits
379
;SIS900 TX Configuration Register Bits
146
    SIS900_ATP        equ      0x10000000 ;Automatic Transmit Padding
380
    SIS900_ATP        equ      0x10000000 ;Automatic Transmit Padding
147
    SIS900_MLB        equ      0x20000000 ;Mac Loopback Enable
381
    SIS900_MLB        equ      0x20000000 ;Mac Loopback Enable
148
    SIS900_HBI        equ      0x40000000 ;HeartBeat Ignore (Req for full-dup)
382
    SIS900_HBI        equ      0x40000000 ;HeartBeat Ignore (Req for full-dup)
149
    SIS900_CSI        equ      0x80000000 ;CarrierSenseIgnore (Req for full-du
383
    SIS900_CSI        equ      0x80000000 ;CarrierSenseIgnore (Req for full-du
150
;SIS900 RX Configuration Register Bits
384
;SIS900 RX Configuration Register Bits
151
    SIS900_AJAB       equ      0x08000000 ;
385
    SIS900_AJAB       equ      0x08000000 ;
152
    SIS900_ATX        equ      0x10000000 ;Accept Transmit Packets
386
    SIS900_ATX        equ      0x10000000 ;Accept Transmit Packets
153
    SIS900_ARP        equ      0x40000000 ;accept runt packets (<64bytes)
387
    SIS900_ARP        equ      0x40000000 ;accept runt packets (<64bytes)
154
    SIS900_AEP        equ      0x80000000 ;accept error packets
388
    SIS900_AEP        equ      0x80000000 ;accept error packets
155
;SIS900 Interrupt Reigster Bits
389
;SIS900 Interrupt Reigster Bits
156
    SIS900_WKEVT           equ      0x10000000
390
    SIS900_WKEVT           equ      0x10000000
157
    SIS900_TxPAUSEEND      equ      0x08000000
391
    SIS900_TxPAUSEEND      equ      0x08000000
158
    SIS900_TxPAUSE         equ      0x04000000
392
    SIS900_TxPAUSE         equ      0x04000000
159
    SIS900_TxRCMP          equ      0x02000000
393
    SIS900_TxRCMP          equ      0x02000000
160
    SIS900_RxRCMP          equ      0x01000000
394
    SIS900_RxRCMP          equ      0x01000000
161
    SIS900_DPERR           equ      0x00800000
395
    SIS900_DPERR           equ      0x00800000
162
    SIS900_SSERR           equ      0x00400000
396
    SIS900_SSERR           equ      0x00400000
163
    SIS900_RMABT           equ      0x00200000
397
    SIS900_RMABT           equ      0x00200000
164
    SIS900_RTABT           equ      0x00100000
398
    SIS900_RTABT           equ      0x00100000
165
    SIS900_RxSOVR          equ      0x00010000
399
    SIS900_RxSOVR          equ      0x00010000
166
    SIS900_HIBERR          equ      0x00008000
400
    SIS900_HIBERR          equ      0x00008000
167
    SIS900_SWINT           equ      0x00001000
401
    SIS900_SWINT           equ      0x00001000
168
    SIS900_MIBINT          equ      0x00000800
402
    SIS900_MIBINT          equ      0x00000800
169
    SIS900_TxURN           equ      0x00000400
403
    SIS900_TxURN           equ      0x00000400
170
    SIS900_TxIDLE          equ      0x00000200
404
    SIS900_TxIDLE          equ      0x00000200
171
    SIS900_TxERR           equ      0x00000100
405
    SIS900_TxERR           equ      0x00000100
172
    SIS900_TxDESC          equ      0x00000080
406
    SIS900_TxDESC          equ      0x00000080
173
    SIS900_TxOK            equ      0x00000040
407
    SIS900_TxOK            equ      0x00000040
174
    SIS900_RxORN           equ      0x00000020
408
    SIS900_RxORN           equ      0x00000020
175
    SIS900_RxIDLE          equ      0x00000010
409
    SIS900_RxIDLE          equ      0x00000010
176
    SIS900_RxEARLY         equ      0x00000008
410
    SIS900_RxEARLY         equ      0x00000008
177
    SIS900_RxERR           equ      0x00000004
411
    SIS900_RxERR           equ      0x00000004
178
    SIS900_RxDESC          equ      0x00000002
412
    SIS900_RxDESC          equ      0x00000002
179
    SIS900_RxOK            equ      0x00000001
413
    SIS900_RxOK            equ      0x00000001
180
;SIS900 Interrupt Enable Reigster Bits
414
;SIS900 Interrupt Enable Reigster Bits
181
    SIS900_IE      equ      0x00000001
415
    SIS900_IE      equ      0x00000001
182
;SIS900 Revision ID
416
;SIS900 Revision ID
183
        SIS900B_900_REV       equ      0x03
417
        SIS900B_900_REV       equ      0x03
184
        SIS630A_900_REV       equ      0x80
418
        SIS630A_900_REV       equ      0x80
185
        SIS630E_900_REV       equ      0x81
419
        SIS630E_900_REV       equ      0x81
186
        SIS630S_900_REV       equ      0x82
420
        SIS630S_900_REV       equ      0x82
187
        SIS630EA1_900_REV     equ      0x83
421
        SIS630EA1_900_REV     equ      0x83
188
        SIS630ET_900_REV      equ      0x84
422
        SIS630ET_900_REV      equ      0x84
189
        SIS635A_900_REV       equ      0x90
423
        SIS635A_900_REV       equ      0x90
190
        SIS900_960_REV        equ      0x91
424
        SIS900_960_REV        equ      0x91
191
;SIS900 Receive Filter Control Register Bits
425
;SIS900 Receive Filter Control Register Bits
192
    SIS900_RFEN          equ 0x80000000
426
    SIS900_RFEN          equ 0x80000000
193
    SIS900_RFAAB         equ 0x40000000
427
    SIS900_RFAAB         equ 0x40000000
194
    SIS900_RFAAM         equ 0x20000000
428
    SIS900_RFAAM         equ 0x20000000
195
    SIS900_RFAAP         equ 0x10000000
429
    SIS900_RFAAP         equ 0x10000000
196
    SIS900_RFPromiscuous equ 0x70000000
430
    SIS900_RFPromiscuous equ 0x70000000
197
;SIS900 Reveive Filter Data Mask
431
;SIS900 Reveive Filter Data Mask
198
    SIS900_RFDAT equ  0x0000FFFF
432
    SIS900_RFDAT equ  0x0000FFFF
199
;SIS900 Eeprom Address
433
;SIS900 Eeprom Address
200
    SIS900_EEPROMSignature equ 0x00
434
    SIS900_EEPROMSignature equ 0x00
201
    SIS900_EEPROMVendorID  equ 0x02
435
    SIS900_EEPROMVendorID  equ 0x02
202
    SIS900_EEPROMDeviceID  equ 0x03
436
    SIS900_EEPROMDeviceID  equ 0x03
203
    SIS900_EEPROMMACAddr   equ 0x08
437
    SIS900_EEPROMMACAddr   equ 0x08
204
    SIS900_EEPROMChecksum  equ 0x0b
438
    SIS900_EEPROMChecksum  equ 0x0b
205
;The EEPROM commands include the alway-set leading bit.
439
;The EEPROM commands include the alway-set leading bit.
206
;SIS900 Eeprom Command
440
;SIS900 Eeprom Command
207
    SIS900_EEread          equ 0x0180
441
    SIS900_EEread          equ 0x0180
208
    SIS900_EEwrite         equ 0x0140
442
    SIS900_EEwrite         equ 0x0140
209
    SIS900_EEerase         equ 0x01C0
443
    SIS900_EEerase         equ 0x01C0
210
    SIS900_EEwriteEnable   equ 0x0130
444
    SIS900_EEwriteEnable   equ 0x0130
211
    SIS900_EEwriteDisable  equ 0x0100
445
    SIS900_EEwriteDisable  equ 0x0100
212
    SIS900_EEeraseAll      equ 0x0120
446
    SIS900_EEeraseAll      equ 0x0120
213
    SIS900_EEwriteAll      equ 0x0110
447
    SIS900_EEwriteAll      equ 0x0110
214
    SIS900_EEaddrMask      equ 0x013F
448
    SIS900_EEaddrMask      equ 0x013F
215
    SIS900_EEcmdShift      equ 16
449
    SIS900_EEcmdShift      equ 16
216
;For SiS962 or SiS963, request the eeprom software access
450
;For SiS962 or SiS963, request the eeprom software access
217
        SIS900_EEREQ    equ 0x00000400
451
        SIS900_EEREQ    equ 0x00000400
218
        SIS900_EEDONE   equ 0x00000200
452
        SIS900_EEDONE   equ 0x00000200
219
        SIS900_EEGNT    equ 0x00000100
453
        SIS900_EEGNT    equ 0x00000100
220
;General Varibles
-
 
221
        SIS900_pci_revision:     db       0
-
 
222
        SIS900_Status                dd   0x03000000
-
 
223
sis900_specific_table:
-
 
224
;    dd SIS630A_900_REV,Get_Mac_SIS630A_900_REV,0
-
 
225
;    dd SIS630E_900_REV,Get_Mac_SIS630E_900_REV,0
-
 
226
    dd SIS630S_900_REV,Get_Mac_SIS635_900_REV,0
-
 
227
    dd SIS630EA1_900_REV,Get_Mac_SIS635_900_REV,0
-
 
228
    dd SIS630ET_900_REV,Get_Mac_SIS635_900_REV,0;SIS630ET_900_REV_SpecialFN
-
 
229
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
-
 
230
    dd SIS900_960_REV,SIS960_get_mac_addr,0
-
 
231
    dd SIS900B_900_REV,SIS900_get_mac_addr,0
-
 
232
    dd 0,0,0,0 ; end of list
-
 
233
sis900_get_mac_func:    dd 0
-
 
234
sis900_special_func:    dd 0
-
 
235
sis900_table_entries:   db 8
-
 
-
 
454
 
-
 
455
SIS900_pci_revision equ ebx+device.pci_revision
-
 
456
sis900_get_mac_func equ ebx+device.get_MAC
-
 
457
sis900_special_func equ ebx+device.special_func
-
 
458
sis900_table_entries equ ebx+device.table_entries
-
 
459
cur_rx equ ebx+device.cur_rx
236
 
460
sys_msg_board_str equ SysMsgBoardStr
237
;***************************************************************************
461
;***************************************************************************
238
;   Function
462
;   Function
239
;      SIS900_probe
463
;      SIS900_probe
240
;   Description
464
;   Description
241
;      Searches for an ethernet card, enables it and clears the rx buffer
465
;      Searches for an ethernet card, enables it and clears the rx buffer
242
;      If a card was found, it enables the ethernet -> TCPIP link
466
;      If a card was found, it enables the ethernet -> TCPIP link
243
;not done  - still need to probe mii transcievers
467
;not done  - still need to probe mii transcievers
244
;***************************************************************************
468
;***************************************************************************
245
if defined SIS900_DEBUG
469
if defined SIS900_DEBUG
246
SIS900_Debug_Str_Unsupported db 'Sorry your card is unsupported ',13,10,0
470
SIS900_Debug_Str_Unsupported db 'Sorry your card is unsupported ',13,10,0
247
end if
471
end if
248
SIS900_probe:
472
SIS900_probe:
249
;******Wake Up Chip*******
473
;******Wake Up Chip*******
250
   mov     al, 4
-
 
251
   mov     bh, [pci_dev]
-
 
252
   mov     ecx, 0
-
 
253
   mov     ah, [pci_bus]
-
 
254
   mov     bl, 0x40
-
 
255
   call    pci_write_reg
474
   stdcall PciWrite8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x40, 0
256
;*******Set some PCI Settings*********
475
;*******Set some PCI Settings*********
257
   call    SIS900_adjust_pci_device
476
   call    SIS900_adjust_pci_device
258
;*****Get Card Revision******
477
;*****Get Card Revision******
259
   mov     al, 1                                        ;one byte to read
478
   stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x08
260
   mov     bh, [pci_dev]
-
 
261
   mov     ah, [pci_bus]
-
 
262
   mov     bl, 0x08                                 ;Revision Register
-
 
263
   call    pci_read_reg
-
 
264
   mov [SIS900_pci_revision], al        ;save the revision for later use
479
   mov [SIS900_pci_revision], al        ;save the revision for later use
265
;****** Look up through the sis900_specific_table
480
;****** Look up through the sis900_specific_table
266
   mov     esi,sis900_specific_table
481
   mov     esi,sis900_specific_table
267
.probe_loop:
482
.probe_loop:
268
   cmp     dword [esi],0                ; Check if we reached end of the list
483
   cmp     dword [esi],0                ; Check if we reached end of the list
269
   je      .probe_loop_failed
484
   je      .probe_loop_failed
270
   cmp     al,[esi]                     ; Check if revision is OK
485
   cmp     al,[esi]                     ; Check if revision is OK
271
   je      .probe_loop_ok
486
   je      .probe_loop_ok
272
   add     esi,12                       ; Advance to next entry
487
   add     esi,12                       ; Advance to next entry
273
   jmp     .probe_loop
488
   jmp     .probe_loop
274
.probe_loop_failed:
489
.probe_loop_failed:
275
   jmp     SIS900_Probe_Unsupported
490
   jmp     SIS900_Probe_Unsupported
276
;*********Find Get Mac Function*********
491
;*********Find Get Mac Function*********
277
.probe_loop_ok:
492
.probe_loop_ok:
278
   mov      eax,[esi+4]         ; Get pointer to "get MAC" function
493
   mov      eax,[esi+4]         ; Get pointer to "get MAC" function
279
   mov      [sis900_get_mac_func],eax
494
   mov      [sis900_get_mac_func],eax
280
   mov      eax,[esi+8]         ; Get pointer to special initialization fn
495
   mov      eax,[esi+8]         ; Get pointer to special initialization fn
281
   mov      [sis900_special_func],eax
496
   mov      [sis900_special_func],eax
282
;******** Get MAC ********
497
;******** Get MAC ********
283
   call     dword [sis900_get_mac_func]
498
   call     dword [sis900_get_mac_func]
284
;******** Call special initialization fn if requested ********
499
;******** Call special initialization fn if requested ********
285
   cmp      dword [sis900_special_func],0
500
   cmp      dword [sis900_special_func],0
286
   je       .no_special_init
501
   je       .no_special_init
287
   call     dword [sis900_special_func]
502
   call     dword [sis900_special_func]
288
.no_special_init:
503
.no_special_init:
289
;******** Set table entries ********
504
;******** Set table entries ********
290
   mov      al,[SIS900_pci_revision]
505
   mov      al,[SIS900_pci_revision]
291
   cmp      al,SIS635A_900_REV
506
   cmp      al,SIS635A_900_REV
292
   jae      .ent16
507
   jae      .ent16
293
   cmp      al,SIS900B_900_REV
508
   cmp      al,SIS900B_900_REV
294
   je       .ent16
509
   je       .ent16
-
 
510
   mov      byte [sis900_table_entries],8
295
   jmp      .ent8
511
   jmp      .ent8
296
.ent16:
512
.ent16:
297
   mov      byte [sis900_table_entries],16
513
   mov      byte [sis900_table_entries],16
298
.ent8:
514
.ent8:
299
;*******Probe for mii transceiver*******
515
;*******Probe for mii transceiver*******
300
;TODO!!*********************
516
;TODO!!*********************
301
;*******Initialize Device*******
517
;*******Initialize Device*******
302
   call sis900_init
518
   call sis900_init
303
   ret
519
   ret
304
 
520
 
305
SIS900_Probe_Unsupported:
521
SIS900_Probe_Unsupported:
306
if defined SIS900_DEBUG
522
if defined SIS900_DEBUG
307
   mov     esi, SIS900_Debug_Str_Unsupported
523
   mov     esi, SIS900_Debug_Str_Unsupported
308
   call    sys_msg_board_str
524
   call    sys_msg_board_str
309
end if
525
end if
-
 
526
   or      eax, -1
310
   ret
527
   ret
311
;***************************************************************************
528
;***************************************************************************
312
; Function: sis900_init
529
; Function: sis900_init
313
;
530
;
314
; Description: resets the ethernet controller chip and various
531
; Description: resets the ethernet controller chip and various
315
;    data structures required for sending and receiving packets.
532
;    data structures required for sending and receiving packets.
316
;
533
;
317
; Arguments:
534
; Arguments:
318
;
535
;
319
; returns:   none
536
; returns:   none
320
;not done
537
;not done
321
;***************************************************************************
538
;***************************************************************************
322
sis900_init:
539
sis900_init:
323
   call SIS900_reset               ;Done
540
   call SIS900_reset               ;Done
324
   call SIS900_init_rxfilter   ;Done
541
   call SIS900_init_rxfilter   ;Done
325
   call SIS900_init_txd        ;Done
542
   call SIS900_init_txd        ;Done
326
   call SIS900_init_rxd            ;Done
543
   call SIS900_init_rxd            ;Done
327
   call SIS900_set_rx_mode     ;done
544
   call SIS900_set_rx_mode     ;done
328
   call SIS900_set_tx_mode
545
   call SIS900_set_tx_mode
329
   ;call SIS900_check_mode
546
   ;call SIS900_check_mode
-
 
547
; enable interrupts on packet receive
-
 
548
	xor	eax, eax
-
 
549
	inc	eax	; eax = 1 = SIS900_RxOK
-
 
550
	mov	edx, [ebx+device.io_addr]
-
 
551
	add	edx, SIS900_imr
-
 
552
	out	dx, eax
-
 
553
; globally enable interrupts
-
 
554
	add	edx, SIS900_ier-SIS900_imr
-
 
555
	out	dx, eax	; eax is still 1
-
 
556
	xor	eax, eax
330
   ret
557
   ret
331
 
558
 
332
;***************************************************************************
559
;***************************************************************************
333
;   Function
560
;   Function
334
;      SIS900_reset
561
;      SIS900_reset
335
;   Description
562
;   Description
336
;      disables interrupts and soft resets the controller chip
563
;      disables interrupts and soft resets the controller chip
337
;
564
;
338
;done+
565
;done+
339
;***************************************************************************
566
;***************************************************************************
340
if defined SIS900_DEBUG
567
if defined SIS900_DEBUG
341
   SIS900_Debug_Reset_Failed db 'Reset Failed ',0
568
   SIS900_Debug_Reset_Failed db 'Reset Failed ',0
342
end if
569
end if
343
SIS900_reset:
570
SIS900_reset:
-
 
571
	movzx	eax, [ebx+device.irq_line]
-
 
572
	stdcall	AttachIntHandler, eax, int_handler, 0
-
 
573
   push     ebp
-
 
574
   mov      ebp, [ebx+device.io_addr] ; base address
344
   ;******Disable Interrupts and reset Receive Filter*******
575
   ;******Disable Interrupts and reset Receive Filter*******
345
   mov      ebp, [io_addr]      ; base address
-
 
346
   xor      eax, eax            ; 0 to initialize
576
   xor      eax, eax            ; 0 to initialize
347
   lea      edx,[ebp+SIS900_ier]
577
   lea      edx,[ebp+SIS900_ier]
348
   out      dx, eax                     ; Write 0 to location
578
   out      dx, eax                     ; Write 0 to location
349
   lea      edx,[ebp+SIS900_imr]
579
   lea      edx,[ebp+SIS900_imr]
350
   out      dx, eax                     ; Write 0 to location
580
   out      dx, eax                     ; Write 0 to location
351
   lea      edx,[ebp+SIS900_rfcr]
581
   lea      edx,[ebp+SIS900_rfcr]
352
   out      dx, eax                     ; Write 0 to location
582
   out      dx, eax                     ; Write 0 to location
353
   ;*******Reset Card***********************************************
583
   ;*******Reset Card***********************************************
354
   lea      edx,[ebp+SIS900_cr]
584
   lea      edx,[ebp+SIS900_cr]
355
   in       eax, dx                             ; Get current Command Register
585
   in       eax, dx                             ; Get current Command Register
356
   or       eax, SIS900_RESET           ; set flags
586
   or       eax, SIS900_RESET           ; set flags
357
   or       eax, SIS900_RxRESET     ;
587
   or       eax, SIS900_RxRESET     ;
358
   or           eax, SIS900_TxRESET         ;
588
   or           eax, SIS900_TxRESET         ;
359
   out      dx, eax                             ; Write new Command Register
589
   out      dx, eax                             ; Write new Command Register
360
   ;*******Wait Loop************************************************
590
   ;*******Wait Loop************************************************
-
 
591
   push     ebx
361
   lea      edx,[ebp+SIS900_isr]
592
   lea      edx,[ebp+SIS900_isr]
362
   mov      ecx, [SIS900_Status]    ; Status we would like to see from card
593
   mov      ecx, 0x03000000         ; Status we would like to see from card
363
   mov      ebx, 2001               ; only loop 1000 times
594
   mov      ebx, 2001               ; only loop 1000 times
364
SIS900_Wait:
595
SIS900_Wait:
365
   dec      ebx                                     ; 1 less loop
596
   dec      ebx                                     ; 1 less loop
366
   jz       SIS900_DoneWait_e           ; 1000 times yet?
597
   jz       SIS900_DoneWait_e           ; 1000 times yet?
367
   in       eax, dx                                 ; move interrup status to eax
598
   in       eax, dx                                 ; move interrup status to eax
368
   and      eax, ecx
599
   and      eax, ecx
369
   xor      ecx, eax
600
   xor      ecx, eax
370
   jz       SIS900_DoneWait
601
   jz       SIS900_DoneWait
371
   jmp      SIS900_Wait
602
   jmp      SIS900_Wait
372
SIS900_DoneWait_e:
603
SIS900_DoneWait_e:
373
if defined SIS900_DEBUG
604
if defined SIS900_DEBUG
374
   mov esi, SIS900_Debug_Reset_Failed
605
   mov esi, SIS900_Debug_Reset_Failed
375
   call sys_msg_board_str
606
   call sys_msg_board_str
376
end if
607
end if
377
SIS900_DoneWait:
608
SIS900_DoneWait:
-
 
609
   pop      ebx
378
   ;*******Set Configuration Register depending on Card Revision********
610
   ;*******Set Configuration Register depending on Card Revision********
379
   lea      edx,[ebp+SIS900_cfg]
611
   lea      edx,[ebp+SIS900_cfg]
380
   mov      eax, SIS900_PESEL               ; Configuration Register Bit
612
   mov      eax, SIS900_PESEL               ; Configuration Register Bit
381
   mov      bl, [SIS900_pci_revision]   ; card revision
613
   mov      cl, [SIS900_pci_revision]   ; card revision
382
   mov      cl, SIS635A_900_REV         ; Check card revision
-
 
383
   cmp      bl, cl
614
   cmp      cl, SIS635A_900_REV
384
   je       SIS900_RevMatch
615
   je       SIS900_RevMatch
385
   mov      cl, SIS900B_900_REV         ; Check card revision
616
   cmp      cl, SIS900B_900_REV         ; Check card revision
386
   cmp      bl, cl
-
 
387
   je       SIS900_RevMatch
617
   je       SIS900_RevMatch
388
   out      dx, eax                                 ; no revision match
618
   out      dx, eax                                 ; no revision match
389
   jmp      SIS900_Reset_Complete
619
   jmp      SIS900_Reset_Complete
390
SIS900_RevMatch:                                        ; Revision match
620
SIS900_RevMatch:                                        ; Revision match
391
   or       eax, SIS900_RND_CNT         ; Configuration Register Bit
621
   or       eax, SIS900_RND_CNT         ; Configuration Register Bit
392
   out      dx, eax
622
   out      dx, eax
393
SIS900_Reset_Complete:
623
SIS900_Reset_Complete:
394
   mov      eax, [pci_data]
624
   xor      eax, eax
395
   mov      [eth_status], eax
625
   pop      ebp
396
   ret
626
   ret
397
 
627
 
398
;***************************************************************************
628
;***************************************************************************
399
; Function: sis_init_rxfilter
629
; Function: sis_init_rxfilter
400
;
630
;
401
; Description: sets receive filter address to our MAC address
631
; Description: sets receive filter address to our MAC address
402
;
632
;
403
; Arguments:
633
; Arguments:
404
;
634
;
405
; returns:
635
; returns:
406
;done+
636
;done+
407
;***************************************************************************
637
;***************************************************************************
408
SIS900_init_rxfilter:
638
SIS900_init_rxfilter:
-
 
639
   push     ebp
-
 
640
   mov      ebp, [ebx+device.io_addr]   ; base address
409
   ;****Get Receive Filter Control Register ********
641
   ;****Get Receive Filter Control Register ********
410
   mov      ebp, [io_addr]          ; base address
-
 
411
   lea      edx,[ebp+SIS900_rfcr]
642
   lea      edx,[ebp+SIS900_rfcr]
412
   in       eax, dx                         ; get register
643
   in       eax, dx                         ; get register
413
   push     eax
644
   push     eax
414
   ;****disable packet filtering before setting filter*******
645
   ;****disable packet filtering before setting filter*******
415
   mov      eax, SIS900_RFEN    ;move receive filter enable flag
646
   mov      eax, SIS900_RFEN    ;move receive filter enable flag
416
   not      eax                         ;1s complement
647
   not      eax                         ;1s complement
417
   pop      ebx                         ;and with our saved register
-
 
418
   and      eax, ebx                    ;disable receiver
648
   and      eax, [esp]                  ;disable receiver
419
   push     ebx                 ;save filter for another use
-
 
420
   out      dx, eax                     ;set receive disabled
649
   out      dx, eax                     ;set receive disabled
421
   ;********load MAC addr to filter data register*********
650
   ;********load MAC addr to filter data register*********
422
   xor      ecx, ecx
651
   xor      ecx, ecx
423
SIS900_RXINT_Mac_Write:
652
SIS900_RXINT_Mac_Write:
424
   ;high word of eax tells card which mac byte to write
653
   ;high word of eax tells card which mac byte to write
425
   mov      eax, ecx
654
   mov      eax, ecx
426
   lea      edx,[ebp+SIS900_rfcr]
655
   lea      edx,[ebp+SIS900_rfcr]
427
   shl      eax, 16                                             ;
656
   shl      eax, 16                                             ;
428
   out      dx, eax                                             ;
657
   out      dx, eax                                             ;
429
   lea      edx,[ebp+SIS900_rfdr]
658
   lea      edx,[ebp+SIS900_rfdr]
430
   mov      ax,  word [node_addr+ecx*2] ; Get Mac ID word
659
   mov      ax,  word [ebx+device.mac+ecx*2] ; Get Mac ID word
431
   out      dx, ax                                              ; Send Mac ID
660
   out      dx, ax                                              ; Send Mac ID
432
   inc      cl                                                  ; send next word
661
   inc      cl                                                  ; send next word
433
   cmp      cl, 3                                               ; more to send?
662
   cmp      cl, 3                                               ; more to send?
434
   jne      SIS900_RXINT_Mac_Write
663
   jne      SIS900_RXINT_Mac_Write
435
   ;********enable packet filitering *****
664
   ;********enable packet filitering *****
436
   pop      eax                             ;old register value
665
   pop      eax                             ;old register value
437
   lea      edx,[ebp+SIS900_rfcr]
666
   lea      edx,[ebp+SIS900_rfcr]
438
   or       eax, SIS900_RFEN    ;enable filtering
667
   or       eax, SIS900_RFEN    ;enable filtering
439
   out      dx, eax             ;set register
668
   out      dx, eax             ;set register
-
 
669
   pop      ebp
440
   ret
670
   ret
441
 
671
 
442
;***************************************************************************
672
;***************************************************************************
443
;*
673
;*
444
;* Function: sis_init_txd
674
;* Function: sis_init_txd
445
;*
675
;*
446
;* Description: initializes the Tx descriptor
676
;* Description: initializes the Tx descriptor
447
;*
677
;*
448
;* Arguments:
678
;* Arguments:
449
;*
679
;*
450
;* returns:
680
;* returns:
451
;*done
681
;*done
452
;***************************************************************************
682
;***************************************************************************
453
SIS900_init_txd:
683
SIS900_init_txd:
454
   ;********** initialize TX descriptor **************
684
   ;********** initialize TX descriptor **************
455
   mov     [txd], dword 0       ;put link to next descriptor in link field
685
   mov     [ebx+device.txd], dword 0       ;put link to next descriptor in link field
456
   mov     [txd+4],dword 0      ;clear status field
686
   mov     [ebx+device.txd+4],dword 0      ;clear status field
-
 
687
   lea     eax, [ebx+0x1000]
-
 
688
   call    GetPgAddr
457
   mov     [txd+8], dword txb - OS_BASE   ;save address to buffer ptr field
689
   mov     [ebx+device.txd+8], eax   ;save address to buffer ptr field
458
   ;*************** load Transmit Descriptor Register ***************
690
   ;*************** load Transmit Descriptor Register ***************
459
   mov     dx, [io_addr]            ; base address
691
   mov     edx, [ebx+device.io_addr]        ; base address
460
   add     dx, SIS900_txdp      ; TX Descriptor Pointer
692
   add     edx, SIS900_txdp      ; TX Descriptor Pointer
461
   mov     eax, txd - OS_BASE               ; First Descriptor
693
   add     eax, device.txd - 0x1000        ; First Descriptor
462
   out     dx, eax                              ; move the pointer
694
   out     dx, eax                             ; move the pointer
463
   ret
695
   ret
464
 
696
 
465
;***************************************************************************
697
;***************************************************************************
466
;* Function: sis_init_rxd
698
;* Function: sis_init_rxd
467
;*
699
;*
468
;* Description: initializes the Rx descriptor ring
700
;* Description: initializes the Rx descriptor ring
469
;*
701
;*
470
;* Arguments:
702
;* Arguments:
471
;*
703
;*
472
;* Returns:
704
;* Returns:
473
;*done
705
;*done
474
;***************************************************************************
706
;***************************************************************************
475
SIS900_init_rxd:
707
SIS900_init_rxd:
476
   xor      ecx,ecx
708
   xor      ecx,ecx
477
   mov      [cur_rx], cl                                        ;Set cuurent rx discriptor to 0
709
   mov      [cur_rx], cl                                        ;Set cuurent rx discriptor to 0
-
 
710
   mov      eax, ebx
-
 
711
   call     GetPgAddr
-
 
712
   mov      esi, eax
478
   ;******** init RX descriptors ********
713
   ;******** init RX descriptors ********
479
SIS900_init_rxd_Loop:
714
SIS900_init_rxd_Loop:
480
    mov     eax, ecx                                        ;current descriptor
715
    mov     edx, ecx                                        ;current descriptor
481
    imul    eax, 12                         ;
716
    imul    edx, 12                         ;
482
    mov     ebx, ecx                                        ;determine next link descriptor
717
    mov     eax, ecx                                        ;determine next link descriptor
483
    inc     ebx                             ;
718
    inc     eax                             ;
484
    cmp     ebx, NUM_RX_DESC                ;
719
    cmp     eax, NUM_RX_DESC                ;
485
    jne     SIS900_init_rxd_Loop_0          ;
720
    jne     SIS900_init_rxd_Loop_0          ;
486
    xor     ebx, ebx                        ;
721
    xor     eax, eax                        ;
487
SIS900_init_rxd_Loop_0:                    ;
722
SIS900_init_rxd_Loop_0:                    ;
488
    imul    ebx, 12                         ;
723
    imul    eax, 12                         ;
489
    add     ebx, rxd - OS_BASE              ;
724
    lea     eax, [eax+esi+device.rxd]
490
    mov     [rxd+eax], ebx                                      ;save link to next descriptor
725
    mov     [ebx+device.rxd+edx], eax                                      ;save link to next descriptor
491
    mov     [rxd+eax+4],dword RX_BUFF_SZ        ;status bits init to buf size
726
    mov     [ebx+device.rxd+edx+4],dword RX_BUFF_SZ        ;status bits init to buf size
492
    mov     ebx, ecx                                            ;find where the buf is located
727
    mov     eax, ecx                                            ;find where the buf is located
493
    imul    ebx,RX_BUFF_SZ                  ;
728
    imul    eax,RX_BUFF_SZ                  ;
494
    add     ebx, rxb - OS_BASE              ;
729
    lea     eax, [eax+esi+0x1000+NUM_TX_DESC*TX_BUFF_SZ]
495
    mov     [rxd+eax+8], ebx                            ;save buffer pointer
730
    mov     [ebx+device.rxd+edx+8], eax                            ;save buffer pointer
496
    inc     ecx                                                     ;next descriptor
731
    inc     ecx                                                     ;next descriptor
497
    cmp     ecx, NUM_RX_DESC                ;
732
    cmp     ecx, NUM_RX_DESC                ;
498
    jne     SIS900_init_rxd_Loop            ;
733
    jne     SIS900_init_rxd_Loop            ;
499
    ;********* load Receive Descriptor Register with address of first
734
    ;********* load Receive Descriptor Register with address of first
500
    ; descriptor*********
735
    ; descriptor*********
501
    mov     dx, [io_addr]
736
    mov     edx, [ebx+device.io_addr]
502
    add     dx, SIS900_rxdp
737
    add     edx, SIS900_rxdp
503
    mov     eax, rxd - OS_BASE
738
    lea     eax, [esi+device.rxd]
504
    out     dx, eax
739
    out     dx, eax
505
    ret
740
    ret
506
 
741
 
507
;***************************************************************************
742
;***************************************************************************
508
;* Function: sis900_set_tx_mode
743
;* Function: sis900_set_tx_mode
509
;*
744
;*
510
;* Description:
745
;* Description:
511
;*    sets the transmit mode to allow for full duplex
746
;*    sets the transmit mode to allow for full duplex
512
;*
747
;*
513
;*
748
;*
514
;* Arguments:
749
;* Arguments:
515
;*
750
;*
516
;* Returns:
751
;* Returns:
517
;*
752
;*
518
;* Comments:
753
;* Comments:
519
;*     If you are having problems transmitting packet try changing the
754
;*     If you are having problems transmitting packet try changing the
520
;*     Max DMA Burst, Possible settings are as follows:
755
;*     Max DMA Burst, Possible settings are as follows:
521
;*         0x00000000 = 512 bytes
756
;*         0x00000000 = 512 bytes
522
;*         0x00100000 = 4 bytes
757
;*         0x00100000 = 4 bytes
523
;*         0x00200000 = 8 bytes
758
;*         0x00200000 = 8 bytes
524
;*         0x00300000 = 16 bytes
759
;*         0x00300000 = 16 bytes
525
;*         0x00400000 = 32 bytes
760
;*         0x00400000 = 32 bytes
526
;*         0x00500000 = 64 bytes
761
;*         0x00500000 = 64 bytes
527
;*         0x00600000 = 128 bytes
762
;*         0x00600000 = 128 bytes
528
;*         0x00700000 = 256 bytes
763
;*         0x00700000 = 256 bytes
529
;***************************************************************************
764
;***************************************************************************
530
SIS900_set_tx_mode:
765
SIS900_set_tx_mode:
-
 
766
   push     ebp
531
   mov      ebp,[io_addr]
767
   mov      ebp,[ebx+device.io_addr]
532
   lea      edx,[ebp+SIS900_cr]
768
   lea      edx,[ebp+SIS900_cr]
533
   in       eax, dx                         ; Get current Command Register
769
   in       eax, dx                         ; Get current Command Register
534
   or       eax, SIS900_TxENA   ;Enable Receive
770
   or       eax, SIS900_TxENA   ;Enable Receive
535
   out      dx, eax
771
   out      dx, eax
536
   lea      edx,[ebp+SIS900_txcfg]; Transmit config Register offset
772
   lea      edx,[ebp+SIS900_txcfg]; Transmit config Register offset
537
   mov      eax, SIS900_ATP             ;allow automatic padding
773
   mov      eax, SIS900_ATP             ;allow automatic padding
538
   or       eax, SIS900_HBI             ;allow heartbeat ignore
774
   or       eax, SIS900_HBI             ;allow heartbeat ignore
539
   or       eax, SIS900_CSI             ;allow carrier sense ignore
775
   or       eax, SIS900_CSI             ;allow carrier sense ignore
540
   or       eax, 0x00600000     ;Max DMA Burst
776
   or       eax, 0x00600000     ;Max DMA Burst
541
   or       eax, 0x00000100     ;TX Fill Threshold
777
   or       eax, 0x00000100     ;TX Fill Threshold
542
   or       eax, 0x00000020     ;TX Drain Threshold
778
   or       eax, 0x00000020     ;TX Drain Threshold
543
   out      dx, eax
779
   out      dx, eax
-
 
780
   pop      ebp
544
   ret
781
   ret
545
 
782
 
546
;***************************************************************************
783
;***************************************************************************
547
;* Function: sis900_set_rx_mode
784
;* Function: sis900_set_rx_mode
548
;*
785
;*
549
;* Description:
786
;* Description:
550
;*    sets the receive mode to accept all broadcast packets and packets
787
;*    sets the receive mode to accept all broadcast packets and packets
551
;*    with our MAC address, and reject all multicast packets.  Also allows
788
;*    with our MAC address, and reject all multicast packets.  Also allows
552
;*    full-duplex
789
;*    full-duplex
553
;*
790
;*
554
;* Arguments:
791
;* Arguments:
555
;*
792
;*
556
;* Returns:
793
;* Returns:
557
;*
794
;*
558
;* Comments:
795
;* Comments:
559
;*     If you are having problems receiving packet try changing the
796
;*     If you are having problems receiving packet try changing the
560
;*     Max DMA Burst, Possible settings are as follows:
797
;*     Max DMA Burst, Possible settings are as follows:
561
;*         0x00000000 = 512 bytes
798
;*         0x00000000 = 512 bytes
562
;*         0x00100000 = 4 bytes
799
;*         0x00100000 = 4 bytes
563
;*         0x00200000 = 8 bytes
800
;*         0x00200000 = 8 bytes
564
;*         0x00300000 = 16 bytes
801
;*         0x00300000 = 16 bytes
565
;*         0x00400000 = 32 bytes
802
;*         0x00400000 = 32 bytes
566
;*         0x00500000 = 64 bytes
803
;*         0x00500000 = 64 bytes
567
;*         0x00600000 = 128 bytes
804
;*         0x00600000 = 128 bytes
568
;*         0x00700000 = 256 bytes
805
;*         0x00700000 = 256 bytes
569
;***************************************************************************
806
;***************************************************************************
570
SIS900_mc_filter: times 16 dw 0
-
 
571
SIS900_set_rx_mode:
807
SIS900_set_rx_mode:
-
 
808
   push     ebp
572
   mov      ebp,[io_addr]
809
   mov      ebp,[ebx+device.io_addr]
573
    ;**************update Multicast Hash Table in Receive Filter
810
    ;**************update Multicast Hash Table in Receive Filter
574
   mov      ebx, 0xffff
-
 
575
   xor      cl, cl
811
   xor      cl, cl
576
SIS900_set_rx_mode_Loop:
812
SIS900_set_rx_mode_Loop:
577
   mov      eax, ecx
813
   mov      eax, ecx
578
   shl      eax, 1
814
   shl      eax, 1
579
   mov      [SIS900_mc_filter+eax], bx
-
 
580
   lea      edx,[ebp+SIS900_rfcr]           ; Receive Filter Control Reg offset
815
   lea      edx,[ebp+SIS900_rfcr]           ; Receive Filter Control Reg offset
581
   mov      eax, 4                                          ;determine table entry
816
   mov      eax, 4                                          ;determine table entry
582
   add      al, cl
817
   add      al, cl
583
   shl      eax, 16
818
   shl      eax, 16
584
   out      dx, eax                                         ;tell card which entry to modify
819
   out      dx, eax                                         ;tell card which entry to modify
585
   lea      edx,[ebp+SIS900_rfdr]           ; Receive Filter Control Reg offset
820
   lea      edx,[ebp+SIS900_rfdr]           ; Receive Filter Control Reg offset
586
   mov      eax, ebx                                ;entry value
821
   mov      eax, 0xffff                             ;entry value
587
   out      dx, ax                                          ;write value to table in card
822
   out      dx, ax                                          ;write value to table in card
588
   inc      cl                                              ;next entry
823
   inc      cl                                              ;next entry
589
   cmp      cl,[sis900_table_entries]   ;
824
   cmp      cl,[sis900_table_entries]   ;
590
   jl       SIS900_set_rx_mode_Loop
825
   jl       SIS900_set_rx_mode_Loop
591
   ;*******Set Receive Filter Control Register*************
826
   ;*******Set Receive Filter Control Register*************
592
   lea      edx,[ebp+SIS900_rfcr]       ; Receive Filter Control Register offset
827
   lea      edx,[ebp+SIS900_rfcr]       ; Receive Filter Control Register offset
593
   mov      eax, SIS900_RFAAB           ;accecpt all broadcast packets
828
   mov      eax, SIS900_RFAAB           ;accecpt all broadcast packets
594
   or       eax, SIS900_RFAAM           ;accept all multicast packets
829
   or       eax, SIS900_RFAAM           ;accept all multicast packets
595
   or       eax, SIS900_RFAAP           ;Accept all packets
830
   or       eax, SIS900_RFAAP           ;Accept all packets
596
   or       eax, SIS900_RFEN            ;enable receiver filter
831
   or       eax, SIS900_RFEN            ;enable receiver filter
597
   out      dx, eax
832
   out      dx, eax
598
   ;******Enable Receiver************
833
   ;******Enable Receiver************
599
   lea      edx,[ebp+SIS900_cr] ; Command Register offset
834
   lea      edx,[ebp+SIS900_cr] ; Command Register offset
600
   in       eax, dx                         ; Get current Command Register
835
   in       eax, dx                         ; Get current Command Register
601
   or       eax, SIS900_RxENA   ;Enable Receive
836
   or       eax, SIS900_RxENA   ;Enable Receive
602
   out      dx, eax
837
   out      dx, eax
603
   ;*********Set
838
   ;*********Set
604
   lea      edx,[ebp+SIS900_rxcfg]      ; Receive Config Register offset
839
   lea      edx,[ebp+SIS900_rxcfg]      ; Receive Config Register offset
605
   mov      eax, SIS900_ATX                     ;Accept Transmit Packets
840
   mov      eax, SIS900_ATX                     ;Accept Transmit Packets
606
                                    ; (Req for full-duplex and PMD Loopback)
841
                                    ; (Req for full-duplex and PMD Loopback)
607
   or       eax, 0x00600000                     ;Max DMA Burst
842
   or       eax, 0x00600000                     ;Max DMA Burst
608
   or       eax, 0x00000002                     ;RX Drain Threshold, 8X8 bytes or 64bytes
843
   or       eax, 0x00000002                     ;RX Drain Threshold, 8X8 bytes or 64bytes
609
   out      dx, eax                                     ;
844
   out      dx, eax                                     ;
-
 
845
   pop      ebp
610
   ret
846
   ret
611
 
847
 
612
;***************************************************************************
848
;***************************************************************************
613
; *     SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
849
; *     SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
614
; *     @pci_dev: the sis900 pci device
850
; *     @pci_dev: the sis900 pci device
615
; *     @net_dev: the net device to get address for
851
; *     @net_dev: the net device to get address for
616
; *
852
; *
617
; *     SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
853
; *     SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
618
; *     is shared by
854
; *     is shared by
619
; *     LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
855
; *     LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
620
; *     and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
856
; *     and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
621
; *     by LAN, otherwise is not. After MAC address is read from EEPROM, send
857
; *     by LAN, otherwise is not. After MAC address is read from EEPROM, send
622
; *     EEDONE signal to refuse EEPROM access by LAN.
858
; *     EEDONE signal to refuse EEPROM access by LAN.
623
; *     The EEPROM map of SiS962 or SiS963 is different to SiS900.
859
; *     The EEPROM map of SiS962 or SiS963 is different to SiS900.
624
; *     The signature field in SiS962 or SiS963 spec is meaningless.
860
; *     The signature field in SiS962 or SiS963 spec is meaningless.
625
; *     MAC address is read into @net_dev->dev_addr.
861
; *     MAC address is read into @net_dev->dev_addr.
626
; *done
862
; *done
627
;*
863
;*
628
;* Return 0 is EAX = failure
864
;* Return 0 is EAX = failure
629
;*Done+
865
;*Done+
630
;***************************************************************************
866
;***************************************************************************
631
if defined SIS900_DEBUG
867
if defined SIS900_DEBUG
632
SIS900_Debug_Str_GetMac_Start db 'Attempting to get SIS900 Mac ID: ',13,10,0
868
SIS900_Debug_Str_GetMac_Start db 'Attempting to get SIS900 Mac ID: ',13,10,0
633
SIS900_Debug_Str_GetMac_Failed db 'Access to EEprom Failed',13,10,0
869
SIS900_Debug_Str_GetMac_Failed db 'Access to EEprom Failed',13,10,0
634
SIS900_Debug_Str_GetMac_Address db 'Your Mac ID is: ',0
870
SIS900_Debug_Str_GetMac_Address db 'Your Mac ID is: ',0
635
SIS900_Debug_Str_GetMac_Address2 db 'Your SIS96x Mac ID is: ',0
871
SIS900_Debug_Str_GetMac_Address2 db 'Your SIS96x Mac ID is: ',0
636
end if
872
end if
637
SIS960_get_mac_addr:
873
SIS960_get_mac_addr:
-
 
874
   push     ebp
638
   mov      ebp,[io_addr]
875
   mov      ebp,[ebx+device.io_addr]
639
   ;**********Send Request for eeprom access*********************
876
   ;**********Send Request for eeprom access*********************
640
   lea      edx,[ebp+SIS900_mear]               ; Eeprom access register
877
   lea      edx,[ebp+SIS900_mear]               ; Eeprom access register
641
   mov      eax, SIS900_EEREQ                   ; Request access to eeprom
878
   mov      eax, SIS900_EEREQ                   ; Request access to eeprom
642
   out      dx, eax                                             ; Send request
879
   out      dx, eax                                             ; Send request
643
   xor      ebx,ebx                                             ;
880
   xor      ecx,ecx                                             ;
644
   ;******Loop 4000 times and if access not granted error out*****
881
   ;******Loop 4000 times and if access not granted error out*****
645
SIS96X_Get_Mac_Wait:
882
SIS96X_Get_Mac_Wait:
646
   in       eax, dx                                     ;get eeprom status
883
   in       eax, dx                                     ;get eeprom status
647
   and      eax, SIS900_EEGNT       ;see if eeprom access granted flag is set
884
   and      eax, SIS900_EEGNT       ;see if eeprom access granted flag is set
648
   jnz      SIS900_Got_EEP_Access       ;if it is, go access the eeprom
885
   jnz      SIS900_Got_EEP_Access       ;if it is, go access the eeprom
649
   inc      ebx                                         ;else keep waiting
886
   inc      ecx                                         ;else keep waiting
650
   cmp      ebx, 4000                           ;have we tried 4000 times yet?
887
   cmp      ecx, 4000                           ;have we tried 4000 times yet?
651
   jl       SIS96X_Get_Mac_Wait     ;if not ask again
888
   jl       SIS96X_Get_Mac_Wait     ;if not ask again
652
   xor      eax, eax                ;return zero in eax indicating failure
889
   xor      eax, eax                ;return zero in eax indicating failure
653
   ;*******Debug **********************
890
   ;*******Debug **********************
654
if defined SIS900_DEBUG
891
if defined SIS900_DEBUG
655
   mov esi,SIS900_Debug_Str_GetMac_Failed
892
   mov esi,SIS900_Debug_Str_GetMac_Failed
656
   call sys_msg_board_str
893
   call sys_msg_board_str
657
end if
894
end if
658
   jmp SIS960_get_mac_addr_done
895
   jmp SIS960_get_mac_addr_done
659
   ;**********EEprom access granted, read MAC from card*************
896
   ;**********EEprom access granted, read MAC from card*************
660
SIS900_Got_EEP_Access:
897
SIS900_Got_EEP_Access:
661
    ; zero based so 3-16 bit reads will take place
898
    ; zero based so 3-16 bit reads will take place
662
   mov      ecx, 2
899
   mov      ecx, 2
663
SIS96x_mac_read_loop:
900
SIS96x_mac_read_loop:
664
   mov      eax, SIS900_EEPROMMACAddr    ;Base Mac Address
901
   mov      eax, SIS900_EEPROMMACAddr    ;Base Mac Address
665
   add      eax, ecx                                 ;Current Mac Byte Offset
902
   add      eax, ecx                                 ;Current Mac Byte Offset
666
   push     ecx
903
   push     ecx
667
   call     sis900_read_eeprom           ;try to read 16 bits
904
   call     sis900_read_eeprom           ;try to read 16 bits
668
   pop      ecx
905
   pop      ecx
669
   mov      [node_addr+ecx*2], ax        ;save 16 bits to the MAC ID varible
906
   mov      word [ebx+device.mac+ecx*2], ax        ;save 16 bits to the MAC ID varible
670
   dec      ecx                          ;one less word to read
907
   dec      ecx                          ;one less word to read
671
   jns      SIS96x_mac_read_loop         ;if more read more
908
   jns      SIS96x_mac_read_loop         ;if more read more
672
   mov      eax, 1                       ;return non-zero indicating success
909
   mov      eax, 1                       ;return non-zero indicating success
673
   ;*******Debug Print MAC ID to debug window**********************
910
   ;*******Debug Print MAC ID to debug window**********************
674
if defined SIS900_DEBUG
911
if defined SIS900_DEBUG
675
   mov esi,SIS900_Debug_Str_GetMac_Address2
912
   mov esi,SIS900_Debug_Str_GetMac_Address2
676
   call sys_msg_board_str
913
   call sys_msg_board_str
677
   mov edx, node_addr
914
   lea edx, [ebx+device.mac]
678
   call Create_Mac_String
915
   call Create_Mac_String
679
end if
916
end if
680
   ;**********Tell EEPROM We are Done Accessing It*********************
917
   ;**********Tell EEPROM We are Done Accessing It*********************
681
SIS960_get_mac_addr_done:
918
SIS960_get_mac_addr_done:
682
   lea      edx,[ebp+SIS900_mear]               ; Eeprom access register
919
   lea      edx,[ebp+SIS900_mear]               ; Eeprom access register
683
   mov      eax, SIS900_EEDONE           ;tell eeprom we are done
920
   mov      eax, SIS900_EEDONE           ;tell eeprom we are done
684
   out      dx,eax
921
   out      dx,eax
-
 
922
   pop      ebp
685
   ret
923
   ret
686
;***************************************************************************
924
;***************************************************************************
687
;*      sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
925
;*      sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
688
;*      @pci_dev: the sis900 pci device
926
;*      @pci_dev: the sis900 pci device
689
;*      @net_dev: the net device to get address for
927
;*      @net_dev: the net device to get address for
690
;*
928
;*
691
;*      Older SiS900 and friends, use EEPROM to store MAC address.
929
;*      Older SiS900 and friends, use EEPROM to store MAC address.
692
;*      MAC address is read from read_eeprom() into @net_dev->dev_addr.
930
;*      MAC address is read from read_eeprom() into @net_dev->dev_addr.
693
;* done/untested
931
;* done/untested
694
;***************************************************************************
932
;***************************************************************************
695
SIS900_get_mac_addr:
933
SIS900_get_mac_addr:
696
   ;*******Debug **********************
934
   ;*******Debug **********************
697
if defined SIS900_DEBUG
935
if defined SIS900_DEBUG
698
   mov esi,SIS900_Debug_Str_GetMac_Start
936
   mov esi,SIS900_Debug_Str_GetMac_Start
699
   call sys_msg_board_str
937
   call sys_msg_board_str
700
end if
938
end if
701
   ;******** check to see if we have sane EEPROM *******
939
   ;******** check to see if we have sane EEPROM *******
702
   mov      eax, SIS900_EEPROMSignature  ;Base Eeprom Signature
940
   mov      eax, SIS900_EEPROMSignature  ;Base Eeprom Signature
703
   call     sis900_read_eeprom           ;try to read 16 bits
941
   call     sis900_read_eeprom           ;try to read 16 bits
704
   cmp ax, 0xffff
942
   cmp ax, 0xffff
705
   je SIS900_Bad_Eeprom
943
   je SIS900_Bad_Eeprom
706
   cmp ax, 0
944
   cmp ax, 0
707
   je SIS900_Bad_Eeprom
945
   je SIS900_Bad_Eeprom
708
   ;**************Read MacID**************
946
   ;**************Read MacID**************
709
   ; zero based so 3-16 bit reads will take place
947
   ; zero based so 3-16 bit reads will take place
710
   mov      ecx, 2
948
   mov      ecx, 2
711
SIS900_mac_read_loop:
949
SIS900_mac_read_loop:
712
   mov      eax, SIS900_EEPROMMACAddr    ;Base Mac Address
950
   mov      eax, SIS900_EEPROMMACAddr    ;Base Mac Address
713
   add      eax, ecx                                 ;Current Mac Byte Offset
951
   add      eax, ecx                                 ;Current Mac Byte Offset
714
   push     ecx
952
   push     ecx
715
   call     sis900_read_eeprom           ;try to read 16 bits
953
   call     sis900_read_eeprom           ;try to read 16 bits
716
   pop      ecx
954
   pop      ecx
717
   mov      [node_addr+ecx*2], ax        ;save 16 bits to the MAC ID storage
955
   mov      word [ebx+device.mac+ecx*2], ax        ;save 16 bits to the MAC ID storage
718
   dec      ecx                          ;one less word to read
956
   dec      ecx                          ;one less word to read
719
   jns      SIS900_mac_read_loop         ;if more read more
957
   jns      SIS900_mac_read_loop         ;if more read more
720
   mov      eax, 1                       ;return non-zero indicating success
958
   mov      eax, 1                       ;return non-zero indicating success
721
   ;*******Debug Print MAC ID to debug window**********************
959
   ;*******Debug Print MAC ID to debug window**********************
722
if defined SIS900_DEBUG
960
if defined SIS900_DEBUG
723
   mov esi,SIS900_Debug_Str_GetMac_Address
961
   mov esi,SIS900_Debug_Str_GetMac_Address
724
   call sys_msg_board_str
962
   call sys_msg_board_str
725
   mov edx, node_addr
963
   lea edx, [ebx+device.mac]
726
   call Create_Mac_String
964
   call Create_Mac_String
727
end if
965
end if
728
   ret
966
   ret
729
 
967
 
730
SIS900_Bad_Eeprom:
968
SIS900_Bad_Eeprom:
731
   xor eax, eax
969
   xor eax, eax
732
   ;*******Debug **********************
970
   ;*******Debug **********************
733
if defined SIS900_DEBUG
971
if defined SIS900_DEBUG
734
   mov esi,SIS900_Debug_Str_GetMac_Failed
972
   mov esi,SIS900_Debug_Str_GetMac_Failed
735
   call sys_msg_board_str
973
   call sys_msg_board_str
736
end if
974
end if
737
   ret
975
   ret
738
;***************************************************************************
976
;***************************************************************************
739
;*      Get_Mac_SIS635_900_REV: - Get MAC address for model 635
977
;*      Get_Mac_SIS635_900_REV: - Get MAC address for model 635
740
;*
978
;*
741
;*
979
;*
742
;***************************************************************************
980
;***************************************************************************
743
Get_Mac_SIS635_900_REV:
981
Get_Mac_SIS635_900_REV:
744
if defined SIS900_DEBUG
982
if defined SIS900_DEBUG
745
    mov     esi,SIS900_Debug_Str_GetMac_Start
983
    mov     esi,SIS900_Debug_Str_GetMac_Start
746
    call    sys_msg_board_str
984
    call    sys_msg_board_str
747
end if
985
end if
-
 
986
    push    ebp
748
    mov     ebp,[io_addr]
987
    mov     ebp,[ebx+device.io_addr]
749
    lea     edx,[ebp+SIS900_rfcr]
988
    lea     edx,[ebp+SIS900_rfcr]
750
    in      eax,dx
989
    in      eax,dx
751
    mov     edi,eax ; EDI=rfcrSave
990
    mov     edi,eax ; EDI=rfcrSave
752
    lea     edx,[ebp+SIS900_cr]
991
    lea     edx,[ebp+SIS900_cr]
753
    or      eax,SIS900_RELOAD
992
    or      eax,SIS900_RELOAD
754
    out     dx,eax
993
    out     dx,eax
755
    xor     eax,eax
994
    xor     eax,eax
756
    out     dx,eax
995
    out     dx,eax
757
    ; Disable packet filtering before setting filter
996
    ; Disable packet filtering before setting filter
758
    lea     edx,[ebp+SIS900_rfcr]
997
    lea     edx,[ebp+SIS900_rfcr]
759
    mov     eax,edi
998
    mov     eax,edi
760
    and     edi,not SIS900_RFEN
999
    and     edi,not SIS900_RFEN
761
    out     dx,eax
1000
    out     dx,eax
762
    ; Load MAC to filter data register
1001
    ; Load MAC to filter data register
763
    xor     ecx,ecx
1002
    xor     ecx,ecx
764
    mov     esi,node_addr
1003
    lea     esi,[ebx+device.mac]
765
.get_mac_loop:
1004
.get_mac_loop:
766
    lea     edx,[ebp+SIS900_rfcr]
1005
    lea     edx,[ebp+SIS900_rfcr]
767
    mov     eax,ecx
1006
    mov     eax,ecx
768
    shl     eax,SIS900_RFADDR_shift
1007
    shl     eax,SIS900_RFADDR_shift
769
    out     dx,eax
1008
    out     dx,eax
770
    lea     edx,[ebp+SIS900_rfdr]
1009
    lea     edx,[ebp+SIS900_rfdr]
771
    in      eax,dx
1010
    in      eax,dx
772
    mov     [esi],ax
1011
    mov     [esi],ax
773
    add     esi,2
1012
    add     esi,2
774
    inc     ecx
1013
    inc     ecx
775
    cmp     ecx,3
1014
    cmp     ecx,3
776
    jne .get_mac_loop
1015
    jne .get_mac_loop
777
    ; Enable packet filtering
1016
    ; Enable packet filtering
778
    ;lea     edx,[ebp+SIS900_rfcr]
1017
    ;lea     edx,[ebp+SIS900_rfcr]
779
    ;mov     eax,edi
1018
    ;mov     eax,edi
780
    ;or      eax,SIS900_RFEN
1019
    ;or      eax,SIS900_RFEN
781
    ;out     dx, eax
1020
    ;out     dx, eax
782
   ;*******Debug Print MAC ID to debug window**********************
1021
   ;*******Debug Print MAC ID to debug window**********************
783
if defined SIS900_DEBUG
1022
if defined SIS900_DEBUG
784
    mov     esi,SIS900_Debug_Str_GetMac_Address
1023
    mov     esi,SIS900_Debug_Str_GetMac_Address
785
    call    sys_msg_board_str
1024
    call    sys_msg_board_str
786
    mov     edx, node_addr
1025
    lea     edx, [ebx+device.mac]
787
    call    Create_Mac_String
1026
    call    Create_Mac_String
788
end if
1027
end if
-
 
1028
    pop     ebp
789
    ret
1029
    ret
790
;***************************************************************************
1030
;***************************************************************************
791
;* Function: sis900_read_eeprom
1031
;* Function: sis900_read_eeprom
792
;*
1032
;*
793
;* Description: reads and returns a given location from EEPROM
1033
;* Description: reads and returns a given location from EEPROM
794
;*
1034
;*
795
;* Arguments: eax - location:       requested EEPROM location
1035
;* Arguments: eax - location:       requested EEPROM location
796
;*
1036
;*
797
;* Returns:   eax :                contents of requested EEPROM location
1037
;* Returns:   eax :                contents of requested EEPROM location
798
;*
1038
;*
799
; Read Serial EEPROM through EEPROM Access Register, Note that location is
1039
; Read Serial EEPROM through EEPROM Access Register, Note that location is
800
;   in word (16 bits) unit */
1040
;   in word (16 bits) unit */
801
;done+
1041
;done+
802
;***************************************************************************
1042
;***************************************************************************
803
sis900_read_eeprom:
1043
sis900_read_eeprom:
804
   push      esi
1044
   push      esi
805
   push      edx
1045
   push      edx
806
   push      ecx
1046
   push      ecx
807
   push      ebx
1047
   push      ebx
-
 
1048
   push      ebp
808
   mov       ebp,[io_addr]
1049
   mov       ebp,[ebx+device.io_addr]
809
   mov       ebx, eax              ;location of Mac byte to read
1050
   mov       ebx, eax              ;location of Mac byte to read
810
   or        ebx, SIS900_EEread    ;
1051
   or        ebx, SIS900_EEread    ;
811
   lea       edx,[ebp+SIS900_mear] ; Eeprom access register
1052
   lea       edx,[ebp+SIS900_mear] ; Eeprom access register
812
   xor       eax, eax              ; start send
1053
   xor       eax, eax              ; start send
813
   out       dx,eax
1054
   out       dx,eax
814
   call      SIS900_Eeprom_Delay_1
1055
   call      SIS900_Eeprom_Delay_1
815
   mov       eax, SIS900_EECLK
1056
   mov       eax, SIS900_EECLK
816
   out       dx, eax
1057
   out       dx, eax
817
   call      SIS900_Eeprom_Delay_1
1058
   call      SIS900_Eeprom_Delay_1
818
    ;************ Shift the read command (9) bits out. *********
1059
    ;************ Shift the read command (9) bits out. *********
819
   mov       cl, 8                                      ;
1060
   mov       cl, 8                                      ;
820
sis900_read_eeprom_Send:
1061
sis900_read_eeprom_Send:
821
   mov       eax, 1
1062
   mov       eax, 1
822
   shl       eax, cl
1063
   shl       eax, cl
823
   and       eax, ebx
1064
   and       eax, ebx
824
   jz SIS900_Read_Eeprom_8
1065
   jz SIS900_Read_Eeprom_8
825
   mov       eax, 9
1066
   mov       eax, 9
826
   jmp       SIS900_Read_Eeprom_9
1067
   jmp       SIS900_Read_Eeprom_9
827
SIS900_Read_Eeprom_8:
1068
SIS900_Read_Eeprom_8:
828
   mov       eax, 8
1069
   mov       eax, 8
829
SIS900_Read_Eeprom_9:
1070
SIS900_Read_Eeprom_9:
830
   out       dx, eax
1071
   out       dx, eax
831
   call      SIS900_Eeprom_Delay_1
1072
   call      SIS900_Eeprom_Delay_1
832
   or        eax, SIS900_EECLK
1073
   or        eax, SIS900_EECLK
833
   out       dx, eax
1074
   out       dx, eax
834
   call      SIS900_Eeprom_Delay_1
1075
   call      SIS900_Eeprom_Delay_1
835
   cmp       cl, 0
1076
   cmp       cl, 0
836
   je        sis900_read_eeprom_Send_Done
1077
   je        sis900_read_eeprom_Send_Done
837
   dec       cl
1078
   dec       cl
838
   jmp       sis900_read_eeprom_Send
1079
   jmp       sis900_read_eeprom_Send
839
   ;*********************
1080
   ;*********************
840
sis900_read_eeprom_Send_Done:
1081
sis900_read_eeprom_Send_Done:
841
   mov       eax, SIS900_EECS           ;
1082
   mov       eax, SIS900_EECS           ;
842
   out       dx, eax
1083
   out       dx, eax
843
   call      SIS900_Eeprom_Delay_1
1084
   call      SIS900_Eeprom_Delay_1
844
    ;********** Read 16-bits of data in ***************
1085
    ;********** Read 16-bits of data in ***************
845
    mov      cx, 16                             ;16 bits to read
1086
    mov      cx, 16                             ;16 bits to read
846
sis900_read_eeprom_Send2:
1087
sis900_read_eeprom_Send2:
847
    mov      eax, SIS900_EECS
1088
    mov      eax, SIS900_EECS
848
    out      dx, eax
1089
    out      dx, eax
849
    call     SIS900_Eeprom_Delay_1
1090
    call     SIS900_Eeprom_Delay_1
850
    or       eax, SIS900_EECLK
1091
    or       eax, SIS900_EECLK
851
    out      dx, eax
1092
    out      dx, eax
852
    call     SIS900_Eeprom_Delay_1
1093
    call     SIS900_Eeprom_Delay_1
853
    in       eax, dx
1094
    in       eax, dx
854
    shl      ebx, 1
1095
    shl      ebx, 1
855
    and      eax, SIS900_EEDO
1096
    and      eax, SIS900_EEDO
856
    jz       SIS900_Read_Eeprom_0
1097
    jz       SIS900_Read_Eeprom_0
857
    or       ebx, 1
1098
    or       ebx, 1
858
SIS900_Read_Eeprom_0:
1099
SIS900_Read_Eeprom_0:
859
   dec       cx
1100
   dec       cx
860
   jnz       sis900_read_eeprom_Send2
1101
   jnz       sis900_read_eeprom_Send2
861
   ;************** Terminate the EEPROM access. **************
1102
   ;************** Terminate the EEPROM access. **************
862
   xor       eax, eax
1103
   xor       eax, eax
863
   out       dx, eax
1104
   out       dx, eax
864
   call      SIS900_Eeprom_Delay_1
1105
   call      SIS900_Eeprom_Delay_1
865
   mov       eax, SIS900_EECLK
1106
   mov       eax, SIS900_EECLK
866
   out       dx, eax
1107
   out       dx, eax
867
   mov       eax, ebx
1108
   mov       eax, ebx
868
   and       eax, 0x0000ffff                    ;return only 16 bits
1109
   and       eax, 0x0000ffff                    ;return only 16 bits
-
 
1110
   pop       ebp
869
   pop       ebx
1111
   pop       ebx
870
   pop       ecx
1112
   pop       ecx
871
   pop       edx
1113
   pop       edx
872
   pop       esi
1114
   pop       esi
873
   ret
1115
   ret
874
;***************************************************************************
1116
;***************************************************************************
875
;   Function
1117
;   Function
876
;      SIS900_Eeprom_Delay_1
1118
;      SIS900_Eeprom_Delay_1
877
;   Description
1119
;   Description
878
;
1120
;
879
;
1121
;
880
;
1122
;
881
;
1123
;
882
;***************************************************************************
1124
;***************************************************************************
883
SIS900_Eeprom_Delay_1:
1125
SIS900_Eeprom_Delay_1:
884
   push eax
1126
   push eax
885
   in eax, dx
1127
   in eax, dx
886
   pop eax
1128
   pop eax
887
   ret
1129
   ret
-
 
1130
 
-
 
1131
write_mac:
-
 
1132
	DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n'
-
 
1133
	add	esp, 6
-
 
1134
	ret
888
 
1135
 
889
;***************************************************************************
1136
;***************************************************************************
890
;   Function
1137
;   Function
891
;      SIS900_poll
1138
;      int_handler
892
;   Description
1139
;   Description
893
;      polls card to see if there is a packet waiting
1140
;      handles received IRQs, which signal received packets
894
;
1141
;
895
;  Currently only supports one descriptor per packet, if packet is fragmented
1142
;  Currently only supports one descriptor per packet, if packet is fragmented
896
;  between multiple descriptors you will lose part of the packet
1143
;  between multiple descriptors you will lose part of the packet
897
;***************************************************************************
1144
;***************************************************************************
898
if defined SIS900_DEBUG
1145
if defined SIS900_DEBUG
899
SIS900_Debug_Pull_Packet_good db 'Good Packet Waiting: ',13,10,0
1146
SIS900_Debug_Pull_Packet_good db 'Good Packet Waiting: ',13,10,0
900
SIS900_Debug_Pull_Bad_Packet_Status db 'Bad Packet Waiting: Status',13,10,0
1147
SIS900_Debug_Pull_Bad_Packet_Status db 'Bad Packet Waiting: Status',13,10,0
901
SIS900_Debug_Pull_Bad_Packet_Size db 'Bad Packet Waiting: Size',13,10,0
1148
SIS900_Debug_Pull_Bad_Packet_Size db 'Bad Packet Waiting: Size',13,10,0
902
end if
1149
end if
-
 
1150
int_handler:
-
 
1151
; find pointer of device which made IRQ occur
-
 
1152
	mov	esi, DEV_LIST
-
 
1153
	mov	ecx, [NUM_DEV]
-
 
1154
	test	ecx, ecx
-
 
1155
	jz	.nothing
903
SIS900_poll:
1156
.nextdevice:
-
 
1157
	mov	ebx, [esi]
-
 
1158
	mov	edx, [ebx+device.io_addr]
-
 
1159
	add	edx, SIS900_isr
-
 
1160
	in	eax, dx	; note that this clears all interrupts
-
 
1161
	test	al, SIS900_RxOK
-
 
1162
	jnz	.got_it
-
 
1163
	loop	.nextdevice
-
 
1164
.nothing:
-
 
1165
	ret
-
 
1166
.got_it:
904
    ;**************Get Status **************
1167
    ;**************Get Status **************
905
    xor       eax, eax                      ;get RX_Status
-
 
906
    mov      [eth_rx_data_len], ax
-
 
907
    mov       al, [cur_rx]          ;find current discriptor
1168
    movzx     eax, [ebx+device.cur_rx]          ;find current discriptor
908
    imul      eax, 12               ;
1169
    imul      eax, 12               ;
909
    mov       ecx, [rxd+eax+4]          ; get receive status
1170
    mov       ecx, [ebx+device.rxd+eax+4]          ; get receive status
910
    ;**************Check Status **************
1171
    ;**************Check Status **************
911
    mov       ebx, ecx                          ;move status
-
 
912
    ;Check RX_Status to see if packet is waiting
1172
    ;Check RX_Status to see if packet is waiting
913
    and       ebx, 0x80000000
1173
    test      ecx, 0x80000000
914
    jnz       SIS900_poll_IS_packet
1174
    jnz       SIS900_poll_IS_packet
915
    ret
1175
    ret
916
   ;**********There is a packet waiting check it for errors**************
1176
   ;**********There is a packet waiting check it for errors**************
917
SIS900_poll_IS_packet:
1177
SIS900_poll_IS_packet:
918
    mov       ebx, ecx                          ;move status
-
 
919
    and       ebx, 0x67C0000            ;see if there are any errors
1178
    test      ecx, 0x67C0000            ;see if there are any errors
920
    jnz       SIS900_Poll_Error_Status
1179
    jnz       SIS900_Poll_Error_Status
921
   ;**************Check size of packet*************
1180
   ;**************Check size of packet*************
922
   and       ecx, SIS900_DSIZE                                  ;get packet size minus CRC
1181
   and       ecx, SIS900_DSIZE                                  ;get packet size minus CRC
923
   cmp       cx, SIS900_CRC_SIZE
1182
   cmp       ecx, SIS900_CRC_SIZE
924
   ;make sure packet contains data
1183
   ;make sure packet contains data
925
   jle       SIS900_Poll_Error_Size
1184
   jle       SIS900_Poll_Error_Size
926
   ;*******Copy Good Packet to receive buffer******
1185
   ;*******Copy Good Packet to receive buffer******
927
   sub      cx, SIS900_CRC_SIZE                             ;dont want crc
1186
   sub      ecx, SIS900_CRC_SIZE                             ;dont want crc
-
 
1187
   ; update statistics
-
 
1188
   inc      dword [ebx+device.packets_rx]
928
   mov      word [eth_rx_data_len], cx          ;save size of packet
1189
   add      dword [ebx+device.bytes_rx], ecx
929
   ;**********Continue copying packet****************
1190
   adc      dword [ebx+device.bytes_rx+4], 0
930
   push     ecx
1191
   push     ecx
-
 
1192
   stdcall  KernelAlloc, ecx
-
 
1193
   pop      ecx
-
 
1194
   test     eax, eax
-
 
1195
   jz       int_handler.nothing
-
 
1196
   push     ebx
-
 
1197
   push     .return ; return address for EthReceiver
-
 
1198
   ;**********Continue copying packet****************
-
 
1199
   push     ecx eax ; save buffer pointer and size for EthReceiver
-
 
1200
   mov      edi, eax
-
 
1201
   movzx    esi, byte [ebx+device.cur_rx]
-
 
1202
   imul     esi, RX_BUFF_SZ
-
 
1203
   lea      esi, [esi+ebx+0x1000+NUM_TX_DESC*TX_BUFF_SZ]
931
   ; first copy dword-wise, divide size by 4
1204
   ; first copy dword-wise, divide size by 4
932
   shr      ecx, 2
1205
   shr      ecx, 2
933
   mov      esi, [rxd+eax+8]                            ; set source
-
 
934
   add      esi, OS_BASE                        ; get linear address
-
 
935
   mov      edi, Ether_buffer               ; set destination
-
 
936
   cld                                                                          ; clear direction
-
 
937
   rep      movsd                                                       ; copy the dwords
1206
   rep      movsd                                                       ; copy the dwords
938
   pop      ecx
1207
   mov      ecx, [esp+4]
939
   and      ecx, 3                                                  ;
1208
   and      ecx, 3                                                  ;
940
   rep      movsb
1209
   rep      movsb
941
   ;********Debug, tell user we have a good packet*************
1210
   ;********Debug, tell user we have a good packet*************
942
if defined SIS900_DEBUG
1211
if defined SIS900_DEBUG
943
   mov      esi, SIS900_Debug_Pull_Packet_good
1212
   mov      esi, SIS900_Debug_Pull_Packet_good
944
   call     sys_msg_board_str
1213
   call     sys_msg_board_str
945
end if
1214
end if
-
 
1215
   jmp      EthReceiver
-
 
1216
.return:
-
 
1217
   pop      ebx
946
   jmp SIS900_Poll_Cnt                      ;
1218
   jmp      SIS900_Poll_Cnt
947
   ;*************Error occured let user know through debug window***********
1219
   ;*************Error occured let user know through debug window***********
948
SIS900_Poll_Error_Status:
1220
SIS900_Poll_Error_Status:
949
if defined SIS900_DEBUG
1221
if defined SIS900_DEBUG
950
                mov      esi, SIS900_Debug_Pull_Bad_Packet_Status
1222
                mov      esi, SIS900_Debug_Pull_Bad_Packet_Status
951
                call     sys_msg_board_str
1223
                call     sys_msg_board_str
952
end if
1224
end if
953
                jmp      SIS900_Poll_Cnt
1225
                jmp      SIS900_Poll_Cnt
954
SIS900_Poll_Error_Size:
1226
SIS900_Poll_Error_Size:
955
if defined SIS900_DEBUG
1227
if defined SIS900_DEBUG
956
                mov      esi, SIS900_Debug_Pull_Bad_Packet_Size
1228
                mov      esi, SIS900_Debug_Pull_Bad_Packet_Size
957
                call     sys_msg_board_str
1229
                call     sys_msg_board_str
958
end if
1230
end if
959
   ;*************Increment to next available descriptor**************
1231
   ;*************Increment to next available descriptor**************
960
SIS900_Poll_Cnt:
1232
SIS900_Poll_Cnt:
961
    ;Reset status, allow ethernet card access to descriptor
1233
    ;Reset status, allow ethernet card access to descriptor
-
 
1234
   movzx    eax, [ebx+device.cur_rx]
-
 
1235
   lea      eax, [eax*3]
962
   mov      ecx, RX_BUFF_SZ
1236
   mov      ecx, RX_BUFF_SZ
963
   mov      [rxd+eax+4], ecx                ;
1237
   mov      [ebx+device.rxd+eax*4+4], ecx                ;
964
   inc      [cur_rx]                                            ;get next descriptor
1238
   inc      [ebx+device.cur_rx]                          ;get next descriptor
965
   and      [cur_rx],3                      ;only 4 descriptors 0-3
1239
   and      [ebx+device.cur_rx],NUM_RX_DESC-1            ;only 4 descriptors 0-3
966
   ;******Enable Receiver************
1240
   ;******Enable Receiver************
967
   mov          ebp, [io_addr]      ; Base Address
1241
   mov      edx, [ebx+device.io_addr]
968
   lea      edx,[ebp+SIS900_cr] ; Command Register offset
1242
   add      edx, SIS900_cr ; Command Register offset
969
   in       eax, dx                         ; Get current Command Register
1243
   in       eax, dx                         ; Get current Command Register
970
   or       eax, SIS900_RxENA   ;Enable Receive
1244
   or       eax, SIS900_RxENA   ;Enable Receive
971
   out      dx, eax
1245
   out      dx, eax
972
   ret
1246
   ret
973
;***************************************************************************
1247
;***************************************************************************
974
;   Function
1248
;   Function
975
;      SIS900_transmit
1249
;      transmit
976
;   Description
1250
;   Description
977
;      Transmits a packet of data via the ethernet card
1251
;      Transmits a packet of data via the ethernet card
978
;         Pointer to 48 bit destination address in edi
-
 
979
;         Type of packet in bx
1252
;         buffer pointer in [esp]
980
;         size of packet in ecx
1253
;         size of buffer in [esp+4]
981
;         pointer to packet data in esi
1254
;         pointer to device structure in ebx
982
;
1255
;
983
;      only one transmit descriptor is used
1256
;      only one transmit descriptor is used
984
;
1257
;
985
;***************************************************************************
1258
;***************************************************************************
986
if defined SIS900_DEBUG
1259
if defined SIS900_DEBUG
987
SIS900_Debug_Transmit_Packet db 'Transmitting Packet: ',13,10,0
1260
SIS900_Debug_Transmit_Packet db 'Transmitting Packet: ',13,10,0
988
SIS900_Debug_Transmit_Packet_Err db 'Transmitting Packet Error: ',13,10,0
1261
SIS900_Debug_Transmit_Packet_Err db 'Transmitting Packet Error: ',13,10,0
989
end if
1262
end if
990
str1 db 'Transmitting packet:',13,10,0
1263
str1 db 'Transmitting packet:',13,10,0
991
str2 db ' ',0
1264
str2 db ' ',0
992
SIS900_transmit:
1265
transmit:
-
 
1266
   cmp      dword [esp+4], MAX_ETH_FRAME_SIZE
-
 
1267
   jg       transmit_finish
-
 
1268
   cmp      dword [esp+4], 60
-
 
1269
   jl       transmit_finish
-
 
1270
   push     ebp
993
   mov          ebp, [io_addr]      ; Base Address
1271
   mov      ebp, [ebx+device.io_addr] ; Base Address
994
   ;******** Stop the transmitter ********
1272
   ;******** Stop the transmitter ********
995
   lea      edx,[ebp+SIS900_cr] ; Command Register offset
1273
   lea      edx,[ebp+SIS900_cr] ; Command Register offset
996
   in       eax, dx                         ; Get current Command Register
1274
   in       eax, dx                         ; Get current Command Register
997
   or       eax, SIS900_TxDIS   ; Disable Transmitter
1275
   or       eax, SIS900_TxDIS   ; Disable Transmitter
998
   out      dx, eax
1276
   out      dx, eax
999
   ;*******load Transmit Descriptor Register *******
1277
   ;*******load Transmit Descriptor Register *******
1000
   lea      edx,[ebp+SIS900_txdp]
1278
   lea      edx,[ebp+SIS900_txdp]
1001
   mov      eax, txd - OS_BASE
1279
   mov      eax, ebx
-
 
1280
   call     GetPgAddr
-
 
1281
   add      eax, device.txd
1002
   out      dx, eax
1282
   out      dx, eax
1003
   ;******* copy packet to descriptor*******
1283
   ;******* copy packet to descriptor*******
1004
   push    esi
1284
   mov     esi, [esp+4]
1005
   mov     esi, edi                ;copy destination addess
1285
   lea     edi, [ebx+0x1000]
1006
   mov     edi, txb
1286
   mov     ecx, [esp+8]
1007
   cld
-
 
1008
   movsd
1287
   mov     edx, ecx
1009
   movsw
1288
   shr     ecx, 2
1010
   mov     esi, node_addr  ;copy my mac address
-
 
1011
   movsd
1289
   and     edx, 3
1012
   movsw
1290
   rep     movsd
1013
   mov     [edi], bx       ;copy packet type
-
 
1014
   add     edi, 2
1291
   mov     ecx, edx
1015
   pop     esi             ;restore pointer to source of packet
-
 
1016
   push    ecx             ;save packet size
-
 
1017
   shr     ecx, 2          ;divide by 4, size in bytes send in dwords
-
 
1018
   rep     movsd                   ;copy data to decriptor
-
 
1019
   pop     ecx                     ;restore packet size
-
 
1020
   push    ecx             ;save packet size
-
 
1021
   and     ecx, 3          ;last three bytes if not a multiple of 4
-
 
1022
   rep     movsb
1292
   rep     movsb
1023
   ;**************set length tag**************
1293
   ;**************set length tag**************
1024
   pop     ecx                           ;restore packet size
1294
   mov     ecx, [esp+8]                  ;restore packet size
1025
   add     ecx, SIS900_ETH_HLEN  ;add header to length
-
 
1026
   and     ecx, SIS900_DSIZE     ;
1295
   and     ecx, SIS900_DSIZE     ;
-
 
1296
   inc      [ebx+device.packets_tx]
-
 
1297
   add      dword [ebx+device.bytes_tx], ecx
-
 
1298
   adc      dword [ebx+device.bytes_tx+4], 0
1027
   ;**************pad to minimum packet size **************not needed
1299
   ;**************pad to minimum packet size **************not needed
1028
   ;cmp       ecx, SIS900_ETH_ZLEN
1300
   ;cmp       ecx, SIS900_ETH_ZLEN
1029
   ;jge       SIS900_transmit_Size_Ok
1301
   ;jge       SIS900_transmit_Size_Ok
1030
   ;push      ecx
1302
   ;push      ecx
1031
   ;mov       ebx, SIS900_ETH_ZLEN
1303
   ;mov       ebx, SIS900_ETH_ZLEN
1032
   ;sub       ebx, ecx
1304
   ;sub       ebx, ecx
1033
   ;mov       ecx, ebx
1305
   ;mov       ecx, ebx
1034
   ;rep       movsb
1306
   ;rep       movsb
1035
   ;pop       ecx
1307
   ;pop       ecx
1036
SIS900_transmit_Size_Ok:
1308
SIS900_transmit_Size_Ok:
1037
   mov      [txd+4], dword 0x80000000                   ;card owns descriptor
1309
   or       ecx, 0x80000000                             ;card owns descriptor
1038
   or       [txd+4], ecx                                                ;set size of packet
1310
   mov      [ebx+device.txd+4], ecx
1039
if defined SIS900_DEBUG
1311
if defined SIS900_DEBUG
1040
   mov      esi, SIS900_Debug_Transmit_Packet
1312
   mov      esi, SIS900_Debug_Transmit_Packet
1041
   call     sys_msg_board_str
1313
   call     sys_msg_board_str
1042
end if
1314
end if
1043
   ;***************restart the transmitter ********
1315
   ;***************restart the transmitter ********
1044
   lea      edx,[ebp+SIS900_cr]
1316
   lea      edx,[ebp+SIS900_cr]
1045
   in       eax, dx                         ; Get current Command Register
1317
   in       eax, dx                         ; Get current Command Register
1046
   or       eax, SIS900_TxENA   ; Enable Transmitter
1318
   or       eax, SIS900_TxENA   ; Enable Transmitter
1047
   out      dx, eax
1319
   out      dx, eax
1048
   ;****make sure packet transmitted successfully****
1320
   ;****make sure packet transmitted successfully****
1049
;   mov      esi,10
1321
;   mov      esi,10
1050
;   call     delay_ms
1322
;   call     delay_ms
1051
   mov      eax, [txd+4]
1323
   mov      eax, [ebx+device.txd+4]
1052
   and      eax, 0x6200000
1324
   and      eax, 0x6200000
1053
   jz       SIS900_transmit_OK
1325
   jz       SIS900_transmit_OK
1054
   ;**************Tell user there was an error through debug window
1326
   ;**************Tell user there was an error through debug window
1055
if defined SIS900_DEBUG
1327
if defined SIS900_DEBUG
1056
   mov      esi, SIS900_Debug_Transmit_Packet_Err
1328
   mov      esi, SIS900_Debug_Transmit_Packet_Err
1057
   call     sys_msg_board_str
1329
   call     sys_msg_board_str
1058
end if
1330
end if
1059
SIS900_transmit_OK:
1331
SIS900_transmit_OK:
1060
   ;******** Disable interrupts by clearing the interrupt mask. ********
1332
   pop      ebp
1061
   lea      edx,[ebp+SIS900_imr]            ; Interupt Mask Register
1333
transmit_finish:
1062
   xor      eax, eax
1334
   call     KernelFree
1063
   out      dx,eax
1335
   add      esp, 4
1064
   ret
1336
   ret
1065
 
1337
 
1066
;***************************************************************************
1338
;***************************************************************************
1067
;* Function: Create_Mac_String
1339
;* Function: Create_Mac_String
1068
;*
1340
;*
1069
;* Description: Converts the 48 bit value to a string for display
1341
;* Description: Converts the 48 bit value to a string for display
1070
;*
1342
;*
1071
;* String Format: XX:XX:XX:XX:XX:XX
1343
;* String Format: XX:XX:XX:XX:XX:XX
1072
;*
1344
;*
1073
;* Arguments: node_addr is location of 48 bit MAC ID
1345
;* Arguments: node_addr is location of 48 bit MAC ID
1074
;*
1346
;*
1075
;* Returns:   Prints string to general debug window
1347
;* Returns:   Prints string to general debug window
1076
;*
1348
;*
1077
;*
1349
;*
1078
;done
1350
;done
1079
;***************************************************************************
1351
;***************************************************************************
1080
if defined SIS900_DEBUG
1352
if defined SIS900_DEBUG
1081
 
1353
 
1082
SIS900_Char_String    db '0','1','2','3','4','5','6','7','8','9'
1354
SIS900_Char_String    db '0','1','2','3','4','5','6','7','8','9'
1083
                      db 'A','B','C','D','E','F'
1355
                      db 'A','B','C','D','E','F'
1084
Mac_str_build: times 20 db 0
1356
Mac_str_build: times 20 db 0
1085
Create_Mac_String:
1357
Create_Mac_String:
1086
   pusha
1358
   pusha
1087
   xor ecx, ecx
1359
   xor ecx, ecx
1088
Create_Mac_String_loop:
1360
Create_Mac_String_loop:
1089
   mov al,byte [edx+ecx];[node_addr+ecx]
1361
   mov al,byte [edx+ecx];[node_addr+ecx]
1090
   push eax
1362
   push eax
1091
   shr eax, 4
1363
   shr eax, 4
1092
   and eax, 0x0f
1364
   and eax, 0x0f
1093
   mov bl, byte [SIS900_Char_String+eax]
1365
   mov bl, byte [SIS900_Char_String+eax]
1094
   mov [Mac_str_build+ecx*3], bl
1366
   mov [Mac_str_build+ecx*3], bl
1095
   pop eax
1367
   pop eax
1096
   and eax, 0x0f
1368
   and eax, 0x0f
1097
   mov bl, byte [SIS900_Char_String+eax]
1369
   mov bl, byte [SIS900_Char_String+eax]
1098
   mov [Mac_str_build+1+ecx*3], bl
1370
   mov [Mac_str_build+1+ecx*3], bl
1099
   cmp ecx, 5
1371
   cmp ecx, 5
1100
   je Create_Mac_String_done
1372
   je Create_Mac_String_done
1101
   mov bl, ':'
1373
   mov bl, ':'
1102
   mov [Mac_str_build+2+ecx*3], bl
1374
   mov [Mac_str_build+2+ecx*3], bl
1103
   inc ecx
1375
   inc ecx
1104
   jmp Create_Mac_String_loop
1376
   jmp Create_Mac_String_loop
1105
Create_Mac_String_done:                                 ;Insert CR and Zero Terminate
1377
Create_Mac_String_done:                                 ;Insert CR and Zero Terminate
1106
   mov [Mac_str_build+2+ecx*3],byte 13
1378
   mov [Mac_str_build+2+ecx*3],byte 13
1107
   mov [Mac_str_build+3+ecx*3],byte 10
1379
   mov [Mac_str_build+3+ecx*3],byte 10
1108
   mov [Mac_str_build+4+ecx*3],byte 0
1380
   mov [Mac_str_build+4+ecx*3],byte 0
1109
   mov esi, Mac_str_build
1381
   mov esi, Mac_str_build
1110
   call sys_msg_board_str                               ;Print String to message board
1382
   call sys_msg_board_str                               ;Print String to message board
1111
   popa
1383
   popa
1112
   ret
1384
   ret
1113
end if
1385
end if
1114
;***************************************************************************
1386
;***************************************************************************
1115
;*      Set device to be a busmaster in case BIOS neglected to do so.
1387
;*      Set device to be a busmaster in case BIOS neglected to do so.
1116
;*      Also adjust PCI latency timer to a reasonable value, 64.
1388
;*      Also adjust PCI latency timer to a reasonable value, 64.
1117
;***************************************************************************
1389
;***************************************************************************
1118
SIS900_adjust_pci_device:
1390
SIS900_adjust_pci_device:
1119
   ;*******Get current setting************************
1391
   ;*******Get current setting************************
1120
   mov     al, 2                                        ;read a word
-
 
1121
   mov     bh, [pci_dev]
-
 
1122
   mov     ah, [pci_bus]
-
 
1123
   mov     bl, 0x04                                 ;from command Register
1392
   stdcall PciRead16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x04
1124
   call    pci_read_reg
-
 
1125
   ;******see if its already set as bus master********
1393
   ;******see if its already set as bus master********
1126
   mov      bx, ax
1394
   mov      cx, ax
1127
   and      bx,5
1395
   and      cx,5
1128
   cmp      bx,5
1396
   cmp      cx,5
1129
   je       SIS900_adjust_pci_device_Latency
1397
   je       SIS900_adjust_pci_device_Latency
1130
   ;******Make card a bus master*******
1398
   ;******Make card a bus master*******
1131
   mov      cx, ax                              ;value to write
1399
   mov      cx, ax                              ;value to write
1132
   mov     bh, [pci_dev]
-
 
1133
   mov     al, 2                                ;write a word
-
 
1134
   or       cx,5
1400
   or       cx,5
1135
   mov     ah, [pci_bus]
-
 
1136
   mov     bl, 0x04                             ;to command register
1401
   stdcall PciWrite16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x04, ecx
1137
   call    pci_write_reg
-
 
1138
   ;******Check latency setting***********
1402
   ;******Check latency setting***********
1139
SIS900_adjust_pci_device_Latency:
1403
SIS900_adjust_pci_device_Latency:
1140
   ;*******Get current latency setting************************
1404
   ;*******Get current latency setting************************
1141
   mov     al, 1                                        ;read a byte
-
 
1142
   mov     bh, [pci_dev]
-
 
1143
   mov     ah, [pci_bus]
-
 
1144
   mov     bl, 0x0D                                 ;from Lantency Timer Register
1405
   stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x0D
1145
   call    pci_read_reg
-
 
1146
   ;******see if its aat least 64 clocks********
1406
   ;******see if its aat least 64 clocks********
1147
   cmp      ax,64
1407
   cmp      al,64
1148
   jge      SIS900_adjust_pci_device_Done
1408
   jge      SIS900_adjust_pci_device_Done
1149
   ;******Set latency to 32 clocks*******
1409
   ;******Set latency to 32 clocks*******
1150
   mov     cx, 64                               ;value to write
-
 
1151
   mov     bh, [pci_dev]
-
 
1152
   mov     al, 1                                ;write a byte
-
 
1153
   mov     ah, [pci_bus]
-
 
1154
   mov     bl, 0x0D                             ;to Lantency Timer Register
1410
   stdcall PciWrite8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x0D, 64
1155
   call    pci_write_reg
-
 
1156
   ;******Check latency setting***********
1411
   ;******Check latency setting***********
1157
SIS900_adjust_pci_device_Done:
1412
SIS900_adjust_pci_device_Done:
1158
   ret
1413
   ret
-
 
1414
 
-
 
1415
; End of code
-
 
1416
 
-
 
1417
align 4 					; Place all initialised data here
-
 
1418
 
-
 
1419
NUM_DEV   dd 0
-
 
1420
 
-
 
1421
sis900_specific_table:
-
 
1422
;    dd SIS630A_900_REV,Get_Mac_SIS630A_900_REV,0
-
 
1423
;    dd SIS630E_900_REV,Get_Mac_SIS630E_900_REV,0
-
 
1424
    dd SIS630S_900_REV,Get_Mac_SIS635_900_REV,0
-
 
1425
    dd SIS630EA1_900_REV,Get_Mac_SIS635_900_REV,0
-
 
1426
    dd SIS630ET_900_REV,Get_Mac_SIS635_900_REV,0;SIS630ET_900_REV_SpecialFN
-
 
1427
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
-
 
1428
    dd SIS900_960_REV,SIS960_get_mac_addr,0
-
 
1429
    dd SIS900B_900_REV,SIS900_get_mac_addr,0
-
 
1430
    dd 0,0,0,0 ; end of list
-
 
1431
 
-
 
1432
version       dd (5 shl 16) or (API_VERSION and 0xFFFF)
-
 
1433
my_service    db 'SIS900',0			; max 16 chars include zero
-
 
1434
 
-
 
1435
include_debug_strings				; All data wich FDO uses will be included here
-
 
1436
 
-
 
1437
section '.data' data readable writable align 16 ; place all uninitialized data place here
-
 
1438
 
-
 
1439
DEV_LIST rd MAX_DEVICES			; This list contains all pointers to device structures the driver is handling
-
 
1440
>
1159
>
-