Lines Matching refs:plxdev

129 static struct plx_dma_desc *plx_dma_get_desc(struct plx_dma_dev *plxdev, int i)  in plx_dma_get_desc()  argument
131 return plxdev->desc_ring[i & (PLX_DMA_RING_COUNT - 1)]; in plx_dma_get_desc()
134 static void plx_dma_process_desc(struct plx_dma_dev *plxdev) in plx_dma_process_desc() argument
140 spin_lock(&plxdev->ring_lock); in plx_dma_process_desc()
142 while (plxdev->tail != plxdev->head) { in plx_dma_process_desc()
143 desc = plx_dma_get_desc(plxdev, plxdev->tail); in plx_dma_process_desc()
165 plxdev->tail++; in plx_dma_process_desc()
168 spin_unlock(&plxdev->ring_lock); in plx_dma_process_desc()
171 static void plx_dma_abort_desc(struct plx_dma_dev *plxdev) in plx_dma_abort_desc() argument
176 plx_dma_process_desc(plxdev); in plx_dma_abort_desc()
178 spin_lock_bh(&plxdev->ring_lock); in plx_dma_abort_desc()
180 while (plxdev->tail != plxdev->head) { in plx_dma_abort_desc()
181 desc = plx_dma_get_desc(plxdev, plxdev->tail); in plx_dma_abort_desc()
192 plxdev->tail++; in plx_dma_abort_desc()
195 spin_unlock_bh(&plxdev->ring_lock); in plx_dma_abort_desc()
198 static void __plx_dma_stop(struct plx_dma_dev *plxdev) in __plx_dma_stop() argument
203 val = readl(plxdev->bar + PLX_REG_CTRL); in __plx_dma_stop()
208 plxdev->bar + PLX_REG_CTRL); in __plx_dma_stop()
211 val = readl(plxdev->bar + PLX_REG_CTRL); in __plx_dma_stop()
219 dev_err(plxdev->dma_dev.dev, in __plx_dma_stop()
223 plxdev->bar + PLX_REG_CTRL); in __plx_dma_stop()
225 writel(0, plxdev->bar + PLX_REG_DESC_RING_COUNT); in __plx_dma_stop()
226 writel(0, plxdev->bar + PLX_REG_DESC_RING_ADDR); in __plx_dma_stop()
227 writel(0, plxdev->bar + PLX_REG_DESC_RING_ADDR_HI); in __plx_dma_stop()
228 writel(0, plxdev->bar + PLX_REG_DESC_RING_NEXT_ADDR); in __plx_dma_stop()
231 static void plx_dma_stop(struct plx_dma_dev *plxdev) in plx_dma_stop() argument
234 if (!rcu_dereference(plxdev->pdev)) { in plx_dma_stop()
239 __plx_dma_stop(plxdev); in plx_dma_stop()
246 struct plx_dma_dev *plxdev = from_tasklet(plxdev, t, desc_task); in plx_dma_desc_task() local
248 plx_dma_process_desc(plxdev); in plx_dma_desc_task()
254 __acquires(plxdev->ring_lock) in plx_dma_prep_memcpy()
256 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(c); in plx_dma_prep_memcpy() local
259 spin_lock_bh(&plxdev->ring_lock); in plx_dma_prep_memcpy()
260 if (!plxdev->ring_active) in plx_dma_prep_memcpy()
263 if (!CIRC_SPACE(plxdev->head, plxdev->tail, PLX_DMA_RING_COUNT)) in plx_dma_prep_memcpy()
269 plxdesc = plx_dma_get_desc(plxdev, plxdev->head); in plx_dma_prep_memcpy()
270 plxdev->head++; in plx_dma_prep_memcpy()
294 __acquire(plxdev->ring_lock); in plx_dma_prep_memcpy()
296 spin_unlock_bh(&plxdev->ring_lock); in plx_dma_prep_memcpy()
301 __releases(plxdev->ring_lock) in plx_dma_tx_submit()
303 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(desc->chan); in plx_dma_tx_submit() local
317 spin_unlock_bh(&plxdev->ring_lock); in plx_dma_tx_submit()
325 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan); in plx_dma_tx_status() local
332 plx_dma_process_desc(plxdev); in plx_dma_tx_status()
339 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan); in plx_dma_issue_pending() local
342 if (!rcu_dereference(plxdev->pdev)) { in plx_dma_issue_pending()
353 writew(PLX_REG_CTRL_START_VAL, plxdev->bar + PLX_REG_CTRL); in plx_dma_issue_pending()
360 struct plx_dma_dev *plxdev = devid; in plx_dma_isr() local
363 status = readw(plxdev->bar + PLX_REG_INTR_STATUS); in plx_dma_isr()
368 if (status & PLX_REG_INTR_STATUS_DESC_DONE && plxdev->ring_active) in plx_dma_isr()
369 tasklet_schedule(&plxdev->desc_task); in plx_dma_isr()
371 writew(status, plxdev->bar + PLX_REG_INTR_STATUS); in plx_dma_isr()
376 static int plx_dma_alloc_desc(struct plx_dma_dev *plxdev) in plx_dma_alloc_desc() argument
381 plxdev->desc_ring = kcalloc(PLX_DMA_RING_COUNT, in plx_dma_alloc_desc()
382 sizeof(*plxdev->desc_ring), GFP_KERNEL); in plx_dma_alloc_desc()
383 if (!plxdev->desc_ring) in plx_dma_alloc_desc()
391 dma_async_tx_descriptor_init(&desc->txd, &plxdev->dma_chan); in plx_dma_alloc_desc()
393 desc->hw = &plxdev->hw_ring[i]; in plx_dma_alloc_desc()
395 plxdev->desc_ring[i] = desc; in plx_dma_alloc_desc()
402 kfree(plxdev->desc_ring[i]); in plx_dma_alloc_desc()
403 kfree(plxdev->desc_ring); in plx_dma_alloc_desc()
409 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan); in plx_dma_alloc_chan_resources() local
410 size_t ring_sz = PLX_DMA_RING_COUNT * sizeof(*plxdev->hw_ring); in plx_dma_alloc_chan_resources()
413 plxdev->head = plxdev->tail = 0; in plx_dma_alloc_chan_resources()
414 plxdev->hw_ring = dma_alloc_coherent(plxdev->dma_dev.dev, ring_sz, in plx_dma_alloc_chan_resources()
415 &plxdev->hw_ring_dma, GFP_KERNEL); in plx_dma_alloc_chan_resources()
416 if (!plxdev->hw_ring) in plx_dma_alloc_chan_resources()
419 rc = plx_dma_alloc_desc(plxdev); in plx_dma_alloc_chan_resources()
424 if (!rcu_dereference(plxdev->pdev)) { in plx_dma_alloc_chan_resources()
430 writel(PLX_REG_CTRL_RESET_VAL, plxdev->bar + PLX_REG_CTRL); in plx_dma_alloc_chan_resources()
431 writel(lower_32_bits(plxdev->hw_ring_dma), in plx_dma_alloc_chan_resources()
432 plxdev->bar + PLX_REG_DESC_RING_ADDR); in plx_dma_alloc_chan_resources()
433 writel(upper_32_bits(plxdev->hw_ring_dma), in plx_dma_alloc_chan_resources()
434 plxdev->bar + PLX_REG_DESC_RING_ADDR_HI); in plx_dma_alloc_chan_resources()
435 writel(lower_32_bits(plxdev->hw_ring_dma), in plx_dma_alloc_chan_resources()
436 plxdev->bar + PLX_REG_DESC_RING_NEXT_ADDR); in plx_dma_alloc_chan_resources()
437 writel(PLX_DMA_RING_COUNT, plxdev->bar + PLX_REG_DESC_RING_COUNT); in plx_dma_alloc_chan_resources()
438 writel(PLX_REG_PREF_LIMIT_PREF_FOUR, plxdev->bar + PLX_REG_PREF_LIMIT); in plx_dma_alloc_chan_resources()
440 plxdev->ring_active = true; in plx_dma_alloc_chan_resources()
447 dma_free_coherent(plxdev->dma_dev.dev, ring_sz, plxdev->hw_ring, in plx_dma_alloc_chan_resources()
448 plxdev->hw_ring_dma); in plx_dma_alloc_chan_resources()
454 struct plx_dma_dev *plxdev = chan_to_plx_dma_dev(chan); in plx_dma_free_chan_resources() local
455 size_t ring_sz = PLX_DMA_RING_COUNT * sizeof(*plxdev->hw_ring); in plx_dma_free_chan_resources()
460 spin_lock_bh(&plxdev->ring_lock); in plx_dma_free_chan_resources()
461 plxdev->ring_active = false; in plx_dma_free_chan_resources()
462 spin_unlock_bh(&plxdev->ring_lock); in plx_dma_free_chan_resources()
464 plx_dma_stop(plxdev); in plx_dma_free_chan_resources()
467 pdev = rcu_dereference(plxdev->pdev); in plx_dma_free_chan_resources()
475 tasklet_kill(&plxdev->desc_task); in plx_dma_free_chan_resources()
477 plx_dma_abort_desc(plxdev); in plx_dma_free_chan_resources()
480 kfree(plxdev->desc_ring[i]); in plx_dma_free_chan_resources()
482 kfree(plxdev->desc_ring); in plx_dma_free_chan_resources()
483 dma_free_coherent(plxdev->dma_dev.dev, ring_sz, plxdev->hw_ring, in plx_dma_free_chan_resources()
484 plxdev->hw_ring_dma); in plx_dma_free_chan_resources()
490 struct plx_dma_dev *plxdev = in plx_dma_release() local
494 kfree(plxdev); in plx_dma_release()
499 struct plx_dma_dev *plxdev; in plx_dma_create() local
504 plxdev = kzalloc(sizeof(*plxdev), GFP_KERNEL); in plx_dma_create()
505 if (!plxdev) in plx_dma_create()
509 KBUILD_MODNAME, plxdev); in plx_dma_create()
513 spin_lock_init(&plxdev->ring_lock); in plx_dma_create()
514 tasklet_setup(&plxdev->desc_task, plx_dma_desc_task); in plx_dma_create()
516 RCU_INIT_POINTER(plxdev->pdev, pdev); in plx_dma_create()
517 plxdev->bar = pcim_iomap_table(pdev)[0]; in plx_dma_create()
519 dma = &plxdev->dma_dev; in plx_dma_create()
532 chan = &plxdev->dma_chan; in plx_dma_create()
543 pci_set_drvdata(pdev, plxdev); in plx_dma_create()
549 free_irq(pci_irq_vector(pdev, 0), plxdev); in plx_dma_create()
551 kfree(plxdev); in plx_dma_create()
596 struct plx_dma_dev *plxdev = pci_get_drvdata(pdev); in plx_dma_remove() local
598 free_irq(pci_irq_vector(pdev, 0), plxdev); in plx_dma_remove()
600 rcu_assign_pointer(plxdev->pdev, NULL); in plx_dma_remove()
603 spin_lock_bh(&plxdev->ring_lock); in plx_dma_remove()
604 plxdev->ring_active = false; in plx_dma_remove()
605 spin_unlock_bh(&plxdev->ring_lock); in plx_dma_remove()
607 __plx_dma_stop(plxdev); in plx_dma_remove()
608 plx_dma_abort_desc(plxdev); in plx_dma_remove()
610 plxdev->bar = NULL; in plx_dma_remove()
611 dma_async_device_unregister(&plxdev->dma_dev); in plx_dma_remove()