Skip to content

Commit 205f1a0

Browse files
committed
Merge tag 'firewire-updates-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394
Pull firewire updates from Takashi Sakamoto: "This includes two changes for core functions, which affects all use cases of this subsystem: - Handle per-device interoperability quirks Some devices have quirks affecting interoperability. To identify such quirks at an early stages of device detection, the step for reading the configuration ROM contents has been changed. As a side effect, the entire detection process is now performed at the basic transaction speed (S100), without a trial to probe higher supported speeds. With this change, the following devices should now work with fewer issues: - TASCAM FW-1884, FW-1804, and FW-1082 - MOTU Audio Express - Safer removals of host card There was a race condition between host card removal and handling of bus reset events in the workqueue. This appears to be a long standing issue, and recent changes to use more workqueues escalate it. To solve it, a new callback has been added to the 1394 OHCI PCI driver to unregister the interrupt sources and wait for workqueue completions when removing a card instance" * tag 'firewire-updates-6.19' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394/linux1394: firewire: core: abort pending transactions at card removal firewire: core: add WQ_UNBOUND to alloc_workqueue users firewire: core: clear sources of hardware interrupt at card removal firewire: core: code refactoring to find and pop transaction entry firewire: core: code refactoring to remove transaction entry firewire: core: use cleanup function to release cached configuration ROM ALSA: firewire-tascam: reserve resources for transferred isochronous packets at S400 firewire: core: handle device quirk of TASCAM FW-1884/FW-1804/FW-1082 firewire: core: determine transaction speed after detecting quirks firewire: core: code refactoring to compute transaction speed firewire: core: handle device quirk of MOTU Audio Express firewire: core: detect device quirk when reading configuration ROM
2 parents 02892f9 + 036176d commit 205f1a0

7 files changed

Lines changed: 304 additions & 124 deletions

File tree

drivers/firewire/core-card.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ static size_t config_rom_length = 1 + 4 + 1 + 1;
8686
*/
8787
#define DEFAULT_SPLIT_TIMEOUT (2 * 8000)
8888

89-
#define CANON_OUI 0x000085
90-
9189
static void generate_config_rom(struct fw_card *card, __be32 *config_rom)
9290
{
9391
struct fw_descriptor *desc;
@@ -308,11 +306,9 @@ __must_hold(&card->lock)
308306
cpu_to_be32(local_id),
309307
};
310308
bool grace = time_is_before_jiffies64(card->reset_jiffies + msecs_to_jiffies(125));
311-
bool irm_is_1394_1995_only = false;
312-
bool keep_this_irm = false;
313309
struct fw_node *irm_node;
314310
struct fw_device *irm_device;
315-
int irm_node_id;
311+
int irm_node_id, irm_device_quirks = 0;
316312
int rcode;
317313

318314
lockdep_assert_held(&card->lock);
@@ -328,15 +324,12 @@ __must_hold(&card->lock)
328324
return BM_CONTENTION_OUTCOME_IRM_HAS_LINK_OFF;
329325
}
330326

327+
// NOTE: It is likely that the quirk detection for IRM device has not done yet.
331328
irm_device = fw_node_get_device(irm_node);
332-
if (irm_device && irm_device->config_rom) {
333-
irm_is_1394_1995_only = (irm_device->config_rom[2] & 0x000000f0) == 0;
334-
335-
// Canon MV5i works unreliably if it is not root node.
336-
keep_this_irm = irm_device->config_rom[3] >> 8 == CANON_OUI;
337-
}
338-
339-
if (irm_is_1394_1995_only && !keep_this_irm) {
329+
if (irm_device)
330+
irm_device_quirks = READ_ONCE(irm_device->quirks);
331+
if ((irm_device_quirks & FW_DEVICE_QUIRK_IRM_IS_1394_1995_ONLY) &&
332+
!(irm_device_quirks & FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER)) {
340333
fw_notice(card, "IRM is not 1394a compliant, making local node (%02x) root\n",
341334
local_id);
342335
return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY;
@@ -373,7 +366,7 @@ __must_hold(&card->lock)
373366
return BM_CONTENTION_OUTCOME_IRM_HOLDS_LOCAL_NODE_AS_BM;
374367
}
375368
default:
376-
if (!keep_this_irm) {
369+
if (!(irm_device_quirks & FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER)) {
377370
fw_notice(card, "BM lock failed (%s), making local node (%02x) root\n",
378371
fw_rcode_string(rcode), local_id);
379372
return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY;
@@ -793,9 +786,13 @@ void fw_core_remove_card(struct fw_card *card)
793786
/* Switch off most of the card driver interface. */
794787
dummy_driver.free_iso_context = card->driver->free_iso_context;
795788
dummy_driver.stop_iso = card->driver->stop_iso;
789+
dummy_driver.disable = card->driver->disable;
796790
card->driver = &dummy_driver;
791+
797792
drain_workqueue(card->isoc_wq);
798793
drain_workqueue(card->async_wq);
794+
card->driver->disable(card);
795+
fw_cancel_pending_transactions(card);
799796

800797
scoped_guard(spinlock_irqsave, &card->lock)
801798
fw_destroy_nodes(card);

drivers/firewire/core-device.c

Lines changed: 135 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,83 @@ static struct device_attribute fw_device_attributes[] = {
542542
__ATTR_NULL,
543543
};
544544

545-
static int read_rom(struct fw_device *device,
546-
int generation, int index, u32 *data)
545+
#define CANON_OUI 0x000085
546+
547+
static int detect_quirks_by_bus_information_block(const u32 *bus_information_block)
548+
{
549+
int quirks = 0;
550+
551+
if ((bus_information_block[2] & 0x000000f0) == 0)
552+
quirks |= FW_DEVICE_QUIRK_IRM_IS_1394_1995_ONLY;
553+
554+
if ((bus_information_block[3] >> 8) == CANON_OUI)
555+
quirks |= FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER;
556+
557+
return quirks;
558+
}
559+
560+
struct entry_match {
561+
unsigned int index;
562+
u32 value;
563+
};
564+
565+
static const struct entry_match motu_audio_express_matches[] = {
566+
{ 1, 0x030001f2 },
567+
{ 3, 0xd1000002 },
568+
{ 4, 0x8d000005 },
569+
{ 6, 0x120001f2 },
570+
{ 7, 0x13000033 },
571+
{ 8, 0x17104800 },
572+
};
573+
574+
static const struct entry_match tascam_fw_series_matches[] = {
575+
{ 1, 0x0300022e },
576+
{ 3, 0x8d000006 },
577+
{ 4, 0xd1000001 },
578+
{ 6, 0x1200022e },
579+
{ 8, 0xd4000004 },
580+
};
581+
582+
static int detect_quirks_by_root_directory(const u32 *root_directory, unsigned int length)
583+
{
584+
static const struct {
585+
enum fw_device_quirk quirk;
586+
const struct entry_match *matches;
587+
unsigned int match_count;
588+
} *entry, entries[] = {
589+
{
590+
.quirk = FW_DEVICE_QUIRK_ACK_PACKET_WITH_INVALID_PENDING_CODE,
591+
.matches = motu_audio_express_matches,
592+
.match_count = ARRAY_SIZE(motu_audio_express_matches),
593+
},
594+
{
595+
.quirk = FW_DEVICE_QUIRK_UNSTABLE_AT_S400,
596+
.matches = tascam_fw_series_matches,
597+
.match_count = ARRAY_SIZE(tascam_fw_series_matches),
598+
},
599+
};
600+
int quirks = 0;
601+
int i;
602+
603+
for (i = 0; i < ARRAY_SIZE(entries); ++i) {
604+
int j;
605+
606+
entry = entries + i;
607+
for (j = 0; j < entry->match_count; ++j) {
608+
unsigned int index = entry->matches[j].index;
609+
unsigned int value = entry->matches[j].value;
610+
611+
if ((length < index) || (root_directory[index] != value))
612+
break;
613+
}
614+
if (j == entry->match_count)
615+
quirks |= entry->quirk;
616+
}
617+
618+
return quirks;
619+
}
620+
621+
static int read_rom(struct fw_device *device, int generation, int speed, int index, u32 *data)
547622
{
548623
u64 offset = (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4;
549624
int i, rcode;
@@ -554,7 +629,7 @@ static int read_rom(struct fw_device *device,
554629
for (i = 10; i < 100; i += 10) {
555630
rcode = fw_run_transaction(device->card,
556631
TCODE_READ_QUADLET_REQUEST, device->node_id,
557-
generation, device->max_speed, offset, data, 4);
632+
generation, speed, offset, data, 4);
558633
if (rcode != RCODE_BUSY)
559634
break;
560635
msleep(i);
@@ -578,10 +653,11 @@ static int read_rom(struct fw_device *device,
578653
static int read_config_rom(struct fw_device *device, int generation)
579654
{
580655
struct fw_card *card = device->card;
581-
const u32 *old_rom, *new_rom;
582-
u32 *rom, *stack;
656+
const u32 *new_rom, *old_rom __free(kfree) = NULL;
657+
u32 *stack, *rom __free(kfree) = NULL;
583658
u32 sp, key;
584-
int i, end, length, ret;
659+
int i, end, length, ret, speed;
660+
int quirks;
585661

586662
rom = kmalloc(sizeof(*rom) * MAX_CONFIG_ROM_SIZE +
587663
sizeof(*stack) * MAX_CONFIG_ROM_SIZE, GFP_KERNEL);
@@ -591,13 +667,13 @@ static int read_config_rom(struct fw_device *device, int generation)
591667
stack = &rom[MAX_CONFIG_ROM_SIZE];
592668
memset(rom, 0, sizeof(*rom) * MAX_CONFIG_ROM_SIZE);
593669

594-
device->max_speed = SCODE_100;
670+
speed = SCODE_100;
595671

596672
/* First read the bus info block. */
597673
for (i = 0; i < 5; i++) {
598-
ret = read_rom(device, generation, i, &rom[i]);
674+
ret = read_rom(device, generation, speed, i, &rom[i]);
599675
if (ret != RCODE_COMPLETE)
600-
goto out;
676+
return ret;
601677
/*
602678
* As per IEEE1212 7.2, during initialization, devices can
603679
* reply with a 0 for the first quadlet of the config
@@ -606,39 +682,14 @@ static int read_config_rom(struct fw_device *device, int generation)
606682
* harddisk). In that case we just fail, and the
607683
* retry mechanism will try again later.
608684
*/
609-
if (i == 0 && rom[i] == 0) {
610-
ret = RCODE_BUSY;
611-
goto out;
612-
}
685+
if (i == 0 && rom[i] == 0)
686+
return RCODE_BUSY;
613687
}
614688

615-
device->max_speed = device->node->max_speed;
616-
617-
/*
618-
* Determine the speed of
619-
* - devices with link speed less than PHY speed,
620-
* - devices with 1394b PHY (unless only connected to 1394a PHYs),
621-
* - all devices if there are 1394b repeaters.
622-
* Note, we cannot use the bus info block's link_spd as starting point
623-
* because some buggy firmwares set it lower than necessary and because
624-
* 1394-1995 nodes do not have the field.
625-
*/
626-
if ((rom[2] & 0x7) < device->max_speed ||
627-
device->max_speed == SCODE_BETA ||
628-
card->beta_repeaters_present) {
629-
u32 dummy;
630-
631-
/* for S1600 and S3200 */
632-
if (device->max_speed == SCODE_BETA)
633-
device->max_speed = card->link_speed;
689+
quirks = detect_quirks_by_bus_information_block(rom);
634690

635-
while (device->max_speed > SCODE_100) {
636-
if (read_rom(device, generation, 0, &dummy) ==
637-
RCODE_COMPLETE)
638-
break;
639-
device->max_speed--;
640-
}
641-
}
691+
// Just prevent from torn writing/reading.
692+
WRITE_ONCE(device->quirks, quirks);
642693

643694
/*
644695
* Now parse the config rom. The config rom is a recursive
@@ -659,15 +710,13 @@ static int read_config_rom(struct fw_device *device, int generation)
659710
*/
660711
key = stack[--sp];
661712
i = key & 0xffffff;
662-
if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) {
663-
ret = -ENXIO;
664-
goto out;
665-
}
713+
if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE))
714+
return -ENXIO;
666715

667716
/* Read header quadlet for the block to get the length. */
668-
ret = read_rom(device, generation, i, &rom[i]);
717+
ret = read_rom(device, generation, speed, i, &rom[i]);
669718
if (ret != RCODE_COMPLETE)
670-
goto out;
719+
return ret;
671720
end = i + (rom[i] >> 16) + 1;
672721
if (end > MAX_CONFIG_ROM_SIZE) {
673722
/*
@@ -689,9 +738,9 @@ static int read_config_rom(struct fw_device *device, int generation)
689738
* it references another block, and push it in that case.
690739
*/
691740
for (; i < end; i++) {
692-
ret = read_rom(device, generation, i, &rom[i]);
741+
ret = read_rom(device, generation, speed, i, &rom[i]);
693742
if (ret != RCODE_COMPLETE)
694-
goto out;
743+
return ret;
695744

696745
if ((key >> 30) != 3 || (rom[i] >> 30) < 2)
697746
continue;
@@ -716,27 +765,54 @@ static int read_config_rom(struct fw_device *device, int generation)
716765
length = i;
717766
}
718767

768+
quirks |= detect_quirks_by_root_directory(rom + ROOT_DIR_OFFSET, length - ROOT_DIR_OFFSET);
769+
770+
// Just prevent from torn writing/reading.
771+
WRITE_ONCE(device->quirks, quirks);
772+
773+
if (unlikely(quirks & FW_DEVICE_QUIRK_UNSTABLE_AT_S400))
774+
speed = SCODE_200;
775+
else
776+
speed = device->node->max_speed;
777+
778+
// Determine the speed of
779+
// - devices with link speed less than PHY speed,
780+
// - devices with 1394b PHY (unless only connected to 1394a PHYs),
781+
// - all devices if there are 1394b repeaters.
782+
// Note, we cannot use the bus info block's link_spd as starting point because some buggy
783+
// firmwares set it lower than necessary and because 1394-1995 nodes do not have the field.
784+
if ((rom[2] & 0x7) < speed || speed == SCODE_BETA || card->beta_repeaters_present) {
785+
u32 dummy;
786+
787+
// for S1600 and S3200.
788+
if (speed == SCODE_BETA)
789+
speed = card->link_speed;
790+
791+
while (speed > SCODE_100) {
792+
if (read_rom(device, generation, speed, 0, &dummy) ==
793+
RCODE_COMPLETE)
794+
break;
795+
--speed;
796+
}
797+
}
798+
799+
device->max_speed = speed;
800+
719801
old_rom = device->config_rom;
720802
new_rom = kmemdup(rom, length * 4, GFP_KERNEL);
721-
if (new_rom == NULL) {
722-
ret = -ENOMEM;
723-
goto out;
724-
}
803+
if (new_rom == NULL)
804+
return -ENOMEM;
725805

726806
scoped_guard(rwsem_write, &fw_device_rwsem) {
727807
device->config_rom = new_rom;
728808
device->config_rom_length = length;
729809
}
730810

731-
kfree(old_rom);
732-
ret = RCODE_COMPLETE;
733811
device->max_rec = rom[2] >> 12 & 0xf;
734812
device->cmc = rom[2] >> 30 & 1;
735813
device->irmc = rom[2] >> 31 & 1;
736-
out:
737-
kfree(rom);
738814

739-
return ret;
815+
return RCODE_COMPLETE;
740816
}
741817

742818
static void fw_unit_release(struct device *dev)
@@ -1122,10 +1198,10 @@ static void fw_device_init(struct work_struct *work)
11221198
device->workfn = fw_device_shutdown;
11231199
fw_schedule_device_work(device, SHUTDOWN_DELAY);
11241200
} else {
1125-
fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n",
1201+
fw_notice(card, "created device %s: GUID %08x%08x, S%d00, quirks %08x\n",
11261202
dev_name(&device->device),
11271203
device->config_rom[3], device->config_rom[4],
1128-
1 << device->max_speed);
1204+
1 << device->max_speed, device->quirks);
11291205
device->config_rom_retries = 0;
11301206

11311207
set_broadcast_channel(device, device->generation);
@@ -1160,7 +1236,7 @@ static int reread_config_rom(struct fw_device *device, int generation,
11601236
int i, rcode;
11611237

11621238
for (i = 0; i < 6; i++) {
1163-
rcode = read_rom(device, generation, i, &q);
1239+
rcode = read_rom(device, generation, device->max_speed, i, &q);
11641240
if (rcode != RCODE_COMPLETE)
11651241
return rcode;
11661242

0 commit comments

Comments
 (0)