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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * libata-pmp.c - libata port multiplier support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2007  SUSE Linux Products GmbH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2007  Tejun Heo <teheo@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include "libata.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include "libata-transport.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) const struct ata_port_operations sata_pmp_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 	.inherits		= &sata_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) 	.pmp_prereset		= ata_std_prereset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) 	.pmp_hardreset		= sata_std_hardreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 	.pmp_postreset		= ata_std_postreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) 	.error_handler		= sata_pmp_error_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *	sata_pmp_read - read PMP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *	@link: link to read PMP register for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *	@reg: register to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *	@r_val: resulting value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *	Read PMP register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *	0 on success, AC_ERR_* mask on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) static unsigned int sata_pmp_read(struct ata_link *link, int reg, u32 *r_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	struct ata_device *pmp_dev = ap->link.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	ata_tf_init(pmp_dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	tf.command = ATA_CMD_PMP_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	tf.protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	tf.feature = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	tf.device = link->pmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	err_mask = ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 				     SATA_PMP_RW_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	if (err_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		return err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	*r_val = tf.nsect | tf.lbal << 8 | tf.lbam << 16 | tf.lbah << 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  *	sata_pmp_write - write PMP register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  *	@link: link to write PMP register for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  *	@reg: register to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  *	@r_val: value to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  *	Write PMP register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  *	0 on success, AC_ERR_* mask on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static unsigned int sata_pmp_write(struct ata_link *link, int reg, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	struct ata_device *pmp_dev = ap->link.device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	struct ata_taskfile tf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	ata_tf_init(pmp_dev, &tf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	tf.command = ATA_CMD_PMP_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	tf.protocol = ATA_PROT_NODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE | ATA_TFLAG_LBA48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	tf.feature = reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	tf.device = link->pmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	tf.nsect = val & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	tf.lbal = (val >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	tf.lbam = (val >> 16) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	tf.lbah = (val >> 24) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	return ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 				 SATA_PMP_RW_TIMEOUT);
^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) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  *	sata_pmp_qc_defer_cmd_switch - qc_defer for command switching PMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  *	@qc: ATA command in question
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  *	A host which has command switching PMP support cannot issue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *	commands to multiple links simultaneously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *	spin_lock_irqsave(host lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  *	ATA_DEFER_* if deferring is needed, 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	struct ata_link *link = qc->dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	if (ap->excl_link == NULL || ap->excl_link == link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		if (ap->nr_active_links == 0 || ata_link_active(link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 			qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 			return ata_std_qc_defer(qc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		ap->excl_link = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	return ATA_DEFER_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  *	sata_pmp_scr_read - read PSCR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  *	@link: ATA link to read PSCR for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  *	@reg: PSCR to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  *	@r_val: resulting value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  *	Read PSCR @reg into @r_val for @link, to be called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  *	ata_scr_read().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *r_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	if (reg > SATA_PMP_PSCR_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	err_mask = sata_pmp_read(link, reg, r_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		ata_link_warn(link, "failed to read SCR %d (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 			      reg, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)  *	sata_pmp_scr_write - write PSCR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159)  *	@link: ATA link to write PSCR for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160)  *	@reg: PSCR to write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161)  *	@val: value to be written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  *	Write @val to PSCR @reg for @link, to be called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  *	ata_scr_write() and ata_scr_write_flush().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	if (reg > SATA_PMP_PSCR_CONTROL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	err_mask = sata_pmp_write(link, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 		ata_link_warn(link, "failed to write SCR %d (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 			      reg, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  *	sata_pmp_set_lpm - configure LPM for a PMP link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  *	@link: PMP link to configure LPM for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)  *	@policy: target LPM policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)  *	@hints: LPM hints
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  *	Configure LPM for @link.  This function will contain any PMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  *	specific workarounds if necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  *	EH context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		     unsigned hints)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	return sata_link_scr_lpm(link, policy, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  *	sata_pmp_read_gscr - read GSCR block of SATA PMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  *	@dev: PMP device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  *	@gscr: buffer to read GSCR block into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)  *	Read selected PMP GSCRs from the PMP at @dev.  This will serve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)  *	as configuration and identification info for the PMP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static int sata_pmp_read_gscr(struct ata_device *dev, u32 *gscr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	static const int gscr_to_read[] = { 0, 1, 2, 32, 33, 64, 96 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	for (i = 0; i < ARRAY_SIZE(gscr_to_read); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		int reg = gscr_to_read[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 		err_mask = sata_pmp_read(dev->link, reg, &gscr[reg]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 			ata_dev_err(dev, "failed to read PMP GSCR[%d] (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 				    reg, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) static const char *sata_pmp_spec_rev_str(const u32 *gscr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	u32 rev = gscr[SATA_PMP_GSCR_REV];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	if (rev & (1 << 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		return "1.2";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	if (rev & (1 << 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		return "1.1";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	if (rev & (1 << 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		return "1.0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	return "<unknown>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) #define PMP_GSCR_SII_POL 129
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) static int sata_pmp_configure(struct ata_device *dev, int print_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	struct ata_port *ap = dev->link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	u32 *gscr = dev->gscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	u16 vendor = sata_pmp_gscr_vendor(gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	u16 devid = sata_pmp_gscr_devid(gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	unsigned int err_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	const char *reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	int nr_ports, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	nr_ports = sata_pmp_gscr_ports(gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	if (nr_ports <= 0 || nr_ports > SATA_PMP_MAX_PORTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		reason = "invalid nr_ports";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	if ((ap->flags & ATA_FLAG_AN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	    (gscr[SATA_PMP_GSCR_FEAT] & SATA_PMP_FEAT_NOTIFY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		dev->flags |= ATA_DFLAG_AN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	/* monitor SERR_PHYRDY_CHG on fan-out ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	err_mask = sata_pmp_write(dev->link, SATA_PMP_GSCR_ERROR_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 				  SERR_PHYRDY_CHG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		reason = "failed to write GSCR_ERROR_EN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	/* Disable sending Early R_OK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	 * With "cached read" HDD testing and multiple ports busy on a SATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	 * host controller, 3x26 PMP will very rarely drop a deferred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	 * R_OK that was intended for the host. Symptom will be all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	 * 5 drives under test will timeout, get reset, and recover.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	if (vendor == 0x1095 && (devid == 0x3726 || devid == 0x3826)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		u32 reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 		err_mask = sata_pmp_read(&ap->link, PMP_GSCR_SII_POL, &reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			reason = "failed to read Sil3x26 Private Register";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		reg &= ~0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		err_mask = sata_pmp_write(&ap->link, PMP_GSCR_SII_POL, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			reason = "failed to write Sil3x26 Private Register";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		}
^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) 	if (print_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		ata_dev_info(dev, "Port Multiplier %s, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			     "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 			     sata_pmp_spec_rev_str(gscr), vendor, devid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 			     sata_pmp_gscr_rev(gscr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 			     nr_ports, gscr[SATA_PMP_GSCR_FEAT_EN],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 			     gscr[SATA_PMP_GSCR_FEAT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		if (!(dev->flags & ATA_DFLAG_AN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			ata_dev_info(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 				"Asynchronous notification not supported, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 				"hotplug won't work on fan-out ports. Use warm-plug instead.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	ata_dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		    "failed to configure Port Multiplier (%s, Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		    reason, err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) static int sata_pmp_init_links (struct ata_port *ap, int nr_ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	struct ata_link *pmp_link = ap->pmp_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if (!pmp_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		pmp_link = kcalloc(SATA_PMP_MAX_PORTS, sizeof(pmp_link[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				   GFP_NOIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		if (!pmp_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		for (i = 0; i < SATA_PMP_MAX_PORTS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			ata_link_init(ap, &pmp_link[i], i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		ap->pmp_link = pmp_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		for (i = 0; i < SATA_PMP_MAX_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			err = ata_tlink_add(&pmp_link[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 				goto err_tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	for (i = 0; i < nr_ports; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		struct ata_link *link = &pmp_link[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		link->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		ehc->i.probe_mask |= ATA_ALL_DEVICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)   err_tlink:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		ata_tlink_delete(&pmp_link[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	kfree(pmp_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	ap->pmp_link = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) static void sata_pmp_quirks(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	u32 *gscr = ap->link.device->gscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	u16 vendor = sata_pmp_gscr_vendor(gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	u16 devid = sata_pmp_gscr_devid(gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	if (vendor == 0x1095 && (devid == 0x3726 || devid == 0x3826)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		/* sil3x26 quirks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			/* link reports offline after LPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			link->flags |= ATA_LFLAG_NO_LPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			 * Class code report is unreliable and SRST times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			 * out under certain configurations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			if (link->pmp < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				link->flags |= ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 					       ATA_LFLAG_ASSUME_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 			/* port 5 is for SEMB device and it doesn't like SRST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			if (link->pmp == 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 				link->flags |= ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 					       ATA_LFLAG_ASSUME_SEMB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	} else if (vendor == 0x1095 && devid == 0x4723) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		 * sil4723 quirks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		 * Link reports offline after LPM.  Class code report is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		 * unreliable.  SIMG PMPs never got SRST reliable and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		 * config device at port 2 locks up on SRST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		ata_for_each_link(link, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 			link->flags |= ATA_LFLAG_NO_LPM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 				       ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 				       ATA_LFLAG_ASSUME_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	} else if (vendor == 0x1095 && devid == 0x4726) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		/* sil4726 quirks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 			/* link reports offline after LPM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			link->flags |= ATA_LFLAG_NO_LPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			/* Class code report is unreliable and SRST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			 * times out under certain configurations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 			 * Config device can be at port 0 or 5 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			 * locks up on SRST.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 			if (link->pmp <= 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 				link->flags |= ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 					       ATA_LFLAG_ASSUME_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 			/* Port 6 is for SEMB device which doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 			 * like SRST either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 			if (link->pmp == 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 				link->flags |= ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 					       ATA_LFLAG_ASSUME_SEMB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	} else if (vendor == 0x1095 && (devid == 0x5723 || devid == 0x5733 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 					devid == 0x5734 || devid == 0x5744)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		/* sil5723/5744 quirks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		/* sil5723/5744 has either two or three downstream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		 * ports depending on operation mode.  The last port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		 * is empty if any actual IO device is available or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		 * occupied by a pseudo configuration device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		 * otherwise.  Don't try hard to recover it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		ap->pmp_link[ap->nr_pmp_links - 1].flags |= ATA_LFLAG_NO_RETRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	} else if (vendor == 0x197b && (devid == 0x2352 || devid == 0x0325)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		 * 0x2352: found in Thermaltake BlackX Duet, jmicron JMB350?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		 * 0x0325: jmicron JMB394.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			/* SRST breaks detection and disks get misclassified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 			 * LPM disabled to avoid potential problems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			link->flags |= ATA_LFLAG_NO_LPM |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 				       ATA_LFLAG_NO_SRST |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				       ATA_LFLAG_ASSUME_ATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	} else if (vendor == 0x11ab && devid == 0x4140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		/* Marvell 4140 quirks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			/* port 4 is for SEMB device and it doesn't like SRST */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			if (link->pmp == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				link->flags |= ATA_LFLAG_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473)  *	sata_pmp_attach - attach a SATA PMP device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474)  *	@dev: SATA PMP device to attach
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476)  *	Configure and attach SATA PMP device @dev.  This function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  *	also responsible for allocating and initializing PMP links.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) int sata_pmp_attach(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	struct ata_link *link = dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct ata_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	/* is it hanging off the right place? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	if (!sata_pmp_supported(ap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		ata_dev_err(dev, "host does not support Port Multiplier\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	if (!ata_is_host_link(link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		ata_dev_err(dev, "Port Multipliers cannot be nested\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	if (dev->devno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		ata_dev_err(dev, "Port Multiplier must be the first device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	WARN_ON(link->pmp != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	link->pmp = SATA_PMP_CTRL_PORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	/* read GSCR block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	rc = sata_pmp_read_gscr(dev, dev->gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	/* config PMP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	rc = sata_pmp_configure(dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	rc = sata_pmp_init_links(ap, sata_pmp_gscr_ports(dev->gscr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		ata_dev_info(dev, "failed to initialize PMP links\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	/* attach it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	WARN_ON(ap->nr_pmp_links);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	ap->nr_pmp_links = sata_pmp_gscr_ports(dev->gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	sata_pmp_quirks(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	if (ap->ops->pmp_attach)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		ap->ops->pmp_attach(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	ata_for_each_link(tlink, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		sata_link_init_spd(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	link->pmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  *	sata_pmp_detach - detach a SATA PMP device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  *	@dev: SATA PMP device to detach
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  *	Detach SATA PMP device @dev.  This function is also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)  *	responsible for deconfiguring PMP links.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) static void sata_pmp_detach(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	struct ata_link *link = dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	struct ata_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	ata_dev_info(dev, "Port Multiplier detaching\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	WARN_ON(!ata_is_host_link(link) || dev->devno ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 		link->pmp != SATA_PMP_CTRL_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	if (ap->ops->pmp_detach)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		ap->ops->pmp_detach(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	ata_for_each_link(tlink, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		ata_eh_detach_dev(tlink->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	ap->nr_pmp_links = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	link->pmp = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  *	sata_pmp_same_pmp - does new GSCR matches the configured PMP?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  *	@dev: PMP device to compare against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)  *	@new_gscr: GSCR block of the new device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)  *	Compare @new_gscr against @dev and determine whether @dev is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)  *	the PMP described by @new_gscr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592)  *	None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595)  *	1 if @dev matches @new_gscr, 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) static int sata_pmp_same_pmp(struct ata_device *dev, const u32 *new_gscr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	const u32 *old_gscr = dev->gscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	u16 old_vendor, new_vendor, old_devid, new_devid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int old_nr_ports, new_nr_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	old_vendor = sata_pmp_gscr_vendor(old_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	new_vendor = sata_pmp_gscr_vendor(new_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	old_devid = sata_pmp_gscr_devid(old_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	new_devid = sata_pmp_gscr_devid(new_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	old_nr_ports = sata_pmp_gscr_ports(old_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	new_nr_ports = sata_pmp_gscr_ports(new_gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (old_vendor != new_vendor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		ata_dev_info(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 			     "Port Multiplier vendor mismatch '0x%x' != '0x%x'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			     old_vendor, new_vendor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	if (old_devid != new_devid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		ata_dev_info(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			     "Port Multiplier device ID mismatch '0x%x' != '0x%x'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 			     old_devid, new_devid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	if (old_nr_ports != new_nr_ports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		ata_dev_info(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			     "Port Multiplier nr_ports mismatch '0x%x' != '0x%x'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			     old_nr_ports, new_nr_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return 0;
^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) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635)  *	sata_pmp_revalidate - revalidate SATA PMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636)  *	@dev: PMP device to revalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637)  *	@new_class: new class code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639)  *	Re-read GSCR block and make sure @dev is still attached to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640)  *	port and properly configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646)  *	0 on success, -errno otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) static int sata_pmp_revalidate(struct ata_device *dev, unsigned int new_class)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	struct ata_link *link = dev->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	u32 *gscr = (void *)ap->sector_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	ata_eh_about_to_do(link, NULL, ATA_EH_REVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	if (!ata_dev_enabled(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	/* wrong class? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	if (ata_class_enabled(new_class) && new_class != ATA_DEV_PMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	/* read GSCR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	rc = sata_pmp_read_gscr(dev, gscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	/* is the pmp still there? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	if (!sata_pmp_same_pmp(dev, gscr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	memcpy(dev->gscr, gscr, sizeof(gscr[0]) * SATA_PMP_GSCR_DWORDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	rc = sata_pmp_configure(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	ata_eh_done(link, NULL, ATA_EH_REVALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	DPRINTK("EXIT, rc=0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	ata_dev_err(dev, "PMP revalidation failed (errno=%d)\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	DPRINTK("EXIT, rc=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699)  *	sata_pmp_revalidate_quick - revalidate SATA PMP quickly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700)  *	@dev: PMP device to revalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702)  *	Make sure the attached PMP is accessible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  *	0 on success, -errno otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) static int sata_pmp_revalidate_quick(struct ata_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	u32 prod_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	err_mask = sata_pmp_read(dev->link, SATA_PMP_GSCR_PROD_ID, &prod_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		ata_dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			    "failed to read PMP product ID (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			    err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if (prod_id != dev->gscr[SATA_PMP_GSCR_PROD_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		ata_dev_err(dev, "PMP product ID mismatch\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		/* something weird is going on, request full PMP recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733)  *	sata_pmp_eh_recover_pmp - recover PMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734)  *	@ap: ATA port PMP is attached to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735)  *	@prereset: prereset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736)  *	@softreset: softreset method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737)  *	@hardreset: hardreset method
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)  *	@postreset: postreset method (can be NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  *	Recover PMP attached to @ap.  Recovery procedure is somewhat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741)  *	similar to that of ata_eh_recover() except that reset should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)  *	always be performed in hard->soft sequence and recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743)  *	failure results in PMP detachment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 		ata_reset_fn_t hardreset, ata_postreset_fn_t postreset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	struct ata_link *link = &ap->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	struct ata_eh_context *ehc = &link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	struct ata_device *dev = link->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	int tries = ATA_EH_PMP_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	int detach = 0, rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	int reval_failed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	DPRINTK("ENTER\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	if (dev->flags & ATA_DFLAG_DETACH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		detach = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	ehc->classes[0] = ATA_DEV_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	if (ehc->i.action & ATA_EH_RESET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		struct ata_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		/* reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		rc = ata_eh_reset(link, 0, prereset, softreset, hardreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 				  postreset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			ata_link_err(link, "failed to reset PMP, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		/* PMP is reset, SErrors cannot be trusted, scan all */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		ata_for_each_link(tlink, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			struct ata_eh_context *ehc = &tlink->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			ehc->i.probe_mask |= ATA_ALL_DEVICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	/* If revalidation is requested, revalidate and reconfigure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	 * otherwise, do quick revalidation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	if (ehc->i.action & ATA_EH_REVALIDATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		rc = sata_pmp_revalidate(dev, ehc->classes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		rc = sata_pmp_revalidate_quick(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		tries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		if (rc == -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			ehc->i.probe_mask |= ATA_ALL_DEVICES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			detach = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			/* give it just two more chances */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			tries = min(tries, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		if (tries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			/* consecutive revalidation failures? speed down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 			if (reval_failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 				sata_down_spd_limit(link, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 				reval_failed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			ata_dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 				    "failed to recover PMP after %d tries, giving up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				    ATA_EH_PMP_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	/* okay, PMP resurrected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	ehc->i.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	DPRINTK("EXIT, rc=0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	sata_pmp_detach(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	if (detach)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		ata_eh_detach_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	DPRINTK("EXIT, rc=%d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		if (!(link->flags & ATA_LFLAG_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		/* Some PMPs require hardreset sequence to get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		 * SError.N working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		sata_link_hardreset(link, sata_deb_timing_normal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 				ata_deadline(jiffies, ATA_TMOUT_INTERNAL_QUICK),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 				NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		/* unconditionally clear SError.N */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		rc = sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 			ata_link_err(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 				     "failed to clear SError.N (errno=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	struct ata_port *ap = link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	if (link_tries[link->pmp] && --link_tries[link->pmp])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	/* disable this link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	if (!(link->flags & ATA_LFLAG_DISABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		ata_link_warn(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 			"failed to recover link after %d tries, disabling\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			ATA_EH_PMP_LINK_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		spin_lock_irqsave(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		link->flags |= ATA_LFLAG_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		spin_unlock_irqrestore(ap->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	ata_dev_disable(link->device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	link->eh_context.i.action = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)  *	sata_pmp_eh_recover - recover PMP-enabled port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)  *	@ap: ATA port to recover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  *	Drive EH recovery operation for PMP enabled port @ap.  This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  *	function recovers host and PMP ports with proper retrials and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)  *	fallbacks.  Actual recovery operations are performed using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915)  *	ata_eh_recover() and sata_pmp_eh_recover_pmp().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  *	RETURNS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)  *	0 on success, -errno on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) static int sata_pmp_eh_recover(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	struct ata_port_operations *ops = ap->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	struct ata_link *pmp_link = &ap->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	struct ata_device *pmp_dev = pmp_link->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	struct ata_eh_context *pmp_ehc = &pmp_link->eh_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	u32 *gscr = pmp_dev->gscr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	struct ata_link *link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	unsigned int err_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	u32 gscr_error, sntf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	int cnt, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	pmp_tries = ATA_EH_PMP_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	ata_for_each_link(link, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941)  retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	/* PMP attached? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (!sata_pmp_attached(ap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 				    ops->hardreset, ops->postreset, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			ata_for_each_dev(dev, &ap->link, ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 				ata_dev_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		if (pmp_dev->class != ATA_DEV_PMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		/* new PMP online */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		ata_for_each_link(link, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 			link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		/* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	/* recover pmp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	rc = sata_pmp_eh_recover_pmp(ap, ops->prereset, ops->softreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 				     ops->hardreset, ops->postreset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		goto pmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	/* PHY event notification can disturb reset and other recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	 * operations.  Turn it off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	if (gscr[SATA_PMP_GSCR_FEAT_EN] & SATA_PMP_FEAT_NOTIFY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		gscr[SATA_PMP_GSCR_FEAT_EN] &= ~SATA_PMP_FEAT_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		err_mask = sata_pmp_write(pmp_link, SATA_PMP_GSCR_FEAT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 					  gscr[SATA_PMP_GSCR_FEAT_EN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			ata_link_warn(pmp_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 				"failed to disable NOTIFY (err_mask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 				err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			goto pmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	/* handle disabled links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	rc = sata_pmp_eh_handle_disabled_links(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		goto pmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	/* recover links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	rc = ata_eh_recover(ap, ops->pmp_prereset, ops->pmp_softreset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 			    ops->pmp_hardreset, ops->pmp_postreset, &link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		goto link_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	/* clear SNotification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	 * If LPM is active on any fan-out port, hotplug wouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	 * work.  Return w/ PHY event notification disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	ata_for_each_link(link, ap, EDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		if (link->lpm_policy > ATA_LPM_MAX_POWER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	 * Connection status might have changed while resetting other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 * links, enable notification and check SATA_PMP_GSCR_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * before returning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	/* enable notification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	if (pmp_dev->flags & ATA_DFLAG_AN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		err_mask = sata_pmp_write(pmp_link, SATA_PMP_GSCR_FEAT_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 					  gscr[SATA_PMP_GSCR_FEAT_EN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 		if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			ata_dev_err(pmp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				    "failed to write PMP_FEAT_EN (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				    err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 			goto pmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		}
^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) 	/* check GSCR_ERROR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	err_mask = sata_pmp_read(pmp_link, SATA_PMP_GSCR_ERROR, &gscr_error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (err_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		ata_dev_err(pmp_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 			    "failed to read PMP_GSCR_ERROR (Emask=0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 			    err_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		goto pmp_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	ata_for_each_link(link, ap, EDGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		if (!(gscr_error & (1 << link->pmp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		if (sata_pmp_handle_link_fail(link, link_tries)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 			ata_ehi_hotplugged(&link->eh_context.i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 			cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 			ata_link_warn(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 				"PHY status changed but maxed out on retries, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 			ata_link_warn(link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 				"Manually issue scan to resume this link\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		ata_port_info(ap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			"PMP SError.N set for some ports, repeating recovery\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)  link_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (sata_pmp_handle_link_fail(link, link_tries)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		pmp_ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	/* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  pmp_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	/* Control always ends up here after detaching PMP.  Shut up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	 * and return if we're unloading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	if (ap->pflags & ATA_PFLAG_UNLOADING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	if (!sata_pmp_attached(ap))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (--pmp_tries) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		pmp_ehc->i.action |= ATA_EH_RESET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	ata_port_err(ap, "failed to recover PMP after %d tries, giving up\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		     ATA_EH_PMP_TRIES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	sata_pmp_detach(pmp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	ata_dev_disable(pmp_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)  *	sata_pmp_error_handler - do standard error handling for PMP-enabled host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)  *	@ap: host port to handle error for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)  *	Perform standard error handling sequence for PMP-enabled host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)  *	@ap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)  *	LOCKING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)  *	Kernel thread context (may sleep).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) void sata_pmp_error_handler(struct ata_port *ap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	ata_eh_autopsy(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	ata_eh_report(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	sata_pmp_eh_recover(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	ata_eh_finish(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) EXPORT_SYMBOL_GPL(sata_pmp_port_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) EXPORT_SYMBOL_GPL(sata_pmp_error_handler);