tsec.c 47 KB

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