tsec.c 44 KB

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