tsec.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  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. /* Set R100 bit in all modes although
  510. * it is only used in RGMII mode
  511. */
  512. if (priv->speed == 100)
  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. if(priv->phyinfo)
  554. phy_run_commands(priv, priv->phyinfo->startup);
  555. adjust_link(dev);
  556. /* Enable Transmit and Receive */
  557. regs->maccfg1 |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  558. /* Tell the DMA it is clear to go */
  559. regs->dmactrl |= DMACTRL_INIT_SETTINGS;
  560. regs->tstat = TSTAT_CLEAR_THALT;
  561. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  562. }
  563. /* This returns the status bits of the device. The return value
  564. * is never checked, and this is what the 8260 driver did, so we
  565. * do the same. Presumably, this would be zero if there were no
  566. * errors
  567. */
  568. static int tsec_send(struct eth_device *dev, volatile void *packet, int length)
  569. {
  570. int i;
  571. int result = 0;
  572. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  573. volatile tsec_t *regs = priv->regs;
  574. /* Find an empty buffer descriptor */
  575. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  576. if (i >= TOUT_LOOP) {
  577. debug("%s: tsec: tx buffers full\n", dev->name);
  578. return result;
  579. }
  580. }
  581. rtx.txbd[txIdx].bufPtr = (uint) packet;
  582. rtx.txbd[txIdx].length = length;
  583. rtx.txbd[txIdx].status |=
  584. (TXBD_READY | TXBD_LAST | TXBD_CRC | TXBD_INTERRUPT);
  585. /* Tell the DMA to go */
  586. regs->tstat = TSTAT_CLEAR_THALT;
  587. /* Wait for buffer to be transmitted */
  588. for (i = 0; rtx.txbd[txIdx].status & TXBD_READY; i++) {
  589. if (i >= TOUT_LOOP) {
  590. debug("%s: tsec: tx error\n", dev->name);
  591. return result;
  592. }
  593. }
  594. txIdx = (txIdx + 1) % TX_BUF_CNT;
  595. result = rtx.txbd[txIdx].status & TXBD_STATS;
  596. return result;
  597. }
  598. static int tsec_recv(struct eth_device *dev)
  599. {
  600. int length;
  601. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  602. volatile tsec_t *regs = priv->regs;
  603. while (!(rtx.rxbd[rxIdx].status & RXBD_EMPTY)) {
  604. length = rtx.rxbd[rxIdx].length;
  605. /* Send the packet up if there were no errors */
  606. if (!(rtx.rxbd[rxIdx].status & RXBD_STATS)) {
  607. NetReceive(NetRxPackets[rxIdx], length - 4);
  608. } else {
  609. printf("Got error %x\n",
  610. (rtx.rxbd[rxIdx].status & RXBD_STATS));
  611. }
  612. rtx.rxbd[rxIdx].length = 0;
  613. /* Set the wrap bit if this is the last element in the list */
  614. rtx.rxbd[rxIdx].status =
  615. RXBD_EMPTY | (((rxIdx + 1) == PKTBUFSRX) ? RXBD_WRAP : 0);
  616. rxIdx = (rxIdx + 1) % PKTBUFSRX;
  617. }
  618. if (regs->ievent & IEVENT_BSY) {
  619. regs->ievent = IEVENT_BSY;
  620. regs->rstat = RSTAT_CLEAR_RHALT;
  621. }
  622. return -1;
  623. }
  624. /* Stop the interface */
  625. static void tsec_halt(struct eth_device *dev)
  626. {
  627. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  628. volatile tsec_t *regs = priv->regs;
  629. regs->dmactrl &= ~(DMACTRL_GRS | DMACTRL_GTS);
  630. regs->dmactrl |= (DMACTRL_GRS | DMACTRL_GTS);
  631. while (!(regs->ievent & (IEVENT_GRSC | IEVENT_GTSC))) ;
  632. regs->maccfg1 &= ~(MACCFG1_TX_EN | MACCFG1_RX_EN);
  633. /* Shut down the PHY, as needed */
  634. if(priv->phyinfo)
  635. phy_run_commands(priv, priv->phyinfo->shutdown);
  636. }
  637. struct phy_info phy_info_M88E1011S = {
  638. 0x01410c6,
  639. "Marvell 88E1011S",
  640. 4,
  641. (struct phy_cmd[]){ /* config */
  642. /* Reset and configure the PHY */
  643. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  644. {0x1d, 0x1f, NULL},
  645. {0x1e, 0x200c, NULL},
  646. {0x1d, 0x5, NULL},
  647. {0x1e, 0x0, NULL},
  648. {0x1e, 0x100, NULL},
  649. {MIIM_GBIT_CONTROL, MIIM_GBIT_CONTROL_INIT, NULL},
  650. {MIIM_ANAR, MIIM_ANAR_INIT, NULL},
  651. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  652. {MIIM_CONTROL, MIIM_CONTROL_INIT, &mii_cr_init},
  653. {miim_end,}
  654. },
  655. (struct phy_cmd[]){ /* startup */
  656. /* Status is read once to clear old link state */
  657. {MIIM_STATUS, miim_read, NULL},
  658. /* Auto-negotiate */
  659. {MIIM_STATUS, miim_read, &mii_parse_sr},
  660. /* Read the status */
  661. {MIIM_88E1011_PHY_STATUS, miim_read,
  662. &mii_parse_88E1011_psr},
  663. {miim_end,}
  664. },
  665. (struct phy_cmd[]){ /* shutdown */
  666. {miim_end,}
  667. },
  668. };
  669. struct phy_info phy_info_M88E1111S = {
  670. 0x01410cc,
  671. "Marvell 88E1111S",
  672. 4,
  673. (struct phy_cmd[]){ /* config */
  674. /* Reset and configure the PHY */
  675. {MIIM_CONTROL, MIIM_CONTROL_RESET, NULL},
  676. {0x1d, 0x1f, NULL},
  677. {0x1e, 0x200c, NULL},
  678. {0x1d, 0x5, NULL},
  679. {0x1e, 0x0, NULL},
  680. {0x1e, 0x100, NULL},
  681. {0x14, 0x0cd2, NULL}, /* Delay RGMII TX and RX */
  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. &phy_info_cis8204,
  957. &phy_info_cis8201,
  958. &phy_info_M88E1011S,
  959. &phy_info_M88E1111S,
  960. &phy_info_M88E1145,
  961. &phy_info_dm9161,
  962. &phy_info_lxt971,
  963. &phy_info_VSC8244,
  964. &phy_info_dp83865,
  965. NULL
  966. };
  967. /* Grab the identifier of the device's PHY, and search through
  968. * all of the known PHYs to see if one matches. If so, return
  969. * it, if not, return NULL
  970. */
  971. struct phy_info *get_phy_info(struct eth_device *dev)
  972. {
  973. struct tsec_private *priv = (struct tsec_private *)dev->priv;
  974. uint phy_reg, phy_ID;
  975. int i;
  976. struct phy_info *theInfo = NULL;
  977. /* Grab the bits from PHYIR1, and put them in the upper half */
  978. phy_reg = read_phy_reg(priv, MIIM_PHYIR1);
  979. phy_ID = (phy_reg & 0xffff) << 16;
  980. /* Grab the bits from PHYIR2, and put them in the lower half */
  981. phy_reg = read_phy_reg(priv, MIIM_PHYIR2);
  982. phy_ID |= (phy_reg & 0xffff);
  983. /* loop through all the known PHY types, and find one that */
  984. /* matches the ID we read from the PHY. */
  985. for (i = 0; phy_info[i]; i++) {
  986. if (phy_info[i]->id == (phy_ID >> phy_info[i]->shift))
  987. theInfo = phy_info[i];
  988. }
  989. if (theInfo == NULL) {
  990. printf("%s: PHY id %x is not supported!\n", dev->name, phy_ID);
  991. return NULL;
  992. } else {
  993. debug("%s: PHY is %s (%x)\n", dev->name, theInfo->name, phy_ID);
  994. }
  995. return theInfo;
  996. }
  997. /* Execute the given series of commands on the given device's
  998. * PHY, running functions as necessary
  999. */
  1000. void phy_run_commands(struct tsec_private *priv, struct phy_cmd *cmd)
  1001. {
  1002. int i;
  1003. uint result;
  1004. volatile tsec_t *phyregs = priv->phyregs;
  1005. phyregs->miimcfg = MIIMCFG_RESET;
  1006. phyregs->miimcfg = MIIMCFG_INIT_VALUE;
  1007. while (phyregs->miimind & MIIMIND_BUSY) ;
  1008. for (i = 0; cmd->mii_reg != miim_end; i++) {
  1009. if (cmd->mii_data == miim_read) {
  1010. result = read_phy_reg(priv, cmd->mii_reg);
  1011. if (cmd->funct != NULL)
  1012. (*(cmd->funct)) (result, priv);
  1013. } else {
  1014. if (cmd->funct != NULL)
  1015. result = (*(cmd->funct)) (cmd->mii_reg, priv);
  1016. else
  1017. result = cmd->mii_data;
  1018. write_phy_reg(priv, cmd->mii_reg, result);
  1019. }
  1020. cmd++;
  1021. }
  1022. }
  1023. /* Relocate the function pointers in the phy cmd lists */
  1024. static void relocate_cmds(void)
  1025. {
  1026. struct phy_cmd **cmdlistptr;
  1027. struct phy_cmd *cmd;
  1028. int i, j, k;
  1029. for (i = 0; phy_info[i]; i++) {
  1030. /* First thing's first: relocate the pointers to the
  1031. * PHY command structures (the structs were done) */
  1032. phy_info[i] = (struct phy_info *)((uint) phy_info[i]
  1033. + gd->reloc_off);
  1034. phy_info[i]->name += gd->reloc_off;
  1035. phy_info[i]->config =
  1036. (struct phy_cmd *)((uint) phy_info[i]->config
  1037. + gd->reloc_off);
  1038. phy_info[i]->startup =
  1039. (struct phy_cmd *)((uint) phy_info[i]->startup
  1040. + gd->reloc_off);
  1041. phy_info[i]->shutdown =
  1042. (struct phy_cmd *)((uint) phy_info[i]->shutdown
  1043. + gd->reloc_off);
  1044. cmdlistptr = &phy_info[i]->config;
  1045. j = 0;
  1046. for (; cmdlistptr <= &phy_info[i]->shutdown; cmdlistptr++) {
  1047. k = 0;
  1048. for (cmd = *cmdlistptr;
  1049. cmd->mii_reg != miim_end;
  1050. cmd++) {
  1051. /* Only relocate non-NULL pointers */
  1052. if (cmd->funct)
  1053. cmd->funct += gd->reloc_off;
  1054. k++;
  1055. }
  1056. j++;
  1057. }
  1058. }
  1059. relocated = 1;
  1060. }
  1061. #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) \
  1062. && !defined(BITBANGMII)
  1063. struct tsec_private *get_priv_for_phy(unsigned char phyaddr)
  1064. {
  1065. int i;
  1066. for (i = 0; i < MAXCONTROLLERS; i++) {
  1067. if (privlist[i]->phyaddr == phyaddr)
  1068. return privlist[i];
  1069. }
  1070. return NULL;
  1071. }
  1072. /*
  1073. * Read a MII PHY register.
  1074. *
  1075. * Returns:
  1076. * 0 on success
  1077. */
  1078. static int tsec_miiphy_read(char *devname, unsigned char addr,
  1079. unsigned char reg, unsigned short *value)
  1080. {
  1081. unsigned short ret;
  1082. struct tsec_private *priv = get_priv_for_phy(addr);
  1083. if (NULL == priv) {
  1084. printf("Can't read PHY at address %d\n", addr);
  1085. return -1;
  1086. }
  1087. ret = (unsigned short)read_phy_reg(priv, reg);
  1088. *value = ret;
  1089. return 0;
  1090. }
  1091. /*
  1092. * Write a MII PHY register.
  1093. *
  1094. * Returns:
  1095. * 0 on success
  1096. */
  1097. static int tsec_miiphy_write(char *devname, unsigned char addr,
  1098. unsigned char reg, unsigned short value)
  1099. {
  1100. struct tsec_private *priv = get_priv_for_phy(addr);
  1101. if (NULL == priv) {
  1102. printf("Can't write PHY at address %d\n", addr);
  1103. return -1;
  1104. }
  1105. write_phy_reg(priv, reg, value);
  1106. return 0;
  1107. }
  1108. #endif /* defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
  1109. && !defined(BITBANGMII) */
  1110. #endif /* CONFIG_TSEC_ENET */