tsec.c 47 KB

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