4xx_enet.c 45 KB

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