tsec.c 44 KB

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