Subversion Repositories Kolibri OS

Rev

Rev 4467 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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