tsec.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964
  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. } else {
  513. /* Wait for auto-negotiation to complete or fail */
  514. mii_parse_sr(mii_reg, priv);
  515. /* Parse BCM54xx copper aux status register */
  516. mii_reg = read_phy_reg(priv, MIIM_BCM54xx_AUXSTATUS);
  517. mii_parse_BCM54xx_sr(mii_reg, priv);
  518. }
  519. return 0;
  520. }
  521. /* Parse the 88E1011's status register for speed and duplex
  522. * information
  523. */
  524. static uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
  525. {
  526. uint speed;
  527. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  528. if ((mii_reg & MIIM_88E1011_PHYSTAT_LINK) &&
  529. !(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
  530. int i = 0;
  531. puts("Waiting for PHY realtime link");
  532. while (!(mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE)) {
  533. /* Timeout reached ? */
  534. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  535. puts(" TIMEOUT !\n");
  536. priv->link = 0;
  537. break;
  538. }
  539. if ((i++ % 1000) == 0) {
  540. putc('.');
  541. }
  542. udelay(1000); /* 1 ms */
  543. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  544. }
  545. puts(" done\n");
  546. udelay(500000); /* another 500 ms (results in faster booting) */
  547. } else {
  548. if (mii_reg & MIIM_88E1011_PHYSTAT_LINK)
  549. priv->link = 1;
  550. else
  551. priv->link = 0;
  552. }
  553. if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
  554. priv->duplexity = 1;
  555. else
  556. priv->duplexity = 0;
  557. speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
  558. switch (speed) {
  559. case MIIM_88E1011_PHYSTAT_GBIT:
  560. priv->speed = 1000;
  561. break;
  562. case MIIM_88E1011_PHYSTAT_100:
  563. priv->speed = 100;
  564. break;
  565. default:
  566. priv->speed = 10;
  567. }
  568. return 0;
  569. }
  570. /* Parse the RTL8211B's status register for speed and duplex
  571. * information
  572. */
  573. static uint mii_parse_RTL8211B_sr(uint mii_reg, struct tsec_private * priv)
  574. {
  575. uint speed;
  576. mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
  577. if (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
  578. int i = 0;
  579. /* in case of timeout ->link is cleared */
  580. priv->link = 1;
  581. puts("Waiting for PHY realtime link");
  582. while (!(mii_reg & MIIM_RTL8211B_PHYSTAT_SPDDONE)) {
  583. /* Timeout reached ? */
  584. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  585. puts(" TIMEOUT !\n");
  586. priv->link = 0;
  587. break;
  588. }
  589. if ((i++ % 1000) == 0) {
  590. putc('.');
  591. }
  592. udelay(1000); /* 1 ms */
  593. mii_reg = read_phy_reg(priv, MIIM_RTL8211B_PHY_STATUS);
  594. }
  595. puts(" done\n");
  596. udelay(500000); /* another 500 ms (results in faster booting) */
  597. } else {
  598. if (mii_reg & MIIM_RTL8211B_PHYSTAT_LINK)
  599. priv->link = 1;
  600. else
  601. priv->link = 0;
  602. }
  603. if (mii_reg & MIIM_RTL8211B_PHYSTAT_DUPLEX)
  604. priv->duplexity = 1;
  605. else
  606. priv->duplexity = 0;
  607. speed = (mii_reg & MIIM_RTL8211B_PHYSTAT_SPEED);
  608. switch (speed) {
  609. case MIIM_RTL8211B_PHYSTAT_GBIT:
  610. priv->speed = 1000;
  611. break;
  612. case MIIM_RTL8211B_PHYSTAT_100:
  613. priv->speed = 100;
  614. break;
  615. default:
  616. priv->speed = 10;
  617. }
  618. return 0;
  619. }
  620. /* Parse the cis8201's status register for speed and duplex
  621. * information
  622. */
  623. static uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
  624. {
  625. uint speed;
  626. if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
  627. priv->duplexity = 1;
  628. else
  629. priv->duplexity = 0;
  630. speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
  631. switch (speed) {
  632. case MIIM_CIS8201_AUXCONSTAT_GBIT:
  633. priv->speed = 1000;
  634. break;
  635. case MIIM_CIS8201_AUXCONSTAT_100:
  636. priv->speed = 100;
  637. break;
  638. default:
  639. priv->speed = 10;
  640. break;
  641. }
  642. return 0;
  643. }
  644. /* Parse the vsc8244's status register for speed and duplex
  645. * information
  646. */
  647. static uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
  648. {
  649. uint speed;
  650. if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
  651. priv->duplexity = 1;
  652. else
  653. priv->duplexity = 0;
  654. speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
  655. switch (speed) {
  656. case MIIM_VSC8244_AUXCONSTAT_GBIT:
  657. priv->speed = 1000;
  658. break;
  659. case MIIM_VSC8244_AUXCONSTAT_100:
  660. priv->speed = 100;
  661. break;
  662. default:
  663. priv->speed = 10;
  664. break;
  665. }
  666. return 0;
  667. }
  668. /* Parse the DM9161's status register for speed and duplex
  669. * information
  670. */
  671. static uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
  672. {
  673. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
  674. priv->speed = 100;
  675. else
  676. priv->speed = 10;
  677. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
  678. priv->duplexity = 1;
  679. else
  680. priv->duplexity = 0;
  681. return 0;
  682. }
  683. /*
  684. * Hack to write all 4 PHYs with the LED values
  685. */
  686. static uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
  687. {
  688. uint phyid;
  689. volatile tsec_mdio_t *regbase = priv->phyregs;
  690. int timeout = 1000000;
  691. for (phyid = 0; phyid < 4; phyid++) {
  692. regbase->miimadd = (phyid << 8) | mii_reg;
  693. regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
  694. asm("sync");
  695. timeout = 1000000;
  696. while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
  697. }
  698. return MIIM_CIS8204_SLEDCON_INIT;
  699. }
  700. static uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
  701. {
  702. if (priv->flags & TSEC_REDUCED)
  703. return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
  704. else
  705. return MIIM_CIS8204_EPHYCON_INIT;
  706. }
  707. static uint mii_m88e1111s_setmode(uint mii_reg, struct tsec_private *priv)
  708. {
  709. uint mii_data = read_phy_reg(priv, mii_reg);
  710. if (priv->flags & TSEC_REDUCED)
  711. mii_data = (mii_data & 0xfff0) | 0x000b;
  712. return mii_data;
  713. }
  714. /* Initialized required registers to appropriate values, zeroing
  715. * those we don't care about (unless zero is bad, in which case,
  716. * choose a more appropriate value)
  717. */
  718. static void init_registers(volatile tsec_t * regs)
  719. {
  720. /* Clear IEVENT */
  721. regs->ievent = IEVENT_INIT_CLEAR;
  722. regs->imask = IMASK_INIT_CLEAR;
  723. regs->hash.iaddr0 = 0;
  724. regs->hash.iaddr1 = 0;
  725. regs->hash.iaddr2 = 0;
  726. regs->hash.iaddr3 = 0;
  727. regs->hash.iaddr4 = 0;
  728. regs->hash.iaddr5 = 0;
  729. regs->hash.iaddr6 = 0;
  730. regs->hash.iaddr7 = 0;
  731. regs->hash.gaddr0 = 0;
  732. regs->hash.gaddr1 = 0;
  733. regs->hash.gaddr2 = 0;
  734. regs->hash.gaddr3 = 0;
  735. regs->hash.gaddr4 = 0;
  736. regs->hash.gaddr5 = 0;
  737. regs->hash.gaddr6 = 0;
  738. regs->hash.gaddr7 = 0;
  739. regs->rctrl = 0x00000000;
  740. /* Init RMON mib registers */
  741. memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
  742. regs->rmon.cam1 = 0xffffffff;
  743. regs->rmon.cam2 = 0xffffffff;
  744. regs->mrblr = MRBLR_INIT_SETTINGS;
  745. regs->minflr = MINFLR_INIT_SETTINGS;
  746. regs->attr = ATTR_INIT_SETTINGS;
  747. regs->attreli = ATTRELI_INIT_SETTINGS;
  748. }
  749. /* Configure maccfg2 based on negotiated speed and duplex
  750. * reported by PHY handling code
  751. */
  752. static void adjust_link(struct eth_device *dev)
  753. {
  754. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  755. volatile tsec_t *regs = priv->regs;
  756. if (priv->link) {
  757. if (priv->duplexity != 0)
  758. regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
  759. else
  760. regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
  761. switch (priv->speed) {
  762. case 1000:
  763. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  764. | MACCFG2_GMII);
  765. break;
  766. case 100:
  767. case 10:
  768. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  769. | MACCFG2_MII);
  770. /* Set R100 bit in all modes although
  771. * it is only used in RGMII mode
  772. */
  773. if (priv->speed == 100)
  774. regs->ecntrl |= ECNTRL_R100;
  775. else
  776. regs->ecntrl &= ~(ECNTRL_R100);
  777. break;
  778. default:
  779. printf("%s: Speed was bad\n", dev->name);
  780. break;
  781. }
  782. printf("Speed: %d, %s duplex\n", priv->speed,
  783. (priv->duplexity) ? "full" : "half");
  784. } else {
  785. printf("%s: No link.\n", dev->name);
  786. }
  787. }
  788. /* Set up the buffers and their descriptors, and bring up the
  789. * interface
  790. */
  791. static void startup_tsec(struct eth_device *dev)
  792. {
  793. int i;
  794. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  795. volatile tsec_t *regs = priv->regs;
  796. /* Point to the buffer descriptors */
  797. regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
  798. regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
  799. /* Initialize the Rx Buffer descriptors */
  800. for (i = 0; i < PKTBUFSRX; i++) {
  801. rtx.rxbd[i].status = RXBD_EMPTY;
  802. rtx.rxbd[i].length = 0;
  803. rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
  804. }
  805. rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
  806. /* Initialize the TX Buffer Descriptors */
  807. for (i = 0; i < TX_BUF_CNT; i++) {
  808. rtx.txbd[i].status = 0;
  809. rtx.txbd[i].length = 0;
  810. rtx.txbd[i].bufPtr = 0;
  811. }
  812. rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
  813. /* Start up the PHY */
  814. if(priv->phyinfo)
  815. phy_run_commands(priv, priv->phyinfo->startup);
  816. adjust_link(dev);
  817. /* Enable Transmit and Receive */
  818. regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  819. /* Tell the DMA it is clear to go */
  820. regs->dmactrl |= DMACTRL_INIT_SETTINGS;
  821. regs->tstat = TSTAT_CLEAR_THALT;
  822. regs->rstat = RSTAT_CLEAR_RHALT;
  823. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  824. }
  825. /* This returns the status bits of the device. The return value
  826. * is never checked, and this is what the 8260 driver did, so we
  827. * do the same. Presumably, this would be zero if there were no
  828. * errors
  829. */
  830. static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
  831. {
  832. int i;
  833. int result = 0;
  834. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  835. volatile tsec_t *regs = priv->regs;
  836. /* Find an empty buffer descriptor */
  837. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  838. if (i >= TOUT_LOOP) {
  839. debug("%s: tsec: tx buffers full\n", dev->name);
  840. return result;
  841. }
  842. }
  843. rtx.txbd[txIdx].bufPtr = (uint) packet;
  844. rtx.txbd[txIdx].length = length;
  845. rtx.txbd[txIdx].status |=
  846. (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
  847. /* Tell the DMA to go */
  848. regs->tstat = TSTAT_CLEAR_THALT;
  849. /* Wait for buffer to be transmitted */
  850. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  851. if (i >= TOUT_LOOP) {
  852. debug("%s: tsec: tx error\n", dev->name);
  853. return result;
  854. }
  855. }
  856. txIdx = (txIdx + 1) % TX_BUF_CNT;
  857. result = rtx.txbd[txIdx].status & TXBD_STATS;
  858. return result;
  859. }
  860. static int tsec_recv(struct eth_device *dev)
  861. {
  862. int length;
  863. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  864. volatile tsec_t *regs = priv->regs;
  865. while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
  866. length = rtx.rxbd[rxIdx].length;
  867. /* Send the packet up if there were no errors */
  868. if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
  869. NetReceive(NetRxPackets[rxIdx], length - 4);
  870. } else {
  871. printf("Got error %x\n",
  872. (rtx.rxbd[rxIdx].status & RXBD_STATS));
  873. }
  874. rtx.rxbd[rxIdx].length = 0;
  875. /* Set the wrap bit if this is the last element in the list */
  876. rtx.rxbd[rxIdx].status =
  877. RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
  878. rxIdx = (rxIdx + 1) % PKTBUFSRX;
  879. }
  880. if (regs->ievent & IEVENT_BSY) {
  881. regs->ievent = IEVENT_BSY;
  882. regs->rstat = RSTAT_CLEAR_RHALT;
  883. }
  884. return -1;
  885. }
  886. /* Stop the interface */
  887. static void tsec_halt(struct eth_device *dev)
  888. {
  889. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  890. volatile tsec_t *regs = priv->regs;
  891. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  892. regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
  893. while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
  894. regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
  895. /* Shut down the PHY, as needed */
  896. if(priv->phyinfo)
  897. phy_run_commands(priv, priv->phyinfo->shutdown);
  898. }
  899. static struct phy_info phy_info_M88E1149S = {
  900. 0x1410ca,
  901. "Marvell 88E1149S",
  902. 4,
  903. (struct phy_cmd[]) { /* config */
  904. /* Reset and configure the PHY */
  905. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  906. {0x1d, 0x1f, NULL},
  907. {0x1e, 0x200c, NULL},
  908. {0x1d, 0x5, NULL},
  909. {0x1e, 0x0, NULL},
  910. {0x1e, 0x100, NULL},
  911. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  912. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  913. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  914. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  915. {miim_end,}
  916. },
  917. (struct phy_cmd[]) { /* startup */
  918. /* Status is read once to clear old link state */
  919. {MIIM_STATUS, miim_read, NULL},
  920. /* Auto-negotiate */
  921. {MIIM_STATUS, miim_read, &mii_parse_sr},
  922. /* Read the status */
  923. {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
  924. {miim_end,}
  925. },
  926. (struct phy_cmd[]) { /* shutdown */
  927. {miim_end,}
  928. },
  929. };
  930. /* The 5411 id is 0x206070, the 5421 is 0x2060e0 */
  931. static struct phy_info phy_info_BCM5461S = {
  932. 0x02060c1, /* 5461 ID */
  933. "Broadcom BCM5461S",
  934. 0, /* not clear to me what minor revisions we can shift away */
  935. (struct phy_cmd[]) { /* config */
  936. /* Reset and configure the PHY */
  937. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  938. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  939. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  940. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  941. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  942. {miim_end,}
  943. },
  944. (struct phy_cmd[]) { /* startup */
  945. /* Status is read once to clear old link state */
  946. {MIIM_STATUS, miim_read, NULL},
  947. /* Auto-negotiate */
  948. {MIIM_STATUS, miim_read, &mii_parse_sr},
  949. /* Read the status */
  950. {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
  951. {miim_end,}
  952. },
  953. (struct phy_cmd[]) { /* shutdown */
  954. {miim_end,}
  955. },
  956. };
  957. static struct phy_info phy_info_BCM5464S = {
  958. 0x02060b1, /* 5464 ID */
  959. "Broadcom BCM5464S",
  960. 0, /* not clear to me what minor revisions we can shift away */
  961. (struct phy_cmd[]) { /* config */
  962. /* Reset and configure the PHY */
  963. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  964. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  965. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  966. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  967. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  968. {miim_end,}
  969. },
  970. (struct phy_cmd[]) { /* startup */
  971. /* Status is read once to clear old link state */
  972. {MIIM_STATUS, miim_read, NULL},
  973. /* Auto-negotiate */
  974. {MIIM_STATUS, miim_read, &mii_parse_sr},
  975. /* Read the status */
  976. {MIIM_BCM54xx_AUXSTATUS, miim_read, &mii_parse_BCM54xx_sr},
  977. {miim_end,}
  978. },
  979. (struct phy_cmd[]) { /* shutdown */
  980. {miim_end,}
  981. },
  982. };
  983. static struct phy_info phy_info_BCM5482S = {
  984. 0x0143bcb,
  985. "Broadcom BCM5482S",
  986. 4,
  987. (struct phy_cmd[]) { /* config */
  988. /* Reset and configure the PHY */
  989. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  990. /* Setup read from auxilary control shadow register 7 */
  991. {MIIM_BCM54xx_AUXCNTL, MIIM_BCM54xx_AUXCNTL_ENCODE(7), NULL},
  992. /* Read Misc Control register and or in Ethernet@Wirespeed */
  993. {MIIM_BCM54xx_AUXCNTL, 0, &mii_BCM54xx_wirespeed},
  994. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  995. /* Initial config/enable of secondary SerDes interface */
  996. {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf), NULL},
  997. /* Write intial value to secondary SerDes Contol */
  998. {MIIM_BCM54XX_EXP_SEL, MIIM_BCM54XX_EXP_SEL_SSD | 0, NULL},
  999. {MIIM_BCM54XX_EXP_DATA, MIIM_CONTROL_RESTART, NULL},
  1000. /* Enable copper/fiber auto-detect */
  1001. {MIIM_BCM54XX_SHD, MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201)},
  1002. {miim_end,}
  1003. },
  1004. (struct phy_cmd[]) { /* startup */
  1005. /* Status is read once to clear old link state */
  1006. {MIIM_STATUS, miim_read, NULL},
  1007. /* Determine copper/fiber, auto-negotiate, and read the result */
  1008. {MIIM_STATUS, miim_read, &mii_parse_BCM5482_sr},
  1009. {miim_end,}
  1010. },
  1011. (struct phy_cmd[]) { /* shutdown */
  1012. {miim_end,}
  1013. },
  1014. };
  1015. static struct phy_info phy_info_M88E1011S = {
  1016. 0x01410c6,
  1017. "Marvell 88E1011S",
  1018. 4,
  1019. (struct phy_cmd[]) { /* config */
  1020. /* Reset and configure the PHY */
  1021. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1022. {0x1d, 0x1f, NULL},
  1023. {0x1e, 0x200c, NULL},
  1024. {0x1d, 0x5, NULL},
  1025. {0x1e, 0x0, NULL},
  1026. {0x1e, 0x100, NULL},
  1027. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1028. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1029. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1030. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1031. {miim_end,}
  1032. },
  1033. (struct phy_cmd[]) { /* startup */
  1034. /* Status is read once to clear old link state */
  1035. {MIIM_STATUS, miim_read, NULL},
  1036. /* Auto-negotiate */
  1037. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1038. /* Read the status */
  1039. {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
  1040. {miim_end,}
  1041. },
  1042. (struct phy_cmd[]) { /* shutdown */
  1043. {miim_end,}
  1044. },
  1045. };
  1046. static struct phy_info phy_info_M88E1111S = {
  1047. 0x01410cc,
  1048. "Marvell 88E1111S",
  1049. 4,
  1050. (struct phy_cmd[]) { /* config */
  1051. /* Reset and configure the PHY */
  1052. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1053. {0x1b, 0x848f, &mii_m88e1111s_setmode},
  1054. {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
  1055. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1056. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1057. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1058. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  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. /* Auto-negotiate */
  1065. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1066. /* Read the status */
  1067. {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
  1068. {miim_end,}
  1069. },
  1070. (struct phy_cmd[]) { /* shutdown */
  1071. {miim_end,}
  1072. },
  1073. };
  1074. static struct phy_info phy_info_M88E1118 = {
  1075. 0x01410e1,
  1076. "Marvell 88E1118",
  1077. 4,
  1078. (struct phy_cmd[]) { /* config */
  1079. /* Reset and configure the PHY */
  1080. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1081. {0x16, 0x0002, NULL}, /* Change Page Number */
  1082. {0x15, 0x1070, NULL}, /* Delay RGMII TX and RX */
  1083. {0x16, 0x0003, NULL}, /* Change Page Number */
  1084. {0x10, 0x021e, NULL}, /* Adjust LED control */
  1085. {0x16, 0x0000, NULL}, /* Change Page Number */
  1086. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1087. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1088. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1089. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1090. {miim_end,}
  1091. },
  1092. (struct phy_cmd[]) { /* startup */
  1093. {0x16, 0x0000, NULL}, /* Change Page Number */
  1094. /* Status is read once to clear old link state */
  1095. {MIIM_STATUS, miim_read, NULL},
  1096. /* Auto-negotiate */
  1097. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1098. /* Read the status */
  1099. {MIIM_88E1011_PHY_STATUS, miim_read,
  1100. &mii_parse_88E1011_psr},
  1101. {miim_end,}
  1102. },
  1103. (struct phy_cmd[]) { /* shutdown */
  1104. {miim_end,}
  1105. },
  1106. };
  1107. /*
  1108. * Since to access LED register we need do switch the page, we
  1109. * do LED configuring in the miim_read-like function as follows
  1110. */
  1111. static uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
  1112. {
  1113. uint pg;
  1114. /* Switch the page to access the led register */
  1115. pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
  1116. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
  1117. /* Configure leds */
  1118. write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
  1119. MIIM_88E1121_PHY_LED_DEF);
  1120. /* Restore the page pointer */
  1121. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
  1122. return 0;
  1123. }
  1124. static struct phy_info phy_info_M88E1121R = {
  1125. 0x01410cb,
  1126. "Marvell 88E1121R",
  1127. 4,
  1128. (struct phy_cmd[]) { /* config */
  1129. /* Reset and configure the PHY */
  1130. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1131. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1132. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1133. /* Configure leds */
  1134. {MIIM_88E1121_PHY_LED_CTRL, miim_read, &mii_88E1121_set_led},
  1135. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1136. /* Disable IRQs and de-assert interrupt */
  1137. {MIIM_88E1121_PHY_IRQ_EN, 0, NULL},
  1138. {MIIM_88E1121_PHY_IRQ_STATUS, miim_read, NULL},
  1139. {miim_end,}
  1140. },
  1141. (struct phy_cmd[]) { /* startup */
  1142. /* Status is read once to clear old link state */
  1143. {MIIM_STATUS, miim_read, NULL},
  1144. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1145. {MIIM_STATUS, miim_read, &mii_parse_link},
  1146. {miim_end,}
  1147. },
  1148. (struct phy_cmd[]) { /* shutdown */
  1149. {miim_end,}
  1150. },
  1151. };
  1152. static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
  1153. {
  1154. uint mii_data = read_phy_reg(priv, mii_reg);
  1155. /* Setting MIIM_88E1145_PHY_EXT_CR */
  1156. if (priv->flags & TSEC_REDUCED)
  1157. return mii_data |
  1158. MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
  1159. else
  1160. return mii_data;
  1161. }
  1162. static struct phy_info phy_info_M88E1145 = {
  1163. 0x01410cd,
  1164. "Marvell 88E1145",
  1165. 4,
  1166. (struct phy_cmd[]) { /* config */
  1167. /* Reset the PHY */
  1168. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1169. /* Errata E0, E1 */
  1170. {29, 0x001b, NULL},
  1171. {30, 0x418f, NULL},
  1172. {29, 0x0016, NULL},
  1173. {30, 0xa2da, NULL},
  1174. /* Configure the PHY */
  1175. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1176. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1177. {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO, NULL},
  1178. {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
  1179. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1180. {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
  1181. {miim_end,}
  1182. },
  1183. (struct phy_cmd[]) { /* startup */
  1184. /* Status is read once to clear old link state */
  1185. {MIIM_STATUS, miim_read, NULL},
  1186. /* Auto-negotiate */
  1187. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1188. {MIIM_88E1111_PHY_LED_CONTROL, MIIM_88E1111_PHY_LED_DIRECT, NULL},
  1189. /* Read the Status */
  1190. {MIIM_88E1011_PHY_STATUS, miim_read, &mii_parse_88E1011_psr},
  1191. {miim_end,}
  1192. },
  1193. (struct phy_cmd[]) { /* shutdown */
  1194. {miim_end,}
  1195. },
  1196. };
  1197. static struct phy_info phy_info_cis8204 = {
  1198. 0x3f11,
  1199. "Cicada Cis8204",
  1200. 6,
  1201. (struct phy_cmd[]) { /* config */
  1202. /* Override PHY config settings */
  1203. {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1204. /* Configure some basic stuff */
  1205. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1206. {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
  1207. &mii_cis8204_fixled},
  1208. {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
  1209. &mii_cis8204_setmode},
  1210. {miim_end,}
  1211. },
  1212. (struct phy_cmd[]) { /* startup */
  1213. /* Read the Status (2x to make sure link is right) */
  1214. {MIIM_STATUS, miim_read, NULL},
  1215. /* Auto-negotiate */
  1216. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1217. /* Read the status */
  1218. {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
  1219. {miim_end,}
  1220. },
  1221. (struct phy_cmd[]) { /* shutdown */
  1222. {miim_end,}
  1223. },
  1224. };
  1225. /* Cicada 8201 */
  1226. static struct phy_info phy_info_cis8201 = {
  1227. 0xfc41,
  1228. "CIS8201",
  1229. 4,
  1230. (struct phy_cmd[]) { /* config */
  1231. /* Override PHY config settings */
  1232. {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1233. /* Set up the interface mode */
  1234. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
  1235. /* Configure some basic stuff */
  1236. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1237. {miim_end,}
  1238. },
  1239. (struct phy_cmd[]) { /* startup */
  1240. /* Read the Status (2x to make sure link is right) */
  1241. {MIIM_STATUS, miim_read, NULL},
  1242. /* Auto-negotiate */
  1243. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1244. /* Read the status */
  1245. {MIIM_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
  1246. {miim_end,}
  1247. },
  1248. (struct phy_cmd[]) { /* shutdown */
  1249. {miim_end,}
  1250. },
  1251. };
  1252. static struct phy_info phy_info_VSC8211 = {
  1253. 0xfc4b,
  1254. "Vitesse VSC8211",
  1255. 4,
  1256. (struct phy_cmd[]) { /* config */
  1257. /* Override PHY config settings */
  1258. {MIIM_CIS8201_AUX_CONSTAT, MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1259. /* Set up the interface mode */
  1260. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT, NULL},
  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_CIS8201_AUX_CONSTAT, miim_read, &mii_parse_cis8201},
  1272. {miim_end,}
  1273. },
  1274. (struct phy_cmd[]) { /* shutdown */
  1275. {miim_end,}
  1276. },
  1277. };
  1278. static struct phy_info phy_info_VSC8244 = {
  1279. 0x3f1b,
  1280. "Vitesse VSC8244",
  1281. 6,
  1282. (struct phy_cmd[]) { /* config */
  1283. /* Override PHY config settings */
  1284. /* Configure some basic stuff */
  1285. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1286. {miim_end,}
  1287. },
  1288. (struct phy_cmd[]) { /* startup */
  1289. /* Read the Status (2x to make sure link is right) */
  1290. {MIIM_STATUS, miim_read, NULL},
  1291. /* Auto-negotiate */
  1292. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1293. /* Read the status */
  1294. {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
  1295. {miim_end,}
  1296. },
  1297. (struct phy_cmd[]) { /* shutdown */
  1298. {miim_end,}
  1299. },
  1300. };
  1301. static struct phy_info phy_info_VSC8641 = {
  1302. 0x7043,
  1303. "Vitesse VSC8641",
  1304. 4,
  1305. (struct phy_cmd[]) { /* config */
  1306. /* Configure some basic stuff */
  1307. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1308. {miim_end,}
  1309. },
  1310. (struct phy_cmd[]) { /* startup */
  1311. /* Read the Status (2x to make sure link is right) */
  1312. {MIIM_STATUS, miim_read, NULL},
  1313. /* Auto-negotiate */
  1314. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1315. /* Read the status */
  1316. {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
  1317. {miim_end,}
  1318. },
  1319. (struct phy_cmd[]) { /* shutdown */
  1320. {miim_end,}
  1321. },
  1322. };
  1323. static struct phy_info phy_info_VSC8221 = {
  1324. 0xfc55,
  1325. "Vitesse VSC8221",
  1326. 4,
  1327. (struct phy_cmd[]) { /* config */
  1328. /* Configure some basic stuff */
  1329. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1330. {miim_end,}
  1331. },
  1332. (struct phy_cmd[]) { /* startup */
  1333. /* Read the Status (2x to make sure link is right) */
  1334. {MIIM_STATUS, miim_read, NULL},
  1335. /* Auto-negotiate */
  1336. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1337. /* Read the status */
  1338. {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
  1339. {miim_end,}
  1340. },
  1341. (struct phy_cmd[]) { /* shutdown */
  1342. {miim_end,}
  1343. },
  1344. };
  1345. static struct phy_info phy_info_VSC8601 = {
  1346. 0x00007042,
  1347. "Vitesse VSC8601",
  1348. 4,
  1349. (struct phy_cmd[]) { /* config */
  1350. /* Override PHY config settings */
  1351. /* Configure some basic stuff */
  1352. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1353. #ifdef CONFIG_SYS_VSC8601_SKEWFIX
  1354. {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
  1355. #if defined(CONFIG_SYS_VSC8601_SKEW_TX) && defined(CONFIG_SYS_VSC8601_SKEW_RX)
  1356. {MIIM_EXT_PAGE_ACCESS,1,NULL},
  1357. #define VSC8101_SKEW \
  1358. (CONFIG_SYS_VSC8601_SKEW_TX << 14) | (CONFIG_SYS_VSC8601_SKEW_RX << 12)
  1359. {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
  1360. {MIIM_EXT_PAGE_ACCESS,0,NULL},
  1361. #endif
  1362. #endif
  1363. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1364. {MIIM_CONTROL, MIIM_CONTROL_RESTART, &mii_cr_init},
  1365. {miim_end,}
  1366. },
  1367. (struct phy_cmd[]) { /* startup */
  1368. /* Read the Status (2x to make sure link is right) */
  1369. {MIIM_STATUS, miim_read, NULL},
  1370. /* Auto-negotiate */
  1371. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1372. /* Read the status */
  1373. {MIIM_VSC8244_AUX_CONSTAT, miim_read, &mii_parse_vsc8244},
  1374. {miim_end,}
  1375. },
  1376. (struct phy_cmd[]) { /* shutdown */
  1377. {miim_end,}
  1378. },
  1379. };
  1380. static struct phy_info phy_info_dm9161 = {
  1381. 0x0181b88,
  1382. "Davicom DM9161E",
  1383. 4,
  1384. (struct phy_cmd[]) { /* config */
  1385. {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
  1386. /* Do not bypass the scrambler/descrambler */
  1387. {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
  1388. /* Clear 10BTCSR to default */
  1389. {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT, NULL},
  1390. /* Configure some basic stuff */
  1391. {MIIM_CONTROL, MIIM_CR_INIT, NULL},
  1392. /* Restart Auto Negotiation */
  1393. {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
  1394. {miim_end,}
  1395. },
  1396. (struct phy_cmd[]) { /* startup */
  1397. /* Status is read once to clear old link state */
  1398. {MIIM_STATUS, miim_read, NULL},
  1399. /* Auto-negotiate */
  1400. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1401. /* Read the status */
  1402. {MIIM_DM9161_SCSR, miim_read, &mii_parse_dm9161_scsr},
  1403. {miim_end,}
  1404. },
  1405. (struct phy_cmd[]) { /* shutdown */
  1406. {miim_end,}
  1407. },
  1408. };
  1409. /* a generic flavor. */
  1410. static struct phy_info phy_info_generic = {
  1411. 0,
  1412. "Unknown/Generic PHY",
  1413. 32,
  1414. (struct phy_cmd[]) { /* config */
  1415. {PHY_BMCR, PHY_BMCR_RESET, NULL},
  1416. {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
  1417. {miim_end,}
  1418. },
  1419. (struct phy_cmd[]) { /* startup */
  1420. {PHY_BMSR, miim_read, NULL},
  1421. {PHY_BMSR, miim_read, &mii_parse_sr},
  1422. {PHY_BMSR, miim_read, &mii_parse_link},
  1423. {miim_end,}
  1424. },
  1425. (struct phy_cmd[]) { /* shutdown */
  1426. {miim_end,}
  1427. }
  1428. };
  1429. static uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
  1430. {
  1431. unsigned int speed;
  1432. if (priv->link) {
  1433. speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
  1434. switch (speed) {
  1435. case MIIM_LXT971_SR2_10HDX:
  1436. priv->speed = 10;
  1437. priv->duplexity = 0;
  1438. break;
  1439. case MIIM_LXT971_SR2_10FDX:
  1440. priv->speed = 10;
  1441. priv->duplexity = 1;
  1442. break;
  1443. case MIIM_LXT971_SR2_100HDX:
  1444. priv->speed = 100;
  1445. priv->duplexity = 0;
  1446. break;
  1447. default:
  1448. priv->speed = 100;
  1449. priv->duplexity = 1;
  1450. }
  1451. } else {
  1452. priv->speed = 0;
  1453. priv->duplexity = 0;
  1454. }
  1455. return 0;
  1456. }
  1457. static struct phy_info phy_info_lxt971 = {
  1458. 0x0001378e,
  1459. "LXT971",
  1460. 4,
  1461. (struct phy_cmd[]) { /* config */
  1462. {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
  1463. {miim_end,}
  1464. },
  1465. (struct phy_cmd[]) { /* startup - enable interrupts */
  1466. /* { 0x12, 0x00f2, NULL }, */
  1467. {MIIM_STATUS, miim_read, NULL},
  1468. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1469. {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
  1470. {miim_end,}
  1471. },
  1472. (struct phy_cmd[]) { /* shutdown - disable interrupts */
  1473. {miim_end,}
  1474. },
  1475. };
  1476. /* Parse the DP83865's link and auto-neg status register for speed and duplex
  1477. * information
  1478. */
  1479. static uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
  1480. {
  1481. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  1482. case MIIM_DP83865_SPD_1000:
  1483. priv->speed = 1000;
  1484. break;
  1485. case MIIM_DP83865_SPD_100:
  1486. priv->speed = 100;
  1487. break;
  1488. default:
  1489. priv->speed = 10;
  1490. break;
  1491. }
  1492. if (mii_reg & MIIM_DP83865_DPX_FULL)
  1493. priv->duplexity = 1;
  1494. else
  1495. priv->duplexity = 0;
  1496. return 0;
  1497. }
  1498. static struct phy_info phy_info_dp83865 = {
  1499. 0x20005c7,
  1500. "NatSemi DP83865",
  1501. 4,
  1502. (struct phy_cmd[]) { /* config */
  1503. {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
  1504. {miim_end,}
  1505. },
  1506. (struct phy_cmd[]) { /* startup */
  1507. /* Status is read once to clear old link state */
  1508. {MIIM_STATUS, miim_read, NULL},
  1509. /* Auto-negotiate */
  1510. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1511. /* Read the link and auto-neg status */
  1512. {MIIM_DP83865_LANR, miim_read, &mii_parse_dp83865_lanr},
  1513. {miim_end,}
  1514. },
  1515. (struct phy_cmd[]) { /* shutdown */
  1516. {miim_end,}
  1517. },
  1518. };
  1519. static struct phy_info phy_info_rtl8211b = {
  1520. 0x001cc91,
  1521. "RealTek RTL8211B",
  1522. 4,
  1523. (struct phy_cmd[]) { /* config */
  1524. /* Reset and configure the PHY */
  1525. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1526. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1527. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1528. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1529. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1530. {miim_end,}
  1531. },
  1532. (struct phy_cmd[]) { /* startup */
  1533. /* Status is read once to clear old link state */
  1534. {MIIM_STATUS, miim_read, NULL},
  1535. /* Auto-negotiate */
  1536. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1537. /* Read the status */
  1538. {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
  1539. {miim_end,}
  1540. },
  1541. (struct phy_cmd[]) { /* shutdown */
  1542. {miim_end,}
  1543. },
  1544. };
  1545. static struct phy_info *phy_info[] = {
  1546. &phy_info_cis8204,
  1547. &phy_info_cis8201,
  1548. &phy_info_BCM5461S,
  1549. &phy_info_BCM5464S,
  1550. &phy_info_BCM5482S,
  1551. &phy_info_M88E1011S,
  1552. &phy_info_M88E1111S,
  1553. &phy_info_M88E1118,
  1554. &phy_info_M88E1121R,
  1555. &phy_info_M88E1145,
  1556. &phy_info_M88E1149S,
  1557. &phy_info_dm9161,
  1558. &phy_info_lxt971,
  1559. &phy_info_VSC8211,
  1560. &phy_info_VSC8244,
  1561. &phy_info_VSC8601,
  1562. &phy_info_VSC8641,
  1563. &phy_info_VSC8221,
  1564. &phy_info_dp83865,
  1565. &phy_info_rtl8211b,
  1566. &phy_info_generic, /* must be last; has ID 0 and 32 bit mask */
  1567. NULL
  1568. };
  1569. /* Grab the identifier of the device's PHY, and search through
  1570. * all of the known PHYs to see if one matches. If so, return
  1571. * it, if not, return NULL
  1572. */
  1573. static struct phy_info *get_phy_info(struct eth_device *dev)
  1574. {
  1575. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  1576. uint phy_reg, phy_ID;
  1577. int i;
  1578. struct phy_info *theInfo = NULL;
  1579. /* Grab the bits from PHYIR1, and put them in the upper half */
  1580. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  1581. phy_ID = (phy_reg & 0xffff) << 16;
  1582. /* Grab the bits from PHYIR2, and put them in the lower half */
  1583. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  1584. phy_ID |= (phy_reg & 0xffff);
  1585. /* loop through all the known PHY types, and find one that */
  1586. /* matches the ID we read from the PHY. */
  1587. for (i = 0; phy_info[i]; i++) {
  1588. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
  1589. theInfo = phy_info[i];
  1590. break;
  1591. }
  1592. }
  1593. if (theInfo == &phy_info_generic) {
  1594. printf("%s: No support for PHY id %x; assuming generic\n",
  1595. dev->name, phy_ID);
  1596. } else {
  1597. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  1598. }
  1599. return theInfo;
  1600. }
  1601. /* Execute the given series of commands on the given device's
  1602. * PHY, running functions as necessary
  1603. */
  1604. static void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1605. {
  1606. int i;
  1607. uint result;
  1608. volatile tsec_mdio_t *phyregs = priv->phyregs;
  1609. phyregs->miimcfg = MIIMCFG_RESET;
  1610. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1611. while (phyregs->miimind & MIIMIND_BUSY) ;
  1612. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1613. if (cmd->mii_data == miim_read) {
  1614. result = read_phy_reg(priv, cmd->mii_reg);
  1615. if (cmd->funct != NULL)
  1616. (*(cmd->funct)) (result, priv);
  1617. } else {
  1618. if (cmd->funct != NULL)
  1619. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1620. else
  1621. result = cmd->mii_data;
  1622. write_phy_reg(priv, cmd->mii_reg, result);
  1623. }
  1624. cmd++;
  1625. }
  1626. }
  1627. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
  1628. && !defined(BITBANGMII)
  1629. /*
  1630. * Read a MII PHY register.
  1631. *
  1632. * Returns:
  1633. * 0 on success
  1634. */
  1635. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1636. unsigned char reg, unsigned short *value)
  1637. {
  1638. unsigned short ret;
  1639. struct tsec_private *priv = privlist[0];
  1640. if (NULL == priv) {
  1641. printf("Can't read PHY at address %d\n", addr);
  1642. return -1;
  1643. }
  1644. ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
  1645. *value = ret;
  1646. return 0;
  1647. }
  1648. /*
  1649. * Write a MII PHY register.
  1650. *
  1651. * Returns:
  1652. * 0 on success
  1653. */
  1654. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1655. unsigned char reg, unsigned short value)
  1656. {
  1657. struct tsec_private *priv = privlist[0];
  1658. if (NULL == priv) {
  1659. printf("Can't write PHY at address %d\n", addr);
  1660. return -1;
  1661. }
  1662. tsec_local_mdio_write(priv->phyregs, addr, reg, value);
  1663. return 0;
  1664. }
  1665. #endif
  1666. #ifdef CONFIG_MCAST_TFTP
  1667. /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
  1668. /* Set the appropriate hash bit for the given addr */
  1669. /* The algorithm works like so:
  1670. * 1) Take the Destination Address (ie the multicast address), and
  1671. * do a CRC on it (little endian), and reverse the bits of the
  1672. * result.
  1673. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1674. * table. The table is controlled through 8 32-bit registers:
  1675. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1676. * gaddr7. This means that the 3 most significant bits in the
  1677. * hash index which gaddr register to use, and the 5 other bits
  1678. * indicate which bit (assuming an IBM numbering scheme, which
  1679. * for PowerPC (tm) is usually the case) in the tregister holds
  1680. * the entry. */
  1681. static int
  1682. tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
  1683. {
  1684. struct tsec_private *priv = privlist[1];
  1685. volatile tsec_t *regs = priv->regs;
  1686. volatile u32 *reg_array, value;
  1687. u8 result, whichbit, whichreg;
  1688. result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
  1689. whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
  1690. whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
  1691. value = (1 << (31-whichbit));
  1692. reg_array = &(regs->hash.gaddr0);
  1693. if (set) {
  1694. reg_array[whichreg] |= value;
  1695. } else {
  1696. reg_array[whichreg] &= ~value;
  1697. }
  1698. return 0;
  1699. }
  1700. #endif /* Multicast TFTP ? */