6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 #include <exec/types.h>
25 #include <exec/resident.h>
27 #include <exec/ports.h>
29 #include <aros/libcall.h>
30 #include <aros/macros.h>
35 #include <devices/sana2.h>
36 #include <devices/sana2specialstats.h>
38 #include <utility/utility.h>
39 #include <utility/tagitem.h>
40 #include <utility/hooks.h>
44 #include <proto/oop.h>
45 #include <proto/exec.h>
46 #include <proto/dos.h>
47 #include <proto/battclock.h>
49 #include <hardware/intbits.h>
54 #include LC_LIBDEFS_FILE
57 #define LIBBASE (unit->rtl8168u_device)
59 #define _R(NAME,MAC,RCR,MASK, JumFrameSz) \
60 { .name = NAME, .mcfg = MAC, .RCR_Cfg = RCR, .RxConfigMask = MASK, .jumbo_frame_sz = JumFrameSz }
66 ULONG RxConfigMask
; /* Clears the bits supported by this chip */
71 (Reserved2_data
<< Reserved2_shift
) | (RX_DMA_BURST
<< RxCfgDMAShift
),
77 (Reserved2_data
<< Reserved2_shift
) | (RX_DMA_BURST
<< RxCfgDMAShift
),
83 (Reserved2_data
<< Reserved2_shift
) | (RX_DMA_BURST
<< RxCfgDMAShift
),
88 CFG_METHOD_4
, RxCfg_128_int_en
| RxCfg_fet_multi_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
94 RxCfg_128_int_en
| RxCfg_fet_multi_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
100 RxCfg_128_int_en
| RxCfg_fet_multi_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
104 _R("RTL8168CP/8111CP",
106 RxCfg_128_int_en
| RxCfg_fet_multi_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
110 _R("RTL8168CP/8111CP",
112 RxCfg_128_int_en
| RxCfg_fet_multi_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
118 RxCfg_128_int_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
124 RxCfg_128_int_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
130 RxCfg_128_int_en
| (RX_DMA_BURST
<< RxCfgDMAShift
),
136 void rtl8168nic_USecDelay(struct net_device
*unit
, ULONG usec
)
140 unit
->rtl8168u_DelayPort
.mp_SigTask
= FindTask(NULL
);
141 unit
->rtl8168u_DelayReq
.tr_node
.io_Command
= TR_ADDREQUEST
;
142 unit
->rtl8168u_DelayReq
.tr_time
.tv_micro
= usec
% 1000000;
143 unit
->rtl8168u_DelayReq
.tr_time
.tv_secs
= usec
/ 1000000;
145 DoIO((struct IORequest
*)&unit
->rtl8168u_DelayReq
);
149 static inline struct rtl8168_priv
*get_pcnpriv(struct net_device
*unit
)
151 return unit
->rtl8168u_priv
;
154 static inline UBYTE
*get_hwbase(struct net_device
*unit
)
156 return (UBYTE
*)unit
->rtl8168u_BaseMem
;
159 void MMIO_W8(APTR addr
, UBYTE val8
)
161 *((volatile UBYTE
*)(addr
)) = (val8
);
166 void MMIO_W16(APTR addr
, UWORD val16
)
168 *((volatile UWORD
*)(addr
)) = (val16
);
173 void MMIO_W32(APTR addr
, ULONG val32
)
175 *((volatile ULONG
*)(addr
)) = (val32
);
180 static void mdio_write(struct net_device
*unit
, int RegAddr
, UWORD value
)
182 APTR base
= get_hwbase(unit
);
185 RTL_W32(base
+ (PHYAR
), PHYAR_Write
|
186 (RegAddr
& PHYAR_Reg_Mask
) << PHYAR_Reg_shift
|
187 (value
& PHYAR_Data_Mask
));
189 for (i
= 0; i
< 10; i
++) {
190 /* Check if the RTL8168 has completed writing to the specified MII register */
191 if (!(RTL_R32(base
+ (PHYAR
)) & PHYAR_Flag
))
198 static ULONG
mdio_read(struct net_device
*unit
, int RegAddr
)
200 APTR base
= get_hwbase(unit
);
201 UWORD value
= 0xffff;
204 RTL_W32(base
+ (PHYAR
), PHYAR_Read
| (RegAddr
& PHYAR_Reg_Mask
) << PHYAR_Reg_shift
);
206 for (i
= 0; i
< 10; i
++) {
207 /* Check if the RTL8168 has completed retrieving data from the specified MII register */
208 if (RTL_R32(base
+ (PHYAR
)) & PHYAR_Flag
) {
209 value
= (UWORD
)(RTL_R32(base
+ (PHYAR
)) & PHYAR_Data_Mask
);
217 static void rtl8168nic_EPHYWrite(struct net_device
*unit
, int RegAddr
, UWORD value
)
219 APTR base
= get_hwbase(unit
);
222 RTL_W32(base
+ (EPHYAR
),
224 (RegAddr
& EPHYAR_Reg_Mask
) << EPHYAR_Reg_shift
|
225 (value
& EPHYAR_Data_Mask
));
227 for (i
= 0; i
< 10; i
++) {
230 /* Check if the RTL8168 has completed EPHY write */
231 if (!(RTL_R32(base
+ (EPHYAR
)) & EPHYAR_Flag
))
238 static UWORD
rtl8168nic_EPHYRead(struct net_device
*unit
, int RegAddr
)
240 APTR base
= get_hwbase(unit
);
241 UWORD value
= 0xffff;
244 RTL_W32(base
+ (EPHYAR
),
245 EPHYAR_Read
| (RegAddr
& EPHYAR_Reg_Mask
) << EPHYAR_Reg_shift
);
247 for (i
= 0; i
< 10; i
++) {
250 /* Check if the RTL8168 has completed EPHY read */
251 if (RTL_R32(base
+ (EPHYAR
)) & EPHYAR_Flag
) {
252 value
= (UWORD
)(RTL_R32(base
+ (EPHYAR
)) & EPHYAR_Data_Mask
);
262 static void rtl8168nic_CSIWrite(struct net_device
*unit
, int addr
, ULONG value
)
264 APTR base
= get_hwbase(unit
);
267 RTL_W32(base
+ (CSIDR
), value
);
268 RTL_W32(base
+ (CSIAR
),
270 CSIAR_ByteEn
<< CSIAR_ByteEn_shift
|
271 (addr
& CSIAR_Addr_Mask
));
273 for (i
= 0; i
< 10; i
++) {
276 /* Check if the RTL8168 has completed CSI write */
277 if (!(RTL_R32(base
+ (CSIAR
)) & CSIAR_Flag
))
284 static ULONG
rtl8168nic_CSIRead(struct net_device
*unit
, int addr
)
286 APTR base
= get_hwbase(unit
);
287 ULONG value
= 0xffffffff;
290 RTL_W32(base
+ (CSIAR
),
292 CSIAR_ByteEn
<< CSIAR_ByteEn_shift
|
293 (addr
& CSIAR_Addr_Mask
));
295 for (i
= 0; i
< 10; i
++) {
298 /* Check if the RTL8168 has completed CSI read */
299 if (RTL_R32(base
+ (CSIAR
)) & CSIAR_Flag
) {
300 value
= RTL_R32(base
+ (CSIDR
));
310 static void rtl8168nic_PHYPowerUP(struct net_device
*unit
)
312 // APTR base = get_hwbase(unit);
314 RTLD(bug("[%s] rtl8168nic_PHYPowerUP()\n", unit
->rtl8168u_name
))
316 mdio_write(unit
, 0x1F, 0x0000);
317 mdio_write(unit
, 0x0E, 0x0000);
320 static void rtl8168nic_GetMACVersion(struct net_device
*unit
)
322 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
323 APTR base
= get_hwbase(unit
);
327 RTLD(bug("[%s] rtl8168nic_GetMACVersion()\n", unit
->rtl8168u_name
))
329 val32
= RTL_R32(base
+ (TxConfig
));
330 reg
= val32
& 0x7c800000;
331 ICVerID
= val32
& 0x00700000;
336 np
->mcfg
= CFG_METHOD_1
;
339 if(ICVerID
== 0x00000000) {
340 np
->mcfg
= CFG_METHOD_2
;
341 } else if(ICVerID
== 0x00500000) {
342 np
->mcfg
= CFG_METHOD_3
;
344 np
->mcfg
= CFG_METHOD_3
;
348 if(ICVerID
== 0x00000000) {
349 np
->mcfg
= CFG_METHOD_4
;
350 } else if(ICVerID
== 0x00200000) {
351 np
->mcfg
= CFG_METHOD_5
;
352 } else if(ICVerID
== 0x00400000) {
353 np
->mcfg
= CFG_METHOD_6
;
355 np
->mcfg
= CFG_METHOD_6
;
359 if (ICVerID
== 0x00100000){
360 np
->mcfg
= CFG_METHOD_7
;
361 } else if (ICVerID
== 0x00300000){
362 np
->mcfg
= CFG_METHOD_8
;
364 np
->mcfg
= CFG_METHOD_8
;
368 if(ICVerID
== 0x00100000) {
369 np
->mcfg
= CFG_METHOD_9
;
370 } else if(ICVerID
== 0x00200000) {
371 np
->mcfg
= CFG_METHOD_10
;
372 } else if(ICVerID
== 0x00300000) {
373 np
->mcfg
= CFG_METHOD_11
;
375 np
->mcfg
= CFG_METHOD_11
;
379 np
->mcfg
= 0xFFFFFFFF;
380 RTLD(bug("[%s] rtl8168nic_GetMACVersion: unknown chip version (%x)\n", unit
->rtl8168u_name
, reg
))
385 static void rtl8168nic_PrintMACVersion(struct net_device
*unit
)
387 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
390 RTLD(bug("[%s] rtl8168nic_PrintMACVersion()\n", unit
->rtl8168u_name
))
392 for (i
= (sizeof(rtl_chip_info
) / sizeof(rtl_chip_info
[0])) - 1; i
>= 0; i
--)
394 if (np
->mcfg
== rtl_chip_info
[i
].mcfg
)
396 RTLD(bug("[%s] rtl8168nic_PrintMACVersion: mcfg == %s (%04d)\n", unit
->rtl8168u_name
,
397 rtl_chip_info
[i
].name
,
398 rtl_chip_info
[i
].mcfg
))
403 RTLD(bug("[%s] rtl8168nic_PrintMACVersion: mac_version == Unknown\n", unit
->rtl8168u_name
))
406 static void rtl8168nic_HWPHYConfig(struct net_device
*unit
)
408 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
409 // APTR base = get_hwbase(unit);
412 RTLD(bug("[%s] rtl8168nic_HWPHYConfig()\n", unit
->rtl8168u_name
))
414 if (np
->mcfg
== CFG_METHOD_1
)
416 mdio_write(unit
, 0x1F, 0x0001);
417 mdio_write(unit
, 0x0B, 0x94B0);
419 mdio_write(unit
, 0x1F, 0x0003);
420 mdio_write(unit
, 0x12, 0x6096);
421 mdio_write(unit
, 0x1F, 0x0000);
423 mdio_write(unit
, 0x0D, 0xF8A0);
424 } else if (np
->mcfg
== CFG_METHOD_2
) {
425 mdio_write(unit
, 0x1F, 0x0001);
426 mdio_write(unit
, 0x0B, 0x94B0);
428 mdio_write(unit
, 0x1F, 0x0003);
429 mdio_write(unit
, 0x12, 0x6096);
431 mdio_write(unit
, 0x1F, 0x0000);
432 } else if (np
->mcfg
== CFG_METHOD_3
) {
433 mdio_write(unit
, 0x1F, 0x0001);
434 mdio_write(unit
, 0x0B, 0x94B0);
436 mdio_write(unit
, 0x1F, 0x0003);
437 mdio_write(unit
, 0x12, 0x6096);
439 mdio_write(unit
, 0x1F, 0x0000);
440 } else if (np
->mcfg
== CFG_METHOD_4
) {
441 mdio_write(unit
, 0x1F, 0x0001);
442 mdio_write(unit
, 0x12, 0x2300);
443 mdio_write(unit
, 0x1F, 0x0000);
444 mdio_write(unit
, 0x1F, 0x0003);
445 mdio_write(unit
, 0x16, 0x000A);
446 mdio_write(unit
, 0x1F, 0x0000);
448 mdio_write(unit
, 0x1F, 0x0003);
449 mdio_write(unit
, 0x12, 0xC096);
450 mdio_write(unit
, 0x1F, 0x0000);
452 mdio_write(unit
, 0x1F, 0x0002);
453 mdio_write(unit
, 0x00, 0x88DE);
454 mdio_write(unit
, 0x01, 0x82B1);
455 mdio_write(unit
, 0x1F, 0x0000);
457 mdio_write(unit
, 0x1F, 0x0002);
458 mdio_write(unit
, 0x08, 0x9E30);
459 mdio_write(unit
, 0x09, 0x01F0);
460 mdio_write(unit
, 0x1F, 0x0000);
462 mdio_write(unit
, 0x1F, 0x0002);
463 mdio_write(unit
, 0x0A, 0x5500);
464 mdio_write(unit
, 0x1F, 0x0000);
466 mdio_write(unit
, 0x1F, 0x0002);
467 mdio_write(unit
, 0x03, 0x7002);
468 mdio_write(unit
, 0x1F, 0x0000);
470 mdio_write(unit
, 0x1F, 0x0002);
471 mdio_write(unit
, 0x0C, 0x00C8);
472 mdio_write(unit
, 0x1F, 0x0000);
474 mdio_write(unit
, 0x1F, 0x0000);
475 mdio_write(unit
, 0x14, mdio_read(unit
, 0x14) | (1 << 5));
476 mdio_write(unit
, 0x0D, mdio_read(unit
, 0x0D) | (1 << 5));
477 } else if (np
->mcfg
== CFG_METHOD_5
) {
478 mdio_write(unit
, 0x1F, 0x0001);
479 mdio_write(unit
, 0x12, 0x2300);
480 mdio_write(unit
, 0x1F, 0x0003);
481 mdio_write(unit
, 0x16, 0x0F0A);
482 mdio_write(unit
, 0x1F, 0x0000);
484 mdio_write(unit
, 0x1F, 0x0002);
485 mdio_write(unit
, 0x00, 0x88DE);
486 mdio_write(unit
, 0x01, 0x82B1);
487 mdio_write(unit
, 0x1F, 0x0000);
489 mdio_write(unit
, 0x1F, 0x0002);
490 mdio_write(unit
, 0x0C, 0x7EB8);
491 mdio_write(unit
, 0x1F, 0x0000);
493 mdio_write(unit
, 0x1F, 0x0002);
494 mdio_write(unit
, 0x06, 0x0761);
495 mdio_write(unit
, 0x1F, 0x0000);
497 mdio_write(unit
, 0x1F, 0x0001);
498 mdio_write(unit
, 0x03, 0x802F);
499 mdio_write(unit
, 0x02, 0x4F02);
500 mdio_write(unit
, 0x01, 0x0409);
501 mdio_write(unit
, 0x00, 0xF099);
502 mdio_write(unit
, 0x04, 0x9800);
503 mdio_write(unit
, 0x04, 0x9000);
504 mdio_write(unit
, 0x1F, 0x0000);
506 mdio_write(unit
, 0x1F, 0x0000);
507 mdio_write(unit
, 0x16, mdio_read(unit
, 0x16) | (1 << 0));
509 mdio_write(unit
, 0x1F, 0x0000);
510 mdio_write(unit
, 0x14, mdio_read(unit
, 0x14) | (1 << 5));
511 mdio_write(unit
, 0x0D, mdio_read(unit
, 0x0D) | (1 << 5));
513 mdio_write(unit
, 0x1F, 0x0001);
514 mdio_write(unit
, 0x1D, 0x3D98);
515 mdio_write(unit
, 0x1F, 0x0000);
517 mdio_write(unit
, 0x1F, 0x0001);
518 mdio_write(unit
, 0x17, 0x0CC0);
519 mdio_write(unit
, 0x1F, 0x0000);
520 } else if (np
->mcfg
== CFG_METHOD_6
) {
521 mdio_write(unit
, 0x1F, 0x0001);
522 mdio_write(unit
, 0x12, 0x2300);
523 mdio_write(unit
, 0x1F, 0x0003);
524 mdio_write(unit
, 0x16, 0x0F0A);
525 mdio_write(unit
, 0x1F, 0x0000);
527 mdio_write(unit
, 0x1F, 0x0002);
528 mdio_write(unit
, 0x00, 0x88DE);
529 mdio_write(unit
, 0x01, 0x82B1);
530 mdio_write(unit
, 0x1F, 0x0000);
532 mdio_write(unit
, 0x1F, 0x0002);
533 mdio_write(unit
, 0x0C, 0x7EB8);
534 mdio_write(unit
, 0x1F, 0x0000);
536 mdio_write(unit
, 0x1F, 0x0002);
537 mdio_write(unit
, 0x06, 0x0761);
538 mdio_write(unit
, 0x1F, 0x0000);
540 mdio_write(unit
, 0x1F, 0x0000);
541 mdio_write(unit
, 0x16, mdio_read(unit
, 0x16) | (1 << 0));
543 mdio_write(unit
, 0x1F, 0x0000);
544 mdio_write(unit
, 0x14, mdio_read(unit
, 0x14) | (1 << 5));
545 mdio_write(unit
, 0x0D, mdio_read(unit
, 0x0D) | (1 << 5));
547 mdio_write(unit
, 0x1F, 0x0001);
548 mdio_write(unit
, 0x1D, 0x3D98);
549 mdio_write(unit
, 0x1F, 0x0000);
551 mdio_write(unit
, 0x1f, 0x0001);
552 mdio_write(unit
, 0x17, 0x0CC0);
553 mdio_write(unit
, 0x1F, 0x0000);
554 } else if (np
->mcfg
== CFG_METHOD_7
) {
555 mdio_write(unit
, 0x1F, 0x0000);
556 mdio_write(unit
, 0x14, mdio_read(unit
, 0x14) | (1 << 5));
557 mdio_write(unit
, 0x0D, mdio_read(unit
, 0x0D) | (1 << 5));
559 mdio_write(unit
, 0x1F, 0x0001);
560 mdio_write(unit
, 0x1D, 0x3D98);
562 mdio_write(unit
, 0x1F, 0x0001);
563 mdio_write(unit
, 0x14, 0xCAA3);
564 mdio_write(unit
, 0x1C, 0x000A);
565 mdio_write(unit
, 0x18, 0x65D0);
567 mdio_write(unit
, 0x1F, 0x0003);
568 mdio_write(unit
, 0x17, 0xB580);
569 mdio_write(unit
, 0x18, 0xFF54);
570 mdio_write(unit
, 0x19, 0x3954);
572 mdio_write(unit
, 0x1F, 0x0002);
573 mdio_write(unit
, 0x0D, 0x310C);
574 mdio_write(unit
, 0x0E, 0x310C);
575 mdio_write(unit
, 0x0F, 0x311C);
576 mdio_write(unit
, 0x06, 0x0761);
578 mdio_write(unit
, 0x1F, 0x0003);
579 mdio_write(unit
, 0x18, 0xFF55);
580 mdio_write(unit
, 0x19, 0x3955);
581 mdio_write(unit
, 0x18, 0xFF54);
582 mdio_write(unit
, 0x19, 0x3954);
584 mdio_write(unit
, 0x1f, 0x0001);
585 mdio_write(unit
, 0x17, 0x0CC0);
587 mdio_write(unit
, 0x1F, 0x0000);
588 } else if (np
->mcfg
== CFG_METHOD_8
) {
589 mdio_write(unit
, 0x1F, 0x0000);
590 mdio_write(unit
, 0x0D, mdio_read(unit
, 0x0D) | (1 << 5));
592 mdio_write(unit
, 0x1F, 0x0001);
593 mdio_write(unit
, 0x14, 0xCAA3);
594 mdio_write(unit
, 0x1C, 0x000A);
595 mdio_write(unit
, 0x18, 0x65D0);
597 mdio_write(unit
, 0x1F, 0x0003);
598 mdio_write(unit
, 0x17, 0xB580);
599 mdio_write(unit
, 0x18, 0xFF54);
600 mdio_write(unit
, 0x19, 0x3954);
602 mdio_write(unit
, 0x1F, 0x0002);
603 mdio_write(unit
, 0x0D, 0x310C);
604 mdio_write(unit
, 0x0E, 0x310C);
605 mdio_write(unit
, 0x0F, 0x311C);
606 mdio_write(unit
, 0x06, 0x0761);
608 mdio_write(unit
, 0x1F, 0x0003);
609 mdio_write(unit
, 0x18, 0xFF55);
610 mdio_write(unit
, 0x19, 0x3955);
611 mdio_write(unit
, 0x18, 0xFF54);
612 mdio_write(unit
, 0x19, 0x3954);
614 mdio_write(unit
, 0x1f, 0x0001);
615 mdio_write(unit
, 0x17, 0x0CC0);
617 mdio_write(unit
, 0x1F, 0x0000);
618 } else if (np
->mcfg
== CFG_METHOD_9
) {
619 mdio_write(unit
, 0x1F, 0x0001);
620 mdio_write(unit
, 0x06, 0x4064);
621 mdio_write(unit
, 0x07, 0x2863);
622 mdio_write(unit
, 0x08, 0x059C);
623 mdio_write(unit
, 0x09, 0x26B4);
624 mdio_write(unit
, 0x0A, 0x6A19);
625 mdio_write(unit
, 0x0B, 0xACC0);
626 mdio_write(unit
, 0x10, 0xF06D);
627 mdio_write(unit
, 0x14, 0x7F68);
628 mdio_write(unit
, 0x18, 0x7FD9);
629 mdio_write(unit
, 0x1C, 0xF0FF);
630 mdio_write(unit
, 0x1D, 0x3D9C);
631 mdio_write(unit
, 0x1F, 0x0003);
632 mdio_write(unit
, 0x12, 0xF49F);
633 mdio_write(unit
, 0x13, 0x070B);
634 mdio_write(unit
, 0x1A, 0x05AD);
635 mdio_write(unit
, 0x14, 0x94C0);
637 mdio_write(unit
, 0x1F, 0x0002);
638 mdio_write(unit
, 0x0B, 0x0B10);
639 mdio_write(unit
, 0x0C, 0xA2F7);
641 mdio_write(unit
, 0x1F, 0x0002);
642 mdio_write(unit
, 0x06, 0x5571);
644 mdio_write(unit
, 0x1F, 0x0002);
645 mdio_write(unit
, 0x02, 0xC107);
646 mdio_write(unit
, 0x03, 0x1002);
648 mdio_write(unit
, 0x1F, 0x0001);
649 mdio_write(unit
, 0x17, 0x0CC0);
651 mdio_write(unit
, 0x1F, 0x0005);
652 mdio_write(unit
, 0x05, 0x8200);
653 mdio_write(unit
, 0x06, 0xF8F9);
654 mdio_write(unit
, 0x06, 0xFAEF);
655 mdio_write(unit
, 0x06, 0x59EE);
656 mdio_write(unit
, 0x06, 0xF8EA);
657 mdio_write(unit
, 0x06, 0x00EE);
658 mdio_write(unit
, 0x06, 0xF8EB);
659 mdio_write(unit
, 0x06, 0x00E0);
660 mdio_write(unit
, 0x06, 0xF87C);
661 mdio_write(unit
, 0x06, 0xE1F8);
662 mdio_write(unit
, 0x06, 0x7D59);
663 mdio_write(unit
, 0x06, 0x0FEF);
664 mdio_write(unit
, 0x06, 0x0139);
665 mdio_write(unit
, 0x06, 0x029E);
666 mdio_write(unit
, 0x06, 0x06EF);
667 mdio_write(unit
, 0x06, 0x1039);
668 mdio_write(unit
, 0x06, 0x089F);
669 mdio_write(unit
, 0x06, 0x2AEE);
670 mdio_write(unit
, 0x06, 0xF8EA);
671 mdio_write(unit
, 0x06, 0x00EE);
672 mdio_write(unit
, 0x06, 0xF8EB);
673 mdio_write(unit
, 0x06, 0x01E0);
674 mdio_write(unit
, 0x06, 0xF87C);
675 mdio_write(unit
, 0x06, 0xE1F8);
676 mdio_write(unit
, 0x06, 0x7D58);
677 mdio_write(unit
, 0x06, 0x409E);
678 mdio_write(unit
, 0x06, 0x0F39);
679 mdio_write(unit
, 0x06, 0x46AA);
680 mdio_write(unit
, 0x06, 0x0BBF);
681 mdio_write(unit
, 0x06, 0x8251);
682 mdio_write(unit
, 0x06, 0xD682);
683 mdio_write(unit
, 0x06, 0x5902);
684 mdio_write(unit
, 0x06, 0x014F);
685 mdio_write(unit
, 0x06, 0xAE09);
686 mdio_write(unit
, 0x06, 0xBF82);
687 mdio_write(unit
, 0x06, 0x59D6);
688 mdio_write(unit
, 0x06, 0x8261);
689 mdio_write(unit
, 0x06, 0x0201);
690 mdio_write(unit
, 0x06, 0x4FEF);
691 mdio_write(unit
, 0x06, 0x95FE);
692 mdio_write(unit
, 0x06, 0xFDFC);
693 mdio_write(unit
, 0x06, 0x054D);
694 mdio_write(unit
, 0x06, 0x2000);
695 mdio_write(unit
, 0x06, 0x024E);
696 mdio_write(unit
, 0x06, 0x2200);
697 mdio_write(unit
, 0x06, 0x024D);
698 mdio_write(unit
, 0x06, 0xDFFF);
699 mdio_write(unit
, 0x06, 0x014E);
700 mdio_write(unit
, 0x06, 0xDDFF);
701 mdio_write(unit
, 0x06, 0x0100);
702 mdio_write(unit
, 0x06, 0x6010);
703 mdio_write(unit
, 0x05, 0xFFF6);
704 mdio_write(unit
, 0x06, 0x00EC);
705 mdio_write(unit
, 0x05, 0x83D4);
706 mdio_write(unit
, 0x06, 0x8200);
707 mdio_write(unit
, 0x1F, 0x0000);
708 } else if (np
->mcfg
== CFG_METHOD_10
) {
709 mdio_write(unit
, 0x1F, 0x0001);
710 mdio_write(unit
, 0x06, 0x4064);
711 mdio_write(unit
, 0x07, 0x2863);
712 mdio_write(unit
, 0x08, 0x059C);
713 mdio_write(unit
, 0x09, 0x26B4);
714 mdio_write(unit
, 0x0A, 0x6A19);
715 mdio_write(unit
, 0x0B, 0xACC0);
716 mdio_write(unit
, 0x10, 0xF06D);
717 mdio_write(unit
, 0x14, 0x7F68);
718 mdio_write(unit
, 0x18, 0x7FD9);
719 mdio_write(unit
, 0x1C, 0xF0FF);
720 mdio_write(unit
, 0x1D, 0x3D9C);
721 mdio_write(unit
, 0x1F, 0x0003);
722 mdio_write(unit
, 0x12, 0xF49F);
723 mdio_write(unit
, 0x13, 0x070B);
724 mdio_write(unit
, 0x1A, 0x05AD);
725 mdio_write(unit
, 0x14, 0x94C0);
727 mdio_write(unit
, 0x1F, 0x0002);
728 mdio_write(unit
, 0x06, 0x5571);
730 mdio_write(unit
, 0x1F, 0x0002);
731 mdio_write(unit
, 0x05, 0x2642);
733 mdio_write(unit
, 0x1F, 0x0002);
734 mdio_write(unit
, 0x02, 0xC107);
735 mdio_write(unit
, 0x03, 0x1002);
737 mdio_write(unit
, 0x1F, 0x0001);
738 mdio_write(unit
, 0x17, 0x0CC0);
740 mdio_write(unit
, 0x1F, 0x0002);
741 mdio_write(unit
, 0x0F, 0x0017);
743 mdio_write(unit
, 0x1F, 0x0005);
744 mdio_write(unit
, 0x05, 0x8200);
745 mdio_write(unit
, 0x06, 0xF8F9);
746 mdio_write(unit
, 0x06, 0xFAEF);
747 mdio_write(unit
, 0x06, 0x59EE);
748 mdio_write(unit
, 0x06, 0xF8EA);
749 mdio_write(unit
, 0x06, 0x00EE);
750 mdio_write(unit
, 0x06, 0xF8EB);
751 mdio_write(unit
, 0x06, 0x00E0);
752 mdio_write(unit
, 0x06, 0xF87C);
753 mdio_write(unit
, 0x06, 0xE1F8);
754 mdio_write(unit
, 0x06, 0x7D59);
755 mdio_write(unit
, 0x06, 0x0FEF);
756 mdio_write(unit
, 0x06, 0x0139);
757 mdio_write(unit
, 0x06, 0x029E);
758 mdio_write(unit
, 0x06, 0x06EF);
759 mdio_write(unit
, 0x06, 0x1039);
760 mdio_write(unit
, 0x06, 0x089F);
761 mdio_write(unit
, 0x06, 0x2AEE);
762 mdio_write(unit
, 0x06, 0xF8EA);
763 mdio_write(unit
, 0x06, 0x00EE);
764 mdio_write(unit
, 0x06, 0xF8EB);
765 mdio_write(unit
, 0x06, 0x01E0);
766 mdio_write(unit
, 0x06, 0xF87C);
767 mdio_write(unit
, 0x06, 0xE1F8);
768 mdio_write(unit
, 0x06, 0x7D58);
769 mdio_write(unit
, 0x06, 0x409E);
770 mdio_write(unit
, 0x06, 0x0F39);
771 mdio_write(unit
, 0x06, 0x46AA);
772 mdio_write(unit
, 0x06, 0x0BBF);
773 mdio_write(unit
, 0x06, 0x8251);
774 mdio_write(unit
, 0x06, 0xD682);
775 mdio_write(unit
, 0x06, 0x5902);
776 mdio_write(unit
, 0x06, 0x014F);
777 mdio_write(unit
, 0x06, 0xAE09);
778 mdio_write(unit
, 0x06, 0xBF82);
779 mdio_write(unit
, 0x06, 0x59D6);
780 mdio_write(unit
, 0x06, 0x8261);
781 mdio_write(unit
, 0x06, 0x0201);
782 mdio_write(unit
, 0x06, 0x4FEF);
783 mdio_write(unit
, 0x06, 0x95FE);
784 mdio_write(unit
, 0x06, 0xFDFC);
785 mdio_write(unit
, 0x06, 0x054D);
786 mdio_write(unit
, 0x06, 0x2000);
787 mdio_write(unit
, 0x06, 0x024E);
788 mdio_write(unit
, 0x06, 0x2200);
789 mdio_write(unit
, 0x06, 0x024D);
790 mdio_write(unit
, 0x06, 0xDFFF);
791 mdio_write(unit
, 0x06, 0x014E);
792 mdio_write(unit
, 0x06, 0xDDFF);
793 mdio_write(unit
, 0x06, 0x0100);
794 mdio_write(unit
, 0x02, 0x6010);
795 mdio_write(unit
, 0x05, 0xFFF6);
796 mdio_write(unit
, 0x06, 0x00EC);
797 mdio_write(unit
, 0x05, 0x83D4);
798 mdio_write(unit
, 0x06, 0x8200);
799 mdio_write(unit
, 0x1F, 0x0000);
800 } else if (np
->mcfg
== CFG_METHOD_11
) {
801 mdio_write(unit
, 0x1F, 0x0001);
802 mdio_write(unit
, 0x06, 0x4064);
803 mdio_write(unit
, 0x07, 0x2863);
804 mdio_write(unit
, 0x08, 0x059C);
805 mdio_write(unit
, 0x09, 0x26B4);
806 mdio_write(unit
, 0x0A, 0x6A19);
807 mdio_write(unit
, 0x0B, 0xACC0);
808 mdio_write(unit
, 0x10, 0xF06D);
809 mdio_write(unit
, 0x14, 0x7F68);
810 mdio_write(unit
, 0x18, 0x7FD9);
811 mdio_write(unit
, 0x1C, 0xF0FF);
812 mdio_write(unit
, 0x1D, 0x3D9C);
813 mdio_write(unit
, 0x1F, 0x0003);
814 mdio_write(unit
, 0x12, 0xF49F);
815 mdio_write(unit
, 0x13, 0x070B);
816 mdio_write(unit
, 0x1A, 0x05AD);
817 mdio_write(unit
, 0x14, 0x94C0);
819 mdio_write(unit
, 0x1F, 0x0002);
820 mdio_write(unit
, 0x06, 0x5571);
822 mdio_write(unit
, 0x1F, 0x0002);
823 mdio_write(unit
, 0x05, 0x2642);
825 mdio_write(unit
, 0x1F, 0x0002);
826 mdio_write(unit
, 0x02, 0xC107);
827 mdio_write(unit
, 0x03, 0x1002);
829 mdio_write(unit
, 0x1F, 0x0001);
830 mdio_write(unit
, 0x17, 0x0CC0);
832 mdio_write(unit
, 0x1F, 0x0002);
833 mdio_write(unit
, 0x0F, 0x0017);
837 static void rtl8168nic_DSM(struct net_device
*unit
, int dev_state
)
839 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
840 APTR base
= get_hwbase(unit
);
844 if ((np
->mcfg
== CFG_METHOD_5
) || (np
->mcfg
== CFG_METHOD_6
)) {
845 if (RTL_R8(base
+ (MACDBG
)) & 0x80) {
846 RTL_W8(base
+ (GPIO
), RTL_R8(base
+ (GPIO
)) | GPIO_en
);
848 RTL_W8(base
+ (GPIO
), RTL_R8(base
+ (GPIO
)) & ~GPIO_en
);
853 case DSM_NIC_GOTO_D3
:
855 if ((np
->mcfg
== CFG_METHOD_5
) || (np
->mcfg
== CFG_METHOD_6
))
856 if (RTL_R8(base
+ (MACDBG
)) & 0x80)
857 RTL_W8(base
+ (GPIO
), RTL_R8(base
+ (GPIO
)) & ~GPIO_en
);
860 case DSM_NIC_RESUME_D3
:
862 if ((np
->mcfg
== CFG_METHOD_5
) || (np
->mcfg
== CFG_METHOD_6
))
863 if (RTL_R8(base
+ (MACDBG
)) & 0x80)
864 RTL_W8(base
+ (GPIO
), RTL_R8(base
+ (GPIO
)) | GPIO_en
);
870 static int rtl8168nic_SetSpeedXMII(struct net_device
*unit
,
875 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
876 // APTR base = get_hwbase(unit);
879 int bmcr_true_force
= 0;
880 // unsigned long flags;
882 RTLD(bug("[%s] rtl8168nic_SetSpeedXMII()\n", unit
->rtl8168u_name
))
884 if ((speed
!= SPEED_1000
) &&
885 (speed
!= SPEED_100
) &&
886 (speed
!= SPEED_10
)) {
888 duplex
= DUPLEX_FULL
;
891 if ((autoneg
== AUTONEG_ENABLE
) || (speed
== SPEED_1000
)) {
893 if ((speed
== SPEED_10
) && (duplex
== DUPLEX_HALF
)) {
894 auto_nego
|= ADVERTISE_10HALF
;
895 } else if ((speed
== SPEED_10
) && (duplex
== DUPLEX_FULL
)) {
896 auto_nego
|= ADVERTISE_10HALF
|
898 } else if ((speed
== SPEED_100
) && (duplex
== DUPLEX_HALF
)) {
899 auto_nego
|= ADVERTISE_100HALF
|
902 } else if ((speed
== SPEED_100
) && (duplex
== DUPLEX_FULL
)) {
903 auto_nego
|= ADVERTISE_100HALF
|
907 } else if (speed
== SPEED_1000
) {
908 giga_ctrl
|= ADVERTISE_1000HALF
|
911 auto_nego
|= ADVERTISE_100HALF
|
917 //disable flow contorol
918 auto_nego
&= ~ADVERTISE_PAUSE_CAP
;
919 auto_nego
&= ~ADVERTISE_PAUSE_ASYM
;
921 np
->phy_auto_nego_reg
= auto_nego
;
922 np
->phy_1000_ctrl_reg
= giga_ctrl
;
924 np
->autoneg
= autoneg
;
928 rtl8168nic_PHYPowerUP(unit
);
930 mdio_write(unit
, 0x1f, 0x0000);
931 mdio_write(unit
, MII_ADVERTISE
, auto_nego
);
932 mdio_write(unit
, MII_CTRL1000
, giga_ctrl
);
933 mdio_write(unit
, MII_BMCR
, BMCR_RESET
| BMCR_ANENABLE
| BMCR_ANRESTART
);
936 #ifndef BMCR_SPEED100
937 #define BMCR_SPEED100 0x0040
941 #define BMCR_SPEED10 0x0000
943 if ((speed
== SPEED_10
) && (duplex
== DUPLEX_HALF
)) {
944 bmcr_true_force
= BMCR_SPEED10
;
945 } else if ((speed
== SPEED_10
) && (duplex
== DUPLEX_FULL
)) {
946 bmcr_true_force
= BMCR_SPEED10
| BMCR_FULLDPLX
;
947 } else if ((speed
== SPEED_100
) && (duplex
== DUPLEX_HALF
)) {
948 bmcr_true_force
= BMCR_SPEED100
;
949 } else if ((speed
== SPEED_100
) && (duplex
== DUPLEX_FULL
)) {
950 bmcr_true_force
= BMCR_SPEED100
| BMCR_FULLDPLX
;
953 mdio_write(unit
, 0x1f, 0x0000);
954 mdio_write(unit
, MII_BMCR
, bmcr_true_force
);
961 static void rtl8168nic_start_rx(struct net_device
*unit
)
963 // struct rtl8168_priv *np = get_pcnpriv(unit);
964 // APTR base = get_hwbase(unit);
966 RTLD(bug("[%s] rtl8168nic_start_rx\n", unit
->rtl8168u_name
))
967 // Already running? Stop it.
968 /* TODO: Handle starting/stopping Rx */
971 static void rtl8168nic_stop_rx(struct net_device
*unit
)
973 // APTR base = get_hwbase(unit);
975 RTLD(bug("[%s] rtl8168nic_stop_rx\n", unit
->rtl8168u_name
))
976 /* TODO: Handle starting/stopping Rx */
979 static void rtl8168nic_start_tx(struct net_device
*unit
)
981 // APTR base = get_hwbase(unit);
983 RTLD(bug("[%s] rtl8168nic_start_tx()\n", unit
->rtl8168u_name
))
984 /* TODO: Handle starting/stopping Tx */
987 static void rtl8168nic_stop_tx(struct net_device
*unit
)
989 // APTR base = get_hwbase(unit);
991 RTLD(bug("[%s] rtl8168nic_stop_tx()\n", unit
->rtl8168u_name
))
992 /* TODO: Handle starting/stopping Tx */
995 static void rtl8168nic_txrx_reset(struct net_device
*unit
)
997 // struct rtl8168_priv *np = get_pcnpriv(unit);
998 // APTR base = get_hwbase(unit);
1000 RTLD(bug("[%s] rtl8168nic_txrx_reset()\n", unit
->rtl8168u_name
))
1005 * rtl8168nic_SetMulticast: unit->set_multicast function
1006 * Called with unit->xmit_lock held.
1008 static void rtl8168nic_SetMulticast(struct net_device
*unit
)
1010 // struct rtl8168_priv *np = get_pcnpriv(unit);
1011 // APTR base = get_hwbase(unit);
1016 RTLD(bug("[%s] rtl8168nic_SetMulticast()\n", unit
->rtl8168u_name
))
1018 memset(addr
, 0, sizeof(addr
));
1019 memset(mask
, 0, sizeof(mask
));
1022 static void rtl8168nic_DeInit(struct net_device
*unit
)
1024 /* TODO: Clean up / DeInit hardware */
1027 static void rtl8168nic_GetMACAddr(struct net_device
*unit
, char *addr
, BOOL fromROM
)
1029 APTR base
= get_hwbase(unit
);
1032 RTLD(bug("[%s] rtl8168nic_GetMACAddr()\n",unit
->rtl8168u_name
))
1033 /* Get MAC address. FIXME: read EEPROM */
1034 for (i
= 0; i
< MAC_ADDR_LEN
; i
++)
1035 addr
[i
] = RTL_R8(base
+ MAC0
+ i
);
1038 static void rtl8168nic_SetMACAddr(struct net_device
*unit
)
1040 APTR base
= get_hwbase(unit
);
1043 RTLD(bug("[%s] rtl8168nic_SetMACAddr()\n",unit
->rtl8168u_name
))
1045 RTL_W8(base
+ (Cfg9346
), Cfg9346_Unlock
);
1047 RTL_W32(base
+ (MAC0
),
1048 unit
->rtl8168u_dev_addr
[0] |
1049 (unit
->rtl8168u_dev_addr
[1] << 8) |
1050 (unit
->rtl8168u_dev_addr
[2] << 16) |
1051 (unit
->rtl8168u_dev_addr
[3] << 24));
1052 RTL_W32(base
+ (MAC4
),
1053 unit
->rtl8168u_dev_addr
[4] |
1054 (unit
->rtl8168u_dev_addr
[5] << 8));
1056 RTL_W8(base
+ (Cfg9346
), Cfg9346_Lock
);
1059 /* Read it back to be certain! */
1061 rtl8168nic_GetMACAddr(unit
, newmac
, FALSE
);
1063 bug("[%s] rtl8168nic_SetMACAddr: New MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", unit
->rtl8168u_name
,
1064 newmac
[0], newmac
[1], newmac
[2],
1065 newmac
[3], newmac
[4], newmac
[5])
1069 static void rtl8168nic_LinkOption(struct net_device
*unit
, UBYTE
*aut
, UWORD
*spd
, UBYTE
*dup
)
1071 unsigned char opt_speed
;
1072 unsigned char opt_duplex
;
1073 unsigned char opt_autoneg
;
1075 opt_speed
= ((unit
->rtl8168u_UnitNum
< MAX_UNITS
) && (unit
->rtl8168u_UnitNum
>= 0)) ? unit
->rtl8168u_device
->speed
[unit
->rtl8168u_UnitNum
] : 0xff;
1076 opt_duplex
= ((unit
->rtl8168u_UnitNum
< MAX_UNITS
) && (unit
->rtl8168u_UnitNum
>= 0)) ? unit
->rtl8168u_device
->duplex
[unit
->rtl8168u_UnitNum
] : 0xff;
1077 opt_autoneg
= ((unit
->rtl8168u_UnitNum
< MAX_UNITS
) && (unit
->rtl8168u_UnitNum
>= 0)) ? unit
->rtl8168u_device
->autoneg
[unit
->rtl8168u_UnitNum
] : 0xff;
1079 if ((opt_speed
== 0xff) |
1080 (opt_duplex
== 0xff) |
1081 (opt_autoneg
== 0xff)) {
1084 *aut
= AUTONEG_ENABLE
;
1086 *spd
= unit
->rtl8168u_device
->speed
[unit
->rtl8168u_UnitNum
];
1087 *dup
= unit
->rtl8168u_device
->duplex
[unit
->rtl8168u_UnitNum
];
1088 *aut
= unit
->rtl8168u_device
->autoneg
[unit
->rtl8168u_UnitNum
];
1092 static void rtl8168nic_Init(struct net_device
*unit
)
1094 struct pHidd_PCIDevice_WriteConfigByte pcibyte
;
1096 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
1097 APTR base
= get_hwbase(unit
);
1098 UBYTE autoneg
, duplex
;
1103 RTLD(bug("[%s] rtl8168nic_Init(unit @ %p)\n", unit
->rtl8168u_name
, unit
))
1105 /* Identify chip attached to board */
1106 rtl8168nic_GetMACVersion(unit
);
1107 rtl8168nic_PrintMACVersion(unit
);
1109 for (i
= (sizeof(rtl_chip_info
) / sizeof(rtl_chip_info
[0])) - 1; i
>= 0; i
--) {
1110 if (np
->mcfg
== rtl_chip_info
[i
].mcfg
)
1115 /* Unknown chip: assume array element #0, original RTL-8168 */
1116 RTLD(bug("[%s] rtl8168nic_Init: Unknown Realtek chip version, assuming %s\n", unit
->rtl8168u_name
, rtl_chip_info
[0].name
))
1121 unit
->rtl8168u_rtl_chipname
= rtl_chip_info
[np
->chipset
].name
;
1123 RTL_W8(base
+ (Cfg9346
), Cfg9346_Unlock
);
1124 RTL_W8(base
+ (Config1
), RTL_R8(base
+ Config1
) | PMEnable
);
1125 RTL_W8(base
+ (Config5
), RTL_R8(base
+ Config5
) & PMEStatus
);
1126 RTL_W8(base
+ (Cfg9346
), Cfg9346_Lock
);
1128 RTLD(bug("[%s] rtl8168nic_Init: Power Management enabled\n", unit
->rtl8168u_name
))
1131 /* RTL_W8(base + (Cfg9346), Cfg9346_Unlock);
1132 np->features |= rtl8168_try_msi(pdev, base);
1133 RTL_W8(base + (Cfg9346), Cfg9346_Lock); */
1136 rtl8168nic_GetMACAddr(unit
, &np
->orig_mac
[0], TRUE
);
1138 unit
->rtl8168u_dev_addr
[0] = unit
->rtl8168u_org_addr
[0] = np
->orig_mac
[0];
1139 unit
->rtl8168u_dev_addr
[1] = unit
->rtl8168u_org_addr
[1] = np
->orig_mac
[1];
1140 unit
->rtl8168u_dev_addr
[2] = unit
->rtl8168u_org_addr
[2] = np
->orig_mac
[2];
1141 unit
->rtl8168u_dev_addr
[3] = unit
->rtl8168u_org_addr
[3] = np
->orig_mac
[3];
1142 unit
->rtl8168u_dev_addr
[4] = unit
->rtl8168u_org_addr
[4] = np
->orig_mac
[4];
1143 unit
->rtl8168u_dev_addr
[5] = unit
->rtl8168u_org_addr
[5] = np
->orig_mac
[5];
1145 RTLD(bug("[%s] rtl8168nic_Init: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", unit
->rtl8168u_name
,
1146 unit
->rtl8168u_dev_addr
[0], unit
->rtl8168u_dev_addr
[1], unit
->rtl8168u_dev_addr
[2],
1147 unit
->rtl8168u_dev_addr
[3], unit
->rtl8168u_dev_addr
[4], unit
->rtl8168u_dev_addr
[5]))
1149 bug("[%s] rtl8168nic_Init: This product is covered by one or more of the following patents:\n", unit
->rtl8168u_name
);
1150 bug("[%s] rtl8168nic_Init: US5,307,459, US5,434,872, US5,732,094, US6,570,884, US6,115,776, and US6,327,625.\n", unit
->rtl8168u_name
);
1153 unit->features |= NETIF_F_IP_CSUM;
1155 np
->cp_cmd
|= RxChkSum
;
1156 np
->cp_cmd
|= RTL_R16(base
+ (CPlusCmd
));
1158 np
->intr_mask
= unit
->rtl8168u_intr_mask
;
1160 rtl8168nic_HWPHYConfig(unit
);
1162 RTLD(bug("[%s] rtl8168nic_Init: PHY Configured\n", unit
->rtl8168u_name
))
1164 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1165 pcibyte
.reg
= PCI_LATENCY_TIMER
;
1167 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1169 rtl8168nic_LinkOption(unit
, &autoneg
, &speed
, &duplex
);
1171 rtl8168nic_SetSpeedXMII(unit
, autoneg
, speed
, duplex
);
1173 RTLD(bug("[%s] rtl8168nic_Init: Link Speed %dbps %s duplex %s\n", unit
->rtl8168u_name
, speed
, (duplex
== DUPLEX_HALF
) ? "half" :"full", (autoneg
== AUTONEG_ENABLE
) ? "(autoneg)" :""))
1176 static void rtl8168nic_drain_tx(struct net_device
*unit
)
1178 // struct rtl8168_priv *np = get_pcnpriv(unit);
1180 // for (i = 0; i < NUM_TX_DESC; i++) {
1181 /* TODO: rtl8168nic_drain_tx does nothing atm. */
1185 static void rtl8168nic_drain_rx(struct net_device
*unit
)
1187 // struct rtl8168_priv *np = get_pcnpriv(unit);
1189 // for (i = 0; i < RX_RING_SIZE; i++) {
1190 /* TODO: rtl8168nic_drain_rx does nothing atm. */
1195 static void drain_ring(struct net_device
*unit
)
1197 rtl8168nic_drain_tx(unit
);
1198 rtl8168nic_drain_rx(unit
);
1201 static int request_irq(struct net_device
*unit
)
1204 RTLD(bug("[%s] request_irq()\n", unit
->rtl8168u_name
))
1206 if (!unit
->rtl8168u_IntsAdded
)
1208 AddIntServer(INTB_KERNEL
+ unit
->rtl8168u_IRQ
,
1209 &unit
->rtl8168u_irqhandler
);
1210 AddIntServer(INTB_VERTB
, &unit
->rtl8168u_touthandler
);
1211 unit
->rtl8168u_IntsAdded
= TRUE
;
1214 RTLD(bug("[%s] request_irq: IRQ Handlers configured\n", unit
->rtl8168u_name
))
1218 static void free_irq(struct net_device
*unit
)
1220 if (unit
->rtl8168u_IntsAdded
)
1222 RemIntServer(INTB_KERNEL
+ unit
->rtl8168u_IRQ
,
1223 &unit
->rtl8168u_irqhandler
);
1224 RemIntServer(INTB_VERTB
, &unit
->rtl8168u_touthandler
);
1225 unit
->rtl8168u_IntsAdded
= FALSE
;
1229 static void rtl8168nic_SetRXBufSize(struct net_device
*unit
)
1231 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
1232 APTR base
= get_hwbase(unit
);
1233 unsigned int mtu
= unit
->rtl8168u_mtu
;
1235 RTLD(bug("[%s] rtl8168nic_SetRXBufSize()\n", unit
->rtl8168u_name
))
1237 np
->rx_buf_sz
= (mtu
> ETH_DATA_LEN
) ? mtu
+ ETH_HLEN
+ 8 : RX_BUF_SIZE
;
1239 RTL_W16(base
+ (RxMaxSize
), np
->rx_buf_sz
+ 1);
1242 static void rtl8168nic_NICReset(struct net_device
*unit
)
1244 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
1245 APTR base
= get_hwbase(unit
);
1248 RTLD(bug("[%s] rtl8168nic_NICReset()\n", unit
->rtl8168u_name
))
1250 if ((np
->mcfg
!= CFG_METHOD_1
) &&
1251 (np
->mcfg
!= CFG_METHOD_2
) &&
1252 (np
->mcfg
!= CFG_METHOD_3
)) {
1253 RTL_W8(base
+ (ChipCmd
), StopReq
| CmdRxEnb
| CmdTxEnb
);
1257 /* Soft reset the chip. */
1258 RTL_W8(base
+ (ChipCmd
), CmdReset
);
1260 /* Check that the chip has finished the reset. */
1261 for (i
= 1000; i
> 0; i
--) {
1262 if ((RTL_R8(base
+ (ChipCmd
)) & CmdReset
) == 0)
1268 static void rtl8168nic_SetRxMode(struct net_device
*unit
)
1270 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
1271 APTR base
= get_hwbase(unit
);
1272 // unsigned long flags;
1273 ULONG mc_filter
[2]; /* Multicast hash filter */
1274 int i
, j
, k
, rx_mode
;
1277 RTLD(bug("[%s] rtl8168nic_SetRxMode()\n", unit
->rtl8168u_name
))
1279 if (unit
->rtl8168u_flags
& IFF_PROMISC
) {
1280 /* Unconditionally log net taps. */
1281 RTLD(bug("[%s] rtl8168nic_SetRxMode: Promiscuous mode enabled\n", unit
->rtl8168u_name
))
1283 AcceptBroadcast
| AcceptMulticast
| AcceptMyPhys
|
1285 mc_filter
[1] = mc_filter
[0] = 0xffffffff;
1286 } else if ((unit
->rtl8168u_mc_count
> unit
->rtl8168u_device
->rtl8168b_MulticastFilterLimit
)
1287 || (unit
->rtl8168u_flags
& IFF_ALLMULTI
)) {
1288 /* Too many to filter perfectly -- accept all multicasts. */
1289 rx_mode
= AcceptBroadcast
| AcceptMulticast
| AcceptMyPhys
;
1290 mc_filter
[1] = mc_filter
[0] = 0xffffffff;
1292 struct dev_mc_list
*mclist
;
1293 rx_mode
= AcceptBroadcast
| AcceptMyPhys
;
1294 mc_filter
[1] = mc_filter
[0] = 0;
1295 for (i
= 0, mclist
= unit
->rtl8168u_mc_list
; mclist
&& i
< unit
->rtl8168u_mc_count
;
1296 i
++, mclist
= mclist
->next
) {
1297 // int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
1298 // mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
1299 rx_mode
|= AcceptMulticast
;
1303 np
->rtl8168_rx_config
= rtl_chip_info
[np
->chipset
].RCR_Cfg
;
1304 tmp
= np
->rtl8168_rx_config
| rx_mode
| (RTL_R32(base
+ (RxConfig
)) & rtl_chip_info
[np
->chipset
].RxConfigMask
);
1306 for (j
= 0; j
< 2; j
++) {
1307 ULONG mask
= 0x000000ff;
1313 for (k
= 0; k
< 4; k
++) {
1314 tmp1
= mc_filter
[j
] & mask
;
1315 x
= 32 - (8 + 16 * k
);
1319 tmp2
= tmp2
| (tmp1
<< x
);
1321 tmp2
= tmp2
| (tmp1
>> y
);
1325 mc_filter
[j
] = tmp2
;
1328 RTL_W32(base
+ (RxConfig
), tmp
);
1329 RTL_W32(base
+ (MAR0
+ 0), mc_filter
[1]);
1330 RTL_W32(base
+ (MAR0
+ 4), mc_filter
[0]);
1333 static void rtl8168nic_HWStart(struct net_device
*unit
)
1335 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
1336 APTR base
= get_hwbase(unit
);
1338 struct pHidd_PCIDevice_WriteConfigByte pcibyte
;
1340 UBYTE device_control
;
1344 RTLD(bug("[%s] rtl8168nic_HWStart()\n", unit
->rtl8168u_name
))
1346 rtl8168nic_NICReset(unit
);
1348 RTL_W8(base
+ (Cfg9346
), Cfg9346_Unlock
);
1350 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1352 np
->cp_cmd
|= PktCntrDisable
| INTT_1
;
1353 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1355 RTL_W16(base
+ (IntrMitigate
), 0x5151);
1357 //Work around for RxFIFO overflow
1358 if (np
->mcfg
== CFG_METHOD_1
) {
1359 unit
->rtl8168u_intr_mask
|= RxFIFOOver
| PCSTimeout
;
1360 unit
->rtl8168u_intr_mask
&= ~RxDescUnavail
;
1363 RTL_W32(base
+ (TxDescStartAddrLow
), ((UQUAD
) (IPTR
)np
->TxPhyAddr
& DMA_32BIT_MASK
));
1364 RTL_W32(base
+ (TxDescStartAddrHigh
), ((UQUAD
) (IPTR
)np
->TxPhyAddr
>> 32));
1365 RTL_W32(base
+ (RxDescAddrLow
), ((UQUAD
) (IPTR
)np
->RxPhyAddr
& DMA_32BIT_MASK
));
1366 RTL_W32(base
+ (RxDescAddrHigh
), ((UQUAD
) (IPTR
)np
->RxPhyAddr
>> 32));
1368 /* Set Rx Config register */
1369 rtl8168nic_SetRxMode(unit
);
1371 /* Set DMA burst size and Interframe Gap Time */
1372 if (np
->mcfg
== CFG_METHOD_1
) {
1373 RTL_W32(base
+ (TxConfig
), (TX_DMA_BURST_512
<< TxDMAShift
) |
1374 (InterFrameGap
<< TxInterFrameGapShift
));
1376 RTL_W32(base
+ (TxConfig
), (TX_DMA_BURST_unlimited
<< TxDMAShift
) |
1377 (InterFrameGap
<< TxInterFrameGapShift
));
1380 /* Clear the interrupt status register. */
1381 RTL_W16(base
+ (IntrStatus
), 0xFFFF);
1383 if (np
->rx_fifo_overflow
== 0) {
1384 /* Enable all known interrupts by setting the interrupt mask. */
1385 RTL_W16(base
+ (IntrMask
), unit
->rtl8168u_intr_mask
);
1386 netif_start_queue(unit
);
1389 if (np
->mcfg
== CFG_METHOD_4
) {
1390 /*set PCI configuration space offset 0x70F to 0x27*/
1391 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1392 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1393 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1395 RTL_W8(base
+ (DBG_reg
), (0x0E << 4) | Fix_Nak_1
| Fix_Nak_2
);
1397 /*Set EPHY registers begin*/
1398 /*Set EPHY register offset 0x02 bit 11 to 0 and bit 12 to 1*/
1399 ephy_data
= rtl8168nic_EPHYRead(unit
, 0x02);
1400 ephy_data
&= ~(1 << 11);
1401 ephy_data
|= (1 << 12);
1402 rtl8168nic_EPHYWrite(unit
, 0x02, ephy_data
);
1404 /*Set EPHY register offset 0x03 bit 1 to 1*/
1405 ephy_data
= rtl8168nic_EPHYRead(unit
, 0x03);
1406 ephy_data
|= (1 << 1);
1407 rtl8168nic_EPHYWrite(unit
, 0x03, ephy_data
);
1409 /*Set EPHY register offset 0x06 bit 7 to 0*/
1410 ephy_data
= rtl8168nic_EPHYRead(unit
, 0x06);
1411 ephy_data
&= ~(1 << 7);
1412 rtl8168nic_EPHYWrite(unit
, 0x06, ephy_data
);
1413 /*Set EPHY registers end*/
1415 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1417 //disable clock request.
1418 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1421 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1423 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1424 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1425 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1427 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1428 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1429 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1430 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1432 //Set PCI configuration space offset 0x79 to 0x20
1433 /*Increase the Tx performance*/
1434 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1436 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1437 device_control
&= ~0x70;
1438 device_control
|= 0x20;
1439 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1441 pcibyte
.val
= device_control
;
1442 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1444 //tx checksum offload disable
1445 // unit->features &= ~NETIF_F_IP_CSUM;
1447 //rx checksum offload disable
1448 np
->cp_cmd
&= ~RxChkSum
;
1449 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1451 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1452 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1453 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1455 //Set PCI configuration space offset 0x79 to 0x50
1456 /*Increase the Tx performance*/
1457 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1459 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1460 device_control
&= ~0x70;
1461 device_control
|= 0x50;
1462 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1464 pcibyte
.val
= device_control
;
1465 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1467 //tx checksum offload enable
1468 // unit->features |= NETIF_F_IP_CSUM;
1470 //rx checksum offload enable
1471 np
->cp_cmd
|= RxChkSum
;
1472 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1474 } else if (np
->mcfg
== CFG_METHOD_5
) {
1475 /*set PCI configuration space offset 0x70F to 0x27*/
1476 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1477 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1478 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1480 /******set EPHY registers for RTL8168CP begin******/
1481 //Set EPHY register offset 0x01 bit 0 to 1.
1482 ephy_data
= rtl8168nic_EPHYRead(unit
, 0x01);
1483 ephy_data
|= (1 << 0);
1484 rtl8168nic_EPHYWrite(unit
, 0x01, ephy_data
);
1486 //Set EPHY register offset 0x03 bit 10 to 0, bit 9 to 1 and bit 5 to 1.
1487 ephy_data
= rtl8168nic_EPHYRead(unit
, 0x03);
1488 ephy_data
&= ~(1 << 10);
1489 ephy_data
|= (1 << 9);
1490 ephy_data
|= (1 << 5);
1491 rtl8168nic_EPHYWrite(unit
, 0x03, ephy_data
);
1492 /******set EPHY registers for RTL8168CP end******/
1494 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1496 //disable clock request.
1497 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1500 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1502 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1503 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1504 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1506 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1507 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1508 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1509 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1511 //Set PCI configuration space offset 0x79 to 0x20
1512 /*Increase the Tx performance*/
1513 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1515 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1516 device_control
&= ~0x70;
1517 device_control
|= 0x20;
1518 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1520 pcibyte
.val
= device_control
;
1521 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1523 //tx checksum offload disable
1524 // unit->features &= ~NETIF_F_IP_CSUM;
1526 //rx checksum offload disable
1527 np
->cp_cmd
&= ~RxChkSum
;
1528 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1530 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1531 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1532 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1534 //Set PCI configuration space offset 0x79 to 0x50
1535 /*Increase the Tx performance*/
1536 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1538 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1539 device_control
&= ~0x70;
1540 device_control
|= 0x50;
1541 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1543 pcibyte
.val
= device_control
;
1544 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1546 //tx checksum offload enable
1547 // unit->features |= NETIF_F_IP_CSUM;
1549 //rx checksum offload enable
1550 np
->cp_cmd
|= RxChkSum
;
1551 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1553 } else if (np
->mcfg
== CFG_METHOD_6
) {
1554 /*set PCI configuration space offset 0x70F to 0x27*/
1555 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1556 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1557 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1559 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1561 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1562 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1563 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1565 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1566 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1567 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1568 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1570 //Set PCI configuration space offset 0x79 to 0x20
1571 /*Increase the Tx performance*/
1572 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1574 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1575 device_control
&= ~0x70;
1576 device_control
|= 0x20;
1577 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1579 pcibyte
.val
= device_control
;
1580 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1582 //tx checksum offload disable
1583 // unit->features &= ~NETIF_F_IP_CSUM;
1585 //rx checksum offload disable
1586 np
->cp_cmd
&= ~RxChkSum
;
1587 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1589 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1590 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1591 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1593 //Set PCI configuration space offset 0x79 to 0x50
1594 /*Increase the Tx performance*/
1595 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1597 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1598 device_control
&= ~0x70;
1599 device_control
|= 0x50;
1600 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1602 pcibyte
.val
= device_control
;
1603 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1605 //tx checksum offload enable
1606 // unit->features |= NETIF_F_IP_CSUM;
1608 //rx checksum offload enable
1609 np
->cp_cmd
|= RxChkSum
;
1610 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1612 } else if (np
->mcfg
== CFG_METHOD_7
) {
1613 /*set PCI configuration space offset 0x70F to 0x27*/
1614 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1615 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1616 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1618 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1619 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1620 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1622 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1624 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1625 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1626 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1627 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1629 //Set PCI configuration space offset 0x79 to 0x20
1630 /*Increase the Tx performance*/
1631 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1633 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1634 device_control
&= ~0x70;
1635 device_control
|= 0x20;
1636 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1638 pcibyte
.val
= device_control
;
1639 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1641 //tx checksum offload disable
1642 // unit->features &= ~NETIF_F_IP_CSUM;
1644 //rx checksum offload disable
1645 np
->cp_cmd
&= ~RxChkSum
;
1646 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1648 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1649 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1650 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1652 //Set PCI configuration space offset 0x79 to 0x50
1653 /*Increase the Tx performance*/
1654 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1656 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1657 device_control
&= ~0x70;
1658 device_control
|= 0x50;
1659 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1661 pcibyte
.val
= device_control
;
1662 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1664 //tx checksum offload enable
1665 // unit->features |= NETIF_F_IP_CSUM;
1667 //rx checksum offload enable
1668 np
->cp_cmd
|= RxChkSum
;
1669 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1671 } else if (np
->mcfg
== CFG_METHOD_8
) {
1672 /*set PCI configuration space offset 0x70F to 0x27*/
1673 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1674 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1675 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1677 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1678 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1679 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1681 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1683 RTL_W8(base
+ (0xD1), 0x20);
1685 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1686 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1687 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1688 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1690 //Set PCI configuration space offset 0x79 to 0x20
1691 /*Increase the Tx performance*/
1692 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1694 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1695 device_control
&= ~0x70;
1696 device_control
|= 0x20;
1697 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1699 pcibyte
.val
= device_control
;
1700 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1702 //tx checksum offload disable
1703 // unit->features &= ~NETIF_F_IP_CSUM;
1705 //rx checksum offload disable
1706 np
->cp_cmd
&= ~RxChkSum
;
1707 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1709 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1710 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1711 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1713 //Set PCI configuration space offset 0x79 to 0x50
1714 /*Increase the Tx performance*/
1715 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1717 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1718 device_control
&= ~0x70;
1719 device_control
|= 0x50;
1720 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1722 pcibyte
.val
= device_control
;
1723 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1725 //tx checksum offload enable
1726 // unit->features |= NETIF_F_IP_CSUM;
1728 //rx checksum offload enable
1729 np
->cp_cmd
|= RxChkSum
;
1730 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1733 } else if (np
->mcfg
== CFG_METHOD_9
) {
1734 /*set PCI configuration space offset 0x70F to 0x27*/
1735 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1736 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1737 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1739 //disable clock request.
1740 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1743 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1745 RTL_W8(base
+ (Config1
), 0xCF);
1746 RTL_W8(base
+ (Config2
), 0x9C);
1747 RTL_W8(base
+ (Config3
), 0x62);
1749 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1750 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1751 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1752 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1754 //Set PCI configuration space offset 0x79 to 0x20
1755 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1757 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1758 device_control
&= ~0x70;
1759 device_control
|= 0x20;
1760 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1762 pcibyte
.val
= device_control
;
1763 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1765 //tx checksum offload disable
1766 // unit->features &= ~NETIF_F_IP_CSUM;
1768 //rx checksum offload disable
1769 np
->cp_cmd
&= ~RxChkSum
;
1770 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1772 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1773 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1774 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1776 //Set PCI configuration space offset 0x79 to 0x50
1777 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1779 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1780 device_control
&= ~0x70;
1781 device_control
|= 0x50;
1782 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1784 pcibyte
.val
= device_control
;
1785 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1787 //tx checksum offload enable
1788 // unit->features |= NETIF_F_IP_CSUM;
1790 //rx checksum offload enable
1791 np
->cp_cmd
|= RxChkSum
;
1792 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1795 /******set EPHY registers begin******/
1796 rtl8168nic_EPHYWrite(unit
, 0x01, 0x7C7D);
1797 rtl8168nic_EPHYWrite(unit
, 0x02, 0x091F);
1798 rtl8168nic_EPHYWrite(unit
, 0x06, 0xB271);
1799 rtl8168nic_EPHYWrite(unit
, 0x07, 0xCE00);
1800 /******set EPHY registers end******/
1802 } else if (np
->mcfg
== CFG_METHOD_10
) {
1803 /*set PCI configuration space offset 0x70F to 0x27*/
1804 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1805 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1806 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1808 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1809 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1810 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1811 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1813 //Set PCI configuration space offset 0x79 to 0x20
1814 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1816 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1817 device_control
&= ~0x70;
1818 device_control
|= 0x20;
1819 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1821 pcibyte
.val
= device_control
;
1822 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1824 //tx checksum offload disable
1825 // unit->features &= ~NETIF_F_IP_CSUM;
1827 //rx checksum offload disable
1828 np
->cp_cmd
&= ~RxChkSum
;
1829 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1831 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1832 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1833 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1835 //Set PCI configuration space offset 0x79 to 0x50
1836 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1838 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1839 device_control
&= ~0x70;
1840 device_control
|= 0x50;
1841 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1843 pcibyte
.val
= device_control
;
1844 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1846 //tx checksum offload enable
1847 // unit->features |= NETIF_F_IP_CSUM;
1849 //rx checksum offload enable
1850 np
->cp_cmd
|= RxChkSum
;
1851 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1854 RTL_W8(base
+ (Config1
), 0xDF);
1856 /******set EPHY registers begin******/
1857 rtl8168nic_EPHYWrite(unit
, 0x01, 0x7C7D);
1858 rtl8168nic_EPHYWrite(unit
, 0x02, 0x091F);
1859 rtl8168nic_EPHYWrite(unit
, 0x03, 0xC5BA);
1860 rtl8168nic_EPHYWrite(unit
, 0x06, 0xB279);
1861 rtl8168nic_EPHYWrite(unit
, 0x07, 0xAF00);
1862 rtl8168nic_EPHYWrite(unit
, 0x1E, 0xB8EB);
1863 /******set EPHY registers end******/
1865 //disable clock request.
1866 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1869 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1871 } else if (np
->mcfg
== CFG_METHOD_11
) {
1872 /*set PCI configuration space offset 0x70F to 0x27*/
1873 /*When the register offset of PCI configuration space larger than 0xff, use CSI to access it.*/
1874 csi_tmp
= rtl8168nic_CSIRead(unit
, 0x70c) & 0x00ffffff;
1875 rtl8168nic_CSIWrite(unit
, 0x70c, csi_tmp
| 0x27000000);
1877 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1878 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1879 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) | Jumbo_En0
);
1880 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | Jumbo_En1
);
1882 //Set PCI configuration space offset 0x79 to 0x20
1883 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1885 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1886 device_control
&= ~0x70;
1887 device_control
|= 0x20;
1888 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1890 pcibyte
.val
= device_control
;
1891 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1893 //tx checksum offload disable
1894 // unit->features &= ~NETIF_F_IP_CSUM;
1896 //rx checksum offload disable
1897 np
->cp_cmd
&= ~RxChkSum
;
1898 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1900 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1901 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Jumbo_En0
);
1902 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~Jumbo_En1
);
1904 //Set PCI configuration space offset 0x79 to 0x50
1905 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1907 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1908 device_control
&= ~0x70;
1909 device_control
|= 0x50;
1910 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1912 pcibyte
.val
= device_control
;
1913 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1915 //tx checksum offload enable
1916 // unit->features |= NETIF_F_IP_CSUM;
1918 //rx checksum offload enable
1919 np
->cp_cmd
|= RxChkSum
;
1920 RTL_W16(base
+ (CPlusCmd
), np
->cp_cmd
);
1923 RTL_W8(base
+ (Config1
), 0xDF);
1925 /******set EPHY registers begin******/
1926 rtl8168nic_EPHYWrite(unit
, 0x01, 0x6C7F);
1927 rtl8168nic_EPHYWrite(unit
, 0x02, 0x011F);
1928 rtl8168nic_EPHYWrite(unit
, 0x03, 0xC1B2);
1929 rtl8168nic_EPHYWrite(unit
, 0x1A, 0x0546);
1930 rtl8168nic_EPHYWrite(unit
, 0x1C, 0x80C4);
1931 rtl8168nic_EPHYWrite(unit
, 0x1D, 0x78E4);
1932 /******set EPHY registers end******/
1934 //disable clock request.
1935 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1938 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1940 RTL_W8(base
+ (0xF3), RTL_R8(base
+ (0xF3)) | (1 << 2));
1942 } else if (np
->mcfg
== CFG_METHOD_1
) {
1943 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1945 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1946 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1947 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1949 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1950 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1952 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1953 device_control
&= ~0x70;
1954 device_control
|= 0x28;
1955 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1957 pcibyte
.val
= device_control
;
1958 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1960 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1962 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1963 device_control
&= ~0x70;
1964 device_control
|= 0x58;
1965 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1967 pcibyte
.val
= device_control
;
1968 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1970 } else if (np
->mcfg
== CFG_METHOD_2
) {
1971 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
1973 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
1974 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
1975 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
1977 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
1978 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1980 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1981 device_control
&= ~0x70;
1982 device_control
|= 0x28;
1983 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1985 pcibyte
.val
= device_control
;
1986 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1988 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
1989 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | (1 << 0));
1991 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
1993 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
1994 device_control
&= ~0x70;
1995 device_control
|= 0x58;
1996 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
1998 pcibyte
.val
= device_control
;
1999 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2001 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
2002 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~(1 << 0));
2004 } else if (np
->mcfg
== CFG_METHOD_3
) {
2005 RTL_W8(base
+ (Config3
), RTL_R8(base
+ (Config3
)) & ~Beacon_en
);
2007 RTL_W16(base
+ (CPlusCmd
), RTL_R16(base
+ (CPlusCmd
)) &
2008 ~(EnableBist
| Macdbgo_oe
| Force_halfdup
| Force_rxflow_en
| Force_txflow_en
|
2009 Cxpl_dbg_sel
| ASF
| PktCntrDisable
| Macdbgo_sel
));
2011 if (unit
->rtl8168u_mtu
> ETH_DATA_LEN
) {
2012 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
2014 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2015 device_control
&= ~0x70;
2016 device_control
|= 0x28;
2017 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
2019 pcibyte
.val
= device_control
;
2020 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2022 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
2023 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) | (1 << 0));
2025 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
2027 device_control
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2028 device_control
&= ~0x70;
2029 device_control
|= 0x58;
2030 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_WriteConfigByte
);
2032 pcibyte
.val
= device_control
;
2033 OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2035 RTL_W8(base
+ (Reserved1
), Reserved1_data
);
2036 RTL_W8(base
+ (Config4
), RTL_R8(base
+ (Config4
)) & ~(1 << 0));
2040 if ((np
->mcfg
== CFG_METHOD_1
) || (np
->mcfg
== CFG_METHOD_2
) || (np
->mcfg
== CFG_METHOD_3
)) {
2041 /* csum offload command for RTL8168B/8111B */
2042 np
->tx_tcp_csum_cmd
= TxIPCS
| TxTCPCS
;
2043 np
->tx_udp_csum_cmd
= TxIPCS
| TxUDPCS
;
2044 np
->tx_ip_csum_cmd
= TxIPCS
;
2046 /* csum offload command for RTL8168C/8111C and RTL8168CP/8111CP */
2047 np
->tx_tcp_csum_cmd
= TxIPCS_C
| TxTCPCS_C
;
2048 np
->tx_udp_csum_cmd
= TxIPCS_C
| TxUDPCS_C
;
2049 np
->tx_ip_csum_cmd
= TxIPCS_C
;
2052 RTL_W8(base
+ (ChipCmd
), CmdTxEnb
| CmdRxEnb
);
2054 RTL_W8(base
+ (Cfg9346
), Cfg9346_Lock
);
2056 if (!np
->pci_cfg_is_read
) {
2057 struct pHidd_PCIDevice_ReadConfigWord readpciword
;
2059 pcibyte
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigByte
);
2060 pcibyte
.reg
= PCI_COMMAND
;
2061 np
->pci_cfg_space
.cmd
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2063 pcibyte
.reg
= PCI_CACHE_LINE_SIZE
;
2064 np
->pci_cfg_space
.cls
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2066 readpciword
.mID
= OOP_GetMethodID(IID_Hidd_PCIDevice
, moHidd_PCIDevice_ReadConfigWord
);
2067 readpciword
.reg
= PCI_BASE_ADDRESS_0
;
2068 np
->pci_cfg_space
.io_base_l
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2069 readpciword
.reg
= PCI_BASE_ADDRESS_0
+ 2;
2070 np
->pci_cfg_space
.io_base_h
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2071 readpciword
.reg
= PCI_BASE_ADDRESS_2
;
2072 np
->pci_cfg_space
.mem_base_l
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2073 readpciword
.reg
= PCI_BASE_ADDRESS_2
+ 2;
2074 np
->pci_cfg_space
.mem_base_h
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2076 pcibyte
.reg
= PCI_INTERRUPT_LINE
;
2077 np
->pci_cfg_space
.ilr
= (UBYTE
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&pcibyte
);
2079 readpciword
.reg
= PCI_BASE_ADDRESS_4
;
2080 np
->pci_cfg_space
.resv_0x20_l
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2081 readpciword
.reg
= PCI_BASE_ADDRESS_4
+ 2;
2082 np
->pci_cfg_space
.resv_0x20_h
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2083 readpciword
.reg
= PCI_BASE_ADDRESS_5
;
2084 np
->pci_cfg_space
.resv_0x24_l
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2085 readpciword
.reg
= PCI_BASE_ADDRESS_5
+ 2;
2086 np
->pci_cfg_space
.resv_0x24_h
= (UWORD
)OOP_DoMethod(unit
->rtl8168u_PCIDevice
, (OOP_Msg
)&readpciword
);
2088 np
->pci_cfg_is_read
= 1;
2091 rtl8168nic_DSM(unit
, DSM_MAC_INIT
);
2096 static unsigned int rtl8168nic_XMIILinkOK(struct net_device
*unit
)
2098 // struct rtl8168_priv *np = get_pcnpriv(unit);
2099 APTR base
= get_hwbase(unit
);
2101 mdio_write(unit
, 0x1f, 0x0000);
2103 return RTL_R8(base
+ (PHYstatus
)) & LinkStatus
;
2106 void rtl8168_CheckLinkStatus(struct net_device
*unit
)
2108 // struct rtl8168_priv *np = get_pcnpriv(unit);
2109 // APTR base = get_hwbase(unit);
2110 // unsigned long flags;
2112 if (rtl8168nic_XMIILinkOK(unit
)) {
2113 netif_carrier_on(unit
);
2114 RTLD(bug("[%s] rtl8168_CheckLinkStatus: Link Up\n", unit
->rtl8168u_name
))
2116 RTLD(bug("[%s] rtl8168_CheckLinkStatus: Link Down\n", unit
->rtl8168u_name
))
2117 netif_carrier_off(unit
);
2121 static void rtl8168nic_InitRingIndexes(struct rtl8168_priv
*np
)
2129 static void rtl8168nic_TxDescInit(struct rtl8168_priv
*np
)
2133 // memset(np->TxDescArray, 0x0, NUM_TX_DESC * sizeof(struct TxDesc));
2135 for (i
= 0; i
< NUM_TX_DESC
; i
++)
2136 if(i
== (NUM_TX_DESC
- 1))
2137 np
->TxDescArray
[i
].opts1
= AROS_LONG2LE(RingEnd
);
2140 static void rtl8168nic_RxDescInit(struct rtl8168_priv
*np
)
2144 // memset(np->RxDescArray, 0x0, NUM_RX_DESC * sizeof(struct RxDesc));
2146 for (i
= 0; i
< NUM_RX_DESC
; i
++) {
2147 if(i
== (NUM_RX_DESC
- 1))
2148 np
->RxDescArray
[i
].opts1
= AROS_LONG2LE((DescOwn
| RingEnd
| (ULONG
)np
->rx_buf_sz
));
2150 np
->RxDescArray
[i
].opts1
= AROS_LONG2LE(DescOwn
| (ULONG
)np
->rx_buf_sz
);
2154 static ULONG
rtl8168nic_RxFill(struct net_device
*unit
, ULONG start
, ULONG end
)
2156 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
2159 for (cur
= start
; end
- cur
> 0; cur
++) {
2160 int i
= cur
% NUM_RX_DESC
;
2162 if (np
->RxDescArray
[i
].addr
)
2165 if ((np
->RxDescArray
[i
].addr
= (IPTR
)HIDD_PCIDriver_AllocPCIMem(unit
->rtl8168u_PCIDriver
, np
->rx_buf_sz
)) == 0)
2168 // RTLD(bug("[%s] rtl8168nic_RxFill: Rx Buffer %d Allocated @ %p\n", unit->rtl8168u_name, i, np->RxDescArray[i].addr))
2173 static inline void rtl8168nic_MarkAsLastDescriptor(struct RxDesc
*desc
)
2175 desc
->opts1
|= AROS_LONG2LE(RingEnd
);
2178 static int rtl8168nic_InitRings(struct net_device
*unit
)
2180 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
2182 RTLD(bug("[%s] rtl8168nic_InitRings(unit @ %p)\n", unit
->rtl8168u_name
, unit
))
2184 rtl8168nic_InitRingIndexes(np
);
2186 rtl8168nic_TxDescInit(np
);
2187 rtl8168nic_RxDescInit(np
);
2189 if (rtl8168nic_RxFill(unit
, 0, NUM_RX_DESC
) != NUM_RX_DESC
)
2192 rtl8168nic_MarkAsLastDescriptor(np
->RxDescArray
+ NUM_RX_DESC
- 1);
2197 // rtl8168_rx_clear(np);
2201 static int rtl8168nic_Open(struct net_device
*unit
)
2203 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
2204 // APTR base = get_hwbase(unit);
2207 RTLD(bug("[%s] rtl8168nic_Open(unit @ %p)\n", unit
->rtl8168u_name
, unit
))
2209 rtl8168nic_SetRXBufSize(unit
);
2211 ret
= request_irq(unit
);
2215 np
->TxDescArray
= HIDD_PCIDriver_AllocPCIMem(unit
->rtl8168u_PCIDriver
, R8168_TX_RING_BYTES
);
2216 np
->TxPhyAddr
= np
->TxDescArray
;
2218 np
->RxDescArray
= HIDD_PCIDriver_AllocPCIMem(unit
->rtl8168u_PCIDriver
, R8168_RX_RING_BYTES
);
2219 np
->RxPhyAddr
= np
->RxDescArray
;
2221 if ((np
->TxDescArray
) && (np
->RxDescArray
))
2223 RTLD(bug("[%s] rtl8168nic_Open: Allocated Descriptor Arrays - Tx @ %p (%d bytes), Rx @ %p (%d bytes)\n", unit
->rtl8168u_name
,
2224 np
->TxDescArray
, R8168_TX_RING_BYTES
,
2225 np
->RxDescArray
, R8168_RX_RING_BYTES
))
2226 if (rtl8168nic_InitRings(unit
) == 0)
2228 rtl8168nic_HWStart(unit
);
2230 // if (np->esd_flag == 0) {
2231 // rtl8168_request_esd_timer(unit);
2234 // rtl8168_request_link_timer(unit);
2236 rtl8168nic_DSM(unit
, DSM_IF_UP
);
2238 rtl8168_CheckLinkStatus(unit
);
2242 RTLD(bug("[%s] rtl8168nic_Open: Failed to initialise Descriptor Arrays!\n",unit
->rtl8168u_name
))
2247 RTLD(bug("[%s] rtl8168nic_Open: Failed to Allocate Descriptor Arrays!\n",unit
->rtl8168u_name
))
2256 static int rtl8168nic_Close(struct net_device
*unit
)
2258 struct rtl8168_priv
*np
= get_pcnpriv(unit
);
2260 RTLD(bug("[%s] rtl8168nic_Close()\n", unit
->rtl8168u_name
))
2262 unit
->rtl8168u_flags
&= ~IFF_UP
;
2264 ObtainSemaphore(&np
->lock
);
2265 // np->in_shutdown = 1;
2266 ReleaseSemaphore(&np
->lock
);
2268 unit
->rtl8168u_toutNEED
= FALSE
;
2270 netif_stop_queue(unit
);
2271 ObtainSemaphore(&np
->lock
);
2273 rtl8168nic_DeInit(unit
);
2275 ReleaseSemaphore(&np
->lock
);
2281 // HIDD_PCIDriver_FreePCIMem(unit->rtl8168u_PCIDriver, np->rx_buffer);
2282 // HIDD_PCIDriver_FreePCIMem(unit->rtl8168u_PCIDriver, np->tx_buffer);
2284 ReportEvents(LIBBASE
, unit
, S2EVENT_OFFLINE
);
2290 void rtl8168nic_get_functions(struct net_device
*Unit
)
2292 Unit
->initialize
= rtl8168nic_Init
;
2293 Unit
->deinitialize
= rtl8168nic_DeInit
;
2294 Unit
->start
= rtl8168nic_Open
;
2295 Unit
->stop
= rtl8168nic_Close
;
2296 Unit
->set_mac_address
= rtl8168nic_SetMACAddr
;
2297 Unit
->set_multicast
= rtl8168nic_SetMulticast
;