tsec.c 48 KB

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