2 * Freescale Three Speed Ethernet Controller driver
4 * This software may be used and distributed according to the
5 * terms of the GNU Public License, Version 2, incorporated
8 * Copyright 2004-2009 Freescale Semiconductor, Inc.
9 * (C) Copyright 2003, Motorola, Inc.
20 #include <asm/errno.h>
24 DECLARE_GLOBAL_DATA_PTR
;
28 static uint rxIdx
; /* index of the current RX buffer */
29 static uint txIdx
; /* index of the current TX buffer */
31 typedef volatile struct rtxbd
{
32 txbd8_t txbd
[TX_BUF_CNT
];
33 rxbd8_t rxbd
[PKTBUFSRX
];
36 #define MAXCONTROLLERS (8)
38 static struct tsec_private
*privlist
[MAXCONTROLLERS
];
39 static int num_tsecs
= 0;
42 static RTXBD rtx
__attribute__ ((aligned(8)));
44 #error "rtx must be 64-bit aligned"
47 static int tsec_send(struct eth_device
*dev
,
48 volatile void *packet
, int length
);
49 static int tsec_recv(struct eth_device
*dev
);
50 static int tsec_init(struct eth_device
*dev
, bd_t
* bd
);
51 static int tsec_initialize(bd_t
* bis
, struct tsec_info_struct
*tsec_info
);
52 static void tsec_halt(struct eth_device
*dev
);
53 static void init_registers(volatile tsec_t
* regs
);
54 static void startup_tsec(struct eth_device
*dev
);
55 static int init_phy(struct eth_device
*dev
);
56 void write_phy_reg(struct tsec_private
*priv
, uint regnum
, uint value
);
57 uint
read_phy_reg(struct tsec_private
*priv
, uint regnum
);
58 static struct phy_info
*get_phy_info(struct eth_device
*dev
);
59 static void phy_run_commands(struct tsec_private
*priv
, struct phy_cmd
*cmd
);
60 static void adjust_link(struct eth_device
*dev
);
61 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
62 && !defined(BITBANGMII)
63 static int tsec_miiphy_write(char *devname
, unsigned char addr
,
64 unsigned char reg
, unsigned short value
);
65 static int tsec_miiphy_read(char *devname
, unsigned char addr
,
66 unsigned char reg
, unsigned short *value
);
68 #ifdef CONFIG_MCAST_TFTP
69 static int tsec_mcast_addr (struct eth_device
*dev
, u8 mcast_mac
, u8 set
);
72 /* Default initializations for TSEC controllers. */
74 static struct tsec_info_struct tsec_info
[] = {
76 STD_TSEC_INFO(1), /* TSEC1 */
79 STD_TSEC_INFO(2), /* TSEC2 */
81 #ifdef CONFIG_MPC85XX_FEC
83 .regs
= (tsec_t
*)(TSEC_BASE_ADDR
+ 0x2000),
84 .miiregs
= (tsec_mdio_t
*)(MDIO_BASE_ADDR
),
85 .devname
= CONFIG_MPC85XX_FEC_NAME
,
86 .phyaddr
= FEC_PHY_ADDR
,
91 STD_TSEC_INFO(3), /* TSEC3 */
94 STD_TSEC_INFO(4), /* TSEC4 */
98 int tsec_eth_init(bd_t
*bis
, struct tsec_info_struct
*tsecs
, int num
)
102 for (i
= 0; i
< num
; i
++)
103 tsec_initialize(bis
, &tsecs
[i
]);
108 int tsec_standard_init(bd_t
*bis
)
110 return tsec_eth_init(bis
, tsec_info
, ARRAY_SIZE(tsec_info
));
113 /* Initialize device structure. Returns success if PHY
114 * initialization succeeded (i.e. if it recognizes the PHY)
116 static int tsec_initialize(bd_t
* bis
, struct tsec_info_struct
*tsec_info
)
118 struct eth_device
*dev
;
120 struct tsec_private
*priv
;
122 dev
= (struct eth_device
*)malloc(sizeof *dev
);
127 memset(dev
, 0, sizeof *dev
);
129 priv
= (struct tsec_private
*)malloc(sizeof(*priv
));
134 privlist
[num_tsecs
++] = priv
;
135 priv
->regs
= tsec_info
->regs
;
136 priv
->phyregs
= tsec_info
->miiregs
;
137 priv
->phyregs_sgmii
= tsec_info
->miiregs_sgmii
;
139 priv
->phyaddr
= tsec_info
->phyaddr
;
140 priv
->flags
= tsec_info
->flags
;
142 sprintf(dev
->name
, tsec_info
->devname
);
145 dev
->init
= tsec_init
;
146 dev
->halt
= tsec_halt
;
147 dev
->send
= tsec_send
;
148 dev
->recv
= tsec_recv
;
149 #ifdef CONFIG_MCAST_TFTP
150 dev
->mcast
= tsec_mcast_addr
;
153 /* Tell u-boot to get the addr from the env */
154 for (i
= 0; i
< 6; i
++)
155 dev
->enetaddr
[i
] = 0;
160 priv
->regs
->maccfg1
|= MACCFG1_SOFT_RESET
;
161 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
162 priv
->regs
->maccfg1
&= ~(MACCFG1_SOFT_RESET
);
164 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
165 && !defined(BITBANGMII)
166 miiphy_register(dev
->name
, tsec_miiphy_read
, tsec_miiphy_write
);
169 /* Try to initialize PHY here, and return */
170 return init_phy(dev
);
173 /* Initializes data structures and registers for the controller,
174 * and brings the interface up. Returns the link status, meaning
175 * that it returns success if the link is up, failure otherwise.
176 * This allows u-boot to find the first active controller.
178 static int tsec_init(struct eth_device
*dev
, bd_t
* bd
)
181 char tmpbuf
[MAC_ADDR_LEN
];
183 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
184 volatile tsec_t
*regs
= priv
->regs
;
186 /* Make sure the controller is stopped */
189 /* Init MACCFG2. Defaults to GMII */
190 regs
->maccfg2
= MACCFG2_INIT_SETTINGS
;
193 regs
->ecntrl
= ECNTRL_INIT_SETTINGS
;
195 /* Copy the station address into the address registers.
196 * Backwards, because little endian MACS are dumb */
197 for (i
= 0; i
< MAC_ADDR_LEN
; i
++) {
198 tmpbuf
[MAC_ADDR_LEN
- 1 - i
] = dev
->enetaddr
[i
];
200 tempval
= (tmpbuf
[0] << 24) | (tmpbuf
[1] << 16) | (tmpbuf
[2] << 8) |
203 regs
->macstnaddr1
= tempval
;
205 tempval
= *((uint
*) (tmpbuf
+ 4));
207 regs
->macstnaddr2
= tempval
;
209 /* reset the indices to zero */
213 /* Clear out (for the most part) the other registers */
214 init_registers(regs
);
216 /* Ready the device for tx/rx */
219 /* If there's no link, fail */
220 return (priv
->link
? 0 : -1);
223 /* Writes the given phy's reg with value, using the specified MDIO regs */
224 static void tsec_local_mdio_write(volatile tsec_mdio_t
*phyregs
, uint addr
,
225 uint reg
, uint value
)
227 int timeout
= 1000000;
229 phyregs
->miimadd
= (addr
<< 8) | reg
;
230 phyregs
->miimcon
= value
;
234 while ((phyregs
->miimind
& MIIMIND_BUSY
) && timeout
--) ;
238 /* Provide the default behavior of writing the PHY of this ethernet device */
239 #define write_phy_reg(priv, regnum, value) \
240 tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
242 /* Reads register regnum on the device's PHY through the
243 * specified registers. It lowers and raises the read
244 * command, and waits for the data to become valid (miimind
245 * notvalid bit cleared), and the bus to cease activity (miimind
246 * busy bit cleared), and then returns the value
248 static uint
tsec_local_mdio_read(volatile tsec_mdio_t
*phyregs
,
249 uint phyid
, uint regnum
)
253 /* Put the address of the phy, and the register
254 * number into MIIMADD */
255 phyregs
->miimadd
= (phyid
<< 8) | regnum
;
257 /* Clear the command register, and wait */
258 phyregs
->miimcom
= 0;
261 /* Initiate a read command, and wait */
262 phyregs
->miimcom
= MIIM_READ_COMMAND
;
265 /* Wait for the the indication that the read is done */
266 while ((phyregs
->miimind
& (MIIMIND_NOTVALID
| MIIMIND_BUSY
))) ;
268 /* Grab the value read from the PHY */
269 value
= phyregs
->miimstat
;
274 /* #define to provide old read_phy_reg functionality without duplicating code */
275 #define read_phy_reg(priv,regnum) \
276 tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
278 #define TBIANA_SETTINGS ( \
279 TBIANA_ASYMMETRIC_PAUSE \
280 | TBIANA_SYMMETRIC_PAUSE \
281 | TBIANA_FULL_DUPLEX \
284 /* Force the TBI PHY into 1000Mbps full duplex when in SGMII mode */
285 #define TBICR_SETTINGS ( \
287 | TBICR_FULL_DUPLEX \
291 /* Configure the TBI for SGMII operation */
292 static void tsec_configure_serdes(struct tsec_private
*priv
)
294 /* Access TBI PHY registers at given TSEC register offset as opposed
295 * to the register offset used for external PHY accesses */
296 tsec_local_mdio_write(priv
->phyregs_sgmii
, priv
->regs
->tbipa
, TBI_ANA
,
298 tsec_local_mdio_write(priv
->phyregs_sgmii
, priv
->regs
->tbipa
, TBI_TBICON
,
300 tsec_local_mdio_write(priv
->phyregs_sgmii
, priv
->regs
->tbipa
, TBI_CR
,
304 /* Discover which PHY is attached to the device, and configure it
305 * properly. If the PHY is not recognized, then return 0
306 * (failure). Otherwise, return 1
308 static int init_phy(struct eth_device
*dev
)
310 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
311 struct phy_info
*curphy
;
312 volatile tsec_t
*regs
= priv
->regs
;
314 /* Assign a Physical address to the TBI */
315 regs
->tbipa
= CONFIG_SYS_TBIPA_VALUE
;
318 /* Reset MII (due to new addresses) */
319 priv
->phyregs
->miimcfg
= MIIMCFG_RESET
;
321 priv
->phyregs
->miimcfg
= MIIMCFG_INIT_VALUE
;
323 while (priv
->phyregs
->miimind
& MIIMIND_BUSY
) ;
325 /* Get the cmd structure corresponding to the attached
327 curphy
= get_phy_info(dev
);
329 if (curphy
== NULL
) {
330 priv
->phyinfo
= NULL
;
331 printf("%s: No PHY found\n", dev
->name
);
336 if (regs
->ecntrl
& ECNTRL_SGMII_MODE
)
337 tsec_configure_serdes(priv
);
339 priv
->phyinfo
= curphy
;
341 phy_run_commands(priv
, priv
->phyinfo
->config
);
347 * Returns which value to write to the control register.
348 * For 10/100, the value is slightly different
350 static uint
mii_cr_init(uint mii_reg
, struct tsec_private
* priv
)
352 if (priv
->flags
& TSEC_GIGABIT
)
353 return MIIM_CONTROL_INIT
;
359 * Wait for auto-negotiation to complete, then determine link
361 static uint
mii_parse_sr(uint mii_reg
, struct tsec_private
* priv
)
364 * Wait if the link is up, and autonegotiation is in progress
365 * (ie - we're capable and it's not done)
367 mii_reg
= read_phy_reg(priv
, MIIM_STATUS
);
368 if ((mii_reg
& PHY_BMSR_AUTN_ABLE
) && !(mii_reg
& PHY_BMSR_AUTN_COMP
)) {
371 puts("Waiting for PHY auto negotiation to complete");
372 while (!(mii_reg
& PHY_BMSR_AUTN_COMP
)) {
376 if (i
> PHY_AUTONEGOTIATE_TIMEOUT
) {
377 puts(" TIMEOUT !\n");
383 puts("user interrupt!\n");
388 if ((i
++ % 1000) == 0) {
391 udelay(1000); /* 1 ms */
392 mii_reg
= read_phy_reg(priv
, MIIM_STATUS
);
396 /* Link status bit is latched low, read it again */
397 mii_reg
= read_phy_reg(priv
, MIIM_STATUS
);
399 udelay(500000); /* another 500 ms (results in faster booting) */
402 priv
->link
= mii_reg
& MIIM_STATUS_LINK
? 1 : 0;
407 /* Generic function which updates the speed and duplex. If
408 * autonegotiation is enabled, it uses the AND of the link
409 * partner's advertised capabilities and our advertised
410 * capabilities. If autonegotiation is disabled, we use the
411 * appropriate bits in the control register.
413 * Stolen from Linux's mii.c and phy_device.c
415 static uint
mii_parse_link(uint mii_reg
, struct tsec_private
*priv
)
417 /* We're using autonegotiation */
418 if (mii_reg
& PHY_BMSR_AUTN_ABLE
) {
422 /* Check for gigabit capability */
423 if (mii_reg
& PHY_BMSR_EXT
) {
424 /* We want a list of states supported by
425 * both PHYs in the link
427 gblpa
= read_phy_reg(priv
, PHY_1000BTSR
);
428 gblpa
&= read_phy_reg(priv
, PHY_1000BTCR
) << 2;
431 /* Set the baseline so we only have to set them
432 * if they're different
437 /* Check the gigabit fields */
438 if (gblpa
& (PHY_1000BTSR_1000FD
| PHY_1000BTSR_1000HD
)) {
441 if (gblpa
& PHY_1000BTSR_1000FD
)
448 lpa
= read_phy_reg(priv
, PHY_ANAR
);
449 lpa
&= read_phy_reg(priv
, PHY_ANLPAR
);
451 if (lpa
& (PHY_ANLPAR_TXFD
| PHY_ANLPAR_TX
)) {
454 if (lpa
& PHY_ANLPAR_TXFD
)
457 } else if (lpa
& PHY_ANLPAR_10FD
)
460 uint bmcr
= read_phy_reg(priv
, PHY_BMCR
);
465 if (bmcr
& PHY_BMCR_DPLX
)
468 if (bmcr
& PHY_BMCR_1000_MBPS
)
470 else if (bmcr
& PHY_BMCR_100_MBPS
)
478 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
479 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
480 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
481 * link. "Ethernet@Wirespeed" reduces advertised speed until link
484 static uint
mii_BCM54xx_wirespeed(uint mii_reg
, struct tsec_private
*priv
)
486 return (read_phy_reg(priv
, mii_reg
) & 0x8FFF) | 0x8010;
490 * Parse the BCM54xx status register for speed and duplex information.
491 * The linux sungem_phy has this information, but in a table format.
493 static uint
mii_parse_BCM54xx_sr(uint mii_reg
, struct tsec_private
*priv
)
495 /* If there is no link, speed and duplex don't matter */
499 switch ((mii_reg
& MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK
) >>
500 MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT
) {
526 printf("Auto-neg error, defaulting to 10BT/HD\n");
536 * Find out if PHY is in copper or serdes mode by looking at Expansion Reg
537 * 0x42 - "Operating Mode Status Register"
539 static int BCM8482_is_serdes(struct tsec_private
*priv
)
544 write_phy_reg(priv
, MIIM_BCM54XX_EXP_SEL
, MIIM_BCM54XX_EXP_SEL_ER
| 0x42);
545 val
= read_phy_reg(priv
, MIIM_BCM54XX_EXP_DATA
);
547 switch (val
& 0x1f) {
548 case 0x0d: /* RGMII-to-100Base-FX */
549 case 0x0e: /* RGMII-to-SGMII */
550 case 0x0f: /* RGMII-to-SerDes */
551 case 0x12: /* SGMII-to-SerDes */
552 case 0x13: /* SGMII-to-100Base-FX */
553 case 0x16: /* SerDes-to-Serdes */
556 case 0x6: /* RGMII-to-Copper */
557 case 0x14: /* SGMII-to-Copper */
558 case 0x17: /* SerDes-to-Copper */
561 printf("ERROR, invalid PHY mode (0x%x\n)", val
);
569 * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating
570 * Mode Status Register"
572 uint
mii_parse_BCM5482_serdes_sr(struct tsec_private
*priv
)
577 /* Wait 1s for link - Clause 37 autonegotiation happens very fast */
579 write_phy_reg(priv
, MIIM_BCM54XX_EXP_SEL
,
580 MIIM_BCM54XX_EXP_SEL_ER
| 0x42);
581 val
= read_phy_reg(priv
, MIIM_BCM54XX_EXP_DATA
);
591 udelay(1000); /* 1 ms */
595 switch ((val
>> 13) & 0x3) {
607 priv
->duplexity
= (val
& 0x1000) == 0x1000;
613 * Figure out if BCM5482 is in serdes or copper mode and determine link
614 * configuration accordingly
616 static uint
mii_parse_BCM5482_sr(uint mii_reg
, struct tsec_private
*priv
)
618 if (BCM8482_is_serdes(priv
)) {
619 mii_parse_BCM5482_serdes_sr(priv
);
620 priv
->flags
|= TSEC_FIBER
;
622 /* Wait for auto-negotiation to complete or fail */
623 mii_parse_sr(mii_reg
, priv
);
625 /* Parse BCM54xx copper aux status register */
626 mii_reg
= read_phy_reg(priv
, MIIM_BCM54xx_AUXSTATUS
);
627 mii_parse_BCM54xx_sr(mii_reg
, priv
);
633 /* Parse the 88E1011's status register for speed and duplex
636 static uint
mii_parse_88E1011_psr(uint mii_reg
, struct tsec_private
* priv
)
640 mii_reg
= read_phy_reg(priv
, MIIM_88E1011_PHY_STATUS
);
642 if ((mii_reg
& MIIM_88E1011_PHYSTAT_LINK
) &&
643 !(mii_reg
& MIIM_88E1011_PHYSTAT_SPDDONE
)) {
646 puts("Waiting for PHY realtime link");
647 while (!(mii_reg
& MIIM_88E1011_PHYSTAT_SPDDONE
)) {
648 /* Timeout reached ? */
649 if (i
> PHY_AUTONEGOTIATE_TIMEOUT
) {
650 puts(" TIMEOUT !\n");
655 if ((i
++ % 1000) == 0) {
658 udelay(1000); /* 1 ms */
659 mii_reg
= read_phy_reg(priv
, MIIM_88E1011_PHY_STATUS
);
662 udelay(500000); /* another 500 ms (results in faster booting) */
664 if (mii_reg
& MIIM_88E1011_PHYSTAT_LINK
)
670 if (mii_reg
& MIIM_88E1011_PHYSTAT_DUPLEX
)
675 speed
= (mii_reg
& MIIM_88E1011_PHYSTAT_SPEED
);
678 case MIIM_88E1011_PHYSTAT_GBIT
:
681 case MIIM_88E1011_PHYSTAT_100
:
691 /* Parse the RTL8211B's status register for speed and duplex
694 static uint
mii_parse_RTL8211B_sr(uint mii_reg
, struct tsec_private
* priv
)
698 mii_reg
= read_phy_reg(priv
, MIIM_RTL8211B_PHY_STATUS
);
699 if (!(mii_reg
& MIIM_RTL8211B_PHYSTAT_SPDDONE
)) {
702 /* in case of timeout ->link is cleared */
704 puts("Waiting for PHY realtime link");
705 while (!(mii_reg
& MIIM_RTL8211B_PHYSTAT_SPDDONE
)) {
706 /* Timeout reached ? */
707 if (i
> PHY_AUTONEGOTIATE_TIMEOUT
) {
708 puts(" TIMEOUT !\n");
713 if ((i
++ % 1000) == 0) {
716 udelay(1000); /* 1 ms */
717 mii_reg
= read_phy_reg(priv
, MIIM_RTL8211B_PHY_STATUS
);
720 udelay(500000); /* another 500 ms (results in faster booting) */
722 if (mii_reg
& MIIM_RTL8211B_PHYSTAT_LINK
)
728 if (mii_reg
& MIIM_RTL8211B_PHYSTAT_DUPLEX
)
733 speed
= (mii_reg
& MIIM_RTL8211B_PHYSTAT_SPEED
);
736 case MIIM_RTL8211B_PHYSTAT_GBIT
:
739 case MIIM_RTL8211B_PHYSTAT_100
:
749 /* Parse the cis8201's status register for speed and duplex
752 static uint
mii_parse_cis8201(uint mii_reg
, struct tsec_private
* priv
)
756 if (mii_reg
& MIIM_CIS8201_AUXCONSTAT_DUPLEX
)
761 speed
= mii_reg
& MIIM_CIS8201_AUXCONSTAT_SPEED
;
763 case MIIM_CIS8201_AUXCONSTAT_GBIT
:
766 case MIIM_CIS8201_AUXCONSTAT_100
:
777 /* Parse the vsc8244's status register for speed and duplex
780 static uint
mii_parse_vsc8244(uint mii_reg
, struct tsec_private
* priv
)
784 if (mii_reg
& MIIM_VSC8244_AUXCONSTAT_DUPLEX
)
789 speed
= mii_reg
& MIIM_VSC8244_AUXCONSTAT_SPEED
;
791 case MIIM_VSC8244_AUXCONSTAT_GBIT
:
794 case MIIM_VSC8244_AUXCONSTAT_100
:
805 /* Parse the DM9161's status register for speed and duplex
808 static uint
mii_parse_dm9161_scsr(uint mii_reg
, struct tsec_private
* priv
)
810 if (mii_reg
& (MIIM_DM9161_SCSR_100F
| MIIM_DM9161_SCSR_100H
))
815 if (mii_reg
& (MIIM_DM9161_SCSR_100F
| MIIM_DM9161_SCSR_10F
))
824 * Hack to write all 4 PHYs with the LED values
826 static uint
mii_cis8204_fixled(uint mii_reg
, struct tsec_private
* priv
)
829 volatile tsec_mdio_t
*regbase
= priv
->phyregs
;
830 int timeout
= 1000000;
832 for (phyid
= 0; phyid
< 4; phyid
++) {
833 regbase
->miimadd
= (phyid
<< 8) | mii_reg
;
834 regbase
->miimcon
= MIIM_CIS8204_SLEDCON_INIT
;
838 while ((regbase
->miimind
& MIIMIND_BUSY
) && timeout
--) ;
841 return MIIM_CIS8204_SLEDCON_INIT
;
844 static uint
mii_cis8204_setmode(uint mii_reg
, struct tsec_private
* priv
)
846 if (priv
->flags
& TSEC_REDUCED
)
847 return MIIM_CIS8204_EPHYCON_INIT
| MIIM_CIS8204_EPHYCON_RGMII
;
849 return MIIM_CIS8204_EPHYCON_INIT
;
852 static uint
mii_m88e1111s_setmode(uint mii_reg
, struct tsec_private
*priv
)
854 uint mii_data
= read_phy_reg(priv
, mii_reg
);
856 if (priv
->flags
& TSEC_REDUCED
)
857 mii_data
= (mii_data
& 0xfff0) | 0x000b;
861 /* Initialized required registers to appropriate values, zeroing
862 * those we don't care about (unless zero is bad, in which case,
863 * choose a more appropriate value)
865 static void init_registers(volatile tsec_t
* regs
)
868 regs
->ievent
= IEVENT_INIT_CLEAR
;
870 regs
->imask
= IMASK_INIT_CLEAR
;
872 regs
->hash
.iaddr0
= 0;
873 regs
->hash
.iaddr1
= 0;
874 regs
->hash
.iaddr2
= 0;
875 regs
->hash
.iaddr3
= 0;
876 regs
->hash
.iaddr4
= 0;
877 regs
->hash
.iaddr5
= 0;
878 regs
->hash
.iaddr6
= 0;
879 regs
->hash
.iaddr7
= 0;
881 regs
->hash
.gaddr0
= 0;
882 regs
->hash
.gaddr1
= 0;
883 regs
->hash
.gaddr2
= 0;
884 regs
->hash
.gaddr3
= 0;
885 regs
->hash
.gaddr4
= 0;
886 regs
->hash
.gaddr5
= 0;
887 regs
->hash
.gaddr6
= 0;
888 regs
->hash
.gaddr7
= 0;
890 regs
->rctrl
= 0x00000000;
892 /* Init RMON mib registers */
893 memset((void *)&(regs
->rmon
), 0, sizeof(rmon_mib_t
));
895 regs
->rmon
.cam1
= 0xffffffff;
896 regs
->rmon
.cam2
= 0xffffffff;
898 regs
->mrblr
= MRBLR_INIT_SETTINGS
;
900 regs
->minflr
= MINFLR_INIT_SETTINGS
;
902 regs
->attr
= ATTR_INIT_SETTINGS
;
903 regs
->attreli
= ATTRELI_INIT_SETTINGS
;
907 /* Configure maccfg2 based on negotiated speed and duplex
908 * reported by PHY handling code
910 static void adjust_link(struct eth_device
*dev
)
912 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
913 volatile tsec_t
*regs
= priv
->regs
;
916 if (priv
->duplexity
!= 0)
917 regs
->maccfg2
|= MACCFG2_FULL_DUPLEX
;
919 regs
->maccfg2
&= ~(MACCFG2_FULL_DUPLEX
);
921 switch (priv
->speed
) {
923 regs
->maccfg2
= ((regs
->maccfg2
& ~(MACCFG2_IF
))
928 regs
->maccfg2
= ((regs
->maccfg2
& ~(MACCFG2_IF
))
931 /* Set R100 bit in all modes although
932 * it is only used in RGMII mode
934 if (priv
->speed
== 100)
935 regs
->ecntrl
|= ECNTRL_R100
;
937 regs
->ecntrl
&= ~(ECNTRL_R100
);
940 printf("%s: Speed was bad\n", dev
->name
);
944 printf("Speed: %d, %s duplex%s\n", priv
->speed
,
945 (priv
->duplexity
) ? "full" : "half",
946 (priv
->flags
& TSEC_FIBER
) ? ", fiber mode" : "");
949 printf("%s: No link.\n", dev
->name
);
953 /* Set up the buffers and their descriptors, and bring up the
956 static void startup_tsec(struct eth_device
*dev
)
959 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
960 volatile tsec_t
*regs
= priv
->regs
;
962 /* Point to the buffer descriptors */
963 regs
->tbase
= (unsigned int)(&rtx
.txbd
[txIdx
]);
964 regs
->rbase
= (unsigned int)(&rtx
.rxbd
[rxIdx
]);
966 /* Initialize the Rx Buffer descriptors */
967 for (i
= 0; i
< PKTBUFSRX
; i
++) {
968 rtx
.rxbd
[i
].status
= RXBD_EMPTY
;
969 rtx
.rxbd
[i
].length
= 0;
970 rtx
.rxbd
[i
].bufPtr
= (uint
) NetRxPackets
[i
];
972 rtx
.rxbd
[PKTBUFSRX
- 1].status
|= RXBD_WRAP
;
974 /* Initialize the TX Buffer Descriptors */
975 for (i
= 0; i
< TX_BUF_CNT
; i
++) {
976 rtx
.txbd
[i
].status
= 0;
977 rtx
.txbd
[i
].length
= 0;
978 rtx
.txbd
[i
].bufPtr
= 0;
980 rtx
.txbd
[TX_BUF_CNT
- 1].status
|= TXBD_WRAP
;
982 /* Start up the PHY */
984 phy_run_commands(priv
, priv
->phyinfo
->startup
);
988 /* Enable Transmit and Receive */
989 regs
->maccfg1
|= (MACCFG1_RX_EN
| MACCFG1_TX_EN
);
991 /* Tell the DMA it is clear to go */
992 regs
->dmactrl
|= DMACTRL_INIT_SETTINGS
;
993 regs
->tstat
= TSTAT_CLEAR_THALT
;
994 regs
->rstat
= RSTAT_CLEAR_RHALT
;
995 regs
->dmactrl
&= ~(DMACTRL_GRS
| DMACTRL_GTS
);
998 /* This returns the status bits of the device. The return value
999 * is never checked, and this is what the 8260 driver did, so we
1000 * do the same. Presumably, this would be zero if there were no
1003 static int tsec_send(struct eth_device
*dev
, volatile void *packet
, int length
)
1007 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
1008 volatile tsec_t
*regs
= priv
->regs
;
1010 /* Find an empty buffer descriptor */
1011 for (i
= 0; rtx
.txbd
[txIdx
].status
& TXBD_READY
; i
++) {
1012 if (i
>= TOUT_LOOP
) {
1013 debug("%s: tsec: tx buffers full\n", dev
->name
);
1018 rtx
.txbd
[txIdx
].bufPtr
= (uint
) packet
;
1019 rtx
.txbd
[txIdx
].length
= length
;
1020 rtx
.txbd
[txIdx
].status
|=
1021 (TXBD_READY
| TXBD_LAST
| TXBD_CRC
| TXBD_INTERRUPT
);
1023 /* Tell the DMA to go */
1024 regs
->tstat
= TSTAT_CLEAR_THALT
;
1026 /* Wait for buffer to be transmitted */
1027 for (i
= 0; rtx
.txbd
[txIdx
].status
& TXBD_READY
; i
++) {
1028 if (i
>= TOUT_LOOP
) {
1029 debug("%s: tsec: tx error\n", dev
->name
);
1034 txIdx
= (txIdx
+ 1) % TX_BUF_CNT
;
1035 result
= rtx
.txbd
[txIdx
].status
& TXBD_STATS
;
1040 static int tsec_recv(struct eth_device
*dev
)
1043 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
1044 volatile tsec_t
*regs
= priv
->regs
;
1046 while (!(rtx
.rxbd
[rxIdx
].status
& RXBD_EMPTY
)) {
1048 length
= rtx
.rxbd
[rxIdx
].length
;
1050 /* Send the packet up if there were no errors */
1051 if (!(rtx
.rxbd
[rxIdx
].status
& RXBD_STATS
)) {
1052 NetReceive(NetRxPackets
[rxIdx
], length
- 4);
1054 printf("Got error %x\n",
1055 (rtx
.rxbd
[rxIdx
].status
& RXBD_STATS
));
1058 rtx
.rxbd
[rxIdx
].length
= 0;
1060 /* Set the wrap bit if this is the last element in the list */
1061 rtx
.rxbd
[rxIdx
].status
=
1062 RXBD_EMPTY
| (((rxIdx
+ 1) == PKTBUFSRX
) ? RXBD_WRAP
: 0);
1064 rxIdx
= (rxIdx
+ 1) % PKTBUFSRX
;
1067 if (regs
->ievent
& IEVENT_BSY
) {
1068 regs
->ievent
= IEVENT_BSY
;
1069 regs
->rstat
= RSTAT_CLEAR_RHALT
;
1076 /* Stop the interface */
1077 static void tsec_halt(struct eth_device
*dev
)
1079 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
1080 volatile tsec_t
*regs
= priv
->regs
;
1082 regs
->dmactrl
&= ~(DMACTRL_GRS
| DMACTRL_GTS
);
1083 regs
->dmactrl
|= (DMACTRL_GRS
| DMACTRL_GTS
);
1085 while ((regs
->ievent
& (IEVENT_GRSC
| IEVENT_GTSC
))
1086 != (IEVENT_GRSC
| IEVENT_GTSC
)) ;
1088 regs
->maccfg1
&= ~(MACCFG1_TX_EN
| MACCFG1_RX_EN
);
1090 /* Shut down the PHY, as needed */
1092 phy_run_commands(priv
, priv
->phyinfo
->shutdown
);
1095 static struct phy_info phy_info_M88E1149S
= {
1099 (struct phy_cmd
[]) { /* config */
1100 /* Reset and configure the PHY */
1101 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1103 {0x1e, 0x200c, NULL
},
1106 {0x1e, 0x100, NULL
},
1107 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1108 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1109 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1110 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1113 (struct phy_cmd
[]) { /* startup */
1114 /* Status is read once to clear old link state */
1115 {MIIM_STATUS
, miim_read
, NULL
},
1116 /* Auto-negotiate */
1117 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1118 /* Read the status */
1119 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
1122 (struct phy_cmd
[]) { /* shutdown */
1127 /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1128 static struct phy_info phy_info_BCM5461S
= {
1129 0x02060c1, /* 5461 ID */
1130 "Broadcom BCM5461S",
1131 0, /* not clear to me what minor revisions we can shift away */
1132 (struct phy_cmd
[]) { /* config */
1133 /* Reset and configure the PHY */
1134 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1135 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1136 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1137 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1138 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1141 (struct phy_cmd
[]) { /* startup */
1142 /* Status is read once to clear old link state */
1143 {MIIM_STATUS
, miim_read
, NULL
},
1144 /* Auto-negotiate */
1145 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1146 /* Read the status */
1147 {MIIM_BCM54xx_AUXSTATUS
, miim_read
, &mii_parse_BCM54xx_sr
},
1150 (struct phy_cmd
[]) { /* shutdown */
1155 static struct phy_info phy_info_BCM5464S
= {
1156 0x02060b1, /* 5464 ID */
1157 "Broadcom BCM5464S",
1158 0, /* not clear to me what minor revisions we can shift away */
1159 (struct phy_cmd
[]) { /* config */
1160 /* Reset and configure the PHY */
1161 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1162 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1163 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1164 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1165 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1168 (struct phy_cmd
[]) { /* startup */
1169 /* Status is read once to clear old link state */
1170 {MIIM_STATUS
, miim_read
, NULL
},
1171 /* Auto-negotiate */
1172 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1173 /* Read the status */
1174 {MIIM_BCM54xx_AUXSTATUS
, miim_read
, &mii_parse_BCM54xx_sr
},
1177 (struct phy_cmd
[]) { /* shutdown */
1182 static struct phy_info phy_info_BCM5482S
= {
1184 "Broadcom BCM5482S",
1186 (struct phy_cmd
[]) { /* config */
1187 /* Reset and configure the PHY */
1188 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1189 /* Setup read from auxilary control shadow register 7 */
1190 {MIIM_BCM54xx_AUXCNTL
, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL
},
1191 /* Read Misc Control register and or in Ethernet@Wirespeed */
1192 {MIIM_BCM54xx_AUXCNTL
, 0, &mii_BCM54xx_wirespeed
},
1193 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1194 /* Initial config/enable of secondary SerDes interface */
1195 {MIIM_BCM54XX_SHD
, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL
},
1196 /* Write intial value to secondary SerDes Contol */
1197 {MIIM_BCM54XX_EXP_SEL
, MIIM_BCM54XX_EXP_SEL_SSD
| 0, NULL
},
1198 {MIIM_BCM54XX_EXP_DATA
, MIIM_CONTROL_RESTART
, NULL
},
1199 /* Enable copper/fiber auto-detect */
1200 {MIIM_BCM54XX_SHD
, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
1203 (struct phy_cmd
[]) { /* startup */
1204 /* Status is read once to clear old link state */
1205 {MIIM_STATUS
, miim_read
, NULL
},
1206 /* Determine copper/fiber, auto-negotiate, and read the result */
1207 {MIIM_STATUS
, miim_read
, &mii_parse_BCM5482_sr
},
1210 (struct phy_cmd
[]) { /* shutdown */
1215 static struct phy_info phy_info_M88E1011S
= {
1219 (struct phy_cmd
[]) { /* config */
1220 /* Reset and configure the PHY */
1221 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1223 {0x1e, 0x200c, NULL
},
1226 {0x1e, 0x100, NULL
},
1227 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1228 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1229 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1230 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1233 (struct phy_cmd
[]) { /* startup */
1234 /* Status is read once to clear old link state */
1235 {MIIM_STATUS
, miim_read
, NULL
},
1236 /* Auto-negotiate */
1237 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1238 /* Read the status */
1239 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
1242 (struct phy_cmd
[]) { /* shutdown */
1247 static struct phy_info phy_info_M88E1111S
= {
1251 (struct phy_cmd
[]) { /* config */
1252 /* Reset and configure the PHY */
1253 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1254 {0x1b, 0x848f, &mii_m88e1111s_setmode
},
1255 {0x14, 0x0cd2, NULL
}, /* Delay RGMII TX and RX */
1256 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1257 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1258 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1259 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1262 (struct phy_cmd
[]) { /* startup */
1263 /* Status is read once to clear old link state */
1264 {MIIM_STATUS
, miim_read
, NULL
},
1265 /* Auto-negotiate */
1266 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1267 /* Read the status */
1268 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
1271 (struct phy_cmd
[]) { /* shutdown */
1276 static struct phy_info phy_info_M88E1118
= {
1280 (struct phy_cmd
[]) { /* config */
1281 /* Reset and configure the PHY */
1282 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1283 {0x16, 0x0002, NULL
}, /* Change Page Number */
1284 {0x15, 0x1070, NULL
}, /* Delay RGMII TX and RX */
1285 {0x16, 0x0003, NULL
}, /* Change Page Number */
1286 {0x10, 0x021e, NULL
}, /* Adjust LED control */
1287 {0x16, 0x0000, NULL
}, /* Change Page Number */
1288 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1289 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1290 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1291 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1294 (struct phy_cmd
[]) { /* startup */
1295 {0x16, 0x0000, NULL
}, /* Change Page Number */
1296 /* Status is read once to clear old link state */
1297 {MIIM_STATUS
, miim_read
, NULL
},
1298 /* Auto-negotiate */
1299 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1300 /* Read the status */
1301 {MIIM_88E1011_PHY_STATUS
, miim_read
,
1302 &mii_parse_88E1011_psr
},
1305 (struct phy_cmd
[]) { /* shutdown */
1311 * Since to access LED register we need do switch the page, we
1312 * do LED configuring in the miim_read-like function as follows
1314 static uint
mii_88E1121_set_led (uint mii_reg
, struct tsec_private
*priv
)
1318 /* Switch the page to access the led register */
1319 pg
= read_phy_reg(priv
, MIIM_88E1121_PHY_PAGE
);
1320 write_phy_reg(priv
, MIIM_88E1121_PHY_PAGE
, MIIM_88E1121_PHY_LED_PAGE
);
1322 /* Configure leds */
1323 write_phy_reg(priv
, MIIM_88E1121_PHY_LED_CTRL
,
1324 MIIM_88E1121_PHY_LED_DEF
);
1326 /* Restore the page pointer */
1327 write_phy_reg(priv
, MIIM_88E1121_PHY_PAGE
, pg
);
1331 static struct phy_info phy_info_M88E1121R
= {
1335 (struct phy_cmd
[]) { /* config */
1336 /* Reset and configure the PHY */
1337 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1338 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1339 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1340 /* Configure leds */
1341 {MIIM_88E1121_PHY_LED_CTRL
, miim_read
, &mii_88E1121_set_led
},
1342 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1343 /* Disable IRQs and de-assert interrupt */
1344 {MIIM_88E1121_PHY_IRQ_EN
, 0, NULL
},
1345 {MIIM_88E1121_PHY_IRQ_STATUS
, miim_read
, NULL
},
1348 (struct phy_cmd
[]) { /* startup */
1349 /* Status is read once to clear old link state */
1350 {MIIM_STATUS
, miim_read
, NULL
},
1351 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1352 {MIIM_STATUS
, miim_read
, &mii_parse_link
},
1355 (struct phy_cmd
[]) { /* shutdown */
1360 static unsigned int m88e1145_setmode(uint mii_reg
, struct tsec_private
*priv
)
1362 uint mii_data
= read_phy_reg(priv
, mii_reg
);
1364 /* Setting MIIM_88E1145_PHY_EXT_CR */
1365 if (priv
->flags
& TSEC_REDUCED
)
1367 MIIM_M88E1145_RGMII_RX_DELAY
| MIIM_M88E1145_RGMII_TX_DELAY
;
1372 static struct phy_info phy_info_M88E1145
= {
1376 (struct phy_cmd
[]) { /* config */
1378 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1386 /* Configure the PHY */
1387 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1388 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1389 {MIIM_88E1011_PHY_SCR
, MIIM_88E1011_PHY_MDI_X_AUTO
, NULL
},
1390 {MIIM_88E1145_PHY_EXT_CR
, 0, &m88e1145_setmode
},
1391 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1392 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, NULL
},
1395 (struct phy_cmd
[]) { /* startup */
1396 /* Status is read once to clear old link state */
1397 {MIIM_STATUS
, miim_read
, NULL
},
1398 /* Auto-negotiate */
1399 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1400 {MIIM_88E1111_PHY_LED_CONTROL
, MIIM_88E1111_PHY_LED_DIRECT
, NULL
},
1401 /* Read the Status */
1402 {MIIM_88E1011_PHY_STATUS
, miim_read
, &mii_parse_88E1011_psr
},
1405 (struct phy_cmd
[]) { /* shutdown */
1410 static struct phy_info phy_info_cis8204
= {
1414 (struct phy_cmd
[]) { /* config */
1415 /* Override PHY config settings */
1416 {MIIM_CIS8201_AUX_CONSTAT
, MIIM_CIS8201_AUXCONSTAT_INIT
, NULL
},
1417 /* Configure some basic stuff */
1418 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1419 {MIIM_CIS8204_SLED_CON
, MIIM_CIS8204_SLEDCON_INIT
,
1420 &mii_cis8204_fixled
},
1421 {MIIM_CIS8204_EPHY_CON
, MIIM_CIS8204_EPHYCON_INIT
,
1422 &mii_cis8204_setmode
},
1425 (struct phy_cmd
[]) { /* startup */
1426 /* Read the Status (2x to make sure link is right) */
1427 {MIIM_STATUS
, miim_read
, NULL
},
1428 /* Auto-negotiate */
1429 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1430 /* Read the status */
1431 {MIIM_CIS8201_AUX_CONSTAT
, miim_read
, &mii_parse_cis8201
},
1434 (struct phy_cmd
[]) { /* shutdown */
1440 static struct phy_info phy_info_cis8201
= {
1444 (struct phy_cmd
[]) { /* config */
1445 /* Override PHY config settings */
1446 {MIIM_CIS8201_AUX_CONSTAT
, MIIM_CIS8201_AUXCONSTAT_INIT
, NULL
},
1447 /* Set up the interface mode */
1448 {MIIM_CIS8201_EXT_CON1
, MIIM_CIS8201_EXTCON1_INIT
, NULL
},
1449 /* Configure some basic stuff */
1450 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1453 (struct phy_cmd
[]) { /* startup */
1454 /* Read the Status (2x to make sure link is right) */
1455 {MIIM_STATUS
, miim_read
, NULL
},
1456 /* Auto-negotiate */
1457 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1458 /* Read the status */
1459 {MIIM_CIS8201_AUX_CONSTAT
, miim_read
, &mii_parse_cis8201
},
1462 (struct phy_cmd
[]) { /* shutdown */
1467 static struct phy_info phy_info_VSC8211
= {
1471 (struct phy_cmd
[]) { /* config */
1472 /* Override PHY config settings */
1473 {MIIM_CIS8201_AUX_CONSTAT
, MIIM_CIS8201_AUXCONSTAT_INIT
, NULL
},
1474 /* Set up the interface mode */
1475 {MIIM_CIS8201_EXT_CON1
, MIIM_CIS8201_EXTCON1_INIT
, NULL
},
1476 /* Configure some basic stuff */
1477 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1480 (struct phy_cmd
[]) { /* startup */
1481 /* Read the Status (2x to make sure link is right) */
1482 {MIIM_STATUS
, miim_read
, NULL
},
1483 /* Auto-negotiate */
1484 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1485 /* Read the status */
1486 {MIIM_CIS8201_AUX_CONSTAT
, miim_read
, &mii_parse_cis8201
},
1489 (struct phy_cmd
[]) { /* shutdown */
1494 static struct phy_info phy_info_VSC8244
= {
1498 (struct phy_cmd
[]) { /* config */
1499 /* Override PHY config settings */
1500 /* Configure some basic stuff */
1501 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1504 (struct phy_cmd
[]) { /* startup */
1505 /* Read the Status (2x to make sure link is right) */
1506 {MIIM_STATUS
, miim_read
, NULL
},
1507 /* Auto-negotiate */
1508 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1509 /* Read the status */
1510 {MIIM_VSC8244_AUX_CONSTAT
, miim_read
, &mii_parse_vsc8244
},
1513 (struct phy_cmd
[]) { /* shutdown */
1518 static struct phy_info phy_info_VSC8641
= {
1522 (struct phy_cmd
[]) { /* config */
1523 /* Configure some basic stuff */
1524 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1527 (struct phy_cmd
[]) { /* startup */
1528 /* Read the Status (2x to make sure link is right) */
1529 {MIIM_STATUS
, miim_read
, NULL
},
1530 /* Auto-negotiate */
1531 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1532 /* Read the status */
1533 {MIIM_VSC8244_AUX_CONSTAT
, miim_read
, &mii_parse_vsc8244
},
1536 (struct phy_cmd
[]) { /* shutdown */
1541 static struct phy_info phy_info_VSC8221
= {
1545 (struct phy_cmd
[]) { /* config */
1546 /* Configure some basic stuff */
1547 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1550 (struct phy_cmd
[]) { /* startup */
1551 /* Read the Status (2x to make sure link is right) */
1552 {MIIM_STATUS
, miim_read
, NULL
},
1553 /* Auto-negotiate */
1554 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1555 /* Read the status */
1556 {MIIM_VSC8244_AUX_CONSTAT
, miim_read
, &mii_parse_vsc8244
},
1559 (struct phy_cmd
[]) { /* shutdown */
1564 static struct phy_info phy_info_VSC8601
= {
1568 (struct phy_cmd
[]) { /* config */
1569 /* Override PHY config settings */
1570 /* Configure some basic stuff */
1571 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1572 #ifdef CONFIG_SYS_VSC8601_SKEWFIX
1573 {MIIM_VSC8601_EPHY_CON
,MIIM_VSC8601_EPHY_CON_INIT_SKEW
,NULL
},
1574 #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
1575 {MIIM_EXT_PAGE_ACCESS
,1,NULL
},
1576 #define VSC8101_SKEW \
1577 (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
1578 {MIIM_VSC8601_SKEW_CTRL
,VSC8101_SKEW
,NULL
},
1579 {MIIM_EXT_PAGE_ACCESS
,0,NULL
},
1582 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1583 {MIIM_CONTROL
, MIIM_CONTROL_RESTART
, &mii_cr_init
},
1586 (struct phy_cmd
[]) { /* startup */
1587 /* Read the Status (2x to make sure link is right) */
1588 {MIIM_STATUS
, miim_read
, NULL
},
1589 /* Auto-negotiate */
1590 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1591 /* Read the status */
1592 {MIIM_VSC8244_AUX_CONSTAT
, miim_read
, &mii_parse_vsc8244
},
1595 (struct phy_cmd
[]) { /* shutdown */
1600 static struct phy_info phy_info_dm9161
= {
1604 (struct phy_cmd
[]) { /* config */
1605 {MIIM_CONTROL
, MIIM_DM9161_CR_STOP
, NULL
},
1606 /* Do not bypass the scrambler/descrambler */
1607 {MIIM_DM9161_SCR
, MIIM_DM9161_SCR_INIT
, NULL
},
1608 /* Clear 10BTCSR to default */
1609 {MIIM_DM9161_10BTCSR
, MIIM_DM9161_10BTCSR_INIT
, NULL
},
1610 /* Configure some basic stuff */
1611 {MIIM_CONTROL
, MIIM_CR_INIT
, NULL
},
1612 /* Restart Auto Negotiation */
1613 {MIIM_CONTROL
, MIIM_DM9161_CR_RSTAN
, NULL
},
1616 (struct phy_cmd
[]) { /* startup */
1617 /* Status is read once to clear old link state */
1618 {MIIM_STATUS
, miim_read
, NULL
},
1619 /* Auto-negotiate */
1620 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1621 /* Read the status */
1622 {MIIM_DM9161_SCSR
, miim_read
, &mii_parse_dm9161_scsr
},
1625 (struct phy_cmd
[]) { /* shutdown */
1630 /* a generic flavor. */
1631 static struct phy_info phy_info_generic
= {
1633 "Unknown/Generic PHY",
1635 (struct phy_cmd
[]) { /* config */
1636 {PHY_BMCR
, PHY_BMCR_RESET
, NULL
},
1637 {PHY_BMCR
, PHY_BMCR_AUTON
|PHY_BMCR_RST_NEG
, NULL
},
1640 (struct phy_cmd
[]) { /* startup */
1641 {PHY_BMSR
, miim_read
, NULL
},
1642 {PHY_BMSR
, miim_read
, &mii_parse_sr
},
1643 {PHY_BMSR
, miim_read
, &mii_parse_link
},
1646 (struct phy_cmd
[]) { /* shutdown */
1651 static uint
mii_parse_lxt971_sr2(uint mii_reg
, struct tsec_private
*priv
)
1655 speed
= mii_reg
& MIIM_LXT971_SR2_SPEED_MASK
;
1658 case MIIM_LXT971_SR2_10HDX
:
1660 priv
->duplexity
= 0;
1662 case MIIM_LXT971_SR2_10FDX
:
1664 priv
->duplexity
= 1;
1666 case MIIM_LXT971_SR2_100HDX
:
1668 priv
->duplexity
= 0;
1672 priv
->duplexity
= 1;
1676 priv
->duplexity
= 0;
1682 static struct phy_info phy_info_lxt971
= {
1686 (struct phy_cmd
[]) { /* config */
1687 {MIIM_CR
, MIIM_CR_INIT
, mii_cr_init
}, /* autonegotiate */
1690 (struct phy_cmd
[]) { /* startup - enable interrupts */
1691 /* { 0x12, 0x00f2, NULL }, */
1692 {MIIM_STATUS
, miim_read
, NULL
},
1693 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1694 {MIIM_LXT971_SR2
, miim_read
, &mii_parse_lxt971_sr2
},
1697 (struct phy_cmd
[]) { /* shutdown - disable interrupts */
1702 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1705 static uint
mii_parse_dp83865_lanr(uint mii_reg
, struct tsec_private
*priv
)
1707 switch (mii_reg
& MIIM_DP83865_SPD_MASK
) {
1709 case MIIM_DP83865_SPD_1000
:
1713 case MIIM_DP83865_SPD_100
:
1723 if (mii_reg
& MIIM_DP83865_DPX_FULL
)
1724 priv
->duplexity
= 1;
1726 priv
->duplexity
= 0;
1731 static struct phy_info phy_info_dp83865
= {
1735 (struct phy_cmd
[]) { /* config */
1736 {MIIM_CONTROL
, MIIM_DP83865_CR_INIT
, NULL
},
1739 (struct phy_cmd
[]) { /* startup */
1740 /* Status is read once to clear old link state */
1741 {MIIM_STATUS
, miim_read
, NULL
},
1742 /* Auto-negotiate */
1743 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1744 /* Read the link and auto-neg status */
1745 {MIIM_DP83865_LANR
, miim_read
, &mii_parse_dp83865_lanr
},
1748 (struct phy_cmd
[]) { /* shutdown */
1753 static struct phy_info phy_info_rtl8211b
= {
1757 (struct phy_cmd
[]) { /* config */
1758 /* Reset and configure the PHY */
1759 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1760 {MIIM_GBIT_CONTROL
, MIIM_GBIT_CONTROL_INIT
, NULL
},
1761 {MIIM_ANAR
, MIIM_ANAR_INIT
, NULL
},
1762 {MIIM_CONTROL
, MIIM_CONTROL_RESET
, NULL
},
1763 {MIIM_CONTROL
, MIIM_CONTROL_INIT
, &mii_cr_init
},
1766 (struct phy_cmd
[]) { /* startup */
1767 /* Status is read once to clear old link state */
1768 {MIIM_STATUS
, miim_read
, NULL
},
1769 /* Auto-negotiate */
1770 {MIIM_STATUS
, miim_read
, &mii_parse_sr
},
1771 /* Read the status */
1772 {MIIM_RTL8211B_PHY_STATUS
, miim_read
, &mii_parse_RTL8211B_sr
},
1775 (struct phy_cmd
[]) { /* shutdown */
1780 static struct phy_info
*phy_info
[] = {
1786 &phy_info_M88E1011S
,
1787 &phy_info_M88E1111S
,
1789 &phy_info_M88E1121R
,
1791 &phy_info_M88E1149S
,
1801 &phy_info_generic
, /* must be last; has ID 0 and 32 bit mask */
1805 /* Grab the identifier of the device's PHY, and search through
1806 * all of the known PHYs to see if one matches. If so, return
1807 * it, if not, return NULL
1809 static struct phy_info
*get_phy_info(struct eth_device
*dev
)
1811 struct tsec_private
*priv
= (struct tsec_private
*)dev
->priv
;
1812 uint phy_reg
, phy_ID
;
1814 struct phy_info
*theInfo
= NULL
;
1816 /* Grab the bits from PHYIR1, and put them in the upper half */
1817 phy_reg
= read_phy_reg(priv
, MIIM_PHYIR1
);
1818 phy_ID
= (phy_reg
& 0xffff) << 16;
1820 /* Grab the bits from PHYIR2, and put them in the lower half */
1821 phy_reg
= read_phy_reg(priv
, MIIM_PHYIR2
);
1822 phy_ID
|= (phy_reg
& 0xffff);
1824 /* loop through all the known PHY types, and find one that */
1825 /* matches the ID we read from the PHY. */
1826 for (i
= 0; phy_info
[i
]; i
++) {
1827 if (phy_info
[i
]->id
== (phy_ID
>> phy_info
[i
]->shift
)) {
1828 theInfo
= phy_info
[i
];
1833 if (theInfo
== &phy_info_generic
) {
1834 printf("%s: No support for PHY id %x; assuming generic\n",
1837 debug("%s: PHY is %s (%x)\n", dev
->name
, theInfo
->name
, phy_ID
);
1843 /* Execute the given series of commands on the given device's
1844 * PHY, running functions as necessary
1846 static void phy_run_commands(struct tsec_private
*priv
, struct phy_cmd
*cmd
)
1850 volatile tsec_mdio_t
*phyregs
= priv
->phyregs
;
1852 phyregs
->miimcfg
= MIIMCFG_RESET
;
1854 phyregs
->miimcfg
= MIIMCFG_INIT_VALUE
;
1856 while (phyregs
->miimind
& MIIMIND_BUSY
) ;
1858 for (i
= 0; cmd
->mii_reg
!= miim_end
; i
++) {
1859 if (cmd
->mii_data
== miim_read
) {
1860 result
= read_phy_reg(priv
, cmd
->mii_reg
);
1862 if (cmd
->funct
!= NULL
)
1863 (*(cmd
->funct
)) (result
, priv
);
1866 if (cmd
->funct
!= NULL
)
1867 result
= (*(cmd
->funct
)) (cmd
->mii_reg
, priv
);
1869 result
= cmd
->mii_data
;
1871 write_phy_reg(priv
, cmd
->mii_reg
, result
);
1878 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1879 && !defined(BITBANGMII)
1882 * Read a MII PHY register.
1887 static int tsec_miiphy_read(char *devname
, unsigned char addr
,
1888 unsigned char reg
, unsigned short *value
)
1891 struct tsec_private
*priv
= privlist
[0];
1894 printf("Can't read PHY at address %d\n", addr
);
1898 ret
= (unsigned short)tsec_local_mdio_read(priv
->phyregs
, addr
, reg
);
1905 * Write a MII PHY register.
1910 static int tsec_miiphy_write(char *devname
, unsigned char addr
,
1911 unsigned char reg
, unsigned short value
)
1913 struct tsec_private
*priv
= privlist
[0];
1916 printf("Can't write PHY at address %d\n", addr
);
1920 tsec_local_mdio_write(priv
->phyregs
, addr
, reg
, value
);
1927 #ifdef CONFIG_MCAST_TFTP
1929 /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1931 /* Set the appropriate hash bit for the given addr */
1933 /* The algorithm works like so:
1934 * 1) Take the Destination Address (ie the multicast address), and
1935 * do a CRC on it (little endian), and reverse the bits of the
1937 * 2) Use the 8 most significant bits as a hash into a 256-entry
1938 * table. The table is controlled through 8 32-bit registers:
1939 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1940 * gaddr7. This means that the 3 most significant bits in the
1941 * hash index which gaddr register to use, and the 5 other bits
1942 * indicate which bit (assuming an IBM numbering scheme, which
1943 * for PowerPC (tm) is usually the case) in the tregister holds
1946 tsec_mcast_addr (struct eth_device
*dev
, u8 mcast_mac
, u8 set
)
1948 struct tsec_private
*priv
= privlist
[1];
1949 volatile tsec_t
*regs
= priv
->regs
;
1950 volatile u32
*reg_array
, value
;
1951 u8 result
, whichbit
, whichreg
;
1953 result
= (u8
)((ether_crc(MAC_ADDR_LEN
,mcast_mac
) >> 24) & 0xff);
1954 whichbit
= result
& 0x1f; /* the 5 LSB = which bit to set */
1955 whichreg
= result
>> 5; /* the 3 MSB = which reg to set it in */
1956 value
= (1 << (31-whichbit
));
1958 reg_array
= &(regs
->hash
.gaddr0
);
1961 reg_array
[whichreg
] |= value
;
1963 reg_array
[whichreg
] &= ~value
;
1967 #endif /* Multicast TFTP ? */