tsec.c 48 KB

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