4xx_enet.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606
  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. miiphy_reset (dev->name, reg);
  447. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  448. #if defined(CONFIG_CIS8201_PHY)
  449. /*
  450. * Cicada 8201 PHY needs to have an extended register whacked
  451. * for RGMII mode.
  452. */
  453. if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) {
  454. #if defined(CONFIG_CIS8201_SHORT_ETCH)
  455. miiphy_write (dev->name, reg, 23, 0x1300);
  456. #else
  457. miiphy_write (dev->name, reg, 23, 0x1000);
  458. #endif
  459. /*
  460. * Vitesse VSC8201/Cicada CIS8201 errata:
  461. * Interoperability problem with Intel 82547EI phys
  462. * This work around (provided by Vitesse) changes
  463. * the default timer convergence from 8ms to 12ms
  464. */
  465. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  466. miiphy_write (dev->name, reg, 0x08, 0x0200);
  467. miiphy_write (dev->name, reg, 0x1f, 0x52b5);
  468. miiphy_write (dev->name, reg, 0x02, 0x0004);
  469. miiphy_write (dev->name, reg, 0x01, 0x0671);
  470. miiphy_write (dev->name, reg, 0x00, 0x8fae);
  471. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  472. miiphy_write (dev->name, reg, 0x08, 0x0000);
  473. miiphy_write (dev->name, reg, 0x1f, 0x0000);
  474. /* end Vitesse/Cicada errata */
  475. }
  476. #endif
  477. #endif
  478. /* Start/Restart autonegotiation */
  479. phy_setup_aneg (dev->name, reg);
  480. udelay (1000);
  481. }
  482. #endif /* defined(CONFIG_PHY_RESET) */
  483. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  484. /*
  485. * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
  486. */
  487. if ((reg_short & PHY_BMSR_AUTN_ABLE)
  488. && !(reg_short & PHY_BMSR_AUTN_COMP)) {
  489. puts ("Waiting for PHY auto negotiation to complete");
  490. i = 0;
  491. while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
  492. /*
  493. * Timeout reached ?
  494. */
  495. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  496. puts (" TIMEOUT !\n");
  497. break;
  498. }
  499. if ((i++ % 1000) == 0) {
  500. putc ('.');
  501. }
  502. udelay (1000); /* 1 ms */
  503. miiphy_read (dev->name, reg, PHY_BMSR, &reg_short);
  504. }
  505. puts (" done\n");
  506. udelay (500000); /* another 500 ms (results in faster booting) */
  507. }
  508. #endif /* #ifndef CONFIG_CS8952_PHY */
  509. speed = miiphy_speed (dev->name, reg);
  510. duplex = miiphy_duplex (dev->name, reg);
  511. if (hw_p->print_speed) {
  512. hw_p->print_speed = 0;
  513. printf ("ENET Speed is %d Mbps - %s duplex connection\n",
  514. (int) speed, (duplex == HALF) ? "HALF" : "FULL");
  515. }
  516. #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
  517. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  518. mfsdr(sdr_mfr, reg);
  519. if (speed == 100) {
  520. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
  521. } else {
  522. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
  523. }
  524. mtsdr(sdr_mfr, reg);
  525. #endif
  526. /* Set ZMII/RGMII speed according to the phy link speed */
  527. reg = in32 (ZMII_SSR);
  528. if ( (speed == 100) || (speed == 1000) )
  529. out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
  530. else
  531. out32 (ZMII_SSR, reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
  532. if ((devnum == 2) || (devnum == 3)) {
  533. if (speed == 1000)
  534. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  535. else if (speed == 100)
  536. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  537. else
  538. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  539. out32 (RGMII_SSR, reg);
  540. }
  541. #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
  542. /* set the Mal configuration reg */
  543. #if defined(CONFIG_440GX) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  544. mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
  545. MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
  546. #else
  547. mtdcr (malmcr, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
  548. /* Errata 1.12: MAL_1 -- Disable MAL bursting */
  549. if (get_pvr() == PVR_440GP_RB) {
  550. mtdcr (malmcr, mfdcr(malmcr) & ~MAL_CR_PLBB);
  551. }
  552. #endif
  553. /* Free "old" buffers */
  554. if (hw_p->alloc_tx_buf)
  555. free (hw_p->alloc_tx_buf);
  556. if (hw_p->alloc_rx_buf)
  557. free (hw_p->alloc_rx_buf);
  558. /*
  559. * Malloc MAL buffer desciptors, make sure they are
  560. * aligned on cache line boundary size
  561. * (401/403/IOP480 = 16, 405 = 32)
  562. * and doesn't cross cache block boundaries.
  563. */
  564. hw_p->alloc_tx_buf =
  565. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
  566. ((2 * CFG_CACHELINE_SIZE) - 2));
  567. if (NULL == hw_p->alloc_tx_buf)
  568. return -1;
  569. if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
  570. hw_p->tx =
  571. (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
  572. CFG_CACHELINE_SIZE -
  573. ((int) hw_p->
  574. alloc_tx_buf & CACHELINE_MASK));
  575. } else {
  576. hw_p->tx = hw_p->alloc_tx_buf;
  577. }
  578. hw_p->alloc_rx_buf =
  579. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
  580. ((2 * CFG_CACHELINE_SIZE) - 2));
  581. if (NULL == hw_p->alloc_rx_buf) {
  582. free(hw_p->alloc_tx_buf);
  583. hw_p->alloc_tx_buf = NULL;
  584. return -1;
  585. }
  586. if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
  587. hw_p->rx =
  588. (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
  589. CFG_CACHELINE_SIZE -
  590. ((int) hw_p->
  591. alloc_rx_buf & CACHELINE_MASK));
  592. } else {
  593. hw_p->rx = hw_p->alloc_rx_buf;
  594. }
  595. for (i = 0; i < NUM_TX_BUFF; i++) {
  596. hw_p->tx[i].ctrl = 0;
  597. hw_p->tx[i].data_len = 0;
  598. if (hw_p->first_init == 0) {
  599. hw_p->txbuf_ptr =
  600. (char *) malloc (ENET_MAX_MTU_ALIGNED);
  601. if (NULL == hw_p->txbuf_ptr) {
  602. free(hw_p->alloc_rx_buf);
  603. free(hw_p->alloc_tx_buf);
  604. hw_p->alloc_rx_buf = NULL;
  605. hw_p->alloc_tx_buf = NULL;
  606. for(j = 0; j < i; j++) {
  607. free(hw_p->tx[i].data_ptr);
  608. hw_p->tx[i].data_ptr = NULL;
  609. }
  610. }
  611. }
  612. hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
  613. if ((NUM_TX_BUFF - 1) == i)
  614. hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
  615. hw_p->tx_run[i] = -1;
  616. #if 0
  617. printf ("TX_BUFF %d @ 0x%08lx\n", i,
  618. (ulong) hw_p->tx[i].data_ptr);
  619. #endif
  620. }
  621. for (i = 0; i < NUM_RX_BUFF; i++) {
  622. hw_p->rx[i].ctrl = 0;
  623. hw_p->rx[i].data_len = 0;
  624. /* rx[i].data_ptr = (char *) &rx_buff[i]; */
  625. hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
  626. if ((NUM_RX_BUFF - 1) == i)
  627. hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
  628. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
  629. hw_p->rx_ready[i] = -1;
  630. #if 0
  631. printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
  632. #endif
  633. }
  634. reg = 0x00000000;
  635. reg |= dev->enetaddr[0]; /* set high address */
  636. reg = reg << 8;
  637. reg |= dev->enetaddr[1];
  638. out32 (EMAC_IAH + hw_p->hw_addr, reg);
  639. reg = 0x00000000;
  640. reg |= dev->enetaddr[2]; /* set low address */
  641. reg = reg << 8;
  642. reg |= dev->enetaddr[3];
  643. reg = reg << 8;
  644. reg |= dev->enetaddr[4];
  645. reg = reg << 8;
  646. reg |= dev->enetaddr[5];
  647. out32 (EMAC_IAL + hw_p->hw_addr, reg);
  648. switch (devnum) {
  649. case 1:
  650. /* setup MAL tx & rx channel pointers */
  651. #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
  652. mtdcr (maltxctp2r, hw_p->tx);
  653. #else
  654. mtdcr (maltxctp1r, hw_p->tx);
  655. #endif
  656. #if defined(CONFIG_440)
  657. mtdcr (maltxbattr, 0x0);
  658. mtdcr (malrxbattr, 0x0);
  659. #endif
  660. mtdcr (malrxctp1r, hw_p->rx);
  661. /* set RX buffer size */
  662. mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
  663. break;
  664. #if defined (CONFIG_440GX)
  665. case 2:
  666. /* setup MAL tx & rx channel pointers */
  667. mtdcr (maltxbattr, 0x0);
  668. mtdcr (malrxbattr, 0x0);
  669. mtdcr (maltxctp2r, hw_p->tx);
  670. mtdcr (malrxctp2r, hw_p->rx);
  671. /* set RX buffer size */
  672. mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
  673. break;
  674. case 3:
  675. /* setup MAL tx & rx channel pointers */
  676. mtdcr (maltxbattr, 0x0);
  677. mtdcr (maltxctp3r, hw_p->tx);
  678. mtdcr (malrxbattr, 0x0);
  679. mtdcr (malrxctp3r, hw_p->rx);
  680. /* set RX buffer size */
  681. mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
  682. break;
  683. #endif /* CONFIG_440GX */
  684. case 0:
  685. default:
  686. /* setup MAL tx & rx channel pointers */
  687. #if defined(CONFIG_440)
  688. mtdcr (maltxbattr, 0x0);
  689. mtdcr (malrxbattr, 0x0);
  690. #endif
  691. mtdcr (maltxctp0r, hw_p->tx);
  692. mtdcr (malrxctp0r, hw_p->rx);
  693. /* set RX buffer size */
  694. mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
  695. break;
  696. }
  697. /* Enable MAL transmit and receive channels */
  698. #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  699. mtdcr (maltxcasr, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
  700. #else
  701. mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  702. #endif
  703. mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  704. /* set transmit enable & receive enable */
  705. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
  706. /* set receive fifo to 4k and tx fifo to 2k */
  707. mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
  708. mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
  709. /* set speed */
  710. if (speed == _1000BASET) {
  711. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  712. unsigned long pfc1;
  713. mfsdr (sdr_pfc1, pfc1);
  714. pfc1 |= SDR0_PFC1_EM_1000;
  715. mtsdr (sdr_pfc1, pfc1);
  716. #endif
  717. mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
  718. } else if (speed == _100BASET)
  719. mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
  720. else
  721. mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
  722. if (duplex == FULL)
  723. mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
  724. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  725. /* Enable broadcast and indvidual address */
  726. /* TBS: enabling runts as some misbehaved nics will send runts */
  727. out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
  728. /* we probably need to set the tx mode1 reg? maybe at tx time */
  729. /* set transmit request threshold register */
  730. out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
  731. /* set receive low/high water mark register */
  732. #if defined(CONFIG_440)
  733. /* 440s has a 64 byte burst length */
  734. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
  735. #else
  736. /* 405s have a 16 byte burst length */
  737. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
  738. #endif /* defined(CONFIG_440) */
  739. out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
  740. /* Set fifo limit entry in tx mode 0 */
  741. out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
  742. /* Frame gap set */
  743. out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
  744. /* Set EMAC IER */
  745. hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
  746. if (speed == _100BASET)
  747. hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
  748. out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
  749. out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
  750. if (hw_p->first_init == 0) {
  751. /*
  752. * Connect interrupt service routines
  753. */
  754. irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
  755. (interrupt_handler_t *) enetInt, dev);
  756. }
  757. mtmsr (msr); /* enable interrupts again */
  758. hw_p->bis = bis;
  759. hw_p->first_init = 1;
  760. return (1);
  761. }
  762. static int ppc_4xx_eth_send (struct eth_device *dev, volatile void *ptr,
  763. int len)
  764. {
  765. struct enet_frame *ef_ptr;
  766. ulong time_start, time_now;
  767. unsigned long temp_txm0;
  768. EMAC_4XX_HW_PST hw_p = dev->priv;
  769. ef_ptr = (struct enet_frame *) ptr;
  770. /*-----------------------------------------------------------------------+
  771. * Copy in our address into the frame.
  772. *-----------------------------------------------------------------------*/
  773. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  774. /*-----------------------------------------------------------------------+
  775. * If frame is too long or too short, modify length.
  776. *-----------------------------------------------------------------------*/
  777. /* TBS: where does the fragment go???? */
  778. if (len > ENET_MAX_MTU)
  779. len = ENET_MAX_MTU;
  780. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  781. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  782. /*-----------------------------------------------------------------------+
  783. * set TX Buffer busy, and send it
  784. *-----------------------------------------------------------------------*/
  785. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  786. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  787. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  788. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  789. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  790. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  791. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  792. __asm__ volatile ("eieio");
  793. out32 (EMAC_TXM0 + hw_p->hw_addr,
  794. in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
  795. #ifdef INFO_4XX_ENET
  796. hw_p->stats.pkts_tx++;
  797. #endif
  798. /*-----------------------------------------------------------------------+
  799. * poll unitl the packet is sent and then make sure it is OK
  800. *-----------------------------------------------------------------------*/
  801. time_start = get_timer (0);
  802. while (1) {
  803. temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
  804. /* loop until either TINT turns on or 3 seconds elapse */
  805. if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
  806. /* transmit is done, so now check for errors
  807. * If there is an error, an interrupt should
  808. * happen when we return
  809. */
  810. time_now = get_timer (0);
  811. if ((time_now - time_start) > 3000) {
  812. return (-1);
  813. }
  814. } else {
  815. return (len);
  816. }
  817. }
  818. }
  819. #if defined (CONFIG_440)
  820. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  821. /*
  822. * Hack: On 440SP all enet irq sources are located on UIC1
  823. * Needs some cleanup. --sr
  824. */
  825. #define UIC0MSR uic1msr
  826. #define UIC0SR uic1sr
  827. #else
  828. #define UIC0MSR uic0msr
  829. #define UIC0SR uic0sr
  830. #endif
  831. int enetInt (struct eth_device *dev)
  832. {
  833. int serviced;
  834. int rc = -1; /* default to not us */
  835. unsigned long mal_isr;
  836. unsigned long emac_isr = 0;
  837. unsigned long mal_rx_eob;
  838. unsigned long my_uic0msr, my_uic1msr;
  839. #if defined(CONFIG_440GX)
  840. unsigned long my_uic2msr;
  841. #endif
  842. EMAC_4XX_HW_PST hw_p;
  843. /*
  844. * Because the mal is generic, we need to get the current
  845. * eth device
  846. */
  847. #if defined(CONFIG_NET_MULTI)
  848. dev = eth_get_dev();
  849. #else
  850. dev = emac0_dev;
  851. #endif
  852. hw_p = dev->priv;
  853. /* enter loop that stays in interrupt code until nothing to service */
  854. do {
  855. serviced = 0;
  856. my_uic0msr = mfdcr (UIC0MSR);
  857. my_uic1msr = mfdcr (uic1msr);
  858. #if defined(CONFIG_440GX)
  859. my_uic2msr = mfdcr (uic2msr);
  860. #endif
  861. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  862. && !(my_uic1msr & (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE))) {
  863. /* not for us */
  864. return (rc);
  865. }
  866. #if defined (CONFIG_440GX)
  867. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  868. && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
  869. /* not for us */
  870. return (rc);
  871. }
  872. #endif
  873. /* get and clear controller status interrupts */
  874. /* look at Mal and EMAC interrupts */
  875. if ((my_uic0msr & (UIC_MRE | UIC_MTE))
  876. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  877. /* we have a MAL interrupt */
  878. mal_isr = mfdcr (malesr);
  879. /* look for mal error */
  880. if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
  881. mal_err (dev, mal_isr, my_uic0msr,
  882. MAL_UIC_DEF, MAL_UIC_ERR);
  883. serviced = 1;
  884. rc = 0;
  885. }
  886. }
  887. /* port by port dispatch of emac interrupts */
  888. if (hw_p->devnum == 0) {
  889. if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
  890. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  891. if ((hw_p->emac_ier & emac_isr) != 0) {
  892. emac_err (dev, emac_isr);
  893. serviced = 1;
  894. rc = 0;
  895. }
  896. }
  897. if ((hw_p->emac_ier & emac_isr)
  898. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  899. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  900. mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  901. return (rc); /* we had errors so get out */
  902. }
  903. }
  904. #if !defined(CONFIG_440SP)
  905. if (hw_p->devnum == 1) {
  906. if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
  907. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  908. if ((hw_p->emac_ier & emac_isr) != 0) {
  909. emac_err (dev, emac_isr);
  910. serviced = 1;
  911. rc = 0;
  912. }
  913. }
  914. if ((hw_p->emac_ier & emac_isr)
  915. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  916. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  917. mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  918. return (rc); /* we had errors so get out */
  919. }
  920. }
  921. #if defined (CONFIG_440GX)
  922. if (hw_p->devnum == 2) {
  923. if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
  924. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  925. if ((hw_p->emac_ier & emac_isr) != 0) {
  926. emac_err (dev, emac_isr);
  927. serviced = 1;
  928. rc = 0;
  929. }
  930. }
  931. if ((hw_p->emac_ier & emac_isr)
  932. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  933. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  934. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  935. mtdcr (uic2sr, UIC_ETH2);
  936. return (rc); /* we had errors so get out */
  937. }
  938. }
  939. if (hw_p->devnum == 3) {
  940. if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
  941. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  942. if ((hw_p->emac_ier & emac_isr) != 0) {
  943. emac_err (dev, emac_isr);
  944. serviced = 1;
  945. rc = 0;
  946. }
  947. }
  948. if ((hw_p->emac_ier & emac_isr)
  949. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  950. mtdcr (UIC0SR, UIC_MRE | UIC_MTE); /* Clear */
  951. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  952. mtdcr (uic2sr, UIC_ETH3);
  953. return (rc); /* we had errors so get out */
  954. }
  955. }
  956. #endif /* CONFIG_440GX */
  957. #endif /* !CONFIG_440SP */
  958. /* handle MAX TX EOB interrupt from a tx */
  959. if (my_uic0msr & UIC_MTE) {
  960. mal_rx_eob = mfdcr (maltxeobisr);
  961. mtdcr (maltxeobisr, mal_rx_eob);
  962. mtdcr (UIC0SR, UIC_MTE);
  963. }
  964. /* handle MAL RX EOB interupt from a receive */
  965. /* check for EOB on valid channels */
  966. if (my_uic0msr & UIC_MRE) {
  967. mal_rx_eob = mfdcr (malrxeobisr);
  968. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  969. /* clear EOB
  970. mtdcr(malrxeobisr, mal_rx_eob); */
  971. enet_rcv (dev, emac_isr);
  972. /* indicate that we serviced an interrupt */
  973. serviced = 1;
  974. rc = 0;
  975. }
  976. }
  977. mtdcr (UIC0SR, UIC_MRE); /* Clear */
  978. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  979. switch (hw_p->devnum) {
  980. case 0:
  981. mtdcr (uic1sr, UIC_ETH0);
  982. break;
  983. case 1:
  984. mtdcr (uic1sr, UIC_ETH1);
  985. break;
  986. #if defined (CONFIG_440GX)
  987. case 2:
  988. mtdcr (uic2sr, UIC_ETH2);
  989. break;
  990. case 3:
  991. mtdcr (uic2sr, UIC_ETH3);
  992. break;
  993. #endif /* CONFIG_440GX */
  994. default:
  995. break;
  996. }
  997. } while (serviced);
  998. return (rc);
  999. }
  1000. #else /* CONFIG_440 */
  1001. int enetInt (struct eth_device *dev)
  1002. {
  1003. int serviced;
  1004. int rc = -1; /* default to not us */
  1005. unsigned long mal_isr;
  1006. unsigned long emac_isr = 0;
  1007. unsigned long mal_rx_eob;
  1008. unsigned long my_uicmsr;
  1009. EMAC_4XX_HW_PST hw_p;
  1010. /*
  1011. * Because the mal is generic, we need to get the current
  1012. * eth device
  1013. */
  1014. #if defined(CONFIG_NET_MULTI)
  1015. dev = eth_get_dev();
  1016. #else
  1017. dev = emac0_dev;
  1018. #endif
  1019. hw_p = dev->priv;
  1020. /* enter loop that stays in interrupt code until nothing to service */
  1021. do {
  1022. serviced = 0;
  1023. my_uicmsr = mfdcr (uicmsr);
  1024. if ((my_uicmsr & (MAL_UIC_DEF | EMAC_UIC_DEF)) == 0) { /* not for us */
  1025. return (rc);
  1026. }
  1027. /* get and clear controller status interrupts */
  1028. /* look at Mal and EMAC interrupts */
  1029. if ((MAL_UIC_DEF & my_uicmsr) != 0) { /* we have a MAL interrupt */
  1030. mal_isr = mfdcr (malesr);
  1031. /* look for mal error */
  1032. if ((my_uicmsr & MAL_UIC_ERR) != 0) {
  1033. mal_err (dev, mal_isr, my_uicmsr, MAL_UIC_DEF, MAL_UIC_ERR);
  1034. serviced = 1;
  1035. rc = 0;
  1036. }
  1037. }
  1038. /* port by port dispatch of emac interrupts */
  1039. if ((SEL_UIC_DEF(hw_p->devnum) & my_uicmsr) != 0) { /* look for EMAC errors */
  1040. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  1041. if ((hw_p->emac_ier & emac_isr) != 0) {
  1042. emac_err (dev, emac_isr);
  1043. serviced = 1;
  1044. rc = 0;
  1045. }
  1046. }
  1047. if (((hw_p->emac_ier & emac_isr) != 0) || ((MAL_UIC_ERR & my_uicmsr) != 0)) {
  1048. mtdcr (uicsr, MAL_UIC_DEF | SEL_UIC_DEF(hw_p->devnum)); /* Clear */
  1049. return (rc); /* we had errors so get out */
  1050. }
  1051. /* handle MAX TX EOB interrupt from a tx */
  1052. if (my_uicmsr & UIC_MAL_TXEOB) {
  1053. mal_rx_eob = mfdcr (maltxeobisr);
  1054. mtdcr (maltxeobisr, mal_rx_eob);
  1055. mtdcr (uicsr, UIC_MAL_TXEOB);
  1056. }
  1057. /* handle MAL RX EOB interupt from a receive */
  1058. /* check for EOB on valid channels */
  1059. if (my_uicmsr & UIC_MAL_RXEOB)
  1060. {
  1061. mal_rx_eob = mfdcr (malrxeobisr);
  1062. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  1063. /* clear EOB
  1064. mtdcr(malrxeobisr, mal_rx_eob); */
  1065. enet_rcv (dev, emac_isr);
  1066. /* indicate that we serviced an interrupt */
  1067. serviced = 1;
  1068. rc = 0;
  1069. }
  1070. }
  1071. mtdcr (uicsr, MAL_UIC_DEF|EMAC_UIC_DEF|EMAC_UIC_DEF1); /* Clear */
  1072. }
  1073. while (serviced);
  1074. return (rc);
  1075. }
  1076. #endif /* CONFIG_440 */
  1077. /*-----------------------------------------------------------------------------+
  1078. * MAL Error Routine
  1079. *-----------------------------------------------------------------------------*/
  1080. static void mal_err (struct eth_device *dev, unsigned long isr,
  1081. unsigned long uic, unsigned long maldef,
  1082. unsigned long mal_errr)
  1083. {
  1084. EMAC_4XX_HW_PST hw_p = dev->priv;
  1085. mtdcr (malesr, isr); /* clear interrupt */
  1086. /* clear DE interrupt */
  1087. mtdcr (maltxdeir, 0xC0000000);
  1088. mtdcr (malrxdeir, 0x80000000);
  1089. #ifdef INFO_4XX_ENET
  1090. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  1091. #endif
  1092. eth_init (hw_p->bis); /* start again... */
  1093. }
  1094. /*-----------------------------------------------------------------------------+
  1095. * EMAC Error Routine
  1096. *-----------------------------------------------------------------------------*/
  1097. static void emac_err (struct eth_device *dev, unsigned long isr)
  1098. {
  1099. EMAC_4XX_HW_PST hw_p = dev->priv;
  1100. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  1101. out32 (EMAC_ISR + hw_p->hw_addr, isr);
  1102. }
  1103. /*-----------------------------------------------------------------------------+
  1104. * enet_rcv() handles the ethernet receive data
  1105. *-----------------------------------------------------------------------------*/
  1106. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  1107. {
  1108. struct enet_frame *ef_ptr;
  1109. unsigned long data_len;
  1110. unsigned long rx_eob_isr;
  1111. EMAC_4XX_HW_PST hw_p = dev->priv;
  1112. int handled = 0;
  1113. int i;
  1114. int loop_count = 0;
  1115. rx_eob_isr = mfdcr (malrxeobisr);
  1116. if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
  1117. /* clear EOB */
  1118. mtdcr (malrxeobisr, rx_eob_isr);
  1119. /* EMAC RX done */
  1120. while (1) { /* do all */
  1121. i = hw_p->rx_slot;
  1122. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  1123. || (loop_count >= NUM_RX_BUFF))
  1124. break;
  1125. loop_count++;
  1126. hw_p->rx_slot++;
  1127. if (NUM_RX_BUFF == hw_p->rx_slot)
  1128. hw_p->rx_slot = 0;
  1129. handled++;
  1130. data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
  1131. if (data_len) {
  1132. if (data_len > ENET_MAX_MTU) /* Check len */
  1133. data_len = 0;
  1134. else {
  1135. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  1136. data_len = 0;
  1137. hw_p->stats.rx_err_log[hw_p->
  1138. rx_err_index]
  1139. = hw_p->rx[i].ctrl;
  1140. hw_p->rx_err_index++;
  1141. if (hw_p->rx_err_index ==
  1142. MAX_ERR_LOG)
  1143. hw_p->rx_err_index =
  1144. 0;
  1145. } /* emac_erros */
  1146. } /* data_len < max mtu */
  1147. } /* if data_len */
  1148. if (!data_len) { /* no data */
  1149. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  1150. hw_p->stats.data_len_err++; /* Error at Rx */
  1151. }
  1152. /* !data_len */
  1153. /* AS.HARNOIS */
  1154. /* Check if user has already eaten buffer */
  1155. /* if not => ERROR */
  1156. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  1157. if (hw_p->is_receiving)
  1158. printf ("ERROR : Receive buffers are full!\n");
  1159. break;
  1160. } else {
  1161. hw_p->stats.rx_frames++;
  1162. hw_p->stats.rx += data_len;
  1163. ef_ptr = (struct enet_frame *) hw_p->rx[i].
  1164. data_ptr;
  1165. #ifdef INFO_4XX_ENET
  1166. hw_p->stats.pkts_rx++;
  1167. #endif
  1168. /* AS.HARNOIS
  1169. * use ring buffer
  1170. */
  1171. hw_p->rx_ready[hw_p->rx_i_index] = i;
  1172. hw_p->rx_i_index++;
  1173. if (NUM_RX_BUFF == hw_p->rx_i_index)
  1174. hw_p->rx_i_index = 0;
  1175. /* AS.HARNOIS
  1176. * free receive buffer only when
  1177. * buffer has been handled (eth_rx)
  1178. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  1179. */
  1180. } /* if data_len */
  1181. } /* while */
  1182. } /* if EMACK_RXCHL */
  1183. }
  1184. static int ppc_4xx_eth_rx (struct eth_device *dev)
  1185. {
  1186. int length;
  1187. int user_index;
  1188. unsigned long msr;
  1189. EMAC_4XX_HW_PST hw_p = dev->priv;
  1190. hw_p->is_receiving = 1; /* tell driver */
  1191. for (;;) {
  1192. /* AS.HARNOIS
  1193. * use ring buffer and
  1194. * get index from rx buffer desciptor queue
  1195. */
  1196. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  1197. if (user_index == -1) {
  1198. length = -1;
  1199. break; /* nothing received - leave for() loop */
  1200. }
  1201. msr = mfmsr ();
  1202. mtmsr (msr & ~(MSR_EE));
  1203. length = hw_p->rx[user_index].data_len;
  1204. /* Pass the packet up to the protocol layers. */
  1205. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  1206. /* NetReceive(NetRxPackets[i], length); */
  1207. NetReceive (NetRxPackets[user_index], length - 4);
  1208. /* Free Recv Buffer */
  1209. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  1210. /* Free rx buffer descriptor queue */
  1211. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  1212. hw_p->rx_u_index++;
  1213. if (NUM_RX_BUFF == hw_p->rx_u_index)
  1214. hw_p->rx_u_index = 0;
  1215. #ifdef INFO_4XX_ENET
  1216. hw_p->stats.pkts_handled++;
  1217. #endif
  1218. mtmsr (msr); /* Enable IRQ's */
  1219. }
  1220. hw_p->is_receiving = 0; /* tell driver */
  1221. return length;
  1222. }
  1223. int ppc_4xx_eth_initialize (bd_t * bis)
  1224. {
  1225. static int virgin = 0;
  1226. struct eth_device *dev;
  1227. int eth_num = 0;
  1228. EMAC_4XX_HW_PST hw = NULL;
  1229. #if defined(CONFIG_440GX)
  1230. unsigned long pfc1;
  1231. mfsdr (sdr_pfc1, pfc1);
  1232. pfc1 &= ~(0x01e00000);
  1233. pfc1 |= 0x01200000;
  1234. mtsdr (sdr_pfc1, pfc1);
  1235. #endif
  1236. /* set phy num and mode */
  1237. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  1238. bis->bi_phymode[0] = 0;
  1239. #if defined(CONFIG_PHY1_ADDR)
  1240. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  1241. bis->bi_phymode[1] = 0;
  1242. #endif
  1243. #if defined(CONFIG_440GX)
  1244. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  1245. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  1246. bis->bi_phymode[2] = 2;
  1247. bis->bi_phymode[3] = 2;
  1248. ppc_4xx_eth_setup_bridge(0, bis);
  1249. #endif
  1250. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1251. /* See if we can actually bring up the interface, otherwise, skip it */
  1252. switch (eth_num) {
  1253. default: /* fall through */
  1254. case 0:
  1255. if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  1256. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1257. continue;
  1258. }
  1259. break;
  1260. #ifdef CONFIG_HAS_ETH1
  1261. case 1:
  1262. if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
  1263. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1264. continue;
  1265. }
  1266. break;
  1267. #endif
  1268. #ifdef CONFIG_HAS_ETH2
  1269. case 2:
  1270. if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
  1271. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1272. continue;
  1273. }
  1274. break;
  1275. #endif
  1276. #ifdef CONFIG_HAS_ETH3
  1277. case 3:
  1278. if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
  1279. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1280. continue;
  1281. }
  1282. break;
  1283. #endif
  1284. }
  1285. /* Allocate device structure */
  1286. dev = (struct eth_device *) malloc (sizeof (*dev));
  1287. if (dev == NULL) {
  1288. printf ("ppc_4xx_eth_initialize: "
  1289. "Cannot allocate eth_device %d\n", eth_num);
  1290. return (-1);
  1291. }
  1292. memset(dev, 0, sizeof(*dev));
  1293. /* Allocate our private use data */
  1294. hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
  1295. if (hw == NULL) {
  1296. printf ("ppc_4xx_eth_initialize: "
  1297. "Cannot allocate private hw data for eth_device %d",
  1298. eth_num);
  1299. free (dev);
  1300. return (-1);
  1301. }
  1302. memset(hw, 0, sizeof(*hw));
  1303. switch (eth_num) {
  1304. default: /* fall through */
  1305. case 0:
  1306. hw->hw_addr = 0;
  1307. memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
  1308. break;
  1309. #ifdef CONFIG_HAS_ETH1
  1310. case 1:
  1311. hw->hw_addr = 0x100;
  1312. memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
  1313. break;
  1314. #endif
  1315. #ifdef CONFIG_HAS_ETH2
  1316. case 2:
  1317. hw->hw_addr = 0x400;
  1318. memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
  1319. break;
  1320. #endif
  1321. #ifdef CONFIG_HAS_ETH3
  1322. case 3:
  1323. hw->hw_addr = 0x600;
  1324. memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
  1325. break;
  1326. #endif
  1327. }
  1328. hw->devnum = eth_num;
  1329. hw->print_speed = 1;
  1330. sprintf (dev->name, "ppc_4xx_eth%d", eth_num);
  1331. dev->priv = (void *) hw;
  1332. dev->init = ppc_4xx_eth_init;
  1333. dev->halt = ppc_4xx_eth_halt;
  1334. dev->send = ppc_4xx_eth_send;
  1335. dev->recv = ppc_4xx_eth_rx;
  1336. if (0 == virgin) {
  1337. /* set the MAL IER ??? names may change with new spec ??? */
  1338. #if defined(CONFIG_440SPE)
  1339. mal_ier =
  1340. MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
  1341. MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
  1342. #else
  1343. mal_ier =
  1344. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  1345. MAL_IER_OPBE | MAL_IER_PLBE;
  1346. #endif
  1347. mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
  1348. mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
  1349. mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
  1350. mtdcr (malier, mal_ier);
  1351. /* install MAL interrupt handler */
  1352. irq_install_handler (VECNUM_MS,
  1353. (interrupt_handler_t *) enetInt,
  1354. dev);
  1355. irq_install_handler (VECNUM_MTE,
  1356. (interrupt_handler_t *) enetInt,
  1357. dev);
  1358. irq_install_handler (VECNUM_MRE,
  1359. (interrupt_handler_t *) enetInt,
  1360. dev);
  1361. irq_install_handler (VECNUM_TXDE,
  1362. (interrupt_handler_t *) enetInt,
  1363. dev);
  1364. irq_install_handler (VECNUM_RXDE,
  1365. (interrupt_handler_t *) enetInt,
  1366. dev);
  1367. virgin = 1;
  1368. }
  1369. #if defined(CONFIG_NET_MULTI)
  1370. eth_register (dev);
  1371. #else
  1372. emac0_dev = dev;
  1373. #endif
  1374. #if defined(CONFIG_NET_MULTI)
  1375. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1376. miiphy_register (dev->name,
  1377. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1378. #endif
  1379. #endif
  1380. } /* end for each supported device */
  1381. return (1);
  1382. }
  1383. #if !defined(CONFIG_NET_MULTI)
  1384. void eth_halt (void) {
  1385. if (emac0_dev) {
  1386. ppc_4xx_eth_halt(emac0_dev);
  1387. free(emac0_dev);
  1388. emac0_dev = NULL;
  1389. }
  1390. }
  1391. int eth_init (bd_t *bis)
  1392. {
  1393. ppc_4xx_eth_initialize(bis);
  1394. if (emac0_dev) {
  1395. return ppc_4xx_eth_init(emac0_dev, bis);
  1396. } else {
  1397. printf("ERROR: ethaddr not set!\n");
  1398. return -1;
  1399. }
  1400. }
  1401. int eth_send(volatile void *packet, int length)
  1402. {
  1403. return (ppc_4xx_eth_send(emac0_dev, packet, length));
  1404. }
  1405. int eth_rx(void)
  1406. {
  1407. return (ppc_4xx_eth_rx(emac0_dev));
  1408. }
  1409. int emac4xx_miiphy_initialize (bd_t * bis)
  1410. {
  1411. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1412. miiphy_register ("ppc_4xx_eth0",
  1413. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1414. #endif
  1415. return 0;
  1416. }
  1417. #endif /* !defined(CONFIG_NET_MULTI) */
  1418. #endif /* #if (CONFIG_COMMANDS & CFG_CMD_NET) */