Subversion Repositories Kolibri OS

Rev

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

Rev 1556 Rev 2387
Line 15... Line 15...
15
;;                                                                 ;;
15
;;                                                                 ;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 17... Line 17...
17
 
17
 
Line 18... Line 18...
18
format MS COFF
18
format MS COFF
19
 
19
 
Line 20... Line 20...
20
	API_VERSION		equ 0x01000100
20
        API_VERSION             equ 0x01000100
Line 21... Line 21...
21
	DRIVER_VERSION		equ 5
21
        DRIVER_VERSION          equ 5
Line 22... Line 22...
22
 
22
 
23
	MAX_DEVICES		equ 16
23
        MAX_DEVICES             equ 16
24
 
24
 
Line 25... Line 25...
25
	RBLEN			equ 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
25
        RBLEN                   equ 3 ; Receive buffer size: 0==8K 1==16k 2==32k 3==64k
26
 
26
 
27
	DEBUG			equ 1
27
        DEBUG                   equ 1
28
	__DEBUG__		equ 1
28
        __DEBUG__               equ 1
Line 29... Line 29...
29
	__DEBUG_LEVEL__ 	equ 2
29
        __DEBUG_LEVEL__         equ 2
30
 
30
 
31
include 'proc32.inc'
31
include 'proc32.inc'
Line 187... Line 187...
187
	TSR_OWN 		equ 1 SHL 13
187
        TSR_OWN                 equ 1 SHL 13
Line 188... Line 188...
188
	TSR_TUN 		equ 1 SHL 14
188
        TSR_TUN                 equ 1 SHL 14
Line 189... Line 189...
189
	TSR_TOK 		equ 1 SHL 15
189
        TSR_TOK                 equ 1 SHL 15
Line 190... Line 190...
190
 
190
 
191
	TSR_CDH 		equ 1 SHL 28
191
        TSR_CDH                 equ 1 SHL 28
Line 192... Line 192...
192
	TSR_OWC 		equ 1 SHL 29
192
        TSR_OWC                 equ 1 SHL 29
193
	TSR_TABT		equ 1 SHL 30
193
        TSR_TABT                equ 1 SHL 30
Line 194... Line 194...
194
	TSR_CRS 		equ 1 SHL 31
194
        TSR_CRS                 equ 1 SHL 31
195
 
195
 
196
 
196
 
197
virtual at ebx
197
virtual at ebx
198
 
198
 
Line 199... Line 199...
199
	device:
199
        device:
Line 200... Line 200...
200
 
200
 
Line 201... Line 201...
201
	ETH_DEVICE
201
        ETH_DEVICE
Line 230... Line 230...
230
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
230
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 231... Line 231...
231
 
231
 
232
align 4
232
align 4
Line 233... Line 233...
233
proc START stdcall, state:dword
233
proc START stdcall, state:dword
234
 
234
 
Line 235... Line 235...
235
	cmp [state], 1
235
        cmp [state], 1
Line 236... Line 236...
236
	jne .exit
236
        jne .exit
237
 
237
 
238
  .entry:
238
  .entry:
Line 239... Line 239...
239
 
239
 
240
	DEBUGF	2,"Loading rtl8139 driver\n"
240
        DEBUGF  2,"Loading rtl8139 driver\n"
241
	stdcall RegService, my_service, service_proc
241
        stdcall RegService, my_service, service_proc
242
	ret
242
        ret
Line 243... Line 243...
243
 
243
 
Line 244... Line 244...
244
  .fail:
244
  .fail:
Line 257... Line 257...
257
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
257
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 258... Line 258...
258
 
258
 
259
align 4
259
align 4
Line 260... Line 260...
260
proc service_proc stdcall, ioctl:dword
260
proc service_proc stdcall, ioctl:dword
261
 
261
 
Line 262... Line 262...
262
	mov	edx, [ioctl]
262
        mov     edx, [ioctl]
Line 263... Line 263...
263
	mov	eax, [IOCTL.io_code]
263
        mov     eax, [IOCTL.io_code]
264
 
264
 
Line 265... Line 265...
265
;------------------------------------------------------
265
;------------------------------------------------------
266
 
266
 
267
	cmp	eax, 0 ;SRV_GETVERSION
267
        cmp     eax, 0 ;SRV_GETVERSION
268
	jne	@F
268
        jne     @F
Line 269... Line 269...
269
 
269
 
270
	cmp	[IOCTL.out_size], 4
270
        cmp     [IOCTL.out_size], 4
Line 271... Line 271...
271
	jl	.fail
271
        jl      .fail
272
	mov	eax, [IOCTL.output]
272
        mov     eax, [IOCTL.output]
273
	mov	[eax], dword API_VERSION
273
        mov     [eax], dword API_VERSION
274
 
274
 
Line 275... Line 275...
275
	xor	eax, eax
275
        xor     eax, eax
276
	ret
276
        ret
Line 277... Line 277...
277
 
277
 
278
;------------------------------------------------------
278
;------------------------------------------------------
279
  @@:
279
  @@:
Line 280... Line 280...
280
	cmp	eax, 1 ;SRV_HOOK
280
        cmp     eax, 1 ;SRV_HOOK
Line 281... Line 281...
281
	jne	.fail
281
        jne     .fail
282
 
282
 
283
	cmp	[IOCTL.inp_size], 3		  ; Data input must be at least 3 bytes
283
        cmp     [IOCTL.inp_size], 3               ; Data input must be at least 3 bytes
284
	jl	.fail
284
        jl      .fail
Line 285... Line 285...
285
 
285
 
286
	mov	eax, [IOCTL.input]
286
        mov     eax, [IOCTL.input]
287
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
287
        cmp     byte [eax], 1                           ; 1 means device number and bus number (pci) are given
288
	jne	.fail					; other types arent supported for this card yet
288
        jne     .fail                                   ; other types arent supported for this card yet
289
 
289
 
290
; check if the device is already listed
290
; check if the device is already listed
291
 
291
 
292
	mov	esi, device_list
292
        mov     esi, device_list
Line 293... Line 293...
293
	mov	ecx, [devices]
293
        mov     ecx, [devices]
294
	test	ecx, ecx
294
        test    ecx, ecx
295
	jz	.firstdevice
295
        jz      .firstdevice
296
 
296
 
Line 297... Line 297...
297
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
297
;        mov     eax, [IOCTL.input]                      ; get the pci bus and device numbers
Line 298... Line 298...
298
	mov	ax , [eax+1]				;
298
        mov     ax , [eax+1]                            ;
Line 299... Line 299...
299
  .nextdevice:
299
  .nextdevice:
300
	mov	ebx, [esi]
300
        mov     ebx, [esi]
301
	cmp	ax , word [device.pci_bus]		; compare with pci and device num in device list (notice the usage of word instead of byte)
301
        cmp     ax , word [device.pci_bus]              ; compare with pci and device num in device list (notice the usage of word instead of byte)
302
	je	.find_devicenum 			; Device is already loaded, let's find it's device number
302
        je      .find_devicenum                         ; Device is already loaded, let's find it's device number
303
	add	esi, 4
303
        add     esi, 4
304
	loop	.nextdevice
304
        loop    .nextdevice
Line 305... Line 305...
305
 
305
 
Line 306... Line 306...
306
 
306
 
307
; This device doesnt have its own eth_device structure yet, lets create one
307
; This device doesnt have its own eth_device structure yet, lets create one
308
  .firstdevice:
308
  .firstdevice:
309
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
309
        cmp     [devices], MAX_DEVICES                  ; First check if the driver can handle one more card
310
	jge	.fail
310
        jge     .fail
Line 311... Line 311...
311
 
311
 
Line 312... Line 312...
312
	allocate_and_clear ebx, device.size, .fail	; Allocate the buffer for device structure
312
        allocate_and_clear ebx, device.size, .fail      ; Allocate the buffer for device structure
Line 313... Line 313...
313
 
313
 
Line 314... Line 314...
314
; Fill in the direct call addresses into the struct
314
; Fill in the direct call addresses into the struct
Line 315... Line 315...
315
 
315
 
316
	mov	[device.reset], reset
316
        mov     [device.reset], reset
Line 317... Line 317...
317
	mov	[device.transmit], transmit
317
        mov     [device.transmit], transmit
Line 318... Line 318...
318
	mov	[device.get_MAC], read_mac
318
        mov     [device.get_MAC], read_mac
319
	mov	[device.set_MAC], write_mac
319
        mov     [device.set_MAC], write_mac
320
	mov	[device.unload], unload
320
        mov     [device.unload], unload
321
	mov	[device.name], my_service
321
        mov     [device.name], my_service
Line 322... Line 322...
322
 
322
 
Line 323... Line 323...
323
; save the pci bus and device numbers
323
; save the pci bus and device numbers
324
 
324
 
325
	mov	eax, [IOCTL.input]
325
        mov     eax, [IOCTL.input]
Line 326... Line 326...
326
	mov	cl , [eax+1]
326
        mov     cl , [eax+1]
327
	mov	[device.pci_bus], cl
327
        mov     [device.pci_bus], cl
328
	mov	cl , [eax+2]
328
        mov     cl , [eax+2]
Line 329... Line 329...
329
	mov	[device.pci_dev], cl
329
        mov     [device.pci_dev], cl
330
 
330
 
Line 331... Line 331...
331
; Now, it's time to find the base io addres of the PCI device
331
; Now, it's time to find the base io addres of the PCI device
332
 
332
 
Line 333... Line 333...
333
	find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
333
        find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
Line 334... Line 334...
334
 
334
 
Line 335... Line 335...
335
; We've found the io address, find IRQ now
335
; We've found the io address, find IRQ now
336
 
336
 
337
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
337
        find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
338
 
338
 
339
	DEBUGF	2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
339
        DEBUGF  2,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
340
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
340
        [device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
341
 
341
 
Line 342... Line 342...
342
; Allocate the receive buffer
342
; Allocate the receive buffer
Line 343... Line 343...
343
 
343
 
344
	stdcall CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW
344
        stdcall CreateRingBuffer, dword (RX_BUFFER_SIZE), dword PG_SW
Line 345... Line 345...
345
	test	eax, eax
345
        test    eax, eax
346
	jz	.err
346
        jz      .err
347
	mov	[device.rx_buffer], eax
347
        mov     [device.rx_buffer], eax
Line 348... Line 348...
348
 
348
 
349
; Ok, the eth_device structure is ready, let's probe the device
349
; Ok, the eth_device structure is ready, let's probe the device
350
 
350
 
Line 351... Line 351...
351
	call	probe							; this function will output in eax
351
        call    probe                                                   ; this function will output in eax
352
	test	eax, eax
352
        test    eax, eax
Line 397... Line 397...
397
;;                                                                        ;;
397
;;                                                                        ;;
398
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
398
;;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\;;
Line 399... Line 399...
399
 
399
 
400
align 4
400
align 4
401
unload:
401
unload:
402
	; TODO: (in this particular order)
402
        ; TODO: (in this particular order)
403
	;
403
        ;
404
	; - Stop the device
404
        ; - Stop the device
405
	; - Detach int handler
405
        ; - Detach int handler
406
	; - Remove device from local list (RTL8139_LIST)
406
        ; - Remove device from local list (RTL8139_LIST)
407
	; - call unregister function in kernel
407
        ; - call unregister function in kernel
Line 408... Line 408...
408
	; - Remove all allocated structures and buffers the card used
408
        ; - Remove all allocated structures and buffers the card used
Line 409... Line 409...
409
 
409
 
Line 410... Line 410...
410
	or	eax,-1
410
        or      eax,-1
Line 418... Line 418...
418
;;
418
;;
419
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
419
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 420... Line 420...
420
 
420
 
421
align 4
421
align 4
422
probe:
422
probe:
Line 423... Line 423...
423
	DEBUGF	2,"Probing rtl8139 device: "
423
        DEBUGF  2,"Probing rtl8139 device: "
Line 424... Line 424...
424
 
424
 
Line 425... Line 425...
425
	make_bus_master [device.pci_bus], [device.pci_dev]
425
        make_bus_master [device.pci_bus], [device.pci_dev]
426
 
426
 
427
; get chip version
427
; get chip version
428
 
428
 
429
	set_io	0
429
        set_io  0
430
	set_io	REG_TXCONFIG + 2
430
        set_io  REG_TXCONFIG + 2
Line 431... Line 431...
431
	in	ax , dx
431
        in      ax , dx
432
	shr	ah , 2
432
        shr     ah , 2
433
	shr	ax , 6
433
        shr     ax , 6
434
	and	al , 01111111b
434
        and     al , 01111111b
435
 
435
 
436
	mov	ecx, HW_VER_ARRAY_SIZE-1
436
        mov     ecx, HW_VER_ARRAY_SIZE-1
437
  .chip_ver_loop:
437
  .chip_ver_loop:
438
	cmp	al , [hw_ver_array + ecx]
438
        cmp     al , [hw_ver_array + ecx]
439
	je	.chip_ver_found
439
        je      .chip_ver_found
440
	dec	ecx
440
        dec     ecx
441
	jns	.chip_ver_loop
441
        jns     .chip_ver_loop
Line 442... Line 442...
442
  .unknown:
442
  .unknown:
Line 443... Line 443...
443
	mov	ecx, 8
443
        mov     ecx, 8
444
  .chip_ver_found:
444
  .chip_ver_found:
Line 445... Line 445...
445
	cmp	ecx, 8
445
        cmp     ecx, 8
Line 446... Line 446...
446
	jg	.unknown
446
        jg      .unknown
Line 447... Line 447...
447
 
447
 
448
	mov	[device.hw_ver_id], cl
448
        mov     [device.hw_ver_id], cl
449
 
449
 
450
	mov	ecx, [crosslist + ecx*4]
450
        mov     ecx, [crosslist + ecx*4]
Line 451... Line 451...
451
	mov	[device.name], ecx
451
        mov     [device.name], ecx
Line 452... Line 452...
452
 
452
 
453
	DEBUGF	2,"Chip version: %s\n", ecx
453
        DEBUGF  2,"Chip version: %s\n", ecx
454
 
454
 
Line 455... Line 455...
455
; wake up the chip
455
; wake up the chip
Line 456... Line 456...
456
 
456
 
457
	set_io	0
457
        set_io  0
458
	set_io	REG_HLTCLK
458
        set_io  REG_HLTCLK
459
	mov	al , 'R' ; run the clock
459
        mov     al , 'R' ; run the clock
Line 460... Line 460...
460
	out	dx , al
460
        out     dx , al
461
 
461
 
462
; unlock config and BMCR registers
462
; unlock config and BMCR registers
463
 
463
 
Line 464... Line 464...
464
	set_io	REG_9346CR
464
        set_io  REG_9346CR
465
	mov	al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
465
        mov     al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
466
	out	dx , al
466
        out     dx , al
467
 
467
 
468
; enable power management
468
; enable power management
469
 
469
 
470
	set_io	REG_CONFIG1
470
        set_io  REG_CONFIG1
471
	in	al , dx
471
        in      al , dx
Line 472... Line 472...
472
	cmp	[device.hw_ver_id], IDX_RTL8139B
472
        cmp     [device.hw_ver_id], IDX_RTL8139B
473
	jl	.old_chip
473
        jl      .old_chip
Line 474... Line 474...
474
 
474
 
Line 475... Line 475...
475
; set LWAKE pin to active high (default value).
475
; set LWAKE pin to active high (default value).
476
; it is for Wake-On-LAN functionality of some motherboards.
476
; it is for Wake-On-LAN functionality of some motherboards.
477
; this signal is used to inform the motherboard to execute a wake-up process.
477
; this signal is used to inform the motherboard to execute a wake-up process.
Line 478... Line 478...
478
; only at newer chips.
478
; only at newer chips.
Line 479... Line 479...
479
 
479
 
480
	or	al , (1 shl BIT_PMEn)
480
        or      al , (1 shl BIT_PMEn)
481
	and	al , not (1 shl BIT_LWACT)
481
        and     al , not (1 shl BIT_LWACT)
482
	out	dx , al
482
        out     dx , al
483
 
483
 
Line 484... Line 484...
484
	set_io	REG_CONFIG4
484
        set_io  REG_CONFIG4
485
	in	al , dx
485
        in      al , dx
486
	and	al , not (1 shl BIT_LWPTN)
486
        and     al , not (1 shl BIT_LWPTN)
487
	out	dx , al
487
        out     dx , al
488
 
488
 
Line 489... Line 489...
489
	jmp	.finish_wake_up
489
        jmp     .finish_wake_up
490
  .old_chip:
490
  .old_chip:
Line 491... Line 491...
491
 
491
 
Line 492... Line 492...
492
; wake up older chips
492
; wake up older chips
493
 
493
 
494
	and	al , not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN))
494
        and     al , not ((1 shl BIT_SLEEP) or (1 shl BIT_PWRDWN))
495
	out	dx , al
495
        out     dx , al
496
  .finish_wake_up:
496
  .finish_wake_up:
497
 
497
 
498
; lock config and BMCR registers
498
; lock config and BMCR registers
499
 
499
 
500
	xor	al , al
500
        xor     al , al
Line 501... Line 501...
501
	set_io	0
501
        set_io  0
Line 502... Line 502...
502
	set_io	REG_9346CR
502
        set_io  REG_9346CR
503
	out	dx , al
503
        out     dx , al
504
	DEBUGF	2,"done!\n"
504
        DEBUGF  2,"done!\n"
505
 
505
 
506
 
506
 
507
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
507
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
508
;;
508
;;
509
;;   reset: Set up all registers and descriptors, clear some values
509
;;   reset: Set up all registers and descriptors, clear some values
510
;;
510
;;
511
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
511
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
512
 
512
 
513
reset:
513
reset:
514
	DEBUGF	2,"Resetting rtl8139: "
514
        DEBUGF  2,"Resetting rtl8139: "
Line 515... Line 515...
515
 
515
 
Line 516... Line 516...
516
; attach int handler
516
; attach int handler
517
 
517
 
518
	movzx	eax, [device.irq_line]
518
        movzx   eax, [device.irq_line]
Line 519... Line 519...
519
	DEBUGF	1,"Attaching int handler to irq %x, ",eax:1
519
        DEBUGF  1,"Attaching int handler to irq %x, ",eax:1
Line 520... Line 520...
520
	stdcall AttachIntHandler, eax, int_handler, dword 0
520
        stdcall AttachIntHandler, eax, int_handler, dword 0
521
	test	eax, eax
521
        test    eax, eax
522
	jnz	@f
522
        jnz     @f
523
	DEBUGF	1,"\nCould not attach int handler!\n"
523
        DEBUGF  1,"\nCould not attach int handler!\n"
524
;        or      eax, -1
524
;        or      eax, -1
Line 525... Line 525...
525
;        ret
525
;        ret
Line 526... Line 526...
526
       @@:
526
       @@:
527
 
527
 
528
; reset chip
528
; reset chip
Line 529... Line 529...
529
 
529
 
530
	DEBUGF	1,"Resetting chip\n"
530
        DEBUGF  1,"Resetting chip\n"
Line 531... Line 531...
531
	set_io	0
531
        set_io  0
532
	set_io	REG_COMMAND
532
        set_io  REG_COMMAND
533
	mov	al , 1 shl BIT_RST
533
        mov     al , 1 shl BIT_RST
Line 534... Line 534...
534
	out	dx , al
534
        out     dx , al
Line 535... Line 535...
535
	mov	cx , 1000		; wait no longer for the reset
535
        mov     cx , 1000               ; wait no longer for the reset
536
  .wait_for_reset:
536
  .wait_for_reset:
537
	in	al , dx
537
        in      al , dx
Line 538... Line 538...
538
	test	al , 1 shl BIT_RST
538
        test    al , 1 shl BIT_RST
Line 539... Line 539...
539
	jz	.reset_completed	; RST remains 1 during reset
539
        jz      .reset_completed        ; RST remains 1 during reset
540
	dec	cx
540
        dec     cx
541
	jns	.wait_for_reset
541
        jns     .wait_for_reset
542
  .reset_completed:
542
  .reset_completed:
Line 543... Line 543...
543
 
543
 
Line 544... Line 544...
544
; unlock config and BMCR registers
544
; unlock config and BMCR registers
545
 
545
 
546
	set_io	REG_9346CR
546
        set_io  REG_9346CR
547
	mov	al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
547
        mov     al , (1 shl BIT_93C46_EEM1) or (1 shl BIT_93C46_EEM0)
Line 548... Line 548...
548
	out	dx , al
548
        out     dx , al
Line 549... Line 549...
549
 
549
 
550
; initialize multicast registers (no filtering)
550
; initialize multicast registers (no filtering)
551
 
551
 
Line 552... Line 552...
552
	mov	eax, 0xffffffff
552
        mov     eax, 0xffffffff
Line 553... Line 553...
553
	set_io	REG_MAR0
553
        set_io  REG_MAR0
554
	out	dx , eax
554
        out     dx , eax
Line 555... Line 555...
555
	set_io	REG_MAR4
555
        set_io  REG_MAR4
556
	out	dx , eax
556
        out     dx , eax
Line 557... Line 557...
557
 
557
 
Line 558... Line 558...
558
; enable Rx/Tx
558
; enable Rx/Tx
559
 
559
 
560
	mov	al , (1 shl BIT_RE) or (1 shl BIT_TE)
560
        mov     al , (1 shl BIT_RE) or (1 shl BIT_TE)
Line 561... Line 561...
561
	set_io	REG_COMMAND
561
        set_io  REG_COMMAND
Line 562... Line 562...
562
	out	dx , al
562
        out     dx , al
563
 
563
 
Line 564... Line 564...
564
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
564
; Rxbuffer size, unlimited dma burst, no wrapping, no rx threshold
Line 565... Line 565...
565
; accept broadcast packets, accept physical match packets
565
; accept broadcast packets, accept physical match packets
566
 
566
 
567
	mov	ax , RX_CONFIG
567
        mov     ax , RX_CONFIG
568
	set_io	REG_RXCONFIG
568
        set_io  REG_RXCONFIG
569
	out	dx , ax
569
        out     dx , ax
570
 
570
 
571
 
571
 
Line 572... Line 572...
572
; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144
572
; 1024 bytes DMA burst, total retries = 16 + 8 * 16 = 144
Line 573... Line 573...
573
 
573
 
Line 574... Line 574...
574
	mov	eax , (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0
574
        mov     eax , (TX_MXDMA shl BIT_TX_MXDMA) or (TXRR shl BIT_TXRR) or BIT_IFG1 or BIT_IFG0
Line 575... Line 575...
575
	set_io	REG_TXCONFIG
575
        set_io  REG_TXCONFIG
576
	out	dx , eax
576
        out     dx , eax
577
 
577
 
578
; enable auto negotiation
578
; enable auto negotiation
Line 579... Line 579...
579
 
579
 
580
	set_io	REG_BMCR
580
        set_io  REG_BMCR
Line 581... Line 581...
581
	in	ax , dx
581
        in      ax , dx
Line 582... Line 582...
582
	or	ax , (1 shl BIT_ANE)
582
        or      ax , (1 shl BIT_ANE)
583
	out	dx , ax
583
        out     dx , ax
Line 584... Line 584...
584
 
584
 
Line 585... Line 585...
585
; set auto negotiation advertisement
585
; set auto negotiation advertisement
586
 
586
 
587
	set_io	REG_ANAR
587
        set_io  REG_ANAR
Line 655... Line 655...
655
;;     pointer to device structure in ebx  ;;
655
;;     pointer to device structure in ebx  ;;
656
;;                                         ;;
656
;;                                         ;;
657
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
657
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
658
align 4
658
align 4
659
transmit:
659
transmit:
660
	DEBUGF	1,"\nTransmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
660
        DEBUGF  1,"\nTransmitting packet, buffer:%x, size:%u\n",[esp+4],[esp+8]
661
	mov	eax, [esp+4]
661
        mov     eax, [esp+4]
662
	DEBUGF	1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
662
        DEBUGF  1,"To: %x-%x-%x-%x-%x-%x From: %x-%x-%x-%x-%x-%x Type:%x%x\n",\
663
	[eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
663
        [eax+00]:2,[eax+01]:2,[eax+02]:2,[eax+03]:2,[eax+04]:2,[eax+05]:2,\
664
	[eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
664
        [eax+06]:2,[eax+07]:2,[eax+08]:2,[eax+09]:2,[eax+10]:2,[eax+11]:2,\
665
	[eax+13]:2,[eax+12]:2
665
        [eax+13]:2,[eax+12]:2
666
 
666
 
667
	cmp	dword [esp+8], MAX_ETH_FRAME_SIZE
667
        cmp     dword [esp+8], MAX_ETH_FRAME_SIZE
668
	jg	.fail
668
        jg      .fail
669
	cmp	dword [esp+8], 60
669
        cmp     dword [esp+8], 60
670
	jl	.fail
670
        jl      .fail
Line 671... Line 671...
671
 
671
 
672
; check if we own the current discriptor
672
; check if we own the current discriptor
673
	set_io	0
673
        set_io  0
674
	set_io	REG_TSD0
674
        set_io  REG_TSD0
675
	movzx	ecx, [device.curr_tx_desc]
675
        movzx   ecx, [device.curr_tx_desc]
676
	shl	ecx, 2
676
        shl     ecx, 2
677
	add	edx, ecx
677
        add     edx, ecx
678
	in	eax, dx
678
        in      eax, dx
679
	test	eax, (1 shl BIT_OWN)
679
        test    eax, (1 shl BIT_OWN)
Line 680... Line 680...
680
	jz	.wait_to_send
680
        jz      .wait_to_send
681
 
681
 
682
  .send_packet:
682
  .send_packet:
683
; get next descriptor
683
; get next descriptor
Line 684... Line 684...
684
	inc	[device.curr_tx_desc]
684
        inc     [device.curr_tx_desc]
685
	and	[device.curr_tx_desc], NUM_TX_DESC-1
685
        and     [device.curr_tx_desc], NUM_TX_DESC-1
686
 
686
 
687
; Update stats
687
; Update stats
688
	inc	[device.packets_tx]
688
        inc     [device.packets_tx]
Line 689... Line 689...
689
	mov	eax, [esp+8]
689
        mov     eax, [esp+8]
690
	add	dword [device.bytes_tx], eax
690
        add     dword [device.bytes_tx], eax
691
	adc	dword [device.bytes_tx + 4], 0
691
        adc     dword [device.bytes_tx + 4], 0
692
 
692
 
693
; Set the buffer address
693
; Set the buffer address
694
	set_io	REG_TSAD0
694
        set_io  REG_TSAD0
Line 695... Line 695...
695
	mov	eax, [esp+4]
695
        mov     eax, [esp+4]
696
	mov	[device.TX_DESC+ecx], eax
696
        mov     [device.TX_DESC+ecx], eax
697
	GetRealAddr
697
        GetRealAddr
698
	out	dx, eax
698
        out     dx, eax
699
 
699
 
700
; And the size of the buffer
700
; And the size of the buffer
701
	set_io	REG_TSD0
701
        set_io  REG_TSD0
702
	mov	eax, [esp+8]
702
        mov     eax, [esp+8]
703
	or	eax, (ERTXTH shl BIT_ERTXTH)	; Early threshold
703
        or      eax, (ERTXTH shl BIT_ERTXTH)    ; Early threshold
Line 704... Line 704...
704
	out	dx, eax
704
        out     dx, eax
705
 
705
 
Line 706... Line 706...
706
	DEBUGF	1,"Packet Sent!\n"
706
        DEBUGF  1,"Packet Sent!\n"
707
	xor	eax, eax
707
        xor     eax, eax
708
	ret	8
708
        ret     8
709
 
709
 
710
  .wait_to_send:
710
  .wait_to_send:
711
	DEBUGF	1,"Waiting for timeout\n"
711
        DEBUGF  1,"Waiting for timeout\n"
712
 
712
 
713
	push	edx
713
        push    edx
714
	mov	esi, 300
714
        mov     esi, 300
715
	stdcall Sleep
715
        stdcall Sleep
716
	pop	edx
716
        pop     edx
717
 
717
 
Line 718... Line 718...
718
	in	ax, dx
718
        in      ax, dx
Line 719... Line 719...
719
	test	ax, (1 shl BIT_OWN)
719
        test    ax, (1 shl BIT_OWN)
720
	jnz	.send_packet
720
        jnz     .send_packet
721
 
721
 
-
 
722
        pusha
722
	pusha
723
        call    reset                            ; if chip hung, reset it
Line 740... Line 741...
740
;;                   ;;
741
;;                   ;;
741
;;;;;;;;;;;;;;;;;;;;;;;
742
;;;;;;;;;;;;;;;;;;;;;;;
742
align 4
743
align 4
743
int_handler:
744
int_handler:
Line 744... Line 745...
744
 
745
 
Line 745... Line 746...
745
	DEBUGF	1,"\nIRQ %x\n", eax:2			; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
746
        DEBUGF  1,"\nIRQ %x\n", eax:2                   ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
Line 746... Line 747...
746
 
747
 
747
; find pointer of device wich made IRQ occur
748
; find pointer of device wich made IRQ occur
748
 
749
 
749
	mov	esi, device_list
750
        mov     esi, device_list
750
	mov	ecx, [devices]
751
        mov     ecx, [devices]
751
	test	ecx, ecx
752
        test    ecx, ecx
Line 752... Line 753...
752
	jz	.fail
753
        jz      .fail
753
.nextdevice:
754
.nextdevice:
754
	mov	ebx, dword [esi]
755
        mov     ebx, dword [esi]
755
 
756
 
Line 756... Line 757...
756
	set_io	0
757
        set_io  0
Line 757... Line 758...
757
	set_io	REG_ISR
758
        set_io  REG_ISR
758
	in	ax , dx
759
        in      ax , dx
Line 759... Line 760...
759
	out	dx , ax 			    ; send it back to ACK
760
        out     dx , ax                             ; send it back to ACK
760
 
761
 
Line 761... Line 762...
761
	add	esi, 4
762
        add     esi, 4
Line 762... Line 763...
762
 
763
 
Line 763... Line 764...
763
	test	ax , ax
764
        test    ax , ax
Line 764... Line 765...
764
	jnz	.got_it
765
        jnz     .got_it
Line 765... Line 766...
765
 
766
 
766
	dec	ecx
767
        dec     ecx
767
	jnz	.nextdevice
768
        jnz     .nextdevice
768
 
769
 
769
	ret					    ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
770
        ret                                         ; If no device was found, abort (The irq was probably for a device, not registered to this driver)
Line 770... Line 771...
770
 
771
 
771
  .got_it:
772
  .got_it:
772
 
773
 
773
; looks like we've found it!
774
; looks like we've found it!
774
 
775
 
775
; Lets found out why the irq occured then..
776
; Lets found out why the irq occured then..
776
 
777
 
777
;----------------------------------------------------
778
;----------------------------------------------------
778
; Received packet ok?
779
; Received packet ok?
779
	test	ax, ISR_ROK
780
        test    ax, ISR_ROK
780
	jz	@f
781
        jz      @f
781
	push	ax
782
        push    ax
782
 
783
 
Line 783... Line 784...
783
  .receive:
784
  .receive:
784
	set_io	0
785
        set_io  0
Line 785... Line 786...
785
	set_io	REG_COMMAND
786
        set_io  REG_COMMAND
Line 786... Line 787...
786
	in	al , dx
787
        in      al , dx
787
	test	al , BUFE			    ; test if RX buffer is empty
788
        test    al , BUFE                           ; test if RX buffer is empty
788
	jnz	.finish 			    ;
789
        jnz     .finish                             ;
789
 
790
 
Line 790... Line 791...
790
	DEBUGF	1,"RX: "
791
        DEBUGF  1,"RX: "
Line 791... Line 792...
791
 
792
 
792
	mov	eax, [device.rx_buffer]
793
        mov     eax, [device.rx_buffer]
793
	add	eax, [device.rx_data_offset]
794
        add     eax, [device.rx_data_offset]
794
	test	byte [eax], (1 shl BIT_ROK)	    ; check if packet is ok
795
        test    byte [eax], (1 shl BIT_ROK)         ; check if packet is ok
795
	jz	.reset_rx
796
        jz      .reset_rx
Line 796... Line 797...
796
 
797
 
Line 797... Line 798...
797
; packet is ok, copy it
798
; packet is ok, copy it
798
	movzx	ecx, word [eax+2]		    ; packet length
799
        movzx   ecx, word [eax+2]                   ; packet length
Line 799... Line 800...
799
 
800
 
800
	sub	ecx, 4				    ; don't copy CRC
801
        sub     ecx, 4                              ; don't copy CRC
Line 801... Line 802...
801
 
802
 
802
; Update stats
803
; Update stats
803
	add	dword [device.bytes_rx], ecx
804
        add     dword [device.bytes_rx], ecx
804
	adc	dword [device.bytes_rx + 4], 0
805
        adc     dword [device.bytes_rx + 4], 0
805
	inc	dword [device.packets_rx]
806
        inc     dword [device.packets_rx]
806
 
807
 
807
	DEBUGF	1,"Received %u bytes\n", ecx
808
        DEBUGF  1,"Received %u bytes\n", ecx
808
 
809
 
809
	push	ebx eax ecx
810
        push    ebx eax ecx
810
	stdcall KernelAlloc, ecx		    ; Allocate a buffer to put packet into
811
        stdcall KernelAlloc, ecx                    ; Allocate a buffer to put packet into
811
	pop	ecx
812
        pop     ecx
812
	test	eax, eax			    ; Test if we allocated succesfully
813
        test    eax, eax                            ; Test if we allocated succesfully
Line 813... Line 814...
813
	jz	.abort
814
        jz      .abort
Line 814... Line 815...
814
 
815
 
815
	mov	edi, eax			    ; Where we will copy too
816
        mov     edi, eax                            ; Where we will copy too
816
 
817
 
817
	mov	esi, [esp]			    ; The buffer we will copy from
818
        mov     esi, [esp]                          ; The buffer we will copy from
818
	add	esi, 4				    ; Dont copy CRC
819
        add     esi, 4                              ; Dont copy CRC
819
 
820
 
820
	push	dword .abort			    ; Kernel will return to this address after EthReceiver
821
        push    dword .abort                        ; Kernel will return to this address after EthReceiver
821
	push	ecx edi 			    ; Save buffer pointer and size, to pass to kernel
822
        push    ecx edi                             ; Save buffer pointer and size, to pass to kernel
822
 
823
 
823
  .copy:
824
  .copy:
824
	shr	ecx, 1
825
        shr     ecx, 1
825
	jnc	.nb
826
        jnc     .nb
826
	movsb
827
        movsb
827
  .nb:
828
  .nb:
828
	shr	ecx, 1
829
        shr     ecx, 1
Line 829... Line 830...
829
	jnc	.nw
830
        jnc     .nw
830
	movsw
831
        movsw
831
  .nw:
832
  .nw:
832
	jz	.nd
833
        jz      .nd
Line 833... Line 834...
833
	rep	movsd
834
        rep     movsd
Line 834... Line 835...
834
  .nd:
835
  .nd:
835
 
836
 
836
	jmp	EthReceiver			    ; Send it to kernel
837
        jmp     EthReceiver                         ; Send it to kernel
837
 
838
 
Line 838... Line 839...
838
  .abort:
839
  .abort:
839
	pop	eax ebx
840
        pop     eax ebx
840
						    ; update eth_data_start_offset
841
                                                    ; update eth_data_start_offset
841
	movzx	eax, word [eax+2]		    ; packet length
842
        movzx   eax, word [eax+2]                   ; packet length
Line 842... Line 843...
842
	add	eax, [device.rx_data_offset]
843
        add     eax, [device.rx_data_offset]
843
	add	eax, 4+3			    ; packet header is 4 bytes long + dword alignment
844
        add     eax, 4+3                            ; packet header is 4 bytes long + dword alignment
844
	and	eax, not 3			    ; dword alignment
845
        and     eax, not 3                          ; dword alignment
845
 
846
 
846
	cmp	eax, RX_BUFFER_SIZE
847
        cmp     eax, RX_BUFFER_SIZE
847
	jl	.no_wrap
848
        jl      .no_wrap
848
	DEBUGF	2,"Wrapping"
849
        DEBUGF  2,"Wrapping"
849
	sub	eax, RX_BUFFER_SIZE
850
        sub     eax, RX_BUFFER_SIZE
850
  .no_wrap:
851
  .no_wrap:
851
	mov	[device.rx_data_offset], eax
852
        mov     [device.rx_data_offset], eax
852
	DEBUGF	1,"New RX ptr: %d\n", eax
853
        DEBUGF  1,"New RX ptr: %d\n", eax
853
 
854
 
854
	set_io	0
855
        set_io  0
855
	set_io	REG_CAPR			    ; update 'Current Address of Packet Read register'
856
        set_io  REG_CAPR                            ; update 'Current Address of Packet Read register'
Line 856... Line 857...
856
	sub	eax, 0x10			    ; value 0x10 is a constant for CAPR
857
        sub     eax, 0x10                           ; value 0x10 is a constant for CAPR
857
	out	dx , ax
858
        out     dx , ax
Line 858... Line 859...
858
 
859
 
859
	jmp	.receive			    ; check for multiple packets
860
        jmp     .receive                            ; check for multiple packets
860
 
861
 
861
  .reset_rx:
862
  .reset_rx:
862
	test	byte [eax], (1 shl BIT_CRC)
863
        test    byte [eax], (1 shl BIT_CRC)
Line 863... Line 864...
863
	jz	.no_crc_error
864
        jz      .no_crc_error
864
	DEBUGF	2,"\nCRC error!\n"
865
        DEBUGF  2,"\nCRC error!\n"
865
 
866
 
866
  .no_crc_error:
867
  .no_crc_error:
867
	test	byte [eax], (1 shl BIT_FAE)
868
        test    byte [eax], (1 shl BIT_FAE)
868
	jz	.no_fae_error
869
        jz      .no_fae_error
869
	DEBUGF	1,"\nFrame alignment error!\n"
870
        DEBUGF  1,"\nFrame alignment error!\n"
Line 870... Line 871...
870
 
871
 
871
  .no_fae_error:
872
  .no_fae_error:
Line 872... Line 873...
872
	DEBUGF	1,"Reset RX\n"
873
        DEBUGF  1,"Reset RX\n"
873
	in	al , dx 			    ; read command register
874
        in      al , dx                             ; read command register
Line 874... Line 875...
874
	push	ax
875
        push    ax
875
 
876
 
876
	and	al , not (1 shl BIT_RE) 	    ; Clear the RE bit
877
        and     al , not (1 shl BIT_RE)             ; Clear the RE bit
877
	out	dx , al
878
        out     dx , al
Line 926... Line 927...
926
;        jz      .nocsl
927
;        jz      .nocsl
927
;        DEBUGF  2, "TX: Carrier Sense Lost!\n"
928
;        DEBUGF  2, "TX: Carrier Sense Lost!\n"
928
;
929
;
929
;  .nocsl:
930
;  .nocsl:
Line 930... Line 931...
930
 
931
 
931
	DEBUGF	1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8
932
        DEBUGF  1,"TX OK: free buffer %x\n", [device.TX_DESC+ecx]:8
932
	push	ecx ebx
933
        push    ecx ebx
933
	stdcall KernelFree, [device.TX_DESC+ecx]
934
        stdcall KernelFree, [device.TX_DESC+ecx]
934
	pop	ebx ecx
935
        pop     ebx ecx
Line 935... Line 936...
935
	mov	[device.TX_DESC+ecx], 0
936
        mov     [device.TX_DESC+ecx], 0
936
 
937
 
937
  .notthisone:
938
  .notthisone:
938
	add	ecx, 4
939
        add     ecx, 4
939
	cmp	ecx, 16
940
        cmp     ecx, 16
Line 940... Line 941...
940
	jl	.txdesloop
941
        jl      .txdesloop
941
	pop	ax
942
        pop     ax
942
 
943
 
943
;----------------------------------------------------
944
;----------------------------------------------------
944
; Rx buffer overflow ?
945
; Rx buffer overflow ?
Line 945... Line 946...
945
  @@:
946
  @@:
946
	test	ax, ISR_RXOVW
947
        test    ax, ISR_RXOVW
Line 947... Line 948...
947
	jz	@f
948
        jz      @f
948
 
949
 
949
	push	ax
950
        push    ax
950
	DEBUGF	2,"RX-buffer overflow!\n"
951
        DEBUGF  2,"RX-buffer overflow!\n"
951
 
952
 
Line 952... Line 953...
952
	set_io	0
953
        set_io  0
953
	set_io	REG_ISR
954
        set_io  REG_ISR
954
	mov	ax , ISR_FIFOOVW or ISR_RXOVW
955
        mov     ax , ISR_FIFOOVW or ISR_RXOVW
955
	out	dx , ax
956
        out     dx , ax
956
	pop	ax
957
        pop     ax
Line 957... Line 958...
957
 
958
 
Line 958... Line 959...
958
;----------------------------------------------------
959
;----------------------------------------------------
959
; Packet underrun?
960
; Packet underrun?
960
  @@:
961
  @@:
961
	test	ax, ISR_PUN
962
        test    ax, ISR_PUN
962
	jz	@f
963
        jz      @f
Line 963... Line 964...
963
 
964
 
964
	DEBUGF	2,"Packet underrun!\n"
965
        DEBUGF  2,"Packet underrun!\n"
Line 965... Line 966...
965
 
966
 
966
;----------------------------------------------------
967
;----------------------------------------------------
967
; Receive FIFO overflow ?
968
; Receive FIFO overflow ?
968
  @@:
969
  @@:
969
	test	ax, ISR_FIFOOVW
970
        test    ax, ISR_FIFOOVW
Line 970... Line 971...
970
	jz	@f
971
        jz      @f
971
 
972
 
972
	push	ax
973
        push    ax
973
	DEBUGF	2,"RX fifo overflow!\n"
974
        DEBUGF  2,"RX fifo overflow!\n"
974
 
975
 
Line 975... Line 976...
975
	set_io	0
976
        set_io  0
976
	set_io	REG_ISR
977
        set_io  REG_ISR
Line 977... Line 978...
977
	mov	ax , ISR_FIFOOVW or ISR_RXOVW
978
        mov     ax , ISR_FIFOOVW or ISR_RXOVW
978
	out	dx , ax
979
        out     dx , ax
Line 979... Line 980...
979
	pop	ax
980
        pop     ax
Line 999... Line 1000...
999
;;                     ;;
1000
;;                     ;;
1000
;;;;;;;;;;;;;;;;;;;;;;;;;
1001
;;;;;;;;;;;;;;;;;;;;;;;;;
Line 1001... Line 1002...
1001
 
1002
 
1002
align 4
1003
align 4
1003
cable:
1004
cable:
Line 1004... Line 1005...
1004
	DEBUGF	1,"Checking Cable status: "
1005
        DEBUGF  1,"Checking Cable status: "
1005
 
1006
 
1006
	mov	edx, dword [device.io_addr]
1007
        mov     edx, dword [device.io_addr]
Line 1007... Line 1008...
1007
	add	edx, REG_MSR
1008
        add     edx, REG_MSR
1008
	in	al , dx
1009
        in      al , dx
Line 1009... Line 1010...
1009
 
1010
 
1010
;        test    al , 1 SHL 2     ; 0 = link ok 1 = link fail
1011
;        test    al , 1 SHL 2     ; 0 = link ok 1 = link fail
Line 1011... Line 1012...
1011
;        jnz     .notconnected
1012
;        jnz     .notconnected
1012
 
1013
 
Line 1013... Line 1014...
1013
;        test    al , 1 SHL 3     ; 0 = 100 Mbps 1 = 10 Mbps
1014
;        test    al , 1 SHL 3     ; 0 = 100 Mbps 1 = 10 Mbps
1014
;        jnz     .10mbps
1015
;        jnz     .10mbps
1015
 
1016
 
Line 1016... Line 1017...
1016
	shr	al, 2
1017
        shr     al, 2
Line 1027... Line 1028...
1027
;; Write MAC address ;;
1028
;; Write MAC address ;;
1028
;;                   ;;
1029
;;                   ;;
1029
;;;;;;;;;;;;;;;;;;;;;;;
1030
;;;;;;;;;;;;;;;;;;;;;;;
Line 1030... Line 1031...
1030
 
1031
 
1031
align 4
1032
align 4
Line 1032... Line 1033...
1032
write_mac:	; in: mac pushed onto stack (as 3 words)
1033
write_mac:      ; in: mac pushed onto stack (as 3 words)
Line 1033... Line 1034...
1033
 
1034
 
Line 1034... Line 1035...
1034
	DEBUGF	2,"Writing MAC: "
1035
        DEBUGF  2,"Writing MAC: "
1035
 
1036
 
1036
; disable all in command registers
1037
; disable all in command registers
1037
 
1038
 
1038
	set_io	0
1039
        set_io  0
1039
	set_io	REG_9346CR
1040
        set_io  REG_9346CR
1040
	xor	eax, eax
1041
        xor     eax, eax
1041
	out	dx , al
1042
        out     dx , al
1042
 
1043
 
1043
	set_io	REG_IMR
1044
        set_io  REG_IMR
1044
	xor	eax, eax
1045
        xor     eax, eax
1045
	out	dx , ax
1046
        out     dx , ax
Line 1046... Line 1047...
1046
 
1047
 
Line 1047... Line 1048...
1047
	set_io	REG_ISR
1048
        set_io  REG_ISR
1048
	mov	eax, -1
1049
        mov     eax, -1
1049
	out	dx , ax
1050
        out     dx , ax
Line 1050... Line 1051...
1050
 
1051
 
Line 1051... Line 1052...
1051
; enable writing
1052
; enable writing
1052
 
1053
 
1053
	set_io	REG_9346CR
1054
        set_io  REG_9346CR
1054
	mov	eax, REG_9346CR_WE
1055
        mov     eax, REG_9346CR_WE
1055
	out	dx , al
1056
        out     dx , al
1056
 
1057
 
1057
 ; write the mac ...
1058
 ; write the mac ...
1058
 
1059
 
Line 1059... Line 1060...
1059
	set_io	REG_IDR0
1060
        set_io  REG_IDR0
Line 1060... Line 1061...
1060
	pop	eax
1061
        pop     eax
1061
	out	dx , eax
1062
        out     dx , eax
1062
 
1063
 
Line 1063... Line 1064...
1063
	set_io	REG_IDR0+4
1064
        set_io  REG_IDR0+4
Line 1064... Line 1065...
1064
	xor	eax, eax
1065
        xor     eax, eax
Line 1065... Line 1066...
1065
	pop	ax
1066
        pop     ax
Line 1081... Line 1082...
1081
;; Read MAC address ;;
1082
;; Read MAC address ;;
1082
;;                  ;;
1083
;;                  ;;
1083
;;;;;;;;;;;;;;;;;;;;;;
1084
;;;;;;;;;;;;;;;;;;;;;;
Line 1084... Line 1085...
1084
 
1085
 
1085
read_mac:
1086
read_mac:
Line 1086... Line 1087...
1086
	DEBUGF	2,"Reading MAC: "
1087
        DEBUGF  2,"Reading MAC: "
1087
 
1088
 
1088
	set_io	0
1089
        set_io  0
1089
	lea	edi, [device.mac]
1090
        lea     edi, [device.mac]
1090
	in	eax, dx
1091
        in      eax, dx
1091
	stosd
1092
        stosd
1092
	add	edx, 4
1093
        add     edx, 4
Line 1093... Line 1094...
1093
	in	ax, dx
1094
        in      ax, dx
Line 1094... Line 1095...
1094
	stosw
1095
        stosw
Line 1095... Line 1096...
1095
 
1096
 
Line 1096... Line 1097...
1096
	DEBUGF	2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2
1097
        DEBUGF  2,"%x-%x-%x-%x-%x-%x\n",[edi-6]:2,[edi-5]:2,[edi-4]:2,[edi-3]:2,[edi-2]:2,[edi-1]:2
1097
 
1098
 
Line 1098... Line 1099...
1098
	ret
1099
        ret
1099
 
1100
 
1100
 
1101
 
1101
; End of code
1102
; End of code
1102
 
1103
 
1103
section '.data' data readable writable align 16 ; place all uninitialized data place here
1104
section '.data' data readable writable align 16 ; place all uninitialized data place here
1104
align 4 					; Place all initialised data here
1105
align 4                                         ; Place all initialised data here
1105
 
1106
 
1106
devices 	dd 0
1107
devices         dd 0
1107
version 	dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1108
version         dd (DRIVER_VERSION shl 16) or (API_VERSION and 0xFFFF)
1108
my_service	db 'RTL8139',0			  ; max 16 chars include zero
1109
my_service      db 'RTL8139',0                    ; max 16 chars include zero
1109
 
1110
 
1110
device_1	db 'Realtek 8139',0
1111
device_1        db 'Realtek 8139',0
Line 1111... Line 1112...
1111
device_2	db 'Realtek 8139A',0
1112
device_2        db 'Realtek 8139A',0
1112
device_3	db 'Realtek 8139B',0
1113
device_3        db 'Realtek 8139B',0
1113
device_4	db 'Realtek 8139C',0
1114
device_4        db 'Realtek 8139C',0
1114
device_5	db 'Realtek 8100',0
1115
device_5        db 'Realtek 8100',0
1115
device_6	db 'Realtek 8139D',0
1116
device_6        db 'Realtek 8139D',0
1116
device_7	db 'Realtek 8139CP',0
1117
device_7        db 'Realtek 8139CP',0
1117
device_8	db 'Realtek 8101',0
1118
device_8        db 'Realtek 8101',0
1118
device_unknown	db 'Unknown RTL8139 clone', 0
1119
device_unknown  db 'Unknown RTL8139 clone', 0
1119
 
1120
 
1120
crosslist:
1121
crosslist:
1121
	dd device_1
1122
        dd device_1
1122
	dd device_2
1123
        dd device_2
1123
	dd device_3
1124
        dd device_3
1124
	dd device_4
1125
        dd device_4
1125
	dd device_5
1126
        dd device_5
1126
	dd device_6
1127
        dd device_6
1127
	dd device_7
1128
        dd device_7
1128
	dd device_8
1129
        dd device_8
1129
	dd device_unknown
1130
        dd device_unknown
1130
 
1131
 
1131
hw_ver_array:			 ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with
1132
hw_ver_array:                    ; This array is used by the probe routine to find out wich version of the RTL8139 we are working with
Line 1132... Line 1133...
1132
	db VER_RTL8139
1133
        db VER_RTL8139
Line 1133... Line 1134...
1133
	db VER_RTL8139A
1134
        db VER_RTL8139A
Line 1134... Line 1135...
1134
	db VER_RTL8139B
1135
        db VER_RTL8139B