tsec.c 50 KB

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