From nobody Thu Dec 18 02:26:21 2025 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 30B5519CCE9 for ; Fri, 14 Jun 2024 19:18:49 +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=1718392730; cv=none; b=FsU7gY+g9EHkTyadYKaOkIMSkb8o5Z0t2m2rtDEEASc4XuCYQ7m58dB11NkqOphdFY3hibS20kC4tZll+9RwtsDKwcYIKYFCariCuMN5AvtFkf7QGh4hffPg5nEPcNfy85B+pXBMCPYpx9S0ZnTD7mZhuBmE7cgpzL+OKxlh9U4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392730; c=relaxed/simple; bh=3kS79tYzgOf3yX79jAg0FWDEvMWZi/lcq/PdWyuqi8I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AUg4hmrsO3R2CLqbq1jNxlCdJlrRwbh6g2eBdx/2yBwqOrdfLgfIaPAlfYi3PpId0qDcjiVA5ne8kJ1stTybv5jAs8xr2k/vYkSqu0CDmZkWiwYQRSU5Wcce0lOoqRiMNyYUvE4AwSJtD53lMX0rhDqM2LicpKbzCF/ynCGdY3I= 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=O2mQf/Y+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="O2mQf/Y+" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7043008f4beso2242453b3a.2 for ; Fri, 14 Jun 2024 12:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718392728; x=1718997528; 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=uSZdAXqO25TNI8nIM2+VeqTcUj08zaT02GPeczOjqik=; b=O2mQf/Y+D2lUQrc4fDYQ1m9Jw+6YyybiHQumEJnQPA45YiF/loJ/TjkogH26TBQE+N XN1OmuuZEr3mHwkMfcDWzIt8tJMxmfaDvsbzv5+3snOjPvYkHkEtwTrGFEtjISX5TNwm jxqCEULJrKwV9AX7Hi/uHlbmsd+9kTAYUHYXrHcBhwy6Lku5F3jrxNX75a2bLhmxQGTQ XsxNu0wZFxpBc9wcR8aWYO0gYkM15OBg+C4elO5e2tvv/ZMqv3Xzoq02LsoezwoJV+bl QVVU88ZLKqE76mEWJB3uQFs4KWbOVp16dkIT50Cj4nxLOrWkSScJTkZnQqXfgvoYDpJi NaAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718392728; x=1718997528; 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=uSZdAXqO25TNI8nIM2+VeqTcUj08zaT02GPeczOjqik=; b=kV1gs9EhVKTo1UUpeWBMn3YqPWd2KpxWK5VQNWPDJRcbgyD0+98QGTpNJykuGkNi8P UcKEvkQvK1JOZggiVlNeN5Cj9M9w7Khyyf3ou0fY9fti7jcyF0oB5PRDn+ElUARcVYlW FnEdSOc9+ZZTjLPOnw6/9IGBfvMyw7syHCoM4bBRPLEoYzhxY2UXOiKldkj7S096ETXs b9Tcy5abk5UKVOO99XLhmuD1cEQ9De1uaEjv1E+Nst//UG+yux1A9O3hAEXVPTY0cdS5 +iwME/oWNwyXfQxr6C9XnSbBFEl9xedpEGYdhrFj/hMMfXwLPhiLQKj3ylHM8OvoicIL XbKg== X-Forwarded-Encrypted: i=1; AJvYcCU98UT25N68IA27mbmL9zbDnDGC8G/C0KvF2a2RDwDrMum3ONVWnjADACXMWflsvTaaq7e3o0SaisPgG2b1Wllmwiq3KoltR6DN/nW6 X-Gm-Message-State: AOJu0Yx58Qsi+8pjXe2t+smCs32ZanZbMivi07PFgnkWQytQrbPt4Qf/ Fb7kora7KhGw6ILKnS7Cd+/8d1juo+Qpqc/h4YBMxfNU2E9gBAnZzi9BXOxZiuIDKrktPI9lcEh uQhkmeegX5Q== X-Google-Smtp-Source: AGHT+IFdj24c8fzBtMzoKfG+48fuiFtXBqhb0JfTQ+EiejlPio658jL+zK7WceIb3isG3JKB/NWVMCK8RBbQDg== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:6a00:1d85:b0:705:27de:74e7 with SMTP id d2e1a72fcca58-705d70f12b2mr58576b3a.1.1718392728230; Fri, 14 Jun 2024 12:18:48 -0700 (PDT) Date: Fri, 14 Jun 2024 19:18:32 +0000 In-Reply-To: <20240614191835.3056153-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240614191835.3056153-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240614191835.3056153-2-ipylypiv@google.com> Subject: [PATCH v1 1/4] ata: libata: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scsi_queue_rq() memsets sense_buffer before a command is dispatched. Libata is not memsetting sense_buffer before setting sense data that was obtained from a disk so there should be no reason to do a memset for ATA PASS-THROUGH / ATAPI. Memsetting the sense_buffer in ata_gen_passthru_sense() is erasing valid sense data that was previously obtained from a disk. A follow-up patch will modify ata_gen_passthru_sense() to stop generating sense data based on ATA status register bits if a valid sense data is already present. Signed-off-by: Igor Pylypiv --- drivers/ata/libata-eh.c | 2 -- drivers/ata/libata-scsi.c | 4 ---- 2 files changed, 6 deletions(-) diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index 214b935c2ced..b5e05efe73f6 100644 --- a/drivers/ata/libata-eh.c +++ b/drivers/ata/libata-eh.c @@ -1479,8 +1479,6 @@ unsigned int atapi_eh_request_sense(struct ata_device= *dev, struct ata_port *ap =3D dev->link->ap; struct ata_taskfile tf; =20 - memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE); - /* initialize sense_buf with the error register, * for the case where they are -not- overwritten */ diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index cdf29b178ddc..032cf11d0bcc 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -858,8 +858,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) unsigned char *desc =3D sb + 8; u8 sense_key, asc, ascq; =20 - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - /* * Use ata_to_sense_error() to map status register bits * onto sense key, asc & ascq. @@ -953,8 +951,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) u64 block; u8 sense_key, asc, ascq; =20 - memset(sb, 0, SCSI_SENSE_BUFFERSIZE); - if (ata_dev_disabled(dev)) { /* Device disabled after error recovery */ /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ --=20 2.45.2.627.g7a2c4fd464-goog From nobody Thu Dec 18 02:26:21 2025 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 4C9111A3BB2 for ; Fri, 14 Jun 2024 19:18:51 +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=1718392732; cv=none; b=QYE7/FUSs3XlvEYf/rfJ5s7vJENDuK9Yqf5LJdJN6FXGmbIhTxpWLBu6usGNymqzzzWS6bHlJyF9sb7hhaT9YPPIjyN7G1VxLP1rimzG/wVUfssr26+/ocjnYmsvT41r3hx37OXW/LBEVNHiqPqS2487MnUqZI4VnFJ/KYc65dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392732; c=relaxed/simple; bh=OXTK3gM4Pr8t3G/JNhWI9HNDMuZTEBhK+WvzY4WWxdI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=J7/g/bDEfNxwrhMw1V4RnUVBvDKn1+NIejdhRCKNYHUvtTzev05OIBzLWrqxRGbVb4h1VMFmERzRlTssEqICTx0YTh1R63A7rT2hNUNhp9/myQg13DTNRNyaatuAfNEdNBUnGfHCGIP713BCysrvcE/aa4kxTtSNs0zKJlhGgkU= 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=3iA6cSmg; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3iA6cSmg" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a1e9807c0so27015047b3.0 for ; Fri, 14 Jun 2024 12:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718392730; x=1718997530; 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=U+A9L+Row2dnJmZ3QpC1oG5yWdVfX7wPmeHXsPZEOds=; b=3iA6cSmgYmEBTuAgmjE3+BsFfK1KRTliplTZ7NlVWdBBZBovwI0cTZ5q8F43rizXy/ Artx1iqvVwlwgpPxw+rJ8r5w9x8qAU+VYmod7v3tQuBNBPkp0NHqQp6xyo2zQ4d1MFLn k8TBdh71DQwG24lcmDAwS6z470rPqSWjsPcaCi+aG94irDaAIYZ9e5Mp1h6PPO6JVWTJ TTXFsL13IbOmK33I1LiWsNN0+WtPVLIycowaoTj8HFnms4W6KrDd7CZh9VjoTFnXqi5n a1OuAih5hDOrWfZEHfPb1WZE8bw6RhGkUJvZWfCNDMOfYhKiUNG7MSqqUWjPmeZf7q7j m/bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718392730; x=1718997530; 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=U+A9L+Row2dnJmZ3QpC1oG5yWdVfX7wPmeHXsPZEOds=; b=UD3dK/vr3JZCiCZsAcSU1cI55fon2Ih3/SIjCdiyDDfR3FVhORm2JyyACVbGbOgArE SuMx8Tj7OkPGIlxn7kRd+hWdnewGfMpKPACpJJJMM8uLyiOnl5ucnpT/MzaKJIpcAlOO hNhG93NPw3JJPmzM28jq0pSNTY8clhsyrpfPoaSiWx57TUC4rXLk82R2PR1yxukD/BHH Pon/+CtoWZkIG9F9N8YgCh+qq7X9GF6tdloxQIP40mGCavp+1HxUyhc+MIcwrv1y0j04 OLzJW9XdSdEN7+0NwxE/ojsBQrps2TZRJOt7Y2jJy6JVisV+T26FoXbkMNrctSSUvxI9 T+jg== X-Forwarded-Encrypted: i=1; AJvYcCWbygUggHX6AQ2LZFGfHMCRdoODKE2ppEkMB5ZETWNBB5kS0iYfmv7exjBpgbQHq8HXHmmVn2awDV4V4qq18oLDxVy4tA5kjrFt0Ham X-Gm-Message-State: AOJu0Yz4P815x0lKRqKArH5pPySHVtS4URbUCJS7PYp80AR/hO8XFSEW xT3LA93qRyBU+TFKfynENRWoalCPbxecXogbCBfRNSfJYCfwX55n5elRNYUFYDHyNIR/knSlxRy hpsGcfsF8qA== X-Google-Smtp-Source: AGHT+IEgr36e43Ztcq9blL3xwno/d+31kbeTYxCB2shQPDd8Hlpao0W3TzB2dN5UT4kq97FW/dtEczVMQBa9BA== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:6e0a:b0:618:5009:cb71 with SMTP id 00721157ae682-632072d3bb5mr9083077b3.5.1718392730342; Fri, 14 Jun 2024 12:18:50 -0700 (PDT) Date: Fri, 14 Jun 2024 19:18:33 +0000 In-Reply-To: <20240614191835.3056153-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240614191835.3056153-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240614191835.3056153-3-ipylypiv@google.com> Subject: [PATCH v1 2/4] ata: libata-scsi: Generate ATA PT sense data when ATA ERR/DF are set 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" SCSI/ATA Translation-5 (SAT-5) Table 209 =E2=80=94 "ATA command results" specifies that SATL shall generate sense data for ATA PASS-THROUGH commands when either CK_COND is set or when ATA_ERR or ATA_DF status bits are set. ata_eh_analyze_tf() sets AC_ERR_DEV bit in qc->err_mask when ATA_ERR or ATA_DF bits are set. It looks like qc->err_mask can be used as an error indicator but ata_eh_link_autopsy() clears AC_ERR_DEV bit when ATA_QCFLAG_SENSE_VALID is set. This effectively clears the error indication if no other bits were set in qc->err_mask. ata_scsi_qc_complete() should not use qc->err_mask for ATA PASS-THROUGH commands because qc->err_mask can be zero (i.e. "no error") even when the corresponding command has failed with ATA_ERR/ATA_DF bits set. Additionally, the presence of valid sense data (ATA_QCFLAG_SENSE_VALID) should not prevent SATL from generating sense data for ATA PASS-THROUGH. Signed-off-by: Igor Pylypiv --- drivers/ata/libata-scsi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 032cf11d0bcc..79e8103ef3a9 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1632,8 +1632,8 @@ static void ata_scsi_qc_complete(struct ata_queued_cm= d *qc) !(qc->flags & ATA_QCFLAG_SENSE_VALID); =20 /* 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 =3D1], a check + * user mandated it or if ATA_ERR or ATA_DF bits are set. Note that + * if we generate because the user forced us to [CK_COND=3D1], 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: @@ -1641,7 +1641,7 @@ static void ata_scsi_qc_complete(struct ata_queued_cm= d *qc) * asc,ascq =3D ATA PASS-THROUGH INFORMATION AVAILABLE */ if (((cdb[0] =3D=3D ATA_16) || (cdb[0] =3D=3D ATA_12)) && - ((cdb[2] & 0x20) || need_sense)) + ((cdb[2] & 0x20) || (qc->result_tf.status & (ATA_ERR | ATA_DF)))) ata_gen_passthru_sense(qc); else if (need_sense) ata_gen_ata_sense(qc); --=20 2.45.2.627.g7a2c4fd464-goog From nobody Thu Dec 18 02:26:21 2025 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 0A4E81A3BA7 for ; Fri, 14 Jun 2024 19:18:52 +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=1718392734; cv=none; b=XUeicco9J40cpeMzRYTgORbrBPD95ilWcsGaVclq1SGqi4rNWHsPKS0L1AQjc0QulcxVPn15a+r+mON4xUMiib2gxRBowZLYjdr0L20HkTVhCfceOM1l3iAevKuNKudJvXWoV+xAutkxkE7/tJkuVaQBs62dI8U6hMgRI3sfg6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392734; c=relaxed/simple; bh=OsE7aRRVqh2vPXKdIi6uRApNlBEwCqMLvrna3Rqbvuw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=feT3OYRu62lxcMa4Cp8pjSJKHGDSVqCjV72t2JBTFrkfwhphvM6uxbsAnWbC78hLllb6gOZtt44YMVu2WGLe2MYSNVuyWKv51zyZ8/odxAyMnXBd7DZqNaKTAJMk2bJFevhvU8tNBLzn6N3Nt/B8Pfp0BBO9CV23NKScxzWuN98= 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=DBOPVBvU; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DBOPVBvU" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-631d53af5e1so29091217b3.2 for ; Fri, 14 Jun 2024 12:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718392732; x=1718997532; 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=N5Y8Q6R7VHhS5DlEz/CEIrnOSJXapU1igMdb8ysJrOY=; b=DBOPVBvU3EXdWiCghMmclltYGpzQ260xnSnXIqsRnLQk8eY2XQbWaRUzX5pv/w3COX iDhHNFDnx8gg6vedSdPF2l1LpJCBcb1ef1geKqNRsRFSA9mHU/ZFE00JhwfN7F5X+tOo rIYOPR3YeRwYSOvJbO93F3ybna1DbI4yjpf+bMPHT4eC+jvucMAJ8Ohi/rGZ6GvkhNge ZvqMAuhpUG7okfesfQLSVtmyfThCFIlSXs9T/aRWZZmMTLe5cKEi0jMjip0ArrVeLvd4 TAZ+FYzGmmAbNpbwpzqlj6xhs//8qCa4a4Gud6cPxbchM56ooebaRN7WdPZk99OjcoxQ Bklg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718392732; x=1718997532; 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=N5Y8Q6R7VHhS5DlEz/CEIrnOSJXapU1igMdb8ysJrOY=; b=m5N0XfCTCrWP7nJxP/WG8uJbPqGVk6KvkDFtqD0rCaqrZ8K09hD7qWThwCdv/96jmM fuTLu6zd0afnbrbvr6iOo5mpTSPXxkp7RzmlRm0L6JO4YPFP+Vpc26LC+kJRPnzhMRnd jY9Yy2Qh+SKn5ZpHH0rcJjnCyL7Dldx+4ekqxmeL9GgZMslp4LrqX/h5iHWM27nWRvQn jpCOvf+CAV/jrtdY+2YuzLqYjUkf6Xjzebj1VAuqA1lungbjDHNFdyt/w02thQEHyMKw 0T8fBS50/mEwCqJqT/RZeaDE75tKhShfrVg4rZLqQcKMEyhtcbkBOxPLvF/31zsxtF6q aMYw== X-Forwarded-Encrypted: i=1; AJvYcCXcjuWn8N4QSxMDl1CvzqJqOQcGS6gaj8JkieXrnlls7gCyYfKPFFmeexxKml7d2f+ubnzC6CSj+DKgtDGu+NEfFZaUKseKv8O7lUaK X-Gm-Message-State: AOJu0YxSyMLPrqEcOqX8I6/0hWICN8K42FYggtiTYtnViIrDyQgeY8rh FwSKATAIJ4A041iUFXnkv+oQbm7HYTOPQsgSLxY+aCe8FSMlTdU2MWoA0ukWzk2z0JPkO4RGHJq iHglAKH11MA== X-Google-Smtp-Source: AGHT+IFAQcSwFKGcNCpGx6cDExUUokRstHtgNipOk4oYaWFz9OzYHZCeAbLOqEXX5BK7k/s00LnS2IvikgPe7Q== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a05:690c:398:b0:62d:a29:537e with SMTP id 00721157ae682-63222565d7emr10233367b3.4.1718392732108; Fri, 14 Jun 2024 12:18:52 -0700 (PDT) Date: Fri, 14 Jun 2024 19:18:34 +0000 In-Reply-To: <20240614191835.3056153-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240614191835.3056153-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240614191835.3056153-4-ipylypiv@google.com> Subject: [PATCH v1 3/4] ata: libata-scsi: Report valid sense data for ATA PT if present 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Do not generate sense data from ATA status/error registers if valid sense data is already present. Signed-off-by: Igor Pylypiv --- drivers/ata/libata-scsi.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 79e8103ef3a9..4bfe47e7d266 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -858,12 +858,17 @@ static void ata_gen_passthru_sense(struct ata_queued_= cmd *qc) unsigned char *desc =3D sb + 8; u8 sense_key, asc, ascq; =20 - /* - * Use ata_to_sense_error() to map status register bits - * onto sense key, asc & ascq. - */ - if (qc->err_mask || - tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { + if (qc->flags & ATA_QCFLAG_SENSE_VALID) { + /* + * Do not generate sense data from ATA status/error + * registers if valid sense data is already present. + */ + } else if (qc->err_mask || + tf->status & (ATA_BUSY | ATA_DF | ATA_ERR | ATA_DRQ)) { + /* + * Use ata_to_sense_error() to map status register bits + * onto sense key, asc & ascq. + */ ata_to_sense_error(qc->ap->print_id, tf->status, tf->error, &sense_key, &asc, &ascq); ata_scsi_set_sense(qc->dev, cmd, sense_key, asc, ascq); --=20 2.45.2.627.g7a2c4fd464-goog From nobody Thu Dec 18 02:26:21 2025 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 4B61B195964 for ; Fri, 14 Jun 2024 19:18:54 +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=1718392735; cv=none; b=AoR2K1VE8Wa/zWIeg/FVh9Kugut18R3V4WrNvCUBxQWM8NDJupjBumb+xL+mO5R1SqCKDX9UNb3rOCOE8EIc+oVC5v/DoQEuZ59oAVnOfUmAJ4AZcDaAHTp7x+MFQxWqH2PoC9ikJ1iOOueI0bFmb/n1sLhe41WhLIiMIjryIgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718392735; c=relaxed/simple; bh=qgmtNL4k97jHCwRfQqDmBVh7jd6+0c78XagNpSAyDsc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=f1fEvT7OPTmA3McVBdl/nmhogiGd6lCZAdXrw7nbW4CkhTP/XshDTI6FXm88FT8COQG8UsfbggRe+Ix3ral9tM9Gq9JiM0w2+WO/hoZquifq2rpiuxCX49rOCb+b8nEl0s+YHQdDcdJdcCFEfrk6Z10/olok9eESaoBwshuPn20= 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=B6Yo+ktA; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B6Yo+ktA" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-6ea972a3547so2149134a12.1 for ; Fri, 14 Jun 2024 12:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718392734; x=1718997534; 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=/4AyfSTdpu6N2Lo5b6nZ4La1DDoSqqNXNC9AYdKo6X0=; b=B6Yo+ktA4Y6r0pnzTunJVbAAVCggpn02WJlQah7rNLepgOF10Ue7B9hbbDHeNi7Sff um9ZhtjPxHctqi4rM1PiBTV76aZksTMo7WhKDr+/9VFuY/3XSpIzmj6JCix2hslAV258 ePiqhnQd3WtakFp0EqYdtrqnPkCJLnXh+xZ8n9licsks2I5uaws8Gd1lP9p5hK8vMVt0 YLKsnZFUXagyci6m77TSRQC68AGLEJmaZMDgfqKYkvRmTb4C7N/HvXXLOme0jOI0dpKo a7Ye4bfKLypEV9dxmSQUUY5bwYpmTyLVPS2tw085zPtGWseih0JJ6UKT64ChrRd+andL ehRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718392734; x=1718997534; 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=/4AyfSTdpu6N2Lo5b6nZ4La1DDoSqqNXNC9AYdKo6X0=; b=e0+2Rbj1Tp9NRPRZV0orhTqB83JI6X6a9A+n4u6M52/RgAXECLmjhu2WTLEUfJpoCY fZnuJmAMyFurZWyxbQT3gAOq5ltARTqMS6xiYgtrHRh2M71XSSkMly9gNCo6dEXTu8QM vJ8HIUug4K6NRJ3bSUJyWfklDHuMOMuJE/A1vAgDXTka2TNArE8Qhb8RjukPu1iZM0bS UZm66PPldKzCbCQ/INDeDd6tjiVA8Aq7aMgL8nbUyynLQtpuhDY3+Qj91N0UwU5TJxhs eqqkbEbFRK1fp3zc0U5TtzE1VKF6wESlpi2uAv0MDKDO4Y1Z8JM5pAko3oAmwnOykfTR gF9w== X-Forwarded-Encrypted: i=1; AJvYcCUE7bjY5iN8jMxMBSt2F6kJORXfAlMCzL+fdZcI8682IatNtw7BC3qZAhlf67c0QPdgHj7ALUiuFOXezfBCgJ36DewRC7HT9lAfn9tC X-Gm-Message-State: AOJu0YzG/+4TjnhUwm5xydC8gKTy1XgmUS5+QHjvM/0isWByj6XesbRZ uR8pppwoKEg0QuoQShEMxlaTnRO6u/FQIgzRZLylWh+o5MbEJgu3f9g2Sq4G4G/y0uF941AOSKh 1BVVoy0zrUQ== X-Google-Smtp-Source: AGHT+IFhH0CY+7Imr4D7VPghy++YvEZgaw5IeIxH2RrSR71z103r+UyBHoV1Cf87mIAHSR19WF+ZEMhiq4U01Q== X-Received: from ip.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:57f3]) (user=ipylypiv job=sendgmr) by 2002:a63:4c04:0:b0:6ea:87eb:9493 with SMTP id 41be03b00d2f7-7019504fd99mr9226a12.2.1718392733536; Fri, 14 Jun 2024 12:18:53 -0700 (PDT) Date: Fri, 14 Jun 2024 19:18:35 +0000 In-Reply-To: <20240614191835.3056153-1-ipylypiv@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240614191835.3056153-1-ipylypiv@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240614191835.3056153-5-ipylypiv@google.com> Subject: [PATCH v1 4/4] 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D SAT-5 Table 212 =E2=80=94 "Fixed format sense data INFORMATION field for th= e 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D 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") 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 4bfe47e7d266..8588512f5975 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_cm= d *qc) struct scsi_cmnd *cmd =3D qc->scsicmd; struct ata_taskfile *tf =3D &qc->result_tf; unsigned char *sb =3D cmd->sense_buffer; - unsigned char *desc =3D sb + 8; u8 sense_key, asc, ascq; =20 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { @@ -880,8 +879,9 @@ static void ata_gen_passthru_sense(struct ata_queued_cm= d *qc) scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); } =20 - if ((cmd->sense_buffer[0] & 0x7f) >=3D 0x72) { + if ((sb[0] & 0x7f) >=3D 0x72) { u8 len; + unsigned char *desc; =20 /* descriptor format */ len =3D sb[7]; @@ -919,21 +919,21 @@ static void ata_gen_passthru_sense(struct ata_queued_= cmd *qc) } } else { /* Fixed sense format */ - desc[0] =3D tf->error; - desc[1] =3D tf->status; - desc[2] =3D tf->device; - desc[3] =3D tf->nsect; - desc[7] =3D 0; + sb[0] |=3D 0x80; + sb[3] =3D tf->error; + sb[4] =3D tf->status; + sb[5] =3D tf->device; + sb[6] =3D tf->nsect; if (tf->flags & ATA_TFLAG_LBA48) { - desc[8] |=3D 0x80; + sb[8] |=3D 0x80; if (tf->hob_nsect) - desc[8] |=3D 0x40; + sb[8] |=3D 0x40; if (tf->hob_lbal || tf->hob_lbam || tf->hob_lbah) - desc[8] |=3D 0x20; + sb[8] |=3D 0x20; } - desc[9] =3D tf->lbal; - desc[10] =3D tf->lbam; - desc[11] =3D tf->lbah; + sb[9] =3D tf->lbal; + sb[10] =3D tf->lbam; + sb[11] =3D tf->lbah; } } =20 --=20 2.45.2.627.g7a2c4fd464-goog