inca-ip_sw.c 19 KB

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