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