Subversion Repositories Kolibri OS

Rev

Rev 1514 | Go to most recent revision | Show entire file | Ignore 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 39... Line 40...
39
include 'netdrv.inc'
40
include 'netdrv.inc'
Line 40... Line 41...
40
 
41
 
41
public START
42
public START
Line 42... Line 43...
42
public version
43
public version
43
 
44
 
44
NUM_RX_DESC    equ    4 	      ;* Number of RX descriptors *
45
NUM_RX_DESC		equ 4		;* Number of RX descriptors *
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
MAX_ETH_FRAME_SIZE  equ    1516
-
 
Line 49... Line 48...
49
 
48
TX_BUFF_SZ		equ 1516	;* Buffer size for each Tx buffer *
50
TOTAL_BUFFERS_SIZE equ NUM_RX_DESC*RX_BUFF_SZ + NUM_TX_DESC*TX_BUFF_SZ
49
MAX_ETH_FRAME_SIZE	equ 1516
Line 51... Line 50...
51
 
50
 
Line 52... Line -...
52
virtual at 0
-
 
53
	device:
51
virtual at ebx
54
 
52
	device:
55
	ETH_DEVICE
53
 
56
 
54
	ETH_DEVICE
57
; device specific
55
 
-
 
56
	.io_addr	dd ?
-
 
57
	.pci_bus	db ?
58
      .io_addr		dd ?
58
	.pci_dev	db ?
59
      .pci_bus		db ?
59
	.irq_line	db ?
-
 
60
	.cur_rx 	db ?
60
      .pci_dev		db ?
61
	.cur_tx 	db ?
-
 
62
	.last_tx	db ?
61
      .irq_line 	db ?
63
	.pci_revision	db ?
-
 
64
	.table_entries	db ?
62
      .cur_rx		db ?
65
 
63
      .pci_revision	db ?
66
			dw ? ; align 4
-
 
67
 
64
      .table_entries:	db ?
68
	.special_func	dd ?
-
 
69
 
65
align 4
70
	.txd		rd (4 * NUM_TX_DESC)
Line 66... Line 71...
66
      .special_func:	dd 0
71
	.rxd		rd (4 * NUM_RX_DESC)
-
 
72
 
67
      .txd: times (3 * NUM_TX_DESC) dd 0
73
	.size = $ - device
68
      .rxd: times (3 * NUM_RX_DESC) dd 0
74
 
69
      .size:
-
 
-
 
75
end virtual
-
 
76
 
-
 
77
macro	ee_delay {
-
 
78
	push	eax
-
 
79
	in	eax, dx
-
 
80
	in	eax, dx
70
end virtual
81
	in	eax, dx
71
 
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
-
 
74
; Note that buffers must be contiguous in the physical memory;
84
	in	eax, dx
75
; because KernelAlloc allocates contiguous physical pages only in 8-pages blocks,
85
	in	eax, dx
76
; align ALLOCATION_SIZE up to 8*(page size) = 8000h
-
 
77
ALLOCATION_SIZE = (ALLOCATION_SIZE + 7FFFh) and not 7FFFh
-
 
78
 
-
 
79
MAX_DEVICES = 16	; maximum number of devices which this driver can handle
-
 
80
 
-
 
81
 
-
 
Line 82... Line 86...
82
	PCI_HEADER_TYPE 	      equ 0x0e	;8 bit
86
	in	eax, dx
Line 83... Line 87...
83
	PCI_BASE_ADDRESS_0	      equ 0x10	;32 bit
87
	in	eax, dx
84
	PCI_BASE_ADDRESS_5	      equ 0x24	;32 bits
88
	in	eax, dx
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 413... Line 403...
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
-
 
449
	jmp	.loop
463
   jmp	   .probe_loop
450
 
464
.probe_loop_failed:
451
  .error:
-
 
452
	DEBUGF	1, "Device not supported!\n"
-
 
453
	or	eax, -1
-
 
454
	ret
465
   jmp	   SIS900_Probe_Unsupported
455
 
466
;*********Find Get Mac Function*********
456
; Find Get Mac Function
467
.probe_loop_ok:
457
  .ok:
468
   mov	    eax,[esi+4] 	; Get pointer to "get MAC" function
458
	mov	eax, [esi+4]		; Get pointer to "get MAC" function
469
   mov	    [sis900_get_mac_func],eax
459
	mov	[get_mac_func], eax
470
   mov	    eax,[esi+8] 	; Get pointer to special initialization fn
460
	mov	eax, [esi+8]		; Get pointer to special initialization fn
-
 
461
	mov	[special_func], eax
471
   mov	    [sis900_special_func],eax
462
 
472
;******** Get MAC ********
463
; Get MAC
-
 
464
	call	[get_mac_func]
473
   call     dword [sis900_get_mac_func]
465
 
-
 
466
; Call special initialization fn if requested
474
;******** Call special initialization fn if requested ********
467
 
475
   cmp	    dword [sis900_special_func],0
468
	cmp	[special_func],0
476
   je	    .no_special_init
469
	je	@f
477
   call     dword [sis900_special_func]
470
	call	[special_func]
-
 
471
       @@:
478
.no_special_init:
472
 
-
 
473
; Set table entries
479
;******** Set table entries ********
474
 
480
   mov	    al,[SIS900_pci_revision]
475
	mov	 byte [table_entries], 16
481
   cmp	    al,SIS635A_900_REV
476
	cmp	 [pci_revision], SIS635A_900_REV
482
   jae	    .ent16
477
	jae	 @f
483
   cmp	    al,SIS900B_900_REV
478
	cmp	 [pci_revision], SIS900B_900_REV
484
   je	    .ent16
479
	je	 @f
485
   mov	    byte [sis900_table_entries],8
480
	mov	 byte [table_entries], 8
486
   jmp	    .ent8
-
 
487
.ent16:
-
 
488
   mov	    byte [sis900_table_entries],16
481
       @@:
489
.ent8:
482
 
490
;*******Probe for mii transceiver*******
-
 
491
;TODO!!*********************
-
 
492
;*******Initialize Device*******
-
 
493
   call sis900_init
-
 
494
   ret
483
; TODO: Probe for mii transceiver
495
 
-
 
496
SIS900_Probe_Unsupported:
-
 
497
if defined SIS900_DEBUG
-
 
498
   mov	   esi, SIS900_Debug_Str_Unsupported
-
 
499
   call    sys_msg_board_str
-
 
500
end if
-
 
501
   or	   eax, -1
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
 
-
 
534
;***************************************************************************
-
 
535
;   Function
-
 
536
;      SIS900_reset
-
 
537
;   Description
522
 
538
;      disables interrupts and soft resets the controller chip
523
;***************************************************************************
-
 
524
;
-
 
525
; reset
-
 
526
;
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:
846
SIS900_Debug_Str_GetMac_Address2 db 'Your SIS96x Mac ID is: ',0
849
;***************************************************************************
847
end if
850
align 4
848
SIS960_get_mac_addr:
851
SIS960_get_mac_addr:
849
   push     ebp
852
 
-
 
853
;-------------------------------
-
 
854
; Send Request for eeprom access
850
   mov	    ebp,[ebx+device.io_addr]
855
 
851
   ;**********Send Request for eeprom access*********************
856
	set_io	0
852
   lea	    edx,[ebp+SIS900_mear]		; Eeprom access register
857
	set_io	mear		; Eeprom access register
-
 
858
	mov	eax, EEREQ	; Request access to eeprom
853
   mov	    eax, SIS900_EEREQ			; Request access to eeprom
859
	out	dx, eax 	; Send request
854
   out	    dx, eax						; Send request
860
 
-
 
861
;-----------------------------------------------------
855
   xor	    ecx,ecx						;
862
; Loop 4000 times and if access not granted, error out
-
 
863
 
856
   ;******Loop 4000 times and if access not granted error out*****
864
	mov	ecx, 4000
857
SIS96X_Get_Mac_Wait:
865
  .loop:
858
   in	    eax, dx					;get eeprom status
866
	in	eax, dx 	; get eeprom status
859
   and	    eax, SIS900_EEGNT	    ;see if eeprom access granted flag is set
867
	test	eax, EEGNT	; see if eeprom access granted flag is set
-
 
868
	jnz	.got_access	; if it is, go access the eeprom
860
   jnz	    SIS900_Got_EEP_Access	;if it is, go access the eeprom
869
	loop	.loop		; else keep waiting
-
 
870
 
861
   inc	    ecx 					;else keep waiting
871
	DEBUGF	1, "Access to EEprom failed!\n", 0
862
   cmp	    ecx, 4000				;have we tried 4000 times yet?
872
 
863
   jl	    SIS96X_Get_Mac_Wait     ;if not ask again
873
	set_io	mear		; Eeprom access register
-
 
874
	mov	eax, EEDONE	; tell eeprom we are done
864
   xor	    eax, eax		    ;return zero in eax indicating failure
875
	out	dx, eax
865
   ;*******Debug **********************
876
 
-
 
877
	or	eax, -1 	; error
866
if defined SIS900_DEBUG
878
	ret
867
   mov esi,SIS900_Debug_Str_GetMac_Failed
879
 
868
   call sys_msg_board_str
880
  .got_access:
869
end if
881
 
870
   jmp SIS960_get_mac_addr_done
-
 
-
 
882
;------------------------------------------
871
   ;**********EEprom access granted, read MAC from card*************
883
; 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
877
   add	    eax, ecx				     ;Current Mac Byte Offset
890
	add	eax, ecx		; Current Mac Byte Offset
878
   push     ecx
891
	push	ecx
879
   call     sis900_read_eeprom		 ;try to read 16 bits
892
	call	read_eeprom		; try to read 16 bits
880
   pop	    ecx
893
	pop	ecx
881
   mov	    word [ebx+device.mac+ecx*2], ax	   ;save 16 bits to the MAC ID varible
894
	mov	word [device.mac+ecx*2], ax	; save 16 bits to the MAC ID varible
882
   dec	    ecx 			 ;one less word to read
895
	dec	ecx			; one less word to read
-
 
896
	jns	.read_loop		; if more read more
883
   jns	    SIS96x_mac_read_loop	 ;if more read more
897
	mov	eax, 1			; return non-zero indicating success
884
   mov	    eax, 1			 ;return non-zero indicating success
-
 
-
 
898
 
885
   ;*******Debug Print MAC ID to debug window**********************
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
886
if defined SIS900_DEBUG
-
 
887
   mov esi,SIS900_Debug_Str_GetMac_Address2
-
 
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
-
 
891
end if
903
 
892
   ;**********Tell EEPROM We are Done Accessing It*********************
904
  .done:
893
SIS960_get_mac_addr_done:
905
	set_io	0
894
   lea	    edx,[ebp+SIS900_mear]		; Eeprom access register
906
	set_io	mear		; Eeprom access register
895
   mov	    eax, SIS900_EEDONE		 ;tell eeprom we are done
-
 
896
   out	    dx,eax
-
 
897
   pop	    ebp
-
 
898
   ret
-
 
899
;***************************************************************************
-
 
900
;*      sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model
-
 
901
;*      @pci_dev: the sis900 pci device
907
	mov	eax, EEDONE	; tell eeprom we are done
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
-
 
907
;***************************************************************************
-
 
908
SIS900_get_mac_addr:
-
 
909
   ;*******Debug **********************
-
 
910
if defined SIS900_DEBUG
-
 
911
   mov esi,SIS900_Debug_Str_GetMac_Start
-
 
912
   call sys_msg_board_str
-
 
913
end if
-
 
914
   ;******** check to see if we have sane EEPROM *******
-
 
915
   mov	    eax, SIS900_EEPROMSignature  ;Base Eeprom Signature
-
 
916
   call     sis900_read_eeprom		 ;try to read 16 bits
-
 
917
   cmp ax, 0xffff
-
 
918
   je SIS900_Bad_Eeprom
-
 
919
   cmp ax, 0
-
 
920
   je SIS900_Bad_Eeprom
-
 
921
   ;**************Read MacID**************
908
	out	dx, eax
922
   ; zero based so 3-16 bit reads will take place
-
 
923
   mov	    ecx, 2
-
 
924
SIS900_mac_read_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
-
 
934
   ;*******Debug Print MAC ID to debug window**********************
-
 
935
if defined SIS900_DEBUG
-
 
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
909
 
940
end if
910
	xor	eax, eax	; ok
941
   ret
-
 
942
 
-
 
943
SIS900_Bad_Eeprom:
-
 
944
   xor eax, eax
-
 
945
   ;*******Debug **********************
-
 
946
if defined SIS900_DEBUG
-
 
947
   mov esi,SIS900_Debug_Str_GetMac_Failed
-
 
948
   call sys_msg_board_str
911
	ret
949
end if
-
 
950
   ret
-
 
951
;***************************************************************************
912
 
952
;*      Get_Mac_SIS635_900_REV: - Get MAC address for model 635
913
 
953
;*
914
 
-
 
915
 
-
 
916
;***************************************************************************
-
 
917
;
-
 
918
; get_mac_addr: - Get MAC address for stand alone SiS900 model
-
 
919
;
-
 
920
; Older SiS900 and friends, use EEPROM to store MAC address.
-
 
921
;
-
 
922
;***************************************************************************
-
 
923
align 4
-
 
924
get_mac_addr:
-
 
925
 
-
 
926
;------------------------------------
-
 
927
; check to see if we have sane EEPROM
-
 
928
 
-
 
929
	mov	eax, EEPROMSignature  ; Base Eeprom Signature
-
 
930
	call	read_eeprom	      ; try to read 16 bits
-
 
931
	cmp	ax, 0xffff
-
 
932
	je	.err
-
 
933
	test	ax, ax
-
 
934
	je	.err
-
 
935
 
-
 
936
;-----------
-
 
937
; Read MacID
-
 
938
 
-
 
939
; zero based so 3-16 bit reads will take place
-
 
940
 
-
 
941
	mov	ecx, 2
-
 
942
  .loop:
-
 
943
	mov	eax, EEPROMMACAddr    ;Base Mac Address
-
 
944
	add	eax, ecx				 ;Current Mac Byte Offset
-
 
945
	push	ecx
-
 
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
-
 
956
 
-
 
957
 
-
 
958
  .err:
-
 
959
	DEBUGF	1, "Access to EEprom failed!\n", 0
-
 
960
 
-
 
961
	or	eax, -1
-
 
962
	ret
-
 
963
 
-
 
964
 
-
 
965
;***************************************************************************
-
 
966
;
-
 
967
; Get_Mac_SIS635_900_REV: - Get MAC address for model 635
-
 
968
;
954
;*
969
;***************************************************************************
955
;***************************************************************************
-
 
956
Get_Mac_SIS635_900_REV:
-
 
957
if defined SIS900_DEBUG
-
 
958
    mov     esi,SIS900_Debug_Str_GetMac_Start
970
align 4
959
    call    sys_msg_board_str
971
Get_Mac_SIS635_900_REV:
960
end if
-
 
961
    push    ebp
972
 
962
    mov     ebp,[ebx+device.io_addr]
973
	set_io	0
963
    lea     edx,[ebp+SIS900_rfcr]
974
	set_io	rfcr
-
 
975
	in	eax, dx
964
    in	    eax,dx
976
	mov	edi, eax ; EDI=rfcrSave
965
    mov     edi,eax ; EDI=rfcrSave
977
 
966
    lea     edx,[ebp+SIS900_cr]
978
	set_io	cr
-
 
979
	or	eax, RELOAD
967
    or	    eax,SIS900_RELOAD
980
	out	dx, eax
968
    out     dx,eax
981
 
-
 
982
	xor	eax, eax
-
 
983
	out	dx, eax
969
    xor     eax,eax
984
 
-
 
985
;-----------------------------------------------
970
    out     dx,eax
986
; Disable packet filtering before setting filter
971
    ; Disable packet filtering before setting filter
987
 
972
    lea     edx,[ebp+SIS900_rfcr]
988
	set_io	rfcr
973
    mov     eax,edi
989
	mov	eax, edi
-
 
990
	and	edi, not RFEN
-
 
991
	out	dx, eax
974
    and     edi,not SIS900_RFEN
992
 
-
 
993
;---------------------------------
975
    out     dx,eax
994
; Load MAC to filter data register
976
    ; Load MAC to filter data register
995
 
977
    xor     ecx,ecx
996
	mov	ecx, 3
-
 
997
	lea	edi, [device.mac]
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
983
    out     dx,eax
1003
	out	dx, eax
984
    lea     edx,[ebp+SIS900_rfdr]
-
 
985
    in	    eax,dx
-
 
986
    mov     [esi],ax
1004
 
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]
1005
	set_io	rfdr
1001
    call    Create_Mac_String
1006
	in	eax, dx
1002
end if
-
 
1003
    pop     ebp
-
 
1004
    ret
-
 
1005
;***************************************************************************
1007
	stosw
1006
;* Function: sis900_read_eeprom
1008
	loop	.loop
1007
;*
-
 
1008
;* Description: reads and returns a given location from EEPROM
1009
 
1009
;*
-
 
1010
;* Arguments: eax - location:       requested EEPROM location
-
 
1011
;*
1010
;------------------------
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:
1011
; Enable packet filtering
1037
   mov	     eax, 1
-
 
1038
   shl	     eax, cl
-
 
1039
   and	     eax, ebx
1012
 
1040
   jz SIS900_Read_Eeprom_8
-
 
1041
   mov	     eax, 9
-
 
1042
   jmp	     SIS900_Read_Eeprom_9
1013
;        set_io  rfcr
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
1014
;        mov     eax, edi
1066
    or	     eax, SIS900_EECLK
-
 
1067
    out      dx, eax
-
 
1068
    call     SIS900_Eeprom_Delay_1
-
 
1069
    in	     eax, dx
-
 
1070
    shl      ebx, 1
-
 
1071
    and      eax, SIS900_EEDO
-
 
1072
    jz	     SIS900_Read_Eeprom_0
-
 
1073
    or	     ebx, 1
1015
;        or      eax, RFEN
1074
SIS900_Read_Eeprom_0:
-
 
1075
   dec	     cx
-
 
1076
   jnz	     sis900_read_eeprom_Send2
1016
;        out     dx, eax
1077
   ;************** Terminate the EEPROM access. **************
-
 
1078
   xor	     eax, eax
-
 
1079
   out	     dx, eax
-
 
1080
   call      SIS900_Eeprom_Delay_1
-
 
1081
   mov	     eax, SIS900_EECLK
-
 
1082
   out	     dx, eax
-
 
1083
   mov	     eax, ebx
-
 
1084
   and	     eax, 0x0000ffff			;return only 16 bits
-
 
1085
   pop	     ebp
-
 
1086
   pop	     ebx
-
 
1087
   pop	     ecx
-
 
1088
   pop	     edx
1017
 
-
 
1018
	xor	eax, eax
1089
   pop	     esi
1019
	ret
1090
   ret
-
 
1091
;***************************************************************************
-
 
1092
;   Function
-
 
1093
;      SIS900_Eeprom_Delay_1
1020
 
-
 
1021
;***************************************************************************
1094
;   Description
1022
;
-
 
1023
; read_eeprom
1095
;
1024
;
-
 
1025
; reads and returns a given location from EEPROM
-
 
1026
;
1096
;
1027
; IN:  si = addr
1097
;
1028
; OUT: ax = data
-
 
1029
;
1098
;
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
-
 
1047
 
-
 
1048
	or	esi, EEread
-
 
1049
	mov	ecx, 1 shl 9
-
 
1050
 
-
 
1051
  .loop:
-
 
1052
	mov	eax, EECS
-
 
1053
	test	esi, ecx
1099
;***************************************************************************
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
-
 
1076
  .loop2:
-
 
1077
	mov	eax, EECS
-
 
1078
	out	dx, eax
-
 
1079
	ee_delay
-
 
1080
 
-
 
1081
	or	eax, EECLK
-
 
1082
	out	dx, eax
1100
SIS900_Eeprom_Delay_1:
1083
	ee_delay
-
 
1084
 
-
 
1085
	in	eax, dx
-
 
1086
	shl	esi, 1
-
 
1087
	test	eax, EEDO
1101
   push eax
1088
	jz	@f
-
 
1089
	inc	esi
-
 
1090
       @@:
-
 
1091
	loop	.loop2
-
 
1092
 
-
 
1093
;----------------------------
-
 
1094
; Terminate the EEPROM access
-
 
1095
 
-
 
1096
	xor	eax, eax
-
 
1097
	out	dx, eax
-
 
1098
	ee_delay
-
 
1099
 
-
 
1100
	mov	eax, EECLK
-
 
1101
	out	dx, eax
-
 
1102
	ee_delay
-
 
1103
 
1102
   in eax, dx
1104
	movzx	eax, si
-
 
1105
 
-
 
1106
	ret
Line -... Line 1107...
-
 
1107
 
1103
   pop eax
1108
 
1104
   ret
1109
 
1105
 
1110
align 4
1106
write_mac:
1111
write_mac:
Line 1107... Line 1112...
1107
	DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n'
1112
	DEBUGF 1,'Setting MAC is not supported for SIS900 card.\n'
1108
	add	esp, 6
-
 
1109
	ret
-
 
1110
 
-
 
1111
;***************************************************************************
-
 
1112
;   Function
1113
	add	esp, 6
-
 
1114
	ret
-
 
1115
 
-
 
1116
;***************************************************************************
-
 
1117
;
1113
;      int_handler
1118
; int_handler
1114
;   Description
1119
;
-
 
1120
; handles received IRQs, which signal received packets
1115
;      handles received IRQs, which signal received packets
1121
;
1116
;
-
 
1117
;  Currently only supports one descriptor per packet, if packet is fragmented
-
 
1118
;  between multiple descriptors you will lose part of the packet
-
 
1119
;***************************************************************************
-
 
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
1131
.nextdevice:
1133
.nextdevice:
1132
	mov	ebx, [esi]
1134
	mov	ebx, [esi]
1133
	mov	edx, [ebx+device.io_addr]
1135
	set_io	0
1134
	add	edx, SIS900_isr
1136
	set_io	isr
1135
	in	eax, dx ; note that this clears all interrupts
1137
	in	eax, dx ; note that this clears all interrupts
1136
	test	al, SIS900_RxOK
1138
	test	ax, IE
1137
	jnz	.got_it
1139
	jnz	.got_it
-
 
1140
	loop	.nextdevice
-
 
1141
.nothing:
-
 
1142
	ret
-
 
1143
.got_it:
-
 
1144
 
-
 
1145
	test	ax, RxOK
-
 
1146
	jz	.no_rx
1138
	loop	.nextdevice
1147
 
1139
.nothing:
1148
	push	ax
1140
	ret
1149
 
1141
.got_it:
1150
;-----------
-
 
1151
; Get Status
1142
    ;**************Get Status **************
1152
	movzx	eax, [device.cur_rx]		; find current discriptor
1143
    movzx     eax, [ebx+device.cur_rx]		;find current discriptor
1153
	shl	eax, 4				; * 16
1144
    imul      eax, 12		    ;
1154
	mov	ecx, dword[device.rxd+eax+4]	; get receive status
1145
    mov       ecx, [ebx+device.rxd+eax+4]	   ; get receive status
1155
 
1146
    ;**************Check Status **************
1156
;-------------------------------------------
-
 
1157
; Check RX_Status to see if packet is waiting
-
 
1158
	test	ecx, 0x80000000
1147
    ;Check RX_Status to see if packet is waiting
1159
	jnz	.is_packet
1148
    test      ecx, 0x80000000
1160
	ret
1149
    jnz       SIS900_poll_IS_packet
1161
 
1150
    ret
1162
;----------------------------------------------
-
 
1163
; There is a packet waiting check it for errors
-
 
1164
  .is_packet:
1151
   ;**********There is a packet waiting check it for errors**************
1165
	test	ecx, 0x67C0000			; see if there are any errors
1152
SIS900_poll_IS_packet:
1166
	jnz	.error_status
1153
    test      ecx, 0x67C0000		;see if there are any errors
-
 
1154
    jnz       SIS900_Poll_Error_Status
1167
 
1155
   ;**************Check size of packet*************
1168
;---------------------
1156
   and	     ecx, SIS900_DSIZE					;get packet size minus CRC
-
 
1157
   cmp	     ecx, SIS900_CRC_SIZE
-
 
-
 
1169
; Check size of packet
1158
   ;make sure packet contains data
1170
	and	ecx, DSIZE			; get packet size minus CRC
1159
   jle	     SIS900_Poll_Error_Size
1171
	sub	ecx, CRC_SIZE			; make sure packet contains data
1160
   ;*******Copy Good Packet to receive buffer******
1172
	jle	.error_size
1161
   sub	    ecx, SIS900_CRC_SIZE			     ;dont want crc
1173
 
-
 
1174
; update statistics
1162
   ; update statistics
1175
	inc	dword [device.packets_rx]
1163
   inc	    dword [ebx+device.packets_rx]
1176
	add	dword [device.bytes_rx], ecx
1164
   add	    dword [ebx+device.bytes_rx], ecx
1177
	adc	dword [device.bytes_rx+4], 0
1165
   adc	    dword [ebx+device.bytes_rx+4], 0
1178
 
1166
   push     ecx
1179
	push	ebx
1167
   stdcall  KernelAlloc, ecx
1180
	push	.return
1168
   pop	    ecx
1181
	push	ecx				; packet size
1169
   test     eax, eax
1182
	push	[device.rxd+eax+12]		; packet ptr
-
 
1183
	DEBUGF	1, "Packet received OK\n"
1170
   jz	    int_handler.nothing
1184
	jmp	EthReceiver
1171
   push     ebx
-
 
1172
   push     .return ; return address for EthReceiver
1185
  .return:
1173
   ;**********Continue copying packet****************
1186
	pop	ebx
1174
   push     ecx eax ; save buffer pointer and size for EthReceiver
1187
 
1175
   mov	    edi, eax
1188
; Reset status, allow ethernet card access to descriptor
1176
   movzx    esi, byte [ebx+device.cur_rx]
1189
	movzx	ecx, [device.cur_rx]
1177
   imul     esi, RX_BUFF_SZ
-
 
1178
   lea	    esi, [esi+ebx+0x1000+NUM_TX_DESC*TX_BUFF_SZ]
1190
	shl	ecx, 4				; *16
1179
   ; first copy dword-wise, divide size by 4
1191
	mov	ecx, [device.rxd+ecx]
1180
   shr	    ecx, 2
1192
	stdcall KernelAlloc, RX_BUFF_SZ
1181
   rep	    movsd							; copy the dwords
1193
	test	eax, eax
1182
   mov	    ecx, [esp+4]
1194
	jz	.fail
-
 
1195
	mov	dword [ecx+12], eax
1183
   and	    ecx, 3						    ;
1196
	GetRealAddr
1184
   rep	    movsb
1197
	mov	dword [ecx+8], eax
1185
   ;********Debug, tell user we have a good packet*************
1198
	mov	dword [ecx+4], RX_BUFF_SZ
1186
if defined SIS900_DEBUG
1199
 
1187
   mov	    esi, SIS900_Debug_Pull_Packet_good
1200
	inc	[device.cur_rx] 			 ; get next descriptor
1188
   call     sys_msg_board_str
-
 
1189
end if
1201
	and	[device.cur_rx], NUM_RX_DESC-1		 ; only 4 descriptors 0-3
1190
   jmp	    EthReceiver
1202
 
1191
.return:
-
 
1192
   pop	    ebx
-
 
1193
   jmp	    SIS900_Poll_Cnt
1203
; Enable Receiver
1194
   ;*************Error occured let user know through debug window***********
1204
	set_io	0
-
 
1205
	set_io	cr		; Command Register offset
1195
SIS900_Poll_Error_Status:
1206
	in	eax, dx 	; Get current Command Register
1196
if defined SIS900_DEBUG
1207
	or	eax, RxENA	; Enable Receiver
-
 
1208
	out	dx, eax
1197
		mov	 esi, SIS900_Debug_Pull_Bad_Packet_Status
1209
 
-
 
1210
	pop	ax
1198
		call	 sys_msg_board_str
1211
	jmp	.no_rx
1199
end if
1212
 
-
 
1213
  .error_status:
1200
		jmp	 SIS900_Poll_Cnt
1214
 
1201
SIS900_Poll_Error_Size:
1215
	DEBUGF	1, "Packet error: %x\n", ecx
1202
if defined SIS900_DEBUG
1216
	jmp	.continue
1203
		mov	 esi, SIS900_Debug_Pull_Bad_Packet_Size
1217
 
1204
		call	 sys_msg_board_str
-
 
-
 
1218
  .error_size:
1205
end if
1219
 
1206
   ;*************Increment to next available descriptor**************
1220
	DEBUGF	1, "Packet too large/small\n"
1207
SIS900_Poll_Cnt:
1221
	jmp	.continue
1208
    ;Reset status, allow ethernet card access to descriptor
-
 
1209
   movzx    eax, [ebx+device.cur_rx]
-
 
1210
   lea	    eax, [eax*3]
-
 
-
 
1222
 
1211
   mov	    ecx, RX_BUFF_SZ
1223
  .no_rx:
1212
   mov	    [ebx+device.rxd+eax*4+4], ecx		 ;
1224
	test	ax, TxOk
1213
   inc	    [ebx+device.cur_rx] 			 ;get next descriptor
-
 
1214
   and	    [ebx+device.cur_rx],NUM_RX_DESC-1		 ;only 4 descriptors 0-3
-
 
1215
   ;******Enable Receiver************
-
 
-
 
1225
	jz	.no_tx
1216
   mov	    edx, [ebx+device.io_addr]
1226
 
-
 
1227
	;;; TODO: free all unused buffers
1217
   add	    edx, SIS900_cr ; Command Register offset
1228
	stdcall   KernelFree, eax
-
 
1229
 
-
 
1230
  .no_tx:
-
 
1231
 
1218
   in	    eax, dx			    ; Get current Command Register
1232
	ret
1219
   or	    eax, SIS900_RxENA	;Enable Receive
1233
 
1220
   out	    dx, eax
1234
 
1221
   ret
1235
 
1222
;***************************************************************************
1236
;***************************************************************************
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
1256
 
1290
   ;***************restart the transmitter ********
-
 
1291
   lea	    edx,[ebp+SIS900_cr]
1257
	movzx	ecx, [device.cur_tx]
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]
1258
	mov	ecx, [device.txd+ecx*16]
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
-
 
1310
 
1259
 
1311
;***************************************************************************
-
 
1312
;* Function: Create_Mac_String
-
 
1313
;*
-
 
1314
;* Description: Converts the 48 bit value to a string for display
1260
;; TODO: check if desc is empty (for example: check for eax, 0x6200000  at [ecx+4]
1315
;*
-
 
1316
;* String Format: XX:XX:XX:XX:XX:XX
-
 
1317
;*
-
 
1318
;* Arguments: node_addr is location of 48 bit MAC ID
-
 
1319
;*
-
 
1320
;* Returns:   Prints string to general debug window
1261
;;; or: count number of available descriptors
1321
;*
-
 
1322
;*
-
 
1323
;done
-
 
1324
;***************************************************************************
-
 
1325
if defined SIS900_DEBUG
-
 
1326
 
1262
 
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
-
 
1330
Create_Mac_String:
1263
	mov	eax, [esp+4]
1331
   pusha
-
 
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
1273
; update stats
1342
   mov bl, byte [SIS900_Char_String+eax]
-
 
1343
   mov [Mac_str_build+1+ecx*3], bl
-
 
1344
   cmp ecx, 5
-
 
1345
   je Create_Mac_String_done
1274
	inc	[device.packets_tx]
1346
   mov bl, ':'
-
 
1347
   mov [Mac_str_build+2+ecx*3], bl
1275
	add	dword [device.bytes_tx], ecx
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
-
 
1353
   mov [Mac_str_build+4+ecx*3],byte 0
1276
	adc	dword [device.bytes_tx+4], 0
1354
   mov esi, Mac_str_build
-
 
1355
   call sys_msg_board_str				;Print String to message board
-
 
1356
   popa
1277
 
1357
   ret
1278
	ret
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:
-
 
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
 
Line 1390... Line 1283...
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
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
Line 1400... Line 1293...
1400
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
1293
    dd SIS635A_900_REV,Get_Mac_SIS635_900_REV,0
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
Line 1404... Line 1297...
1404
 
1297