mac-fec.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Freescale Ethernet controllers
  3. *
  4. * Copyright (c) 2005 Intracom S.A.
  5. * by Pantelis Antoniou <panto@intracom.gr>
  6. *
  7. * 2005 (c) MontaVista Software, Inc.
  8. * Vitaly Bordug <vbordug@ru.mvista.com>
  9. *
  10. * This file is licensed under the terms of the GNU General Public License
  11. * version 2. This program is licensed "as is" without any warranty of any
  12. * kind, whether express or implied.
  13. */
  14. #include <linux/config.h>
  15. #include <linux/module.h>
  16. #include <linux/kernel.h>
  17. #include <linux/types.h>
  18. #include <linux/sched.h>
  19. #include <linux/string.h>
  20. #include <linux/ptrace.h>
  21. #include <linux/errno.h>
  22. #include <linux/ioport.h>
  23. #include <linux/slab.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/pci.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/mii.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/bitops.h>
  35. #include <linux/fs.h>
  36. #include <asm/irq.h>
  37. #include <asm/uaccess.h>
  38. #ifdef CONFIG_8xx
  39. #include <asm/8xx_immap.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/mpc8xx.h>
  42. #include <asm/commproc.h>
  43. #endif
  44. #include "fs_enet.h"
  45. /*************************************************/
  46. #if defined(CONFIG_CPM1)
  47. /* for a CPM1 __raw_xxx's are sufficient */
  48. #define __fs_out32(addr, x) __raw_writel(x, addr)
  49. #define __fs_out16(addr, x) __raw_writew(x, addr)
  50. #define __fs_in32(addr) __raw_readl(addr)
  51. #define __fs_in16(addr) __raw_readw(addr)
  52. #else
  53. /* for others play it safe */
  54. #define __fs_out32(addr, x) out_be32(addr, x)
  55. #define __fs_out16(addr, x) out_be16(addr, x)
  56. #define __fs_in32(addr) in_be32(addr)
  57. #define __fs_in16(addr) in_be16(addr)
  58. #endif
  59. /* write */
  60. #define FW(_fecp, _reg, _v) __fs_out32(&(_fecp)->fec_ ## _reg, (_v))
  61. /* read */
  62. #define FR(_fecp, _reg) __fs_in32(&(_fecp)->fec_ ## _reg)
  63. /* set bits */
  64. #define FS(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) | (_v))
  65. /* clear bits */
  66. #define FC(_fecp, _reg, _v) FW(_fecp, _reg, FR(_fecp, _reg) & ~(_v))
  67. /* CRC polynomium used by the FEC for the multicast group filtering */
  68. #define FEC_CRC_POLY 0x04C11DB7
  69. #define FEC_MAX_MULTICAST_ADDRS 64
  70. /* Interrupt events/masks.
  71. */
  72. #define FEC_ENET_HBERR 0x80000000U /* Heartbeat error */
  73. #define FEC_ENET_BABR 0x40000000U /* Babbling receiver */
  74. #define FEC_ENET_BABT 0x20000000U /* Babbling transmitter */
  75. #define FEC_ENET_GRA 0x10000000U /* Graceful stop complete */
  76. #define FEC_ENET_TXF 0x08000000U /* Full frame transmitted */
  77. #define FEC_ENET_TXB 0x04000000U /* A buffer was transmitted */
  78. #define FEC_ENET_RXF 0x02000000U /* Full frame received */
  79. #define FEC_ENET_RXB 0x01000000U /* A buffer was received */
  80. #define FEC_ENET_MII 0x00800000U /* MII interrupt */
  81. #define FEC_ENET_EBERR 0x00400000U /* SDMA bus error */
  82. #define FEC_ECNTRL_PINMUX 0x00000004
  83. #define FEC_ECNTRL_ETHER_EN 0x00000002
  84. #define FEC_ECNTRL_RESET 0x00000001
  85. #define FEC_RCNTRL_BC_REJ 0x00000010
  86. #define FEC_RCNTRL_PROM 0x00000008
  87. #define FEC_RCNTRL_MII_MODE 0x00000004
  88. #define FEC_RCNTRL_DRT 0x00000002
  89. #define FEC_RCNTRL_LOOP 0x00000001
  90. #define FEC_TCNTRL_FDEN 0x00000004
  91. #define FEC_TCNTRL_HBC 0x00000002
  92. #define FEC_TCNTRL_GTS 0x00000001
  93. /* Make MII read/write commands for the FEC.
  94. */
  95. #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
  96. #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
  97. #define mk_mii_end 0
  98. #define FEC_MII_LOOPS 10000
  99. /*
  100. * Delay to wait for FEC reset command to complete (in us)
  101. */
  102. #define FEC_RESET_DELAY 50
  103. static int whack_reset(fec_t * fecp)
  104. {
  105. int i;
  106. FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_RESET);
  107. for (i = 0; i < FEC_RESET_DELAY; i++) {
  108. if ((FR(fecp, ecntrl) & FEC_ECNTRL_RESET) == 0)
  109. return 0; /* OK */
  110. udelay(1);
  111. }
  112. return -1;
  113. }
  114. static int do_pd_setup(struct fs_enet_private *fep)
  115. {
  116. struct platform_device *pdev = to_platform_device(fep->dev);
  117. struct resource *r;
  118. /* Fill out IRQ field */
  119. fep->interrupt = platform_get_irq_byname(pdev,"interrupt");
  120. r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  121. fep->fec.fecp =(void*)r->start;
  122. if(fep->fec.fecp == NULL)
  123. return -EINVAL;
  124. return 0;
  125. }
  126. #define FEC_NAPI_RX_EVENT_MSK (FEC_ENET_RXF | FEC_ENET_RXB)
  127. #define FEC_RX_EVENT (FEC_ENET_RXF)
  128. #define FEC_TX_EVENT (FEC_ENET_TXF)
  129. #define FEC_ERR_EVENT_MSK (FEC_ENET_HBERR | FEC_ENET_BABR | \
  130. FEC_ENET_BABT | FEC_ENET_EBERR)
  131. static int setup_data(struct net_device *dev)
  132. {
  133. struct fs_enet_private *fep = netdev_priv(dev);
  134. if (do_pd_setup(fep) != 0)
  135. return -EINVAL;
  136. fep->fec.hthi = 0;
  137. fep->fec.htlo = 0;
  138. fep->ev_napi_rx = FEC_NAPI_RX_EVENT_MSK;
  139. fep->ev_rx = FEC_RX_EVENT;
  140. fep->ev_tx = FEC_TX_EVENT;
  141. fep->ev_err = FEC_ERR_EVENT_MSK;
  142. return 0;
  143. }
  144. static int allocate_bd(struct net_device *dev)
  145. {
  146. struct fs_enet_private *fep = netdev_priv(dev);
  147. const struct fs_platform_info *fpi = fep->fpi;
  148. fep->ring_base = dma_alloc_coherent(fep->dev,
  149. (fpi->tx_ring + fpi->rx_ring) *
  150. sizeof(cbd_t), &fep->ring_mem_addr,
  151. GFP_KERNEL);
  152. if (fep->ring_base == NULL)
  153. return -ENOMEM;
  154. return 0;
  155. }
  156. static void free_bd(struct net_device *dev)
  157. {
  158. struct fs_enet_private *fep = netdev_priv(dev);
  159. const struct fs_platform_info *fpi = fep->fpi;
  160. if(fep->ring_base)
  161. dma_free_coherent(fep->dev, (fpi->tx_ring + fpi->rx_ring)
  162. * sizeof(cbd_t),
  163. fep->ring_base,
  164. fep->ring_mem_addr);
  165. }
  166. static void cleanup_data(struct net_device *dev)
  167. {
  168. /* nothing */
  169. }
  170. static void set_promiscuous_mode(struct net_device *dev)
  171. {
  172. struct fs_enet_private *fep = netdev_priv(dev);
  173. fec_t *fecp = fep->fec.fecp;
  174. FS(fecp, r_cntrl, FEC_RCNTRL_PROM);
  175. }
  176. static void set_multicast_start(struct net_device *dev)
  177. {
  178. struct fs_enet_private *fep = netdev_priv(dev);
  179. fep->fec.hthi = 0;
  180. fep->fec.htlo = 0;
  181. }
  182. static void set_multicast_one(struct net_device *dev, const u8 *mac)
  183. {
  184. struct fs_enet_private *fep = netdev_priv(dev);
  185. int temp, hash_index, i, j;
  186. u32 crc, csrVal;
  187. u8 byte, msb;
  188. crc = 0xffffffff;
  189. for (i = 0; i < 6; i++) {
  190. byte = mac[i];
  191. for (j = 0; j < 8; j++) {
  192. msb = crc >> 31;
  193. crc <<= 1;
  194. if (msb ^ (byte & 0x1))
  195. crc ^= FEC_CRC_POLY;
  196. byte >>= 1;
  197. }
  198. }
  199. temp = (crc & 0x3f) >> 1;
  200. hash_index = ((temp & 0x01) << 4) |
  201. ((temp & 0x02) << 2) |
  202. ((temp & 0x04)) |
  203. ((temp & 0x08) >> 2) |
  204. ((temp & 0x10) >> 4);
  205. csrVal = 1 << hash_index;
  206. if (crc & 1)
  207. fep->fec.hthi |= csrVal;
  208. else
  209. fep->fec.htlo |= csrVal;
  210. }
  211. static void set_multicast_finish(struct net_device *dev)
  212. {
  213. struct fs_enet_private *fep = netdev_priv(dev);
  214. fec_t *fecp = fep->fec.fecp;
  215. /* if all multi or too many multicasts; just enable all */
  216. if ((dev->flags & IFF_ALLMULTI) != 0 ||
  217. dev->mc_count > FEC_MAX_MULTICAST_ADDRS) {
  218. fep->fec.hthi = 0xffffffffU;
  219. fep->fec.htlo = 0xffffffffU;
  220. }
  221. FC(fecp, r_cntrl, FEC_RCNTRL_PROM);
  222. FW(fecp, hash_table_high, fep->fec.hthi);
  223. FW(fecp, hash_table_low, fep->fec.htlo);
  224. }
  225. static void set_multicast_list(struct net_device *dev)
  226. {
  227. struct dev_mc_list *pmc;
  228. if ((dev->flags & IFF_PROMISC) == 0) {
  229. set_multicast_start(dev);
  230. for (pmc = dev->mc_list; pmc != NULL; pmc = pmc->next)
  231. set_multicast_one(dev, pmc->dmi_addr);
  232. set_multicast_finish(dev);
  233. } else
  234. set_promiscuous_mode(dev);
  235. }
  236. static void restart(struct net_device *dev)
  237. {
  238. #ifdef CONFIG_DUET
  239. immap_t *immap = fs_enet_immap;
  240. u32 cptr;
  241. #endif
  242. struct fs_enet_private *fep = netdev_priv(dev);
  243. fec_t *fecp = fep->fec.fecp;
  244. const struct fs_platform_info *fpi = fep->fpi;
  245. dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
  246. int r;
  247. u32 addrhi, addrlo;
  248. r = whack_reset(fep->fec.fecp);
  249. if (r != 0)
  250. printk(KERN_ERR DRV_MODULE_NAME
  251. ": %s FEC Reset FAILED!\n", dev->name);
  252. /*
  253. * Set station address.
  254. */
  255. addrhi = ((u32) dev->dev_addr[0] << 24) |
  256. ((u32) dev->dev_addr[1] << 16) |
  257. ((u32) dev->dev_addr[2] << 8) |
  258. (u32) dev->dev_addr[3];
  259. addrlo = ((u32) dev->dev_addr[4] << 24) |
  260. ((u32) dev->dev_addr[5] << 16);
  261. FW(fecp, addr_low, addrhi);
  262. FW(fecp, addr_high, addrlo);
  263. /*
  264. * Reset all multicast.
  265. */
  266. FW(fecp, hash_table_high, fep->fec.hthi);
  267. FW(fecp, hash_table_low, fep->fec.htlo);
  268. /*
  269. * Set maximum receive buffer size.
  270. */
  271. FW(fecp, r_buff_size, PKT_MAXBLR_SIZE);
  272. FW(fecp, r_hash, PKT_MAXBUF_SIZE);
  273. /* get physical address */
  274. rx_bd_base_phys = fep->ring_mem_addr;
  275. tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
  276. /*
  277. * Set receive and transmit descriptor base.
  278. */
  279. FW(fecp, r_des_start, rx_bd_base_phys);
  280. FW(fecp, x_des_start, tx_bd_base_phys);
  281. fs_init_bds(dev);
  282. /*
  283. * Enable big endian and don't care about SDMA FC.
  284. */
  285. FW(fecp, fun_code, 0x78000000);
  286. /*
  287. * Set MII speed.
  288. */
  289. FW(fecp, mii_speed, fep->mii_bus->fec.mii_speed);
  290. /*
  291. * Clear any outstanding interrupt.
  292. */
  293. FW(fecp, ievent, 0xffc0);
  294. FW(fecp, ivec, (fep->interrupt / 2) << 29);
  295. /*
  296. * adjust to speed (only for DUET & RMII)
  297. */
  298. #ifdef CONFIG_DUET
  299. if (fpi->use_rmii) {
  300. cptr = in_be32(&immap->im_cpm.cp_cptr);
  301. switch (fs_get_fec_index(fpi->fs_no)) {
  302. case 0:
  303. cptr |= 0x100;
  304. if (fep->speed == 10)
  305. cptr |= 0x0000010;
  306. else if (fep->speed == 100)
  307. cptr &= ~0x0000010;
  308. break;
  309. case 1:
  310. cptr |= 0x80;
  311. if (fep->speed == 10)
  312. cptr |= 0x0000008;
  313. else if (fep->speed == 100)
  314. cptr &= ~0x0000008;
  315. break;
  316. default:
  317. BUG(); /* should never happen */
  318. break;
  319. }
  320. out_be32(&immap->im_cpm.cp_cptr, cptr);
  321. }
  322. #endif
  323. FW(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
  324. /*
  325. * adjust to duplex mode
  326. */
  327. if (fep->duplex) {
  328. FC(fecp, r_cntrl, FEC_RCNTRL_DRT);
  329. FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */
  330. } else {
  331. FS(fecp, r_cntrl, FEC_RCNTRL_DRT);
  332. FC(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD disable */
  333. }
  334. /*
  335. * Enable interrupts we wish to service.
  336. */
  337. FW(fecp, imask, FEC_ENET_TXF | FEC_ENET_TXB |
  338. FEC_ENET_RXF | FEC_ENET_RXB);
  339. /*
  340. * And last, enable the transmit and receive processing.
  341. */
  342. FW(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
  343. FW(fecp, r_des_active, 0x01000000);
  344. }
  345. static void stop(struct net_device *dev)
  346. {
  347. struct fs_enet_private *fep = netdev_priv(dev);
  348. fec_t *fecp = fep->fec.fecp;
  349. struct fs_enet_mii_bus *bus = fep->mii_bus;
  350. const struct fs_mii_bus_info *bi = bus->bus_info;
  351. int i;
  352. if ((FR(fecp, ecntrl) & FEC_ECNTRL_ETHER_EN) == 0)
  353. return; /* already down */
  354. FW(fecp, x_cntrl, 0x01); /* Graceful transmit stop */
  355. for (i = 0; ((FR(fecp, ievent) & 0x10000000) == 0) &&
  356. i < FEC_RESET_DELAY; i++)
  357. udelay(1);
  358. if (i == FEC_RESET_DELAY)
  359. printk(KERN_WARNING DRV_MODULE_NAME
  360. ": %s FEC timeout on graceful transmit stop\n",
  361. dev->name);
  362. /*
  363. * Disable FEC. Let only MII interrupts.
  364. */
  365. FW(fecp, imask, 0);
  366. FC(fecp, ecntrl, FEC_ECNTRL_ETHER_EN);
  367. fs_cleanup_bds(dev);
  368. /* shut down FEC1? that's where the mii bus is */
  369. if (fep->fec.idx == 0 && bus->refs > 1 && bi->method == fsmii_fec) {
  370. FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
  371. FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
  372. FW(fecp, ievent, FEC_ENET_MII);
  373. FW(fecp, mii_speed, bus->fec.mii_speed);
  374. }
  375. }
  376. static void pre_request_irq(struct net_device *dev, int irq)
  377. {
  378. immap_t *immap = fs_enet_immap;
  379. u32 siel;
  380. /* SIU interrupt */
  381. if (irq >= SIU_IRQ0 && irq < SIU_LEVEL7) {
  382. siel = in_be32(&immap->im_siu_conf.sc_siel);
  383. if ((irq & 1) == 0)
  384. siel |= (0x80000000 >> irq);
  385. else
  386. siel &= ~(0x80000000 >> (irq & ~1));
  387. out_be32(&immap->im_siu_conf.sc_siel, siel);
  388. }
  389. }
  390. static void post_free_irq(struct net_device *dev, int irq)
  391. {
  392. /* nothing */
  393. }
  394. static void napi_clear_rx_event(struct net_device *dev)
  395. {
  396. struct fs_enet_private *fep = netdev_priv(dev);
  397. fec_t *fecp = fep->fec.fecp;
  398. FW(fecp, ievent, FEC_NAPI_RX_EVENT_MSK);
  399. }
  400. static void napi_enable_rx(struct net_device *dev)
  401. {
  402. struct fs_enet_private *fep = netdev_priv(dev);
  403. fec_t *fecp = fep->fec.fecp;
  404. FS(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
  405. }
  406. static void napi_disable_rx(struct net_device *dev)
  407. {
  408. struct fs_enet_private *fep = netdev_priv(dev);
  409. fec_t *fecp = fep->fec.fecp;
  410. FC(fecp, imask, FEC_NAPI_RX_EVENT_MSK);
  411. }
  412. static void rx_bd_done(struct net_device *dev)
  413. {
  414. struct fs_enet_private *fep = netdev_priv(dev);
  415. fec_t *fecp = fep->fec.fecp;
  416. FW(fecp, r_des_active, 0x01000000);
  417. }
  418. static void tx_kickstart(struct net_device *dev)
  419. {
  420. struct fs_enet_private *fep = netdev_priv(dev);
  421. fec_t *fecp = fep->fec.fecp;
  422. FW(fecp, x_des_active, 0x01000000);
  423. }
  424. static u32 get_int_events(struct net_device *dev)
  425. {
  426. struct fs_enet_private *fep = netdev_priv(dev);
  427. fec_t *fecp = fep->fec.fecp;
  428. return FR(fecp, ievent) & FR(fecp, imask);
  429. }
  430. static void clear_int_events(struct net_device *dev, u32 int_events)
  431. {
  432. struct fs_enet_private *fep = netdev_priv(dev);
  433. fec_t *fecp = fep->fec.fecp;
  434. FW(fecp, ievent, int_events);
  435. }
  436. static void ev_error(struct net_device *dev, u32 int_events)
  437. {
  438. printk(KERN_WARNING DRV_MODULE_NAME
  439. ": %s FEC ERROR(s) 0x%x\n", dev->name, int_events);
  440. }
  441. int get_regs(struct net_device *dev, void *p, int *sizep)
  442. {
  443. struct fs_enet_private *fep = netdev_priv(dev);
  444. if (*sizep < sizeof(fec_t))
  445. return -EINVAL;
  446. memcpy_fromio(p, fep->fec.fecp, sizeof(fec_t));
  447. return 0;
  448. }
  449. int get_regs_len(struct net_device *dev)
  450. {
  451. return sizeof(fec_t);
  452. }
  453. void tx_restart(struct net_device *dev)
  454. {
  455. /* nothing */
  456. }
  457. /*************************************************************************/
  458. const struct fs_ops fs_fec_ops = {
  459. .setup_data = setup_data,
  460. .cleanup_data = cleanup_data,
  461. .set_multicast_list = set_multicast_list,
  462. .restart = restart,
  463. .stop = stop,
  464. .pre_request_irq = pre_request_irq,
  465. .post_free_irq = post_free_irq,
  466. .napi_clear_rx_event = napi_clear_rx_event,
  467. .napi_enable_rx = napi_enable_rx,
  468. .napi_disable_rx = napi_disable_rx,
  469. .rx_bd_done = rx_bd_done,
  470. .tx_kickstart = tx_kickstart,
  471. .get_int_events = get_int_events,
  472. .clear_int_events = clear_int_events,
  473. .ev_error = ev_error,
  474. .get_regs = get_regs,
  475. .get_regs_len = get_regs_len,
  476. .tx_restart = tx_restart,
  477. .allocate_bd = allocate_bd,
  478. .free_bd = free_bd,
  479. };
  480. /***********************************************************************/
  481. static int mii_read(struct fs_enet_mii_bus *bus, int phy_id, int location)
  482. {
  483. fec_t *fecp = bus->fec.fecp;
  484. int i, ret = -1;
  485. if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
  486. BUG();
  487. /* Add PHY address to register command. */
  488. FW(fecp, mii_data, (phy_id << 23) | mk_mii_read(location));
  489. for (i = 0; i < FEC_MII_LOOPS; i++)
  490. if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
  491. break;
  492. if (i < FEC_MII_LOOPS) {
  493. FW(fecp, ievent, FEC_ENET_MII);
  494. ret = FR(fecp, mii_data) & 0xffff;
  495. }
  496. return ret;
  497. }
  498. static void mii_write(struct fs_enet_mii_bus *bus, int phy_id, int location, int value)
  499. {
  500. fec_t *fecp = bus->fec.fecp;
  501. int i;
  502. /* this must never happen */
  503. if ((FR(fecp, r_cntrl) & FEC_RCNTRL_MII_MODE) == 0)
  504. BUG();
  505. /* Add PHY address to register command. */
  506. FW(fecp, mii_data, (phy_id << 23) | mk_mii_write(location, value));
  507. for (i = 0; i < FEC_MII_LOOPS; i++)
  508. if ((FR(fecp, ievent) & FEC_ENET_MII) != 0)
  509. break;
  510. if (i < FEC_MII_LOOPS)
  511. FW(fecp, ievent, FEC_ENET_MII);
  512. }
  513. int fs_mii_fec_init(struct fs_enet_mii_bus *bus)
  514. {
  515. bd_t *bd = (bd_t *)__res;
  516. const struct fs_mii_bus_info *bi = bus->bus_info;
  517. fec_t *fecp;
  518. if (bi->id != 0)
  519. return -1;
  520. bus->fec.fecp = &((immap_t *)fs_enet_immap)->im_cpm.cp_fec;
  521. bus->fec.mii_speed = ((((bd->bi_intfreq + 4999999) / 2500000) / 2)
  522. & 0x3F) << 1;
  523. fecp = bus->fec.fecp;
  524. FS(fecp, r_cntrl, FEC_RCNTRL_MII_MODE); /* MII enable */
  525. FS(fecp, ecntrl, FEC_ECNTRL_PINMUX | FEC_ECNTRL_ETHER_EN);
  526. FW(fecp, ievent, FEC_ENET_MII);
  527. FW(fecp, mii_speed, bus->fec.mii_speed);
  528. bus->mii_read = mii_read;
  529. bus->mii_write = mii_write;
  530. return 0;
  531. }