Skip to content

Commit a08abd8

Browse files
committed
async_tx: structify submission arguments, add scribble
Prepare the api for the arrival of a new parameter, 'scribble'. This will allow callers to identify scratchpad memory for dma address or page address conversions. As this adds yet another parameter, take this opportunity to convert the common submission parameters (flags, dependency, callback, and callback argument) into an object that is passed by reference. Also, take this opportunity to fix up the kerneldoc and add notes about the relevant ASYNC_TX_* flags for each routine. [ Impact: moves api pass-by-value parameters to a pass-by-reference struct ] Signed-off-by: Andre Noll <maan@systemlinux.org> Acked-by: Maciej Sosnowski <maciej.sosnowski@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 88ba2aa commit a08abd8

7 files changed

Lines changed: 200 additions & 174 deletions

File tree

‎Documentation/crypto/async-tx-api.txt‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ features surfaced as a result:
5454

5555
3.1 General format of the API:
5656
struct dma_async_tx_descriptor *
57-
async_<operation>(<op specific parameters>,
58-
enum async_tx_flags flags,
59-
struct dma_async_tx_descriptor *dependency,
60-
dma_async_tx_callback callback_routine,
61-
void *callback_parameter);
57+
async_<operation>(<op specific parameters>, struct async_submit ctl *submit)
6258

6359
3.2 Supported operations:
6460
memcpy - memory copy between a source and a destination buffer

‎crypto/async_tx/async_memcpy.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@
3333
* async_memcpy - attempt to copy memory with a dma engine.
3434
* @dest: destination page
3535
* @src: src page
36-
* @offset: offset in pages to start transaction
36+
* @dest_offset: offset into 'dest' to start transaction
37+
* @src_offset: offset into 'src' to start transaction
3738
* @len: length in bytes
38-
* @flags: ASYNC_TX_ACK
39-
* @depend_tx: memcpy depends on the result of this transaction
40-
* @cb_fn: function to call when the memcpy completes
41-
* @cb_param: parameter to pass to the callback routine
39+
* @submit: submission / completion modifiers
40+
*
41+
* honored flags: ASYNC_TX_ACK
4242
*/
4343
struct dma_async_tx_descriptor *
4444
async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
45-
unsigned int src_offset, size_t len, enum async_tx_flags flags,
46-
struct dma_async_tx_descriptor *depend_tx,
47-
dma_async_tx_callback cb_fn, void *cb_param)
45+
unsigned int src_offset, size_t len,
46+
struct async_submit_ctl *submit)
4847
{
49-
struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMCPY,
48+
struct dma_chan *chan = async_tx_find_channel(submit, DMA_MEMCPY,
5049
&dest, 1, &src, 1, len);
5150
struct dma_device *device = chan ? chan->device : NULL;
5251
struct dma_async_tx_descriptor *tx = NULL;
5352

5453
if (device) {
5554
dma_addr_t dma_dest, dma_src;
56-
unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
55+
unsigned long dma_prep_flags;
5756

57+
dma_prep_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
5858
dma_dest = dma_map_page(device->dev, dest, dest_offset, len,
5959
DMA_FROM_DEVICE);
6060

@@ -67,13 +67,13 @@ async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
6767

6868
if (tx) {
6969
pr_debug("%s: (async) len: %zu\n", __func__, len);
70-
async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
70+
async_tx_submit(chan, tx, submit);
7171
} else {
7272
void *dest_buf, *src_buf;
7373
pr_debug("%s: (sync) len: %zu\n", __func__, len);
7474

7575
/* wait for any prerequisite operations */
76-
async_tx_quiesce(&depend_tx);
76+
async_tx_quiesce(&submit->depend_tx);
7777

7878
dest_buf = kmap_atomic(dest, KM_USER0) + dest_offset;
7979
src_buf = kmap_atomic(src, KM_USER1) + src_offset;
@@ -83,7 +83,7 @@ async_memcpy(struct page *dest, struct page *src, unsigned int dest_offset,
8383
kunmap_atomic(dest_buf, KM_USER0);
8484
kunmap_atomic(src_buf, KM_USER1);
8585

86-
async_tx_sync_epilog(cb_fn, cb_param);
86+
async_tx_sync_epilog(submit);
8787
}
8888

8989
return tx;

‎crypto/async_tx/async_memset.c‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,23 @@
3535
* @val: fill value
3636
* @offset: offset in pages to start transaction
3737
* @len: length in bytes
38-
* @flags: ASYNC_TX_ACK
39-
* @depend_tx: memset depends on the result of this transaction
40-
* @cb_fn: function to call when the memcpy completes
41-
* @cb_param: parameter to pass to the callback routine
38+
*
39+
* honored flags: ASYNC_TX_ACK
4240
*/
4341
struct dma_async_tx_descriptor *
44-
async_memset(struct page *dest, int val, unsigned int offset,
45-
size_t len, enum async_tx_flags flags,
46-
struct dma_async_tx_descriptor *depend_tx,
47-
dma_async_tx_callback cb_fn, void *cb_param)
42+
async_memset(struct page *dest, int val, unsigned int offset, size_t len,
43+
struct async_submit_ctl *submit)
4844
{
49-
struct dma_chan *chan = async_tx_find_channel(depend_tx, DMA_MEMSET,
45+
struct dma_chan *chan = async_tx_find_channel(submit, DMA_MEMSET,
5046
&dest, 1, NULL, 0, len);
5147
struct dma_device *device = chan ? chan->device : NULL;
5248
struct dma_async_tx_descriptor *tx = NULL;
5349

5450
if (device) {
5551
dma_addr_t dma_dest;
56-
unsigned long dma_prep_flags = cb_fn ? DMA_PREP_INTERRUPT : 0;
52+
unsigned long dma_prep_flags;
5753

54+
dma_prep_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
5855
dma_dest = dma_map_page(device->dev, dest, offset, len,
5956
DMA_FROM_DEVICE);
6057

@@ -64,19 +61,19 @@ async_memset(struct page *dest, int val, unsigned int offset,
6461

6562
if (tx) {
6663
pr_debug("%s: (async) len: %zu\n", __func__, len);
67-
async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
64+
async_tx_submit(chan, tx, submit);
6865
} else { /* run the memset synchronously */
6966
void *dest_buf;
7067
pr_debug("%s: (sync) len: %zu\n", __func__, len);
7168

72-
dest_buf = (void *) (((char *) page_address(dest)) + offset);
69+
dest_buf = page_address(dest) + offset;
7370

7471
/* wait for any prerequisite operations */
75-
async_tx_quiesce(&depend_tx);
72+
async_tx_quiesce(&submit->depend_tx);
7673

7774
memset(dest_buf, val, len);
7875

79-
async_tx_sync_epilog(cb_fn, cb_param);
76+
async_tx_sync_epilog(submit);
8077
}
8178

8279
return tx;

‎crypto/async_tx/async_tx.c‎

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ static void __exit async_tx_exit(void)
4545
/**
4646
* __async_tx_find_channel - find a channel to carry out the operation or let
4747
* the transaction execute synchronously
48-
* @depend_tx: transaction dependency
48+
* @submit: transaction dependency and submission modifiers
4949
* @tx_type: transaction type
5050
*/
5151
struct dma_chan *
52-
__async_tx_find_channel(struct dma_async_tx_descriptor *depend_tx,
53-
enum dma_transaction_type tx_type)
52+
__async_tx_find_channel(struct async_submit_ctl *submit,
53+
enum dma_transaction_type tx_type)
5454
{
55+
struct dma_async_tx_descriptor *depend_tx = submit->depend_tx;
56+
5557
/* see if we can keep the chain on one channel */
5658
if (depend_tx &&
5759
dma_has_cap(tx_type, depend_tx->chan->device->cap_mask))
@@ -144,13 +146,14 @@ async_tx_channel_switch(struct dma_async_tx_descriptor *depend_tx,
144146

145147

146148
/**
147-
* submit_disposition - while holding depend_tx->lock we must avoid submitting
148-
* new operations to prevent a circular locking dependency with
149-
* drivers that already hold a channel lock when calling
150-
* async_tx_run_dependencies.
149+
* submit_disposition - flags for routing an incoming operation
151150
* @ASYNC_TX_SUBMITTED: we were able to append the new operation under the lock
152151
* @ASYNC_TX_CHANNEL_SWITCH: when the lock is dropped schedule a channel switch
153152
* @ASYNC_TX_DIRECT_SUBMIT: when the lock is dropped submit directly
153+
*
154+
* while holding depend_tx->lock we must avoid submitting new operations
155+
* to prevent a circular locking dependency with drivers that already
156+
* hold a channel lock when calling async_tx_run_dependencies.
154157
*/
155158
enum submit_disposition {
156159
ASYNC_TX_SUBMITTED,
@@ -160,11 +163,12 @@ enum submit_disposition {
160163

161164
void
162165
async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
163-
enum async_tx_flags flags, struct dma_async_tx_descriptor *depend_tx,
164-
dma_async_tx_callback cb_fn, void *cb_param)
166+
struct async_submit_ctl *submit)
165167
{
166-
tx->callback = cb_fn;
167-
tx->callback_param = cb_param;
168+
struct dma_async_tx_descriptor *depend_tx = submit->depend_tx;
169+
170+
tx->callback = submit->cb_fn;
171+
tx->callback_param = submit->cb_param;
168172

169173
if (depend_tx) {
170174
enum submit_disposition s;
@@ -220,7 +224,7 @@ async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
220224
tx->tx_submit(tx);
221225
}
222226

223-
if (flags & ASYNC_TX_ACK)
227+
if (submit->flags & ASYNC_TX_ACK)
224228
async_tx_ack(tx);
225229

226230
if (depend_tx)
@@ -229,21 +233,20 @@ async_tx_submit(struct dma_chan *chan, struct dma_async_tx_descriptor *tx,
229233
EXPORT_SYMBOL_GPL(async_tx_submit);
230234

231235
/**
232-
* async_trigger_callback - schedules the callback function to be run after
233-
* any dependent operations have been completed.
234-
* @flags: ASYNC_TX_ACK
235-
* @depend_tx: 'callback' requires the completion of this transaction
236-
* @cb_fn: function to call after depend_tx completes
237-
* @cb_param: parameter to pass to the callback routine
236+
* async_trigger_callback - schedules the callback function to be run
237+
* @submit: submission and completion parameters
238+
*
239+
* honored flags: ASYNC_TX_ACK
240+
*
241+
* The callback is run after any dependent operations have completed.
238242
*/
239243
struct dma_async_tx_descriptor *
240-
async_trigger_callback(enum async_tx_flags flags,
241-
struct dma_async_tx_descriptor *depend_tx,
242-
dma_async_tx_callback cb_fn, void *cb_param)
244+
async_trigger_callback(struct async_submit_ctl *submit)
243245
{
244246
struct dma_chan *chan;
245247
struct dma_device *device;
246248
struct dma_async_tx_descriptor *tx;
249+
struct dma_async_tx_descriptor *depend_tx = submit->depend_tx;
247250

248251
if (depend_tx) {
249252
chan = depend_tx->chan;
@@ -262,14 +265,14 @@ async_trigger_callback(enum async_tx_flags flags,
262265
if (tx) {
263266
pr_debug("%s: (async)\n", __func__);
264267

265-
async_tx_submit(chan, tx, flags, depend_tx, cb_fn, cb_param);
268+
async_tx_submit(chan, tx, submit);
266269
} else {
267270
pr_debug("%s: (sync)\n", __func__);
268271

269272
/* wait for any prerequisite operations */
270-
async_tx_quiesce(&depend_tx);
273+
async_tx_quiesce(&submit->depend_tx);
271274

272-
async_tx_sync_epilog(cb_fn, cb_param);
275+
async_tx_sync_epilog(submit);
273276
}
274277

275278
return tx;

0 commit comments

Comments
 (0)