blob: e50d516f5773f919642d3946cd02d4157f738f21 [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>
19
wdenk9c53f402003-10-15 23:53:47 +000020#include "tsec.h"
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 +000035struct tsec_info_struct {
36 unsigned int phyaddr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050037 u32 flags;
wdenka445ddf2004-06-09 00:34:46 +000038 unsigned int phyregidx;
39};
40
wdenka445ddf2004-06-09 00:34:46 +000041/* The tsec_info structure contains 3 values which the
42 * driver uses to determine how to operate a given ethernet
Andy Fleming239e75f2006-09-13 10:34:18 -050043 * device. The information needed is:
wdenka445ddf2004-06-09 00:34:46 +000044 * phyaddr - The address of the PHY which is attached to
wdenkbfad55d2005-03-14 23:56:42 +000045 * the given device.
wdenka445ddf2004-06-09 00:34:46 +000046 *
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050047 * flags - This variable indicates whether the device
48 * supports gigabit speed ethernet, and whether it should be
49 * in reduced mode.
wdenka445ddf2004-06-09 00:34:46 +000050 *
51 * phyregidx - This variable specifies which ethernet device
wdenkbfad55d2005-03-14 23:56:42 +000052 * controls the MII Management registers which are connected
Andy Fleming239e75f2006-09-13 10:34:18 -050053 * to the PHY. For now, only TSEC1 (index 0) has
wdenkbfad55d2005-03-14 23:56:42 +000054 * access to the PHYs, so all of the entries have "0".
wdenka445ddf2004-06-09 00:34:46 +000055 *
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:
Andy Fleming239e75f2006-09-13 10:34:18 -050059 * TSECn_PHY_ADDR
60 * TSECn_PHYIDX
wdenka445ddf2004-06-09 00:34:46 +000061 *
Andy Fleming239e75f2006-09-13 10:34:18 -050062 * for n = 1,2,3, etc. And for FEC:
wdenka445ddf2004-06-09 00:34:46 +000063 * FEC_PHY_ADDR
64 * FEC_PHYIDX
65 */
66static struct tsec_info_struct tsec_info[] = {
Andy Fleming09b88df2007-08-15 20:03:25 -050067#ifdef CONFIG_TSEC1
68 {TSEC1_PHY_ADDR, TSEC1_FLAGS, TSEC1_PHYIDX},
Zach Sadeckif5dd2992007-07-31 12:27:25 -050069#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050070 {0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000071#endif
Andy Fleming09b88df2007-08-15 20:03:25 -050072#ifdef CONFIG_TSEC2
73 {TSEC2_PHY_ADDR, TSEC2_FLAGS, TSEC2_PHYIDX},
Zach Sadeckif5dd2992007-07-31 12:27:25 -050074#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050075 {0, 0, 0},
wdenka445ddf2004-06-09 00:34:46 +000076#endif
77#ifdef CONFIG_MPC85XX_FEC
Andy Fleming09b88df2007-08-15 20:03:25 -050078 {FEC_PHY_ADDR, FEC_FLAGS, FEC_PHYIDX},
wdenkbfad55d2005-03-14 23:56:42 +000079#else
Andy Fleming09b88df2007-08-15 20:03:25 -050080#ifdef CONFIG_TSEC3
81 {TSEC3_PHY_ADDR, TSEC3_FLAGS, TSEC3_PHYIDX},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050082#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050083 {0, 0, 0},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050084#endif
Andy Fleming09b88df2007-08-15 20:03:25 -050085#ifdef CONFIG_TSEC4
86 {TSEC4_PHY_ADDR, TSEC4_FLAGS, TSEC4_PHYIDX},
Jon Loeliger5c8aa972006-04-26 17:58:56 -050087#else
Jon Loeligerb7ced082006-10-10 17:03:43 -050088 {0, 0, 0},
Andy Fleming09b88df2007-08-15 20:03:25 -050089#endif /* CONFIG_TSEC4 */
90#endif /* CONFIG_MPC85XX_FEC */
wdenka445ddf2004-06-09 00:34:46 +000091};
92
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050093#define MAXCONTROLLERS (4)
wdenka445ddf2004-06-09 00:34:46 +000094
95static int relocated = 0;
96
97static struct tsec_private *privlist[MAXCONTROLLERS];
98
wdenk9c53f402003-10-15 23:53:47 +000099#ifdef __GNUC__
100static RTXBD rtx __attribute__ ((aligned(8)));
101#else
102#error "rtx must be 64-bit aligned"
103#endif
104
Jon Loeligerb7ced082006-10-10 17:03:43 -0500105static int tsec_send(struct eth_device *dev,
106 volatile void *packet, int length);
107static int tsec_recv(struct eth_device *dev);
108static int tsec_init(struct eth_device *dev, bd_t * bd);
109static void tsec_halt(struct eth_device *dev);
110static void init_registers(volatile tsec_t * regs);
wdenka445ddf2004-06-09 00:34:46 +0000111static void startup_tsec(struct eth_device *dev);
112static int init_phy(struct eth_device *dev);
113void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
114uint read_phy_reg(struct tsec_private *priv, uint regnum);
Jon Loeligerb7ced082006-10-10 17:03:43 -0500115struct phy_info *get_phy_info(struct eth_device *dev);
wdenka445ddf2004-06-09 00:34:46 +0000116void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
117static void adjust_link(struct eth_device *dev);
118static void relocate_cmds(void);
Wolfgang Denk92254112007-11-18 16:36:27 +0100119#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
120 && !defined(BITBANGMII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200121static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500122 unsigned char reg, unsigned short value);
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200123static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500124 unsigned char reg, unsigned short *value);
Wolfgang Denk92254112007-11-18 16:36:27 +0100125#endif
David Updegraff7280da72007-06-11 10:41:07 -0500126#ifdef CONFIG_MCAST_TFTP
127static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
128#endif
wdenk78924a72004-04-18 21:45:42 +0000129
wdenka445ddf2004-06-09 00:34:46 +0000130/* Initialize device structure. Returns success if PHY
131 * initialization succeeded (i.e. if it recognizes the PHY)
132 */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500133int tsec_initialize(bd_t * bis, int index, char *devname)
wdenk9c53f402003-10-15 23:53:47 +0000134{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500135 struct eth_device *dev;
wdenk9c53f402003-10-15 23:53:47 +0000136 int i;
wdenka445ddf2004-06-09 00:34:46 +0000137 struct tsec_private *priv;
wdenk9c53f402003-10-15 23:53:47 +0000138
Jon Loeligerb7ced082006-10-10 17:03:43 -0500139 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk9c53f402003-10-15 23:53:47 +0000140
Jon Loeligerb7ced082006-10-10 17:03:43 -0500141 if (NULL == dev)
wdenk9c53f402003-10-15 23:53:47 +0000142 return 0;
143
144 memset(dev, 0, sizeof *dev);
145
Jon Loeligerb7ced082006-10-10 17:03:43 -0500146 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenka445ddf2004-06-09 00:34:46 +0000147
Jon Loeligerb7ced082006-10-10 17:03:43 -0500148 if (NULL == priv)
wdenka445ddf2004-06-09 00:34:46 +0000149 return 0;
150
151 privlist[index] = priv;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500152 priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE);
wdenka445ddf2004-06-09 00:34:46 +0000153 priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
Jon Loeligerb7ced082006-10-10 17:03:43 -0500154 tsec_info[index].phyregidx *
155 TSEC_SIZE);
wdenka445ddf2004-06-09 00:34:46 +0000156
157 priv->phyaddr = tsec_info[index].phyaddr;
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500158 priv->flags = tsec_info[index].flags;
wdenka445ddf2004-06-09 00:34:46 +0000159
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500160 sprintf(dev->name, devname);
wdenk9c53f402003-10-15 23:53:47 +0000161 dev->iobase = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500162 dev->priv = priv;
163 dev->init = tsec_init;
164 dev->halt = tsec_halt;
165 dev->send = tsec_send;
166 dev->recv = tsec_recv;
David Updegraff7280da72007-06-11 10:41:07 -0500167#ifdef CONFIG_MCAST_TFTP
168 dev->mcast = tsec_mcast_addr;
169#endif
wdenk9c53f402003-10-15 23:53:47 +0000170
171 /* Tell u-boot to get the addr from the env */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500172 for (i = 0; i < 6; i++)
wdenk9c53f402003-10-15 23:53:47 +0000173 dev->enetaddr[i] = 0;
174
175 eth_register(dev);
176
wdenka445ddf2004-06-09 00:34:46 +0000177 /* Reset the MAC */
178 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
179 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk78924a72004-04-18 21:45:42 +0000180
Jon Loeliger82ecaad2007-07-09 17:39:42 -0500181#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200182 && !defined(BITBANGMII)
183 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
184#endif
185
wdenka445ddf2004-06-09 00:34:46 +0000186 /* Try to initialize PHY here, and return */
187 return init_phy(dev);
wdenk9c53f402003-10-15 23:53:47 +0000188}
189
wdenk9c53f402003-10-15 23:53:47 +0000190/* Initializes data structures and registers for the controller,
wdenkbfad55d2005-03-14 23:56:42 +0000191 * and brings the interface up. Returns the link status, meaning
wdenka445ddf2004-06-09 00:34:46 +0000192 * that it returns success if the link is up, failure otherwise.
Jon Loeligerb7ced082006-10-10 17:03:43 -0500193 * This allows u-boot to find the first active controller.
194 */
195int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk9c53f402003-10-15 23:53:47 +0000196{
wdenk9c53f402003-10-15 23:53:47 +0000197 uint tempval;
198 char tmpbuf[MAC_ADDR_LEN];
199 int i;
wdenka445ddf2004-06-09 00:34:46 +0000200 struct tsec_private *priv = (struct tsec_private *)dev->priv;
201 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000202
203 /* Make sure the controller is stopped */
204 tsec_halt(dev);
205
wdenka445ddf2004-06-09 00:34:46 +0000206 /* Init MACCFG2. Defaults to GMII */
wdenk9c53f402003-10-15 23:53:47 +0000207 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
208
209 /* Init ECNTRL */
210 regs->ecntrl = ECNTRL_INIT_SETTINGS;
211
212 /* Copy the station address into the address registers.
213 * Backwards, because little endian MACS are dumb */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500214 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenka445ddf2004-06-09 00:34:46 +0000215 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk9c53f402003-10-15 23:53:47 +0000216 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500217 regs->macstnaddr1 = *((uint *) (tmpbuf));
wdenk9c53f402003-10-15 23:53:47 +0000218
Jon Loeligerb7ced082006-10-10 17:03:43 -0500219 tempval = *((uint *) (tmpbuf + 4));
wdenk9c53f402003-10-15 23:53:47 +0000220
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200221 regs->macstnaddr2 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000222
wdenk9c53f402003-10-15 23:53:47 +0000223 /* reset the indices to zero */
224 rxIdx = 0;
225 txIdx = 0;
226
227 /* Clear out (for the most part) the other registers */
228 init_registers(regs);
229
230 /* Ready the device for tx/rx */
wdenka445ddf2004-06-09 00:34:46 +0000231 startup_tsec(dev);
wdenk9c53f402003-10-15 23:53:47 +0000232
wdenka445ddf2004-06-09 00:34:46 +0000233 /* If there's no link, fail */
Ben Warrende9fcb52008-01-09 18:15:53 -0500234 return (priv->link ? 0 : -1);
wdenka445ddf2004-06-09 00:34:46 +0000235
236}
wdenk9c53f402003-10-15 23:53:47 +0000237
wdenka445ddf2004-06-09 00:34:46 +0000238/* 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
242 */
michael.firth@bt.com08384842008-01-16 11:40:51 +0000243void write_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum, uint value)
wdenka445ddf2004-06-09 00:34:46 +0000244{
245 volatile tsec_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500246 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000247
248 regbase->miimadd = (phyid << 8) | regnum;
249 regbase->miimcon = value;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500250 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000251
Jon Loeligerb7ced082006-10-10 17:03:43 -0500252 timeout = 1000000;
253 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000254}
255
michael.firth@bt.com08384842008-01-16 11:40:51 +0000256/* #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)
258
wdenka445ddf2004-06-09 00:34:46 +0000259/* Reads register regnum on the device's PHY through the
wdenkbfad55d2005-03-14 23:56:42 +0000260 * registers specified in priv. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +0000261 * 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
264 */
michael.firth@bt.com08384842008-01-16 11:40:51 +0000265uint read_any_phy_reg(struct tsec_private *priv, uint phyid, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +0000266{
267 uint value;
wdenka445ddf2004-06-09 00:34:46 +0000268 volatile tsec_t *regbase = priv->phyregs;
wdenk9c53f402003-10-15 23:53:47 +0000269
wdenka445ddf2004-06-09 00:34:46 +0000270 /* Put the address of the phy, and the register
271 * number into MIIMADD */
272 regbase->miimadd = (phyid << 8) | regnum;
wdenk9c53f402003-10-15 23:53:47 +0000273
274 /* Clear the command register, and wait */
275 regbase->miimcom = 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500276 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000277
278 /* Initiate a read command, and wait */
279 regbase->miimcom = MIIM_READ_COMMAND;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500280 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000281
282 /* Wait for the the indication that the read is done */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500283 while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk9c53f402003-10-15 23:53:47 +0000284
285 /* Grab the value read from the PHY */
286 value = regbase->miimstat;
287
288 return value;
289}
290
michael.firth@bt.com08384842008-01-16 11:40:51 +0000291/* #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)
293
wdenka445ddf2004-06-09 00:34:46 +0000294/* 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
297 */
298static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000299{
wdenka445ddf2004-06-09 00:34:46 +0000300 struct tsec_private *priv = (struct tsec_private *)dev->priv;
301 struct phy_info *curphy;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500302 volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
wdenk9c53f402003-10-15 23:53:47 +0000303
304 /* Assign a Physical address to the TBI */
Joe Hamman4290d4c2007-08-09 09:08:18 -0500305 regs->tbipa = CFG_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500306 regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
Joe Hamman4290d4c2007-08-09 09:08:18 -0500307 regs->tbipa = CFG_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500308 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000309
310 /* Reset MII (due to new addresses) */
311 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500312 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000313 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500314 asm("sync");
Jon Loeligerb7ced082006-10-10 17:03:43 -0500315 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk9c53f402003-10-15 23:53:47 +0000316
Jon Loeligerb7ced082006-10-10 17:03:43 -0500317 if (0 == relocated)
wdenka445ddf2004-06-09 00:34:46 +0000318 relocate_cmds();
wdenk9c53f402003-10-15 23:53:47 +0000319
wdenka445ddf2004-06-09 00:34:46 +0000320 /* Get the cmd structure corresponding to the attached
321 * PHY */
322 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000323
Ben Warrenf11eefb2006-10-26 14:38:25 -0400324 if (curphy == NULL) {
325 priv->phyinfo = NULL;
wdenka445ddf2004-06-09 00:34:46 +0000326 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000327
wdenka445ddf2004-06-09 00:34:46 +0000328 return 0;
329 }
wdenk9c53f402003-10-15 23:53:47 +0000330
wdenka445ddf2004-06-09 00:34:46 +0000331 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000332
wdenka445ddf2004-06-09 00:34:46 +0000333 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000334
wdenka445ddf2004-06-09 00:34:46 +0000335 return 1;
336}
wdenk9c53f402003-10-15 23:53:47 +0000337
Jon Loeligerb7ced082006-10-10 17:03:43 -0500338/*
339 * Returns which value to write to the control register.
340 * For 10/100, the value is slightly different
341 */
342uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000343{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500344 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000345 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000346 else
wdenka445ddf2004-06-09 00:34:46 +0000347 return MIIM_CR_INIT;
348}
wdenk9c53f402003-10-15 23:53:47 +0000349
wdenka445ddf2004-06-09 00:34:46 +0000350/* Parse the status register for link, and then do
Jon Loeligerb7ced082006-10-10 17:03:43 -0500351 * auto-negotiation
352 */
353uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000354{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200355 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500356 * Wait if the link is up, and autonegotiation is in progress
357 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200358 */
359 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500360 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500361 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200362 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000363
Jon Loeligerb7ced082006-10-10 17:03:43 -0500364 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500365 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200366 /*
367 * Timeout reached ?
368 */
369 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500370 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200371 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800372 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200373 }
wdenk9c53f402003-10-15 23:53:47 +0000374
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200375 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500376 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200377 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500378 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000379 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200380 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500381 puts(" done\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200382 priv->link = 1;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500383 udelay(500000); /* another 500 ms (results in faster booting) */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200384 } else {
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500385 if (mii_reg & MIIM_STATUS_LINK)
386 priv->link = 1;
387 else
388 priv->link = 0;
wdenk9c53f402003-10-15 23:53:47 +0000389 }
390
wdenka445ddf2004-06-09 00:34:46 +0000391 return 0;
392}
393
David Updegraff0451b012007-04-20 14:34:48 -0500394/* 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.
399 *
400 * Stolen from Linux's mii.c and phy_device.c
401 */
402uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
403{
404 /* We're using autonegotiation */
405 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
406 uint lpa = 0;
407 uint gblpa = 0;
408
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
413 */
414 gblpa = read_phy_reg(priv, PHY_1000BTSR);
415 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
416 }
417
418 /* Set the baseline so we only have to set them
419 * if they're different
420 */
421 priv->speed = 10;
422 priv->duplexity = 0;
423
424 /* Check the gigabit fields */
425 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
426 priv->speed = 1000;
427
428 if (gblpa & PHY_1000BTSR_1000FD)
429 priv->duplexity = 1;
430
431 /* We're done! */
432 return 0;
433 }
434
435 lpa = read_phy_reg(priv, PHY_ANAR);
436 lpa &= read_phy_reg(priv, PHY_ANLPAR);
437
438 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
439 priv->speed = 100;
440
441 if (lpa & PHY_ANLPAR_TXFD)
442 priv->duplexity = 1;
443
444 } else if (lpa & PHY_ANLPAR_10FD)
445 priv->duplexity = 1;
446 } else {
447 uint bmcr = read_phy_reg(priv, PHY_BMCR);
448
449 priv->speed = 10;
450 priv->duplexity = 0;
451
452 if (bmcr & PHY_BMCR_DPLX)
453 priv->duplexity = 1;
454
455 if (bmcr & PHY_BMCR_1000_MBPS)
456 priv->speed = 1000;
457 else if (bmcr & PHY_BMCR_100_MBPS)
458 priv->speed = 100;
459 }
460
461 return 0;
462}
463
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500464/*
465 * Parse the BCM54xx status register for speed and duplex information.
466 * The linux sungem_phy has this information, but in a table format.
467 */
468uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
469{
470
471 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
472
473 case 1:
474 printf("Enet starting in 10BT/HD\n");
475 priv->duplexity = 0;
476 priv->speed = 10;
477 break;
478
479 case 2:
480 printf("Enet starting in 10BT/FD\n");
481 priv->duplexity = 1;
482 priv->speed = 10;
483 break;
484
485 case 3:
486 printf("Enet starting in 100BT/HD\n");
487 priv->duplexity = 0;
488 priv->speed = 100;
489 break;
490
491 case 5:
492 printf("Enet starting in 100BT/FD\n");
493 priv->duplexity = 1;
494 priv->speed = 100;
495 break;
496
497 case 6:
498 printf("Enet starting in 1000BT/HD\n");
499 priv->duplexity = 0;
500 priv->speed = 1000;
501 break;
502
503 case 7:
504 printf("Enet starting in 1000BT/FD\n");
505 priv->duplexity = 1;
506 priv->speed = 1000;
507 break;
508
509 default:
510 printf("Auto-neg error, defaulting to 10BT/HD\n");
511 priv->duplexity = 0;
512 priv->speed = 10;
513 break;
514 }
515
516 return 0;
517
518}
wdenka445ddf2004-06-09 00:34:46 +0000519/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500520 * information
521 */
522uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000523{
524 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000525
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200526 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
527
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500528 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
529 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200530 int i = 0;
531
Jon Loeligerb7ced082006-10-10 17:03:43 -0500532 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500533 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
534 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200535 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500536 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200537 priv->link = 0;
538 break;
539 }
540
541 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500542 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200543 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500544 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200545 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
546 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500547 puts(" done\n");
548 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500549 } else {
550 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
551 priv->link = 1;
552 else
553 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200554 }
555
Jon Loeligerb7ced082006-10-10 17:03:43 -0500556 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000557 priv->duplexity = 1;
558 else
559 priv->duplexity = 0;
560
Jon Loeligerb7ced082006-10-10 17:03:43 -0500561 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000562
Jon Loeligerb7ced082006-10-10 17:03:43 -0500563 switch (speed) {
564 case MIIM_88E1011_PHYSTAT_GBIT:
565 priv->speed = 1000;
566 break;
567 case MIIM_88E1011_PHYSTAT_100:
568 priv->speed = 100;
569 break;
570 default:
571 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000572 }
573
wdenka445ddf2004-06-09 00:34:46 +0000574 return 0;
575}
576
Dave Liua304a282008-01-11 18:45:28 +0800577/* Parse the RTL8211B's status register for speed and duplex
578 * information
579 */
580uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
581{
582 uint speed;
583
584 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300585 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800586 int i = 0;
587
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300588 /* in case of timeout ->link is cleared */
589 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800590 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");
595 priv->link = 0;
596 break;
597 }
598
599 if ((i++ % 1000) == 0) {
600 putc('.');
601 }
602 udelay(1000); /* 1 ms */
603 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
604 }
605 puts(" done\n");
606 udelay(500000); /* another 500 ms (results in faster booting) */
607 } else {
608 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
609 priv->link = 1;
610 else
611 priv->link = 0;
612 }
613
614 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
615 priv->duplexity = 1;
616 else
617 priv->duplexity = 0;
618
619 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
620
621 switch (speed) {
622 case MIIM_RTL8211B_PHYSTAT_GBIT:
623 priv->speed = 1000;
624 break;
625 case MIIM_RTL8211B_PHYSTAT_100:
626 priv->speed = 100;
627 break;
628 default:
629 priv->speed = 10;
630 }
631
632 return 0;
633}
634
wdenka445ddf2004-06-09 00:34:46 +0000635/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500636 * information
637 */
638uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000639{
640 uint speed;
641
Jon Loeligerb7ced082006-10-10 17:03:43 -0500642 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000643 priv->duplexity = 1;
644 else
645 priv->duplexity = 0;
646
647 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500648 switch (speed) {
649 case MIIM_CIS8201_AUXCONSTAT_GBIT:
650 priv->speed = 1000;
651 break;
652 case MIIM_CIS8201_AUXCONSTAT_100:
653 priv->speed = 100;
654 break;
655 default:
656 priv->speed = 10;
657 break;
wdenk9c53f402003-10-15 23:53:47 +0000658 }
659
wdenka445ddf2004-06-09 00:34:46 +0000660 return 0;
661}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500662
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500663/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500664 * information
665 */
666uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500667{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500668 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000669
Jon Loeligerb7ced082006-10-10 17:03:43 -0500670 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
671 priv->duplexity = 1;
672 else
673 priv->duplexity = 0;
674
675 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
676 switch (speed) {
677 case MIIM_VSC8244_AUXCONSTAT_GBIT:
678 priv->speed = 1000;
679 break;
680 case MIIM_VSC8244_AUXCONSTAT_100:
681 priv->speed = 100;
682 break;
683 default:
684 priv->speed = 10;
685 break;
686 }
687
688 return 0;
689}
wdenka445ddf2004-06-09 00:34:46 +0000690
691/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500692 * information
693 */
694uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000695{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500696 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000697 priv->speed = 100;
698 else
699 priv->speed = 10;
700
Jon Loeligerb7ced082006-10-10 17:03:43 -0500701 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000702 priv->duplexity = 1;
703 else
704 priv->duplexity = 0;
705
706 return 0;
707}
708
Jon Loeligerb7ced082006-10-10 17:03:43 -0500709/*
710 * Hack to write all 4 PHYs with the LED values
711 */
712uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000713{
714 uint phyid;
715 volatile tsec_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500716 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000717
Jon Loeligerb7ced082006-10-10 17:03:43 -0500718 for (phyid = 0; phyid < 4; phyid++) {
wdenka445ddf2004-06-09 00:34:46 +0000719 regbase->miimadd = (phyid << 8) | mii_reg;
720 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500721 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000722
Jon Loeligerb7ced082006-10-10 17:03:43 -0500723 timeout = 1000000;
724 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000725 }
wdenk9c53f402003-10-15 23:53:47 +0000726
wdenka445ddf2004-06-09 00:34:46 +0000727 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000728}
729
Jon Loeligerb7ced082006-10-10 17:03:43 -0500730uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500731{
732 if (priv->flags & TSEC_REDUCED)
733 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
734 else
735 return MIIM_CIS8204_EPHYCON_INIT;
736}
wdenk9c53f402003-10-15 23:53:47 +0000737
Dave Liub19ecd32007-09-18 12:37:57 +0800738uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
739{
740 uint mii_data = read_phy_reg(priv, mii_reg);
741
742 if (priv->flags & TSEC_REDUCED)
743 mii_data = (mii_data & 0xfff0) | 0x000b;
744 return mii_data;
745}
746
wdenka445ddf2004-06-09 00:34:46 +0000747/* Initialized required registers to appropriate values, zeroing
748 * those we don't care about (unless zero is bad, in which case,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500749 * choose a more appropriate value)
750 */
751static void init_registers(volatile tsec_t * regs)
wdenk9c53f402003-10-15 23:53:47 +0000752{
753 /* Clear IEVENT */
754 regs->ievent = IEVENT_INIT_CLEAR;
755
756 regs->imask = IMASK_INIT_CLEAR;
757
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;
766
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;
775
776 regs->rctrl = 0x00000000;
777
778 /* Init RMON mib registers */
779 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
780
781 regs->rmon.cam1 = 0xffffffff;
782 regs->rmon.cam2 = 0xffffffff;
783
784 regs->mrblr = MRBLR_INIT_SETTINGS;
785
786 regs->minflr = MINFLR_INIT_SETTINGS;
787
788 regs->attr = ATTR_INIT_SETTINGS;
789 regs->attreli = ATTRELI_INIT_SETTINGS;
790
wdenka445ddf2004-06-09 00:34:46 +0000791}
792
wdenka445ddf2004-06-09 00:34:46 +0000793/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500794 * reported by PHY handling code
795 */
wdenka445ddf2004-06-09 00:34:46 +0000796static void adjust_link(struct eth_device *dev)
797{
798 struct tsec_private *priv = (struct tsec_private *)dev->priv;
799 volatile tsec_t *regs = priv->regs;
800
Jon Loeligerb7ced082006-10-10 17:03:43 -0500801 if (priv->link) {
802 if (priv->duplexity != 0)
wdenka445ddf2004-06-09 00:34:46 +0000803 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
804 else
805 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
806
Jon Loeligerb7ced082006-10-10 17:03:43 -0500807 switch (priv->speed) {
808 case 1000:
809 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
810 | MACCFG2_GMII);
811 break;
812 case 100:
813 case 10:
814 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
815 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500816
Nick Spenceec9670b2006-09-07 07:39:46 -0700817 /* Set R100 bit in all modes although
818 * it is only used in RGMII mode
Jon Loeligerb7ced082006-10-10 17:03:43 -0500819 */
Nick Spenceec9670b2006-09-07 07:39:46 -0700820 if (priv->speed == 100)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500821 regs->ecntrl |= ECNTRL_R100;
822 else
823 regs->ecntrl &= ~(ECNTRL_R100);
824 break;
825 default:
826 printf("%s: Speed was bad\n", dev->name);
827 break;
wdenka445ddf2004-06-09 00:34:46 +0000828 }
829
830 printf("Speed: %d, %s duplex\n", priv->speed,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500831 (priv->duplexity) ? "full" : "half");
wdenka445ddf2004-06-09 00:34:46 +0000832
833 } else {
834 printf("%s: No link.\n", dev->name);
835 }
wdenk9c53f402003-10-15 23:53:47 +0000836}
837
wdenka445ddf2004-06-09 00:34:46 +0000838/* Set up the buffers and their descriptors, and bring up the
Jon Loeligerb7ced082006-10-10 17:03:43 -0500839 * interface
840 */
wdenka445ddf2004-06-09 00:34:46 +0000841static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000842{
843 int i;
wdenka445ddf2004-06-09 00:34:46 +0000844 struct tsec_private *priv = (struct tsec_private *)dev->priv;
845 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000846
847 /* Point to the buffer descriptors */
848 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
849 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
850
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;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500855 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk9c53f402003-10-15 23:53:47 +0000856 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500857 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000858
859 /* Initialize the TX Buffer Descriptors */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500860 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000861 rtx.txbd[i].status = 0;
862 rtx.txbd[i].length = 0;
863 rtx.txbd[i].bufPtr = 0;
864 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500865 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000866
wdenka445ddf2004-06-09 00:34:46 +0000867 /* Start up the PHY */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400868 if(priv->phyinfo)
869 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraff0451b012007-04-20 14:34:48 -0500870
wdenka445ddf2004-06-09 00:34:46 +0000871 adjust_link(dev);
872
wdenk9c53f402003-10-15 23:53:47 +0000873 /* Enable Transmit and Receive */
874 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
875
876 /* Tell the DMA it is clear to go */
877 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
878 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilsone3d7d6b2007-10-19 11:33:48 -0500879 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk9c53f402003-10-15 23:53:47 +0000880 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
881}
882
wdenkbfad55d2005-03-14 23:56:42 +0000883/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +0000884 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +0000885 * do the same. Presumably, this would be zero if there were no
Jon Loeligerb7ced082006-10-10 17:03:43 -0500886 * errors
887 */
888static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +0000889{
890 int i;
891 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +0000892 struct tsec_private *priv = (struct tsec_private *)dev->priv;
893 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000894
895 /* Find an empty buffer descriptor */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500896 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000897 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500898 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000899 return result;
900 }
901 }
902
Jon Loeligerb7ced082006-10-10 17:03:43 -0500903 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk9c53f402003-10-15 23:53:47 +0000904 rtx.txbd[txIdx].length = length;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500905 rtx.txbd[txIdx].status |=
906 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk9c53f402003-10-15 23:53:47 +0000907
908 /* Tell the DMA to go */
909 regs->tstat = TSTAT_CLEAR_THALT;
910
911 /* Wait for buffer to be transmitted */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500912 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000913 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500914 debug("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000915 return result;
916 }
917 }
918
919 txIdx = (txIdx + 1) % TX_BUF_CNT;
920 result = rtx.txbd[txIdx].status & TXBD_STATS;
921
922 return result;
923}
924
Jon Loeligerb7ced082006-10-10 17:03:43 -0500925static int tsec_recv(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000926{
927 int length;
wdenka445ddf2004-06-09 00:34:46 +0000928 struct tsec_private *priv = (struct tsec_private *)dev->priv;
929 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000930
Jon Loeligerb7ced082006-10-10 17:03:43 -0500931 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk9c53f402003-10-15 23:53:47 +0000932
933 length = rtx.rxbd[rxIdx].length;
934
935 /* Send the packet up if there were no errors */
936 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
937 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +0000938 } else {
939 printf("Got error %x\n",
Jon Loeligerb7ced082006-10-10 17:03:43 -0500940 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +0000941 }
942
943 rtx.rxbd[rxIdx].length = 0;
944
945 /* Set the wrap bit if this is the last element in the list */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500946 rtx.rxbd[rxIdx].status =
947 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk9c53f402003-10-15 23:53:47 +0000948
949 rxIdx = (rxIdx + 1) % PKTBUFSRX;
950 }
951
Jon Loeligerb7ced082006-10-10 17:03:43 -0500952 if (regs->ievent & IEVENT_BSY) {
wdenk9c53f402003-10-15 23:53:47 +0000953 regs->ievent = IEVENT_BSY;
954 regs->rstat = RSTAT_CLEAR_RHALT;
955 }
956
957 return -1;
958
959}
960
wdenka445ddf2004-06-09 00:34:46 +0000961/* Stop the interface */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500962static void tsec_halt(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000963{
wdenka445ddf2004-06-09 00:34:46 +0000964 struct tsec_private *priv = (struct tsec_private *)dev->priv;
965 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000966
967 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
968 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
969
Jon Loeligerb7ced082006-10-10 17:03:43 -0500970 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk9c53f402003-10-15 23:53:47 +0000971
972 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
973
wdenka445ddf2004-06-09 00:34:46 +0000974 /* Shut down the PHY, as needed */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400975 if(priv->phyinfo)
976 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenka445ddf2004-06-09 00:34:46 +0000977}
978
Andy Flemingbee67002007-08-03 04:05:25 -0500979struct phy_info phy_info_M88E1149S = {
Wolfgang Denk15e87572007-08-06 01:01:49 +0200980 0x1410ca,
981 "Marvell 88E1149S",
982 4,
983 (struct phy_cmd[]){ /* config */
984 /* Reset and configure the PHY */
985 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
986 {0x1d, 0x1f, NULL},
987 {0x1e, 0x200c, NULL},
988 {0x1d, 0x5, NULL},
989 {0x1e, 0x0, NULL},
990 {0x1e, 0x100, 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},
995 {miim_end,}
996 },
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},
1005 {miim_end,}
1006 },
1007 (struct phy_cmd[]){ /* shutdown */
1008 {miim_end,}
1009 },
Andy Flemingbee67002007-08-03 04:05:25 -05001010};
1011
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001012/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1013struct 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},
1024 {miim_end,}
1025 },
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},
1033 {miim_end,}
1034 },
1035 (struct phy_cmd[]) { /* shutdown */
1036 {miim_end,}
1037 },
1038};
1039
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001040struct 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},
1051 {miim_end,}
1052 },
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},
1060 {miim_end,}
1061 },
1062 (struct phy_cmd[]) { /* shutdown */
1063 {miim_end,}
1064 },
1065};
1066
wdenka445ddf2004-06-09 00:34:46 +00001067struct phy_info phy_info_M88E1011S = {
1068 0x01410c6,
1069 "Marvell 88E1011S",
1070 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001071 (struct phy_cmd[]){ /* config */
1072 /* Reset and configure the PHY */
1073 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1074 {0x1d, 0x1f, NULL},
1075 {0x1e, 0x200c, NULL},
1076 {0x1d, 0x5, NULL},
1077 {0x1e, 0x0, 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},
1083 {miim_end,}
1084 },
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},
1093 {miim_end,}
1094 },
1095 (struct phy_cmd[]){ /* shutdown */
1096 {miim_end,}
1097 },
wdenka445ddf2004-06-09 00:34:46 +00001098};
1099
wdenkbfad55d2005-03-14 23:56:42 +00001100struct phy_info phy_info_M88E1111S = {
1101 0x01410cc,
1102 "Marvell 88E1111S",
1103 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001104 (struct phy_cmd[]){ /* config */
1105 /* Reset and configure the PHY */
1106 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Dave Liub19ecd32007-09-18 12:37:57 +08001107 {0x1b, 0x848f, &mii_m88e1111s_setmode},
Nick Spenceec9670b2006-09-07 07:39:46 -07001108 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001109 {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},
1113 {miim_end,}
1114 },
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},
1123 {miim_end,}
1124 },
1125 (struct phy_cmd[]){ /* shutdown */
1126 {miim_end,}
1127 },
wdenkbfad55d2005-03-14 23:56:42 +00001128};
1129
Ron Madridc1e2b582008-05-23 15:37:05 -07001130struct phy_info phy_info_M88E1118 = {
1131 0x01410e1,
1132 "Marvell 88E1118",
1133 4,
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},
1143 {miim_end,}
1144 },
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},
1153 {miim_end,}
1154 },
1155 (struct phy_cmd[]){ /* shutdown */
1156 {miim_end,}
1157 },
1158};
1159
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001160/*
1161 * Since to access LED register we need do switch the page, we
1162 * do LED configuring in the miim_read-like function as follows
1163 */
1164uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1165{
1166 uint pg;
1167
1168 /* Switch the page to access the led register */
1169 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1170 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1171
1172 /* Configure leds */
1173 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1174 MIIM_88E1121_PHY_LED_DEF);
1175
1176 /* Restore the page pointer */
1177 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1178 return 0;
1179}
1180
1181struct phy_info phy_info_M88E1121R = {
1182 0x01410cb,
1183 "Marvell 88E1121R",
1184 4,
1185 (struct phy_cmd[]){ /* config */
1186 /* Reset and configure the PHY */
1187 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1188 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1189 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1190 /* Configure leds */
1191 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1192 &mii_88E1121_set_led},
1193 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1194 {miim_end,}
1195 },
1196 (struct phy_cmd[]){ /* startup */
1197 /* Status is read once to clear old link state */
1198 {MIIM_STATUS, miim_read, NULL},
1199 {MIIM_STATUS, miim_read, &mii_parse_sr},
1200 {MIIM_STATUS, miim_read, &mii_parse_link},
1201 {miim_end,}
1202 },
1203 (struct phy_cmd[]){ /* shutdown */
1204 {miim_end,}
1205 },
1206};
1207
Andy Fleming239e75f2006-09-13 10:34:18 -05001208static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1209{
Andy Fleming239e75f2006-09-13 10:34:18 -05001210 uint mii_data = read_phy_reg(priv, mii_reg);
1211
Andy Fleming239e75f2006-09-13 10:34:18 -05001212 /* Setting MIIM_88E1145_PHY_EXT_CR */
1213 if (priv->flags & TSEC_REDUCED)
1214 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -05001215 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -05001216 else
1217 return mii_data;
1218}
1219
1220static struct phy_info phy_info_M88E1145 = {
1221 0x01410cd,
1222 "Marvell 88E1145",
1223 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001224 (struct phy_cmd[]){ /* config */
Andy Fleming180d03a2007-05-08 17:23:02 -05001225 /* Reset the PHY */
1226 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1227
Jon Loeligerb7ced082006-10-10 17:03:43 -05001228 /* Errata E0, E1 */
1229 {29, 0x001b, NULL},
1230 {30, 0x418f, NULL},
1231 {29, 0x0016, NULL},
1232 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -05001233
Andy Fleming180d03a2007-05-08 17:23:02 -05001234 /* Configure the PHY */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001235 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1236 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1237 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1238 NULL},
1239 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1240 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1241 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1242 {miim_end,}
1243 },
1244 (struct phy_cmd[]){ /* startup */
1245 /* Status is read once to clear old link state */
1246 {MIIM_STATUS, miim_read, NULL},
1247 /* Auto-negotiate */
1248 {MIIM_STATUS, miim_read, &mii_parse_sr},
1249 {MIIM_88E1111_PHY_LED_CONTROL,
1250 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1251 /* Read the Status */
1252 {MIIM_88E1011_PHY_STATUS, miim_read,
1253 &mii_parse_88E1011_psr},
1254 {miim_end,}
1255 },
1256 (struct phy_cmd[]){ /* shutdown */
1257 {miim_end,}
1258 },
Andy Fleming239e75f2006-09-13 10:34:18 -05001259};
1260
wdenka445ddf2004-06-09 00:34:46 +00001261struct phy_info phy_info_cis8204 = {
1262 0x3f11,
1263 "Cicada Cis8204",
1264 6,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001265 (struct phy_cmd[]){ /* config */
1266 /* Override PHY config settings */
1267 {MIIM_CIS8201_AUX_CONSTAT,
1268 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1269 /* Configure some basic stuff */
1270 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1271 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1272 &mii_cis8204_fixled},
1273 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1274 &mii_cis8204_setmode},
1275 {miim_end,}
1276 },
1277 (struct phy_cmd[]){ /* startup */
1278 /* Read the Status (2x to make sure link is right) */
1279 {MIIM_STATUS, miim_read, NULL},
1280 /* Auto-negotiate */
1281 {MIIM_STATUS, miim_read, &mii_parse_sr},
1282 /* Read the status */
1283 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1284 &mii_parse_cis8201},
1285 {miim_end,}
1286 },
1287 (struct phy_cmd[]){ /* shutdown */
1288 {miim_end,}
1289 },
wdenka445ddf2004-06-09 00:34:46 +00001290};
1291
1292/* Cicada 8201 */
1293struct phy_info phy_info_cis8201 = {
1294 0xfc41,
1295 "CIS8201",
1296 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001297 (struct phy_cmd[]){ /* config */
1298 /* Override PHY config settings */
1299 {MIIM_CIS8201_AUX_CONSTAT,
1300 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1301 /* Set up the interface mode */
1302 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1303 NULL},
1304 /* Configure some basic stuff */
1305 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1306 {miim_end,}
1307 },
1308 (struct phy_cmd[]){ /* startup */
1309 /* Read the Status (2x to make sure link is right) */
1310 {MIIM_STATUS, miim_read, NULL},
1311 /* Auto-negotiate */
1312 {MIIM_STATUS, miim_read, &mii_parse_sr},
1313 /* Read the status */
1314 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1315 &mii_parse_cis8201},
1316 {miim_end,}
1317 },
1318 (struct phy_cmd[]){ /* shutdown */
1319 {miim_end,}
1320 },
wdenka445ddf2004-06-09 00:34:46 +00001321};
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001322struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001323 0x3f1b,
1324 "Vitesse VSC8244",
1325 6,
1326 (struct phy_cmd[]){ /* config */
1327 /* Override PHY config settings */
1328 /* Configure some basic stuff */
1329 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1330 {miim_end,}
1331 },
1332 (struct phy_cmd[]){ /* startup */
1333 /* Read the Status (2x to make sure link is right) */
1334 {MIIM_STATUS, miim_read, NULL},
1335 /* Auto-negotiate */
1336 {MIIM_STATUS, miim_read, &mii_parse_sr},
1337 /* Read the status */
1338 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1339 &mii_parse_vsc8244},
1340 {miim_end,}
1341 },
1342 (struct phy_cmd[]){ /* shutdown */
1343 {miim_end,}
1344 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001345};
wdenka445ddf2004-06-09 00:34:46 +00001346
Tor Krill8b3a82f2008-03-28 15:29:45 +01001347struct phy_info phy_info_VSC8601 = {
1348 0x00007042,
1349 "Vitesse VSC8601",
1350 4,
1351 (struct phy_cmd[]){ /* config */
1352 /* Override PHY config settings */
1353 /* Configure some basic stuff */
1354 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1355#ifdef CFG_VSC8601_SKEWFIX
1356 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Wolfgang Denk88390f62008-05-04 00:35:15 +02001357#if defined(CFG_VSC8601_SKEW_TX) && defined(CFG_VSC8601_SKEW_RX)
Andre Schwarz1e18be12008-04-29 19:18:32 +02001358 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1359#define VSC8101_SKEW (CFG_VSC8601_SKEW_TX<<14)|(CFG_VSC8601_SKEW_RX<<12)
1360 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1361 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1362#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001363#endif
1364 {miim_end,}
1365 },
1366 (struct phy_cmd[]){ /* startup */
1367 /* Read the Status (2x to make sure link is right) */
1368 {MIIM_STATUS, miim_read, NULL},
1369 /* Auto-negotiate */
1370 {MIIM_STATUS, miim_read, &mii_parse_sr},
1371 /* Read the status */
1372 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1373 &mii_parse_vsc8244},
1374 {miim_end,}
1375 },
1376 (struct phy_cmd[]){ /* shutdown */
1377 {miim_end,}
1378 },
1379};
1380
1381
wdenka445ddf2004-06-09 00:34:46 +00001382struct phy_info phy_info_dm9161 = {
1383 0x0181b88,
1384 "Davicom DM9161E",
1385 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001386 (struct phy_cmd[]){ /* config */
1387 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1388 /* Do not bypass the scrambler/descrambler */
1389 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1390 /* Clear 10BTCSR to default */
1391 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1392 NULL},
1393 /* Configure some basic stuff */
1394 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1395 /* Restart Auto Negotiation */
1396 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1397 {miim_end,}
1398 },
1399 (struct phy_cmd[]){ /* startup */
1400 /* Status is read once to clear old link state */
1401 {MIIM_STATUS, miim_read, NULL},
1402 /* Auto-negotiate */
1403 {MIIM_STATUS, miim_read, &mii_parse_sr},
1404 /* Read the status */
1405 {MIIM_DM9161_SCSR, miim_read,
1406 &mii_parse_dm9161_scsr},
1407 {miim_end,}
1408 },
1409 (struct phy_cmd[]){ /* shutdown */
1410 {miim_end,}
1411 },
wdenka445ddf2004-06-09 00:34:46 +00001412};
David Updegraff0451b012007-04-20 14:34:48 -05001413/* a generic flavor. */
1414struct phy_info phy_info_generic = {
1415 0,
1416 "Unknown/Generic PHY",
1417 32,
1418 (struct phy_cmd[]) { /* config */
1419 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1420 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1421 {miim_end,}
1422 },
1423 (struct phy_cmd[]) { /* startup */
1424 {PHY_BMSR, miim_read, NULL},
1425 {PHY_BMSR, miim_read, &mii_parse_sr},
1426 {PHY_BMSR, miim_read, &mii_parse_link},
1427 {miim_end,}
1428 },
1429 (struct phy_cmd[]) { /* shutdown */
1430 {miim_end,}
1431 }
1432};
1433
wdenka445ddf2004-06-09 00:34:46 +00001434
wdenkf41ff3b2005-04-04 23:43:44 +00001435uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1436{
wdenke085e5b2005-04-05 23:32:21 +00001437 unsigned int speed;
1438 if (priv->link) {
1439 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001440
wdenke085e5b2005-04-05 23:32:21 +00001441 switch (speed) {
1442 case MIIM_LXT971_SR2_10HDX:
1443 priv->speed = 10;
1444 priv->duplexity = 0;
1445 break;
1446 case MIIM_LXT971_SR2_10FDX:
1447 priv->speed = 10;
1448 priv->duplexity = 1;
1449 break;
1450 case MIIM_LXT971_SR2_100HDX:
1451 priv->speed = 100;
1452 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001453 break;
wdenke085e5b2005-04-05 23:32:21 +00001454 default:
1455 priv->speed = 100;
1456 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001457 }
1458 } else {
1459 priv->speed = 0;
1460 priv->duplexity = 0;
1461 }
wdenkf41ff3b2005-04-04 23:43:44 +00001462
wdenke085e5b2005-04-05 23:32:21 +00001463 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +00001464}
1465
wdenkbfad55d2005-03-14 23:56:42 +00001466static struct phy_info phy_info_lxt971 = {
1467 0x0001378e,
1468 "LXT971",
1469 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001470 (struct phy_cmd[]){ /* config */
1471 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1472 {miim_end,}
1473 },
1474 (struct phy_cmd[]){ /* startup - enable interrupts */
1475 /* { 0x12, 0x00f2, NULL }, */
1476 {MIIM_STATUS, miim_read, NULL},
1477 {MIIM_STATUS, miim_read, &mii_parse_sr},
1478 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1479 {miim_end,}
1480 },
1481 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1482 {miim_end,}
1483 },
wdenkbfad55d2005-03-14 23:56:42 +00001484};
1485
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001486/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -05001487 * information
1488 */
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001489uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1490{
1491 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1492
1493 case MIIM_DP83865_SPD_1000:
1494 priv->speed = 1000;
1495 break;
1496
1497 case MIIM_DP83865_SPD_100:
1498 priv->speed = 100;
1499 break;
1500
1501 default:
1502 priv->speed = 10;
1503 break;
1504
1505 }
1506
1507 if (mii_reg & MIIM_DP83865_DPX_FULL)
1508 priv->duplexity = 1;
1509 else
1510 priv->duplexity = 0;
1511
1512 return 0;
1513}
1514
1515struct phy_info phy_info_dp83865 = {
1516 0x20005c7,
1517 "NatSemi DP83865",
1518 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001519 (struct phy_cmd[]){ /* config */
1520 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1521 {miim_end,}
1522 },
1523 (struct phy_cmd[]){ /* startup */
1524 /* Status is read once to clear old link state */
1525 {MIIM_STATUS, miim_read, NULL},
1526 /* Auto-negotiate */
1527 {MIIM_STATUS, miim_read, &mii_parse_sr},
1528 /* Read the link and auto-neg status */
1529 {MIIM_DP83865_LANR, miim_read,
1530 &mii_parse_dp83865_lanr},
1531 {miim_end,}
1532 },
1533 (struct phy_cmd[]){ /* shutdown */
1534 {miim_end,}
1535 },
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001536};
1537
Dave Liua304a282008-01-11 18:45:28 +08001538struct phy_info phy_info_rtl8211b = {
1539 0x001cc91,
1540 "RealTek RTL8211B",
1541 4,
1542 (struct phy_cmd[]){ /* config */
1543 /* Reset and configure the PHY */
1544 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1545 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1546 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1547 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1548 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1549 {miim_end,}
1550 },
1551 (struct phy_cmd[]){ /* startup */
1552 /* Status is read once to clear old link state */
1553 {MIIM_STATUS, miim_read, NULL},
1554 /* Auto-negotiate */
1555 {MIIM_STATUS, miim_read, &mii_parse_sr},
1556 /* Read the status */
1557 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1558 {miim_end,}
1559 },
1560 (struct phy_cmd[]){ /* shutdown */
1561 {miim_end,}
1562 },
1563};
1564
wdenka445ddf2004-06-09 00:34:46 +00001565struct phy_info *phy_info[] = {
wdenka445ddf2004-06-09 00:34:46 +00001566 &phy_info_cis8204,
Timur Tabi054838e2006-10-31 18:44:42 -06001567 &phy_info_cis8201,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001568 &phy_info_BCM5461S,
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001569 &phy_info_BCM5464S,
wdenka445ddf2004-06-09 00:34:46 +00001570 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +00001571 &phy_info_M88E1111S,
Ron Madridc1e2b582008-05-23 15:37:05 -07001572 &phy_info_M88E1118,
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001573 &phy_info_M88E1121R,
Andy Fleming239e75f2006-09-13 10:34:18 -05001574 &phy_info_M88E1145,
Wolfgang Denk15e87572007-08-06 01:01:49 +02001575 &phy_info_M88E1149S,
wdenka445ddf2004-06-09 00:34:46 +00001576 &phy_info_dm9161,
wdenkbfad55d2005-03-14 23:56:42 +00001577 &phy_info_lxt971,
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001578 &phy_info_VSC8244,
Tor Krill8b3a82f2008-03-28 15:29:45 +01001579 &phy_info_VSC8601,
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001580 &phy_info_dp83865,
Dave Liua304a282008-01-11 18:45:28 +08001581 &phy_info_rtl8211b,
David Updegraff0451b012007-04-20 14:34:48 -05001582 &phy_info_generic,
wdenka445ddf2004-06-09 00:34:46 +00001583 NULL
1584};
1585
wdenka445ddf2004-06-09 00:34:46 +00001586/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +00001587 * all of the known PHYs to see if one matches. If so, return
Jon Loeligerb7ced082006-10-10 17:03:43 -05001588 * it, if not, return NULL
1589 */
1590struct phy_info *get_phy_info(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001591{
1592 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1593 uint phy_reg, phy_ID;
1594 int i;
1595 struct phy_info *theInfo = NULL;
1596
1597 /* Grab the bits from PHYIR1, and put them in the upper half */
1598 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1599 phy_ID = (phy_reg & 0xffff) << 16;
1600
1601 /* Grab the bits from PHYIR2, and put them in the lower half */
1602 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1603 phy_ID |= (phy_reg & 0xffff);
1604
1605 /* loop through all the known PHY types, and find one that */
1606 /* matches the ID we read from the PHY. */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001607 for (i = 0; phy_info[i]; i++) {
Andy Flemingb2d14f42007-05-09 00:54:20 -05001608 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenka445ddf2004-06-09 00:34:46 +00001609 theInfo = phy_info[i];
Andy Flemingb2d14f42007-05-09 00:54:20 -05001610 break;
1611 }
wdenka445ddf2004-06-09 00:34:46 +00001612 }
1613
Jon Loeligerb7ced082006-10-10 17:03:43 -05001614 if (theInfo == NULL) {
wdenka445ddf2004-06-09 00:34:46 +00001615 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1616 return NULL;
1617 } else {
Stefan Roesec0dc34f2005-09-21 18:20:22 +02001618 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001619 }
1620
1621 return theInfo;
1622}
1623
wdenka445ddf2004-06-09 00:34:46 +00001624/* Execute the given series of commands on the given device's
Jon Loeligerb7ced082006-10-10 17:03:43 -05001625 * PHY, running functions as necessary
1626 */
wdenka445ddf2004-06-09 00:34:46 +00001627void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1628{
1629 int i;
1630 uint result;
1631 volatile tsec_t *phyregs = priv->phyregs;
1632
1633 phyregs->miimcfg = MIIMCFG_RESET;
1634
1635 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1636
Jon Loeligerb7ced082006-10-10 17:03:43 -05001637 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenka445ddf2004-06-09 00:34:46 +00001638
Jon Loeligerb7ced082006-10-10 17:03:43 -05001639 for (i = 0; cmd->mii_reg != miim_end; i++) {
1640 if (cmd->mii_data == miim_read) {
wdenka445ddf2004-06-09 00:34:46 +00001641 result = read_phy_reg(priv, cmd->mii_reg);
1642
Jon Loeligerb7ced082006-10-10 17:03:43 -05001643 if (cmd->funct != NULL)
1644 (*(cmd->funct)) (result, priv);
wdenka445ddf2004-06-09 00:34:46 +00001645
1646 } else {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001647 if (cmd->funct != NULL)
1648 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenka445ddf2004-06-09 00:34:46 +00001649 else
1650 result = cmd->mii_data;
1651
1652 write_phy_reg(priv, cmd->mii_reg, result);
1653
1654 }
1655 cmd++;
1656 }
1657}
1658
wdenka445ddf2004-06-09 00:34:46 +00001659/* Relocate the function pointers in the phy cmd lists */
1660static void relocate_cmds(void)
1661{
1662 struct phy_cmd **cmdlistptr;
1663 struct phy_cmd *cmd;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001664 int i, j, k;
wdenka445ddf2004-06-09 00:34:46 +00001665
Jon Loeligerb7ced082006-10-10 17:03:43 -05001666 for (i = 0; phy_info[i]; i++) {
wdenka445ddf2004-06-09 00:34:46 +00001667 /* First thing's first: relocate the pointers to the
1668 * PHY command structures (the structs were done) */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001669 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1670 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001671 phy_info[i]->name += gd->reloc_off;
1672 phy_info[i]->config =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001673 (struct phy_cmd *)((uint) phy_info[i]->config
1674 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001675 phy_info[i]->startup =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001676 (struct phy_cmd *)((uint) phy_info[i]->startup
1677 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001678 phy_info[i]->shutdown =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001679 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1680 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001681
1682 cmdlistptr = &phy_info[i]->config;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001683 j = 0;
1684 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1685 k = 0;
1686 for (cmd = *cmdlistptr;
1687 cmd->mii_reg != miim_end;
1688 cmd++) {
wdenka445ddf2004-06-09 00:34:46 +00001689 /* Only relocate non-NULL pointers */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001690 if (cmd->funct)
wdenka445ddf2004-06-09 00:34:46 +00001691 cmd->funct += gd->reloc_off;
1692
1693 k++;
1694 }
1695 j++;
1696 }
1697 }
1698
1699 relocated = 1;
wdenk78924a72004-04-18 21:45:42 +00001700}
1701
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001702#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001703 && !defined(BITBANGMII)
wdenka445ddf2004-06-09 00:34:46 +00001704
wdenk78924a72004-04-18 21:45:42 +00001705/*
1706 * Read a MII PHY register.
1707 *
1708 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001709 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001710 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001711static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001712 unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001713{
wdenka445ddf2004-06-09 00:34:46 +00001714 unsigned short ret;
michael.firth@bt.com08384842008-01-16 11:40:51 +00001715 struct tsec_private *priv = privlist[0];
wdenk78924a72004-04-18 21:45:42 +00001716
Jon Loeligerb7ced082006-10-10 17:03:43 -05001717 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001718 printf("Can't read PHY at address %d\n", addr);
1719 return -1;
1720 }
1721
michael.firth@bt.com08384842008-01-16 11:40:51 +00001722 ret = (unsigned short)read_any_phy_reg(priv, addr, reg);
wdenka445ddf2004-06-09 00:34:46 +00001723 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001724
1725 return 0;
1726}
1727
1728/*
1729 * Write a MII PHY register.
1730 *
1731 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001732 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001733 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001734static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001735 unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001736{
michael.firth@bt.com08384842008-01-16 11:40:51 +00001737 struct tsec_private *priv = privlist[0];
wdenka445ddf2004-06-09 00:34:46 +00001738
Jon Loeligerb7ced082006-10-10 17:03:43 -05001739 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001740 printf("Can't write PHY at address %d\n", addr);
1741 return -1;
1742 }
wdenk78924a72004-04-18 21:45:42 +00001743
michael.firth@bt.com08384842008-01-16 11:40:51 +00001744 write_any_phy_reg(priv, addr, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001745
1746 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001747}
wdenka445ddf2004-06-09 00:34:46 +00001748
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001749#endif
wdenka445ddf2004-06-09 00:34:46 +00001750
David Updegraff7280da72007-06-11 10:41:07 -05001751#ifdef CONFIG_MCAST_TFTP
1752
1753/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1754
1755/* Set the appropriate hash bit for the given addr */
1756
1757/* The algorithm works like so:
1758 * 1) Take the Destination Address (ie the multicast address), and
1759 * do a CRC on it (little endian), and reverse the bits of the
1760 * result.
1761 * 2) Use the 8 most significant bits as a hash into a 256-entry
1762 * table. The table is controlled through 8 32-bit registers:
1763 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1764 * gaddr7. This means that the 3 most significant bits in the
1765 * hash index which gaddr register to use, and the 5 other bits
1766 * indicate which bit (assuming an IBM numbering scheme, which
1767 * for PowerPC (tm) is usually the case) in the tregister holds
1768 * the entry. */
1769static int
1770tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1771{
1772 struct tsec_private *priv = privlist[1];
1773 volatile tsec_t *regs = priv->regs;
1774 volatile u32 *reg_array, value;
1775 u8 result, whichbit, whichreg;
1776
1777 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1778 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1779 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1780 value = (1 << (31-whichbit));
1781
1782 reg_array = &(regs->hash.gaddr0);
1783
1784 if (set) {
1785 reg_array[whichreg] |= value;
1786 } else {
1787 reg_array[whichreg] &= ~value;
1788 }
1789 return 0;
1790}
1791#endif /* Multicast TFTP ? */