Rev 1514 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1514 | Rev 1519 | ||
---|---|---|---|
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. ;; |
9 | ;; ;; |
9 | ;; ;; |
10 | ;; This driver is based on the SIS900 driver from ;; |
10 | ;; This driver is based on the SIS900 driver from ;; |
11 | ;; the etherboot 5.0.6 project. The copyright statement is ;; |
11 | ;; the etherboot 5.0.6 project. The copyright statement is ;; |
12 | ;; ;; |
12 | ;; ;; |
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
13 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; Version 2, June 1991 ;; |
14 | ;; Version 2, June 1991 ;; |
15 | ;; ;; |
15 | ;; ;; |
16 | ;; remaining parts Copyright 2004 Jason Delozier, ;; |
16 | ;; remaining parts Copyright 2004 Jason Delozier, ;; |
17 | ;; cordata51@hotmail.com ;; |
17 | ;; cordata51@hotmail.com ;; |
18 | ;; ;; |
18 | ;; ;; |
19 | ;; See file COPYING for details ;; |
19 | ;; See file COPYING for details ;; |
20 | ;; ;; |
20 | ;; ;; |
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
25 | - | ||
26 | ; $Revision: 1514 $ |
- | |
27 | 25 | ||
28 | format MS COFF |
26 | format MS COFF |
29 | 27 | ||
30 | API_VERSION equ 0x01000100 |
28 | API_VERSION equ 0x01000100 |
- | 29 | DRIVER_VERSION equ 5 |
|
- | 30 | ||
- | 31 | MAX_DEVICES equ 16 |
|
31 | 32 | ||
32 | DEBUG equ 1 |
33 | DEBUG equ 1 |
33 | __DEBUG__ equ 1 |
34 | __DEBUG__ equ 1 |
34 | __DEBUG_LEVEL__ equ 1 |
35 | __DEBUG_LEVEL__ equ 1 |
35 | 36 | ||
36 | include 'proc32.inc' |
37 | include 'proc32.inc' |
37 | include 'imports.inc' |
38 | include 'imports.inc' |
38 | include 'fdo.inc' |
39 | include 'fdo.inc' |
39 | include 'netdrv.inc' |
40 | include 'netdrv.inc' |
40 | 41 | ||
41 | public START |
42 | public START |
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 | 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 |
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 |
53 | device: |
52 | device: |
54 | 53 | ||
55 | ETH_DEVICE |
54 | ETH_DEVICE |
56 | - | ||
57 | ; device specific |
55 | |
58 | .io_addr dd ? |
56 | .io_addr dd ? |
59 | .pci_bus db ? |
57 | .pci_bus db ? |
60 | .pci_dev db ? |
58 | .pci_dev db ? |
61 | .irq_line db ? |
59 | .irq_line db ? |
62 | .cur_rx db ? |
60 | .cur_rx db ? |
- | 61 | .cur_tx db ? |
|
- | 62 | .last_tx db ? |
|
63 | .pci_revision db ? |
63 | .pci_revision db ? |
64 | .table_entries: db ? |
64 | .table_entries db ? |
- | 65 | ||
65 | align 4 |
66 | dw ? ; align 4 |
- | 67 | ||
66 | .special_func: dd 0 |
68 | .special_func dd ? |
- | 69 | ||
67 | .txd: times (3 * NUM_TX_DESC) dd 0 |
70 | .txd rd (4 * NUM_TX_DESC) |
68 | .rxd: times (3 * NUM_RX_DESC) dd 0 |
71 | .rxd rd (4 * NUM_RX_DESC) |
- | 72 | ||
69 | .size: |
73 | .size = $ - device |
- | 74 | ||
70 | end virtual |
75 | end virtual |
71 | 76 | ||
- | 77 | macro ee_delay { |
|
72 | ; First page is designated to ETH_DEVICE, buffers start from second |
78 | push eax |
73 | ALLOCATION_SIZE = ((device.size+0FFFh) and not 0FFFh) + TOTAL_BUFFERS_SIZE |
79 | in eax, dx |
74 | ; Note that buffers must be contiguous in the physical memory; |
- | |
- | 80 | in eax, dx |
|
- | 81 | in eax, dx |
|
- | 82 | in eax, dx |
|
- | 83 | in eax, dx |
|
- | 84 | in eax, dx |
|
- | 85 | in eax, dx |
|
75 | ; because KernelAlloc allocates contiguous physical pages only in 8-pages blocks, |
86 | in eax, dx |
76 | ; align ALLOCATION_SIZE up to 8*(page size) = 8000h |
87 | in eax, dx |
77 | ALLOCATION_SIZE = (ALLOCATION_SIZE + 7FFFh) and not 7FFFh |
88 | in eax, dx |
78 | - | ||
79 | MAX_DEVICES = 16 ; maximum number of devices which this driver can handle |
89 | pop eax |
80 | 90 | } |
|
81 | - | ||
82 | PCI_HEADER_TYPE equ 0x0e ;8 bit |
- | |
83 | PCI_BASE_ADDRESS_0 equ 0x10 ;32 bit |
- | |
84 | PCI_BASE_ADDRESS_5 equ 0x24 ;32 bits |
- | |
85 | PCI_BASE_ADDRESS_SPACE_IO equ 0x01 |
- | |
86 | PCI_VENDOR_ID equ 0x00 ;16 bit |
- | |
87 | PCI_BASE_ADDRESS_IO_MASK equ 0xFFFFFFFC |
91 | |
88 | 92 | ||
89 | section '.flat' code readable align 16 |
93 | section '.flat' code readable align 16 |
90 | 94 | ||
91 | ; Driver entry point - register our service when the driver is loading. |
95 | ; Driver entry point - register our service when the driver is loading. |
92 | ; TODO: add needed operations when unloading |
96 | ; TODO: add needed operations when unloading |
93 | START: |
97 | START: |
94 | cmp dword [esp+4], 1 |
98 | cmp dword [esp+4], 1 |
95 | jne .exit |
99 | jne .exit |
96 | stdcall RegService, my_service, service_proc |
100 | stdcall RegService, my_service, service_proc |
97 | ret 4 |
101 | ret 4 |
98 | .exit: |
102 | .exit: |
99 | xor eax, eax |
103 | xor eax, eax |
100 | ret 4 |
104 | ret 4 |
101 | 105 | ||
102 | ; Service procedure for the driver - handle all I/O requests for the driver. |
106 | ; Service procedure for the driver - handle all I/O requests for the driver. |
103 | ; Currently handled requests are: SRV_GETVERSION = 0 and SRV_HOOK = 1. |
107 | ; Currently handled requests are: SRV_GETVERSION = 0 and SRV_HOOK = 1. |
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 |
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 |
177 | ; TODO: implement check if bus and dev exist on this machine |
187 | ; TODO: implement check if bus and dev exist on this machine |
178 | - | ||
179 | mov edx, PCI_BASE_ADDRESS_0 |
- | |
180 | .reg_check: |
- | |
181 | push edx |
188 | |
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 | - | ||
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 |
192 | ; We've found the io address, find IRQ now |
199 | stdcall PciRead8, dword [ebx+device.pci_bus], dword [ebx+device.pci_dev], 0x3c |
- | |
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). |
203 | mov eax, [NUM_DEV] |
196 | mov eax, [devices] |
204 | mov [DEV_LIST+4*eax], ebx |
197 | mov [device_list+4*eax], ebx |
205 | inc [NUM_DEV] |
- | |
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 |
|
209 | call SIS900_probe |
201 | call probe |
210 | test eax, eax |
202 | test eax, eax |
211 | jnz .destroy |
203 | jnz .destroy |
212 | ; 4n. If device was successfully initialized, register it for the kernel. |
204 | ; 4n. If device was successfully initialized, register it for the kernel. |
213 | 205 | ||
214 | mov [device.type], NET_TYPE_ETH |
206 | mov [device.type], NET_TYPE_ETH |
215 | call NetRegDev |
207 | call NetRegDev |
216 | 208 | ||
217 | cmp eax, -1 |
209 | cmp eax, -1 |
218 | je .destroy |
210 | je .destroy |
219 | 211 | ||
220 | ret 4 |
212 | ret 4 |
221 | 213 | ||
222 | ; 5. If the device was already loaded, find the device number and return it in eax |
214 | ; 5. If the device was already loaded, find the device number and return it in eax |
223 | 215 | ||
224 | .find_devicenum: |
216 | .find_devicenum: |
225 | mov ebx, eax |
217 | mov ebx, eax |
226 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
218 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
227 | ; into a device number in edi |
219 | ; into a device number in edi |
228 | mov eax, edi ; Application wants it in eax instead |
220 | mov eax, edi ; Application wants it in eax instead |
229 | ret 4 |
221 | ret 4 |
230 | 222 | ||
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: |
234 | dec [NUM_DEV] |
226 | dec [devices] |
235 | ; todo: reset device into virgin state |
227 | ; todo: reset device into virgin state |
236 | 228 | ||
237 | .err: |
229 | .err: |
238 | stdcall KernelFree, ebx |
230 | stdcall KernelFree, ebx |
239 | 231 | ||
240 | 232 | ||
241 | .fail: |
233 | .fail: |
242 | xor eax, eax |
234 | xor eax, eax |
243 | ret 4 |
235 | ret 4 |
244 | 236 | ||
245 | 237 | ||
246 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
238 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
247 | ;; ;; |
239 | ;; ;; |
248 | ;; Actual Hardware dependent code starts here ;; |
240 | ;; Actual Hardware dependent code starts here ;; |
249 | ;; ;; |
241 | ;; ;; |
250 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
242 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
251 | 243 | ||
252 | unload: |
244 | unload: |
253 | ; TODO: (in this particular order) |
245 | ; TODO: (in this particular order) |
254 | ; |
246 | ; |
255 | ; - Stop the device |
247 | ; - Stop the device |
256 | ; - Detach int handler |
248 | ; - Detach int handler |
257 | ; - Remove device from local list |
249 | ; - Remove device from local list |
258 | ; - call unregister function in kernel |
250 | ; - call unregister function in kernel |
259 | ; - Remove all allocated structures and buffers the card used |
251 | ; - Remove all allocated structures and buffers the card used |
260 | 252 | ||
261 | or eax,-1 |
253 | or eax,-1 |
262 | 254 | ||
263 | ret |
255 | ret |
264 | 256 | ||
265 | ;******************************************************************** |
257 | ;******************************************************************** |
266 | ; Interface |
- | |
267 | ; SIS900_reset |
- | |
268 | ; SIS900_probe |
- | |
269 | ; SIS900_poll |
- | |
270 | ; SIS900_transmit |
- | |
271 | ; |
- | |
272 | ;******************************************************************** |
- | |
273 | ;******************************************************************** |
- | |
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 |
277 | ; - Device ID: 0x0900 Vendor ID: 0x1039 Revision: 0x90 |
261 | ; - Device ID: 0x0900 Vendor ID: 0x1039 Revision: 0x90 |
278 | ; |
262 | ; |
279 | ; If your card is not listed, try it and let me know if it |
263 | ; If your card is not listed, try it and let me know if it |
280 | ; functions properly and it will be aded to the list. If not |
264 | ; functions properly and it will be aded to the list. If not |
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 | ;******************************************************************** |
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 |
399 | SIS900_960_REV equ 0x91 |
385 | 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 |
405 | SIS900_RFPromiscuous equ 0x70000000 |
392 | RFPromiscuous equ 0x70000000 |
- | 393 | ||
406 | ;SIS900 Reveive Filter Data Mask |
394 | ; Reveive Filter Data Mask |
407 | SIS900_RFDAT equ 0x0000FFFF |
395 | 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 |
413 | SIS900_EEPROMChecksum equ 0x0b |
402 | EEPROMChecksum equ 0x0b |
- | 403 | ||
414 | ;The EEPROM commands include the alway-set leading bit. |
404 | ;The EEPROM commands include the alway-set leading bit. |
415 | ;SIS900 Eeprom Command |
- | |
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 |
424 | SIS900_EEcmdShift equ 16 |
413 | 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 | 419 | ||
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 |
- | |
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 | ; |
|
442 | ;not done - still need to probe mii transcievers |
427 | ; TODO: probe mii transceivers |
- | 428 | ; |
|
443 | ;*************************************************************************** |
429 | ;*************************************************************************** |
444 | if defined SIS900_DEBUG |
- | |
445 | SIS900_Debug_Str_Unsupported db 'Sorry your card is unsupported ',13,10,0 |
- | |
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 | ||
451 | call SIS900_adjust_pci_device |
435 | make_bus_master [device.pci_bus], [device.pci_dev] |
- | 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 |
454 | mov [SIS900_pci_revision], al ;save the revision for later use |
439 | mov [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 |
449 | jmp .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 |
- | |
495 | 450 | ||
496 | SIS900_Probe_Unsupported: |
451 | .error: |
497 | if defined SIS900_DEBUG |
- | |
498 | mov esi, SIS900_Debug_Str_Unsupported |
452 | DEBUGF 1, "Device not supported!\n" |
499 | call sys_msg_board_str |
- | |
500 | end if |
- | |
501 | or eax, -1 |
453 | or eax, -1 |
502 | ret |
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 | ||
- | 485 | ||
503 | ;*************************************************************************** |
486 | ;*************************************************************************** |
504 | ; Function: sis900_init |
- | |
505 | ; |
487 | ; |
506 | ; Description: resets the ethernet controller chip and various |
- | |
507 | ; data structures required for sending and receiving packets. |
488 | ; init |
508 | ; |
489 | ; |
509 | ; Arguments: |
490 | ; resets the ethernet controller chip and various |
- | 491 | ; data structures required for sending and receiving packets. |
|
510 | ; |
492 | ; |
511 | ; returns: none |
- | |
512 | ;not done |
- | |
513 | ;*************************************************************************** |
493 | ;*************************************************************************** |
- | 494 | align 4 |
|
514 | sis900_init: |
495 | 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 |
521 | ;call SIS900_check_mode |
503 | ;call check_mode |
- | 504 | ||
522 | ; enable interrupts on packet receive |
505 | ; 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 |
527 | out dx, eax |
511 | out dx, eax |
- | 512 | ||
528 | ; globally enable interrupts |
513 | ; 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 |
531 | xor eax, eax |
517 | xor eax, eax |
- | 518 | ||
- | 519 | mov [device.mtu], 1514 |
|
- | 520 | ||
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 |
527 | ; disables interrupts and soft resets the controller chip |
539 | ; |
528 | ; |
540 | ;done+ |
- | |
541 | ;*************************************************************************** |
529 | ;*************************************************************************** |
542 | if defined SIS900_DEBUG |
- | |
543 | SIS900_Debug_Reset_Failed db 'Reset Failed ',0 |
- | |
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 | |
549 | mov ebp, [ebx+device.io_addr] ; base address |
535 | ;-------------------------------------------- |
550 | ;******Disable Interrupts and reset Receive Filter******* |
536 | ; Disable Interrupts and reset Receive Filter |
- | 537 | ||
- | 538 | set_io 0 |
|
551 | xor eax, eax ; 0 to initialize |
539 | set_io ier |
552 | lea edx,[ebp+SIS900_ier] |
540 | xor eax, eax |
553 | out dx, eax ; Write 0 to location |
541 | out dx, eax |
- | 542 | ||
554 | lea edx,[ebp+SIS900_imr] |
543 | set_io imr |
555 | out dx, eax ; Write 0 to location |
544 | out dx, eax |
- | 545 | ||
556 | lea edx,[ebp+SIS900_rfcr] |
546 | set_io rfcr |
557 | out dx, eax ; Write 0 to location |
547 | out dx, eax |
- | 548 | ||
- | 549 | ;----------- |
|
558 | ;*******Reset Card*********************************************** |
550 | ; Reset Card |
- | 551 | ||
559 | lea edx,[ebp+SIS900_cr] |
552 | set_io cr |
560 | in eax, dx ; Get current Command Register |
553 | in eax, dx ; Get current Command Register |
561 | or eax, SIS900_RESET ; set flags |
554 | or eax, RESET + RxRESET + TxRESET ; set flags |
562 | or eax, SIS900_RxRESET ; |
- | |
563 | or eax, SIS900_TxRESET ; |
- | |
564 | out dx, eax ; Write new Command Register |
555 | out dx, eax ; Write new Command Register |
565 | ;*******Wait Loop************************************************ |
- | |
- | 556 | ||
- | 557 | ;---------- |
|
566 | push ebx |
558 | ; Wait loop |
- | 559 | ||
567 | lea edx,[ebp+SIS900_isr] |
560 | set_io isr |
568 | mov ecx, 0x03000000 ; Status we would like to see from card |
- | |
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? |
564 | jz .error |
573 | in eax, dx ; move interrup status to eax |
565 | in eax, dx ; move interrup status to eax |
574 | and eax, ecx |
- | |
575 | xor ecx, eax |
- | |
576 | jz SIS900_DoneWait |
- | |
577 | jmp SIS900_Wait |
566 | cmp eax, 0x03000000 |
578 | SIS900_DoneWait_e: |
567 | jne .loop |
579 | if defined SIS900_DEBUG |
- | |
580 | mov esi, SIS900_Debug_Reset_Failed |
- | |
581 | call sys_msg_board_str |
- | |
582 | end if |
568 | |
583 | SIS900_DoneWait: |
569 | ;------------------------------------------------------ |
584 | pop ebx |
- | |
585 | ;*******Set Configuration Register depending on Card Revision******** |
570 | ; Set Configuration Register depending on Card Revision |
- | 571 | ||
586 | lea edx,[ebp+SIS900_cfg] |
572 | set_io cfg |
587 | mov eax, SIS900_PESEL ; Configuration Register Bit |
573 | mov eax, PESEL ; Configuration Register Bit |
588 | mov cl, [SIS900_pci_revision] ; card revision |
- | |
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 |
593 | out dx, eax ; no revision match |
578 | out dx, eax ; no revision match |
594 | jmp SIS900_Reset_Complete |
579 | jmp .done |
- | 580 | ||
595 | SIS900_RevMatch: ; Revision match |
581 | .match: ; Revision match |
596 | or eax, SIS900_RND_CNT ; Configuration Register Bit |
582 | or eax, RND_CNT ; Configuration Register Bit |
597 | out dx, eax |
583 | out dx, eax |
- | 584 | ||
598 | SIS900_Reset_Complete: |
585 | .done: |
599 | xor eax, eax |
586 | xor eax, eax |
600 | pop ebp |
- | |
601 | ret |
587 | ret |
- | 588 | ||
- | 589 | .error: |
|
- | 590 | DEBUGF 1, "Reset failed!\n" |
|
- | 591 | or eax, -1 |
|
- | 592 | ret |
|
- | 593 | ||
602 | 594 | ||
603 | ;*************************************************************************** |
- | |
604 | ; Function: sis_init_rxfilter |
595 | ;*************************************************************************** |
605 | ; |
596 | ; |
606 | ; Description: sets receive filter address to our MAC address |
597 | ; sis_init_rxfilter |
607 | ; |
598 | ; |
608 | ; Arguments: |
599 | ; sets receive filter address to our MAC address |
609 | ; |
- | |
610 | ; returns: |
- | |
611 | ;done+ |
600 | ; |
- | 601 | ;*************************************************************************** |
|
612 | ;*************************************************************************** |
602 | align 4 |
613 | SIS900_init_rxfilter: |
603 | init_rxfilter: |
614 | push ebp |
604 | |
615 | mov ebp, [ebx+device.io_addr] ; base address |
605 | ;------------------------------------ |
- | 606 | ; Get Receive Filter Control Register |
|
- | 607 | ||
616 | ;****Get Receive Filter Control Register ******** |
608 | set_io 0 |
617 | lea edx,[ebp+SIS900_rfcr] |
609 | set_io rfcr |
618 | in eax, dx ; get register |
610 | in eax, dx |
- | 611 | push eax |
|
- | 612 | ||
619 | push eax |
613 | ;----------------------------------------------- |
620 | ;****disable packet filtering before setting filter******* |
- | |
- | 614 | ; disable packet filtering before setting filter |
|
621 | mov eax, SIS900_RFEN ;move receive filter enable flag |
615 | |
622 | not eax ;1s complement |
616 | and eax, not RFEN |
- | 617 | out dx, eax |
|
623 | and eax, [esp] ;disable receiver |
618 | |
624 | out dx, eax ;set receive disabled |
619 | ;-------------------------------------- |
- | 620 | ; load MAC addr to filter data register |
|
625 | ;********load MAC addr to filter data register********* |
621 | |
626 | xor ecx, ecx |
- | |
627 | SIS900_RXINT_Mac_Write: |
622 | xor ecx, ecx |
628 | ;high word of eax tells card which mac byte to write |
623 | RXINT_Mac_Write: ; 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 |
636 | inc cl ; send next word |
632 | inc cl ; send next word |
637 | cmp cl, 3 ; more to send? |
633 | cmp cl, 3 ; more to send? |
638 | jne SIS900_RXINT_Mac_Write |
634 | jne RXINT_Mac_Write |
- | 635 | ||
- | 636 | ;------------------------ |
|
639 | ;********enable packet filitering ***** |
637 | ; enable packet filtering |
- | 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 |
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 | ;* |
647 | ; |
649 | ;* Function: sis_init_txd |
648 | ; init_txd |
650 | ;* |
649 | ; |
651 | ;* Description: initializes the Tx descriptor |
650 | ; initializes the Tx descriptor |
652 | ;* |
- | |
653 | ;* Arguments: |
- | |
654 | ;* |
651 | ; |
655 | ;* returns: |
- | |
656 | ;*done |
- | |
657 | ;*************************************************************************** |
652 | ;*************************************************************************** |
- | 653 | align 4 |
|
658 | SIS900_init_txd: |
654 | init_txd: |
- | 655 | ||
- | 656 | ;------------------------- |
|
659 | ;********** initialize TX descriptor ************** |
657 | ; initialize TX descriptor |
- | 658 | ||
660 | mov [ebx+device.txd], dword 0 ;put link to next descriptor in link field |
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 |
662 | lea eax, [ebx+0x1000] |
- | |
663 | call GetPgAddr |
- | |
664 | mov [ebx+device.txd+8], eax ;save address to buffer ptr field |
661 | mov dword [device.txd+8], 0 ; ptr to buffer |
- | 662 | ||
- | 663 | ;---------------------------------- |
|
665 | ;*************** load Transmit Descriptor Register *************** |
664 | ; load Transmit Descriptor Register |
- | 665 | ||
666 | mov edx, [ebx+device.io_addr] ; base address |
666 | set_io 0 |
667 | add edx, SIS900_txdp ; TX Descriptor Pointer |
667 | set_io txdp ; TX Descriptor Pointer |
668 | add eax, device.txd - 0x1000 ; First Descriptor |
668 | lea eax, [device.txd] |
- | 669 | GetRealAddr |
|
669 | out dx, eax ; move the pointer |
670 | out dx, eax ; move the pointer |
- | 671 | ||
670 | ret |
672 | ret |
671 | 673 | ||
672 | ;*************************************************************************** |
674 | ;*************************************************************************** |
- | 675 | ; |
|
673 | ;* Function: sis_init_rxd |
676 | ; init_rxd |
674 | ;* |
677 | ; |
675 | ;* Description: initializes the Rx descriptor ring |
678 | ; initializes the Rx descriptor ring |
676 | ;* |
- | |
677 | ;* Arguments: |
- | |
678 | ;* |
679 | ; |
679 | ;* Returns: |
- | |
680 | ;*done |
- | |
681 | ;*************************************************************************** |
680 | ;*************************************************************************** |
- | 681 | align 4 |
|
682 | SIS900_init_rxd: |
682 | init_rxd: |
- | 683 | ||
683 | xor ecx,ecx |
684 | ; init RX descriptors |
684 | mov [cur_rx], cl ;Set cuurent rx discriptor to 0 |
- | |
685 | mov eax, ebx |
685 | mov ecx, NUM_RX_DESC |
686 | call GetPgAddr |
686 | lea esi, [device.rxd] |
- | 687 | ||
687 | mov esi, eax |
688 | .loop: |
688 | ;******** init RX descriptors ******** |
689 | lea eax, [esi + 16] |
689 | SIS900_init_rxd_Loop: |
690 | GetRealAddr |
690 | mov edx, ecx ;current descriptor |
691 | mov dword [esi+0], eax |
691 | imul edx, 12 ; |
692 | mov dword [esi+4], RX_BUFF_SZ |
- | 693 | ||
692 | mov eax, ecx ;determine next link descriptor |
694 | stdcall KernelAlloc, RX_BUFF_SZ |
693 | inc eax ; |
695 | test eax, eax |
- | 696 | jz .fail |
|
694 | cmp eax, NUM_RX_DESC ; |
697 | mov dword [esi+12], eax |
695 | jne SIS900_init_rxd_Loop_0 ; |
698 | GetRealAddr |
696 | xor eax, eax ; |
699 | mov dword [esi+8], eax |
697 | SIS900_init_rxd_Loop_0: ; |
700 | add esi, 16 |
698 | imul eax, 12 ; |
701 | loop .loop |
- | 702 | ||
699 | lea eax, [eax+esi+device.rxd] |
703 | lea eax, [device.rxd] |
700 | mov [ebx+device.rxd+edx], eax ;save link to next descriptor |
- | |
701 | mov [ebx+device.rxd+edx+4],dword RX_BUFF_SZ ;status bits init to buf size |
- | |
702 | mov eax, ecx ;find where the buf is located |
- | |
703 | imul eax,RX_BUFF_SZ ; |
704 | GetRealAddr |
704 | lea eax, [eax+esi+0x1000+NUM_TX_DESC*TX_BUFF_SZ] |
- | |
705 | mov [ebx+device.rxd+edx+8], eax ;save buffer pointer |
705 | mov dword [esi - 16], eax ; correct last descriptor link ptr |
- | 706 | ||
706 | inc ecx ;next descriptor |
707 | ; And output ptr to first desc, to device |
707 | cmp ecx, NUM_RX_DESC ; |
- | |
708 | jne SIS900_init_rxd_Loop ; |
- | |
709 | ;********* load Receive Descriptor Register with address of first |
- | |
- | 708 | ||
710 | ; descriptor********* |
709 | set_io 0 |
711 | mov edx, [ebx+device.io_addr] |
- | |
712 | add edx, SIS900_rxdp |
710 | set_io rxdp |
713 | lea eax, [esi+device.rxd] |
- | |
714 | out dx, eax |
711 | out dx, eax |
- | 712 | ||
- | 713 | mov [device.cur_rx], 0 ; Set curent rx discriptor to 0 |
|
- | 714 | ||
- | 715 | .fail: ;;; TODO: abort instead! |
|
715 | ret |
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 |
|
- | 731 | ; 0x00300000 = 16 bytes |
|
- | 732 | ; 0x00400000 = 32 bytes |
|
- | 733 | ; 0x00500000 = 64 bytes |
|
- | 734 | ; 0x00600000 = 128 bytes |
|
- | 735 | ; 0x00700000 = 256 bytes |
|
716 | 736 | ; |
|
717 | ;*************************************************************************** |
- | |
718 | ;* Function: sis900_set_tx_mode |
- | |
719 | ;* |
- | |
720 | ;* Description: |
- | |
721 | ;* sets the transmit mode to allow for full duplex |
- | |
722 | ;* |
737 | ;*************************************************************************** |
723 | ;* |
738 | align 4 |
724 | ;* Arguments: |
739 | set_tx_mode: |
725 | ;* |
740 | |
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 |
- | |
735 | ;* 0x00400000 = 32 bytes |
- | |
736 | ;* 0x00500000 = 64 bytes |
- | |
737 | ;* 0x00600000 = 128 bytes |
- | |
738 | ;* 0x00700000 = 256 bytes |
- | |
739 | ;*************************************************************************** |
741 | set_io 0 |
740 | SIS900_set_tx_mode: |
- | |
741 | push ebp |
- | |
742 | mov ebp,[ebx+device.io_addr] |
- | |
743 | lea edx,[ebp+SIS900_cr] |
742 | set_io cr |
744 | in eax, dx ; Get current Command Register |
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 |
|
- | 749 | ; allow automatic padding |
|
- | 750 | ; allow heartbeat ignore |
|
- | 751 | ; allow carrier sense ignore |
|
- | 752 | ; Max DMA Burst (128 bytes) |
|
- | 753 | ; TX Fill Threshold |
|
745 | or eax, SIS900_TxENA ;Enable Receive |
754 | ; TX Drain Threshold |
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 | or eax, SIS900_CSI ;allow carrier sense ignore |
- | |
751 | or eax, 0x00600000 ;Max DMA Burst |
- | |
752 | or eax, 0x00000100 ;TX Fill Threshold |
- | |
753 | or eax, 0x00000020 ;TX Drain Threshold |
- | |
754 | out dx, eax |
755 | out dx, eax |
755 | pop ebp |
756 | |
756 | ret |
757 | ret |
757 | 758 | ||
758 | ;*************************************************************************** |
759 | ;*************************************************************************** |
759 | ;* Function: sis900_set_rx_mode |
- | |
760 | ;* |
760 | ; |
761 | ;* Description: |
761 | ; set_rx_mode |
- | 762 | ; |
|
762 | ;* sets the receive mode to accept all broadcast packets and packets |
763 | ; sets the receive mode to accept all broadcast packets and packets |
763 | ;* with our MAC address, and reject all multicast packets. Also allows |
764 | ; with our MAC address, and reject all multicast packets. Also allows |
764 | ;* full-duplex |
765 | ; full-duplex |
765 | ;* |
- | |
766 | ;* Arguments: |
- | |
767 | ;* |
- | |
768 | ;* Returns: |
- | |
769 | ;* |
766 | ; |
770 | ;* Comments: |
- | |
771 | ;* If you are having problems receiving packet try changing the |
767 | ; If you are having problems receiving packet try changing the |
772 | ;* Max DMA Burst, Possible settings are as follows: |
768 | ; Max DMA Burst, Possible settings are as follows: |
- | 769 | ; |
|
773 | ;* 0x00000000 = 512 bytes |
770 | ; 0x00000000 = 512 bytes |
774 | ;* 0x00100000 = 4 bytes |
771 | ; 0x00100000 = 4 bytes |
775 | ;* 0x00200000 = 8 bytes |
772 | ; 0x00200000 = 8 bytes |
776 | ;* 0x00300000 = 16 bytes |
773 | ; 0x00300000 = 16 bytes |
777 | ;* 0x00400000 = 32 bytes |
774 | ; 0x00400000 = 32 bytes |
778 | ;* 0x00500000 = 64 bytes |
775 | ; 0x00500000 = 64 bytes |
779 | ;* 0x00600000 = 128 bytes |
776 | ; 0x00600000 = 128 bytes |
780 | ;* 0x00700000 = 256 bytes |
777 | ; 0x00700000 = 256 bytes |
- | 778 | ; |
|
781 | ;*************************************************************************** |
779 | ;*************************************************************************** |
- | 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 |
- | 785 | ||
786 | xor cl, cl |
786 | xor cl, cl |
787 | SIS900_set_rx_mode_Loop: |
- | |
788 | mov eax, ecx |
787 | .loop: |
789 | shl eax, 1 |
788 | set_io 0 |
790 | lea edx,[ebp+SIS900_rfcr] ; Receive Filter Control Reg offset |
789 | set_io rfcr ; Receive Filter Control Reg offset |
791 | mov eax, 4 ;determine table entry |
790 | mov eax, 4 ; determine table entry |
792 | add al, cl |
791 | add al, cl |
793 | shl eax, 16 |
792 | shl eax, 16 |
794 | out dx, eax ;tell card which entry to modify |
793 | out dx, eax ; tell card which entry to modify |
- | 794 | ||
795 | lea edx,[ebp+SIS900_rfdr] ; Receive Filter Control Reg offset |
795 | set_io rfdr ; Receive Filter Control Reg offset |
796 | mov eax, 0xffff ;entry value |
796 | mov eax, 0xffff ; entry value |
797 | out dx, ax ;write value to table in card |
797 | out dx, ax ; write value to table in card |
- | 798 | ||
798 | inc cl ;next entry |
799 | inc cl ; next entry |
799 | cmp cl,[sis900_table_entries] ; |
800 | cmp cl, [table_entries] |
- | 801 | jl .loop |
|
- | 802 | ||
800 | jl SIS900_set_rx_mode_Loop |
803 | ;------------------------------------ |
801 | ;*******Set Receive Filter Control Register************* |
804 | ; Set Receive Filter Control Register |
- | 805 | ||
802 | lea edx,[ebp+SIS900_rfcr] ; Receive Filter Control Register offset |
806 | set_io rfcr ; Receive Filter Control Register offset |
- | 807 | mov eax, RFAAB + RFAAM + RFAAP + RFEN |
|
803 | mov eax, SIS900_RFAAB ;accecpt all broadcast packets |
808 | ; accecpt all broadcast packets |
804 | or eax, SIS900_RFAAM ;accept all multicast packets |
809 | ; accept all multicast packets |
805 | or eax, SIS900_RFAAP ;Accept all packets |
810 | ; Accept all packets |
806 | or eax, SIS900_RFEN ;enable receiver filter |
811 | ; enable receiver filter |
807 | out dx, eax |
812 | out dx, eax |
- | 813 | ;---------------- |
|
808 | ;******Enable Receiver************ |
814 | ; Enable Receiver |
- | 815 | ||
809 | lea edx,[ebp+SIS900_cr] ; Command Register offset |
816 | set_io cr |
810 | in eax, dx ; Get current Command Register |
817 | in eax, dx ; Get current Command Register |
811 | or eax, SIS900_RxENA ;Enable Receive |
818 | or eax, RxENA ; Enable Receive |
812 | out dx, eax |
819 | out dx, eax |
- | 820 | ||
- | 821 | ;------------------- |
|
813 | ;*********Set |
822 | ; Configure Receiver |
- | 823 | ||
814 | lea edx,[ebp+SIS900_rxcfg] ; Receive Config Register offset |
824 | set_io rxcfg ; Receive Config Register offset |
- | 825 | mov eax, ATX + 0x00600002 |
|
815 | mov eax, SIS900_ATX ;Accept Transmit Packets |
826 | ; Accept Transmit Packets |
816 | ; (Req for full-duplex and PMD Loopback) |
827 | ; (Req for full-duplex and PMD Loopback) |
817 | or eax, 0x00600000 ;Max DMA Burst |
828 | ; Max DMA Burst |
818 | or eax, 0x00000002 ;RX Drain Threshold, 8X8 bytes or 64bytes |
829 | ; RX Drain Threshold, 8X8 bytes or 64bytes |
819 | out dx, eax ; |
830 | out dx, eax |
820 | pop ebp |
831 | |
821 | ret |
832 | ret |
822 | 833 | ||
823 | ;*************************************************************************** |
834 | ;*************************************************************************** |
- | 835 | ; |
|
824 | ; * SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model |
836 | ; SIS960_get_mac_addr: - Get MAC address for SiS962 or SiS963 model |
825 | ; * @pci_dev: the sis900 pci device |
- | |
826 | ; * @net_dev: the net device to get address for |
- | |
827 | ; * |
837 | ; |
828 | ; * SiS962 or SiS963 model, use EEPROM to store MAC address. And EEPROM |
838 | ; SiS962 or SiS963 model, use EEPROM to store MAC address. |
829 | ; * is shared by |
839 | ; EEPROM is shared by LAN and 1394. |
830 | ; * LAN and 1394. When access EEPROM, send EEREQ signal to hardware first |
840 | ; When access EEPROM, send EEREQ signal to hardware first, and wait for EEGNT. |
831 | ; * and wait for EEGNT. If EEGNT is ON, EEPROM is permitted to be access |
841 | ; If EEGNT is ON, EEPROM is permitted to be accessed by LAN, otherwise is not. |
832 | ; * by LAN, otherwise is not. After MAC address is read from EEPROM, send |
842 | ; After MAC address is read from EEPROM, send |
833 | ; * EEDONE signal to refuse EEPROM access by LAN. |
843 | ; EEDONE signal to refuse EEPROM access by LAN. |
834 | ; * The EEPROM map of SiS962 or SiS963 is different to SiS900. |
844 | ; The EEPROM map of SiS962 or SiS963 is different to SiS900. |
835 | ; * The signature field in SiS962 or SiS963 spec is meaningless. |
845 | ; The signature field in SiS962 or SiS963 spec is meaningless. |
836 | ; * MAC address is read into @net_dev->dev_addr. |
- | |
837 | ; *done |
- | |
838 | ;* |
846 | ; |
839 | ;* Return 0 is EAX = failure |
847 | ; Return 0 is EAX = failure |
840 | ;*Done+ |
848 | ; |
841 | ;*************************************************************************** |
849 | ;*************************************************************************** |
842 | if defined SIS900_DEBUG |
- | |
843 | SIS900_Debug_Str_GetMac_Start db 'Attempting to get SIS900 Mac ID: ',13,10,0 |
- | |
844 | SIS900_Debug_Str_GetMac_Failed db 'Access to EEprom Failed',13,10,0 |
- | |
845 | SIS900_Debug_Str_GetMac_Address db 'Your Mac ID is: ',0 |
- | |
846 | SIS900_Debug_Str_GetMac_Address2 db 'Your SIS96x Mac ID is: ',0 |
- | |
847 | end if |
850 | align 4 |
848 | SIS960_get_mac_addr: |
851 | SIS960_get_mac_addr: |
849 | push ebp |
852 | |
850 | mov ebp,[ebx+device.io_addr] |
853 | ;------------------------------- |
851 | ;**********Send Request for eeprom access********************* |
854 | ; Send Request for eeprom access |
- | 855 | ||
- | 856 | set_io 0 |
|
852 | lea edx,[ebp+SIS900_mear] ; Eeprom access register |
857 | set_io mear ; Eeprom access register |
853 | mov eax, SIS900_EEREQ ; Request access to eeprom |
858 | mov eax, EEREQ ; Request access to eeprom |
854 | out dx, eax ; Send request |
859 | out dx, eax ; Send request |
- | 860 | ||
855 | xor ecx,ecx ; |
861 | ;----------------------------------------------------- |
856 | ;******Loop 4000 times and if access not granted error out***** |
862 | ; Loop 4000 times and if access not granted, error out |
- | 863 | ||
857 | SIS96X_Get_Mac_Wait: |
864 | mov ecx, 4000 |
- | 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 |
860 | jnz SIS900_Got_EEP_Access ;if it is, go access the eeprom |
868 | jnz .got_access ; if it is, go access the eeprom |
861 | inc ecx ;else keep waiting |
869 | loop .loop ; else keep waiting |
- | 870 | ||
862 | cmp ecx, 4000 ;have we tried 4000 times yet? |
871 | DEBUGF 1, "Access to EEprom failed!\n", 0 |
- | 872 | ||
863 | jl SIS96X_Get_Mac_Wait ;if not ask again |
873 | set_io mear ; Eeprom access register |
864 | xor eax, eax ;return zero in eax indicating failure |
874 | mov eax, EEDONE ; tell eeprom we are done |
865 | ;*******Debug ********************** |
875 | out dx, eax |
- | 876 | ||
866 | if defined SIS900_DEBUG |
877 | or eax, -1 ; error |
867 | mov esi,SIS900_Debug_Str_GetMac_Failed |
878 | ret |
- | 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 |
872 | SIS900_Got_EEP_Access: |
- | |
- | 884 | ||
873 | ; zero based so 3-16 bit reads will take place |
885 | ; 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 |
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 |
897 | 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 |
- | |
- | 900 | ||
887 | mov esi,SIS900_Debug_Str_GetMac_Address2 |
901 | ;------------------------------------- |
888 | call sys_msg_board_str |
- | |
889 | lea edx, [ebx+device.mac] |
- | |
890 | call Create_Mac_String |
902 | ; Tell EEPROM We are Done Accessing It |
- | 903 | ||
891 | end if |
904 | .done: |
892 | ;**********Tell EEPROM We are Done Accessing It********************* |
- | |
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 |
907 | mov eax, EEDONE ; tell eeprom we are done |
896 | out dx,eax |
908 | out dx, eax |
- | 909 | ||
897 | pop ebp |
910 | xor eax, eax ; ok |
898 | ret |
911 | ret |
- | 912 | ||
- | 913 | ||
- | 914 | ||
- | 915 | ||
899 | ;*************************************************************************** |
916 | ;*************************************************************************** |
- | 917 | ; |
|
900 | ;* sis900_get_mac_addr: - Get MAC address for stand alone SiS900 model |
918 | ; get_mac_addr: - Get MAC address for stand alone SiS900 model |
901 | ;* @pci_dev: the sis900 pci device |
- | |
902 | ;* @net_dev: the net device to get address for |
- | |
903 | ;* |
919 | ; |
904 | ;* Older SiS900 and friends, use EEPROM to store MAC address. |
920 | ; 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 |
921 | ; |
907 | ;*************************************************************************** |
922 | ;*************************************************************************** |
- | 923 | align 4 |
|
908 | SIS900_get_mac_addr: |
924 | get_mac_addr: |
- | 925 | ||
909 | ;*******Debug ********************** |
926 | ;------------------------------------ |
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 ******* |
927 | ; check to see if we have sane EEPROM |
- | 928 | ||
915 | mov eax, SIS900_EEPROMSignature ;Base Eeprom Signature |
929 | mov eax, EEPROMSignature ; Base Eeprom Signature |
916 | call sis900_read_eeprom ;try to read 16 bits |
930 | call read_eeprom ; try to read 16 bits |
917 | cmp ax, 0xffff |
931 | cmp ax, 0xffff |
918 | je SIS900_Bad_Eeprom |
932 | je .err |
919 | cmp ax, 0 |
933 | test ax, ax |
920 | je SIS900_Bad_Eeprom |
934 | je .err |
- | 935 | ||
- | 936 | ;----------- |
|
921 | ;**************Read MacID************** |
937 | ; Read MacID |
- | 938 | ||
922 | ; zero based so 3-16 bit reads will take place |
939 | ; 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 |
943 | mov eax, EEPROMMACAddr ;Base Mac Address |
926 | add eax, ecx ;Current Mac Byte Offset |
944 | add eax, ecx ;Current Mac Byte Offset |
927 | push ecx |
945 | push ecx |
928 | call sis900_read_eeprom ;try to read 16 bits |
946 | call read_eeprom ;try to read 16 bits |
929 | pop ecx |
947 | pop ecx |
930 | mov word [ebx+device.mac+ecx*2], ax ;save 16 bits to the MAC ID storage |
948 | mov word [device.mac+ecx*2], ax ;save 16 bits to the MAC ID storage |
931 | dec ecx ;one less word to read |
949 | dec ecx ;one less word to read |
932 | jns SIS900_mac_read_loop ;if more read more |
950 | jns 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 |
- | |
940 | end if |
- | |
941 | ret |
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 |
|
942 | - | ||
943 | SIS900_Bad_Eeprom: |
953 | |
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 |
- | |
949 | end if |
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 | ||
950 | ret |
964 | |
- | 965 | ;*************************************************************************** |
|
951 | ;*************************************************************************** |
966 | ; |
952 | ;* Get_Mac_SIS635_900_REV: - Get MAC address for model 635 |
- | |
953 | ;* |
967 | ; Get_Mac_SIS635_900_REV: - Get MAC address for model 635 |
954 | ;* |
968 | ; |
- | 969 | ;*************************************************************************** |
|
955 | ;*************************************************************************** |
970 | align 4 |
956 | Get_Mac_SIS635_900_REV: |
- | |
957 | if defined SIS900_DEBUG |
- | |
958 | mov esi,SIS900_Debug_Str_GetMac_Start |
- | |
959 | call sys_msg_board_str |
971 | Get_Mac_SIS635_900_REV: |
960 | end if |
972 | |
961 | push ebp |
- | |
962 | mov ebp,[ebx+device.io_addr] |
973 | set_io 0 |
963 | lea edx,[ebp+SIS900_rfcr] |
974 | set_io rfcr |
964 | in eax,dx |
975 | 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 |
967 | or eax,SIS900_RELOAD |
979 | or eax, RELOAD |
- | 980 | out dx, eax |
|
968 | out dx,eax |
981 | |
969 | xor eax,eax |
982 | xor eax, eax |
- | 983 | out dx, eax |
|
- | 984 | ||
970 | out dx,eax |
985 | ;----------------------------------------------- |
- | 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 |
974 | and edi,not SIS900_RFEN |
990 | and edi, not RFEN |
- | 991 | out dx, eax |
|
- | 992 | ||
975 | out dx,eax |
993 | ;--------------------------------- |
- | 994 | ; Load MAC to filter data register |
|
976 | ; Load MAC to filter data register |
995 | |
977 | xor ecx,ecx |
996 | mov ecx, 3 |
978 | lea esi,[ebx+device.mac] |
997 | lea edi, [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 |
- | |
986 | mov [esi],ax |
1006 | in eax, dx |
987 | add esi,2 |
1007 | stosw |
988 | inc ecx |
- | |
- | 1008 | loop .loop |
|
989 | cmp ecx,3 |
1009 | |
990 | jne .get_mac_loop |
1010 | ;------------------------ |
- | 1011 | ; Enable packet filtering |
|
991 | ; Enable packet filtering |
1012 | |
992 | ;lea edx,[ebp+SIS900_rfcr] |
1013 | ; set_io rfcr |
993 | ;mov eax,edi |
1014 | ; mov eax, edi |
994 | ;or eax,SIS900_RFEN |
1015 | ; or eax, 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 |
- | |
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 |
1016 | ; out dx, eax |
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 |
- | |
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. ************** |
1017 | |
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 |
- | |
1089 | pop esi |
1018 | xor eax, eax |
- | 1019 | ret |
|
1090 | ret |
1020 | |
1091 | ;*************************************************************************** |
- | |
1092 | ; Function |
- | |
1093 | ; SIS900_Eeprom_Delay_1 |
- | |
1094 | ; Description |
1021 | ;*************************************************************************** |
- | 1022 | ; |
|
1095 | ; |
1023 | ; read_eeprom |
- | 1024 | ; |
|
1096 | ; |
1025 | ; reads and returns a given location from EEPROM |
- | 1026 | ; |
|
- | 1027 | ; IN: si = addr |
|
1097 | ; |
1028 | ; OUT: ax = data |
1098 | ; |
1029 | ; |
- | 1030 | ;*************************************************************************** |
|
1099 | ;*************************************************************************** |
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 |
|
- | 1054 | jz @f |
|
1100 | SIS900_Eeprom_Delay_1: |
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 |
|
- | 1083 | ee_delay |
|
1101 | push eax |
1084 | |
- | 1085 | in eax, dx |
|
- | 1086 | shl esi, 1 |
|
- | 1087 | test eax, EEDO |
|
- | 1088 | jz @f |
|
1102 | in eax, dx |
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 | ||
- | 1104 | movzx eax, si |
|
1103 | pop eax |
1105 | |
- | 1106 | ret |
|
- | 1107 | ||
- | 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' |
1108 | add esp, 6 |
1113 | add esp, 6 |
1109 | ret |
1114 | ret |
1110 | 1115 | ||
1111 | ;*************************************************************************** |
1116 | ;*************************************************************************** |
1112 | ; Function |
1117 | ; |
1113 | ; int_handler |
1118 | ; int_handler |
1114 | ; Description |
1119 | ; |
1115 | ; handles received IRQs, which signal received packets |
1120 | ; handles received IRQs, which signal received packets |
1116 | ; |
1121 | ; |
1117 | ; Currently only supports one descriptor per packet, if packet is fragmented |
1122 | ; Currently only supports one descriptor per packet, if packet is fragmented |
1118 | ; between multiple descriptors you will lose part of the packet |
1123 | ; between multiple descriptors you will lose part of the packet |
- | 1124 | ; |
|
1119 | ;*************************************************************************** |
1125 | ;*************************************************************************** |
1120 | if defined SIS900_DEBUG |
- | |
1121 | SIS900_Debug_Pull_Packet_good db 'Good Packet Waiting: ',13,10,0 |
- | |
1122 | SIS900_Debug_Pull_Bad_Packet_Status db 'Bad Packet Waiting: Status',13,10,0 |
- | |
1123 | SIS900_Debug_Pull_Bad_Packet_Size db 'Bad Packet Waiting: Size',13,10,0 |
- | |
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 |
1138 | loop .nextdevice |
1140 | loop .nextdevice |
1139 | .nothing: |
1141 | .nothing: |
1140 | ret |
1142 | ret |
1141 | .got_it: |
1143 | .got_it: |
- | 1144 | ||
- | 1145 | test ax, RxOK |
|
- | 1146 | jz .no_rx |
|
- | 1147 | ||
- | 1148 | push ax |
|
- | 1149 | ||
- | 1150 | ;----------- |
|
1142 | ;**************Get Status ************** |
1151 | ; Get Status |
1143 | movzx eax, [ebx+device.cur_rx] ;find current discriptor |
1152 | movzx eax, [device.cur_rx] ; find current discriptor |
1144 | imul eax, 12 ; |
1153 | shl eax, 4 ; * 16 |
1145 | mov ecx, [ebx+device.rxd+eax+4] ; get receive status |
1154 | mov ecx, dword[device.rxd+eax+4] ; get receive status |
- | 1155 | ||
1146 | ;**************Check Status ************** |
1156 | ;------------------------------------------- |
1147 | ;Check RX_Status to see if packet is waiting |
1157 | ; Check RX_Status to see if packet is waiting |
1148 | test ecx, 0x80000000 |
1158 | test ecx, 0x80000000 |
1149 | jnz SIS900_poll_IS_packet |
1159 | jnz .is_packet |
1150 | ret |
1160 | ret |
- | 1161 | ||
- | 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 |
- | 1167 | ||
- | 1168 | ;--------------------- |
|
1155 | ;**************Check size of packet************* |
1169 | ; Check size of packet |
1156 | and ecx, SIS900_DSIZE ;get packet size minus CRC |
1170 | and ecx, DSIZE ; get packet size minus CRC |
1157 | cmp ecx, SIS900_CRC_SIZE |
- | |
1158 | ;make sure packet contains data |
1171 | sub ecx, CRC_SIZE ; make sure packet contains data |
1159 | jle SIS900_Poll_Error_Size |
1172 | jle .error_size |
1160 | ;*******Copy Good Packet to receive buffer****** |
- | |
1161 | sub ecx, SIS900_CRC_SIZE ;dont want crc |
- | |
- | 1173 | ||
1162 | ; update statistics |
1174 | ; update statistics |
1163 | inc dword [ebx+device.packets_rx] |
1175 | inc dword [device.packets_rx] |
1164 | add dword [ebx+device.bytes_rx], ecx |
1176 | add dword [device.bytes_rx], ecx |
1165 | adc dword [ebx+device.bytes_rx+4], 0 |
1177 | adc dword [device.bytes_rx+4], 0 |
1166 | push ecx |
- | |
1167 | stdcall KernelAlloc, ecx |
- | |
1168 | pop ecx |
1178 | |
1169 | test eax, eax |
- | |
1170 | jz int_handler.nothing |
- | |
1171 | push ebx |
1179 | 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] |
- | |
1177 | imul esi, RX_BUFF_SZ |
- | |
1178 | lea esi, [esi+ebx+0x1000+NUM_TX_DESC*TX_BUFF_SZ] |
- | |
1179 | ; first copy dword-wise, divide size by 4 |
- | |
1180 | shr ecx, 2 |
1180 | push .return |
1181 | rep movsd ; copy the dwords |
1181 | push ecx ; packet size |
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 |
1182 | push [device.rxd+eax+12] ; packet ptr |
1188 | call sys_msg_board_str |
1183 | DEBUGF 1, "Packet received OK\n" |
1189 | end if |
- | |
1190 | jmp EthReceiver |
1184 | jmp EthReceiver |
1191 | .return: |
1185 | .return: |
1192 | pop ebx |
1186 | 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 |
- | |
1198 | call sys_msg_board_str |
- | |
1199 | end if |
1187 | |
1200 | jmp SIS900_Poll_Cnt |
- | |
1201 | SIS900_Poll_Error_Size: |
- | |
1202 | if defined SIS900_DEBUG |
- | |
1203 | mov esi, SIS900_Debug_Pull_Bad_Packet_Size |
- | |
1204 | call sys_msg_board_str |
- | |
1205 | end if |
- | |
1206 | ;*************Increment to next available descriptor************** |
- | |
1207 | SIS900_Poll_Cnt: |
- | |
1208 | ;Reset status, allow ethernet card access to descriptor |
1188 | ; Reset status, allow ethernet card access to descriptor |
1209 | movzx eax, [ebx+device.cur_rx] |
1189 | movzx ecx, [device.cur_rx] |
1210 | lea eax, [eax*3] |
1190 | shl ecx, 4 ; *16 |
- | 1191 | mov ecx, [device.rxd+ecx] |
|
1211 | mov ecx, RX_BUFF_SZ |
1192 | stdcall KernelAlloc, RX_BUFF_SZ |
- | 1193 | test eax, eax |
|
- | 1194 | jz .fail |
|
- | 1195 | mov dword [ecx+12], eax |
|
- | 1196 | GetRealAddr |
|
1212 | mov [ebx+device.rxd+eax*4+4], ecx ; |
1197 | mov dword [ecx+8], eax |
- | 1198 | mov dword [ecx+4], RX_BUFF_SZ |
|
- | 1199 | ||
1213 | inc [ebx+device.cur_rx] ;get next descriptor |
1200 | inc [device.cur_rx] ; get next descriptor |
1214 | and [ebx+device.cur_rx],NUM_RX_DESC-1 ;only 4 descriptors 0-3 |
1201 | and [device.cur_rx], NUM_RX_DESC-1 ; only 4 descriptors 0-3 |
- | 1202 | ||
1215 | ;******Enable Receiver************ |
1203 | ; Enable Receiver |
1216 | mov edx, [ebx+device.io_addr] |
1204 | set_io 0 |
1217 | add edx, SIS900_cr ; Command Register offset |
1205 | set_io cr ; Command Register offset |
1218 | in eax, dx ; Get current Command Register |
1206 | in eax, dx ; Get current Command Register |
1219 | or eax, SIS900_RxENA ;Enable Receive |
1207 | or eax, RxENA ; Enable Receiver |
1220 | out dx, eax |
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" |
|
- | 1221 | jmp .continue |
|
- | 1222 | ||
- | 1223 | .no_rx: |
|
- | 1224 | test ax, TxOk |
|
- | 1225 | jz .no_tx |
|
- | 1226 | ||
- | 1227 | ;;; TODO: free all unused buffers |
|
- | 1228 | stdcall KernelFree, eax |
|
- | 1229 | ||
- | 1230 | .no_tx: |
|
- | 1231 | ||
1221 | ret |
1232 | ret |
- | 1233 | ||
- | 1234 | ||
- | 1235 | ||
1222 | ;*************************************************************************** |
1236 | ;*************************************************************************** |
1223 | ; Function |
1237 | ; Function |
1224 | ; transmit |
1238 | ; transmit |
1225 | ; Description |
1239 | ; Description |
1226 | ; Transmits a packet of data via the ethernet card |
1240 | ; Transmits a packet of data via the ethernet card |
1227 | ; buffer pointer in [esp+4] |
1241 | ; buffer pointer in [esp+4] |
1228 | ; size of buffer in [esp+8] |
1242 | ; size of buffer in [esp+8] |
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 |
- | |
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 | |
- | 1278 | ret |
|
1386 | ret |
1279 | |
1387 | 1280 | ||
1388 | ; End of code |
1281 | ; End of code |
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 |
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 |
1401 | dd SIS900_960_REV,SIS960_get_mac_addr,0 |
1294 | dd SIS900_960_REV,SIS960_get_mac_addr,0 |
1402 | dd SIS900B_900_REV,SIS900_get_mac_addr,0 |
1295 | dd SIS900B_900_REV,get_mac_addr,0 |
1403 | dd 0,0,0,0 ; end of list |
1296 | dd 0 ; end of list |
1404 | 1297 | ||
1405 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
1298 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
1406 | my_service db 'SIS900',0 ; max 16 chars include zero |
1299 | my_service db 'SIS900',0 ; max 16 chars include zero |
1407 | 1300 | ||
1408 | include_debug_strings ; All data wich FDO uses will be included here |
1301 | include_debug_strings ; All data wich FDO uses will be included here |
1409 | 1302 | ||
1410 | section '.data' data readable writable align 16 ; place all uninitialized data place here |
1303 | section '.data' data readable writable align 16; place all uninitialized data place here |
1411 | 1304 | ||
1412 | DEV_LIST rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling64bytes) |
1305 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling64bytes) |
1413 | > |
1306 | > |