tsec.c 51 KB

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