Subversion Repositories Kolibri OS

Rev

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

Rev 1377 Rev 1492
Line 8... Line 8...
8
;;                                                                  ;;
8
;;                                                                  ;;
9
;; Status: under construction                                       ;;
9
;; Status: under construction                                       ;;
10
;;                                                                  ;;
10
;;                                                                  ;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 12... Line 12...
12
 
12
 
Line 13... Line 13...
13
; $Revision: 1377 $
13
; $Revision: 1492 $
Line 14... Line 14...
14
 
14
 
Line 24... Line 24...
24
MAX_ETH_FRAME_SIZE equ 1514
24
MAX_ETH_FRAME_SIZE equ 1514
Line 25... Line 25...
25
 
25
 
26
include 'proc32.inc'
26
include 'proc32.inc'
27
include 'imports.inc'
27
include 'imports.inc'
-
 
28
include 'fdo.inc'
Line -... Line 29...
-
 
29
include 'netdrv.inc'
28
include 'fdo.inc'
30
 
29
 
31
 
30
OS_BASE 	equ 0;
32
OS_BASE 	equ 0
Line 31... Line 33...
31
new_app_base	equ 0x60400000
33
new_app_base	equ 0x60400000
32
PROC_BASE	equ OS_BASE+0x0080000
34
PROC_BASE	equ OS_BASE+0x0080000
33
 
35
 
Line 34... Line -...
34
public START
-
 
35
public service_proc
-
 
36
public version
-
 
37
 
-
 
38
struc IOCTL {
-
 
39
      .handle		dd ?
-
 
40
      .io_code		dd ?
-
 
41
      .input		dd ?
-
 
Line 42... Line 36...
42
      .inp_size 	dd ?
36
public START
43
      .output		dd ?
37
public service_proc
44
      .out_size 	dd ?
38
public version
Line 45... Line 39...
45
}
39
 
46
 
-
 
47
virtual at 0
-
 
48
  IOCTL IOCTL
-
 
49
end virtual
-
 
50
 
-
 
51
struc ETH_DEVICE {
-
 
52
; pointers to procedures
-
 
53
      .unload		dd ?
-
 
54
      .reset		dd ?
-
 
55
      .transmit 	dd ?
-
 
56
      .set_MAC		dd ?
-
 
57
      .get_MAC		dd ?
-
 
58
      .set_mode 	dd ?
-
 
59
      .get_mode 	dd ?
-
 
60
; status
-
 
61
      .bytes_tx 	dq ?
-
 
62
      .bytes_rx 	dq ?
-
 
Line 63... Line 40...
63
      .packets_tx	dd ?
40
 
64
      .packets_rx	dd ?
41
virtual at ebx
Line 65... Line 42...
65
      .mode		dd ?  ; This dword contains cable status (10mbit/100mbit, full/half duplex, auto negotiation or not,..)
42
 
66
      .name		dd ?
43
	device:
67
      .mac		dp ?
44
 
68
; device specific
45
	ETH_DEVICE
-
 
46
 
-
 
47
      .rx_buffer	dd ?
-
 
48
      .tx_buffer	dd ?
-
 
49
 
-
 
50
      .io_addr		dd ?
-
 
51
      .irq_line 	db ?
-
 
52
      .pci_bus		db ?
-
 
53
      .pci_dev		db ?
-
 
54
			db ?	; align 4
Line 69... Line 55...
69
 
55
 
70
      .rx_buffer	dd ?
56
      .access_read_csr		dd ?
71
      .tx_buffer	dd ?
-
 
-
 
57
      .access_write_csr 	dd ?
72
 
58
      .access_read_bcr		dd ?
73
      .io_addr		dd ?
59
      .access_write_bcr 	dd ?
74
      .irq_line 	db ?
60
      .access_read_rap		dd ?
75
      .pci_bus		db ?
61
      .access_write_rap 	dd ?
76
      .pci_dev		db ?
62
      .access_reset		dd ?
Line 100... Line 86...
100
      .ltint		db ?
86
      .ltint		db ?
101
      .dxsuflo		db ?
87
      .dxsuflo		db ?
102
      .fset		db ?
88
      .fset		db ?
103
      .fdx		db ?
89
      .fdx		db ?
Line 104... Line -...
104
 
-
 
105
      .access_read_csr		dd ?
-
 
106
      .access_write_csr 	dd ?
-
 
107
      .access_read_bcr		dd ?
-
 
108
      .access_write_bcr 	dd ?
-
 
109
      .access_read_rap		dd ?
-
 
110
      .access_write_rap 	dd ?
90
 
111
      .access_reset		dd ?
-
 
112
 
-
 
113
      .size:
-
 
114
 
-
 
Line 115... Line -...
115
}
-
 
116
 
-
 
117
virtual at 0
91
      .size = $ - device
Line 118... Line 92...
118
 device ETH_DEVICE
92
 
119
end virtual
93
end virtual
120
 
94
 
Line 438... Line 412...
438
;; proc START             ;;
412
;; proc START             ;;
439
;;                        ;;
413
;;                        ;;
440
;; (standard driver proc) ;;
414
;; (standard driver proc) ;;
441
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
415
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line -... Line 416...
-
 
416
 
442
 
417
align 4
Line 443... Line 418...
443
proc START stdcall, state:dword
418
proc START stdcall, state:dword
444
 
419
 
Line 468... Line 443...
468
 
443
 
469
align 4
444
align 4
Line 470... Line 445...
470
proc service_proc stdcall, ioctl:dword
445
proc service_proc stdcall, ioctl:dword
471
 
446
 
Line 472... Line 447...
472
	mov	edx, [ioctl]
447
	mov	edx, [ioctl]
Line 473... Line 448...
473
	mov	eax, [edx+IOCTL.io_code]
448
	mov	eax, [IOCTL.io_code]
474
 
449
 
Line 475... Line 450...
475
;------------------------------------------------------
450
;------------------------------------------------------
476
 
451
 
477
	cmp	eax, 0 ;SRV_GETVERSION
452
	cmp	eax, 0 ;SRV_GETVERSION
478
	jne	@F
453
	jne	@F
Line 479... Line 454...
479
 
454
 
480
	cmp	[edx+IOCTL.out_size], 4
455
	cmp	[IOCTL.out_size], 4
Line 481... Line 456...
481
	jl	.fail
456
	jl	.fail
482
	mov	eax, [edx+IOCTL.output]
457
	mov	eax, [IOCTL.output]
483
	mov	[eax], dword API_VERSION
458
	mov	[eax], dword API_VERSION
484
 
459
 
Line 485... Line -...
485
	xor	eax, eax
-
 
486
	ret
-
 
487
 
460
	xor	eax, eax
488
;------------------------------------------------------
461
	ret
Line 489... Line 462...
489
  @@:
462
 
490
	cmp	eax, 1 ;SRV_HOOK
463
;------------------------------------------------------
491
	jne	.fail
464
  @@:
Line 492... Line 465...
492
 
465
	cmp	eax, 1 ;SRV_HOOK
Line 493... Line -...
493
	mov	eax, [esp]
-
 
494
 
466
	jne	.fail
495
	cmp	[edx + IOCTL.inp_size], 3		; Data input must be at least 3 bytes
467
 
496
	jl	.fail
468
	cmp	[IOCTL.inp_size], 3			; Data input must be at least 3 bytes
-
 
469
	jl	.fail
-
 
470
 
497
 
471
	mov	eax, [IOCTL.input]
498
	mov	eax, [edx + IOCTL.input]
472
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
499
	cmp	byte [eax], 1				; 1 means device number and bus number (pci) are given
473
	jne	.fail					; other types arent supported for this card yet
500
	jne	.fail					; other types arent supported for this card yet
474
 
501
 
475
; check if the device is already listed
502
; check if the device is already listed
476
 
503
 
477
	mov	ecx, [PCNET_DEV]
504
	mov	esi, PCNET_LIST
478
	test	ecx, ecx
Line 505... Line 479...
505
	mov	ecx, [PCNET_DEV]
479
	jz	.firstdevice
Line 506... Line 480...
506
	test	ecx, ecx
480
 
Line 527... Line 501...
527
	jz	.fail
501
	jz	.fail
528
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
502
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
Line 529... Line 503...
529
 
503
 
Line 530... Line 504...
530
; Fill in the direct call addresses into the struct
504
; Fill in the direct call addresses into the struct
531
 
505
 
532
	mov	dword [ebx+device.reset], reset
506
	mov	[device.reset], reset
533
	mov	dword [ebx+device.transmit], transmit
507
	mov	[device.transmit], transmit
534
	mov	dword [ebx+device.get_MAC], read_mac
508
	mov	[device.get_MAC], read_mac
535
	mov	dword [ebx+device.set_MAC], write_mac
509
	mov	[device.set_MAC], write_mac
Line 536... Line 510...
536
	mov	dword [ebx+device.unload], unload
510
	mov	[device.unload], unload
Line 537... Line 511...
537
	mov	dword [ebx+device.name], my_service
511
	mov	[device.name], my_service
538
 
512
 
539
; save the pci bus and device numbers
513
; save the pci bus and device numbers
540
 
514
 
541
	mov	eax, [edx+IOCTL.input]
515
	mov	eax, [IOCTL.input]
Line 542... Line 516...
542
	mov	cl , [eax+1]
516
	mov	cl , [eax+1]
543
	mov	[ebx+device.pci_bus], cl
-
 
544
	mov	cl , [eax+2]
-
 
545
	mov	[ebx+device.pci_dev], cl
-
 
546
 
-
 
547
; Now, it's time to find the base io addres of the PCI device
-
 
548
; TODO: implement check if bus and dev exist on this machine
-
 
549
 
-
 
550
	mov	edx, PCI_BASE_ADDRESS_0
-
 
551
  .reg_check:
-
 
552
	movzx	eax, byte [ebx+device.pci_bus]
-
 
553
	movzx	ecx, byte [ebx+device.pci_dev]
-
 
554
 
-
 
555
	push	edx ecx
-
 
556
	stdcall PciRead16, eax ,ecx ,edx
-
 
557
	pop	ecx edx
-
 
558
 
-
 
559
	mov	[ebx+device.io_addr], eax
-
 
560
	and	eax, PCI_BASE_ADDRESS_IO_MASK
-
 
561
	test	eax, eax
-
 
Line 562... Line 517...
562
	jz	.inc_reg
517
	mov	[device.pci_bus], cl
563
	mov	eax, [ebx+device.io_addr]
-
 
564
	and	eax, PCI_BASE_ADDRESS_SPACE_IO
-
 
565
	test	eax, eax
-
 
566
	jz	.inc_reg
-
 
567
 
-
 
568
	mov	eax, [ebx+device.io_addr]
-
 
569
	and	eax, PCI_BASE_ADDRESS_IO_MASK
-
 
570
	mov	[ebx+device.io_addr], eax
-
 
571
	jmp	.got_io
-
 
572
 
-
 
Line 573... Line 518...
573
  .inc_reg:
518
	mov	cl , [eax+2]
Line 574... Line -...
574
	add	edx, 4
-
 
575
	cmp	edx, PCI_BASE_ADDRESS_5
519
	mov	[device.pci_dev], cl
576
	jbe	.reg_check
-
 
577
 
-
 
578
  .got_io:
-
 
579
 
-
 
Line 580... Line 520...
580
; We've found the io address, find IRQ now
520
 
581
 
521
; Now, it's time to find the base io addres of the PCI device
582
	movzx	eax, byte [ebx+device.pci_bus]
-
 
583
	movzx	ecx, byte [ebx+device.pci_dev]
-
 
584
	push	ebx
-
 
585
	stdcall PciRead8, eax ,ecx ,0x3c				; 0x3c is the offset where irq can be found
-
 
586
	pop	ebx
-
 
587
	mov	byte [ebx+device.irq_line], al
-
 
588
 
-
 
589
	DEBUGF	1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
-
 
Line -... Line 522...
-
 
522
 
-
 
523
	find_io [device.pci_bus], [device.pci_dev], [device.io_addr]
590
	[ebx+device.pci_dev]:1,[ebx+device.pci_bus]:1,[ebx+device.irq_line]:1,[ebx+device.io_addr]:4
524
 
Line 591... Line -...
591
 
-
 
592
 
-
 
593
; Allocate the Receive buffer
-
 
594
 
-
 
595
	stdcall KernelAlloc, PCNET_RX_RING_SIZE * PCNET_PKT_BUF_SZ
-
 
596
	test	eax, eax
-
 
597
	jz	.err
-
 
598
	mov	[ebx+device.rx_buffer], eax				; Save the address to it into the device struct
-
 
599
 
-
 
600
; Allocate the Transmit Buffer
-
 
601
 
525
; We've found the io address, find IRQ now
602
	stdcall KernelAlloc, PCNET_TX_RING_SIZE * PCNET_PKT_BUF_SZ
526
 
603
	test	eax, eax
527
	find_irq [device.pci_bus], [device.pci_dev], [device.irq_line]
604
	jz	.err
-
 
605
	mov	[ebx+device.tx_buffer], eax
-
 
606
 
-
 
607
; Allocate the RX Ring
-
 
608
 
-
 
609
	stdcall KernelAlloc, PCNET_RX_RING_SIZE * buf_head.size
-
 
610
	test	eax, eax
-
 
611
	jz	.err
-
 
612
	mov	dword [ebx + device.rx_ring], eax
-
 
613
	call	GetPgAddr
-
 
614
	mov	dword [ebx + device.rx_ring_phys], eax
-
 
615
 
-
 
616
; Allocate the TX ring
-
 
Line 617... Line -...
617
 
-
 
618
	stdcall KernelAlloc, PCNET_TX_RING_SIZE * buf_head.size
-
 
619
	test	eax, eax
-
 
620
	jz	.err
-
 
621
	mov	dword [ebx + device.tx_ring], eax
-
 
622
	call	GetPgAddr
-
 
623
	mov	dword [ebx + device.tx_ring_phys], eax
528
 
624
 
-
 
625
; fill in some of the structure variables
-
 
626
 
-
 
627
	call	switch_to_wio
-
 
628
 
-
 
629
	mov	edi, [ebx + device.rx_ring]
-
 
630
	mov	ecx, PCNET_RX_RING_SIZE
-
 
Line 631... Line 529...
631
	mov	eax, [ebx + device.rx_buffer]
529
	DEBUGF	1,"Hooking into device, dev:%x, bus:%x, irq:%x, addr:%x\n",\
632
	call	GetPgAddr
-
 
633
  .rx_init:
-
 
634
	mov	[edi + buf_head.base], eax
530
	[device.pci_dev]:1,[device.pci_bus]:1,[device.irq_line]:1,[device.io_addr]:4
635
	mov	[edi + buf_head.length], PCNET_PKT_BUF_SZ_NEG
-
 
636
	mov	[edi + buf_head.status], 0x8000
531
 
637
	and	dword [edi + buf_head.msg_length], 0
-
 
638
	and	dword [edi + buf_head.reserved], 0
-
 
639
	add	eax, PCNET_PKT_BUF_SZ
-
 
640
;        inc     eax
-
 
641
	add	 edi, buf_head.size
-
 
642
	loop	 .rx_init
-
 
643
 
-
 
644
	mov	edi, [ebx + device.tx_ring]
-
 
Line 645... Line 532...
645
	mov	ecx, PCNET_TX_RING_SIZE
532
	allocate_and_clear [device.tx_buffer], (PCNET_RX_RING_SIZE * PCNET_PKT_BUF_SZ), .err
646
	mov	eax, [ebx + device.tx_buffer]
533
	allocate_and_clear [device.rx_buffer], (PCNET_TX_RING_SIZE * PCNET_PKT_BUF_SZ), .err
647
	call	GetPgAddr
534
	allocate_and_clear [device.rx_ring], (PCNET_RX_RING_SIZE * buf_head.size), .err
648
  .tx_init:
535
 
Line 685... Line 572...
685
 
572
 
Line 686... Line 573...
686
; If an error occured, remove all allocated data and exit (returning -1 in eax)
573
; If an error occured, remove all allocated data and exit (returning -1 in eax)
687
 
574
 
688
  .destroy:
-
 
689
	; todo: reset device into virgin state
575
  .destroy:
690
 
576
	; todo: reset device into virgin state
691
	dec	[PCNET_DEV]
577
	dec	[PCNET_DEV]
692
  .err:
578
  .err:
693
	DEBUGF	1,"Error, removing all data !\n"
579
	DEBUGF	1,"Error, removing all data !\n"
694
	stdcall KernelFree, dword [ebx+device.rx_buffer]
580
	stdcall KernelFree, [device.rx_buffer]
Line 695... Line 581...
695
	stdcall KernelFree, dword [ebx+device.tx_buffer]
581
	stdcall KernelFree, [device.tx_buffer]
696
	stdcall KernelFree, ebx
582
	stdcall KernelFree, ebx
697
 
583
 
Line 730... Line 616...
730
;;
616
;;
731
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
617
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 732... Line 618...
732
 
618
 
733
align 4
619
align 4
734
probe:
-
 
Line -... Line 620...
-
 
620
probe:
-
 
621
 
-
 
622
	make_bus_master [device.pci_bus], [device.pci_dev]
-
 
623
 
-
 
624
; first, fill in some of the structure variables
-
 
625
 
-
 
626
	mov	edi, [device.rx_ring]
-
 
627
	mov	ecx, PCNET_RX_RING_SIZE
-
 
628
	mov	eax, [device.rx_buffer]
-
 
629
	call	GetPgAddr
-
 
630
  .rx_init:
-
 
631
	mov	[edi + buf_head.base], eax
-
 
632
	mov	[edi + buf_head.length], PCNET_PKT_BUF_SZ_NEG
-
 
633
	mov	[edi + buf_head.status], 0x8000
-
 
634
	and	dword [edi + buf_head.msg_length], 0
-
 
635
	and	dword [edi + buf_head.reserved], 0
-
 
636
	add	eax, PCNET_PKT_BUF_SZ
-
 
637
;        inc     eax
-
 
638
	add	 edi, buf_head.size
-
 
639
	loop	 .rx_init
-
 
640
 
-
 
641
	mov	edi, [device.tx_ring]
-
 
642
	mov	ecx, PCNET_TX_RING_SIZE
-
 
643
	mov	eax, [device.tx_buffer]
-
 
644
	call	GetPgAddr
-
 
645
  .tx_init:
-
 
646
	mov	[edi + buf_head.base], eax
-
 
647
	and	dword [edi + buf_head.length], 0
-
 
648
	and	dword [edi + buf_head.msg_length], 0
-
 
649
	and	dword [edi + buf_head.reserved], 0
-
 
650
	add	eax, PCNET_PKT_BUF_SZ
-
 
651
	add	edi, buf_head.size
-
 
652
	loop	.tx_init
-
 
653
 
-
 
654
	mov	[device.tlen_rlen], (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS)
-
 
655
 
-
 
656
	; First, we must try to use Word operations
735
	mov	edx, [ebx + device.io_addr]
657
	call	switch_to_wio
Line 736... Line 658...
736
 
658
	set_io	0
737
	call	wio_reset
659
	call	wio_reset
738
 
660
 
Line 759... Line 681...
759
	jmp	.L1
681
	jmp	.L1
Line 760... Line 682...
760
 
682
 
761
  .try_dwio:
683
  .try_dwio:
Line -... Line 684...
-
 
684
	call	dwio_reset
762
	call	dwio_reset
685
 
763
 
686
	set_io	0
764
	xor	ecx, ecx
687
	xor	ecx, ecx
765
	call	dwio_read_csr
688
	call	dwio_read_csr
Line 766... Line 689...
766
	cmp	eax, 4
689
	cmp	eax, 4
767
	jne	.no_dev
690
	jne	.no_dev
768
 
691
 
769
	; Try Dword I/O
692
	; Try Dword I/O
770
	add	edx, PCNET_DWIO_RAP
693
	set_io	PCNET_DWIO_RAP
771
	mov	eax, 88
694
	mov	eax, 88
772
	out	dx , eax
695
	out	dx , eax
773
	nop
696
	nop
774
	nop
697
	nop
775
	in	eax, dx
698
	in	eax, dx
776
	sub	edx, PCNET_DWIO_RAP
699
	set_io	0
Line 777... Line 700...
777
	and	eax, 0xffff
700
	and	eax, 0xffff
Line 787... Line 710...
787
  .no_dev:
710
  .no_dev:
788
	DEBUGF 1,"PCnet device not found!\n"
711
	DEBUGF 1,"PCnet device not found!\n"
789
	mov	eax, 1
712
	mov	eax, 1
790
	ret
713
	ret
791
  .L1:
714
  .L1:
792
	; TODO: remember to use WORD or DWORD operations
-
 
793
 
-
 
794
;;;        stdcall Sleep, 10
-
 
795
 
-
 
796
;---------------------------------------------
-
 
797
; Switch to dword operations
-
 
798
 
-
 
799
 ;       DEBUGF 1,"Switching to 32\n"
-
 
800
 ;
-
 
801
 ;       mov     ecx, PCNET_DWIO_RDP
-
 
802
 ;       mov     eax, 0
-
 
803
 ;       call    wio_write_csr
-
 
804
 
-
 
805
;---------------------------------------------
-
 
Line 806... Line 715...
806
 
715
 
807
	mov	ecx, PCNET_CSR_CHIPID0
716
	mov	ecx, PCNET_CSR_CHIPID0
808
	call	[ebx + device.access_read_csr]
717
	call	[device.access_read_csr]
Line 809... Line 718...
809
	mov	esi, eax
718
	mov	esi, eax
810
 
719
 
811
	mov	ecx, PCNET_CSR_CHIPID1
720
	mov	ecx, PCNET_CSR_CHIPID1
812
	call	[ebx + device.access_read_csr]
721
	call	[device.access_read_csr]
Line 813... Line 722...
813
	shl	eax, 16
722
	shl	eax, 16
814
	or	eax, esi
723
	or	eax, esi
815
 
724
 
816
	mov	ecx, eax
725
	mov	ecx, eax
Line 817... Line 726...
817
	and	ecx, 0xfff
726
	and	ecx, 0xfff
818
	cmp	ecx, 3
727
	cmp	ecx, 3
819
	jne	.no_dev
728
	jne	.no_dev
Line 820... Line 729...
820
 
729
 
821
	shr	eax, 12
730
	shr	eax, 12
822
	and	eax, 0xffff
731
	and	eax, 0xffff
823
	mov	[ebx + device.chip_version], eax
732
	mov	[device.chip_version], eax
824
 
733
 
825
	DEBUGF 1,"chip version ok\n"
734
	DEBUGF 1,"chip version ok\n"
Line 826... Line 735...
826
	mov	[ebx + device.fdx], 0
735
	mov	[device.fdx], 0
827
	mov	[ebx + device.mii], 0
736
	mov	[device.mii], 0
828
	mov	[ebx + device.fset], 0
737
	mov	[device.fset], 0
829
	mov	[ebx + device.dxsuflo], 0
738
	mov	[device.dxsuflo], 0
Line 830... Line 739...
830
	mov	[ebx + device.ltint], 0
739
	mov	[device.ltint], 0
Line 831... Line 740...
831
 
740
 
832
	cmp	eax, 0x2420
741
	cmp	eax, 0x2420
833
	je	.L2
742
	je	.L2
834
	cmp	eax, 0x2430
743
	cmp	eax, 0x2430
Line 850... Line 759...
850
	je	.L9
759
	je	.L9
Line 851... Line 760...
851
 
760
 
852
	DEBUGF 1,"Invalid chip rev\n"
761
	DEBUGF 1,"Invalid chip rev\n"
853
	jmp	.no_dev
762
	jmp	.no_dev
854
  .L2:
763
  .L2:
855
	mov	[ebx + device.name], device_l2
764
	mov	[device.name], device_l2
856
	jmp	.L10
765
	jmp	.L10
857
  .L4:
766
  .L4:
858
	mov	[ebx + device.name], device_l4
767
	mov	[device.name], device_l4
859
;        mov     [ebx + device.fdx], 1
768
;        mov     [device.fdx], 1
860
	jmp	.L10
769
	jmp	.L10
861
  .L5:
770
  .L5:
862
	mov	[ebx + device.name], device_l5
771
	mov	[device.name], device_l5
863
;        mov     [ebx + device.fdx], 1
772
;        mov     [device.fdx], 1
864
	mov	[ebx + device.mii], 1
773
	mov	[device.mii], 1
865
	mov	[ebx + device.fset], 1
774
	mov	[device.fset], 1
866
	mov	[ebx + device.ltint], 1
775
	mov	[device.ltint], 1
867
	jmp	.L10
776
	jmp	.L10
868
  .L6:
777
  .L6:
869
	mov	[ebx + device.name], device_l6
778
	mov	[device.name], device_l6
870
;        mov     [ebx + device.fdx], 1
779
;        mov     [device.fdx], 1
871
	mov	[ebx + device.mii], 1
780
	mov	[device.mii], 1
872
	mov	[ebx + device.fset], 1
781
	mov	[device.fset], 1
873
	jmp	.L10
782
	jmp	.L10
874
  .L7:
783
  .L7:
875
	mov	[ebx + device.name], device_l7
784
	mov	[device.name], device_l7
876
;        mov     [ebx + device.fdx], 1
785
;        mov     [device.fdx], 1
877
	mov	[ebx + device.mii], 1
786
	mov	[device.mii], 1
878
	jmp	.L10
787
	jmp	.L10
879
  .L8:
788
  .L8:
880
	mov	[ebx + device.name], device_l8
789
	mov	[device.name], device_l8
881
;        mov     [ebx + device.fdx], 1
790
;        mov     [device.fdx], 1
882
	mov	ecx, PCNET_CSR_RXPOLL
791
	mov	ecx, PCNET_CSR_RXPOLL
883
	call	dword [ebx + device.access_read_bcr]
792
	call	[device.access_read_bcr]
884
	call	dword [ebx + device.access_write_bcr]
793
	call	[device.access_write_bcr]
885
	jmp	.L10
794
	jmp	.L10
886
  .L9:
795
  .L9:
887
	mov	[ebx + device.name], device_l9
796
	mov	[device.name], device_l9
888
;        mov     [ebx + device.fdx], 1
797
;        mov     [device.fdx], 1
889
	mov	[ebx + device.mii], 1
798
	mov	[device.mii], 1
890
  .L10:
799
  .L10:
Line 891... Line 800...
891
	DEBUGF 1,"device name: %s\n",[ebx + device.name]
800
	DEBUGF 1,"device name: %s\n",[device.name]
892
 
801
 
893
	cmp	[ebx + device.fset], 1
802
	cmp	[device.fset], 1
894
	jne	.L11
803
	jne	.L11
895
	mov	ecx, PCNET_BCR_BUSCTL
804
	mov	ecx, PCNET_BCR_BUSCTL
896
	call	[ebx + device.access_read_bcr]
805
	call	[device.access_read_bcr]
Line 897... Line 806...
897
	or	eax, 0x800
806
	or	eax, 0x800
898
	call	[ebx + device.access_write_bcr]
807
	call	[device.access_write_bcr]
899
 
808
 
900
	mov	ecx, PCNET_CSR_DMACTL
809
	mov	ecx, PCNET_CSR_DMACTL
901
	call	[ebx + device.access_read_csr]
810
	call	[device.access_read_csr]
902
;        and     eax, 0xc00
811
;        and     eax, 0xc00
Line 903... Line 812...
903
;        or      eax, 0xc00
812
;        or      eax, 0xc00
904
	mov	eax, 0xc00
813
	mov	eax, 0xc00
905
	call	[ebx + device.access_write_csr]
814
	call	[device.access_write_csr]
Line 906... Line -...
906
 
-
 
907
	mov	[ebx + device.dxsuflo],1
-
 
908
	mov	[ebx + device.ltint],1
-
 
909
  .L11:
-
 
910
 
815
 
911
	push	ebx
816
	mov	[device.dxsuflo],1
912
	call	adjust_pci_device
817
	mov	[device.ltint],1
913
	pop	ebx
818
  .L11:
914
 
819
 
Line 915... Line 820...
915
	DEBUGF 1,"PCI done\n"
820
	DEBUGF 1,"PCI done\n"
916
	mov	eax, PCNET_PORT_ASEL
821
	mov	eax, PCNET_PORT_ASEL
Line 917... Line 822...
917
	mov	[ebx + device.options], eax
822
	mov	[device.options], eax
918
	mov	[ebx + device.mode_], word 0x0003
823
	mov	[device.mode_], word 0x0003
919
	mov	[ebx + device.tlen_rlen], word (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS)
824
	mov	[device.tlen_rlen], word (PCNET_TX_RING_LEN_BITS or PCNET_RX_RING_LEN_BITS)
Line 920... Line -...
920
 
-
 
Line 921... Line -...
921
	mov	dword [ebx + device.filter], 0
-
 
922
	mov	dword [ebx + device.filter+4], 0
-
 
923
 
-
 
Line 924... Line -...
924
	mov	eax, PCNET_IMR
-
 
925
	mov	ecx, PCNET_CSR_IMR			; Write interrupt mask
-
 
926
	call	[ebx + device.access_write_csr]
-
 
927
 
-
 
928
if 0
-
 
929
 
-
 
930
	mov	ecx, PCNET_BCR_SSTYLE		; Select Software style 2       TODO: freebsd driver uses style 3, why?
-
 
931
	mov	eax, 2
-
 
932
	call	[ebx + device.access_write_bcr]
-
 
933
 
-
 
934
 
-
 
935
; ------------ really nescessary??? ----------------
-
 
936
	lea	eax, [ebx + device.private]
-
 
937
	mov	ecx, eax
-
 
938
	and	ecx, 0xFFF ; KolibriOS PAGE SIZE
-
 
939
	call	GetPgAddr
-
 
940
	add	eax, ecx
-
 
941
 
-
 
942
	and	eax, 0xffff
-
 
943
	mov	ecx, PCNET_CSR_IAB0
-
 
944
	call	[ebx + device.access_write_csr]
-
 
945
 
-
 
946
 
-
 
947
	lea	eax, [ebx + device.private]
-
 
948
	mov	ecx, eax
-
 
949
	and	ecx, 0xFFF ; KolibriOS PAGE SIZE
-
 
950
	call	GetPgAddr
-
 
951
	add	eax, ecx
-
 
952
 
-
 
953
	shr	eax,16
-
 
954
	mov	ecx, PCNET_CSR_IAB1
-
 
Line -... Line 825...
-
 
825
 
955
	call	[ebx + device.access_write_csr]
826
	mov	dword [device.filter], 0
Line 956... Line 827...
956
 
827
	mov	dword [device.filter+4], 0
Line 957... Line 828...
957
	mov	ecx, PCNET_CSR_CSR
828
 
958
	mov	eax, 1
829
	mov	eax, PCNET_IMR
959
	call	[ebx + device.access_write_csr]
830
	mov	ecx, PCNET_CSR_IMR			; Write interrupt mask
960
; ------------------------------------------------
831
	call	[device.access_write_csr]
961
end if
832
 
962
 
833
 
963
;       mov     esi, 1
834
 
964
;       call    Sleep
835
 
965
 
836
 
Line -... Line 837...
-
 
837
align 4
-
 
838
reset:
-
 
839
 
-
 
840
; attach int handler
-
 
841
 
-
 
842
	movzx	eax, [device.irq_line]
-
 
843
	DEBUGF	1,"Attaching int handler to irq %x\n",eax:1
966
 
844
	stdcall AttachIntHandler, eax, int_handler, dword 0
-
 
845
	test	eax, eax
967
reset:
846
	jnz	@f
-
 
847
	DEBUGF	1,"\nCould not attach int handler!\n"
-
 
848
;        or      eax, -1
-
 
849
;        ret
-
 
850
  @@:
-
 
851
 
-
 
852
	set_io	0
-
 
853
	call	[device.access_reset]		; after a reset, device will be in WIO mode!
-
 
854
 
-
 
855
; Switch to dword operations
-
 
856
 
-
 
857
	DEBUGF 1,"Switching to 32-bit mode\n"
-
 
858
 
-
 
859
	mov	ecx, PCNET_DWIO_RDP
-
 
860
	mov	eax, 0
-
 
861
	call	wio_write_csr
-
 
862
 
Line 968... Line 863...
968
 
863
	call	switch_to_dwio
969
; attach int handler
-
 
970
 
864
 
971
	movzx	eax, [ebx+device.irq_line]
865
; Lets find out if we are really in 32-bit mode now..
-
 
866
 
-
 
867
	set_io	0
Line 972... Line 868...
972
	DEBUGF	1,"Attaching int handler to irq %x\n",eax:1
868
	set_io	PCNET_DWIO_RAP
973
	stdcall AttachIntHandler, eax, int_handler, dword 0
869
	mov	eax, 88
974
	test	eax, eax
870
	out	dx , eax
975
	jnz	@f
871
	nop
976
	DEBUGF	1,"\nCould not attach int handler!\n"
872
	nop
977
;        or      eax, -1
873
	in	eax, dx
978
;        ret
874
	set_io	0
979
  @@:
875
	and	eax, 0xffff
980
 
876
	cmp	eax, 88
Line 981... Line 877...
981
	mov	edx, [ebx + device.io_addr]
877
	je	.yes_dwio
982
	call	[ebx + device.access_reset]
878
 
983
 
879
	call	switch_to_wio			; it seem to have failed, reset device again and use wio
984
	; Switch pcnet32 to 32bit mode
880
	set_io	0
985
	mov	ecx, PCNET_BCR_SSTYLE
881
	call	[device.access_reset]
986
	mov	eax, 2
882
 
987
	call	[ebx + device.access_write_bcr]
883
  .yes_dwio:
988
 
884
 
989
	; set/reset autoselect bit
885
	; set/reset autoselect bit
990
	mov	ecx, PCNET_BCR_MISCCFG
886
	mov	ecx, PCNET_BCR_MISCCFG
991
	call	[ebx + device.access_read_bcr]
887
	call	[device.access_read_bcr]
992
	and	eax,not 2
888
	and	eax,not 2
993
	test	[ebx + device.options], PCNET_PORT_ASEL
889
	test	[device.options], PCNET_PORT_ASEL
994
	jz	.L1
890
	jz	.L1
995
	or	eax, 2
891
	or	eax, 2
996
  .L1:
892
  .L1:
997
	call	[ebx + device.access_write_bcr]
893
	call	[device.access_write_bcr]
998
 
894
 
999
 
895
 
1000
	; Handle full duplex setting
896
	; Handle full duplex setting
1001
	cmp	byte [ebx + device.full_duplex], 0
897
	cmp	byte [device.full_duplex], 0
1002
	je	.L2
898
	je	.L2
1003
	mov	ecx, PCNET_BCR_DUPLEX
899
	mov	ecx, PCNET_BCR_DUPLEX
Line 1004... Line 900...
1004
	call	[ebx + device.access_read_bcr]
900
	call	[device.access_read_bcr]
1005
	and	eax, not 3
901
	and	eax, not 3
1006
	test	[ebx + device.options], PCNET_PORT_FD
902
	test	[device.options], PCNET_PORT_FD
1007
	jz	.L3
903
	jz	.L3
1008
	or	eax, 1
904
	or	eax, 1
1009
	cmp	[ebx + device.options], PCNET_PORT_FD or PCNET_PORT_AUI
905
	cmp	[device.options], PCNET_PORT_FD or PCNET_PORT_AUI
1010
	jne	.L4
906
	jne	.L4
1011
	or	eax, 2
907
	or	eax, 2
1012
	jmp	.L4
908
	jmp	.L4
1013
  .L3:
909
  .L3:
1014
	test	[ebx + device.options], PCNET_PORT_ASEL
910
	test	[device.options], PCNET_PORT_ASEL
1015
	jz	.L4
911
	jz	.L4
1016
	cmp	[ebx + device.chip_version], 0x2627
912
	cmp	[device.chip_version], 0x2627
1017
	jne	.L4
913
	jne	.L4
1018
	or	eax, 3
914
	or	eax, 3
1019
  .L4:
915
  .L4:
1020
	mov	ecx, PCNET_BCR_DUPLEX
916
	mov	ecx, PCNET_BCR_DUPLEX
1021
	call	[ebx + device.access_write_bcr]
917
	call	[device.access_write_bcr]
1022
  .L2:
918
  .L2:
1023
 
919
 
1024
 
920
 
1025
	; set/reset GPSI bit in test register
921
	; set/reset GPSI bit in test register
1026
	mov	ecx, 124
922
	mov	ecx, 124
1027
	call	[ebx + device.access_read_csr]
923
	call	[device.access_read_csr]
1028
	mov	ecx, [ebx + device.options]
924
	mov	ecx, [device.options]
1029
	and	ecx, PCNET_PORT_PORTSEL
925
	and	ecx, PCNET_PORT_PORTSEL
1030
	cmp	ecx, PCNET_PORT_GPSI
926
	cmp	ecx, PCNET_PORT_GPSI
1031
	jne	.L5
927
	jne	.L5
1032
	or	eax, 0x10
928
	or	eax, 0x10
1033
  .L5:
929
  .L5:
1034
	call	[ebx + device.access_write_csr]
930
	call	[device.access_write_csr]
1035
	cmp	[ebx + device.mii], 0
931
	cmp	[device.mii], 0
1036
	je	.L6
932
	je	.L6
1037
	test	[ebx + device.options], PCNET_PORT_ASEL
933
	test	[device.options], PCNET_PORT_ASEL
1038
	jnz	.L6
934
	jnz	.L6
1039
	mov	ecx, PCNET_BCR_MIICTL
935
	mov	ecx, PCNET_BCR_MIICTL
1040
	call	[ebx + device.access_read_bcr]
936
	call	[device.access_read_bcr]
1041
	and	eax,not 0x38
937
	and	eax,not 0x38
1042
	test	[ebx + device.options], PCNET_PORT_FD
938
	test	[device.options], PCNET_PORT_FD
1043
	jz	.L7
939
	jz	.L7
1044
	or	eax, 0x10
940
	or	eax, 0x10
1045
  .L7:
941
  .L7:
1046
	test	[ebx + device.options], PCNET_PORT_100
942
	test	[device.options], PCNET_PORT_100
1047
	jz	.L8
943
	jz	.L8
1048
	or	eax, 0x08
944
	or	eax, 0x08
1049
  .L8:
945
  .L8:
1050
	call	[ebx + device.access_write_bcr]
946
	call	[device.access_write_bcr]
1051
	jmp	.L9
947
	jmp	.L9
1052
.L6:
948
.L6:
1053
	test	[ebx + device.options], PCNET_PORT_ASEL
949
	test	[device.options], PCNET_PORT_ASEL
Line 1054... Line 950...
1054
	jz	.L9
950
	jz	.L9
Line 1055... Line 951...
1055
	mov	ecx, PCNET_BCR_MIICTL
951
	mov	ecx, PCNET_BCR_MIICTL
1056
	DEBUGF 1,"ASEL, enable auto-negotiation\n"
952
	DEBUGF 1,"ASEL, enable auto-negotiation\n"
1057
	call	[ebx + device.access_read_bcr]
953
	call	[device.access_read_bcr]
1058
	and	eax, not 0x98
954
	and	eax, not 0x98
Line 1059... Line 955...
1059
	or	eax, 0x20
955
	or	eax, 0x20
1060
	call	[ebx + device.access_write_bcr]
956
	call	[device.access_write_bcr]
1061
.L9:
957
.L9:
1062
	cmp	[ebx + device.ltint],0
958
	cmp	[device.ltint],0
1063
	je	.L10
959
	je	.L10
Line 1064... Line 960...
1064
	mov	ecx,5
960
	mov	ecx,5
1065
	call	[ebx + device.access_read_csr]
961
	call	[device.access_read_csr]
1066
	or	eax,(1 shl 14)
962
	or	eax,(1 shl 14)
1067
	call	[ebx + device.access_write_csr]
963
	call	[device.access_write_csr]
1068
.L10:
964
.L10:
1069
	mov	eax,[ebx  + device.options]
965
	mov	eax, [device.options]
1070
	and	eax,PCNET_PORT_PORTSEL
966
	and	eax, PCNET_PORT_PORTSEL
1071
	shl	eax,7
967
	shl	eax, 7
Line 1072... Line 968...
1072
	mov	[ebx + device.mode_],ax
968
	mov	[device.mode_], ax
1073
	mov	dword [ebx + device.filter], -1
969
	mov	dword [device.filter], -1
1074
	mov	dword [ebx + device.filter+4], -1
970
	mov	dword [device.filter+4], -1
Line 1075... Line 971...
1075
 
971
 
1076
	call	read_mac
972
	call	read_mac
1077
 
973
 
Line 1078... Line 974...
1078
	lea	esi, [ebx + device.mac]
974
	lea	esi, [device.mac]
1079
	lea	edi, [ebx + device.phys_addr]
975
	lea	edi, [device.phys_addr]
1080
	movsd
976
	movsd
1081
	movsw
977
	movsw
1082
 
978
 
Line 1083... Line 979...
1083
	lea	eax, [ebx + device.private]
979
	lea	eax, [device.private]
1084
	mov	ecx, eax
980
	mov	ecx, eax
1085
	and	ecx, 0xFFF ; KolibriOS PAGE SIZE
981
	and	ecx, 0xFFF ; KolibriOS PAGE SIZE
1086
	call	GetPgAddr
982
	call	GetPgAddr
1087
	add	eax, ecx
983
	add	eax, ecx
1088
 
984
 
1089
	push	eax
985
	push	eax
1090
	and	eax, 0xffff
986
	and	eax, 0xffff
1091
	mov	ecx, 1
987
	mov	ecx, 1
1092
	call	[ebx + device.access_write_csr]
988
	call	[device.access_write_csr]
Line 1093... Line 989...
1093
	pop	eax
989
	pop	eax
1094
	shr	eax,16
990
	shr	eax,16
1095
	mov	ecx,2
991
	mov	ecx,2
1096
	call	[ebx + device.access_write_csr]
992
	call	[device.access_write_csr]
Line 1097... Line 993...
1097
 
993
 
1098
	mov	ecx,4
994
	mov	ecx,4
Line 1099... Line 995...
1099
	mov	eax,0x0915
995
	mov	eax,0x0915
1100
	call	[ebx + device.access_write_csr]
996
	call	[device.access_write_csr]
1101
 
997
 
Line 1102... Line 998...
1102
	mov	ecx,0
998
	mov	ecx,0
1103
	mov	eax,1
999
	mov	eax,1
-
 
1000
	call	[device.access_write_csr]
-
 
1001
 
-
 
1002
	mov	[device.tx_full],0
-
 
1003
	mov	[device.cur_rx],0
-
 
1004
	mov	[device.cur_tx],0
1104
	call	[ebx + device.access_write_csr]
1005
	mov	[device.dirty_rx],0
Line 1162... Line 1063...
1162
	jg	.finish 			; packet is too long
1063
	jg	.finish 			; packet is too long
1163
	cmp	dword [esp+8], 60
1064
	cmp	dword [esp+8], 60
1164
	jl	.finish 			; packet is too short
1065
	jl	.finish 			; packet is too short
Line 1165... Line 1066...
1165
 
1066
 
1166
; check descriptor
1067
; check descriptor
1167
	movzx	eax, [ebx + device.cur_tx]
1068
	movzx	eax, [device.cur_tx]
1168
	imul	edi, eax, PCNET_PKT_BUF_SZ
1069
	imul	edi, eax, PCNET_PKT_BUF_SZ
1169
	shl	eax, 4
1070
	shl	eax, 4
1170
	add	edi, [ebx + device.tx_buffer]
1071
	add	edi, [device.tx_buffer]
1171
	add	eax, [ebx + device.tx_ring]
1072
	add	eax, [device.tx_ring]
1172
	test	byte [eax + buf_head.status + 1], 80h
1073
	test	byte [eax + buf_head.status + 1], 80h
1173
	jnz	.nospace
1074
	jnz	.nospace
1174
; descriptor is free, copy data
1075
; descriptor is free, copy data
1175
	mov	esi, [esp+4]
1076
	mov	esi, [esp+4]
Line 1187... Line 1088...
1187
; put to transfer queue
1088
; put to transfer queue
1188
	mov	[eax + buf_head.status], 0x8300
1089
	mov	[eax + buf_head.status], 0x8300
Line 1189... Line 1090...
1189
 
1090
 
1190
; trigger an immediate send
1091
; trigger an immediate send
1191
	xor	ecx, ecx	 ; CSR0
1092
	xor	ecx, ecx	 ; CSR0
1192
	call	[ebx + device.access_read_csr]
1093
	call	[device.access_read_csr]
1193
	or	eax, PCNET_CSR_TX
1094
	or	eax, PCNET_CSR_TX
Line 1194... Line 1095...
1194
	call	[ebx + device.access_write_csr]
1095
	call	[device.access_write_csr]
1195
 
1096
 
1196
; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...
1097
; get next descriptor 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...
1197
	inc	[ebx + device.cur_tx]
1098
	inc	[device.cur_tx]
Line 1198... Line 1099...
1198
	and	[ebx + device.cur_tx], 3
1099
	and	[device.cur_tx], 3
-
 
1100
	DEBUGF	2," - Packet Sent! "
-
 
1101
 
-
 
1102
.finish:
-
 
1103
; update statistics
-
 
1104
	inc	[device.packets_tx]
-
 
1105
 
1199
	DEBUGF	2," - Packet Sent! "
1106
	mov	ecx, [esp+8]
1200
 
1107
	add	dword [device.bytes_tx], ecx
Line 1201... Line 1108...
1201
.finish:
1108
	adc	dword [device.bytes_tx + 4], 0
1202
	DEBUGF	2," - Done!\n"
1109
	DEBUGF	2," - Done!\n"
Line 1216... Line 1123...
1216
;;;;;;;;;;;;;;;;;;;;;;;
1123
;;;;;;;;;;;;;;;;;;;;;;;
Line 1217... Line 1124...
1217
 
1124
 
1218
align 4
1125
align 4
Line 1219... Line 1126...
1219
int_handler:
1126
int_handler:
Line 1220... Line 1127...
1220
 
1127
 
Line 1221... Line 1128...
1221
;       DEBUGF  1,"IRQ %x ",eax:2                   ; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
1128
	DEBUGF	1,"IRQ %x ", eax:2		; no, you cant replace 'eax:2' with 'al', this must be a bug in FDO
1222
 
1129
 
1223
; find pointer of device wich made IRQ occur
1130
; find pointer of device wich made IRQ occur
1224
 
1131
 
1225
	mov	esi, PCNET_LIST
1132
	mov	esi, PCNET_LIST
1226
	mov	ecx, [PCNET_DEV]
1133
	mov	ecx, [PCNET_DEV]
1227
	test	ecx, ecx
1134
	test	ecx, ecx
-
 
1135
	jz	.abort
Line 1228... Line 1136...
1228
	jz	.abort
1136
  .nextdevice:
1229
  .nextdevice:
1137
	mov	ebx, [esi]
1230
	mov	ebx, dword [esi]
1138
	DEBUGF	1,"device=%x? ", ebx
1231
	mov	edx, [ebx + device.io_addr]	; get IRQ reason
1139
	set_io	0
Line 1232... Line 1140...
1232
 
1140
 
1233
	push	ecx
1141
	push	ecx
Line 1234... Line 1142...
1234
	xor	ecx, ecx ; CSR0
1142
	xor	ecx, ecx ; CSR0
1235
	call	[ebx + device.access_read_csr]
1143
	call	[device.access_read_csr]       ; get IRQ reason
Line 1236... Line 1144...
1236
	pop	ecx
1144
	pop	ecx
Line 1237... Line 1145...
1237
 
1145
 
-
 
1146
	test	ax , ax
1238
	test	al , al
1147
	jnz	.got_it
1239
	js	.got_it
1148
 
1240
 
1149
	add	esi, 4
1241
	add	esi, 4
1150
	loop	.nextdevice
1242
	loop	.nextdevice
1151
 
1243
 
1152
	ret					; If no device was found, abort (The irq was probably for a device, not registered to this driver
1244
	ret					    ; If no device was found, abort (The irq was probably for a device, not registered to this driver
1153
 
1245
 
1154
  .got_it:
1246
  .got_it:
1155
	DEBUGF	1,"yes, reason=%x ", ax
1247
;-------------------------------------------------------
1156
;-------------------------------------------------------
1248
; Possible reasons:
1157
; Possible reasons:
Line 1249... Line 1158...
1249
; initialization done - ignore
1158
; initialization done - ignore
1250
; transmit done - ignore
1159
; transmit done - ignore
Line 1251... Line 1160...
1251
; packet received - handle
1160
; packet received - handle
1252
; Clear ALL IRQ reasons.
1161
; Clear ALL IRQ reasons.
1253
; N.B. One who wants to handle more than one reason must be ready
1162
; N.B. One who wants to handle more than one reason must be ready
1254
; to two or more reasons in one IRQ.
1163
; to two or more reasons in one IRQ.
Line 1255... Line 1164...
1255
	xor	ecx, ecx
1164
	xor	ecx, ecx
1256
	call	[ebx + device.access_write_csr]
1165
	call	[device.access_write_csr]
Line 1257... Line 1166...
1257
; Received packet ok?
1166
; Received packet ok?
1258
 
1167
 
Line 1259... Line 1168...
1259
	test	ax, PCNET_CSR_RINT
1168
	test	ax, PCNET_CSR_RINT
Line 1260... Line 1169...
1260
	jz	@f
1169
	jz	@f
1261
 
1170
 
Line 1292... Line 1201...
1292
 
1201
 
1293
	push	.receiver_test_loop		;
1202
	push	.receiver_test_loop		;
1294
	push	ecx				; for eth_receiver
1203
	push	ecx				; for eth_receiver
Line -... Line 1204...
-
 
1204
	push	eax				;
-
 
1205
 
-
 
1206
; update statistics
-
 
1207
	inc	[device.packets_rx]
-
 
1208
 
-
 
1209
	add	dword [device.bytes_rx], ecx
1295
	push	eax				;
1210
	adc	dword [device.bytes_rx + 4], 0
-
 
1211
 
-
 
1212
	xchg	edi, eax
-
 
1213
 
1296
 
1214
; copy packet data
-
 
1215
	shr	cx , 1
-
 
1216
	jnc	.nb
1297
	xchg	edi, eax
1217
	movsb
-
 
1218
  .nb:
1298
	push	ecx
1219
	shr	cx , 1
-
 
1220
	jnc	.nw
1299
	shr	ecx, 2
1221
	movsw
1300
	cld
-
 
1301
	rep	movsd
-
 
1302
	pop	ecx
-
 
Line 1303... Line 1222...
1303
	and	ecx, 3
1222
  .nw:
1304
	rep	movsb
1223
	rep	movsd
Line 1305... Line 1224...
1305
 
1224
 
1306
;       mov     word [eax + buf_head.length], PCNET_PKT_BUF_SZ_NEG
1225
;       mov     word [eax + buf_head.length], PCNET_PKT_BUF_SZ_NEG
Line -... Line 1226...
-
 
1226
	mov	word [eax + buf_head.status], PCNET_RXSTAT_OWN	    ; Set OWN bit back to 1 (controller may write to tx-buffer again now)
1307
	mov	word [eax + buf_head.status], PCNET_RXSTAT_OWN	    ; Set OWN bit back to 1 (controller may write to tx-buffer again now)
1227
 
Line 1308... Line 1228...
1308
 
1228
	inc	[device.cur_rx] 	  ; update descriptor
1309
	inc	[ebx + device.cur_rx]		; update descriptor
-
 
-
 
1229
	and	[device.cur_rx], 3	  ;
1310
	and	[ebx + device.cur_rx], 3	;
1230
 
Line 1311... Line 1231...
1311
 
1231
	DEBUGF	1,"Inserting packet\n"
Line 1329... Line 1249...
1329
align 4
1249
align 4
1330
write_mac:	; in: mac pushed onto stack (as 3 words)
1250
write_mac:	; in: mac pushed onto stack (as 3 words)
Line 1331... Line 1251...
1331
 
1251
 
Line 1332... Line 1252...
1332
	DEBUGF	1,"Writing MAC: %x-%x-%x-%x-%x-%x",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2
1252
	DEBUGF	1,"Writing MAC: %x-%x-%x-%x-%x-%x",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2
1333
 
1253
 
1334
	mov	edx, [ebx + device.io_addr]
1254
	mov	edx, [device.io_addr]
Line 1335... Line 1255...
1335
	add	dx, 2
1255
	add	edx, 2
1336
	xor	eax, eax
1256
	xor	eax, eax
1337
 
1257
 
1338
	mov	ecx, PCNET_CSR_PAR0
1258
	mov	ecx, PCNET_CSR_PAR0
1339
       @@:
1259
       @@:
1340
	pop	ax
1260
	pop	ax
1341
	call	[ebx + device.access_write_csr]
1261
	call	[device.access_write_csr]
1342
	DEBUGF	1,"."
1262
	DEBUGF	1,"."
Line 1352... Line 1272...
1352
;;                  ;;
1272
;;                  ;;
1353
;; Read MAC address ;;
1273
;; Read MAC address ;;
1354
;;                  ;;
1274
;;                  ;;
1355
;;;;;;;;;;;;;;;;;;;;;;
1275
;;;;;;;;;;;;;;;;;;;;;;
Line 1356... Line 1276...
1356
 
1276
 
1357
read_mac:				; T- OK
1277
read_mac:
Line 1358... Line 1278...
1358
	DEBUGF	1,"Reading MAC"
1278
	DEBUGF	1,"Reading MAC"
1359
 
1279
 
1360
	mov	edx, [ebx + device.io_addr]
1280
	mov	edx, [device.io_addr]
1361
	add	dx, 6
1281
	add	edx, 6
1362
       @@:
1282
       @@:
1363
	dec	dx
1283
	dec	dx
1364
	dec	dx
1284
	dec	dx
1365
	in	ax, dx
1285
	in	ax, dx
1366
	push	ax
1286
	push	ax
1367
	DEBUGF	1,"."
1287
	DEBUGF	1,"."
Line 1368... Line 1288...
1368
	cmp	edx, [ebx + device.io_addr]
1288
	cmp	edx, [device.io_addr]
Line 1369... Line 1289...
1369
	jg	@r
1289
	jg	@r
1370
 
1290
 
1371
	DEBUGF	1," %x-%x-%x-%x-%x-%x\n",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2
1291
	DEBUGF	1," %x-%x-%x-%x-%x-%x\n",[esp+0]:2,[esp+1]:2,[esp+2]:2,[esp+3]:2,[esp+4]:2,[esp+5]:2
1372
 
1292
 
1373
	lea	edi, [ebx + device.mac]
1293
	lea	edi, [device.mac]
1374
	pop	ax
1294
	pop	ax
Line 1380... Line 1300...
1380
 
1300
 
Line 1381... Line 1301...
1381
	ret
1301
	ret
-
 
1302
 
Line 1382... Line 1303...
1382
 
1303
 
1383
 
1304
switch_to_wio:
1384
switch_to_wio:
1305
	DEBUGF	1,"Switch to WIO\n"
1385
 
1306
 
1386
	mov	[ebx + device.access_read_csr], wio_read_csr
1307
	mov	[device.access_read_csr], wio_read_csr
1387
	mov	[ebx + device.access_write_csr], wio_write_csr
1308
	mov	[device.access_write_csr], wio_write_csr
1388
	mov	[ebx + device.access_read_bcr], wio_read_bcr
1309
	mov	[device.access_read_bcr], wio_read_bcr
Line 1389... Line 1310...
1389
	mov	[ebx + device.access_write_bcr], wio_write_bcr
1310
	mov	[device.access_write_bcr], wio_write_bcr
Line 1390... Line 1311...
1390
	mov	[ebx + device.access_read_rap], wio_read_rap
1311
	mov	[device.access_read_rap], wio_read_rap
-
 
1312
	mov	[device.access_write_rap], wio_write_rap
Line 1391... Line 1313...
1391
	mov	[ebx + device.access_write_rap], wio_write_rap
1313
	mov	[device.access_reset], wio_reset
1392
	mov	[ebx + device.access_reset], wio_reset
1314
 
1393
 
1315
	ret
1394
	ret
1316
 
1395
 
1317
switch_to_dwio:
1396
switch_to_dwio:
1318
	DEBUGF	1,"Switch to DWIO\n"
1397
 
1319
 
Line 1398... Line 1320...
1398
	mov	[ebx + device.access_read_csr], dwio_read_csr
1320
	mov	[device.access_read_csr], dwio_read_csr
Line 1487... Line 1409...
1487
	out	dx , ax
1409
	out	dx , ax
1488
	sub	edx, PCNET_WIO_RAP
1410
	sub	edx, PCNET_WIO_RAP
Line 1489... Line 1411...
1489
 
1411
 
Line 1490... Line -...
1490
	ret
-
 
1491
 
1412
	ret
Line 1492... Line 1413...
1492
 
1413
 
1493
wio_reset:
1414
wio_reset:
1494
 
1415
 
Line 1499... Line 1420...
1499
	sub	edx, PCNET_WIO_RESET
1420
	sub	edx, PCNET_WIO_RESET
Line 1500... Line 1421...
1500
 
1421
 
Line 1501... Line -...
1501
	ret
-
 
1502
 
1422
	ret
1503
 
1423
 
1504
 
1424
 
1505
; ecx - index
1425
; ecx - index
Line 1593... Line 1513...
1593
 
1513
 
Line 1594... Line -...
1594
	ret
-
 
1595
 
-
 
1596
 
-
 
1597
 
-
 
1598
adjust_pci_device:
-
 
1599
	;*******Get current setting************************
-
 
1600
	movzx	 edx, byte [ebx + device.pci_dev]
-
 
1601
	movzx	 ecx, byte [ebx + device.pci_bus]
-
 
1602
	push	ecx edx
-
 
1603
	stdcall  PciRead16, ecx ,edx ,0x04
-
 
1604
	pop	edx ecx
-
 
1605
;        ;******see if its already set as bus master********
-
 
1606
;        and      ax,5
-
 
1607
;        cmp      ax,5
-
 
1608
;        je       .Latency
-
 
1609
	;******Make card a bus master*******
-
 
1610
	or	 al, 5
-
 
1611
	stdcall  PciWrite16, ecx ,edx ,0x04, eax
-
 
1612
	;******Check latency setting***********
-
 
1613
  .Latency:
-
 
1614
   ;*******Get current latency setting************************
-
 
1615
;   mov     al, 1                                       ;read a byte
-
 
1616
;   mov     bh, [pci_dev]
-
 
1617
;   mov     ah, [pci_bus]
-
 
1618
;   mov     bl, 0x0D                                ;from Lantency Timer Register
-
 
1619
;   call    pci_read_reg
-
 
1620
   ;******see if its aat least 64 clocks********
-
 
1621
;   cmp      ax,64
-
 
1622
;   jge      PCNET_adjust_pci_device_Done
-
 
1623
   ;******Set latency to 32 clocks*******
-
 
1624
;   mov     cx, 64                              ;value to write
-
 
1625
;   mov     bh, [pci_dev]
-
 
1626
;   mov     al, 1                               ;write a byte
-
 
1627
;   mov     ah, [pci_bus]
-
 
1628
;   mov     bl, 0x0D                            ;to Lantency Timer Register
-
 
1629
;   call    pci_write_reg
-
 
1630
   ;******Check latency setting***********
-
 
1631
  .Done:
-
 
1632
	ret
-
 
1633
 
1514
	ret
Line 1634... Line 1515...
1634
 
1515
 
Line 1635... Line 1516...
1635
 
1516