Rev 4470 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4470 | Rev 4663 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2014. 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 | ;; Broadcom NetXtreme 57xx driver for KolibriOS ;; |
6 | ;; Broadcom NetXtreme 57xx driver for KolibriOS ;; |
7 | ;; ;; |
7 | ;; ;; |
8 | ;; ;; |
8 | ;; ;; |
9 | ;; GNU GENERAL PUBLIC LICENSE ;; |
9 | ;; GNU GENERAL PUBLIC LICENSE ;; |
10 | ;; Version 2, June 1991 ;; |
10 | ;; Version 2, June 1991 ;; |
11 | ;; ;; |
11 | ;; ;; |
12 | ;; Broadcom's programmers's manual for the BCM57xx ;; |
12 | ;; Broadcom's programmers's manual for the BCM57xx ;; |
13 | ;; http://www.broadcom.com/collateral/pg/57XX-PG105-R.pdf ;; |
13 | ;; http://www.broadcom.com/collateral/pg/57XX-PG105-R.pdf ;; |
14 | ;; ;; |
14 | ;; ;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
16 | 16 | ||
- | 17 | format PE DLL native |
|
17 | ; TODO: make better use of the available descriptors |
- | |
18 | - | ||
19 | format MS COFF |
18 | entry START |
20 | 19 | ||
- | 20 | CURRENT_API = 0x0200 |
|
21 | API_VERSION = 0x01000100 |
21 | COMPATIBLE_API = 0x0100 |
22 | DRIVER_VERSION = 5 |
22 | API_VERSION = (COMPATIBLE_API shl 16) + CURRENT_API |
23 | 23 | ||
24 | MAX_DEVICES = 16 |
24 | MAX_DEVICES = 16 |
25 | - | ||
26 | DEBUG = 1 |
25 | |
27 | __DEBUG__ = 1 |
26 | __DEBUG__ = 1 |
28 | __DEBUG_LEVEL__ = 2 |
27 | __DEBUG_LEVEL__ = 2 |
- | 28 | ||
- | 29 | section '.flat' readable writable executable |
|
- | 30 | ||
29 | 31 | include '../proc32.inc' |
|
30 | include '../struct.inc' |
32 | include '../struct.inc' |
31 | include '../macros.inc' |
- | |
32 | include '../proc32.inc' |
- | |
33 | include '../imports.inc' |
33 | include '../macros.inc' |
34 | include '../fdo.inc' |
34 | include '../fdo.inc' |
35 | include '../netdrv.inc' |
- | |
36 | - | ||
37 | public START |
- | |
38 | public service_proc |
- | |
- | 35 | include '../netdrv_pe.inc' |
|
- | 36 | ||
39 | public version |
37 | struct device ETH_DEVICE |
40 | 38 | ||
41 | 39 | mmio_addr dd ? |
|
42 | virtual at ebx |
- | |
43 | device: |
40 | pci_bus dd ? |
44 | ETH_DEVICE |
41 | pci_dev dd ? |
45 | - | ||
46 | .mmio_addr dd ? |
42 | irq_line db ? |
47 | .pci_bus dd ? |
43 | |
48 | .pci_dev dd ? |
44 | cur_tx dd ? |
49 | .irq_line db ? |
45 | last_tx dd ? |
50 | - | ||
51 | .cur_tx dd ? |
- | |
52 | .last_tx dd ? |
- | |
53 | - | ||
54 | rb 0x100 - (($ - device) and 0xff) |
- | |
55 | .rx_desc rd 256/8 |
46 | |
56 | - | ||
57 | rb 0x100 - (($ - device) and 0xff) |
- | |
58 | .tx_desc rd 256/8 |
47 | rb 0x100 - ($ and 0xff) ; align 256 |
59 | 48 | rx_desc rd 256/8 |
|
60 | sizeof.device_struct = $ - device |
49 | |
61 | 50 | rb 0x100 - ($ and 0xff) ; align 256 |
|
62 | end virtual |
51 | tx_desc rd 256/8 |
63 | 52 | ||
64 | section '.flat' code readable align 16 |
53 | ends |
65 | 54 | ||
66 | 55 | ||
67 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
56 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
68 | ;; ;; |
57 | ;; ;; |
69 | ;; proc START ;; |
58 | ;; proc START ;; |
70 | ;; ;; |
59 | ;; ;; |
71 | ;; (standard driver proc) ;; |
60 | ;; (standard driver proc) ;; |
72 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
61 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
73 | - | ||
74 | align 4 |
62 | |
75 | proc START stdcall, state:dword |
63 | proc START c, reason:dword, cmdline:dword |
76 | 64 | ||
77 | cmp [state], 1 |
- | |
78 | jne .exit |
- | |
79 | 65 | cmp [reason], DRV_ENTRY |
|
80 | .entry: |
66 | jne .fail |
81 | 67 | ||
82 | DEBUGF 2,"Loading driver\n" |
68 | DEBUGF 1,"Loading driver\n" |
83 | stdcall RegService, my_service, service_proc |
69 | invoke RegService, my_service, service_proc |
84 | ret |
70 | ret |
85 | 71 | ||
86 | .fail: |
72 | .fail: |
87 | .exit: |
- | |
88 | xor eax, eax |
73 | xor eax, eax |
89 | ret |
74 | ret |
90 | 75 | ||
91 | endp |
76 | endp |
92 | 77 | ||
93 | 78 | ||
94 | - | ||
95 | 79 | ||
96 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
80 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
97 | ;; ;; |
81 | ;; ;; |
98 | ;; proc SERVICE_PROC ;; |
82 | ;; proc SERVICE_PROC ;; |
99 | ;; ;; |
83 | ;; ;; |
100 | ;; (standard driver proc) ;; |
84 | ;; (standard driver proc) ;; |
101 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
85 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
102 | - | ||
103 | align 4 |
86 | |
104 | proc service_proc stdcall, ioctl:dword |
87 | proc service_proc stdcall, ioctl:dword |
105 | 88 | ||
106 | mov edx, [ioctl] |
89 | mov edx, [ioctl] |
107 | mov eax, [edx + IOCTL.io_code] |
90 | mov eax, [edx + IOCTL.io_code] |
108 | 91 | ||
109 | ;------------------------------------------------------ |
92 | ;------------------------------------------------------ |
110 | 93 | ||
111 | cmp eax, 0 ;SRV_GETVERSION |
94 | cmp eax, 0 ;SRV_GETVERSION |
112 | jne @F |
95 | jne @F |
113 | 96 | ||
114 | cmp [edx + IOCTL.out_size], 4 |
97 | cmp [edx + IOCTL.out_size], 4 |
115 | jb .fail |
98 | jb .fail |
116 | mov eax, [edx + IOCTL.output] |
99 | mov eax, [edx + IOCTL.output] |
117 | mov [eax], dword API_VERSION |
100 | mov [eax], dword API_VERSION |
118 | 101 | ||
119 | xor eax, eax |
102 | xor eax, eax |
120 | ret |
103 | ret |
121 | 104 | ||
122 | ;------------------------------------------------------ |
105 | ;------------------------------------------------------ |
123 | @@: |
106 | @@: |
124 | cmp eax, 1 ;SRV_HOOK |
107 | cmp eax, 1 ;SRV_HOOK |
125 | jne .fail |
108 | jne .fail |
126 | 109 | ||
127 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
110 | cmp [edx + IOCTL.inp_size], 3 ; Data input must be at least 3 bytes |
128 | jb .fail |
111 | jb .fail |
129 | 112 | ||
130 | mov eax, [edx + IOCTL.input] |
113 | mov eax, [edx + IOCTL.input] |
131 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
114 | cmp byte [eax], 1 ; 1 means device number and bus number (pci) are given |
132 | jne .fail ; other types arent supported for this card yet |
115 | jne .fail ; other types arent supported for this card yet |
133 | 116 | ||
134 | ; check if the device is already listed |
117 | ; check if the device is already listed |
135 | 118 | ||
136 | mov esi, device_list |
119 | mov esi, device_list |
137 | mov ecx, [devices] |
120 | mov ecx, [devices] |
138 | test ecx, ecx |
121 | test ecx, ecx |
139 | jz .firstdevice |
122 | jz .firstdevice |
140 | 123 | ||
141 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
124 | ; mov eax, [edx + IOCTL.input] ; get the pci bus and device numbers |
142 | mov ax, [eax+1] ; |
125 | mov ax, [eax+1] ; |
143 | .nextdevice: |
126 | .nextdevice: |
144 | mov ebx, [esi] |
127 | mov ebx, [esi] |
145 | cmp al, byte [device.pci_bus] |
128 | cmp al, byte [ebx + device.pci_bus] |
146 | jne .next |
129 | jne .next |
147 | cmp ah, byte [device.pci_dev] |
130 | cmp ah, byte [ebx + device.pci_dev] |
148 | je .find_devicenum ; Device is already loaded, let's find it's device number |
131 | je .find_devicenum ; Device is already loaded, let's find it's device number |
149 | .next: |
132 | .next: |
150 | add esi, 4 |
133 | add esi, 4 |
151 | loop .nextdevice |
134 | loop .nextdevice |
152 | 135 | ||
153 | 136 | ||
154 | ; This device doesnt have its own eth_device structure yet, lets create one |
137 | ; This device doesnt have its own eth_device structure yet, lets create one |
155 | .firstdevice: |
138 | .firstdevice: |
156 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
139 | cmp [devices], MAX_DEVICES ; First check if the driver can handle one more card |
157 | jae .fail |
140 | jae .fail |
158 | 141 | ||
159 | allocate_and_clear ebx, sizeof.device_struct, .fail ; Allocate the buffer for device structure |
142 | allocate_and_clear ebx, sizeof.device, .fail ; Allocate the buffer for device structure |
160 | 143 | ||
161 | ; Fill in the direct call addresses into the struct |
144 | ; Fill in the direct call addresses into the struct |
162 | 145 | ||
163 | mov [device.reset], reset |
146 | mov [ebx + device.reset], reset |
164 | mov [device.transmit], transmit |
147 | mov [ebx + device.transmit], transmit |
165 | mov [device.unload], unload |
148 | mov [ebx + device.unload], unload |
166 | mov [device.name], my_service |
149 | mov [ebx + device.name], my_service |
167 | 150 | ||
168 | ; save the pci bus and device numbers |
151 | ; save the pci bus and device numbers |
169 | 152 | ||
170 | mov eax, [edx + IOCTL.input] |
153 | mov eax, [edx + IOCTL.input] |
171 | movzx ecx, byte [eax+1] |
154 | movzx ecx, byte [eax+1] |
172 | mov [device.pci_bus], ecx |
155 | mov [ebx + device.pci_bus], ecx |
173 | movzx ecx, byte [eax+2] |
156 | movzx ecx, byte [eax+2] |
174 | mov [device.pci_dev], ecx |
157 | mov [ebx + device.pci_dev], ecx |
175 | 158 | ||
176 | ; Now, it's time to find the base mmio addres of the PCI device |
159 | ; Now, it's time to find the base mmio addres of the PCI device |
177 | 160 | ||
178 | PCI_find_mmio32 |
161 | stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev] |
179 | 162 | ||
180 | ; Create virtual mapping of the physical memory |
163 | ; Create virtual mapping of the physical memory |
181 | 164 | ||
182 | push 1Bh ; PG_SW+PG_NOCACHE |
165 | push 1Bh ; PG_SW+PG_NOCACHE |
183 | push 10000h ; size of the map |
166 | push 10000h ; size of the map |
184 | push eax |
167 | push eax |
185 | call MapIoMem |
168 | invoke MapIoMem |
186 | mov [device.mmio_addr], eax |
169 | mov [ebx + device.mmio_addr], eax |
187 | 170 | ||
188 | ; We've found the mmio address, find IRQ now |
171 | ; We've found the mmio address, find IRQ now |
- | 172 | ||
189 | 173 | invoke PciRead8, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.interrupt_line |
|
190 | PCI_find_irq |
174 | mov [ebx + device.irq_line], al |
191 | 175 | ||
192 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
176 | DEBUGF 1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\ |
193 | [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.mmio_addr]:8 |
177 | [ebx + device.pci_dev]:1,[ebx + device.pci_bus]:1,[ebx + device.irq_line]:1,[ebx + device.mmio_addr]:8 |
194 | 178 | ||
195 | ; Ok, the eth_device structure is ready, let's probe the device |
179 | ; Ok, the eth_device structure is ready, let's probe the device |
196 | call probe ; this function will output in eax |
180 | call probe ; this function will output in eax |
197 | test eax, eax |
181 | test eax, eax |
198 | jnz .err ; If an error occured, exit |
182 | jnz .err ; If an error occured, exit |
199 | 183 | ||
200 | mov eax, [devices] ; Add the device structure to our device list |
184 | mov eax, [devices] ; Add the device structure to our device list |
201 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
185 | mov [device_list+4*eax], ebx ; (IRQ handler uses this list to find device) |
202 | inc [devices] ; |
186 | inc [devices] ; |
203 | 187 | ||
204 | mov [device.type], NET_TYPE_ETH |
188 | mov [ebx + device.type], NET_TYPE_ETH |
205 | call NetRegDev |
189 | invoke NetRegDev |
206 | 190 | ||
207 | cmp eax, -1 |
191 | cmp eax, -1 |
208 | je .destroy |
192 | je .destroy |
209 | 193 | ||
210 | ret |
194 | ret |
211 | 195 | ||
212 | ; If the device was already loaded, find the device number and return it in eax |
196 | ; If the device was already loaded, find the device number and return it in eax |
213 | 197 | ||
214 | .find_devicenum: |
198 | .find_devicenum: |
215 | DEBUGF 1,"Trying to find device number of already registered device\n" |
199 | DEBUGF 1,"Trying to find device number of already registered device\n" |
216 | call NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
200 | invoke NetPtrToNum ; This kernel procedure converts a pointer to device struct in ebx |
217 | ; into a device number in edi |
201 | ; into a device number in edi |
218 | mov eax, edi ; Application wants it in eax instead |
202 | mov eax, edi ; Application wants it in eax instead |
219 | DEBUGF 1,"Kernel says: %u\n", eax |
203 | DEBUGF 1,"Kernel says: %u\n", eax |
220 | ret |
204 | ret |
221 | 205 | ||
222 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
206 | ; If an error occured, remove all allocated data and exit (returning -1 in eax) |
223 | 207 | ||
224 | .destroy: |
208 | .destroy: |
225 | ; todo: reset device into virgin state |
209 | ; todo: reset device into virgin state |
226 | 210 | ||
227 | .err: |
211 | .err: |
228 | stdcall KernelFree, ebx |
212 | invoke KernelFree, ebx |
229 | 213 | ||
230 | .fail: |
214 | .fail: |
231 | or eax, -1 |
215 | or eax, -1 |
232 | ret |
216 | ret |
233 | 217 | ||
234 | ;------------------------------------------------------ |
218 | ;------------------------------------------------------ |
235 | endp |
219 | endp |
236 | 220 | ||
237 | 221 | ||
238 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
222 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
239 | ;; ;; |
223 | ;; ;; |
240 | ;; Actual Hardware dependent code starts here ;; |
224 | ;; Actual Hardware dependent code starts here ;; |
241 | ;; ;; |
225 | ;; ;; |
242 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
226 | ;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;; |
243 | - | ||
244 | - | ||
245 | align 4 |
227 | |
246 | unload: |
228 | unload: |
247 | ; TODO: (in this particular order) |
229 | ; TODO: (in this particular order) |
248 | ; |
230 | ; |
249 | ; - Stop the device |
231 | ; - Stop the device |
250 | ; - Detach int handler |
232 | ; - Detach int handler |
251 | ; - Remove device from local list (device_list) |
233 | ; - Remove device from local list (device_list) |
252 | ; - call unregister function in kernel |
234 | ; - call unregister function in kernel |
253 | ; - Remove all allocated structures and buffers the card used |
235 | ; - Remove all allocated structures and buffers the card used |
254 | 236 | ||
255 | or eax, -1 |
237 | or eax, -1 |
256 | 238 | ||
257 | ret |
239 | ret |
258 | 240 | ||
259 | 241 | ||
260 | 242 | ||
261 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
243 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
262 | ;; |
244 | ;; |
263 | ;; probe: enables the device (if it really is I8254X) |
245 | ;; probe: enables the device (if it really is BCM57XX) |
264 | ;; |
246 | ;; |
265 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
247 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
266 | align 4 |
248 | |
267 | probe: |
249 | probe: |
268 | 250 | ||
269 | DEBUGF 1,"Probe\n" |
251 | DEBUGF 1,"Probe\n" |
270 | 252 | ||
- | 253 | ; Make the device a bus master |
|
- | 254 | invoke PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command |
|
- | 255 | or al, PCI_CMD_MASTER |
|
271 | PCI_make_bus_master |
- | |
- | 256 | invoke PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax |
|
272 | 257 | ||
273 | ; TODO: validate the device |
258 | |
274 | 259 | ; TODO: validate the device |
|
275 | 260 | ||
276 | 261 | ||
277 | 262 | ||
278 | - | ||
279 | align 4 |
263 | |
280 | reset: |
264 | reset: |
281 | 265 | ||
282 | DEBUGF 1,"Reset\n" |
266 | DEBUGF 1,"Reset\n" |
283 | 267 | ||
284 | movzx eax, [device.irq_line] |
268 | movzx eax, [ebx + device.irq_line] |
285 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
269 | DEBUGF 1,"Attaching int handler to irq %x\n", eax:1 |
286 | stdcall AttachIntHandler, eax, int_handler, dword 0 |
270 | invoke AttachIntHandler, eax, int_handler, ebx |
287 | test eax, eax |
271 | test eax, eax |
288 | jnz @f |
272 | jnz @f |
289 | DEBUGF 1,"\nCould not attach int handler!\n" |
273 | DEBUGF 1,"\nCould not attach int handler!\n" |
290 | ; or eax, -1 |
274 | ; or eax, -1 |
291 | ; ret |
275 | ; ret |
292 | @@: |
276 | @@: |
293 | 277 | ||
294 | call read_mac |
278 | call read_mac |
295 | 279 | ||
296 | ; Set the mtu, kernel will be able to send now |
280 | ; Set the mtu, kernel will be able to send now |
297 | mov [device.mtu], 1514 |
281 | mov [ebx + device.mtu], 1514 |
298 | 282 | ||
299 | ; Set link state to unknown |
283 | ; Set link state to unknown |
300 | mov [device.state], ETH_LINK_UNKOWN |
284 | mov [ebx + device.state], ETH_LINK_UNKNOWN |
301 | 285 | ||
302 | ret |
286 | ret |
303 | 287 | ||
304 | 288 | ||
305 | 289 | ||
306 | 290 | ||
307 | align 4 |
291 | align 4 |
308 | read_mac: |
292 | read_mac: |
309 | 293 | ||
310 | DEBUGF 1,"Read MAC\n" |
294 | DEBUGF 1,"Read MAC\n" |
311 | 295 | ||
312 | mov esi, [device.mmio_addr] |
296 | mov esi, [ebx + device.mmio_addr] |
313 | lea edi, [device.mac] |
297 | lea edi, [ebx + device.mac] |
314 | movsd |
298 | movsd |
315 | movsw |
299 | movsw |
316 | 300 | ||
317 | .mac_ok: |
301 | .mac_ok: |
318 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
302 | DEBUGF 1,"MAC = %x-%x-%x-%x-%x-%x\n",\ |
319 | [device.mac+0]:2,[device.mac+1]:2,[device.mac+2]:2,[device.mac+3]:2,[device.mac+4]:2,[device.mac+5]:2 |
303 | [ebx + device.mac+0]:2,[ebx + device.mac+1]:2,[ebx + device.mac+2]:2,[ebx + device.mac+3]:2,[ebx + device.mac+4]:2,[ebx + device.mac+5]:2 |
320 | 304 | ||
321 | ret |
305 | ret |
322 | 306 | ||
323 | 307 | ||
324 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
308 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
325 | ;; ;; |
309 | ;; ;; |
326 | ;; Transmit ;; |
310 | ;; Transmit ;; |
327 | ;; ;; |
311 | ;; ;; |
328 | ;; In: buffer pointer in [esp+4] ;; |
312 | ;; In: buffer pointer in [esp+4] ;; |
329 | ;; size of buffer in [esp+8] ;; |
313 | ;; size of buffer in [esp+8] ;; |
330 | ;; pointer to device structure in ebx ;; |
314 | ;; pointer to device structure in ebx ;; |
331 | ;; ;; |
315 | ;; ;; |
332 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
316 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
- | 317 | ||
- | 318 | proc transmit stdcall bufferptr, buffersize |
|
- | 319 | ||
333 | align 4 |
320 | pushf |
334 | transmit: |
321 | cli |
- | 322 | ||
335 | DEBUGF 2,"\nTransmitting packet, buffer:%x, size:%u\n", [esp+4], [esp+8] |
323 | DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [buffersize] |
336 | mov eax, [esp+4] |
324 | mov eax, [bufferptr] |
337 | DEBUGF 2,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
325 | DEBUGF 1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\ |
338 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
326 | [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\ |
339 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
327 | [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\ |
340 | [eax+13]:2,[eax+12]:2 |
328 | [eax+13]:2,[eax+12]:2 |
341 | 329 | ||
342 | cmp dword [esp + 8], 1514 |
330 | cmp [buffersize], 1514 |
343 | ja .fail |
331 | ja .fail |
344 | cmp dword [esp + 8], 60 |
332 | cmp [buffersize], 60 |
345 | jb .fail |
333 | jb .fail |
346 | 334 | ||
347 | 335 | ||
348 | 336 | ||
- | 337 | ||
349 | 338 | ||
350 | ; Update stats |
339 | ; Update stats |
351 | inc [device.packets_tx] |
340 | inc [ebx + device.packets_tx] |
352 | mov eax, [esp + 8] |
341 | mov eax, [buffersize] |
353 | add dword [device.bytes_tx], eax |
342 | add dword[ebx + device.bytes_tx], eax |
- | 343 | adc dword[ebx + device.bytes_tx + 4], 0 |
|
- | 344 | ||
354 | adc dword [device.bytes_tx + 4], 0 |
345 | DEBUGF 1,"Transmit OK\n" |
355 | 346 | popf |
|
356 | xor eax, eax |
347 | xor eax, eax |
357 | ret 8 |
348 | ret |
358 | 349 | ||
- | 350 | .fail: |
|
359 | .fail: |
351 | DEBUGF 2,"Transmit failed\n" |
360 | DEBUGF 1,"Send failed\n" |
352 | invoke KernelFree, [bufferptr] |
- | 353 | popf |
|
- | 354 | or eax, -1 |
|
361 | stdcall KernelFree, [esp+4] |
355 | ret |
362 | or eax, -1 |
356 | |
363 | ret 8 |
357 | endp |
364 | 358 | ||
365 | 359 | ||
366 | ;;;;;;;;;;;;;;;;;;;;;;; |
360 | ;;;;;;;;;;;;;;;;;;;;;;; |
367 | ;; ;; |
361 | ;; ;; |
368 | ;; Interrupt handler ;; |
362 | ;; Interrupt handler ;; |
369 | ;; ;; |
363 | ;; ;; |
370 | ;;;;;;;;;;;;;;;;;;;;;;; |
364 | ;;;;;;;;;;;;;;;;;;;;;;; |
371 | 365 | ||
372 | align 4 |
366 | align 4 |
373 | int_handler: |
367 | int_handler: |
374 | 368 | ||
375 | push ebx esi edi |
369 | push ebx esi edi |
376 | 370 | ||
377 | DEBUGF 1,"\n%s int\n", my_service |
371 | DEBUGF 1,"INT\n" |
378 | ;------------------------------------------- |
372 | ;------------------------------------------- |
379 | ; Find pointer of device wich made IRQ occur |
373 | ; Find pointer of device wich made IRQ occur |
380 | 374 | ||
381 | mov ecx, [devices] |
375 | mov ecx, [devices] |
382 | test ecx, ecx |
376 | test ecx, ecx |
383 | jz .nothing |
377 | jz .nothing |
384 | mov esi, device_list |
378 | mov esi, device_list |
385 | .nextdevice: |
379 | .nextdevice: |
386 | mov ebx, [esi] |
380 | mov ebx, [esi] |
387 | 381 | ||
388 | ; mov edi, [device.mmio_addr] |
382 | ; mov edi, [ebx + device.mmio_addr] |
389 | ; mov eax, [edi + REG_ICR] |
383 | ; mov eax, [edi + REG_ICR] |
390 | test eax, eax |
384 | test eax, eax |
391 | jnz .got_it |
385 | jnz .got_it |
392 | .continue: |
386 | .continue: |
393 | add esi, 4 |
387 | add esi, 4 |
394 | dec ecx |
388 | dec ecx |
395 | jnz .nextdevice |
389 | jnz .nextdevice |
396 | .nothing: |
390 | .nothing: |
397 | pop edi esi ebx |
391 | pop edi esi ebx |
398 | xor eax, eax |
392 | xor eax, eax |
399 | 393 | ||
400 | ret |
394 | ret |
401 | 395 | ||
402 | .got_it: |
396 | .got_it: |
403 | 397 | ||
404 | DEBUGF 1,"Device: %x Status: %x ", ebx, eax |
398 | DEBUGF 1,"Device: %x Status: %x ", ebx, eax |
405 | 399 | ||
406 | pop edi esi ebx |
400 | pop edi esi ebx |
407 | xor eax, eax |
401 | xor eax, eax |
408 | inc eax |
402 | inc eax |
409 | 403 | ||
410 | ret |
404 | ret |
411 | 405 | ||
412 | 406 | ||
413 | 407 | ||
414 | 408 | ||
415 | ; End of code |
409 | ; End of code |
416 | 410 | ||
417 | section '.data' data readable writable align 16 |
411 | data fixups |
- | 412 | end data |
|
- | 413 | ||
418 | align 4 |
- | |
419 | - | ||
420 | devices dd 0 |
414 | include '../peimport.inc' |
421 | version dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF) |
415 | |
422 | my_service db 'BCM57XX',0 ; max 16 chars include zero |
416 | my_service db 'BCM57XX',0 ; max 16 chars include zero |
423 | 417 | ||
424 | include_debug_strings ; All data wich FDO uses will be included here |
418 | include_debug_strings ; All data wich FDO uses will be included here |
- | 419 | ||
- | 420 | align 4 |
|
425 | 421 | devices dd 0 |
|
426 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |
422 | device_list rd MAX_DEVICES ; This list contains all pointers to device structures the driver is handling |