tsec.c 46 KB

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