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