blob: 9c9fd377c94798624b46d7b74c5c47db95848835 [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 *
Kumar Gala6a6d9482009-07-28 21:49:52 -05008 * Copyright (C) 2004-2009 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
Andy Flemingfecff2b2008-08-31 16:33:26 -050035#define MAXCONTROLLERS (8)
wdenka445ddf2004-06-09 00:34:46 +000036
37static int relocated = 0;
38
39static struct tsec_private *privlist[MAXCONTROLLERS];
Andy Flemingfecff2b2008-08-31 16:33:26 -050040static int num_tsecs = 0;
wdenka445ddf2004-06-09 00:34:46 +000041
wdenk9c53f402003-10-15 23:53:47 +000042#ifdef __GNUC__
43static RTXBD rtx __attribute__ ((aligned(8)));
44#else
45#error "rtx must be 64-bit aligned"
46#endif
47
Jon Loeligerb7ced082006-10-10 17:03:43 -050048static int tsec_send(struct eth_device *dev,
49 volatile void *packet, int length);
50static int tsec_recv(struct eth_device *dev);
51static int tsec_init(struct eth_device *dev, bd_t * bd);
52static void tsec_halt(struct eth_device *dev);
53static void init_registers(volatile tsec_t * regs);
wdenka445ddf2004-06-09 00:34:46 +000054static void startup_tsec(struct eth_device *dev);
55static int init_phy(struct eth_device *dev);
56void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
57uint read_phy_reg(struct tsec_private *priv, uint regnum);
Jon Loeligerb7ced082006-10-10 17:03:43 -050058struct phy_info *get_phy_info(struct eth_device *dev);
wdenka445ddf2004-06-09 00:34:46 +000059void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
60static void adjust_link(struct eth_device *dev);
61static void relocate_cmds(void);
Wolfgang Denk92254112007-11-18 16:36:27 +010062#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
63 && !defined(BITBANGMII)
Marian Balakowiczaab8c492005-10-28 22:30:33 +020064static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -050065 unsigned char reg, unsigned short value);
Marian Balakowiczaab8c492005-10-28 22:30:33 +020066static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -050067 unsigned char reg, unsigned short *value);
Wolfgang Denk92254112007-11-18 16:36:27 +010068#endif
David Updegraff7280da72007-06-11 10:41:07 -050069#ifdef CONFIG_MCAST_TFTP
70static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
71#endif
wdenk78924a72004-04-18 21:45:42 +000072
Andy Flemingfecff2b2008-08-31 16:33:26 -050073/* Default initializations for TSEC controllers. */
74
75static struct tsec_info_struct tsec_info[] = {
76#ifdef CONFIG_TSEC1
77 STD_TSEC_INFO(1), /* TSEC1 */
78#endif
79#ifdef CONFIG_TSEC2
80 STD_TSEC_INFO(2), /* TSEC2 */
81#endif
82#ifdef CONFIG_MPC85XX_FEC
83 {
84 .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
85 .miiregs = (tsec_t *)(TSEC_BASE_ADDR),
86 .devname = CONFIG_MPC85XX_FEC_NAME,
87 .phyaddr = FEC_PHY_ADDR,
88 .flags = FEC_FLAGS
89 }, /* FEC */
90#endif
91#ifdef CONFIG_TSEC3
92 STD_TSEC_INFO(3), /* TSEC3 */
93#endif
94#ifdef CONFIG_TSEC4
95 STD_TSEC_INFO(4), /* TSEC4 */
96#endif
97};
98
99int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
100{
101 int i;
102
103 for (i = 0; i < num; i++)
104 tsec_initialize(bis, &tsecs[i]);
105
106 return 0;
107}
108
109int tsec_standard_init(bd_t *bis)
110{
111 return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
112}
113
wdenka445ddf2004-06-09 00:34:46 +0000114/* Initialize device structure. Returns success if PHY
115 * initialization succeeded (i.e. if it recognizes the PHY)
116 */
Andy Flemingfecff2b2008-08-31 16:33:26 -0500117int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
wdenk9c53f402003-10-15 23:53:47 +0000118{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500119 struct eth_device *dev;
wdenk9c53f402003-10-15 23:53:47 +0000120 int i;
wdenka445ddf2004-06-09 00:34:46 +0000121 struct tsec_private *priv;
wdenk9c53f402003-10-15 23:53:47 +0000122
Jon Loeligerb7ced082006-10-10 17:03:43 -0500123 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk9c53f402003-10-15 23:53:47 +0000124
Jon Loeligerb7ced082006-10-10 17:03:43 -0500125 if (NULL == dev)
wdenk9c53f402003-10-15 23:53:47 +0000126 return 0;
127
128 memset(dev, 0, sizeof *dev);
129
Jon Loeligerb7ced082006-10-10 17:03:43 -0500130 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenka445ddf2004-06-09 00:34:46 +0000131
Jon Loeligerb7ced082006-10-10 17:03:43 -0500132 if (NULL == priv)
wdenka445ddf2004-06-09 00:34:46 +0000133 return 0;
134
Andy Flemingfecff2b2008-08-31 16:33:26 -0500135 privlist[num_tsecs++] = priv;
136 priv->regs = tsec_info->regs;
137 priv->phyregs = tsec_info->miiregs;
wdenka445ddf2004-06-09 00:34:46 +0000138
Andy Flemingfecff2b2008-08-31 16:33:26 -0500139 priv->phyaddr = tsec_info->phyaddr;
140 priv->flags = tsec_info->flags;
wdenka445ddf2004-06-09 00:34:46 +0000141
Andy Flemingfecff2b2008-08-31 16:33:26 -0500142 sprintf(dev->name, tsec_info->devname);
wdenk9c53f402003-10-15 23:53:47 +0000143 dev->iobase = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500144 dev->priv = priv;
145 dev->init = tsec_init;
146 dev->halt = tsec_halt;
147 dev->send = tsec_send;
148 dev->recv = tsec_recv;
David Updegraff7280da72007-06-11 10:41:07 -0500149#ifdef CONFIG_MCAST_TFTP
150 dev->mcast = tsec_mcast_addr;
151#endif
wdenk9c53f402003-10-15 23:53:47 +0000152
153 /* Tell u-boot to get the addr from the env */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500154 for (i = 0; i < 6; i++)
wdenk9c53f402003-10-15 23:53:47 +0000155 dev->enetaddr[i] = 0;
156
157 eth_register(dev);
158
wdenka445ddf2004-06-09 00:34:46 +0000159 /* Reset the MAC */
160 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
Andy Fleming2d1db142009-02-03 18:26:41 -0600161 udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
wdenka445ddf2004-06-09 00:34:46 +0000162 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk78924a72004-04-18 21:45:42 +0000163
Jon Loeliger82ecaad2007-07-09 17:39:42 -0500164#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +0200165 && !defined(BITBANGMII)
166 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
167#endif
168
wdenka445ddf2004-06-09 00:34:46 +0000169 /* Try to initialize PHY here, and return */
170 return init_phy(dev);
wdenk9c53f402003-10-15 23:53:47 +0000171}
172
wdenk9c53f402003-10-15 23:53:47 +0000173/* Initializes data structures and registers for the controller,
wdenkbfad55d2005-03-14 23:56:42 +0000174 * and brings the interface up. Returns the link status, meaning
wdenka445ddf2004-06-09 00:34:46 +0000175 * that it returns success if the link is up, failure otherwise.
Jon Loeligerb7ced082006-10-10 17:03:43 -0500176 * This allows u-boot to find the first active controller.
177 */
178int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk9c53f402003-10-15 23:53:47 +0000179{
wdenk9c53f402003-10-15 23:53:47 +0000180 uint tempval;
181 char tmpbuf[MAC_ADDR_LEN];
182 int i;
wdenka445ddf2004-06-09 00:34:46 +0000183 struct tsec_private *priv = (struct tsec_private *)dev->priv;
184 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000185
186 /* Make sure the controller is stopped */
187 tsec_halt(dev);
188
wdenka445ddf2004-06-09 00:34:46 +0000189 /* Init MACCFG2. Defaults to GMII */
wdenk9c53f402003-10-15 23:53:47 +0000190 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
191
192 /* Init ECNTRL */
193 regs->ecntrl = ECNTRL_INIT_SETTINGS;
194
195 /* Copy the station address into the address registers.
196 * Backwards, because little endian MACS are dumb */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500197 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenka445ddf2004-06-09 00:34:46 +0000198 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk9c53f402003-10-15 23:53:47 +0000199 }
Kim Phillips4f8b6332009-07-17 12:17:00 -0500200 tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
201 tmpbuf[3];
202
203 regs->macstnaddr1 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000204
Jon Loeligerb7ced082006-10-10 17:03:43 -0500205 tempval = *((uint *) (tmpbuf + 4));
wdenk9c53f402003-10-15 23:53:47 +0000206
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200207 regs->macstnaddr2 = tempval;
wdenk9c53f402003-10-15 23:53:47 +0000208
wdenk9c53f402003-10-15 23:53:47 +0000209 /* reset the indices to zero */
210 rxIdx = 0;
211 txIdx = 0;
212
213 /* Clear out (for the most part) the other registers */
214 init_registers(regs);
215
216 /* Ready the device for tx/rx */
wdenka445ddf2004-06-09 00:34:46 +0000217 startup_tsec(dev);
wdenk9c53f402003-10-15 23:53:47 +0000218
wdenka445ddf2004-06-09 00:34:46 +0000219 /* If there's no link, fail */
Ben Warrende9fcb52008-01-09 18:15:53 -0500220 return (priv->link ? 0 : -1);
wdenka445ddf2004-06-09 00:34:46 +0000221}
wdenk9c53f402003-10-15 23:53:47 +0000222
Andy Flemingac65e072008-08-31 16:33:27 -0500223/* Writes the given phy's reg with value, using the specified MDIO regs */
224static void tsec_local_mdio_write(volatile tsec_t *phyregs, uint addr,
225 uint reg, uint value)
wdenka445ddf2004-06-09 00:34:46 +0000226{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500227 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000228
Andy Flemingac65e072008-08-31 16:33:27 -0500229 phyregs->miimadd = (addr << 8) | reg;
230 phyregs->miimcon = value;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500231 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000232
Jon Loeligerb7ced082006-10-10 17:03:43 -0500233 timeout = 1000000;
Andy Flemingac65e072008-08-31 16:33:27 -0500234 while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000235}
236
Andy Flemingac65e072008-08-31 16:33:27 -0500237
238/* Provide the default behavior of writing the PHY of this ethernet device */
239#define write_phy_reg(priv, regnum, value) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
michael.firth@bt.com08384842008-01-16 11:40:51 +0000240
wdenka445ddf2004-06-09 00:34:46 +0000241/* Reads register regnum on the device's PHY through the
Andy Flemingac65e072008-08-31 16:33:27 -0500242 * specified registers. It lowers and raises the read
wdenka445ddf2004-06-09 00:34:46 +0000243 * command, and waits for the data to become valid (miimind
244 * notvalid bit cleared), and the bus to cease activity (miimind
245 * busy bit cleared), and then returns the value
246 */
Andy Flemingac65e072008-08-31 16:33:27 -0500247uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum)
wdenk9c53f402003-10-15 23:53:47 +0000248{
249 uint value;
250
wdenka445ddf2004-06-09 00:34:46 +0000251 /* Put the address of the phy, and the register
252 * number into MIIMADD */
Andy Flemingac65e072008-08-31 16:33:27 -0500253 phyregs->miimadd = (phyid << 8) | regnum;
wdenk9c53f402003-10-15 23:53:47 +0000254
255 /* Clear the command register, and wait */
Andy Flemingac65e072008-08-31 16:33:27 -0500256 phyregs->miimcom = 0;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500257 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000258
259 /* Initiate a read command, and wait */
Andy Flemingac65e072008-08-31 16:33:27 -0500260 phyregs->miimcom = MIIM_READ_COMMAND;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500261 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000262
263 /* Wait for the the indication that the read is done */
Andy Flemingac65e072008-08-31 16:33:27 -0500264 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk9c53f402003-10-15 23:53:47 +0000265
266 /* Grab the value read from the PHY */
Andy Flemingac65e072008-08-31 16:33:27 -0500267 value = phyregs->miimstat;
wdenk9c53f402003-10-15 23:53:47 +0000268
269 return value;
270}
271
michael.firth@bt.com08384842008-01-16 11:40:51 +0000272/* #define to provide old read_phy_reg functionality without duplicating code */
Andy Flemingac65e072008-08-31 16:33:27 -0500273#define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
274
275#define TBIANA_SETTINGS ( \
276 TBIANA_ASYMMETRIC_PAUSE \
277 | TBIANA_SYMMETRIC_PAUSE \
278 | TBIANA_FULL_DUPLEX \
279 )
280
281#define TBICR_SETTINGS ( \
282 TBICR_PHY_RESET \
283 | TBICR_ANEG_ENABLE \
284 | TBICR_FULL_DUPLEX \
285 | TBICR_SPEED1_SET \
286 )
287/* Configure the TBI for SGMII operation */
288static void tsec_configure_serdes(struct tsec_private *priv)
289{
Peter Tysercb3d2de2008-09-16 10:04:47 -0500290 /* Access TBI PHY registers at given TSEC register offset as opposed to the
291 * register offset used for external PHY accesses */
292 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_ANA,
Andy Flemingac65e072008-08-31 16:33:27 -0500293 TBIANA_SETTINGS);
Peter Tysercb3d2de2008-09-16 10:04:47 -0500294 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_TBICON,
Andy Flemingac65e072008-08-31 16:33:27 -0500295 TBICON_CLK_SELECT);
Peter Tysercb3d2de2008-09-16 10:04:47 -0500296 tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_CR,
Andy Flemingac65e072008-08-31 16:33:27 -0500297 TBICR_SETTINGS);
298}
michael.firth@bt.com08384842008-01-16 11:40:51 +0000299
wdenka445ddf2004-06-09 00:34:46 +0000300/* Discover which PHY is attached to the device, and configure it
301 * properly. If the PHY is not recognized, then return 0
302 * (failure). Otherwise, return 1
303 */
304static int init_phy(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000305{
wdenka445ddf2004-06-09 00:34:46 +0000306 struct tsec_private *priv = (struct tsec_private *)dev->priv;
307 struct phy_info *curphy;
Andy Flemingac65e072008-08-31 16:33:27 -0500308 volatile tsec_t *phyregs = priv->phyregs;
309 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000310
311 /* Assign a Physical address to the TBI */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200312 regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
313 phyregs->tbipa = CONFIG_SYS_TBIPA_VALUE;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500314 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000315
316 /* Reset MII (due to new addresses) */
317 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500318 asm("sync");
wdenkf41ff3b2005-04-04 23:43:44 +0000319 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500320 asm("sync");
Jon Loeligerb7ced082006-10-10 17:03:43 -0500321 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk9c53f402003-10-15 23:53:47 +0000322
Jon Loeligerb7ced082006-10-10 17:03:43 -0500323 if (0 == relocated)
wdenka445ddf2004-06-09 00:34:46 +0000324 relocate_cmds();
wdenk9c53f402003-10-15 23:53:47 +0000325
wdenka445ddf2004-06-09 00:34:46 +0000326 /* Get the cmd structure corresponding to the attached
327 * PHY */
328 curphy = get_phy_info(dev);
wdenk9c53f402003-10-15 23:53:47 +0000329
Ben Warrenf11eefb2006-10-26 14:38:25 -0400330 if (curphy == NULL) {
331 priv->phyinfo = NULL;
wdenka445ddf2004-06-09 00:34:46 +0000332 printf("%s: No PHY found\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000333
wdenka445ddf2004-06-09 00:34:46 +0000334 return 0;
335 }
wdenk9c53f402003-10-15 23:53:47 +0000336
Andy Flemingac65e072008-08-31 16:33:27 -0500337 if (regs->ecntrl & ECNTRL_SGMII_MODE)
338 tsec_configure_serdes(priv);
339
wdenka445ddf2004-06-09 00:34:46 +0000340 priv->phyinfo = curphy;
wdenk9c53f402003-10-15 23:53:47 +0000341
wdenka445ddf2004-06-09 00:34:46 +0000342 phy_run_commands(priv, priv->phyinfo->config);
wdenk9c53f402003-10-15 23:53:47 +0000343
wdenka445ddf2004-06-09 00:34:46 +0000344 return 1;
345}
wdenk9c53f402003-10-15 23:53:47 +0000346
Jon Loeligerb7ced082006-10-10 17:03:43 -0500347/*
348 * Returns which value to write to the control register.
349 * For 10/100, the value is slightly different
350 */
351uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000352{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500353 if (priv->flags & TSEC_GIGABIT)
wdenka445ddf2004-06-09 00:34:46 +0000354 return MIIM_CONTROL_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000355 else
wdenka445ddf2004-06-09 00:34:46 +0000356 return MIIM_CR_INIT;
357}
wdenk9c53f402003-10-15 23:53:47 +0000358
Peter Tyser4c84fd52009-02-04 15:14:05 -0600359/*
360 * Wait for auto-negotiation to complete, then determine link
Jon Loeligerb7ced082006-10-10 17:03:43 -0500361 */
362uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000363{
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200364 /*
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500365 * Wait if the link is up, and autonegotiation is in progress
366 * (ie - we're capable and it's not done)
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200367 */
368 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Peter Tyser4c84fd52009-02-04 15:14:05 -0600369 if ((mii_reg & PHY_BMSR_AUTN_ABLE) && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200370 int i = 0;
wdenk9c53f402003-10-15 23:53:47 +0000371
Jon Loeligerb7ced082006-10-10 17:03:43 -0500372 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500373 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200374 /*
375 * Timeout reached ?
376 */
377 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500378 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200379 priv->link = 0;
Jin Zhengxiong-R64188487d2232006-06-27 18:12:23 +0800380 return 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200381 }
wdenk9c53f402003-10-15 23:53:47 +0000382
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200383 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500384 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200385 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500386 udelay(1000); /* 1 ms */
wdenka445ddf2004-06-09 00:34:46 +0000387 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200388 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500389 puts(" done\n");
Peter Tyser4c84fd52009-02-04 15:14:05 -0600390
391 /* Link status bit is latched low, read it again */
392 mii_reg = read_phy_reg(priv, MIIM_STATUS);
393
Jon Loeligerb7ced082006-10-10 17:03:43 -0500394 udelay(500000); /* another 500 ms (results in faster booting) */
wdenk9c53f402003-10-15 23:53:47 +0000395 }
396
Peter Tyser4c84fd52009-02-04 15:14:05 -0600397 priv->link = mii_reg & MIIM_STATUS_LINK ? 1 : 0;
398
wdenka445ddf2004-06-09 00:34:46 +0000399 return 0;
400}
401
David Updegraff0451b012007-04-20 14:34:48 -0500402/* Generic function which updates the speed and duplex. If
403 * autonegotiation is enabled, it uses the AND of the link
404 * partner's advertised capabilities and our advertised
405 * capabilities. If autonegotiation is disabled, we use the
406 * appropriate bits in the control register.
407 *
408 * Stolen from Linux's mii.c and phy_device.c
409 */
410uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
411{
412 /* We're using autonegotiation */
413 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
414 uint lpa = 0;
415 uint gblpa = 0;
416
417 /* Check for gigabit capability */
418 if (mii_reg & PHY_BMSR_EXT) {
419 /* We want a list of states supported by
420 * both PHYs in the link
421 */
422 gblpa = read_phy_reg(priv, PHY_1000BTSR);
423 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
424 }
425
426 /* Set the baseline so we only have to set them
427 * if they're different
428 */
429 priv->speed = 10;
430 priv->duplexity = 0;
431
432 /* Check the gigabit fields */
433 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
434 priv->speed = 1000;
435
436 if (gblpa & PHY_1000BTSR_1000FD)
437 priv->duplexity = 1;
438
439 /* We're done! */
440 return 0;
441 }
442
443 lpa = read_phy_reg(priv, PHY_ANAR);
444 lpa &= read_phy_reg(priv, PHY_ANLPAR);
445
446 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
447 priv->speed = 100;
448
449 if (lpa & PHY_ANLPAR_TXFD)
450 priv->duplexity = 1;
451
452 } else if (lpa & PHY_ANLPAR_10FD)
453 priv->duplexity = 1;
454 } else {
455 uint bmcr = read_phy_reg(priv, PHY_BMCR);
456
457 priv->speed = 10;
458 priv->duplexity = 0;
459
460 if (bmcr & PHY_BMCR_DPLX)
461 priv->duplexity = 1;
462
463 if (bmcr & PHY_BMCR_1000_MBPS)
464 priv->speed = 1000;
465 else if (bmcr & PHY_BMCR_100_MBPS)
466 priv->speed = 100;
467 }
468
469 return 0;
470}
471
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500472/*
Zach LeRoyddb7fc72009-05-22 10:26:33 -0500473 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
474 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
475 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
476 * link. "Ethernet@Wirespeed" reduces advertised speed until link
477 * can be achieved.
478 */
479uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
480{
481 return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
482}
483
484/*
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500485 * Parse the BCM54xx status register for speed and duplex information.
486 * The linux sungem_phy has this information, but in a table format.
487 */
488uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
489{
490
491 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
492
493 case 1:
494 printf("Enet starting in 10BT/HD\n");
495 priv->duplexity = 0;
496 priv->speed = 10;
497 break;
498
499 case 2:
500 printf("Enet starting in 10BT/FD\n");
501 priv->duplexity = 1;
502 priv->speed = 10;
503 break;
504
505 case 3:
506 printf("Enet starting in 100BT/HD\n");
507 priv->duplexity = 0;
508 priv->speed = 100;
509 break;
510
511 case 5:
512 printf("Enet starting in 100BT/FD\n");
513 priv->duplexity = 1;
514 priv->speed = 100;
515 break;
516
517 case 6:
518 printf("Enet starting in 1000BT/HD\n");
519 priv->duplexity = 0;
520 priv->speed = 1000;
521 break;
522
523 case 7:
524 printf("Enet starting in 1000BT/FD\n");
525 priv->duplexity = 1;
526 priv->speed = 1000;
527 break;
528
529 default:
530 printf("Auto-neg error, defaulting to 10BT/HD\n");
531 priv->duplexity = 0;
532 priv->speed = 10;
533 break;
534 }
535
536 return 0;
537
538}
wdenka445ddf2004-06-09 00:34:46 +0000539/* Parse the 88E1011's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500540 * information
541 */
542uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000543{
544 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000545
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200546 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
547
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500548 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
549 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200550 int i = 0;
551
Jon Loeligerb7ced082006-10-10 17:03:43 -0500552 puts("Waiting for PHY realtime link");
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500553 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
554 /* Timeout reached ? */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200555 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500556 puts(" TIMEOUT !\n");
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200557 priv->link = 0;
558 break;
559 }
560
561 if ((i++ % 1000) == 0) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500562 putc('.');
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200563 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500564 udelay(1000); /* 1 ms */
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200565 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
566 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500567 puts(" done\n");
568 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming4eb3dcf2007-08-15 20:03:44 -0500569 } else {
570 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
571 priv->link = 1;
572 else
573 priv->link = 0;
Stefan Roesec0dc34f2005-09-21 18:20:22 +0200574 }
575
Jon Loeligerb7ced082006-10-10 17:03:43 -0500576 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000577 priv->duplexity = 1;
578 else
579 priv->duplexity = 0;
580
Jon Loeligerb7ced082006-10-10 17:03:43 -0500581 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenka445ddf2004-06-09 00:34:46 +0000582
Jon Loeligerb7ced082006-10-10 17:03:43 -0500583 switch (speed) {
584 case MIIM_88E1011_PHYSTAT_GBIT:
585 priv->speed = 1000;
586 break;
587 case MIIM_88E1011_PHYSTAT_100:
588 priv->speed = 100;
589 break;
590 default:
591 priv->speed = 10;
wdenk9c53f402003-10-15 23:53:47 +0000592 }
593
wdenka445ddf2004-06-09 00:34:46 +0000594 return 0;
595}
596
Dave Liua304a282008-01-11 18:45:28 +0800597/* Parse the RTL8211B's status register for speed and duplex
598 * information
599 */
600uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
601{
602 uint speed;
603
604 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300605 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liua304a282008-01-11 18:45:28 +0800606 int i = 0;
607
Anton Vorontsov91112ec2008-03-14 23:20:30 +0300608 /* in case of timeout ->link is cleared */
609 priv->link = 1;
Dave Liua304a282008-01-11 18:45:28 +0800610 puts("Waiting for PHY realtime link");
611 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
612 /* Timeout reached ? */
613 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
614 puts(" TIMEOUT !\n");
615 priv->link = 0;
616 break;
617 }
618
619 if ((i++ % 1000) == 0) {
620 putc('.');
621 }
622 udelay(1000); /* 1 ms */
623 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
624 }
625 puts(" done\n");
626 udelay(500000); /* another 500 ms (results in faster booting) */
627 } else {
628 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
629 priv->link = 1;
630 else
631 priv->link = 0;
632 }
633
634 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
635 priv->duplexity = 1;
636 else
637 priv->duplexity = 0;
638
639 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
640
641 switch (speed) {
642 case MIIM_RTL8211B_PHYSTAT_GBIT:
643 priv->speed = 1000;
644 break;
645 case MIIM_RTL8211B_PHYSTAT_100:
646 priv->speed = 100;
647 break;
648 default:
649 priv->speed = 10;
650 }
651
652 return 0;
653}
654
wdenka445ddf2004-06-09 00:34:46 +0000655/* Parse the cis8201's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500656 * information
657 */
658uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000659{
660 uint speed;
661
Jon Loeligerb7ced082006-10-10 17:03:43 -0500662 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenka445ddf2004-06-09 00:34:46 +0000663 priv->duplexity = 1;
664 else
665 priv->duplexity = 0;
666
667 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500668 switch (speed) {
669 case MIIM_CIS8201_AUXCONSTAT_GBIT:
670 priv->speed = 1000;
671 break;
672 case MIIM_CIS8201_AUXCONSTAT_100:
673 priv->speed = 100;
674 break;
675 default:
676 priv->speed = 10;
677 break;
wdenk9c53f402003-10-15 23:53:47 +0000678 }
679
wdenka445ddf2004-06-09 00:34:46 +0000680 return 0;
681}
Jon Loeligerb7ced082006-10-10 17:03:43 -0500682
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500683/* Parse the vsc8244's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500684 * information
685 */
686uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500687{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500688 uint speed;
wdenk9c53f402003-10-15 23:53:47 +0000689
Jon Loeligerb7ced082006-10-10 17:03:43 -0500690 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
691 priv->duplexity = 1;
692 else
693 priv->duplexity = 0;
694
695 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
696 switch (speed) {
697 case MIIM_VSC8244_AUXCONSTAT_GBIT:
698 priv->speed = 1000;
699 break;
700 case MIIM_VSC8244_AUXCONSTAT_100:
701 priv->speed = 100;
702 break;
703 default:
704 priv->speed = 10;
705 break;
706 }
707
708 return 0;
709}
wdenka445ddf2004-06-09 00:34:46 +0000710
711/* Parse the DM9161's status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500712 * information
713 */
714uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000715{
Jon Loeligerb7ced082006-10-10 17:03:43 -0500716 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenka445ddf2004-06-09 00:34:46 +0000717 priv->speed = 100;
718 else
719 priv->speed = 10;
720
Jon Loeligerb7ced082006-10-10 17:03:43 -0500721 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenka445ddf2004-06-09 00:34:46 +0000722 priv->duplexity = 1;
723 else
724 priv->duplexity = 0;
725
726 return 0;
727}
728
Jon Loeligerb7ced082006-10-10 17:03:43 -0500729/*
730 * Hack to write all 4 PHYs with the LED values
731 */
732uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenka445ddf2004-06-09 00:34:46 +0000733{
734 uint phyid;
735 volatile tsec_t *regbase = priv->phyregs;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500736 int timeout = 1000000;
wdenka445ddf2004-06-09 00:34:46 +0000737
Jon Loeligerb7ced082006-10-10 17:03:43 -0500738 for (phyid = 0; phyid < 4; phyid++) {
wdenka445ddf2004-06-09 00:34:46 +0000739 regbase->miimadd = (phyid << 8) | mii_reg;
740 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Liberty9095d4a2005-07-28 10:08:46 -0500741 asm("sync");
wdenka445ddf2004-06-09 00:34:46 +0000742
Jon Loeligerb7ced082006-10-10 17:03:43 -0500743 timeout = 1000000;
744 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk9c53f402003-10-15 23:53:47 +0000745 }
wdenk9c53f402003-10-15 23:53:47 +0000746
wdenka445ddf2004-06-09 00:34:46 +0000747 return MIIM_CIS8204_SLEDCON_INIT;
wdenk9c53f402003-10-15 23:53:47 +0000748}
749
Jon Loeligerb7ced082006-10-10 17:03:43 -0500750uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500751{
752 if (priv->flags & TSEC_REDUCED)
753 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
754 else
755 return MIIM_CIS8204_EPHYCON_INIT;
756}
wdenk9c53f402003-10-15 23:53:47 +0000757
Dave Liub19ecd32007-09-18 12:37:57 +0800758uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
759{
760 uint mii_data = read_phy_reg(priv, mii_reg);
761
762 if (priv->flags & TSEC_REDUCED)
763 mii_data = (mii_data & 0xfff0) | 0x000b;
764 return mii_data;
765}
766
wdenka445ddf2004-06-09 00:34:46 +0000767/* Initialized required registers to appropriate values, zeroing
768 * those we don't care about (unless zero is bad, in which case,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500769 * choose a more appropriate value)
770 */
771static void init_registers(volatile tsec_t * regs)
wdenk9c53f402003-10-15 23:53:47 +0000772{
773 /* Clear IEVENT */
774 regs->ievent = IEVENT_INIT_CLEAR;
775
776 regs->imask = IMASK_INIT_CLEAR;
777
778 regs->hash.iaddr0 = 0;
779 regs->hash.iaddr1 = 0;
780 regs->hash.iaddr2 = 0;
781 regs->hash.iaddr3 = 0;
782 regs->hash.iaddr4 = 0;
783 regs->hash.iaddr5 = 0;
784 regs->hash.iaddr6 = 0;
785 regs->hash.iaddr7 = 0;
786
787 regs->hash.gaddr0 = 0;
788 regs->hash.gaddr1 = 0;
789 regs->hash.gaddr2 = 0;
790 regs->hash.gaddr3 = 0;
791 regs->hash.gaddr4 = 0;
792 regs->hash.gaddr5 = 0;
793 regs->hash.gaddr6 = 0;
794 regs->hash.gaddr7 = 0;
795
796 regs->rctrl = 0x00000000;
797
798 /* Init RMON mib registers */
799 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
800
801 regs->rmon.cam1 = 0xffffffff;
802 regs->rmon.cam2 = 0xffffffff;
803
804 regs->mrblr = MRBLR_INIT_SETTINGS;
805
806 regs->minflr = MINFLR_INIT_SETTINGS;
807
808 regs->attr = ATTR_INIT_SETTINGS;
809 regs->attreli = ATTRELI_INIT_SETTINGS;
810
wdenka445ddf2004-06-09 00:34:46 +0000811}
812
wdenka445ddf2004-06-09 00:34:46 +0000813/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -0500814 * reported by PHY handling code
815 */
wdenka445ddf2004-06-09 00:34:46 +0000816static void adjust_link(struct eth_device *dev)
817{
818 struct tsec_private *priv = (struct tsec_private *)dev->priv;
819 volatile tsec_t *regs = priv->regs;
820
Jon Loeligerb7ced082006-10-10 17:03:43 -0500821 if (priv->link) {
822 if (priv->duplexity != 0)
wdenka445ddf2004-06-09 00:34:46 +0000823 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
824 else
825 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
826
Jon Loeligerb7ced082006-10-10 17:03:43 -0500827 switch (priv->speed) {
828 case 1000:
829 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
830 | MACCFG2_GMII);
831 break;
832 case 100:
833 case 10:
834 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
835 | MACCFG2_MII);
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500836
Nick Spenceec9670b2006-09-07 07:39:46 -0700837 /* Set R100 bit in all modes although
838 * it is only used in RGMII mode
Jon Loeligerb7ced082006-10-10 17:03:43 -0500839 */
Nick Spenceec9670b2006-09-07 07:39:46 -0700840 if (priv->speed == 100)
Jon Loeligerb7ced082006-10-10 17:03:43 -0500841 regs->ecntrl |= ECNTRL_R100;
842 else
843 regs->ecntrl &= ~(ECNTRL_R100);
844 break;
845 default:
846 printf("%s: Speed was bad\n", dev->name);
847 break;
wdenka445ddf2004-06-09 00:34:46 +0000848 }
849
850 printf("Speed: %d, %s duplex\n", priv->speed,
Jon Loeligerb7ced082006-10-10 17:03:43 -0500851 (priv->duplexity) ? "full" : "half");
wdenka445ddf2004-06-09 00:34:46 +0000852
853 } else {
854 printf("%s: No link.\n", dev->name);
855 }
wdenk9c53f402003-10-15 23:53:47 +0000856}
857
wdenka445ddf2004-06-09 00:34:46 +0000858/* Set up the buffers and their descriptors, and bring up the
Jon Loeligerb7ced082006-10-10 17:03:43 -0500859 * interface
860 */
wdenka445ddf2004-06-09 00:34:46 +0000861static void startup_tsec(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000862{
863 int i;
wdenka445ddf2004-06-09 00:34:46 +0000864 struct tsec_private *priv = (struct tsec_private *)dev->priv;
865 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000866
867 /* Point to the buffer descriptors */
868 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
869 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
870
871 /* Initialize the Rx Buffer descriptors */
872 for (i = 0; i < PKTBUFSRX; i++) {
873 rtx.rxbd[i].status = RXBD_EMPTY;
874 rtx.rxbd[i].length = 0;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500875 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk9c53f402003-10-15 23:53:47 +0000876 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500877 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000878
879 /* Initialize the TX Buffer Descriptors */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500880 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000881 rtx.txbd[i].status = 0;
882 rtx.txbd[i].length = 0;
883 rtx.txbd[i].bufPtr = 0;
884 }
Jon Loeligerb7ced082006-10-10 17:03:43 -0500885 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk9c53f402003-10-15 23:53:47 +0000886
wdenka445ddf2004-06-09 00:34:46 +0000887 /* Start up the PHY */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400888 if(priv->phyinfo)
889 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraff0451b012007-04-20 14:34:48 -0500890
wdenka445ddf2004-06-09 00:34:46 +0000891 adjust_link(dev);
892
wdenk9c53f402003-10-15 23:53:47 +0000893 /* Enable Transmit and Receive */
894 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
895
896 /* Tell the DMA it is clear to go */
897 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
898 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilsone3d7d6b2007-10-19 11:33:48 -0500899 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk9c53f402003-10-15 23:53:47 +0000900 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
901}
902
wdenkbfad55d2005-03-14 23:56:42 +0000903/* This returns the status bits of the device. The return value
wdenk9c53f402003-10-15 23:53:47 +0000904 * is never checked, and this is what the 8260 driver did, so we
wdenkbfad55d2005-03-14 23:56:42 +0000905 * do the same. Presumably, this would be zero if there were no
Jon Loeligerb7ced082006-10-10 17:03:43 -0500906 * errors
907 */
908static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk9c53f402003-10-15 23:53:47 +0000909{
910 int i;
911 int result = 0;
wdenka445ddf2004-06-09 00:34:46 +0000912 struct tsec_private *priv = (struct tsec_private *)dev->priv;
913 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000914
915 /* Find an empty buffer descriptor */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500916 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000917 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500918 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000919 return result;
920 }
921 }
922
Jon Loeligerb7ced082006-10-10 17:03:43 -0500923 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk9c53f402003-10-15 23:53:47 +0000924 rtx.txbd[txIdx].length = length;
Jon Loeligerb7ced082006-10-10 17:03:43 -0500925 rtx.txbd[txIdx].status |=
926 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk9c53f402003-10-15 23:53:47 +0000927
928 /* Tell the DMA to go */
929 regs->tstat = TSTAT_CLEAR_THALT;
930
931 /* Wait for buffer to be transmitted */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500932 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk9c53f402003-10-15 23:53:47 +0000933 if (i >= TOUT_LOOP) {
Jon Loeligerb7ced082006-10-10 17:03:43 -0500934 debug("%s: tsec: tx error\n", dev->name);
wdenk9c53f402003-10-15 23:53:47 +0000935 return result;
936 }
937 }
938
939 txIdx = (txIdx + 1) % TX_BUF_CNT;
940 result = rtx.txbd[txIdx].status & TXBD_STATS;
941
942 return result;
943}
944
Jon Loeligerb7ced082006-10-10 17:03:43 -0500945static int tsec_recv(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000946{
947 int length;
wdenka445ddf2004-06-09 00:34:46 +0000948 struct tsec_private *priv = (struct tsec_private *)dev->priv;
949 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000950
Jon Loeligerb7ced082006-10-10 17:03:43 -0500951 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk9c53f402003-10-15 23:53:47 +0000952
953 length = rtx.rxbd[rxIdx].length;
954
955 /* Send the packet up if there were no errors */
956 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
957 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenka445ddf2004-06-09 00:34:46 +0000958 } else {
959 printf("Got error %x\n",
Jon Loeligerb7ced082006-10-10 17:03:43 -0500960 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk9c53f402003-10-15 23:53:47 +0000961 }
962
963 rtx.rxbd[rxIdx].length = 0;
964
965 /* Set the wrap bit if this is the last element in the list */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500966 rtx.rxbd[rxIdx].status =
967 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk9c53f402003-10-15 23:53:47 +0000968
969 rxIdx = (rxIdx + 1) % PKTBUFSRX;
970 }
971
Jon Loeligerb7ced082006-10-10 17:03:43 -0500972 if (regs->ievent & IEVENT_BSY) {
wdenk9c53f402003-10-15 23:53:47 +0000973 regs->ievent = IEVENT_BSY;
974 regs->rstat = RSTAT_CLEAR_RHALT;
975 }
976
977 return -1;
978
979}
980
wdenka445ddf2004-06-09 00:34:46 +0000981/* Stop the interface */
Jon Loeligerb7ced082006-10-10 17:03:43 -0500982static void tsec_halt(struct eth_device *dev)
wdenk9c53f402003-10-15 23:53:47 +0000983{
wdenka445ddf2004-06-09 00:34:46 +0000984 struct tsec_private *priv = (struct tsec_private *)dev->priv;
985 volatile tsec_t *regs = priv->regs;
wdenk9c53f402003-10-15 23:53:47 +0000986
987 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
988 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
989
Jon Loeligerb7ced082006-10-10 17:03:43 -0500990 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk9c53f402003-10-15 23:53:47 +0000991
992 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
993
wdenka445ddf2004-06-09 00:34:46 +0000994 /* Shut down the PHY, as needed */
Ben Warrenf11eefb2006-10-26 14:38:25 -0400995 if(priv->phyinfo)
996 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenka445ddf2004-06-09 00:34:46 +0000997}
998
Andy Flemingbee67002007-08-03 04:05:25 -0500999struct phy_info phy_info_M88E1149S = {
Wolfgang Denk15e87572007-08-06 01:01:49 +02001000 0x1410ca,
1001 "Marvell 88E1149S",
1002 4,
1003 (struct phy_cmd[]){ /* config */
1004 /* Reset and configure the PHY */
1005 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1006 {0x1d, 0x1f, NULL},
1007 {0x1e, 0x200c, NULL},
1008 {0x1d, 0x5, NULL},
1009 {0x1e, 0x0, NULL},
1010 {0x1e, 0x100, NULL},
1011 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1012 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1013 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1014 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1015 {miim_end,}
1016 },
1017 (struct phy_cmd[]){ /* startup */
1018 /* Status is read once to clear old link state */
1019 {MIIM_STATUS, miim_read, NULL},
1020 /* Auto-negotiate */
1021 {MIIM_STATUS, miim_read, &mii_parse_sr},
1022 /* Read the status */
1023 {MIIM_88E1011_PHY_STATUS, miim_read,
1024 &mii_parse_88E1011_psr},
1025 {miim_end,}
1026 },
1027 (struct phy_cmd[]){ /* shutdown */
1028 {miim_end,}
1029 },
Andy Flemingbee67002007-08-03 04:05:25 -05001030};
1031
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001032/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1033struct phy_info phy_info_BCM5461S = {
1034 0x02060c1, /* 5461 ID */
1035 "Broadcom BCM5461S",
1036 0, /* not clear to me what minor revisions we can shift away */
1037 (struct phy_cmd[]) { /* config */
1038 /* Reset and configure the PHY */
1039 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1040 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1041 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1042 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1043 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1044 {miim_end,}
1045 },
1046 (struct phy_cmd[]) { /* startup */
1047 /* Status is read once to clear old link state */
1048 {MIIM_STATUS, miim_read, NULL},
1049 /* Auto-negotiate */
1050 {MIIM_STATUS, miim_read, &mii_parse_sr},
1051 /* Read the status */
1052 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1053 {miim_end,}
1054 },
1055 (struct phy_cmd[]) { /* shutdown */
1056 {miim_end,}
1057 },
1058};
1059
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001060struct phy_info phy_info_BCM5464S = {
1061 0x02060b1, /* 5464 ID */
1062 "Broadcom BCM5464S",
1063 0, /* not clear to me what minor revisions we can shift away */
1064 (struct phy_cmd[]) { /* config */
1065 /* Reset and configure the PHY */
1066 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1067 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1068 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1069 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001070 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1071 {miim_end,}
1072 },
1073 (struct phy_cmd[]) { /* startup */
1074 /* Status is read once to clear old link state */
1075 {MIIM_STATUS, miim_read, NULL},
1076 /* Auto-negotiate */
1077 {MIIM_STATUS, miim_read, &mii_parse_sr},
1078 /* Read the status */
1079 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1080 {miim_end,}
1081 },
1082 (struct phy_cmd[]) { /* shutdown */
1083 {miim_end,}
1084 },
1085};
1086
1087struct phy_info phy_info_BCM5482S = {
1088 0x0143bcb,
1089 "Broadcom BCM5482S",
1090 4,
1091 (struct phy_cmd[]) { /* config */
1092 /* Reset and configure the PHY */
1093 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1094 /* Setup read from auxilary control shadow register 7 */
1095 {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
1096 /* Read Misc Control register and or in Ethernet@Wirespeed */
1097 {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001098 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1099 {miim_end,}
1100 },
1101 (struct phy_cmd[]) { /* startup */
1102 /* Status is read once to clear old link state */
1103 {MIIM_STATUS, miim_read, NULL},
1104 /* Auto-negotiate */
1105 {MIIM_STATUS, miim_read, &mii_parse_sr},
1106 /* Read the status */
1107 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1108 {miim_end,}
1109 },
1110 (struct phy_cmd[]) { /* shutdown */
1111 {miim_end,}
1112 },
1113};
1114
wdenka445ddf2004-06-09 00:34:46 +00001115struct phy_info phy_info_M88E1011S = {
1116 0x01410c6,
1117 "Marvell 88E1011S",
1118 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001119 (struct phy_cmd[]){ /* config */
1120 /* Reset and configure the PHY */
1121 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1122 {0x1d, 0x1f, NULL},
1123 {0x1e, 0x200c, NULL},
1124 {0x1d, 0x5, NULL},
1125 {0x1e, 0x0, NULL},
1126 {0x1e, 0x100, NULL},
1127 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1128 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1129 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1130 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1131 {miim_end,}
1132 },
1133 (struct phy_cmd[]){ /* startup */
1134 /* Status is read once to clear old link state */
1135 {MIIM_STATUS, miim_read, NULL},
1136 /* Auto-negotiate */
1137 {MIIM_STATUS, miim_read, &mii_parse_sr},
1138 /* Read the status */
1139 {MIIM_88E1011_PHY_STATUS, miim_read,
1140 &mii_parse_88E1011_psr},
1141 {miim_end,}
1142 },
1143 (struct phy_cmd[]){ /* shutdown */
1144 {miim_end,}
1145 },
wdenka445ddf2004-06-09 00:34:46 +00001146};
1147
wdenkbfad55d2005-03-14 23:56:42 +00001148struct phy_info phy_info_M88E1111S = {
1149 0x01410cc,
1150 "Marvell 88E1111S",
1151 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001152 (struct phy_cmd[]){ /* config */
1153 /* Reset and configure the PHY */
1154 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Dave Liub19ecd32007-09-18 12:37:57 +08001155 {0x1b, 0x848f, &mii_m88e1111s_setmode},
Nick Spenceec9670b2006-09-07 07:39:46 -07001156 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001157 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1158 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1159 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1160 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1161 {miim_end,}
1162 },
1163 (struct phy_cmd[]){ /* startup */
1164 /* Status is read once to clear old link state */
1165 {MIIM_STATUS, miim_read, NULL},
1166 /* Auto-negotiate */
1167 {MIIM_STATUS, miim_read, &mii_parse_sr},
1168 /* Read the status */
1169 {MIIM_88E1011_PHY_STATUS, miim_read,
1170 &mii_parse_88E1011_psr},
1171 {miim_end,}
1172 },
1173 (struct phy_cmd[]){ /* shutdown */
1174 {miim_end,}
1175 },
wdenkbfad55d2005-03-14 23:56:42 +00001176};
1177
Ron Madridc1e2b582008-05-23 15:37:05 -07001178struct phy_info phy_info_M88E1118 = {
1179 0x01410e1,
1180 "Marvell 88E1118",
1181 4,
1182 (struct phy_cmd[]){ /* config */
1183 /* Reset and configure the PHY */
1184 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1185 {0x16, 0x0002, NULL}, /* Change Page Number */
1186 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
Ron Madridaa4aac42009-01-28 16:17:21 -08001187 {0x16, 0x0003, NULL}, /* Change Page Number */
1188 {0x10, 0x021e, NULL}, /* Adjust LED control */
1189 {0x16, 0x0000, NULL}, /* Change Page Number */
Ron Madridc1e2b582008-05-23 15:37:05 -07001190 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1191 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1192 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1193 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1194 {miim_end,}
1195 },
1196 (struct phy_cmd[]){ /* startup */
1197 {0x16, 0x0000, NULL}, /* Change Page Number */
1198 /* Status is read once to clear old link state */
1199 {MIIM_STATUS, miim_read, NULL},
1200 /* Auto-negotiate */
Ron Madridaa4aac42009-01-28 16:17:21 -08001201 {MIIM_STATUS, miim_read, &mii_parse_sr},
Ron Madridc1e2b582008-05-23 15:37:05 -07001202 /* Read the status */
1203 {MIIM_88E1011_PHY_STATUS, miim_read,
1204 &mii_parse_88E1011_psr},
1205 {miim_end,}
1206 },
1207 (struct phy_cmd[]){ /* shutdown */
1208 {miim_end,}
1209 },
1210};
1211
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001212/*
1213 * Since to access LED register we need do switch the page, we
1214 * do LED configuring in the miim_read-like function as follows
1215 */
1216uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1217{
1218 uint pg;
1219
1220 /* Switch the page to access the led register */
1221 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1222 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1223
1224 /* Configure leds */
1225 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1226 MIIM_88E1121_PHY_LED_DEF);
1227
1228 /* Restore the page pointer */
1229 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1230 return 0;
1231}
1232
1233struct phy_info phy_info_M88E1121R = {
1234 0x01410cb,
1235 "Marvell 88E1121R",
1236 4,
1237 (struct phy_cmd[]){ /* config */
1238 /* Reset and configure the PHY */
1239 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1240 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1241 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1242 /* Configure leds */
1243 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1244 &mii_88E1121_set_led},
1245 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Anatolij Gustschind015a022008-12-02 10:31:04 +01001246 /* Disable IRQs and de-assert interrupt */
1247 {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
1248 {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001249 {miim_end,}
1250 },
1251 (struct phy_cmd[]){ /* startup */
1252 /* Status is read once to clear old link state */
1253 {MIIM_STATUS, miim_read, NULL},
1254 {MIIM_STATUS, miim_read, &mii_parse_sr},
1255 {MIIM_STATUS, miim_read, &mii_parse_link},
1256 {miim_end,}
1257 },
1258 (struct phy_cmd[]){ /* shutdown */
1259 {miim_end,}
1260 },
1261};
1262
Andy Fleming239e75f2006-09-13 10:34:18 -05001263static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1264{
Andy Fleming239e75f2006-09-13 10:34:18 -05001265 uint mii_data = read_phy_reg(priv, mii_reg);
1266
Andy Fleming239e75f2006-09-13 10:34:18 -05001267 /* Setting MIIM_88E1145_PHY_EXT_CR */
1268 if (priv->flags & TSEC_REDUCED)
1269 return mii_data |
Jon Loeligerb7ced082006-10-10 17:03:43 -05001270 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming239e75f2006-09-13 10:34:18 -05001271 else
1272 return mii_data;
1273}
1274
1275static struct phy_info phy_info_M88E1145 = {
1276 0x01410cd,
1277 "Marvell 88E1145",
1278 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001279 (struct phy_cmd[]){ /* config */
Andy Fleming180d03a2007-05-08 17:23:02 -05001280 /* Reset the PHY */
1281 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1282
Jon Loeligerb7ced082006-10-10 17:03:43 -05001283 /* Errata E0, E1 */
1284 {29, 0x001b, NULL},
1285 {30, 0x418f, NULL},
1286 {29, 0x0016, NULL},
1287 {30, 0xa2da, NULL},
Andy Fleming239e75f2006-09-13 10:34:18 -05001288
Andy Fleming180d03a2007-05-08 17:23:02 -05001289 /* Configure the PHY */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001290 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1291 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1292 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1293 NULL},
1294 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1295 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1296 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1297 {miim_end,}
1298 },
1299 (struct phy_cmd[]){ /* startup */
1300 /* Status is read once to clear old link state */
1301 {MIIM_STATUS, miim_read, NULL},
1302 /* Auto-negotiate */
1303 {MIIM_STATUS, miim_read, &mii_parse_sr},
1304 {MIIM_88E1111_PHY_LED_CONTROL,
1305 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1306 /* Read the Status */
1307 {MIIM_88E1011_PHY_STATUS, miim_read,
1308 &mii_parse_88E1011_psr},
1309 {miim_end,}
1310 },
1311 (struct phy_cmd[]){ /* shutdown */
1312 {miim_end,}
1313 },
Andy Fleming239e75f2006-09-13 10:34:18 -05001314};
1315
wdenka445ddf2004-06-09 00:34:46 +00001316struct phy_info phy_info_cis8204 = {
1317 0x3f11,
1318 "Cicada Cis8204",
1319 6,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001320 (struct phy_cmd[]){ /* config */
1321 /* Override PHY config settings */
1322 {MIIM_CIS8201_AUX_CONSTAT,
1323 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1324 /* Configure some basic stuff */
1325 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1326 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1327 &mii_cis8204_fixled},
1328 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1329 &mii_cis8204_setmode},
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_CIS8201_AUX_CONSTAT, miim_read,
1339 &mii_parse_cis8201},
1340 {miim_end,}
1341 },
1342 (struct phy_cmd[]){ /* shutdown */
1343 {miim_end,}
1344 },
wdenka445ddf2004-06-09 00:34:46 +00001345};
1346
1347/* Cicada 8201 */
1348struct phy_info phy_info_cis8201 = {
1349 0xfc41,
1350 "CIS8201",
1351 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001352 (struct phy_cmd[]){ /* config */
1353 /* Override PHY config settings */
1354 {MIIM_CIS8201_AUX_CONSTAT,
1355 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1356 /* Set up the interface mode */
1357 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1358 NULL},
1359 /* Configure some basic stuff */
1360 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1361 {miim_end,}
1362 },
1363 (struct phy_cmd[]){ /* startup */
1364 /* Read the Status (2x to make sure link is right) */
1365 {MIIM_STATUS, miim_read, NULL},
1366 /* Auto-negotiate */
1367 {MIIM_STATUS, miim_read, &mii_parse_sr},
1368 /* Read the status */
1369 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1370 &mii_parse_cis8201},
1371 {miim_end,}
1372 },
1373 (struct phy_cmd[]){ /* shutdown */
1374 {miim_end,}
1375 },
wdenka445ddf2004-06-09 00:34:46 +00001376};
Pieter Henning9370c8b2009-02-22 23:17:15 -08001377struct phy_info phy_info_VSC8211 = {
1378 0xfc4b,
1379 "Vitesse VSC8211",
1380 4,
1381 (struct phy_cmd[]) { /* config */
1382 /* Override PHY config settings */
1383 {MIIM_CIS8201_AUX_CONSTAT,
1384 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1385 /* Set up the interface mode */
1386 {MIIM_CIS8201_EXT_CON1,
1387 MIIM_CIS8201_EXTCON1_INIT, NULL},
1388 /* Configure some basic stuff */
1389 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1390 {miim_end,}
1391 },
1392 (struct phy_cmd[]) { /* startup */
1393 /* Read the Status (2x to make sure link is right) */
1394 {MIIM_STATUS, miim_read, NULL},
1395 /* Auto-negotiate */
1396 {MIIM_STATUS, miim_read, &mii_parse_sr},
1397 /* Read the status */
1398 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1399 &mii_parse_cis8201},
1400 {miim_end,}
1401 },
1402 (struct phy_cmd[]) { /* shutdown */
1403 {miim_end,}
1404 },
1405};
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001406struct phy_info phy_info_VSC8244 = {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001407 0x3f1b,
1408 "Vitesse VSC8244",
1409 6,
1410 (struct phy_cmd[]){ /* config */
1411 /* Override PHY config settings */
1412 /* Configure some basic stuff */
1413 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1414 {miim_end,}
1415 },
1416 (struct phy_cmd[]){ /* startup */
1417 /* Read the Status (2x to make sure link is right) */
1418 {MIIM_STATUS, miim_read, NULL},
1419 /* Auto-negotiate */
1420 {MIIM_STATUS, miim_read, &mii_parse_sr},
1421 /* Read the status */
1422 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1423 &mii_parse_vsc8244},
1424 {miim_end,}
1425 },
1426 (struct phy_cmd[]){ /* shutdown */
1427 {miim_end,}
1428 },
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001429};
wdenka445ddf2004-06-09 00:34:46 +00001430
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301431struct phy_info phy_info_VSC8641 = {
1432 0x7043,
1433 "Vitesse VSC8641",
1434 4,
1435 (struct phy_cmd[]){ /* config */
1436 /* Configure some basic stuff */
1437 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1438 {miim_end,}
1439 },
1440 (struct phy_cmd[]){ /* startup */
1441 /* Read the Status (2x to make sure link is right) */
1442 {MIIM_STATUS, miim_read, NULL},
1443 /* Auto-negotiate */
1444 {MIIM_STATUS, miim_read, &mii_parse_sr},
1445 /* Read the status */
1446 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1447 &mii_parse_vsc8244},
1448 {miim_end,}
1449 },
1450 (struct phy_cmd[]){ /* shutdown */
1451 {miim_end,}
1452 },
1453};
1454
1455struct phy_info phy_info_VSC8221 = {
1456 0xfc55,
1457 "Vitesse VSC8221",
1458 4,
1459 (struct phy_cmd[]){ /* config */
1460 /* Configure some basic stuff */
1461 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1462 {miim_end,}
1463 },
1464 (struct phy_cmd[]){ /* startup */
1465 /* Read the Status (2x to make sure link is right) */
1466 {MIIM_STATUS, miim_read, NULL},
1467 /* Auto-negotiate */
1468 {MIIM_STATUS, miim_read, &mii_parse_sr},
1469 /* Read the status */
1470 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1471 &mii_parse_vsc8244},
1472 {miim_end,}
1473 },
1474 (struct phy_cmd[]){ /* shutdown */
1475 {miim_end,}
1476 },
1477};
1478
Tor Krill8b3a82f2008-03-28 15:29:45 +01001479struct phy_info phy_info_VSC8601 = {
1480 0x00007042,
1481 "Vitesse VSC8601",
1482 4,
1483 (struct phy_cmd[]){ /* config */
1484 /* Override PHY config settings */
1485 /* Configure some basic stuff */
1486 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001487#ifdef CONFIG_SYS_VSC8601_SKEWFIX
Tor Krill8b3a82f2008-03-28 15:29:45 +01001488 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001489#if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
Andre Schwarz1e18be12008-04-29 19:18:32 +02001490 {MIIM_EXT_PAGE_ACCESS,1,NULL},
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001491#define VSC8101_SKEW (CONFIG_SYS_VSC8601_SKEW_TX<<14)|(CONFIG_SYS_VSC8601_SKEW_RX<<12)
Andre Schwarz1e18be12008-04-29 19:18:32 +02001492 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1493 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1494#endif
Tor Krill8b3a82f2008-03-28 15:29:45 +01001495#endif
Andre Schwarz4005e3b2008-08-19 16:07:03 +02001496 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1497 {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
Tor Krill8b3a82f2008-03-28 15:29:45 +01001498 {miim_end,}
1499 },
1500 (struct phy_cmd[]){ /* startup */
1501 /* Read the Status (2x to make sure link is right) */
1502 {MIIM_STATUS, miim_read, NULL},
1503 /* Auto-negotiate */
1504 {MIIM_STATUS, miim_read, &mii_parse_sr},
1505 /* Read the status */
1506 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1507 &mii_parse_vsc8244},
1508 {miim_end,}
1509 },
1510 (struct phy_cmd[]){ /* shutdown */
1511 {miim_end,}
1512 },
1513};
1514
1515
wdenka445ddf2004-06-09 00:34:46 +00001516struct phy_info phy_info_dm9161 = {
1517 0x0181b88,
1518 "Davicom DM9161E",
1519 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001520 (struct phy_cmd[]){ /* config */
1521 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1522 /* Do not bypass the scrambler/descrambler */
1523 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1524 /* Clear 10BTCSR to default */
1525 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1526 NULL},
1527 /* Configure some basic stuff */
1528 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1529 /* Restart Auto Negotiation */
1530 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1531 {miim_end,}
1532 },
1533 (struct phy_cmd[]){ /* startup */
1534 /* Status is read once to clear old link state */
1535 {MIIM_STATUS, miim_read, NULL},
1536 /* Auto-negotiate */
1537 {MIIM_STATUS, miim_read, &mii_parse_sr},
1538 /* Read the status */
1539 {MIIM_DM9161_SCSR, miim_read,
1540 &mii_parse_dm9161_scsr},
1541 {miim_end,}
1542 },
1543 (struct phy_cmd[]){ /* shutdown */
1544 {miim_end,}
1545 },
wdenka445ddf2004-06-09 00:34:46 +00001546};
David Updegraff0451b012007-04-20 14:34:48 -05001547/* a generic flavor. */
1548struct phy_info phy_info_generic = {
1549 0,
1550 "Unknown/Generic PHY",
1551 32,
1552 (struct phy_cmd[]) { /* config */
1553 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1554 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1555 {miim_end,}
1556 },
1557 (struct phy_cmd[]) { /* startup */
1558 {PHY_BMSR, miim_read, NULL},
1559 {PHY_BMSR, miim_read, &mii_parse_sr},
1560 {PHY_BMSR, miim_read, &mii_parse_link},
1561 {miim_end,}
1562 },
1563 (struct phy_cmd[]) { /* shutdown */
1564 {miim_end,}
1565 }
1566};
1567
wdenka445ddf2004-06-09 00:34:46 +00001568
wdenkf41ff3b2005-04-04 23:43:44 +00001569uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1570{
wdenke085e5b2005-04-05 23:32:21 +00001571 unsigned int speed;
1572 if (priv->link) {
1573 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenkf41ff3b2005-04-04 23:43:44 +00001574
wdenke085e5b2005-04-05 23:32:21 +00001575 switch (speed) {
1576 case MIIM_LXT971_SR2_10HDX:
1577 priv->speed = 10;
1578 priv->duplexity = 0;
1579 break;
1580 case MIIM_LXT971_SR2_10FDX:
1581 priv->speed = 10;
1582 priv->duplexity = 1;
1583 break;
1584 case MIIM_LXT971_SR2_100HDX:
1585 priv->speed = 100;
1586 priv->duplexity = 0;
urwithsughosh@gmail.com34b3f2e2007-09-10 14:54:56 -04001587 break;
wdenke085e5b2005-04-05 23:32:21 +00001588 default:
1589 priv->speed = 100;
1590 priv->duplexity = 1;
wdenke085e5b2005-04-05 23:32:21 +00001591 }
1592 } else {
1593 priv->speed = 0;
1594 priv->duplexity = 0;
1595 }
wdenkf41ff3b2005-04-04 23:43:44 +00001596
wdenke085e5b2005-04-05 23:32:21 +00001597 return 0;
wdenkf41ff3b2005-04-04 23:43:44 +00001598}
1599
wdenkbfad55d2005-03-14 23:56:42 +00001600static struct phy_info phy_info_lxt971 = {
1601 0x0001378e,
1602 "LXT971",
1603 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001604 (struct phy_cmd[]){ /* config */
1605 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1606 {miim_end,}
1607 },
1608 (struct phy_cmd[]){ /* startup - enable interrupts */
1609 /* { 0x12, 0x00f2, NULL }, */
1610 {MIIM_STATUS, miim_read, NULL},
1611 {MIIM_STATUS, miim_read, &mii_parse_sr},
1612 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1613 {miim_end,}
1614 },
1615 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1616 {miim_end,}
1617 },
wdenkbfad55d2005-03-14 23:56:42 +00001618};
1619
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001620/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeligerb7ced082006-10-10 17:03:43 -05001621 * information
1622 */
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001623uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1624{
1625 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1626
1627 case MIIM_DP83865_SPD_1000:
1628 priv->speed = 1000;
1629 break;
1630
1631 case MIIM_DP83865_SPD_100:
1632 priv->speed = 100;
1633 break;
1634
1635 default:
1636 priv->speed = 10;
1637 break;
1638
1639 }
1640
1641 if (mii_reg & MIIM_DP83865_DPX_FULL)
1642 priv->duplexity = 1;
1643 else
1644 priv->duplexity = 0;
1645
1646 return 0;
1647}
1648
1649struct phy_info phy_info_dp83865 = {
1650 0x20005c7,
1651 "NatSemi DP83865",
1652 4,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001653 (struct phy_cmd[]){ /* config */
1654 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1655 {miim_end,}
1656 },
1657 (struct phy_cmd[]){ /* startup */
1658 /* Status is read once to clear old link state */
1659 {MIIM_STATUS, miim_read, NULL},
1660 /* Auto-negotiate */
1661 {MIIM_STATUS, miim_read, &mii_parse_sr},
1662 /* Read the link and auto-neg status */
1663 {MIIM_DP83865_LANR, miim_read,
1664 &mii_parse_dp83865_lanr},
1665 {miim_end,}
1666 },
1667 (struct phy_cmd[]){ /* shutdown */
1668 {miim_end,}
1669 },
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001670};
1671
Dave Liua304a282008-01-11 18:45:28 +08001672struct phy_info phy_info_rtl8211b = {
1673 0x001cc91,
1674 "RealTek RTL8211B",
1675 4,
1676 (struct phy_cmd[]){ /* config */
1677 /* Reset and configure the PHY */
1678 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1679 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1680 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1681 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1682 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1683 {miim_end,}
1684 },
1685 (struct phy_cmd[]){ /* startup */
1686 /* Status is read once to clear old link state */
1687 {MIIM_STATUS, miim_read, NULL},
1688 /* Auto-negotiate */
1689 {MIIM_STATUS, miim_read, &mii_parse_sr},
1690 /* Read the status */
1691 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1692 {miim_end,}
1693 },
1694 (struct phy_cmd[]){ /* shutdown */
1695 {miim_end,}
1696 },
1697};
1698
wdenka445ddf2004-06-09 00:34:46 +00001699struct phy_info *phy_info[] = {
wdenka445ddf2004-06-09 00:34:46 +00001700 &phy_info_cis8204,
Timur Tabi054838e2006-10-31 18:44:42 -06001701 &phy_info_cis8201,
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -05001702 &phy_info_BCM5461S,
Joe Hammaned7ad4e2007-04-30 16:47:28 -05001703 &phy_info_BCM5464S,
Zach LeRoyddb7fc72009-05-22 10:26:33 -05001704 &phy_info_BCM5482S,
wdenka445ddf2004-06-09 00:34:46 +00001705 &phy_info_M88E1011S,
wdenkbfad55d2005-03-14 23:56:42 +00001706 &phy_info_M88E1111S,
Ron Madridc1e2b582008-05-23 15:37:05 -07001707 &phy_info_M88E1118,
Sergei Poselenov7d4a2c32008-06-06 15:52:44 +02001708 &phy_info_M88E1121R,
Andy Fleming239e75f2006-09-13 10:34:18 -05001709 &phy_info_M88E1145,
Wolfgang Denk15e87572007-08-06 01:01:49 +02001710 &phy_info_M88E1149S,
wdenka445ddf2004-06-09 00:34:46 +00001711 &phy_info_dm9161,
wdenkbfad55d2005-03-14 23:56:42 +00001712 &phy_info_lxt971,
Pieter Henning9370c8b2009-02-22 23:17:15 -08001713 &phy_info_VSC8211,
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001714 &phy_info_VSC8244,
Tor Krill8b3a82f2008-03-28 15:29:45 +01001715 &phy_info_VSC8601,
Poonam Aggrwalc91b5de2009-07-02 16:15:13 +05301716 &phy_info_VSC8641,
1717 &phy_info_VSC8221,
Wolfgang Denkf0c4e462006-03-12 22:50:55 +01001718 &phy_info_dp83865,
Dave Liua304a282008-01-11 18:45:28 +08001719 &phy_info_rtl8211b,
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001720 &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
wdenka445ddf2004-06-09 00:34:46 +00001721 NULL
1722};
1723
wdenka445ddf2004-06-09 00:34:46 +00001724/* Grab the identifier of the device's PHY, and search through
wdenkbfad55d2005-03-14 23:56:42 +00001725 * all of the known PHYs to see if one matches. If so, return
Jon Loeligerb7ced082006-10-10 17:03:43 -05001726 * it, if not, return NULL
1727 */
1728struct phy_info *get_phy_info(struct eth_device *dev)
wdenka445ddf2004-06-09 00:34:46 +00001729{
1730 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1731 uint phy_reg, phy_ID;
1732 int i;
1733 struct phy_info *theInfo = NULL;
1734
1735 /* Grab the bits from PHYIR1, and put them in the upper half */
1736 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1737 phy_ID = (phy_reg & 0xffff) << 16;
1738
1739 /* Grab the bits from PHYIR2, and put them in the lower half */
1740 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1741 phy_ID |= (phy_reg & 0xffff);
1742
1743 /* loop through all the known PHY types, and find one that */
1744 /* matches the ID we read from the PHY. */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001745 for (i = 0; phy_info[i]; i++) {
Andy Flemingb2d14f42007-05-09 00:54:20 -05001746 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenka445ddf2004-06-09 00:34:46 +00001747 theInfo = phy_info[i];
Andy Flemingb2d14f42007-05-09 00:54:20 -05001748 break;
1749 }
wdenka445ddf2004-06-09 00:34:46 +00001750 }
1751
Paul Gortmakerf81b8232009-03-09 18:07:53 -05001752 if (theInfo == &phy_info_generic) {
1753 printf("%s: No support for PHY id %x; assuming generic\n", dev->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001754 } else {
Stefan Roesec0dc34f2005-09-21 18:20:22 +02001755 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenka445ddf2004-06-09 00:34:46 +00001756 }
1757
1758 return theInfo;
1759}
1760
wdenka445ddf2004-06-09 00:34:46 +00001761/* Execute the given series of commands on the given device's
Jon Loeligerb7ced082006-10-10 17:03:43 -05001762 * PHY, running functions as necessary
1763 */
wdenka445ddf2004-06-09 00:34:46 +00001764void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1765{
1766 int i;
1767 uint result;
1768 volatile tsec_t *phyregs = priv->phyregs;
1769
1770 phyregs->miimcfg = MIIMCFG_RESET;
1771
1772 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1773
Jon Loeligerb7ced082006-10-10 17:03:43 -05001774 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenka445ddf2004-06-09 00:34:46 +00001775
Jon Loeligerb7ced082006-10-10 17:03:43 -05001776 for (i = 0; cmd->mii_reg != miim_end; i++) {
1777 if (cmd->mii_data == miim_read) {
wdenka445ddf2004-06-09 00:34:46 +00001778 result = read_phy_reg(priv, cmd->mii_reg);
1779
Jon Loeligerb7ced082006-10-10 17:03:43 -05001780 if (cmd->funct != NULL)
1781 (*(cmd->funct)) (result, priv);
wdenka445ddf2004-06-09 00:34:46 +00001782
1783 } else {
Jon Loeligerb7ced082006-10-10 17:03:43 -05001784 if (cmd->funct != NULL)
1785 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenka445ddf2004-06-09 00:34:46 +00001786 else
1787 result = cmd->mii_data;
1788
1789 write_phy_reg(priv, cmd->mii_reg, result);
1790
1791 }
1792 cmd++;
1793 }
1794}
1795
wdenka445ddf2004-06-09 00:34:46 +00001796/* Relocate the function pointers in the phy cmd lists */
1797static void relocate_cmds(void)
1798{
1799 struct phy_cmd **cmdlistptr;
1800 struct phy_cmd *cmd;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001801 int i, j, k;
wdenka445ddf2004-06-09 00:34:46 +00001802
Jon Loeligerb7ced082006-10-10 17:03:43 -05001803 for (i = 0; phy_info[i]; i++) {
wdenka445ddf2004-06-09 00:34:46 +00001804 /* First thing's first: relocate the pointers to the
1805 * PHY command structures (the structs were done) */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001806 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1807 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001808 phy_info[i]->name += gd->reloc_off;
1809 phy_info[i]->config =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001810 (struct phy_cmd *)((uint) phy_info[i]->config
1811 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001812 phy_info[i]->startup =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001813 (struct phy_cmd *)((uint) phy_info[i]->startup
1814 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001815 phy_info[i]->shutdown =
Jon Loeligerb7ced082006-10-10 17:03:43 -05001816 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1817 + gd->reloc_off);
wdenka445ddf2004-06-09 00:34:46 +00001818
1819 cmdlistptr = &phy_info[i]->config;
Jon Loeligerb7ced082006-10-10 17:03:43 -05001820 j = 0;
1821 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1822 k = 0;
1823 for (cmd = *cmdlistptr;
1824 cmd->mii_reg != miim_end;
1825 cmd++) {
wdenka445ddf2004-06-09 00:34:46 +00001826 /* Only relocate non-NULL pointers */
Jon Loeligerb7ced082006-10-10 17:03:43 -05001827 if (cmd->funct)
wdenka445ddf2004-06-09 00:34:46 +00001828 cmd->funct += gd->reloc_off;
1829
1830 k++;
1831 }
1832 j++;
1833 }
1834 }
1835
1836 relocated = 1;
wdenk78924a72004-04-18 21:45:42 +00001837}
1838
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001839#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001840 && !defined(BITBANGMII)
wdenka445ddf2004-06-09 00:34:46 +00001841
wdenk78924a72004-04-18 21:45:42 +00001842/*
1843 * Read a MII PHY register.
1844 *
1845 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001846 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001847 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001848static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001849 unsigned char reg, unsigned short *value)
wdenk78924a72004-04-18 21:45:42 +00001850{
wdenka445ddf2004-06-09 00:34:46 +00001851 unsigned short ret;
michael.firth@bt.com08384842008-01-16 11:40:51 +00001852 struct tsec_private *priv = privlist[0];
wdenk78924a72004-04-18 21:45:42 +00001853
Jon Loeligerb7ced082006-10-10 17:03:43 -05001854 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001855 printf("Can't read PHY at address %d\n", addr);
1856 return -1;
1857 }
1858
Andy Flemingac65e072008-08-31 16:33:27 -05001859 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
wdenka445ddf2004-06-09 00:34:46 +00001860 *value = ret;
wdenk78924a72004-04-18 21:45:42 +00001861
1862 return 0;
1863}
1864
1865/*
1866 * Write a MII PHY register.
1867 *
1868 * Returns:
wdenka445ddf2004-06-09 00:34:46 +00001869 * 0 on success
wdenk78924a72004-04-18 21:45:42 +00001870 */
Marian Balakowiczaab8c492005-10-28 22:30:33 +02001871static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeligerb7ced082006-10-10 17:03:43 -05001872 unsigned char reg, unsigned short value)
wdenk78924a72004-04-18 21:45:42 +00001873{
michael.firth@bt.com08384842008-01-16 11:40:51 +00001874 struct tsec_private *priv = privlist[0];
wdenka445ddf2004-06-09 00:34:46 +00001875
Jon Loeligerb7ced082006-10-10 17:03:43 -05001876 if (NULL == priv) {
wdenka445ddf2004-06-09 00:34:46 +00001877 printf("Can't write PHY at address %d\n", addr);
1878 return -1;
1879 }
wdenk78924a72004-04-18 21:45:42 +00001880
Andy Flemingac65e072008-08-31 16:33:27 -05001881 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
wdenk78924a72004-04-18 21:45:42 +00001882
1883 return 0;
wdenk9c53f402003-10-15 23:53:47 +00001884}
wdenka445ddf2004-06-09 00:34:46 +00001885
Jon Loeliger82ecaad2007-07-09 17:39:42 -05001886#endif
wdenka445ddf2004-06-09 00:34:46 +00001887
David Updegraff7280da72007-06-11 10:41:07 -05001888#ifdef CONFIG_MCAST_TFTP
1889
1890/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1891
1892/* Set the appropriate hash bit for the given addr */
1893
1894/* The algorithm works like so:
1895 * 1) Take the Destination Address (ie the multicast address), and
1896 * do a CRC on it (little endian), and reverse the bits of the
1897 * result.
1898 * 2) Use the 8 most significant bits as a hash into a 256-entry
1899 * table. The table is controlled through 8 32-bit registers:
1900 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1901 * gaddr7. This means that the 3 most significant bits in the
1902 * hash index which gaddr register to use, and the 5 other bits
1903 * indicate which bit (assuming an IBM numbering scheme, which
1904 * for PowerPC (tm) is usually the case) in the tregister holds
1905 * the entry. */
1906static int
1907tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1908{
1909 struct tsec_private *priv = privlist[1];
1910 volatile tsec_t *regs = priv->regs;
1911 volatile u32 *reg_array, value;
1912 u8 result, whichbit, whichreg;
1913
1914 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1915 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1916 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1917 value = (1 << (31-whichbit));
1918
1919 reg_array = &(regs->hash.gaddr0);
1920
1921 if (set) {
1922 reg_array[whichreg] |= value;
1923 } else {
1924 reg_array[whichreg] &= ~value;
1925 }
1926 return 0;
1927}
1928#endif /* Multicast TFTP ? */