Module Name:    src
Committed By:   martin
Date:           Sat Dec  3 12:20:32 UTC 2016

Modified Files:
        src/sbin/scsictl [netbsd-7]: scsictl.8 scsictl.c
        src/sys/dev/scsipi [netbsd-7]: scsi_disk.h

Log Message:
Pull up following revision(s) (requested by flxd in ticket #1276):
        sys/dev/scsipi/scsi_disk.h: revision 1.32
        sbin/scsictl/scsictl.8: revision 1.27-1.30
        sbin/scsictl/scsictl.c: revision 1.39
Add "getrealloc" and "setrealloc" commands to get/set automatic reallocation
parameters/enables for error recovery, similar to {get,set}cache.
Many old SCSI disks shipped with reallocation disabled, albeit
supporting it.
Minor (cosmetic) fixup of scsi_disk_pages while there.
Based upon code in PR bin/29165 by Greg A. Woods.
OK christos@
Bump date for previous.
Use more and more appropriate markup while here.
Add crossreference to scsi(4) per note in PR 9627.
Whitespace, sort.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.6.1 src/sbin/scsictl/scsictl.8
cvs rdiff -u -r1.37 -r1.37.8.1 src/sbin/scsictl/scsictl.c
cvs rdiff -u -r1.31 -r1.31.138.1 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/sbin/scsictl/scsictl.8
diff -u src/sbin/scsictl/scsictl.8:1.26 src/sbin/scsictl/scsictl.8:1.26.6.1
--- src/sbin/scsictl/scsictl.8:1.26	Fri Mar 29 21:46:32 2013
+++ src/sbin/scsictl/scsictl.8	Sat Dec  3 12:20:32 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: scsictl.8,v 1.26 2013/03/29 21:46:32 christos Exp $
+.\"	$NetBSD: scsictl.8,v 1.26.6.1 2016/12/03 12:20:32 martin Exp $
 .\"
 .\" Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 29, 2013
+.Dd November 19, 2016
 .Dt SCSICTL 8
 .Os
 .Sh NAME
@@ -60,10 +60,8 @@ will be decoded by
 and displayed to the standard output.
 .Sh DEVICE COMMANDS
 The following commands are supported for SCSI devices:
-.Pp
-.Nm debug
-.Ar level
-.Pp
+.Bl -tag -width flushcacheXX
+.It Cm debug Ar level
 Set the debugging level for the given device; the following flags are
 supported:
 .Pp
@@ -80,24 +78,13 @@ Device specific debugging.
 .Pp
 This option is only supported with kernels compiled with
 .Dv SCSIPI_DEBUG .
-.Pp
-.Nm defects
-.Op primary
-.Op grown
-.Op block|byte|physical
-.Pp
+.It Cm defects Oo primary Oc Oo grown Oc Oo block|byte|physical Oc
 Read the primary and/or grown defect lists from the specified device
 in block, byte from index, or physical sector format.
 The default is to return both the primary and grown defect lists
 in physical sector format.
 This command is only supported on direct access devices.
-.Pp
-.Nm format
-.Oo blocksize
-.Oo immediate
-.Oc
-.Oc
-.Pp
+.It Cm format Oo blocksize Oo immediate Oc Oc
 (Low level) format the named device.
 If the optional
 .Li blocksize
@@ -132,73 +119,47 @@ This associated sense data has a progres
 how far the format is progressing.
 Note well that most SCSI disk drives prior to
 a few years ago do not support this option.
-.Pp
-.Nm identify
-.Pp
+.It Cm identify
 Identify the specified device, displaying the device's SCSI
 bus, target, and lun, as well as the device's vendor, product,
 and revision strings.
-.Pp
-.Nm reassign
-.Ar blkno
-.Oo blkno Oo ...
-.Oc
-.Oc
-.Pp
+.Cm It reassign Ar blkno Oo blkno Oo ... Oc Oc
 Issues a
 .Li REASSIGN BLOCKS
 command to the device, adding the specified blocks to the
 grown defect list.
 This command is only supported on direct access devices.
-.Pp
-.Nm release
-.Pp
+.It Cm release
 Send a
 .Dq RELEASE
 command to the device to release a reservation on it.
-.Pp
-.Nm reserve
-.Pp
+.It Cm reserve
 Send a
 .Dq RESERVE
 command to the device to place a reservation on it.
-.Pp
-.Nm reset
-.Pp
+.It Cm reset
 Reset the device.
 This command is only supported for devices which support the
 .Li SCIOCRESET
 ioctl.
-.Pp
-.Nm start
-.Pp
+.It Cm start
 Send a
 .Dq START
 command to the device.
 This is useful typically only for disk devices.
-.Pp
-.Nm stop
-.Pp
+.It Cm stop
 Send a
 .Dq STOP
 command to the device.
 This is useful typically only for disk devices.
-.Pp
-.Nm tur
-.Pp
+.It Cm tur
 Send a
 .Dq TEST UNIT READY
 command to the device.
 This is useful for generating current device status.
-.Pp
-.Nm getcache
-.Pp
+.It Cm getcache
 Returns basic cache parameters for the device.
-.Pp
-.Nm setcache
-.Ar none|r|w|rw
-.Op Ar save
-.Pp
+.It Cm setcache Ar none|r|w|rw Op Ar save
 Set basic cache parameters for the device.
 The cache may be disabled
 .Pq none ,
@@ -212,32 +173,39 @@ If the drive's cache parameters are sava
 .Ar save
 after the cache enable state will cause the parameters to be saved in
 non-volatile storage.
-.Pp
-.Nm flushcache
-.Pp
+.It Cm flushcache
 Explicitly flushes the write cache.
-.Pp
-.Nm setspeed
-.Ar speed
-.Pp
+.It Cm setspeed Ar speed
 Set the highest speed that the optical drive should use for reading
 data.
 The units are multiples of a single speed CDROM (150 KB/s).
 Specify 0 to use the drive's fastest speed.
+.It Cm getrealloc
+Returns automatic reallocation parameters for the device.
+.It Cm setrealloc Ar none|r|w|rw Op Ar save
+Set automatic reallocation parameters for the device.
+Automatic reallocation may be disabled
+.Pq none ,
+the automatic read reallocation enabled
+.Pq r ,
+the automatic write reallocation enabled
+.Pq w ,
+or both automatic read and write reallocation enabled
+.Pq rw .
+If the drive's automatic reallocation parameters are savable, specifying
+.Ar save
+after the automatic reallocation enable state will cause the parameters to be
+saved in non-volatile storage.
+.El
 .Sh BUS COMMANDS
 The following commands are supported for SCSI busses:
-.Pp
-.Nm reset
-.Pp
+.Bl -tag width scanXtargetXlunXX
+.It Cm reset
 Reset the SCSI bus.
 This command is only supported if the host adapter supports the
 .Li SCBUSIORESET
 ioctl.
-.Pp
-.Nm scan
-.Ar target
-.Ar lun
-.Pp
+.It Cm scan Ar target Ar lun
 Scan the SCSI bus for devices.
 This is useful if a device was not connected or powered
 on when the system was booted.
@@ -250,11 +218,7 @@ Either may be wildcarded by specifying t
 .Dq any
 or
 .Dq all .
-.Pp
-.Nm detach
-.Ar target
-.Ar lun
-.Pp
+.It Cm detach Ar target Ar lun
 Detach the specified device from the bus.
 Useful if a device is powered down after use.
 The
@@ -262,8 +226,9 @@ The
 and
 .Ar lun
 arguments have the same meaning as for the
-.Nm scan
+.Cm scan
 command, and may also be wildcarded.
+.El
 .Sh NOTES
 When scanning the SCSI bus, information about newly recognized devices
 is printed to console.
@@ -275,6 +240,7 @@ No information is printed for already pr
 .Xr ioctl 2 ,
 .Xr cd 4 ,
 .Xr ch 4 ,
+.Xr scsi 4 ,
 .Xr sd 4 ,
 .Xr se 4 ,
 .Xr ss 4 ,
@@ -288,7 +254,9 @@ The
 command first appeared in
 .Nx 1.4 .
 .Sh AUTHORS
+.An -nosplit
 The
 .Nm
-command was written by Jason R. Thorpe of the Numerical Aerospace Simulation
-Facility, NASA Ames Research Center.
+command was written by
+.An Jason R. Thorpe
+of the Numerical Aerospace Simulation Facility, NASA Ames Research Center.

Index: src/sbin/scsictl/scsictl.c
diff -u src/sbin/scsictl/scsictl.c:1.37 src/sbin/scsictl/scsictl.c:1.37.8.1
--- src/sbin/scsictl/scsictl.c:1.37	Sat Jan 12 02:52:59 2013
+++ src/sbin/scsictl/scsictl.c	Sat Dec  3 12:20:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsictl.c,v 1.37 2013/01/12 02:52:59 jakllsch Exp $	*/
+/*	$NetBSD: scsictl.c,v 1.37.8.1 2016/12/03 12:20:32 martin Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: scsictl.c,v 1.37 2013/01/12 02:52:59 jakllsch Exp $");
+__RCSID("$NetBSD: scsictl.c,v 1.37.8.1 2016/12/03 12:20:32 martin Exp $");
 #endif
 
 
@@ -91,6 +91,8 @@ static void	device_getcache(int, char *[
 static void	device_setcache(int, char *[]);
 static void	device_flushcache(int, char *[]);
 static void	device_setspeed(int, char *[]);
+static void	device_getrealloc(int, char *[]);
+static void	device_setrealloc(int, char *[]);
 
 static struct command device_commands[] = {
 	{ "defects",	"[primary] [grown] [block|byte|physical]",
@@ -111,6 +113,8 @@ static struct command device_commands[] 
 	{ "setcache",	"none|r|w|rw [save]",	device_setcache },
 	{ "flushcache",	"",			device_flushcache },
 	{ "setspeed",	"[speed]",		device_setspeed },
+	{ "getrealloc",	"",			device_getrealloc },
+	{ "setrealloc",	"none|r|w|rw [save]",	device_setrealloc },
 	{ NULL,		NULL,			NULL },
 };
 
@@ -981,6 +985,93 @@ device_setspeed(int argc, char *argv[])
 }
 
 /*
+ * device_getrealloc:
+ *
+ *	Get the automatic reallocation parameters for a SCSI disk.
+ */
+static void
+device_getrealloc(int argc, char *argv[])
+{
+	struct {
+		struct scsi_mode_parameter_header_6 header;
+		struct scsi_general_block_descriptor blk_desc;
+		struct page_err_recov err_recov_params;
+	} data;
+	u_int8_t flags;
+
+	/* No arguments. */
+	if (argc != 0)
+		usage();
+
+	scsi_mode_sense(fd, 0x01, 0x00, &data, sizeof(data));
+
+	flags = data.err_recov_params.flags;
+	if ((flags & (ERR_RECOV_ARRE | ERR_RECOV_AWRE)) == 0)
+		printf("%s: no automatic reallocation enabled\n", dvname);
+	else {
+		printf("%s: automatic read reallocation %senabled\n", dvname,
+		    (flags & ERR_RECOV_ARRE) ? "" : "not ");
+		printf("%s: automatic write reallocation %senabled\n", dvname,
+		    (flags & ERR_RECOV_AWRE) ? "" : "not ");
+	}
+	printf("%s: error recovery parameters are %ssavable\n", dvname,
+	    (data.err_recov_params.pg_code & PGCODE_PS) ? "" : "not ");
+}
+
+/*
+ * device_setrealloc:
+ *
+ *	Set the automatic reallocation parameters for a SCSI disk.
+ */
+static void
+device_setrealloc(int argc, char *argv[])
+{
+	struct {
+		struct scsi_mode_parameter_header_6 header;
+		struct scsi_general_block_descriptor blk_desc;
+		struct page_err_recov err_recov_params;
+	} data;
+	int dlen;
+	u_int8_t flags, byte2;
+
+	if (argc > 2 || argc == 0)
+		usage();
+
+	flags = 0;
+	byte2 = 0;
+	if (strcmp(argv[0], "none") == 0)
+		flags = 0;
+	else if (strcmp(argv[0], "r") == 0)
+		flags = ERR_RECOV_ARRE;
+	else if (strcmp(argv[0], "w") == 0)
+		flags = ERR_RECOV_AWRE;
+	else if (strcmp(argv[0], "rw") == 0)
+		flags = ERR_RECOV_ARRE | ERR_RECOV_AWRE;
+	else
+		usage();
+
+	if (argc == 2) {
+		if (strcmp(argv[1], "save") == 0)
+			byte2 = SMS_SP;
+		else
+			usage();
+	}
+
+	scsi_mode_sense(fd, 0x01, 0x00, &data, sizeof(data));
+
+	data.err_recov_params.pg_code &= PGCODE_MASK;
+	data.err_recov_params.flags &= ~(ERR_RECOV_ARRE | ERR_RECOV_AWRE);
+	data.err_recov_params.flags |= flags;
+
+	data.header.data_length = 0;
+
+	dlen = sizeof(data.header) + sizeof(data.blk_desc) + 2 +
+	    data.err_recov_params.pg_length;
+
+	scsi_mode_select(fd, byte2, &data, dlen);
+}
+
+/*
  * device_prevent:
  *
  *      Issue a prevent to a SCSI device.

Index: src/sys/dev/scsipi/scsi_disk.h
diff -u src/sys/dev/scsipi/scsi_disk.h:1.31 src/sys/dev/scsipi/scsi_disk.h:1.31.138.1
--- src/sys/dev/scsipi/scsi_disk.h:1.31	Sun Dec 11 12:23:50 2005
+++ src/sys/dev/scsipi/scsi_disk.h	Sat Dec  3 12:20:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: scsi_disk.h,v 1.31 2005/12/11 12:23:50 christos Exp $	*/
+/*	$NetBSD: scsi_disk.h,v 1.31.138.1 2016/12/03 12:20:32 martin Exp $	*/
 
 /*
  * SCSI-specific interface description
@@ -236,6 +236,27 @@ struct scsi_read_defect_data_data {
 
 union scsi_disk_pages {
 #define	DISK_PGCODE	0x3F	/* only 6 bits valid */
+	struct page_err_recov {
+		u_int8_t pg_code;	/* page code (should be 1) */
+		u_int8_t pg_length;	/* page length (should be 0x0a) */
+		u_int8_t flags;		/* error recovery flags */
+#define	ERR_RECOV_DCR	0x01		/* disable correction */
+#define	ERR_RECOV_DTE	0x02		/* disable transfer on error */
+#define	ERR_RECOV_PER	0x04		/* post error */
+#define	ERR_RECOV_EER	0x08		/* enable early recovery */
+#define	ERR_RECOV_RC	0x10		/* read continuous */
+#define	ERR_RECOV_TB	0x20		/* transfer block */
+#define	ERR_RECOV_ARRE	0x40		/* autom. read reallocation enable */
+#define	ERR_RECOV_AWRE	0x80		/* autom. write reallocation enable */
+		u_int8_t rd_retry_ct;	/* read retry count */
+		u_int8_t corr_span;	/* correction span */
+		u_int8_t hd_off_ct;	/* head offset count */
+		u_int8_t dat_strb_off_ct; /* data strobe offset count */
+		u_int8_t reserved1;
+		u_int8_t wr_retry_ct;	/* write retry count */
+		u_int8_t reserved2;
+		u_int8_t recov_tm_lim[2]; /* recovery time limit */
+	} err_recov_params;
 	struct page_disk_format {
 		u_int8_t pg_code;	/* page code (should be 3) */
 		u_int8_t pg_length;	/* page length (should be 0x16) */
@@ -253,6 +274,7 @@ union scsi_disk_pages {
 #define	DISK_FMT_RMB	0x20
 #define	DISK_FMT_HSEC	0x40
 #define	DISK_FMT_SSEC	0x80
+		u_int8_t reserved1;
 		u_int8_t reserved2;
 		u_int8_t reserved3;
 	} disk_format;
@@ -303,8 +325,8 @@ union scsi_disk_pages {
 		u_int8_t pin_34_2;	/* pin 34 (6) pin 2 (7/11) definition */
 		u_int8_t pin_4_1;	/* pin 4 (8/9) pin 1 (13) definition */
 		u_int8_t rpm[2];	/* rotational rate */
-		u_int8_t reserved3;
-		u_int8_t reserved4;
+		u_int8_t reserved1;
+		u_int8_t reserved2;
 	} flex_geometry;
 	struct page_caching {
 		u_int8_t pg_code;	/* page code (should be 8) */

Reply via email to