tsec.c 49 KB

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