tsec.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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 Freescale Semiconductor.
  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. #if defined(CONFIG_TSEC_ENET)
  19. #include "tsec.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. struct tsec_info_struct {
  30. unsigned int phyaddr;
  31. u32 flags;
  32. unsigned int phyregidx;
  33. };
  34. /* The tsec_info structure contains 3 values which the
  35. * driver uses to determine how to operate a given ethernet
  36. * device. The information needed is:
  37. * phyaddr - The address of the PHY which is attached to
  38. * the given device.
  39. *
  40. * flags - This variable indicates whether the device
  41. * supports gigabit speed ethernet, and whether it should be
  42. * in reduced mode.
  43. *
  44. * phyregidx - This variable specifies which ethernet device
  45. * controls the MII Management registers which are connected
  46. * to the PHY. For now, only TSEC1 (index 0) has
  47. * access to the PHYs, so all of the entries have "0".
  48. *
  49. * The values specified in the table are taken from the board's
  50. * config file in include/configs/. When implementing a new
  51. * board with ethernet capability, it is necessary to define:
  52. * TSECn_PHY_ADDR
  53. * TSECn_PHYIDX
  54. *
  55. * for n = 1,2,3, etc. And for FEC:
  56. * FEC_PHY_ADDR
  57. * FEC_PHYIDX
  58. */
  59. static struct tsec_info_struct tsec_info[] = {
  60. #if defined(CONFIG_MPC85XX_TSEC1) || defined(CONFIG_MPC83XX_TSEC1)
  61. {TSEC1_PHY_ADDR, TSEC_GIGABIT, TSEC1_PHYIDX},
  62. #elif defined(CONFIG_MPC86XX_TSEC1)
  63. {TSEC1_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC1_PHYIDX},
  64. #else
  65. {0, 0, 0},
  66. #endif
  67. #if defined(CONFIG_MPC85XX_TSEC2) || defined(CONFIG_MPC83XX_TSEC2)
  68. {TSEC2_PHY_ADDR, TSEC_GIGABIT, TSEC2_PHYIDX},
  69. #elif defined(CONFIG_MPC86XX_TSEC2)
  70. {TSEC2_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC2_PHYIDX},
  71. #else
  72. {0, 0, 0},
  73. #endif
  74. #ifdef CONFIG_MPC85XX_FEC
  75. {FEC_PHY_ADDR, 0, FEC_PHYIDX},
  76. #else
  77. #if defined(CONFIG_MPC85XX_TSEC3) || defined(CONFIG_MPC83XX_TSEC3) || defined(CONFIG_MPC86XX_TSEC3)
  78. {TSEC3_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC3_PHYIDX},
  79. #else
  80. {0, 0, 0},
  81. #endif
  82. #if defined(CONFIG_MPC85XX_TSEC4) || defined(CONFIG_MPC83XX_TSEC4) || defined(CONFIG_MPC86XX_TSEC4)
  83. {TSEC4_PHY_ADDR, TSEC_GIGABIT | TSEC_REDUCED, TSEC4_PHYIDX},
  84. #else
  85. {0, 0, 0},
  86. #endif
  87. #endif
  88. };
  89. #define MAXCONTROLLERS (4)
  90. static int relocated = 0;
  91. static struct tsec_private *privlist[MAXCONTROLLERS];
  92. #ifdef __GNUC__
  93. static RTXBD rtx __attribute__ ((aligned(8)));
  94. #else
  95. #error "rtx must be 64-bit aligned"
  96. #endif
  97. static int tsec_send(struct eth_device *dev,
  98. volatile void *packet, int length);
  99. static int tsec_recv(struct eth_device *dev);
  100. static int tsec_init(struct eth_device *dev, bd_t * bd);
  101. static void tsec_halt(struct eth_device *dev);
  102. static void init_registers(volatile tsec_t * regs);
  103. static void startup_tsec(struct eth_device *dev);
  104. static int init_phy(struct eth_device *dev);
  105. void write_phy_reg(struct tsec_private *priv, uint regnum, uint value);
  106. uint read_phy_reg(struct tsec_private *priv, uint regnum);
  107. struct phy_info *get_phy_info(struct eth_device *dev);
  108. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd);
  109. static void adjust_link(struct eth_device *dev);
  110. static void relocate_cmds(void);
  111. static int tsec_miiphy_write(char *devname, unsigned char addr,
  112. unsigned char reg, unsigned short value);
  113. static int tsec_miiphy_read(char *devname, unsigned char addr,
  114. unsigned char reg, unsigned short *value);
  115. /* Initialize device structure. Returns success if PHY
  116. * initialization succeeded (i.e. if it recognizes the PHY)
  117. */
  118. int tsec_initialize(bd_t * bis, int index, char *devname)
  119. {
  120. struct eth_device *dev;
  121. int i;
  122. struct tsec_private *priv;
  123. dev = (struct eth_device *)malloc(sizeof *dev);
  124. if (NULL == dev)
  125. return 0;
  126. memset(dev, 0, sizeof *dev);
  127. priv = (struct tsec_private *)malloc(sizeof(*priv));
  128. if (NULL == priv)
  129. return 0;
  130. privlist[index] = priv;
  131. priv->regs = (volatile tsec_t *)(TSEC_BASE_ADDR + index * TSEC_SIZE);
  132. priv->phyregs = (volatile tsec_t *)(TSEC_BASE_ADDR +
  133. tsec_info[index].phyregidx *
  134. TSEC_SIZE);
  135. priv->phyaddr = tsec_info[index].phyaddr;
  136. priv->flags = tsec_info[index].flags;
  137. sprintf(dev->name, devname);
  138. dev->iobase = 0;
  139. dev->priv = priv;
  140. dev->init = tsec_init;
  141. dev->halt = tsec_halt;
  142. dev->send = tsec_send;
  143. dev->recv = tsec_recv;
  144. /* Tell u-boot to get the addr from the env */
  145. for (i = 0; i < 6; i++)
  146. dev->enetaddr[i] = 0;
  147. eth_register(dev);
  148. /* Reset the MAC */
  149. priv->regs->maccfg1 |= MACCFG1_SOFT_RESET;
  150. priv->regs->maccfg1 &= ~(MACCFG1_SOFT_RESET);
  151. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
  152. && !defined(BITBANGMII)
  153. miiphy_register(dev->name, tsec_miiphy_read, tsec_miiphy_write);
  154. #endif
  155. /* Try to initialize PHY here, and return */
  156. return init_phy(dev);
  157. }
  158. /* Initializes data structures and registers for the controller,
  159. * and brings the interface up. Returns the link status, meaning
  160. * that it returns success if the link is up, failure otherwise.
  161. * This allows u-boot to find the first active controller.
  162. */
  163. int tsec_init(struct eth_device *dev, bd_t * bd)
  164. {
  165. uint tempval;
  166. char tmpbuf[MAC_ADDR_LEN];
  167. int i;
  168. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  169. volatile tsec_t *regs = priv->regs;
  170. /* Make sure the controller is stopped */
  171. tsec_halt(dev);
  172. /* Init MACCFG2. Defaults to GMII */
  173. regs->maccfg2 = MACCFG2_INIT_SETTINGS;
  174. /* Init ECNTRL */
  175. regs->ecntrl = ECNTRL_INIT_SETTINGS;
  176. /* Copy the station address into the address registers.
  177. * Backwards, because little endian MACS are dumb */
  178. for (i = 0; i < MAC_ADDR_LEN; i++) {
  179. tmpbuf[MAC_ADDR_LEN - 1 - i] = dev->enetaddr[i];
  180. }
  181. regs->macstnaddr1 = *((uint *) (tmpbuf));
  182. tempval = *((uint *) (tmpbuf + 4));
  183. regs->macstnaddr2 = tempval;
  184. /* reset the indices to zero */
  185. rxIdx = 0;
  186. txIdx = 0;
  187. /* Clear out (for the most part) the other registers */
  188. init_registers(regs);
  189. /* Ready the device for tx/rx */
  190. startup_tsec(dev);
  191. /* If there's no link, fail */
  192. return priv->link;
  193. }
  194. /* Write value to the device's PHY through the registers
  195. * specified in priv, modifying the register specified in regnum.
  196. * It will wait for the write to be done (or for a timeout to
  197. * expire) before exiting
  198. */
  199. void write_phy_reg(struct tsec_private *priv, uint regnum, uint value)
  200. {
  201. volatile tsec_t *regbase = priv->phyregs;
  202. uint phyid = priv->phyaddr;
  203. int timeout = 1000000;
  204. regbase->miimadd = (phyid << 8) | regnum;
  205. regbase->miimcon = value;
  206. asm("sync");
  207. timeout = 1000000;
  208. while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
  209. }
  210. /* Reads register regnum on the device's PHY through the
  211. * registers specified in priv. It lowers and raises the read
  212. * command, and waits for the data to become valid (miimind
  213. * notvalid bit cleared), and the bus to cease activity (miimind
  214. * busy bit cleared), and then returns the value
  215. */
  216. uint read_phy_reg(struct tsec_private *priv, uint regnum)
  217. {
  218. uint value;
  219. volatile tsec_t *regbase = priv->phyregs;
  220. uint phyid = priv->phyaddr;
  221. /* Put the address of the phy, and the register
  222. * number into MIIMADD */
  223. regbase->miimadd = (phyid << 8) | regnum;
  224. /* Clear the command register, and wait */
  225. regbase->miimcom = 0;
  226. asm("sync");
  227. /* Initiate a read command, and wait */
  228. regbase->miimcom = MIIM_READ_COMMAND;
  229. asm("sync");
  230. /* Wait for the the indication that the read is done */
  231. while ((regbase->miimind & (MIIMIND_NOTVALID | MIIMIND_BUSY))) ;
  232. /* Grab the value read from the PHY */
  233. value = regbase->miimstat;
  234. return value;
  235. }
  236. /* Discover which PHY is attached to the device, and configure it
  237. * properly. If the PHY is not recognized, then return 0
  238. * (failure). Otherwise, return 1
  239. */
  240. static int init_phy(struct eth_device *dev)
  241. {
  242. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  243. struct phy_info *curphy;
  244. volatile tsec_t *regs = (volatile tsec_t *)(TSEC_BASE_ADDR);
  245. /* Assign a Physical address to the TBI */
  246. regs->tbipa = TBIPA_VALUE;
  247. regs = (volatile tsec_t *)(TSEC_BASE_ADDR + TSEC_SIZE);
  248. regs->tbipa = TBIPA_VALUE;
  249. asm("sync");
  250. /* Reset MII (due to new addresses) */
  251. priv->phyregs->miimcfg = MIIMCFG_RESET;
  252. asm("sync");
  253. priv->phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  254. asm("sync");
  255. while (priv->phyregs->miimind & MIIMIND_BUSY) ;
  256. if (0 == relocated)
  257. relocate_cmds();
  258. /* Get the cmd structure corresponding to the attached
  259. * PHY */
  260. curphy = get_phy_info(dev);
  261. if (NULL == curphy) {
  262. printf("%s: No PHY found\n", dev->name);
  263. return 0;
  264. }
  265. priv->phyinfo = curphy;
  266. phy_run_commands(priv, priv->phyinfo->config);
  267. return 1;
  268. }
  269. /*
  270. * Returns which value to write to the control register.
  271. * For 10/100, the value is slightly different
  272. */
  273. uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
  274. {
  275. if (priv->flags & TSEC_GIGABIT)
  276. return MIIM_CONTROL_INIT;
  277. else
  278. return MIIM_CR_INIT;
  279. }
  280. /* Parse the status register for link, and then do
  281. * auto-negotiation
  282. */
  283. uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
  284. {
  285. /*
  286. * Wait if PHY is capable of autonegotiation and autonegotiation
  287. * is not complete.
  288. */
  289. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  290. if ((mii_reg & PHY_BMSR_AUTN_ABLE)
  291. && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
  292. int i = 0;
  293. puts("Waiting for PHY auto negotiation to complete");
  294. while (!((mii_reg & PHY_BMSR_AUTN_COMP)
  295. && (mii_reg & MIIM_STATUS_LINK))) {
  296. /*
  297. * Timeout reached ?
  298. */
  299. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  300. puts(" TIMEOUT !\n");
  301. priv->link = 0;
  302. return 0;
  303. }
  304. if ((i++ % 1000) == 0) {
  305. putc('.');
  306. }
  307. udelay(1000); /* 1 ms */
  308. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  309. }
  310. puts(" done\n");
  311. priv->link = 1;
  312. udelay(500000); /* another 500 ms (results in faster booting) */
  313. } else {
  314. priv->link = 1;
  315. }
  316. return 0;
  317. }
  318. /* Parse the 88E1011's status register for speed and duplex
  319. * information
  320. */
  321. uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
  322. {
  323. uint speed;
  324. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  325. if (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
  326. (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
  327. int i = 0;
  328. puts("Waiting for PHY realtime link");
  329. while (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
  330. (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
  331. /*
  332. * Timeout reached ?
  333. */
  334. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  335. puts(" TIMEOUT !\n");
  336. priv->link = 0;
  337. break;
  338. }
  339. if ((i++ % 1000) == 0) {
  340. putc('.');
  341. }
  342. udelay(1000); /* 1 ms */
  343. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  344. }
  345. puts(" done\n");
  346. udelay(500000); /* another 500 ms (results in faster booting) */
  347. }
  348. if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
  349. priv->duplexity = 1;
  350. else
  351. priv->duplexity = 0;
  352. speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
  353. switch (speed) {
  354. case MIIM_88E1011_PHYSTAT_GBIT:
  355. priv->speed = 1000;
  356. break;
  357. case MIIM_88E1011_PHYSTAT_100:
  358. priv->speed = 100;
  359. break;
  360. default:
  361. priv->speed = 10;
  362. }
  363. return 0;
  364. }
  365. /* Parse the cis8201's status register for speed and duplex
  366. * information
  367. */
  368. uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
  369. {
  370. uint speed;
  371. if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
  372. priv->duplexity = 1;
  373. else
  374. priv->duplexity = 0;
  375. speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
  376. switch (speed) {
  377. case MIIM_CIS8201_AUXCONSTAT_GBIT:
  378. priv->speed = 1000;
  379. break;
  380. case MIIM_CIS8201_AUXCONSTAT_100:
  381. priv->speed = 100;
  382. break;
  383. default:
  384. priv->speed = 10;
  385. break;
  386. }
  387. return 0;
  388. }
  389. /* Parse the vsc8244's status register for speed and duplex
  390. * information
  391. */
  392. uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
  393. {
  394. uint speed;
  395. if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
  396. priv->duplexity = 1;
  397. else
  398. priv->duplexity = 0;
  399. speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
  400. switch (speed) {
  401. case MIIM_VSC8244_AUXCONSTAT_GBIT:
  402. priv->speed = 1000;
  403. break;
  404. case MIIM_VSC8244_AUXCONSTAT_100:
  405. priv->speed = 100;
  406. break;
  407. default:
  408. priv->speed = 10;
  409. break;
  410. }
  411. return 0;
  412. }
  413. /* Parse the DM9161's status register for speed and duplex
  414. * information
  415. */
  416. uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
  417. {
  418. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
  419. priv->speed = 100;
  420. else
  421. priv->speed = 10;
  422. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
  423. priv->duplexity = 1;
  424. else
  425. priv->duplexity = 0;
  426. return 0;
  427. }
  428. /*
  429. * Hack to write all 4 PHYs with the LED values
  430. */
  431. uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
  432. {
  433. uint phyid;
  434. volatile tsec_t *regbase = priv->phyregs;
  435. int timeout = 1000000;
  436. for (phyid = 0; phyid < 4; phyid++) {
  437. regbase->miimadd = (phyid << 8) | mii_reg;
  438. regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
  439. asm("sync");
  440. timeout = 1000000;
  441. while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
  442. }
  443. return MIIM_CIS8204_SLEDCON_INIT;
  444. }
  445. uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
  446. {
  447. if (priv->flags & TSEC_REDUCED)
  448. return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
  449. else
  450. return MIIM_CIS8204_EPHYCON_INIT;
  451. }
  452. /* Initialized required registers to appropriate values, zeroing
  453. * those we don't care about (unless zero is bad, in which case,
  454. * choose a more appropriate value)
  455. */
  456. static void init_registers(volatile tsec_t * regs)
  457. {
  458. /* Clear IEVENT */
  459. regs->ievent = IEVENT_INIT_CLEAR;
  460. regs->imask = IMASK_INIT_CLEAR;
  461. regs->hash.iaddr0 = 0;
  462. regs->hash.iaddr1 = 0;
  463. regs->hash.iaddr2 = 0;
  464. regs->hash.iaddr3 = 0;
  465. regs->hash.iaddr4 = 0;
  466. regs->hash.iaddr5 = 0;
  467. regs->hash.iaddr6 = 0;
  468. regs->hash.iaddr7 = 0;
  469. regs->hash.gaddr0 = 0;
  470. regs->hash.gaddr1 = 0;
  471. regs->hash.gaddr2 = 0;
  472. regs->hash.gaddr3 = 0;
  473. regs->hash.gaddr4 = 0;
  474. regs->hash.gaddr5 = 0;
  475. regs->hash.gaddr6 = 0;
  476. regs->hash.gaddr7 = 0;
  477. regs->rctrl = 0x00000000;
  478. /* Init RMON mib registers */
  479. memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
  480. regs->rmon.cam1 = 0xffffffff;
  481. regs->rmon.cam2 = 0xffffffff;
  482. regs->mrblr = MRBLR_INIT_SETTINGS;
  483. regs->minflr = MINFLR_INIT_SETTINGS;
  484. regs->attr = ATTR_INIT_SETTINGS;
  485. regs->attreli = ATTRELI_INIT_SETTINGS;
  486. }
  487. /* Configure maccfg2 based on negotiated speed and duplex
  488. * reported by PHY handling code
  489. */
  490. static void adjust_link(struct eth_device *dev)
  491. {
  492. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  493. volatile tsec_t *regs = priv->regs;
  494. if (priv->link) {
  495. if (priv->duplexity != 0)
  496. regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
  497. else
  498. regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
  499. switch (priv->speed) {
  500. case 1000:
  501. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  502. | MACCFG2_GMII);
  503. break;
  504. case 100:
  505. case 10:
  506. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  507. | MACCFG2_MII);
  508. /* If We're in reduced mode, we need
  509. * to say whether we're 10 or 100 MB.
  510. */
  511. if ((priv->speed == 100)
  512. && (priv->flags & TSEC_REDUCED))
  513. regs->ecntrl |= ECNTRL_R100;
  514. else
  515. regs->ecntrl &= ~(ECNTRL_R100);
  516. break;
  517. default:
  518. printf("%s: Speed was bad\n", dev->name);
  519. break;
  520. }
  521. printf("Speed: %d, %s duplex\n", priv->speed,
  522. (priv->duplexity) ? "full" : "half");
  523. } else {
  524. printf("%s: No link.\n", dev->name);
  525. }
  526. }
  527. /* Set up the buffers and their descriptors, and bring up the
  528. * interface
  529. */
  530. static void startup_tsec(struct eth_device *dev)
  531. {
  532. int i;
  533. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  534. volatile tsec_t *regs = priv->regs;
  535. /* Point to the buffer descriptors */
  536. regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
  537. regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
  538. /* Initialize the Rx Buffer descriptors */
  539. for (i = 0; i < PKTBUFSRX; i++) {
  540. rtx.rxbd[i].status = RXBD_EMPTY;
  541. rtx.rxbd[i].length = 0;
  542. rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
  543. }
  544. rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
  545. /* Initialize the TX Buffer Descriptors */
  546. for (i = 0; i < TX_BUF_CNT; i++) {
  547. rtx.txbd[i].status = 0;
  548. rtx.txbd[i].length = 0;
  549. rtx.txbd[i].bufPtr = 0;
  550. }
  551. rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
  552. /* Start up the PHY */
  553. phy_run_commands(priv, priv->phyinfo->startup);
  554. adjust_link(dev);
  555. /* Enable Transmit and Receive */
  556. regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  557. /* Tell the DMA it is clear to go */
  558. regs->dmactrl |= DMACTRL_INIT_SETTINGS;
  559. regs->tstat = TSTAT_CLEAR_THALT;
  560. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  561. }
  562. /* This returns the status bits of the device. The return value
  563. * is never checked, and this is what the 8260 driver did, so we
  564. * do the same. Presumably, this would be zero if there were no
  565. * errors
  566. */
  567. static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
  568. {
  569. int i;
  570. int result = 0;
  571. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  572. volatile tsec_t *regs = priv->regs;
  573. /* Find an empty buffer descriptor */
  574. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  575. if (i >= TOUT_LOOP) {
  576. debug("%s: tsec: tx buffers full\n", dev->name);
  577. return result;
  578. }
  579. }
  580. rtx.txbd[txIdx].bufPtr = (uint) packet;
  581. rtx.txbd[txIdx].length = length;
  582. rtx.txbd[txIdx].status |=
  583. (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
  584. /* Tell the DMA to go */
  585. regs->tstat = TSTAT_CLEAR_THALT;
  586. /* Wait for buffer to be transmitted */
  587. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  588. if (i >= TOUT_LOOP) {
  589. debug("%s: tsec: tx error\n", dev->name);
  590. return result;
  591. }
  592. }
  593. txIdx = (txIdx + 1) % TX_BUF_CNT;
  594. result = rtx.txbd[txIdx].status & TXBD_STATS;
  595. return result;
  596. }
  597. static int tsec_recv(struct eth_device *dev)
  598. {
  599. int length;
  600. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  601. volatile tsec_t *regs = priv->regs;
  602. while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
  603. length = rtx.rxbd[rxIdx].length;
  604. /* Send the packet up if there were no errors */
  605. if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
  606. NetReceive(NetRxPackets[rxIdx], length - 4);
  607. } else {
  608. printf("Got error %x\n",
  609. (rtx.rxbd[rxIdx].status & RXBD_STATS));
  610. }
  611. rtx.rxbd[rxIdx].length = 0;
  612. /* Set the wrap bit if this is the last element in the list */
  613. rtx.rxbd[rxIdx].status =
  614. RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
  615. rxIdx = (rxIdx + 1) % PKTBUFSRX;
  616. }
  617. if (regs->ievent & IEVENT_BSY) {
  618. regs->ievent = IEVENT_BSY;
  619. regs->rstat = RSTAT_CLEAR_RHALT;
  620. }
  621. return -1;
  622. }
  623. /* Stop the interface */
  624. static void tsec_halt(struct eth_device *dev)
  625. {
  626. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  627. volatile tsec_t *regs = priv->regs;
  628. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  629. regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
  630. while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
  631. regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
  632. /* Shut down the PHY, as needed */
  633. phy_run_commands(priv, priv->phyinfo->shutdown);
  634. }
  635. struct phy_info phy_info_M88E1011S = {
  636. 0x01410c6,
  637. "Marvell 88E1011S",
  638. 4,
  639. (struct phy_cmd[]){ /* config */
  640. /* Reset and configure the PHY */
  641. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  642. {0x1d, 0x1f, NULL},
  643. {0x1e, 0x200c, NULL},
  644. {0x1d, 0x5, NULL},
  645. {0x1e, 0x0, NULL},
  646. {0x1e, 0x100, NULL},
  647. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  648. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  649. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  650. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  651. {miim_end,}
  652. },
  653. (struct phy_cmd[]){ /* startup */
  654. /* Status is read once to clear old link state */
  655. {MIIM_STATUS, miim_read, NULL},
  656. /* Auto-negotiate */
  657. {MIIM_STATUS, miim_read, &mii_parse_sr},
  658. /* Read the status */
  659. {MIIM_88E1011_PHY_STATUS, miim_read,
  660. &mii_parse_88E1011_psr},
  661. {miim_end,}
  662. },
  663. (struct phy_cmd[]){ /* shutdown */
  664. {miim_end,}
  665. },
  666. };
  667. struct phy_info phy_info_M88E1111S = {
  668. 0x01410cc,
  669. "Marvell 88E1111S",
  670. 4,
  671. (struct phy_cmd[]){ /* config */
  672. /* Reset and configure the PHY */
  673. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  674. {0x1d, 0x1f, NULL},
  675. {0x1e, 0x200c, NULL},
  676. {0x1d, 0x5, NULL},
  677. {0x1e, 0x0, NULL},
  678. {0x1e, 0x100, NULL},
  679. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  680. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  681. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  682. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  683. {miim_end,}
  684. },
  685. (struct phy_cmd[]){ /* startup */
  686. /* Status is read once to clear old link state */
  687. {MIIM_STATUS, miim_read, NULL},
  688. /* Auto-negotiate */
  689. {MIIM_STATUS, miim_read, &mii_parse_sr},
  690. /* Read the status */
  691. {MIIM_88E1011_PHY_STATUS, miim_read,
  692. &mii_parse_88E1011_psr},
  693. {miim_end,}
  694. },
  695. (struct phy_cmd[]){ /* shutdown */
  696. {miim_end,}
  697. },
  698. };
  699. static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
  700. {
  701. uint mii_data = read_phy_reg(priv, mii_reg);
  702. /* Setting MIIM_88E1145_PHY_EXT_CR */
  703. if (priv->flags & TSEC_REDUCED)
  704. return mii_data |
  705. MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
  706. else
  707. return mii_data;
  708. }
  709. static struct phy_info phy_info_M88E1145 = {
  710. 0x01410cd,
  711. "Marvell 88E1145",
  712. 4,
  713. (struct phy_cmd[]){ /* config */
  714. /* Errata E0, E1 */
  715. {29, 0x001b, NULL},
  716. {30, 0x418f, NULL},
  717. {29, 0x0016, NULL},
  718. {30, 0xa2da, NULL},
  719. /* Reset and configure the PHY */
  720. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  721. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  722. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  723. {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
  724. NULL},
  725. {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
  726. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  727. {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
  728. {miim_end,}
  729. },
  730. (struct phy_cmd[]){ /* startup */
  731. /* Status is read once to clear old link state */
  732. {MIIM_STATUS, miim_read, NULL},
  733. /* Auto-negotiate */
  734. {MIIM_STATUS, miim_read, &mii_parse_sr},
  735. {MIIM_88E1111_PHY_LED_CONTROL,
  736. MIIM_88E1111_PHY_LED_DIRECT, NULL},
  737. /* Read the Status */
  738. {MIIM_88E1011_PHY_STATUS, miim_read,
  739. &mii_parse_88E1011_psr},
  740. {miim_end,}
  741. },
  742. (struct phy_cmd[]){ /* shutdown */
  743. {miim_end,}
  744. },
  745. };
  746. struct phy_info phy_info_cis8204 = {
  747. 0x3f11,
  748. "Cicada Cis8204",
  749. 6,
  750. (struct phy_cmd[]){ /* config */
  751. /* Override PHY config settings */
  752. {MIIM_CIS8201_AUX_CONSTAT,
  753. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  754. /* Configure some basic stuff */
  755. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  756. {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
  757. &mii_cis8204_fixled},
  758. {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
  759. &mii_cis8204_setmode},
  760. {miim_end,}
  761. },
  762. (struct phy_cmd[]){ /* startup */
  763. /* Read the Status (2x to make sure link is right) */
  764. {MIIM_STATUS, miim_read, NULL},
  765. /* Auto-negotiate */
  766. {MIIM_STATUS, miim_read, &mii_parse_sr},
  767. /* Read the status */
  768. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  769. &mii_parse_cis8201},
  770. {miim_end,}
  771. },
  772. (struct phy_cmd[]){ /* shutdown */
  773. {miim_end,}
  774. },
  775. };
  776. /* Cicada 8201 */
  777. struct phy_info phy_info_cis8201 = {
  778. 0xfc41,
  779. "CIS8201",
  780. 4,
  781. (struct phy_cmd[]){ /* config */
  782. /* Override PHY config settings */
  783. {MIIM_CIS8201_AUX_CONSTAT,
  784. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  785. /* Set up the interface mode */
  786. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
  787. NULL},
  788. /* Configure some basic stuff */
  789. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  790. {miim_end,}
  791. },
  792. (struct phy_cmd[]){ /* startup */
  793. /* Read the Status (2x to make sure link is right) */
  794. {MIIM_STATUS, miim_read, NULL},
  795. /* Auto-negotiate */
  796. {MIIM_STATUS, miim_read, &mii_parse_sr},
  797. /* Read the status */
  798. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  799. &mii_parse_cis8201},
  800. {miim_end,}
  801. },
  802. (struct phy_cmd[]){ /* shutdown */
  803. {miim_end,}
  804. },
  805. };
  806. struct phy_info phy_info_VSC8244 = {
  807. 0x3f1b,
  808. "Vitesse VSC8244",
  809. 6,
  810. (struct phy_cmd[]){ /* config */
  811. /* Override PHY config settings */
  812. /* Configure some basic stuff */
  813. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  814. {miim_end,}
  815. },
  816. (struct phy_cmd[]){ /* startup */
  817. /* Read the Status (2x to make sure link is right) */
  818. {MIIM_STATUS, miim_read, NULL},
  819. /* Auto-negotiate */
  820. {MIIM_STATUS, miim_read, &mii_parse_sr},
  821. /* Read the status */
  822. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  823. &mii_parse_vsc8244},
  824. {miim_end,}
  825. },
  826. (struct phy_cmd[]){ /* shutdown */
  827. {miim_end,}
  828. },
  829. };
  830. struct phy_info phy_info_dm9161 = {
  831. 0x0181b88,
  832. "Davicom DM9161E",
  833. 4,
  834. (struct phy_cmd[]){ /* config */
  835. {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
  836. /* Do not bypass the scrambler/descrambler */
  837. {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
  838. /* Clear 10BTCSR to default */
  839. {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
  840. NULL},
  841. /* Configure some basic stuff */
  842. {MIIM_CONTROL, MIIM_CR_INIT, NULL},
  843. /* Restart Auto Negotiation */
  844. {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
  845. {miim_end,}
  846. },
  847. (struct phy_cmd[]){ /* startup */
  848. /* Status is read once to clear old link state */
  849. {MIIM_STATUS, miim_read, NULL},
  850. /* Auto-negotiate */
  851. {MIIM_STATUS, miim_read, &mii_parse_sr},
  852. /* Read the status */
  853. {MIIM_DM9161_SCSR, miim_read,
  854. &mii_parse_dm9161_scsr},
  855. {miim_end,}
  856. },
  857. (struct phy_cmd[]){ /* shutdown */
  858. {miim_end,}
  859. },
  860. };
  861. uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
  862. {
  863. unsigned int speed;
  864. if (priv->link) {
  865. speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
  866. switch (speed) {
  867. case MIIM_LXT971_SR2_10HDX:
  868. priv->speed = 10;
  869. priv->duplexity = 0;
  870. break;
  871. case MIIM_LXT971_SR2_10FDX:
  872. priv->speed = 10;
  873. priv->duplexity = 1;
  874. break;
  875. case MIIM_LXT971_SR2_100HDX:
  876. priv->speed = 100;
  877. priv->duplexity = 0;
  878. default:
  879. priv->speed = 100;
  880. priv->duplexity = 1;
  881. break;
  882. }
  883. } else {
  884. priv->speed = 0;
  885. priv->duplexity = 0;
  886. }
  887. return 0;
  888. }
  889. static struct phy_info phy_info_lxt971 = {
  890. 0x0001378e,
  891. "LXT971",
  892. 4,
  893. (struct phy_cmd[]){ /* config */
  894. {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
  895. {miim_end,}
  896. },
  897. (struct phy_cmd[]){ /* startup - enable interrupts */
  898. /* { 0x12, 0x00f2, NULL }, */
  899. {MIIM_STATUS, miim_read, NULL},
  900. {MIIM_STATUS, miim_read, &mii_parse_sr},
  901. {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
  902. {miim_end,}
  903. },
  904. (struct phy_cmd[]){ /* shutdown - disable interrupts */
  905. {miim_end,}
  906. },
  907. };
  908. /* Parse the DP83865's link and auto-neg status register for speed and duplex
  909. * information
  910. */
  911. uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
  912. {
  913. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  914. case MIIM_DP83865_SPD_1000:
  915. priv->speed = 1000;
  916. break;
  917. case MIIM_DP83865_SPD_100:
  918. priv->speed = 100;
  919. break;
  920. default:
  921. priv->speed = 10;
  922. break;
  923. }
  924. if (mii_reg & MIIM_DP83865_DPX_FULL)
  925. priv->duplexity = 1;
  926. else
  927. priv->duplexity = 0;
  928. return 0;
  929. }
  930. struct phy_info phy_info_dp83865 = {
  931. 0x20005c7,
  932. "NatSemi DP83865",
  933. 4,
  934. (struct phy_cmd[]){ /* config */
  935. {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
  936. {miim_end,}
  937. },
  938. (struct phy_cmd[]){ /* startup */
  939. /* Status is read once to clear old link state */
  940. {MIIM_STATUS, miim_read, NULL},
  941. /* Auto-negotiate */
  942. {MIIM_STATUS, miim_read, &mii_parse_sr},
  943. /* Read the link and auto-neg status */
  944. {MIIM_DP83865_LANR, miim_read,
  945. &mii_parse_dp83865_lanr},
  946. {miim_end,}
  947. },
  948. (struct phy_cmd[]){ /* shutdown */
  949. {miim_end,}
  950. },
  951. };
  952. struct phy_info *phy_info[] = {
  953. #if 0
  954. &phy_info_cis8201,
  955. #endif
  956. &phy_info_cis8204,
  957. &phy_info_M88E1011S,
  958. &phy_info_M88E1111S,
  959. &phy_info_M88E1145,
  960. &phy_info_dm9161,
  961. &phy_info_lxt971,
  962. &phy_info_VSC8244,
  963. &phy_info_dp83865,
  964. NULL
  965. };
  966. /* Grab the identifier of the device's PHY, and search through
  967. * all of the known PHYs to see if one matches. If so, return
  968. * it, if not, return NULL
  969. */
  970. struct phy_info *get_phy_info(struct eth_device *dev)
  971. {
  972. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  973. uint phy_reg, phy_ID;
  974. int i;
  975. struct phy_info *theInfo = NULL;
  976. /* Grab the bits from PHYIR1, and put them in the upper half */
  977. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  978. phy_ID = (phy_reg & 0xffff) << 16;
  979. /* Grab the bits from PHYIR2, and put them in the lower half */
  980. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  981. phy_ID |= (phy_reg & 0xffff);
  982. /* loop through all the known PHY types, and find one that */
  983. /* matches the ID we read from the PHY. */
  984. for (i = 0; phy_info[i]; i++) {
  985. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
  986. theInfo = phy_info[i];
  987. }
  988. if (theInfo == NULL) {
  989. printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
  990. return NULL;
  991. } else {
  992. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  993. }
  994. return theInfo;
  995. }
  996. /* Execute the given series of commands on the given device's
  997. * PHY, running functions as necessary
  998. */
  999. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1000. {
  1001. int i;
  1002. uint result;
  1003. volatile tsec_t *phyregs = priv->phyregs;
  1004. phyregs->miimcfg = MIIMCFG_RESET;
  1005. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1006. while (phyregs->miimind & MIIMIND_BUSY) ;
  1007. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1008. if (cmd->mii_data == miim_read) {
  1009. result = read_phy_reg(priv, cmd->mii_reg);
  1010. if (cmd->funct != NULL)
  1011. (*(cmd->funct)) (result, priv);
  1012. } else {
  1013. if (cmd->funct != NULL)
  1014. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1015. else
  1016. result = cmd->mii_data;
  1017. write_phy_reg(priv, cmd->mii_reg, result);
  1018. }
  1019. cmd++;
  1020. }
  1021. }
  1022. /* Relocate the function pointers in the phy cmd lists */
  1023. static void relocate_cmds(void)
  1024. {
  1025. struct phy_cmd **cmdlistptr;
  1026. struct phy_cmd *cmd;
  1027. int i, j, k;
  1028. for (i = 0; phy_info[i]; i++) {
  1029. /* First thing's first: relocate the pointers to the
  1030. * PHY command structures (the structs were done) */
  1031. phy_info[i] = (struct phy_info *)((uint) phy_info[i]
  1032. + gd->reloc_off);
  1033. phy_info[i]->name += gd->reloc_off;
  1034. phy_info[i]->config =
  1035. (struct phy_cmd *)((uint) phy_info[i]->config
  1036. + gd->reloc_off);
  1037. phy_info[i]->startup =
  1038. (struct phy_cmd *)((uint) phy_info[i]->startup
  1039. + gd->reloc_off);
  1040. phy_info[i]->shutdown =
  1041. (struct phy_cmd *)((uint) phy_info[i]->shutdown
  1042. + gd->reloc_off);
  1043. cmdlistptr = &phy_info[i]->config;
  1044. j = 0;
  1045. for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
  1046. k = 0;
  1047. for (cmd = *cmdlistptr;
  1048. cmd->mii_reg != miim_end;
  1049. cmd++) {
  1050. /* Only relocate non-NULL pointers */
  1051. if (cmd->funct)
  1052. cmd->funct += gd->reloc_off;
  1053. k++;
  1054. }
  1055. j++;
  1056. }
  1057. }
  1058. relocated = 1;
  1059. }
  1060. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
  1061. && !defined(BITBANGMII)
  1062. struct tsec_private *get_priv_for_phy(unsigned char phyaddr)
  1063. {
  1064. int i;
  1065. for (i = 0; i < MAXCONTROLLERS; i++) {
  1066. if (privlist[i]->phyaddr == phyaddr)
  1067. return privlist[i];
  1068. }
  1069. return NULL;
  1070. }
  1071. /*
  1072. * Read a MII PHY register.
  1073. *
  1074. * Returns:
  1075. * 0 on success
  1076. */
  1077. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1078. unsigned char reg, unsigned short *value)
  1079. {
  1080. unsigned short ret;
  1081. struct tsec_private *priv = get_priv_for_phy(addr);
  1082. if (NULL == priv) {
  1083. printf("Can't read PHY at address %d\n", addr);
  1084. return -1;
  1085. }
  1086. ret = (unsigned short)read_phy_reg(priv, reg);
  1087. *value = ret;
  1088. return 0;
  1089. }
  1090. /*
  1091. * Write a MII PHY register.
  1092. *
  1093. * Returns:
  1094. * 0 on success
  1095. */
  1096. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1097. unsigned char reg, unsigned short value)
  1098. {
  1099. struct tsec_private *priv = get_priv_for_phy(addr);
  1100. if (NULL == priv) {
  1101. printf("Can't write PHY at address %d\n", addr);
  1102. return -1;
  1103. }
  1104. write_phy_reg(priv, reg, value);
  1105. return 0;
  1106. }
  1107. #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1108. && !defined(BITBANGMII) */
  1109. #endif /* CONFIG_TSEC_ENET */