Subversion Repositories Kolibri OS

Rev

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

Rev 1556 Rev 1557
Line 234... Line 234...
234
 
234
 
235
PCFG_METHOD_1	    equ 0x01	; PHY Reg 0x03 bit0-3 == 0x0000
235
PCFG_METHOD_1	    equ 0x01	; PHY Reg 0x03 bit0-3 == 0x0000
236
PCFG_METHOD_2	    equ 0x02	; PHY Reg 0x03 bit0-3 == 0x0001
236
PCFG_METHOD_2	    equ 0x02	; PHY Reg 0x03 bit0-3 == 0x0001
Line 237... Line -...
237
PCFG_METHOD_3	    equ 0x03	; PHY Reg 0x03 bit0-3 == 0x0002
-
 
238
 
-
 
239
PCI_COMMAND_IO		equ 0x1   ; Enable response in I/O space
-
 
240
PCI_COMMAND_MEM 	equ 0x2   ; Enable response in mem space
-
 
241
PCI_COMMAND_MASTER	equ 0x4   ; Enable bus mastering
-
 
242
PCI_LATENCY_TIMER	equ 0x0d  ; 8 bits
-
 
243
PCI_COMMAND_SPECIAL	equ 0x8   ; Enable response to special cycles
-
 
244
PCI_COMMAND_INVALIDATE	equ 0x10  ; Use memory write and invalidate
-
 
245
PCI_COMMAND_VGA_PALETTE equ 0x20  ; Enable palette snooping
-
 
246
PCI_COMMAND_PARITY	equ 0x40  ; Enable parity checking
-
 
247
PCI_COMMAND_WAIT	equ 0x80  ; Enable address/data stepping
-
 
248
PCI_COMMAND_SERR	equ 0x100 ; Enable SERR
-
 
249
PCI_COMMAND_FAST_BACK	equ 0x200 ; Enable back-to-back writes
237
PCFG_METHOD_3	    equ 0x03	; PHY Reg 0x03 bit0-3 == 0x0002
250
 
238
 
251
virtual at 0
239
virtual at 0
252
  tx_desc:
240
  tx_desc:
253
  .status    dd ?
241
  .status    dd ?
254
  .vlan_tag  dd ?
-
 
255
  .buf_addr  dd ?
242
  .vlan_tag  dd ?
-
 
243
  .buf_addr  dq ?
-
 
244
  .size = $
256
  .buf_Haddr dd ?
245
  rb	(NUM_TX_DESC-1)*tx_desc.size
Line 257... Line 246...
257
  .size = $
246
  .buf_soft_addr	dd ?
258
end virtual
247
end virtual
259
 
248
 
260
virtual at 0
249
virtual at 0
261
  rx_desc:
250
  rx_desc:
262
  .status    dd ?
-
 
263
  .vlan_tag  dd ?
251
  .status    dd ?
-
 
252
  .vlan_tag  dd ?
-
 
253
  .buf_addr  dq ?
264
  .buf_addr  dd ?
254
  .size = $
Line 265... Line 255...
265
  .buf_Haddr dd ?
255
  rb	(NUM_RX_DESC-1)*rx_desc.size
Line 266... Line 256...
266
  .size = $
256
  .buf_soft_addr	dd ?
Line 287... Line 277...
287
	.TxDescArrays	dd ? ; Index of Tx Descriptor buffer
277
	.TxDescArrays	dd ? ; Index of Tx Descriptor buffer
288
	.RxDescArrays	dd ? ; Index of Rx Descriptor buffer
278
	.RxDescArrays	dd ? ; Index of Rx Descriptor buffer
289
	.TxDescArray	dd ? ; Index of 256-alignment Tx Descriptor buffer
279
	.TxDescArray	dd ? ; Index of 256-alignment Tx Descriptor buffer
290
	.RxDescArray	dd ? ; Index of 256-alignment Rx Descriptor buffer
280
	.RxDescArray	dd ? ; Index of 256-alignment Rx Descriptor buffer
Line 291... Line 281...
291
 
281
 
292
	rb 255-(($ - ebx) and 255)		;        align 256
282
	rb 256-(($ - device) and 255)		   ;        align 256
Line 293... Line 283...
293
	tx_ring rb NUM_TX_DESC * tx_desc.size
283
	tx_ring rb NUM_TX_DESC * tx_desc.size * 2
294
 
284
 
Line 295... Line 285...
295
	rb 255-(($ - ebx) and 255)		;        align 256
285
	rb 256-(($ - device) and 255)		   ;        align 256
Line 296... Line 286...
296
	rx_ring rb NUM_RX_DESC * rx_desc.size
286
	rx_ring rb NUM_RX_DESC * rx_desc.size * 2
Line 328... Line 318...
328
 
318
 
Line 329... Line 319...
329
macro	READ_GMII_REG  RegAddr {
319
macro	READ_GMII_REG  RegAddr {
Line 330... Line -...
330
 
-
 
331
local	.error, .done
320
 
-
 
321
local	.error, .done
332
 
322
 
Line 333... Line 323...
333
	mov	eax, RegAddr shl 16
323
	set_io	REG_PHYAR
334
	set_io	REG_PHYAR
324
	mov	eax, RegAddr shl 16
Line 335... Line -...
335
	in	eax, dx
-
 
336
 
325
	out	dx, eax
337
	call	PHY_WAIT
326
 
338
	jz	.error
327
	call	PHY_WAIT
Line 339... Line 328...
339
 
328
	jz	.error
Line 352... Line 341...
352
 
341
 
Line 353... Line 342...
353
	udelay	1	 ;;;1000
342
	udelay	1	 ;;;1000
354
 
343
 
355
	push	ecx
344
	push	ecx
356
	mov	ecx, 2000
345
	mov	ecx, 2000
357
	; Check if the RTL8169 has completed writing to the specified MII register
346
	; Check if the RTL8169 has completed writing/reading to the specified MII register
358
    @@:
347
    @@:
359
	in	eax, dx
348
	in	eax, dx
360
	test	eax, 0x80000000
349
	test	eax, 0x80000000
Line 454... Line 443...
454
; This device doesnt have its own eth_device structure yet, lets create one
443
; This device doesnt have its own eth_device structure yet, lets create one
455
  .firstdevice:
444
  .firstdevice:
456
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
445
	cmp	[devices], MAX_DEVICES			; First check if the driver can handle one more card
457
	jge	.fail
446
	jge	.fail
Line 458... Line -...
458
 
-
 
459
	push	edx
447
 
460
	stdcall KernelAlloc, device_size		; Allocate the buffer for eth_device structure
-
 
461
	pop	edx
-
 
462
	test	eax, eax
-
 
463
	jz	.fail
-
 
Line 464... Line 448...
464
	mov	ebx, eax				; ebx is always used as a pointer to the structure (in driver, but also in kernel code)
448
	allocate_and_clear ebx, device_size, .fail	; Allocate memory to put the device structure in
Line 465... Line 449...
465
 
449
 
466
; Fill in the direct call addresses into the struct
450
; Fill in the direct call addresses into the struct
Line 687... Line 671...
687
	udelay	100
671
	udelay	100
688
	mov	ecx, 10000
672
	mov	ecx, 10000
689
	; wait for auto-negotiation process
673
	; wait for auto-negotiation process
690
    @@: dec	ecx
674
    @@: dec	ecx
691
	jz	@f
675
	jz	@f
-
 
676
	set_io	0
692
	READ_GMII_REG PHY_STAT_REG
677
	READ_GMII_REG PHY_STAT_REG
693
	udelay	100
678
	udelay	100
694
	test	eax, PHY_Auto_Neco_Comp
679
	test	eax, PHY_Auto_Neco_Comp
695
	jz	@b
680
	jz	@b
696
	set_io	0
-
 
697
	set_io	REG_PHYstatus
681
	set_io	REG_PHYstatus
698
	in	al, dx
682
	in	al, dx
699
	jmp	@f
683
	jmp	@f
700
  .tbi_dis:
684
  .tbi_dis:
701
	udelay	100
685
	udelay	100
Line 728... Line 712...
728
	call	hw_start
712
	call	hw_start
Line 729... Line 713...
729
 
713
 
Line 730... Line 714...
730
	mov	[device.mtu], 1500
714
	mov	[device.mtu], 1500
731
 
-
 
732
	xor	eax, eax
715
 
Line 742... Line 725...
742
 
725
 
Line 743... Line 726...
743
	DEBUGF	1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[tpc.mcfg],[tpc.pcfg]
726
	DEBUGF	1,"hw_PHY_config: priv.mcfg=%d, priv.pcfg=%d\n",[tpc.mcfg],[tpc.pcfg]
744
 
727
 
-
 
728
	cmp	[tpc.mcfg], MCFG_METHOD_04
745
	cmp	[tpc.mcfg], MCFG_METHOD_04
729
	jne	.not_4
746
	jne	.not_4
730
	set_io	0
747
;       WRITE_GMII_REG 0x1F, 0x0001
731
;       WRITE_GMII_REG 0x1F, 0x0001
748
;       WRITE_GMII_REG 0x1b, 0x841e
732
;       WRITE_GMII_REG 0x1b, 0x841e
749
;       WRITE_GMII_REG 0x0e, 0x7bfb
733
;       WRITE_GMII_REG 0x0e, 0x7bfb
Line 755... Line 739...
755
  .not_4:
739
  .not_4:
756
	cmp	[tpc.mcfg], MCFG_METHOD_02
740
	cmp	[tpc.mcfg], MCFG_METHOD_02
757
	je	@f
741
	je	@f
758
	cmp	[tpc.mcfg], MCFG_METHOD_03
742
	cmp	[tpc.mcfg], MCFG_METHOD_03
759
	jne	.not_2_or_3
743
	jne	.not_2_or_3
-
 
744
    @@:
-
 
745
	set_io	0
760
    @@: WRITE_GMII_REG 0x1F, 0x0001
746
	WRITE_GMII_REG 0x1F, 0x0001
761
	WRITE_GMII_REG 0x15, 0x1000
747
	WRITE_GMII_REG 0x15, 0x1000
762
	WRITE_GMII_REG 0x18, 0x65C7
748
	WRITE_GMII_REG 0x18, 0x65C7
763
	WRITE_GMII_REG 0x04, 0x0000
749
	WRITE_GMII_REG 0x04, 0x0000
764
	WRITE_GMII_REG 0x03, 0x00A1
750
	WRITE_GMII_REG 0x03, 0x00A1
765
	WRITE_GMII_REG 0x02, 0x0008
751
	WRITE_GMII_REG 0x02, 0x0008
Line 848... Line 834...
848
	mov	ecx, (NUM_RX_DESC * rx_desc.size) / 4
834
	mov	ecx, (NUM_RX_DESC * rx_desc.size) / 4
849
	rep	stosd
835
	rep	stosd
Line 850... Line 836...
850
 
836
 
851
	mov	edi, [tpc.RxDescArray]
837
	mov	edi, [tpc.RxDescArray]
852
	mov	ecx, NUM_RX_DESC
838
	mov	ecx, NUM_RX_DESC
-
 
839
  .loop:
853
    @@:
840
	push	ecx
854
	stdcall KernelAlloc, 2048
841
	stdcall KernelAlloc, RX_BUF_SIZE
855
	mov	[edi + rx_desc.buf_Haddr], eax
842
	mov	[edi + rx_desc.buf_soft_addr], eax
856
	GetRealAddr
843
	call	GetPgAddr
857
	mov	[edi + rx_desc.buf_addr], eax
844
	mov	dword [edi + rx_desc.buf_addr], eax
858
	mov	[edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
845
	mov	[edi + rx_desc.status], DSB_OWNbit or RX_BUF_SIZE
-
 
846
	add	edi, rx_desc.size
859
	add	edi, rx_desc.size
847
	pop	ecx
860
	loop	@b
848
	loop	.loop
Line 861... Line 849...
861
	or	[edi - rx_desc.size + rx_desc.status], DSB_EORbit
849
	or	[edi - rx_desc.size + rx_desc.status], DSB_EORbit
Line 970... Line 958...
970
	set_io	REG_RxMissed
958
	set_io	REG_RxMissed
971
	out	dx, eax
959
	out	dx, eax
Line 972... Line 960...
972
 
960
 
Line -... Line 961...
-
 
961
	call	set_rx_mode
973
	call	set_rx_mode
962
 
974
 
963
	set_io	0
975
	; no early-rx interrupts
964
	; no early-rx interrupts
976
	set_io	REG_MultiIntr
965
	set_io	REG_MultiIntr
977
	in	ax, dx
966
	in	ax, dx
Line 991... Line 980...
991
read_mac:
980
read_mac:
Line 992... Line 981...
992
 
981
 
993
	set_io	0
982
	set_io	0
994
	set_io	REG_MAC0
983
	set_io	REG_MAC0
995
	xor	ecx, ecx
984
	xor	ecx, ecx
996
	lea	esi, [device.mac]
985
	lea	edi, [device.mac]
Line 997... Line 986...
997
	mov	ecx, MAC_ADDR_LEN
986
	mov	ecx, MAC_ADDR_LEN
998
 
987
 
999
	; Get MAC address. FIXME: read EEPROM
988
	; Get MAC address. FIXME: read EEPROM
Line 1046... Line 1035...
1046
	lea	esi, [eax + tx_ring]
1035
	lea	esi, [eax + tx_ring]
Line 1047... Line 1036...
1047
 
1036
 
1048
;---------------------------
1037
;---------------------------
Line 1049... Line 1038...
1049
; Program the packet pointer
1038
; Program the packet pointer
1050
 
1039
 
1051
	mov	eax, [esp]
1040
	mov	eax, [esp + 4]
1052
	mov	[esi + tx_desc.buf_Haddr], eax
1041
	mov	[esi + tx_desc.buf_soft_addr], eax
Line 1053... Line 1042...
1053
	GetRealAddr
1042
	GetRealAddr
1054
	mov	[esi + tx_desc.buf_addr], eax
1043
	mov	dword [esi + tx_desc.buf_addr], eax
Line 1055... Line 1044...
1055
 
1044
 
1056
;------------------------
1045
;------------------------
1057
; Program the packet size
1046
; Program the packet size
1058
 
1047
 
1059
	mov	eax, [esp + 4]
1048
	mov	eax, [esp + 8]
1060
    @@: or	eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
1049
    @@: or	eax, DSB_OWNbit or DSB_FSbit or DSB_LSbit
Line 1074... Line 1063...
1074
;-----------------------
1063
;-----------------------
1075
; Update TX descriptor
1064
; Update TX descriptor
Line 1076... Line 1065...
1076
 
1065
 
1077
	inc	[tpc.cur_tx]
1066
	inc	[tpc.cur_tx]
1078
	and	[tpc.cur_tx], NUM_TX_DESC - 1
-
 
1079
 
1067
	and	[tpc.cur_tx], NUM_TX_DESC - 1
Line 1080... Line 1068...
1080
	ret	8
1068
	ret	8
1081
 
1069
 
1082
  .fail:
1070
  .fail:
Line 1107... Line 1095...
1107
	jz	.fail
1095
	jz	.fail
1108
	mov	esi, device_list
1096
	mov	esi, device_list
1109
  .nextdevice:
1097
  .nextdevice:
1110
	mov	ebx, dword [esi]
1098
	mov	ebx, dword [esi]
Line -... Line 1099...
-
 
1099
 
1111
 
1100
	set_io	0
1112
	set_io	REG_IntrStatus
1101
	set_io	REG_IntrStatus
Line 1113... Line 1102...
1113
	in	ax, dx
1102
	in	ax, dx
1114
 
1103
 
Line 1140... Line 1129...
1140
	mul	[tpc.cur_rx]
1129
	mul	[tpc.cur_rx]
1141
	lea	esi, [eax + rx_ring]
1130
	lea	esi, [eax + rx_ring]
Line 1142... Line 1131...
1142
 
1131
 
Line 1143... Line 1132...
1143
	DEBUGF	1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
1132
	DEBUGF	1,"RxDesc.status = 0x%x\n", [esi + rx_desc.status]
-
 
1133
 
1144
 
1134
	mov	eax, [esi + rx_desc.status]
Line 1145... Line 1135...
1145
	test	[esi + rx_desc.status], DSB_OWNbit
1135
	test	eax, DSB_OWNbit ;;;
Line 1146... Line 1136...
1146
	jnz	.rx_return
1136
	jnz	.rx_return
Line 1154... Line 1144...
1154
	and	eax, 0x00001FFF
1144
	and	eax, 0x00001FFF
1155
	add	eax, -4 			; we dont need CRC
1145
	add	eax, -4 			; we dont need CRC
1156
	push	eax
1146
	push	eax
1157
	DEBUGF	1,"data length = %u\n", ax
1147
	DEBUGF	1,"data length = %u\n", ax
Line 1158... Line 1148...
1158
 
1148
 
-
 
1149
	push	[esi + rx_desc.buf_soft_addr]
-
 
1150
 
-
 
1151
;----------------------
-
 
1152
; Allocate a new buffer
-
 
1153
 
-
 
1154
	stdcall KernelAlloc, RX_BUF_SIZE
-
 
1155
	mov	[esi + rx_desc.buf_soft_addr], eax
-
 
1156
	GetRealAddr
Line 1159... Line 1157...
1159
	push	[esi + rx_desc.buf_Haddr]
1157
	mov	dword [esi + rx_desc.buf_addr], eax
1160
 
1158
 
Line 1161... Line 1159...
1161
;---------------
1159
;---------------
1162
; re set OWN bit
1160
; re set OWN bit
1163
 
1161
 
1164
	mov	eax, DSB_OWNbit or RX_BUF_SIZE
1162
	mov	eax, DSB_OWNbit or RX_BUF_SIZE
1165
	cmp	[tpc.cur_rx], NUM_RX_DESC - 1
1163
	cmp	[tpc.cur_rx], NUM_RX_DESC - 1
Line 1166... Line -...
1166
	jne	@f
-
 
1167
	or	eax, DSB_EORbit
-
 
1168
    @@: mov	[esi + rx_desc.status], eax
-
 
1169
 
-
 
1170
;----------------------
-
 
1171
; Allocate a new buffer
-
 
1172
 
-
 
1173
	stdcall KernelAlloc, RX_BUF_SIZE
-
 
1174
	mov	[esi + rx_desc.buf_Haddr], eax
1164
	jne	@f
1175
	GetRealAddr
1165
	or	eax, DSB_EORbit
Line 1176... Line 1166...
1176
	sub	[esi + rx_desc.buf_addr], eax
1166
    @@: mov	[esi + rx_desc.status], eax
1177
 
1167