blob: 59d41e9ce681f81ea4ec53b80ec89c46029cbbc5 [file] [log] [blame]
wdenk9c53f402003-10-15 23:53:47 +00001/*
wdenka445ddf2004-06-09 00:34:46 +00002 * Freescale Three Speed Ethernet Controller driver
wdenk9c53f402003-10-15 23:53:47 +00003 *
4 * This software may be used and distributed according to the
5 * terms of the GNU Public License, Version 2, incorporated
6 * herein by reference.
7 *
Andy Fleming2fffa052007-04-23 02:24:28 -05008 * Copyright 2004, 2007 Freescale Semiconductor, Inc.
wdenk9c53f402003-10-15 23:53:47 +00009 * (C) Copyright 2003, Motorola, Inc.
wdenk9c53f402003-10-15 23:53:47 +000010 * author Andy Fleming
11 *
12 */
13
14#include <config.h>
wdenk9c53f402003-10-15 23:53:47 +000015#include <common.h>
16#include <malloc.h>
17#include <net.h>
18#include <command.h>
Andy Flemingc067fc12008-08-31 16:33:25 -050019#include <tsec.h>
wdenk9c53f402003-10-15 23:53:47 +000020
Marian Balakowiczaab8c492005-10-28 22:30:33 +020021#include "miiphy.h"
wdenk9c53f402003-10-15 23:53:47 +000022
Wolfgang Denk6405a152006-03-31 18:32:53 +020023DECLARE_GLOBAL_DATA_PTR;
24
Marian Balakowiczaab8c492005-10-28 22:30:33 +020025#define TX_BUF_CNT 2
wdenk9c53f402003-10-15 23:53:47 +000026
Jon Loeligerb7ced082006-10-10 17:03:43 -050027static uint rxIdx; /* index of the current RX buffer */
28static uint txIdx; /* index of the current TX buffer */
wdenk9c53f402003-10-15 23:53:47 +000029
30typedef volatile struct rtxbd {
31 txbd8_t txbd[TX_BUF_CNT];
32 rxbd8_t rxbd[PKTBUFSRX];
Jon Loeligerb7ced082006-10-10 17:03:43 -050033} RTXBD;
wdenk9c53f402003-10-15 23:53:47 +000034
wdenka445ddf2004-06-09 00:34:46 +000035/* The tsec_info structure contains 3 values which the
36 * driver uses to determine how to operate a given ethernet
Andy Fleming239e75f2006-09-13 10:34:18 -050037 * device. The information needed is:
wdenka445ddf2004-06-09 00:34:46 +000038 * phyaddr - The address of the PHY which is attached to
wdenkbfad55d2005-03-14 23:56:42 +000039 * the given device.
wdenka445ddf2004-06-09 00:34:46 +000040 *
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050041 * flags - This variable indicates whether the device
42 * supports gigabit speed ethernet, and whether it should be
43 * in reduced mode.
wdenka445ddf2004-06-09 00:34:46 +000044 *
45 * phyregidx - This variable specifies which ethernet device
wdenkbfad55d2005-03-14 23:56:42 +000046 * controls the MII Management registers which are connected
Andy Fleming239e75f2006-09-13 10:34:18 -050047 * to the PHY. For now, only TSEC1 (index 0) has
wdenkbfad55d2005-03-14 23:56:42 +000048 * access to the PHYs, so all of the entries have "0".
wdenka445ddf2004-06-09 00:34:46 +000049 *
50 * The values specified in the table are taken from the board's
51 * config file in include/configs/. When implementing a new
52 * board with ethernet capability, it is necessary to define:
Andy Fleming239e75f2006-09-13 10:34:18 -050053 * TSECn_PHY_ADDR
54 * TSECn_PHYIDX
wdenka445ddf2004-06-09 00:34:46 +000055 *
Andy Fleming239e75f2006-09-13 10:34:18 -050056 * for n = 1,2,3, etc. And for FEC:
wdenka445ddf2004-06-09 00:34:46 +000057 * FEC_PHY_ADDR
58 * FEC_PHYIDX
59 */
60static struct tsec_info_struct tsec_info[] = {
Andy Fleming09b88df2007-08-15 20:03:25 -050061#ifdef CONFIG_TSEC1
62 {TSEC1_PHY_ADDR, TSEC1_FLAGS, TSEC1_PHYIDX},
Zach Sadeckif5dd2992007-07-31 12:27:25 -050063#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050064 {0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000065#endif
Andy Fleming09b88df2007-08-15 20:03:25 -050066#ifdef CONFIG_TSEC2
67 {TSEC2_PHY_ADDR, TSEC2_FLAGS, TSEC2_PHYIDX},
Zach Sadeckif5dd2992007-07-31 12:27:25 -050068#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050069 {0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000070#endif
71#ifdef CONFIG_MPC85XX_FEC
Andy Fleming09b88df2007-08-15 20:03:25 -050072 {FEC_PHY_ADDR, FEC_FLAGS, FEC_PHYIDX},
wdenkbfad55d2005-03-14 23:56:42 +000073#else
Andy Fleming09b88df2007-08-15 20:03:25 -050074#ifdef CONFIG_TSEC3
75 {TSEC3_PHY_ADDR, TSEC3_FLAGS, TSEC3_PHYIDX},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050076#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050077 {0, 0, 0},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050078#endif
Andy Fleming09b88df2007-08-15 20:03:25 -050079#ifdef CONFIG_TSEC4
80 {TSEC4_PHY_ADDR, TSEC4_FLAGS, TSEC4_PHYIDX},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050081#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050082 {0, 0, 0},
Andy Fleming09b88df2007-08-15 20:03:25 -050083#endif /* CONFIG_TSEC4 */
84#endif /* CONFIG_MPC85XX_FEC */
wdenka445ddf2004-06-09 00:34:46 +000085};
86
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050087#define MAXCONTROLLERS (4)
wdenka445ddf2004-06-09 00:34:46 +000088
89static int relocated = 0;
90
91static struct tsec_private *privlist[MAXCONTROLLERS];
92
wdenk9c53f402003-10-15 23:53:47 +000093#ifdef __GNUC__
94static RTXBD rtx __attribute__ ((aligned(8)));
95#else
96#error "rtx must be 64-bit aligned"
97#endif
98
Jon Loeligerb7ced082006-10-10 17:03:43 -050099static int tsec_send(struct eth_device *dev,
100 volatile void *packet, int length);
101static int tsec_recv(struct eth_device *dev);
102static int tsec_init(struct eth_device *dev, bd_t * bd);
103static void tsec_halt(struct eth_device *dev);
104static void init_registers(volatile tsec_t * regs);
wdenka445ddf2004-06-09 00:34:46 +0000105static void startup_tsec(struct eth_device *dev);
106static int init_phy(struct eth_device *dev);
107void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
108uint read_phy_reg(struct tsec_private *priv, uint regnum);
Jon Loeligerb7ced082006-10-10 17:03:43 -0500109struct phy_info *get_phy_info(struct eth_device *dev);
wdenka445ddf2004-06-09 00:34:46 +0000110void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
111static void adjust_link(struct eth_device *dev);
112static void relocate_cmds(void);
Wolfgang Denk92254112007-11-18 16:36:27 +0100113#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
114 && !defined(BITBANGMII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200115static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500116 unsigned char reg, unsigned short value);
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200117static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500118 unsigned char reg, unsigned short *value);
Wolfgang Denk92254112007-11-18 16:36:27 +0100119#endif
David Updegraff7280da72007-06-11 10:41:07 -0500120#ifdef CONFIG_MCAST_TFTP
121static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
122#endif
wdenk78924a72004-04-18 21:45:42 +0000123
wdenka445ddf2004-06-09 00:34:46 +0000124/* Initialize device structure. Returns success if PHY
125 * initialization succeeded (i.e. if it recognizes the PHY)
126 */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500127int tsec_initialize(bd_t * bis, int index, char *devname)
wdenk9c53f402003-10-15 23:53:47 +0000128{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500129 struct eth_device *dev;
wdenk9c53f402003-10-15 23:53:47 +0000130 int i;
wdenka445ddf2004-06-09 00:34:46 +0000131 struct tsec_private *priv;
wdenk9c53f402003-10-15 23:53:47 +0000132
Jon Loeligerb7ced082006-10-10 17:03:43 -0500133 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk9c53f402003-10-15 23:53:47 +0000134
Jon Loeligerb7ced082006-10-10 17:03:43 -0500135 if (NULL == dev)
wdenk9c53f402003-10-15 23:53:47 +0000136 return 0;
137
138 memset(dev, 0, sizeof *dev);
139
Jon Loeligerb7ced082006-10-10 17:03:43 -0500140 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenka445ddf2004-06-09 00:34:46 +0000141
Jon Loeligerb7ced082006-10-10 17:03:43 -0500142 if (NULL == priv)
wdenka445ddf2004-06-09 00:34:46 +0000143 return 0;
144
145 privlist[index] = priv;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500146 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE);
wdenka445ddf2004-06-09 00:34:46 +0000147 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
Jon Loeligerb7ced082006-10-10 17:03:43 -0500148 tsec_info[index].phyregidx *
149 TSEC_SIZE);
wdenka445ddf2004-06-09 00:34:46 +0000150
151 priv->phyaddr = tsec_info[index].phyaddr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500152 priv->flags = tsec_info[index].flags;
wdenka445ddf2004-06-09 00:34:46 +0000153
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500154 sprintf(dev->name, devname);
wdenk9c53f402003-10-15 23:53:47 +0000155 dev->iobase = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500156 dev->priv = priv;
157 dev->init = tsec_init;
158 dev->halt = tsec_halt;
159 dev->send = tsec_send;
160 dev->recv = tsec_recv;
David Updegraff7280da72007-06-11 10:41:07 -0500161#ifdef CONFIG_MCAST_TFTP
162 dev->mcast = tsec_mcast_addr;
163#endif
wdenk9c53f402003-10-15 23:53:47 +0000164
165 /* Tell u-boot to get the addr from the env */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500166 for (i = 0; i < 6; i++)
wdenk9c53f402003-10-15 23:53:47 +0000167 dev->enetaddr[i] = 0;
168
169 eth_register(dev);
170
wdenka445ddf2004-06-09 00:34:46 +0000171 /* Reset the MAC */
172 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
173 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk78924a72004-04-18 21:45:42 +0000174
Jon Loeliger82ecaad2007-07-09 17:39:42 -0500175#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200176 && !defined(BITBANGMII)
177 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
178#endif
179
wdenka445ddf2004-06-09 00:34:46 +0000180 /* Try to initialize PHY here, and return */
181 return init_phy(dev);
wdenk9c53f402003-10-15 23:53:47 +0000182}
183
wdenk9c53f402003-10-15 23:53:47 +0000184/* Initializes data structures and registers for the controller,
wdenkbfad55d2005-03-14 23:56:42 +0000185 * and brings the interface up. Returns the link status, meaning
wdenka445ddf2004-06-09 00:34:46 +0000186 * that it returns success if the link is up, failure otherwise.
Jon Loeligerb7ced082006-10-10 17:03:43 -0500187 * This allows u-boot to find the first active controller.
188 */
189int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk9c53f402003-10-15 23:53:47 +0000190{
wdenk9c53f402003-10-15 23:53:47 +0000191 uint tempval;
192 char tmpbuf[MAC_ADDR_LEN];
193 int i;
wdenka445ddf2004-06-09 00:34:46 +0000194 struct tsec_private *priv = (struct tsec_private *)dev->priv;
195 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000196
197 /* Make sure the controller is stopped */
198 tsec_halt(dev);
199
wdenka445ddf2004-06-09 00:34:46 +0000200 /* Init MACCFG2. Defaults to GMII */
wdenk9c53f402003-10-15 23:53:47 +0000201 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
202
203 /* Init ECNTRL */
204 regs->ecntrl = ECNTRL_INIT_SETTINGS;
205
206 /* Copy the station address into the address registers.
207 * Backwards, because little endian MACS are dumb */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500208 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenka445ddf2004-06-09 00:34:46 +0000209 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk9c53f402003-10-15 23:53:47 +0000210 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500211 regs->macstnaddr1 = *((uint *) (tmpbuf));
wdenk9c53f402003-10-15 23:53:47 +0000212
Jon Loeligerb7ced082006-10-10 17:03:43 -0500213 tempval = *((uint *) (tmpbuf + 4));
wdenk9c53f402003-10-15 23:53:47 +0000214
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200215 regs->macstnaddr2 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000216
wdenk9c53f402003-10-15 23:53:47 +0000217 /* reset the indices to zero */
218 rxIdx = 0;
219 txIdx = 0;
220
221 /* Clear out (for the most part) the other registers */
222 init_registers(regs);
223
224 /* Ready the device for tx/rx */
wdenka445ddf2004-06-09 00:34:46 +0000225 startup_tsec(dev);
wdenk9c53f402003-10-15 23:53:47 +0000226
wdenka445ddf2004-06-09 00:34:46 +0000227 /* If there's no link, fail */
Ben Warrende9fcb52008-01-09 18:15:53 -0500228 return (priv->link ? 0 : -1);
wdenka445ddf2004-06-09 00:34:46 +0000229
230}
wdenk9c53f402003-10-15 23:53:47 +0000231
wdenka445ddf2004-06-09 00:34:46 +0000232/* Write value to the device's PHY through the registers
233 * specified in priv, modifying the register specified in regnum.
234 * It will wait for the write to be done (or for a timeout to
235 * expire) before exiting
236 */
michael.firth@bt.com08384842008-01-16 11:40:51 +0000237void write_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum, uint value)
wdenka445ddf2004-06-09 00:34:46 +0000238{
239 volatile tsec_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500240 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000241
242 regbase->miimadd = (phyid << 8) | regnum;
243 regbase->miimcon = value;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500244 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000245
Jon Loeligerb7ced082006-10-10 17:03:43 -0500246 timeout = 1000000;
247 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000248}
249
michael.firth@bt.com08384842008-01-16 11:40:51 +0000250/* #define to provide old write_phy_reg functionality without duplicating code */
251#define write_phy_reg(priv, regnum, value) write_any_phy_reg(priv,priv->phyaddr,regnum,value)
252
wdenka445ddf2004-06-09 00:34:46 +0000253/* Reads register regnum on the device's PHY through the
wdenkbfad55d2005-03-14 23:56:42 +0000254 * registers specified in priv. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +0000255 * command, and waits for the data to become valid (miimind
256 * notvalid bit cleared), and the bus to cease activity (miimind
257 * busy bit cleared), and then returns the value
258 */
michael.firth@bt.com08384842008-01-16 11:40:51 +0000259uint read_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +0000260{
261 uint value;
wdenka445ddf2004-06-09 00:34:46 +0000262 volatile tsec_t *regbase = priv->phyregs;
wdenk9c53f402003-10-15 23:53:47 +0000263
wdenka445ddf2004-06-09 00:34:46 +0000264 /* Put the address of the phy, and the register
265 * number into MIIMADD */
266 regbase->miimadd = (phyid << 8) | regnum;
wdenk9c53f402003-10-15 23:53:47 +0000267
268 /* Clear the command register, and wait */
269 regbase->miimcom = 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500270 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000271
272 /* Initiate a read command, and wait */
273 regbase->miimcom = MIIM_READ_COMMAND;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500274 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000275
276 /* Wait for the the indication that the read is done */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500277 while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk9c53f402003-10-15 23:53:47 +0000278
279 /* Grab the value read from the PHY */
280 value = regbase->miimstat;
281
282 return value;
283}
284
michael.firth@bt.com08384842008-01-16 11:40:51 +0000285/* #define to provide old read_phy_reg functionality without duplicating code */
286#define read_phy_reg(priv,regnum) read_any_phy_reg(priv,priv->phyaddr,regnum)
287
wdenka445ddf2004-06-09 00:34:46 +0000288/* Discover which PHY is attached to the device, and configure it
289 * properly. If the PHY is not recognized, then return 0
290 * (failure). Otherwise, return 1
291 */
292static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000293{
wdenka445ddf2004-06-09 00:34:46 +0000294 struct tsec_private *priv = (struct tsec_private *)dev->priv;
295 struct phy_info *curphy;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500296 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000297
298 /* Assign a Physical address to the TBI */
Joe Hamman4290d4c2007-08-09 09:08:18 -0500299 regs->tbipa = CFG_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500300 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
Joe Hamman4290d4c2007-08-09 09:08:18 -0500301 regs->tbipa = CFG_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500302 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000303
304 /* Reset MII (due to new addresses) */
305 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500306 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000307 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500308 asm("sync");
Jon Loeligerb7ced082006-10-10 17:03:43 -0500309 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk9c53f402003-10-15 23:53:47 +0000310
Jon Loeligerb7ced082006-10-10 17:03:43 -0500311 if (0 == relocated)
wdenka445ddf2004-06-09 00:34:46 +0000312 relocate_cmds();
wdenk9c53f402003-10-15 23:53:47 +0000313
wdenka445ddf2004-06-09 00:34:46 +0000314 /* Get the cmd structure corresponding to the attached
315 * PHY */
316 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000317
Ben Warrenf11eefb2006-10-26 14:38:25 -0400318 if (curphy == NULL) {
319 priv->phyinfo = NULL;
wdenka445ddf2004-06-09 00:34:46 +0000320 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000321
wdenka445ddf2004-06-09 00:34:46 +0000322 return 0;
323 }
wdenk9c53f402003-10-15 23:53:47 +0000324
wdenka445ddf2004-06-09 00:34:46 +0000325 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000326
wdenka445ddf2004-06-09 00:34:46 +0000327 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000328
wdenka445ddf2004-06-09 00:34:46 +0000329 return 1;
330}
wdenk9c53f402003-10-15 23:53:47 +0000331
Jon Loeligerb7ced082006-10-10 17:03:43 -0500332/*
333 * Returns which value to write to the control register.
334 * For 10/100, the value is slightly different
335 */
336uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000337{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500338 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000339 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000340 else
wdenka445ddf2004-06-09 00:34:46 +0000341 return MIIM_CR_INIT;
342}
wdenk9c53f402003-10-15 23:53:47 +0000343
wdenka445ddf2004-06-09 00:34:46 +0000344/* Parse the status register for link, and then do
Jon Loeligerb7ced082006-10-10 17:03:43 -0500345 * auto-negotiation
346 */
347uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000348{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200349 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500350 * Wait if the link is up, and autonegotiation is in progress
351 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200352 */
353 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500354 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500355 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200356 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000357
Jon Loeligerb7ced082006-10-10 17:03:43 -0500358 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500359 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200360 /*
361 * Timeout reached ?
362 */
363 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500364 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200365 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800366 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200367 }
wdenk9c53f402003-10-15 23:53:47 +0000368
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200369 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500370 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200371 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500372 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000373 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200374 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500375 puts(" done\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200376 priv->link = 1;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500377 udelay(500000); /* another 500 ms (results in faster booting) */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200378 } else {
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500379 if (mii_reg & MIIM_STATUS_LINK)
380 priv->link = 1;
381 else
382 priv->link = 0;
wdenk9c53f402003-10-15 23:53:47 +0000383 }
384
wdenka445ddf2004-06-09 00:34:46 +0000385 return 0;
386}
387
David Updegraff0451b012007-04-20 14:34:48 -0500388/* Generic function which updates the speed and duplex. If
389 * autonegotiation is enabled, it uses the AND of the link
390 * partner's advertised capabilities and our advertised
391 * capabilities. If autonegotiation is disabled, we use the
392 * appropriate bits in the control register.
393 *
394 * Stolen from Linux's mii.c and phy_device.c
395 */
396uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
397{
398 /* We're using autonegotiation */
399 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
400 uint lpa = 0;
401 uint gblpa = 0;
402
403 /* Check for gigabit capability */
404 if (mii_reg & PHY_BMSR_EXT) {
405 /* We want a list of states supported by
406 * both PHYs in the link
407 */
408 gblpa = read_phy_reg(priv, PHY_1000BTSR);
409 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
410 }
411
412 /* Set the baseline so we only have to set them
413 * if they're different
414 */
415 priv->speed = 10;
416 priv->duplexity = 0;
417
418 /* Check the gigabit fields */
419 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
420 priv->speed = 1000;
421
422 if (gblpa & PHY_1000BTSR_1000FD)
423 priv->duplexity = 1;
424
425 /* We're done! */
426 return 0;
427 }
428
429 lpa = read_phy_reg(priv, PHY_ANAR);
430 lpa &= read_phy_reg(priv, PHY_ANLPAR);
431
432 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
433 priv->speed = 100;
434
435 if (lpa & PHY_ANLPAR_TXFD)
436 priv->duplexity = 1;
437
438 } else if (lpa & PHY_ANLPAR_10FD)
439 priv->duplexity = 1;
440 } else {
441 uint bmcr = read_phy_reg(priv, PHY_BMCR);
442
443 priv->speed = 10;
444 priv->duplexity = 0;
445
446 if (bmcr & PHY_BMCR_DPLX)
447 priv->duplexity = 1;
448
449 if (bmcr & PHY_BMCR_1000_MBPS)
450 priv->speed = 1000;
451 else if (bmcr & PHY_BMCR_100_MBPS)
452 priv->speed = 100;
453 }
454
455 return 0;
456}
457
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500458/*
459 * Parse the BCM54xx status register for speed and duplex information.
460 * The linux sungem_phy has this information, but in a table format.
461 */
462uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
463{
464
465 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
466
467 case 1:
468 printf("Enet starting in 10BT/HD\n");
469 priv->duplexity = 0;
470 priv->speed = 10;
471 break;
472
473 case 2:
474 printf("Enet starting in 10BT/FD\n");
475 priv->duplexity = 1;
476 priv->speed = 10;
477 break;
478
479 case 3:
480 printf("Enet starting in 100BT/HD\n");
481 priv->duplexity = 0;
482 priv->speed = 100;
483 break;
484
485 case 5:
486 printf("Enet starting in 100BT/FD\n");
487 priv->duplexity = 1;
488 priv->speed = 100;
489 break;
490
491 case 6:
492 printf("Enet starting in 1000BT/HD\n");
493 priv->duplexity = 0;
494 priv->speed = 1000;
495 break;
496
497 case 7:
498 printf("Enet starting in 1000BT/FD\n");
499 priv->duplexity = 1;
500 priv->speed = 1000;
501 break;
502
503 default:
504 printf("Auto-neg error, defaulting to 10BT/HD\n");
505 priv->duplexity = 0;
506 priv->speed = 10;
507 break;
508 }
509
510 return 0;
511
512}
wdenka445ddf2004-06-09 00:34:46 +0000513/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500514 * information
515 */
516uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000517{
518 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000519
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200520 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
521
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500522 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
523 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200524 int i = 0;
525
Jon Loeligerb7ced082006-10-10 17:03:43 -0500526 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500527 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
528 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200529 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500530 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200531 priv->link = 0;
532 break;
533 }
534
535 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500536 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200537 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500538 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200539 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
540 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500541 puts(" done\n");
542 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500543 } else {
544 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
545 priv->link = 1;
546 else
547 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200548 }
549
Jon Loeligerb7ced082006-10-10 17:03:43 -0500550 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000551 priv->duplexity = 1;
552 else
553 priv->duplexity = 0;
554
Jon Loeligerb7ced082006-10-10 17:03:43 -0500555 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000556
Jon Loeligerb7ced082006-10-10 17:03:43 -0500557 switch (speed) {
558 case MIIM_88E1011_PHYSTAT_GBIT:
559 priv->speed = 1000;
560 break;
561 case MIIM_88E1011_PHYSTAT_100:
562 priv->speed = 100;
563 break;
564 default:
565 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000566 }
567
wdenka445ddf2004-06-09 00:34:46 +0000568 return 0;
569}
570
Dave Liua304a282008-01-11 18:45:28 +0800571/* Parse the RTL8211B's status register for speed and duplex
572 * information
573 */
574uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
575{
576 uint speed;
577
578 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300579 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800580 int i = 0;
581
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300582 /* in case of timeout ->link is cleared */
583 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800584 puts("Waiting for PHY realtime link");
585 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
586 /* Timeout reached ? */
587 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
588 puts(" TIMEOUT !\n");
589 priv->link = 0;
590 break;
591 }
592
593 if ((i++ % 1000) == 0) {
594 putc('.');
595 }
596 udelay(1000); /* 1 ms */
597 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
598 }
599 puts(" done\n");
600 udelay(500000); /* another 500 ms (results in faster booting) */
601 } else {
602 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
603 priv->link = 1;
604 else
605 priv->link = 0;
606 }
607
608 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
609 priv->duplexity = 1;
610 else
611 priv->duplexity = 0;
612
613 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
614
615 switch (speed) {
616 case MIIM_RTL8211B_PHYSTAT_GBIT:
617 priv->speed = 1000;
618 break;
619 case MIIM_RTL8211B_PHYSTAT_100:
620 priv->speed = 100;
621 break;
622 default:
623 priv->speed = 10;
624 }
625
626 return 0;
627}
628
wdenka445ddf2004-06-09 00:34:46 +0000629/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500630 * information
631 */
632uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000633{
634 uint speed;
635
Jon Loeligerb7ced082006-10-10 17:03:43 -0500636 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000637 priv->duplexity = 1;
638 else
639 priv->duplexity = 0;
640
641 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500642 switch (speed) {
643 case MIIM_CIS8201_AUXCONSTAT_GBIT:
644 priv->speed = 1000;
645 break;
646 case MIIM_CIS8201_AUXCONSTAT_100:
647 priv->speed = 100;
648 break;
649 default:
650 priv->speed = 10;
651 break;
wdenk9c53f402003-10-15 23:53:47 +0000652 }
653
wdenka445ddf2004-06-09 00:34:46 +0000654 return 0;
655}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500656
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500657/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500658 * information
659 */
660uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500661{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500662 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000663
Jon Loeligerb7ced082006-10-10 17:03:43 -0500664 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
665 priv->duplexity = 1;
666 else
667 priv->duplexity = 0;
668
669 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
670 switch (speed) {
671 case MIIM_VSC8244_AUXCONSTAT_GBIT:
672 priv->speed = 1000;
673 break;
674 case MIIM_VSC8244_AUXCONSTAT_100:
675 priv->speed = 100;
676 break;
677 default:
678 priv->speed = 10;
679 break;
680 }
681
682 return 0;
683}
wdenka445ddf2004-06-09 00:34:46 +0000684
685/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500686 * information
687 */
688uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000689{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500690 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000691 priv->speed = 100;
692 else
693 priv->speed = 10;
694
Jon Loeligerb7ced082006-10-10 17:03:43 -0500695 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000696 priv->duplexity = 1;
697 else
698 priv->duplexity = 0;
699
700 return 0;
701}
702
Jon Loeligerb7ced082006-10-10 17:03:43 -0500703/*
704 * Hack to write all 4 PHYs with the LED values
705 */
706uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000707{
708 uint phyid;
709 volatile tsec_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500710 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000711
Jon Loeligerb7ced082006-10-10 17:03:43 -0500712 for (phyid = 0; phyid < 4; phyid++) {
wdenka445ddf2004-06-09 00:34:46 +0000713 regbase->miimadd = (phyid << 8) | mii_reg;
714 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500715 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000716
Jon Loeligerb7ced082006-10-10 17:03:43 -0500717 timeout = 1000000;
718 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000719 }
wdenk9c53f402003-10-15 23:53:47 +0000720
wdenka445ddf2004-06-09 00:34:46 +0000721 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000722}
723
Jon Loeligerb7ced082006-10-10 17:03:43 -0500724uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500725{
726 if (priv->flags & TSEC_REDUCED)
727 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
728 else
729 return MIIM_CIS8204_EPHYCON_INIT;
730}
wdenk9c53f402003-10-15 23:53:47 +0000731
Dave Liub19ecd32007-09-18 12:37:57 +0800732uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
733{
734 uint mii_data = read_phy_reg(priv, mii_reg);
735
736 if (priv->flags & TSEC_REDUCED)
737 mii_data = (mii_data & 0xfff0) | 0x000b;
738 return mii_data;
739}
740
wdenka445ddf2004-06-09 00:34:46 +0000741/* Initialized required registers to appropriate values, zeroing
742 * those we don't care about (unless zero is bad, in which case,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500743 * choose a more appropriate value)
744 */
745static void init_registers(volatile tsec_t * regs)
wdenk9c53f402003-10-15 23:53:47 +0000746{
747 /* Clear IEVENT */
748 regs->ievent = IEVENT_INIT_CLEAR;
749
750 regs->imask = IMASK_INIT_CLEAR;
751
752 regs->hash.iaddr0 = 0;
753 regs->hash.iaddr1 = 0;
754 regs->hash.iaddr2 = 0;
755 regs->hash.iaddr3 = 0;
756 regs->hash.iaddr4 = 0;
757 regs->hash.iaddr5 = 0;
758 regs->hash.iaddr6 = 0;
759 regs->hash.iaddr7 = 0;
760
761 regs->hash.gaddr0 = 0;
762 regs->hash.gaddr1 = 0;
763 regs->hash.gaddr2 = 0;
764 regs->hash.gaddr3 = 0;
765 regs->hash.gaddr4 = 0;
766 regs->hash.gaddr5 = 0;
767 regs->hash.gaddr6 = 0;
768 regs->hash.gaddr7 = 0;
769
770 regs->rctrl = 0x00000000;
771
772 /* Init RMON mib registers */
773 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
774
775 regs->rmon.cam1 = 0xffffffff;
776 regs->rmon.cam2 = 0xffffffff;
777
778 regs->mrblr = MRBLR_INIT_SETTINGS;
779
780 regs->minflr = MINFLR_INIT_SETTINGS;
781
782 regs->attr = ATTR_INIT_SETTINGS;
783 regs->attreli = ATTRELI_INIT_SETTINGS;
784
wdenka445ddf2004-06-09 00:34:46 +0000785}
786
wdenka445ddf2004-06-09 00:34:46 +0000787/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500788 * reported by PHY handling code
789 */
wdenka445ddf2004-06-09 00:34:46 +0000790static void adjust_link(struct eth_device *dev)
791{
792 struct tsec_private *priv = (struct tsec_private *)dev->priv;
793 volatile tsec_t *regs = priv->regs;
794
Jon Loeligerb7ced082006-10-10 17:03:43 -0500795 if (priv->link) {
796 if (priv->duplexity != 0)
wdenka445ddf2004-06-09 00:34:46 +0000797 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
798 else
799 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
800
Jon Loeligerb7ced082006-10-10 17:03:43 -0500801 switch (priv->speed) {
802 case 1000:
803 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
804 | MACCFG2_GMII);
805 break;
806 case 100:
807 case 10:
808 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
809 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500810
Nick Spenceec9670b2006-09-07 07:39:46 -0700811 /* Set R100 bit in all modes although
812 * it is only used in RGMII mode
Jon Loeligerb7ced082006-10-10 17:03:43 -0500813 */
Nick Spenceec9670b2006-09-07 07:39:46 -0700814 if (priv->speed == 100)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500815 regs->ecntrl |= ECNTRL_R100;
816 else
817 regs->ecntrl &= ~(ECNTRL_R100);
818 break;
819 default:
820 printf("%s: Speed was bad\n", dev->name);
821 break;
wdenka445ddf2004-06-09 00:34:46 +0000822 }
823
824 printf("Speed: %d, %s duplex\n", priv->speed,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500825 (priv->duplexity) ? "full" : "half");
wdenka445ddf2004-06-09 00:34:46 +0000826
827 } else {
828 printf("%s: No link.\n", dev->name);
829 }
wdenk9c53f402003-10-15 23:53:47 +0000830}
831
wdenka445ddf2004-06-09 00:34:46 +0000832/* Set up the buffers and their descriptors, and bring up the
Jon Loeligerb7ced082006-10-10 17:03:43 -0500833 * interface
834 */
wdenka445ddf2004-06-09 00:34:46 +0000835static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000836{
837 int i;
wdenka445ddf2004-06-09 00:34:46 +0000838 struct tsec_private *priv = (struct tsec_private *)dev->priv;
839 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000840
841 /* Point to the buffer descriptors */
842 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
843 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
844
845 /* Initialize the Rx Buffer descriptors */
846 for (i = 0; i < PKTBUFSRX; i++) {
847 rtx.rxbd[i].status = RXBD_EMPTY;
848 rtx.rxbd[i].length = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500849 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk9c53f402003-10-15 23:53:47 +0000850 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500851 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000852
853 /* Initialize the TX Buffer Descriptors */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500854 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000855 rtx.txbd[i].status = 0;
856 rtx.txbd[i].length = 0;
857 rtx.txbd[i].bufPtr = 0;
858 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500859 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000860
wdenka445ddf2004-06-09 00:34:46 +0000861 /* Start up the PHY */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400862 if(priv->phyinfo)
863 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraff0451b012007-04-20 14:34:48 -0500864
wdenka445ddf2004-06-09 00:34:46 +0000865 adjust_link(dev);
866
wdenk9c53f402003-10-15 23:53:47 +0000867 /* Enable Transmit and Receive */
868 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
869
870 /* Tell the DMA it is clear to go */
871 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
872 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilsone3d7d6b2007-10-19 11:33:48 -0500873 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk9c53f402003-10-15 23:53:47 +0000874 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
875}
876
wdenkbfad55d2005-03-14 23:56:42 +0000877/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +0000878 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +0000879 * do the same. Presumably, this would be zero if there were no
Jon Loeligerb7ced082006-10-10 17:03:43 -0500880 * errors
881 */
882static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +0000883{
884 int i;
885 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +0000886 struct tsec_private *priv = (struct tsec_private *)dev->priv;
887 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000888
889 /* Find an empty buffer descriptor */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500890 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000891 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500892 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000893 return result;
894 }
895 }
896
Jon Loeligerb7ced082006-10-10 17:03:43 -0500897 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk9c53f402003-10-15 23:53:47 +0000898 rtx.txbd[txIdx].length = length;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500899 rtx.txbd[txIdx].status |=
900 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk9c53f402003-10-15 23:53:47 +0000901
902 /* Tell the DMA to go */
903 regs->tstat = TSTAT_CLEAR_THALT;
904
905 /* Wait for buffer to be transmitted */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500906 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000907 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500908 debug("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000909 return result;
910 }
911 }
912
913 txIdx = (txIdx + 1) % TX_BUF_CNT;
914 result = rtx.txbd[txIdx].status & TXBD_STATS;
915
916 return result;
917}
918
Jon Loeligerb7ced082006-10-10 17:03:43 -0500919static int tsec_recv(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000920{
921 int length;
wdenka445ddf2004-06-09 00:34:46 +0000922 struct tsec_private *priv = (struct tsec_private *)dev->priv;
923 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000924
Jon Loeligerb7ced082006-10-10 17:03:43 -0500925 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk9c53f402003-10-15 23:53:47 +0000926
927 length = rtx.rxbd[rxIdx].length;
928
929 /* Send the packet up if there were no errors */
930 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
931 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +0000932 } else {
933 printf("Got error %x\n",
Jon Loeligerb7ced082006-10-10 17:03:43 -0500934 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +0000935 }
936
937 rtx.rxbd[rxIdx].length = 0;
938
939 /* Set the wrap bit if this is the last element in the list */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500940 rtx.rxbd[rxIdx].status =
941 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk9c53f402003-10-15 23:53:47 +0000942
943 rxIdx = (rxIdx + 1) % PKTBUFSRX;
944 }
945
Jon Loeligerb7ced082006-10-10 17:03:43 -0500946 if (regs->ievent & IEVENT_BSY) {
wdenk9c53f402003-10-15 23:53:47 +0000947 regs->ievent = IEVENT_BSY;
948 regs->rstat = RSTAT_CLEAR_RHALT;
949 }
950
951 return -1;
952
953}
954
wdenka445ddf2004-06-09 00:34:46 +0000955/* Stop the interface */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500956static void tsec_halt(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000957{
wdenka445ddf2004-06-09 00:34:46 +0000958 struct tsec_private *priv = (struct tsec_private *)dev->priv;
959 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000960
961 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
962 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
963
Jon Loeligerb7ced082006-10-10 17:03:43 -0500964 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk9c53f402003-10-15 23:53:47 +0000965
966 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
967
wdenka445ddf2004-06-09 00:34:46 +0000968 /* Shut down the PHY, as needed */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400969 if(priv->phyinfo)
970 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenka445ddf2004-06-09 00:34:46 +0000971}
972
Andy Flemingbee67002007-08-03 04:05:25 -0500973struct phy_info phy_info_M88E1149S = {
Wolfgang Denk15e87572007-08-06 01:01:49 +0200974 0x1410ca,
975 "Marvell 88E1149S",
976 4,
977 (struct phy_cmd[]){ /* config */
978 /* Reset and configure the PHY */
979 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
980 {0x1d, 0x1f, NULL},
981 {0x1e, 0x200c, NULL},
982 {0x1d, 0x5, NULL},
983 {0x1e, 0x0, NULL},
984 {0x1e, 0x100, NULL},
985 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
986 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
987 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
988 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
989 {miim_end,}
990 },
991 (struct phy_cmd[]){ /* startup */
992 /* Status is read once to clear old link state */
993 {MIIM_STATUS, miim_read, NULL},
994 /* Auto-negotiate */
995 {MIIM_STATUS, miim_read, &mii_parse_sr},
996 /* Read the status */
997 {MIIM_88E1011_PHY_STATUS, miim_read,
998 &mii_parse_88E1011_psr},
999 {miim_end,}
1000 },
1001 (struct phy_cmd[]){ /* shutdown */
1002 {miim_end,}
1003 },
Andy Flemingbee67002007-08-03 04:05:25 -05001004};
1005
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001006/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1007struct phy_info phy_info_BCM5461S = {
1008 0x02060c1, /* 5461 ID */
1009 "Broadcom BCM5461S",
1010 0, /* not clear to me what minor revisions we can shift away */
1011 (struct phy_cmd[]) { /* config */
1012 /* Reset and configure the PHY */
1013 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1014 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1015 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1016 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1017 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1018 {miim_end,}
1019 },
1020 (struct phy_cmd[]) { /* startup */
1021 /* Status is read once to clear old link state */
1022 {MIIM_STATUS, miim_read, NULL},
1023 /* Auto-negotiate */
1024 {MIIM_STATUS, miim_read, &mii_parse_sr},
1025 /* Read the status */
1026 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1027 {miim_end,}
1028 },
1029 (struct phy_cmd[]) { /* shutdown */
1030 {miim_end,}
1031 },
1032};
1033
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001034struct phy_info phy_info_BCM5464S = {
1035 0x02060b1, /* 5464 ID */
1036 "Broadcom BCM5464S",
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},
1045 {miim_end,}
1046 },
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},
1054 {miim_end,}
1055 },
1056 (struct phy_cmd[]) { /* shutdown */
1057 {miim_end,}
1058 },
1059};
1060
wdenka445ddf2004-06-09 00:34:46 +00001061struct phy_info phy_info_M88E1011S = {
1062 0x01410c6,
1063 "Marvell 88E1011S",
1064 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001065 (struct phy_cmd[]){ /* config */
1066 /* Reset and configure the PHY */
1067 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1068 {0x1d, 0x1f, NULL},
1069 {0x1e, 0x200c, NULL},
1070 {0x1d, 0x5, NULL},
1071 {0x1e, 0x0, NULL},
1072 {0x1e, 0x100, NULL},
1073 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1074 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1075 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1076 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1077 {miim_end,}
1078 },
1079 (struct phy_cmd[]){ /* startup */
1080 /* Status is read once to clear old link state */
1081 {MIIM_STATUS, miim_read, NULL},
1082 /* Auto-negotiate */
1083 {MIIM_STATUS, miim_read, &mii_parse_sr},
1084 /* Read the status */
1085 {MIIM_88E1011_PHY_STATUS, miim_read,
1086 &mii_parse_88E1011_psr},
1087 {miim_end,}
1088 },
1089 (struct phy_cmd[]){ /* shutdown */
1090 {miim_end,}
1091 },
wdenka445ddf2004-06-09 00:34:46 +00001092};
1093
wdenkbfad55d2005-03-14 23:56:42 +00001094struct phy_info phy_info_M88E1111S = {
1095 0x01410cc,
1096 "Marvell 88E1111S",
1097 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001098 (struct phy_cmd[]){ /* config */
1099 /* Reset and configure the PHY */
1100 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Dave Liub19ecd32007-09-18 12:37:57 +08001101 {0x1b, 0x848f, &mii_m88e1111s_setmode},
Nick Spenceec9670b2006-09-07 07:39:46 -07001102 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001103 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1104 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1105 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1106 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1107 {miim_end,}
1108 },
1109 (struct phy_cmd[]){ /* startup */
1110 /* Status is read once to clear old link state */
1111 {MIIM_STATUS, miim_read, NULL},
1112 /* Auto-negotiate */
1113 {MIIM_STATUS, miim_read, &mii_parse_sr},
1114 /* Read the status */
1115 {MIIM_88E1011_PHY_STATUS, miim_read,
1116 &mii_parse_88E1011_psr},
1117 {miim_end,}
1118 },
1119 (struct phy_cmd[]){ /* shutdown */
1120 {miim_end,}
1121 },
wdenkbfad55d2005-03-14 23:56:42 +00001122};
1123
Ron Madridc1e2b582008-05-23 15:37:05 -07001124struct phy_info phy_info_M88E1118 = {
1125 0x01410e1,
1126 "Marvell 88E1118",
1127 4,
1128 (struct phy_cmd[]){ /* config */
1129 /* Reset and configure the PHY */
1130 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1131 {0x16, 0x0002, NULL}, /* Change Page Number */
1132 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
1133 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1134 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1135 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1136 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1137 {miim_end,}
1138 },
1139 (struct phy_cmd[]){ /* startup */
1140 {0x16, 0x0000, NULL}, /* Change Page Number */
1141 /* Status is read once to clear old link state */
1142 {MIIM_STATUS, miim_read, NULL},
1143 /* Auto-negotiate */
1144 /* Read the status */
1145 {MIIM_88E1011_PHY_STATUS, miim_read,
1146 &mii_parse_88E1011_psr},
1147 {miim_end,}
1148 },
1149 (struct phy_cmd[]){ /* shutdown */
1150 {miim_end,}
1151 },
1152};
1153
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001154/*
1155 * Since to access LED register we need do switch the page, we
1156 * do LED configuring in the miim_read-like function as follows
1157 */
1158uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1159{
1160 uint pg;
1161
1162 /* Switch the page to access the led register */
1163 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1164 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1165
1166 /* Configure leds */
1167 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1168 MIIM_88E1121_PHY_LED_DEF);
1169
1170 /* Restore the page pointer */
1171 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1172 return 0;
1173}
1174
1175struct phy_info phy_info_M88E1121R = {
1176 0x01410cb,
1177 "Marvell 88E1121R",
1178 4,
1179 (struct phy_cmd[]){ /* config */
1180 /* Reset and configure the PHY */
1181 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1182 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1183 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1184 /* Configure leds */
1185 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1186 &mii_88E1121_set_led},
1187 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1188 {miim_end,}
1189 },
1190 (struct phy_cmd[]){ /* startup */
1191 /* Status is read once to clear old link state */
1192 {MIIM_STATUS, miim_read, NULL},
1193 {MIIM_STATUS, miim_read, &mii_parse_sr},
1194 {MIIM_STATUS, miim_read, &mii_parse_link},
1195 {miim_end,}
1196 },
1197 (struct phy_cmd[]){ /* shutdown */
1198 {miim_end,}
1199 },
1200};
1201
Andy Fleming239e75f2006-09-13 10:34:18 -05001202static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1203{
Andy Fleming239e75f2006-09-13 10:34:18 -05001204 uint mii_data = read_phy_reg(priv, mii_reg);
1205
Andy Fleming239e75f2006-09-13 10:34:18 -05001206 /* Setting MIIM_88E1145_PHY_EXT_CR */
1207 if (priv->flags & TSEC_REDUCED)
1208 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -05001209 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -05001210 else
1211 return mii_data;
1212}
1213
1214static struct phy_info phy_info_M88E1145 = {
1215 0x01410cd,
1216 "Marvell 88E1145",
1217 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001218 (struct phy_cmd[]){ /* config */
Andy Fleming180d03a2007-05-08 17:23:02 -05001219 /* Reset the PHY */
1220 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1221
Jon Loeligerb7ced082006-10-10 17:03:43 -05001222 /* Errata E0, E1 */
1223 {29, 0x001b, NULL},
1224 {30, 0x418f, NULL},
1225 {29, 0x0016, NULL},
1226 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -05001227
Andy Fleming180d03a2007-05-08 17:23:02 -05001228 /* Configure the PHY */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001229 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1230 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1231 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1232 NULL},
1233 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1234 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1235 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1236 {miim_end,}
1237 },
1238 (struct phy_cmd[]){ /* startup */
1239 /* Status is read once to clear old link state */
1240 {MIIM_STATUS, miim_read, NULL},
1241 /* Auto-negotiate */
1242 {MIIM_STATUS, miim_read, &mii_parse_sr},
1243 {MIIM_88E1111_PHY_LED_CONTROL,
1244 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1245 /* Read the Status */
1246 {MIIM_88E1011_PHY_STATUS, miim_read,
1247 &mii_parse_88E1011_psr},
1248 {miim_end,}
1249 },
1250 (struct phy_cmd[]){ /* shutdown */
1251 {miim_end,}
1252 },
Andy Fleming239e75f2006-09-13 10:34:18 -05001253};
1254
wdenka445ddf2004-06-09 00:34:46 +00001255struct phy_info phy_info_cis8204 = {
1256 0x3f11,
1257 "Cicada Cis8204",
1258 6,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001259 (struct phy_cmd[]){ /* config */
1260 /* Override PHY config settings */
1261 {MIIM_CIS8201_AUX_CONSTAT,
1262 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1263 /* Configure some basic stuff */
1264 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1265 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1266 &mii_cis8204_fixled},
1267 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1268 &mii_cis8204_setmode},
1269 {miim_end,}
1270 },
1271 (struct phy_cmd[]){ /* startup */
1272 /* Read the Status (2x to make sure link is right) */
1273 {MIIM_STATUS, miim_read, NULL},
1274 /* Auto-negotiate */
1275 {MIIM_STATUS, miim_read, &mii_parse_sr},
1276 /* Read the status */
1277 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1278 &mii_parse_cis8201},
1279 {miim_end,}
1280 },
1281 (struct phy_cmd[]){ /* shutdown */
1282 {miim_end,}
1283 },
wdenka445ddf2004-06-09 00:34:46 +00001284};
1285
1286/* Cicada 8201 */
1287struct phy_info phy_info_cis8201 = {
1288 0xfc41,
1289 "CIS8201",
1290 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001291 (struct phy_cmd[]){ /* config */
1292 /* Override PHY config settings */
1293 {MIIM_CIS8201_AUX_CONSTAT,
1294 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1295 /* Set up the interface mode */
1296 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1297 NULL},
1298 /* Configure some basic stuff */
1299 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1300 {miim_end,}
1301 },
1302 (struct phy_cmd[]){ /* startup */
1303 /* Read the Status (2x to make sure link is right) */
1304 {MIIM_STATUS, miim_read, NULL},
1305 /* Auto-negotiate */
1306 {MIIM_STATUS, miim_read, &mii_parse_sr},
1307 /* Read the status */
1308 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1309 &mii_parse_cis8201},
1310 {miim_end,}
1311 },
1312 (struct phy_cmd[]){ /* shutdown */
1313 {miim_end,}
1314 },
wdenka445ddf2004-06-09 00:34:46 +00001315};
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001316struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001317 0x3f1b,
1318 "Vitesse VSC8244",
1319 6,
1320 (struct phy_cmd[]){ /* config */
1321 /* Override PHY config settings */
1322 /* Configure some basic stuff */
1323 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1324 {miim_end,}
1325 },
1326 (struct phy_cmd[]){ /* startup */
1327 /* Read the Status (2x to make sure link is right) */
1328 {MIIM_STATUS, miim_read, NULL},
1329 /* Auto-negotiate */
1330 {MIIM_STATUS, miim_read, &mii_parse_sr},
1331 /* Read the status */
1332 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1333 &mii_parse_vsc8244},
1334 {miim_end,}
1335 },
1336 (struct phy_cmd[]){ /* shutdown */
1337 {miim_end,}
1338 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001339};
wdenka445ddf2004-06-09 00:34:46 +00001340
Tor Krill8b3a82f2008-03-28 15:29:45 +01001341struct phy_info phy_info_VSC8601 = {
1342 0x00007042,
1343 "Vitesse VSC8601",
1344 4,
1345 (struct phy_cmd[]){ /* config */
1346 /* Override PHY config settings */
1347 /* Configure some basic stuff */
1348 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1349#ifdef CFG_VSC8601_SKEWFIX
1350 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Wolfgang Denk88390f62008-05-04 00:35:15 +02001351#if defined(CFG_VSC8601_SKEW_TX) && defined(CFG_VSC8601_SKEW_RX)
Andre Schwarz1e18be12008-04-29 19:18:32 +02001352 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1353#define VSC8101_SKEW (CFG_VSC8601_SKEW_TX<<14)|(CFG_VSC8601_SKEW_RX<<12)
1354 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1355 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1356#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001357#endif
1358 {miim_end,}
1359 },
1360 (struct phy_cmd[]){ /* startup */
1361 /* Read the Status (2x to make sure link is right) */
1362 {MIIM_STATUS, miim_read, NULL},
1363 /* Auto-negotiate */
1364 {MIIM_STATUS, miim_read, &mii_parse_sr},
1365 /* Read the status */
1366 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1367 &mii_parse_vsc8244},
1368 {miim_end,}
1369 },
1370 (struct phy_cmd[]){ /* shutdown */
1371 {miim_end,}
1372 },
1373};
1374
1375
wdenka445ddf2004-06-09 00:34:46 +00001376struct phy_info phy_info_dm9161 = {
1377 0x0181b88,
1378 "Davicom DM9161E",
1379 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001380 (struct phy_cmd[]){ /* config */
1381 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1382 /* Do not bypass the scrambler/descrambler */
1383 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1384 /* Clear 10BTCSR to default */
1385 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1386 NULL},
1387 /* Configure some basic stuff */
1388 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1389 /* Restart Auto Negotiation */
1390 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1391 {miim_end,}
1392 },
1393 (struct phy_cmd[]){ /* startup */
1394 /* Status is read once to clear old link state */
1395 {MIIM_STATUS, miim_read, NULL},
1396 /* Auto-negotiate */
1397 {MIIM_STATUS, miim_read, &mii_parse_sr},
1398 /* Read the status */
1399 {MIIM_DM9161_SCSR, miim_read,
1400 &mii_parse_dm9161_scsr},
1401 {miim_end,}
1402 },
1403 (struct phy_cmd[]){ /* shutdown */
1404 {miim_end,}
1405 },
wdenka445ddf2004-06-09 00:34:46 +00001406};
David Updegraff0451b012007-04-20 14:34:48 -05001407/* a generic flavor. */
1408struct phy_info phy_info_generic = {
1409 0,
1410 "Unknown/Generic PHY",
1411 32,
1412 (struct phy_cmd[]) { /* config */
1413 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1414 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1415 {miim_end,}
1416 },
1417 (struct phy_cmd[]) { /* startup */
1418 {PHY_BMSR, miim_read, NULL},
1419 {PHY_BMSR, miim_read, &mii_parse_sr},
1420 {PHY_BMSR, miim_read, &mii_parse_link},
1421 {miim_end,}
1422 },
1423 (struct phy_cmd[]) { /* shutdown */
1424 {miim_end,}
1425 }
1426};
1427
wdenka445ddf2004-06-09 00:34:46 +00001428
wdenkf41ff3b2005-04-04 23:43:44 +00001429uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1430{
wdenke085e5b2005-04-05 23:32:21 +00001431 unsigned int speed;
1432 if (priv->link) {
1433 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001434
wdenke085e5b2005-04-05 23:32:21 +00001435 switch (speed) {
1436 case MIIM_LXT971_SR2_10HDX:
1437 priv->speed = 10;
1438 priv->duplexity = 0;
1439 break;
1440 case MIIM_LXT971_SR2_10FDX:
1441 priv->speed = 10;
1442 priv->duplexity = 1;
1443 break;
1444 case MIIM_LXT971_SR2_100HDX:
1445 priv->speed = 100;
1446 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001447 break;
wdenke085e5b2005-04-05 23:32:21 +00001448 default:
1449 priv->speed = 100;
1450 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001451 }
1452 } else {
1453 priv->speed = 0;
1454 priv->duplexity = 0;
1455 }
wdenkf41ff3b2005-04-04 23:43:44 +00001456
wdenke085e5b2005-04-05 23:32:21 +00001457 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +00001458}
1459
wdenkbfad55d2005-03-14 23:56:42 +00001460static struct phy_info phy_info_lxt971 = {
1461 0x0001378e,
1462 "LXT971",
1463 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001464 (struct phy_cmd[]){ /* config */
1465 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1466 {miim_end,}
1467 },
1468 (struct phy_cmd[]){ /* startup - enable interrupts */
1469 /* { 0x12, 0x00f2, NULL }, */
1470 {MIIM_STATUS, miim_read, NULL},
1471 {MIIM_STATUS, miim_read, &mii_parse_sr},
1472 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1473 {miim_end,}
1474 },
1475 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1476 {miim_end,}
1477 },
wdenkbfad55d2005-03-14 23:56:42 +00001478};
1479
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001480/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -05001481 * information
1482 */
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001483uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1484{
1485 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1486
1487 case MIIM_DP83865_SPD_1000:
1488 priv->speed = 1000;
1489 break;
1490
1491 case MIIM_DP83865_SPD_100:
1492 priv->speed = 100;
1493 break;
1494
1495 default:
1496 priv->speed = 10;
1497 break;
1498
1499 }
1500
1501 if (mii_reg & MIIM_DP83865_DPX_FULL)
1502 priv->duplexity = 1;
1503 else
1504 priv->duplexity = 0;
1505
1506 return 0;
1507}
1508
1509struct phy_info phy_info_dp83865 = {
1510 0x20005c7,
1511 "NatSemi DP83865",
1512 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001513 (struct phy_cmd[]){ /* config */
1514 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1515 {miim_end,}
1516 },
1517 (struct phy_cmd[]){ /* startup */
1518 /* Status is read once to clear old link state */
1519 {MIIM_STATUS, miim_read, NULL},
1520 /* Auto-negotiate */
1521 {MIIM_STATUS, miim_read, &mii_parse_sr},
1522 /* Read the link and auto-neg status */
1523 {MIIM_DP83865_LANR, miim_read,
1524 &mii_parse_dp83865_lanr},
1525 {miim_end,}
1526 },
1527 (struct phy_cmd[]){ /* shutdown */
1528 {miim_end,}
1529 },
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001530};
1531
Dave Liua304a282008-01-11 18:45:28 +08001532struct phy_info phy_info_rtl8211b = {
1533 0x001cc91,
1534 "RealTek RTL8211B",
1535 4,
1536 (struct phy_cmd[]){ /* config */
1537 /* Reset and configure the PHY */
1538 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1539 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1540 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1541 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1542 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1543 {miim_end,}
1544 },
1545 (struct phy_cmd[]){ /* startup */
1546 /* Status is read once to clear old link state */
1547 {MIIM_STATUS, miim_read, NULL},
1548 /* Auto-negotiate */
1549 {MIIM_STATUS, miim_read, &mii_parse_sr},
1550 /* Read the status */
1551 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1552 {miim_end,}
1553 },
1554 (struct phy_cmd[]){ /* shutdown */
1555 {miim_end,}
1556 },
1557};
1558
wdenka445ddf2004-06-09 00:34:46 +00001559struct phy_info *phy_info[] = {
wdenka445ddf2004-06-09 00:34:46 +00001560 &phy_info_cis8204,
Timur Tabi054838e2006-10-31 18:44:42 -06001561 &phy_info_cis8201,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001562 &phy_info_BCM5461S,
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001563 &phy_info_BCM5464S,
wdenka445ddf2004-06-09 00:34:46 +00001564 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +00001565 &phy_info_M88E1111S,
Ron Madridc1e2b582008-05-23 15:37:05 -07001566 &phy_info_M88E1118,
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001567 &phy_info_M88E1121R,
Andy Fleming239e75f2006-09-13 10:34:18 -05001568 &phy_info_M88E1145,
Wolfgang Denk15e87572007-08-06 01:01:49 +02001569 &phy_info_M88E1149S,
wdenka445ddf2004-06-09 00:34:46 +00001570 &phy_info_dm9161,
wdenkbfad55d2005-03-14 23:56:42 +00001571 &phy_info_lxt971,
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001572 &phy_info_VSC8244,
Tor Krill8b3a82f2008-03-28 15:29:45 +01001573 &phy_info_VSC8601,
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001574 &phy_info_dp83865,
Dave Liua304a282008-01-11 18:45:28 +08001575 &phy_info_rtl8211b,
David Updegraff0451b012007-04-20 14:34:48 -05001576 &phy_info_generic,
wdenka445ddf2004-06-09 00:34:46 +00001577 NULL
1578};
1579
wdenka445ddf2004-06-09 00:34:46 +00001580/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +00001581 * all of the known PHYs to see if one matches. If so, return
Jon Loeligerb7ced082006-10-10 17:03:43 -05001582 * it, if not, return NULL
1583 */
1584struct phy_info *get_phy_info(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001585{
1586 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1587 uint phy_reg, phy_ID;
1588 int i;
1589 struct phy_info *theInfo = NULL;
1590
1591 /* Grab the bits from PHYIR1, and put them in the upper half */
1592 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1593 phy_ID = (phy_reg & 0xffff) << 16;
1594
1595 /* Grab the bits from PHYIR2, and put them in the lower half */
1596 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1597 phy_ID |= (phy_reg & 0xffff);
1598
1599 /* loop through all the known PHY types, and find one that */
1600 /* matches the ID we read from the PHY. */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001601 for (i = 0; phy_info[i]; i++) {
Andy Flemingb2d14f42007-05-09 00:54:20 -05001602 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenka445ddf2004-06-09 00:34:46 +00001603 theInfo = phy_info[i];
Andy Flemingb2d14f42007-05-09 00:54:20 -05001604 break;
1605 }
wdenka445ddf2004-06-09 00:34:46 +00001606 }
1607
Jon Loeligerb7ced082006-10-10 17:03:43 -05001608 if (theInfo == NULL) {
wdenka445ddf2004-06-09 00:34:46 +00001609 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1610 return NULL;
1611 } else {
Stefan Roesec0dc34f2005-09-21 18:20:22 +02001612 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001613 }
1614
1615 return theInfo;
1616}
1617
wdenka445ddf2004-06-09 00:34:46 +00001618/* Execute the given series of commands on the given device's
Jon Loeligerb7ced082006-10-10 17:03:43 -05001619 * PHY, running functions as necessary
1620 */
wdenka445ddf2004-06-09 00:34:46 +00001621void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1622{
1623 int i;
1624 uint result;
1625 volatile tsec_t *phyregs = priv->phyregs;
1626
1627 phyregs->miimcfg = MIIMCFG_RESET;
1628
1629 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1630
Jon Loeligerb7ced082006-10-10 17:03:43 -05001631 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenka445ddf2004-06-09 00:34:46 +00001632
Jon Loeligerb7ced082006-10-10 17:03:43 -05001633 for (i = 0; cmd->mii_reg != miim_end; i++) {
1634 if (cmd->mii_data == miim_read) {
wdenka445ddf2004-06-09 00:34:46 +00001635 result = read_phy_reg(priv, cmd->mii_reg);
1636
Jon Loeligerb7ced082006-10-10 17:03:43 -05001637 if (cmd->funct != NULL)
1638 (*(cmd->funct)) (result, priv);
wdenka445ddf2004-06-09 00:34:46 +00001639
1640 } else {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001641 if (cmd->funct != NULL)
1642 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenka445ddf2004-06-09 00:34:46 +00001643 else
1644 result = cmd->mii_data;
1645
1646 write_phy_reg(priv, cmd->mii_reg, result);
1647
1648 }
1649 cmd++;
1650 }
1651}
1652
wdenka445ddf2004-06-09 00:34:46 +00001653/* Relocate the function pointers in the phy cmd lists */
1654static void relocate_cmds(void)
1655{
1656 struct phy_cmd **cmdlistptr;
1657 struct phy_cmd *cmd;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001658 int i, j, k;
wdenka445ddf2004-06-09 00:34:46 +00001659
Jon Loeligerb7ced082006-10-10 17:03:43 -05001660 for (i = 0; phy_info[i]; i++) {
wdenka445ddf2004-06-09 00:34:46 +00001661 /* First thing's first: relocate the pointers to the
1662 * PHY command structures (the structs were done) */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001663 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1664 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001665 phy_info[i]->name += gd->reloc_off;
1666 phy_info[i]->config =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001667 (struct phy_cmd *)((uint) phy_info[i]->config
1668 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001669 phy_info[i]->startup =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001670 (struct phy_cmd *)((uint) phy_info[i]->startup
1671 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001672 phy_info[i]->shutdown =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001673 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1674 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001675
1676 cmdlistptr = &phy_info[i]->config;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001677 j = 0;
1678 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1679 k = 0;
1680 for (cmd = *cmdlistptr;
1681 cmd->mii_reg != miim_end;
1682 cmd++) {
wdenka445ddf2004-06-09 00:34:46 +00001683 /* Only relocate non-NULL pointers */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001684 if (cmd->funct)
wdenka445ddf2004-06-09 00:34:46 +00001685 cmd->funct += gd->reloc_off;
1686
1687 k++;
1688 }
1689 j++;
1690 }
1691 }
1692
1693 relocated = 1;
wdenk78924a72004-04-18 21:45:42 +00001694}
1695
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001696#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001697 && !defined(BITBANGMII)
wdenka445ddf2004-06-09 00:34:46 +00001698
wdenk78924a72004-04-18 21:45:42 +00001699/*
1700 * Read a MII PHY register.
1701 *
1702 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001703 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001704 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001705static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001706 unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001707{
wdenka445ddf2004-06-09 00:34:46 +00001708 unsigned short ret;
michael.firth@bt.com08384842008-01-16 11:40:51 +00001709 struct tsec_private *priv = privlist[0];
wdenk78924a72004-04-18 21:45:42 +00001710
Jon Loeligerb7ced082006-10-10 17:03:43 -05001711 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001712 printf("Can't read PHY at address %d\n", addr);
1713 return -1;
1714 }
1715
michael.firth@bt.com08384842008-01-16 11:40:51 +00001716 ret = (unsigned short)read_any_phy_reg(priv, addr, reg);
wdenka445ddf2004-06-09 00:34:46 +00001717 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001718
1719 return 0;
1720}
1721
1722/*
1723 * Write a MII PHY register.
1724 *
1725 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001726 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001727 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001728static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001729 unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001730{
michael.firth@bt.com08384842008-01-16 11:40:51 +00001731 struct tsec_private *priv = privlist[0];
wdenka445ddf2004-06-09 00:34:46 +00001732
Jon Loeligerb7ced082006-10-10 17:03:43 -05001733 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001734 printf("Can't write PHY at address %d\n", addr);
1735 return -1;
1736 }
wdenk78924a72004-04-18 21:45:42 +00001737
michael.firth@bt.com08384842008-01-16 11:40:51 +00001738 write_any_phy_reg(priv, addr, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001739
1740 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001741}
wdenka445ddf2004-06-09 00:34:46 +00001742
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001743#endif
wdenka445ddf2004-06-09 00:34:46 +00001744
David Updegraff7280da72007-06-11 10:41:07 -05001745#ifdef CONFIG_MCAST_TFTP
1746
1747/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1748
1749/* Set the appropriate hash bit for the given addr */
1750
1751/* The algorithm works like so:
1752 * 1) Take the Destination Address (ie the multicast address), and
1753 * do a CRC on it (little endian), and reverse the bits of the
1754 * result.
1755 * 2) Use the 8 most significant bits as a hash into a 256-entry
1756 * table. The table is controlled through 8 32-bit registers:
1757 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1758 * gaddr7. This means that the 3 most significant bits in the
1759 * hash index which gaddr register to use, and the 5 other bits
1760 * indicate which bit (assuming an IBM numbering scheme, which
1761 * for PowerPC (tm) is usually the case) in the tregister holds
1762 * the entry. */
1763static int
1764tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1765{
1766 struct tsec_private *priv = privlist[1];
1767 volatile tsec_t *regs = priv->regs;
1768 volatile u32 *reg_array, value;
1769 u8 result, whichbit, whichreg;
1770
1771 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1772 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1773 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1774 value = (1 << (31-whichbit));
1775
1776 reg_array = &(regs->hash.gaddr0);
1777
1778 if (set) {
1779 reg_array[whichreg] |= value;
1780 } else {
1781 reg_array[whichreg] &= ~value;
1782 }
1783 return 0;
1784}
1785#endif /* Multicast TFTP ? */