tsec.c 47 KB

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