Skip to content

Commit 138f4c3

Browse files
committed
dmaengine, async_tx: add a "no channel switch" allocator
Channel switching is problematic for some dmaengine drivers as the architecture precludes separating the ->prep from ->submit. In these cases the driver can select ASYNC_TX_DISABLE_CHANNEL_SWITCH to modify the async_tx allocator to only return channels that support all of the required asynchronous operations. For example MD_RAID456=y selects support for asynchronous xor, xor validate, pq, pq validate, and memcpy. When ASYNC_TX_DISABLE_CHANNEL_SWITCH=y any channel with all these capabilities is marked DMA_ASYNC_TX allowing async_tx_find_channel() to quickly locate compatible channels with the guarantee that dependency chains will remain on one channel. When ASYNC_TX_DISABLE_CHANNEL_SWITCH=n async_tx_find_channel() may select channels that lead to operation chains that need to cross channel boundaries using the async_tx channel switch capability. Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 0403e38 commit 138f4c3

4 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎crypto/async_tx/async_tx.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ async_tx_channel_switch(struct dma_async_tx_descriptor *depend_tx,
8181
struct dma_device *device = chan->device;
8282
struct dma_async_tx_descriptor *intr_tx = (void *) ~0;
8383

84+
#ifdef CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH
85+
BUG();
86+
#endif
87+
8488
/* first check to see if we can still append to depend_tx */
8589
spin_lock_bh(&depend_tx->lock);
8690
if (depend_tx->parent && depend_tx->chan == tx->chan) {

‎drivers/dma/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ if DMADEVICES
1717

1818
comment "DMA Devices"
1919

20+
config ASYNC_TX_DISABLE_CHANNEL_SWITCH
21+
bool
22+
2023
config INTEL_IOATDMA
2124
tristate "Intel I/OAT DMA support"
2225
depends on PCI && X86
2326
select DMA_ENGINE
2427
select DCA
28+
select ASYNC_TX_DISABLE_CHANNEL_SWITCH
2529
help
2630
Enable support for the Intel(R) I/OAT DMA engine present
2731
in recent Intel Xeon chipsets.

‎drivers/dma/dmaengine.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,40 @@ void dmaengine_put(void)
608608
}
609609
EXPORT_SYMBOL(dmaengine_put);
610610

611+
static bool device_has_all_tx_types(struct dma_device *device)
612+
{
613+
/* A device that satisfies this test has channels that will never cause
614+
* an async_tx channel switch event as all possible operation types can
615+
* be handled.
616+
*/
617+
#ifdef CONFIG_ASYNC_TX_DMA
618+
if (!dma_has_cap(DMA_INTERRUPT, device->cap_mask))
619+
return false;
620+
#endif
621+
622+
#if defined(CONFIG_ASYNC_MEMCPY) || defined(CONFIG_ASYNC_MEMCPY_MODULE)
623+
if (!dma_has_cap(DMA_MEMCPY, device->cap_mask))
624+
return false;
625+
#endif
626+
627+
#if defined(CONFIG_ASYNC_MEMSET) || defined(CONFIG_ASYNC_MEMSET_MODULE)
628+
if (!dma_has_cap(DMA_MEMSET, device->cap_mask))
629+
return false;
630+
#endif
631+
632+
#if defined(CONFIG_ASYNC_XOR) || defined(CONFIG_ASYNC_XOR_MODULE)
633+
if (!dma_has_cap(DMA_XOR, device->cap_mask))
634+
return false;
635+
#endif
636+
637+
#if defined(CONFIG_ASYNC_PQ) || defined(CONFIG_ASYNC_PQ_MODULE)
638+
if (!dma_has_cap(DMA_PQ, device->cap_mask))
639+
return false;
640+
#endif
641+
642+
return true;
643+
}
644+
611645
static int get_dma_id(struct dma_device *device)
612646
{
613647
int rc;
@@ -665,6 +699,12 @@ int dma_async_device_register(struct dma_device *device)
665699
BUG_ON(!device->device_issue_pending);
666700
BUG_ON(!device->dev);
667701

702+
/* note: this only matters in the
703+
* CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH=y case
704+
*/
705+
if (device_has_all_tx_types(device))
706+
dma_cap_set(DMA_ASYNC_TX, device->cap_mask);
707+
668708
idr_ref = kmalloc(sizeof(*idr_ref), GFP_KERNEL);
669709
if (!idr_ref)
670710
return -ENOMEM;

‎include/linux/dmaengine.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ enum dma_status {
4848

4949
/**
5050
* enum dma_transaction_type - DMA transaction types/indexes
51+
*
52+
* Note: The DMA_ASYNC_TX capability is not to be set by drivers. It is
53+
* automatically set as dma devices are registered.
5154
*/
5255
enum dma_transaction_type {
5356
DMA_MEMCPY,
@@ -61,6 +64,7 @@ enum dma_transaction_type {
6164
DMA_MEMCPY_CRC32C,
6265
DMA_INTERRUPT,
6366
DMA_PRIVATE,
67+
DMA_ASYNC_TX,
6468
DMA_SLAVE,
6569
};
6670

@@ -396,7 +400,11 @@ static inline void net_dmaengine_put(void)
396400
#ifdef CONFIG_ASYNC_TX_DMA
397401
#define async_dmaengine_get() dmaengine_get()
398402
#define async_dmaengine_put() dmaengine_put()
403+
#ifdef CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH
404+
#define async_dma_find_channel(type) dma_find_channel(DMA_ASYNC_TX)
405+
#else
399406
#define async_dma_find_channel(type) dma_find_channel(type)
407+
#endif /* CONFIG_ASYNC_TX_DISABLE_CHANNEL_SWITCH */
400408
#else
401409
static inline void async_dmaengine_get(void)
402410
{
@@ -409,7 +417,7 @@ async_dma_find_channel(enum dma_transaction_type type)
409417
{
410418
return NULL;
411419
}
412-
#endif
420+
#endif /* CONFIG_ASYNC_TX_DMA */
413421

414422
dma_cookie_t dma_async_memcpy_buf_to_buf(struct dma_chan *chan,
415423
void *dest, void *src, size_t len);

0 commit comments

Comments
 (0)