wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * INCA-IP internal switch ethernet driver. |
| 3 | * |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 4 | * (C) Copyright 2003-2004 |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 5 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #include <common.h> |
| 28 | |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 29 | #include <malloc.h> |
| 30 | #include <net.h> |
| 31 | #include <asm/inca-ip.h> |
| 32 | #include <asm/addrspace.h> |
| 33 | |
| 34 | |
| 35 | #define NUM_RX_DESC PKTBUFSRX |
| 36 | #define NUM_TX_DESC 3 |
| 37 | #define TOUT_LOOP 1000000 |
| 38 | |
| 39 | |
| 40 | #define DELAY udelay(10000) |
wdenk | 7f1447f | 2004-06-09 00:10:59 +0000 | [diff] [blame] | 41 | /* Sometimes the store word instruction hangs while writing to one |
| 42 | * of the Switch registers. Moving the instruction into a separate |
| 43 | * function somehow makes the problem go away. |
| 44 | */ |
| 45 | static void SWORD(volatile u32 * reg, u32 value) |
| 46 | { |
| 47 | *reg = value; |
| 48 | } |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 49 | |
| 50 | #define DMA_WRITE_REG(reg, value) *((volatile u32 *)reg) = (u32)value; |
| 51 | #define DMA_READ_REG(reg, value) value = (u32)*((volatile u32*)reg) |
| 52 | #define SW_WRITE_REG(reg, value) \ |
wdenk | 7f1447f | 2004-06-09 00:10:59 +0000 | [diff] [blame] | 53 | SWORD(reg, value);\ |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 54 | DELAY;\ |
wdenk | 7f1447f | 2004-06-09 00:10:59 +0000 | [diff] [blame] | 55 | SWORD(reg, value); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 56 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 57 | #define SW_READ_REG(reg, value) \ |
| 58 | value = (u32)*((volatile u32*)reg);\ |
| 59 | DELAY;\ |
| 60 | value = (u32)*((volatile u32*)reg); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 61 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 62 | #define INCA_DMA_TX_POLLING_TIME 0x07 |
| 63 | #define INCA_DMA_RX_POLLING_TIME 0x07 |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 64 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 65 | #define INCA_DMA_TX_HOLD 0x80000000 |
| 66 | #define INCA_DMA_TX_EOP 0x40000000 |
| 67 | #define INCA_DMA_TX_SOP 0x20000000 |
| 68 | #define INCA_DMA_TX_ICPT 0x10000000 |
| 69 | #define INCA_DMA_TX_IEOP 0x08000000 |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 70 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 71 | #define INCA_DMA_RX_C 0x80000000 |
| 72 | #define INCA_DMA_RX_SOP 0x40000000 |
| 73 | #define INCA_DMA_RX_EOP 0x20000000 |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 74 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 75 | #define INCA_SWITCH_PHY_SPEED_10H 0x1 |
| 76 | #define INCA_SWITCH_PHY_SPEED_10F 0x5 |
| 77 | #define INCA_SWITCH_PHY_SPEED_100H 0x2 |
| 78 | #define INCA_SWITCH_PHY_SPEED_100F 0x6 |
| 79 | |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 80 | /************************ Auto MDIX settings ************************/ |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 81 | #define INCA_IP_AUTO_MDIX_LAN_PORTS_DIR INCA_IP_Ports_P1_DIR |
| 82 | #define INCA_IP_AUTO_MDIX_LAN_PORTS_ALTSEL INCA_IP_Ports_P1_ALTSEL |
| 83 | #define INCA_IP_AUTO_MDIX_LAN_PORTS_OUT INCA_IP_Ports_P1_OUT |
| 84 | #define INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX 16 |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 85 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 86 | #define WAIT_SIGNAL_RETRIES 100 |
| 87 | #define WAIT_LINK_RETRIES 100 |
| 88 | #define LINK_RETRY_DELAY 2000 /* ms */ |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 89 | /********************************************************************/ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 90 | |
| 91 | typedef struct |
| 92 | { |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 93 | union { |
| 94 | struct { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 95 | volatile u32 HOLD :1; |
| 96 | volatile u32 ICpt :1; |
| 97 | volatile u32 IEop :1; |
| 98 | volatile u32 offset :3; |
| 99 | volatile u32 reserved0 :4; |
| 100 | volatile u32 NFB :22; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 101 | }field; |
| 102 | |
| 103 | volatile u32 word; |
| 104 | }params; |
| 105 | |
| 106 | volatile u32 nextRxDescPtr; |
| 107 | |
| 108 | volatile u32 RxDataPtr; |
| 109 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 110 | union { |
| 111 | struct { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 112 | volatile u32 C :1; |
| 113 | volatile u32 Sop :1; |
| 114 | volatile u32 Eop :1; |
| 115 | volatile u32 reserved3 :12; |
| 116 | volatile u32 NBT :17; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 117 | }field; |
| 118 | |
| 119 | volatile u32 word; |
| 120 | }status; |
| 121 | |
| 122 | } inca_rx_descriptor_t; |
| 123 | |
| 124 | |
| 125 | typedef struct |
| 126 | { |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 127 | union { |
| 128 | struct { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 129 | volatile u32 HOLD :1; |
| 130 | volatile u32 Eop :1; |
| 131 | volatile u32 Sop :1; |
| 132 | volatile u32 ICpt :1; |
| 133 | volatile u32 IEop :1; |
| 134 | volatile u32 reserved0 :5; |
| 135 | volatile u32 NBA :22; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 136 | }field; |
| 137 | |
| 138 | volatile u32 word; |
| 139 | }params; |
| 140 | |
| 141 | volatile u32 nextTxDescPtr; |
| 142 | |
| 143 | volatile u32 TxDataPtr; |
| 144 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 145 | volatile u32 C :1; |
| 146 | volatile u32 reserved3 :31; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 147 | |
| 148 | } inca_tx_descriptor_t; |
| 149 | |
| 150 | |
| 151 | static inca_rx_descriptor_t rx_ring[NUM_RX_DESC] __attribute__ ((aligned(16))); |
| 152 | static inca_tx_descriptor_t tx_ring[NUM_TX_DESC] __attribute__ ((aligned(16))); |
| 153 | |
| 154 | static int tx_new, rx_new, tx_hold, rx_hold; |
| 155 | static int tx_old_hold = -1; |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 156 | static int initialized = 0; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 157 | |
| 158 | |
| 159 | static int inca_switch_init(struct eth_device *dev, bd_t * bis); |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 160 | static int inca_switch_send(struct eth_device *dev, volatile void *packet, int length); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 161 | static int inca_switch_recv(struct eth_device *dev); |
| 162 | static void inca_switch_halt(struct eth_device *dev); |
| 163 | static void inca_init_switch_chip(void); |
| 164 | static void inca_dma_init(void); |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 165 | static int inca_amdix(void); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 166 | |
| 167 | |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 168 | int inca_switch_initialize(bd_t * bis) |
| 169 | { |
| 170 | struct eth_device *dev; |
| 171 | |
| 172 | #if 0 |
| 173 | printf("Entered inca_switch_initialize()\n"); |
| 174 | #endif |
| 175 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 176 | if (!(dev = (struct eth_device *) malloc (sizeof *dev))) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 177 | printf("Failed to allocate memory\n"); |
| 178 | return 0; |
| 179 | } |
| 180 | memset(dev, 0, sizeof(*dev)); |
| 181 | |
| 182 | inca_dma_init(); |
| 183 | |
| 184 | inca_init_switch_chip(); |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 185 | |
wdenk | db82c8e | 2004-02-26 23:01:04 +0000 | [diff] [blame] | 186 | #if defined(CONFIG_INCA_IP_SWITCH_AMDIX) |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 187 | inca_amdix(); |
wdenk | db82c8e | 2004-02-26 23:01:04 +0000 | [diff] [blame] | 188 | #endif |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 189 | |
| 190 | sprintf(dev->name, "INCA-IP Switch"); |
| 191 | dev->init = inca_switch_init; |
| 192 | dev->halt = inca_switch_halt; |
| 193 | dev->send = inca_switch_send; |
| 194 | dev->recv = inca_switch_recv; |
| 195 | |
| 196 | eth_register(dev); |
| 197 | |
| 198 | #if 0 |
| 199 | printf("Leaving inca_switch_initialize()\n"); |
| 200 | #endif |
| 201 | |
| 202 | return 1; |
| 203 | } |
| 204 | |
| 205 | |
| 206 | static int inca_switch_init(struct eth_device *dev, bd_t * bis) |
| 207 | { |
| 208 | int i; |
| 209 | u32 v, regValue; |
| 210 | u16 wTmp; |
| 211 | |
| 212 | #if 0 |
| 213 | printf("Entering inca_switch_init()\n"); |
| 214 | #endif |
| 215 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 216 | /* Set MAC address. |
| 217 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 218 | wTmp = (u16)dev->enetaddr[0]; |
| 219 | regValue = (wTmp << 8) | dev->enetaddr[1]; |
| 220 | |
| 221 | SW_WRITE_REG(INCA_IP_Switch_PMAC_SA1, regValue); |
| 222 | |
| 223 | wTmp = (u16)dev->enetaddr[2]; |
| 224 | regValue = (wTmp << 8) | dev->enetaddr[3]; |
| 225 | regValue = regValue << 16; |
| 226 | wTmp = (u16)dev->enetaddr[4]; |
| 227 | regValue |= (wTmp<<8) | dev->enetaddr[5]; |
| 228 | |
| 229 | SW_WRITE_REG(INCA_IP_Switch_PMAC_SA2, regValue); |
| 230 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 231 | /* Initialize the descriptor rings. |
| 232 | */ |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 233 | for (i = 0; i < NUM_RX_DESC; i++) { |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 234 | inca_rx_descriptor_t * rx_desc = (inca_rx_descriptor_t *)CKSEG1ADDR(&rx_ring[i]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 235 | memset(rx_desc, 0, sizeof(rx_ring[i])); |
| 236 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 237 | /* Set maximum size of receive buffer. |
| 238 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 239 | rx_desc->params.field.NFB = PKTSIZE_ALIGN; |
| 240 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 241 | /* Set the offset of the receive buffer. Zero means |
| 242 | * that the offset mechanism is not used. |
| 243 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 244 | rx_desc->params.field.offset = 0; |
| 245 | |
| 246 | /* Check if it is the last descriptor. |
| 247 | */ |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 248 | if (i == (NUM_RX_DESC - 1)) { |
| 249 | /* Let the last descriptor point to the first |
| 250 | * one. |
| 251 | */ |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 252 | rx_desc->nextRxDescPtr = (u32)CKSEG1ADDR(rx_ring); |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 253 | } else { |
| 254 | /* Set the address of the next descriptor. |
| 255 | */ |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 256 | rx_desc->nextRxDescPtr = (u32)CKSEG1ADDR(&rx_ring[i+1]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 259 | rx_desc->RxDataPtr = (u32)CKSEG1ADDR(NetRxPackets[i]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | #if 0 |
| 263 | printf("rx_ring = 0x%08X 0x%08X\n", (u32)rx_ring, (u32)&rx_ring[0]); |
| 264 | printf("tx_ring = 0x%08X 0x%08X\n", (u32)tx_ring, (u32)&tx_ring[0]); |
| 265 | #endif |
| 266 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 267 | for (i = 0; i < NUM_TX_DESC; i++) { |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 268 | inca_tx_descriptor_t * tx_desc = (inca_tx_descriptor_t *)CKSEG1ADDR(&tx_ring[i]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 269 | |
| 270 | memset(tx_desc, 0, sizeof(tx_ring[i])); |
| 271 | |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 272 | tx_desc->params.word = 0; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 273 | tx_desc->params.field.HOLD = 1; |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 274 | tx_desc->C = 1; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 275 | |
| 276 | /* Check if it is the last descriptor. |
| 277 | */ |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 278 | if (i == (NUM_TX_DESC - 1)) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 279 | /* Let the last descriptor point to the |
| 280 | * first one. |
| 281 | */ |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 282 | tx_desc->nextTxDescPtr = (u32)CKSEG1ADDR(tx_ring); |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 283 | } else { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 284 | /* Set the address of the next descriptor. |
| 285 | */ |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 286 | tx_desc->nextTxDescPtr = (u32)CKSEG1ADDR(&tx_ring[i+1]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 290 | /* Initialize RxDMA. |
| 291 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 292 | DMA_READ_REG(INCA_IP_DMA_DMA_RXISR, v); |
| 293 | #if 0 |
| 294 | printf("RX status = 0x%08X\n", v); |
| 295 | #endif |
| 296 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 297 | /* Writing to the FRDA of CHANNEL. |
| 298 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 299 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXFRDA0, (u32)rx_ring); |
| 300 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 301 | /* Writing to the COMMAND REG. |
| 302 | */ |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 303 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0, INCA_IP_DMA_DMA_RXCCR0_INIT); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 304 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 305 | /* Initialize TxDMA. |
| 306 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 307 | DMA_READ_REG(INCA_IP_DMA_DMA_TXISR, v); |
| 308 | #if 0 |
| 309 | printf("TX status = 0x%08X\n", v); |
| 310 | #endif |
| 311 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 312 | /* Writing to the FRDA of CHANNEL. |
| 313 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 314 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXFRDA0, (u32)tx_ring); |
| 315 | |
| 316 | tx_new = rx_new = 0; |
| 317 | |
| 318 | tx_hold = NUM_TX_DESC - 1; |
| 319 | rx_hold = NUM_RX_DESC - 1; |
| 320 | |
| 321 | #if 0 |
| 322 | rx_ring[rx_hold].params.field.HOLD = 1; |
| 323 | #endif |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 324 | /* enable spanning tree forwarding, enable the CPU port */ |
| 325 | /* ST_PT: |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 326 | * CPS (CPU port status) 0x3 (forwarding) |
| 327 | * LPS (LAN port status) 0x3 (forwarding) |
| 328 | * PPS (PC port status) 0x3 (forwarding) |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 329 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 330 | SW_WRITE_REG(INCA_IP_Switch_ST_PT,0x3f); |
| 331 | |
| 332 | #if 0 |
| 333 | printf("Leaving inca_switch_init()\n"); |
| 334 | #endif |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 340 | static int inca_switch_send(struct eth_device *dev, volatile void *packet, int length) |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 341 | { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 342 | int i; |
| 343 | int res = -1; |
| 344 | u32 command; |
| 345 | u32 regValue; |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 346 | inca_tx_descriptor_t * tx_desc = (inca_tx_descriptor_t *)CKSEG1ADDR(&tx_ring[tx_new]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 347 | |
| 348 | #if 0 |
| 349 | printf("Entered inca_switch_send()\n"); |
| 350 | #endif |
| 351 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 352 | if (length <= 0) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 353 | printf ("%s: bad packet size: %d\n", dev->name, length); |
| 354 | goto Done; |
| 355 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 356 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 357 | for(i = 0; tx_desc->C == 0; i++) { |
| 358 | if (i >= TOUT_LOOP) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 359 | printf("%s: tx error buffer not ready\n", dev->name); |
| 360 | goto Done; |
| 361 | } |
| 362 | } |
| 363 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 364 | if (tx_old_hold >= 0) { |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 365 | ((inca_tx_descriptor_t *)CKSEG1ADDR(&tx_ring[tx_old_hold]))->params.field.HOLD = 1; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 366 | } |
| 367 | tx_old_hold = tx_hold; |
| 368 | |
| 369 | tx_desc->params.word = |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 370 | (INCA_DMA_TX_SOP | INCA_DMA_TX_EOP | INCA_DMA_TX_HOLD); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 371 | |
| 372 | tx_desc->C = 0; |
| 373 | tx_desc->TxDataPtr = (u32)packet; |
| 374 | tx_desc->params.field.NBA = length; |
| 375 | |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 376 | ((inca_tx_descriptor_t *)CKSEG1ADDR(&tx_ring[tx_hold]))->params.field.HOLD = 0; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 377 | |
| 378 | tx_hold = tx_new; |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 379 | tx_new = (tx_new + 1) % NUM_TX_DESC; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 380 | |
| 381 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 382 | if (! initialized) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 383 | command = INCA_IP_DMA_DMA_TXCCR0_INIT; |
| 384 | initialized = 1; |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 385 | } else { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 386 | command = INCA_IP_DMA_DMA_TXCCR0_HR; |
| 387 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 388 | |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 389 | DMA_READ_REG(INCA_IP_DMA_DMA_TXCCR0, regValue); |
| 390 | regValue |= command; |
| 391 | #if 0 |
| 392 | printf("regValue = 0x%x\n", regValue); |
| 393 | #endif |
| 394 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, regValue); |
| 395 | |
| 396 | #if 1 |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 397 | for(i = 0; ((inca_tx_descriptor_t *)CKSEG1ADDR(&tx_ring[tx_hold]))->C == 0; i++) { |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 398 | if (i >= TOUT_LOOP) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 399 | printf("%s: tx buffer not ready\n", dev->name); |
| 400 | goto Done; |
| 401 | } |
| 402 | } |
| 403 | #endif |
| 404 | res = length; |
| 405 | Done: |
| 406 | #if 0 |
| 407 | printf("Leaving inca_switch_send()\n"); |
| 408 | #endif |
| 409 | return res; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static int inca_switch_recv(struct eth_device *dev) |
| 414 | { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 415 | int length = 0; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 416 | inca_rx_descriptor_t * rx_desc; |
| 417 | |
| 418 | #if 0 |
| 419 | printf("Entered inca_switch_recv()\n"); |
| 420 | #endif |
| 421 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 422 | for (;;) { |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 423 | rx_desc = (inca_rx_descriptor_t *)CKSEG1ADDR(&rx_ring[rx_new]); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 424 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 425 | if (rx_desc->status.field.C == 0) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | |
| 429 | #if 0 |
| 430 | rx_ring[rx_new].params.field.HOLD = 1; |
| 431 | #endif |
| 432 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 433 | if (! rx_desc->status.field.Eop) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 434 | printf("Partly received packet!!!\n"); |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | length = rx_desc->status.field.NBT; |
| 439 | rx_desc->status.word &= |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 440 | ~(INCA_DMA_RX_EOP | INCA_DMA_RX_SOP | INCA_DMA_RX_C); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 441 | #if 0 |
| 442 | { |
| 443 | int i; |
| 444 | for (i=0;i<length - 4;i++) { |
| 445 | if (i % 16 == 0) printf("\n%04x: ", i); |
| 446 | printf("%02X ", NetRxPackets[rx_new][i]); |
| 447 | } |
| 448 | printf("\n"); |
| 449 | } |
| 450 | #endif |
| 451 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 452 | if (length) { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 453 | #if 0 |
| 454 | printf("Received %d bytes\n", length); |
| 455 | #endif |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 456 | NetReceive((void*)CKSEG1ADDR(NetRxPackets[rx_new]), length - 4); |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 457 | } else { |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 458 | #if 1 |
| 459 | printf("Zero length!!!\n"); |
| 460 | #endif |
| 461 | } |
| 462 | |
| 463 | |
Shinya Kuribayashi | 6c6b261 | 2008-06-05 22:29:00 +0900 | [diff] [blame] | 464 | ((inca_rx_descriptor_t *)CKSEG1ADDR(&rx_ring[rx_hold]))->params.field.HOLD = 0; |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 465 | |
| 466 | rx_hold = rx_new; |
| 467 | |
| 468 | rx_new = (rx_new + 1) % NUM_RX_DESC; |
| 469 | } |
| 470 | |
| 471 | #if 0 |
| 472 | printf("Leaving inca_switch_recv()\n"); |
| 473 | #endif |
| 474 | |
| 475 | return length; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | static void inca_switch_halt(struct eth_device *dev) |
| 480 | { |
| 481 | #if 0 |
| 482 | printf("Entered inca_switch_halt()\n"); |
| 483 | #endif |
| 484 | |
| 485 | #if 1 |
| 486 | initialized = 0; |
| 487 | #endif |
| 488 | #if 1 |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 489 | /* Disable forwarding to the CPU port. |
| 490 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 491 | SW_WRITE_REG(INCA_IP_Switch_ST_PT,0xf); |
| 492 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 493 | /* Close RxDMA channel. |
| 494 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 495 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF); |
| 496 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 497 | /* Close TxDMA channel. |
| 498 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 499 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, INCA_IP_DMA_DMA_TXCCR0_OFF); |
| 500 | |
| 501 | |
| 502 | #endif |
| 503 | #if 0 |
| 504 | printf("Leaving inca_switch_halt()\n"); |
| 505 | #endif |
| 506 | } |
| 507 | |
| 508 | |
| 509 | static void inca_init_switch_chip(void) |
| 510 | { |
| 511 | u32 regValue; |
| 512 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 513 | /* To workaround a problem with collision counter |
| 514 | * (see Errata sheet). |
| 515 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 516 | SW_WRITE_REG(INCA_IP_Switch_PC_TX_CTL, 0x00000001); |
| 517 | SW_WRITE_REG(INCA_IP_Switch_LAN_TX_CTL, 0x00000001); |
| 518 | |
| 519 | #if 1 |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 520 | /* init MDIO configuration: |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 521 | * MDS (Poll speed): 0x01 (4ms) |
| 522 | * PHY_LAN_ADDR: 0x06 |
| 523 | * PHY_PC_ADDR: 0x05 |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 524 | * UEP (Use External PHY): 0x00 (Internal PHY is used) |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 525 | * PS (Port Select): 0x00 (PT/UMM for LAN) |
| 526 | * PT (PHY Test): 0x00 (no test mode) |
| 527 | * UMM (Use MDIO Mode): 0x00 (state machine is disabled) |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 528 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 529 | SW_WRITE_REG(INCA_IP_Switch_MDIO_CFG, 0x4c50); |
| 530 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 531 | /* init PHY: |
| 532 | * SL (Auto Neg. Speed for LAN) |
| 533 | * SP (Auto Neg. Speed for PC) |
| 534 | * LL (Link Status for LAN) |
| 535 | * LP (Link Status for PC) |
| 536 | * DL (Duplex Status for LAN) |
| 537 | * DP (Duplex Status for PC) |
| 538 | * PL (Auto Neg. Pause Status for LAN) |
| 539 | * PP (Auto Neg. Pause Status for PC) |
| 540 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 541 | SW_WRITE_REG (INCA_IP_Switch_EPHY, 0xff); |
| 542 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 543 | /* MDIO_ACC: |
| 544 | * RA (Request/Ack) 0x01 (Request) |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 545 | * RW (Read/Write) 0x01 (Write) |
| 546 | * PHY_ADDR 0x05 (PC) |
| 547 | * REG_ADDR 0x00 (PHY_BCR: basic control register) |
| 548 | * PHY_DATA 0x8000 |
| 549 | * Reset - software reset |
| 550 | * LB (loop back) - normal |
| 551 | * SS (speed select) - 10 Mbit/s |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 552 | * ANE (auto neg. enable) - enable |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 553 | * PD (power down) - normal |
| 554 | * ISO (isolate) - normal |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 555 | * RAN (restart auto neg.) - normal |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 556 | * DM (duplex mode) - half duplex |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 557 | * CT (collision test) - enable |
| 558 | */ |
| 559 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, 0xc0a09000); |
| 560 | |
| 561 | /* MDIO_ACC: |
| 562 | * RA (Request/Ack) 0x01 (Request) |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 563 | * RW (Read/Write) 0x01 (Write) |
| 564 | * PHY_ADDR 0x06 (LAN) |
| 565 | * REG_ADDR 0x00 (PHY_BCR: basic control register) |
| 566 | * PHY_DATA 0x8000 |
| 567 | * Reset - software reset |
| 568 | * LB (loop back) - normal |
| 569 | * SS (speed select) - 10 Mbit/s |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 570 | * ANE (auto neg. enable) - enable |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 571 | * PD (power down) - normal |
| 572 | * ISO (isolate) - normal |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 573 | * RAN (restart auto neg.) - normal |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 574 | * DM (duplex mode) - half duplex |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 575 | * CT (collision test) - enable |
| 576 | */ |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 577 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, 0xc0c09000); |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 578 | |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 579 | #endif |
| 580 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 581 | /* Make sure the CPU port is disabled for now. We |
| 582 | * don't want packets to get stacked for us until |
| 583 | * we enable DMA and are prepared to receive them. |
| 584 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 585 | SW_WRITE_REG(INCA_IP_Switch_ST_PT,0xf); |
| 586 | |
| 587 | SW_READ_REG(INCA_IP_Switch_ARL_CTL, regValue); |
| 588 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 589 | /* CRC GEN is enabled. |
| 590 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 591 | regValue |= 0x00000200; |
| 592 | SW_WRITE_REG(INCA_IP_Switch_ARL_CTL, regValue); |
| 593 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 594 | /* ADD TAG is disabled. |
| 595 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 596 | SW_READ_REG(INCA_IP_Switch_PMAC_HD_CTL, regValue); |
| 597 | regValue &= ~0x00000002; |
| 598 | SW_WRITE_REG(INCA_IP_Switch_PMAC_HD_CTL, regValue); |
| 599 | } |
| 600 | |
| 601 | |
| 602 | static void inca_dma_init(void) |
| 603 | { |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 604 | /* Switch off all DMA channels. |
| 605 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 606 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF); |
| 607 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXCCR1, INCA_IP_DMA_DMA_RXCCR1_OFF); |
| 608 | |
| 609 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR0, INCA_IP_DMA_DMA_RXCCR0_OFF); |
| 610 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR1, INCA_IP_DMA_DMA_TXCCR1_OFF); |
| 611 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXCCR2, INCA_IP_DMA_DMA_TXCCR2_OFF); |
| 612 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 613 | /* Setup TX channel polling time. |
| 614 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 615 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXPOLL, INCA_DMA_TX_POLLING_TIME); |
| 616 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 617 | /* Setup RX channel polling time. |
| 618 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 619 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXPOLL, INCA_DMA_RX_POLLING_TIME); |
| 620 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 621 | /* ERRATA: write reset value into the DMA RX IMR register. |
| 622 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 623 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXIMR, 0xFFFFFFFF); |
| 624 | |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 625 | /* Just in case: disable all transmit interrupts also. |
| 626 | */ |
wdenk | 1adff3d | 2003-03-26 11:42:53 +0000 | [diff] [blame] | 627 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXIMR, 0xFFFFFFFF); |
| 628 | |
| 629 | DMA_WRITE_REG(INCA_IP_DMA_DMA_TXISR, 0xFFFFFFFF); |
| 630 | DMA_WRITE_REG(INCA_IP_DMA_DMA_RXISR, 0xFFFFFFFF); |
| 631 | } |
| 632 | |
wdenk | db82c8e | 2004-02-26 23:01:04 +0000 | [diff] [blame] | 633 | #if defined(CONFIG_INCA_IP_SWITCH_AMDIX) |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 634 | static int inca_amdix(void) |
| 635 | { |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 636 | u32 phyReg1 = 0; |
| 637 | u32 phyReg4 = 0; |
| 638 | u32 phyReg5 = 0; |
| 639 | u32 phyReg6 = 0; |
| 640 | u32 phyReg31 = 0; |
| 641 | u32 regEphy = 0; |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 642 | int mdi_flag; |
| 643 | int retries; |
| 644 | |
| 645 | /* Setup GPIO pins. |
| 646 | */ |
| 647 | *INCA_IP_AUTO_MDIX_LAN_PORTS_DIR |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX); |
| 648 | *INCA_IP_AUTO_MDIX_LAN_PORTS_ALTSEL |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX); |
| 649 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 650 | #if 0 |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 651 | /* Wait for signal. |
| 652 | */ |
| 653 | retries = WAIT_SIGNAL_RETRIES; |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 654 | while (--retries) { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 655 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 656 | (0x1 << 31) | /* RA */ |
| 657 | (0x0 << 30) | /* Read */ |
| 658 | (0x6 << 21) | /* LAN */ |
| 659 | (17 << 16)); /* PHY_MCSR */ |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 660 | do { |
| 661 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg1); |
| 662 | } while (phyReg1 & (1 << 31)); |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 663 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 664 | if (phyReg1 & (1 << 1)) { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 665 | /* Signal detected */ |
| 666 | break; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if (!retries) |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 671 | goto Fail; |
| 672 | #endif |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 673 | |
| 674 | /* Set MDI mode. |
| 675 | */ |
| 676 | *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT &= ~(1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX); |
| 677 | mdi_flag = 1; |
| 678 | |
| 679 | /* Wait for link. |
| 680 | */ |
| 681 | retries = WAIT_LINK_RETRIES; |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 682 | while (--retries) { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 683 | udelay(LINK_RETRY_DELAY * 1000); |
| 684 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 685 | (0x1 << 31) | /* RA */ |
| 686 | (0x0 << 30) | /* Read */ |
| 687 | (0x6 << 21) | /* LAN */ |
| 688 | (1 << 16)); /* PHY_BSR */ |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 689 | do { |
| 690 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg1); |
| 691 | } while (phyReg1 & (1 << 31)); |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 692 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 693 | if (phyReg1 & (1 << 2)) { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 694 | /* Link is up */ |
| 695 | break; |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 696 | } else if (mdi_flag) { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 697 | /* Set MDIX mode */ |
| 698 | *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT |= (1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX); |
| 699 | mdi_flag = 0; |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 700 | } else { |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 701 | /* Set MDI mode */ |
| 702 | *INCA_IP_AUTO_MDIX_LAN_PORTS_OUT &= ~(1 << INCA_IP_AUTO_MDIX_LAN_GPIO_PIN_RXTX); |
| 703 | mdi_flag = 1; |
| 704 | } |
| 705 | } |
| 706 | |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 707 | if (!retries) { |
| 708 | goto Fail; |
| 709 | } else { |
| 710 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 711 | (0x1 << 31) | /* RA */ |
| 712 | (0x0 << 30) | /* Read */ |
| 713 | (0x6 << 21) | /* LAN */ |
| 714 | (1 << 16)); /* PHY_BSR */ |
| 715 | do { |
| 716 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg1); |
| 717 | } while (phyReg1 & (1 << 31)); |
| 718 | |
| 719 | /* Auto-negotiation / Parallel detection complete |
| 720 | */ |
| 721 | if (phyReg1 & (1 << 5)) { |
| 722 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 723 | (0x1 << 31) | /* RA */ |
| 724 | (0x0 << 30) | /* Read */ |
| 725 | (0x6 << 21) | /* LAN */ |
| 726 | (31 << 16)); /* PHY_SCSR */ |
| 727 | do { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 728 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg31); |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 729 | } while (phyReg31 & (1 << 31)); |
| 730 | |
| 731 | switch ((phyReg31 >> 2) & 0x7) { |
| 732 | case INCA_SWITCH_PHY_SPEED_10H: |
| 733 | /* 10Base-T Half-duplex */ |
| 734 | regEphy = 0; |
| 735 | break; |
| 736 | case INCA_SWITCH_PHY_SPEED_10F: |
| 737 | /* 10Base-T Full-duplex */ |
| 738 | regEphy = INCA_IP_Switch_EPHY_DL; |
| 739 | break; |
| 740 | case INCA_SWITCH_PHY_SPEED_100H: |
| 741 | /* 100Base-TX Half-duplex */ |
| 742 | regEphy = INCA_IP_Switch_EPHY_SL; |
| 743 | break; |
| 744 | case INCA_SWITCH_PHY_SPEED_100F: |
| 745 | /* 100Base-TX Full-duplex */ |
| 746 | regEphy = INCA_IP_Switch_EPHY_SL | INCA_IP_Switch_EPHY_DL; |
| 747 | break; |
| 748 | } |
| 749 | |
| 750 | /* In case of Auto-negotiation, |
| 751 | * update the negotiated PAUSE support status |
| 752 | */ |
| 753 | if (phyReg1 & (1 << 3)) { |
| 754 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 755 | (0x1 << 31) | /* RA */ |
| 756 | (0x0 << 30) | /* Read */ |
| 757 | (0x6 << 21) | /* LAN */ |
| 758 | (6 << 16)); /* PHY_ANER */ |
| 759 | do { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 760 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg6); |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 761 | } while (phyReg6 & (1 << 31)); |
| 762 | |
| 763 | /* We are Autoneg-able. |
| 764 | * Is Link partner also able to autoneg? |
| 765 | */ |
| 766 | if (phyReg6 & (1 << 0)) { |
| 767 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 768 | (0x1 << 31) | /* RA */ |
| 769 | (0x0 << 30) | /* Read */ |
| 770 | (0x6 << 21) | /* LAN */ |
| 771 | (4 << 16)); /* PHY_ANAR */ |
| 772 | do { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 773 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg4); |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 774 | } while (phyReg4 & (1 << 31)); |
| 775 | |
| 776 | /* We advertise PAUSE capab. |
| 777 | * Does link partner also advertise it? |
| 778 | */ |
| 779 | if (phyReg4 & (1 << 10)) { |
| 780 | SW_WRITE_REG(INCA_IP_Switch_MDIO_ACC, |
| 781 | (0x1 << 31) | /* RA */ |
| 782 | (0x0 << 30) | /* Read */ |
| 783 | (0x6 << 21) | /* LAN */ |
| 784 | (5 << 16)); /* PHY_ANLPAR */ |
| 785 | do { |
wdenk | 0a12b75 | 2004-03-11 22:46:36 +0000 | [diff] [blame] | 786 | SW_READ_REG(INCA_IP_Switch_MDIO_ACC, phyReg5); |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 787 | } while (phyReg5 & (1 << 31)); |
| 788 | |
| 789 | /* Link partner is PAUSE capab. |
| 790 | */ |
| 791 | if (phyReg5 & (1 << 10)) { |
| 792 | regEphy |= INCA_IP_Switch_EPHY_PL; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | } |
| 798 | |
| 799 | /* Link is up */ |
| 800 | regEphy |= INCA_IP_Switch_EPHY_LL; |
| 801 | |
| 802 | SW_WRITE_REG(INCA_IP_Switch_EPHY, regEphy); |
| 803 | } |
| 804 | } |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 805 | |
| 806 | return 0; |
wdenk | 0e2874cb | 2004-03-02 14:05:39 +0000 | [diff] [blame] | 807 | |
| 808 | Fail: |
| 809 | printf("No Link on LAN port\n"); |
| 810 | return -1; |
wdenk | 4dd56e5 | 2004-02-20 22:02:48 +0000 | [diff] [blame] | 811 | } |
wdenk | db82c8e | 2004-02-26 23:01:04 +0000 | [diff] [blame] | 812 | #endif /* CONFIG_INCA_IP_SWITCH_AMDIX */ |