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