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

firewire: core: code refactoring to compute transaction speed

This commit refactors the helper function to read the content of
configuration ROM with the passed speed.

Link: https://lore.kernel.org/r/20251018035532.287124-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

+17 -18
+17 -18
drivers/firewire/core-device.c
··· 605 605 return quirks; 606 606 } 607 607 608 - static int read_rom(struct fw_device *device, 609 - int generation, int index, u32 *data) 608 + static int read_rom(struct fw_device *device, int generation, int speed, int index, u32 *data) 610 609 { 611 610 u64 offset = (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4; 612 611 int i, rcode; ··· 616 617 for (i = 10; i < 100; i += 10) { 617 618 rcode = fw_run_transaction(device->card, 618 619 TCODE_READ_QUADLET_REQUEST, device->node_id, 619 - generation, device->max_speed, offset, data, 4); 620 + generation, speed, offset, data, 4); 620 621 if (rcode != RCODE_BUSY) 621 622 break; 622 623 msleep(i); ··· 643 644 const u32 *old_rom, *new_rom; 644 645 u32 *rom, *stack; 645 646 u32 sp, key; 646 - int i, end, length, ret; 647 + int i, end, length, ret, speed; 647 648 int quirks; 648 649 649 650 rom = kmalloc(sizeof(*rom) * MAX_CONFIG_ROM_SIZE + ··· 654 655 stack = &rom[MAX_CONFIG_ROM_SIZE]; 655 656 memset(rom, 0, sizeof(*rom) * MAX_CONFIG_ROM_SIZE); 656 657 657 - device->max_speed = SCODE_100; 658 + speed = SCODE_100; 658 659 659 660 /* First read the bus info block. */ 660 661 for (i = 0; i < 5; i++) { 661 - ret = read_rom(device, generation, i, &rom[i]); 662 + ret = read_rom(device, generation, speed, i, &rom[i]); 662 663 if (ret != RCODE_COMPLETE) 663 664 goto out; 664 665 /* ··· 680 681 // Just prevent from torn writing/reading. 681 682 WRITE_ONCE(device->quirks, quirks); 682 683 683 - device->max_speed = device->node->max_speed; 684 + speed = device->node->max_speed; 684 685 685 686 /* 686 687 * Determine the speed of ··· 691 692 * because some buggy firmwares set it lower than necessary and because 692 693 * 1394-1995 nodes do not have the field. 693 694 */ 694 - if ((rom[2] & 0x7) < device->max_speed || 695 - device->max_speed == SCODE_BETA || 696 - card->beta_repeaters_present) { 695 + if ((rom[2] & 0x7) < speed || speed == SCODE_BETA || card->beta_repeaters_present) { 697 696 u32 dummy; 698 697 699 698 /* for S1600 and S3200 */ 700 - if (device->max_speed == SCODE_BETA) 701 - device->max_speed = card->link_speed; 699 + if (speed == SCODE_BETA) 700 + speed = card->link_speed; 702 701 703 - while (device->max_speed > SCODE_100) { 704 - if (read_rom(device, generation, 0, &dummy) == 702 + while (speed > SCODE_100) { 703 + if (read_rom(device, generation, speed, 0, &dummy) == 705 704 RCODE_COMPLETE) 706 705 break; 707 - device->max_speed--; 706 + --speed; 708 707 } 709 708 } 710 709 ··· 731 734 } 732 735 733 736 /* Read header quadlet for the block to get the length. */ 734 - ret = read_rom(device, generation, i, &rom[i]); 737 + ret = read_rom(device, generation, speed, i, &rom[i]); 735 738 if (ret != RCODE_COMPLETE) 736 739 goto out; 737 740 end = i + (rom[i] >> 16) + 1; ··· 755 758 * it references another block, and push it in that case. 756 759 */ 757 760 for (; i < end; i++) { 758 - ret = read_rom(device, generation, i, &rom[i]); 761 + ret = read_rom(device, generation, speed, i, &rom[i]); 759 762 if (ret != RCODE_COMPLETE) 760 763 goto out; 761 764 ··· 781 784 if (length < i) 782 785 length = i; 783 786 } 787 + 788 + device->max_speed = speed; 784 789 785 790 quirks |= detect_quirks_by_root_directory(rom + ROOT_DIR_OFFSET, length - ROOT_DIR_OFFSET); 786 791 ··· 1233 1234 int i, rcode; 1234 1235 1235 1236 for (i = 0; i < 6; i++) { 1236 - rcode = read_rom(device, generation, i, &q); 1237 + rcode = read_rom(device, generation, device->max_speed, i, &q); 1237 1238 if (rcode != RCODE_COMPLETE) 1238 1239 return rcode; 1239 1240