440gx_enet.c 33 KB

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