From patchwork Mon Apr 19 11:01:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kashyap Desai X-Patchwork-Id: 424266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE, SPF_PASS, T_TVD_MIME_NO_HEADERS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C9AC433B4 for ; Mon, 19 Apr 2021 11:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E14861166 for ; Mon, 19 Apr 2021 11:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234144AbhDSLDV (ORCPT ); Mon, 19 Apr 2021 07:03:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238539AbhDSLDR (ORCPT ); Mon, 19 Apr 2021 07:03:17 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 232F3C06174A for ; Mon, 19 Apr 2021 04:02:47 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id b8-20020a17090a5508b029014d0fbe9b64so20141273pji.5 for ; Mon, 19 Apr 2021 04:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=naLXqsO7+QgyZjN9G8xTGnkGK6TKh+lRqwFoI6nBn/U=; b=Ne3HTHfhXN8Pr5W9/pMRytkAUh4J5FKrbKpfObqAiM7d60NWlYA+SAlkxk2mMQlMU2 V595Aqwf+UHnvvHSEGpWcr2M+8dfkbka/7+LfrSKYG8qaD7yv1PkaePMRiypX+pTCe3Z 3Ewjbf4ltXepV6PWFtG9DmaQrr4/FuiCefcO8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=naLXqsO7+QgyZjN9G8xTGnkGK6TKh+lRqwFoI6nBn/U=; b=QoYPHcF8WDVWbVuEdHt3Ln8ZsqcDrzxuyeaFK8y+7dkYNsQ/gD5jxLa8Il4VPk7KKo Xo0SIcHL/KqvT8FFre/z4KrxZ0QtUf21wdNHxOf9TfVbzP51yz4dOr8syRkSVxHk38nH Dp6YLG+xXVKJDekj3fjaJmsshFpZhoR+dE1hvfsIBfC4ViliFylIqkF+kn48wUMy62jf UOnH6TWl2pQ3RvGGxYpGjV+iAjIm5hel9D3cHEj3tCg4i5pCWA+wy4cADDOCFfSUOMBE ZEbQYyNNsKZ+odxKSjAnzjZ1IMFeMLexisHR9dCFi1f7eiF4BwHm88CpxfpjqFRhDL+t oEVg== X-Gm-Message-State: AOAM530GCjaugiwMkDiEIiLf2MFkzE1X6dzgjymSXZS7Z1CIQEKPyX/3 nAPufNOcokx5iqX9ZIlTwbhYZifWMGld4mzcb7plaPQdZMnjJ+p0hgjpdJELSmCiZi76FUrS7lu cBFZR+Br9lG71IeTmTFF2TpoepTPldOMhzJQ0MkdrmWQSwGeWNRvAsPVaO5fpU9r562Yhz5YBG1 s2BqZXMPS6 X-Google-Smtp-Source: ABdhPJwerPTFJGnA6wIx1qFy3mXhb55epGNkR8BAbEEsmW/GaGFyZgg9pxM4t029nZsfmH6vyh4qMQ== X-Received: by 2002:a17:90a:94c4:: with SMTP id j4mr23353950pjw.14.1618830166233; Mon, 19 Apr 2021 04:02:46 -0700 (PDT) Received: from drv-bst-rhel8.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id k13sm11825736pfc.50.2021.04.19.04.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 04:02:45 -0700 (PDT) From: Kashyap Desai To: linux-scsi@vger.kernel.org Cc: jejb@linux.ibm.com, martin.petersen@oracle.com, steve.hagan@broadcom.com, peter.rivera@broadcom.com, mpi3mr-linuxdrv.pdl@broadcom.com, Kashyap Desai , sathya.prakash@broadcom.com Subject: [PATCH v3 16/24] mpi3mr: hardware workaround for UNMAP commands to nvme drives Date: Mon, 19 Apr 2021 16:31:48 +0530 Message-Id: <20210419110156.1786882-17-kashyap.desai@broadcom.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210419110156.1786882-1-kashyap.desai@broadcom.com> References: <20210419110156.1786882-1-kashyap.desai@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The controller hardware can not handle certain unmap commands for NVMe drives, this patch adds support in the driver to check those commands and handle as appropriate. Signed-off-by: Kashyap Desai Reviewed-by: Hannes Reinecke Reviewed-by: Tomas Henzl Cc: sathya.prakash@broadcom.com Reviewed-by: Himanshu Madhani --- drivers/scsi/mpi3mr/mpi3mr_os.c | 99 +++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index ac30699c7d69..01b82bd2e8df 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -2786,6 +2786,100 @@ static int mpi3mr_target_alloc(struct scsi_target *starget) return retval; } +/** + * mpi3mr_check_return_unmap - Whether an unmap is allowed + * @mrioc: Adapter instance reference + * @scmd: SCSI Command reference + * + * The controller hardware cannot handle certain unmap commands + * for NVMe drives, this routine checks those and return true + * and completes the SCSI command with proper status and sense + * data. + * + * Return: TRUE for not allowed unmap, FALSE otherwise. + */ +static bool mpi3mr_check_return_unmap(struct mpi3mr_ioc *mrioc, + struct scsi_cmnd *scmd) +{ + unsigned char *buf; + u16 param_len, desc_len; + + param_len = get_unaligned_be16(scmd->cmnd + 7); + + if (!param_len) { + ioc_warn(mrioc, + "%s: CDB received with zero parameter length\n", + __func__); + scsi_print_command(scmd); + scmd->result = DID_OK << 16; + scmd->scsi_done(scmd); + return true; + } + + if (param_len < 24) { + ioc_warn(mrioc, + "%s: CDB received with invalid param_len: %d\n", + __func__, param_len); + scsi_print_command(scmd); + scmd->result = (DRIVER_SENSE << 24) | + SAM_STAT_CHECK_CONDITION; + scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, + 0x1A, 0); + scmd->scsi_done(scmd); + return true; + } + if (param_len != scsi_bufflen(scmd)) { + ioc_warn(mrioc, + "%s: CDB received with param_len: %d bufflen: %d\n", + __func__, param_len, scsi_bufflen(scmd)); + scsi_print_command(scmd); + scmd->result = (DRIVER_SENSE << 24) | + SAM_STAT_CHECK_CONDITION; + scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, + 0x1A, 0); + scmd->scsi_done(scmd); + return true; + } + buf = kzalloc(scsi_bufflen(scmd), GFP_ATOMIC); + if (!buf) { + scsi_print_command(scmd); + scmd->result = (DRIVER_SENSE << 24) | + SAM_STAT_CHECK_CONDITION; + scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, + 0x55, 0x03); + scmd->scsi_done(scmd); + return true; + } + scsi_sg_copy_to_buffer(scmd, buf, scsi_bufflen(scmd)); + desc_len = get_unaligned_be16(&buf[2]); + + if (desc_len < 16) { + ioc_warn(mrioc, + "%s: Invalid descriptor length in param list: %d\n", + __func__, desc_len); + scsi_print_command(scmd); + scmd->result = (DRIVER_SENSE << 24) | + SAM_STAT_CHECK_CONDITION; + scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, + 0x26, 0); + scmd->scsi_done(scmd); + kfree(buf); + return true; + } + + if (param_len > (desc_len + 8)) { + scsi_print_command(scmd); + ioc_warn(mrioc, + "%s: Truncating param_len(%d) to desc_len+8(%d)\n", + __func__, param_len, (desc_len + 8)); + param_len = desc_len + 8; + put_unaligned_be16(param_len, scmd->cmnd+7); + scsi_print_command(scmd); + } + + kfree(buf); + return false; +} /** * mpi3mr_allow_scmd_to_fw - Command is allowed during shutdown @@ -2878,6 +2972,11 @@ static int mpi3mr_qcmd(struct Scsi_Host *shost, goto out; } + if ((scmd->cmnd[0] == UNMAP) && + (stgt_priv_data->dev_type == MPI3_DEVICE_DEVFORM_PCIE) && + mpi3mr_check_return_unmap(mrioc, scmd)) + goto out; + host_tag = mpi3mr_host_tag_for_scmd(mrioc, scmd); if (host_tag == MPI3MR_HOSTTAG_INVALID) { scmd->result = DID_ERROR << 16;