PageRenderTime 74ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/u-boot-1.1.6/cpu/ppc4xx/4xx_enet.c

http://dingoo-linux.googlecode.com/
C | 1724 lines | 1222 code | 196 blank | 306 comment | 287 complexity | 3c0ea43826d020bea4adbebb20a83763 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0, CC-BY-SA-3.0
  1. /*-----------------------------------------------------------------------------+
  2. *
  3. * This source code has been made available to you by IBM on an AS-IS
  4. * basis. Anyone receiving this source is licensed under IBM
  5. * copyrights to use it in any way he or she deems fit, including
  6. * copying it, modifying it, compiling it, and redistributing it either
  7. * with or without modifications. No license under IBM patents or
  8. * patent applications is to be implied by the copyright license.
  9. *
  10. * Any user of this software should understand that IBM cannot provide
  11. * technical support for this software and will not be responsible for
  12. * any consequences resulting from the use of this software.
  13. *
  14. * Any person who transfers this source code or any derivative work
  15. * must include the IBM copyright notice, this paragraph, and the
  16. * preceding two paragraphs in the transferred software.
  17. *
  18. * COPYRIGHT I B M CORPORATION 1995
  19. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  20. *-----------------------------------------------------------------------------*/
  21. /*-----------------------------------------------------------------------------+
  22. *
  23. * File Name: enetemac.c
  24. *
  25. * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
  26. *
  27. * Author: Mark Wisner
  28. *
  29. * Change Activity-
  30. *
  31. * Date Description of Change BY
  32. * --------- --------------------- ---
  33. * 05-May-99 Created MKW
  34. * 27-Jun-99 Clean up JWB
  35. * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW
  36. * 29-Jul-99 Added Full duplex support MKW
  37. * 06-Aug-99 Changed names for Mal CR reg MKW
  38. * 23-Aug-99 Turned off SYE when running at 10Mbs MKW
  39. * 24-Aug-99 Marked descriptor empty after call_xlc MKW
  40. * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG
  41. * to avoid chaining maximum sized packets. Push starting
  42. * RX descriptor address up to the next cache line boundary.
  43. * 16-Jan-00 Added support for booting with IP of 0x0 MKW
  44. * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the
  45. * EMAC_RXM register. JWB
  46. * 12-Mar-01 anne-sophie.harnois@nextream.fr
  47. * - Variables are compatible with those already defined in
  48. * include/net.h
  49. * - Receive buffer descriptor ring is used to send buffers
  50. * to the user
  51. * - Info print about send/received/handled packet number if
  52. * INFO_405_ENET is set
  53. * 17-Apr-01 stefan.roese@esd-electronics.com
  54. * - MAL reset in "eth_halt" included
  55. * - Enet speed and duplex output now in one line
  56. * 08-May-01 stefan.roese@esd-electronics.com
  57. * - MAL error handling added (eth_init called again)
  58. * 13-Nov-01 stefan.roese@esd-electronics.com
  59. * - Set IST bit in EMAC_M1 reg upon 100MBit or full duplex
  60. * 04-Jan-02 stefan.roese@esd-electronics.com
  61. * - Wait for PHY auto negotiation to complete added
  62. * 06-Feb-02 stefan.roese@esd-electronics.com
  63. * - Bug fixed in waiting for auto negotiation to complete
  64. * 26-Feb-02 stefan.roese@esd-electronics.com
  65. * - rx and tx buffer descriptors now allocated (no fixed address
  66. * used anymore)
  67. * 17-Jun-02 stefan.roese@esd-electronics.com
  68. * - MAL error debug printf 'M' removed (rx de interrupt may
  69. * occur upon many incoming packets with only 4 rx buffers).
  70. *-----------------------------------------------------------------------------*
  71. * 17-Nov-03 travis.sawyer@sandburst.com
  72. * - ported from 405gp_enet.c to utilized upto 4 EMAC ports
  73. * in the 440GX. This port should work with the 440GP
  74. * (2 EMACs) also
  75. * 15-Aug-05 sr@denx.de
  76. * - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c
  77. now handling all 4xx cpu's.
  78. *-----------------------------------------------------------------------------*/
  79. #include <config.h>
  80. #include <common.h>
  81. #include <net.h>
  82. #include <asm/processor.h>
  83. #include <commproc.h>
  84. #include <ppc4xx.h>
  85. #include <ppc4xx_enet.h>
  86. #include <405_mal.h>
  87. #include <miiphy.h>
  88. #include <malloc.h>
  89. #include "vecnum.h"
  90. /*
  91. * Only compile for platform with AMCC EMAC ethernet controller and
  92. * network support enabled.
  93. * Remark: CONFIG_405 describes Xilinx PPC405 FPGA without EMAC controller!
  94. */
  95. #if (CONFIG_COMMANDS & CFG_CMD_NET) && !defined(CONFIG_405) && !defined(CONFIG_IOP480)
  96. #if !(defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII))
  97. #error "CONFIG_MII has to be defined!"
  98. #endif
  99. #if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_NET_MULTI)
  100. #error "CONFIG_NET_MULTI has to be defined for NetConsole"
  101. #endif
  102. #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
  103. #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
  104. /* Ethernet Transmit and Receive Buffers */
  105. /* AS.HARNOIS
  106. * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
  107. * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
  108. */
  109. #define ENET_MAX_MTU PKTSIZE
  110. #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
  111. /*-----------------------------------------------------------------------------+
  112. * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
  113. * Interrupt Controller).
  114. *-----------------------------------------------------------------------------*/
  115. #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
  116. #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
  117. #define EMAC_UIC_DEF UIC_ENET
  118. #define EMAC_UIC_DEF1 UIC_ENET1
  119. #define SEL_UIC_DEF(p) (p ? UIC_ENET1 : UIC_ENET )
  120. #undef INFO_4XX_ENET
  121. #define BI_PHYMODE_NONE 0
  122. #define BI_PHYMODE_ZMII 1
  123. #define BI_PHYMODE_RGMII 2
  124. #define BI_PHYMODE_GMII 3
  125. #define BI_PHYMODE_RTBI 4
  126. #define BI_PHYMODE_TBI 5
  127. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  128. #define BI_PHYMODE_SMII 6
  129. #define BI_PHYMODE_MII 7
  130. #endif
  131. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  132. #define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
  133. #endif
  134. /*-----------------------------------------------------------------------------+
  135. * Global variables. TX and RX descriptors and buffers.
  136. *-----------------------------------------------------------------------------*/
  137. /* IER globals */
  138. static uint32_t mal_ier;
  139. #if !defined(CONFIG_NET_MULTI)
  140. struct eth_device *emac0_dev = NULL;
  141. #endif
  142. /*
  143. * Get count of EMAC devices (doesn't have to be the max. possible number
  144. * supported by the cpu)
  145. */
  146. #if defined(CONFIG_HAS_ETH3)
  147. #define LAST_EMAC_NUM 4
  148. #elif defined(CONFIG_HAS_ETH2)
  149. #define LAST_EMAC_NUM 3
  150. #elif defined(CONFIG_HAS_ETH1)
  151. #define LAST_EMAC_NUM 2
  152. #else
  153. #define LAST_EMAC_NUM 1
  154. #endif
  155. /*-----------------------------------------------------------------------------+
  156. * Prototypes and externals.
  157. *-----------------------------------------------------------------------------*/
  158. static void enet_rcv (struct eth_device *dev, unsigned long malisr);
  159. int enetInt (struct eth_device *dev);
  160. static void mal_err (struct eth_device *dev, unsigned long isr,
  161. unsigned long uic, unsigned long maldef,
  162. unsigned long mal_errr);
  163. static void emac_err (struct eth_device *dev, unsigned long isr);
  164. extern int phy_setup_aneg (char *devname, unsigned char addr);
  165. extern int emac4xx_miiphy_read (char *devname, unsigned char addr,
  166. unsigned char reg, unsigned short *value);
  167. extern int emac4xx_miiphy_write (char *devname, unsigned char addr,
  168. unsigned char reg, unsigned short value);
  169. /*-----------------------------------------------------------------------------+
  170. | ppc_4xx_eth_halt
  171. | Disable MAL channel, and EMACn
  172. +-----------------------------------------------------------------------------*/
  173. static void ppc_4xx_eth_halt (struct eth_device *dev)
  174. {
  175. EMAC_4XX_HW_PST hw_p = dev->priv;
  176. uint32_t failsafe = 10000;
  177. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  178. unsigned long mfr;
  179. #endif
  180. out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
  181. /* 1st reset MAL channel */
  182. /* Note: writing a 0 to a channel has no effect */
  183. #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  184. mtdcr (maltxcarr, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
  185. #else
  186. mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  187. #endif
  188. mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  189. /* wait for reset */
  190. while (mfdcr (malrxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
  191. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  192. failsafe--;
  193. if (failsafe == 0)
  194. break;
  195. }
  196. /* EMAC RESET */
  197. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  198. /* provide clocks for EMAC internal loopback */
  199. mfsdr (sdr_mfr, mfr);
  200. mfr |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
  201. mtsdr(sdr_mfr, mfr);
  202. #endif
  203. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  204. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  205. /* remove clocks for EMAC internal loopback */
  206. mfsdr (sdr_mfr, mfr);
  207. mfr &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
  208. mtsdr(sdr_mfr, mfr);
  209. #endif
  210. #ifndef CONFIG_NETCONSOLE
  211. hw_p->print_speed = 1; /* print speed message again next time */
  212. #endif
  213. return;
  214. }
  215. #if defined (CONFIG_440GX)
  216. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  217. {
  218. unsigned long pfc1;
  219. unsigned long zmiifer;
  220. unsigned long rmiifer;
  221. mfsdr(sdr_pfc1, pfc1);
  222. pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
  223. zmiifer = 0;
  224. rmiifer = 0;
  225. switch (pfc1) {
  226. case 1:
  227. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  228. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
  229. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
  230. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
  231. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  232. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  233. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  234. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  235. break;
  236. case 2:
  237. zmiifer = ZMII_FER_SMII << ZMII_FER_V(0);
  238. zmiifer = ZMII_FER_SMII << ZMII_FER_V(1);
  239. zmiifer = ZMII_FER_SMII << ZMII_FER_V(2);
  240. zmiifer = ZMII_FER_SMII << ZMII_FER_V(3);
  241. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  242. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  243. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  244. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  245. break;
  246. case 3:
  247. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  248. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  249. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  250. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  251. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  252. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  253. break;
  254. case 4:
  255. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  256. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  257. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
  258. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
  259. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  260. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  261. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  262. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  263. break;
  264. case 5:
  265. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  266. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  267. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
  268. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
  269. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  270. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  271. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  272. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  273. break;
  274. case 6:
  275. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  276. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  277. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  278. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  279. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  280. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  281. break;
  282. case 0:
  283. default:
  284. zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
  285. rmiifer = 0x0;
  286. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  287. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  288. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  289. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  290. break;
  291. }
  292. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  293. zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
  294. out32 (ZMII_FER, zmiifer);
  295. out32 (RGMII_FER, rmiifer);
  296. return ((int)pfc1);
  297. }
  298. #endif /* CONFIG_440_GX */
  299. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  300. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  301. {
  302. unsigned long zmiifer=0x0;
  303. /*
  304. * Right now only 2*RGMII is supported. Please extend when needed.
  305. * sr - 2006-08-29
  306. */
  307. switch (1) {
  308. case 0:
  309. /* 1 x GMII port */
  310. out32 (ZMII_FER, 0x00);
  311. out32 (RGMII_FER, 0x00000037);
  312. bis->bi_phymode[0] = BI_PHYMODE_GMII;
  313. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  314. break;
  315. case 1:
  316. /* 2 x RGMII ports */
  317. out32 (ZMII_FER, 0x00);
  318. out32 (RGMII_FER, 0x00000055);
  319. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  320. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  321. break;
  322. case 2:
  323. /* 2 x SMII ports */
  324. break;
  325. default:
  326. break;
  327. }
  328. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  329. zmiifer = in32 (ZMII_FER);
  330. zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
  331. out32 (ZMII_FER, zmiifer);
  332. return ((int)0x0);
  333. }
  334. #endif /* CONFIG_440EPX */
  335. static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
  336. {
  337. int i, j;
  338. unsigned long reg = 0;
  339. unsigned long msr;
  340. unsigned long speed;
  341. unsigned long duplex;
  342. unsigned long failsafe;
  343. unsigned mode_reg;
  344. unsigned short devnum;
  345. unsigned short reg_short;
  346. #if defined(CONFIG_440GX) || \
  347. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  348. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  349. sys_info_t sysinfo;
  350. #if defined(CONFIG_440GX) || defined(CONFIG_440SPE) || \
  351. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  352. int ethgroup = -1;
  353. #endif
  354. #endif
  355. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || defined(CONFIG_440SPE)
  356. unsigned long mfr;
  357. #endif
  358. EMAC_4XX_HW_PST hw_p = dev->priv;
  359. /* before doing anything, figure out if we have a MAC address */
  360. /* if not, bail */
  361. if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  362. printf("ERROR: ethaddr not set!\n");
  363. return -1;
  364. }
  365. #if defined(CONFIG_440GX) || \
  366. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  367. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  368. /* Need to get the OPB frequency so we can access the PHY */
  369. get_sys_info (&sysinfo);
  370. #endif
  371. msr = mfmsr ();
  372. mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
  373. devnum = hw_p->devnum;
  374. #ifdef INFO_4XX_ENET
  375. /* AS.HARNOIS
  376. * We should have :
  377. * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
  378. * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
  379. * is possible that new packets (without relationship with
  380. * current transfer) have got the time to arrived before
  381. * netloop calls eth_halt
  382. */
  383. printf ("About preceeding transfer (eth%d):\n"
  384. "- Sent packet number %d\n"
  385. "- Received packet number %d\n"
  386. "- Handled packet number %d\n",
  387. hw_p->devnum,
  388. hw_p->stats.pkts_tx,
  389. hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
  390. hw_p->stats.pkts_tx = 0;
  391. hw_p->stats.pkts_rx = 0;
  392. hw_p->stats.pkts_handled = 0;
  393. hw_p->print_speed = 1; /* print speed message again next time */
  394. #endif
  395. hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
  396. hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
  397. hw_p->rx_slot = 0; /* MAL Receive Slot */
  398. hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
  399. hw_p->rx_u_index = 0; /* Receive User Queue Index */
  400. hw_p->tx_slot = 0; /* MAL Transmit Slot */
  401. hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
  402. hw_p->tx_u_index = 0; /* Transmit User Queue Index */
  403. #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
  404. /* set RMII mode */
  405. /* NOTE: 440GX spec states that mode is mutually exclusive */
  406. /* NOTE: Therefore, disable all other EMACS, since we handle */
  407. /* NOTE: only one emac at a time */
  408. reg = 0;
  409. out32 (ZMII_FER, 0);
  410. udelay (100);
  411. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  412. out32 (ZMII_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
  413. #elif defined(CONFIG_440GX) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  414. ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
  415. #elif defined(CONFIG_440GP)
  416. /* set RMII mode */
  417. out32 (ZMII_FER, ZMII_RMII | ZMII_MDI0);
  418. #else
  419. if ((devnum == 0) || (devnum == 1)) {
  420. out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
  421. }
  422. else { /* ((devnum == 2) || (devnum == 3)) */
  423. out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
  424. out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
  425. (RGMII_FER_RGMII << RGMII_FER_V (3))));
  426. }
  427. #endif
  428. out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
  429. #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
  430. __asm__ volatile ("eieio");
  431. /* reset emac so we have access to the phy */
  432. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  433. /* provide clocks for EMAC internal loopback */
  434. mfsdr (sdr_mfr, mfr);
  435. mfr |= SDR0_MFR_ETH_CLK_SEL_V(devnum);
  436. mtsdr(sdr_mfr, mfr);
  437. #endif
  438. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  439. __asm__ volatile ("eieio");
  440. failsafe = 1000;
  441. while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
  442. udelay (1000);
  443. failsafe--;
  444. }
  445. if (failsafe <= 0)
  446. printf("\nProblem resetting EMAC!\n");
  447. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  448. /* remove clocks for EMAC internal loopback */
  449. mfsdr (sdr_mfr, mfr);
  450. mfr &= ~SDR0_MFR_ETH_CLK_SEL_V(devnum);
  451. mtsdr(sdr_mfr, mfr);
  452. #endif
  453. #if defined(CONFIG_440GX) || \
  454. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  455. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  456. /* Whack the M1 register */
  457. mode_reg = 0x0;
  458. mode_reg &= ~0x00000038;
  459. if (sysinfo.freqOPB <= 50000000);
  460. else if (sysinfo.freqOPB <= 66666667)
  461. mode_reg |= EMAC_M1_OBCI_66;
  462. else if (sysinfo.freqOPB <= 83333333)
  463. mode_reg |= EMAC_M1_OBCI_83;
  464. else if (sysinfo.freqOPB <= 100000000)
  465. mode_reg |= EMAC_M1_OBCI_100;
  466. else
  467. mode_reg |= EMAC_M1_OBCI_GT100;
  468. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  469. #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
  470. /* wait for PHY to complete auto negotiation */
  471. reg_short = 0;
  472. #ifndef CONFIG_CS8952_PHY
  473. switch (devnum) {
  474. case 0:
  475. reg = CONFIG_PHY_ADDR;
  476. break;
  477. #if defined (CONFIG_PHY1_ADDR)
  478. case 1:
  479. reg = CONFIG_PHY1_ADDR;
  480. break;
  481. #endif
  482. #if defined (CONFIG_440GX)
  483. case 2:
  484. reg = CONFIG_PHY2_ADDR;
  485. break;
  486. case 3:
  487. reg = CONFIG_PHY3_ADDR;
  488. break;
  489. #endif
  490. default:
  491. reg = CONFIG_PHY_ADDR;
  492. break;
  493. }
  494. bis->bi_phynum[devnum] = reg;
  495. #if defined(CONFIG_PHY_RESET)
  496. /*
  497. * Reset the phy, only if its the first time through
  498. * otherwise, just check the speeds & feeds
  499. */
  500. if (hw_p->first_init == 0) {
  501. #if defined(CONFIG_88E1111_CLK_DELAY)
  502. /*
  503. * On some boards (e.g. ALPR) the Marvell 88E1111 PHY needs
  504. * the "RGMII transmit timing control" and "RGMII receive
  505. * timing control" bits set, so that Gbit communication works
  506. * without problems.
  507. * Also set the "Transmitter disable" to 1 to enable the
  508. * transmitter.
  509. * After setting these bits a soft-reset must occur for this
  510. * change to become active.
  511. */
  512. miiphy_read (dev->name, reg, 0x14, &reg_short);
  513. reg_short |= (1 << 7) | (1 << 1) | (1 << 0);
  514. miiphy_write (dev->name, reg, 0x14, reg_short);
  515. #endif
  516. #if defined(CONFIG_M88E1111_PHY) /* test-only: merge with CONFIG_88E1111_CLK_DELAY !!! */
  517. miiphy_write (dev->name, reg, 0x14, 0x0ce3);
  518. miiphy_write (dev->name, reg, 0x18, 0x4101);
  519. miiphy_write (dev->name, reg, 0x09, 0x0e00);
  520. miiphy_write (dev->name, reg, 0x04, 0x01e1);
  521. #endif
  522. miiphy_reset (dev->name, reg);
  523. #if defined(CONFIG_440GX) || \
  524. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  525. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  526. #if defined(CONFIG_CIS8201_PHY)
  527. /*
  528. * Cicada 8201 PHY needs to have an extended register whacked
  529. * for RGMII mode.
  530. */
  531. if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
  532. #if defined(CONFIG_CIS8201_SHORT_ETCH)
  533. miiphy_write (dev->name, reg, 23, 0x1300);
  534. #else
  535. miiphy_write (dev->name, reg, 23, 0x1000);
  536. #endif
  537. /*
  538. * Vitesse VSC8201/Cicada CIS8201 errata:
  539. * Interoperability problem with Intel 82547EI phys
  540. * This work around (provided by Vitesse) changes
  541. * the default timer convergence from 8ms to 12ms
  542. */
  543. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  544. miiphy_write (dev->name, reg, 0x08, 0x0200);
  545. miiphy_write (dev->name, reg, 0x1f, 0x52b5);
  546. miiphy_write (dev->name, reg, 0x02, 0x0004);
  547. miiphy_write (dev->name, reg, 0x01, 0x0671);
  548. miiphy_write (dev->name, reg, 0x00, 0x8fae);
  549. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  550. miiphy_write (dev->name, reg, 0x08, 0x0000);
  551. miiphy_write (dev->name, reg, 0x1f, 0x0000);
  552. /* end Vitesse/Cicada errata */
  553. }
  554. #endif
  555. #endif
  556. /* Start/Restart autonegotiation */
  557. phy_setup_aneg (dev->name, reg);
  558. udelay (1000);
  559. }
  560. #endif /* defined(CONFIG_PHY_RESET) */
  561. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  562. /*
  563. * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
  564. */
  565. if ((reg_short & PHY_BMSR_AUTN_ABLE)
  566. && !(reg_short & PHY_BMSR_AUTN_COMP)) {
  567. puts ("Waiting for PHY auto negotiation to complete");
  568. i = 0;
  569. while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
  570. /*
  571. * Timeout reached ?
  572. */
  573. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  574. puts (" TIMEOUT !\n");
  575. break;
  576. }
  577. if ((i++ % 1000) == 0) {
  578. putc ('.');
  579. }
  580. udelay (1000); /* 1 ms */
  581. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  582. }
  583. puts (" done\n");
  584. udelay (500000); /* another 500 ms (results in faster booting) */
  585. }
  586. #endif /* #ifndef CONFIG_CS8952_PHY */
  587. speed = miiphy_speed (dev->name, reg);
  588. duplex = miiphy_duplex (dev->name, reg);
  589. if (hw_p->print_speed) {
  590. hw_p->print_speed = 0;
  591. printf ("ENET Speed is %d Mbps - %s duplex connection\n",
  592. (int) speed, (duplex == HALF) ? "HALF" : "FULL");
  593. }
  594. #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
  595. !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
  596. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  597. mfsdr(sdr_mfr, reg);
  598. if (speed == 100) {
  599. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
  600. } else {
  601. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
  602. }
  603. mtsdr(sdr_mfr, reg);
  604. #endif
  605. /* Set ZMII/RGMII speed according to the phy link speed */
  606. reg = in32 (ZMII_SSR);
  607. if ( (speed == 100) || (speed == 1000) )
  608. out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
  609. else
  610. out32 (ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
  611. if ((devnum == 2) || (devnum == 3)) {
  612. if (speed == 1000)
  613. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  614. else if (speed == 100)
  615. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  616. else if (speed == 10)
  617. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  618. else {
  619. printf("Error in RGMII Speed\n");
  620. return -1;
  621. }
  622. out32 (RGMII_SSR, reg);
  623. }
  624. #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
  625. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  626. if (speed == 1000)
  627. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  628. else if (speed == 100)
  629. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  630. else if (speed == 10)
  631. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  632. else {
  633. printf("Error in RGMII Speed\n");
  634. return -1;
  635. }
  636. out32 (RGMII_SSR, reg);
  637. #endif
  638. /* set the Mal configuration reg */
  639. #if defined(CONFIG_440GX) || \
  640. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  641. defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  642. mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
  643. MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
  644. #else
  645. mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
  646. /* Errata 1.12: MAL_1 -- Disable MAL bursting */
  647. if (get_pvr() == PVR_440GP_RB) {
  648. mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
  649. }
  650. #endif
  651. /* Free "old" buffers */
  652. if (hw_p->alloc_tx_buf)
  653. free (hw_p->alloc_tx_buf);
  654. if (hw_p->alloc_rx_buf)
  655. free (hw_p->alloc_rx_buf);
  656. /*
  657. * Malloc MAL buffer desciptors, make sure they are
  658. * aligned on cache line boundary size
  659. * (401/403/IOP480 = 16, 405 = 32)
  660. * and doesn't cross cache block boundaries.
  661. */
  662. hw_p->alloc_tx_buf =
  663. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
  664. ((2 * CFG_CACHELINE_SIZE) - 2));
  665. if (NULL == hw_p->alloc_tx_buf)
  666. return -1;
  667. if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
  668. hw_p->tx =
  669. (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
  670. CFG_CACHELINE_SIZE -
  671. ((int) hw_p->
  672. alloc_tx_buf & CACHELINE_MASK));
  673. } else {
  674. hw_p->tx = hw_p->alloc_tx_buf;
  675. }
  676. hw_p->alloc_rx_buf =
  677. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
  678. ((2 * CFG_CACHELINE_SIZE) - 2));
  679. if (NULL == hw_p->alloc_rx_buf) {
  680. free(hw_p->alloc_tx_buf);
  681. hw_p->alloc_tx_buf = NULL;
  682. return -1;
  683. }
  684. if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
  685. hw_p->rx =
  686. (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
  687. CFG_CACHELINE_SIZE -
  688. ((int) hw_p->
  689. alloc_rx_buf & CACHELINE_MASK));
  690. } else {
  691. hw_p->rx = hw_p->alloc_rx_buf;
  692. }
  693. for (i = 0; i < NUM_TX_BUFF; i++) {
  694. hw_p->tx[i].ctrl = 0;
  695. hw_p->tx[i].data_len = 0;
  696. if (hw_p->first_init == 0) {
  697. hw_p->txbuf_ptr =
  698. (char *) malloc (ENET_MAX_MTU_ALIGNED);
  699. if (NULL == hw_p->txbuf_ptr) {
  700. free(hw_p->alloc_rx_buf);
  701. free(hw_p->alloc_tx_buf);
  702. hw_p->alloc_rx_buf = NULL;
  703. hw_p->alloc_tx_buf = NULL;
  704. for(j = 0; j < i; j++) {
  705. free(hw_p->tx[i].data_ptr);
  706. hw_p->tx[i].data_ptr = NULL;
  707. }
  708. }
  709. }
  710. hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
  711. if ((NUM_TX_BUFF - 1) == i)
  712. hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
  713. hw_p->tx_run[i] = -1;
  714. #if 0
  715. printf ("TX_BUFF %d @ 0x%08lx\n", i,
  716. (ulong) hw_p->tx[i].data_ptr);
  717. #endif
  718. }
  719. for (i = 0; i < NUM_RX_BUFF; i++) {
  720. hw_p->rx[i].ctrl = 0;
  721. hw_p->rx[i].data_len = 0;
  722. /* rx[i].data_ptr = (char *) &rx_buff[i]; */
  723. hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
  724. if ((NUM_RX_BUFF - 1) == i)
  725. hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
  726. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
  727. hw_p->rx_ready[i] = -1;
  728. #if 0
  729. printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
  730. #endif
  731. }
  732. reg = 0x00000000;
  733. reg |= dev->enetaddr[0]; /* set high address */
  734. reg = reg << 8;
  735. reg |= dev->enetaddr[1];
  736. out32 (EMAC_IAH + hw_p->hw_addr, reg);
  737. reg = 0x00000000;
  738. reg |= dev->enetaddr[2]; /* set low address */
  739. reg = reg << 8;
  740. reg |= dev->enetaddr[3];
  741. reg = reg << 8;
  742. reg |= dev->enetaddr[4];
  743. reg = reg << 8;
  744. reg |= dev->enetaddr[5];
  745. out32 (EMAC_IAL + hw_p->hw_addr, reg);
  746. switch (devnum) {
  747. case 1:
  748. /* setup MAL tx & rx channel pointers */
  749. #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
  750. mtdcr (maltxctp2r, hw_p->tx);
  751. #else
  752. mtdcr (maltxctp1r, hw_p->tx);
  753. #endif
  754. #if defined(CONFIG_440)
  755. mtdcr (maltxbattr, 0x0);
  756. mtdcr (malrxbattr, 0x0);
  757. #endif
  758. mtdcr (malrxctp1r, hw_p->rx);
  759. /* set RX buffer size */
  760. mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
  761. break;
  762. #if defined (CONFIG_440GX)
  763. case 2:
  764. /* setup MAL tx & rx channel pointers */
  765. mtdcr (maltxbattr, 0x0);
  766. mtdcr (malrxbattr, 0x0);
  767. mtdcr (maltxctp2r, hw_p->tx);
  768. mtdcr (malrxctp2r, hw_p->rx);
  769. /* set RX buffer size */
  770. mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
  771. break;
  772. case 3:
  773. /* setup MAL tx & rx channel pointers */
  774. mtdcr (maltxbattr, 0x0);
  775. mtdcr (maltxctp3r, hw_p->tx);
  776. mtdcr (malrxbattr, 0x0);
  777. mtdcr (malrxctp3r, hw_p->rx);
  778. /* set RX buffer size */
  779. mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
  780. break;
  781. #endif /* CONFIG_440GX */
  782. case 0:
  783. default:
  784. /* setup MAL tx & rx channel pointers */
  785. #if defined(CONFIG_440)
  786. mtdcr (maltxbattr, 0x0);
  787. mtdcr (malrxbattr, 0x0);
  788. #endif
  789. mtdcr (maltxctp0r, hw_p->tx);
  790. mtdcr (malrxctp0r, hw_p->rx);
  791. /* set RX buffer size */
  792. mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
  793. break;
  794. }
  795. /* Enable MAL transmit and receive channels */
  796. #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  797. mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
  798. #else
  799. mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  800. #endif
  801. mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  802. /* set transmit enable & receive enable */
  803. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
  804. /* set receive fifo to 4k and tx fifo to 2k */
  805. mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
  806. mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
  807. /* set speed */
  808. if (speed == _1000BASET) {
  809. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  810. defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  811. unsigned long pfc1;
  812. mfsdr (sdr_pfc1, pfc1);
  813. pfc1 |= SDR0_PFC1_EM_1000;
  814. mtsdr (sdr_pfc1, pfc1);
  815. #endif
  816. mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
  817. } else if (speed == _100BASET)
  818. mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
  819. else
  820. mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
  821. if (duplex == FULL)
  822. mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
  823. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  824. /* Enable broadcast and indvidual address */
  825. /* TBS: enabling runts as some misbehaved nics will send runts */
  826. out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
  827. /* we probably need to set the tx mode1 reg? maybe at tx time */
  828. /* set transmit request threshold register */
  829. out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
  830. /* set receive low/high water mark register */
  831. #if defined(CONFIG_440)
  832. /* 440s has a 64 byte burst length */
  833. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
  834. #else
  835. /* 405s have a 16 byte burst length */
  836. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
  837. #endif /* defined(CONFIG_440) */
  838. out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
  839. /* Set fifo limit entry in tx mode 0 */
  840. out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
  841. /* Frame gap set */
  842. out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
  843. /* Set EMAC IER */
  844. hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
  845. if (speed == _100BASET)
  846. hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
  847. out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
  848. out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
  849. if (hw_p->first_init == 0) {
  850. /*
  851. * Connect interrupt service routines
  852. */
  853. irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
  854. (interrupt_handler_t *) enetInt, dev);
  855. }
  856. mtmsr (msr); /* enable interrupts again */
  857. hw_p->bis = bis;
  858. hw_p->first_init = 1;
  859. return (1);
  860. }
  861. static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
  862. int len)
  863. {
  864. struct enet_frame *ef_ptr;
  865. ulong time_start, time_now;
  866. unsigned long temp_txm0;
  867. EMAC_4XX_HW_PST hw_p = dev->priv;
  868. ef_ptr = (struct enet_frame *) ptr;
  869. /*-----------------------------------------------------------------------+
  870. * Copy in our address into the frame.
  871. *-----------------------------------------------------------------------*/
  872. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  873. /*-----------------------------------------------------------------------+
  874. * If frame is too long or too short, modify length.
  875. *-----------------------------------------------------------------------*/
  876. /* TBS: where does the fragment go???? */
  877. if (len > ENET_MAX_MTU)
  878. len = ENET_MAX_MTU;
  879. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  880. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  881. /*-----------------------------------------------------------------------+
  882. * set TX Buffer busy, and send it
  883. *-----------------------------------------------------------------------*/
  884. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  885. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  886. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  887. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  888. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  889. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  890. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  891. __asm__ volatile ("eieio");
  892. out32 (EMAC_TXM0 + hw_p->hw_addr,
  893. in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
  894. #ifdef INFO_4XX_ENET
  895. hw_p->stats.pkts_tx++;
  896. #endif
  897. /*-----------------------------------------------------------------------+
  898. * poll unitl the packet is sent and then make sure it is OK
  899. *-----------------------------------------------------------------------*/
  900. time_start = get_timer (0);
  901. while (1) {
  902. temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
  903. /* loop until either TINT turns on or 3 seconds elapse */
  904. if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
  905. /* transmit is done, so now check for errors
  906. * If there is an error, an interrupt should
  907. * happen when we return
  908. */
  909. time_now = get_timer (0);
  910. if ((time_now - time_start) > 3000) {
  911. return (-1);
  912. }
  913. } else {
  914. return (len);
  915. }
  916. }
  917. }
  918. #if defined (CONFIG_440)
  919. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  920. /*
  921. * Hack: On 440SP all enet irq sources are located on UIC1
  922. * Needs some cleanup. --sr
  923. */
  924. #define UIC0MSR uic1msr
  925. #define UIC0SR uic1sr
  926. #else
  927. #define UIC0MSR uic0msr
  928. #define UIC0SR uic0sr
  929. #endif
  930. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  931. #define UICMSR_ETHX uic0msr
  932. #define UICSR_ETHX uic0sr
  933. #else
  934. #define UICMSR_ETHX uic1msr
  935. #define UICSR_ETHX uic1sr
  936. #endif
  937. int enetInt (struct eth_device *dev)
  938. {
  939. int serviced;
  940. int rc = -1; /* default to not us */
  941. unsigned long mal_isr;
  942. unsigned long emac_isr = 0;
  943. unsigned long mal_rx_eob;
  944. unsigned long my_uic0msr, my_uic1msr;
  945. unsigned long my_uicmsr_ethx;
  946. #if defined(CONFIG_440GX)
  947. unsigned long my_uic2msr;
  948. #endif
  949. EMAC_4XX_HW_PST hw_p;
  950. /*
  951. * Because the mal is generic, we need to get the current
  952. * eth device
  953. */
  954. #if defined(CONFIG_NET_MULTI)
  955. dev = eth_get_dev();
  956. #else
  957. dev = emac0_dev;
  958. #endif
  959. hw_p = dev->priv;
  960. /* enter loop that stays in interrupt code until nothing to service */
  961. do {
  962. serviced = 0;
  963. my_uic0msr = mfdcr (UIC0MSR);
  964. my_uic1msr = mfdcr (uic1msr);
  965. #if defined(CONFIG_440GX)
  966. my_uic2msr = mfdcr (uic2msr);
  967. #endif
  968. my_uicmsr_ethx = mfdcr (UICMSR_ETHX);
  969. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  970. && !(my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))
  971. && !(my_uicmsr_ethx & (UIC_ETH0 | UIC_ETH1))) {
  972. /* not for us */
  973. return (rc);
  974. }
  975. #if defined (CONFIG_440GX)
  976. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  977. && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
  978. /* not for us */
  979. return (rc);
  980. }
  981. #endif
  982. /* get and clear controller status interrupts */
  983. /* look at Mal and EMAC interrupts */
  984. if ((my_uic0msr & (UIC_MRE | UIC_MTE))
  985. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  986. /* we have a MAL interrupt */
  987. mal_isr = mfdcr (malesr);
  988. /* look for mal error */
  989. if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
  990. mal_err (dev, mal_isr, my_uic1msr, MAL_UIC_DEF, MAL_UIC_ERR);
  991. serviced = 1;
  992. rc = 0;
  993. }
  994. }
  995. /* port by port dispatch of emac interrupts */
  996. if (hw_p->devnum == 0) {
  997. if (UIC_ETH0 & my_uicmsr_ethx) { /* look for EMAC errors */
  998. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  999. if ((hw_p->emac_ier & emac_isr) != 0) {
  1000. emac_err (dev, emac_isr);
  1001. serviced = 1;
  1002. rc = 0;
  1003. }
  1004. }
  1005. if ((hw_p->emac_ier & emac_isr)
  1006. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  1007. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  1008. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  1009. mtdcr (UICSR_ETHX, UIC_ETH0); /* Clear */
  1010. return (rc); /* we had errors so get out */
  1011. }
  1012. }
  1013. #if !defined(CONFIG_440SP)
  1014. if (hw_p->devnum == 1) {
  1015. if (UIC_ETH1 & my_uicmsr_ethx) { /* look for EMAC errors */
  1016. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  1017. if ((hw_p->emac_ier & emac_isr) != 0) {
  1018. emac_err (dev, emac_isr);
  1019. serviced = 1;
  1020. rc = 0;
  1021. }
  1022. }
  1023. if ((hw_p->emac_ier & emac_isr)
  1024. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  1025. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  1026. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  1027. mtdcr (UICSR_ETHX, UIC_ETH1); /* Clear */
  1028. return (rc); /* we had errors so get out */
  1029. }
  1030. }
  1031. #if defined (CONFIG_440GX)
  1032. if (hw_p->devnum == 2) {
  1033. if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
  1034. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  1035. if ((hw_p->emac_ier & emac_isr) != 0) {
  1036. emac_err (dev, emac_isr);
  1037. serviced = 1;
  1038. rc = 0;
  1039. }
  1040. }
  1041. if ((hw_p->emac_ier & emac_isr)
  1042. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  1043. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  1044. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  1045. mtdcr (uic2sr, UIC_ETH2);
  1046. return (rc); /* we had errors so get out */
  1047. }
  1048. }
  1049. if (hw_p->devnum == 3) {
  1050. if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
  1051. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  1052. if ((hw_p->emac_ier & emac_isr) != 0) {
  1053. emac_err (dev, emac_isr);
  1054. serviced = 1;
  1055. rc = 0;
  1056. }
  1057. }
  1058. if ((hw_p->emac_ier & emac_isr)
  1059. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  1060. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  1061. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  1062. mtdcr (uic2sr, UIC_ETH3);
  1063. return (rc); /* we had errors so get out */
  1064. }
  1065. }
  1066. #endif /* CONFIG_440GX */
  1067. #endif /* !CONFIG_440SP */
  1068. /* handle MAX TX EOB interrupt from a tx */
  1069. if (my_uic0msr & UIC_MTE) {
  1070. mal_rx_eob = mfdcr (maltxeobisr);
  1071. mtdcr (maltxeobisr, mal_rx_eob);
  1072. mtdcr (UIC0SR, UIC_MTE);
  1073. }
  1074. /* handle MAL RX EOB interupt from a receive */
  1075. /* check for EOB on valid channels */
  1076. if (my_uic0msr & UIC_MRE) {
  1077. mal_rx_eob = mfdcr (malrxeobisr);
  1078. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  1079. /* clear EOB
  1080. mtdcr(malrxeobisr, mal_rx_eob); */
  1081. enet_rcv (dev, emac_isr);
  1082. /* indicate that we serviced an interrupt */
  1083. serviced = 1;
  1084. rc = 0;
  1085. }
  1086. }
  1087. mtdcr (UIC0SR, UIC_MRE); /* Clear */
  1088. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  1089. switch (hw_p->devnum) {
  1090. case 0:
  1091. mtdcr (UICSR_ETHX, UIC_ETH0);
  1092. break;
  1093. case 1:
  1094. mtdcr (UICSR_ETHX, UIC_ETH1);
  1095. break;
  1096. #if defined (CONFIG_440GX)
  1097. case 2:
  1098. mtdcr (uic2sr, UIC_ETH2);
  1099. break;
  1100. case 3:
  1101. mtdcr (uic2sr, UIC_ETH3);
  1102. break;
  1103. #endif /* CONFIG_440GX */
  1104. default:
  1105. break;
  1106. }
  1107. } while (serviced);
  1108. return (rc);
  1109. }
  1110. #else /* CONFIG_440 */
  1111. int enetInt (struct eth_device *dev)
  1112. {
  1113. int serviced;
  1114. int rc = -1; /* default to not us */
  1115. unsigned long mal_isr;
  1116. unsigned long emac_isr = 0;
  1117. unsigned long mal_rx_eob;
  1118. unsigned long my_uicmsr;
  1119. EMAC_4XX_HW_PST hw_p;
  1120. /*
  1121. * Because the mal is generic, we need to get the current
  1122. * eth device
  1123. */
  1124. #if defined(CONFIG_NET_MULTI)
  1125. dev = eth_get_dev();
  1126. #else
  1127. dev = emac0_dev;
  1128. #endif
  1129. hw_p = dev->priv;
  1130. /* enter loop that stays in interrupt code until nothing to service */
  1131. do {
  1132. serviced = 0;
  1133. my_uicmsr = mfdcr (uicmsr);
  1134. if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
  1135. return (rc);
  1136. }
  1137. /* get and clear controller status interrupts */
  1138. /* look at Mal and EMAC interrupts */
  1139. if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
  1140. mal_isr = mfdcr (malesr);
  1141. /* look for mal error */
  1142. if ((my_uicmsr & MAL_UIC_ERR) != 0) {
  1143. mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
  1144. serviced = 1;
  1145. rc = 0;
  1146. }
  1147. }
  1148. /* port by port dispatch of emac interrupts */
  1149. if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
  1150. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  1151. if ((hw_p->emac_ier & emac_isr) != 0) {
  1152. emac_err (dev, emac_isr);
  1153. serviced = 1;
  1154. rc = 0;
  1155. }
  1156. }
  1157. if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
  1158. mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
  1159. return (rc); /* we had errors so get out */
  1160. }
  1161. /* handle MAX TX EOB interrupt from a tx */
  1162. if (my_uicmsr & UIC_MAL_TXEOB) {
  1163. mal_rx_eob = mfdcr (maltxeobisr);
  1164. mtdcr (maltxeobisr, mal_rx_eob);
  1165. mtdcr (uicsr, UIC_MAL_TXEOB);
  1166. }
  1167. /* handle MAL RX EOB interupt from a receive */
  1168. /* check for EOB on valid channels */
  1169. if (my_uicmsr & UIC_MAL_RXEOB)
  1170. {
  1171. mal_rx_eob = mfdcr (malrxeobisr);
  1172. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  1173. /* clear EOB
  1174. mtdcr(malrxeobisr, mal_rx_eob); */
  1175. enet_rcv (dev, emac_isr);
  1176. /* indicate that we serviced an interrupt */
  1177. serviced = 1;
  1178. rc = 0;
  1179. }
  1180. }
  1181. mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
  1182. }
  1183. while (serviced);
  1184. return (rc);
  1185. }
  1186. #endif /* CONFIG_440 */
  1187. /*-----------------------------------------------------------------------------+
  1188. * MAL Error Routine
  1189. *-----------------------------------------------------------------------------*/
  1190. static void mal_err (struct eth_device *dev, unsigned long isr,
  1191. unsigned long uic, unsigned long maldef,
  1192. unsigned long mal_errr)
  1193. {
  1194. EMAC_4XX_HW_PST hw_p = dev->priv;
  1195. mtdcr (malesr, isr); /* clear interrupt */
  1196. /* clear DE interrupt */
  1197. mtdcr (maltxdeir, 0xC0000000);
  1198. mtdcr (malrxdeir, 0x80000000);
  1199. #ifdef INFO_4XX_ENET
  1200. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  1201. #endif
  1202. eth_init (hw_p->bis); /* start again... */
  1203. }
  1204. /*-----------------------------------------------------------------------------+
  1205. * EMAC Error Routine
  1206. *-----------------------------------------------------------------------------*/
  1207. static void emac_err (struct eth_device *dev, unsigned long isr)
  1208. {
  1209. EMAC_4XX_HW_PST hw_p = dev->priv;
  1210. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  1211. out32 (EMAC_ISR + hw_p->hw_addr, isr);
  1212. }
  1213. /*-----------------------------------------------------------------------------+
  1214. * enet_rcv() handles the ethernet receive data
  1215. *-----------------------------------------------------------------------------*/
  1216. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  1217. {
  1218. struct enet_frame *ef_ptr;
  1219. unsigned long data_len;
  1220. unsigned long rx_eob_isr;
  1221. EMAC_4XX_HW_PST hw_p = dev->priv;
  1222. int handled = 0;
  1223. int i;
  1224. int loop_count = 0;
  1225. rx_eob_isr = mfdcr (malrxeobisr);
  1226. if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
  1227. /* clear EOB */
  1228. mtdcr (malrxeobisr, rx_eob_isr);
  1229. /* EMAC RX done */
  1230. while (1) { /* do all */
  1231. i = hw_p->rx_slot;
  1232. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  1233. || (loop_count >= NUM_RX_BUFF))
  1234. break;
  1235. loop_count++;
  1236. hw_p->rx_slot++;
  1237. if (NUM_RX_BUFF == hw_p->rx_slot)
  1238. hw_p->rx_slot = 0;
  1239. handled++;
  1240. data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
  1241. if (data_len) {
  1242. if (data_len > ENET_MAX_MTU) /* Check len */
  1243. data_len = 0;
  1244. else {
  1245. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  1246. data_len = 0;
  1247. hw_p->stats.rx_err_log[hw_p->
  1248. rx_err_index]
  1249. = hw_p->rx[i].ctrl;
  1250. hw_p->rx_err_index++;
  1251. if (hw_p->rx_err_index ==
  1252. MAX_ERR_LOG)
  1253. hw_p->rx_err_index =
  1254. 0;
  1255. } /* emac_erros */
  1256. } /* data_len < max mtu */
  1257. } /* if data_len */
  1258. if (!data_len) { /* no data */
  1259. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  1260. hw_p->stats.data_len_err++; /* Error at Rx */
  1261. }
  1262. /* !data_len */
  1263. /* AS.HARNOIS */
  1264. /* Check if user has already eaten buffer */
  1265. /* if not => ERROR */
  1266. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  1267. if (hw_p->is_receiving)
  1268. printf ("ERROR : Receive buffers are full!\n");
  1269. break;
  1270. } else {
  1271. hw_p->stats.rx_frames++;
  1272. hw_p->stats.rx += data_len;
  1273. ef_ptr = (struct enet_frame *) hw_p->rx[i].
  1274. data_ptr;
  1275. #ifdef INFO_4XX_ENET
  1276. hw_p->stats.pkts_rx++;
  1277. #endif
  1278. /* AS.HARNOIS
  1279. * use ring buffer
  1280. */
  1281. hw_p->rx_ready[hw_p->rx_i_index] = i;
  1282. hw_p->rx_i_index++;
  1283. if (NUM_RX_BUFF == hw_p->rx_i_index)
  1284. hw_p->rx_i_index = 0;
  1285. /* AS.HARNOIS
  1286. * free receive buffer only when
  1287. * buffer has been handled (eth_rx)
  1288. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  1289. */
  1290. } /* if data_len */
  1291. } /* while */
  1292. } /* if EMACK_RXCHL */
  1293. }
  1294. static int ppc_4xx_eth_rx (struct eth_device *dev)
  1295. {
  1296. int length;
  1297. int user_index;
  1298. unsigned long msr;
  1299. EMAC_4XX_HW_PST hw_p = dev->priv;
  1300. hw_p->is_receiving = 1; /* tell driver */
  1301. for (;;) {
  1302. /* AS.HARNOIS
  1303. * use ring buffer and
  1304. * get index from rx buffer desciptor queue
  1305. */
  1306. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  1307. if (user_index == -1) {
  1308. length = -1;
  1309. break; /* nothing received - leave for() loop */
  1310. }
  1311. msr = mfmsr ();
  1312. mtmsr (msr & ~(MSR_EE));
  1313. length = hw_p->rx[user_index].data_len;
  1314. /* Pass the packet up to the protocol layers. */
  1315. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  1316. /* NetReceive(NetRxPackets[i], length); */
  1317. NetReceive (NetRxPackets[user_index], length - 4);
  1318. /* Free Recv Buffer */
  1319. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  1320. /* Free rx buffer descriptor queue */
  1321. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  1322. hw_p->rx_u_index++;
  1323. if (NUM_RX_BUFF == hw_p->rx_u_index)
  1324. hw_p->rx_u_index = 0;
  1325. #ifdef INFO_4XX_ENET
  1326. hw_p->stats.pkts_handled++;
  1327. #endif
  1328. mtmsr (msr); /* Enable IRQ's */
  1329. }
  1330. hw_p->is_receiving = 0; /* tell driver */
  1331. return length;
  1332. }
  1333. int ppc_4xx_eth_initialize (bd_t * bis)
  1334. {
  1335. static int virgin = 0;
  1336. struct eth_device *dev;
  1337. int eth_num = 0;
  1338. EMAC_4XX_HW_PST hw = NULL;
  1339. #if defined(CONFIG_440GX)
  1340. unsigned long pfc1;
  1341. mfsdr (sdr_pfc1, pfc1);
  1342. pfc1 &= ~(0x01e00000);
  1343. pfc1 |= 0x01200000;
  1344. mtsdr (sdr_pfc1, pfc1);
  1345. #endif
  1346. /* set phy num and mode */
  1347. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  1348. bis->bi_phymode[0] = 0;
  1349. #if defined(CONFIG_PHY1_ADDR)
  1350. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  1351. bis->bi_phymode[1] = 0;
  1352. #endif
  1353. #if defined(CONFIG_440GX)
  1354. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  1355. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  1356. bis->bi_phymode[2] = 2;
  1357. bis->bi_phymode[3] = 2;
  1358. ppc_4xx_eth_setup_bridge(0, bis);
  1359. #endif
  1360. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1361. /* See if we can actually bring up the interface, otherwise, skip it */
  1362. switch (eth_num) {
  1363. default: /* fall through */
  1364. case 0:
  1365. if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  1366. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1367. continue;
  1368. }
  1369. break;
  1370. #ifdef CONFIG_HAS_ETH1
  1371. case 1:
  1372. if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
  1373. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1374. continue;
  1375. }
  1376. break;
  1377. #endif
  1378. #ifdef CONFIG_HAS_ETH2
  1379. case 2:
  1380. if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
  1381. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1382. continue;
  1383. }
  1384. break;
  1385. #endif
  1386. #ifdef CONFIG_HAS_ETH3
  1387. case 3:
  1388. if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
  1389. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1390. continue;
  1391. }
  1392. break;
  1393. #endif
  1394. }
  1395. /* Allocate device structure */
  1396. dev = (struct eth_device *) malloc (sizeof (*dev));
  1397. if (dev == NULL) {
  1398. printf ("ppc_4xx_eth_initialize: "
  1399. "Cannot allocate eth_device %d\n", eth_num);
  1400. return (-1);
  1401. }
  1402. memset(dev, 0, sizeof(*dev));
  1403. /* Allocate our private use data */
  1404. hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
  1405. if (hw == NULL) {
  1406. printf ("ppc_4xx_eth_initialize: "
  1407. "Cannot allocate private hw data for eth_device %d",
  1408. eth_num);
  1409. free (dev);
  1410. return (-1);
  1411. }
  1412. memset(hw, 0, sizeof(*hw));
  1413. switch (eth_num) {
  1414. default: /* fall through */
  1415. case 0:
  1416. hw->hw_addr = 0;
  1417. memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
  1418. break;
  1419. #ifdef CONFIG_HAS_ETH1
  1420. case 1:
  1421. hw->hw_addr = 0x100;
  1422. memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
  1423. break;
  1424. #endif
  1425. #ifdef CONFIG_HAS_ETH2
  1426. case 2:
  1427. hw->hw_addr = 0x400;
  1428. memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
  1429. break;
  1430. #endif
  1431. #ifdef CONFIG_HAS_ETH3
  1432. case 3:
  1433. hw->hw_addr = 0x600;
  1434. memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
  1435. break;
  1436. #endif
  1437. }
  1438. hw->devnum = eth_num;
  1439. hw->print_speed = 1;
  1440. sprintf (dev->name, "ppc_4xx_eth%d", eth_num);
  1441. dev->priv = (void *) hw;
  1442. dev->init = ppc_4xx_eth_init;
  1443. dev->halt = ppc_4xx_eth_halt;
  1444. dev->send = ppc_4xx_eth_send;
  1445. dev->recv = ppc_4xx_eth_rx;
  1446. if (0 == virgin) {
  1447. /* set the MAL IER ??? names may change with new spec ??? */
  1448. #if defined(CONFIG_440SPE) || defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  1449. mal_ier =
  1450. MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
  1451. MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
  1452. #else
  1453. mal_ier =
  1454. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  1455. MAL_IER_OPBE | MAL_IER_PLBE;
  1456. #endif
  1457. mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
  1458. mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
  1459. mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
  1460. mtdcr (malier, mal_ier);
  1461. /* install MAL interrupt handler */
  1462. irq_install_handler (VECNUM_MS,
  1463. (interrupt_handler_t *) enetInt,
  1464. dev);
  1465. irq_install_handler (VECNUM_MTE,
  1466. (interrupt_handler_t *) enetInt,
  1467. dev);
  1468. irq_install_handler (VECNUM_MRE,
  1469. (interrupt_handler_t *) enetInt,
  1470. dev);
  1471. irq_install_handler (VECNUM_TXDE,
  1472. (interrupt_handler_t *) enetInt,
  1473. dev);
  1474. irq_install_handler (VECNUM_RXDE,
  1475. (interrupt_handler_t *) enetInt,
  1476. dev);
  1477. virgin = 1;
  1478. }
  1479. #if defined(CONFIG_NET_MULTI)
  1480. eth_register (dev);
  1481. #else
  1482. emac0_dev = dev;
  1483. #endif
  1484. #if defined(CONFIG_NET_MULTI)
  1485. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1486. miiphy_register (dev->name,
  1487. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1488. #endif
  1489. #endif
  1490. } /* end for each supported device */
  1491. return (1);
  1492. }
  1493. #if !defined(CONFIG_NET_MULTI)
  1494. void eth_halt (void) {
  1495. if (emac0_dev) {
  1496. ppc_4xx_eth_halt(emac0_dev);
  1497. free(emac0_dev);
  1498. emac0_dev = NULL;
  1499. }
  1500. }
  1501. int eth_init (bd_t *bis)
  1502. {
  1503. ppc_4xx_eth_initialize(bis);
  1504. if (emac0_dev) {
  1505. return ppc_4xx_eth_init(emac0_dev, bis);
  1506. } else {
  1507. printf("ERROR: ethaddr not set!\n");
  1508. return -1;
  1509. }
  1510. }
  1511. int eth_send(volatile void *packet, int length)
  1512. {
  1513. return (ppc_4xx_eth_send(emac0_dev, packet, length));
  1514. }
  1515. int eth_rx(void)
  1516. {
  1517. return (ppc_4xx_eth_rx(emac0_dev));
  1518. }
  1519. int emac4xx_miiphy_initialize (bd_t * bis)
  1520. {
  1521. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1522. miiphy_register ("ppc_4xx_eth0",
  1523. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1524. #endif
  1525. return 0;
  1526. }
  1527. #endif /* !defined(CONFIG_NET_MULTI) */
  1528. #endif /* #if (CONFIG_COMMANDS & CFG_CMD_NET) */