Skip to content

Commit 4f55ad7

Browse files
committed
firewire: core: add local API to queue work item to workqueue specific to isochronous contexts
In the previous commit, the workqueue is added per the instance of fw_card structure for isochronous contexts. The workqueue is designed to be used by the implementation of fw_card_driver structure underlying the fw_card. This commit adds some local APIs to be used by the implementation. Tested-by: Edmund Raile <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent c6fb88a commit 4f55ad7

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

drivers/firewire/core-iso.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,47 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush);
211211

212212
int fw_iso_context_flush_completions(struct fw_iso_context *ctx)
213213
{
214+
int err;
215+
214216
trace_isoc_outbound_flush_completions(ctx);
215217
trace_isoc_inbound_single_flush_completions(ctx);
216218
trace_isoc_inbound_multiple_flush_completions(ctx);
217219

218-
return ctx->card->driver->flush_iso_completions(ctx);
220+
might_sleep();
221+
222+
// Avoid dead lock due to programming mistake.
223+
if (WARN_ON(current_work() == &ctx->work))
224+
return 0;
225+
226+
disable_work_sync(&ctx->work);
227+
228+
err = ctx->card->driver->flush_iso_completions(ctx);
229+
230+
enable_work(&ctx->work);
231+
232+
return err;
219233
}
220234
EXPORT_SYMBOL(fw_iso_context_flush_completions);
221235

222236
int fw_iso_context_stop(struct fw_iso_context *ctx)
223237
{
238+
int err;
239+
224240
trace_isoc_outbound_stop(ctx);
225241
trace_isoc_inbound_single_stop(ctx);
226242
trace_isoc_inbound_multiple_stop(ctx);
227243

228-
return ctx->card->driver->stop_iso(ctx);
244+
might_sleep();
245+
246+
// Avoid dead lock due to programming mistake.
247+
if (WARN_ON(current_work() == &ctx->work))
248+
return 0;
249+
250+
err = ctx->card->driver->stop_iso(ctx);
251+
252+
cancel_work_sync(&ctx->work);
253+
254+
return err;
229255
}
230256
EXPORT_SYMBOL(fw_iso_context_stop);
231257

drivers/firewire/core.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count);
159159
int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card,
160160
enum dma_data_direction direction);
161161

162+
static inline void fw_iso_context_init_work(struct fw_iso_context *ctx, work_func_t func)
163+
{
164+
INIT_WORK(&ctx->work, func);
165+
}
166+
167+
static inline void fw_iso_context_queue_work(struct fw_iso_context *ctx)
168+
{
169+
queue_work(ctx->card->isoc_wq, &ctx->work);
170+
}
171+
162172

163173
/* -topology */
164174

include/linux/firewire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ union fw_iso_callback {
511511

512512
struct fw_iso_context {
513513
struct fw_card *card;
514+
struct work_struct work;
514515
int type;
515516
int channel;
516517
int speed;

0 commit comments

Comments
 (0)