From patchwork Tue Jul 19 01:26:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF6D6C433EF for ; Tue, 19 Jul 2022 02:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236701AbiGSCGB (ORCPT ); Mon, 18 Jul 2022 22:06:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236475AbiGSCGA (ORCPT ); Mon, 18 Jul 2022 22:06:00 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1F6F63CA; Mon, 18 Jul 2022 19:05:58 -0700 (PDT) Received: from pps.filterd (m0297265.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILfl1i029330; Mon, 18 Jul 2022 18:26:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=yAZZWy276p5sPzjI5n0T4dZwrfUn0k9KxJke9IIfpLc=; b=dDzOOfQTLoPATVIcpdwXN3/dCaAxZT8F9MPHHeZD8T6/hH01YVz5QZ5U9BgfR5RFIWEM v8AcpReDNRoXGONXS/MnZcYVRYxc/FDQv/6Eumi0Rz/7XrRZ6+nStzMHWda5hY5sUoih IA7cjKtwzrWnykR3lZ2dSsiNcKMDJAlWNEuJut+lsBx38VX8SIWuiTdjMA9LwuEzmRGs Xht/7x2rkYWJaD9ohKqmNHwl7brBoSwlSKPKb5/qdZ/N1Y6H5htpBI+bDIZq7hMXewZX yPIJEacYCGDhg7xKuF8JVxonrIyB6/jpGlUCouPwvpq6H1ZZdwW7//ll18V5jQo6aESr Ag== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5dq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:12 -0700 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id E8CD7C0649; Tue, 19 Jul 2022 01:26:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658193971; bh=DLunloD49fKZwbypsH/3t3UFeb+X8d/VWtL3un/nSYg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=DcFYJbpmwGV6SyerL6pw+LlE/I+yPcjULjArP/feALOe7ZiqaCnK4xfOusa64YW4W DSAap0+rrgRw8LTFq33hm2yIxrbU0N4u5D9LkbTTCGGDG8/tza+6fq4hYjZHjWAJf+ brq/3U+Lo+XAk2bteYSexHCP6Y2hI2omLKS19NTSIahdouWNKpwFFc7rMKEf0VItXX gAD+4hq7peC8F7aduFCWw9gfBXcV1Vv73tPDXHA1EsebyKwn54kAG6pMp9RLOMgIW2 T+8EppgfHAUzO49HuQNWG5oLkCZVAf05EMqYZ9kKAnypJIDIPvAWAVXKhjTinA2JJE xrTK7PDIXoUmQ== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id AE426A0068; Tue, 19 Jul 2022 01:26:10 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:10 -0700 Date: Mon, 18 Jul 2022 18:26:10 -0700 Message-Id: <1dbdd36fdcc823dc0a7185cc120073cbdc299c77.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 01/25] target: Add overlapped response to tmrsp_table To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-ORIG-GUID: amv1Yam69oRupuv322c88zNYZPULSD3k X-Proofpoint-GUID: amv1Yam69oRupuv322c88zNYZPULSD3k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxlogscore=999 clxscore=1015 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add TMR_OVERLAPPED_TAG_ATTEMPTED response to tmrsp_table. Signed-off-by: Thinh Nguyen --- Changes in v2: - None include/target/target_core_base.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index c2b36f7d917d..8e3da143a1ce 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -223,6 +223,7 @@ enum tcm_tmrsp_table { TMR_LUN_DOES_NOT_EXIST = 3, TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED = 4, TMR_FUNCTION_REJECTED = 5, + TMR_OVERLAPPED_TAG_ATTEMPTED = 6, }; /* From patchwork Tue Jul 19 01:26:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B943CCA482 for ; Tue, 19 Jul 2022 02:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236659AbiGSCCE (ORCPT ); Mon, 18 Jul 2022 22:02:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234994AbiGSCCD (ORCPT ); Mon, 18 Jul 2022 22:02:03 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F10FF3B95F; Mon, 18 Jul 2022 19:02:02 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26INZLPO002294; Mon, 18 Jul 2022 18:26:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=HaG0eGEEJvR0yBp0RO+qatOJAoNJtow+GPziYoQUtGw=; b=fbWjcppz4iPuT7JGLFyg/1jj9s94YSqiivYv1Y9LoAuI4a94zeXAXbYhpj1JRoutmRij FMOSeMUNMEJsEd5ath565ZPxQWQ7WSMyXUe9EFcC3TeClb7B7Nic2dJq9MB+yX5InrjV DQuP+7my4hmfJxmKIhN29k2/HygyzXT3cl8A2SgaLDwQ5S1Hdyu+NQBpt5QZMf9mF4in va23lhlgE8h/FFu6u5cnIEH5PFBrfdy9DUuQZj9qgmclSKS1i+Olk2SCt/EH5+3M9vni cyGKI4oya2rxjGlN++VxgOBmfOTnGrGpAqzFYSE4lywQJlfvXDbGKBm3PPDH86XNaHn+ 7w== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhna-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:19 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 55A054008A; Tue, 19 Jul 2022 01:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658193978; bh=89Zu00Axch/Lemrn6fD8kbfnRTfQLFsKhC9ceaKXyYE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=I7x8kuV7vaXnugM32sr3x0HnqJwDHG3a4T75S4WpvtIMW1o6SQsEwlgdwh0sFEE6s mZeRAyCRd4cdHrFvp+x55DSEYspZ8D/lj/I8WRlyzxY4oOpEp4iFo0JjVNsHUSHQ82 4ou+ZOvq56yjpzZ6giVDogYnT9atp477JASsGhKNTDwwJHbEu3WqVdvP/rOz12VlwU tIh/1tviJSh1n80Q+BmUYVNkVFNIqRfh0dHc0VCrh6r4Gw1w4XDVNTbPOUhIeAwweF Gyyy8M0BfOHcgdeU10oCKGYnJH2CCvqiHpAzO353Wmb3dcS9M2WJpirWkL5K3+/46N wri7FXqYnR+JA== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id C972BA0096; Tue, 19 Jul 2022 01:26:16 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:16 -0700 Date: Mon, 18 Jul 2022 18:26:16 -0700 Message-Id: <27f3e2ced002bd9b738f4245f7e9b674b3bb3436.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 02/25] target: Add common TMR enum To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: John Youn , Felipe Balbi , Greg KH , Thinh Nguyen , linux-usb@vger.kernel.org X-Proofpoint-GUID: aVrnOJ595mQX0UtRmL_dPolrnck9jPBo X-Proofpoint-ORIG-GUID: aVrnOJ595mQX0UtRmL_dPolrnck9jPBo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add the following common TMR enum: * TMR_I_T_NEXUS_RESET * TMR_QUERY_TASK * TMR_QUERY_TASK_SET * TMR_QUERY_ASYNC_EVENT Signed-off-by: Thinh Nguyen --- Changes in v2: - Changed enum numbering to continue from 8, 9, 10, ... drivers/target/target_core_transport.c | 10 ++++++++++ include/target/target_core_base.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7838dc20f713..92cb4a4a9ab9 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3094,6 +3094,10 @@ static const char *target_tmf_name(enum tcm_tmreq_table tmf) case TMR_TARGET_WARM_RESET: return "TARGET_WARM_RESET"; case TMR_TARGET_COLD_RESET: return "TARGET_COLD_RESET"; case TMR_LUN_RESET_PRO: return "LUN_RESET_PRO"; + case TMR_I_T_NEXUS_RESET: return "I_T_NEXUS_RESET"; + case TMR_QUERY_TASK: return "QUERY_TASK"; + case TMR_QUERY_TASK_SET: return "QUERY_TASK_SET"; + case TMR_QUERY_ASYNC_EVENT: return "QUERY_ASYNC_EVENT"; case TMR_UNKNOWN: break; } return "(?)"; @@ -3542,6 +3546,12 @@ static void target_tmr_work(struct work_struct *work) case TMR_TARGET_COLD_RESET: tmr->response = TMR_FUNCTION_REJECTED; break; + case TMR_I_T_NEXUS_RESET: + case TMR_QUERY_TASK: + case TMR_QUERY_TASK_SET: + case TMR_QUERY_ASYNC_EVENT: + tmr->response = TMR_FUNCTION_REJECTED; + break; default: pr_err("Unknown TMR function: 0x%02x.\n", tmr->function); diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 8e3da143a1ce..b3e3125fac97 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -211,6 +211,10 @@ enum tcm_tmreq_table { TMR_LUN_RESET = 5, TMR_TARGET_WARM_RESET = 6, TMR_TARGET_COLD_RESET = 7, + TMR_I_T_NEXUS_RESET = 8, + TMR_QUERY_TASK = 9, + TMR_QUERY_TASK_SET = 10, + TMR_QUERY_ASYNC_EVENT = 11, TMR_LUN_RESET_PRO = 0x80, TMR_UNKNOWN = 0xff, }; From patchwork Tue Jul 19 01:26:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A1EFCCA482 for ; Tue, 19 Jul 2022 02:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236896AbiGSCSz (ORCPT ); Mon, 18 Jul 2022 22:18:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236900AbiGSCSy (ORCPT ); Mon, 18 Jul 2022 22:18:54 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C23F73C8E9; Mon, 18 Jul 2022 19:18:52 -0700 (PDT) Received: from pps.filterd (m0098572.ppops.net [127.0.0.1]) by mx0b-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILoCF8020763; Mon, 18 Jul 2022 18:26:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=MtkL5HtVzu1AN/MUKIOAzTNp5lPvcuXSXw6ukmlraiA=; b=O41UM5yyqiIFG2UePAX9b6+bmaekA88pimIs4SdsojbZODzoBtY4Iig9XWNPVZ3UV3Ri cIWTlVvQqY3SNB+8XvmyOoWqBV9BmlW2Qt8eeD0p8u6cCKb83txh+gHeE082AFezorda ac8tkGuI28WqwqjdEXDFVdfwsVFQURBvz7pVbv10BxGRfw6CwkxlO7KCD5avBwrwQaQH e+dq3T2OSTzFTEbnTtbp/DND+22uo1AVMBA4lvFDL3Iyfyj4wn2sSd6QgrDV5MSLGv7H qmmERH6iW8jheCHMEw5dDdQ7fzCGDDoFcaFpD9hjmZE+4JvCtPVOlgL7BnCxvL2yC5nX gQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 3hc6c344wm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:37 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id D3D2FC0649; Tue, 19 Jul 2022 01:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658193996; bh=JhsO1p/dFQs74XyIe0gssm1C8LZABLQ+B+PPL+9af98=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=lH3Dwnem7Z6tCz8PUq6Wk+ziBIEuT015RauWjZLMoH4ceVsFhzWwJAcsXsBDz50iM r78HEY339840ILH2StMRmzJBhytaahzRL1ZRGKkyYk4f3LCUvXikrshJErCuAG2Xl3 xSme2ZO5B3GmBjzARrqSDfbcoKkZXMSh5KTaBWD9cXRx4La7X4WnH5uR7OBP1E94fq 9mLubC1qeyvQ6voEEXhbNFJCcSrJ8ILJ3zBWpAZ8+0+hz834dVW6CAsKmgwzTXeTGr pTlYhdYvETaK12zO1DjQy5Z3InfIHgp+OqFg7mf/2Fjm+u+6K42x1qsOxMABMM7YM8 1Q50E5YAEevpw== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 98801A0096; Tue, 19 Jul 2022 01:26:35 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:35 -0700 Date: Mon, 18 Jul 2022 18:26:35 -0700 Message-Id: <1ca4811d61c50e5b9ff81e2b181544ae0ac3106a.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 05/25] usb: gadget: f_tcm: Don't set static stream_id To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: 9p4-WGYie49SZDCX9BLCYq5hNt4wWpxr X-Proofpoint-GUID: 9p4-WGYie49SZDCX9BLCYq5hNt4wWpxr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 malwarescore=0 priorityscore=1501 mlxscore=0 impostorscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=946 phishscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Host can assign stream ID value greater than number of streams allocated. The tcm function needs to keep track of which stream is available to assign the stream ID. This patch doesn't track that, but at least it makes sure that there's no Oops if the host send tag with a value greater than the number of supported streams. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 32 +++++------------------------ 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 270ec631481d..7721216dc9bc 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -532,6 +532,7 @@ static int uasp_prepare_r_request(struct usbg_cmd *cmd) } stream->req_in->is_last = 1; + stream->req_in->stream_id = cmd->tag; stream->req_in->complete = uasp_status_data_cmpl; stream->req_in->length = se_cmd->data_length; stream->req_in->context = cmd; @@ -556,6 +557,7 @@ static void uasp_prepare_status(struct usbg_cmd *cmd) iu->len = cpu_to_be16(se_cmd->scsi_sense_length); iu->status = se_cmd->scsi_status; stream->req_status->is_last = 1; + stream->req_status->stream_id = cmd->tag; stream->req_status->context = cmd; stream->req_status->length = se_cmd->scsi_sense_length + 16; stream->req_status->buf = iu; @@ -786,19 +788,6 @@ static int uasp_alloc_cmd(struct f_uas *fu) return -ENOMEM; } -static void uasp_setup_stream_res(struct f_uas *fu, int max_streams) -{ - int i; - - for (i = 0; i < max_streams; i++) { - struct uas_stream *s = &fu->stream[i]; - - s->req_in->stream_id = i + 1; - s->req_out->stream_id = i + 1; - s->req_status->stream_id = i + 1; - } -} - static int uasp_prepare_reqs(struct f_uas *fu) { int ret; @@ -819,7 +808,6 @@ static int uasp_prepare_reqs(struct f_uas *fu) ret = uasp_alloc_cmd(fu); if (ret) goto err_free_stream; - uasp_setup_stream_res(fu, max_streams); ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); if (ret) @@ -995,6 +983,7 @@ static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) } req->is_last = 1; + req->stream_id = cmd->tag; req->complete = usbg_data_write_cmpl; req->length = se_cmd->data_length; req->context = cmd; @@ -1125,16 +1114,8 @@ static int usbg_submit_command(struct f_uas *fu, } memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); - if (fu->flags & USBG_USE_STREAMS) { - if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) - goto err; - if (!cmd->tag) - cmd->stream = &fu->stream[0]; - else - cmd->stream = &fu->stream[cmd->tag - 1]; - } else { - cmd->stream = &fu->stream[0]; - } + cmd->stream = &fu->stream[cmd->tag % + UASP_SS_EP_COMP_NUM_STREAMS]; switch (cmd_iu->prio_attr & 0x7) { case UAS_HEAD_TAG: @@ -1161,9 +1142,6 @@ static int usbg_submit_command(struct f_uas *fu, queue_work(tpg->workqueue, &cmd->work); return 0; -err: - usbg_release_cmd(&cmd->se_cmd); - return -EINVAL; } static void bot_cmd_work(struct work_struct *work) From patchwork Tue Jul 19 01:26:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2CBCC433EF for ; Tue, 19 Jul 2022 01:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236541AbiGSB56 (ORCPT ); Mon, 18 Jul 2022 21:57:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234867AbiGSB5z (ORCPT ); Mon, 18 Jul 2022 21:57:55 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9094127B17; Mon, 18 Jul 2022 18:57:54 -0700 (PDT) Received: from pps.filterd (m0297265.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILfl1k029330; Mon, 18 Jul 2022 18:26:44 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=DTLVMFxbtnKtLzNLUzmmwdnWVf2t1U1qJ+NQUnwA82Q=; b=Td5NjD8bCFa117eZgcU4XA/W4JPkg+UZ8lSs70M1gKaHKpX5UMDn7DazUzH4P4dZXihH WlCJg2zuevh4fSA2yGp3C14zo1HI3yIcmO+LXn+ArRs8Ji95rPOiMyqYq1IY4P/M73TM 0upm3SJ6OKdmajOcAq3GwgbZAhzA0sThysnK0X5Q+y01qd0nnOboSPdozko6wL1jEyLa rIl+x6w6CMP8xeId+zLQHbCxXd0P9ylwzQ34fyU154gsTvfcl6lUOrX7LiFLlNvThewg I7T2wFexMVEhw5D1L1qUNSGJTQ5Fd0sRurnXBGwV5zF7oVbVjqvWNEs7559bfjJuGThI +w== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5f0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:44 -0700 Received: from mailhost.synopsys.com (sv1-mailhost1.synopsys.com [10.205.2.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 27F8EC0649; Tue, 19 Jul 2022 01:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194003; bh=3yP8H4UW+LN/RDlXQUz7ixouteSYRQT6QCwxxucIo8g=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GfiS7EpV6YWTqhU9W0C82ldkirZbYnDu/gnjeSRN3J33BKseWYJ0Ymwg/0ggNsF/5 OZanebpEGbBLX52guzt5Ppa6o9n+gBOrljdc+q5FplFTsq/jhJaemJ/amcK3A1PE9z LiDzi4tOWgmXBdEHGeDKCLustY6BRQ2/tiIlxIOrkDiQF2vhhIaK8ndS1sTSSMWLui gGvkQBMpaa2lV/kWhqXGaUgwe45WSMPs/oVeQHtrT3gLo9pRFXX4lW76liMOMX4HEU puJPOwprFwVuXh5ZcN+fXIRvqbyJRliQg7Igbc5IvltOG20bSN3ItkzMe0lGSBnBKa saRFJZKIPHZSQ== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id B5426A0068; Tue, 19 Jul 2022 01:26:41 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:41 -0700 Date: Mon, 18 Jul 2022 18:26:41 -0700 Message-Id: <8e0fa7c61240a934870c5866989ca13d070d9d59.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 06/25] usb: gadget: f_tcm: Allocate matching number of commands to streams To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: Obgl_4WHFiqYDDCscWLcpis0vbs1RNR8 X-Proofpoint-GUID: Obgl_4WHFiqYDDCscWLcpis0vbs1RNR8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxlogscore=999 clxscore=1015 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We can handle multiple commands concurently. Each command services a stream id. At the moment, the driver will handle 32 outstanding streams, which is equivalent to 32 commands. Make sure to allocate a matching number of commands to the number of streams. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 110 ++++++++++++++-------------- drivers/usb/gadget/function/tcm.h | 8 +- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 7721216dc9bc..6e0b54985932 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -50,7 +50,7 @@ static int bot_enqueue_cmd_cbw(struct f_uas *fu) if (fu->flags & USBG_BOT_CMD_PEND) return 0; - ret = usb_ep_queue(fu->ep_out, fu->cmd.req, GFP_ATOMIC); + ret = usb_ep_queue(fu->ep_out, fu->cmd[0].req, GFP_ATOMIC); if (!ret) fu->flags |= USBG_BOT_CMD_PEND; return ret; @@ -136,7 +136,7 @@ static void bot_send_bad_status(struct usbg_cmd *cmd) } req->complete = bot_err_compl; req->context = cmd; - req->buf = fu->cmd.buf; + req->buf = fu->cmd[0].buf; usb_ep_queue(ep, req, GFP_KERNEL); } else { bot_enqueue_sense_code(fu, cmd); @@ -314,8 +314,8 @@ static int bot_prepare_reqs(struct f_uas *fu) if (!fu->bot_req_out) goto err_out; - fu->cmd.req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); - if (!fu->cmd.req) + fu->cmd[0].req = usb_ep_alloc_request(fu->ep_out, GFP_KERNEL); + if (!fu->cmd[0].req) goto err_cmd; fu->bot_status.req = usb_ep_alloc_request(fu->ep_in, GFP_KERNEL); @@ -327,27 +327,27 @@ static int bot_prepare_reqs(struct f_uas *fu) fu->bot_status.req->complete = bot_status_complete; fu->bot_status.csw.Signature = cpu_to_le32(US_BULK_CS_SIGN); - fu->cmd.buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); - if (!fu->cmd.buf) + fu->cmd[0].buf = kmalloc(fu->ep_out->maxpacket, GFP_KERNEL); + if (!fu->cmd[0].buf) goto err_buf; - fu->cmd.req->complete = bot_cmd_complete; - fu->cmd.req->buf = fu->cmd.buf; - fu->cmd.req->length = fu->ep_out->maxpacket; - fu->cmd.req->context = fu; + fu->cmd[0].req->complete = bot_cmd_complete; + fu->cmd[0].req->buf = fu->cmd[0].buf; + fu->cmd[0].req->length = fu->ep_out->maxpacket; + fu->cmd[0].req->context = fu; ret = bot_enqueue_cmd_cbw(fu); if (ret) goto err_queue; return 0; err_queue: - kfree(fu->cmd.buf); - fu->cmd.buf = NULL; + kfree(fu->cmd[0].buf); + fu->cmd[0].buf = NULL; err_buf: usb_ep_free_request(fu->ep_in, fu->bot_status.req); err_sts: - usb_ep_free_request(fu->ep_out, fu->cmd.req); - fu->cmd.req = NULL; + usb_ep_free_request(fu->ep_out, fu->cmd[0].req); + fu->cmd[0].req = NULL; err_cmd: usb_ep_free_request(fu->ep_out, fu->bot_req_out); fu->bot_req_out = NULL; @@ -372,16 +372,16 @@ static void bot_cleanup_old_alt(struct f_uas *fu) usb_ep_free_request(fu->ep_in, fu->bot_req_in); usb_ep_free_request(fu->ep_out, fu->bot_req_out); - usb_ep_free_request(fu->ep_out, fu->cmd.req); + usb_ep_free_request(fu->ep_out, fu->cmd[0].req); usb_ep_free_request(fu->ep_in, fu->bot_status.req); - kfree(fu->cmd.buf); + kfree(fu->cmd[0].buf); fu->bot_req_in = NULL; fu->bot_req_out = NULL; - fu->cmd.req = NULL; + fu->cmd[0].req = NULL; fu->bot_status.req = NULL; - fu->cmd.buf = NULL; + fu->cmd[0].buf = NULL; } static void bot_set_alt(struct f_uas *fu) @@ -482,10 +482,14 @@ static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) static void uasp_free_cmdreq(struct f_uas *fu) { - usb_ep_free_request(fu->ep_cmd, fu->cmd.req); - kfree(fu->cmd.buf); - fu->cmd.req = NULL; - fu->cmd.buf = NULL; + int i; + + for (i = 0; i < USBG_NUM_CMDS; i++) { + usb_ep_free_request(fu->ep_cmd, fu->cmd[i].req); + kfree(fu->cmd[i].buf); + fu->cmd[i].req = NULL; + fu->cmd[i].buf = NULL; + } } static void uasp_cleanup_old_alt(struct f_uas *fu) @@ -500,7 +504,7 @@ static void uasp_cleanup_old_alt(struct f_uas *fu) usb_ep_disable(fu->ep_status); usb_ep_disable(fu->ep_cmd); - for (i = 0; i < UASP_SS_EP_COMP_NUM_STREAMS; i++) + for (i = 0; i < USBG_NUM_CMDS; i++) uasp_cleanup_one_stream(fu, &fu->stream[i]); uasp_free_cmdreq(fu); } @@ -603,7 +607,8 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) case UASP_QUEUE_COMMAND: transport_generic_free_cmd(&cmd->se_cmd, 0); - usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); + usb_ep_queue(fu->ep_cmd, cmd->req, GFP_ATOMIC); + break; default: @@ -718,7 +723,7 @@ static int uasp_send_write_request(struct usbg_cmd *cmd) return ret; } -static int usbg_submit_command(struct f_uas *, void *, unsigned int); +static int usbg_submit_command(struct f_uas *, struct usb_request *); static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) { @@ -728,7 +733,7 @@ static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) if (req->status < 0) return; - ret = usbg_submit_command(fu, req->buf, req->actual); + ret = usbg_submit_command(fu, req); /* * Once we tune for performance enqueue the command req here again so * we can receive a second command while we processing this one. Pay @@ -737,7 +742,7 @@ static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) */ if (!ret) return; - usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); + usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC); } static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) @@ -766,24 +771,24 @@ static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) return -ENOMEM; } -static int uasp_alloc_cmd(struct f_uas *fu) +static int uasp_alloc_cmd(struct f_uas *fu, int i) { - fu->cmd.req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); - if (!fu->cmd.req) + fu->cmd[i].req = usb_ep_alloc_request(fu->ep_cmd, GFP_KERNEL); + if (!fu->cmd[i].req) goto err; - fu->cmd.buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); - if (!fu->cmd.buf) + fu->cmd[i].buf = kmalloc(fu->ep_cmd->maxpacket, GFP_KERNEL); + if (!fu->cmd[i].buf) goto err_buf; - fu->cmd.req->complete = uasp_cmd_complete; - fu->cmd.req->buf = fu->cmd.buf; - fu->cmd.req->length = fu->ep_cmd->maxpacket; - fu->cmd.req->context = fu; + fu->cmd[i].req->complete = uasp_cmd_complete; + fu->cmd[i].req->buf = fu->cmd[i].buf; + fu->cmd[i].req->length = fu->ep_cmd->maxpacket; + fu->cmd[i].req->context = fu; return 0; err_buf: - usb_ep_free_request(fu->ep_cmd, fu->cmd.req); + usb_ep_free_request(fu->ep_cmd, fu->cmd[i].req); err: return -ENOMEM; } @@ -792,26 +797,22 @@ static int uasp_prepare_reqs(struct f_uas *fu) { int ret; int i; - int max_streams; - - if (fu->flags & USBG_USE_STREAMS) - max_streams = UASP_SS_EP_COMP_NUM_STREAMS; - else - max_streams = 1; - for (i = 0; i < max_streams; i++) { + for (i = 0; i < USBG_NUM_CMDS; i++) { ret = uasp_alloc_stream_res(fu, &fu->stream[i]); if (ret) goto err_cleanup; } - ret = uasp_alloc_cmd(fu); - if (ret) - goto err_free_stream; + for (i = 0; i < USBG_NUM_CMDS; i++) { + ret = uasp_alloc_cmd(fu, i); + if (ret) + goto err_free_stream; - ret = usb_ep_queue(fu->ep_cmd, fu->cmd.req, GFP_ATOMIC); - if (ret) - goto err_free_stream; + ret = usb_ep_queue(fu->ep_cmd, fu->cmd[i].req, GFP_ATOMIC); + if (ret) + goto err_free_stream; + } return 0; @@ -1081,10 +1082,9 @@ static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, static void usbg_release_cmd(struct se_cmd *); -static int usbg_submit_command(struct f_uas *fu, - void *cmdbuf, unsigned int len) +static int usbg_submit_command(struct f_uas *fu, struct usb_request *req) { - struct command_iu *cmd_iu = cmdbuf; + struct command_iu *cmd_iu = req->buf; struct usbg_cmd *cmd; struct usbg_tpg *tpg = fu->tpg; struct tcm_usbg_nexus *tv_nexus; @@ -1114,8 +1114,7 @@ static int usbg_submit_command(struct f_uas *fu, } memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); - cmd->stream = &fu->stream[cmd->tag % - UASP_SS_EP_COMP_NUM_STREAMS]; + cmd->stream = &fu->stream[cmd->tag % USBG_NUM_CMDS]; switch (cmd_iu->prio_attr & 0x7) { case UAS_HEAD_TAG: @@ -1137,6 +1136,7 @@ static int usbg_submit_command(struct f_uas *fu, } cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); + cmd->req = req; INIT_WORK(&cmd->work, usbg_cmd_work); queue_work(tpg->workqueue, &cmd->work); diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index 6cb05dcd19ff..bcbe35bb5015 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -16,6 +16,8 @@ #define UASP_SS_EP_COMP_LOG_STREAMS 5 #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) +#define USBG_NUM_CMDS UASP_SS_EP_COMP_NUM_STREAMS + enum { USB_G_STR_INT_UAS = 0, USB_G_STR_INT_BBB, @@ -75,6 +77,8 @@ struct usbg_cmd { struct completion write_complete; struct kref ref; + struct usb_request *req; + /* UAS only */ u16 tag; u16 prio_attr; @@ -117,14 +121,14 @@ struct f_uas { #define USBG_IS_BOT (1 << 3) #define USBG_BOT_CMD_PEND (1 << 4) - struct usbg_cdb cmd; + struct usbg_cdb cmd[USBG_NUM_CMDS]; struct usb_ep *ep_in; struct usb_ep *ep_out; /* UAS */ struct usb_ep *ep_status; struct usb_ep *ep_cmd; - struct uas_stream stream[UASP_SS_EP_COMP_NUM_STREAMS]; + struct uas_stream stream[USBG_NUM_CMDS]; /* BOT */ struct bot_status bot_status; From patchwork Tue Jul 19 01:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0E5DC43334 for ; Tue, 19 Jul 2022 02:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236701AbiGSCJN (ORCPT ); Mon, 18 Jul 2022 22:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236799AbiGSCJL (ORCPT ); Mon, 18 Jul 2022 22:09:11 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 812173C8DE; Mon, 18 Jul 2022 19:09:10 -0700 (PDT) Received: from pps.filterd (m0297265.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILqKEe029328; Mon, 18 Jul 2022 18:26:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=qkJPrxgGtrbNqfw9s1Vi60239Bt3cH0yMi4lqKGKFLM=; b=ksWsU/e6frKTXBg9ufIMu7jHIjcoToMCAo/Mz8i6SaRVQszWIgom5Jj/qm1rwm2AUz/A SODLdQUFbFPssTa7wG51DTbb1kaD2Ezk7L65P31OZWGegU2Bv81Y4E2L/yY1fMNkaDcH 4minQCSS5MnaKS5rPJi9EYGVw4+tkRg6t+8lWPfBy5OonJ42ohDNx+MYfVcJvGQXEdYW 9jvcdbhLJuM57rPsr6CHD78uB9r4iGK8Na6CDf9UV4PtukAjUPkbqa1WjFB9pjrF7iFq HQEdSr1GMmyBkuP8CZbCXGCHDjO2e8qgyD7GH6hF7anrJ8Gbxbzdak0JslaLlNys2qVl tQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5g9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:56 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 4E50D4008A; Tue, 19 Jul 2022 01:26:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194015; bh=/2Vftf4mdEB0AyUJNYx0wby0+U0fRBZYVdKa84rgIMA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=igkUuIo5wyTlfcQ5gCND1+3UnZFZ4gd/e3HAqtakO5qRbFli54IvgqJVBrXlf+8FT rY12pNxdN1oE15vuV+T5+t25Lkv2nkI46my+U/SodzD+XLlRmcRQBSWw0C0V/dEr1z P2UQHVNQg4uzK+2CLjmA5Fc6Q0s9A8v5w8MWxdxeN2irgDmUO+PqyrWeK62c08/QrU 6/9LNUSdZW3n8DYP8NicPF1XDiC/l2NpH5mXXHJV0yz/z2mRaLdCZucv41D8M5qEKI DygyEoTR1QtKYerm0UEpzfc7QbDFqM6mzR3M1Np240eVY80D9OZ5XyfS6yuXJARkXz S64XX4T+RR1Eg== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 226FBA0096; Tue, 19 Jul 2022 01:26:54 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:54 -0700 Date: Mon, 18 Jul 2022 18:26:54 -0700 Message-Id: <2562ea25269c4af173382c6e03fde9d423f664d4.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 08/25] usb: gadget: f_tcm: Handle multiple commands in parallel To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: ZiFs0SmjsTFdPmPRYEWOFVQrksZ3aI2R X-Proofpoint-GUID: ZiFs0SmjsTFdPmPRYEWOFVQrksZ3aI2R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxlogscore=999 clxscore=1015 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Resubmit command on completion to fetch more commands and service them in parallel. Increase the number of work in a queue. Each work will be for each command allowing them to be processed concurrently. Also, set them to be unbounded by cpu to improve performance. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 6e0b54985932..91d853682468 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -728,21 +728,16 @@ static int usbg_submit_command(struct f_uas *, struct usb_request *); static void uasp_cmd_complete(struct usb_ep *ep, struct usb_request *req) { struct f_uas *fu = req->context; - int ret; - if (req->status < 0) + if (req->status == -ESHUTDOWN) return; - ret = usbg_submit_command(fu, req); - /* - * Once we tune for performance enqueue the command req here again so - * we can receive a second command while we processing this one. Pay - * attention to properly sync STAUS endpoint with DATA IN + OUT so you - * don't break HS. - */ - if (!ret) + if (req->status < 0) { + usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC); return; - usb_ep_queue(fu->ep_cmd, req, GFP_ATOMIC); + } + + usbg_submit_command(fu, req); } static int uasp_alloc_stream_res(struct f_uas *fu, struct uas_stream *stream) @@ -1357,7 +1352,8 @@ static struct se_portal_group *usbg_make_tpg(struct se_wwn *wwn, goto unref_dep; mutex_init(&tpg->tpg_mutex); atomic_set(&tpg->tpg_port_count, 0); - tpg->workqueue = alloc_workqueue("tcm_usb_gadget", 0, 1); + tpg->workqueue = alloc_workqueue("tcm_usb_gadget", + WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE); if (!tpg->workqueue) goto free_tpg; From patchwork Tue Jul 19 01:27:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592367 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22E08CCA482 for ; Tue, 19 Jul 2022 02:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236585AbiGSB76 (ORCPT ); Mon, 18 Jul 2022 21:59:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiGSB75 (ORCPT ); Mon, 18 Jul 2022 21:59:57 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 741FD3AB13; Mon, 18 Jul 2022 18:59:56 -0700 (PDT) Received: from pps.filterd (m0297265.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILhqxe029327; Mon, 18 Jul 2022 18:27:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=4ZVLdzbMUcrfP/EafEBZxfI6im0iYb4s/IkAcW58Hf0=; b=G5/9NSoIUat986llcO7MIdTlzWze+GoJ9zsIJoRwQiw1gzLpQPB+fCEQ22W9k0eJ0gxo bzO2wzjZRP2wNsDxSQ7ACgYEFr2Mv8c9f4QFUVLcipiTDmIFPxS3bWs7elLXaVS7PKP5 g8ug9tpaWwAxrfy3TInI2yKfYbf3/bS5hag6kZDESf0cQnfWQkuAbYKw8LUNKSQxmdfV qigPF1kBwZcl8NQQDxXBhHCvoNO/dl60+rmWrjCDAdxd91FKzJYwGlQx/w1VBKMo0uF5 arBhdZtKjOhdaPKpdrNMJbmimv5gT3QT2Nfx1Rw6M4IRAu9T/8ep7EgkVUIELxrdNeDr Eg== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5hp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:08 -0700 Received: from mailhost.synopsys.com (sv2-mailhost2.synopsys.com [10.205.2.134]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 7C2FE4008A; Tue, 19 Jul 2022 01:27:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194027; bh=ZMdZU1K7CwtMhxl8DY31/uSscHDaBNyOTjP59A3yGu8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=XU8K0SkWLf3qabPFpb3MSvKQsrRtSZq3BfDn65KdjRq3M3mlHl8N9Gn2pLD8kFCq5 EklTcOidJQ2eChLO5qqAW/SN/iNH3SscF4RavWWCN3wFiF6A6VQU8GL9gZrqPhYw1T 7bHVjukFPi5d8xRFOy4YKiFvjXPZ+CeATyhhs/u1G5m5ExQmRapYpjrs/nZjZQ5uyI JBB++faMlxUeDGfBVB9ZSzkzFUDYcmIoWCG9E13oNbhJq8X2NlFLiH8GGcnbp9CA3V ngdJjn14jBJAdWbn3xLO9d7kuH0ogSafOua3vjz4xjmMCdqoAFxPz4NfXoc6K8a1IR +Qe1UWblapmdg== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 5B683A0096; Tue, 19 Jul 2022 01:27:06 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:06 -0700 Date: Mon, 18 Jul 2022 18:27:06 -0700 Message-Id: <38fd7899b6861846f1bb614d026ef009a2546df9.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 10/25] usb: gadget: f_tcm: Return ATA cmd direction To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: Cb88W5sHxH7AaOEb2Do6iSiscB9Uc9yf X-Proofpoint-GUID: Cb88W5sHxH7AaOEb2Do6iSiscB9Uc9yf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxlogscore=623 clxscore=1015 malwarescore=0 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 priorityscore=1501 spamscore=0 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Check ATA Pass-Through for direction. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 91d853682468..6fea80afe2d7 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -898,6 +898,8 @@ static int get_cmd_dir(const unsigned char *cdb) case READ_TOC: case READ_FORMAT_CAPACITIES: case REQUEST_SENSE: + case ATA_12: + case ATA_16: ret = DMA_FROM_DEVICE; break; From patchwork Tue Jul 19 01:27:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57C20CCA479 for ; Tue, 19 Jul 2022 02:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236818AbiGSCPg (ORCPT ); Mon, 18 Jul 2022 22:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232694AbiGSCPf (ORCPT ); Mon, 18 Jul 2022 22:15:35 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CA74140E9; Mon, 18 Jul 2022 19:15:35 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26ILhi6f002271; Mon, 18 Jul 2022 18:27:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=8tolDFm89/8zK78M9TjG6dQ+ZoazYBzcHvBv82IAklM=; b=qE/f54D5BRB1UvyObVCwR9scIL+q/rOC2+8LpRsd+ygIn/zaWpdRfW9F5tY01k3nY36c tz/ufnI3Vvoar3A/5KOQ1OGA4nVVodmVC1KpQANxNJr5m2QrpZS3LfTL6FFu90drEEkk xgrhKyUVOk1GdfVCGiSxKWuWFOkGiExDuB38PG4sdoEGtZIG3CwPwX4b0ajkVBgeM7Dt 35W0kxpftVFClI00blkgHJfSXdLuQIGPYWd3PKckMtGPI4jVGqhPjvyFfKvkr1KzrUTu 7SzpvDaotFKghraP8/F0TbkVTjSbO9Els7PC/z/7kywOt3QwPcYZwoLez7bdPM8MgIHR JA== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:35 -0700 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id B5A6DC0765; Tue, 19 Jul 2022 01:27:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194054; bh=pP7gQU+q6Jbs9kRO4wHEn4LGNIaHXAzO28B7lxUiCKg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=hDCgspOlKFCTMC60DQOHxwY8hgV1tyZcl//LB5xgDZ1m3Ln4fUEQWGlk0Qi7TDM28 7W+HPEXDJqSUTHxkvl3guARjlaDxfa4ME1D07IXKHLgUZ0PaSDAw2V43BtRXWNZrUp 2x7vTSSdjp/zYAOvzBLOvA+Ye2ARJQb4OLqN/vxKtdqohypR62yluzoWo4bq9XCMVW PAKNyu2w4o/uLBjYaz/f7piTDYE62MBctMGaQ+7g5ved/BOqEMC5hCpf45OitQA1zw rOv2ZaJIodwKl3b9mTmJiTGubQAW1QTLVtsmb68lG05ND6O2LTwXhQvfJF7kGHxFTC lX6JE1bvvUuHQ== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id B9B77A006D; Tue, 19 Jul 2022 01:27:32 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:32 -0700 Date: Mon, 18 Jul 2022 18:27:32 -0700 Message-Id: <443175c77873b6b86d01b8df8fc5d5aeba6748f0.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 14/25] usb: gadget: f_tcm: Translate error to sense To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov , Nicholas Bellinger , Sebastian Andrzej Siewior Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Alan Stern , Christoph Hellwig X-Proofpoint-GUID: BkB21a4mBxOUK3O8ASrTfNw3O9-Fglq7 X-Proofpoint-ORIG-GUID: BkB21a4mBxOUK3O8ASrTfNw3O9-Fglq7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=725 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When respond with check_condition error status, clear from_transport input so the target layer can translate the sense reason reported by f_tcm. Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT") Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index cace5746c0f9..28b560ab44fd 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1044,7 +1044,7 @@ static void usbg_cmd_work(struct work_struct *work) out: transport_send_check_condition_and_sense(se_cmd, - TCM_UNSUPPORTED_SCSI_OPCODE, 1); + TCM_UNSUPPORTED_SCSI_OPCODE, 0); } static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, @@ -1160,7 +1160,7 @@ static void bot_cmd_work(struct work_struct *work) out: transport_send_check_condition_and_sense(se_cmd, - TCM_UNSUPPORTED_SCSI_OPCODE, 1); + TCM_UNSUPPORTED_SCSI_OPCODE, 0); transport_generic_free_cmd(&cmd->se_cmd, 0); } From patchwork Tue Jul 19 01:28:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44ED9CCA479 for ; Tue, 19 Jul 2022 02:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236822AbiGSCMf (ORCPT ); Mon, 18 Jul 2022 22:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236818AbiGSCMd (ORCPT ); Mon, 18 Jul 2022 22:12:33 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 704BB3CBF1; Mon, 18 Jul 2022 19:12:32 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26IMtTBx002288; Mon, 18 Jul 2022 18:28:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=COQI1joPVzY6z+LSK+qBe+EhRAlVvI0mDGN7HZSpcO4=; b=GrxUNfNUIGNPcGcb1TsR2lJeud8fJGMoe5h/Go6nTVq2U5EC0jh3dRLMfhh9YE20+4RM XaXR+x532l1QgWEVeDtmKPfTFuPBpjY4/YmQ7xT3O7tA0+k7o/h29n1st3mn1W+oSBBW teGMxMza/TKRmXPP1YUKVxxZZ5qWep/GHsYYS4GwXMxSA70YV6DY9UuuDA594XxNUy+1 y8ivxwWwa6+3/6zE337g1dutM20I75snDjIkVEnc4ESbZWK1sT3yxnYBXOnaP4axqd8Z UqXO3DYqfwms+J6YMAXpBrQBoDYlpD3GjlEvBgTqiiT1sLYIGBXc+J2qaHd6TjdgyMg0 4A== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:24 -0700 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id AB42D4008A; Tue, 19 Jul 2022 01:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194103; bh=cKiEzj0MB8Y/2NbCc7NTZJ2ZmmooMzpVd2l2YHy7B+o=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=eNZLR6jLLgI8LDnCzLNYrp6u/LG4OoKRHirjl1M/enYZE9npDSHl8kcvEc+PQwWyi ZmMKfQp2AM0uJZlnnl/A/G9R5RYDGCres/DCZtrQsKYz9R82KxM3Jc/aMv2Y0prTVQ cRuDk+uysMPyl0lCJBpvNJzNhrWfc0jOn/yA37lrrhWRj2p6VqDVQ2VU5q4SWxOuug kKfk775h9hAbC/n+dTVZms/hYwPC+fJh6vimLEWfzbBobBQWOpj4orzPOVzkNLlIXr pxRQtyeJcvqDjhUA/xStkDqNiu+y4e6O4iaKDsfeGgimaNbeSVu0KCgYMtjsJQADS4 aBISDLtUQPC9w== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 6D43FA006D; Tue, 19 Jul 2022 01:28:22 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:22 -0700 Date: Mon, 18 Jul 2022 18:28:22 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 22/25] usb: gadget: f_tcm: Send sense on cancelled transfer To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-GUID: tilO8DR2S2fTvM2aQtZFhkd7bH4g4fy4 X-Proofpoint-ORIG-GUID: tilO8DR2S2fTvM2aQtZFhkd7bH4g4fy4 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=613 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If the transfer is cancelled due to a disconnect or driver tear down (error code -ESHUTDOWN), then just free the command. However, if it got cancelled due to other reasons, then send a sense CHECK CONDITION status with TCM_CHECK_CONDITION_ABORT_CMD status to host notifying the delivery failure. Note that this is separate from TASK MANAGEMENT function abort task command, which will require a separate response IU. See UAS-r04 section 8. Signed-off-by: Thinh Nguyen --- Changes in v2: - New patch drivers/usb/gadget/function/f_tcm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index a10e74290664..116be1c47ac9 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -949,11 +949,16 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) { struct usbg_cmd *cmd = req->context; struct se_cmd *se_cmd = &cmd->se_cmd; + struct uas_stream *stream = uasp_get_stream_by_tag(cmd->fu, cmd->tag); cmd->state = UASP_QUEUE_COMMAND; - if (req->status == -ESHUTDOWN) - goto cleanup; + if (req->status == -ESHUTDOWN) { + stream->cmd = NULL; + target_put_sess_cmd(se_cmd); + transport_generic_free_cmd(&cmd->se_cmd, 0); + return; + } if (req->status) { pr_err("%s() state %d transfer failed\n", __func__, cmd->state); @@ -972,7 +977,8 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) cleanup: target_put_sess_cmd(se_cmd); - transport_generic_free_cmd(&cmd->se_cmd, 0); + transport_send_check_condition_and_sense(se_cmd, + TCM_CHECK_CONDITION_ABORT_CMD, 0); } static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) From patchwork Tue Jul 19 01:28:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F9E4C43334 for ; Tue, 19 Jul 2022 02:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236922AbiGSC0r (ORCPT ); Mon, 18 Jul 2022 22:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbiGSC0r (ORCPT ); Mon, 18 Jul 2022 22:26:47 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A85F3AE76; Mon, 18 Jul 2022 19:26:46 -0700 (PDT) Received: from pps.filterd (m0098571.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J1JOUZ002282; Mon, 18 Jul 2022 18:28:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=ZELufq2Y8q9hAay4jmJM1QEnlK1jv++ZwEONvskwPCo=; b=IFpR/nr1mzePRHVe5Vy1CxxhsIIdzBqdbj+G6s2CHhijNfgW8KPA8wimt4XhDSCNbU4l aFP/PsZ/5IOPMdGmgRbPRVkcaH2PEO2hKI4E2XYwSaMBF2xPXv9T9FxaWcdLDcY4c1aA 2FjaK6Kr3a9Nm0H6//izU1z9W9I7mKSnbYOdEAVIKgANaI26V2N0qNT430/tF/hD5LiS eVaRNRe3tzIeubmtLvLYhC8aBF2Tg+0jAq9btll7/YP1WqGe1LxYK3cHId/cR3JDXF80 RpH6YDIVwCvD2iOXvJ4GNRiBYGcaUJzb2Y2oPjNc+dcT6atM4TWKJmAsOFKfbBMOoN5v iw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhvu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:30 -0700 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id B2B904008A; Tue, 19 Jul 2022 01:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194109; bh=IuLkUSf4/N0Op0xK4G/uDW4KdpKVrzDZox9PRZ7HwKc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Xp7QTpTyPwx0qu3wvL8p5UWXG8YWPjIDxSbDFb5x63lMccPNtndSEaY8RCSIFhf/f DKYe4ly9jJ5XZkJT7byp3srbM+tLWefEu5VkBVa0Gf42uX4ayX9y5f/A12blevZHPU GnD5mfxVHgOsLbiyd+pqxAHQwiAP5IelOFoCRcj8kyeY8ADI07VrwwztiH08nkIH1V jKdyRxVZYo74JgPRxMV6LImh2+6uAyRfHvVBuJKlBPsuixeKWqi6fgHp+iRz2JXdno PRm9wGkNz9YmCSehNoyWLIk6WqHMKLp+7+emPVva1vg+H58EokqhFtZBvxbWqgz+rQ wbRYoKy5OFVuA== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id 89A3EA006D; Tue, 19 Jul 2022 01:28:28 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:28 -0700 Date: Mon, 18 Jul 2022 18:28:28 -0700 Message-Id: <4b16a01640798df3561965de0dc5755d370dd0c7.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 23/25] usb: gadget: f_tcm: Handle TASK_MANAGEMENT commands To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-GUID: 37RUzTze6vhSJN4H6PDI55tPj3J-L6hQ X-Proofpoint-ORIG-GUID: 37RUzTze6vhSJN4H6PDI55tPj3J-L6hQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 clxscore=1015 priorityscore=1501 impostorscore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Handle target_core_fabric_ops TASK MANAGEMENT functions and their response. If a TASK MANAGEMENT command is received, the driver will interpret the function TMF_*, translate to TMR_*, and fire off a command work executing target_submit_tmr(). On completion, it will handle the TASK MANAGEMENT response through uasp_send_tm_response(). Signed-off-by: Thinh Nguyen --- Changes in v2: - Splitted into smaller change. Remove handling of overlapped tag. - Directly respond to host if f_tcm detected failure with response IU rather than reporting to target core. drivers/usb/gadget/function/f_tcm.c | 206 +++++++++++++++++++++++++--- drivers/usb/gadget/function/tcm.h | 7 +- 2 files changed, 193 insertions(+), 20 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 116be1c47ac9..8b99ee07df87 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -462,6 +463,51 @@ static int usbg_bot_setup(struct usb_function *f, /* Start uas.c code */ +static int tcm_to_uasp_response(enum tcm_tmrsp_table code) +{ + switch (code) { + case TMR_FUNCTION_FAILED: + return RC_TMF_FAILED; + case TMR_FUNCTION_COMPLETE: + case TMR_TASK_DOES_NOT_EXIST: + return RC_TMF_COMPLETE; + case TMR_LUN_DOES_NOT_EXIST: + return RC_INCORRECT_LUN; + case TMR_OVERLAPPED_TAG_ATTEMPTED: + return RC_OVERLAPPED_TAG; + case TMR_FUNCTION_REJECTED: + case TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED: + default: + return RC_TMF_NOT_SUPPORTED; + } +} + +static unsigned char uasp_to_tcm_func(int code) +{ + switch (code) { + case TMF_ABORT_TASK: + return TMR_ABORT_TASK; + case TMF_ABORT_TASK_SET: + return TMR_ABORT_TASK_SET; + case TMF_CLEAR_TASK_SET: + return TMR_CLEAR_TASK_SET; + case TMF_LOGICAL_UNIT_RESET: + return TMR_LUN_RESET; + case TMF_I_T_NEXUS_RESET: + return TMR_I_T_NEXUS_RESET; + case TMF_CLEAR_ACA: + return TMR_CLEAR_ACA; + case TMF_QUERY_TASK: + return TMR_QUERY_TASK; + case TMF_QUERY_TASK_SET: + return TMR_QUERY_TASK_SET; + case TMF_QUERY_ASYNC_EVENT: + return TMR_QUERY_ASYNC_EVENT; + default: + return TMR_UNKNOWN; + } +} + static void uasp_cleanup_one_stream(struct f_uas *fu, struct uas_stream *stream) { /* We have either all three allocated or none */ @@ -581,6 +627,33 @@ static void uasp_prepare_status(struct usbg_cmd *cmd) stream->req_status->complete = uasp_status_data_cmpl; } +static void uasp_prepare_response(struct usbg_cmd *cmd) +{ + struct se_cmd *se_cmd = &cmd->se_cmd; + struct response_iu *rsp_iu = &cmd->response_iu; + struct uas_stream *stream = uasp_get_stream_by_tag(cmd->fu, cmd->tag); + + cmd->state = UASP_QUEUE_COMMAND; + rsp_iu->iu_id = IU_ID_RESPONSE; + rsp_iu->tag = cpu_to_be16(cmd->tag); + + if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) + rsp_iu->response_code = cmd->tmr_rsp; + else + rsp_iu->response_code = + tcm_to_uasp_response(se_cmd->se_tmr_req->response); + + stream->req_status->is_last = 1; + stream->req_status->stream_id = cmd->tag; + stream->req_status->context = cmd; + stream->req_status->length = sizeof(struct response_iu); + stream->req_status->buf = rsp_iu; + stream->req_status->complete = uasp_status_data_cmpl; +} + +static void usbg_release_cmd(struct se_cmd *se_cmd); +static int uasp_send_tm_response(struct usbg_cmd *cmd); + static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) { struct usbg_cmd *cmd = req->context; @@ -619,9 +692,26 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) break; case UASP_QUEUE_COMMAND: - transport_generic_free_cmd(&cmd->se_cmd, 0); - usb_ep_queue(fu->ep_cmd, cmd->req, GFP_ATOMIC); + stream->cmd = NULL; + + /* + * If no command submitted to target core here, just free the + * bitmap index. This is for the cases where f_tcm handles + * status response instead of the target core. + */ + if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) { + struct se_session *se_sess; + + se_sess = fu->tpg->tpg_nexus->tvn_se_sess; + sbitmap_queue_clear(&se_sess->sess_tag_pool, + cmd->se_cmd.map_tag, + cmd->se_cmd.map_cpu); + } else { + transport_generic_free_cmd(&cmd->se_cmd, 0); + } + + usb_ep_queue(fu->ep_cmd, cmd->req, GFP_ATOMIC); break; default: @@ -630,6 +720,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) return; cleanup: + stream->cmd = NULL; transport_generic_free_cmd(&cmd->se_cmd, 0); } @@ -645,6 +736,18 @@ static int uasp_send_status_response(struct usbg_cmd *cmd) return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); } +static int uasp_send_tm_response(struct usbg_cmd *cmd) +{ + struct f_uas *fu = cmd->fu; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); + struct response_iu *iu = &cmd->response_iu; + + iu->tag = cpu_to_be16(cmd->tag); + cmd->fu = fu; + uasp_prepare_response(cmd); + return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); +} + static int uasp_send_read_response(struct usbg_cmd *cmd) { struct f_uas *fu = cmd->fu; @@ -1045,9 +1148,24 @@ static int usbg_send_read_response(struct se_cmd *se_cmd) return uasp_send_read_response(cmd); } -static void usbg_cmd_work(struct work_struct *work) +static void usbg_submit_tmr(struct usbg_cmd *cmd) { struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); + struct se_session *se_sess; + struct se_cmd *se_cmd; + int flags = TARGET_SCF_ACK_KREF; + + se_cmd = &cmd->se_cmd; + se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess; + + target_submit_tmr(se_cmd, se_sess, + cmd->response_iu.add_response_info, + cmd->unpacked_lun, NULL, cmd->tmr_func, + GFP_ATOMIC, cmd->tag, flags); +} + +static void usbg_submit_cmd(struct usbg_cmd *cmd) +{ struct se_cmd *se_cmd; struct tcm_usbg_nexus *tv_nexus; struct usbg_tpg *tpg; @@ -1076,6 +1194,29 @@ static void usbg_cmd_work(struct work_struct *work) TCM_UNSUPPORTED_SCSI_OPCODE, 0); } +static void usbg_cmd_work(struct work_struct *work) +{ + struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); + + /* + * Failure is detected by f_tcm here. Skip submitting the command to the + * target core if we already know the failing response and send the usb + * response to the host directly. + */ + if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) + goto skip; + + if (cmd->tmr_func) + usbg_submit_tmr(cmd); + else + usbg_submit_cmd(cmd); + + return; + +skip: + uasp_send_tm_response(cmd); +} + static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, struct tcm_usbg_nexus *tv_nexus, u32 scsi_tag) { @@ -1102,37 +1243,63 @@ static void usbg_release_cmd(struct se_cmd *); static int usbg_submit_command(struct f_uas *fu, struct usb_request *req) { - struct command_iu *cmd_iu = req->buf; + struct iu *iu = req->buf; struct usbg_cmd *cmd; struct usbg_tpg *tpg = fu->tpg; struct tcm_usbg_nexus *tv_nexus; + struct uas_stream *stream; + struct command_iu *cmd_iu; u32 cmd_len; u16 scsi_tag; - if (cmd_iu->iu_id != IU_ID_COMMAND) { - pr_err("Unsupported type %d\n", cmd_iu->iu_id); - return -EINVAL; - } - tv_nexus = tpg->tpg_nexus; if (!tv_nexus) { pr_err("Missing nexus, ignoring command\n"); return -EINVAL; } - cmd_len = (cmd_iu->len & ~0x3) + 16; - if (cmd_len > USBG_MAX_CMD) - return -EINVAL; - - scsi_tag = be16_to_cpup(&cmd_iu->tag); + scsi_tag = be16_to_cpup(&iu->tag); cmd = usbg_get_cmd(fu, tv_nexus, scsi_tag); if (IS_ERR(cmd)) { pr_err("usbg_get_cmd failed\n"); return -ENOMEM; } - memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); - cmd->stream = &fu->stream[cmd->tag % USBG_NUM_CMDS]; + cmd->req = req; + cmd->fu = fu; + cmd->tag = scsi_tag; + cmd->se_cmd.tag = scsi_tag; + cmd->tmr_func = 0; + cmd->tmr_rsp = RC_RESPONSE_UNKNOWN; + + cmd_iu = (struct command_iu *)iu; + + /* Command and Task Management IUs share the same LUN offset */ + cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); + + if (iu->iu_id != IU_ID_COMMAND && iu->iu_id != IU_ID_TASK_MGMT) { + cmd->tmr_rsp = RC_INVALID_INFO_UNIT; + goto skip; + } + + stream->cmd = cmd; + + if (iu->iu_id == IU_ID_TASK_MGMT) { + struct task_mgmt_iu *tm_iu; + + tm_iu = (struct task_mgmt_iu *)iu; + cmd->tmr_func = uasp_to_tcm_func(tm_iu->function); + goto skip; + } + + cmd_len = (cmd_iu->len & ~0x3) + 16; + if (cmd_len > USBG_MAX_CMD) { + pr_err("invalid len %d\n", cmd_len); + target_free_tag(tv_nexus->tvn_se_sess, &cmd->se_cmd); + stream->cmd = NULL; + return -EINVAL; + } + memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); switch (cmd_iu->prio_attr & 0x7) { case UAS_HEAD_TAG: @@ -1153,9 +1320,7 @@ static int usbg_submit_command(struct f_uas *fu, struct usb_request *req) break; } - cmd->unpacked_lun = scsilun_to_int(&cmd_iu->lun); - cmd->req = req; - +skip: INIT_WORK(&cmd->work, usbg_cmd_work); queue_work(tpg->workqueue, &cmd->work); @@ -1301,6 +1466,9 @@ static int usbg_get_cmd_state(struct se_cmd *se_cmd) static void usbg_queue_tm_rsp(struct se_cmd *se_cmd) { + struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, se_cmd); + + uasp_send_tm_response(cmd); } static void usbg_aborted_task(struct se_cmd *se_cmd) diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index 5157af1b166b..7fafc4336984 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -82,8 +82,11 @@ struct usbg_cmd { u16 tag; u16 prio_attr; struct sense_iu sense_iu; + struct response_iu response_iu; enum uas_state state; - struct uas_stream *stream; + int tmr_func; + int tmr_rsp; +#define RC_RESPONSE_UNKNOWN 0xff /* BOT only */ __le32 bot_tag; @@ -96,6 +99,8 @@ struct uas_stream { struct usb_request *req_in; struct usb_request *req_out; struct usb_request *req_status; + + struct usbg_cmd *cmd; }; struct usbg_cdb { From patchwork Tue Jul 19 01:28:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 979DDCCA482 for ; Tue, 19 Jul 2022 01:54:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236262AbiGSBy0 (ORCPT ); Mon, 18 Jul 2022 21:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiGSByV (ORCPT ); Mon, 18 Jul 2022 21:54:21 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 392A265C1; Mon, 18 Jul 2022 18:54:20 -0700 (PDT) Received: from pps.filterd (m0297266.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26IMdcX9011679; Mon, 18 Jul 2022 18:28:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=dsx0v3KZyRAXYLFDkxI6YesZPcTkabKtSF1bHFjFvH0=; b=F8tVV0eG0TFaV1/QIEiyZGXvz2CxFs1kYi0K0usv13sDVeNQYg20H5c1dXVIXcX7GhX9 Ol7Y+RIVmjqutiLWqZ36TI7HZaVZV1NO/3yPwUmI4FD8qC6hbiHLM8xwYD8oJLxPTWSi WwPARLv+7yUYmmOnBSfZCaEHH4tJNLRzguT474CBfZ3+s0yHA78ImHs4fuautXf8nAxW c2f7gaCenjUN6R79+O6d28VSAO+vuNN/KqrenUTZpNORl5zq3q//c+Qm3FW1SwgoNb0j GDddrNyuwd2I/uPyIIyfnBtqxN6KKkChuyguj6pcmPdC4Dj9z4B7tuWntVLr4ImWkNiE Hw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whrv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:36 -0700 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id EB53BC0649; Tue, 19 Jul 2022 01:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194116; bh=sz9bKv1KPILgNQcgqxf2ikPC+5xnOP2hP/v91jBj7dU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=IjYCixwhFMA0CmOXKFZvkz6YqyexUAAEAQQqAVJqqJDZ0orEP/QiJSwZ2MRWDh3hn BJzgo9SbPAuFyqkbzv0t3jtEgVQBI8QeQGk97D4BWF5dUQWwLZ5bbqrGIIhARh7msN FTNY+fu6q2ZQVqyZDZTAOWOnrGTkO0hPbtj99HeIl6zqX7DIHlVCwWFo+qIciyk5Eh 9Rq87o2QFSdyJ0+NSujAyLHfAT8JG5YF6TNbYH8B/hE1uDZ/jvSgfJ1hLb8B0h8HIq aBE/e0oI4bAB+2AkTo/vc78sYEokh0ZXGWYR2svt4O/E2jHQANKPDIbL8G64HzSsDV ZA8SLk7t0l8vA== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id AD17FA006D; Tue, 19 Jul 2022 01:28:34 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:34 -0700 Date: Mon, 18 Jul 2022 18:28:34 -0700 Message-Id: <0150d7b669ad80e94596b371cbce0460a327ce7c.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 24/25] usb: gadget: f_tcm: Check overlapped command To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-GUID: Bi9Hoo4uTMd3TW6s4mx5mSgnAMd-9i5C X-Proofpoint-ORIG-GUID: Bi9Hoo4uTMd3TW6s4mx5mSgnAMd-9i5C X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=999 malwarescore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If there's an overlapped command tag, cancel the command and respond with RC_OVERLAPPED_TAG to host. Signed-off-by: Thinh Nguyen --- Changes in v2: - New patch. It was part of TASK MANAGEMENT change. - Directly respond to host on overlapped tag instead of reporting to target core. drivers/usb/gadget/function/f_tcm.c | 75 ++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 8b99ee07df87..dfa3e7c043a3 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -692,6 +692,15 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) break; case UASP_QUEUE_COMMAND: + /* + * Overlapped command detected and cancelled. + * So send overlapped attempted status. + */ + if (cmd->tmr_rsp == RC_OVERLAPPED_TAG && + req->status == -ECONNRESET) { + uasp_send_tm_response(cmd); + return; + } stream->cmd = NULL; @@ -700,7 +709,8 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) * bitmap index. This is for the cases where f_tcm handles * status response instead of the target core. */ - if (cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) { + if (cmd->tmr_rsp != RC_OVERLAPPED_TAG && + cmd->tmr_rsp != RC_RESPONSE_UNKNOWN) { struct se_session *se_sess; se_sess = fu->tpg->tpg_nexus->tvn_se_sess; @@ -1080,6 +1090,14 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) cleanup: target_put_sess_cmd(se_cmd); + + /* Command was aborted due to overlapped tag */ + if (cmd->state == UASP_QUEUE_COMMAND && + cmd->tmr_rsp == RC_OVERLAPPED_TAG) { + uasp_send_tm_response(cmd); + return; + } + transport_send_check_condition_and_sense(se_cmd, TCM_CHECK_CONDITION_ABORT_CMD, 0); } @@ -1148,9 +1166,10 @@ static int usbg_send_read_response(struct se_cmd *se_cmd) return uasp_send_read_response(cmd); } +static void usbg_aborted_task(struct se_cmd *se_cmd); + static void usbg_submit_tmr(struct usbg_cmd *cmd) { - struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); struct se_session *se_sess; struct se_cmd *se_cmd; int flags = TARGET_SCF_ACK_KREF; @@ -1214,6 +1233,51 @@ static void usbg_cmd_work(struct work_struct *work) return; skip: + if (cmd->tmr_rsp == RC_OVERLAPPED_TAG) { + struct se_session *se_sess; + struct uas_stream *stream; + + se_sess = cmd->fu->tpg->tpg_nexus->tvn_se_sess; + stream = uasp_get_stream_by_tag(cmd->fu, cmd->tag); + + /* + * There's no guarantee of a matching completion order between + * different endpoints. i.e. The device may receive a new (CDB) + * command request completion of the command endpoint before it + * gets notified of the previous command status completion from + * a status endpoint. The driver still needs to detect + * misbehaving host and respond with an overlap command tag. To + * prevent false overlapped tag failure, give the active and + * matching stream id a short time (1ms) to complete before + * respond with overlapped command failure. + */ + msleep(1); + + /* If the stream is completed, retry the command. */ + if (!stream->cmd) { + usbg_submit_command(cmd->fu, cmd->req); + return; + } + + /* + * The command isn't submitted to the target core, so we're safe + * to remove the bitmap index from the session tag pool. + */ + sbitmap_queue_clear(&se_sess->sess_tag_pool, + cmd->se_cmd.map_tag, + cmd->se_cmd.map_cpu); + + /* + * Overlap command tag detected. Cancel any pending transfer of + * the command submitted to target core. + */ + stream->cmd->tmr_rsp = RC_OVERLAPPED_TAG; + usbg_aborted_task(&stream->cmd->se_cmd); + + /* Send the response after the transfer is aborted. */ + return; + } + uasp_send_tm_response(cmd); } @@ -1282,6 +1346,13 @@ static int usbg_submit_command(struct f_uas *fu, struct usb_request *req) goto skip; } + stream = uasp_get_stream_by_tag(fu, scsi_tag); + if (stream->cmd) { + pr_err("Command tag %d overlapped\n", scsi_tag); + cmd->tmr_rsp = RC_OVERLAPPED_TAG; + goto skip; + } + stream->cmd = cmd; if (iu->iu_id == IU_ID_TASK_MGMT) { From patchwork Tue Jul 19 01:28:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 592370 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48FB8C433EF for ; Tue, 19 Jul 2022 01:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235211AbiGSBrw (ORCPT ); Mon, 18 Jul 2022 21:47:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiGSBrv (ORCPT ); Mon, 18 Jul 2022 21:47:51 -0400 X-Greylist: delayed 197 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 18 Jul 2022 18:47:50 PDT Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA331B7A9; Mon, 18 Jul 2022 18:47:50 -0700 (PDT) Received: from pps.filterd (m0297266.ppops.net [127.0.0.1]) by mx0a-00230701.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26J15LEr011685; Mon, 18 Jul 2022 18:28:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=synopsys.com; h=date : message-id : in-reply-to : references : from : subject : to : cc; s=pfptdkimsnps; bh=nuHVSWCgl9dwD0wByFXYvmOFMYvn1dm33E7o/YfdqrY=; b=b4Smb5ZFNadz6txMBipOo46sdJ3CaFE63gOYfnJWcwSoRua4xxZYySvhvKCb6zsNSZRq g85UHtxAuNCfM0nVxa0CVdCpHpNCUNhC1ZeoDW9nz4Zf2n2hAnt0K10RdfbcxfhQZEwe oz9YVB69o0rCSWBLX7BFgekHNpurCiBXcnGq/LVnX/0Fd+I9YOyaDUw9UTd4N1bjx1Bl JJCEc4wq171MmvcIEeEiq901MbrotZFa4FczZNb0I/J+TDMk/3eg6v4Jmz92ijD+H1pu D2Cmn7BBeCXf4wpmiNIlx4460NqrEJ+nKkIQaE9QtOfLVrvhWdOM6VUnjo7/tU5WPKne 5g== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whs7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:42 -0700 Received: from mailhost.synopsys.com (sv1-mailhost2.synopsys.com [10.205.2.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mailhost.synopsys.com", Issuer "SNPSica2" (verified OK)) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 10A6BC0649; Tue, 19 Jul 2022 01:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194122; bh=HXpi+zxefL7ycJivlkZYu4nzewzzTh6ZNR2/6Q/0HNU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=C8SUhXbjLJ3if4wFdDLLFvdmLTKOdNAA3ZJHB8CUVF8EKUXzizs0hP94IOK27QyqF 52Yko+tCl0Nz/E4n92fl+aHxyxB1gxfMreqNh7enX+vpTb5gN26FY2UKo27k+4FFCl cKjlvyeEcLsEflsTRd6T1zSYTyRIPQXXCAaS6Z8vdKjBXuGjk6SdRsag92YdfGRS5K 6hJsi5JzHOwzK6+6q+eamTI9UHXwfh5w6jjh1LVAL7575LuYklIyfY9DgI7IBRc/eG a9gLiEtbFkh2+qDzttS//72h3wc4P8PNhh7EiuvPxUT8JTg/9TSCjT85nWw3sHdqFY /8ew9dSLhhYiA== Received: from te-lab16-v2 (nanobot.internal.synopsys.com [10.204.48.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mailhost.synopsys.com (Postfix) with ESMTPSA id C92F8A006D; Tue, 19 Jul 2022 01:28:40 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:40 -0700 Date: Mon, 18 Jul 2022 18:28:40 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 25/25] usb: gadget: f_tcm: Comply with UAS Task Management requirement To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-GUID: _F5FVp5rpwqkwXYASrUTrMfRvAALCqWr X-Proofpoint-ORIG-GUID: _F5FVp5rpwqkwXYASrUTrMfRvAALCqWr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_22,2022-07-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_active_cloned_notspam policy=outbound_active_cloned score=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxlogscore=987 malwarescore=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207190004 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The UASP driver must support all the task management functions listed in Table 20 of UAS-r04. However, not all of them are implemented in the Target core. To remain compliant while indicate that the TMR did not go through, report RC_TMF_FAILED instead of RC_TMF_NOT_SUPPORTED and print a warning to the user. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index dfa3e7c043a3..727d7c3e61c2 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -643,6 +643,30 @@ static void uasp_prepare_response(struct usbg_cmd *cmd) rsp_iu->response_code = tcm_to_uasp_response(se_cmd->se_tmr_req->response); + /* + * The UASP driver must support all the task management functions listed + * in Table 20 of UAS-r04. To remain compliant while indicate that the + * TMR did not go through, report RC_TMF_FAILED instead of + * RC_TMF_NOT_SUPPORTED and print a warning to the user. + */ + switch (cmd->tmr_func) { + case TMR_ABORT_TASK: + case TMR_ABORT_TASK_SET: + case TMR_CLEAR_TASK_SET: + case TMR_LUN_RESET: + case TMR_I_T_NEXUS_RESET: + case TMR_CLEAR_ACA: + case TMR_QUERY_TASK: + case TMR_QUERY_TASK_SET: + case TMR_QUERY_ASYNC_EVENT: + if (rsp_iu->response_code == RC_TMF_NOT_SUPPORTED) { + pr_warn("TMR function %d not supported\n", + cmd->tmr_func); + rsp_iu->response_code = RC_TMF_FAILED; + } + break; + } + stream->req_status->is_last = 1; stream->req_status->stream_id = cmd->tag; stream->req_status->context = cmd;