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