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: 12922011 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 4E200C43334 for ; Tue, 19 Jul 2022 02:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236694AbiGSCGB (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: target-devel@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: 12921999 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 22F99C433EF for ; Tue, 19 Jul 2022 02:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236654AbiGSCCE (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: target-devel@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: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: 12922063 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 D5328C43334 for ; Tue, 19 Jul 2022 02:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236539AbiGSCYu (ORCPT ); Mon, 18 Jul 2022 22:24:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbiGSCYt (ORCPT ); Mon, 18 Jul 2022 22:24:49 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E92033E20; Mon, 18 Jul 2022 19:24:48 -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 26ILoCF6020763; Mon, 18 Jul 2022 18:26:25 -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=wJLBErIwYYuh2hawl3dyRP19SnzNtsp24HjH65Z2HG8=; b=LB2kEkZHqHjFisGsOAhyhkG7edkLWVm7ix45nNw9O4uvf/rC3opylgYYrUKFPOaUYplo Tno/cB1M2QiyG2Kn7Wh3a5R71ZqZ5Gd82MbUDskvCzE3Hp9YpmjqVwXEokDRXfYXK8+W DVol6NhLEgL3Gh3HV1VLhDqBPeiH7tjVIYU9FxxCK3I0A1+4xXfzPSgyjDl3HcaZw4qI gK2q6krcI3UFoMF9bwOJGxjE25TD2zXiiGPJkEzzIR/jLiYl7x2Emxu32QaguKoRfJ4J 43HJe1UySYbZU1g0ztUIoL4uffplEcQIaWKVnzaPx5U2QVeAFJWFimNZDkRvrvF5mJGj oQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 3hc6c344w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:25 -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 9A9E0C0649; Tue, 19 Jul 2022 01:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658193984; bh=rV2b9OgEtHbGnZVIuN0NlxP74jauj/eZVINv1IvF/24=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=JPoEEy39bnGv532h6w1knmPNe3NfcPQacVvtQ6xwCHfWV6KBpm+X6Hc7nQPPnE1PR 7bU1egqy2utfc8wa8YwWe4FyL11S4efF1sYsT6lSz+qdKLvqelLhKbehlBtdFvZmio ESuQQqJtyhB5RGKw6UkYORbX60BgBZnW+1JYFVRkMgbQDOG7kPUIRJCwL2nFjvnCb/ UJcGtK+MYmVQ9qxvEsSRl63x+DrxSXxwJlnhpOZj3iBz3lOwbau6sw0LoRnkhGWQjU AbOuPbKZvNyI09Dv91BG91sBS03wrG9P4BUTqR0RvFamVFGrUTXuncSkkb6m/GKfxL QvZZsI2tjBRPg== 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 EC046A0068; Tue, 19 Jul 2022 01:26:22 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:22 -0700 Date: Mon, 18 Jul 2022 18:26:22 -0700 Message-Id: <79dbca4db65f676df37462b7a008198c81a3297e.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 03/25] usb: gadget: f_tcm: Increase stream count To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: _6NFdC33YKtdkKoJ-b64cooS6uPQgnTM X-Proofpoint-GUID: _6NFdC33YKtdkKoJ-b64cooS6uPQgnTM 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=723 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: target-devel@vger.kernel.org Some old builds of Microsoft Windows 10 UASP class driver reject USAP device with stream count of 2^4. To keep compatibility with both Linux and Windows, let's increase the stream count to 2^5. Also, internal tests show that stream count of 2^5 increases performance slightly. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/tcm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index 3cd565794ad7..6cb05dcd19ff 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -13,7 +13,7 @@ #define USBG_NAMELEN 32 #define fuas_to_gadget(f) (f->function.config->cdev->gadget) -#define UASP_SS_EP_COMP_LOG_STREAMS 4 +#define UASP_SS_EP_COMP_LOG_STREAMS 5 #define UASP_SS_EP_COMP_NUM_STREAMS (1 << UASP_SS_EP_COMP_LOG_STREAMS) enum { From patchwork Tue Jul 19 01:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922012 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 BC679C433EF for ; Tue, 19 Jul 2022 02:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236641AbiGSCGz (ORCPT ); Mon, 18 Jul 2022 22:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235510AbiGSCGy (ORCPT ); Mon, 18 Jul 2022 22:06:54 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A5D3C8D9; Mon, 18 Jul 2022 19:06:53 -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 26ILooam020734; Mon, 18 Jul 2022 18:26:31 -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=5JtutWQ3TvVbO9MexC8Mla+M0EsNrFxPIoJRfZIzkIA=; b=GmUGd/WqaXGlCOJjolQhAzofyZnqQ80rWXby0hsxHFm173MuxVMqJnz/yfVbFdQScbSl oXI5zDUf2wMJgkoKdCa2M7tPH/VXQ6AngDnWRypUBgcge4lbsEDBlXwy71QaEdigQDOt epnI5ngN+U+7BeOFcTUOEVpMNtgbD7P62/hbxk2/Ce6p4A2by/9bB7z5ETRJAM03hB3D iZ7vrmO64DrxKRo72wYkeJw9g3CM687PTu041HB9NfFKNYz7QWJyI7Asnwgxw8ss8Ew8 D14+7ynAFh+j9oOmTnZ2ct9nrdJxRhD3xPaxmyjTmMEqx1kLgRRd0SoqNUR8T0HmCPsh Fw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0b-00230701.pphosted.com (PPS) with ESMTPS id 3hc6c344we-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:31 -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 B6AD6C0649; Tue, 19 Jul 2022 01:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658193990; bh=g644d0gYPJVQYiL4nKwFKzkvaaT1M/KFt0n+kHVCwEs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=RN6mUNigP63geO2l9KAsaLAAjMKuBsniGJqWPw5bvISJ8s6k8AcaNEhHfShS9Hj1e TCFdnaaIQ8+pCxF7tZjegAh/eobt3QyoZcD1gshwsTr9e6Yri15wwGSOCdqd8HbonT zR8PM14hY7dIl8+W9z8Kp/CSozRvXRZg7Krb6/6vaalyA/gD5999mFQXUeUFEfDCL6 EVXWhRXvlmI/Wkc84JmsDRLhRQN2L75cy1a65N5FZmWnZyI6O7o9ieCX8ytz+GdM/s 6hvkI8pd908R/5BOhC9O6CQn5SPbmZCu+AfASYktBWeZ+SzOLED/FK9+yxjk4ntnkb hgogrf5etZj7g== 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 7B898A0096; Tue, 19 Jul 2022 01:26:29 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:29 -0700 Date: Mon, 18 Jul 2022 18:26:29 -0700 Message-Id: <93ccca7015e6b10e904c26fd2653c6026b606644.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 04/25] usb: gadget: f_tcm: Increase bMaxBurst 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: iOya1dphKypYK6_ArQddTz3Ae_OWd1NU X-Proofpoint-GUID: iOya1dphKypYK6_ArQddTz3Ae_OWd1NU 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=756 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: target-devel@vger.kernel.org Currently the default bMaxBurst is 0. Set default bMaxBurst to 15 (i.e. 16 bursts) to Data IN and OUT endpoints to improve performance. It should be fine for a controller that supports less than 16 bursts. It should be able to negotiate properly with the host at packet level for the end of burst. If the controller can't handle a burst of 16, and high performance isn't important, the user can use BOT protocol from mass_storage gadget driver instead. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 8e17ac831be0..270ec631481d 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1774,7 +1774,7 @@ static struct usb_endpoint_descriptor uasp_ss_bi_desc = { static struct usb_ss_ep_comp_descriptor uasp_bi_ep_comp_desc = { .bLength = sizeof(uasp_bi_ep_comp_desc), .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, - .bMaxBurst = 0, + .bMaxBurst = 15, .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, .wBytesPerInterval = 0, }; @@ -1782,7 +1782,7 @@ static struct usb_ss_ep_comp_descriptor uasp_bi_ep_comp_desc = { static struct usb_ss_ep_comp_descriptor bot_bi_ep_comp_desc = { .bLength = sizeof(bot_bi_ep_comp_desc), .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, - .bMaxBurst = 0, + .bMaxBurst = 15, }; static struct usb_endpoint_descriptor uasp_bo_desc = { @@ -1817,12 +1817,14 @@ static struct usb_endpoint_descriptor uasp_ss_bo_desc = { static struct usb_ss_ep_comp_descriptor uasp_bo_ep_comp_desc = { .bLength = sizeof(uasp_bo_ep_comp_desc), .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, + .bMaxBurst = 15, .bmAttributes = UASP_SS_EP_COMP_LOG_STREAMS, }; static struct usb_ss_ep_comp_descriptor bot_bo_ep_comp_desc = { .bLength = sizeof(bot_bo_ep_comp_desc), .bDescriptorType = USB_DT_SS_ENDPOINT_COMP, + .bMaxBurst = 15, }; static struct usb_endpoint_descriptor uasp_status_desc = { 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: 12922057 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 54716CCA479 for ; Tue, 19 Jul 2022 02:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236895AbiGSCSz (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: target-devel@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: 12921984 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 090B4C43334 for ; Tue, 19 Jul 2022 01:57:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236441AbiGSB55 (ORCPT ); Mon, 18 Jul 2022 21:57:57 -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: target-devel@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:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922082 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 DD524C43334 for ; Tue, 19 Jul 2022 03:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235828AbiGSDUm (ORCPT ); Mon, 18 Jul 2022 23:20:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234935AbiGSDUi (ORCPT ); Mon, 18 Jul 2022 23:20:38 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC38A24F25; Mon, 18 Jul 2022 20:20:28 -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 26ILeY2P029326; Mon, 18 Jul 2022 18:26:50 -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=M180YcUp4LTEpyCxleR4FVpckgymUrgVO89H/11fMPg=; b=GQW344vCkoFDSgBVShL5hSEsap/SwqnYUokefgIHtfSTbU4o+ywg4rvDf7P5kU5anvYV Qefx6ohxo9S+FylUqTMP32SHlWrsPgXKiefvGyto4Ja/Ex3MRO/6mm/ietKs7ycj5VrF NABjyLDh1HRXoPgkNng0nhPtCcctLVUrczFqILygu/HwfEDl2vvCClfacXVvn0Si7Ui6 Ajg77x4UAT6ENHFnWP6CYm3VjWI9q5NFbnrWXZiOzW34KRwpxcOFwsWdKQc9Ih5GERD4 M67WN3cJiAr8tsnA3Dc5p18frSmw7iV2gzvZsfQ9IVcDwtGWqzDQxaNW8U4fgpU0FvYo QQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5fa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:26:50 -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 286CF4008A; Tue, 19 Jul 2022 01:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194009; bh=tNgndfD1F79ARxp0mVGVrV9+gTpVlt3d7W6aaKNj5QY=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=go8OJejElGgKpXSj0lOdvZudMCsBEc2JNCkOyrKcOlW231kjaSA1O8/UO/vqK14AI y6rVO2wSyE3MW9YaHU7y2P6oPAGDG6V45JhM/SxGQLYPh/yeBfCLy0i6iS1VtxABKB J4oS5JbpFFUXqCa1McoQ8ZpXkcXoHILEeOnlnBXwNN5P/wFbXjA25WHWMJjZvp16J1 wbaXZPWUWTdnXKOwowmX+2rzVQYvH5NT4gwekuqHq3wpgkpV0x59HmE7785G/il3ct 4H7ZXFZJw6AR4YXGZC9CMaAHxzfpzOasNGfPnrhD0KnqaSs3xhPS1XJ0dcc2R/lFBR pwz5sDHTyLPAA== 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 09316A0068; Tue, 19 Jul 2022 01:26:48 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:26:47 -0700 Date: Mon, 18 Jul 2022 18:26:47 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 07/25] usb: gadget: f_tcm: Limit number of sessions To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: N8n_EpjNDkF3a89Yh31weB8Mttcz4h-Q X-Proofpoint-GUID: N8n_EpjNDkF3a89Yh31weB8Mttcz4h-Q 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=908 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: target-devel@vger.kernel.org Only allocate up to USBG_NUM_CMDS number of session tags. We should not be using more than USBG_NUM_CMDS of tags due to the number of commands limit we imposed. Each command uses a unique tag. Any more than that is unnecessary. By limitting it, we can detect an issue in our driver immediately should we run out of session tags. Signed-off-by: Thinh Nguyen --- Changes in v2: - Add more comments in change log for the change reason. drivers/usb/gadget/function/tcm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index bcbe35bb5015..df768559fb60 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -26,7 +26,7 @@ enum { #define USB_G_ALT_INT_BBB 0 #define USB_G_ALT_INT_UAS 1 -#define USB_G_DEFAULT_SESSION_TAGS 128 +#define USB_G_DEFAULT_SESSION_TAGS USBG_NUM_CMDS struct tcm_usbg_nexus { struct se_session *tvn_se_sess; 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: 12922037 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 A1E0DC433EF for ; Tue, 19 Jul 2022 02:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236718AbiGSCJN (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: target-devel@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:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922014 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 72FFFCCA485 for ; Tue, 19 Jul 2022 02:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236754AbiGSCHB (ORCPT ); Mon, 18 Jul 2022 22:07:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236733AbiGSCG6 (ORCPT ); Mon, 18 Jul 2022 22:06:58 -0400 Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 314D23C8F6; Mon, 18 Jul 2022 19:06: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 26J0KFhM029346; Mon, 18 Jul 2022 18:27:02 -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=EJyimqz53Z0T6wkrPrc8lFhAbEkc9ytvO6P5ConP0C0=; b=V9/prvsaFea9IAzldImSOmFTzluHFRh45/K7n5stYkUcDrR8kSC9xagy8t1hvlaRfIjO cFU3gevrMvx43dg3lljBR31dgAXjsC7Y0jN3ciLSSw+bi8ONxS9cNcmn38dtq4NqDUE9 EUNEZLujD8tFGryu5fsiv1s+HhiE4LLfsanraBd1anZWUb7hK3kgvS+iXyQ/Hh7zVLQx k5LmPJ8jLuYQY9P6iTDi/zrdOyI9u47gaut9WBA0Y7Sdzwfi00/RdF/kOc+MemAbpqZs /4o6eQDkJ7nX/4guM7ubVPiCwXGVRrdg/x90IM0FCYjzzAj3/4ryR/OGcxvMEpl7V+EJ 7Q== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5h5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:02 -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 60BFE4008A; Tue, 19 Jul 2022 01:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194021; bh=IyeW+hiZulNtLHbEM02GHa7eRIJF78uaYlraYY09p+g=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=NGDU90r7k75Ps4+1Q81huYDF6Pc5Wk3TrhAX6Ff8XPR3Ijc38r6JNtdOXA5UHgklc 8Qhe9jAQUre+y9EcDOSclXsIYUBBV26pWSImw+kXALTg6l8yYlRTb6iHXUR186v8VL 0PveTwPkDsXzc9Qc3/ed4g7yavH8RQfsaq75aW4wkz8gKVvW4cqKQqe3Pwo4VpNxoI 6O8MrPXyhN6FBH7b9mAJ/M586+YwtsvIBOCjmwBi6EqkygfKDltH3NT7lgOFcyfHrX mLwtBE4uI37Rg4IQOn3DMapoUxfVMF2lgWaz8VA6EyNaHGm03dP7EuVFaRTlXGyTzz aGeKaXpY7u+xg== 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 3F2CEA0068; Tue, 19 Jul 2022 01:27:00 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:00 -0700 Date: Mon, 18 Jul 2022 18:27:00 -0700 Message-Id: <3310604a0940fd3029404b9d7ba3cdf2800f6cf4.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 09/25] usb: gadget: f_tcm: Use extra number of commands To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org X-Proofpoint-ORIG-GUID: iP87kAFGM-EMiXa5S4qBH4EVUQdHyXnI X-Proofpoint-GUID: iP87kAFGM-EMiXa5S4qBH4EVUQdHyXnI 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=662 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: target-devel@vger.kernel.org To properly respond to host sending more commands than the number of streams the device advertises, the device needs to be able to reject the command with a response. Allocate an extra request to handle 1 more command than the number of streams. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/tcm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index df768559fb60..c7e6d36afd3a 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -16,7 +16,7 @@ #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 +#define USBG_NUM_CMDS (UASP_SS_EP_COMP_NUM_STREAMS + 1) enum { USB_G_STR_INT_UAS = 0, 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: 12921997 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 DFA0EC433EF for ; Tue, 19 Jul 2022 01:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235991AbiGSB75 (ORCPT ); Mon, 18 Jul 2022 21:59:57 -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: target-devel@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:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12921983 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 D2DF4C433EF for ; Tue, 19 Jul 2022 01:57:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236262AbiGSB5N (ORCPT ); Mon, 18 Jul 2022 21:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236514AbiGSB5K (ORCPT ); Mon, 18 Jul 2022 21:57:10 -0400 X-Greylist: delayed 126 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 18 Jul 2022 18:56:54 PDT Received: from mx0b-00230701.pphosted.com (mx0b-00230701.pphosted.com [148.163.158.9]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE0943AB15; Mon, 18 Jul 2022 18:56: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 26J0KFhO029346; Mon, 18 Jul 2022 18:27:15 -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=a7LvvtmsDCzq5sgn7YADzX4n9vJFy5h9YpSPqPmsSoc=; b=X42QkjNQ7dbxfkfa9IVirwPWrNTfIuTtWYHHwi0ZsBDRLY+CYPqIYYB9t4RpCkF0XUWx qYEYRMB/7aiVPM8/SzHWilABIvYf67nFMw2l5IAaU1A7DpiGxfrFyT2lr/Q6pzR+VuXI Va9O8N9YJNB/PWR8IeE6GvOcyROU9Xju4b/xhCfcsllGhyn9MrtDW/Lf90v6q2TG/Mgv aKtEJegKNlYQPANdapYuZB++yGJllnZ/Ex9CxbI0zgO6aNxjUyBVSc/8Lshw+bBzqcRn lzKTTXrhGH9li+WPxM3MRcBLdiUyTjfHYnB4YRBfn6VWEiPA0Qc1nEukyV3n4Mw21XK7 BA== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hc6dec5hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:15 -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 7EF884008A; Tue, 19 Jul 2022 01:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194034; bh=HR+//0OTCdoeUXuBkPE2suel5h52O0aLq+A26bTyDp4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ACZ2dylA6K7PLVGRw3l2IUmYpxVOxGmS/Qubu7SCQ+4WWSBIeoTRMjPOnyaIny+dk wkjMSWZHwyVuKei/S/F12RI8f8K1z7f5uAio39u7bNMJTfPxIkGJSe5mMDBzX3GtRk FHCEQBBOo4f8K1zRffA7e//NwmM6thHFsTdlXQtS45gl7SaD2/VvWVfKTlPaolCkHS UHevXONCbHe4+hXqXynH6e9RZco7xhyYzKGHyNWTsgxLhertNKWDaXLlm8xXLM2H3B UuwlgEUpf83hESC/CEvmxgH3SYoiuukew2ugCtcqE35jbTZRWmyG/rOIzLIpkiIp+j 0APpdzgApTj+A== 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 CBC85A006D; Tue, 19 Jul 2022 01:27:12 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:12 -0700 Date: Mon, 18 Jul 2022 18:27:12 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 11/25] usb: gadget: f_tcm: Execute command on write completion 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: CZESAK36mznakSqxAX5nFh2OGbrPNBUn X-Proofpoint-GUID: CZESAK36mznakSqxAX5nFh2OGbrPNBUn 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=947 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: target-devel@vger.kernel.org Don't just wait for the data write completion and execute the target command. We need to verify if the request completed successfully and not just sending invalid data. The verification is done in the write request completion routine, so we can just run target_execute_cmd() there. The wait for the data write is not needed. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 8 +------- drivers/usb/gadget/function/tcm.h | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 6fea80afe2d7..ec83f2f9a858 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -248,7 +248,6 @@ static int bot_send_write_request(struct usbg_cmd *cmd) struct usb_gadget *gadget = fuas_to_gadget(fu); int ret; - init_completion(&cmd->write_complete); cmd->fu = fu; if (!cmd->data_len) { @@ -279,8 +278,6 @@ static int bot_send_write_request(struct usbg_cmd *cmd) if (ret) pr_err("%s(%d)\n", __func__, __LINE__); - wait_for_completion(&cmd->write_complete); - target_execute_cmd(se_cmd); cleanup: return ret; } @@ -685,7 +682,6 @@ static int uasp_send_write_request(struct usbg_cmd *cmd) struct sense_iu *iu = &cmd->sense_iu; int ret; - init_completion(&cmd->write_complete); cmd->fu = fu; iu->tag = cpu_to_be16(cmd->tag); @@ -717,8 +713,6 @@ static int uasp_send_write_request(struct usbg_cmd *cmd) pr_err("%s(%d)\n", __func__, __LINE__); } - wait_for_completion(&cmd->write_complete); - target_execute_cmd(se_cmd); cleanup: return ret; } @@ -955,7 +949,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) se_cmd->data_length); } - complete(&cmd->write_complete); + target_execute_cmd(se_cmd); return; cleanup: diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index c7e6d36afd3a..5157af1b166b 100644 --- a/drivers/usb/gadget/function/tcm.h +++ b/drivers/usb/gadget/function/tcm.h @@ -74,7 +74,6 @@ struct usbg_cmd { struct se_cmd se_cmd; void *data_buf; /* used if no sg support available */ struct f_uas *fu; - struct completion write_complete; struct kref ref; struct usb_request *req; From patchwork Tue Jul 19 01:27:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922010 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 14DB8C43334 for ; Tue, 19 Jul 2022 02:03:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235991AbiGSCDZ (ORCPT ); Mon, 18 Jul 2022 22:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbiGSCDY (ORCPT ); Mon, 18 Jul 2022 22:03:24 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE95B3B97E; Mon, 18 Jul 2022 19:03:23 -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 26IMIaO9011734; Mon, 18 Jul 2022 18:27:21 -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=5p7YrDBdLa0/d/BEqV9bZhGLXEdirc45pHjB+sUzbD4=; b=fWoF6g4Y/U+hbPFUMNybgDLpwNaLQjVdTO5++xssFfoNp71rClstekSnpwWuqZvuPLIb bR77zlrY6pWKq0QYov4EImkM2rUXho9kUIoNaN1RiyEf+zF19QdDJ4/mn1k0nhyTi0pd ygCiKlXItofB8C6VJaWaQ2tTqLydNI+CYFGn3GyqVo5GNY66c2OMmpZjLtdjxuwMJ+L1 IKnyg6zinlGateldFi6gZ7i8NQKPDopUg7Drub70mbWJOo28TfbfwMtdrO9aXRX/8ljF 0o7CfMdEF+FZ/z0ICJQJPm1/Dfwv1fbaJ+L8SKY+Ne6jffbO9RO/5dkWX8kzQwZ7fjA4 4g== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whmb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:21 -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 B7BACC0649; Tue, 19 Jul 2022 01:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194040; bh=IMazAZqLEBIxNJhRkGrUVaJ9d5nGkSk8QFUqoizUzzE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=k89Ay8ftqZ1RT3wNsQk+e1e+iMnyWDdzTE8wMPHs7M/+9ZmoVPdTcgLMZ4ydOHTCk JVvsw5Z1tuaFcGu4UsiIk70CTVA8yZo0Tflv1VxybNv4XkhM6f6FHODX+f7j7Iw8bA j7yEsv8m++CxJ1sCO6CrtkVbv7QhJU+28Afz/28GzI6RKwPIXN8+xNhpam1KTDnYy4 wqnR8qknomZHi0nX1dLr5A9tbecXc4gsmj21hPpBVPhJHNH2I/6hJ1tr472NCb7j8Y iNIdNvkiuKrhrd2DtQ2eSbKJ/QLrVINIbDDyulHN2lWQQnWDWKJ9Te+qhBtlvM48AX KZ/X49NbIGaHA== 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 7B91BA0068; Tue, 19 Jul 2022 01:27:19 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:19 -0700 Date: Mon, 18 Jul 2022 18:27:19 -0700 Message-Id: <7e236a9022761be52c39638321b959cf0f00bc0c.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 12/25] usb: gadget: f_tcm: Minor cleanup redundant code 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: FWOJ_yoTyd55J047IesOkj-qf3NbchPn X-Proofpoint-ORIG-GUID: FWOJ_yoTyd55J047IesOkj-qf3NbchPn 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=888 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: target-devel@vger.kernel.org The status request preparation is done in uasp_prepare_status(). Remove duplicate code. No functional change here. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index ec83f2f9a858..53b178ad4f90 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -624,8 +624,6 @@ static int uasp_send_status_response(struct usbg_cmd *cmd) struct sense_iu *iu = &cmd->sense_iu; iu->tag = cpu_to_be16(cmd->tag); - stream->req_status->complete = uasp_status_data_cmpl; - stream->req_status->context = cmd; cmd->fu = fu; uasp_prepare_status(cmd); return usb_ep_queue(fu->ep_status, stream->req_status, GFP_ATOMIC); From patchwork Tue Jul 19 01:27:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922038 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 F3691C43334 for ; Tue, 19 Jul 2022 02:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236615AbiGSCLo (ORCPT ); Mon, 18 Jul 2022 22:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235521AbiGSCLm (ORCPT ); Mon, 18 Jul 2022 22:11:42 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 358472A97F; Mon, 18 Jul 2022 19:11:42 -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 26ILhi6e002271; Mon, 18 Jul 2022 18:27:29 -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=0YDOTLFLGfQtmls8fcXazGD6uzhGVaDdgiSn1jTpAOw=; b=tey3YVUMnh3/Tq/HyydHuK9lwcufUEHrC126u2Sk1ietLycxYRQL2pW8meOeXTkjufbq sOQUnGRbQl72QoTAqoSxzxxyb1/E9TxgHtq4deElnsabMczvxEAlIHaROeQwVz9VlGoP bs4vt/VQ/k8d+qylmDNMqVBfNdBqR/ugq1PVPFJ8lBKlwYDCfxsyE4GIzwa/eDy/q4Ap Y1lDOWmHqAUnKOGAcoWn4U44Dy7rHrPlh//P5KyAncI3EyIainANMPfEcIGOYpYBvIFR sB5Hw7VNA8d8o1WcWTRB7U0Fwlicyor+IFS1tNxz0ETL04D6IAxVLHkPe8iq7VP520xP hQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhsn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:29 -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 C34824008A; Tue, 19 Jul 2022 01:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194048; bh=9C/C9peMaFH4yIQhG0ciT8FsvOej0rEdfJ3PBquPxfM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=E9ufCstSdSRtG73L/Len2FUUsTDv7JCwmpkbiMb4/27qm4rfUTzxXgGgG92xwD892 ovHZbSFDZmm8rWKnsFlISkY/CHYW4g1N2pVF+zLtl/UTmiet1sLX+vp7ZSPDO3Ewc6 SEssvx5KM6CtFxddK5LT8F3pziS0AiZNqgImDKS95UENkK5+tHiXgj8T74tydLyyIE Dx64YWYk5moyClsX2dpqyqdT1URd5WttKfyxpuiatBVBnB6iOt66aE1PucxDUxPUQq 4P26E1aZ7pUUM3R136oDjNPBhlfA2TqLPNDvNG8E+fqXeGsz+f+qc290lIK0pRvynv 7MUiY4sh6iWZQ== 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 98FD1A006D; Tue, 19 Jul 2022 01:27:25 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:25 -0700 Date: Mon, 18 Jul 2022 18:27:25 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 13/25] usb: gadget: f_tcm: Don't free command immediately To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov , Nicholas Bellinger Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Andrzej Pietrasiewicz , Sebastian Andrzej Siewior X-Proofpoint-GUID: JB4qvKEf7fG-WmXvAIZ3On8z9ukdRAV_ X-Proofpoint-ORIG-GUID: JB4qvKEf7fG-WmXvAIZ3On8z9ukdRAV_ 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=685 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: target-devel@vger.kernel.org Don't prematurely free the command. Wait for the status completion of the sense status. It can be freed then. Otherwise we will double-free the command. Fixes: cff834c16d23 ("usb-gadget/tcm: Convert to TARGET_SCF_ACK_KREF I/O krefs") Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 53b178ad4f90..cace5746c0f9 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1045,7 +1045,6 @@ static void usbg_cmd_work(struct work_struct *work) out: transport_send_check_condition_and_sense(se_cmd, TCM_UNSUPPORTED_SCSI_OPCODE, 1); - transport_generic_free_cmd(&cmd->se_cmd, 0); } static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, 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: 12922051 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 44135C43334 for ; Tue, 19 Jul 2022 02:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236701AbiGSCPg (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: target-devel@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:27:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12921998 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 2FA41C433EF for ; Tue, 19 Jul 2022 02:00:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236541AbiGSCAs (ORCPT ); Mon, 18 Jul 2022 22:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbiGSCAr (ORCPT ); Mon, 18 Jul 2022 22:00:47 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3975513D05; Mon, 18 Jul 2022 19:00:47 -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 26INpod4011657; Mon, 18 Jul 2022 18:27:41 -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=8F0gXGID+CdTS5g4PPBSgqjJKTPYm0EbKjo/WZ2Oz88=; b=pWfs1r1880u1SQJw3lWyQfFzqssST4lRbiEawUnYa+sW/4s/ZFiaTnpCbWIkgEd0faA2 g2OkvOJNH2HHgTBRezQlGS0qs5OWEDn3ncDHJuKSsxbEhuZjvuDWH1l8LBLnVMJ3EKVF 9KeDNV7CpaXjK/ReNjaxbVVJuwTZ/+OsyuRubnYd1PGTwuR3d3/B5WziF4ZMk0aUJm92 ZLE/bfXmgwib6sieyQLbP2ubGNQqilFN44UlXw42vG9gzL6hfonyC7ZYkudNlw2Dt2s9 1q16w3xpFr/W9y6zH0skOl4+1fYF1FcKBX819LEBNepHPqvsiLjz6SANxM93HthP1LSM Lw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:41 -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 C571D40097; Tue, 19 Jul 2022 01:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194060; bh=vvRdsPn/wHMKfHQ1z7oX1vkbtug+pziFFH4VyhYW+TU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Mx8ICcsxW9R/NUVSVB+sYJuYqSyHUg7/0qVBG5RO/336vYjbxtXZkV1wg+58ZltR5 dFzdVkgpEWDTQOOL1rX391Llc2Itf3Rq7Jfby6y3cXfgpx/aB/R3vXDXBWW03S3OoY iTMjc1icksqF8ByZipKs1ytmc4XncLFnVtR+hdDyD/j8JcKeTMIPNTaJNjte0f3AOe F+nwP0GQpgX8oUFw56ivQ+sb2b60Yk3u7wlCRfhGVgTg+r2sEVqz2s8u8xqPu5pr34 7JBA0H5OA9bUBD1O44K9NgaF68to3PQYIugcv86V+T9OXurfSBTKBP73VqKw0B7+St DEGQBKKNqsS/A== 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 96028A0096; Tue, 19 Jul 2022 01:27:39 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:39 -0700 Date: Mon, 18 Jul 2022 18:27:39 -0700 Message-Id: <420c91967948fb8e7c758ed0857c708b3b070d72.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 15/25] usb: gadget: f_tcm: Cleanup unused variable 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: -gN4YhreYozy-RVPCVjCdSYfJBeV-8dt X-Proofpoint-ORIG-GUID: -gN4YhreYozy-RVPCVjCdSYfJBeV-8dt 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=564 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: target-devel@vger.kernel.org se_cmd is not used anywhere. Remove it. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 28b560ab44fd..1e7d29f8aecb 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -675,7 +675,6 @@ static int uasp_send_read_response(struct usbg_cmd *cmd) static int uasp_send_write_request(struct usbg_cmd *cmd) { struct f_uas *fu = cmd->fu; - struct se_cmd *se_cmd = &cmd->se_cmd; struct uas_stream *stream = cmd->stream; struct sense_iu *iu = &cmd->sense_iu; int ret; From patchwork Tue Jul 19 01:27:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12921996 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 BC096C433EF for ; Tue, 19 Jul 2022 01:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236558AbiGSB6r (ORCPT ); Mon, 18 Jul 2022 21:58:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233381AbiGSB6r (ORCPT ); Mon, 18 Jul 2022 21:58:47 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B5AF39B9A; Mon, 18 Jul 2022 18:58:46 -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 26INawLR011668; Mon, 18 Jul 2022 18:27:47 -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=p86ySwkfPEOGRNYiCayfsxV8vR/Zt884NmPL1N4e22Y=; b=E/csdIsFpHyYTCx1TdtNWGkYcZucfl8sFJnHZSkTs2EN6tcpJfP9EVOkT8CTI3I4MNEE VOb0atHgJPhW/ew8IY9hRlrf0aciM2tNtGtK4RVm1a/TCcWCutZTN8E+AW29QJJZh1+P qiwxReUGzBL9nqJ+dFYkX0xEFkBEJzbH6Lh5Hy0Ja951EfvucC1+MlaKg8EU9p8uTJMO N1jS54R57CpjY6GIFMfouJ8m34lcKPgkkfnQqlHobhD8s0n8kd3JKFi0JYik8tYRIS2A eg+2ffpXt5Rbs6sfXGbhQK4FYvoIJdiotinKWGORqbC53R8FyxcS7EfbP4nj/KfZrqVD Gg== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whpc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:47 -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 ECA03C0649; Tue, 19 Jul 2022 01:27:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194067; bh=2HvC2YXu4BJ+vnsXvfnddzVm8KC6PIuyWJsyVPWUmj4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Byoi86g/AVX8l4cZhT40x6S/eX6MgNJf7C9JaEN+ENoKi9bfO85x/clPIFsxtG20s deU3P4ntTZMT22sxMmJJttzhvviMXj8OiXDDxPIUPLm6eGSlz44+F/Ukv0c/wzY3JF E7LaNgLSsayNrn93/btI7VFnrpCEhc0EUrlq8uCAjtaus1DlMaChD6LcAq/8z3ijGq A9yyfMkFvXvTJ8j20r9HoCD6xTWuv3JxxUnUQ5TsApNy4QjsLPeyPdiJT6qvKbdUbP KXZF9NUiKA9Pq4h0Zib7SBriGUpGYX9DLXXaBwbEtA+lCmcKXc5T+bCaLeUgh0DfRJ FAfX7KgiDTgKA== 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 B1EC7A0069; Tue, 19 Jul 2022 01:27:45 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:45 -0700 Date: Mon, 18 Jul 2022 18:27:45 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 16/25] usb: gadget: f_tcm: Update state on data write 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: UvshAVfQl2i9V9HfpsIGAKefCxSGQ2-W X-Proofpoint-ORIG-GUID: UvshAVfQl2i9V9HfpsIGAKefCxSGQ2-W 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=936 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: target-devel@vger.kernel.org When preparing request for data write state, the next state is UASP_SEND_STATUS. When data write completes, the next state is UASP_QUEUE_COMMAND. Without this change, the command will transition to the wrong state. Signed-off-by: Thinh Nguyen --- Changes in v2: - Move a related change from TASK MANAGEMENT updating cmd state to UASP_QUEUE_COMMAND to here. drivers/usb/gadget/function/f_tcm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 1e7d29f8aecb..d7318c84af98 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -934,6 +934,8 @@ 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; + cmd->state = UASP_QUEUE_COMMAND; + if (req->status < 0) { pr_err("%s() state %d transfer failed\n", __func__, cmd->state); goto cleanup; @@ -976,6 +978,8 @@ static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) req->complete = usbg_data_write_cmpl; req->length = se_cmd->data_length; req->context = cmd; + + cmd->state = UASP_SEND_STATUS; return 0; } From patchwork Tue Jul 19 01:27:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12921972 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 1C702C43334 for ; Tue, 19 Jul 2022 01:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233271AbiGSBvW (ORCPT ); Mon, 18 Jul 2022 21:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233561AbiGSBvW (ORCPT ); Mon, 18 Jul 2022 21:51:22 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49A99219; Mon, 18 Jul 2022 18:51: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 26IMdcX5011679; Mon, 18 Jul 2022 18:27:53 -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=7VmFkG8+6gcOskHL/t2k80ZjODg183bvO+6+/+nliyQ=; b=ZmeoPX+MHZX7fBQUlUlY2xefMvRKSJKaJ/gQb3uvOBEsyuDcy88L1x693Bzw7tHbNb3R AhfPbokkucriXdpv/bDWFisk1hNkSM9hhIPbCaiPth24s8nrIKqRYL3uW7Gfh+TRFKDg ZcADEsEg90M2QgTJTTmB8fcqVH8JC9xi+UjWA8jl4oG9YewPKVG73L3ZPwNo8+B8P4Sl K8Gqjv/h6/Ut+0Mkmlwz4vtPA5U9HaW6DqJrT52ra3Zgwg+9gpAn7/6Udg3kibr4sea7 9onAUC/lat4pi4gRNS3wcwy3Ts1kBDb7LTlP3pIpWW3qq5wC9XabW2zD5WOK5+gRyT7I kQ== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:53 -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 149E0C0649; Tue, 19 Jul 2022 01:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194073; bh=k1PpIrVAGNI15QgEMmyoYc15szdzFTiIjkWRmlBBZAM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=IYu3W1seEybbWYAksBfL5htPGbPDjY4fsOzvmZnFpbJ8p5kBil/3avtTLrn+mHpRo l06Gd1fsPHea3FoVlDccjlP3Ca28BXk1BCd3XlqIdQ/kB+SfBNwCv7nBa8k0XX++nh +gTy3b/mcI0h1gx7VjE5pa4adFAMHfXkUlLaWN2qgwvGO03iqwYY2g7X21QERp4TGk CBKeiATlshMC3YLEyJJMLp4yLzHk3u6DPiAIahg4i6XdvB3cohfGvJDnOu6iWuaBH+ d3+cyfREsncwH6sG0JjRx0Dffh3RuBm9ZreXBsMIKh0jGpZ8rj8owPodOrOwl+RbaB 1zoo6Ku3LP3+A== 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 CE22EA0096; Tue, 19 Jul 2022 01:27:51 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:51 -0700 Date: Mon, 18 Jul 2022 18:27:51 -0700 Message-Id: <099a4bd5ed02f4c48f4640347379b5127075e453.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 17/25] usb: gadget: f_tcm: Handle abort 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: 4Rcy1KGt19VMc1GOKIQ84T6pnh3igkga X-Proofpoint-ORIG-GUID: 4Rcy1KGt19VMc1GOKIQ84T6pnh3igkga 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=926 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: target-devel@vger.kernel.org Implemented aborted_task to cancel outstanding request. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index d7318c84af98..8f7eb7045e64 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1278,6 +1278,22 @@ static void usbg_queue_tm_rsp(struct se_cmd *se_cmd) static void usbg_aborted_task(struct se_cmd *se_cmd) { + struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, se_cmd); + struct f_uas *fu = cmd->fu; + struct uas_stream *stream = cmd->stream; + int ret = 0; + + if (stream->req_out->status == -EINPROGRESS) + ret = usb_ep_dequeue(fu->ep_out, stream->req_out); + else if (stream->req_in->status == -EINPROGRESS) + ret = usb_ep_dequeue(fu->ep_in, stream->req_in); + else if (stream->req_status->status == -EINPROGRESS) + ret = usb_ep_dequeue(fu->ep_status, stream->req_status); + + if (ret) + pr_err("Unable to dequeue se_cmd out %p\n", se_cmd); + + cmd->state = UASP_QUEUE_COMMAND; } static const char *usbg_check_wwn(const char *name) From patchwork Tue Jul 19 01:27:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12921958 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 9ACE1C43334 for ; Tue, 19 Jul 2022 01:44:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233749AbiGSBog (ORCPT ); Mon, 18 Jul 2022 21:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231635AbiGSBof (ORCPT ); Mon, 18 Jul 2022 21:44:35 -0400 X-Greylist: delayed 1009 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 18 Jul 2022 18:44:34 PDT Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09548EE38; Mon, 18 Jul 2022 18:44:33 -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 26IM5U1w002272; Mon, 18 Jul 2022 18:27:59 -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=b7MfKPf9nQqlmO/dDxc6MjRx/cnBJnR5IidJCKntjdg=; b=jJj62atp918abmoxQFFL17Z3GqYvon6Lsd3M8l+wuNWgMwAVTwpvl05XMijEdA+1s91w E0Ux1NGUZZIEIthVoG+0P661JSMiaMXwbgifKd5jKYOE7wAbzMZYWxe9b7fmxaDzYlQ8 fOaMA94LtU+VYm2YL+JeSeqjAGqPkKtluBXIUylRFjGh5Z9RRSVupTvfo6ee2CI9hDjp nDiLdoQa5I/l90rDMuPBC39p/dGmIJ4ZdBgBTKL1MC6R8G5ZtloI3ymze5uduPBfa4aZ THA64T0FCGrSS5VktyrdeISWg2S9h6SyCYGSnQQY6Ck6VP2LWo1n3uccStlWd/GbjwLp Tg== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvbmwhtr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:27:59 -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 17B274008A; Tue, 19 Jul 2022 01:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194079; bh=OrBOJOTlFf/nTJ3m0qhtxxTxNpwmgDDjmhBn0n85VZo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=bNleh05+dhtViPOLnCBYh7xUbQI3U/dKoHajoIjH8S723gmeeawj8/fsNb0FLtd6J 9xtxlPduknuKJRfJgKMAlGh3RyEM8IR8Om8Ab7luAfdPDRHwBmYhtrqBQogJ+AQ1f4 8IWbD49HzePd0lK/8oTymb+UJ/BcWBfI4ITyo0S27PRVEK11GXA5kQk2/ACzl8xiTm sza1tvb4LDiIksQTxiTwu6qbqHfQsq2wVCp6gtErQldw33V7YQTvvqAM0WHzV4gwQg BST5PgcBRNPz1uz1xsaIGvs+yBg1B2G5+u3O4eiWNdgsTgeVb4VasVgMxNRWjLQ+sV +p+jCfk6Tp1vw== 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 E95D2A0096; Tue, 19 Jul 2022 01:27:57 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:27:57 -0700 Date: Mon, 18 Jul 2022 18:27:57 -0700 Message-Id: <782c62e59d8902044e6021fa7dd6c249a4ea4288.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 18/25] usb: gadget: f_tcm: Cleanup requests on ep disable 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: x7H5AlVZrQl5IezmB09RvunRrE48r1NQ X-Proofpoint-ORIG-GUID: x7H5AlVZrQl5IezmB09RvunRrE48r1NQ 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=740 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: target-devel@vger.kernel.org If the endpoint is disabled, then free the command. Normally we don't free a command until it's completed its UASP status (failure or not). Signed-off-by: Thinh Nguyen --- Changes in v2: - Use goto cleanup for a cleaner look. drivers/usb/gadget/function/f_tcm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 8f7eb7045e64..a8a730e5126d 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -572,7 +572,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) struct f_uas *fu = cmd->fu; int ret; - if (req->status < 0) + if (req->status == -ESHUTDOWN) goto cleanup; switch (cmd->state) { @@ -936,7 +936,10 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) cmd->state = UASP_QUEUE_COMMAND; - if (req->status < 0) { + if (req->status == -ESHUTDOWN) + goto cleanup; + + if (req->status) { pr_err("%s() state %d transfer failed\n", __func__, cmd->state); goto cleanup; } From patchwork Tue Jul 19 01:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 12922040 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 94689C43334 for ; Tue, 19 Jul 2022 02:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236818AbiGSCMo (ORCPT ); Mon, 18 Jul 2022 22:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236840AbiGSCMm (ORCPT ); Mon, 18 Jul 2022 22:12:42 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 796BD3C8D9; Mon, 18 Jul 2022 19:12:41 -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 26IMIaOD011734; Mon, 18 Jul 2022 18:28:05 -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=kwMOGmIIfzbY7VpWpTbmlhazk7iSokgmI1XZfcrQx8Y=; b=q7ePfUsZBGWTsxGqJ2HFZ60FbK+CzJEjf1g4F5P6u2dgJzfzlGCs/Crs7FWtpkvemMy4 C23khzlxDTAhAq/jKHpx+5C6sF2t5IoING3dG/6c8APMqVv2gYxLmflEe6zE5mHjC7xI 5qi2KVM3yB3gNYpb+6cdj5O2yEpVmMLRHSg6UO/Ezv1gEhi/YAZ9qWS0LBBW05o5262m MwlJs7S8zh5NHG1WRwzcs7XwJ4ERzSxB2acsn/O0hua3BKw5mO5qTRTzVWSDbvPYnFe9 /Si22hMlYFhpbA5jY2stMYcyBEzAhEr4Q+i0C0YHAW6yTOKSpiCsIKHjx1UEHSW2S+8T qw== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:05 -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 3A50C4008A; Tue, 19 Jul 2022 01:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194085; bh=ZqUV820F7j/nDTM7lrEmn3rGOhNylVJHOQIpC6HclvU=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=InLE3jiupEu8CPftk9AXUU+aDxb2onINhk4xqWPwwNArVHfD9Am4eS9vjkkixt1K4 RBp1p/j7GDehL4C+ddWC13GxyA3A5xQNAhq5fN03EdDozzl/18aJ50/SuqPnaXoYTY XtbrZI4oOPVcyiFGzxitKuA0pl+KrLLQXbuWBXLqUrz2u093YvrAJiFO2yYQ28eTK3 3RMSHDEPkWOPC4k/txuFYvXss5jXB8SBG3Hp9fJDqFchuUCYRr75Tk695nNNhETAa1 1vVSpCqTOswfExcZ/7AbT4KqaUsdyR9kzmf7jcoGq4AFr4Z4MtDeWGUJxLdAXNl5h8 awt2ocJp8um2A== 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 12DA6A0096; Tue, 19 Jul 2022 01:28:04 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:04 -0700 Date: Mon, 18 Jul 2022 18:28:04 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 19/25] usb: gadget: f_tcm: Decrement command ref count on cleanup To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Bogdanov , Nicholas Bellinger Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Andrzej Pietrasiewicz , Sebastian Andrzej Siewior X-Proofpoint-GUID: R4CY43pP7J6M-Dp9w_mYnvKsjEVWg-lC X-Proofpoint-ORIG-GUID: R4CY43pP7J6M-Dp9w_mYnvKsjEVWg-lC 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=858 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: target-devel@vger.kernel.org We submitted the command with TARGET_SCF_ACK_KREF, which requires acknowledgment of command completion. If the command fails, make sure to decrement the ref count. Fixes: cff834c16d23 ("usb-gadget/tcm: Convert to TARGET_SCF_ACK_KREF I/O krefs") Signed-off-by: Thinh Nguyen --- Changes in v2: - New patch drivers/usb/gadget/function/f_tcm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index a8a730e5126d..6cf95c9723a3 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -955,6 +955,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) return; cleanup: + target_put_sess_cmd(se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); } From patchwork Tue Jul 19 01:28: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: 12922071 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 EA870C43334 for ; Tue, 19 Jul 2022 02:28:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236857AbiGSC22 (ORCPT ); Mon, 18 Jul 2022 22:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbiGSC21 (ORCPT ); Mon, 18 Jul 2022 22:28:27 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1AAC3AE74; Mon, 18 Jul 2022 19:28:26 -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 26INawLW011668; Mon, 18 Jul 2022 18:28:11 -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=BygQ6+1FH3jCaSFf7qCsSOuQqp/3Wicq5Kz0DudzHSc=; b=hAcFbV/GEOeIJWAEXS/eq3UEIy0g4XQhVLx5uVy8abeLgRiultUw48DqDnJPTnZny8Uq whSTR5CsllCojd1UP52Z0zDaavvSnPbm61/fBgjIwpCOwNjkO40oDpRqzMDTjyw9Ja1b hdf0hTIa7k67GQJFCr7fCR69lvC+C1ymernhu+Wwzzt2i8RUJRFno9/bfL54fQNdQj9C DgYARq0v6rZFTFjGj//PC6lHrX38greNm7fovIOQvRvTs8nnjSUZgD2OUCrHwYT9K3Xi maXhH+W58jM8+xasoWOZTVesATjeDQdS4ZU/USL5uxPTSopkokAOCLQzmCa6Ukv2Dl4u Ww== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whqu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:11 -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 5602440097; Tue, 19 Jul 2022 01:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194091; bh=Hu9EZfKQjGaOvgd4CEzDGOBcW56c1F3mlREuvVB3bmg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=mY3hbt8OThXNhwN/J3LIgKLeNB99vTGyFAQvCR1ZcykQ7C16/GUcHfw54dknU96IT jRjsW2fwWGazUg7tT6NwX32t6/oX7JX+HSfvbBloCys6L6OGHzSRRbBx4cL3PZvo28 J4tQr5Js7Aawl9Oe2fkb79RCqNpLB87RITRGXMWK8HudOw43zWNiTr513ki+o7KwbN 3WOLfCtod2Lk3RhwmQBchNgfu0AHW8hYz/Coj8xr+45oLZXC3bY6V21k31mrm0L5Ws oTdZp6/zj45YE1eIywq/Mp0U8bGnBnwnh6XUK55i/NiWbIg+8kzFrLEIwXBh7o5Nmz a1R9QqLQkMeEw== 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 34EEBA0096; Tue, 19 Jul 2022 01:28:10 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:10 -0700 Date: Mon, 18 Jul 2022 18:28:10 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 20/25] usb: gadget: f_tcm: Save CPU ID per 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: 9HEe-fpxbqdu5ye2vAoO0qlYKYC5UgS0 X-Proofpoint-ORIG-GUID: 9HEe-fpxbqdu5ye2vAoO0qlYKYC5UgS0 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=672 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: target-devel@vger.kernel.org Normally we don't care about the CPU id, but if we ever use TARGET_SCF_USE_CPUID, then we need to save the cpuid. Signed-off-by: Thinh Nguyen --- Changes in v2: - None drivers/usb/gadget/function/f_tcm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 6cf95c9723a3..084143213176 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1069,6 +1069,7 @@ static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, memset(cmd, 0, sizeof(*cmd)); cmd->se_cmd.map_tag = tag; cmd->se_cmd.map_cpu = cpu; + cmd->se_cmd.cpuid = cpu; cmd->se_cmd.tag = cmd->tag = scsi_tag; cmd->fu = fu; From patchwork Tue Jul 19 01:28: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: 12922052 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 96168C43334 for ; Tue, 19 Jul 2022 02:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236861AbiGSCQ0 (ORCPT ); Mon, 18 Jul 2022 22:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232694AbiGSCQZ (ORCPT ); Mon, 18 Jul 2022 22:16:25 -0400 Received: from mx0a-00230701.pphosted.com (mx0a-00230701.pphosted.com [148.163.156.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D4C22BFA; Mon, 18 Jul 2022 19:16:24 -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 26INpod5011657; Mon, 18 Jul 2022 18:28:18 -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=onOJh2hcdIl+q/Y9f/POAVrOhKBEi/urtBPAsHEj5Z4=; b=a9ms9QOWQssmrIQCIgWV3evwBH200OPMURyEmnPCQ+tpbwcyPUxhYbRqpsQAchc4l0jl G/89gCvWJZNFHp/CMH4qQnOvpgO4Xhd5clYupOy6TS6ztGV8I3de70zCTpwOvnX0sltw jFibBsGEvIRb/c4qdn//QORpGuWl+jsZNnQKRwq1SX7S2zW/0tmEKDeJk6mYSdu94MwA Jvga1FN4xnapUYXMjD7yoT42wfg3IK1IzxStmUiXWWB5WHrgMKF3/4ysyQsQyjpp7Z+H VOYuTmvD8AY7KNgyoqxf9C2d/onvkkRAB2652etIIVrxYwAt5tcVRdviTVGa7WoHkdyi xA== Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by mx0a-00230701.pphosted.com (PPS) with ESMTPS id 3hbvk5whr1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 18 Jul 2022 18:28:18 -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 8AAADC0649; Tue, 19 Jul 2022 01:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1658194097; bh=4MEfvkp8Bb/ru/wAgS6sQwD0ijPTHIo4v+U4hbSm5ko=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=but6wzf8WcRKU9isqjBG6xHxDTS8vZ4P3Fna6BHvzVHHZz2OfKznzRpz6IU1uYPB2 qqIyLUanRU1tmVwbMhFFbssI5gkEDt39WPqL181eotYL+ZYi/uUBfVmCB7zh5VSCIx 0zTYfQiU6NhJLtBXIpXyN4RWufdTstLKoVyk4nCei0CHnDztFc9gu2IoP13Xrx008m A1sHo60rUYVkTC+A6sN3LolR9Ui/tBoJFs2grp9zy1hOWggPZ7oteF4Y2BzVtjusby m6ciE+xK5pKx9C97fC4xlRRUBwnfspUTgLShKgAHpW3bf4kw/h6iO5wxbNnvHf8o/J iLKwCEFuWPMQw== 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 5173DA0096; Tue, 19 Jul 2022 01:28:16 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Mon, 18 Jul 2022 18:28:16 -0700 Date: Mon, 18 Jul 2022 18:28:16 -0700 Message-Id: <3fbae6ecb8e9f31807635152a377b076e86fb12e.1658192351.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH v2 21/25] usb: gadget: f_tcm: Get stream by tag 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: ZYL-LpT_TcOrJqtcR4_I4NedvyT0rqxs X-Proofpoint-ORIG-GUID: ZYL-LpT_TcOrJqtcR4_I4NedvyT0rqxs 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=991 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: target-devel@vger.kernel.org In preparation for TASK MANAGEMENT handling of overlapped command, implement uasp_get_stream_by_tag() to find the active stream/command based on a given tag. For simplicity, we use mod operation to quickly find an in-progress matching command tag to check for overlapped command. The assumption is that the UASP class driver will limit to using tag id from 1 to USBG_NUM_CMDS. This is based on observation from the Windows and Linux UASP storage class driver behavior. If an unusual UASP class driver uses a tag greater than USBG_NUM_CMDS, then this method may no longer work due to possible stream id collision. In that case, we need to use a proper algorithm to fetch the stream (or simply walk through all active streams to check for overlap). Signed-off-by: Thinh Nguyen --- Changes in v2: - Splitted from TASK MANAGEMENT change drivers/usb/gadget/function/f_tcm.c | 30 ++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 084143213176..a10e74290664 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -506,6 +506,22 @@ static void uasp_cleanup_old_alt(struct f_uas *fu) uasp_free_cmdreq(fu); } +static struct uas_stream *uasp_get_stream_by_tag(struct f_uas *fu, u16 tag) +{ + /* + * For simplicity, we use mod operation to quickly find an in-progress + * matching command tag to check for overlapped command. The assumption + * is that the UASP class driver will limit to using tag id from 1 to + * USBG_NUM_CMDS. This is based on observation from the Windows and + * Linux UASP storage class driver behavior. If an unusual UASP class + * driver uses a tag greater than USBG_NUM_CMDS, then this method may no + * longer work due to possible stream id collision. In that case, we + * need to use a proper algorithm to fetch the stream (or simply walk + * through all active streams to check for overlap). + */ + return &fu->stream[tag % USBG_NUM_CMDS]; +} + static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req); static int uasp_prepare_r_request(struct usbg_cmd *cmd) @@ -513,7 +529,7 @@ static int uasp_prepare_r_request(struct usbg_cmd *cmd) struct se_cmd *se_cmd = &cmd->se_cmd; struct f_uas *fu = cmd->fu; struct usb_gadget *gadget = fuas_to_gadget(fu); - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); if (!gadget->sg_supported) { cmd->data_buf = kmalloc(se_cmd->data_length, GFP_ATOMIC); @@ -546,7 +562,7 @@ static void uasp_prepare_status(struct usbg_cmd *cmd) { struct se_cmd *se_cmd = &cmd->se_cmd; struct sense_iu *iu = &cmd->sense_iu; - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(cmd->fu, cmd->tag); cmd->state = UASP_QUEUE_COMMAND; iu->iu_id = IU_ID_STATUS; @@ -568,8 +584,8 @@ static void uasp_prepare_status(struct usbg_cmd *cmd) static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) { struct usbg_cmd *cmd = req->context; - struct uas_stream *stream = cmd->stream; struct f_uas *fu = cmd->fu; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); int ret; if (req->status == -ESHUTDOWN) @@ -620,7 +636,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) static int uasp_send_status_response(struct usbg_cmd *cmd) { struct f_uas *fu = cmd->fu; - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); struct sense_iu *iu = &cmd->sense_iu; iu->tag = cpu_to_be16(cmd->tag); @@ -632,7 +648,7 @@ static int uasp_send_status_response(struct usbg_cmd *cmd) static int uasp_send_read_response(struct usbg_cmd *cmd) { struct f_uas *fu = cmd->fu; - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); struct sense_iu *iu = &cmd->sense_iu; int ret; @@ -675,7 +691,7 @@ static int uasp_send_read_response(struct usbg_cmd *cmd) static int uasp_send_write_request(struct usbg_cmd *cmd) { struct f_uas *fu = cmd->fu; - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); struct sense_iu *iu = &cmd->sense_iu; int ret; @@ -1285,7 +1301,7 @@ static void usbg_aborted_task(struct se_cmd *se_cmd) { struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, se_cmd); struct f_uas *fu = cmd->fu; - struct uas_stream *stream = cmd->stream; + struct uas_stream *stream = uasp_get_stream_by_tag(fu, cmd->tag); int ret = 0; if (stream->req_out->status == -EINPROGRESS) 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: 12922039 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 20809C43334 for ; Tue, 19 Jul 2022 02:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236795AbiGSCMf (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: target-devel@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: 12922064 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 653EEC433EF for ; Tue, 19 Jul 2022 02:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbiGSC0r (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: target-devel@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: 12921982 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 903C5C433EF for ; Tue, 19 Jul 2022 01:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235928AbiGSBy0 (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: target-devel@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: 12921959 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 7CB3AC43334 for ; Tue, 19 Jul 2022 01:47:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235143AbiGSBrw (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: target-devel@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;