Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  libata-eh.c - libata error handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright 2006 Tejun Heo <htejun@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  libata documentation is available via 'make {ps|pdf}docs',
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  as Documentation/driver-api/libata.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  Hardware documentation available from http://www.t13.org/ and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *  http://www.sata-io.org/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <scsi/scsi_eh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <scsi/scsi_dbg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include "../scsi/scsi_transport_api.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <trace/events/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include "libata.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	/* speed down verdicts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	ATA_EH_SPDN_NCQ_OFF		= (1 << 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 	ATA_EH_SPDN_SPEED_DOWN		= (1 << 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	ATA_EH_SPDN_FALLBACK_TO_PIO	= (1 << 2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 	ATA_EH_SPDN_KEEP_ERRORS		= (1 << 3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	/* error flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	ATA_EFLAG_IS_IO			= (1 << 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	ATA_EFLAG_DUBIOUS_XFER		= (1 << 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	ATA_EFLAG_OLD_ER                = (1 << 31),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	/* error categories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	ATA_ECAT_NONE			= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	ATA_ECAT_ATA_BUS		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	ATA_ECAT_TOUT_HSM		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	ATA_ECAT_UNK_DEV		= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	ATA_ECAT_DUBIOUS_NONE		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	ATA_ECAT_DUBIOUS_ATA_BUS	= 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	ATA_ECAT_DUBIOUS_TOUT_HSM	= 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	ATA_ECAT_DUBIOUS_UNK_DEV	= 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	ATA_ECAT_NR			= 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	ATA_EH_CMD_DFL_TIMEOUT		=  5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	/* always put at least this amount of time between resets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	ATA_EH_RESET_COOL_DOWN		=  5000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	/* Waiting in ->prereset can never be reliable.  It's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	 * sometimes nice to wait there but it can't be depended upon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	 * otherwise, we wouldn't be resetting.  Just give it enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	 * time for most drives to spin up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	ATA_EH_PRERESET_TIMEOUT		= 10000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	ATA_EH_FASTDRAIN_INTERVAL	=  3000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 	ATA_EH_UA_TRIES			= 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	/* probe speed down parameters, see ata_eh_schedule_probe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	ATA_EH_PROBE_TRIAL_INTERVAL	= 60000,	/* 1 min */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 	ATA_EH_PROBE_TRIALS		= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /* The following table determines how we sequence resets.  Each entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * represents timeout for that try.  The first try can be soft or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * hardreset.  All others are hardreset if available.  In most cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * the first reset w/ 10sec timeout should succeed.  Following entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * are mostly for error handling, hotplug and those outlier devices that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  * take an exceptionally long time to recover from reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) static const unsigned long ata_eh_reset_timeouts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	10000,	/* most drives spin up by 10sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	10000,	/* > 99% working drives spin up before 20sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	35000,	/* give > 30 secs of idleness for outlier devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	 5000,	/* and sweet one last chance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	ULONG_MAX, /* > 1 min has elapsed, give up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static const unsigned long ata_eh_identify_timeouts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	 5000,	/* covers > 99% of successes and not too boring on failures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	10000,  /* combined time till here is enough even for media access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	30000,	/* for true idiots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static const unsigned long ata_eh_revalidate_timeouts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	15000,	/* Some drives are slow to read log pages when waking-up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	15000,  /* combined time till here is enough even for media access */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static const unsigned long ata_eh_flush_timeouts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	15000,	/* be generous with flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	15000,  /* ditto */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	30000,	/* and even more generous */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static const unsigned long ata_eh_other_timeouts[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	 5000,	/* same rationale as identify timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	10000,	/* ditto */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	/* but no merciful 30sec for other commands, it just isn't worth it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) struct ata_eh_cmd_timeout_ent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	const u8		*commands;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	const unsigned long	*timeouts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) /* The following table determines timeouts to use for EH internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122)  * commands.  Each table entry is a command class and matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * commands the entry applies to and the timeout table to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * On the retry after a command timed out, the next timeout value from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  * the table is used.  If the table doesn't contain further entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  * the last value is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  * ehc->cmd_timeout_idx keeps track of which timeout to use per
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  * command class, so if SET_FEATURES times out on the first try, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  * next try will use the second timeout value only for that class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #define CMDS(cmds...)	(const u8 []){ cmds, 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static const struct ata_eh_cmd_timeout_ent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) ata_eh_cmd_timeout_table[ATA_EH_CMD_TIMEOUT_TABLE_SIZE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	{ .commands = CMDS(ATA_CMD_ID_ATA, ATA_CMD_ID_ATAPI),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	  .timeouts = ata_eh_identify_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	{ .commands = CMDS(ATA_CMD_READ_LOG_EXT, ATA_CMD_READ_LOG_DMA_EXT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	  .timeouts = ata_eh_revalidate_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	{ .commands = CMDS(ATA_CMD_READ_NATIVE_MAX, ATA_CMD_READ_NATIVE_MAX_EXT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	  .timeouts = ata_eh_other_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	{ .commands = CMDS(ATA_CMD_SET_MAX, ATA_CMD_SET_MAX_EXT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	  .timeouts = ata_eh_other_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	{ .commands = CMDS(ATA_CMD_SET_FEATURES),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	  .timeouts = ata_eh_other_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	{ .commands = CMDS(ATA_CMD_INIT_DEV_PARAMS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	  .timeouts = ata_eh_other_timeouts, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	{ .commands = CMDS(ATA_CMD_FLUSH, ATA_CMD_FLUSH_EXT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	  .timeouts = ata_eh_flush_timeouts },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) #undef CMDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static void __ata_port_freeze(struct ata_port *ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static void ata_eh_handle_port_suspend(struct ata_port *ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) static void ata_eh_handle_port_resume(struct ata_port *ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #else /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) static void ata_eh_handle_port_suspend(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) static void ata_eh_handle_port_resume(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) static __printf(2, 0) void __ata_ehi_pushv_desc(struct ata_eh_info *ehi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 				 const char *fmt, va_list args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 				     ATA_EH_DESC_LEN - ehi->desc_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 				     fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  *	__ata_ehi_push_desc - push error description without adding separator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175)  *	@ehi: target EHI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)  *	@fmt: printf format string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)  *	Format string according to @fmt and append it to @ehi->desc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	__ata_ehi_pushv_desc(ehi, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  *	ata_ehi_push_desc - push error description with separator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  *	@ehi: target EHI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  *	@fmt: printf format string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  *	Format string according to @fmt and append it to @ehi->desc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  *	If @ehi->desc is not empty, ", " is added in-between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	if (ehi->desc_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		__ata_ehi_push_desc(ehi, ", ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	__ata_ehi_pushv_desc(ehi, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  *	ata_ehi_clear_desc - clean error description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  *	@ehi: target EHI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  *	Clear @ehi->desc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) void ata_ehi_clear_desc(struct ata_eh_info *ehi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	ehi->desc[0] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	ehi->desc_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  *	ata_port_desc - append port description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)  *	@ap: target ATA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236)  *	@fmt: printf format string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)  *	Format string according to @fmt and append it to port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  *	description.  If port description is not empty, " " is added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  *	in-between.  This function is to be used while initializing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)  *	ata_host.  The description is printed on host registration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) void ata_port_desc(struct ata_port *ap, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	WARN_ON(!(ap->pflags & ATA_PFLAG_INITIALIZING));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	if (ap->link.eh_info.desc_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		__ata_ehi_push_desc(&ap->link.eh_info, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	__ata_ehi_pushv_desc(&ap->link.eh_info, fmt, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) EXPORT_SYMBOL_GPL(ata_port_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) #ifdef CONFIG_PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)  *	ata_port_pbar_desc - append PCI BAR description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)  *	@ap: target ATA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)  *	@bar: target PCI BAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)  *	@offset: offset into PCI BAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)  *	@name: name of the area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)  *	If @offset is negative, this function formats a string which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)  *	contains the name, address, size and type of the BAR and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)  *	appends it to the port description.  If @offset is zero or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)  *	positive, only name and offsetted address is appended.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	char *type = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	unsigned long long start, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		type = "m";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	else if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		type = "i";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	start = (unsigned long long)pci_resource_start(pdev, bar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	len = (unsigned long long)pci_resource_len(pdev, bar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	if (offset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 		ata_port_desc(ap, "%s %s%llu@0x%llx", name, type, len, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		ata_port_desc(ap, "%s 0x%llx", name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 				start + (unsigned long long)offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) #endif /* CONFIG_PCI */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) static int ata_lookup_timeout_table(u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	for (i = 0; i < ATA_EH_CMD_TIMEOUT_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		const u8 *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		for (cur = ata_eh_cmd_timeout_table[i].commands; *cur; cur++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			if (*cur == cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 				return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  *	ata_internal_cmd_timeout - determine timeout for an internal command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)  *	@dev: target device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)  *	@cmd: internal command to be issued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321)  *	Determine timeout for internal command @cmd for @dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327)  *	Determined timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	int ent = ata_lookup_timeout_table(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	if (ent < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		return ATA_EH_CMD_DFL_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	idx = ehc->cmd_timeout_idx[dev->devno][ent];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	return ata_eh_cmd_timeout_table[ent].timeouts[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  *	ata_internal_cmd_timed_out - notification for internal command timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)  *	@dev: target device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)  *	@cmd: internal command which timed out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  *	Notify EH that internal command @cmd for @dev timed out.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  *	function should be called only for commands whose timeouts are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  *	determined using ata_internal_cmd_timeout().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	int ent = ata_lookup_timeout_table(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	if (ent < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	idx = ehc->cmd_timeout_idx[dev->devno][ent];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	if (ata_eh_cmd_timeout_table[ent].timeouts[idx + 1] != ULONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		ehc->cmd_timeout_idx[dev->devno][ent]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) static void ata_ering_record(struct ata_ering *ering, unsigned int eflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			     unsigned int err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	struct ata_ering_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	WARN_ON(!err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	ering->cursor++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	ering->cursor %= ATA_ERING_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	ent = &ering->ring[ering->cursor];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	ent->eflags = eflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	ent->err_mask = err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	ent->timestamp = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	struct ata_ering_entry *ent = &ering->ring[ering->cursor];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (ent->err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		return ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) int ata_ering_map(struct ata_ering *ering,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		  int (*map_fn)(struct ata_ering_entry *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		  void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	int idx, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct ata_ering_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	idx = ering->cursor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		ent = &ering->ring[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		if (!ent->err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		rc = map_fn(ent, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		idx = (idx - 1 + ATA_ERING_SIZE) % ATA_ERING_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	} while (idx != ering->cursor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) static int ata_ering_clear_cb(struct ata_ering_entry *ent, void *void_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	ent->eflags |= ATA_EFLAG_OLD_ER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) static void ata_ering_clear(struct ata_ering *ering)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	ata_ering_map(ering, ata_ering_clear_cb, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) static unsigned int ata_eh_dev_action(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	return ehc->i.action | ehc->i.dev_action[dev->devno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 				struct ata_eh_info *ehi, unsigned int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	struct ata_device *tdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		ehi->action &= ~action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		ata_for_each_dev(tdev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 			ehi->dev_action[tdev->devno] &= ~action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		/* doesn't make sense for port-wide EH actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		WARN_ON(!(action & ATA_EH_PERDEV_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		/* break ehi->action into ehi->dev_action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		if (ehi->action & action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			ata_for_each_dev(tdev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 				ehi->dev_action[tdev->devno] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 					ehi->action & action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			ehi->action &= ~action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		/* turn off the specified per-dev action */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		ehi->dev_action[dev->devno] &= ~action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459)  *	ata_eh_acquire - acquire EH ownership
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460)  *	@ap: ATA port to acquire EH ownership for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)  *	Acquire EH ownership for @ap.  This is the basic exclusion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463)  *	mechanism for ports sharing a host.  Only one port hanging off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  *	the same host can claim the ownership of EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) void ata_eh_acquire(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	mutex_lock(&ap->host->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	WARN_ON_ONCE(ap->host->eh_owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	ap->host->eh_owner = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  *	ata_eh_release - release EH ownership
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  *	@ap: ATA port to release EH ownership for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  *	Release EH ownership for @ap if the caller.  The caller must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  *	have acquired EH ownership using ata_eh_acquire() previously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) void ata_eh_release(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	WARN_ON_ONCE(ap->host->eh_owner != current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	ap->host->eh_owner = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	mutex_unlock(&ap->host->eh_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) static void ata_eh_unload(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	/* Restore SControl IPM and SPD for the next driver and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	 * disable attached devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	ata_for_each_link(link, ap, PMP_FIRST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	/* freeze and set UNLOADED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	ata_port_freeze(ap);			/* won't be thawed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	ap->pflags &= ~ATA_PFLAG_EH_PENDING;	/* clear pending from freeze */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	ap->pflags |= ATA_PFLAG_UNLOADED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  *	ata_scsi_error - SCSI layer error handler callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  *	@host: SCSI host on which error occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522)  *	Handles SCSI-layer-thrown error events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525)  *	Inherited from SCSI layer (none, can sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  *	Zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) void ata_scsi_error(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	struct ata_port *ap = ata_shost_to_port(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	LIST_HEAD(eh_work_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	spin_lock_irqsave(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	list_splice_init(&host->eh_cmd_q, &eh_work_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	spin_unlock_irqrestore(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	ata_scsi_cmd_error_handler(host, ap, &eh_work_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	/* If we timed raced normal completion and there is nothing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	   recover nr_timedout == 0 why exactly are we doing error recovery ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	ata_scsi_port_error_handler(host, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	/* finish or retry handled scmd's and clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	WARN_ON(!list_empty(&eh_work_q));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	DPRINTK("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555)  * ata_scsi_cmd_error_handler - error callback for a list of commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556)  * @host:	scsi host containing the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)  * @ap:		ATA port within the host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  * @eh_work_q:	list of commands to process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * process the given list of commands and return those finished to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * ap->eh_done_q.  This function is the first part of the libata error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * handler which processes a given list of failed commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 				struct list_head *eh_work_q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	/* make sure sff pio task is not running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	ata_sff_flush_pio_task(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	/* synchronize with host lock and sort out timeouts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	/* For new EH, all qcs are finished in one of three ways -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	 * normal completion, error completion, and SCSI timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	 * Both completions can race against SCSI timeout.  When normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	 * completion wins, the qc never reaches EH.  When error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	 * completion wins, the qc has ATA_QCFLAG_FAILED set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	 * When SCSI timeout wins, things are a bit more complex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	 * Normal or error completion can occur after the timeout but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	 * before this point.  In such cases, both types of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	 * completions are honored.  A scmd is determined to have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	 * timed out iff its associated qc is active and not failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (ap->ops->error_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		struct scsi_cmnd *scmd, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		int nr_timedout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		/* This must occur under the ap->lock as we don't want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		   a polled recovery to race the real interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		   The lost_interrupt handler checks for any completed but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 		   non-notified command and completes much like an IRQ handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 		   We then fall into the error recovery code which will treat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		   this as if normal completion won the race */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		if (ap->ops->lost_interrupt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 			ap->ops->lost_interrupt(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		list_for_each_entry_safe(scmd, tmp, eh_work_q, eh_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			ata_qc_for_each_raw(ap, qc, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 				if (qc->flags & ATA_QCFLAG_ACTIVE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 				    qc->scsicmd == scmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			if (i < ATA_MAX_QUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 				/* the scmd has an associated qc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 				if (!(qc->flags & ATA_QCFLAG_FAILED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 					/* which hasn't failed yet, timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 					qc->err_mask |= AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 					qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 					nr_timedout++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 				/* Normal completion occurred after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 				 * SCSI timeout but before this point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 				 * Successfully complete it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 				scmd->retries = scmd->allowed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 				scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		/* If we have timed out qcs.  They belong to EH from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		 * this point but the state of the controller is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		 * unknown.  Freeze the port to make sure the IRQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		 * handler doesn't diddle with those qcs.  This must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		 * be done atomically w.r.t. setting QCFLAG_FAILED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		if (nr_timedout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 			__ata_port_freeze(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		/* initialize eh_tries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		ap->eh_tries = ATA_EH_MAX_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) EXPORT_SYMBOL(ata_scsi_cmd_error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)  * ata_scsi_port_error_handler - recover the port after the commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)  * @host:	SCSI host containing the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652)  * @ap:		the ATA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)  * Handle the recovery of the port @ap after all the commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655)  * have been recovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	/* invoke error handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (ap->ops->error_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		/* acquire EH ownership */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		ata_eh_acquire(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667)  repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		/* kill fast drain timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		del_timer_sync(&ap->fastdrain_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		/* process port resume request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		ata_eh_handle_port_resume(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		/* fetch & clear EH info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		ata_for_each_link(link, ap, HOST_FIRST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 			struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 			memset(&link->eh_context, 0, sizeof(link->eh_context));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			link->eh_context.i = link->eh_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			memset(&link->eh_info, 0, sizeof(link->eh_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				int devno = dev->devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				ehc->saved_xfer_mode[devno] = dev->xfer_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 				if (ata_ncq_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 					ehc->saved_ncq_enabled |= 1 << devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		ap->pflags |= ATA_PFLAG_EH_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		ap->pflags &= ~ATA_PFLAG_EH_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		ap->excl_link = NULL;	/* don't maintain exclusion over EH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		/* invoke EH, skip if unloading or suspended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			ap->ops->error_handler(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			/* if unloading, commence suicide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 			if ((ap->pflags & ATA_PFLAG_UNLOADING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 			    !(ap->pflags & ATA_PFLAG_UNLOADED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 				ata_eh_unload(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			ata_eh_finish(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		/* process port suspend request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		ata_eh_handle_port_suspend(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		/* Exception might have happened after ->error_handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		 * recovered the port but before this point.  Repeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		 * EH in such case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		if (ap->pflags & ATA_PFLAG_EH_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			if (--ap->eh_tries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 				spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 				goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			ata_port_err(ap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 				     "EH pending after %d tries, giving up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 				     ATA_EH_MAX_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			ap->pflags &= ~ATA_PFLAG_EH_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		/* this run is complete, make sure EH info is clear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		ata_for_each_link(link, ap, HOST_FIRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			memset(&link->eh_info, 0, sizeof(link->eh_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		/* end eh (clear host_eh_scheduled) while holding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		 * ap->lock such that if exception occurs after this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		 * point but before EH completion, SCSI midlayer will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		 * re-initiate EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		ap->ops->end_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		ata_eh_release(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 		WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 		ap->ops->eng_timeout(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	scsi_eh_flush_done_q(&ap->eh_done_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	/* clean up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	if (ap->pflags & ATA_PFLAG_LOADING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		ap->pflags &= ~ATA_PFLAG_LOADING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	else if ((ap->pflags & ATA_PFLAG_SCSI_HOTPLUG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 		!(ap->flags & ATA_FLAG_SAS_HOST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		schedule_delayed_work(&ap->hotplug_task, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	if (ap->pflags & ATA_PFLAG_RECOVERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		ata_port_info(ap, "EH complete\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	ap->pflags &= ~(ATA_PFLAG_SCSI_HOTPLUG | ATA_PFLAG_RECOVERED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	/* tell wait_eh that we're done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	ap->pflags &= ~ATA_PFLAG_EH_IN_PROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	wake_up_all(&ap->eh_wait_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) EXPORT_SYMBOL_GPL(ata_scsi_port_error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)  *	ata_port_wait_eh - Wait for the currently pending EH to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)  *	@ap: Port to wait EH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)  *	Wait until the currently pending EH is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) void ata_port_wait_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)  retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	while (ap->pflags & (ATA_PFLAG_EH_PENDING | ATA_PFLAG_EH_IN_PROGRESS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		prepare_to_wait(&ap->eh_wait_q, &wait, TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	finish_wait(&ap->eh_wait_q, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	/* make sure SCSI EH is complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	if (scsi_host_in_recovery(ap->scsi_host)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		ata_msleep(ap, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) EXPORT_SYMBOL_GPL(ata_port_wait_eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) static int ata_eh_nr_in_flight(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	unsigned int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	int nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	/* count only non-internal commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	ata_qc_for_each(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		if (qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	return nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) void ata_eh_fastdrain_timerfn(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	struct ata_port *ap = from_timer(ap, t, fastdrain_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	cnt = ata_eh_nr_in_flight(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	/* are we done? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	if (cnt == ap->fastdrain_cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		unsigned int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		/* No progress during the last interval, tag all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		 * in-flight qcs as timed out and freeze the port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		ata_qc_for_each(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			if (qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 				qc->err_mask |= AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		ata_port_freeze(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 		/* some qcs have finished, give it another chance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		ap->fastdrain_cnt = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		ap->fastdrain_timer.expires =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			ata_deadline(jiffies, ATA_EH_FASTDRAIN_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		add_timer(&ap->fastdrain_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)  out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  *	ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  *	@ap: target ATA port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)  *	@fastdrain: activate fast drain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  *	Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  *	is non-zero and EH wasn't pending before.  Fast drain ensures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)  *	that EH kicks in in timely manner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) static void ata_eh_set_pending(struct ata_port *ap, int fastdrain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	/* already scheduled? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	if (ap->pflags & ATA_PFLAG_EH_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	ap->pflags |= ATA_PFLAG_EH_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	if (!fastdrain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	/* do we have in-flight qcs? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	cnt = ata_eh_nr_in_flight(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (!cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	/* activate fast drain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	ap->fastdrain_cnt = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	ap->fastdrain_timer.expires =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		ata_deadline(jiffies, ATA_EH_FASTDRAIN_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	add_timer(&ap->fastdrain_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  *	ata_qc_schedule_eh - schedule qc for error handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)  *	@qc: command to schedule error handling for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  *	Schedule error handling for @qc.  EH will kick in as soon as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)  *	other commands are drained.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	struct ata_port *ap = qc->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	WARN_ON(!ap->ops->error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	ata_eh_set_pending(ap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	/* The following will fail if timeout has already expired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	 * ata_scsi_error() takes care of such scmds on EH entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	 * Note that ATA_QCFLAG_FAILED is unconditionally set after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	 * this function completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	blk_abort_request(qc->scsicmd->request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927)  * ata_std_sched_eh - non-libsas ata_ports issue eh with this common routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928)  * @ap: ATA port to schedule EH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930)  *	LOCKING: inherited from ata_port_schedule_eh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) void ata_std_sched_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	WARN_ON(!ap->ops->error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (ap->pflags & ATA_PFLAG_INITIALIZING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	ata_eh_set_pending(ap, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	scsi_schedule_eh(ap->scsi_host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	DPRINTK("port EH scheduled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) EXPORT_SYMBOL_GPL(ata_std_sched_eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948)  * ata_std_end_eh - non-libsas ata_ports complete eh with this common routine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949)  * @ap: ATA port to end EH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)  * In the libata object model there is a 1:1 mapping of ata_port to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)  * shost, so host fields can be directly manipulated under ap->lock, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  * the libsas case we need to hold a lock at the ha->level to coordinate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)  * these events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) void ata_std_end_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	struct Scsi_Host *host = ap->scsi_host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	host->host_eh_scheduled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) EXPORT_SYMBOL(ata_std_end_eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969)  *	ata_port_schedule_eh - schedule error handling without a qc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)  *	@ap: ATA port to schedule EH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972)  *	Schedule error handling for @ap.  EH will kick in as soon as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)  *	all commands are drained.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) void ata_port_schedule_eh(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	/* see: ata_std_sched_eh, unless you know better */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	ap->ops->sched_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) static int ata_do_link_abort(struct ata_port *ap, struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	int tag, nr_aborted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	WARN_ON(!ap->ops->error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	/* we're gonna abort all commands, no need for fast drain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	ata_eh_set_pending(ap, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	/* include internal tag in iteration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	ata_qc_for_each_with_internal(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		if (qc && (!link || qc->dev->link == link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			qc->flags |= ATA_QCFLAG_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			ata_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			nr_aborted++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	if (!nr_aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		ata_port_schedule_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	return nr_aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  *	ata_link_abort - abort all qc's on the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  *	@link: ATA link to abort qc's for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  *	Abort all active qc's active on @link and schedule EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  *	Number of aborted qc's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) int ata_link_abort(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	return ata_do_link_abort(link->ap, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) EXPORT_SYMBOL_GPL(ata_link_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)  *	ata_port_abort - abort all qc's on the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)  *	@ap: ATA port to abort qc's for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)  *	Abort all active qc's of @ap and schedule EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  *	spin_lock_irqsave(host_set lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  *	Number of aborted qc's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) int ata_port_abort(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	return ata_do_link_abort(ap, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) EXPORT_SYMBOL_GPL(ata_port_abort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)  *	__ata_port_freeze - freeze port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)  *	@ap: ATA port to freeze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)  *	This function is called when HSM violation or some other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)  *	condition disrupts normal operation of the port.  Frozen port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)  *	is not allowed to perform any operation until the port is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)  *	thawed, which usually follows a successful reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)  *	ap->ops->freeze() callback can be used for freezing the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)  *	hardware-wise (e.g. mask interrupt and stop DMA engine).  If a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)  *	port cannot be frozen hardware-wise, the interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)  *	must ack and clear interrupts unconditionally while the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)  *	is frozen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) static void __ata_port_freeze(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	WARN_ON(!ap->ops->error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	if (ap->ops->freeze)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		ap->ops->freeze(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	ap->pflags |= ATA_PFLAG_FROZEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	DPRINTK("ata%u port frozen\n", ap->print_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  *	ata_port_freeze - abort & freeze port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)  *	@ap: ATA port to freeze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)  *	Abort and freeze @ap.  The freeze operation must be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)  *	first, because some hardware requires special operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)  *	before the taskfile registers are accessible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)  *	Number of aborted commands.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) int ata_port_freeze(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	int nr_aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	WARN_ON(!ap->ops->error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	__ata_port_freeze(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	nr_aborted = ata_port_abort(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	return nr_aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) EXPORT_SYMBOL_GPL(ata_port_freeze);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)  *	ata_eh_freeze_port - EH helper to freeze port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)  *	@ap: ATA port to freeze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)  *	Freeze @ap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) void ata_eh_freeze_port(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	if (!ap->ops->error_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	__ata_port_freeze(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) EXPORT_SYMBOL_GPL(ata_eh_freeze_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  *	ata_eh_thaw_port - EH helper to thaw port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)  *	@ap: ATA port to thaw
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)  *	Thaw frozen port @ap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) void ata_eh_thaw_port(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (!ap->ops->error_handler)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	ap->pflags &= ~ATA_PFLAG_FROZEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	if (ap->ops->thaw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		ap->ops->thaw(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	DPRINTK("ata%u port thawed\n", ap->print_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) static void ata_eh_scsidone(struct scsi_cmnd *scmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	/* nada */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static void __ata_eh_qc_complete(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	struct ata_port *ap = qc->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	struct scsi_cmnd *scmd = qc->scsicmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	qc->scsidone = ata_eh_scsidone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	__ata_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	WARN_ON(ata_tag_valid(qc->tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	scsi_eh_finish_cmd(scmd, &ap->eh_done_q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)  *	ata_eh_qc_complete - Complete an active ATA command from EH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)  *	@qc: Command to complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)  *	Indicate to the mid and upper layers that an ATA command has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)  *	completed.  To be used from EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) void ata_eh_qc_complete(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	struct scsi_cmnd *scmd = qc->scsicmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	scmd->retries = scmd->allowed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	__ata_eh_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)  *	ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)  *	@qc: Command to retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  *	Indicate to the mid and upper layers that an ATA command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  *	should be retried.  To be used from EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)  *	SCSI midlayer limits the number of retries to scmd->allowed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)  *	scmd->allowed is incremented for commands which get retried
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)  *	due to unrelated failures (qc->err_mask is zero).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) void ata_eh_qc_retry(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	struct scsi_cmnd *scmd = qc->scsicmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	if (!qc->err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 		scmd->allowed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	__ata_eh_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)  *	ata_dev_disable - disable ATA device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)  *	@dev: ATA device to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)  *	Disable @dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  *	Locking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) void ata_dev_disable(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	if (!ata_dev_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	if (ata_msg_drv(dev->link->ap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 		ata_dev_warn(dev, "disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	ata_acpi_on_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 | ATA_DNXFER_QUIET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	dev->class++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	/* From now till the next successful probe, ering is used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	 * track probe failures.  Clear accumulated device error info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	ata_ering_clear(&dev->ering);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) EXPORT_SYMBOL_GPL(ata_dev_disable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  *	ata_eh_detach_dev - detach ATA device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)  *	@dev: ATA device to detach
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)  *	Detach @dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) void ata_eh_detach_dev(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	struct ata_link *link = dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	dev->flags &= ~ATA_DFLAG_DETACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	if (ata_scsi_offline_dev(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		dev->flags |= ATA_DFLAG_DETACHED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	/* clear per-dev EH info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	ata_eh_clear_action(link, dev, &link->eh_info, ATA_EH_PERDEV_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	ata_eh_clear_action(link, dev, &link->eh_context.i, ATA_EH_PERDEV_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	ehc->saved_xfer_mode[dev->devno] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	ehc->saved_ncq_enabled &= ~(1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)  *	ata_eh_about_to_do - about to perform eh_action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)  *	@link: target ATA link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)  *	@dev: target ATA dev for per-dev action (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)  *	@action: action about to be performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)  *	Called just before performing EH actions to clear related bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)  *	in @link->eh_info such that eh actions are not unnecessarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)  *	repeated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 			unsigned int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	struct ata_eh_info *ehi = &link->eh_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	ata_eh_clear_action(link, dev, ehi, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	/* About to take EH action, set RECOVERED.  Ignore actions on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	 * slave links as master will do them again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	if (!(ehc->i.flags & ATA_EHI_QUIET) && link != ap->slave_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 		ap->pflags |= ATA_PFLAG_RECOVERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)  *	ata_eh_done - EH action complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)  *	@link: ATA link for which EH actions are complete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)  *	@dev: target ATA dev for per-dev action (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)  *	@action: action just completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)  *	Called right after performing EH actions to clear related bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)  *	in @link->eh_context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) void ata_eh_done(struct ata_link *link, struct ata_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		 unsigned int action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	ata_eh_clear_action(link, dev, &ehc->i, action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)  *	ata_err_string - convert err_mask to descriptive string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)  *	@err_mask: error mask to convert to string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)  *	Convert @err_mask to descriptive string.  Errors are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)  *	prioritized according to severity and only the most severe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)  *	error is reported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)  *	Descriptive string for @err_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) static const char *ata_err_string(unsigned int err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	if (err_mask & AC_ERR_HOST_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		return "host bus error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	if (err_mask & AC_ERR_ATA_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return "ATA bus error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	if (err_mask & AC_ERR_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		return "timeout";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	if (err_mask & AC_ERR_HSM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		return "HSM violation";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	if (err_mask & AC_ERR_SYSTEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		return "internal error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	if (err_mask & AC_ERR_MEDIA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		return "media error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	if (err_mask & AC_ERR_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		return "invalid argument";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	if (err_mask & AC_ERR_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		return "device error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	if (err_mask & AC_ERR_NCQ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 		return "NCQ error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	if (err_mask & AC_ERR_NODEV_HINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		return "Polling detection error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	return "unknown error";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)  *	atapi_eh_tur - perform ATAPI TEST_UNIT_READY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)  *	@dev: target ATAPI device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)  *	@r_sense_key: out parameter for sense_key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367)  *	Perform ATAPI TEST_UNIT_READY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)  *	EH context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)  *	0 on success, AC_ERR_* mask on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	u8 cdb[ATAPI_CDB_LEN] = { TEST_UNIT_READY, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	ata_tf_init(dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	tf.command = ATA_CMD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	tf.protocol = ATAPI_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	err_mask = ata_exec_internal(dev, &tf, cdb, DMA_NONE, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	if (err_mask == AC_ERR_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		*r_sense_key = tf.feature >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	return err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)  *	ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)  *	@qc: qc to perform REQUEST_SENSE_SENSE_DATA_EXT to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)  *	@cmd: scsi command for which the sense code should be set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)  *	Perform REQUEST_SENSE_DATA_EXT after the device reported CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)  *	SENSE.  This function is an EH helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) static void ata_eh_request_sense(struct ata_queued_cmd *qc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 				 struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	struct ata_device *dev = qc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	if (qc->ap->pflags & ATA_PFLAG_FROZEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		ata_dev_warn(dev, "sense data available but port frozen\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	if (!ata_id_sense_reporting_enabled(dev->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		ata_dev_warn(qc->dev, "sense data reporting disabled\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	DPRINTK("ATA request sense\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	ata_tf_init(dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	tf.flags |= ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	tf.command = ATA_CMD_REQ_SENSE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	tf.protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	/* Ignore err_mask; ATA_ERR might be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	if (tf.command & ATA_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		qc->flags |= ATA_QCFLAG_SENSE_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		ata_dev_warn(dev, "request sense failed stat %02x emask %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			     tf.command, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444)  *	atapi_eh_request_sense - perform ATAPI REQUEST_SENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)  *	@dev: device to perform REQUEST_SENSE to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)  *	@sense_buf: result sense data buffer (SCSI_SENSE_BUFFERSIZE bytes long)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)  *	@dfl_sense_key: default sense key to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)  *	Perform ATAPI REQUEST_SENSE after the device reported CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)  *	SENSE.  This function is EH helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456)  *	0 on success, AC_ERR_* mask on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) unsigned int atapi_eh_request_sense(struct ata_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 					   u8 *sense_buf, u8 dfl_sense_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	u8 cdb[ATAPI_CDB_LEN] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		{ REQUEST_SENSE, 0, 0, 0, SCSI_SENSE_BUFFERSIZE, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	struct ata_port *ap = dev->link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	DPRINTK("ATAPI request sense\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	/* initialize sense_buf with the error register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	 * for the case where they are -not- overwritten
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	sense_buf[0] = 0x70;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	sense_buf[2] = dfl_sense_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	/* some devices time out if garbage left in tf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	ata_tf_init(dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	tf.command = ATA_CMD_PACKET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	/* is it pointless to prefer PIO for "safety reasons"? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	if (ap->flags & ATA_FLAG_PIO_DMA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		tf.protocol = ATAPI_PROT_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		tf.feature |= ATAPI_PKT_DMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		tf.protocol = ATAPI_PROT_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		tf.lbam = SCSI_SENSE_BUFFERSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		tf.lbah = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	return ata_exec_internal(dev, &tf, cdb, DMA_FROM_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 				 sense_buf, SCSI_SENSE_BUFFERSIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)  *	ata_eh_analyze_serror - analyze SError for a failed port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)  *	@link: ATA link to analyze SError for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)  *	Analyze SError if available and further determine cause of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)  *	failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) static void ata_eh_analyze_serror(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	u32 serror = ehc->i.serror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	unsigned int err_mask = 0, action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	u32 hotplug_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	if (serror & (SERR_PERSISTENT | SERR_DATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		err_mask |= AC_ERR_ATA_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 		action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	if (serror & SERR_PROTOCOL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 		err_mask |= AC_ERR_HSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 		action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	if (serror & SERR_INTERNAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		err_mask |= AC_ERR_SYSTEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 		action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	/* Determine whether a hotplug event has occurred.  Both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	 * SError.N/X are considered hotplug events for enabled or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	 * host links.  For disabled PMP links, only N bit is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	 * considered as X bit is left at 1 for link plugging.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	if (link->lpm_policy > ATA_LPM_MAX_POWER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 		hotplug_mask = 0;	/* hotplug doesn't work w/ LPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 		hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 		hotplug_mask = SERR_PHYRDY_CHG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	if (serror & hotplug_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		ata_ehi_hotplugged(&ehc->i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	ehc->i.err_mask |= err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	ehc->i.action |= action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)  *	ata_eh_analyze_tf - analyze taskfile of a failed qc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)  *	@qc: qc to analyze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)  *	@tf: Taskfile registers to analyze
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)  *	Analyze taskfile of @qc and further determine cause of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)  *	failure.  This function also requests ATAPI sense data if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)  *	available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)  *	Determined recovery action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 				      const struct ata_taskfile *tf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	unsigned int tmp, action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	u8 stat = tf->command, err = tf->feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	if ((stat & (ATA_BUSY | ATA_DRQ | ATA_DRDY)) != ATA_DRDY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		qc->err_mask |= AC_ERR_HSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		return ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	if (stat & (ATA_ERR | ATA_DF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 		qc->err_mask |= AC_ERR_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 		 * Sense data reporting does not work if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		 * device fault bit is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 		if (stat & ATA_DF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 			stat &= ~ATA_SENSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	switch (qc->dev->class) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	case ATA_DEV_ZAC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 		if (stat & ATA_SENSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 			ata_eh_request_sense(qc, qc->scsicmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	case ATA_DEV_ATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		if (err & ATA_ICRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			qc->err_mask |= AC_ERR_ATA_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		if (err & (ATA_UNC | ATA_AMNF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			qc->err_mask |= AC_ERR_MEDIA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 		if (err & ATA_IDNF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 			qc->err_mask |= AC_ERR_INVALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	case ATA_DEV_ATAPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 		if (!(qc->ap->pflags & ATA_PFLAG_FROZEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			tmp = atapi_eh_request_sense(qc->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 						qc->scsicmd->sense_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 						qc->result_tf.feature >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 			if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 				qc->flags |= ATA_QCFLAG_SENSE_VALID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 				qc->err_mask |= tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		int ret = scsi_check_sense(qc->scsicmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		 * SUCCESS here means that the sense code could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		 * evaluated and should be passed to the upper layers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 		 * for correct evaluation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		 * FAILED means the sense code could not be interpreted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		 * and the device would need to be reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		 * NEEDS_RETRY and ADD_TO_MLQUEUE means that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		 * command would need to be retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		if (ret == NEEDS_RETRY || ret == ADD_TO_MLQUEUE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			qc->flags |= ATA_QCFLAG_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			qc->err_mask |= AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		} else if (ret != SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			qc->err_mask |= AC_ERR_HSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	if (qc->err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT | AC_ERR_ATA_BUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	return action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) static int ata_eh_categorize_error(unsigned int eflags, unsigned int err_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 				   int *xfer_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	int base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	if (!(eflags & ATA_EFLAG_DUBIOUS_XFER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 		*xfer_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	if (!*xfer_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 		base = ATA_ECAT_DUBIOUS_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	if (err_mask & AC_ERR_ATA_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 		return base + ATA_ECAT_ATA_BUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	if (err_mask & AC_ERR_TIMEOUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		return base + ATA_ECAT_TOUT_HSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	if (eflags & ATA_EFLAG_IS_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 		if (err_mask & AC_ERR_HSM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			return base + ATA_ECAT_TOUT_HSM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		if ((err_mask &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		     (AC_ERR_DEV|AC_ERR_MEDIA|AC_ERR_INVALID)) == AC_ERR_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 			return base + ATA_ECAT_UNK_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) struct speed_down_verdict_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	u64 since;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	int xfer_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	int nr_errors[ATA_ECAT_NR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	struct speed_down_verdict_arg *arg = void_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	int cat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 	cat = ata_eh_categorize_error(ent->eflags, ent->err_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 				      &arg->xfer_ok);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 	arg->nr_errors[cat]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)  *	ata_eh_speed_down_verdict - Determine speed down verdict
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)  *	@dev: Device of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)  *	This function examines error ring of @dev and determines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687)  *	whether NCQ needs to be turned off, transfer speed should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)  *	stepped down, or falling back to PIO is necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)  *	ECAT_ATA_BUS	: ATA_BUS error for any command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)  *	ECAT_TOUT_HSM	: TIMEOUT for any command or HSM violation for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)  *			  IO commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)  *	ECAT_UNK_DEV	: Unknown DEV error for IO commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)  *	ECAT_DUBIOUS_*	: Identical to above three but occurred while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)  *			  data transfer hasn't been verified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)  *	Verdicts are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)  *	NCQ_OFF		: Turn off NCQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)  *	SPEED_DOWN	: Speed down transfer speed but don't fall back
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)  *			  to PIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)  *	FALLBACK_TO_PIO	: Fall back to PIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)  *	Even if multiple verdicts are returned, only one action is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)  *	taken per error.  An action triggered by non-DUBIOUS errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)  *	clears ering, while one triggered by DUBIOUS_* errors doesn't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)  *	This is to expedite speed down decisions right after device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)  *	initially configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)  *	The following are speed down rules.  #1 and #2 deal with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)  *	DUBIOUS errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)  *	1. If more than one DUBIOUS_ATA_BUS or DUBIOUS_TOUT_HSM errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)  *	   occurred during last 5 mins, SPEED_DOWN and FALLBACK_TO_PIO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)  *	2. If more than one DUBIOUS_TOUT_HSM or DUBIOUS_UNK_DEV errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)  *	   occurred during last 5 mins, NCQ_OFF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)  *	3. If more than 8 ATA_BUS, TOUT_HSM or UNK_DEV errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)  *	   occurred during last 5 mins, FALLBACK_TO_PIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)  *	4. If more than 3 TOUT_HSM or UNK_DEV errors occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)  *	   during last 10 mins, NCQ_OFF.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)  *	5. If more than 3 ATA_BUS or TOUT_HSM errors, or more than 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)  *	   UNK_DEV errors occurred during last 10 mins, SPEED_DOWN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)  *	Inherited from caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)  *	OR of ATA_EH_SPDN_* flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) static unsigned int ata_eh_speed_down_verdict(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	const u64 j5mins = 5LLU * 60 * HZ, j10mins = 10LLU * 60 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	u64 j64 = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	struct speed_down_verdict_arg arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	unsigned int verdict = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	/* scan past 5 mins of error history */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	memset(&arg, 0, sizeof(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	arg.since = j64 - min(j64, j5mins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	if (arg.nr_errors[ATA_ECAT_DUBIOUS_ATA_BUS] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	    arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 		verdict |= ATA_EH_SPDN_SPEED_DOWN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 			ATA_EH_SPDN_FALLBACK_TO_PIO | ATA_EH_SPDN_KEEP_ERRORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	if (arg.nr_errors[ATA_ECAT_DUBIOUS_TOUT_HSM] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	    arg.nr_errors[ATA_ECAT_DUBIOUS_UNK_DEV] > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 		verdict |= ATA_EH_SPDN_NCQ_OFF | ATA_EH_SPDN_KEEP_ERRORS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	    arg.nr_errors[ATA_ECAT_TOUT_HSM] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	    arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		verdict |= ATA_EH_SPDN_FALLBACK_TO_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	/* scan past 10 mins of error history */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	memset(&arg, 0, sizeof(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	arg.since = j64 - min(j64, j10mins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	ata_ering_map(&dev->ering, speed_down_verdict_cb, &arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	if (arg.nr_errors[ATA_ECAT_TOUT_HSM] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	    arg.nr_errors[ATA_ECAT_UNK_DEV] > 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		verdict |= ATA_EH_SPDN_NCQ_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	if (arg.nr_errors[ATA_ECAT_ATA_BUS] +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	    arg.nr_errors[ATA_ECAT_TOUT_HSM] > 3 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	    arg.nr_errors[ATA_ECAT_UNK_DEV] > 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 		verdict |= ATA_EH_SPDN_SPEED_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	return verdict;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783)  *	ata_eh_speed_down - record error and speed down if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)  *	@dev: Failed device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)  *	@eflags: mask of ATA_EFLAG_* flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786)  *	@err_mask: err_mask of the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)  *	Record error and examine error history to determine whether
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)  *	adjusting transmission speed is necessary.  It also sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)  *	transmission limits appropriately if such adjustment is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)  *	necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)  *	Determined recovery action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) static unsigned int ata_eh_speed_down(struct ata_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 				unsigned int eflags, unsigned int err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	struct ata_link *link = ata_dev_phys_link(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	int xfer_ok = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	unsigned int verdict;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	unsigned int action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	/* don't bother if Cat-0 error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	if (ata_eh_categorize_error(eflags, err_mask, &xfer_ok) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	/* record error and determine whether speed down is necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	ata_ering_record(&dev->ering, eflags, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	verdict = ata_eh_speed_down_verdict(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	/* turn off NCQ? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	if ((verdict & ATA_EH_SPDN_NCQ_OFF) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	    (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 			   ATA_DFLAG_NCQ_OFF)) == ATA_DFLAG_NCQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 		dev->flags |= ATA_DFLAG_NCQ_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		ata_dev_warn(dev, "NCQ disabled due to excessive errors\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	/* speed down? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	if (verdict & ATA_EH_SPDN_SPEED_DOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 		/* speed down SATA link speed if possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 		if (sata_down_spd_limit(link, 0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 			action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 		/* lower transfer mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		if (dev->spdn_cnt < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 			static const int dma_dnxfer_sel[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 				{ ATA_DNXFER_DMA, ATA_DNXFER_40C };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 			static const int pio_dnxfer_sel[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 				{ ATA_DNXFER_PIO, ATA_DNXFER_FORCE_PIO0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 			int sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 			if (dev->xfer_shift != ATA_SHIFT_PIO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 				sel = dma_dnxfer_sel[dev->spdn_cnt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 				sel = pio_dnxfer_sel[dev->spdn_cnt];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 			dev->spdn_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 			if (ata_down_xfermask_limit(dev, sel) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 				action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	/* Fall back to PIO?  Slowing down to PIO is meaningless for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	 * SATA ATA devices.  Consider it only for PATA and SATAPI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	if ((verdict & ATA_EH_SPDN_FALLBACK_TO_PIO) && (dev->spdn_cnt >= 2) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	    (link->ap->cbl != ATA_CBL_SATA || dev->class == ATA_DEV_ATAPI) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	    (dev->xfer_shift != ATA_SHIFT_PIO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 		if (ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 			dev->spdn_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 			action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 			goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)  done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	/* device has been slowed down, blow error history */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	if (!(verdict & ATA_EH_SPDN_KEEP_ERRORS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 		ata_ering_clear(&dev->ering);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	return action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876)  *	ata_eh_worth_retry - analyze error and decide whether to retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)  *	@qc: qc to possibly retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)  *	Look at the cause of the error and decide if a retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)  * 	might be useful or not.  We don't want to retry media errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)  *	because the drive itself has probably already taken 10-30 seconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)  *	doing its own internal retries before reporting the failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) static inline int ata_eh_worth_retry(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	if (qc->err_mask & AC_ERR_MEDIA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 		return 0;	/* don't retry media errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	if (qc->flags & ATA_QCFLAG_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		return 1;	/* otherwise retry anything from fs stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	if (qc->err_mask & AC_ERR_INVALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 		return 0;	/* don't retry these */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	return qc->err_mask != AC_ERR_DEV;  /* retry if not dev error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)  *      ata_eh_quiet - check if we need to be quiet about a command error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)  *      @qc: qc to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)  *      Look at the qc flags anbd its scsi command request flags to determine
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)  *      if we need to be quiet about the command failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) static inline bool ata_eh_quiet(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	if (qc->scsicmd &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 	    qc->scsicmd->request->rq_flags & RQF_QUIET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 		qc->flags |= ATA_QCFLAG_QUIET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	return qc->flags & ATA_QCFLAG_QUIET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)  *	ata_eh_link_autopsy - analyze error and determine recovery action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)  *	@link: host link to perform autopsy on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)  *	Analyze why @link failed and determine which recovery actions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915)  *	are needed.  This function also sets more detailed AC_ERR_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916)  *	values and fills sense data for ATAPI CHECK SENSE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) static void ata_eh_link_autopsy(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	unsigned int all_err_mask = 0, eflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	int tag, nr_failed = 0, nr_quiet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	u32 serror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	if (ehc->i.flags & ATA_EHI_NO_AUTOPSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	/* obtain and analyze SError */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	rc = sata_scr_read(link, SCR_ERROR, &serror);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 		ehc->i.serror |= serror;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 		ata_eh_analyze_serror(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	} else if (rc != -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		/* SError read failed, force reset and probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		ehc->i.probe_mask |= ATA_ALL_DEVICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 		ehc->i.err_mask |= AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	/* analyze NCQ failure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 	ata_eh_analyze_ncq_error(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	/* any real error trumps AC_ERR_OTHER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 	if (ehc->i.err_mask & ~AC_ERR_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		ehc->i.err_mask &= ~AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	all_err_mask |= ehc->i.err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 	ata_qc_for_each_raw(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		if (!(qc->flags & ATA_QCFLAG_FAILED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		    ata_dev_phys_link(qc->dev) != link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		/* inherit upper level err_mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		qc->err_mask |= ehc->i.err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		/* analyze TF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 		ehc->i.action |= ata_eh_analyze_tf(qc, &qc->result_tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 		/* DEV errors are probably spurious in case of ATA_BUS error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		if (qc->err_mask & AC_ERR_ATA_BUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 			qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_MEDIA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 					  AC_ERR_INVALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 		/* any real error trumps unknown error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		if (qc->err_mask & ~AC_ERR_OTHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 			qc->err_mask &= ~AC_ERR_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		 * SENSE_VALID trumps dev/unknown error and revalidation. Upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 		 * layers will determine whether the command is worth retrying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 		 * based on the sense data and device class/type. Otherwise,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 		 * determine directly if the command is worth retrying using its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 		 * error mask and flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 		if (qc->flags & ATA_QCFLAG_SENSE_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 			qc->err_mask &= ~(AC_ERR_DEV | AC_ERR_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 		else if (ata_eh_worth_retry(qc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 			qc->flags |= ATA_QCFLAG_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 		/* accumulate error info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 		ehc->i.dev = qc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 		all_err_mask |= qc->err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 		if (qc->flags & ATA_QCFLAG_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 			eflags |= ATA_EFLAG_IS_IO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 		trace_ata_eh_link_autopsy_qc(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 		/* Count quiet errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 		if (ata_eh_quiet(qc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 			nr_quiet++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		nr_failed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 	/* If all failed commands requested silence, then be quiet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	if (nr_quiet == nr_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 		ehc->i.flags |= ATA_EHI_QUIET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	/* enforce default EH actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 	if (ap->pflags & ATA_PFLAG_FROZEN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	    all_err_mask & (AC_ERR_HSM | AC_ERR_TIMEOUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 		ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	else if (((eflags & ATA_EFLAG_IS_IO) && all_err_mask) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		 (!(eflags & ATA_EFLAG_IS_IO) && (all_err_mask & ~AC_ERR_DEV)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 		ehc->i.action |= ATA_EH_REVALIDATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	/* If we have offending qcs and the associated failed device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 	 * perform per-dev EH action only on the offending device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 	if (ehc->i.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 		ehc->i.dev_action[ehc->i.dev->devno] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 			ehc->i.action & ATA_EH_PERDEV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 		ehc->i.action &= ~ATA_EH_PERDEV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	/* propagate timeout to host link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 	if ((all_err_mask & AC_ERR_TIMEOUT) && !ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		ap->link.eh_context.i.err_mask |= AC_ERR_TIMEOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	/* record error and consider speeding down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 	dev = ehc->i.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 	if (!dev && ((ata_link_max_devices(link) == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		      ata_dev_enabled(link->device))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	    dev = link->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	if (dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 		if (dev->flags & ATA_DFLAG_DUBIOUS_XFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 			eflags |= ATA_EFLAG_DUBIOUS_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 		ehc->i.action |= ata_eh_speed_down(dev, eflags, all_err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 		trace_ata_eh_link_autopsy(dev, ehc->i.action, all_err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	DPRINTK("EXIT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)  *	ata_eh_autopsy - analyze error and determine recovery action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)  *	@ap: host port to perform autopsy on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)  *	Analyze all links of @ap and determine why they failed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)  *	which recovery actions are needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) void ata_eh_autopsy(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	ata_for_each_link(link, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 		ata_eh_link_autopsy(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	/* Handle the frigging slave link.  Autopsy is done similarly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	 * but actions and flags are transferred over to the master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 	 * link and handled from there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	if (ap->slave_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		struct ata_eh_context *mehc = &ap->link.eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 		struct ata_eh_context *sehc = &ap->slave_link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 		/* transfer control flags from master to slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 		sehc->i.flags |= mehc->i.flags & ATA_EHI_TO_SLAVE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 		/* perform autopsy on the slave link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 		ata_eh_link_autopsy(ap->slave_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 		/* transfer actions from slave to master and clear slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 		ata_eh_about_to_do(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 		mehc->i.action		|= sehc->i.action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 		mehc->i.dev_action[1]	|= sehc->i.dev_action[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 		mehc->i.flags		|= sehc->i.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 		ata_eh_done(ap->slave_link, NULL, ATA_EH_ALL_ACTIONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	/* Autopsy of fanout ports can affect host link autopsy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	 * Perform host link autopsy last.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	if (sata_pmp_attached(ap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 		ata_eh_link_autopsy(&ap->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)  *	ata_get_cmd_descript - get description for ATA command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)  *	@command: ATA command code to get description for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093)  *	Return a textual description of the given command, or NULL if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)  *	command is not known.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)  *	None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) const char *ata_get_cmd_descript(u8 command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) #ifdef CONFIG_ATA_VERBOSE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	static const struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 		u8 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 		const char *text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 	} cmd_descr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 		{ ATA_CMD_DEV_RESET,		"DEVICE RESET" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 		{ ATA_CMD_CHK_POWER,		"CHECK POWER MODE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 		{ ATA_CMD_STANDBY,		"STANDBY" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 		{ ATA_CMD_IDLE,			"IDLE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 		{ ATA_CMD_EDD,			"EXECUTE DEVICE DIAGNOSTIC" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 		{ ATA_CMD_DOWNLOAD_MICRO,	"DOWNLOAD MICROCODE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 		{ ATA_CMD_DOWNLOAD_MICRO_DMA,	"DOWNLOAD MICROCODE DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		{ ATA_CMD_NOP,			"NOP" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 		{ ATA_CMD_FLUSH,		"FLUSH CACHE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 		{ ATA_CMD_FLUSH_EXT,		"FLUSH CACHE EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 		{ ATA_CMD_ID_ATA,		"IDENTIFY DEVICE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 		{ ATA_CMD_ID_ATAPI,		"IDENTIFY PACKET DEVICE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 		{ ATA_CMD_SERVICE,		"SERVICE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 		{ ATA_CMD_READ,			"READ DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 		{ ATA_CMD_READ_EXT,		"READ DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 		{ ATA_CMD_READ_QUEUED,		"READ DMA QUEUED" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 		{ ATA_CMD_READ_STREAM_EXT,	"READ STREAM EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 		{ ATA_CMD_READ_STREAM_DMA_EXT,  "READ STREAM DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 		{ ATA_CMD_WRITE,		"WRITE DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 		{ ATA_CMD_WRITE_EXT,		"WRITE DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 		{ ATA_CMD_WRITE_QUEUED,		"WRITE DMA QUEUED EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 		{ ATA_CMD_WRITE_STREAM_EXT,	"WRITE STREAM EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 		{ ATA_CMD_WRITE_STREAM_DMA_EXT, "WRITE STREAM DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		{ ATA_CMD_WRITE_FUA_EXT,	"WRITE DMA FUA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		{ ATA_CMD_WRITE_QUEUED_FUA_EXT, "WRITE DMA QUEUED FUA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		{ ATA_CMD_FPDMA_READ,		"READ FPDMA QUEUED" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		{ ATA_CMD_FPDMA_WRITE,		"WRITE FPDMA QUEUED" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 		{ ATA_CMD_FPDMA_SEND,		"SEND FPDMA QUEUED" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 		{ ATA_CMD_FPDMA_RECV,		"RECEIVE FPDMA QUEUED" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 		{ ATA_CMD_PIO_READ,		"READ SECTOR(S)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 		{ ATA_CMD_PIO_READ_EXT,		"READ SECTOR(S) EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 		{ ATA_CMD_PIO_WRITE,		"WRITE SECTOR(S)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 		{ ATA_CMD_PIO_WRITE_EXT,	"WRITE SECTOR(S) EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 		{ ATA_CMD_READ_MULTI,		"READ MULTIPLE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 		{ ATA_CMD_READ_MULTI_EXT,	"READ MULTIPLE EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 		{ ATA_CMD_WRITE_MULTI,		"WRITE MULTIPLE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 		{ ATA_CMD_WRITE_MULTI_EXT,	"WRITE MULTIPLE EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 		{ ATA_CMD_WRITE_MULTI_FUA_EXT,	"WRITE MULTIPLE FUA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 		{ ATA_CMD_SET_FEATURES,		"SET FEATURES" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 		{ ATA_CMD_SET_MULTI,		"SET MULTIPLE MODE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 		{ ATA_CMD_VERIFY,		"READ VERIFY SECTOR(S)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 		{ ATA_CMD_VERIFY_EXT,		"READ VERIFY SECTOR(S) EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 		{ ATA_CMD_WRITE_UNCORR_EXT,	"WRITE UNCORRECTABLE EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 		{ ATA_CMD_STANDBYNOW1,		"STANDBY IMMEDIATE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 		{ ATA_CMD_IDLEIMMEDIATE,	"IDLE IMMEDIATE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 		{ ATA_CMD_SLEEP,		"SLEEP" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 		{ ATA_CMD_INIT_DEV_PARAMS,	"INITIALIZE DEVICE PARAMETERS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 		{ ATA_CMD_READ_NATIVE_MAX,	"READ NATIVE MAX ADDRESS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 		{ ATA_CMD_READ_NATIVE_MAX_EXT,	"READ NATIVE MAX ADDRESS EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 		{ ATA_CMD_SET_MAX,		"SET MAX ADDRESS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 		{ ATA_CMD_SET_MAX_EXT,		"SET MAX ADDRESS EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 		{ ATA_CMD_READ_LOG_EXT,		"READ LOG EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 		{ ATA_CMD_WRITE_LOG_EXT,	"WRITE LOG EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 		{ ATA_CMD_READ_LOG_DMA_EXT,	"READ LOG DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		{ ATA_CMD_WRITE_LOG_DMA_EXT,	"WRITE LOG DMA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 		{ ATA_CMD_TRUSTED_NONDATA,	"TRUSTED NON-DATA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 		{ ATA_CMD_TRUSTED_RCV,		"TRUSTED RECEIVE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 		{ ATA_CMD_TRUSTED_RCV_DMA,	"TRUSTED RECEIVE DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 		{ ATA_CMD_TRUSTED_SND,		"TRUSTED SEND" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 		{ ATA_CMD_TRUSTED_SND_DMA,	"TRUSTED SEND DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 		{ ATA_CMD_PMP_READ,		"READ BUFFER" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 		{ ATA_CMD_PMP_READ_DMA,		"READ BUFFER DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 		{ ATA_CMD_PMP_WRITE,		"WRITE BUFFER" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 		{ ATA_CMD_PMP_WRITE_DMA,	"WRITE BUFFER DMA" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 		{ ATA_CMD_CONF_OVERLAY,		"DEVICE CONFIGURATION OVERLAY" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 		{ ATA_CMD_SEC_SET_PASS,		"SECURITY SET PASSWORD" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 		{ ATA_CMD_SEC_UNLOCK,		"SECURITY UNLOCK" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 		{ ATA_CMD_SEC_ERASE_PREP,	"SECURITY ERASE PREPARE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 		{ ATA_CMD_SEC_ERASE_UNIT,	"SECURITY ERASE UNIT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 		{ ATA_CMD_SEC_FREEZE_LOCK,	"SECURITY FREEZE LOCK" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 		{ ATA_CMD_SEC_DISABLE_PASS,	"SECURITY DISABLE PASSWORD" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 		{ ATA_CMD_CONFIG_STREAM,	"CONFIGURE STREAM" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		{ ATA_CMD_SMART,		"SMART" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 		{ ATA_CMD_MEDIA_LOCK,		"DOOR LOCK" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 		{ ATA_CMD_MEDIA_UNLOCK,		"DOOR UNLOCK" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		{ ATA_CMD_DSM,			"DATA SET MANAGEMENT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 		{ ATA_CMD_CHK_MED_CRD_TYP,	"CHECK MEDIA CARD TYPE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		{ ATA_CMD_CFA_REQ_EXT_ERR,	"CFA REQUEST EXTENDED ERROR" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 		{ ATA_CMD_CFA_WRITE_NE,		"CFA WRITE SECTORS WITHOUT ERASE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 		{ ATA_CMD_CFA_TRANS_SECT,	"CFA TRANSLATE SECTOR" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 		{ ATA_CMD_CFA_ERASE,		"CFA ERASE SECTORS" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 		{ ATA_CMD_CFA_WRITE_MULT_NE,	"CFA WRITE MULTIPLE WITHOUT ERASE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		{ ATA_CMD_REQ_SENSE_DATA,	"REQUEST SENSE DATA EXT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 		{ ATA_CMD_SANITIZE_DEVICE,	"SANITIZE DEVICE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 		{ ATA_CMD_ZAC_MGMT_IN,		"ZAC MANAGEMENT IN" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 		{ ATA_CMD_ZAC_MGMT_OUT,		"ZAC MANAGEMENT OUT" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 		{ ATA_CMD_READ_LONG,		"READ LONG (with retries)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 		{ ATA_CMD_READ_LONG_ONCE,	"READ LONG (without retries)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 		{ ATA_CMD_WRITE_LONG,		"WRITE LONG (with retries)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 		{ ATA_CMD_WRITE_LONG_ONCE,	"WRITE LONG (without retries)" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 		{ ATA_CMD_RESTORE,		"RECALIBRATE" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		{ 0,				NULL } /* terminate list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	for (i = 0; cmd_descr[i].text; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 		if (cmd_descr[i].command == command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 			return cmd_descr[i].text;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) EXPORT_SYMBOL_GPL(ata_get_cmd_descript);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)  *	ata_eh_link_report - report error handling to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)  *	@link: ATA link EH is going on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)  *	Report EH to user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) static void ata_eh_link_report(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	const char *frozen, *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 	char tries_buf[6] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	int tag, nr_failed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 	if (ehc->i.flags & ATA_EHI_QUIET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	desc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	if (ehc->i.desc[0] != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 		desc = ehc->i.desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	ata_qc_for_each_raw(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 		if (!(qc->flags & ATA_QCFLAG_FAILED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 		    ata_dev_phys_link(qc->dev) != link ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 		    ((qc->flags & ATA_QCFLAG_QUIET) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 		     qc->err_mask == AC_ERR_DEV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 		if (qc->flags & ATA_QCFLAG_SENSE_VALID && !qc->err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 		nr_failed++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	if (!nr_failed && !ehc->i.err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	frozen = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	if (ap->pflags & ATA_PFLAG_FROZEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 		frozen = " frozen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	if (ap->eh_tries < ATA_EH_MAX_TRIES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 		snprintf(tries_buf, sizeof(tries_buf), " t%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 			 ap->eh_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	if (ehc->i.dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 		ata_dev_err(ehc->i.dev, "exception Emask 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 			    "SAct 0x%x SErr 0x%x action 0x%x%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 			    ehc->i.err_mask, link->sactive, ehc->i.serror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 			    ehc->i.action, frozen, tries_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 		if (desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 			ata_dev_err(ehc->i.dev, "%s\n", desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 		ata_link_err(link, "exception Emask 0x%x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 			     "SAct 0x%x SErr 0x%x action 0x%x%s%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 			     ehc->i.err_mask, link->sactive, ehc->i.serror,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 			     ehc->i.action, frozen, tries_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 		if (desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 			ata_link_err(link, "%s\n", desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) #ifdef CONFIG_ATA_VERBOSE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	if (ehc->i.serror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		ata_link_err(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 		  "SError: { %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		  ehc->i.serror & SERR_DATA_RECOVERED ? "RecovData " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		  ehc->i.serror & SERR_COMM_RECOVERED ? "RecovComm " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		  ehc->i.serror & SERR_DATA ? "UnrecovData " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 		  ehc->i.serror & SERR_PERSISTENT ? "Persist " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 		  ehc->i.serror & SERR_PROTOCOL ? "Proto " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 		  ehc->i.serror & SERR_INTERNAL ? "HostInt " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		  ehc->i.serror & SERR_PHYRDY_CHG ? "PHYRdyChg " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 		  ehc->i.serror & SERR_PHY_INT_ERR ? "PHYInt " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 		  ehc->i.serror & SERR_COMM_WAKE ? "CommWake " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 		  ehc->i.serror & SERR_10B_8B_ERR ? "10B8B " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 		  ehc->i.serror & SERR_DISPARITY ? "Dispar " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		  ehc->i.serror & SERR_CRC ? "BadCRC " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		  ehc->i.serror & SERR_HANDSHAKE ? "Handshk " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 		  ehc->i.serror & SERR_LINK_SEQ_ERR ? "LinkSeq " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 		  ehc->i.serror & SERR_TRANS_ST_ERROR ? "TrStaTrns " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 		  ehc->i.serror & SERR_UNRECOG_FIS ? "UnrecFIS " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 		  ehc->i.serror & SERR_DEV_XCHG ? "DevExch " : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) 	ata_qc_for_each_raw(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 		struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 		char data_buf[20] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 		char cdb_buf[70] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 		if (!(qc->flags & ATA_QCFLAG_FAILED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 		    ata_dev_phys_link(qc->dev) != link || !qc->err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 		if (qc->dma_dir != DMA_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 			static const char *dma_str[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 				[DMA_BIDIRECTIONAL]	= "bidi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 				[DMA_TO_DEVICE]		= "out",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 				[DMA_FROM_DEVICE]	= "in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) 			};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 			const char *prot_str = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 			switch (qc->tf.protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 			case ATA_PROT_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) 				prot_str = "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 			case ATA_PROT_NODATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) 				prot_str = "nodata";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 			case ATA_PROT_PIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 				prot_str = "pio";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 			case ATA_PROT_DMA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 				prot_str = "dma";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 			case ATA_PROT_NCQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 				prot_str = "ncq dma";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 			case ATA_PROT_NCQ_NODATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 				prot_str = "ncq nodata";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 			case ATAPI_PROT_NODATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 				prot_str = "nodata";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 			case ATAPI_PROT_PIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 				prot_str = "pio";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 			case ATAPI_PROT_DMA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 				prot_str = "dma";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 			snprintf(data_buf, sizeof(data_buf), " %s %u %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 				 prot_str, qc->nbytes, dma_str[qc->dma_dir]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 		if (ata_is_atapi(qc->tf.protocol)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			const u8 *cdb = qc->cdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 			size_t cdb_len = qc->dev->cdb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 			if (qc->scsicmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 				cdb = qc->scsicmd->cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 				cdb_len = qc->scsicmd->cmd_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 			__scsi_format_command(cdb_buf, sizeof(cdb_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 					      cdb, cdb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 			const char *descr = ata_get_cmd_descript(cmd->command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 			if (descr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) 				ata_dev_err(qc->dev, "failed command: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 					    descr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 		ata_dev_err(qc->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 			"cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 			"tag %d%s\n         %s"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 			"res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 			"Emask 0x%x (%s)%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 			cmd->command, cmd->feature, cmd->nsect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 			cmd->lbal, cmd->lbam, cmd->lbah,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 			cmd->hob_feature, cmd->hob_nsect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 			cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 			cmd->device, qc->tag, data_buf, cdb_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 			res->command, res->feature, res->nsect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 			res->lbal, res->lbam, res->lbah,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 			res->hob_feature, res->hob_nsect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 			res->hob_lbal, res->hob_lbam, res->hob_lbah,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 			res->device, qc->err_mask, ata_err_string(qc->err_mask),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 			qc->err_mask & AC_ERR_NCQ ? " <F>" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) #ifdef CONFIG_ATA_VERBOSE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 		if (res->command & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 				    ATA_SENSE | ATA_ERR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 			if (res->command & ATA_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 				ata_dev_err(qc->dev, "status: { Busy }\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 				ata_dev_err(qc->dev, "status: { %s%s%s%s%s}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 				  res->command & ATA_DRDY ? "DRDY " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 				  res->command & ATA_DF ? "DF " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 				  res->command & ATA_DRQ ? "DRQ " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 				  res->command & ATA_SENSE ? "SENSE " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 				  res->command & ATA_ERR ? "ERR " : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 		if (cmd->command != ATA_CMD_PACKET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 		    (res->feature & (ATA_ICRC | ATA_UNC | ATA_AMNF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 				     ATA_IDNF | ATA_ABORTED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 			ata_dev_err(qc->dev, "error: { %s%s%s%s%s}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 			  res->feature & ATA_ICRC ? "ICRC " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 			  res->feature & ATA_UNC ? "UNC " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 			  res->feature & ATA_AMNF ? "AMNF " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 			  res->feature & ATA_IDNF ? "IDNF " : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 			  res->feature & ATA_ABORTED ? "ABRT " : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)  *	ata_eh_report - report error handling to user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)  *	@ap: ATA port to report EH about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)  *	Report EH to user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) void ata_eh_report(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 	ata_for_each_link(link, ap, HOST_FIRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 		ata_eh_link_report(link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 			unsigned int *classes, unsigned long deadline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 			bool clear_classes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	if (clear_classes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 		ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 			classes[dev->devno] = ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	return reset(link, classes, deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) static int ata_eh_followup_srst_needed(struct ata_link *link, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	if ((link->flags & ATA_LFLAG_NO_SRST) || ata_link_offline(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	if (rc == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) int ata_eh_reset(struct ata_link *link, int classify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 		 ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 		 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	struct ata_link *slave = ap->slave_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	struct ata_eh_context *sehc = slave ? &slave->eh_context : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 	unsigned int *classes = ehc->classes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 	unsigned int lflags = link->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	int max_tries = 0, try = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	struct ata_link *failed_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	unsigned long deadline, now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	ata_reset_fn_t reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	u32 sstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 	int nr_unknown, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	 * Prepare to reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	while (ata_eh_reset_timeouts[max_tries] != ULONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 		max_tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	if (link->flags & ATA_LFLAG_RST_ONCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 		max_tries = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	if (link->flags & ATA_LFLAG_NO_HRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 		hardreset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	if (link->flags & ATA_LFLAG_NO_SRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		softreset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	/* make sure each reset attempt is at least COOL_DOWN apart */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 	if (ehc->i.flags & ATA_EHI_DID_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 		now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		WARN_ON(time_after(ehc->last_reset, now));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 		deadline = ata_deadline(ehc->last_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 					ATA_EH_RESET_COOL_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 		if (time_before(now, deadline))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 			schedule_timeout_uninterruptible(deadline - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 	ap->pflags |= ATA_PFLAG_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 	ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 	ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		/* If we issue an SRST then an ATA drive (not ATAPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 		 * may change configuration and be in PIO0 timing. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 		 * we do a hard reset (or are coming from power on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		 * this is true for ATA or ATAPI. Until we've set a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 		 * suitable controller mode we should not touch the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		 * bus as we may be talking too fast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 		dev->pio_mode = XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 		dev->dma_mode = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 		/* If the controller has a pio mode setup function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 		 * then use it to set the chipset to rights. Don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 		 * touch the DMA setup as that will be dealt with when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 		 * configuring devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		if (ap->ops->set_piomode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 			ap->ops->set_piomode(ap, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 	/* prefer hardreset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 	reset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	ehc->i.action &= ~ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	if (hardreset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		reset = hardreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 		ehc->i.action |= ATA_EH_HARDRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 	} else if (softreset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		reset = softreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		ehc->i.action |= ATA_EH_SOFTRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	if (prereset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 		unsigned long deadline = ata_deadline(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 						      ATA_EH_PRERESET_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 		if (slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 			sehc->i.action &= ~ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 			sehc->i.action |= ehc->i.action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 		rc = prereset(link, deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		/* If present, do prereset on slave link too.  Reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 		 * is skipped iff both master and slave links report
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		 * -ENOENT or clear ATA_EH_RESET.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 		if (slave && (rc == 0 || rc == -ENOENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 			int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 			tmp = prereset(slave, deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 			if (tmp != -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) 				rc = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 			ehc->i.action |= sehc->i.action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 			if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 				ata_link_dbg(link, "port disabled--ignoring\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) 				ehc->i.action &= ~ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) 				ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 					classes[dev->devno] = ATA_DEV_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 				rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 				ata_link_err(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 					     "prereset failed (errno=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 					     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		/* prereset() might have cleared ATA_EH_RESET.  If so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		 * bang classes, thaw and return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 		if (reset && !(ehc->i.action & ATA_EH_RESET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 			ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 				classes[dev->devno] = ATA_DEV_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 			if ((ap->pflags & ATA_PFLAG_FROZEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 			    ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 				ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 			rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584)  retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 	 * Perform reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 	if (ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 		ata_eh_freeze_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	deadline = ata_deadline(jiffies, ata_eh_reset_timeouts[try++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 	if (reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) 		if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) 			ata_link_info(link, "%s resetting link\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 				      reset == softreset ? "soft" : "hard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 		/* mark that this EH session started with reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) 		ehc->last_reset = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 		if (reset == hardreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 			ehc->i.flags |= ATA_EHI_DID_HARDRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 			ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) 		rc = ata_do_reset(link, reset, classes, deadline, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 		if (rc && rc != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) 			failed_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) 		/* hardreset slave link if existent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 		if (slave && reset == hardreset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 			int tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 			if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 				ata_link_info(slave, "hard resetting link\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 			ata_eh_about_to_do(slave, NULL, ATA_EH_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 			tmp = ata_do_reset(slave, reset, classes, deadline,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 					   false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 			switch (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 			case -EAGAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 				rc = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 			case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 				failed_link = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 				rc = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) 		/* perform follow-up SRST if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 		if (reset == hardreset &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) 		    ata_eh_followup_srst_needed(link, rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 			reset = softreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) 			if (!reset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 				ata_link_err(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 	     "follow-up softreset required but no softreset available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 				failed_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 				rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 			ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) 			rc = ata_do_reset(link, reset, classes, deadline, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 				failed_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 		if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 			ata_link_info(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 	"no reset method available, skipping reset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 		if (!(lflags & ATA_LFLAG_ASSUME_CLASS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 			lflags |= ATA_LFLAG_ASSUME_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	 * Post-reset processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 		/* After the reset, the device state is PIO 0 and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 		 * controller state is undefined.  Reset also wakes up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		 * drives from sleeping mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 		dev->pio_mode = XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 		dev->flags &= ~ATA_DFLAG_SLEEPING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		if (ata_phys_link_offline(ata_dev_phys_link(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 		/* apply class override */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 		if (lflags & ATA_LFLAG_ASSUME_ATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 			classes[dev->devno] = ATA_DEV_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		else if (lflags & ATA_LFLAG_ASSUME_SEMB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 			classes[dev->devno] = ATA_DEV_SEMB_UNSUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	/* record current link speed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 	if (sata_scr_read(link, SCR_STATUS, &sstatus) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 		link->sata_spd = (sstatus >> 4) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 	if (slave && sata_scr_read(slave, SCR_STATUS, &sstatus) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 		slave->sata_spd = (sstatus >> 4) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	/* thaw the port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	if (ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 	/* postreset() should clear hardware SError.  Although SError
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	 * is cleared during link resume, clearing SError here is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 	 * necessary as some PHYs raise hotplug events after SRST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 	 * This introduces race condition where hotplug occurs between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 	 * reset and here.  This race is mediated by cross checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 	 * link onlineness and classification result later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	if (postreset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 		postreset(link, classes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 		if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 			postreset(slave, classes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	 * Some controllers can't be frozen very well and may set spurious
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	 * error conditions during reset.  Clear accumulated error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 	 * information and re-thaw the port if frozen.  As reset is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	 * final recovery action and we cross check link onlineness against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 	 * device classification later, no hotplug event is lost by this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	spin_lock_irqsave(link->ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) 	memset(&link->eh_info, 0, sizeof(link->eh_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 	if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) 		memset(&slave->eh_info, 0, sizeof(link->eh_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) 	ap->pflags &= ~ATA_PFLAG_EH_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	spin_unlock_irqrestore(link->ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 	if (ap->pflags & ATA_PFLAG_FROZEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 		ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 	 * Make sure onlineness and classification result correspond.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 	 * Hotplug could have happened during reset and some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 	 * controllers fail to wait while a drive is spinning up after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	 * being hotplugged causing misdetection.  By cross checking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	 * link on/offlineness and classification result, those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	 * conditions can be reliably detected and retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) 	nr_unknown = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 	ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) 		if (ata_phys_link_online(ata_dev_phys_link(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 			if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 				ata_dev_dbg(dev, "link online but device misclassified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) 				classes[dev->devno] = ATA_DEV_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 				nr_unknown++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 		} else if (ata_phys_link_offline(ata_dev_phys_link(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) 			if (ata_class_enabled(classes[dev->devno]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) 				ata_dev_dbg(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 					    "link offline, clearing class %d to NONE\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 					    classes[dev->devno]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 			classes[dev->devno] = ATA_DEV_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 		} else if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 			ata_dev_dbg(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) 				    "link status unknown, clearing UNKNOWN to NONE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) 			classes[dev->devno] = ATA_DEV_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 	if (classify && nr_unknown) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) 		if (try < max_tries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) 			ata_link_warn(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 				      "link online but %d devices misclassified, retrying\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) 				      nr_unknown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 			failed_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) 			rc = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		ata_link_warn(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 			      "link online but %d devices misclassified, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 			      "device detection might fail\n", nr_unknown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 	/* reset successful, schedule revalidation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 	ata_eh_done(link, NULL, ATA_EH_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 	if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 		ata_eh_done(slave, NULL, ATA_EH_RESET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 	ehc->last_reset = jiffies;		/* update to completion time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 	ehc->i.action |= ATA_EH_REVALIDATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 	link->lpm_policy = ATA_LPM_UNKNOWN;	/* reset LPM state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 	/* clear hotplug flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 	ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 	if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) 		sehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) 	ap->pflags &= ~ATA_PFLAG_RESETTING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	/* if SCR isn't accessible on a fan-out port, PMP needs to be reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 	if (!ata_is_host_link(link) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 	    sata_scr_read(link, SCR_STATUS, &sstatus))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 		rc = -ERESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) 	if (try >= max_tries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) 		 * Thaw host port even if reset failed, so that the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) 		 * can be retried on the next phy event.  This risks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 		 * repeated EH runs but seems to be a better tradeoff than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 		 * shutting down a port after a botched hotplug attempt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 		if (ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 			ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) 	now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	if (time_before(now, deadline)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 		unsigned long delta = deadline - now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 		ata_link_warn(failed_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 			"reset failed (errno=%d), retrying in %u secs\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 			rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) 		ata_eh_release(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) 		while (delta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 			delta = schedule_timeout_uninterruptible(delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 		ata_eh_acquire(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	 * While disks spinup behind PMP, some controllers fail sending SRST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	 * They need to be reset - as well as the PMP - before retrying.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) 	if (rc == -ERESTART) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 		if (ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 			ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 	if (try == max_tries - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 		sata_down_spd_limit(link, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 		if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 			sata_down_spd_limit(slave, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	} else if (rc == -EPIPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 		sata_down_spd_limit(failed_link, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 	if (hardreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) 		reset = hardreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) 	goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) static inline void ata_eh_pull_park_action(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) 	 * This function can be thought of as an extended version of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) 	 * ata_eh_about_to_do() specially crafted to accommodate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) 	 * requirements of ATA_EH_PARK handling. Since the EH thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 	 * does not leave the do {} while () loop in ata_eh_recover as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) 	 * long as the timeout for a park request to *one* device on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) 	 * the port has not expired, and since we still want to pick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) 	 * up park requests to other devices on the same port or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) 	 * timeout updates for the same device, we have to pull
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) 	 * ATA_EH_PARK actions from eh_info into eh_context.i
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) 	 * ourselves at the beginning of each pass over the loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) 	 * Additionally, all write accesses to &ap->park_req_pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 	 * through reinit_completion() (see below) or complete_all()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) 	 * (see ata_scsi_park_store()) are protected by the host lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) 	 * As a result we have that park_req_pending.done is zero on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 	 * exit from this function, i.e. when ATA_EH_PARK actions for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 	 * *all* devices on port ap have been pulled into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 	 * respective eh_context structs. If, and only if,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) 	 * park_req_pending.done is non-zero by the time we reach
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) 	 * wait_for_completion_timeout(), another ATA_EH_PARK action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 	 * has been scheduled for at least one of the devices on port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 	 * ap and we have to cycle over the do {} while () loop in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 	 * ata_eh_recover() again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) 	reinit_completion(&ap->park_req_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 		ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 			struct ata_eh_info *ehi = &link->eh_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 			link->eh_context.i.dev_action[dev->devno] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 				ehi->dev_action[dev->devno] & ATA_EH_PARK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) 			ata_eh_clear_action(link, dev, ehi, ATA_EH_PARK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) static void ata_eh_park_issue_cmd(struct ata_device *dev, int park)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 	ata_tf_init(dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 	if (park) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 		ehc->unloaded_mask |= 1 << dev->devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 		tf.command = ATA_CMD_IDLEIMMEDIATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 		tf.feature = 0x44;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 		tf.lbal = 0x4c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 		tf.lbam = 0x4e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) 		tf.lbah = 0x55;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) 		ehc->unloaded_mask &= ~(1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) 		tf.command = ATA_CMD_CHK_POWER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) 	tf.flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 	tf.protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) 	err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) 	if (park && (err_mask || tf.lbal != 0xc4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 		ata_dev_err(dev, "head unload failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) 		ehc->unloaded_mask &= ~(1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) static int ata_eh_revalidate_and_attach(struct ata_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 					struct ata_device **r_failed_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	unsigned int new_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	/* For PATA drive side cable detection to work, IDENTIFY must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	 * be done backwards such that PDIAG- is released by the slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	 * device before the master device is identified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 	ata_for_each_dev(dev, link, ALL_REVERSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) 		unsigned int action = ata_eh_dev_action(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 		unsigned int readid_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		if (ehc->i.flags & ATA_EHI_DID_RESET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 			readid_flags |= ATA_READID_POSTRESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 		if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) 			WARN_ON(dev->class == ATA_DEV_PMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) 			if (ata_phys_link_offline(ata_dev_phys_link(dev))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 				rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 			ata_eh_about_to_do(link, dev, ATA_EH_REVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 			rc = ata_dev_revalidate(dev, ehc->classes[dev->devno],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 						readid_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 			ata_eh_done(link, dev, ATA_EH_REVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 			/* Configuration may have changed, reconfigure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 			 * transfer mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 			ehc->i.flags |= ATA_EHI_SETMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 			/* schedule the scsi_rescan_device() here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) 			schedule_work(&(ap->scsi_rescan_task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 		} else if (dev->class == ATA_DEV_UNKNOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) 			   ehc->tries[dev->devno] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) 			   ata_class_enabled(ehc->classes[dev->devno])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 			/* Temporarily set dev->class, it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 			 * permanently set once all configurations are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 			 * complete.  This is necessary because new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 			 * device configuration is done in two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 			 * separate loops.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 			dev->class = ehc->classes[dev->devno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 			if (dev->class == ATA_DEV_PMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 				rc = sata_pmp_attach(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 				rc = ata_dev_read_id(dev, &dev->class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) 						     readid_flags, dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 			/* read_id might have changed class, store and reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 			ehc->classes[dev->devno] = dev->class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) 			dev->class = ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) 			switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 			case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) 				/* clear error info accumulated during probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 				ata_ering_clear(&dev->ering);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 				new_mask |= 1 << dev->devno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 			case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) 				/* IDENTIFY was issued to non-existent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) 				 * device.  No need to reset.  Just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 				 * thaw and ignore the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) 				ata_eh_thaw_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) 	/* PDIAG- should have been released, ask cable type if post-reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) 	if ((ehc->i.flags & ATA_EHI_DID_RESET) && ata_is_host_link(link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 		if (ap->ops->cable_detect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 			ap->cbl = ap->ops->cable_detect(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 		ata_force_cbl(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 	/* Configure new devices forward such that user doesn't see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	 * device detection messages backwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 		if (!(new_mask & (1 << dev->devno)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 		dev->class = ehc->classes[dev->devno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 		if (dev->class == ATA_DEV_PMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 		ehc->i.flags |= ATA_EHI_PRINTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) 		rc = ata_dev_configure(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 		ehc->i.flags &= ~ATA_EHI_PRINTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) 			dev->class = ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 		ap->pflags |= ATA_PFLAG_SCSI_HOTPLUG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 		/* new device discovered, configure xfermode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 		ehc->i.flags |= ATA_EHI_SETMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	*r_failed_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 	DPRINTK("EXIT rc=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044)  *	ata_set_mode - Program timings and issue SET FEATURES - XFER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045)  *	@link: link on which timings will be programmed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046)  *	@r_failed_dev: out parameter for failed device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048)  *	Set ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)  *	ata_set_mode() fails, pointer to the failing device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050)  *	returned in @r_failed_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)  *	PCI/etc. bus probe sem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056)  *	0 on success, negative errno otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 	/* if data transfer is verified, clear DUBIOUS_XFER on ering top */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 	ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 		if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 			struct ata_ering_entry *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 			ent = ata_ering_top(&dev->ering);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 			if (ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 				ent->eflags &= ~ATA_EFLAG_DUBIOUS_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 	/* has private set_mode? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) 	if (ap->ops->set_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) 		rc = ap->ops->set_mode(link, r_failed_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 		rc = ata_do_set_mode(link, r_failed_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	/* if transfer mode has changed, set DUBIOUS_XFER on device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 	ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) 		u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 		u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) 		if (dev->xfer_mode != saved_xfer_mode ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 		    ata_ncq_enabled(dev) != saved_ncq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 			dev->flags |= ATA_DFLAG_DUBIOUS_XFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096)  *	atapi_eh_clear_ua - Clear ATAPI UNIT ATTENTION after reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)  *	@dev: ATAPI device to clear UA for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)  *	Resets and other operations can make an ATAPI device raise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)  *	UNIT ATTENTION which causes the next operation to fail.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)  *	function clears UA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)  *	EH context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) static int atapi_eh_clear_ua(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) 	for (i = 0; i < ATA_EH_UA_TRIES; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) 		u8 *sense_buffer = dev->link->ap->sector_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 		u8 sense_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) 		unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) 		err_mask = atapi_eh_tur(dev, &sense_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) 		if (err_mask != 0 && err_mask != AC_ERR_DEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 			ata_dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) 				     "TEST_UNIT_READY failed (err_mask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 				     err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) 		if (!err_mask || sense_key != UNIT_ATTENTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) 		err_mask = atapi_eh_request_sense(dev, sense_buffer, sense_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) 			ata_dev_warn(dev, "failed to clear "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 				"UNIT ATTENTION (err_mask=0x%x)\n", err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 	ata_dev_warn(dev, "UNIT ATTENTION persists after %d tries\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) 		     ATA_EH_UA_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)  *	ata_eh_maybe_retry_flush - Retry FLUSH if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145)  *	@dev: ATA device which may need FLUSH retry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147)  *	If @dev failed FLUSH, it needs to be reported upper layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148)  *	immediately as it means that @dev failed to remap and already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149)  *	lost at least a sector and further FLUSH retrials won't make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150)  *	any difference to the lost sector.  However, if FLUSH failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151)  *	for other reasons, for example transmission error, FLUSH needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)  *	to be retried.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)  *	This function determines whether FLUSH failure retry is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)  *	necessary and performs it if so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158)  *	0 if EH can continue, -errno if EH needs to be repeated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) static int ata_eh_maybe_retry_flush(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 	struct ata_link *link = dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) 	/* did flush fail for this device? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 	if (!ata_tag_valid(link->active_tag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	qc = __ata_qc_from_tag(ap, link->active_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) 	if (qc->dev != dev || (qc->tf.command != ATA_CMD_FLUSH_EXT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 			       qc->tf.command != ATA_CMD_FLUSH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	/* if the device failed it, it should be reported to upper layers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	if (qc->err_mask & AC_ERR_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 	/* flush failed for some other reason, give it another shot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) 	ata_tf_init(dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	tf.command = qc->tf.command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) 	tf.flags |= ATA_TFLAG_DEVICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 	tf.protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) 	ata_dev_warn(dev, "retrying FLUSH 0x%x Emask 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 		       tf.command, qc->err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 	if (!err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 		 * FLUSH is complete but there's no way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 		 * successfully complete a failed command from EH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 		 * Making sure retry is allowed at least once and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 		 * retrying it should do the trick - whatever was in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 		 * the cache is already on the platter and this won't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) 		 * cause infinite loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) 		qc->scsicmd->allowed = max(qc->scsicmd->allowed, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 		ata_dev_warn(dev, "FLUSH failed Emask 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 			       err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 		/* if device failed it, report it to upper layers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 		if (err_mask & AC_ERR_DEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 			qc->err_mask |= AC_ERR_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 			qc->result_tf = tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 			if (!(ap->pflags & ATA_PFLAG_FROZEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 				rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)  *	ata_eh_set_lpm - configure SATA interface power management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221)  *	@link: link to configure power management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)  *	@policy: the link power management policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223)  *	@r_failed_dev: out parameter for failed device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)  *	Enable SATA Interface power management.  This will enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226)  *	Device Interface Power Management (DIPM) for min_power and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)  *	medium_power_with_dipm policies, and then call driver specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228)  *	callbacks for enabling Host Initiated Power management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) 			  struct ata_device **r_failed_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) 	struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 	struct ata_device *dev, *link_dev = NULL, *lpm_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 	enum ata_lpm_policy old_policy = link->lpm_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 	bool no_dipm = link->ap->flags & ATA_FLAG_NO_DIPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	unsigned int hints = ATA_LPM_EMPTY | ATA_LPM_HIPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) 	/* if the link or host doesn't do LPM, noop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 	if (!IS_ENABLED(CONFIG_SATA_HOST) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) 	    (link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 	 * DIPM is enabled only for MIN_POWER as some devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 	 * misbehave when the host NACKs transition to SLUMBER.  Order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 	 * device and link configurations such that the host always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 	 * allows DIPM requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) 	ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 		bool hipm = ata_id_has_hipm(dev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) 		bool dipm = ata_id_has_dipm(dev->id) && !no_dipm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) 		/* find the first enabled and LPM enabled devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 		if (!link_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) 			link_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) 		if (!lpm_dev && (hipm || dipm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 			lpm_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 		hints &= ~ATA_LPM_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 		if (!hipm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 			hints &= ~ATA_LPM_HIPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 		/* disable DIPM before changing link config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 		if (policy < ATA_LPM_MED_POWER_WITH_DIPM && dipm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) 			err_mask = ata_dev_set_feature(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 					SETFEATURES_SATA_DISABLE, SATA_DIPM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) 			if (err_mask && err_mask != AC_ERR_DEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 				ata_dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) 					     "failed to disable DIPM, Emask 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 					     err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) 				rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 	if (ap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) 		rc = ap->ops->set_lpm(link, policy, hints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) 		if (!rc && ap->slave_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 			rc = ap->ops->set_lpm(ap->slave_link, policy, hints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 		rc = sata_pmp_set_lpm(link, policy, hints);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 	 * Attribute link config failure to the first (LPM) enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 	 * device on the link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 		if (rc == -EOPNOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 			link->flags |= ATA_LFLAG_NO_LPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 		dev = lpm_dev ? lpm_dev : link_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) 	 * Low level driver acked the transition.  Issue DIPM command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) 	 * with the new policy set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 	link->lpm_policy = policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) 	if (ap && ap->slave_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) 		ap->slave_link->lpm_policy = policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 	/* host config updated, enable DIPM if transitioning to MIN_POWER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 		if (policy >= ATA_LPM_MED_POWER_WITH_DIPM && !no_dipm &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 		    ata_id_has_dipm(dev->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 			err_mask = ata_dev_set_feature(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 					SETFEATURES_SATA_ENABLE, SATA_DIPM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 			if (err_mask && err_mask != AC_ERR_DEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) 				ata_dev_warn(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 					"failed to enable DIPM, Emask 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) 					err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 				rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) 				goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 	link->last_lpm_change = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 	link->flags |= ATA_LFLAG_CHANGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 	/* restore the old policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 	link->lpm_policy = old_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 	if (ap && ap->slave_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 		ap->slave_link->lpm_policy = old_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 	/* if no device or only one more chance is left, disable LPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 	if (!dev || ehc->tries[dev->devno] <= 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 		ata_link_warn(link, "disabling LPM on the link\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 		link->flags |= ATA_LFLAG_NO_LPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 	if (r_failed_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) 		*r_failed_dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) int ata_link_nr_enabled(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 	int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	ata_for_each_dev(dev, link, ENABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 		cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 	return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) static int ata_link_nr_vacant(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) 	int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 	ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 		if (dev->class == ATA_DEV_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) 	return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) static int ata_eh_skip_recovery(struct ata_link *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) 	/* skip disabled links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) 	if (link->flags & ATA_LFLAG_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) 	/* skip if explicitly requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) 	if (ehc->i.flags & ATA_EHI_NO_RECOVERY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) 	/* thaw frozen port and recover failed devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) 	if ((ap->pflags & ATA_PFLAG_FROZEN) || ata_link_nr_enabled(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) 	/* reset at least once if reset is requested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) 	if ((ehc->i.action & ATA_EH_RESET) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) 	    !(ehc->i.flags & ATA_EHI_DID_RESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) 	/* skip if class codes for all vacant slots are ATA_DEV_NONE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) 	ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) 		if (dev->class == ATA_DEV_UNKNOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) 		    ehc->classes[dev->devno] != ATA_DEV_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) static int ata_count_probe_trials_cb(struct ata_ering_entry *ent, void *void_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) 	u64 interval = msecs_to_jiffies(ATA_EH_PROBE_TRIAL_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) 	u64 now = get_jiffies_64();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 	int *trials = void_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 	if ((ent->eflags & ATA_EFLAG_OLD_ER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) 	    (ent->timestamp < now - min(now, interval)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) 	(*trials)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) static int ata_eh_schedule_probe(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) 	struct ata_link *link = ata_dev_phys_link(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) 	int trials = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) 	if (!(ehc->i.probe_mask & (1 << dev->devno)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 	    (ehc->did_probe_mask & (1 << dev->devno)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) 	ata_eh_detach_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 	ata_dev_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) 	ehc->did_probe_mask |= (1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 	ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) 	ehc->saved_xfer_mode[dev->devno] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) 	ehc->saved_ncq_enabled &= ~(1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 	/* the link maybe in a deep sleep, wake it up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 	if (link->lpm_policy > ATA_LPM_MAX_POWER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) 		if (ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 			link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) 					       ATA_LPM_EMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 			sata_pmp_set_lpm(link, ATA_LPM_MAX_POWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) 					 ATA_LPM_EMPTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 	/* Record and count probe trials on the ering.  The specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) 	 * error mask used is irrelevant.  Because a successful device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 	 * detection clears the ering, this count accumulates only if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 	 * there are consecutive failed probes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 	 * If the count is equal to or higher than ATA_EH_PROBE_TRIALS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) 	 * in the last ATA_EH_PROBE_TRIAL_INTERVAL, link speed is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 	 * forced to 1.5Gbps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 	 * This is to work around cases where failed link speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) 	 * negotiation results in device misdetection leading to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 	 * infinite DEVXCHG or PHRDY CHG events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) 	ata_ering_record(&dev->ering, 0, AC_ERR_OTHER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 	ata_ering_map(&dev->ering, ata_count_probe_trials_cb, &trials);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) 	if (trials > ATA_EH_PROBE_TRIALS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 		sata_down_spd_limit(link, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) static int ata_eh_handle_dev_fail(struct ata_device *dev, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) 	struct ata_eh_context *ehc = &dev->link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) 	/* -EAGAIN from EH routine indicates retry without prejudice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) 	 * The requester is responsible for ensuring forward progress.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) 	if (err != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) 		ehc->tries[dev->devno]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) 	switch (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) 	case -ENODEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) 		/* device missing or wrong IDENTIFY data, schedule probing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 		ehc->i.probe_mask |= (1 << dev->devno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) 	case -EINVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) 		/* give it just one more chance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) 		ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) 	case -EIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) 		if (ehc->tries[dev->devno] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) 			/* This is the last chance, better to slow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) 			 * down than lose it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) 			sata_down_spd_limit(ata_dev_phys_link(dev), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) 			if (dev->pio_mode > XFER_PIO_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) 				ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) 	if (ata_dev_enabled(dev) && !ehc->tries[dev->devno]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) 		/* disable device if it has used up all its chances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) 		ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 		/* detach if offline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) 		if (ata_phys_link_offline(ata_dev_phys_link(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) 			ata_eh_detach_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) 		/* schedule probe if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) 		if (ata_eh_schedule_probe(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 			ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) 			memset(ehc->cmd_timeout_idx[dev->devno], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) 			       sizeof(ehc->cmd_timeout_idx[dev->devno]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) 		ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523)  *	ata_eh_recover - recover host port after error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524)  *	@ap: host port to recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525)  *	@prereset: prereset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526)  *	@softreset: softreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527)  *	@hardreset: hardreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528)  *	@postreset: postreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529)  *	@r_failed_link: out parameter for failed link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531)  *	This is the alpha and omega, eum and yang, heart and soul of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532)  *	libata exception handling.  On entry, actions required to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533)  *	recover each link and hotplug requests are recorded in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534)  *	link's eh_context.  This function executes all the operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535)  *	with appropriate retrials and fallbacks to resurrect failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536)  *	devices, detach goners and greet newcomers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) 		   ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) 		   ata_postreset_fn_t postreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) 		   struct ata_link **r_failed_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) 	int rc, nr_fails;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) 	unsigned long flags, deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) 	/* prep for recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) 		/* re-enable link? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) 		if (ehc->i.action & ATA_EH_ENABLE_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 			ata_eh_about_to_do(link, NULL, ATA_EH_ENABLE_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) 			spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) 			link->flags &= ~ATA_LFLAG_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) 			spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) 			ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) 		ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) 			if (link->flags & ATA_LFLAG_NO_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) 				ehc->tries[dev->devno] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 				ehc->tries[dev->devno] = ATA_EH_DEV_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 			/* collect port action mask recorded in dev actions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) 			ehc->i.action |= ehc->i.dev_action[dev->devno] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) 					 ~ATA_EH_PERDEV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) 			ehc->i.dev_action[dev->devno] &= ATA_EH_PERDEV_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 			/* process hotplug request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) 			if (dev->flags & ATA_DFLAG_DETACH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) 				ata_eh_detach_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) 			/* schedule probe if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 			if (!ata_dev_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) 				ata_eh_schedule_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590)  retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 	/* if UNLOADING, finish immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) 	if (ap->pflags & ATA_PFLAG_UNLOADING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 	/* prep for EH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 		/* skip EH if possible. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) 		if (ata_eh_skip_recovery(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 			ehc->i.action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) 		ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 			ehc->classes[dev->devno] = ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) 	/* reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) 		if (!(ehc->i.action & ATA_EH_RESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) 		rc = ata_eh_reset(link, ata_link_nr_vacant(link),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) 				  prereset, softreset, hardreset, postreset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) 			ata_link_err(link, "reset failed, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 		unsigned long now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) 		 * clears ATA_EH_PARK in eh_info and resets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) 		 * ap->park_req_pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) 		ata_eh_pull_park_action(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) 		deadline = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) 		ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 			ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) 				struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 				unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) 				if (dev->class != ATA_DEV_ATA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 				    dev->class != ATA_DEV_ZAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) 				if (!(ehc->i.dev_action[dev->devno] &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) 				      ATA_EH_PARK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) 				tmp = dev->unpark_deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 				if (time_before(deadline, tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) 					deadline = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 				else if (time_before_eq(tmp, jiffies))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) 				if (ehc->unloaded_mask & (1 << dev->devno))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) 				ata_eh_park_issue_cmd(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) 		now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) 		if (time_before_eq(deadline, now))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) 		ata_eh_release(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) 		deadline = wait_for_completion_timeout(&ap->park_req_pending,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) 						       deadline - now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) 		ata_eh_acquire(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) 	} while (deadline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) 		ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) 			if (!(link->eh_context.unloaded_mask &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 			      (1 << dev->devno)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) 			ata_eh_park_issue_cmd(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) 			ata_eh_done(link, dev, ATA_EH_PARK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) 	/* the rest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 	nr_fails = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) 	ata_for_each_link(link, ap, PMP_FIRST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 		if (sata_pmp_attached(ap) && ata_is_host_link(link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) 			goto config_lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) 		/* revalidate existing devices and attach new ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) 		rc = ata_eh_revalidate_and_attach(link, &dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) 			goto rest_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 		/* if PMP got attached, return, pmp EH will take care of it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) 		if (link->device->class == ATA_DEV_PMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) 			ehc->i.action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) 		/* configure transfer mode if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) 		if (ehc->i.flags & ATA_EHI_SETMODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) 			rc = ata_set_mode(link, &dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 				goto rest_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) 			ehc->i.flags &= ~ATA_EHI_SETMODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) 		/* If reset has been issued, clear UA to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 		 * disrupting the current users of the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) 		if (ehc->i.flags & ATA_EHI_DID_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) 			ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 				if (dev->class != ATA_DEV_ATAPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 				rc = atapi_eh_clear_ua(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) 				if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) 					goto rest_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) 				if (zpodd_dev_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) 					zpodd_post_poweron(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 		/* retry flush if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) 		ata_for_each_dev(dev, link, ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 			if (dev->class != ATA_DEV_ATA &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) 			    dev->class != ATA_DEV_ZAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) 			rc = ata_eh_maybe_retry_flush(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) 				goto rest_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) 	config_lpm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) 		/* configure link power saving */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) 		if (link->lpm_policy != ap->target_lpm_policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) 			rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 			if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) 				goto rest_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) 		/* this link is okay now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) 		ehc->i.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) 		continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 	rest_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) 		nr_fails++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) 		if (dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) 			ata_eh_handle_dev_fail(dev, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 		if (ap->pflags & ATA_PFLAG_FROZEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) 			/* PMP reset requires working host port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) 			 * Can't retry if it's frozen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) 			if (sata_pmp_attached(ap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) 	if (nr_fails)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 	if (rc && r_failed_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 		*r_failed_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	DPRINTK("EXIT, rc=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768)  *	ata_eh_finish - finish up EH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769)  *	@ap: host port to finish EH for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771)  *	Recovery is complete.  Clean up EH states and retry or finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772)  *	failed qcs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) void ata_eh_finish(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 	struct ata_queued_cmd *qc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 	int tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	/* retry or finish qcs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	ata_qc_for_each_raw(ap, qc, tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 		if (!(qc->flags & ATA_QCFLAG_FAILED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 		if (qc->err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 			/* FIXME: Once EH migration is complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 			 * generate sense data in this function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 			 * considering both err_mask and tf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 			if (qc->flags & ATA_QCFLAG_RETRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 				ata_eh_qc_retry(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 				ata_eh_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 			if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 				ata_eh_qc_complete(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 				/* feed zero TF to sense generation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 				memset(&qc->result_tf, 0, sizeof(qc->result_tf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 				ata_eh_qc_retry(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 	/* make sure nr_active_links is zero after EH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	WARN_ON(ap->nr_active_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 	ap->nr_active_links = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813)  *	ata_do_eh - do standard error handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814)  *	@ap: host port to handle error for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816)  *	@prereset: prereset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817)  *	@softreset: softreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818)  *	@hardreset: hardreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819)  *	@postreset: postreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821)  *	Perform standard error handling sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) 	       ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) 	       ata_postreset_fn_t postreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 	ata_eh_autopsy(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 	ata_eh_report(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) 	rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 			    NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 		ata_for_each_dev(dev, &ap->link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 			ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 	ata_eh_finish(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847)  *	ata_std_error_handler - standard error handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848)  *	@ap: host port to handle error for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850)  *	Standard error handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) void ata_std_error_handler(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 	struct ata_port_operations *ops = ap->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 	ata_reset_fn_t hardreset = ops->hardreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 	/* ignore built-in hardreset if SCR access is not available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) 	if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 		hardreset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 	ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) EXPORT_SYMBOL_GPL(ata_std_error_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870)  *	ata_eh_handle_port_suspend - perform port suspend operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871)  *	@ap: port to suspend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)  *	Suspend @ap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) static void ata_eh_handle_port_suspend(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 	/* are we suspending? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) 	if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 	    ap->pm_mesg.event & PM_EVENT_RESUME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 	WARN_ON(ap->pflags & ATA_PFLAG_SUSPENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 	 * If we have a ZPODD attached, check its zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 	 * power ready status before the port is frozen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 	 * Only needed for runtime suspend.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 	if (PMSG_IS_AUTO(ap->pm_mesg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) 		ata_for_each_dev(dev, &ap->link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 			if (zpodd_dev_enabled(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) 				zpodd_on_suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 	/* tell ACPI we're suspending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 	rc = ata_acpi_on_suspend(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 	/* suspend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 	ata_eh_freeze_port(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 	if (ap->ops->port_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 		rc = ap->ops->port_suspend(ap, ap->pm_mesg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 	ata_acpi_set_state(ap, ap->pm_mesg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 	/* update the flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) 	ap->pflags &= ~ATA_PFLAG_PM_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 		ap->pflags |= ATA_PFLAG_SUSPENDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) 	else if (ap->pflags & ATA_PFLAG_FROZEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 		ata_port_schedule_eh(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935)  *	ata_eh_handle_port_resume - perform port resume operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936)  *	@ap: port to resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938)  *	Resume @ap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) static void ata_eh_handle_port_resume(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) 	/* are we resuming? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) 	if (!(ap->pflags & ATA_PFLAG_PM_PENDING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) 	    !(ap->pm_mesg.event & PM_EVENT_RESUME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) 	WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) 	 * Error timestamps are in jiffies which doesn't run while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) 	 * suspended and PHY events during resume isn't too uncommon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) 	 * When the two are combined, it can lead to unnecessary speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) 	 * downs if the machine is suspended and resumed repeatedly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) 	 * Clear error history.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) 	ata_for_each_link(link, ap, HOST_FIRST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) 		ata_for_each_dev(dev, link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) 			ata_ering_clear(&dev->ering);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) 	ata_acpi_set_state(ap, ap->pm_mesg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) 	if (ap->ops->port_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) 		ap->ops->port_resume(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) 	/* tell ACPI that we're resuming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) 	ata_acpi_on_resume(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) 	/* update the flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) 	ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) #endif /* CONFIG_PM */