]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/suse-2.6.27.25/patches.drivers/libata-implement-slave_link
Revert "Move xen patchset to new version's subdir."
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.drivers / libata-implement-slave_link
CommitLineData
00e5a55c
BS
1From b1c72916abbdd0a55015c87358536ca0ebaf6735 Mon Sep 17 00:00:00 2001
2From: Tejun Heo <tj@kernel.org>
3Date: Thu, 31 Jul 2008 17:02:43 +0900
4Subject: [PATCH] libata: implement slave_link
5References: bnc#441420
6
7Explanation taken from the comment of ata_slave_link_init().
8
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.
14
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).
22
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.
31
32 prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
33 softreset(M) -> postreset(M) -> postreset(S)
34
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).
38
39As slave_link excludes PMP support and only code paths which deal with
40the attributes of physical link are affected, all the changes are
41localized to libata.h, libata-core.c and libata-eh.c.
42
43 * ata_is_host_link() updated so that slave_link is considered as host
44 link too.
45
46 * iterator extended to iterate over the slave_link when using the
47 underbarred version.
48
49 * force param handling updated such that devno 16 is mapped to the
50 slave link/device.
51
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
54 versions.
55
56 * EH autopsy and report are performed separately for master slave
57 links. Reset is udpated to implement the above described reset
58 sequence.
59
60Except for reset update, most changes are minor, many of them just
61modifying dev->link to ata_dev_phys_link(dev) or using phys online
62test instead.
63
64After this update, LLDs can take full advantage of per-dev SCR
65registers by simply turning on slave link.
66
67Signed-off-by: Tejun Heo <tj@kernel.org>
68Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
69Signed-off-by: Tejun Heo <teheo@suse.de>
70---
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(-)
76
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
80 return &ap->link;
81 }
82
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;
91 return NULL;
92+ }
93 return ap->pmp_link;
94 }
95
96+ /* slave_link excludes PMP */
97+ if (unlikely(link == ap->slave_link))
98+ return NULL;
99+
100 /* iterate to the next PMP link */
101 if (++link < ap->pmp_link + ap->nr_pmp_links)
102 return link;
103@@ -193,6 +200,31 @@ struct ata_link *__ata_port_next_link(st
104 }
105
106 /**
107+ * ata_dev_phys_link - find physical link for a device
108+ * @dev: ATA device to look up physical link for
109+ *
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.
113+ *
114+ * LOCKING:
115+ * Don't care.
116+ *
117+ * RETURNS:
118+ * Pointer to the found physical link.
119+ */
120+struct ata_link *ata_dev_phys_link(struct ata_device *dev)
121+{
122+ struct ata_port *ap = dev->link->ap;
123+
124+ if (!ap->slave_link)
125+ return dev->link;
126+ if (!dev->devno)
127+ return &ap->link;
128+ return ap->slave_link;
129+}
130+
131+/**
132 * ata_force_cbl - force cable type according to libata.force
133 * @ap: ATA port of interest
134 *
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.
142 *
143 * LOCKING:
144 * EH context.
145@@ -243,12 +276,11 @@ void ata_force_cbl(struct ata_port *ap)
146 static void ata_force_link_limits(struct ata_link *link)
147 {
148 bool did_spd = false;
149- int linkno, i;
150+ int linkno = link->pmp;
151+ int i;
152
153 if (ata_is_host_link(link))
154- linkno = 15;
155- else
156- linkno = link->pmp;
157+ linkno += 15;
158
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;
163 int i;
164
165- /* allow n.15 for the first device attached to host port */
166- if (ata_is_host_link(dev->link) && devno == 0)
167- alt_devno = 15;
168+ /* allow n.15/16 for devices attached to host port */
169+ if (ata_is_host_link(dev->link))
170+ alt_devno += 15;
171
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;
176 int i;
177
178- /* allow n.15 for the first device attached to host port */
179- if (ata_is_host_link(dev->link) && devno == 0)
180- alt_devno = 15;
181+ /* allow n.15/16 for devices attached to host port */
182+ if (ata_is_host_link(dev->link))
183+ alt_devno += 15;
184
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
188 return;
189 sata_scr_read(link, SCR_CONTROL, &scontrol);
190
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);
198 int warned = 0;
199
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.
203+ */
204+ WARN_ON(link == link->ap->slave_link);
205+
206 if (time_after(nodev_deadline, deadline))
207 nodev_deadline = deadline;
208
209@@ -3631,7 +3669,7 @@ int ata_std_prereset(struct ata_link *li
210 }
211
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;
216
217 return 0;
218@@ -3709,7 +3747,7 @@ int sata_link_hardreset(struct ata_link
219 if (rc)
220 goto out;
221 /* if link is offline nothing more to do */
222- if (ata_link_offline(link))
223+ if (ata_phys_link_offline(link))
224 goto out;
225
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
228 }
229
230 /**
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
234 *
235 * Test whether @link is online. Note that this function returns
236@@ -5054,7 +5092,7 @@ int sata_scr_write_flush(struct ata_link
237 * RETURNS:
238 * True if the port online status is available and online.
239 */
240-bool ata_link_online(struct ata_link *link)
241+bool ata_phys_link_online(struct ata_link *link)
242 {
243 u32 sstatus;
244
245@@ -5065,7 +5103,7 @@ bool ata_link_online(struct ata_link *li
246 }
247
248 /**
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
252 *
253 * Test whether @link is offline. Note that this function
254@@ -5078,7 +5116,7 @@ bool ata_link_online(struct ata_link *li
255 * RETURNS:
256 * True if the port offline status is available and offline.
257 */
258-bool ata_link_offline(struct ata_link *link)
259+bool ata_phys_link_offline(struct ata_link *link)
260 {
261 u32 sstatus;
262
263@@ -5088,6 +5126,58 @@ bool ata_link_offline(struct ata_link *l
264 return false;
265 }
266
267+/**
268+ * ata_link_online - test whether the given link is online
269+ * @link: ATA link to test
270+ *
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
275+ * online.
276+ *
277+ * LOCKING:
278+ * None.
279+ *
280+ * RETURNS:
281+ * True if the port online status is available and online.
282+ */
283+bool ata_link_online(struct ata_link *link)
284+{
285+ struct ata_link *slave = link->ap->slave_link;
286+
287+ WARN_ON(link == slave); /* shouldn't be called on slave link */
288+
289+ return ata_phys_link_online(link) ||
290+ (slave && ata_phys_link_online(slave));
291+}
292+
293+/**
294+ * ata_link_offline - test whether the given link is offline
295+ * @link: ATA link to test
296+ *
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
301+ * offline.
302+ *
303+ * LOCKING:
304+ * None.
305+ *
306+ * RETURNS:
307+ * True if the port offline status is available and offline.
308+ */
309+bool ata_link_offline(struct ata_link *link)
310+{
311+ struct ata_link *slave = link->ap->slave_link;
312+
313+ WARN_ON(link == slave); /* shouldn't be called on slave link */
314+
315+ return ata_phys_link_offline(link) &&
316+ (!slave || ata_phys_link_offline(slave));
317+}
318+
319 #ifdef CONFIG_PM
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)
323 */
324 void ata_dev_init(struct ata_device *dev)
325 {
326- struct ata_link *link = dev->link;
327+ struct ata_link *link = ata_dev_phys_link(dev);
328 struct ata_port *ap = link->ap;
329 unsigned long flags;
330
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;
334 link->sata_spd = 0;
335
336@@ -5396,6 +5486,7 @@ static void ata_host_release(struct devi
337 scsi_host_put(ap->scsi_host);
338
339 kfree(ap->pmp_link);
340+ kfree(ap->slave_link);
341 kfree(ap);
342 host->ports[i] = NULL;
343 }
344@@ -5516,6 +5607,68 @@ struct ata_host *ata_host_alloc_pinfo(st
345 return host;
346 }
347
348+/**
349+ * ata_slave_link_init - initialize slave link
350+ * @ap: port to initialize slave link for
351+ *
352+ * Create and initialize slave link for @ap. This enables slave
353+ * link handling on the port.
354+ *
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
360+ * and slave.
361+ *
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).
370+ *
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.
380+ *
381+ * prereset(M) -> prereset(S) -> hardreset(M) -> hardreset(S) ->
382+ * softreset(M) -> postreset(M) -> postreset(S)
383+ *
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).
387+ *
388+ * LOCKING:
389+ * Should be called before host is registered.
390+ *
391+ * RETURNS:
392+ * 0 on success, -errno on failure.
393+ */
394+int ata_slave_link_init(struct ata_port *ap)
395+{
396+ struct ata_link *link;
397+
398+ WARN_ON(ap->slave_link);
399+ WARN_ON(ap->flags & ATA_FLAG_PMP);
400+
401+ link = kzalloc(sizeof(*link), GFP_KERNEL);
402+ if (!link)
403+ return -ENOMEM;
404+
405+ ata_link_init(ap, link, 1);
406+ ap->slave_link = link;
407+ return 0;
408+}
409+
410 static void ata_host_stop(struct device *gendev, void *res)
411 {
412 struct ata_host *host = dev_get_drvdata(gendev);
413@@ -5742,6 +5895,8 @@ int ata_host_register(struct ata_host *h
414
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);
419
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)
435 {
436- struct ata_link *link = dev->link;
437+ struct ata_link *link = ata_dev_phys_link(dev);
438 int xfer_ok = 0;
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);
444
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)
448 continue;
449
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);
454
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.
458+ */
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;
462+
463+ ata_eh_link_autopsy(ap->slave_link);
464+
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);
470+ }
471+
472 /* Autopsy of fanout ports can affect host link autopsy.
473 * Perform host link autopsy last.
474 */
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);
478
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))
484 continue;
485@@ -2065,7 +2084,7 @@ static void ata_eh_link_report(struct at
486 char cdb_buf[70] = "";
487
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)
491 continue;
492
493 if (qc->dma_dir != DMA_NONE) {
494@@ -2157,12 +2176,14 @@ void ata_eh_report(struct ata_port *ap)
495 }
496
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)
501 {
502 struct ata_device *dev;
503
504- ata_link_for_each_dev(dev, link)
505- classes[dev->devno] = ATA_DEV_UNKNOWN;
506+ if (clear_classes)
507+ ata_link_for_each_dev(dev, link)
508+ classes[dev->devno] = ATA_DEV_UNKNOWN;
509
510 return reset(link, classes, deadline);
511 }
512@@ -2184,17 +2205,20 @@ int ata_eh_reset(struct ata_link *link,
513 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
514 {
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;
527 unsigned long flags;
528 u32 sstatus;
529- int nr_known, rc;
530+ int nr_unknown, rc;
531
532 /*
533 * Prepare to reset
534@@ -2253,8 +2277,30 @@ int ata_eh_reset(struct ata_link *link,
535 }
536
537 if (prereset) {
538- rc = prereset(link,
539- ata_deadline(jiffies, ATA_EH_PRERESET_TIMEOUT));
540+ unsigned long deadline = ata_deadline(jiffies,
541+ ATA_EH_PRERESET_TIMEOUT);
542+
543+ if (slave) {
544+ sehc->i.action &= ~ATA_EH_RESET;
545+ sehc->i.action |= ehc->i.action;
546+ }
547+
548+ rc = prereset(link, deadline);
549+
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.
553+ */
554+ if (slave && (rc == 0 || rc == -ENOENT)) {
555+ int tmp;
556+
557+ tmp = prereset(slave, deadline);
558+ if (tmp != -ENOENT)
559+ rc = tmp;
560+
561+ ehc->i.action |= sehc->i.action;
562+ }
563+
564 if (rc) {
565 if (rc == -ENOENT) {
566 ata_link_printk(link, KERN_DEBUG,
567@@ -2306,25 +2352,51 @@ int ata_eh_reset(struct ata_link *link,
568 else
569 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
570
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;
576 goto fail;
577+ }
578+
579+ /* hardreset slave link if existent */
580+ if (slave && reset == hardreset) {
581+ int tmp;
582+
583+ if (verbose)
584+ ata_link_printk(slave, KERN_INFO,
585+ "hard resetting link\n");
586+
587+ ata_eh_about_to_do(slave, NULL, ATA_EH_RESET);
588+ tmp = ata_do_reset(slave, reset, classes, deadline,
589+ false);
590+ switch (tmp) {
591+ case -EAGAIN:
592+ rc = -EAGAIN;
593+ case 0:
594+ break;
595+ default:
596+ failed_link = slave;
597+ rc = tmp;
598+ goto fail;
599+ }
600+ }
601
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 */
606 reset = softreset;
607
608 if (!reset) {
609 ata_link_printk(link, KERN_ERR,
610 "follow-up softreset required "
611 "but no softreset avaliable\n");
612+ failed_link = link;
613 rc = -EINVAL;
614 goto fail;
615 }
616
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);
620 }
621 } else {
622 if (verbose)
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;
626
627- if (ata_link_offline(link))
628+ if (ata_phys_link_offline(ata_dev_phys_link(dev)))
629 continue;
630
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;
638
639 /* thaw the port */
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.
644 */
645- if (postreset)
646+ if (postreset) {
647 postreset(link, classes);
648+ if (slave)
649+ postreset(slave, classes);
650+ }
651
652 /* clear cached SError */
653 spin_lock_irqsave(link->ap->lock, flags);
654 link->eh_info.serror = 0;
655+ if (slave)
656+ slave->eh_info.serror = 0;
657 spin_unlock_irqrestore(link->ap->lock, flags);
658
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.
663 */
664- nr_known = 0;
665+ nr_unknown = 0;
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;
671- else
672- nr_known++;
673+ if (ata_phys_link_online(ata_dev_phys_link(dev)))
674+ nr_unknown++;
675+ }
676 }
677
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;
684 rc = -EAGAIN;
685 goto fail;
686 }
687@@ -2408,6 +2489,8 @@ int ata_eh_reset(struct ata_link *link,
688
689 /* reset successful, schedule revalidation */
690 ata_eh_done(link, NULL, ATA_EH_RESET);
691+ if (slave)
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;
695
696@@ -2415,6 +2498,8 @@ int ata_eh_reset(struct ata_link *link,
697 out:
698 /* clear hotplug flag */
699 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
700+ if (slave)
701+ sehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
702
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;
708
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));
713
714@@ -2443,8 +2528,13 @@ int ata_eh_reset(struct ata_link *link,
715 delta = schedule_timeout_uninterruptible(delta);
716 }
717
718- if (rc == -EPIPE || try == max_tries - 1)
719+ if (try == max_tries - 1) {
720 sata_down_spd_limit(link);
721+ if (slave)
722+ sata_down_spd_limit(slave);
723+ } else if (rc == -EPIPE)
724+ sata_down_spd_limit(failed_link);
725+
726 if (hardreset)
727 reset = hardreset;
728 goto retry;
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);
732
733- if (ata_link_offline(link)) {
734+ if (ata_phys_link_offline(ata_dev_phys_link(dev))) {
735 rc = -EIO;
736 goto err;
737 }
738@@ -2701,7 +2791,7 @@ static int ata_eh_handle_dev_fail(struct
739 /* This is the last chance, better to slow
740 * down than lose it.
741 */
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);
746 }
747@@ -2712,7 +2802,7 @@ static int ata_eh_handle_dev_fail(struct
748 ata_dev_disable(dev);
749
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);
754
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 */
780
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() */
784
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
796
797 static inline int ata_is_host_link(const struct ata_link *link)
798 {
799- return link == &link->ap->link;
800+ return link == &link->ap->link || link == link->ap->slave_link;
801 }
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)
806
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); \
812 else \