From patchwork Mon Jul 1 19:57:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=qIO5CXwX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-1777-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcKl2zHpz1xpc for ; Tue, 2 Jul 2024 05:58:19 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8EC421C220C9 for ; Mon, 1 Jul 2024 19:58:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0EAC17106C; Mon, 1 Jul 2024 19:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qIO5CXwX" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 093F616EC06 for ; Mon, 1 Jul 2024 19:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863888; cv=none; b=hY9LyD+MvApBvxurlMcR+DR2WErDCrsRhwRxkeNuoVKVEJDx/PKeEICpv+U6Z0ZSlXgHVCMSFl1/Q9B7TidBNhP+0IxHwGqphFKVSG7bTNOF5l8qU3WU+LtCgkPeDrxrh2NKMxm8uOmZjJI8X2UP01Qiig1Wn2p8YbLhZ9J1IIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863888; c=relaxed/simple; bh=khdJffv/7S+fJo+T1ERSS/3kzh8tOaLDJIGVkc4xP/s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lPgw6Gej7bAyqbLqprBbJQGjm+6yUahbRv3SF2wC/VeGnIYVTafEijK/0zjjTYUrPoJNr0Y3SejgoDbSbrzKp+mVTz3V6ivWCMgJTZ6c2QgFy6WmaJARwnjdiUG3dCxNIEthjfz0tfCMzOcxhuju2iRXTXR8x0L0hiGHrZvZauU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qIO5CXwX; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64b5588bcafso50265207b3.1 for ; Mon, 01 Jul 2024 12:58:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863886; x=1720468686; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=dnwRRitprzkm9CFQnXP8vP+tPUkvyuIbgLz5w5FglfM=; b=qIO5CXwX4Z+q/un3+dPyJov/IdHdVx3LxX+SGM9FiLY+99fm56R2ImcDK740w4NTrF K+Z69e2Yj3jGl4iMLPLy4hjI3lU9gcjpYf8HQl/wAy1QDKBmlmqSuy+dwCN1w3o4W+G1 jqV58ovnVaTdR4QuhILoUV84ZsklDZyJe3zqs0eMxuSxXZy2jmivULhPXQdHfJLQDAM+ WP3h7fLrscPHtsqrxRwnZ38x9JVv3ULdg8CspvAsLrR3h4k+cO8JUBvcUBbXcqT0Mh9/ ou8fsxZRGuoVjCUke4YeevXw5LySEiRPUS7lDpthxh2yNu5fyftZTCZmvWNKiwNCvgf7 xV0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863886; x=1720468686; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=dnwRRitprzkm9CFQnXP8vP+tPUkvyuIbgLz5w5FglfM=; b=dinjyzvtO2wb4vPKnFKPrl/GQ6JavptSfifey/rrVbJJy81wlf6GvdACv4EeXAdiJg iG7NZULOirMPPGwnlbR1V1MRqquc/5Eqt/UOEAqqBdakANKDevHriVqL0bEZ7VQlbew5 XwHKSG+bN4Lv40vhDjRft7jERlhS479WjVSM+3budTcEjMHl86nRI22E+Eo6ExZ5mr72 x2AUCh5bLa8GmJvNJaFiun3BorGzt+wn+PZfEoRkOM6VqNPIIOaCU7NxKrQvZcFgdUNr IwSNHgl6Oi6Bq3AslHT42IRlz1dPG+e5Q6hgCWeTrU6bFSZIq4zAcAqEYm+YAeLa+fOI y2JQ== X-Forwarded-Encrypted: i=1; AJvYcCXGLNzu1FM6JNicB7rWHv4r6T6JgDk8jSeGXLcKDrPcdHUj3lVgCR1mzSfKSHAOF8ED5j/qhfiM2tCySL80q70wXi6bhD/ToWOI X-Gm-Message-State: AOJu0YypKBEji6oTTqbusJ7fHdhnrzoHyRMDYRJPc5p1KUnSfgAtAoqd C21dRgiH0h9YxtzqAfpO6AgKFlY2rf13qbEIOAEWhiIOErM+5K7aCZ8c0H5ETtzZ62QwpltnMdD Dg9xWbO9Myg== X-Google-Smtp-Source: AGHT+IGzMEpQQ0h2vrhesUkCvW4udpb8us0XQRrchEc3aCPHfOQhX6iByBHH4rABuctrZO5NmeW5fAelZsUPQA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:1009:b0:df4:d6ca:fed0 with SMTP id 3f1490d57ef6-e036eaf6cbemr16573276.4.1719863886049; Mon, 01 Jul 2024 12:58:06 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:51 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-2-ipylypiv@google.com> Subject: [PATCH v4 1/8] ata: libata-scsi: Fix offsets for the fixed format sense data From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv , Akshat Jain , stable@vger.kernel.org Correct the ATA PASS-THROUGH fixed format sense data offsets to conform to SPC-6 and SAT-5 specifications. Additionally, set the VALID bit to indicate that the INFORMATION field contains valid information. INFORMATION =========== SAT-5 Table 212 — "Fixed format sense data INFORMATION field for the ATA PASS-THROUGH commands" defines the following format: +------+------------+ | Byte | Field | +------+------------+ | 0 | ERROR | | 1 | STATUS | | 2 | DEVICE | | 3 | COUNT(7:0) | +------+------------+ SPC-6 Table 48 - "Fixed format sense data" specifies that the INFORMATION field starts at byte 3 in sense buffer resulting in the following offsets for the ATA PASS-THROUGH commands: +------------+-------------------------+ | Field | Offset in sense buffer | +------------+-------------------------+ | ERROR | 3 | | STATUS | 4 | | DEVICE | 5 | | COUNT(7:0) | 6 | +------------+-------------------------+ COMMAND-SPECIFIC INFORMATION ============================ SAT-5 Table 213 - "Fixed format sense data COMMAND-SPECIFIC INFORMATION field for ATA PASS-THROUGH" defines the following format: +------+-------------------+ | Byte | Field | +------+-------------------+ | 0 | FLAGS | LOG INDEX | | 1 | LBA (7:0) | | 2 | LBA (15:8) | | 3 | LBA (23:16) | +------+-------------------+ SPC-6 Table 48 - "Fixed format sense data" specifies that the COMMAND-SPECIFIC-INFORMATION field starts at byte 8 in sense buffer resulting in the following offsets for the ATA PASS-THROUGH commands: Offsets of these fields in the fixed sense format are as follows: +-------------------+-------------------------+ | Field | Offset in sense buffer | +-------------------+-------------------------+ | FLAGS | LOG INDEX | 8 | | LBA (7:0) | 9 | | LBA (15:8) | 10 | | LBA (23:16) | 11 | +-------------------+-------------------------+ Reported-by: Akshat Jain Fixes: 11093cb1ef56 ("libata-scsi: generate correct ATA pass-through sense") Cc: stable@vger.kernel.org Reviewed-by: Hannes Reinecke Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bb4d30d377ae..a9e44ad4c2de 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -855,7 +855,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) struct scsi_cmnd *cmd = qc->scsicmd; struct ata_taskfile *tf = &qc->result_tf; unsigned char *sb = cmd->sense_buffer; - unsigned char *desc = sb + 8; u8 sense_key, asc, ascq; memset(sb, 0, SCSI_SENSE_BUFFERSIZE); @@ -877,7 +876,8 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } - if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { + if ((sb[0] & 0x7f) >= 0x72) { + unsigned char *desc; u8 len; /* descriptor format */ @@ -916,21 +916,21 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) } } else { /* Fixed sense format */ - desc[0] = tf->error; - desc[1] = tf->status; - desc[2] = tf->device; - desc[3] = tf->nsect; - desc[7] = 0; + sb[0] |= 0x80; + sb[3] = tf->error; + sb[4] = tf->status; + sb[5] = tf->device; + sb[6] = tf->nsect; if (tf->flags & ATA_TFLAG_LBA48) { - desc[8] |= 0x80; + sb[8] |= 0x80; if (tf->hob_nsect) - desc[8] |= 0x40; + sb[8] |= 0x40; if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - desc[8] |= 0x20; + sb[8] |= 0x20; } - desc[9] = tf->lbal; - desc[10] = tf->lbam; - desc[11] = tf->lbah; + sb[9] = tf->lbal; + sb[10] = tf->lbam; + sb[11] = tf->lbah; } } From patchwork Mon Jul 1 19:57:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954915 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=MCdmzE9d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ide+bounces-1779-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcLB5nBhz1xpc for ; Tue, 2 Jul 2024 05:58:42 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C067B1C21D28 for ; Mon, 1 Jul 2024 19:58:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E61E917165D; Mon, 1 Jul 2024 19:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MCdmzE9d" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE0AB171068 for ; Mon, 1 Jul 2024 19:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863891; cv=none; b=Dh/+2lf82FZYD1TWVOevMFwFxgxVjAKunnF//NqXnuNF2hBpkHx7hgE+4uUCR/tf1OSglOtMqcEANWVYFFh6SuNFjdx6ibZ5rPMLs3OhMfgKcgbCRCWDJWINVSU7hKBVfS85mint1tHrCENE0z8Hzn37MbJ0cv8NVsuPndqGFCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863891; c=relaxed/simple; bh=ZLjYMaL8Qyi9TVUaRicQazbm16gA30cvYVELDgT010w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EBFrRDCgJVcX39bolhWAfnBh2mOr/TcpHLNmUDbgRKwcVXf8RWtUL6k3cz9l6ls8wZ9Kc2UHbH1zDbLFQWj9Vge8UMxIBXh1EWQbsUsJUAunVl/Cpyh7D944xJKo+Ydz+wTRTgS+AZNEG4kfYKbqIgqe7P7E2+Aw1yDDLw0eEoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MCdmzE9d; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62d032a07a9so60489057b3.2 for ; Mon, 01 Jul 2024 12:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863888; x=1720468688; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=7hpsMKkbWsm8xFwmpkpRI0G9chARJ4LR35R5atPcFvU=; b=MCdmzE9dPXnrId4NjSEtwGrKRXRI5bzz6t6TD1rL9BmIetsDJvKesMgn9Tr2ImszqR vJ7qZ1jkyw1ivPvkyTm5r5XqEg8WkTgAzkfUE3cGTuqrFmbEbIXHDS3+SzdxcKr14/fu cCCaAO4xGFki304NmHlcsBXcfev30Ka32pcFRWh4Am9AL2kx67JVSacX7irVP9Tkt7Ef I+8zAcMNw1IcZHNYqHXrjt6LRGinQbLlF8ae5/l8Hl2MbdS0PbKT08hN0oJqV6i5EnO/ j2aWUGMpO6L+gKbCFm+Ov98QdQFIaaWo2/kZmSKE7WEL0pJknwQqXl/jUlsLPJK4v4xW Zptg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863888; x=1720468688; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7hpsMKkbWsm8xFwmpkpRI0G9chARJ4LR35R5atPcFvU=; b=STkVckiN1FM17AcjM8vNyezQHz/ANUhXJlq+QQ21ZtwOjWFREtGRIkTXDfDbtD/bUP 1OadMgZL4CPFCkXvxNcrp8s1eQdrXSpZunKZG0BKXTq0xBFRnXOcE/oalOmJUfcdu3l5 vEWhu7adnhD0MDnBXh8MODrox+Rjw4aEJDv2RChTmjcKggShOqqk8IZrlMb7KIP2wo/y ezPtjL/LhJLBGEoOMbaDQqaALUYlbC/VN/QyI6BbCZGNq1oQEUK3tN0odqTPp1kackmP zFCQBpqna66+gKYro4xq8x7zbiH0/7tZ7FOHZR50amNMY/3ZakLRz6+9fps+f18SYw1p I2Mg== X-Forwarded-Encrypted: i=1; AJvYcCXjnRcM4dLsaY9BuwqvBLVnlHg8RMUB6cBbkYWoxzgZ0Z9da2Goii11uPteGVmDeAqVK9Va2PGSRSGaU4c+jfF7LzDZNz8mo8g9 X-Gm-Message-State: AOJu0YwIHZnIzQtueyo4FBajgTG+ciK2nL03ls8fqtar8gHOxRcAPisG MAQrOo4rGAhED/Tlj099NdfNBIioxj67pfP+TEC4bPzisugXkiDzfPh1+xbsoOhYSWGNG21A2hv Y5l4ZYfCjBg== X-Google-Smtp-Source: AGHT+IFjzwVH/lDbFP6+5t+gbN7tDyJ7ZS3m5w81CUiAeq010hfBfbhybTg1/Btd5srp4wcEbmWfqUUz0u9acg== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:d1a:b0:62d:1142:83a5 with SMTP id 00721157ae682-64c77ca3b5dmr940657b3.8.1719863887691; Mon, 01 Jul 2024 12:58:07 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:52 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-3-ipylypiv@google.com> Subject: [PATCH v4 2/8] ata: libata-scsi: Do not overwrite valid sense data when CK_COND=1 From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv , stable@vger.kernel.org Current ata_gen_passthru_sense() code performs two actions: 1. Generates sense data based on the ATA 'status' and ATA 'error' fields. 2. Populates "ATA Status Return sense data descriptor" / "Fixed format sense data" with ATA taskfile fields. The problem is that #1 generates sense data even when a valid sense data is already present (ATA_QCFLAG_SENSE_VALID is set). Factoring out #2 into a separate function allows us to generate sense data only when there is no valid sense data (ATA_QCFLAG_SENSE_VALID is not set). As a bonus, we can now delete a FIXME comment in atapi_qc_complete() which states that we don't want to translate taskfile registers into sense descriptors for ATAPI. Cc: stable@vger.kernel.org # 4.19+ Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 158 +++++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 72 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a9e44ad4c2de..26b1263f5c7c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -230,6 +230,80 @@ void ata_scsi_set_sense_information(struct ata_device *dev, SCSI_SENSE_BUFFERSIZE, information); } +/** + * ata_scsi_set_passthru_sense_fields - Set ATA fields in sense buffer + * @qc: ATA PASS-THROUGH command. + * + * Populates "ATA Status Return sense data descriptor" / "Fixed format + * sense data" with ATA taskfile fields. + * + * LOCKING: + * None. + */ +static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc) +{ + struct scsi_cmnd *cmd = qc->scsicmd; + struct ata_taskfile *tf = &qc->result_tf; + unsigned char *sb = cmd->sense_buffer; + + if ((sb[0] & 0x7f) >= 0x72) { + unsigned char *desc; + u8 len; + + /* descriptor format */ + len = sb[7]; + desc = (char *)scsi_sense_desc_find(sb, len + 8, 9); + if (!desc) { + if (SCSI_SENSE_BUFFERSIZE < len + 14) + return; + sb[7] = len + 14; + desc = sb + 8 + len; + } + desc[0] = 9; + desc[1] = 12; + /* + * Copy registers into sense buffer. + */ + desc[2] = 0x00; + desc[3] = tf->error; + desc[5] = tf->nsect; + desc[7] = tf->lbal; + desc[9] = tf->lbam; + desc[11] = tf->lbah; + desc[12] = tf->device; + desc[13] = tf->status; + + /* + * Fill in Extend bit, and the high order bytes + * if applicable. + */ + if (tf->flags & ATA_TFLAG_LBA48) { + desc[2] |= 0x01; + desc[4] = tf->hob_nsect; + desc[6] = tf->hob_lbal; + desc[8] = tf->hob_lbam; + desc[10] = tf->hob_lbah; + } + } else { + /* Fixed sense format */ + sb[0] |= 0x80; + sb[3] = tf->error; + sb[4] = tf->status; + sb[5] = tf->device; + sb[6] = tf->nsect; + if (tf->flags & ATA_TFLAG_LBA48) { + sb[8] |= 0x80; + if (tf->hob_nsect) + sb[8] |= 0x40; + if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) + sb[8] |= 0x20; + } + sb[9] = tf->lbal; + sb[10] = tf->lbam; + sb[11] = tf->lbah; + } +} + static void ata_scsi_set_invalid_field(struct ata_device *dev, struct scsi_cmnd *cmd, u16 field, u8 bit) { @@ -837,10 +911,8 @@ static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, * ata_gen_passthru_sense - Generate check condition sense block. * @qc: Command that completed. * - * This function is specific to the ATA descriptor format sense - * block specified for the ATA pass through commands. Regardless - * of whether the command errored or not, return a sense - * block. Copy all controller registers into the sense + * This function is specific to the ATA pass through commands. + * Regardless of whether the command errored or not, return a sense * block. If there was no error, we get the request from an ATA * passthrough command, so we use the following sense data: * sk = RECOVERED ERROR @@ -875,63 +947,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) */ scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } - - if ((sb[0] & 0x7f) >= 0x72) { - unsigned char *desc; - u8 len; - - /* descriptor format */ - len = sb[7]; - desc = (char *)scsi_sense_desc_find(sb, len + 8, 9); - if (!desc) { - if (SCSI_SENSE_BUFFERSIZE < len + 14) - return; - sb[7] = len + 14; - desc = sb + 8 + len; - } - desc[0] = 9; - desc[1] = 12; - /* - * Copy registers into sense buffer. - */ - desc[2] = 0x00; - desc[3] = tf->error; - desc[5] = tf->nsect; - desc[7] = tf->lbal; - desc[9] = tf->lbam; - desc[11] = tf->lbah; - desc[12] = tf->device; - desc[13] = tf->status; - - /* - * Fill in Extend bit, and the high order bytes - * if applicable. - */ - if (tf->flags & ATA_TFLAG_LBA48) { - desc[2] |= 0x01; - desc[4] = tf->hob_nsect; - desc[6] = tf->hob_lbal; - desc[8] = tf->hob_lbam; - desc[10] = tf->hob_lbah; - } - } else { - /* Fixed sense format */ - sb[0] |= 0x80; - sb[3] = tf->error; - sb[4] = tf->status; - sb[5] = tf->device; - sb[6] = tf->nsect; - if (tf->flags & ATA_TFLAG_LBA48) { - sb[8] |= 0x80; - if (tf->hob_nsect) - sb[8] |= 0x40; - if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - sb[8] |= 0x20; - } - sb[9] = tf->lbal; - sb[10] = tf->lbam; - sb[11] = tf->lbah; - } } /** @@ -1634,6 +1649,8 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) u8 *cdb = cmd->cmnd; int need_sense = (qc->err_mask != 0) && !(qc->flags & ATA_QCFLAG_SENSE_VALID); + int need_passthru_sense = (qc->err_mask != 0) || + (qc->flags & ATA_QCFLAG_SENSE_VALID); /* For ATA pass thru (SAT) commands, generate a sense block if * user mandated it or if there's an error. Note that if we @@ -1645,13 +1662,16 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE */ if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && - ((cdb[2] & 0x20) || need_sense)) - ata_gen_passthru_sense(qc); - else if (need_sense) + ((cdb[2] & 0x20) || need_passthru_sense)) { + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) + ata_gen_passthru_sense(qc); + ata_scsi_set_passthru_sense_fields(qc); + } else if (need_sense) { ata_gen_ata_sense(qc); - else + } else { /* Keep the SCSI ML and status byte, clear host byte. */ cmd->result &= 0x0000ffff; + } ata_qc_done(qc); } @@ -2590,14 +2610,8 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc) /* handle completion from EH */ if (unlikely(err_mask || qc->flags & ATA_QCFLAG_SENSE_VALID)) { - if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) { - /* FIXME: not quite right; we don't want the - * translation of taskfile registers into a - * sense descriptors, since that's only - * correct for ATA, not ATAPI - */ + if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) ata_gen_passthru_sense(qc); - } /* SCSI EH automatically locks door if sdev->locked is * set. Sometimes door lock request continues to From patchwork Mon Jul 1 19:57:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954914 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=k7w3CaWh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ide+bounces-1778-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcL66F6hz1xpc for ; Tue, 2 Jul 2024 05:58:38 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9B68E2842F6 for ; Mon, 1 Jul 2024 19:58:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8809171651; Mon, 1 Jul 2024 19:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="k7w3CaWh" X-Original-To: linux-ide@vger.kernel.org Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21AFF17108B for ; Mon, 1 Jul 2024 19:58:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863891; cv=none; b=a7DoFCGJljffcY0MRAfLaIpdYZaOZrxs10xkhgnrarhURGLD0wmhJE1KRwdrPKastcXWO9YdkHyTqg5PJmRPntRXBaggtPuob3ntUggUUu1eS4cUSHNKoG9I++FFVueBWOYiHuDTGXw4AFFe+aZ9ND8afXlHB+ed1q6h/lLkXGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863891; c=relaxed/simple; bh=i1WM4kmIfmDHPI5dw7j2QdeDu+pN70xb5vkqTT4Klio=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IZ3wUxwd55tPnbjH/BAz5oDB7IREed496ngcRjbahUPnuMCzsTQRh+6OA6o1jeME4IX6gsCL8HZGzwysWtHLBLCIbOcCviBLqwFiBepNNTfqcbAqMZ98DxPqOLTIXhQHF6kgh2FenqRzTigaXwu1H55p35eSiS6LXaNhJEZx1H8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=k7w3CaWh; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-706698fe5b4so3164325b3a.2 for ; Mon, 01 Jul 2024 12:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863889; x=1720468689; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MMO2KKUa8/8PW1hug4/vwJix22ScHjcmOPyPA73iWX4=; b=k7w3CaWhvv+L8yZDE5/eQgrqkbG/rwjjPeOzvT6xVjTVUwXMqrCfT8wo6zMePw1RGK Fou0imwoYIoZgTH0jE2PwkOozeWPuPp5Nf7DDqphbtirONKGA65Qmbe5tfgXVvHjIcuR nfmtO+G8cw3z/dZMpRtMnjkJSwDnn7m7HFwMTix6LQ+vjbXj8MNcjYy9yvVyDqj3Hcn4 GYAbiZOu8fW2dA3eCOWusNlqKyl/a79kBeh9a09KJcEiAAnc1+rOL/fefWgLMIPauyiB RX7V4jbcY9VJZwGov+I+k1XQPt7w5LHERBr3mBh/Sv1gnrB/aXOGextKURzu2n+laarX WnmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863889; x=1720468689; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MMO2KKUa8/8PW1hug4/vwJix22ScHjcmOPyPA73iWX4=; b=EsrZHsqTXI+s00naW2iIzuQJ/hrRSrqfBcRKvV9ABnq/+fb9uCDyoj+jhAxdxHtrWX Uz1P0QamOsD5nhs2WVIdF/YJS21GUzVGdmtZFPb+Gfc/d+cbhzFWqdicztRMgXwUF4Qa R+JQRu8cCG07oav5fGV2ydTxKAChond69ABfoQ4qNdbRSDOy1IuTp8SNkTH+nnBa9tYK YB2/5fTcrxXFFXLNr3w64niS5ehgKoTCwlQMEMiSFVyK3HY88UN9mI48ek/06OwdHNQb mNSqoIKhQJO8NTOxfXpJnErE7WcBEEx95NDYndD88rgQHROKVhbxYjanIl21hiZBpFt6 cEcw== X-Forwarded-Encrypted: i=1; AJvYcCWgZ/jeFleWQQBjLilYDsHzG4qIO2o6SMLp92dqH7juvytyzH6NmbW7XKOwVJvkb5Q4prcv37sukcotyZNfcJOXPSa36xysnY7/ X-Gm-Message-State: AOJu0YzqEOucYgru1XoSkIwh8Lk8Ew44m9eZZf6vzQMifYYApJ+AQ5lI QXw7QSufRgfEIUza5niv0u9y9lnzDXGonp/EQtNog/vb5bnxisBTaAbQdxX9d43pFwaohpNTlGZ W60oFcZP7wQ== X-Google-Smtp-Source: AGHT+IHReH8MOWTtus6bvZ9IiV9dzMjmSS3I/s0f4LPu18gpADTm0fop6yxvqbOXiivfQbvbcjpBGN3Z6yyMCQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:1889:b0:706:2a35:66e3 with SMTP id d2e1a72fcca58-70aaaf9d74emr528990b3a.6.1719863889424; Mon, 01 Jul 2024 12:58:09 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:53 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-4-ipylypiv@google.com> Subject: [PATCH v4 3/8] ata: libata-scsi: Honour the D_SENSE bit for CK_COND=1 and no error From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv , stable@vger.kernel.org SAT-5 revision 8 specification removed the text about the ANSI INCITS 431-2007 compliance which was requiring SCSI/ATA Translation (SAT) to return descriptor format sense data for the ATA PASS-THROUGH commands regardless of the setting of the D_SENSE bit. Let's honour the D_SENSE bit for CK_COND=1 commands that had no error. Kernel already honours the D_SENSE bit when creating the sense buffer for commands that had an error. SAT-5 revision 7 ================ 12.2.2.8 Fixed format sense data Table 212 shows the fields returned in the fixed format sense data (see SPC-5) for ATA PASS-THROUGH commands. SATLs compliant with ANSI INCITS 431-2007, SCSI/ATA Translation (SAT) return descriptor format sense data for the ATA PASS-THROUGH commands regardless of the setting of the D_SENSE bit. SAT-5 revision 8 ================ 12.2.2.8 Fixed format sense data Table 211 shows the fields returned in the fixed format sense data (see SPC-5) for ATA PASS-THROUGH commands. Cc: stable@vger.kernel.org # 4.19+ Reported-by: Niklas Cassel Closes: https://lore.kernel.org/linux-ide/Zn1WUhmLglM4iais@ryzen.lan Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 26b1263f5c7c..ace6b009e7ff 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -941,11 +941,8 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) &sense_key, &asc, &ascq); ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); } else { - /* - * ATA PASS-THROUGH INFORMATION AVAILABLE - * Always in descriptor format sense. - */ - scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); + /* ATA PASS-THROUGH INFORMATION AVAILABLE */ + ata_scsi_set_sense(qc->dev, cmd, RECOVERED_ERROR, 0, 0x1D); } } From patchwork Mon Jul 1 19:57:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=ksaHk4R2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ide+bounces-1780-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcLS1lD1z1xpc for ; Tue, 2 Jul 2024 05:58:56 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8BFA51F2384F for ; Mon, 1 Jul 2024 19:58:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FE02171E40; Mon, 1 Jul 2024 19:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ksaHk4R2" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4CD116FF45 for ; Mon, 1 Jul 2024 19:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863893; cv=none; b=eqL/szkA2K14giRxlSYB6L27NvS0xw8L4/W115BucdqotxKcmk8HPBCHpC1TTdCsekStVc5XKOhRnjG7PY5k2238fLH/M8ZaTLtjPoucma5K44ZtPDtaK7qjPcwcQM/aKtCdr9zfMBK7w1n3YCAO5zBilH9MAjP3dTyG9A+Nqms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863893; c=relaxed/simple; bh=eNn85Fcj7KCcSuMYSdoEr0B/RTvkczi9hHJCBqhaPCs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eBf50a1DyemIzRrVGFlVCMbt/1DQ2T4onXTCqCeZUIjkNZ4fq9u+48KdCOaPf6BD8aCCPc4sf9m7ekPmRBtppsPJr6C3mjZt+B1x8323LxnIXh/3sOz7p2ndbEX70s6/E/KGOXu3datr3askA4+zC+mH4na6Nr1bFrSwhmZZwgw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ksaHk4R2; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-64bacf9a659so51631297b3.2 for ; Mon, 01 Jul 2024 12:58:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863891; x=1720468691; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NBOTiXxGTl6GNLs3EaV9yCivuLqQXgDZHBD5L6v/nwg=; b=ksaHk4R2hDVkHs4kuLAngw7JwLvOM8v6LqbFd0ZYRRAoMC5CzjyyRjlgG5QgJSI8n/ eIxfgSh4vs344QomzRyv0wgnRtyaIfL7ndVk2bpVf2qgKHmhe3CLvXtSvJFqhKBdFj/6 ucbVPxUostz3i2YZdowxhRmwN0Zz8+RTChm+Z8yUa8TqOXZiXMx+FjAu9yoX8ngJnEp0 oi/aLxypOTPq8ycetHkZqZ16/1f8rRmDDH6z+OB7mHLH/kAhi93tsAWVyA2EVOtgMI2M QUqMub9s4D0a6M6RQkvmPgjdBH/cb6CGbJ3ULTwyiyYNRBO3YNVd32kC6t4z+KEFxVYq NJqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863891; x=1720468691; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NBOTiXxGTl6GNLs3EaV9yCivuLqQXgDZHBD5L6v/nwg=; b=WcK4ZpCRF4YUfROH7Gl4B2iDgRx8MWPNQjJWIGRvkIeuESR6vy1473JEI6Wo8aXOam wKBnOuwFxkyf+5xjDOog5SxtiOGi2j0BtvINL/Hh/TsfGTJIRKb/MuVPtjPBMIes72Is ZHBKhZOHkmZIItW/l12l5lIqG5PQVX4R7gryc12Yckxte650CPzZpFh5DQA2lKDOM/ML mr+U40E9Txl1SvQNndsT6BcJCyxY9tj4n1l2VRnzMo1Gxf2+e+14iqppsDgK3ZPmNbDK x3r3CmhuNSKxXgN3vS+/r7W5vvZTqifqjwTnNuY8JeKIYmqeOOJ3DWr6rrrN48jaEA4Y q9Ew== X-Forwarded-Encrypted: i=1; AJvYcCWnKjXMaiur2kpOrnoFlDpcuFS0KjIIdNqWxYDhVRnjuPjFjTnWaFRRS/hEOK3Q5OhP7meOPqbTVzQBChIdApP4AdXcmEtL9zoI X-Gm-Message-State: AOJu0YwgJjJZdKtPfnuJeSnUl7Zr12ZH1KurTVOSeJSoZFhkasPCbEKg wbXGPnr0hc9yhI2AiFN1li9q0ZdE4DISVh9Gz1enCYdcIzl0XPtqC4zCYlFokMLO+jC+KLtYg21 uS9i3br+6Hg== X-Google-Smtp-Source: AGHT+IGGuHrEYXjyiMSFh+UBkKB6xRBF3G+mpXgTXcpxTLMS8PdCo5X5+gFF9R+5CNIc/yOizJi+4yBEmjtMng== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:1889:b0:e03:39fb:5729 with SMTP id 3f1490d57ef6-e036ec41ca6mr672429276.10.1719863890874; Mon, 01 Jul 2024 12:58:10 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:54 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-5-ipylypiv@google.com> Subject: [PATCH v4 4/8] ata: libata-scsi: Remove redundant sense_buffer memsets From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv SCSI layer clears sense_buffer in scsi_queue_rq() so there is no need for libata to clear it again. Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index ace6b009e7ff..c11ae77d3ca6 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -926,11 +926,8 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) { struct scsi_cmnd *cmd = qc->scsicmd; struct ata_taskfile *tf = &qc->result_tf; - unsigned char *sb = cmd->sense_buffer; u8 sense_key, asc, ascq; - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -965,8 +962,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) u64 block; u8 sense_key, asc, ascq; - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - if (ata_dev_disabled(dev)) { /* Device disabled after error recovery */ /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ From patchwork Mon Jul 1 19:57:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954917 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=Qpno7nQs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ide+bounces-1781-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcLl5tvpz1xpc for ; Tue, 2 Jul 2024 05:59:11 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 71CD7280C03 for ; Mon, 1 Jul 2024 19:59:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CFD1172793; Mon, 1 Jul 2024 19:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Qpno7nQs" X-Original-To: linux-ide@vger.kernel.org Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59D42171676 for ; Mon, 1 Jul 2024 19:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863895; cv=none; b=LOPS03XEGRCHgOu8d3+TNgUdMhN/GeFVuUtPQVGuU6dNEgwX0WMrsVjYP89m0U0TuPccVO1DWk7TAtnBNPtmfw4dO7WLFq/GGGMepzMuZi6nIdi55ZkIiVW+1iOhKsp/rP+d+DITRMQQ0vZdhHssCHBPShvBCCzAYDST3rHXcyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863895; c=relaxed/simple; bh=7GLjsJebG0QqRDF4wDvrP0SWART+au2lQFNxr/q73XA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IlczL8qfDosUiTe4o6AzA4OG2ANV7SOKRFtjuOR3qeEPeDQwou0DRsAUn8VMdIvM9v1TeCF1YbeBgdPz//o5+Npp8B0GClOYlMVx0c6ELa4JRGhfNNpU0RQkqSmjK0r1xWsrPhtkclEnakVxbkUZNRy0srV5/lIMB9ZLqRGlRTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Qpno7nQs; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2c7d46d273cso2741636a91.1 for ; Mon, 01 Jul 2024 12:58:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863893; x=1720468693; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VOewcSvCbExIuuMYZcC7TibLRcnuMMvd64eAILBEvyc=; b=Qpno7nQsAARmXwMAoIgar9fPByTne+TBh8pEc7aHkd/I87vDI72+0BkNgLt2Y30moX hxuMYreIRPaTrR25PT5Lk5mNpWVhHxnM3K6tGVjDIkKIKggk8VfY9yR6A4cUE2JvzhWW cOIDl5HLkjF8BHE1indDaVENCM+CHayDyjNOGGKkVsy47PhV/C5J3eWZFM125oAW7Osb jxjpdPZEhtIsHtkU9lQ5SWyuS6kPGWxMSkBdh4y8nXkU57VdHpoYWWPc9lU9qheFRB0j QZys7ouoho03Gi/PIyxfdrMq6FXjsvnviUV/rTj+e6pciBT09uIpWK32UZjlxwCxOOP2 XG5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863893; x=1720468693; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VOewcSvCbExIuuMYZcC7TibLRcnuMMvd64eAILBEvyc=; b=p3bh32/BAbXHDdPR/VNUqJN19OGKwFY7H72qZ6RG4cNBtKMVIUhqkHITtPWGkHtNN/ FaqM9kxlKs0r8wp2uGKX5qWjt+s1iQqX43ojVRukRZWWS+gjix93SDJvuuYMxd6ZxH6r mC+MNS+MYpwrBhAUgF3BK8XAJqds+mnYYLj/9hq2UxJ8B4ch8YqEOZzct0+b4V5BQ6yZ 4LtCVPBfaH9PysCndmRcQqm72b3QyePO7WxOMVu3ls6FL7XlOXktRBvtdEF6qgYfhdHU JlxXSaSkfQlDjleB+uBmmmldxjvTbL6aiJ2Ojk6BL0mVQDZp4tSB0NDfJtwTrloLx4Ke 0Jlw== X-Forwarded-Encrypted: i=1; AJvYcCW8ScOS3oPPPr/v3syAq2Xktd+d64HJEc68VGJooercoioayEDu3wS+I/0z6CKNPtnPrxOwXBB2PEHvuQGc5+A+Xwfg7n2HaZGU X-Gm-Message-State: AOJu0YxhzBezlOc1nG9IjYzUZMlKgVjbW4H5j4YJrNLMZk6VKjB7IvcE tI2by9qAC0OqKG8RjRKsA6iWPFObJ2MEFKgPLkGkF9osgetHIlCKJAivyGU7rET7xrF0rkRxfKS N/MpXl/mlhg== X-Google-Smtp-Source: AGHT+IHpFXS1KDK85fnPVcZoeeQnujmrZ567T9Vva1yNGkEdWyBDg0ywNSYuztiQHIu/rbX9opCql6t0Orb7MQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:90a:ea17:b0:2c8:3c85:3d1f with SMTP id 98e67ed59e1d1-2c9271558bcmr63919a91.0.1719863892611; Mon, 01 Jul 2024 12:58:12 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:55 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-6-ipylypiv@google.com> Subject: [PATCH v4 5/8] ata: libata-scsi: Do not pass ATA device id to ata_to_sense_error() From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv ATA device id is not used in ata_to_sense_error(). Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index c11ae77d3ca6..92d75780fc3b 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -785,7 +785,6 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) /** * ata_to_sense_error - convert ATA error to SCSI error - * @id: ATA device number * @drv_stat: value contained in ATA status register * @drv_err: value contained in ATA error register * @sk: the sense key we'll fill out @@ -799,8 +798,8 @@ static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) * LOCKING: * spin_lock_irqsave(host lock) */ -static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, - u8 *asc, u8 *ascq) +static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, + u8 *ascq) { int i; @@ -934,7 +933,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) */ if (qc->err_mask || tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { - ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, + ata_to_sense_error(tf->status, tf->error, &sense_key, &asc, &ascq); ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); } else { @@ -973,7 +972,7 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) */ if (qc->err_mask || tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { - ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, + ata_to_sense_error(tf->status, tf->error, &sense_key, &asc, &ascq); ata_scsi_set_sense(dev, cmd, sense_key, asc, ascq); } else { From patchwork Mon Jul 1 19:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=dP0eY8qm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ide+bounces-1782-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcM30VGRz1xpc for ; Tue, 2 Jul 2024 05:59:27 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 495541F2368E for ; Mon, 1 Jul 2024 19:59:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0A26172BCE; Mon, 1 Jul 2024 19:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dP0eY8qm" X-Original-To: linux-ide@vger.kernel.org Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24A79172BAB for ; Mon, 1 Jul 2024 19:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863897; cv=none; b=rJyRySbX6/LRyYUY/8+ABtRv90cieeVIn93qXQDPaS+3LTlhE3F/7CbIxZmyIrSsRQoByKWfpFNlylfAufT69DB1G0QeTF7yFGQU/pCOD+9mhzMU9Ji80nNKfg9WGrx3neQV+ZfbAtNRDHhQOQRkstuyfoB7kYd9jva6SoruFpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863897; c=relaxed/simple; bh=jp/EJgN5EJlygiYPMBnOCCu6H23x0pk/OIZFHXKB2ls=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QOit5LrKA6ohzMQP5sgvTfZdOzAnUqokHtOUywM30VCLmcggVKQVKy+uPX7O6e2oWQBAizOGmQvxz6ldDDFTezOwikVv0jWkhlcuRxw9FxOInb0CiYc17KJ86e81oG7f2DTNo+SpvDEjozVxbdG5/n9Qorc231zFUqpwxm26UGI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=dP0eY8qm; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2c7d46d273cso2741658a91.1 for ; Mon, 01 Jul 2024 12:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863895; x=1720468695; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hBcCivyF1P8rhgIjZ2/cBXkYOTDbZ96Cj7XNFUz4SOg=; b=dP0eY8qmyX0zBoQqbeaC1XpDKyeKn+jl6foQ8tPnjM9pt7MVvhy7Eak/7KLOPLcOJB PBDjS5mECuEcIw0lRzF/GZZwVcJldiQs12dfdBQxyJ3pogHvfvivE9NYwipDGayQaHE7 P+0u7d7SoLv1yMZmKnn9xUso+8tC8QrD9XPszVji3nYkpQqHBbKtW7Om93+GKDpNyrMn PtZhCJMS1nBX7KUoiu2n7bO2KSMt1ywwqw2wOs7oBf0RjzApjAHUN4muS+AYIlwvr3ko gmiJdMWHOwd3G3kkH2Gkj6mh0wYb5+9gtT/GfFpkw0zOFNQHkOygGgdtqcaPZcFq2Bk3 X98A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863895; x=1720468695; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hBcCivyF1P8rhgIjZ2/cBXkYOTDbZ96Cj7XNFUz4SOg=; b=l4Z82DkTYZloyHAKGETRS5JMreDYxbt0UD1R9g2AwVJiS8iQq1pNjN0dBE2lBrqmEm vhIlfJBR1uLnXKhJi0mg5mfbxKsVItoRPVS/QwxSoihSXqPuEpceCOrTgj5EpewuIQim rUJ2vJRwDgfEerSRJ9vTvIAJJ7orN78gj1xvFO3KYep281gSyjnYGl2K90rLfVufZc6R yCjWdHM0dCKrjgPU5mgtNevrf78e5TEnCRj6jyhNZ/njiqk4oW2grvaXcPmgjvD5kzvl uPoUCMwrTv8O8IAGWBJ3yE5fqh+WCaH29UCkFxTGT0rzBl1YoUUBZzGz0Vrcbhcy3Svq HzuA== X-Forwarded-Encrypted: i=1; AJvYcCXo6AiD5y03AgLma4o/sa+/16y/2rSIMg4j+buJarWTGjFwBW/l3Wd+WzH96tpHI/E8syKbpJfDTGJPMwDPn/5JZNy5bD91HDo+ X-Gm-Message-State: AOJu0YwaoK0Lx2QoJ2wzlzydhai7GgKRBorkWKU7CV6fwfRfUykDkqOW /O0PisVSrAI2uN1tgIh8dKtKVVnQEEvRYMRsM9RY65DbqpVL6IV6YTFjqEgyhNy0xtxG0XxmiS+ 4b6qVt3ks4w== X-Google-Smtp-Source: AGHT+IEAmoCDVb1CCwTLs+zWio2dwxCB3f8jcfxMQ9ve8CmB/yMJcLgXLwiLFKAR65sY8QS/BAMdzTKNJ5TLng== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:90a:1543:b0:2c7:471d:172b with SMTP id 98e67ed59e1d1-2c92804c405mr63658a91.2.1719863894361; Mon, 01 Jul 2024 12:58:14 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:56 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-7-ipylypiv@google.com> Subject: [PATCH v4 6/8] ata: libata-core: Set ATA_QCFLAG_RTF_FILLED in fill_result_tf() From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv ATA_QCFLAG_RTF_FILLED is not specific to ahci and can be used generally to check if qc->result_tf contains valid data. Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libahci.c | 12 ++---------- drivers/ata/libata-core.c | 8 ++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 83431aae74d8..fdfa7b266218 100644 --- a/drivers/ata/libahci.c +++ b/drivers/ata/libahci.c @@ -2075,13 +2075,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) struct ahci_port_priv *pp = qc->ap->private_data; u8 *rx_fis = pp->rx_fis; - /* - * rtf may already be filled (e.g. for successful NCQ commands). - * If that is the case, we have nothing to do. - */ - if (qc->flags & ATA_QCFLAG_RTF_FILLED) - return; - if (pp->fbs_enabled) rx_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ; @@ -2095,7 +2088,6 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) !(qc->flags & ATA_QCFLAG_EH)) { ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf); qc->result_tf.status = (rx_fis + RX_FIS_PIO_SETUP)[15]; - qc->flags |= ATA_QCFLAG_RTF_FILLED; return; } @@ -2118,12 +2110,10 @@ static void ahci_qc_fill_rtf(struct ata_queued_cmd *qc) */ qc->result_tf.status = fis[2]; qc->result_tf.error = fis[3]; - qc->flags |= ATA_QCFLAG_RTF_FILLED; return; } ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf); - qc->flags |= ATA_QCFLAG_RTF_FILLED; } static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) @@ -2158,6 +2148,7 @@ static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) if (qc && ata_is_ncq(qc->tf.protocol)) { qc->result_tf.status = status; qc->result_tf.error = error; + qc->result_tf.flags = qc->tf.flags; qc->flags |= ATA_QCFLAG_RTF_FILLED; } done_mask &= ~(1ULL << tag); @@ -2182,6 +2173,7 @@ static void ahci_qc_ncq_fill_rtf(struct ata_port *ap, u64 done_mask) fis += RX_FIS_SDB; qc->result_tf.status = fis[2]; qc->result_tf.error = fis[3]; + qc->result_tf.flags = qc->tf.flags; qc->flags |= ATA_QCFLAG_RTF_FILLED; } done_mask &= ~(1ULL << tag); diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 74b59b78d278..949662bc50e4 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -4800,8 +4800,16 @@ static void fill_result_tf(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; + /* + * rtf may already be filled (e.g. for successful NCQ commands). + * If that is the case, we have nothing to do. + */ + if (qc->flags & ATA_QCFLAG_RTF_FILLED) + return; + qc->result_tf.flags = qc->tf.flags; ap->ops->qc_fill_rtf(qc); + qc->flags |= ATA_QCFLAG_RTF_FILLED; } static void ata_verify_xfer(struct ata_queued_cmd *qc) From patchwork Mon Jul 1 19:57:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=JCtS9x2R; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ide+bounces-1783-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcM82Y6rz1xpc for ; Tue, 2 Jul 2024 05:59:32 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F1CB328286A for ; Mon, 1 Jul 2024 19:59:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 547FD172BDC; Mon, 1 Jul 2024 19:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JCtS9x2R" X-Original-To: linux-ide@vger.kernel.org Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C593B172BBA for ; Mon, 1 Jul 2024 19:58:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863899; cv=none; b=NIuynlRzEmFwlU55p6Qt7jglf0Vci8Lm2NrDUNkEuZ7kcp2SUfhxNvma0LDrqmJNHAhqlyv/wLQDO8KN8v5LZbp97boErLk5ts6npjQmibSR9Zv2MWJnMAvqnyI1zmq9SBLsSdNv5iwDC6AKu3AAGKJkU3Y+0v7dvh9W249DhEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863899; c=relaxed/simple; bh=TdwWxPt68vemC3NjLpNegwFE9LXNnMsLaGF7PK7//vE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VJcwTIYqn/0tZW1FPUvErAC99gLYZKsdYe0RWy2XWLf2ZGGysbymiIrc5eKO2EP1OF8U7w/jsi+0EhGBPZX/kkOnmq+1yskqR1SF8AWV7PwcMpQvnAVQz4TkNE8UYXOgmrYMlgbWt4+RjG+E1LKVJSGL6XT1YpF/ZiJxudiA6uQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JCtS9x2R; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-70d8b7924e7so2016544a12.2 for ; Mon, 01 Jul 2024 12:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863897; x=1720468697; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fAE+S7QoWzFH/OclA3EgmIeGcizxeFkCmPKpIfdU7EE=; b=JCtS9x2R0x7nXvkMbjq7/Mq+2+zaq/R7/Ecer4K/gfErnNAxpYOK7LENS4rjeYGj1l /5aoh51sMyBqLvHNmiMM0xvXQHI512uOBiuqPlY9rz6e531dgNyUS6Cj7FxXVHg4zWEo rjyNCaDhRQp1UVg+5k2lH1E7uHyjX7y1InJTEshYVR+ucoB8yfnUKYghI+mBCa957uoo pK7QBtPck6+OYEMGVJLshZJpKDp7c6zJC7bdk7ZvWVrL3A7xw8kFbPD5YRi0ep1LhVX+ W6zKdQAoao9Q1+6aDQkyDar3CQ42m31TQLB9xc81K/Oi29nVxpc8LkaBQqi1ZZWdU1kj zJrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863897; x=1720468697; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fAE+S7QoWzFH/OclA3EgmIeGcizxeFkCmPKpIfdU7EE=; b=Vg/ddyq6jNG3OD2uFvlHu46f5nhNJWFyITRxajmssFpFzbwHlMIMyjY6gSIuWwc6rY i0nY9VvWdqEV/wqGY2c1uXrhjLEMWY19GYYe6kXfNvD0txBt8aTjJo1pjU5zJyy+cBpO s1ip8mO5NLgY/aehgJL4jIz9zT650lpSQhbUXKZ3Pe506zgGnRW2H2RsrLhlUpySifOx hl6qP5RaBlp7GZZCQCIckGvQcH4WOb1PEX5u65PIS68dvjENnJ70Mp4u+ToxZb5rwwUI Cr4dpRiy7uY44X2FD485K2cmA+b527Wsl1Pa2SdxyJKLfcBs8ZsQ+b5NIlrXgokwNmEO P46g== X-Forwarded-Encrypted: i=1; AJvYcCVeH1VDiMw1lxUL8lz4NCyFDMaVfyYNZieydwfTr22ckvCuU2/tzncSQNb85F3uLfrAevE/O/OBgkIPdHL7rPv53pJh4Aho1RWY X-Gm-Message-State: AOJu0YzyRB4LdLUMSwQsliyPhbYnuA6fNal+vETzej7z16ppGd5fhx5m s+4TMS9/BJrgKBoJjPUxBo8iVWWpy/ws8xF/eIt5yDfyhIJgPQvkNekvGHxZivEAYmF1ogZHWkX a44MbT1eOVA== X-Google-Smtp-Source: AGHT+IGeBjcfeksNmObJJCdjEL5DSD5FQ7r2tl+wmERKHImybrRhNIc+EbJN086wSbYxF7ttUGty6fFeKxqwDw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a63:3347:0:b0:718:b441:478f with SMTP id 41be03b00d2f7-73cf2c29ad8mr16400a12.3.1719863896897; Mon, 01 Jul 2024 12:58:16 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:57 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-8-ipylypiv@google.com> Subject: [PATCH v4 7/8] ata: libata-scsi: Check ATA_QCFLAG_RTF_FILLED before using result_tf From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv qc->result_tf contents are only valid when the ATA_QCFLAG_RTF_FILLED flag is set. The ATA_QCFLAG_RTF_FILLED flag should be always set for commands that failed or for commands that have the ATA_QCFLAG_RESULT_TF flag set. Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 92d75780fc3b..a66c177b6087 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -242,10 +242,17 @@ void ata_scsi_set_sense_information(struct ata_device *dev, */ static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc) { + struct ata_device *dev = qc->dev; struct scsi_cmnd *cmd = qc->scsicmd; struct ata_taskfile *tf = &qc->result_tf; unsigned char *sb = cmd->sense_buffer; + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, + "missing result TF: can't set ATA PT sense fields\n"); + return; + } + if ((sb[0] & 0x7f) >= 0x72) { unsigned char *desc; u8 len; @@ -923,10 +930,17 @@ static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, */ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) { + struct ata_device *dev = qc->dev; struct scsi_cmnd *cmd = qc->scsicmd; struct ata_taskfile *tf = &qc->result_tf; u8 sense_key, asc, ascq; + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, + "missing result TF: can't generate ATA PT sense data\n"); + return; + } + /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -967,6 +981,13 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) ata_scsi_set_sense(dev, cmd, NOT_READY, 0x04, 0x21); return; } + + if (!(qc->flags & ATA_QCFLAG_RTF_FILLED)) { + ata_dev_dbg(dev, + "missing result TF: can't generate sense data\n"); + return; + } + /* Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. */ From patchwork Mon Jul 1 19:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=yOtzG8WJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ide+bounces-1784-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCcMW5jHYz1xpc for ; Tue, 2 Jul 2024 05:59:51 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 53D0D284706 for ; Mon, 1 Jul 2024 19:59:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 390C6171076; Mon, 1 Jul 2024 19:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yOtzG8WJ" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2B84173326 for ; Mon, 1 Jul 2024 19:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863902; cv=none; b=czuGW54Dhd0eiFo+XrGMD7/L/OBJuVEJx/KY9o1k2b5hhXkg+hmT6EABoDViMq4MwR+YjIIZSd4SBnjS7f5hbAxc0tw4KBBy3baK9xzr2dgeK0nMrNbt7zwWwsnVjp+cs/uKb47ElQ1mvudl1abb2Y/1rvQM5RSqH/PQgzANq+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719863902; c=relaxed/simple; bh=SGLDCCdcSGl/5KZWzQWNbQHDwV7PVlEgpPhtBzv/BHs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MvIFWMcFRiuTHOlAhUqCXjccoWTzIl+FOCIxA+3MLuUsXNSM1Sz9D9KfhY7fHYcFDWqgUMOt9iJOit4VctU/KwQwDvkydRb5ZnUjxShbnoUSMLcv7B80TsrR3rdWGjWXAwUJgLa8W1MB6b4tILe4mZz67+iLV90FmRMb7W/pip4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yOtzG8WJ; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ipylypiv.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-64b49f4232eso50313157b3.2 for ; Mon, 01 Jul 2024 12:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719863899; x=1720468699; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AVwwqckKyhckc77/Vm3GySk6R9oDUsxFVKO3y3cHTK8=; b=yOtzG8WJEs1vUsgqA5seVUbbZlYb7arCrMoH4tcrjajgfrE5EkEnSVhTVfOBdwpa+z 2ckXHNdMBZ0/pPkrE76O2n4Byp1ObY0+AfZ8o9oCKo/Ns6JxpzVJt7XaNQyEWnKKFYnd sV7FXQlTqKsOWOAn2kcZRAQ1apuynkiUcIm+xzOo8Y7MrjMJ5feJ7WTZSVhXV6iciwMk 8c0qyIyGBehCmdLfiYGo95HTtoBLzwqW9hJywwd4TD8St+8PUUL5bG5NpbgrbE13IyB+ MhoFaUZU0RF53nYegnbyUztzbx7zox94gw0HWMMRp6dmlgaUodsIHPtbnN2y+D62rgjy Z85g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719863899; x=1720468699; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AVwwqckKyhckc77/Vm3GySk6R9oDUsxFVKO3y3cHTK8=; b=gOrfSPPq4AHuL62q/W22VKsaFOtfEOG2vqbJCicUpE9SApTqVcLnh7SiRo9ucEQk9g F7c0VD1B9G65JV6j0uNtxlnTbC7yon5tzgKZtB/ukniLxxFcDgaZDVHL8+xSMWtAsp7p BWVjBXqo4ekiIgyH36ak+wPf5BIKl5rYFrxIHeX68T4XtqY6ILduQjKsSaPGi5bkJAew g2wHMaWeLjPrm0y60DUhM1tsWRgOG0qJjkl24DE2kFAnTDUNvrDefB4YxUfEHq7kZRxL htO/3HXTy2J90y7g0vBL8BO1C7ZNjGSivZ4Lc/rDLCdBHeSsWZJlV9iGzEknmf4l/qkI MTMA== X-Forwarded-Encrypted: i=1; AJvYcCWYQxwcpZREd+kkEggJEt3cleJeLO3BC//CDcQgWFjJySALNetVlcIADyjUCYnmdA0GqivEMpYcPWAarnSSANqDf6nm0LZ5cDf+ X-Gm-Message-State: AOJu0YxP96cnJ5/K0FL5QABuC58souH8Hq8Il2hZpJyxVshOjrgsNMRp Da6Af6n1SwjEGmY7UXVhdfNH9619IzctOS0hzIv0d51hx56mVIE6XnVjmDNZNr+c8JsQ0hc3flS XNL/gGMKZHA== X-Google-Smtp-Source: AGHT+IFUWN0zMur3c1eDEJteOuIigfCOtAjrWxujYZwgpJadqu5Y3EF6L0+M+Mf+VIqZA2gUeEINdCt1Ta4ZHg== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a81:6057:0:b0:64b:7bd4:1fcd with SMTP id 00721157ae682-64c76d2ffa9mr194767b3.5.1719863898807; Mon, 01 Jul 2024 12:58:18 -0700 (PDT) Date: Mon, 1 Jul 2024 19:57:58 +0000 In-Reply-To: <20240701195758.1045917-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-ide@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240701195758.1045917-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240701195758.1045917-9-ipylypiv@google.com> Subject: [PATCH v4 8/8] ata: libata-scsi: Make ata_scsi_qc_complete() more readable From: Igor Pylypiv To: Damien Le Moal , Niklas Cassel Cc: Tejun Heo , Hannes Reinecke , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Igor Pylypiv The ATA PASS-THROUGH handling logic in ata_scsi_qc_complete() is hard to read/understand. Improve the readability of the code by moving checks into self-explanatory boolean variables. Additionally, always set SAM_STAT_CHECK_CONDITION when CK_COND=1 because SAT specification mandates that SATL shall return CHECK CONDITION if the CK_COND bit is set. Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel Signed-off-by: Igor Pylypiv Reviewed-by: Niklas Cassel --- drivers/ata/libata-scsi.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a66c177b6087..8f21b3b0bc75 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1659,26 +1659,27 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) { struct scsi_cmnd *cmd = qc->scsicmd; u8 *cdb = cmd->cmnd; - int need_sense = (qc->err_mask != 0) && - !(qc->flags & ATA_QCFLAG_SENSE_VALID); - int need_passthru_sense = (qc->err_mask != 0) || - (qc->flags & ATA_QCFLAG_SENSE_VALID); + bool have_sense = qc->flags & ATA_QCFLAG_SENSE_VALID; + bool is_ata_passthru = cdb[0] == ATA_16 || cdb[0] == ATA_12; + bool is_ck_cond_request = cdb[2] & 0x20; + bool is_error = qc->err_mask != 0; /* For ATA pass thru (SAT) commands, generate a sense block if * user mandated it or if there's an error. Note that if we - * generate because the user forced us to [CK_COND =1], a check + * generate because the user forced us to [CK_COND=1], a check * condition is generated and the ATA register values are returned * whether the command completed successfully or not. If there - * was no error, we use the following sense data: + * was no error, and CK_COND=1, we use the following sense data: * sk = RECOVERED ERROR * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE */ - if (((cdb[0] == ATA_16) || (cdb[0] == ATA_12)) && - ((cdb[2] & 0x20) || need_passthru_sense)) { - if (!(qc->flags & ATA_QCFLAG_SENSE_VALID)) + if (is_ata_passthru && (is_ck_cond_request || is_error || have_sense)) { + if (!have_sense) ata_gen_passthru_sense(qc); ata_scsi_set_passthru_sense_fields(qc); - } else if (need_sense) { + if (is_ck_cond_request) + set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION); + } else if (is_error && !have_sense) { ata_gen_ata_sense(qc); } else { /* Keep the SCSI ML and status byte, clear host byte. */