tsec.c 44 KB

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