Subversion Repositories Kolibri OS

Rev

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

Rev 1514 Rev 1519
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                    ;;
2
;;                                                                    ;;
3
;; Copyright (C) KolibriOS team 2004-2009. All rights reserved.       ;;
3
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved.       ;;
4
;; Distributed under terms of the GNU General Public License          ;;
4
;; Distributed under terms of the GNU General Public License          ;;
5
;;                                                                    ;;
5
;;                                                                    ;;
6
;;  Ethernet driver for KolibriOS                                     ;;
6
;;  Ethernet driver for KolibriOS                                     ;;
7
;;  This is an adaptation of MenuetOS driver with minimal changes.    ;;
7
;;  This is an adaptation of MenuetOS driver with minimal changes.    ;;
8
;;  Changes were made by CleverMouse. Original copyright follows.     ;;
8
;;  Changes were made by CleverMouse. Original copyright follows.     ;;
Line 21... Line 21...
21
;;  Updates:                                                          ;;
21
;;  Updates:                                                          ;;
22
;;    Revision Look up table and SIS635 Mac Address by Jarek Pelczar  ;;
22
;;    Revision Look up table and SIS635 Mac Address by Jarek Pelczar  ;;
23
;;                                                                    ;;
23
;;                                                                    ;;
24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 25... Line -...
25
 
-
 
26
; $Revision: 1514 $
-
 
27
 
25
 
Line 28... Line 26...
28
format MS COFF
26
format MS COFF
-
 
27
 
-
 
28
	API_VERSION		equ 0x01000100
-
 
29
	DRIVER_VERSION		equ 5
Line 29... Line 30...
29
 
30
 
30
	API_VERSION		equ 0x01000100
31
	MAX_DEVICES		equ 16
31
 
32
 
Line 45... Line 46...
45
NUM_TX_DESC    equ    1 	      ;* Number of TX descriptors *
46
NUM_TX_DESC		equ 1		;* Number of TX descriptors *
46
RX_BUFF_SZ	    equ    1520 	   ;* Buffer size for each Rx buffer *
47
RX_BUFF_SZ		equ 1520	;* Buffer size for each Rx buffer *
47
TX_BUFF_SZ	    equ    1516 	   ;* Buffer size for each Tx buffer *
48
TX_BUFF_SZ		equ 1516	;* Buffer size for each Tx buffer *
48
MAX_ETH_FRAME_SIZE  equ    1516
49
MAX_ETH_FRAME_SIZE	equ 1516
Line 49... Line -...
49
 
-
 
50
TOTAL_BUFFERS_SIZE equ NUM_RX_DESC*RX_BUFF_SZ + NUM_TX_DESC*TX_BUFF_SZ
-
 
51
 
50
 
52
virtual at 0
51
virtual at ebx
Line 53... Line 52...
53
	device:
52
	device:
Line 54... Line -...
54
 
-
 
55
	ETH_DEVICE
53
 
56
 
54
	ETH_DEVICE
57
; device specific
55
 
58
      .io_addr		dd ?
56
	.io_addr	dd ?
59
      .pci_bus		db ?
57
	.pci_bus	db ?
-
 
58
	.pci_dev	db ?
-
 
59
	.irq_line	db ?
60
      .pci_dev		db ?
60
	.cur_rx 	db ?
61
      .irq_line 	db ?
61
	.cur_tx 	db ?
-
 
62
	.last_tx	db ?
62
      .cur_rx		db ?
63
	.pci_revision	db ?
-
 
64
	.table_entries	db ?
63
      .pci_revision	db ?
65
 
-
 
66
			dw ? ; align 4
64
      .table_entries:	db ?
67
 
65
align 4
68
	.special_func	dd ?
-
 
69
 
66
      .special_func:	dd 0
70
	.txd		rd (4 * NUM_TX_DESC)
-
 
71
	.rxd		rd (4 * NUM_RX_DESC)
67
      .txd: times (3 * NUM_TX_DESC) dd 0
72
 
Line 68... Line 73...
68
      .rxd: times (3 * NUM_RX_DESC) dd 0
73
	.size = $ - device
-
 
74
 
69
      .size:
75
end virtual
70
end virtual
76
 
71
 
-
 
-
 
77
macro	ee_delay {
-
 
78
	push	eax
-
 
79
	in	eax, dx
-
 
80
	in	eax, dx
-
 
81
	in	eax, dx
-
 
82
	in	eax, dx
72
; First page is designated to ETH_DEVICE, buffers start from second
83
	in	eax, dx
73
ALLOCATION_SIZE = ((device.size+0FFFh) and not 0FFFh) + TOTAL_BUFFERS_SIZE
84
	in	eax, dx
74
; Note that buffers must be contiguous in the physical memory;
85
	in	eax, dx
75
; because KernelAlloc allocates contiguous physical pages only in 8-pages blocks,
-
 
76
; align ALLOCATION_SIZE up to 8*(page size) = 8000h
86
	in	eax, dx
77
ALLOCATION_SIZE = (ALLOCATION_SIZE + 7FFFh) and not 7FFFh
87
	in	eax, dx
78
 
-
 
79
MAX_DEVICES = 16	; maximum number of devices which this driver can handle
-
 
80
 
-
 
81
 
-
 
82
	PCI_HEADER_TYPE 	      equ 0x0e	;8 bit
-
 
83
	PCI_BASE_ADDRESS_0	      equ 0x10	;32 bit
-
 
Line 84... Line 88...
84
	PCI_BASE_ADDRESS_5	      equ 0x24	;32 bits
88
	in	eax, dx
Line 85... Line 89...
85
	PCI_BASE_ADDRESS_SPACE_IO     equ 0x01
89
	pop	eax
86
	PCI_VENDOR_ID		      equ 0x00	;16 bit
90
}
Line 104... Line 108...
104
service_proc:
108
service_proc:
105
; 1. Get parameter from the stack: [esp+4] is the first parameter,
109
; 1. Get parameter from the stack: [esp+4] is the first parameter,
106
;       pointer to IOCTL structure.
110
;       pointer to IOCTL structure.
107
	mov	edx, [esp+4]	; edx -> IOCTL
111
	mov	edx, [esp+4]	; edx -> IOCTL
108
; 2. Get request code and select a handler for the code.
112
; 2. Get request code and select a handler for the code.
109
	mov	eax, [edx+IOCTL.io_code]
113
	mov	eax, [IOCTL.io_code]
110
	test	eax, eax	; check for SRV_GETVERSION
114
	test	eax, eax	; check for SRV_GETVERSION
111
	jnz	@f
115
	jnz	@f
112
; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION.
116
; 3. This is SRV_GETVERSION request, no input, 4 bytes output, API_VERSION.
113
; 3a. Output size must be at least 4 bytes.
117
; 3a. Output size must be at least 4 bytes.
114
	cmp	[edx+IOCTL.out_size], 4
118
	cmp	[IOCTL.out_size], 4
115
	jl	.fail
119
	jl	.fail
116
; 3b. Write result to the output buffer.
120
; 3b. Write result to the output buffer.
117
	mov	eax, [edx+IOCTL.output]
121
	mov	eax, [IOCTL.output]
118
	mov	[eax], dword API_VERSION
122
	mov	[eax], dword API_VERSION
119
; 3c. Return success.
123
; 3c. Return success.
120
	xor	eax, eax
124
	xor	eax, eax
121
	ret	4
125
	ret	4
122
@@:
126
@@:
123
	dec	eax	; check for SRV_HOOK
127
	dec	eax	; check for SRV_HOOK
124
	jnz	.fail
128
	jnz	.fail
125
; 4. This is SRV_HOOK request, input defines the device to hook, no output.
129
; 4. This is SRV_HOOK request, input defines the device to hook, no output.
126
; 4a. The driver works only with PCI devices,
130
; 4a. The driver works only with PCI devices,
127
;       so input must be at least 3 bytes long.
131
;       so input must be at least 3 bytes long.
128
	cmp	[edx + IOCTL.inp_size], 3
132
	cmp	[IOCTL.inp_size], 3
129
	jl	.fail
133
	jl	.fail
130
; 4b. First byte of input is bus type, 1 stands for PCI.
134
; 4b. First byte of input is bus type, 1 stands for PCI.
131
	mov	eax, [edx + IOCTL.input]
135
	mov	eax, [IOCTL.input]
132
	cmp	byte [eax], 1
136
	cmp	byte [eax], 1
133
	jne	.fail
137
	jne	.fail
134
; 4c. Second and third bytes of the input define the device: bus and dev.
138
; 4c. Second and third bytes of the input define the device: bus and dev.
135
;       Word in bx holds both bytes.
139
;       Word in bx holds both bytes.
136
	mov	bx, [eax+1]
140
	mov	bx, [eax+1]
137
; 4d. Check if the device was already hooked,
141
; 4d. Check if the device was already hooked,
138
;       scan through the list of known devices.
142
;       scan through the list of known devices.
-
 
143
; check if the device is already listed
139
	mov	esi, DEV_LIST
144
	mov	esi, device_list
140
	mov	ecx, [NUM_DEV]
145
	mov	ecx, [devices]
141
	test	ecx, ecx
146
	test	ecx, ecx
142
	jz	.firstdevice
147
	jz	.firstdevice
-
 
148
 
-
 
149
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
-
 
150
	mov	ax , [eax+1]				;
143
  .nextdevice:
151
  .nextdevice:
144
	lodsd
152
	mov	ebx, [esi]
-
 
153
	cmp	ax , word [device.pci_bus]		; compare with pci and device num in device list (notice the usage of word instead of byte)
145
	cmp	bx, word [eax + device.pci_bus]
154
	je	.find_devicenum 			; Device is already loaded, let's find it's device number
146
	je	.find_devicenum
155
	add	esi, 4
147
	loop	.nextdevice
156
	loop	.nextdevice
148
; 4e. This device doesn't have its own eth_device structure yet, let's create one
157
; 4e. This device doesn't have its own eth_device structure yet, let's create one
149
  .firstdevice:
158
  .firstdevice:
150
; 4f. Check that we have place for new device.
159
; 4f. Check that we have place for new device.
151
	cmp	[NUM_DEV], MAX_DEVICES
160
	cmp	[devices], MAX_DEVICES
152
	jge	.fail
161
	jge	.fail
153
; 4g. Allocate memory for device descriptor and receive+transmit buffers.
162
; 4g. Allocate memory for device descriptor and receive+transmit buffers.
154
	stdcall KernelAlloc, ALLOCATION_SIZE
163
	stdcall KernelAlloc, device.size
155
	test	eax, eax
164
	test	eax, eax
156
	jz	.fail
165
	jz	.fail
157
; 4h. Zero the structure.
166
; 4h. Zero the structure.
158
	push	eax
-
 
159
	mov	edi, eax
167
	mov	edi, eax
160
	mov	ecx, (device.size + 3) shr 2
168
	mov	ecx, (device.size + 3) shr 2
161
	xor	eax, eax
169
	xor	eax, eax
162
	rep	stosd
170
	rep	stosd
163
	pop	eax
-
 
164
; 4i. Save PCI coordinates, loaded to bx at 4c.
171
; 4i. Save PCI coordinates
-
 
172
	mov	eax, [IOCTL.input]
-
 
173
	mov	cl , [eax+1]
165
	mov	word [eax+device.pci_bus], bx
174
	mov	[device.pci_bus], cl
-
 
175
	mov	cl , [eax+2]
166
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
176
	mov	[device.pci_dev], cl
167
; 4j. Fill in the direct call addresses into the struct.
177
; 4j. Fill in the direct call addresses into the struct.
168
; Note that get_MAC pointer is filled in initialization by SIS900_probe.
178
; Note that get_MAC pointer is filled in initialization by probe.
169
	mov	dword [ebx+device.reset], sis900_init
179
	mov	[device.reset], init
170
	mov	dword [ebx+device.transmit], transmit
180
	mov	[device.transmit], transmit
171
;       mov     dword [ebx+device.get_MAC], read_mac
181
;       mov     [device.get_MAC], read_mac
172
	mov	dword [ebx+device.set_MAC], write_mac
182
	mov	[device.set_MAC], write_mac
173
	mov	dword [ebx+device.unload], unload
183
	mov	[device.unload], unload
174
	mov	dword [ebx+device.name], my_service
184
	mov	[device.name], my_service
Line 175... Line 185...
175
 
185
 
176
; 4k. Now, it's time to find the base io addres of the PCI device
186
; 4k. Now, it's time to find the base io addres of the PCI device
Line 177... Line -...
177
; TODO: implement check if bus and dev exist on this machine
-
 
178
 
-
 
179
	mov	edx, PCI_BASE_ADDRESS_0
-
 
180
.reg_check:
187
; TODO: implement check if bus and dev exist on this machine
181
	push	edx
-
 
182
	stdcall PciRead16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], edx
-
 
183
	pop	edx
-
 
184
	test	al, PCI_BASE_ADDRESS_SPACE_IO
-
 
185
	jz	.inc_reg
-
 
186
	and	eax, PCI_BASE_ADDRESS_IO_MASK
-
 
187
	jnz	.got_io
-
 
188
 
-
 
189
  .inc_reg:
-
 
190
	add	edx, 4
-
 
191
	cmp	edx, PCI_BASE_ADDRESS_5
-
 
192
	jbe	.reg_check
-
 
193
	jmp	.fail
-
 
194
 
188
 
195
  .got_io:
189
; Now, it's time to find the base io addres of the PCI device
196
	mov	[ebx+device.io_addr], eax
190
	find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
197
 
191
 
198
; 4l. We've found the io address, find IRQ now
-
 
Line 199... Line 192...
199
	stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x3c
192
; We've found the io address, find IRQ now
200
	mov	byte [ebx+device.irq_line], al
193
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
201
 
194
 
202
; 4m. Add new device to the list (required for int_handler).
195
; 4m. Add new device to the list (required for int_handler).
Line 203... Line 196...
203
	mov	eax, [NUM_DEV]
196
	mov	eax, [devices]
204
	mov	[DEV_LIST+4*eax], ebx
-
 
205
	inc	[NUM_DEV]
197
	mov	[device_list+4*eax], ebx
206
 
198
	inc	[devices]
207
; 4m. Ok, the eth_device structure is ready, let's probe the device
199
 
208
 
200
; 4m. Ok, the eth_device structure is ready, let's probe the device
Line 209... Line 201...
209
	call	SIS900_probe
201
	call	probe
Line 229... Line 221...
229
	ret	4
221
	ret	4
Line 230... Line 222...
230
 
222
 
Line 231... Line 223...
231
; If an error occured, remove all allocated data and exit (returning -1 in eax)
223
; If an error occured, remove all allocated data and exit (returning -1 in eax)
232
 
224
 
233
  .destroy:
225
  .destroy:
Line 234... Line 226...
234
	dec	[NUM_DEV]
226
	dec	[devices]
235
	; todo: reset device into virgin state
227
	; todo: reset device into virgin state
Line 261... Line 253...
261
	or	eax,-1
253
	or	eax,-1
Line 262... Line 254...
262
 
254
 
Line 263... Line 255...
263
ret
255
ret
264
 
-
 
265
;********************************************************************
-
 
266
;   Interface
-
 
267
;      SIS900_reset
-
 
268
;      SIS900_probe
-
 
269
;      SIS900_poll
-
 
270
;      SIS900_transmit
-
 
271
;
-
 
272
;********************************************************************
256
 
273
;********************************************************************
257
;********************************************************************
274
;  Comments:
258
;  Comments:
275
;    Known to work with the following SIS900 ethernet cards:
259
;    Known to work with the following SIS900 ethernet cards:
276
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x91
260
;      -  Device ID: 0x0900   Vendor ID: 0x1039   Revision: 0x91
Line 281... Line 265...
281
;    we may be able to add support for it.
265
;    we may be able to add support for it.
282
;
266
;
283
;  ToDo:
267
;  ToDo:
284
;     -  Enable MII interface for reading speed
268
;     -  Enable MII interface for reading speed
285
;        and duplex settings.
269
;        and duplex settings.
286
;
-
 
287
;     -  Update Poll routine to support packet fragmentation.
270
;     -  Update receive routine to support packet fragmentation.
288
;
-
 
289
;     -  Add additional support for other sis900 based cards
271
;     -  Add additional support for other sis900 based cards
290
;
272
;
291
;********************************************************************
273
;********************************************************************
Line 391... Line 377...
391
;SIS900 Revision ID
377
; Revision ID
392
	SIS900B_900_REV       equ      0x03
378
	SIS900B_900_REV 	equ 0x03
393
	SIS630A_900_REV       equ      0x80
379
	SIS630A_900_REV 	equ 0x80
394
	SIS630E_900_REV       equ      0x81
380
	SIS630E_900_REV 	equ 0x81
395
	SIS630S_900_REV       equ      0x82
381
	SIS630S_900_REV 	equ 0x82
396
	SIS630EA1_900_REV     equ      0x83
382
	SIS630EA1_900_REV	equ 0x83
397
	SIS630ET_900_REV      equ      0x84
383
	SIS630ET_900_REV	equ 0x84
398
	SIS635A_900_REV       equ      0x90
384
	SIS635A_900_REV 	equ 0x90
-
 
385
	SIS900_960_REV		equ 0x91
399
	SIS900_960_REV	      equ      0x91
386
 
400
;SIS900 Receive Filter Control Register Bits
387
; Receive Filter Control Register Bits
401
    SIS900_RFEN 	 equ 0x80000000
388
	RFEN		equ 0x80000000
402
    SIS900_RFAAB	 equ 0x40000000
389
	RFAAB		equ 0x40000000
403
    SIS900_RFAAM	 equ 0x20000000
390
	RFAAM		equ 0x20000000
404
    SIS900_RFAAP	 equ 0x10000000
391
	RFAAP		equ 0x10000000
-
 
392
	RFPromiscuous	equ 0x70000000
405
    SIS900_RFPromiscuous equ 0x70000000
393
 
406
;SIS900 Reveive Filter Data Mask
394
; Reveive Filter Data Mask
-
 
395
	RFDAT		equ 0x0000FFFF
407
    SIS900_RFDAT equ  0x0000FFFF
396
 
408
;SIS900 Eeprom Address
397
; Eeprom Address
409
    SIS900_EEPROMSignature equ 0x00
398
	EEPROMSignature equ 0x00
410
    SIS900_EEPROMVendorID  equ 0x02
399
	EEPROMVendorID	equ 0x02
411
    SIS900_EEPROMDeviceID  equ 0x03
400
	EEPROMDeviceID	equ 0x03
412
    SIS900_EEPROMMACAddr   equ 0x08
401
	EEPROMMACAddr	equ 0x08
-
 
402
	EEPROMChecksum	equ 0x0b
413
    SIS900_EEPROMChecksum  equ 0x0b
403
 
414
;The EEPROM commands include the alway-set leading bit.
-
 
415
;SIS900 Eeprom Command
404
;The EEPROM commands include the alway-set leading bit.
416
    SIS900_EEread	   equ 0x0180
405
	EEread		equ 0x0180
417
    SIS900_EEwrite	   equ 0x0140
406
	EEwrite 	equ 0x0140
418
    SIS900_EEerase	   equ 0x01C0
407
	EEerase 	equ 0x01C0
419
    SIS900_EEwriteEnable   equ 0x0130
408
	EEwriteEnable	equ 0x0130
420
    SIS900_EEwriteDisable  equ 0x0100
409
	EEwriteDisable	equ 0x0100
421
    SIS900_EEeraseAll	   equ 0x0120
410
	EEeraseAll	equ 0x0120
422
    SIS900_EEwriteAll	   equ 0x0110
411
	EEwriteAll	equ 0x0110
423
    SIS900_EEaddrMask	   equ 0x013F
412
	EEaddrMask	equ 0x013F
-
 
413
	EEcmdShift	equ 16
424
    SIS900_EEcmdShift	   equ 16
414
 
425
;For SiS962 or SiS963, request the eeprom software access
415
;For SiS962 or SiS963, request the eeprom software access
426
	SIS900_EEREQ	equ 0x00000400
416
	EEREQ		equ 0x00000400
427
	SIS900_EEDONE	equ 0x00000200
417
	EEDONE		equ 0x00000200
428
	SIS900_EEGNT	equ 0x00000100
418
	EEGNT		equ 0x00000100
429
 
-
 
430
SIS900_pci_revision equ ebx+device.pci_revision
-
 
431
sis900_get_mac_func equ ebx+device.get_MAC
-
 
432
sis900_special_func equ ebx+device.special_func
-
 
433
sis900_table_entries equ ebx+device.table_entries
-
 
434
cur_rx equ ebx+device.cur_rx
-
 
-
 
419
 
435
sys_msg_board_str equ SysMsgBoardStr
420
 
436
;***************************************************************************
421
;***************************************************************************
437
;   Function
422
;
438
;      SIS900_probe
423
; probe
439
;   Description
424
;
440
;      Searches for an ethernet card, enables it and clears the rx buffer
-
 
-
 
425
; Searches for an ethernet card, enables it and clears the rx buffer
441
;      If a card was found, it enables the ethernet -> TCPIP link
426
;
-
 
427
; TODO: probe mii transceivers
442
;not done  - still need to probe mii transcievers
428
;
443
;***************************************************************************
-
 
444
if defined SIS900_DEBUG
-
 
445
SIS900_Debug_Str_Unsupported db 'Sorry your card is unsupported ',13,10,0
429
;***************************************************************************
446
end if
430
align 4
447
SIS900_probe:
-
 
-
 
431
probe:
448
;******Wake Up Chip*******
432
 
449
   stdcall PciWrite8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x40, 0
-
 
-
 
433
	stdcall PciWrite8, dword [device.pci_bus], dword [device.pci_dev], 0x40, 0	; Wake Up Chip
450
;*******Set some PCI Settings*********
434
 
-
 
435
	make_bus_master [device.pci_bus], [device.pci_dev]
451
   call    SIS900_adjust_pci_device
436
 
452
;*****Get Card Revision******
437
; Get Card Revision
453
   stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x08
438
	stdcall PciRead8, dword [device.pci_bus], dword [device.pci_dev], 0x08
-
 
439
	mov	[pci_revision], al							; save the revision for later use
454
   mov [SIS900_pci_revision], al	;save the revision for later use
440
 
455
;****** Look up through the sis900_specific_table
441
; Look up through the specific_table
456
   mov	   esi,sis900_specific_table
442
	mov	esi, specific_table
457
.probe_loop:
443
  .loop:
458
   cmp	   dword [esi],0		; Check if we reached end of the list
444
	cmp	dword [esi], 0		     ; Check if we reached end of the list
459
   je	   .probe_loop_failed
445
	je	.error
460
   cmp	   al,[esi]			; Check if revision is OK
446
	cmp	al, [esi]		     ; Check if revision is OK
461
   je	   .probe_loop_ok
447
	je	.ok
462
   add	   esi,12			; Advance to next entry
448
	add	esi, 12 		     ; Advance to next entry
463
   jmp	   .probe_loop
-
 
464
.probe_loop_failed:
-
 
465
   jmp	   SIS900_Probe_Unsupported
-
 
466
;*********Find Get Mac Function*********
-
 
467
.probe_loop_ok:
-
 
468
   mov	    eax,[esi+4] 	; Get pointer to "get MAC" function
-
 
469
   mov	    [sis900_get_mac_func],eax
-
 
470
   mov	    eax,[esi+8] 	; Get pointer to special initialization fn
-
 
471
   mov	    [sis900_special_func],eax
-
 
472
;******** Get MAC ********
-
 
473
   call     dword [sis900_get_mac_func]
-
 
474
;******** Call special initialization fn if requested ********
-
 
475
   cmp	    dword [sis900_special_func],0
-
 
476
   je	    .no_special_init
-
 
477
   call     dword [sis900_special_func]
-
 
478
.no_special_init:
-
 
479
;******** Set table entries ********
-
 
480
   mov	    al,[SIS900_pci_revision]
-
 
481
   cmp	    al,SIS635A_900_REV
-
 
482
   jae	    .ent16
-
 
483
   cmp	    al,SIS900B_900_REV
-
 
484
   je	    .ent16
-
 
485
   mov	    byte [sis900_table_entries],8
-
 
486
   jmp	    .ent8
-
 
487
.ent16:
-
 
488
   mov	    byte [sis900_table_entries],16
-
 
489
.ent8:
-
 
490
;*******Probe for mii transceiver*******
-
 
491
;TODO!!*********************
-
 
492
;*******Initialize Device*******
-
 
493
   call sis900_init
-
 
494
   ret
449
	jmp	.loop
495
 
450
 
496
SIS900_Probe_Unsupported:
-
 
497
if defined SIS900_DEBUG
451
  .error:
498
   mov	   esi, SIS900_Debug_Str_Unsupported
-
 
499
   call    sys_msg_board_str
-
 
500
end if
452
	DEBUGF	1, "Device not supported!\n"
501
   or	   eax, -1
453
	or	eax, -1
-
 
454
	ret
-
 
455
 
-
 
456
; Find Get Mac Function
-
 
457
  .ok:
-
 
458
	mov	eax, [esi+4]		; Get pointer to "get MAC" function
-
 
459
	mov	[get_mac_func], eax
-
 
460
	mov	eax, [esi+8]		; Get pointer to special initialization fn
-
 
461
	mov	[special_func], eax
-
 
462
 
-
 
463
; Get MAC
-
 
464
	call	[get_mac_func]
-
 
465
 
-
 
466
; Call special initialization fn if requested
-
 
467
 
-
 
468
	cmp	[special_func],0
-
 
469
	je	@f
-
 
470
	call	[special_func]
-
 
471
       @@:
-
 
472
 
-
 
473
; Set table entries
-
 
474
 
-
 
475
	mov	 byte [table_entries], 16
-
 
476
	cmp	 [pci_revision], SIS635A_900_REV
-
 
477
	jae	 @f
-
 
478
	cmp	 [pci_revision], SIS900B_900_REV
-
 
479
	je	 @f
-
 
480
	mov	 byte [table_entries], 8
-
 
481
       @@:
-
 
482
 
-
 
483
; TODO: Probe for mii transceiver
-
 
484
 
502
   ret
485
 
503
;***************************************************************************
-
 
504
; Function: sis900_init
486
;***************************************************************************
505
;
-
 
506
; Description: resets the ethernet controller chip and various
487
;
507
;    data structures required for sending and receiving packets.
488
; init
508
;
489
;
-
 
490
; resets the ethernet controller chip and various
509
; Arguments:
491
;    data structures required for sending and receiving packets.
510
;
-
 
511
; returns:   none
-
 
512
;not done
492
;
-
 
493
;***************************************************************************
513
;***************************************************************************
494
align 4
-
 
495
init:
514
sis900_init:
496
 
515
   call SIS900_reset		   ;Done
497
	call reset
516
   call SIS900_init_rxfilter   ;Done
498
	call init_rxfilter
517
   call SIS900_init_txd        ;Done
499
	call init_txd
518
   call SIS900_init_rxd 	   ;Done
500
	call init_rxd
519
   call SIS900_set_rx_mode     ;done
501
	call set_rx_mode
520
   call SIS900_set_tx_mode
502
	call set_tx_mode
-
 
503
	;call check_mode
521
   ;call SIS900_check_mode
504
 
-
 
505
; enable interrupts on packet receive
522
; enable interrupts on packet receive
506
 
523
	xor	eax, eax
507
	xor	eax, eax
524
	inc	eax	; eax = 1 = SIS900_RxOK
508
	inc	eax	; eax = 1 = RxOK
525
	mov	edx, [ebx+device.io_addr]
509
	set_io	0
526
	add	edx, SIS900_imr
510
	set_io	imr
-
 
511
	out	dx, eax
527
	out	dx, eax
512
 
-
 
513
; globally enable interrupts
528
; globally enable interrupts
514
 
529
	add	edx, SIS900_ier-SIS900_imr
515
	set_io	ier
530
	out	dx, eax ; eax is still 1
516
	out	dx, eax ; eax is still 1
-
 
517
	xor	eax, eax
-
 
518
 
-
 
519
	mov	[device.mtu], 1514
531
	xor	eax, eax
520
 
Line 532... Line 521...
532
   ret
521
	ret
533
 
522
 
534
;***************************************************************************
523
;***************************************************************************
535
;   Function
524
;
536
;      SIS900_reset
525
; reset
537
;   Description
526
;
538
;      disables interrupts and soft resets the controller chip
-
 
539
;
527
; disables interrupts and soft resets the controller chip
540
;done+
-
 
541
;***************************************************************************
-
 
542
if defined SIS900_DEBUG
528
;
543
   SIS900_Debug_Reset_Failed db 'Reset Failed ',0
529
;***************************************************************************
544
end if
530
align 4
545
SIS900_reset:
531
reset:
546
	movzx	eax, [ebx+device.irq_line]
532
	movzx	eax, [device.irq_line]
547
	stdcall AttachIntHandler, eax, int_handler, 0
533
	stdcall AttachIntHandler, eax, int_handler, 0
548
   push     ebp
534
 
-
 
535
;--------------------------------------------
-
 
536
; Disable Interrupts and reset Receive Filter
549
   mov	    ebp, [ebx+device.io_addr] ; base address
537
 
550
   ;******Disable Interrupts and reset Receive Filter*******
538
	set_io	0
551
   xor	    eax, eax		; 0 to initialize
539
	set_io	ier
-
 
540
	xor	eax, eax
552
   lea	    edx,[ebp+SIS900_ier]
541
	out	dx, eax
553
   out	    dx, eax			; Write 0 to location
542
 
-
 
543
	set_io	imr
554
   lea	    edx,[ebp+SIS900_imr]
544
	out	dx, eax
555
   out	    dx, eax			; Write 0 to location
545
 
-
 
546
	set_io	rfcr
-
 
547
	out	dx, eax
556
   lea	    edx,[ebp+SIS900_rfcr]
548
 
-
 
549
;-----------
557
   out	    dx, eax			; Write 0 to location
550
; Reset Card
558
   ;*******Reset Card***********************************************
551
 
559
   lea	    edx,[ebp+SIS900_cr]
552
	set_io	cr
560
   in	    eax, dx				; Get current Command Register
-
 
561
   or	    eax, SIS900_RESET		; set flags
-
 
562
   or	    eax, SIS900_RxRESET     ;
553
	in	eax, dx 			; Get current Command Register
563
   or		eax, SIS900_TxRESET	    ;
-
 
-
 
554
	or	eax, RESET + RxRESET + TxRESET	; set flags
-
 
555
	out	dx, eax 			; Write new Command Register
564
   out	    dx, eax				; Write new Command Register
556
 
-
 
557
;----------
565
   ;*******Wait Loop************************************************
558
; Wait loop
566
   push     ebx
-
 
567
   lea	    edx,[ebp+SIS900_isr]
559
 
568
   mov	    ecx, 0x03000000	    ; Status we would like to see from card
560
	set_io	isr
569
   mov	    ebx, 2001		    ; only loop 1000 times
561
	mov	ecx, 1000
570
SIS900_Wait:
562
  .loop:
571
   dec	    ebx 				    ; 1 less loop
563
	dec	ecx
572
   jz	    SIS900_DoneWait_e		; 1000 times yet?
-
 
573
   in	    eax, dx				    ; move interrup status to eax
-
 
574
   and	    eax, ecx
-
 
575
   xor	    ecx, eax
564
	jz	.error
576
   jz	    SIS900_DoneWait
565
	in	eax, dx 			; move interrup status to eax
577
   jmp	    SIS900_Wait
-
 
578
SIS900_DoneWait_e:
-
 
579
if defined SIS900_DEBUG
-
 
580
   mov esi, SIS900_Debug_Reset_Failed
566
	cmp	eax, 0x03000000
581
   call sys_msg_board_str
567
	jne	.loop
582
end if
-
 
583
SIS900_DoneWait:
568
 
-
 
569
;------------------------------------------------------
584
   pop	    ebx
570
; Set Configuration Register depending on Card Revision
585
   ;*******Set Configuration Register depending on Card Revision********
571
 
586
   lea	    edx,[ebp+SIS900_cfg]
-
 
587
   mov	    eax, SIS900_PESEL		    ; Configuration Register Bit
572
	set_io	cfg
588
   mov	    cl, [SIS900_pci_revision]	; card revision
573
	mov	eax, PESEL			; Configuration Register Bit
589
   cmp	    cl, SIS635A_900_REV
574
	cmp	[pci_revision], SIS635A_900_REV
590
   je	    SIS900_RevMatch
575
	je	.match
591
   cmp	    cl, SIS900B_900_REV 	; Check card revision
576
	cmp	[pci_revision], SIS900B_900_REV ; Check card revision
592
   je	    SIS900_RevMatch
577
	je	.match
-
 
578
	out	dx, eax 			; no revision match
593
   out	    dx, eax				    ; no revision match
579
	jmp	.done
594
   jmp	    SIS900_Reset_Complete
580
 
595
SIS900_RevMatch:					; Revision match
581
  .match:					; Revision match
-
 
582
	or	eax, RND_CNT			; Configuration Register Bit
596
   or	    eax, SIS900_RND_CNT 	; Configuration Register Bit
583
	out	dx, eax
597
   out	    dx, eax
584
 
598
SIS900_Reset_Complete:
-
 
599
   xor	    eax, eax
585
  .done:
Line -... Line 586...
-
 
586
	xor	eax, eax
-
 
587
	ret
-
 
588
 
-
 
589
  .error:
-
 
590
	DEBUGF	1, "Reset failed!\n"
-
 
591
	or	eax, -1
600
   pop	    ebp
592
	ret
601
   ret
-
 
602
 
593
 
603
;***************************************************************************
594
 
604
; Function: sis_init_rxfilter
595
;***************************************************************************
605
;
596
;
606
; Description: sets receive filter address to our MAC address
597
; sis_init_rxfilter
607
;
-
 
608
; Arguments:
-
 
609
;
598
;
-
 
599
; sets receive filter address to our MAC address
610
; returns:
600
;
611
;done+
601
;***************************************************************************
612
;***************************************************************************
602
align 4
613
SIS900_init_rxfilter:
603
init_rxfilter:
-
 
604
 
-
 
605
;------------------------------------
614
   push     ebp
606
; Get Receive Filter Control Register
615
   mov	    ebp, [ebx+device.io_addr]	; base address
607
 
616
   ;****Get Receive Filter Control Register ********
608
	set_io	0
-
 
609
	set_io	rfcr
-
 
610
	in	eax, dx
617
   lea	    edx,[ebp+SIS900_rfcr]
611
	push	eax
618
   in	    eax, dx			    ; get register
-
 
-
 
612
 
619
   push     eax
613
;-----------------------------------------------
620
   ;****disable packet filtering before setting filter*******
614
; disable packet filtering before setting filter
-
 
615
 
621
   mov	    eax, SIS900_RFEN	;move receive filter enable flag
616
	and	eax, not RFEN
622
   not	    eax 			;1s complement
617
	out	dx, eax
-
 
618
 
623
   and	    eax, [esp]			;disable receiver
619
;--------------------------------------
624
   out	    dx, eax			;set receive disabled
-
 
625
   ;********load MAC addr to filter data register*********
620
; load MAC addr to filter data register
626
   xor	    ecx, ecx
621
 
-
 
622
	xor	ecx, ecx
627
SIS900_RXINT_Mac_Write:
623
RXINT_Mac_Write:	; high word of eax tells card which mac byte to write
628
   ;high word of eax tells card which mac byte to write
624
	mov	eax, ecx
629
   mov	    eax, ecx
625
	set_io	0
630
   lea	    edx,[ebp+SIS900_rfcr]
626
	set_io	rfcr
631
   shl	    eax, 16						;
627
	shl	eax, 16 					    ;
632
   out	    dx, eax						;
628
	out	dx, eax 					    ;
633
   lea	    edx,[ebp+SIS900_rfdr]
629
	set_io	rfdr
634
   mov	    ax,  word [ebx+device.mac+ecx*2] ; Get Mac ID word
630
	mov	ax, word [device.mac+ecx*2]			    ; Get Mac ID word
635
   out	    dx, ax						; Send Mac ID
631
	out	dx, ax						    ; Send Mac ID
-
 
632
	inc	cl						    ; send next word
-
 
633
	cmp	cl, 3						    ; more to send?
636
   inc	    cl							; send next word
634
	jne	RXINT_Mac_Write
-
 
635
 
637
   cmp	    cl, 3						; more to send?
636
;------------------------
638
   jne	    SIS900_RXINT_Mac_Write
637
; enable packet filtering
639
   ;********enable packet filitering *****
638
 
640
   pop	    eax 			    ;old register value
639
	pop	eax				;old register value
641
   lea	    edx,[ebp+SIS900_rfcr]
640
	set_io	rfcr
642
   or	    eax, SIS900_RFEN	;enable filtering
641
	or	eax, RFEN    ;enable filtering
Line 643... Line 642...
643
   out	    dx, eax		;set register
642
	out	dx, eax 	    ;set register
644
   pop	    ebp
643
 
645
   ret
644
	ret
646
 
645
 
647
;***************************************************************************
646
;***************************************************************************
648
;*
-
 
649
;* Function: sis_init_txd
-
 
650
;*
647
;
651
;* Description: initializes the Tx descriptor
-
 
652
;*
-
 
653
;* Arguments:
648
; init_txd
-
 
649
;
654
;*
650
; initializes the Tx descriptor
-
 
651
;
-
 
652
;***************************************************************************
655
;* returns:
653
align 4
-
 
654
init_txd:
656
;*done
655
 
657
;***************************************************************************
656
;-------------------------
658
SIS900_init_txd:
-
 
659
   ;********** initialize TX descriptor **************
-
 
660
   mov	   [ebx+device.txd], dword 0	   ;put link to next descriptor in link field
657
; initialize TX descriptor
-
 
658
 
-
 
659
	mov	dword [device.txd], 0		; put link to next descriptor in link field
661
   mov	   [ebx+device.txd+4],dword 0	   ;clear status field
660
	mov	dword [device.txd+4], 0 	; clear status field
-
 
661
	mov	dword [device.txd+8], 0 	; ptr to buffer
662
   lea	   eax, [ebx+0x1000]
662
 
663
   call    GetPgAddr
663
;----------------------------------
664
   mov	   [ebx+device.txd+8], eax   ;save address to buffer ptr field
664
; load Transmit Descriptor Register
-
 
665
 
665
   ;*************** load Transmit Descriptor Register ***************
666
	set_io	0
-
 
667
	set_io	txdp			; TX Descriptor Pointer
666
   mov	   edx, [ebx+device.io_addr]	    ; base address
668
	lea	eax, [device.txd]
Line 667... Line 669...
667
   add	   edx, SIS900_txdp	 ; TX Descriptor Pointer
669
	GetRealAddr
-
 
670
	out	dx, eax 			    ; move the pointer
668
   add	   eax, device.txd - 0x1000	   ; First Descriptor
671
 
669
   out	   dx, eax			       ; move the pointer
672
	ret
670
   ret
673
 
671
 
-
 
672
;***************************************************************************
-
 
673
;* Function: sis_init_rxd
674
;***************************************************************************
674
;*
-
 
675
;* Description: initializes the Rx descriptor ring
-
 
676
;*
675
;
-
 
676
; init_rxd
677
;* Arguments:
677
;
-
 
678
; initializes the Rx descriptor ring
678
;*
679
;
679
;* Returns:
-
 
680
;*done
680
;***************************************************************************
681
;***************************************************************************
681
align 4
-
 
682
init_rxd:
682
SIS900_init_rxd:
683
 
683
   xor	    ecx,ecx
684
; init RX descriptors
684
   mov	    [cur_rx], cl					;Set cuurent rx discriptor to 0
685
	mov	ecx, NUM_RX_DESC
685
   mov	    eax, ebx
686
	lea	esi, [device.rxd]
686
   call     GetPgAddr
687
 
-
 
688
  .loop:
687
   mov	    esi, eax
689
	lea	eax, [esi + 16]
688
   ;******** init RX descriptors ********
690
	GetRealAddr
-
 
691
	mov	dword [esi+0], eax
689
SIS900_init_rxd_Loop:
692
	mov	dword [esi+4], RX_BUFF_SZ
690
    mov     edx, ecx					    ;current descriptor
693
 
691
    imul    edx, 12			    ;
694
	stdcall KernelAlloc, RX_BUFF_SZ
692
    mov     eax, ecx					    ;determine next link descriptor
695
	test	eax, eax
693
    inc     eax 			    ;
696
	jz	.fail
-
 
697
	mov	dword [esi+12], eax
694
    cmp     eax, NUM_RX_DESC		    ;
698
	GetRealAddr
695
    jne     SIS900_init_rxd_Loop_0	    ;
-
 
696
    xor     eax, eax			    ;
-
 
697
SIS900_init_rxd_Loop_0: 		   ;
-
 
698
    imul    eax, 12			    ;
699
	mov	dword [esi+8], eax
699
    lea     eax, [eax+esi+device.rxd]
-
 
700
    mov     [ebx+device.rxd+edx], eax					   ;save link to next descriptor
700
	add	esi, 16
-
 
701
	loop	.loop
701
    mov     [ebx+device.rxd+edx+4],dword RX_BUFF_SZ	   ;status bits init to buf size
702
 
702
    mov     eax, ecx						;find where the buf is located
-
 
703
    imul    eax,RX_BUFF_SZ		    ;
-
 
704
    lea     eax, [eax+esi+0x1000+NUM_TX_DESC*TX_BUFF_SZ]
-
 
-
 
703
	lea	eax, [device.rxd]
705
    mov     [ebx+device.rxd+edx+8], eax 			   ;save buffer pointer
704
	GetRealAddr
706
    inc     ecx 						    ;next descriptor
-
 
707
    cmp     ecx, NUM_RX_DESC		    ;
705
	mov	dword [esi - 16], eax	; correct last descriptor link ptr
708
    jne     SIS900_init_rxd_Loop	    ;
-
 
709
    ;********* load Receive Descriptor Register with address of first
706
 
-
 
707
; And output ptr to first desc, to device
-
 
708
 
-
 
709
	set_io	0
-
 
710
	set_io	rxdp
710
    ; descriptor*********
711
	out	dx, eax
Line -... Line 712...
-
 
712
 
-
 
713
	mov	[device.cur_rx], 0	; Set curent rx discriptor to 0
-
 
714
 
-
 
715
  .fail:	;;; TODO: abort instead!
-
 
716
	ret
-
 
717
 
-
 
718
 
-
 
719
;***************************************************************************
-
 
720
;
-
 
721
; set_tx_mode
-
 
722
;
-
 
723
; sets the transmit mode to allow for full duplex
-
 
724
;
-
 
725
; If you are having problems transmitting packet try changing the
-
 
726
; Max DMA Burst, Possible settings are as follows:
-
 
727
;
-
 
728
; 0x00000000 = 512 bytes
-
 
729
; 0x00100000 = 4 bytes
-
 
730
; 0x00200000 = 8 bytes
711
    mov     edx, [ebx+device.io_addr]
731
; 0x00300000 = 16 bytes
712
    add     edx, SIS900_rxdp
-
 
713
    lea     eax, [esi+device.rxd]
-
 
714
    out     dx, eax
-
 
715
    ret
-
 
716
 
-
 
717
;***************************************************************************
732
; 0x00400000 = 32 bytes
718
;* Function: sis900_set_tx_mode
733
; 0x00500000 = 64 bytes
719
;*
734
; 0x00600000 = 128 bytes
720
;* Description:
735
; 0x00700000 = 256 bytes
721
;*    sets the transmit mode to allow for full duplex
-
 
722
;*
-
 
723
;*
-
 
724
;* Arguments:
-
 
725
;*
-
 
726
;* Returns:
-
 
727
;*
-
 
728
;* Comments:
-
 
729
;*     If you are having problems transmitting packet try changing the
-
 
730
;*     Max DMA Burst, Possible settings are as follows:
-
 
731
;*         0x00000000 = 512 bytes
-
 
732
;*         0x00100000 = 4 bytes
-
 
733
;*         0x00200000 = 8 bytes
-
 
734
;*         0x00300000 = 16 bytes
736
;
735
;*         0x00400000 = 32 bytes
-
 
736
;*         0x00500000 = 64 bytes
-
 
737
;*         0x00600000 = 128 bytes
-
 
738
;*         0x00700000 = 256 bytes
737
;***************************************************************************
739
;***************************************************************************
738
align 4
-
 
739
set_tx_mode:
-
 
740
 
-
 
741
	set_io	0
-
 
742
	set_io	cr
-
 
743
	in	eax, dx 			; Get current Command Register
-
 
744
	or	eax, TxENA			; Enable Receive
-
 
745
	out	dx, eax
-
 
746
 
-
 
747
	set_io	txcfg					; Transmit config Register offset
-
 
748
	mov	eax, ATP + HBI + CSI +0x00600120
740
SIS900_set_tx_mode:
749
	; allow automatic padding
741
   push     ebp
-
 
742
   mov	    ebp,[ebx+device.io_addr]
-
 
743
   lea	    edx,[ebp+SIS900_cr]
-
 
744
   in	    eax, dx			    ; Get current Command Register
-
 
745
   or	    eax, SIS900_TxENA	;Enable Receive
-
 
746
   out	    dx, eax
-
 
747
   lea	    edx,[ebp+SIS900_txcfg]; Transmit config Register offset
-
 
748
   mov	    eax, SIS900_ATP		;allow automatic padding
-
 
749
   or	    eax, SIS900_HBI		;allow heartbeat ignore
750
	; allow heartbeat ignore
750
   or	    eax, SIS900_CSI		;allow carrier sense ignore
751
	; allow carrier sense ignore
Line 751... Line 752...
751
   or	    eax, 0x00600000	;Max DMA Burst
752
	; Max DMA Burst (128 bytes)
752
   or	    eax, 0x00000100	;TX Fill Threshold
-
 
753
   or	    eax, 0x00000020	;TX Drain Threshold
753
	; TX Fill Threshold
754
   out	    dx, eax
754
	; TX Drain Threshold
-
 
755
	out	 dx, eax
755
   pop	    ebp
756
 
756
   ret
757
	ret
757
 
758
 
758
;***************************************************************************
-
 
759
;* Function: sis900_set_rx_mode
-
 
760
;*
-
 
761
;* Description:
-
 
762
;*    sets the receive mode to accept all broadcast packets and packets
759
;***************************************************************************
763
;*    with our MAC address, and reject all multicast packets.  Also allows
-
 
764
;*    full-duplex
760
;
765
;*
761
; set_rx_mode
-
 
762
;
766
;* Arguments:
763
; sets the receive mode to accept all broadcast packets and packets
767
;*
764
; with our MAC address, and reject all multicast packets.  Also allows
768
;* Returns:
765
; full-duplex
769
;*
766
;
770
;* Comments:
767
; If you are having problems receiving packet try changing the
771
;*     If you are having problems receiving packet try changing the
768
; Max DMA Burst, Possible settings are as follows:
772
;*     Max DMA Burst, Possible settings are as follows:
769
;
773
;*         0x00000000 = 512 bytes
770
; 0x00000000 = 512 bytes
-
 
771
; 0x00100000 = 4 bytes
774
;*         0x00100000 = 4 bytes
772
; 0x00200000 = 8 bytes
-
 
773
; 0x00300000 = 16 bytes
775
;*         0x00200000 = 8 bytes
774
; 0x00400000 = 32 bytes
776
;*         0x00300000 = 16 bytes
775
; 0x00500000 = 64 bytes
777
;*         0x00400000 = 32 bytes
776
; 0x00600000 = 128 bytes
778
;*         0x00500000 = 64 bytes
777
; 0x00700000 = 256 bytes
-
 
778
;
779
;*         0x00600000 = 128 bytes
779
;***************************************************************************
780
;*         0x00700000 = 256 bytes
-
 
781
;***************************************************************************
780
align 4
782
SIS900_set_rx_mode:
781
set_rx_mode:
783
   push     ebp
782
 
784
   mov	    ebp,[ebx+device.io_addr]
783
;----------------------------------------------
785
    ;**************update Multicast Hash Table in Receive Filter
784
; update Multicast Hash Table in Receive Filter
786
   xor	    cl, cl
785
 
787
SIS900_set_rx_mode_Loop:
786
	xor	 cl, cl
-
 
787
  .loop:
788
   mov	    eax, ecx
788
	set_io	 0
789
   shl	    eax, 1
789
	set_io	 rfcr			; Receive Filter Control Reg offset
790
   lea	    edx,[ebp+SIS900_rfcr]	    ; Receive Filter Control Reg offset
790
	mov	 eax, 4 		; determine table entry
-
 
791
	add	 al, cl
791
   mov	    eax, 4					    ;determine table entry
792
	shl	 eax, 16
792
   add	    al, cl
793
	out	 dx, eax		; tell card which entry to modify
-
 
794
 
-
 
795
	set_io	 rfdr			; Receive Filter Control Reg offset
793
   shl	    eax, 16
796
	mov	 eax, 0xffff		; entry value
794
   out	    dx, eax					    ;tell card which entry to modify
797
	out	 dx, ax 		; write value to table in card
-
 
798
 
795
   lea	    edx,[ebp+SIS900_rfdr]	    ; Receive Filter Control Reg offset
799
	inc	 cl			; next entry
-
 
800
	cmp	 cl, [table_entries]
796
   mov	    eax, 0xffff 			    ;entry value
801
	jl	 .loop
797
   out	    dx, ax					    ;write value to table in card
802
 
798
   inc	    cl						    ;next entry
803
;------------------------------------
799
   cmp	    cl,[sis900_table_entries]	;
804
; Set Receive Filter Control Register
800
   jl	    SIS900_set_rx_mode_Loop
805
 
-
 
806
	set_io	rfcr			; Receive Filter Control Register offset
801
   ;*******Set Receive Filter Control Register*************
807
	mov	eax, RFAAB + RFAAM + RFAAP + RFEN
-
 
808
	; accecpt all broadcast packets
802
   lea	    edx,[ebp+SIS900_rfcr]	; Receive Filter Control Register offset
809
	; accept all multicast packets
803
   mov	    eax, SIS900_RFAAB		;accecpt all broadcast packets
810
	; Accept all packets
804
   or	    eax, SIS900_RFAAM		;accept all multicast packets
811
	; enable receiver filter
805
   or	    eax, SIS900_RFAAP		;Accept all packets
812
	out	dx, eax
-
 
813
;----------------
-
 
814
; Enable Receiver
806
   or	    eax, SIS900_RFEN		;enable receiver filter
815
 
-
 
816
	set_io	cr
807
   out	    dx, eax
817
	in	eax, dx 		; Get current Command Register
-
 
818
	or	eax, RxENA		; Enable Receive
808
   ;******Enable Receiver************
819
	out	dx, eax
809
   lea	    edx,[ebp+SIS900_cr] ; Command Register offset
820
 
810
   in	    eax, dx			    ; Get current Command Register
821
;-------------------
811
   or	    eax, SIS900_RxENA	;Enable Receive
822
; Configure Receiver
812
   out	    dx, eax
823
 
813
   ;*********Set
824
	set_io	rxcfg			; Receive Config Register offset
814
   lea	    edx,[ebp+SIS900_rxcfg]	; Receive Config Register offset
825
	mov	eax, ATX + 0x00600002
Line 815... Line 826...
815
   mov	    eax, SIS900_ATX			;Accept Transmit Packets
826
	; Accept Transmit Packets
-
 
827
	; (Req for full-duplex and PMD Loopback)
816
				    ; (Req for full-duplex and PMD Loopback)
828
	; Max DMA Burst
817
   or	    eax, 0x00600000			;Max DMA Burst
-
 
818
   or	    eax, 0x00000002			;RX Drain Threshold, 8X8 bytes or 64bytes
-
 
819
   out	    dx, eax					;
829
	; RX Drain Threshold, 8X8 bytes or 64bytes
820
   pop	    ebp
830
	out	 dx, eax
821
   ret
831
 
822
 
832
	ret
823
;***************************************************************************
833
 
824
; *     SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
834
;***************************************************************************
825
; *     @pci_dev: the sis900 pci device
835
;
826
; *     @net_dev: the net device to get address for
836
; SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model
827
; *
837
;
828
; *     SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM
-
 
829
; *     is shared by
-
 
830
; *     LAN and 1394. When access EEPROM, send EEREQ signal to hardware first
838
; SiS962 or SiS963 model, use EEPROM to store MAC address.
831
; *     and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access
839
; EEPROM is shared by LAN and 1394.
832
; *     by LAN, otherwise is not. After MAC address is read from EEPROM, send
840
; When access EEPROM, send EEREQ signal to hardware first, and wait for EEGNT.
833
; *     EEDONE signal to refuse EEPROM access by LAN.
841
; If EEGNT is ON, EEPROM is permitted to be accessed by LAN, otherwise is not.
834
; *     The EEPROM map of SiS962 or SiS963 is different to SiS900.
-
 
835
; *     The signature field in SiS962 or SiS963 spec is meaningless.
-
 
836
; *     MAC address is read into @net_dev->dev_addr.
-
 
837
; *done
-
 
838
;*
-
 
839
;* Return 0 is EAX = failure
842
; After MAC address is read from EEPROM, send
840
;*Done+
843
; EEDONE signal to refuse EEPROM access by LAN.
841
;***************************************************************************
844
; The EEPROM map of SiS962 or SiS963 is different to SiS900.
842
if defined SIS900_DEBUG
845
; The signature field in SiS962 or SiS963 spec is meaningless.
843
SIS900_Debug_Str_GetMac_Start db 'Attempting to get SIS900 Mac ID: ',13,10,0
846
;
-
 
847
; Return 0 is EAX = failure
-
 
848
;
844
SIS900_Debug_Str_GetMac_Failed db 'Access to EEprom Failed',13,10,0
849
;***************************************************************************
845
SIS900_Debug_Str_GetMac_Address db 'Your Mac ID is: ',0
850
align 4
846
SIS900_Debug_Str_GetMac_Address2 db 'Your SIS96x Mac ID is: ',0
851
SIS960_get_mac_addr:
-
 
852
 
847
end if
853
;-------------------------------
848
SIS960_get_mac_addr:
854
; Send Request for eeprom access
-
 
855
 
849
   push     ebp
856
	set_io	0
-
 
857
	set_io	mear		; Eeprom access register
850
   mov	    ebp,[ebx+device.io_addr]
858
	mov	eax, EEREQ	; Request access to eeprom
851
   ;**********Send Request for eeprom access*********************
859
	out	dx, eax 	; Send request
852
   lea	    edx,[ebp+SIS900_mear]		; Eeprom access register
860
 
853
   mov	    eax, SIS900_EEREQ			; Request access to eeprom
861
;-----------------------------------------------------
-
 
862
; Loop 4000 times and if access not granted, error out
854
   out	    dx, eax						; Send request
863
 
-
 
864
	mov	ecx, 4000
855
   xor	    ecx,ecx						;
865
  .loop:
856
   ;******Loop 4000 times and if access not granted error out*****
866
	in	eax, dx 	; get eeprom status
857
SIS96X_Get_Mac_Wait:
867
	test	eax, EEGNT	; see if eeprom access granted flag is set
-
 
868
	jnz	.got_access	; if it is, go access the eeprom
858
   in	    eax, dx					;get eeprom status
869
	loop	.loop		; else keep waiting
859
   and	    eax, SIS900_EEGNT	    ;see if eeprom access granted flag is set
870
 
-
 
871
	DEBUGF	1, "Access to EEprom failed!\n", 0
860
   jnz	    SIS900_Got_EEP_Access	;if it is, go access the eeprom
872
 
861
   inc	    ecx 					;else keep waiting
873
	set_io	mear		; Eeprom access register
862
   cmp	    ecx, 4000				;have we tried 4000 times yet?
874
	mov	eax, EEDONE	; tell eeprom we are done
863
   jl	    SIS96X_Get_Mac_Wait     ;if not ask again
875
	out	dx, eax
864
   xor	    eax, eax		    ;return zero in eax indicating failure
-
 
-
 
876
 
865
   ;*******Debug **********************
877
	or	eax, -1 	; error
-
 
878
	ret
866
if defined SIS900_DEBUG
879
 
867
   mov esi,SIS900_Debug_Str_GetMac_Failed
880
  .got_access:
868
   call sys_msg_board_str
881
 
869
end if
882
;------------------------------------------
870
   jmp SIS960_get_mac_addr_done
883
; EEprom access granted, read MAC from card
871
   ;**********EEprom access granted, read MAC from card*************
884
 
872
SIS900_Got_EEP_Access:
885
    ; zero based so 3-16 bit reads will take place
873
    ; zero based so 3-16 bit reads will take place
886
 
874
   mov	    ecx, 2
887
	mov	ecx, 2
875
SIS96x_mac_read_loop:
888
  .read_loop:
876
   mov	    eax, SIS900_EEPROMMACAddr	 ;Base Mac Address
889
	mov	eax, EEPROMMACAddr	; Base Mac Address
-
 
890
	add	eax, ecx		; Current Mac Byte Offset
877
   add	    eax, ecx				     ;Current Mac Byte Offset
891
	push	ecx
878
   push     ecx
-
 
-
 
892
	call	read_eeprom		; try to read 16 bits
879
   call     sis900_read_eeprom		 ;try to read 16 bits
893
	pop	ecx
880
   pop	    ecx
-
 
881
   mov	    word [ebx+device.mac+ecx*2], ax	   ;save 16 bits to the MAC ID varible
-
 
882
   dec	    ecx 			 ;one less word to read
894
	mov	word [device.mac+ecx*2], ax	; save 16 bits to the MAC ID varible
-
 
895
	dec	ecx			; one less word to read
883
   jns	    SIS96x_mac_read_loop	 ;if more read more
896
	jns	.read_loop		; if more read more
884
   mov	    eax, 1			 ;return non-zero indicating success
-
 
885
   ;*******Debug Print MAC ID to debug window**********************
897
	mov	eax, 1			; return non-zero indicating success
886
if defined SIS900_DEBUG
898
 
887
   mov esi,SIS900_Debug_Str_GetMac_Address2
899
	DEBUGF	2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
888
   call sys_msg_board_str
900
 
-
 
901
;-------------------------------------
889
   lea edx, [ebx+device.mac]
902
; Tell EEPROM We are Done Accessing It
890
   call Create_Mac_String
903
 
-
 
904
  .done:
-
 
905
	set_io	0
-
 
906
	set_io	mear		; Eeprom access register
-
 
907
	mov	eax, EEDONE	; tell eeprom we are done
891
end if
908
	out	dx, eax
-
 
909
 
892
   ;**********Tell EEPROM We are Done Accessing It*********************
910
	xor	eax, eax	; ok
893
SIS960_get_mac_addr_done:
-
 
894
   lea	    edx,[ebp+SIS900_mear]		; Eeprom access register
-
 
895
   mov	    eax, SIS900_EEDONE		 ;tell eeprom we are done
911
	ret
896
   out	    dx,eax
912
 
897
   pop	    ebp
-
 
898
   ret
913
 
899
;***************************************************************************
914
 
-
 
915
 
900
;*      sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
916
;***************************************************************************
-
 
917
;
901
;*      @pci_dev: the sis900 pci device
918
; get_mac_addr: - Get MAC address for stand alone SiS900 model
902
;*      @net_dev: the net device to get address for
-
 
903
;*
-
 
904
;*      Older SiS900 and friends, use EEPROM to store MAC address.
-
 
905
;*      MAC address is read from read_eeprom() into @net_dev->dev_addr.
-
 
906
;* done/untested
919
;
-
 
920
; Older SiS900 and friends, use EEPROM to store MAC address.
907
;***************************************************************************
921
;
908
SIS900_get_mac_addr:
922
;***************************************************************************
909
   ;*******Debug **********************
923
align 4
910
if defined SIS900_DEBUG
924
get_mac_addr:
911
   mov esi,SIS900_Debug_Str_GetMac_Start
925
 
912
   call sys_msg_board_str
926
;------------------------------------
-
 
927
; check to see if we have sane EEPROM
-
 
928
 
913
end if
929
	mov	eax, EEPROMSignature  ; Base Eeprom Signature
-
 
930
	call	read_eeprom	      ; try to read 16 bits
914
   ;******** check to see if we have sane EEPROM *******
931
	cmp	ax, 0xffff
-
 
932
	je	.err
915
   mov	    eax, SIS900_EEPROMSignature  ;Base Eeprom Signature
933
	test	ax, ax
916
   call     sis900_read_eeprom		 ;try to read 16 bits
934
	je	.err
917
   cmp ax, 0xffff
935
 
918
   je SIS900_Bad_Eeprom
936
;-----------
919
   cmp ax, 0
937
; Read MacID
920
   je SIS900_Bad_Eeprom
938
 
921
   ;**************Read MacID**************
939
; zero based so 3-16 bit reads will take place
922
   ; zero based so 3-16 bit reads will take place
940
 
923
   mov	    ecx, 2
941
	mov	ecx, 2
924
SIS900_mac_read_loop:
942
  .loop:
925
   mov	    eax, SIS900_EEPROMMACAddr	 ;Base Mac Address
-
 
926
   add	    eax, ecx				     ;Current Mac Byte Offset
-
 
927
   push     ecx
-
 
928
   call     sis900_read_eeprom		 ;try to read 16 bits
-
 
929
   pop	    ecx
-
 
930
   mov	    word [ebx+device.mac+ecx*2], ax	   ;save 16 bits to the MAC ID storage
-
 
931
   dec	    ecx 			 ;one less word to read
-
 
932
   jns	    SIS900_mac_read_loop	 ;if more read more
-
 
933
   mov	    eax, 1			 ;return non-zero indicating success
943
	mov	eax, EEPROMMACAddr    ;Base Mac Address
-
 
944
	add	eax, ecx				 ;Current Mac Byte Offset
Line 934... Line -...
934
   ;*******Debug Print MAC ID to debug window**********************
-
 
935
if defined SIS900_DEBUG
945
	push	ecx
936
   mov esi,SIS900_Debug_Str_GetMac_Address
-
 
937
   call sys_msg_board_str
-
 
938
   lea edx, [ebx+device.mac]
-
 
939
   call Create_Mac_String
-
 
940
end if
-
 
941
   ret
946
	call	read_eeprom	      ;try to read 16 bits
-
 
947
	pop	ecx
-
 
948
	mov	word [device.mac+ecx*2], ax	   ;save 16 bits to the MAC ID storage
-
 
949
	dec	ecx			     ;one less word to read
-
 
950
	jns	mac_read_loop	      ;if more read more
-
 
951
 
-
 
952
	DEBUGF	2,"%x-%x-%x-%x-%x-%x\n",[device.mac]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2
-
 
953
 
-
 
954
	xor	eax, eax
-
 
955
	ret
942
 
956
 
-
 
957
 
943
SIS900_Bad_Eeprom:
958
  .err:
944
   xor eax, eax
-
 
945
   ;*******Debug **********************
959
	DEBUGF	1, "Access to EEprom failed!\n", 0
946
if defined SIS900_DEBUG
960
 
-
 
961
	or	eax, -1
947
   mov esi,SIS900_Debug_Str_GetMac_Failed
962
	ret
948
   call sys_msg_board_str
-
 
949
end if
-
 
950
   ret
-
 
951
;***************************************************************************
963
 
952
;*      Get_Mac_SIS635_900_REV: - Get MAC address for model 635
964
 
953
;*
-
 
954
;*
965
;***************************************************************************
955
;***************************************************************************
966
;
956
Get_Mac_SIS635_900_REV:
967
; Get_Mac_SIS635_900_REV: - Get MAC address for model 635
-
 
968
;
957
if defined SIS900_DEBUG
969
;***************************************************************************
958
    mov     esi,SIS900_Debug_Str_GetMac_Start
970
align 4
959
    call    sys_msg_board_str
971
Get_Mac_SIS635_900_REV:
-
 
972
 
960
end if
973
	set_io	0
961
    push    ebp
974
	set_io	rfcr
-
 
975
	in	eax, dx
-
 
976
	mov	edi, eax ; EDI=rfcrSave
962
    mov     ebp,[ebx+device.io_addr]
977
 
-
 
978
	set_io	cr
963
    lea     edx,[ebp+SIS900_rfcr]
979
	or	eax, RELOAD
964
    in	    eax,dx
980
	out	dx, eax
965
    mov     edi,eax ; EDI=rfcrSave
981
 
966
    lea     edx,[ebp+SIS900_cr]
982
	xor	eax, eax
-
 
983
	out	dx, eax
-
 
984
 
967
    or	    eax,SIS900_RELOAD
985
;-----------------------------------------------
-
 
986
; Disable packet filtering before setting filter
968
    out     dx,eax
987
 
969
    xor     eax,eax
988
	set_io	rfcr
970
    out     dx,eax
989
	mov	eax, edi
-
 
990
	and	edi, not RFEN
971
    ; Disable packet filtering before setting filter
991
	out	dx, eax
972
    lea     edx,[ebp+SIS900_rfcr]
992
 
973
    mov     eax,edi
993
;---------------------------------
974
    and     edi,not SIS900_RFEN
994
; Load MAC to filter data register
-
 
995
 
975
    out     dx,eax
996
	mov	ecx, 3
976
    ; Load MAC to filter data register
997
	lea	edi, [device.mac]
977
    xor     ecx,ecx
-
 
978
    lea     esi,[ebx+device.mac]
998
  .loop:
979
.get_mac_loop:
999
	set_io	0
980
    lea     edx,[ebp+SIS900_rfcr]
-
 
-
 
1000
	set_io	rfcr
981
    mov     eax,ecx
1001
	mov	eax, ecx
982
    shl     eax,SIS900_RFADDR_shift
1002
	shl	eax, RFADDR_shift
-
 
1003
	out	dx, eax
983
    out     dx,eax
1004
 
984
    lea     edx,[ebp+SIS900_rfdr]
1005
	set_io	rfdr
985
    in	    eax,dx
1006
	in	eax, dx
986
    mov     [esi],ax
1007
	stosw
987
    add     esi,2
-
 
988
    inc     ecx
-
 
989
    cmp     ecx,3
-
 
990
    jne .get_mac_loop
-
 
991
    ; Enable packet filtering
-
 
992
    ;lea     edx,[ebp+SIS900_rfcr]
-
 
993
    ;mov     eax,edi
-
 
994
    ;or      eax,SIS900_RFEN
-
 
995
    ;out     dx, eax
-
 
996
   ;*******Debug Print MAC ID to debug window**********************
-
 
997
if defined SIS900_DEBUG
-
 
998
    mov     esi,SIS900_Debug_Str_GetMac_Address
-
 
999
    call    sys_msg_board_str
-
 
1000
    lea     edx, [ebx+device.mac]
-
 
1001
    call    Create_Mac_String
-
 
1002
end if
-
 
1003
    pop     ebp
-
 
1004
    ret
1008
	loop	.loop
1005
;***************************************************************************
-
 
1006
;* Function: sis900_read_eeprom
-
 
1007
;*
-
 
1008
;* Description: reads and returns a given location from EEPROM
-
 
1009
;*
-
 
1010
;* Arguments: eax - location:       requested EEPROM location
-
 
1011
;*
-
 
1012
;* Returns:   eax :                contents of requested EEPROM location
-
 
1013
;*
-
 
1014
; Read Serial EEPROM through EEPROM Access Register, Note that location is
-
 
1015
;   in word (16 bits) unit */
-
 
1016
;done+
-
 
1017
;***************************************************************************
-
 
1018
sis900_read_eeprom:
-
 
1019
   push      esi
-
 
1020
   push      edx
-
 
1021
   push      ecx
-
 
1022
   push      ebx
-
 
1023
   push      ebp
-
 
1024
   mov	     ebp,[ebx+device.io_addr]
-
 
1025
   mov	     ebx, eax		   ;location of Mac byte to read
-
 
1026
   or	     ebx, SIS900_EEread    ;
-
 
1027
   lea	     edx,[ebp+SIS900_mear] ; Eeprom access register
-
 
1028
   xor	     eax, eax		   ; start send
-
 
1029
   out	     dx,eax
-
 
1030
   call      SIS900_Eeprom_Delay_1
-
 
1031
   mov	     eax, SIS900_EECLK
-
 
1032
   out	     dx, eax
-
 
1033
   call      SIS900_Eeprom_Delay_1
-
 
1034
    ;************ Shift the read command (9) bits out. *********
-
 
1035
   mov	     cl, 8					;
-
 
1036
sis900_read_eeprom_Send:
-
 
1037
   mov	     eax, 1
-
 
1038
   shl	     eax, cl
-
 
1039
   and	     eax, ebx
-
 
1040
   jz SIS900_Read_Eeprom_8
-
 
1041
   mov	     eax, 9
-
 
1042
   jmp	     SIS900_Read_Eeprom_9
-
 
1043
SIS900_Read_Eeprom_8:
-
 
1044
   mov	     eax, 8
-
 
1045
SIS900_Read_Eeprom_9:
-
 
1046
   out	     dx, eax
-
 
1047
   call      SIS900_Eeprom_Delay_1
-
 
1048
   or	     eax, SIS900_EECLK
-
 
1049
   out	     dx, eax
-
 
1050
   call      SIS900_Eeprom_Delay_1
-
 
1051
   cmp	     cl, 0
-
 
1052
   je	     sis900_read_eeprom_Send_Done
-
 
1053
   dec	     cl
-
 
1054
   jmp	     sis900_read_eeprom_Send
-
 
1055
   ;*********************
-
 
1056
sis900_read_eeprom_Send_Done:
-
 
1057
   mov	     eax, SIS900_EECS		;
-
 
1058
   out	     dx, eax
-
 
1059
   call      SIS900_Eeprom_Delay_1
-
 
1060
    ;********** Read 16-bits of data in ***************
-
 
1061
    mov      cx, 16				;16 bits to read
-
 
1062
sis900_read_eeprom_Send2:
-
 
1063
    mov      eax, SIS900_EECS
-
 
1064
    out      dx, eax
-
 
1065
    call     SIS900_Eeprom_Delay_1
-
 
1066
    or	     eax, SIS900_EECLK
-
 
1067
    out      dx, eax
-
 
1068
    call     SIS900_Eeprom_Delay_1
-
 
1069
    in	     eax, dx
1009
 
1070
    shl      ebx, 1
-
 
1071
    and      eax, SIS900_EEDO
-
 
1072
    jz	     SIS900_Read_Eeprom_0
-
 
1073
    or	     ebx, 1
-
 
1074
SIS900_Read_Eeprom_0:
-
 
1075
   dec	     cx
-
 
1076
   jnz	     sis900_read_eeprom_Send2
-
 
1077
   ;************** Terminate the EEPROM access. **************
-
 
1078
   xor	     eax, eax
-
 
1079
   out	     dx, eax
-
 
1080
   call      SIS900_Eeprom_Delay_1
-
 
1081
   mov	     eax, SIS900_EECLK
1010
;------------------------
-
 
1011
; Enable packet filtering
1082
   out	     dx, eax
1012
 
1083
   mov	     eax, ebx
-
 
1084
   and	     eax, 0x0000ffff			;return only 16 bits
-
 
1085
   pop	     ebp
-
 
1086
   pop	     ebx
1013
;        set_io  rfcr
-
 
1014
;        mov     eax, edi
1087
   pop	     ecx
1015
;        or      eax, RFEN
-
 
1016
;        out     dx, eax
1088
   pop	     edx
1017
 
-
 
1018
	xor	eax, eax
-
 
1019
	ret
1089
   pop	     esi
1020
 
1090
   ret
1021
;***************************************************************************
-
 
1022
;
1091
;***************************************************************************
1023
; read_eeprom
-
 
1024
;
-
 
1025
; reads and returns a given location from EEPROM
-
 
1026
;
-
 
1027
; IN:  si = addr
-
 
1028
; OUT: ax = data
-
 
1029
;
-
 
1030
;***************************************************************************
-
 
1031
align 4
-
 
1032
read_eeprom:
-
 
1033
 
-
 
1034
	set_io	0
-
 
1035
	set_io	mear
-
 
1036
 
-
 
1037
	xor	eax, eax	      ; start send
-
 
1038
	out	dx, eax
-
 
1039
	ee_delay
-
 
1040
 
-
 
1041
	or	eax, EECLK
-
 
1042
	out	dx, eax
-
 
1043
	ee_delay
-
 
1044
 
-
 
1045
;------------------------------------
-
 
1046
; Send the read command
1092
;   Function
1047
 
-
 
1048
	or	esi, EEread
-
 
1049
	mov	ecx, 1 shl 9
-
 
1050
 
-
 
1051
  .loop:
-
 
1052
	mov	eax, EECS
-
 
1053
	test	esi, ecx
-
 
1054
	jz	@f
-
 
1055
	or	eax, EEDI
-
 
1056
       @@:
-
 
1057
	out	dx, eax
-
 
1058
	ee_delay
-
 
1059
 
-
 
1060
	or	eax, EECLK
-
 
1061
	out	dx, eax
-
 
1062
	ee_delay
-
 
1063
 
-
 
1064
	shr	esi, 1
-
 
1065
	jnc	.loop
-
 
1066
 
-
 
1067
	mov	eax, EECS
-
 
1068
	out	dx, eax
-
 
1069
	ee_delay
-
 
1070
 
-
 
1071
;------------------------
-
 
1072
; Read 16-bits of data in
-
 
1073
 
-
 
1074
	xor	esi, esi
-
 
1075
	mov	cx, 16
1093
;      SIS900_Eeprom_Delay_1
1076
  .loop2:
-
 
1077
	mov	eax, EECS
-
 
1078
	out	dx, eax
-
 
1079
	ee_delay
-
 
1080
 
1094
;   Description
1081
	or	eax, EECLK
-
 
1082
	out	dx, eax
-
 
1083
	ee_delay
-
 
1084
 
-
 
1085
	in	eax, dx
-
 
1086
	shl	esi, 1
-
 
1087
	test	eax, EEDO
-
 
1088
	jz	@f
-
 
1089
	inc	esi
-
 
1090
       @@:
-
 
1091
	loop	.loop2
-
 
1092
 
-
 
1093
;----------------------------
-
 
1094
; Terminate the EEPROM access
-
 
1095
 
-
 
1096
	xor	eax, eax
1095
;
1097
	out	dx, eax
Line -... Line 1098...
-
 
1098
	ee_delay
-
 
1099
 
-
 
1100
	mov	eax, EECLK
1096
;
1101
	out	dx, eax
1097
;
1102
	ee_delay
1098
;
1103
 
1099
;***************************************************************************
1104
	movzx	eax, si
Line 1100... Line 1105...
1100
SIS900_Eeprom_Delay_1:
1105
 
1101
   push eax
1106
	ret
1102
   in eax, dx
1107
 
1103
   pop eax
1108
 
1104
   ret
1109
 
1105
 
1110
align 4
1106
write_mac:
1111
write_mac:
1107
	DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n'
1112
	DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n'
-
 
1113
	add	esp, 6
1108
	add	esp, 6
1114
	ret
1109
	ret
-
 
1110
 
-
 
1111
;***************************************************************************
-
 
1112
;   Function
-
 
1113
;      int_handler
1115
 
1114
;   Description
1116
;***************************************************************************
1115
;      handles received IRQs, which signal received packets
1117
;
1116
;
1118
; int_handler
1117
;  Currently only supports one descriptor per packet, if packet is fragmented
1119
;
1118
;  between multiple descriptors you will lose part of the packet
1120
; handles received IRQs, which signal received packets
1119
;***************************************************************************
1121
;
1120
if defined SIS900_DEBUG
1122
; Currently only supports one descriptor per packet, if packet is fragmented
1121
SIS900_Debug_Pull_Packet_good db 'Good Packet Waiting: ',13,10,0
1123
; between multiple descriptors you will lose part of the packet
1122
SIS900_Debug_Pull_Bad_Packet_Status db 'Bad Packet Waiting: Status',13,10,0
1124
;
1123
SIS900_Debug_Pull_Bad_Packet_Size db 'Bad Packet Waiting: Size',13,10,0
1125
;***************************************************************************
1124
end if
1126
align 4
1125
int_handler:
1127
int_handler:
1126
; find pointer of device which made IRQ occur
1128
; find pointer of device which made IRQ occur
1127
	mov	esi, DEV_LIST
1129
	mov	esi, device_list
1128
	mov	ecx, [NUM_DEV]
1130
	mov	ecx, [devices]
1129
	test	ecx, ecx
1131
	test	ecx, ecx
1130
	jz	.nothing
1132
	jz	.nothing
-
 
1133
.nextdevice:
-
 
1134
	mov	ebx, [esi]
-
 
1135
	set_io	0
-
 
1136
	set_io	isr
-
 
1137
	in	eax, dx ; note that this clears all interrupts
-
 
1138
	test	ax, IE
-
 
1139
	jnz	.got_it
1131
.nextdevice:
1140
	loop	.nextdevice
1132
	mov	ebx, [esi]
1141
.nothing:
1133
	mov	edx, [ebx+device.io_addr]
1142
	ret
1134
	add	edx, SIS900_isr
1143
.got_it:
-
 
1144
 
1135
	in	eax, dx ; note that this clears all interrupts
1145
	test	ax, RxOK
1136
	test	al, SIS900_RxOK
1146
	jz	.no_rx
1137
	jnz	.got_it
1147
 
1138
	loop	.nextdevice
1148
	push	ax
1139
.nothing:
1149
 
-
 
1150
;-----------
-
 
1151
; Get Status
1140
	ret
1152
	movzx	eax, [device.cur_rx]		; find current discriptor
1141
.got_it:
1153
	shl	eax, 4				; * 16
1142
    ;**************Get Status **************
1154
	mov	ecx, dword[device.rxd+eax+4]	; get receive status
1143
    movzx     eax, [ebx+device.cur_rx]		;find current discriptor
1155
 
-
 
1156
;-------------------------------------------
-
 
1157
; Check RX_Status to see if packet is waiting
1144
    imul      eax, 12		    ;
1158
	test	ecx, 0x80000000
1145
    mov       ecx, [ebx+device.rxd+eax+4]	   ; get receive status
1159
	jnz	.is_packet
1146
    ;**************Check Status **************
-
 
1147
    ;Check RX_Status to see if packet is waiting
1160
	ret
1148
    test      ecx, 0x80000000
1161
 
1149
    jnz       SIS900_poll_IS_packet
-
 
1150
    ret
-
 
-
 
1162
;----------------------------------------------
1151
   ;**********There is a packet waiting check it for errors**************
1163
; There is a packet waiting check it for errors
1152
SIS900_poll_IS_packet:
1164
  .is_packet:
1153
    test      ecx, 0x67C0000		;see if there are any errors
1165
	test	ecx, 0x67C0000			; see if there are any errors
1154
    jnz       SIS900_Poll_Error_Status
1166
	jnz	.error_status
1155
   ;**************Check size of packet*************
-
 
1156
   and	     ecx, SIS900_DSIZE					;get packet size minus CRC
-
 
1157
   cmp	     ecx, SIS900_CRC_SIZE
1167
 
1158
   ;make sure packet contains data
-
 
1159
   jle	     SIS900_Poll_Error_Size
-
 
1160
   ;*******Copy Good Packet to receive buffer******
1168
;---------------------
1161
   sub	    ecx, SIS900_CRC_SIZE			     ;dont want crc
-
 
1162
   ; update statistics
-
 
1163
   inc	    dword [ebx+device.packets_rx]
-
 
1164
   add	    dword [ebx+device.bytes_rx], ecx
-
 
1165
   adc	    dword [ebx+device.bytes_rx+4], 0
-
 
1166
   push     ecx
-
 
1167
   stdcall  KernelAlloc, ecx
-
 
1168
   pop	    ecx
-
 
1169
   test     eax, eax
1169
; Check size of packet
1170
   jz	    int_handler.nothing
1170
	and	ecx, DSIZE			; get packet size minus CRC
1171
   push     ebx
-
 
1172
   push     .return ; return address for EthReceiver
-
 
1173
   ;**********Continue copying packet****************
-
 
1174
   push     ecx eax ; save buffer pointer and size for EthReceiver
-
 
1175
   mov	    edi, eax
-
 
1176
   movzx    esi, byte [ebx+device.cur_rx]
1171
	sub	ecx, CRC_SIZE			; make sure packet contains data
1177
   imul     esi, RX_BUFF_SZ
1172
	jle	.error_size
1178
   lea	    esi, [esi+ebx+0x1000+NUM_TX_DESC*TX_BUFF_SZ]
-
 
1179
   ; first copy dword-wise, divide size by 4
1173
 
1180
   shr	    ecx, 2
1174
; update statistics
1181
   rep	    movsd							; copy the dwords
1175
	inc	dword [device.packets_rx]
1182
   mov	    ecx, [esp+4]
-
 
1183
   and	    ecx, 3						    ;
-
 
1184
   rep	    movsb
-
 
1185
   ;********Debug, tell user we have a good packet*************
-
 
1186
if defined SIS900_DEBUG
-
 
1187
   mov	    esi, SIS900_Debug_Pull_Packet_good
-
 
1188
   call     sys_msg_board_str
1176
	add	dword [device.bytes_rx], ecx
1189
end if
-
 
1190
   jmp	    EthReceiver
-
 
1191
.return:
-
 
1192
   pop	    ebx
-
 
1193
   jmp	    SIS900_Poll_Cnt
-
 
1194
   ;*************Error occured let user know through debug window***********
-
 
1195
SIS900_Poll_Error_Status:
-
 
1196
if defined SIS900_DEBUG
-
 
1197
		mov	 esi, SIS900_Debug_Pull_Bad_Packet_Status
1177
	adc	dword [device.bytes_rx+4], 0
1198
		call	 sys_msg_board_str
1178
 
1199
end if
1179
	push	ebx
-
 
1180
	push	.return
1200
		jmp	 SIS900_Poll_Cnt
1181
	push	ecx				; packet size
-
 
1182
	push	[device.rxd+eax+12]		; packet ptr
-
 
1183
	DEBUGF	1, "Packet received OK\n"
-
 
1184
	jmp	EthReceiver
-
 
1185
  .return:
1201
SIS900_Poll_Error_Size:
1186
	pop	ebx
-
 
1187
 
-
 
1188
; Reset status, allow ethernet card access to descriptor
1202
if defined SIS900_DEBUG
1189
	movzx	ecx, [device.cur_rx]
1203
		mov	 esi, SIS900_Debug_Pull_Bad_Packet_Size
1190
	shl	ecx, 4				; *16
-
 
1191
	mov	ecx, [device.rxd+ecx]
1204
		call	 sys_msg_board_str
1192
	stdcall KernelAlloc, RX_BUFF_SZ
1205
end if
1193
	test	eax, eax
1206
   ;*************Increment to next available descriptor**************
1194
	jz	.fail
1207
SIS900_Poll_Cnt:
1195
	mov	dword [ecx+12], eax
1208
    ;Reset status, allow ethernet card access to descriptor
1196
	GetRealAddr
1209
   movzx    eax, [ebx+device.cur_rx]
1197
	mov	dword [ecx+8], eax
-
 
1198
	mov	dword [ecx+4], RX_BUFF_SZ
-
 
1199
 
-
 
1200
	inc	[device.cur_rx] 			 ; get next descriptor
-
 
1201
	and	[device.cur_rx], NUM_RX_DESC-1		 ; only 4 descriptors 0-3
-
 
1202
 
-
 
1203
; Enable Receiver
-
 
1204
	set_io	0
-
 
1205
	set_io	cr		; Command Register offset
-
 
1206
	in	eax, dx 	; Get current Command Register
-
 
1207
	or	eax, RxENA	; Enable Receiver
-
 
1208
	out	dx, eax
-
 
1209
 
-
 
1210
	pop	ax
-
 
1211
	jmp	.no_rx
-
 
1212
 
-
 
1213
  .error_status:
-
 
1214
 
-
 
1215
	DEBUGF	1, "Packet error: %x\n", ecx
-
 
1216
	jmp	.continue
-
 
1217
 
-
 
1218
  .error_size:
-
 
1219
 
-
 
1220
	DEBUGF	1, "Packet too large/small\n"
1210
   lea	    eax, [eax*3]
1221
	jmp	.continue
-
 
1222
 
-
 
1223
  .no_rx:
-
 
1224
	test	ax, TxOk
1211
   mov	    ecx, RX_BUFF_SZ
1225
	jz	.no_tx
1212
   mov	    [ebx+device.rxd+eax*4+4], ecx		 ;
1226
 
1213
   inc	    [ebx+device.cur_rx] 			 ;get next descriptor
1227
	;;; TODO: free all unused buffers
1214
   and	    [ebx+device.cur_rx],NUM_RX_DESC-1		 ;only 4 descriptors 0-3
1228
	stdcall   KernelFree, eax
1215
   ;******Enable Receiver************
1229
 
Line 1229... Line 1243...
1229
;         pointer to device structure in ebx
1243
;         pointer to device structure in ebx
1230
;
1244
;
1231
;      only one transmit descriptor is used
1245
;      only one transmit descriptor is used
1232
;
1246
;
1233
;***************************************************************************
1247
;***************************************************************************
1234
if defined SIS900_DEBUG
-
 
1235
SIS900_Debug_Transmit_Packet db 'Transmitting Packet: ',13,10,0
-
 
1236
SIS900_Debug_Transmit_Packet_Err db 'Transmitting Packet Error: ',13,10,0
-
 
1237
end if
1248
align 4
1238
str1 db 'Transmitting packet:',13,10,0
-
 
1239
str2 db ' ',0
-
 
1240
transmit:
1249
transmit:
-
 
1250
 
1241
   cmp	    dword [esp+8], MAX_ETH_FRAME_SIZE
1251
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
1242
   jg	    transmit_finish
1252
	jg	transmit_finish
-
 
1253
 
1243
   cmp	    dword [esp+8], 60
1254
	cmp	dword [esp+8], 60
1244
   jl	    transmit_finish
1255
	jl	transmit_finish
1245
   push     ebp
-
 
1246
   mov	    ebp, [ebx+device.io_addr] ; Base Address
-
 
1247
   ;******** Stop the transmitter ********
-
 
1248
   lea	    edx,[ebp+SIS900_cr] ; Command Register offset
-
 
1249
   in	    eax, dx			    ; Get current Command Register
-
 
1250
   or	    eax, SIS900_TxDIS	; Disable Transmitter
-
 
1251
   out	    dx, eax
-
 
1252
   ;*******load Transmit Descriptor Register *******
-
 
1253
   lea	    edx,[ebp+SIS900_txdp]
-
 
1254
   mov	    eax, ebx
-
 
1255
   call     GetPgAddr
-
 
1256
   add	    eax, device.txd
-
 
1257
   out	    dx, eax
-
 
1258
   ;******* copy packet to descriptor*******
-
 
1259
   mov	   esi, [esp+8]
-
 
1260
   lea	   edi, [ebx+0x1000]
-
 
1261
   mov	   ecx, [esp+12]
-
 
1262
   mov	   edx, ecx
-
 
1263
   shr	   ecx, 2
-
 
1264
   and	   edx, 3
-
 
1265
   rep	   movsd
-
 
1266
   mov	   ecx, edx
-
 
1267
   rep	   movsb
-
 
1268
   ;**************set length tag**************
-
 
1269
   mov	   ecx, [esp+12]		  ;restore packet size
-
 
1270
   and	   ecx, SIS900_DSIZE	 ;
-
 
1271
   inc	    [ebx+device.packets_tx]
-
 
1272
   add	    dword [ebx+device.bytes_tx], ecx
-
 
1273
   adc	    dword [ebx+device.bytes_tx+4], 0
-
 
1274
   ;**************pad to minimum packet size **************not needed
-
 
1275
   ;cmp       ecx, SIS900_ETH_ZLEN
-
 
1276
   ;jge       SIS900_transmit_Size_Ok
-
 
1277
   ;push      ecx
-
 
1278
   ;mov       ebx, SIS900_ETH_ZLEN
-
 
1279
   ;sub       ebx, ecx
-
 
1280
   ;mov       ecx, ebx
-
 
1281
   ;rep       movsb
-
 
1282
   ;pop       ecx
-
 
1283
SIS900_transmit_Size_Ok:
-
 
1284
   or	    ecx, 0x80000000				;card owns descriptor
-
 
1285
   mov	    [ebx+device.txd+4], ecx
-
 
1286
if defined SIS900_DEBUG
-
 
1287
   mov	    esi, SIS900_Debug_Transmit_Packet
-
 
1288
   call     sys_msg_board_str
-
 
1289
end if
-
 
1290
   ;***************restart the transmitter ********
-
 
1291
   lea	    edx,[ebp+SIS900_cr]
-
 
1292
   in	    eax, dx			    ; Get current Command Register
-
 
1293
   or	    eax, SIS900_TxENA	; Enable Transmitter
-
 
1294
   out	    dx, eax
-
 
1295
   ;****make sure packet transmitted successfully****
-
 
1296
;   mov      esi,10
-
 
1297
;   call     delay_ms
-
 
1298
   mov	    eax, [ebx+device.txd+4]
-
 
1299
   and	    eax, 0x6200000
-
 
1300
   jz	    SIS900_transmit_OK
-
 
1301
   ;**************Tell user there was an error through debug window
-
 
1302
if defined SIS900_DEBUG
-
 
1303
   mov	    esi, SIS900_Debug_Transmit_Packet_Err
-
 
1304
   call     sys_msg_board_str
-
 
1305
end if
-
 
1306
SIS900_transmit_OK:
-
 
1307
   pop	    ebp
-
 
1308
transmit_finish:
-
 
1309
   ret
-
 
Line 1310... Line -...
1310
 
-
 
1311
;***************************************************************************
1256
 
1312
;* Function: Create_Mac_String
-
 
1313
;*
-
 
1314
;* Description: Converts the 48 bit value to a string for display
-
 
1315
;*
1257
	movzx	ecx, [device.cur_tx]
1316
;* String Format: XX:XX:XX:XX:XX:XX
1258
	mov	ecx, [device.txd+ecx*16]
1317
;*
1259
 
1318
;* Arguments: node_addr is location of 48 bit MAC ID
-
 
1319
;*
1260
;; TODO: check if desc is empty (for example: check for eax, 0x6200000  at [ecx+4]
1320
;* Returns:   Prints string to general debug window
-
 
1321
;*
-
 
1322
;*
-
 
1323
;done
-
 
1324
;***************************************************************************
-
 
1325
if defined SIS900_DEBUG
1261
;;; or: count number of available descriptors
1326
 
-
 
1327
SIS900_Char_String    db '0','1','2','3','4','5','6','7','8','9'
-
 
1328
		      db 'A','B','C','D','E','F'
-
 
1329
Mac_str_build: times 20 db 0
1262
 
1330
Create_Mac_String:
-
 
1331
   pusha
1263
	mov	eax, [esp+4]
1332
   xor ecx, ecx
1264
	mov	dword [ecx + 12], eax
1333
Create_Mac_String_loop:
1265
	GetRealAddr
1334
   mov al,byte [edx+ecx];[node_addr+ecx]
1266
	mov	dword [ecx + 8], eax
1335
   push eax
1267
 
1336
   shr eax, 4
1268
	mov	eax, [esp+8]
1337
   and eax, 0x0f
1269
	and	eax, DSIZE
1338
   mov bl, byte [SIS900_Char_String+eax]
1270
	or	eax, 0x80000000 	; card owns descriptor
1339
   mov [Mac_str_build+ecx*3], bl
1271
	mov	dword [ecx + 4], eax
1340
   pop eax
1272
 
1341
   and eax, 0x0f
-
 
1342
   mov bl, byte [SIS900_Char_String+eax]
-
 
1343
   mov [Mac_str_build+1+ecx*3], bl
-
 
1344
   cmp ecx, 5
1273
; update stats
1345
   je Create_Mac_String_done
-
 
1346
   mov bl, ':'
1274
	inc	[device.packets_tx]
1347
   mov [Mac_str_build+2+ecx*3], bl
-
 
1348
   inc ecx
-
 
1349
   jmp Create_Mac_String_loop
-
 
1350
Create_Mac_String_done: 				;Insert CR and Zero Terminate
-
 
1351
   mov [Mac_str_build+2+ecx*3],byte 13
-
 
1352
   mov [Mac_str_build+3+ecx*3],byte 10
1275
	add	dword [device.bytes_tx], ecx
1353
   mov [Mac_str_build+4+ecx*3],byte 0
-
 
1354
   mov esi, Mac_str_build
-
 
1355
   call sys_msg_board_str				;Print String to message board
-
 
1356
   popa
-
 
1357
   ret
1276
	adc	dword [device.bytes_tx+4], 0
1358
end if
-
 
1359
;***************************************************************************
-
 
1360
;*      Set device to be a busmaster in case BIOS neglected to do so.
-
 
1361
;*      Also adjust PCI latency timer to a reasonable value, 64.
-
 
1362
;***************************************************************************
-
 
1363
SIS900_adjust_pci_device:
-
 
1364
   ;*******Get current setting************************
-
 
1365
   stdcall PciRead16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x04
-
 
1366
   ;******see if its already set as bus master********
-
 
1367
   mov	    cx, ax
-
 
1368
   and	    cx,5
-
 
1369
   cmp	    cx,5
-
 
1370
   je	    SIS900_adjust_pci_device_Latency
-
 
1371
   ;******Make card a bus master*******
-
 
1372
   mov	    cx, ax				;value to write
-
 
1373
   or	    cx,5
-
 
1374
   stdcall PciWrite16, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x04, ecx
-
 
1375
   ;******Check latency setting***********
-
 
1376
SIS900_adjust_pci_device_Latency:
-
 
1377
   ;*******Get current latency setting************************
-
 
1378
   stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x0D
-
 
1379
   ;******see if its aat least 64 clocks********
-
 
1380
   cmp	    al,64
-
 
1381
   jge	    SIS900_adjust_pci_device_Done
-
 
1382
   ;******Set latency to 32 clocks*******
-
 
1383
   stdcall PciWrite8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x0D, 64
-
 
1384
   ;******Check latency setting***********
-
 
1385
SIS900_adjust_pci_device_Done:
1277
 
Line -... Line 1278...
-
 
1278
	ret
1386
   ret
1279
 
Line 1387... Line 1280...
1387
 
1280
 
Line 1388... Line 1281...
1388
; End of code
1281
; End of code
Line 1389... Line 1282...
1389
 
1282
 
1390
align 4 					; Place all initialised data here
1283
align 4 					; Place all initialised data here
1391
 
1284
 
1392
NUM_DEV   dd 0
1285
devices 	dd 0
1393
 
1286
 
1394
sis900_specific_table:
1287
specific_table:
1395
;    dd SIS630A_900_REV,Get_Mac_SIS630A_900_REV,0
1288
;    dd SIS630A_900_REV,Get_Mac_SIS630A_900_REV,0
1396
;    dd SIS630E_900_REV,Get_Mac_SIS630E_900_REV,0
1289
;    dd SIS630E_900_REV,Get_Mac_SIS630E_900_REV,0
1397
    dd SIS630S_900_REV,Get_Mac_SIS635_900_REV,0
1290
    dd SIS630S_900_REV,Get_Mac_SIS635_900_REV,0
1398
    dd SIS630EA1_900_REV,Get_Mac_SIS635_900_REV,0
1291
    dd SIS630EA1_900_REV,Get_Mac_SIS635_900_REV,0
Line 1399... Line 1292...
1399
    dd SIS630ET_900_REV,Get_Mac_SIS635_900_REV,0;SIS630ET_900_REV_SpecialFN
1292
    dd SIS630ET_900_REV,Get_Mac_SIS635_900_REV,0;SIS630ET_900_REV_SpecialFN
1400
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
1293
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
Line 1401... Line 1294...
1401
    dd SIS900_960_REV,SIS960_get_mac_addr,0
1294
    dd SIS900_960_REV,SIS960_get_mac_addr,0
Line 1402... Line 1295...
1402
    dd SIS900B_900_REV,SIS900_get_mac_addr,0
1295
    dd SIS900B_900_REV,get_mac_addr,0
Line 1403... Line 1296...
1403
    dd 0,0,0,0 ; end of list
1296
    dd 0					; end of list