tsec.c 50 KB

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