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