tsec.c 50 KB

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