eth.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. /**************************************************************************
  2. Etherboot - BOOTP/TFTP Bootstrap Program
  3. Skeleton NIC driver for Etherboot
  4. ***************************************************************************/
  5. /*
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2, or (at
  9. * your option) any later version.
  10. */
  11. /*
  12. * This file is a modified version from the Galileo polled mode
  13. * network driver for the ethernet contained within the GT64260
  14. * chip. It has been modified to fit into the U-Boot framework, from
  15. * the original (etherboot) setup. Also, additional cleanup and features
  16. * were added.
  17. *
  18. * - Josh Huber <huber@mclx.com>
  19. */
  20. #include <common.h>
  21. #include <malloc.h>
  22. #include <galileo/gt64260R.h>
  23. #include <galileo/core.h>
  24. #include <asm/cache.h>
  25. #include <miiphy.h>
  26. #include <net.h>
  27. #include "eth.h"
  28. #include "eth_addrtbl.h"
  29. #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)
  30. #define GT6426x_ETH_BUF_SIZE 1536
  31. /* if you like verbose output, turn this on! */
  32. #undef DEBUG
  33. /* Restart autoneg if we detect link is up on phy init. */
  34. /*
  35. * The GT doc's say that after Rst is deasserted, and the PHY
  36. * reports autoneg complete, it runs through its autoneg
  37. * procedures. This doesn't seem to be the case for MII
  38. * PHY's. To work around this check for link up && autoneg
  39. * complete when initilizing the port. If they are both set,
  40. * then restart PHY autoneg. Of course, it may be something
  41. * completly different.
  42. */
  43. #ifdef CONFIG_ETHER_PORT_MII
  44. # define RESTART_AUTONEG
  45. #endif
  46. /* do this if you dont want to use snooping */
  47. #define USE_SOFTWARE_CACHE_MANAGEMENT
  48. #ifdef USE_SOFTWARE_CACHE_MANAGEMENT
  49. #define FLUSH_DCACHE(a,b) if(dcache_status()){clean_dcache_range((u32)(a),(u32)(b));}
  50. #define FLUSH_AND_INVALIDATE_DCACHE(a,b) if(dcache_status()){flush_dcache_range((u32)(a),(u32)(b));}
  51. #define INVALIDATE_DCACHE(a,b) if(dcache_status()){invalidate_dcache_range((u32)(a),(u32)(b));}
  52. #else
  53. /* bummer - w/o flush, nothing works, even with snooping - FIXME */
  54. /* #define FLUSH_DCACHE(a,b) */
  55. #define FLUSH_DCACHE(a,b) if(dcache_status()){clean_dcache_range((u32)(a),(u32)(b));}
  56. #define FLUSH_AND_INVALIDATE_DCACHE(a,b)
  57. #define INVALIDATE_DCACHE(a,b)
  58. #endif
  59. struct eth_dev_s {
  60. eth0_tx_desc_single *eth_tx_desc;
  61. eth0_rx_desc_single *eth_rx_desc;
  62. char *eth_tx_buffer;
  63. char *eth_rx_buffer[NR];
  64. int tdn, rdn;
  65. int dev;
  66. unsigned int reg_base;
  67. };
  68. #ifdef CONFIG_INTEL_LXT97X
  69. /* for intel LXT972 */
  70. static const char ether_port_phy_addr[3]={0,1,2};
  71. #else
  72. static const char ether_port_phy_addr[3]={4,5,6};
  73. #endif
  74. static inline unsigned short
  75. miiphy_read_ret(unsigned short phy, unsigned short reg)
  76. {
  77. unsigned short val;
  78. miiphy_read(phy,reg,&val);
  79. return val;
  80. }
  81. /**************************************************************************
  82. RESET - Reset adapter
  83. ***************************************************************************/
  84. void
  85. gt6426x_eth_reset(void *v)
  86. {
  87. /* we should do something here...
  88. struct eth_device *wp = (struct eth_device *)v;
  89. struct eth_dev_s *p = wp->priv;
  90. */
  91. printf ("RESET\n");
  92. /* put the card in its initial state */
  93. }
  94. static void gt6426x_handle_SMI(struct eth_dev_s *p, unsigned int icr)
  95. {
  96. #ifdef DEBUG
  97. printf("SMI interrupt: ");
  98. if(icr&0x20000000) {
  99. printf("SMI done\n");
  100. }
  101. #endif
  102. if(icr&0x10000000) {
  103. unsigned int psr;
  104. psr=GTREGREAD(ETHERNET0_PORT_STATUS_REGISTER + p->reg_base);
  105. #ifdef DEBUG
  106. printf("PHY state change:\n"
  107. " GT:%s:%s:%s:%s\n",
  108. psr&1?"100":" 10",
  109. psr&8?" Link":"nLink",
  110. psr&2?"FD":"HD",
  111. psr&4?" FC":"nFC");
  112. #ifdef CONFIG_INTEL_LXT97X /* non-standard mii reg (intel lxt972a) */
  113. {
  114. unsigned short mii_11;
  115. mii_11=miiphy_read_ret(ether_port_phy_addr[p->dev],0x11);
  116. printf(" mii:%s:%s:%s:%s %s:%s %s\n",
  117. mii_11&(1<<14)?"100":" 10",
  118. mii_11&(1<<10)?" Link":"nLink",
  119. mii_11&(1<<9)?"FD":"HD",
  120. mii_11&(1<<4)?" FC":"nFC",
  121. mii_11&(1<<7)?"ANc":"ANnc",
  122. mii_11&(1<<8)?"AN":"Manual",
  123. ""
  124. );
  125. }
  126. #endif /* CONFIG_INTEL_LXT97X */
  127. #endif /* DEBUG */
  128. }
  129. }
  130. static int
  131. gt6426x_eth_receive(struct eth_dev_s *p,unsigned int icr)
  132. {
  133. int eth_len=0;
  134. char *eth_data;
  135. eth0_rx_desc_single *rx=&p->eth_rx_desc[(p->rdn)];
  136. INVALIDATE_DCACHE((unsigned int)rx,(unsigned int)(rx+1));
  137. if (rx->command_status & 0x80000000) {
  138. return 0; /* No packet received */
  139. }
  140. eth_len = (unsigned int)
  141. (rx->buff_size_byte_count) & 0x0000ffff;
  142. eth_data = (char *) p->eth_rx_buffer[p->rdn];
  143. #ifdef DEBUG
  144. if (eth_len) {
  145. printf ("%s: Recived %d byte Packet @ 0x%p\n",
  146. __FUNCTION__, eth_len, eth_data);
  147. }
  148. #endif
  149. /*
  150. * packet is now in:
  151. * eth0_rx_buffer[RDN_ETH0];
  152. */
  153. /* let the upper layer handle the packet */
  154. NetReceive (eth_data, eth_len);
  155. rx->buff_size_byte_count = GT6426x_ETH_BUF_SIZE<<16;
  156. /* GT96100 Owner */
  157. rx->command_status = 0x80000000;
  158. FLUSH_DCACHE((unsigned int)rx,(unsigned int)(rx+1));
  159. p->rdn ++;
  160. if (p->rdn == NR) {p->rdn = 0;}
  161. sync();
  162. /* Start Rx*/
  163. GT_REG_WRITE (ETHERNET0_SDMA_COMMAND_REGISTER + p->reg_base, 0x00000080);
  164. #ifdef DEBUG
  165. {
  166. int i;
  167. for (i=0;i<12;i++) {
  168. printf(" %02x", eth_data[i]);
  169. }
  170. }
  171. printf(": %d bytes\n", eth_len);
  172. #endif
  173. INVALIDATE_DCACHE((unsigned int)eth_data,
  174. (unsigned int)eth_data+eth_len);
  175. return eth_len;
  176. }
  177. /**************************************************************************
  178. POLL - look for an rx frame, handle other conditions
  179. ***************************************************************************/
  180. int
  181. gt6426x_eth_poll(void *v)
  182. {
  183. struct eth_device *wp = (struct eth_device *)v;
  184. struct eth_dev_s *p = wp->priv;
  185. unsigned int icr=GTREGREAD(ETHERNET0_INTERRUPT_CAUSE_REGISTER + p->reg_base);
  186. if(icr) {
  187. GT_REG_WRITE(ETHERNET0_INTERRUPT_CAUSE_REGISTER +p->reg_base, 0);
  188. #ifdef DEBUG
  189. printf("poll got ICR %08x\n", icr);
  190. #endif
  191. /* SMI done or PHY state change*/
  192. if(icr&0x30000000) gt6426x_handle_SMI(p, icr);
  193. }
  194. /* always process. We aren't using RX interrupts */
  195. return gt6426x_eth_receive(p, icr);
  196. }
  197. /**************************************************************************
  198. TRANSMIT - Transmit a frame
  199. ***************************************************************************/
  200. int
  201. gt6426x_eth_transmit(void *v, volatile char *p, unsigned int s)
  202. {
  203. struct eth_device *wp = (struct eth_device *)v;
  204. struct eth_dev_s *dev = (struct eth_dev_s *)wp->priv;
  205. #ifdef DEBUG
  206. unsigned int old_command_stat,old_psr;
  207. #endif
  208. eth0_tx_desc_single *tx=&dev->eth_tx_desc[dev->tdn];
  209. /* wait for tx to be ready */
  210. INVALIDATE_DCACHE((unsigned int)tx,(unsigned int)(tx+1));
  211. while (tx->command_status & 0x80000000) {
  212. int i;
  213. for(i=0;i<1000;i++);
  214. INVALIDATE_DCACHE((unsigned int)tx,(unsigned int)(tx+1));
  215. }
  216. GT_REG_WRITE (ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER0 + dev->reg_base,
  217. (unsigned int)tx);
  218. #ifdef DEBUG
  219. printf("copying to tx_buffer [%p], length %x, desc = %p\n",
  220. dev->eth_tx_buffer, s, dev->eth_tx_desc);
  221. #endif
  222. memcpy(dev->eth_tx_buffer, (char *) p, s);
  223. tx->buff_pointer = dev->eth_tx_buffer;
  224. tx->bytecount_reserved = ((__u16)s) << 16;
  225. /* 31 - own
  226. * 22 - gencrc
  227. * 18:16 - pad, last, first */
  228. tx->command_status = (1<<31) | (1<<22) | (7<<16);
  229. #if 0
  230. /* FEr #18 */
  231. tx->next_desc = NULL;
  232. #else
  233. tx->next_desc =
  234. (struct eth0_tx_desc_struct *)
  235. &dev->eth_tx_desc[(dev->tdn+1)%NT].bytecount_reserved;
  236. /* cpu owned */
  237. dev->eth_tx_desc[(dev->tdn+1)%NT].command_status = (7<<16); /* pad, last, first */
  238. #endif
  239. #ifdef DEBUG
  240. old_command_stat=tx->command_status,
  241. old_psr=GTREGREAD(ETHERNET0_PORT_STATUS_REGISTER + dev->reg_base);
  242. #endif
  243. FLUSH_DCACHE((unsigned int)tx,
  244. (unsigned int)&dev->eth_tx_desc[(dev->tdn+2)%NT]);
  245. FLUSH_DCACHE((unsigned int)dev->eth_tx_buffer,(unsigned int)dev->eth_tx_buffer+s);
  246. GT_REG_WRITE(ETHERNET0_SDMA_COMMAND_REGISTER + dev->reg_base, 0x01000000);
  247. #ifdef DEBUG
  248. {
  249. unsigned int command_stat=0;
  250. printf("cmd_stat: %08x PSR: %08x\n", old_command_stat, old_psr);
  251. /* wait for tx to be ready */
  252. do {
  253. unsigned int psr=GTREGREAD(ETHERNET0_PORT_STATUS_REGISTER + dev->reg_base);
  254. command_stat=tx->command_status;
  255. if(command_stat!=old_command_stat || psr !=old_psr) {
  256. printf("cmd_stat: %08x PSR: %08x\n", command_stat, psr);
  257. old_command_stat = command_stat;
  258. old_psr = psr;
  259. }
  260. /* gt6426x_eth0_poll(); */
  261. } while (command_stat & 0x80000000);
  262. printf("sent %d byte frame\n", s);
  263. if((command_stat & (3<<15)) == 3) {
  264. printf("frame had error (stat=%08x)\n", command_stat);
  265. }
  266. }
  267. #endif
  268. return 0;
  269. }
  270. /**************************************************************************
  271. DISABLE - Turn off ethernet interface
  272. ***************************************************************************/
  273. void
  274. gt6426x_eth_disable(void *v)
  275. {
  276. struct eth_device *wp = (struct eth_device *)v;
  277. struct eth_dev_s *p = (struct eth_dev_s *)wp->priv;
  278. GT_REG_WRITE(ETHERNET0_SDMA_COMMAND_REGISTER + p->reg_base, 0x80008000);
  279. }
  280. /**************************************************************************
  281. MII utilities - write: write to an MII register via SMI
  282. ***************************************************************************/
  283. int
  284. miiphy_write(unsigned char phy, unsigned char reg,
  285. unsigned short data)
  286. {
  287. unsigned int temp= (reg<<21) | (phy<<16) | data;
  288. while(GTREGREAD(ETHERNET_SMI_REGISTER) & (1<<28)); /* wait for !Busy */
  289. GT_REG_WRITE(ETHERNET_SMI_REGISTER, temp);
  290. return 0;
  291. }
  292. /**************************************************************************
  293. MII utilities - read: read from an MII register via SMI
  294. ***************************************************************************/
  295. int
  296. miiphy_read(unsigned char phy, unsigned char reg,
  297. unsigned short *val)
  298. {
  299. unsigned int temp= (reg<<21) | (phy<<16) | 1<<26;
  300. while(GTREGREAD(ETHERNET_SMI_REGISTER) & (1<<28)); /* wait for !Busy */
  301. GT_REG_WRITE(ETHERNET_SMI_REGISTER, temp);
  302. while(1) {
  303. temp=GTREGREAD(ETHERNET_SMI_REGISTER);
  304. if(temp & (1<<27)) break; /* wait for ReadValid */
  305. }
  306. *val = temp & 0xffff;
  307. return 0;
  308. }
  309. #ifdef DEBUG
  310. /**************************************************************************
  311. MII utilities - dump mii registers
  312. ***************************************************************************/
  313. static void
  314. gt6426x_dump_mii(bd_t *bis, unsigned short phy)
  315. {
  316. printf("mii reg 0 - 3: %04x %04x %04x %04x\n",
  317. miiphy_read_ret(phy, 0x0),
  318. miiphy_read_ret(phy, 0x1),
  319. miiphy_read_ret(phy, 0x2),
  320. miiphy_read_ret(phy, 0x3)
  321. );
  322. printf(" 4 - 7: %04x %04x %04x %04x\n",
  323. miiphy_read_ret(phy, 0x4),
  324. miiphy_read_ret(phy, 0x5),
  325. miiphy_read_ret(phy, 0x6),
  326. miiphy_read_ret(phy, 0x7)
  327. );
  328. printf(" 8: %04x\n",
  329. miiphy_read_ret(phy, 0x8)
  330. );
  331. printf(" 16-19: %04x %04x %04x %04x\n",
  332. miiphy_read_ret(phy, 0x10),
  333. miiphy_read_ret(phy, 0x11),
  334. miiphy_read_ret(phy, 0x12),
  335. miiphy_read_ret(phy, 0x13)
  336. );
  337. printf(" 20,30: %04x %04x\n",
  338. miiphy_read_ret(phy, 20),
  339. miiphy_read_ret(phy, 30)
  340. );
  341. }
  342. #endif
  343. #ifdef RESTART_AUTONEG
  344. /* If link is up && autoneg compleate, and if
  345. * GT and PHY disagree about link capabilitys,
  346. * restart autoneg - something screwy with FD/HD
  347. * unless we do this. */
  348. static void
  349. check_phy_state(struct eth_dev_s *p)
  350. {
  351. int bmsr = miiphy_read_ret(ether_port_phy_addr[p->dev], PHY_BMSR);
  352. int psr = GTREGREAD(ETHERNET0_PORT_STATUS_REGISTER + p->reg_base);
  353. if ((psr & 1<<3) && (bmsr & PHY_BMSR_LS)) {
  354. int nego = miiphy_read_ret(ether_port_phy_addr[p->dev], PHY_ANAR) &
  355. miiphy_read_ret(ether_port_phy_addr[p->dev], PHY_ANLPAR);
  356. int want;
  357. if (nego & PHY_ANLPAR_TXFD) {
  358. want = 0x3;
  359. printf("MII: 100Base-TX, Full Duplex\n");
  360. } else if (nego & PHY_ANLPAR_TX) {
  361. want = 0x1;
  362. printf("MII: 100Base-TX, Half Duplex\n");
  363. } else if (nego & PHY_ANLPAR_10FD) {
  364. want = 0x2;
  365. printf("MII: 10Base-T, Full Duplex\n");
  366. } else if (nego & PHY_ANLPAR_10) {
  367. want = 0x0;
  368. printf("MII: 10Base-T, Half Duplex\n");
  369. } else {
  370. printf("MII: Unknown link-foo! %x\n", nego);
  371. return;
  372. }
  373. if ((psr & 0x3) != want) {
  374. printf("MII: GT thinks %x, PHY thinks %x, restarting autoneg..\n",
  375. psr & 0x3, want);
  376. miiphy_write(ether_port_phy_addr[p->dev],0,
  377. miiphy_read_ret(ether_port_phy_addr[p->dev],0) | (1<<9));
  378. udelay(10000); /* the EVB's GT takes a while to notice phy
  379. went down and up */
  380. }
  381. }
  382. }
  383. #endif
  384. /**************************************************************************
  385. PROBE - Look for an adapter, this routine's visible to the outside
  386. ***************************************************************************/
  387. int
  388. gt6426x_eth_probe(void *v, bd_t *bis)
  389. {
  390. struct eth_device *wp = (struct eth_device *)v;
  391. struct eth_dev_s *p = (struct eth_dev_s *)wp->priv;
  392. int dev = p->dev;
  393. unsigned int reg_base = p->reg_base;
  394. unsigned long temp;
  395. int i;
  396. if (( dev < 0 ) || ( dev >= GAL_ETH_DEVS ))
  397. { /* This should never happen */
  398. printf("%s: Invalid device %d\n", __FUNCTION__, dev );
  399. return 0;
  400. }
  401. #ifdef DEBUG
  402. printf ("%s: initializing %s\n", __FUNCTION__, wp->name );
  403. printf ("\nCOMM_CONTROL = %08x , COMM_CONF = %08x\n",
  404. GTREGREAD(COMM_UNIT_ARBITER_CONTROL),
  405. GTREGREAD(COMM_UNIT_ARBITER_CONFIGURATION_REGISTER));
  406. #endif
  407. /* clear MIB counters */
  408. for(i=0;i<255; i++)
  409. temp=GTREGREAD(ETHERNET0_MIB_COUNTER_BASE + reg_base +i);
  410. #ifdef CONFIG_INTEL_LXT97X
  411. /* for intel LXT972 */
  412. /* led 1: 0x1=txact
  413. led 2: 0xc=link/rxact
  414. led 3: 0x2=rxact (N/C)
  415. strch: 0,2=30 ms, enable */
  416. miiphy_write(ether_port_phy_addr[p->dev], 20, 0x1c22);
  417. /* 2.7ns port rise time */
  418. /*miiphy_write(ether_port_phy_addr[p->dev], 30, 0x0<<10); */
  419. #else
  420. /* already set up in mpsc.c */
  421. /*GT_REG_WRITE(MAIN_ROUTING_REGISTER, 0x7ffe38); / b400 */
  422. /* already set up in sdram_init.S... */
  423. /* MPSC0, MPSC1, RMII */
  424. /*GT_REG_WRITE(SERIAL_PORT_MULTIPLEX, 0x1102); / f010 */
  425. #endif
  426. GT_REG_WRITE(ETHERNET_PHY_ADDRESS_REGISTER,
  427. ether_port_phy_addr[0] |
  428. (ether_port_phy_addr[1]<<5) |
  429. (ether_port_phy_addr[2]<<10)); /* 2000 */
  430. /* 13:12 - 10: 4x64bit burst (cache line size = 32 bytes)
  431. * 9 - 1: RIFB - interrupt on frame boundaries only
  432. * 6:7 - 00: big endian rx and tx
  433. * 5:2 - 1111: 15 retries */
  434. GT_REG_WRITE(ETHERNET0_SDMA_CONFIGURATION_REGISTER + reg_base,
  435. (2<<12) | (1<<9) | (0xf<<2) ); /* 2440 */
  436. #ifndef USE_SOFTWARE_CACHE_MANAGEMENT
  437. /* enable rx/tx desc/buffer cache snoop */
  438. GT_REG_READ(ETHERNET_0_ADDRESS_CONTROL_LOW + dev*0x20,
  439. &temp); /* f200 */
  440. temp|= (1<<6)| (1<<14)| (1<<22)| (1<<30);
  441. GT_REG_WRITE(ETHERNET_0_ADDRESS_CONTROL_LOW + dev*0x20,
  442. temp);
  443. #endif
  444. /* 31 28 27 24 23 20 19 16
  445. * 0000 0000 0000 0000 [0004]
  446. * 15 12 11 8 7 4 3 0
  447. * 1000 1101 0000 0000 [4d00]
  448. * 20 - 0=MII 1=RMII
  449. * 19 - 0=speed autoneg
  450. * 15:14 - framesize 1536 (GT6426x_ETH_BUF_SIZE)
  451. * 11 - no force link pass
  452. * 10 - 1=disable fctl autoneg
  453. * 8 - override prio ?? */
  454. temp = 0x00004d00;
  455. #ifndef CONFIG_ETHER_PORT_MII
  456. temp |= (1<<20); /* RMII */
  457. #endif
  458. /* set En */
  459. GT_REG_WRITE(ETHERNET0_PORT_CONFIGURATION_EXTEND_REGISTER + reg_base,
  460. temp); /* 2408 */
  461. /* hardcode E1 also? */
  462. /* -- according to dox, this is safer due to extra pulldowns? */
  463. if (dev<2) {
  464. GT_REG_WRITE(ETHERNET0_PORT_CONFIGURATION_EXTEND_REGISTER + (dev+1) * 0x400,
  465. temp); /* 2408 */
  466. }
  467. /* wake up MAC */ /* 2400 */
  468. GT_REG_READ(ETHERNET0_PORT_CONFIGURATION_REGISTER + reg_base, &temp);
  469. temp |= (1<<7); /* enable port */
  470. #ifdef CONFIG_GT_USE_MAC_HASH_TABLE
  471. temp |= (1<<12); /* hash size 1/2k */
  472. #else
  473. temp |= 1; /* promisc */
  474. #endif
  475. GT_REG_WRITE(ETHERNET0_PORT_CONFIGURATION_REGISTER + reg_base, temp);
  476. /* 2400 */
  477. #ifdef RESTART_AUTONEG
  478. check_phy_state(p);
  479. #endif
  480. printf("%s: Waiting for link up..\n", wp->name);
  481. temp = 10 * 1000;
  482. /* wait for link back up */
  483. while(!(GTREGREAD(ETHERNET0_PORT_STATUS_REGISTER + reg_base) & 8)
  484. && (--temp > 0)){
  485. udelay(1000); /* wait 1 ms */
  486. }
  487. if ( temp == 0) {
  488. printf("%s: Failed!\n", wp->name);
  489. return (0);
  490. }
  491. printf("%s: OK!\n", wp->name);
  492. p->tdn = 0;
  493. p->rdn = 0;
  494. p->eth_tx_desc[p->tdn].command_status = 0;
  495. /* Initialize Rx Side */
  496. for (temp = 0; temp < NR; temp++) {
  497. p->eth_rx_desc[temp].buff_pointer = p->eth_rx_buffer[temp];
  498. p->eth_rx_desc[temp].buff_size_byte_count = GT6426x_ETH_BUF_SIZE<<16;
  499. /* GT96100 Owner */
  500. p->eth_rx_desc[temp].command_status = 0x80000000;
  501. p->eth_rx_desc[temp].next_desc =
  502. (struct eth0_rx_desc_struct *)
  503. &p->eth_rx_desc[(temp+1)%NR].buff_size_byte_count;
  504. }
  505. FLUSH_DCACHE((unsigned int)&p->eth_tx_desc[0],
  506. (unsigned int)&p->eth_tx_desc[NR]);
  507. FLUSH_DCACHE((unsigned int)&p->eth_rx_desc[0],
  508. (unsigned int)&p->eth_rx_desc[NR]);
  509. GT_REG_WRITE(ETHERNET0_CURRENT_TX_DESCRIPTOR_POINTER0 + reg_base,
  510. (unsigned int) p->eth_tx_desc);
  511. GT_REG_WRITE(ETHERNET0_FIRST_RX_DESCRIPTOR_POINTER0 + reg_base,
  512. (unsigned int) p->eth_rx_desc);
  513. GT_REG_WRITE(ETHERNET0_CURRENT_RX_DESCRIPTOR_POINTER0 + reg_base,
  514. (unsigned int) p->eth_rx_desc);
  515. #ifdef DEBUG
  516. printf ("\nRx descriptor pointer is %08x %08x\n",
  517. GTREGREAD(ETHERNET0_FIRST_RX_DESCRIPTOR_POINTER0 + reg_base),
  518. GTREGREAD(ETHERNET0_CURRENT_RX_DESCRIPTOR_POINTER0 + reg_base));
  519. printf ("\n\n%08x %08x\n",
  520. (unsigned int)p->eth_rx_desc,p->eth_rx_desc[0].command_status);
  521. printf ("Descriptor dump:\n");
  522. printf ("cmd status: %08x\n",p->eth_rx_desc[0].command_status);
  523. printf ("byte_count: %08x\n",p->eth_rx_desc[0].buff_size_byte_count);
  524. printf ("buff_ptr: %08x\n",(unsigned int)p->eth_rx_desc[0].buff_pointer);
  525. printf ("next_desc: %08x\n\n",(unsigned int)p->eth_rx_desc[0].next_desc);
  526. printf ("%08x\n",*(unsigned int *) ((unsigned int)p->eth_rx_desc + 0x0));
  527. printf ("%08x\n",*(unsigned int *) ((unsigned int)p->eth_rx_desc + 0x4));
  528. printf ("%08x\n",*(unsigned int *) ((unsigned int)p->eth_rx_desc + 0x8));
  529. printf ("%08x\n\n",
  530. *(unsigned int *) ((unsigned int)p->eth_rx_desc + 0xc));
  531. #endif
  532. #ifdef DEBUG
  533. gt6426x_dump_mii(bis,ether_port_phy_addr[p->dev]);
  534. #endif
  535. #ifdef CONFIG_GT_USE_MAC_HASH_TABLE
  536. {
  537. unsigned int hashtable_base;
  538. u8 *b = (u8 *)(wp->enetaddr);
  539. u32 macH, macL;
  540. /* twist the MAC up into the way the discovery wants it */
  541. macH= (b[0]<<8) | b[1];
  542. macL= (b[2]<<24) | (b[3]<<16) | (b[4]<<8) | b[5];
  543. /* mode 0, size 0x800 */
  544. hashtable_base =initAddressTable(dev,0,1);
  545. if(!hashtable_base) {
  546. printf("initAddressTable failed\n");
  547. return 0;
  548. }
  549. addAddressTableEntry(dev, macH, macL, 1, 0);
  550. GT_REG_WRITE(ETHERNET0_HASH_TABLE_POINTER_REGISTER + reg_base,
  551. hashtable_base);
  552. }
  553. #endif
  554. /* Start Rx*/
  555. GT_REG_WRITE(ETHERNET0_SDMA_COMMAND_REGISTER + reg_base, 0x00000080);
  556. printf("%s: gt6426x eth device %d init success \n", wp->name, dev );
  557. return 1;
  558. }
  559. /* enter all the galileo ethernet devs into MULTI-BOOT */
  560. void
  561. gt6426x_eth_initialize(bd_t *bis)
  562. {
  563. struct eth_device *dev;
  564. struct eth_dev_s *p;
  565. int devnum, x, temp;
  566. char *s, *e, buf[64];
  567. #ifdef DEBUG
  568. printf( "\n%s\n", __FUNCTION );
  569. #endif
  570. for (devnum = 0; devnum < GAL_ETH_DEVS; devnum++) {
  571. dev = calloc(sizeof(*dev), 1);
  572. if (!dev) {
  573. printf( "%s: gal_enet%d allocation failure, %s\n",
  574. __FUNCTION__, devnum, "eth_device structure");
  575. return;
  576. }
  577. /* must be less than NAMESIZE (16) */
  578. sprintf(dev->name, "gal_enet%d", devnum);
  579. #ifdef DEBUG
  580. printf( "Initializing %s\n", dev->name );
  581. #endif
  582. /* Extract the MAC address from the environment */
  583. switch (devnum)
  584. {
  585. case 0: s = "ethaddr"; break;
  586. #if (GAL_ETH_DEVS > 1)
  587. case 1: s = "eth1addr"; break;
  588. #endif
  589. #if (GAL_ETH_DEVS > 2)
  590. case 2: s = "eth2addr"; break;
  591. #endif
  592. default: /* this should never happen */
  593. printf( "%s: Invalid device number %d\n",
  594. __FUNCTION__, devnum );
  595. return;
  596. }
  597. temp = getenv_r (s, buf, sizeof(buf));
  598. s = (temp > 0) ? buf : NULL;
  599. #ifdef DEBUG
  600. printf ("Setting MAC %d to %s\n", devnum, s );
  601. #endif
  602. for (x = 0; x < 6; ++x) {
  603. dev->enetaddr[x] = s ? simple_strtoul(s, &e, 16) : 0;
  604. if (s)
  605. s = (*e) ? e+1 : e;
  606. }
  607. dev->init = (void*)gt6426x_eth_probe;
  608. dev->halt = (void*)gt6426x_eth_reset;
  609. dev->send = (void*)gt6426x_eth_transmit;
  610. dev->recv = (void*)gt6426x_eth_poll;
  611. dev->priv = (void*)p = calloc( sizeof(*p), 1 );
  612. if (!p)
  613. {
  614. printf( "%s: %s allocation failure, %s\n",
  615. __FUNCTION__, dev->name, "Private Device Structure");
  616. free(dev);
  617. return;
  618. }
  619. p->dev = devnum;
  620. p->tdn=0;
  621. p->rdn=0;
  622. p->reg_base = devnum * ETHERNET_PORTS_DIFFERENCE_OFFSETS;
  623. p->eth_tx_desc =
  624. (eth0_tx_desc_single *)
  625. (((unsigned int) malloc(sizeof (eth0_tx_desc_single) *
  626. (NT+1)) & 0xfffffff0) + 0x10);
  627. if (!p)
  628. {
  629. printf( "%s: %s allocation failure, %s\n",
  630. __FUNCTION__, dev->name, "Tx Descriptor");
  631. free(dev);
  632. return;
  633. }
  634. p->eth_rx_desc =
  635. (eth0_rx_desc_single *)
  636. (((unsigned int) malloc(sizeof (eth0_rx_desc_single) *
  637. (NR+1)) & 0xfffffff0) + 0x10);
  638. if (!p->eth_rx_desc)
  639. {
  640. printf( "%s: %s allocation failure, %s\n",
  641. __FUNCTION__, dev->name, "Rx Descriptor");
  642. free(dev);
  643. free(p);
  644. return;
  645. }
  646. p->eth_tx_buffer =
  647. (char *) (((unsigned int) malloc(GT6426x_ETH_BUF_SIZE) & 0xfffffff0) + 0x10);
  648. if (!p->eth_tx_buffer)
  649. {
  650. printf( "%s: %s allocation failure, %s\n",
  651. __FUNCTION__, dev->name, "Tx Bufffer");
  652. free(dev);
  653. free(p);
  654. free(p->eth_rx_desc);
  655. return;
  656. }
  657. for (temp = 0 ; temp < NR ; temp ++) {
  658. p->eth_rx_buffer[temp] =
  659. (char *)
  660. (((unsigned int) malloc(GT6426x_ETH_BUF_SIZE) & 0xfffffff0) + 0x10);
  661. if (!p->eth_rx_buffer[temp])
  662. {
  663. printf( "%s: %s allocation failure, %s\n",
  664. __FUNCTION__, dev->name, "Rx Buffers");
  665. free(dev);
  666. free(p);
  667. free(p->eth_tx_buffer);
  668. free(p->eth_rx_desc);
  669. free(p->eth_tx_desc);
  670. while (temp >= 0)
  671. free(p->eth_rx_buffer[--temp]);
  672. return;
  673. }
  674. }
  675. eth_register(dev);
  676. }
  677. }
  678. #endif /* CFG_CMD_NET && CONFIG_NET_MULTI */