Skip to content

Commit b642212

Browse files
committed
ata: libata: Move sata_down_spd_limit() to libata-sata.c
Move the definition of the function sata_down_spd_limit() to libata-sata.c where it belongs, together with sata_set_spd(). The helper function ata_sstatus_online() is also changed to be an inline function defined in drivers/ata/libata.h. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]>
1 parent 5bb52d9 commit b642212

File tree

3 files changed

+96
-86
lines changed

3 files changed

+96
-86
lines changed

drivers/ata/libata-core.c

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ static inline bool ata_dev_print_info(const struct ata_device *dev)
167167
return ehc->i.flags & ATA_EHI_PRINTINFO;
168168
}
169169

170-
static bool ata_sstatus_online(u32 sstatus)
171-
{
172-
return (sstatus & 0xf) == 0x3;
173-
}
174-
175170
/**
176171
* ata_link_next - link iteration helper
177172
* @link: the previous link, NULL to start
@@ -3200,86 +3195,6 @@ struct ata_device *ata_dev_pair(struct ata_device *adev)
32003195
}
32013196
EXPORT_SYMBOL_GPL(ata_dev_pair);
32023197

3203-
/**
3204-
* sata_down_spd_limit - adjust SATA spd limit downward
3205-
* @link: Link to adjust SATA spd limit for
3206-
* @spd_limit: Additional limit
3207-
*
3208-
* Adjust SATA spd limit of @link downward. Note that this
3209-
* function only adjusts the limit. The change must be applied
3210-
* using sata_set_spd().
3211-
*
3212-
* If @spd_limit is non-zero, the speed is limited to equal to or
3213-
* lower than @spd_limit if such speed is supported. If
3214-
* @spd_limit is slower than any supported speed, only the lowest
3215-
* supported speed is allowed.
3216-
*
3217-
* LOCKING:
3218-
* Inherited from caller.
3219-
*
3220-
* RETURNS:
3221-
* 0 on success, negative errno on failure
3222-
*/
3223-
int sata_down_spd_limit(struct ata_link *link, u32 spd_limit)
3224-
{
3225-
u32 sstatus, spd, mask;
3226-
int rc, bit;
3227-
3228-
if (!sata_scr_valid(link))
3229-
return -EOPNOTSUPP;
3230-
3231-
/* If SCR can be read, use it to determine the current SPD.
3232-
* If not, use cached value in link->sata_spd.
3233-
*/
3234-
rc = sata_scr_read(link, SCR_STATUS, &sstatus);
3235-
if (rc == 0 && ata_sstatus_online(sstatus))
3236-
spd = (sstatus >> 4) & 0xf;
3237-
else
3238-
spd = link->sata_spd;
3239-
3240-
mask = link->sata_spd_limit;
3241-
if (mask <= 1)
3242-
return -EINVAL;
3243-
3244-
/* unconditionally mask off the highest bit */
3245-
bit = fls(mask) - 1;
3246-
mask &= ~(1 << bit);
3247-
3248-
/*
3249-
* Mask off all speeds higher than or equal to the current one. At
3250-
* this point, if current SPD is not available and we previously
3251-
* recorded the link speed from SStatus, the driver has already
3252-
* masked off the highest bit so mask should already be 1 or 0.
3253-
* Otherwise, we should not force 1.5Gbps on a link where we have
3254-
* not previously recorded speed from SStatus. Just return in this
3255-
* case.
3256-
*/
3257-
if (spd > 1)
3258-
mask &= (1 << (spd - 1)) - 1;
3259-
else if (link->sata_spd)
3260-
return -EINVAL;
3261-
3262-
/* were we already at the bottom? */
3263-
if (!mask)
3264-
return -EINVAL;
3265-
3266-
if (spd_limit) {
3267-
if (mask & ((1 << spd_limit) - 1))
3268-
mask &= (1 << spd_limit) - 1;
3269-
else {
3270-
bit = ffs(mask) - 1;
3271-
mask = 1 << bit;
3272-
}
3273-
}
3274-
3275-
link->sata_spd_limit = mask;
3276-
3277-
ata_link_warn(link, "limiting SATA link speed to %s\n",
3278-
sata_spd_string(fls(mask)));
3279-
3280-
return 0;
3281-
}
3282-
32833198
#ifdef CONFIG_ATA_ACPI
32843199
/**
32853200
* ata_timing_cycle2mode - find xfer mode for the specified cycle duration

drivers/ata/libata-sata.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,86 @@ int sata_set_spd(struct ata_link *link)
517517
}
518518
EXPORT_SYMBOL_GPL(sata_set_spd);
519519

520+
/**
521+
* sata_down_spd_limit - adjust SATA spd limit downward
522+
* @link: Link to adjust SATA spd limit for
523+
* @spd_limit: Additional limit
524+
*
525+
* Adjust SATA spd limit of @link downward. Note that this
526+
* function only adjusts the limit. The change must be applied
527+
* using sata_set_spd().
528+
*
529+
* If @spd_limit is non-zero, the speed is limited to equal to or
530+
* lower than @spd_limit if such speed is supported. If
531+
* @spd_limit is slower than any supported speed, only the lowest
532+
* supported speed is allowed.
533+
*
534+
* LOCKING:
535+
* Inherited from caller.
536+
*
537+
* RETURNS:
538+
* 0 on success, negative errno on failure
539+
*/
540+
int sata_down_spd_limit(struct ata_link *link, u32 spd_limit)
541+
{
542+
u32 sstatus, spd, mask;
543+
int rc, bit;
544+
545+
if (!sata_scr_valid(link))
546+
return -EOPNOTSUPP;
547+
548+
/* If SCR can be read, use it to determine the current SPD.
549+
* If not, use cached value in link->sata_spd.
550+
*/
551+
rc = sata_scr_read(link, SCR_STATUS, &sstatus);
552+
if (rc == 0 && ata_sstatus_online(sstatus))
553+
spd = (sstatus >> 4) & 0xf;
554+
else
555+
spd = link->sata_spd;
556+
557+
mask = link->sata_spd_limit;
558+
if (mask <= 1)
559+
return -EINVAL;
560+
561+
/* unconditionally mask off the highest bit */
562+
bit = fls(mask) - 1;
563+
mask &= ~(1 << bit);
564+
565+
/*
566+
* Mask off all speeds higher than or equal to the current one. At
567+
* this point, if current SPD is not available and we previously
568+
* recorded the link speed from SStatus, the driver has already
569+
* masked off the highest bit so mask should already be 1 or 0.
570+
* Otherwise, we should not force 1.5Gbps on a link where we have
571+
* not previously recorded speed from SStatus. Just return in this
572+
* case.
573+
*/
574+
if (spd > 1)
575+
mask &= (1 << (spd - 1)) - 1;
576+
else if (link->sata_spd)
577+
return -EINVAL;
578+
579+
/* were we already at the bottom? */
580+
if (!mask)
581+
return -EINVAL;
582+
583+
if (spd_limit) {
584+
if (mask & ((1 << spd_limit) - 1))
585+
mask &= (1 << spd_limit) - 1;
586+
else {
587+
bit = ffs(mask) - 1;
588+
mask = 1 << bit;
589+
}
590+
}
591+
592+
link->sata_spd_limit = mask;
593+
594+
ata_link_warn(link, "limiting SATA link speed to %s\n",
595+
sata_spd_string(fls(mask)));
596+
597+
return 0;
598+
}
599+
520600
/**
521601
* sata_link_hardreset - reset link via SATA phy reset
522602
* @link: link to reset

drivers/ata/libata.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ extern int libata_noacpi;
3838
extern int libata_allow_tpm;
3939
extern const struct device_type ata_port_type;
4040
extern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
41+
42+
static inline bool ata_sstatus_online(u32 sstatus)
43+
{
44+
return (sstatus & 0xf) == 0x3;
45+
}
46+
4147
#ifdef CONFIG_ATA_FORCE
4248
extern void ata_force_cbl(struct ata_port *ap);
4349
#else
@@ -65,7 +71,6 @@ extern bool ata_dev_power_init_tf(struct ata_device *dev,
6571
struct ata_taskfile *tf, bool set_active);
6672
extern void ata_dev_power_set_standby(struct ata_device *dev);
6773
extern void ata_dev_power_set_active(struct ata_device *dev);
68-
extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit);
6974
extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
7075
extern unsigned int ata_dev_set_feature(struct ata_device *dev,
7176
u8 subcmd, u8 action);
@@ -87,6 +92,16 @@ extern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
8792

8893
#define to_ata_port(d) container_of(d, struct ata_port, tdev)
8994

95+
/* libata-sata.c */
96+
#ifdef CONFIG_SATA_HOST
97+
int sata_down_spd_limit(struct ata_link *link, u32 spd_limit);
98+
#else
99+
static inline int sata_down_spd_limit(struct ata_link *link, u32 spd_limit)
100+
{
101+
return -EOPNOTSUPP;
102+
}
103+
#endif
104+
90105
/* libata-acpi.c */
91106
#ifdef CONFIG_ATA_ACPI
92107
extern unsigned int ata_acpi_gtf_filter;

0 commit comments

Comments
 (0)