Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+304 -124
+11 -14
drivers/firewire/core-card.c
··· 86 86 */ 87 87 #define DEFAULT_SPLIT_TIMEOUT (2 * 8000) 88 88 89 - #define CANON_OUI 0x000085 90 - 91 89 static void generate_config_rom(struct fw_card *card, __be32 *config_rom) 92 90 { 93 91 struct fw_descriptor *desc; ··· 306 308 cpu_to_be32(local_id), 307 309 }; 308 310 bool grace = time_is_before_jiffies64(card->reset_jiffies + msecs_to_jiffies(125)); 309 - bool irm_is_1394_1995_only = false; 310 - bool keep_this_irm = false; 311 311 struct fw_node *irm_node; 312 312 struct fw_device *irm_device; 313 - int irm_node_id; 313 + int irm_node_id, irm_device_quirks = 0; 314 314 int rcode; 315 315 316 316 lockdep_assert_held(&card->lock); ··· 324 328 return BM_CONTENTION_OUTCOME_IRM_HAS_LINK_OFF; 325 329 } 326 330 331 + // NOTE: It is likely that the quirk detection for IRM device has not done yet. 327 332 irm_device = fw_node_get_device(irm_node); 328 - if (irm_device && irm_device->config_rom) { 329 - irm_is_1394_1995_only = (irm_device->config_rom[2] & 0x000000f0) == 0; 330 - 331 - // Canon MV5i works unreliably if it is not root node. 332 - keep_this_irm = irm_device->config_rom[3] >> 8 == CANON_OUI; 333 - } 334 - 335 - if (irm_is_1394_1995_only && !keep_this_irm) { 333 + if (irm_device) 334 + irm_device_quirks = READ_ONCE(irm_device->quirks); 335 + if ((irm_device_quirks & FW_DEVICE_QUIRK_IRM_IS_1394_1995_ONLY) && 336 + !(irm_device_quirks & FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER)) { 336 337 fw_notice(card, "IRM is not 1394a compliant, making local node (%02x) root\n", 337 338 local_id); 338 339 return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY; ··· 366 373 return BM_CONTENTION_OUTCOME_IRM_HOLDS_LOCAL_NODE_AS_BM; 367 374 } 368 375 default: 369 - if (!keep_this_irm) { 376 + if (!(irm_device_quirks & FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER)) { 370 377 fw_notice(card, "BM lock failed (%s), making local node (%02x) root\n", 371 378 fw_rcode_string(rcode), local_id); 372 379 return BM_CONTENTION_OUTCOME_IRM_COMPLIES_1394_1995_ONLY; ··· 786 793 /* Switch off most of the card driver interface. */ 787 794 dummy_driver.free_iso_context = card->driver->free_iso_context; 788 795 dummy_driver.stop_iso = card->driver->stop_iso; 796 + dummy_driver.disable = card->driver->disable; 789 797 card->driver = &dummy_driver; 798 + 790 799 drain_workqueue(card->isoc_wq); 791 800 drain_workqueue(card->async_wq); 801 + card->driver->disable(card); 802 + fw_cancel_pending_transactions(card); 792 803 793 804 scoped_guard(spinlock_irqsave, &card->lock) 794 805 fw_destroy_nodes(card);
+135 -59
drivers/firewire/core-device.c
··· 542 542 __ATTR_NULL, 543 543 }; 544 544 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) 547 622 { 548 623 u64 offset = (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4; 549 624 int i, rcode; ··· 629 554 for (i = 10; i < 100; i += 10) { 630 555 rcode = fw_run_transaction(device->card, 631 556 TCODE_READ_QUADLET_REQUEST, device->node_id, 632 - generation, device->max_speed, offset, data, 4); 557 + generation, speed, offset, data, 4); 633 558 if (rcode != RCODE_BUSY) 634 559 break; 635 560 msleep(i); ··· 653 578 static int read_config_rom(struct fw_device *device, int generation) 654 579 { 655 580 struct fw_card *card = device->card; 656 - const u32 *old_rom, *new_rom; 657 - u32 *rom, *stack; 581 + const u32 *new_rom, *old_rom __free(kfree) = NULL; 582 + u32 *stack, *rom __free(kfree) = NULL; 658 583 u32 sp, key; 659 - int i, end, length, ret; 584 + int i, end, length, ret, speed; 585 + int quirks; 660 586 661 587 rom = kmalloc(sizeof(*rom) * MAX_CONFIG_ROM_SIZE + 662 588 sizeof(*stack) * MAX_CONFIG_ROM_SIZE, GFP_KERNEL); ··· 667 591 stack = &rom[MAX_CONFIG_ROM_SIZE]; 668 592 memset(rom, 0, sizeof(*rom) * MAX_CONFIG_ROM_SIZE); 669 593 670 - device->max_speed = SCODE_100; 594 + speed = SCODE_100; 671 595 672 596 /* First read the bus info block. */ 673 597 for (i = 0; i < 5; i++) { 674 - ret = read_rom(device, generation, i, &rom[i]); 598 + ret = read_rom(device, generation, speed, i, &rom[i]); 675 599 if (ret != RCODE_COMPLETE) 676 - goto out; 600 + return ret; 677 601 /* 678 602 * As per IEEE1212 7.2, during initialization, devices can 679 603 * reply with a 0 for the first quadlet of the config ··· 682 606 * harddisk). In that case we just fail, and the 683 607 * retry mechanism will try again later. 684 608 */ 685 - if (i == 0 && rom[i] == 0) { 686 - ret = RCODE_BUSY; 687 - goto out; 688 - } 609 + if (i == 0 && rom[i] == 0) 610 + return RCODE_BUSY; 689 611 } 690 612 691 - device->max_speed = device->node->max_speed; 613 + quirks = detect_quirks_by_bus_information_block(rom); 692 614 693 - /* 694 - * Determine the speed of 695 - * - devices with link speed less than PHY speed, 696 - * - devices with 1394b PHY (unless only connected to 1394a PHYs), 697 - * - all devices if there are 1394b repeaters. 698 - * Note, we cannot use the bus info block's link_spd as starting point 699 - * because some buggy firmwares set it lower than necessary and because 700 - * 1394-1995 nodes do not have the field. 701 - */ 702 - if ((rom[2] & 0x7) < device->max_speed || 703 - device->max_speed == SCODE_BETA || 704 - card->beta_repeaters_present) { 705 - u32 dummy; 706 - 707 - /* for S1600 and S3200 */ 708 - if (device->max_speed == SCODE_BETA) 709 - device->max_speed = card->link_speed; 710 - 711 - while (device->max_speed > SCODE_100) { 712 - if (read_rom(device, generation, 0, &dummy) == 713 - RCODE_COMPLETE) 714 - break; 715 - device->max_speed--; 716 - } 717 - } 615 + // Just prevent from torn writing/reading. 616 + WRITE_ONCE(device->quirks, quirks); 718 617 719 618 /* 720 619 * Now parse the config rom. The config rom is a recursive ··· 710 659 */ 711 660 key = stack[--sp]; 712 661 i = key & 0xffffff; 713 - if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) { 714 - ret = -ENXIO; 715 - goto out; 716 - } 662 + if (WARN_ON(i >= MAX_CONFIG_ROM_SIZE)) 663 + return -ENXIO; 717 664 718 665 /* Read header quadlet for the block to get the length. */ 719 - ret = read_rom(device, generation, i, &rom[i]); 666 + ret = read_rom(device, generation, speed, i, &rom[i]); 720 667 if (ret != RCODE_COMPLETE) 721 - goto out; 668 + return ret; 722 669 end = i + (rom[i] >> 16) + 1; 723 670 if (end > MAX_CONFIG_ROM_SIZE) { 724 671 /* ··· 738 689 * it references another block, and push it in that case. 739 690 */ 740 691 for (; i < end; i++) { 741 - ret = read_rom(device, generation, i, &rom[i]); 692 + ret = read_rom(device, generation, speed, i, &rom[i]); 742 693 if (ret != RCODE_COMPLETE) 743 - goto out; 694 + return ret; 744 695 745 696 if ((key >> 30) != 3 || (rom[i] >> 30) < 2) 746 697 continue; ··· 765 716 length = i; 766 717 } 767 718 719 + quirks |= detect_quirks_by_root_directory(rom + ROOT_DIR_OFFSET, length - ROOT_DIR_OFFSET); 720 + 721 + // Just prevent from torn writing/reading. 722 + WRITE_ONCE(device->quirks, quirks); 723 + 724 + if (unlikely(quirks & FW_DEVICE_QUIRK_UNSTABLE_AT_S400)) 725 + speed = SCODE_200; 726 + else 727 + speed = device->node->max_speed; 728 + 729 + // Determine the speed of 730 + // - devices with link speed less than PHY speed, 731 + // - devices with 1394b PHY (unless only connected to 1394a PHYs), 732 + // - all devices if there are 1394b repeaters. 733 + // Note, we cannot use the bus info block's link_spd as starting point because some buggy 734 + // firmwares set it lower than necessary and because 1394-1995 nodes do not have the field. 735 + if ((rom[2] & 0x7) < speed || speed == SCODE_BETA || card->beta_repeaters_present) { 736 + u32 dummy; 737 + 738 + // for S1600 and S3200. 739 + if (speed == SCODE_BETA) 740 + speed = card->link_speed; 741 + 742 + while (speed > SCODE_100) { 743 + if (read_rom(device, generation, speed, 0, &dummy) == 744 + RCODE_COMPLETE) 745 + break; 746 + --speed; 747 + } 748 + } 749 + 750 + device->max_speed = speed; 751 + 768 752 old_rom = device->config_rom; 769 753 new_rom = kmemdup(rom, length * 4, GFP_KERNEL); 770 - if (new_rom == NULL) { 771 - ret = -ENOMEM; 772 - goto out; 773 - } 754 + if (new_rom == NULL) 755 + return -ENOMEM; 774 756 775 757 scoped_guard(rwsem_write, &fw_device_rwsem) { 776 758 device->config_rom = new_rom; 777 759 device->config_rom_length = length; 778 760 } 779 761 780 - kfree(old_rom); 781 - ret = RCODE_COMPLETE; 782 762 device->max_rec = rom[2] >> 12 & 0xf; 783 763 device->cmc = rom[2] >> 30 & 1; 784 764 device->irmc = rom[2] >> 31 & 1; 785 - out: 786 - kfree(rom); 787 765 788 - return ret; 766 + return RCODE_COMPLETE; 789 767 } 790 768 791 769 static void fw_unit_release(struct device *dev) ··· 1198 1122 device->workfn = fw_device_shutdown; 1199 1123 fw_schedule_device_work(device, SHUTDOWN_DELAY); 1200 1124 } else { 1201 - fw_notice(card, "created device %s: GUID %08x%08x, S%d00\n", 1125 + fw_notice(card, "created device %s: GUID %08x%08x, S%d00, quirks %08x\n", 1202 1126 dev_name(&device->device), 1203 1127 device->config_rom[3], device->config_rom[4], 1204 - 1 << device->max_speed); 1128 + 1 << device->max_speed, device->quirks); 1205 1129 device->config_rom_retries = 0; 1206 1130 1207 1131 set_broadcast_channel(device, device->generation); ··· 1236 1160 int i, rcode; 1237 1161 1238 1162 for (i = 0; i < 6; i++) { 1239 - rcode = read_rom(device, generation, i, &q); 1163 + rcode = read_rom(device, generation, device->max_speed, i, &q); 1240 1164 if (rcode != RCODE_COMPLETE) 1241 1165 return rcode; 1242 1166
+60 -28
drivers/firewire/core-transaction.c
··· 44 44 return 1; 45 45 } 46 46 47 - static int close_transaction(struct fw_transaction *transaction, struct fw_card *card, int rcode, 48 - u32 response_tstamp) 47 + // card->transactions.lock must be acquired in advance. 48 + static void remove_transaction_entry(struct fw_card *card, struct fw_transaction *entry) 49 49 { 50 - struct fw_transaction *t = NULL, *iter; 50 + list_del_init(&entry->link); 51 + card->transactions.tlabel_mask &= ~(1ULL << entry->tlabel); 52 + } 53 + 54 + // Must be called without holding card->transactions.lock. 55 + void fw_cancel_pending_transactions(struct fw_card *card) 56 + { 57 + struct fw_transaction *t, *tmp; 58 + LIST_HEAD(pending_list); 51 59 52 60 // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 53 61 // local destination never runs in any type of IRQ context. 54 62 scoped_guard(spinlock_irqsave, &card->transactions.lock) { 55 - list_for_each_entry(iter, &card->transactions.list, link) { 56 - if (iter == transaction) { 57 - if (try_cancel_split_timeout(iter)) { 58 - list_del_init(&iter->link); 59 - card->transactions.tlabel_mask &= ~(1ULL << iter->tlabel); 60 - t = iter; 61 - } 62 - break; 63 - } 63 + list_for_each_entry_safe(t, tmp, &card->transactions.list, link) { 64 + if (try_cancel_split_timeout(t)) 65 + list_move(&t->link, &pending_list); 64 66 } 65 67 } 66 68 67 - if (!t) 68 - return -ENOENT; 69 + list_for_each_entry_safe(t, tmp, &pending_list, link) { 70 + list_del(&t->link); 71 + 72 + if (!t->with_tstamp) { 73 + t->callback.without_tstamp(card, RCODE_CANCELLED, NULL, 0, 74 + t->callback_data); 75 + } else { 76 + t->callback.with_tstamp(card, RCODE_CANCELLED, t->packet.timestamp, 0, 77 + NULL, 0, t->callback_data); 78 + } 79 + } 80 + } 81 + 82 + // card->transactions.lock must be acquired in advance. 83 + #define find_and_pop_transaction_entry(card, condition) \ 84 + ({ \ 85 + struct fw_transaction *iter, *t = NULL; \ 86 + list_for_each_entry(iter, &card->transactions.list, link) { \ 87 + if (condition) { \ 88 + t = iter; \ 89 + break; \ 90 + } \ 91 + } \ 92 + if (t && try_cancel_split_timeout(t)) \ 93 + remove_transaction_entry(card, t); \ 94 + t; \ 95 + }) 96 + 97 + static int close_transaction(struct fw_transaction *transaction, struct fw_card *card, int rcode, 98 + u32 response_tstamp) 99 + { 100 + struct fw_transaction *t; 101 + 102 + // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 103 + // local destination never runs in any type of IRQ context. 104 + scoped_guard(spinlock_irqsave, &card->transactions.lock) { 105 + t = find_and_pop_transaction_entry(card, iter == transaction); 106 + if (!t) 107 + return -ENOENT; 108 + } 69 109 70 110 if (!t->with_tstamp) { 71 111 t->callback.without_tstamp(card, rcode, NULL, 0, t->callback_data); ··· 162 122 scoped_guard(spinlock_irqsave, &card->transactions.lock) { 163 123 if (list_empty(&t->link)) 164 124 return; 165 - list_del(&t->link); 166 - card->transactions.tlabel_mask &= ~(1ULL << t->tlabel); 125 + remove_transaction_entry(card, t); 167 126 } 168 127 169 128 if (!t->with_tstamp) { ··· 1136 1097 1137 1098 void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) 1138 1099 { 1139 - struct fw_transaction *t = NULL, *iter; 1100 + struct fw_transaction *t = NULL; 1140 1101 u32 *data; 1141 1102 size_t data_length; 1142 1103 int tcode, tlabel, source, rcode; ··· 1178 1139 // NOTE: This can be without irqsave when we can guarantee that __fw_send_request() for 1179 1140 // local destination never runs in any type of IRQ context. 1180 1141 scoped_guard(spinlock_irqsave, &card->transactions.lock) { 1181 - list_for_each_entry(iter, &card->transactions.list, link) { 1182 - if (iter->node_id == source && iter->tlabel == tlabel) { 1183 - if (try_cancel_split_timeout(iter)) { 1184 - list_del_init(&iter->link); 1185 - card->transactions.tlabel_mask &= ~(1ULL << iter->tlabel); 1186 - t = iter; 1187 - } 1188 - break; 1189 - } 1190 - } 1142 + t = find_and_pop_transaction_entry(card, 1143 + iter->node_id == source && iter->tlabel == tlabel); 1191 1144 } 1192 1145 1193 1146 trace_async_response_inbound((uintptr_t)t, card->index, p->generation, p->speed, p->ack, ··· 1468 1437 { 1469 1438 int ret; 1470 1439 1471 - fw_workqueue = alloc_workqueue("firewire", WQ_MEM_RECLAIM, 0); 1440 + fw_workqueue = alloc_workqueue("firewire", WQ_MEM_RECLAIM | WQ_UNBOUND, 1441 + 0); 1472 1442 if (!fw_workqueue) 1473 1443 return -ENOMEM; 1474 1444
+5
drivers/firewire/core.h
··· 65 65 int (*enable)(struct fw_card *card, 66 66 const __be32 *config_rom, size_t length); 67 67 68 + // After returning the call, any function is no longer triggered to handle hardware event. 69 + void (*disable)(struct fw_card *card); 70 + 68 71 int (*read_phy_reg)(struct fw_card *card, int address); 69 72 int (*update_phy_reg)(struct fw_card *card, int address, 70 73 int clear_bits, int set_bits); ··· 286 283 287 284 void fw_request_get(struct fw_request *request); 288 285 void fw_request_put(struct fw_request *request); 286 + 287 + void fw_cancel_pending_transactions(struct fw_card *card); 289 288 290 289 // Convert the value of IEEE 1394 CYCLE_TIME register to the format of timeStamp field in 291 290 // descriptors of 1394 OHCI.
+65 -13
drivers/firewire/ohci.c
··· 1319 1319 enable_work(&ctx->work); 1320 1320 } 1321 1321 1322 + static int find_fw_device(struct device *dev, const void *data) 1323 + { 1324 + struct fw_device *device = fw_device(dev); 1325 + const u32 *params = data; 1326 + 1327 + return (device->generation == params[0]) && (device->node_id == params[1]); 1328 + } 1329 + 1322 1330 static int handle_at_packet(struct context *context, 1323 1331 struct descriptor *d, 1324 1332 struct descriptor *last) ··· 1398 1390 fallthrough; 1399 1391 1400 1392 default: 1393 + if (unlikely(evt == 0x10)) { 1394 + u32 params[2] = { 1395 + packet->generation, 1396 + async_header_get_destination(packet->header), 1397 + }; 1398 + struct device *dev; 1399 + 1400 + fw_card_get(&ohci->card); 1401 + dev = device_find_child(ohci->card.device, (const void *)params, find_fw_device); 1402 + fw_card_put(&ohci->card); 1403 + if (dev) { 1404 + struct fw_device *device = fw_device(dev); 1405 + int quirks = READ_ONCE(device->quirks); 1406 + 1407 + put_device(dev); 1408 + if (quirks & FW_DEVICE_QUIRK_ACK_PACKET_WITH_INVALID_PENDING_CODE) { 1409 + packet->ack = ACK_PENDING; 1410 + break; 1411 + } 1412 + } 1413 + } 1401 1414 packet->ack = RCODE_SEND_ERROR; 1402 1415 break; 1403 1416 } ··· 2406 2377 fw_schedule_bus_reset(&ohci->card, false, true); 2407 2378 2408 2379 return 0; 2380 + } 2381 + 2382 + static void ohci_disable(struct fw_card *card) 2383 + { 2384 + struct pci_dev *pdev = to_pci_dev(card->device); 2385 + struct fw_ohci *ohci = pci_get_drvdata(pdev); 2386 + int i, irq = pci_irq_vector(pdev, 0); 2387 + 2388 + // If the removal is happening from the suspend state, LPS won't be enabled and host 2389 + // registers (eg., IntMaskClear) won't be accessible. 2390 + if (!(reg_read(ohci, OHCI1394_HCControlSet) & OHCI1394_HCControl_LPS)) 2391 + return; 2392 + 2393 + reg_write(ohci, OHCI1394_IntMaskClear, ~0); 2394 + flush_writes(ohci); 2395 + 2396 + if (irq >= 0) 2397 + synchronize_irq(irq); 2398 + 2399 + flush_work(&ohci->ar_request_ctx.work); 2400 + flush_work(&ohci->ar_response_ctx.work); 2401 + flush_work(&ohci->at_request_ctx.work); 2402 + flush_work(&ohci->at_response_ctx.work); 2403 + 2404 + for (i = 0; i < ohci->n_ir; ++i) { 2405 + if (!(ohci->ir_context_mask & BIT(i))) 2406 + flush_work(&ohci->ir_context_list[i].base.work); 2407 + } 2408 + for (i = 0; i < ohci->n_it; ++i) { 2409 + if (!(ohci->it_context_mask & BIT(i))) 2410 + flush_work(&ohci->it_context_list[i].base.work); 2411 + } 2412 + 2413 + at_context_flush(&ohci->at_request_ctx); 2414 + at_context_flush(&ohci->at_response_ctx); 2409 2415 } 2410 2416 2411 2417 static int ohci_set_config_rom(struct fw_card *card, ··· 3477 3413 3478 3414 static const struct fw_card_driver ohci_driver = { 3479 3415 .enable = ohci_enable, 3416 + .disable = ohci_disable, 3480 3417 .read_phy_reg = ohci_read_phy_reg, 3481 3418 .update_phy_reg = ohci_update_phy_reg, 3482 3419 .set_config_rom = ohci_set_config_rom, ··· 3717 3652 struct fw_ohci *ohci = pci_get_drvdata(dev); 3718 3653 int irq; 3719 3654 3720 - /* 3721 - * If the removal is happening from the suspend state, LPS won't be 3722 - * enabled and host registers (eg., IntMaskClear) won't be accessible. 3723 - */ 3724 - if (reg_read(ohci, OHCI1394_HCControlSet) & OHCI1394_HCControl_LPS) { 3725 - reg_write(ohci, OHCI1394_IntMaskClear, ~0); 3726 - flush_writes(ohci); 3727 - } 3728 3655 fw_core_remove_card(&ohci->card); 3729 - 3730 - /* 3731 - * FIXME: Fail all pending packets here, now that the upper 3732 - * layers can't queue any more. 3733 - */ 3734 3656 3735 3657 software_reset(ohci); 3736 3658
+17
include/linux/firewire.h
··· 170 170 struct attribute *attrs[13]; 171 171 }; 172 172 173 + enum fw_device_quirk { 174 + // See afa1282a35d3 ("firewire: core: check for 1394a compliant IRM, fix inaccessibility of Sony camcorder"). 175 + FW_DEVICE_QUIRK_IRM_IS_1394_1995_ONLY = BIT(0), 176 + 177 + // See a509e43ff338 ("firewire: core: fix unstable I/O with Canon camcorder"). 178 + FW_DEVICE_QUIRK_IRM_IGNORES_BUS_MANAGER = BIT(1), 179 + 180 + // MOTU Audio Express transfers acknowledge packet with 0x10 for pending state. 181 + FW_DEVICE_QUIRK_ACK_PACKET_WITH_INVALID_PENDING_CODE = BIT(2), 182 + 183 + // TASCAM FW-1082/FW-1804/FW-1884 often freezes when receiving S400 packets. 184 + FW_DEVICE_QUIRK_UNSTABLE_AT_S400 = BIT(3), 185 + }; 186 + 173 187 enum fw_device_state { 174 188 FW_DEVICE_INITIALIZING, 175 189 FW_DEVICE_RUNNING, ··· 216 202 unsigned max_speed; 217 203 struct fw_card *card; 218 204 struct device device; 205 + 206 + // A set of enum fw_device_quirk. 207 + int quirks; 219 208 220 209 struct mutex client_list_mutex; 221 210 struct list_head client_list;
+11 -10
sound/firewire/tascam/tascam-stream.c
··· 282 282 struct amdtp_stream *stream) 283 283 { 284 284 struct fw_iso_resources *resources; 285 + int speed; 285 286 int err; 286 287 287 - if (stream == &tscm->tx_stream) 288 + if (stream == &tscm->tx_stream) { 288 289 resources = &tscm->tx_resources; 289 - else 290 + speed = fw_parent_device(tscm->unit)->max_speed; 291 + } else { 290 292 resources = &tscm->rx_resources; 293 + speed = SCODE_400; 294 + } 291 295 292 296 err = amdtp_tscm_set_parameters(stream, rate); 293 297 if (err < 0) 294 298 return err; 295 299 296 - return fw_iso_resources_allocate(resources, 297 - amdtp_stream_get_max_payload(stream), 298 - fw_parent_device(tscm->unit)->max_speed); 300 + return fw_iso_resources_allocate(resources, amdtp_stream_get_max_payload(stream), speed); 299 301 } 300 302 301 303 static int init_stream(struct snd_tscm *tscm, struct amdtp_stream *s) ··· 457 455 } 458 456 459 457 if (!amdtp_stream_running(&tscm->rx_stream)) { 460 - int spd = fw_parent_device(tscm->unit)->max_speed; 461 458 unsigned int tx_init_skip_cycles; 462 459 463 460 err = set_stream_formats(tscm, rate); ··· 467 466 if (err < 0) 468 467 goto error; 469 468 470 - err = amdtp_domain_add_stream(&tscm->domain, &tscm->rx_stream, 471 - tscm->rx_resources.channel, spd); 469 + err = amdtp_domain_add_stream(&tscm->domain, &tscm->rx_stream, tscm->rx_resources.channel, 470 + fw_parent_device(tscm->unit)->max_speed); 472 471 if (err < 0) 473 472 goto error; 474 473 475 - err = amdtp_domain_add_stream(&tscm->domain, &tscm->tx_stream, 476 - tscm->tx_resources.channel, spd); 474 + err = amdtp_domain_add_stream(&tscm->domain, &tscm->tx_stream, tscm->tx_resources.channel, 475 + SCODE_400); 477 476 if (err < 0) 478 477 goto error; 479 478