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