Skip to content

Commit b52df41

Browse files
djbwJames Bottomley
authored andcommitted
[SCSI] libsas: use libata-eh-reset for sata rediscovery fis transmit failures
Since sata devices can take several seconds to recover the link on reset the 0.5 seconds that libsas currently waits may not be enough. Instead if we are rediscovering a phy that was previously attached to a sata device let libata handle any resets to encourage the device to transmit the initial fis. Once sas_ata_hard_reset() and lldds learn how to honor 'deadline' libsas should stop encountering phys in an intermediate state, until then this will loop until the fis is transmitted or ->attached_sas_addr gets cleared, but in the more likely initial discovery case we keep existing behavior. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
1 parent 3a2cdf3 commit b52df41

3 files changed

Lines changed: 63 additions & 6 deletions

File tree

‎drivers/scsi/libsas/sas_ata.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,22 @@ int sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
679679

680680
return rtn;
681681
}
682+
683+
void sas_ata_schedule_reset(struct domain_device *dev)
684+
{
685+
struct ata_eh_info *ehi;
686+
struct ata_port *ap;
687+
unsigned long flags;
688+
689+
if (!dev_is_sata(dev))
690+
return;
691+
692+
ap = dev->sata_dev.ap;
693+
ehi = &ap->link.eh_info;
694+
695+
spin_lock_irqsave(ap->lock, flags);
696+
ehi->err_mask |= AC_ERR_TIMEOUT;
697+
ehi->action |= ATA_EH_RESET;
698+
ata_port_schedule_eh(ap);
699+
spin_unlock_irqrestore(ap->lock, flags);
700+
}

‎drivers/scsi/libsas/sas_expander.c‎

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "sas_internal.h"
3030

31+
#include <scsi/sas_ata.h>
3132
#include <scsi/scsi_transport.h>
3233
#include <scsi/scsi_transport_sas.h>
3334
#include "../scsi_sas_internal.h"
@@ -226,12 +227,35 @@ static void sas_set_ex_phy(struct domain_device *dev, int phy_id,
226227
return;
227228
}
228229

230+
/* check if we have an existing attached ata device on this expander phy */
231+
static struct domain_device *sas_ex_to_ata(struct domain_device *ex_dev, int phy_id)
232+
{
233+
struct ex_phy *ex_phy = &ex_dev->ex_dev.ex_phy[phy_id];
234+
struct domain_device *dev;
235+
struct sas_rphy *rphy;
236+
237+
if (!ex_phy->port)
238+
return NULL;
239+
240+
rphy = ex_phy->port->rphy;
241+
if (!rphy)
242+
return NULL;
243+
244+
dev = sas_find_dev_by_rphy(rphy);
245+
246+
if (dev && dev_is_sata(dev))
247+
return dev;
248+
249+
return NULL;
250+
}
251+
229252
#define DISCOVER_REQ_SIZE 16
230253
#define DISCOVER_RESP_SIZE 56
231254

232255
static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req,
233256
u8 *disc_resp, int single)
234257
{
258+
struct domain_device *ata_dev = sas_ex_to_ata(dev, single);
235259
int i, res;
236260

237261
disc_req[9] = single;
@@ -242,20 +266,30 @@ static int sas_ex_phy_discover_helper(struct domain_device *dev, u8 *disc_req,
242266
disc_resp, DISCOVER_RESP_SIZE);
243267
if (res)
244268
return res;
245-
/* This is detecting a failure to transmit initial
246-
* dev to host FIS as described in section G.5 of
247-
* sas-2 r 04b */
248269
dr = &((struct smp_resp *)disc_resp)->disc;
249270
if (memcmp(dev->sas_addr, dr->attached_sas_addr,
250271
SAS_ADDR_SIZE) == 0) {
251272
sas_printk("Found loopback topology, just ignore it!\n");
252273
return 0;
253274
}
275+
276+
/* This is detecting a failure to transmit initial
277+
* dev to host FIS as described in section J.5 of
278+
* sas-2 r16
279+
*/
254280
if (!(dr->attached_dev_type == 0 &&
255281
dr->attached_sata_dev))
256282
break;
257-
/* In order to generate the dev to host FIS, we
258-
* send a link reset to the expander port */
283+
284+
/* In order to generate the dev to host FIS, we send a
285+
* link reset to the expander port. If a device was
286+
* previously detected on this port we ask libata to
287+
* manage the reset and link recovery.
288+
*/
289+
if (ata_dev) {
290+
sas_ata_schedule_reset(ata_dev);
291+
break;
292+
}
259293
sas_smp_phy_control(dev, single, PHY_FUNC_LINK_RESET, NULL);
260294
/* Wait for the reset to trigger the negotiation */
261295
msleep(500);

‎include/scsi/sas_ata.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void sas_ata_strategy_handler(struct Scsi_Host *shost);
4444
int sas_ata_eh(struct Scsi_Host *shost, struct list_head *work_q,
4545
struct list_head *done_q);
4646
void sas_probe_sata(struct work_struct *work);
47-
47+
void sas_ata_schedule_reset(struct domain_device *dev);
4848
#else
4949

5050

@@ -75,6 +75,10 @@ static inline void sas_probe_sata(struct work_struct *work)
7575
{
7676
}
7777

78+
static inline void sas_ata_schedule_reset(struct domain_device *dev)
79+
{
80+
}
81+
7882
#endif
7983

8084
#endif /* _SAS_ATA_H_ */

0 commit comments

Comments
 (0)