From patchwork Tue Jul 2 02:47:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954985 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=HNkcTudQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-1795-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (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 4WCnQN17SHz1xpP for ; Tue, 2 Jul 2024 12:47: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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 8D95BB224F8 for ; Tue, 2 Jul 2024 02:47:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 278841DDDB; Tue, 2 Jul 2024 02:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HNkcTudQ" 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 6D02D171C1 for ; Tue, 2 Jul 2024 02:47:42 +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=1719888463; cv=none; b=E2bO1Z3mh6wouapv1cZMyEyWh7pUEZ2rkKd11cm8sqGmoT1/CAdXTyj+lF3SNJE34Hw3q3qIfgdGixGpagpeYqFlK1eHBGm+O4XP+vzIHyVsb8O27M9/2aOqlHuTXW0kBMH2AKV7KaKkaBGbRuY5Kc3XPl2TX++3aBkdbRPApi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888463; c=relaxed/simple; bh=HTrgxcWff1OSSYrDj5ylupNG6UKIfx6wTzhICaZOCC4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ppj156mHZwE0hoa8EUK8cpMrYqsz2MhA3+OmsEQFh4cTq5DxiKjJCxZymFsc7V14064UKjSXQpO3IAE8NthdDZSiyIHLXZk1bOENRTSFoB9v/Jtq8baJoKnamAFn2r09QSFSKHhqYgHUprQQgmtVwNiJuIPIFKoqZ41NbGrZh2U= 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=HNkcTudQ; 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-62fb36d7f5fso56610747b3.1 for ; Mon, 01 Jul 2024 19:47:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888461; x=1720493261; 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=+mbUb6G4m1uUehtvXxBjGbQF+Fq5mFzQsrUm91ddIqA=; b=HNkcTudQ67W1ugZIr7jLT10fu/hvsabY+UBGiMvwXc60jfyXsdde3BNqJN0DmO2qKZ k+M/vHm9hdxExdSRI0czdmPjh4Szr9yQSHitVSOqNJ1LZrZmoDNAM6cFscJ3qeQybx6Z 92IwTcxzbC4Hi5vA5eLOTbKdO376qgS9WVDsOX3UXZXgNwPAXLI5krd+c+Y+066LKM8r YB5fOwiS1QRy+nTJl37gR/67hp6i0iuhn8EsPpDuuaWa9itAgEyBH48lUj01h8ay94lE F/wSMXVsT2g499ewvbqIj3LeLBNpvAalp9ydkTpY1gGXJLJCFzepbBa37pN/gJej/aev SEKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888461; x=1720493261; 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=+mbUb6G4m1uUehtvXxBjGbQF+Fq5mFzQsrUm91ddIqA=; b=DOI6Nlv/g/Lbm2PAVEkYjSpvXer1NseEFtsnx4JIyCkUBGD2Zfageq/2j619Yh23rT C15sayR8zSwQ9+g2p++ZPFBl7OUTmBC3DH5aFkaBuaZ5Flq3OOH13SnOeABfSWePhIVx yJAH2fD49Xv4CWL+HJP/TEjv7mgDXwAhfaoog5kM8i6gFWDeP3nL1DoqD8GWHFT63zfY q8YyOjKmWhY/U5JXNmTqrl+0ksT9I2EEJbWr3fWFV8uqRmj51i3O4Tn/rvFmF3svKWuJ R4R/MN4JxI1LFSE9a6PBq7F8MqCx8w6MM34ctMqW5GUer8AVwL/BfL+c9btX7ILgKmtp X2jw== X-Forwarded-Encrypted: i=1; AJvYcCW3JPp0hVa77CEQ+56e7JFcqywmoS+uPrjj4cBPYLKkOMv9t+5HsUP4IDjlvl/2GrKOND+ptVL4ZBGXNRtQvw7hoNrRXVOi1Iqx X-Gm-Message-State: AOJu0Yz9MJOYKfexh6c10PLs1Euu0/7eUefk4g8n0NBFBinqgbUCIqCE CeY6TlgZnt/kQ4kX8wJeKB0tHEMXftY0qusuPvDW6uCEC8EdJa9OBiHIOhWK8ycUq6yDBEs0rJd YhUvbJtMmhQ== X-Google-Smtp-Source: AGHT+IElMlsVkkIH/SoAz+8WBYWit8jbyFBfvfQcb/6vfTSYNoTYjYrLAnrzRdUSqlDyem0nhaD9sQJFjV9D8Q== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:2b13:b0:dff:ad2:3c13 with SMTP id 3f1490d57ef6-e036ec376bfmr558093276.9.1719888461370; Mon, 01 Jul 2024 19:47:41 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:29 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-2-ipylypiv@google.com> Subject: [PATCH v5 1/7] 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- 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 Tue Jul 2 02:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954986 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=jmQNRHd1; 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-1796-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCnQc1CQJz1xpP for ; Tue, 2 Jul 2024 12:48:08 +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 1BA911C224A1 for ; Tue, 2 Jul 2024 02:48:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C72F32AF16; Tue, 2 Jul 2024 02:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jmQNRHd1" 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 0C4211C686 for ; Tue, 2 Jul 2024 02:47:43 +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=1719888465; cv=none; b=i7bMjq7Zum3THDImw328eDvDIKR2QjQ9+KMlzgSOUkN/sHDmg5PfD7RQpaenlV5DXJfMOst2Src4slJ3OH3jKqAeBsSgfK3hj9/OKE3Bk/TfI2XN+O2wXAkasrRruoZAf2BeOw4py/Fd86E7oIkv2gyIYquvJKaQVlfeyCpcO1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888465; c=relaxed/simple; bh=BMiyKMLwYO4ZPYOP19tvEv3Gb8DtBupJrrjIS0a8MKs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hVOVnjBFqBcYNC8z3ismtLBFbEeueQ2r/Xk5+FIHqqxISR2Zpm37dXyjRalvkKItK8CSHtWVZJC0RHoMOFnrmmDrUhdsNgGDjfAfhB2nQ2DwE50ijls+tR0nxNcB3k/AlEtZSEUdFyDdODcmjgIu50+v15VkPFj2fNQLRbv2NWY= 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=jmQNRHd1; 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-71bce629b2fso3249880a12.1 for ; Mon, 01 Jul 2024 19:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888463; x=1720493263; 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=4oDyu1t8Xgx68nOCglw7QJXgCM7MJOxOJdmoGHyawoE=; b=jmQNRHd1h2gdjbHaftwZc3f7TqhCnGEl9fuKWmjLdTS7mx4vUn6rhehSw3gA0fyKv0 cDaCfCbXp1ty/TsnfSbfaPdznVpq2p+24CMRhngpJYt8QtcKf8V+3KhSXaUKumUsnyKN zDfC++oauGoKaihvRUbuyGDaImK5UlW+VB5A27+9E6aqglWxpW+zXx5uB9t760Eta+d9 QLPDpK7dq0O/gB/DKqJWYDDQiJmLifQFYUm6wB3JeFTryw2Tjnr9lbY/Tfk0zubuA5+T apLxAxEuNvrMpQ502H9vFOXUohn5VV6vW4ynZ8C8n4gOx4EsxFE3wWYxOon5l2eXRNhe judQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888463; x=1720493263; 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=4oDyu1t8Xgx68nOCglw7QJXgCM7MJOxOJdmoGHyawoE=; b=FVL6mdrhRt5BspwL5GJ89isQarMPt5JqxCh8pJVC9B/1DtW/Va8gv1jebJddYFmEkk PVNcs+OA7hLQdM6QdAZj/pF+Rt0g+2+8oqLQI39bA0bNI+RMMIJ5P2IAqxqeavaP0YPV FR/br1tYTYjsfdhDkl/VOcZhJjR1dYR9XuUa+AjgOhZbNz0fSTyyl6iNeIPKzugtgEVT v5wUymXJ+m46FBBskoHj6AYlfkhc9f/AjPxBbop8XBkThFZ5DeEDHG6z8s5rQUJJHO92 J8belNb8ghXyeSbEkq2+F0jgY/BcjiKZ3k1aFL9v+sj3wgMh6Mvcgv8XJKS9BQUMSFLV /04w== X-Forwarded-Encrypted: i=1; AJvYcCUop9fJF1hf0Bz6U53SPLaFMHGwTeOzLd7vVeztwgSU5OTI8QmtwHrhF9qvFLWV2lKln1IXz5gsn7Pr9vkp7gnVptOHPg166UY6 X-Gm-Message-State: AOJu0YyiG+cwUObiVUXHG+1yUs+vEL30P9+6fkg9MdDXVo5iMIjWM5KB BRYKskA0/nwN54DLV1CvuHzOur2CFQjzefCjVu9KC34waScAEjP9oAQFq2HE1B+FVxqnBAlysvu JskRHG63iVg== X-Google-Smtp-Source: AGHT+IFBvwUGGAdmLQ5Bq25tNXwFEG7MnA2qkz6mLuAQxc8eTODP7wPfu4gagCH1EcQOqtBjBzmTe9QdVanGhw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a63:6384:0:b0:6ea:a4f3:14a3 with SMTP id 41be03b00d2f7-74ceedd8de4mr5115a12.4.1719888463253; Mon, 01 Jul 2024 19:47:43 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:30 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-3-ipylypiv@google.com> Subject: [PATCH v5 2/7] 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. 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. 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. Cc: stable@vger.kernel.org # 4.19+ Co-developed-by: Niklas Cassel Signed-off-by: Niklas Cassel Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- drivers/ata/libata-scsi.c | 169 +++++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 77 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a9e44ad4c2de..b59cbb5ce5a6 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; - } } /** @@ -1632,26 +1647,32 @@ 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); + 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_sense)) - ata_gen_passthru_sense(qc); - else if (need_sense) + 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); + 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 + } else { /* Keep the SCSI ML and status byte, clear host byte. */ cmd->result &= 0x0000ffff; + } ata_qc_done(qc); } @@ -2590,14 +2611,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 Tue Jul 2 02:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954987 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=E/y/Zik2; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-1797-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (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 4WCnQq24Wjz1xpP for ; Tue, 2 Jul 2024 12:48: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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C052EB229DB for ; Tue, 2 Jul 2024 02:48:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A0B0381AF; Tue, 2 Jul 2024 02:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E/y/Zik2" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 D6E7F2B9C5 for ; Tue, 2 Jul 2024 02:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888467; cv=none; b=OtX9Lvi+L+1CZYfnHcq/Onma9B4T8gEMc5r4K0SG0KfFv8NBtXd4ZA8kB1UUDbxw63F9Wkh6qMOEC/XzfQOxfkk706FnIZS7RM4b3TZ1CG5rQvKPpFhH000tPfzY8CmeYwhzyURpn5qvum3zJC3L2WptZX7WMdqzSt+nbV8mcU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888467; c=relaxed/simple; bh=UQZTNgxuo/nQ4A40i4CKkg/R6rQqJGLMQemrM+QDYEI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=koWYU5OZ3i05ftXYcYU8Bqf06ymu5eio2o81rkZ5R7aGNcCAQbZ5wmfMvYF0Vp4WPQRNJhi3lM6kSmtdM+FBLEIE1DcbT8pN5xEh4FphDRRAWFSwFp6S+xvYYgUcysOU/epuDd/2SWP0ToYKDKbOVyukGNuU9rffd83VTxQyjYk= 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=E/y/Zik2; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02b8c0c2c9so6700812276.1 for ; Mon, 01 Jul 2024 19:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888465; x=1720493265; 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=w00QSz187T1KSvOH92zkWn3h1qrakV8FNdVfs8AN5w0=; b=E/y/Zik2Y4fQQm2Xc+17rXiBV52nI6BWL3bE2wodmL6A1SnHxUTMAnDhCsdta9/Z+0 gtcF+zEmEe5DHYRcTR3iayRrwdTQLUm7sHYeCMFsOsYjUQ0qzLLpArqxJTzfFpBdPt0c VXryAc162Y1wmcsEg73UP48XQq8E40HkbYIZJm2qjEi8yXVvQb/jLvngKeCoxCHr19M/ 20mxqtxEX+6yogcMVoI0fbIYhky2v+6VltyJFTBNov5pxdXnK6F8H9oel6D4Be/zPtYt pRcVxppH63gMfpsf0STrMdG/mS/oG/fjXXErZ5+LAKwX0sX4fLFd7QGXRozrve17W7Kc IFkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888465; x=1720493265; 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=w00QSz187T1KSvOH92zkWn3h1qrakV8FNdVfs8AN5w0=; b=Lq4BBwpcUbipq9bEBR4+wzAKHRBihNCdV32EJMRJIALag+pI3WuU+CtYZsnO6VmeVn nv+V7E8bcAOU4U5Sug57XJDOE7bsJV6SIhoWHsYtOIsrf2gOmDZuneKDm49vP5oqAuOz VhyWankpVmmSIk64BwyTnywESkPq6Y8MnUnQnSQ4xw//ascRDcTRntWs6L5yrmTRNsqZ /jFexYk9ZRuEMnxcUARHU7R3PfOdyVe0D0UhlZ3Bn3WjbHdne0HEHBcoPjliPxxhKBAd U2ExZueXG1Zy1cHkdlQM++LnivjpE+UEoRrAwVTuS3B+GVgGq7+ehi0FHqSWGAs82DY7 Xi8w== X-Forwarded-Encrypted: i=1; AJvYcCUUZD2nKd9I+sB3P0CUmfRxFevLlMsB7gbUno3lS65ZtoZOeUtbm9FGSAmcFlxljhaxkr7qdwPmpsQTlynBYHs1xXqh8GzSy563 X-Gm-Message-State: AOJu0YxZRWlTM9PTb4HH20N++c6THu8VNaikyalTh6OdlY+UOKbk+bLh RRSv0wPuuJBYPPIS9KFyYHdwvIjVbWi2l93K2EAQPTJJr68RHkCmm4PfbgswB75Jt5vUZR2BELP ltb1hNpgxwA== X-Google-Smtp-Source: AGHT+IEvUTFIgKCzrTE5ovL08iBb/D3RskDQu4+yIlR5yKTtxFavno3Ikw8Oljg6ZVkQd+fpyujDnQ6yQRlZtg== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a25:9206:0:b0:e03:4d2d:b0df with SMTP id 3f1490d57ef6-e036eb573b9mr201128276.6.1719888464966; Mon, 01 Jul 2024 19:47:44 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:31 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-4-ipylypiv@google.com> Subject: [PATCH v5 3/7] ata: libata-scsi: Honor 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 honor the D_SENSE bit for ATA PASS-THROUGH commands while generating the "ATA PASS-THROUGH INFORMATION AVAILABLE" sense data. 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv Reviewed-by: Hannes Reinecke --- 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 b59cbb5ce5a6..076fbeadce01 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 Tue Jul 2 02:47:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954988 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=HWDOynoi; 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-1798-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCnR230VWz1xpP for ; Tue, 2 Jul 2024 12:48:30 +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 54B371C22469 for ; Tue, 2 Jul 2024 02:48:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E15E33F8E2; Tue, 2 Jul 2024 02:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HWDOynoi" 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 5F08336120 for ; Tue, 2 Jul 2024 02:47:47 +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=1719888468; cv=none; b=VPZdCFYmAMqYcxWRHJ3KMYXTTSTDyQFedomKb6UYQpwamrZEF9qNZx67NYy8wbj+SY0nmjZWSKkV3fDgzX1UuC3LdirHenz0+a6EdmUpl07t3USugIE0Agg/I2chf7GcJo3C6jMYLi1y9JWeS9ZuAOYdFwAr8pMkueqKFq+WqFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888468; c=relaxed/simple; bh=doFIBDqtTa5Mu/2uxDG8Al0PrGigMDt7dbzK5fiISpc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dUyWNz4JbfazNhu1EzsmQHQJWjYQHY1iiDrGcfMgh+AyeZgQwKEk6/y5JKkBiUzHLBn5Dqc/NSytfxu4Tc5JUsgBGdz0WQjUZVe1B30oJ1QiCJGtkXqdja1AjoUHGpTZT5uqcwWfkpQgPZSjkRHC3rXZGc4r2SjoBRUiVvrDzOM= 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=HWDOynoi; 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-7065df788f6so3369739b3a.3 for ; Mon, 01 Jul 2024 19:47:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888467; x=1720493267; 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=vWYD3CFi0xqKyZt66+JpR9ECkv5q52fY5lPhimPSxvE=; b=HWDOynoiXExHm+o81NswJuT6jt4dLHJkGrzmV1J/1fgAlSlpzd1sJqH7A4I7ad4p2a XMpdTZGHTKo5/LENxLUsMgUvcByS1uLIt7ppT14U3+0b5LanWuF0CxVdc/3GSJz07iP4 psxGwklnYhrRrfSNG/Dp0AGEvPgjXjNrJT7tvy/cDAjXx7xGlVmP3yB6IVfuayrh5o3M I9ZneRMpTICHUozu/qV/URgyBkRM7YPSn6XEZNb8bXlgxyjAX+gclQ2oIdio7TBU8+hP dd+Cvq84YidQbU6+90c+5sSmnLOJxXL37vDErB2EyZCsL2lM5gk31/qykiFi+vro3MV1 8BQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888467; x=1720493267; 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=vWYD3CFi0xqKyZt66+JpR9ECkv5q52fY5lPhimPSxvE=; b=MpuTRFsbC3TCoDdrwLIJrwYcXJmQfyytRhgQ8B0CNKY6ZNHU6vqzojfNmwlASOgmID muVin2afnNVYiFVpcCkSUQCu+wX0otClGe/PsR1oyr8Se47cEmSTBZ5YZ99l5M2x9Mwd Ygl2FwdbNLhfqbe4VvrqPjP0hT4E7NQ4F+9LmvpghC7eiTv0veJZdkNDGXPPe5bOR0Ib TLbMu6fJ3oq2y5qSdmggpm6I9agJmRQ/8E6RkYKGAq1qx+KmkqHPpUMW1gKSY49NZziK fvN/x0pIHl6rc8lxw7RqVgxmErLlxAA7AF0XwmAGss/pTC8DrxO5bDCxnIpPtVXEPuzM WLUw== X-Forwarded-Encrypted: i=1; AJvYcCXiSNWl2IFo7TnEELshpXXM06Mr9JGLmw8GnxWZVgTlgpnF7RpMWT8OMaj1p++ecUy0PC4qW2cHthAW79h+AsSscyzugtJjtZzy X-Gm-Message-State: AOJu0YzkRrJky6yf8ilGBHlx8guHxuK0zX36owzql8os7kLPkwKseBcG PWMMMZnDmQPY2YictASWVzOIg42JUGDjrv/v9CjlVK1y9WqItcN67zwW3ou83HUmcHHtPPSyO8T RfR7jQ81MlQ== X-Google-Smtp-Source: AGHT+IEnUZWAIySfE2wBFSt1tDNvCahMYriM4Y6yt/rtcfr0+yUwTcq1HyF/y24/NusyTaAevhRKjh5UEFw5Yw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:1304:b0:708:2033:63e with SMTP id d2e1a72fcca58-70aaaf6e482mr474635b3a.5.1719888466711; Mon, 01 Jul 2024 19:47:46 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:32 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-5-ipylypiv@google.com> Subject: [PATCH v5 4/7] 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- 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 076fbeadce01..145319874c1a 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 Tue Jul 2 02:47:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954989 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=FO6mIwiX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-1799-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::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 4WCnRJ6mVJz1xpP for ; Tue, 2 Jul 2024 12:48:44 +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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3BF9CB22415 for ; Tue, 2 Jul 2024 02:48:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15094179AF; Tue, 2 Jul 2024 02:47:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FO6mIwiX" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 5D21647F45 for ; Tue, 2 Jul 2024 02:47:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888470; cv=none; b=NqiRrhL8kzOi6bHpEBYDOCUKfAb6ilzm/MFoZntht6/kjDmnIlr1td5kMvJ/szcG0BqVyLKgzEajXpeaL7MM6KaiJrbGzxwcpznejCsHq7+3nPAbyz9Su1l6txUvr6C8dWluTIqH+VDMgULCLjhINGq4N/ZPKR++eZ/CUoRNOGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888470; c=relaxed/simple; bh=6q2XtXMfjJDSePaQ2bcHelVvF3WWc13ttlQWb34qK9w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QF6HNmqDV2nPwJc20gzm4eeTxzBwWoZ4A976dqkpx0YKoKpFPR0AQ2K2sQUjxgZp/VCMhOn2V85PX4qyXOpG2Z0afq01/wH8lxCyr2mx4NPUZTuEMigRUzbDRqHEUvtd/IlEDYHxJ43Ny5vyWQr1+y1WKB2BMmpc5vsAIan4ors= 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=FO6mIwiX; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-e035f7f715cso3684807276.1 for ; Mon, 01 Jul 2024 19:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888468; x=1720493268; 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=xnHqVDC7cuQpLJUncoQ6Ep2IcWycGGYxv6pv9bVVUIw=; b=FO6mIwiXsrRJ98UYgS22BYCUAIrahYfdjh9wlDL8uHwe95r4lriQIzfpbJr/YwuoBV gN1X57PuoOSqRX4gz++zOREuqTpWQRTIKGWnMeCepk6OK+l9o3YtiTDYru5zJ6pXjl7x TPOXRDF61KSUf0pez/frw0QDsR6gB7PQU3ckRXwUtF7oX5vUENwif46XXC/Jxq0NzTna yKvEtb9equ6KO+ZjqRFPdDJUC70PatIf6/VUFm8D2g6fbaTboQZAzi0bT7oWk9peXG9N LEpQd/VeXXZ07iy1w28Q8AwJhC11gPwoM8+8GnoxzXvcnzAiD7Nn9iY0AFESLZnz3Qdv 8tmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888468; x=1720493268; 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=xnHqVDC7cuQpLJUncoQ6Ep2IcWycGGYxv6pv9bVVUIw=; b=g72/RyVNGoF2keNZ/mtt79chrw67iacz+QajVffC0kdClfOfKFO/cMMJzDPf5Fn1lf zk+kJp4EUpYHWrtO/Qc0dcHkI2Gxprvek4T3cVpRn30o0fx1qq/To3JFKe56fMLq0fGK hk6Q/eynMq95B+m9k1A4l8yiqUS8D2ZdlspOiFizDolDhuIvHBUaJtbI3+iVcr7PHRj1 VIyc158M710iXInhizRV1TYW9tAO/LGJcgT47yaJj1iiRS2U4MpmOOkdLOEHIOrlW1yD GnPIx5b4dpUC9xip3fbjHpty9EoNbrMVf89tE6MSz57fFsVarBxp5AS1yMeC+TondFZw +E+A== X-Forwarded-Encrypted: i=1; AJvYcCUDDscezOe2CTOAPPo6/CLP49sEsCL7HsCQEs66lq2e/6d4xpouilAerDHqnWe1y7ewnhXcbhq77XRsfLhsHG9BBcf4nqAhdlft X-Gm-Message-State: AOJu0YxWp1O78AP7qRrpBlrPWDJGbKlra14frenHGVex9MBkx0Lv2RIu z8aaLrr/uCpwGJJqBTqYV0wqDTkuys2+15ZKU23R/uqtx3Fjmg1l/r7NVd5lTOVVWRzhu34IVTy TE6Xy1Y2T8w== X-Google-Smtp-Source: AGHT+IE8BuvEAubldm7affIT7w5nUKEMKVB8uiyHBceDURelDM4xrZugLTZA2bjl0xdR+Tk5nDY+2O8OWgfkmA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:f12:b0:e03:5e58:489b with SMTP id 3f1490d57ef6-e035e585039mr152667276.3.1719888468352; Mon, 01 Jul 2024 19:47:48 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:33 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-6-ipylypiv@google.com> Subject: [PATCH v5 5/7] 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- 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 145319874c1a..226a36c9504b 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 Tue Jul 2 02:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954990 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=bRg7OFZm; 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-1800-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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WCnRV1gNjz1xpP for ; Tue, 2 Jul 2024 12:48:54 +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 DAB8A2847D5 for ; Tue, 2 Jul 2024 02:48:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FF7C76F17; Tue, 2 Jul 2024 02:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bRg7OFZm" 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 C654A5A0F4 for ; Tue, 2 Jul 2024 02:47:50 +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=1719888472; cv=none; b=lSwC3Z5CliamRNJ95gAh93MvfiiagQZDLajbujCgNLjcY+hMer5hsvEb5QBVZsq8upqbJnhE/sE6tAYoz9EHTfz0ftSa39sBJwFPQMAKv1NB05EC3693z//B1MXNJefRLOTBExe/7cICEqCQLHOBSzqN5O63u+Iq/XvtBm02CFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888472; c=relaxed/simple; bh=armYVp6bALgwlq3EStO19rEjX4MhF4wYcg/Vy9Y+1tk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=dmayWTjwNH+o82S3mJ4VR15KLCwf+j+vY5m6Vx4qQrHbyvqjHwiOxeTh2ynunuLc/IMiGfd41JeFonhPouG+CEtPRvYe2/3qGWUeBE/GArSlTXaaSDtgnCRZMz1tQJAzserOJUSvP73RrOiaak6c8SOhDp4fme5gTVhou/lKnBw= 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=bRg7OFZm; 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-706a87c62a4so2528843b3a.1 for ; Mon, 01 Jul 2024 19:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888470; x=1720493270; 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=FuQ8E2r4ig1tVpjaudUDpj4znPX45jR9JD1FPJMHy0c=; b=bRg7OFZmffSqCswrGWe0AU1LRYEKjnQQGM9hIYF+L6zlczUS1b8QTENjMbyySA2mzu /+OGySHjhOFbPNmR1DHFxH+WPaN2zxWarwS7PjTuxKhHiyVTRFvkjOQYR4o9tOzH3/fG tC0oi146ZOL4YvR9XUJmmgUtRUMY2Ciq7TaSHH8yzH3GYCPHgZts99E7DJVOCj9fQT1f KZ8ZMRrGNXoUzv5CoK598TL0e/EVmHfp3tWxtg/TGl1gd4LjVnm80QNgg9152yV+3bb5 HnjrhfFUEHJHgNUx1P9/Tm6vkmHHMdOYPuNciztMKlFwRwKkZ/GvY+gqqcZ5OM1KmguQ 1UqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888470; x=1720493270; 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=FuQ8E2r4ig1tVpjaudUDpj4znPX45jR9JD1FPJMHy0c=; b=EbOvMYqHkxMlvozQD3QoKXpT/VXHjxaLpcQVm36Dm4r9w7TK+k1YNSMpTBW73IFVAC Jno4T2cxfHSGHab9aJ4y1rDPHUk28S+Qmix4h5TPzdu4dlbsFagQazHp7LhqgHZfn41j WY3IvCbFHxdT6sW69Gy81tVrhw55sefyzjnN4fcMU3MAK7nWLJV/BSXyRNTpQksDVo7I FGvLXtUZkmt3y3WvSNL5jRSHqBmHY64OczgQ4HNj7IzxFjm820OgwhAJ6VYh4UT+k3U1 yAb5Kye9hBuIlcizc36+jlkEIkyi9UC05pGDLLcJy11+PUiWx7X8IpE3siNj/r/9U9V2 Bxqw== X-Forwarded-Encrypted: i=1; AJvYcCV3z1WAFadqwuNNRDZ0H6eOEok7wxl24AzcNksTRO/Dy/dd+6MEcOBF1DTsXEfgC8Qrvf4pFVlHzdqzgYV6TgQQfbltiOUiD6LX X-Gm-Message-State: AOJu0YwTWV4EowKy6UUPCcA+SYjN1u9nXU00D9YEywA6GJb+PmX9JU09 +KRg3iQ79A8TBt1Hn6MhR1cSPjRiGubDGVFLYCZoRyV2dYronn6YYEEkDuLA1sFNC99VW2gPNh+ rivR7uK7ZDA== X-Google-Smtp-Source: AGHT+IH+lL6r5VzGA0HxS1DdbBK4xw6ZsH2Sc+qAySIDyF6GkpVg26LKJoL3DppsDXBiRCJiVxykE5vl471l4w== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:1255:b0:706:6b52:43a7 with SMTP id d2e1a72fcca58-70aaaf0e3c0mr296701b3a.3.1719888470043; Mon, 01 Jul 2024 19:47:50 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:34 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-7-ipylypiv@google.com> Subject: [PATCH v5 6/7] 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- 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 Tue Jul 2 02:47:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1954991 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=j+rm9ksd; 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-1801-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 4WCnRl5Mg0z1xpP for ; Tue, 2 Jul 2024 12:49:07 +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 9B7461F21D25 for ; Tue, 2 Jul 2024 02:49:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 19B9A8003F; Tue, 2 Jul 2024 02:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="j+rm9ksd" X-Original-To: linux-ide@vger.kernel.org Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 7552C77105 for ; Tue, 2 Jul 2024 02:47:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888473; cv=none; b=NAPxJexTKlh+hSd6Flp84UF5Hxk0SvBHBcVxuD9w9ZiG49twjFNWC5bZTome3TxzKPjjKgki0B4ZiPsn6w08pIdMF3cbK9xX2M0dIqGaVOW8QUiNvG+O+U8Ff73xMtM+Kkab8qL3ig3EjSqddM2RMyn4QVH+iXXB+dvJaJNg+dU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719888473; c=relaxed/simple; bh=DNUVAyv47k38434cyzshYGZfiQCUuvKrQV4LMhKazxc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=boAxflj7mhOWDrcO6sYdHBrXbkElSZlfOzVloTZlx2KdZj4B6erA4ChDxNy7nRaRL4KuBoadHoD1W3HieetmDN8f/tKulxdFmbAWtD7SG9MJDSb4TTPYN2T2wO32efCe6+pPcALaXcT336KL+cF/hUSHuGkjKj3HEe1B9da/5S8= 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=j+rm9ksd; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0353bb2fecso6763802276.2 for ; Mon, 01 Jul 2024 19:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719888471; x=1720493271; 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=3MNHowcTUXzmf64pvPdyG2MLqdUXcPdrWLseGnurKJE=; b=j+rm9ksdzdgSAUbKc/pFbe+Rof518Kmp5lV05UDJoHNHDQ43//QoDdeMFDnzxZZ819 pKz1ccJuz1MRQIkNQboL5Txyeb6KZHCxtFC8XLF3+WO5ghpQze4dheHb0GZWuBpIWaZy 23QmZgPx1OmqyZCF92gaglnJaB8m+hHu5bWX+CmsLefjNFN9KNmyorJvExjuHb8PEmfL 1oMbUOhwb6Qy86eVAtebekL5+Zmf+xux2ZSOmJsra15fC+PoOWA+ij0KcuPJGtHg4/NS FdyPZVTIWQYix0e+wSEWeuTR5cATS3WnAC+gMupmDKHB5d4ijnSorr21AELjYS/dq9bA L7Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719888471; x=1720493271; 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=3MNHowcTUXzmf64pvPdyG2MLqdUXcPdrWLseGnurKJE=; b=rC0NgLo/6/+JnhhNPG1Bisz9aIij1lL2sB4Uw2ZPhhjIVh+0XoqNX9dgEdEVF0ADbv yV9emWPRn8pJC0YEuuRkFtj0ze3DlD/x8IRJAIMsEOOUJ12Tz8zPJQOpOTsgdzGxGwMi ztw3xGiweG8HaRhsElzzouoqzr3hRum+8gCKd0YuPQVy0+wiTEJTJlZC+og/MohamLpm JVw/76PMLXckAD6vAmTn7K7gRYVyQTp+eLJHHjwTDy25s7hzVE9n9TGtXNhZqc5pj2aA t4gmblyST7D0WmEQSAngGsDV8RhT/SYzwZkNGQep0657qZNKJ7DgsUoBF/sieTH8RoDu adrw== X-Forwarded-Encrypted: i=1; AJvYcCW8rdNZaQkL/n4sPbZ7pQYg2xtF4E9UP7YzJ1Idelch1DrHHwZ8frahPxNz4sDDm5WDM0TRgiHaPOYW1IsazPeNT9EDfxLAr/mA X-Gm-Message-State: AOJu0YyUIYP913DbJgC8Y30+lzGFfnWUhqR9H3S4rXI7b6YvzTJRnDnC DXb2OkqUZKHAJBolPH2UNggUVnLFf/ujguFdzjK4Wf0XhB4hj7TXVDSNJ10AxqmylkoOVi5u/OY 8p9ZCzFBk9w== X-Google-Smtp-Source: AGHT+IFI/SVSIyN6BwKOfwv+gERTLL4AsKvZU1MITQc3NOrEJnH3r1eYrd/ssXsWI6jJqzXGObMENfBEDs9jVw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:2d91:b0:e03:250f:c1ee with SMTP id 3f1490d57ef6-e036eb5e687mr63261276.5.1719888471621; Mon, 01 Jul 2024 19:47:51 -0700 (PDT) Date: Tue, 2 Jul 2024 02:47:35 +0000 In-Reply-To: <20240702024735.1152293-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: <20240702024735.1152293-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240702024735.1152293-8-ipylypiv@google.com> Subject: [PATCH v5 7/7] 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 Reviewed-by: Niklas Cassel Signed-off-by: Igor Pylypiv --- 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 226a36c9504b..8f21b3b0bc75 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. */