Subversion Repositories Kolibri OS

Rev

Rev 4470 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4470 Rev 4663
Line 12... Line 12...
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
-
 
17
format PE DLL native
Line 17... Line -...
17
        ; TODO: make better use of the available descriptors
-
 
18
 
-
 
19
format MS COFF
18
entry START
20
 
19
 
-
 
20
        CURRENT_API             = 0x0200
Line 21... Line 21...
21
        API_VERSION             = 0x01000100
21
        COMPATIBLE_API          = 0x0100
Line 22... Line -...
22
        DRIVER_VERSION          = 5
-
 
23
 
22
        API_VERSION             = (COMPATIBLE_API shl 16) + CURRENT_API
24
        MAX_DEVICES             = 16
23
 
Line -... Line 24...
-
 
24
        MAX_DEVICES             = 16
-
 
25
 
-
 
26
        __DEBUG__               = 1
25
 
27
        __DEBUG_LEVEL__         = 2
26
        DEBUG                   = 1
28
 
27
        __DEBUG__               = 1
-
 
28
        __DEBUG_LEVEL__         = 2
-
 
29
 
29
section '.flat' readable writable executable
30
include '../struct.inc'
30
 
31
include '../macros.inc'
-
 
32
include '../proc32.inc'
-
 
33
include '../imports.inc'
-
 
34
include '../fdo.inc'
-
 
Line -... Line 31...
-
 
31
include '../proc32.inc'
Line -... Line 32...
-
 
32
include '../struct.inc'
35
include '../netdrv.inc'
33
include '../macros.inc'
36
 
34
include '../fdo.inc'
37
public START
35
include '../netdrv_pe.inc'
Line 38... Line -...
38
public service_proc
-
 
39
public version
36
 
40
 
37
struct  device          ETH_DEVICE
41
 
-
 
Line 42... Line 38...
42
virtual at ebx
38
 
43
        device:
39
        mmio_addr       dd ?
Line 44... Line 40...
44
        ETH_DEVICE
40
        pci_bus         dd ?
45
 
41
        pci_dev         dd ?
Line 46... Line -...
46
        .mmio_addr      dd ?
-
 
47
        .pci_bus        dd ?
-
 
48
        .pci_dev        dd ?
-
 
49
        .irq_line       db ?
-
 
50
 
-
 
51
        .cur_tx         dd ?
42
        irq_line        db ?
52
        .last_tx        dd ?
-
 
53
 
-
 
Line 54... Line 43...
54
                        rb 0x100 - (($ - device) and 0xff)
43
 
55
        .rx_desc        rd 256/8
44
        cur_tx          dd ?
56
 
45
        last_tx         dd ?
57
                        rb 0x100 - (($ - device) and 0xff)
46
 
58
        .tx_desc        rd 256/8
47
        rb 0x100 - ($ and 0xff) ; align 256
59
 
48
        rx_desc         rd 256/8
Line 60... Line -...
60
        sizeof.device_struct = $ - device
-
 
61
 
49
 
Line 62... Line 50...
62
end virtual
50
        rb 0x100 - ($ and 0xff) ; align 256
63
 
51
        tx_desc         rd 256/8
64
section '.flat' code readable align 16
-
 
65
 
-
 
Line 66... Line 52...
66
 
52
 
67
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
53
ends
68
;;                        ;;
54
 
Line 69... Line 55...
69
;; proc START             ;;
55
 
70
;;                        ;;
-
 
71
;; (standard driver proc) ;;
56
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
72
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
57
;;                        ;;
Line 73... Line 58...
73
 
58
;; proc START             ;;
Line 74... Line -...
74
align 4
-
 
75
proc START stdcall, state:dword
59
;;                        ;;
76
 
60
;; (standard driver proc) ;;
77
        cmp [state], 1
61
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78
        jne .exit
62
 
79
 
63
proc START c, reason:dword, cmdline:dword
80
  .entry:
64
 
Line 81... Line -...
81
 
-
 
82
        DEBUGF  2,"Loading driver\n"
65
        cmp     [reason], DRV_ENTRY
Line 83... Line 66...
83
        stdcall RegService, my_service, service_proc
66
        jne     .fail
84
        ret
67
 
Line 140... Line 123...
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
Line 154... Line 137...
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
Line 158... Line 141...
158
 
141
 
Line 159... Line 142...
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
Line 160... Line 143...
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
Line 164... Line 147...
164
        mov     [device.transmit], transmit
147
        mov     [ebx + device.transmit], transmit
Line 165... Line 148...
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
 
Line 170... Line 153...
170
        mov     eax, [edx + IOCTL.input]
153
        mov     eax, [edx + IOCTL.input]
Line 171... Line 154...
171
        movzx   ecx, byte [eax+1]
154
        movzx   ecx, byte [eax+1]
Line 172... Line 155...
172
        mov     [device.pci_bus], ecx
155
        mov     [ebx + device.pci_bus], ecx
Line 173... Line 156...
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
 
Line 178... Line 161...
178
        PCI_find_mmio32
161
        stdcall PCI_find_mmio32, [ebx + device.pci_bus], [ebx + device.pci_dev]
Line -... Line 162...
-
 
162
 
179
 
163
; Create virtual mapping of the physical memory
Line 180... Line 164...
180
; Create virtual mapping of the physical memory
164
 
181
 
165
        push    1Bh             ; PG_SW+PG_NOCACHE
Line 182... Line 166...
182
        push    1Bh             ; PG_SW+PG_NOCACHE
166
        push    10000h          ; size of the map
183
        push    10000h          ; size of the map
167
        push    eax
184
        push    eax
168
        invoke  MapIoMem
185
        call    MapIoMem
169
        mov     [ebx + device.mmio_addr], eax
Line 186... Line 170...
186
        mov     [device.mmio_addr], eax
170
 
187
 
171
; We've found the mmio address, find IRQ now
188
; We've found the mmio address, find IRQ now
172
 
Line 189... Line 173...
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
Line 191... Line 175...
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",\
Line 193... Line 177...
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
Line 194... Line 178...
194
 
178
 
Line 195... Line 179...
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)
Line 223... Line 207...
223
 
207
 
224
  .destroy:
208
  .destroy:
Line 225... Line 209...
225
        ; todo: reset device into virgin state
209
        ; todo: reset device into virgin state
226
 
210
 
Line 227... Line 211...
227
  .err:
211
  .err:
228
        stdcall KernelFree, ebx
212
        invoke  KernelFree, ebx
229
 
213
 
Line 239... Line 223...
239
;;                                                                        ;;
223
;;                                                                        ;;
240
;;        Actual Hardware dependent code starts here                      ;;
224
;;        Actual Hardware dependent code starts here                      ;;
241
;;                                                                        ;;
225
;;                                                                        ;;
242
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
226
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
Line 243... Line -...
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
Line 258... Line 240...
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
;;
Line 265... Line 247...
265
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
247
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 266... Line 248...
266
align 4
248
 
-
 
249
probe:
-
 
250
 
-
 
251
        DEBUGF  1,"Probe\n"
Line 267... Line -...
267
probe:
-
 
Line -... Line 252...
-
 
252
 
Line 268... Line -...
268
 
-
 
269
        DEBUGF  1,"Probe\n"
253
; Make the device a bus master
Line 270... Line 254...
270
 
254
        invoke  PciRead32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command
Line 271... Line 255...
271
        PCI_make_bus_master
255
        or      al, PCI_CMD_MASTER
272
 
256
        invoke  PciWrite32, [ebx + device.pci_bus], [ebx + device.pci_dev], PCI_header00.command, eax
273
        ; TODO: validate the device
257
 
274
 
258
 
275
 
259
        ; TODO: validate the device
276
 
260
 
277
 
261
 
278
 
262
 
279
align 4
263
 
Line 280... Line 264...
280
reset:
264
reset:
Line 281... Line 265...
281
 
265
 
282
        DEBUGF  1,"Reset\n"
266
        DEBUGF  1,"Reset\n"
Line 283... Line 267...
283
 
267
 
284
        movzx   eax, [device.irq_line]
268
        movzx   eax, [ebx + device.irq_line]
Line 285... Line 269...
285
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
269
        DEBUGF  1,"Attaching int handler to irq %x\n", eax:1
Line 307... Line 291...
307
align 4
291
align 4
308
read_mac:
292
read_mac:
Line 309... Line 293...
309
 
293
 
Line 310... Line 294...
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]
Line 314... Line 298...
314
        movsd
298
        movsd
315
        movsw
299
        movsw
316
 
300
 
Line 317... Line 301...
317
  .mac_ok:
301
  .mac_ok:
Line 318... Line 302...
318
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n",\
302
        DEBUGF  1,"MAC = %x-%x-%x-%x-%x-%x\n",\
Line 328... Line 312...
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
Line 341... Line 329...
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
Line -... Line 333...
-
 
333
        jb      .fail
345
        jb      .fail
334
 
346
 
335
 
347
 
336
 
348
 
337
 
349
 
338
 
Line -... Line 339...
-
 
339
; Update stats
-
 
340
        inc     [ebx + device.packets_tx]
350
; Update stats
341
        mov     eax, [buffersize]
351
        inc     [device.packets_tx]
342
        add     dword[ebx + device.bytes_tx], eax
Line 352... Line 343...
352
        mov     eax, [esp + 8]
343
        adc     dword[ebx + device.bytes_tx + 4], 0
353
        add     dword [device.bytes_tx], eax
344
 
354
        adc     dword [device.bytes_tx + 4], 0
345
        DEBUGF  1,"Transmit OK\n"
-
 
346
        popf
355
 
347
        xor     eax, eax
356
        xor     eax, eax
348
        ret
-
 
349
 
-
 
350
  .fail:
Line 357... Line 351...
357
        ret     8
351
        DEBUGF  2,"Transmit failed\n"
358
 
352
        invoke  KernelFree, [bufferptr]
359
  .fail:
353
        popf
Line 372... Line 366...
372
align 4
366
align 4
373
int_handler:
367
int_handler:
Line 374... Line 368...
374
 
368
 
Line 375... Line 369...
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"
Line 378... Line 372...
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
Line 384... Line 378...
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]
Line 412... Line 406...
412
 
406
 
Line 413... Line 407...
413
 
407
 
414
 
408
 
-
 
409
; End of code
-
 
410
 
Line 415... Line -...
415
; End of code
-
 
416
 
-
 
417
section '.data' data readable writable align 16
411
data fixups
Line 418... Line 412...
418
align 4
412
end data
Line -... Line 413...
-
 
413
 
-
 
414
include '../peimport.inc'
419
 
415