tsec.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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 (curphy == NULL) {
  262. priv->phyinfo = NULL;
  263. printf("%s: No PHY found\n", dev->name);
  264. return 0;
  265. }
  266. priv->phyinfo = curphy;
  267. phy_run_commands(priv, priv->phyinfo->config);
  268. return 1;
  269. }
  270. /*
  271. * Returns which value to write to the control register.
  272. * For 10/100, the value is slightly different
  273. */
  274. uint mii_cr_init(uint mii_reg, struct tsec_private * priv)
  275. {
  276. if (priv->flags & TSEC_GIGABIT)
  277. return MIIM_CONTROL_INIT;
  278. else
  279. return MIIM_CR_INIT;
  280. }
  281. /* Parse the status register for link, and then do
  282. * auto-negotiation
  283. */
  284. uint mii_parse_sr(uint mii_reg, struct tsec_private * priv)
  285. {
  286. /*
  287. * Wait if PHY is capable of autonegotiation and autonegotiation
  288. * is not complete.
  289. */
  290. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  291. if ((mii_reg & PHY_BMSR_AUTN_ABLE)
  292. && !(mii_reg & PHY_BMSR_AUTN_COMP)) {
  293. int i = 0;
  294. puts("Waiting for PHY auto negotiation to complete");
  295. while (!((mii_reg & PHY_BMSR_AUTN_COMP)
  296. && (mii_reg & MIIM_STATUS_LINK))) {
  297. /*
  298. * Timeout reached ?
  299. */
  300. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  301. puts(" TIMEOUT !\n");
  302. priv->link = 0;
  303. return 0;
  304. }
  305. if ((i++ % 1000) == 0) {
  306. putc('.');
  307. }
  308. udelay(1000); /* 1 ms */
  309. mii_reg = read_phy_reg(priv, MIIM_STATUS);
  310. }
  311. puts(" done\n");
  312. priv->link = 1;
  313. udelay(500000); /* another 500 ms (results in faster booting) */
  314. } else {
  315. priv->link = 1;
  316. }
  317. return 0;
  318. }
  319. /* Parse the 88E1011's status register for speed and duplex
  320. * information
  321. */
  322. uint mii_parse_88E1011_psr(uint mii_reg, struct tsec_private * priv)
  323. {
  324. uint speed;
  325. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  326. if (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
  327. (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
  328. int i = 0;
  329. puts("Waiting for PHY realtime link");
  330. while (!((mii_reg & MIIM_88E1011_PHYSTAT_SPDDONE) &&
  331. (mii_reg & MIIM_88E1011_PHYSTAT_LINK))) {
  332. /*
  333. * Timeout reached ?
  334. */
  335. if (i > PHY_AUTONEGOTIATE_TIMEOUT) {
  336. puts(" TIMEOUT !\n");
  337. priv->link = 0;
  338. break;
  339. }
  340. if ((i++ % 1000) == 0) {
  341. putc('.');
  342. }
  343. udelay(1000); /* 1 ms */
  344. mii_reg = read_phy_reg(priv, MIIM_88E1011_PHY_STATUS);
  345. }
  346. puts(" done\n");
  347. udelay(500000); /* another 500 ms (results in faster booting) */
  348. }
  349. if (mii_reg & MIIM_88E1011_PHYSTAT_DUPLEX)
  350. priv->duplexity = 1;
  351. else
  352. priv->duplexity = 0;
  353. speed = (mii_reg & MIIM_88E1011_PHYSTAT_SPEED);
  354. switch (speed) {
  355. case MIIM_88E1011_PHYSTAT_GBIT:
  356. priv->speed = 1000;
  357. break;
  358. case MIIM_88E1011_PHYSTAT_100:
  359. priv->speed = 100;
  360. break;
  361. default:
  362. priv->speed = 10;
  363. }
  364. return 0;
  365. }
  366. /* Parse the cis8201's status register for speed and duplex
  367. * information
  368. */
  369. uint mii_parse_cis8201(uint mii_reg, struct tsec_private * priv)
  370. {
  371. uint speed;
  372. if (mii_reg & MIIM_CIS8201_AUXCONSTAT_DUPLEX)
  373. priv->duplexity = 1;
  374. else
  375. priv->duplexity = 0;
  376. speed = mii_reg & MIIM_CIS8201_AUXCONSTAT_SPEED;
  377. switch (speed) {
  378. case MIIM_CIS8201_AUXCONSTAT_GBIT:
  379. priv->speed = 1000;
  380. break;
  381. case MIIM_CIS8201_AUXCONSTAT_100:
  382. priv->speed = 100;
  383. break;
  384. default:
  385. priv->speed = 10;
  386. break;
  387. }
  388. return 0;
  389. }
  390. /* Parse the vsc8244's status register for speed and duplex
  391. * information
  392. */
  393. uint mii_parse_vsc8244(uint mii_reg, struct tsec_private * priv)
  394. {
  395. uint speed;
  396. if (mii_reg & MIIM_VSC8244_AUXCONSTAT_DUPLEX)
  397. priv->duplexity = 1;
  398. else
  399. priv->duplexity = 0;
  400. speed = mii_reg & MIIM_VSC8244_AUXCONSTAT_SPEED;
  401. switch (speed) {
  402. case MIIM_VSC8244_AUXCONSTAT_GBIT:
  403. priv->speed = 1000;
  404. break;
  405. case MIIM_VSC8244_AUXCONSTAT_100:
  406. priv->speed = 100;
  407. break;
  408. default:
  409. priv->speed = 10;
  410. break;
  411. }
  412. return 0;
  413. }
  414. /* Parse the DM9161's status register for speed and duplex
  415. * information
  416. */
  417. uint mii_parse_dm9161_scsr(uint mii_reg, struct tsec_private * priv)
  418. {
  419. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_100H))
  420. priv->speed = 100;
  421. else
  422. priv->speed = 10;
  423. if (mii_reg & (MIIM_DM9161_SCSR_100F | MIIM_DM9161_SCSR_10F))
  424. priv->duplexity = 1;
  425. else
  426. priv->duplexity = 0;
  427. return 0;
  428. }
  429. /*
  430. * Hack to write all 4 PHYs with the LED values
  431. */
  432. uint mii_cis8204_fixled(uint mii_reg, struct tsec_private * priv)
  433. {
  434. uint phyid;
  435. volatile tsec_t *regbase = priv->phyregs;
  436. int timeout = 1000000;
  437. for (phyid = 0; phyid < 4; phyid++) {
  438. regbase->miimadd = (phyid << 8) | mii_reg;
  439. regbase->miimcon = MIIM_CIS8204_SLEDCON_INIT;
  440. asm("sync");
  441. timeout = 1000000;
  442. while ((regbase->miimind & MIIMIND_BUSY) && timeout--) ;
  443. }
  444. return MIIM_CIS8204_SLEDCON_INIT;
  445. }
  446. uint mii_cis8204_setmode(uint mii_reg, struct tsec_private * priv)
  447. {
  448. if (priv->flags & TSEC_REDUCED)
  449. return MIIM_CIS8204_EPHYCON_INIT | MIIM_CIS8204_EPHYCON_RGMII;
  450. else
  451. return MIIM_CIS8204_EPHYCON_INIT;
  452. }
  453. /* Initialized required registers to appropriate values, zeroing
  454. * those we don't care about (unless zero is bad, in which case,
  455. * choose a more appropriate value)
  456. */
  457. static void init_registers(volatile tsec_t * regs)
  458. {
  459. /* Clear IEVENT */
  460. regs->ievent = IEVENT_INIT_CLEAR;
  461. regs->imask = IMASK_INIT_CLEAR;
  462. regs->hash.iaddr0 = 0;
  463. regs->hash.iaddr1 = 0;
  464. regs->hash.iaddr2 = 0;
  465. regs->hash.iaddr3 = 0;
  466. regs->hash.iaddr4 = 0;
  467. regs->hash.iaddr5 = 0;
  468. regs->hash.iaddr6 = 0;
  469. regs->hash.iaddr7 = 0;
  470. regs->hash.gaddr0 = 0;
  471. regs->hash.gaddr1 = 0;
  472. regs->hash.gaddr2 = 0;
  473. regs->hash.gaddr3 = 0;
  474. regs->hash.gaddr4 = 0;
  475. regs->hash.gaddr5 = 0;
  476. regs->hash.gaddr6 = 0;
  477. regs->hash.gaddr7 = 0;
  478. regs->rctrl = 0x00000000;
  479. /* Init RMON mib registers */
  480. memset((void *)&(regs->rmon), 0, sizeof(rmon_mib_t));
  481. regs->rmon.cam1 = 0xffffffff;
  482. regs->rmon.cam2 = 0xffffffff;
  483. regs->mrblr = MRBLR_INIT_SETTINGS;
  484. regs->minflr = MINFLR_INIT_SETTINGS;
  485. regs->attr = ATTR_INIT_SETTINGS;
  486. regs->attreli = ATTRELI_INIT_SETTINGS;
  487. }
  488. /* Configure maccfg2 based on negotiated speed and duplex
  489. * reported by PHY handling code
  490. */
  491. static void adjust_link(struct eth_device *dev)
  492. {
  493. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  494. volatile tsec_t *regs = priv->regs;
  495. if (priv->link) {
  496. if (priv->duplexity != 0)
  497. regs->maccfg2 |= MACCFG2_FULL_DUPLEX;
  498. else
  499. regs->maccfg2 &= ~(MACCFG2_FULL_DUPLEX);
  500. switch (priv->speed) {
  501. case 1000:
  502. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  503. | MACCFG2_GMII);
  504. break;
  505. case 100:
  506. case 10:
  507. regs->maccfg2 = ((regs->maccfg2 & ~(MACCFG2_IF))
  508. | MACCFG2_MII);
  509. /* If We're in reduced mode, we need
  510. * to say whether we're 10 or 100 MB.
  511. */
  512. if ((priv->speed == 100)
  513. && (priv->flags & TSEC_REDUCED))
  514. regs->ecntrl |= ECNTRL_R100;
  515. else
  516. regs->ecntrl &= ~(ECNTRL_R100);
  517. break;
  518. default:
  519. printf("%s: Speed was bad\n", dev->name);
  520. break;
  521. }
  522. printf("Speed: %d, %s duplex\n", priv->speed,
  523. (priv->duplexity) ? "full" : "half");
  524. } else {
  525. printf("%s: No link.\n", dev->name);
  526. }
  527. }
  528. /* Set up the buffers and their descriptors, and bring up the
  529. * interface
  530. */
  531. static void startup_tsec(struct eth_device *dev)
  532. {
  533. int i;
  534. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  535. volatile tsec_t *regs = priv->regs;
  536. /* Point to the buffer descriptors */
  537. regs->tbase = (unsigned int)(&rtx.txbd[txIdx]);
  538. regs->rbase = (unsigned int)(&rtx.rxbd[rxIdx]);
  539. /* Initialize the Rx Buffer descriptors */
  540. for (i = 0; i < PKTBUFSRX; i++) {
  541. rtx.rxbd[i].status = RXBD_EMPTY;
  542. rtx.rxbd[i].length = 0;
  543. rtx.rxbd[i].bufPtr = (uint) NetRxPackets[i];
  544. }
  545. rtx.rxbd[PKTBUFSRX - 1].status |= RXBD_WRAP;
  546. /* Initialize the TX Buffer Descriptors */
  547. for (i = 0; i < TX_BUF_CNT; i++) {
  548. rtx.txbd[i].status = 0;
  549. rtx.txbd[i].length = 0;
  550. rtx.txbd[i].bufPtr = 0;
  551. }
  552. rtx.txbd[TX_BUF_CNT - 1].status |= TXBD_WRAP;
  553. /* Start up the PHY */
  554. if(priv->phyinfo)
  555. phy_run_commands(priv, priv->phyinfo->startup);
  556. adjust_link(dev);
  557. /* Enable Transmit and Receive */
  558. regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  559. /* Tell the DMA it is clear to go */
  560. regs->dmactrl |= DMACTRL_INIT_SETTINGS;
  561. regs->tstat = TSTAT_CLEAR_THALT;
  562. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  563. }
  564. /* This returns the status bits of the device. The return value
  565. * is never checked, and this is what the 8260 driver did, so we
  566. * do the same. Presumably, this would be zero if there were no
  567. * errors
  568. */
  569. static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
  570. {
  571. int i;
  572. int result = 0;
  573. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  574. volatile tsec_t *regs = priv->regs;
  575. /* Find an empty buffer descriptor */
  576. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  577. if (i >= TOUT_LOOP) {
  578. debug("%s: tsec: tx buffers full\n", dev->name);
  579. return result;
  580. }
  581. }
  582. rtx.txbd[txIdx].bufPtr = (uint) packet;
  583. rtx.txbd[txIdx].length = length;
  584. rtx.txbd[txIdx].status |=
  585. (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
  586. /* Tell the DMA to go */
  587. regs->tstat = TSTAT_CLEAR_THALT;
  588. /* Wait for buffer to be transmitted */
  589. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  590. if (i >= TOUT_LOOP) {
  591. debug("%s: tsec: tx error\n", dev->name);
  592. return result;
  593. }
  594. }
  595. txIdx = (txIdx + 1) % TX_BUF_CNT;
  596. result = rtx.txbd[txIdx].status & TXBD_STATS;
  597. return result;
  598. }
  599. static int tsec_recv(struct eth_device *dev)
  600. {
  601. int length;
  602. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  603. volatile tsec_t *regs = priv->regs;
  604. while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
  605. length = rtx.rxbd[rxIdx].length;
  606. /* Send the packet up if there were no errors */
  607. if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
  608. NetReceive(NetRxPackets[rxIdx], length - 4);
  609. } else {
  610. printf("Got error %x\n",
  611. (rtx.rxbd[rxIdx].status & RXBD_STATS));
  612. }
  613. rtx.rxbd[rxIdx].length = 0;
  614. /* Set the wrap bit if this is the last element in the list */
  615. rtx.rxbd[rxIdx].status =
  616. RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
  617. rxIdx = (rxIdx + 1) % PKTBUFSRX;
  618. }
  619. if (regs->ievent & IEVENT_BSY) {
  620. regs->ievent = IEVENT_BSY;
  621. regs->rstat = RSTAT_CLEAR_RHALT;
  622. }
  623. return -1;
  624. }
  625. /* Stop the interface */
  626. static void tsec_halt(struct eth_device *dev)
  627. {
  628. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  629. volatile tsec_t *regs = priv->regs;
  630. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  631. regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
  632. while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
  633. regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
  634. /* Shut down the PHY, as needed */
  635. if(priv->phyinfo)
  636. phy_run_commands(priv, priv->phyinfo->shutdown);
  637. }
  638. struct phy_info phy_info_M88E1011S = {
  639. 0x01410c6,
  640. "Marvell 88E1011S",
  641. 4,
  642. (struct phy_cmd[]){ /* config */
  643. /* Reset and configure the PHY */
  644. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  645. {0x1d, 0x1f, NULL},
  646. {0x1e, 0x200c, NULL},
  647. {0x1d, 0x5, NULL},
  648. {0x1e, 0x0, NULL},
  649. {0x1e, 0x100, NULL},
  650. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  651. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  652. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  653. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  654. {miim_end,}
  655. },
  656. (struct phy_cmd[]){ /* startup */
  657. /* Status is read once to clear old link state */
  658. {MIIM_STATUS, miim_read, NULL},
  659. /* Auto-negotiate */
  660. {MIIM_STATUS, miim_read, &mii_parse_sr},
  661. /* Read the status */
  662. {MIIM_88E1011_PHY_STATUS, miim_read,
  663. &mii_parse_88E1011_psr},
  664. {miim_end,}
  665. },
  666. (struct phy_cmd[]){ /* shutdown */
  667. {miim_end,}
  668. },
  669. };
  670. struct phy_info phy_info_M88E1111S = {
  671. 0x01410cc,
  672. "Marvell 88E1111S",
  673. 4,
  674. (struct phy_cmd[]){ /* config */
  675. /* Reset and configure the PHY */
  676. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  677. {0x1d, 0x1f, NULL},
  678. {0x1e, 0x200c, NULL},
  679. {0x1d, 0x5, NULL},
  680. {0x1e, 0x0, NULL},
  681. {0x1e, 0x100, NULL},
  682. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  683. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  684. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  685. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  686. {miim_end,}
  687. },
  688. (struct phy_cmd[]){ /* startup */
  689. /* Status is read once to clear old link state */
  690. {MIIM_STATUS, miim_read, NULL},
  691. /* Auto-negotiate */
  692. {MIIM_STATUS, miim_read, &mii_parse_sr},
  693. /* Read the status */
  694. {MIIM_88E1011_PHY_STATUS, miim_read,
  695. &mii_parse_88E1011_psr},
  696. {miim_end,}
  697. },
  698. (struct phy_cmd[]){ /* shutdown */
  699. {miim_end,}
  700. },
  701. };
  702. static unsigned int m88e1145_setmode(uint mii_reg, struct tsec_private *priv)
  703. {
  704. uint mii_data = read_phy_reg(priv, mii_reg);
  705. /* Setting MIIM_88E1145_PHY_EXT_CR */
  706. if (priv->flags & TSEC_REDUCED)
  707. return mii_data |
  708. MIIM_M88E1145_RGMII_RX_DELAY | MIIM_M88E1145_RGMII_TX_DELAY;
  709. else
  710. return mii_data;
  711. }
  712. static struct phy_info phy_info_M88E1145 = {
  713. 0x01410cd,
  714. "Marvell 88E1145",
  715. 4,
  716. (struct phy_cmd[]){ /* config */
  717. /* Errata E0, E1 */
  718. {29, 0x001b, NULL},
  719. {30, 0x418f, NULL},
  720. {29, 0x0016, NULL},
  721. {30, 0xa2da, NULL},
  722. /* Reset and configure the PHY */
  723. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  724. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  725. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  726. {MIIM_88E1011_PHY_SCR, MIIM_88E1011_PHY_MDI_X_AUTO,
  727. NULL},
  728. {MIIM_88E1145_PHY_EXT_CR, 0, &m88e1145_setmode},
  729. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  730. {MIIM_CONTROL, MIIM_CONTROL_INIT, NULL},
  731. {miim_end,}
  732. },
  733. (struct phy_cmd[]){ /* startup */
  734. /* Status is read once to clear old link state */
  735. {MIIM_STATUS, miim_read, NULL},
  736. /* Auto-negotiate */
  737. {MIIM_STATUS, miim_read, &mii_parse_sr},
  738. {MIIM_88E1111_PHY_LED_CONTROL,
  739. MIIM_88E1111_PHY_LED_DIRECT, NULL},
  740. /* Read the Status */
  741. {MIIM_88E1011_PHY_STATUS, miim_read,
  742. &mii_parse_88E1011_psr},
  743. {miim_end,}
  744. },
  745. (struct phy_cmd[]){ /* shutdown */
  746. {miim_end,}
  747. },
  748. };
  749. struct phy_info phy_info_cis8204 = {
  750. 0x3f11,
  751. "Cicada Cis8204",
  752. 6,
  753. (struct phy_cmd[]){ /* config */
  754. /* Override PHY config settings */
  755. {MIIM_CIS8201_AUX_CONSTAT,
  756. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  757. /* Configure some basic stuff */
  758. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  759. {MIIM_CIS8204_SLED_CON, MIIM_CIS8204_SLEDCON_INIT,
  760. &mii_cis8204_fixled},
  761. {MIIM_CIS8204_EPHY_CON, MIIM_CIS8204_EPHYCON_INIT,
  762. &mii_cis8204_setmode},
  763. {miim_end,}
  764. },
  765. (struct phy_cmd[]){ /* startup */
  766. /* Read the Status (2x to make sure link is right) */
  767. {MIIM_STATUS, miim_read, NULL},
  768. /* Auto-negotiate */
  769. {MIIM_STATUS, miim_read, &mii_parse_sr},
  770. /* Read the status */
  771. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  772. &mii_parse_cis8201},
  773. {miim_end,}
  774. },
  775. (struct phy_cmd[]){ /* shutdown */
  776. {miim_end,}
  777. },
  778. };
  779. /* Cicada 8201 */
  780. struct phy_info phy_info_cis8201 = {
  781. 0xfc41,
  782. "CIS8201",
  783. 4,
  784. (struct phy_cmd[]){ /* config */
  785. /* Override PHY config settings */
  786. {MIIM_CIS8201_AUX_CONSTAT,
  787. MIIM_CIS8201_AUXCONSTAT_INIT, NULL},
  788. /* Set up the interface mode */
  789. {MIIM_CIS8201_EXT_CON1, MIIM_CIS8201_EXTCON1_INIT,
  790. NULL},
  791. /* Configure some basic stuff */
  792. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  793. {miim_end,}
  794. },
  795. (struct phy_cmd[]){ /* startup */
  796. /* Read the Status (2x to make sure link is right) */
  797. {MIIM_STATUS, miim_read, NULL},
  798. /* Auto-negotiate */
  799. {MIIM_STATUS, miim_read, &mii_parse_sr},
  800. /* Read the status */
  801. {MIIM_CIS8201_AUX_CONSTAT, miim_read,
  802. &mii_parse_cis8201},
  803. {miim_end,}
  804. },
  805. (struct phy_cmd[]){ /* shutdown */
  806. {miim_end,}
  807. },
  808. };
  809. struct phy_info phy_info_VSC8244 = {
  810. 0x3f1b,
  811. "Vitesse VSC8244",
  812. 6,
  813. (struct phy_cmd[]){ /* config */
  814. /* Override PHY config settings */
  815. /* Configure some basic stuff */
  816. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  817. {miim_end,}
  818. },
  819. (struct phy_cmd[]){ /* startup */
  820. /* Read the Status (2x to make sure link is right) */
  821. {MIIM_STATUS, miim_read, NULL},
  822. /* Auto-negotiate */
  823. {MIIM_STATUS, miim_read, &mii_parse_sr},
  824. /* Read the status */
  825. {MIIM_VSC8244_AUX_CONSTAT, miim_read,
  826. &mii_parse_vsc8244},
  827. {miim_end,}
  828. },
  829. (struct phy_cmd[]){ /* shutdown */
  830. {miim_end,}
  831. },
  832. };
  833. struct phy_info phy_info_dm9161 = {
  834. 0x0181b88,
  835. "Davicom DM9161E",
  836. 4,
  837. (struct phy_cmd[]){ /* config */
  838. {MIIM_CONTROL, MIIM_DM9161_CR_STOP, NULL},
  839. /* Do not bypass the scrambler/descrambler */
  840. {MIIM_DM9161_SCR, MIIM_DM9161_SCR_INIT, NULL},
  841. /* Clear 10BTCSR to default */
  842. {MIIM_DM9161_10BTCSR, MIIM_DM9161_10BTCSR_INIT,
  843. NULL},
  844. /* Configure some basic stuff */
  845. {MIIM_CONTROL, MIIM_CR_INIT, NULL},
  846. /* Restart Auto Negotiation */
  847. {MIIM_CONTROL, MIIM_DM9161_CR_RSTAN, NULL},
  848. {miim_end,}
  849. },
  850. (struct phy_cmd[]){ /* startup */
  851. /* Status is read once to clear old link state */
  852. {MIIM_STATUS, miim_read, NULL},
  853. /* Auto-negotiate */
  854. {MIIM_STATUS, miim_read, &mii_parse_sr},
  855. /* Read the status */
  856. {MIIM_DM9161_SCSR, miim_read,
  857. &mii_parse_dm9161_scsr},
  858. {miim_end,}
  859. },
  860. (struct phy_cmd[]){ /* shutdown */
  861. {miim_end,}
  862. },
  863. };
  864. uint mii_parse_lxt971_sr2(uint mii_reg, struct tsec_private *priv)
  865. {
  866. unsigned int speed;
  867. if (priv->link) {
  868. speed = mii_reg & MIIM_LXT971_SR2_SPEED_MASK;
  869. switch (speed) {
  870. case MIIM_LXT971_SR2_10HDX:
  871. priv->speed = 10;
  872. priv->duplexity = 0;
  873. break;
  874. case MIIM_LXT971_SR2_10FDX:
  875. priv->speed = 10;
  876. priv->duplexity = 1;
  877. break;
  878. case MIIM_LXT971_SR2_100HDX:
  879. priv->speed = 100;
  880. priv->duplexity = 0;
  881. default:
  882. priv->speed = 100;
  883. priv->duplexity = 1;
  884. break;
  885. }
  886. } else {
  887. priv->speed = 0;
  888. priv->duplexity = 0;
  889. }
  890. return 0;
  891. }
  892. static struct phy_info phy_info_lxt971 = {
  893. 0x0001378e,
  894. "LXT971",
  895. 4,
  896. (struct phy_cmd[]){ /* config */
  897. {MIIM_CR, MIIM_CR_INIT, mii_cr_init}, /* autonegotiate */
  898. {miim_end,}
  899. },
  900. (struct phy_cmd[]){ /* startup - enable interrupts */
  901. /* { 0x12, 0x00f2, NULL }, */
  902. {MIIM_STATUS, miim_read, NULL},
  903. {MIIM_STATUS, miim_read, &mii_parse_sr},
  904. {MIIM_LXT971_SR2, miim_read, &mii_parse_lxt971_sr2},
  905. {miim_end,}
  906. },
  907. (struct phy_cmd[]){ /* shutdown - disable interrupts */
  908. {miim_end,}
  909. },
  910. };
  911. /* Parse the DP83865's link and auto-neg status register for speed and duplex
  912. * information
  913. */
  914. uint mii_parse_dp83865_lanr(uint mii_reg, struct tsec_private *priv)
  915. {
  916. switch (mii_reg & MIIM_DP83865_SPD_MASK) {
  917. case MIIM_DP83865_SPD_1000:
  918. priv->speed = 1000;
  919. break;
  920. case MIIM_DP83865_SPD_100:
  921. priv->speed = 100;
  922. break;
  923. default:
  924. priv->speed = 10;
  925. break;
  926. }
  927. if (mii_reg & MIIM_DP83865_DPX_FULL)
  928. priv->duplexity = 1;
  929. else
  930. priv->duplexity = 0;
  931. return 0;
  932. }
  933. struct phy_info phy_info_dp83865 = {
  934. 0x20005c7,
  935. "NatSemi DP83865",
  936. 4,
  937. (struct phy_cmd[]){ /* config */
  938. {MIIM_CONTROL, MIIM_DP83865_CR_INIT, NULL},
  939. {miim_end,}
  940. },
  941. (struct phy_cmd[]){ /* startup */
  942. /* Status is read once to clear old link state */
  943. {MIIM_STATUS, miim_read, NULL},
  944. /* Auto-negotiate */
  945. {MIIM_STATUS, miim_read, &mii_parse_sr},
  946. /* Read the link and auto-neg status */
  947. {MIIM_DP83865_LANR, miim_read,
  948. &mii_parse_dp83865_lanr},
  949. {miim_end,}
  950. },
  951. (struct phy_cmd[]){ /* shutdown */
  952. {miim_end,}
  953. },
  954. };
  955. struct phy_info *phy_info[] = {
  956. #if 0
  957. &phy_info_cis8201,
  958. #endif
  959. &phy_info_cis8204,
  960. &phy_info_M88E1011S,
  961. &phy_info_M88E1111S,
  962. &phy_info_M88E1145,
  963. &phy_info_dm9161,
  964. &phy_info_lxt971,
  965. &phy_info_VSC8244,
  966. &phy_info_dp83865,
  967. NULL
  968. };
  969. /* Grab the identifier of the device's PHY, and search through
  970. * all of the known PHYs to see if one matches. If so, return
  971. * it, if not, return NULL
  972. */
  973. struct phy_info *get_phy_info(struct eth_device *dev)
  974. {
  975. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  976. uint phy_reg, phy_ID;
  977. int i;
  978. struct phy_info *theInfo = NULL;
  979. /* Grab the bits from PHYIR1, and put them in the upper half */
  980. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  981. phy_ID = (phy_reg & 0xffff) << 16;
  982. /* Grab the bits from PHYIR2, and put them in the lower half */
  983. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  984. phy_ID |= (phy_reg & 0xffff);
  985. /* loop through all the known PHY types, and find one that */
  986. /* matches the ID we read from the PHY. */
  987. for (i = 0; phy_info[i]; i++) {
  988. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
  989. theInfo = phy_info[i];
  990. }
  991. if (theInfo == NULL) {
  992. printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
  993. return NULL;
  994. } else {
  995. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  996. }
  997. return theInfo;
  998. }
  999. /* Execute the given series of commands on the given device's
  1000. * PHY, running functions as necessary
  1001. */
  1002. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1003. {
  1004. int i;
  1005. uint result;
  1006. volatile tsec_t *phyregs = priv->phyregs;
  1007. phyregs->miimcfg = MIIMCFG_RESET;
  1008. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1009. while (phyregs->miimind & MIIMIND_BUSY) ;
  1010. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1011. if (cmd->mii_data == miim_read) {
  1012. result = read_phy_reg(priv, cmd->mii_reg);
  1013. if (cmd->funct != NULL)
  1014. (*(cmd->funct)) (result, priv);
  1015. } else {
  1016. if (cmd->funct != NULL)
  1017. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1018. else
  1019. result = cmd->mii_data;
  1020. write_phy_reg(priv, cmd->mii_reg, result);
  1021. }
  1022. cmd++;
  1023. }
  1024. }
  1025. /* Relocate the function pointers in the phy cmd lists */
  1026. static void relocate_cmds(void)
  1027. {
  1028. struct phy_cmd **cmdlistptr;
  1029. struct phy_cmd *cmd;
  1030. int i, j, k;
  1031. for (i = 0; phy_info[i]; i++) {
  1032. /* First thing's first: relocate the pointers to the
  1033. * PHY command structures (the structs were done) */
  1034. phy_info[i] = (struct phy_info *)((uint) phy_info[i]
  1035. + gd->reloc_off);
  1036. phy_info[i]->name += gd->reloc_off;
  1037. phy_info[i]->config =
  1038. (struct phy_cmd *)((uint) phy_info[i]->config
  1039. + gd->reloc_off);
  1040. phy_info[i]->startup =
  1041. (struct phy_cmd *)((uint) phy_info[i]->startup
  1042. + gd->reloc_off);
  1043. phy_info[i]->shutdown =
  1044. (struct phy_cmd *)((uint) phy_info[i]->shutdown
  1045. + gd->reloc_off);
  1046. cmdlistptr = &phy_info[i]->config;
  1047. j = 0;
  1048. for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
  1049. k = 0;
  1050. for (cmd = *cmdlistptr;
  1051. cmd->mii_reg != miim_end;
  1052. cmd++) {
  1053. /* Only relocate non-NULL pointers */
  1054. if (cmd->funct)
  1055. cmd->funct += gd->reloc_off;
  1056. k++;
  1057. }
  1058. j++;
  1059. }
  1060. }
  1061. relocated = 1;
  1062. }
  1063. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
  1064. && !defined(BITBANGMII)
  1065. struct tsec_private *get_priv_for_phy(unsigned char phyaddr)
  1066. {
  1067. int i;
  1068. for (i = 0; i < MAXCONTROLLERS; i++) {
  1069. if (privlist[i]->phyaddr == phyaddr)
  1070. return privlist[i];
  1071. }
  1072. return NULL;
  1073. }
  1074. /*
  1075. * Read a MII PHY register.
  1076. *
  1077. * Returns:
  1078. * 0 on success
  1079. */
  1080. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1081. unsigned char reg, unsigned short *value)
  1082. {
  1083. unsigned short ret;
  1084. struct tsec_private *priv = get_priv_for_phy(addr);
  1085. if (NULL == priv) {
  1086. printf("Can't read PHY at address %d\n", addr);
  1087. return -1;
  1088. }
  1089. ret = (unsigned short)read_phy_reg(priv, reg);
  1090. *value = ret;
  1091. return 0;
  1092. }
  1093. /*
  1094. * Write a MII PHY register.
  1095. *
  1096. * Returns:
  1097. * 0 on success
  1098. */
  1099. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1100. unsigned char reg, unsigned short value)
  1101. {
  1102. struct tsec_private *priv = get_priv_for_phy(addr);
  1103. if (NULL == priv) {
  1104. printf("Can't write PHY at address %d\n", addr);
  1105. return -1;
  1106. }
  1107. write_phy_reg(priv, reg, value);
  1108. return 0;
  1109. }
  1110. #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1111. && !defined(BITBANGMII) */
  1112. #endif /* CONFIG_TSEC_ENET */