tsec.c 44 KB

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