tsec.c 45 KB

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