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