firewire: core: use helper macros instead of direct access to HZ
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 15 Sep 2025 02:42:31 +0000 (11:42 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 15 Sep 2025 02:49:34 +0000 (11:49 +0900)
There are some macros available to convert usecs, msecs, and secs into
jiffies count.

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

index adb9016..2541e8b 100644 (file)
@@ -229,8 +229,7 @@ void fw_schedule_bus_reset(struct fw_card *card, bool delayed, bool short_reset)
 
        /* Use an arbitrary short delay to combine multiple reset requests. */
        fw_card_get(card);
-       if (!queue_delayed_work(fw_workqueue, &card->br_work,
-                               delayed ? DIV_ROUND_UP(HZ, 100) : 0))
+       if (!queue_delayed_work(fw_workqueue, &card->br_work, delayed ? msecs_to_jiffies(10) : 0))
                fw_card_put(card);
 }
 EXPORT_SYMBOL(fw_schedule_bus_reset);
@@ -241,10 +240,10 @@ static void br_work(struct work_struct *work)
 
        /* Delay for 2s after last reset per IEEE 1394 clause 8.2.1. */
        if (card->reset_jiffies != 0 &&
-           time_before64(get_jiffies_64(), card->reset_jiffies + 2 * HZ)) {
+           time_before64(get_jiffies_64(), card->reset_jiffies + secs_to_jiffies(2))) {
                trace_bus_reset_postpone(card->index, card->generation, card->br_short);
 
-               if (!queue_delayed_work(fw_workqueue, &card->br_work, 2 * HZ))
+               if (!queue_delayed_work(fw_workqueue, &card->br_work, secs_to_jiffies(2)))
                        fw_card_put(card);
                return;
        }
@@ -309,8 +308,7 @@ static void bm_work(struct work_struct *work)
        irm_id   = card->irm_node->node_id;
        local_id = card->local_node->node_id;
 
-       grace = time_after64(get_jiffies_64(),
-                            card->reset_jiffies + DIV_ROUND_UP(HZ, 8));
+       grace = time_after64(get_jiffies_64(), card->reset_jiffies + msecs_to_jiffies(125));
 
        if ((is_next_generation(generation, card->bm_generation) &&
             !card->bm_abdicate) ||
@@ -396,7 +394,7 @@ static void bm_work(struct work_struct *work)
                         * that the problem has gone away by then.
                         */
                        spin_unlock_irq(&card->lock);
-                       fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
+                       fw_schedule_bm_work(card, msecs_to_jiffies(125));
                        return;
                }
 
@@ -418,7 +416,7 @@ static void bm_work(struct work_struct *work)
                 * bus reset is less than 125ms ago.  Reschedule this job.
                 */
                spin_unlock_irq(&card->lock);
-               fw_schedule_bm_work(card, DIV_ROUND_UP(HZ, 8));
+               fw_schedule_bm_work(card, msecs_to_jiffies(125));
                return;
        }
 
@@ -551,8 +549,7 @@ void fw_card_initialize(struct fw_card *card,
        card->split_timeout_hi = DEFAULT_SPLIT_TIMEOUT / 8000;
        card->split_timeout_lo = (DEFAULT_SPLIT_TIMEOUT % 8000) << 19;
        card->split_timeout_cycles = DEFAULT_SPLIT_TIMEOUT;
-       card->split_timeout_jiffies =
-                       DIV_ROUND_UP(DEFAULT_SPLIT_TIMEOUT * HZ, 8000);
+       card->split_timeout_jiffies = isoc_cycles_to_jiffies(DEFAULT_SPLIT_TIMEOUT);
        card->color = 0;
        card->broadcast_channel = BROADCAST_CHANNEL_INITIAL;
 
index 78b10c6..9e90c79 100644 (file)
@@ -1324,8 +1324,8 @@ static void iso_resource_work(struct work_struct *work)
                todo = r->todo;
                // Allow 1000ms grace period for other reallocations.
                if (todo == ISO_RES_ALLOC &&
-                   time_before64(get_jiffies_64(), client->device->card->reset_jiffies + HZ)) {
-                       schedule_iso_resource(r, DIV_ROUND_UP(HZ, 3));
+                   time_before64(get_jiffies_64(), client->device->card->reset_jiffies + secs_to_jiffies(1))) {
+                       schedule_iso_resource(r, msecs_to_jiffies(333));
                        skip = true;
                } else {
                        // We could be called twice within the same generation.
index 6a04a00..7d5821c 100644 (file)
@@ -847,9 +847,9 @@ static void fw_schedule_device_work(struct fw_device *device,
  */
 
 #define MAX_RETRIES    10
-#define RETRY_DELAY    (3 * HZ)
-#define INITIAL_DELAY  (HZ / 2)
-#define SHUTDOWN_DELAY (2 * HZ)
+#define RETRY_DELAY    secs_to_jiffies(3)
+#define INITIAL_DELAY  msecs_to_jiffies(500)
+#define SHUTDOWN_DELAY secs_to_jiffies(2)
 
 static void fw_device_shutdown(struct work_struct *work)
 {
index 1d1c2d8..623e1d9 100644 (file)
@@ -458,7 +458,7 @@ static struct fw_packet phy_config_packet = {
 void fw_send_phy_config(struct fw_card *card,
                        int node_id, int generation, int gap_count)
 {
-       long timeout = DIV_ROUND_UP(HZ, 10);
+       long timeout = msecs_to_jiffies(100);
        u32 data = 0;
 
        phy_packet_set_packet_identifier(&data, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG);
@@ -1220,7 +1220,7 @@ static void update_split_timeout(struct fw_card *card)
        cycles = clamp(cycles, 800u, 3u * 8000u);
 
        card->split_timeout_cycles = cycles;
-       card->split_timeout_jiffies = DIV_ROUND_UP(cycles * HZ, 8000);
+       card->split_timeout_jiffies = isoc_cycles_to_jiffies(cycles);
 }
 
 static void handle_registers(struct fw_card *card, struct fw_request *request,
index 9e68ebf..7f2ca93 100644 (file)
@@ -30,6 +30,8 @@ struct fw_packet;
 // This is the arbitrary value we use to indicate a mismatched gap count.
 #define GAP_COUNT_MISMATCHED   0
 
+#define isoc_cycles_to_jiffies(cycles) usecs_to_jiffies(cycles * USEC_PER_SEC / 8000)
+
 extern __printf(2, 3)
 void fw_err(const struct fw_card *card, const char *fmt, ...);
 extern __printf(2, 3)