Skip to content

Commit 24cfd86

Browse files
committed
ata: ahci: Add mask_port_map module parameter
Commits 0077a50 ("ahci: asm1166: correct count of reported ports") and 9815e39 ("ahci: asm1064: correct count of reported ports") attempted to limit the ports of the ASM1166 and ASM1064 AHCI controllers to avoid long boot times caused by the fact that these adapters report a port map larger than the number of physical ports. The excess ports are "virtual" to hide port multiplier devices and probing these ports takes time. However, these commits caused a regression for users that do use PMP devices, as the ATA devices connected to the PMP cannot be scanned. These commits have thus been reverted by commit 6cd8adc ("ahci: asm1064: asm1166: don't limit reported ports") to allow the discovery of devices connected through a port multiplier. But this revert re-introduced the long boot times for users that do not use a port multiplier setup. This patch adds the mask_port_map ahci module parameter to allow users to manually specify port map masks for controllers. In the case of the ASMedia 1166 and 1064 controllers, users that do not have port multiplier devices can mask the excess virtual ports exposed by the controller to speedup port scanning, thus reducing boot time. The mask_port_map parameter accepts 2 different formats: - mask_port_map=<mask> This applies the same mask to all AHCI controllers present in the system. This format is convenient for small systems that have only a single AHCI controller. - mask_port_map=<pci_dev>=<mask>,<pci_dev>=mask,... This applies the specified masks only to the PCI device listed. The <pci_dev> field is a regular PCI device ID (domain:bus:dev.func). This ID can be seen following "ahci" in the kernel messages. E.g. for "ahci 0000:01:00.0: 2/2 ports implemented (port mask 0x3)", the <pci_dev> field is "0000:01:00.0". When used, the function ahci_save_initial_config() indicates that a port map mask was applied with the message "masking port_map ...". E.g.: without a mask: modprobe ahci dmesg | grep ahci ... ahci 0000:00:17.0: AHCI vers 0001.0301, 32 command slots, 6 Gbps, SATA mode ahci 0000:00:17.0: (0000:00:17.0) 8/8 ports implemented (port mask 0xff) With a mask: modprobe ahci mask_port_map=0000:00:17.0=0x1 dmesg | grep ahci ... ahci 0000:00:17.0: masking port_map 0xff -> 0x1 ahci 0000:00:17.0: AHCI vers 0001.0301, 32 command slots, 6 Gbps, SATA mode ahci 0000:00:17.0: (0000:00:17.0) 1/8 ports implemented (port mask 0x1) Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
1 parent e85006a commit 24cfd86

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

drivers/ata/ahci.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,87 @@ static int mobile_lpm_policy = -1;
666666
module_param(mobile_lpm_policy, int, 0644);
667667
MODULE_PARM_DESC(mobile_lpm_policy, "Default LPM policy for mobile chipsets");
668668

669+
static char *ahci_mask_port_map;
670+
module_param_named(mask_port_map, ahci_mask_port_map, charp, 0444);
671+
MODULE_PARM_DESC(mask_port_map,
672+
"32-bits port map masks to ignore controllers ports. "
673+
"Valid values are: "
674+
"\"<mask>\" to apply the same mask to all AHCI controller "
675+
"devices, and \"<pci_dev>=<mask>,<pci_dev>=<mask>,...\" to "
676+
"specify different masks for the controllers specified, "
677+
"where <pci_dev> is the PCI ID of an AHCI controller in the "
678+
"form \"domain:bus:dev.func\"");
679+
680+
static void ahci_apply_port_map_mask(struct device *dev,
681+
struct ahci_host_priv *hpriv, char *mask_s)
682+
{
683+
unsigned int mask;
684+
685+
if (kstrtouint(mask_s, 0, &mask)) {
686+
dev_err(dev, "Invalid port map mask\n");
687+
return;
688+
}
689+
690+
hpriv->mask_port_map = mask;
691+
}
692+
693+
static void ahci_get_port_map_mask(struct device *dev,
694+
struct ahci_host_priv *hpriv)
695+
{
696+
char *param, *end, *str, *mask_s;
697+
char *name;
698+
699+
if (!strlen(ahci_mask_port_map))
700+
return;
701+
702+
str = kstrdup(ahci_mask_port_map, GFP_KERNEL);
703+
if (!str)
704+
return;
705+
706+
/* Handle single mask case */
707+
if (!strchr(str, '=')) {
708+
ahci_apply_port_map_mask(dev, hpriv, str);
709+
goto free;
710+
}
711+
712+
/*
713+
* Mask list case: parse the parameter to apply the mask only if
714+
* the device name matches.
715+
*/
716+
param = str;
717+
end = param + strlen(param);
718+
while (param && param < end && *param) {
719+
name = param;
720+
param = strchr(name, '=');
721+
if (!param)
722+
break;
723+
724+
*param = '\0';
725+
param++;
726+
if (param >= end)
727+
break;
728+
729+
if (strcmp(dev_name(dev), name) != 0) {
730+
param = strchr(param, ',');
731+
if (param)
732+
param++;
733+
continue;
734+
}
735+
736+
mask_s = param;
737+
param = strchr(mask_s, ',');
738+
if (param) {
739+
*param = '\0';
740+
param++;
741+
}
742+
743+
ahci_apply_port_map_mask(dev, hpriv, mask_s);
744+
}
745+
746+
free:
747+
kfree(str);
748+
}
749+
669750
static void ahci_pci_save_initial_config(struct pci_dev *pdev,
670751
struct ahci_host_priv *hpriv)
671752
{
@@ -688,6 +769,10 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev,
688769
"Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
689770
}
690771

772+
/* Handle port map masks passed as module parameter. */
773+
if (ahci_mask_port_map)
774+
ahci_get_port_map_mask(&pdev->dev, hpriv);
775+
691776
ahci_save_initial_config(&pdev->dev, hpriv);
692777
}
693778

0 commit comments

Comments
 (0)