Commit 86baade9 authored by Takashi Sakamoto's avatar Takashi Sakamoto

firewire: ohci: use guard macro to maintain image of configuration ROM

The 1394 OHCI driver uses spinlock for the process to update local
configuration ROM.

This commit uses guard macro to maintain the spinlock.

Link: https://lore.kernel.org/r/20240805085408.251763-17-o-takashi@sakamocchi.jpSigned-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
parent b10e56fd
...@@ -2139,53 +2139,42 @@ static void bus_reset_work(struct work_struct *work) ...@@ -2139,53 +2139,42 @@ static void bus_reset_work(struct work_struct *work)
at_context_flush(&ohci->at_request_ctx); at_context_flush(&ohci->at_request_ctx);
at_context_flush(&ohci->at_response_ctx); at_context_flush(&ohci->at_response_ctx);
spin_lock_irq(&ohci->lock); scoped_guard(spinlock_irq, &ohci->lock) {
ohci->generation = generation;
ohci->generation = generation; reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset); reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
if (ohci->quirks & QUIRK_RESET_PACKET)
if (ohci->quirks & QUIRK_RESET_PACKET) ohci->request_generation = generation;
ohci->request_generation = generation;
// This next bit is unrelated to the AT context stuff but we have to do it under the
/* // spinlock also. If a new config rom was set up before this reset, the old one is
* This next bit is unrelated to the AT context stuff but we // now no longer in use and we can free it. Update the config rom pointers to point
* have to do it under the spinlock also. If a new config rom // to the current config rom and clear the next_config_rom pointer so a new update
* was set up before this reset, the old one is now no longer // can take place.
* in use and we can free it. Update the config rom pointers if (ohci->next_config_rom != NULL) {
* to point to the current config rom and clear the if (ohci->next_config_rom != ohci->config_rom) {
* next_config_rom pointer so a new update can take place. free_rom = ohci->config_rom;
*/ free_rom_bus = ohci->config_rom_bus;
}
if (ohci->next_config_rom != NULL) { ohci->config_rom = ohci->next_config_rom;
if (ohci->next_config_rom != ohci->config_rom) { ohci->config_rom_bus = ohci->next_config_rom_bus;
free_rom = ohci->config_rom; ohci->next_config_rom = NULL;
free_rom_bus = ohci->config_rom_bus;
// Restore config_rom image and manually update config_rom registers.
// Writing the header quadlet will indicate that the config rom is ready,
// so we do that last.
reg_write(ohci, OHCI1394_BusOptions, be32_to_cpu(ohci->config_rom[2]));
ohci->config_rom[0] = ohci->next_header;
reg_write(ohci, OHCI1394_ConfigROMhdr, be32_to_cpu(ohci->next_header));
} }
ohci->config_rom = ohci->next_config_rom;
ohci->config_rom_bus = ohci->next_config_rom_bus;
ohci->next_config_rom = NULL;
/* if (param_remote_dma) {
* Restore config_rom image and manually update reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
* config_rom registers. Writing the header quadlet reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
* will indicate that the config rom is ready, so we }
* do that last.
*/
reg_write(ohci, OHCI1394_BusOptions,
be32_to_cpu(ohci->config_rom[2]));
ohci->config_rom[0] = ohci->next_header;
reg_write(ohci, OHCI1394_ConfigROMhdr,
be32_to_cpu(ohci->next_header));
}
if (param_remote_dma) {
reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
} }
spin_unlock_irq(&ohci->lock);
if (free_rom) if (free_rom)
dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_rom_bus); dmam_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, free_rom, free_rom_bus);
...@@ -2626,33 +2615,26 @@ static int ohci_set_config_rom(struct fw_card *card, ...@@ -2626,33 +2615,26 @@ static int ohci_set_config_rom(struct fw_card *card,
if (next_config_rom == NULL) if (next_config_rom == NULL)
return -ENOMEM; return -ENOMEM;
spin_lock_irq(&ohci->lock); scoped_guard(spinlock_irq, &ohci->lock) {
// If there is not an already pending config_rom update, push our new allocation
/* // into the ohci->next_config_rom and then mark the local variable as null so that
* If there is not an already pending config_rom update, // we won't deallocate the new buffer.
* push our new allocation into the ohci->next_config_rom //
* and then mark the local variable as null so that we // OTOH, if there is a pending config_rom update, just use that buffer with the new
* won't deallocate the new buffer. // config_rom data, and let this routine free the unused DMA allocation.
* if (ohci->next_config_rom == NULL) {
* OTOH, if there is a pending config_rom update, just ohci->next_config_rom = next_config_rom;
* use that buffer with the new config_rom data, and ohci->next_config_rom_bus = next_config_rom_bus;
* let this routine free the unused DMA allocation. next_config_rom = NULL;
*/ }
if (ohci->next_config_rom == NULL) {
ohci->next_config_rom = next_config_rom;
ohci->next_config_rom_bus = next_config_rom_bus;
next_config_rom = NULL;
}
copy_config_rom(ohci->next_config_rom, config_rom, length); copy_config_rom(ohci->next_config_rom, config_rom, length);
ohci->next_header = config_rom[0]; ohci->next_header = config_rom[0];
ohci->next_config_rom[0] = 0; ohci->next_config_rom[0] = 0;
reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus); reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
}
spin_unlock_irq(&ohci->lock);
/* If we didn't use the DMA allocation, delete it. */ /* If we didn't use the DMA allocation, delete it. */
if (next_config_rom != NULL) { if (next_config_rom != NULL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment