From patchwork Tue Apr 4 18:24:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670726 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 4927AC761A6 for ; Tue, 4 Apr 2023 18:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236529AbjDDSat (ORCPT ); Tue, 4 Apr 2023 14:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236403AbjDDSaE (ORCPT ); Tue, 4 Apr 2023 14:30:04 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 584B559D8; Tue, 4 Apr 2023 11:27:23 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id br6so43469784lfb.11; Tue, 04 Apr 2023 11:27:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632840; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5g55SbwLmj3fuu3xVa+qGvQr2N7UpbSSnSP357n+4sc=; b=6/Ee2WJyqOy18cbxXPew0vybXqk8WvInCC6NqO92FbdipOvb+8yWZaI7XISX0U1rbA dH2dA35YCEsaER2+gF/aJrEYAtljio4LJ33+OHaqZ8W4eQSWaS7fOG/2ayJ4GqglksbQ xSdLGTL4B3vy3TAL/ppV9efPQjdL9V6gWJ/yl+KPosLg7yO+3dTIS0DQjglFkTnXM1BS QeChxN52RFNq891aFc36dNKt16HCVqqlaNMiJTgJqnhGcQ8Esj1PvXUncSKoB/LMxOXH Xdh+6W/7ms16mQzQAlYO74Z43GDEsKF81bszBfDZyOOWKqOvMdbDSUrhtgsJ79fCvJ1S KPAw== X-Gm-Message-State: AAQBX9fP3YiRXavisEgZRs/3J8ekqBZigwSzpCm4ZJQ0Nc0TjEV4zpAm goEe56Z0TqY9coMq5sjsLJAuvUWpiThtVQ== X-Google-Smtp-Source: AKy350ZLZ+W1w4X36ZIfETsEeq7Ik8CwNs5LTJ8D7CONZgIE3BdE3ZYntyOV55Gn/rAkQtxupSQc9g== X-Received: by 2002:ac2:55af:0:b0:4eb:2a0:4021 with SMTP id y15-20020ac255af000000b004eb02a04021mr987383lfg.34.1680632839841; Tue, 04 Apr 2023 11:27:19 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id g14-20020ac2538e000000b004db44dfd888sm2435841lfh.30.2023.04.04.11.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:27:19 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 8FC43B5; Tue, 4 Apr 2023 20:27:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632838; bh=sRNE170mXMWIMMdRjN580krn/bbL2IaR+aAZBckGFfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r7Lz7zQVt3j7RcwVNhoN5SVoq7kJTPP87KqxHbGFpn34ZwWFFDHIBxb//MngBqm7/ dUlZgWq2jhrwpjjuzbFADtTDPnBE7ax7A6XNcKQpsU4I3904fMeGtIWj/7ZyDcmxl6 uwEehhi/DTtL3uy9w9zIuEyrZYOtcDho6vseRD6E= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 7BEF6865; Tue, 4 Apr 2023 20:25:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632728; bh=sRNE170mXMWIMMdRjN580krn/bbL2IaR+aAZBckGFfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W29RbxkLSmxbw65I9yZvXpd4xcxrUq+VK1wVx56Hj9Kq8CtHHubNy/SqKlIsZTVH1 Ho3pKSZ+RFchPDKmROapEYTXGJqJsC8BS4zPiDQY9a7o/Dj7Cg9GQ2sAq/s4Vv9de6 zMUt4fad2S2lTvrJGDgNcu6JlNbvuGlf/TwZagtA= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Paolo Valente Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Damien Le Moal , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 01/19] ioprio: cleanup interface definition Date: Tue, 4 Apr 2023 20:24:06 +0200 Message-Id: <20230404182428.715140-2-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal The IO priority user interface defines the 16-bits ioprio values as the combination of the upper 3-bits for an IO priority class and the lower 13-bits as priority data. However, the kernel only uses the lower 3-bits of the priority data to define priority levels for the RT and BE priority classes. The data part of an ioprio value is completely ignored for the IDLE and NONE classes. This is enforced by checks done in ioprio_check_cap(), which is called for all paths that allow defining an IO priority for IOs: the per-context ioprio_set() system call, aio interface and io-uring interface. Clarify this fact in the uapi ioprio.h header file and introduce the IOPRIO_PRIO_LEVEL_MASK and IOPRIO_PRIO_LEVEL() macros for users to define and get priority levels in an ioprio value. The coarser macro IOPRIO_PRIO_DATA() is retained for backward compatibility with old applications already using it. There is no functional change introduced with this. In-kernel users of the IOPRIO_PRIO_DATA() macro which are explicitly handling IO priority data as a priority level are modified to use the new IOPRIO_PRIO_LEVEL() macro without any functional change. Since f2fs is the only user of this macro not explicitly using that value as a priority level, it is left unchanged. Signed-off-by: Damien Le Moal Signed-off-by: Niklas Cassel --- block/bfq-iosched.c | 8 ++++---- block/ioprio.c | 6 +++--- include/uapi/linux/ioprio.h | 19 ++++++++++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index d9ed3108c17a..a4d2879096a5 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -5523,16 +5523,16 @@ bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) bfqq->new_ioprio_class = task_nice_ioclass(tsk); break; case IOPRIO_CLASS_RT: - bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); + bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); bfqq->new_ioprio_class = IOPRIO_CLASS_RT; break; case IOPRIO_CLASS_BE: - bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); + bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); bfqq->new_ioprio_class = IOPRIO_CLASS_BE; break; case IOPRIO_CLASS_IDLE: bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; - bfqq->new_ioprio = 7; + bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; break; } @@ -5829,7 +5829,7 @@ static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd, struct bfq_io_cq *bic, bool respawn) { - const int ioprio = IOPRIO_PRIO_DATA(bic->ioprio); + const int ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio); struct bfq_queue **async_bfqq = NULL; struct bfq_queue *bfqq; diff --git a/block/ioprio.c b/block/ioprio.c index 32a456b45804..f0d9e818abc5 100644 --- a/block/ioprio.c +++ b/block/ioprio.c @@ -33,7 +33,7 @@ int ioprio_check_cap(int ioprio) { int class = IOPRIO_PRIO_CLASS(ioprio); - int data = IOPRIO_PRIO_DATA(ioprio); + int level = IOPRIO_PRIO_LEVEL(ioprio); switch (class) { case IOPRIO_CLASS_RT: @@ -49,13 +49,13 @@ int ioprio_check_cap(int ioprio) fallthrough; /* rt has prio field too */ case IOPRIO_CLASS_BE: - if (data >= IOPRIO_NR_LEVELS || data < 0) + if (level >= IOPRIO_NR_LEVELS) return -EINVAL; break; case IOPRIO_CLASS_IDLE: break; case IOPRIO_CLASS_NONE: - if (data) + if (level) return -EINVAL; break; default: diff --git a/include/uapi/linux/ioprio.h b/include/uapi/linux/ioprio.h index f70f2596a6bf..4444b4e4fdad 100644 --- a/include/uapi/linux/ioprio.h +++ b/include/uapi/linux/ioprio.h @@ -17,7 +17,7 @@ ((data) & IOPRIO_PRIO_MASK)) /* - * These are the io priority groups as implemented by the BFQ and mq-deadline + * These are the io priority classes as implemented by the BFQ and mq-deadline * schedulers. RT is the realtime class, it always gets premium service. For * ATA disks supporting NCQ IO priority, RT class IOs will be processed using * high priority NCQ commands. BE is the best-effort scheduling class, the @@ -32,11 +32,20 @@ enum { }; /* - * The RT and BE priority classes both support up to 8 priority levels. + * The RT and BE priority classes both support up to 8 priority levels that + * can be specified using the lower 3-bits of the priority data. */ -#define IOPRIO_NR_LEVELS 8 -#define IOPRIO_BE_NR IOPRIO_NR_LEVELS +#define IOPRIO_LEVEL_NR_BITS 3 +#define IOPRIO_NR_LEVELS (1 << IOPRIO_LEVEL_NR_BITS) +#define IOPRIO_LEVEL_MASK (IOPRIO_NR_LEVELS - 1) +#define IOPRIO_PRIO_LEVEL(ioprio) ((ioprio) & IOPRIO_LEVEL_MASK) +#define IOPRIO_BE_NR IOPRIO_NR_LEVELS + +/* + * Possible values for the "which" argument of the ioprio_get() and + * ioprio_set() system calls (see "man ioprio_set"). + */ enum { IOPRIO_WHO_PROCESS = 1, IOPRIO_WHO_PGRP, @@ -44,7 +53,7 @@ enum { }; /* - * Fallback BE priority level. + * Fallback BE class priority level. */ #define IOPRIO_NORM 4 #define IOPRIO_BE_NORM IOPRIO_NORM From patchwork Tue Apr 4 18:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670725 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 1BA89C77B6C for ; Tue, 4 Apr 2023 18:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbjDDSbc (ORCPT ); Tue, 4 Apr 2023 14:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236523AbjDDSbQ (ORCPT ); Tue, 4 Apr 2023 14:31:16 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 174107DA8; Tue, 4 Apr 2023 11:28:08 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id bi9so43473763lfb.12; Tue, 04 Apr 2023 11:28:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dr2Hww8UkSMsbtWPl+uiEpvBEwJnNqlS9FIB4hVpH0g=; b=h4k40g8vQJajU78yuzkHpUfM6d2X7fiC3yvzXT7wR0VP+Verp6bnLxw1h1u0xTTWoQ ArkSYfcTQjUBpFWBDy/CX+Ee9ikPMlkNANUKaMBP/DqLjr4GvIvVQbAkXBlyHHNvtpOX HDWRyb/g3yCttC+g8WvzTrREx6WgJgCjpW7n0e7zXPyI9Fu63pf+dwY2D9cAB3pQjqBU xUS+OxSqOpk+m0nOxK2j0gLD0jocQi5LQ99SLaAOAuyPk0KDvlJa2XW4gH3Y5N9rOJDw ni5jQZhbW9Y24H6CzQgX2+NhY6HEzCo0ggzI38R0Jhw7qVo5PvQcBIk7jWTBpkerxayi xaUg== X-Gm-Message-State: AAQBX9efizTDchny1OWGI1TvWNK286ayynQX2hi+5wGSGbzzanbgG5H5 9rHBugSVAPaO1bq1oF1gYsDZCvtCqbokVQ== X-Google-Smtp-Source: AKy350aRYtv6EJShn5WeYu6AwRQkfCJFaJW9Per6FhKhpuQwL6IS43eFhsvk+l4P7JaHkaDh5RcAIQ== X-Received: by 2002:a05:6512:38c2:b0:4dd:cb1d:b3cc with SMTP id p2-20020a05651238c200b004ddcb1db3ccmr782804lft.11.1680632886047; Tue, 04 Apr 2023 11:28:06 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id a14-20020a056512020e00b004eae7890269sm2422268lfo.138.2023.04.04.11.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:28:05 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id AA5DE2C0; Tue, 4 Apr 2023 20:28:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632883; bh=Ml7y/jf7AIB69js3iH/Wxe2UpbdPAiIMGTLWNNw4CTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bIqu4ZJL798Pl2Z3UogpuQNhSnArYFFbTh6cgleIvYG0s/m6/lAfI73UIZMQiat4b h4SQokQNld0N/x1sT+Jn9yUjMuWEHySu2d8JXjgct+XcTnA7bHObWmsnKo2O/ydhrC 1JaA70AYCBKQiifryZwdKnS+2Nj7AkoHrzRJOk6s= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id DF04C89C; Tue, 4 Apr 2023 20:25:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632733; bh=Ml7y/jf7AIB69js3iH/Wxe2UpbdPAiIMGTLWNNw4CTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tuFdalKspLSIzF6JcaH68N4L3lNX/v6hh3QPLjnJcEBifajrU4YnSAd+uURxL15Qg ypfni1XWP9wQK0GHfv/zveDFsINw0+41cmv82sY/GOsw2m4mw+zUMdIeMFxPKyUchw dRj4BzzKMJa7z3/Hedak23Qcky01VPy9YrxMuHrg= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Damien Le Moal , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 03/19] block: introduce BLK_STS_DURATION_LIMIT Date: Tue, 4 Apr 2023 20:24:08 +0200 Message-Id: <20230404182428.715140-4-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal Introduce the new block IO status BLK_STS_DURATION_LIMIT for LLDDs to report command that failed due to a command duration limit being exceeded. This new status is mapped to the ETIME error code to allow users to differentiate "soft" duration limit failures from other more serious hardware related errors. If we compare BLK_STS_DURATION_LIMIT with BLK_STS_TIMEOUT: -BLK_STS_DURATION_LIMIT means that the drive gave a reply indicating that the command duration limit was exceeded before the command could be completed. This IO status is mapped to ETIME for user space. -BLK_STS_TIMEOUT means that the drive never gave a reply at all. This IO status is mapped to ETIMEDOUT for user space. Signed-off-by: Damien Le Moal Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig --- block/blk-core.c | 3 +++ include/linux/blk_types.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 42926e6cb83c..be7facaa11a6 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -170,6 +170,9 @@ static const struct { [BLK_STS_ZONE_OPEN_RESOURCE] = { -ETOOMANYREFS, "open zones exceeded" }, [BLK_STS_ZONE_ACTIVE_RESOURCE] = { -EOVERFLOW, "active zones exceeded" }, + /* Command duration limit device-side timeout */ + [BLK_STS_DURATION_LIMIT] = { -ETIME, "duration limit exceeded" }, + /* everything else not covered above: */ [BLK_STS_IOERR] = { -EIO, "I/O" }, }; diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 99be590f952f..cde997590765 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -166,6 +166,12 @@ typedef u16 blk_short_t; */ #define BLK_STS_OFFLINE ((__force blk_status_t)17) +/* + * BLK_STS_DURATION_LIMIT is returned from the driver when the target device + * aborted the command because it exceeded one of its Command Duration Limits. + */ +#define BLK_STS_DURATION_LIMIT ((__force blk_status_t)18) + /** * blk_path_error - returns true if error may be path related * @error: status the request was completed with From patchwork Tue Apr 4 18:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670724 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 AD694C77B62 for ; Tue, 4 Apr 2023 18:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235825AbjDDScx (ORCPT ); Tue, 4 Apr 2023 14:32:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236403AbjDDSch (ORCPT ); Tue, 4 Apr 2023 14:32:37 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C07E7299; Tue, 4 Apr 2023 11:29:57 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id g19so30395002lfr.9; Tue, 04 Apr 2023 11:29:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632996; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iyOtHBCn/uWNrq/R7ZU6Qv+JF796mVDB+Rf4s24M8k8=; b=ib9mbykm3+8hKIYWnHITKJCz17TUtGdUTKk3v2uwnImQG0J82GrUq7qgQzTPkd6HrE NhUZnvOEsVdDd5WEBFutKoE1kma+7g+QUz70yaiTiO3qcT191MzskWZQp2v9FFFetYZS RAimbJ+Zcyg6HtPr620V/qQXvzId/t9IOiCP70bP8Eq4KR/dczuw3doaQGADSRLmr7Jb wlSvh8/DIk+QRn0Kx6P9fUli/q00rSqWwsFxTd8C4sT1ZV+7Lf5FcxUM+vEFvU+6+wpV 1VOv3423fRJRwEetZEFoKm6sfj6XxVmnhfwORe+C1Gv4hOBfnUfABVd/+wR9JZ+GXNaZ W+NQ== X-Gm-Message-State: AAQBX9db/+JF0xRPwwwaooBom1RyOfVkXH5WFlk6XKWSZkz19+5QNyMY kSOa8ec461BPIVyhG85bPxsI0tEnHEY2jw== X-Google-Smtp-Source: AKy350Zuu6oRwoWxK7jFyzhkUcbAGbkBFA6XrYXRGF/ep7kWeA/x99mPQ7eqCAXA4HSUMpmEEdphTg== X-Received: by 2002:ac2:495c:0:b0:4eb:f6d:64f with SMTP id o28-20020ac2495c000000b004eb0f6d064fmr875381lfi.42.1680632995622; Tue, 04 Apr 2023 11:29:55 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id q17-20020a19a411000000b004d3d43c7569sm2434994lfc.3.2023.04.04.11.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:29:55 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 58508895; Tue, 4 Apr 2023 20:29:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632993; bh=rbfvsr3tquiM93ijFijrjR0bS0TPBVeknlwL0sNNs3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3DxNnZoYVoyfOR9GBn/fKDA+kCpFRiV4COlGHiFOmiGGYiHRvsH7YO3hhH7tmRY9 UbcueSw/PFYgvmiPrJAy4lNHlfj7ZoIt/+YVeISDOfL0qIrl/AvpdzlHIWgZIvY/v7 +BIuO6uKJfXuIGGHZ5P+en4vLcnwgB8pZ8VFyStA= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 47F2CA55; Tue, 4 Apr 2023 20:25:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632737; bh=rbfvsr3tquiM93ijFijrjR0bS0TPBVeknlwL0sNNs3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JWi/ewFA6jmNPVTTeqjpc+8T/swngda6y6f4QJuGJxv7ruzgZDA0vqDUbWGIfLCVK bUicPZep8s+7Ys3YYoA66fwda9r7qzoDHHIR3H4aah70tAVh0o5lfquU1b5NEqVl63 KMJXYpIayHlUHNqO2boKhvQXS7AfxtnemS5FKxGQ= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , "James E.J. Bottomley" Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Damien Le Moal , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel , Mike Christie Subject: [PATCH v5 05/19] scsi: rename and move get_scsi_ml_byte() Date: Tue, 4 Apr 2023 20:24:10 +0200 Message-Id: <20230404182428.715140-6-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Niklas Cassel SCSI has two different getters: - get_XXX_byte() (in scsi_cmnd.h) which takes a struct scsi_cmnd *, and - XXX_byte() (in scsi.h) which takes a scmd->result. The proper name for get_scsi_ml_byte() should thus be without the get_ prefix, as it takes a scmd->result. Rename the function to rectify this. (This change was suggested by Mike Christie.) Additionally, move get_scsi_ml_byte() to scsi_priv.h since both scsi_lib.c and scsi_error.c will need to use this helper in a follow-up patch. Cc: Mike Christie Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 7 +------ drivers/scsi/scsi_priv.h | 5 +++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index b7c569a42aa4..fac9c31161d2 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -578,11 +578,6 @@ static bool scsi_end_request(struct request *req, blk_status_t error, return false; } -static inline u8 get_scsi_ml_byte(int result) -{ - return (result >> 8) & 0xff; -} - /** * scsi_result_to_blk_status - translate a SCSI result code into blk_status_t * @result: scsi error code @@ -595,7 +590,7 @@ static blk_status_t scsi_result_to_blk_status(int result) * Check the scsi-ml byte first in case we converted a host or status * byte. */ - switch (get_scsi_ml_byte(result)) { + switch (scsi_ml_byte(result)) { case SCSIML_STAT_OK: break; case SCSIML_STAT_RESV_CONFLICT: diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h index 96284a0e13fe..74324fba4281 100644 --- a/drivers/scsi/scsi_priv.h +++ b/drivers/scsi/scsi_priv.h @@ -29,6 +29,11 @@ enum scsi_ml_status { SCSIML_STAT_TGT_FAILURE = 0x04, /* Permanent target failure */ }; +static inline u8 scsi_ml_byte(int result) +{ + return (result >> 8) & 0xff; +} + /* * Scsi Error Handler Flags */ From patchwork Tue Apr 4 18:24:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670723 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 C417EC6FD1D for ; Tue, 4 Apr 2023 18:33:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236465AbjDDSdn (ORCPT ); Tue, 4 Apr 2023 14:33:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236359AbjDDSd1 (ORCPT ); Tue, 4 Apr 2023 14:33:27 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6458993D8; Tue, 4 Apr 2023 11:30:48 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id s20so14567990ljp.7; Tue, 04 Apr 2023 11:30:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633046; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hL6vKKlAcCQuDQvOTLeI2NShllETqWRBpGOfrTugoHE=; b=Rgse10eMkRADlfBRlUrm63y+tC21tfyVSoqwnuoBhTjBXTlcjVXA59PwgZ0N7rQbZY RAuckeAbktZPjqtALxBciPDZT4iVnE/0YvNdOZ0hIIKoG7nkAOJ+IFhQSE/Z3OyNskP/ 1zi9Z+9AT2eChfMU/q9DnFeMyRU/mCKN6E6Th66eHC2t27sCs9ri+BJoadjQcIyVPHkm 1uO84v4K9444L0+C1V7UlcHUyH8VwqG9liPtHjwyWLcNKvucuXy1jMLE3R55M647RI/Z WKIzgh5qD9pK2okaVNJw66qyU9sHVJqjXVnDII+NsZv+ZfVeX05Sr/DinqgdSDbIGlEp QhpQ== X-Gm-Message-State: AAQBX9efu1Z1STBTap91fxVUFB9q0ComxFXm5h3O74aIs2UlTqCoz0Pd C3nrVw9WxZJekyJyn2kItOFlm8bVZjQrGQ== X-Google-Smtp-Source: AKy350YC1AaBRN6mPy8t4jTBiAJ7fKPzeGQQwBObjPoF6ZcwO7RLO5zXYzQhc+enqtrfMlcMzCn/7w== X-Received: by 2002:a2e:95d0:0:b0:298:591b:9786 with SMTP id y16-20020a2e95d0000000b00298591b9786mr1015853ljh.52.1680633046641; Tue, 04 Apr 2023 11:30:46 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id u19-20020a2e9f13000000b0029a1ccdc560sm2460795ljk.118.2023.04.04.11.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:30:46 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 6E85A2C0; Tue, 4 Apr 2023 20:30:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633045; bh=VQc2yCNjhXN6NvsuvJhWU3KLSSjWiq7Re2qaCSxBEjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0kUyJSq4W9aDmrHRmhd4cnLQY76q/pKuyyulTRfJqlIe3QI4eEhezIwpTmCvMFjp XkeeD7IxPL7gWHWDxpSFrLLEHqGby00O9Z3P1+coQMjT5fFTsJqU/vaZWLF17Mq/6y nd3SeGHUDso7K+zSEuRqXxO0X1VGvjOyEc4oKX4k= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 2E8A0D0E; Tue, 4 Apr 2023 20:25:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632739; bh=VQc2yCNjhXN6NvsuvJhWU3KLSSjWiq7Re2qaCSxBEjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EVLZYCA9PRHBoNxkdlLZ4cZVbRhgpxtgLP8N/gqqyo+ZJT0RHDZ/q3dSKr6o0xzul HdgsrYspfgWLGxP32gSmMkub8DKZ2VQry3ET2KiL0kB9Z9bYm18Du+HCq7MSIPFNnw EN5gfs5kQq8z1q6jATF1ZVshIOTRaMq3q6ZMc/0g= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , "James E.J. Bottomley" Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Damien Le Moal , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 07/19] scsi: support service action in scsi_report_opcode() Date: Tue, 4 Apr 2023 20:24:12 +0200 Message-Id: <20230404182428.715140-8-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal The REPORT_SUPPORTED_OPERATION_CODES command allows checking for support of commands that have the same opcode but different service actions, such as READ 32 and WRITE 32. However, the current implementation of scsi_report_opcode() only allows checking an operation code without a service action differentiation. Add the "sa" argument to scsi_report_opcode() to allow passing a service action. If a non-zero service action is specified, the reporting options field value is set to 3 to have the service action field taken into account by the device. If no service action field is specified (zero), the reporting options field is set to 1 as before. Signed-off-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- drivers/scsi/scsi.c | 28 +++++++++++++++++++--------- drivers/scsi/sd.c | 10 +++++----- include/scsi/scsi_device.h | 5 +++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 09ef0b31dfc0..62d9472e08e9 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -504,18 +504,22 @@ void scsi_attach_vpd(struct scsi_device *sdev) } /** - * scsi_report_opcode - Find out if a given command opcode is supported + * scsi_report_opcode - Find out if a given command is supported * @sdev: scsi device to query * @buffer: scratch buffer (must be at least 20 bytes long) * @len: length of buffer - * @opcode: opcode for command to look up - * - * Uses the REPORT SUPPORTED OPERATION CODES to look up the given - * opcode. Returns -EINVAL if RSOC fails, 0 if the command opcode is - * unsupported and 1 if the device claims to support the command. + * @opcode: opcode for the command to look up + * @sa: service action for the command to look up + * + * Uses the REPORT SUPPORTED OPERATION CODES to check support for the + * command identified with @opcode and @sa. If the command does not + * have a service action, @sa must be 0. Returns -EINVAL if RSOC fails, + * 0 if the command is not supported and 1 if the device claims to + * support the command. */ int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, - unsigned int len, unsigned char opcode) + unsigned int len, unsigned char opcode, + unsigned short sa) { unsigned char cmd[16]; struct scsi_sense_hdr sshdr; @@ -539,8 +543,14 @@ int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, memset(cmd, 0, 16); cmd[0] = MAINTENANCE_IN; cmd[1] = MI_REPORT_SUPPORTED_OPERATION_CODES; - cmd[2] = 1; /* One command format */ - cmd[3] = opcode; + if (!sa) { + cmd[2] = 1; /* One command format */ + cmd[3] = opcode; + } else { + cmd[2] = 3; /* One command format with service action */ + cmd[3] = opcode; + put_unaligned_be16(sa, &cmd[4]); + } put_unaligned_be32(request_len, &cmd[6]); memset(buffer, 0, len); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 2de4b27cedc5..2dc4223a4c97 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3057,7 +3057,7 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) return; } - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY) < 0) { + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, INQUIRY, 0) < 0) { struct scsi_vpd *vpd; sdev->no_report_opcodes = 1; @@ -3073,10 +3073,10 @@ static void sd_read_write_same(struct scsi_disk *sdkp, unsigned char *buffer) rcu_read_unlock(); } - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16) == 1) + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME_16, 0) == 1) sdkp->ws16 = 1; - if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME) == 1) + if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, WRITE_SAME, 0) == 1) sdkp->ws10 = 1; } @@ -3088,9 +3088,9 @@ static void sd_read_security(struct scsi_disk *sdkp, unsigned char *buffer) return; if (scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, - SECURITY_PROTOCOL_IN) == 1 && + SECURITY_PROTOCOL_IN, 0) == 1 && scsi_report_opcode(sdev, buffer, SD_BUF_SIZE, - SECURITY_PROTOCOL_OUT) == 1) + SECURITY_PROTOCOL_OUT, 0) == 1) sdkp->security = 1; } diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index c146cc807d44..c93c5aaf637e 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -433,8 +433,9 @@ extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout, int retries, struct scsi_sense_hdr *sshdr); extern int scsi_get_vpd_page(struct scsi_device *, u8 page, unsigned char *buf, int buf_len); -extern int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, - unsigned int len, unsigned char opcode); +int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer, + unsigned int len, unsigned char opcode, + unsigned short sa); extern int scsi_device_set_state(struct scsi_device *sdev, enum scsi_device_state state); extern struct scsi_event *sdev_evt_alloc(enum scsi_device_event evt_type, From patchwork Tue Apr 4 18:24:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670722 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 94797C77B60 for ; Tue, 4 Apr 2023 18:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236478AbjDDSe2 (ORCPT ); Tue, 4 Apr 2023 14:34:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236385AbjDDSeK (ORCPT ); Tue, 4 Apr 2023 14:34:10 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB8AE7AA9; Tue, 4 Apr 2023 11:31:34 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id x20so34857245ljq.9; Tue, 04 Apr 2023 11:31:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633093; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=laWPLn081d5VPfahsGu6BqueKGfg+QZwf4pkTPBTIXI=; b=b9MaLgV6AyJfPsK5xa0R4BBVGAKzr06vKVBDaSkqcN3J/xpw6EXZ97/v45b1eIf8Mb QuWgK20wTuKR7Vr4DB+X2xiom+pC9diMX9V/n3F7F8IL4FY5J8QrFTtXpwvqLe6IJftP u62H4C301D2UuyQQ2acCvP7/sb/IIHThLKKWG2U4TXkbCSykozZntG4zBPZ59p2O0DZM 0upU2ksoyCi+63WJEVswIeYzmMjCtm/R5PtOJTzyKVmqnN/aU3f5g3DopzRrFN2+t5Wo csje+wZkNRoIjtNMh3wx2G/xzp1rqSSJ/RgDcPnLLz0YMA/CGMhaqFnBfk2B5oxkH2bE YStQ== X-Gm-Message-State: AAQBX9fbDWB70hNzuMKlWUz/HVhBZoxTl2+KRavY8t2hAXpdG9r3By5l xYI4PtkwQ/e9jW7NBM5MuZSz98nSC5AljQ== X-Google-Smtp-Source: AKy350bCt3GHsbw6tf/YJsYkKdBhs+94kJ7B0Fc39Tc6DnzqwA335w4Na4SdHZVcxJ3mEGcafV517w== X-Received: by 2002:a2e:7315:0:b0:2a3:6b99:4030 with SMTP id o21-20020a2e7315000000b002a36b994030mr1296530ljc.36.1680633092913; Tue, 04 Apr 2023 11:31:32 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id h13-20020a2e900d000000b00295733a3390sm2418960ljg.101.2023.04.04.11.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:31:32 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 699A6B5; Tue, 4 Apr 2023 20:31:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633091; bh=fJkyCUCmYaJG48RjauqpSErCyOrMsg8LLyg8ClLNQ3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UUOyAiwwS+oue4ytlqRTO3vOk1NbB0+OWmACx4x+JaSZabvb01sYzcdRpeUIK1gzU fME106RfHYcMk6dLesMMpXSFWMmskhA98Z0seEvukgXsj8lYCE272rGTNQZtWkA9aY coQRRo4o7DIewfF62I8I/AFlgROm226VHXJROFr8= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id EFBD7EC7; Tue, 4 Apr 2023 20:25:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632741; bh=fJkyCUCmYaJG48RjauqpSErCyOrMsg8LLyg8ClLNQ3k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dnx7ExpMIpN3Ug+1+fVqkbd/M5jGefMZrhFp3/zdL3ws3sIFxRt54/ptXQVocRxUz ttDY0/3iaz94JJk9BdYbXi5KaiXvKOB0XWh4OkhOoRGwKyGstZsm/6yJ6VZ8vmGJO3 Eww4iHKcoHo2n4hnAaurPBslGA4OCJbhKR6eURqU= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , "James E.J. Bottomley" Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Damien Le Moal , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 09/19] scsi: allow enabling and disabling command duration limits Date: Tue, 4 Apr 2023 20:24:14 +0200 Message-Id: <20230404182428.715140-10-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal Add the sysfs scsi device attribute cdl_enable to allow a user to turn enable or disable a device command duration limits feature. CDL is disabled by default. This feature must be explicitly enabled by a user by setting the cdl_enable attribute to 1. The new function scsi_cdl_enable() does not do anything beside setting the cdl_enable field of struct scsi_device in the case of a (real) scsi device (e.g. a SAS HDD). For ATA devices, the command duration limits feature needs to be enabled/disabled using the ATA feature sub-page of the control mode page. To do so, the scsi_cdl_enable() function checks if this mode page is supported using scsi_mode_sense(). If it is, scsi_mode_select() is used to enable and disable CDL. Signed-off-by: Damien Le Moal Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel --- Documentation/ABI/testing/sysfs-block-device | 13 ++++ drivers/scsi/scsi.c | 62 ++++++++++++++++++++ drivers/scsi/scsi_sysfs.c | 31 ++++++++++ include/scsi/scsi_device.h | 2 + 4 files changed, 108 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-block-device b/Documentation/ABI/testing/sysfs-block-device index ee3610a25845..626d48ac504b 100644 --- a/Documentation/ABI/testing/sysfs-block-device +++ b/Documentation/ABI/testing/sysfs-block-device @@ -104,3 +104,16 @@ Contact: linux-scsi@vger.kernel.org Description: (RO) Indicates if the device supports the command duration limits feature found in some ATA and SCSI devices. + + +What: /sys/block/*/device/cdl_enable +Date: Mar, 2023 +KernelVersion: v6.4 +Contact: linux-scsi@vger.kernel.org +Description: + (RW) For a device supporting the command duration limits + feature, write to the file to turn on or off the feature. + By default this feature is turned off. + Writing "1" to this file enables the use of command duration + limits for read and write commands in the kernel and turns on + the feature on the device. Writing "0" disables the feature. diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index c03814ce23ca..c4bf99a842f3 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -651,6 +651,68 @@ void scsi_cdl_check(struct scsi_device *sdev) kfree(buf); } +/** + * scsi_cdl_enable - Enable or disable a SCSI device supports for Command + * Duration Limits + * @sdev: The target device + * @enable: the target state + */ +int scsi_cdl_enable(struct scsi_device *sdev, bool enable) +{ + struct scsi_mode_data data; + struct scsi_sense_hdr sshdr; + struct scsi_vpd *vpd; + bool is_ata = false; + char buf[64]; + int ret; + + if (!sdev->cdl_supported) + return -EOPNOTSUPP; + + rcu_read_lock(); + vpd = rcu_dereference(sdev->vpd_pg89); + if (vpd) + is_ata = true; + rcu_read_unlock(); + + /* + * For ATA devices, CDL needs to be enabled with a SET FEATURES command. + */ + if (is_ata) { + char *buf_data; + int len; + + ret = scsi_mode_sense(sdev, 0x08, 0x0a, 0xf2, buf, sizeof(buf), + 5 * HZ, 3, &data, NULL); + if (ret) + return -EINVAL; + + /* Enable CDL using the ATA feature page */ + len = min_t(size_t, sizeof(buf), + data.length - data.header_length - + data.block_descriptor_length); + buf_data = buf + data.header_length + + data.block_descriptor_length; + if (enable) + buf_data[4] = 0x02; + else + buf_data[4] = 0; + + ret = scsi_mode_select(sdev, 1, 0, buf_data, len, 5 * HZ, 3, + &data, &sshdr); + if (ret) { + if (scsi_sense_valid(&sshdr)) + scsi_print_sense_hdr(sdev, + dev_name(&sdev->sdev_gendev), &sshdr); + return ret; + } + } + + sdev->cdl_enable = enable; + + return 0; +} + /** * scsi_device_get - get an additional reference to a scsi_device * @sdev: device to get a reference to diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 4994148e685b..9a54b2c0fee7 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -1222,6 +1222,36 @@ static DEVICE_ATTR(queue_ramp_up_period, S_IRUGO | S_IWUSR, sdev_show_queue_ramp_up_period, sdev_store_queue_ramp_up_period); +static ssize_t sdev_show_cdl_enable(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + + return sysfs_emit(buf, "%d\n", (int)sdev->cdl_enable); +} + +static ssize_t sdev_store_cdl_enable(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + int ret; + bool v; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (kstrtobool(buf, &v)) + return -EINVAL; + + ret = scsi_cdl_enable(to_scsi_device(dev), v); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR(cdl_enable, S_IRUGO | S_IWUSR, + sdev_show_cdl_enable, sdev_store_cdl_enable); + static umode_t scsi_sdev_attr_is_visible(struct kobject *kobj, struct attribute *attr, int i) { @@ -1302,6 +1332,7 @@ static struct attribute *scsi_sdev_attrs[] = { #endif &dev_attr_queue_ramp_up_period.attr, &dev_attr_cdl_supported.attr, + &dev_attr_cdl_enable.attr, REF_EVT(media_change), REF_EVT(inquiry_change_reported), REF_EVT(capacity_change_reported), diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 6b8df9e253a0..b2cdb078b7bd 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -219,6 +219,7 @@ struct scsi_device { unsigned no_vpd_size:1; /* No VPD size reported in header */ unsigned cdl_supported:1; /* Command duration limits supported */ + unsigned cdl_enable:1; /* Enable/disable Command duration limits */ unsigned int queue_stopped; /* request queue is quiesced */ bool offline_already; /* Device offline message logged */ @@ -367,6 +368,7 @@ extern void scsi_remove_device(struct scsi_device *); extern int scsi_unregister_device_handler(struct scsi_device_handler *scsi_dh); void scsi_attach_vpd(struct scsi_device *sdev); void scsi_cdl_check(struct scsi_device *sdev); +int scsi_cdl_enable(struct scsi_device *sdev, bool enable); extern struct scsi_device *scsi_device_from_queue(struct request_queue *q); extern int __must_check scsi_device_get(struct scsi_device *); From patchwork Tue Apr 4 18:24:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670721 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 371F2C77B6C for ; Tue, 4 Apr 2023 18:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235778AbjDDSfF (ORCPT ); Tue, 4 Apr 2023 14:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236487AbjDDSeq (ORCPT ); Tue, 4 Apr 2023 14:34:46 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3FF55FF7; Tue, 4 Apr 2023 11:32:32 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id h25so43518956lfv.6; Tue, 04 Apr 2023 11:32:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633151; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w7uewdVPDtWlBmd0txwJX02g5PYGjBmA/8tf1xq7PQc=; b=qdn+l6SMWdKq3D8JEKfGnZy46u3/ov6F91Qg5pTKyCdjW1OpQXVfJe8RqJO+dYbii+ 5yx9CTNbo7DbS0Z5J+0dG3bbwCWcdNilO4anr9GsgW6UKGbo0lcL2eHoe9jY7E9ZTYpT cJXD2T+YwQj7IIuqepFJJBInaQT6LHIKK/dKsINqH7m8YK8h5NHMmnzy0cU1NikKvs4C GHQGi/D3F+hhJAbuzUmu76OV9jntlpoxkJRdlD05H1UgCh9KmgTCPICtFBoQuP2LWLDK Vt3jWUJjH/E4xkx3pf1velZtycvQQ8fJk3XRMOuVnTjuOAOqfWOxK1r3er6R+I8v9e3z isUA== X-Gm-Message-State: AAQBX9d9NSuKqEf08sEWH9pJ2Zgfe5MVzStpfVl1pUsFIyNZLRZCnzCt SggZkE5pz+2+PhqDsDzdnT87XAbnPgZKSg== X-Google-Smtp-Source: AKy350a/q6j+7ThkLuTFZuBTOSVG5cY4mVJyjQ0w0cl+0NfiEIAn3w/peHFABBmFLbyApZAMl3zwVg== X-Received: by 2002:a05:6512:244:b0:4db:3928:d66d with SMTP id b4-20020a056512024400b004db3928d66dmr789969lfo.42.1680633151138; Tue, 04 Apr 2023 11:32:31 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id q28-20020ac25a1c000000b004db1a7e6decsm2436206lfn.205.2023.04.04.11.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:32:30 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 1DEE82C0; Tue, 4 Apr 2023 20:32:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633150; bh=OuulYDiO5r4YnHxGZH5etX0gMKwwO40hqAMiklCCvpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tn3TB8ZBVAHi+2X3GT643OVNgPiVhOKq4HcoyaVY3I5tQUZrfK/7Gdm+XCwu32lTD 0kFYJ8bS7a4d6OllMMjxtgOe+zKX9a8Z3ozly2dskCJpPKGZcecvq0V54W9VrwsYtE BOvLPiBgtUcwao7dtGvPimX8tAYr4bKyiOjKX7a8= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id B4A191112; Tue, 4 Apr 2023 20:25:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632751; bh=OuulYDiO5r4YnHxGZH5etX0gMKwwO40hqAMiklCCvpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rja1UesVO/e3UwGidur3122sukAkFvkvYeY0RqiAzvV2HLQRA81UlURq80douhzUa QdUy5a+uLtHrvLBHULRTFqvzJwRSyd8lIF7rJAlBxRleJ+oNf1vYaj/URw8Fxes3DD eJP1LVJQGJBECn/O2gvOhXVhSHEPonuHlxGqAmPg= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Damien Le Moal Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 12/19] ata: libata-scsi: remove unnecessary !cmd checks Date: Tue, 4 Apr 2023 20:24:17 +0200 Message-Id: <20230404182428.715140-13-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Niklas Cassel There is no need to check if !cmd as this can only happen for ATA internal commands which uses the ATA internal tag (32). Most users of ata_scsi_set_sense() are from _xlat functions that translate a scsicmd to an ATA command. These obviously have a qc->scsicmd. ata_scsi_qc_complete() can also call ata_scsi_set_sense() via ata_gen_passthru_sense() / ata_gen_ata_sense(), called via ata_scsi_qc_complete(). This callback is only called for translated commands, so it also has a qc->scsicmd. ata_eh_analyze_ncq_error(): the NCQ error log can only contain a 0-31 value, so it will never be able to get the ATA internal tag (32). ata_eh_request_sense(): only called by ata_eh_analyze_tf(), which is only called when iteratating the QCs using ata_qc_for_each_raw(), which does not include the internal tag. Since there is no existing call site where cmd can be NULL, remove the !cmd check from ata_scsi_set_sense() and ata_scsi_set_sense_information(). Suggested-by: Christoph Hellwig Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index e093c7a7deeb..26746609bf76 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -209,9 +209,6 @@ void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, { bool d_sense = (dev->flags & ATA_DFLAG_D_SENSE); - if (!cmd) - return; - scsi_build_sense(cmd, d_sense, sk, asc, ascq); } @@ -221,9 +218,6 @@ void ata_scsi_set_sense_information(struct ata_device *dev, { u64 information; - if (!cmd) - return; - information = ata_tf_read_block(tf, dev); if (information == U64_MAX) return; From patchwork Tue Apr 4 18:24:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670720 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 73E40C77B62 for ; Tue, 4 Apr 2023 18:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236424AbjDDSgB (ORCPT ); Tue, 4 Apr 2023 14:36:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236402AbjDDSfl (ORCPT ); Tue, 4 Apr 2023 14:35:41 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1D36582; Tue, 4 Apr 2023 11:33:14 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id br6so43490147lfb.11; Tue, 04 Apr 2023 11:33:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633193; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=s8H2qIMz3Gty35NiNYKZYVBmBlGMd1so+hGxNCASCEY=; b=IjxsZrGaUE0aYYVN3MWZaPwiFL+gtqk72QzhuVC+m02cpmK/W2kv6ESPaLF1eQaN7L +BvDkVZxCOAv4SZ6YfwtwRs0len2kJ7c2YaRyG+0ISTSnUVZCkXGNwvyLkjX4v+9BJCc 6rxVLIME6lCH+bv4ZFPyKnmzmUXf1HInecLxadnBSHJjWKvRbOGisddJoDbmJhaHG24L bEIevyiEj/80hKQYZrS9Ehe8P6bS2bm3CPPiDV1azgQEQonptiusrFC5caVr6OMOujH1 zB5Uw8OSctJTqHoTxFMVpfCmbdC8dcbtmjwAft6tOjU1++yJFkPipzUa4DDpkUAC9art XSig== X-Gm-Message-State: AAQBX9cn/jSrkdXrcpJyJTeGFMoWNl4WrsZt/LzvN2QkDtGhTy36bM0R 9CEGP1jvg8H6bNClfKOtqNBdbem21brCGQ== X-Google-Smtp-Source: AKy350ZFt7lV1WRE8AnWhFZdWE3oAIje0MW5aj6+5d6FnhFD51oPReJH3kug7iGhTmXDx54sVjkkIA== X-Received: by 2002:a05:6512:147:b0:4eb:18d:91df with SMTP id m7-20020a056512014700b004eb018d91dfmr739642lfo.27.1680633193019; Tue, 04 Apr 2023 11:33:13 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id l25-20020a19c219000000b004eb258f73a9sm2426229lfc.163.2023.04.04.11.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:33:12 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id EEE2E2C0; Tue, 4 Apr 2023 20:33:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633192; bh=EW5tWLpRWwKlaovMDrPHJz7vr86vu6Zk+592YnNpO6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUVxpf2UJZgXs0fQ2Rq7X3Ef77i/cUcFvsfNRoldU1Zvo7yl6AbsEKk0doh4e+w8K ZxroN+RBWWiWxZjx8JQRArWwbflkLWgYnfON+dNUwV57pqCOazDZ9avyu2L6YQBrUj DQ14dEY6nrcOZ1Zt/Ojy677fyjjp+w/1bERGeR/8= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id A19121110; Tue, 4 Apr 2023 20:25:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632751; bh=EW5tWLpRWwKlaovMDrPHJz7vr86vu6Zk+592YnNpO6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlQrLNLQVCD3GCKSKahHKH3U8uY5W3cSRBs2mrlY3+kdwvWmx9Gt1qlIibv5V6AO8 ub7Xc46v4PiQGYZ9NoiPlyH2XbYCGdY9rezoJPSovDO1LcXAdt/5LgBp1plDhFVALF QWV88IoPAOLjmZMzFB2KCv3vWiOKmMFW7QR6U+mI= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Damien Le Moal Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 13/19] ata: libata: change ata_eh_request_sense() to not set CHECK_CONDITION Date: Tue, 4 Apr 2023 20:24:18 +0200 Message-Id: <20230404182428.715140-14-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Niklas Cassel Currently, ata_eh_request_sense() unconditionally sets the scsicmd->result to SAM_STAT_CHECK_CONDITION. For Command Duration Limits policy 0xD: The device shall complete the command without error (SAM_STAT_GOOD) with the additional sense code set to DATA CURRENTLY UNAVAILABLE. It is perfectly fine to have sense data for a command that returned completion without error. In order to support for CDL policy 0xD, we have to remove this assumption that having sense data means that the command failed (SAM_STAT_CHECK_CONDITION). Change ata_eh_request_sense() to not set SAM_STAT_CHECK_CONDITION, and instead move the setting of SAM_STAT_CHECK_CONDITION to the single caller that wants SAM_STAT_CHECK_CONDITION set, that way ata_eh_request_sense() can be reused in a follow-up patch that adds support for CDL policy 0xD. The only caller of ata_eh_request_sense() is protected by: if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)), so we can remove this duplicated check from ata_eh_request_sense() itself. Additionally, ata_eh_request_sense() is only called from ata_eh_analyze_tf(), which is only called when iteratating the QCs using ata_qc_for_each_raw(), which does not include the internal tag, so cmd can never be NULL (all non-internal commands have qc->scsicmd set), so remove the !cmd check as well. Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-eh.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index a6c901811802..598ae07195b6 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1401,8 +1401,11 @@ unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key) * * LOCKING: * Kernel thread context (may sleep). + * + * RETURNS: + * true if sense data could be fetched, false otherwise. */ -static void ata_eh_request_sense(struct ata_queued_cmd *qc) +static bool ata_eh_request_sense(struct ata_queued_cmd *qc) { struct scsi_cmnd *cmd = qc->scsicmd; struct ata_device *dev = qc->dev; @@ -1411,15 +1414,12 @@ static void ata_eh_request_sense(struct ata_queued_cmd *qc) if (ata_port_is_frozen(qc->ap)) { ata_dev_warn(dev, "sense data available but port frozen\n"); - return; + return false; } - if (!cmd || qc->flags & ATA_QCFLAG_SENSE_VALID) - return; - if (!ata_id_sense_reporting_enabled(dev->id)) { ata_dev_warn(qc->dev, "sense data reporting disabled\n"); - return; + return false; } ata_tf_init(dev, &tf); @@ -1432,13 +1432,19 @@ static void ata_eh_request_sense(struct ata_queued_cmd *qc) /* Ignore err_mask; ATA_ERR might be set */ if (tf.status & ATA_SENSE) { if (ata_scsi_sense_is_valid(tf.lbah, tf.lbam, tf.lbal)) { - ata_scsi_set_sense(dev, cmd, tf.lbah, tf.lbam, tf.lbal); + /* Set sense without also setting scsicmd->result */ + scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE, + cmd->sense_buffer, tf.lbah, + tf.lbam, tf.lbal); qc->flags |= ATA_QCFLAG_SENSE_VALID; + return true; } } else { ata_dev_warn(dev, "request sense failed stat %02x emask %x\n", tf.status, err_mask); } + + return false; } /** @@ -1588,8 +1594,9 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc) * was not included in the NCQ command error log * (i.e. NCQ autosense is not supported by the device). */ - if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && (stat & ATA_SENSE)) - ata_eh_request_sense(qc); + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID) && + (stat & ATA_SENSE) && ata_eh_request_sense(qc)) + set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION); if (err & ATA_ICRC) qc->err_mask |= AC_ERR_ATA_BUS; if (err & (ATA_UNC | ATA_AMNF)) From patchwork Tue Apr 4 18:24:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670719 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 DFF00C6FD1D for ; Tue, 4 Apr 2023 18:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236308AbjDDShg (ORCPT ); Tue, 4 Apr 2023 14:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233070AbjDDSfo (ORCPT ); Tue, 4 Apr 2023 14:35:44 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18FFC5BAB; Tue, 4 Apr 2023 11:33:23 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id g19so30406524lfr.9; Tue, 04 Apr 2023 11:33:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633201; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Sez0JqSEJDZoQCI4cYFTIkIcFqtr16cDfE+vpO4F2qE=; b=JbQxlfUSd8nsM9jpuQvq4jFTy/2F8bvj1Rd23hqmL6jbI9AVPrduyz3kkhvHiHPf93 P+RKA+vI7G3CYWxWjb48unIDfxlrgdPBew6YlT069vyAUs1iZPcEZ6kisZvhh5ptSv8L S6ANN37BhxXydoIRAR+kCg1j/aFPr4Dhj6pAQzPsIJlfEOYruS1Gz6k0uUZSQbB0HLcW nb+Ny2ZzfOY+ghofWBW/A1cMGtLyFHg7HAMzAxPtYIqOkzrppFWuqChyC4G5cE5KHQH1 yZhomnYSk807e1azodnnAg95HpUhS/bVeC4vGyKZE0B2SLnaRIXb0ztihUexiXENWCoO OitA== X-Gm-Message-State: AAQBX9dvJWTLNEsM69kRUMEp+sKtDBPMChmLPhYwiK0cDtPdYd0EcnUk VmXOKCe+7nkk0gOCRlWdHzx8+AKGAAw05g== X-Google-Smtp-Source: AKy350YOerJ4ucoQ4B+y1WZEHiff7uMIscPHe8lQ4sz28tu3Iv+ajC7LeBqy19zEk50OurAYaJub9A== X-Received: by 2002:ac2:5214:0:b0:4ea:2bc6:e3c5 with SMTP id a20-20020ac25214000000b004ea2bc6e3c5mr693041lfl.64.1680633201213; Tue, 04 Apr 2023 11:33:21 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id q27-20020ac2515b000000b004eb07f5cde6sm2428490lfd.297.2023.04.04.11.33.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:33:21 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 25377865; Tue, 4 Apr 2023 20:33:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633200; bh=oHNYZ7iMW9cAnHwRR28IKXGzailtc9klvKBLS2ZCCbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlFG2UYbUKu9B/613ZAmIYNoU7eOhdyh8ldLW91Neo9FGN9rFUf/w1c0OzY1oXkqZ tnZ6azfthzU5bLoFE3AysjRe1zdndIf8KTaJMWdcIsmPgsdNk+4w/MKZIdRpyUoiP+ 8JCpgSDOJGexUeIaNH6HT/51kyz1Qt5ZzPbbiTG0= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id A16DA1111; Tue, 4 Apr 2023 20:25:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632752; bh=oHNYZ7iMW9cAnHwRR28IKXGzailtc9klvKBLS2ZCCbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YlhEM1Ac4XmcyqH4lNRXeqVBZYDSnaQIX924IzDUKAbjh5Z/xtcP6zKdSf8mawN4P ZmhI+T+j7/8fncs3KXgBReruXFxYRO4f2hvxZz1d/BfKuoNcsxScTfOGvsL0yYMnHY cydN/978k715lHk2hWBJg8tzvnJk5aL0znJDJKJ0= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Damien Le Moal Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 14/19] ata: libata: detect support for command duration limits Date: Tue, 4 Apr 2023 20:24:19 +0200 Message-Id: <20230404182428.715140-15-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal Use the supported capabilities identify device data log page to detect if a device supports the command duration limits feature. For devices supporting this feature, set the device flag ATA_DFLAG_CDL. To support scsi-ata translation, retrieve the command duration limits log page 18h and cache this page content using the cdl array added to the ata_device data structure. Signed-off-by: Damien Le Moal Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 52 ++++++++++++++++++++++++++++++++++++++- drivers/ata/libata-scsi.c | 17 ++++++------- include/linux/ata.h | 5 +++- include/linux/libata.h | 29 +++++++++++++--------- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 14c17c3bda4e..78e53f4fa741 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2367,6 +2367,54 @@ static void ata_dev_config_trusted(struct ata_device *dev) dev->flags |= ATA_DFLAG_TRUSTED; } +static void ata_dev_config_cdl(struct ata_device *dev) +{ + struct ata_port *ap = dev->link->ap; + unsigned int err_mask; + u64 val; + + if (ata_id_major_version(dev->id) < 12) + goto not_supported; + + if (!ata_log_supported(dev, ATA_LOG_IDENTIFY_DEVICE) || + !ata_identify_page_supported(dev, ATA_LOG_SUPPORTED_CAPABILITIES)) + goto not_supported; + + err_mask = ata_read_log_page(dev, ATA_LOG_IDENTIFY_DEVICE, + ATA_LOG_SUPPORTED_CAPABILITIES, + ap->sector_buf, 1); + if (err_mask) + goto not_supported; + + /* Check Command Duration Limit Supported bits */ + val = get_unaligned_le64(&ap->sector_buf[168]); + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(0))) + goto not_supported; + + /* Warn the user if command duration guideline is not supported */ + if (!(val & BIT_ULL(1))) + ata_dev_warn(dev, + "Command duration guideline is not supported\n"); + + /* + * Command duration limits is supported: cache the CDL log page 18h + * (command duration descriptors). + */ + err_mask = ata_read_log_page(dev, ATA_LOG_CDL, 0, ap->sector_buf, 1); + if (err_mask) { + ata_dev_warn(dev, "Read Command Duration Limits log failed\n"); + goto not_supported; + } + + memcpy(dev->cdl, ap->sector_buf, ATA_LOG_CDL_SIZE); + dev->flags |= ATA_DFLAG_CDL; + + return; + +not_supported: + dev->flags &= ~ATA_DFLAG_CDL; +} + static int ata_dev_config_lba(struct ata_device *dev) { const u16 *id = dev->id; @@ -2534,13 +2582,14 @@ static void ata_dev_print_features(struct ata_device *dev) return; ata_dev_info(dev, - "Features:%s%s%s%s%s%s%s\n", + "Features:%s%s%s%s%s%s%s%s\n", dev->flags & ATA_DFLAG_FUA ? " FUA" : "", dev->flags & ATA_DFLAG_TRUSTED ? " Trust" : "", dev->flags & ATA_DFLAG_DA ? " Dev-Attention" : "", dev->flags & ATA_DFLAG_DEVSLP ? " Dev-Sleep" : "", dev->flags & ATA_DFLAG_NCQ_SEND_RECV ? " NCQ-sndrcv" : "", dev->flags & ATA_DFLAG_NCQ_PRIO ? " NCQ-prio" : "", + dev->flags & ATA_DFLAG_CDL ? " CDL" : "", dev->cpr_log ? " CPR" : ""); } @@ -2702,6 +2751,7 @@ int ata_dev_configure(struct ata_device *dev) ata_dev_config_zac(dev); ata_dev_config_trusted(dev); ata_dev_config_cpr(dev); + ata_dev_config_cdl(dev); dev->cdb_len = 32; if (print_info) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 26746609bf76..716c33af999c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -47,15 +47,14 @@ typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc); static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); -#define RW_RECOVERY_MPAGE 0x1 -#define RW_RECOVERY_MPAGE_LEN 12 -#define CACHE_MPAGE 0x8 -#define CACHE_MPAGE_LEN 20 -#define CONTROL_MPAGE 0xa -#define CONTROL_MPAGE_LEN 12 -#define ALL_MPAGES 0x3f -#define ALL_SUB_MPAGES 0xff - +#define RW_RECOVERY_MPAGE 0x1 +#define RW_RECOVERY_MPAGE_LEN 12 +#define CACHE_MPAGE 0x8 +#define CACHE_MPAGE_LEN 20 +#define CONTROL_MPAGE 0xa +#define CONTROL_MPAGE_LEN 12 +#define ALL_MPAGES 0x3f +#define ALL_SUB_MPAGES 0xff static const u8 def_rw_recovery_mpage[RW_RECOVERY_MPAGE_LEN] = { RW_RECOVERY_MPAGE, diff --git a/include/linux/ata.h b/include/linux/ata.h index 0c18499f60b6..b01e2cebe1fe 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -323,15 +323,18 @@ enum { ATA_LOG_SATA_NCQ = 0x10, ATA_LOG_NCQ_NON_DATA = 0x12, ATA_LOG_NCQ_SEND_RECV = 0x13, + ATA_LOG_CDL = 0x18, + ATA_LOG_CDL_SIZE = ATA_SECT_SIZE, ATA_LOG_IDENTIFY_DEVICE = 0x30, ATA_LOG_CONCURRENT_POSITIONING_RANGES = 0x47, /* Identify device log pages: */ + ATA_LOG_SUPPORTED_CAPABILITIES = 0x03, ATA_LOG_SECURITY = 0x06, ATA_LOG_SATA_SETTINGS = 0x08, ATA_LOG_ZONED_INFORMATION = 0x09, - /* Identify device SATA settings log:*/ + /* Identify device SATA settings log: */ ATA_LOG_DEVSLP_OFFSET = 0x30, ATA_LOG_DEVSLP_SIZE = 0x08, ATA_LOG_DEVSLP_MDAT = 0x00, diff --git a/include/linux/libata.h b/include/linux/libata.h index a759dfbdcc91..2b17d6c99a37 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -94,17 +94,18 @@ enum { ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */ ATA_DFLAG_NCQ_SEND_RECV = (1 << 11), /* device supports NCQ SEND and RECV */ ATA_DFLAG_NCQ_PRIO = (1 << 12), /* device supports NCQ priority */ - ATA_DFLAG_CFG_MASK = (1 << 13) - 1, - - ATA_DFLAG_PIO = (1 << 13), /* device limited to PIO mode */ - ATA_DFLAG_NCQ_OFF = (1 << 14), /* device limited to non-NCQ mode */ - ATA_DFLAG_SLEEPING = (1 << 15), /* device is sleeping */ - ATA_DFLAG_DUBIOUS_XFER = (1 << 16), /* data transfer not verified */ - ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */ - ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */ - ATA_DFLAG_INIT_MASK = (1 << 19) - 1, - - ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 19), /* Priority cmds sent to dev */ + ATA_DFLAG_CDL = (1 << 13), /* supports cmd duration limits */ + ATA_DFLAG_CFG_MASK = (1 << 14) - 1, + + ATA_DFLAG_PIO = (1 << 14), /* device limited to PIO mode */ + ATA_DFLAG_NCQ_OFF = (1 << 15), /* device limited to non-NCQ mode */ + ATA_DFLAG_SLEEPING = (1 << 16), /* device is sleeping */ + ATA_DFLAG_DUBIOUS_XFER = (1 << 17), /* data transfer not verified */ + ATA_DFLAG_NO_UNLOAD = (1 << 18), /* device doesn't support unload */ + ATA_DFLAG_UNLOCK_HPA = (1 << 19), /* unlock HPA */ + ATA_DFLAG_INIT_MASK = (1 << 20) - 1, + + ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 20), /* Priority cmds sent to dev */ ATA_DFLAG_DETACH = (1 << 24), ATA_DFLAG_DETACHED = (1 << 25), ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */ @@ -115,7 +116,8 @@ enum { ATA_DFLAG_FEATURES_MASK = (ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \ ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \ - ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA), + ATA_DFLAG_NCQ_PRIO | ATA_DFLAG_FUA | \ + ATA_DFLAG_CDL), ATA_DEV_UNKNOWN = 0, /* unknown device */ ATA_DEV_ATA = 1, /* ATA device */ @@ -709,6 +711,9 @@ struct ata_device { /* Concurrent positioning ranges */ struct ata_cpr_log *cpr_log; + /* Command Duration Limits log support */ + u8 cdl[ATA_LOG_CDL_SIZE]; + /* error history */ int spdn_cnt; /* ering is CLEAR_END, read comment above CLEAR_END */ From patchwork Tue Apr 4 18:24:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670718 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 E612BC6FD1D for ; Tue, 4 Apr 2023 18:38:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235739AbjDDSiD (ORCPT ); Tue, 4 Apr 2023 14:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231477AbjDDShd (ORCPT ); Tue, 4 Apr 2023 14:37:33 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 227447AB7; Tue, 4 Apr 2023 11:36:15 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id h25so43531172lfv.6; Tue, 04 Apr 2023 11:36:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W/SwkKdRoNxVb2d2rk1vwXdhi8clxcOTg7uTJ+39OtY=; b=MAiJJmjGzfBrSrtxXE3OBkR5HEXE2XC3zyFaRNOgrl4IYaLwiaUuc6kjlEe1xYRln5 XIw11cBVPE08D4xtIEmxqjeQ58JakLhVrLCIa10bde82A4ILbLQ6XZKT+Qwm771sQWsz J0MsIRynQhGdqdvL15gWGGg6/waGqODBXPnS643wzRaBkY6JnqopOwnQl2PYTVwoltIl ETGccPhNHLy06mq3fvWlZhkAr46DqE1E7tw0/AdkwlIvGcP4vyvo1uMCv8PxB0h3VPI8 EK5qNUUjG5ZMdAtr3Ax1SlBAE9lbGG1Sk3/k52f3mPc0vsju8Tz7rarJpjVRJp6BlgJz js2A== X-Gm-Message-State: AAQBX9dM2tlPObKPpHDTjkUGYO+iKQFxJ1J1PH+8k7LXs0mQAziv1eXo i2COI0Q1i1TOGbJHOQpcQ3e7hbhvEdliAA== X-Google-Smtp-Source: AKy350aPXMW3TfRYyAnxIwpMDqHjHzPUfdPPztvAVMXx0VrkXQRltHF7iWWUnLQtHmCGHZJxxJw0Qw== X-Received: by 2002:ac2:4838:0:b0:4e8:47cd:b4ba with SMTP id 24-20020ac24838000000b004e847cdb4bamr966088lft.13.1680633373249; Tue, 04 Apr 2023 11:36:13 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id e3-20020ac25463000000b004eb2f35045bsm2349200lfn.269.2023.04.04.11.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:36:12 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id 0862C865; Tue, 4 Apr 2023 20:36:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633372; bh=EUU/zT1qGCY9K02epCW90BO/+ShxykgjORaxgXb+Zxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmTjJTnFq1BBWKSkKfSBZ+RoGaRz8B6oVq7TZDJJosXezZ+gJPPAgXG9NLSoQ5fE6 PyyRezEHooAmpWEi/ElZwhPXiR3TvPhQe30MTeK3qlXseuq1jbMf/jA7TDnNdweKJk zVpUTg4v8cwZTDdjQiM8XR5t/QQVPol4y7eFJdUw= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id DB03611C2; Tue, 4 Apr 2023 20:25:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632757; bh=EUU/zT1qGCY9K02epCW90BO/+ShxykgjORaxgXb+Zxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CrnAfyxro0GxJbKBbtEJzXvJ9ATtfmLVxSTnW9tgvt2DVrKssN/RThASC0wxKSCyi MC0lbFj9IQCku9RttsjUb3pne8WadzecfWO1B1up4ml5azF7FeZnYqQ4l2TqnYEQ5I 4NOblZ7E5qk3hbKUPSkEJVxCnN7+dO9NNbTw7Brc= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Damien Le Moal Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 18/19] ata: libata: set read/write commands CDL index Date: Tue, 4 Apr 2023 20:24:23 +0200 Message-Id: <20230404182428.715140-19-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Damien Le Moal For devices supporting the command duration limits feature, translate the dld field of read and write operation to set the command duration limit index field of the command task file when the duration limit feature is enabled. The function ata_set_tf_cdl() is introduced to do this. For unqueued (non NCQ) read and write operations, this function sets the command duration limit index set as the lower 2 bits of the feature field. For queued NCQ read/write commands, the index is set as the lower 2 bits of the auxiliary field. The flag ATA_QCFLAG_HAS_CDL is introduced to indicate that a command taskfile has a non zero cdl field. Signed-off-by: Damien Le Moal Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel Reviewed-by: Igor Pylypiv --- drivers/ata/libata-core.c | 32 +++++++++++++++++++++++++++++--- drivers/ata/libata-scsi.c | 16 +++++++++++++++- drivers/ata/libata.h | 2 +- include/linux/libata.h | 1 + 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 62e100fa90e2..c68e7b684a87 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -665,12 +665,29 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) return block; } +/* + * Set a taskfile command duration limit index. + */ +static inline void ata_set_tf_cdl(struct ata_queued_cmd *qc, int cdl) +{ + struct ata_taskfile *tf = &qc->tf; + + if (tf->protocol == ATA_PROT_NCQ) + tf->auxiliary |= cdl; + else + tf->feature |= cdl; + + /* Mark this command as having a CDL */ + qc->flags |= ATA_QCFLAG_HAS_CDL; +} + /** * ata_build_rw_tf - Build ATA taskfile for given read/write request * @qc: Metadata associated with the taskfile to build * @block: Block address * @n_block: Number of blocks * @tf_flags: RW/FUA etc... + * @cdl: Command duration limit index * @class: IO priority class * * LOCKING: @@ -685,7 +702,7 @@ u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev) * -EINVAL if the request is invalid. */ int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block, - unsigned int tf_flags, int class) + unsigned int tf_flags, int cdl, int class) { struct ata_taskfile *tf = &qc->tf; struct ata_device *dev = qc->dev; @@ -724,11 +741,20 @@ int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block, if (dev->flags & ATA_DFLAG_NCQ_PRIO_ENABLED && class == IOPRIO_CLASS_RT) tf->hob_nsect |= ATA_PRIO_HIGH << ATA_SHIFT_PRIO; + + if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) + ata_set_tf_cdl(qc, cdl); + } else if (dev->flags & ATA_DFLAG_LBA) { tf->flags |= ATA_TFLAG_LBA; - /* We need LBA48 for FUA writes */ - if (!(tf->flags & ATA_TFLAG_FUA) && lba_28_ok(block, n_block)) { + if ((dev->flags & ATA_DFLAG_CDL_ENABLED) && cdl) + ata_set_tf_cdl(qc, cdl); + + /* Both FUA writes and a CDL index require 48-bit commands */ + if (!(tf->flags & ATA_TFLAG_FUA) && + !(qc->flags & ATA_QCFLAG_HAS_CDL) && + lba_28_ok(block, n_block)) { /* use LBA28 */ tf->device |= (block >> 24) & 0xf; } else if (lba_48_ok(block, n_block)) { diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 8dde1cede5ca..05bde27947a2 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1380,6 +1380,18 @@ static inline void scsi_16_lba_len(const u8 *cdb, u64 *plba, u32 *plen) *plen = get_unaligned_be32(&cdb[10]); } +/** + * scsi_dld - Get duration limit descriptor index + * @cdb: SCSI command to translate + * + * Returns the dld bits indicating the index of a command duration limit + * descriptor. + */ +static inline int scsi_dld(const u8 *cdb) +{ + return ((cdb[1] & 0x01) << 2) | ((cdb[14] >> 6) & 0x03); +} + /** * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one * @qc: Storage for translated ATA taskfile @@ -1548,6 +1560,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) struct request *rq = scsi_cmd_to_rq(scmd); int class = IOPRIO_PRIO_CLASS(req_get_ioprio(rq)); unsigned int tf_flags = 0; + int dld = 0; u64 block; u32 n_block; int rc; @@ -1598,6 +1611,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) goto invalid_fld; } scsi_16_lba_len(cdb, &block, &n_block); + dld = scsi_dld(cdb); if (cdb[1] & (1 << 3)) tf_flags |= ATA_TFLAG_FUA; if (!ata_check_nblocks(scmd, n_block)) @@ -1622,7 +1636,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) qc->flags |= ATA_QCFLAG_IO; qc->nbytes = n_block * scmd->device->sector_size; - rc = ata_build_rw_tf(qc, block, n_block, tf_flags, class); + rc = ata_build_rw_tf(qc, block, n_block, tf_flags, dld, class); if (likely(rc == 0)) return 0; diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h index 2cd6124a01e8..73dd2ebc277c 100644 --- a/drivers/ata/libata.h +++ b/drivers/ata/libata.h @@ -45,7 +45,7 @@ static inline void ata_force_cbl(struct ata_port *ap) { } extern u64 ata_tf_to_lba(const struct ata_taskfile *tf); extern u64 ata_tf_to_lba48(const struct ata_taskfile *tf); extern int ata_build_rw_tf(struct ata_queued_cmd *qc, u64 block, u32 n_block, - unsigned int tf_flags, int class); + unsigned int tf_flags, int dld, int class); extern u64 ata_tf_read_block(const struct ata_taskfile *tf, struct ata_device *dev); extern unsigned ata_exec_internal(struct ata_device *dev, diff --git a/include/linux/libata.h b/include/linux/libata.h index d7fe735e6322..ab8b62036c12 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -209,6 +209,7 @@ enum { ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */ ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */ ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */ + ATA_QCFLAG_HAS_CDL = (1 << 8), /* qc has CDL a descriptor set */ ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */ ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */ From patchwork Tue Apr 4 18:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Cassel X-Patchwork-Id: 670717 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 95A3BC77B62 for ; Tue, 4 Apr 2023 18:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236266AbjDDSik (ORCPT ); Tue, 4 Apr 2023 14:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234858AbjDDSiY (ORCPT ); Tue, 4 Apr 2023 14:38:24 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F3D46A0; Tue, 4 Apr 2023 11:36:56 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id j11so43491593lfg.13; Tue, 04 Apr 2023 11:36:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680633415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jSxhZ/HdAzehwTgE/T8mjdk0t8X1zWnlluo39/CKDrU=; b=UouFtyTpxjCqRPOV46osYtp0gA+OLtl/gSwLG+gSpcB0g0q4NkQDEwWd0kT+SipG8h S8D9+tAUpcdsCrplNLdUyLBHnbfRQ1Ny6IEL8e//3xp3XKuFWO1yNB1g8tpLxFXuroxT A88T5vosV0nTnvyPxLjwokvzqWp/afVbkR592qJNwgZWv1nrqqsp4vagy7N1DPucD1Kq 8PvTOlqyIjH8jLCrYkTLxmVAXSBM8nr6j/QoJiqGug/HoUuks5cPvH/bChiEy5NKnmXi VbY+pHKhSxUDWEj/EkwNPy1hopihaXr4gxf+cZZBs7MUCdwVVl5GBOjCgjdXpTMo7TvJ 6Arw== X-Gm-Message-State: AAQBX9ebE2hFYZRZJGI2hzgrAAJ/AbME+5Kt7j60rC8S95qkIwxQqoe6 P9PHeISothMBPNJAt0XarnJx4wNwXx8gSg== X-Google-Smtp-Source: AKy350agswhXbrGs+LgsYSWvF2j/348r9qiklenSOe3A7coDG/ClcOMnrlUKmF/oePuvlnXnApDTgg== X-Received: by 2002:ac2:4e4a:0:b0:4e9:bf52:7898 with SMTP id f10-20020ac24e4a000000b004e9bf527898mr676688lfr.37.1680633414694; Tue, 04 Apr 2023 11:36:54 -0700 (PDT) Received: from flawful.org (c-a3f5e255.011-101-6d6c6d3.bbcust.telenor.se. [85.226.245.163]) by smtp.gmail.com with ESMTPSA id n1-20020ac24901000000b004b58500383bsm2434988lfi.272.2023.04.04.11.36.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:36:54 -0700 (PDT) Received: by flawful.org (Postfix, from userid 112) id A2B9A895; Tue, 4 Apr 2023 20:36:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680633413; bh=1rCYlLuSLfr9P5cuQ0ZoGYtYynJ1G0MGLAZ4aFy98fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jL9wX4+mKw8dsZaL3mb3ShUNyPIDbcamk3k6VF2MCNVRv6naNNgaQlN0LVJriPsfP dTmtIHdRfux6+OTx5mplPuK2bynaFLvIJ7INZblTaLrYIn0VpJIOoMFxXTLgDAaPza OsPzVdjbNJMCzf2672VWzJi8L0BsoZFrJVEtA2w4= Received: from x1-carbon.lan (OpenWrt.lan [192.168.1.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by flawful.org (Postfix) with ESMTPSA id 7412D11C3; Tue, 4 Apr 2023 20:25:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=flawful.org; s=mail; t=1680632758; bh=1rCYlLuSLfr9P5cuQ0ZoGYtYynJ1G0MGLAZ4aFy98fI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ExQSHV+hjlIgROi+X/Cuoxm8MB9f3a4QGIyTPlVJIlI4T6wdmZ+CGaSdjNV7g8dL3 p6GsDKpFUmj8O2TmGiHt7li7q9x6y88M/I85qjZcBXdZoOZ7RYP5hHQv0QAiIE0eSS CQJZ0YEN1DK8va8/hy/BYUP1rmmWLUKOhQjsWQG0= From: Niklas Cassel To: Jens Axboe , "Martin K . Petersen" , Damien Le Moal Cc: Bart Van Assche , Christoph Hellwig , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-ide@vger.kernel.org, linux-block@vger.kernel.org, Niklas Cassel Subject: [PATCH v5 19/19] ata: libata: handle completion of CDL commands using policy 0xD Date: Tue, 4 Apr 2023 20:24:24 +0200 Message-Id: <20230404182428.715140-20-nks@flawful.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230404182428.715140-1-nks@flawful.org> References: <20230404182428.715140-1-nks@flawful.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Niklas Cassel A CDL timeout for policy 0xF is defined as a NCQ error, just with a CDL specific sk/asc/ascq in the sense data. Therefore, the existing code in libata does not need to be modified to handle a policy 0xF CDL timeout. For Command Duration Limits policy 0xD: The device shall complete the command without error with the additional sense code set to DATA CURRENTLY UNAVAILABLE. Since a CDL timeout for policy 0xD is not an error, we cannot use the NCQ Command Error log (10h). Instead, we need to read the Sense Data for Successful NCQ Commands log (0Fh). In the success case, just like in the error case, we cannot simply read a log page from the interrupt handler itself, since reading a log page involves sending a READ LOG DMA EXT or READ LOG EXT command. Therefore, we add a new EH action ATA_EH_GET_SUCCESS_SENSE. When a command completes without error, and when the ATA_SENSE bit is set, this new action is set as pending, and EH is scheduled. This way, similar to the NCQ error case, the log page will be read from EH context. An alternative would have been to add a new kthread or workqueue to handle this. However, extending EH can be done with minimal changes and avoids the need to synchronize a new kthread/workqueue with EH. Co-developed-by: Damien Le Moal Signed-off-by: Damien Le Moal Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 88 +++++++++++++++++++++++++++++++- drivers/ata/libata-eh.c | 105 +++++++++++++++++++++++++++++++++++++- drivers/ata/libata-sata.c | 92 +++++++++++++++++++++++++++++++++ include/linux/ata.h | 3 ++ include/linux/libata.h | 11 +++- 5 files changed, 295 insertions(+), 4 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index c68e7b684a87..634b987c6518 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -677,8 +677,12 @@ static inline void ata_set_tf_cdl(struct ata_queued_cmd *qc, int cdl) else tf->feature |= cdl; - /* Mark this command as having a CDL */ - qc->flags |= ATA_QCFLAG_HAS_CDL; + /* + * Mark this command as having a CDL and request the result + * task file so that we can inspect the sense data available + * bit on completion. + */ + qc->flags |= ATA_QCFLAG_HAS_CDL | ATA_QCFLAG_RESULT_TF; } /** @@ -2424,6 +2428,24 @@ static void ata_dev_config_cdl(struct ata_device *dev) ata_dev_warn(dev, "Command duration guideline is not supported\n"); + /* + * We must have support for the sense data for successful NCQ commands + * log indicated by the successful NCQ command sense data supported bit. + */ + val = get_unaligned_le64(&ap->sector_buf[8]); + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(47))) { + ata_dev_warn(dev, + "CDL supported but Successful NCQ Command Sense Data is not supported\n"); + goto not_supported; + } + + /* Without NCQ autosense, the successful NCQ commands log is useless. */ + if (!ata_id_has_ncq_autosense(dev->id)) { + ata_dev_warn(dev, + "CDL supported but NCQ autosense is not supported\n"); + goto not_supported; + } + /* * If CDL is marked as enabled, make sure the feature is enabled too. * Conversely, if CDL is disabled, make sure the feature is turned off. @@ -2458,6 +2480,35 @@ static void ata_dev_config_cdl(struct ata_device *dev) } } + /* + * While CDL itself has to be enabled using sysfs, CDL requires that + * sense data for successful NCQ commands is enabled to work properly. + * Just like ata_dev_config_sense_reporting(), enable it unconditionally + * if supported. + */ + if (!(val & BIT_ULL(63)) || !(val & BIT_ULL(18))) { + err_mask = ata_dev_set_feature(dev, + SETFEATURE_SENSE_DATA_SUCC_NCQ, 0x1); + if (err_mask) { + ata_dev_warn(dev, + "failed to enable Sense Data for successful NCQ commands, Emask 0x%x\n", + err_mask); + goto not_supported; + } + } + + /* + * Allocate a buffer to handle reading the sense data for successful + * NCQ Commands log page for commands using a CDL with one of the limit + * policy set to 0xD (successful completion with sense data available + * bit set). + */ + if (!ap->ncq_sense_buf) { + ap->ncq_sense_buf = kmalloc(ATA_LOG_SENSE_NCQ_SIZE, GFP_KERNEL); + if (!ap->ncq_sense_buf) + goto not_supported; + } + /* * Command duration limits is supported: cache the CDL log page 18h * (command duration descriptors). @@ -2475,6 +2526,8 @@ static void ata_dev_config_cdl(struct ata_device *dev) not_supported: dev->flags &= ~(ATA_DFLAG_CDL | ATA_DFLAG_CDL_ENABLED); + kfree(ap->ncq_sense_buf); + ap->ncq_sense_buf = NULL; } static int ata_dev_config_lba(struct ata_device *dev) @@ -4878,6 +4931,36 @@ void ata_qc_complete(struct ata_queued_cmd *qc) fill_result_tf(qc); trace_ata_qc_complete_done(qc); + + /* + * For CDL commands that completed without an error, check if + * we have sense data (ATA_SENSE is set). If we do, then the + * command may have been aborted by the device due to a limit + * timeout using the policy 0xD. For these commands, invoke EH + * to get the command sense data. + */ + if (qc->result_tf.status & ATA_SENSE && + ((ata_is_ncq(qc->tf.protocol) && + dev->flags & ATA_DFLAG_CDL_ENABLED) || + (!(ata_is_ncq(qc->tf.protocol) && + ata_id_sense_reporting_enabled(dev->id))))) { + /* + * Tell SCSI EH to not overwrite scmd->result even if + * this command is finished with result SAM_STAT_GOOD. + */ + qc->scsicmd->flags |= SCMD_FORCE_EH_SUCCESS; + qc->flags |= ATA_QCFLAG_EH_SUCCESS_CMD; + ehi->dev_action[dev->devno] |= ATA_EH_GET_SUCCESS_SENSE; + + /* + * set pending so that ata_qc_schedule_eh() does not + * trigger fast drain, and freeze the port. + */ + ap->pflags |= ATA_PFLAG_EH_PENDING; + ata_qc_schedule_eh(qc); + return; + } + /* Some commands need post-processing after successful * completion. */ @@ -5510,6 +5593,7 @@ static void ata_host_release(struct kref *kref) kfree(ap->pmp_link); kfree(ap->slave_link); + kfree(ap->ncq_sense_buf); kfree(ap); host->ports[i] = NULL; } diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 598ae07195b6..05af292eb8ce 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1917,6 +1917,99 @@ static inline bool ata_eh_quiet(struct ata_queued_cmd *qc) return qc->flags & ATA_QCFLAG_QUIET; } +static int ata_eh_read_sense_success_non_ncq(struct ata_link *link) +{ + struct ata_port *ap = link->ap; + struct ata_queued_cmd *qc; + + qc = __ata_qc_from_tag(ap, link->active_tag); + if (!qc) + return -EIO; + + if (!(qc->flags & ATA_QCFLAG_EH) || + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || + qc->err_mask) + return -EIO; + + if (!ata_eh_request_sense(qc)) + return -EIO; + + /* + * If we have sense data, call scsi_check_sense() in order to set the + * correct SCSI ML byte (if any). No point in checking the return value, + * since the command has already completed successfully. + */ + scsi_check_sense(qc->scsicmd); + + return 0; +} + +static void ata_eh_get_success_sense(struct ata_link *link) +{ + struct ata_eh_context *ehc = &link->eh_context; + struct ata_device *dev = link->device; + struct ata_port *ap = link->ap; + struct ata_queued_cmd *qc; + int tag, ret = 0; + + if (!(ehc->i.dev_action[dev->devno] & ATA_EH_GET_SUCCESS_SENSE)) + return; + + /* if frozen, we can't do much */ + if (ata_port_is_frozen(ap)) { + ata_dev_warn(dev, + "successful sense data available but port frozen\n"); + goto out; + } + + /* + * If the link has sactive set, then we have outstanding NCQ commands + * and have to read the Successful NCQ Commands log to get the sense + * data. Otherwise, we are dealing with a non-NCQ command and use + * request sense ext command to retrieve the sense data. + */ + if (link->sactive) + ret = ata_eh_read_sense_success_ncq_log(link); + else + ret = ata_eh_read_sense_success_non_ncq(link); + if (ret) + goto out; + + ata_eh_done(link, dev, ATA_EH_GET_SUCCESS_SENSE); + return; + +out: + /* + * If we failed to get sense data for a successful command that ought to + * have sense data, we cannot simply return BLK_STS_OK to user space. + * This is because we can't know if the sense data that we couldn't get + * was actually "DATA CURRENTLY UNAVAILABLE". Reporting such a command + * as success to user space would result in a silent data corruption. + * Thus, add a bogus ABORTED_COMMAND sense data to such commands, such + * that SCSI will report these commands as BLK_STS_IOERR to user space. + */ + ata_qc_for_each_raw(ap, qc, tag) { + if (!(qc->flags & ATA_QCFLAG_EH) || + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || + qc->err_mask || + ata_dev_phys_link(qc->dev) != link) + continue; + + /* We managed to get sense for this success command, skip. */ + if (qc->flags & ATA_QCFLAG_SENSE_VALID) + continue; + + /* This success command did not have any sense data, skip. */ + if (!(qc->result_tf.status & ATA_SENSE)) + continue; + + /* This success command had sense data, but we failed to get. */ + ata_scsi_set_sense(dev, qc->scsicmd, ABORTED_COMMAND, 0, 0); + qc->flags |= ATA_QCFLAG_SENSE_VALID; + } + ata_eh_done(link, dev, ATA_EH_GET_SUCCESS_SENSE); +} + /** * ata_eh_link_autopsy - analyze error and determine recovery action * @link: host link to perform autopsy on @@ -1957,6 +2050,14 @@ static void ata_eh_link_autopsy(struct ata_link *link) /* analyze NCQ failure */ ata_eh_analyze_ncq_error(link); + /* + * Check if this was a successful command that simply needs sense data. + * Since the sense data is not part of the completion, we need to fetch + * it using an additional command. Since this can't be done from irq + * context, the sense data for successful commands are fetched by EH. + */ + ata_eh_get_success_sense(link); + /* any real error trumps AC_ERR_OTHER */ if (ehc->i.err_mask & ~AC_ERR_OTHER) ehc->i.err_mask &= ~AC_ERR_OTHER; @@ -1966,6 +2067,7 @@ static void ata_eh_link_autopsy(struct ata_link *link) ata_qc_for_each_raw(ap, qc, tag) { if (!(qc->flags & ATA_QCFLAG_EH) || qc->flags & ATA_QCFLAG_RETRY || + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD || ata_dev_phys_link(qc->dev) != link) continue; @@ -3825,7 +3927,8 @@ void ata_eh_finish(struct ata_port *ap) else ata_eh_qc_complete(qc); } else { - if (qc->flags & ATA_QCFLAG_SENSE_VALID) { + if (qc->flags & ATA_QCFLAG_SENSE_VALID || + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) { ata_eh_qc_complete(qc); } else { /* feed zero TF to sense generation */ diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c index 57cb33060c9d..7de4d8901fac 100644 --- a/drivers/ata/libata-sata.c +++ b/drivers/ata/libata-sata.c @@ -11,7 +11,9 @@ #include #include #include +#include #include +#include #include "libata.h" #include "libata-transport.h" @@ -1408,6 +1410,95 @@ static int ata_eh_read_log_10h(struct ata_device *dev, return 0; } +/** + * ata_eh_read_sense_success_ncq_log - Read the sense data for successful + * NCQ commands log + * @link: ATA link to get sense data for + * + * Read the sense data for successful NCQ commands log page to obtain + * sense data for all NCQ commands that completed successfully with + * the sense data available bit set. + * + * LOCKING: + * Kernel thread context (may sleep). + * + * RETURNS: + * 0 on success, -errno otherwise. + */ +int ata_eh_read_sense_success_ncq_log(struct ata_link *link) +{ + struct ata_device *dev = link->device; + struct ata_port *ap = dev->link->ap; + u8 *buf = ap->ncq_sense_buf; + struct ata_queued_cmd *qc; + unsigned int err_mask, tag; + u8 *sense, sk = 0, asc = 0, ascq = 0; + u64 sense_valid, val; + int ret = 0; + + err_mask = ata_read_log_page(dev, ATA_LOG_SENSE_NCQ, 0, buf, 2); + if (err_mask) { + ata_dev_err(dev, + "Failed to read Sense Data for Successful NCQ Commands log\n"); + return -EIO; + } + + /* Check the log header */ + val = get_unaligned_le64(&buf[0]); + if ((val & 0xffff) != 1 || ((val >> 16) & 0xff) != 0x0f) { + ata_dev_err(dev, + "Invalid Sense Data for Successful NCQ Commands log\n"); + return -EIO; + } + + sense_valid = (u64)buf[8] | ((u64)buf[9] << 8) | + ((u64)buf[10] << 16) | ((u64)buf[11] << 24); + + ata_qc_for_each_raw(ap, qc, tag) { + if (!(qc->flags & ATA_QCFLAG_EH) || + !(qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD) || + qc->err_mask || + ata_dev_phys_link(qc->dev) != link) + continue; + + /* + * If the command does not have any sense data, clear ATA_SENSE. + * Keep ATA_QCFLAG_EH_SUCCESS_CMD so that command is finished. + */ + if (!(sense_valid & (1ULL << tag))) { + qc->result_tf.status &= ~ATA_SENSE; + continue; + } + + sense = &buf[32 + 24 * tag]; + sk = sense[0]; + asc = sense[1]; + ascq = sense[2]; + + if (!ata_scsi_sense_is_valid(sk, asc, ascq)) { + ret = -EIO; + continue; + } + + /* Set sense without also setting scsicmd->result */ + scsi_build_sense_buffer(dev->flags & ATA_DFLAG_D_SENSE, + qc->scsicmd->sense_buffer, sk, + asc, ascq); + qc->flags |= ATA_QCFLAG_SENSE_VALID; + + /* + * If we have sense data, call scsi_check_sense() in order to + * set the correct SCSI ML byte (if any). No point in checking + * the return value, since the command has already completed + * successfully. + */ + scsi_check_sense(qc->scsicmd); + } + + return ret; +} +EXPORT_SYMBOL_GPL(ata_eh_read_sense_success_ncq_log); + /** * ata_eh_analyze_ncq_error - analyze NCQ error * @link: ATA link to analyze NCQ error for @@ -1488,6 +1579,7 @@ void ata_eh_analyze_ncq_error(struct ata_link *link) ata_qc_for_each_raw(ap, qc, tag) { if (!(qc->flags & ATA_QCFLAG_EH) || + qc->flags & ATA_QCFLAG_EH_SUCCESS_CMD || ata_dev_phys_link(qc->dev) != link) continue; diff --git a/include/linux/ata.h b/include/linux/ata.h index a59b17d6ad11..2e2e22362096 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -326,6 +326,8 @@ enum { ATA_LOG_CDL = 0x18, ATA_LOG_CDL_SIZE = ATA_SECT_SIZE, ATA_LOG_IDENTIFY_DEVICE = 0x30, + ATA_LOG_SENSE_NCQ = 0x0F, + ATA_LOG_SENSE_NCQ_SIZE = ATA_SECT_SIZE * 2, ATA_LOG_CONCURRENT_POSITIONING_RANGES = 0x47, /* Identify device log pages: */ @@ -432,6 +434,7 @@ enum { SATA_DEVSLP = 0x09, /* Device Sleep */ SETFEATURE_SENSE_DATA = 0xC3, /* Sense Data Reporting feature */ + SETFEATURE_SENSE_DATA_SUCC_NCQ = 0xC4, /* Sense Data for successful NCQ commands */ /* feature values for SET_MAX */ ATA_SET_MAX_ADDR = 0x00, diff --git a/include/linux/libata.h b/include/linux/libata.h index ab8b62036c12..70ac635fe5d7 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -214,6 +214,7 @@ enum { ATA_QCFLAG_EH = (1 << 16), /* cmd aborted and owned by EH */ ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */ ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */ + ATA_QCFLAG_EH_SUCCESS_CMD = (1 << 19), /* EH should fetch sense for this successful cmd */ /* host set flags */ ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */ @@ -312,8 +313,10 @@ enum { ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET, ATA_EH_ENABLE_LINK = (1 << 3), ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */ + ATA_EH_GET_SUCCESS_SENSE = (1 << 6), /* Get sense data for successful cmd */ - ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK, + ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK | + ATA_EH_GET_SUCCESS_SENSE, ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET | ATA_EH_ENABLE_LINK, @@ -867,6 +870,7 @@ struct ata_port { struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */ #endif /* owned by EH */ + u8 *ncq_sense_buf; u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned; }; @@ -1185,6 +1189,7 @@ extern int sata_link_hardreset(struct ata_link *link, bool *online, int (*check_ready)(struct ata_link *)); extern int sata_link_resume(struct ata_link *link, const unsigned long *params, unsigned long deadline); +extern int ata_eh_read_sense_success_ncq_log(struct ata_link *link); extern void ata_eh_analyze_ncq_error(struct ata_link *link); #else static inline const unsigned long * @@ -1222,6 +1227,10 @@ static inline int sata_link_resume(struct ata_link *link, { return -EOPNOTSUPP; } +static inline int ata_eh_read_sense_success_ncq_log(struct ata_link *link) +{ + return -EOPNOTSUPP; +} static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { } #endif extern int sata_link_debounce(struct ata_link *link,