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