1 From b1c72916abbdd0a55015c87358536ca0ebaf6735 Mon Sep 17 00:00:00 2001
2 From: Tejun Heo <tj@kernel.org>
3 Date: Thu, 31 Jul 2008 17:02:43 +0900
4 Subject: [PATCH] libata: implement slave_link
7 Explanation taken from the comment of ata_slave_link_init().
9 In libata, a port contains links and a link contains devices. There
10 is single host link but if a PMP is attached to it, there can be
11 multiple fan-out links. On SATA, there's usually a single device
12 connected to a link but PATA and SATA controllers emulating TF based
13 interface can have two - master and slave.
15 However, there are a few controllers which don't fit into this
16 abstraction too well - SATA controllers which emulate TF interface
17 with both master and slave devices but also have separate SCR
18 register sets for each device. These controllers need separate links
19 for physical link handling (e.g. onlineness, link speed) but should
20 be treated like a traditional M/S controller for everything else
21 (e.g. command issue, softreset).
23 slave_link is libata's way of handling this class of controllers
24 without impacting core layer too much. For anything other than
25 physical link handling, the default host link is used for both master
26 and slave. For physical link handling, separate @ap->slave_link is
27 used. All dirty details are implemented inside libata core layer.
28 From LLD's POV, the only difference is that prereset, hardreset and
29 postreset are called once more for the slave link, so the reset
30 sequence looks like the following.
32 prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
33 softreset(M) -> postreset(M) -> postreset(S)
35 Note that softreset is called only for the master. Softreset resets
36 both M/S by definition, so SRST on master should handle both (the
37 standard method will work just fine).
39 As slave_link excludes PMP support and only code paths which deal with
40 the attributes of physical link are affected, all the changes are
41 localized to libata.h, libata-core.c and libata-eh.c.
43 * ata_is_host_link() updated so that slave_link is considered as host
46 * iterator extended to iterate over the slave_link when using the
49 * force param handling updated such that devno 16 is mapped to the
52 * ata_link_on/offline() updated to return the combined result from
53 master and slave link. ata_phys_link_on/offline() are the direct
56 * EH autopsy and report are performed separately for master slave
57 links. Reset is udpated to implement the above described reset
60 Except for reset update, most changes are minor, many of them just
61 modifying dev->link to ata_dev_phys_link(dev) or using phys online
64 After this update, LLDs can take full advantage of per-dev SCR
65 registers by simply turning on slave link.
67 Signed-off-by: Tejun Heo <tj@kernel.org>
68 Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
69 Signed-off-by: Tejun Heo <teheo@suse.de>
71 drivers/ata/libata-core.c | 202 ++++++++++++++++++++++++++++++++++++++++------
72 drivers/ata/libata-eh.c | 142 ++++++++++++++++++++++++++------
73 drivers/ata/libata.h | 3
74 include/linux/libata.h | 8 +
75 4 files changed, 303 insertions(+), 52 deletions(-)
77 --- a/drivers/ata/libata-core.c
78 +++ b/drivers/ata/libata-core.c
79 @@ -179,13 +179,20 @@ struct ata_link *__ata_port_next_link(st
83 - /* we just iterated over the host link, what's next? */
84 - if (ata_is_host_link(link)) {
85 - if (!sata_pmp_attached(ap))
86 + /* we just iterated over the host master link, what's next? */
87 + if (link == &ap->link) {
88 + if (!sata_pmp_attached(ap)) {
89 + if (unlikely(ap->slave_link) && !dev_only)
90 + return ap->slave_link;
96 + /* slave_link excludes PMP */
97 + if (unlikely(link == ap->slave_link))
100 /* iterate to the next PMP link */
101 if (++link < ap->pmp_link + ap->nr_pmp_links)
103 @@ -193,6 +200,31 @@ struct ata_link *__ata_port_next_link(st
107 + * ata_dev_phys_link - find physical link for a device
108 + * @dev: ATA device to look up physical link for
110 + * Look up physical link which @dev is attached to. Note that
111 + * this is different from @dev->link only when @dev is on slave
112 + * link. For all other cases, it's the same as @dev->link.
118 + * Pointer to the found physical link.
120 +struct ata_link *ata_dev_phys_link(struct ata_device *dev)
122 + struct ata_port *ap = dev->link->ap;
124 + if (!ap->slave_link)
128 + return ap->slave_link;
132 * ata_force_cbl - force cable type according to libata.force
133 * @ap: ATA port of interest
135 @@ -235,7 +267,8 @@ void ata_force_cbl(struct ata_port *ap)
136 * the host link and all fan-out ports connected via PMP. If the
137 * device part is specified as 0 (e.g. 1.00:), it specifies the
138 * first fan-out link not the host link. Device number 15 always
139 - * points to the host link whether PMP is attached or not.
140 + * points to the host link whether PMP is attached or not. If the
141 + * controller has slave link, device number 16 points to it.
145 @@ -243,12 +276,11 @@ void ata_force_cbl(struct ata_port *ap)
146 static void ata_force_link_limits(struct ata_link *link)
148 bool did_spd = false;
150 + int linkno = link->pmp;
153 if (ata_is_host_link(link))
156 - linkno = link->pmp;
159 for (i = ata_force_tbl_size - 1; i >= 0; i--) {
160 const struct ata_force_ent *fe = &ata_force_tbl[i];
161 @@ -295,9 +327,9 @@ static void ata_force_xfermask(struct at
162 int alt_devno = devno;
165 - /* allow n.15 for the first device attached to host port */
166 - if (ata_is_host_link(dev->link) && devno == 0)
168 + /* allow n.15/16 for devices attached to host port */
169 + if (ata_is_host_link(dev->link))
172 for (i = ata_force_tbl_size - 1; i >= 0; i--) {
173 const struct ata_force_ent *fe = &ata_force_tbl[i];
174 @@ -349,9 +381,9 @@ static void ata_force_horkage(struct ata
175 int alt_devno = devno;
178 - /* allow n.15 for the first device attached to host port */
179 - if (ata_is_host_link(dev->link) && devno == 0)
181 + /* allow n.15/16 for devices attached to host port */
182 + if (ata_is_host_link(dev->link))
185 for (i = 0; i < ata_force_tbl_size; i++) {
186 const struct ata_force_ent *fe = &ata_force_tbl[i];
187 @@ -2719,7 +2751,7 @@ static void sata_print_link_status(struc
189 sata_scr_read(link, SCR_CONTROL, &scontrol);
191 - if (ata_link_online(link)) {
192 + if (ata_phys_link_online(link)) {
193 tmp = (sstatus >> 4) & 0xf;
194 ata_link_printk(link, KERN_INFO,
195 "SATA link up %s (SStatus %X SControl %X)\n",
196 @@ -3410,6 +3442,12 @@ int ata_wait_ready(struct ata_link *link
197 unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
200 + /* Slave readiness can't be tested separately from master. On
201 + * M/S emulation configuration, this function should be called
202 + * only on the master and it will handle both master and slave.
204 + WARN_ON(link == link->ap->slave_link);
206 if (time_after(nodev_deadline, deadline))
207 nodev_deadline = deadline;
209 @@ -3631,7 +3669,7 @@ int ata_std_prereset(struct ata_link *li
212 /* no point in trying softreset on offline link */
213 - if (ata_link_offline(link))
214 + if (ata_phys_link_offline(link))
215 ehc->i.action &= ~ATA_EH_SOFTRESET;
218 @@ -3709,7 +3747,7 @@ int sata_link_hardreset(struct ata_link
221 /* if link is offline nothing more to do */
222 - if (ata_link_offline(link))
223 + if (ata_phys_link_offline(link))
226 /* Link is online. From this point, -ENODEV too is an error. */
227 @@ -5041,7 +5079,7 @@ int sata_scr_write_flush(struct ata_link
231 - * ata_link_online - test whether the given link is online
232 + * ata_phys_link_online - test whether the given link is online
233 * @link: ATA link to test
235 * Test whether @link is online. Note that this function returns
236 @@ -5054,7 +5092,7 @@ int sata_scr_write_flush(struct ata_link
238 * True if the port online status is available and online.
240 -bool ata_link_online(struct ata_link *link)
241 +bool ata_phys_link_online(struct ata_link *link)
245 @@ -5065,7 +5103,7 @@ bool ata_link_online(struct ata_link *li
249 - * ata_link_offline - test whether the given link is offline
250 + * ata_phys_link_offline - test whether the given link is offline
251 * @link: ATA link to test
253 * Test whether @link is offline. Note that this function
254 @@ -5078,7 +5116,7 @@ bool ata_link_online(struct ata_link *li
256 * True if the port offline status is available and offline.
258 -bool ata_link_offline(struct ata_link *link)
259 +bool ata_phys_link_offline(struct ata_link *link)
263 @@ -5088,6 +5126,58 @@ bool ata_link_offline(struct ata_link *l
268 + * ata_link_online - test whether the given link is online
269 + * @link: ATA link to test
271 + * Test whether @link is online. This is identical to
272 + * ata_phys_link_online() when there's no slave link. When
273 + * there's a slave link, this function should only be called on
274 + * the master link and will return true if any of M/S links is
281 + * True if the port online status is available and online.
283 +bool ata_link_online(struct ata_link *link)
285 + struct ata_link *slave = link->ap->slave_link;
287 + WARN_ON(link == slave); /* shouldn't be called on slave link */
289 + return ata_phys_link_online(link) ||
290 + (slave && ata_phys_link_online(slave));
294 + * ata_link_offline - test whether the given link is offline
295 + * @link: ATA link to test
297 + * Test whether @link is offline. This is identical to
298 + * ata_phys_link_offline() when there's no slave link. When
299 + * there's a slave link, this function should only be called on
300 + * the master link and will return true if both M/S links are
307 + * True if the port offline status is available and offline.
309 +bool ata_link_offline(struct ata_link *link)
311 + struct ata_link *slave = link->ap->slave_link;
313 + WARN_ON(link == slave); /* shouldn't be called on slave link */
315 + return ata_phys_link_offline(link) &&
316 + (!slave || ata_phys_link_offline(slave));
320 static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
321 unsigned int action, unsigned int ehi_flags,
322 @@ -5227,11 +5317,11 @@ int ata_port_start(struct ata_port *ap)
324 void ata_dev_init(struct ata_device *dev)
326 - struct ata_link *link = dev->link;
327 + struct ata_link *link = ata_dev_phys_link(dev);
328 struct ata_port *ap = link->ap;
331 - /* SATA spd limit is bound to the first device */
332 + /* SATA spd limit is bound to the attached device, reset together */
333 link->sata_spd_limit = link->hw_sata_spd_limit;
336 @@ -5396,6 +5486,7 @@ static void ata_host_release(struct devi
337 scsi_host_put(ap->scsi_host);
340 + kfree(ap->slave_link);
342 host->ports[i] = NULL;
344 @@ -5516,6 +5607,68 @@ struct ata_host *ata_host_alloc_pinfo(st
349 + * ata_slave_link_init - initialize slave link
350 + * @ap: port to initialize slave link for
352 + * Create and initialize slave link for @ap. This enables slave
353 + * link handling on the port.
355 + * In libata, a port contains links and a link contains devices.
356 + * There is single host link but if a PMP is attached to it,
357 + * there can be multiple fan-out links. On SATA, there's usually
358 + * a single device connected to a link but PATA and SATA
359 + * controllers emulating TF based interface can have two - master
362 + * However, there are a few controllers which don't fit into this
363 + * abstraction too well - SATA controllers which emulate TF
364 + * interface with both master and slave devices but also have
365 + * separate SCR register sets for each device. These controllers
366 + * need separate links for physical link handling
367 + * (e.g. onlineness, link speed) but should be treated like a
368 + * traditional M/S controller for everything else (e.g. command
369 + * issue, softreset).
371 + * slave_link is libata's way of handling this class of
372 + * controllers without impacting core layer too much. For
373 + * anything other than physical link handling, the default host
374 + * link is used for both master and slave. For physical link
375 + * handling, separate @ap->slave_link is used. All dirty details
376 + * are implemented inside libata core layer. From LLD's POV, the
377 + * only difference is that prereset, hardreset and postreset are
378 + * called once more for the slave link, so the reset sequence
379 + * looks like the following.
381 + * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
382 + * softreset(M) -> postreset(M) -> postreset(S)
384 + * Note that softreset is called only for the master. Softreset
385 + * resets both M/S by definition, so SRST on master should handle
386 + * both (the standard method will work just fine).
389 + * Should be called before host is registered.
392 + * 0 on success, -errno on failure.
394 +int ata_slave_link_init(struct ata_port *ap)
396 + struct ata_link *link;
398 + WARN_ON(ap->slave_link);
399 + WARN_ON(ap->flags & ATA_FLAG_PMP);
401 + link = kzalloc(sizeof(*link), GFP_KERNEL);
405 + ata_link_init(ap, link, 1);
406 + ap->slave_link = link;
410 static void ata_host_stop(struct device *gendev, void *res)
412 struct ata_host *host = dev_get_drvdata(gendev);
413 @@ -5742,6 +5895,8 @@ int ata_host_register(struct ata_host *h
415 /* init sata_spd_limit to the current value */
416 sata_link_init_spd(&ap->link);
417 + if (ap->slave_link)
418 + sata_link_init_spd(ap->slave_link);
420 /* print per-port info to dmesg */
421 xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
422 @@ -6367,6 +6522,7 @@ EXPORT_SYMBOL_GPL(ata_std_bios_param);
423 EXPORT_SYMBOL_GPL(ata_host_init);
424 EXPORT_SYMBOL_GPL(ata_host_alloc);
425 EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo);
426 +EXPORT_SYMBOL_GPL(ata_slave_link_init);
427 EXPORT_SYMBOL_GPL(ata_host_start);
428 EXPORT_SYMBOL_GPL(ata_host_register);
429 EXPORT_SYMBOL_GPL(ata_host_activate);
430 --- a/drivers/ata/libata-eh.c
431 +++ b/drivers/ata/libata-eh.c
432 @@ -1753,7 +1753,7 @@ static unsigned int ata_eh_speed_down_ve
433 static unsigned int ata_eh_speed_down(struct ata_device *dev,
434 unsigned int eflags, unsigned int err_mask)
436 - struct ata_link *link = dev->link;
437 + struct ata_link *link = ata_dev_phys_link(dev);
439 unsigned int verdict;
440 unsigned int action = 0;
441 @@ -1877,7 +1877,8 @@ static void ata_eh_link_autopsy(struct a
442 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
443 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
445 - if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link)
446 + if (!(qc->flags & ATA_QCFLAG_FAILED) ||
447 + ata_dev_phys_link(qc->dev) != link)
450 /* inherit upper level err_mask */
451 @@ -1964,6 +1965,23 @@ void ata_eh_autopsy(struct ata_port *ap)
452 ata_port_for_each_link(link, ap)
453 ata_eh_link_autopsy(link);
455 + /* Handle the frigging slave link. Autopsy is done similarly
456 + * but actions and flags are transferred over to the master
457 + * link and handled from there.
459 + if (ap->slave_link) {
460 + struct ata_eh_context *mehc = &ap->link.eh_context;
461 + struct ata_eh_context *sehc = &ap->slave_link->eh_context;
463 + ata_eh_link_autopsy(ap->slave_link);
465 + ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
466 + mehc->i.action |= sehc->i.action;
467 + mehc->i.dev_action[1] |= sehc->i.dev_action[1];
468 + mehc->i.flags |= sehc->i.flags;
469 + ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
472 /* Autopsy of fanout ports can affect host link autopsy.
473 * Perform host link autopsy last.
475 @@ -1998,7 +2016,8 @@ static void ata_eh_link_report(struct at
476 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
477 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
479 - if (!(qc->flags & ATA_QCFLAG_FAILED) || qc->dev->link != link ||
480 + if (!(qc->flags & ATA_QCFLAG_FAILED) ||
481 + ata_dev_phys_link(qc->dev) != link ||
482 ((qc->flags & ATA_QCFLAG_QUIET) &&
483 qc->err_mask == AC_ERR_DEV))
485 @@ -2065,7 +2084,7 @@ static void ata_eh_link_report(struct at
486 char cdb_buf[70] = "";
488 if (!(qc->flags & ATA_QCFLAG_FAILED) ||
489 - qc->dev->link != link || !qc->err_mask)
490 + ata_dev_phys_link(qc->dev) != link || !qc->err_mask)
493 if (qc->dma_dir != DMA_NONE) {
494 @@ -2157,12 +2176,14 @@ void ata_eh_report(struct ata_port *ap)
497 static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
498 - unsigned int *classes, unsigned long deadline)
499 + unsigned int *classes, unsigned long deadline,
500 + bool clear_classes)
502 struct ata_device *dev;
504 - ata_link_for_each_dev(dev, link)
505 - classes[dev->devno] = ATA_DEV_UNKNOWN;
507 + ata_link_for_each_dev(dev, link)
508 + classes[dev->devno] = ATA_DEV_UNKNOWN;
510 return reset(link, classes, deadline);
512 @@ -2184,17 +2205,20 @@ int ata_eh_reset(struct ata_link *link,
513 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
515 struct ata_port *ap = link->ap;
516 + struct ata_link *slave = ap->slave_link;
517 struct ata_eh_context *ehc = &link->eh_context;
518 + struct ata_eh_context *sehc = &slave->eh_context;
519 unsigned int *classes = ehc->classes;
520 unsigned int lflags = link->flags;
521 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
522 int max_tries = 0, try = 0;
523 + struct ata_link *failed_link;
524 struct ata_device *dev;
525 unsigned long deadline, now;
526 ata_reset_fn_t reset;
530 + int nr_unknown, rc;
534 @@ -2253,8 +2277,30 @@ int ata_eh_reset(struct ata_link *link,
538 - rc = prereset(link,
539 - ata_deadline(jiffies, ATA_EH_PRERESET_TIMEOUT));
540 + unsigned long deadline = ata_deadline(jiffies,
541 + ATA_EH_PRERESET_TIMEOUT);
544 + sehc->i.action &= ~ATA_EH_RESET;
545 + sehc->i.action |= ehc->i.action;
548 + rc = prereset(link, deadline);
550 + /* If present, do prereset on slave link too. Reset
551 + * is skipped iff both master and slave links report
552 + * -ENOENT or clear ATA_EH_RESET.
554 + if (slave && (rc == 0 || rc == -ENOENT)) {
557 + tmp = prereset(slave, deadline);
558 + if (tmp != -ENOENT)
561 + ehc->i.action |= sehc->i.action;
566 ata_link_printk(link, KERN_DEBUG,
567 @@ -2306,25 +2352,51 @@ int ata_eh_reset(struct ata_link *link,
569 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
571 - rc = ata_do_reset(link, reset, classes, deadline);
572 - if (rc && rc != -EAGAIN)
573 + rc = ata_do_reset(link, reset, classes, deadline, true);
574 + if (rc && rc != -EAGAIN) {
575 + failed_link = link;
579 + /* hardreset slave link if existent */
580 + if (slave && reset == hardreset) {
584 + ata_link_printk(slave, KERN_INFO,
585 + "hard resetting link\n");
587 + ata_eh_about_to_do(slave, NULL, ATA_EH_RESET);
588 + tmp = ata_do_reset(slave, reset, classes, deadline,
596 + failed_link = slave;
602 + /* perform follow-up SRST if necessary */
603 if (reset == hardreset &&
604 ata_eh_followup_srst_needed(link, rc, classes)) {
605 - /* okay, let's do follow-up softreset */
609 ata_link_printk(link, KERN_ERR,
610 "follow-up softreset required "
611 "but no softreset avaliable\n");
612 + failed_link = link;
617 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
618 - rc = ata_do_reset(link, reset, classes, deadline);
619 + rc = ata_do_reset(link, reset, classes, deadline, true);
623 @@ -2345,7 +2417,7 @@ int ata_eh_reset(struct ata_link *link,
624 dev->pio_mode = XFER_PIO_0;
625 dev->flags &= ~ATA_DFLAG_SLEEPING;
627 - if (ata_link_offline(link))
628 + if (ata_phys_link_offline(ata_dev_phys_link(dev)))
631 /* apply class override */
632 @@ -2358,6 +2430,8 @@ int ata_eh_reset(struct ata_link *link,
633 /* record current link speed */
634 if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
635 link->sata_spd = (sstatus >> 4) & 0xf;
636 + if (slave && sata_scr_read(slave, SCR_STATUS, &sstatus) == 0)
637 + slave->sata_spd = (sstatus >> 4) & 0xf;
640 if (ata_is_host_link(link))
641 @@ -2370,12 +2444,17 @@ int ata_eh_reset(struct ata_link *link,
642 * reset and here. This race is mediated by cross checking
643 * link onlineness and classification result later.
647 postreset(link, classes);
649 + postreset(slave, classes);
652 /* clear cached SError */
653 spin_lock_irqsave(link->ap->lock, flags);
654 link->eh_info.serror = 0;
656 + slave->eh_info.serror = 0;
657 spin_unlock_irqrestore(link->ap->lock, flags);
659 /* Make sure onlineness and classification result correspond.
660 @@ -2385,19 +2464,21 @@ int ata_eh_reset(struct ata_link *link,
661 * link onlineness and classification result, those conditions
662 * can be reliably detected and retried.
666 ata_link_for_each_dev(dev, link) {
667 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */
668 - if (classes[dev->devno] == ATA_DEV_UNKNOWN)
669 + if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
670 classes[dev->devno] = ATA_DEV_NONE;
673 + if (ata_phys_link_online(ata_dev_phys_link(dev)))
678 - if (classify && !nr_known && ata_link_online(link)) {
679 + if (classify && nr_unknown) {
680 if (try < max_tries) {
681 ata_link_printk(link, KERN_WARNING, "link online but "
682 "device misclassified, retrying\n");
683 + failed_link = link;
687 @@ -2408,6 +2489,8 @@ int ata_eh_reset(struct ata_link *link,
689 /* reset successful, schedule revalidation */
690 ata_eh_done(link, NULL, ATA_EH_RESET);
692 + ata_eh_done(slave, NULL, ATA_EH_RESET);
693 ehc->last_reset = jiffies; /* update to completion time */
694 ehc->i.action |= ATA_EH_REVALIDATE;
696 @@ -2415,6 +2498,8 @@ int ata_eh_reset(struct ata_link *link,
698 /* clear hotplug flag */
699 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
701 + sehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
703 spin_lock_irqsave(ap->lock, flags);
704 ap->pflags &= ~ATA_PFLAG_RESETTING;
705 @@ -2435,7 +2520,7 @@ int ata_eh_reset(struct ata_link *link,
706 if (time_before(now, deadline)) {
707 unsigned long delta = deadline - now;
709 - ata_link_printk(link, KERN_WARNING,
710 + ata_link_printk(failed_link, KERN_WARNING,
711 "reset failed (errno=%d), retrying in %u secs\n",
712 rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000));
714 @@ -2443,8 +2528,13 @@ int ata_eh_reset(struct ata_link *link,
715 delta = schedule_timeout_uninterruptible(delta);
718 - if (rc == -EPIPE || try == max_tries - 1)
719 + if (try == max_tries - 1) {
720 sata_down_spd_limit(link);
722 + sata_down_spd_limit(slave);
723 + } else if (rc == -EPIPE)
724 + sata_down_spd_limit(failed_link);
729 @@ -2476,7 +2566,7 @@ static int ata_eh_revalidate_and_attach(
730 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
731 WARN_ON(dev->class == ATA_DEV_PMP);
733 - if (ata_link_offline(link)) {
734 + if (ata_phys_link_offline(ata_dev_phys_link(dev))) {
738 @@ -2701,7 +2791,7 @@ static int ata_eh_handle_dev_fail(struct
739 /* This is the last chance, better to slow
742 - sata_down_spd_limit(dev->link);
743 + sata_down_spd_limit(ata_dev_phys_link(dev));
744 if (dev->pio_mode > XFER_PIO_0)
745 ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
747 @@ -2712,7 +2802,7 @@ static int ata_eh_handle_dev_fail(struct
748 ata_dev_disable(dev);
750 /* detach if offline */
751 - if (ata_link_offline(dev->link))
752 + if (ata_phys_link_offline(ata_dev_phys_link(dev)))
753 ata_eh_detach_dev(dev);
755 /* schedule probe if necessary */
756 --- a/drivers/ata/libata.h
757 +++ b/drivers/ata/libata.h
758 @@ -70,6 +70,7 @@ extern int atapi_passthru16;
759 extern int libata_fua;
760 extern int libata_noacpi;
761 extern int libata_allow_tpm;
762 +extern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
763 extern void ata_force_cbl(struct ata_port *ap);
764 extern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
765 extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
766 @@ -107,6 +108,8 @@ extern void ata_qc_issue(struct ata_queu
767 extern void __ata_qc_complete(struct ata_queued_cmd *qc);
768 extern int atapi_check_dma(struct ata_queued_cmd *qc);
769 extern void swap_buf_le16(u16 *buf, unsigned int buf_words);
770 +extern bool ata_phys_link_online(struct ata_link *link);
771 +extern bool ata_phys_link_offline(struct ata_link *link);
772 extern void ata_dev_init(struct ata_device *dev);
773 extern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp);
774 extern int sata_link_init_spd(struct ata_link *link);
775 --- a/include/linux/libata.h
776 +++ b/include/linux/libata.h
777 @@ -691,7 +691,8 @@ struct ata_port {
778 unsigned int qc_active;
779 int nr_active_links; /* #links with active qcs */
781 - struct ata_link link; /* host default link */
782 + struct ata_link link; /* host default link */
783 + struct ata_link *slave_link; /* see ata_slave_link_init() */
785 int nr_pmp_links; /* nr of available PMP links */
786 struct ata_link *pmp_link; /* array of PMP links */
787 @@ -898,6 +899,7 @@ extern void ata_port_disable(struct ata_
788 extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
789 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
790 const struct ata_port_info * const * ppi, int n_ports);
791 +extern int ata_slave_link_init(struct ata_port *ap);
792 extern int ata_host_start(struct ata_host *host);
793 extern int ata_host_register(struct ata_host *host,
794 struct scsi_host_template *sht);
795 @@ -1137,7 +1139,7 @@ static inline bool sata_pmp_attached(str
797 static inline int ata_is_host_link(const struct ata_link *link)
799 - return link == &link->ap->link;
800 + return link == &link->ap->link || link == link->ap->slave_link;
802 #else /* CONFIG_SATA_PMP */
803 static inline bool sata_pmp_supported(struct ata_port *ap)
804 @@ -1170,7 +1172,7 @@ static inline int sata_srst_pmp(struct a
805 printk("%sata%u: "fmt, lv, (ap)->print_id , ##args)
807 #define ata_link_printk(link, lv, fmt, args...) do { \
808 - if (sata_pmp_attached((link)->ap)) \
809 + if (sata_pmp_attached((link)->ap) || (link)->ap->slave_link) \
810 printk("%sata%u.%02u: "fmt, lv, (link)->ap->print_id, \
811 (link)->pmp , ##args); \