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 struct tsec_info_struct {
38 unsigned int phyregidx;
41 /* The tsec_info structure contains 3 values which the
42 * driver uses to determine how to operate a given ethernet
43 * device. The information needed is:
44 * phyaddr - The address of the PHY which is attached to
47 * flags - This variable indicates whether the device
48 * supports gigabit speed ethernet, and whether it should be
51 * phyregidx - This variable specifies which ethernet device
52 * controls the MII Management registers which are connected
53 * to the PHY. For now, only TSEC1 (index 0) has
54 * access to the PHYs, so all of the entries have "0".
56 * The values specified in the table are taken from the board's
57 * config file in include/configs/. When implementing a new
58 * board with ethernet capability, it is necessary to define:
62 * for n = 1,2,3, etc. And for FEC:
66 static struct tsec_info_struct tsec_info[] = {
68 {TSEC1_PHY_ADDR, TSEC1_FLAGS, TSEC1_PHYIDX},
73 {TSEC2_PHY_ADDR, TSEC2_FLAGS, TSEC2_PHYIDX},
77 #ifdef CONFIG_MPC85XX_FEC
78 {FEC_PHY_ADDR, FEC_FLAGS, FEC_PHYIDX},
81 {TSEC3_PHY_ADDR, TSEC3_FLAGS, TSEC3_PHYIDX},
86 {TSEC4_PHY_ADDR, TSEC4_FLAGS, TSEC4_PHYIDX},
89 #endif /* CONFIG_TSEC4 */
90 #endif /* CONFIG_MPC85XX_FEC */
93 #define MAXCONTROLLERS (4)
95 static int relocated = 0;
97 static struct tsec_private *privlist[MAXCONTROLLERS];
100 static RTXBD rtx __attribute__ ((aligned(8)));
102 #error "rtx must be 64-bit aligned"
105 static int tsec_send(struct eth_device *dev,
106 volatile void *packet, int length);
107 static int tsec_recv(struct eth_device *dev);
108 static int tsec_init(struct eth_device *dev, bd_t * bd);
109 static void tsec_halt(struct eth_device *dev);
110 static void init_registers(volatile tsec_t * regs);
111 static void startup_tsec(struct eth_device *dev);
112 static int init_phy(struct eth_device *dev);
113 void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
114 uint read_phy_reg(struct tsec_private *priv, uint regnum);
115 struct phy_info *get_phy_info(struct eth_device *dev);
116 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
117 static void adjust_link(struct eth_device *dev);
118 static void relocate_cmds(void);
119 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
120 && !defined(BITBANGMII)
121 static int tsec_miiphy_write(char *devname, unsigned char addr,
122 unsigned char reg, unsigned short value);
123 static int tsec_miiphy_read(char *devname, unsigned char addr,
124 unsigned char reg, unsigned short *value);
126 #ifdef CONFIG_MCAST_TFTP
127 static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
130 /* Initialize device structure. Returns success if PHY
131 * initialization succeeded (i.e. if it recognizes the PHY)
133 int tsec_initialize(bd_t * bis, int index, char *devname)
135 struct eth_device *dev;
137 struct tsec_private *priv;
139 dev = (struct eth_device *)malloc(sizeof *dev);
144 memset(dev, 0, sizeof *dev);
146 priv = (struct tsec_private *)malloc(sizeof(*priv));
151 privlist[index] = priv;
152 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE);
153 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
154 tsec_info[index].phyregidx *
157 priv->phyaddr = tsec_info[index].phyaddr;
158 priv->flags = tsec_info[index].flags;
160 sprintf(dev->name, devname);
163 dev->init = tsec_init;
164 dev->halt = tsec_halt;
165 dev->send = tsec_send;
166 dev->recv = tsec_recv;
167 #ifdef CONFIG_MCAST_TFTP
168 dev->mcast = tsec_mcast_addr;
171 /* Tell u-boot to get the addr from the env */
172 for (i = 0; i < 6; i++)
173 dev->enetaddr[i] = 0;
178 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
179 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
181 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
182 && !defined(BITBANGMII)
183 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
186 /* Try to initialize PHY here, and return */
187 return init_phy(dev);
190 /* Initializes data structures and registers for the controller,
191 * and brings the interface up. Returns the link status, meaning
192 * that it returns success if the link is up, failure otherwise.
193 * This allows u-boot to find the first active controller.
195 int tsec_init(struct eth_device *dev, bd_t * bd)
198 char tmpbuf[MAC_ADDR_LEN];
200 struct tsec_private *priv = (struct tsec_private *)dev->priv;
201 volatile tsec_t *regs = priv->regs;
203 /* Make sure the controller is stopped */
206 /* Init MACCFG2. Defaults to GMII */
207 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
210 regs->ecntrl = ECNTRL_INIT_SETTINGS;
212 /* Copy the station address into the address registers.
213 * Backwards, because little endian MACS are dumb */
214 for (i = 0; i < MAC_ADDR_LEN; i++) {
215 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
217 regs->macstnaddr1 = *((uint *) (tmpbuf));
219 tempval = *((uint *) (tmpbuf + 4));
221 regs->macstnaddr2 = tempval;
223 /* reset the indices to zero */
227 /* Clear out (for the most part) the other registers */
228 init_registers(regs);
230 /* Ready the device for tx/rx */
233 /* If there's no link, fail */
234 return (priv->link ? 0 : -1);
238 /* Write value to the device's PHY through the registers
239 * specified in priv, modifying the register specified in regnum.
240 * It will wait for the write to be done (or for a timeout to
241 * expire) before exiting
243 void write_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum, uint value)
245 volatile tsec_t *regbase = priv->phyregs;
246 int timeout = 1000000;
248 regbase->miimadd = (phyid << 8) | regnum;
249 regbase->miimcon = value;
253 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
256 /* #define to provide old write_phy_reg functionality without duplicating code */
257 #define write_phy_reg(priv, regnum, value) write_any_phy_reg(priv,priv->phyaddr,regnum,value)
259 /* Reads register regnum on the device's PHY through the
260 * registers specified in priv. It lowers and raises the read
261 * command, and waits for the data to become valid (miimind
262 * notvalid bit cleared), and the bus to cease activity (miimind
263 * busy bit cleared), and then returns the value
265 uint read_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum)
268 volatile tsec_t *regbase = priv->phyregs;
270 /* Put the address of the phy, and the register
271 * number into MIIMADD */
272 regbase->miimadd = (phyid << 8) | regnum;
274 /* Clear the command register, and wait */
275 regbase->miimcom = 0;
278 /* Initiate a read command, and wait */
279 regbase->miimcom = MIIM_READ_COMMAND;
282 /* Wait for the the indication that the read is done */
283 while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
285 /* Grab the value read from the PHY */
286 value = regbase->miimstat;
291 /* #define to provide old read_phy_reg functionality without duplicating code */
292 #define read_phy_reg(priv,regnum) read_any_phy_reg(priv,priv->phyaddr,regnum)
294 /* Discover which PHY is attached to the device, and configure it
295 * properly. If the PHY is not recognized, then return 0
296 * (failure). Otherwise, return 1
298 static int init_phy(struct eth_device *dev)
300 struct tsec_private *priv = (struct tsec_private *)dev->priv;
301 struct phy_info *curphy;
302 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
304 /* Assign a Physical address to the TBI */
305 regs->tbipa = CFG_TBIPA_VALUE;
306 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
307 regs->tbipa = CFG_TBIPA_VALUE;
310 /* Reset MII (due to new addresses) */
311 priv->phyregs->miimcfg = MIIMCFG_RESET;
313 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
315 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
320 /* Get the cmd structure corresponding to the attached
322 curphy = get_phy_info(dev);
324 if (curphy == NULL) {
325 priv->phyinfo = NULL;
326 printf("%s: No PHY found\n", dev->name);
331 priv->phyinfo = curphy;
333 phy_run_commands(priv, priv->phyinfo->config);
339 * Returns which value to write to the control register.
340 * For 10/100, the value is slightly different
342 uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
344 if (priv->flags & TSEC_GIGABIT)
345 return MIIM_CONTROL_INIT;
350 /* Parse the status register for link, and then do
353 uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
356 * Wait if the link is up, and autonegotiation is in progress
357 * (ie - we're capable and it's not done)
359 mii_reg = read_phy_reg(priv, MIIM_STATUS);
360 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
361 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
364 puts("Waiting for PHY auto negotiation to complete");
365 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
369 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
370 puts(" TIMEOUT !\n");
375 if ((i++ % 1000) == 0) {
378 udelay(1000); /* 1 ms */
379 mii_reg = read_phy_reg(priv, MIIM_STATUS);
383 udelay(500000); /* another 500 ms (results in faster booting) */
385 if (mii_reg & MIIM_STATUS_LINK)
394 /* Generic function which updates the speed and duplex. If
395 * autonegotiation is enabled, it uses the AND of the link
396 * partner's advertised capabilities and our advertised
397 * capabilities. If autonegotiation is disabled, we use the
398 * appropriate bits in the control register.
400 * Stolen from Linux's mii.c and phy_device.c
402 uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
404 /* We're using autonegotiation */
405 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
409 /* Check for gigabit capability */
410 if (mii_reg & PHY_BMSR_EXT) {
411 /* We want a list of states supported by
412 * both PHYs in the link
414 gblpa = read_phy_reg(priv, PHY_1000BTSR);
415 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
418 /* Set the baseline so we only have to set them
419 * if they're different
424 /* Check the gigabit fields */
425 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
428 if (gblpa & PHY_1000BTSR_1000FD)
435 lpa = read_phy_reg(priv, PHY_ANAR);
436 lpa &= read_phy_reg(priv, PHY_ANLPAR);
438 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
441 if (lpa & PHY_ANLPAR_TXFD)
444 } else if (lpa & PHY_ANLPAR_10FD)
447 uint bmcr = read_phy_reg(priv, PHY_BMCR);
452 if (bmcr & PHY_BMCR_DPLX)
455 if (bmcr & PHY_BMCR_1000_MBPS)
457 else if (bmcr & PHY_BMCR_100_MBPS)
465 * Parse the BCM54xx status register for speed and duplex information.
466 * The linux sungem_phy has this information, but in a table format.
468 uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
471 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
474 printf("Enet starting in 10BT/HD\n");
480 printf("Enet starting in 10BT/FD\n");
486 printf("Enet starting in 100BT/HD\n");
492 printf("Enet starting in 100BT/FD\n");
498 printf("Enet starting in 1000BT/HD\n");
504 printf("Enet starting in 1000BT/FD\n");
510 printf("Auto-neg error, defaulting to 10BT/HD\n");
519 /* Parse the 88E1011's status register for speed and duplex
522 uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
526 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
528 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
529 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
532 puts("Waiting for PHY realtime link");
533 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
534 /* Timeout reached ? */
535 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
536 puts(" TIMEOUT !\n");
541 if ((i++ % 1000) == 0) {
544 udelay(1000); /* 1 ms */
545 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
548 udelay(500000); /* another 500 ms (results in faster booting) */
550 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
556 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
561 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
564 case MIIM_88E1011_PHYSTAT_GBIT:
567 case MIIM_88E1011_PHYSTAT_100:
577 /* Parse the RTL8211B's status register for speed and duplex
580 uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
584 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
585 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
588 /* in case of timeout ->link is cleared */
590 puts("Waiting for PHY realtime link");
591 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
592 /* Timeout reached ? */
593 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
594 puts(" TIMEOUT !\n");
599 if ((i++ % 1000) == 0) {
602 udelay(1000); /* 1 ms */
603 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
606 udelay(500000); /* another 500 ms (results in faster booting) */
608 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
614 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
619 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
622 case MIIM_RTL8211B_PHYSTAT_GBIT:
625 case MIIM_RTL8211B_PHYSTAT_100:
635 /* Parse the cis8201's status register for speed and duplex
638 uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
642 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
647 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
649 case MIIM_CIS8201_AUXCONSTAT_GBIT:
652 case MIIM_CIS8201_AUXCONSTAT_100:
663 /* Parse the vsc8244's status register for speed and duplex
666 uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
670 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
675 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
677 case MIIM_VSC8244_AUXCONSTAT_GBIT:
680 case MIIM_VSC8244_AUXCONSTAT_100:
691 /* Parse the DM9161's status register for speed and duplex
694 uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
696 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
701 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
710 * Hack to write all 4 PHYs with the LED values
712 uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
715 volatile tsec_t *regbase = priv->phyregs;
716 int timeout = 1000000;
718 for (phyid = 0; phyid < 4; phyid++) {
719 regbase->miimadd = (phyid << 8) | mii_reg;
720 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
724 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
727 return MIIM_CIS8204_SLEDCON_INIT;
730 uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
732 if (priv->flags & TSEC_REDUCED)
733 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
735 return MIIM_CIS8204_EPHYCON_INIT;
738 uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
740 uint mii_data = read_phy_reg(priv, mii_reg);
742 if (priv->flags & TSEC_REDUCED)
743 mii_data = (mii_data & 0xfff0) | 0x000b;
747 /* Initialized required registers to appropriate values, zeroing
748 * those we don't care about (unless zero is bad, in which case,
749 * choose a more appropriate value)
751 static void init_registers(volatile tsec_t * regs)
754 regs->ievent = IEVENT_INIT_CLEAR;
756 regs->imask = IMASK_INIT_CLEAR;
758 regs->hash.iaddr0 = 0;
759 regs->hash.iaddr1 = 0;
760 regs->hash.iaddr2 = 0;
761 regs->hash.iaddr3 = 0;
762 regs->hash.iaddr4 = 0;
763 regs->hash.iaddr5 = 0;
764 regs->hash.iaddr6 = 0;
765 regs->hash.iaddr7 = 0;
767 regs->hash.gaddr0 = 0;
768 regs->hash.gaddr1 = 0;
769 regs->hash.gaddr2 = 0;
770 regs->hash.gaddr3 = 0;
771 regs->hash.gaddr4 = 0;
772 regs->hash.gaddr5 = 0;
773 regs->hash.gaddr6 = 0;
774 regs->hash.gaddr7 = 0;
776 regs->rctrl = 0x00000000;
778 /* Init RMON mib registers */
779 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
781 regs->rmon.cam1 = 0xffffffff;
782 regs->rmon.cam2 = 0xffffffff;
784 regs->mrblr = MRBLR_INIT_SETTINGS;
786 regs->minflr = MINFLR_INIT_SETTINGS;
788 regs->attr = ATTR_INIT_SETTINGS;
789 regs->attreli = ATTRELI_INIT_SETTINGS;
793 /* Configure maccfg2 based on negotiated speed and duplex
794 * reported by PHY handling code
796 static void adjust_link(struct eth_device *dev)
798 struct tsec_private *priv = (struct tsec_private *)dev->priv;
799 volatile tsec_t *regs = priv->regs;
802 if (priv->duplexity != 0)
803 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
805 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
807 switch (priv->speed) {
809 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
814 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
817 /* Set R100 bit in all modes although
818 * it is only used in RGMII mode
820 if (priv->speed == 100)
821 regs->ecntrl |= ECNTRL_R100;
823 regs->ecntrl &= ~(ECNTRL_R100);
826 printf("%s: Speed was bad\n", dev->name);
830 printf("Speed: %d, %s duplex\n", priv->speed,
831 (priv->duplexity) ? "full" : "half");
834 printf("%s: No link.\n", dev->name);
838 /* Set up the buffers and their descriptors, and bring up the
841 static void startup_tsec(struct eth_device *dev)
844 struct tsec_private *priv = (struct tsec_private *)dev->priv;
845 volatile tsec_t *regs = priv->regs;
847 /* Point to the buffer descriptors */
848 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
849 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
851 /* Initialize the Rx Buffer descriptors */
852 for (i = 0; i < PKTBUFSRX; i++) {
853 rtx.rxbd[i].status = RXBD_EMPTY;
854 rtx.rxbd[i].length = 0;
855 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
857 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
859 /* Initialize the TX Buffer Descriptors */
860 for (i = 0; i < TX_BUF_CNT; i++) {
861 rtx.txbd[i].status = 0;
862 rtx.txbd[i].length = 0;
863 rtx.txbd[i].bufPtr = 0;
865 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
867 /* Start up the PHY */
869 phy_run_commands(priv, priv->phyinfo->startup);
873 /* Enable Transmit and Receive */
874 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
876 /* Tell the DMA it is clear to go */
877 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
878 regs->tstat = TSTAT_CLEAR_THALT;
879 regs->rstat = RSTAT_CLEAR_RHALT;
880 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
883 /* This returns the status bits of the device. The return value
884 * is never checked, and this is what the 8260 driver did, so we
885 * do the same. Presumably, this would be zero if there were no
888 static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
892 struct tsec_private *priv = (struct tsec_private *)dev->priv;
893 volatile tsec_t *regs = priv->regs;
895 /* Find an empty buffer descriptor */
896 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
897 if (i >= TOUT_LOOP) {
898 debug("%s: tsec: tx buffers full\n", dev->name);
903 rtx.txbd[txIdx].bufPtr = (uint) packet;
904 rtx.txbd[txIdx].length = length;
905 rtx.txbd[txIdx].status |=
906 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
908 /* Tell the DMA to go */
909 regs->tstat = TSTAT_CLEAR_THALT;
911 /* Wait for buffer to be transmitted */
912 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
913 if (i >= TOUT_LOOP) {
914 debug("%s: tsec: tx error\n", dev->name);
919 txIdx = (txIdx + 1) % TX_BUF_CNT;
920 result = rtx.txbd[txIdx].status & TXBD_STATS;
925 static int tsec_recv(struct eth_device *dev)
928 struct tsec_private *priv = (struct tsec_private *)dev->priv;
929 volatile tsec_t *regs = priv->regs;
931 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
933 length = rtx.rxbd[rxIdx].length;
935 /* Send the packet up if there were no errors */
936 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
937 NetReceive(NetRxPackets[rxIdx], length - 4);
939 printf("Got error %x\n",
940 (rtx.rxbd[rxIdx].status & RXBD_STATS));
943 rtx.rxbd[rxIdx].length = 0;
945 /* Set the wrap bit if this is the last element in the list */
946 rtx.rxbd[rxIdx].status =
947 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
949 rxIdx = (rxIdx + 1) % PKTBUFSRX;
952 if (regs->ievent & IEVENT_BSY) {
953 regs->ievent = IEVENT_BSY;
954 regs->rstat = RSTAT_CLEAR_RHALT;
961 /* Stop the interface */
962 static void tsec_halt(struct eth_device *dev)
964 struct tsec_private *priv = (struct tsec_private *)dev->priv;
965 volatile tsec_t *regs = priv->regs;
967 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
968 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
970 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
972 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
974 /* Shut down the PHY, as needed */
976 phy_run_commands(priv, priv->phyinfo->shutdown);
979 struct phy_info phy_info_M88E1149S = {
983 (struct phy_cmd[]){ /* config */
984 /* Reset and configure the PHY */
985 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
987 {0x1e, 0x200c, NULL},
991 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
992 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
993 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
994 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
997 (struct phy_cmd[]){ /* startup */
998 /* Status is read once to clear old link state */
999 {MIIM_STATUS, miim_read, NULL},
1000 /* Auto-negotiate */
1001 {MIIM_STATUS, miim_read, &mii_parse_sr},
1002 /* Read the status */
1003 {MIIM_88E1011_PHY_STATUS, miim_read,
1004 &mii_parse_88E1011_psr},
1007 (struct phy_cmd[]){ /* shutdown */
1012 /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1013 struct phy_info phy_info_BCM5461S = {
1014 0x02060c1, /* 5461 ID */
1015 "Broadcom BCM5461S",
1016 0, /* not clear to me what minor revisions we can shift away */
1017 (struct phy_cmd[]) { /* config */
1018 /* Reset and configure the PHY */
1019 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1020 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1021 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1022 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1023 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1026 (struct phy_cmd[]) { /* startup */
1027 /* Status is read once to clear old link state */
1028 {MIIM_STATUS, miim_read, NULL},
1029 /* Auto-negotiate */
1030 {MIIM_STATUS, miim_read, &mii_parse_sr},
1031 /* Read the status */
1032 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1035 (struct phy_cmd[]) { /* shutdown */
1040 struct phy_info phy_info_BCM5464S = {
1041 0x02060b1, /* 5464 ID */
1042 "Broadcom BCM5464S",
1043 0, /* not clear to me what minor revisions we can shift away */
1044 (struct phy_cmd[]) { /* config */
1045 /* Reset and configure the PHY */
1046 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1047 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1048 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1049 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1050 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1053 (struct phy_cmd[]) { /* startup */
1054 /* Status is read once to clear old link state */
1055 {MIIM_STATUS, miim_read, NULL},
1056 /* Auto-negotiate */
1057 {MIIM_STATUS, miim_read, &mii_parse_sr},
1058 /* Read the status */
1059 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1062 (struct phy_cmd[]) { /* shutdown */
1067 struct phy_info phy_info_M88E1011S = {
1071 (struct phy_cmd[]){ /* config */
1072 /* Reset and configure the PHY */
1073 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1075 {0x1e, 0x200c, NULL},
1078 {0x1e, 0x100, NULL},
1079 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1080 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1081 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1082 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1085 (struct phy_cmd[]){ /* startup */
1086 /* Status is read once to clear old link state */
1087 {MIIM_STATUS, miim_read, NULL},
1088 /* Auto-negotiate */
1089 {MIIM_STATUS, miim_read, &mii_parse_sr},
1090 /* Read the status */
1091 {MIIM_88E1011_PHY_STATUS, miim_read,
1092 &mii_parse_88E1011_psr},
1095 (struct phy_cmd[]){ /* shutdown */
1100 struct phy_info phy_info_M88E1111S = {
1104 (struct phy_cmd[]){ /* config */
1105 /* Reset and configure the PHY */
1106 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1107 {0x1b, 0x848f, &mii_m88e1111s_setmode},
1108 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
1109 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1110 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1111 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1112 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1115 (struct phy_cmd[]){ /* startup */
1116 /* Status is read once to clear old link state */
1117 {MIIM_STATUS, miim_read, NULL},
1118 /* Auto-negotiate */
1119 {MIIM_STATUS, miim_read, &mii_parse_sr},
1120 /* Read the status */
1121 {MIIM_88E1011_PHY_STATUS, miim_read,
1122 &mii_parse_88E1011_psr},
1125 (struct phy_cmd[]){ /* shutdown */
1130 struct phy_info phy_info_M88E1118 = {
1134 (struct phy_cmd[]){ /* config */
1135 /* Reset and configure the PHY */
1136 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1137 {0x16, 0x0002, NULL}, /* Change Page Number */
1138 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
1139 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1140 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1141 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1142 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1145 (struct phy_cmd[]){ /* startup */
1146 {0x16, 0x0000, NULL}, /* Change Page Number */
1147 /* Status is read once to clear old link state */
1148 {MIIM_STATUS, miim_read, NULL},
1149 /* Auto-negotiate */
1150 /* Read the status */
1151 {MIIM_88E1011_PHY_STATUS, miim_read,
1152 &mii_parse_88E1011_psr},
1155 (struct phy_cmd[]){ /* shutdown */
1160 static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1162 uint mii_data = read_phy_reg(priv, mii_reg);
1164 /* Setting MIIM_88E1145_PHY_EXT_CR */
1165 if (priv->flags & TSEC_REDUCED)
1167 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
1172 static struct phy_info phy_info_M88E1145 = {
1176 (struct phy_cmd[]){ /* config */
1178 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1186 /* Configure the PHY */
1187 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1188 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1189 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1191 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1192 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1193 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1196 (struct phy_cmd[]){ /* startup */
1197 /* Status is read once to clear old link state */
1198 {MIIM_STATUS, miim_read, NULL},
1199 /* Auto-negotiate */
1200 {MIIM_STATUS, miim_read, &mii_parse_sr},
1201 {MIIM_88E1111_PHY_LED_CONTROL,
1202 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1203 /* Read the Status */
1204 {MIIM_88E1011_PHY_STATUS, miim_read,
1205 &mii_parse_88E1011_psr},
1208 (struct phy_cmd[]){ /* shutdown */
1213 struct phy_info phy_info_cis8204 = {
1217 (struct phy_cmd[]){ /* config */
1218 /* Override PHY config settings */
1219 {MIIM_CIS8201_AUX_CONSTAT,
1220 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1221 /* Configure some basic stuff */
1222 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1223 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1224 &mii_cis8204_fixled},
1225 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1226 &mii_cis8204_setmode},
1229 (struct phy_cmd[]){ /* startup */
1230 /* Read the Status (2x to make sure link is right) */
1231 {MIIM_STATUS, miim_read, NULL},
1232 /* Auto-negotiate */
1233 {MIIM_STATUS, miim_read, &mii_parse_sr},
1234 /* Read the status */
1235 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1236 &mii_parse_cis8201},
1239 (struct phy_cmd[]){ /* shutdown */
1245 struct phy_info phy_info_cis8201 = {
1249 (struct phy_cmd[]){ /* config */
1250 /* Override PHY config settings */
1251 {MIIM_CIS8201_AUX_CONSTAT,
1252 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1253 /* Set up the interface mode */
1254 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1256 /* Configure some basic stuff */
1257 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1260 (struct phy_cmd[]){ /* startup */
1261 /* Read the Status (2x to make sure link is right) */
1262 {MIIM_STATUS, miim_read, NULL},
1263 /* Auto-negotiate */
1264 {MIIM_STATUS, miim_read, &mii_parse_sr},
1265 /* Read the status */
1266 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1267 &mii_parse_cis8201},
1270 (struct phy_cmd[]){ /* shutdown */
1274 struct phy_info phy_info_VSC8244 = {
1278 (struct phy_cmd[]){ /* config */
1279 /* Override PHY config settings */
1280 /* Configure some basic stuff */
1281 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1284 (struct phy_cmd[]){ /* startup */
1285 /* Read the Status (2x to make sure link is right) */
1286 {MIIM_STATUS, miim_read, NULL},
1287 /* Auto-negotiate */
1288 {MIIM_STATUS, miim_read, &mii_parse_sr},
1289 /* Read the status */
1290 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1291 &mii_parse_vsc8244},
1294 (struct phy_cmd[]){ /* shutdown */
1299 struct phy_info phy_info_VSC8601 = {
1303 (struct phy_cmd[]){ /* config */
1304 /* Override PHY config settings */
1305 /* Configure some basic stuff */
1306 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1307 #ifdef CFG_VSC8601_SKEWFIX
1308 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
1309 #if defined(CFG_VSC8601_SKEW_TX) && defined(CFG_VSC8601_SKEW_RX)
1310 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1311 #define VSC8101_SKEW (CFG_VSC8601_SKEW_TX<<14)|(CFG_VSC8601_SKEW_RX<<12)
1312 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1313 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1318 (struct phy_cmd[]){ /* startup */
1319 /* Read the Status (2x to make sure link is right) */
1320 {MIIM_STATUS, miim_read, NULL},
1321 /* Auto-negotiate */
1322 {MIIM_STATUS, miim_read, &mii_parse_sr},
1323 /* Read the status */
1324 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1325 &mii_parse_vsc8244},
1328 (struct phy_cmd[]){ /* shutdown */
1334 struct phy_info phy_info_dm9161 = {
1338 (struct phy_cmd[]){ /* config */
1339 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1340 /* Do not bypass the scrambler/descrambler */
1341 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1342 /* Clear 10BTCSR to default */
1343 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1345 /* Configure some basic stuff */
1346 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1347 /* Restart Auto Negotiation */
1348 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1351 (struct phy_cmd[]){ /* startup */
1352 /* Status is read once to clear old link state */
1353 {MIIM_STATUS, miim_read, NULL},
1354 /* Auto-negotiate */
1355 {MIIM_STATUS, miim_read, &mii_parse_sr},
1356 /* Read the status */
1357 {MIIM_DM9161_SCSR, miim_read,
1358 &mii_parse_dm9161_scsr},
1361 (struct phy_cmd[]){ /* shutdown */
1365 /* a generic flavor. */
1366 struct phy_info phy_info_generic = {
1368 "Unknown/Generic PHY",
1370 (struct phy_cmd[]) { /* config */
1371 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1372 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1375 (struct phy_cmd[]) { /* startup */
1376 {PHY_BMSR, miim_read, NULL},
1377 {PHY_BMSR, miim_read, &mii_parse_sr},
1378 {PHY_BMSR, miim_read, &mii_parse_link},
1381 (struct phy_cmd[]) { /* shutdown */
1387 uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1391 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
1394 case MIIM_LXT971_SR2_10HDX:
1396 priv->duplexity = 0;
1398 case MIIM_LXT971_SR2_10FDX:
1400 priv->duplexity = 1;
1402 case MIIM_LXT971_SR2_100HDX:
1404 priv->duplexity = 0;
1408 priv->duplexity = 1;
1412 priv->duplexity = 0;
1418 static struct phy_info phy_info_lxt971 = {
1422 (struct phy_cmd[]){ /* config */
1423 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1426 (struct phy_cmd[]){ /* startup - enable interrupts */
1427 /* { 0x12, 0x00f2, NULL }, */
1428 {MIIM_STATUS, miim_read, NULL},
1429 {MIIM_STATUS, miim_read, &mii_parse_sr},
1430 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1433 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1438 /* Parse the DP83865's link and auto-neg status register for speed and duplex
1441 uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1443 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1445 case MIIM_DP83865_SPD_1000:
1449 case MIIM_DP83865_SPD_100:
1459 if (mii_reg & MIIM_DP83865_DPX_FULL)
1460 priv->duplexity = 1;
1462 priv->duplexity = 0;
1467 struct phy_info phy_info_dp83865 = {
1471 (struct phy_cmd[]){ /* config */
1472 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1475 (struct phy_cmd[]){ /* startup */
1476 /* Status is read once to clear old link state */
1477 {MIIM_STATUS, miim_read, NULL},
1478 /* Auto-negotiate */
1479 {MIIM_STATUS, miim_read, &mii_parse_sr},
1480 /* Read the link and auto-neg status */
1481 {MIIM_DP83865_LANR, miim_read,
1482 &mii_parse_dp83865_lanr},
1485 (struct phy_cmd[]){ /* shutdown */
1490 struct phy_info phy_info_rtl8211b = {
1494 (struct phy_cmd[]){ /* config */
1495 /* Reset and configure the PHY */
1496 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1497 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1498 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1499 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1500 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1503 (struct phy_cmd[]){ /* startup */
1504 /* Status is read once to clear old link state */
1505 {MIIM_STATUS, miim_read, NULL},
1506 /* Auto-negotiate */
1507 {MIIM_STATUS, miim_read, &mii_parse_sr},
1508 /* Read the status */
1509 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1512 (struct phy_cmd[]){ /* shutdown */
1517 struct phy_info *phy_info[] = {
1522 &phy_info_M88E1011S,
1523 &phy_info_M88E1111S,
1526 &phy_info_M88E1149S,
1537 /* Grab the identifier of the device's PHY, and search through
1538 * all of the known PHYs to see if one matches. If so, return
1539 * it, if not, return NULL
1541 struct phy_info *get_phy_info(struct eth_device *dev)
1543 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1544 uint phy_reg, phy_ID;
1546 struct phy_info *theInfo = NULL;
1548 /* Grab the bits from PHYIR1, and put them in the upper half */
1549 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1550 phy_ID = (phy_reg & 0xffff) << 16;
1552 /* Grab the bits from PHYIR2, and put them in the lower half */
1553 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1554 phy_ID |= (phy_reg & 0xffff);
1556 /* loop through all the known PHY types, and find one that */
1557 /* matches the ID we read from the PHY. */
1558 for (i = 0; phy_info[i]; i++) {
1559 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
1560 theInfo = phy_info[i];
1565 if (theInfo == NULL) {
1566 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1569 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
1575 /* Execute the given series of commands on the given device's
1576 * PHY, running functions as necessary
1578 void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1582 volatile tsec_t *phyregs = priv->phyregs;
1584 phyregs->miimcfg = MIIMCFG_RESET;
1586 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1588 while (phyregs->miimind & MIIMIND_BUSY) ;
1590 for (i = 0; cmd->mii_reg != miim_end; i++) {
1591 if (cmd->mii_data == miim_read) {
1592 result = read_phy_reg(priv, cmd->mii_reg);
1594 if (cmd->funct != NULL)
1595 (*(cmd->funct)) (result, priv);
1598 if (cmd->funct != NULL)
1599 result = (*(cmd->funct)) (cmd->mii_reg, priv);
1601 result = cmd->mii_data;
1603 write_phy_reg(priv, cmd->mii_reg, result);
1610 /* Relocate the function pointers in the phy cmd lists */
1611 static void relocate_cmds(void)
1613 struct phy_cmd **cmdlistptr;
1614 struct phy_cmd *cmd;
1617 for (i = 0; phy_info[i]; i++) {
1618 /* First thing's first: relocate the pointers to the
1619 * PHY command structures (the structs were done) */
1620 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1622 phy_info[i]->name += gd->reloc_off;
1623 phy_info[i]->config =
1624 (struct phy_cmd *)((uint) phy_info[i]->config
1626 phy_info[i]->startup =
1627 (struct phy_cmd *)((uint) phy_info[i]->startup
1629 phy_info[i]->shutdown =
1630 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1633 cmdlistptr = &phy_info[i]->config;
1635 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1637 for (cmd = *cmdlistptr;
1638 cmd->mii_reg != miim_end;
1640 /* Only relocate non-NULL pointers */
1642 cmd->funct += gd->reloc_off;
1653 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
1654 && !defined(BITBANGMII)
1657 * Read a MII PHY register.
1662 static int tsec_miiphy_read(char *devname, unsigned char addr,
1663 unsigned char reg, unsigned short *value)
1666 struct tsec_private *priv = privlist[0];
1669 printf("Can't read PHY at address %d\n", addr);
1673 ret = (unsigned short)read_any_phy_reg(priv, addr, reg);
1680 * Write a MII PHY register.
1685 static int tsec_miiphy_write(char *devname, unsigned char addr,
1686 unsigned char reg, unsigned short value)
1688 struct tsec_private *priv = privlist[0];
1691 printf("Can't write PHY at address %d\n", addr);
1695 write_any_phy_reg(priv, addr, reg, value);
1702 #ifdef CONFIG_MCAST_TFTP
1704 /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1706 /* Set the appropriate hash bit for the given addr */
1708 /* The algorithm works like so:
1709 * 1) Take the Destination Address (ie the multicast address), and
1710 * do a CRC on it (little endian), and reverse the bits of the
1712 * 2) Use the 8 most significant bits as a hash into a 256-entry
1713 * table. The table is controlled through 8 32-bit registers:
1714 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1715 * gaddr7. This means that the 3 most significant bits in the
1716 * hash index which gaddr register to use, and the 5 other bits
1717 * indicate which bit (assuming an IBM numbering scheme, which
1718 * for PowerPC (tm) is usually the case) in the tregister holds
1721 tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1723 struct tsec_private *priv = privlist[1];
1724 volatile tsec_t *regs = priv->regs;
1725 volatile u32 *reg_array, value;
1726 u8 result, whichbit, whichreg;
1728 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1729 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1730 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1731 value = (1 << (31-whichbit));
1733 reg_array = &(regs->hash.gaddr0);
1736 reg_array[whichreg] |= value;
1738 reg_array[whichreg] &= ~value;
1742 #endif /* Multicast TFTP ? */