tsec.c 47 KB

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