tsec.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  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 = CFG_TBIPA_VALUE;
  250. phyregs->tbipa = CFG_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. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  960. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  961. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  962. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  963. {miim_end,}
  964. },
  965. (struct phy_cmd[]){ /* startup */
  966. {0x16, 0x0000, NULL}, /* Change Page Number */
  967. /* Status is read once to clear old link state */
  968. {MIIM_STATUS, miim_read, NULL},
  969. /* Auto-negotiate */
  970. /* Read the status */
  971. {MIIM_88E1011_PHY_STATUS, miim_read,
  972. &mii_parse_88E1011_psr},
  973. {miim_end,}
  974. },
  975. (struct phy_cmd[]){ /* shutdown */
  976. {miim_end,}
  977. },
  978. };
  979. /*
  980. * Since to access LED register we need do switch the page, we
  981. * do LED configuring in the miim_read-like function as follows
  982. */
  983. uint mii_88E1121_set_led (uint mii_reg, struct tsec_private *priv)
  984. {
  985. uint pg;
  986. /* Switch the page to access the led register */
  987. pg = read_phy_reg(priv, MIIM_88E1121_PHY_PAGE);
  988. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, MIIM_88E1121_PHY_LED_PAGE);
  989. /* Configure leds */
  990. write_phy_reg(priv, MIIM_88E1121_PHY_LED_CTRL,
  991. MIIM_88E1121_PHY_LED_DEF);
  992. /* Restore the page pointer */
  993. write_phy_reg(priv, MIIM_88E1121_PHY_PAGE, pg);
  994. return 0;
  995. }
  996. struct phy_info phy_info_M88E1121R = {
  997. 0x01410cb,
  998. "Marvell 88E1121R",
  999. 4,
  1000. (struct phy_cmd[]){ /* config */
  1001. /* Reset and configure the PHY */
  1002. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1003. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1004. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1005. /* Configure leds */
  1006. {MIIM_88E1121_PHY_LED_CTRL, miim_read,
  1007. &mii_88E1121_set_led},
  1008. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1009. {miim_end,}
  1010. },
  1011. (struct phy_cmd[]){ /* startup */
  1012. /* Status is read once to clear old link state */
  1013. {MIIM_STATUS, miim_read, NULL},
  1014. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1015. {MIIM_STATUS, miim_read, &mii_parse_link},
  1016. {miim_end,}
  1017. },
  1018. (struct phy_cmd[]){ /* shutdown */
  1019. {miim_end,}
  1020. },
  1021. };
  1022. static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
  1023. {
  1024. uint mii_data = read_phy_reg(priv, mii_reg);
  1025. /* Setting MIIM_88E1145_PHY_EXT_CR */
  1026. if (priv->flags & TSEC_REDUCED)
  1027. return mii_data |
  1028. MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
  1029. else
  1030. return mii_data;
  1031. }
  1032. static struct phy_info phy_info_M88E1145 = {
  1033. 0x01410cd,
  1034. "Marvell 88E1145",
  1035. 4,
  1036. (struct phy_cmd[]){ /* config */
  1037. /* Reset the PHY */
  1038. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1039. /* Errata E0, E1 */
  1040. {29, 0x001b, NULL},
  1041. {30, 0x418f, NULL},
  1042. {29, 0x0016, NULL},
  1043. {30, 0xa2da, NULL},
  1044. /* Configure the PHY */
  1045. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1046. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1047. {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
  1048. NULL},
  1049. {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
  1050. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1051. {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
  1052. {miim_end,}
  1053. },
  1054. (struct phy_cmd[]){ /* startup */
  1055. /* Status is read once to clear old link state */
  1056. {MIIM_STATUS, miim_read, NULL},
  1057. /* Auto-negotiate */
  1058. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1059. {MIIM_88E1111_PHY_LED_CONTROL,
  1060. MIIM_88E1111_PHY_LED_DIRECT, NULL},
  1061. /* Read the Status */
  1062. {MIIM_88E1011_PHY_STATUS, miim_read,
  1063. &mii_parse_88E1011_psr},
  1064. {miim_end,}
  1065. },
  1066. (struct phy_cmd[]){ /* shutdown */
  1067. {miim_end,}
  1068. },
  1069. };
  1070. struct phy_info phy_info_cis8204 = {
  1071. 0x3f11,
  1072. "Cicada Cis8204",
  1073. 6,
  1074. (struct phy_cmd[]){ /* config */
  1075. /* Override PHY config settings */
  1076. {MIIM_CIS8201_AUX_CONSTAT,
  1077. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1078. /* Configure some basic stuff */
  1079. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1080. {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
  1081. &mii_cis8204_fixled},
  1082. {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
  1083. &mii_cis8204_setmode},
  1084. {miim_end,}
  1085. },
  1086. (struct phy_cmd[]){ /* startup */
  1087. /* Read the Status (2x to make sure link is right) */
  1088. {MIIM_STATUS, miim_read, NULL},
  1089. /* Auto-negotiate */
  1090. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1091. /* Read the status */
  1092. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  1093. &mii_parse_cis8201},
  1094. {miim_end,}
  1095. },
  1096. (struct phy_cmd[]){ /* shutdown */
  1097. {miim_end,}
  1098. },
  1099. };
  1100. /* Cicada 8201 */
  1101. struct phy_info phy_info_cis8201 = {
  1102. 0xfc41,
  1103. "CIS8201",
  1104. 4,
  1105. (struct phy_cmd[]){ /* config */
  1106. /* Override PHY config settings */
  1107. {MIIM_CIS8201_AUX_CONSTAT,
  1108. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  1109. /* Set up the interface mode */
  1110. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
  1111. NULL},
  1112. /* Configure some basic stuff */
  1113. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1114. {miim_end,}
  1115. },
  1116. (struct phy_cmd[]){ /* startup */
  1117. /* Read the Status (2x to make sure link is right) */
  1118. {MIIM_STATUS, miim_read, NULL},
  1119. /* Auto-negotiate */
  1120. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1121. /* Read the status */
  1122. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  1123. &mii_parse_cis8201},
  1124. {miim_end,}
  1125. },
  1126. (struct phy_cmd[]){ /* shutdown */
  1127. {miim_end,}
  1128. },
  1129. };
  1130. struct phy_info phy_info_VSC8244 = {
  1131. 0x3f1b,
  1132. "Vitesse VSC8244",
  1133. 6,
  1134. (struct phy_cmd[]){ /* config */
  1135. /* Override PHY config settings */
  1136. /* Configure some basic stuff */
  1137. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1138. {miim_end,}
  1139. },
  1140. (struct phy_cmd[]){ /* startup */
  1141. /* Read the Status (2x to make sure link is right) */
  1142. {MIIM_STATUS, miim_read, NULL},
  1143. /* Auto-negotiate */
  1144. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1145. /* Read the status */
  1146. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1147. &mii_parse_vsc8244},
  1148. {miim_end,}
  1149. },
  1150. (struct phy_cmd[]){ /* shutdown */
  1151. {miim_end,}
  1152. },
  1153. };
  1154. struct phy_info phy_info_VSC8601 = {
  1155. 0x00007042,
  1156. "Vitesse VSC8601",
  1157. 4,
  1158. (struct phy_cmd[]){ /* config */
  1159. /* Override PHY config settings */
  1160. /* Configure some basic stuff */
  1161. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1162. #ifdef CFG_VSC8601_SKEWFIX
  1163. {MIIM_VSC8601_EPHY_CON,MIIM_VSC8601_EPHY_CON_INIT_SKEW,NULL},
  1164. #if defined(CFG_VSC8601_SKEW_TX) && defined(CFG_VSC8601_SKEW_RX)
  1165. {MIIM_EXT_PAGE_ACCESS,1,NULL},
  1166. #define VSC8101_SKEW (CFG_VSC8601_SKEW_TX<<14)|(CFG_VSC8601_SKEW_RX<<12)
  1167. {MIIM_VSC8601_SKEW_CTRL,VSC8101_SKEW,NULL},
  1168. {MIIM_EXT_PAGE_ACCESS,0,NULL},
  1169. #endif
  1170. #endif
  1171. {miim_end,}
  1172. },
  1173. (struct phy_cmd[]){ /* startup */
  1174. /* Read the Status (2x to make sure link is right) */
  1175. {MIIM_STATUS, miim_read, NULL},
  1176. /* Auto-negotiate */
  1177. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1178. /* Read the status */
  1179. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  1180. &mii_parse_vsc8244},
  1181. {miim_end,}
  1182. },
  1183. (struct phy_cmd[]){ /* shutdown */
  1184. {miim_end,}
  1185. },
  1186. };
  1187. struct phy_info phy_info_dm9161 = {
  1188. 0x0181b88,
  1189. "Davicom DM9161E",
  1190. 4,
  1191. (struct phy_cmd[]){ /* config */
  1192. {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
  1193. /* Do not bypass the scrambler/descrambler */
  1194. {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
  1195. /* Clear 10BTCSR to default */
  1196. {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
  1197. NULL},
  1198. /* Configure some basic stuff */
  1199. {MIIM_CONTROL, MIIM_CR_INIT, NULL},
  1200. /* Restart Auto Negotiation */
  1201. {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
  1202. {miim_end,}
  1203. },
  1204. (struct phy_cmd[]){ /* startup */
  1205. /* Status is read once to clear old link state */
  1206. {MIIM_STATUS, miim_read, NULL},
  1207. /* Auto-negotiate */
  1208. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1209. /* Read the status */
  1210. {MIIM_DM9161_SCSR, miim_read,
  1211. &mii_parse_dm9161_scsr},
  1212. {miim_end,}
  1213. },
  1214. (struct phy_cmd[]){ /* shutdown */
  1215. {miim_end,}
  1216. },
  1217. };
  1218. /* a generic flavor. */
  1219. struct phy_info phy_info_generic = {
  1220. 0,
  1221. "Unknown/Generic PHY",
  1222. 32,
  1223. (struct phy_cmd[]) { /* config */
  1224. {PHY_BMCR, PHY_BMCR_RESET, NULL},
  1225. {PHY_BMCR, PHY_BMCR_AUTON|PHY_BMCR_RST_NEG, NULL},
  1226. {miim_end,}
  1227. },
  1228. (struct phy_cmd[]) { /* startup */
  1229. {PHY_BMSR, miim_read, NULL},
  1230. {PHY_BMSR, miim_read, &mii_parse_sr},
  1231. {PHY_BMSR, miim_read, &mii_parse_link},
  1232. {miim_end,}
  1233. },
  1234. (struct phy_cmd[]) { /* shutdown */
  1235. {miim_end,}
  1236. }
  1237. };
  1238. uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
  1239. {
  1240. unsigned int speed;
  1241. if (priv->link) {
  1242. speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
  1243. switch (speed) {
  1244. case MIIM_LXT971_SR2_10HDX:
  1245. priv->speed = 10;
  1246. priv->duplexity = 0;
  1247. break;
  1248. case MIIM_LXT971_SR2_10FDX:
  1249. priv->speed = 10;
  1250. priv->duplexity = 1;
  1251. break;
  1252. case MIIM_LXT971_SR2_100HDX:
  1253. priv->speed = 100;
  1254. priv->duplexity = 0;
  1255. break;
  1256. default:
  1257. priv->speed = 100;
  1258. priv->duplexity = 1;
  1259. }
  1260. } else {
  1261. priv->speed = 0;
  1262. priv->duplexity = 0;
  1263. }
  1264. return 0;
  1265. }
  1266. static struct phy_info phy_info_lxt971 = {
  1267. 0x0001378e,
  1268. "LXT971",
  1269. 4,
  1270. (struct phy_cmd[]){ /* config */
  1271. {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
  1272. {miim_end,}
  1273. },
  1274. (struct phy_cmd[]){ /* startup - enable interrupts */
  1275. /* { 0x12, 0x00f2, NULL }, */
  1276. {MIIM_STATUS, miim_read, NULL},
  1277. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1278. {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
  1279. {miim_end,}
  1280. },
  1281. (struct phy_cmd[]){ /* shutdown - disable interrupts */
  1282. {miim_end,}
  1283. },
  1284. };
  1285. /* Parse the DP83865's link and auto-neg status register for speed and duplex
  1286. * information
  1287. */
  1288. uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
  1289. {
  1290. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  1291. case MIIM_DP83865_SPD_1000:
  1292. priv->speed = 1000;
  1293. break;
  1294. case MIIM_DP83865_SPD_100:
  1295. priv->speed = 100;
  1296. break;
  1297. default:
  1298. priv->speed = 10;
  1299. break;
  1300. }
  1301. if (mii_reg & MIIM_DP83865_DPX_FULL)
  1302. priv->duplexity = 1;
  1303. else
  1304. priv->duplexity = 0;
  1305. return 0;
  1306. }
  1307. struct phy_info phy_info_dp83865 = {
  1308. 0x20005c7,
  1309. "NatSemi DP83865",
  1310. 4,
  1311. (struct phy_cmd[]){ /* config */
  1312. {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
  1313. {miim_end,}
  1314. },
  1315. (struct phy_cmd[]){ /* startup */
  1316. /* Status is read once to clear old link state */
  1317. {MIIM_STATUS, miim_read, NULL},
  1318. /* Auto-negotiate */
  1319. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1320. /* Read the link and auto-neg status */
  1321. {MIIM_DP83865_LANR, miim_read,
  1322. &mii_parse_dp83865_lanr},
  1323. {miim_end,}
  1324. },
  1325. (struct phy_cmd[]){ /* shutdown */
  1326. {miim_end,}
  1327. },
  1328. };
  1329. struct phy_info phy_info_rtl8211b = {
  1330. 0x001cc91,
  1331. "RealTek RTL8211B",
  1332. 4,
  1333. (struct phy_cmd[]){ /* config */
  1334. /* Reset and configure the PHY */
  1335. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1336. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  1337. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  1338. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  1339. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  1340. {miim_end,}
  1341. },
  1342. (struct phy_cmd[]){ /* startup */
  1343. /* Status is read once to clear old link state */
  1344. {MIIM_STATUS, miim_read, NULL},
  1345. /* Auto-negotiate */
  1346. {MIIM_STATUS, miim_read, &mii_parse_sr},
  1347. /* Read the status */
  1348. {MIIM_RTL8211B_PHY_STATUS, miim_read, &mii_parse_RTL8211B_sr},
  1349. {miim_end,}
  1350. },
  1351. (struct phy_cmd[]){ /* shutdown */
  1352. {miim_end,}
  1353. },
  1354. };
  1355. struct phy_info *phy_info[] = {
  1356. &phy_info_cis8204,
  1357. &phy_info_cis8201,
  1358. &phy_info_BCM5461S,
  1359. &phy_info_BCM5464S,
  1360. &phy_info_M88E1011S,
  1361. &phy_info_M88E1111S,
  1362. &phy_info_M88E1118,
  1363. &phy_info_M88E1121R,
  1364. &phy_info_M88E1145,
  1365. &phy_info_M88E1149S,
  1366. &phy_info_dm9161,
  1367. &phy_info_lxt971,
  1368. &phy_info_VSC8244,
  1369. &phy_info_VSC8601,
  1370. &phy_info_dp83865,
  1371. &phy_info_rtl8211b,
  1372. &phy_info_generic,
  1373. NULL
  1374. };
  1375. /* Grab the identifier of the device's PHY, and search through
  1376. * all of the known PHYs to see if one matches. If so, return
  1377. * it, if not, return NULL
  1378. */
  1379. struct phy_info *get_phy_info(struct eth_device *dev)
  1380. {
  1381. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  1382. uint phy_reg, phy_ID;
  1383. int i;
  1384. struct phy_info *theInfo = NULL;
  1385. /* Grab the bits from PHYIR1, and put them in the upper half */
  1386. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  1387. phy_ID = (phy_reg & 0xffff) << 16;
  1388. /* Grab the bits from PHYIR2, and put them in the lower half */
  1389. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  1390. phy_ID |= (phy_reg & 0xffff);
  1391. /* loop through all the known PHY types, and find one that */
  1392. /* matches the ID we read from the PHY. */
  1393. for (i = 0; phy_info[i]; i++) {
  1394. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift)) {
  1395. theInfo = phy_info[i];
  1396. break;
  1397. }
  1398. }
  1399. if (theInfo == NULL) {
  1400. printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
  1401. return NULL;
  1402. } else {
  1403. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  1404. }
  1405. return theInfo;
  1406. }
  1407. /* Execute the given series of commands on the given device's
  1408. * PHY, running functions as necessary
  1409. */
  1410. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1411. {
  1412. int i;
  1413. uint result;
  1414. volatile tsec_t *phyregs = priv->phyregs;
  1415. phyregs->miimcfg = MIIMCFG_RESET;
  1416. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1417. while (phyregs->miimind & MIIMIND_BUSY) ;
  1418. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1419. if (cmd->mii_data == miim_read) {
  1420. result = read_phy_reg(priv, cmd->mii_reg);
  1421. if (cmd->funct != NULL)
  1422. (*(cmd->funct)) (result, priv);
  1423. } else {
  1424. if (cmd->funct != NULL)
  1425. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1426. else
  1427. result = cmd->mii_data;
  1428. write_phy_reg(priv, cmd->mii_reg, result);
  1429. }
  1430. cmd++;
  1431. }
  1432. }
  1433. /* Relocate the function pointers in the phy cmd lists */
  1434. static void relocate_cmds(void)
  1435. {
  1436. struct phy_cmd **cmdlistptr;
  1437. struct phy_cmd *cmd;
  1438. int i, j, k;
  1439. for (i = 0; phy_info[i]; i++) {
  1440. /* First thing's first: relocate the pointers to the
  1441. * PHY command structures (the structs were done) */
  1442. phy_info[i] = (struct phy_info *)((uint) phy_info[i]
  1443. + gd->reloc_off);
  1444. phy_info[i]->name += gd->reloc_off;
  1445. phy_info[i]->config =
  1446. (struct phy_cmd *)((uint) phy_info[i]->config
  1447. + gd->reloc_off);
  1448. phy_info[i]->startup =
  1449. (struct phy_cmd *)((uint) phy_info[i]->startup
  1450. + gd->reloc_off);
  1451. phy_info[i]->shutdown =
  1452. (struct phy_cmd *)((uint) phy_info[i]->shutdown
  1453. + gd->reloc_off);
  1454. cmdlistptr = &phy_info[i]->config;
  1455. j = 0;
  1456. for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
  1457. k = 0;
  1458. for (cmd = *cmdlistptr;
  1459. cmd->mii_reg != miim_end;
  1460. cmd++) {
  1461. /* Only relocate non-NULL pointers */
  1462. if (cmd->funct)
  1463. cmd->funct += gd->reloc_off;
  1464. k++;
  1465. }
  1466. j++;
  1467. }
  1468. }
  1469. relocated = 1;
  1470. }
  1471. #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) \
  1472. && !defined(BITBANGMII)
  1473. /*
  1474. * Read a MII PHY register.
  1475. *
  1476. * Returns:
  1477. * 0 on success
  1478. */
  1479. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1480. unsigned char reg, unsigned short *value)
  1481. {
  1482. unsigned short ret;
  1483. struct tsec_private *priv = privlist[0];
  1484. if (NULL == priv) {
  1485. printf("Can't read PHY at address %d\n", addr);
  1486. return -1;
  1487. }
  1488. ret = (unsigned short)tsec_local_mdio_read(priv->phyregs, addr, reg);
  1489. *value = ret;
  1490. return 0;
  1491. }
  1492. /*
  1493. * Write a MII PHY register.
  1494. *
  1495. * Returns:
  1496. * 0 on success
  1497. */
  1498. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1499. unsigned char reg, unsigned short value)
  1500. {
  1501. struct tsec_private *priv = privlist[0];
  1502. if (NULL == priv) {
  1503. printf("Can't write PHY at address %d\n", addr);
  1504. return -1;
  1505. }
  1506. tsec_local_mdio_write(priv->phyregs, addr, reg, value);
  1507. return 0;
  1508. }
  1509. #endif
  1510. #ifdef CONFIG_MCAST_TFTP
  1511. /* CREDITS: linux gianfar driver, slightly adjusted... thanx. */
  1512. /* Set the appropriate hash bit for the given addr */
  1513. /* The algorithm works like so:
  1514. * 1) Take the Destination Address (ie the multicast address), and
  1515. * do a CRC on it (little endian), and reverse the bits of the
  1516. * result.
  1517. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1518. * table. The table is controlled through 8 32-bit registers:
  1519. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1520. * gaddr7. This means that the 3 most significant bits in the
  1521. * hash index which gaddr register to use, and the 5 other bits
  1522. * indicate which bit (assuming an IBM numbering scheme, which
  1523. * for PowerPC (tm) is usually the case) in the tregister holds
  1524. * the entry. */
  1525. static int
  1526. tsec_mcast_addr (struct eth_device *dev, u8 mcast_mac, u8 set)
  1527. {
  1528. struct tsec_private *priv = privlist[1];
  1529. volatile tsec_t *regs = priv->regs;
  1530. volatile u32 *reg_array, value;
  1531. u8 result, whichbit, whichreg;
  1532. result = (u8)((ether_crc(MAC_ADDR_LEN,mcast_mac) >> 24) & 0xff);
  1533. whichbit = result & 0x1f; /* the 5 LSB = which bit to set */
  1534. whichreg = result >> 5; /* the 3 MSB = which reg to set it in */
  1535. value = (1 << (31-whichbit));
  1536. reg_array = &(regs->hash.gaddr0);
  1537. if (set) {
  1538. reg_array[whichreg] |= value;
  1539. } else {
  1540. reg_array[whichreg] &= ~value;
  1541. }
  1542. return 0;
  1543. }
  1544. #endif /* Multicast TFTP ? */