Skip to content

Commit 531643f

Browse files
committed
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
2 parents 06526da + fca6cae commit 531643f

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

drivers/scsi/mpi3mr/mpi3mr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ struct mpi3mr_hba_port {
542542
* @port_list: List of ports belonging to a SAS node
543543
* @num_phys: Number of phys associated with port
544544
* @marked_responding: used while refresing the sas ports
545-
* @lowest_phy: lowest phy ID of current sas port
546-
* @phy_mask: phy_mask of current sas port
545+
* @lowest_phy: lowest phy ID of current sas port, valid for controller port
546+
* @phy_mask: phy_mask of current sas port, valid for controller port
547547
* @hba_port: HBA port entry
548548
* @remote_identify: Attached device identification
549549
* @rphy: SAS transport layer rphy object

drivers/scsi/mpi3mr/mpi3mr_transport.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,13 @@ static enum sas_linkrate mpi3mr_convert_phy_link_rate(u8 link_rate)
590590
* @mrioc: Adapter instance reference
591591
* @mr_sas_port: Internal Port object
592592
* @mr_sas_phy: Internal Phy object
593+
* @host_node: Flag to indicate this is a host_node
593594
*
594595
* Return: None.
595596
*/
596597
static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
597598
struct mpi3mr_sas_port *mr_sas_port,
598-
struct mpi3mr_sas_phy *mr_sas_phy)
599+
struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
599600
{
600601
u64 sas_address = mr_sas_port->remote_identify.sas_address;
601602

@@ -605,9 +606,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
605606

606607
list_del(&mr_sas_phy->port_siblings);
607608
mr_sas_port->num_phys--;
608-
mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id);
609-
if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id)
610-
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
609+
610+
if (host_node) {
611+
mr_sas_port->phy_mask &= ~(1 << mr_sas_phy->phy_id);
612+
613+
if (mr_sas_port->lowest_phy == mr_sas_phy->phy_id)
614+
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
615+
}
611616
sas_port_delete_phy(mr_sas_port->port, mr_sas_phy->phy);
612617
mr_sas_phy->phy_belongs_to_port = 0;
613618
}
@@ -617,12 +622,13 @@ static void mpi3mr_delete_sas_phy(struct mpi3mr_ioc *mrioc,
617622
* @mrioc: Adapter instance reference
618623
* @mr_sas_port: Internal Port object
619624
* @mr_sas_phy: Internal Phy object
625+
* @host_node: Flag to indicate this is a host_node
620626
*
621627
* Return: None.
622628
*/
623629
static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
624630
struct mpi3mr_sas_port *mr_sas_port,
625-
struct mpi3mr_sas_phy *mr_sas_phy)
631+
struct mpi3mr_sas_phy *mr_sas_phy, u8 host_node)
626632
{
627633
u64 sas_address = mr_sas_port->remote_identify.sas_address;
628634

@@ -632,9 +638,12 @@ static void mpi3mr_add_sas_phy(struct mpi3mr_ioc *mrioc,
632638

633639
list_add_tail(&mr_sas_phy->port_siblings, &mr_sas_port->phy_list);
634640
mr_sas_port->num_phys++;
635-
mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id);
636-
if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy)
637-
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
641+
if (host_node) {
642+
mr_sas_port->phy_mask |= (1 << mr_sas_phy->phy_id);
643+
644+
if (mr_sas_phy->phy_id < mr_sas_port->lowest_phy)
645+
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
646+
}
638647
sas_port_add_phy(mr_sas_port->port, mr_sas_phy->phy);
639648
mr_sas_phy->phy_belongs_to_port = 1;
640649
}
@@ -675,7 +684,7 @@ static void mpi3mr_add_phy_to_an_existing_port(struct mpi3mr_ioc *mrioc,
675684
if (srch_phy == mr_sas_phy)
676685
return;
677686
}
678-
mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy);
687+
mpi3mr_add_sas_phy(mrioc, mr_sas_port, mr_sas_phy, mr_sas_node->host_node);
679688
return;
680689
}
681690
}
@@ -736,7 +745,7 @@ static void mpi3mr_del_phy_from_an_existing_port(struct mpi3mr_ioc *mrioc,
736745
mpi3mr_delete_sas_port(mrioc, mr_sas_port);
737746
else
738747
mpi3mr_delete_sas_phy(mrioc, mr_sas_port,
739-
mr_sas_phy);
748+
mr_sas_phy, mr_sas_node->host_node);
740749
return;
741750
}
742751
}
@@ -1028,7 +1037,7 @@ mpi3mr_alloc_hba_port(struct mpi3mr_ioc *mrioc, u16 port_id)
10281037
/**
10291038
* mpi3mr_get_hba_port_by_id - find hba port by id
10301039
* @mrioc: Adapter instance reference
1031-
* @port_id - Port ID to search
1040+
* @port_id: Port ID to search
10321041
*
10331042
* Return: mpi3mr_hba_port reference for the matched port
10341043
*/
@@ -1367,7 +1376,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
13671376
mpi3mr_sas_port_sanity_check(mrioc, mr_sas_node,
13681377
mr_sas_port->remote_identify.sas_address, hba_port);
13691378

1370-
if (mr_sas_node->num_phys >= sizeof(mr_sas_port->phy_mask) * 8)
1379+
if (mr_sas_node->host_node && mr_sas_node->num_phys >=
1380+
sizeof(mr_sas_port->phy_mask) * 8)
13711381
ioc_info(mrioc, "max port count %u could be too high\n",
13721382
mr_sas_node->num_phys);
13731383

@@ -1377,15 +1387,16 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
13771387
(mr_sas_node->phy[i].hba_port != hba_port))
13781388
continue;
13791389

1380-
if (i >= sizeof(mr_sas_port->phy_mask) * 8) {
1390+
if (mr_sas_node->host_node && (i >= sizeof(mr_sas_port->phy_mask) * 8)) {
13811391
ioc_warn(mrioc, "skipping port %u, max allowed value is %zu\n",
13821392
i, sizeof(mr_sas_port->phy_mask) * 8);
13831393
goto out_fail;
13841394
}
13851395
list_add_tail(&mr_sas_node->phy[i].port_siblings,
13861396
&mr_sas_port->phy_list);
13871397
mr_sas_port->num_phys++;
1388-
mr_sas_port->phy_mask |= (1 << i);
1398+
if (mr_sas_node->host_node)
1399+
mr_sas_port->phy_mask |= (1 << i);
13891400
}
13901401

13911402
if (!mr_sas_port->num_phys) {
@@ -1394,7 +1405,8 @@ static struct mpi3mr_sas_port *mpi3mr_sas_port_add(struct mpi3mr_ioc *mrioc,
13941405
goto out_fail;
13951406
}
13961407

1397-
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
1408+
if (mr_sas_node->host_node)
1409+
mr_sas_port->lowest_phy = ffs(mr_sas_port->phy_mask) - 1;
13981410

13991411
if (mr_sas_port->remote_identify.device_type == SAS_END_DEVICE) {
14001412
tgtdev = mpi3mr_get_tgtdev_by_addr(mrioc,

drivers/target/target_core_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
691691

692692
dev->queues = kcalloc(nr_cpu_ids, sizeof(*dev->queues), GFP_KERNEL);
693693
if (!dev->queues) {
694-
dev->transport->free_device(dev);
694+
hba->backend->ops->free_device(dev);
695695
return NULL;
696696
}
697697

drivers/ufs/core/ufs-mcq.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
539539
struct scsi_cmnd *cmd = lrbp->cmd;
540540
struct ufs_hw_queue *hwq;
541541
void __iomem *reg, *opr_sqd_base;
542-
u32 nexus, id, val;
542+
u32 nexus, id, val, rtc;
543543
int err;
544544

545545
if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_RTC)
@@ -569,17 +569,18 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
569569
opr_sqd_base = mcq_opr_base(hba, OPR_SQD, id);
570570
writel(nexus, opr_sqd_base + REG_SQCTI);
571571

572-
/* SQRTCy.ICU = 1 */
573-
writel(SQ_ICU, opr_sqd_base + REG_SQRTC);
572+
/* Initiate Cleanup */
573+
writel(readl(opr_sqd_base + REG_SQRTC) | SQ_ICU,
574+
opr_sqd_base + REG_SQRTC);
574575

575576
/* Poll SQRTSy.CUS = 1. Return result from SQRTSy.RTC */
576577
reg = opr_sqd_base + REG_SQRTS;
577578
err = read_poll_timeout(readl, val, val & SQ_CUS, 20,
578579
MCQ_POLL_US, false, reg);
579-
if (err)
580-
dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%ld\n",
581-
__func__, id, task_tag,
582-
FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg)));
580+
rtc = FIELD_GET(SQ_ICU_ERR_CODE_MASK, readl(reg));
581+
if (err || rtc)
582+
dev_err(hba->dev, "%s: failed. hwq=%d, tag=%d err=%d RTC=%d\n",
583+
__func__, id, task_tag, err, rtc);
583584

584585
if (ufshcd_mcq_sq_start(hba, hwq))
585586
err = -ETIMEDOUT;

drivers/ufs/core/ufshcd.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5416,10 +5416,12 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp,
54165416
}
54175417
break;
54185418
case OCS_ABORTED:
5419-
result |= DID_ABORT << 16;
5420-
break;
54215419
case OCS_INVALID_COMMAND_STATUS:
54225420
result |= DID_REQUEUE << 16;
5421+
dev_warn(hba->dev,
5422+
"OCS %s from controller for tag %d\n",
5423+
(ocs == OCS_ABORTED ? "aborted" : "invalid"),
5424+
lrbp->task_tag);
54235425
break;
54245426
case OCS_INVALID_CMD_TABLE_ATTR:
54255427
case OCS_INVALID_PRDT_ATTR:
@@ -6465,26 +6467,12 @@ static bool ufshcd_abort_one(struct request *rq, void *priv)
64656467
struct scsi_device *sdev = cmd->device;
64666468
struct Scsi_Host *shost = sdev->host;
64676469
struct ufs_hba *hba = shost_priv(shost);
6468-
struct ufshcd_lrb *lrbp = &hba->lrb[tag];
6469-
struct ufs_hw_queue *hwq;
6470-
unsigned long flags;
64716470

64726471
*ret = ufshcd_try_to_abort_task(hba, tag);
64736472
dev_err(hba->dev, "Aborting tag %d / CDB %#02x %s\n", tag,
64746473
hba->lrb[tag].cmd ? hba->lrb[tag].cmd->cmnd[0] : -1,
64756474
*ret ? "failed" : "succeeded");
64766475

6477-
/* Release cmd in MCQ mode if abort succeeds */
6478-
if (hba->mcq_enabled && (*ret == 0)) {
6479-
hwq = ufshcd_mcq_req_to_hwq(hba, scsi_cmd_to_rq(lrbp->cmd));
6480-
if (!hwq)
6481-
return 0;
6482-
spin_lock_irqsave(&hwq->cq_lock, flags);
6483-
if (ufshcd_cmd_inflight(lrbp->cmd))
6484-
ufshcd_release_scsi_cmd(hba, lrbp);
6485-
spin_unlock_irqrestore(&hwq->cq_lock, flags);
6486-
}
6487-
64886476
return *ret == 0;
64896477
}
64906478

@@ -10209,7 +10197,9 @@ static void ufshcd_wl_shutdown(struct device *dev)
1020910197
shost_for_each_device(sdev, hba->host) {
1021010198
if (sdev == hba->ufs_device_wlun)
1021110199
continue;
10212-
scsi_device_quiesce(sdev);
10200+
mutex_lock(&sdev->state_mutex);
10201+
scsi_device_set_state(sdev, SDEV_OFFLINE);
10202+
mutex_unlock(&sdev->state_mutex);
1021310203
}
1021410204
__ufshcd_wl_suspend(hba, UFS_SHUTDOWN_PM);
1021510205

0 commit comments

Comments
 (0)