tsec.c 49 KB

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