blob: f81211adb9820d18f84d4fd6bf2067fd23c9e8d6 [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
wdenk97d80fc2004-06-09 00:34:46 +00002 * Freescale Three Speed Ethernet Controller driver
wdenk42d1f032003-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 Fleming81f481c2007-04-23 02:24:28 -05008 * Copyright 2004, 2007 Freescale Semiconductor, Inc.
wdenk42d1f032003-10-15 23:53:47 +00009 * (C) Copyright 2003, Motorola, Inc.
wdenk42d1f032003-10-15 23:53:47 +000010 * author Andy Fleming
11 *
12 */
13
14#include <config.h>
wdenk42d1f032003-10-15 23:53:47 +000015#include <common.h>
16#include <malloc.h>
17#include <net.h>
18#include <command.h>
Andy Flemingdd3d1f52008-08-31 16:33:25 -050019#include <tsec.h>
wdenk42d1f032003-10-15 23:53:47 +000020
Marian Balakowicz63ff0042005-10-28 22:30:33 +020021#include "miiphy.h"
wdenk42d1f032003-10-15 23:53:47 +000022
Wolfgang Denkd87080b2006-03-31 18:32:53 +020023DECLARE_GLOBAL_DATA_PTR;
24
Marian Balakowicz63ff0042005-10-28 22:30:33 +020025#define TX_BUF_CNT 2
wdenk42d1f032003-10-15 23:53:47 +000026
Jon Loeliger89875e92006-10-10 17:03:43 -050027static uint rxIdx; /* index of the current RX buffer */
28static uint txIdx; /* index of the current TX buffer */
wdenk42d1f032003-10-15 23:53:47 +000029
30typedef volatile struct rtxbd {
31 txbd8_t txbd[TX_BUF_CNT];
32 rxbd8_t rxbd[PKTBUFSRX];
Jon Loeliger89875e92006-10-10 17:03:43 -050033} RTXBD;
wdenk42d1f032003-10-15 23:53:47 +000034
Andy Fleming75b9d4a2008-08-31 16:33:26 -050035#define MAXCONTROLLERS (8)
wdenk97d80fc2004-06-09 00:34:46 +000036
37static int relocated = 0;
38
39static struct tsec_private *privlist[MAXCONTROLLERS];
Andy Fleming75b9d4a2008-08-31 16:33:26 -050040static int num_tsecs = 0;
wdenk97d80fc2004-06-09 00:34:46 +000041
wdenk42d1f032003-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 Loeliger89875e92006-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);
wdenk97d80fc2004-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 Loeliger89875e92006-10-10 17:03:43 -050058struct phy_info *get_phy_info(struct eth_device *dev);
wdenk97d80fc2004-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 Denk409ecdc2007-11-18 16:36:27 +010062#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
63 && !defined(BITBANGMII)
Marian Balakowicz63ff0042005-10-28 22:30:33 +020064static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -050065 unsigned char reg, unsigned short value);
Marian Balakowicz63ff0042005-10-28 22:30:33 +020066static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -050067 unsigned char reg, unsigned short *value);
Wolfgang Denk409ecdc2007-11-18 16:36:27 +010068#endif
David Updegraff53a5c422007-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
wdenk7abf0c52004-04-18 21:45:42 +000072
Andy Fleming75b9d4a2008-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
wdenk97d80fc2004-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 Fleming75b9d4a2008-08-31 16:33:26 -0500117int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
wdenk42d1f032003-10-15 23:53:47 +0000118{
Jon Loeliger89875e92006-10-10 17:03:43 -0500119 struct eth_device *dev;
wdenk42d1f032003-10-15 23:53:47 +0000120 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000121 struct tsec_private *priv;
wdenk42d1f032003-10-15 23:53:47 +0000122
Jon Loeliger89875e92006-10-10 17:03:43 -0500123 dev = (struct eth_device *)malloc(sizeof *dev);
wdenk42d1f032003-10-15 23:53:47 +0000124
Jon Loeliger89875e92006-10-10 17:03:43 -0500125 if (NULL == dev)
wdenk42d1f032003-10-15 23:53:47 +0000126 return 0;
127
128 memset(dev, 0, sizeof *dev);
129
Jon Loeliger89875e92006-10-10 17:03:43 -0500130 priv = (struct tsec_private *)malloc(sizeof(*priv));
wdenk97d80fc2004-06-09 00:34:46 +0000131
Jon Loeliger89875e92006-10-10 17:03:43 -0500132 if (NULL == priv)
wdenk97d80fc2004-06-09 00:34:46 +0000133 return 0;
134
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500135 privlist[num_tsecs++] = priv;
136 priv->regs = tsec_info->regs;
137 priv->phyregs = tsec_info->miiregs;
wdenk97d80fc2004-06-09 00:34:46 +0000138
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500139 priv->phyaddr = tsec_info->phyaddr;
140 priv->flags = tsec_info->flags;
wdenk97d80fc2004-06-09 00:34:46 +0000141
Andy Fleming75b9d4a2008-08-31 16:33:26 -0500142 sprintf(dev->name, tsec_info->devname);
wdenk42d1f032003-10-15 23:53:47 +0000143 dev->iobase = 0;
Jon Loeliger89875e92006-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 Updegraff53a5c422007-06-11 10:41:07 -0500149#ifdef CONFIG_MCAST_TFTP
150 dev->mcast = tsec_mcast_addr;
151#endif
wdenk42d1f032003-10-15 23:53:47 +0000152
153 /* Tell u-boot to get the addr from the env */
Jon Loeliger89875e92006-10-10 17:03:43 -0500154 for (i = 0; i < 6; i++)
wdenk42d1f032003-10-15 23:53:47 +0000155 dev->enetaddr[i] = 0;
156
157 eth_register(dev);
158
wdenk97d80fc2004-06-09 00:34:46 +0000159 /* Reset the MAC */
160 priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
161 priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
wdenk7abf0c52004-04-18 21:45:42 +0000162
Jon Loeligercb51c0b2007-07-09 17:39:42 -0500163#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200164 && !defined(BITBANGMII)
165 miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
166#endif
167
wdenk97d80fc2004-06-09 00:34:46 +0000168 /* Try to initialize PHY here, and return */
169 return init_phy(dev);
wdenk42d1f032003-10-15 23:53:47 +0000170}
171
wdenk42d1f032003-10-15 23:53:47 +0000172/* Initializes data structures and registers for the controller,
wdenk9d46ea42005-03-14 23:56:42 +0000173 * and brings the interface up. Returns the link status, meaning
wdenk97d80fc2004-06-09 00:34:46 +0000174 * that it returns success if the link is up, failure otherwise.
Jon Loeliger89875e92006-10-10 17:03:43 -0500175 * This allows u-boot to find the first active controller.
176 */
177int tsec_init(struct eth_device *dev, bd_t * bd)
wdenk42d1f032003-10-15 23:53:47 +0000178{
wdenk42d1f032003-10-15 23:53:47 +0000179 uint tempval;
180 char tmpbuf[MAC_ADDR_LEN];
181 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000182 struct tsec_private *priv = (struct tsec_private *)dev->priv;
183 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000184
185 /* Make sure the controller is stopped */
186 tsec_halt(dev);
187
wdenk97d80fc2004-06-09 00:34:46 +0000188 /* Init MACCFG2. Defaults to GMII */
wdenk42d1f032003-10-15 23:53:47 +0000189 regs->maccfg2 = MACCFG2_INIT_SETTINGS;
190
191 /* Init ECNTRL */
192 regs->ecntrl = ECNTRL_INIT_SETTINGS;
193
194 /* Copy the station address into the address registers.
195 * Backwards, because little endian MACS are dumb */
Jon Loeliger89875e92006-10-10 17:03:43 -0500196 for (i = 0; i < MAC_ADDR_LEN; i++) {
wdenk97d80fc2004-06-09 00:34:46 +0000197 tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
wdenk42d1f032003-10-15 23:53:47 +0000198 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500199 regs->macstnaddr1 = *((uint *) (tmpbuf));
wdenk42d1f032003-10-15 23:53:47 +0000200
Jon Loeliger89875e92006-10-10 17:03:43 -0500201 tempval = *((uint *) (tmpbuf + 4));
wdenk42d1f032003-10-15 23:53:47 +0000202
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200203 regs->macstnaddr2 = tempval;
wdenk42d1f032003-10-15 23:53:47 +0000204
wdenk42d1f032003-10-15 23:53:47 +0000205 /* reset the indices to zero */
206 rxIdx = 0;
207 txIdx = 0;
208
209 /* Clear out (for the most part) the other registers */
210 init_registers(regs);
211
212 /* Ready the device for tx/rx */
wdenk97d80fc2004-06-09 00:34:46 +0000213 startup_tsec(dev);
wdenk42d1f032003-10-15 23:53:47 +0000214
wdenk97d80fc2004-06-09 00:34:46 +0000215 /* If there's no link, fail */
Ben Warren422b1a02008-01-09 18:15:53 -0500216 return (priv->link ? 0 : -1);
wdenk42d1f032003-10-15 23:53:47 +0000217}
218
Andy Fleming2abe3612008-08-31 16:33:27 -0500219/* Writes the given phy's reg with value, using the specified MDIO regs */
220static void tsec_local_mdio_write(volatile tsec_t *phyregs, uint addr,
221 uint reg, uint value)
wdenk97d80fc2004-06-09 00:34:46 +0000222{
Jon Loeliger89875e92006-10-10 17:03:43 -0500223 int timeout = 1000000;
wdenk97d80fc2004-06-09 00:34:46 +0000224
Andy Fleming2abe3612008-08-31 16:33:27 -0500225 phyregs->miimadd = (addr << 8) | reg;
226 phyregs->miimcon = value;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500227 asm("sync");
wdenk97d80fc2004-06-09 00:34:46 +0000228
Jon Loeliger89875e92006-10-10 17:03:43 -0500229 timeout = 1000000;
Andy Fleming2abe3612008-08-31 16:33:27 -0500230 while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk97d80fc2004-06-09 00:34:46 +0000231}
232
Andy Fleming2abe3612008-08-31 16:33:27 -0500233
234/* Provide the default behavior of writing the PHY of this ethernet device */
235#define write_phy_reg(priv, regnum, value) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +0000236
wdenk97d80fc2004-06-09 00:34:46 +0000237/* Reads register regnum on the device's PHY through the
Andy Fleming2abe3612008-08-31 16:33:27 -0500238 * specified registers. It lowers and raises the read
wdenk97d80fc2004-06-09 00:34:46 +0000239 * command, and waits for the data to become valid (miimind
240 * notvalid bit cleared), and the bus to cease activity (miimind
241 * busy bit cleared), and then returns the value
242 */
Andy Fleming2abe3612008-08-31 16:33:27 -0500243uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum)
wdenk42d1f032003-10-15 23:53:47 +0000244{
245 uint value;
246
wdenk97d80fc2004-06-09 00:34:46 +0000247 /* Put the address of the phy, and the register
248 * number into MIIMADD */
Andy Fleming2abe3612008-08-31 16:33:27 -0500249 phyregs->miimadd = (phyid << 8) | regnum;
wdenk42d1f032003-10-15 23:53:47 +0000250
251 /* Clear the command register, and wait */
Andy Fleming2abe3612008-08-31 16:33:27 -0500252 phyregs->miimcom = 0;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500253 asm("sync");
wdenk42d1f032003-10-15 23:53:47 +0000254
255 /* Initiate a read command, and wait */
Andy Fleming2abe3612008-08-31 16:33:27 -0500256 phyregs->miimcom = MIIM_READ_COMMAND;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500257 asm("sync");
wdenk42d1f032003-10-15 23:53:47 +0000258
259 /* Wait for the the indication that the read is done */
Andy Fleming2abe3612008-08-31 16:33:27 -0500260 while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
wdenk42d1f032003-10-15 23:53:47 +0000261
262 /* Grab the value read from the PHY */
Andy Fleming2abe3612008-08-31 16:33:27 -0500263 value = phyregs->miimstat;
wdenk42d1f032003-10-15 23:53:47 +0000264
265 return value;
266}
267
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +0000268/* #define to provide old read_phy_reg functionality without duplicating code */
Andy Fleming2abe3612008-08-31 16:33:27 -0500269#define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
270
271#define TBIANA_SETTINGS ( \
272 TBIANA_ASYMMETRIC_PAUSE \
273 | TBIANA_SYMMETRIC_PAUSE \
274 | TBIANA_FULL_DUPLEX \
275 )
276
277#define TBICR_SETTINGS ( \
278 TBICR_PHY_RESET \
279 | TBICR_ANEG_ENABLE \
280 | TBICR_FULL_DUPLEX \
281 | TBICR_SPEED1_SET \
282 )
283/* Configure the TBI for SGMII operation */
284static void tsec_configure_serdes(struct tsec_private *priv)
285{
286 tsec_local_mdio_write(priv->phyregs, CFG_TBIPA_VALUE, TBI_ANA,
287 TBIANA_SETTINGS);
288 tsec_local_mdio_write(priv->phyregs, CFG_TBIPA_VALUE, TBI_TBICON,
289 TBICON_CLK_SELECT);
290 tsec_local_mdio_write(priv->phyregs, CFG_TBIPA_VALUE, TBI_CR,
291 TBICR_SETTINGS);
292}
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +0000293
wdenk97d80fc2004-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)
wdenk42d1f032003-10-15 23:53:47 +0000299{
wdenk97d80fc2004-06-09 00:34:46 +0000300 struct tsec_private *priv = (struct tsec_private *)dev->priv;
301 struct phy_info *curphy;
Andy Fleming2abe3612008-08-31 16:33:27 -0500302 volatile tsec_t *phyregs = priv->phyregs;
303 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000304
305 /* Assign a Physical address to the TBI */
Joe Hammandcb84b72007-08-09 09:08:18 -0500306 regs->tbipa = CFG_TBIPA_VALUE;
Andy Fleming2abe3612008-08-31 16:33:27 -0500307 phyregs->tbipa = CFG_TBIPA_VALUE;
Jon Loeliger89875e92006-10-10 17:03:43 -0500308 asm("sync");
wdenk3dd7f0f2005-04-04 23:43:44 +0000309
310 /* Reset MII (due to new addresses) */
311 priv->phyregs->miimcfg = MIIMCFG_RESET;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500312 asm("sync");
wdenk3dd7f0f2005-04-04 23:43:44 +0000313 priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500314 asm("sync");
Jon Loeliger89875e92006-10-10 17:03:43 -0500315 while (priv->phyregs->miimind & MIIMIND_BUSY) ;
wdenk42d1f032003-10-15 23:53:47 +0000316
Jon Loeliger89875e92006-10-10 17:03:43 -0500317 if (0 == relocated)
wdenk97d80fc2004-06-09 00:34:46 +0000318 relocate_cmds();
wdenk42d1f032003-10-15 23:53:47 +0000319
wdenk97d80fc2004-06-09 00:34:46 +0000320 /* Get the cmd structure corresponding to the attached
321 * PHY */
322 curphy = get_phy_info(dev);
wdenk42d1f032003-10-15 23:53:47 +0000323
Ben Warren4653f912006-10-26 14:38:25 -0400324 if (curphy == NULL) {
325 priv->phyinfo = NULL;
wdenk97d80fc2004-06-09 00:34:46 +0000326 printf("%s: No PHY found\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +0000327
wdenk97d80fc2004-06-09 00:34:46 +0000328 return 0;
wdenk42d1f032003-10-15 23:53:47 +0000329 }
330
Andy Fleming2abe3612008-08-31 16:33:27 -0500331 if (regs->ecntrl & ECNTRL_SGMII_MODE)
332 tsec_configure_serdes(priv);
333
wdenk97d80fc2004-06-09 00:34:46 +0000334 priv->phyinfo = curphy;
wdenk42d1f032003-10-15 23:53:47 +0000335
wdenk97d80fc2004-06-09 00:34:46 +0000336 phy_run_commands(priv, priv->phyinfo->config);
wdenk42d1f032003-10-15 23:53:47 +0000337
wdenk97d80fc2004-06-09 00:34:46 +0000338 return 1;
wdenk42d1f032003-10-15 23:53:47 +0000339}
340
Jon Loeliger89875e92006-10-10 17:03:43 -0500341/*
342 * Returns which value to write to the control register.
343 * For 10/100, the value is slightly different
344 */
345uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000346{
Jon Loeliger89875e92006-10-10 17:03:43 -0500347 if (priv->flags & TSEC_GIGABIT)
wdenk97d80fc2004-06-09 00:34:46 +0000348 return MIIM_CONTROL_INIT;
349 else
350 return MIIM_CR_INIT;
351}
352
wdenk97d80fc2004-06-09 00:34:46 +0000353/* Parse the status register for link, and then do
Jon Loeliger89875e92006-10-10 17:03:43 -0500354 * auto-negotiation
355 */
356uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000357{
Stefan Roese5810dc32005-09-21 18:20:22 +0200358 /*
Andy Fleming7613afd2007-08-15 20:03:44 -0500359 * Wait if the link is up, and autonegotiation is in progress
360 * (ie - we're capable and it's not done)
Stefan Roese5810dc32005-09-21 18:20:22 +0200361 */
362 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Andy Fleming7613afd2007-08-15 20:03:44 -0500363 if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
Jon Loeliger89875e92006-10-10 17:03:43 -0500364 && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200365 int i = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000366
Jon Loeliger89875e92006-10-10 17:03:43 -0500367 puts("Waiting for PHY auto negotiation to complete");
Andy Fleming7613afd2007-08-15 20:03:44 -0500368 while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200369 /*
370 * Timeout reached ?
371 */
372 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500373 puts(" TIMEOUT !\n");
Stefan Roese5810dc32005-09-21 18:20:22 +0200374 priv->link = 0;
Jin Zhengxiong-R64188fcfb9a52006-06-27 18:12:23 +0800375 return 0;
Stefan Roese5810dc32005-09-21 18:20:22 +0200376 }
wdenk97d80fc2004-06-09 00:34:46 +0000377
Stefan Roese5810dc32005-09-21 18:20:22 +0200378 if ((i++ % 1000) == 0) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500379 putc('.');
Stefan Roese5810dc32005-09-21 18:20:22 +0200380 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500381 udelay(1000); /* 1 ms */
wdenk97d80fc2004-06-09 00:34:46 +0000382 mii_reg = read_phy_reg(priv, MIIM_STATUS);
Stefan Roese5810dc32005-09-21 18:20:22 +0200383 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500384 puts(" done\n");
Stefan Roese5810dc32005-09-21 18:20:22 +0200385 priv->link = 1;
Jon Loeliger89875e92006-10-10 17:03:43 -0500386 udelay(500000); /* another 500 ms (results in faster booting) */
Stefan Roese5810dc32005-09-21 18:20:22 +0200387 } else {
Andy Fleming7613afd2007-08-15 20:03:44 -0500388 if (mii_reg & MIIM_STATUS_LINK)
389 priv->link = 1;
390 else
391 priv->link = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000392 }
393
394 return 0;
395}
396
David Updegraffaf1c2b82007-04-20 14:34:48 -0500397/* Generic function which updates the speed and duplex. If
398 * autonegotiation is enabled, it uses the AND of the link
399 * partner's advertised capabilities and our advertised
400 * capabilities. If autonegotiation is disabled, we use the
401 * appropriate bits in the control register.
402 *
403 * Stolen from Linux's mii.c and phy_device.c
404 */
405uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
406{
407 /* We're using autonegotiation */
408 if (mii_reg & PHY_BMSR_AUTN_ABLE) {
409 uint lpa = 0;
410 uint gblpa = 0;
411
412 /* Check for gigabit capability */
413 if (mii_reg & PHY_BMSR_EXT) {
414 /* We want a list of states supported by
415 * both PHYs in the link
416 */
417 gblpa = read_phy_reg(priv, PHY_1000BTSR);
418 gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
419 }
420
421 /* Set the baseline so we only have to set them
422 * if they're different
423 */
424 priv->speed = 10;
425 priv->duplexity = 0;
426
427 /* Check the gigabit fields */
428 if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
429 priv->speed = 1000;
430
431 if (gblpa & PHY_1000BTSR_1000FD)
432 priv->duplexity = 1;
433
434 /* We're done! */
435 return 0;
436 }
437
438 lpa = read_phy_reg(priv, PHY_ANAR);
439 lpa &= read_phy_reg(priv, PHY_ANLPAR);
440
441 if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
442 priv->speed = 100;
443
444 if (lpa & PHY_ANLPAR_TXFD)
445 priv->duplexity = 1;
446
447 } else if (lpa & PHY_ANLPAR_10FD)
448 priv->duplexity = 1;
449 } else {
450 uint bmcr = read_phy_reg(priv, PHY_BMCR);
451
452 priv->speed = 10;
453 priv->duplexity = 0;
454
455 if (bmcr & PHY_BMCR_DPLX)
456 priv->duplexity = 1;
457
458 if (bmcr & PHY_BMCR_1000_MBPS)
459 priv->speed = 1000;
460 else if (bmcr & PHY_BMCR_100_MBPS)
461 priv->speed = 100;
462 }
463
464 return 0;
465}
466
Paul Gortmaker91e25762007-01-16 11:38:14 -0500467/*
468 * Parse the BCM54xx status register for speed and duplex information.
469 * The linux sungem_phy has this information, but in a table format.
470 */
471uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
472{
473
474 switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
475
476 case 1:
477 printf("Enet starting in 10BT/HD\n");
478 priv->duplexity = 0;
479 priv->speed = 10;
480 break;
481
482 case 2:
483 printf("Enet starting in 10BT/FD\n");
484 priv->duplexity = 1;
485 priv->speed = 10;
486 break;
487
488 case 3:
489 printf("Enet starting in 100BT/HD\n");
490 priv->duplexity = 0;
491 priv->speed = 100;
492 break;
493
494 case 5:
495 printf("Enet starting in 100BT/FD\n");
496 priv->duplexity = 1;
497 priv->speed = 100;
498 break;
499
500 case 6:
501 printf("Enet starting in 1000BT/HD\n");
502 priv->duplexity = 0;
503 priv->speed = 1000;
504 break;
505
506 case 7:
507 printf("Enet starting in 1000BT/FD\n");
508 priv->duplexity = 1;
509 priv->speed = 1000;
510 break;
511
512 default:
513 printf("Auto-neg error, defaulting to 10BT/HD\n");
514 priv->duplexity = 0;
515 priv->speed = 10;
516 break;
517 }
518
519 return 0;
520
521}
wdenk97d80fc2004-06-09 00:34:46 +0000522/* Parse the 88E1011's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500523 * information
524 */
525uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000526{
527 uint speed;
528
Stefan Roese5810dc32005-09-21 18:20:22 +0200529 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
530
Andy Fleming7613afd2007-08-15 20:03:44 -0500531 if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
532 !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
Stefan Roese5810dc32005-09-21 18:20:22 +0200533 int i = 0;
534
Jon Loeliger89875e92006-10-10 17:03:43 -0500535 puts("Waiting for PHY realtime link");
Andy Fleming7613afd2007-08-15 20:03:44 -0500536 while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
537 /* Timeout reached ? */
Stefan Roese5810dc32005-09-21 18:20:22 +0200538 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500539 puts(" TIMEOUT !\n");
Stefan Roese5810dc32005-09-21 18:20:22 +0200540 priv->link = 0;
541 break;
542 }
543
544 if ((i++ % 1000) == 0) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500545 putc('.');
Stefan Roese5810dc32005-09-21 18:20:22 +0200546 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500547 udelay(1000); /* 1 ms */
Stefan Roese5810dc32005-09-21 18:20:22 +0200548 mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
549 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500550 puts(" done\n");
551 udelay(500000); /* another 500 ms (results in faster booting) */
Andy Fleming7613afd2007-08-15 20:03:44 -0500552 } else {
553 if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
554 priv->link = 1;
555 else
556 priv->link = 0;
Stefan Roese5810dc32005-09-21 18:20:22 +0200557 }
558
Jon Loeliger89875e92006-10-10 17:03:43 -0500559 if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
wdenk97d80fc2004-06-09 00:34:46 +0000560 priv->duplexity = 1;
561 else
562 priv->duplexity = 0;
563
Jon Loeliger89875e92006-10-10 17:03:43 -0500564 speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
wdenk97d80fc2004-06-09 00:34:46 +0000565
Jon Loeliger89875e92006-10-10 17:03:43 -0500566 switch (speed) {
567 case MIIM_88E1011_PHYSTAT_GBIT:
568 priv->speed = 1000;
569 break;
570 case MIIM_88E1011_PHYSTAT_100:
571 priv->speed = 100;
572 break;
573 default:
574 priv->speed = 10;
wdenk97d80fc2004-06-09 00:34:46 +0000575 }
576
577 return 0;
578}
579
Dave Liu18ee3202008-01-11 18:45:28 +0800580/* Parse the RTL8211B's status register for speed and duplex
581 * information
582 */
583uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
584{
585 uint speed;
586
587 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
Anton Vorontsovc7604782008-03-14 23:20:30 +0300588 if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
Dave Liu18ee3202008-01-11 18:45:28 +0800589 int i = 0;
590
Anton Vorontsovc7604782008-03-14 23:20:30 +0300591 /* in case of timeout ->link is cleared */
592 priv->link = 1;
Dave Liu18ee3202008-01-11 18:45:28 +0800593 puts("Waiting for PHY realtime link");
594 while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
595 /* Timeout reached ? */
596 if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
597 puts(" TIMEOUT !\n");
598 priv->link = 0;
599 break;
600 }
601
602 if ((i++ % 1000) == 0) {
603 putc('.');
604 }
605 udelay(1000); /* 1 ms */
606 mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
607 }
608 puts(" done\n");
609 udelay(500000); /* another 500 ms (results in faster booting) */
610 } else {
611 if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
612 priv->link = 1;
613 else
614 priv->link = 0;
615 }
616
617 if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
618 priv->duplexity = 1;
619 else
620 priv->duplexity = 0;
621
622 speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
623
624 switch (speed) {
625 case MIIM_RTL8211B_PHYSTAT_GBIT:
626 priv->speed = 1000;
627 break;
628 case MIIM_RTL8211B_PHYSTAT_100:
629 priv->speed = 100;
630 break;
631 default:
632 priv->speed = 10;
633 }
634
635 return 0;
636}
637
wdenk97d80fc2004-06-09 00:34:46 +0000638/* Parse the cis8201's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500639 * information
640 */
641uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000642{
643 uint speed;
644
Jon Loeliger89875e92006-10-10 17:03:43 -0500645 if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
wdenk97d80fc2004-06-09 00:34:46 +0000646 priv->duplexity = 1;
647 else
648 priv->duplexity = 0;
649
650 speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
Jon Loeliger89875e92006-10-10 17:03:43 -0500651 switch (speed) {
652 case MIIM_CIS8201_AUXCONSTAT_GBIT:
653 priv->speed = 1000;
654 break;
655 case MIIM_CIS8201_AUXCONSTAT_100:
656 priv->speed = 100;
657 break;
658 default:
659 priv->speed = 10;
660 break;
wdenk97d80fc2004-06-09 00:34:46 +0000661 }
662
663 return 0;
664}
Jon Loeliger89875e92006-10-10 17:03:43 -0500665
Jon Loeligerdebb7352006-04-26 17:58:56 -0500666/* Parse the vsc8244's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500667 * information
668 */
669uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500670{
Jon Loeliger89875e92006-10-10 17:03:43 -0500671 uint speed;
672
673 if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
674 priv->duplexity = 1;
675 else
676 priv->duplexity = 0;
677
678 speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
679 switch (speed) {
680 case MIIM_VSC8244_AUXCONSTAT_GBIT:
681 priv->speed = 1000;
682 break;
683 case MIIM_VSC8244_AUXCONSTAT_100:
684 priv->speed = 100;
685 break;
686 default:
687 priv->speed = 10;
688 break;
689 }
690
691 return 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500692}
wdenk97d80fc2004-06-09 00:34:46 +0000693
wdenk97d80fc2004-06-09 00:34:46 +0000694/* Parse the DM9161's status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500695 * information
696 */
697uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000698{
Jon Loeliger89875e92006-10-10 17:03:43 -0500699 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
wdenk97d80fc2004-06-09 00:34:46 +0000700 priv->speed = 100;
701 else
702 priv->speed = 10;
703
Jon Loeliger89875e92006-10-10 17:03:43 -0500704 if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
wdenk97d80fc2004-06-09 00:34:46 +0000705 priv->duplexity = 1;
706 else
707 priv->duplexity = 0;
708
709 return 0;
710}
711
Jon Loeliger89875e92006-10-10 17:03:43 -0500712/*
713 * Hack to write all 4 PHYs with the LED values
714 */
715uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
wdenk97d80fc2004-06-09 00:34:46 +0000716{
717 uint phyid;
718 volatile tsec_t *regbase = priv->phyregs;
Jon Loeliger89875e92006-10-10 17:03:43 -0500719 int timeout = 1000000;
wdenk97d80fc2004-06-09 00:34:46 +0000720
Jon Loeliger89875e92006-10-10 17:03:43 -0500721 for (phyid = 0; phyid < 4; phyid++) {
wdenk97d80fc2004-06-09 00:34:46 +0000722 regbase->miimadd = (phyid << 8) | mii_reg;
723 regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
Eran Libertyf046ccd2005-07-28 10:08:46 -0500724 asm("sync");
wdenk97d80fc2004-06-09 00:34:46 +0000725
Jon Loeliger89875e92006-10-10 17:03:43 -0500726 timeout = 1000000;
727 while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
wdenk97d80fc2004-06-09 00:34:46 +0000728 }
729
730 return MIIM_CIS8204_SLEDCON_INIT;
731}
732
Jon Loeliger89875e92006-10-10 17:03:43 -0500733uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500734{
735 if (priv->flags & TSEC_REDUCED)
736 return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
737 else
738 return MIIM_CIS8204_EPHYCON_INIT;
739}
wdenk97d80fc2004-06-09 00:34:46 +0000740
Dave Liu19580e62007-09-18 12:37:57 +0800741uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
742{
743 uint mii_data = read_phy_reg(priv, mii_reg);
744
745 if (priv->flags & TSEC_REDUCED)
746 mii_data = (mii_data & 0xfff0) | 0x000b;
747 return mii_data;
748}
749
wdenk97d80fc2004-06-09 00:34:46 +0000750/* Initialized required registers to appropriate values, zeroing
751 * those we don't care about (unless zero is bad, in which case,
Jon Loeliger89875e92006-10-10 17:03:43 -0500752 * choose a more appropriate value)
753 */
754static void init_registers(volatile tsec_t * regs)
wdenk42d1f032003-10-15 23:53:47 +0000755{
756 /* Clear IEVENT */
757 regs->ievent = IEVENT_INIT_CLEAR;
758
759 regs->imask = IMASK_INIT_CLEAR;
760
761 regs->hash.iaddr0 = 0;
762 regs->hash.iaddr1 = 0;
763 regs->hash.iaddr2 = 0;
764 regs->hash.iaddr3 = 0;
765 regs->hash.iaddr4 = 0;
766 regs->hash.iaddr5 = 0;
767 regs->hash.iaddr6 = 0;
768 regs->hash.iaddr7 = 0;
769
770 regs->hash.gaddr0 = 0;
771 regs->hash.gaddr1 = 0;
772 regs->hash.gaddr2 = 0;
773 regs->hash.gaddr3 = 0;
774 regs->hash.gaddr4 = 0;
775 regs->hash.gaddr5 = 0;
776 regs->hash.gaddr6 = 0;
777 regs->hash.gaddr7 = 0;
778
779 regs->rctrl = 0x00000000;
780
781 /* Init RMON mib registers */
782 memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
783
784 regs->rmon.cam1 = 0xffffffff;
785 regs->rmon.cam2 = 0xffffffff;
786
787 regs->mrblr = MRBLR_INIT_SETTINGS;
788
789 regs->minflr = MINFLR_INIT_SETTINGS;
790
791 regs->attr = ATTR_INIT_SETTINGS;
792 regs->attreli = ATTRELI_INIT_SETTINGS;
793
794}
795
wdenk97d80fc2004-06-09 00:34:46 +0000796/* Configure maccfg2 based on negotiated speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -0500797 * reported by PHY handling code
798 */
wdenk97d80fc2004-06-09 00:34:46 +0000799static void adjust_link(struct eth_device *dev)
800{
801 struct tsec_private *priv = (struct tsec_private *)dev->priv;
802 volatile tsec_t *regs = priv->regs;
803
Jon Loeliger89875e92006-10-10 17:03:43 -0500804 if (priv->link) {
805 if (priv->duplexity != 0)
wdenk97d80fc2004-06-09 00:34:46 +0000806 regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
807 else
808 regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
809
Jon Loeliger89875e92006-10-10 17:03:43 -0500810 switch (priv->speed) {
811 case 1000:
812 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
813 | MACCFG2_GMII);
814 break;
815 case 100:
816 case 10:
817 regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
818 | MACCFG2_MII);
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500819
Nick Spencef484dc72006-09-07 07:39:46 -0700820 /* Set R100 bit in all modes although
821 * it is only used in RGMII mode
Jon Loeliger89875e92006-10-10 17:03:43 -0500822 */
Nick Spencef484dc72006-09-07 07:39:46 -0700823 if (priv->speed == 100)
Jon Loeliger89875e92006-10-10 17:03:43 -0500824 regs->ecntrl |= ECNTRL_R100;
825 else
826 regs->ecntrl &= ~(ECNTRL_R100);
827 break;
828 default:
829 printf("%s: Speed was bad\n", dev->name);
830 break;
wdenk97d80fc2004-06-09 00:34:46 +0000831 }
832
833 printf("Speed: %d, %s duplex\n", priv->speed,
Jon Loeliger89875e92006-10-10 17:03:43 -0500834 (priv->duplexity) ? "full" : "half");
wdenk97d80fc2004-06-09 00:34:46 +0000835
836 } else {
837 printf("%s: No link.\n", dev->name);
838 }
839}
840
wdenk97d80fc2004-06-09 00:34:46 +0000841/* Set up the buffers and their descriptors, and bring up the
Jon Loeliger89875e92006-10-10 17:03:43 -0500842 * interface
843 */
wdenk97d80fc2004-06-09 00:34:46 +0000844static void startup_tsec(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +0000845{
846 int i;
wdenk97d80fc2004-06-09 00:34:46 +0000847 struct tsec_private *priv = (struct tsec_private *)dev->priv;
848 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000849
850 /* Point to the buffer descriptors */
851 regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
852 regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
853
854 /* Initialize the Rx Buffer descriptors */
855 for (i = 0; i < PKTBUFSRX; i++) {
856 rtx.rxbd[i].status = RXBD_EMPTY;
857 rtx.rxbd[i].length = 0;
Jon Loeliger89875e92006-10-10 17:03:43 -0500858 rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
wdenk42d1f032003-10-15 23:53:47 +0000859 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500860 rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
wdenk42d1f032003-10-15 23:53:47 +0000861
862 /* Initialize the TX Buffer Descriptors */
Jon Loeliger89875e92006-10-10 17:03:43 -0500863 for (i = 0; i < TX_BUF_CNT; i++) {
wdenk42d1f032003-10-15 23:53:47 +0000864 rtx.txbd[i].status = 0;
865 rtx.txbd[i].length = 0;
866 rtx.txbd[i].bufPtr = 0;
867 }
Jon Loeliger89875e92006-10-10 17:03:43 -0500868 rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
wdenk42d1f032003-10-15 23:53:47 +0000869
wdenk97d80fc2004-06-09 00:34:46 +0000870 /* Start up the PHY */
Ben Warren4653f912006-10-26 14:38:25 -0400871 if(priv->phyinfo)
872 phy_run_commands(priv, priv->phyinfo->startup);
David Updegraffaf1c2b82007-04-20 14:34:48 -0500873
wdenk97d80fc2004-06-09 00:34:46 +0000874 adjust_link(dev);
875
wdenk42d1f032003-10-15 23:53:47 +0000876 /* Enable Transmit and Receive */
877 regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
878
879 /* Tell the DMA it is clear to go */
880 regs->dmactrl |= DMACTRL_INIT_SETTINGS;
881 regs->tstat = TSTAT_CLEAR_THALT;
Dan Wilson5c7ea642007-10-19 11:33:48 -0500882 regs->rstat = RSTAT_CLEAR_RHALT;
wdenk42d1f032003-10-15 23:53:47 +0000883 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
884}
885
wdenk9d46ea42005-03-14 23:56:42 +0000886/* This returns the status bits of the device. The return value
wdenk42d1f032003-10-15 23:53:47 +0000887 * is never checked, and this is what the 8260 driver did, so we
wdenk9d46ea42005-03-14 23:56:42 +0000888 * do the same. Presumably, this would be zero if there were no
Jon Loeliger89875e92006-10-10 17:03:43 -0500889 * errors
890 */
891static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
wdenk42d1f032003-10-15 23:53:47 +0000892{
893 int i;
894 int result = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000895 struct tsec_private *priv = (struct tsec_private *)dev->priv;
896 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000897
898 /* Find an empty buffer descriptor */
Jon Loeliger89875e92006-10-10 17:03:43 -0500899 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk42d1f032003-10-15 23:53:47 +0000900 if (i >= TOUT_LOOP) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500901 debug("%s: tsec: tx buffers full\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +0000902 return result;
903 }
904 }
905
Jon Loeliger89875e92006-10-10 17:03:43 -0500906 rtx.txbd[txIdx].bufPtr = (uint) packet;
wdenk42d1f032003-10-15 23:53:47 +0000907 rtx.txbd[txIdx].length = length;
Jon Loeliger89875e92006-10-10 17:03:43 -0500908 rtx.txbd[txIdx].status |=
909 (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
wdenk42d1f032003-10-15 23:53:47 +0000910
911 /* Tell the DMA to go */
912 regs->tstat = TSTAT_CLEAR_THALT;
913
914 /* Wait for buffer to be transmitted */
Jon Loeliger89875e92006-10-10 17:03:43 -0500915 for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
wdenk42d1f032003-10-15 23:53:47 +0000916 if (i >= TOUT_LOOP) {
Jon Loeliger89875e92006-10-10 17:03:43 -0500917 debug("%s: tsec: tx error\n", dev->name);
wdenk42d1f032003-10-15 23:53:47 +0000918 return result;
919 }
920 }
921
922 txIdx = (txIdx + 1) % TX_BUF_CNT;
923 result = rtx.txbd[txIdx].status & TXBD_STATS;
924
925 return result;
926}
927
Jon Loeliger89875e92006-10-10 17:03:43 -0500928static int tsec_recv(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +0000929{
930 int length;
wdenk97d80fc2004-06-09 00:34:46 +0000931 struct tsec_private *priv = (struct tsec_private *)dev->priv;
932 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000933
Jon Loeliger89875e92006-10-10 17:03:43 -0500934 while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
wdenk42d1f032003-10-15 23:53:47 +0000935
936 length = rtx.rxbd[rxIdx].length;
937
938 /* Send the packet up if there were no errors */
939 if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
940 NetReceive(NetRxPackets[rxIdx], length - 4);
wdenk97d80fc2004-06-09 00:34:46 +0000941 } else {
942 printf("Got error %x\n",
Jon Loeliger89875e92006-10-10 17:03:43 -0500943 (rtx.rxbd[rxIdx].status & RXBD_STATS));
wdenk42d1f032003-10-15 23:53:47 +0000944 }
945
946 rtx.rxbd[rxIdx].length = 0;
947
948 /* Set the wrap bit if this is the last element in the list */
Jon Loeliger89875e92006-10-10 17:03:43 -0500949 rtx.rxbd[rxIdx].status =
950 RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
wdenk42d1f032003-10-15 23:53:47 +0000951
952 rxIdx = (rxIdx + 1) % PKTBUFSRX;
953 }
954
Jon Loeliger89875e92006-10-10 17:03:43 -0500955 if (regs->ievent & IEVENT_BSY) {
wdenk42d1f032003-10-15 23:53:47 +0000956 regs->ievent = IEVENT_BSY;
957 regs->rstat = RSTAT_CLEAR_RHALT;
958 }
959
960 return -1;
961
962}
963
wdenk97d80fc2004-06-09 00:34:46 +0000964/* Stop the interface */
Jon Loeliger89875e92006-10-10 17:03:43 -0500965static void tsec_halt(struct eth_device *dev)
wdenk42d1f032003-10-15 23:53:47 +0000966{
wdenk97d80fc2004-06-09 00:34:46 +0000967 struct tsec_private *priv = (struct tsec_private *)dev->priv;
968 volatile tsec_t *regs = priv->regs;
wdenk42d1f032003-10-15 23:53:47 +0000969
970 regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
971 regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
972
Jon Loeliger89875e92006-10-10 17:03:43 -0500973 while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
wdenk42d1f032003-10-15 23:53:47 +0000974
975 regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
976
wdenk97d80fc2004-06-09 00:34:46 +0000977 /* Shut down the PHY, as needed */
Ben Warren4653f912006-10-26 14:38:25 -0400978 if(priv->phyinfo)
979 phy_run_commands(priv, priv->phyinfo->shutdown);
wdenk42d1f032003-10-15 23:53:47 +0000980}
wdenk7abf0c52004-04-18 21:45:42 +0000981
Andy Flemingc7e717e2007-08-03 04:05:25 -0500982struct phy_info phy_info_M88E1149S = {
Wolfgang Denk5728be32007-08-06 01:01:49 +0200983 0x1410ca,
984 "Marvell 88E1149S",
985 4,
986 (struct phy_cmd[]){ /* config */
987 /* Reset and configure the PHY */
988 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
989 {0x1d, 0x1f, NULL},
990 {0x1e, 0x200c, NULL},
991 {0x1d, 0x5, NULL},
992 {0x1e, 0x0, NULL},
993 {0x1e, 0x100, NULL},
994 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
995 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
996 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
997 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
998 {miim_end,}
999 },
1000 (struct phy_cmd[]){ /* startup */
1001 /* Status is read once to clear old link state */
1002 {MIIM_STATUS, miim_read, NULL},
1003 /* Auto-negotiate */
1004 {MIIM_STATUS, miim_read, &mii_parse_sr},
1005 /* Read the status */
1006 {MIIM_88E1011_PHY_STATUS, miim_read,
1007 &mii_parse_88E1011_psr},
1008 {miim_end,}
1009 },
1010 (struct phy_cmd[]){ /* shutdown */
1011 {miim_end,}
1012 },
Andy Flemingc7e717e2007-08-03 04:05:25 -05001013};
1014
Paul Gortmaker91e25762007-01-16 11:38:14 -05001015/* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
1016struct phy_info phy_info_BCM5461S = {
1017 0x02060c1, /* 5461 ID */
1018 "Broadcom BCM5461S",
1019 0, /* not clear to me what minor revisions we can shift away */
1020 (struct phy_cmd[]) { /* config */
1021 /* Reset and configure the PHY */
1022 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1023 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1024 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1025 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1026 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1027 {miim_end,}
1028 },
1029 (struct phy_cmd[]) { /* startup */
1030 /* Status is read once to clear old link state */
1031 {MIIM_STATUS, miim_read, NULL},
1032 /* Auto-negotiate */
1033 {MIIM_STATUS, miim_read, &mii_parse_sr},
1034 /* Read the status */
1035 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1036 {miim_end,}
1037 },
1038 (struct phy_cmd[]) { /* shutdown */
1039 {miim_end,}
1040 },
1041};
1042
Joe Hammanc3243cf2007-04-30 16:47:28 -05001043struct phy_info phy_info_BCM5464S = {
1044 0x02060b1, /* 5464 ID */
1045 "Broadcom BCM5464S",
1046 0, /* not clear to me what minor revisions we can shift away */
1047 (struct phy_cmd[]) { /* config */
1048 /* Reset and configure the PHY */
1049 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1050 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1051 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1052 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1053 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1054 {miim_end,}
1055 },
1056 (struct phy_cmd[]) { /* startup */
1057 /* Status is read once to clear old link state */
1058 {MIIM_STATUS, miim_read, NULL},
1059 /* Auto-negotiate */
1060 {MIIM_STATUS, miim_read, &mii_parse_sr},
1061 /* Read the status */
1062 {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
1063 {miim_end,}
1064 },
1065 (struct phy_cmd[]) { /* shutdown */
1066 {miim_end,}
1067 },
1068};
1069
wdenk97d80fc2004-06-09 00:34:46 +00001070struct phy_info phy_info_M88E1011S = {
1071 0x01410c6,
1072 "Marvell 88E1011S",
1073 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001074 (struct phy_cmd[]){ /* config */
1075 /* Reset and configure the PHY */
1076 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1077 {0x1d, 0x1f, NULL},
1078 {0x1e, 0x200c, NULL},
1079 {0x1d, 0x5, NULL},
1080 {0x1e, 0x0, NULL},
1081 {0x1e, 0x100, NULL},
1082 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1083 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1084 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1085 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1086 {miim_end,}
1087 },
1088 (struct phy_cmd[]){ /* startup */
1089 /* Status is read once to clear old link state */
1090 {MIIM_STATUS, miim_read, NULL},
1091 /* Auto-negotiate */
1092 {MIIM_STATUS, miim_read, &mii_parse_sr},
1093 /* Read the status */
1094 {MIIM_88E1011_PHY_STATUS, miim_read,
1095 &mii_parse_88E1011_psr},
1096 {miim_end,}
1097 },
1098 (struct phy_cmd[]){ /* shutdown */
1099 {miim_end,}
1100 },
wdenk97d80fc2004-06-09 00:34:46 +00001101};
1102
wdenk9d46ea42005-03-14 23:56:42 +00001103struct phy_info phy_info_M88E1111S = {
1104 0x01410cc,
1105 "Marvell 88E1111S",
1106 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001107 (struct phy_cmd[]){ /* config */
1108 /* Reset and configure the PHY */
1109 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
Dave Liu19580e62007-09-18 12:37:57 +08001110 {0x1b, 0x848f, &mii_m88e1111s_setmode},
Nick Spencef484dc72006-09-07 07:39:46 -07001111 {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
Jon Loeliger89875e92006-10-10 17:03:43 -05001112 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1113 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1114 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1115 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1116 {miim_end,}
1117 },
1118 (struct phy_cmd[]){ /* startup */
1119 /* Status is read once to clear old link state */
1120 {MIIM_STATUS, miim_read, NULL},
1121 /* Auto-negotiate */
1122 {MIIM_STATUS, miim_read, &mii_parse_sr},
1123 /* Read the status */
1124 {MIIM_88E1011_PHY_STATUS, miim_read,
1125 &mii_parse_88E1011_psr},
1126 {miim_end,}
1127 },
1128 (struct phy_cmd[]){ /* shutdown */
1129 {miim_end,}
1130 },
wdenk9d46ea42005-03-14 23:56:42 +00001131};
1132
Ron Madrid290ef642008-05-23 15:37:05 -07001133struct phy_info phy_info_M88E1118 = {
1134 0x01410e1,
1135 "Marvell 88E1118",
1136 4,
1137 (struct phy_cmd[]){ /* config */
1138 /* Reset and configure the PHY */
1139 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1140 {0x16, 0x0002, NULL}, /* Change Page Number */
1141 {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
1142 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1143 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1144 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1145 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1146 {miim_end,}
1147 },
1148 (struct phy_cmd[]){ /* startup */
1149 {0x16, 0x0000, NULL}, /* Change Page Number */
1150 /* Status is read once to clear old link state */
1151 {MIIM_STATUS, miim_read, NULL},
1152 /* Auto-negotiate */
1153 /* Read the status */
1154 {MIIM_88E1011_PHY_STATUS, miim_read,
1155 &mii_parse_88E1011_psr},
1156 {miim_end,}
1157 },
1158 (struct phy_cmd[]){ /* shutdown */
1159 {miim_end,}
1160 },
1161};
1162
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001163/*
1164 * Since to access LED register we need do switch the page, we
1165 * do LED configuring in the miim_read-like function as follows
1166 */
1167uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
1168{
1169 uint pg;
1170
1171 /* Switch the page to access the led register */
1172 pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
1173 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
1174
1175 /* Configure leds */
1176 write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
1177 MIIM_88E1121_PHY_LED_DEF);
1178
1179 /* Restore the page pointer */
1180 write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
1181 return 0;
1182}
1183
1184struct phy_info phy_info_M88E1121R = {
1185 0x01410cb,
1186 "Marvell 88E1121R",
1187 4,
1188 (struct phy_cmd[]){ /* config */
1189 /* Reset and configure the PHY */
1190 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1191 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1192 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1193 /* Configure leds */
1194 {MIIM_88E1121_PHY_LED_CTRL, miim_read,
1195 &mii_88E1121_set_led},
1196 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1197 {miim_end,}
1198 },
1199 (struct phy_cmd[]){ /* startup */
1200 /* Status is read once to clear old link state */
1201 {MIIM_STATUS, miim_read, NULL},
1202 {MIIM_STATUS, miim_read, &mii_parse_sr},
1203 {MIIM_STATUS, miim_read, &mii_parse_link},
1204 {miim_end,}
1205 },
1206 (struct phy_cmd[]){ /* shutdown */
1207 {miim_end,}
1208 },
1209};
1210
Andy Fleming09f3e092006-09-13 10:34:18 -05001211static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
1212{
Andy Fleming09f3e092006-09-13 10:34:18 -05001213 uint mii_data = read_phy_reg(priv, mii_reg);
1214
Andy Fleming09f3e092006-09-13 10:34:18 -05001215 /* Setting MIIM_88E1145_PHY_EXT_CR */
1216 if (priv->flags & TSEC_REDUCED)
1217 return mii_data |
Jon Loeliger89875e92006-10-10 17:03:43 -05001218 MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
Andy Fleming09f3e092006-09-13 10:34:18 -05001219 else
1220 return mii_data;
1221}
1222
1223static struct phy_info phy_info_M88E1145 = {
1224 0x01410cd,
1225 "Marvell 88E1145",
1226 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001227 (struct phy_cmd[]){ /* config */
Andy Fleming7507d562007-05-08 17:23:02 -05001228 /* Reset the PHY */
1229 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1230
Jon Loeliger89875e92006-10-10 17:03:43 -05001231 /* Errata E0, E1 */
1232 {29, 0x001b, NULL},
1233 {30, 0x418f, NULL},
1234 {29, 0x0016, NULL},
1235 {30, 0xa2da, NULL},
Andy Fleming09f3e092006-09-13 10:34:18 -05001236
Andy Fleming7507d562007-05-08 17:23:02 -05001237 /* Configure the PHY */
Jon Loeliger89875e92006-10-10 17:03:43 -05001238 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1239 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1240 {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
1241 NULL},
1242 {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
1243 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1244 {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
1245 {miim_end,}
1246 },
1247 (struct phy_cmd[]){ /* startup */
1248 /* Status is read once to clear old link state */
1249 {MIIM_STATUS, miim_read, NULL},
1250 /* Auto-negotiate */
1251 {MIIM_STATUS, miim_read, &mii_parse_sr},
1252 {MIIM_88E1111_PHY_LED_CONTROL,
1253 MIIM_88E1111_PHY_LED_DIRECT, NULL},
1254 /* Read the Status */
1255 {MIIM_88E1011_PHY_STATUS, miim_read,
1256 &mii_parse_88E1011_psr},
1257 {miim_end,}
1258 },
1259 (struct phy_cmd[]){ /* shutdown */
1260 {miim_end,}
1261 },
Andy Fleming09f3e092006-09-13 10:34:18 -05001262};
1263
wdenk97d80fc2004-06-09 00:34:46 +00001264struct phy_info phy_info_cis8204 = {
1265 0x3f11,
1266 "Cicada Cis8204",
1267 6,
Jon Loeliger89875e92006-10-10 17:03:43 -05001268 (struct phy_cmd[]){ /* config */
1269 /* Override PHY config settings */
1270 {MIIM_CIS8201_AUX_CONSTAT,
1271 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1272 /* Configure some basic stuff */
1273 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1274 {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
1275 &mii_cis8204_fixled},
1276 {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
1277 &mii_cis8204_setmode},
1278 {miim_end,}
1279 },
1280 (struct phy_cmd[]){ /* startup */
1281 /* Read the Status (2x to make sure link is right) */
1282 {MIIM_STATUS, miim_read, NULL},
1283 /* Auto-negotiate */
1284 {MIIM_STATUS, miim_read, &mii_parse_sr},
1285 /* Read the status */
1286 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1287 &mii_parse_cis8201},
1288 {miim_end,}
1289 },
1290 (struct phy_cmd[]){ /* shutdown */
1291 {miim_end,}
1292 },
wdenk97d80fc2004-06-09 00:34:46 +00001293};
1294
1295/* Cicada 8201 */
1296struct phy_info phy_info_cis8201 = {
1297 0xfc41,
1298 "CIS8201",
1299 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001300 (struct phy_cmd[]){ /* config */
1301 /* Override PHY config settings */
1302 {MIIM_CIS8201_AUX_CONSTAT,
1303 MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
1304 /* Set up the interface mode */
1305 {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
1306 NULL},
1307 /* Configure some basic stuff */
1308 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1309 {miim_end,}
1310 },
1311 (struct phy_cmd[]){ /* startup */
1312 /* Read the Status (2x to make sure link is right) */
1313 {MIIM_STATUS, miim_read, NULL},
1314 /* Auto-negotiate */
1315 {MIIM_STATUS, miim_read, &mii_parse_sr},
1316 /* Read the status */
1317 {MIIM_CIS8201_AUX_CONSTAT, miim_read,
1318 &mii_parse_cis8201},
1319 {miim_end,}
1320 },
1321 (struct phy_cmd[]){ /* shutdown */
1322 {miim_end,}
1323 },
wdenk97d80fc2004-06-09 00:34:46 +00001324};
Jon Loeligerdebb7352006-04-26 17:58:56 -05001325struct phy_info phy_info_VSC8244 = {
Jon Loeliger89875e92006-10-10 17:03:43 -05001326 0x3f1b,
1327 "Vitesse VSC8244",
1328 6,
1329 (struct phy_cmd[]){ /* config */
1330 /* Override PHY config settings */
1331 /* Configure some basic stuff */
1332 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1333 {miim_end,}
1334 },
1335 (struct phy_cmd[]){ /* startup */
1336 /* Read the Status (2x to make sure link is right) */
1337 {MIIM_STATUS, miim_read, NULL},
1338 /* Auto-negotiate */
1339 {MIIM_STATUS, miim_read, &mii_parse_sr},
1340 /* Read the status */
1341 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1342 &mii_parse_vsc8244},
1343 {miim_end,}
1344 },
1345 (struct phy_cmd[]){ /* shutdown */
1346 {miim_end,}
1347 },
Jon Loeligerdebb7352006-04-26 17:58:56 -05001348};
wdenk97d80fc2004-06-09 00:34:46 +00001349
Tor Krill2d934ea2008-03-28 15:29:45 +01001350struct phy_info phy_info_VSC8601 = {
1351 0x00007042,
1352 "Vitesse VSC8601",
1353 4,
1354 (struct phy_cmd[]){ /* config */
1355 /* Override PHY config settings */
1356 /* Configure some basic stuff */
1357 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1358#ifdef CFG_VSC8601_SKEWFIX
1359 {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
Wolfgang Denk7c0773f2008-05-04 00:35:15 +02001360#if defined(CFG_VSC8601_SKEW_TX) && defined(CFG_VSC8601_SKEW_RX)
Andre Schwarz9acde122008-04-29 19:18:32 +02001361 {MIIM_EXT_PAGE_ACCESS,1,NULL},
1362#define VSC8101_SKEW (CFG_VSC8601_SKEW_TX<<14)|(CFG_VSC8601_SKEW_RX<<12)
1363 {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
1364 {MIIM_EXT_PAGE_ACCESS,0,NULL},
1365#endif
Tor Krill2d934ea2008-03-28 15:29:45 +01001366#endif
1367 {miim_end,}
1368 },
1369 (struct phy_cmd[]){ /* startup */
1370 /* Read the Status (2x to make sure link is right) */
1371 {MIIM_STATUS, miim_read, NULL},
1372 /* Auto-negotiate */
1373 {MIIM_STATUS, miim_read, &mii_parse_sr},
1374 /* Read the status */
1375 {MIIM_VSC8244_AUX_CONSTAT, miim_read,
1376 &mii_parse_vsc8244},
1377 {miim_end,}
1378 },
1379 (struct phy_cmd[]){ /* shutdown */
1380 {miim_end,}
1381 },
1382};
1383
1384
wdenk97d80fc2004-06-09 00:34:46 +00001385struct phy_info phy_info_dm9161 = {
1386 0x0181b88,
1387 "Davicom DM9161E",
1388 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001389 (struct phy_cmd[]){ /* config */
1390 {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
1391 /* Do not bypass the scrambler/descrambler */
1392 {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
1393 /* Clear 10BTCSR to default */
1394 {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
1395 NULL},
1396 /* Configure some basic stuff */
1397 {MIIM_CONTROL, MIIM_CR_INIT, NULL},
1398 /* Restart Auto Negotiation */
1399 {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
1400 {miim_end,}
1401 },
1402 (struct phy_cmd[]){ /* startup */
1403 /* Status is read once to clear old link state */
1404 {MIIM_STATUS, miim_read, NULL},
1405 /* Auto-negotiate */
1406 {MIIM_STATUS, miim_read, &mii_parse_sr},
1407 /* Read the status */
1408 {MIIM_DM9161_SCSR, miim_read,
1409 &mii_parse_dm9161_scsr},
1410 {miim_end,}
1411 },
1412 (struct phy_cmd[]){ /* shutdown */
1413 {miim_end,}
1414 },
wdenk97d80fc2004-06-09 00:34:46 +00001415};
David Updegraffaf1c2b82007-04-20 14:34:48 -05001416/* a generic flavor. */
1417struct phy_info phy_info_generic = {
1418 0,
1419 "Unknown/Generic PHY",
1420 32,
1421 (struct phy_cmd[]) { /* config */
1422 {PHY_BMCR, PHY_BMCR_RESET, NULL},
1423 {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
1424 {miim_end,}
1425 },
1426 (struct phy_cmd[]) { /* startup */
1427 {PHY_BMSR, miim_read, NULL},
1428 {PHY_BMSR, miim_read, &mii_parse_sr},
1429 {PHY_BMSR, miim_read, &mii_parse_link},
1430 {miim_end,}
1431 },
1432 (struct phy_cmd[]) { /* shutdown */
1433 {miim_end,}
1434 }
1435};
1436
wdenk97d80fc2004-06-09 00:34:46 +00001437
wdenk3dd7f0f2005-04-04 23:43:44 +00001438uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
1439{
wdenk3c2b3d42005-04-05 23:32:21 +00001440 unsigned int speed;
1441 if (priv->link) {
1442 speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
wdenk3dd7f0f2005-04-04 23:43:44 +00001443
wdenk3c2b3d42005-04-05 23:32:21 +00001444 switch (speed) {
1445 case MIIM_LXT971_SR2_10HDX:
1446 priv->speed = 10;
1447 priv->duplexity = 0;
1448 break;
1449 case MIIM_LXT971_SR2_10FDX:
1450 priv->speed = 10;
1451 priv->duplexity = 1;
1452 break;
1453 case MIIM_LXT971_SR2_100HDX:
1454 priv->speed = 100;
1455 priv->duplexity = 0;
urwithsughosh@gmail.comcd2d1602007-09-10 14:54:56 -04001456 break;
wdenk3c2b3d42005-04-05 23:32:21 +00001457 default:
1458 priv->speed = 100;
1459 priv->duplexity = 1;
wdenk3c2b3d42005-04-05 23:32:21 +00001460 }
1461 } else {
1462 priv->speed = 0;
1463 priv->duplexity = 0;
1464 }
wdenk3dd7f0f2005-04-04 23:43:44 +00001465
wdenk3c2b3d42005-04-05 23:32:21 +00001466 return 0;
wdenk3dd7f0f2005-04-04 23:43:44 +00001467}
1468
wdenk9d46ea42005-03-14 23:56:42 +00001469static struct phy_info phy_info_lxt971 = {
1470 0x0001378e,
1471 "LXT971",
1472 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001473 (struct phy_cmd[]){ /* config */
1474 {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
1475 {miim_end,}
1476 },
1477 (struct phy_cmd[]){ /* startup - enable interrupts */
1478 /* { 0x12, 0x00f2, NULL }, */
1479 {MIIM_STATUS, miim_read, NULL},
1480 {MIIM_STATUS, miim_read, &mii_parse_sr},
1481 {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
1482 {miim_end,}
1483 },
1484 (struct phy_cmd[]){ /* shutdown - disable interrupts */
1485 {miim_end,}
1486 },
wdenk9d46ea42005-03-14 23:56:42 +00001487};
1488
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001489/* Parse the DP83865's link and auto-neg status register for speed and duplex
Jon Loeliger89875e92006-10-10 17:03:43 -05001490 * information
1491 */
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001492uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
1493{
1494 switch (mii_reg & MIIM_DP83865_SPD_MASK) {
1495
1496 case MIIM_DP83865_SPD_1000:
1497 priv->speed = 1000;
1498 break;
1499
1500 case MIIM_DP83865_SPD_100:
1501 priv->speed = 100;
1502 break;
1503
1504 default:
1505 priv->speed = 10;
1506 break;
1507
1508 }
1509
1510 if (mii_reg & MIIM_DP83865_DPX_FULL)
1511 priv->duplexity = 1;
1512 else
1513 priv->duplexity = 0;
1514
1515 return 0;
1516}
1517
1518struct phy_info phy_info_dp83865 = {
1519 0x20005c7,
1520 "NatSemi DP83865",
1521 4,
Jon Loeliger89875e92006-10-10 17:03:43 -05001522 (struct phy_cmd[]){ /* config */
1523 {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
1524 {miim_end,}
1525 },
1526 (struct phy_cmd[]){ /* startup */
1527 /* Status is read once to clear old link state */
1528 {MIIM_STATUS, miim_read, NULL},
1529 /* Auto-negotiate */
1530 {MIIM_STATUS, miim_read, &mii_parse_sr},
1531 /* Read the link and auto-neg status */
1532 {MIIM_DP83865_LANR, miim_read,
1533 &mii_parse_dp83865_lanr},
1534 {miim_end,}
1535 },
1536 (struct phy_cmd[]){ /* shutdown */
1537 {miim_end,}
1538 },
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001539};
1540
Dave Liu18ee3202008-01-11 18:45:28 +08001541struct phy_info phy_info_rtl8211b = {
1542 0x001cc91,
1543 "RealTek RTL8211B",
1544 4,
1545 (struct phy_cmd[]){ /* config */
1546 /* Reset and configure the PHY */
1547 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1548 {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
1549 {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
1550 {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
1551 {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
1552 {miim_end,}
1553 },
1554 (struct phy_cmd[]){ /* startup */
1555 /* Status is read once to clear old link state */
1556 {MIIM_STATUS, miim_read, NULL},
1557 /* Auto-negotiate */
1558 {MIIM_STATUS, miim_read, &mii_parse_sr},
1559 /* Read the status */
1560 {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
1561 {miim_end,}
1562 },
1563 (struct phy_cmd[]){ /* shutdown */
1564 {miim_end,}
1565 },
1566};
1567
wdenk97d80fc2004-06-09 00:34:46 +00001568struct phy_info *phy_info[] = {
wdenk97d80fc2004-06-09 00:34:46 +00001569 &phy_info_cis8204,
Timur Tabi2ad6b512006-10-31 18:44:42 -06001570 &phy_info_cis8201,
Paul Gortmaker91e25762007-01-16 11:38:14 -05001571 &phy_info_BCM5461S,
Joe Hammanc3243cf2007-04-30 16:47:28 -05001572 &phy_info_BCM5464S,
wdenk97d80fc2004-06-09 00:34:46 +00001573 &phy_info_M88E1011S,
wdenk9d46ea42005-03-14 23:56:42 +00001574 &phy_info_M88E1111S,
Ron Madrid290ef642008-05-23 15:37:05 -07001575 &phy_info_M88E1118,
Sergei Poselenovd23dc392008-06-06 15:52:44 +02001576 &phy_info_M88E1121R,
Andy Fleming09f3e092006-09-13 10:34:18 -05001577 &phy_info_M88E1145,
Wolfgang Denk5728be32007-08-06 01:01:49 +02001578 &phy_info_M88E1149S,
wdenk97d80fc2004-06-09 00:34:46 +00001579 &phy_info_dm9161,
wdenk9d46ea42005-03-14 23:56:42 +00001580 &phy_info_lxt971,
Jon Loeligerdebb7352006-04-26 17:58:56 -05001581 &phy_info_VSC8244,
Tor Krill2d934ea2008-03-28 15:29:45 +01001582 &phy_info_VSC8601,
Wolfgang Denkbe5048f2006-03-12 22:50:55 +01001583 &phy_info_dp83865,
Dave Liu18ee3202008-01-11 18:45:28 +08001584 &phy_info_rtl8211b,
David Updegraffaf1c2b82007-04-20 14:34:48 -05001585 &phy_info_generic,
wdenk97d80fc2004-06-09 00:34:46 +00001586 NULL
1587};
1588
wdenk97d80fc2004-06-09 00:34:46 +00001589/* Grab the identifier of the device's PHY, and search through
wdenk9d46ea42005-03-14 23:56:42 +00001590 * all of the known PHYs to see if one matches. If so, return
Jon Loeliger89875e92006-10-10 17:03:43 -05001591 * it, if not, return NULL
1592 */
1593struct phy_info *get_phy_info(struct eth_device *dev)
wdenk97d80fc2004-06-09 00:34:46 +00001594{
1595 struct tsec_private *priv = (struct tsec_private *)dev->priv;
1596 uint phy_reg, phy_ID;
1597 int i;
1598 struct phy_info *theInfo = NULL;
1599
1600 /* Grab the bits from PHYIR1, and put them in the upper half */
1601 phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
1602 phy_ID = (phy_reg & 0xffff) << 16;
1603
1604 /* Grab the bits from PHYIR2, and put them in the lower half */
1605 phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
1606 phy_ID |= (phy_reg & 0xffff);
1607
1608 /* loop through all the known PHY types, and find one that */
1609 /* matches the ID we read from the PHY. */
Jon Loeliger89875e92006-10-10 17:03:43 -05001610 for (i = 0; phy_info[i]; i++) {
Andy Fleming2a3cee42007-05-09 00:54:20 -05001611 if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
wdenk97d80fc2004-06-09 00:34:46 +00001612 theInfo = phy_info[i];
Andy Fleming2a3cee42007-05-09 00:54:20 -05001613 break;
1614 }
wdenk97d80fc2004-06-09 00:34:46 +00001615 }
1616
Jon Loeliger89875e92006-10-10 17:03:43 -05001617 if (theInfo == NULL) {
wdenk97d80fc2004-06-09 00:34:46 +00001618 printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
1619 return NULL;
1620 } else {
Stefan Roese5810dc32005-09-21 18:20:22 +02001621 debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
wdenk97d80fc2004-06-09 00:34:46 +00001622 }
1623
1624 return theInfo;
1625}
1626
wdenk97d80fc2004-06-09 00:34:46 +00001627/* Execute the given series of commands on the given device's
Jon Loeliger89875e92006-10-10 17:03:43 -05001628 * PHY, running functions as necessary
1629 */
wdenk97d80fc2004-06-09 00:34:46 +00001630void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
1631{
1632 int i;
1633 uint result;
1634 volatile tsec_t *phyregs = priv->phyregs;
1635
1636 phyregs->miimcfg = MIIMCFG_RESET;
1637
1638 phyregs->miimcfg = MIIMCFG_INIT_VALUE;
1639
Jon Loeliger89875e92006-10-10 17:03:43 -05001640 while (phyregs->miimind & MIIMIND_BUSY) ;
wdenk97d80fc2004-06-09 00:34:46 +00001641
Jon Loeliger89875e92006-10-10 17:03:43 -05001642 for (i = 0; cmd->mii_reg != miim_end; i++) {
1643 if (cmd->mii_data == miim_read) {
wdenk97d80fc2004-06-09 00:34:46 +00001644 result = read_phy_reg(priv, cmd->mii_reg);
1645
Jon Loeliger89875e92006-10-10 17:03:43 -05001646 if (cmd->funct != NULL)
1647 (*(cmd->funct)) (result, priv);
wdenk97d80fc2004-06-09 00:34:46 +00001648
1649 } else {
Jon Loeliger89875e92006-10-10 17:03:43 -05001650 if (cmd->funct != NULL)
1651 result = (*(cmd->funct)) (cmd->mii_reg, priv);
wdenk97d80fc2004-06-09 00:34:46 +00001652 else
1653 result = cmd->mii_data;
1654
1655 write_phy_reg(priv, cmd->mii_reg, result);
1656
1657 }
1658 cmd++;
1659 }
1660}
1661
wdenk97d80fc2004-06-09 00:34:46 +00001662/* Relocate the function pointers in the phy cmd lists */
1663static void relocate_cmds(void)
1664{
1665 struct phy_cmd **cmdlistptr;
1666 struct phy_cmd *cmd;
Jon Loeliger89875e92006-10-10 17:03:43 -05001667 int i, j, k;
wdenk97d80fc2004-06-09 00:34:46 +00001668
Jon Loeliger89875e92006-10-10 17:03:43 -05001669 for (i = 0; phy_info[i]; i++) {
wdenk97d80fc2004-06-09 00:34:46 +00001670 /* First thing's first: relocate the pointers to the
1671 * PHY command structures (the structs were done) */
Jon Loeliger89875e92006-10-10 17:03:43 -05001672 phy_info[i] = (struct phy_info *)((uint) phy_info[i]
1673 + gd->reloc_off);
wdenk97d80fc2004-06-09 00:34:46 +00001674 phy_info[i]->name += gd->reloc_off;
1675 phy_info[i]->config =
Jon Loeliger89875e92006-10-10 17:03:43 -05001676 (struct phy_cmd *)((uint) phy_info[i]->config
1677 + gd->reloc_off);
wdenk97d80fc2004-06-09 00:34:46 +00001678 phy_info[i]->startup =
Jon Loeliger89875e92006-10-10 17:03:43 -05001679 (struct phy_cmd *)((uint) phy_info[i]->startup
1680 + gd->reloc_off);
wdenk97d80fc2004-06-09 00:34:46 +00001681 phy_info[i]->shutdown =
Jon Loeliger89875e92006-10-10 17:03:43 -05001682 (struct phy_cmd *)((uint) phy_info[i]->shutdown
1683 + gd->reloc_off);
wdenk97d80fc2004-06-09 00:34:46 +00001684
1685 cmdlistptr = &phy_info[i]->config;
Jon Loeliger89875e92006-10-10 17:03:43 -05001686 j = 0;
1687 for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
1688 k = 0;
1689 for (cmd = *cmdlistptr;
1690 cmd->mii_reg != miim_end;
1691 cmd++) {
wdenk97d80fc2004-06-09 00:34:46 +00001692 /* Only relocate non-NULL pointers */
Jon Loeliger89875e92006-10-10 17:03:43 -05001693 if (cmd->funct)
wdenk97d80fc2004-06-09 00:34:46 +00001694 cmd->funct += gd->reloc_off;
1695
1696 k++;
1697 }
1698 j++;
1699 }
1700 }
1701
1702 relocated = 1;
1703}
1704
Jon Loeligercb51c0b2007-07-09 17:39:42 -05001705#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001706 && !defined(BITBANGMII)
wdenk97d80fc2004-06-09 00:34:46 +00001707
wdenk7abf0c52004-04-18 21:45:42 +00001708/*
1709 * Read a MII PHY register.
1710 *
1711 * Returns:
wdenk97d80fc2004-06-09 00:34:46 +00001712 * 0 on success
wdenk7abf0c52004-04-18 21:45:42 +00001713 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001714static int tsec_miiphy_read(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -05001715 unsigned char reg, unsigned short *value)
wdenk7abf0c52004-04-18 21:45:42 +00001716{
wdenk97d80fc2004-06-09 00:34:46 +00001717 unsigned short ret;
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +00001718 struct tsec_private *priv = privlist[0];
wdenk7abf0c52004-04-18 21:45:42 +00001719
Jon Loeliger89875e92006-10-10 17:03:43 -05001720 if (NULL == priv) {
wdenk97d80fc2004-06-09 00:34:46 +00001721 printf("Can't read PHY at address %d\n", addr);
1722 return -1;
1723 }
1724
Andy Fleming2abe3612008-08-31 16:33:27 -05001725 ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
wdenk97d80fc2004-06-09 00:34:46 +00001726 *value = ret;
wdenk7abf0c52004-04-18 21:45:42 +00001727
1728 return 0;
1729}
1730
1731/*
1732 * Write a MII PHY register.
1733 *
1734 * Returns:
wdenk97d80fc2004-06-09 00:34:46 +00001735 * 0 on success
wdenk7abf0c52004-04-18 21:45:42 +00001736 */
Marian Balakowicz63ff0042005-10-28 22:30:33 +02001737static int tsec_miiphy_write(char *devname, unsigned char addr,
Jon Loeliger89875e92006-10-10 17:03:43 -05001738 unsigned char reg, unsigned short value)
wdenk7abf0c52004-04-18 21:45:42 +00001739{
michael.firth@bt.com55fe7c52008-01-16 11:40:51 +00001740 struct tsec_private *priv = privlist[0];
wdenk7abf0c52004-04-18 21:45:42 +00001741
Jon Loeliger89875e92006-10-10 17:03:43 -05001742 if (NULL == priv) {
wdenk97d80fc2004-06-09 00:34:46 +00001743 printf("Can't write PHY at address %d\n", addr);
1744 return -1;
1745 }
1746
Andy Fleming2abe3612008-08-31 16:33:27 -05001747 tsec_local_mdio_write(priv->phyregs, addr, reg, value);
wdenk7abf0c52004-04-18 21:45:42 +00001748
1749 return 0;
1750}
wdenk97d80fc2004-06-09 00:34:46 +00001751
Jon Loeligercb51c0b2007-07-09 17:39:42 -05001752#endif
wdenk97d80fc2004-06-09 00:34:46 +00001753
David Updegraff53a5c422007-06-11 10:41:07 -05001754#ifdef CONFIG_MCAST_TFTP
1755
1756/* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
1757
1758/* Set the appropriate hash bit for the given addr */
1759
1760/* The algorithm works like so:
1761 * 1) Take the Destination Address (ie the multicast address), and
1762 * do a CRC on it (little endian), and reverse the bits of the
1763 * result.
1764 * 2) Use the 8 most significant bits as a hash into a 256-entry
1765 * table. The table is controlled through 8 32-bit registers:
1766 * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
1767 * gaddr7. This means that the 3 most significant bits in the
1768 * hash index which gaddr register to use, and the 5 other bits
1769 * indicate which bit (assuming an IBM numbering scheme, which
1770 * for PowerPC (tm) is usually the case) in the tregister holds
1771 * the entry. */
1772static int
1773tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
1774{
1775 struct tsec_private *priv = privlist[1];
1776 volatile tsec_t *regs = priv->regs;
1777 volatile u32 *reg_array, value;
1778 u8 result, whichbit, whichreg;
1779
1780 result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
1781 whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
1782 whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
1783 value = (1 << (31-whichbit));
1784
1785 reg_array = &(regs->hash.gaddr0);
1786
1787 if (set) {
1788 reg_array[whichreg] |= value;
1789 } else {
1790 reg_array[whichreg] &= ~value;
1791 }
1792 return 0;
1793}
1794#endif /* Multicast TFTP ? */