NetBSD Problem Report #57407

From www@netbsd.org  Sat May 13 16:36:13 2023
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 121ED1A923C
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 13 May 2023 16:36:13 +0000 (UTC)
Message-Id: <20230513163611.B81DE1A923D@mollari.NetBSD.org>
Date: Sat, 13 May 2023 16:36:11 +0000 (UTC)
From: hpaluch@seznam.cz
Reply-To: hpaluch@seznam.cz
To: gnats-bugs@NetBSD.org
Subject: Fix for kernel freeze with "BSY never cleared, status 0x80" with 1TB Seagate SATA HDD
X-Send-Pr-Version: www-1.0

>Number:         57407
>Category:       kern
>Synopsis:       Fix for kernel freeze with "BSY never cleared, status 0x80" with 1TB Seagate SATA HDD
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat May 13 16:40:00 +0000 2023
>Last-Modified:  Sun May 14 17:15:01 +0000 2023
>Originator:     Henryk Paluch
>Release:        9.3-RELEASE
>Organization:
N/A
>Environment:
From custom kernel (stock kernel freezes on boot):

NetBSD localhost 9.3 NetBSD 9.3 (GENERIC_HP) #0: Sat May 13 08:32:51 UTC 2023  root@netbsd93.example.com:/usr/src/sys/arch/amd64/compile/GENERIC_HP amd64

>Description:
When I boot standard NetBSD 9.3 CD - tested NetBSD-9.3-amd64.iso -
with new 1TB Seagate drive: ST1000DM010-2EP102 the kernel freeze on SATA link reset with message "BSY never cleared, status 0x80".

Here are relevant messages regarding my SATA controller and that HDD:

viaide2 at pci0 dev 5 function 1: NVIDIA MCP55 Serial ATA Controller (rev. 0xa2)
viaide2: bus-master DMA support present
viaide2: primary channel wired to native-PCI mode
viaide2: using ioapic0 pin 21 for native-PCI interrupt
atabus3 at viaide2 channel 0
viaide2: secondary channel wired to native-PCI mode
atabus4 at viaide2 channel 1
viaide2 port 1: device present, speed: 3.0Gb/s
viaide2: BSY never cleared, status 0x80

I have found that other HDD (old WD 500GB SATA disk) works without problem with same NetBSD. Also OpenBSD and Linux boots on same machine without issue (installed in GPT+BIOS with few small hacks).

There one report which can be related - on Internet, for example:
- https://www.unitedbsd.com/d/605-netbsd-92-amd64-does-not-recognize-hard-disk/5
However it is not yet confirmed.

More HW details:
- MB MSI K9N Platinum
- nVidia nForce 570 chipset
- CPU AMD X2 (Dual-Core Athlon)
- 8GB of RAM
- here are details on HDD with fixed kernel:

wd0 at atabus4 drive 0
wd0: <ST1000DM010-2EP102>
wd0: drive supports 16-sector PIO transfers, LBA48 addressing
wd0: 931 GB, 1938021 cyl, 16 head, 63 sec, 512 bytes/sect x 1953525168 sectors (0 bytes/physsect; first aligned sector: 8)
wd0: GPT GUID: 044fdb79-3b9c-4fff-86a9-66becdf9aebd
...

>How-To-Repeat:
Boot NetBSD 9.3 with old SATA controller (tested NVIDIA MCP55 Serial ATA) and new Seagate 1TB SATA disk (tested ST1000DM010-2EP102). 

The kernel will freeze for around 5minutes with:

BSY never cleared, status 0x80

After around 5 minutes it will continue boot, however such disk is completely ignored, so NetBSD can't be installed on it.
>Fix:
I found that this trivial patch, that forces SATA1 1.5Gb/s mode fixes the problem and I was able to installed NetBSD on that system:

--- /root/sata_subr.c	2023-05-13 07:38:30.264874166 +0000
+++ /usr/src/sys/dev/ata/sata_subr.c	2023-05-13 07:40:24.075628047 +0000
@@ -93,8 +93,10 @@
 	 * the device. It doesn't hurt for other devices.
 	 */
 	bus_space_write_4(sata_t, scontrol_r, 0, 0);
-	scontrol = SControl_IPM_NONE | SControl_SPD_ANY | SControl_DET_INIT;
+	scontrol = SControl_IPM_NONE | SControl_SPD_G1 | SControl_DET_INIT;
 	bus_space_write_4(sata_t, scontrol_r, 0, scontrol);
+	aprint_normal("%s port %d: enforcing SATA1 speed at 1.5Gb/s\n",
+		    device_xname(chp->ch_atac->atac_dev), chp->ch_channel);

 	ata_delay(chp, 50, "sataup", flags);
 	scontrol &= ~SControl_DET_INIT;

>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: kern/57407: Fix for kernel freeze with "BSY never cleared, status 0x80" with 1TB Seagate SATA HDD
Date: Mon, 15 May 2023 03:14:24 +1000

 FWIW, part of testing attempts to read from a failing disk i had written
 code to do similar with kernel options.  i vaguely meant to try to convert
 it to using some sort of config flags so it's per-device capable, not all
 devices, that's why i didn't commit or send for review yet.

 you'd use it for your need as:

    options SATA_FORCE_SPD=SControl_SPD_G1


 .mrg.


 Index: sys/dev/ata/sata_subr.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/ata/sata_subr.c,v
 retrieving revision 1.24
 diff -p -u -r1.24 sata_subr.c
 --- sys/dev/ata/sata_subr.c	21 Jun 2018 21:52:15 -0000	1.24
 +++ sys/dev/ata/sata_subr.c	14 May 2023 17:12:15 -0000
 @@ -93,7 +93,11 @@ sata_reset_interface(struct ata_channel 
  	 * the device. It doesn't hurt for other devices.
  	 */
  	bus_space_write_4(sata_t, scontrol_r, 0, 0);
 +#ifdef SATA_FORCE_SPD
 +	scontrol = SControl_IPM_NONE | SATA_FORCE_SPD | SControl_DET_INIT;
 +#else
  	scontrol = SControl_IPM_NONE | SControl_SPD_ANY | SControl_DET_INIT;
 +#endif
  	bus_space_write_4(sata_t, scontrol_r, 0, scontrol);

  	ata_delay(chp, 50, "sataup", flags);

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.