tsec.c 47 KB

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