inca-ip_sw.c 19 KB

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