inca-ip_sw.c 19 KB

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