]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firewire: core: allocate workqueue for AR/AT request/response contexts
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 15 Jun 2025 13:32:51 +0000 (22:32 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 15 Jun 2025 13:40:29 +0000 (22:40 +0900)
Some tasklets (softIRQs) are still used as bottom-halves to handle
events for 1394 OHCI AR/AT contexts. However, using softIRQs for IRQ
bottom halves is generally discouraged today.

This commit adds a per-fw_card workqueue to accommodate the behaviour
specified by the 1394 OHCI specification.

According to the 1394 OHCI specification, system memory pages are
reserved for each asynchronous DMA context. This allows concurrent
operation across contexts. In the 1394 OHCI PCI driver implementation,
the hardware generates IRQs either upon receiving asynchronous packets
from other nodes (incoming) or after completing transmission to them
(outgoing). These independent events can occur in the same transmission
cycle, therefore the max_active parameter for the workqueue is set to the
total number of AR/AT contexts (=4). The WQ_UNBOUND flag is used to
allow the work to be scheduled on any available core, since there is
little CPU cache affinity benefit for the data.

Each DMA context uses a circular descriptor list in system memory,
allowing deferred data processing in software as long as buffer overrun
are avoided. Since the overall operation is sleepable except for small
atomic regions, WQ_BH is not used. As the descriptors contain
timestamps, WQ_HIGHPRI is specified to support semi-real-time
processing.

The asynchronous context is also used by the SCSI over IEEE 1394
protocol implementation (sbp2), which can be part of memory reclaim paths.
Therefore, WQ_MEM_RECLAIM is required.

To allow uses to adjust CPU affinity according to workload, WQ_SYSFS is
specified so that workqueue attributes are exposed to user space.

Link: https://lore.kernel.org/r/20250615133253.433057-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
drivers/firewire/core-card.c
include/linux/firewire.h

index 2b6ad47b6d57ac384bb32126b8fc1805aa522b48..b3e48ca516fe29c2fdcda287a139799a8f0ddca0 100644 (file)
@@ -574,7 +574,6 @@ EXPORT_SYMBOL(fw_card_initialize);
 int fw_card_add(struct fw_card *card, u32 max_receive, u32 link_speed, u64 guid,
                unsigned int supported_isoc_contexts)
 {
-       struct workqueue_struct *isoc_wq;
        int ret;
 
        // This workqueue should be:
@@ -589,29 +588,48 @@ int fw_card_add(struct fw_card *card, u32 max_receive, u32 link_speed, u64 guid,
        //  * == WQ_SYSFS               Parameters are available via sysfs.
        //  * max_active == n_it + n_ir A hardIRQ could notify events for multiple isochronous
        //                              contexts if they are scheduled to the same cycle.
-       isoc_wq = alloc_workqueue("firewire-isoc-card%u",
-                                 WQ_UNBOUND | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS,
-                                 supported_isoc_contexts, card->index);
-       if (!isoc_wq)
+       card->isoc_wq = alloc_workqueue("firewire-isoc-card%u",
+                                       WQ_UNBOUND | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS,
+                                       supported_isoc_contexts, card->index);
+       if (!card->isoc_wq)
                return -ENOMEM;
 
+       // This workqueue should be:
+       //  * != WQ_BH                  Sleepable.
+       //  * == WQ_UNBOUND             Any core can process data for asynchronous context.
+       //  * == WQ_MEM_RECLAIM         Used for any backend of block device.
+       //  * == WQ_FREEZABLE           The target device would not be available when being freezed.
+       //  * == WQ_HIGHPRI             High priority to process semi-realtime timestamped data.
+       //  * == WQ_SYSFS               Parameters are available via sysfs.
+       //  * max_active == 4           A hardIRQ could notify events for a pair of requests and
+       //                              response AR/AT contexts.
+       card->async_wq = alloc_workqueue("firewire-async-card%u",
+                                        WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_HIGHPRI | WQ_SYSFS,
+                                        4, card->index);
+       if (!card->async_wq) {
+               ret = -ENOMEM;
+               goto err_isoc;
+       }
+
        card->max_receive = max_receive;
        card->link_speed = link_speed;
        card->guid = guid;
 
-       guard(mutex)(&card_mutex);
+       scoped_guard(mutex, &card_mutex) {
+               generate_config_rom(card, tmp_config_rom);
+               ret = card->driver->enable(card, tmp_config_rom, config_rom_length);
+               if (ret < 0)
+                       goto err_async;
 
-       generate_config_rom(card, tmp_config_rom);
-       ret = card->driver->enable(card, tmp_config_rom, config_rom_length);
-       if (ret < 0) {
-               destroy_workqueue(isoc_wq);
-               return ret;
+               list_add_tail(&card->link, &card_list);
        }
 
-       card->isoc_wq = isoc_wq;
-       list_add_tail(&card->link, &card_list);
-
        return 0;
+err_async:
+       destroy_workqueue(card->async_wq);
+err_isoc:
+       destroy_workqueue(card->isoc_wq);
+       return ret;
 }
 EXPORT_SYMBOL(fw_card_add);
 
@@ -744,6 +762,7 @@ void fw_core_remove_card(struct fw_card *card)
        dummy_driver.stop_iso           = card->driver->stop_iso;
        card->driver = &dummy_driver;
        drain_workqueue(card->isoc_wq);
+       drain_workqueue(card->async_wq);
 
        scoped_guard(spinlock_irqsave, &card->lock)
                fw_destroy_nodes(card);
@@ -753,6 +772,7 @@ void fw_core_remove_card(struct fw_card *card)
        wait_for_completion(&card->done);
 
        destroy_workqueue(card->isoc_wq);
+       destroy_workqueue(card->async_wq);
 
        WARN_ON(!list_empty(&card->transaction_list));
 }
index b632eec3ab5263c6da62dfe63d0f0bc263a94893..c55b8e30e700dad5f6d2360d71a756dddb33506f 100644 (file)
@@ -136,6 +136,7 @@ struct fw_card {
        __be32 maint_utility_register;
 
        struct workqueue_struct *isoc_wq;
+       struct workqueue_struct *async_wq;
 };
 
 static inline struct fw_card *fw_card_get(struct fw_card *card)