* [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work
@ 2025-09-13 10:57 Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 1/2] firewire: core: use macro expression for gap count mismatch Takashi Sakamoto
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-13 10:57 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
Hi,
Some magic numbers are used for bus manager work. This patchset adds
some macros to replace the magic numbers.
* 0x3f: BUS_MANAGER_ID_NOT_REGISTERED
* 0: GAP_COUNT_MISMATCHED
Takashi Sakamoto (2):
firewire: core: use macro expression for gap count mismatch
firewire: core: use macro expression for not-registered state of
BUS_MANAGER_ID
drivers/firewire/core-card.c | 14 +++++++++-----
drivers/firewire/core-topology.c | 2 +-
drivers/firewire/core.h | 6 ++++++
3 files changed, 16 insertions(+), 6 deletions(-)
base-commit: 136d8a6f73fee0686d163dca91fdffb35e25f092
--
2.48.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] firewire: core: use macro expression for gap count mismatch
2025-09-13 10:57 [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
@ 2025-09-13 10:57 ` Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 2/2] firewire: core: use macro expression for not-registered state of BUS_MANAGER_ID Takashi Sakamoto
2025-09-14 11:08 ` [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
2 siblings, 0 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-13 10:57 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
The gap_count field is assigned to zero when mismatch is detected. In such
case, the macro expression is preferable since it is easy to understand
the situation.
This commit applies the idea.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
drivers/firewire/core-card.c | 2 +-
drivers/firewire/core-topology.c | 2 +-
drivers/firewire/core.h | 3 +++
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
index 32cf6b3344cd..bf2e7f55b83e 100644
--- a/drivers/firewire/core-card.c
+++ b/drivers/firewire/core-card.c
@@ -425,7 +425,7 @@ static void bm_work(struct work_struct *work)
*/
card->bm_generation = generation;
- if (card->gap_count == 0) {
+ if (card->gap_count == GAP_COUNT_MISMATCHED) {
/*
* If self IDs have inconsistent gap counts, do a
* bus reset ASAP. The config rom read might never
diff --git a/drivers/firewire/core-topology.c b/drivers/firewire/core-topology.c
index 74a6aa7d8cc9..5f8fb1201d80 100644
--- a/drivers/firewire/core-topology.c
+++ b/drivers/firewire/core-topology.c
@@ -241,7 +241,7 @@ static struct fw_node *build_tree(struct fw_card *card, const u32 *sid, int self
// If PHYs report different gap counts, set an invalid count which will force a gap
// count reconfiguration and a reset.
if (phy_packet_self_id_zero_get_gap_count(self_id_sequence[0]) != gap_count)
- gap_count = 0;
+ gap_count = GAP_COUNT_MISMATCHED;
update_hop_count(node);
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
index 083e39034c37..79eb57fd5812 100644
--- a/drivers/firewire/core.h
+++ b/drivers/firewire/core.h
@@ -27,6 +27,9 @@ struct fw_packet;
/* -card */
+// This is the arbitrary value we use to indicate a mismatched gap count.
+#define GAP_COUNT_MISMATCHED 0
+
extern __printf(2, 3)
void fw_err(const struct fw_card *card, const char *fmt, ...);
extern __printf(2, 3)
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] firewire: core: use macro expression for not-registered state of BUS_MANAGER_ID
2025-09-13 10:57 [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 1/2] firewire: core: use macro expression for gap count mismatch Takashi Sakamoto
@ 2025-09-13 10:57 ` Takashi Sakamoto
2025-09-14 11:08 ` [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
2 siblings, 0 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-13 10:57 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
The value of BUS_MANAGER_ID register has 0x3f when no node_id is
registered. Current implementation uses hard-coded numeric literal but
in the case the macro expression is preferable since it is easy to
distinguish the state from node ID mask.
This commit applies the idea.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
drivers/firewire/core-card.c | 12 ++++++++----
drivers/firewire/core.h | 3 +++
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
index bf2e7f55b83e..adb90161c4c6 100644
--- a/drivers/firewire/core-card.c
+++ b/drivers/firewire/core-card.c
@@ -327,7 +327,7 @@ static void bm_work(struct work_struct *work)
* next generation.
*/
__be32 data[2] = {
- cpu_to_be32(0x3f),
+ cpu_to_be32(BUS_MANAGER_ID_NOT_REGISTERED),
cpu_to_be32(local_id),
};
struct fw_device *irm_device = fw_node_get_device(card->irm_node);
@@ -372,10 +372,14 @@ static void bm_work(struct work_struct *work)
if (rcode == RCODE_COMPLETE) {
int bm_id = be32_to_cpu(data[0]);
- if (generation == card->generation)
- card->bm_node_id = bm_id == 0x3f ? local_id : 0xffc0 | bm_id;
+ if (generation == card->generation) {
+ if (bm_id != BUS_MANAGER_ID_NOT_REGISTERED)
+ card->bm_node_id = 0xffc0 & bm_id;
+ else
+ card->bm_node_id = local_id;
+ }
- if (bm_id != 0x3f) {
+ if (bm_id != BUS_MANAGER_ID_NOT_REGISTERED) {
spin_unlock_irq(&card->lock);
// Somebody else is BM. Only act as IRM.
diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
index 79eb57fd5812..9e68ebf0673d 100644
--- a/drivers/firewire/core.h
+++ b/drivers/firewire/core.h
@@ -170,6 +170,9 @@ static inline void fw_iso_context_init_work(struct fw_iso_context *ctx, work_fun
/* -topology */
+// The initial value of BUS_MANAGER_ID register, to express nothing registered.
+#define BUS_MANAGER_ID_NOT_REGISTERED 0x3f
+
enum {
FW_NODE_CREATED,
FW_NODE_UPDATED,
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work
2025-09-13 10:57 [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 1/2] firewire: core: use macro expression for gap count mismatch Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 2/2] firewire: core: use macro expression for not-registered state of BUS_MANAGER_ID Takashi Sakamoto
@ 2025-09-14 11:08 ` Takashi Sakamoto
2 siblings, 0 replies; 4+ messages in thread
From: Takashi Sakamoto @ 2025-09-14 11:08 UTC (permalink / raw)
To: linux1394-devel; +Cc: linux-kernel
On Sat, Sep 13, 2025 at 07:57:35PM +0900, Takashi Sakamoto wrote:
> Hi,
>
> Some magic numbers are used for bus manager work. This patchset adds
> some macros to replace the magic numbers.
>
> * 0x3f: BUS_MANAGER_ID_NOT_REGISTERED
> * 0: GAP_COUNT_MISMATCHED
>
> Takashi Sakamoto (2):
> firewire: core: use macro expression for gap count mismatch
> firewire: core: use macro expression for not-registered state of
> BUS_MANAGER_ID
>
> drivers/firewire/core-card.c | 14 +++++++++-----
> drivers/firewire/core-topology.c | 2 +-
> drivers/firewire/core.h | 6 ++++++
> 3 files changed, 16 insertions(+), 6 deletions(-)
Applied to for-next branch.
Regards
Takashi Sakamoto
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-14 11:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-13 10:57 [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 1/2] firewire: core: use macro expression for gap count mismatch Takashi Sakamoto
2025-09-13 10:57 ` [PATCH 2/2] firewire: core: use macro expression for not-registered state of BUS_MANAGER_ID Takashi Sakamoto
2025-09-14 11:08 ` [PATCH 0/2] firewire: core: use macro for magic numbers related to bus manager work Takashi Sakamoto
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox