tsec.c 34 KB

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