tsec.c 45 KB

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