tsec.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. /*
  2. * Freescale Three Speed Ethernet Controller driver
  3. *
  4. * This software may be used and distributed according to the
  5. * terms of the GNU Public License, Version 2, incorporated
  6. * herein by reference.
  7. *
  8. * Copyright (C) 2004-2009 Freescale Semiconductor, Inc.
  9. * (C) Copyright 2003, Motorola, Inc.
  10. * author Andy Fleming
  11. *
  12. */
  13. #include <config.h>
  14. #include <common.h>
  15. #include <malloc.h>
  16. #include <net.h>
  17. #include <command.h>
  18. #include <tsec.h>
  19. #include "miiphy.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #define TX_BUF_CNT 2
  22. static uint rxIdx; /* index of the current RX buffer */
  23. static uint txIdx; /* index of the current TX buffer */
  24. typedef volatile struct rtxbd {
  25. txbd8_t txbd[TX_BUF_CNT];
  26. rxbd8_t rxbd[PKTBUFSRX];
  27. } RTXBD;
  28. #define MAXCONTROLLERS (8)
  29. static int relocated = 0;
  30. static struct tsec_private *privlist[MAXCONTROLLERS];
  31. static int num_tsecs = 0;
  32. #ifdef __GNUC__
  33. static RTXBD rtx __attribute__ ((aligned(8)));
  34. #else
  35. #error "rtx must be 64-bit aligned"
  36. #endif
  37. static int tsec_send(struct eth_device *dev,
  38. volatile void *packet, int length);
  39. static int tsec_recv(struct eth_device *dev);
  40. static int tsec_init(struct eth_device *dev, bd_t * bd);
  41. static void tsec_halt(struct eth_device *dev);
  42. static void init_registers(volatile tsec_t * regs);
  43. static void startup_tsec(struct eth_device *dev);
  44. static int init_phy(struct eth_device *dev);
  45. void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
  46. uint read_phy_reg(struct tsec_private *priv, uint regnum);
  47. struct phy_info *get_phy_info(struct eth_device *dev);
  48. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
  49. static void adjust_link(struct eth_device *dev);
  50. static void relocate_cmds(void);
  51. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
  52. && !defined(BITBANGMII)
  53. static int tsec_miiphy_write(char *devname, unsigned char addr,
  54. unsigned char reg, unsigned short value);
  55. static int tsec_miiphy_read(char *devname, unsigned char addr,
  56. unsigned char reg, unsigned short *value);
  57. #endif
  58. #ifdef CONFIG_MCAST_TFTP
  59. static int tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set);
  60. #endif
  61. /* Default initializations for TSEC controllers. */
  62. static struct tsec_info_struct tsec_info[] = {
  63. #ifdef CONFIG_TSEC1
  64. STD_TSEC_INFO(1), /* TSEC1 */
  65. #endif
  66. #ifdef CONFIG_TSEC2
  67. STD_TSEC_INFO(2), /* TSEC2 */
  68. #endif
  69. #ifdef CONFIG_MPC85XX_FEC
  70. {
  71. .regs = (tsec_t *)(TSEC_BASE_ADDR + 0x2000),
  72. .miiregs = (tsec_t *)(TSEC_BASE_ADDR),
  73. .devname = CONFIG_MPC85XX_FEC_NAME,
  74. .phyaddr = FEC_PHY_ADDR,
  75. .flags = FEC_FLAGS
  76. }, /* FEC */
  77. #endif
  78. #ifdef CONFIG_TSEC3
  79. STD_TSEC_INFO(3), /* TSEC3 */
  80. #endif
  81. #ifdef CONFIG_TSEC4
  82. STD_TSEC_INFO(4), /* TSEC4 */
  83. #endif
  84. };
  85. int tsec_eth_init(bd_t *bis, struct tsec_info_struct *tsecs, int num)
  86. {
  87. int i;
  88. for (i = 0; i < num; i++)
  89. tsec_initialize(bis, &tsecs[i]);
  90. return 0;
  91. }
  92. int tsec_standard_init(bd_t *bis)
  93. {
  94. return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info));
  95. }
  96. /* Initialize device structure. Returns success if PHY
  97. * initialization succeeded (i.e. if it recognizes the PHY)
  98. */
  99. int tsec_initialize(bd_t * bis, struct tsec_info_struct *tsec_info)
  100. {
  101. struct eth_device *dev;
  102. int i;
  103. struct tsec_private *priv;
  104. dev = (struct eth_device *)malloc(sizeof *dev);
  105. if (NULL == dev)
  106. return 0;
  107. memset(dev, 0, sizeof *dev);
  108. priv = (struct tsec_private *)malloc(sizeof(*priv));
  109. if (NULL == priv)
  110. return 0;
  111. privlist[num_tsecs++] = priv;
  112. priv->regs = tsec_info->regs;
  113. priv->phyregs = tsec_info->miiregs;
  114. priv->phyaddr = tsec_info->phyaddr;
  115. priv->flags = tsec_info->flags;
  116. sprintf(dev->name, tsec_info->devname);
  117. dev->iobase = 0;
  118. dev->priv = priv;
  119. dev->init = tsec_init;
  120. dev->halt = tsec_halt;
  121. dev->send = tsec_send;
  122. dev->recv = tsec_recv;
  123. #ifdef CONFIG_MCAST_TFTP
  124. dev->mcast = tsec_mcast_addr;
  125. #endif
  126. /* Tell u-boot to get the addr from the env */
  127. for (i = 0; i < 6; i++)
  128. dev->enetaddr[i] = 0;
  129. eth_register(dev);
  130. /* Reset the MAC */
  131. priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
  132. udelay(2); /* Soft Reset must be asserted for 3 TX clocks */
  133. priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
  134. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
  135. && !defined(BITBANGMII)
  136. miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
  137. #endif
  138. /* Try to initialize PHY here, and return */
  139. return init_phy(dev);
  140. }
  141. /* Initializes data structures and registers for the controller,
  142. * and brings the interface up. Returns the link status, meaning
  143. * that it returns success if the link is up, failure otherwise.
  144. * This allows u-boot to find the first active controller.
  145. */
  146. int tsec_init(struct eth_device *dev, bd_t * bd)
  147. {
  148. uint tempval;
  149. char tmpbuf[MAC_ADDR_LEN];
  150. int i;
  151. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  152. volatile tsec_t *regs = priv->regs;
  153. /* Make sure the controller is stopped */
  154. tsec_halt(dev);
  155. /* Init MACCFG2. Defaults to GMII */
  156. regs->maccfg2 = MACCFG2_INIT_SETTINGS;
  157. /* Init ECNTRL */
  158. regs->ecntrl = ECNTRL_INIT_SETTINGS;
  159. /* Copy the station address into the address registers.
  160. * Backwards, because little endian MACS are dumb */
  161. for (i = 0; i < MAC_ADDR_LEN; i++) {
  162. tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
  163. }
  164. tempval = (tmpbuf[0] << 24) | (tmpbuf[1] << 16) | (tmpbuf[2] << 8) |
  165. tmpbuf[3];
  166. regs->macstnaddr1 = tempval;
  167. tempval = *((uint *) (tmpbuf + 4));
  168. regs->macstnaddr2 = tempval;
  169. /* reset the indices to zero */
  170. rxIdx = 0;
  171. txIdx = 0;
  172. /* Clear out (for the most part) the other registers */
  173. init_registers(regs);
  174. /* Ready the device for tx/rx */
  175. startup_tsec(dev);
  176. /* If there's no link, fail */
  177. return (priv->link ? 0 : -1);
  178. }
  179. /* Writes the given phy's reg with value, using the specified MDIO regs */
  180. static void tsec_local_mdio_write(volatile tsec_t *phyregs, uint addr,
  181. uint reg, uint value)
  182. {
  183. int timeout = 1000000;
  184. phyregs->miimadd = (addr << 8) | reg;
  185. phyregs->miimcon = value;
  186. asm("sync");
  187. timeout = 1000000;
  188. while ((phyregs->miimind & MIIMIND_BUSY) && timeout--) ;
  189. }
  190. /* Provide the default behavior of writing the PHY of this ethernet device */
  191. #define write_phy_reg(priv, regnum, value) tsec_local_mdio_write(priv->phyregs,priv->phyaddr,regnum,value)
  192. /* Reads register regnum on the device's PHY through the
  193. * specified registers. It lowers and raises the read
  194. * command, and waits for the data to become valid (miimind
  195. * notvalid bit cleared), and the bus to cease activity (miimind
  196. * busy bit cleared), and then returns the value
  197. */
  198. uint tsec_local_mdio_read(volatile tsec_t *phyregs, uint phyid, uint regnum)
  199. {
  200. uint value;
  201. /* Put the address of the phy, and the register
  202. * number into MIIMADD */
  203. phyregs->miimadd = (phyid << 8) | regnum;
  204. /* Clear the command register, and wait */
  205. phyregs->miimcom = 0;
  206. asm("sync");
  207. /* Initiate a read command, and wait */
  208. phyregs->miimcom = MIIM_READ_COMMAND;
  209. asm("sync");
  210. /* Wait for the the indication that the read is done */
  211. while ((phyregs->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
  212. /* Grab the value read from the PHY */
  213. value = phyregs->miimstat;
  214. return value;
  215. }
  216. /* #define to provide old read_phy_reg functionality without duplicating code */
  217. #define read_phy_reg(priv,regnum) tsec_local_mdio_read(priv->phyregs,priv->phyaddr,regnum)
  218. #define TBIANA_SETTINGS ( \
  219. TBIANA_ASYMMETRIC_PAUSE \
  220. | TBIANA_SYMMETRIC_PAUSE \
  221. | TBIANA_FULL_DUPLEX \
  222. )
  223. #define TBICR_SETTINGS ( \
  224. TBICR_PHY_RESET \
  225. | TBICR_ANEG_ENABLE \
  226. | TBICR_FULL_DUPLEX \
  227. | TBICR_SPEED1_SET \
  228. )
  229. /* Configure the TBI for SGMII operation */
  230. static void tsec_configure_serdes(struct tsec_private *priv)
  231. {
  232. /* Access TBI PHY registers at given TSEC register offset as opposed to the
  233. * register offset used for external PHY accesses */
  234. tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_ANA,
  235. TBIANA_SETTINGS);
  236. tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_TBICON,
  237. TBICON_CLK_SELECT);
  238. tsec_local_mdio_write(priv->regs, priv->regs->tbipa, TBI_CR,
  239. TBICR_SETTINGS);
  240. }
  241. /* Discover which PHY is attached to the device, and configure it
  242. * properly. If the PHY is not recognized, then return 0
  243. * (failure). Otherwise, return 1
  244. */
  245. static int init_phy(struct eth_device *dev)
  246. {
  247. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  248. struct phy_info *curphy;
  249. volatile tsec_t *phyregs = priv->phyregs;
  250. volatile tsec_t *regs = priv->regs;
  251. /* Assign a Physical address to the TBI */
  252. regs->tbipa = CONFIG_SYS_TBIPA_VALUE;
  253. phyregs->tbipa = CONFIG_SYS_TBIPA_VALUE;
  254. asm("sync");
  255. /* Reset MII (due to new addresses) */
  256. priv->phyregs->miimcfg = MIIMCFG_RESET;
  257. asm("sync");
  258. priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  259. asm("sync");
  260. while (priv->phyregs->miimind & MIIMIND_BUSY) ;
  261. if (0 == relocated)
  262. relocate_cmds();
  263. /* Get the cmd structure corresponding to the attached
  264. * PHY */
  265. curphy = get_phy_info(dev);
  266. if (curphy == NULL) {
  267. priv->phyinfo = NULL;
  268. printf("%s: No PHY found\n", dev->name);
  269. return 0;
  270. }
  271. if (regs->ecntrl & ECNTRL_SGMII_MODE)
  272. tsec_configure_serdes(priv);
  273. priv->phyinfo = curphy;
  274. phy_run_commands(priv, priv->phyinfo->config);
  275. return 1;
  276. }
  277. /*
  278. * Returns which value to write to the control register.
  279. * For 10/100, the value is slightly different
  280. */
  281. uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
  282. {
  283. if (priv->flags & TSEC_GIGABIT)
  284. return MIIM_CONTROL_INIT;
  285. else
  286. return MIIM_CR_INIT;
  287. }
  288. /* Parse the status register for link, and then do
  289. * auto-negotiation
  290. */
  291. uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
  292. {
  293. /*
  294. * Wait if the link is up, and autonegotiation is in progress
  295. * (ie - we're capable and it's not done)
  296. */
  297. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  298. if ((mii_reg & MIIM_STATUS_LINK) && (mii_reg & PHY_BMSR_AUTN_ABLE)
  299. && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
  300. int i = 0;
  301. puts("Waiting for PHY auto negotiation to complete");
  302. while (!(mii_reg & PHY_BMSR_AUTN_COMP)) {
  303. /*
  304. * Timeout reached ?
  305. */
  306. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  307. puts(" TIMEOUT !\n");
  308. priv->link = 0;
  309. return 0;
  310. }
  311. if ((i++ % 1000) == 0) {
  312. putc('.');
  313. }
  314. udelay(1000); /* 1 ms */
  315. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  316. }
  317. puts(" done\n");
  318. priv->link = 1;
  319. udelay(500000); /* another 500 ms (results in faster booting) */
  320. } else {
  321. if (mii_reg & MIIM_STATUS_LINK)
  322. priv->link = 1;
  323. else
  324. priv->link = 0;
  325. }
  326. return 0;
  327. }
  328. /* Generic function which updates the speed and duplex. If
  329. * autonegotiation is enabled, it uses the AND of the link
  330. * partner's advertised capabilities and our advertised
  331. * capabilities. If autonegotiation is disabled, we use the
  332. * appropriate bits in the control register.
  333. *
  334. * Stolen from Linux's mii.c and phy_device.c
  335. */
  336. uint mii_parse_link(uint mii_reg, struct tsec_private *priv)
  337. {
  338. /* We're using autonegotiation */
  339. if (mii_reg & PHY_BMSR_AUTN_ABLE) {
  340. uint lpa = 0;
  341. uint gblpa = 0;
  342. /* Check for gigabit capability */
  343. if (mii_reg & PHY_BMSR_EXT) {
  344. /* We want a list of states supported by
  345. * both PHYs in the link
  346. */
  347. gblpa = read_phy_reg(priv, PHY_1000BTSR);
  348. gblpa &= read_phy_reg(priv, PHY_1000BTCR) << 2;
  349. }
  350. /* Set the baseline so we only have to set them
  351. * if they're different
  352. */
  353. priv->speed = 10;
  354. priv->duplexity = 0;
  355. /* Check the gigabit fields */
  356. if (gblpa & (PHY_1000BTSR_1000FD | PHY_1000BTSR_1000HD)) {
  357. priv->speed = 1000;
  358. if (gblpa & PHY_1000BTSR_1000FD)
  359. priv->duplexity = 1;
  360. /* We're done! */
  361. return 0;
  362. }
  363. lpa = read_phy_reg(priv, PHY_ANAR);
  364. lpa &= read_phy_reg(priv, PHY_ANLPAR);
  365. if (lpa & (PHY_ANLPAR_TXFD | PHY_ANLPAR_TX)) {
  366. priv->speed = 100;
  367. if (lpa & PHY_ANLPAR_TXFD)
  368. priv->duplexity = 1;
  369. } else if (lpa & PHY_ANLPAR_10FD)
  370. priv->duplexity = 1;
  371. } else {
  372. uint bmcr = read_phy_reg(priv, PHY_BMCR);
  373. priv->speed = 10;
  374. priv->duplexity = 0;
  375. if (bmcr & PHY_BMCR_DPLX)
  376. priv->duplexity = 1;
  377. if (bmcr & PHY_BMCR_1000_MBPS)
  378. priv->speed = 1000;
  379. else if (bmcr & PHY_BMCR_100_MBPS)
  380. priv->speed = 100;
  381. }
  382. return 0;
  383. }
  384. /*
  385. * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
  386. * circumstances. eg a gigabit TSEC connected to a gigabit switch with
  387. * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
  388. * link. "Ethernet@Wirespeed" reduces advertised speed until link
  389. * can be achieved.
  390. */
  391. uint mii_BCM54xx_wirespeed(uint mii_reg, struct tsec_private *priv)
  392. {
  393. return (read_phy_reg(priv, mii_reg) & 0x8FFF) | 0x8010;
  394. }
  395. /*
  396. * Parse the BCM54xx status register for speed and duplex information.
  397. * The linux sungem_phy has this information, but in a table format.
  398. */
  399. uint mii_parse_BCM54xx_sr(uint mii_reg, struct tsec_private *priv)
  400. {
  401. switch((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >> MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT){
  402. case 1:
  403. printf("Enet starting in 10BT/HD\n");
  404. priv->duplexity = 0;
  405. priv->speed = 10;
  406. break;
  407. case 2:
  408. printf("Enet starting in 10BT/FD\n");
  409. priv->duplexity = 1;
  410. priv->speed = 10;
  411. break;
  412. case 3:
  413. printf("Enet starting in 100BT/HD\n");
  414. priv->duplexity = 0;
  415. priv->speed = 100;
  416. break;
  417. case 5:
  418. printf("Enet starting in 100BT/FD\n");
  419. priv->duplexity = 1;
  420. priv->speed = 100;
  421. break;
  422. case 6:
  423. printf("Enet starting in 1000BT/HD\n");
  424. priv->duplexity = 0;
  425. priv->speed = 1000;
  426. break;
  427. case 7:
  428. printf("Enet starting in 1000BT/FD\n");
  429. priv->duplexity = 1;
  430. priv->speed = 1000;
  431. break;
  432. default:
  433. printf("Auto-neg error, defaulting to 10BT/HD\n");
  434. priv->duplexity = 0;
  435. priv->speed = 10;
  436. break;
  437. }
  438. return 0;
  439. }
  440. /* Parse the 88E1011's status register for speed and duplex
  441. * information
  442. */
  443. uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
  444. {
  445. uint speed;
  446. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  447. if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
  448. !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
  449. int i = 0;
  450. puts("Waiting for PHY realtime link");
  451. while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
  452. /* Timeout reached ? */
  453. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  454. puts(" TIMEOUT !\n");
  455. priv->link = 0;
  456. break;
  457. }
  458. if ((i++ % 1000) == 0) {
  459. putc('.');
  460. }
  461. udelay(1000); /* 1 ms */
  462. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  463. }
  464. puts(" done\n");
  465. udelay(500000); /* another 500 ms (results in faster booting) */
  466. } else {
  467. if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
  468. priv->link = 1;
  469. else
  470. priv->link = 0;
  471. }
  472. if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
  473. priv->duplexity = 1;
  474. else
  475. priv->duplexity = 0;
  476. speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
  477. switch (speed) {
  478. case MIIM_88E1011_PHYSTAT_GBIT:
  479. priv->speed = 1000;
  480. break;
  481. case MIIM_88E1011_PHYSTAT_100:
  482. priv->speed = 100;
  483. break;
  484. default:
  485. priv->speed = 10;
  486. }
  487. return 0;
  488. }
  489. /* Parse the RTL8211B's status register for speed and duplex
  490. * information
  491. */
  492. uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
  493. {
  494. uint speed;
  495. mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
  496. if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
  497. int i = 0;
  498. /* in case of timeout ->link is cleared */
  499. priv->link = 1;
  500. puts("Waiting for PHY realtime link");
  501. while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
  502. /* Timeout reached ? */
  503. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  504. puts(" TIMEOUT !\n");
  505. priv->link = 0;
  506. break;
  507. }
  508. if ((i++ % 1000) == 0) {
  509. putc('.');
  510. }
  511. udelay(1000); /* 1 ms */
  512. mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
  513. }
  514. puts(" done\n");
  515. udelay(500000); /* another 500 ms (results in faster booting) */
  516. } else {
  517. if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
  518. priv->link = 1;
  519. else
  520. priv->link = 0;
  521. }
  522. if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
  523. priv->duplexity = 1;
  524. else
  525. priv->duplexity = 0;
  526. speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
  527. switch (speed) {
  528. case MIIM_RTL8211B_PHYSTAT_GBIT:
  529. priv->speed = 1000;
  530. break;
  531. case MIIM_RTL8211B_PHYSTAT_100:
  532. priv->speed = 100;
  533. break;
  534. default:
  535. priv->speed = 10;
  536. }
  537. return 0;
  538. }
  539. /* Parse the cis8201's status register for speed and duplex
  540. * information
  541. */
  542. uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
  543. {
  544. uint speed;
  545. if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
  546. priv->duplexity = 1;
  547. else
  548. priv->duplexity = 0;
  549. speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
  550. switch (speed) {
  551. case MIIM_CIS8201_AUXCONSTAT_GBIT:
  552. priv->speed = 1000;
  553. break;
  554. case MIIM_CIS8201_AUXCONSTAT_100:
  555. priv->speed = 100;
  556. break;
  557. default:
  558. priv->speed = 10;
  559. break;
  560. }
  561. return 0;
  562. }
  563. /* Parse the vsc8244's status register for speed and duplex
  564. * information
  565. */
  566. uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
  567. {
  568. uint speed;
  569. if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
  570. priv->duplexity = 1;
  571. else
  572. priv->duplexity = 0;
  573. speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
  574. switch (speed) {
  575. case MIIM_VSC8244_AUXCONSTAT_GBIT:
  576. priv->speed = 1000;
  577. break;
  578. case MIIM_VSC8244_AUXCONSTAT_100:
  579. priv->speed = 100;
  580. break;
  581. default:
  582. priv->speed = 10;
  583. break;
  584. }
  585. return 0;
  586. }
  587. /* Parse the DM9161's status register for speed and duplex
  588. * information
  589. */
  590. uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
  591. {
  592. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
  593. priv->speed = 100;
  594. else
  595. priv->speed = 10;
  596. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
  597. priv->duplexity = 1;
  598. else
  599. priv->duplexity = 0;
  600. return 0;
  601. }
  602. /*
  603. * Hack to write all 4 PHYs with the LED values
  604. */
  605. uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
  606. {
  607. uint phyid;
  608. volatile tsec_t *regbase = priv->phyregs;
  609. int timeout = 1000000;
  610. for (phyid = 0; phyid < 4; phyid++) {
  611. regbase->miimadd = (phyid << 8) | mii_reg;
  612. regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
  613. asm("sync");
  614. timeout = 1000000;
  615. while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
  616. }
  617. return MIIM_CIS8204_SLEDCON_INIT;
  618. }
  619. uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
  620. {
  621. if (priv->flags & TSEC_REDUCED)
  622. return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
  623. else
  624. return MIIM_CIS8204_EPHYCON_INIT;
  625. }
  626. uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
  627. {
  628. uint mii_data = read_phy_reg(priv, mii_reg);
  629. if (priv->flags & TSEC_REDUCED)
  630. mii_data = (mii_data & 0xfff0) | 0x000b;
  631. return mii_data;
  632. }
  633. /* Initialized required registers to appropriate values, zeroing
  634. * those we don't care about (unless zero is bad, in which case,
  635. * choose a more appropriate value)
  636. */
  637. static void init_registers(volatile tsec_t * regs)
  638. {
  639. /* Clear IEVENT */
  640. regs->ievent = IEVENT_INIT_CLEAR;
  641. regs->imask = IMASK_INIT_CLEAR;
  642. regs->hash.iaddr0 = 0;
  643. regs->hash.iaddr1 = 0;
  644. regs->hash.iaddr2 = 0;
  645. regs->hash.iaddr3 = 0;
  646. regs->hash.iaddr4 = 0;
  647. regs->hash.iaddr5 = 0;
  648. regs->hash.iaddr6 = 0;
  649. regs->hash.iaddr7 = 0;
  650. regs->hash.gaddr0 = 0;
  651. regs->hash.gaddr1 = 0;
  652. regs->hash.gaddr2 = 0;
  653. regs->hash.gaddr3 = 0;
  654. regs->hash.gaddr4 = 0;
  655. regs->hash.gaddr5 = 0;
  656. regs->hash.gaddr6 = 0;
  657. regs->hash.gaddr7 = 0;
  658. regs->rctrl = 0x00000000;
  659. /* Init RMON mib registers */
  660. memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
  661. regs->rmon.cam1 = 0xffffffff;
  662. regs->rmon.cam2 = 0xffffffff;
  663. regs->mrblr = MRBLR_INIT_SETTINGS;
  664. regs->minflr = MINFLR_INIT_SETTINGS;
  665. regs->attr = ATTR_INIT_SETTINGS;
  666. regs->attreli = ATTRELI_INIT_SETTINGS;
  667. }
  668. /* Configure maccfg2 based on negotiated speed and duplex
  669. * reported by PHY handling code
  670. */
  671. static void adjust_link(struct eth_device *dev)
  672. {
  673. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  674. volatile tsec_t *regs = priv->regs;
  675. if (priv->link) {
  676. if (priv->duplexity != 0)
  677. regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
  678. else
  679. regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
  680. switch (priv->speed) {
  681. case 1000:
  682. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  683. | MACCFG2_GMII);
  684. break;
  685. case 100:
  686. case 10:
  687. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  688. | MACCFG2_MII);
  689. /* Set R100 bit in all modes although
  690. * it is only used in RGMII mode
  691. */
  692. if (priv->speed == 100)
  693. regs->ecntrl |= ECNTRL_R100;
  694. else
  695. regs->ecntrl &= ~(ECNTRL_R100);
  696. break;
  697. default:
  698. printf("%s: Speed was bad\n", dev->name);
  699. break;
  700. }
  701. printf("Speed: %d, %s duplex\n", priv->speed,
  702. (priv->duplexity) ? "full" : "half");
  703. } else {
  704. printf("%s: No link.\n", dev->name);
  705. }
  706. }
  707. /* Set up the buffers and their descriptors, and bring up the
  708. * interface
  709. */
  710. static void startup_tsec(struct eth_device *dev)
  711. {
  712. int i;
  713. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  714. volatile tsec_t *regs = priv->regs;
  715. /* Point to the buffer descriptors */
  716. regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
  717. regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
  718. /* Initialize the Rx Buffer descriptors */
  719. for (i = 0; i < PKTBUFSRX; i++) {
  720. rtx.rxbd[i].status = RXBD_EMPTY;
  721. rtx.rxbd[i].length = 0;
  722. rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
  723. }
  724. rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
  725. /* Initialize the TX Buffer Descriptors */
  726. for (i = 0; i < TX_BUF_CNT; i++) {
  727. rtx.txbd[i].status = 0;
  728. rtx.txbd[i].length = 0;
  729. rtx.txbd[i].bufPtr = 0;
  730. }
  731. rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
  732. /* Start up the PHY */
  733. if(priv->phyinfo)
  734. phy_run_commands(priv, priv->phyinfo->startup);
  735. adjust_link(dev);
  736. /* Enable Transmit and Receive */
  737. regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  738. /* Tell the DMA it is clear to go */
  739. regs->dmactrl |= DMACTRL_INIT_SETTINGS;
  740. regs->tstat = TSTAT_CLEAR_THALT;
  741. regs->rstat = RSTAT_CLEAR_RHALT;
  742. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  743. }
  744. /* This returns the status bits of the device. The return value
  745. * is never checked, and this is what the 8260 driver did, so we
  746. * do the same. Presumably, this would be zero if there were no
  747. * errors
  748. */
  749. static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
  750. {
  751. int i;
  752. int result = 0;
  753. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  754. volatile tsec_t *regs = priv->regs;
  755. /* Find an empty buffer descriptor */
  756. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  757. if (i >= TOUT_LOOP) {
  758. debug("%s: tsec: tx buffers full\n", dev->name);
  759. return result;
  760. }
  761. }
  762. rtx.txbd[txIdx].bufPtr = (uint) packet;
  763. rtx.txbd[txIdx].length = length;
  764. rtx.txbd[txIdx].status |=
  765. (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
  766. /* Tell the DMA to go */
  767. regs->tstat = TSTAT_CLEAR_THALT;
  768. /* Wait for buffer to be transmitted */
  769. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  770. if (i >= TOUT_LOOP) {
  771. debug("%s: tsec: tx error\n", dev->name);
  772. return result;
  773. }
  774. }
  775. txIdx = (txIdx + 1) % TX_BUF_CNT;
  776. result = rtx.txbd[txIdx].status & TXBD_STATS;
  777. return result;
  778. }
  779. static int tsec_recv(struct eth_device *dev)
  780. {
  781. int length;
  782. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  783. volatile tsec_t *regs = priv->regs;
  784. while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
  785. length = rtx.rxbd[rxIdx].length;
  786. /* Send the packet up if there were no errors */
  787. if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
  788. NetReceive(NetRxPackets[rxIdx], length - 4);
  789. } else {
  790. printf("Got error %x\n",
  791. (rtx.rxbd[rxIdx].status & RXBD_STATS));
  792. }
  793. rtx.rxbd[rxIdx].length = 0;
  794. /* Set the wrap bit if this is the last element in the list */
  795. rtx.rxbd[rxIdx].status =
  796. RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
  797. rxIdx = (rxIdx + 1) % PKTBUFSRX;
  798. }
  799. if (regs->ievent & IEVENT_BSY) {
  800. regs->ievent = IEVENT_BSY;
  801. regs->rstat = RSTAT_CLEAR_RHALT;
  802. }
  803. return -1;
  804. }
  805. /* Stop the interface */
  806. static void tsec_halt(struct eth_device *dev)
  807. {
  808. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  809. volatile tsec_t *regs = priv->regs;
  810. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  811. regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
  812. while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
  813. regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
  814. /* Shut down the PHY, as needed */
  815. if(priv->phyinfo)
  816. phy_run_commands(priv, priv->phyinfo->shutdown);
  817. }
  818. struct phy_info phy_info_M88E1149S = {
  819. 0x1410ca,
  820. "Marvell 88E1149S",
  821. 4,
  822. (struct phy_cmd[]){ /* config */
  823. /* Reset and configure the PHY */
  824. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  825. {0x1d, 0x1f, NULL},
  826. {0x1e, 0x200c, NULL},
  827. {0x1d, 0x5, NULL},
  828. {0x1e, 0x0, NULL},
  829. {0x1e, 0x100, NULL},
  830. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  831. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  832. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  833. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  834. {miim_end,}
  835. },
  836. (struct phy_cmd[]){ /* startup */
  837. /* Status is read once to clear old link state */
  838. {MIIM_STATUS, miim_read, NULL},
  839. /* Auto-negotiate */
  840. {MIIM_STATUS, miim_read, &mii_parse_sr},
  841. /* Read the status */
  842. {MIIM_88E1011_PHY_STATUS, miim_read,
  843. &mii_parse_88E1011_psr},
  844. {miim_end,}
  845. },
  846. (struct phy_cmd[]){ /* shutdown */
  847. {miim_end,}
  848. },
  849. };
  850. /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
  851. struct phy_info phy_info_BCM5461S = {
  852. 0x02060c1, /* 5461 ID */
  853. "Broadcom BCM5461S",
  854. 0, /* not clear to me what minor revisions we can shift away */
  855. (struct phy_cmd[]) { /* config */
  856. /* Reset and configure the PHY */
  857. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  858. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  859. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  860. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  861. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  862. {miim_end,}
  863. },
  864. (struct phy_cmd[]) { /* startup */
  865. /* Status is read once to clear old link state */
  866. {MIIM_STATUS, miim_read, NULL},
  867. /* Auto-negotiate */
  868. {MIIM_STATUS, miim_read, &mii_parse_sr},
  869. /* Read the status */
  870. {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
  871. {miim_end,}
  872. },
  873. (struct phy_cmd[]) { /* shutdown */
  874. {miim_end,}
  875. },
  876. };
  877. struct phy_info phy_info_BCM5464S = {
  878. 0x02060b1, /* 5464 ID */
  879. "Broadcom BCM5464S",
  880. 0, /* not clear to me what minor revisions we can shift away */
  881. (struct phy_cmd[]) { /* config */
  882. /* Reset and configure the PHY */
  883. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  884. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  885. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  886. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  887. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  888. {miim_end,}
  889. },
  890. (struct phy_cmd[]) { /* startup */
  891. /* Status is read once to clear old link state */
  892. {MIIM_STATUS, miim_read, NULL},
  893. /* Auto-negotiate */
  894. {MIIM_STATUS, miim_read, &mii_parse_sr},
  895. /* Read the status */
  896. {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
  897. {miim_end,}
  898. },
  899. (struct phy_cmd[]) { /* shutdown */
  900. {miim_end,}
  901. },
  902. };
  903. struct phy_info phy_info_BCM5482S = {
  904. 0x0143bcb,
  905. "Broadcom BCM5482S",
  906. 4,
  907. (struct phy_cmd[]) { /* config */
  908. /* Reset and configure the PHY */
  909. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  910. /* Setup read from auxilary control shadow register 7 */
  911. {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
  912. /* Read Misc Control register and or in Ethernet@Wirespeed */
  913. {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
  914. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  915. {miim_end,}
  916. },
  917. (struct phy_cmd[]) { /* startup */
  918. /* Status is read once to clear old link state */
  919. {MIIM_STATUS, miim_read, NULL},
  920. /* Auto-negotiate */
  921. {MIIM_STATUS, miim_read, &mii_parse_sr},
  922. /* Read the status */
  923. {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
  924. {miim_end,}
  925. },
  926. (struct phy_cmd[]) { /* shutdown */
  927. {miim_end,}
  928. },
  929. };
  930. struct phy_info phy_info_M88E1011S = {
  931. 0x01410c6,
  932. "Marvell 88E1011S",
  933. 4,
  934. (struct phy_cmd[]){ /* config */
  935. /* Reset and configure the PHY */
  936. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  937. {0x1d, 0x1f, NULL},
  938. {0x1e, 0x200c, NULL},
  939. {0x1d, 0x5, NULL},
  940. {0x1e, 0x0, NULL},
  941. {0x1e, 0x100, NULL},
  942. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  943. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  944. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  945. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  946. {miim_end,}
  947. },
  948. (struct phy_cmd[]){ /* startup */
  949. /* Status is read once to clear old link state */
  950. {MIIM_STATUS, miim_read, NULL},
  951. /* Auto-negotiate */
  952. {MIIM_STATUS, miim_read, &mii_parse_sr},
  953. /* Read the status */
  954. {MIIM_88E1011_PHY_STATUS, miim_read,
  955. &mii_parse_88E1011_psr},
  956. {miim_end,}
  957. },
  958. (struct phy_cmd[]){ /* shutdown */
  959. {miim_end,}
  960. },
  961. };
  962. struct phy_info phy_info_M88E1111S = {
  963. 0x01410cc,
  964. "Marvell 88E1111S",
  965. 4,
  966. (struct phy_cmd[]){ /* config */
  967. /* Reset and configure the PHY */
  968. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  969. {0x1b, 0x848f, &mii_m88e1111s_setmode},
  970. {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
  971. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  972. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  973. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  974. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  975. {miim_end,}
  976. },
  977. (struct phy_cmd[]){ /* startup */
  978. /* Status is read once to clear old link state */
  979. {MIIM_STATUS, miim_read, NULL},
  980. /* Auto-negotiate */
  981. {MIIM_STATUS, miim_read, &mii_parse_sr},
  982. /* Read the status */
  983. {MIIM_88E1011_PHY_STATUS, miim_read,
  984. &mii_parse_88E1011_psr},
  985. {miim_end,}
  986. },
  987. (struct phy_cmd[]){ /* shutdown */
  988. {miim_end,}
  989. },
  990. };
  991. struct phy_info phy_info_M88E1118 = {
  992. 0x01410e1,
  993. "Marvell 88E1118",
  994. 4,
  995. (struct phy_cmd[]){ /* config */
  996. /* Reset and configure the PHY */
  997. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  998. {0x16, 0x0002, NULL}, /* Change Page Number */
  999. {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
  1000. {0x16, 0x0003, NULL}, /* Change Page Number */
  1001. {0x10, 0x021e, NULL}, /* Adjust LED control */
  1002. {0x16, 0x0000, NULL}, /* Change Page Number */
  1003. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1004. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1005. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1006. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1007. {miim_end,}
  1008. },
  1009. (struct phy_cmd[]){ /* startup */
  1010. {0x16, 0x0000, NULL}, /* Change Page Number */
  1011. /* Status is read once to clear old link state */
  1012. {MIIM_STATUS, miim_read, NULL},
  1013. /* Auto-negotiate */
  1014. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1015. /* Read the status */
  1016. {MIIM_88E1011_PHY_STATUS, miim_read,
  1017. &mii_parse_88E1011_psr},
  1018. {miim_end,}
  1019. },
  1020. (struct phy_cmd[]){ /* shutdown */
  1021. {miim_end,}
  1022. },
  1023. };
  1024. /*
  1025. * Since to access LED register we need do switch the page, we
  1026. * do LED configuring in the miim_read-like function as follows
  1027. */
  1028. uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
  1029. {
  1030. uint pg;
  1031. /* Switch the page to access the led register */
  1032. pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
  1033. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
  1034. /* Configure leds */
  1035. write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
  1036. MIIM_88E1121_PHY_LED_DEF);
  1037. /* Restore the page pointer */
  1038. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
  1039. return 0;
  1040. }
  1041. struct phy_info phy_info_M88E1121R = {
  1042. 0x01410cb,
  1043. "Marvell 88E1121R",
  1044. 4,
  1045. (struct phy_cmd[]){ /* config */
  1046. /* Reset and configure the PHY */
  1047. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1048. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1049. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1050. /* Configure leds */
  1051. {MIIM_88E1121_PHY_LED_CTRL, miim_read,
  1052. &mii_88E1121_set_led},
  1053. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1054. /* Disable IRQs and de-assert interrupt */
  1055. {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
  1056. {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
  1057. {miim_end,}
  1058. },
  1059. (struct phy_cmd[]){ /* startup */
  1060. /* Status is read once to clear old link state */
  1061. {MIIM_STATUS, miim_read, NULL},
  1062. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1063. {MIIM_STATUS, miim_read, &mii_parse_link},
  1064. {miim_end,}
  1065. },
  1066. (struct phy_cmd[]){ /* shutdown */
  1067. {miim_end,}
  1068. },
  1069. };
  1070. static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
  1071. {
  1072. uint mii_data = read_phy_reg(priv, mii_reg);
  1073. /* Setting MIIM_88E1145_PHY_EXT_CR */
  1074. if (priv->flags & TSEC_REDUCED)
  1075. return mii_data |
  1076. MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
  1077. else
  1078. return mii_data;
  1079. }
  1080. static struct phy_info phy_info_M88E1145 = {
  1081. 0x01410cd,
  1082. "Marvell 88E1145",
  1083. 4,
  1084. (struct phy_cmd[]){ /* config */
  1085. /* Reset the PHY */
  1086. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1087. /* Errata E0, E1 */
  1088. {29, 0x001b, NULL},
  1089. {30, 0x418f, NULL},
  1090. {29, 0x0016, NULL},
  1091. {30, 0xa2da, NULL},
  1092. /* Configure the PHY */
  1093. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1094. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1095. {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
  1096. NULL},
  1097. {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
  1098. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1099. {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
  1100. {miim_end,}
  1101. },
  1102. (struct phy_cmd[]){ /* startup */
  1103. /* Status is read once to clear old link state */
  1104. {MIIM_STATUS, miim_read, NULL},
  1105. /* Auto-negotiate */
  1106. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1107. {MIIM_88E1111_PHY_LED_CONTROL,
  1108. MIIM_88E1111_PHY_LED_DIRECT, NULL},
  1109. /* Read the Status */
  1110. {MIIM_88E1011_PHY_STATUS, miim_read,
  1111. &mii_parse_88E1011_psr},
  1112. {miim_end,}
  1113. },
  1114. (struct phy_cmd[]){ /* shutdown */
  1115. {miim_end,}
  1116. },
  1117. };
  1118. struct phy_info phy_info_cis8204 = {
  1119. 0x3f11,
  1120. "Cicada Cis8204",
  1121. 6,
  1122. (struct phy_cmd[]){ /* config */
  1123. /* Override PHY config settings */
  1124. {MIIM_CIS8201_AUX_CONSTAT,
  1125. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1126. /* Configure some basic stuff */
  1127. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1128. {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
  1129. &mii_cis8204_fixled},
  1130. {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
  1131. &mii_cis8204_setmode},
  1132. {miim_end,}
  1133. },
  1134. (struct phy_cmd[]){ /* startup */
  1135. /* Read the Status (2x to make sure link is right) */
  1136. {MIIM_STATUS, miim_read, NULL},
  1137. /* Auto-negotiate */
  1138. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1139. /* Read the status */
  1140. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  1141. &mii_parse_cis8201},
  1142. {miim_end,}
  1143. },
  1144. (struct phy_cmd[]){ /* shutdown */
  1145. {miim_end,}
  1146. },
  1147. };
  1148. /* Cicada 8201 */
  1149. struct phy_info phy_info_cis8201 = {
  1150. 0xfc41,
  1151. "CIS8201",
  1152. 4,
  1153. (struct phy_cmd[]){ /* config */
  1154. /* Override PHY config settings */
  1155. {MIIM_CIS8201_AUX_CONSTAT,
  1156. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1157. /* Set up the interface mode */
  1158. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
  1159. NULL},
  1160. /* Configure some basic stuff */
  1161. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1162. {miim_end,}
  1163. },
  1164. (struct phy_cmd[]){ /* startup */
  1165. /* Read the Status (2x to make sure link is right) */
  1166. {MIIM_STATUS, miim_read, NULL},
  1167. /* Auto-negotiate */
  1168. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1169. /* Read the status */
  1170. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  1171. &mii_parse_cis8201},
  1172. {miim_end,}
  1173. },
  1174. (struct phy_cmd[]){ /* shutdown */
  1175. {miim_end,}
  1176. },
  1177. };
  1178. struct phy_info phy_info_VSC8211 = {
  1179. 0xfc4b,
  1180. "Vitesse VSC8211",
  1181. 4,
  1182. (struct phy_cmd[]) { /* config */
  1183. /* Override PHY config settings */
  1184. {MIIM_CIS8201_AUX_CONSTAT,
  1185. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1186. /* Set up the interface mode */
  1187. {MIIM_CIS8201_EXT_CON1,
  1188. MIIM_CIS8201_EXTCON1_INIT, NULL},
  1189. /* Configure some basic stuff */
  1190. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1191. {miim_end,}
  1192. },
  1193. (struct phy_cmd[]) { /* startup */
  1194. /* Read the Status (2x to make sure link is right) */
  1195. {MIIM_STATUS, miim_read, NULL},
  1196. /* Auto-negotiate */
  1197. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1198. /* Read the status */
  1199. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  1200. &mii_parse_cis8201},
  1201. {miim_end,}
  1202. },
  1203. (struct phy_cmd[]) { /* shutdown */
  1204. {miim_end,}
  1205. },
  1206. };
  1207. struct phy_info phy_info_VSC8244 = {
  1208. 0x3f1b,
  1209. "Vitesse VSC8244",
  1210. 6,
  1211. (struct phy_cmd[]){ /* config */
  1212. /* Override PHY config settings */
  1213. /* Configure some basic stuff */
  1214. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1215. {miim_end,}
  1216. },
  1217. (struct phy_cmd[]){ /* startup */
  1218. /* Read the Status (2x to make sure link is right) */
  1219. {MIIM_STATUS, miim_read, NULL},
  1220. /* Auto-negotiate */
  1221. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1222. /* Read the status */
  1223. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1224. &mii_parse_vsc8244},
  1225. {miim_end,}
  1226. },
  1227. (struct phy_cmd[]){ /* shutdown */
  1228. {miim_end,}
  1229. },
  1230. };
  1231. struct phy_info phy_info_VSC8641 = {
  1232. 0x7043,
  1233. "Vitesse VSC8641",
  1234. 4,
  1235. (struct phy_cmd[]){ /* config */
  1236. /* Configure some basic stuff */
  1237. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1238. {miim_end,}
  1239. },
  1240. (struct phy_cmd[]){ /* startup */
  1241. /* Read the Status (2x to make sure link is right) */
  1242. {MIIM_STATUS, miim_read, NULL},
  1243. /* Auto-negotiate */
  1244. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1245. /* Read the status */
  1246. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1247. &mii_parse_vsc8244},
  1248. {miim_end,}
  1249. },
  1250. (struct phy_cmd[]){ /* shutdown */
  1251. {miim_end,}
  1252. },
  1253. };
  1254. struct phy_info phy_info_VSC8221 = {
  1255. 0xfc55,
  1256. "Vitesse VSC8221",
  1257. 4,
  1258. (struct phy_cmd[]){ /* config */
  1259. /* Configure some basic stuff */
  1260. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1261. {miim_end,}
  1262. },
  1263. (struct phy_cmd[]){ /* startup */
  1264. /* Read the Status (2x to make sure link is right) */
  1265. {MIIM_STATUS, miim_read, NULL},
  1266. /* Auto-negotiate */
  1267. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1268. /* Read the status */
  1269. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1270. &mii_parse_vsc8244},
  1271. {miim_end,}
  1272. },
  1273. (struct phy_cmd[]){ /* shutdown */
  1274. {miim_end,}
  1275. },
  1276. };
  1277. struct phy_info phy_info_VSC8601 = {
  1278. 0x00007042,
  1279. "Vitesse VSC8601",
  1280. 4,
  1281. (struct phy_cmd[]){ /* config */
  1282. /* Override PHY config settings */
  1283. /* Configure some basic stuff */
  1284. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1285. #ifdef CONFIG_SYS_VSC8601_SKEWFIX
  1286. {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
  1287. #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
  1288. {MIIM_EXT_PAGE_ACCESS,1,NULL},
  1289. #define VSC8101_SKEW (CONFIG_SYS_VSC8601_SKEW_TX<<14)|(CONFIG_SYS_VSC8601_SKEW_RX<<12)
  1290. {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
  1291. {MIIM_EXT_PAGE_ACCESS,0,NULL},
  1292. #endif
  1293. #endif
  1294. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1295. {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
  1296. {miim_end,}
  1297. },
  1298. (struct phy_cmd[]){ /* startup */
  1299. /* Read the Status (2x to make sure link is right) */
  1300. {MIIM_STATUS, miim_read, NULL},
  1301. /* Auto-negotiate */
  1302. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1303. /* Read the status */
  1304. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1305. &mii_parse_vsc8244},
  1306. {miim_end,}
  1307. },
  1308. (struct phy_cmd[]){ /* shutdown */
  1309. {miim_end,}
  1310. },
  1311. };
  1312. struct phy_info phy_info_dm9161 = {
  1313. 0x0181b88,
  1314. "Davicom DM9161E",
  1315. 4,
  1316. (struct phy_cmd[]){ /* config */
  1317. {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
  1318. /* Do not bypass the scrambler/descrambler */
  1319. {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
  1320. /* Clear 10BTCSR to default */
  1321. {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
  1322. NULL},
  1323. /* Configure some basic stuff */
  1324. {MIIM_CONTROL, MIIM_CR_INIT, NULL},
  1325. /* Restart Auto Negotiation */
  1326. {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
  1327. {miim_end,}
  1328. },
  1329. (struct phy_cmd[]){ /* startup */
  1330. /* Status is read once to clear old link state */
  1331. {MIIM_STATUS, miim_read, NULL},
  1332. /* Auto-negotiate */
  1333. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1334. /* Read the status */
  1335. {MIIM_DM9161_SCSR, miim_read,
  1336. &mii_parse_dm9161_scsr},
  1337. {miim_end,}
  1338. },
  1339. (struct phy_cmd[]){ /* shutdown */
  1340. {miim_end,}
  1341. },
  1342. };
  1343. /* a generic flavor. */
  1344. struct phy_info phy_info_generic = {
  1345. 0,
  1346. "Unknown/Generic PHY",
  1347. 32,
  1348. (struct phy_cmd[]) { /* config */
  1349. {PHY_BMCR, PHY_BMCR_RESET, NULL},
  1350. {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
  1351. {miim_end,}
  1352. },
  1353. (struct phy_cmd[]) { /* startup */
  1354. {PHY_BMSR, miim_read, NULL},
  1355. {PHY_BMSR, miim_read, &mii_parse_sr},
  1356. {PHY_BMSR, miim_read, &mii_parse_link},
  1357. {miim_end,}
  1358. },
  1359. (struct phy_cmd[]) { /* shutdown */
  1360. {miim_end,}
  1361. }
  1362. };
  1363. uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
  1364. {
  1365. unsigned int speed;
  1366. if (priv->link) {
  1367. speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
  1368. switch (speed) {
  1369. case MIIM_LXT971_SR2_10HDX:
  1370. priv->speed = 10;
  1371. priv->duplexity = 0;
  1372. break;
  1373. case MIIM_LXT971_SR2_10FDX:
  1374. priv->speed = 10;
  1375. priv->duplexity = 1;
  1376. break;
  1377. case MIIM_LXT971_SR2_100HDX:
  1378. priv->speed = 100;
  1379. priv->duplexity = 0;
  1380. break;
  1381. default:
  1382. priv->speed = 100;
  1383. priv->duplexity = 1;
  1384. }
  1385. } else {
  1386. priv->speed = 0;
  1387. priv->duplexity = 0;
  1388. }
  1389. return 0;
  1390. }
  1391. static struct phy_info phy_info_lxt971 = {
  1392. 0x0001378e,
  1393. "LXT971",
  1394. 4,
  1395. (struct phy_cmd[]){ /* config */
  1396. {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
  1397. {miim_end,}
  1398. },
  1399. (struct phy_cmd[]){ /* startup - enable interrupts */
  1400. /* { 0x12, 0x00f2, NULL }, */
  1401. {MIIM_STATUS, miim_read, NULL},
  1402. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1403. {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
  1404. {miim_end,}
  1405. },
  1406. (struct phy_cmd[]){ /* shutdown - disable interrupts */
  1407. {miim_end,}
  1408. },
  1409. };
  1410. /* Parse the DP83865's link and auto-neg status register for speed and duplex
  1411. * information
  1412. */
  1413. uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
  1414. {
  1415. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  1416. case MIIM_DP83865_SPD_1000:
  1417. priv->speed = 1000;
  1418. break;
  1419. case MIIM_DP83865_SPD_100:
  1420. priv->speed = 100;
  1421. break;
  1422. default:
  1423. priv->speed = 10;
  1424. break;
  1425. }
  1426. if (mii_reg & MIIM_DP83865_DPX_FULL)
  1427. priv->duplexity = 1;
  1428. else
  1429. priv->duplexity = 0;
  1430. return 0;
  1431. }
  1432. struct phy_info phy_info_dp83865 = {
  1433. 0x20005c7,
  1434. "NatSemi DP83865",
  1435. 4,
  1436. (struct phy_cmd[]){ /* config */
  1437. {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
  1438. {miim_end,}
  1439. },
  1440. (struct phy_cmd[]){ /* startup */
  1441. /* Status is read once to clear old link state */
  1442. {MIIM_STATUS, miim_read, NULL},
  1443. /* Auto-negotiate */
  1444. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1445. /* Read the link and auto-neg status */
  1446. {MIIM_DP83865_LANR, miim_read,
  1447. &mii_parse_dp83865_lanr},
  1448. {miim_end,}
  1449. },
  1450. (struct phy_cmd[]){ /* shutdown */
  1451. {miim_end,}
  1452. },
  1453. };
  1454. struct phy_info phy_info_rtl8211b = {
  1455. 0x001cc91,
  1456. "RealTek RTL8211B",
  1457. 4,
  1458. (struct phy_cmd[]){ /* config */
  1459. /* Reset and configure the PHY */
  1460. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1461. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1462. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1463. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1464. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1465. {miim_end,}
  1466. },
  1467. (struct phy_cmd[]){ /* startup */
  1468. /* Status is read once to clear old link state */
  1469. {MIIM_STATUS, miim_read, NULL},
  1470. /* Auto-negotiate */
  1471. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1472. /* Read the status */
  1473. {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
  1474. {miim_end,}
  1475. },
  1476. (struct phy_cmd[]){ /* shutdown */
  1477. {miim_end,}
  1478. },
  1479. };
  1480. struct phy_info *phy_info[] = {
  1481. &phy_info_cis8204,
  1482. &phy_info_cis8201,
  1483. &phy_info_BCM5461S,
  1484. &phy_info_BCM5464S,
  1485. &phy_info_BCM5482S,
  1486. &phy_info_M88E1011S,
  1487. &phy_info_M88E1111S,
  1488. &phy_info_M88E1118,
  1489. &phy_info_M88E1121R,
  1490. &phy_info_M88E1145,
  1491. &phy_info_M88E1149S,
  1492. &phy_info_dm9161,
  1493. &phy_info_lxt971,
  1494. &phy_info_VSC8211,
  1495. &phy_info_VSC8244,
  1496. &phy_info_VSC8601,
  1497. &phy_info_VSC8641,
  1498. &phy_info_VSC8221,
  1499. &phy_info_dp83865,
  1500. &phy_info_rtl8211b,
  1501. &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
  1502. NULL
  1503. };
  1504. /* Grab the identifier of the device's PHY, and search through
  1505. * all of the known PHYs to see if one matches. If so, return
  1506. * it, if not, return NULL
  1507. */
  1508. struct phy_info *get_phy_info(struct eth_device *dev)
  1509. {
  1510. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  1511. uint phy_reg, phy_ID;
  1512. int i;
  1513. struct phy_info *theInfo = NULL;
  1514. /* Grab the bits from PHYIR1, and put them in the upper half */
  1515. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  1516. phy_ID = (phy_reg & 0xffff) << 16;
  1517. /* Grab the bits from PHYIR2, and put them in the lower half */
  1518. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  1519. phy_ID |= (phy_reg & 0xffff);
  1520. /* loop through all the known PHY types, and find one that */
  1521. /* matches the ID we read from the PHY. */
  1522. for (i = 0; phy_info[i]; i++) {
  1523. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
  1524. theInfo = phy_info[i];
  1525. break;
  1526. }
  1527. }
  1528. if (theInfo == &phy_info_generic) {
  1529. printf("%s: No support for PHY id %x; assuming generic\n", dev->name, phy_ID);
  1530. } else {
  1531. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  1532. }
  1533. return theInfo;
  1534. }
  1535. /* Execute the given series of commands on the given device's
  1536. * PHY, running functions as necessary
  1537. */
  1538. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1539. {
  1540. int i;
  1541. uint result;
  1542. volatile tsec_t *phyregs = priv->phyregs;
  1543. phyregs->miimcfg = MIIMCFG_RESET;
  1544. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1545. while (phyregs->miimind & MIIMIND_BUSY) ;
  1546. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1547. if (cmd->mii_data == miim_read) {
  1548. result = read_phy_reg(priv, cmd->mii_reg);
  1549. if (cmd->funct != NULL)
  1550. (*(cmd->funct)) (result, priv);
  1551. } else {
  1552. if (cmd->funct != NULL)
  1553. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1554. else
  1555. result = cmd->mii_data;
  1556. write_phy_reg(priv, cmd->mii_reg, result);
  1557. }
  1558. cmd++;
  1559. }
  1560. }
  1561. /* Relocate the function pointers in the phy cmd lists */
  1562. static void relocate_cmds(void)
  1563. {
  1564. struct phy_cmd **cmdlistptr;
  1565. struct phy_cmd *cmd;
  1566. int i, j, k;
  1567. for (i = 0; phy_info[i]; i++) {
  1568. /* First thing's first: relocate the pointers to the
  1569. * PHY command structures (the structs were done) */
  1570. phy_info[i] = (struct phy_info *)((uint) phy_info[i]
  1571. + gd->reloc_off);
  1572. phy_info[i]->name += gd->reloc_off;
  1573. phy_info[i]->config =
  1574. (struct phy_cmd *)((uint) phy_info[i]->config
  1575. + gd->reloc_off);
  1576. phy_info[i]->startup =
  1577. (struct phy_cmd *)((uint) phy_info[i]->startup
  1578. + gd->reloc_off);
  1579. phy_info[i]->shutdown =
  1580. (struct phy_cmd *)((uint) phy_info[i]->shutdown
  1581. + gd->reloc_off);
  1582. cmdlistptr = &phy_info[i]->config;
  1583. j = 0;
  1584. for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
  1585. k = 0;
  1586. for (cmd = *cmdlistptr;
  1587. cmd->mii_reg != miim_end;
  1588. cmd++) {
  1589. /* Only relocate non-NULL pointers */
  1590. if (cmd->funct)
  1591. cmd->funct += gd->reloc_off;
  1592. k++;
  1593. }
  1594. j++;
  1595. }
  1596. }
  1597. relocated = 1;
  1598. }
  1599. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
  1600. && !defined(BITBANGMII)
  1601. /*
  1602. * Read a MII PHY register.
  1603. *
  1604. * Returns:
  1605. * 0 on success
  1606. */
  1607. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1608. unsigned char reg, unsigned short *value)
  1609. {
  1610. unsigned short ret;
  1611. struct tsec_private *priv = privlist[0];
  1612. if (NULL == priv) {
  1613. printf("Can't read PHY at address %d\n", addr);
  1614. return -1;
  1615. }
  1616. ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
  1617. *value = ret;
  1618. return 0;
  1619. }
  1620. /*
  1621. * Write a MII PHY register.
  1622. *
  1623. * Returns:
  1624. * 0 on success
  1625. */
  1626. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1627. unsigned char reg, unsigned short value)
  1628. {
  1629. struct tsec_private *priv = privlist[0];
  1630. if (NULL == priv) {
  1631. printf("Can't write PHY at address %d\n", addr);
  1632. return -1;
  1633. }
  1634. tsec_local_mdio_write(priv->phyregs, addr, reg, value);
  1635. return 0;
  1636. }
  1637. #endif
  1638. #ifdef CONFIG_MCAST_TFTP
  1639. /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
  1640. /* Set the appropriate hash bit for the given addr */
  1641. /* The algorithm works like so:
  1642. * 1) Take the Destination Address (ie the multicast address), and
  1643. * do a CRC on it (little endian), and reverse the bits of the
  1644. * result.
  1645. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1646. * table. The table is controlled through 8 32-bit registers:
  1647. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1648. * gaddr7. This means that the 3 most significant bits in the
  1649. * hash index which gaddr register to use, and the 5 other bits
  1650. * indicate which bit (assuming an IBM numbering scheme, which
  1651. * for PowerPC (tm) is usually the case) in the tregister holds
  1652. * the entry. */
  1653. static int
  1654. tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
  1655. {
  1656. struct tsec_private *priv = privlist[1];
  1657. volatile tsec_t *regs = priv->regs;
  1658. volatile u32 *reg_array, value;
  1659. u8 result, whichbit, whichreg;
  1660. result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
  1661. whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
  1662. whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
  1663. value = (1 << (31-whichbit));
  1664. reg_array = &(regs->hash.gaddr0);
  1665. if (set) {
  1666. reg_array[whichreg] |= value;
  1667. } else {
  1668. reg_array[whichreg] &= ~value;
  1669. }
  1670. return 0;
  1671. }
  1672. #endif /* Multicast TFTP ? */