mac-fcc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * FCC driver for Motorola MPC82xx (PQ2).
  3. *
  4. * Copyright (c) 2003 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/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/types.h>
  17. #include <linux/string.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/errno.h>
  20. #include <linux/ioport.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/delay.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/skbuff.h>
  26. #include <linux/spinlock.h>
  27. #include <linux/mii.h>
  28. #include <linux/ethtool.h>
  29. #include <linux/bitops.h>
  30. #include <linux/fs.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/phy.h>
  33. #include <linux/of_address.h>
  34. #include <linux/of_device.h>
  35. #include <linux/of_irq.h>
  36. #include <linux/gfp.h>
  37. #include <asm/immap_cpm2.h>
  38. #include <asm/mpc8260.h>
  39. #include <asm/cpm2.h>
  40. #include <asm/pgtable.h>
  41. #include <asm/irq.h>
  42. #include <asm/uaccess.h>
  43. #include "fs_enet.h"
  44. /*************************************************/
  45. /* FCC access macros */
  46. /* write, read, set bits, clear bits */
  47. #define W32(_p, _m, _v) out_be32(&(_p)->_m, (_v))
  48. #define R32(_p, _m) in_be32(&(_p)->_m)
  49. #define S32(_p, _m, _v) W32(_p, _m, R32(_p, _m) | (_v))
  50. #define C32(_p, _m, _v) W32(_p, _m, R32(_p, _m) & ~(_v))
  51. #define W16(_p, _m, _v) out_be16(&(_p)->_m, (_v))
  52. #define R16(_p, _m) in_be16(&(_p)->_m)
  53. #define S16(_p, _m, _v) W16(_p, _m, R16(_p, _m) | (_v))
  54. #define C16(_p, _m, _v) W16(_p, _m, R16(_p, _m) & ~(_v))
  55. #define W8(_p, _m, _v) out_8(&(_p)->_m, (_v))
  56. #define R8(_p, _m) in_8(&(_p)->_m)
  57. #define S8(_p, _m, _v) W8(_p, _m, R8(_p, _m) | (_v))
  58. #define C8(_p, _m, _v) W8(_p, _m, R8(_p, _m) & ~(_v))
  59. /*************************************************/
  60. #define FCC_MAX_MULTICAST_ADDRS 64
  61. #define mk_mii_read(REG) (0x60020000 | ((REG & 0x1f) << 18))
  62. #define mk_mii_write(REG, VAL) (0x50020000 | ((REG & 0x1f) << 18) | (VAL & 0xffff))
  63. #define mk_mii_end 0
  64. #define MAX_CR_CMD_LOOPS 10000
  65. static inline int fcc_cr_cmd(struct fs_enet_private *fep, u32 op)
  66. {
  67. const struct fs_platform_info *fpi = fep->fpi;
  68. return cpm_command(fpi->cp_command, op);
  69. }
  70. static int do_pd_setup(struct fs_enet_private *fep)
  71. {
  72. struct platform_device *ofdev = to_platform_device(fep->dev);
  73. struct fs_platform_info *fpi = fep->fpi;
  74. int ret = -EINVAL;
  75. fep->interrupt = irq_of_parse_and_map(ofdev->dev.of_node, 0);
  76. if (fep->interrupt == NO_IRQ)
  77. goto out;
  78. fep->fcc.fccp = of_iomap(ofdev->dev.of_node, 0);
  79. if (!fep->fcc.fccp)
  80. goto out;
  81. fep->fcc.ep = of_iomap(ofdev->dev.of_node, 1);
  82. if (!fep->fcc.ep)
  83. goto out_fccp;
  84. fep->fcc.fcccp = of_iomap(ofdev->dev.of_node, 2);
  85. if (!fep->fcc.fcccp)
  86. goto out_ep;
  87. fep->fcc.mem = (void __iomem *)cpm2_immr;
  88. fpi->dpram_offset = cpm_dpalloc(128, 32);
  89. if (IS_ERR_VALUE(fpi->dpram_offset)) {
  90. ret = fpi->dpram_offset;
  91. goto out_fcccp;
  92. }
  93. return 0;
  94. out_fcccp:
  95. iounmap(fep->fcc.fcccp);
  96. out_ep:
  97. iounmap(fep->fcc.ep);
  98. out_fccp:
  99. iounmap(fep->fcc.fccp);
  100. out:
  101. return ret;
  102. }
  103. #define FCC_NAPI_RX_EVENT_MSK (FCC_ENET_RXF | FCC_ENET_RXB)
  104. #define FCC_NAPI_TX_EVENT_MSK (FCC_ENET_TXB)
  105. #define FCC_RX_EVENT (FCC_ENET_RXF)
  106. #define FCC_TX_EVENT (FCC_ENET_TXB)
  107. #define FCC_ERR_EVENT_MSK (FCC_ENET_TXE)
  108. static int setup_data(struct net_device *dev)
  109. {
  110. struct fs_enet_private *fep = netdev_priv(dev);
  111. if (do_pd_setup(fep) != 0)
  112. return -EINVAL;
  113. fep->ev_napi_rx = FCC_NAPI_RX_EVENT_MSK;
  114. fep->ev_napi_tx = FCC_NAPI_TX_EVENT_MSK;
  115. fep->ev_rx = FCC_RX_EVENT;
  116. fep->ev_tx = FCC_TX_EVENT;
  117. fep->ev_err = FCC_ERR_EVENT_MSK;
  118. return 0;
  119. }
  120. static int allocate_bd(struct net_device *dev)
  121. {
  122. struct fs_enet_private *fep = netdev_priv(dev);
  123. const struct fs_platform_info *fpi = fep->fpi;
  124. fep->ring_base = (void __iomem __force *)dma_alloc_coherent(fep->dev,
  125. (fpi->tx_ring + fpi->rx_ring) *
  126. sizeof(cbd_t), &fep->ring_mem_addr,
  127. GFP_KERNEL);
  128. if (fep->ring_base == NULL)
  129. return -ENOMEM;
  130. return 0;
  131. }
  132. static void free_bd(struct net_device *dev)
  133. {
  134. struct fs_enet_private *fep = netdev_priv(dev);
  135. const struct fs_platform_info *fpi = fep->fpi;
  136. if (fep->ring_base)
  137. dma_free_coherent(fep->dev,
  138. (fpi->tx_ring + fpi->rx_ring) * sizeof(cbd_t),
  139. (void __force *)fep->ring_base, fep->ring_mem_addr);
  140. }
  141. static void cleanup_data(struct net_device *dev)
  142. {
  143. /* nothing */
  144. }
  145. static void set_promiscuous_mode(struct net_device *dev)
  146. {
  147. struct fs_enet_private *fep = netdev_priv(dev);
  148. fcc_t __iomem *fccp = fep->fcc.fccp;
  149. S32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
  150. }
  151. static void set_multicast_start(struct net_device *dev)
  152. {
  153. struct fs_enet_private *fep = netdev_priv(dev);
  154. fcc_enet_t __iomem *ep = fep->fcc.ep;
  155. W32(ep, fen_gaddrh, 0);
  156. W32(ep, fen_gaddrl, 0);
  157. }
  158. static void set_multicast_one(struct net_device *dev, const u8 *mac)
  159. {
  160. struct fs_enet_private *fep = netdev_priv(dev);
  161. fcc_enet_t __iomem *ep = fep->fcc.ep;
  162. u16 taddrh, taddrm, taddrl;
  163. taddrh = ((u16)mac[5] << 8) | mac[4];
  164. taddrm = ((u16)mac[3] << 8) | mac[2];
  165. taddrl = ((u16)mac[1] << 8) | mac[0];
  166. W16(ep, fen_taddrh, taddrh);
  167. W16(ep, fen_taddrm, taddrm);
  168. W16(ep, fen_taddrl, taddrl);
  169. fcc_cr_cmd(fep, CPM_CR_SET_GADDR);
  170. }
  171. static void set_multicast_finish(struct net_device *dev)
  172. {
  173. struct fs_enet_private *fep = netdev_priv(dev);
  174. fcc_t __iomem *fccp = fep->fcc.fccp;
  175. fcc_enet_t __iomem *ep = fep->fcc.ep;
  176. /* clear promiscuous always */
  177. C32(fccp, fcc_fpsmr, FCC_PSMR_PRO);
  178. /* if all multi or too many multicasts; just enable all */
  179. if ((dev->flags & IFF_ALLMULTI) != 0 ||
  180. netdev_mc_count(dev) > FCC_MAX_MULTICAST_ADDRS) {
  181. W32(ep, fen_gaddrh, 0xffffffff);
  182. W32(ep, fen_gaddrl, 0xffffffff);
  183. }
  184. /* read back */
  185. fep->fcc.gaddrh = R32(ep, fen_gaddrh);
  186. fep->fcc.gaddrl = R32(ep, fen_gaddrl);
  187. }
  188. static void set_multicast_list(struct net_device *dev)
  189. {
  190. struct netdev_hw_addr *ha;
  191. if ((dev->flags & IFF_PROMISC) == 0) {
  192. set_multicast_start(dev);
  193. netdev_for_each_mc_addr(ha, dev)
  194. set_multicast_one(dev, ha->addr);
  195. set_multicast_finish(dev);
  196. } else
  197. set_promiscuous_mode(dev);
  198. }
  199. static void restart(struct net_device *dev)
  200. {
  201. struct fs_enet_private *fep = netdev_priv(dev);
  202. const struct fs_platform_info *fpi = fep->fpi;
  203. fcc_t __iomem *fccp = fep->fcc.fccp;
  204. fcc_c_t __iomem *fcccp = fep->fcc.fcccp;
  205. fcc_enet_t __iomem *ep = fep->fcc.ep;
  206. dma_addr_t rx_bd_base_phys, tx_bd_base_phys;
  207. u16 paddrh, paddrm, paddrl;
  208. const unsigned char *mac;
  209. int i;
  210. C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
  211. /* clear everything (slow & steady does it) */
  212. for (i = 0; i < sizeof(*ep); i++)
  213. out_8((u8 __iomem *)ep + i, 0);
  214. /* get physical address */
  215. rx_bd_base_phys = fep->ring_mem_addr;
  216. tx_bd_base_phys = rx_bd_base_phys + sizeof(cbd_t) * fpi->rx_ring;
  217. /* point to bds */
  218. W32(ep, fen_genfcc.fcc_rbase, rx_bd_base_phys);
  219. W32(ep, fen_genfcc.fcc_tbase, tx_bd_base_phys);
  220. /* Set maximum bytes per receive buffer.
  221. * It must be a multiple of 32.
  222. */
  223. W16(ep, fen_genfcc.fcc_mrblr, PKT_MAXBLR_SIZE);
  224. W32(ep, fen_genfcc.fcc_rstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
  225. W32(ep, fen_genfcc.fcc_tstate, (CPMFCR_GBL | CPMFCR_EB) << 24);
  226. /* Allocate space in the reserved FCC area of DPRAM for the
  227. * internal buffers. No one uses this space (yet), so we
  228. * can do this. Later, we will add resource management for
  229. * this area.
  230. */
  231. W16(ep, fen_genfcc.fcc_riptr, fpi->dpram_offset);
  232. W16(ep, fen_genfcc.fcc_tiptr, fpi->dpram_offset + 32);
  233. W16(ep, fen_padptr, fpi->dpram_offset + 64);
  234. /* fill with special symbol... */
  235. memset_io(fep->fcc.mem + fpi->dpram_offset + 64, 0x88, 32);
  236. W32(ep, fen_genfcc.fcc_rbptr, 0);
  237. W32(ep, fen_genfcc.fcc_tbptr, 0);
  238. W32(ep, fen_genfcc.fcc_rcrc, 0);
  239. W32(ep, fen_genfcc.fcc_tcrc, 0);
  240. W16(ep, fen_genfcc.fcc_res1, 0);
  241. W32(ep, fen_genfcc.fcc_res2, 0);
  242. /* no CAM */
  243. W32(ep, fen_camptr, 0);
  244. /* Set CRC preset and mask */
  245. W32(ep, fen_cmask, 0xdebb20e3);
  246. W32(ep, fen_cpres, 0xffffffff);
  247. W32(ep, fen_crcec, 0); /* CRC Error counter */
  248. W32(ep, fen_alec, 0); /* alignment error counter */
  249. W32(ep, fen_disfc, 0); /* discard frame counter */
  250. W16(ep, fen_retlim, 15); /* Retry limit threshold */
  251. W16(ep, fen_pper, 0); /* Normal persistence */
  252. /* set group address */
  253. W32(ep, fen_gaddrh, fep->fcc.gaddrh);
  254. W32(ep, fen_gaddrl, fep->fcc.gaddrh);
  255. /* Clear hash filter tables */
  256. W32(ep, fen_iaddrh, 0);
  257. W32(ep, fen_iaddrl, 0);
  258. /* Clear the Out-of-sequence TxBD */
  259. W16(ep, fen_tfcstat, 0);
  260. W16(ep, fen_tfclen, 0);
  261. W32(ep, fen_tfcptr, 0);
  262. W16(ep, fen_mflr, PKT_MAXBUF_SIZE); /* maximum frame length register */
  263. W16(ep, fen_minflr, PKT_MINBUF_SIZE); /* minimum frame length register */
  264. /* set address */
  265. mac = dev->dev_addr;
  266. paddrh = ((u16)mac[5] << 8) | mac[4];
  267. paddrm = ((u16)mac[3] << 8) | mac[2];
  268. paddrl = ((u16)mac[1] << 8) | mac[0];
  269. W16(ep, fen_paddrh, paddrh);
  270. W16(ep, fen_paddrm, paddrm);
  271. W16(ep, fen_paddrl, paddrl);
  272. W16(ep, fen_taddrh, 0);
  273. W16(ep, fen_taddrm, 0);
  274. W16(ep, fen_taddrl, 0);
  275. W16(ep, fen_maxd1, 1520); /* maximum DMA1 length */
  276. W16(ep, fen_maxd2, 1520); /* maximum DMA2 length */
  277. /* Clear stat counters, in case we ever enable RMON */
  278. W32(ep, fen_octc, 0);
  279. W32(ep, fen_colc, 0);
  280. W32(ep, fen_broc, 0);
  281. W32(ep, fen_mulc, 0);
  282. W32(ep, fen_uspc, 0);
  283. W32(ep, fen_frgc, 0);
  284. W32(ep, fen_ospc, 0);
  285. W32(ep, fen_jbrc, 0);
  286. W32(ep, fen_p64c, 0);
  287. W32(ep, fen_p65c, 0);
  288. W32(ep, fen_p128c, 0);
  289. W32(ep, fen_p256c, 0);
  290. W32(ep, fen_p512c, 0);
  291. W32(ep, fen_p1024c, 0);
  292. W16(ep, fen_rfthr, 0); /* Suggested by manual */
  293. W16(ep, fen_rfcnt, 0);
  294. W16(ep, fen_cftype, 0);
  295. fs_init_bds(dev);
  296. /* adjust to speed (for RMII mode) */
  297. if (fpi->use_rmii) {
  298. if (fep->phydev->speed == 100)
  299. C8(fcccp, fcc_gfemr, 0x20);
  300. else
  301. S8(fcccp, fcc_gfemr, 0x20);
  302. }
  303. fcc_cr_cmd(fep, CPM_CR_INIT_TRX);
  304. /* clear events */
  305. W16(fccp, fcc_fcce, 0xffff);
  306. /* Enable interrupts we wish to service */
  307. W16(fccp, fcc_fccm, FCC_ENET_TXE | FCC_ENET_RXF | FCC_ENET_TXB);
  308. /* Set GFMR to enable Ethernet operating mode */
  309. W32(fccp, fcc_gfmr, FCC_GFMR_TCI | FCC_GFMR_MODE_ENET);
  310. /* set sync/delimiters */
  311. W16(fccp, fcc_fdsr, 0xd555);
  312. W32(fccp, fcc_fpsmr, FCC_PSMR_ENCRC);
  313. if (fpi->use_rmii)
  314. S32(fccp, fcc_fpsmr, FCC_PSMR_RMII);
  315. /* adjust to duplex mode */
  316. if (fep->phydev->duplex)
  317. S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
  318. else
  319. C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB);
  320. /* Restore multicast and promiscuous settings */
  321. set_multicast_list(dev);
  322. S32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
  323. }
  324. static void stop(struct net_device *dev)
  325. {
  326. struct fs_enet_private *fep = netdev_priv(dev);
  327. fcc_t __iomem *fccp = fep->fcc.fccp;
  328. /* stop ethernet */
  329. C32(fccp, fcc_gfmr, FCC_GFMR_ENR | FCC_GFMR_ENT);
  330. /* clear events */
  331. W16(fccp, fcc_fcce, 0xffff);
  332. /* clear interrupt mask */
  333. W16(fccp, fcc_fccm, 0);
  334. fs_cleanup_bds(dev);
  335. }
  336. static void napi_clear_rx_event(struct net_device *dev)
  337. {
  338. struct fs_enet_private *fep = netdev_priv(dev);
  339. fcc_t __iomem *fccp = fep->fcc.fccp;
  340. W16(fccp, fcc_fcce, FCC_NAPI_RX_EVENT_MSK);
  341. }
  342. static void napi_enable_rx(struct net_device *dev)
  343. {
  344. struct fs_enet_private *fep = netdev_priv(dev);
  345. fcc_t __iomem *fccp = fep->fcc.fccp;
  346. S16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
  347. }
  348. static void napi_disable_rx(struct net_device *dev)
  349. {
  350. struct fs_enet_private *fep = netdev_priv(dev);
  351. fcc_t __iomem *fccp = fep->fcc.fccp;
  352. C16(fccp, fcc_fccm, FCC_NAPI_RX_EVENT_MSK);
  353. }
  354. static void napi_clear_tx_event(struct net_device *dev)
  355. {
  356. struct fs_enet_private *fep = netdev_priv(dev);
  357. fcc_t __iomem *fccp = fep->fcc.fccp;
  358. W16(fccp, fcc_fcce, FCC_NAPI_TX_EVENT_MSK);
  359. }
  360. static void napi_enable_tx(struct net_device *dev)
  361. {
  362. struct fs_enet_private *fep = netdev_priv(dev);
  363. fcc_t __iomem *fccp = fep->fcc.fccp;
  364. S16(fccp, fcc_fccm, FCC_NAPI_TX_EVENT_MSK);
  365. }
  366. static void napi_disable_tx(struct net_device *dev)
  367. {
  368. struct fs_enet_private *fep = netdev_priv(dev);
  369. fcc_t __iomem *fccp = fep->fcc.fccp;
  370. C16(fccp, fcc_fccm, FCC_NAPI_TX_EVENT_MSK);
  371. }
  372. static void rx_bd_done(struct net_device *dev)
  373. {
  374. /* nothing */
  375. }
  376. static void tx_kickstart(struct net_device *dev)
  377. {
  378. struct fs_enet_private *fep = netdev_priv(dev);
  379. fcc_t __iomem *fccp = fep->fcc.fccp;
  380. S16(fccp, fcc_ftodr, 0x8000);
  381. }
  382. static u32 get_int_events(struct net_device *dev)
  383. {
  384. struct fs_enet_private *fep = netdev_priv(dev);
  385. fcc_t __iomem *fccp = fep->fcc.fccp;
  386. return (u32)R16(fccp, fcc_fcce);
  387. }
  388. static void clear_int_events(struct net_device *dev, u32 int_events)
  389. {
  390. struct fs_enet_private *fep = netdev_priv(dev);
  391. fcc_t __iomem *fccp = fep->fcc.fccp;
  392. W16(fccp, fcc_fcce, int_events & 0xffff);
  393. }
  394. static void ev_error(struct net_device *dev, u32 int_events)
  395. {
  396. struct fs_enet_private *fep = netdev_priv(dev);
  397. dev_warn(fep->dev, "FS_ENET ERROR(s) 0x%x\n", int_events);
  398. }
  399. static int get_regs(struct net_device *dev, void *p, int *sizep)
  400. {
  401. struct fs_enet_private *fep = netdev_priv(dev);
  402. if (*sizep < sizeof(fcc_t) + sizeof(fcc_enet_t) + 1)
  403. return -EINVAL;
  404. memcpy_fromio(p, fep->fcc.fccp, sizeof(fcc_t));
  405. p = (char *)p + sizeof(fcc_t);
  406. memcpy_fromio(p, fep->fcc.ep, sizeof(fcc_enet_t));
  407. p = (char *)p + sizeof(fcc_enet_t);
  408. memcpy_fromio(p, fep->fcc.fcccp, 1);
  409. return 0;
  410. }
  411. static int get_regs_len(struct net_device *dev)
  412. {
  413. return sizeof(fcc_t) + sizeof(fcc_enet_t) + 1;
  414. }
  415. /* Some transmit errors cause the transmitter to shut
  416. * down. We now issue a restart transmit.
  417. * Also, to workaround 8260 device erratum CPM37, we must
  418. * disable and then re-enable the transmitterfollowing a
  419. * Late Collision, Underrun, or Retry Limit error.
  420. * In addition, tbptr may point beyond BDs beyond still marked
  421. * as ready due to internal pipelining, so we need to look back
  422. * through the BDs and adjust tbptr to point to the last BD
  423. * marked as ready. This may result in some buffers being
  424. * retransmitted.
  425. */
  426. static void tx_restart(struct net_device *dev)
  427. {
  428. struct fs_enet_private *fep = netdev_priv(dev);
  429. fcc_t __iomem *fccp = fep->fcc.fccp;
  430. const struct fs_platform_info *fpi = fep->fpi;
  431. fcc_enet_t __iomem *ep = fep->fcc.ep;
  432. cbd_t __iomem *curr_tbptr;
  433. cbd_t __iomem *recheck_bd;
  434. cbd_t __iomem *prev_bd;
  435. cbd_t __iomem *last_tx_bd;
  436. last_tx_bd = fep->tx_bd_base + ((fpi->tx_ring - 1) * sizeof(cbd_t));
  437. /* get the current bd held in TBPTR and scan back from this point */
  438. recheck_bd = curr_tbptr = (cbd_t __iomem *)
  439. ((R32(ep, fen_genfcc.fcc_tbptr) - fep->ring_mem_addr) +
  440. fep->ring_base);
  441. prev_bd = (recheck_bd == fep->tx_bd_base) ? last_tx_bd : recheck_bd - 1;
  442. /* Move through the bds in reverse, look for the earliest buffer
  443. * that is not ready. Adjust TBPTR to the following buffer */
  444. while ((CBDR_SC(prev_bd) & BD_ENET_TX_READY) != 0) {
  445. /* Go back one buffer */
  446. recheck_bd = prev_bd;
  447. /* update the previous buffer */
  448. prev_bd = (prev_bd == fep->tx_bd_base) ? last_tx_bd : prev_bd - 1;
  449. /* We should never see all bds marked as ready, check anyway */
  450. if (recheck_bd == curr_tbptr)
  451. break;
  452. }
  453. /* Now update the TBPTR and dirty flag to the current buffer */
  454. W32(ep, fen_genfcc.fcc_tbptr,
  455. (uint) (((void *)recheck_bd - fep->ring_base) +
  456. fep->ring_mem_addr));
  457. fep->dirty_tx = recheck_bd;
  458. C32(fccp, fcc_gfmr, FCC_GFMR_ENT);
  459. udelay(10);
  460. S32(fccp, fcc_gfmr, FCC_GFMR_ENT);
  461. fcc_cr_cmd(fep, CPM_CR_RESTART_TX);
  462. }
  463. /*************************************************************************/
  464. const struct fs_ops fs_fcc_ops = {
  465. .setup_data = setup_data,
  466. .cleanup_data = cleanup_data,
  467. .set_multicast_list = set_multicast_list,
  468. .restart = restart,
  469. .stop = stop,
  470. .napi_clear_rx_event = napi_clear_rx_event,
  471. .napi_enable_rx = napi_enable_rx,
  472. .napi_disable_rx = napi_disable_rx,
  473. .napi_clear_tx_event = napi_clear_tx_event,
  474. .napi_enable_tx = napi_enable_tx,
  475. .napi_disable_tx = napi_disable_tx,
  476. .rx_bd_done = rx_bd_done,
  477. .tx_kickstart = tx_kickstart,
  478. .get_int_events = get_int_events,
  479. .clear_int_events = clear_int_events,
  480. .ev_error = ev_error,
  481. .get_regs = get_regs,
  482. .get_regs_len = get_regs_len,
  483. .tx_restart = tx_restart,
  484. .allocate_bd = allocate_bd,
  485. .free_bd = free_bd,
  486. };