1 diff -urNp -x '*.orig' linux-4.4/Documentation/scsi/link_power_management_policy.txt linux-4.4/Documentation/scsi/link_power_management_policy.txt
2 --- linux-4.4/Documentation/scsi/link_power_management_policy.txt 2016-01-11 00:01:32.000000000 +0100
3 +++ linux-4.4/Documentation/scsi/link_power_management_policy.txt 2021-02-24 17:42:47.900118751 +0100
5 This parameter allows the user to set the link (interface) power management.
6 -There are 3 possible options:
7 +There are 4 possible options:
10 ----------------------------------------------------------------------------
11 +firmware_defaults Inherit configuration from the state programmed by
12 + the firmware during system init.
14 min_power Tell the controller to try to make the link use the
15 least possible power when possible. This may
16 sacrifice some performance due to increased latency
17 diff -urNp -x '*.orig' linux-4.4/drivers/ata/acard-ahci.c linux-4.4/drivers/ata/acard-ahci.c
18 --- linux-4.4/drivers/ata/acard-ahci.c 2021-02-24 17:42:34.233049827 +0100
19 +++ linux-4.4/drivers/ata/acard-ahci.c 2021-02-24 17:42:47.896785319 +0100
20 @@ -480,6 +480,9 @@ static int acard_ahci_init_one(struct pc
21 ata_port_pbar_desc(ap, AHCI_PCI_BAR,
22 0x100 + ap->port_no * 0x80, "port");
24 + rc = ahci_setup_port_privdata(ap);
27 /* set initial link pm policy */
29 ap->pm_policy = NOT_AVAILABLE;
30 diff -urNp -x '*.orig' linux-4.4/drivers/ata/ahci.c linux-4.4/drivers/ata/ahci.c
31 --- linux-4.4/drivers/ata/ahci.c 2021-02-24 17:42:34.233049827 +0100
32 +++ linux-4.4/drivers/ata/ahci.c 2021-02-24 17:42:47.896785319 +0100
33 @@ -1695,6 +1695,9 @@ static int ahci_init_one(struct pci_dev
34 if (ap->flags & ATA_FLAG_EM)
35 ap->em_message_type = hpriv->em_msg_type;
37 + rc = ahci_setup_port_privdata(ap);
41 /* disabled/not-implemented port */
42 if (!(hpriv->port_map & (1 << i)))
43 diff -urNp -x '*.orig' linux-4.4/drivers/ata/ahci.h linux-4.4/drivers/ata/ahci.h
44 --- linux-4.4/drivers/ata/ahci.h 2016-01-11 00:01:32.000000000 +0100
45 +++ linux-4.4/drivers/ata/ahci.h 2021-02-24 17:42:47.896785319 +0100
46 @@ -317,6 +317,12 @@ struct ahci_port_priv {
47 /* enclosure management info per PM slot */
48 struct ahci_em_priv em_priv[EM_MAX_SLOTS];
49 char *irq_desc; /* desc in /proc/interrupts */
50 + bool init_alpe; /* alpe enabled by default */
51 + bool init_asp; /* asp enabled by default */
52 + bool init_devslp; /* devslp enabled by default */
53 + u32 init_dito; /* initial dito configuration */
54 + u32 init_deto; /* initial deto configuration */
55 + u32 init_mdat; /* initial mdat configuration */
58 struct ahci_host_priv {
59 @@ -376,6 +382,7 @@ extern struct ata_port_operations ahci_p
60 extern struct ata_port_operations ahci_pmp_retry_srst_ops;
62 unsigned int ahci_dev_classify(struct ata_port *ap);
63 +int ahci_setup_port_privdata(struct ata_port *ap);
64 void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
66 void ahci_save_initial_config(struct device *dev,
67 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libahci.c linux-4.4/drivers/ata/libahci.c
68 --- linux-4.4/drivers/ata/libahci.c 2021-02-24 17:42:34.233049827 +0100
69 +++ linux-4.4/drivers/ata/libahci.c 2021-02-24 17:42:47.903452182 +0100
70 @@ -684,6 +684,7 @@ static int ahci_set_lpm(struct ata_link
72 struct ata_port *ap = link->ap;
73 struct ahci_host_priv *hpriv = ap->host->private_data;
74 + struct ahci_port_priv *ppriv = ap->private_data;
75 struct ahci_port_priv *pp = ap->private_data;
76 void __iomem *port_mmio = ahci_port_base(ap);
78 @@ -701,9 +702,9 @@ static int ahci_set_lpm(struct ata_link
80 if (hpriv->cap & HOST_CAP_ALPM) {
81 u32 cmd = readl(port_mmio + PORT_CMD);
82 + cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE);
84 if (policy == ATA_LPM_MAX_POWER || !(hints & ATA_LPM_HIPM)) {
85 - cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE);
86 cmd |= PORT_CMD_ICC_ACTIVE;
88 writel(cmd, port_mmio + PORT_CMD);
89 @@ -711,6 +712,13 @@ static int ahci_set_lpm(struct ata_link
91 /* wait 10ms to be sure we've come out of LPM state */
93 + } else if (policy == ATA_LPM_FIRMWARE_DEFAULTS) {
94 + if (ppriv->init_alpe)
95 + cmd |= PORT_CMD_ALPE;
96 + if (ppriv->init_asp)
97 + cmd |= PORT_CMD_ASP;
99 + writel(cmd, port_mmio + PORT_CMD);
101 cmd |= PORT_CMD_ALPE;
102 if (policy == ATA_LPM_MIN_POWER)
103 @@ -725,10 +733,18 @@ static int ahci_set_lpm(struct ata_link
104 if ((hpriv->cap2 & HOST_CAP2_SDS) &&
105 (hpriv->cap2 & HOST_CAP2_SADM) &&
106 (link->device->flags & ATA_DFLAG_DEVSLP)) {
107 - if (policy == ATA_LPM_MIN_POWER)
109 + case ATA_LPM_MIN_POWER:
110 ahci_set_aggressive_devslp(ap, true);
113 + case ATA_LPM_FIRMWARE_DEFAULTS:
114 + case ATA_LPM_MED_POWER:
115 + ahci_set_aggressive_devslp(ap, ppriv->init_devslp);
118 ahci_set_aggressive_devslp(ap, false);
123 if (policy == ATA_LPM_MAX_POWER) {
124 @@ -2057,6 +2073,7 @@ static void ahci_post_internal_cmd(struc
125 static void ahci_set_aggressive_devslp(struct ata_port *ap, bool sleep)
127 struct ahci_host_priv *hpriv = ap->host->private_data;
128 + struct ahci_port_priv *ppriv = ap->private_data;
129 void __iomem *port_mmio = ahci_port_base(ap);
130 struct ata_device *dev = ap->link.device;
131 u32 devslp, dm, dito, mdat, deto;
132 @@ -2092,26 +2109,32 @@ static void ahci_set_aggressive_devslp(s
136 - dm = (devslp & PORT_DEVSLP_DM_MASK) >> PORT_DEVSLP_DM_OFFSET;
137 - dito = devslp_idle_timeout / (dm + 1);
141 - /* Use the nominal value 10 ms if the read MDAT is zero,
142 - * the nominal value of DETO is 20 ms.
144 - if (dev->devslp_timing[ATA_LOG_DEVSLP_VALID] &
145 - ATA_LOG_DEVSLP_VALID_MASK) {
146 - mdat = dev->devslp_timing[ATA_LOG_DEVSLP_MDAT] &
147 - ATA_LOG_DEVSLP_MDAT_MASK;
149 + if (ppriv->init_devslp) {
150 + dito = ppriv->init_dito;
151 + deto = ppriv->init_deto;
152 + mdat = ppriv->init_mdat;
154 + dm = (devslp & PORT_DEVSLP_DM_MASK) >> PORT_DEVSLP_DM_OFFSET;
155 + dito = devslp_idle_timeout / (dm + 1);
159 + /* Use the nominal value 10 ms if the read MDAT is zero,
160 + * the nominal value of DETO is 20 ms.
162 + if (dev->devslp_timing[ATA_LOG_DEVSLP_VALID] &
163 + ATA_LOG_DEVSLP_VALID_MASK) {
164 + mdat = dev->devslp_timing[ATA_LOG_DEVSLP_MDAT] &
165 + ATA_LOG_DEVSLP_MDAT_MASK;
168 + deto = dev->devslp_timing[ATA_LOG_DEVSLP_DETO];
173 - deto = dev->devslp_timing[ATA_LOG_DEVSLP_DETO];
182 /* Make dito, mdat, deto bits to 0s */
183 @@ -2276,19 +2299,53 @@ static int ahci_port_suspend(struct ata_
188 + * Allocate port privdata and read back initial power management configuration
190 +int ahci_setup_port_privdata(struct ata_port *ap)
192 + struct ahci_port_priv *pp;
194 + void __iomem *port_mmio = ahci_port_base(ap);
196 + pp = kzalloc(sizeof(*pp), GFP_KERNEL);
200 + ap->private_data = pp;
202 + cmd = readl(port_mmio + PORT_CMD);
204 + if (cmd & PORT_CMD_ALPE)
205 + pp->init_alpe = true;
207 + if (cmd & PORT_CMD_ASP)
208 + pp->init_asp = true;
210 + devslp = readl(port_mmio + PORT_DEVSLP);
212 + /* devslp unsupported or disabled */
213 + if (!(devslp & PORT_DEVSLP_DSP) || !(devslp & PORT_DEVSLP_ADSE))
216 + pp->init_devslp = true;
217 + pp->init_dito = (devslp >> PORT_DEVSLP_DITO_OFFSET) & 0x3ff;
218 + pp->init_deto = (devslp >> PORT_DEVSLP_DETO_OFFSET) & 0xff;
219 + pp->init_mdat = (devslp >> PORT_DEVSLP_MDAT_OFFSET) & 0x1f;
223 +EXPORT_SYMBOL_GPL(ahci_setup_port_privdata);
225 static int ahci_port_start(struct ata_port *ap)
227 struct ahci_host_priv *hpriv = ap->host->private_data;
228 + struct ahci_port_priv *pp = ap->private_data;
229 struct device *dev = ap->host->dev;
230 - struct ahci_port_priv *pp;
233 size_t dma_sz, rx_fis_sz;
235 - pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
239 if (ap->host->n_ports > 1) {
240 pp->irq_desc = devm_kzalloc(dev, 8, GFP_KERNEL);
242 @@ -2367,8 +2424,6 @@ static int ahci_port_start(struct ata_po
243 ap->lock = &pp->lock;
246 - ap->private_data = pp;
248 /* engage engines, captain */
249 return ahci_port_resume(ap);
251 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libahci_platform.c linux-4.4/drivers/ata/libahci_platform.c
252 --- linux-4.4/drivers/ata/libahci_platform.c 2021-02-24 17:42:34.233049827 +0100
253 +++ linux-4.4/drivers/ata/libahci_platform.c 2021-02-24 17:42:47.896785319 +0100
254 @@ -569,6 +569,10 @@ int ahci_platform_init_host(struct platf
255 if (ap->flags & ATA_FLAG_EM)
256 ap->em_message_type = hpriv->em_msg_type;
258 + rc = ahci_setup_port_privdata(ap);
262 /* disabled/not-implemented port */
263 if (!(hpriv->port_map & (1 << i)))
264 ap->ops = &ata_dummy_port_ops;
265 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libata-core.c linux-4.4/drivers/ata/libata-core.c
266 --- linux-4.4/drivers/ata/libata-core.c 2021-02-24 17:42:34.233049827 +0100
267 +++ linux-4.4/drivers/ata/libata-core.c 2021-02-24 17:42:47.903452182 +0100
268 @@ -2023,6 +2023,9 @@ retry:
272 + if (id[79] & (1 << SATA_DIPM))
273 + dev->init_dipm = true;
278 @@ -3657,6 +3660,11 @@ int sata_link_scr_lpm(struct ata_link *l
282 + case ATA_LPM_FIRMWARE_DEFAULTS:
283 + /* use the values we read at probe */
284 + scontrol &= ~(0x7 << 8);
285 + scontrol |= (link->init_lpm << 8);
287 case ATA_LPM_MAX_POWER:
288 /* disable all LPM transitions */
289 scontrol |= (0x7 << 8);
290 @@ -3667,10 +3675,6 @@ int sata_link_scr_lpm(struct ata_link *l
293 case ATA_LPM_MED_POWER:
294 - /* allow LPM to PARTIAL */
295 - scontrol &= ~(0x1 << 8);
296 - scontrol |= (0x6 << 8);
298 case ATA_LPM_MIN_POWER:
299 if (ata_link_nr_enabled(link) > 0)
300 /* no restrictions on LPM transitions */
301 @@ -5627,11 +5631,11 @@ void ata_link_init(struct ata_port *ap,
305 - * sata_link_init_spd - Initialize link->sata_spd_limit
306 - * @link: Link to configure sata_spd_limit for
307 + * sata_link_init_config - Initialize link->sata_spd_limit and init_lpm
308 + * @link: Link to configure sata_spd_limit and init_lpm for
310 - * Initialize @link->[hw_]sata_spd_limit to the currently
311 - * configured value.
312 + * Initialize @link->[hw_]sata_spd_limit and @link->init_lpm to the
313 + * currently configured value.
316 * Kernel thread context (may sleep).
317 @@ -5639,7 +5643,7 @@ void ata_link_init(struct ata_port *ap,
319 * 0 on success, -errno on failure.
321 -int sata_link_init_spd(struct ata_link *link)
322 +int sata_link_init_config(struct ata_link *link)
326 @@ -5656,6 +5660,8 @@ int sata_link_init_spd(struct ata_link *
328 link->sata_spd_limit = link->hw_sata_spd_limit;
330 + link->init_lpm = (link->saved_scontrol >> 8) & 0x7;
335 @@ -6205,9 +6211,9 @@ int ata_host_register(struct ata_host *h
336 ap->cbl = ATA_CBL_SATA;
338 /* init sata_spd_limit to the current value */
339 - sata_link_init_spd(&ap->link);
340 + sata_link_init_config(&ap->link);
342 - sata_link_init_spd(ap->slave_link);
343 + sata_link_init_config(ap->slave_link);
345 /* print per-port info to dmesg */
346 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
347 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libata-eh.c linux-4.4/drivers/ata/libata-eh.c
348 --- linux-4.4/drivers/ata/libata-eh.c 2021-02-24 17:42:34.236383257 +0100
349 +++ linux-4.4/drivers/ata/libata-eh.c 2021-02-24 17:42:47.906785614 +0100
350 @@ -3441,9 +3441,7 @@ static int ata_eh_set_lpm(struct ata_lin
354 - * DIPM is enabled only for MIN_POWER as some devices
355 - * misbehave when the host NACKs transition to SLUMBER. Order
356 - * device and link configurations such that the host always
357 + * Order device and link configurations such that the host always
358 * allows DIPM requests.
360 ata_for_each_dev(dev, link, ENABLED) {
361 @@ -3462,7 +3460,7 @@ static int ata_eh_set_lpm(struct ata_lin
362 hints &= ~ATA_LPM_HIPM;
364 /* disable DIPM before changing link config */
365 - if (policy != ATA_LPM_MIN_POWER && dipm) {
366 + if (policy < ATA_LPM_MED_POWER && dipm) {
367 err_mask = ata_dev_set_feature(dev,
368 SETFEATURES_SATA_DISABLE, SATA_DIPM);
369 if (err_mask && err_mask != AC_ERR_DEV) {
370 @@ -3503,10 +3501,13 @@ static int ata_eh_set_lpm(struct ata_lin
371 if (ap && ap->slave_link)
372 ap->slave_link->lpm_policy = policy;
374 - /* host config updated, enable DIPM if transitioning to MIN_POWER */
375 + /* host config updated, enable DIPM if transitioning to MED_POWER,
376 + * MIN_POWER or FIRMWARE_DEFAULT when enabled by firmware
378 ata_for_each_dev(dev, link, ENABLED) {
379 - if (policy == ATA_LPM_MIN_POWER && !no_dipm &&
380 - ata_id_has_dipm(dev->id)) {
381 + if ((policy >= ATA_LPM_MED_POWER && !no_dipm &&
382 + ata_id_has_dipm(dev->id)) ||
383 + (policy == ATA_LPM_FIRMWARE_DEFAULTS && dev->init_dipm)) {
384 err_mask = ata_dev_set_feature(dev,
385 SETFEATURES_SATA_ENABLE, SATA_DIPM);
386 if (err_mask && err_mask != AC_ERR_DEV) {
387 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libata-pmp.c linux-4.4/drivers/ata/libata-pmp.c
388 --- linux-4.4/drivers/ata/libata-pmp.c 2021-02-24 17:42:34.236383257 +0100
389 +++ linux-4.4/drivers/ata/libata-pmp.c 2021-02-24 17:42:47.900118751 +0100
390 @@ -538,7 +538,7 @@ int sata_pmp_attach(struct ata_device *d
391 ap->ops->pmp_attach(ap);
393 ata_for_each_link(tlink, ap, EDGE)
394 - sata_link_init_spd(tlink);
395 + sata_link_init_config(tlink);
399 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libata-scsi.c linux-4.4/drivers/ata/libata-scsi.c
400 --- linux-4.4/drivers/ata/libata-scsi.c 2021-02-24 17:42:34.236383257 +0100
401 +++ linux-4.4/drivers/ata/libata-scsi.c 2021-02-24 17:42:47.903452182 +0100
402 @@ -107,6 +107,7 @@ static const u8 def_control_mpage[CONTRO
403 static const char *ata_lpm_policy_names[] = {
404 [ATA_LPM_UNKNOWN] = "max_performance",
405 [ATA_LPM_MAX_POWER] = "max_performance",
406 + [ATA_LPM_FIRMWARE_DEFAULTS] = "firmware_defaults",
407 [ATA_LPM_MED_POWER] = "medium_power",
408 [ATA_LPM_MIN_POWER] = "min_power",
410 diff -urNp -x '*.orig' linux-4.4/drivers/ata/libata.h linux-4.4/drivers/ata/libata.h
411 --- linux-4.4/drivers/ata/libata.h 2016-01-11 00:01:32.000000000 +0100
412 +++ linux-4.4/drivers/ata/libata.h 2021-02-24 17:42:47.900118751 +0100
413 @@ -98,7 +98,7 @@ extern bool ata_phys_link_online(struct
414 extern bool ata_phys_link_offline(struct ata_link *link);
415 extern void ata_dev_init(struct ata_device *dev);
416 extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp);
417 -extern int sata_link_init_spd(struct ata_link *link);
418 +extern int sata_link_init_config(struct ata_link *link);
419 extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
420 extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
421 extern struct ata_port *ata_port_alloc(struct ata_host *host);
422 diff -urNp -x '*.orig' linux-4.4/drivers/ata/sata_highbank.c linux-4.4/drivers/ata/sata_highbank.c
423 --- linux-4.4/drivers/ata/sata_highbank.c 2016-01-11 00:01:32.000000000 +0100
424 +++ linux-4.4/drivers/ata/sata_highbank.c 2021-02-24 17:42:47.900118751 +0100
425 @@ -557,6 +557,10 @@ static int ahci_highbank_probe(struct pl
426 if (ap->flags & ATA_FLAG_EM)
427 ap->em_message_type = hpriv->em_msg_type;
429 + rc = ahci_setup_port_privdata(ap);
433 /* disabled/not-implemented port */
434 if (!(hpriv->port_map & (1 << i)))
435 ap->ops = &ata_dummy_port_ops;
436 diff -urNp -x '*.orig' linux-4.4/include/linux/libata.h linux-4.4/include/linux/libata.h
437 --- linux-4.4/include/linux/libata.h 2021-02-24 17:42:35.659758447 +0100
438 +++ linux-4.4/include/linux/libata.h 2021-02-24 17:42:47.903452182 +0100
439 @@ -521,6 +521,7 @@ enum ata_completion_errors {
440 enum ata_lpm_policy {
443 + ATA_LPM_FIRMWARE_DEFAULTS,
447 @@ -733,6 +734,8 @@ struct ata_device {
449 /* ering is CLEAR_END, read comment above CLEAR_END */
450 struct ata_ering ering;
451 + /* Initial DIPM configuration */
455 /* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
456 @@ -804,6 +807,7 @@ struct ata_link {
457 struct ata_device device[ATA_MAX_DEVICES];
459 unsigned long last_lpm_change; /* when last LPM change happened */
460 + u8 init_lpm; /* initial lpm configuration */
462 #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
463 #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])