eth.c 22 KB

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