Subversion Repositories Kolibri OS

Rev

Rev 5363 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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