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