440gx_enet.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  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. *-----------------------------------------------------------------------------*/
  76. #include <config.h>
  77. #if defined(CONFIG_440) && defined(CONFIG_NET_MULTI)
  78. #include <common.h>
  79. #include <net.h>
  80. #include <asm/processor.h>
  81. #include <ppc440.h>
  82. #include <commproc.h>
  83. #include <440gx_enet.h>
  84. #include <405_mal.h>
  85. #include <miiphy.h>
  86. #include <malloc.h>
  87. #include "vecnum.h"
  88. #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
  89. #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
  90. /* Ethernet Transmit and Receive Buffers */
  91. /* AS.HARNOIS
  92. * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
  93. * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
  94. */
  95. #define ENET_MAX_MTU PKTSIZE
  96. #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
  97. /* define the number of channels implemented */
  98. #define EMAC_RXCHL EMAC_NUM_DEV
  99. #define EMAC_TXCHL EMAC_NUM_DEV
  100. /*-----------------------------------------------------------------------------+
  101. * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
  102. * Interrupt Controller).
  103. *-----------------------------------------------------------------------------*/
  104. #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
  105. #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
  106. #define EMAC_UIC_DEF UIC_ENET
  107. #undef INFO_440_ENET
  108. #define BI_PHYMODE_NONE 0
  109. #define BI_PHYMODE_ZMII 1
  110. #define BI_PHYMODE_RGMII 2
  111. /*-----------------------------------------------------------------------------+
  112. * Global variables. TX and RX descriptors and buffers.
  113. *-----------------------------------------------------------------------------*/
  114. /* IER globals */
  115. static uint32_t mal_ier;
  116. /*-----------------------------------------------------------------------------+
  117. * Prototypes and externals.
  118. *-----------------------------------------------------------------------------*/
  119. static void enet_rcv (struct eth_device *dev, unsigned long malisr);
  120. int enetInt (struct eth_device *dev);
  121. static void mal_err (struct eth_device *dev, unsigned long isr,
  122. unsigned long uic, unsigned long maldef,
  123. unsigned long mal_errr);
  124. static void emac_err (struct eth_device *dev, unsigned long isr);
  125. /*-----------------------------------------------------------------------------+
  126. | ppc_440x_eth_halt
  127. | Disable MAL channel, and EMACn
  128. |
  129. |
  130. +-----------------------------------------------------------------------------*/
  131. static void ppc_440x_eth_halt (struct eth_device *dev)
  132. {
  133. EMAC_440GX_HW_PST hw_p = dev->priv;
  134. uint32_t failsafe = 10000;
  135. out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
  136. /* 1st reset MAL channel */
  137. /* Note: writing a 0 to a channel has no effect */
  138. mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  139. mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  140. /* wait for reset */
  141. while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
  142. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  143. failsafe--;
  144. if (failsafe == 0)
  145. break;
  146. }
  147. /* EMAC RESET */
  148. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  149. hw_p->print_speed = 1; /* print speed message again next time */
  150. return;
  151. }
  152. extern int phy_setup_aneg (unsigned char addr);
  153. extern int miiphy_reset (unsigned char addr);
  154. static int ppc_440x_eth_init (struct eth_device *dev, bd_t * bis)
  155. {
  156. int i;
  157. unsigned long reg;
  158. unsigned long msr;
  159. unsigned long speed;
  160. unsigned long duplex;
  161. unsigned long failsafe;
  162. unsigned mode_reg;
  163. unsigned short devnum;
  164. unsigned short reg_short;
  165. sys_info_t sysinfo;
  166. EMAC_440GX_HW_PST hw_p = dev->priv;
  167. /* before doing anything, figure out if we have a MAC address */
  168. /* if not, bail */
  169. if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0)
  170. return -1;
  171. /* Need to get the OPB frequency so we can access the PHY */
  172. get_sys_info (&sysinfo);
  173. msr = mfmsr ();
  174. mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
  175. devnum = hw_p->devnum;
  176. #ifdef INFO_440_ENET
  177. /* AS.HARNOIS
  178. * We should have :
  179. * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
  180. * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
  181. * is possible that new packets (without relationship with
  182. * current transfer) have got the time to arrived before
  183. * netloop calls eth_halt
  184. */
  185. printf ("About preceeding transfer (eth%d):\n"
  186. "- Sent packet number %d\n"
  187. "- Received packet number %d\n"
  188. "- Handled packet number %d\n",
  189. hw_p->devnum,
  190. hw_p->stats.pkts_tx,
  191. hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
  192. hw_p->stats.pkts_tx = 0;
  193. hw_p->stats.pkts_rx = 0;
  194. hw_p->stats.pkts_handled = 0;
  195. #endif
  196. /* MAL Channel RESET */
  197. /* 1st reset MAL channel */
  198. /* Note: writing a 0 to a channel has no effect */
  199. mtdcr (maltxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
  200. mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
  201. /* wait for reset */
  202. /* TBS: should have udelay and failsafe here */
  203. failsafe = 10000;
  204. /* wait for reset */
  205. while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
  206. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  207. failsafe--;
  208. if (failsafe == 0)
  209. break;
  210. }
  211. hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
  212. hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
  213. hw_p->rx_slot = 0; /* MAL Receive Slot */
  214. hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
  215. hw_p->rx_u_index = 0; /* Receive User Queue Index */
  216. hw_p->tx_slot = 0; /* MAL Transmit Slot */
  217. hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
  218. hw_p->tx_u_index = 0; /* Transmit User Queue Index */
  219. /* set RMII mode */
  220. /* NOTE: 440GX spec states that mode is mutually exclusive */
  221. /* NOTE: Therefore, disable all other EMACS, since we handle */
  222. /* NOTE: only one emac at a time */
  223. reg = 0;
  224. out32 (ZMII_FER, 0);
  225. udelay (100);
  226. out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
  227. out32 (ZMII_SSR, 0x11110000);
  228. /* reset emac so we have access to the phy */
  229. __asm__ volatile ("eieio");
  230. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  231. __asm__ volatile ("eieio");
  232. if ((devnum == 2) || (devnum == 3))
  233. out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
  234. (RGMII_FER_RGMII << RGMII_FER_V (3))));
  235. __asm__ volatile ("eieio");
  236. failsafe = 1000;
  237. while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
  238. udelay (1000);
  239. failsafe--;
  240. }
  241. /* Whack the M1 register */
  242. mode_reg = 0x0;
  243. mode_reg &= ~0x00000038;
  244. if (sysinfo.freqOPB <= 50000000);
  245. else if (sysinfo.freqOPB <= 66666667)
  246. mode_reg |= EMAC_M1_OBCI_66;
  247. else if (sysinfo.freqOPB <= 83333333)
  248. mode_reg |= EMAC_M1_OBCI_83;
  249. else if (sysinfo.freqOPB <= 100000000)
  250. mode_reg |= EMAC_M1_OBCI_100;
  251. else
  252. mode_reg |= EMAC_M1_OBCI_GT100;
  253. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  254. /* wait for PHY to complete auto negotiation */
  255. reg_short = 0;
  256. #ifndef CONFIG_CS8952_PHY
  257. switch (devnum) {
  258. case 0:
  259. reg = CONFIG_PHY_ADDR;
  260. break;
  261. case 1:
  262. reg = CONFIG_PHY1_ADDR;
  263. break;
  264. #if defined (CONFIG_440_GX)
  265. case 2:
  266. reg = CONFIG_PHY2_ADDR;
  267. break;
  268. case 3:
  269. reg = CONFIG_PHY3_ADDR;
  270. break;
  271. #endif
  272. default:
  273. reg = CONFIG_PHY_ADDR;
  274. break;
  275. }
  276. bis->bi_phynum[devnum] = reg;
  277. /* Reset the phy */
  278. miiphy_reset (reg);
  279. /* Start/Restart autonegotiation */
  280. phy_setup_aneg (reg);
  281. udelay (1000);
  282. miiphy_read (reg, PHY_BMSR, &reg_short);
  283. /*
  284. * Wait if PHY is able of autonegotiation and autonegotiation is not complete
  285. */
  286. if ((reg_short & PHY_BMSR_AUTN_ABLE)
  287. && !(reg_short & PHY_BMSR_AUTN_COMP)) {
  288. puts ("Waiting for PHY auto negotiation to complete");
  289. i = 0;
  290. while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
  291. /*
  292. * Timeout reached ?
  293. */
  294. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  295. puts (" TIMEOUT !\n");
  296. break;
  297. }
  298. if ((i++ % 1000) == 0) {
  299. putc ('.');
  300. }
  301. udelay (1000); /* 1 ms */
  302. miiphy_read (reg, PHY_BMSR, &reg_short);
  303. }
  304. puts (" done\n");
  305. udelay (500000); /* another 500 ms (results in faster booting) */
  306. }
  307. #endif
  308. speed = miiphy_speed (reg);
  309. duplex = miiphy_duplex (reg);
  310. if (hw_p->print_speed) {
  311. hw_p->print_speed = 0;
  312. printf ("ENET Speed is %d Mbps - %s duplex connection\n",
  313. (int) speed, (duplex == HALF) ? "HALF" : "FULL");
  314. }
  315. /* Set ZMII/RGMII speed according to the phy link speed */
  316. reg = in32 (ZMII_SSR);
  317. if (speed == 100)
  318. out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
  319. else
  320. out32 (ZMII_SSR,
  321. reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
  322. if ((devnum == 2) || (devnum == 3)) {
  323. if (speed == 1000)
  324. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  325. else if (speed == 100)
  326. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  327. else
  328. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  329. out32 (RGMII_SSR, reg);
  330. }
  331. /* set the Mal configuration reg */
  332. /* Errata 1.12: MAL_1 -- Disable MAL bursting */
  333. if (get_pvr () == PVR_440GP_RB)
  334. mtdcr (malmcr,
  335. MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
  336. else
  337. mtdcr (malmcr,
  338. MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
  339. MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
  340. /* Free "old" buffers */
  341. if (hw_p->alloc_tx_buf)
  342. free (hw_p->alloc_tx_buf);
  343. if (hw_p->alloc_rx_buf)
  344. free (hw_p->alloc_rx_buf);
  345. /*
  346. * Malloc MAL buffer desciptors, make sure they are
  347. * aligned on cache line boundary size
  348. * (401/403/IOP480 = 16, 405 = 32)
  349. * and doesn't cross cache block boundaries.
  350. */
  351. hw_p->alloc_tx_buf =
  352. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
  353. ((2 * CFG_CACHELINE_SIZE) - 2));
  354. if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
  355. hw_p->tx =
  356. (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
  357. CFG_CACHELINE_SIZE -
  358. ((int) hw_p->
  359. alloc_tx_buf & CACHELINE_MASK));
  360. } else {
  361. hw_p->tx = hw_p->alloc_tx_buf;
  362. }
  363. hw_p->alloc_rx_buf =
  364. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
  365. ((2 * CFG_CACHELINE_SIZE) - 2));
  366. if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
  367. hw_p->rx =
  368. (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
  369. CFG_CACHELINE_SIZE -
  370. ((int) hw_p->
  371. alloc_rx_buf & CACHELINE_MASK));
  372. } else {
  373. hw_p->rx = hw_p->alloc_rx_buf;
  374. }
  375. for (i = 0; i < NUM_TX_BUFF; i++) {
  376. hw_p->tx[i].ctrl = 0;
  377. hw_p->tx[i].data_len = 0;
  378. if (hw_p->first_init == 0)
  379. hw_p->txbuf_ptr =
  380. (char *) malloc (ENET_MAX_MTU_ALIGNED);
  381. hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
  382. if ((NUM_TX_BUFF - 1) == i)
  383. hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
  384. hw_p->tx_run[i] = -1;
  385. #if 0
  386. printf ("TX_BUFF %d @ 0x%08lx\n", i,
  387. (ulong) hw_p->tx[i].data_ptr);
  388. #endif
  389. }
  390. for (i = 0; i < NUM_RX_BUFF; i++) {
  391. hw_p->rx[i].ctrl = 0;
  392. hw_p->rx[i].data_len = 0;
  393. /* rx[i].data_ptr = (char *) &rx_buff[i]; */
  394. hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
  395. if ((NUM_RX_BUFF - 1) == i)
  396. hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
  397. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
  398. hw_p->rx_ready[i] = -1;
  399. #if 0
  400. printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
  401. #endif
  402. }
  403. reg = 0x00000000;
  404. reg |= dev->enetaddr[0]; /* set high address */
  405. reg = reg << 8;
  406. reg |= dev->enetaddr[1];
  407. out32 (EMAC_IAH + hw_p->hw_addr, reg);
  408. reg = 0x00000000;
  409. reg |= dev->enetaddr[2]; /* set low address */
  410. reg = reg << 8;
  411. reg |= dev->enetaddr[3];
  412. reg = reg << 8;
  413. reg |= dev->enetaddr[4];
  414. reg = reg << 8;
  415. reg |= dev->enetaddr[5];
  416. out32 (EMAC_IAL + hw_p->hw_addr, reg);
  417. switch (devnum) {
  418. case 1:
  419. /* setup MAL tx & rx channel pointers */
  420. mtdcr (maltxbattr, 0x0);
  421. mtdcr (maltxctp1r, hw_p->tx);
  422. mtdcr (malrxbattr, 0x0);
  423. mtdcr (malrxctp1r, hw_p->rx);
  424. /* set RX buffer size */
  425. mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
  426. break;
  427. #if defined (CONFIG_440_GX)
  428. case 2:
  429. /* setup MAL tx & rx channel pointers */
  430. mtdcr (maltxbattr, 0x0);
  431. mtdcr (maltxctp2r, hw_p->tx);
  432. mtdcr (malrxbattr, 0x0);
  433. mtdcr (malrxctp2r, hw_p->rx);
  434. /* set RX buffer size */
  435. mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
  436. break;
  437. case 3:
  438. /* setup MAL tx & rx channel pointers */
  439. mtdcr (maltxbattr, 0x0);
  440. mtdcr (maltxctp3r, hw_p->tx);
  441. mtdcr (malrxbattr, 0x0);
  442. mtdcr (malrxctp3r, hw_p->rx);
  443. /* set RX buffer size */
  444. mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
  445. break;
  446. #endif /*CONFIG_440_GX */
  447. case 0:
  448. default:
  449. /* setup MAL tx & rx channel pointers */
  450. mtdcr (maltxbattr, 0x0);
  451. mtdcr (maltxctp0r, hw_p->tx);
  452. mtdcr (malrxbattr, 0x0);
  453. mtdcr (malrxctp0r, hw_p->rx);
  454. /* set RX buffer size */
  455. mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
  456. break;
  457. }
  458. /* Enable MAL transmit and receive channels */
  459. mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  460. mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  461. /* set transmit enable & receive enable */
  462. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
  463. /* set receive fifo to 4k and tx fifo to 2k */
  464. mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
  465. mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
  466. /* set speed */
  467. /* TBS: do 1GbE */
  468. if (speed == _100BASET)
  469. mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
  470. else
  471. mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
  472. if (duplex == FULL)
  473. mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
  474. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  475. /* Enable broadcast and indvidual address */
  476. /* TBS: enabling runts as some misbehaved nics will send runts */
  477. out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
  478. /* we probably need to set the tx mode1 reg? maybe at tx time */
  479. /* set transmit request threshold register */
  480. out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
  481. /* set receive low/high water mark register */
  482. /* 440GP has a 64 byte burst length */
  483. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
  484. out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
  485. /* Set fifo limit entry in tx mode 0 */
  486. out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
  487. /* Frame gap set */
  488. out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
  489. /* Set EMAC IER */
  490. hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS |
  491. EMAC_ISR_PTLE | EMAC_ISR_ORE | EMAC_ISR_IRE;
  492. if (speed == _100BASET)
  493. hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
  494. out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
  495. out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
  496. if (hw_p->first_init == 0) {
  497. /*
  498. * Connect interrupt service routines
  499. */
  500. irq_install_handler (VECNUM_EWU0 + (hw_p->devnum * 2),
  501. (interrupt_handler_t *) enetInt, dev);
  502. irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
  503. (interrupt_handler_t *) enetInt, dev);
  504. }
  505. mtmsr (msr); /* enable interrupts again */
  506. hw_p->bis = bis;
  507. hw_p->first_init = 1;
  508. return (1);
  509. }
  510. static int ppc_440x_eth_send (struct eth_device *dev, volatile void *ptr,
  511. int len)
  512. {
  513. struct enet_frame *ef_ptr;
  514. ulong time_start, time_now;
  515. unsigned long temp_txm0;
  516. EMAC_440GX_HW_PST hw_p = dev->priv;
  517. ef_ptr = (struct enet_frame *) ptr;
  518. /*-----------------------------------------------------------------------+
  519. * Copy in our address into the frame.
  520. *-----------------------------------------------------------------------*/
  521. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  522. /*-----------------------------------------------------------------------+
  523. * If frame is too long or too short, modify length.
  524. *-----------------------------------------------------------------------*/
  525. /* TBS: where does the fragment go???? */
  526. if (len > ENET_MAX_MTU)
  527. len = ENET_MAX_MTU;
  528. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  529. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  530. /*-----------------------------------------------------------------------+
  531. * set TX Buffer busy, and send it
  532. *-----------------------------------------------------------------------*/
  533. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  534. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  535. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  536. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  537. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  538. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  539. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  540. __asm__ volatile ("eieio");
  541. out32 (EMAC_TXM0 + hw_p->hw_addr,
  542. in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
  543. #ifdef INFO_440_ENET
  544. hw_p->stats.pkts_tx++;
  545. #endif
  546. /*-----------------------------------------------------------------------+
  547. * poll unitl the packet is sent and then make sure it is OK
  548. *-----------------------------------------------------------------------*/
  549. time_start = get_timer (0);
  550. while (1) {
  551. temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
  552. /* loop until either TINT turns on or 3 seconds elapse */
  553. if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
  554. /* transmit is done, so now check for errors
  555. * If there is an error, an interrupt should
  556. * happen when we return
  557. */
  558. time_now = get_timer (0);
  559. if ((time_now - time_start) > 3000) {
  560. return (-1);
  561. }
  562. } else {
  563. return (len);
  564. }
  565. }
  566. }
  567. int enetInt (struct eth_device *dev)
  568. {
  569. int serviced;
  570. int rc = -1; /* default to not us */
  571. unsigned long mal_isr;
  572. unsigned long emac_isr = 0;
  573. unsigned long mal_rx_eob;
  574. unsigned long my_uic0msr, my_uic1msr;
  575. #if defined(CONFIG_440_GX)
  576. unsigned long my_uic2msr;
  577. #endif
  578. EMAC_440GX_HW_PST hw_p;
  579. /*
  580. * Because the mal is generic, we need to get the current
  581. * eth device
  582. */
  583. dev = eth_get_dev ();
  584. hw_p = dev->priv;
  585. /* enter loop that stays in interrupt code until nothing to service */
  586. do {
  587. serviced = 0;
  588. my_uic0msr = mfdcr (uic0msr);
  589. my_uic1msr = mfdcr (uic1msr);
  590. #if defined(CONFIG_440_GX)
  591. my_uic2msr = mfdcr (uic2msr);
  592. #endif
  593. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  594. && !(my_uic1msr &
  595. (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE |
  596. UIC_MRDE))) {
  597. /* not for us */
  598. return (rc);
  599. }
  600. #if defined (CONFIG_440_GX)
  601. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  602. && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
  603. /* not for us */
  604. return (rc);
  605. }
  606. #endif
  607. /* get and clear controller status interrupts */
  608. /* look at Mal and EMAC interrupts */
  609. if ((my_uic0msr & (UIC_MRE | UIC_MTE))
  610. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  611. /* we have a MAL interrupt */
  612. mal_isr = mfdcr (malesr);
  613. /* look for mal error */
  614. if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
  615. mal_err (dev, mal_isr, my_uic0msr,
  616. MAL_UIC_DEF, MAL_UIC_ERR);
  617. serviced = 1;
  618. rc = 0;
  619. }
  620. }
  621. /* port by port dispatch of emac interrupts */
  622. if (hw_p->devnum == 0) {
  623. if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
  624. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  625. if ((hw_p->emac_ier & emac_isr) != 0) {
  626. emac_err (dev, emac_isr);
  627. serviced = 1;
  628. rc = 0;
  629. }
  630. }
  631. if ((hw_p->emac_ier & emac_isr)
  632. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  633. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  634. mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  635. return (rc); /* we had errors so get out */
  636. }
  637. }
  638. if (hw_p->devnum == 1) {
  639. if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
  640. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  641. if ((hw_p->emac_ier & emac_isr) != 0) {
  642. emac_err (dev, emac_isr);
  643. serviced = 1;
  644. rc = 0;
  645. }
  646. }
  647. if ((hw_p->emac_ier & emac_isr)
  648. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  649. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  650. mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  651. return (rc); /* we had errors so get out */
  652. }
  653. }
  654. #if defined (CONFIG_440_GX)
  655. if (hw_p->devnum == 2) {
  656. if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
  657. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  658. if ((hw_p->emac_ier & emac_isr) != 0) {
  659. emac_err (dev, emac_isr);
  660. serviced = 1;
  661. rc = 0;
  662. }
  663. }
  664. if ((hw_p->emac_ier & emac_isr)
  665. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  666. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  667. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  668. mtdcr (uic2sr, UIC_ETH2);
  669. return (rc); /* we had errors so get out */
  670. }
  671. }
  672. if (hw_p->devnum == 3) {
  673. if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
  674. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  675. if ((hw_p->emac_ier & emac_isr) != 0) {
  676. emac_err (dev, emac_isr);
  677. serviced = 1;
  678. rc = 0;
  679. }
  680. }
  681. if ((hw_p->emac_ier & emac_isr)
  682. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  683. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  684. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  685. mtdcr (uic2sr, UIC_ETH3);
  686. return (rc); /* we had errors so get out */
  687. }
  688. }
  689. #endif /* CONFIG_440_GX */
  690. /* handle MAX TX EOB interrupt from a tx */
  691. if (my_uic0msr & UIC_MTE) {
  692. mal_rx_eob = mfdcr (maltxeobisr);
  693. mtdcr (maltxeobisr, mal_rx_eob);
  694. mtdcr (uic0sr, UIC_MTE);
  695. }
  696. /* handle MAL RX EOB interupt from a receive */
  697. /* check for EOB on valid channels */
  698. if (my_uic0msr & UIC_MRE) {
  699. mal_rx_eob = mfdcr (malrxeobisr);
  700. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  701. /* clear EOB
  702. mtdcr(malrxeobisr, mal_rx_eob); */
  703. enet_rcv (dev, emac_isr);
  704. /* indicate that we serviced an interrupt */
  705. serviced = 1;
  706. rc = 0;
  707. }
  708. }
  709. mtdcr (uic0sr, UIC_MRE); /* Clear */
  710. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  711. switch (hw_p->devnum) {
  712. case 0:
  713. mtdcr (uic1sr, UIC_ETH0);
  714. break;
  715. case 1:
  716. mtdcr (uic1sr, UIC_ETH1);
  717. break;
  718. #if defined (CONFIG_440_GX)
  719. case 2:
  720. mtdcr (uic2sr, UIC_ETH2);
  721. break;
  722. case 3:
  723. mtdcr (uic2sr, UIC_ETH3);
  724. break;
  725. #endif /* CONFIG_440_GX */
  726. default:
  727. break;
  728. }
  729. } while (serviced);
  730. return (rc);
  731. }
  732. /*-----------------------------------------------------------------------------+
  733. * MAL Error Routine
  734. *-----------------------------------------------------------------------------*/
  735. static void mal_err (struct eth_device *dev, unsigned long isr,
  736. unsigned long uic, unsigned long maldef,
  737. unsigned long mal_errr)
  738. {
  739. EMAC_440GX_HW_PST hw_p = dev->priv;
  740. mtdcr (malesr, isr); /* clear interrupt */
  741. /* clear DE interrupt */
  742. mtdcr (maltxdeir, 0xC0000000);
  743. mtdcr (malrxdeir, 0x80000000);
  744. #ifdef INFO_440_ENET
  745. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  746. #endif
  747. eth_init (hw_p->bis); /* start again... */
  748. }
  749. /*-----------------------------------------------------------------------------+
  750. * EMAC Error Routine
  751. *-----------------------------------------------------------------------------*/
  752. static void emac_err (struct eth_device *dev, unsigned long isr)
  753. {
  754. EMAC_440GX_HW_PST hw_p = dev->priv;
  755. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  756. out32 (EMAC_ISR + hw_p->hw_addr, isr);
  757. }
  758. /*-----------------------------------------------------------------------------+
  759. * enet_rcv() handles the ethernet receive data
  760. *-----------------------------------------------------------------------------*/
  761. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  762. {
  763. struct enet_frame *ef_ptr;
  764. unsigned long data_len;
  765. unsigned long rx_eob_isr;
  766. EMAC_440GX_HW_PST hw_p = dev->priv;
  767. int handled = 0;
  768. int i;
  769. int loop_count = 0;
  770. rx_eob_isr = mfdcr (malrxeobisr);
  771. if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
  772. /* clear EOB */
  773. mtdcr (malrxeobisr, rx_eob_isr);
  774. /* EMAC RX done */
  775. while (1) { /* do all */
  776. i = hw_p->rx_slot;
  777. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  778. || (loop_count >= NUM_RX_BUFF))
  779. break;
  780. loop_count++;
  781. hw_p->rx_slot++;
  782. if (NUM_RX_BUFF == hw_p->rx_slot)
  783. hw_p->rx_slot = 0;
  784. handled++;
  785. data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
  786. if (data_len) {
  787. if (data_len > ENET_MAX_MTU) /* Check len */
  788. data_len = 0;
  789. else {
  790. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  791. data_len = 0;
  792. hw_p->stats.rx_err_log[hw_p->
  793. rx_err_index]
  794. = hw_p->rx[i].ctrl;
  795. hw_p->rx_err_index++;
  796. if (hw_p->rx_err_index ==
  797. MAX_ERR_LOG)
  798. hw_p->rx_err_index =
  799. 0;
  800. } /* emac_erros */
  801. } /* data_len < max mtu */
  802. } /* if data_len */
  803. if (!data_len) { /* no data */
  804. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  805. hw_p->stats.data_len_err++; /* Error at Rx */
  806. }
  807. /* !data_len */
  808. /* AS.HARNOIS */
  809. /* Check if user has already eaten buffer */
  810. /* if not => ERROR */
  811. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  812. if (hw_p->is_receiving)
  813. printf ("ERROR : Receive buffers are full!\n");
  814. break;
  815. } else {
  816. hw_p->stats.rx_frames++;
  817. hw_p->stats.rx += data_len;
  818. ef_ptr = (struct enet_frame *) hw_p->rx[i].
  819. data_ptr;
  820. #ifdef INFO_440_ENET
  821. hw_p->stats.pkts_rx++;
  822. #endif
  823. /* AS.HARNOIS
  824. * use ring buffer
  825. */
  826. hw_p->rx_ready[hw_p->rx_i_index] = i;
  827. hw_p->rx_i_index++;
  828. if (NUM_RX_BUFF == hw_p->rx_i_index)
  829. hw_p->rx_i_index = 0;
  830. /* printf("X"); /|* test-only *|/ */
  831. /* AS.HARNOIS
  832. * free receive buffer only when
  833. * buffer has been handled (eth_rx)
  834. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  835. */
  836. } /* if data_len */
  837. } /* while */
  838. } /* if EMACK_RXCHL */
  839. }
  840. static int ppc_440x_eth_rx (struct eth_device *dev)
  841. {
  842. int length;
  843. int user_index;
  844. unsigned long msr;
  845. EMAC_440GX_HW_PST hw_p = dev->priv;
  846. hw_p->is_receiving = 1; /* tell driver */
  847. for (;;) {
  848. /* AS.HARNOIS
  849. * use ring buffer and
  850. * get index from rx buffer desciptor queue
  851. */
  852. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  853. if (user_index == -1) {
  854. length = -1;
  855. break; /* nothing received - leave for() loop */
  856. }
  857. msr = mfmsr ();
  858. mtmsr (msr & ~(MSR_EE));
  859. length = hw_p->rx[user_index].data_len;
  860. /* Pass the packet up to the protocol layers. */
  861. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  862. /* NetReceive(NetRxPackets[i], length); */
  863. NetReceive (NetRxPackets[user_index], length - 4);
  864. /* Free Recv Buffer */
  865. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  866. /* Free rx buffer descriptor queue */
  867. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  868. hw_p->rx_u_index++;
  869. if (NUM_RX_BUFF == hw_p->rx_u_index)
  870. hw_p->rx_u_index = 0;
  871. #ifdef INFO_440_ENET
  872. hw_p->stats.pkts_handled++;
  873. #endif
  874. mtmsr (msr); /* Enable IRQ's */
  875. }
  876. hw_p->is_receiving = 0; /* tell driver */
  877. return length;
  878. }
  879. int ppc_440x_eth_initialize (bd_t * bis)
  880. {
  881. static int virgin = 0;
  882. unsigned long pfc1;
  883. struct eth_device *dev;
  884. int eth_num = 0;
  885. EMAC_440GX_HW_PST hw = NULL;
  886. mfsdr (sdr_pfc1, pfc1);
  887. pfc1 &= ~(0x01e00000);
  888. pfc1 |= 0x01200000;
  889. mtsdr (sdr_pfc1, pfc1);
  890. /* set phy num and mode */
  891. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  892. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  893. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  894. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  895. bis->bi_phymode[0] = 0;
  896. bis->bi_phymode[1] = 0;
  897. bis->bi_phymode[2] = 2;
  898. bis->bi_phymode[3] = 2;
  899. for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) {
  900. /* See if we can actually bring up the interface, otherwise, skip it */
  901. switch (eth_num) {
  902. case 0:
  903. if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  904. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  905. continue;
  906. }
  907. break;
  908. case 1:
  909. if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
  910. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  911. continue;
  912. }
  913. break;
  914. case 2:
  915. if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
  916. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  917. continue;
  918. }
  919. break;
  920. case 3:
  921. if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
  922. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  923. continue;
  924. }
  925. break;
  926. default:
  927. if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  928. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  929. continue;
  930. }
  931. break;
  932. }
  933. /* Allocate device structure */
  934. dev = (struct eth_device *) malloc (sizeof (*dev));
  935. if (dev == NULL) {
  936. printf (__FUNCTION__
  937. ": Cannot allocate eth_device %d\n", eth_num);
  938. return (-1);
  939. }
  940. /* Allocate our private use data */
  941. hw = (EMAC_440GX_HW_PST) malloc (sizeof (*hw));
  942. if (hw == NULL) {
  943. printf (__FUNCTION__
  944. ": Cannot allocate private hw data for eth_device %d",
  945. eth_num);
  946. free (dev);
  947. return (-1);
  948. }
  949. switch (eth_num) {
  950. case 0:
  951. hw->hw_addr = 0;
  952. memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
  953. break;
  954. case 1:
  955. hw->hw_addr = 0x100;
  956. memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
  957. break;
  958. case 2:
  959. hw->hw_addr = 0x400;
  960. memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
  961. break;
  962. case 3:
  963. hw->hw_addr = 0x600;
  964. memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
  965. break;
  966. default:
  967. hw->hw_addr = 0;
  968. memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
  969. break;
  970. }
  971. hw->devnum = eth_num;
  972. sprintf (dev->name, "ppc_440x_eth%d", eth_num);
  973. dev->priv = (void *) hw;
  974. dev->init = ppc_440x_eth_init;
  975. dev->halt = ppc_440x_eth_halt;
  976. dev->send = ppc_440x_eth_send;
  977. dev->recv = ppc_440x_eth_rx;
  978. if (0 == virgin) {
  979. /* set the MAL IER ??? names may change with new spec ??? */
  980. mal_ier =
  981. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  982. MAL_IER_OPBE | MAL_IER_PLBE;
  983. mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
  984. mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
  985. mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
  986. mtdcr (malier, mal_ier);
  987. /* install MAL interrupt handler */
  988. irq_install_handler (VECNUM_MS,
  989. (interrupt_handler_t *) enetInt,
  990. dev);
  991. irq_install_handler (VECNUM_MTE,
  992. (interrupt_handler_t *) enetInt,
  993. dev);
  994. irq_install_handler (VECNUM_MRE,
  995. (interrupt_handler_t *) enetInt,
  996. dev);
  997. irq_install_handler (VECNUM_TXDE,
  998. (interrupt_handler_t *) enetInt,
  999. dev);
  1000. irq_install_handler (VECNUM_RXDE,
  1001. (interrupt_handler_t *) enetInt,
  1002. dev);
  1003. virgin = 1;
  1004. }
  1005. eth_register (dev);
  1006. } /* end for each supported device */
  1007. return (1);
  1008. }
  1009. #endif /* CONFIG_440 && CONFIG_NET_MULTI */