tsec.c 49 KB

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