CVS commit: src/sys/dev/scsipi

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 22:06:50 UTC 2024

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
Don't try to discover wedges when the unit isn't online.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2024-02-24 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sat Feb 24 22:06:50 UTC 2024

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
Don't try to discover wedges when the unit isn't online.


To generate a diff of this commit:
cvs rdiff -u -r1.335 -r1.336 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.335 src/sys/dev/scsipi/sd.c:1.336
--- src/sys/dev/scsipi/sd.c:1.335	Sun Aug 28 10:26:37 2022
+++ src/sys/dev/scsipi/sd.c	Sat Feb 24 22:06:49 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $	*/
+/*	$NetBSD: sd.c,v 1.336 2024/02/24 22:06:49 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.336 2024/02/24 22:06:49 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -351,8 +351,9 @@ sdattach(device_t parent, device_t self,
 	}
 	aprint_normal("\n");
 
-	/* Discover wedges on this disk. */
-	dkwedge_discover(>sc_dkdev);
+	/* Discover wedges on this disk if it is online */
+	if (result == SDGP_RESULT_OK)
+		dkwedge_discover(>sc_dkdev);
 
 	/*
 	 * Establish a shutdown hook so that we can ensure that



CVS commit: src/sys/dev/scsipi

2024-01-01 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Jan  1 22:29:49 UTC 2024

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
if_dse.c: s/addredses/addresses/ in comment


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2024-01-01 Thread David H. Gutteridge
Module Name:src
Committed By:   gutteridge
Date:   Mon Jan  1 22:29:49 UTC 2024

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
if_dse.c: s/addredses/addresses/ in comment


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_dse.c
diff -u src/sys/dev/scsipi/if_dse.c:1.4 src/sys/dev/scsipi/if_dse.c:1.5
--- src/sys/dev/scsipi/if_dse.c:1.4	Wed Dec 20 18:09:19 2023
+++ src/sys/dev/scsipi/if_dse.c	Mon Jan  1 22:29:48 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_dse.c,v 1.4 2023/12/20 18:09:19 skrll Exp $ */
+/*	$NetBSD: if_dse.c,v 1.5 2024/01/01 22:29:48 gutteridge Exp $ */
 
 /*
  * Driver for DaynaPORT SCSI/Link SCSI-Ethernet
@@ -300,7 +300,7 @@ static const scsi_dayna_ether_generic	so
 
 #if 0
 /*
- * Compare two Ether/802 addredses for equality, inlined and
+ * Compare two Ether/802 addresses for equality, inlined and
  * unrolled for speed.
  * Note: use this like memcmp()
  */



CVS commit: src/sys/dev/scsipi

2023-12-06 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec  7 07:04:13 UTC 2023

Modified Files:
src/sys/dev/scsipi: scsi_disk.h

Log Message:
s/multiplcation/multiplication/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/scsipi/scsi_disk.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2023-12-06 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Dec  7 07:04:13 UTC 2023

Modified Files:
src/sys/dev/scsipi: scsi_disk.h

Log Message:
s/multiplcation/multiplication/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/scsipi/scsi_disk.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsi_disk.h
diff -u src/sys/dev/scsipi/scsi_disk.h:1.34 src/sys/dev/scsipi/scsi_disk.h:1.35
--- src/sys/dev/scsipi/scsi_disk.h:1.34	Wed Nov 10 16:17:34 2021
+++ src/sys/dev/scsipi/scsi_disk.h	Thu Dec  7 07:04:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsi_disk.h,v 1.34 2021/11/10 16:17:34 msaitoh Exp $	*/
+/*	$NetBSD: scsi_disk.h,v 1.35 2023/12/07 07:04:13 andvar Exp $	*/
 
 /*
  * SCSI-specific interface description
@@ -333,7 +333,7 @@ union scsi_disk_pages {
 		u_int8_t pg_length;	/* page length (should be 0x0a) */
 		u_int8_t flags;		/* cache parameter flags */
 #define	CACHING_RCD	0x01		/* read cache disable */
-#define	CACHING_MF	0x02		/* multiplcation factor */
+#define	CACHING_MF	0x02		/* multiplication factor */
 #define	CACHING_WCE	0x04		/* write cache enable (write-back) */
 #define	CACHING_SIZE	0x08		/* use CACHE SEGMENT SIZE */
 #define	CACHING_DISC	0x10		/* pftch across time discontinuities */



CVS commit: src/sys/dev/scsipi

2022-12-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Dec 22 23:06:11 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
Fix condition for ending the pacet read loop.

len is unsigned 16 bit so testing for less than zero is not valid.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-12-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Dec 22 23:06:11 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
Fix condition for ending the pacet read loop.

len is unsigned 16 bit so testing for less than zero is not valid.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_dse.c
diff -u src/sys/dev/scsipi/if_dse.c:1.2 src/sys/dev/scsipi/if_dse.c:1.3
--- src/sys/dev/scsipi/if_dse.c:1.2	Thu Dec 22 22:39:20 2022
+++ src/sys/dev/scsipi/if_dse.c	Thu Dec 22 23:06:11 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_dse.c,v 1.2 2022/12/22 22:39:20 nat Exp $ */
+/*	$NetBSD: if_dse.c,v 1.3 2022/12/22 23:06:11 nat Exp $ */
 
 /*
  * Driver for DaynaPORT SCSI/Link SCSI-Ethernet
@@ -850,7 +850,7 @@ dse_read(struct dse_softc *sc, uint8_t *
 			len = peek_packet(data);
 		}
 #endif
-		if (len <=0)
+		if (len == 0)
 			break;
 
 #ifdef DSE_DEBUG



CVS commit: src/sys/dev/scsipi

2022-12-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Dec 22 22:39:20 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
Remove unused commented out code.
Remove unintentional stray debug printfs.
Fix DSE_DEBUG build.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-12-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Thu Dec 22 22:39:20 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_dse.c

Log Message:
Remove unused commented out code.
Remove unintentional stray debug printfs.
Fix DSE_DEBUG build.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/scsipi/if_dse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_dse.c
diff -u src/sys/dev/scsipi/if_dse.c:1.1 src/sys/dev/scsipi/if_dse.c:1.2
--- src/sys/dev/scsipi/if_dse.c:1.1	Thu Dec 22 11:05:55 2022
+++ src/sys/dev/scsipi/if_dse.c	Thu Dec 22 22:39:20 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_dse.c,v 1.1 2022/12/22 11:05:55 nat Exp $ */
+/*	$NetBSD: if_dse.c,v 1.2 2022/12/22 22:39:20 nat Exp $ */
 
 /*
  * Driver for DaynaPORT SCSI/Link SCSI-Ethernet
@@ -561,11 +561,11 @@ dse_send_worker(struct work *wk, void *c
 			m = m0 = m_free(m);
 		}
 		if (len < DSE_MINSIZE) {
-#ifdef SEDEBUG
+#ifdef DSE_DEBUG
 			if (sc->sc_debug)
-aprnt_error_dev(sc->sc_dev,
+aprint_error_dev(sc->sc_dev,
 "packet size %d (%zu) < %d\n", len,
-cp - (u_char *)sc->sc_tbuf, SEMINSIZE);
+cp - (u_char *)sc->sc_tbuf, DSE_MINSIZE);
 #endif
 			memset(cp, 0, DSE_MINSIZE - len);
 			len = DSE_MINSIZE;
@@ -854,8 +854,8 @@ dse_read(struct dse_softc *sc, uint8_t *
 			break;
 
 #ifdef DSE_DEBUG
-		aprint_error_dev("dse_read: datalen = %d, packetlen = %d, "
-		"proto = 0x%04x\n", datalen, len,
+		aprint_error_dev(sc->sc_dev, "dse_read: datalen = %d, packetlen"
+		" = %d, proto = 0x%04x\n", datalen, len,
 		ntohs(((struct ether_header *)data)->ether_type));
 #endif
 		if ((len < (DSE_MINSIZE + ETHER_CRC_LEN)) ||
@@ -865,7 +865,6 @@ dse_read(struct dse_softc *sc, uint8_t *
 			"%d; dropping\n", len);
 #endif
 			if_statinc(ifp, if_ierrors);
-printf("LEN %d\n",len);
 			break;
 		}
 
@@ -874,10 +873,9 @@ printf("LEN %d\n",len);
 		if (m == NULL) {
 #ifdef DSE_DEBUG
 			if (sc->sc_debug)
-aprint_error_dev("dse_read: dse_get returned "
-"null\n");
+aprint_error_dev(sc->sc_dev, "dse_read: "
+"dse_get returned null\n");
 #endif
-printf("M null\n");
 			if_statinc(ifp, if_ierrors);
 			goto next_packet;
 		}
@@ -1146,7 +1144,6 @@ dse_ioctl(struct ifnet *ifp, u_long cmd,
 		switch (ifa->ifa_addr->sa_family) {
 #ifdef INET
 		case AF_INET:
-	//		sc->protos |= (PROTO_IP | PROTO_ARP | PROTO_REVARP);
 			if ((error = dse_init(sc)) != 0)
 break;
 			arp_ifinit(ifp, ifa);
@@ -1154,7 +1151,6 @@ dse_ioctl(struct ifnet *ifp, u_long cmd,
 #endif
 #ifdef NETATALK
 		case AF_APPLETALK:
-	//		sc->protos |= (PROTO_AT | PROTO_AARP);
 			if ((error = dse_init(sc)) != 0)
 break;
 			break;
@@ -1233,7 +1229,7 @@ dse_ioctl(struct ifnet *ifp, u_long cmd,
 			mutex_exit(>sc_iflock);
 			break;
 		}
-#ifdef SEDEBUG
+#ifdef DSE_DEBUG
 		if (ifp->if_flags & IFF_DEBUG)
 			sc->sc_debug = 1;
 		else



CVS commit: src/sys/dev/scsipi

2022-10-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Oct 15 18:42:49 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Add PQUIRK_ONLYBIG for Oracle OCI BlockVolumes.

Oracle cloud BlockVolumes do not appear to support SCSI READ6 or WRITE6
commands, so set PQUIRK_ONLYBIG to avoid it here.


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.302 src/sys/dev/scsipi/scsiconf.c:1.303
--- src/sys/dev/scsipi/scsiconf.c:1.302	Thu Apr 14 16:50:26 2022
+++ src/sys/dev/scsipi/scsiconf.c	Sat Oct 15 18:42:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.302 2022/04/14 16:50:26 pgoyette Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.303 2022/10/15 18:42:49 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.302 2022/04/14 16:50:26 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.303 2022/10/15 18:42:49 jmcneill Exp $");
 
 #include 
 #include 
@@ -792,6 +792,8 @@ static const struct scsi_quirk_inquiry_p
 	 "SEAGATE ", "SX336704LC"   , ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
 	{{T_DIRECT, T_FIXED,
 	 "SEAGATE ", "SX173404LC",   ""}, PQUIRK_CAP_SYNC | PQUIRK_CAP_WIDE16},
+	{{T_DIRECT, T_FIXED,
+	 "ORACLE",   "BlockVolume",	 ""},	  PQUIRK_ONLYBIG},
 
 	{{T_DIRECT, T_REMOV,
 	 "IOMEGA", "ZIP 100",		 "J.03"}, PQUIRK_NOLUNS|PQUIRK_NOSYNC},



CVS commit: src/sys/dev/scsipi

2022-10-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Oct 15 18:42:49 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Add PQUIRK_ONLYBIG for Oracle OCI BlockVolumes.

Oracle cloud BlockVolumes do not appear to support SCSI READ6 or WRITE6
commands, so set PQUIRK_ONLYBIG to avoid it here.


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-08-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Aug 29 07:32:46 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Make this build again.  Sorry about that.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.117 src/sys/dev/scsipi/if_se.c:1.118
--- src/sys/dev/scsipi/if_se.c:1.117	Sun Aug 28 09:48:12 2022
+++ src/sys/dev/scsipi/if_se.c	Mon Aug 29 07:32:46 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.117 2022/08/28 09:48:12 skrll Exp $	*/
+/*	$NetBSD: if_se.c,v 1.118 2022/08/29 07:32:46 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.117 2022/08/28 09:48:12 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.118 2022/08/29 07:32:46 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -207,7 +207,9 @@ static void	se_ifstart(struct ifnet *);
 
 static void	sedone(struct scsipi_xfer *, int);
 static int	se_ioctl(struct ifnet *, u_long, void *);
+#if 0
 static void	sewatchdog(struct ifnet *);
+#endif
 
 #if 0
 static inline uint16_t ether_cmp(void *, void *);
@@ -217,7 +219,9 @@ static void	se_recv_worker(struct work *
 static void	se_recv(struct se_softc *);
 static struct mbuf *se_get(struct se_softc *, char *, int);
 static int	se_read(struct se_softc *, char *, int);
+#if 0
 static void	se_reset(struct se_softc *);
+#endif
 static int	se_add_proto(struct se_softc *, int);
 static int	se_get_addr(struct se_softc *, uint8_t *);
 static int	se_set_media(struct se_softc *, int);
@@ -778,7 +782,6 @@ sewatchdog(struct ifnet *ifp)
 
 	se_reset(sc);
 }
-#endif
 
 static void
 se_reset(struct se_softc *sc)
@@ -794,6 +797,7 @@ se_reset(struct se_softc *sc)
 #endif
 	se_init(sc);
 }
+#endif
 
 static int
 se_add_proto(struct se_softc *sc, int proto)



CVS commit: src/sys/dev/scsipi

2022-08-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Aug 29 07:32:46 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Make this build again.  Sorry about that.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-08-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 28 10:26:37 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c sdvar.h

Log Message:
Don't fetch data beyond end of inquiry buffer, which, here, is not
NUL-terminated.

Reduce target buffer to needed size (product name + NUL terminator).


To generate a diff of this commit:
cvs rdiff -u -r1.334 -r1.335 src/sys/dev/scsipi/sd.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/scsipi/sdvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.334 src/sys/dev/scsipi/sd.c:1.335
--- src/sys/dev/scsipi/sd.c:1.334	Mon Mar 28 12:39:46 2022
+++ src/sys/dev/scsipi/sd.c	Sun Aug 28 10:26:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.334 2022/03/28 12:39:46 riastradh Exp $	*/
+/*	$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.334 2022/03/28 12:39:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.335 2022/08/28 10:26:37 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -258,9 +258,8 @@ sdattach(device_t parent, device_t self,
 	SC_DEBUG(periph, SCSIPI_DB2, ("sdattach: "));
 
 	sd->type = (sa->sa_inqbuf.type & SID_TYPE);
-	strncpy(sd->name, sa->sa_inqbuf.product, sizeof(sd->name));
-
-	strncpy(sd->typename, sa->sa_inqbuf.product, sizeof(sd->typename));
+	memcpy(sd->name, sa->sa_inqbuf.product, uimin(16, sizeof(sd->name)));
+	memcpy(sd->typename, sa->sa_inqbuf.product, uimin(16, sizeof(sd->typename)));
 
 	if (sd->type == T_SIMPLE_DIRECT)
 		periph->periph_quirks |= PQUIRK_ONLYBIG | PQUIRK_NOBIGMODESENSE;

Index: src/sys/dev/scsipi/sdvar.h
diff -u src/sys/dev/scsipi/sdvar.h:1.39 src/sys/dev/scsipi/sdvar.h:1.40
--- src/sys/dev/scsipi/sdvar.h:1.39	Tue Mar 19 06:59:40 2019
+++ src/sys/dev/scsipi/sdvar.h	Sun Aug 28 10:26:37 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdvar.h,v 1.39 2019/03/19 06:59:40 mlelstv Exp $	*/
+/*	$NetBSD: sdvar.h,v 1.40 2022/08/28 10:26:37 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -88,7 +88,7 @@ struct sd_softc {
 	callout_t sc_callout;
 	u_int8_t type;
 	char name[16]; /* product name, for default disklabel */
-	char typename[128+4+1]; /* stored in disk info */
+	char typename[16+1]; /* stored in disk info */
 };
 
 #define	SDGP_RESULT_OK		0	/* parameters obtained */



CVS commit: src/sys/dev/scsipi

2022-08-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Aug 28 10:26:37 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c sdvar.h

Log Message:
Don't fetch data beyond end of inquiry buffer, which, here, is not
NUL-terminated.

Reduce target buffer to needed size (product name + NUL terminator).


To generate a diff of this commit:
cvs rdiff -u -r1.334 -r1.335 src/sys/dev/scsipi/sd.c
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/scsipi/sdvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-08-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Aug 28 09:48:12 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
se(4): don't set if_watchdog as it's not used.

if_timer is never set in this driver and so if_watchdog will never be
called.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.116 src/sys/dev/scsipi/if_se.c:1.117
--- src/sys/dev/scsipi/if_se.c:1.116	Thu Jul  7 06:11:28 2022
+++ src/sys/dev/scsipi/if_se.c	Sun Aug 28 09:48:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.116 2022/07/07 06:11:28 skrll Exp $	*/
+/*	$NetBSD: if_se.c,v 1.117 2022/08/28 09:48:12 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.116 2022/07/07 06:11:28 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.117 2022/08/28 09:48:12 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -359,7 +359,7 @@ seattach(device_t parent, device_t self,
 	ifp->if_softc = sc;
 	ifp->if_start = se_ifstart;
 	ifp->if_ioctl = se_ioctl;
-	ifp->if_watchdog = sewatchdog;
+	ifp->if_watchdog = NULL;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_extflags = IFEF_MPSAFE;
 	IFQ_SET_READY(>if_snd);
@@ -767,7 +767,7 @@ se_read(struct se_softc *sc, char *data,
 	return (n);
 }
 
-
+#if 0
 static void
 sewatchdog(struct ifnet *ifp)
 {
@@ -778,6 +778,7 @@ sewatchdog(struct ifnet *ifp)
 
 	se_reset(sc);
 }
+#endif
 
 static void
 se_reset(struct se_softc *sc)



CVS commit: src/sys/dev/scsipi

2022-08-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Aug 28 09:48:12 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
se(4): don't set if_watchdog as it's not used.

if_timer is never set in this driver and so if_watchdog will never be
called.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-07-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jul  7 06:11:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.115 src/sys/dev/scsipi/if_se.c:1.116
--- src/sys/dev/scsipi/if_se.c:1.115	Sat Jan  1 10:32:29 2022
+++ src/sys/dev/scsipi/if_se.c	Thu Jul  7 06:11:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.115 2022/01/01 10:32:29 msaitoh Exp $	*/
+/*	$NetBSD: if_se.c,v 1.116 2022/07/07 06:11:28 skrll Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.115 2022/01/01 10:32:29 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.116 2022/07/07 06:11:28 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -465,7 +465,7 @@ se_ifstart(struct ifnet *ifp)
 	if (!sc->sc_send_work_pending)  {
 		sc->sc_send_work_pending = true;
 		workqueue_enqueue(sc->sc_send_wq, >sc_send_work, NULL);
-	} 
+	}
 	/* else: nothing to do - work is already queued */
 	mutex_exit(>sc_iflock);
 }
@@ -915,7 +915,7 @@ se_init(struct se_softc *sc)
 			sc->sc_recv_work_pending = true;
 			workqueue_enqueue(sc->sc_recv_wq, >sc_recv_work,
 			NULL);
-		} 
+		}
 		mutex_exit(>sc_iflock);
 		ifp->if_flags &= ~IFF_OACTIVE;
 		mutex_enter(>sc_iflock);
@@ -923,7 +923,7 @@ se_init(struct se_softc *sc)
 			sc->sc_send_work_pending = true;
 			workqueue_enqueue(sc->sc_send_wq, >sc_send_work,
 			NULL);
-		} 
+		}
 		mutex_exit(>sc_iflock);
 	}
 	return (error);



CVS commit: src/sys/dev/scsipi

2022-07-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jul  7 06:11:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-06-26 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Jun 26 21:00:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
s/Ramdom/Random/ in comments.


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.354 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.353 src/sys/dev/scsipi/cd.c:1.354
--- src/sys/dev/scsipi/cd.c:1.353	Tue Oct 12 08:36:29 2021
+++ src/sys/dev/scsipi/cd.c	Sun Jun 26 21:00:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.353 2021/10/12 08:36:29 andvar Exp $	*/
+/*	$NetBSD: cd.c,v 1.354 2022/06/26 21:00:28 andvar Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.353 2021/10/12 08:36:29 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.354 2022/06/26 21:00:28 andvar Exp $");
 
 #include 
 #include 
@@ -2461,7 +2461,7 @@ mmc_profile2class(uint16_t mmc_profile)
 		return MMC_CLASS_DVD;
 	case 0x40 : /* BD-ROM  */
 	case 0x41 : /* BD-R Sequential recording (SRM) */
-	case 0x42 : /* BD-R Ramdom Recording (RRM) */
+	case 0x42 : /* BD-R Random Recording (RRM) */
 	case 0x43 : /* BD-RE */
 		return MMC_CLASS_BD;
 	}
@@ -3334,7 +3334,7 @@ mmc_do_closetrack(struct scsipi_periph *
 	case 0x12 : /* DVD-RAM */
 	case 0x1a : /* DVD+RW  */
 	case 0x2a : /* DVD+RW Dual layer */
-	case 0x42 : /* BD-R Ramdom Recording (RRM) */
+	case 0x42 : /* BD-R Random Recording (RRM) */
 	case 0x43 : /* BD-RE */
 	case 0x52 : /* HD DVD-RW ; DVD-RAM like */
 		return EINVAL;
@@ -3393,7 +3393,7 @@ mmc_do_close_or_finalise(struct scsipi_p
 	case 0x12 : /* DVD-RAM */
 	case 0x1a : /* DVD+RW  */
 	case 0x2a : /* DVD+RW Dual layer */
-	case 0x42 : /* BD-R Ramdom Recording (RRM) */
+	case 0x42 : /* BD-R Random Recording (RRM) */
 	case 0x43 : /* BD-RE */
 	case 0x52 : /* HD DVD-RW; DVD-RAM like */
 		return EINVAL;



CVS commit: src/sys/dev/scsipi

2022-06-26 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Sun Jun 26 21:00:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
s/Ramdom/Random/ in comments.


To generate a diff of this commit:
cvs rdiff -u -r1.353 -r1.354 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Mar 28 12:39:47 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
sd(4): Use d_cfdriver/devtounit to avoid open/detach races.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.333 src/sys/dev/scsipi/sd.c:1.334
--- src/sys/dev/scsipi/sd.c:1.333	Thu Jan 27 18:44:49 2022
+++ src/sys/dev/scsipi/sd.c	Mon Mar 28 12:39:46 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.333 2022/01/27 18:44:49 jakllsch Exp $	*/
+/*	$NetBSD: sd.c,v 1.334 2022/03/28 12:39:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.333 2022/01/27 18:44:49 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.334 2022/03/28 12:39:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -167,6 +167,8 @@ const struct bdevsw sd_bdevsw = {
 	.d_dump = sddump,
 	.d_psize = sdsize,
 	.d_discard = nodiscard,
+	.d_cfdriver = _cd,
+	.d_devtounit = disklabel_dev_unit,
 	.d_flag = D_DISK | D_MPSAFE
 };
 
@@ -182,6 +184,8 @@ const struct cdevsw sd_cdevsw = {
 	.d_mmap = nommap,
 	.d_kqfilter = nokqfilter,
 	.d_discard = nodiscard,
+	.d_cfdriver = _cd,
+	.d_devtounit = disklabel_dev_unit,
 	.d_flag = D_DISK | D_MPSAFE
 };
 



CVS commit: src/sys/dev/scsipi

2022-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Mar 28 12:39:47 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
sd(4): Use d_cfdriver/devtounit to avoid open/detach races.


To generate a diff of this commit:
cvs rdiff -u -r1.333 -r1.334 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-03-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 12 16:57:16 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
scsi(9): Handle bogus number of LUNs in SCSI_REPORT_LUNS.

Reported-by: syzbot+76ef9084533d4bcce...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.299 src/sys/dev/scsipi/scsiconf.c:1.300
--- src/sys/dev/scsipi/scsiconf.c:1.299	Sat Mar 12 15:32:32 2022
+++ src/sys/dev/scsipi/scsiconf.c	Sat Mar 12 16:57:15 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.299 2022/03/12 15:32:32 riastradh Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.300 2022/03/12 16:57:15 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.299 2022/03/12 15:32:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.300 2022/03/12 16:57:15 riastradh Exp $");
 
 #include 
 #include 
@@ -400,7 +400,7 @@ scsi_report_luns(struct scsibus_softc *s
 	uint16_t tmp;
 
 	int error;
-	size_t i, rlrlen;
+	size_t i, rlrlen, rlrlenmin;
 
 	memset(, 0, sizeof(replun));
 
@@ -421,7 +421,7 @@ scsi_report_luns(struct scsibus_softc *s
 		goto end2;
 	}
 
-	rlrlen = sizeof(*rlr) + sizeof(*lunp) * 1;
+	rlrlen = rlrlenmin = sizeof(*rlr) + sizeof(*lunp) * 1;
 
 again:
 	rlr = kmem_zalloc(rlrlen, KM_SLEEP);
@@ -443,6 +443,10 @@ again:
 		16383 * sizeof(*lunp));
 		kmem_free(rlr, old_rlrlen);
 		rlr = NULL;
+		if (rlrlen < rlrlenmin) {
+			error = EIO;
+			goto end;
+		}
 		goto again;
 	}
 



CVS commit: src/sys/dev/scsipi

2022-03-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 12 16:57:16 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
scsi(9): Handle bogus number of LUNs in SCSI_REPORT_LUNS.

Reported-by: syzbot+76ef9084533d4bcce...@syzkaller.appspotmail.com


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Feb  5 17:32:59 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Initialize "replun" -- found with KMSAN.


To generate a diff of this commit:
cvs rdiff -u -r1.297 -r1.298 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.297 src/sys/dev/scsipi/scsiconf.c:1.298
--- src/sys/dev/scsipi/scsiconf.c:1.297	Sat Jan 29 11:20:30 2022
+++ src/sys/dev/scsipi/scsiconf.c	Sat Feb  5 17:32:59 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.297 2022/01/29 11:20:30 martin Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.298 2022/02/05 17:32:59 hannken Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.297 2022/01/29 11:20:30 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.298 2022/02/05 17:32:59 hannken Exp $");
 
 #include 
 #include 
@@ -399,6 +399,8 @@ scsi_report_luns(struct scsibus_softc *s
 	int error;
 	size_t i, rlrlen;
 
+	memset(, 0, sizeof(replun));
+
 	periph = scsipi_alloc_periph(M_WAITOK);
 	periph->periph_channel = chan;
 	periph->periph_switch = _probe_dev;



CVS commit: src/sys/dev/scsipi

2022-02-05 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Sat Feb  5 17:32:59 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Initialize "replun" -- found with KMSAN.


To generate a diff of this commit:
cvs rdiff -u -r1.297 -r1.298 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jan 29 11:20:30 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
In some cases the gcc optimizer is not smart enough to figure out why
the luns and nluns variables are never actually used when they are not
initialized - so initialize them always.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-29 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jan 29 11:20:30 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
In some cases the gcc optimizer is not smart enough to figure out why
the luns and nluns variables are never actually used when they are not
initialized - so initialize them always.


To generate a diff of this commit:
cvs rdiff -u -r1.296 -r1.297 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.296 src/sys/dev/scsipi/scsiconf.c:1.297
--- src/sys/dev/scsipi/scsiconf.c:1.296	Fri Jan 28 18:23:28 2022
+++ src/sys/dev/scsipi/scsiconf.c	Sat Jan 29 11:20:30 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.297 2022/01/29 11:20:30 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.297 2022/01/29 11:20:30 martin Exp $");
 
 #include 
 #include 
@@ -477,8 +477,8 @@ end2:
 static void
 scsi_discover_luns(struct scsibus_softc *sc, int target, int minlun, int maxlun)
 {
-	uint16_t *luns;
-	size_t nluns;
+	uint16_t *luns = NULL;	/* XXX gcc */
+	size_t nluns = 0;	/* XXX gcc */
 
 	if (scsi_report_luns(sc, target, , ) == 0) {
 		for (size_t i = 0; i < nluns; i++)



CVS commit: src/sys/dev/scsipi

2022-01-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 28 18:23:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Factor out the lun detection code to simplify control flow.


To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.295 src/sys/dev/scsipi/scsiconf.c:1.296
--- src/sys/dev/scsipi/scsiconf.c:1.295	Fri Jan 28 09:02:45 2022
+++ src/sys/dev/scsipi/scsiconf.c	Fri Jan 28 13:23:28 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $");
 
 #include 
 #include 
@@ -474,6 +474,30 @@ end2:
 	return error;
 }
 
+static void
+scsi_discover_luns(struct scsibus_softc *sc, int target, int minlun, int maxlun)
+{
+	uint16_t *luns;
+	size_t nluns;
+
+	if (scsi_report_luns(sc, target, , ) == 0) {
+		for (size_t i = 0; i < nluns; i++)
+			if (luns[i] >= minlun && luns[i] <= maxlun)
+scsi_probe_device(sc, target, luns[i]);
+		kmem_free(luns, sizeof(*luns) * nluns);
+		return;
+	}
+
+	for (int lun = minlun; lun <= maxlun; lun++) {
+		/*
+		 * See if there's a device present, and configure it.
+		 */
+		if (scsi_probe_device(sc, target, lun) == 0)
+			break;
+		/* otherwise something says we should look further */
+	}
+}
+
 /*
  * Probe the requested scsi bus. It must be already set up.
  * target and lun optionally narrow the search if not -1
@@ -482,8 +506,6 @@ int
 scsi_probe_bus(struct scsibus_softc *sc, int target, int lun)
 {
 	struct scsipi_channel *chan = sc->sc_channel;
-	uint16_t *luns;
-	size_t nluns = 0; /* XXXGCC */
 	int maxtarget, mintarget, maxlun, minlun;
 	int error;
 
@@ -516,25 +538,8 @@ scsi_probe_bus(struct scsibus_softc *sc,
 	for (target = mintarget; target <= maxtarget; target++) {
 		if (target == chan->chan_id)
 			continue;
-		if (scsi_report_luns(sc, target, , ) == 0) {
-			for (size_t i = 0; i < nluns; i++)
-if (luns[i] >= minlun && luns[i] <= maxlun)
-	scsi_probe_device(sc, target, luns[i]);
-		} else
-		for (lun = minlun; lun <= maxlun; lun++) {
-			/*
-			 * See if there's a device present, and configure it.
-			 */
-			if (scsi_probe_device(sc, target, lun) == 0)
-break;
-			/* otherwise something says we should look further */
-		}
 
-		if (luns != NULL) {
-			kmem_free(luns, sizeof(*luns) * nluns);
-			luns = NULL;
-			nluns = 0;
-		}
+		scsi_discover_luns(sc, target, minlun, maxlun);
 
 		/*
 		 * Now that we've discovered all of the LUNs on this



CVS commit: src/sys/dev/scsipi

2022-01-28 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 28 18:23:28 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Factor out the lun detection code to simplify control flow.


To generate a diff of this commit:
cvs rdiff -u -r1.295 -r1.296 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-28 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Jan 28 14:02:45 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
shut up GCC about possibly-uninit; some KNF


To generate a diff of this commit:
cvs rdiff -u -r1.294 -r1.295 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.294 src/sys/dev/scsipi/scsiconf.c:1.295
--- src/sys/dev/scsipi/scsiconf.c:1.294	Thu Jan 27 18:37:02 2022
+++ src/sys/dev/scsipi/scsiconf.c	Fri Jan 28 14:02:45 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.294 2022/01/27 18:37:02 jakllsch Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.294 2022/01/27 18:37:02 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $");
 
 #include 
 #include 
@@ -482,6 +482,8 @@ int
 scsi_probe_bus(struct scsibus_softc *sc, int target, int lun)
 {
 	struct scsipi_channel *chan = sc->sc_channel;
+	uint16_t *luns;
+	size_t nluns = 0; /* XXXGCC */
 	int maxtarget, mintarget, maxlun, minlun;
 	int error;
 
@@ -509,9 +511,6 @@ scsi_probe_bus(struct scsibus_softc *sc,
 	 */
 	scsipi_adapter_ioctl(chan, SCBUSIOLLSCAN, NULL, 0, curproc);
 
-	uint16_t *luns;
-	size_t nluns;
-
 	if ((error = scsipi_adapter_addref(chan->chan_adapter)) != 0)
 		goto ret;
 	for (target = mintarget; target <= maxtarget; target++) {



CVS commit: src/sys/dev/scsipi

2022-01-28 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Jan 28 14:02:45 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
shut up GCC about possibly-uninit; some KNF


To generate a diff of this commit:
cvs rdiff -u -r1.294 -r1.295 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-27 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Jan 27 18:44:49 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
use powerof2() in sd_validate_blksize()


To generate a diff of this commit:
cvs rdiff -u -r1.332 -r1.333 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.332 src/sys/dev/scsipi/sd.c:1.333
--- src/sys/dev/scsipi/sd.c:1.332	Sun May 30 06:46:46 2021
+++ src/sys/dev/scsipi/sd.c	Thu Jan 27 18:44:49 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.332 2021/05/30 06:46:46 dholland Exp $	*/
+/*	$NetBSD: sd.c,v 1.333 2022/01/27 18:44:49 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.332 2021/05/30 06:46:46 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.333 2022/01/27 18:44:49 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -1311,19 +1311,14 @@ static int
 sd_validate_blksize(struct scsipi_periph *periph, int len)
 {
 
-	switch (len) {
-	case 256:
-	case 512:
-	case 1024:
-	case 2048:
-	case 4096:
+	if (len >= 256 && powerof2(len) && len <= 4096) {
 		return 1;
 	}
 
 	if (periph) {
 		scsipi_printaddr(periph);
 		printf("%s sector size: 0x%x.  Defaulting to %d bytes.\n",
-		(len ^ (1 << (ffs(len) - 1))) ?
+		!powerof2(len) ?
 		"preposterous" : "unsupported",
 		len, SD_DEFAULT_BLKSIZE);
 	}



CVS commit: src/sys/dev/scsipi

2022-01-27 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Jan 27 18:44:49 UTC 2022

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
use powerof2() in sd_validate_blksize()


To generate a diff of this commit:
cvs rdiff -u -r1.332 -r1.333 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-27 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Jan 27 18:37:02 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsi_spc.h scsiconf.c

Log Message:
Try REPORT LUNS command to enumerate logical units.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/scsipi/scsi_spc.h
cvs rdiff -u -r1.293 -r1.294 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2022-01-27 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Jan 27 18:37:02 UTC 2022

Modified Files:
src/sys/dev/scsipi: scsi_spc.h scsiconf.c

Log Message:
Try REPORT LUNS command to enumerate logical units.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/scsipi/scsi_spc.h
cvs rdiff -u -r1.293 -r1.294 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsi_spc.h
diff -u src/sys/dev/scsipi/scsi_spc.h:1.6 src/sys/dev/scsipi/scsi_spc.h:1.7
--- src/sys/dev/scsipi/scsi_spc.h:1.6	Thu Mar 28 10:44:29 2019
+++ src/sys/dev/scsipi/scsi_spc.h	Thu Jan 27 18:37:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsi_spc.h,v 1.6 2019/03/28 10:44:29 kardel Exp $	*/
+/*	$NetBSD: scsi_spc.h,v 1.7 2022/01/27 18:37:02 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -404,6 +404,30 @@ struct scsi_reserve_release_10_idparam {
 /*
  * REPORT LUNS
  */
+#define SCSI_REPORT_LUNS		0xa0
+
+struct scsi_report_luns {
+	uint8_t opcode;
+	uint8_t reserved1;
+	uint8_t selectreport;
+#define SELECTREPORT_NORMAL		0x00
+#define SELECTREPORT_WELLKNOWN		0x01
+#define SELECTREPORT_ALL		0x02
+	uint8_t reserved3[3];
+	uint8_t alloclen[4];
+	uint8_t reserved10;
+	uint8_t control;
+};
+
+struct scsi_report_luns_header {
+	uint8_t	length[4];		/* in bytes, not including header */
+	uint8_t _res4[4];
+	/* followed by array of: */
+};
+
+struct scsi_report_luns_lun {
+	uint8_t lun[8];
+};
 
 /*
  * MAINTENANCE_IN[REPORT SUPPORTED OPERATION CODES]

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.293 src/sys/dev/scsipi/scsiconf.c:1.294
--- src/sys/dev/scsipi/scsiconf.c:1.293	Tue Dec 21 22:53:21 2021
+++ src/sys/dev/scsipi/scsiconf.c	Thu Jan 27 18:37:02 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.294 2022/01/27 18:37:02 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.294 2022/01/27 18:37:02 jakllsch Exp $");
 
 #include 
 #include 
@@ -64,6 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -370,6 +371,109 @@ scsibusdetach(device_t self, int flags)
 	return 0;
 }
 
+static int
+lun_compar(const void *a, const void *b)
+{
+	const uint16_t * const la = a, * const lb = b;
+
+	if (*la < *lb)
+		return -1;
+	if (*la > *lb)
+		return 1;
+	return 0;
+}
+
+static int
+scsi_report_luns(struct scsibus_softc *sc, int target,
+uint16_t ** const luns, size_t *nluns)
+{
+	struct scsi_report_luns replun;
+	struct scsi_report_luns_header *rlr;
+	struct scsi_report_luns_lun *lunp;
+
+	struct scsipi_channel *chan = sc->sc_channel;
+	struct scsipi_inquiry_data inqbuf;
+	struct scsipi_periph *periph;
+	uint16_t tmp;
+
+	int error;
+	size_t i, rlrlen;
+
+	periph = scsipi_alloc_periph(M_WAITOK);
+	periph->periph_channel = chan;
+	periph->periph_switch = _probe_dev;
+
+	periph->periph_target = target;
+	periph->periph_lun = 0;
+	periph->periph_quirks = chan->chan_defquirks;
+
+	if ((error = scsipi_inquire(periph, ,
+	XS_CTL_DISCOVERY | XS_CTL_SILENT)))
+		goto end2;
+	periph->periph_version = inqbuf.version & SID_ANSII;
+	if (periph->periph_version < 3) {
+		error = ENOTSUP;
+		goto end2;
+	}
+
+	rlrlen = sizeof(*rlr) + sizeof(*lunp) * 1;
+
+again:
+	rlr = kmem_zalloc(rlrlen, KM_SLEEP);
+
+	replun.opcode = SCSI_REPORT_LUNS;
+	replun.selectreport = SELECTREPORT_NORMAL;
+	_lto4b(rlrlen, replun.alloclen);
+
+	error = scsipi_command(periph, (void *), sizeof(replun),
+	(void *)rlr, rlrlen, SCSIPIRETRIES, 1, NULL,
+	XS_CTL_DATA_IN | XS_CTL_DISCOVERY | XS_CTL_SILENT);
+	if (error)
+		goto end;
+
+	if (sizeof(*rlr) + _4btol(rlr->length) > rlrlen &&
+	sizeof(*rlr) + _4btol(rlr->length) <= 32) {
+		const size_t old_rlrlen = rlrlen;
+		rlrlen = sizeof(*rlr) + uimin(_4btol(rlr->length),
+		16383 * sizeof(*lunp));
+		kmem_free(rlr, old_rlrlen);
+		rlr = NULL;
+		goto again;
+	}
+
+	KASSERT(nluns != NULL);
+	*nluns = (rlrlen - sizeof(*rlr)) / sizeof(*lunp);
+
+	KASSERT(luns != NULL);
+	*luns = kmem_alloc(*nluns * sizeof(**luns), KM_SLEEP);
+
+	for (i = 0; i < *nluns; i++) {
+		lunp = &((struct scsi_report_luns_lun *)[1])[i];
+		switch (lunp->lun[0] & 0xC0) {
+		default:
+			scsi_print_addr(periph);
+			printf("LUN %016"PRIx64" ignored\n", _8btol(lunp->lun));
+			(*luns)[i] = 0;
+			break;
+		case 0x40:
+			(*luns)[i] = _2btol(>lun[0]) & 0x3FFF;
+			break;
+		case 0x00:
+			(*luns)[i] = _2btol(>lun[0]) & 0x00FF;
+			break;
+		}
+	}
+
+	kheapsort(*luns, *nluns, sizeof(**luns), lun_compar, );
+
+end:
+	if (rlr)
+		kmem_free(rlr, rlrlen);
+end2:
+	scsipi_free_periph(periph);
+	return error;
+}

CVS commit: src/sys/dev/scsipi

2021-12-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Dec 21 22:53:21 UTC 2021

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
scsi(4): Take kernel lock around entry into autoconf.

This code paths is entered by kthreads marked MP-safe, not just from
autoconf.

I'm not sure this is sufficient -- it's not clear to me whether
anything prevents concurrently scanning the same target.  Someone with
a better understanding of scsi(4) locking will have to audit this.

(For example, maybe it is guaranteed only to happen only either (a)
in autoconf, or (b) in a thread that doesn't start until autoconf is
done.  But I don't know -- and if it is this, it should be asserted
so we can verify it.)


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.292 src/sys/dev/scsipi/scsiconf.c:1.293
--- src/sys/dev/scsipi/scsiconf.c:1.292	Sat Aug  7 16:19:16 2021
+++ src/sys/dev/scsipi/scsiconf.c	Tue Dec 21 22:53:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.292 2021/08/07 16:19:16 thorpej Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.292 2021/08/07 16:19:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.293 2021/12/21 22:53:21 riastradh Exp $");
 
 #include 
 #include 
@@ -1012,6 +1012,7 @@ scsi_probe_device(struct scsibus_softc *
 	locs[SCSIBUSCF_TARGET] = target;
 	locs[SCSIBUSCF_LUN] = lun;
 
+	KERNEL_LOCK(1, NULL);
 	if ((cf = config_search(sc->sc_dev, ,
 CFARGS(.submatch = config_stdsubmatch,
    .locators = locs))) != NULL) {
@@ -1034,9 +1035,11 @@ scsi_probe_device(struct scsibus_softc *
 		 */
 		config_attach(sc->sc_dev, cf, , scsibusprint,
 		CFARGS(.locators = locs));
+		KERNEL_UNLOCK_ONE(NULL);
 	} else {
 		scsibusprint(, device_xname(sc->sc_dev));
 		aprint_normal(" not configured\n");
+		KERNEL_UNLOCK_ONE(NULL);
 		goto bad;
 	}
 



CVS commit: src/sys/dev/scsipi

2021-12-21 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Dec 21 22:53:21 UTC 2021

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
scsi(4): Take kernel lock around entry into autoconf.

This code paths is entered by kthreads marked MP-safe, not just from
autoconf.

I'm not sure this is sufficient -- it's not clear to me whether
anything prevents concurrently scanning the same target.  Someone with
a better understanding of scsi(4) locking will have to audit this.

(For example, maybe it is guaranteed only to happen only either (a)
in autoconf, or (b) in a thread that doesn't start until autoconf is
done.  But I don't know -- and if it is this, it should be asserted
so we can verify it.)


To generate a diff of this commit:
cvs rdiff -u -r1.292 -r1.293 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2021-09-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Sep 26 14:57:19 UTC 2021

Modified Files:
src/sys/dev/scsipi: ch.c

Log Message:
Use seltrue_filtops rather than rolling our own with filt_seltrue.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/scsipi/ch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/ch.c
diff -u src/sys/dev/scsipi/ch.c:1.94 src/sys/dev/scsipi/ch.c:1.95
--- src/sys/dev/scsipi/ch.c:1.94	Sun Sep 26 01:16:09 2021
+++ src/sys/dev/scsipi/ch.c	Sun Sep 26 14:57:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ch.c,v 1.94 2021/09/26 01:16:09 thorpej Exp $	*/
+/*	$NetBSD: ch.c,v 1.95 2021/09/26 14:57:19 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.94 2021/09/26 01:16:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.95 2021/09/26 14:57:19 thorpej Exp $");
 
 #include 
 #include 
@@ -494,13 +494,6 @@ static const struct filterops chread_fil
 	.f_event = filt_chread,
 };
 
-static const struct filterops chwrite_filtops = {
-	.f_flags = FILTEROP_ISFD,
-	.f_attach = NULL,
-	.f_detach = filt_chdetach,
-	.f_event = filt_seltrue,
-};
-
 static int
 chkqfilter(dev_t dev, struct knote *kn)
 {
@@ -509,20 +502,18 @@ chkqfilter(dev_t dev, struct knote *kn)
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
 		kn->kn_fop = _filtops;
+		kn->kn_hook = sc;
+		selrecord_knote(>sc_selq, kn);
 		break;
 
 	case EVFILT_WRITE:
-		kn->kn_fop = _filtops;
+		kn->kn_fop = _filtops;
 		break;
 
 	default:
 		return (EINVAL);
 	}
 
-	kn->kn_hook = sc;
-
-	selrecord_knote(>sc_selq, kn);
-
 	return (0);
 }
 



CVS commit: src/sys/dev/scsipi

2021-09-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Sep 26 14:57:19 UTC 2021

Modified Files:
src/sys/dev/scsipi: ch.c

Log Message:
Use seltrue_filtops rather than rolling our own with filt_seltrue.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/scsipi/ch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 10:07:56 UTC 2021

Modified Files:
src/sys/dev/scsipi: st.c

Log Message:
Restore EOM handling.


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/dev/scsipi/st.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/st.c
diff -u src/sys/dev/scsipi/st.c:1.240 src/sys/dev/scsipi/st.c:1.241
--- src/sys/dev/scsipi/st.c:1.240	Fri Dec 27 09:41:51 2019
+++ src/sys/dev/scsipi/st.c	Sun Jun 13 10:07:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: st.c,v 1.240 2019/12/27 09:41:51 msaitoh Exp $ */
+/*	$NetBSD: st.c,v 1.241 2021/06/13 10:07:56 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.240 2019/12/27 09:41:51 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.241 2021/06/13 10:07:56 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -343,7 +343,7 @@ static int	st_mount_tape(dev_t, int);
 static void	st_unmount(struct st_softc *, boolean);
 static int	st_decide_mode(struct st_softc *, boolean);
 static void	ststart(struct scsipi_periph *);
-static int	ststart1(struct scsipi_periph *, struct buf *);
+static int	ststart1(struct scsipi_periph *, struct buf *, int *);
 static void	strestart(void *);
 static void	stdone(struct scsipi_xfer *, int);
 static int	st_read(struct st_softc *, char *, int, int);
@@ -1183,13 +1183,13 @@ abort:
  * ststart() is called with channel lock held
  */
 static int
-ststart1(struct scsipi_periph *periph, struct buf *bp)
+ststart1(struct scsipi_periph *periph, struct buf *bp, int *errnop)
 {
 	struct st_softc *st = device_private(periph->periph_dev);
 struct scsipi_channel *chan = periph->periph_channel;
 	struct scsi_rw_tape cmd;
 	struct scsipi_xfer *xs;
-	int flags, error;
+	int flags, error, complete = 1;
 
 	SC_DEBUG(periph, SCSIPI_DB2, ("ststart1 "));
 
@@ -1239,7 +1239,6 @@ ststart1(struct scsipi_periph *periph, s
 	goto out;
 }
 			} else {
-bp->b_resid = bp->b_bcount;
 error = 0;
 st->flags &= ~ST_AT_FILEMARK;
 goto out;
@@ -1251,7 +1250,10 @@ ststart1(struct scsipi_periph *periph, s
 	 * yet then we should report it now.
 	 */
 	if (st->flags & (ST_EOM_PENDING|ST_EIO_PENDING)) {
-		error = EIO;
+		error = 0;
+		if (st->flags & ST_EIO_PENDING)
+			error = EIO;
+		st->flags &= ~(ST_EOM_PENDING|ST_EIO_PENDING);
 		goto out;
 	}
 
@@ -1299,11 +1301,14 @@ ststart1(struct scsipi_periph *periph, s
 	error = scsipi_execute_xs(xs);
 	/* with a scsipi_xfer preallocated, scsipi_command can't fail */
 	KASSERT(error == 0);
+	if (error == 0)
+		complete = 0;
 
 out:
 	mutex_exit(chan_mtx(chan));
 
-	return error;
+	*errnop = error;
+	return complete;
 }
 
 static void
@@ -1312,7 +1317,7 @@ ststart(struct scsipi_periph *periph)
 	struct st_softc *st = device_private(periph->periph_dev);
 struct scsipi_channel *chan = periph->periph_channel;
 	struct buf *bp;
-	int error;
+	int error, complete;
 
 	SC_DEBUG(periph, SCSIPI_DB2, ("ststart "));
 
@@ -1325,19 +1330,20 @@ ststart(struct scsipi_periph *periph)
 		iostat_busy(st->stats);
 		mutex_exit(>sc_iolock);
 
-		error = ststart1(periph, bp);
+		complete = ststart1(periph, bp, );
 
 		mutex_enter(>sc_iolock);
-		if (error != 0)
+		if (complete) {
 			iostat_unbusy(st->stats, 0,
 			  ((bp->b_flags & B_READ) == B_READ));
-		if (error == EAGAIN) {
-			bufq_put(st->buf_defer, bp);
-			break;
+			if (error == EAGAIN) {
+bufq_put(st->buf_defer, bp);
+break;
+			}
 		}
 		mutex_exit(>sc_iolock);
 
-		if (error != 0) {
+		if (complete) {
 			bp->b_error = error;
 			bp->b_resid = bp->b_bcount;
 			biodone(bp);



CVS commit: src/sys/dev/scsipi

2021-06-13 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Jun 13 10:07:56 UTC 2021

Modified Files:
src/sys/dev/scsipi: st.c

Log Message:
Restore EOM handling.


To generate a diff of this commit:
cvs rdiff -u -r1.240 -r1.241 src/sys/dev/scsipi/st.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2021-05-30 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun May 30 06:46:46 UTC 2021

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.331 -r1.332 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.331 src/sys/dev/scsipi/sd.c:1.332
--- src/sys/dev/scsipi/sd.c:1.331	Wed Feb 10 16:30:01 2021
+++ src/sys/dev/scsipi/sd.c	Sun May 30 06:46:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.331 2021/02/10 16:30:01 christos Exp $	*/
+/*	$NetBSD: sd.c,v 1.332 2021/05/30 06:46:46 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.331 2021/02/10 16:30:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.332 2021/05/30 06:46:46 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -681,7 +681,7 @@ sd_diskstart(device_t dev, struct buf *b
 	/*
 	 * If the device has become invalid, abort all the
 	 * reads and writes until all files have been closed and
-	 * re-opened
+	 * re-opened.
 	 */
 	if (__predict_false(
 	(periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)) {



CVS commit: src/sys/dev/scsipi

2021-05-30 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun May 30 06:46:46 UTC 2021

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.331 -r1.332 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2021-04-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Apr 16 12:58:54 UTC 2021

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Limit buffer size for device capabilities requests as a work-around for PR
kern/56109.


To generate a diff of this commit:
cvs rdiff -u -r1.350 -r1.351 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2021-04-16 Thread Reinoud Zandijk
Module Name:src
Committed By:   reinoud
Date:   Fri Apr 16 12:58:54 UTC 2021

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Limit buffer size for device capabilities requests as a work-around for PR
kern/56109.


To generate a diff of this commit:
cvs rdiff -u -r1.350 -r1.351 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.350 src/sys/dev/scsipi/cd.c:1.351
--- src/sys/dev/scsipi/cd.c:1.350	Wed Feb 10 16:30:01 2021
+++ src/sys/dev/scsipi/cd.c	Fri Apr 16 12:58:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $	*/
+/*	$NetBSD: cd.c,v 1.351 2021/04/16 12:58:54 reinoud Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.351 2021/04/16 12:58:54 reinoud Exp $");
 
 #include 
 #include 
@@ -2695,15 +2695,13 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 	struct scsipi_get_conf_feature   *gcf;
 	struct scsipi_read_discinfo   di_cmd;
 	struct scsipi_read_discinfo_data  di __aligned(2);
-	const uint32_t buffer_size = 1024;
-	uint32_t feat_tbl_len, pos;
+	const uint32_t buffer_size = 0x200; /* XXX RPZ USB3 SCSI size issue */
+	uint32_t pos;
 	u_long   last_lba = 0;
 	uint8_t  *buffer, *fpos;
 	int feature, last_feature, features_len, feature_cur, feature_len;
 	int lsb, msb, error, flags;
 
-	feat_tbl_len = buffer_size;
-
 	buffer = malloc(buffer_size, M_TEMP, M_WAITOK);
 
 	/* initialise structure */
@@ -2748,12 +2746,12 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 		memset(_cmd, 0, sizeof(gc_cmd));
 		gc_cmd.opcode = GET_CONFIGURATION;
 		_lto2b(last_feature, gc_cmd.start_at_feature);
-		_lto2b(feat_tbl_len, gc_cmd.data_len);
-		memset(gc, 0, feat_tbl_len);
+		_lto2b(buffer_size, gc_cmd.data_len);
+		memset(gc, 0, buffer_size);
 
 		error = scsipi_command(periph,
 			(void *)_cmd, sizeof(gc_cmd),
-			(void *) gc, feat_tbl_len,
+			(void *) gc, buffer_size,
 			CDRETRIES, 3, NULL, flags);
 		if (error) {
 			/* ieeek... break out of loop... i dunno what to do */
@@ -2761,7 +2759,7 @@ mmc_getdiscinfo(struct scsipi_periph *pe
 		}
 
 		features_len = _4btol(gc->data_len);
-		if (features_len < 4 || features_len > feat_tbl_len)
+		if (features_len < 4 || features_len > buffer_size)
 			break;
 
 		pos  = 0;



CVS commit: src/sys/dev/scsipi

2021-02-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 10 16:30:01 UTC 2021

Modified Files:
src/sys/dev/scsipi: cd.c sd.c

Log Message:
PR/55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
consistent by also using __BIT()


To generate a diff of this commit:
cvs rdiff -u -r1.349 -r1.350 src/sys/dev/scsipi/cd.c
cvs rdiff -u -r1.330 -r1.331 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.349 src/sys/dev/scsipi/cd.c:1.350
--- src/sys/dev/scsipi/cd.c:1.349	Mon Oct 26 07:39:48 2020
+++ src/sys/dev/scsipi/cd.c	Wed Feb 10 11:30:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.349 2020/10/26 11:39:48 mlelstv Exp $	*/
+/*	$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.349 2020/10/26 11:39:48 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.350 2021/02/10 16:30:01 christos Exp $");
 
 #include 
 #include 
@@ -1378,7 +1378,7 @@ cdioctl(dev_t dev, u_long cmd, void *add
 		XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE));
 	case DIOCEJECT:
 		if (*(int *)addr == 0) {
-			int pmask = 1 << part;
+			int pmask = __BIT(part);
 			/*
 			 * Don't force eject: check that we are the only
 			 * partition open. If so, unlock it.

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.330 src/sys/dev/scsipi/sd.c:1.331
--- src/sys/dev/scsipi/sd.c:1.330	Fri Sep 25 09:08:00 2020
+++ src/sys/dev/scsipi/sd.c	Wed Feb 10 11:30:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.330 2020/09/25 13:08:00 jakllsch Exp $	*/
+/*	$NetBSD: sd.c,v 1.331 2021/02/10 16:30:01 christos Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.330 2020/09/25 13:08:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.331 2021/02/10 16:30:01 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -954,11 +954,12 @@ sdioctl(dev_t dev, u_long cmd, void *add
 		if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
 			return (ENOTTY);
 		if (*(int *)addr == 0) {
+			int pmask = __BIT(part);
 			/*
 			 * Don't force eject: check that we are the only
 			 * partition open. If so, unlock it.
 			 */
-			if (DK_BUSY(dksc, part) == 0) {
+			if (DK_BUSY(dksc, pmask) == 0) {
 error = scsipi_prevent(periph, SPAMR_ALLOW,
 XS_CTL_IGNORE_NOT_READY);
 if (error)



CVS commit: src/sys/dev/scsipi

2021-02-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Feb 10 16:30:01 UTC 2021

Modified Files:
src/sys/dev/scsipi: cd.c sd.c

Log Message:
PR/55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
consistent by also using __BIT()


To generate a diff of this commit:
cvs rdiff -u -r1.349 -r1.350 src/sys/dev/scsipi/cd.c
cvs rdiff -u -r1.330 -r1.331 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-12-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec 18 01:55:22 UTC 2020

Modified Files:
src/sys/dev/scsipi: ch.c

Log Message:
Use sel{record,remove}_knote().


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/scsipi/ch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/ch.c
diff -u src/sys/dev/scsipi/ch.c:1.92 src/sys/dev/scsipi/ch.c:1.93
--- src/sys/dev/scsipi/ch.c:1.92	Wed Oct 25 08:12:39 2017
+++ src/sys/dev/scsipi/ch.c	Fri Dec 18 01:55:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ch.c,v 1.92 2017/10/25 08:12:39 maya Exp $	*/
+/*	$NetBSD: ch.c,v 1.93 2020/12/18 01:55:22 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.92 2017/10/25 08:12:39 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ch.c,v 1.93 2020/12/18 01:55:22 thorpej Exp $");
 
 #include 
 #include 
@@ -473,7 +473,7 @@ filt_chdetach(struct knote *kn)
 {
 	struct ch_softc *sc = kn->kn_hook;
 
-	SLIST_REMOVE(>sc_selq.sel_klist, kn, knote, kn_selnext);
+	selremove_knote(>sc_selq, kn);
 }
 
 static int
@@ -505,16 +505,13 @@ static int
 chkqfilter(dev_t dev, struct knote *kn)
 {
 	struct ch_softc *sc = device_lookup_private(_cd, CHUNIT(dev));
-	struct klist *klist;
 
 	switch (kn->kn_filter) {
 	case EVFILT_READ:
-		klist = >sc_selq.sel_klist;
 		kn->kn_fop = _filtops;
 		break;
 
 	case EVFILT_WRITE:
-		klist = >sc_selq.sel_klist;
 		kn->kn_fop = _filtops;
 		break;
 
@@ -524,7 +521,7 @@ chkqfilter(dev_t dev, struct knote *kn)
 
 	kn->kn_hook = sc;
 
-	SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+	selrecord_knote(>sc_selq, kn);
 
 	return (0);
 }



CVS commit: src/sys/dev/scsipi

2020-12-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec 18 01:55:22 UTC 2020

Modified Files:
src/sys/dev/scsipi: ch.c

Log Message:
Use sel{record,remove}_knote().


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/scsipi/ch.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-10-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Oct 26 11:39:48 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Avoid buffer overflow when copying from bounce buffer.
Fixes PR 54810

Don't use uninitialized pointer in split bounce buffer case and
free a partially allocated bounce buffer on error.


To generate a diff of this commit:
cvs rdiff -u -r1.348 -r1.349 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.348 src/sys/dev/scsipi/cd.c:1.349
--- src/sys/dev/scsipi/cd.c:1.348	Tue Sep 29 03:04:03 2020
+++ src/sys/dev/scsipi/cd.c	Mon Oct 26 11:39:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.348 2020/09/29 03:04:03 msaitoh Exp $	*/
+/*	$NetBSD: cd.c,v 1.349 2020/10/26 11:39:48 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.348 2020/09/29 03:04:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.349 2020/10/26 11:39:48 mlelstv Exp $");
 
 #include 
 #include 
@@ -667,7 +667,7 @@ cd_make_bounce(struct cd_softc *cd, stru
 	cd_iosize(dksc->sc_dev, );
 
 	bounce->head = skip * DEV_BSIZE;
-	bounce->lcount = count - bounce->head;
+	bounce->lcount = imin(count - bounce->head, bp->b_bcount);
 	bounce->rcount = bp->b_bcount - bounce->lcount;
 
 	error = cd_make_bounce_buffer(cd, bp, blkno, count, , bounce);
@@ -678,10 +678,10 @@ cd_make_bounce(struct cd_softc *cd, stru
 	count = total - count;
 
 	if (count > 0) {
-		bounce->lbp->b_private = bounce;
 		error = cd_make_bounce_buffer(cd, bp, blkno, count, , bounce);
 		if (error) {
-			putiobuf(bounce->lbp);
+			free(lbp->b_data, M_DEVBUF);
+			putiobuf(lbp);
 			goto bad;
 		}
 	} else



CVS commit: src/sys/dev/scsipi

2020-10-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Oct 26 11:39:48 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Avoid buffer overflow when copying from bounce buffer.
Fixes PR 54810

Don't use uninitialized pointer in split bounce buffer case and
free a partially allocated bounce buffer on error.


To generate a diff of this commit:
cvs rdiff -u -r1.348 -r1.349 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-09-28 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep 29 03:04:03 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
s/settng/setting/


To generate a diff of this commit:
cvs rdiff -u -r1.347 -r1.348 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.347 src/sys/dev/scsipi/cd.c:1.348
--- src/sys/dev/scsipi/cd.c:1.347	Tue Sep 29 03:02:19 2020
+++ src/sys/dev/scsipi/cd.c	Tue Sep 29 03:04:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.347 2020/09/29 03:02:19 msaitoh Exp $	*/
+/*	$NetBSD: cd.c,v 1.348 2020/09/29 03:04:03 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.347 2020/09/29 03:02:19 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.348 2020/09/29 03:04:03 msaitoh Exp $");
 
 #include 
 #include 
@@ -1030,7 +1030,7 @@ cdminphys(struct buf *bp)
 	 *
 	 * XXX Note that the SCSI-I spec says that 256-block transfers
 	 * are allowed in a 6-byte read/write, and are specified
-	 * by settng the "length" to 0.  However, we're conservative
+	 * by setting the "length" to 0.  However, we're conservative
 	 * here, allowing only 255-block transfers in case an
 	 * ancient device gets confused by length == 0.  A length of 0
 	 * in a 10-byte read/write actually means 0 blocks.



CVS commit: src/sys/dev/scsipi

2020-09-28 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Sep 29 03:04:03 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
s/settng/setting/


To generate a diff of this commit:
cvs rdiff -u -r1.347 -r1.348 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-09-25 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Sep 25 13:08:00 UTC 2020

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
spelling fixes in sd.c comments


To generate a diff of this commit:
cvs rdiff -u -r1.329 -r1.330 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-09-25 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Sep 25 13:08:00 UTC 2020

Modified Files:
src/sys/dev/scsipi: sd.c

Log Message:
spelling fixes in sd.c comments


To generate a diff of this commit:
cvs rdiff -u -r1.329 -r1.330 src/sys/dev/scsipi/sd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.329 src/sys/dev/scsipi/sd.c:1.330
--- src/sys/dev/scsipi/sd.c:1.329	Mon Apr 13 08:05:02 2020
+++ src/sys/dev/scsipi/sd.c	Fri Sep 25 13:08:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.329 2020/04/13 08:05:02 maxv Exp $	*/
+/*	$NetBSD: sd.c,v 1.330 2020/09/25 13:08:00 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.329 2020/04/13 08:05:02 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.330 2020/09/25 13:08:00 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -444,7 +444,7 @@ sd_firstopen(device_t self, dev_t dev, i
 
 	/*
 	 * Start the pack spinning if necessary. Always allow the
-	 * raw parition to be opened, for raw IOCTLs. Data transfers
+	 * raw partition to be opened, for raw IOCTLs. Data transfers
 	 * will check for SDEV_MEDIA_LOADED.
 	 */
 	if (error == EIO) {
@@ -588,7 +588,7 @@ sd_lastclose(device_t self)
 }
 
 /*
- * close the device.. only called if we are the LAST occurence of an open
+ * close the device.. only called if we are the LAST occurrence of an open
  * device.  Convenient now but usually a pain.
  */
 static int
@@ -642,7 +642,7 @@ sdstrategy(struct buf *bp)
 /*
  * Issue single I/O command
  *
- * Called from dk_start and implicitely from dk_strategy
+ * Called from dk_start and implicitly from dk_strategy
  */
 static int
 sd_diskstart(device_t dev, struct buf *bp)
@@ -871,7 +871,7 @@ sdminphys(struct buf *bp)
 	 *
 	 * XXX Note that the SCSI-I spec says that 256-block transfers
 	 * are allowed in a 6-byte read/write, and are specified
-	 * by settng the "length" to 0.  However, we're conservative
+	 * by setting the "length" to 0.  However, we're conservative
 	 * here, allowing only 255-block transfers in case an
 	 * ancient device gets confused by length == 0.  A length of 0
 	 * in a 10-byte read/write actually means 0 blocks.



Re: CVS commit: src/sys/dev/scsipi

2020-09-19 Thread Kimmo Suominen
I don't think this should be reverted, because LUN 0 must exist, but if
there is no device on it, it will report "NOT PRESENT". We do not want
the scan to stop in this case, but it should continue with other LUNs
(such as those found through REPORT LUNS in the future).

Kind regards,
+ Kimmo


On Fri, Sep 18, 2020 at 03:04:25PM +, Jonathan A. Kollasch wrote:
> Module Name:  src
> Committed By: jakllsch
> Date: Fri Sep 18 15:04:25 UTC 2020
> 
> Modified Files:
>   src/sys/dev/scsipi: scsiconf.c
> 
> Log Message:
> Revert scsiconf.c 1.288, it only worked for LUN 1.
> 
> vioscsi(4) now sets PQUIRK_FORCELUNS, which fixes the original issue for
> all LUNs.
> 
> To-do: should issue REPORT LUNS and use the information it returns to
> probe LUNs in an optimized way.
> 
> 
> To generate a diff of this commit:
> cvs rdiff -u -r1.289 -r1.290 src/sys/dev/scsipi/scsiconf.c
> 
> Please note that diffs are not public domain; they are subject to the
> copyright notices on the relevant files.
> 


CVS commit: src/sys/dev/scsipi

2020-09-18 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Sep 18 15:04:25 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Revert scsiconf.c 1.288, it only worked for LUN 1.

vioscsi(4) now sets PQUIRK_FORCELUNS, which fixes the original issue for
all LUNs.

To-do: should issue REPORT LUNS and use the information it returns to
probe LUNs in an optimized way.


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.289 src/sys/dev/scsipi/scsiconf.c:1.290
--- src/sys/dev/scsipi/scsiconf.c:1.289	Thu Sep 17 01:19:41 2020
+++ src/sys/dev/scsipi/scsiconf.c	Fri Sep 18 15:04:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.289 2020/09/17 01:19:41 jakllsch Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.290 2020/09/18 15:04:25 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.289 2020/09/17 01:19:41 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.290 2020/09/18 15:04:25 jakllsch Exp $");
 
 #include 
 #include 
@@ -883,8 +883,6 @@ scsi_probe_device(struct scsibus_softc *
 		break;
 
 	case SID_QUAL_LU_NOTPRESENT:
-		docontinue = 1;
-		/* FALLTHROUGH */
 	case SID_QUAL_reserved:
 	case SID_QUAL_LU_NOT_SUPP:
 		goto bad;



CVS commit: src/sys/dev/scsipi

2020-09-18 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Fri Sep 18 15:04:25 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Revert scsiconf.c 1.288, it only worked for LUN 1.

vioscsi(4) now sets PQUIRK_FORCELUNS, which fixes the original issue for
all LUNs.

To-do: should issue REPORT LUNS and use the information it returns to
probe LUNs in an optimized way.


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-09-16 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Sep 17 01:19:41 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c scsipi_base.c

Log Message:
Some misspelling-in-comments fixes for scsipi


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.186 -r1.187 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.288 src/sys/dev/scsipi/scsiconf.c:1.289
--- src/sys/dev/scsipi/scsiconf.c:1.288	Sat Jul 11 14:31:46 2020
+++ src/sys/dev/scsipi/scsiconf.c	Thu Sep 17 01:19:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.288 2020/07/11 14:31:46 kim Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.289 2020/09/17 01:19:41 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.288 2020/07/11 14:31:46 kim Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.289 2020/09/17 01:19:41 jakllsch Exp $");
 
 #include 
 #include 
@@ -401,7 +401,7 @@ scsi_probe_bus(struct scsibus_softc *sc,
 
 	/*
 	 * Some HBAs provide an abstracted view of the bus; give them an
-	 * oppertunity to re-scan it before we do.
+	 * opportunity to re-scan it before we do.
 	 */
 	scsipi_adapter_ioctl(chan, SCBUSIOLLSCAN, NULL, 0, curproc);
 
@@ -809,10 +809,10 @@ scsi_probe_device(struct scsibus_softc *
 	int locs[SCSIBUSCF_NLOCS];
 
 	/*
-	 * Assume no more luns to search after this one.
+	 * Assume no more LUNs to search after this one.
 	 * If we successfully get Inquiry data and after
 	 * merging quirks we find we can probe for more
-	 * luns, we will.
+	 * LUNs, we will.
 	 */
 	docontinue = 0;
 
@@ -893,7 +893,7 @@ scsi_probe_device(struct scsibus_softc *
 		break;
 	}
 
-	/* Let the adapter driver handle the device separatley if it wants. */
+	/* Let the adapter driver handle the device separately if it wants. */
 	if (chan->chan_adapter->adapt_accesschk != NULL &&
 	(*chan->chan_adapter->adapt_accesschk)(periph, _inqbuf))
 		goto bad;

Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.186 src/sys/dev/scsipi/scsipi_base.c:1.187
--- src/sys/dev/scsipi/scsipi_base.c:1.186	Mon Apr 13 00:27:17 2020
+++ src/sys/dev/scsipi/scsipi_base.c	Thu Sep 17 01:19:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_base.c,v 1.186 2020/04/13 00:27:17 chs Exp $	*/
+/*	$NetBSD: scsipi_base.c,v 1.187 2020/09/17 01:19:41 jakllsch Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.186 2020/04/13 00:27:17 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.187 2020/09/17 01:19:41 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -871,7 +871,7 @@ scsipi_print_cdb(struct scsipi_generic *
  *	Look at the returned sense and act on the error, determining
  *	the unix error number to pass back.  (0 = report no error)
  *
- *	NOTE: If we return ERESTART, we are expected to haved
+ *	NOTE: If we return ERESTART, we are expected to have
  *	thawed the device!
  *
  *	THIS IS THE DEFAULT ERROR HANDLER FOR SCSI DEVICES.
@@ -1208,7 +1208,7 @@ scsipi_inquire(struct scsipi_periph *per
 	 * If we request more data than the device can provide, it SHOULD just
 	 * return a short response.  However, some devices error with an
 	 * ILLEGAL REQUEST sense code, and yet others have even more special
-	 * failture modes (such as the GL641USB flash adapter, which goes loony
+	 * failure modes (such as the GL641USB flash adapter, which goes loony
 	 * and sends corrupted CRCs).  To work around this, and to bring our
 	 * behavior more in line with other OSes, we do a shorter inquiry,
 	 * covering all the SCSI-2 information, first, and then request more
@@ -1395,7 +1395,7 @@ scsipi_mode_select_big(struct scsipi_per
 /*
  * scsipi_get_opcodeinfo:
  *
- * query the device for supported commends and their timeout
+ * query the device for supported commands and their timeout
  * building a timeout lookup table if timeout information is available.
  */
 void
@@ -1514,7 +1514,7 @@ scsipi_get_opcodeinfo(struct scsipi_peri
 
 /*
  * scsipi_update_timeouts:
- * 	Overide timeout value if device/config provided
+ * 	Override timeout value if device/config provided
  *  timeouts are available.
  */
 static void
@@ -1665,9 +1665,9 @@ scsipi_done(struct scsipi_xfer *xs)
 		/*
 		 * If it's a polling job, just return, to unwind the
 		 * call graph.  We don't need to restart the queue,
-		 * because pollings jobs are treated specially, and
+		 * because polling jobs are treated specially, and
 		 * are really only used during crash dumps anyway
-		 * (XXX or during boot-time autconfiguration of
+		 * (XXX or during boot-time autoconfiguration of
 		 * 

CVS commit: src/sys/dev/scsipi

2020-09-16 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Thu Sep 17 01:19:41 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c scsipi_base.c

Log Message:
Some misspelling-in-comments fixes for scsipi


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/dev/scsipi/scsiconf.c
cvs rdiff -u -r1.186 -r1.187 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-07-27 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jul 27 15:41:03 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Improve the workqueue and callout handling.  Prompted by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-07-27 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jul 27 15:41:03 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Improve the workqueue and callout handling.  Prompted by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.110 src/sys/dev/scsipi/if_se.c:1.111
--- src/sys/dev/scsipi/if_se.c:1.110	Wed Jul 22 17:18:10 2020
+++ src/sys/dev/scsipi/if_se.c	Mon Jul 27 15:41:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.110 2020/07/22 17:18:10 riastradh Exp $	*/
+/*	$NetBSD: if_se.c,v 1.111 2020/07/27 15:41:03 jdc Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.110 2020/07/22 17:18:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.111 2020/07/27 15:41:03 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -332,6 +332,7 @@ seattach(device_t parent, device_t self,
 
 	sc->sc_attach_state = 0;
 	callout_init(>sc_recv_ch, CALLOUT_MPSAFE);
+	callout_setfunc(>sc_recv_ch, se_recv_callout, (void *)sc);
 	mutex_init(>sc_iflock, MUTEX_DEFAULT, IPL_SOFTNET);
 
 	/*
@@ -415,7 +416,6 @@ sedetach(device_t self, int flags)
 		mutex_enter(>sc_iflock);
 		ifp->if_flags &= ~IFF_RUNNING;
 		se_disable(sc);
-		callout_halt(>sc_recv_ch, NULL);
 		ether_ifdetach(ifp);
 		if_detach(ifp);
 		mutex_exit(>sc_iflock);
@@ -464,18 +464,13 @@ static void
 se_ifstart(struct ifnet *ifp)
 {
 	struct se_softc *sc = ifp->if_softc;
-	int i = 100;
 
 	mutex_enter(>sc_iflock);
-	while (i && sc->sc_send_work_pending == true) {
-		i--;
-		delay(10);
-	}
-	if (i) {
+	if (!sc->sc_send_work_pending)  {
 		sc->sc_send_work_pending = true;
 		workqueue_enqueue(sc->sc_send_wq, >sc_send_work, NULL);
-	} else
-		if_statinc(ifp, if_oerrors);
+	} 
+	/* else: nothing to do - work is already queued */
 	mutex_exit(>sc_iflock);
 }
 
@@ -575,8 +570,7 @@ sedone(struct scsipi_xfer *xs, int error
 		/* scsipi_free_xs will call start. Harmless. */
 		if (error) {
 			/* Reschedule after a delay */
-			callout_reset(>sc_recv_ch, se_poll,
-			se_recv_callout, (void *)sc);
+			callout_schedule(>sc_recv_ch, se_poll);
 		} else {
 			int n, ntimeo;
 			n = se_read(sc, xs->data, xs->datalen - xs->resid);
@@ -597,8 +591,7 @@ sedone(struct scsipi_xfer *xs, int error
 	  se_poll: ntimeo);
 			}
 			sc->sc_last_timeout = ntimeo;
-			callout_reset(>sc_recv_ch, ntimeo,
-			se_recv_callout, (void *)sc);
+			callout_schedule(>sc_recv_ch, ntimeo);
 		}
 	}
 }
@@ -618,8 +611,8 @@ se_recv_callout(void *v)
 
 	mutex_enter(>sc_iflock);
 	if (sc->sc_recv_work_pending == true) {
-		callout_reset(>sc_recv_ch, se_poll,
-		se_recv_callout, (void *)sc);
+		callout_schedule(>sc_recv_ch, se_poll);
+		mutex_exit(>sc_iflock);
 		return;
 	}
 
@@ -660,8 +653,7 @@ se_recv(struct se_softc *sc)
 	sc->sc_rbuf, RBUF_LEN, SERETRIES, SETIMEOUT, NULL,
 	XS_CTL_NOSLEEP | XS_CTL_DATA_IN);
 	if (error)
-		callout_reset(>sc_recv_ch, se_poll,
-		se_recv_callout, (void *)sc);
+		callout_schedule(>sc_recv_ch, se_poll);
 }
 
 /*
@@ -923,12 +915,19 @@ se_init(struct se_softc *sc)
 	if ((ifp->if_flags & (IFF_RUNNING | IFF_UP)) == IFF_UP) {
 		ifp->if_flags |= IFF_RUNNING;
 		mutex_enter(>sc_iflock);
-		sc->sc_recv_work_pending = true;
-		workqueue_enqueue(sc->sc_recv_wq, >sc_recv_work, NULL);
+		if (!sc->sc_recv_work_pending)  {
+			sc->sc_recv_work_pending = true;
+			workqueue_enqueue(sc->sc_recv_wq, >sc_recv_work,
+			NULL);
+		} 
 		mutex_exit(>sc_iflock);
 		ifp->if_flags &= ~IFF_OACTIVE;
 		mutex_enter(>sc_iflock);
-		workqueue_enqueue(sc->sc_send_wq, >sc_send_work, NULL);
+		if (!sc->sc_send_work_pending)  {
+			sc->sc_send_work_pending = true;
+			workqueue_enqueue(sc->sc_send_wq, >sc_send_work,
+			NULL);
+		} 
 		mutex_exit(>sc_iflock);
 	}
 	return (error);
@@ -1019,7 +1018,7 @@ se_stop(struct se_softc *sc)
 {
 
 	/* Don't schedule any reads */
-	callout_stop(>sc_recv_ch);
+	callout_halt(>sc_recv_ch, >sc_iflock);
 
 	/* Wait for the workqueues to finish */
 	mutex_enter(>sc_iflock);



Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Kimmo Suominen
On Sun, Jul 12, 2020 at 12:05:37AM +0700, Robert Elz wrote:
> Just to make things clear here, the LUN you're talking about is not
> the scsi unit number (which is what I think Martin was referring to)
> but a sub-device number within a single scsi ID.   Right?

Correct. I should have written "SCSI target" instead of "SCSI bus" in
my commit message to avoid confusion.

In both of the use cases I highlighted (Proxmox and Linode), the disks
are always on SCSI ID 0. However, the "problematic" disks are on LUN 1
instead of LUN 0.

Out of curiosity, I just added a "scsi2" disk to the Proxmox VM. It has
been placed on LUN 2, and NetBSD does not pick it up even with this
patch... FreeBSD does (although the earlier LUNs are clearly causing
unexpected output from the "pass" attachments), so I guess I might be
looking at this a bit more. It would be nice to have (at least debug)
output about the LUN that terminates the scan loop.

Will probably open a ticket with Proxmox, too, in an attempt to put
a stop to this unnecessary wasteful skipping of perfectly good LUN
numbers.

+ Kimmo


Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Robert Elz
Date:Sat, 11 Jul 2020 18:24:51 +0300
From:Kimmo Suominen 
Message-ID:  <20200711152451.ga1...@homeworld.netbsd.org>

  | On Sat, Jul 11, 2020 at 05:00:02PM +0200, Martin Husemann wrote:
  | > I don't understand the change. When was this broken? This has always 
worked
  | > for me e.g. with the sd0 at LUN 3 and the controller at 6 or 7.
  |
  | I think all real SCSI hardware I've had has always just only had LUN 0,
  | and each disk has been on its own SCSI ID (target).

Just to make things clear here, the LUN you're talking about is not
the scsi unit number (which is what I think Martin was referring to)
but a sub-device number within a single scsi ID.   Right?

In real scsi hardware, the only place I think I've ever seen other than
LUN 0 is in a raid array device, where there is a single scsi bus
attachment, with a single ID, and then each raid volume created gets
a different LUN (not all scsi raids work that way I think, but some do).

kre



Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Martin Husemann
On Sat, Jul 11, 2020 at 06:24:51PM +0300, Kimmo Suominen wrote:
> I think all real SCSI hardware I've had has always just only had LUN 0,
> and each disk has been on its own SCSI ID (target).

Yes, I confused ID and LUN here - just ignore me.

Martin


Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Kimmo Suominen
On Sat, Jul 11, 2020 at 05:00:02PM +0200, Martin Husemann wrote:
> I don't understand the change. When was this broken? This has always worked
> for me e.g. with the sd0 at LUN 3 and the controller at 6 or 7.

I think all real SCSI hardware I've had has always just only had LUN 0,
and each disk has been on its own SCSI ID (target).

> Or is there something special in your setup?

Well, this is how Proxmox and Linode do it, and with this change it is
possible to install and use NetBSD on those platforms.

Of course, anyone running their own Proxmox could just avoid the "Virtio
SCSI single" controller type (or SCSI disks altogether), but there is
no user or admin control for specifying the LUN ID of a disk.

With a platform like Linode, you are stuck with the configuration it
creates for you from a boot profile (or other UI object). Although Linode
is usually responsive to bug reports, here it is not clear if the bug is
in how they do things or how NetBSD behaves.

With this change it is possible to run the NetBSD installer just like
the FreeBSD one (or any other "custom distro") on Linode.

Kind regards,
+ Kimmo


Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Martin Husemann
On Sat, Jul 11, 2020 at 05:57:46PM +0300, Kimmo Suominen wrote:
> On Sat, Jul 11, 2020 at 05:47:34PM +0300, Jukka Ruohonen wrote:
> > I'd reckon a pullup to NetBSD 9 would be in order?
> 
> Yes, I was just waiting to be able to link to mail-index.  I had
> already checked that the patch applies cleanly to both netbsd-9
> and netbsd-8.

I don't understand the change. When was this broken? This has always worked
for me e.g. with the sd0 at LUN 3 and the controller at 6 or 7.

Or is there something special in your setup?

Martin


Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Kimmo Suominen
On Sat, Jul 11, 2020 at 05:47:34PM +0300, Jukka Ruohonen wrote:
> I'd reckon a pullup to NetBSD 9 would be in order?

Yes, I was just waiting to be able to link to mail-index.  I had
already checked that the patch applies cleanly to both netbsd-9
and netbsd-8.

http://releng.netbsd.org/cgi-bin/req-9.cgi?show=1000
http://releng.netbsd.org/cgi-bin/req-8.cgi?show=1571

Cheers,
+ Kimmo


Re: CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Jukka Ruohonen
On Sat, Jul 11, 2020 at 02:31:46PM +, Kimmo Suominen wrote:
> Use case 2: A Linode boot profile with multiple disks results in
> the first disk ("sda") on LUN 1, while the second disk ("sdb") is
> on LUN 0, each on their own bus.

As Linode is quite popular, and supposedly uses a rather similar setup to
its competitors (e.g., Vultr), I'd reckon a pullup to NetBSD 9 would be in
order?  Some of these (e.g., netcup.eu in Europe) even offer off-the-shelf
NetBSD 9 images.

- Jukka


CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Sat Jul 11 14:31:46 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Continue scanning a SCSI bus when a LUN is reported not present

This fixes disk attachment under Qemu when there is no disk on LUN 0 on
a SCSI bus but there is a disk on LUN 1. The inquiry for LUN 0 returns
SID_QUAL_LU_NOTPRESENT & T_NODEVICE.  Quirks are only checked if neither
one of those are set, so cannot use a quirk entry.

Use case 1: Proxmox 6 configures each disk on its own bus when using
the "Virtio SCSI single" SCSI controller. However, while the "scsi0"
disk is on LUN 0, the "scsi1" disk is on LUN 1.

Use case 2: A Linode boot profile with multiple disks results in
the first disk ("sda") on LUN 1, while the second disk ("sdb") is
on LUN 0, each on their own bus.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.287 src/sys/dev/scsipi/scsiconf.c:1.288
--- src/sys/dev/scsipi/scsiconf.c:1.287	Sat May  2 06:45:53 2020
+++ src/sys/dev/scsipi/scsiconf.c	Sat Jul 11 14:31:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.287 2020/05/02 06:45:53 jdc Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.288 2020/07/11 14:31:46 kim Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.287 2020/05/02 06:45:53 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.288 2020/07/11 14:31:46 kim Exp $");
 
 #include 
 #include 
@@ -883,6 +883,8 @@ scsi_probe_device(struct scsibus_softc *
 		break;
 
 	case SID_QUAL_LU_NOTPRESENT:
+		docontinue = 1;
+		/* FALLTHROUGH */
 	case SID_QUAL_reserved:
 	case SID_QUAL_LU_NOT_SUPP:
 		goto bad;



CVS commit: src/sys/dev/scsipi

2020-07-11 Thread Kimmo Suominen
Module Name:src
Committed By:   kim
Date:   Sat Jul 11 14:31:46 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Continue scanning a SCSI bus when a LUN is reported not present

This fixes disk attachment under Qemu when there is no disk on LUN 0 on
a SCSI bus but there is a disk on LUN 1. The inquiry for LUN 0 returns
SID_QUAL_LU_NOTPRESENT & T_NODEVICE.  Quirks are only checked if neither
one of those are set, so cannot use a quirk entry.

Use case 1: Proxmox 6 configures each disk on its own bus when using
the "Virtio SCSI single" SCSI controller. However, while the "scsi0"
disk is on LUN 0, the "scsi1" disk is on LUN 1.

Use case 2: A Linode boot profile with multiple disks results in
the first disk ("sda") on LUN 1, while the second disk ("sdb") is
on LUN 0, each on their own bus.


To generate a diff of this commit:
cvs rdiff -u -r1.287 -r1.288 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-06-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jun 22 17:38:27 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Add sedetach() and also use it to remove duplicate code from seattach().
Correct a comment about sedone().


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.106 src/sys/dev/scsipi/if_se.c:1.107
--- src/sys/dev/scsipi/if_se.c:1.106	Mon Jun 22 16:05:20 2020
+++ src/sys/dev/scsipi/if_se.c	Mon Jun 22 17:38:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.106 2020/06/22 16:05:20 jdc Exp $	*/
+/*	$NetBSD: if_se.c,v 1.107 2020/06/22 17:38:27 jdc Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.106 2020/06/22 16:05:20 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.107 2020/06/22 17:38:27 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -198,10 +198,12 @@ struct se_softc {
 	int sc_flags;
 	int sc_last_timeout;
 	int sc_enabled;
+	int sc_attach_state;
 };
 
 static int	sematch(device_t, cfdata_t, void *);
 static void	seattach(device_t, device_t, void *);
+static int	sedetach(device_t, int);
 
 static void	se_ifstart(struct ifnet *);
 
@@ -240,7 +242,7 @@ int	se_enable(struct se_softc *);
 void	se_disable(struct se_softc *);
 
 CFATTACH_DECL_NEW(se, sizeof(struct se_softc),
-sematch, seattach, NULL, NULL);
+sematch, seattach, sedetach, NULL);
 
 extern struct cfdriver se_cd;
 
@@ -267,7 +269,7 @@ const struct scsipi_periphsw se_switch =
 	NULL,			/* Use default error handler */
 	NULL,			/* have no queue */
 	NULL,			/* have no async handler */
-	sedone,			/* deal with stats at interrupt time */
+	sedone,			/* deal with send/recv completion */
 };
 
 const struct scsipi_inquiry_pattern se_patterns[] = {
@@ -330,6 +332,7 @@ seattach(device_t parent, device_t self,
 	printf("\n");
 	SC_DEBUG(periph, SCSIPI_DB2, ("seattach: "));
 
+	sc->sc_attach_state = 0;
 	callout_init(>sc_recv_ch, CALLOUT_MPSAFE);
 	mutex_init(>sc_iflock, MUTEX_DEFAULT, IPL_SOFTNET);
 
@@ -363,43 +366,82 @@ seattach(device_t parent, device_t self,
 	IFQ_SET_READY(>if_snd);
 
 	se_get_addr(sc, myaddr);
+	sc->sc_attach_state = 1;
 
 	/* Attach the interface. */
 	rv = if_initialize(ifp);
 	if (rv != 0) {
-		free(sc->sc_tbuf, M_DEVBUF);
-		callout_destroy(>sc_recv_ch);
-		mutex_destroy(>sc_iflock);
+		sedetach(sc->sc_dev, 0);
 		return; /* Error */
 	}
+	
 	snprintf(wqname, sizeof(wqname), "%sRx", device_xname(sc->sc_dev));
 	rv = workqueue_create(>sc_recv_wq, wqname, se_recv_worker, sc,
 	PRI_SOFTNET, IPL_NET, WQ_MPSAFE);
 	if (rv != 0) {
 		aprint_error_dev(sc->sc_dev,
-		"unable to create recv workqueue\n");
-		free(sc->sc_tbuf, M_DEVBUF);
-		callout_destroy(>sc_recv_ch);
-		mutex_destroy(>sc_iflock);
+		"unable to create recv Rx workqueue\n");
+		sedetach(sc->sc_dev, 0);
 		return; /* Error */
 	}
 	sc->sc_recv_work_pending = false;
+	sc->sc_attach_state = 2;
+
 	snprintf(wqname, sizeof(wqname), "%sTx", device_xname(sc->sc_dev));
 	rv = workqueue_create(>sc_send_wq, wqname, se_send_worker, ifp,
 	PRI_SOFTNET, IPL_NET, WQ_MPSAFE);
 	if (rv != 0) {
 		aprint_error_dev(sc->sc_dev,
-		"unable to create send workqueue\n");
-		free(sc->sc_tbuf, M_DEVBUF);
-		callout_destroy(>sc_recv_ch);
-		mutex_destroy(>sc_iflock);
-		workqueue_destroy(sc->sc_send_wq);
+		"unable to create send Tx workqueue\n");
+		sedetach(sc->sc_dev, 0);
 		return; /* Error */
 	}
 	sc->sc_send_work_pending = false;
+	sc->sc_attach_state = 3;
+
 	sc->sc_ipq = if_percpuq_create(>sc_ethercom.ec_if);
 	ether_ifattach(ifp, myaddr);
 	if_register(ifp);
+	sc->sc_attach_state = 4;
+}
+
+static int
+sedetach(device_t self, int flags)
+{
+	struct se_softc *sc = device_private(self);
+	struct ifnet *ifp = >sc_ethercom.ec_if;
+
+	switch(sc->sc_attach_state) {
+	case 4:
+		se_stop(sc);
+		mutex_enter(>sc_iflock);
+		ifp->if_flags &= ~IFF_RUNNING;
+		se_disable(sc);
+		callout_halt(>sc_recv_ch, NULL);
+		ether_ifdetach(ifp);
+		if_detach(ifp);
+		mutex_exit(>sc_iflock);
+		if_percpuq_destroy(sc->sc_ipq);
+		/*FALLTHROUGH*/
+	case 3:
+		workqueue_destroy(sc->sc_send_wq);
+		/*FALLTHROUGH*/
+	case 2:
+		workqueue_destroy(sc->sc_recv_wq);
+		/*FALLTHROUGH*/
+	case 1:
+		free(sc->sc_rbuf, M_DEVBUF);
+		free(sc->sc_tbuf, M_DEVBUF);
+		callout_destroy(>sc_recv_ch);
+		mutex_destroy(>sc_iflock);
+		break;
+	default:
+		aprint_error_dev(sc->sc_dev, "detach failed (state %d)\n",
+		sc->sc_attach_state);
+		return 1;
+		break;
+	}
+	return 0;
 }
 
 /*



CVS commit: src/sys/dev/scsipi

2020-06-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jun 22 17:38:27 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Add sedetach() and also use it to remove duplicate code from seattach().
Correct a comment about sedone().


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-06-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jun 22 16:05:20 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Use workqueues so that we don't call into the scsipi subsystem via
a softint from the network stack.
Don't recurse through scsipi_command() when we have multiple packets
in the send queue - use a loop instead.  This means that we no longer
need sestart(), as we can now handle everything in sedone().
Fix a couple of XXX's.
Rework the locking logic slightly from the previous revision.
Now this works with DIAGNOSTIC+LOCKDEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-06-22 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon Jun 22 16:05:20 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Use workqueues so that we don't call into the scsipi subsystem via
a softint from the network stack.
Don't recurse through scsipi_command() when we have multiple packets
in the send queue - use a loop instead.  This means that we no longer
need sestart(), as we can now handle everything in sedone().
Fix a couple of XXX's.
Rework the locking logic slightly from the previous revision.
Now this works with DIAGNOSTIC+LOCKDEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.105 src/sys/dev/scsipi/if_se.c:1.106
--- src/sys/dev/scsipi/if_se.c:1.105	Fri Jun 19 10:30:27 2020
+++ src/sys/dev/scsipi/if_se.c	Mon Jun 22 16:05:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.105 2020/06/19 10:30:27 jdc Exp $	*/
+/*	$NetBSD: if_se.c,v 1.106 2020/06/22 16:05:20 jdc Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -49,7 +49,7 @@
  * This driver is also a bit unusual. It must look like a network
  * interface and it must also appear to be a scsi device to the scsi
  * system. Hence there are cases where there are two entry points. eg
- * sestart is to be called from the scsi subsytem and se_ifstart from
+ * sedone is to be called from the scsi subsytem and se_ifstart from
  * the network interface subsystem.  In addition, to facilitate scsi
  * commands issued by userland programs, there are open, close and
  * ioctl entry points. This allows a user program to, for example,
@@ -59,10 +59,11 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.105 2020/06/19 10:30:27 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.106 2020/06/22 16:05:20 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
+#include "opt_net_mpsafe.h"
 #include "opt_atalk.h"
 #endif
 
@@ -85,6 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -177,10 +179,12 @@ struct se_softc {
 	struct ethercom sc_ethercom;	/* Ethernet common part */
 	struct scsipi_periph *sc_periph;/* contains our targ, lun, etc. */
 
-	struct callout sc_ifstart_ch;
 	struct callout sc_recv_ch;
 	struct kmutex sc_iflock;
 	struct if_percpuq *sc_ipq;
+	struct workqueue *sc_recv_wq, *sc_send_wq;
+	struct work sc_recv_work, sc_send_work;
+	int sc_recv_work_pending, sc_send_work_pending;
 
 	char *sc_tbuf;
 	char *sc_rbuf;
@@ -200,7 +204,6 @@ static int	sematch(device_t, cfdata_t, v
 static void	seattach(device_t, device_t, void *);
 
 static void	se_ifstart(struct ifnet *);
-static void	sestart(struct scsipi_periph *);
 
 static void	sedone(struct scsipi_xfer *, int);
 static int	se_ioctl(struct ifnet *, u_long, void *);
@@ -209,10 +212,12 @@ static void	sewatchdog(struct ifnet *);
 #if 0
 static inline uint16_t ether_cmp(void *, void *);
 #endif
-static void	se_recv(void *);
+static void	se_recv_callout(void *);
+static void	se_recv_worker(struct work *wk, void *cookie);
+static void	se_recv(struct se_softc *);
 static struct mbuf *se_get(struct se_softc *, char *, int);
 static int	se_read(struct se_softc *, char *, int);
-static int	se_reset(struct se_softc *);
+static void	se_reset(struct se_softc *);
 static int	se_add_proto(struct se_softc *, int);
 static int	se_get_addr(struct se_softc *, uint8_t *);
 static int	se_set_media(struct se_softc *, int);
@@ -228,7 +233,7 @@ static inline int se_scsipi_cmd(struct s
 			int cmdlen, u_char *data_addr, int datalen,
 			int retries, int timeout, struct buf *bp,
 			int flags);
-static void	se_delayed_ifstart(void *);
+static void	se_send_worker(struct work *wk, void *cookie);
 static int	se_set_mode(struct se_softc *, int, int);
 
 int	se_enable(struct se_softc *);
@@ -260,7 +265,7 @@ const struct cdevsw se_cdevsw = {
 
 const struct scsipi_periphsw se_switch = {
 	NULL,			/* Use default error handler */
-	sestart,		/* have a queue, served by this */
+	NULL,			/* have no queue */
 	NULL,			/* have no async handler */
 	sedone,			/* deal with stats at interrupt time */
 };
@@ -317,6 +322,7 @@ seattach(device_t parent, device_t self,
 	struct scsipi_periph *periph = sa->sa_periph;
 	struct ifnet *ifp = >sc_ethercom.ec_if;
 	uint8_t myaddr[ETHER_ADDR_LEN];
+	char wqname[MAXCOMLEN];
 	int rv;
 
 	sc->sc_dev = self;
@@ -324,7 +330,6 @@ seattach(device_t parent, device_t self,
 	printf("\n");
 	SC_DEBUG(periph, SCSIPI_DB2, ("seattach: "));
 
-	callout_init(>sc_ifstart_ch, CALLOUT_MPSAFE);
 	callout_init(>sc_recv_ch, CALLOUT_MPSAFE);
 	mutex_init(>sc_iflock, MUTEX_DEFAULT, IPL_SOFTNET);
 
@@ -335,21 +340,17 @@ seattach(device_t parent, device_t self,
 	periph->periph_dev = sc->sc_dev;
 	periph->periph_switch = _switch;
 
-	/* XXX increase openings? */
-
 	

CVS commit: src/sys/dev/scsipi

2020-06-19 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Fri Jun 19 10:30:27 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
First pass at making this work again.
Remove spl and add some locking around network access (needs more work).
Make sure that we consistently use the channel lock for scsipi commands.
Remove the preference for send over receive, as this can lead to deadlocks
- we only advertise 1 opening, but we can try to send before the receive is
complete in this case.
Don't use XS_CTL_ASYNC because we don't provide a buffer.
Tested on UP sparc and compile-tested on atari.
Tested with LOCKDEBUG.
Still fails with DIAGNOSTIC because we can call into the scsipi routines
from a softint.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.104 src/sys/dev/scsipi/if_se.c:1.105
--- src/sys/dev/scsipi/if_se.c:1.104	Wed Jan 29 05:59:50 2020
+++ src/sys/dev/scsipi/if_se.c	Fri Jun 19 10:30:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.104 2020/01/29 05:59:50 thorpej Exp $	*/
+/*	$NetBSD: if_se.c,v 1.105 2020/06/19 10:30:27 jdc Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.104 2020/01/29 05:59:50 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.105 2020/06/19 10:30:27 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -83,6 +83,8 @@ __KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -142,7 +144,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.
 #define SE_POLL0 10		/* default in milliseconds */
 int se_poll = 0;		/* Delay in ticks set at attach time */
 int se_poll0 = 0;
+#ifdef SE_DEBUG
 int se_max_received = 0;	/* Instrumentation */
+#endif
 
 #define	PROTOCMD(p, d) \
 	((d) = (p))
@@ -175,6 +179,8 @@ struct se_softc {
 
 	struct callout sc_ifstart_ch;
 	struct callout sc_recv_ch;
+	struct kmutex sc_iflock;
+	struct if_percpuq *sc_ipq;
 
 	char *sc_tbuf;
 	char *sc_rbuf;
@@ -186,7 +192,6 @@ struct se_softc {
 #define PROTO_AARP	0x10
 	int sc_debug;
 	int sc_flags;
-#define SE_NEED_RECV 0x1
 	int sc_last_timeout;
 	int sc_enabled;
 };
@@ -250,7 +255,7 @@ const struct cdevsw se_cdevsw = {
 	.d_mmap = nommap,
 	.d_kqfilter = nokqfilter,
 	.d_discard = nodiscard,
-	.d_flag = D_OTHER
+	.d_flag = D_OTHER | D_MPSAFE
 };
 
 const struct scsipi_periphsw se_switch = {
@@ -319,8 +324,9 @@ seattach(device_t parent, device_t self,
 	printf("\n");
 	SC_DEBUG(periph, SCSIPI_DB2, ("seattach: "));
 
-	callout_init(>sc_ifstart_ch, 0);
-	callout_init(>sc_recv_ch, 0);
+	callout_init(>sc_ifstart_ch, CALLOUT_MPSAFE);
+	callout_init(>sc_recv_ch, CALLOUT_MPSAFE);
+	mutex_init(>sc_iflock, MUTEX_DEFAULT, IPL_SOFTNET);
 
 	/*
 	 * Store information needed to contact our base driver
@@ -360,13 +366,17 @@ seattach(device_t parent, device_t self,
 		free(sc->sc_tbuf, M_DEVBUF);
 		callout_destroy(>sc_ifstart_ch);
 		callout_destroy(>sc_recv_ch);
+		mutex_destroy(>sc_iflock);
 		return; /* Error */
 	}
+	sc->sc_ipq = if_percpuq_create(>sc_ethercom.ec_if);
 	ether_ifattach(ifp, myaddr);
 	if_register(ifp);
 }
 
-
+/*
+ * Send a command to the device
+ */
 static inline int
 se_scsipi_cmd(struct scsipi_periph *periph, struct scsipi_generic *cmd,
 int cmdlen, u_char *data_addr, int datalen, int retries, int timeout,
@@ -374,21 +384,24 @@ se_scsipi_cmd(struct scsipi_periph *peri
 {
 	int error;
 
+	KASSERT(!mutex_owned(chan_mtx(periph->periph_channel)));
+
 	error = scsipi_command(periph, cmd, cmdlen, data_addr,
 	datalen, retries, timeout, bp, flags);
 	return (error);
 }
 
-/* Start routine for calling from scsi sub system */
+/*
+ * Start routine for calling from scsi sub system
+ * Called with the channel lock held
+ */
 static void
 sestart(struct scsipi_periph *periph)
 {
 	struct se_softc *sc = device_private(periph->periph_dev);
 	struct ifnet *ifp = >sc_ethercom.ec_if;
-	int s = splnet();
 
 	se_ifstart(ifp);
-	(void) splx(s);
 }
 
 static void
@@ -396,19 +409,18 @@ se_delayed_ifstart(void *v)
 {
 	struct ifnet *ifp = v;
 	struct se_softc *sc = ifp->if_softc;
-	int s;
 
-	s = splnet();
+	mutex_enter(chan_mtx(sc->sc_periph->periph_channel));
 	if (sc->sc_enabled) {
 		ifp->if_flags &= ~IFF_OACTIVE;
 		se_ifstart(ifp);
 	}
-	splx(s);
+	mutex_exit(chan_mtx(sc->sc_periph->periph_channel));
 }
 
 /*
  * Start transmission on the interface.
- * Always called at splnet().
+ * Must be called with the scsipi channel lock held
  */
 static void
 se_ifstart(struct ifnet *ifp)
@@ -426,6 +438,9 @@ se_ifstart(struct ifnet *ifp)
 	IFQ_DEQUEUE(>if_snd, m0);
 	if (m0 == 0)
 		return;
+
+	KASSERT(mutex_owned(chan_mtx(sc->sc_periph->periph_channel)));
+
 	/* If BPF is listening on this interface, let it see the

CVS commit: src/sys/dev/scsipi

2020-06-19 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Fri Jun 19 10:30:27 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
First pass at making this work again.
Remove spl and add some locking around network access (needs more work).
Make sure that we consistently use the channel lock for scsipi commands.
Remove the preference for send over receive, as this can lead to deadlocks
- we only advertise 1 opening, but we can try to send before the receive is
complete in this case.
Don't use XS_CTL_ASYNC because we don't provide a buffer.
Tested on UP sparc and compile-tested on atari.
Tested with LOCKDEBUG.
Still fails with DIAGNOSTIC because we can call into the scsipi routines
from a softint.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-05-02 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Sat May  2 06:45:53 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Don't attempt to read opcodes and their timeouts at attach time for
old devices.  The MAINTENANCE IN command was introduced with SCSI-3
and sending it to older peripherals can cause timeouts or them not
to respond to further requests.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsiconf.c
diff -u src/sys/dev/scsipi/scsiconf.c:1.286 src/sys/dev/scsipi/scsiconf.c:1.287
--- src/sys/dev/scsipi/scsiconf.c:1.286	Wed Feb 19 16:04:39 2020
+++ src/sys/dev/scsipi/scsiconf.c	Sat May  2 06:45:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsiconf.c,v 1.286 2020/02/19 16:04:39 riastradh Exp $	*/
+/*	$NetBSD: scsiconf.c,v 1.287 2020/05/02 06:45:53 jdc Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.286 2020/02/19 16:04:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.287 2020/05/02 06:45:53 jdc Exp $");
 
 #include 
 #include 
@@ -1018,10 +1018,14 @@ scsi_probe_device(struct scsibus_softc *
 		scsipi_insert_periph(chan, periph);
 
 		/*
-		 * determine supported opcodes and
-		 * timeouts if available
+		 * Determine supported opcodes and timeouts if available.
+		 * Only do this on peripherals reporting SCSI version 3
+		 * or greater - this command isn't in the SCSI-2 spec. and
+		 * it causes either timeouts or peripherals disappearing
+		 * when sent to some SCSI-1 or SCSI-2 peripherals.
 		 */
-		scsipi_get_opcodeinfo(periph);
+		if (periph->periph_version >= 3)
+			scsipi_get_opcodeinfo(periph);
 
 		/*
 		 * XXX Can't assign periph_dev here, because we'll



CVS commit: src/sys/dev/scsipi

2020-05-02 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Sat May  2 06:45:53 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsiconf.c

Log Message:
Don't attempt to read opcodes and their timeouts at attach time for
old devices.  The MAINTENANCE IN command was introduced with SCSI-3
and sending it to older peripherals can cause timeouts or them not
to respond to further requests.


To generate a diff of this commit:
cvs rdiff -u -r1.286 -r1.287 src/sys/dev/scsipi/scsiconf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-03-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Mar 27 11:15:33 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Allow open of RAWPART even when no medium is loaded.
Keep errors silent if no medium is loaded.

Fixes PR kern/55104


To generate a diff of this commit:
cvs rdiff -u -r1.342 -r1.343 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-03-27 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Mar 27 11:15:33 UTC 2020

Modified Files:
src/sys/dev/scsipi: cd.c

Log Message:
Allow open of RAWPART even when no medium is loaded.
Keep errors silent if no medium is loaded.

Fixes PR kern/55104


To generate a diff of this commit:
cvs rdiff -u -r1.342 -r1.343 src/sys/dev/scsipi/cd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/cd.c
diff -u src/sys/dev/scsipi/cd.c:1.342 src/sys/dev/scsipi/cd.c:1.343
--- src/sys/dev/scsipi/cd.c:1.342	Mon Sep  3 16:29:33 2018
+++ src/sys/dev/scsipi/cd.c	Fri Mar 27 11:15:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cd.c,v 1.342 2018/09/03 16:29:33 riastradh Exp $	*/
+/*	$NetBSD: cd.c,v 1.343 2020/03/27 11:15:33 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.342 2018/09/03 16:29:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.343 2020/03/27 11:15:33 mlelstv Exp $");
 
 #include 
 #include 
@@ -401,8 +401,8 @@ cd_firstopen(device_t self, dev_t dev, i
 else
 silent = 0;
 
-	/* make cdclose() loud again */
-	cd->flags &= ~CDF_EJECTED;
+	/* make cdclose() silent */
+	cd->flags |= CDF_EJECTED;
 
 	/* Check that it is still responding and ok. */
 	error = scsipi_test_unit_ready(periph,
@@ -419,8 +419,11 @@ cd_firstopen(device_t self, dev_t dev, i
 		if (error == EINVAL)
 			error = EIO;
 	}
-	if (error)
+	if (error) {
+		if (part == RAW_PART)
+			goto out;
 		goto bad;
+	}
 
 	/* Lock the pack in. */
 	error = scsipi_prevent(periph, SPAMR_PREVENT_DT,
@@ -448,6 +451,9 @@ cd_firstopen(device_t self, dev_t dev, i
 		SC_DEBUG(periph, SCSIPI_DB3, ("Params loaded "));
 
 		cd_set_geometry(cd);
+
+		/* make cdclose() loud again */
+		cd->flags &= ~CDF_EJECTED;
 	}
 
 	periph->periph_flags |= PERIPH_OPEN;
@@ -519,7 +525,8 @@ cd_lastclose(device_t self)
 	struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
 	int silent;
 
-	if (cd->flags & CDF_EJECTED)
+	if ((cd->flags & CDF_EJECTED) != 0 ||
+	(periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)
 		silent = XS_CTL_SILENT;
 	else
 		silent = 0;
@@ -1213,6 +1220,14 @@ cdioctl(dev_t dev, u_long cmd, void *add
 		return (EIO);
 
 	switch (cmd) {
+	case DIOCTUR: {
+		/* test unit ready */
+		error = scsipi_test_unit_ready(cd->sc_periph, XS_CTL_SILENT);
+		*((int*)addr) = (error == 0);
+		if (error == ENODEV || error == EIO || error == 0)
+			return 0;   
+		return error;
+	}
 	case CDIOCPLAYTRACKS: {
 		/* PLAY_MSF command */
 		struct ioc_play_track *args = addr;
@@ -1447,15 +1462,18 @@ static void
 cd_label(device_t self, struct disklabel *lp)
 {
 	struct cd_softc *cd = device_private(self);
+	struct scsipi_periph *periph = cd->sc_periph;
 	struct cd_formatted_toc toc;
-	int lastsession;
+	int lastsession = 0;
 
 	strncpy(lp->d_typename, "optical media", 16);
 	lp->d_rpm = 300;
-	lp->d_flags |= D_REMOVABLE | D_SCSI_MMC;
+	lp->d_flags |= D_REMOVABLE;
 
-	if (cdreadmsaddr(cd, , ) != 0)
-		lastsession = 0;
+	if ((periph->periph_flags & PERIPH_MEDIA_LOADED) != 0) {
+		lp->d_flags |= D_SCSI_MMC;
+		(void) cdreadmsaddr(cd, , );
+	}
 
 	lp->d_partitions[0].p_offset = 0;
 	lp->d_partitions[0].p_size = lp->d_secperunit;



CVS commit: src/sys/dev/scsipi

2020-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Feb 19 16:05:41 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsipi_base.c
Added Files:
src/sys/dev/scsipi: scsi_sdt.h

Log Message:
Sprinkle some dtrace probes into scsi(4).


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/scsipi/scsi_sdt.h
cvs rdiff -u -r1.184 -r1.185 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.184 src/sys/dev/scsipi/scsipi_base.c:1.185
--- src/sys/dev/scsipi/scsipi_base.c:1.184	Sun Nov 10 21:16:37 2019
+++ src/sys/dev/scsipi/scsipi_base.c	Wed Feb 19 16:05:41 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_base.c,v 1.184 2019/11/10 21:16:37 chs Exp $	*/
+/*	$NetBSD: scsipi_base.c,v 1.185 2020/02/19 16:05:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.184 2019/11/10 21:16:37 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.185 2020/02/19 16:05:41 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: scsipi_base.
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -62,6 +63,38 @@ __KERNEL_RCSID(0, "$NetBSD: scsipi_base.
 
 #include 
 
+SDT_PROVIDER_DEFINE(scsi);
+
+SDT_PROBE_DEFINE3(scsi, base, tag, get,
+"struct scsipi_xfer *"/*xs*/, "uint8_t"/*tag*/, "uint8_t"/*type*/);
+SDT_PROBE_DEFINE3(scsi, base, tag, put,
+"struct scsipi_xfer *"/*xs*/, "uint8_t"/*tag*/, "uint8_t"/*type*/);
+
+SDT_PROBE_DEFINE3(scsi, base, adapter, request__start,
+"struct scsipi_channel *"/*chan*/,
+"scsipi_adapter_req_t"/*req*/,
+"void *"/*arg*/);
+SDT_PROBE_DEFINE3(scsi, base, adapter, request__done,
+"struct scsipi_channel *"/*chan*/,
+"scsipi_adapter_req_t"/*req*/,
+"void *"/*arg*/);
+
+SDT_PROBE_DEFINE1(scsi, base, queue, batch__start,
+"struct scsipi_channel *"/*chan*/);
+SDT_PROBE_DEFINE2(scsi, base, queue, run,
+"struct scsipi_channel *"/*chan*/,
+"struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, queue, batch__done,
+"struct scsipi_channel *"/*chan*/);
+
+SDT_PROBE_DEFINE1(scsi, base, xfer, execute,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, enqueue,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, done,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, redone,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, complete,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, restart,  "struct scsipi_xfer *"/*xs*/);
+SDT_PROBE_DEFINE1(scsi, base, xfer, free,  "struct scsipi_xfer *"/*xs*/);
+
 static int	scsipi_complete(struct scsipi_xfer *);
 static void	scsipi_request_sense(struct scsipi_xfer *);
 static int	scsipi_enqueue(struct scsipi_xfer *);
@@ -378,6 +411,8 @@ scsipi_get_tag(struct scsipi_xfer *xs)
 	}
 
 	xs->xs_tag_id = tag;
+	SDT_PROBE3(scsi, base, tag, get,
+	xs, xs->xs_tag_id, xs->xs_tag_type);
 }
 
 /*
@@ -395,6 +430,9 @@ scsipi_put_tag(struct scsipi_xfer *xs)
 
 	KASSERT(mutex_owned(chan_mtx(periph->periph_channel)));
 
+	SDT_PROBE3(scsi, base, tag, put,
+	xs, xs->xs_tag_id, xs->xs_tag_type);
+
 	word = xs->xs_tag_id >> 5;
 	bit = xs->xs_tag_id & 0x1f;
 
@@ -541,6 +579,7 @@ scsipi_put_xs(struct scsipi_xfer *xs)
 	struct scsipi_periph *periph = xs->xs_periph;
 	int flags = xs->xs_control;
 
+	SDT_PROBE1(scsi, base, xfer, free,  xs);
 	SC_DEBUG(periph, SCSIPI_DB3, ("scsipi_free_xs\n"));
 	KASSERT(mutex_owned(chan_mtx(periph->periph_channel)));
 
@@ -1559,6 +1598,7 @@ scsipi_done(struct scsipi_xfer *xs)
 #endif
 
 	mutex_enter(chan_mtx(chan));
+	SDT_PROBE1(scsi, base, xfer, done,  xs);
 	/*
 	 * The resource this command was using is now free.
 	 */
@@ -1573,6 +1613,7 @@ scsipi_done(struct scsipi_xfer *xs)
 		 * that this won't ever happen (and can be turned into
 		 * a KASSERT().
 		 */
+		SDT_PROBE1(scsi, base, xfer, redone,  xs);
 		mutex_exit(chan_mtx(chan));
 		goto out;
 	}
@@ -1704,6 +1745,8 @@ scsipi_complete(struct scsipi_xfer *xs)
 	struct scsipi_channel *chan = periph->periph_channel;
 	int error;
 
+	SDT_PROBE1(scsi, base, xfer, complete,  xs);
+
 #ifdef DIAGNOSTIC
 	if ((xs->xs_control & XS_CTL_ASYNC) != 0 && xs->bp == NULL)
 		panic("scsipi_complete: XS_CTL_ASYNC but no buf");
@@ -1872,6 +1915,7 @@ scsipi_complete(struct scsipi_xfer *xs)
 
 	mutex_enter(chan_mtx(chan));
 	if (error == ERESTART) {
+		SDT_PROBE1(scsi, base, xfer, restart,  xs);
 		/*
 		 * If we get here, the periph has been thawed and frozen
 		 * again if we had to issue recovery commands.  Alternatively,
@@ -1981,6 +2025,8 @@ scsipi_enqueue(struct scsipi_xfer *xs)
 	struct scsipi_channel *chan = xs->xs_periph->periph_channel;
 	

CVS commit: src/sys/dev/scsipi

2020-02-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Feb 19 16:05:41 UTC 2020

Modified Files:
src/sys/dev/scsipi: scsipi_base.c
Added Files:
src/sys/dev/scsipi: scsi_sdt.h

Log Message:
Sprinkle some dtrace probes into scsi(4).


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/scsipi/scsi_sdt.h
cvs rdiff -u -r1.184 -r1.185 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-02-11 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Feb 12 00:19:07 UTC 2020

Modified Files:
src/sys/dev/scsipi: atapi_wdc.c

Log Message:
the number of possible ATAPI devices on an ATA bus is not always 2,
it is however many devices the underlying ATA bus can have (eg. 1 for SATA),
so initialize the scsipi chan_ntargets from the ATA ch_ndrives.
this fixes a memory read overrun detected by KASAN.
discussed with mlelstv@ and jdolecek@


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/dev/scsipi/atapi_wdc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/atapi_wdc.c
diff -u src/sys/dev/scsipi/atapi_wdc.c:1.134 src/sys/dev/scsipi/atapi_wdc.c:1.135
--- src/sys/dev/scsipi/atapi_wdc.c:1.134	Sun Nov 10 21:16:37 2019
+++ src/sys/dev/scsipi/atapi_wdc.c	Wed Feb 12 00:19:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: atapi_wdc.c,v 1.134 2019/11/10 21:16:37 chs Exp $	*/
+/*	$NetBSD: atapi_wdc.c,v 1.135 2020/02/12 00:19:07 chs Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Manuel Bouyer.
@@ -25,7 +25,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.134 2019/11/10 21:16:37 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapi_wdc.c,v 1.135 2020/02/12 00:19:07 chs Exp $");
 
 #ifndef ATADEBUG
 #define ATADEBUG
@@ -138,7 +138,7 @@ wdc_atapibus_attach(struct atabus_softc 
 	chan->chan_flags = SCSIPI_CHAN_OPENINGS;
 	chan->chan_openings = 1;
 	chan->chan_max_periph = 1;
-	chan->chan_ntargets = 2;
+	chan->chan_ntargets = chp->ch_ndrives;
 	chan->chan_nluns = 1;
 
 	chp->atapibus = config_found_ia(ata_sc->sc_dev, "atapi", chan,



CVS commit: src/sys/dev/scsipi

2020-02-11 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Wed Feb 12 00:19:07 UTC 2020

Modified Files:
src/sys/dev/scsipi: atapi_wdc.c

Log Message:
the number of possible ATAPI devices on an ATA bus is not always 2,
it is however many devices the underlying ATA bus can have (eg. 1 for SATA),
so initialize the scsipi chan_ntargets from the ATA ch_ndrives.
this fixes a memory read overrun detected by KASAN.
discussed with mlelstv@ and jdolecek@


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/dev/scsipi/atapi_wdc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 05:59:50 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/if_se.c
diff -u src/sys/dev/scsipi/if_se.c:1.103 src/sys/dev/scsipi/if_se.c:1.104
--- src/sys/dev/scsipi/if_se.c:1.103	Sun Nov 10 21:16:37 2019
+++ src/sys/dev/scsipi/if_se.c	Wed Jan 29 05:59:50 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_se.c,v 1.103 2019/11/10 21:16:37 chs Exp $	*/
+/*	$NetBSD: if_se.c,v 1.104 2020/01/29 05:59:50 thorpej Exp $	*/
 
 /*
  * Copyright (c) 1997 Ian W. Dall 
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.103 2019/11/10 21:16:37 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_se.c,v 1.104 2020/01/29 05:59:50 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -467,10 +467,10 @@ se_ifstart(struct ifnet *ifp)
 	SETIMEOUT, NULL, XS_CTL_NOSLEEP | XS_CTL_ASYNC | XS_CTL_DATA_OUT);
 	if (error) {
 		aprint_error_dev(sc->sc_dev, "not queued, error %d\n", error);
-		ifp->if_oerrors++;
+		if_statinc(ifp, if_oerrors);
 		ifp->if_flags &= ~IFF_OACTIVE;
 	} else
-		ifp->if_opackets++;
+		if_statinc(ifp, if_opackets);
 	if (sc->sc_flags & SE_NEED_RECV) {
 		sc->sc_flags &= ~SE_NEED_RECV;
 		se_recv((void *) sc);
@@ -648,7 +648,7 @@ se_read(struct se_softc *sc, char *data,
 			printf("%s: invalid packet size %d; dropping\n",
 			   device_xname(sc->sc_dev), len);
 #endif
-			ifp->if_ierrors++;
+			if_statinc(ifp, if_ierrors);
 			goto next_packet;
 		}
 
@@ -659,7 +659,7 @@ se_read(struct se_softc *sc, char *data,
 			if (sc->sc_debug)
 printf("se_read: se_get returned null\n");
 #endif
-			ifp->if_ierrors++;
+			if_statinc(ifp, if_ierrors);
 			goto next_packet;
 		}
 		if ((ifp->if_flags & IFF_PROMISC) != 0) {
@@ -684,7 +684,7 @@ sewatchdog(struct ifnet *ifp)
 	struct se_softc *sc = ifp->if_softc;
 
 	log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
-	++ifp->if_oerrors;
+	if_statinc(ifp, if_oerrors);
 
 	se_reset(sc);
 }



CVS commit: src/sys/dev/scsipi

2020-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 29 05:59:50 UTC 2020

Modified Files:
src/sys/dev/scsipi: if_se.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/scsipi/if_se.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2019-09-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 03:37:31 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_base.c

Log Message:
 Use unsigned to avoid undefined behavior in scsipi_{get,put}_tag().
Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2019-09-18 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Sep 19 03:37:31 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_base.c

Log Message:
 Use unsigned to avoid undefined behavior in scsipi_{get,put}_tag().
Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/dev/scsipi/scsipi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.182 src/sys/dev/scsipi/scsipi_base.c:1.183
--- src/sys/dev/scsipi/scsipi_base.c:1.182	Thu Mar 28 10:44:29 2019
+++ src/sys/dev/scsipi/scsipi_base.c	Thu Sep 19 03:37:31 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_base.c,v 1.182 2019/03/28 10:44:29 kardel Exp $	*/
+/*	$NetBSD: scsipi_base.c,v 1.183 2019/09/19 03:37:31 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.182 2019/03/28 10:44:29 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.183 2019/09/19 03:37:31 msaitoh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -367,7 +367,7 @@ scsipi_get_tag(struct scsipi_xfer *xs)
 #endif
 
 	bit -= 1;
-	periph->periph_freetags[word] &= ~(1 << bit);
+	periph->periph_freetags[word] &= ~(1U << bit);
 	tag = (word << 5) | bit;
 
 	/* XXX Should eventually disallow this completely. */
@@ -398,7 +398,7 @@ scsipi_put_tag(struct scsipi_xfer *xs)
 	word = xs->xs_tag_id >> 5;
 	bit = xs->xs_tag_id & 0x1f;
 
-	periph->periph_freetags[word] |= (1 << bit);
+	periph->periph_freetags[word] |= (1U << bit);
 }
 
 /*



CVS commit: src/sys/dev/scsipi

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu May 30 16:57:39 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_ioctl.c

Log Message:
use correct size when copying outgoing sense data.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/scsipi/scsipi_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2019-05-30 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Thu May 30 16:57:39 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_ioctl.c

Log Message:
use correct size when copying outgoing sense data.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/scsipi/scsipi_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsipi_ioctl.c
diff -u src/sys/dev/scsipi/scsipi_ioctl.c:1.71 src/sys/dev/scsipi/scsipi_ioctl.c:1.72
--- src/sys/dev/scsipi/scsipi_ioctl.c:1.71	Sun May 26 08:12:41 2019
+++ src/sys/dev/scsipi/scsipi_ioctl.c	Thu May 30 16:57:39 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_ioctl.c,v 1.71 2019/05/26 08:12:41 mlelstv Exp $	*/
+/*	$NetBSD: scsipi_ioctl.c,v 1.72 2019/05/30 16:57:39 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.71 2019/05/26 08:12:41 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.72 2019/05/30 16:57:39 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_freebsd.h"
@@ -168,14 +168,16 @@ scsipi_user_done(struct scsipi_xfer *xs)
 		SC_DEBUG(periph, SCSIPI_DB3, ("have sense\n"));
 		screq->senselen_used = uimin(sizeof(xs->sense.scsi_sense),
 		SENSEBUFLEN);
-		memcpy(screq->sense, >sense.scsi_sense, screq->senselen);
+		memcpy(screq->sense, >sense.scsi_sense,
+		screq->senselen_used);
 		screq->retsts = SCCMD_SENSE;
 		break;
 	case XS_SHORTSENSE:
 		SC_DEBUG(periph, SCSIPI_DB3, ("have short sense\n"));
 		screq->senselen_used = uimin(sizeof(xs->sense.atapi_sense),
 		SENSEBUFLEN);
-		memcpy(screq->sense, >sense.scsi_sense, screq->senselen);
+		memcpy(screq->sense, >sense.atapi_sense,
+		screq->senselen_used);
 		screq->retsts = SCCMD_UNKNOWN; /* XXX need a shortsense here */
 		break;
 	case XS_DRIVER_STUFFUP:



CVS commit: src/sys/dev/scsipi

2019-05-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 26 08:12:41 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_ioctl.c

Log Message:
Add sanity checks to SCIOCCOMMAND, adapter drivers might be confused or trigger
assertions (e.g. umass).


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/scsipi/scsipi_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2019-05-26 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 26 08:12:41 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsipi_ioctl.c

Log Message:
Add sanity checks to SCIOCCOMMAND, adapter drivers might be confused or trigger
assertions (e.g. umass).


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/scsipi/scsipi_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsipi_ioctl.c
diff -u src/sys/dev/scsipi/scsipi_ioctl.c:1.70 src/sys/dev/scsipi/scsipi_ioctl.c:1.71
--- src/sys/dev/scsipi/scsipi_ioctl.c:1.70	Mon Sep  3 16:29:33 2018
+++ src/sys/dev/scsipi/scsipi_ioctl.c	Sun May 26 08:12:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsipi_ioctl.c,v 1.70 2018/09/03 16:29:33 riastradh Exp $	*/
+/*	$NetBSD: scsipi_ioctl.c,v 1.71 2019/05/26 08:12:41 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.70 2018/09/03 16:29:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_ioctl.c,v 1.71 2019/05/26 08:12:41 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_freebsd.h"
@@ -328,10 +328,18 @@ scsipi_do_ioctl(struct scsipi_periph *pe
 		struct scsi_ioctl *si;
 		int len;
 
+		len = screq->datalen;
+
+		/*
+		 * If there is data, there must be a data buffer and a direction specified
+		 */
+		if (len > 0 && (screq->databuf == NULL ||
+		(screq->flags & (SCCMD_READ|SCCMD_WRITE)) == 0))
+			return (EINVAL);
+
 		si = si_get();
 		si->si_screq = *screq;
 		si->si_periph = periph;
-		len = screq->datalen;
 		if (len) {
 			si->si_iov.iov_base = screq->databuf;
 			si->si_iov.iov_len = len;



CVS commit: src/sys/dev/scsipi

2019-05-19 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Sun May 19 19:06:53 UTC 2019

Modified Files:
src/sys/dev/scsipi: st.c

Log Message:
Add simple position recovery when positioning to EOM by reading
the position with READ_POSITION.
this allows for
mt eom
mt st
to return the correct file position.


To generate a diff of this commit:
cvs rdiff -u -r1.237 -r1.238 src/sys/dev/scsipi/st.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/st.c
diff -u src/sys/dev/scsipi/st.c:1.237 src/sys/dev/scsipi/st.c:1.238
--- src/sys/dev/scsipi/st.c:1.237	Sat Feb 23 11:57:41 2019
+++ src/sys/dev/scsipi/st.c	Sun May 19 19:06:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: st.c,v 1.237 2019/02/23 11:57:41 kamil Exp $ */
+/*	$NetBSD: st.c,v 1.238 2019/05/19 19:06:53 kardel Exp $ */
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.237 2019/02/23 11:57:41 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: st.c,v 1.238 2019/05/19 19:06:53 kardel Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -355,6 +355,7 @@ static int	st_rewind(struct st_softc *, 
 static int	st_interpret_sense(struct scsipi_xfer *);
 static int	st_touch_tape(struct st_softc *);
 static int	st_erase(struct st_softc *, int full, int flags);
+static void st_updatefilepos(struct st_softc *);
 static int	st_rdpos(struct st_softc *, int, uint32_t *);
 static int	st_setpos(struct st_softc *, int, uint32_t *);
 
@@ -1823,8 +1824,7 @@ st_space(struct st_softc *st, int number
 	st->blkno = -1;
 			}
 		} else if (what == SP_EOM) {
-			/* This loses us relative position. */
-			st->fileno = st->blkno = -1;
+st_updatefilepos(st);
 		}
 	}
 	return error;
@@ -1997,6 +1997,54 @@ st_rewind(struct st_softc *st, u_int imm
 	return error;
 }
 
+static void
+st_updatefilepos(struct st_softc *st)
+{
+int error;
+uint8_t posdata[32];
+struct scsi_tape_read_position cmd;
+
+memset(, 0, sizeof(cmd));
+memset(, 0, sizeof(posdata));
+cmd.opcode = READ_POSITION;
+cmd.byte1 = 6;  /* service action: LONG FORM */
+
+error = scsipi_command(st->sc_periph, (void *), sizeof(cmd),
+(void *), sizeof(posdata), ST_RETRIES, ST_CTL_TIME, NULL,
+XS_CTL_SILENT | XS_CTL_DATA_IN);
+
+if (error == 0) {
+#ifdef SCSIPI_DEBUG
+if (st->sc_periph->periph_dbflags & SCSIPI_DB3) {
+int hard;
+
+printf("posdata: ");
+for (hard = 0; hard < sizeof(posdata); hard++)
+printf("%02x ", posdata[hard] & 0xff);
+printf("\n");
+}
+#endif
+if (posdata[0] & 0xC) { /* Block|Mark Position Unknown */
+SC_DEBUG(st->sc_periph, SCSIPI_DB3,
+ ("st_updatefilepos block/mark position unknown (0x%02x)\n",
+  posdata[0]));
+} else {
+st->fileno = _8btol([16]);
+st->blkno = 0;
+SC_DEBUG(st->sc_periph, SCSIPI_DB3,
+ ("st_updatefilepos file position %"PRId64"\n",
+  st->fileno));
+return;
+}
+} else {
+SC_DEBUG(st->sc_periph, SCSIPI_DB3,
+ ("st_updatefilepos READ POSITION(LONG_FORM) failed (error=%d)\n",
+  error));
+}
+st->fileno = -1;
+st->blkno = -1;
+}
+
 static int
 st_rdpos(struct st_softc *st, int hard, uint32_t *blkptr)
 {



CVS commit: src/sys/dev/scsipi

2019-05-03 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri May  3 16:06:56 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsi_base.c

Log Message:
Avoid null pointer deref in printing xfer mode when no target driver
is attached. Fixes kern/54157.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/scsipi/scsi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/scsi_base.c
diff -u src/sys/dev/scsipi/scsi_base.c:1.92 src/sys/dev/scsipi/scsi_base.c:1.93
--- src/sys/dev/scsipi/scsi_base.c:1.92	Sat Jun 17 22:35:50 2017
+++ src/sys/dev/scsipi/scsi_base.c	Fri May  3 16:06:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsi_base.c,v 1.92 2017/06/17 22:35:50 mlelstv Exp $	*/
+/*	$NetBSD: scsi_base.c,v 1.93 2019/05/03 16:06:56 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.92 2017/06/17 22:35:50 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.93 2019/05/03 16:06:56 mlelstv Exp $");
 
 #include 
 #include 
@@ -136,9 +136,17 @@ scsi_kill_pending(struct scsipi_periph *
 static void
 scsi_print_xfer_mode(struct scsipi_periph *periph)
 {
+	struct scsipi_channel *chan = periph->periph_channel;
+	struct scsipi_adapter *adapt = chan->chan_adapter;
 	int period, freq, speed, mbs;
 
-	aprint_normal_dev(periph->periph_dev, "");
+	if (periph->periph_dev)
+		aprint_normal_dev(periph->periph_dev, "");
+	else
+		aprint_normal("probe(%s:%d:%d:%d): ",
+			device_xname(adapt->adapt_dev),
+			chan->chan_channel, periph->periph_target,
+			periph->periph_lun);
 	if (periph->periph_mode & (PERIPH_CAP_SYNC | PERIPH_CAP_DT)) {
 		period = scsipi_sync_factor_to_period(periph->periph_period);
 		aprint_normal("sync (%d.%02dns offset %d)",



CVS commit: src/sys/dev/scsipi

2019-05-03 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri May  3 16:06:56 UTC 2019

Modified Files:
src/sys/dev/scsipi: scsi_base.c

Log Message:
Avoid null pointer deref in printing xfer mode when no target driver
is attached. Fixes kern/54157.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/scsipi/scsi_base.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/scsipi

2019-03-19 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Mar 19 06:59:40 UTC 2019

Modified Files:
src/sys/dev/scsipi: sd.c sdvar.h

Log Message:
Set disk product name as disk type. The information can be queried through
drvctl(4).


To generate a diff of this commit:
cvs rdiff -u -r1.326 -r1.327 src/sys/dev/scsipi/sd.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/scsipi/sdvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/scsipi/sd.c
diff -u src/sys/dev/scsipi/sd.c:1.326 src/sys/dev/scsipi/sd.c:1.327
--- src/sys/dev/scsipi/sd.c:1.326	Sun Oct  7 18:14:32 2018
+++ src/sys/dev/scsipi/sd.c	Tue Mar 19 06:59:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sd.c,v 1.326 2018/10/07 18:14:32 christos Exp $	*/
+/*	$NetBSD: sd.c,v 1.327 2019/03/19 06:59:40 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.326 2018/10/07 18:14:32 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.327 2019/03/19 06:59:40 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -256,6 +256,8 @@ sdattach(device_t parent, device_t self,
 	sd->type = (sa->sa_inqbuf.type & SID_TYPE);
 	strncpy(sd->name, sa->sa_inqbuf.product, sizeof(sd->name));
 
+	strncpy(sd->typename, sa->sa_inqbuf.product, sizeof(sd->typename));
+
 	if (sd->type == T_SIMPLE_DIRECT)
 		periph->periph_quirks |= PQUIRK_ONLYBIG | PQUIRK_NOBIGMODESENSE;
 
@@ -1936,5 +1938,5 @@ sd_set_geometry(struct sd_softc *sd)
 	dg->dg_ntracks = sd->params.heads;
 	dg->dg_ncylinders = sd->params.cyls;
 
-	disk_set_info(dksc->sc_dev, >sc_dkdev, NULL);
+	disk_set_info(dksc->sc_dev, >sc_dkdev, sd->typename);
 }

Index: src/sys/dev/scsipi/sdvar.h
diff -u src/sys/dev/scsipi/sdvar.h:1.38 src/sys/dev/scsipi/sdvar.h:1.39
--- src/sys/dev/scsipi/sdvar.h:1.38	Sat Dec 10 10:26:38 2016
+++ src/sys/dev/scsipi/sdvar.h	Tue Mar 19 06:59:40 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdvar.h,v 1.38 2016/12/10 10:26:38 mlelstv Exp $	*/
+/*	$NetBSD: sdvar.h,v 1.39 2019/03/19 06:59:40 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -88,6 +88,7 @@ struct sd_softc {
 	callout_t sc_callout;
 	u_int8_t type;
 	char name[16]; /* product name, for default disklabel */
+	char typename[128+4+1]; /* stored in disk info */
 };
 
 #define	SDGP_RESULT_OK		0	/* parameters obtained */



  1   2   3   4   >