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