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, 2007 Freescale Semiconductor, Inc.
9 * (C) Copyright 2003, Motorola, Inc.
23 DECLARE_GLOBAL_DATA_PTR;
27 static uint rxIdx; /* index of the current RX buffer */
28 static uint txIdx; /* index of the current TX buffer */
30 typedef volatile struct rtxbd {
31 txbd8_t txbd[TX_BUF_CNT];
32 rxbd8_t rxbd[PKTBUFSRX];
35 #define MAXCONTROLLERS (8)
37 static int relocated = 0;
39 static struct tsec_private *privlist[MAXCONTROLLERS];
40 static int num_tsecs = 0;
43 static RTXBD rtx __attribute__ ((aligned(8)));
45 #error "rtx must be 64-bit aligned"
48 static int tsec_send(struct eth_device *dev,
49 volatile void *packet, int length);
50 static int tsec_recv(struct eth_device *dev);
51 static int tsec_init(struct eth_device *dev, bd_t * bd);
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 struct phy_info *get_phy_info(struct eth_device *dev);
59 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
60 static void adjust_link(struct eth_device *dev);
61 static void relocate_cmds(void);
62 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
63 && !defined(BITBANGMII)
64 static int tsec_miiphy_write(char *devname, unsigned char addr,
65 unsigned char reg, unsigned short value);
66 static int tsec_miiphy_read(char *devname, unsigned char addr,
67 unsigned char reg, unsigned short *value);
69 #ifdef CONFIG_MCAST_TFTP
70 static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
73 /* Default initializations for TSEC controllers. */
75 static struct tsec_info_struct tsec_info[] = {
77 STD_TSEC_INFO(1), /* TSEC1 */
80 STD_TSEC_INFO(2), /* TSEC2 */
82 #ifdef CONFIG_MPC85XX_FEC
84 .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
85 .miiregs = (tsec_t *)(TSEC_BASE_ADDR),
86 .devname = CONFIG_MPC85XX_FEC_NAME,
87 .phyaddr = FEC_PHY_ADDR,
92 STD_TSEC_INFO(3), /* TSEC3 */
95 STD_TSEC_INFO(4), /* TSEC4 */
99 int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
103 for (i = 0; i < num; i++)
104 tsec_initialize(bis, &tsecs[i]);
109 int tsec_standard_init(bd_t *bis)
111 return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
114 /* Initialize device structure. Returns success if PHY
115 * initialization succeeded (i.e. if it recognizes the PHY)
117 int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
119 struct eth_device *dev;
121 struct tsec_private *priv;
123 dev = (struct eth_device *)malloc(sizeof *dev);
128 memset(dev, 0, sizeof *dev);
130 priv = (struct tsec_private *)malloc(sizeof(*priv));
135 privlist[num_tsecs++] = priv;
136 priv->regs = tsec_info->regs;
137 priv->phyregs = tsec_info->miiregs;
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 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_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) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
241 /* Reads register regnum on the device's PHY through the
242 * specified registers. It lowers and raises the read
243 * command, and waits for the data to become valid (miimind
244 * notvalid bit cleared), and the bus to cease activity (miimind
245 * busy bit cleared), and then returns the value
247 uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum)
251 /* Put the address of the phy, and the register
252 * number into MIIMADD */
253 phyregs->miimadd = (phyid << 8) | regnum;
255 /* Clear the command register, and wait */
256 phyregs->miimcom = 0;
259 /* Initiate a read command, and wait */
260 phyregs->miimcom = MIIM_READ_COMMAND;
263 /* Wait for the the indication that the read is done */
264 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
266 /* Grab the value read from the PHY */
267 value = phyregs->miimstat;
272 /* #define to provide old read_phy_reg functionality without duplicating code */
273 #define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
275 #define TBIANA_SETTINGS ( \
276 TBIANA_ASYMMETRIC_PAUSE \
277 | TBIANA_SYMMETRIC_PAUSE \
278 | TBIANA_FULL_DUPLEX \
281 #define TBICR_SETTINGS ( \
283 | TBICR_ANEG_ENABLE \
284 | TBICR_FULL_DUPLEX \
287 /* Configure the TBI for SGMII operation */
288 static void tsec_configure_serdes(struct tsec_private *priv)
290 /* Access TBI PHY registers at given TSEC register offset as opposed to the
291 * register offset used for external PHY accesses */
292 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_ANA,
294 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_TBICON,
296 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_CR,
300 /* Discover which PHY is attached to the device, and configure it
301 * properly. If the PHY is not recognized, then return 0
302 * (failure). Otherwise, return 1
304 static int init_phy(struct eth_device *dev)
306 struct tsec_private *priv = (struct tsec_private *)dev->priv;
307 struct phy_info *curphy;
308 volatile tsec_t *phyregs = priv->phyregs;
309 volatile tsec_t *regs = priv->regs;
311 /* Assign a Physical address to the TBI */
312 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
313 phyregs->tbipa = CONFIG_SYS_TBIPA_VALUE;
316 /* Reset MII (due to new addresses) */
317 priv->phyregs->miimcfg = MIIMCFG_RESET;
319 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
321 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
326 /* Get the cmd structure corresponding to the attached
328 curphy = get_phy_info(dev);
330 if (curphy == NULL) {
331 priv->phyinfo = NULL;
332 printf("%s: No PHY found\n", dev->name);
337 if (regs->ecntrl & ECNTRL_SGMII_MODE)
338 tsec_configure_serdes(priv);
340 priv->phyinfo = curphy;
342 phy_run_commands(priv, priv->phyinfo->config);
348 * Returns which value to write to the control register.
349 * For 10/100, the value is slightly different
351 uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
353 if (priv->flags & TSEC_GIGABIT)
354 return MIIM_CONTROL_INIT;
359 /* Parse the status register for link, and then do
362 uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
365 * Wait if the link is up, and autonegotiation is in progress
366 * (ie - we're capable and it's not done)
368 mii_reg = read_phy_reg(priv, MIIM_STATUS);
369 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
370 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
373 puts("Waiting for PHY auto negotiation to complete");
374 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
378 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
379 puts(" TIMEOUT !\n");
384 if ((i++ % 1000) == 0) {
387 udelay(1000); /* 1 ms */
388 mii_reg = read_phy_reg(priv, MIIM_STATUS);
392 udelay(500000); /* another 500 ms (results in faster booting) */
394 if (mii_reg & MIIM_STATUS_LINK)
403 /* Generic function which updates the speed and duplex. If
404 * autonegotiation is enabled, it uses the AND of the link
405 * partner's advertised capabilities and our advertised
406 * capabilities. If autonegotiation is disabled, we use the
407 * appropriate bits in the control register.
409 * Stolen from Linux's mii.c and phy_device.c
411 uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
413 /* We're using autonegotiation */
414 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
418 /* Check for gigabit capability */
419 if (mii_reg & PHY_BMSR_EXT) {
420 /* We want a list of states supported by
421 * both PHYs in the link
423 gblpa = read_phy_reg(priv, PHY_1000BTSR);
424 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
427 /* Set the baseline so we only have to set them
428 * if they're different
433 /* Check the gigabit fields */
434 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
437 if (gblpa & PHY_1000BTSR_1000FD)
444 lpa = read_phy_reg(priv, PHY_ANAR);
445 lpa &= read_phy_reg(priv, PHY_ANLPAR);
447 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
450 if (lpa & PHY_ANLPAR_TXFD)
453 } else if (lpa & PHY_ANLPAR_10FD)
456 uint bmcr = read_phy_reg(priv, PHY_BMCR);
461 if (bmcr & PHY_BMCR_DPLX)
464 if (bmcr & PHY_BMCR_1000_MBPS)
466 else if (bmcr & PHY_BMCR_100_MBPS)
474 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
475 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
476 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
477 * link. "Ethernet@Wirespeed" reduces advertised speed until link
480 uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
482 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
486 * Parse the BCM54xx status register for speed and duplex information.
487 * The linux sungem_phy has this information, but in a table format.
489 uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
492 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
495 printf("Enet starting in 10BT/HD\n");
501 printf("Enet starting in 10BT/FD\n");
507 printf("Enet starting in 100BT/HD\n");
513 printf("Enet starting in 100BT/FD\n");
519 printf("Enet starting in 1000BT/HD\n");
525 printf("Enet starting in 1000BT/FD\n");
531 printf("Auto-neg error, defaulting to 10BT/HD\n");
540 /* Parse the 88E1011's status register for speed and duplex
543 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
547 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
549 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
550 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
553 puts("Waiting for PHY realtime link");
554 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
555 /* Timeout reached ? */
556 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
557 puts(" TIMEOUT !\n");
562 if ((i++ % 1000) == 0) {
565 udelay(1000); /* 1 ms */
566 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
569 udelay(500000); /* another 500 ms (results in faster booting) */
571 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
577 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
582 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
585 case MIIM_88E1011_PHYSTAT_GBIT:
588 case MIIM_88E1011_PHYSTAT_100:
598 /* Parse the RTL8211B's status register for speed and duplex
601 uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
605 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
606 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
609 /* in case of timeout ->link is cleared */
611 puts("Waiting for PHY realtime link");
612 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
613 /* Timeout reached ? */
614 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
615 puts(" TIMEOUT !\n");
620 if ((i++ % 1000) == 0) {
623 udelay(1000); /* 1 ms */
624 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
627 udelay(500000); /* another 500 ms (results in faster booting) */
629 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
635 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
640 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
643 case MIIM_RTL8211B_PHYSTAT_GBIT:
646 case MIIM_RTL8211B_PHYSTAT_100:
656 /* Parse the cis8201's status register for speed and duplex
659 uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
663 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
668 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
670 case MIIM_CIS8201_AUXCONSTAT_GBIT:
673 case MIIM_CIS8201_AUXCONSTAT_100:
684 /* Parse the vsc8244's status register for speed and duplex
687 uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
691 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
696 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
698 case MIIM_VSC8244_AUXCONSTAT_GBIT:
701 case MIIM_VSC8244_AUXCONSTAT_100:
712 /* Parse the DM9161's status register for speed and duplex
715 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
717 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
722 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
731 * Hack to write all 4 PHYs with the LED values
733 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
736 volatile tsec_t *regbase = priv->phyregs;
737 int timeout = 1000000;
739 for (phyid = 0; phyid < 4; phyid++) {
740 regbase->miimadd = (phyid << 8) | mii_reg;
741 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
745 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
748 return MIIM_CIS8204_SLEDCON_INIT;
751 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
753 if (priv->flags & TSEC_REDUCED)
754 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
756 return MIIM_CIS8204_EPHYCON_INIT;
759 uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
761 uint mii_data = read_phy_reg(priv, mii_reg);
763 if (priv->flags & TSEC_REDUCED)
764 mii_data = (mii_data & 0xfff0) | 0x000b;
768 /* Initialized required registers to appropriate values, zeroing
769 * those we don't care about (unless zero is bad, in which case,
770 * choose a more appropriate value)
772 static void init_registers(volatile tsec_t * regs)
775 regs->ievent = IEVENT_INIT_CLEAR;
777 regs->imask = IMASK_INIT_CLEAR;
779 regs->hash.iaddr0 = 0;
780 regs->hash.iaddr1 = 0;
781 regs->hash.iaddr2 = 0;
782 regs->hash.iaddr3 = 0;
783 regs->hash.iaddr4 = 0;
784 regs->hash.iaddr5 = 0;
785 regs->hash.iaddr6 = 0;
786 regs->hash.iaddr7 = 0;
788 regs->hash.gaddr0 = 0;
789 regs->hash.gaddr1 = 0;
790 regs->hash.gaddr2 = 0;
791 regs->hash.gaddr3 = 0;
792 regs->hash.gaddr4 = 0;
793 regs->hash.gaddr5 = 0;
794 regs->hash.gaddr6 = 0;
795 regs->hash.gaddr7 = 0;
797 regs->rctrl = 0x00000000;
799 /* Init RMON mib registers */
800 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
802 regs->rmon.cam1 = 0xffffffff;
803 regs->rmon.cam2 = 0xffffffff;
805 regs->mrblr = MRBLR_INIT_SETTINGS;
807 regs->minflr = MINFLR_INIT_SETTINGS;
809 regs->attr = ATTR_INIT_SETTINGS;
810 regs->attreli = ATTRELI_INIT_SETTINGS;
814 /* Configure maccfg2 based on negotiated speed and duplex
815 * reported by PHY handling code
817 static void adjust_link(struct eth_device *dev)
819 struct tsec_private *priv = (struct tsec_private *)dev->priv;
820 volatile tsec_t *regs = priv->regs;
823 if (priv->duplexity != 0)
824 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
826 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
828 switch (priv->speed) {
830 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
835 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
838 /* Set R100 bit in all modes although
839 * it is only used in RGMII mode
841 if (priv->speed == 100)
842 regs->ecntrl |= ECNTRL_R100;
844 regs->ecntrl &= ~(ECNTRL_R100);
847 printf("%s: Speed was bad\n", dev->name);
851 printf("Speed: %d, %s duplex\n", priv->speed,
852 (priv->duplexity) ? "full" : "half");
855 printf("%s: No link.\n", dev->name);
859 /* Set up the buffers and their descriptors, and bring up the
862 static void startup_tsec(struct eth_device *dev)
865 struct tsec_private *priv = (struct tsec_private *)dev->priv;
866 volatile tsec_t *regs = priv->regs;
868 /* Point to the buffer descriptors */
869 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
870 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
872 /* Initialize the Rx Buffer descriptors */
873 for (i = 0; i < PKTBUFSRX; i++) {
874 rtx.rxbd[i].status = RXBD_EMPTY;
875 rtx.rxbd[i].length = 0;
876 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
878 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
880 /* Initialize the TX Buffer Descriptors */
881 for (i = 0; i < TX_BUF_CNT; i++) {
882 rtx.txbd[i].status = 0;
883 rtx.txbd[i].length = 0;
884 rtx.txbd[i].bufPtr = 0;
886 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
888 /* Start up the PHY */
890 phy_run_commands(priv, priv->phyinfo->startup);
894 /* Enable Transmit and Receive */
895 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
897 /* Tell the DMA it is clear to go */
898 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
899 regs->tstat = TSTAT_CLEAR_THALT;
900 regs->rstat = RSTAT_CLEAR_RHALT;
901 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
904 /* This returns the status bits of the device. The return value
905 * is never checked, and this is what the 8260 driver did, so we
906 * do the same. Presumably, this would be zero if there were no
909 static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
913 struct tsec_private *priv = (struct tsec_private *)dev->priv;
914 volatile tsec_t *regs = priv->regs;
916 /* Find an empty buffer descriptor */
917 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
918 if (i >= TOUT_LOOP) {
919 debug("%s: tsec: tx buffers full\n", dev->name);
924 rtx.txbd[txIdx].bufPtr = (uint) packet;
925 rtx.txbd[txIdx].length = length;
926 rtx.txbd[txIdx].status |=
927 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
929 /* Tell the DMA to go */
930 regs->tstat = TSTAT_CLEAR_THALT;
932 /* Wait for buffer to be transmitted */
933 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
934 if (i >= TOUT_LOOP) {
935 debug("%s: tsec: tx error\n", dev->name);
940 txIdx = (txIdx + 1) % TX_BUF_CNT;
941 result = rtx.txbd[txIdx].status & TXBD_STATS;
946 static int tsec_recv(struct eth_device *dev)
949 struct tsec_private *priv = (struct tsec_private *)dev->priv;
950 volatile tsec_t *regs = priv->regs;
952 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
954 length = rtx.rxbd[rxIdx].length;
956 /* Send the packet up if there were no errors */
957 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
958 NetReceive(NetRxPackets[rxIdx], length - 4);
960 printf("Got error %x\n",
961 (rtx.rxbd[rxIdx].status & RXBD_STATS));
964 rtx.rxbd[rxIdx].length = 0;
966 /* Set the wrap bit if this is the last element in the list */
967 rtx.rxbd[rxIdx].status =
968 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
970 rxIdx = (rxIdx + 1) % PKTBUFSRX;
973 if (regs->ievent & IEVENT_BSY) {
974 regs->ievent = IEVENT_BSY;
975 regs->rstat = RSTAT_CLEAR_RHALT;
982 /* Stop the interface */
983 static void tsec_halt(struct eth_device *dev)
985 struct tsec_private *priv = (struct tsec_private *)dev->priv;
986 volatile tsec_t *regs = priv->regs;
988 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
989 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
991 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
993 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
995 /* Shut down the PHY, as needed */
997 phy_run_commands(priv, priv->phyinfo->shutdown);
1000 struct phy_info phy_info_M88E1149S = {
1004 (struct phy_cmd[]){ /* config */
1005 /* Reset and configure the PHY */
1006 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1008 {0x1e, 0x200c, NULL},
1011 {0x1e, 0x100, NULL},
1012 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1013 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1014 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1015 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1018 (struct phy_cmd[]){ /* startup */
1019 /* Status is read once to clear old link state */
1020 {MIIM_STATUS, miim_read, NULL},
1021 /* Auto-negotiate */
1022 {MIIM_STATUS, miim_read, &mii_parse_sr},
1023 /* Read the status */
1024 {MIIM_88E1011_PHY_STATUS, miim_read,
1025 &mii_parse_88E1011_psr},
1028 (struct phy_cmd[]){ /* shutdown */
1033 /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1034 struct phy_info phy_info_BCM5461S = {
1035 0x02060c1, /* 5461 ID */
1036 "Broadcom BCM5461S",
1037 0, /* not clear to me what minor revisions we can shift away */
1038 (struct phy_cmd[]) { /* config */
1039 /* Reset and configure the PHY */
1040 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1041 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1042 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1043 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1044 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1047 (struct phy_cmd[]) { /* startup */
1048 /* Status is read once to clear old link state */
1049 {MIIM_STATUS, miim_read, NULL},
1050 /* Auto-negotiate */
1051 {MIIM_STATUS, miim_read, &mii_parse_sr},
1052 /* Read the status */
1053 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1056 (struct phy_cmd[]) { /* shutdown */
1061 struct phy_info phy_info_BCM5464S = {
1062 0x02060b1, /* 5464 ID */
1063 "Broadcom BCM5464S",
1064 0, /* not clear to me what minor revisions we can shift away */
1065 (struct phy_cmd[]) { /* config */
1066 /* Reset and configure the PHY */
1067 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1068 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1069 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1070 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1071 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1074 (struct phy_cmd[]) { /* startup */
1075 /* Status is read once to clear old link state */
1076 {MIIM_STATUS, miim_read, NULL},
1077 /* Auto-negotiate */
1078 {MIIM_STATUS, miim_read, &mii_parse_sr},
1079 /* Read the status */
1080 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1083 (struct phy_cmd[]) { /* shutdown */
1088 struct phy_info phy_info_BCM5482S = {
1090 "Broadcom BCM5482S",
1092 (struct phy_cmd[]) { /* config */
1093 /* Reset and configure the PHY */
1094 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1095 /* Setup read from auxilary control shadow register 7 */
1096 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
1097 /* Read Misc Control register and or in Ethernet@Wirespeed */
1098 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
1099 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1102 (struct phy_cmd[]) { /* startup */
1103 /* Status is read once to clear old link state */
1104 {MIIM_STATUS, miim_read, NULL},
1105 /* Auto-negotiate */
1106 {MIIM_STATUS, miim_read, &mii_parse_sr},
1107 /* Read the status */
1108 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1111 (struct phy_cmd[]) { /* shutdown */
1116 struct phy_info phy_info_M88E1011S = {
1120 (struct phy_cmd[]){ /* config */
1121 /* Reset and configure the PHY */
1122 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1124 {0x1e, 0x200c, NULL},
1127 {0x1e, 0x100, NULL},
1128 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1129 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1130 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1131 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1134 (struct phy_cmd[]){ /* startup */
1135 /* Status is read once to clear old link state */
1136 {MIIM_STATUS, miim_read, NULL},
1137 /* Auto-negotiate */
1138 {MIIM_STATUS, miim_read, &mii_parse_sr},
1139 /* Read the status */
1140 {MIIM_88E1011_PHY_STATUS, miim_read,
1141 &mii_parse_88E1011_psr},
1144 (struct phy_cmd[]){ /* shutdown */
1149 struct phy_info phy_info_M88E1111S = {
1153 (struct phy_cmd[]){ /* config */
1154 /* Reset and configure the PHY */
1155 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1156 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1157 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1158 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1159 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1160 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1161 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1164 (struct phy_cmd[]){ /* startup */
1165 /* Status is read once to clear old link state */
1166 {MIIM_STATUS, miim_read, NULL},
1167 /* Auto-negotiate */
1168 {MIIM_STATUS, miim_read, &mii_parse_sr},
1169 /* Read the status */
1170 {MIIM_88E1011_PHY_STATUS, miim_read,
1171 &mii_parse_88E1011_psr},
1174 (struct phy_cmd[]){ /* shutdown */
1179 struct phy_info phy_info_M88E1118 = {
1183 (struct phy_cmd[]){ /* config */
1184 /* Reset and configure the PHY */
1185 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1186 {0x16, 0x0002, NULL}, /* Change Page Number */
1187 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
1188 {0x16, 0x0003, NULL}, /* Change Page Number */
1189 {0x10, 0x021e, NULL}, /* Adjust LED control */
1190 {0x16, 0x0000, NULL}, /* Change Page Number */
1191 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1192 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1193 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1194 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1197 (struct phy_cmd[]){ /* startup */
1198 {0x16, 0x0000, NULL}, /* Change Page Number */
1199 /* Status is read once to clear old link state */
1200 {MIIM_STATUS, miim_read, NULL},
1201 /* Auto-negotiate */
1202 {MIIM_STATUS, miim_read, &mii_parse_sr},
1203 /* Read the status */
1204 {MIIM_88E1011_PHY_STATUS, miim_read,
1205 &mii_parse_88E1011_psr},
1208 (struct phy_cmd[]){ /* shutdown */
1214 * Since to access LED register we need do switch the page, we
1215 * do LED configuring in the miim_read-like function as follows
1217 uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1221 /* Switch the page to access the led register */
1222 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1223 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1225 /* Configure leds */
1226 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1227 MIIM_88E1121_PHY_LED_DEF);
1229 /* Restore the page pointer */
1230 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1234 struct phy_info phy_info_M88E1121R = {
1238 (struct phy_cmd[]){ /* config */
1239 /* Reset and configure the PHY */
1240 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1241 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1242 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1243 /* Configure leds */
1244 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1245 &mii_88E1121_set_led},
1246 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1247 /* Disable IRQs and de-assert interrupt */
1248 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1249 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
1252 (struct phy_cmd[]){ /* startup */
1253 /* Status is read once to clear old link state */
1254 {MIIM_STATUS, miim_read, NULL},
1255 {MIIM_STATUS, miim_read, &mii_parse_sr},
1256 {MIIM_STATUS, miim_read, &mii_parse_link},
1259 (struct phy_cmd[]){ /* shutdown */
1264 static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1266 uint mii_data = read_phy_reg(priv, mii_reg);
1268 /* Setting MIIM_88E1145_PHY_EXT_CR */
1269 if (priv->flags & TSEC_REDUCED)
1271 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
1276 static struct phy_info phy_info_M88E1145 = {
1280 (struct phy_cmd[]){ /* config */
1282 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1290 /* Configure the PHY */
1291 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1292 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1293 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1295 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1296 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1297 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1300 (struct phy_cmd[]){ /* startup */
1301 /* Status is read once to clear old link state */
1302 {MIIM_STATUS, miim_read, NULL},
1303 /* Auto-negotiate */
1304 {MIIM_STATUS, miim_read, &mii_parse_sr},
1305 {MIIM_88E1111_PHY_LED_CONTROL,
1306 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1307 /* Read the Status */
1308 {MIIM_88E1011_PHY_STATUS, miim_read,
1309 &mii_parse_88E1011_psr},
1312 (struct phy_cmd[]){ /* shutdown */
1317 struct phy_info phy_info_cis8204 = {
1321 (struct phy_cmd[]){ /* config */
1322 /* Override PHY config settings */
1323 {MIIM_CIS8201_AUX_CONSTAT,
1324 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1325 /* Configure some basic stuff */
1326 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1327 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1328 &mii_cis8204_fixled},
1329 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1330 &mii_cis8204_setmode},
1333 (struct phy_cmd[]){ /* startup */
1334 /* Read the Status (2x to make sure link is right) */
1335 {MIIM_STATUS, miim_read, NULL},
1336 /* Auto-negotiate */
1337 {MIIM_STATUS, miim_read, &mii_parse_sr},
1338 /* Read the status */
1339 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1340 &mii_parse_cis8201},
1343 (struct phy_cmd[]){ /* shutdown */
1349 struct phy_info phy_info_cis8201 = {
1353 (struct phy_cmd[]){ /* config */
1354 /* Override PHY config settings */
1355 {MIIM_CIS8201_AUX_CONSTAT,
1356 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1357 /* Set up the interface mode */
1358 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1360 /* Configure some basic stuff */
1361 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1364 (struct phy_cmd[]){ /* startup */
1365 /* Read the Status (2x to make sure link is right) */
1366 {MIIM_STATUS, miim_read, NULL},
1367 /* Auto-negotiate */
1368 {MIIM_STATUS, miim_read, &mii_parse_sr},
1369 /* Read the status */
1370 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1371 &mii_parse_cis8201},
1374 (struct phy_cmd[]){ /* shutdown */
1378 struct phy_info phy_info_VSC8211 = {
1382 (struct phy_cmd[]) { /* config */
1383 /* Override PHY config settings */
1384 {MIIM_CIS8201_AUX_CONSTAT,
1385 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1386 /* Set up the interface mode */
1387 {MIIM_CIS8201_EXT_CON1,
1388 MIIM_CIS8201_EXTCON1_INIT, NULL},
1389 /* Configure some basic stuff */
1390 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1393 (struct phy_cmd[]) { /* startup */
1394 /* Read the Status (2x to make sure link is right) */
1395 {MIIM_STATUS, miim_read, NULL},
1396 /* Auto-negotiate */
1397 {MIIM_STATUS, miim_read, &mii_parse_sr},
1398 /* Read the status */
1399 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1400 &mii_parse_cis8201},
1403 (struct phy_cmd[]) { /* shutdown */
1407 struct phy_info phy_info_VSC8244 = {
1411 (struct phy_cmd[]){ /* config */
1412 /* Override PHY config settings */
1413 /* Configure some basic stuff */
1414 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1417 (struct phy_cmd[]){ /* startup */
1418 /* Read the Status (2x to make sure link is right) */
1419 {MIIM_STATUS, miim_read, NULL},
1420 /* Auto-negotiate */
1421 {MIIM_STATUS, miim_read, &mii_parse_sr},
1422 /* Read the status */
1423 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1424 &mii_parse_vsc8244},
1427 (struct phy_cmd[]){ /* shutdown */
1432 struct phy_info phy_info_VSC8601 = {
1436 (struct phy_cmd[]){ /* config */
1437 /* Override PHY config settings */
1438 /* Configure some basic stuff */
1439 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1440 #ifdef CONFIG_SYS_VSC8601_SKEWFIX
1441 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
1442 #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
1443 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1444 #define VSC8101_SKEW (CONFIG_SYS_VSC8601_SKEW_TX<<14)|(CONFIG_SYS_VSC8601_SKEW_RX<<12)
1445 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1446 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1449 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1450 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &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_VSC8244_AUX_CONSTAT, miim_read,
1460 &mii_parse_vsc8244},
1463 (struct phy_cmd[]){ /* shutdown */
1469 struct phy_info phy_info_dm9161 = {
1473 (struct phy_cmd[]){ /* config */
1474 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1475 /* Do not bypass the scrambler/descrambler */
1476 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1477 /* Clear 10BTCSR to default */
1478 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1480 /* Configure some basic stuff */
1481 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1482 /* Restart Auto Negotiation */
1483 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1486 (struct phy_cmd[]){ /* startup */
1487 /* Status is read once to clear old link state */
1488 {MIIM_STATUS, miim_read, NULL},
1489 /* Auto-negotiate */
1490 {MIIM_STATUS, miim_read, &mii_parse_sr},
1491 /* Read the status */
1492 {MIIM_DM9161_SCSR, miim_read,
1493 &mii_parse_dm9161_scsr},
1496 (struct phy_cmd[]){ /* shutdown */
1500 /* a generic flavor. */
1501 struct phy_info phy_info_generic = {
1503 "Unknown/Generic PHY",
1505 (struct phy_cmd[]) { /* config */
1506 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1507 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1510 (struct phy_cmd[]) { /* startup */
1511 {PHY_BMSR, miim_read, NULL},
1512 {PHY_BMSR, miim_read, &mii_parse_sr},
1513 {PHY_BMSR, miim_read, &mii_parse_link},
1516 (struct phy_cmd[]) { /* shutdown */
1522 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1526 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
1529 case MIIM_LXT971_SR2_10HDX:
1531 priv->duplexity = 0;
1533 case MIIM_LXT971_SR2_10FDX:
1535 priv->duplexity = 1;
1537 case MIIM_LXT971_SR2_100HDX:
1539 priv->duplexity = 0;
1543 priv->duplexity = 1;
1547 priv->duplexity = 0;
1553 static struct phy_info phy_info_lxt971 = {
1557 (struct phy_cmd[]){ /* config */
1558 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1561 (struct phy_cmd[]){ /* startup - enable interrupts */
1562 /* { 0x12, 0x00f2, NULL }, */
1563 {MIIM_STATUS, miim_read, NULL},
1564 {MIIM_STATUS, miim_read, &mii_parse_sr},
1565 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1568 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1573 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1576 uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1578 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1580 case MIIM_DP83865_SPD_1000:
1584 case MIIM_DP83865_SPD_100:
1594 if (mii_reg & MIIM_DP83865_DPX_FULL)
1595 priv->duplexity = 1;
1597 priv->duplexity = 0;
1602 struct phy_info phy_info_dp83865 = {
1606 (struct phy_cmd[]){ /* config */
1607 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1610 (struct phy_cmd[]){ /* startup */
1611 /* Status is read once to clear old link state */
1612 {MIIM_STATUS, miim_read, NULL},
1613 /* Auto-negotiate */
1614 {MIIM_STATUS, miim_read, &mii_parse_sr},
1615 /* Read the link and auto-neg status */
1616 {MIIM_DP83865_LANR, miim_read,
1617 &mii_parse_dp83865_lanr},
1620 (struct phy_cmd[]){ /* shutdown */
1625 struct phy_info phy_info_rtl8211b = {
1629 (struct phy_cmd[]){ /* config */
1630 /* Reset and configure the PHY */
1631 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1632 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1633 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1634 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1635 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1638 (struct phy_cmd[]){ /* startup */
1639 /* Status is read once to clear old link state */
1640 {MIIM_STATUS, miim_read, NULL},
1641 /* Auto-negotiate */
1642 {MIIM_STATUS, miim_read, &mii_parse_sr},
1643 /* Read the status */
1644 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1647 (struct phy_cmd[]){ /* shutdown */
1652 struct phy_info *phy_info[] = {
1658 &phy_info_M88E1011S,
1659 &phy_info_M88E1111S,
1661 &phy_info_M88E1121R,
1663 &phy_info_M88E1149S,
1671 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
1675 /* Grab the identifier of the device's PHY, and search through
1676 * all of the known PHYs to see if one matches. If so, return
1677 * it, if not, return NULL
1679 struct phy_info *get_phy_info(struct eth_device *dev)
1681 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1682 uint phy_reg, phy_ID;
1684 struct phy_info *theInfo = NULL;
1686 /* Grab the bits from PHYIR1, and put them in the upper half */
1687 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1688 phy_ID = (phy_reg & 0xffff) << 16;
1690 /* Grab the bits from PHYIR2, and put them in the lower half */
1691 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1692 phy_ID |= (phy_reg & 0xffff);
1694 /* loop through all the known PHY types, and find one that */
1695 /* matches the ID we read from the PHY. */
1696 for (i = 0; phy_info[i]; i++) {
1697 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
1698 theInfo = phy_info[i];
1703 if (theInfo == &phy_info_generic) {
1704 printf("%s: No support for PHY id %x; assuming generic\n", dev->name, phy_ID);
1706 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1712 /* Execute the given series of commands on the given device's
1713 * PHY, running functions as necessary
1715 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1719 volatile tsec_t *phyregs = priv->phyregs;
1721 phyregs->miimcfg = MIIMCFG_RESET;
1723 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1725 while (phyregs->miimind & MIIMIND_BUSY) ;
1727 for (i = 0; cmd->mii_reg != miim_end; i++) {
1728 if (cmd->mii_data == miim_read) {
1729 result = read_phy_reg(priv, cmd->mii_reg);
1731 if (cmd->funct != NULL)
1732 (*(cmd->funct)) (result, priv);
1735 if (cmd->funct != NULL)
1736 result = (*(cmd->funct)) (cmd->mii_reg, priv);
1738 result = cmd->mii_data;
1740 write_phy_reg(priv, cmd->mii_reg, result);
1747 /* Relocate the function pointers in the phy cmd lists */
1748 static void relocate_cmds(void)
1750 struct phy_cmd **cmdlistptr;
1751 struct phy_cmd *cmd;
1754 for (i = 0; phy_info[i]; i++) {
1755 /* First thing's first: relocate the pointers to the
1756 * PHY command structures (the structs were done) */
1757 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1759 phy_info[i]->name += gd->reloc_off;
1760 phy_info[i]->config =
1761 (struct phy_cmd *)((uint) phy_info[i]->config
1763 phy_info[i]->startup =
1764 (struct phy_cmd *)((uint) phy_info[i]->startup
1766 phy_info[i]->shutdown =
1767 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1770 cmdlistptr = &phy_info[i]->config;
1772 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1774 for (cmd = *cmdlistptr;
1775 cmd->mii_reg != miim_end;
1777 /* Only relocate non-NULL pointers */
1779 cmd->funct += gd->reloc_off;
1790 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1791 && !defined(BITBANGMII)
1794 * Read a MII PHY register.
1799 static int tsec_miiphy_read(char *devname, unsigned char addr,
1800 unsigned char reg, unsigned short *value)
1803 struct tsec_private *priv = privlist[0];
1806 printf("Can't read PHY at address %d\n", addr);
1810 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
1817 * Write a MII PHY register.
1822 static int tsec_miiphy_write(char *devname, unsigned char addr,
1823 unsigned char reg, unsigned short value)
1825 struct tsec_private *priv = privlist[0];
1828 printf("Can't write PHY at address %d\n", addr);
1832 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
1839 #ifdef CONFIG_MCAST_TFTP
1841 /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1843 /* Set the appropriate hash bit for the given addr */
1845 /* The algorithm works like so:
1846 * 1) Take the Destination Address (ie the multicast address), and
1847 * do a CRC on it (little endian), and reverse the bits of the
1849 * 2) Use the 8 most significant bits as a hash into a 256-entry
1850 * table. The table is controlled through 8 32-bit registers:
1851 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1852 * gaddr7. This means that the 3 most significant bits in the
1853 * hash index which gaddr register to use, and the 5 other bits
1854 * indicate which bit (assuming an IBM numbering scheme, which
1855 * for PowerPC (tm) is usually the case) in the tregister holds
1858 tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1860 struct tsec_private *priv = privlist[1];
1861 volatile tsec_t *regs = priv->regs;
1862 volatile u32 *reg_array, value;
1863 u8 result, whichbit, whichreg;
1865 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1866 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1867 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1868 value = (1 << (31-whichbit));
1870 reg_array = &(regs->hash.gaddr0);
1873 reg_array[whichreg] |= value;
1875 reg_array[whichreg] &= ~value;
1879 #endif /* Multicast TFTP ? */