From patchwork Wed Jun 26 23:04:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952825 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=BnlfWH+k; 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-1692-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 4W8cjH6jhSz20Xf for ; Thu, 27 Jun 2024 09:04: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 6137C2831E6 for ; Wed, 26 Jun 2024 23:04:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E04E1940B7; Wed, 26 Jun 2024 23:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BnlfWH+k" 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 75C27194094 for ; Wed, 26 Jun 2024 23:04:26 +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=1719443069; cv=none; b=ifuPnIi3aZWARST0vty+huty0l3N98o2a3/awUcOzXH8APZ12IR2ADHPBmUHrHsvgqpG9tBCtaP9ZGszJR7ISJLeJhGJv3DbCer1jTWXx7sC9BKG148tctByW5P4qauwxenRws6kKrgdPN1HZUxJj+wn4kmGvb+hslHWIHX7mP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443069; 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=bo/0fjEZgusi1bcRcwR/6ddbWTlyXhTC8iKwQe5rTWe8OtYVp8X+rTeSzZhyN/c6SRCybtN9CrBHXmsaCnTqYNDcGu448gaMgFi6DqdZWjW/wvdRkJl/rXlmlSGbWd3pyw3YVd1vu7anzerx4Ue+tIjB+uuGBd4CFMfwVmP2RrQ= 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=BnlfWH+k; 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-70673c32a44so5426238b3a.1 for ; Wed, 26 Jun 2024 16:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443066; x=1720047866; 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=BnlfWH+kh4pCSzSEkA0JamA1/YmsqWcYd5476OH6k4G7l4Oblp6jxNxDyr1zeg9+0/ BjeTM+s9+o0NhMPcINf+RAl/e2ET2gVrDoCcQIIIUymr3MgS3gBSjufDy+OdapotWTG2 R6Gbk1DdvZv78rNwPb72ZcqORnjPibBYuWePHXQNbNBPa9ISpYp8knYKAYSCH4Fe5wCd gWfEor51PdTw1+Dsj2iIaRiFovVA19YmTkm7VP3H+hGDn/CMb01An4gqY/bfsQ82tPT+ 7MG9KazcDzqH6PpHM3JqjSBXI6iK8x0bzq1xpxUZxuz8aXDZKAQ6AbnFZ6JTq3oFWh7A jiog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443066; x=1720047866; 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=W2wv0FjAqCrDHZa38JU4XU8CGYKGR/n6eBOlfWn5v+hdHSGxYt7Afpn3JUpcaS6FlE +Gs0Yt6cJ4S+YlwQS5pZ9TLIV3tzz2He4HekE7e2Ta//F1wzmLiJSpB2wYS7KL4RowoP KX8xZ/q58RF6sKJuDE6CljU36K+6jV7hvrJ068VdjFIeRoITbdh6GNW3j/Gqq09Qt18e cUfVxojVIldiKTIbHzsHDWhk3wbfb8iSh+QCmabEqhBShjD5TbNC2/LCDQBtepM3IyKx W1OFv1nSJdK5CDm+pweIJugoKG8XLHShCQAQfTqcZ/SIC9BXET4hu6FXBGBt0EhMDbeM qQzg== X-Forwarded-Encrypted: i=1; AJvYcCVyVVhkze5IpgKI7LiacE4ZWiRcowwVSpOQPBPNVPbeSBCYmumRfMZOok+VLFC6pzXPS5izqKHnxGgv8KvzXPswltEcto814gxa X-Gm-Message-State: AOJu0YxzW0ySvtr19iW6VlErXTVQNiQFnl9Klu+RLTY3elB3f9dIa8JP LQFjD7meMWmtq85pfWRjRwtVLCZv+i5cNOgXtvNYEAikyKu1JUu+qXtfER54HUyQu1Ln4E8dAKU ZgzaK+Fm1fg== X-Google-Smtp-Source: AGHT+IHvsNwVLyqt1nlHJrNX+JOFz8qm6kONJcbmJ7hVLToZgq5nwNwp7+9RQ6WkWCM2moHWG+jhCkeW/hz4Og== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:3319:b0:704:2cd2:7822 with SMTP id d2e1a72fcca58-7066e721059mr108308b3a.4.1719443065577; Wed, 26 Jun 2024 16:04:25 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:06 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-2-ipylypiv@google.com> Subject: [PATCH v3 1/6] 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 --- 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 Wed Jun 26 23:04:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952826 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=mx8v7Sf5; 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-1693-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 4W8cjS1NkNz20Xf for ; Thu, 27 Jun 2024 09:05:00 +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 2E8801C22144 for ; Wed, 26 Jun 2024 23:04:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CDFA1946A5; Wed, 26 Jun 2024 23:04:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mx8v7Sf5" 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 4168D194129 for ; Wed, 26 Jun 2024 23:04:28 +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=1719443070; cv=none; b=BdqhDySHFBlTUkObGnwrbVTDIKsDyBmOX1/Gptctvi3th/+0qgEKXZuj16lZpG/rEGkGebLnxXZJWlhfsFxTPqVt+GwWWGSa9J6yz1epcKOvwrbiaBs0VHRsWD3XltjJSDGnAhyvEjjyg/wUTGNUXN/mqfHqdgpGGXQ206EPwbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443070; c=relaxed/simple; bh=X36javU244m1Pe7Nm6RJMAr7OamOkUPb1UbNIZe4cd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=W3z/au5q26WfoVnW6i6l04wiNK3b/2IAD9iEu4AAcCH2hU/FKnJpmFfoZt3itxzyjjg+5jJ+FnNZfnxT+8MBO2DYfCVi1yh9ppmp0J4l0RrHbfbncoBkmYyDSyP8f92UDwxdWH2cK1r8ekwE0l1RvF87FzrpawagkXJPcPm4KN4= 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=mx8v7Sf5; 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-6c559235c6eso9412580a12.2 for ; Wed, 26 Jun 2024 16:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443067; x=1720047867; 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=jYTcox1uxiDsgrgstLUNMompUZVUnfSZPE6ZrKVubcY=; b=mx8v7Sf5VSZ/raWU8yjyqdOgcCg0xNkuiNr2Ez/PP56TT6o4zPZXp6pI6aqbYYRLjX kKF+FBeaaDpAgYh9YuJo5zrJohSnorUnkL0uODIG7J9k7SMO8JocD5ekS37UTHC4DFvc 207j9SpkKOtMcjI8v7bLNb2Wj9WKQ+IGyUtOe9ud3qTucj9VHiNZz6OrMeaq6u0mRs7U WB0+iQUkNhbi0eVhK2c6yPbsbE91AkDOrlesG1Xfbue2QddhU8XVVdEDyg1B7CZJubNY yGRIWWMMY8aoYee4GxbFkXNx70R5VHp+CSdM+Veyo/vkqlmw+zVMSnOaOb5jhvyU3kRT UwHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443067; x=1720047867; 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=jYTcox1uxiDsgrgstLUNMompUZVUnfSZPE6ZrKVubcY=; b=syj19e536aKMUp+/1Gu7tr7rgm/KLfBCWZA/jCXlTQBDbsbV0OYYRcvKC4IAYBpT5i YT+CWWeqqB1buJkZKXMvnr6aCwhK58m4FgsWQjdotAPzFh7xUlJWU+OLwhfSRlvFtM8y bi0k1cQ7zTEuy3ZDe/kksCsyFOGSHMub8pEZjOXn7YyjoWZTiVbkrn8Qi/Lwtbw+6oot U6nhESfZ0FWKwXzqaWoFeHuVZKezY8vEIGQxBMBa7JFqqEBGVjXwGJ8U/sip1h89xJEj i0RaSwOIcu09NCteOCZDS+tPLfzevwD84DJp1lLzgrwj9q3Y1uhbEawOW6qnTK9HJCgi 4uXg== X-Forwarded-Encrypted: i=1; AJvYcCUHwfevLGVuFiIWfsShFkif9/BsFMUuxHAhf7p4dTePlf1tMTY/U/25nI2keeqXyTW6W6smGIJZ3fnSKJSSwIg2Ex4uY5cjUBcb X-Gm-Message-State: AOJu0Yym73iuQgUSarmVZwOP4NihO8dMh87jEP54PFobXWxXUqRpO5H1 Rnen8vZVq4nx6e92uj/PXjZFOZNihTvy3o7/ji7V+InM1rzJQAhCAR/pp4muvNsbVBC9NKRcy4f 3PciUFYelnQ== X-Google-Smtp-Source: AGHT+IFovcMZN+k505LVJQ0M7+wE+Qk1gQ7CAGuZCVOne74Cr/uZsi84LMT4f7Jo9RaI7qWgiK8IxZ8+6US2HQ== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a63:3d43:0:b0:71a:1f6f:1d0f with SMTP id 41be03b00d2f7-71b5c3db10amr29716a12.6.1719443067521; Wed, 26 Jun 2024 16:04:27 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:07 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-3-ipylypiv@google.com> Subject: [PATCH v3 2/6] 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 Reviewed-by: Hannes Reinecke Reviewed-by: Damien Le Moal Signed-off-by: Igor Pylypiv --- 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 Wed Jun 26 23:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952827 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=3NyliBBX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-1694-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (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 4W8cjZ6xt1z20Xg for ; Thu, 27 Jun 2024 09:05:06 +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 7D6F9B21297 for ; Wed, 26 Jun 2024 23:05:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81ECC1946BA; Wed, 26 Jun 2024 23:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3NyliBBX" X-Original-To: linux-ide@vger.kernel.org Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 E5F37194099 for ; Wed, 26 Jun 2024 23:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443071; cv=none; b=rHigrRA/ugiA/qkKLD+oLleAK0muANDNi7dHbOEk8xnql1euEFC4zvC6DcQTB6LyBXgSFUW3O0i6Z+jCcygVn43v9dXN2BrRAWzPzlyCcODwNvcLrH8eaI4yq9Wji6SAGsv5brQvwoDSlC7YS16C8kGUPpltJ1EO+upNDO3VnXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443071; c=relaxed/simple; bh=QOUE3m85wg/4GIuezGsx91HxmkwAowzlGh5n1SnE+jk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=k5c+ec0RjiQb/53ZAZCYhNj6VCOhDLeVvndntLNgDbYgGqOsMzWjzKIMwmgfHX/18E/y1PyziSgFvynqmBYwdVuUV1VG2oRTfd0EiiPWwJ2AORKhNLhsCalRkpXSi6rV6YLy4fXh+3+1+Pmmd/2Up0nANEzAyqDSIoWtV1gNevE= 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=3NyliBBX; arc=none smtp.client-ip=209.85.214.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-pl1-f201.google.com with SMTP id d9443c01a7336-1f6174d0421so79516005ad.2 for ; Wed, 26 Jun 2024 16:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443069; x=1720047869; 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=WRuxhaMQ+1lW78nuyDa9Lm/q++gXoPPs3JwtC5y4GFo=; b=3NyliBBXP/fMKNHYsdd9Rjno6iYeRXJ9Q0JR8vH8xzdYYZbQo7ZIN4jVnXAQwNL5N0 GXiVIpz1DUDINdc1ZHbfDtOQId92SmFdjl2FuR0fYCCm/rDcaFuiRUyjoPNUAlXM2vEP JhGTCoPf9gqLqZx4l9fupbIcFRdFn9FnPawUsw7OuTq4VgG2g7iKBnEgBk6QfksEQuYr Em132c68o7KwcGsJnYp3fnkh2MfiUKdnIkaGVu0FVwZ3+cj/+BRFSbWTKJVXtq+cXqbA bQitxYyTu1NuWXLXnYGpt4JYFkSGlYJOXKaBf2STv1TwhogdMyXt5XDjYjZ3ItjIGiom Or8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443069; x=1720047869; 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=WRuxhaMQ+1lW78nuyDa9Lm/q++gXoPPs3JwtC5y4GFo=; b=ihQqYX+rc0jJUFwLydb2pF24CChUULX/UcSRRt31skNy2y5X/JKyRAzdY/LXcvzLsP pt1TVRGRxd20+Ihj6PHwS6VwPKKHZKEP0DhGDXr9mbf88BdgXowuH8YdtSV7Sno4FbTJ VexMT6li1q4jIyi2r7MetAT4y1l1vEs3ps0j93dZ3SdRvlZbn6Qi+5h061bAUm0X/DTa NC5yFvIr9pJvuKvMP22NeNVx8b+ZeStxrR6tfHGc715WrbpTgTFDsYN66j2x/OdSYp25 fUiwKqLD3o0tCUaHUdWWOQ5QgEBywCLNmQRYzbjvo3cCBHkZg9Sqbf3aLwz8fIBMwMet Ga/w== X-Forwarded-Encrypted: i=1; AJvYcCUmdtfocilOBHHUnrTHI16z/uVNbFLb/A5YJZFN87lBdxzK0o1NQNksjdQNuvlenYzRsoNZjfne/ZNXsatmCXQi1gfID5W+O1kX X-Gm-Message-State: AOJu0Ywg9eS3d1sm3W3nVDP3QXnirQGKyuoOrmheEC6Si85P3dw61BSF dMRU3utw9k8ft+CGl95XFhDzxlHQQPrP2KGQUineENk2HFP1msTvExeCHwtNcR7r+Z3zAbDrApw QxKc/HtAIMw== X-Google-Smtp-Source: AGHT+IEIAPNfqnBOOftySkpy/S1qLhtNZDiXS8lsXqrU0dYyZt2TBCiMdv15J5+VPG4DtZa7SQgsCmuWlH4hFA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a17:902:c40c:b0:1fa:1be4:1e5c with SMTP id d9443c01a7336-1fa1be42246mr10318515ad.3.1719443069215; Wed, 26 Jun 2024 16:04:29 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:08 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-4-ipylypiv@google.com> Subject: [PATCH v3 3/6] 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 --- 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 26b1263f5c7c..6b6e35292620 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. @@ -968,8 +965,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 Wed Jun 26 23:04:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952828 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=wLm0kUne; 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-1695-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 4W8ckC1244z20X6 for ; Thu, 27 Jun 2024 09:05:39 +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 33C6C1C21044 for ; Wed, 26 Jun 2024 23:05:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 927C4194A5C; Wed, 26 Jun 2024 23:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wLm0kUne" 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 D73D81946D5 for ; Wed, 26 Jun 2024 23:04:31 +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=1719443074; cv=none; b=I3UkNTN25T0nMqu/lGwvuvwgnUBQMDb73ajFl1LLQSZfXpEvT9xvLGtvDc2pSq488UQyHUq0fYvgGPvljjKK2HRuFcuY6dA+be1I4OFgJjTlAyd4je9ACRWCTx5J3kh2yj3feGDyHY3Vk5uiuLR8zh+vRqz01vtD1f/1RV3aqzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443074; c=relaxed/simple; bh=rrgk4/GN+4afQi82RWjkVdACN68Mce2bh09M2M+kIiE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UuIw7WGy0+OSiJbYQguggWCnKzFf70HvPbJzTUZ/B4nsHMOmlcHyyNOtHonvf/nq/rjTKyYDwv8YXGw5H2d9BXsDTFguD9EV14hSeOO+bCJmkg0ScL4rnsuRaGdNJIUxOVrbMlXy09mS/T79mH/oqq9cMfheanWpY0eGyOuEo5w= 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=wLm0kUne; 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-64399573fd3so123435427b3.0 for ; Wed, 26 Jun 2024 16:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443071; x=1720047871; 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=t/AvM/q6eju1FsW+yZoXAdsmFslERaWnMqALTvRepcM=; b=wLm0kUne+f06wja8x6z0zsOrKV5ScP28P/L/bdTpFOyUM1ZIhDhGDy+hboncNldeZ0 AfABcmWmhvwIgCXoC7bbeowqvcGTd7ZyzQnbRYJY2NMYxNWqjkDB93iy2r1IohQGzAZG OK+JQU/wc23B+zbdhc2zSie+k3ag9/MuTFahFwLVtLCuiEZBGnwWbOdYomTZ3ozx3hYK lo7w0X1j7z9hNkmijOWRPqsW4QnwtOv7XiQ77HOEHy9/5JAcnhpLia6dstp9LOkkZwqL BZIEXaWNfn9aYXwKtet/ZZpWHruVCDycYdTzgGCzXqKL9K6uMqDlrP0TomkZzKeg0MUM lV2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443071; x=1720047871; 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=t/AvM/q6eju1FsW+yZoXAdsmFslERaWnMqALTvRepcM=; b=TBO0eZ17uy2MnEKBPfP6NH1o1+CXLsU3VgcvNwqKbHEYVcV20vobZKFWnfxbh8WX0I GzSpq4G9iAnAKDIgreOAKuCQYMVOxFS2bO4kjomzx+CNmmve9o4BHBvhM2zx3+TfCoA6 2MgFXb/s12IfKjiSf3B/oqpBwVGiYCvd1kvsTyh9jUJYkSKYEvkZQ6AgmGGj/W5SwsWp AqXuk0YCQwEs3/b4uVjVkJpkQjZSoT0dIFJgt/O60ehhqyqM2nRipOsU3VM1uaQFxahw YZr2CdxEOzR6f7sGFrIXruUWCQgv8j8tLWYHV3F0S51dZXN28f4HEqqVbcE+iVI2/ZF+ TyMQ== X-Forwarded-Encrypted: i=1; AJvYcCX8nuHxxoLadSSyfA21Q7XL+amwJb3HaBl1M8tMD+WDpu+Wg7E64VJj8ckTwcZ08vcaNg6NaJKAIOCqmHuNxmQkox2AM+kPlPur X-Gm-Message-State: AOJu0YxbEdotKZ6aKjpW+ZZ4Vw2Qu3Cd4o4t2dDyM4euydMQUQKHaT13 g28TbYnkXTtWKg/FO9VHJIpSicGpH4Dl4QrLdDzeCZ6QUKonk1u7kEX+009CJ/+OPz5EZc6q+R9 dWcUlP0AU+A== X-Google-Smtp-Source: AGHT+IGHbW9wWs9Mfi0inpboOmSQg9uCUPvebnEdxpQuJ2+zXLOG/ST6R9W4mdAq7jmPeHiFUa3LGqjhiLvsAw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:f85:b0:e03:33c7:5678 with SMTP id 3f1490d57ef6-e0333c75779mr304400276.13.1719443070943; Wed, 26 Jun 2024 16:04:30 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:09 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-5-ipylypiv@google.com> Subject: [PATCH v3 4/6] 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 --- 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 6b6e35292620..02af4d5d5799 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 { @@ -976,7 +975,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 Wed Jun 26 23:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952829 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=fd5cMyQh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.48.161; helo=sy.mirrors.kernel.org; envelope-from=linux-ide+bounces-1696-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [147.75.48.161]) (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 4W8ckK0f71z20X6 for ; Thu, 27 Jun 2024 09:05:45 +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 CFF06B215DB for ; Wed, 26 Jun 2024 23:05:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 713DC194A69; Wed, 26 Jun 2024 23:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fd5cMyQh" 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 BBDA9194A45 for ; Wed, 26 Jun 2024 23:04:33 +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=1719443075; cv=none; b=TbIWQ4Qt89dAYQwQu+aKavIYIMXeZBwJgIORfG3FohDEuItfuX0fc5/x7d1qsGq71jRM5jvSmsMHvMs1E5DQPFjcJnINp7FpXXE6YUm9SnT/5N+YK6ap6M9gsyAUfVMIvD/hDBDCUoPMKRsoKTyqcTtAilDyMVTJX/la0aWFcmE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443075; c=relaxed/simple; bh=bVYP/yh9H60FMAxPtcm0Q5OLzE/o5Ocz16UtfVNPa4U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eNL4PcD8McWUNCaCO7QZZvNUXKRFT63yz0se1tInvkdg6zGogfUzhY2+IjLk6Il0pkIRhWEQUObwki35fM1QIGkC4bB5jkJiYDFjmT9WaCHU/gTv0WYJF1iaaaJynghyOgYXm9bWKxZYpzO4Hw0PbhNjaPzuFnYg4uZXTjcttFg= 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=fd5cMyQh; 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-645eb1025b5so61577987b3.2 for ; Wed, 26 Jun 2024 16:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443073; x=1720047873; 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=TktkKoidPCE335Y52c+z5B8f/TUhLrrbeBqorbEFGO4=; b=fd5cMyQhfvZ/Uhp1HdtqM3KHl4H0XLxRdEvI+VSfv2VxmKyynKF59gkJQwnFgiLw+a McS2IqGXQp2A3iXZ2wTnACOZf5mkWxBvRAwbm8gP7kYXlE4r6o84miIYRwinvJ41gxte gVqyESHOb4ZUKO+IUvPpFF+dm5F0yrGr7plV5ySl/NAR/joGzJCaFBDtn0tGjtvu4/R8 a/LYn0lXdDHHHsonRBNkCcL0vQvSlN4hqqxD9eOYw4poSsKzWdHmGJfZJcu3azPBiIgf EUZ9At8dO5K8jogKYvUbbTAgjbxVEABiKv5Conl5jJfY9+1vSJFuc4rE7/Pgf/JhJCnZ j3xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443073; x=1720047873; 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=TktkKoidPCE335Y52c+z5B8f/TUhLrrbeBqorbEFGO4=; b=IZAxeMJH2W7wGo7vtObvDZNFeFJ1IZQ0RISPyxDhsp7v1KoHAjUbXrSXiOmEJXmPcI nkURTmheLB8FS41WCCtgKh0HnbLYhUmpFfX1QJxLxreMPmMw0lmz0GOUNi+03uM8ma3G IGZNKb7LfsxgW4Hc7ORnDw7WsW2gYDksJt+ptRG5FwwUpiQ8Hd1vTW4fIEvZBkySJY2N 64Ffch8ZrDHZEkXcUjHKnHFDjrVOK7uAtHx4ucx2V+WmVzHQarOIhq97LoDkAZ/MozVc 4kpKnYLQy5PSv/nk88zCJh4elA2qit6IfOC/ZuZq5xpuOuk1q8iEX7dsjIjdFxy9/jd5 ShRw== X-Forwarded-Encrypted: i=1; AJvYcCWXwoc2UHdVeNkwqn+1JJDYQhteCsoDv0/HS2QDeYzNG2rqp7MsGu3H4iSJY5DWZdRb7TxybaJMIWbvPAGMK+0WoI98+bIB4stJ X-Gm-Message-State: AOJu0Yw3SQguXYV+6ADeemxG9jmvDQPI4N60ERX8Ss92gBjmJJ75qTc6 yuY23ZqSxPUyCsQVA/RUjeBUuTD2lY7GsUJT4FPbMpHDvLz25RxiIjMjaJfyXyC91VxjAkfrfPH IaRz19uX29A== X-Google-Smtp-Source: AGHT+IEb4we7BM5x93dwmclinIUkfoKE9eA0csWjhO9wldRsT+EUgld1jSbloaZMyQXtxOZFolUe7L1HRqV/XA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6902:1109:b0:e03:3683:e67f with SMTP id 3f1490d57ef6-e033683e751mr4888276.5.1719443072715; Wed, 26 Jun 2024 16:04:32 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:10 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-6-ipylypiv@google.com> Subject: [PATCH v3 5/6] ata: libata: 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 --- drivers/ata/libahci.c | 10 ---------- drivers/ata/libata-core.c | 8 ++++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c index 83431aae74d8..0728d445e531 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) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index e1bf8a19b3c8..a9fc3ec9300f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -4801,8 +4801,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 Wed Jun 26 23:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Pylypiv X-Patchwork-Id: 1952830 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=f0NnXEZ9; 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-1697-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 4W8ckY3H0Lz20X6 for ; Thu, 27 Jun 2024 09:05:57 +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 9ADC31C2074E for ; Wed, 26 Jun 2024 23:05:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CE67194AD5; Wed, 26 Jun 2024 23:04:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="f0NnXEZ9" 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 58C39194A65 for ; Wed, 26 Jun 2024 23:04:35 +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=1719443076; cv=none; b=DQSeUHcLwDiRWClHVXKccbQbz4dcEyIdm/baoFxWsP04HrGQ1shUbm3+iZr1syyZwZmoeijiCPwgYKLjkMS5bXW+NYRzLW/JUIOGiG/0Aed8W3Lr4Y8btM76szptU1thfVKSD38BFO5XCIJksHsH/fruGy450FBinJxuRF/9c7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719443076; c=relaxed/simple; bh=vKCPSZCxsriB7WThJFHjvVytk0B8CH0/B2lctEhKZJI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PCQ5ajjFVovYSZndtCOnHUkDohpRBKCVQNfm9RYMP32l3842ia0mPB+gFOFstWxWe2Y5wWa0xYab8mub/hF+u1g8lnGKAzOOugKrL0hx0ZDs1j9h+s1UgrBURuOH95L5/iH/NmAxIvXLcvHQTnhctDQrOmya0gYmUuCW7F9ScRw= 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=f0NnXEZ9; 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-646f6df9683so53587147b3.2 for ; Wed, 26 Jun 2024 16:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719443074; x=1720047874; 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=PEyKI1QsiIJEewnF527ltuQV4oeBpkyWMn9QtWCUb2g=; b=f0NnXEZ9Kk4PBi87AmOOr4ZP9E2uGHCVvpqZazMUUTnAs56AaHJtI/TOfFi+tLtBmJ hH1+RGzbJecDuDK8XCgF0jd1BHxkK2W4/DW5Xx8Y1hGbIlx6/cSpp7Wq9aJ0Qag1HtUj xvjC8sOa5CdpkYChSCUZSQztrLTia3kk6ueGISxEhtSfI540IwHJ2kwGpxNOZ9MO35jZ zCWGT6Kl1AJ6JyIfjmIBdqolHdxz8vwze/xfFsG028AMF9aTVv8416EhTuzTLbliM5QS bGmdjgHNPR+F4a5iYJxmEC0DqqHZrzCb3umUBCfDT6X0imzoE1Zh6a2GCGQOvZAYmNeQ JxMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443074; x=1720047874; 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=PEyKI1QsiIJEewnF527ltuQV4oeBpkyWMn9QtWCUb2g=; b=GD/SQE3ZIv7Yjaq05zvWLqzcFvhixtqDvat+yXbAFIPg84ZHqUvS87rq9XZVphligw wQcF/hGny/tkJNd5WU5JjAqQ/ZEICWtRslg5m/hiS7X1oeOY/75yKia1jR/yXpdddlfm I6pyPfwza05JB7NKc4UV2Hi9FFE8G7sjl7h5WyOV5FesANSW7qPhSlBRTeOnzK/3FFvk 64r8J9ob6mjX68V7BWzOFM7FsuPgZ+GK3GaEYdbF/cnhIritrvcSqe3hty5Ut9CQYu0e TbjmEryt8bqJiyGL95aPQIM9H489DG5Rwt4ygizI/ClYuqgsfew+Ll4kls8Df7LgZj7N VQqw== X-Forwarded-Encrypted: i=1; AJvYcCWboX1qkAhPEtyzWyazg+ishHxa3eHC6VSVDUxAdVwzQABo2n0nhQQb9uqAUoY/SnsRxXbjBV/gwMSuZqcTGcvyZP+4r4ax3mmU X-Gm-Message-State: AOJu0YyXZcsilmQ6bcZDHqt3KusJBUxppwO+UFOg4XdjDcZZmMW2fdPU 26+0mDVuMaQRPVPhpI9kWX+JNT6D2MgjXN11XCqzBzCF6UAnfkm7VvOo9vBU52knwzDdoPCywXv dwtIWIy9buw== X-Google-Smtp-Source: AGHT+IHEjGoOj0rKBY90tBQ+URsGB4VTurQ8pFXkmw/P+KxoNfpIx64+6no67l8qdUYDXNV6XjzwXAXXQvy3Bw== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:fc8:b0:648:2a9d:1a63 with SMTP id 00721157ae682-6482a9d24bfmr2023537b3.7.1719443074353; Wed, 26 Jun 2024 16:04:34 -0700 (PDT) Date: Wed, 26 Jun 2024 23:04:11 +0000 In-Reply-To: <20240626230411.3471543-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: <20240626230411.3471543-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240626230411.3471543-7-ipylypiv@google.com> Subject: [PATCH v3 6/6] 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. Signed-off-by: Igor Pylypiv Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-scsi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 02af4d5d5799..d5874d4b9253 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -242,10 +242,16 @@ 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 RTF: cannot set ATA PT sense fields.\n"); + return; + } + if ((sb[0] & 0x7f) >= 0x72) { unsigned char *desc; u8 len; @@ -923,10 +929,16 @@ 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 RTF: cannot generate ATA PT sense data.\n"); + return; + } + /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -970,6 +982,12 @@ 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 RTF: cannot generate sense data.\n"); + return; + } + /* Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. */