tsec.c 49 KB

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