4xx_enet.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  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, volatile void *ptr,
  1403. int len)
  1404. {
  1405. struct enet_frame *ef_ptr;
  1406. ulong time_start, time_now;
  1407. unsigned long temp_txm0;
  1408. EMAC_4XX_HW_PST hw_p = dev->priv;
  1409. ef_ptr = (struct enet_frame *) ptr;
  1410. /*-----------------------------------------------------------------------+
  1411. * Copy in our address into the frame.
  1412. *-----------------------------------------------------------------------*/
  1413. (void) memcpy (ef_ptr->source_addr, dev->enetaddr, ENET_ADDR_LENGTH);
  1414. /*-----------------------------------------------------------------------+
  1415. * If frame is too long or too short, modify length.
  1416. *-----------------------------------------------------------------------*/
  1417. /* TBS: where does the fragment go???? */
  1418. if (len > ENET_MAX_MTU)
  1419. len = ENET_MAX_MTU;
  1420. /* memcpy ((void *) &tx_buff[tx_slot], (const void *) ptr, len); */
  1421. memcpy ((void *) hw_p->txbuf_ptr, (const void *) ptr, len);
  1422. flush_dcache_range((u32)hw_p->txbuf_ptr, (u32)hw_p->txbuf_ptr + len);
  1423. /*-----------------------------------------------------------------------+
  1424. * set TX Buffer busy, and send it
  1425. *-----------------------------------------------------------------------*/
  1426. hw_p->tx[hw_p->tx_slot].ctrl = (MAL_TX_CTRL_LAST |
  1427. EMAC_TX_CTRL_GFCS | EMAC_TX_CTRL_GP) &
  1428. ~(EMAC_TX_CTRL_ISA | EMAC_TX_CTRL_RSA);
  1429. if ((NUM_TX_BUFF - 1) == hw_p->tx_slot)
  1430. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_WRAP;
  1431. hw_p->tx[hw_p->tx_slot].data_len = (short) len;
  1432. hw_p->tx[hw_p->tx_slot].ctrl |= MAL_TX_CTRL_READY;
  1433. sync();
  1434. out_be32((void *)EMAC0_TMR0 + hw_p->hw_addr,
  1435. in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr) | EMAC_TMR0_GNP0);
  1436. #ifdef INFO_4XX_ENET
  1437. hw_p->stats.pkts_tx++;
  1438. #endif
  1439. /*-----------------------------------------------------------------------+
  1440. * poll unitl the packet is sent and then make sure it is OK
  1441. *-----------------------------------------------------------------------*/
  1442. time_start = get_timer (0);
  1443. while (1) {
  1444. temp_txm0 = in_be32((void *)EMAC0_TMR0 + hw_p->hw_addr);
  1445. /* loop until either TINT turns on or 3 seconds elapse */
  1446. if ((temp_txm0 & EMAC_TMR0_GNP0) != 0) {
  1447. /* transmit is done, so now check for errors
  1448. * If there is an error, an interrupt should
  1449. * happen when we return
  1450. */
  1451. time_now = get_timer (0);
  1452. if ((time_now - time_start) > 3000) {
  1453. return (-1);
  1454. }
  1455. } else {
  1456. return (len);
  1457. }
  1458. }
  1459. }
  1460. int enetInt (struct eth_device *dev)
  1461. {
  1462. int serviced;
  1463. int rc = -1; /* default to not us */
  1464. u32 mal_isr;
  1465. u32 emac_isr = 0;
  1466. u32 mal_eob;
  1467. u32 uic_mal;
  1468. u32 uic_mal_err;
  1469. u32 uic_emac;
  1470. u32 uic_emac_b;
  1471. EMAC_4XX_HW_PST hw_p;
  1472. /*
  1473. * Because the mal is generic, we need to get the current
  1474. * eth device
  1475. */
  1476. dev = eth_get_dev();
  1477. hw_p = dev->priv;
  1478. /* enter loop that stays in interrupt code until nothing to service */
  1479. do {
  1480. serviced = 0;
  1481. uic_mal = mfdcr(UIC_BASE_MAL + UIC_MSR);
  1482. uic_mal_err = mfdcr(UIC_BASE_MAL_ERR + UIC_MSR);
  1483. uic_emac = mfdcr(UIC_BASE_EMAC + UIC_MSR);
  1484. uic_emac_b = mfdcr(UIC_BASE_EMAC_B + UIC_MSR);
  1485. if (!(uic_mal & (UIC_MAL_RXEOB | UIC_MAL_TXEOB))
  1486. && !(uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE))
  1487. && !(uic_emac & UIC_ETHx) && !(uic_emac_b & UIC_ETHxB)) {
  1488. /* not for us */
  1489. return (rc);
  1490. }
  1491. /* get and clear controller status interrupts */
  1492. /* look at MAL and EMAC error interrupts */
  1493. if (uic_mal_err & (UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE)) {
  1494. /* we have a MAL error interrupt */
  1495. mal_isr = mfdcr(MAL0_ESR);
  1496. mal_err(dev, mal_isr, uic_mal_err,
  1497. MAL_UIC_DEF, MAL_UIC_ERR);
  1498. /* clear MAL error interrupt status bits */
  1499. mtdcr(UIC_BASE_MAL_ERR + UIC_SR,
  1500. UIC_MAL_SERR | UIC_MAL_TXDE | UIC_MAL_RXDE);
  1501. return -1;
  1502. }
  1503. /* look for EMAC errors */
  1504. if ((uic_emac & UIC_ETHx) || (uic_emac_b & UIC_ETHxB)) {
  1505. emac_isr = in_be32((void *)EMAC0_ISR + hw_p->hw_addr);
  1506. emac_err(dev, emac_isr);
  1507. /* clear EMAC error interrupt status bits */
  1508. mtdcr(UIC_BASE_EMAC + UIC_SR, UIC_ETHx);
  1509. mtdcr(UIC_BASE_EMAC_B + UIC_SR, UIC_ETHxB);
  1510. return -1;
  1511. }
  1512. /* handle MAX TX EOB interrupt from a tx */
  1513. if (uic_mal & UIC_MAL_TXEOB) {
  1514. /* clear MAL interrupt status bits */
  1515. mal_eob = mfdcr(MAL0_TXEOBISR);
  1516. mtdcr(MAL0_TXEOBISR, mal_eob);
  1517. mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_TXEOB);
  1518. /* indicate that we serviced an interrupt */
  1519. serviced = 1;
  1520. rc = 0;
  1521. }
  1522. /* handle MAL RX EOB interrupt from a receive */
  1523. /* check for EOB on valid channels */
  1524. if (uic_mal & UIC_MAL_RXEOB) {
  1525. mal_eob = mfdcr(MAL0_RXEOBISR);
  1526. if (mal_eob &
  1527. (0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL))) {
  1528. /* push packet to upper layer */
  1529. enet_rcv(dev, emac_isr);
  1530. /* clear MAL interrupt status bits */
  1531. mtdcr(UIC_BASE_MAL + UIC_SR, UIC_MAL_RXEOB);
  1532. /* indicate that we serviced an interrupt */
  1533. serviced = 1;
  1534. rc = 0;
  1535. }
  1536. }
  1537. #if defined(CONFIG_405EZ)
  1538. /*
  1539. * On 405EZ the RX-/TX-interrupts are coalesced into
  1540. * one IRQ bit in the UIC. We need to acknowledge the
  1541. * RX-/TX-interrupts in the SDR0_ICINTSTAT reg as well.
  1542. */
  1543. mtsdr(SDR0_ICINTSTAT,
  1544. SDR_ICRX_STAT | SDR_ICTX0_STAT | SDR_ICTX1_STAT);
  1545. #endif /* defined(CONFIG_405EZ) */
  1546. } while (serviced);
  1547. return (rc);
  1548. }
  1549. /*-----------------------------------------------------------------------------+
  1550. * MAL Error Routine
  1551. *-----------------------------------------------------------------------------*/
  1552. static void mal_err (struct eth_device *dev, unsigned long isr,
  1553. unsigned long uic, unsigned long maldef,
  1554. unsigned long mal_errr)
  1555. {
  1556. EMAC_4XX_HW_PST hw_p = dev->priv;
  1557. mtdcr (MAL0_ESR, isr); /* clear interrupt */
  1558. /* clear DE interrupt */
  1559. mtdcr (MAL0_TXDEIR, 0xC0000000);
  1560. mtdcr (MAL0_RXDEIR, 0x80000000);
  1561. #ifdef INFO_4XX_ENET
  1562. printf ("\nMAL error occured.... ISR = %lx UIC = = %lx MAL_DEF = %lx MAL_ERR= %lx \n", isr, uic, maldef, mal_errr);
  1563. #endif
  1564. eth_init (hw_p->bis); /* start again... */
  1565. }
  1566. /*-----------------------------------------------------------------------------+
  1567. * EMAC Error Routine
  1568. *-----------------------------------------------------------------------------*/
  1569. static void emac_err (struct eth_device *dev, unsigned long isr)
  1570. {
  1571. EMAC_4XX_HW_PST hw_p = dev->priv;
  1572. printf ("EMAC%d error occured.... ISR = %lx\n", hw_p->devnum, isr);
  1573. out_be32((void *)EMAC0_ISR + hw_p->hw_addr, isr);
  1574. }
  1575. /*-----------------------------------------------------------------------------+
  1576. * enet_rcv() handles the ethernet receive data
  1577. *-----------------------------------------------------------------------------*/
  1578. static void enet_rcv (struct eth_device *dev, unsigned long malisr)
  1579. {
  1580. unsigned long data_len;
  1581. unsigned long rx_eob_isr;
  1582. EMAC_4XX_HW_PST hw_p = dev->priv;
  1583. int handled = 0;
  1584. int i;
  1585. int loop_count = 0;
  1586. rx_eob_isr = mfdcr (MAL0_RXEOBISR);
  1587. if ((0x80000000 >> (hw_p->devnum * MAL_RX_CHAN_MUL)) & rx_eob_isr) {
  1588. /* clear EOB */
  1589. mtdcr (MAL0_RXEOBISR, rx_eob_isr);
  1590. /* EMAC RX done */
  1591. while (1) { /* do all */
  1592. i = hw_p->rx_slot;
  1593. if ((MAL_RX_CTRL_EMPTY & hw_p->rx[i].ctrl)
  1594. || (loop_count >= NUM_RX_BUFF))
  1595. break;
  1596. loop_count++;
  1597. handled++;
  1598. data_len = (unsigned long) hw_p->rx[i].data_len & 0x0fff; /* Get len */
  1599. if (data_len) {
  1600. if (data_len > ENET_MAX_MTU) /* Check len */
  1601. data_len = 0;
  1602. else {
  1603. if (EMAC_RX_ERRORS & hw_p->rx[i].ctrl) { /* Check Errors */
  1604. data_len = 0;
  1605. hw_p->stats.rx_err_log[hw_p->
  1606. rx_err_index]
  1607. = hw_p->rx[i].ctrl;
  1608. hw_p->rx_err_index++;
  1609. if (hw_p->rx_err_index ==
  1610. MAX_ERR_LOG)
  1611. hw_p->rx_err_index =
  1612. 0;
  1613. } /* emac_erros */
  1614. } /* data_len < max mtu */
  1615. } /* if data_len */
  1616. if (!data_len) { /* no data */
  1617. hw_p->rx[i].ctrl |= MAL_RX_CTRL_EMPTY; /* Free Recv Buffer */
  1618. hw_p->stats.data_len_err++; /* Error at Rx */
  1619. }
  1620. /* !data_len */
  1621. /* AS.HARNOIS */
  1622. /* Check if user has already eaten buffer */
  1623. /* if not => ERROR */
  1624. else if (hw_p->rx_ready[hw_p->rx_i_index] != -1) {
  1625. if (hw_p->is_receiving)
  1626. printf ("ERROR : Receive buffers are full!\n");
  1627. break;
  1628. } else {
  1629. hw_p->stats.rx_frames++;
  1630. hw_p->stats.rx += data_len;
  1631. #ifdef INFO_4XX_ENET
  1632. hw_p->stats.pkts_rx++;
  1633. #endif
  1634. /* AS.HARNOIS
  1635. * use ring buffer
  1636. */
  1637. hw_p->rx_ready[hw_p->rx_i_index] = i;
  1638. hw_p->rx_i_index++;
  1639. if (NUM_RX_BUFF == hw_p->rx_i_index)
  1640. hw_p->rx_i_index = 0;
  1641. hw_p->rx_slot++;
  1642. if (NUM_RX_BUFF == hw_p->rx_slot)
  1643. hw_p->rx_slot = 0;
  1644. /* AS.HARNOIS
  1645. * free receive buffer only when
  1646. * buffer has been handled (eth_rx)
  1647. rx[i].ctrl |= MAL_RX_CTRL_EMPTY;
  1648. */
  1649. } /* if data_len */
  1650. } /* while */
  1651. } /* if EMACK_RXCHL */
  1652. }
  1653. static int ppc_4xx_eth_rx (struct eth_device *dev)
  1654. {
  1655. int length;
  1656. int user_index;
  1657. unsigned long msr;
  1658. EMAC_4XX_HW_PST hw_p = dev->priv;
  1659. hw_p->is_receiving = 1; /* tell driver */
  1660. for (;;) {
  1661. /* AS.HARNOIS
  1662. * use ring buffer and
  1663. * get index from rx buffer desciptor queue
  1664. */
  1665. user_index = hw_p->rx_ready[hw_p->rx_u_index];
  1666. if (user_index == -1) {
  1667. length = -1;
  1668. break; /* nothing received - leave for() loop */
  1669. }
  1670. msr = mfmsr ();
  1671. mtmsr (msr & ~(MSR_EE));
  1672. length = hw_p->rx[user_index].data_len & 0x0fff;
  1673. /* Pass the packet up to the protocol layers. */
  1674. /* NetReceive(NetRxPackets[rxIdx], length - 4); */
  1675. /* NetReceive(NetRxPackets[i], length); */
  1676. invalidate_dcache_range((u32)hw_p->rx[user_index].data_ptr,
  1677. (u32)hw_p->rx[user_index].data_ptr +
  1678. length - 4);
  1679. NetReceive (NetRxPackets[user_index], length - 4);
  1680. /* Free Recv Buffer */
  1681. hw_p->rx[user_index].ctrl |= MAL_RX_CTRL_EMPTY;
  1682. /* Free rx buffer descriptor queue */
  1683. hw_p->rx_ready[hw_p->rx_u_index] = -1;
  1684. hw_p->rx_u_index++;
  1685. if (NUM_RX_BUFF == hw_p->rx_u_index)
  1686. hw_p->rx_u_index = 0;
  1687. #ifdef INFO_4XX_ENET
  1688. hw_p->stats.pkts_handled++;
  1689. #endif
  1690. mtmsr (msr); /* Enable IRQ's */
  1691. }
  1692. hw_p->is_receiving = 0; /* tell driver */
  1693. return length;
  1694. }
  1695. int ppc_4xx_eth_initialize (bd_t * bis)
  1696. {
  1697. static int virgin = 0;
  1698. struct eth_device *dev;
  1699. int eth_num = 0;
  1700. EMAC_4XX_HW_PST hw = NULL;
  1701. u8 ethaddr[4 + CONFIG_EMAC_NR_START][6];
  1702. u32 hw_addr[4];
  1703. u32 mal_ier;
  1704. #if defined(CONFIG_440GX)
  1705. unsigned long pfc1;
  1706. mfsdr (SDR0_PFC1, pfc1);
  1707. pfc1 &= ~(0x01e00000);
  1708. pfc1 |= 0x01200000;
  1709. mtsdr (SDR0_PFC1, pfc1);
  1710. #endif
  1711. /* first clear all mac-addresses */
  1712. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++)
  1713. memcpy(ethaddr[eth_num], "\0\0\0\0\0\0", 6);
  1714. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1715. int ethaddr_idx = eth_num + CONFIG_EMAC_NR_START;
  1716. switch (eth_num) {
  1717. default: /* fall through */
  1718. case 0:
  1719. eth_getenv_enetaddr("ethaddr", ethaddr[ethaddr_idx]);
  1720. hw_addr[eth_num] = 0x0;
  1721. break;
  1722. #ifdef CONFIG_HAS_ETH1
  1723. case 1:
  1724. eth_getenv_enetaddr("eth1addr", ethaddr[ethaddr_idx]);
  1725. hw_addr[eth_num] = 0x100;
  1726. break;
  1727. #endif
  1728. #ifdef CONFIG_HAS_ETH2
  1729. case 2:
  1730. eth_getenv_enetaddr("eth2addr", ethaddr[ethaddr_idx]);
  1731. #if defined(CONFIG_460GT)
  1732. hw_addr[eth_num] = 0x300;
  1733. #else
  1734. hw_addr[eth_num] = 0x400;
  1735. #endif
  1736. break;
  1737. #endif
  1738. #ifdef CONFIG_HAS_ETH3
  1739. case 3:
  1740. eth_getenv_enetaddr("eth3addr", ethaddr[ethaddr_idx]);
  1741. #if defined(CONFIG_460GT)
  1742. hw_addr[eth_num] = 0x400;
  1743. #else
  1744. hw_addr[eth_num] = 0x600;
  1745. #endif
  1746. break;
  1747. #endif
  1748. }
  1749. }
  1750. /* set phy num and mode */
  1751. bis->bi_phynum[0] = CONFIG_PHY_ADDR;
  1752. bis->bi_phymode[0] = 0;
  1753. #if defined(CONFIG_PHY1_ADDR)
  1754. bis->bi_phynum[1] = CONFIG_PHY1_ADDR;
  1755. bis->bi_phymode[1] = 0;
  1756. #endif
  1757. #if defined(CONFIG_440GX)
  1758. bis->bi_phynum[2] = CONFIG_PHY2_ADDR;
  1759. bis->bi_phynum[3] = CONFIG_PHY3_ADDR;
  1760. bis->bi_phymode[2] = 2;
  1761. bis->bi_phymode[3] = 2;
  1762. #endif
  1763. #if defined(CONFIG_440GX) || \
  1764. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1765. defined(CONFIG_405EX)
  1766. ppc_4xx_eth_setup_bridge(0, bis);
  1767. #endif
  1768. for (eth_num = 0; eth_num < LAST_EMAC_NUM; eth_num++) {
  1769. /*
  1770. * See if we can actually bring up the interface,
  1771. * otherwise, skip it
  1772. */
  1773. if (memcmp (ethaddr[eth_num], "\0\0\0\0\0\0", 6) == 0) {
  1774. bis->bi_phymode[eth_num] = BI_PHYMODE_NONE;
  1775. continue;
  1776. }
  1777. /* Allocate device structure */
  1778. dev = (struct eth_device *) malloc (sizeof (*dev));
  1779. if (dev == NULL) {
  1780. printf ("ppc_4xx_eth_initialize: "
  1781. "Cannot allocate eth_device %d\n", eth_num);
  1782. return (-1);
  1783. }
  1784. memset(dev, 0, sizeof(*dev));
  1785. /* Allocate our private use data */
  1786. hw = (EMAC_4XX_HW_PST) malloc (sizeof (*hw));
  1787. if (hw == NULL) {
  1788. printf ("ppc_4xx_eth_initialize: "
  1789. "Cannot allocate private hw data for eth_device %d",
  1790. eth_num);
  1791. free (dev);
  1792. return (-1);
  1793. }
  1794. memset(hw, 0, sizeof(*hw));
  1795. hw->hw_addr = hw_addr[eth_num];
  1796. memcpy (dev->enetaddr, ethaddr[eth_num], 6);
  1797. hw->devnum = eth_num;
  1798. hw->print_speed = 1;
  1799. sprintf (dev->name, "ppc_4xx_eth%d", eth_num - CONFIG_EMAC_NR_START);
  1800. dev->priv = (void *) hw;
  1801. dev->init = ppc_4xx_eth_init;
  1802. dev->halt = ppc_4xx_eth_halt;
  1803. dev->send = ppc_4xx_eth_send;
  1804. dev->recv = ppc_4xx_eth_rx;
  1805. eth_register(dev);
  1806. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
  1807. miiphy_register(dev->name,
  1808. emac4xx_miiphy_read, emac4xx_miiphy_write);
  1809. #endif
  1810. if (0 == virgin) {
  1811. /* set the MAL IER ??? names may change with new spec ??? */
  1812. #if defined(CONFIG_440SPE) || \
  1813. defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
  1814. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  1815. defined(CONFIG_405EX)
  1816. mal_ier =
  1817. MAL_IER_PT | MAL_IER_PRE | MAL_IER_PWE |
  1818. MAL_IER_DE | MAL_IER_OTE | MAL_IER_OE | MAL_IER_PE ;
  1819. #else
  1820. mal_ier =
  1821. MAL_IER_DE | MAL_IER_NE | MAL_IER_TE |
  1822. MAL_IER_OPBE | MAL_IER_PLBE;
  1823. #endif
  1824. mtdcr (MAL0_ESR, 0xffffffff); /* clear pending interrupts */
  1825. mtdcr (MAL0_TXDEIR, 0xffffffff); /* clear pending interrupts */
  1826. mtdcr (MAL0_RXDEIR, 0xffffffff); /* clear pending interrupts */
  1827. mtdcr (MAL0_IER, mal_ier);
  1828. /* install MAL interrupt handler */
  1829. irq_install_handler (VECNUM_MAL_SERR,
  1830. (interrupt_handler_t *) enetInt,
  1831. dev);
  1832. irq_install_handler (VECNUM_MAL_TXEOB,
  1833. (interrupt_handler_t *) enetInt,
  1834. dev);
  1835. irq_install_handler (VECNUM_MAL_RXEOB,
  1836. (interrupt_handler_t *) enetInt,
  1837. dev);
  1838. irq_install_handler (VECNUM_MAL_TXDE,
  1839. (interrupt_handler_t *) enetInt,
  1840. dev);
  1841. irq_install_handler (VECNUM_MAL_RXDE,
  1842. (interrupt_handler_t *) enetInt,
  1843. dev);
  1844. virgin = 1;
  1845. }
  1846. } /* end for each supported device */
  1847. return 0;
  1848. }