1

SCSI fixes on 20241019

Fixes all in drivers. The largest is the mpi3mr which corrects a phy
 count limit that should only apply to the controller but was being
 incorrectly applied to expander phys.
 
 Signed-off-by: James E.J. Bottomley <James.Bottomley@HansenPartnership.com>
 -----BEGIN PGP SIGNATURE-----
 
 iJwEABMIAEQWIQTnYEDbdso9F2cI+arnQslM7pishQUCZxQINSYcamFtZXMuYm90
 dG9tbGV5QGhhbnNlbnBhcnRuZXJzaGlwLmNvbQAKCRDnQslM7pishfuiAP9+gxzU
 MYpyNFYmS8iwbma+wagKMr2ZxpiIAnQIukBtugD7Baqw7YjNbAPtCcQMgC96y8ac
 X7zeMkLTyMqkaIjOQFk=
 =eHKZ
 -----END PGP SIGNATURE-----

Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi

Pull SCSI fixes from James Bottomley:
 "Fixes all in drivers. The largest is the mpi3mr which corrects a phy
  count limit that should only apply to the controller but was being
  incorrectly applied to expander phys"

* tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi:
  scsi: target: core: Fix null-ptr-deref in target_alloc_device()
  scsi: mpi3mr: Validate SAS port assignments
  scsi: ufs: core: Set SDEV_OFFLINE when UFS is shut down
  scsi: ufs: core: Requeue aborted request
  scsi: ufs: core: Fix the issue of ICU failure
This commit is contained in:
Linus Torvalds 2024-10-19 12:52:19 -07:00
commit 531643fcd9
5 changed files with 45 additions and 42 deletions

View File

@ -542,8 +542,8 @@ struct mpi3mr_hba_port {
* @port_list: List of ports belonging to a SAS node * @port_list: List of ports belonging to a SAS node
* @num_phys: Number of phys associated with port * @num_phys: Number of phys associated with port
* @marked_responding: used while refresing the sas ports * @marked_responding: used while refresing the sas ports
* @lowest_phy: lowest phy ID of current sas port * @lowest_phy: lowest phy ID of current sas port, valid for controller port
* @phy_mask: phy_mask of current sas port * @phy_mask: phy_mask of current sas port, valid for controller port
* @hba_port: HBA port entry * @hba_port: HBA port entry
* @remote_identify: Attached device identification * @remote_identify: Attached device identification
* @rphy: SAS transport layer rphy object * @rphy: SAS transport layer rphy object

View File

@ -590,12 +590,13 @@ static enum sas_linkrate mpi3mr_convert_phy_link_rate(u8 link_rate)
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @mr_sas_port: Internal Port object * @mr_sas_port: Internal Port object
* @mr_sas_phy: Internal Phy object * @mr_sas_phy: Internal Phy object
* @host_node: Flag to indicate this is a host_node
* *
* Return: None. * Return: None.
*/ */
static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc, static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
struct mpi3mr_sas_port *mr_sas_port, struct mpi3mr_sas_port *mr_sas_port,
struct mpi3mr_sas_phy *mr_sas_phy) struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
{ {
u64 sas_address = mr_sas_port->remote_identify.sas_address; u64 sas_address = mr_sas_port->remote_identify.sas_address;
@ -605,9 +606,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
list_del(&mr_sas_phy->port_siblings); list_del(&mr_sas_phy->port_siblings);
mr_sas_port->num_phys--; mr_sas_port->num_phys--;
mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id);
if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id) if (host_node) {
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1; mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id);
if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
}
sas_port_delete_phy(mr_sas_port->port, mr_sas_phy->phy); sas_port_delete_phy(mr_sas_port->port, mr_sas_phy->phy);
mr_sas_phy->phy_belongs_to_port = 0; mr_sas_phy->phy_belongs_to_port = 0;
} }
@ -617,12 +622,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @mr_sas_port: Internal Port object * @mr_sas_port: Internal Port object
* @mr_sas_phy: Internal Phy object * @mr_sas_phy: Internal Phy object
* @host_node: Flag to indicate this is a host_node
* *
* Return: None. * Return: None.
*/ */
static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc, static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
struct mpi3mr_sas_port *mr_sas_port, struct mpi3mr_sas_port *mr_sas_port,
struct mpi3mr_sas_phy *mr_sas_phy) struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
{ {
u64 sas_address = mr_sas_port->remote_identify.sas_address; u64 sas_address = mr_sas_port->remote_identify.sas_address;
@ -632,9 +638,12 @@ static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
list_add_tail(&mr_sas_phy->port_siblings, &mr_sas_port->phy_list); list_add_tail(&mr_sas_phy->port_siblings, &mr_sas_port->phy_list);
mr_sas_port->num_phys++; mr_sas_port->num_phys++;
mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id); if (host_node) {
if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy) mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id);
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
}
sas_port_add_phy(mr_sas_port->port, mr_sas_phy->phy); sas_port_add_phy(mr_sas_port->port, mr_sas_phy->phy);
mr_sas_phy->phy_belongs_to_port = 1; mr_sas_phy->phy_belongs_to_port = 1;
} }
@ -675,7 +684,7 @@ static void mpi3mr_add_phy_to_an_existing_port(struct mpi3mr_ioc *mrioc,
if (srch_phy == mr_sas_phy) if (srch_phy == mr_sas_phy)
return; return;
} }
mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy); mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy, mr_sas_node->host_node);
return; return;
} }
} }
@ -736,7 +745,7 @@ static void mpi3mr_del_phy_from_an_existing_port(struct mpi3mr_ioc *mrioc,
mpi3mr_delete_sas_port(mrioc, mr_sas_port); mpi3mr_delete_sas_port(mrioc, mr_sas_port);
else else
mpi3mr_delete_sas_phy(mrioc, mr_sas_port, mpi3mr_delete_sas_phy(mrioc, mr_sas_port,
mr_sas_phy); mr_sas_phy, mr_sas_node->host_node);
return; return;
} }
} }
@ -1028,7 +1037,7 @@ mpi3mr_alloc_hba_port(struct mpi3mr_ioc *mrioc, u16 port_id)
/** /**
* mpi3mr_get_hba_port_by_id - find hba port by id * mpi3mr_get_hba_port_by_id - find hba port by id
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* @port_id - Port ID to search * @port_id: Port ID to search
* *
* Return: mpi3mr_hba_port reference for the matched port * Return: mpi3mr_hba_port reference for the matched port
*/ */
@ -1367,7 +1376,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node, mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
mr_sas_port->remote_identify.sas_address, hba_port); mr_sas_port->remote_identify.sas_address, hba_port);
if (mr_sas_node->num_phys >= sizeof(mr_sas_port->phy_mask) * 8) if (mr_sas_node->host_node && mr_sas_node->num_phys >=
sizeof(mr_sas_port->phy_mask) * 8)
ioc_info(mrioc, "max port count %u could be too high\n", ioc_info(mrioc, "max port count %u could be too high\n",
mr_sas_node->num_phys); mr_sas_node->num_phys);
@ -1377,7 +1387,7 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
(mr_sas_node->phy[i].hba_port != hba_port)) (mr_sas_node->phy[i].hba_port != hba_port))
continue; continue;
if (i >= sizeof(mr_sas_port->phy_mask) * 8) { if (mr_sas_node->host_node && (i >= sizeof(mr_sas_port->phy_mask) * 8)) {
ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n", ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n",
i, sizeof(mr_sas_port->phy_mask) * 8); i, sizeof(mr_sas_port->phy_mask) * 8);
goto out_fail; goto out_fail;
@ -1385,7 +1395,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
list_add_tail(&mr_sas_node->phy[i].port_siblings, list_add_tail(&mr_sas_node->phy[i].port_siblings,
&mr_sas_port->phy_list); &mr_sas_port->phy_list);
mr_sas_port->num_phys++; mr_sas_port->num_phys++;
mr_sas_port->phy_mask |= (1 << i); if (mr_sas_node->host_node)
mr_sas_port->phy_mask |= (1 << i);
} }
if (!mr_sas_port->num_phys) { if (!mr_sas_port->num_phys) {
@ -1394,7 +1405,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
goto out_fail; goto out_fail;
} }
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1; if (mr_sas_node->host_node)
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
if (mr_sas_port->remote_identify.device_type == SAS_END_DEVICE) { if (mr_sas_port->remote_identify.device_type == SAS_END_DEVICE) {
tgtdev = mpi3mr_get_tgtdev_by_addr(mrioc, tgtdev = mpi3mr_get_tgtdev_by_addr(mrioc,

View File

@ -691,7 +691,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
dev->queues = kcalloc(nr_cpu_ids, sizeof(*dev->queues), GFP_KERNEL); dev->queues = kcalloc(nr_cpu_ids, sizeof(*dev->queues), GFP_KERNEL);
if (!dev->queues) { if (!dev->queues) {
dev->transport->free_device(dev); hba->backend->ops->free_device(dev);
return NULL; return NULL;
} }

View File

@ -539,7 +539,7 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
struct scsi_cmnd *cmd = lrbp->cmd; struct scsi_cmnd *cmd = lrbp->cmd;
struct ufs_hw_queue *hwq; struct ufs_hw_queue *hwq;
void __iomem *reg, *opr_sqd_base; void __iomem *reg, *opr_sqd_base;
u32 nexus, id, val; u32 nexus, id, val, rtc;
int err; int err;
if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_RTC) if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_RTC)
@ -569,17 +569,18 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
opr_sqd_base = mcq_opr_base(hba, OPR_SQD, id); opr_sqd_base = mcq_opr_base(hba, OPR_SQD, id);
writel(nexus, opr_sqd_base + REG_SQCTI); writel(nexus, opr_sqd_base + REG_SQCTI);
/* SQRTCy.ICU = 1 */ /* Initiate Cleanup */
writel(SQ_ICU, opr_sqd_base + REG_SQRTC); writel(readl(opr_sqd_base + REG_SQRTC) | SQ_ICU,
opr_sqd_base + REG_SQRTC);
/* Poll SQRTSy.CUS = 1. Return result from SQRTSy.RTC */ /* Poll SQRTSy.CUS = 1. Return result from SQRTSy.RTC */
reg = opr_sqd_base + REG_SQRTS; reg = opr_sqd_base + REG_SQRTS;
err = read_poll_timeout(readl, val, val & SQ_CUS, 20, err = read_poll_timeout(readl, val, val & SQ_CUS, 20,
MCQ_POLL_US, false, reg); MCQ_POLL_US, false, reg);
if (err) rtc = FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg));
dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%ld\n", if (err || rtc)
__func__, id, task_tag, dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%d RTC=%d\n",
FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg))); __func__, id, task_tag, err, rtc);
if (ufshcd_mcq_sq_start(hba, hwq)) if (ufshcd_mcq_sq_start(hba, hwq))
err = -ETIMEDOUT; err = -ETIMEDOUT;

View File

@ -5416,10 +5416,12 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
} }
break; break;
case OCS_ABORTED: case OCS_ABORTED:
result |= DID_ABORT << 16;
break;
case OCS_INVALID_COMMAND_STATUS: case OCS_INVALID_COMMAND_STATUS:
result |= DID_REQUEUE << 16; result |= DID_REQUEUE << 16;
dev_warn(hba->dev,
"OCS %s from controller for tag %d\n",
(ocs == OCS_ABORTED ? "aborted" : "invalid"),
lrbp->task_tag);
break; break;
case OCS_INVALID_CMD_TABLE_ATTR: case OCS_INVALID_CMD_TABLE_ATTR:
case OCS_INVALID_PRDT_ATTR: case OCS_INVALID_PRDT_ATTR:
@ -6465,26 +6467,12 @@ static bool ufshcd_abort_one(struct request *rq, void *priv)
struct scsi_device *sdev = cmd->device; struct scsi_device *sdev = cmd->device;
struct Scsi_Host *shost = sdev->host; struct Scsi_Host *shost = sdev->host;
struct ufs_hba *hba = shost_priv(shost); struct ufs_hba *hba = shost_priv(shost);
struct ufshcd_lrb *lrbp = &hba->lrb[tag];
struct ufs_hw_queue *hwq;
unsigned long flags;
*ret = ufshcd_try_to_abort_task(hba, tag); *ret = ufshcd_try_to_abort_task(hba, tag);
dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag, dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag,
hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1, hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1,
*ret ? "failed" : "succeeded"); *ret ? "failed" : "succeeded");
/* Release cmd in MCQ mode if abort succeeds */
if (hba->mcq_enabled && (*ret == 0)) {
hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd));
if (!hwq)
return 0;
spin_lock_irqsave(&hwq->cq_lock, flags);
if (ufshcd_cmd_inflight(lrbp->cmd))
ufshcd_release_scsi_cmd(hba, lrbp);
spin_unlock_irqrestore(&hwq->cq_lock, flags);
}
return *ret == 0; return *ret == 0;
} }
@ -10209,7 +10197,9 @@ static void ufshcd_wl_shutdown(struct device *dev)
shost_for_each_device(sdev, hba->host) { shost_for_each_device(sdev, hba->host) {
if (sdev == hba->ufs_device_wlun) if (sdev == hba->ufs_device_wlun)
continue; continue;
scsi_device_quiesce(sdev); mutex_lock(&sdev->state_mutex);
scsi_device_set_state(sdev, SDEV_OFFLINE);
mutex_unlock(&sdev->state_mutex);
} }
__ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM); __ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM);