plx_dma.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Microsemi Switchtec(tm) PCIe Management Driver
  4. * Copyright (c) 2019, Logan Gunthorpe <[email protected]>
  5. * Copyright (c) 2019, GigaIO Networks, Inc
  6. */
  7. #include "dmaengine.h"
  8. #include <linux/circ_buf.h>
  9. #include <linux/dmaengine.h>
  10. #include <linux/kref.h>
  11. #include <linux/list.h>
  12. #include <linux/module.h>
  13. #include <linux/pci.h>
  14. MODULE_DESCRIPTION("PLX ExpressLane PEX PCI Switch DMA Engine");
  15. MODULE_VERSION("0.1");
  16. MODULE_LICENSE("GPL");
  17. MODULE_AUTHOR("Logan Gunthorpe");
  18. #define PLX_REG_DESC_RING_ADDR 0x214
  19. #define PLX_REG_DESC_RING_ADDR_HI 0x218
  20. #define PLX_REG_DESC_RING_NEXT_ADDR 0x21C
  21. #define PLX_REG_DESC_RING_COUNT 0x220
  22. #define PLX_REG_DESC_RING_LAST_ADDR 0x224
  23. #define PLX_REG_DESC_RING_LAST_SIZE 0x228
  24. #define PLX_REG_PREF_LIMIT 0x234
  25. #define PLX_REG_CTRL 0x238
  26. #define PLX_REG_CTRL2 0x23A
  27. #define PLX_REG_INTR_CTRL 0x23C
  28. #define PLX_REG_INTR_STATUS 0x23E
  29. #define PLX_REG_PREF_LIMIT_PREF_FOUR 8
  30. #define PLX_REG_CTRL_GRACEFUL_PAUSE BIT(0)
  31. #define PLX_REG_CTRL_ABORT BIT(1)
  32. #define PLX_REG_CTRL_WRITE_BACK_EN BIT(2)
  33. #define PLX_REG_CTRL_START BIT(3)
  34. #define PLX_REG_CTRL_RING_STOP_MODE BIT(4)
  35. #define PLX_REG_CTRL_DESC_MODE_BLOCK (0 << 5)
  36. #define PLX_REG_CTRL_DESC_MODE_ON_CHIP (1 << 5)
  37. #define PLX_REG_CTRL_DESC_MODE_OFF_CHIP (2 << 5)
  38. #define PLX_REG_CTRL_DESC_INVALID BIT(8)
  39. #define PLX_REG_CTRL_GRACEFUL_PAUSE_DONE BIT(9)
  40. #define PLX_REG_CTRL_ABORT_DONE BIT(10)
  41. #define PLX_REG_CTRL_IMM_PAUSE_DONE BIT(12)
  42. #define PLX_REG_CTRL_IN_PROGRESS BIT(30)
  43. #define PLX_REG_CTRL_RESET_VAL (PLX_REG_CTRL_DESC_INVALID | \
  44. PLX_REG_CTRL_GRACEFUL_PAUSE_DONE | \
  45. PLX_REG_CTRL_ABORT_DONE | \
  46. PLX_REG_CTRL_IMM_PAUSE_DONE)
  47. #define PLX_REG_CTRL_START_VAL (PLX_REG_CTRL_WRITE_BACK_EN | \
  48. PLX_REG_CTRL_DESC_MODE_OFF_CHIP | \
  49. PLX_REG_CTRL_START | \
  50. PLX_REG_CTRL_RESET_VAL)
  51. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_64B 0
  52. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_128B 1
  53. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_256B 2
  54. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_512B 3
  55. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_1KB 4
  56. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_2KB 5
  57. #define PLX_REG_CTRL2_MAX_TXFR_SIZE_4B 7
  58. #define PLX_REG_INTR_CRTL_ERROR_EN BIT(0)
  59. #define PLX_REG_INTR_CRTL_INV_DESC_EN BIT(1)
  60. #define PLX_REG_INTR_CRTL_ABORT_DONE_EN BIT(3)
  61. #define PLX_REG_INTR_CRTL_PAUSE_DONE_EN BIT(4)
  62. #define PLX_REG_INTR_CRTL_IMM_PAUSE_DONE_EN BIT(5)
  63. #define PLX_REG_INTR_STATUS_ERROR BIT(0)
  64. #define PLX_REG_INTR_STATUS_INV_DESC BIT(1)
  65. #define PLX_REG_INTR_STATUS_DESC_DONE BIT(2)
  66. #define PLX_REG_INTR_CRTL_ABORT_DONE BIT(3)
  67. struct plx_dma_hw_std_desc {
  68. __le32 flags_and_size;
  69. __le16 dst_addr_hi;
  70. __le16 src_addr_hi;
  71. __le32 dst_addr_lo;
  72. __le32 src_addr_lo;
  73. };
  74. #define PLX_DESC_SIZE_MASK 0x7ffffff
  75. #define PLX_DESC_FLAG_VALID BIT(31)
  76. #define PLX_DESC_FLAG_INT_WHEN_DONE BIT(30)
  77. #define PLX_DESC_WB_SUCCESS BIT(30)
  78. #define PLX_DESC_WB_RD_FAIL BIT(29)
  79. #define PLX_DESC_WB_WR_FAIL BIT(28)
  80. #define PLX_DMA_RING_COUNT 2048
  81. struct plx_dma_desc {
  82. struct dma_async_tx_descriptor txd;
  83. struct plx_dma_hw_std_desc *hw;
  84. u32 orig_size;
  85. };
  86. struct plx_dma_dev {
  87. struct dma_device dma_dev;
  88. struct dma_chan dma_chan;
  89. struct pci_dev __rcu *pdev;
  90. void __iomem *bar;
  91. struct tasklet_struct desc_task;
  92. spinlock_t ring_lock;
  93. bool ring_active;
  94. int head;
  95. int tail;
  96. struct plx_dma_hw_std_desc *hw_ring;
  97. dma_addr_t hw_ring_dma;
  98. struct plx_dma_desc **desc_ring;
  99. };
  100. static struct plx_dma_dev *chan_to_plx_dma_dev(struct dma_chan *c)
  101. {
  102. return container_of(c, struct plx_dma_dev, dma_chan);
  103. }
  104. static struct plx_dma_desc *to_plx_desc(struct dma_async_tx_descriptor *txd)
  105. {
  106. return container_of(txd, struct plx_dma_desc, txd);
  107. }
  108. static struct plx_dma_desc *plx_dma_get_desc(struct plx_dma_dev *plxdev, int i)
  109. {
  110. return plxdev->desc_ring[i & (PLX_DMA_RING_COUNT - 1)];
  111. }
  112. static void plx_dma_process_desc(struct plx_dma_dev *plxdev)
  113. {
  114. struct dmaengine_result res;
  115. struct plx_dma_desc *desc;
  116. u32 flags;
  117. spin_lock(&plxdev->ring_lock);
  118. while (plxdev->tail != plxdev->head) {
  119. desc = plx_dma_get_desc(plxdev, plxdev->tail);
  120. flags = le32_to_cpu(READ_ONCE(desc->hw->flags_and_size));
  121. if (flags & PLX_DESC_FLAG_VALID)
  122. break;
  123. res.residue = desc->orig_size - (flags & PLX_DESC_SIZE_MASK);
  124. if (flags & PLX_DESC_WB_SUCCESS)
  125. res.result = DMA_TRANS_NOERROR;
  126. else if (flags & PLX_DESC_WB_WR_FAIL)
  127. res.result = DMA_TRANS_WRITE_FAILED;
  128. else
  129. res.result = DMA_TRANS_READ_FAILED;
  130. dma_cookie_complete(&desc->txd);
  131. dma_descriptor_unmap(&desc->txd);
  132. dmaengine_desc_get_callback_invoke(&desc->txd, &res);
  133. desc->txd.callback = NULL;
  134. desc->txd.callback_result = NULL;
  135. plxdev->tail++;
  136. }
  137. spin_unlock(&plxdev->ring_lock);
  138. }
  139. static void plx_dma_abort_desc(struct plx_dma_dev *plxdev)
  140. {
  141. struct dmaengine_result res;
  142. struct plx_dma_desc *desc;
  143. plx_dma_process_desc(plxdev);
  144. spin_lock_bh(&plxdev->ring_lock);
  145. while (plxdev->tail != plxdev->head) {
  146. desc = plx_dma_get_desc(plxdev, plxdev->tail);
  147. res.residue = desc->orig_size;
  148. res.result = DMA_TRANS_ABORTED;
  149. dma_cookie_complete(&desc->txd);
  150. dma_descriptor_unmap(&desc->txd);
  151. dmaengine_desc_get_callback_invoke(&desc->txd, &res);
  152. desc->txd.callback = NULL;
  153. desc->txd.callback_result = NULL;
  154. plxdev->tail++;
  155. }
  156. spin_unlock_bh(&plxdev->ring_lock);
  157. }
  158. static void __plx_dma_stop(struct plx_dma_dev *plxdev)
  159. {
  160. unsigned long timeout = jiffies + msecs_to_jiffies(1000);
  161. u32 val;
  162. val = readl(plxdev->bar + PLX_REG_CTRL);
  163. if (!(val & ~PLX_REG_CTRL_GRACEFUL_PAUSE))
  164. return;
  165. writel(PLX_REG_CTRL_RESET_VAL | PLX_REG_CTRL_GRACEFUL_PAUSE,
  166. plxdev->bar + PLX_REG_CTRL);
  167. while (!time_after(jiffies, timeout)) {
  168. val = readl(plxdev->bar + PLX_REG_CTRL);
  169. if (val & PLX_REG_CTRL_GRACEFUL_PAUSE_DONE)
  170. break;
  171. cpu_relax();
  172. }
  173. if (!(val & PLX_REG_CTRL_GRACEFUL_PAUSE_DONE))
  174. dev_err(plxdev->dma_dev.dev,
  175. "Timeout waiting for graceful pause!\n");
  176. writel(PLX_REG_CTRL_RESET_VAL | PLX_REG_CTRL_GRACEFUL_PAUSE,
  177. plxdev->bar + PLX_REG_CTRL);
  178. writel(0, plxdev->bar + PLX_REG_DESC_RING_COUNT);
  179. writel(0, plxdev->bar + PLX_REG_DESC_RING_ADDR);
  180. writel(0, plxdev->bar + PLX_REG_DESC_RING_ADDR_HI);
  181. writel(0, plxdev->bar + PLX_REG_DESC_RING_NEXT_ADDR);
  182. }
  183. static void plx_dma_stop(struct plx_dma_dev *plxdev)
  184. {
  185. rcu_read_lock();
  186. if (!rcu_dereference(plxdev->pdev)) {
  187. rcu_read_unlock();
  188. return;
  189. }
  190. __plx_dma_stop(plxdev);
  191. rcu_read_unlock();
  192. }
  193. static void plx_dma_desc_task(struct tasklet_struct *t)
  194. {
  195. struct plx_dma_dev *plxdev = from_tasklet(plxdev, t, desc_task);
  196. plx_dma_process_desc(plxdev);
  197. }
  198. static struct dma_async_tx_descriptor *plx_dma_prep_memcpy(struct dma_chan *c,
  199. dma_addr_t dma_dst, dma_addr_t dma_src, size_t len,
  200. unsigned long flags)
  201. __acquires(plxdev->ring_lock)
  202. {
  203. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(c);
  204. struct plx_dma_desc *plxdesc;
  205. spin_lock_bh(&plxdev->ring_lock);
  206. if (!plxdev->ring_active)
  207. goto err_unlock;
  208. if (!CIRC_SPACE(plxdev->head, plxdev->tail, PLX_DMA_RING_COUNT))
  209. goto err_unlock;
  210. if (len > PLX_DESC_SIZE_MASK)
  211. goto err_unlock;
  212. plxdesc = plx_dma_get_desc(plxdev, plxdev->head);
  213. plxdev->head++;
  214. plxdesc->hw->dst_addr_lo = cpu_to_le32(lower_32_bits(dma_dst));
  215. plxdesc->hw->dst_addr_hi = cpu_to_le16(upper_32_bits(dma_dst));
  216. plxdesc->hw->src_addr_lo = cpu_to_le32(lower_32_bits(dma_src));
  217. plxdesc->hw->src_addr_hi = cpu_to_le16(upper_32_bits(dma_src));
  218. plxdesc->orig_size = len;
  219. if (flags & DMA_PREP_INTERRUPT)
  220. len |= PLX_DESC_FLAG_INT_WHEN_DONE;
  221. plxdesc->hw->flags_and_size = cpu_to_le32(len);
  222. plxdesc->txd.flags = flags;
  223. /* return with the lock held, it will be released in tx_submit */
  224. return &plxdesc->txd;
  225. err_unlock:
  226. /*
  227. * Keep sparse happy by restoring an even lock count on
  228. * this lock.
  229. */
  230. __acquire(plxdev->ring_lock);
  231. spin_unlock_bh(&plxdev->ring_lock);
  232. return NULL;
  233. }
  234. static dma_cookie_t plx_dma_tx_submit(struct dma_async_tx_descriptor *desc)
  235. __releases(plxdev->ring_lock)
  236. {
  237. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(desc->chan);
  238. struct plx_dma_desc *plxdesc = to_plx_desc(desc);
  239. dma_cookie_t cookie;
  240. cookie = dma_cookie_assign(desc);
  241. /*
  242. * Ensure the descriptor updates are visible to the dma device
  243. * before setting the valid bit.
  244. */
  245. wmb();
  246. plxdesc->hw->flags_and_size |= cpu_to_le32(PLX_DESC_FLAG_VALID);
  247. spin_unlock_bh(&plxdev->ring_lock);
  248. return cookie;
  249. }
  250. static enum dma_status plx_dma_tx_status(struct dma_chan *chan,
  251. dma_cookie_t cookie, struct dma_tx_state *txstate)
  252. {
  253. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan);
  254. enum dma_status ret;
  255. ret = dma_cookie_status(chan, cookie, txstate);
  256. if (ret == DMA_COMPLETE)
  257. return ret;
  258. plx_dma_process_desc(plxdev);
  259. return dma_cookie_status(chan, cookie, txstate);
  260. }
  261. static void plx_dma_issue_pending(struct dma_chan *chan)
  262. {
  263. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan);
  264. rcu_read_lock();
  265. if (!rcu_dereference(plxdev->pdev)) {
  266. rcu_read_unlock();
  267. return;
  268. }
  269. /*
  270. * Ensure the valid bits are visible before starting the
  271. * DMA engine.
  272. */
  273. wmb();
  274. writew(PLX_REG_CTRL_START_VAL, plxdev->bar + PLX_REG_CTRL);
  275. rcu_read_unlock();
  276. }
  277. static irqreturn_t plx_dma_isr(int irq, void *devid)
  278. {
  279. struct plx_dma_dev *plxdev = devid;
  280. u32 status;
  281. status = readw(plxdev->bar + PLX_REG_INTR_STATUS);
  282. if (!status)
  283. return IRQ_NONE;
  284. if (status & PLX_REG_INTR_STATUS_DESC_DONE && plxdev->ring_active)
  285. tasklet_schedule(&plxdev->desc_task);
  286. writew(status, plxdev->bar + PLX_REG_INTR_STATUS);
  287. return IRQ_HANDLED;
  288. }
  289. static int plx_dma_alloc_desc(struct plx_dma_dev *plxdev)
  290. {
  291. struct plx_dma_desc *desc;
  292. int i;
  293. plxdev->desc_ring = kcalloc(PLX_DMA_RING_COUNT,
  294. sizeof(*plxdev->desc_ring), GFP_KERNEL);
  295. if (!plxdev->desc_ring)
  296. return -ENOMEM;
  297. for (i = 0; i < PLX_DMA_RING_COUNT; i++) {
  298. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  299. if (!desc)
  300. goto free_and_exit;
  301. dma_async_tx_descriptor_init(&desc->txd, &plxdev->dma_chan);
  302. desc->txd.tx_submit = plx_dma_tx_submit;
  303. desc->hw = &plxdev->hw_ring[i];
  304. plxdev->desc_ring[i] = desc;
  305. }
  306. return 0;
  307. free_and_exit:
  308. for (i = 0; i < PLX_DMA_RING_COUNT; i++)
  309. kfree(plxdev->desc_ring[i]);
  310. kfree(plxdev->desc_ring);
  311. return -ENOMEM;
  312. }
  313. static int plx_dma_alloc_chan_resources(struct dma_chan *chan)
  314. {
  315. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan);
  316. size_t ring_sz = PLX_DMA_RING_COUNT * sizeof(*plxdev->hw_ring);
  317. int rc;
  318. plxdev->head = plxdev->tail = 0;
  319. plxdev->hw_ring = dma_alloc_coherent(plxdev->dma_dev.dev, ring_sz,
  320. &plxdev->hw_ring_dma, GFP_KERNEL);
  321. if (!plxdev->hw_ring)
  322. return -ENOMEM;
  323. rc = plx_dma_alloc_desc(plxdev);
  324. if (rc)
  325. goto out_free_hw_ring;
  326. rcu_read_lock();
  327. if (!rcu_dereference(plxdev->pdev)) {
  328. rcu_read_unlock();
  329. rc = -ENODEV;
  330. goto out_free_hw_ring;
  331. }
  332. writel(PLX_REG_CTRL_RESET_VAL, plxdev->bar + PLX_REG_CTRL);
  333. writel(lower_32_bits(plxdev->hw_ring_dma),
  334. plxdev->bar + PLX_REG_DESC_RING_ADDR);
  335. writel(upper_32_bits(plxdev->hw_ring_dma),
  336. plxdev->bar + PLX_REG_DESC_RING_ADDR_HI);
  337. writel(lower_32_bits(plxdev->hw_ring_dma),
  338. plxdev->bar + PLX_REG_DESC_RING_NEXT_ADDR);
  339. writel(PLX_DMA_RING_COUNT, plxdev->bar + PLX_REG_DESC_RING_COUNT);
  340. writel(PLX_REG_PREF_LIMIT_PREF_FOUR, plxdev->bar + PLX_REG_PREF_LIMIT);
  341. plxdev->ring_active = true;
  342. rcu_read_unlock();
  343. return PLX_DMA_RING_COUNT;
  344. out_free_hw_ring:
  345. dma_free_coherent(plxdev->dma_dev.dev, ring_sz, plxdev->hw_ring,
  346. plxdev->hw_ring_dma);
  347. return rc;
  348. }
  349. static void plx_dma_free_chan_resources(struct dma_chan *chan)
  350. {
  351. struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan);
  352. size_t ring_sz = PLX_DMA_RING_COUNT * sizeof(*plxdev->hw_ring);
  353. struct pci_dev *pdev;
  354. int irq = -1;
  355. int i;
  356. spin_lock_bh(&plxdev->ring_lock);
  357. plxdev->ring_active = false;
  358. spin_unlock_bh(&plxdev->ring_lock);
  359. plx_dma_stop(plxdev);
  360. rcu_read_lock();
  361. pdev = rcu_dereference(plxdev->pdev);
  362. if (pdev)
  363. irq = pci_irq_vector(pdev, 0);
  364. rcu_read_unlock();
  365. if (irq > 0)
  366. synchronize_irq(irq);
  367. tasklet_kill(&plxdev->desc_task);
  368. plx_dma_abort_desc(plxdev);
  369. for (i = 0; i < PLX_DMA_RING_COUNT; i++)
  370. kfree(plxdev->desc_ring[i]);
  371. kfree(plxdev->desc_ring);
  372. dma_free_coherent(plxdev->dma_dev.dev, ring_sz, plxdev->hw_ring,
  373. plxdev->hw_ring_dma);
  374. }
  375. static void plx_dma_release(struct dma_device *dma_dev)
  376. {
  377. struct plx_dma_dev *plxdev =
  378. container_of(dma_dev, struct plx_dma_dev, dma_dev);
  379. put_device(dma_dev->dev);
  380. kfree(plxdev);
  381. }
  382. static int plx_dma_create(struct pci_dev *pdev)
  383. {
  384. struct plx_dma_dev *plxdev;
  385. struct dma_device *dma;
  386. struct dma_chan *chan;
  387. int rc;
  388. plxdev = kzalloc(sizeof(*plxdev), GFP_KERNEL);
  389. if (!plxdev)
  390. return -ENOMEM;
  391. rc = request_irq(pci_irq_vector(pdev, 0), plx_dma_isr, 0,
  392. KBUILD_MODNAME, plxdev);
  393. if (rc)
  394. goto free_plx;
  395. spin_lock_init(&plxdev->ring_lock);
  396. tasklet_setup(&plxdev->desc_task, plx_dma_desc_task);
  397. RCU_INIT_POINTER(plxdev->pdev, pdev);
  398. plxdev->bar = pcim_iomap_table(pdev)[0];
  399. dma = &plxdev->dma_dev;
  400. dma->chancnt = 1;
  401. INIT_LIST_HEAD(&dma->channels);
  402. dma_cap_set(DMA_MEMCPY, dma->cap_mask);
  403. dma->copy_align = DMAENGINE_ALIGN_1_BYTE;
  404. dma->dev = get_device(&pdev->dev);
  405. dma->device_alloc_chan_resources = plx_dma_alloc_chan_resources;
  406. dma->device_free_chan_resources = plx_dma_free_chan_resources;
  407. dma->device_prep_dma_memcpy = plx_dma_prep_memcpy;
  408. dma->device_issue_pending = plx_dma_issue_pending;
  409. dma->device_tx_status = plx_dma_tx_status;
  410. dma->device_release = plx_dma_release;
  411. chan = &plxdev->dma_chan;
  412. chan->device = dma;
  413. dma_cookie_init(chan);
  414. list_add_tail(&chan->device_node, &dma->channels);
  415. rc = dma_async_device_register(dma);
  416. if (rc) {
  417. pci_err(pdev, "Failed to register dma device: %d\n", rc);
  418. goto put_device;
  419. }
  420. pci_set_drvdata(pdev, plxdev);
  421. return 0;
  422. put_device:
  423. put_device(&pdev->dev);
  424. free_irq(pci_irq_vector(pdev, 0), plxdev);
  425. free_plx:
  426. kfree(plxdev);
  427. return rc;
  428. }
  429. static int plx_dma_probe(struct pci_dev *pdev,
  430. const struct pci_device_id *id)
  431. {
  432. int rc;
  433. rc = pcim_enable_device(pdev);
  434. if (rc)
  435. return rc;
  436. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(48));
  437. if (rc)
  438. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  439. if (rc)
  440. return rc;
  441. rc = pcim_iomap_regions(pdev, 1, KBUILD_MODNAME);
  442. if (rc)
  443. return rc;
  444. rc = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
  445. if (rc <= 0)
  446. return rc;
  447. pci_set_master(pdev);
  448. rc = plx_dma_create(pdev);
  449. if (rc)
  450. goto err_free_irq_vectors;
  451. pci_info(pdev, "PLX DMA Channel Registered\n");
  452. return 0;
  453. err_free_irq_vectors:
  454. pci_free_irq_vectors(pdev);
  455. return rc;
  456. }
  457. static void plx_dma_remove(struct pci_dev *pdev)
  458. {
  459. struct plx_dma_dev *plxdev = pci_get_drvdata(pdev);
  460. free_irq(pci_irq_vector(pdev, 0), plxdev);
  461. rcu_assign_pointer(plxdev->pdev, NULL);
  462. synchronize_rcu();
  463. spin_lock_bh(&plxdev->ring_lock);
  464. plxdev->ring_active = false;
  465. spin_unlock_bh(&plxdev->ring_lock);
  466. __plx_dma_stop(plxdev);
  467. plx_dma_abort_desc(plxdev);
  468. plxdev->bar = NULL;
  469. dma_async_device_unregister(&plxdev->dma_dev);
  470. pci_free_irq_vectors(pdev);
  471. }
  472. static const struct pci_device_id plx_dma_pci_tbl[] = {
  473. {
  474. .vendor = PCI_VENDOR_ID_PLX,
  475. .device = 0x87D0,
  476. .subvendor = PCI_ANY_ID,
  477. .subdevice = PCI_ANY_ID,
  478. .class = PCI_CLASS_SYSTEM_OTHER << 8,
  479. .class_mask = 0xFFFFFFFF,
  480. },
  481. {0}
  482. };
  483. MODULE_DEVICE_TABLE(pci, plx_dma_pci_tbl);
  484. static struct pci_driver plx_dma_pci_driver = {
  485. .name = KBUILD_MODNAME,
  486. .id_table = plx_dma_pci_tbl,
  487. .probe = plx_dma_probe,
  488. .remove = plx_dma_remove,
  489. };
  490. module_pci_driver(plx_dma_pci_driver);