1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-15 11:03:02 +00:00

1235 Commits

Author SHA1 Message Date
Takashi Sakamoto
1107aac1ad firewire: core: fix to update generation field in topology map
The generation field of topology map is updated after initialized by zero.
The updated value of generation field is always zero, and is against
specification.

This commit fixes the bug.

Fixes: 7d138cb269db ("firewire: core: use spin lock specific to topology map")
Link: https://lore.kernel.org/r/20251114144421.415278-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-16 21:30:26 +09:00
Ville Syrjälä
37339122a7 firewire: core: Initialize topology_map.lock
Lockdep barfs on the new uninitialized spinlock.
Initialize it.

protip: enable lockdep (CONFIG_PROVE_LOCKING=y) when
        doing locking changes

firewire_ohci 0000:02:01.1: added OHCI v1.10 device as card 0, 4 IR + 4 IT contexts, quirks 0x11
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe
you didn't initialize this object before use?
turning off the locking correctness validator.
CPU: 0 UID: 0 PID: 1042 Comm: irq/17-firewire Not tainted 6.17.0-rc2-cl-bisect2-00026-g7d138cb269db #136 PREEMPT
Hardware name: Dell Inc. Latitude E5400                  /0D695C, BIOS A19 06/13/2013
Call Trace:
 <TASK>
 dump_stack_lvl+0x6d/0xa0
 register_lock_class+0x783/0x790
 ? find_held_lock+0x2b/0x80
 ? __mod_timer+0x110/0x320
 ? __mod_timer+0x110/0x320
 __lock_acquire+0x405/0x2600
 lock_acquire+0xca/0x2e0
 ? fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 ? fw_core_handle_bus_reset+0x878/0xca0 [firewire_core]
 ? fw_core_handle_bus_reset+0x878/0xca0 [firewire_core]
 _raw_spin_lock+0x2e/0x40
 ? fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 fw_core_handle_bus_reset+0x888/0xca0 [firewire_core]
 handle_selfid_complete_event+0x35c/0x7a0 [firewire_ohci]
 ? irq_thread+0x8d/0x280
 irq_thread_fn+0x18/0x50
 irq_thread+0x15a/0x280
 ? irq_check_status_bit+0x100/0x100
 ? lockdep_hardirqs_on+0x78/0x100
 ? irq_finalize_oneshot.part.0+0xc0/0xc0
 ? irq_forced_thread_fn+0x60/0x60
 kthread+0x114/0x200
 ? kthreads_online_cpu+0x110/0x110
 ret_from_fork+0x158/0x1e0
 ? kthreads_online_cpu+0x110/0x110
 ret_from_fork_asm+0x11/0x20
 </TASK>

Reported-by: Erhard Furtner <erhard_f@mailbox.org>
Fixes: 7d138cb269db ("firewire: core: use spin lock specific to topology map")
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-11-14 23:18:50 +09:00
Nirbhay Sharma
73ba88fb04 firewire: init_ohci1394_dma: add missing function parameter documentation
Add missing kernel-doc parameter descriptions for five functions
in init_ohci1394_dma.c to fix documentation warnings when building
with W=1.

This patch addresses the following warnings:
- init_ohci1394_wait_for_busresets: missing @ohci description
- init_ohci1394_enable_physical_dma: missing @ohci description
- init_ohci1394_reset_and_init_dma: missing @ohci description
- init_ohci1394_controller: missing @num, @slot, @func descriptions
- setup_ohci1394_dma: missing @opt description

Tested with GCC 13.2.0 and W=1 flag. All documentation warnings
for these functions have been resolved.

Signed-off-by: Nirbhay Sharma <nirbhay.lkd@gmail.com>
Link: https://lore.kernel.org/r/20251024203219.101990-2-nirbhay.lkd@gmail.com
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-25 08:29:56 +09:00
Takashi Sakamoto
246aca5b2a firewire: core: fix __must_hold() annotation
The variable name passed to __must_hold() annotation is invalid.

This commit fixes it.

Fixes: 420bd7068cbf ("firewire: core: use spin lock specific to transaction")
Link: https://lore.kernel.org/r/20251023104349.415310-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-10-24 09:59:34 +09:00
Linus Torvalds
f07c3695bf firewire updates for v6.18
This update includes the following changes:
 
 - Removal of the deprecated debug parameter from firewire-ohci module
 - Replacement of the module-local workqueue in 1394 OHCI PCI driver with
   a companion IRQ thread
 - Refactoring of bus management code
 - Additional minor code cleanup
 
 The existing tracepoints serve as an alternative to the removed debug
 parameter. The use of IRQ thread is experimental, as it handles 1394 OHCI
 SelfIDComplete event only. It may be replaced in the future releases with
 another approach; e.g. by providing workqueue from core functionality
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQE66IEYNDXNBPeGKSsLtaWM8LwEwUCaNqKwQAKCRCsLtaWM8Lw
 E8J0APwNtyOFP/r/ojGG8QezyDtxd67LPoU5ocLxEMsAUltE9QD+LMhtMkGXzz2r
 Xfg54jwiEi52Y4eQ9r9UZhN78kmW8gw=
 =tKD2
 -----END PGP SIGNATURE-----

Merge tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394

Pull firewire updates from Takashi Sakamoto:
 "This update includes the following changes:

   - Removal of the deprecated debug parameter from firewire-ohci module

   - Replacement of the module-local workqueue in 1394 OHCI PCI driver
     with a companion IRQ thread

   - Refactoring of bus management code

   - Additional minor code cleanup

  The existing tracepoints serve as an alternative to the removed debug
  parameter. The use of IRQ thread is experimental, as it handles 1394
  OHCI SelfIDComplete event only. It may be replaced in the future
  releases with another approach; e.g. by providing workqueue from core
  functionality"

* tag 'firewire-updates-6.18' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: (43 commits)
  firewire: core: fix undefined reference error in ARM EABI
  Revert "firewire: core: disable bus management work temporarily during updating topology"
  Revert "firewire: core: shrink critical section of fw_card spinlock in bm_work"
  firewire: core: suppress overflow warning when computing jiffies from isochronous cycle
  firewire: core: minor code refactoring to delete useless local variable
  firewire: core; eliminate pick_me goto label
  firewire: core: code refactoring to split contention procedure for bus manager
  firewire: core: code refactoring for the case of generation mismatch
  firewire: core: use switch statement to evaluate transaction result to CSR_BUS_MANAGER_ID
  firewire: core: remove useless generation check
  firewire: core: use struct_size and flex_array_size in ioctl_add_descriptor
  firewire: core: shrink critical section of fw_card spinlock in bm_work
  firewire: core: disable bus management work temporarily during updating topology
  firewire: core: schedule bm_work item outside of spin lock
  firewire: core: annotate fw_destroy_nodes with must-hold-lock
  firewire: core: use spin lock specific to timer for split transaction
  firewire: core: use spin lock specific to transaction
  firewire: core: use spin lock specific to topology map
  firewire: core: maintain phy packet receivers locally in cdev layer
  firewire: core: use scoped_guard() to manage critical section to update topology
  ...
2025-10-01 12:52:43 -07:00
Takashi Sakamoto
40d4c76120 firewire: core: fix undefined reference error in ARM EABI
For ARM EABI, GCC generates a reference to __aeabi_uldivmod when compiling
a division of 64-bit integer with 32-bit integer. This function is not
available in Linux kernel. In such cases, helper macros are defined in
include/linux/math64.h.

This commit replaces the division with div_u64().

Fixes: 8ec6a8ec23b9 ("firewire: core: suppress overflow warning when computing jiffies from isochronous cycle")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509270428.FZaO2PPq-lkp@intel.com/
Link: https://lore.kernel.org/r/20250928011910.581475-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-28 10:20:30 +09:00
Takashi Sakamoto
e216c49b3e Revert "firewire: core: disable bus management work temporarily during updating topology"
This reverts commit abe7159125702c734e851bc0c52b51cd446298a5.

The bus manager work item acquires the spin lock of fw_card again, thus
no need to serialize it against fw_core_handle_bus_reset().

Link: https://lore.kernel.org/r/20250924131823.262136-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:20:01 +09:00
Takashi Sakamoto
a6176b7b2a Revert "firewire: core: shrink critical section of fw_card spinlock in bm_work"
This reverts commit 582310376d6e9a8d261b682178713cdc4b251af6.

The bus manager work has the race condition against fw_destroy_nodes()
called by fw_core_remove_card(). The acquition of spin lock of fw_card
is left as is again.

Link: https://lore.kernel.org/r/20250924131823.262136-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:20:01 +09:00
Takashi Sakamoto
8ec6a8ec23 firewire: core: suppress overflow warning when computing jiffies from isochronous cycle
The multiplication by USEC_PER_SEC (=1000000L) may trigger an overflow
warning with 32 bit storage. In the case of the subsystem the input value
ranges between 800 and 16000, thus the result always fits within 32 bit
storage.

This commit suppresses the warning by using widening conversion to 64 bit
storage before multiplication, then using narrowing conversion to 32 bit
storage.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202509170136.b5ZHaNAV-lkp@intel.com/
Fixes: 379b870c28c6 ("firewire: core: use helper macros instead of direct access to HZ")
Link: https://lore.kernel.org/r/20250924131140.261686-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-24 22:19:15 +09:00
Takashi Sakamoto
853a57ba26 firewire: core: fix overlooked update of subsystem ABI version
In kernel v6.5, several functions were added to the cdev layer. This
required updating the default version of subsystem ABI up to 6, but
this requirement was overlooked.

This commit updates the version accordingly.

Fixes: 6add87e9764d ("firewire: cdev: add new version of ABI to notify time stamp at request/response subaction of transaction#")
Link: https://lore.kernel.org/r/20250920025148.163402-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-20 12:17:50 +09:00
Takashi Sakamoto
19e73f6594 firewire: core: minor code refactoring to delete useless local variable
The do_reset local variable has less merit. Let's remove it.

Link: https://lore.kernel.org/r/20250918235448.129705-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
9192c37929 firewire: core; eliminate pick_me goto label
This commit uses condition statements instead of pick_me goto label.

Link: https://lore.kernel.org/r/20250918235448.129705-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
4ff62194d3 firewire: core: code refactoring to split contention procedure for bus manager
The precedure to contend for bus manager has much code. It is better to
split it into a helper function.

This commit refactors in the point.

Link: https://lore.kernel.org/r/20250918235448.129705-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
e31b990caf firewire: core: code refactoring for the case of generation mismatch
Current implementation stores the bus generation at which the bus manager
contending procedure finishes. The condition for the procedure is the
mismatch of the stored generation against current bus generation.

This commit refactors the code for the contending procedure. Two existing
branches are put into a new branch to detect the generation mismatch, thus
the most of change is indentation.

Link: https://lore.kernel.org/r/20250918235448.129705-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
52561ebfae firewire: core: use switch statement to evaluate transaction result to CSR_BUS_MANAGER_ID
The result of the lock transaction to swap bus manager on isochronous
resource manager looks like an ad-hoc style. It is hard to read.

This commit uses switch statement to evaluate the result.

Link: https://lore.kernel.org/r/20250918235448.129705-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Takashi Sakamoto
182edc05b0 firewire: core: remove useless generation check
Two functions, fw_core_handle_bus_reset() and bm_work(), are serialized
by a commit 3d91fd440cc7 ("firewire: core: disable bus management work
temporarily during updating topology"). Therefore the generation member
of fw_card is immutable in bm_work().

This commit removes useless generation check in bm_work().

Link: https://lore.kernel.org/r/20250918235448.129705-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-19 08:58:34 +09:00
Thorsten Blum
e6d2338b6f firewire: core: use struct_size and flex_array_size in ioctl_add_descriptor
Use struct_size() to determine the memory needed for a new 'struct
descriptor_resource' and flex_array_size() to calculate the number of
bytes to copy from userspace. This removes the hardcoded size (4 bytes)
for the 'u32 data[]' entries.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20250916122143.2459993-3-thorsten.blum@linux.dev
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-18 00:29:48 +09:00
Takashi Sakamoto
582310376d firewire: core: shrink critical section of fw_card spinlock in bm_work
Now fw_core_handle_bus_reset() and bm_work() are serialized. Some members
of fw_card are free to access in bm_work()

This commit shrinks critical section of fw_card spinlock in bm_work()

Link: https://lore.kernel.org/r/20250917000347.52369-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-17 09:07:03 +09:00
Takashi Sakamoto
abe7159125 firewire: core: disable bus management work temporarily during updating topology
When processing selfID sequence, bus topology tree is (re)built, and some
members of fw_card are determined. Once determined, the members are valid
during the bus generation. The above operations are in the critical
section of fw_card spin lock.

Before building the bus topology, a work item is scheduled for bus manager
work. The bm_work() function is invoked by the work item. The function
tries to acquire the spin lock, then can be stalled until the bus topology
building finishes.

The bus manager should work once the members of fw_card are determined.
This commit suppresses the above situation by disabling the work item
during processing selfID sequence.

Link: https://lore.kernel.org/r/20250917000347.52369-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-17 09:07:03 +09:00
Takashi Sakamoto
b460b317b2 firewire: core: schedule bm_work item outside of spin lock
Before (re)building topology tree, fw_core_handle_bus_reset() schedules
a work item under acquiring fw_card spin lock. The work item invokes
bm_work() which acquires the spin lock at first, then can be stalled to
wait until the building tree finishes. This is inconvenient.

This commit moves the timing to schedule the work item after releasing
the spin lock.

Link: https://lore.kernel.org/r/20250917000347.52369-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-17 09:07:03 +09:00
Takashi Sakamoto
e0cda0dd12 firewire: core: annotate fw_destroy_nodes with must-hold-lock
The function, fw_destroy_nodes(), is used widely within firewire-core
module. It has a prerequisite condition that struct fw_card.lock must
be hold in advance.

This commit adds annotation for it.

Link: https://lore.kernel.org/r/20250915234747.915922-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:19 +09:00
Takashi Sakamoto
b5725cfa41 firewire: core: use spin lock specific to timer for split transaction
At present the parameters to compute timeout time for split transaction is
protected by card-wide spin lock, while it is not necessarily convenient
in a point to narrower critical section.

This commit adds and uses another spin lock specific for the purpose.

Link: https://lore.kernel.org/r/20250915234747.915922-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:19 +09:00
Takashi Sakamoto
420bd7068c firewire: core: use spin lock specific to transaction
The list of instance for asynchronous transaction to wait for response
subaction is maintained as a member of fw_card structure. The card-wide
spinlock is used at present for any operation over the list, however it
is not necessarily suited for the purpose.

This commit adds and uses the spin lock specific to maintain the list.

Link: https://lore.kernel.org/r/20250915234747.915922-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:18 +09:00
Takashi Sakamoto
7d138cb269 firewire: core: use spin lock specific to topology map
At present, the operation for read transaction to topology map register is
not protected by any kind of lock primitives. This causes a potential
problem to result in the mixed content of topology map.

This commit adds and uses spin lock specific to topology map.

Link: https://lore.kernel.org/r/20250915234747.915922-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:18 +09:00
Takashi Sakamoto
07c446e35b firewire: core: maintain phy packet receivers locally in cdev layer
The list of receivers for phy packet is used only by cdev layer, while it
is maintained as a member of fw_card structure.

This commit maintains the list locally in cdev layer.

Link: https://lore.kernel.org/r/20250915234747.915922-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:18 +09:00
Takashi Sakamoto
80c5b023a7 firewire: core: use scoped_guard() to manage critical section to update topology
At present, guard() macro is used for the critical section to update
topology. It is inconvenient to add the other critical sections into
the function.

This commit uses scoped_guard() macro instead.

Link: https://lore.kernel.org/r/20250915234747.915922-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-16 08:52:18 +09:00
Takashi Sakamoto
931383f161 firewire: core: use helper macro to compare against current jiffies
The pattern of calling either time_before64() or time_after64() with
get_jiffies_64() can be replaced with the corresponding helper macros.

Link: https://lore.kernel.org/r/20250915024232.851955-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-15 11:49:34 +09:00
Takashi Sakamoto
379b870c28 firewire: core: use helper macros instead of direct access to HZ
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>
2025-09-15 11:49:34 +09:00
Takashi Sakamoto
2ba08d1bad firewire: core: use macro expression for not-registered state of BUS_MANAGER_ID
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.

Link: https://lore.kernel.org/r/20250913105737.778038-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-13 19:59:21 +09:00
Takashi Sakamoto
91bf158f8c firewire: core: use macro expression for gap count mismatch
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.

Link: https://lore.kernel.org/r/20250913105737.778038-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-13 19:59:21 +09:00
Takashi Sakamoto
136d8a6f73 firewire: core: remove useless lockdep_assert_held()
The bm_work work item should be scheduled after holding fw_card reference
counting. At a commit 25feb1a96e21 ("firewire: core: use cleanup function
in bm_work"), I misinterpreted it as fw_card spinlock and inserted
lockdep_assert_hold() wrongly.

This commit removes the useless line.

Fixes: 25feb1a96e21 ("firewire: core: use cleanup function in bm_work")
Link: https://lore.kernel.org/r/20250911221312.678076-1-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-12 07:54:23 +09:00
Takashi Sakamoto
a4bac55d99 firewire: core: code refactoring whether root node is cycle master capable
The check of cycle master capability in root node is currently just in a
condition branch. In this case, the required variable should be within the
branch.

This commit is just for the purpose.

Link: https://lore.kernel.org/r/20250908012108.514698-12-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
cae2d92cdc firewire: core: code refactoring to investigate root node for bus manager
In the middle of bm_work function, both the value of gap_count and the
state of root node are investigated. Current implementation is not a good
shape since the investigation is aligned to be flat.

This commit refactors the investigation with two large branches.

Link: https://lore.kernel.org/r/20250908012108.514698-11-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
ca17601b15 firewire: core: code refactoring to detect both IEEE 1394:1995 IRM and Canon MV5i
The detection of IEEE 1394:1995 and Canon MV5i is just required within
some of the condition branches. In this case, these check can be
capsulated within these branches.

This commit refactors the checks.

Link: https://lore.kernel.org/r/20250908012108.514698-10-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
8c2d2fcd6b firewire: core: refer fw_card member to initiate bus reset under acquiring lock
The gap_count member of fw_card structure is referred when initiate bus
reset. This reference is done out of acquiring lock. This is not good.

This commit takes the reference within the acquiring lock, with
additional code refactoring.

Link: https://lore.kernel.org/r/20250908012108.514698-9-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
7dc12e84ef firewire: core: code refactoring to evaluate transaction result to CSR_BUS_MANAGER_ID
The call of bm_work should be done after acquiring spin lock of fw_card.
For asynchronous transaction, the lock should be released temporarily
due to event waiting.

A commit 27310d561622 ("firewire: core: use guard macro to maintain
properties of fw_card") applied scoped_guard() to the bm_work function,
however it looks hard to follow to the control flow.

This commit refactors the spin lock acquisition after the transaction.

Link: https://lore.kernel.org/r/20250908012108.514698-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
b70a5f3338 firewire: ohci: localize transaction data and rcode per condition branch
The function local variable, transaction_data, in bm_work function is
conditionally used. In the case, the branch-level variable is sometimes
useful.

This commit uses this idea.

Link: https://lore.kernel.org/r/20250908012108.514698-7-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
25feb1a96e firewire: core: use cleanup function in bm_work
In "bm_work" function, the references to fw_card and fw_node are
released at last. This is achieved by using goto statements. For this
case, the kernel cleanup framework is available.

This commit uses the framework to remove these statements.

Link: https://lore.kernel.org/r/20250908012108.514698-6-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
a2bbb8602d firewire: core: add helper functions to access to fw_device data in fw_node structure
The data mbmer in fw_node structure is an opaque pointer, while nowadays
it is just used to refer to fw_device associated with the fw_node.

This commit redefines the opaque pointer to a pointer to fw_device
structure, and adds some helper functions to set/get it.

Link: https://lore.kernel.org/r/20250908012108.514698-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:26 +09:00
Takashi Sakamoto
cbb13dceec firewire: ohci: use return value from fw_node_get()
The programming pattern, referring after increasing reference count, is
supported by fw_node_get().

This commit simplify the programming pattern.

Link: https://lore.kernel.org/r/20250908012108.514698-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:25 +09:00
Takashi Sakamoto
c908e072b6 firewire: core: utilize cleanup function to release workqueue in error path
The helper macro, retain_and_null_ptr(), introduced by a commit
092d00ead733 ("cleanup: Provide retain_and_null_ptr()") in v6.16 kernel,
is useful in the error path to release the part of structure member.

This commit uses the relatively new function.

Link: https://lore.kernel.org/r/20250908012108.514698-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:25 +09:00
Takashi Sakamoto
ada2e4091d firewire: ohci: use kcalloc() variant for array allocation
When allocating the list of isochronous context structure, a kzalloc()
variant of managed device API is used. In this case, a kcalloc() variant
is available.

This commit replaces these lines with devm_kcalloc().

Link: https://lore.kernel.org/r/20250908012108.514698-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-09-08 10:26:25 +09:00
Takashi Sakamoto
a901f493d0 firewire: ohci: remove module-local workqueue
Now module-local workqueue has been replaced by a threaded IRQ handler.

This commit removes the workqueue and the associated work item
accordingly.

Link: https://lore.kernel.org/r/20250823030954.268412-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-23 18:06:17 +09:00
Takashi Sakamoto
61efd0e1af firewire: ohci: use threaded IRQ handler to handle SelfIDComplete event
The first step  maintaining the bus topology is to handle SelfIDComplete
event. This event occurs after initiating bus reset when 1394 OHCI link
layer is enabled, or when the bus topology changes (e.g. when a device is
added). Because enumeration of the selfID sequence can take some time, it
should be processed in a bottom half.

Currently, this is done in a module-local workqueue with the
WQ_MEM_RECLAIM flag, to allow invocation during memory reclaim paths. A
threaded IRQ handler is a preferable alternative, as it eliminates the
need to manage workqueue attributes manually.

Although SelfIDComplete events are not so frequent in normal usage,
handling them correctly is critical for proper bus topology management.
This commit switches SelfIDComplete handling to a threaded IRQ handler.

Link: https://lore.kernel.org/r/20250823030954.268412-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-23 18:06:17 +09:00
Takashi Sakamoto
696968262a firewire: ohci: move self_id_complete tracepoint after validating register
The value of OHCI1394_SelfIDCount register includes an error-indicating
bit. It is safer to place the tracepoint probe after validating the
register value.

Link: https://lore.kernel.org/r/20250823030954.268412-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-23 18:06:17 +09:00
Takashi Sakamoto
8748368c3d firewire: ohci: remove obsolete module-level debug parameter
The module-level debug parameter was added in v2.6.26 by a commit
ad3c0fe8b8d16 ("firewire: debug interrupt events"). Its functionality
has long been superseded by tracepoints.

This commit removes the module parameter, bye.

Link: https://lore.kernel.org/r/20250821003017.186752-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-22 09:53:49 +09:00
Takashi Sakamoto
6354cc9519 firewire: ohci: remove obsolete debug logging for AT/AR results
Between v6.11 and v6.12, a set of tracepoints was added to record
asynchronous communication events:

- firewire:async_phy_inbound
- firewire:async_phy_outbound_initiate
- firewire:async_phy_outbound_complete
- firewire:async_response_inbound
- firewire:async_response_outbound_initiate
- firewire:async_response_outbound_complete
- firewire:async_request_inbound
- firewire:async_request_outbound_initiate
- firewire:async_request_outbound_complete

These tracepoints cover the functionality of the existing debug logging.
This commit removes the logging.

Link: https://lore.kernel.org/r/20250821003017.186752-4-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-22 09:53:48 +09:00
Takashi Sakamoto
c579f1fe08 firewire: ohci: remove obsolete debug logging for selfID sequence
A commit 677ceae19073 ("firewire: core: add tracepoints event for
self_id_sequence") added the "firewire:self_id_sequence" event in v6.11.
A commit 526e21a2aa6f ("firewire: ohci: add tracepoints event for data
of Self-ID DMA") added the "firewire_ohci:self_id_complete" event in
v6.12.

These tracepoints replace the equivalent debug logging. This commit
removes the logging.

Link: https://lore.kernel.org/r/20250821003017.186752-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-22 09:53:48 +09:00
Takashi Sakamoto
82b523f369 firewire: ohci: remove obsolete debug logging for IRQ events
A commit 0d8914165dd1 ("firewire: ohci: add tracepoints event for hardIRQ
event") added "firewire_ohci:irqs" event in v6.11, which can provide
equivalent information to the existing debug logging.

This commit removes the logging.

Link: https://lore.kernel.org/r/20250821003017.186752-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-22 09:53:48 +09:00
Takashi Sakamoto
0342273e14 firewire: core: reallocate buffer for FCP address handlers when more than 4 are registered
The former commit has a limitation that only up to 4 FCP address
handlers could be processed per request. Although it suffices for most
use cases, it is technically a regression.

This commit lifts the restriction by reallocating the buffer from kernel
heap when more than 4 handlers are registered. The allocation is performed
within RCU read-side critical section, thus it uses GCP_ATOMIC flag. The
buffer size is rounded up to the next power of two to align with kmalloc
allocation units.

Link: https://lore.kernel.org/r/20250803122015.236493-5-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
2025-08-03 21:20:15 +09:00