mtu3_qmu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * mtu3_qmu.c - Queue Management Unit driver for device controller
  4. *
  5. * Copyright (C) 2016 MediaTek Inc.
  6. *
  7. * Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
  8. */
  9. /*
  10. * Queue Management Unit (QMU) is designed to unload SW effort
  11. * to serve DMA interrupts.
  12. * By preparing General Purpose Descriptor (GPD) and Buffer Descriptor (BD),
  13. * SW links data buffers and triggers QMU to send / receive data to
  14. * host / from device at a time.
  15. * And now only GPD is supported.
  16. *
  17. * For more detailed information, please refer to QMU Programming Guide
  18. */
  19. #include <linux/dmapool.h>
  20. #include <linux/iopoll.h>
  21. #include "mtu3.h"
  22. #define QMU_CHECKSUM_LEN 16
  23. #define GPD_FLAGS_HWO BIT(0)
  24. #define GPD_FLAGS_BDP BIT(1)
  25. #define GPD_FLAGS_BPS BIT(2)
  26. #define GPD_FLAGS_IOC BIT(7)
  27. #define GPD_EXT_FLAG_ZLP BIT(5)
  28. #define GPD_EXT_NGP(x) (((x) & 0xf) << 4)
  29. #define GPD_EXT_BUF(x) (((x) & 0xf) << 0)
  30. #define HILO_GEN64(hi, lo) (((u64)(hi) << 32) + (lo))
  31. #define HILO_DMA(hi, lo) \
  32. ((dma_addr_t)HILO_GEN64((le32_to_cpu(hi)), (le32_to_cpu(lo))))
  33. static dma_addr_t read_txq_cur_addr(void __iomem *mbase, u8 epnum)
  34. {
  35. u32 txcpr;
  36. u32 txhiar;
  37. txcpr = mtu3_readl(mbase, USB_QMU_TQCPR(epnum));
  38. txhiar = mtu3_readl(mbase, USB_QMU_TQHIAR(epnum));
  39. return HILO_DMA(QMU_CUR_GPD_ADDR_HI(txhiar), txcpr);
  40. }
  41. static dma_addr_t read_rxq_cur_addr(void __iomem *mbase, u8 epnum)
  42. {
  43. u32 rxcpr;
  44. u32 rxhiar;
  45. rxcpr = mtu3_readl(mbase, USB_QMU_RQCPR(epnum));
  46. rxhiar = mtu3_readl(mbase, USB_QMU_RQHIAR(epnum));
  47. return HILO_DMA(QMU_CUR_GPD_ADDR_HI(rxhiar), rxcpr);
  48. }
  49. static void write_txq_start_addr(void __iomem *mbase, u8 epnum, dma_addr_t dma)
  50. {
  51. u32 tqhiar;
  52. mtu3_writel(mbase, USB_QMU_TQSAR(epnum),
  53. cpu_to_le32(lower_32_bits(dma)));
  54. tqhiar = mtu3_readl(mbase, USB_QMU_TQHIAR(epnum));
  55. tqhiar &= ~QMU_START_ADDR_HI_MSK;
  56. tqhiar |= QMU_START_ADDR_HI(upper_32_bits(dma));
  57. mtu3_writel(mbase, USB_QMU_TQHIAR(epnum), tqhiar);
  58. }
  59. static void write_rxq_start_addr(void __iomem *mbase, u8 epnum, dma_addr_t dma)
  60. {
  61. u32 rqhiar;
  62. mtu3_writel(mbase, USB_QMU_RQSAR(epnum),
  63. cpu_to_le32(lower_32_bits(dma)));
  64. rqhiar = mtu3_readl(mbase, USB_QMU_RQHIAR(epnum));
  65. rqhiar &= ~QMU_START_ADDR_HI_MSK;
  66. rqhiar |= QMU_START_ADDR_HI(upper_32_bits(dma));
  67. mtu3_writel(mbase, USB_QMU_RQHIAR(epnum), rqhiar);
  68. }
  69. static struct qmu_gpd *gpd_dma_to_virt(struct mtu3_gpd_ring *ring,
  70. dma_addr_t dma_addr)
  71. {
  72. dma_addr_t dma_base = ring->dma;
  73. struct qmu_gpd *gpd_head = ring->start;
  74. u32 offset = (dma_addr - dma_base) / sizeof(*gpd_head);
  75. if (offset >= MAX_GPD_NUM)
  76. return NULL;
  77. return gpd_head + offset;
  78. }
  79. static dma_addr_t gpd_virt_to_dma(struct mtu3_gpd_ring *ring,
  80. struct qmu_gpd *gpd)
  81. {
  82. dma_addr_t dma_base = ring->dma;
  83. struct qmu_gpd *gpd_head = ring->start;
  84. u32 offset;
  85. offset = gpd - gpd_head;
  86. if (offset >= MAX_GPD_NUM)
  87. return 0;
  88. return dma_base + (offset * sizeof(*gpd));
  89. }
  90. static void gpd_ring_init(struct mtu3_gpd_ring *ring, struct qmu_gpd *gpd)
  91. {
  92. ring->start = gpd;
  93. ring->enqueue = gpd;
  94. ring->dequeue = gpd;
  95. ring->end = gpd + MAX_GPD_NUM - 1;
  96. }
  97. static void reset_gpd_list(struct mtu3_ep *mep)
  98. {
  99. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  100. struct qmu_gpd *gpd = ring->start;
  101. if (gpd) {
  102. gpd->flag &= ~GPD_FLAGS_HWO;
  103. gpd_ring_init(ring, gpd);
  104. }
  105. }
  106. int mtu3_gpd_ring_alloc(struct mtu3_ep *mep)
  107. {
  108. struct qmu_gpd *gpd;
  109. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  110. /* software own all gpds as default */
  111. gpd = dma_pool_zalloc(mep->mtu->qmu_gpd_pool, GFP_ATOMIC, &ring->dma);
  112. if (gpd == NULL)
  113. return -ENOMEM;
  114. gpd_ring_init(ring, gpd);
  115. return 0;
  116. }
  117. void mtu3_gpd_ring_free(struct mtu3_ep *mep)
  118. {
  119. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  120. dma_pool_free(mep->mtu->qmu_gpd_pool,
  121. ring->start, ring->dma);
  122. memset(ring, 0, sizeof(*ring));
  123. }
  124. /*
  125. * calculate check sum of a gpd or bd
  126. * add "noinline" and "mb" to prevent wrong calculation
  127. */
  128. static noinline u8 qmu_calc_checksum(u8 *data)
  129. {
  130. u8 chksum = 0;
  131. int i;
  132. data[1] = 0x0; /* set checksum to 0 */
  133. mb(); /* ensure the gpd/bd is really up-to-date */
  134. for (i = 0; i < QMU_CHECKSUM_LEN; i++)
  135. chksum += data[i];
  136. /* Default: HWO=1, @flag[bit0] */
  137. chksum += 1;
  138. return 0xFF - chksum;
  139. }
  140. void mtu3_qmu_resume(struct mtu3_ep *mep)
  141. {
  142. struct mtu3 *mtu = mep->mtu;
  143. void __iomem *mbase = mtu->mac_base;
  144. int epnum = mep->epnum;
  145. u32 offset;
  146. offset = mep->is_in ? USB_QMU_TQCSR(epnum) : USB_QMU_RQCSR(epnum);
  147. mtu3_writel(mbase, offset, QMU_Q_RESUME);
  148. if (!(mtu3_readl(mbase, offset) & QMU_Q_ACTIVE))
  149. mtu3_writel(mbase, offset, QMU_Q_RESUME);
  150. }
  151. static struct qmu_gpd *advance_enq_gpd(struct mtu3_gpd_ring *ring)
  152. {
  153. if (ring->enqueue < ring->end)
  154. ring->enqueue++;
  155. else
  156. ring->enqueue = ring->start;
  157. return ring->enqueue;
  158. }
  159. static struct qmu_gpd *advance_deq_gpd(struct mtu3_gpd_ring *ring)
  160. {
  161. if (ring->dequeue < ring->end)
  162. ring->dequeue++;
  163. else
  164. ring->dequeue = ring->start;
  165. return ring->dequeue;
  166. }
  167. /* check if a ring is emtpy */
  168. static int gpd_ring_empty(struct mtu3_gpd_ring *ring)
  169. {
  170. struct qmu_gpd *enq = ring->enqueue;
  171. struct qmu_gpd *next;
  172. if (ring->enqueue < ring->end)
  173. next = enq + 1;
  174. else
  175. next = ring->start;
  176. /* one gpd is reserved to simplify gpd preparation */
  177. return next == ring->dequeue;
  178. }
  179. int mtu3_prepare_transfer(struct mtu3_ep *mep)
  180. {
  181. return gpd_ring_empty(&mep->gpd_ring);
  182. }
  183. static int mtu3_prepare_tx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
  184. {
  185. struct qmu_gpd *enq;
  186. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  187. struct qmu_gpd *gpd = ring->enqueue;
  188. struct usb_request *req = &mreq->request;
  189. dma_addr_t enq_dma;
  190. u16 ext_addr;
  191. /* set all fields to zero as default value */
  192. memset(gpd, 0, sizeof(*gpd));
  193. gpd->buffer = cpu_to_le32(lower_32_bits(req->dma));
  194. ext_addr = GPD_EXT_BUF(upper_32_bits(req->dma));
  195. gpd->buf_len = cpu_to_le16(req->length);
  196. gpd->flag |= GPD_FLAGS_IOC;
  197. /* get the next GPD */
  198. enq = advance_enq_gpd(ring);
  199. enq_dma = gpd_virt_to_dma(ring, enq);
  200. dev_dbg(mep->mtu->dev, "TX-EP%d queue gpd=%p, enq=%p, qdma=%pad\n",
  201. mep->epnum, gpd, enq, &enq_dma);
  202. enq->flag &= ~GPD_FLAGS_HWO;
  203. gpd->next_gpd = cpu_to_le32(lower_32_bits(enq_dma));
  204. ext_addr |= GPD_EXT_NGP(upper_32_bits(enq_dma));
  205. gpd->tx_ext_addr = cpu_to_le16(ext_addr);
  206. if (req->zero)
  207. gpd->ext_flag |= GPD_EXT_FLAG_ZLP;
  208. gpd->chksum = qmu_calc_checksum((u8 *)gpd);
  209. gpd->flag |= GPD_FLAGS_HWO;
  210. mreq->gpd = gpd;
  211. return 0;
  212. }
  213. static int mtu3_prepare_rx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
  214. {
  215. struct qmu_gpd *enq;
  216. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  217. struct qmu_gpd *gpd = ring->enqueue;
  218. struct usb_request *req = &mreq->request;
  219. dma_addr_t enq_dma;
  220. u16 ext_addr;
  221. /* set all fields to zero as default value */
  222. memset(gpd, 0, sizeof(*gpd));
  223. gpd->buffer = cpu_to_le32(lower_32_bits(req->dma));
  224. ext_addr = GPD_EXT_BUF(upper_32_bits(req->dma));
  225. gpd->data_buf_len = cpu_to_le16(req->length);
  226. gpd->flag |= GPD_FLAGS_IOC;
  227. /* get the next GPD */
  228. enq = advance_enq_gpd(ring);
  229. enq_dma = gpd_virt_to_dma(ring, enq);
  230. dev_dbg(mep->mtu->dev, "RX-EP%d queue gpd=%p, enq=%p, qdma=%pad\n",
  231. mep->epnum, gpd, enq, &enq_dma);
  232. enq->flag &= ~GPD_FLAGS_HWO;
  233. gpd->next_gpd = cpu_to_le32(lower_32_bits(enq_dma));
  234. ext_addr |= GPD_EXT_NGP(upper_32_bits(enq_dma));
  235. gpd->rx_ext_addr = cpu_to_le16(ext_addr);
  236. gpd->chksum = qmu_calc_checksum((u8 *)gpd);
  237. gpd->flag |= GPD_FLAGS_HWO;
  238. mreq->gpd = gpd;
  239. return 0;
  240. }
  241. void mtu3_insert_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
  242. {
  243. if (mep->is_in)
  244. mtu3_prepare_tx_gpd(mep, mreq);
  245. else
  246. mtu3_prepare_rx_gpd(mep, mreq);
  247. }
  248. int mtu3_qmu_start(struct mtu3_ep *mep)
  249. {
  250. struct mtu3 *mtu = mep->mtu;
  251. void __iomem *mbase = mtu->mac_base;
  252. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  253. u8 epnum = mep->epnum;
  254. if (mep->is_in) {
  255. /* set QMU start address */
  256. write_txq_start_addr(mbase, epnum, ring->dma);
  257. mtu3_setbits(mbase, MU3D_EP_TXCR0(epnum), TX_DMAREQEN);
  258. mtu3_setbits(mbase, U3D_QCR0, QMU_TX_CS_EN(epnum));
  259. /* send zero length packet according to ZLP flag in GPD */
  260. mtu3_setbits(mbase, U3D_QCR1, QMU_TX_ZLP(epnum));
  261. mtu3_writel(mbase, U3D_TQERRIESR0,
  262. QMU_TX_LEN_ERR(epnum) | QMU_TX_CS_ERR(epnum));
  263. if (mtu3_readl(mbase, USB_QMU_TQCSR(epnum)) & QMU_Q_ACTIVE) {
  264. dev_warn(mtu->dev, "Tx %d Active Now!\n", epnum);
  265. return 0;
  266. }
  267. mtu3_writel(mbase, USB_QMU_TQCSR(epnum), QMU_Q_START);
  268. } else {
  269. write_rxq_start_addr(mbase, epnum, ring->dma);
  270. mtu3_setbits(mbase, MU3D_EP_RXCR0(epnum), RX_DMAREQEN);
  271. mtu3_setbits(mbase, U3D_QCR0, QMU_RX_CS_EN(epnum));
  272. /* don't expect ZLP */
  273. mtu3_clrbits(mbase, U3D_QCR3, QMU_RX_ZLP(epnum));
  274. /* move to next GPD when receive ZLP */
  275. mtu3_setbits(mbase, U3D_QCR3, QMU_RX_COZ(epnum));
  276. mtu3_writel(mbase, U3D_RQERRIESR0,
  277. QMU_RX_LEN_ERR(epnum) | QMU_RX_CS_ERR(epnum));
  278. mtu3_writel(mbase, U3D_RQERRIESR1, QMU_RX_ZLP_ERR(epnum));
  279. if (mtu3_readl(mbase, USB_QMU_RQCSR(epnum)) & QMU_Q_ACTIVE) {
  280. dev_warn(mtu->dev, "Rx %d Active Now!\n", epnum);
  281. return 0;
  282. }
  283. mtu3_writel(mbase, USB_QMU_RQCSR(epnum), QMU_Q_START);
  284. }
  285. return 0;
  286. }
  287. /* may called in atomic context */
  288. void mtu3_qmu_stop(struct mtu3_ep *mep)
  289. {
  290. struct mtu3 *mtu = mep->mtu;
  291. void __iomem *mbase = mtu->mac_base;
  292. int epnum = mep->epnum;
  293. u32 value = 0;
  294. u32 qcsr;
  295. int ret;
  296. qcsr = mep->is_in ? USB_QMU_TQCSR(epnum) : USB_QMU_RQCSR(epnum);
  297. if (!(mtu3_readl(mbase, qcsr) & QMU_Q_ACTIVE)) {
  298. dev_dbg(mtu->dev, "%s's qmu is inactive now!\n", mep->name);
  299. return;
  300. }
  301. mtu3_writel(mbase, qcsr, QMU_Q_STOP);
  302. ret = readl_poll_timeout_atomic(mbase + qcsr, value,
  303. !(value & QMU_Q_ACTIVE), 1, 1000);
  304. if (ret) {
  305. dev_err(mtu->dev, "stop %s's qmu failed\n", mep->name);
  306. return;
  307. }
  308. dev_dbg(mtu->dev, "%s's qmu stop now!\n", mep->name);
  309. }
  310. void mtu3_qmu_flush(struct mtu3_ep *mep)
  311. {
  312. dev_dbg(mep->mtu->dev, "%s flush QMU %s\n", __func__,
  313. ((mep->is_in) ? "TX" : "RX"));
  314. /*Stop QMU */
  315. mtu3_qmu_stop(mep);
  316. reset_gpd_list(mep);
  317. }
  318. /*
  319. * QMU can't transfer zero length packet directly (a hardware limit
  320. * on old SoCs), so when needs to send ZLP, we intentionally trigger
  321. * a length error interrupt, and in the ISR sends a ZLP by BMU.
  322. */
  323. static void qmu_tx_zlp_error_handler(struct mtu3 *mtu, u8 epnum)
  324. {
  325. struct mtu3_ep *mep = mtu->in_eps + epnum;
  326. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  327. void __iomem *mbase = mtu->mac_base;
  328. struct qmu_gpd *gpd_current = NULL;
  329. struct usb_request *req = NULL;
  330. struct mtu3_request *mreq;
  331. dma_addr_t cur_gpd_dma;
  332. u32 txcsr = 0;
  333. int ret;
  334. mreq = next_request(mep);
  335. if (mreq && mreq->request.length == 0)
  336. req = &mreq->request;
  337. else
  338. return;
  339. cur_gpd_dma = read_txq_cur_addr(mbase, epnum);
  340. gpd_current = gpd_dma_to_virt(ring, cur_gpd_dma);
  341. if (le16_to_cpu(gpd_current->buf_len) != 0) {
  342. dev_err(mtu->dev, "TX EP%d buffer length error(!=0)\n", epnum);
  343. return;
  344. }
  345. dev_dbg(mtu->dev, "%s send ZLP for req=%p\n", __func__, req);
  346. mtu3_clrbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_DMAREQEN);
  347. ret = readl_poll_timeout_atomic(mbase + MU3D_EP_TXCR0(mep->epnum),
  348. txcsr, !(txcsr & TX_FIFOFULL), 1, 1000);
  349. if (ret) {
  350. dev_err(mtu->dev, "%s wait for fifo empty fail\n", __func__);
  351. return;
  352. }
  353. mtu3_setbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_TXPKTRDY);
  354. /* by pass the current GDP */
  355. gpd_current->flag |= GPD_FLAGS_BPS;
  356. gpd_current->chksum = qmu_calc_checksum((u8 *)gpd_current);
  357. gpd_current->flag |= GPD_FLAGS_HWO;
  358. /*enable DMAREQEN, switch back to QMU mode */
  359. mtu3_setbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_DMAREQEN);
  360. mtu3_qmu_resume(mep);
  361. }
  362. /*
  363. * NOTE: request list maybe is already empty as following case:
  364. * queue_tx --> qmu_interrupt(clear interrupt pending, schedule tasklet)-->
  365. * queue_tx --> process_tasklet(meanwhile, the second one is transferred,
  366. * tasklet process both of them)-->qmu_interrupt for second one.
  367. * To avoid upper case, put qmu_done_tx in ISR directly to process it.
  368. */
  369. static void qmu_done_tx(struct mtu3 *mtu, u8 epnum)
  370. {
  371. struct mtu3_ep *mep = mtu->in_eps + epnum;
  372. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  373. void __iomem *mbase = mtu->mac_base;
  374. struct qmu_gpd *gpd = ring->dequeue;
  375. struct qmu_gpd *gpd_current = NULL;
  376. struct usb_request *request = NULL;
  377. struct mtu3_request *mreq;
  378. dma_addr_t cur_gpd_dma;
  379. /*transfer phy address got from QMU register to virtual address */
  380. cur_gpd_dma = read_txq_cur_addr(mbase, epnum);
  381. gpd_current = gpd_dma_to_virt(ring, cur_gpd_dma);
  382. dev_dbg(mtu->dev, "%s EP%d, last=%p, current=%p, enq=%p\n",
  383. __func__, epnum, gpd, gpd_current, ring->enqueue);
  384. while (gpd != gpd_current && !(gpd->flag & GPD_FLAGS_HWO)) {
  385. mreq = next_request(mep);
  386. if (mreq == NULL || mreq->gpd != gpd) {
  387. dev_err(mtu->dev, "no correct TX req is found\n");
  388. break;
  389. }
  390. request = &mreq->request;
  391. request->actual = le16_to_cpu(gpd->buf_len);
  392. mtu3_req_complete(mep, request, 0);
  393. gpd = advance_deq_gpd(ring);
  394. }
  395. dev_dbg(mtu->dev, "%s EP%d, deq=%p, enq=%p, complete\n",
  396. __func__, epnum, ring->dequeue, ring->enqueue);
  397. }
  398. static void qmu_done_rx(struct mtu3 *mtu, u8 epnum)
  399. {
  400. struct mtu3_ep *mep = mtu->out_eps + epnum;
  401. struct mtu3_gpd_ring *ring = &mep->gpd_ring;
  402. void __iomem *mbase = mtu->mac_base;
  403. struct qmu_gpd *gpd = ring->dequeue;
  404. struct qmu_gpd *gpd_current = NULL;
  405. struct usb_request *req = NULL;
  406. struct mtu3_request *mreq;
  407. dma_addr_t cur_gpd_dma;
  408. cur_gpd_dma = read_rxq_cur_addr(mbase, epnum);
  409. gpd_current = gpd_dma_to_virt(ring, cur_gpd_dma);
  410. dev_dbg(mtu->dev, "%s EP%d, last=%p, current=%p, enq=%p\n",
  411. __func__, epnum, gpd, gpd_current, ring->enqueue);
  412. while (gpd != gpd_current && !(gpd->flag & GPD_FLAGS_HWO)) {
  413. mreq = next_request(mep);
  414. if (mreq == NULL || mreq->gpd != gpd) {
  415. dev_err(mtu->dev, "no correct RX req is found\n");
  416. break;
  417. }
  418. req = &mreq->request;
  419. req->actual = le16_to_cpu(gpd->buf_len);
  420. mtu3_req_complete(mep, req, 0);
  421. gpd = advance_deq_gpd(ring);
  422. }
  423. dev_dbg(mtu->dev, "%s EP%d, deq=%p, enq=%p, complete\n",
  424. __func__, epnum, ring->dequeue, ring->enqueue);
  425. }
  426. static void qmu_done_isr(struct mtu3 *mtu, u32 done_status)
  427. {
  428. int i;
  429. for (i = 1; i < mtu->num_eps; i++) {
  430. if (done_status & QMU_RX_DONE_INT(i))
  431. qmu_done_rx(mtu, i);
  432. if (done_status & QMU_TX_DONE_INT(i))
  433. qmu_done_tx(mtu, i);
  434. }
  435. }
  436. static void qmu_exception_isr(struct mtu3 *mtu, u32 qmu_status)
  437. {
  438. void __iomem *mbase = mtu->mac_base;
  439. u32 errval;
  440. int i;
  441. if ((qmu_status & RXQ_CSERR_INT) || (qmu_status & RXQ_LENERR_INT)) {
  442. errval = mtu3_readl(mbase, U3D_RQERRIR0);
  443. for (i = 1; i < mtu->num_eps; i++) {
  444. if (errval & QMU_RX_CS_ERR(i))
  445. dev_err(mtu->dev, "Rx %d CS error!\n", i);
  446. if (errval & QMU_RX_LEN_ERR(i))
  447. dev_err(mtu->dev, "RX %d Length error\n", i);
  448. }
  449. mtu3_writel(mbase, U3D_RQERRIR0, errval);
  450. }
  451. if (qmu_status & RXQ_ZLPERR_INT) {
  452. errval = mtu3_readl(mbase, U3D_RQERRIR1);
  453. for (i = 1; i < mtu->num_eps; i++) {
  454. if (errval & QMU_RX_ZLP_ERR(i))
  455. dev_dbg(mtu->dev, "RX EP%d Recv ZLP\n", i);
  456. }
  457. mtu3_writel(mbase, U3D_RQERRIR1, errval);
  458. }
  459. if ((qmu_status & TXQ_CSERR_INT) || (qmu_status & TXQ_LENERR_INT)) {
  460. errval = mtu3_readl(mbase, U3D_TQERRIR0);
  461. for (i = 1; i < mtu->num_eps; i++) {
  462. if (errval & QMU_TX_CS_ERR(i))
  463. dev_err(mtu->dev, "Tx %d checksum error!\n", i);
  464. if (errval & QMU_TX_LEN_ERR(i))
  465. qmu_tx_zlp_error_handler(mtu, i);
  466. }
  467. mtu3_writel(mbase, U3D_TQERRIR0, errval);
  468. }
  469. }
  470. irqreturn_t mtu3_qmu_isr(struct mtu3 *mtu)
  471. {
  472. void __iomem *mbase = mtu->mac_base;
  473. u32 qmu_status;
  474. u32 qmu_done_status;
  475. /* U3D_QISAR1 is read update */
  476. qmu_status = mtu3_readl(mbase, U3D_QISAR1);
  477. qmu_status &= mtu3_readl(mbase, U3D_QIER1);
  478. qmu_done_status = mtu3_readl(mbase, U3D_QISAR0);
  479. qmu_done_status &= mtu3_readl(mbase, U3D_QIER0);
  480. mtu3_writel(mbase, U3D_QISAR0, qmu_done_status); /* W1C */
  481. dev_dbg(mtu->dev, "=== QMUdone[tx=%x, rx=%x] QMUexp[%x] ===\n",
  482. (qmu_done_status & 0xFFFF), qmu_done_status >> 16,
  483. qmu_status);
  484. if (qmu_done_status)
  485. qmu_done_isr(mtu, qmu_done_status);
  486. if (qmu_status)
  487. qmu_exception_isr(mtu, qmu_status);
  488. return IRQ_HANDLED;
  489. }
  490. int mtu3_qmu_init(struct mtu3 *mtu)
  491. {
  492. compiletime_assert(QMU_GPD_SIZE == 16, "QMU_GPD size SHOULD be 16B");
  493. mtu->qmu_gpd_pool = dma_pool_create("QMU_GPD", mtu->dev,
  494. QMU_GPD_RING_SIZE, QMU_GPD_SIZE, 0);
  495. if (!mtu->qmu_gpd_pool)
  496. return -ENOMEM;
  497. return 0;
  498. }
  499. void mtu3_qmu_exit(struct mtu3 *mtu)
  500. {
  501. dma_pool_destroy(mtu->qmu_gpd_pool);
  502. }