Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc14c8db authored by Sujit Reddy Thumma's avatar Sujit Reddy Thumma
Browse files

scsi: ufs: issue request sense before sending Start Stop Unit



Issue request sense before sending START_STOP_UNIT to the device
well-known logical unit (w-lun) to make sure that the device w-lun
unit attention condition is cleared.

Change-Id: I3666b96624ee02278802f624df2ce33c5969d877
Signed-off-by: default avatarSujit Reddy Thumma <sthumma@codeaurora.org>
parent 6badacdb
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -4350,6 +4350,35 @@ static void ufshcd_hba_exit(struct ufs_hba *hba)
	}
}

static int
ufshcd_send_request_sense(struct ufs_hba *hba, struct scsi_device *sdp)
{
	unsigned char cmd[6] = {REQUEST_SENSE,
				0,
				0,
				0,
				SCSI_SENSE_BUFFERSIZE,
				0};
	char *buffer;
	int ret;

	buffer = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL);
	if (!buffer) {
		ret = -ENOMEM;
		goto out;
	}

	ret = scsi_execute_req_flags(sdp, cmd, DMA_FROM_DEVICE, buffer,
				SCSI_SENSE_BUFFERSIZE, NULL,
				msecs_to_jiffies(1000), 3, NULL, REQ_PM);
	if (ret)
		pr_err("%s: failed with err %d\n", __func__, ret);

	kfree(buffer);
out:
	return ret;
}

/**
 * ufshcd_set_dev_pwr_mode - sends START STOP UNIT command to set device
 *			     power mode
@@ -4370,6 +4399,12 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
	if (!sdp || !scsi_device_online(sdp))
		return -ENODEV;

	if (pwr_mode != UFS_ACTIVE_PWR_MODE) {
		ret = ufshcd_send_request_sense(hba, sdp);
		if (ret)
			goto out;
	}

	cmd[4] = pwr_mode << 4;

	/*
@@ -4391,7 +4426,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,

	if (!ret)
		hba->curr_dev_pwr_mode = pwr_mode;

out:
	return ret;
}