inca-ip_sw.c 19 KB

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