440gx_enet.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. /*-----------------------------------------------------------------------------+
  2. *
  3. * This source code has been made available to you by IBM on an AS-IS
  4. * basis. Anyone receiving this source is licensed under IBM
  5. * copyrights to use it in any way he or she deems fit, including
  6. * copying it, modifying it, compiling it, and redistributing it either
  7. * with or without modifications. No license under IBM patents or
  8. * patent applications is to be implied by the copyright license.
  9. *
  10. * Any user of this software should understand that IBM cannot provide
  11. * technical support for this software and will not be responsible for
  12. * any consequences resulting from the use of this software.
  13. *
  14. * Any person who transfers this source code or any derivative work
  15. * must include the IBM copyright notice, this paragraph, and the
  16. * preceding two paragraphs in the transferred software.
  17. *
  18. * COPYRIGHT I B M CORPORATION 1995
  19. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  20. *-----------------------------------------------------------------------------*/
  21. /*-----------------------------------------------------------------------------+
  22. *
  23. * File Name: enetemac.c
  24. *
  25. * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
  26. *
  27. * Author: Mark Wisner
  28. *
  29. * Change Activity-
  30. *
  31. * Date Description of Change BY
  32. * --------- --------------------- ---
  33. * 05-May-99 Created MKW
  34. * 27-Jun-99 Clean up JWB
  35. * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW
  36. * 29-Jul-99 Added Full duplex support MKW
  37. * 06-Aug-99 Changed names for Mal CR reg MKW
  38. * 23-Aug-99 Turned off SYE when running at 10Mbs MKW
  39. * 24-Aug-99 Marked descriptor empty after call_xlc MKW
  40. * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG
  41. * to avoid chaining maximum sized packets. Push starting
  42. * RX descriptor address up to the next cache line boundary.
  43. * 16-Jan-00 Added support for booting with IP of 0x0 MKW
  44. * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the
  45. * EMAC_RXM register. JWB
  46. * 12-Mar-01 anne-sophie.harnois@nextream.fr
  47. * - Variables are compatible with those already defined in
  48. * include/net.h
  49. * - Receive buffer descriptor ring is used to send buffers
  50. * to the user
  51. * - Info print about send/received/handled packet number if
  52. * INFO_405_ENET is set
  53. * 17-Apr-01 stefan.roese@esd-electronics.com
  54. * - MAL reset in "eth_halt" included
  55. * - Enet speed and duplex output now in one line
  56. * 08-May-01 stefan.roese@esd-electronics.com
  57. * - MAL error handling added (eth_init called again)
  58. * 13-Nov-01 stefan.roese@esd-electronics.com
  59. * - Set IST bit in EMAC_M1 reg upon 100MBit or full duplex
  60. * 04-Jan-02 stefan.roese@esd-electronics.com
  61. * - Wait for PHY auto negotiation to complete added
  62. * 06-Feb-02 stefan.roese@esd-electronics.com
  63. * - Bug fixed in waiting for auto negotiation to complete
  64. * 26-Feb-02 stefan.roese@esd-electronics.com
  65. * - rx and tx buffer descriptors now allocated (no fixed address
  66. * used anymore)
  67. * 17-Jun-02 stefan.roese@esd-electronics.com
  68. * - MAL error debug printf 'M' removed (rx de interrupt may
  69. * occur upon many incoming packets with only 4 rx buffers).
  70. *-----------------------------------------------------------------------------*
  71. * 17-Nov-03 travis.sawyer@sandburst.com
  72. * - ported from 405gp_enet.c to utilized upto 4 EMAC ports
  73. * in the 440GX. This port should work with the 440GP
  74. * (2 EMACs) also
  75. *-----------------------------------------------------------------------------*/
  76. #include <config.h>
  77. #if defined(CONFIG_440) && defined(CONFIG_NET_MULTI)
  78. #include <common.h>
  79. #include <net.h>
  80. #include <asm/processor.h>
  81. #include <ppc440.h>
  82. #include <commproc.h>
  83. #include <440gx_enet.h>
  84. #include <405_mal.h>
  85. #include <miiphy.h>
  86. #include <malloc.h>
  87. #include "vecnum.h"
  88. #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
  89. #define PHY_AUTONEGOTIATE_TIMEOUT 4000 /* 4000 ms autonegotiate timeout */
  90. /* Ethernet Transmit and Receive Buffers */
  91. /* AS.HARNOIS
  92. * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
  93. * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
  94. */
  95. #define ENET_MAX_MTU PKTSIZE
  96. #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
  97. /* define the number of channels implemented */
  98. #define EMAC_RXCHL EMAC_NUM_DEV
  99. #define EMAC_TXCHL EMAC_NUM_DEV
  100. /*-----------------------------------------------------------------------------+
  101. * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
  102. * Interrupt Controller).
  103. *-----------------------------------------------------------------------------*/
  104. #define MAL_UIC_ERR ( UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
  105. #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
  106. #define EMAC_UIC_DEF UIC_ENET
  107. #undef INFO_440_ENET
  108. #define BI_PHYMODE_NONE 0
  109. #define BI_PHYMODE_ZMII 1
  110. #define BI_PHYMODE_RGMII 2
  111. /*-----------------------------------------------------------------------------+
  112. * Global variables. TX and RX descriptors and buffers.
  113. *-----------------------------------------------------------------------------*/
  114. /* IER globals */
  115. static uint32_t mal_ier;
  116. /*-----------------------------------------------------------------------------+
  117. * Prototypes and externals.
  118. *-----------------------------------------------------------------------------*/
  119. static void enet_rcv (struct eth_device *dev, unsigned long malisr);
  120. int enetInt (struct eth_device *dev);
  121. static void mal_err (struct eth_device *dev, unsigned long isr,
  122. unsigned long uic, unsigned long maldef,
  123. unsigned long mal_errr);
  124. static void emac_err (struct eth_device *dev, unsigned long isr);
  125. /*-----------------------------------------------------------------------------+
  126. | ppc_440x_eth_halt
  127. | Disable MAL channel, and EMACn
  128. |
  129. |
  130. +-----------------------------------------------------------------------------*/
  131. static void ppc_440x_eth_halt (struct eth_device *dev)
  132. {
  133. EMAC_440GX_HW_PST hw_p = dev->priv;
  134. uint32_t failsafe = 10000;
  135. out32 (EMAC_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
  136. /* 1st reset MAL channel */
  137. /* Note: writing a 0 to a channel has no effect */
  138. mtdcr (maltxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  139. mtdcr (malrxcarr, (MAL_CR_MMSR >> hw_p->devnum));
  140. /* wait for reset */
  141. while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
  142. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  143. failsafe--;
  144. if (failsafe == 0)
  145. break;
  146. }
  147. /* EMAC RESET */
  148. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  149. return;
  150. }
  151. extern int phy_setup_aneg (unsigned char addr);
  152. extern int miiphy_reset (unsigned char addr);
  153. #if defined (CONFIG_440_GX)
  154. int ppc_440x_eth_setup_bridge(int devnum, bd_t * bis)
  155. {
  156. unsigned long pfc1;
  157. unsigned long zmiifer;
  158. unsigned long rmiifer;
  159. mfsdr(sdr_pfc1, pfc1);
  160. pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
  161. zmiifer = 0;
  162. rmiifer = 0;
  163. switch (pfc1) {
  164. case 1:
  165. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  166. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
  167. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
  168. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
  169. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  170. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  171. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  172. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  173. break;
  174. case 2:
  175. zmiifer = ZMII_FER_SMII << ZMII_FER_V(0);
  176. zmiifer = ZMII_FER_SMII << ZMII_FER_V(1);
  177. zmiifer = ZMII_FER_SMII << ZMII_FER_V(2);
  178. zmiifer = ZMII_FER_SMII << ZMII_FER_V(3);
  179. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  180. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  181. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  182. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  183. break;
  184. case 3:
  185. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  186. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  187. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  188. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  189. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  190. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  191. break;
  192. case 4:
  193. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  194. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  195. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
  196. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
  197. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  198. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  199. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  200. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  201. break;
  202. case 5:
  203. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  204. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  205. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
  206. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
  207. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  208. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  209. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  210. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  211. break;
  212. case 6:
  213. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  214. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  215. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  216. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  217. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  218. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  219. break;
  220. case 0:
  221. default:
  222. zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
  223. rmiifer = 0x0;
  224. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  225. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  226. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  227. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  228. break;
  229. }
  230. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  231. zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
  232. out32 (ZMII_FER, zmiifer);
  233. out32 (RGMII_FER, rmiifer);
  234. return ((int)pfc1);
  235. }
  236. #endif
  237. static int ppc_440x_eth_init (struct eth_device *dev, bd_t * bis)
  238. {
  239. int i;
  240. unsigned long reg;
  241. unsigned long msr;
  242. unsigned long speed;
  243. unsigned long duplex;
  244. unsigned long failsafe;
  245. unsigned mode_reg;
  246. unsigned short devnum;
  247. unsigned short reg_short;
  248. sys_info_t sysinfo;
  249. int ethgroup;
  250. EMAC_440GX_HW_PST hw_p = dev->priv;
  251. /* before doing anything, figure out if we have a MAC address */
  252. /* if not, bail */
  253. if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0)
  254. return -1;
  255. /* Need to get the OPB frequency so we can access the PHY */
  256. get_sys_info (&sysinfo);
  257. msr = mfmsr ();
  258. mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
  259. devnum = hw_p->devnum;
  260. #ifdef INFO_440_ENET
  261. /* AS.HARNOIS
  262. * We should have :
  263. * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
  264. * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
  265. * is possible that new packets (without relationship with
  266. * current transfer) have got the time to arrived before
  267. * netloop calls eth_halt
  268. */
  269. printf ("About preceeding transfer (eth%d):\n"
  270. "- Sent packet number %d\n"
  271. "- Received packet number %d\n"
  272. "- Handled packet number %d\n",
  273. hw_p->devnum,
  274. hw_p->stats.pkts_tx,
  275. hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
  276. hw_p->stats.pkts_tx = 0;
  277. hw_p->stats.pkts_rx = 0;
  278. hw_p->stats.pkts_handled = 0;
  279. #endif
  280. /* MAL Channel RESET */
  281. /* 1st reset MAL channel */
  282. /* Note: writing a 0 to a channel has no effect */
  283. mtdcr (maltxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
  284. mtdcr (malrxcarr, (MAL_TXRX_CASR >> hw_p->devnum));
  285. /* wait for reset */
  286. /* TBS: should have udelay and failsafe here */
  287. failsafe = 10000;
  288. /* wait for reset */
  289. while (mfdcr (maltxcasr) & (MAL_CR_MMSR >> hw_p->devnum)) {
  290. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  291. failsafe--;
  292. if (failsafe == 0)
  293. break;
  294. }
  295. hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
  296. hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
  297. hw_p->rx_slot = 0; /* MAL Receive Slot */
  298. hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
  299. hw_p->rx_u_index = 0; /* Receive User Queue Index */
  300. hw_p->tx_slot = 0; /* MAL Transmit Slot */
  301. hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
  302. hw_p->tx_u_index = 0; /* Transmit User Queue Index */
  303. /* set RMII mode */
  304. /* NOTE: 440GX spec states that mode is mutually exclusive */
  305. /* NOTE: Therefore, disable all other EMACS, since we handle */
  306. /* NOTE: only one emac at a time */
  307. reg = 0;
  308. out32 (ZMII_FER, 0);
  309. udelay (100);
  310. #if defined(CONFIG_440_GX)
  311. ethgroup = ppc_440x_eth_setup_bridge(devnum, bis);
  312. #else
  313. if ((devnum == 0) || (devnum == 1)) {
  314. out32 (ZMII_FER, (ZMII_FER_SMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
  315. }
  316. else { /* ((devnum == 2) || (devnum == 3)) */
  317. out32 (ZMII_FER, ZMII_FER_MDI << ZMII_FER_V (devnum));
  318. out32 (RGMII_FER, ((RGMII_FER_RGMII << RGMII_FER_V (2)) |
  319. (RGMII_FER_RGMII << RGMII_FER_V (3))));
  320. }
  321. #endif
  322. out32 (ZMII_SSR, ZMII_SSR_SP << ZMII_SSR_V(devnum));
  323. __asm__ volatile ("eieio");
  324. /* reset emac so we have access to the phy */
  325. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_SRST);
  326. __asm__ volatile ("eieio");
  327. failsafe = 1000;
  328. while ((in32 (EMAC_M0 + hw_p->hw_addr) & (EMAC_M0_SRST)) && failsafe) {
  329. udelay (1000);
  330. failsafe--;
  331. }
  332. /* Whack the M1 register */
  333. mode_reg = 0x0;
  334. mode_reg &= ~0x00000038;
  335. if (sysinfo.freqOPB <= 50000000);
  336. else if (sysinfo.freqOPB <= 66666667)
  337. mode_reg |= EMAC_M1_OBCI_66;
  338. else if (sysinfo.freqOPB <= 83333333)
  339. mode_reg |= EMAC_M1_OBCI_83;
  340. else if (sysinfo.freqOPB <= 100000000)
  341. mode_reg |= EMAC_M1_OBCI_100;
  342. else
  343. mode_reg |= EMAC_M1_OBCI_GT100;
  344. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  345. /* wait for PHY to complete auto negotiation */
  346. reg_short = 0;
  347. #ifndef CONFIG_CS8952_PHY
  348. switch (devnum) {
  349. case 0:
  350. reg = CONFIG_PHY_ADDR;
  351. break;
  352. case 1:
  353. reg = CONFIG_PHY1_ADDR;
  354. break;
  355. #if defined (CONFIG_440_GX)
  356. case 2:
  357. reg = CONFIG_PHY2_ADDR;
  358. break;
  359. case 3:
  360. reg = CONFIG_PHY3_ADDR;
  361. break;
  362. #endif
  363. default:
  364. reg = CONFIG_PHY_ADDR;
  365. break;
  366. }
  367. bis->bi_phynum[devnum] = reg;
  368. /*
  369. * Reset the phy, only if its the first time through
  370. * otherwise, just check the speeds & feeds
  371. */
  372. if (hw_p->first_init == 0) {
  373. miiphy_reset (reg);
  374. #if defined(CONFIG_440_GX)
  375. #if defined(CONFIG_CIS8201_PHY)
  376. /*
  377. * Cicada 8201 PHY needs to have an extended register whacked
  378. * for RGMII mode.
  379. */
  380. if ( ((devnum == 2) || (devnum ==3)) && (4 == ethgroup) ) {
  381. miiphy_write (reg, 23, 0x1200);
  382. /*
  383. * Vitesse VSC8201/Cicada CIS8201 errata:
  384. * Interoperability problem with Intel 82547EI phys
  385. * This work around (provided by Vitesse) changes
  386. * the default timer convergence from 8ms to 12ms
  387. */
  388. miiphy_write (reg, 0x1f, 0x2a30);
  389. miiphy_write (reg, 0x08, 0x0200);
  390. miiphy_write (reg, 0x1f, 0x52b5);
  391. miiphy_write (reg, 0x02, 0x0004);
  392. miiphy_write (reg, 0x01, 0x0671);
  393. miiphy_write (reg, 0x00, 0x8fae);
  394. miiphy_write (reg, 0x1f, 0x2a30);
  395. miiphy_write (reg, 0x08, 0x0000);
  396. miiphy_write (reg, 0x1f, 0x0000);
  397. /* end Vitesse/Cicada errata */
  398. }
  399. #endif
  400. #endif
  401. /* Start/Restart autonegotiation */
  402. phy_setup_aneg (reg);
  403. udelay (1000);
  404. }
  405. miiphy_read (reg, PHY_BMSR, &reg_short);
  406. /*
  407. * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
  408. */
  409. if ((reg_short & PHY_BMSR_AUTN_ABLE)
  410. && !(reg_short & PHY_BMSR_AUTN_COMP)) {
  411. puts ("Waiting for PHY auto negotiation to complete");
  412. i = 0;
  413. while (!(reg_short & PHY_BMSR_AUTN_COMP)) {
  414. /*
  415. * Timeout reached ?
  416. */
  417. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  418. puts (" TIMEOUT !\n");
  419. break;
  420. }
  421. if ((i++ % 1000) == 0) {
  422. putc ('.');
  423. }
  424. udelay (1000); /* 1 ms */
  425. miiphy_read (reg, PHY_BMSR, &reg_short);
  426. }
  427. puts (" done\n");
  428. udelay (500000); /* another 500 ms (results in faster booting) */
  429. }
  430. #endif
  431. speed = miiphy_speed (reg);
  432. duplex = miiphy_duplex (reg);
  433. if (hw_p->print_speed) {
  434. hw_p->print_speed = 0;
  435. printf ("ENET Speed is %d Mbps - %s duplex connection\n",
  436. (int) speed, (duplex == HALF) ? "HALF" : "FULL");
  437. }
  438. /* Set ZMII/RGMII speed according to the phy link speed */
  439. reg = in32 (ZMII_SSR);
  440. if ( (speed == 100) || (speed == 1000) )
  441. out32 (ZMII_SSR, reg | (ZMII_SSR_SP << ZMII_SSR_V (devnum)));
  442. else
  443. out32 (ZMII_SSR,
  444. reg & (~(ZMII_SSR_SP << ZMII_SSR_V (devnum))));
  445. if ((devnum == 2) || (devnum == 3)) {
  446. if (speed == 1000)
  447. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  448. else if (speed == 100)
  449. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  450. else
  451. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  452. out32 (RGMII_SSR, reg);
  453. }
  454. /* set the Mal configuration reg */
  455. /* Errata 1.12: MAL_1 -- Disable MAL bursting */
  456. if (get_pvr () == PVR_440GP_RB)
  457. mtdcr (malmcr,
  458. MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
  459. else
  460. mtdcr (malmcr,
  461. MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
  462. MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
  463. /* Free "old" buffers */
  464. if (hw_p->alloc_tx_buf)
  465. free (hw_p->alloc_tx_buf);
  466. if (hw_p->alloc_rx_buf)
  467. free (hw_p->alloc_rx_buf);
  468. /*
  469. * Malloc MAL buffer desciptors, make sure they are
  470. * aligned on cache line boundary size
  471. * (401/403/IOP480 = 16, 405 = 32)
  472. * and doesn't cross cache block boundaries.
  473. */
  474. hw_p->alloc_tx_buf =
  475. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_TX_BUFF) +
  476. ((2 * CFG_CACHELINE_SIZE) - 2));
  477. if (((int) hw_p->alloc_tx_buf & CACHELINE_MASK) != 0) {
  478. hw_p->tx =
  479. (mal_desc_t *) ((int) hw_p->alloc_tx_buf +
  480. CFG_CACHELINE_SIZE -
  481. ((int) hw_p->
  482. alloc_tx_buf & CACHELINE_MASK));
  483. } else {
  484. hw_p->tx = hw_p->alloc_tx_buf;
  485. }
  486. hw_p->alloc_rx_buf =
  487. (mal_desc_t *) malloc ((sizeof (mal_desc_t) * NUM_RX_BUFF) +
  488. ((2 * CFG_CACHELINE_SIZE) - 2));
  489. if (((int) hw_p->alloc_rx_buf & CACHELINE_MASK) != 0) {
  490. hw_p->rx =
  491. (mal_desc_t *) ((int) hw_p->alloc_rx_buf +
  492. CFG_CACHELINE_SIZE -
  493. ((int) hw_p->
  494. alloc_rx_buf & CACHELINE_MASK));
  495. } else {
  496. hw_p->rx = hw_p->alloc_rx_buf;
  497. }
  498. for (i = 0; i < NUM_TX_BUFF; i++) {
  499. hw_p->tx[i].ctrl = 0;
  500. hw_p->tx[i].data_len = 0;
  501. if (hw_p->first_init == 0)
  502. hw_p->txbuf_ptr =
  503. (char *) malloc (ENET_MAX_MTU_ALIGNED);
  504. hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
  505. if ((NUM_TX_BUFF - 1) == i)
  506. hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
  507. hw_p->tx_run[i] = -1;
  508. #if 0
  509. printf ("TX_BUFF %d @ 0x%08lx\n", i,
  510. (ulong) hw_p->tx[i].data_ptr);
  511. #endif
  512. }
  513. for (i = 0; i < NUM_RX_BUFF; i++) {
  514. hw_p->rx[i].ctrl = 0;
  515. hw_p->rx[i].data_len = 0;
  516. /* rx[i].data_ptr = (char *) &rx_buff[i]; */
  517. hw_p->rx[i].data_ptr = (char *) NetRxPackets[i];
  518. if ((NUM_RX_BUFF - 1) == i)
  519. hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
  520. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
  521. hw_p->rx_ready[i] = -1;
  522. #if 0
  523. printf ("RX_BUFF %d @ 0x%08lx\n", i, (ulong) rx[i].data_ptr);
  524. #endif
  525. }
  526. reg = 0x00000000;
  527. reg |= dev->enetaddr[0]; /* set high address */
  528. reg = reg << 8;
  529. reg |= dev->enetaddr[1];
  530. out32 (EMAC_IAH + hw_p->hw_addr, reg);
  531. reg = 0x00000000;
  532. reg |= dev->enetaddr[2]; /* set low address */
  533. reg = reg << 8;
  534. reg |= dev->enetaddr[3];
  535. reg = reg << 8;
  536. reg |= dev->enetaddr[4];
  537. reg = reg << 8;
  538. reg |= dev->enetaddr[5];
  539. out32 (EMAC_IAL + hw_p->hw_addr, reg);
  540. switch (devnum) {
  541. case 1:
  542. /* setup MAL tx & rx channel pointers */
  543. mtdcr (maltxbattr, 0x0);
  544. mtdcr (maltxctp1r, hw_p->tx);
  545. mtdcr (malrxbattr, 0x0);
  546. mtdcr (malrxctp1r, hw_p->rx);
  547. /* set RX buffer size */
  548. mtdcr (malrcbs1, ENET_MAX_MTU_ALIGNED / 16);
  549. break;
  550. #if defined (CONFIG_440_GX)
  551. case 2:
  552. /* setup MAL tx & rx channel pointers */
  553. mtdcr (maltxbattr, 0x0);
  554. mtdcr (maltxctp2r, hw_p->tx);
  555. mtdcr (malrxbattr, 0x0);
  556. mtdcr (malrxctp2r, hw_p->rx);
  557. /* set RX buffer size */
  558. mtdcr (malrcbs2, ENET_MAX_MTU_ALIGNED / 16);
  559. break;
  560. case 3:
  561. /* setup MAL tx & rx channel pointers */
  562. mtdcr (maltxbattr, 0x0);
  563. mtdcr (maltxctp3r, hw_p->tx);
  564. mtdcr (malrxbattr, 0x0);
  565. mtdcr (malrxctp3r, hw_p->rx);
  566. /* set RX buffer size */
  567. mtdcr (malrcbs3, ENET_MAX_MTU_ALIGNED / 16);
  568. break;
  569. #endif /*CONFIG_440_GX */
  570. case 0:
  571. default:
  572. /* setup MAL tx & rx channel pointers */
  573. mtdcr (maltxbattr, 0x0);
  574. mtdcr (maltxctp0r, hw_p->tx);
  575. mtdcr (malrxbattr, 0x0);
  576. mtdcr (malrxctp0r, hw_p->rx);
  577. /* set RX buffer size */
  578. mtdcr (malrcbs0, ENET_MAX_MTU_ALIGNED / 16);
  579. break;
  580. }
  581. /* Enable MAL transmit and receive channels */
  582. mtdcr (maltxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  583. mtdcr (malrxcasr, (MAL_TXRX_CASR >> hw_p->devnum));
  584. /* set transmit enable & receive enable */
  585. out32 (EMAC_M0 + hw_p->hw_addr, EMAC_M0_TXE | EMAC_M0_RXE);
  586. /* set receive fifo to 4k and tx fifo to 2k */
  587. mode_reg = in32 (EMAC_M1 + hw_p->hw_addr);
  588. mode_reg |= EMAC_M1_RFS_4K | EMAC_M1_TX_FIFO_2K;
  589. /* set speed */
  590. if (speed == _1000BASET)
  591. mode_reg = mode_reg | EMAC_M1_MF_1000MBPS | EMAC_M1_IST;
  592. else if (speed == _100BASET)
  593. mode_reg = mode_reg | EMAC_M1_MF_100MBPS | EMAC_M1_IST;
  594. else
  595. mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
  596. if (duplex == FULL)
  597. mode_reg = mode_reg | 0x80000000 | EMAC_M1_IST;
  598. out32 (EMAC_M1 + hw_p->hw_addr, mode_reg);
  599. /* Enable broadcast and indvidual address */
  600. /* TBS: enabling runts as some misbehaved nics will send runts */
  601. out32 (EMAC_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
  602. /* we probably need to set the tx mode1 reg? maybe at tx time */
  603. /* set transmit request threshold register */
  604. out32 (EMAC_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
  605. /* set receive low/high water mark register */
  606. /* 440GP has a 64 byte burst length */
  607. out32 (EMAC_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
  608. out32 (EMAC_TXM1 + hw_p->hw_addr, 0xf8640000);
  609. /* Set fifo limit entry in tx mode 0 */
  610. out32 (EMAC_TXM0 + hw_p->hw_addr, 0x00000003);
  611. /* Frame gap set */
  612. out32 (EMAC_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
  613. /* Set EMAC IER */
  614. hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS |
  615. EMAC_ISR_PTLE | EMAC_ISR_ORE | EMAC_ISR_IRE;
  616. if (speed == _100BASET)
  617. hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
  618. out32 (EMAC_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
  619. out32 (EMAC_IER + hw_p->hw_addr, hw_p->emac_ier);
  620. if (hw_p->first_init == 0) {
  621. /*
  622. * Connect interrupt service routines
  623. */
  624. irq_install_handler (VECNUM_EWU0 + (hw_p->devnum * 2),
  625. (interrupt_handler_t *) enetInt, dev);
  626. irq_install_handler (VECNUM_ETH0 + (hw_p->devnum * 2),
  627. (interrupt_handler_t *) enetInt, dev);
  628. }
  629. mtmsr (msr); /* enable interrupts again */
  630. hw_p->bis = bis;
  631. hw_p->first_init = 1;
  632. return (1);
  633. }
  634. static int ppc_440x_eth_send (struct eth_device *dev, volatile void *ptr,
  635. int len)
  636. {
  637. struct enet_frame *ef_ptr;
  638. ulong time_start, time_now;
  639. unsigned long temp_txm0;
  640. EMAC_440GX_HW_PST hw_p = dev->priv;
  641. ef_ptr = (struct enet_frame *) ptr;
  642. /*-----------------------------------------------------------------------+
  643. * Copy in our address into the frame.
  644. *-----------------------------------------------------------------------*/
  645. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  646. /*-----------------------------------------------------------------------+
  647. * If frame is too long or too short, modify length.
  648. *-----------------------------------------------------------------------*/
  649. /* TBS: where does the fragment go???? */
  650. if (len > ENET_MAX_MTU)
  651. len = ENET_MAX_MTU;
  652. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  653. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  654. /*-----------------------------------------------------------------------+
  655. * set TX Buffer busy, and send it
  656. *-----------------------------------------------------------------------*/
  657. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  658. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  659. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  660. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  661. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  662. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  663. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  664. __asm__ volatile ("eieio");
  665. out32 (EMAC_TXM0 + hw_p->hw_addr,
  666. in32 (EMAC_TXM0 + hw_p->hw_addr) | EMAC_TXM0_GNP0);
  667. #ifdef INFO_440_ENET
  668. hw_p->stats.pkts_tx++;
  669. #endif
  670. /*-----------------------------------------------------------------------+
  671. * poll unitl the packet is sent and then make sure it is OK
  672. *-----------------------------------------------------------------------*/
  673. time_start = get_timer (0);
  674. while (1) {
  675. temp_txm0 = in32 (EMAC_TXM0 + hw_p->hw_addr);
  676. /* loop until either TINT turns on or 3 seconds elapse */
  677. if ((temp_txm0 & EMAC_TXM0_GNP0) != 0) {
  678. /* transmit is done, so now check for errors
  679. * If there is an error, an interrupt should
  680. * happen when we return
  681. */
  682. time_now = get_timer (0);
  683. if ((time_now - time_start) > 3000) {
  684. return (-1);
  685. }
  686. } else {
  687. return (len);
  688. }
  689. }
  690. }
  691. int enetInt (struct eth_device *dev)
  692. {
  693. int serviced;
  694. int rc = -1; /* default to not us */
  695. unsigned long mal_isr;
  696. unsigned long emac_isr = 0;
  697. unsigned long mal_rx_eob;
  698. unsigned long my_uic0msr, my_uic1msr;
  699. #if defined(CONFIG_440_GX)
  700. unsigned long my_uic2msr;
  701. #endif
  702. EMAC_440GX_HW_PST hw_p;
  703. /*
  704. * Because the mal is generic, we need to get the current
  705. * eth device
  706. */
  707. dev = eth_get_dev ();
  708. hw_p = dev->priv;
  709. /* enter loop that stays in interrupt code until nothing to service */
  710. do {
  711. serviced = 0;
  712. my_uic0msr = mfdcr (uic0msr);
  713. my_uic1msr = mfdcr (uic1msr);
  714. #if defined(CONFIG_440_GX)
  715. my_uic2msr = mfdcr (uic2msr);
  716. #endif
  717. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  718. && !(my_uic1msr &
  719. (UIC_ETH0 | UIC_ETH1 | UIC_MS | UIC_MTDE |
  720. UIC_MRDE))) {
  721. /* not for us */
  722. return (rc);
  723. }
  724. #if defined (CONFIG_440_GX)
  725. if (!(my_uic0msr & (UIC_MRE | UIC_MTE))
  726. && !(my_uic2msr & (UIC_ETH2 | UIC_ETH3))) {
  727. /* not for us */
  728. return (rc);
  729. }
  730. #endif
  731. /* get and clear controller status interrupts */
  732. /* look at Mal and EMAC interrupts */
  733. if ((my_uic0msr & (UIC_MRE | UIC_MTE))
  734. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  735. /* we have a MAL interrupt */
  736. mal_isr = mfdcr (malesr);
  737. /* look for mal error */
  738. if (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE)) {
  739. mal_err (dev, mal_isr, my_uic0msr,
  740. MAL_UIC_DEF, MAL_UIC_ERR);
  741. serviced = 1;
  742. rc = 0;
  743. }
  744. }
  745. /* port by port dispatch of emac interrupts */
  746. if (hw_p->devnum == 0) {
  747. if (UIC_ETH0 & my_uic1msr) { /* look for EMAC errors */
  748. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  749. if ((hw_p->emac_ier & emac_isr) != 0) {
  750. emac_err (dev, emac_isr);
  751. serviced = 1;
  752. rc = 0;
  753. }
  754. }
  755. if ((hw_p->emac_ier & emac_isr)
  756. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  757. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  758. mtdcr (uic1sr, UIC_ETH0 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  759. return (rc); /* we had errors so get out */
  760. }
  761. }
  762. if (hw_p->devnum == 1) {
  763. if (UIC_ETH1 & my_uic1msr) { /* look for EMAC errors */
  764. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  765. if ((hw_p->emac_ier & emac_isr) != 0) {
  766. emac_err (dev, emac_isr);
  767. serviced = 1;
  768. rc = 0;
  769. }
  770. }
  771. if ((hw_p->emac_ier & emac_isr)
  772. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  773. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  774. mtdcr (uic1sr, UIC_ETH1 | UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  775. return (rc); /* we had errors so get out */
  776. }
  777. }
  778. #if defined (CONFIG_440_GX)
  779. if (hw_p->devnum == 2) {
  780. if (UIC_ETH2 & my_uic2msr) { /* look for EMAC errors */
  781. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  782. if ((hw_p->emac_ier & emac_isr) != 0) {
  783. emac_err (dev, emac_isr);
  784. serviced = 1;
  785. rc = 0;
  786. }
  787. }
  788. if ((hw_p->emac_ier & emac_isr)
  789. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  790. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  791. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  792. mtdcr (uic2sr, UIC_ETH2);
  793. return (rc); /* we had errors so get out */
  794. }
  795. }
  796. if (hw_p->devnum == 3) {
  797. if (UIC_ETH3 & my_uic2msr) { /* look for EMAC errors */
  798. emac_isr = in32 (EMAC_ISR + hw_p->hw_addr);
  799. if ((hw_p->emac_ier & emac_isr) != 0) {
  800. emac_err (dev, emac_isr);
  801. serviced = 1;
  802. rc = 0;
  803. }
  804. }
  805. if ((hw_p->emac_ier & emac_isr)
  806. || (my_uic1msr & (UIC_MS | UIC_MTDE | UIC_MRDE))) {
  807. mtdcr (uic0sr, UIC_MRE | UIC_MTE); /* Clear */
  808. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  809. mtdcr (uic2sr, UIC_ETH3);
  810. return (rc); /* we had errors so get out */
  811. }
  812. }
  813. #endif /* CONFIG_440_GX */
  814. /* handle MAX TX EOB interrupt from a tx */
  815. if (my_uic0msr & UIC_MTE) {
  816. mal_rx_eob = mfdcr (maltxeobisr);
  817. mtdcr (maltxeobisr, mal_rx_eob);
  818. mtdcr (uic0sr, UIC_MTE);
  819. }
  820. /* handle MAL RX EOB interupt from a receive */
  821. /* check for EOB on valid channels */
  822. if (my_uic0msr & UIC_MRE) {
  823. mal_rx_eob = mfdcr (malrxeobisr);
  824. if ((mal_rx_eob & (0x80000000 >> hw_p->devnum)) != 0) { /* call emac routine for channel x */
  825. /* clear EOB
  826. mtdcr(malrxeobisr, mal_rx_eob); */
  827. enet_rcv (dev, emac_isr);
  828. /* indicate that we serviced an interrupt */
  829. serviced = 1;
  830. rc = 0;
  831. }
  832. }
  833. mtdcr (uic0sr, UIC_MRE); /* Clear */
  834. mtdcr (uic1sr, UIC_MS | UIC_MTDE | UIC_MRDE); /* Clear */
  835. switch (hw_p->devnum) {
  836. case 0:
  837. mtdcr (uic1sr, UIC_ETH0);
  838. break;
  839. case 1:
  840. mtdcr (uic1sr, UIC_ETH1);
  841. break;
  842. #if defined (CONFIG_440_GX)
  843. case 2:
  844. mtdcr (uic2sr, UIC_ETH2);
  845. break;
  846. case 3:
  847. mtdcr (uic2sr, UIC_ETH3);
  848. break;
  849. #endif /* CONFIG_440_GX */
  850. default:
  851. break;
  852. }
  853. } while (serviced);
  854. return (rc);
  855. }
  856. /*-----------------------------------------------------------------------------+
  857. * MAL Error Routine
  858. *-----------------------------------------------------------------------------*/
  859. static void mal_err (struct eth_device *dev, unsigned long isr,
  860. unsigned long uic, unsigned long maldef,
  861. unsigned long mal_errr)
  862. {
  863. EMAC_440GX_HW_PST hw_p = dev->priv;
  864. mtdcr (malesr, isr); /* clear interrupt */
  865. /* clear DE interrupt */
  866. mtdcr (maltxdeir, 0xC0000000);
  867. mtdcr (malrxdeir, 0x80000000);
  868. #ifdef INFO_440_ENET
  869. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  870. #endif
  871. eth_init (hw_p->bis); /* start again... */
  872. }
  873. /*-----------------------------------------------------------------------------+
  874. * EMAC Error Routine
  875. *-----------------------------------------------------------------------------*/
  876. static void emac_err (struct eth_device *dev, unsigned long isr)
  877. {
  878. EMAC_440GX_HW_PST hw_p = dev->priv;
  879. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  880. out32 (EMAC_ISR + hw_p->hw_addr, isr);
  881. }
  882. /*-----------------------------------------------------------------------------+
  883. * enet_rcv() handles the ethernet receive data
  884. *-----------------------------------------------------------------------------*/
  885. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  886. {
  887. struct enet_frame *ef_ptr;
  888. unsigned long data_len;
  889. unsigned long rx_eob_isr;
  890. EMAC_440GX_HW_PST hw_p = dev->priv;
  891. int handled = 0;
  892. int i;
  893. int loop_count = 0;
  894. rx_eob_isr = mfdcr (malrxeobisr);
  895. if ((0x80000000 >> hw_p->devnum) & rx_eob_isr) {
  896. /* clear EOB */
  897. mtdcr (malrxeobisr, rx_eob_isr);
  898. /* EMAC RX done */
  899. while (1) { /* do all */
  900. i = hw_p->rx_slot;
  901. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  902. || (loop_count >= NUM_RX_BUFF))
  903. break;
  904. loop_count++;
  905. hw_p->rx_slot++;
  906. if (NUM_RX_BUFF == hw_p->rx_slot)
  907. hw_p->rx_slot = 0;
  908. handled++;
  909. data_len = (unsigned long) hw_p->rx[i].data_len; /* Get len */
  910. if (data_len) {
  911. if (data_len > ENET_MAX_MTU) /* Check len */
  912. data_len = 0;
  913. else {
  914. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  915. data_len = 0;
  916. hw_p->stats.rx_err_log[hw_p->
  917. rx_err_index]
  918. = hw_p->rx[i].ctrl;
  919. hw_p->rx_err_index++;
  920. if (hw_p->rx_err_index ==
  921. MAX_ERR_LOG)
  922. hw_p->rx_err_index =
  923. 0;
  924. } /* emac_erros */
  925. } /* data_len < max mtu */
  926. } /* if data_len */
  927. if (!data_len) { /* no data */
  928. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  929. hw_p->stats.data_len_err++; /* Error at Rx */
  930. }
  931. /* !data_len */
  932. /* AS.HARNOIS */
  933. /* Check if user has already eaten buffer */
  934. /* if not => ERROR */
  935. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  936. if (hw_p->is_receiving)
  937. printf ("ERROR : Receive buffers are full!\n");
  938. break;
  939. } else {
  940. hw_p->stats.rx_frames++;
  941. hw_p->stats.rx += data_len;
  942. ef_ptr = (struct enet_frame *) hw_p->rx[i].
  943. data_ptr;
  944. #ifdef INFO_440_ENET
  945. hw_p->stats.pkts_rx++;
  946. #endif
  947. /* AS.HARNOIS
  948. * use ring buffer
  949. */
  950. hw_p->rx_ready[hw_p->rx_i_index] = i;
  951. hw_p->rx_i_index++;
  952. if (NUM_RX_BUFF == hw_p->rx_i_index)
  953. hw_p->rx_i_index = 0;
  954. /* printf("X"); /|* test-only *|/ */
  955. /* AS.HARNOIS
  956. * free receive buffer only when
  957. * buffer has been handled (eth_rx)
  958. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  959. */
  960. } /* if data_len */
  961. } /* while */
  962. } /* if EMACK_RXCHL */
  963. }
  964. static int ppc_440x_eth_rx (struct eth_device *dev)
  965. {
  966. int length;
  967. int user_index;
  968. unsigned long msr;
  969. EMAC_440GX_HW_PST hw_p = dev->priv;
  970. hw_p->is_receiving = 1; /* tell driver */
  971. for (;;) {
  972. /* AS.HARNOIS
  973. * use ring buffer and
  974. * get index from rx buffer desciptor queue
  975. */
  976. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  977. if (user_index == -1) {
  978. length = -1;
  979. break; /* nothing received - leave for() loop */
  980. }
  981. msr = mfmsr ();
  982. mtmsr (msr & ~(MSR_EE));
  983. length = hw_p->rx[user_index].data_len;
  984. /* Pass the packet up to the protocol layers. */
  985. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  986. /* NetReceive(NetRxPackets[i], length); */
  987. NetReceive (NetRxPackets[user_index], length - 4);
  988. /* Free Recv Buffer */
  989. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  990. /* Free rx buffer descriptor queue */
  991. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  992. hw_p->rx_u_index++;
  993. if (NUM_RX_BUFF == hw_p->rx_u_index)
  994. hw_p->rx_u_index = 0;
  995. #ifdef INFO_440_ENET
  996. hw_p->stats.pkts_handled++;
  997. #endif
  998. mtmsr (msr); /* Enable IRQ's */
  999. }
  1000. hw_p->is_receiving = 0; /* tell driver */
  1001. return length;
  1002. }
  1003. int ppc_440x_eth_initialize (bd_t * bis)
  1004. {
  1005. static int virgin = 0;
  1006. unsigned long pfc1;
  1007. struct eth_device *dev;
  1008. int eth_num = 0;
  1009. EMAC_440GX_HW_PST hw = NULL;
  1010. mfsdr (sdr_pfc1, pfc1);
  1011. pfc1 &= ~(0x01e00000);
  1012. pfc1 |= 0x01200000;
  1013. mtsdr (sdr_pfc1, pfc1);
  1014. /* set phy num and mode */
  1015. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  1016. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  1017. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  1018. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  1019. bis->bi_phymode[0] = 0;
  1020. bis->bi_phymode[1] = 0;
  1021. bis->bi_phymode[2] = 2;
  1022. bis->bi_phymode[3] = 2;
  1023. #if defined (CONFIG_440_GX)
  1024. ppc_440x_eth_setup_bridge(0, bis);
  1025. #endif
  1026. for (eth_num = 0; eth_num < EMAC_NUM_DEV; eth_num++) {
  1027. /* See if we can actually bring up the interface, otherwise, skip it */
  1028. switch (eth_num) {
  1029. default: /* fall through */
  1030. case 0:
  1031. if (memcmp (bis->bi_enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  1032. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1033. continue;
  1034. }
  1035. break;
  1036. #ifdef CONFIG_HAS_ETH1
  1037. case 1:
  1038. if (memcmp (bis->bi_enet1addr, "\0\0\0\0\0\0", 6) == 0) {
  1039. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1040. continue;
  1041. }
  1042. break;
  1043. #endif
  1044. #ifdef CONFIG_HAS_ETH2
  1045. case 2:
  1046. if (memcmp (bis->bi_enet2addr, "\0\0\0\0\0\0", 6) == 0) {
  1047. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1048. continue;
  1049. }
  1050. break;
  1051. #endif
  1052. #ifdef CONFIG_HAS_ETH3
  1053. case 3:
  1054. if (memcmp (bis->bi_enet3addr, "\0\0\0\0\0\0", 6) == 0) {
  1055. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1056. continue;
  1057. }
  1058. break;
  1059. #endif
  1060. }
  1061. /* Allocate device structure */
  1062. dev = (struct eth_device *) malloc (sizeof (*dev));
  1063. if (dev == NULL) {
  1064. printf ("ppc_440x_eth_initialize: "
  1065. "Cannot allocate eth_device %d\n", eth_num);
  1066. return (-1);
  1067. }
  1068. memset(dev, 0, sizeof(*dev));
  1069. /* Allocate our private use data */
  1070. hw = (EMAC_440GX_HW_PST) malloc (sizeof (*hw));
  1071. if (hw == NULL) {
  1072. printf ("ppc_440x_eth_initialize: "
  1073. "Cannot allocate private hw data for eth_device %d",
  1074. eth_num);
  1075. free (dev);
  1076. return (-1);
  1077. }
  1078. memset(hw, 0, sizeof(*hw));
  1079. switch (eth_num) {
  1080. default: /* fall through */
  1081. case 0:
  1082. hw->hw_addr = 0;
  1083. memcpy (dev->enetaddr, bis->bi_enetaddr, 6);
  1084. break;
  1085. #ifdef CONFIG_HAS_ETH1
  1086. case 1:
  1087. hw->hw_addr = 0x100;
  1088. memcpy (dev->enetaddr, bis->bi_enet1addr, 6);
  1089. break;
  1090. #endif
  1091. #ifdef CONFIG_HAS_ETH2
  1092. case 2:
  1093. hw->hw_addr = 0x400;
  1094. memcpy (dev->enetaddr, bis->bi_enet2addr, 6);
  1095. break;
  1096. #endif
  1097. #ifdef CONFIG_HAS_ETH3
  1098. case 3:
  1099. hw->hw_addr = 0x600;
  1100. memcpy (dev->enetaddr, bis->bi_enet3addr, 6);
  1101. break;
  1102. #endif
  1103. }
  1104. hw->devnum = eth_num;
  1105. sprintf (dev->name, "ppc_440x_eth%d", eth_num);
  1106. dev->priv = (void *) hw;
  1107. dev->init = ppc_440x_eth_init;
  1108. dev->halt = ppc_440x_eth_halt;
  1109. dev->send = ppc_440x_eth_send;
  1110. dev->recv = ppc_440x_eth_rx;
  1111. if (0 == virgin) {
  1112. /* set the MAL IER ??? names may change with new spec ??? */
  1113. mal_ier =
  1114. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  1115. MAL_IER_OPBE | MAL_IER_PLBE;
  1116. mtdcr (malesr, 0xffffffff); /* clear pending interrupts */
  1117. mtdcr (maltxdeir, 0xffffffff); /* clear pending interrupts */
  1118. mtdcr (malrxdeir, 0xffffffff); /* clear pending interrupts */
  1119. mtdcr (malier, mal_ier);
  1120. /* install MAL interrupt handler */
  1121. irq_install_handler (VECNUM_MS,
  1122. (interrupt_handler_t *) enetInt,
  1123. dev);
  1124. irq_install_handler (VECNUM_MTE,
  1125. (interrupt_handler_t *) enetInt,
  1126. dev);
  1127. irq_install_handler (VECNUM_MRE,
  1128. (interrupt_handler_t *) enetInt,
  1129. dev);
  1130. irq_install_handler (VECNUM_TXDE,
  1131. (interrupt_handler_t *) enetInt,
  1132. dev);
  1133. irq_install_handler (VECNUM_RXDE,
  1134. (interrupt_handler_t *) enetInt,
  1135. dev);
  1136. virgin = 1;
  1137. }
  1138. eth_register (dev);
  1139. } /* end for each supported device */
  1140. return (1);
  1141. }
  1142. #endif /* CONFIG_440 && CONFIG_NET_MULTI */