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