NetBSD Problem Report #58231

From staffan@shell.shangtai.net  Tue May  7 10:03:17 2024
Return-Path: <staffan@shell.shangtai.net>
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 B06B31A9238
	for <gnats-bugs@gnats.NetBSD.org>; Tue,  7 May 2024 10:03:17 +0000 (UTC)
Message-Id: <20240507100312.1865A5D293@shell.shangtai.net>
Date: Tue,  7 May 2024 13:03:11 +0300 (EEST)
From: staffan@shangtai.net
Reply-To: staffan@shangtai.net
To: gnats-bugs@NetBSD.org
Subject: NXP LPC1xxx virtual umass devices fail become ready
X-Send-Pr-Version: 3.95

>Number:         58231
>Category:       kern
>Synopsis:       NXP LPC1xxx virtual umass devices fail become ready
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 07 10:05:00 +0000 2024
>Originator:     staffan@shangtai.net
>Release:        NetBSD 10.0
>Organization:
>Environment:
System: NetBSD shell.shangtai.net 9.3 NetBSD 9.3 (BLUEGLEAM_XEN3_DOMU) #11: Sat Aug 6 17:48:46 UTC 2022 duck@power.shangtai.net:/usr/build/src/sys/arch/amd64/compile/obj/BLUEGLEAM_XEN3_DOMU amd64
Architecture: x86_64
Machine: amd64
>Description:

This is a follow-up with a patch to the discussion on tech-kern@
(thread starts here:
http://mail-index.netbsd.org/tech-kern/2024/01/26/msg029452.html) about the LPC flash chip on my mnt reform2, so that the change can hopefully be included.

As discovered in the thread, these devices require that a SCSI START command
NOT be sent before they are accessed, and such a quirk is currently nonexistent
in NetBSD.

>How-To-Repeat:

Try to mount the virtual umass device on an NXP LPC1xxx on NetBSD

>Fix:

The following patch adds the required PQUIRK and adds a usb device quirk for
the LPC1xxx. It includes a change to the minimum number of cylinders in sd.c
that I'm not sure if is required (this is a very small device). I can test
without it if this change isn't desired.

This patchset is against the (then unreleased) netbsd-10 branch as of
February 4th 2024 (see patch header for more details)

# HG changeset patch
# User Staffan Thomen <duck@shangtai.net>
# Date 1707080552 0
#      Sun Feb 04 21:02:32 2024 +0000
# Branch netbsd-10
# Node ID f368df5ceae4dbeb3a6a10e7e8b3c6668dc08303
# Parent  7ddaaaeb813a1bceaf4190cb6c3444cc3c225ebb
Round up cylinders to 1 if the device is so small it would be 0

diff -r 7ddaaaeb813a -r f368df5ceae4 sys/dev/scsipi/sd.c
--- a/sys/dev/scsipi/sd.c	Tue Jan 16 08:28:51 2024 +0000
+++ b/sys/dev/scsipi/sd.c	Sun Feb 04 21:02:32 2024 +0000
@@ -1769,6 +1769,8 @@
 		dp->heads = 64;
 		dp->sectors = 32;
 		dp->cyls = dp->disksize / (64 * 32);
+		if (dp->cyls == 0)
+			dp->cyls = 1;
 	}
 	dp->rot_rate = 3600;

# HG changeset patch
# User Staffan Thomen <duck@shangtai.net>
# Date 1707080615 0
#      Sun Feb 04 21:03:35 2024 +0000
# Branch netbsd-10
# Node ID fb8c5f27a9473039c3bc82d453164ab2c201d5f4
# Parent  f368df5ceae4dbeb3a6a10e7e8b3c6668dc08303
Add the PQUIRK_NOSTART quirk to prevent a START command from being sent to devices that don't support them

diff -r f368df5ceae4 -r fb8c5f27a947 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c	Sun Feb 04 21:02:32 2024 +0000
+++ b/sys/dev/scsipi/scsipi_base.c	Sun Feb 04 21:03:35 2024 +0000
@@ -1312,6 +1312,9 @@
 {
 	struct scsipi_start_stop cmd;

+	if (periph->periph_quirks & PQUIRK_NOSTART)
+		return 0;
+
 	memset(&cmd, 0, sizeof(cmd));
 	cmd.opcode = START_STOP;
 	cmd.byte2 = 0x00;
diff -r f368df5ceae4 -r fb8c5f27a947 sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h	Sun Feb 04 21:02:32 2024 +0000
+++ b/sys/dev/scsipi/scsipiconf.h	Sun Feb 04 21:03:35 2024 +0000
@@ -504,6 +504,7 @@
 #define PQUIRK_NOREPSUPPOPC     0x01000000      /* does not grok
 						   REPORT SUPPORTED OPCODES
 						   to fetch device timeouts */
+#define PQUIRK_NOSTART      0x02000000	/* does not support START STOP */
 /*
  * Error values an adapter driver may return
  */
# HG changeset patch
# User Staffan Thomen <duck@shangtai.net>
# Date 1707080713 0
#      Sun Feb 04 21:05:13 2024 +0000
# Branch netbsd-10
# Node ID cb668c56dec8cabbe5d0f6ed362d35db3faef28a
# Parent  fb8c5f27a9473039c3bc82d453164ab2c201d5f4
Add the NXP vendor and the LPC1XXX product to apply its quirks

diff -r fb8c5f27a947 -r cb668c56dec8 sys/dev/usb/umass_quirks.c
--- a/sys/dev/usb/umass_quirks.c	Sun Feb 04 21:03:35 2024 +0000
+++ b/sys/dev/usb/umass_quirks.c	Sun Feb 04 21:05:13 2024 +0000
@@ -343,6 +343,16 @@
 	  UMATCH_VENDOR_PRODUCT,
 	  NULL, NULL
 	},
+
+	/* NXP LPC1xxx series ISP (In-System Programming) devices */
+
+	{ { USB_VENDOR_NXP, USB_PRODUCT_NXP_LPC1XXX },
+	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
+	  0,
+	  PQUIRK_NOSTART | PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE | PQUIRK_ONLYBIG,
+	  UMATCH_VENDOR_PRODUCT,
+	  NULL, NULL
+	}
 };

 const struct umass_quirk *
diff -r fb8c5f27a947 -r cb668c56dec8 sys/dev/usb/usbdevs
--- a/sys/dev/usb/usbdevs	Sun Feb 04 21:03:35 2024 +0000
+++ b/sys/dev/usb/usbdevs	Sun Feb 04 21:05:13 2024 +0000
@@ -563,6 +563,7 @@
 vendor LINUXFOUNDATION	0x1d6b	Linux Foundation
 vendor CINTERION	0x1e2d	Cinterion
 vendor AIRTIES		0x1eda	AirTies
+vendor NXP          0x1fc9  NXP
 vendor DLINK		0x2001	D-Link
 vendor PLANEX2		0x2019	Planex Communications
 vendor ENCORE		0x203d	Encore
@@ -2572,6 +2573,9 @@
 product NOVATEL2 U760_DRIVER	0x5030	Novatel Wireless U760 Windows/Mac Driver
 product NOVATEL2 U760		0x6000	Novatel 760USB

+/* NXP products */
+product NXP LPC1XXX         0x000b  NXP LPC1xxx IFLASH
+
 /* Olympus products */
 product OLYMPUS C1		0x0102	C-1 Digital Camera
 product OLYMPUS C700		0x0105	C-700 Ultra Zoom

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-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.