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 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
163 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
164 && !defined(BITBANGMII)
165 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
168 /* Try to initialize PHY here, and return */
169 return init_phy(dev);
172 /* Initializes data structures and registers for the controller,
173 * and brings the interface up. Returns the link status, meaning
174 * that it returns success if the link is up, failure otherwise.
175 * This allows u-boot to find the first active controller.
177 int tsec_init(struct eth_device *dev, bd_t * bd)
180 char tmpbuf[MAC_ADDR_LEN];
182 struct tsec_private *priv = (struct tsec_private *)dev->priv;
183 volatile tsec_t *regs = priv->regs;
185 /* Make sure the controller is stopped */
188 /* Init MACCFG2. Defaults to GMII */
189 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
192 regs->ecntrl = ECNTRL_INIT_SETTINGS;
194 /* Copy the station address into the address registers.
195 * Backwards, because little endian MACS are dumb */
196 for (i = 0; i < MAC_ADDR_LEN; i++) {
197 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
199 regs->macstnaddr1 = *((uint *) (tmpbuf));
201 tempval = *((uint *) (tmpbuf + 4));
203 regs->macstnaddr2 = tempval;
205 /* reset the indices to zero */
209 /* Clear out (for the most part) the other registers */
210 init_registers(regs);
212 /* Ready the device for tx/rx */
215 /* If there's no link, fail */
216 return (priv->link ? 0 : -1);
219 /* Writes the given phy's reg with value, using the specified MDIO regs */
220 static void tsec_local_mdio_write(volatile tsec_t *phyregs, uint addr,
221 uint reg, uint value)
223 int timeout = 1000000;
225 phyregs->miimadd = (addr << 8) | reg;
226 phyregs->miimcon = value;
230 while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
234 /* Provide the default behavior of writing the PHY of this ethernet device */
235 #define write_phy_reg(priv, regnum, value) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
237 /* Reads register regnum on the device's PHY through the
238 * specified registers. It lowers and raises the read
239 * command, and waits for the data to become valid (miimind
240 * notvalid bit cleared), and the bus to cease activity (miimind
241 * busy bit cleared), and then returns the value
243 uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum)
247 /* Put the address of the phy, and the register
248 * number into MIIMADD */
249 phyregs->miimadd = (phyid << 8) | regnum;
251 /* Clear the command register, and wait */
252 phyregs->miimcom = 0;
255 /* Initiate a read command, and wait */
256 phyregs->miimcom = MIIM_READ_COMMAND;
259 /* Wait for the the indication that the read is done */
260 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
262 /* Grab the value read from the PHY */
263 value = phyregs->miimstat;
268 /* #define to provide old read_phy_reg functionality without duplicating code */
269 #define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
271 #define TBIANA_SETTINGS ( \
272 TBIANA_ASYMMETRIC_PAUSE \
273 | TBIANA_SYMMETRIC_PAUSE \
274 | TBIANA_FULL_DUPLEX \
277 #define TBICR_SETTINGS ( \
279 | TBICR_ANEG_ENABLE \
280 | TBICR_FULL_DUPLEX \
283 /* Configure the TBI for SGMII operation */
284 static void tsec_configure_serdes(struct tsec_private *priv)
286 /* Access TBI PHY registers at given TSEC register offset as opposed to the
287 * register offset used for external PHY accesses */
288 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_ANA,
290 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_TBICON,
292 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_CR,
296 /* Discover which PHY is attached to the device, and configure it
297 * properly. If the PHY is not recognized, then return 0
298 * (failure). Otherwise, return 1
300 static int init_phy(struct eth_device *dev)
302 struct tsec_private *priv = (struct tsec_private *)dev->priv;
303 struct phy_info *curphy;
304 volatile tsec_t *phyregs = priv->phyregs;
305 volatile tsec_t *regs = priv->regs;
307 /* Assign a Physical address to the TBI */
308 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
309 phyregs->tbipa = CONFIG_SYS_TBIPA_VALUE;
312 /* Reset MII (due to new addresses) */
313 priv->phyregs->miimcfg = MIIMCFG_RESET;
315 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
317 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
322 /* Get the cmd structure corresponding to the attached
324 curphy = get_phy_info(dev);
326 if (curphy == NULL) {
327 priv->phyinfo = NULL;
328 printf("%s: No PHY found\n", dev->name);
333 if (regs->ecntrl & ECNTRL_SGMII_MODE)
334 tsec_configure_serdes(priv);
336 priv->phyinfo = curphy;
338 phy_run_commands(priv, priv->phyinfo->config);
344 * Returns which value to write to the control register.
345 * For 10/100, the value is slightly different
347 uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
349 if (priv->flags & TSEC_GIGABIT)
350 return MIIM_CONTROL_INIT;
355 /* Parse the status register for link, and then do
358 uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
361 * Wait if the link is up, and autonegotiation is in progress
362 * (ie - we're capable and it's not done)
364 mii_reg = read_phy_reg(priv, MIIM_STATUS);
365 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
366 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
369 puts("Waiting for PHY auto negotiation to complete");
370 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
374 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
375 puts(" TIMEOUT !\n");
380 if ((i++ % 1000) == 0) {
383 udelay(1000); /* 1 ms */
384 mii_reg = read_phy_reg(priv, MIIM_STATUS);
388 udelay(500000); /* another 500 ms (results in faster booting) */
390 if (mii_reg & MIIM_STATUS_LINK)
399 /* Generic function which updates the speed and duplex. If
400 * autonegotiation is enabled, it uses the AND of the link
401 * partner's advertised capabilities and our advertised
402 * capabilities. If autonegotiation is disabled, we use the
403 * appropriate bits in the control register.
405 * Stolen from Linux's mii.c and phy_device.c
407 uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
409 /* We're using autonegotiation */
410 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
414 /* Check for gigabit capability */
415 if (mii_reg & PHY_BMSR_EXT) {
416 /* We want a list of states supported by
417 * both PHYs in the link
419 gblpa = read_phy_reg(priv, PHY_1000BTSR);
420 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
423 /* Set the baseline so we only have to set them
424 * if they're different
429 /* Check the gigabit fields */
430 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
433 if (gblpa & PHY_1000BTSR_1000FD)
440 lpa = read_phy_reg(priv, PHY_ANAR);
441 lpa &= read_phy_reg(priv, PHY_ANLPAR);
443 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
446 if (lpa & PHY_ANLPAR_TXFD)
449 } else if (lpa & PHY_ANLPAR_10FD)
452 uint bmcr = read_phy_reg(priv, PHY_BMCR);
457 if (bmcr & PHY_BMCR_DPLX)
460 if (bmcr & PHY_BMCR_1000_MBPS)
462 else if (bmcr & PHY_BMCR_100_MBPS)
470 * Parse the BCM54xx status register for speed and duplex information.
471 * The linux sungem_phy has this information, but in a table format.
473 uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
476 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
479 printf("Enet starting in 10BT/HD\n");
485 printf("Enet starting in 10BT/FD\n");
491 printf("Enet starting in 100BT/HD\n");
497 printf("Enet starting in 100BT/FD\n");
503 printf("Enet starting in 1000BT/HD\n");
509 printf("Enet starting in 1000BT/FD\n");
515 printf("Auto-neg error, defaulting to 10BT/HD\n");
524 /* Parse the 88E1011's status register for speed and duplex
527 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
531 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
533 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
534 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
537 puts("Waiting for PHY realtime link");
538 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
539 /* Timeout reached ? */
540 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
541 puts(" TIMEOUT !\n");
546 if ((i++ % 1000) == 0) {
549 udelay(1000); /* 1 ms */
550 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
553 udelay(500000); /* another 500 ms (results in faster booting) */
555 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
561 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
566 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
569 case MIIM_88E1011_PHYSTAT_GBIT:
572 case MIIM_88E1011_PHYSTAT_100:
582 /* Parse the RTL8211B's status register for speed and duplex
585 uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
589 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
590 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
593 /* in case of timeout ->link is cleared */
595 puts("Waiting for PHY realtime link");
596 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
597 /* Timeout reached ? */
598 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
599 puts(" TIMEOUT !\n");
604 if ((i++ % 1000) == 0) {
607 udelay(1000); /* 1 ms */
608 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
611 udelay(500000); /* another 500 ms (results in faster booting) */
613 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
619 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
624 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
627 case MIIM_RTL8211B_PHYSTAT_GBIT:
630 case MIIM_RTL8211B_PHYSTAT_100:
640 /* Parse the cis8201's status register for speed and duplex
643 uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
647 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
652 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
654 case MIIM_CIS8201_AUXCONSTAT_GBIT:
657 case MIIM_CIS8201_AUXCONSTAT_100:
668 /* Parse the vsc8244's status register for speed and duplex
671 uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
675 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
680 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
682 case MIIM_VSC8244_AUXCONSTAT_GBIT:
685 case MIIM_VSC8244_AUXCONSTAT_100:
696 /* Parse the DM9161's status register for speed and duplex
699 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
701 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
706 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
715 * Hack to write all 4 PHYs with the LED values
717 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
720 volatile tsec_t *regbase = priv->phyregs;
721 int timeout = 1000000;
723 for (phyid = 0; phyid < 4; phyid++) {
724 regbase->miimadd = (phyid << 8) | mii_reg;
725 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
729 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
732 return MIIM_CIS8204_SLEDCON_INIT;
735 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
737 if (priv->flags & TSEC_REDUCED)
738 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
740 return MIIM_CIS8204_EPHYCON_INIT;
743 uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
745 uint mii_data = read_phy_reg(priv, mii_reg);
747 if (priv->flags & TSEC_REDUCED)
748 mii_data = (mii_data & 0xfff0) | 0x000b;
752 /* Initialized required registers to appropriate values, zeroing
753 * those we don't care about (unless zero is bad, in which case,
754 * choose a more appropriate value)
756 static void init_registers(volatile tsec_t * regs)
759 regs->ievent = IEVENT_INIT_CLEAR;
761 regs->imask = IMASK_INIT_CLEAR;
763 regs->hash.iaddr0 = 0;
764 regs->hash.iaddr1 = 0;
765 regs->hash.iaddr2 = 0;
766 regs->hash.iaddr3 = 0;
767 regs->hash.iaddr4 = 0;
768 regs->hash.iaddr5 = 0;
769 regs->hash.iaddr6 = 0;
770 regs->hash.iaddr7 = 0;
772 regs->hash.gaddr0 = 0;
773 regs->hash.gaddr1 = 0;
774 regs->hash.gaddr2 = 0;
775 regs->hash.gaddr3 = 0;
776 regs->hash.gaddr4 = 0;
777 regs->hash.gaddr5 = 0;
778 regs->hash.gaddr6 = 0;
779 regs->hash.gaddr7 = 0;
781 regs->rctrl = 0x00000000;
783 /* Init RMON mib registers */
784 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
786 regs->rmon.cam1 = 0xffffffff;
787 regs->rmon.cam2 = 0xffffffff;
789 regs->mrblr = MRBLR_INIT_SETTINGS;
791 regs->minflr = MINFLR_INIT_SETTINGS;
793 regs->attr = ATTR_INIT_SETTINGS;
794 regs->attreli = ATTRELI_INIT_SETTINGS;
798 /* Configure maccfg2 based on negotiated speed and duplex
799 * reported by PHY handling code
801 static void adjust_link(struct eth_device *dev)
803 struct tsec_private *priv = (struct tsec_private *)dev->priv;
804 volatile tsec_t *regs = priv->regs;
807 if (priv->duplexity != 0)
808 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
810 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
812 switch (priv->speed) {
814 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
819 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
822 /* Set R100 bit in all modes although
823 * it is only used in RGMII mode
825 if (priv->speed == 100)
826 regs->ecntrl |= ECNTRL_R100;
828 regs->ecntrl &= ~(ECNTRL_R100);
831 printf("%s: Speed was bad\n", dev->name);
835 printf("Speed: %d, %s duplex\n", priv->speed,
836 (priv->duplexity) ? "full" : "half");
839 printf("%s: No link.\n", dev->name);
843 /* Set up the buffers and their descriptors, and bring up the
846 static void startup_tsec(struct eth_device *dev)
849 struct tsec_private *priv = (struct tsec_private *)dev->priv;
850 volatile tsec_t *regs = priv->regs;
852 /* Point to the buffer descriptors */
853 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
854 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
856 /* Initialize the Rx Buffer descriptors */
857 for (i = 0; i < PKTBUFSRX; i++) {
858 rtx.rxbd[i].status = RXBD_EMPTY;
859 rtx.rxbd[i].length = 0;
860 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
862 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
864 /* Initialize the TX Buffer Descriptors */
865 for (i = 0; i < TX_BUF_CNT; i++) {
866 rtx.txbd[i].status = 0;
867 rtx.txbd[i].length = 0;
868 rtx.txbd[i].bufPtr = 0;
870 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
872 /* Start up the PHY */
874 phy_run_commands(priv, priv->phyinfo->startup);
878 /* Enable Transmit and Receive */
879 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
881 /* Tell the DMA it is clear to go */
882 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
883 regs->tstat = TSTAT_CLEAR_THALT;
884 regs->rstat = RSTAT_CLEAR_RHALT;
885 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
888 /* This returns the status bits of the device. The return value
889 * is never checked, and this is what the 8260 driver did, so we
890 * do the same. Presumably, this would be zero if there were no
893 static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
897 struct tsec_private *priv = (struct tsec_private *)dev->priv;
898 volatile tsec_t *regs = priv->regs;
900 /* Find an empty buffer descriptor */
901 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
902 if (i >= TOUT_LOOP) {
903 debug("%s: tsec: tx buffers full\n", dev->name);
908 rtx.txbd[txIdx].bufPtr = (uint) packet;
909 rtx.txbd[txIdx].length = length;
910 rtx.txbd[txIdx].status |=
911 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
913 /* Tell the DMA to go */
914 regs->tstat = TSTAT_CLEAR_THALT;
916 /* Wait for buffer to be transmitted */
917 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
918 if (i >= TOUT_LOOP) {
919 debug("%s: tsec: tx error\n", dev->name);
924 txIdx = (txIdx + 1) % TX_BUF_CNT;
925 result = rtx.txbd[txIdx].status & TXBD_STATS;
930 static int tsec_recv(struct eth_device *dev)
933 struct tsec_private *priv = (struct tsec_private *)dev->priv;
934 volatile tsec_t *regs = priv->regs;
936 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
938 length = rtx.rxbd[rxIdx].length;
940 /* Send the packet up if there were no errors */
941 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
942 NetReceive(NetRxPackets[rxIdx], length - 4);
944 printf("Got error %x\n",
945 (rtx.rxbd[rxIdx].status & RXBD_STATS));
948 rtx.rxbd[rxIdx].length = 0;
950 /* Set the wrap bit if this is the last element in the list */
951 rtx.rxbd[rxIdx].status =
952 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
954 rxIdx = (rxIdx + 1) % PKTBUFSRX;
957 if (regs->ievent & IEVENT_BSY) {
958 regs->ievent = IEVENT_BSY;
959 regs->rstat = RSTAT_CLEAR_RHALT;
966 /* Stop the interface */
967 static void tsec_halt(struct eth_device *dev)
969 struct tsec_private *priv = (struct tsec_private *)dev->priv;
970 volatile tsec_t *regs = priv->regs;
972 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
973 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
975 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
977 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
979 /* Shut down the PHY, as needed */
981 phy_run_commands(priv, priv->phyinfo->shutdown);
984 struct phy_info phy_info_M88E1149S = {
988 (struct phy_cmd[]){ /* config */
989 /* Reset and configure the PHY */
990 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
992 {0x1e, 0x200c, NULL},
996 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
997 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
998 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
999 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1002 (struct phy_cmd[]){ /* startup */
1003 /* Status is read once to clear old link state */
1004 {MIIM_STATUS, miim_read, NULL},
1005 /* Auto-negotiate */
1006 {MIIM_STATUS, miim_read, &mii_parse_sr},
1007 /* Read the status */
1008 {MIIM_88E1011_PHY_STATUS, miim_read,
1009 &mii_parse_88E1011_psr},
1012 (struct phy_cmd[]){ /* shutdown */
1017 /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1018 struct phy_info phy_info_BCM5461S = {
1019 0x02060c1, /* 5461 ID */
1020 "Broadcom BCM5461S",
1021 0, /* not clear to me what minor revisions we can shift away */
1022 (struct phy_cmd[]) { /* config */
1023 /* Reset and configure the PHY */
1024 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1025 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1026 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1027 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1028 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1031 (struct phy_cmd[]) { /* startup */
1032 /* Status is read once to clear old link state */
1033 {MIIM_STATUS, miim_read, NULL},
1034 /* Auto-negotiate */
1035 {MIIM_STATUS, miim_read, &mii_parse_sr},
1036 /* Read the status */
1037 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1040 (struct phy_cmd[]) { /* shutdown */
1045 struct phy_info phy_info_BCM5464S = {
1046 0x02060b1, /* 5464 ID */
1047 "Broadcom BCM5464S",
1048 0, /* not clear to me what minor revisions we can shift away */
1049 (struct phy_cmd[]) { /* config */
1050 /* Reset and configure the PHY */
1051 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1052 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1053 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1054 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1055 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1058 (struct phy_cmd[]) { /* startup */
1059 /* Status is read once to clear old link state */
1060 {MIIM_STATUS, miim_read, NULL},
1061 /* Auto-negotiate */
1062 {MIIM_STATUS, miim_read, &mii_parse_sr},
1063 /* Read the status */
1064 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1067 (struct phy_cmd[]) { /* shutdown */
1072 struct phy_info phy_info_M88E1011S = {
1076 (struct phy_cmd[]){ /* config */
1077 /* Reset and configure the PHY */
1078 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1080 {0x1e, 0x200c, NULL},
1083 {0x1e, 0x100, NULL},
1084 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1085 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1086 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1087 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1090 (struct phy_cmd[]){ /* startup */
1091 /* Status is read once to clear old link state */
1092 {MIIM_STATUS, miim_read, NULL},
1093 /* Auto-negotiate */
1094 {MIIM_STATUS, miim_read, &mii_parse_sr},
1095 /* Read the status */
1096 {MIIM_88E1011_PHY_STATUS, miim_read,
1097 &mii_parse_88E1011_psr},
1100 (struct phy_cmd[]){ /* shutdown */
1105 struct phy_info phy_info_M88E1111S = {
1109 (struct phy_cmd[]){ /* config */
1110 /* Reset and configure the PHY */
1111 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1112 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1113 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1114 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1115 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1116 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1117 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1120 (struct phy_cmd[]){ /* startup */
1121 /* Status is read once to clear old link state */
1122 {MIIM_STATUS, miim_read, NULL},
1123 /* Auto-negotiate */
1124 {MIIM_STATUS, miim_read, &mii_parse_sr},
1125 /* Read the status */
1126 {MIIM_88E1011_PHY_STATUS, miim_read,
1127 &mii_parse_88E1011_psr},
1130 (struct phy_cmd[]){ /* shutdown */
1135 struct phy_info phy_info_M88E1118 = {
1139 (struct phy_cmd[]){ /* config */
1140 /* Reset and configure the PHY */
1141 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1142 {0x16, 0x0002, NULL}, /* Change Page Number */
1143 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
1144 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1145 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1146 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1147 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1150 (struct phy_cmd[]){ /* startup */
1151 {0x16, 0x0000, NULL}, /* Change Page Number */
1152 /* Status is read once to clear old link state */
1153 {MIIM_STATUS, miim_read, NULL},
1154 /* Auto-negotiate */
1155 /* Read the status */
1156 {MIIM_88E1011_PHY_STATUS, miim_read,
1157 &mii_parse_88E1011_psr},
1160 (struct phy_cmd[]){ /* shutdown */
1166 * Since to access LED register we need do switch the page, we
1167 * do LED configuring in the miim_read-like function as follows
1169 uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1173 /* Switch the page to access the led register */
1174 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1175 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1177 /* Configure leds */
1178 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1179 MIIM_88E1121_PHY_LED_DEF);
1181 /* Restore the page pointer */
1182 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1186 struct phy_info phy_info_M88E1121R = {
1190 (struct phy_cmd[]){ /* config */
1191 /* Reset and configure the PHY */
1192 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1193 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1194 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1195 /* Configure leds */
1196 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1197 &mii_88E1121_set_led},
1198 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1199 /* Disable IRQs and de-assert interrupt */
1200 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1201 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
1204 (struct phy_cmd[]){ /* startup */
1205 /* Status is read once to clear old link state */
1206 {MIIM_STATUS, miim_read, NULL},
1207 {MIIM_STATUS, miim_read, &mii_parse_sr},
1208 {MIIM_STATUS, miim_read, &mii_parse_link},
1211 (struct phy_cmd[]){ /* shutdown */
1216 static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1218 uint mii_data = read_phy_reg(priv, mii_reg);
1220 /* Setting MIIM_88E1145_PHY_EXT_CR */
1221 if (priv->flags & TSEC_REDUCED)
1223 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
1228 static struct phy_info phy_info_M88E1145 = {
1232 (struct phy_cmd[]){ /* config */
1234 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1242 /* Configure the PHY */
1243 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1244 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1245 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1247 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1248 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1249 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1252 (struct phy_cmd[]){ /* startup */
1253 /* Status is read once to clear old link state */
1254 {MIIM_STATUS, miim_read, NULL},
1255 /* Auto-negotiate */
1256 {MIIM_STATUS, miim_read, &mii_parse_sr},
1257 {MIIM_88E1111_PHY_LED_CONTROL,
1258 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1259 /* Read the Status */
1260 {MIIM_88E1011_PHY_STATUS, miim_read,
1261 &mii_parse_88E1011_psr},
1264 (struct phy_cmd[]){ /* shutdown */
1269 struct phy_info phy_info_cis8204 = {
1273 (struct phy_cmd[]){ /* config */
1274 /* Override PHY config settings */
1275 {MIIM_CIS8201_AUX_CONSTAT,
1276 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1277 /* Configure some basic stuff */
1278 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1279 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1280 &mii_cis8204_fixled},
1281 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1282 &mii_cis8204_setmode},
1285 (struct phy_cmd[]){ /* startup */
1286 /* Read the Status (2x to make sure link is right) */
1287 {MIIM_STATUS, miim_read, NULL},
1288 /* Auto-negotiate */
1289 {MIIM_STATUS, miim_read, &mii_parse_sr},
1290 /* Read the status */
1291 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1292 &mii_parse_cis8201},
1295 (struct phy_cmd[]){ /* shutdown */
1301 struct phy_info phy_info_cis8201 = {
1305 (struct phy_cmd[]){ /* config */
1306 /* Override PHY config settings */
1307 {MIIM_CIS8201_AUX_CONSTAT,
1308 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1309 /* Set up the interface mode */
1310 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1312 /* Configure some basic stuff */
1313 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1316 (struct phy_cmd[]){ /* startup */
1317 /* Read the Status (2x to make sure link is right) */
1318 {MIIM_STATUS, miim_read, NULL},
1319 /* Auto-negotiate */
1320 {MIIM_STATUS, miim_read, &mii_parse_sr},
1321 /* Read the status */
1322 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1323 &mii_parse_cis8201},
1326 (struct phy_cmd[]){ /* shutdown */
1330 struct phy_info phy_info_VSC8244 = {
1334 (struct phy_cmd[]){ /* config */
1335 /* Override PHY config settings */
1336 /* Configure some basic stuff */
1337 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1340 (struct phy_cmd[]){ /* startup */
1341 /* Read the Status (2x to make sure link is right) */
1342 {MIIM_STATUS, miim_read, NULL},
1343 /* Auto-negotiate */
1344 {MIIM_STATUS, miim_read, &mii_parse_sr},
1345 /* Read the status */
1346 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1347 &mii_parse_vsc8244},
1350 (struct phy_cmd[]){ /* shutdown */
1355 struct phy_info phy_info_VSC8601 = {
1359 (struct phy_cmd[]){ /* config */
1360 /* Override PHY config settings */
1361 /* Configure some basic stuff */
1362 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1363 #ifdef CONFIG_SYS_VSC8601_SKEWFIX
1364 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
1365 #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
1366 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1367 #define VSC8101_SKEW (CONFIG_SYS_VSC8601_SKEW_TX<<14)|(CONFIG_SYS_VSC8601_SKEW_RX<<12)
1368 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1369 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1372 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1373 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
1376 (struct phy_cmd[]){ /* startup */
1377 /* Read the Status (2x to make sure link is right) */
1378 {MIIM_STATUS, miim_read, NULL},
1379 /* Auto-negotiate */
1380 {MIIM_STATUS, miim_read, &mii_parse_sr},
1381 /* Read the status */
1382 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1383 &mii_parse_vsc8244},
1386 (struct phy_cmd[]){ /* shutdown */
1392 struct phy_info phy_info_dm9161 = {
1396 (struct phy_cmd[]){ /* config */
1397 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1398 /* Do not bypass the scrambler/descrambler */
1399 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1400 /* Clear 10BTCSR to default */
1401 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1403 /* Configure some basic stuff */
1404 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1405 /* Restart Auto Negotiation */
1406 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1409 (struct phy_cmd[]){ /* startup */
1410 /* Status is read once to clear old link state */
1411 {MIIM_STATUS, miim_read, NULL},
1412 /* Auto-negotiate */
1413 {MIIM_STATUS, miim_read, &mii_parse_sr},
1414 /* Read the status */
1415 {MIIM_DM9161_SCSR, miim_read,
1416 &mii_parse_dm9161_scsr},
1419 (struct phy_cmd[]){ /* shutdown */
1423 /* a generic flavor. */
1424 struct phy_info phy_info_generic = {
1426 "Unknown/Generic PHY",
1428 (struct phy_cmd[]) { /* config */
1429 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1430 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1433 (struct phy_cmd[]) { /* startup */
1434 {PHY_BMSR, miim_read, NULL},
1435 {PHY_BMSR, miim_read, &mii_parse_sr},
1436 {PHY_BMSR, miim_read, &mii_parse_link},
1439 (struct phy_cmd[]) { /* shutdown */
1445 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1449 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
1452 case MIIM_LXT971_SR2_10HDX:
1454 priv->duplexity = 0;
1456 case MIIM_LXT971_SR2_10FDX:
1458 priv->duplexity = 1;
1460 case MIIM_LXT971_SR2_100HDX:
1462 priv->duplexity = 0;
1466 priv->duplexity = 1;
1470 priv->duplexity = 0;
1476 static struct phy_info phy_info_lxt971 = {
1480 (struct phy_cmd[]){ /* config */
1481 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1484 (struct phy_cmd[]){ /* startup - enable interrupts */
1485 /* { 0x12, 0x00f2, NULL }, */
1486 {MIIM_STATUS, miim_read, NULL},
1487 {MIIM_STATUS, miim_read, &mii_parse_sr},
1488 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1491 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1496 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1499 uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1501 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1503 case MIIM_DP83865_SPD_1000:
1507 case MIIM_DP83865_SPD_100:
1517 if (mii_reg & MIIM_DP83865_DPX_FULL)
1518 priv->duplexity = 1;
1520 priv->duplexity = 0;
1525 struct phy_info phy_info_dp83865 = {
1529 (struct phy_cmd[]){ /* config */
1530 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1533 (struct phy_cmd[]){ /* startup */
1534 /* Status is read once to clear old link state */
1535 {MIIM_STATUS, miim_read, NULL},
1536 /* Auto-negotiate */
1537 {MIIM_STATUS, miim_read, &mii_parse_sr},
1538 /* Read the link and auto-neg status */
1539 {MIIM_DP83865_LANR, miim_read,
1540 &mii_parse_dp83865_lanr},
1543 (struct phy_cmd[]){ /* shutdown */
1548 struct phy_info phy_info_rtl8211b = {
1552 (struct phy_cmd[]){ /* config */
1553 /* Reset and configure the PHY */
1554 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1555 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1556 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1557 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1558 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1561 (struct phy_cmd[]){ /* startup */
1562 /* Status is read once to clear old link state */
1563 {MIIM_STATUS, miim_read, NULL},
1564 /* Auto-negotiate */
1565 {MIIM_STATUS, miim_read, &mii_parse_sr},
1566 /* Read the status */
1567 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1570 (struct phy_cmd[]){ /* shutdown */
1575 struct phy_info *phy_info[] = {
1580 &phy_info_M88E1011S,
1581 &phy_info_M88E1111S,
1583 &phy_info_M88E1121R,
1585 &phy_info_M88E1149S,
1596 /* Grab the identifier of the device's PHY, and search through
1597 * all of the known PHYs to see if one matches. If so, return
1598 * it, if not, return NULL
1600 struct phy_info *get_phy_info(struct eth_device *dev)
1602 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1603 uint phy_reg, phy_ID;
1605 struct phy_info *theInfo = NULL;
1607 /* Grab the bits from PHYIR1, and put them in the upper half */
1608 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1609 phy_ID = (phy_reg & 0xffff) << 16;
1611 /* Grab the bits from PHYIR2, and put them in the lower half */
1612 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1613 phy_ID |= (phy_reg & 0xffff);
1615 /* loop through all the known PHY types, and find one that */
1616 /* matches the ID we read from the PHY. */
1617 for (i = 0; phy_info[i]; i++) {
1618 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
1619 theInfo = phy_info[i];
1624 if (theInfo == NULL) {
1625 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1628 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1634 /* Execute the given series of commands on the given device's
1635 * PHY, running functions as necessary
1637 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1641 volatile tsec_t *phyregs = priv->phyregs;
1643 phyregs->miimcfg = MIIMCFG_RESET;
1645 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1647 while (phyregs->miimind & MIIMIND_BUSY) ;
1649 for (i = 0; cmd->mii_reg != miim_end; i++) {
1650 if (cmd->mii_data == miim_read) {
1651 result = read_phy_reg(priv, cmd->mii_reg);
1653 if (cmd->funct != NULL)
1654 (*(cmd->funct)) (result, priv);
1657 if (cmd->funct != NULL)
1658 result = (*(cmd->funct)) (cmd->mii_reg, priv);
1660 result = cmd->mii_data;
1662 write_phy_reg(priv, cmd->mii_reg, result);
1669 /* Relocate the function pointers in the phy cmd lists */
1670 static void relocate_cmds(void)
1672 struct phy_cmd **cmdlistptr;
1673 struct phy_cmd *cmd;
1676 for (i = 0; phy_info[i]; i++) {
1677 /* First thing's first: relocate the pointers to the
1678 * PHY command structures (the structs were done) */
1679 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1681 phy_info[i]->name += gd->reloc_off;
1682 phy_info[i]->config =
1683 (struct phy_cmd *)((uint) phy_info[i]->config
1685 phy_info[i]->startup =
1686 (struct phy_cmd *)((uint) phy_info[i]->startup
1688 phy_info[i]->shutdown =
1689 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1692 cmdlistptr = &phy_info[i]->config;
1694 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1696 for (cmd = *cmdlistptr;
1697 cmd->mii_reg != miim_end;
1699 /* Only relocate non-NULL pointers */
1701 cmd->funct += gd->reloc_off;
1712 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1713 && !defined(BITBANGMII)
1716 * Read a MII PHY register.
1721 static int tsec_miiphy_read(char *devname, unsigned char addr,
1722 unsigned char reg, unsigned short *value)
1725 struct tsec_private *priv = privlist[0];
1728 printf("Can't read PHY at address %d\n", addr);
1732 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
1739 * Write a MII PHY register.
1744 static int tsec_miiphy_write(char *devname, unsigned char addr,
1745 unsigned char reg, unsigned short value)
1747 struct tsec_private *priv = privlist[0];
1750 printf("Can't write PHY at address %d\n", addr);
1754 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
1761 #ifdef CONFIG_MCAST_TFTP
1763 /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1765 /* Set the appropriate hash bit for the given addr */
1767 /* The algorithm works like so:
1768 * 1) Take the Destination Address (ie the multicast address), and
1769 * do a CRC on it (little endian), and reverse the bits of the
1771 * 2) Use the 8 most significant bits as a hash into a 256-entry
1772 * table. The table is controlled through 8 32-bit registers:
1773 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1774 * gaddr7. This means that the 3 most significant bits in the
1775 * hash index which gaddr register to use, and the 5 other bits
1776 * indicate which bit (assuming an IBM numbering scheme, which
1777 * for PowerPC (tm) is usually the case) in the tregister holds
1780 tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1782 struct tsec_private *priv = privlist[1];
1783 volatile tsec_t *regs = priv->regs;
1784 volatile u32 *reg_array, value;
1785 u8 result, whichbit, whichreg;
1787 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1788 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1789 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1790 value = (1 << (31-whichbit));
1792 reg_array = &(regs->hash.gaddr0);
1795 reg_array[whichreg] |= value;
1797 reg_array[whichreg] &= ~value;
1801 #endif /* Multicast TFTP ? */