4xx_enet.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  1. /*-----------------------------------------------------------------------------+
  2. * This source code is dual-licensed. You may use it under the terms of the
  3. * GNU General Public License version 2, or under the license below.
  4. *
  5. * This source code has been made available to you by IBM on an AS-IS
  6. * basis. Anyone receiving this source is licensed under IBM
  7. * copyrights to use it in any way he or she deems fit, including
  8. * copying it, modifying it, compiling it, and redistributing it either
  9. * with or without modifications. No license under IBM patents or
  10. * patent applications is to be implied by the copyright license.
  11. *
  12. * Any user of this software should understand that IBM cannot provide
  13. * technical support for this software and will not be responsible for
  14. * any consequences resulting from the use of this software.
  15. *
  16. * Any person who transfers this source code or any derivative work
  17. * must include the IBM copyright notice, this paragraph, and the
  18. * preceding two paragraphs in the transferred software.
  19. *
  20. * COPYRIGHT I B M CORPORATION 1995
  21. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  22. *-----------------------------------------------------------------------------*/
  23. /*-----------------------------------------------------------------------------+
  24. *
  25. * File Name: enetemac.c
  26. *
  27. * Function: Device driver for the ethernet EMAC3 macro on the 405GP.
  28. *
  29. * Author: Mark Wisner
  30. *
  31. * Change Activity-
  32. *
  33. * Date Description of Change BY
  34. * --------- --------------------- ---
  35. * 05-May-99 Created MKW
  36. * 27-Jun-99 Clean up JWB
  37. * 16-Jul-99 Added MAL error recovery and better IP packet handling MKW
  38. * 29-Jul-99 Added Full duplex support MKW
  39. * 06-Aug-99 Changed names for Mal CR reg MKW
  40. * 23-Aug-99 Turned off SYE when running at 10Mbs MKW
  41. * 24-Aug-99 Marked descriptor empty after call_xlc MKW
  42. * 07-Sep-99 Set MAL RX buffer size reg to ENET_MAX_MTU_ALIGNED / 16 MCG
  43. * to avoid chaining maximum sized packets. Push starting
  44. * RX descriptor address up to the next cache line boundary.
  45. * 16-Jan-00 Added support for booting with IP of 0x0 MKW
  46. * 15-Mar-00 Updated enetInit() to enable broadcast addresses in the
  47. * EMAC0_RXM register. JWB
  48. * 12-Mar-01 anne-sophie.harnois@nextream.fr
  49. * - Variables are compatible with those already defined in
  50. * include/net.h
  51. * - Receive buffer descriptor ring is used to send buffers
  52. * to the user
  53. * - Info print about send/received/handled packet number if
  54. * INFO_405_ENET is set
  55. * 17-Apr-01 stefan.roese@esd-electronics.com
  56. * - MAL reset in "eth_halt" included
  57. * - Enet speed and duplex output now in one line
  58. * 08-May-01 stefan.roese@esd-electronics.com
  59. * - MAL error handling added (eth_init called again)
  60. * 13-Nov-01 stefan.roese@esd-electronics.com
  61. * - Set IST bit in EMAC0_MR1 reg upon 100MBit or full duplex
  62. * 04-Jan-02 stefan.roese@esd-electronics.com
  63. * - Wait for PHY auto negotiation to complete added
  64. * 06-Feb-02 stefan.roese@esd-electronics.com
  65. * - Bug fixed in waiting for auto negotiation to complete
  66. * 26-Feb-02 stefan.roese@esd-electronics.com
  67. * - rx and tx buffer descriptors now allocated (no fixed address
  68. * used anymore)
  69. * 17-Jun-02 stefan.roese@esd-electronics.com
  70. * - MAL error debug printf 'M' removed (rx de interrupt may
  71. * occur upon many incoming packets with only 4 rx buffers).
  72. *-----------------------------------------------------------------------------*
  73. * 17-Nov-03 travis.sawyer@sandburst.com
  74. * - ported from 405gp_enet.c to utilized upto 4 EMAC ports
  75. * in the 440GX. This port should work with the 440GP
  76. * (2 EMACs) also
  77. * 15-Aug-05 sr@denx.de
  78. * - merged 405gp_enet.c and 440gx_enet.c to generic 4xx_enet.c
  79. now handling all 4xx cpu's.
  80. *-----------------------------------------------------------------------------*/
  81. #include <config.h>
  82. #include <common.h>
  83. #include <net.h>
  84. #include <asm/processor.h>
  85. #include <asm/io.h>
  86. #include <asm/cache.h>
  87. #include <asm/mmu.h>
  88. #include <commproc.h>
  89. #include <asm/ppc4xx.h>
  90. #include <asm/ppc4xx-emac.h>
  91. #include <asm/ppc4xx-mal.h>
  92. #include <miiphy.h>
  93. #include <malloc.h>
  94. #include <linux/compiler.h>
  95. #if !(defined(CONFIG_MII) || defined(CONFIG_CMD_MII))
  96. #error "CONFIG_MII has to be defined!"
  97. #endif
  98. #define EMAC_RESET_TIMEOUT 1000 /* 1000 ms reset timeout */
  99. #define PHY_AUTONEGOTIATE_TIMEOUT 5000 /* 5000 ms autonegotiate timeout */
  100. /* Ethernet Transmit and Receive Buffers */
  101. /* AS.HARNOIS
  102. * In the same way ENET_MAX_MTU and ENET_MAX_MTU_ALIGNED are set from
  103. * PKTSIZE and PKTSIZE_ALIGN (include/net.h)
  104. */
  105. #define ENET_MAX_MTU PKTSIZE
  106. #define ENET_MAX_MTU_ALIGNED PKTSIZE_ALIGN
  107. /*-----------------------------------------------------------------------------+
  108. * Defines for MAL/EMAC interrupt conditions as reported in the UIC (Universal
  109. * Interrupt Controller).
  110. *-----------------------------------------------------------------------------*/
  111. #define ETH_IRQ_NUM(dev) (VECNUM_ETH0 + ((dev) * VECNUM_ETH1_OFFS))
  112. #if defined(CONFIG_HAS_ETH3)
  113. #if !defined(CONFIG_440GX)
  114. #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
  115. UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
  116. #else
  117. /* Unfortunately 440GX spreads EMAC interrupts on multiple UIC's */
  118. #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
  119. #define UIC_ETHxB (UIC_MASK(ETH_IRQ_NUM(2)) || UIC_MASK(ETH_IRQ_NUM(3)))
  120. #endif /* !defined(CONFIG_440GX) */
  121. #elif defined(CONFIG_HAS_ETH2)
  122. #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)) || \
  123. UIC_MASK(ETH_IRQ_NUM(2)))
  124. #elif defined(CONFIG_HAS_ETH1)
  125. #define UIC_ETHx (UIC_MASK(ETH_IRQ_NUM(0)) || UIC_MASK(ETH_IRQ_NUM(1)))
  126. #else
  127. #define UIC_ETHx UIC_MASK(ETH_IRQ_NUM(0))
  128. #endif
  129. /*
  130. * Define a default version for UIC_ETHxB for non 440GX so that we can
  131. * use common code for all 4xx variants
  132. */
  133. #if !defined(UIC_ETHxB)
  134. #define UIC_ETHxB 0
  135. #endif
  136. #define UIC_MAL_SERR UIC_MASK(VECNUM_MAL_SERR)
  137. #define UIC_MAL_TXDE UIC_MASK(VECNUM_MAL_TXDE)
  138. #define UIC_MAL_RXDE UIC_MASK(VECNUM_MAL_RXDE)
  139. #define UIC_MAL_TXEOB UIC_MASK(VECNUM_MAL_TXEOB)
  140. #define UIC_MAL_RXEOB UIC_MASK(VECNUM_MAL_RXEOB)
  141. #define MAL_UIC_ERR (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)
  142. #define MAL_UIC_DEF (UIC_MAL_RXEOB | MAL_UIC_ERR)
  143. /*
  144. * We have 3 different interrupt types:
  145. * - MAL interrupts indicating successful transfer
  146. * - MAL error interrupts indicating MAL related errors
  147. * - EMAC interrupts indicating EMAC related errors
  148. *
  149. * All those interrupts can be on different UIC's, but since
  150. * now at least all interrupts from one type are on the same
  151. * UIC. Only exception is 440GX where the EMAC interrupts are
  152. * spread over two UIC's!
  153. */
  154. #if defined(CONFIG_440GX)
  155. #define UIC_BASE_MAL UIC1_DCR_BASE
  156. #define UIC_BASE_MAL_ERR UIC2_DCR_BASE
  157. #define UIC_BASE_EMAC UIC2_DCR_BASE
  158. #define UIC_BASE_EMAC_B UIC3_DCR_BASE
  159. #else
  160. #define UIC_BASE_MAL (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_TXEOB) * 0x10))
  161. #define UIC_BASE_MAL_ERR (UIC0_DCR_BASE + (UIC_NR(VECNUM_MAL_SERR) * 0x10))
  162. #define UIC_BASE_EMAC (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
  163. #define UIC_BASE_EMAC_B (UIC0_DCR_BASE + (UIC_NR(ETH_IRQ_NUM(0)) * 0x10))
  164. #endif
  165. #undef INFO_4XX_ENET
  166. #define BI_PHYMODE_NONE 0
  167. #define BI_PHYMODE_ZMII 1
  168. #define BI_PHYMODE_RGMII 2
  169. #define BI_PHYMODE_GMII 3
  170. #define BI_PHYMODE_RTBI 4
  171. #define BI_PHYMODE_TBI 5
  172. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  173. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  174. defined(CONFIG_405EX)
  175. #define BI_PHYMODE_SMII 6
  176. #define BI_PHYMODE_MII 7
  177. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  178. #define BI_PHYMODE_RMII 8
  179. #endif
  180. #endif
  181. #define BI_PHYMODE_SGMII 9
  182. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  183. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  184. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  185. defined(CONFIG_405EX)
  186. #define SDR0_MFR_ETH_CLK_SEL_V(n) ((0x01<<27) / (n+1))
  187. #endif
  188. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  189. #define SDR0_ETH_CFG_CLK_SEL_V(n) (0x01 << (8 + n))
  190. #endif
  191. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  192. #define MAL_RX_CHAN_MUL 8 /* 460EX/GT uses MAL channel 8 for EMAC1 */
  193. #else
  194. #define MAL_RX_CHAN_MUL 1
  195. #endif
  196. /*--------------------------------------------------------------------+
  197. * Fixed PHY (PHY-less) support for Ethernet Ports.
  198. *--------------------------------------------------------------------*/
  199. /*
  200. * Some boards do not have a PHY for each ethernet port. These ports
  201. * are known as Fixed PHY (or PHY-less) ports. For such ports, set
  202. * the appropriate CONFIG_PHY_ADDR equal to CONFIG_FIXED_PHY and
  203. * then define CONFIG_SYS_FIXED_PHY_PORTS to define what the speed and
  204. * duplex should be for these ports in the board configuration
  205. * file.
  206. *
  207. * For Example:
  208. * #define CONFIG_FIXED_PHY 0xFFFFFFFF
  209. *
  210. * #define CONFIG_PHY_ADDR CONFIG_FIXED_PHY
  211. * #define CONFIG_PHY1_ADDR 1
  212. * #define CONFIG_PHY2_ADDR CONFIG_FIXED_PHY
  213. * #define CONFIG_PHY3_ADDR 3
  214. *
  215. * #define CONFIG_SYS_FIXED_PHY_PORT(devnum,speed,duplex) \
  216. * {devnum, speed, duplex},
  217. *
  218. * #define CONFIG_SYS_FIXED_PHY_PORTS \
  219. * CONFIG_SYS_FIXED_PHY_PORT(0,1000,FULL) \
  220. * CONFIG_SYS_FIXED_PHY_PORT(2,100,HALF)
  221. */
  222. #ifndef CONFIG_FIXED_PHY
  223. #define CONFIG_FIXED_PHY 0xFFFFFFFF /* Fixed PHY (PHY-less) */
  224. #endif
  225. #ifndef CONFIG_SYS_FIXED_PHY_PORTS
  226. #define CONFIG_SYS_FIXED_PHY_PORTS /* default is an empty array */
  227. #endif
  228. struct fixed_phy_port {
  229. unsigned int devnum; /* ethernet port */
  230. unsigned int speed; /* specified speed 10,100 or 1000 */
  231. unsigned int duplex; /* specified duplex FULL or HALF */
  232. };
  233. static const struct fixed_phy_port fixed_phy_port[] = {
  234. CONFIG_SYS_FIXED_PHY_PORTS /* defined in board configuration file */
  235. };
  236. /*-----------------------------------------------------------------------------+
  237. * Global variables. TX and RX descriptors and buffers.
  238. *-----------------------------------------------------------------------------*/
  239. /*
  240. * Get count of EMAC devices (doesn't have to be the max. possible number
  241. * supported by the cpu)
  242. *
  243. * CONFIG_BOARD_EMAC_COUNT added so now a "dynamic" way to configure the
  244. * EMAC count is possible. As it is needed for the Kilauea/Haleakala
  245. * 405EX/405EXr eval board, using the same binary.
  246. */
  247. #if defined(CONFIG_BOARD_EMAC_COUNT)
  248. #define LAST_EMAC_NUM board_emac_count()
  249. #else /* CONFIG_BOARD_EMAC_COUNT */
  250. #if defined(CONFIG_HAS_ETH3)
  251. #define LAST_EMAC_NUM 4
  252. #elif defined(CONFIG_HAS_ETH2)
  253. #define LAST_EMAC_NUM 3
  254. #elif defined(CONFIG_HAS_ETH1)
  255. #define LAST_EMAC_NUM 2
  256. #else
  257. #define LAST_EMAC_NUM 1
  258. #endif
  259. #endif /* CONFIG_BOARD_EMAC_COUNT */
  260. /* normal boards start with EMAC0 */
  261. #if !defined(CONFIG_EMAC_NR_START)
  262. #define CONFIG_EMAC_NR_START 0
  263. #endif
  264. #define MAL_RX_DESC_SIZE 2048
  265. #define MAL_TX_DESC_SIZE 2048
  266. #define MAL_ALLOC_SIZE (MAL_TX_DESC_SIZE + MAL_RX_DESC_SIZE)
  267. /*-----------------------------------------------------------------------------+
  268. * Prototypes and externals.
  269. *-----------------------------------------------------------------------------*/
  270. static void enet_rcv (struct eth_device *dev, unsigned long malisr);
  271. int enetInt (struct eth_device *dev);
  272. static void mal_err (struct eth_device *dev, unsigned long isr,
  273. unsigned long uic, unsigned long maldef,
  274. unsigned long mal_errr);
  275. static void emac_err (struct eth_device *dev, unsigned long isr);
  276. extern int phy_setup_aneg (char *devname, unsigned char addr);
  277. extern int emac4xx_miiphy_read (const char *devname, unsigned char addr,
  278. unsigned char reg, unsigned short *value);
  279. extern int emac4xx_miiphy_write (const char *devname, unsigned char addr,
  280. unsigned char reg, unsigned short value);
  281. int board_emac_count(void);
  282. static void emac_loopback_enable(EMAC_4XX_HW_PST hw_p)
  283. {
  284. #if defined(CONFIG_440SPE) || \
  285. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  286. defined(CONFIG_405EX)
  287. u32 val;
  288. mfsdr(SDR0_MFR, val);
  289. val |= SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
  290. mtsdr(SDR0_MFR, val);
  291. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  292. u32 val;
  293. mfsdr(SDR0_ETH_CFG, val);
  294. val |= SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
  295. mtsdr(SDR0_ETH_CFG, val);
  296. #endif
  297. }
  298. static void emac_loopback_disable(EMAC_4XX_HW_PST hw_p)
  299. {
  300. #if defined(CONFIG_440SPE) || \
  301. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  302. defined(CONFIG_405EX)
  303. u32 val;
  304. mfsdr(SDR0_MFR, val);
  305. val &= ~SDR0_MFR_ETH_CLK_SEL_V(hw_p->devnum);
  306. mtsdr(SDR0_MFR, val);
  307. #elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
  308. u32 val;
  309. mfsdr(SDR0_ETH_CFG, val);
  310. val &= ~SDR0_ETH_CFG_CLK_SEL_V(hw_p->devnum);
  311. mtsdr(SDR0_ETH_CFG, val);
  312. #endif
  313. }
  314. /*-----------------------------------------------------------------------------+
  315. | ppc_4xx_eth_halt
  316. | Disable MAL channel, and EMACn
  317. +-----------------------------------------------------------------------------*/
  318. static void ppc_4xx_eth_halt (struct eth_device *dev)
  319. {
  320. EMAC_4XX_HW_PST hw_p = dev->priv;
  321. u32 val = 10000;
  322. out_be32((void *)EMAC0_IER + hw_p->hw_addr, 0x00000000); /* disable emac interrupts */
  323. /* 1st reset MAL channel */
  324. /* Note: writing a 0 to a channel has no effect */
  325. #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  326. mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> (hw_p->devnum * 2)));
  327. #else
  328. mtdcr (MAL0_TXCARR, (MAL_CR_MMSR >> hw_p->devnum));
  329. #endif
  330. mtdcr (MAL0_RXCARR, (MAL_CR_MMSR >> hw_p->devnum));
  331. /* wait for reset */
  332. while (mfdcr (MAL0_RXCASR) & (MAL_CR_MMSR >> hw_p->devnum)) {
  333. udelay (1000); /* Delay 1 MS so as not to hammer the register */
  334. val--;
  335. if (val == 0)
  336. break;
  337. }
  338. /* provide clocks for EMAC internal loopback */
  339. emac_loopback_enable(hw_p);
  340. /* EMAC RESET */
  341. out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
  342. /* remove clocks for EMAC internal loopback */
  343. emac_loopback_disable(hw_p);
  344. #ifndef CONFIG_NETCONSOLE
  345. hw_p->print_speed = 1; /* print speed message again next time */
  346. #endif
  347. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  348. /* don't bypass the TAHOE0/TAHOE1 cores for Linux */
  349. mfsdr(SDR0_ETH_CFG, val);
  350. val &= ~(SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
  351. mtsdr(SDR0_ETH_CFG, val);
  352. #endif
  353. return;
  354. }
  355. #if defined (CONFIG_440GX)
  356. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  357. {
  358. unsigned long pfc1;
  359. unsigned long zmiifer;
  360. unsigned long rmiifer;
  361. mfsdr(SDR0_PFC1, pfc1);
  362. pfc1 = SDR0_PFC1_EPS_DECODE(pfc1);
  363. zmiifer = 0;
  364. rmiifer = 0;
  365. switch (pfc1) {
  366. case 1:
  367. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  368. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
  369. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
  370. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
  371. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  372. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  373. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  374. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  375. break;
  376. case 2:
  377. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  378. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  379. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
  380. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
  381. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  382. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  383. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  384. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  385. break;
  386. case 3:
  387. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  388. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  389. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  390. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  391. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  392. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  393. break;
  394. case 4:
  395. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  396. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  397. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (2);
  398. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V (3);
  399. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  400. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  401. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  402. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  403. break;
  404. case 5:
  405. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  406. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  407. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (2);
  408. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
  409. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  410. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  411. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  412. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  413. break;
  414. case 6:
  415. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (0);
  416. zmiifer |= ZMII_FER_SMII << ZMII_FER_V (1);
  417. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  418. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  419. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  420. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  421. break;
  422. case 0:
  423. default:
  424. zmiifer = ZMII_FER_MII << ZMII_FER_V(devnum);
  425. rmiifer = 0x0;
  426. bis->bi_phymode[0] = BI_PHYMODE_ZMII;
  427. bis->bi_phymode[1] = BI_PHYMODE_ZMII;
  428. bis->bi_phymode[2] = BI_PHYMODE_ZMII;
  429. bis->bi_phymode[3] = BI_PHYMODE_ZMII;
  430. break;
  431. }
  432. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  433. zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
  434. out_be32((void *)ZMII0_FER, zmiifer);
  435. out_be32((void *)RGMII_FER, rmiifer);
  436. return ((int)pfc1);
  437. }
  438. #endif /* CONFIG_440_GX */
  439. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
  440. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  441. {
  442. unsigned long zmiifer=0x0;
  443. unsigned long pfc1;
  444. mfsdr(SDR0_PFC1, pfc1);
  445. pfc1 &= SDR0_PFC1_SELECT_MASK;
  446. switch (pfc1) {
  447. case SDR0_PFC1_SELECT_CONFIG_2:
  448. /* 1 x GMII port */
  449. out_be32((void *)ZMII0_FER, 0x00);
  450. out_be32((void *)RGMII_FER, 0x00000037);
  451. bis->bi_phymode[0] = BI_PHYMODE_GMII;
  452. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  453. break;
  454. case SDR0_PFC1_SELECT_CONFIG_4:
  455. /* 2 x RGMII ports */
  456. out_be32((void *)ZMII0_FER, 0x00);
  457. out_be32((void *)RGMII_FER, 0x00000055);
  458. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  459. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  460. break;
  461. case SDR0_PFC1_SELECT_CONFIG_6:
  462. /* 2 x SMII ports */
  463. out_be32((void *)ZMII0_FER,
  464. ((ZMII_FER_SMII) << ZMII_FER_V(0)) |
  465. ((ZMII_FER_SMII) << ZMII_FER_V(1)));
  466. out_be32((void *)RGMII_FER, 0x00000000);
  467. bis->bi_phymode[0] = BI_PHYMODE_SMII;
  468. bis->bi_phymode[1] = BI_PHYMODE_SMII;
  469. break;
  470. case SDR0_PFC1_SELECT_CONFIG_1_2:
  471. /* only 1 x MII supported */
  472. out_be32((void *)ZMII0_FER, (ZMII_FER_MII) << ZMII_FER_V(0));
  473. out_be32((void *)RGMII_FER, 0x00000000);
  474. bis->bi_phymode[0] = BI_PHYMODE_MII;
  475. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  476. break;
  477. default:
  478. break;
  479. }
  480. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  481. zmiifer = in_be32((void *)ZMII0_FER);
  482. zmiifer |= (ZMII_FER_MDI) << ZMII_FER_V(devnum);
  483. out_be32((void *)ZMII0_FER, zmiifer);
  484. return ((int)0x0);
  485. }
  486. #endif /* CONFIG_440EPX */
  487. #if defined(CONFIG_405EX)
  488. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  489. {
  490. u32 rgmiifer = 0;
  491. /*
  492. * The 405EX(r)'s RGMII bridge can operate in one of several
  493. * modes, only one of which (2 x RGMII) allows the
  494. * simultaneous use of both EMACs on the 405EX.
  495. */
  496. switch (CONFIG_EMAC_PHY_MODE) {
  497. case EMAC_PHY_MODE_NONE:
  498. /* No ports */
  499. rgmiifer |= RGMII_FER_DIS << 0;
  500. rgmiifer |= RGMII_FER_DIS << 4;
  501. out_be32((void *)RGMII_FER, rgmiifer);
  502. bis->bi_phymode[0] = BI_PHYMODE_NONE;
  503. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  504. break;
  505. case EMAC_PHY_MODE_NONE_RGMII:
  506. /* 1 x RGMII port on channel 0 */
  507. rgmiifer |= RGMII_FER_RGMII << 0;
  508. rgmiifer |= RGMII_FER_DIS << 4;
  509. out_be32((void *)RGMII_FER, rgmiifer);
  510. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  511. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  512. break;
  513. case EMAC_PHY_MODE_RGMII_NONE:
  514. /* 1 x RGMII port on channel 1 */
  515. rgmiifer |= RGMII_FER_DIS << 0;
  516. rgmiifer |= RGMII_FER_RGMII << 4;
  517. out_be32((void *)RGMII_FER, rgmiifer);
  518. bis->bi_phymode[0] = BI_PHYMODE_NONE;
  519. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  520. break;
  521. case EMAC_PHY_MODE_RGMII_RGMII:
  522. /* 2 x RGMII ports */
  523. rgmiifer |= RGMII_FER_RGMII << 0;
  524. rgmiifer |= RGMII_FER_RGMII << 4;
  525. out_be32((void *)RGMII_FER, rgmiifer);
  526. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  527. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  528. break;
  529. case EMAC_PHY_MODE_NONE_GMII:
  530. /* 1 x GMII port on channel 0 */
  531. rgmiifer |= RGMII_FER_GMII << 0;
  532. rgmiifer |= RGMII_FER_DIS << 4;
  533. out_be32((void *)RGMII_FER, rgmiifer);
  534. bis->bi_phymode[0] = BI_PHYMODE_GMII;
  535. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  536. break;
  537. case EMAC_PHY_MODE_NONE_MII:
  538. /* 1 x MII port on channel 0 */
  539. rgmiifer |= RGMII_FER_MII << 0;
  540. rgmiifer |= RGMII_FER_DIS << 4;
  541. out_be32((void *)RGMII_FER, rgmiifer);
  542. bis->bi_phymode[0] = BI_PHYMODE_MII;
  543. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  544. break;
  545. case EMAC_PHY_MODE_GMII_NONE:
  546. /* 1 x GMII port on channel 1 */
  547. rgmiifer |= RGMII_FER_DIS << 0;
  548. rgmiifer |= RGMII_FER_GMII << 4;
  549. out_be32((void *)RGMII_FER, rgmiifer);
  550. bis->bi_phymode[0] = BI_PHYMODE_NONE;
  551. bis->bi_phymode[1] = BI_PHYMODE_GMII;
  552. break;
  553. case EMAC_PHY_MODE_MII_NONE:
  554. /* 1 x MII port on channel 1 */
  555. rgmiifer |= RGMII_FER_DIS << 0;
  556. rgmiifer |= RGMII_FER_MII << 4;
  557. out_be32((void *)RGMII_FER, rgmiifer);
  558. bis->bi_phymode[0] = BI_PHYMODE_NONE;
  559. bis->bi_phymode[1] = BI_PHYMODE_MII;
  560. break;
  561. default:
  562. break;
  563. }
  564. /* Ensure we setup mdio for this devnum and ONLY this devnum */
  565. rgmiifer = in_be32((void *)RGMII_FER);
  566. rgmiifer |= (1 << (19-devnum));
  567. out_be32((void *)RGMII_FER, rgmiifer);
  568. return ((int)0x0);
  569. }
  570. #endif /* CONFIG_405EX */
  571. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  572. int ppc_4xx_eth_setup_bridge(int devnum, bd_t * bis)
  573. {
  574. u32 eth_cfg;
  575. u32 zmiifer; /* ZMII0_FER reg. */
  576. u32 rmiifer; /* RGMII0_FER reg. Bridge 0 */
  577. u32 rmiifer1; /* RGMII0_FER reg. Bridge 1 */
  578. int mode;
  579. zmiifer = 0;
  580. rmiifer = 0;
  581. rmiifer1 = 0;
  582. #if defined(CONFIG_460EX)
  583. mode = 9;
  584. mfsdr(SDR0_ETH_CFG, eth_cfg);
  585. if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
  586. ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0))
  587. mode = 11; /* config SGMII */
  588. #else
  589. mode = 10;
  590. mfsdr(SDR0_ETH_CFG, eth_cfg);
  591. if (((eth_cfg & SDR0_ETH_CFG_SGMII0_ENABLE) > 0) &&
  592. ((eth_cfg & SDR0_ETH_CFG_SGMII1_ENABLE) > 0) &&
  593. ((eth_cfg & SDR0_ETH_CFG_SGMII2_ENABLE) > 0))
  594. mode = 12; /* config SGMII */
  595. #endif
  596. /* TODO:
  597. * NOTE: 460GT has 2 RGMII bridge cores:
  598. * emac0 ------ RGMII0_BASE
  599. * |
  600. * emac1 -----+
  601. *
  602. * emac2 ------ RGMII1_BASE
  603. * |
  604. * emac3 -----+
  605. *
  606. * 460EX has 1 RGMII bridge core:
  607. * and RGMII1_BASE is disabled
  608. * emac0 ------ RGMII0_BASE
  609. * |
  610. * emac1 -----+
  611. */
  612. /*
  613. * Right now only 2*RGMII is supported. Please extend when needed.
  614. * sr - 2008-02-19
  615. * Add SGMII support.
  616. * vg - 2008-07-28
  617. */
  618. switch (mode) {
  619. case 1:
  620. /* 1 MII - 460EX */
  621. /* GMC0 EMAC4_0, ZMII Bridge */
  622. zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
  623. bis->bi_phymode[0] = BI_PHYMODE_MII;
  624. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  625. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  626. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  627. break;
  628. case 2:
  629. /* 2 MII - 460GT */
  630. /* GMC0 EMAC4_0, GMC1 EMAC4_2, ZMII Bridge */
  631. zmiifer |= ZMII_FER_MII << ZMII_FER_V(0);
  632. zmiifer |= ZMII_FER_MII << ZMII_FER_V(2);
  633. bis->bi_phymode[0] = BI_PHYMODE_MII;
  634. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  635. bis->bi_phymode[2] = BI_PHYMODE_MII;
  636. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  637. break;
  638. case 3:
  639. /* 2 RMII - 460EX */
  640. /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
  641. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  642. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
  643. bis->bi_phymode[0] = BI_PHYMODE_RMII;
  644. bis->bi_phymode[1] = BI_PHYMODE_RMII;
  645. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  646. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  647. break;
  648. case 4:
  649. /* 4 RMII - 460GT */
  650. /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC1 EMAC4_2, GMC1, EMAC4_3 */
  651. /* ZMII Bridge */
  652. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(0);
  653. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(1);
  654. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(2);
  655. zmiifer |= ZMII_FER_RMII << ZMII_FER_V(3);
  656. bis->bi_phymode[0] = BI_PHYMODE_RMII;
  657. bis->bi_phymode[1] = BI_PHYMODE_RMII;
  658. bis->bi_phymode[2] = BI_PHYMODE_RMII;
  659. bis->bi_phymode[3] = BI_PHYMODE_RMII;
  660. break;
  661. case 5:
  662. /* 2 SMII - 460EX */
  663. /* GMC0 EMAC4_0, GMC0 EMAC4_1, ZMII Bridge */
  664. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  665. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  666. bis->bi_phymode[0] = BI_PHYMODE_SMII;
  667. bis->bi_phymode[1] = BI_PHYMODE_SMII;
  668. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  669. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  670. break;
  671. case 6:
  672. /* 4 SMII - 460GT */
  673. /* GMC0 EMAC4_0, GMC0 EMAC4_1, GMC0 EMAC4_3, GMC0 EMAC4_3 */
  674. /* ZMII Bridge */
  675. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(0);
  676. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(1);
  677. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(2);
  678. zmiifer |= ZMII_FER_SMII << ZMII_FER_V(3);
  679. bis->bi_phymode[0] = BI_PHYMODE_SMII;
  680. bis->bi_phymode[1] = BI_PHYMODE_SMII;
  681. bis->bi_phymode[2] = BI_PHYMODE_SMII;
  682. bis->bi_phymode[3] = BI_PHYMODE_SMII;
  683. break;
  684. case 7:
  685. /* This is the default mode that we want for board bringup - Maple */
  686. /* 1 GMII - 460EX */
  687. /* GMC0 EMAC4_0, RGMII Bridge 0 */
  688. rmiifer |= RGMII_FER_MDIO(0);
  689. if (devnum == 0) {
  690. rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
  691. bis->bi_phymode[0] = BI_PHYMODE_GMII;
  692. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  693. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  694. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  695. } else {
  696. rmiifer |= RGMII_FER_GMII << RGMII_FER_V(3); /* CH1CFG - EMAC1 */
  697. bis->bi_phymode[0] = BI_PHYMODE_NONE;
  698. bis->bi_phymode[1] = BI_PHYMODE_GMII;
  699. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  700. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  701. }
  702. break;
  703. case 8:
  704. /* 2 GMII - 460GT */
  705. /* GMC0 EMAC4_0, RGMII Bridge 0 */
  706. /* GMC1 EMAC4_2, RGMII Bridge 1 */
  707. rmiifer |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC0 */
  708. rmiifer1 |= RGMII_FER_GMII << RGMII_FER_V(2); /* CH0CFG - EMAC2 */
  709. rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
  710. rmiifer1 |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC2 */
  711. bis->bi_phymode[0] = BI_PHYMODE_GMII;
  712. bis->bi_phymode[1] = BI_PHYMODE_NONE;
  713. bis->bi_phymode[2] = BI_PHYMODE_GMII;
  714. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  715. break;
  716. case 9:
  717. /* 2 RGMII - 460EX */
  718. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  719. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  720. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
  721. rmiifer |= RGMII_FER_MDIO(0); /* enable MDIO - EMAC0 */
  722. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  723. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  724. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  725. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  726. break;
  727. case 10:
  728. /* 4 RGMII - 460GT */
  729. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  730. /* GMC1 EMAC4_2, GMC1 EMAC4_3, RGMII Bridge 1 */
  731. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(2);
  732. rmiifer |= RGMII_FER_RGMII << RGMII_FER_V(3);
  733. rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(2);
  734. rmiifer1 |= RGMII_FER_RGMII << RGMII_FER_V(3);
  735. bis->bi_phymode[0] = BI_PHYMODE_RGMII;
  736. bis->bi_phymode[1] = BI_PHYMODE_RGMII;
  737. bis->bi_phymode[2] = BI_PHYMODE_RGMII;
  738. bis->bi_phymode[3] = BI_PHYMODE_RGMII;
  739. break;
  740. case 11:
  741. /* 2 SGMII - 460EX */
  742. bis->bi_phymode[0] = BI_PHYMODE_SGMII;
  743. bis->bi_phymode[1] = BI_PHYMODE_SGMII;
  744. bis->bi_phymode[2] = BI_PHYMODE_NONE;
  745. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  746. break;
  747. case 12:
  748. /* 3 SGMII - 460GT */
  749. bis->bi_phymode[0] = BI_PHYMODE_SGMII;
  750. bis->bi_phymode[1] = BI_PHYMODE_SGMII;
  751. bis->bi_phymode[2] = BI_PHYMODE_SGMII;
  752. bis->bi_phymode[3] = BI_PHYMODE_NONE;
  753. break;
  754. default:
  755. break;
  756. }
  757. /* Set EMAC for MDIO */
  758. mfsdr(SDR0_ETH_CFG, eth_cfg);
  759. eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
  760. mtsdr(SDR0_ETH_CFG, eth_cfg);
  761. out_be32((void *)RGMII_FER, rmiifer);
  762. #if defined(CONFIG_460GT)
  763. out_be32((void *)RGMII_FER + RGMII1_BASE_OFFSET, rmiifer1);
  764. #endif
  765. /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
  766. mfsdr(SDR0_ETH_CFG, eth_cfg);
  767. eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
  768. mtsdr(SDR0_ETH_CFG, eth_cfg);
  769. return 0;
  770. }
  771. #endif /* CONFIG_460EX || CONFIG_460GT */
  772. static inline void *malloc_aligned(u32 size, u32 align)
  773. {
  774. return (void *)(((u32)malloc(size + align) + align - 1) &
  775. ~(align - 1));
  776. }
  777. static int ppc_4xx_eth_init (struct eth_device *dev, bd_t * bis)
  778. {
  779. int i;
  780. unsigned long reg = 0;
  781. unsigned long msr;
  782. unsigned long speed;
  783. unsigned long duplex;
  784. unsigned long failsafe;
  785. unsigned mode_reg;
  786. unsigned short devnum;
  787. unsigned short reg_short;
  788. #if defined(CONFIG_440GX) || \
  789. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  790. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  791. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  792. defined(CONFIG_405EX)
  793. u32 opbfreq;
  794. sys_info_t sysinfo;
  795. #if defined(CONFIG_440GX) || \
  796. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  797. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  798. defined(CONFIG_405EX)
  799. __maybe_unused int ethgroup = -1;
  800. #endif
  801. #endif
  802. u32 bd_cached;
  803. u32 bd_uncached = 0;
  804. #ifdef CONFIG_4xx_DCACHE
  805. static u32 last_used_ea = 0;
  806. #endif
  807. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  808. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  809. defined(CONFIG_405EX)
  810. int rgmii_channel;
  811. #endif
  812. EMAC_4XX_HW_PST hw_p = dev->priv;
  813. /* before doing anything, figure out if we have a MAC address */
  814. /* if not, bail */
  815. if (memcmp (dev->enetaddr, "\0\0\0\0\0\0", 6) == 0) {
  816. printf("ERROR: ethaddr not set!\n");
  817. return -1;
  818. }
  819. #if defined(CONFIG_440GX) || \
  820. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  821. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  822. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  823. defined(CONFIG_405EX)
  824. /* Need to get the OPB frequency so we can access the PHY */
  825. get_sys_info (&sysinfo);
  826. #endif
  827. msr = mfmsr ();
  828. mtmsr (msr & ~(MSR_EE)); /* disable interrupts */
  829. devnum = hw_p->devnum;
  830. #ifdef INFO_4XX_ENET
  831. /* AS.HARNOIS
  832. * We should have :
  833. * hw_p->stats.pkts_handled <= hw_p->stats.pkts_rx <= hw_p->stats.pkts_handled+PKTBUFSRX
  834. * In the most cases hw_p->stats.pkts_handled = hw_p->stats.pkts_rx, but it
  835. * is possible that new packets (without relationship with
  836. * current transfer) have got the time to arrived before
  837. * netloop calls eth_halt
  838. */
  839. printf ("About preceeding transfer (eth%d):\n"
  840. "- Sent packet number %d\n"
  841. "- Received packet number %d\n"
  842. "- Handled packet number %d\n",
  843. hw_p->devnum,
  844. hw_p->stats.pkts_tx,
  845. hw_p->stats.pkts_rx, hw_p->stats.pkts_handled);
  846. hw_p->stats.pkts_tx = 0;
  847. hw_p->stats.pkts_rx = 0;
  848. hw_p->stats.pkts_handled = 0;
  849. hw_p->print_speed = 1; /* print speed message again next time */
  850. #endif
  851. hw_p->tx_err_index = 0; /* Transmit Error Index for tx_err_log */
  852. hw_p->rx_err_index = 0; /* Receive Error Index for rx_err_log */
  853. hw_p->rx_slot = 0; /* MAL Receive Slot */
  854. hw_p->rx_i_index = 0; /* Receive Interrupt Queue Index */
  855. hw_p->rx_u_index = 0; /* Receive User Queue Index */
  856. hw_p->tx_slot = 0; /* MAL Transmit Slot */
  857. hw_p->tx_i_index = 0; /* Transmit Interrupt Queue Index */
  858. hw_p->tx_u_index = 0; /* Transmit User Queue Index */
  859. #if defined(CONFIG_440) && !defined(CONFIG_440SP) && !defined(CONFIG_440SPE)
  860. /* set RMII mode */
  861. /* NOTE: 440GX spec states that mode is mutually exclusive */
  862. /* NOTE: Therefore, disable all other EMACS, since we handle */
  863. /* NOTE: only one emac at a time */
  864. reg = 0;
  865. out_be32((void *)ZMII0_FER, 0);
  866. udelay (100);
  867. #if defined(CONFIG_440GP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  868. out_be32((void *)ZMII0_FER, (ZMII_FER_RMII | ZMII_FER_MDI) << ZMII_FER_V (devnum));
  869. #elif defined(CONFIG_440GX) || \
  870. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  871. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  872. ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
  873. #endif
  874. out_be32((void *)ZMII0_SSR, ZMII0_SSR_SP << ZMII0_SSR_V(devnum));
  875. #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
  876. #if defined(CONFIG_405EX)
  877. ethgroup = ppc_4xx_eth_setup_bridge(devnum, bis);
  878. #endif
  879. sync();
  880. /* provide clocks for EMAC internal loopback */
  881. emac_loopback_enable(hw_p);
  882. /* EMAC RESET */
  883. out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_SRST);
  884. /* remove clocks for EMAC internal loopback */
  885. emac_loopback_disable(hw_p);
  886. failsafe = 1000;
  887. while ((in_be32((void *)EMAC0_MR0 + hw_p->hw_addr) & (EMAC_MR0_SRST)) && failsafe) {
  888. udelay (1000);
  889. failsafe--;
  890. }
  891. if (failsafe <= 0)
  892. printf("\nProblem resetting EMAC!\n");
  893. #if defined(CONFIG_440GX) || \
  894. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  895. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  896. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  897. defined(CONFIG_405EX)
  898. /* Whack the M1 register */
  899. mode_reg = 0x0;
  900. mode_reg &= ~0x00000038;
  901. opbfreq = sysinfo.freqOPB / 1000000;
  902. if (opbfreq <= 50);
  903. else if (opbfreq <= 66)
  904. mode_reg |= EMAC_MR1_OBCI_66;
  905. else if (opbfreq <= 83)
  906. mode_reg |= EMAC_MR1_OBCI_83;
  907. else if (opbfreq <= 100)
  908. mode_reg |= EMAC_MR1_OBCI_100;
  909. else
  910. mode_reg |= EMAC_MR1_OBCI_GT100;
  911. out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
  912. #endif /* defined(CONFIG_440GX) || defined(CONFIG_440SP) */
  913. #if defined(CONFIG_GPCS_PHY_ADDR) || defined(CONFIG_GPCS_PHY1_ADDR) || \
  914. defined(CONFIG_GPCS_PHY2_ADDR) || defined(CONFIG_GPCS_PHY3_ADDR)
  915. if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
  916. /*
  917. * In SGMII mode, GPCS access is needed for
  918. * communication with the internal SGMII SerDes.
  919. */
  920. switch (devnum) {
  921. #if defined(CONFIG_GPCS_PHY_ADDR)
  922. case 0:
  923. reg = CONFIG_GPCS_PHY_ADDR;
  924. break;
  925. #endif
  926. #if defined(CONFIG_GPCS_PHY1_ADDR)
  927. case 1:
  928. reg = CONFIG_GPCS_PHY1_ADDR;
  929. break;
  930. #endif
  931. #if defined(CONFIG_GPCS_PHY2_ADDR)
  932. case 2:
  933. reg = CONFIG_GPCS_PHY2_ADDR;
  934. break;
  935. #endif
  936. #if defined(CONFIG_GPCS_PHY3_ADDR)
  937. case 3:
  938. reg = CONFIG_GPCS_PHY3_ADDR;
  939. break;
  940. #endif
  941. }
  942. mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
  943. mode_reg |= EMAC_MR1_MF_1000GPCS | EMAC_MR1_IPPA_SET(reg);
  944. out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
  945. /* Configure GPCS interface to recommended setting for SGMII */
  946. miiphy_reset(dev->name, reg);
  947. miiphy_write(dev->name, reg, 0x04, 0x8120); /* AsymPause, FDX */
  948. miiphy_write(dev->name, reg, 0x07, 0x2801); /* msg_pg, toggle */
  949. miiphy_write(dev->name, reg, 0x00, 0x0140); /* 1Gbps, FDX */
  950. }
  951. #endif /* defined(CONFIG_GPCS_PHY_ADDR) */
  952. /* wait for PHY to complete auto negotiation */
  953. reg_short = 0;
  954. switch (devnum) {
  955. case 0:
  956. reg = CONFIG_PHY_ADDR;
  957. break;
  958. #if defined (CONFIG_PHY1_ADDR)
  959. case 1:
  960. reg = CONFIG_PHY1_ADDR;
  961. break;
  962. #endif
  963. #if defined (CONFIG_PHY2_ADDR)
  964. case 2:
  965. reg = CONFIG_PHY2_ADDR;
  966. break;
  967. #endif
  968. #if defined (CONFIG_PHY3_ADDR)
  969. case 3:
  970. reg = CONFIG_PHY3_ADDR;
  971. break;
  972. #endif
  973. default:
  974. reg = CONFIG_PHY_ADDR;
  975. break;
  976. }
  977. bis->bi_phynum[devnum] = reg;
  978. if (reg == CONFIG_FIXED_PHY)
  979. goto get_speed;
  980. #if defined(CONFIG_PHY_RESET)
  981. /*
  982. * Reset the phy, only if its the first time through
  983. * otherwise, just check the speeds & feeds
  984. */
  985. if (hw_p->first_init == 0) {
  986. #if defined(CONFIG_M88E1111_PHY)
  987. miiphy_write (dev->name, reg, 0x14, 0x0ce3);
  988. miiphy_write (dev->name, reg, 0x18, 0x4101);
  989. miiphy_write (dev->name, reg, 0x09, 0x0e00);
  990. miiphy_write (dev->name, reg, 0x04, 0x01e1);
  991. #if defined(CONFIG_M88E1111_DISABLE_FIBER)
  992. miiphy_read(dev->name, reg, 0x1b, &reg_short);
  993. reg_short |= 0x8000;
  994. miiphy_write(dev->name, reg, 0x1b, reg_short);
  995. #endif
  996. #endif
  997. #if defined(CONFIG_M88E1112_PHY)
  998. if (bis->bi_phymode[devnum] == BI_PHYMODE_SGMII) {
  999. /*
  1000. * Marvell 88E1112 PHY needs to have the SGMII MAC
  1001. * interace (page 2) properly configured to
  1002. * communicate with the 460EX/GT GPCS interface.
  1003. */
  1004. /* Set access to Page 2 */
  1005. miiphy_write(dev->name, reg, 0x16, 0x0002);
  1006. miiphy_write(dev->name, reg, 0x00, 0x0040); /* 1Gbps */
  1007. miiphy_read(dev->name, reg, 0x1a, &reg_short);
  1008. reg_short |= 0x8000; /* bypass Auto-Negotiation */
  1009. miiphy_write(dev->name, reg, 0x1a, reg_short);
  1010. miiphy_reset(dev->name, reg); /* reset MAC interface */
  1011. /* Reset access to Page 0 */
  1012. miiphy_write(dev->name, reg, 0x16, 0x0000);
  1013. }
  1014. #endif /* defined(CONFIG_M88E1112_PHY) */
  1015. miiphy_reset (dev->name, reg);
  1016. #if defined(CONFIG_440GX) || \
  1017. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1018. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  1019. defined(CONFIG_405EX)
  1020. #if defined(CONFIG_CIS8201_PHY)
  1021. /*
  1022. * Cicada 8201 PHY needs to have an extended register whacked
  1023. * for RGMII mode.
  1024. */
  1025. if (((devnum == 2) || (devnum == 3)) && (4 == ethgroup)) {
  1026. #if defined(CONFIG_CIS8201_SHORT_ETCH)
  1027. miiphy_write (dev->name, reg, 23, 0x1300);
  1028. #else
  1029. miiphy_write (dev->name, reg, 23, 0x1000);
  1030. #endif
  1031. /*
  1032. * Vitesse VSC8201/Cicada CIS8201 errata:
  1033. * Interoperability problem with Intel 82547EI phys
  1034. * This work around (provided by Vitesse) changes
  1035. * the default timer convergence from 8ms to 12ms
  1036. */
  1037. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  1038. miiphy_write (dev->name, reg, 0x08, 0x0200);
  1039. miiphy_write (dev->name, reg, 0x1f, 0x52b5);
  1040. miiphy_write (dev->name, reg, 0x02, 0x0004);
  1041. miiphy_write (dev->name, reg, 0x01, 0x0671);
  1042. miiphy_write (dev->name, reg, 0x00, 0x8fae);
  1043. miiphy_write (dev->name, reg, 0x1f, 0x2a30);
  1044. miiphy_write (dev->name, reg, 0x08, 0x0000);
  1045. miiphy_write (dev->name, reg, 0x1f, 0x0000);
  1046. /* end Vitesse/Cicada errata */
  1047. }
  1048. #endif /* defined(CONFIG_CIS8201_PHY) */
  1049. #if defined(CONFIG_ET1011C_PHY)
  1050. /*
  1051. * Agere ET1011c PHY needs to have an extended register whacked
  1052. * for RGMII mode.
  1053. */
  1054. if (((devnum == 2) || (devnum ==3)) && (4 == ethgroup)) {
  1055. miiphy_read (dev->name, reg, 0x16, &reg_short);
  1056. reg_short &= ~(0x7);
  1057. reg_short |= 0x6; /* RGMII DLL Delay*/
  1058. miiphy_write (dev->name, reg, 0x16, reg_short);
  1059. miiphy_read (dev->name, reg, 0x17, &reg_short);
  1060. reg_short &= ~(0x40);
  1061. miiphy_write (dev->name, reg, 0x17, reg_short);
  1062. miiphy_write(dev->name, reg, 0x1c, 0x74f0);
  1063. }
  1064. #endif /* defined(CONFIG_ET1011C_PHY) */
  1065. #endif /* defined(CONFIG_440GX) ... */
  1066. /* Start/Restart autonegotiation */
  1067. phy_setup_aneg (dev->name, reg);
  1068. udelay (1000);
  1069. }
  1070. #endif /* defined(CONFIG_PHY_RESET) */
  1071. miiphy_read (dev->name, reg, MII_BMSR, &reg_short);
  1072. /*
  1073. * Wait if PHY is capable of autonegotiation and autonegotiation is not complete
  1074. */
  1075. if ((reg_short & BMSR_ANEGCAPABLE)
  1076. && !(reg_short & BMSR_ANEGCOMPLETE)) {
  1077. puts ("Waiting for PHY auto negotiation to complete");
  1078. i = 0;
  1079. while (!(reg_short & BMSR_ANEGCOMPLETE)) {
  1080. /*
  1081. * Timeout reached ?
  1082. */
  1083. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  1084. puts (" TIMEOUT !\n");
  1085. break;
  1086. }
  1087. if ((i++ % 1000) == 0) {
  1088. putc ('.');
  1089. }
  1090. udelay (1000); /* 1 ms */
  1091. miiphy_read (dev->name, reg, MII_BMSR, &reg_short);
  1092. }
  1093. puts (" done\n");
  1094. udelay (500000); /* another 500 ms (results in faster booting) */
  1095. }
  1096. get_speed:
  1097. if (reg == CONFIG_FIXED_PHY) {
  1098. for (i = 0; i < ARRAY_SIZE(fixed_phy_port); i++) {
  1099. if (devnum == fixed_phy_port[i].devnum) {
  1100. speed = fixed_phy_port[i].speed;
  1101. duplex = fixed_phy_port[i].duplex;
  1102. break;
  1103. }
  1104. }
  1105. if (i == ARRAY_SIZE(fixed_phy_port)) {
  1106. printf("ERROR: PHY (%s) not configured correctly!\n",
  1107. dev->name);
  1108. return -1;
  1109. }
  1110. } else {
  1111. speed = miiphy_speed(dev->name, reg);
  1112. duplex = miiphy_duplex(dev->name, reg);
  1113. }
  1114. if (hw_p->print_speed) {
  1115. hw_p->print_speed = 0;
  1116. printf ("ENET Speed is %d Mbps - %s duplex connection (EMAC%d)\n",
  1117. (int) speed, (duplex == HALF) ? "HALF" : "FULL",
  1118. hw_p->devnum);
  1119. }
  1120. #if defined(CONFIG_440) && \
  1121. !defined(CONFIG_440SP) && !defined(CONFIG_440SPE) && \
  1122. !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) && \
  1123. !defined(CONFIG_460EX) && !defined(CONFIG_460GT)
  1124. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  1125. mfsdr(SDR0_MFR, reg);
  1126. if (speed == 100) {
  1127. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_100M;
  1128. } else {
  1129. reg = (reg & ~SDR0_MFR_ZMII_MODE_MASK) | SDR0_MFR_ZMII_MODE_RMII_10M;
  1130. }
  1131. mtsdr(SDR0_MFR, reg);
  1132. #endif
  1133. /* Set ZMII/RGMII speed according to the phy link speed */
  1134. reg = in_be32((void *)ZMII0_SSR);
  1135. if ( (speed == 100) || (speed == 1000) )
  1136. out_be32((void *)ZMII0_SSR, reg | (ZMII0_SSR_SP << ZMII0_SSR_V (devnum)));
  1137. else
  1138. out_be32((void *)ZMII0_SSR, reg & (~(ZMII0_SSR_SP << ZMII0_SSR_V (devnum))));
  1139. if ((devnum == 2) || (devnum == 3)) {
  1140. if (speed == 1000)
  1141. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V (devnum));
  1142. else if (speed == 100)
  1143. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V (devnum));
  1144. else if (speed == 10)
  1145. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V (devnum));
  1146. else {
  1147. printf("Error in RGMII Speed\n");
  1148. return -1;
  1149. }
  1150. out_be32((void *)RGMII_SSR, reg);
  1151. }
  1152. #endif /* defined(CONFIG_440) && !defined(CONFIG_440SP) */
  1153. #if defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1154. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  1155. defined(CONFIG_405EX)
  1156. if (devnum >= 2)
  1157. rgmii_channel = devnum - 2;
  1158. else
  1159. rgmii_channel = devnum;
  1160. if (speed == 1000)
  1161. reg = (RGMII_SSR_SP_1000MBPS << RGMII_SSR_V(rgmii_channel));
  1162. else if (speed == 100)
  1163. reg = (RGMII_SSR_SP_100MBPS << RGMII_SSR_V(rgmii_channel));
  1164. else if (speed == 10)
  1165. reg = (RGMII_SSR_SP_10MBPS << RGMII_SSR_V(rgmii_channel));
  1166. else {
  1167. printf("Error in RGMII Speed\n");
  1168. return -1;
  1169. }
  1170. out_be32((void *)RGMII_SSR, reg);
  1171. #if defined(CONFIG_460GT)
  1172. if ((devnum == 2) || (devnum == 3))
  1173. out_be32((void *)RGMII_SSR + RGMII1_BASE_OFFSET, reg);
  1174. #endif
  1175. #endif
  1176. /* set the Mal configuration reg */
  1177. #if defined(CONFIG_440GX) || \
  1178. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1179. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  1180. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  1181. defined(CONFIG_405EX)
  1182. mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA |
  1183. MAL_CR_PLBLT_DEFAULT | MAL_CR_EOPIE | 0x00330000);
  1184. #else
  1185. mtdcr (MAL0_CFG, MAL_CR_PLBB | MAL_CR_OPBBL | MAL_CR_LEA | MAL_CR_PLBLT_DEFAULT);
  1186. /* Errata 1.12: MAL_1 -- Disable MAL bursting */
  1187. if (get_pvr() == PVR_440GP_RB) {
  1188. mtdcr (MAL0_CFG, mfdcr(MAL0_CFG) & ~MAL_CR_PLBB);
  1189. }
  1190. #endif
  1191. /*
  1192. * Malloc MAL buffer desciptors, make sure they are
  1193. * aligned on cache line boundary size
  1194. * (401/403/IOP480 = 16, 405 = 32)
  1195. * and doesn't cross cache block boundaries.
  1196. */
  1197. if (hw_p->first_init == 0) {
  1198. debug("*** Allocating descriptor memory ***\n");
  1199. bd_cached = (u32)malloc_aligned(MAL_ALLOC_SIZE, 4096);
  1200. if (!bd_cached) {
  1201. printf("%s: Error allocating MAL descriptor buffers!\n", __func__);
  1202. return -1;
  1203. }
  1204. #ifdef CONFIG_4xx_DCACHE
  1205. flush_dcache_range(bd_cached, bd_cached + MAL_ALLOC_SIZE);
  1206. if (!last_used_ea)
  1207. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  1208. bd_uncached = bis->bi_memsize + CONFIG_SYS_MEM_TOP_HIDE;
  1209. #else
  1210. bd_uncached = bis->bi_memsize;
  1211. #endif
  1212. else
  1213. bd_uncached = last_used_ea + MAL_ALLOC_SIZE;
  1214. last_used_ea = bd_uncached;
  1215. program_tlb(bd_cached, bd_uncached, MAL_ALLOC_SIZE,
  1216. TLB_WORD2_I_ENABLE);
  1217. #else
  1218. bd_uncached = bd_cached;
  1219. #endif
  1220. hw_p->tx_phys = bd_cached;
  1221. hw_p->rx_phys = bd_cached + MAL_TX_DESC_SIZE;
  1222. hw_p->tx = (mal_desc_t *)(bd_uncached);
  1223. hw_p->rx = (mal_desc_t *)(bd_uncached + MAL_TX_DESC_SIZE);
  1224. debug("hw_p->tx=%p, hw_p->rx=%p\n", hw_p->tx, hw_p->rx);
  1225. }
  1226. for (i = 0; i < NUM_TX_BUFF; i++) {
  1227. hw_p->tx[i].ctrl = 0;
  1228. hw_p->tx[i].data_len = 0;
  1229. if (hw_p->first_init == 0)
  1230. hw_p->txbuf_ptr = malloc_aligned(MAL_ALLOC_SIZE,
  1231. L1_CACHE_BYTES);
  1232. hw_p->tx[i].data_ptr = hw_p->txbuf_ptr;
  1233. if ((NUM_TX_BUFF - 1) == i)
  1234. hw_p->tx[i].ctrl |= MAL_TX_CTRL_WRAP;
  1235. hw_p->tx_run[i] = -1;
  1236. debug("TX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->tx[i].data_ptr);
  1237. }
  1238. for (i = 0; i < NUM_RX_BUFF; i++) {
  1239. hw_p->rx[i].ctrl = 0;
  1240. hw_p->rx[i].data_len = 0;
  1241. hw_p->rx[i].data_ptr = (char *)NetRxPackets[i];
  1242. if ((NUM_RX_BUFF - 1) == i)
  1243. hw_p->rx[i].ctrl |= MAL_RX_CTRL_WRAP;
  1244. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY | MAL_RX_CTRL_INTR;
  1245. hw_p->rx_ready[i] = -1;
  1246. debug("RX_BUFF %d @ 0x%08x\n", i, (u32)hw_p->rx[i].data_ptr);
  1247. }
  1248. reg = 0x00000000;
  1249. reg |= dev->enetaddr[0]; /* set high address */
  1250. reg = reg << 8;
  1251. reg |= dev->enetaddr[1];
  1252. out_be32((void *)EMAC0_IAH + hw_p->hw_addr, reg);
  1253. reg = 0x00000000;
  1254. reg |= dev->enetaddr[2]; /* set low address */
  1255. reg = reg << 8;
  1256. reg |= dev->enetaddr[3];
  1257. reg = reg << 8;
  1258. reg |= dev->enetaddr[4];
  1259. reg = reg << 8;
  1260. reg |= dev->enetaddr[5];
  1261. out_be32((void *)EMAC0_IAL + hw_p->hw_addr, reg);
  1262. switch (devnum) {
  1263. case 1:
  1264. /* setup MAL tx & rx channel pointers */
  1265. #if defined (CONFIG_405EP) || defined (CONFIG_440EP) || defined (CONFIG_440GR)
  1266. mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
  1267. #else
  1268. mtdcr (MAL0_TXCTP1R, hw_p->tx_phys);
  1269. #endif
  1270. #if defined(CONFIG_440)
  1271. mtdcr (MAL0_TXBADDR, 0x0);
  1272. mtdcr (MAL0_RXBADDR, 0x0);
  1273. #endif
  1274. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  1275. mtdcr (MAL0_RXCTP8R, hw_p->rx_phys);
  1276. /* set RX buffer size */
  1277. mtdcr (MAL0_RCBS8, ENET_MAX_MTU_ALIGNED / 16);
  1278. #else
  1279. mtdcr (MAL0_RXCTP1R, hw_p->rx_phys);
  1280. /* set RX buffer size */
  1281. mtdcr (MAL0_RCBS1, ENET_MAX_MTU_ALIGNED / 16);
  1282. #endif
  1283. break;
  1284. #if defined (CONFIG_440GX)
  1285. case 2:
  1286. /* setup MAL tx & rx channel pointers */
  1287. mtdcr (MAL0_TXBADDR, 0x0);
  1288. mtdcr (MAL0_RXBADDR, 0x0);
  1289. mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
  1290. mtdcr (MAL0_RXCTP2R, hw_p->rx_phys);
  1291. /* set RX buffer size */
  1292. mtdcr (MAL0_RCBS2, ENET_MAX_MTU_ALIGNED / 16);
  1293. break;
  1294. case 3:
  1295. /* setup MAL tx & rx channel pointers */
  1296. mtdcr (MAL0_TXBADDR, 0x0);
  1297. mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
  1298. mtdcr (MAL0_RXBADDR, 0x0);
  1299. mtdcr (MAL0_RXCTP3R, hw_p->rx_phys);
  1300. /* set RX buffer size */
  1301. mtdcr (MAL0_RCBS3, ENET_MAX_MTU_ALIGNED / 16);
  1302. break;
  1303. #endif /* CONFIG_440GX */
  1304. #if defined (CONFIG_460GT)
  1305. case 2:
  1306. /* setup MAL tx & rx channel pointers */
  1307. mtdcr (MAL0_TXBADDR, 0x0);
  1308. mtdcr (MAL0_RXBADDR, 0x0);
  1309. mtdcr (MAL0_TXCTP2R, hw_p->tx_phys);
  1310. mtdcr (MAL0_RXCTP16R, hw_p->rx_phys);
  1311. /* set RX buffer size */
  1312. mtdcr (MAL0_RCBS16, ENET_MAX_MTU_ALIGNED / 16);
  1313. break;
  1314. case 3:
  1315. /* setup MAL tx & rx channel pointers */
  1316. mtdcr (MAL0_TXBADDR, 0x0);
  1317. mtdcr (MAL0_RXBADDR, 0x0);
  1318. mtdcr (MAL0_TXCTP3R, hw_p->tx_phys);
  1319. mtdcr (MAL0_RXCTP24R, hw_p->rx_phys);
  1320. /* set RX buffer size */
  1321. mtdcr (MAL0_RCBS24, ENET_MAX_MTU_ALIGNED / 16);
  1322. break;
  1323. #endif /* CONFIG_460GT */
  1324. case 0:
  1325. default:
  1326. /* setup MAL tx & rx channel pointers */
  1327. #if defined(CONFIG_440)
  1328. mtdcr (MAL0_TXBADDR, 0x0);
  1329. mtdcr (MAL0_RXBADDR, 0x0);
  1330. #endif
  1331. mtdcr (MAL0_TXCTP0R, hw_p->tx_phys);
  1332. mtdcr (MAL0_RXCTP0R, hw_p->rx_phys);
  1333. /* set RX buffer size */
  1334. mtdcr (MAL0_RCBS0, ENET_MAX_MTU_ALIGNED / 16);
  1335. break;
  1336. }
  1337. /* Enable MAL transmit and receive channels */
  1338. #if defined(CONFIG_405EP) || defined(CONFIG_440EP) || defined(CONFIG_440GR)
  1339. mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> (hw_p->devnum*2)));
  1340. #else
  1341. mtdcr (MAL0_TXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
  1342. #endif
  1343. mtdcr (MAL0_RXCASR, (MAL_TXRX_CASR >> hw_p->devnum));
  1344. /* set transmit enable & receive enable */
  1345. out_be32((void *)EMAC0_MR0 + hw_p->hw_addr, EMAC_MR0_TXE | EMAC_MR0_RXE);
  1346. mode_reg = in_be32((void *)EMAC0_MR1 + hw_p->hw_addr);
  1347. /* set rx-/tx-fifo size */
  1348. mode_reg = (mode_reg & ~EMAC_MR1_FIFO_MASK) | EMAC_MR1_FIFO_SIZE;
  1349. /* set speed */
  1350. if (speed == _1000BASET) {
  1351. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  1352. unsigned long pfc1;
  1353. mfsdr (SDR0_PFC1, pfc1);
  1354. pfc1 |= SDR0_PFC1_EM_1000;
  1355. mtsdr (SDR0_PFC1, pfc1);
  1356. #endif
  1357. mode_reg = mode_reg | EMAC_MR1_MF_1000MBPS | EMAC_MR1_IST;
  1358. } else if (speed == _100BASET)
  1359. mode_reg = mode_reg | EMAC_MR1_MF_100MBPS | EMAC_MR1_IST;
  1360. else
  1361. mode_reg = mode_reg & ~0x00C00000; /* 10 MBPS */
  1362. if (duplex == FULL)
  1363. mode_reg = mode_reg | 0x80000000 | EMAC_MR1_IST;
  1364. out_be32((void *)EMAC0_MR1 + hw_p->hw_addr, mode_reg);
  1365. /* Enable broadcast and indvidual address */
  1366. /* TBS: enabling runts as some misbehaved nics will send runts */
  1367. out_be32((void *)EMAC0_RXM + hw_p->hw_addr, EMAC_RMR_BAE | EMAC_RMR_IAE);
  1368. /* we probably need to set the tx mode1 reg? maybe at tx time */
  1369. /* set transmit request threshold register */
  1370. out_be32((void *)EMAC0_TRTR + hw_p->hw_addr, 0x18000000); /* 256 byte threshold */
  1371. /* set receive low/high water mark register */
  1372. #if defined(CONFIG_440)
  1373. /* 440s has a 64 byte burst length */
  1374. out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x80009000);
  1375. #else
  1376. /* 405s have a 16 byte burst length */
  1377. out_be32((void *)EMAC0_RX_HI_LO_WMARK + hw_p->hw_addr, 0x0f002000);
  1378. #endif /* defined(CONFIG_440) */
  1379. out_be32((void *)EMAC0_TMR1 + hw_p->hw_addr, 0xf8640000);
  1380. /* Set fifo limit entry in tx mode 0 */
  1381. out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr, 0x00000003);
  1382. /* Frame gap set */
  1383. out_be32((void *)EMAC0_I_FRAME_GAP_REG + hw_p->hw_addr, 0x00000008);
  1384. /* Set EMAC IER */
  1385. hw_p->emac_ier = EMAC_ISR_PTLE | EMAC_ISR_BFCS | EMAC_ISR_ORE | EMAC_ISR_IRE;
  1386. if (speed == _100BASET)
  1387. hw_p->emac_ier = hw_p->emac_ier | EMAC_ISR_SYE;
  1388. out_be32((void *)EMAC0_ISR + hw_p->hw_addr, 0xffffffff); /* clear pending interrupts */
  1389. out_be32((void *)EMAC0_IER + hw_p->hw_addr, hw_p->emac_ier);
  1390. if (hw_p->first_init == 0) {
  1391. /*
  1392. * Connect interrupt service routines
  1393. */
  1394. irq_install_handler(ETH_IRQ_NUM(hw_p->devnum),
  1395. (interrupt_handler_t *) enetInt, dev);
  1396. }
  1397. mtmsr (msr); /* enable interrupts again */
  1398. hw_p->bis = bis;
  1399. hw_p->first_init = 1;
  1400. return 0;
  1401. }
  1402. static int ppc_4xx_eth_send(struct eth_device *dev, void *ptr, int len)
  1403. {
  1404. struct enet_frame *ef_ptr;
  1405. ulong time_start, time_now;
  1406. unsigned long temp_txm0;
  1407. EMAC_4XX_HW_PST hw_p = dev->priv;
  1408. ef_ptr = (struct enet_frame *) ptr;
  1409. /*-----------------------------------------------------------------------+
  1410. * Copy in our address into the frame.
  1411. *-----------------------------------------------------------------------*/
  1412. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  1413. /*-----------------------------------------------------------------------+
  1414. * If frame is too long or too short, modify length.
  1415. *-----------------------------------------------------------------------*/
  1416. /* TBS: where does the fragment go???? */
  1417. if (len > ENET_MAX_MTU)
  1418. len = ENET_MAX_MTU;
  1419. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  1420. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  1421. flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
  1422. /*-----------------------------------------------------------------------+
  1423. * set TX Buffer busy, and send it
  1424. *-----------------------------------------------------------------------*/
  1425. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  1426. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  1427. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  1428. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  1429. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  1430. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  1431. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  1432. sync();
  1433. out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr,
  1434. in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr) | EMAC_TMR0_GNP0);
  1435. #ifdef INFO_4XX_ENET
  1436. hw_p->stats.pkts_tx++;
  1437. #endif
  1438. /*-----------------------------------------------------------------------+
  1439. * poll unitl the packet is sent and then make sure it is OK
  1440. *-----------------------------------------------------------------------*/
  1441. time_start = get_timer (0);
  1442. while (1) {
  1443. temp_txm0 = in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr);
  1444. /* loop until either TINT turns on or 3 seconds elapse */
  1445. if ((temp_txm0 & EMAC_TMR0_GNP0) != 0) {
  1446. /* transmit is done, so now check for errors
  1447. * If there is an error, an interrupt should
  1448. * happen when we return
  1449. */
  1450. time_now = get_timer (0);
  1451. if ((time_now - time_start) > 3000) {
  1452. return (-1);
  1453. }
  1454. } else {
  1455. return (len);
  1456. }
  1457. }
  1458. }
  1459. int enetInt (struct eth_device *dev)
  1460. {
  1461. int serviced;
  1462. int rc = -1; /* default to not us */
  1463. u32 mal_isr;
  1464. u32 emac_isr = 0;
  1465. u32 mal_eob;
  1466. u32 uic_mal;
  1467. u32 uic_mal_err;
  1468. u32 uic_emac;
  1469. u32 uic_emac_b;
  1470. EMAC_4XX_HW_PST hw_p;
  1471. /*
  1472. * Because the mal is generic, we need to get the current
  1473. * eth device
  1474. */
  1475. dev = eth_get_dev();
  1476. hw_p = dev->priv;
  1477. /* enter loop that stays in interrupt code until nothing to service */
  1478. do {
  1479. serviced = 0;
  1480. uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
  1481. uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
  1482. uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
  1483. uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
  1484. if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
  1485. && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
  1486. && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
  1487. /* not for us */
  1488. return (rc);
  1489. }
  1490. /* get and clear controller status interrupts */
  1491. /* look at MAL and EMAC error interrupts */
  1492. if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
  1493. /* we have a MAL error interrupt */
  1494. mal_isr = mfdcr(MAL0_ESR);
  1495. mal_err(dev, mal_isr, uic_mal_err,
  1496. MAL_UIC_DEF, MAL_UIC_ERR);
  1497. /* clear MAL error interrupt status bits */
  1498. mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
  1499. UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
  1500. return -1;
  1501. }
  1502. /* look for EMAC errors */
  1503. if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
  1504. emac_isr = in_be32((void *)EMAC0_ISR + hw_p->hw_addr);
  1505. emac_err(dev, emac_isr);
  1506. /* clear EMAC error interrupt status bits */
  1507. mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
  1508. mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
  1509. return -1;
  1510. }
  1511. /* handle MAX TX EOB interrupt from a tx */
  1512. if (uic_mal & UIC_MAL_TXEOB) {
  1513. /* clear MAL interrupt status bits */
  1514. mal_eob = mfdcr(MAL0_TXEOBISR);
  1515. mtdcr(MAL0_TXEOBISR, mal_eob);
  1516. mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
  1517. /* indicate that we serviced an interrupt */
  1518. serviced = 1;
  1519. rc = 0;
  1520. }
  1521. /* handle MAL RX EOB interrupt from a receive */
  1522. /* check for EOB on valid channels */
  1523. if (uic_mal & UIC_MAL_RXEOB) {
  1524. mal_eob = mfdcr(MAL0_RXEOBISR);
  1525. if (mal_eob &
  1526. (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
  1527. /* push packet to upper layer */
  1528. enet_rcv(dev, emac_isr);
  1529. /* clear MAL interrupt status bits */
  1530. mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
  1531. /* indicate that we serviced an interrupt */
  1532. serviced = 1;
  1533. rc = 0;
  1534. }
  1535. }
  1536. #if defined(CONFIG_405EZ)
  1537. /*
  1538. * On 405EZ the RX-/TX-interrupts are coalesced into
  1539. * one IRQ bit in the UIC. We need to acknowledge the
  1540. * RX-/TX-interrupts in the SDR0_ICINTSTAT reg as well.
  1541. */
  1542. mtsdr(SDR0_ICINTSTAT,
  1543. SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
  1544. #endif /* defined(CONFIG_405EZ) */
  1545. } while (serviced);
  1546. return (rc);
  1547. }
  1548. /*-----------------------------------------------------------------------------+
  1549. * MAL Error Routine
  1550. *-----------------------------------------------------------------------------*/
  1551. static void mal_err (struct eth_device *dev, unsigned long isr,
  1552. unsigned long uic, unsigned long maldef,
  1553. unsigned long mal_errr)
  1554. {
  1555. EMAC_4XX_HW_PST hw_p = dev->priv;
  1556. mtdcr (MAL0_ESR, isr); /* clear interrupt */
  1557. /* clear DE interrupt */
  1558. mtdcr (MAL0_TXDEIR, 0xC0000000);
  1559. mtdcr (MAL0_RXDEIR, 0x80000000);
  1560. #ifdef INFO_4XX_ENET
  1561. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  1562. #endif
  1563. eth_init (hw_p->bis); /* start again... */
  1564. }
  1565. /*-----------------------------------------------------------------------------+
  1566. * EMAC Error Routine
  1567. *-----------------------------------------------------------------------------*/
  1568. static void emac_err (struct eth_device *dev, unsigned long isr)
  1569. {
  1570. EMAC_4XX_HW_PST hw_p = dev->priv;
  1571. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  1572. out_be32((void *)EMAC0_ISR + hw_p->hw_addr, isr);
  1573. }
  1574. /*-----------------------------------------------------------------------------+
  1575. * enet_rcv() handles the ethernet receive data
  1576. *-----------------------------------------------------------------------------*/
  1577. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  1578. {
  1579. unsigned long data_len;
  1580. unsigned long rx_eob_isr;
  1581. EMAC_4XX_HW_PST hw_p = dev->priv;
  1582. int handled = 0;
  1583. int i;
  1584. int loop_count = 0;
  1585. rx_eob_isr = mfdcr (MAL0_RXEOBISR);
  1586. if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
  1587. /* clear EOB */
  1588. mtdcr (MAL0_RXEOBISR, rx_eob_isr);
  1589. /* EMAC RX done */
  1590. while (1) { /* do all */
  1591. i = hw_p->rx_slot;
  1592. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  1593. || (loop_count >= NUM_RX_BUFF))
  1594. break;
  1595. loop_count++;
  1596. handled++;
  1597. data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
  1598. if (data_len) {
  1599. if (data_len > ENET_MAX_MTU) /* Check len */
  1600. data_len = 0;
  1601. else {
  1602. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  1603. data_len = 0;
  1604. hw_p->stats.rx_err_log[hw_p->
  1605. rx_err_index]
  1606. = hw_p->rx[i].ctrl;
  1607. hw_p->rx_err_index++;
  1608. if (hw_p->rx_err_index ==
  1609. MAX_ERR_LOG)
  1610. hw_p->rx_err_index =
  1611. 0;
  1612. } /* emac_erros */
  1613. } /* data_len < max mtu */
  1614. } /* if data_len */
  1615. if (!data_len) { /* no data */
  1616. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  1617. hw_p->stats.data_len_err++; /* Error at Rx */
  1618. }
  1619. /* !data_len */
  1620. /* AS.HARNOIS */
  1621. /* Check if user has already eaten buffer */
  1622. /* if not => ERROR */
  1623. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  1624. if (hw_p->is_receiving)
  1625. printf ("ERROR : Receive buffers are full!\n");
  1626. break;
  1627. } else {
  1628. hw_p->stats.rx_frames++;
  1629. hw_p->stats.rx += data_len;
  1630. #ifdef INFO_4XX_ENET
  1631. hw_p->stats.pkts_rx++;
  1632. #endif
  1633. /* AS.HARNOIS
  1634. * use ring buffer
  1635. */
  1636. hw_p->rx_ready[hw_p->rx_i_index] = i;
  1637. hw_p->rx_i_index++;
  1638. if (NUM_RX_BUFF == hw_p->rx_i_index)
  1639. hw_p->rx_i_index = 0;
  1640. hw_p->rx_slot++;
  1641. if (NUM_RX_BUFF == hw_p->rx_slot)
  1642. hw_p->rx_slot = 0;
  1643. /* AS.HARNOIS
  1644. * free receive buffer only when
  1645. * buffer has been handled (eth_rx)
  1646. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  1647. */
  1648. } /* if data_len */
  1649. } /* while */
  1650. } /* if EMACK_RXCHL */
  1651. }
  1652. static int ppc_4xx_eth_rx (struct eth_device *dev)
  1653. {
  1654. int length;
  1655. int user_index;
  1656. unsigned long msr;
  1657. EMAC_4XX_HW_PST hw_p = dev->priv;
  1658. hw_p->is_receiving = 1; /* tell driver */
  1659. for (;;) {
  1660. /* AS.HARNOIS
  1661. * use ring buffer and
  1662. * get index from rx buffer desciptor queue
  1663. */
  1664. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  1665. if (user_index == -1) {
  1666. length = -1;
  1667. break; /* nothing received - leave for() loop */
  1668. }
  1669. msr = mfmsr ();
  1670. mtmsr (msr & ~(MSR_EE));
  1671. length = hw_p->rx[user_index].data_len & 0x0fff;
  1672. /* Pass the packet up to the protocol layers. */
  1673. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  1674. /* NetReceive(NetRxPackets[i], length); */
  1675. invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
  1676. (u32)hw_p->rx[user_index].data_ptr +
  1677. length - 4);
  1678. NetReceive (NetRxPackets[user_index], length - 4);
  1679. /* Free Recv Buffer */
  1680. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  1681. /* Free rx buffer descriptor queue */
  1682. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  1683. hw_p->rx_u_index++;
  1684. if (NUM_RX_BUFF == hw_p->rx_u_index)
  1685. hw_p->rx_u_index = 0;
  1686. #ifdef INFO_4XX_ENET
  1687. hw_p->stats.pkts_handled++;
  1688. #endif
  1689. mtmsr (msr); /* Enable IRQ's */
  1690. }
  1691. hw_p->is_receiving = 0; /* tell driver */
  1692. return length;
  1693. }
  1694. int ppc_4xx_eth_initialize (bd_t * bis)
  1695. {
  1696. static int virgin = 0;
  1697. struct eth_device *dev;
  1698. int eth_num = 0;
  1699. EMAC_4XX_HW_PST hw = NULL;
  1700. u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
  1701. u32 hw_addr[4];
  1702. u32 mal_ier;
  1703. #if defined(CONFIG_440GX)
  1704. unsigned long pfc1;
  1705. mfsdr (SDR0_PFC1, pfc1);
  1706. pfc1 &= ~(0x01e00000);
  1707. pfc1 |= 0x01200000;
  1708. mtsdr (SDR0_PFC1, pfc1);
  1709. #endif
  1710. /* first clear all mac-addresses */
  1711. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
  1712. memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
  1713. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1714. int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
  1715. switch (eth_num) {
  1716. default: /* fall through */
  1717. case 0:
  1718. eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
  1719. hw_addr[eth_num] = 0x0;
  1720. break;
  1721. #ifdef CONFIG_HAS_ETH1
  1722. case 1:
  1723. eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
  1724. hw_addr[eth_num] = 0x100;
  1725. break;
  1726. #endif
  1727. #ifdef CONFIG_HAS_ETH2
  1728. case 2:
  1729. eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
  1730. #if defined(CONFIG_460GT)
  1731. hw_addr[eth_num] = 0x300;
  1732. #else
  1733. hw_addr[eth_num] = 0x400;
  1734. #endif
  1735. break;
  1736. #endif
  1737. #ifdef CONFIG_HAS_ETH3
  1738. case 3:
  1739. eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
  1740. #if defined(CONFIG_460GT)
  1741. hw_addr[eth_num] = 0x400;
  1742. #else
  1743. hw_addr[eth_num] = 0x600;
  1744. #endif
  1745. break;
  1746. #endif
  1747. }
  1748. }
  1749. /* set phy num and mode */
  1750. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  1751. bis->bi_phymode[0] = 0;
  1752. #if defined(CONFIG_PHY1_ADDR)
  1753. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  1754. bis->bi_phymode[1] = 0;
  1755. #endif
  1756. #if defined(CONFIG_440GX)
  1757. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  1758. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  1759. bis->bi_phymode[2] = 2;
  1760. bis->bi_phymode[3] = 2;
  1761. #endif
  1762. #if defined(CONFIG_440GX) || \
  1763. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1764. defined(CONFIG_405EX)
  1765. ppc_4xx_eth_setup_bridge(0, bis);
  1766. #endif
  1767. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1768. /*
  1769. * See if we can actually bring up the interface,
  1770. * otherwise, skip it
  1771. */
  1772. if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
  1773. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1774. continue;
  1775. }
  1776. /* Allocate device structure */
  1777. dev = (struct eth_device *) malloc (sizeof (*dev));
  1778. if (dev == NULL) {
  1779. printf ("ppc_4xx_eth_initialize: "
  1780. "Cannot allocate eth_device %d\n", eth_num);
  1781. return (-1);
  1782. }
  1783. memset(dev, 0, sizeof(*dev));
  1784. /* Allocate our private use data */
  1785. hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
  1786. if (hw == NULL) {
  1787. printf ("ppc_4xx_eth_initialize: "
  1788. "Cannot allocate private hw data for eth_device %d",
  1789. eth_num);
  1790. free (dev);
  1791. return (-1);
  1792. }
  1793. memset(hw, 0, sizeof(*hw));
  1794. hw->hw_addr = hw_addr[eth_num];
  1795. memcpy (dev->enetaddr, ethaddr[eth_num], 6);
  1796. hw->devnum = eth_num;
  1797. hw->print_speed = 1;
  1798. sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
  1799. dev->priv = (void *) hw;
  1800. dev->init = ppc_4xx_eth_init;
  1801. dev->halt = ppc_4xx_eth_halt;
  1802. dev->send = ppc_4xx_eth_send;
  1803. dev->recv = ppc_4xx_eth_rx;
  1804. eth_register(dev);
  1805. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  1806. miiphy_register(dev->name,
  1807. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1808. #endif
  1809. if (0 == virgin) {
  1810. /* set the MAL IER ??? names may change with new spec ??? */
  1811. #if defined(CONFIG_440SPE) || \
  1812. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1813. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  1814. defined(CONFIG_405EX)
  1815. mal_ier =
  1816. MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
  1817. MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
  1818. #else
  1819. mal_ier =
  1820. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  1821. MAL_IER_OPBE | MAL_IER_PLBE;
  1822. #endif
  1823. mtdcr (MAL0_ESR, 0xffffffff); /* clear pending interrupts */
  1824. mtdcr (MAL0_TXDEIR, 0xffffffff); /* clear pending interrupts */
  1825. mtdcr (MAL0_RXDEIR, 0xffffffff); /* clear pending interrupts */
  1826. mtdcr (MAL0_IER, mal_ier);
  1827. /* install MAL interrupt handler */
  1828. irq_install_handler (VECNUM_MAL_SERR,
  1829. (interrupt_handler_t *) enetInt,
  1830. dev);
  1831. irq_install_handler (VECNUM_MAL_TXEOB,
  1832. (interrupt_handler_t *) enetInt,
  1833. dev);
  1834. irq_install_handler (VECNUM_MAL_RXEOB,
  1835. (interrupt_handler_t *) enetInt,
  1836. dev);
  1837. irq_install_handler (VECNUM_MAL_TXDE,
  1838. (interrupt_handler_t *) enetInt,
  1839. dev);
  1840. irq_install_handler (VECNUM_MAL_RXDE,
  1841. (interrupt_handler_t *) enetInt,
  1842. dev);
  1843. virgin = 1;
  1844. }
  1845. } /* end for each supported device */
  1846. return 0;
  1847. }