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