tsec.c 45 KB

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