Skip to content

Commit f067025

Browse files
davejiangVinod Koul
authored andcommitted
dmaengine: add support to provide error result from a DMA transation
Adding a new callback that will provide the error result for a transaction. The result is allocated on the stack and the callback should create a copy if it wishes to retain the information after exiting. The result parameter is now defined and takes over the dummy void pointer we placed in the helper functions previously. dmaengine drivers should start converting to the new "callback_result" callback in order to receive transaction results. Signed-off-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent b1f884a commit f067025

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

drivers/dma/dmaengine.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ static inline void dma_set_residue(struct dma_tx_state *state, u32 residue)
8888

8989
struct dmaengine_desc_callback {
9090
dma_async_tx_callback callback;
91+
dma_async_tx_callback_result callback_result;
9192
void *callback_param;
9293
};
9394

@@ -105,39 +106,50 @@ dmaengine_desc_get_callback(struct dma_async_tx_descriptor *tx,
105106
struct dmaengine_desc_callback *cb)
106107
{
107108
cb->callback = tx->callback;
109+
cb->callback_result = tx->callback_result;
108110
cb->callback_param = tx->callback_param;
109111
}
110112

111113
/**
112114
* dmaengine_desc_callback_invoke - call the callback function in cb struct
113115
* @cb: temp struct that is holding the callback info
114-
* @result: dummy pointer for now
116+
* @result: transaction result
115117
*
116118
* Call the callback function provided in the cb struct with the parameter
117119
* in the cb struct.
118120
* Locking is dependent on the driver.
119121
*/
120122
static inline void
121123
dmaengine_desc_callback_invoke(struct dmaengine_desc_callback *cb,
122-
const void *result)
124+
const struct dmaengine_result *result)
123125
{
124-
if (cb->callback)
126+
struct dmaengine_result dummy_result = {
127+
.result = DMA_TRANS_NOERROR,
128+
.residue = 0
129+
};
130+
131+
if (cb->callback_result) {
132+
if (!result)
133+
result = &dummy_result;
134+
cb->callback_result(cb->callback_param, result);
135+
} else if (cb->callback) {
125136
cb->callback(cb->callback_param);
137+
}
126138
}
127139

128140
/**
129141
* dmaengine_desc_get_callback_invoke - get the callback in tx descriptor and
130142
* then immediately call the callback.
131143
* @tx: dma async tx descriptor
132-
* @result: dummy pointer for now
144+
* @result: transaction result
133145
*
134146
* Call dmaengine_desc_get_callback() and dmaengine_desc_callback_invoke()
135147
* in a single function since no work is necessary in between for the driver.
136148
* Locking is dependent on the driver.
137149
*/
138150
static inline void
139151
dmaengine_desc_get_callback_invoke(struct dma_async_tx_descriptor *tx,
140-
const void *result)
152+
const struct dmaengine_result *result)
141153
{
142154
struct dmaengine_desc_callback cb;
143155

include/linux/dmaengine.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,21 @@ typedef bool (*dma_filter_fn)(struct dma_chan *chan, void *filter_param);
441441

442442
typedef void (*dma_async_tx_callback)(void *dma_async_param);
443443

444+
enum dmaengine_tx_result {
445+
DMA_TRANS_NOERROR = 0, /* SUCCESS */
446+
DMA_TRANS_READ_FAILED, /* Source DMA read failed */
447+
DMA_TRANS_WRITE_FAILED, /* Destination DMA write failed */
448+
DMA_TRANS_ABORTED, /* Op never submitted / aborted */
449+
};
450+
451+
struct dmaengine_result {
452+
enum dmaengine_tx_result result;
453+
u32 residue;
454+
};
455+
456+
typedef void (*dma_async_tx_callback_result)(void *dma_async_param,
457+
const struct dmaengine_result *result);
458+
444459
struct dmaengine_unmap_data {
445460
u8 map_cnt;
446461
u8 to_cnt;
@@ -478,6 +493,7 @@ struct dma_async_tx_descriptor {
478493
dma_cookie_t (*tx_submit)(struct dma_async_tx_descriptor *tx);
479494
int (*desc_free)(struct dma_async_tx_descriptor *tx);
480495
dma_async_tx_callback callback;
496+
dma_async_tx_callback_result callback_result;
481497
void *callback_param;
482498
struct dmaengine_unmap_data *unmap;
483499
#ifdef CONFIG_ASYNC_TX_ENABLE_CHANNEL_SWITCH

0 commit comments

Comments
 (0)