]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firewire: core: add local API to queue work item to workqueue specific to isochronous...
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 4 Sep 2024 12:51:51 +0000 (21:51 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 4 Sep 2024 12:51:51 +0000 (21:51 +0900)
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 <edmund.raile@protonmail.com>
Link: https://lore.kernel.org/r/20240904125155.461886-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-iso.c
drivers/firewire/core.h
include/linux/firewire.h

index 101433b8bb51338563b278f02f0cae16f8286f2f..af76fa1823f1b8e73f052e294d6e89209c4c222f 100644 (file)
@@ -211,21 +211,47 @@ EXPORT_SYMBOL(fw_iso_context_queue_flush);
 
 int fw_iso_context_flush_completions(struct fw_iso_context *ctx)
 {
+       int err;
+
        trace_isoc_outbound_flush_completions(ctx);
        trace_isoc_inbound_single_flush_completions(ctx);
        trace_isoc_inbound_multiple_flush_completions(ctx);
 
-       return ctx->card->driver->flush_iso_completions(ctx);
+       might_sleep();
+
+       // Avoid dead lock due to programming mistake.
+       if (WARN_ON(current_work() == &ctx->work))
+               return 0;
+
+       disable_work_sync(&ctx->work);
+
+       err = ctx->card->driver->flush_iso_completions(ctx);
+
+       enable_work(&ctx->work);
+
+       return err;
 }
 EXPORT_SYMBOL(fw_iso_context_flush_completions);
 
 int fw_iso_context_stop(struct fw_iso_context *ctx)
 {
+       int err;
+
        trace_isoc_outbound_stop(ctx);
        trace_isoc_inbound_single_stop(ctx);
        trace_isoc_inbound_multiple_stop(ctx);
 
-       return ctx->card->driver->stop_iso(ctx);
+       might_sleep();
+
+       // Avoid dead lock due to programming mistake.
+       if (WARN_ON(current_work() == &ctx->work))
+               return 0;
+
+       err = ctx->card->driver->stop_iso(ctx);
+
+       cancel_work_sync(&ctx->work);
+
+       return err;
 }
 EXPORT_SYMBOL(fw_iso_context_stop);
 
index 96ae366889e0e27fb51d3440fbea7b993d72bf5a..2874f316156a63a8eb1eeba8bb88e69fec820b2d 100644 (file)
@@ -159,6 +159,16 @@ int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count);
 int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card,
                          enum dma_data_direction direction);
 
+static inline void fw_iso_context_init_work(struct fw_iso_context *ctx, work_func_t func)
+{
+       INIT_WORK(&ctx->work, func);
+}
+
+static inline void fw_iso_context_queue_work(struct fw_iso_context *ctx)
+{
+       queue_work(ctx->card->isoc_wq, &ctx->work);
+}
+
 
 /* -topology */
 
index 10e135d6082412a6c7e82309f5fb09d3bf9a26ac..72f497b6173914d1e6a362b9fc5f6fe0b670751b 100644 (file)
@@ -511,6 +511,7 @@ union fw_iso_callback {
 
 struct fw_iso_context {
        struct fw_card *card;
+       struct work_struct work;
        int type;
        int channel;
        int speed;