From patchwork Wed Jul 6 23:34: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: 588456 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 BDE55CCA480 for ; Wed, 6 Jul 2022 23:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234196AbiGFXee (ORCPT ); Wed, 6 Jul 2022 19:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234177AbiGFXec (ORCPT ); Wed, 6 Jul 2022 19:34:32 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C7BC2C665; Wed, 6 Jul 2022 16:34:32 -0700 (PDT) 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 70B87C06E7; Wed, 6 Jul 2022 23:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150472; bh=sssFnbK7YbZe7A5/J1ruA6k6G3/8G/yNcmvmNc2Hg8s=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PeVQg7EWiysa81JH922CCsx0pBS7zs2qworbNuQjJeP477ykARdF9d6CEt8eZYB/E i1koKlpsWacs0WQoP2zV/heAr3hPauCyOSfsemdY0ewukzKNCYrtC4l2Fx9oy1c8jn iEyaIzQYdFtzdFBXfjKHVHeLEVl4dS3emHpB5pHmjepYemJP49wC6s8bCg3KBVaRSJ wSMEmK8zFpBZxEbjnt/EmfNA5fQxzci45Il+B9ODNTyWrFcjmD594PpWxqasWIw4hf uXwKdC0lDRVMNgZK2y1/NclyWPKgDCBbFjQIqqhnGICRvWfFFKnlcPn952d7APi95Y fVVgG1bUAL5lA== 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 C4452A0063; Wed, 6 Jul 2022 23:34:29 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:34:29 -0700 Date: Wed, 06 Jul 2022 16:34:29 -0700 Message-Id: <118900ffaf094a279f7799ac9d2c73265c889121.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 01/36] target: Handle MI_REPORT_SUPPORTED_OPERATION_CODES To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Microsoft Windows checks for MI_REPORT_SUPPORTED_OPERATION_CODES. Let's handle this MAINTENANCE_IN command and report supported commands. Signed-off-by: Thinh Nguyen Reported-by: kernel test robot --- drivers/target/target_core_alua.c | 66 +++++++++++++++++++++++++++++++ drivers/target/target_core_alua.h | 2 + drivers/target/target_core_spc.c | 14 ++++++- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c index b56ef8af66e7..20cfcb70805d 100644 --- a/drivers/target/target_core_alua.c +++ b/drivers/target/target_core_alua.c @@ -259,6 +259,72 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd) return 0; } +/* + * REPORT_SUPPORTED_OPERATION_CODES + * + * See spc4r17 section 6.27 + */ +sense_reason_t +target_emulate_report_supported_opcodes(struct se_cmd *cmd) +{ + unsigned char *cdb = cmd->t_task_cdb; + unsigned char *buf; + u8 supported = 0; + + if (cdb[2] != 1) { + pr_warn("Invalid command format %d\n", cdb[2]); + goto out; + } + + buf = transport_kmap_data_sg(cmd); + if (!buf) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + + switch (cdb[3]) { + case INQUIRY: + case MODE_SENSE: + case MODE_SENSE_10: + case READ_CAPACITY: + case SERVICE_ACTION_IN_16: + case REPORT_LUNS: + case REQUEST_SENSE: + case SYNCHRONIZE_CACHE: + case REZERO_UNIT: + case SEEK_6: + case SEEK_10: + case TEST_UNIT_READY: + case SEND_DIAGNOSTIC: + case MAINTENANCE_IN: + case READ_6: + case READ_10: + case READ_16: + case WRITE_6: + case WRITE_10: + case WRITE_16: + case VERIFY_16: + case MODE_SELECT: + case MODE_SELECT_10: + case START_STOP: + case SECURITY_PROTOCOL_IN: + case SECURITY_PROTOCOL_OUT: + supported = 3; + break; + case ATA_12: + case ATA_16: + case VERIFY: + case ZBC_IN: + case ZBC_OUT: + default: + break; + } + + transport_kunmap_data_sg(cmd); +out: + buf[1] = supported; + target_complete_cmd(cmd, SAM_STAT_GOOD); + return 0; +} + /* * SET_TARGET_PORT_GROUPS for explicit ALUA operation. * diff --git a/drivers/target/target_core_alua.h b/drivers/target/target_core_alua.h index fc9637cce825..7941e4dd4f97 100644 --- a/drivers/target/target_core_alua.h +++ b/drivers/target/target_core_alua.h @@ -82,6 +82,8 @@ extern struct kmem_cache *t10_alua_tg_pt_gp_cache; extern struct kmem_cache *t10_alua_lba_map_cache; extern struct kmem_cache *t10_alua_lba_map_mem_cache; +extern sense_reason_t +target_emulate_report_supported_opcodes(struct se_cmd *cmd); extern sense_reason_t target_emulate_report_target_port_groups(struct se_cmd *); extern sense_reason_t target_emulate_set_target_port_groups(struct se_cmd *); extern sense_reason_t target_emulate_report_referrals(struct se_cmd *); diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index c14441c89bed..dd799158609d 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -1425,15 +1425,25 @@ spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) break; case MAINTENANCE_IN: if (dev->transport->get_device_type(dev) != TYPE_ROM) { + u8 action = cdb[1] & 0x1f; + /* * MAINTENANCE_IN from SCC-2 * Check for emulated MI_REPORT_TARGET_PGS */ - if ((cdb[1] & 0x1f) == MI_REPORT_TARGET_PGS) { + if (action == MI_REPORT_TARGET_PGS) { cmd->execute_cmd = target_emulate_report_target_port_groups; + + *size = get_unaligned_be32(&cdb[6]); + } + + if (action == MI_REPORT_SUPPORTED_OPERATION_CODES) { + cmd->execute_cmd = + target_emulate_report_supported_opcodes; + + *size = get_unaligned_be16(&cdb[2]); } - *size = get_unaligned_be32(&cdb[6]); } else { /* * GPCMD_SEND_KEY from multi media commands From patchwork Wed Jul 6 23:34: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: 588027 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 1F4EFC433EF for ; Wed, 6 Jul 2022 23:34:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234226AbiGFXek (ORCPT ); Wed, 6 Jul 2022 19:34:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234220AbiGFXei (ORCPT ); Wed, 6 Jul 2022 19:34:38 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECA6D2C671; Wed, 6 Jul 2022 16:34:37 -0700 (PDT) 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 ACEACC06E8; Wed, 6 Jul 2022 23:34:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150477; bh=wr713SSi0TL3kWN+vsfQtgS+wGCjHIK8hmLX+enppoQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=QMQ+Dp0SMxqwn9Kb0udb3Y4+cJ5Y6J8rgS+Bm2MVc3amxN/Bs8N3X30tkxhRFOQG9 g/Otr0mkgVPcQ7O9hPckzq2C+GiCZ2fGgkIDiOtEjtJgIqdNoj+SILn4o7eShnd2Fm hkT4jg0Eg2OURlxnu4BKBchfu3rD8GZAzWWeap4OtiHHU38G3Hx21/mxLL4NDx2bVv Jc0vRYFkroH5L7AysLoUuNhvgyGxPDOncFaPHoup6bIGWx7J61zRNthZ+LC9tGkboW N/NfQLSgblkSWRiL1Dp2xz7MIq6FiFiS/yHo/OsYwddvTlmJiK0EvH1cS+4i6pcRHp Rko4j9UwZg2AA== 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 77439A006F; Wed, 6 Jul 2022 23:34:35 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:34:35 -0700 Date: Wed, 06 Jul 2022 16:34:35 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 02/36] target: Add overlapped response to tmrsp_table To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, "Martin K. Petersen" Cc: Thinh Nguyen , linux-usb@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add TMR_OVERLAPPED_TAG_ATTEMPTED response to tmrsp_table. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:34:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588455 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 CFA34C43334 for ; Wed, 6 Jul 2022 23:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234360AbiGFXet (ORCPT ); Wed, 6 Jul 2022 19:34:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234271AbiGFXep (ORCPT ); Wed, 6 Jul 2022 19:34:45 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30C02C661; Wed, 6 Jul 2022 16:34:44 -0700 (PDT) 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 812B54077F; Wed, 6 Jul 2022 23:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150484; bh=S4G9ZIAPaz/eAlg/Un4EY6UluBtJfBD5gweu6q/WYTk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PYiMOGPPx4YSAqjYbG4rcXFtlKROGGmf0C4LSuTQQfgeujpL0BamXmQIcRNa8v2cC Z1Y5gyOiYBvPfsqz93ySWKu7aaCp6jIMsCCZeRbgahKRKAUMOQvGBPZ7f4tmFTVjHh aBuq6RuBarpLeHg8/CcSNAwBb6mr7B8xO3iGbqjvBFVy12NuvJnZ8sNjbCPprL5Sls Be2XMnV3P0Hw9chNud9fnVtxiOsHtyAbCazmc9DP9BFNyahfkGcddzvsoiLlDBd1SR mCvp/fTooG+TcoA3WQ9P/Z+eViFS1FWVxolsv3eoxTSHh1VaSb5y4Qn4DtE+m66bDa Dn2wQ2elRA5TA== 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 02321A0096; Wed, 6 Jul 2022 23:34:42 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:34:42 -0700 Date: Wed, 06 Jul 2022 16:34:42 -0700 Message-Id: <0af951cacb921def80b5dfbc0ca82b39b1ecd1cc.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 03/36] target: Don't drain empty list To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If the preempt_and_abort_list is NULL, don't attempt to drain it. Otherwise, it may lead to invalid access. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index bac111456fa1..7a7e24069ba7 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -383,9 +383,11 @@ int core_tmr_lun_reset( (preempt_and_abort_list) ? "Preempt" : "TMR", dev->transport->name, tas); - core_tmr_drain_tmr_list(dev, tmr, preempt_and_abort_list); - core_tmr_drain_state_list(dev, prout_cmd, tmr_sess, tas, - preempt_and_abort_list); + if (preempt_and_abort_list) { + core_tmr_drain_tmr_list(dev, tmr, preempt_and_abort_list); + core_tmr_drain_state_list(dev, prout_cmd, tmr_sess, tas, + preempt_and_abort_list); + } /* * Clear any legacy SPC-2 reservation when called during From patchwork Wed Jul 6 23:34:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588026 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 2B4BDC433EF for ; Wed, 6 Jul 2022 23:34:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234319AbiGFXe6 (ORCPT ); Wed, 6 Jul 2022 19:34:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234229AbiGFXev (ORCPT ); Wed, 6 Jul 2022 19:34:51 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BFD62C667; Wed, 6 Jul 2022 16:34:51 -0700 (PDT) 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 B7483C06E7; Wed, 6 Jul 2022 23:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150490; bh=y3Ojr2fJhBsNq1NiuvKYlOf45Uycs4J7Ybp3J692uHA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=epg3z/rx1ip25w5s/eVvtC8/53LJ3OCLkPLpo0fFL2Ethk4PkasNPnPCq2ebeUc+M kqqkOOg/tqqHzUaxvPh/heUho6KkoTjUyuboKgk3qpdVPNLhFAsCfqOsazHbuz8eDA ghqJIt4W/MBsjgzDbvsIOsydU1i7mdSWJxaQMk1T4df7f95rk8AqxU/zHYDMKNl/k2 v914Uy7oeVI8oMgrHa6gQd3Ud56fxqpd59F9WB9LGHweSrRhIc+DXo2JN+cP2MqrCG Rft2Y2d8fsqFChO+iWsMiSpxOCXRPSa5wUj3WtoKyYbXojl/pkIulY4F3f5XsbC2YY Ty+qcGcYecR+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 7C2B3A0096; Wed, 6 Jul 2022 23:34:49 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:34:49 -0700 Date: Wed, 06 Jul 2022 16:34:49 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 04/36] target: Does tmr notify on aborted command To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If the tmr_notify is not implemented, simply execute a generic command completion to notify the command abort. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 7a7e24069ba7..2af80d0998bf 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -150,6 +151,9 @@ void core_tmr_abort_task( if (dev->transport->tmr_notify) dev->transport->tmr_notify(dev, TMR_ABORT_TASK, &aborted_list); + else + target_complete_cmd(se_cmd, + SAM_STAT_TASK_ABORTED); list_del_init(&se_cmd->state_list); target_put_cmd_and_wait(se_cmd); From patchwork Wed Jul 6 23:34:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588454 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 6AA65C433EF for ; Wed, 6 Jul 2022 23:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234237AbiGFXfD (ORCPT ); Wed, 6 Jul 2022 19:35:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234254AbiGFXe5 (ORCPT ); Wed, 6 Jul 2022 19:34:57 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF3092CC9E; Wed, 6 Jul 2022 16:34:56 -0700 (PDT) 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 BB0C440CAF; Wed, 6 Jul 2022 23:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150496; bh=CekRVjk+qBcYfyXCVZJcBG4eqEOYXvl5smRYi4chxRE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=IExX8YgZzsz1JRfu9Hv5I9PgxZQre2jExe6Mti9zqppYc/AoCG62uQHa0s1E997xU wMBv8mPot1qjdwV9bGqviPtJxvk7m8znumXEObGpMP6vCzwHm+6Z136xVd1508+8O1 F0gSsX07HA9n0wMQ70bUOXTx6SxeBiSiqHugEgh3RrJyjh6xhQtSuC4iHyblRiclw4 yiZi28LOLdpNm29M/u49jxHwE8zBrdhTZExDrsM/qibabrHMa4ONSmP7qr6EYhLZxh KG+fSViNdh/S9VTiMX7GK0IZOD6R9vssdrKvjpmySVAElIqUgQxa5GrBqfceRgzZjO v9FgQFhN9N8Zw== 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 998E1A0096; Wed, 6 Jul 2022 23:34:55 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:34:55 -0700 Date: Wed, 06 Jul 2022 16:34:55 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 05/36] target: Don't remove command too early To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org A command completion is asynchronous, regardless if an abort command is executed. Don't just free the command before its completion. Similarly, a TMR command is not completed until its response is completed. The freeing of the command can be done by the target user through target_generic_free_cmd(). Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 7838dc20f713..105d3b0e470f 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -836,10 +836,6 @@ static void target_handle_abort(struct se_cmd *cmd) } WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); - - transport_lun_remove_cmd(cmd); - - transport_cmd_check_stop_to_fabric(cmd); } static void target_abort_work(struct work_struct *work) @@ -3553,9 +3549,6 @@ static void target_tmr_work(struct work_struct *work) goto aborted; cmd->se_tfo->queue_tm_rsp(cmd); - - transport_lun_remove_cmd(cmd); - transport_cmd_check_stop_to_fabric(cmd); return; aborted: From patchwork Wed Jul 6 23:35:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588025 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 C2D9BC433EF for ; Wed, 6 Jul 2022 23:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234295AbiGFXfH (ORCPT ); Wed, 6 Jul 2022 19:35:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234184AbiGFXfF (ORCPT ); Wed, 6 Jul 2022 19:35:05 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE452C675; Wed, 6 Jul 2022 16:35:04 -0700 (PDT) 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 00405C06E7; Wed, 6 Jul 2022 23:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150504; bh=9/FurYrjR5WH7mu1sEESAafuqAzMvL/raaE9Kmb++Vc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PGkKVS8vpUflYIb9uZp8SJTOoD4EBUTHgYjqOdY8UelMM3Br82ht6c8nOHCun3/tX BBmIxZMtuvGAhn0aqwuvttgE+/J0ZjdfVPe1WHRlr04QdJ2y4tWK1EQOjweW+U9Ivb 8WaryRfHvVFYjwyKMRRbfHyHB6XBnZkof4bZLHpdDJoYwW+IcUFqlylWAf3xT6ET8b 2niObggOxe0R9hpy/5kRPzwKCkHDz7cWw8xffeJdJqy7AUC3lFL1/z47Anc6yUJbg6 Ygf2w2ZbQJHc+pmjrtVQw7oJClE2ozEC5DXmYYAxmBkJUvyCerZb+hGduwFEZxU3ir 3+f299ayhIZJA== 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 B6C13A0065; Wed, 6 Jul 2022 23:35:01 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:01 -0700 Date: Wed, 06 Jul 2022 16:35:01 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 06/36] target: Return Function Complete To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Nicholas Bellinger , "Martin K. Petersen" Cc: John Youn , Felipe Balbi , Greg KH , Thinh Nguyen , linux-usb@vger.kernel.org, Christoph Hellwig Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org According to SAM-4 r14 section 7.2, for ABORT TASK function, a response of FUNCTION COMPLETE shall indicate that the command was aborted or was not in the task set. Currently we respond with TASK DOES NOT EXIST when there's no command in the task set. Fix the response to FUNCTION COMPLETE instead. Fixes: 3d28934aaae5 ("target: Add TMR_ABORT_TASK task management support") Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 2af80d0998bf..724ddabda488 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -170,9 +170,9 @@ void core_tmr_abort_task( if (dev->transport->tmr_notify) dev->transport->tmr_notify(dev, TMR_ABORT_TASK, &aborted_list); - printk("ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %lld\n", + printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for ref_tag: %lld\n", tmr->ref_task_tag); - tmr->response = TMR_TASK_DOES_NOT_EXIST; + tmr->response = TMR_FUNCTION_COMPLETE; atomic_long_inc(&dev->aborts_no_task); } From patchwork Wed Jul 6 23:35:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588453 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 82D17C43334 for ; Wed, 6 Jul 2022 23:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234376AbiGFXfM (ORCPT ); Wed, 6 Jul 2022 19:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234279AbiGFXfK (ORCPT ); Wed, 6 Jul 2022 19:35:10 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCD0F2C67E; Wed, 6 Jul 2022 16:35:09 -0700 (PDT) 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 7641CC06E7; Wed, 6 Jul 2022 23:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150509; bh=wEid/4p31uEfYV/Ls1d/d9euimuTb5BnMCIs9je5TBc=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=OmBuakiZeFAF/2zlteeGUsQsx05sBdJc2/sDMjBa0ZPJup+E68KsJsVze2sKv5mau HJRcT9E9M3nQbOiHCio9s8KwUbDL4R3y+9zfE+yfBcVs1bYwnMP9/RFIihXza8jJXA 1MLDswcg8VeWe44M0xVqfyPLreUnjEkN9NqxA8a8/fDPXMZ78/cH0Fro4CIDxKFx2T PiBoQYfritwGRxGOm/vxbRK4jiOJ5VNwztAyeGacx2BUmVA8y65P2y31KTORx4DR8a rM5Puvz4f8kFPCTcSa93A7pa87FgVslNWE+ZDKFWm3nzwR/LON3ioXnwfrU6wRY0AE xHgxv3+8CuMhQ== 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 D5AA9A006F; Wed, 6 Jul 2022 23:35:07 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:07 -0700 Date: Wed, 06 Jul 2022 16:35:07 -0700 Message-Id: <92ec6c71a200b42c1a70ba2054087da9715741c8.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 07/36] target: Don't do tmr_notify on empty aborted list To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If there's no command to abort, just skip doing tmr_notify to an empty list. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 724ddabda488..718d985e4860 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -167,9 +167,6 @@ void core_tmr_abort_task( spin_unlock_irqrestore(&dev->queues[i].lock, flags); } - if (dev->transport->tmr_notify) - dev->transport->tmr_notify(dev, TMR_ABORT_TASK, &aborted_list); - printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for ref_tag: %lld\n", tmr->ref_task_tag); tmr->response = TMR_FUNCTION_COMPLETE; From patchwork Wed Jul 6 23:35:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588024 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 A1BF2C433EF for ; Wed, 6 Jul 2022 23:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234406AbiGFXfV (ORCPT ); Wed, 6 Jul 2022 19:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234436AbiGFXfS (ORCPT ); Wed, 6 Jul 2022 19:35:18 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0BB62CC94; Wed, 6 Jul 2022 16:35:15 -0700 (PDT) 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 93311C06EA; Wed, 6 Jul 2022 23:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150515; bh=y5pkndQX80vQNmjBBzzMFVHmPJ3i9shoyXSIzhTSt24=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=hfDSR4OwLzKLLJttZbBBiDN+z5hI7kpwzzGubE7bCql0wZIekiBM3tXeJmvEcxMAt CfCsg0Esf1dG3FAFKJCas2zSIaVg6usJgyOM7RhOALtswmBnS2N7RdZhmxSFKJ3Fcs CrrTQr0Uv3Ekwt5u12ORwxi+l1XHXPRUp2NIv1gmlPrPVIONBSMBetKk+J2YIjhe8B 3d0zHOxl/WUbdgDNBm/JcjfGlYuxIqgHD9WtD1eyjCQJ5dhECBUu1vk5p5XrSp3bCc ZQZWYfznHqlzQsDKCwlGJFZpjzlvbjmrEj2z+E/yPj7nC7/XwZbaPbSVXbohyR/H0z MGVdoC90O8cQg== 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 5742AA0096; Wed, 6 Jul 2022 23:35:14 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:14 -0700 Date: Wed, 06 Jul 2022 16:35:14 -0700 Message-Id: <5b89eee29b74fbafaa9df34ca3f6170d1cfc5728.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 08/36] target: Refactor core_tmr_abort_task To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Minor refactoring of core_tmr_abort_task to avoid duplicate code. No functional change here. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 718d985e4860..3e73f60319d5 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -158,15 +158,13 @@ void core_tmr_abort_task( list_del_init(&se_cmd->state_list); target_put_cmd_and_wait(se_cmd); - pr_err("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for ref_tag: %llu\n", - ref_tag); - tmr->response = TMR_FUNCTION_COMPLETE; atomic_long_inc(&dev->aborts_complete); - return; + goto exit; } spin_unlock_irqrestore(&dev->queues[i].lock, flags); } +exit: printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for ref_tag: %lld\n", tmr->ref_task_tag); tmr->response = TMR_FUNCTION_COMPLETE; From patchwork Wed Jul 6 23:35:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588452 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 57971C43334 for ; Wed, 6 Jul 2022 23:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234436AbiGFXf0 (ORCPT ); Wed, 6 Jul 2022 19:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234279AbiGFXfW (ORCPT ); Wed, 6 Jul 2022 19:35:22 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062F12CC85; Wed, 6 Jul 2022 16:35:22 -0700 (PDT) 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 B06BFC06E7; Wed, 6 Jul 2022 23:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150521; bh=q878+lWPBGSxxokg46YfF8UDwB3RmWNiMqYhoPO3WVw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=TAHBkuf0ERT0AJ5voU2S9W450+/0+kWfwcaxW0bVLmiE+ubuDPTi1rcOKMdAUrt0a HdpZXUZKYjBLSc2cCoJoDLKdrrkmNnJOu2lp7nJXqEiYvWZG6huUgjZSrX9a9Y61kg PaQyXfqGgh3Q0XJtnloxCVPS0mQ7hAAyx+Lg1ODm8kIdagZbig0kyNI+2QlPxzYyv5 z8f3JS3uhk8oyOZP0aYormwk7kiJipCFhUsiJ3JR/ynRUrEK+K8VMyI45jqjOPPGqm On8aJKPbuF1HXRHPhqV1ByhOhEp9SIKB2TdYbZXT5OFZKsNM2Ch0pqcLkp5phNlIjA PPMiIHVfGOFVQ== 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 74ADBA0096; Wed, 6 Jul 2022 23:35:20 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:20 -0700 Date: Wed, 06 Jul 2022 16:35:20 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 09/36] target: Add common Task Management values To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add some standard TMR and match their code id based on UAS-r04 and SPL4-r13. Note that the non-standard TMR_LUN_RESET_PRO is using the same id value of QUERY TASK. Change it to 0xf0 instead. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 10 ++++++++++ include/target/target_core_base.h | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 105d3b0e470f..cbd876e44cf0 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3090,6 +3090,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 "(?)"; @@ -3538,6 +3542,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..ccd98604eaf4 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -206,12 +206,16 @@ enum target_sc_flags_table { enum tcm_tmreq_table { TMR_ABORT_TASK = 1, TMR_ABORT_TASK_SET = 2, - TMR_CLEAR_ACA = 3, + TMR_CLEAR_ACA = 0x40, TMR_CLEAR_TASK_SET = 4, TMR_LUN_RESET = 5, TMR_TARGET_WARM_RESET = 6, TMR_TARGET_COLD_RESET = 7, - TMR_LUN_RESET_PRO = 0x80, + TMR_I_T_NEXUS_RESET = 0x10, + TMR_QUERY_TASK = 0x80, + TMR_QUERY_TASK_SET = 0x81, + TMR_QUERY_ASYNC_EVENT = 0x82, + TMR_LUN_RESET_PRO = 0xf0, TMR_UNKNOWN = 0xff, }; From patchwork Wed Jul 6 23:35:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588023 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 32AFCC43334 for ; Wed, 6 Jul 2022 23:35:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234467AbiGFXfe (ORCPT ); Wed, 6 Jul 2022 19:35:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234448AbiGFXf2 (ORCPT ); Wed, 6 Jul 2022 19:35:28 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5DD2CC85; Wed, 6 Jul 2022 16:35:28 -0700 (PDT) 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 CAB2EC06E8; Wed, 6 Jul 2022 23:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150527; bh=CFa3kMjkUHA5vD1AUam1eiYQgAj3Bq4ibvH20BkWmqQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=ZgGGfPGsH6/3iYgkZT20Rqm84RAFL3h1JR3uvQAYiMa6u+G8X8rgELJfkcw+vpwwc LUQ29770dsEz8FHHYMtRYpNMI7BkPXoZYTzwFAM5HAtXO7vZV2iWpkozgq40qq8gCC XeVMfj7eCkFla161PQlJGsYd6nYMKIKhTAF6kjtwpQWCgD/QcGMPWLQCUNaKVKWE3b 1SorV+4hrhJW0dvezTSKMNOpJPRYS1ZxwfER1V1Zd0W8xqgMYP7eKtUeu6L0b4SuuD XMnAx2U17OCZ2CFzIYHyLqOAQHgxfyxgsNP+PfMhWR9AGI32ceQIVBDvFLlNkHBPjI rw+eHmoBEjM+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 91F95A0096; Wed, 6 Jul 2022 23:35:26 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:26 -0700 Date: Wed, 06 Jul 2022 16:35:26 -0700 Message-Id: <0004ae8cc8650a32f2aaab0ef9ee3b6e6eb6b69c.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 10/36] target: Implement TMR_ABORT_TASK_SET To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Task ABORT TASK SET function is required by SCSI transport protocol standards (SAM-4 r14 section 7.3). It is similar to ABORT TASK function, but it applies to all commands received on a specified I_T nexus rather than a specific referenced command. Modify core_tmr_abort_task() to support TMR_ABORT_TASK_SET. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_tmr.c | 16 +++++++++++----- drivers/target/target_core_transport.c | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 3e73f60319d5..e77721db1ea9 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -132,11 +132,13 @@ void core_tmr_abort_task( continue; ref_tag = se_cmd->tag; - if (tmr->ref_task_tag != ref_tag) - continue; + if (tmr->function == TMR_ABORT_TASK) { + if (tmr->ref_task_tag != ref_tag) + continue; - pr_err("ABORT_TASK: Found referenced %s task_tag: %llu\n", - se_cmd->se_tfo->fabric_name, ref_tag); + pr_err("ABORT_TASK: Found referenced %s task_tag: %llu\n", + se_cmd->se_tfo->fabric_name, ref_tag); + } spin_lock(&se_sess->sess_cmd_lock); rc = __target_check_io_state(se_cmd, se_sess, 0); @@ -159,7 +161,11 @@ void core_tmr_abort_task( target_put_cmd_and_wait(se_cmd); atomic_long_inc(&dev->aborts_complete); - goto exit; + + if (tmr->function == TMR_ABORT_TASK) + goto exit; + + spin_lock_irqsave(&dev->queues[i].lock, flags); } spin_unlock_irqrestore(&dev->queues[i].lock, flags); } diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index cbd876e44cf0..bc1e4a7c4538 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3519,9 +3519,9 @@ static void target_tmr_work(struct work_struct *work) switch (tmr->function) { case TMR_ABORT_TASK: + case TMR_ABORT_TASK_SET: core_tmr_abort_task(dev, tmr, cmd->se_sess); break; - case TMR_ABORT_TASK_SET: case TMR_CLEAR_ACA: case TMR_CLEAR_TASK_SET: tmr->response = TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED; From patchwork Wed Jul 6 23:35: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: 588451 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 485F9C43334 for ; Wed, 6 Jul 2022 23:35:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234472AbiGFXfh (ORCPT ); Wed, 6 Jul 2022 19:35:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234445AbiGFXfe (ORCPT ); Wed, 6 Jul 2022 19:35:34 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF6322C675; Wed, 6 Jul 2022 16:35:33 -0700 (PDT) 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 CEB7540C87; Wed, 6 Jul 2022 23:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150533; bh=aToiGLA9O7oYZ4jAsz46TfZTlCnEY70cMNLIBmiDQgA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=E5cjqX8UL3onxIFt07rTN6/7QonYsCpA62Umb8tu6WXXEeyB11QP5UWtj6MFJFBvZ Us8yPKh9Wxu/IB7t/cFLthvfC3FIUrcK+AVDe2BnC85j10NKPzMgb47xPX/tBX+VBT JSCg29y9dc7OVPwCWdfe6bQw7TxP4cjajHGLJ+tPsFyWuLKw5TJKffiL4qeiSg50Ve SjrfnQcuFhR8jRtZWT5yE82Meh9kXZcFd63v02k9xykoZJuaPyFBAjWVZE5J0hah+Z WkDVzgb+rwY+exbkN6m8Mhf3s3xMjuVUA0cEL2fRecm5hloSd57bRnGO8CiA6gktfF K1t9pZW5ToB+g== 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 AC05EA006F; Wed, 6 Jul 2022 23:35:32 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:32 -0700 Date: Wed, 06 Jul 2022 16:35:32 -0700 Message-Id: <61593a434f543184f41df91a4ba858e1158fd33c.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 11/36] target: Properly set Sense Data Length of CHECK CONDITION To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org CHECK CONDITION returns sense data, and sense data is minimum 8 bytes long plus additional sense data length in the data buffer. Don't just set the allocated buffer length to the cmd->scsi_sense_length and check the sense data for that. See SPC4-r37 section 4.5.2.1. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index bc1e4a7c4538..9734952a6228 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3459,12 +3459,20 @@ static void translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) cmd->se_cmd_flags |= SCF_EMULATED_TASK_SENSE; cmd->scsi_status = SAM_STAT_CHECK_CONDITION; - cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; + + /* + * CHECK CONDITION returns sense data, and sense data is minimum 8 + * bytes long. See SPC4-r37 section 4.5.2.1. + */ + cmd->scsi_sense_length = 8; + scsi_build_sense_buffer(desc_format, buffer, key, asc, ascq); if (sd->add_sense_info) WARN_ON_ONCE(scsi_set_sense_information(buffer, cmd->scsi_sense_length, cmd->sense_info) < 0); + /* Additional sense data length */ + cmd->scsi_sense_length += buffer[7]; } int From patchwork Wed Jul 6 23:35:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588022 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 E99C6C43334 for ; Wed, 6 Jul 2022 23:35:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234512AbiGFXfm (ORCPT ); Wed, 6 Jul 2022 19:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234496AbiGFXfk (ORCPT ); Wed, 6 Jul 2022 19:35:40 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C8E62C67E; Wed, 6 Jul 2022 16:35:40 -0700 (PDT) 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 12B24C06E7; Wed, 6 Jul 2022 23:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150540; bh=m9ECj4YTF1Q8AeFPvov7DBXyw0CywQmT4c9/1eSyfPM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=e8r1PmY0MUmGdoZlHd8GGIj5cHz9FhCnWAZzZj3t8SWu6G+HnC3pFCI1qRhxUDAJF ryORhQOB02bDTyVS0K6wGMOkO7RR7Lwv97nJVG/BXPjQeJa/TkEdkAHS2WQo5HAQGN Xa2tTnlYDt6p+rSHZI9j4uCcHze+9JdZtUGvX8SdPUu6QdgwRhsal52SK+sY0nFLXp 0xP32CoC4GThsIAl+bEiJSRQFMJUm5dQOAElhUuySvKoR1sPbz1RbWz+9YcKGxeaIg k5Y9tYJ2oGD54XDA0Qjed2qfbfhro9eP6EL8BHYB7Q+F0u/5rA0RSvXanaC4oBlvdg dv6DdgJwJSRcw== 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 CB6B4A006F; Wed, 6 Jul 2022 23:35:38 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:38 -0700 Date: Wed, 06 Jul 2022 16:35:38 -0700 Message-Id: <9cb2ee13f6edbcfd9b719e4b4b53f7cec0080d3b.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 12/36] target: Properly set Sense data length when copy sense To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The transport_get_sense_buffer() sets sense data length to be the allocated sense buffer length TRANSPORT_SENSE_BUFFER. However, the sense data length is depending on the sense data description. Check the sense data for cmd->scsi_sense_length. See SPC4-R37 section 4.5.2.1. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 9734952a6228..2fc4ba1814c6 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -771,8 +771,6 @@ static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) return NULL; - cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; - pr_debug("HBA_[%u]_PLUG[%s]: Requesting sense for SAM STATUS: 0x%02x\n", dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); return cmd->sense_buffer; @@ -791,7 +789,12 @@ void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense) } cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; - memcpy(cmd_sense_buf, sense, cmd->scsi_sense_length); + memcpy(cmd_sense_buf, sense, TRANSPORT_SENSE_BUFFER); + + /* Sense data length = min sense data + additional sense data length */ + cmd->scsi_sense_length = min_t(int, 8 + cmd_sense_buf[7], + TRANSPORT_SENSE_BUFFER); + spin_unlock_irqrestore(&cmd->t_state_lock, flags); } EXPORT_SYMBOL(transport_copy_sense_to_cmd); From patchwork Wed Jul 6 23:35:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588450 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 BC2A8C43334 for ; Wed, 6 Jul 2022 23:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234521AbiGFXft (ORCPT ); Wed, 6 Jul 2022 19:35:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234494AbiGFXfr (ORCPT ); Wed, 6 Jul 2022 19:35:47 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD372C675; Wed, 6 Jul 2022 16:35:46 -0700 (PDT) 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 2F89CC06E7; Wed, 6 Jul 2022 23:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150546; bh=VqZ4QrtIgHeYHuR+ZiRgwQmglyXuamz+Gex6t28X73o=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=H78ITZOWYvbQ4yyEl46xCuF/rnv/orb7iE/hyBx+jdzsZ9v0IzCcaj1VCZ56eRDAR 4o/mfQQ+7ZtFiOICHR6riUrKdIufY0hUS+lvVEujiVkZvK2BTy77/hQkT05dKdmJyq hl+cY6cSaCFdU09esFefH6zFUisCYL0JkuzTgvmFBlpYr3EhZlAraKtJk+Gek22IRU IB/3oEL2oVjfKMQTddeskNkNxivO7F2D+nsW04C9zc3HGJQ9TBPWHlXy7J0PpEBkGm Zc0it/lz+GBYOREIIOtwt9E/m+nteDh91FGGgiDBxzo/nyuC8x+KL83VMClXRDShUI ZKL6SMG141Q3Q== 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 EA904A0237; Wed, 6 Jul 2022 23:35:44 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:44 -0700 Date: Wed, 06 Jul 2022 16:35:44 -0700 Message-Id: <17031426bf0084a5342b9ed404368361bef7c50f.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 13/36] target: Don't respond TMR_LUN_DOES_NOT_EXIST for all TMR failure To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Not every Task Management failure is due to TMR_LUN_DOES_NOT_EXIST, which is currently being set if target_complete_tmr_failure() is executed. Only set this response where it should apply. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 2fc4ba1814c6..930bf8779d87 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1916,7 +1916,6 @@ static void target_complete_tmr_failure(struct work_struct *work) { struct se_cmd *se_cmd = container_of(work, struct se_cmd, work); - se_cmd->se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST; se_cmd->se_tfo->queue_tm_rsp(se_cmd); transport_lun_remove_cmd(se_cmd); @@ -1983,6 +1982,7 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, * to process context with TMR_LUN_DOES_NOT_EXIST status. */ failure: + se_cmd->se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST; INIT_WORK(&se_cmd->work, target_complete_tmr_failure); schedule_work(&se_cmd->work); return 0; From patchwork Wed Jul 6 23:35: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: 588021 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 0019DC43334 for ; Wed, 6 Jul 2022 23:35:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234528AbiGFXfx (ORCPT ); Wed, 6 Jul 2022 19:35:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbiGFXfw (ORCPT ); Wed, 6 Jul 2022 19:35:52 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 562E62C675; Wed, 6 Jul 2022 16:35:52 -0700 (PDT) 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 339E640787; Wed, 6 Jul 2022 23:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150552; bh=LZdfP1dedOAVuUz3XRTRsLB/VZpumsqI+DHamdN21kM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=JD0mvMO5r5a/X/MAWKtRRK4ACD4+ih+RZhFC0YONHr9/eKjs2WfEJjqt2g2cW73Ba 7ZZ6oBA9etEigMZp5+BaLDeQbm2x9gvgX9bQuNb1ixK8QJ28frUH39dkuhmPCxqzTS OI8tdX9PHDHRpqtttj/YX3mppA89JfS2i3vjpT15jBDv3LhYH/nmN1iIxvPu/Bwld6 hubhx+kU2xx14mMwhnRfBG9QN+ed4sdgWKvlzuUFn6CVkTA88RloD+N9+Nj0EBnVjK R/j9Zp6l9A/RyxY5EiqAvacso0EamSnebSrXfZjcSKqA+FU3iXA42nbxpb5ixVyMn8 bFYkhC+a6KX+g== 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 112F4A0063; Wed, 6 Jul 2022 23:35:51 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:51 -0700 Date: Wed, 06 Jul 2022 16:35:51 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 14/36] target: Introduce target_submit_tmr_fail_response To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Similar to transport_send_check_condition_and_sense(), some error condition and status can only be checked by the user of the target core (such as TMR_OVERLAPPED_TAG_ATTEMPTED). Introduce target_submit_tmr_fail_response() to allow the user to directly provide the fail reason of the TMR command. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_transport.c | 33 ++++++++++++++++++++++++++ include/target/target_core_fabric.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 930bf8779d87..c899da241b38 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1989,6 +1989,39 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, } EXPORT_SYMBOL(target_submit_tmr); +void target_submit_tmr_fail_response(struct se_cmd *se_cmd, + enum tcm_tmrsp_table rsp, + struct se_session *se_sess, u64 unpacked_lun, + gfp_t gfp, u64 tag, int flags) +{ + struct se_portal_group *se_tpg; + int ret; + + se_tpg = se_sess->se_tpg; + BUG_ON(!se_tpg); + + __target_init_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, + 0, DMA_NONE, TCM_SIMPLE_TAG, NULL, unpacked_lun); + + ret = core_tmr_alloc_req(se_cmd, NULL, TMR_UNKNOWN, gfp); + if (ret < 0) + return; + + se_cmd->se_tmr_req->ref_task_tag = tag; + se_cmd->se_tmr_req->response = rsp; + + /* See target_submit_cmd for commentary */ + ret = target_get_sess_cmd(se_cmd, flags & TARGET_SCF_ACK_KREF); + if (ret) { + core_tmr_release_req(se_cmd->se_tmr_req); + return; + } + + INIT_WORK(&se_cmd->work, target_complete_tmr_failure); + schedule_work(&se_cmd->work); +} +EXPORT_SYMBOL(target_submit_tmr_fail_response); + /* * Handle SAM-esque emulation for generic transport request failures. */ diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index 38f0662476d1..73bf6b372926 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -172,6 +172,9 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, unsigned char *sense, u64 unpacked_lun, void *fabric_tmr_ptr, unsigned char tm_type, gfp_t, u64, int); +void target_submit_tmr_fail_response(struct se_cmd *se_cmd, + enum tcm_tmrsp_table rsp, + struct se_session *se_sess, u64 unpacked_lun, gfp_t, u64, int); int transport_handle_cdb_direct(struct se_cmd *); sense_reason_t transport_generic_new_cmd(struct se_cmd *); From patchwork Wed Jul 6 23:35: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: 588449 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 DF2CFC43334 for ; Wed, 6 Jul 2022 23:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234568AbiGFXgB (ORCPT ); Wed, 6 Jul 2022 19:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbiGFXgA (ORCPT ); Wed, 6 Jul 2022 19:36:00 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E74992CC82; Wed, 6 Jul 2022 16:35:58 -0700 (PDT) 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 A15EEC06E7; Wed, 6 Jul 2022 23:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150558; bh=coRozXGBdbR7RSe6uUMa2STttmf3UXA5ykQYkUIgaII=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=UoMhhGOF5/oFsgrHI6yKi/owvhjNvpl7iSo6uLEPcn1UpYUFx0guBU7CXyJEA8I/+ 9dwSc6uXote6jnkMV/XothSHWx31isb1MzNqtSfoSET5R63eEUuKbAJUeXC7vQMP4e 2a/PH6ChlMEuSJgoNepQKnnYmHWJnKQ0zFhVjGFErsBhTkLLQ2mao9wnCUa70pZAT2 GVJ4PZNwm4ahl+5oq5qR1FqlEYpxnhdohc1qJWgf4l3bI1r8bN/D76fBsgUkSwB3tb M3vUyn0KA4qbBkDWgo0KIMJvicvm2meWbDgfrT8yE8Owo5CxLpZDmAb1jfJ3aE3jEC 524vXZqc/fTrw== 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 65EE0A0065; Wed, 6 Jul 2022 23:35:57 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:35:57 -0700 Date: Wed, 06 Jul 2022 16:35:57 -0700 Message-Id: <2557ef61dddba5056b9d89d73248bf4140e92f19.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 15/36] target: Include INQUIRY length To: 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The INQUIRY data length is minimum 36 bytes plus additional length jindicated in the descriptor. See SPC4-r37 section 6.6.2. The "len" here is the total length of the INQUIRY data. Make sure to include the 36 initial bytes. Signed-off-by: Thinh Nguyen --- drivers/target/target_core_spc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index dd799158609d..1801e10cd575 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -756,7 +756,7 @@ spc_emulate_inquiry(struct se_cmd *cmd) } ret = spc_emulate_inquiry_std(cmd, buf); - len = buf[4] + 5; + len = buf[4] + 5 + INQUIRY_LEN; goto out; } From patchwork Wed Jul 6 23:36:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588020 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 47D26C43334 for ; Wed, 6 Jul 2022 23:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234576AbiGFXgG (ORCPT ); Wed, 6 Jul 2022 19:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbiGFXgF (ORCPT ); Wed, 6 Jul 2022 19:36:05 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 084E12CCA5; Wed, 6 Jul 2022 16:36:05 -0700 (PDT) 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 B6AD0C06E9; Wed, 6 Jul 2022 23:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150564; bh=7XZC//FjT8V7YbxDMiaxmHsFWT/vd2SLfx/okdtJIOo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=TzpISlAhrUptKs9h3pUx6faJ69KLBUE9O5g6HODfywIuwfZMVV/SgR4b1zgXGSUG2 HIn7ERC3QWqW2CkFRrP5RGWePOV1ymX8mYxTj/wVZtNUrVJVSwbGlZiDcG5nOib5a7 YPQ3VkIfYLK+3mfY32GRdeWecXYmtD8o6cNreZoAB7DlmyOxHmqq2vbre96F7wWis8 +0gLSrYvz+JhHfKiPlP+WQqBDbUtaAXB8Bgm0p/MrVd9Hc4Iurz5zyubZWcJdDX+L/ hA7oDF4yGHUOdgg9v3PExxyt949nGxHr5/XPeu33upRea6VHcSJ5x2DwUvXYTuS9qj W7KttD/9H24mw== 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 826D8A0096; Wed, 6 Jul 2022 23:36:03 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:03 -0700 Date: Wed, 06 Jul 2022 16:36:03 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 16/36] usb: gadget: f_tcm: Increase stream count To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:36:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588448 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 AD5E4C43334 for ; Wed, 6 Jul 2022 23:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234583AbiGFXgN (ORCPT ); Wed, 6 Jul 2022 19:36:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbiGFXgM (ORCPT ); Wed, 6 Jul 2022 19:36:12 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3993E2CC96; Wed, 6 Jul 2022 16:36:11 -0700 (PDT) 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 DF199C06E7; Wed, 6 Jul 2022 23:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150571; bh=F3Qoy0QuryBNUqCHx2QWqtDm02xUe/FRghqpjnMdxjw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=flOP24YJugwaCOZ9Uar56iE4yMYr4U4ZIUtEjdfKmKY+/toHUzXlz3e07fTt5/x2i R9sDfEli8pAfDwUvQwBa5cKx6ww/icqA0TJZ3QoxkNTHlD52M6k+n02gC09myu/TSp t8piO0d5CNMeK5ij78/u9ejxFYgbcQDprvQHJsgpa0pWFmIVkbIq447AaHuy+Ev03F S/bISRQ/5CYbWdG77ipCAFQZSSU67XORYLsB6B3oar3MIC8g8E9wNgVQmoOH86+bpW ggqsOdoCLWoGL8HtZq2x9ghH+M8nsib6HcIvrCy5TlWuyzzhCgHFwGUYe77ujr2cPB 2tEbv5LNDi35A== 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 97F43A006F; Wed, 6 Jul 2022 23:36:09 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:09 -0700 Date: Wed, 06 Jul 2022 16:36:09 -0700 Message-Id: <333ce15207bc7ef15e3df97280bacc7639937da1.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 17/36] usb: gadget: f_tcm: Increase bMaxBurst To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:36:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588019 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 42B49C43334 for ; Wed, 6 Jul 2022 23:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234609AbiGFXgU (ORCPT ); Wed, 6 Jul 2022 19:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234586AbiGFXgS (ORCPT ); Wed, 6 Jul 2022 19:36:18 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A4F32CCB1; Wed, 6 Jul 2022 16:36:17 -0700 (PDT) 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 0D030C06E8; Wed, 6 Jul 2022 23:36:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150577; bh=ID+KNbEF1qrOBaTI4FRkar7KOfJ0VQUCqvZyNnmVmF4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=I6w3zyy8CinvsvJflrUFt8d0Yck8DvLE/GyyYYb+dP637KteO0D71zqyUdoQJ0g3u Ll+jpeb81WnRiM5jezzBizEzWy45oMDmQCTR/3qZqhZmF9hSYuZ0ypdZF7zprQ2E0U j7hq9eeMQivTqIuAZukFdRX7Sm8u+CAhMRli+t5fX4Wa44PWpB7FfLT88TzO6ylnZR FEm0CCC2/IfzaupwDYZh6+93qJK6jLierf6+kz1qSLvzD30LYwtJV0Gh5LTyNvMbzY rhR1i3G+4jrGWbsE+ktLEueEfowkRBCNpWrA9tPojffOJHU07+ephV6Rezn1y1riVJ RnbY+WrtE8qAg== 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 C0F56A006F; Wed, 6 Jul 2022 23:36:15 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:15 -0700 Date: Wed, 06 Jul 2022 16:36:15 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 18/36] usb: gadget: f_tcm: Don't set static stream_id To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Host can assign stream ID value greater than number of streams allocated. The tcm function needs to keep track of which stream is available to assign the stream ID. This patch doesn't track that, but at least it makes sure that there's no Oops if the host send tag with a value greater than the number of supported streams. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:36:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588447 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 17DE4C43334 for ; Wed, 6 Jul 2022 23:36:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234616AbiGFXg1 (ORCPT ); Wed, 6 Jul 2022 19:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234610AbiGFXgZ (ORCPT ); Wed, 6 Jul 2022 19:36:25 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B04052CCA5; Wed, 6 Jul 2022 16:36:23 -0700 (PDT) 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 2ABFA40787; Wed, 6 Jul 2022 23:36:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150583; bh=XmkV08/1OWjuoGBMF9UqFv99vhmgKcYXwDcNGVMohpg=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=cqxm+5pvyLKmOOIhg3Yf2qcSs6LzOLCk0AdaLThAazPuqAlv/7rkgnYJKLCKh5lPh TafeLuqH6BV1L9+2aA9WJggi/MSB+4OKcNy3EY1XBDaJpOMI53+KQlf0Oqd30CoSar qNxLfdsqbuviOOuia3MdcoPw7jfxt2uM881SjvFwZ8y2mBJPf095r/tq/D+MLXtLiz D3lSQLk8C7BnHdupx0OIKbrOIKoIpnEqWknf3kaWdTVFjrkGT0kmXVcee04NLZI1ED IEIFSBPkWHek0clBht8dImNMpFkoLD1gyRyi7ZC5wFTPsOr+DsMmduNR0h+ncl2wx+ JicaJihdKrAWg== 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 E5DEFA0096; Wed, 6 Jul 2022 23:36:21 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:21 -0700 Date: Wed, 06 Jul 2022 16:36:21 -0700 Message-Id: <8c031f3f2ee313efc07ccf1c6ee24451e501aecc.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 19/36] usb: gadget: f_tcm: Allocate matching number of commands to streams To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org We can handle multiple commands concurently. Each command services a stream id. At the moment, the driver will handle 32 outstanding streams, which is equivalent to 32 commands. Make sure to allocate a matching number of commands to the number of streams. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:36: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: 588018 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 1FE4CC43334 for ; Wed, 6 Jul 2022 23:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234639AbiGFXgh (ORCPT ); Wed, 6 Jul 2022 19:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234610AbiGFXga (ORCPT ); Wed, 6 Jul 2022 19:36:30 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642612CDC0; Wed, 6 Jul 2022 16:36:29 -0700 (PDT) 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 44E7940CB0; Wed, 6 Jul 2022 23:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150589; bh=4SmiljU/B5qo4IXZ7glKCXdA5yUHCmpz6d2nsJHU6pE=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=iRm3cadgMmDHf2tqQ2n6cpnAxxxwP3rO3oMj+wLvAENpMZLFuHgo1KczfrHEmHg5r aK/ytIIJvXp37k+9isNN3l8mj/3+ysr549FMSgsxH2vZiJYdidiOxcGai/mVLGCBg6 Vh00sGh7KWnhmj6AA9Vh4UPamxUoK+uB4SEaiWjowstPKOizFGP0SWUnWQNEljkWSM nr1Qdt2CyYO0NPgR6nrRJq8A5MIQaDb3CShJgdgmwl7NKV8TN49V+9VSfugJicYQyY B5mwNumPLQzi6/uzNQSp/c5vHgJTGM5RFRJPQMkHG7yggTdY/DWczhfF0inmwWWfGz 64NhStKNmHsrQ== 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 271D4A0096; Wed, 6 Jul 2022 23:36:28 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:28 -0700 Date: Wed, 06 Jul 2022 16:36:28 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 20/36] usb: gadget: f_tcm: Limit number of sessions To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Only allocate up to USBG_NUM_CMDS number of sessions. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:36: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: 588446 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 408DBC43334 for ; Wed, 6 Jul 2022 23:36:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbiGFXgl (ORCPT ); Wed, 6 Jul 2022 19:36:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234635AbiGFXgh (ORCPT ); Wed, 6 Jul 2022 19:36:37 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AFDC2CDD2; Wed, 6 Jul 2022 16:36:35 -0700 (PDT) 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 6A31940CAF; Wed, 6 Jul 2022 23:36:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150595; bh=b0z6oYvD/qo8jaCPnFSickuF7051V1qJDrAqeJZJ2cw=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=jFedgQEH1E/yjsAnkPHWe4oz77TXUSmQ+mD5lr5F5xIrXiU6KPEYZHixddkuuy8qR s5ygmfDxoSeRqTIhOD6zDCWjg7kLLBQvn+95Z+yQjrIASDGg/ES4N/O+aXOWjHt7pK HeHex5kq1WD/lcBwEhEx7YToS7NK4a1QEZY5r2yDJ5wTIB36pqPLN3dGHlY4chwLDE 5rMS56HFnc2FsfxC+dGV9Kp0dzkVS4fePKAKsnNGLrNxJnZ9DdXapYSKjliOKMJ86L U4ThST9E7KUaP8LVDmsrzYiqJuPQUaFS2X1vCwfixl+wgiJkq5ag7wtal/DLBp2J7v QFQN1dp7qBAzg== 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 41932A0063; Wed, 6 Jul 2022 23:36:34 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:34 -0700 Date: Wed, 06 Jul 2022 16:36:34 -0700 Message-Id: <6f7b66be0db84fc5a362293dbff6674f19a5b311.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 21/36] usb: gadget: f_tcm: Handle multiple commands in parallel To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Resubmit command on completion to fetch more commands and service them in parallel. Increase the number of work in a queue. Each work will be for each command allowing them to be processed concurrently. Also, set them to be unbounded by cpu to improve performance. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:36: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: 588017 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 B29B1C433EF for ; Wed, 6 Jul 2022 23:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234656AbiGFXgr (ORCPT ); Wed, 6 Jul 2022 19:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234610AbiGFXgm (ORCPT ); Wed, 6 Jul 2022 19:36:42 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A750C2CCA8; Wed, 6 Jul 2022 16:36:41 -0700 (PDT) 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 8263340CAF; Wed, 6 Jul 2022 23:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150601; bh=bAS8o77Z1Y+tMzGOThOXTs6nCn/UzEd3nCbgY2zNJnA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PamxDTt/zxJOTIpaGJgHyUYsZvb+vRoUVGHQCiBW0CIcGh9r5QcTC46XukSFsLGkd dJphZBwReCoydzIL5nxf5MkXu0CEO+YHoCu4Lz+ptKzIXPuyKJRfkIeWbc+bDqtoCG Z7s4k1SGTks+ODWip2zoQrkl/bBQKd0KDumt2ULmDRPYphMt+5nUDG2fRu06VGGaUo EJeSrZGkbkNSBOj6qM8ejdi9y7UWHFetqaz7fMzNQRrNZh3RsoxCMjos+sdiWy1abt 15TGk2cSvAdtk2SbxKYUlYsSLJLfUk071A6eNntMZGXWf8Om3DJgfyPynB3FuWa97q yUoZZLDm8Srdw== 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 659F1A006F; Wed, 6 Jul 2022 23:36:40 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:40 -0700 Date: Wed, 06 Jul 2022 16:36:40 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 22/36] usb: gadget: f_tcm: Use extra number of commands To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:36:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588445 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 D6A10C43334 for ; Wed, 6 Jul 2022 23:36:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234683AbiGFXg6 (ORCPT ); Wed, 6 Jul 2022 19:36:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234610AbiGFXgs (ORCPT ); Wed, 6 Jul 2022 19:36:48 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BA8B2CCBD; Wed, 6 Jul 2022 16:36:48 -0700 (PDT) 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 BBA36C06E8; Wed, 6 Jul 2022 23:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150607; bh=YGzx5por/UlZOG67bE/uBBta4HSH9MaY/jMT7mI9Li8=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=fV8JkjJd8JHk0pbIrF/uXrQ9ErQYZEQzgIDmdnkQuKh7wlX65mkFr51aTFkcxydF1 bnM9mO8GqJidJeeAxqE1/8n8ZFhdOQd9lgHgRc+UZGYczsDQnvkozrbADSFw+mtbH4 jH+ce+XArG8+1i7cmdbxqaDUY4OJeBSC2BJV6eyLSOGT0ZzGAEsBheNywN1P4w2aQD 1FvsI6r6oNP41tSLX0AuMTR4PLt3GvHf984VkxnQC9MwNHd++VSlSOdRhlniNQqY89 m3WN2tsEobyaFwVWn8PvdPEo59Fai6JQ0P3zl7DX33JGEGJHAYO5kJdgkrcNYiEslk hq6u/UU+v31Uw== 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 7EB60A0063; Wed, 6 Jul 2022 23:36:46 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:46 -0700 Date: Wed, 06 Jul 2022 16:36:46 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 23/36] usb: gadget: f_tcm: Return ATA cmd direction To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Check ATA Pass-Through for direction. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588016 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 303A6C433EF for ; Wed, 6 Jul 2022 23:37:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234663AbiGFXhH (ORCPT ); Wed, 6 Jul 2022 19:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234650AbiGFXg4 (ORCPT ); Wed, 6 Jul 2022 19:36:56 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27F642CDE8; Wed, 6 Jul 2022 16:36:54 -0700 (PDT) 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 DA29BC06E7; Wed, 6 Jul 2022 23:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150613; bh=H1Y0fI12pHBObx79yeAmuO8D3fEdIGn4JCaPf1w581c=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=PGyfh1X1xudkrfbqvnGhZY7LHelRIZoHhmA1thcm/EIQAaD+/ipAQtptShmUk3mJL FxM+9k7aVeMXlUtnxxG3Q0vOFv2fKWYB0++mCzSIsZYToCgzLdgVrFAod6CKZ1iaxU OLQOQbsZmntkh+G3xux/0bNvbUweTOX5dtNLPIlU4ewKrAXLIPz/a0lgEkuBQw2Io0 0P26dX27N09/FJVdtzrQGZelJoUGs/ZGJSY7v+aV7HtQ73LEVUcbwP/vAu1HT1hR2a aKNzLSXQQ1SuSHg9ufCJSU6wRk1VqRXzrFxeeULtWEeF2MvyvXk/yimgnDekQeOJiA X5UfXM4pFjd/w== 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 9D37CA0096; Wed, 6 Jul 2022 23:36:52 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:52 -0700 Date: Wed, 06 Jul 2022 16:36:52 -0700 Message-Id: <8dc7362e3493da40caa3a6b6029701fcdfa765f6.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 24/36] usb: gadget: f_tcm: Execute command on write completion To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:36:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588444 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 9DFCFCCA47C for ; Wed, 6 Jul 2022 23:37:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234618AbiGFXhK (ORCPT ); Wed, 6 Jul 2022 19:37:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234622AbiGFXhA (ORCPT ); Wed, 6 Jul 2022 19:37:00 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 449F92CCBD; Wed, 6 Jul 2022 16:37:00 -0700 (PDT) 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 01458C06E7; Wed, 6 Jul 2022 23:37:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150620; bh=JnxikKbjvXzJXotPBzekngWry19ktZFxoUadaalhjvA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=YrdmeYZ2qdtKsSuWdnUD2J5x2ZgJveuo+UkF/tpPxtV/ulTW1eZt2cMc839EKiZxi v3vE23StHpda5nIJ7eQxCCqWwWrIc666K0HHnr8CReXnFfJxcufFAmrQdZjrQfxlSx VGhSHaVU1xtwzg0MvigiqGCKRSaIvL3EylwFt5BI8h9p/CDxY1BlOn75mbiAV5xX2f ImOYJewrIlqTRI2nyM79lWjPoFNNdvuAO6WuUoo+6SPQ8o4LVU8UBKMcuFKFgQR44M yZQv3FMnXOYRN2ck8tBfsIoCwcMGK8SSHQrRPxxoG9rQEtlECbdWSdz7tPNpQSpIQy BWY5Ytrs375mQ== 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 BA318A0096; Wed, 6 Jul 2022 23:36:58 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:36:58 -0700 Date: Wed, 06 Jul 2022 16:36:58 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 25/36] usb: gadget: f_tcm: Minor cleanup redundant code To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:37: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: 588015 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 8C0F2CCA481 for ; Wed, 6 Jul 2022 23:37:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234679AbiGFXhM (ORCPT ); Wed, 6 Jul 2022 19:37:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234661AbiGFXhH (ORCPT ); Wed, 6 Jul 2022 19:37:07 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 543DD2CDC9; Wed, 6 Jul 2022 16:37:07 -0700 (PDT) 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 24BA54077F; Wed, 6 Jul 2022 23:37:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150627; bh=W3tGsKXgdwRs/twkzD8FF5EhDgkxWHBsOlMoHb/p1PM=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GArJC/WUl97fb3nWZ0mwuxUzY42cIaWFioeguUU66TtftiEgAWZ4SBUftPInevBP8 din840CmruWWMKRrm67jEnQaBTtAkNh0zWDr5GGDoihyR/C8RmWqd1AEQkF/OUcOsI dhhtUSPZS0/oDuHnKQfSoNcrDJhqf4dUA55I7KsnbSO0iZfsjSMHz0t7Ja4OIfKIH/ 2Pa9Ol7qetZ6GFtsdsGOU3o9WvM/i0euzyEmatxasD/XM7JlJvJz9Vvnqzrk4axrJr XYyr4D15KUac+voU1GFLeUacvHyaaB/1/+y85uIFVhv0s+V5gsthbJB56wG+w7I71g j0jjLacMmtgIQ== 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 D76F0A006F; Wed, 6 Jul 2022 23:37:04 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:04 -0700 Date: Wed, 06 Jul 2022 16:37:04 -0700 Message-Id: <73f6f1ed35feba3db337124a860bd2c89817db0e.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 26/36] usb: gadget: f_tcm: Don't free command immediately To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , Nicholas Bellinger , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Andrzej Pietrasiewicz , Sebastian Andrzej Siewior Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 Wed Jul 6 23:37: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: 588443 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 20B1EC43334 for ; Wed, 6 Jul 2022 23:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234531AbiGFXhV (ORCPT ); Wed, 6 Jul 2022 19:37:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234523AbiGFXhP (ORCPT ); Wed, 6 Jul 2022 19:37:15 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0FE2CDCF; Wed, 6 Jul 2022 16:37:14 -0700 (PDT) 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 0C1A440787; Wed, 6 Jul 2022 23:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150634; bh=hc+Kg8C/uliaa9f3+AzFdNq64S4itgFWRR5PyNmRGCk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=KhSoMam4EvxPgGOx+cQKtdirJjUpHbiZ1JSk6p4L2hq+JecxHK3NhyQNwcefYvEkl zgeCxJJ7ucND/3kT6IafD/ZutZJxtMMGoAtprNZw5ag4uMvbCNPGUuiWNdtp99IGMd n9ougeuZOkshj+Y2ApRdiHFvNuQLu8yh9A0xvYY9D72Z5u/xkGBiSCsOxUR+zuRVgJ FYKbrcixAW6rVG0xYds1uuaJdO3ThC2z4/++NWlv7AVBjI6yKPOuz52/WMf2q6KAjq qiqYyuF1gFlXGbtugpvS6MM67WvdUkKLe+remgo0MuYGwjz+2M8fzSVBDfNyxsKQuO hxOUbzh9sLEeA== 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 201BCA006F; Wed, 6 Jul 2022 23:37:12 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:12 -0700 Date: Wed, 06 Jul 2022 16:37:12 -0700 Message-Id: <342c691002b7d39f72ed1a51bc3907c57b2954b6.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 27/36] usb: gadget: f_tcm: Translate error to sense To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , Nicholas Bellinger , "Martin K. Petersen" , Sebastian Andrzej Siewior , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, Alan Stern , Christoph Hellwig Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When respond with check_condition error status, clear from_transport input so the target layer can translate the sense reason reported by f_tcm. Fixes: c52661d60f63 ("usb-gadget: Initial merge of target module for UASP + BOT") Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:37:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588014 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 07FEEC433EF for ; Wed, 6 Jul 2022 23:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234627AbiGFXhW (ORCPT ); Wed, 6 Jul 2022 19:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbiGFXhV (ORCPT ); Wed, 6 Jul 2022 19:37:21 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8359B2CDC0; Wed, 6 Jul 2022 16:37:20 -0700 (PDT) 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 3EEB5C06E7; Wed, 6 Jul 2022 23:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150640; bh=dA2YHCwSJAcz5AMgI1fqU2N3tyrdZDQD1ZO/Td92ZvQ=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=bdzRmZTHphuShNJUHu1XzuV8qt3YtU9eTBa/vdaK0/BV/vazmJ/Mqjnsq8GdCmQdS ebpKOT0X70qikChv8FzWNqJTcsi16LcZmCbbjCxGw6hypuhVUIet/q7G1Dzex1oH+/ RQGnxz/UKeg/VxE+N+0mNo5+uVSXcZp1VwDG1jhZZ8cSq7lJ/KAPjrFqbpC4QTsjfw JzHX3krbhcNicaYxagT6M1yGJiH3yjD8c7wVNDVdD4qoPBEUKF9J18Wmfg0tkRH+yY GvlrvxGVSY6wPjdoTFktC47WDutS5ZItyn89kOCWjpCJ5jYsn9MUCIkte+wPVIq/uf /4FNYGyDIsg4A== 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 F3ED8A0096; Wed, 6 Jul 2022 23:37:18 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:18 -0700 Date: Wed, 06 Jul 2022 16:37:18 -0700 Message-Id: <5c0de82cc09fdca096aca491843918355faceb33.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 28/36] usb: gadget: f_tcm: Cleanup unused variable To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org se_cmd is not used anywhere. Remove it. Signed-off-by: Thinh Nguyen --- 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 Wed Jul 6 23:37: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: 588442 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 1C342C43334 for ; Wed, 6 Jul 2022 23:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234702AbiGFXhb (ORCPT ); Wed, 6 Jul 2022 19:37:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234701AbiGFXh3 (ORCPT ); Wed, 6 Jul 2022 19:37:29 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A21082CDDE; Wed, 6 Jul 2022 16:37:26 -0700 (PDT) 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 5DE04C06E7; Wed, 6 Jul 2022 23:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150646; bh=oa6xu0ObsRu520otSO2oJVyaSj320UHpAKlVmc3OV9k=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=YQ9FJAlx2Im0RjRPqXBtUfkPLlFE9h/3eJHOaP7IvQpKEXjG5gzBAaAxYVLk4XWa+ +xzdBuk6DwWK+WUHXYCln1p9h4dsJcTqRtmGvkNBkE6Tsyvh7+Mxcsgjncw5m5k66J H92fuoovAsUHDoPolYNn1a+Qa1z2MowKw+HCqTKDr6+Dd9K7nwQST+7TjmwZ3LFFXz QioR/FA6bwCaPJuOxx4wKnoEHF5Jf2EutwzzoEmCfdB3hy2xHjrc+fXKkqr2GMNZbb cH6UJYtsDK2tKeZKuhJkP+ABi3fNERd1ubs2vwVDKDxhTtEJWM6SCZseorsI2+q4Yn xjymDBobOJaiw== 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 1FB49A0096; Wed, 6 Jul 2022 23:37:25 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:25 -0700 Date: Wed, 06 Jul 2022 16:37:25 -0700 Message-Id: <3b9f369c245b9029ce225cc7e1bdf3815ab78542.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 29/36] usb: gadget: f_tcm: Update state on data write To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When preparing request for data write state, the next state is UASP_SEND_STATUS. Signed-off-by: Thinh Nguyen --- 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 1e7d29f8aecb..c7f64d0eba0f 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -976,6 +976,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 Wed Jul 6 23:37:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588013 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 855F7C433EF for ; Wed, 6 Jul 2022 23:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234704AbiGFXhe (ORCPT ); Wed, 6 Jul 2022 19:37:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234523AbiGFXhc (ORCPT ); Wed, 6 Jul 2022 19:37:32 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82D542CCAF; Wed, 6 Jul 2022 16:37:32 -0700 (PDT) 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 631C54077F; Wed, 6 Jul 2022 23:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150652; bh=4E78Qdi0bMwX8IqwoL/VcWhUlyD+K8rZ+0+hKD0xQAo=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=NPEtaX7Sf9LHnhs+K38YVTjv/IiBkqH1YaS5oRj28v487D2rkV0zFzEL2GZeSpXDV TGhtpoXk9/J4SZ6THACjuPQeTf2dr/iBv22GY3/mOMtp0e2KsuDuSVHykhtTgGX6Su P06ZYfe1tmSKO6E11Ev6XwDM00p4PWzXCNYHPJC5Zfl0H0+oI35Um4p5oas3i8V9M7 qpmanIY0jLSMkJOdlc6MRwpirxUh0fomociUSYjsn55PztLYmBLo6vuHFvdThE9PMc qfnZEr/WqKW7fQgToy7XNTM8uce0jlBgGVTrkQxPuh7/ss86CbqdWfVZG7ym2Qy+pk lMSEN9HXbbKxg== 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 3E5B3A006F; Wed, 6 Jul 2022 23:37:31 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:31 -0700 Date: Wed, 06 Jul 2022 16:37:31 -0700 Message-Id: <90d31ee68d69cd875c4d4f6e29783b45ebfb1e89.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 30/36] usb: gadget: f_tcm: Handle abort command To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Implemented aborted_task to cancel outstanding request. Signed-off-by: Thinh Nguyen --- 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 c7f64d0eba0f..d15008b14beb 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1276,6 +1276,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 Wed Jul 6 23:37:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588441 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 F0CD3C43334 for ; Wed, 6 Jul 2022 23:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234523AbiGFXho (ORCPT ); Wed, 6 Jul 2022 19:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234729AbiGFXhk (ORCPT ); Wed, 6 Jul 2022 19:37:40 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB18F2CDED; Wed, 6 Jul 2022 16:37:38 -0700 (PDT) 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 838C140CB0; Wed, 6 Jul 2022 23:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150658; bh=JiYHnhrRXvLBGRy/eKUbd/upiMBoGhP32EnyJ2uIdwk=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=dZfQ2S5ATvrRt8ejPx26UfoXcgG+i4gC/KDm8K9zddJTBsSGG5zMdvbad9sYzMFLs sqkrDxkQEfYTGQyDKI7Zva1Yb+vfgrW+RcjUSoWaHXB7yVt3jL4idPL1QdoM3widex 2egRIZOaUotbrDy+9yjOC6YY5jcxnu354koLHfT21IaSMvz8p0WH/LGEkvPTmo4RjQ ciH/y73kJMp3+0y+sq8Z5IZCipu3GFveOdGbUZH+96U24vVTrqzhMB1r2vtCN88ERz HLNidov4Oxv6+G9xshBlBktWIiNEQ1JJX+Y+BsMvSixU7FkUQSkZdGfUJvLhLCPLUD /2aBhxbdzJKBw== 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 5EFF5A0096; Wed, 6 Jul 2022 23:37:37 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:37 -0700 Date: Wed, 06 Jul 2022 16:37:37 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 31/36] usb: gadget: f_tcm: Cleanup requests on ep disable To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- drivers/usb/gadget/function/f_tcm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index d15008b14beb..7162be5fdf2f 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) { @@ -934,7 +934,12 @@ 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; - if (req->status < 0) { + if (req->status == -ESHUTDOWN) { + transport_generic_free_cmd(&cmd->se_cmd, 0); + return; + } + + if (req->status) { pr_err("%s() state %d transfer failed\n", __func__, cmd->state); goto cleanup; } From patchwork Wed Jul 6 23:37:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588012 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 1548FCCA480 for ; Wed, 6 Jul 2022 23:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234725AbiGFXhv (ORCPT ); Wed, 6 Jul 2022 19:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234666AbiGFXhp (ORCPT ); Wed, 6 Jul 2022 19:37:45 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C99B2CDE3; Wed, 6 Jul 2022 16:37:45 -0700 (PDT) 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 C4F57C06E8; Wed, 6 Jul 2022 23:37:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150664; bh=sozJ++cXeSxQ4ZCq/1PovSLzC4Dfvr8b/qzLB5n6zPs=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=GE4LD9+iU2DLHLLCgJ0lTg/NM263EvJFUlDUhEkcKkHBMfnKNuXZA9xKh8iXrFFjN iZwX/CUIgRISX5ygBlRvlMeRLVrvDRO1kWIUjJcqhry7hPDawRtWMag41BgvLPIVIX 3FPkQamOSnbxqDXHd12akxGKOjMuwXxre7cE55PmJ2mgDgCDXgNXQ2ctGbIsXDYjan HrDiDI2hMhVdi1XIWEhxpq7wp+L/85AQIPsOcH0VdIjbc93UFMg4heHDSMK9Ratn7O BvhH/xOBT2rLs8HkGXHisAcFOVrrDUpkdxLofTmui2272sFlgvKlAGJVLGay++FMOr 9taZLv2VZk55g== 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 7E6DAA006F; Wed, 6 Jul 2022 23:37:43 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:43 -0700 Date: Wed, 06 Jul 2022 16:37:43 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 32/36] usb: gadget: f_tcm: Send sense reason To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org If there's a failure, report it back to the host with a sense reason. Signed-off-by: Thinh Nguyen --- drivers/usb/gadget/function/f_tcm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index 7162be5fdf2f..fb9b71158c4b 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -669,6 +669,9 @@ static int uasp_send_read_response(struct usbg_cmd *cmd) pr_err("%s(%d) => %d\n", __func__, __LINE__, ret); } out: + if (ret) + transport_send_check_condition_and_sense(&cmd->se_cmd, + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0); return ret; } @@ -711,6 +714,9 @@ static int uasp_send_write_request(struct usbg_cmd *cmd) } cleanup: + if (ret) + transport_send_check_condition_and_sense(&cmd->se_cmd, + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0); return ret; } @@ -955,7 +961,15 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) return; cleanup: - transport_generic_free_cmd(&cmd->se_cmd, 0); + /* Command was aborted */ + if (cmd->state == UASP_QUEUE_COMMAND) { + transport_generic_free_cmd(se_cmd, 0); + return; + } + + cmd->state = UASP_QUEUE_COMMAND; + transport_send_check_condition_and_sense(se_cmd, + TCM_CHECK_CONDITION_UNIT_ATTENTION, 0); } static int usbg_prepare_w_request(struct usbg_cmd *cmd, struct usb_request *req) From patchwork Wed Jul 6 23:37:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588440 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 614E3C43334 for ; Wed, 6 Jul 2022 23:37:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234595AbiGFXhz (ORCPT ); Wed, 6 Jul 2022 19:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234708AbiGFXhv (ORCPT ); Wed, 6 Jul 2022 19:37:51 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E918C2CDD6; Wed, 6 Jul 2022 16:37:50 -0700 (PDT) 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 C9EEB4077F; Wed, 6 Jul 2022 23:37:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150670; bh=/RISCmRz56QKvQJvxjK6Y26DGM4C3D1LuInOMKo9zn4=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=M7QxtFtdGy77qti38DJ7WK7Gx7L+vk5ieLKMa2UeeCm/nTwC015NXztbpgAiehzAq ssqyQBoMZYXMwLJbGq/KcSjhpm0i6T7yp6my0tvJa8UdV9NGpUicn3mZeav0ZW+ETk PaZBjG+nSLqqTHbfpMWJDbX7I8MDuNZo/Cr0xl/fja7EVzky9VtvwyqQBe2z9Eo90m /xJoBJgFd+cwOZDUX+U0pGqJjX1Dn5FW/pWjD/cuC354sG5qsTbNQIChz8aduQXUlh DWj0UkeBcGsVl+LOf2vdEpcbUCoEopDCsXfujw1vNi5CPCCHbd7yT1AqlfbGLDXPwn JtjqIil6GI/wg== 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 A666EA0096; Wed, 6 Jul 2022 23:37:49 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:49 -0700 Date: Wed, 06 Jul 2022 16:37:49 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 33/36] usb: gadget: f_tcm: Save CPU ID per command To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 --- 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 fb9b71158c4b..c13aa61d82aa 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1082,6 +1082,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 Wed Jul 6 23:37:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588011 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 32A0BC43334 for ; Wed, 6 Jul 2022 23:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234738AbiGFXiC (ORCPT ); Wed, 6 Jul 2022 19:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234740AbiGFXh5 (ORCPT ); Wed, 6 Jul 2022 19:37:57 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.87.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 576E42CCB6; Wed, 6 Jul 2022 16:37:57 -0700 (PDT) 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 108BCC06E8; Wed, 6 Jul 2022 23:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150677; bh=qjumXPSqSC2H/3vK7/X+IjhPPbUDz4xo5sZJBKB2S6k=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=jNXcNU5HsF8YCbRsIBFwgEdK8rAUpoIaiIA1eLHC3JLKKEIMcaRJ8GaSMdS88IL9X tTAmiilN80Byim5eKqnPHAwU213mkgHZDv0jXJ1yXorqumF6aFp0Mg3v26XYNUM3eJ 57Nj7JTE1yTvfYcjD7m8FnCtUjGW8fu3J/Fq5y7PXTT0vwutAovD9aQ1Kbdd7Slg1J LPCpQFqZkfGZkSqOT5eHQaVb4KfM2N99i2ku6JfmUm6jB+52766z7AfzvzCHKdZ9zR 5+ihOjarpGRoJt3d4Bivjkqh5oBnCTiKUw5Gls+sxCK5e3sj00sKdbA4EcwSINUhLK lq/OiDs0zGxzg== 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 C5451A006F; Wed, 6 Jul 2022 23:37:55 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:37:55 -0700 Date: Wed, 06 Jul 2022 16:37:55 -0700 Message-Id: <6a5487365f0804447d4cbb8911d0719d8b21b601.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 34/36] usb: gadget: f_tcm: Free tags earlier To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Free up sbitmap index immediately once the command is completed rather than waiting for kref to call freeing tag. This keeps the sbitmap queue free quicker. Signed-off-by: Thinh Nguyen --- drivers/usb/gadget/function/f_tcm.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index c13aa61d82aa..fa09999adda7 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -570,6 +570,7 @@ 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 se_session *se_sess = cmd->se_cmd.se_sess; int ret; if (req->status == -ESHUTDOWN) @@ -603,6 +604,8 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) break; case UASP_QUEUE_COMMAND: + + target_free_tag(se_sess, &cmd->se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); usb_ep_queue(fu->ep_cmd, cmd->req, GFP_ATOMIC); @@ -614,6 +617,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) return; cleanup: + target_free_tag(se_sess, &cmd->se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); } @@ -941,6 +945,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) struct se_cmd *se_cmd = &cmd->se_cmd; if (req->status == -ESHUTDOWN) { + target_free_tag(se_cmd->se_sess, se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); return; } @@ -963,6 +968,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) cleanup: /* Command was aborted */ if (cmd->state == UASP_QUEUE_COMMAND) { + target_free_tag(se_cmd->se_sess, se_cmd); transport_generic_free_cmd(se_cmd, 0); return; } From patchwork Wed Jul 6 23:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588439 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 9EE78CCA47C for ; Wed, 6 Jul 2022 23:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234712AbiGFXiI (ORCPT ); Wed, 6 Jul 2022 19:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234710AbiGFXiE (ORCPT ); Wed, 6 Jul 2022 19:38:04 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397472CCAF; Wed, 6 Jul 2022 16:38:03 -0700 (PDT) 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 1A4844077F; Wed, 6 Jul 2022 23:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150683; bh=Q6RKjzlpKY/DTJrLNk3ezhXEqIY0VjZFy7Ipg44oqLA=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=TgPcVvdyv8RE0Mjxd3NN1HzRELvzRUuixCLdeLvBE97dgEp/hiKucjdGfsWBIwSUG uTW36zWkz9lpxf2hDVfPED4Qk9jr49Kk1kkvoM/ANQvswpciJChHGBI85d80xZJHHP xyteju73wfICiLMH7r1Xe35mFu0npkV7keTddhx0/GwF4GwOAvATawPUUzz2HPLLef lYgH0gt4VsNvbQWhkcGkQAWHzuWUSfJA8N0k2Jwd4AMFWMGqChonbQFkQ+nCmXqgVL HrjjH28Ku4JOFamGjGY1n1Kwm6X2cPGwKhtu7Yr8whEyDpQOx5vPES02vRHIJ67eqC 0CRjqDTy5ueTA== 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 E68AEA0063; Wed, 6 Jul 2022 23:38:01 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:38:01 -0700 Date: Wed, 06 Jul 2022 16:38:01 -0700 Message-Id: <70aa4f59a7f9d9d0c770bf42a0723825fa564548.1657149962.git.Thinh.Nguyen@synopsys.com> In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 35/36] usb: gadget: f_tcm: Handle TASK_MANAGEMENT commands To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Handle target_core_fabric_ops TASK MANAGEMENT functions and their response. If a TASK MANAGEMENT command is received, the driver will interpret the function TMF_*, translate to TMR_*, and fire off a command work executing target_submit_tmr(). On completion, it will handle the TASK MANAGEMENT response through uasp_send_tm_response(). Signed-off-by: Thinh Nguyen --- NOTE: I appologize for this big patch. I feel that this feature needs to be viewed in its entirety to see the whole picture and easier review. drivers/usb/gadget/function/f_tcm.c | 260 +++++++++++++++++++++++++--- drivers/usb/gadget/function/tcm.h | 7 +- 2 files changed, 241 insertions(+), 26 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index fa09999adda7..a68436f97f91 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,53 @@ 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: + return RC_TMF_COMPLETE; + case TMR_FUNCTION_REJECTED: + return RC_TMF_NOT_SUPPORTED; + case TMR_LUN_DOES_NOT_EXIST: + return RC_INCORRECT_LUN; + case TMR_OVERLAPPED_TAG_ATTEMPTED: + return RC_OVERLAPPED_TAG; + case TMR_TASK_DOES_NOT_EXIST: + return RC_INVALID_INFO_UNIT; + 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 */ @@ -506,6 +554,11 @@ 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) +{ + 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 +566,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 +599,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; @@ -565,11 +618,36 @@ 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 != TMR_RESPONSE_UNKNOWN) + rsp_iu->response_code = + tcm_to_uasp_response(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 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); struct se_session *se_sess = cmd->se_cmd.se_sess; int ret; @@ -604,6 +682,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) break; case UASP_QUEUE_COMMAND: + stream->cmd = NULL; target_free_tag(se_sess, &cmd->se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); @@ -617,6 +696,7 @@ static void uasp_status_data_cmpl(struct usb_ep *ep, struct usb_request *req) return; cleanup: + stream->cmd = NULL; target_free_tag(se_sess, &cmd->se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); } @@ -624,7 +704,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); @@ -633,10 +713,22 @@ 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; - 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; @@ -682,7 +774,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; @@ -943,8 +1035,10 @@ 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); if (req->status == -ESHUTDOWN) { + stream->cmd = NULL; target_free_tag(se_cmd->se_sess, se_cmd); transport_generic_free_cmd(&cmd->se_cmd, 0); return; @@ -962,6 +1056,7 @@ static void usbg_data_write_cmpl(struct usb_ep *ep, struct usb_request *req) se_cmd->data_length); } + cmd->state = UASP_QUEUE_COMMAND; target_execute_cmd(se_cmd); return; @@ -1042,9 +1137,66 @@ 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 se_cmd *se_cmd; + struct tcm_usbg_nexus *tv_nexus; + struct uas_stream *stream; + int flags = TARGET_SCF_ACK_KREF; + + se_cmd = &cmd->se_cmd; + tv_nexus = cmd->fu->tpg->tpg_nexus; + stream = uasp_get_stream_by_tag(cmd->fu, cmd->tag); + + /* Failure detected by f_tcm */ + if (cmd->tmr_rsp != TMR_RESPONSE_UNKNOWN) { + if (cmd->tmr_rsp == TMR_OVERLAPPED_TAG_ATTEMPTED) { + /* + * 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; + } + + /* Overlap command tag detected. Abort command. */ + cmd->state = UASP_QUEUE_COMMAND; + stream->cmd->se_cmd.transport_state |= CMD_T_ABORTED; + target_get_sess_cmd(&stream->cmd->se_cmd, true); + + /* This will trigger command abort handler */ + target_execute_cmd(&stream->cmd->se_cmd); + transport_generic_free_cmd(&stream->cmd->se_cmd, 1); + } + + + target_submit_tmr_fail_response(se_cmd, cmd->tmr_rsp, + tv_nexus->tvn_se_sess, cmd->unpacked_lun, + GFP_ATOMIC, cmd->tag, flags); + return; + } + + target_submit_tmr(se_cmd, tv_nexus->tvn_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 usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); struct se_cmd *se_cmd; struct tcm_usbg_nexus *tv_nexus; struct usbg_tpg *tpg; @@ -1073,6 +1225,16 @@ 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); + + if (cmd->tmr_func || cmd->tmr_rsp != TMR_RESPONSE_UNKNOWN) + usbg_submit_tmr(cmd); + else + usbg_submit_cmd(cmd); +} + static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, struct tcm_usbg_nexus *tv_nexus, u32 scsi_tag) { @@ -1099,37 +1261,84 @@ 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 = TMR_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 = TMR_TASK_DOES_NOT_EXIST; + goto skip; + } + + /* + * For simplicity, we use mod operation to quickly find an in-progress + * matching command tag and respond with 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). + */ + stream = uasp_get_stream_by_tag(fu, scsi_tag); + if (stream->cmd) { + WARN_ONCE(stream->cmd->tag != scsi_tag, + "Command tag %d collided with Stream id %d\n", + scsi_tag, stream->cmd->tag); + + cmd->tmr_rsp = TMR_OVERLAPPED_TAG_ATTEMPTED; + 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: @@ -1150,9 +1359,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); @@ -1298,13 +1505,16 @@ 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) { 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) diff --git a/drivers/usb/gadget/function/tcm.h b/drivers/usb/gadget/function/tcm.h index 5157af1b166b..f1cd2399fd69 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 TMR_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 Wed Jul 6 23:38:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 588010 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 69DB0C43334 for ; Wed, 6 Jul 2022 23:38:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234740AbiGFXiO (ORCPT ); Wed, 6 Jul 2022 19:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234713AbiGFXiJ (ORCPT ); Wed, 6 Jul 2022 19:38:09 -0400 Received: from smtprelay-out1.synopsys.com (smtprelay-out1.synopsys.com [149.117.73.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A3282CCBD; Wed, 6 Jul 2022 16:38:09 -0700 (PDT) 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 3C41740787; Wed, 6 Jul 2022 23:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1657150689; bh=H49rpr1BNaC58aPVdMWuYpKSmmZsypu9brrKmZKOH5w=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=lyEsNpnil19gsAEbdRYuOZ9AtA0Svha2UEwXgvOs/vbfC35gkf2NcdigS1viH5BfW q9Agwl5dkXUQy8A5ofAXdUwPF6s9wn3j3dZfCwgDKdPM8c1h/OkPDyad8ZjAoRoAa/ ytzaAHM5YPnw9Vy/sKq+ZUu1TIN2EfROerB5Xy4scXqZ/csLJsKvU3QP7VnrHc3Zys eYXWu7Yh9PTEV9kkENn9FaxER6q2/xh4wce33pdsovspB1ku7rehst0HOUp6rtafvb kR7h944tIfV99zFDdgtPqGuxPt0jmYWtTNv+s+09ulsZkxSJISwtNh/nr/lAsF1Y69 Bk/yxyFFOFOOg== 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 16337A0063; Wed, 6 Jul 2022 23:38:08 +0000 (UTC) Received: by te-lab16-v2 (sSMTP sendmail emulation); Wed, 06 Jul 2022 16:38:08 -0700 Date: Wed, 06 Jul 2022 16:38:08 -0700 Message-Id: In-Reply-To: References: X-SNPS-Relay: synopsys.com From: Thinh Nguyen Subject: [PATCH 36/36] usb: gadget: f_tcm: Comply with UAS Task Management requirement To: Felipe Balbi , Greg Kroah-Hartman , Thinh Nguyen , linux-usb@vger.kernel.org, Dmitry Bogdanov , Mike Christie , "Martin K. Petersen" , Roman Bolshakov Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The UASP driver must support all the task management functions listed in Table 20 of UAS-r04. However, not all of them are implemented in the Target core. To remain compliant while indicate that the TMR did not go through, report RC_TMF_FAILED instead of RC_TMF_NOT_SUPPORTED and print a warning to the user. Signed-off-by: Thinh Nguyen --- 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 a68436f97f91..da9e6e07cfb8 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -635,6 +635,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;