Skip to content

Commit c9b5be9

Browse files
committed
ahci: Introduce ahci_ignore_port() helper
libahci and AHCI drivers may ignore some ports if the port is invalid (its ID does not correspond to a valid physical port) or if the user explicitly requested the port to be ignored with the mask_port_map ahci module parameter. Such port that shall be ignored can be identified by checking that the bit corresponding to the port ID is not set in the mask_port_map field of struct ahci_host_priv. E.g. code such as: "if (!(hpriv->mask_port_map & (1 << portid)))". Replace all direct use of the mask_port_map field to detect such port with the new helper inline function ahci_ignore_port() to make the code more readable/easier to understand. The comment describing the mask_port_map field of struct ahci_host_priv is also updated to be more accurate. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Niklas Cassel <[email protected]>
1 parent 8c87215 commit c9b5be9

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

drivers/ata/ahci.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ struct ahci_port_priv {
328328
struct ahci_host_priv {
329329
/* Input fields */
330330
unsigned int flags; /* AHCI_HFLAG_* */
331-
u32 mask_port_map; /* mask out particular bits */
331+
u32 mask_port_map; /* Mask of valid ports */
332332

333333
void __iomem * mmio; /* bus-independent mem map */
334334
u32 cap; /* cap to use */
@@ -379,6 +379,17 @@ struct ahci_host_priv {
379379
int port);
380380
};
381381

382+
/*
383+
* Return true if a port should be ignored because it is excluded from
384+
* the host port map.
385+
*/
386+
static inline bool ahci_ignore_port(struct ahci_host_priv *hpriv,
387+
unsigned int portid)
388+
{
389+
return portid >= hpriv->nports ||
390+
!(hpriv->mask_port_map & (1 << portid));
391+
}
392+
382393
extern int ahci_ignore_sss;
383394

384395
extern const struct attribute_group *ahci_shost_groups[];

drivers/ata/ahci_brcm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static unsigned int brcm_ahci_read_id(struct ata_device *dev,
288288

289289
/* Re-initialize and calibrate the PHY */
290290
for (i = 0; i < hpriv->nports; i++) {
291-
if (!(hpriv->mask_port_map & (1 << i)))
291+
if (ahci_ignore_port(hpriv, i))
292292
continue;
293293

294294
rc = phy_init(hpriv->phys[i]);

drivers/ata/ahci_ceva.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static int ceva_ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
206206
goto disable_clks;
207207

208208
for (i = 0; i < hpriv->nports; i++) {
209-
if (!(hpriv->mask_port_map & (1 << i)))
209+
if (ahci_ignore_port(hpriv, i))
210210
continue;
211211

212212
rc = phy_init(hpriv->phys[i]);
@@ -218,7 +218,7 @@ static int ceva_ahci_platform_enable_resources(struct ahci_host_priv *hpriv)
218218
ahci_platform_deassert_rsts(hpriv);
219219

220220
for (i = 0; i < hpriv->nports; i++) {
221-
if (!(hpriv->mask_port_map & (1 << i)))
221+
if (ahci_ignore_port(hpriv, i))
222222
continue;
223223

224224
rc = phy_power_on(hpriv->phys[i]);

drivers/ata/libahci_platform.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)
4949
int rc, i;
5050

5151
for (i = 0; i < hpriv->nports; i++) {
52-
if (!(hpriv->mask_port_map & (1 << i)))
52+
if (ahci_ignore_port(hpriv, i))
5353
continue;
5454

5555
rc = phy_init(hpriv->phys[i]);
@@ -73,7 +73,7 @@ int ahci_platform_enable_phys(struct ahci_host_priv *hpriv)
7373

7474
disable_phys:
7575
while (--i >= 0) {
76-
if (!(hpriv->mask_port_map & (1 << i)))
76+
if (ahci_ignore_port(hpriv, i))
7777
continue;
7878

7979
phy_power_off(hpriv->phys[i]);
@@ -94,7 +94,7 @@ void ahci_platform_disable_phys(struct ahci_host_priv *hpriv)
9494
int i;
9595

9696
for (i = 0; i < hpriv->nports; i++) {
97-
if (!(hpriv->mask_port_map & (1 << i)))
97+
if (ahci_ignore_port(hpriv, i))
9898
continue;
9999

100100
phy_power_off(hpriv->phys[i]);

0 commit comments

Comments
 (0)