wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 1 | /* |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 2 | * Freescale Three Speed Ethernet Controller driver |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 3 | * |
| 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 Fleming | 81f481c | 2007-04-23 02:24:28 -0500 | [diff] [blame] | 8 | * Copyright 2004, 2007 Freescale Semiconductor, Inc. |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 9 | * (C) Copyright 2003, Motorola, Inc. |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 10 | * author Andy Fleming |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <config.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 15 | #include <common.h> |
| 16 | #include <malloc.h> |
| 17 | #include <net.h> |
| 18 | #include <command.h> |
Andy Fleming | dd3d1f5 | 2008-08-31 16:33:25 -0500 | [diff] [blame] | 19 | #include <tsec.h> |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 20 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 21 | #include "miiphy.h" |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 22 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 25 | #define TX_BUF_CNT 2 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 26 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 27 | static uint rxIdx; /* index of the current RX buffer */ |
| 28 | static uint txIdx; /* index of the current TX buffer */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 29 | |
| 30 | typedef volatile struct rtxbd { |
| 31 | txbd8_t txbd[TX_BUF_CNT]; |
| 32 | rxbd8_t rxbd[PKTBUFSRX]; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 33 | } RTXBD; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 34 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 35 | #define MAXCONTROLLERS (8) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 36 | |
| 37 | static int relocated = 0; |
| 38 | |
| 39 | static struct tsec_private *privlist[MAXCONTROLLERS]; |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 40 | static int num_tsecs = 0; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 41 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 42 | #ifdef __GNUC__ |
| 43 | static RTXBD rtx __attribute__ ((aligned(8))); |
| 44 | #else |
| 45 | #error "rtx must be 64-bit aligned" |
| 46 | #endif |
| 47 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 48 | static int tsec_send(struct eth_device *dev, |
| 49 | volatile void *packet, int length); |
| 50 | static int tsec_recv(struct eth_device *dev); |
| 51 | static int tsec_init(struct eth_device *dev, bd_t * bd); |
| 52 | static void tsec_halt(struct eth_device *dev); |
| 53 | static void init_registers(volatile tsec_t * regs); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 54 | static void startup_tsec(struct eth_device *dev); |
| 55 | static int init_phy(struct eth_device *dev); |
| 56 | void write_phy_reg(struct tsec_private *priv, uint regnum, uint value); |
| 57 | uint read_phy_reg(struct tsec_private *priv, uint regnum); |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 58 | struct phy_info *get_phy_info(struct eth_device *dev); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 59 | void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd); |
| 60 | static void adjust_link(struct eth_device *dev); |
| 61 | static void relocate_cmds(void); |
Wolfgang Denk | 409ecdc | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 62 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
| 63 | && !defined(BITBANGMII) |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 64 | static int tsec_miiphy_write(char *devname, unsigned char addr, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 65 | unsigned char reg, unsigned short value); |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 66 | static int tsec_miiphy_read(char *devname, unsigned char addr, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 67 | unsigned char reg, unsigned short *value); |
Wolfgang Denk | 409ecdc | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 68 | #endif |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 69 | #ifdef CONFIG_MCAST_TFTP |
| 70 | static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set); |
| 71 | #endif |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 72 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 73 | /* Default initializations for TSEC controllers. */ |
| 74 | |
| 75 | static 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 | |
| 99 | int 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 | |
| 109 | int tsec_standard_init(bd_t *bis) |
| 110 | { |
| 111 | return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info)); |
| 112 | } |
| 113 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 114 | /* Initialize device structure. Returns success if PHY |
| 115 | * initialization succeeded (i.e. if it recognizes the PHY) |
| 116 | */ |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 117 | int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 118 | { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 119 | struct eth_device *dev; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 120 | int i; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 121 | struct tsec_private *priv; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 122 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 123 | dev = (struct eth_device *)malloc(sizeof *dev); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 124 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 125 | if (NULL == dev) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 126 | return 0; |
| 127 | |
| 128 | memset(dev, 0, sizeof *dev); |
| 129 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 130 | priv = (struct tsec_private *)malloc(sizeof(*priv)); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 131 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 132 | if (NULL == priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 133 | return 0; |
| 134 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 135 | privlist[num_tsecs++] = priv; |
| 136 | priv->regs = tsec_info->regs; |
| 137 | priv->phyregs = tsec_info->miiregs; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 138 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 139 | priv->phyaddr = tsec_info->phyaddr; |
| 140 | priv->flags = tsec_info->flags; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 141 | |
Andy Fleming | 75b9d4a | 2008-08-31 16:33:26 -0500 | [diff] [blame] | 142 | sprintf(dev->name, tsec_info->devname); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 143 | dev->iobase = 0; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 144 | dev->priv = priv; |
| 145 | dev->init = tsec_init; |
| 146 | dev->halt = tsec_halt; |
| 147 | dev->send = tsec_send; |
| 148 | dev->recv = tsec_recv; |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 149 | #ifdef CONFIG_MCAST_TFTP |
| 150 | dev->mcast = tsec_mcast_addr; |
| 151 | #endif |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 152 | |
| 153 | /* Tell u-boot to get the addr from the env */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 154 | for (i = 0; i < 6; i++) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 155 | dev->enetaddr[i] = 0; |
| 156 | |
| 157 | eth_register(dev); |
| 158 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 159 | /* Reset the MAC */ |
| 160 | priv->regs->maccfg1 |= MACCFG1_SOFT_RESET; |
Andy Fleming | 9e5be82 | 2009-02-03 18:26:41 -0600 | [diff] [blame] | 161 | udelay(2); /* Soft Reset must be asserted for 3 TX clocks */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 162 | priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET); |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 163 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 164 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 165 | && !defined(BITBANGMII) |
| 166 | miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write); |
| 167 | #endif |
| 168 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 169 | /* Try to initialize PHY here, and return */ |
| 170 | return init_phy(dev); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 171 | } |
| 172 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 173 | /* Initializes data structures and registers for the controller, |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 174 | * and brings the interface up. Returns the link status, meaning |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 175 | * that it returns success if the link is up, failure otherwise. |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 176 | * This allows u-boot to find the first active controller. |
| 177 | */ |
| 178 | int tsec_init(struct eth_device *dev, bd_t * bd) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 179 | { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 180 | uint tempval; |
| 181 | char tmpbuf[MAC_ADDR_LEN]; |
| 182 | int i; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 183 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 184 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 185 | |
| 186 | /* Make sure the controller is stopped */ |
| 187 | tsec_halt(dev); |
| 188 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 189 | /* Init MACCFG2. Defaults to GMII */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 190 | 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 Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 197 | for (i = 0; i < MAC_ADDR_LEN; i++) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 198 | tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i]; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 199 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 200 | regs->macstnaddr1 = *((uint *) (tmpbuf)); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 201 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 202 | tempval = *((uint *) (tmpbuf + 4)); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 203 | |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 204 | regs->macstnaddr2 = tempval; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 205 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 206 | /* reset the indices to zero */ |
| 207 | rxIdx = 0; |
| 208 | txIdx = 0; |
| 209 | |
| 210 | /* Clear out (for the most part) the other registers */ |
| 211 | init_registers(regs); |
| 212 | |
| 213 | /* Ready the device for tx/rx */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 214 | startup_tsec(dev); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 215 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 216 | /* If there's no link, fail */ |
Ben Warren | 422b1a0 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 217 | return (priv->link ? 0 : -1); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 220 | /* Writes the given phy's reg with value, using the specified MDIO regs */ |
| 221 | static void tsec_local_mdio_write(volatile tsec_t *phyregs, uint addr, |
| 222 | uint reg, uint value) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 223 | { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 224 | int timeout = 1000000; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 225 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 226 | phyregs->miimadd = (addr << 8) | reg; |
| 227 | phyregs->miimcon = value; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 228 | asm("sync"); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 229 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 230 | timeout = 1000000; |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 231 | while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 234 | |
| 235 | /* Provide the default behavior of writing the PHY of this ethernet device */ |
| 236 | #define write_phy_reg(priv, regnum, value) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value) |
michael.firth@bt.com | 55fe7c5 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 237 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 238 | /* Reads register regnum on the device's PHY through the |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 239 | * specified registers. It lowers and raises the read |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 240 | * command, and waits for the data to become valid (miimind |
| 241 | * notvalid bit cleared), and the bus to cease activity (miimind |
| 242 | * busy bit cleared), and then returns the value |
| 243 | */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 244 | uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 245 | { |
| 246 | uint value; |
| 247 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 248 | /* Put the address of the phy, and the register |
| 249 | * number into MIIMADD */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 250 | phyregs->miimadd = (phyid << 8) | regnum; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 251 | |
| 252 | /* Clear the command register, and wait */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 253 | phyregs->miimcom = 0; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 254 | asm("sync"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 255 | |
| 256 | /* Initiate a read command, and wait */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 257 | phyregs->miimcom = MIIM_READ_COMMAND; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 258 | asm("sync"); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 259 | |
| 260 | /* Wait for the the indication that the read is done */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 261 | while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 262 | |
| 263 | /* Grab the value read from the PHY */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 264 | value = phyregs->miimstat; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 265 | |
| 266 | return value; |
| 267 | } |
| 268 | |
michael.firth@bt.com | 55fe7c5 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 269 | /* #define to provide old read_phy_reg functionality without duplicating code */ |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 270 | #define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum) |
| 271 | |
| 272 | #define TBIANA_SETTINGS ( \ |
| 273 | TBIANA_ASYMMETRIC_PAUSE \ |
| 274 | | TBIANA_SYMMETRIC_PAUSE \ |
| 275 | | TBIANA_FULL_DUPLEX \ |
| 276 | ) |
| 277 | |
| 278 | #define TBICR_SETTINGS ( \ |
| 279 | TBICR_PHY_RESET \ |
| 280 | | TBICR_ANEG_ENABLE \ |
| 281 | | TBICR_FULL_DUPLEX \ |
| 282 | | TBICR_SPEED1_SET \ |
| 283 | ) |
| 284 | /* Configure the TBI for SGMII operation */ |
| 285 | static void tsec_configure_serdes(struct tsec_private *priv) |
| 286 | { |
Peter Tyser | ce47eb4 | 2008-09-16 10:04:47 -0500 | [diff] [blame] | 287 | /* Access TBI PHY registers at given TSEC register offset as opposed to the |
| 288 | * register offset used for external PHY accesses */ |
| 289 | tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_ANA, |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 290 | TBIANA_SETTINGS); |
Peter Tyser | ce47eb4 | 2008-09-16 10:04:47 -0500 | [diff] [blame] | 291 | tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_TBICON, |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 292 | TBICON_CLK_SELECT); |
Peter Tyser | ce47eb4 | 2008-09-16 10:04:47 -0500 | [diff] [blame] | 293 | tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_CR, |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 294 | TBICR_SETTINGS); |
| 295 | } |
michael.firth@bt.com | 55fe7c5 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 296 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 297 | /* Discover which PHY is attached to the device, and configure it |
| 298 | * properly. If the PHY is not recognized, then return 0 |
| 299 | * (failure). Otherwise, return 1 |
| 300 | */ |
| 301 | static int init_phy(struct eth_device *dev) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 302 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 303 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 304 | struct phy_info *curphy; |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 305 | volatile tsec_t *phyregs = priv->phyregs; |
| 306 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 307 | |
| 308 | /* Assign a Physical address to the TBI */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 309 | regs->tbipa = CONFIG_SYS_TBIPA_VALUE; |
| 310 | phyregs->tbipa = CONFIG_SYS_TBIPA_VALUE; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 311 | asm("sync"); |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 312 | |
| 313 | /* Reset MII (due to new addresses) */ |
| 314 | priv->phyregs->miimcfg = MIIMCFG_RESET; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 315 | asm("sync"); |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 316 | priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 317 | asm("sync"); |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 318 | while (priv->phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 319 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 320 | if (0 == relocated) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 321 | relocate_cmds(); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 322 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 323 | /* Get the cmd structure corresponding to the attached |
| 324 | * PHY */ |
| 325 | curphy = get_phy_info(dev); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 326 | |
Ben Warren | 4653f91 | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 327 | if (curphy == NULL) { |
| 328 | priv->phyinfo = NULL; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 329 | printf("%s: No PHY found\n", dev->name); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 330 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 331 | return 0; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 334 | if (regs->ecntrl & ECNTRL_SGMII_MODE) |
| 335 | tsec_configure_serdes(priv); |
| 336 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 337 | priv->phyinfo = curphy; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 338 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 339 | phy_run_commands(priv, priv->phyinfo->config); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 340 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 341 | return 1; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 344 | /* |
| 345 | * Returns which value to write to the control register. |
| 346 | * For 10/100, the value is slightly different |
| 347 | */ |
| 348 | uint mii_cr_init(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 349 | { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 350 | if (priv->flags & TSEC_GIGABIT) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 351 | return MIIM_CONTROL_INIT; |
| 352 | else |
| 353 | return MIIM_CR_INIT; |
| 354 | } |
| 355 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 356 | /* Parse the status register for link, and then do |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 357 | * auto-negotiation |
| 358 | */ |
| 359 | uint mii_parse_sr(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 360 | { |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 361 | /* |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 362 | * Wait if the link is up, and autonegotiation is in progress |
| 363 | * (ie - we're capable and it's not done) |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 364 | */ |
| 365 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 366 | if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE) |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 367 | && !(mii_reg & PHY_BMSR_AUTN_COMP)) { |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 368 | int i = 0; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 369 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 370 | puts("Waiting for PHY auto negotiation to complete"); |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 371 | while (!(mii_reg & PHY_BMSR_AUTN_COMP)) { |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 372 | /* |
| 373 | * Timeout reached ? |
| 374 | */ |
| 375 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 376 | puts(" TIMEOUT !\n"); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 377 | priv->link = 0; |
Jin Zhengxiong-R64188 | fcfb9a5 | 2006-06-27 18:12:23 +0800 | [diff] [blame] | 378 | return 0; |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 379 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 380 | |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 381 | if ((i++ % 1000) == 0) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 382 | putc('.'); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 383 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 384 | udelay(1000); /* 1 ms */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 385 | mii_reg = read_phy_reg(priv, MIIM_STATUS); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 386 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 387 | puts(" done\n"); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 388 | priv->link = 1; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 389 | udelay(500000); /* another 500 ms (results in faster booting) */ |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 390 | } else { |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 391 | if (mii_reg & MIIM_STATUS_LINK) |
| 392 | priv->link = 1; |
| 393 | else |
| 394 | priv->link = 0; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | return 0; |
| 398 | } |
| 399 | |
David Updegraff | af1c2b8 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 400 | /* Generic function which updates the speed and duplex. If |
| 401 | * autonegotiation is enabled, it uses the AND of the link |
| 402 | * partner's advertised capabilities and our advertised |
| 403 | * capabilities. If autonegotiation is disabled, we use the |
| 404 | * appropriate bits in the control register. |
| 405 | * |
| 406 | * Stolen from Linux's mii.c and phy_device.c |
| 407 | */ |
| 408 | uint mii_parse_link(uint mii_reg, struct tsec_private *priv) |
| 409 | { |
| 410 | /* We're using autonegotiation */ |
| 411 | if (mii_reg & PHY_BMSR_AUTN_ABLE) { |
| 412 | uint lpa = 0; |
| 413 | uint gblpa = 0; |
| 414 | |
| 415 | /* Check for gigabit capability */ |
| 416 | if (mii_reg & PHY_BMSR_EXT) { |
| 417 | /* We want a list of states supported by |
| 418 | * both PHYs in the link |
| 419 | */ |
| 420 | gblpa = read_phy_reg(priv, PHY_1000BTSR); |
| 421 | gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2; |
| 422 | } |
| 423 | |
| 424 | /* Set the baseline so we only have to set them |
| 425 | * if they're different |
| 426 | */ |
| 427 | priv->speed = 10; |
| 428 | priv->duplexity = 0; |
| 429 | |
| 430 | /* Check the gigabit fields */ |
| 431 | if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) { |
| 432 | priv->speed = 1000; |
| 433 | |
| 434 | if (gblpa & PHY_1000BTSR_1000FD) |
| 435 | priv->duplexity = 1; |
| 436 | |
| 437 | /* We're done! */ |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | lpa = read_phy_reg(priv, PHY_ANAR); |
| 442 | lpa &= read_phy_reg(priv, PHY_ANLPAR); |
| 443 | |
| 444 | if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) { |
| 445 | priv->speed = 100; |
| 446 | |
| 447 | if (lpa & PHY_ANLPAR_TXFD) |
| 448 | priv->duplexity = 1; |
| 449 | |
| 450 | } else if (lpa & PHY_ANLPAR_10FD) |
| 451 | priv->duplexity = 1; |
| 452 | } else { |
| 453 | uint bmcr = read_phy_reg(priv, PHY_BMCR); |
| 454 | |
| 455 | priv->speed = 10; |
| 456 | priv->duplexity = 0; |
| 457 | |
| 458 | if (bmcr & PHY_BMCR_DPLX) |
| 459 | priv->duplexity = 1; |
| 460 | |
| 461 | if (bmcr & PHY_BMCR_1000_MBPS) |
| 462 | priv->speed = 1000; |
| 463 | else if (bmcr & PHY_BMCR_100_MBPS) |
| 464 | priv->speed = 100; |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 470 | /* |
Zach LeRoy | 091dc9f | 2009-05-22 10:26:33 -0500 | [diff] [blame^] | 471 | * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain |
| 472 | * circumstances. eg a gigabit TSEC connected to a gigabit switch with |
| 473 | * a 4-wire ethernet cable. Both ends advertise gigabit, but can't |
| 474 | * link. "Ethernet@Wirespeed" reduces advertised speed until link |
| 475 | * can be achieved. |
| 476 | */ |
| 477 | uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv) |
| 478 | { |
| 479 | return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010; |
| 480 | } |
| 481 | |
| 482 | /* |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 483 | * Parse the BCM54xx status register for speed and duplex information. |
| 484 | * The linux sungem_phy has this information, but in a table format. |
| 485 | */ |
| 486 | uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv) |
| 487 | { |
| 488 | |
| 489 | switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){ |
| 490 | |
| 491 | case 1: |
| 492 | printf("Enet starting in 10BT/HD\n"); |
| 493 | priv->duplexity = 0; |
| 494 | priv->speed = 10; |
| 495 | break; |
| 496 | |
| 497 | case 2: |
| 498 | printf("Enet starting in 10BT/FD\n"); |
| 499 | priv->duplexity = 1; |
| 500 | priv->speed = 10; |
| 501 | break; |
| 502 | |
| 503 | case 3: |
| 504 | printf("Enet starting in 100BT/HD\n"); |
| 505 | priv->duplexity = 0; |
| 506 | priv->speed = 100; |
| 507 | break; |
| 508 | |
| 509 | case 5: |
| 510 | printf("Enet starting in 100BT/FD\n"); |
| 511 | priv->duplexity = 1; |
| 512 | priv->speed = 100; |
| 513 | break; |
| 514 | |
| 515 | case 6: |
| 516 | printf("Enet starting in 1000BT/HD\n"); |
| 517 | priv->duplexity = 0; |
| 518 | priv->speed = 1000; |
| 519 | break; |
| 520 | |
| 521 | case 7: |
| 522 | printf("Enet starting in 1000BT/FD\n"); |
| 523 | priv->duplexity = 1; |
| 524 | priv->speed = 1000; |
| 525 | break; |
| 526 | |
| 527 | default: |
| 528 | printf("Auto-neg error, defaulting to 10BT/HD\n"); |
| 529 | priv->duplexity = 0; |
| 530 | priv->speed = 10; |
| 531 | break; |
| 532 | } |
| 533 | |
| 534 | return 0; |
| 535 | |
| 536 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 537 | /* Parse the 88E1011's status register for speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 538 | * information |
| 539 | */ |
| 540 | uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 541 | { |
| 542 | uint speed; |
| 543 | |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 544 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 545 | |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 546 | if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) && |
| 547 | !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) { |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 548 | int i = 0; |
| 549 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 550 | puts("Waiting for PHY realtime link"); |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 551 | while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) { |
| 552 | /* Timeout reached ? */ |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 553 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 554 | puts(" TIMEOUT !\n"); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 555 | priv->link = 0; |
| 556 | break; |
| 557 | } |
| 558 | |
| 559 | if ((i++ % 1000) == 0) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 560 | putc('.'); |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 561 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 562 | udelay(1000); /* 1 ms */ |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 563 | mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS); |
| 564 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 565 | puts(" done\n"); |
| 566 | udelay(500000); /* another 500 ms (results in faster booting) */ |
Andy Fleming | 7613afd | 2007-08-15 20:03:44 -0500 | [diff] [blame] | 567 | } else { |
| 568 | if (mii_reg & MIIM_88E1011_PHYSTAT_LINK) |
| 569 | priv->link = 1; |
| 570 | else |
| 571 | priv->link = 0; |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 574 | if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 575 | priv->duplexity = 1; |
| 576 | else |
| 577 | priv->duplexity = 0; |
| 578 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 579 | speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 580 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 581 | switch (speed) { |
| 582 | case MIIM_88E1011_PHYSTAT_GBIT: |
| 583 | priv->speed = 1000; |
| 584 | break; |
| 585 | case MIIM_88E1011_PHYSTAT_100: |
| 586 | priv->speed = 100; |
| 587 | break; |
| 588 | default: |
| 589 | priv->speed = 10; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
Dave Liu | 18ee320 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 595 | /* Parse the RTL8211B's status register for speed and duplex |
| 596 | * information |
| 597 | */ |
| 598 | uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv) |
| 599 | { |
| 600 | uint speed; |
| 601 | |
| 602 | mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS); |
Anton Vorontsov | c760478 | 2008-03-14 23:20:30 +0300 | [diff] [blame] | 603 | if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) { |
Dave Liu | 18ee320 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 604 | int i = 0; |
| 605 | |
Anton Vorontsov | c760478 | 2008-03-14 23:20:30 +0300 | [diff] [blame] | 606 | /* in case of timeout ->link is cleared */ |
| 607 | priv->link = 1; |
Dave Liu | 18ee320 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 608 | puts("Waiting for PHY realtime link"); |
| 609 | while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) { |
| 610 | /* Timeout reached ? */ |
| 611 | if (i > PHY_AUTONEGOTIATE_TIMEOUT) { |
| 612 | puts(" TIMEOUT !\n"); |
| 613 | priv->link = 0; |
| 614 | break; |
| 615 | } |
| 616 | |
| 617 | if ((i++ % 1000) == 0) { |
| 618 | putc('.'); |
| 619 | } |
| 620 | udelay(1000); /* 1 ms */ |
| 621 | mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS); |
| 622 | } |
| 623 | puts(" done\n"); |
| 624 | udelay(500000); /* another 500 ms (results in faster booting) */ |
| 625 | } else { |
| 626 | if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK) |
| 627 | priv->link = 1; |
| 628 | else |
| 629 | priv->link = 0; |
| 630 | } |
| 631 | |
| 632 | if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX) |
| 633 | priv->duplexity = 1; |
| 634 | else |
| 635 | priv->duplexity = 0; |
| 636 | |
| 637 | speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED); |
| 638 | |
| 639 | switch (speed) { |
| 640 | case MIIM_RTL8211B_PHYSTAT_GBIT: |
| 641 | priv->speed = 1000; |
| 642 | break; |
| 643 | case MIIM_RTL8211B_PHYSTAT_100: |
| 644 | priv->speed = 100; |
| 645 | break; |
| 646 | default: |
| 647 | priv->speed = 10; |
| 648 | } |
| 649 | |
| 650 | return 0; |
| 651 | } |
| 652 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 653 | /* Parse the cis8201's status register for speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 654 | * information |
| 655 | */ |
| 656 | uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 657 | { |
| 658 | uint speed; |
| 659 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 660 | if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 661 | priv->duplexity = 1; |
| 662 | else |
| 663 | priv->duplexity = 0; |
| 664 | |
| 665 | speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 666 | switch (speed) { |
| 667 | case MIIM_CIS8201_AUXCONSTAT_GBIT: |
| 668 | priv->speed = 1000; |
| 669 | break; |
| 670 | case MIIM_CIS8201_AUXCONSTAT_100: |
| 671 | priv->speed = 100; |
| 672 | break; |
| 673 | default: |
| 674 | priv->speed = 10; |
| 675 | break; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | return 0; |
| 679 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 680 | |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 681 | /* Parse the vsc8244's status register for speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 682 | * information |
| 683 | */ |
| 684 | uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 685 | { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 686 | uint speed; |
| 687 | |
| 688 | if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX) |
| 689 | priv->duplexity = 1; |
| 690 | else |
| 691 | priv->duplexity = 0; |
| 692 | |
| 693 | speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED; |
| 694 | switch (speed) { |
| 695 | case MIIM_VSC8244_AUXCONSTAT_GBIT: |
| 696 | priv->speed = 1000; |
| 697 | break; |
| 698 | case MIIM_VSC8244_AUXCONSTAT_100: |
| 699 | priv->speed = 100; |
| 700 | break; |
| 701 | default: |
| 702 | priv->speed = 10; |
| 703 | break; |
| 704 | } |
| 705 | |
| 706 | return 0; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 707 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 708 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 709 | /* Parse the DM9161's status register for speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 710 | * information |
| 711 | */ |
| 712 | uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 713 | { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 714 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H)) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 715 | priv->speed = 100; |
| 716 | else |
| 717 | priv->speed = 10; |
| 718 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 719 | if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F)) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 720 | priv->duplexity = 1; |
| 721 | else |
| 722 | priv->duplexity = 0; |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 727 | /* |
| 728 | * Hack to write all 4 PHYs with the LED values |
| 729 | */ |
| 730 | uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 731 | { |
| 732 | uint phyid; |
| 733 | volatile tsec_t *regbase = priv->phyregs; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 734 | int timeout = 1000000; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 735 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 736 | for (phyid = 0; phyid < 4; phyid++) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 737 | regbase->miimadd = (phyid << 8) | mii_reg; |
| 738 | regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT; |
Eran Liberty | f046ccd | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 739 | asm("sync"); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 740 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 741 | timeout = 1000000; |
| 742 | while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | return MIIM_CIS8204_SLEDCON_INIT; |
| 746 | } |
| 747 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 748 | uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv) |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 749 | { |
| 750 | if (priv->flags & TSEC_REDUCED) |
| 751 | return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII; |
| 752 | else |
| 753 | return MIIM_CIS8204_EPHYCON_INIT; |
| 754 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 755 | |
Dave Liu | 19580e6 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 756 | uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv) |
| 757 | { |
| 758 | uint mii_data = read_phy_reg(priv, mii_reg); |
| 759 | |
| 760 | if (priv->flags & TSEC_REDUCED) |
| 761 | mii_data = (mii_data & 0xfff0) | 0x000b; |
| 762 | return mii_data; |
| 763 | } |
| 764 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 765 | /* Initialized required registers to appropriate values, zeroing |
| 766 | * those we don't care about (unless zero is bad, in which case, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 767 | * choose a more appropriate value) |
| 768 | */ |
| 769 | static void init_registers(volatile tsec_t * regs) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 770 | { |
| 771 | /* Clear IEVENT */ |
| 772 | regs->ievent = IEVENT_INIT_CLEAR; |
| 773 | |
| 774 | regs->imask = IMASK_INIT_CLEAR; |
| 775 | |
| 776 | regs->hash.iaddr0 = 0; |
| 777 | regs->hash.iaddr1 = 0; |
| 778 | regs->hash.iaddr2 = 0; |
| 779 | regs->hash.iaddr3 = 0; |
| 780 | regs->hash.iaddr4 = 0; |
| 781 | regs->hash.iaddr5 = 0; |
| 782 | regs->hash.iaddr6 = 0; |
| 783 | regs->hash.iaddr7 = 0; |
| 784 | |
| 785 | regs->hash.gaddr0 = 0; |
| 786 | regs->hash.gaddr1 = 0; |
| 787 | regs->hash.gaddr2 = 0; |
| 788 | regs->hash.gaddr3 = 0; |
| 789 | regs->hash.gaddr4 = 0; |
| 790 | regs->hash.gaddr5 = 0; |
| 791 | regs->hash.gaddr6 = 0; |
| 792 | regs->hash.gaddr7 = 0; |
| 793 | |
| 794 | regs->rctrl = 0x00000000; |
| 795 | |
| 796 | /* Init RMON mib registers */ |
| 797 | memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t)); |
| 798 | |
| 799 | regs->rmon.cam1 = 0xffffffff; |
| 800 | regs->rmon.cam2 = 0xffffffff; |
| 801 | |
| 802 | regs->mrblr = MRBLR_INIT_SETTINGS; |
| 803 | |
| 804 | regs->minflr = MINFLR_INIT_SETTINGS; |
| 805 | |
| 806 | regs->attr = ATTR_INIT_SETTINGS; |
| 807 | regs->attreli = ATTRELI_INIT_SETTINGS; |
| 808 | |
| 809 | } |
| 810 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 811 | /* Configure maccfg2 based on negotiated speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 812 | * reported by PHY handling code |
| 813 | */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 814 | static void adjust_link(struct eth_device *dev) |
| 815 | { |
| 816 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 817 | volatile tsec_t *regs = priv->regs; |
| 818 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 819 | if (priv->link) { |
| 820 | if (priv->duplexity != 0) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 821 | regs->maccfg2 |= MACCFG2_FULL_DUPLEX; |
| 822 | else |
| 823 | regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX); |
| 824 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 825 | switch (priv->speed) { |
| 826 | case 1000: |
| 827 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 828 | | MACCFG2_GMII); |
| 829 | break; |
| 830 | case 100: |
| 831 | case 10: |
| 832 | regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF)) |
| 833 | | MACCFG2_MII); |
Jon Loeliger | d9b94f2 | 2005-07-25 14:05:07 -0500 | [diff] [blame] | 834 | |
Nick Spence | f484dc7 | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 835 | /* Set R100 bit in all modes although |
| 836 | * it is only used in RGMII mode |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 837 | */ |
Nick Spence | f484dc7 | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 838 | if (priv->speed == 100) |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 839 | regs->ecntrl |= ECNTRL_R100; |
| 840 | else |
| 841 | regs->ecntrl &= ~(ECNTRL_R100); |
| 842 | break; |
| 843 | default: |
| 844 | printf("%s: Speed was bad\n", dev->name); |
| 845 | break; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | printf("Speed: %d, %s duplex\n", priv->speed, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 849 | (priv->duplexity) ? "full" : "half"); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 850 | |
| 851 | } else { |
| 852 | printf("%s: No link.\n", dev->name); |
| 853 | } |
| 854 | } |
| 855 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 856 | /* Set up the buffers and their descriptors, and bring up the |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 857 | * interface |
| 858 | */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 859 | static void startup_tsec(struct eth_device *dev) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 860 | { |
| 861 | int i; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 862 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 863 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 864 | |
| 865 | /* Point to the buffer descriptors */ |
| 866 | regs->tbase = (unsigned int)(&rtx.txbd[txIdx]); |
| 867 | regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]); |
| 868 | |
| 869 | /* Initialize the Rx Buffer descriptors */ |
| 870 | for (i = 0; i < PKTBUFSRX; i++) { |
| 871 | rtx.rxbd[i].status = RXBD_EMPTY; |
| 872 | rtx.rxbd[i].length = 0; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 873 | rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i]; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 874 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 875 | rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 876 | |
| 877 | /* Initialize the TX Buffer Descriptors */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 878 | for (i = 0; i < TX_BUF_CNT; i++) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 879 | rtx.txbd[i].status = 0; |
| 880 | rtx.txbd[i].length = 0; |
| 881 | rtx.txbd[i].bufPtr = 0; |
| 882 | } |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 883 | rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 884 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 885 | /* Start up the PHY */ |
Ben Warren | 4653f91 | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 886 | if(priv->phyinfo) |
| 887 | phy_run_commands(priv, priv->phyinfo->startup); |
David Updegraff | af1c2b8 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 888 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 889 | adjust_link(dev); |
| 890 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 891 | /* Enable Transmit and Receive */ |
| 892 | regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN); |
| 893 | |
| 894 | /* Tell the DMA it is clear to go */ |
| 895 | regs->dmactrl |= DMACTRL_INIT_SETTINGS; |
| 896 | regs->tstat = TSTAT_CLEAR_THALT; |
Dan Wilson | 5c7ea64 | 2007-10-19 11:33:48 -0500 | [diff] [blame] | 897 | regs->rstat = RSTAT_CLEAR_RHALT; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 898 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 899 | } |
| 900 | |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 901 | /* This returns the status bits of the device. The return value |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 902 | * is never checked, and this is what the 8260 driver did, so we |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 903 | * do the same. Presumably, this would be zero if there were no |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 904 | * errors |
| 905 | */ |
| 906 | static int tsec_send(struct eth_device *dev, volatile void *packet, int length) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 907 | { |
| 908 | int i; |
| 909 | int result = 0; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 910 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 911 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 912 | |
| 913 | /* Find an empty buffer descriptor */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 914 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 915 | if (i >= TOUT_LOOP) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 916 | debug("%s: tsec: tx buffers full\n", dev->name); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 917 | return result; |
| 918 | } |
| 919 | } |
| 920 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 921 | rtx.txbd[txIdx].bufPtr = (uint) packet; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 922 | rtx.txbd[txIdx].length = length; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 923 | rtx.txbd[txIdx].status |= |
| 924 | (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 925 | |
| 926 | /* Tell the DMA to go */ |
| 927 | regs->tstat = TSTAT_CLEAR_THALT; |
| 928 | |
| 929 | /* Wait for buffer to be transmitted */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 930 | for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 931 | if (i >= TOUT_LOOP) { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 932 | debug("%s: tsec: tx error\n", dev->name); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 933 | return result; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | txIdx = (txIdx + 1) % TX_BUF_CNT; |
| 938 | result = rtx.txbd[txIdx].status & TXBD_STATS; |
| 939 | |
| 940 | return result; |
| 941 | } |
| 942 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 943 | static int tsec_recv(struct eth_device *dev) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 944 | { |
| 945 | int length; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 946 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 947 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 948 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 949 | while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 950 | |
| 951 | length = rtx.rxbd[rxIdx].length; |
| 952 | |
| 953 | /* Send the packet up if there were no errors */ |
| 954 | if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) { |
| 955 | NetReceive(NetRxPackets[rxIdx], length - 4); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 956 | } else { |
| 957 | printf("Got error %x\n", |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 958 | (rtx.rxbd[rxIdx].status & RXBD_STATS)); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | rtx.rxbd[rxIdx].length = 0; |
| 962 | |
| 963 | /* Set the wrap bit if this is the last element in the list */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 964 | rtx.rxbd[rxIdx].status = |
| 965 | RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 966 | |
| 967 | rxIdx = (rxIdx + 1) % PKTBUFSRX; |
| 968 | } |
| 969 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 970 | if (regs->ievent & IEVENT_BSY) { |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 971 | regs->ievent = IEVENT_BSY; |
| 972 | regs->rstat = RSTAT_CLEAR_RHALT; |
| 973 | } |
| 974 | |
| 975 | return -1; |
| 976 | |
| 977 | } |
| 978 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 979 | /* Stop the interface */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 980 | static void tsec_halt(struct eth_device *dev) |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 981 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 982 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 983 | volatile tsec_t *regs = priv->regs; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 984 | |
| 985 | regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS); |
| 986 | regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS); |
| 987 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 988 | while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 989 | |
| 990 | regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN); |
| 991 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 992 | /* Shut down the PHY, as needed */ |
Ben Warren | 4653f91 | 2006-10-26 14:38:25 -0400 | [diff] [blame] | 993 | if(priv->phyinfo) |
| 994 | phy_run_commands(priv, priv->phyinfo->shutdown); |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 995 | } |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 996 | |
Andy Fleming | c7e717e | 2007-08-03 04:05:25 -0500 | [diff] [blame] | 997 | struct phy_info phy_info_M88E1149S = { |
Wolfgang Denk | 5728be3 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 998 | 0x1410ca, |
| 999 | "Marvell 88E1149S", |
| 1000 | 4, |
| 1001 | (struct phy_cmd[]){ /* config */ |
| 1002 | /* Reset and configure the PHY */ |
| 1003 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1004 | {0x1d, 0x1f, NULL}, |
| 1005 | {0x1e, 0x200c, NULL}, |
| 1006 | {0x1d, 0x5, NULL}, |
| 1007 | {0x1e, 0x0, NULL}, |
| 1008 | {0x1e, 0x100, NULL}, |
| 1009 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1010 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1011 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1012 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1013 | {miim_end,} |
| 1014 | }, |
| 1015 | (struct phy_cmd[]){ /* startup */ |
| 1016 | /* Status is read once to clear old link state */ |
| 1017 | {MIIM_STATUS, miim_read, NULL}, |
| 1018 | /* Auto-negotiate */ |
| 1019 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1020 | /* Read the status */ |
| 1021 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1022 | &mii_parse_88E1011_psr}, |
| 1023 | {miim_end,} |
| 1024 | }, |
| 1025 | (struct phy_cmd[]){ /* shutdown */ |
| 1026 | {miim_end,} |
| 1027 | }, |
Andy Fleming | c7e717e | 2007-08-03 04:05:25 -0500 | [diff] [blame] | 1028 | }; |
| 1029 | |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1030 | /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */ |
| 1031 | struct phy_info phy_info_BCM5461S = { |
| 1032 | 0x02060c1, /* 5461 ID */ |
| 1033 | "Broadcom BCM5461S", |
| 1034 | 0, /* not clear to me what minor revisions we can shift away */ |
| 1035 | (struct phy_cmd[]) { /* config */ |
| 1036 | /* Reset and configure the PHY */ |
| 1037 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1038 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1039 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1040 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1041 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1042 | {miim_end,} |
| 1043 | }, |
| 1044 | (struct phy_cmd[]) { /* startup */ |
| 1045 | /* Status is read once to clear old link state */ |
| 1046 | {MIIM_STATUS, miim_read, NULL}, |
| 1047 | /* Auto-negotiate */ |
| 1048 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1049 | /* Read the status */ |
| 1050 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 1051 | {miim_end,} |
| 1052 | }, |
| 1053 | (struct phy_cmd[]) { /* shutdown */ |
| 1054 | {miim_end,} |
| 1055 | }, |
| 1056 | }; |
| 1057 | |
Joe Hamman | c3243cf | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1058 | struct phy_info phy_info_BCM5464S = { |
| 1059 | 0x02060b1, /* 5464 ID */ |
| 1060 | "Broadcom BCM5464S", |
| 1061 | 0, /* not clear to me what minor revisions we can shift away */ |
| 1062 | (struct phy_cmd[]) { /* config */ |
| 1063 | /* Reset and configure the PHY */ |
| 1064 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1065 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1066 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1067 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1068 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1069 | {miim_end,} |
| 1070 | }, |
| 1071 | (struct phy_cmd[]) { /* startup */ |
| 1072 | /* Status is read once to clear old link state */ |
| 1073 | {MIIM_STATUS, miim_read, NULL}, |
| 1074 | /* Auto-negotiate */ |
| 1075 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1076 | /* Read the status */ |
| 1077 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 1078 | {miim_end,} |
| 1079 | }, |
| 1080 | (struct phy_cmd[]) { /* shutdown */ |
| 1081 | {miim_end,} |
| 1082 | }, |
| 1083 | }; |
| 1084 | |
Zach LeRoy | 091dc9f | 2009-05-22 10:26:33 -0500 | [diff] [blame^] | 1085 | struct phy_info phy_info_BCM5482S = { |
| 1086 | 0x0143bcb, |
| 1087 | "Broadcom BCM5482S", |
| 1088 | 4, |
| 1089 | (struct phy_cmd[]) { /* config */ |
| 1090 | /* Reset and configure the PHY */ |
| 1091 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1092 | /* Setup read from auxilary control shadow register 7 */ |
| 1093 | {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL}, |
| 1094 | /* Read Misc Control register and or in Ethernet@Wirespeed */ |
| 1095 | {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed}, |
| 1096 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1097 | {miim_end,} |
| 1098 | }, |
| 1099 | (struct phy_cmd[]) { /* startup */ |
| 1100 | /* Status is read once to clear old link state */ |
| 1101 | {MIIM_STATUS, miim_read, NULL}, |
| 1102 | /* Auto-negotiate */ |
| 1103 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1104 | /* Read the status */ |
| 1105 | {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr}, |
| 1106 | {miim_end,} |
| 1107 | }, |
| 1108 | (struct phy_cmd[]) { /* shutdown */ |
| 1109 | {miim_end,} |
| 1110 | }, |
| 1111 | }; |
| 1112 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1113 | struct phy_info phy_info_M88E1011S = { |
| 1114 | 0x01410c6, |
| 1115 | "Marvell 88E1011S", |
| 1116 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1117 | (struct phy_cmd[]){ /* config */ |
| 1118 | /* Reset and configure the PHY */ |
| 1119 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1120 | {0x1d, 0x1f, NULL}, |
| 1121 | {0x1e, 0x200c, NULL}, |
| 1122 | {0x1d, 0x5, NULL}, |
| 1123 | {0x1e, 0x0, NULL}, |
| 1124 | {0x1e, 0x100, NULL}, |
| 1125 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1126 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1127 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1128 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1129 | {miim_end,} |
| 1130 | }, |
| 1131 | (struct phy_cmd[]){ /* startup */ |
| 1132 | /* Status is read once to clear old link state */ |
| 1133 | {MIIM_STATUS, miim_read, NULL}, |
| 1134 | /* Auto-negotiate */ |
| 1135 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1136 | /* Read the status */ |
| 1137 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1138 | &mii_parse_88E1011_psr}, |
| 1139 | {miim_end,} |
| 1140 | }, |
| 1141 | (struct phy_cmd[]){ /* shutdown */ |
| 1142 | {miim_end,} |
| 1143 | }, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1144 | }; |
| 1145 | |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1146 | struct phy_info phy_info_M88E1111S = { |
| 1147 | 0x01410cc, |
| 1148 | "Marvell 88E1111S", |
| 1149 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1150 | (struct phy_cmd[]){ /* config */ |
| 1151 | /* Reset and configure the PHY */ |
| 1152 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
Dave Liu | 19580e6 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 1153 | {0x1b, 0x848f, &mii_m88e1111s_setmode}, |
Nick Spence | f484dc7 | 2006-09-07 07:39:46 -0700 | [diff] [blame] | 1154 | {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1155 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1156 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1157 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1158 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1159 | {miim_end,} |
| 1160 | }, |
| 1161 | (struct phy_cmd[]){ /* startup */ |
| 1162 | /* Status is read once to clear old link state */ |
| 1163 | {MIIM_STATUS, miim_read, NULL}, |
| 1164 | /* Auto-negotiate */ |
| 1165 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1166 | /* Read the status */ |
| 1167 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1168 | &mii_parse_88E1011_psr}, |
| 1169 | {miim_end,} |
| 1170 | }, |
| 1171 | (struct phy_cmd[]){ /* shutdown */ |
| 1172 | {miim_end,} |
| 1173 | }, |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1174 | }; |
| 1175 | |
Ron Madrid | 290ef64 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1176 | struct phy_info phy_info_M88E1118 = { |
| 1177 | 0x01410e1, |
| 1178 | "Marvell 88E1118", |
| 1179 | 4, |
| 1180 | (struct phy_cmd[]){ /* config */ |
| 1181 | /* Reset and configure the PHY */ |
| 1182 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1183 | {0x16, 0x0002, NULL}, /* Change Page Number */ |
| 1184 | {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */ |
Ron Madrid | 12a8b9d | 2009-01-28 16:17:21 -0800 | [diff] [blame] | 1185 | {0x16, 0x0003, NULL}, /* Change Page Number */ |
| 1186 | {0x10, 0x021e, NULL}, /* Adjust LED control */ |
| 1187 | {0x16, 0x0000, NULL}, /* Change Page Number */ |
Ron Madrid | 290ef64 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1188 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1189 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1190 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1191 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1192 | {miim_end,} |
| 1193 | }, |
| 1194 | (struct phy_cmd[]){ /* startup */ |
| 1195 | {0x16, 0x0000, NULL}, /* Change Page Number */ |
| 1196 | /* Status is read once to clear old link state */ |
| 1197 | {MIIM_STATUS, miim_read, NULL}, |
| 1198 | /* Auto-negotiate */ |
Ron Madrid | 12a8b9d | 2009-01-28 16:17:21 -0800 | [diff] [blame] | 1199 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
Ron Madrid | 290ef64 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1200 | /* Read the status */ |
| 1201 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1202 | &mii_parse_88E1011_psr}, |
| 1203 | {miim_end,} |
| 1204 | }, |
| 1205 | (struct phy_cmd[]){ /* shutdown */ |
| 1206 | {miim_end,} |
| 1207 | }, |
| 1208 | }; |
| 1209 | |
Sergei Poselenov | d23dc39 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1210 | /* |
| 1211 | * Since to access LED register we need do switch the page, we |
| 1212 | * do LED configuring in the miim_read-like function as follows |
| 1213 | */ |
| 1214 | uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv) |
| 1215 | { |
| 1216 | uint pg; |
| 1217 | |
| 1218 | /* Switch the page to access the led register */ |
| 1219 | pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE); |
| 1220 | write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE); |
| 1221 | |
| 1222 | /* Configure leds */ |
| 1223 | write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL, |
| 1224 | MIIM_88E1121_PHY_LED_DEF); |
| 1225 | |
| 1226 | /* Restore the page pointer */ |
| 1227 | write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg); |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | struct phy_info phy_info_M88E1121R = { |
| 1232 | 0x01410cb, |
| 1233 | "Marvell 88E1121R", |
| 1234 | 4, |
| 1235 | (struct phy_cmd[]){ /* config */ |
| 1236 | /* Reset and configure the PHY */ |
| 1237 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1238 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1239 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1240 | /* Configure leds */ |
| 1241 | {MIIM_88E1121_PHY_LED_CTRL, miim_read, |
| 1242 | &mii_88E1121_set_led}, |
| 1243 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
Anatolij Gustschin | 23afaba | 2008-12-02 10:31:04 +0100 | [diff] [blame] | 1244 | /* Disable IRQs and de-assert interrupt */ |
| 1245 | {MIIM_88E1121_PHY_IRQ_EN, 0, NULL}, |
| 1246 | {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL}, |
Sergei Poselenov | d23dc39 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1247 | {miim_end,} |
| 1248 | }, |
| 1249 | (struct phy_cmd[]){ /* startup */ |
| 1250 | /* Status is read once to clear old link state */ |
| 1251 | {MIIM_STATUS, miim_read, NULL}, |
| 1252 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1253 | {MIIM_STATUS, miim_read, &mii_parse_link}, |
| 1254 | {miim_end,} |
| 1255 | }, |
| 1256 | (struct phy_cmd[]){ /* shutdown */ |
| 1257 | {miim_end,} |
| 1258 | }, |
| 1259 | }; |
| 1260 | |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1261 | static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv) |
| 1262 | { |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1263 | uint mii_data = read_phy_reg(priv, mii_reg); |
| 1264 | |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1265 | /* Setting MIIM_88E1145_PHY_EXT_CR */ |
| 1266 | if (priv->flags & TSEC_REDUCED) |
| 1267 | return mii_data | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1268 | MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY; |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1269 | else |
| 1270 | return mii_data; |
| 1271 | } |
| 1272 | |
| 1273 | static struct phy_info phy_info_M88E1145 = { |
| 1274 | 0x01410cd, |
| 1275 | "Marvell 88E1145", |
| 1276 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1277 | (struct phy_cmd[]){ /* config */ |
Andy Fleming | 7507d56 | 2007-05-08 17:23:02 -0500 | [diff] [blame] | 1278 | /* Reset the PHY */ |
| 1279 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1280 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1281 | /* Errata E0, E1 */ |
| 1282 | {29, 0x001b, NULL}, |
| 1283 | {30, 0x418f, NULL}, |
| 1284 | {29, 0x0016, NULL}, |
| 1285 | {30, 0xa2da, NULL}, |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1286 | |
Andy Fleming | 7507d56 | 2007-05-08 17:23:02 -0500 | [diff] [blame] | 1287 | /* Configure the PHY */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1288 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1289 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1290 | {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, |
| 1291 | NULL}, |
| 1292 | {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode}, |
| 1293 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1294 | {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL}, |
| 1295 | {miim_end,} |
| 1296 | }, |
| 1297 | (struct phy_cmd[]){ /* startup */ |
| 1298 | /* Status is read once to clear old link state */ |
| 1299 | {MIIM_STATUS, miim_read, NULL}, |
| 1300 | /* Auto-negotiate */ |
| 1301 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1302 | {MIIM_88E1111_PHY_LED_CONTROL, |
| 1303 | MIIM_88E1111_PHY_LED_DIRECT, NULL}, |
| 1304 | /* Read the Status */ |
| 1305 | {MIIM_88E1011_PHY_STATUS, miim_read, |
| 1306 | &mii_parse_88E1011_psr}, |
| 1307 | {miim_end,} |
| 1308 | }, |
| 1309 | (struct phy_cmd[]){ /* shutdown */ |
| 1310 | {miim_end,} |
| 1311 | }, |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1312 | }; |
| 1313 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1314 | struct phy_info phy_info_cis8204 = { |
| 1315 | 0x3f11, |
| 1316 | "Cicada Cis8204", |
| 1317 | 6, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1318 | (struct phy_cmd[]){ /* config */ |
| 1319 | /* Override PHY config settings */ |
| 1320 | {MIIM_CIS8201_AUX_CONSTAT, |
| 1321 | MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1322 | /* Configure some basic stuff */ |
| 1323 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1324 | {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT, |
| 1325 | &mii_cis8204_fixled}, |
| 1326 | {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT, |
| 1327 | &mii_cis8204_setmode}, |
| 1328 | {miim_end,} |
| 1329 | }, |
| 1330 | (struct phy_cmd[]){ /* startup */ |
| 1331 | /* Read the Status (2x to make sure link is right) */ |
| 1332 | {MIIM_STATUS, miim_read, NULL}, |
| 1333 | /* Auto-negotiate */ |
| 1334 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1335 | /* Read the status */ |
| 1336 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, |
| 1337 | &mii_parse_cis8201}, |
| 1338 | {miim_end,} |
| 1339 | }, |
| 1340 | (struct phy_cmd[]){ /* shutdown */ |
| 1341 | {miim_end,} |
| 1342 | }, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1343 | }; |
| 1344 | |
| 1345 | /* Cicada 8201 */ |
| 1346 | struct phy_info phy_info_cis8201 = { |
| 1347 | 0xfc41, |
| 1348 | "CIS8201", |
| 1349 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1350 | (struct phy_cmd[]){ /* config */ |
| 1351 | /* Override PHY config settings */ |
| 1352 | {MIIM_CIS8201_AUX_CONSTAT, |
| 1353 | MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1354 | /* Set up the interface mode */ |
| 1355 | {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, |
| 1356 | NULL}, |
| 1357 | /* Configure some basic stuff */ |
| 1358 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1359 | {miim_end,} |
| 1360 | }, |
| 1361 | (struct phy_cmd[]){ /* startup */ |
| 1362 | /* Read the Status (2x to make sure link is right) */ |
| 1363 | {MIIM_STATUS, miim_read, NULL}, |
| 1364 | /* Auto-negotiate */ |
| 1365 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1366 | /* Read the status */ |
| 1367 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, |
| 1368 | &mii_parse_cis8201}, |
| 1369 | {miim_end,} |
| 1370 | }, |
| 1371 | (struct phy_cmd[]){ /* shutdown */ |
| 1372 | {miim_end,} |
| 1373 | }, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1374 | }; |
Pieter Henning | 736323a | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1375 | struct phy_info phy_info_VSC8211 = { |
| 1376 | 0xfc4b, |
| 1377 | "Vitesse VSC8211", |
| 1378 | 4, |
| 1379 | (struct phy_cmd[]) { /* config */ |
| 1380 | /* Override PHY config settings */ |
| 1381 | {MIIM_CIS8201_AUX_CONSTAT, |
| 1382 | MIIM_CIS8201_AUXCONSTAT_INIT, NULL}, |
| 1383 | /* Set up the interface mode */ |
| 1384 | {MIIM_CIS8201_EXT_CON1, |
| 1385 | MIIM_CIS8201_EXTCON1_INIT, NULL}, |
| 1386 | /* Configure some basic stuff */ |
| 1387 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1388 | {miim_end,} |
| 1389 | }, |
| 1390 | (struct phy_cmd[]) { /* startup */ |
| 1391 | /* Read the Status (2x to make sure link is right) */ |
| 1392 | {MIIM_STATUS, miim_read, NULL}, |
| 1393 | /* Auto-negotiate */ |
| 1394 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1395 | /* Read the status */ |
| 1396 | {MIIM_CIS8201_AUX_CONSTAT, miim_read, |
| 1397 | &mii_parse_cis8201}, |
| 1398 | {miim_end,} |
| 1399 | }, |
| 1400 | (struct phy_cmd[]) { /* shutdown */ |
| 1401 | {miim_end,} |
| 1402 | }, |
| 1403 | }; |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1404 | struct phy_info phy_info_VSC8244 = { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1405 | 0x3f1b, |
| 1406 | "Vitesse VSC8244", |
| 1407 | 6, |
| 1408 | (struct phy_cmd[]){ /* config */ |
| 1409 | /* Override PHY config settings */ |
| 1410 | /* Configure some basic stuff */ |
| 1411 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1412 | {miim_end,} |
| 1413 | }, |
| 1414 | (struct phy_cmd[]){ /* startup */ |
| 1415 | /* Read the Status (2x to make sure link is right) */ |
| 1416 | {MIIM_STATUS, miim_read, NULL}, |
| 1417 | /* Auto-negotiate */ |
| 1418 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1419 | /* Read the status */ |
| 1420 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, |
| 1421 | &mii_parse_vsc8244}, |
| 1422 | {miim_end,} |
| 1423 | }, |
| 1424 | (struct phy_cmd[]){ /* shutdown */ |
| 1425 | {miim_end,} |
| 1426 | }, |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1427 | }; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1428 | |
Tor Krill | 2d934ea | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1429 | struct phy_info phy_info_VSC8601 = { |
| 1430 | 0x00007042, |
| 1431 | "Vitesse VSC8601", |
| 1432 | 4, |
| 1433 | (struct phy_cmd[]){ /* config */ |
| 1434 | /* Override PHY config settings */ |
| 1435 | /* Configure some basic stuff */ |
| 1436 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1437 | #ifdef CONFIG_SYS_VSC8601_SKEWFIX |
Tor Krill | 2d934ea | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1438 | {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL}, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1439 | #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX) |
Andre Schwarz | 9acde12 | 2008-04-29 19:18:32 +0200 | [diff] [blame] | 1440 | {MIIM_EXT_PAGE_ACCESS,1,NULL}, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1441 | #define VSC8101_SKEW (CONFIG_SYS_VSC8601_SKEW_TX<<14)|(CONFIG_SYS_VSC8601_SKEW_RX<<12) |
Andre Schwarz | 9acde12 | 2008-04-29 19:18:32 +0200 | [diff] [blame] | 1442 | {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL}, |
| 1443 | {MIIM_EXT_PAGE_ACCESS,0,NULL}, |
| 1444 | #endif |
Tor Krill | 2d934ea | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1445 | #endif |
Andre Schwarz | c9d6b69 | 2008-08-19 16:07:03 +0200 | [diff] [blame] | 1446 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1447 | {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init}, |
Tor Krill | 2d934ea | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1448 | {miim_end,} |
| 1449 | }, |
| 1450 | (struct phy_cmd[]){ /* startup */ |
| 1451 | /* Read the Status (2x to make sure link is right) */ |
| 1452 | {MIIM_STATUS, miim_read, NULL}, |
| 1453 | /* Auto-negotiate */ |
| 1454 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1455 | /* Read the status */ |
| 1456 | {MIIM_VSC8244_AUX_CONSTAT, miim_read, |
| 1457 | &mii_parse_vsc8244}, |
| 1458 | {miim_end,} |
| 1459 | }, |
| 1460 | (struct phy_cmd[]){ /* shutdown */ |
| 1461 | {miim_end,} |
| 1462 | }, |
| 1463 | }; |
| 1464 | |
| 1465 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1466 | struct phy_info phy_info_dm9161 = { |
| 1467 | 0x0181b88, |
| 1468 | "Davicom DM9161E", |
| 1469 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1470 | (struct phy_cmd[]){ /* config */ |
| 1471 | {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL}, |
| 1472 | /* Do not bypass the scrambler/descrambler */ |
| 1473 | {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL}, |
| 1474 | /* Clear 10BTCSR to default */ |
| 1475 | {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, |
| 1476 | NULL}, |
| 1477 | /* Configure some basic stuff */ |
| 1478 | {MIIM_CONTROL, MIIM_CR_INIT, NULL}, |
| 1479 | /* Restart Auto Negotiation */ |
| 1480 | {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL}, |
| 1481 | {miim_end,} |
| 1482 | }, |
| 1483 | (struct phy_cmd[]){ /* startup */ |
| 1484 | /* Status is read once to clear old link state */ |
| 1485 | {MIIM_STATUS, miim_read, NULL}, |
| 1486 | /* Auto-negotiate */ |
| 1487 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1488 | /* Read the status */ |
| 1489 | {MIIM_DM9161_SCSR, miim_read, |
| 1490 | &mii_parse_dm9161_scsr}, |
| 1491 | {miim_end,} |
| 1492 | }, |
| 1493 | (struct phy_cmd[]){ /* shutdown */ |
| 1494 | {miim_end,} |
| 1495 | }, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1496 | }; |
David Updegraff | af1c2b8 | 2007-04-20 14:34:48 -0500 | [diff] [blame] | 1497 | /* a generic flavor. */ |
| 1498 | struct phy_info phy_info_generic = { |
| 1499 | 0, |
| 1500 | "Unknown/Generic PHY", |
| 1501 | 32, |
| 1502 | (struct phy_cmd[]) { /* config */ |
| 1503 | {PHY_BMCR, PHY_BMCR_RESET, NULL}, |
| 1504 | {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL}, |
| 1505 | {miim_end,} |
| 1506 | }, |
| 1507 | (struct phy_cmd[]) { /* startup */ |
| 1508 | {PHY_BMSR, miim_read, NULL}, |
| 1509 | {PHY_BMSR, miim_read, &mii_parse_sr}, |
| 1510 | {PHY_BMSR, miim_read, &mii_parse_link}, |
| 1511 | {miim_end,} |
| 1512 | }, |
| 1513 | (struct phy_cmd[]) { /* shutdown */ |
| 1514 | {miim_end,} |
| 1515 | } |
| 1516 | }; |
| 1517 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1518 | |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1519 | uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv) |
| 1520 | { |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1521 | unsigned int speed; |
| 1522 | if (priv->link) { |
| 1523 | speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK; |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1524 | |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1525 | switch (speed) { |
| 1526 | case MIIM_LXT971_SR2_10HDX: |
| 1527 | priv->speed = 10; |
| 1528 | priv->duplexity = 0; |
| 1529 | break; |
| 1530 | case MIIM_LXT971_SR2_10FDX: |
| 1531 | priv->speed = 10; |
| 1532 | priv->duplexity = 1; |
| 1533 | break; |
| 1534 | case MIIM_LXT971_SR2_100HDX: |
| 1535 | priv->speed = 100; |
| 1536 | priv->duplexity = 0; |
urwithsughosh@gmail.com | cd2d160 | 2007-09-10 14:54:56 -0400 | [diff] [blame] | 1537 | break; |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1538 | default: |
| 1539 | priv->speed = 100; |
| 1540 | priv->duplexity = 1; |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1541 | } |
| 1542 | } else { |
| 1543 | priv->speed = 0; |
| 1544 | priv->duplexity = 0; |
| 1545 | } |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1546 | |
wdenk | 3c2b3d4 | 2005-04-05 23:32:21 +0000 | [diff] [blame] | 1547 | return 0; |
wdenk | 3dd7f0f | 2005-04-04 23:43:44 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1550 | static struct phy_info phy_info_lxt971 = { |
| 1551 | 0x0001378e, |
| 1552 | "LXT971", |
| 1553 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1554 | (struct phy_cmd[]){ /* config */ |
| 1555 | {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */ |
| 1556 | {miim_end,} |
| 1557 | }, |
| 1558 | (struct phy_cmd[]){ /* startup - enable interrupts */ |
| 1559 | /* { 0x12, 0x00f2, NULL }, */ |
| 1560 | {MIIM_STATUS, miim_read, NULL}, |
| 1561 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1562 | {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2}, |
| 1563 | {miim_end,} |
| 1564 | }, |
| 1565 | (struct phy_cmd[]){ /* shutdown - disable interrupts */ |
| 1566 | {miim_end,} |
| 1567 | }, |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1568 | }; |
| 1569 | |
Wolfgang Denk | be5048f | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1570 | /* Parse the DP83865's link and auto-neg status register for speed and duplex |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1571 | * information |
| 1572 | */ |
Wolfgang Denk | be5048f | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1573 | uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv) |
| 1574 | { |
| 1575 | switch (mii_reg & MIIM_DP83865_SPD_MASK) { |
| 1576 | |
| 1577 | case MIIM_DP83865_SPD_1000: |
| 1578 | priv->speed = 1000; |
| 1579 | break; |
| 1580 | |
| 1581 | case MIIM_DP83865_SPD_100: |
| 1582 | priv->speed = 100; |
| 1583 | break; |
| 1584 | |
| 1585 | default: |
| 1586 | priv->speed = 10; |
| 1587 | break; |
| 1588 | |
| 1589 | } |
| 1590 | |
| 1591 | if (mii_reg & MIIM_DP83865_DPX_FULL) |
| 1592 | priv->duplexity = 1; |
| 1593 | else |
| 1594 | priv->duplexity = 0; |
| 1595 | |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | struct phy_info phy_info_dp83865 = { |
| 1600 | 0x20005c7, |
| 1601 | "NatSemi DP83865", |
| 1602 | 4, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1603 | (struct phy_cmd[]){ /* config */ |
| 1604 | {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL}, |
| 1605 | {miim_end,} |
| 1606 | }, |
| 1607 | (struct phy_cmd[]){ /* startup */ |
| 1608 | /* Status is read once to clear old link state */ |
| 1609 | {MIIM_STATUS, miim_read, NULL}, |
| 1610 | /* Auto-negotiate */ |
| 1611 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1612 | /* Read the link and auto-neg status */ |
| 1613 | {MIIM_DP83865_LANR, miim_read, |
| 1614 | &mii_parse_dp83865_lanr}, |
| 1615 | {miim_end,} |
| 1616 | }, |
| 1617 | (struct phy_cmd[]){ /* shutdown */ |
| 1618 | {miim_end,} |
| 1619 | }, |
Wolfgang Denk | be5048f | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1620 | }; |
| 1621 | |
Dave Liu | 18ee320 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1622 | struct phy_info phy_info_rtl8211b = { |
| 1623 | 0x001cc91, |
| 1624 | "RealTek RTL8211B", |
| 1625 | 4, |
| 1626 | (struct phy_cmd[]){ /* config */ |
| 1627 | /* Reset and configure the PHY */ |
| 1628 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1629 | {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL}, |
| 1630 | {MIIM_ANAR, MIIM_ANAR_INIT, NULL}, |
| 1631 | {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL}, |
| 1632 | {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init}, |
| 1633 | {miim_end,} |
| 1634 | }, |
| 1635 | (struct phy_cmd[]){ /* startup */ |
| 1636 | /* Status is read once to clear old link state */ |
| 1637 | {MIIM_STATUS, miim_read, NULL}, |
| 1638 | /* Auto-negotiate */ |
| 1639 | {MIIM_STATUS, miim_read, &mii_parse_sr}, |
| 1640 | /* Read the status */ |
| 1641 | {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr}, |
| 1642 | {miim_end,} |
| 1643 | }, |
| 1644 | (struct phy_cmd[]){ /* shutdown */ |
| 1645 | {miim_end,} |
| 1646 | }, |
| 1647 | }; |
| 1648 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1649 | struct phy_info *phy_info[] = { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1650 | &phy_info_cis8204, |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 1651 | &phy_info_cis8201, |
Paul Gortmaker | 91e2576 | 2007-01-16 11:38:14 -0500 | [diff] [blame] | 1652 | &phy_info_BCM5461S, |
Joe Hamman | c3243cf | 2007-04-30 16:47:28 -0500 | [diff] [blame] | 1653 | &phy_info_BCM5464S, |
Zach LeRoy | 091dc9f | 2009-05-22 10:26:33 -0500 | [diff] [blame^] | 1654 | &phy_info_BCM5482S, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1655 | &phy_info_M88E1011S, |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1656 | &phy_info_M88E1111S, |
Ron Madrid | 290ef64 | 2008-05-23 15:37:05 -0700 | [diff] [blame] | 1657 | &phy_info_M88E1118, |
Sergei Poselenov | d23dc39 | 2008-06-06 15:52:44 +0200 | [diff] [blame] | 1658 | &phy_info_M88E1121R, |
Andy Fleming | 09f3e09 | 2006-09-13 10:34:18 -0500 | [diff] [blame] | 1659 | &phy_info_M88E1145, |
Wolfgang Denk | 5728be3 | 2007-08-06 01:01:49 +0200 | [diff] [blame] | 1660 | &phy_info_M88E1149S, |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1661 | &phy_info_dm9161, |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1662 | &phy_info_lxt971, |
Pieter Henning | 736323a | 2009-02-22 23:17:15 -0800 | [diff] [blame] | 1663 | &phy_info_VSC8211, |
Jon Loeliger | debb735 | 2006-04-26 17:58:56 -0500 | [diff] [blame] | 1664 | &phy_info_VSC8244, |
Tor Krill | 2d934ea | 2008-03-28 15:29:45 +0100 | [diff] [blame] | 1665 | &phy_info_VSC8601, |
Wolfgang Denk | be5048f | 2006-03-12 22:50:55 +0100 | [diff] [blame] | 1666 | &phy_info_dp83865, |
Dave Liu | 18ee320 | 2008-01-11 18:45:28 +0800 | [diff] [blame] | 1667 | &phy_info_rtl8211b, |
Paul Gortmaker | 0452352 | 2009-03-09 18:07:53 -0500 | [diff] [blame] | 1668 | &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1669 | NULL |
| 1670 | }; |
| 1671 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1672 | /* Grab the identifier of the device's PHY, and search through |
wdenk | 9d46ea4 | 2005-03-14 23:56:42 +0000 | [diff] [blame] | 1673 | * all of the known PHYs to see if one matches. If so, return |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1674 | * it, if not, return NULL |
| 1675 | */ |
| 1676 | struct phy_info *get_phy_info(struct eth_device *dev) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1677 | { |
| 1678 | struct tsec_private *priv = (struct tsec_private *)dev->priv; |
| 1679 | uint phy_reg, phy_ID; |
| 1680 | int i; |
| 1681 | struct phy_info *theInfo = NULL; |
| 1682 | |
| 1683 | /* Grab the bits from PHYIR1, and put them in the upper half */ |
| 1684 | phy_reg = read_phy_reg(priv, MIIM_PHYIR1); |
| 1685 | phy_ID = (phy_reg & 0xffff) << 16; |
| 1686 | |
| 1687 | /* Grab the bits from PHYIR2, and put them in the lower half */ |
| 1688 | phy_reg = read_phy_reg(priv, MIIM_PHYIR2); |
| 1689 | phy_ID |= (phy_reg & 0xffff); |
| 1690 | |
| 1691 | /* loop through all the known PHY types, and find one that */ |
| 1692 | /* matches the ID we read from the PHY. */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1693 | for (i = 0; phy_info[i]; i++) { |
Andy Fleming | 2a3cee4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1694 | if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1695 | theInfo = phy_info[i]; |
Andy Fleming | 2a3cee4 | 2007-05-09 00:54:20 -0500 | [diff] [blame] | 1696 | break; |
| 1697 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Paul Gortmaker | 0452352 | 2009-03-09 18:07:53 -0500 | [diff] [blame] | 1700 | if (theInfo == &phy_info_generic) { |
| 1701 | printf("%s: No support for PHY id %x; assuming generic\n", dev->name, phy_ID); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1702 | } else { |
Stefan Roese | 5810dc3 | 2005-09-21 18:20:22 +0200 | [diff] [blame] | 1703 | debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | return theInfo; |
| 1707 | } |
| 1708 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1709 | /* Execute the given series of commands on the given device's |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1710 | * PHY, running functions as necessary |
| 1711 | */ |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1712 | void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd) |
| 1713 | { |
| 1714 | int i; |
| 1715 | uint result; |
| 1716 | volatile tsec_t *phyregs = priv->phyregs; |
| 1717 | |
| 1718 | phyregs->miimcfg = MIIMCFG_RESET; |
| 1719 | |
| 1720 | phyregs->miimcfg = MIIMCFG_INIT_VALUE; |
| 1721 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1722 | while (phyregs->miimind & MIIMIND_BUSY) ; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1723 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1724 | for (i = 0; cmd->mii_reg != miim_end; i++) { |
| 1725 | if (cmd->mii_data == miim_read) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1726 | result = read_phy_reg(priv, cmd->mii_reg); |
| 1727 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1728 | if (cmd->funct != NULL) |
| 1729 | (*(cmd->funct)) (result, priv); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1730 | |
| 1731 | } else { |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1732 | if (cmd->funct != NULL) |
| 1733 | result = (*(cmd->funct)) (cmd->mii_reg, priv); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1734 | else |
| 1735 | result = cmd->mii_data; |
| 1736 | |
| 1737 | write_phy_reg(priv, cmd->mii_reg, result); |
| 1738 | |
| 1739 | } |
| 1740 | cmd++; |
| 1741 | } |
| 1742 | } |
| 1743 | |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1744 | /* Relocate the function pointers in the phy cmd lists */ |
| 1745 | static void relocate_cmds(void) |
| 1746 | { |
| 1747 | struct phy_cmd **cmdlistptr; |
| 1748 | struct phy_cmd *cmd; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1749 | int i, j, k; |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1750 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1751 | for (i = 0; phy_info[i]; i++) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1752 | /* First thing's first: relocate the pointers to the |
| 1753 | * PHY command structures (the structs were done) */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1754 | phy_info[i] = (struct phy_info *)((uint) phy_info[i] |
| 1755 | + gd->reloc_off); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1756 | phy_info[i]->name += gd->reloc_off; |
| 1757 | phy_info[i]->config = |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1758 | (struct phy_cmd *)((uint) phy_info[i]->config |
| 1759 | + gd->reloc_off); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1760 | phy_info[i]->startup = |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1761 | (struct phy_cmd *)((uint) phy_info[i]->startup |
| 1762 | + gd->reloc_off); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1763 | phy_info[i]->shutdown = |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1764 | (struct phy_cmd *)((uint) phy_info[i]->shutdown |
| 1765 | + gd->reloc_off); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1766 | |
| 1767 | cmdlistptr = &phy_info[i]->config; |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1768 | j = 0; |
| 1769 | for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) { |
| 1770 | k = 0; |
| 1771 | for (cmd = *cmdlistptr; |
| 1772 | cmd->mii_reg != miim_end; |
| 1773 | cmd++) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1774 | /* Only relocate non-NULL pointers */ |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1775 | if (cmd->funct) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1776 | cmd->funct += gd->reloc_off; |
| 1777 | |
| 1778 | k++; |
| 1779 | } |
| 1780 | j++; |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | relocated = 1; |
| 1785 | } |
| 1786 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1787 | #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1788 | && !defined(BITBANGMII) |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1789 | |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1790 | /* |
| 1791 | * Read a MII PHY register. |
| 1792 | * |
| 1793 | * Returns: |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1794 | * 0 on success |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1795 | */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1796 | static int tsec_miiphy_read(char *devname, unsigned char addr, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1797 | unsigned char reg, unsigned short *value) |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1798 | { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1799 | unsigned short ret; |
michael.firth@bt.com | 55fe7c5 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 1800 | struct tsec_private *priv = privlist[0]; |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1801 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1802 | if (NULL == priv) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1803 | printf("Can't read PHY at address %d\n", addr); |
| 1804 | return -1; |
| 1805 | } |
| 1806 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 1807 | ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg); |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1808 | *value = ret; |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1809 | |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
| 1813 | /* |
| 1814 | * Write a MII PHY register. |
| 1815 | * |
| 1816 | * Returns: |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1817 | * 0 on success |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1818 | */ |
Marian Balakowicz | 63ff004 | 2005-10-28 22:30:33 +0200 | [diff] [blame] | 1819 | static int tsec_miiphy_write(char *devname, unsigned char addr, |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1820 | unsigned char reg, unsigned short value) |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1821 | { |
michael.firth@bt.com | 55fe7c5 | 2008-01-16 11:40:51 +0000 | [diff] [blame] | 1822 | struct tsec_private *priv = privlist[0]; |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1823 | |
Jon Loeliger | 89875e9 | 2006-10-10 17:03:43 -0500 | [diff] [blame] | 1824 | if (NULL == priv) { |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1825 | printf("Can't write PHY at address %d\n", addr); |
| 1826 | return -1; |
| 1827 | } |
| 1828 | |
Andy Fleming | 2abe361 | 2008-08-31 16:33:27 -0500 | [diff] [blame] | 1829 | tsec_local_mdio_write(priv->phyregs, addr, reg, value); |
wdenk | 7abf0c5 | 2004-04-18 21:45:42 +0000 | [diff] [blame] | 1830 | |
| 1831 | return 0; |
| 1832 | } |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1833 | |
Jon Loeliger | cb51c0b | 2007-07-09 17:39:42 -0500 | [diff] [blame] | 1834 | #endif |
wdenk | 97d80fc | 2004-06-09 00:34:46 +0000 | [diff] [blame] | 1835 | |
David Updegraff | 53a5c42 | 2007-06-11 10:41:07 -0500 | [diff] [blame] | 1836 | #ifdef CONFIG_MCAST_TFTP |
| 1837 | |
| 1838 | /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */ |
| 1839 | |
| 1840 | /* Set the appropriate hash bit for the given addr */ |
| 1841 | |
| 1842 | /* The algorithm works like so: |
| 1843 | * 1) Take the Destination Address (ie the multicast address), and |
| 1844 | * do a CRC on it (little endian), and reverse the bits of the |
| 1845 | * result. |
| 1846 | * 2) Use the 8 most significant bits as a hash into a 256-entry |
| 1847 | * table. The table is controlled through 8 32-bit registers: |
| 1848 | * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is |
| 1849 | * gaddr7. This means that the 3 most significant bits in the |
| 1850 | * hash index which gaddr register to use, and the 5 other bits |
| 1851 | * indicate which bit (assuming an IBM numbering scheme, which |
| 1852 | * for PowerPC (tm) is usually the case) in the tregister holds |
| 1853 | * the entry. */ |
| 1854 | static int |
| 1855 | tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set) |
| 1856 | { |
| 1857 | struct tsec_private *priv = privlist[1]; |
| 1858 | volatile tsec_t *regs = priv->regs; |
| 1859 | volatile u32 *reg_array, value; |
| 1860 | u8 result, whichbit, whichreg; |
| 1861 | |
| 1862 | result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff); |
| 1863 | whichbit = result & 0x1f; /* the 5 LSB = which bit to set */ |
| 1864 | whichreg = result >> 5; /* the 3 MSB = which reg to set it in */ |
| 1865 | value = (1 << (31-whichbit)); |
| 1866 | |
| 1867 | reg_array = &(regs->hash.gaddr0); |
| 1868 | |
| 1869 | if (set) { |
| 1870 | reg_array[whichreg] |= value; |
| 1871 | } else { |
| 1872 | reg_array[whichreg] &= ~value; |
| 1873 | } |
| 1874 | return 0; |
| 1875 | } |
| 1876 | #endif /* Multicast TFTP ? */ |