tsec.c 32 KB

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