CVS commit: src/sys/dev/ic

2021-08-10 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Aug 10 15:28:44 UTC 2021

Modified Files:
src/sys/dev/ic: bcmgenet.c

Log Message:
Clear IFF_OACTIVE in genet_txintr (bug introduced in r1.8) and don't
sync DMA maps with size 0.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/bcmgenet.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/ic/bcmgenet.c
diff -u src/sys/dev/ic/bcmgenet.c:1.9 src/sys/dev/ic/bcmgenet.c:1.10
--- src/sys/dev/ic/bcmgenet.c:1.9	Mon May  3 10:28:26 2021
+++ src/sys/dev/ic/bcmgenet.c	Tue Aug 10 15:28:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.10 2021/08/10 15:28:44 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.9 2021/05/03 10:28:26 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.10 2021/08/10 15:28:44 jmcneill Exp $");
 
 #include 
 #include 
@@ -726,9 +726,11 @@ genet_rxintr(struct genet_softc *sc, int
 		}
 
 		/* unload map before it gets loaded in setup_rxbuf */
-		bus_dmamap_sync(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map,
-		0, sc->sc_rx.buf_map[index].map->dm_mapsize,
-		BUS_DMASYNC_POSTREAD);
+		if (sc->sc_rx.buf_map[index].map->dm_mapsize > 0) {
+			bus_dmamap_sync(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map,
+			0, sc->sc_rx.buf_map[index].map->dm_mapsize,
+			BUS_DMASYNC_POSTREAD);
+		}
 		bus_dmamap_unload(sc->sc_rx.buf_tag, sc->sc_rx.buf_map[index].map);
 		sc->sc_rx.buf_map[index].mbuf = NULL;
 
@@ -778,15 +780,18 @@ genet_txintr(struct genet_softc *sc, int
 		bmap = >sc_tx.buf_map[i];
 		if (bmap->mbuf != NULL) {
 			/* XXX first segment already unloads */
-			bus_dmamap_sync(sc->sc_tx.buf_tag, bmap->map,
-			0, bmap->map->dm_mapsize,
-			BUS_DMASYNC_POSTWRITE);
+			if (bmap->map->dm_mapsize > 0) {
+bus_dmamap_sync(sc->sc_tx.buf_tag, bmap->map,
+0, bmap->map->dm_mapsize,
+BUS_DMASYNC_POSTWRITE);
+			}
 			bus_dmamap_unload(sc->sc_tx.buf_tag, bmap->map);
 			m_freem(bmap->mbuf);
 			bmap->mbuf = NULL;
 			++pkts;
 		}
 
+		ifp->if_flags &= ~IFF_OACTIVE;
 		i = TX_NEXT(i);
 		sc->sc_tx.cidx = (sc->sc_tx.cidx + 1) & 0x;
 	}



CVS commit: src/sys/dev/ic

2021-08-06 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Fri Aug  6 18:15:48 UTC 2021

Modified Files:
src/sys/dev/ic: ssdfb.c

Log Message:
conditionally put back the include of 

This is a kludge to fix the build on some ports. According to pmap(9),
including  should be sufficient to use
"bool pmap_is_modified(struct vm_page *pg)". However, on several ports,
the function is implemented as a macro and depends on implementation
details of "struct vm_page *", which is normally an incomplete forward
declaration only. XXX revert when all ports are fixed.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/ic/ssdfb.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/ic/ssdfb.c
diff -u src/sys/dev/ic/ssdfb.c:1.19 src/sys/dev/ic/ssdfb.c:1.20
--- src/sys/dev/ic/ssdfb.c:1.19	Thu Aug  5 22:31:20 2021
+++ src/sys/dev/ic/ssdfb.c	Fri Aug  6 18:15:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb.c,v 1.19 2021/08/05 22:31:20 tnn Exp $ */
+/* $NetBSD: ssdfb.c,v 1.20 2021/08/06 18:15:48 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.19 2021/08/05 22:31:20 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.20 2021/08/06 18:15:48 tnn Exp $");
 
 #include "opt_ddb.h"
 
@@ -43,6 +43,9 @@ __KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.
 
 #include 
 #include 
+#ifdef pmap_is_modified
+#include 
+#endif
 
 #include 
 #include 



CVS commit: src/sys/dev/ic

2021-08-05 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug  5 19:07:09 UTC 2021

Modified Files:
src/sys/dev/ic: ssdfb.c ssdfbvar.h

Log Message:
ssdfb: support the SSD1353 controller and the DEP 160128A(1)-RGB display

DEP 160128A is a 160x128 18-bit RGB OLED display module advertised as
having an 8-bit parallel I/O interface. The controller can however attach
serially via spi(4) by moving jumper resistors J1 and J2 to GND position.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ic/ssdfb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ic/ssdfbvar.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/ic/ssdfb.c
diff -u src/sys/dev/ic/ssdfb.c:1.17 src/sys/dev/ic/ssdfb.c:1.18
--- src/sys/dev/ic/ssdfb.c:1.17	Thu Aug  5 00:16:36 2021
+++ src/sys/dev/ic/ssdfb.c	Thu Aug  5 19:07:09 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb.c,v 1.17 2021/08/05 00:16:36 tnn Exp $ */
+/* $NetBSD: ssdfb.c,v 1.18 2021/08/05 19:07:09 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.17 2021/08/05 00:16:36 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.18 2021/08/05 19:07:09 tnn Exp $");
 
 #include "opt_ddb.h"
 
@@ -75,6 +75,7 @@ static void	ssdfb_cursor(void *, int, in
 /* hardware interface */
 static int	ssdfb_init_ssd1306(struct ssdfb_softc *);
 static int	ssdfb_init_ssd1322(struct ssdfb_softc *);
+static int	ssdfb_init_ssd1353(struct ssdfb_softc *);
 static int	ssdfb_set_contrast(struct ssdfb_softc *, uint8_t, bool);
 static int	ssdfb_set_display_on(struct ssdfb_softc *, bool, bool);
 static int	ssdfb_set_mode(struct ssdfb_softc *, u_int);
@@ -89,6 +90,7 @@ static void	ssdfb_set_usepoll(struct ssd
 static int	ssdfb_sync(struct ssdfb_softc *, bool);
 static int	ssdfb_sync_ssd1306(struct ssdfb_softc *, bool);
 static int	ssdfb_sync_ssd1322(struct ssdfb_softc *, bool);
+static int	ssdfb_sync_ssd1353(struct ssdfb_softc *, bool);
 static uint64_t	ssdfb_transpose_block(uint8_t *, size_t);
 
 /* misc helpers */
@@ -104,7 +106,8 @@ static const char *ssdfb_controller_name
 	[SSDFB_CONTROLLER_UNKNOWN] =	"unknown",
 	[SSDFB_CONTROLLER_SSD1306] =	"Solomon Systech SSD1306",
 	[SSDFB_CONTROLLER_SH1106] =	"Sino Wealth SH1106",
-	[SSDFB_CONTROLLER_SSD1322] =	"Solomon Systech SSD1322"
+	[SSDFB_CONTROLLER_SSD1322] =	"Solomon Systech SSD1322",
+	[SSDFB_CONTROLLER_SSD1353] =	"Solomon Systech SSD1353"
 };
 
 /*
@@ -204,6 +207,44 @@ static const struct ssdfb_product ssdfb_
 		.p_multiplex_ratio =	0x3f,
 		.p_init =		ssdfb_init_ssd1322,
 		.p_sync =		ssdfb_sync_ssd1322
+	},
+	{
+		.p_product_id =		SSDFB_PRODUCT_SSD1353_GENERIC,
+		.p_controller_id =	SSDFB_CONTROLLER_SSD1353,
+		.p_name =		"generic",
+		.p_width =		160,
+		.p_height =		132,
+		.p_bits_per_pixel =	32,
+		.p_rgb = 		true,
+		.p_panel_shift =	0,
+		.p_compin_cfg = SSD1353_REMAP_RGB | SSD1353_REMAP_SPLIT_ODD_EVEN
+		| __SHIFTIN(2, SSD1353_REMAP_PIXEL_FORMAT_MASK),
+		.p_vcomh_deselect_level = SSD1353_DEFAULT_VCOMH,
+		.p_fosc =		SSD1353_DEFAULT_FREQUENCY,
+		.p_fosc_div =		SSD1353_DEFAULT_DIVIDER,
+		.p_default_contrast =	SSD1353_DEFAULT_CONTRAST_CONTROL,
+		.p_multiplex_ratio =	0x83,
+		.p_init =		ssdfb_init_ssd1353,
+		.p_sync =		ssdfb_sync_ssd1353
+	},
+	{
+		.p_product_id =		SSDFB_PRODUCT_DEP_160128A_RGB,
+		.p_controller_id =	SSDFB_CONTROLLER_SSD1353,
+		.p_name =		"Display Elektronik GmbH DEP 160128A(1)-RGB",
+		.p_width =		160,
+		.p_height =		128,
+		.p_bits_per_pixel =	32,
+		.p_rgb = 		true,
+		.p_panel_shift =	0,
+		.p_compin_cfg = SSD1353_REMAP_RGB | SSD1353_REMAP_SPLIT_ODD_EVEN
+		| __SHIFTIN(2, SSD1353_REMAP_PIXEL_FORMAT_MASK),
+		.p_vcomh_deselect_level = SSD1353_DEFAULT_VCOMH,
+		.p_fosc =		SSD1353_DEFAULT_FREQUENCY,
+		.p_fosc_div =		SSD1353_DEFAULT_DIVIDER,
+		.p_default_contrast =	SSD1353_DEFAULT_CONTRAST_CONTROL,
+		.p_multiplex_ratio =	0x83,
+		.p_init =		ssdfb_init_ssd1353,
+		.p_sync =		ssdfb_sync_ssd1353
 	}
 };
 
@@ -872,18 +913,148 @@ ssdfb_init_ssd1322(struct ssdfb_softc *s
 }
 
 static int
+ssdfb_init_ssd1353(struct ssdfb_softc *sc)
+{
+	int error;
+	uint8_t cmd[3];
+	bool usepoll = true;
+	uint8_t remap;
+
+	/*
+	 * Enter sleep.
+	 */
+	SSDFB_CMD2(SSD1353_CMD_SET_COMMAND_LOCK, SSD1353_COMMAND_UNLOCK_MAGIC);
+	if (error)
+		return error;
+	SSDFB_CMD1(SSD1353_CMD_RESET);
+	if (error)
+		return error;
+	SSDFB_CMD1(SSD1353_CMD_DEACTIVATE_SCROLL);
+	if (error)
+		return error;
+	SSDFB_CMD1(SSD1353_CMD_SET_DISPLAY_OFF);
+	if (error)
+		return error;
+
+	/*
+	 * Start charge pumps.
+	 */
+	SSDFB_CMD2(SSD1353_CMD_SET_VCOMH, sc->sc_p->p_vcomh_deselect_level);
+	if (error)
+		return error;
+	SSDFB_CMD2(SSD1353_CMD_SET_PRE_CHARGE_VOLTAGE_LEVEL,
+	SSD1353_DEFAULT_PRE_CHARGE_VOLTAGE_LEVEL);
+	if (error)
+		return error;
+
+	/*
+	 * Configure timing characteristics.
+	 */
+	SSDFB_CMD2(SSD1353_CMD_SET_FRONT_CLOCK_DIVIDER,
+	   

CVS commit: src/sys/dev/ic

2021-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug  5 00:16:36 UTC 2021

Modified Files:
src/sys/dev/ic: ssdfb.c ssdfbvar.h

Log Message:
ssdfb: prepare for supporting rgb color displays


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/ssdfb.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/ssdfbvar.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/ic/ssdfb.c
diff -u src/sys/dev/ic/ssdfb.c:1.16 src/sys/dev/ic/ssdfb.c:1.17
--- src/sys/dev/ic/ssdfb.c:1.16	Thu Aug  5 00:02:51 2021
+++ src/sys/dev/ic/ssdfb.c	Thu Aug  5 00:16:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb.c,v 1.16 2021/08/05 00:02:51 tnn Exp $ */
+/* $NetBSD: ssdfb.c,v 1.17 2021/08/05 00:16:36 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.16 2021/08/05 00:02:51 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.17 2021/08/05 00:16:36 tnn Exp $");
 
 #include "opt_ddb.h"
 
@@ -268,16 +268,35 @@ ssdfb_attach(struct ssdfb_softc *sc, int
 		goto out;
 	}
 #ifdef SSDFB_USE_NATIVE_DEPTH
-	ri->ri_depth =	sc->sc_p->p_bits_per_pixel;
+	ri->ri_depth = sc->sc_p->p_bits_per_pixel;
 #else
-	ri->ri_depth =	8;
+	if (sc->sc_p->p_rgb && sc->sc_p->p_bits_per_pixel == 32) {
+		ri->ri_depth = sc->sc_p->p_bits_per_pixel;
+		ri->ri_rnum = 8;
+		ri->ri_gnum = 8;
+		ri->ri_bnum = 8;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+		ri->ri_rpos = 0;
+		ri->ri_gpos = 8;
+		ri->ri_bpos = 16;
+#else
+		ri->ri_rpos = 24;
+		ri->ri_gpos = 16;
+		ri->ri_bpos = 8;
+#endif
+	} else {
+		ri->ri_depth = 8;
+	}
 #endif
 	ri->ri_font =	sc->sc_font;
 	ri->ri_width =	sc->sc_p->p_width;
 	ri->ri_height =	sc->sc_p->p_height;
 	ri->ri_stride =	ri->ri_width * ri->ri_depth / 8;
 	ri->ri_hw =	sc;
-	ri->ri_flg =	RI_FULLCLEAR | RI_FORCEMONO;
+	ri->ri_flg =	RI_FULLCLEAR;
+	if (!sc->sc_p->p_rgb) {
+		ri->ri_flg |= RI_FORCEMONO;
+	}
 	sc->sc_ri_bits_len = round_page(ri->ri_stride * ri->ri_height);
 	ri->ri_bits	= (u_char *)uvm_km_alloc(kernel_map, sc->sc_ri_bits_len,
 		 0, UVM_KMF_WIRED);
@@ -290,7 +309,9 @@ ssdfb_attach(struct ssdfb_softc *sc, int
 	if (error)
 		goto out;
 
-	ri->ri_caps &= ~WSSCREEN_WSCOLORS;
+	if (!sc->sc_p->p_rgb) {
+		ri->ri_caps &= ~WSSCREEN_WSCOLORS;
+	}
 
 	/*
 	 * Save original emul ops & insert our damage notification hooks.
@@ -425,8 +446,10 @@ ssdfb_ioctl(void *v, void *vs, u_long cm
 	case WSDISPLAYIO_GET_FBINFO:
 		fbi = (struct wsdisplayio_fbinfo *)data;
 		error = wsdisplayio_get_fbinfo(>sc_ri, fbi);
-		fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = cmaplen;
-		/* fbi->fbi_pixeltype = WSFB_GREYSCALE */;
+		if (!sc->sc_p->p_rgb) {
+			fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = cmaplen;
+			/* fbi->fbi_pixeltype = WSFB_GREYSCALE */;
+		}
 		return error;
 	case WSDISPLAYIO_LINEBYTES:
 		*(u_int *)data = sc->sc_ri.ri_stride;
@@ -483,6 +506,8 @@ ssdfb_ioctl(void *v, void *vs, u_long cm
 		return 0;
 #endif
 	case WSDISPLAYIO_GETCMAP:
+		if (sc->sc_p->p_rgb)
+			return ENOTSUP;
 		wc = (struct wsdisplay_cmap *)data;
 		if (wc->index >= cmaplen ||
 		wc->count > cmaplen - wc->index)
@@ -1117,9 +1142,9 @@ ssdfb_sync_ssd1322(struct ssdfb_softc *s
 	 * Transfer rasops bitmap into gddram shadow buffer while keeping track
 	 * of the bounding box of the dirty region we scribbled over.
 	 */
-	x1 = sc->sc_p->p_width;
+	x1 = width;
 	x2 = -1;
-	y1 = sc->sc_p->p_height;
+	y1 = height;
 	y2 = -1;
 	blockp = (uint16_t*)sc->sc_gddram;
 	for (y = 0; y < height; y++) {

Index: src/sys/dev/ic/ssdfbvar.h
diff -u src/sys/dev/ic/ssdfbvar.h:1.7 src/sys/dev/ic/ssdfbvar.h:1.8
--- src/sys/dev/ic/ssdfbvar.h:1.7	Mon Aug  2 14:00:48 2021
+++ src/sys/dev/ic/ssdfbvar.h	Thu Aug  5 00:16:36 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfbvar.h,v 1.7 2021/08/02 14:00:48 tnn Exp $ */
+/* $NetBSD: ssdfbvar.h,v 1.8 2021/08/05 00:16:36 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -235,6 +235,13 @@
 #define SSD1353_CMD_SET_SECOND_PRECHARGE_SPEED		0x8a
 	#define SSD1353_DEFAULT_SECOND_PRECHARGE_SPEED	2
 #define SSD1353_CMD_REMAP_COLOR_DEPTH			0xa0
+	#define SSD1353_REMAP_NO_INCREMENT		__BIT(0)
+	#define SSD1353_REMAP_SEG_DIRECTION		__BIT(1)
+	#define SSD1353_REMAP_RGB			__BIT(2)
+	#define SSD1353_REMAP_LR			__BIT(3)
+	#define SSD1353_REMAP_COM_DIRECTION		__BIT(4)
+	#define SSD1353_REMAP_SPLIT_ODD_EVEN		__BIT(5)
+	#define SSD1353_REMAP_PIXEL_FORMAT_MASK		__BITS(7, 6)
 #define SSD1353_CMD_SET_DISPLAY_START_LINE		SSD1322_CMD_SET_DISPLAY_START_LINE
 #define SSD1353_CMD_SET_DISPLAY_OFFSET			SSD1322_CMD_SET_DISPLAY_OFFSET
 #define SSD1353_CMD_SET_VERTICAL_SCROLL_AREA		SSDFB_CMD_SET_VERTICAL_SCROLL_AREA
@@ -305,6 +312,7 @@ struct ssdfb_product {
 	intp_width;
 	intp_height;
 	intp_bits_per_pixel;
+	boolp_rgb;
 	intp_panel_shift;
 	uint8_tp_fosc;
 	uint8_tp_fosc_div;



CVS commit: src/sys/dev/ic

2021-08-04 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Aug  5 00:02:51 UTC 2021

Modified Files:
src/sys/dev/ic: ssdfb.c

Log Message:
ssdfb: make it work on big-endian


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/ic/ssdfb.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/ic/ssdfb.c
diff -u src/sys/dev/ic/ssdfb.c:1.15 src/sys/dev/ic/ssdfb.c:1.16
--- src/sys/dev/ic/ssdfb.c:1.15	Mon Aug  2 14:00:48 2021
+++ src/sys/dev/ic/ssdfb.c	Thu Aug  5 00:02:51 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb.c,v 1.15 2021/08/02 14:00:48 tnn Exp $ */
+/* $NetBSD: ssdfb.c,v 1.16 2021/08/05 00:02:51 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.15 2021/08/02 14:00:48 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.16 2021/08/05 00:02:51 tnn Exp $");
 
 #include "opt_ddb.h"
 
@@ -1126,24 +1126,27 @@ ssdfb_sync_ssd1322(struct ssdfb_softc *s
 		src = (uint16_t*)>ri_bits[y * ri->ri_stride];
 		src32 = (uint32_t*)src;
 		for (x = 0; x < width_in_blocks; x++) {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
-#  ifdef SSDFB_USE_NATIVE_DEPTH
+#ifdef SSDFB_USE_NATIVE_DEPTH
 			raw_block =
 			((*src << 12) & 0xf000) |
-			((*src << 4) & 0x0f00) |
-			((*src >> 4) & 0x00f0) |
+			((*src << 4)  & 0x0f00) |
+			((*src >> 4)  & 0x00f0) |
 			((*src >> 12) & 0x000f);
 			src++;
-#  else
+#else
 			raw_block =
+#  if _BYTE_ORDER == _LITTLE_ENDIAN
 			((*src32 <<  8) & 0x0f00) |
 			((*src32 <<  4) & 0xf000) |
 			((*src32 >> 16) & 0x000f) |
 			((*src32 >> 20) & 0x00f0);
+#  else
+			((*src32 >> 24) & 0x000f) |
+			((*src32 >> 12) & 0x00f0) |
+			((*src32  ) & 0x0f00) |
+			((*src32 << 12) & 0xf000);
 #  endif
 			src32++;
-#else
-#  error please add big endian host support here
 #endif
 			if (raw_block != *blockp) {
 *blockp = raw_block;
@@ -1159,7 +1162,6 @@ ssdfb_sync_ssd1322(struct ssdfb_softc *s
 			blockp++;
 		}
 	}
-
 	blockp = (uint16_t*)sc->sc_gddram;
 	if (x2 != -1)
 		return sc->sc_transfer_rect(sc->sc_cookie,



CVS commit: src/sys/dev/ic

2021-08-02 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Mon Aug  2 14:00:48 UTC 2021

Modified Files:
src/sys/dev/ic: ssdfb.c ssdfbvar.h

Log Message:
ssdfb: define SSD1353 command set

also adjust some SSD1322 command names


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/ic/ssdfb.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/ssdfbvar.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/ic/ssdfb.c
diff -u src/sys/dev/ic/ssdfb.c:1.14 src/sys/dev/ic/ssdfb.c:1.15
--- src/sys/dev/ic/ssdfb.c:1.14	Fri Jul 30 13:44:09 2021
+++ src/sys/dev/ic/ssdfb.c	Mon Aug  2 14:00:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb.c,v 1.14 2021/07/30 13:44:09 tnn Exp $ */
+/* $NetBSD: ssdfb.c,v 1.15 2021/08/02 14:00:48 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.14 2021/07/30 13:44:09 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.15 2021/08/02 14:00:48 tnn Exp $");
 
 #include "opt_ddb.h"
 
@@ -271,7 +271,7 @@ ssdfb_attach(struct ssdfb_softc *sc, int
 	ri->ri_depth =	sc->sc_p->p_bits_per_pixel;
 #else
 	ri->ri_depth =	8;
-#endif	
+#endif
 	ri->ri_font =	sc->sc_font;
 	ri->ri_width =	sc->sc_p->p_width;
 	ri->ri_height =	sc->sc_p->p_height;
@@ -774,14 +774,14 @@ ssdfb_init_ssd1322(struct ssdfb_softc *s
 	if (error)
 		return error;
 	SSDFB_CMD2(SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD,
-	SSD1322_DEFAULT_SECOND_PRECHARGE);
+	SSD1322_DEFAULT_SECOND_PRECHARGE_PERIOD);
 	if (error)
 		return error;
 
 	/*
 	 * Configure physical display panel layout.
 	 */
-	SSDFB_CMD2(SSD1322_CMD_SET_MUX_RATIO, sc->sc_p->p_multiplex_ratio);
+	SSDFB_CMD2(SSD1322_CMD_SET_MULTIPLEX_RATIO, sc->sc_p->p_multiplex_ratio);
 	if (error)
 		return error;
 	if (sc->sc_upsidedown)

Index: src/sys/dev/ic/ssdfbvar.h
diff -u src/sys/dev/ic/ssdfbvar.h:1.6 src/sys/dev/ic/ssdfbvar.h:1.7
--- src/sys/dev/ic/ssdfbvar.h:1.6	Fri Jul 30 13:44:09 2021
+++ src/sys/dev/ic/ssdfbvar.h	Mon Aug  2 14:00:48 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfbvar.h,v 1.6 2021/07/30 13:44:09 tnn Exp $ */
+/* $NetBSD: ssdfbvar.h,v 1.7 2021/08/02 14:00:48 tnn Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -154,13 +154,12 @@
 #define SSD1322_CMD_SET_DISPLAY_START_LINE		0xa1
 #define SSD1322_CMD_SET_DISPLAY_OFFSET			0xa2
 
-/* These are the same as SSDFB generic commands */
-#define SSD1322_CMD_ENTIRE_DISPLAY_OFF			0xa4
-#define SSD1322_CMD_ENTIRE_DISPLAY_ON			0xa5
-#define SSD1322_CMD_NORMAL_DISPLAY			0xa6
-#define SSD1322_CMD_INVERSE_DISPLAY			0xa7
-#define SSD1322_CMD_SET_SLEEP_MODE_ON			0xae
-#define SSD1322_CMD_SET_SLEEP_MODE_OFF			0xaf
+#define SSD1322_CMD_ENTIRE_DISPLAY_OFF			SSDFB_CMD_ENTIRE_DISPLAY_OFF
+#define SSD1322_CMD_ENTIRE_DISPLAY_ON			SSDFB_CMD_ENTIRE_DISPLAY_ON
+#define SSD1322_CMD_NORMAL_DISPLAY			SSDFB_CMD_SET_NORMAL_DISPLAY
+#define SSD1322_CMD_INVERSE_DISPLAY			SSDFB_CMD_SET_INVERSE_DISPLAY
+#define SSD1322_CMD_SET_SLEEP_MODE_ON			SSDFB_CMD_SET_DISPLAY_OFF
+#define SSD1322_CMD_SET_SLEEP_MODE_OFF			SSDFB_CMD_SET_DISPLAY_ON
 
 #define SSD1322_CMD_ENABLE_PARTIAL_DISPLAY		0xa8
 #define SSD1322_CMD_EXIT_PARTIAL_DISPLAY		0xa9
@@ -190,7 +189,7 @@
 	#define SSD1322_GPIO1_LOW			__BIT(3)
 	#define SSD1322_GPIO1_HIGH			__BITS(3, 2)
 #define SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD		0xb6
-	#define SSD1322_DEFAULT_SECOND_PRECHARGE	8
+	#define SSD1322_DEFAULT_SECOND_PRECHARGE_PERIOD	8
 #define SSD1322_CMD_SET_GRAY_SCALE_TABLE		0xb8
 #define SSD1322_CMD_SET_DEFAULT_GRAY_SCALE_TABLE	0xb9
 #define SSD1322_CMD_SET_PRE_CHARGE_VOLTAGE_LEVEL	0xbb
@@ -201,13 +200,73 @@
 	#define SSD1322_DEFAULT_CONTRAST_CURRENT	0x7f
 #define SSD1322_CMD_MASTER_CONTRAST_CURRENT_CONTROL	0xc7
 	#define SSD1322_DEFAULT_MASTER_CONTRAST_CURRENT_CONTROL	0xf
-#define SSD1322_CMD_SET_MUX_RATIO			0xca
+#define SSD1322_CMD_SET_MULTIPLEX_RATIO			0xca
 #define SSD1322_CMD_DISPLAY_ENHANCEMENT_B		0xd1
 	#define SSD1322_DISPLAY_ENHANCEMENT_B_MAGIC1	0xa2
 	#define SSD1322_DISPLAY_ENHANCEMENT_B_MAGIC2	0x20
 #define SSD1322_CMD_SET_COMMAND_LOCK			0xfd
 	#define SSD1322_COMMAND_UNLOCK_MAGIC		0x12
 	#define SSD1322_COMMAND_LOCK_MAGIC		0x16
+/* undocumented on this chip, but works in practice */
+#define SSD1322_CMD_NOP	SSDFB_CMD_NOP
+
+/*
+ * SSD1353 command set
+ */
+#define SSD1353_CMD_SET_COLUMN_ADDRESS			SSD1322_CMD_SET_COLUMN_ADDRESS
+#define SSD1353_CMD_DRAW_LINE0x21
+#define SSD1353_CMD_DRAW_RECTANGLE			0x22
+#define SSD1353_CMD_COPY0x23
+#define SSD1353_CMD_DIM	0x24
+#define SSD1353_CMD_CLEAR_WINDOW			0x25
+#define SSD1353_CMD_FILL_ENABLE0x26
+#define SSD1353_CMD_SCROLLING_SETUP			0x27
+#define SSD1353_CMD_DEACTIVATE_SCROLL			SSDFB_CMD_DEACTIVATE_SCROLL
+#define SSD1353_CMD_ACTIVATE_SCROLL			SSDFB_CMD_ACTIVATE_SCROLL
+#define SSD1353_CMD_WRITE_RAMSSD1322_CMD_WRITE_RAM
+#define SD1353_CMD_READ_RAMSSD1322_CMD_READ_RAM
+#define 

CVS commit: src/sys/dev/ic

2021-07-31 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Jul 31 10:04:13 UTC 2021

Modified Files:
src/sys/dev/ic: com.c

Log Message:
only read cpr register if we're going to use the value


To generate a diff of this commit:
cvs rdiff -u -r1.364 -r1.365 src/sys/dev/ic/com.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/ic/com.c
diff -u src/sys/dev/ic/com.c:1.364 src/sys/dev/ic/com.c:1.365
--- src/sys/dev/ic/com.c:1.364	Fri Jul 30 12:46:46 2021
+++ src/sys/dev/ic/com.c	Sat Jul 31 10:04:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.364 2021/07/30 12:46:46 tnn Exp $ */
+/* $NetBSD: com.c,v 1.365 2021/07/31 10:04:12 tnn Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.364 2021/07/30 12:46:46 tnn Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.365 2021/07/31 10:04:12 tnn Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -539,10 +539,11 @@ com_attach_subr(struct com_softc *sc)
 		goto fifodelay;
 
 	case COM_TYPE_DW_APB:
-		cpr = bus_space_read_4(sc->sc_regs.cr_iot, sc->sc_regs.cr_ioh,
-		DW_APB_UART_CPR);
-		if (!prop_dictionary_get_uint(dict, "fifolen", >sc_fifolen))
+		if (!prop_dictionary_get_uint(dict, "fifolen", >sc_fifolen)) {
+			cpr = bus_space_read_4(sc->sc_regs.cr_iot,
+			sc->sc_regs.cr_ioh, DW_APB_UART_CPR);
 			sc->sc_fifolen = __SHIFTOUT(cpr, UART_CPR_FIFO_MODE) * 16;
+		}
 		if (sc->sc_fifolen == 0) {
 			sc->sc_fifolen = 1;
 			fifo_msg = "DesignWare APB UART, no fifo";



CVS commit: src/sys/dev/ic

2021-07-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jul  1 20:39:15 UTC 2021

Modified Files:
src/sys/dev/ic: ax88190.c dl10019.c dp8390.c

Log Message:
Make sure the media / mii members in struct ethercom are initialized
so that the media-related ioctls work.  Problem reported by Björn Johannesson
on current-users@.

XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ic/ax88190.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/dl10019.c
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/ic/dp8390.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/ic/ax88190.c
diff -u src/sys/dev/ic/ax88190.c:1.17 src/sys/dev/ic/ax88190.c:1.18
--- src/sys/dev/ic/ax88190.c:1.17	Wed Jun 30 20:00:18 2021
+++ src/sys/dev/ic/ax88190.c	Thu Jul  1 20:39:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ax88190.c,v 1.17 2021/06/30 20:00:18 thorpej Exp $	*/
+/*	$NetBSD: ax88190.c,v 1.18 2021/07/01 20:39:15 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.17 2021/06/30 20:00:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.18 2021/07/01 20:39:15 thorpej Exp $");
 
 #include 
 #include 
@@ -101,6 +101,8 @@ ax88190_media_init(struct dp8390_softc *
 
 	callout_setfunc(>sc_tick_ch, ax88190_tick, sc);
 
+	sc->sc_ec.ec_mii = mii;
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = ax88190_mii_readreg;
 	mii->mii_writereg = ax88190_mii_writereg;

Index: src/sys/dev/ic/dl10019.c
diff -u src/sys/dev/ic/dl10019.c:1.16 src/sys/dev/ic/dl10019.c:1.17
--- src/sys/dev/ic/dl10019.c:1.16	Wed Jun 30 20:00:18 2021
+++ src/sys/dev/ic/dl10019.c	Thu Jul  1 20:39:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dl10019.c,v 1.16 2021/06/30 20:00:18 thorpej Exp $	*/
+/*	$NetBSD: dl10019.c,v 1.17 2021/07/01 20:39:15 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.16 2021/06/30 20:00:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.17 2021/07/01 20:39:15 thorpej Exp $");
 
 #include 
 #include 
@@ -134,6 +134,8 @@ dl10019_media_init(struct dp8390_softc *
 
 	callout_setfunc(>sc_tick_ch, dl10019_tick, sc);
 
+	sc->sc_ec.ec_mii = mii;
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = dl10019_mii_readreg;
 	mii->mii_writereg = dl10019_mii_writereg;

Index: src/sys/dev/ic/dp8390.c
diff -u src/sys/dev/ic/dp8390.c:1.98 src/sys/dev/ic/dp8390.c:1.99
--- src/sys/dev/ic/dp8390.c:1.98	Wed Jun 30 20:00:18 2021
+++ src/sys/dev/ic/dp8390.c	Thu Jul  1 20:39:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dp8390.c,v 1.98 2021/06/30 20:00:18 thorpej Exp $	*/
+/*	$NetBSD: dp8390.c,v 1.99 2021/07/01 20:39:15 thorpej Exp $	*/
 
 /*
  * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
@@ -14,7 +14,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.98 2021/06/30 20:00:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dp8390.c,v 1.99 2021/07/01 20:39:15 thorpej Exp $");
 
 #include "opt_inet.h"
 
@@ -68,7 +68,6 @@ void
 dp8390_media_init(struct dp8390_softc *sc)
 {
 
-	sc->sc_ec.ec_ifmedia = >sc_media;
 	ifmedia_init(>sc_media, 0, dp8390_mediachange, dp8390_mediastatus);
 	ifmedia_add(>sc_media, IFM_ETHER | IFM_MANUAL, 0, NULL);
 	ifmedia_set(>sc_media, IFM_ETHER | IFM_MANUAL);
@@ -135,7 +134,13 @@ dp8390_config(struct dp8390_softc *sc)
 	aprint_normal_dev(sc->sc_dev, "Ethernet address %s\n",
 	ether_sprintf(sc->sc_enaddr));
 
-	/* Initialize media goo. */
+	/*
+	 * Initialize media structures.  We'll default to pointing ec_ifmedia
+	 * at our embedded media structure.  A card front-end can initialize
+	 * ec_mii if it has an MII interface.  (Note that sc_media is an
+	 * alias of sc_mii.mii_media in dp8390_softc.)
+	 */
+	sc->sc_ec.ec_ifmedia = >sc_media;
 	(*sc->sc_media_init)(sc);
 
 	/* We can support 802.1Q VLAN-sized frames. */



CVS commit: src/sys/dev/ic

2021-06-30 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jun 30 20:00:18 UTC 2021

Modified Files:
src/sys/dev/ic: ax88190.c dl10019.c dp8390.c dp8390var.h

Log Message:
Fix a couple of problems with MII-equipped NE2000 derivatives reported by
Björn Johannesson on current-users@:

- Re-factor dp8390_stop() into dp8390_halt() (that does the stuff to
  halt the hardware) and dp8390_stop() (which alls dp8390_halt() before
  calling mii_down() via sc->sc_stop_card()).  This prevents us from
  calling mii_down() before all of the interface data structures have
  been set up, which these days can trip a KASSERT().

- Add a 1-second timer to call mii_tick(), and enable it in the
  sc->sc_init_card() callback, and cancel it in the sc->sc_stop_card()
  and sc->sc_media_fini() callbacks.  This is actually a long-standing
  bug that previously didn't have much practical effect, but causes
  problems with dhcpcd's link live-ness detection logic.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/ax88190.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/ic/dl10019.c
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/ic/dp8390.c
cvs rdiff -u -r1.34 -r1.35 src/sys/dev/ic/dp8390var.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/ic/ax88190.c
diff -u src/sys/dev/ic/ax88190.c:1.16 src/sys/dev/ic/ax88190.c:1.17
--- src/sys/dev/ic/ax88190.c:1.16	Tue Feb  4 05:25:39 2020
+++ src/sys/dev/ic/ax88190.c	Wed Jun 30 20:00:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ax88190.c,v 1.16 2020/02/04 05:25:39 thorpej Exp $	*/
+/*	$NetBSD: ax88190.c,v 1.17 2021/06/30 20:00:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.16 2020/02/04 05:25:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ax88190.c,v 1.17 2021/06/30 20:00:18 thorpej Exp $");
 
 #include 
 #include 
@@ -80,12 +80,27 @@ static const struct mii_bitbang_ops ax88
 	}
 };
 
+static void
+ax88190_tick(void *arg)
+{
+	struct dp8390_softc *sc = arg;
+	int s;
+
+	s = splnet();
+	mii_tick(>sc_mii);
+	splx(s);
+
+	callout_schedule(>sc_tick_ch, hz);
+}
+
 void
 ax88190_media_init(struct dp8390_softc *sc)
 {
 	struct ifnet *ifp = >sc_ec.ec_if;
 	struct mii_data *mii = >sc_mii;
 
+	callout_setfunc(>sc_tick_ch, ax88190_tick, sc);
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = ax88190_mii_readreg;
 	mii->mii_writereg = ax88190_mii_writereg;
@@ -107,8 +122,9 @@ void
 ax88190_media_fini(struct dp8390_softc *sc)
 {
 
+	callout_stop(>sc_tick_ch);
 	mii_detach(>sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
-	ifmedia_fini(>sc_mii.mii_media);
+	/* dp8390_detach() will call ifmedia_fini(). */
 }
 
 int
@@ -135,12 +151,14 @@ ax88190_init_card(struct dp8390_softc *s
 {
 
 	mii_mediachg(>sc_mii);
+	callout_schedule(>sc_tick_ch, hz);
 }
 
 void
 ax88190_stop_card(struct dp8390_softc *sc)
 {
 
+	callout_stop(>sc_tick_ch);
 	mii_down(>sc_mii);
 }
 

Index: src/sys/dev/ic/dl10019.c
diff -u src/sys/dev/ic/dl10019.c:1.15 src/sys/dev/ic/dl10019.c:1.16
--- src/sys/dev/ic/dl10019.c:1.15	Tue Feb  4 05:25:39 2020
+++ src/sys/dev/ic/dl10019.c	Wed Jun 30 20:00:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dl10019.c,v 1.15 2020/02/04 05:25:39 thorpej Exp $	*/
+/*	$NetBSD: dl10019.c,v 1.16 2021/06/30 20:00:18 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.15 2020/02/04 05:25:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.16 2021/06/30 20:00:18 thorpej Exp $");
 
 #include 
 #include 
@@ -113,12 +113,27 @@ dl10019_mii_reset(struct dp8390_softc *s
 	bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO, 0x00);
 }
 
+static void
+dl10019_tick(void *arg)
+{
+	struct dp8390_softc *sc = arg;
+	int s;
+
+	s = splnet();
+	mii_tick(>sc_mii);
+	splx(s);
+
+	callout_schedule(>sc_tick_ch, hz);
+}
+
 void
 dl10019_media_init(struct dp8390_softc *sc)
 {
 	struct ifnet *ifp = >sc_ec.ec_if;
 	struct mii_data *mii = >sc_mii;
 
+	callout_setfunc(>sc_tick_ch, dl10019_tick, sc);
+
 	mii->mii_ifp = ifp;
 	mii->mii_readreg = dl10019_mii_readreg;
 	mii->mii_writereg = dl10019_mii_writereg;
@@ -142,8 +157,9 @@ void
 dl10019_media_fini(struct dp8390_softc *sc)
 {
 
+	callout_stop(>sc_tick_ch);
 	mii_detach(>sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
-	ifmedia_fini(>sc_mii.mii_media);
+	/* dp8390_detach() will call ifmedia_fini(). */
 }
 
 int
@@ -171,12 +187,14 @@ dl10019_init_card(struct dp8390_softc *s
 
 	dl10019_mii_reset(sc);
 	mii_mediachg(>sc_mii);
+	callout_schedule(>sc_tick_ch, hz);
 }
 
 void
 dl10019_stop_card(struct dp8390_softc *sc)
 {
 
+	callout_stop(>sc_tick_ch);
 	mii_down(>sc_mii);
 }
 

Index: src/sys/dev/ic/dp8390.c
diff -u src/sys/dev/ic/dp8390.c:1.97 src/sys/dev/ic/dp8390.c:1.98
--- src/sys/dev/ic/dp8390.c:1.97	Tue Feb  4 05:25:39 2020
+++ src/sys/dev/ic/dp8390.c	Wed Jun 30 20:00:18 2021
@@ -1,4 

CVS commit: src/sys/dev/ic

2021-06-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Jun 12 12:15:54 UTC 2021

Modified Files:
src/sys/dev/ic: ath.c

Log Message:
ath(4): Use config_deactivate; don't abuse autoconf private dv_flags.


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 src/sys/dev/ic/ath.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/ic/ath.c
diff -u src/sys/dev/ic/ath.c:1.134 src/sys/dev/ic/ath.c:1.135
--- src/sys/dev/ic/ath.c:1.134	Tue Apr 13 03:27:13 2021
+++ src/sys/dev/ic/ath.c	Sat Jun 12 12:15:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ath.c,v 1.134 2021/04/13 03:27:13 mrg Exp $	*/
+/*	$NetBSD: ath.c,v 1.135 2021/06/12 12:15:54 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -41,7 +41,7 @@
 __FBSDID("$FreeBSD: src/sys/dev/ath/if_ath.c,v 1.104 2005/09/16 10:09:23 ru Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.134 2021/04/13 03:27:13 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.135 2021/06/12 12:15:54 riastradh Exp $");
 #endif
 
 /*
@@ -652,8 +652,7 @@ bad2:
 bad:
 	if (ah)
 		ath_hal_detach(ah);
-	/* XXX don't get under the abstraction like this */
-	sc->sc_dev->dv_flags &= ~DVF_ACTIVE;
+	(void)config_deactivate(sc->sc_dev);
 	return error;
 }
 



CVS commit: src/sys/dev/ic

2021-06-10 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Fri Jun 11 05:00:42 UTC 2021

Modified Files:
src/sys/dev/ic: an.c

Log Message:
Add a missing htole16() around the length passed to bpf_mtap2().
Allows `tcpdump` to work on BE machines without panicing the kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/ic/an.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/ic/an.c
diff -u src/sys/dev/ic/an.c:1.73 src/sys/dev/ic/an.c:1.74
--- src/sys/dev/ic/an.c:1.73	Wed Jan 29 14:09:58 2020
+++ src/sys/dev/ic/an.c	Fri Jun 11 05:00:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: an.c,v 1.73 2020/01/29 14:09:58 thorpej Exp $	*/
+/*	$NetBSD: an.c,v 1.74 2021/06/11 05:00:41 jdc Exp $	*/
 /*
  * Copyright (c) 1997, 1998, 1999
  *	Bill Paul .  All rights reserved.
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.73 2020/01/29 14:09:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: an.c,v 1.74 2021/06/11 05:00:41 jdc Exp $");
 
 
 #include 
@@ -1509,7 +1509,7 @@ an_rx_intr(struct an_softc *sc)
 		(le16toh(frmhdr.an_rx_status) & AN_STAT_UNDECRYPTABLE))
 		tap->ar_flags |= IEEE80211_RADIOTAP_F_BADFCS;
 
-		bpf_mtap2(sc->sc_drvbpf, tap, tap->ar_ihdr.it_len, m,
+		bpf_mtap2(sc->sc_drvbpf, tap, htole16(tap->ar_ihdr.it_len), m,
 		BPF_D_IN);
 	}
 	wh = mtod(m, struct ieee80211_frame_min *);



CVS commit: src/sys/dev/ic

2021-06-02 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jun  2 21:35:17 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c

Log Message:
tpm(4): Preserve error if any on ending commands.

This way we don't spuriously suppress an error, such as
TPM_DEACTIVATED, in a loop where we rely on it.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/ic/tpm.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.21 src/sys/dev/ic/tpm.c:1.22
--- src/sys/dev/ic/tpm.c:1.21	Sat May 29 08:45:29 2021
+++ src/sys/dev/ic/tpm.c	Wed Jun  2 21:35:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.21 2021/05/29 08:45:29 riastradh Exp $	*/
+/*	$NetBSD: tpm.c,v 1.22 2021/06/02 21:35:17 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.21 2021/05/29 08:45:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.22 2021/06/02 21:35:17 riastradh Exp $");
 
 #include 
 #include 
@@ -811,7 +811,7 @@ tpm_tis12_end(struct tpm_softc *sc, int 
 	if (rw == UIO_READ) {
 		rv = tpm_waitfor(sc, TPM_STS_VALID, TPM_READ_TMO, sc->sc_intf->read);
 		if (rv)
-			return rv;
+			goto out;
 
 		/* Still more data? */
 		sc->sc_status = tpm_status(sc);
@@ -836,7 +836,7 @@ tpm_tis12_end(struct tpm_softc *sc, int 
 		err ? TPM_STS_CMD_READY : TPM_STS_GO);
 	}
 
-	return rv;
+out:	return err ? err : rv;
 }
 
 const struct tpm_intf tpm_intf_tis12 = {



CVS commit: src/sys/dev/ic

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 10:48:23 UTC 2021

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
nvme(4): Move disestablishment of admin q interrupt to nvme_detach.

Nothing re-established this after suspend/resume, so attempting
suspend/resume/suspend would crash, and presumably we would miss
interrupts after resume.  This keeps the establish/disestablish more
symmetric in attach/detach.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.56 src/sys/dev/ic/nvme.c:1.57
--- src/sys/dev/ic/nvme.c:1.56	Sat May 29 08:46:38 2021
+++ src/sys/dev/ic/nvme.c	Sat May 29 10:48:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.56 2021/05/29 08:46:38 riastradh Exp $	*/
+/*	$NetBSD: nvme.c,v 1.57 2021/05/29 10:48:23 riastradh Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.56 2021/05/29 08:46:38 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.57 2021/05/29 10:48:23 riastradh Exp $");
 
 #include 
 #include 
@@ -558,6 +558,7 @@ nvme_detach(struct nvme_softc *sc, int f
 		return error;
 
 	/* from now on we are committed to detach, following will never fail */
+	sc->sc_intr_disestablish(sc, NVME_ADMIN_Q);
 	for (i = 0; i < sc->sc_nq; i++)
 		nvme_q_free(sc, sc->sc_q[i]);
 	kmem_free(sc->sc_q, sizeof(*sc->sc_q) * sc->sc_nq);
@@ -628,7 +629,7 @@ disable:
 	return error;
 }
 
-int
+static int
 nvme_shutdown(struct nvme_softc *sc)
 {
 	uint32_t cc, csts;
@@ -645,7 +646,6 @@ nvme_shutdown(struct nvme_softc *sc)
 			disabled = true;
 		}
 	}
-	sc->sc_intr_disestablish(sc, NVME_ADMIN_Q);
 	if (disabled)
 		goto disable;
 



CVS commit: src/sys/dev/ic

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 08:45:29 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c tpmreg.h

Log Message:
tpm(4): Handle TPM 2.0 random source too, and loop on short reads.

Tested on ThinkPad T480.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/ic/tpm.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ic/tpmreg.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.20 src/sys/dev/ic/tpm.c:1.21
--- src/sys/dev/ic/tpm.c:1.20	Sat May 22 01:24:27 2021
+++ src/sys/dev/ic/tpm.c	Sat May 29 08:45:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.20 2021/05/22 01:24:27 thorpej Exp $	*/
+/*	$NetBSD: tpm.c,v 1.21 2021/05/29 08:45:29 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.20 2021/05/22 01:24:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.21 2021/05/29 08:45:29 riastradh Exp $");
 
 #include 
 #include 
@@ -327,10 +327,9 @@ tpm_tis12_probe(bus_space_tag_t bt, bus_
 	return 0;
 }
 
-static void
-tpm_tis12_rng_work(struct work *wk, void *cookie)
+static int
+tpm12_rng(struct tpm_softc *sc, unsigned *entropybitsp)
 {
-	struct tpm_softc *sc = cookie;
 	/*
 	 * TPM Specification Version 1.2, Main Part 3: Commands,
 	 * Sec. 13.6 TPM_GetRandom
@@ -344,25 +343,12 @@ tpm_tis12_rng_work(struct work *wk, void
 		uint32_t randomBytesSize;
 		uint8_t	bytes[64];
 	} __packed response;
-	bool busy, endwrite = false, endread = false;
+	bool endwrite = false, endread = false;
 	size_t nread;
 	uint16_t tag;
-	uint32_t pktlen, code, nbytes;
+	uint32_t pktlen, code, nbytes, entropybits = 0;
 	int rv;
 
-	/* Acknowledge the request.  */
-	sc->sc_rndpending = 0;
-
-	/* Lock userland out of the tpm, or fail if it's already open.  */
-	mutex_enter(>sc_lock);
-	busy = sc->sc_busy;
-	sc->sc_busy = true;
-	mutex_exit(>sc_lock);
-	if (busy) {		/* tough */
-		aprint_debug_dev(sc->sc_dev, "%s: device in use\n", __func__);
-		return;
-	}
-
 	/* Encode the command.  */
 	memset(, 0, sizeof(command));
 	command.hdr.tag = htobe16(TPM_TAG_RQU_COMMAND);
@@ -465,9 +451,199 @@ tpm_tis12_rng_work(struct work *wk, void
 	 * perhaps, cargocultily) estimate half a bit of entropy per
 	 * bit of data.
 	 */
-	rnd_add_data(>sc_rnd, response.bytes, nbytes, (NBBY/2)*nbytes);
+	CTASSERT(sizeof(response.bytes) <= UINT_MAX/(NBBY/2));
+	entropybits = (NBBY/2)*nbytes;
+	rnd_add_data(>sc_rnd, response.bytes, nbytes, entropybits);
+
+out:	/* End the read or write if still ongoing.  */
+	if (endread)
+		rv = (*sc->sc_intf->end)(sc, UIO_READ, rv);
+	if (endwrite)
+		rv = (*sc->sc_intf->end)(sc, UIO_WRITE, rv);
+
+	*entropybitsp = entropybits;
+	return rv;
+}
+
+static int
+tpm20_rng(struct tpm_softc *sc, unsigned *entropybitsp)
+{
+	/*
+	 * Trusted Platform Module Library, Family "2.0", Level 00
+	 * Revision 01.38, Part 3: Commands, Sec. 16.1 `TPM2_GetRandom'
+	 *
+	 * https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-3-Commands-01.38.pdf#page=133
+	 */
+	struct {
+		struct tpm_header hdr;
+		uint16_t bytesRequested;
+	} __packed command;
+	struct response {
+		struct tpm_header hdr;
+		uint16_t randomBytesSize;
+		uint8_t bytes[64];
+	} __packed response;
+	bool endwrite = false, endread = false;
+	size_t nread;
+	uint16_t tag;
+	uint32_t pktlen, code, nbytes, entropybits = 0;
+	int rv;
+
+	/* Encode the command.  */
+	memset(, 0, sizeof(command));
+	command.hdr.tag = htobe16(TPM2_ST_NO_SESSIONS);
+	command.hdr.length = htobe32(sizeof(command));
+	command.hdr.code = htobe32(TPM2_CC_GetRandom);
+	command.bytesRequested = htobe16(sizeof(response.bytes));
+
+	/* Write the command.   */
+	if ((rv = (*sc->sc_intf->start)(sc, UIO_WRITE)) != 0) {
+		device_printf(sc->sc_dev, "start write failed, error=%d\n",
+		rv);
+		goto out;
+	}
+	endwrite = true;
+	if ((rv = (*sc->sc_intf->write)(sc, , sizeof(command))) != 0) {
+		device_printf(sc->sc_dev, "write failed, error=%d\n", rv);
+		goto out;
+	}
+	rv = (*sc->sc_intf->end)(sc, UIO_WRITE, 0);
+	endwrite = false;
+	if (rv) {
+		device_printf(sc->sc_dev, "end write failed, error=%d\n", rv);
+		goto out;
+	}
+
+	/* Read the response header.  */
+	if ((rv = (*sc->sc_intf->start)(sc, UIO_READ)) != 0) {
+		device_printf(sc->sc_dev, "start write failed, error=%d\n",
+		rv);
+		goto out;
+	}
+	endread = true;
+	if ((rv = (*sc->sc_intf->read)(sc, , sizeof(response.hdr),
+		, 0)) != 0) {
+		device_printf(sc->sc_dev, "read failed, error=%d\n", rv);
+		goto out;
+	}
+
+	/* Verify the response header looks sensible.  */
+	if (nread != sizeof(response.hdr)) {
+		device_printf(sc->sc_dev, "read %zu bytes, expected %zu",
+		nread, sizeof(response.hdr));
+		goto out;
+	}
+	tag = be16toh(response.hdr.tag);
+	pktlen = be32toh(response.hdr.length);
+	code = be32toh(response.hdr.code);
+	if 

CVS commit: src/sys/dev/ic

2021-05-21 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 22 01:24:27 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c

Log Message:
Remove extra newline from boot messages (isa and acpi front-ends
already provide the newline).


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/ic/tpm.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.19 src/sys/dev/ic/tpm.c:1.20
--- src/sys/dev/ic/tpm.c:1.19	Mon Jan  4 18:26:59 2021
+++ src/sys/dev/ic/tpm.c	Sat May 22 01:24:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.19 2021/01/04 18:26:59 riastradh Exp $	*/
+/*	$NetBSD: tpm.c,v 1.20 2021/05/22 01:24:27 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.19 2021/01/04 18:26:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.20 2021/05/22 01:24:27 thorpej Exp $");
 
 #include 
 #include 
@@ -505,9 +505,6 @@ tpm_tis12_init(struct tpm_softc *sc)
 {
 	int rv;
 
-	aprint_naive("\n");
-	aprint_normal("\n");
-
 	sc->sc_caps = bus_space_read_4(sc->sc_bt, sc->sc_bh,
 	TPM_INTF_CAPABILITY);
 	sc->sc_devid = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_ID);



CVS commit: src/sys/dev/ic

2021-05-12 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu May 13 05:56:39 UTC 2021

Modified Files:
src/sys/dev/ic: dwc_gmac.c

Log Message:
 Cast to uint32_t to avoid undefined behavior in dwc_gmac_write_hwaddr().
Found by kUBSan.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/dev/ic/dwc_gmac.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/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.72 src/sys/dev/ic/dwc_gmac.c:1.73
--- src/sys/dev/ic/dwc_gmac.c:1.72	Thu Dec 31 15:09:12 2020
+++ src/sys/dev/ic/dwc_gmac.c	Thu May 13 05:56:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.72 2020/12/31 15:09:12 ryo Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.73 2021/05/13 05:56:39 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.72 2020/12/31 15:09:12 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.73 2021/05/13 05:56:39 msaitoh Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -398,7 +398,7 @@ dwc_gmac_write_hwaddr(struct dwc_gmac_so
 
 	hi = enaddr[4] | (enaddr[5] << 8);
 	lo = enaddr[0] | (enaddr[1] << 8) | (enaddr[2] << 16)
-	| (enaddr[3] << 24);
+	| ((uint32_t)enaddr[3] << 24);
 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_ADDR0HI, hi);
 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_MAC_ADDR0LO, lo);
 }



CVS commit: src/sys/dev/ic

2021-04-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Apr 13 04:13:52 UTC 2021

Modified Files:
src/sys/dev/ic: bwfm.c

Log Message:
remove extra line that clearly isn't meant to be there and may trigger
uninitialised reads of variables.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/ic/bwfm.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.29 src/sys/dev/ic/bwfm.c:1.30
--- src/sys/dev/ic/bwfm.c:1.29	Wed Jul 22 17:23:52 2020
+++ src/sys/dev/ic/bwfm.c	Tue Apr 13 04:13:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.29 2020/07/22 17:23:52 riastradh Exp $ */
+/* $NetBSD: bwfm.c,v 1.30 2021/04/13 04:13:52 mrg Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -166,7 +166,6 @@ bwfm_firmware_read_file(struct bwfm_soft
 
 	names[1] = kmem_asprintf("%s.%s", fwp->fwsel_basename,
 	bwfm_firmware_filetypes[which].suffix);
-	if (ctx->ctx_model)
 	names[0] = ctx->ctx_model ? kmem_asprintf("%s.%s.%s",
 	fwp->fwsel_basename, ctx->ctx_model,
 	bwfm_firmware_filetypes[which].suffix) : NULL;



CVS commit: src/sys/dev/ic

2021-03-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Mar 25 05:34:49 UTC 2021

Modified Files:
src/sys/dev/ic: com.c comvar.h

Log Message:
Introduce COM_HW_BROKEN_ETXRDY bit in sc_hwflags; push TX queue if
possible in comintr() even if IIR_NOPEND is asserted.

Combined with sc_poll_ticks, this flag works around HW bug, by which
ETXRDY interrupts are (sometimes) lost.


To generate a diff of this commit:
cvs rdiff -u -r1.362 -r1.363 src/sys/dev/ic/com.c
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/ic/comvar.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/ic/com.c
diff -u src/sys/dev/ic/com.c:1.362 src/sys/dev/ic/com.c:1.363
--- src/sys/dev/ic/com.c:1.362	Thu Mar 25 05:33:59 2021
+++ src/sys/dev/ic/com.c	Thu Mar 25 05:34:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.362 2021/03/25 05:33:59 rin Exp $ */
+/* $NetBSD: com.c,v 1.363 2021/03/25 05:34:49 rin Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.362 2021/03/25 05:33:59 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.363 2021/03/25 05:34:49 rin Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -2162,15 +2162,17 @@ comintr(void *arg)
 		}
 	}
 
+	end = sc->sc_ebuf;
+	put = sc->sc_rbput;
+	cc = sc->sc_rbavail;
+
 	if (ISSET(iir, IIR_NOPEND)) {
+		if (ISSET(sc->sc_hwflags, COM_HW_BROKEN_ETXRDY))
+			goto do_tx;
 		mutex_spin_exit(>sc_lock);
 		return (0);
 	}
 
-	end = sc->sc_ebuf;
-	put = sc->sc_rbput;
-	cc = sc->sc_rbavail;
-
 again:	do {
 		u_char	msr, delta;
 
@@ -2306,6 +2308,7 @@ again:	do {
 	 */
 	(iir & IIR_IMASK) != IIR_TXRDY);
 
+do_tx:
 	/*
 	 * Read LSR again, since there may be an interrupt between
 	 * the last LSR read and IIR read above.
@@ -2358,7 +2361,8 @@ again:	do {
 	mutex_spin_exit(>sc_lock);
 
 	/* Wake up the poller. */
-	softint_schedule(sc->sc_si);
+	if ((sc->sc_rx_ready | sc->sc_st_check | sc->sc_tx_done) != 0)
+		softint_schedule(sc->sc_si);
 
 #ifdef RND_COM
 	rnd_add_uint32(>rnd_source, iir | lsr);

Index: src/sys/dev/ic/comvar.h
diff -u src/sys/dev/ic/comvar.h:1.93 src/sys/dev/ic/comvar.h:1.94
--- src/sys/dev/ic/comvar.h:1.93	Thu Mar 25 05:33:59 2021
+++ src/sys/dev/ic/comvar.h	Thu Mar 25 05:34:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: comvar.h,v 1.93 2021/03/25 05:33:59 rin Exp $	*/
+/*	$NetBSD: comvar.h,v 1.94 2021/03/25 05:34:49 rin Exp $	*/
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
@@ -61,7 +61,7 @@ int com_is_console(bus_space_tag_t, bus_
 /* Hardware flag masks */
 #define	COM_HW_NOIEN	0x01
 #define	COM_HW_FIFO	0x02
-		/*	0x04	free for use */
+#define	COM_HW_BROKEN_ETXRDY	0x04
 #define	COM_HW_FLOW	0x08
 #define	COM_HW_DEV_OK	0x20
 #define	COM_HW_CONSOLE	0x40



CVS commit: src/sys/dev/ic

2021-03-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar 14 08:13:58 UTC 2021

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
No need to have an MD #ifdef in an MI file, so remove it.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.28 src/sys/dev/ic/sti.c:1.29
--- src/sys/dev/ic/sti.c:1.28	Sun Mar  7 14:31:20 2021
+++ src/sys/dev/ic/sti.c	Sun Mar 14 08:13:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.28 2021/03/07 14:31:20 skrll Exp $	*/
+/*	$NetBSD: sti.c,v 1.29 2021/03/14 08:13:58 skrll Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.28 2021/03/07 14:31:20 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.29 2021/03/14 08:13:58 skrll Exp $");
 
 #include "wsdisplay.h"
 
@@ -1427,9 +1427,8 @@ sti_alloc_attr(void *v, int fg, int bg, 
 	return 0;
 }
 
-#ifdef hp300	/* XXX */
 /*
- * Early console support.  Only used on hp300.
+ * Early console support.  Only used on hp300, currently
  */
 int
 sti_cnattach(struct sti_rom *rom, struct sti_screen *scr, bus_space_tag_t memt,
@@ -1465,7 +1464,6 @@ sti_cnattach(struct sti_rom *rom, struct
 
 	return 0;
 }
-#endif
 
 int
 ngle_default_putcmap(struct sti_screen *scr, u_int idx, u_int count)



CVS commit: src/sys/dev/ic

2021-03-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Mar 10 18:26:16 UTC 2021

Modified Files:
src/sys/dev/ic: gem.c

Log Message:
remove extra arguments


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/sys/dev/ic/gem.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/ic/gem.c
diff -u src/sys/dev/ic/gem.c:1.133 src/sys/dev/ic/gem.c:1.134
--- src/sys/dev/ic/gem.c:1.133	Sat Jan 30 02:53:01 2021
+++ src/sys/dev/ic/gem.c	Wed Mar 10 13:26:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gem.c,v 1.133 2021/01/30 07:53:01 jdc Exp $ */
+/*	$NetBSD: gem.c,v 1.134 2021/03/10 18:26:16 christos Exp $ */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.133 2021/01/30 07:53:01 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.134 2021/03/10 18:26:16 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -2297,17 +2297,17 @@ gem_rx_watchdog(void *arg)
 		if (rx_fifo_wr_ptr != rx_fifo_rd_ptr) {
 			DPRINTF(sc,
 			("%s: rx_watchdog: wr & rd ptr different\n",
-			device_xname(sc->sc_dev), state));
+			device_xname(sc->sc_dev)));
 			needreset = 0;
 		}
 		if (sc->sc_rx_fifo_wr_ptr != rx_fifo_wr_ptr) {
 			DPRINTF(sc, ("%s: rx_watchdog: wr pointer != saved\n",
-			device_xname(sc->sc_dev), state));
+			device_xname(sc->sc_dev)));
 			needreset = 0;
 		}
 		if (sc->sc_rx_fifo_rd_ptr != rx_fifo_rd_ptr) {
 			DPRINTF(sc, ("%s: rx_watchdog: rd pointer != saved\n",
-			device_xname(sc->sc_dev), state));
+			device_xname(sc->sc_dev)));
 			needreset = 0;
 		}
 		if (needreset) {



CVS commit: src/sys/dev/ic

2021-03-08 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar  8 13:14:44 UTC 2021

Modified Files:
src/sys/dev/ic: bcmgenet.c bcmgenetreg.h bcmgenetvar.h

Log Message:
Compute CRC for all segments of a multi-buffer packet.
Add interrupt mitigation for transmit and receive.
Use separate transmit lock.
Fix some error paths.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/bcmgenet.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/ic/bcmgenetreg.h
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/ic/bcmgenetvar.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/ic/bcmgenet.c
diff -u src/sys/dev/ic/bcmgenet.c:1.7 src/sys/dev/ic/bcmgenet.c:1.8
--- src/sys/dev/ic/bcmgenet.c:1.7	Sat Jun 27 13:34:20 2020
+++ src/sys/dev/ic/bcmgenet.c	Mon Mar  8 13:14:44 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.7 2020/06/27 13:34:20 jmcneill Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.8 2021/03/08 13:14:44 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.7 2020/06/27 13:34:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.8 2021/03/08 13:14:44 mlelstv Exp $");
 
 #include 
 #include 
@@ -72,20 +72,24 @@ CTASSERT(MCLBYTES == 2048);
 #define	CALLOUT_FLAGS		0
 #endif
 
-#define	TX_SKIP(n, o)		(((n) + (o)) & (GENET_DMA_DESC_COUNT - 1))
-#define	TX_NEXT(n)		TX_SKIP(n, 1)
-#define	RX_NEXT(n)		(((n) + 1) & (GENET_DMA_DESC_COUNT - 1))
-
 #define	TX_MAX_SEGS		128
-#define	TX_DESC_COUNT		GENET_DMA_DESC_COUNT
-#define	RX_DESC_COUNT		GENET_DMA_DESC_COUNT
+#define	TX_DESC_COUNT		256 /* GENET_DMA_DESC_COUNT */
+#define	RX_DESC_COUNT		256 /* GENET_DMA_DESC_COUNT */
 #define	MII_BUSY_RETRY		1000
 #define	GENET_MAX_MDF_FILTER	17
 
+#define	TX_SKIP(n, o)		(((n) + (o)) % TX_DESC_COUNT)
+#define	TX_NEXT(n)		TX_SKIP(n, 1)
+#define	RX_NEXT(n)		(((n) + 1) % RX_DESC_COUNT)
+
 #define	GENET_LOCK(sc)		mutex_enter(&(sc)->sc_lock)
 #define	GENET_UNLOCK(sc)	mutex_exit(&(sc)->sc_lock)
 #define	GENET_ASSERT_LOCKED(sc)	KASSERT(mutex_owned(&(sc)->sc_lock))
 
+#define	GENET_TXLOCK(sc)		mutex_enter(&(sc)->sc_txlock)
+#define	GENET_TXUNLOCK(sc)		mutex_exit(&(sc)->sc_txlock)
+#define	GENET_ASSERT_TXLOCKED(sc)	KASSERT(mutex_owned(&(sc)->sc_txlock))
+
 #define	RD4(sc, reg)			\
 	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
 #define	WR4(sc, reg, val)		\
@@ -190,7 +194,6 @@ genet_setup_txdesc(struct genet_softc *s
 	uint32_t status;
 
 	status = flags | __SHIFTIN(len, GENET_TX_DESC_STATUS_BUFLEN);
-	++sc->sc_tx.queued;
 
 	WR4(sc, GENET_TX_DESC_ADDRESS_LO(index), (uint32_t)paddr);
 	WR4(sc, GENET_TX_DESC_ADDRESS_HI(index), (uint32_t)(paddr >> 32));
@@ -203,49 +206,58 @@ genet_setup_txbuf(struct genet_softc *sc
 	bus_dma_segment_t *segs;
 	int error, nsegs, cur, i;
 	uint32_t flags;
+	bool nospace;
+
+	/* at least one descriptor free ? */
+	if (sc->sc_tx.queued >= TX_DESC_COUNT - 1)
+		return -1;
 
 	error = bus_dmamap_load_mbuf(sc->sc_tx.buf_tag,
 	sc->sc_tx.buf_map[index].map, m, BUS_DMA_WRITE | BUS_DMA_NOWAIT);
 	if (error == EFBIG) {
 		device_printf(sc->sc_dev,
 		"TX packet needs too many DMA segments, dropping...\n");
-		m_freem(m);
-		return 0;
+		return -2;
 	}
-	if (error != 0)
+	if (error != 0) {
+		device_printf(sc->sc_dev,
+		"TX packet cannot be mapped, retried...\n");
 		return 0;
+	}
 
 	segs = sc->sc_tx.buf_map[index].map->dm_segs;
 	nsegs = sc->sc_tx.buf_map[index].map->dm_nsegs;
 
-	if (sc->sc_tx.queued >= GENET_DMA_DESC_COUNT - nsegs) {
+	nospace = sc->sc_tx.queued >= TX_DESC_COUNT - nsegs;
+	if (nospace) {
 		bus_dmamap_unload(sc->sc_tx.buf_tag,
 		sc->sc_tx.buf_map[index].map);
+		/* XXX coalesce and retry ? */
 		return -1;
 	}
 
+	bus_dmamap_sync(sc->sc_tx.buf_tag, sc->sc_tx.buf_map[index].map,
+	0, sc->sc_tx.buf_map[index].map->dm_mapsize, BUS_DMASYNC_PREWRITE);
+
+	/* stored in same index as loaded map */
+	sc->sc_tx.buf_map[index].mbuf = m;
+
 	flags = GENET_TX_DESC_STATUS_SOP |
 		GENET_TX_DESC_STATUS_CRC |
 		GENET_TX_DESC_STATUS_QTAG;
 
 	for (cur = index, i = 0; i < nsegs; i++) {
-		sc->sc_tx.buf_map[cur].mbuf = (i == 0 ? m : NULL);
 		if (i == nsegs - 1)
 			flags |= GENET_TX_DESC_STATUS_EOP;
 
 		genet_setup_txdesc(sc, cur, flags, segs[i].ds_addr,
 		segs[i].ds_len);
 
-		if (i == 0) {
+		if (i == 0)
 			flags &= ~GENET_TX_DESC_STATUS_SOP;
-			flags &= ~GENET_TX_DESC_STATUS_CRC;
-		}
 		cur = TX_NEXT(cur);
 	}
 
-	bus_dmamap_sync(sc->sc_tx.buf_tag, sc->sc_tx.buf_map[index].map,
-	0, sc->sc_tx.buf_map[index].map->dm_mapsize, BUS_DMASYNC_PREWRITE);
-
 	return nsegs;
 }
 
@@ -426,6 +438,43 @@ genet_reset(struct genet_softc *sc)
 }
 
 static void
+genet_set_rxthresh(struct genet_softc *sc, int qid, int usecs, int count)
+{
+	int ticks;
+	uint32_t val;
+
+	/* convert to 125MHz/1024 ticks */
+	ticks = howmany(usecs * 125, 1024);
+
+	if (count < 1)
+		count = 1;
+	if 

CVS commit: src/sys/dev/ic

2021-03-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar  7 14:31:20 UTC 2021

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
Remove an '#ifndef hp300' and make STI_{EN,DIS}ABLE_ROM simply check the
sc_{en,disable}_rom methdos provide by the bus attachment glue.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.27 src/sys/dev/ic/sti.c:1.28
--- src/sys/dev/ic/sti.c:1.27	Sun Mar  7 10:02:33 2021
+++ src/sys/dev/ic/sti.c	Sun Mar  7 14:31:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.27 2021/03/07 10:02:33 skrll Exp $	*/
+/*	$NetBSD: sti.c,v 1.28 2021/03/07 14:31:20 skrll Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.27 2021/03/07 10:02:33 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.28 2021/03/07 14:31:20 skrll Exp $");
 
 #include "wsdisplay.h"
 
@@ -54,10 +54,6 @@ __KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.27
 #include 
 #include 
 
-#ifndef hp300	/* XXX */
-#include "sti_pci.h"
-#endif
-
 #ifdef STIDEBUG
 
 #define	DPRINTF(s)	do {	\
@@ -139,7 +135,6 @@ void	ngle_timber_setupfb(struct sti_scre
 int	ngle_putcmap(struct sti_screen *, u_int, u_int);
 #endif
 
-#if NSTI_PCI > 0
 #define	STI_ENABLE_ROM(sc) \
 do { \
 	if ((sc) != NULL && (sc)->sc_enable_rom != NULL) \
@@ -150,10 +145,6 @@ do { \
 	if ((sc) != NULL && (sc)->sc_disable_rom != NULL) \
 		(*(sc)->sc_disable_rom)(sc); \
 } while (0)
-#else
-#define	STI_ENABLE_ROM(sc)		do { /* nothing */ } while (0)
-#define	STI_DISABLE_ROM(sc)		do { /* nothing */ } while (0)
-#endif
 
 /* Macros to read larger than 8 bit values from byte roms */
 #define	parseshort(o) \



CVS commit: src/sys/dev/ic

2021-03-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Mar  7 10:02:34 UTC 2021

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
Use bus_space_mmap in sti_mmap.  This makes X on sti for my B160L nearly
work (the colour map is somewhat wrong), but at least the machine doesn't
wedge.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.26 src/sys/dev/ic/sti.c:1.27
--- src/sys/dev/ic/sti.c:1.26	Thu Mar  4 20:30:39 2021
+++ src/sys/dev/ic/sti.c	Sun Mar  7 10:02:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.26 2021/03/04 20:30:39 skrll Exp $	*/
+/*	$NetBSD: sti.c,v 1.27 2021/03/07 10:02:33 skrll Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.26 2021/03/04 20:30:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.27 2021/03/07 10:02:33 skrll Exp $");
 
 #include "wsdisplay.h"
 
@@ -1171,9 +1171,7 @@ paddr_t
 sti_mmap(void *v, void *vs, off_t offset, int prot)
 {
 	struct sti_screen *scr = (struct sti_screen *)v;
-#if 0
 	struct sti_rom *rom = scr->scr_rom;
-#endif
 	paddr_t pa;
 
 	if ((offset & PAGE_MASK) != 0)
@@ -1182,12 +1180,14 @@ sti_mmap(void *v, void *vs, off_t offset
 	if (offset < 0 || offset >= scr->fblen)
 		return -1;
 
-#if 0 /* XXX not all platforms provide bus_space_mmap() yet */
+	if (scr->scr_wsmode != WSDISPLAYIO_MODE_DUMBFB)
+		return -1;
+
 	pa = bus_space_mmap(rom->memt, scr->fbaddr, offset, prot,
 	BUS_SPACE_MAP_LINEAR);
-#else
-	pa = scr->fbaddr + offset;
-#endif
+
+	if (pa == -1)
+		pa = scr->fbaddr + offset;
 
 	return pa;
 }



CVS commit: src/sys/dev/ic

2021-03-05 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sat Mar  6 05:37:18 UTC 2021

Modified Files:
src/sys/dev/ic: mb89352.c

Log Message:
Fix a possible race condition in spc_msgin() in NO_MANUAL_XFER case.

To avoid the race, check SSTS and INTS after XFR command as
spc_pio_datain() does.

Reported from isaki@, observed on nono emulator.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/ic/mb89352.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/ic/mb89352.c
diff -u src/sys/dev/ic/mb89352.c:1.57 src/sys/dev/ic/mb89352.c:1.58
--- src/sys/dev/ic/mb89352.c:1.57	Mon Sep  3 16:29:31 2018
+++ src/sys/dev/ic/mb89352.c	Sat Mar  6 05:37:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $	*/
+/*	$NetBSD: mb89352.c,v 1.58 2021/03/06 05:37:18 tsutsui Exp $	*/
 /*	NecBSD: mb89352.c,v 1.4 1998/03/14 07:31:20 kmatsuda Exp	*/
 
 /*-
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.58 2021/03/06 05:37:18 tsutsui Exp $");
 
 #ifdef DDB
 #define	integrate
@@ -932,6 +932,7 @@ nextbyte:
 	 */
 	for (;;) {
 #ifdef NO_MANUAL_XFER /* XXX */
+		uint8_t intstat;
 		if (bus_space_read_1(iot, ioh, INTS) != 0) {
 			/*
 			 * Target left MESSAGE IN, probably because it
@@ -960,12 +961,18 @@ nextbyte:
 #else
 		bus_space_write_1(iot, ioh, SCMD, SCMD_XFR | SCMD_PROG_XFR);
 #endif
+		intstat = 0;
 		for (;;) {
 			if ((bus_space_read_1(iot, ioh, SSTS) &
 			SSTS_DREG_EMPTY) == 0)
 break;
-			if (bus_space_read_1(iot, ioh, INTS) != 0)
+			/*
+			 * We have to read INTS before checking SSTS to avoid
+			 * race between SSTS_DREG_EMPTY and INTS_CMD_DONE.
+			 */
+			if (intstat != 0)
 goto out;
+			intstat = bus_space_read_1(iot, ioh, INTS);
 		}
 		msg = bus_space_read_1(iot, ioh, DREG);
 #else



CVS commit: src/sys/dev/ic

2021-03-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Mar  4 20:30:39 UTC 2021

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.25 src/sys/dev/ic/sti.c:1.26
--- src/sys/dev/ic/sti.c:1.25	Sat Dec 26 08:58:03 2020
+++ src/sys/dev/ic/sti.c	Thu Mar  4 20:30:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.25 2020/12/26 08:58:03 tsutsui Exp $	*/
+/*	$NetBSD: sti.c,v 1.26 2021/03/04 20:30:39 skrll Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.25 2020/12/26 08:58:03 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.26 2021/03/04 20:30:39 skrll Exp $");
 
 #include "wsdisplay.h"
 
@@ -1260,7 +1260,7 @@ static const uint8_t
 sti_unitoroman[0x100 - 0xa0] = {
 	0xa0, 0xb8, 0xbf, 0xbb, 0xba, 0xbc,0, 0xbd,
 	0xab,0, 0xf9, 0xfb,0, 0xf6,0, 0xb0,
-	
+
 	0xb3, 0xfe,0,0, 0xa8, 0xf3, 0xf4, 0xf2,
 	   0,0, 0xfa, 0xfd, 0xf7, 0xf8,0, 0xb9,
 
@@ -1425,11 +1425,11 @@ sti_alloc_attr(void *v, int fg, int bg, 
 	WSATTR_UNDERLINE | WSATTR_WSCOLORS)) != 0)
 		return EINVAL;
 	if ((flags & WSATTR_REVERSE) != 0) {
-		fg = STI_COLOUR_BLACK; 
+		fg = STI_COLOUR_BLACK;
 		bg = STI_COLOUR_WHITE;
 	} else {
 		fg = STI_COLOUR_WHITE;
-		bg = STI_COLOUR_BLACK; 
+		bg = STI_COLOUR_BLACK;
 	}
 
 	*pattr = WSATTR_PACK(fg, bg, flags);



CVS commit: src/sys/dev/ic

2021-03-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Mar  4 07:29:40 UTC 2021

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Use BUS_ADDR_{LO,HI}32.  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.96 src/sys/dev/ic/ahcisata_core.c:1.97
--- src/sys/dev/ic/ahcisata_core.c:1.96	Thu Mar  4 07:24:38 2021
+++ src/sys/dev/ic/ahcisata_core.c	Thu Mar  4 07:29:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.96 2021/03/04 07:24:38 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.97 2021/03/04 07:29:40 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.96 2021/03/04 07:24:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.97 2021/03/04 07:29:40 skrll Exp $");
 
 #include 
 #include 
@@ -221,10 +221,10 @@ ahci_setup_port(struct ahci_softc *sc, i
 
 	achp = >sc_channels[i];
 
-	AHCI_WRITE(sc, AHCI_P_CLB(i), achp->ahcic_bus_cmdh);
-	AHCI_WRITE(sc, AHCI_P_CLBU(i), (uint64_t)achp->ahcic_bus_cmdh>>32);
-	AHCI_WRITE(sc, AHCI_P_FB(i), achp->ahcic_bus_rfis);
-	AHCI_WRITE(sc, AHCI_P_FBU(i), (uint64_t)achp->ahcic_bus_rfis>>32);
+	AHCI_WRITE(sc, AHCI_P_CLB(i), BUS_ADDR_LO32(achp->ahcic_bus_cmdh));
+	AHCI_WRITE(sc, AHCI_P_CLBU(i), BUS_ADDR_HI32(achp->ahcic_bus_cmdh));
+	AHCI_WRITE(sc, AHCI_P_FB(i), BUS_ADDR_LO32(achp->ahcic_bus_rfis));
+	AHCI_WRITE(sc, AHCI_P_FBU(i), BUS_ADDR_HI32(achp->ahcic_bus_rfis));
 }
 
 static void



CVS commit: src/sys/dev/ic

2021-03-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Mar  4 07:24:38 UTC 2021

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Use __BIT().  NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.95 src/sys/dev/ic/ahcisata_core.c:1.96
--- src/sys/dev/ic/ahcisata_core.c:1.95	Mon Jan 11 16:48:35 2021
+++ src/sys/dev/ic/ahcisata_core.c	Thu Mar  4 07:24:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.95 2021/01/11 16:48:35 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.96 2021/03/04 07:24:38 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.95 2021/01/11 16:48:35 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.96 2021/03/04 07:24:38 skrll Exp $");
 
 #include 
 #include 
@@ -604,7 +604,7 @@ ahci_intr(void *v)
 		while ((bit = ffs(ports)) != 0) {
 			bit--;
 			ahci_intr_port_common(>sc_channels[bit].ata_channel);
-			ports &= ~(1U << bit);
+			ports &= ~__BIT(bit);
 		}
 		AHCI_WRITE(sc, AHCI_IS, is);
 	}



CVS commit: src/sys/dev/ic

2021-01-29 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Sat Jan 30 07:53:01 UTC 2021

Modified Files:
src/sys/dev/ic: gem.c gemvar.h

Log Message:
Improve handling of receive overflows.  When we get an overflow, don't
reset the chip if we are still receiving packets.  Real overflows can
happen when network and CPU(s) are loaded, so the reset is not needed
in this case.
Add a counter to track receive overflows (when GEM_COUNTERS is defined).

This reverts some changes (always reset on overflow) from
PR port-sparc64/46260.


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/dev/ic/gem.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/ic/gemvar.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/ic/gem.c
diff -u src/sys/dev/ic/gem.c:1.132 src/sys/dev/ic/gem.c:1.133
--- src/sys/dev/ic/gem.c:1.132	Tue Sep 15 08:33:40 2020
+++ src/sys/dev/ic/gem.c	Sat Jan 30 07:53:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gem.c,v 1.132 2020/09/15 08:33:40 mrg Exp $ */
+/*	$NetBSD: gem.c,v 1.133 2021/01/30 07:53:01 jdc Exp $ */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.132 2020/09/15 08:33:40 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.133 2021/01/30 07:53:01 jdc Exp $");
 
 #include "opt_inet.h"
 
@@ -169,6 +169,7 @@ gem_detach(struct gem_softc *sc, int fla
 		evcnt_detach(>sc_ev_rxfull);
 		evcnt_detach(>sc_ev_rxint);
 		evcnt_detach(>sc_ev_txint);
+		evcnt_detach(>sc_ev_rxoverflow);
 #endif
 		evcnt_detach(>sc_ev_intr);
 
@@ -596,6 +597,8 @@ gem_attach(struct gem_softc *sc, const u
 	>sc_ev_rxint, device_xname(sc->sc_dev), "rx ring full");
 	evcnt_attach_dynamic(>sc_ev_rxnobuf, EVCNT_TYPE_INTR,
 	>sc_ev_rxint, device_xname(sc->sc_dev), "rx malloc failure");
+	evcnt_attach_dynamic(>sc_ev_rxoverflow, EVCNT_TYPE_INTR,
+	>sc_ev_rxint, device_xname(sc->sc_dev), "rx overflow");
 	evcnt_attach_dynamic(>sc_ev_rxhist[0], EVCNT_TYPE_INTR,
 	>sc_ev_rxint, device_xname(sc->sc_dev), "rx 0desc");
 	evcnt_attach_dynamic(>sc_ev_rxhist[1], EVCNT_TYPE_INTR,
@@ -1803,8 +1806,8 @@ gem_rint(struct gem_softc *sc)
 
 		if (rxstat & GEM_RD_BAD_CRC) {
 			if_statinc(ifp, if_ierrors);
-			aprint_error_dev(sc->sc_dev,
-			"receive error: CRC error\n");
+			DPRINTF(sc, ("%s: receive error: CRC error\n",
+			device_xname(sc->sc_dev)));
 			GEM_INIT_RXDESC(sc, i);
 			continue;
 		}
@@ -2215,8 +2218,11 @@ gem_intr(void *v)
 		 */
 		if (rxstat & GEM_MAC_RX_OVERFLOW) {
 			if_statinc(ifp, if_ierrors);
+			GEM_COUNTER_INCR(sc, sc_ev_rxoverflow);
+#ifdef GEM_DEBUG
 			aprint_error_dev(sc->sc_dev,
 			"receive error: RX overflow sc->rxptr %d, complete %d\n", sc->sc_rxptr, bus_space_read_4(t, h, GEM_RX_COMPLETION));
+#endif
 			sc->sc_rx_fifo_wr_ptr =
 bus_space_read_4(t, h, GEM_RX_FIFO_WR_PTR);
 			sc->sc_rx_fifo_rd_ptr =
@@ -2282,25 +2288,33 @@ gem_rx_watchdog(void *arg)
 		"receiver stuck in overflow, resetting\n");
 		gem_init(ifp);
 	} else {
+		int needreset = 1;
 		if ((state & GEM_MAC_STATE_OVERFLOW) != GEM_MAC_STATE_OVERFLOW) {
-			aprint_error_dev(sc->sc_dev,
-"rx_watchdog: not in overflow state: 0x%x\n",
-state);
+			DPRINTF(sc,
+			("%s: rx_watchdog: not in overflow state: 0x%x\n",
+			device_xname(sc->sc_dev), state));
 		}
 		if (rx_fifo_wr_ptr != rx_fifo_rd_ptr) {
-			aprint_error_dev(sc->sc_dev,
-"rx_watchdog: wr & rd ptr different\n");
+			DPRINTF(sc,
+			("%s: rx_watchdog: wr & rd ptr different\n",
+			device_xname(sc->sc_dev), state));
+			needreset = 0;
 		}
 		if (sc->sc_rx_fifo_wr_ptr != rx_fifo_wr_ptr) {
-			aprint_error_dev(sc->sc_dev,
-"rx_watchdog: wr pointer != saved\n");
+			DPRINTF(sc, ("%s: rx_watchdog: wr pointer != saved\n",
+			device_xname(sc->sc_dev), state));
+			needreset = 0;
 		}
 		if (sc->sc_rx_fifo_rd_ptr != rx_fifo_rd_ptr) {
+			DPRINTF(sc, ("%s: rx_watchdog: rd pointer != saved\n",
+			device_xname(sc->sc_dev), state));
+			needreset = 0;
+		}
+		if (needreset) {
 			aprint_error_dev(sc->sc_dev,
-"rx_watchdog: rd pointer != saved\n");
+			"rx_watchdog: resetting anyway\n");
+			gem_init(ifp);
 		}
-		aprint_error_dev(sc->sc_dev, "resetting anyway\n");
-		gem_init(ifp);
 	}
 }
 

Index: src/sys/dev/ic/gemvar.h
diff -u src/sys/dev/ic/gemvar.h:1.27 src/sys/dev/ic/gemvar.h:1.28
--- src/sys/dev/ic/gemvar.h:1.27	Sun Mar  1 05:50:56 2020
+++ src/sys/dev/ic/gemvar.h	Sat Jan 30 07:53:01 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gemvar.h,v 1.27 2020/03/01 05:50:56 thorpej Exp $ */
+/*	$NetBSD: gemvar.h,v 1.28 2021/01/30 07:53:01 jdc Exp $ */
 
 /*
  *
@@ -219,6 +219,7 @@ struct gem_softc {
 #ifdef GEM_COUNTERS
 	struct evcnt sc_ev_txint;
 	struct evcnt sc_ev_rxint;
+	struct evcnt sc_ev_rxoverflow;
 	struct evcnt sc_ev_rxnobuf;
 	struct evcnt sc_ev_rxfull;
 	struct evcnt sc_ev_rxhist[9];



CVS commit: src/sys/dev/ic

2021-01-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan 11 16:48:35 UTC 2021

Modified Files:
src/sys/dev/ic: ahcisata_core.c siisata.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/ic/siisata.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.94 src/sys/dev/ic/ahcisata_core.c:1.95
--- src/sys/dev/ic/ahcisata_core.c:1.94	Tue Dec 29 08:00:48 2020
+++ src/sys/dev/ic/ahcisata_core.c	Mon Jan 11 16:48:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.94 2020/12/29 08:00:48 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.95 2021/01/11 16:48:35 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.94 2020/12/29 08:00:48 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.95 2021/01/11 16:48:35 skrll Exp $");
 
 #include 
 #include 
@@ -729,7 +729,7 @@ ahci_intr_port_common(struct ata_channel
 		 * commands active before we start processing.
 		 */
 
-		for (slot=0; slot < sc->sc_ncmds; slot++) {
+		for (slot = 0; slot < sc->sc_ncmds; slot++) {
 			if ((aslots & __BIT(slot)) != 0 &&
 			(sact & __BIT(slot)) == 0) {
 xfer = ata_queue_hwslot_to_xfer(chp, slot);

Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.45 src/sys/dev/ic/siisata.c:1.46
--- src/sys/dev/ic/siisata.c:1.45	Mon Jan 11 16:48:03 2021
+++ src/sys/dev/ic/siisata.c	Mon Jan 11 16:48:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.45 2021/01/11 16:48:03 skrll Exp $ */
+/* $NetBSD: siisata.c,v 1.46 2021/01/11 16:48:35 skrll Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.45 2021/01/11 16:48:03 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.46 2021/01/11 16:48:35 skrll Exp $");
 
 #include 
 #include 
@@ -604,7 +604,7 @@ process:
 		 */
 		uint32_t aslots = ata_queue_active(chp);
 
-		for (int slot=0; slot < SIISATA_MAX_SLOTS; slot++) {
+		for (int slot = 0; slot < SIISATA_MAX_SLOTS; slot++) {
 			if ((aslots & __BIT(slot)) != 0 &&
 			(pss & PR_PXSS(slot)) == 0) {
 xfer = ata_queue_hwslot_to_xfer(chp, slot);



CVS commit: src/sys/dev/ic

2021-01-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan 11 16:48:03 UTC 2021

Modified Files:
src/sys/dev/ic: siisata.c

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/ic/siisata.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/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.44 src/sys/dev/ic/siisata.c:1.45
--- src/sys/dev/ic/siisata.c:1.44	Fri Dec 25 12:33:03 2020
+++ src/sys/dev/ic/siisata.c	Mon Jan 11 16:48:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.44 2020/12/25 12:33:03 skrll Exp $ */
+/* $NetBSD: siisata.c,v 1.45 2021/01/11 16:48:03 skrll Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.44 2020/12/25 12:33:03 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.45 2021/01/11 16:48:03 skrll Exp $");
 
 #include 
 #include 
@@ -561,7 +561,7 @@ siisata_intr_port(struct siisata_channel
 			 * We don't expect the recovery to trigger error,
 			 * but handle this just in case.
 			 */
-			if (!ISSET(chp->ch_flags, ATACH_RECOVERING)) 
+			if (!ISSET(chp->ch_flags, ATACH_RECOVERING))
 recover = true;
 			else {
 aprint_error_dev(sc->sc_atac.atac_dev,
@@ -841,7 +841,7 @@ siisata_probe_drive(struct ata_channel *
 		}
 		if (timed_out) {
 			aprint_error_dev(sc->sc_atac.atac_dev,
-			"timed out waiting for PORT_READY on port %d, " 
+			"timed out waiting for PORT_READY on port %d, "
 			"reinitializing\n", chp->ch_channel);
 			if (siisata_reinit_port(chp, -1))
 siisata_reset_channel(chp, AT_WAIT);



CVS commit: src/sys/dev/ic

2021-01-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jan  4 18:27:00 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c tpmreg.h tpmvar.h

Log Message:
dev/ic/tpm: Take advantage of entropy source if available.

If the tpm is deactivated, though, detach the entropy source so we
don't continue to try polling it -- it can't be activated without a
reboot anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/ic/tpm.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/tpmreg.h
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ic/tpmvar.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.18 src/sys/dev/ic/tpm.c:1.19
--- src/sys/dev/ic/tpm.c:1.18	Mon Jan  4 18:26:08 2021
+++ src/sys/dev/ic/tpm.c	Mon Jan  4 18:26:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.18 2021/01/04 18:26:08 riastradh Exp $	*/
+/*	$NetBSD: tpm.c,v 1.19 2021/01/04 18:26:59 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,11 +48,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.18 2021/01/04 18:26:08 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.19 2021/01/04 18:26:59 riastradh Exp $");
 
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -61,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.18
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -325,6 +327,179 @@ tpm_tis12_probe(bus_space_tag_t bt, bus_
 	return 0;
 }
 
+static void
+tpm_tis12_rng_work(struct work *wk, void *cookie)
+{
+	struct tpm_softc *sc = cookie;
+	/*
+	 * TPM Specification Version 1.2, Main Part 3: Commands,
+	 * Sec. 13.6 TPM_GetRandom
+	 */
+	struct {
+		struct tpm_header hdr;
+		uint32_t bytesRequested;
+	} __packed command;
+	struct response {
+		struct tpm_header hdr;
+		uint32_t randomBytesSize;
+		uint8_t	bytes[64];
+	} __packed response;
+	bool busy, endwrite = false, endread = false;
+	size_t nread;
+	uint16_t tag;
+	uint32_t pktlen, code, nbytes;
+	int rv;
+
+	/* Acknowledge the request.  */
+	sc->sc_rndpending = 0;
+
+	/* Lock userland out of the tpm, or fail if it's already open.  */
+	mutex_enter(>sc_lock);
+	busy = sc->sc_busy;
+	sc->sc_busy = true;
+	mutex_exit(>sc_lock);
+	if (busy) {		/* tough */
+		aprint_debug_dev(sc->sc_dev, "%s: device in use\n", __func__);
+		return;
+	}
+
+	/* Encode the command.  */
+	memset(, 0, sizeof(command));
+	command.hdr.tag = htobe16(TPM_TAG_RQU_COMMAND);
+	command.hdr.length = htobe32(sizeof(command));
+	command.hdr.code = htobe32(TPM_ORD_GetRandom);
+	command.bytesRequested = htobe32(sizeof(response.bytes));
+
+	/* Write the command.   */
+	if ((rv = (*sc->sc_intf->start)(sc, UIO_WRITE)) != 0) {
+		device_printf(sc->sc_dev, "start write failed, error=%d\n",
+		rv);
+		goto out;
+	}
+	endwrite = true;
+	if ((rv = (*sc->sc_intf->write)(sc, , sizeof(command))) != 0) {
+		device_printf(sc->sc_dev, "write failed, error=%d\n", rv);
+		goto out;
+	}
+	rv = (*sc->sc_intf->end)(sc, UIO_WRITE, 0);
+	endwrite = false;
+	if (rv) {
+		device_printf(sc->sc_dev, "end write failed, error=%d\n", rv);
+		goto out;
+	}
+
+	/* Read the response header.  */
+	if ((rv = (*sc->sc_intf->start)(sc, UIO_READ)) != 0) {
+		device_printf(sc->sc_dev, "start write failed, error=%d\n",
+		rv);
+		goto out;
+	}
+	endread = true;
+	if ((rv = (*sc->sc_intf->read)(sc, , sizeof(response.hdr),
+		, 0)) != 0) {
+		device_printf(sc->sc_dev, "read failed, error=%d\n", rv);
+		goto out;
+	}
+
+	/* Verify the response header looks sensible.  */
+	if (nread != sizeof(response.hdr)) {
+		device_printf(sc->sc_dev, "read %zu bytes, expected %zu",
+		nread, sizeof(response.hdr));
+		goto out;
+	}
+	tag = be16toh(response.hdr.tag);
+	pktlen = be32toh(response.hdr.length);
+	code = be32toh(response.hdr.code);
+	if (tag != TPM_TAG_RSP_COMMAND ||
+	pktlen < offsetof(struct response, bytes) ||
+	pktlen > sizeof(response) ||
+	code != 0) {
+		/*
+		 * If the tpm itself is busy (e.g., it has yet to run a
+		 * self-test, or it's in a timeout period to defend
+		 * against brute force attacks), then we can try again
+		 * later.  Otherwise, give up.
+		 */
+		if (code & TPM_NON_FATAL) {
+			aprint_debug_dev(sc->sc_dev, "%s: tpm busy, code=%u\n",
+			__func__, code & ~TPM_NON_FATAL);
+			rv = 0;
+		} else if (code == TPM_DEACTIVATED) {
+			device_printf(sc->sc_dev, "tpm is deactivated\n");
+			rv = ENXIO;
+		} else {
+			device_printf(sc->sc_dev, "bad tpm response:"
+			" tag=%u len=%u code=%u\n", tag, pktlen, code);
+			hexdump(aprint_debug, "tpm response header",
+			(const void *),
+			sizeof(response.hdr));
+			rv = EIO;
+		}
+		goto out;
+	}
+
+	/* Read the response payload.  */
+	if ((rv = (*sc->sc_intf->read)(sc,
+		(char *) + nread, pktlen - nread,
+		NULL, TPM_PARAM_SIZE)) != 0) {
+		device_printf(sc->sc_dev, "read failed, error=%d\n", rv);
+		goto out;
+	}
+	

CVS commit: src/sys/dev/ic

2021-01-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jan  4 18:26:08 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c

Log Message:
dev/ic/tpm: Add missing line break in attach output.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ic/tpm.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.17 src/sys/dev/ic/tpm.c:1.18
--- src/sys/dev/ic/tpm.c:1.17	Mon Jan  4 18:22:19 2021
+++ src/sys/dev/ic/tpm.c	Mon Jan  4 18:26:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $	*/
+/*	$NetBSD: tpm.c,v 1.18 2021/01/04 18:26:08 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.18 2021/01/04 18:26:08 riastradh Exp $");
 
 #include 
 #include 
@@ -330,6 +330,9 @@ tpm_tis12_init(struct tpm_softc *sc)
 {
 	int rv;
 
+	aprint_naive("\n");
+	aprint_normal("\n");
+
 	sc->sc_caps = bus_space_read_4(sc->sc_bt, sc->sc_bh,
 	TPM_INTF_CAPABILITY);
 	sc->sc_devid = bus_space_read_4(sc->sc_bt, sc->sc_bh, TPM_ID);



CVS commit: src/sys/dev/ic

2021-01-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jan  4 18:22:19 UTC 2021

Modified Files:
src/sys/dev/ic: tpm.c tpmreg.h tpmvar.h

Log Message:
dev/ic/tpm: Tidy up headers.

- Add include guards.
- Add necessary includes.
- Sort includes.
- Use _BYTE_ORDER, not BYTE_ORDER, for public header.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/tpm.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/tpmreg.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/tpmvar.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/ic/tpm.c
diff -u src/sys/dev/ic/tpm.c:1.16 src/sys/dev/ic/tpm.c:1.17
--- src/sys/dev/ic/tpm.c:1.16	Wed Oct  9 14:03:58 2019
+++ src/sys/dev/ic/tpm.c	Mon Jan  4 18:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpm.c,v 1.16 2019/10/09 14:03:58 maxv Exp $	*/
+/*	$NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -48,17 +48,19 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.16 2019/10/09 14:03:58 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm.c,v 1.17 2021/01/04 18:22:19 riastradh Exp $");
 
 #include 
-#include 
+#include 
+
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
-#include 
-#include 
-#include 
 #include 
+#include 
+#include 
 
 #include 
 #include 

Index: src/sys/dev/ic/tpmreg.h
diff -u src/sys/dev/ic/tpmreg.h:1.6 src/sys/dev/ic/tpmreg.h:1.7
--- src/sys/dev/ic/tpmreg.h:1.6	Wed Oct  9 07:30:58 2019
+++ src/sys/dev/ic/tpmreg.h	Mon Jan  4 18:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpmreg.h,v 1.6 2019/10/09 07:30:58 maxv Exp $	*/
+/*	$NetBSD: tpmreg.h,v 1.7 2021/01/04 18:22:19 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,7 +29,15 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if (BYTE_ORDER == LITTLE_ENDIAN)
+#ifndef	DEV_IC_TPMREG_H
+#define	DEV_IC_TPMREG_H
+
+#include 
+
+#include 
+#include 
+
+#if (_BYTE_ORDER == _LITTLE_ENDIAN)
 #define TPM_BE16(a)	bswap16(a)
 #define TPM_BE32(a)	bswap32(a)
 #else
@@ -105,3 +113,5 @@ struct tpm_header {
  * Five localities, 4K per locality.
  */
 #define	TPM_SPACE_SIZE	0x5000
+
+#endif	/* DEV_IC_TPMREG_H */

Index: src/sys/dev/ic/tpmvar.h
diff -u src/sys/dev/ic/tpmvar.h:1.7 src/sys/dev/ic/tpmvar.h:1.8
--- src/sys/dev/ic/tpmvar.h:1.7	Wed Oct  9 14:03:58 2019
+++ src/sys/dev/ic/tpmvar.h	Mon Jan  4 18:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tpmvar.h,v 1.7 2019/10/09 14:03:58 maxv Exp $	*/
+/*	$NetBSD: tpmvar.h,v 1.8 2021/01/04 18:22:19 riastradh Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -29,6 +29,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#ifndef	DEV_IC_TPMVAR_H
+#define	DEV_IC_TPMVAR_H
+
+#include 
+
 #define TPM_API_VERSION		1
 
 enum tpm_version {
@@ -54,6 +59,10 @@ struct tpm_ioc_getinfo {
 
 #ifdef _KERNEL
 
+#include 
+#include 
+#include 
+
 struct tpm_softc;
 
 struct tpm_intf {
@@ -88,3 +97,5 @@ bool tpm_suspend(device_t, const pmf_qua
 bool tpm_resume(device_t, const pmf_qual_t *);
 
 #endif
+
+#endif	/* DEV_IC_TPMVAR_H */



CVS commit: src/sys/dev/ic

2021-01-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Jan  4 15:14:32 UTC 2021

Modified Files:
src/sys/dev/ic: wdc.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/dev/ic/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/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.305 src/sys/dev/ic/wdc.c:1.306
--- src/sys/dev/ic/wdc.c:1.305	Mon Jan  4 15:13:50 2021
+++ src/sys/dev/ic/wdc.c	Mon Jan  4 15:14:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.305 2021/01/04 15:13:50 skrll Exp $ */
+/*	$NetBSD: wdc.c,v 1.306 2021/01/04 15:14:32 skrll Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.305 2021/01/04 15:13:50 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.306 2021/01/04 15:14:32 skrll Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -372,7 +372,7 @@ wdc_drvprobe(struct ata_channel *chp)
 		 * Init error counter so that an error within the first xfers
 		 * will trigger a downgrade
 		 */
-		chp->ch_drive[i].n_dmaerrs = NERRS_MAX-1;
+		chp->ch_drive[i].n_dmaerrs = NERRS_MAX - 1;
 #endif
 
 		/* If controller can't do 16bit flag the drives as 32bit */



CVS commit: src/sys/dev/ic

2020-12-31 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Dec 31 15:09:12 UTC 2020

Modified Files:
src/sys/dev/ic: dwc_gmac.c

Log Message:
extend the timeout value. dwc_gmac_reset() sometimes takes more time.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/ic/dwc_gmac.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/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.71 src/sys/dev/ic/dwc_gmac.c:1.72
--- src/sys/dev/ic/dwc_gmac.c:1.71	Sat Jun 27 13:34:20 2020
+++ src/sys/dev/ic/dwc_gmac.c	Thu Dec 31 15:09:12 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.71 2020/06/27 13:34:20 jmcneill Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.72 2020/12/31 15:09:12 ryo Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.71 2020/06/27 13:34:20 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.72 2020/12/31 15:09:12 ryo Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -379,7 +379,7 @@ dwc_gmac_reset(struct dwc_gmac_softc *sc
 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_DMA_BUSMODE,
 	bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_DMA_BUSMODE)
 	| GMAC_BUSMODE_RESET);
-	for (cnt = 0; cnt < 3000; cnt++) {
+	for (cnt = 0; cnt < 3; cnt++) {
 		if ((bus_space_read_4(sc->sc_bst, sc->sc_bsh, AWIN_GMAC_DMA_BUSMODE)
 		& GMAC_BUSMODE_RESET) == 0)
 			return 0;



CVS commit: src/sys/dev/ic

2020-12-29 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Dec 29 08:00:48 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Some more whitespace consistency / KNF


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.93 src/sys/dev/ic/ahcisata_core.c:1.94
--- src/sys/dev/ic/ahcisata_core.c:1.93	Tue Dec 29 07:56:22 2020
+++ src/sys/dev/ic/ahcisata_core.c	Tue Dec 29 08:00:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.93 2020/12/29 07:56:22 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.94 2020/12/29 08:00:48 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.93 2020/12/29 07:56:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.94 2020/12/29 08:00:48 skrll Exp $");
 
 #include 
 #include 
@@ -702,7 +702,6 @@ ahci_intr_port_common(struct ata_channel
 
 			AHCIDEBUG_PRINT(("%s port %d: transfer aborted 0x%x\n",
 			AHCINAME(sc), chp->ch_channel, tfd), DEBUG_INTR);
-
 		}
 	} else {
 		tfd = 0;
@@ -1170,7 +1169,7 @@ ahci_cmd_start(struct ata_channel *chp, 
 
 	cmd_tbl = achp->ahcic_cmd_tbl[slot];
 	AHCIDEBUG_PRINT(("%s port %d tbl %p\n", AHCINAME(sc), chp->ch_channel,
-	  cmd_tbl), DEBUG_XFERS);
+	cmd_tbl), DEBUG_XFERS);
 
 	satafis_rhd_construct_cmd(ata_c, cmd_tbl->cmdt_cfis);
 	cmd_tbl->cmdt_cfis[rhd_c] |= xfer->c_drive;
@@ -1763,7 +1762,7 @@ ahci_dma_setup(struct ata_channel *chp, 
 	bus_dmamap_sync(sc->sc_dmat, achp->ahcic_datad[slot], 0,
 	achp->ahcic_datad[slot]->dm_mapsize,
 	(op == BUS_DMA_READ) ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
-	for (seg = 0; seg <  achp->ahcic_datad[slot]->dm_nsegs; seg++) {
+	for (seg = 0; seg < achp->ahcic_datad[slot]->dm_nsegs; seg++) {
 		cmd_tbl->cmdt_prd[seg].prd_dba = htole64(
 		 achp->ahcic_datad[slot]->dm_segs[seg].ds_addr);
 		cmd_tbl->cmdt_prd[seg].prd_dbc = htole32(



CVS commit: src/sys/dev/ic

2020-12-28 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Dec 29 07:56:22 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Function declaration formating whitespace consistency.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.92 src/sys/dev/ic/ahcisata_core.c:1.93
--- src/sys/dev/ic/ahcisata_core.c:1.92	Mon Dec 28 14:08:42 2020
+++ src/sys/dev/ic/ahcisata_core.c	Tue Dec 29 07:56:22 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.92 2020/12/28 14:08:42 jmcneill Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.93 2020/12/29 07:56:22 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.92 2020/12/28 14:08:42 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.93 2020/12/29 07:56:22 skrll Exp $");
 
 #include 
 #include 
@@ -62,19 +62,19 @@ static int  ahci_do_reset_drive(struct a
 	uint8_t);
 static void ahci_reset_drive(struct ata_drive_datas *, int, uint32_t *);
 static void ahci_reset_channel(struct ata_channel *, int);
-static void  ahci_exec_command(struct ata_drive_datas *, struct ata_xfer *);
+static void ahci_exec_command(struct ata_drive_datas *, struct ata_xfer *);
 static int  ahci_ata_addref(struct ata_drive_datas *);
 static void ahci_ata_delref(struct ata_drive_datas *);
 static void ahci_killpending(struct ata_drive_datas *);
 
-static int ahci_cmd_start(struct ata_channel *, struct ata_xfer *);
+static int  ahci_cmd_start(struct ata_channel *, struct ata_xfer *);
 static int  ahci_cmd_complete(struct ata_channel *, struct ata_xfer *, int);
 static void ahci_cmd_poll(struct ata_channel *, struct ata_xfer *);
 static void ahci_cmd_abort(struct ata_channel *, struct ata_xfer *);
 static void ahci_cmd_done(struct ata_channel *, struct ata_xfer *);
 static void ahci_cmd_done_end(struct ata_channel *, struct ata_xfer *);
 static void ahci_cmd_kill_xfer(struct ata_channel *, struct ata_xfer *, int);
-static int ahci_bio_start(struct ata_channel *, struct ata_xfer *);
+static int  ahci_bio_start(struct ata_channel *, struct ata_xfer *);
 static void ahci_bio_poll(struct ata_channel *, struct ata_xfer *);
 static void ahci_bio_abort(struct ata_channel *, struct ata_xfer *);
 static int  ahci_bio_complete(struct ata_channel *, struct ata_xfer *, int);
@@ -84,7 +84,7 @@ static void ahci_channel_start(struct ah
 int, int);
 static void ahci_channel_recover(struct ata_channel *, int, uint32_t);
 static int  ahci_dma_setup(struct ata_channel *, int, void *, size_t, int);
-static int ahci_intr_port_common(struct ata_channel *);
+static int  ahci_intr_port_common(struct ata_channel *);
 
 #if NATAPIBUS > 0
 static void ahci_atapibus_attach(struct atabus_softc *);
@@ -92,7 +92,7 @@ static void ahci_atapi_kill_pending(stru
 static void ahci_atapi_minphys(struct buf *);
 static void ahci_atapi_scsipi_request(struct scsipi_channel *,
 scsipi_adapter_req_t, void *);
-static int ahci_atapi_start(struct ata_channel *, struct ata_xfer *);
+static int  ahci_atapi_start(struct ata_channel *, struct ata_xfer *);
 static void ahci_atapi_poll(struct ata_channel *, struct ata_xfer *);
 static void ahci_atapi_abort(struct ata_channel *, struct ata_xfer *);
 static int  ahci_atapi_complete(struct ata_channel *, struct ata_xfer *, int);



CVS commit: src/sys/dev/ic

2020-12-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec 28 11:05:54 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Make sure to ack IS after PxIS when polling and when using multiple MSI-X
messages.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.90 src/sys/dev/ic/ahcisata_core.c:1.91
--- src/sys/dev/ic/ahcisata_core.c:1.90	Sun Dec 27 15:13:07 2020
+++ src/sys/dev/ic/ahcisata_core.c	Mon Dec 28 11:05:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.90 2020/12/27 15:13:07 jmcneill Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.91 2020/12/28 11:05:54 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.90 2020/12/27 15:13:07 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.91 2020/12/28 11:05:54 jmcneill Exp $");
 
 #include 
 #include 
@@ -84,6 +84,7 @@ static void ahci_channel_start(struct ah
 int, int);
 static void ahci_channel_recover(struct ata_channel *, int, uint32_t);
 static int  ahci_dma_setup(struct ata_channel *, int, void *, size_t, int);
+static int ahci_intr_port_common(struct ata_channel *);
 
 #if NATAPIBUS > 0
 static void ahci_atapibus_attach(struct atabus_softc *);
@@ -602,7 +603,7 @@ ahci_intr(void *v)
 		ports = is;
 		while ((bit = ffs(ports)) != 0) {
 			bit--;
-			ahci_intr_port(>sc_channels[bit]);
+			ahci_intr_port_common(>sc_channels[bit].ata_channel);
 			ports &= ~(1U << bit);
 		}
 		AHCI_WRITE(sc, AHCI_IS, is);
@@ -617,6 +618,20 @@ ahci_intr_port(void *v)
 	struct ahci_channel *achp = v;
 	struct ata_channel *chp = >ata_channel;
 	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
+	int ret;
+
+	ret = ahci_intr_port_common(chp);
+	if (ret) {
+		AHCI_WRITE(sc, AHCI_IS, 1U << chp->ch_channel);
+	}
+
+	return ret;
+}
+
+static int
+ahci_intr_port_common(struct ata_channel *chp)
+{
+	struct ahci_softc *sc = (struct ahci_softc *)chp->ch_atac;
 	uint32_t is, tfd, sact;
 	struct ata_xfer *xfer;
 	int slot = -1;
@@ -626,8 +641,8 @@ ahci_intr_port(void *v)
 	is = AHCI_READ(sc, AHCI_P_IS(chp->ch_channel));
 	AHCI_WRITE(sc, AHCI_P_IS(chp->ch_channel), is);
 
-	AHCIDEBUG_PRINT((
-	"ahci_intr_port %s port %d is 0x%x CI 0x%x SACT 0x%x TFD 0x%x\n",
+	AHCIDEBUG_PRINT(("ahci_intr_port_common %s port %d "
+	"is 0x%x CI 0x%x SACT 0x%x TFD 0x%x\n",
 	AHCINAME(sc),
 	chp->ch_channel, is,
 	AHCI_READ(sc, AHCI_P_CI(chp->ch_channel)),



CVS commit: src/sys/dev/ic

2020-12-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 27 16:52:01 UTC 2020

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
Zero DMA memory after load, and add PREREAD sync op after to ensure it is 
visible


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.53 src/sys/dev/ic/nvme.c:1.54
--- src/sys/dev/ic/nvme.c:1.53	Fri Dec  4 23:03:11 2020
+++ src/sys/dev/ic/nvme.c	Sun Dec 27 16:52:01 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.53 2020/12/04 23:03:11 kardel Exp $	*/
+/*	$NetBSD: nvme.c,v 1.54 2020/12/27 16:52:01 jmcneill Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.53 2020/12/04 23:03:11 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.54 2020/12/27 16:52:01 jmcneill Exp $");
 
 #include 
 #include 
@@ -1925,12 +1925,14 @@ nvme_dmamem_alloc(struct nvme_softc *sc,
 	if (bus_dmamem_map(sc->sc_dmat, >ndm_seg, nsegs, size,
 	>ndm_kva, BUS_DMA_WAITOK) != 0)
 		goto free;
-	memset(ndm->ndm_kva, 0, size);
 
 	if (bus_dmamap_load(sc->sc_dmat, ndm->ndm_map, ndm->ndm_kva, size,
 	NULL, BUS_DMA_WAITOK) != 0)
 		goto unmap;
 
+	memset(ndm->ndm_kva, 0, size);
+	bus_dmamap_sync(sc->sc_dmat, ndm->ndm_map, 0, size, BUS_DMASYNC_PREREAD);
+
 	return ndm;
 
 unmap:



CVS commit: src/sys/dev/ic

2020-12-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 27 15:13:07 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
AHCI 1.3.1 section 5.5.3 "Processing Completed Commands" says that we
should clear PxIS before IS.IPS.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.89 src/sys/dev/ic/ahcisata_core.c:1.90
--- src/sys/dev/ic/ahcisata_core.c:1.89	Sat Dec 26 15:40:29 2020
+++ src/sys/dev/ic/ahcisata_core.c	Sun Dec 27 15:13:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.89 2020/12/26 15:40:29 jmcneill Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.90 2020/12/27 15:13:07 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.89 2020/12/26 15:40:29 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.90 2020/12/27 15:13:07 jmcneill Exp $");
 
 #include 
 #include 
@@ -599,13 +599,13 @@ ahci_intr(void *v)
 		AHCIDEBUG_PRINT(("%s ahci_intr 0x%x\n", AHCINAME(sc), is),
 		DEBUG_INTR);
 		r = 1;
-		AHCI_WRITE(sc, AHCI_IS, is);
 		ports = is;
 		while ((bit = ffs(ports)) != 0) {
 			bit--;
 			ahci_intr_port(>sc_channels[bit]);
 			ports &= ~(1U << bit);
 		}
+		AHCI_WRITE(sc, AHCI_IS, is);
 	}
 
 	return r;



CVS commit: src/sys/dev/ic

2020-12-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Dec 26 15:40:29 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
ahci_intr: use ffs in the port bitmask instead of looping over all 32 bits


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.88 src/sys/dev/ic/ahcisata_core.c:1.89
--- src/sys/dev/ic/ahcisata_core.c:1.88	Sat Dec 26 10:56:25 2020
+++ src/sys/dev/ic/ahcisata_core.c	Sat Dec 26 15:40:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.88 2020/12/26 10:56:25 jmcneill Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.89 2020/12/26 15:40:29 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.88 2020/12/26 10:56:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.89 2020/12/26 15:40:29 jmcneill Exp $");
 
 #include 
 #include 
@@ -592,17 +592,20 @@ int
 ahci_intr(void *v)
 {
 	struct ahci_softc *sc = v;
-	uint32_t is;
-	int i, r = 0;
+	uint32_t is, ports;
+	int bit, r = 0;
 
 	while ((is = AHCI_READ(sc, AHCI_IS))) {
 		AHCIDEBUG_PRINT(("%s ahci_intr 0x%x\n", AHCINAME(sc), is),
 		DEBUG_INTR);
 		r = 1;
 		AHCI_WRITE(sc, AHCI_IS, is);
-		for (i = 0; i < AHCI_MAX_PORTS; i++)
-			if (is & (1U << i))
-ahci_intr_port(>sc_channels[i]);
+		ports = is;
+		while ((bit = ffs(ports)) != 0) {
+			bit--;
+			ahci_intr_port(>sc_channels[bit]);
+			ports &= ~(1U << bit);
+		}
 	}
 
 	return r;



CVS commit: src/sys/dev/ic

2020-12-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Dec 26 10:56:25 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
AHCI 1.3.1 specification says that it is good practice for system software
to 'zero-out' the memory allocated and referenced by PxCLB and PxFB.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.87 src/sys/dev/ic/ahcisata_core.c:1.88
--- src/sys/dev/ic/ahcisata_core.c:1.87	Fri Dec 25 08:57:38 2020
+++ src/sys/dev/ic/ahcisata_core.c	Sat Dec 26 10:56:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.87 2020/12/25 08:57:38 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.88 2020/12/26 10:56:25 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.87 2020/12/25 08:57:38 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.88 2020/12/26 10:56:25 jmcneill Exp $");
 
 #include 
 #include 
@@ -363,6 +363,9 @@ ahci_attach(struct ahci_softc *sc)
 		return;
 	}
 	sc->sc_cmd_hdr = cmdhp;
+	memset(cmdhp, 0, dmasize);
+	bus_dmamap_sync(sc->sc_dmat, sc->sc_cmd_hdrd, 0, dmasize,
+	BUS_DMASYNC_PREWRITE);
 
 	ahci_enable_intrs(sc);
 
@@ -429,6 +432,9 @@ ahci_attach(struct ahci_softc *sc)
 			", error=%d\n", AHCINAME(sc), error);
 			break;
 		}
+		memset(cmdtblp, 0, dmasize);
+		bus_dmamap_sync(sc->sc_dmat, achp->ahcic_cmd_tbld, 0,
+		dmasize, BUS_DMASYNC_PREWRITE);
 		achp->ahcic_cmdh  = (struct ahci_cmd_header *)
 		((char *)cmdhp + AHCI_CMDH_SIZE * port);
 		achp->ahcic_bus_cmdh = sc->sc_cmd_hdrd->dm_segs[0].ds_addr +



CVS commit: src/sys/dev/ic

2020-12-26 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Sat Dec 26 08:58:03 UTC 2020

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
Ignore WSDISPLAYIO_PUTCMAP in WSDISPLAYIO_MODE_EMUL, i.e. text mode.

The hardware palette settings are handled by the STI ROM in STI_TEXTMODE
and changing cmap could cause mangled text colors at least on CRX on 425t.
Updating CMAP in EMUL mode isn't expected anyway.

Fixes "red or invisible text" after exiting mlterm-wscons on A1659 CRX.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.24 src/sys/dev/ic/sti.c:1.25
--- src/sys/dev/ic/sti.c:1.24	Fri Dec 25 20:41:24 2020
+++ src/sys/dev/ic/sti.c	Sat Dec 26 08:58:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.24 2020/12/25 20:41:24 tsutsui Exp $	*/
+/*	$NetBSD: sti.c,v 1.25 2020/12/26 08:58:03 tsutsui Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.24 2020/12/25 20:41:24 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.25 2020/12/26 08:58:03 tsutsui Exp $");
 
 #include "wsdisplay.h"
 
@@ -1129,6 +1129,16 @@ sti_ioctl(void *v, void *vs, u_long cmd,
 	case WSDISPLAYIO_PUTCMAP:
 		if (scr->putcmap == NULL || scr->scr_bpp > 8)
 			return ENODEV;
+		if (scr->scr_wsmode == WSDISPLAYIO_MODE_EMUL) {
+			/*
+			 * The hardware palette settings are handled by
+			 * the STI ROM in STI_TEXTMODE and changing cmap
+			 * could cause mangled text colors at least on CRX.
+			 * Updating CMAP in EMUL mode isn't expected anyway
+			 * so just ignore it.
+			 */
+			return 0;
+		}
 		cmapp = (struct wsdisplay_cmap *)data;
 		idx = cmapp->index;
 		count = cmapp->count;



CVS commit: src/sys/dev/ic

2020-12-25 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Fri Dec 25 20:41:24 UTC 2020

Modified Files:
src/sys/dev/ic: sti.c

Log Message:
Handle WSSCREEN_REVERSE properly.  Based on OpenBSD's sti(4).

Also remove WSSCREEN_UNDERLINE from capabilities that is not handled
by sti(4) ROM routines.

Tested on HP9000/425t with CRX.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ic/sti.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.23 src/sys/dev/ic/sti.c:1.24
--- src/sys/dev/ic/sti.c:1.23	Wed Dec 23 08:34:35 2020
+++ src/sys/dev/ic/sti.c	Fri Dec 25 20:41:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.23 2020/12/23 08:34:35 tsutsui Exp $	*/
+/*	$NetBSD: sti.c,v 1.24 2020/12/25 20:41:24 tsutsui Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.23 2020/12/23 08:34:35 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.24 2020/12/25 20:41:24 tsutsui Exp $");
 
 #include "wsdisplay.h"
 
@@ -79,6 +79,18 @@ void sti_copyrows(void *, int, int, int)
 void sti_eraserows(void *, int, int, long);
 int  sti_alloc_attr(void *, int, int, int, long *);
 
+/* pseudo attribute ops for sti ROM putchar function */
+#define WSATTR_FG_SHIFT	24
+#define WSATTR_BG_SHIFT	16
+#define WSATTR_UNPACK_FG(attr)	(((attr) >> WSATTR_FG_SHIFT) & 0xff)
+#define WSATTR_UNPACK_BG(attr)	(((attr) >> WSATTR_BG_SHIFT) & 0xff)
+#define WSATTR_UNPACK_FLAG(attr) ((attr) & WSATTR_USERMASK)
+#define WSATTR_PACK_FG(fg)	((fg) << WSATTR_FG_SHIFT)
+#define WSATTR_PACK_BG(bg)	((bg) << WSATTR_BG_SHIFT)
+#define WSATTR_PACK_FLAG(flag)	((flag))
+#define WSATTR_PACK(fg, bg, flag)	\
+(WSATTR_PACK_FG(fg) | WSATTR_PACK_BG(bg) | WSATTR_PACK_FLAG(flag))
+
 struct wsdisplay_emulops sti_emulops = {
 	.cursor = sti_cursor,
 	.mapchar = sti_mapchar,
@@ -618,7 +630,7 @@ sti_screen_setup(struct sti_screen *scr,
 	scr->scr_wsd.textops = _emulops;
 	scr->scr_wsd.fontwidth = scr->scr_curfont.width;
 	scr->scr_wsd.fontheight = scr->scr_curfont.height;
-	scr->scr_wsd.capabilities = WSSCREEN_REVERSE | WSSCREEN_UNDERLINE;
+	scr->scr_wsd.capabilities = WSSCREEN_REVERSE;
 
 	scr->scr_scrlist[0] = >scr_wsd;
 	scr->scr_screenlist.nscreens = 1;
@@ -1293,6 +1305,10 @@ sti_putchar(void *v, int row, int col, u
 	struct sti_screen *scr = (struct sti_screen *)v;
 	struct sti_rom *rom = scr->scr_rom;
 	struct sti_font *fp = >scr_curfont;
+	int bg, fg;
+
+	fg = WSATTR_UNPACK_FG(attr);
+	bg = WSATTR_UNPACK_BG(attr);
 
 	if (scr->scr_romfont != NULL) {
 		/*
@@ -1307,9 +1323,8 @@ sti_putchar(void *v, int row, int col, u
 		memset(, 0, sizeof(a));
 
 		a.flags.flags = STI_UNPMVF_WAIT;
-		/* XXX does not handle text attributes */
-		a.in.fg_colour = STI_COLOUR_WHITE;
-		a.in.bg_colour = STI_COLOUR_BLACK;
+		a.in.fg_colour = fg;
+		a.in.bg_colour = bg;
 		a.in.x = col * fp->width;
 		a.in.y = row * fp->height;
 		a.in.font_addr = scr->scr_romfont;
@@ -1329,9 +1344,8 @@ sti_putchar(void *v, int row, int col, u
 		memset(, 0, sizeof(a));
 
 		a.flags.flags = STI_BLKMVF_WAIT;
-		/* XXX does not handle text attributes */
-		a.in.fg_colour = STI_COLOUR_WHITE;
-		a.in.bg_colour = STI_COLOUR_BLACK;
+		a.in.fg_colour = fg;
+		a.in.bg_colour = bg;
 
 		a.in.srcx = ((uc - fp->first) / scr->scr_fontmaxcol) *
 		fp->width + scr->scr_fontbase;
@@ -1397,8 +1411,18 @@ sti_alloc_attr(void *v, int fg, int bg, 
 	struct sti_screen *scr = (struct sti_screen *)v;
 #endif
 
-	*pattr = 0;
+	if ((flags & (WSATTR_HILIT | WSATTR_BLINK |
+	WSATTR_UNDERLINE | WSATTR_WSCOLORS)) != 0)
+		return EINVAL;
+	if ((flags & WSATTR_REVERSE) != 0) {
+		fg = STI_COLOUR_BLACK; 
+		bg = STI_COLOUR_WHITE;
+	} else {
+		fg = STI_COLOUR_WHITE;
+		bg = STI_COLOUR_BLACK; 
+	}
 
+	*pattr = WSATTR_PACK(fg, bg, flags);
 	return 0;
 }
 



CVS commit: src/sys/dev/ic

2020-12-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec 25 12:33:03 UTC 2020

Modified Files:
src/sys/dev/ic: mvsata.c siisata.c

Log Message:
Use designated initializers for struct ata_bustype


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/ic/mvsata.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/ic/siisata.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/ic/mvsata.c
diff -u src/sys/dev/ic/mvsata.c:1.57 src/sys/dev/ic/mvsata.c:1.58
--- src/sys/dev/ic/mvsata.c:1.57	Tue May 19 08:08:51 2020
+++ src/sys/dev/ic/mvsata.c	Fri Dec 25 12:33:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mvsata.c,v 1.57 2020/05/19 08:08:51 jdolecek Exp $	*/
+/*	$NetBSD: mvsata.c,v 1.58 2020/12/25 12:33:03 skrll Exp $	*/
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
  * All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.57 2020/05/19 08:08:51 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mvsata.c,v 1.58 2020/12/25 12:33:03 skrll Exp $");
 
 #include "opt_mvsata.h"
 
@@ -221,16 +221,16 @@ static void mvsata_print_eprd(struct mvs
 #endif
 
 static const struct ata_bustype mvsata_ata_bustype = {
-	SCSIPI_BUSTYPE_ATA,
-	mvsata_bio,
-	mvsata_reset_drive,
-	mvsata_reset_channel,
-	mvsata_exec_command,
-	ata_get_params,
-	mvsata_addref,
-	mvsata_delref,
-	mvsata_killpending,
-	mvsata_channel_recover,
+	.bustype_type = SCSIPI_BUSTYPE_ATA,
+	.ata_bio = mvsata_bio,
+	.ata_reset_drive = mvsata_reset_drive,
+	.ata_reset_channel = mvsata_reset_channel,
+	.ata_exec_command = mvsata_exec_command,
+	.ata_get_params = ata_get_params,
+	.ata_addref = mvsata_addref,
+	.ata_delref = mvsata_delref,
+	.ata_killpending = mvsata_killpending,
+	.ata_recovery = mvsata_channel_recover,
 };
 
 #if NATAPIBUS > 0

Index: src/sys/dev/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.43 src/sys/dev/ic/siisata.c:1.44
--- src/sys/dev/ic/siisata.c:1.43	Sat Oct 10 20:27:54 2020
+++ src/sys/dev/ic/siisata.c	Fri Dec 25 12:33:03 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.43 2020/10/10 20:27:54 thorpej Exp $ */
+/* $NetBSD: siisata.c,v 1.44 2020/12/25 12:33:03 skrll Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.43 2020/10/10 20:27:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.44 2020/12/25 12:33:03 skrll Exp $");
 
 #include 
 #include 
@@ -184,16 +184,16 @@ void siisata_atapi_kill_pending(struct s
 #endif /* NATAPIBUS */
 
 const struct ata_bustype siisata_ata_bustype = {
-	SCSIPI_BUSTYPE_ATA,
-	siisata_ata_bio,
-	siisata_reset_drive,
-	siisata_reset_channel,
-	siisata_exec_command,
-	ata_get_params,
-	siisata_ata_addref,
-	siisata_ata_delref,
-	siisata_killpending,
-	siisata_channel_recover,
+	.bustype_type = SCSIPI_BUSTYPE_ATA,
+	.ata_bio = siisata_ata_bio,
+	.ata_reset_drive = siisata_reset_drive,
+	.ata_reset_channel = siisata_reset_channel,
+	.ata_exec_command = siisata_exec_command,
+	.ata_get_params = ata_get_params,
+	.ata_addref = siisata_ata_addref,
+	.ata_delref = siisata_ata_delref,
+	.ata_killpending = siisata_killpending,
+	.ata_recovery = siisata_channel_recover,
 };
 
 #if NATAPIBUS > 0



CVS commit: src/sys/dev/ic

2020-12-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec 25 08:57:38 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c ahcisatavar.h

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/ic/ahcisata_core.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/ic/ahcisatavar.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.86 src/sys/dev/ic/ahcisata_core.c:1.87
--- src/sys/dev/ic/ahcisata_core.c:1.86	Fri Dec 25 08:55:40 2020
+++ src/sys/dev/ic/ahcisata_core.c	Fri Dec 25 08:57:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.86 2020/12/25 08:55:40 skrll Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.87 2020/12/25 08:57:38 skrll Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.86 2020/12/25 08:55:40 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.87 2020/12/25 08:57:38 skrll Exp $");
 
 #include 
 #include 
@@ -176,7 +176,7 @@ static void
 ahci_setup_ports(struct ahci_softc *sc)
 {
 	int i, port;
-	
+
 	for (i = 0, port = 0; i < AHCI_MAX_PORTS; i++) {
 		if ((sc->sc_ahci_ports & (1U << i)) == 0)
 			continue;
@@ -254,7 +254,7 @@ ahci_attach(struct ahci_softc *sc)
 
 		sc->sc_init_data.cap = AHCI_READ(sc, AHCI_CAP);
 		sc->sc_init_data.ports = AHCI_READ(sc, AHCI_PI);
-		
+
 		ahci_rev = AHCI_READ(sc, AHCI_VS);
 		if (AHCI_VS_MJR(ahci_rev) > 1 ||
 		(AHCI_VS_MJR(ahci_rev) == 1 && AHCI_VS_MNR(ahci_rev) >= 20)) {
@@ -314,7 +314,7 @@ ahci_attach(struct ahci_softc *sc)
 	", %d port%s, %d slot%s, CAP %s\n",
 	AHCI_VS_MJR(ahci_rev), AHCI_VS_MNR(ahci_rev),
 	sc->sc_atac.atac_nchannels,
-	(sc->sc_atac.atac_nchannels == 1 ? "" : "s"), 
+	(sc->sc_atac.atac_nchannels == 1 ? "" : "s"),
 	sc->sc_ncmds, (sc->sc_ncmds == 1 ? "" : "s"), buf);
 
 	sc->sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DMA | ATAC_CAP_UDMA
@@ -434,18 +434,18 @@ ahci_attach(struct ahci_softc *sc)
 		achp->ahcic_bus_cmdh = sc->sc_cmd_hdrd->dm_segs[0].ds_addr +
 		AHCI_CMDH_SIZE * port;
 		achp->ahcic_rfis = (struct ahci_r_fis *)
-		((char *)cmdhp + 
-		 AHCI_CMDH_SIZE * sc->sc_atac.atac_nchannels + 
+		((char *)cmdhp +
+		 AHCI_CMDH_SIZE * sc->sc_atac.atac_nchannels +
 		 AHCI_RFIS_SIZE * port);
 		achp->ahcic_bus_rfis = sc->sc_cmd_hdrd->dm_segs[0].ds_addr +
-		 AHCI_CMDH_SIZE * sc->sc_atac.atac_nchannels + 
+		 AHCI_CMDH_SIZE * sc->sc_atac.atac_nchannels +
 		 AHCI_RFIS_SIZE * port;
 		AHCIDEBUG_PRINT(("port %d cmdh %p (0x%" PRIx64 ") "
  "rfis %p (0x%" PRIx64 ")\n", i,
 		   achp->ahcic_cmdh, (uint64_t)achp->ahcic_bus_cmdh,
 		   achp->ahcic_rfis, (uint64_t)achp->ahcic_bus_rfis),
 		   DEBUG_PROBE);
-		
+
 		for (j = 0; j < sc->sc_ncmds; j++) {
 			achp->ahcic_cmd_tbl[j] = (struct ahci_cmd_tbl *)
 			((char *)cmdtblp + AHCI_CMDTBL_SIZE * j);
@@ -718,7 +718,7 @@ ahci_intr_port(void *v)
 	if (__predict_false(recover)) {
 		ata_channel_lock(chp);
 		ata_channel_thaw_locked(chp);
-		ata_thread_run(chp, 0, ATACH_TH_RECOVERY, tfd); 
+		ata_thread_run(chp, 0, ATACH_TH_RECOVERY, tfd);
 		ata_channel_unlock(chp);
 	}
 
@@ -1198,7 +1198,7 @@ ahci_cmd_poll(struct ata_channel *chp, s
 	ata_channel_lock(chp);
 
 	/*
-	 * Polled command. 
+	 * Polled command.
 	 */
 	for (int i = 0; i < xfer->c_ata_c.timeout / 10; i++) {
 		if (xfer->c_ata_c.flags & AT_DONE)
@@ -1208,7 +1208,7 @@ ahci_cmd_poll(struct ata_channel *chp, s
 		ata_channel_lock(chp);
 		ata_delay(chp, 10, "ahcipl", xfer->c_ata_c.flags);
 	}
-	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), chp->ch_channel, 
+	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), chp->ch_channel,
 	AHCI_READ(sc, AHCI_GHC), AHCI_READ(sc, AHCI_IS),
 	AHCI_READ(sc, AHCI_P_CLBU(chp->ch_channel)),
 	AHCI_READ(sc, AHCI_P_CLB(chp->ch_channel)),
@@ -1444,7 +1444,7 @@ ahci_bio_poll(struct ata_channel *chp, s
 	struct ahci_channel *achp = (struct ahci_channel *)chp;
 
 	/*
-	 * Polled command. 
+	 * Polled command.
 	 */
 	for (int i = 0; i < ATA_DELAY * 10; i++) {
 		if (xfer->c_bio.flags & ATA_ITSDONE)
@@ -1452,7 +1452,7 @@ ahci_bio_poll(struct ata_channel *chp, s
 		ahci_intr_port(achp);
 		delay(100);
 	}
-	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), chp->ch_channel, 
+	AHCIDEBUG_PRINT(("%s port %d poll end GHC 0x%x IS 0x%x list 0x%x%x fis 0x%x%x CMD 0x%x CI 0x%x\n", AHCINAME(sc), chp->ch_channel,
 	AHCI_READ(sc, AHCI_GHC), AHCI_READ(sc, AHCI_IS),
 	AHCI_READ(sc, AHCI_P_CLBU(chp->ch_channel)),
 	AHCI_READ(sc, AHCI_P_CLB(chp->ch_channel)),
@@ -1536,7 +1536,7 @@ ahci_bio_complete(struct ata_channel *ch
 

CVS commit: src/sys/dev/ic

2020-12-23 Thread Izumi Tsutsui
Module Name:src
Committed By:   tsutsui
Date:   Wed Dec 23 08:34:35 UTC 2020

Modified Files:
src/sys/dev/ic: sti.c stivar.h

Log Message:
Pull the latest OpenBSD sti(4) changes for bitmap framebuffer support.

- bitmap and colormap ops based on old HP ngle X11 driver:
  http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/ic/sti.c#rev1.76
  > Work-in-progress support for non-accelerated X11 on *some* sti(4)
  > frame buffers; based upon the old HP ngle X11 driver.
  > Currently limited to CRX (720/735/750), Timber (710, old 715),
  > Artist (712, 715) and EG (B-series), however the
  > colormap isn't set up correctly on Timber and EG yet.
  >
  > Joint work with Artem Falcon, now in good enough shape to be worked further
  > in the tree.
- misc other cosmetic changes to reduce diffs

No particular comments on port-hp300@ and port-hppa@:
 https://mail-index.netbsd.org/port-hp300/2020/12/19/msg000184.html
 https://mail-index.netbsd.org/port-hp300/2020/12/20/msg000185.html

The MD hp300 attachment for SGC CRX (A1659-66001) will be committed
separately.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/ic/sti.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/ic/stivar.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/ic/sti.c
diff -u src/sys/dev/ic/sti.c:1.22 src/sys/dev/ic/sti.c:1.23
--- src/sys/dev/ic/sti.c:1.22	Sat Sep  5 16:30:11 2020
+++ src/sys/dev/ic/sti.c	Wed Dec 23 08:34:35 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sti.c,v 1.22 2020/09/05 16:30:11 riastradh Exp $	*/
+/*	$NetBSD: sti.c,v 1.23 2020/12/23 08:34:35 tsutsui Exp $	*/
 
 /*	$OpenBSD: sti.c,v 1.61 2009/09/05 14:09:35 miod Exp $	*/
 
@@ -31,11 +31,11 @@
  * TODO:
  *	call sti procs asynchronously;
  *	implement console scroll-back;
- *	X11 support.
+ *	X11 support on more models.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.22 2020/09/05 16:30:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sti.c,v 1.23 2020/12/23 08:34:35 tsutsui Exp $");
 
 #include "wsdisplay.h"
 
@@ -80,32 +80,32 @@ void sti_eraserows(void *, int, int, lon
 int  sti_alloc_attr(void *, int, int, int, long *);
 
 struct wsdisplay_emulops sti_emulops = {
-	sti_cursor,
-	sti_mapchar,
-	sti_putchar,
-	sti_copycols,
-	sti_erasecols,
-	sti_copyrows,
-	sti_eraserows,
-	sti_alloc_attr
+	.cursor = sti_cursor,
+	.mapchar = sti_mapchar,
+	.putchar = sti_putchar,
+	.copycols = sti_copycols,
+	.erasecols = sti_erasecols,
+	.copyrows = sti_copyrows,
+	.eraserows = sti_eraserows,
+	.allocattr = sti_alloc_attr
 };
 
 const struct wsdisplay_accessops sti_accessops = {
-	sti_ioctl,
-	sti_mmap,
-	sti_alloc_screen,
-	sti_free_screen,
-	sti_show_screen,
-	sti_load_font
+	.ioctl = sti_ioctl,
+	.mmap = sti_mmap,
+	.alloc_screen = sti_alloc_screen,
+	.free_screen = sti_free_screen,
+	.show_screen = sti_show_screen,
+	.load_font = sti_load_font
 };
 
 enum sti_bmove_funcs {
 	bmf_clear, bmf_copy, bmf_invert, bmf_underline
 };
 
-int	sti_inqcfg(struct sti_screen *, struct sti_inqconfout *);
 void	sti_bmove(struct sti_screen *, int, int, int, int, int, int,
 	enum sti_bmove_funcs);
+int	sti_inqcfg(struct sti_screen *, struct sti_inqconfout *);
 int	sti_setcment(struct sti_screen *, u_int, u_char, u_char, u_char);
 
 struct sti_screen *sti_attach_screen(struct sti_softc *, int);
@@ -118,6 +118,15 @@ int	sti_rom_setup(struct sti_rom *, bus_
 	bus_space_handle_t, bus_addr_t *, u_int);
 int	sti_screen_setup(struct sti_screen *, int);
 
+int	ngle_default_putcmap(struct sti_screen *, u_int, u_int);
+
+#ifndef SMALL_KERNEL
+void	ngle_artist_setupfb(struct sti_screen *);
+void	ngle_elk_setupfb(struct sti_screen *);
+void	ngle_timber_setupfb(struct sti_screen *);
+int	ngle_putcmap(struct sti_screen *, u_int, u_int);
+#endif
+
 #if NSTI_PCI > 0
 #define	STI_ENABLE_ROM(sc) \
 do { \
@@ -210,51 +219,52 @@ sti_rom_setup(struct sti_rom *rom, bus_s
 	/*
 	 * Get ROM header and code function pointers.
 	 */
+
 	dd = >rom_dd;
 	rom->rom_devtype = bus_space_read_1(memt, romh, 3);
 	if (rom->rom_devtype == STI_DEVTYPE1) {
-		dd->dd_type  = bus_space_read_1(memt, romh, 0x03);
-		dd->dd_nmon  = bus_space_read_1(memt, romh, 0x07);
-		dd->dd_grrev = bus_space_read_1(memt, romh, 0x0b);
-		dd->dd_lrrev = bus_space_read_1(memt, romh, 0x0f);
-		dd->dd_grid[0] = parseword(0x10);
-		dd->dd_grid[1] = parseword(0x20);
-		dd->dd_fntaddr = parseword(0x30) & ~3;
-		dd->dd_maxst   = parseword(0x40);
-		dd->dd_romend  = parseword(0x50) & ~3;
-		dd->dd_reglst  = parseword(0x60) & ~3;
-		dd->dd_maxreent= parseshort(0x70);
-		dd->dd_maxtimo = parseshort(0x78);
-		dd->dd_montbl  = parseword(0x80) & ~3;
-		dd->dd_udaddr  = parseword(0x90) & ~3;
-		dd->dd_stimemreq=parseword(0xa0);
-		dd->dd_udsize  = parseword(0xb0);
-		dd->dd_pwruse  = parseshort(0xc0);
-		dd->dd_bussup  = bus_space_read_1(memt, romh, 0xcb);
-		dd->dd_ebussup = bus_space_read_1(memt, romh, 0xcf);
-		dd->dd_altcodet= 

CVS commit: src/sys/dev/ic

2020-12-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 20 00:14:30 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
Retry clearing WDCTL_RST a few times before giving up. Makes SATA work in
Solidrun Honeycomb LX2K.


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.84 src/sys/dev/ic/ahcisata_core.c:1.85
--- src/sys/dev/ic/ahcisata_core.c:1.84	Sat Dec 19 19:12:02 2020
+++ src/sys/dev/ic/ahcisata_core.c	Sun Dec 20 00:14:30 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.84 2020/12/19 19:12:02 jmcneill Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.85 2020/12/20 00:14:30 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.84 2020/12/19 19:12:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.85 2020/12/20 00:14:30 jmcneill Exp $");
 
 #include 
 #include 
@@ -810,7 +810,7 @@ ahci_do_reset_drive(struct ata_channel *
 	struct ahci_cmd_header *cmd_h;
 	int i, error = 0;
 	uint32_t sig, cmd;
-	int noclo_retry = 0;
+	int noclo_retry = 0, retry;
 
 	ata_channel_lock_owned(chp);
 
@@ -892,22 +892,34 @@ again:
 	 */
 	ata_delay(chp, 10, "ahcirstw", flags);
 
-	cmd_h->cmdh_flags = htole16(RHD_FISLEN / 4 |
-	(drive << AHCI_CMDH_F_PMP_SHIFT));
-	cmd_h->cmdh_prdbc = 0;
-	memset(cmd_tbl->cmdt_cfis, 0, 64);
-	cmd_tbl->cmdt_cfis[fis_type] = RHD_FISTYPE;
-	cmd_tbl->cmdt_cfis[rhd_c] = drive;
-	cmd_tbl->cmdt_cfis[rhd_control] = WDCTL_4BIT;
-	switch (ahci_exec_fis(chp, 310, flags, c_slot)) {
-	case ERR_DF:
-	case TIMEOUT:
+	/*
+	 * Try to clear WDCTL_RST a few times before giving up.
+	 */
+	for (error = EBUSY, retry = 0; error != 0 && retry < 5; retry++) {
+		cmd_h->cmdh_flags = htole16(RHD_FISLEN / 4 |
+		(drive << AHCI_CMDH_F_PMP_SHIFT));
+		cmd_h->cmdh_prdbc = 0;
+		memset(cmd_tbl->cmdt_cfis, 0, 64);
+		cmd_tbl->cmdt_cfis[fis_type] = RHD_FISTYPE;
+		cmd_tbl->cmdt_cfis[rhd_c] = drive;
+		cmd_tbl->cmdt_cfis[rhd_control] = WDCTL_4BIT;
+		switch (ahci_exec_fis(chp, 310, flags, c_slot)) {
+		case ERR_DF:
+		case TIMEOUT:
+			error = EBUSY;
+			break;
+		default:
+			error = 0;
+			break;
+		}
+		if (error == 0) {
+			break;
+		}
+	}
+	if (error == EBUSY) {
 		aprint_error("%s port %d: clearing WDCTL_RST failed "
 		"for drive %d\n", AHCINAME(sc), chp->ch_channel, drive);
-		error = EBUSY;
 		goto end;
-	default:
-		break;
 	}
 
 skip_reset:



CVS commit: src/sys/dev/ic

2020-12-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Dec 19 19:12:02 UTC 2020

Modified Files:
src/sys/dev/ic: ahcisata_core.c

Log Message:
ahci_exec_fis: wait for the correct amount of time when AT_WAIT is set


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/sys/dev/ic/ahcisata_core.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/ic/ahcisata_core.c
diff -u src/sys/dev/ic/ahcisata_core.c:1.83 src/sys/dev/ic/ahcisata_core.c:1.84
--- src/sys/dev/ic/ahcisata_core.c:1.83	Mon Apr 13 10:49:34 2020
+++ src/sys/dev/ic/ahcisata_core.c	Sat Dec 19 19:12:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahcisata_core.c,v 1.83 2020/04/13 10:49:34 jdolecek Exp $	*/
+/*	$NetBSD: ahcisata_core.c,v 1.84 2020/12/19 19:12:02 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.83 2020/04/13 10:49:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_core.c,v 1.84 2020/12/19 19:12:02 jmcneill Exp $");
 
 #include 
 #include 
@@ -761,14 +761,10 @@ ahci_exec_fis(struct ata_channel *chp, i
 	uint32_t is;
 
 	/*
-	 * Base timeout is specified in ms.
-	 * If we are allowed to sleep, wait a tick each round.
-	 * Otherwise delay for 10ms on each round.
+	 * Base timeout is specified in ms. Delay for 10ms
+	 * on each round.
 	 */
-	if (flags & AT_WAIT)
-		timeout = MAX(1, mstohz(timeout));
-	else
-		timeout = timeout / 10;
+	timeout = timeout / 10;
 
 	AHCI_CMDTBL_SYNC(sc, achp, slot, BUS_DMASYNC_PREWRITE);
 	AHCI_CMDH_SYNC(sc, achp, slot,



CVS commit: src/sys/dev/ic

2020-12-04 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Fri Dec  4 23:03:11 UTC 2020

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
PR kern/55839:
handle multiple nvme_rescan()s correctly by doing the
name-space identify only once per nsid.

fixes issue where modloading triggers multiple
rescans.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.52 src/sys/dev/ic/nvme.c:1.53
--- src/sys/dev/ic/nvme.c:1.52	Tue Nov 10 07:39:12 2020
+++ src/sys/dev/ic/nvme.c	Fri Dec  4 23:03:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.52 2020/11/10 07:39:12 rin Exp $	*/
+/*	$NetBSD: nvme.c,v 1.53 2020/12/04 23:03:11 kardel Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.52 2020/11/10 07:39:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.53 2020/12/04 23:03:11 kardel Exp $");
 
 #include 
 #include 
@@ -628,6 +628,12 @@ nvme_ns_identify(struct nvme_softc *sc, 
 
 	KASSERT(nsid > 0);
 
+	ns = nvme_ns_get(sc, nsid);
+	KASSERT(ns);
+
+	if (ns->ident != NULL)
+		return 0;
+
 	ccb = nvme_ccb_get(sc->sc_admin_q, false);
 	KASSERT(ccb != NULL); /* it's a bug if we don't have spare ccb here */
 
@@ -665,9 +671,6 @@ nvme_ns_identify(struct nvme_softc *sc, 
 	/* Convert data to host endian */
 	nvme_identify_namespace_swapbytes(identify);
 
-	ns = nvme_ns_get(sc, nsid);
-	KASSERT(ns);
-	KASSERT(ns->ident == NULL);
 	ns->ident = identify;
 
 done:



CVS commit: src/sys/dev/ic

2020-12-03 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Dec  4 00:38:08 UTC 2020

Modified Files:
src/sys/dev/ic: ibm561.c

Log Message:
- malloc(9) -> kmem(9)
- In ibm561_set_cmap(), allocating 3K on the stack is not polite; allocate
  a temporary buffer for the cmap data using kmem_alloc().


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/ic/ibm561.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/ic/ibm561.c
diff -u src/sys/dev/ic/ibm561.c:1.13 src/sys/dev/ic/ibm561.c:1.14
--- src/sys/dev/ic/ibm561.c:1.13	Wed Jun 24 20:17:55 2020
+++ src/sys/dev/ic/ibm561.c	Fri Dec  4 00:38:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ibm561.c,v 1.13 2020/06/24 20:17:55 jdolecek Exp $ */
+/* $NetBSD: ibm561.c,v 1.14 2020/12/04 00:38:08 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,14 +30,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.13 2020/06/24 20:17:55 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.14 2020/12/04 00:38:08 thorpej Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include 
 #include 
@@ -141,7 +141,7 @@ ibm561_register(
 {
 	struct ibm561data *data;
 
-	data = malloc(sizeof *data, M_DEVBUF, M_WAITOK|M_ZERO);
+	data = kmem_zalloc(sizeof *data, KM_SLEEP);
 	data->cookie = v;
 	data->ramdac_sched_update = sched_update;
 	data->ramdac_wr = wr;
@@ -255,26 +255,30 @@ ibm561_set_cmap(struct ramdac_cookie *rc
 {
 	struct ibm561data *data = (struct ibm561data *)rc;
 	u_int count, index;
-	uint8_t r[IBM561_NCMAP_ENTRIES];
-	uint8_t g[IBM561_NCMAP_ENTRIES];
-	uint8_t b[IBM561_NCMAP_ENTRIES];
+	uint8_t *cmap_entries, *r, *g, *b;
 	int s, error;
 
 	if (cmapp->index >= IBM561_NCMAP_ENTRIES ||
 	cmapp->count > IBM561_NCMAP_ENTRIES - cmapp->index)
 		return (EINVAL);
 
+	cmap_entries = kmem_alloc(IBM561_NCMAP_ENTRIES * 3, KM_SLEEP);
+	r = _entries[0 * IBM561_NCMAP_ENTRIES];
+	g = _entries[1 * IBM561_NCMAP_ENTRIES];
+	b = _entries[2 * IBM561_NCMAP_ENTRIES];
+
 	index = cmapp->index;
 	count = cmapp->count;
 	error = copyin(cmapp->red, [index], count);
 	if (error)
-		return error;
+		goto out;
 	error = copyin(cmapp->green, [index], count);
 	if (error)
-		return error;
+		goto out;
 	error = copyin(cmapp->blue, [index], count);
 	if (error)
-		return error;
+		goto out;
+
 	s = spltty();
 	memcpy(>cmap_r[index], [index], count);
 	memcpy(>cmap_g[index], [index], count);
@@ -282,7 +286,10 @@ ibm561_set_cmap(struct ramdac_cookie *rc
 	data->changed |= CHANGED_CMAP;
 	data->ramdac_sched_update(data->cookie, ibm561_update);
 	splx(s);
-	return (0);
+
+ out:
+	kmem_free(cmap_entries, IBM561_NCMAP_ENTRIES * 3);
+	return (error);
 }
 
 int



CVS commit: src/sys/dev/ic

2020-11-15 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov 16 00:12:13 UTC 2020

Modified Files:
src/sys/dev/ic: ath.c atppc.c

Log Message:
s/reseting/resetting/


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/sys/dev/ic/ath.c
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/ic/atppc.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/ic/ath.c
diff -u src/sys/dev/ic/ath.c:1.132 src/sys/dev/ic/ath.c:1.133
--- src/sys/dev/ic/ath.c:1.132	Wed Jul 22 01:24:40 2020
+++ src/sys/dev/ic/ath.c	Mon Nov 16 00:12:13 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ath.c,v 1.132 2020/07/22 01:24:40 msaitoh Exp $	*/
+/*	$NetBSD: ath.c,v 1.133 2020/11/16 00:12:13 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -41,7 +41,7 @@
 __FBSDID("$FreeBSD: src/sys/dev/ath/if_ath.c,v 1.104 2005/09/16 10:09:23 ru Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.132 2020/07/22 01:24:40 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ath.c,v 1.133 2020/11/16 00:12:13 msaitoh Exp $");
 #endif
 
 /*
@@ -4551,7 +4551,7 @@ ath_dfswait(void *arg)
 
 /*
  * Set/change channels.  If the channel is really being changed,
- * it's done by reseting the chip.  To accomplish this we must
+ * it's done by resetting the chip.  To accomplish this we must
  * first cleanup any pending DMA, then restart stuff after a la
  * ath_init.
  */
@@ -5226,7 +5226,7 @@ ath_setcurmode(struct ath_softc *sc, enu
 	/* XXX layering violation */
 	sc->sc_mcastrix = ath_tx_findrix(rt, sc->sc_ic.ic_mcast_rate);
 	sc->sc_mcastrate = sc->sc_ic.ic_mcast_rate;
-	/* NB: caller is responsible for reseting rate control state */
+	/* NB: caller is responsible for resetting rate control state */
 #undef N
 }
 

Index: src/sys/dev/ic/atppc.c
diff -u src/sys/dev/ic/atppc.c:1.36 src/sys/dev/ic/atppc.c:1.37
--- src/sys/dev/ic/atppc.c:1.36	Wed Jul 22 01:24:40 2020
+++ src/sys/dev/ic/atppc.c	Mon Nov 16 00:12:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc.c,v 1.36 2020/07/22 01:24:40 msaitoh Exp $ */
+/* $NetBSD: atppc.c,v 1.37 2020/11/16 00:12:13 msaitoh Exp $ */
 
 /*
  * Copyright (c) 2001 Alcove - Nicolas Souchu
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: atppc.c,v 1.36 2020/07/22 01:24:40 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc.c,v 1.37 2020/11/16 00:12:13 msaitoh Exp $");
 
 #include "opt_atppc.h"
 
@@ -2310,7 +2310,7 @@ atppc_fifo_write_error(struct atppc_soft
 		atppc->sc_outbstart += worklen;
 	}
 
-	ATPPC_DPRINTF(("%s: reseting FIFO.\n", __func__));
+	ATPPC_DPRINTF(("%s: resetting FIFO.\n", __func__));
 	atppc_w_ecr(atppc, ATPPC_ECR_PS2);
 	atppc_barrier_w(atppc);
 }



CVS commit: src/sys/dev/ic

2020-11-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun Nov 15 12:33:53 UTC 2020

Modified Files:
src/sys/dev/ic: athn.c

Log Message:
Don't unlock without having taken the lock.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ic/athn.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/ic/athn.c
diff -u src/sys/dev/ic/athn.c:1.23 src/sys/dev/ic/athn.c:1.24
--- src/sys/dev/ic/athn.c:1.23	Wed Jan 29 14:09:58 2020
+++ src/sys/dev/ic/athn.c	Sun Nov 15 12:33:53 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: athn.c,v 1.23 2020/01/29 14:09:58 thorpej Exp $	*/
+/*	$NetBSD: athn.c,v 1.24 2020/11/15 12:33:53 mlelstv Exp $	*/
 /*	$OpenBSD: athn.c,v 1.83 2014/07/22 13:12:11 mpi Exp $	*/
 
 /*-
@@ -23,7 +23,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.23 2020/01/29 14:09:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: athn.c,v 1.24 2020/11/15 12:33:53 mlelstv Exp $");
 
 #ifndef _MODULE
 #include "athn_usb.h"		/* for NATHN_USB */
@@ -2734,7 +2734,7 @@ athn_set_multi(struct athn_softc *sc)
 
 	if ((ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) != 0) {
 		lo = hi = 0x;
-		goto done;
+		goto done2;
 	}
 	lo = hi = 0;
 	ETHER_LOCK(ec);
@@ -2760,6 +2760,7 @@ athn_set_multi(struct athn_softc *sc)
 	}
  done:
 	ETHER_UNLOCK(ec);
+ done2:
 	AR_WRITE(sc, AR_MCAST_FIL0, lo);
 	AR_WRITE(sc, AR_MCAST_FIL1, hi);
 	AR_WRITE_BARRIER(sc);



CVS commit: src/sys/dev/ic

2020-11-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Tue Nov 10 07:39:12 UTC 2020

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
One more fix for big-endian machines.

Now, ld(4) at nvme(4) works perfectly for aarch64eb!

Tested on ROCKPro64 and qemu-system-aarch64.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.51 src/sys/dev/ic/nvme.c:1.52
--- src/sys/dev/ic/nvme.c:1.51	Thu Sep 24 09:59:11 2020
+++ src/sys/dev/ic/nvme.c	Tue Nov 10 07:39:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.51 2020/09/24 09:59:11 ryo Exp $	*/
+/*	$NetBSD: nvme.c,v 1.52 2020/11/10 07:39:12 rin Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.51 2020/09/24 09:59:11 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.52 2020/11/10 07:39:12 rin Exp $");
 
 #include 
 #include 
@@ -1377,7 +1377,7 @@ nvme_q_complete(struct nvme_softc *sc, s
 		if ((flags & NVME_CQE_PHASE) != q->q_cq_phase)
 			break;
 
-		ccb = >q_ccbs[cqe->cid];
+		ccb = >q_ccbs[lemtoh16(>cid)];
 
 		if (++q->q_cq_head >= q->q_entries) {
 			q->q_cq_head = 0;



CVS commit: src/sys/dev/ic

2020-10-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Oct 18 11:51:09 UTC 2020

Modified Files:
src/sys/dev/ic: ac97.c

Log Message:
Fix undefined behaviors found by kUBSan.
Tested on VirtualBox with amd64 kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/ic/ac97.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/ic/ac97.c
diff -u src/sys/dev/ic/ac97.c:1.99 src/sys/dev/ic/ac97.c:1.100
--- src/sys/dev/ic/ac97.c:1.99	Thu Nov 28 05:07:27 2019
+++ src/sys/dev/ic/ac97.c	Sun Oct 18 11:51:08 2020
@@ -1,4 +1,4 @@
-/*  $NetBSD: ac97.c,v 1.99 2019/11/28 05:07:27 isaki Exp $ */
+/*  $NetBSD: ac97.c,v 1.100 2020/10/18 11:51:08 rin Exp $ */
 /*	$OpenBSD: ac97.c,v 1.8 2000/07/19 09:01:35 csapuntz Exp $	*/
 
 /*
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.99 2019/11/28 05:07:27 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.100 2020/10/18 11:51:08 rin Exp $");
 
 #include 
 #include 
@@ -1315,7 +1315,7 @@ ac97_attach_type(struct ac97_host_if *ho
 
 	mutex_exit(as->lock);
 
-	id = (id1 << 16) | id2;
+	id = ((uint32_t)id1 << 16) | id2;
 	aprint_normal_dev(sc_dev, "ac97: ");
 
 	for (i = 0; ; i++) {
@@ -1696,7 +1696,8 @@ ac97_query_devinfo(struct ac97_codec_if 
 		if (name)
 			strcpy(dip->label.name, name);
 
-		memcpy(>un, si->info, si->info_size);
+		if (si->info)
+			memcpy(>un, si->info, si->info_size);
 
 		/* Set the delta for volume sources */
 		if (dip->type == AUDIO_MIXER_VALUE)



CVS commit: src/sys/dev/ic

2020-10-10 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Oct 10 20:27:55 UTC 2020

Modified Files:
src/sys/dev/ic: siisata.c

Log Message:
In siisata_intr_port(), skip reading the error condition if
ata_queue_get_active_xfer() returns NULL.

PR kern/55682.  Fix suggested by mlelstv@.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/ic/siisata.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/ic/siisata.c
diff -u src/sys/dev/ic/siisata.c:1.42 src/sys/dev/ic/siisata.c:1.43
--- src/sys/dev/ic/siisata.c:1.42	Mon Apr 13 10:49:34 2020
+++ src/sys/dev/ic/siisata.c	Sat Oct 10 20:27:54 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: siisata.c,v 1.42 2020/04/13 10:49:34 jdolecek Exp $ */
+/* $NetBSD: siisata.c,v 1.43 2020/10/10 20:27:54 thorpej Exp $ */
 
 /* from ahcisata_core.c */
 
@@ -79,7 +79,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.42 2020/04/13 10:49:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: siisata.c,v 1.43 2020/10/10 20:27:54 thorpej Exp $");
 
 #include 
 #include 
@@ -540,10 +540,9 @@ siisata_intr_port(struct siisata_channel
 		tfd = ATACH_ERR_ST(WDCE_CRC, WDCS_ERR);
 
 		if (ec <= PR_PCE_DATAFISERROR) {
-			if (ec == PR_PCE_DEVICEERROR
-			&& (chp->ch_flags & ATACH_NCQ) == 0) {
-xfer = ata_queue_get_active_xfer(chp);
-
+			if (ec == PR_PCE_DEVICEERROR &&
+			(chp->ch_flags & ATACH_NCQ) == 0 &&
+			(xfer = ata_queue_get_active_xfer(chp)) != NULL) {
 /* read in specific information about error */
 uint32_t prbfis = bus_space_read_stream_4(
 sc->sc_prt, sc->sc_prh,



CVS commit: src/sys/dev/ic

2020-10-08 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Oct  8 21:00:25 UTC 2020

Modified Files:
src/sys/dev/ic: dm9000reg.h

Log Message:
add DM9000A register definitions


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/ic/dm9000reg.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/ic/dm9000reg.h
diff -u src/sys/dev/ic/dm9000reg.h:1.5 src/sys/dev/ic/dm9000reg.h:1.6
--- src/sys/dev/ic/dm9000reg.h:1.5	Thu Oct  8 11:29:04 2020
+++ src/sys/dev/ic/dm9000reg.h	Thu Oct  8 21:00:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dm9000reg.h,v 1.5 2020/10/08 11:29:04 nisimura Exp $	*/
+/*	$NetBSD: dm9000reg.h,v 1.6 2020/10/08 21:00:25 nisimura Exp $	*/
 
 /*
  * Copyright (c) 2009 Paul Fleischer
@@ -167,17 +167,29 @@
 #define DM9000_PID1	0x2B	/* product ID 15:8 */
 #define DM9000_CHIPR	0x2C	/* chip revision */
 
-#define DM9000_SMCR	0x2F	/* "serial mode" control */
+#define DM9000_TCR2	0x2D	/* Tx control 2 */
+#define DM9000_OTCR	0x2E	/* operation test control */
+#define DM9000_SMCR	0x2F	/* special mode control */
 #define  DM9000_FB0	(1<<0)	/* force shortest back-off time */
 #define  DM9000_FB1	(1<<1)	/* force longeset back-off time */
 #define  DM9000_FLC	(1<<2)	/* force late collsion */
 #define  DM9000_SM_EN	(1<<7)	/* serial mode enable */
-#define DM9000_MRCMDX	0xF0	/* "no increment"   read byte */
-#define DM9000_MRCMD	0xF2	/* "auto increment" read byte */
+#define DM9000_ETXCSR	0x30	/* early xmit control and status */
+#define DM9000_TCSCR	0x31	/* xmit checksum control */
+#define DM9000_RCSCSR	0x32	/* recv checksum control and status */
+#define DM9000_MPAR	0x33	/* MII PHY address */
+#define DM9000_LEDCR	0x34	/* LED pin control */
+#define DM9000_BUSCR	0x38	/* processor bus control */
+#define DM9000_INTCR	0x39	/* INT pin control */
+#define DM9000_SCCR	0x50	/* system clock turn on control */
+#define DM9000_RSCCR	0x51	/* resume system clock control */
+#define DM9000_MRCMDX	0xF0	/* "no increment" pre-fetch read */
+#define DM9000_MRCMDX1	0xF1	/* "no increment" read */
+#define DM9000_MRCMD	0xF2	/* "auto increment" read */
 #define DM9000_MRRL	0xF4	/* memory read address 7:0 */
 #define DM9000_MRRH	0xF5	/* memory read address 15:8 */
-#define DM9000_MWCMDX	0xF6	/* "no increment"   write byte */
-#define DM9000_MWCMD	0xF8	/* "auto increment" write byte */
+#define DM9000_MWCMDX	0xF6	/* "no increment" write */
+#define DM9000_MWCMD	0xF8	/* "auto increment" write */
 #define DM9000_MWRL	0xFA	/* memory write address 7:0 */
 #define DM9000_MWRH	0xFB	/* memory write address 15:8 */
 #define DM9000_TXPLL	0xFC	/* frame len 7:0 to transmit */



CVS commit: src/sys/dev/ic

2020-10-08 Thread Tohru Nishimura
Module Name:src
Committed By:   nisimura
Date:   Thu Oct  8 11:29:05 UTC 2020

Modified Files:
src/sys/dev/ic: dm9000reg.h

Log Message:
improve register descriptions


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/ic/dm9000reg.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/ic/dm9000reg.h
diff -u src/sys/dev/ic/dm9000reg.h:1.4 src/sys/dev/ic/dm9000reg.h:1.5
--- src/sys/dev/ic/dm9000reg.h:1.4	Tue Mar 31 02:32:25 2020
+++ src/sys/dev/ic/dm9000reg.h	Thu Oct  8 11:29:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dm9000reg.h,v 1.4 2020/03/31 02:32:25 nisimura Exp $	*/
+/*	$NetBSD: dm9000reg.h,v 1.5 2020/10/08 11:29:04 nisimura Exp $	*/
 
 /*
  * Copyright (c) 2009 Paul Fleischer
@@ -47,77 +47,92 @@
 
 #define DM9000_IOSIZE 4
 
-#define DM9000_NCR		0x00
+#define DM9000_NCR		0x00	/* "network" control */
 #define  DM9000_NCR_RST		(1<<0)	/* reset chip, self clear */
-#define  DM9000_NCR_LBK_MASK	(0x06)
+#define  DM9000_NCR_LBK_MASK	(0x06)	/* loopback test selection */
 #define  DM9000_NCR_LBK_SHIFT	(1)
-#define  DM9000_NCR_LBK_MAC_INTERNAL (1<1522) */
-#define  DM9000_RCR_WTDIS	(1<<6)	/* disable Rx watchdog timer */
-#define DM9000_RSR		0x06
+#define  DM9000_RCR_DIS_LONG	(1<<5)	/* drop too long frame >1522 */
+#define  DM9000_RCR_WTDIS	(1<<6)	/* disable >2048 Rx detect timer */
+#define DM9000_RSR		0x06	/* Rx status */
 #define  DM9000_RSR_FOE		(1<<0)	/* Rx FIFO overflow detected */
-#define  DM9000_RSR_CE		(1<<1)
-#define  DM9000_RSR_AE		(1<<2)
-#define  DM9000_RSR_PLE		(1<<3)
-#define  DM9000_RSR_RWTO	(1<<4)
-#define  DM9000_RSR_LCS		(1<<5)
+#define  DM9000_RSR_CE		(1<<1)	/* CRC error found */
+#define  DM9000_RSR_AE		(1<<2)	/* tail not ended in byte boundary */
+#define  DM9000_RSR_PLE		(1<<3)	/* physical layer error */
+#define  DM9000_RSR_RWTO	(1<<4)	/* >2048 condition detected */
+#define  DM9000_RSR_LCS		(1<<5)	/* late colli. detected */
 #define  DM9000_RSR_MF		(1<<6)	/* mcast/bcast frame received */
-#define  DM9000_RSR_RF		(1<<7)	/* runt frame received (<64 bytes) */
-#define DM9000_ROCR		0x07
-#define DM9000_BPTR		0x08
-#define DM9000_FCTR		0x09
-#define DM9000_FCR		0x0A
+#define  DM9000_RSR_RF		(1<<7)	/* damaged runt frame received <64 */
+#define DM9000_ROCR		0x07	/* receive overflow counter */
+/* 7: OVF detected, 6:0 statistic couner */
+#define DM9000_BPTR		0x08	/* back pressure threshold */
+/* 7:4 back pressure high watermark (3 def), 3:0 jam pattern time (7 def) */
+#define DM9000_FCTR		0x09	/* flow control threshold */
+/* 7:4 Rx FIFO high w.m. (3 def), low w.m. (8 def) */
+#define DM9000_FCR		0x0A	/* Rx flow control */
 #define  DM9000_FCR_FLCE	(1<<0)	/* flow control enable */
 #define  DM9000_FCR_RXPCS	(1<<1)	/* Rx PAUSE current status */
-#define  DM9000_FCR_RXPS	(1<<2)	/* Rx PAUSE status, read to clear */
-#define  DM9000_FCR_BKPM	(1<<3)
-#define  DM9000_FCR_BKPA	(1<<4)
-#define  DM9000_FCR_TXPEN	(1<<5)	/* force PAUSE/unPAUSE */
-#define  DM9000_FCR_TXPF	(1<<6)	/* Tx PAUSE packet (when full */
+#define  DM9000_FCR_RXPS	(1<<2)	/* Rx PAUSE status, latched R2C */
+#define  DM9000_FCR_BKPM	(1<<3)	/* HDX back pressure for my frames */
+#define  DM9000_FCR_BKPA	(1<<4)	/* HDX back pressure for any frames */
+#define  DM9000_FCR_TXPEN	(1<<5)	/* activate auto PAUSE operation */
+#define  DM9000_FCR_TXPF	(1<<6)	/* Tx PAUSE packet (when full) */
 #define  DM9000_FCR_TXP0	(1<<7)	/* Tx PAUSE packet (when empty) */
-#define DM9000_EPCR		0x0B
+#define DM9000_EPCR		0x0B	/* EEPROM / PHY control */
 #define  DM9000_EPCR_ERRE	(1<<0)	/* operation in progress, busy bit */
-#define  DM9000_EPCR_ERPRW	(1<<1)	/* instruct to write */
-#define  DM9000_EPCR_ERPRR	(1<<2)	/* instruct to read */
-#define  DM9000_EPCR_EPOS_EEPROM (0<<3)	/* 1: PHY op, 0: EEPROM op */
-#define  DM9000_EPCR_EPOS_PHY(1<<3)
-#define  DM9000_EPCR_WEP	(1<<4)
-#define  DM9000_EPCR_REEP	(1<<5)
-#define DM9000_EPAR		0x0C	/* 7:6 (!!) PHY id, 5:0 reg num */
-#define  DM9000_EPAR_EROA_MASK	0x3F	/* bits 0-5 */
+#define  DM9000_EPCR_ERPRW	(1<<1)	/* instruct to write, not SC */
+#define  DM9000_EPCR_ERPRR	(1<<2)	/* instruct to read, not SC */
+#define  DM9000_EPCR_EPOS_EEPROM (0<<3)	/* EEPROM operation */
+#define  DM9000_EPCR_EPOS_PHY(1<<3)	/* PHY operation */
+#define  DM9000_EPCR_WEP	(1<<4)	/* EEPROM write enable */
+#define  DM9000_EPCR_REEP	(1<<5)	/* reload EEPROM contents, not SC */
+#define DM9000_EPAR		0x0C	/* EEPROM / PHY address */
+#define  DM9000_EPAR_EROA_MASK	0x3F	/* 7:6 (!!) PHY id, 5:0 addr/reg */
 #define  DM9000_EPAR_INT_PHY	0x40	/* EPAR[7:6] = 01 for internal PHY */
-#define DM9000_EPDRL		0x0D	/* data 7:0 */
-#define DM9000_EPDRH		0x0E	/* data 15:8 */
-#define DM9000_WCR		0x0F
+#define DM9000_EPDRL		0x0D	/* EEPROM / PHY data 7:0 */
+#define DM9000_EPDRH		0x0E	/* EEPROM / PHY data 15:8 */
+#define DM9000_WCR		0x0F	/* wakeup control and status */
+#define  DM9000_MAGIC		(1<<0)	/* magic 

CVS commit: src/sys/dev/ic

2020-09-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Sep 30 14:56:34 UTC 2020

Modified Files:
src/sys/dev/ic: com.c

Log Message:
Set sc_fifolen=1 for the no fifo case


To generate a diff of this commit:
cvs rdiff -u -r1.360 -r1.361 src/sys/dev/ic/com.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/ic/com.c
diff -u src/sys/dev/ic/com.c:1.360 src/sys/dev/ic/com.c:1.361
--- src/sys/dev/ic/com.c:1.360	Mon Sep 28 11:33:15 2020
+++ src/sys/dev/ic/com.c	Wed Sep 30 14:56:34 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $ */
+/* $NetBSD: com.c,v 1.361 2020/09/30 14:56:34 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.361 2020/09/30 14:56:34 jmcneill Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -543,6 +543,7 @@ com_attach_subr(struct com_softc *sc)
 		DW_APB_UART_CPR);
 		sc->sc_fifolen = __SHIFTOUT(cpr, UART_CPR_FIFO_MODE) * 16;
 		if (sc->sc_fifolen == 0) {
+			sc->sc_fifolen = 1;
 			fifo_msg = "DesignWare APB UART, no fifo";
 			CSR_WRITE_1(regsp, COM_REG_FIFO, 0);
 		} else {



CVS commit: src/sys/dev/ic

2020-09-29 Thread Simon Burge
Module Name:src
Committed By:   simonb
Date:   Wed Sep 30 05:04:55 UTC 2020

Modified Files:
src/sys/dev/ic: sl811hs.c

Log Message:
Add some KNF whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/ic/sl811hs.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/ic/sl811hs.c
diff -u src/sys/dev/ic/sl811hs.c:1.103 src/sys/dev/ic/sl811hs.c:1.104
--- src/sys/dev/ic/sl811hs.c:1.103	Sat Feb 15 01:21:56 2020
+++ src/sys/dev/ic/sl811hs.c	Wed Sep 30 05:04:54 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sl811hs.c,v 1.103 2020/02/15 01:21:56 riastradh Exp $	*/
+/*	$NetBSD: sl811hs.c,v 1.104 2020/09/30 05:04:54 simonb Exp $	*/
 
 /*
  * Not (c) 2007 Matthew Orgass
@@ -68,7 +68,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.103 2020/02/15 01:21:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.104 2020/09/30 05:04:54 simonb Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_slhci.h"
@@ -584,28 +584,28 @@ DDOLOGBUF(uint8_t *buf, unsigned int len
 	SLHCIHIST_FUNC(); SLHCIHIST_CALLED();
 	int i;
 
-	for(i=0; i+8 <= length; i+=8)
+	for(i = 0; i + 8 <= length; i += 8)
 		DDOLOG("%.4x %.4x %.4x %.4x", (buf[i] << 8) | buf[i+1],
 		(buf[i+2] << 8) | buf[i+3], (buf[i+4] << 8) | buf[i+5],
 		(buf[i+6] << 8) | buf[i+7]);
-	if (length == i+7)
+	if (length == i + 7)
 		DDOLOG("%.4x %.4x %.4x %.2x", (buf[i] << 8) | buf[i+1],
 		(buf[i+2] << 8) | buf[i+3], (buf[i+4] << 8) | buf[i+5],
 		buf[i+6]);
-	else if (length == i+6)
+	else if (length == i + 6)
 		DDOLOG("%.4x %.4x %.4x", (buf[i] << 8) | buf[i+1],
 		(buf[i+2] << 8) | buf[i+3], (buf[i+4] << 8) | buf[i+5], 0);
-	else if (length == i+5)
+	else if (length == i + 5)
 		DDOLOG("%.4x %.4x %.2x", (buf[i] << 8) | buf[i+1],
 		(buf[i+2] << 8) | buf[i+3], buf[i+4], 0);
-	else if (length == i+4)
+	else if (length == i + 4)
 		DDOLOG("%.4x %.4x", (buf[i] << 8) | buf[i+1],
 		(buf[i+2] << 8) | buf[i+3], 0,0);
-	else if (length == i+3)
+	else if (length == i + 3)
 		DDOLOG("%.4x %.2x", (buf[i] << 8) | buf[i+1], buf[i+2], 0,0);
-	else if (length == i+2)
+	else if (length == i + 2)
 		DDOLOG("%.4x", (buf[i] << 8) | buf[i+1], 0,0,0);
-	else if (length == i+1)
+	else if (length == i + 1)
 		DDOLOG("%.2x", buf[i], 0,0,0);
 }
 #define DLOGBUF(x, b, l) SLHCI_DEXEC(x, DDOLOGBUF(b, l))
@@ -702,7 +702,7 @@ DDOLOGBUF(uint8_t *buf, unsigned int len
 
 const struct usbd_bus_methods slhci_bus_methods = {
 	.ubm_open = slhci_open,
-	.ubm_softint= slhci_void,
+	.ubm_softint = slhci_void,
 	.ubm_dopoll = slhci_poll,
 	.ubm_allocx = slhci_allocx,
 	.ubm_freex = slhci_freex,
@@ -2742,7 +2742,7 @@ slhci_drain(struct slhci_softc *sc)
 
 	t->pend = INT_MAX;
 
-	for (i=0; i<=1; i++) {
+	for (i = 0; i <= 1; i++) {
 		t->len[i] = -1;
 		if (t->spipe[i] != NULL) {
 			enter_callback(t, t->spipe[i]);
@@ -3518,7 +3518,7 @@ slhci_log_sc(void)
 	DDOLOG("a = %p Alen=%d b = %p Blen=%d", t->spipe[0], t->len[0],
 	t->spipe[1], t->len[1]);
 
-	for (i=0; i<=Q_MAX; i++)
+	for (i = 0; i <= Q_MAX; i++)
 		DDOLOG("Q %d: %p", i, gcq_hq(>q[i]), 0,0);
 
 	DDOLOG("TIMED: %p", GCQ_ITEM(gcq_hq(>to),



CVS commit: src/sys/dev/ic

2020-09-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Sep 28 11:33:15 UTC 2020

Modified Files:
src/sys/dev/ic: com.c comreg.h

Log Message:
Auto-detect DW APB UART FIFO length and print the FIFO length when enabled
instead of just "working fifo".


To generate a diff of this commit:
cvs rdiff -u -r1.359 -r1.360 src/sys/dev/ic/com.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/ic/comreg.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/ic/com.c
diff -u src/sys/dev/ic/com.c:1.359 src/sys/dev/ic/com.c:1.360
--- src/sys/dev/ic/com.c:1.359	Tue May 26 13:24:52 2020
+++ src/sys/dev/ic/com.c	Mon Sep 28 11:33:15 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $ */
+/* $NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.360 2020/09/28 11:33:15 jmcneill Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -428,9 +428,10 @@ com_attach_subr(struct com_softc *sc)
 {
 	struct com_regs *regsp = >sc_regs;
 	struct tty *tp;
-	u_int8_t lcr;
+	uint32_t cpr;
+	uint8_t lcr;
 	const char *fifo_msg = NULL;
-	prop_dictionary_t	dict;
+	prop_dictionary_t dict;
 	bool is_console = true;
 	bool force_console = false;
 
@@ -498,32 +499,32 @@ com_attach_subr(struct com_softc *sc)
 
 	case COM_TYPE_AU1x00:
 		sc->sc_fifolen = 16;
-		fifo_msg = "Au1X00 UART, working fifo";
+		fifo_msg = "Au1X00 UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_16550_NOERS:
 		sc->sc_fifolen = 16;
-		fifo_msg = "ns16650, no ERS, working fifo";
+		fifo_msg = "ns16650, no ERS";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_OMAP:
 		sc->sc_fifolen = 64;
-		fifo_msg = "OMAP UART, working fifo";
+		fifo_msg = "OMAP UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		goto fifodelay;
 
 	case COM_TYPE_INGENIC:
 		sc->sc_fifolen = 16;
-		fifo_msg = "Ingenic UART, working fifo";
+		fifo_msg = "Ingenic UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		SET(sc->sc_hwflags, COM_HW_NOIEN);
 		goto fifodelay;
 
 	case COM_TYPE_TEGRA:
 		sc->sc_fifolen = 8;
-		fifo_msg = "Tegra UART, working fifo";
+		fifo_msg = "Tegra UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		CSR_WRITE_1(regsp, COM_REG_FIFO,
 		FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
@@ -531,11 +532,26 @@ com_attach_subr(struct com_softc *sc)
 
 	case COM_TYPE_BCMAUXUART:
 		sc->sc_fifolen = 1;
-		fifo_msg = "BCM AUX UART, working fifo";
+		fifo_msg = "BCM AUX UART";
 		SET(sc->sc_hwflags, COM_HW_FIFO);
 		CSR_WRITE_1(regsp, COM_REG_FIFO,
 		FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
 		goto fifodelay;
+
+	case COM_TYPE_DW_APB:
+		cpr = bus_space_read_4(sc->sc_regs.cr_iot, sc->sc_regs.cr_ioh,
+		DW_APB_UART_CPR);
+		sc->sc_fifolen = __SHIFTOUT(cpr, UART_CPR_FIFO_MODE) * 16;
+		if (sc->sc_fifolen == 0) {
+			fifo_msg = "DesignWare APB UART, no fifo";
+			CSR_WRITE_1(regsp, COM_REG_FIFO, 0);
+		} else {
+			fifo_msg = "DesignWare APB UART";
+			SET(sc->sc_hwflags, COM_HW_FIFO);
+			CSR_WRITE_1(regsp, COM_REG_FIFO,
+			FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1);
+		}
+		goto fifodelay;
 	}
 
 	sc->sc_fifolen = 1;
@@ -554,7 +570,7 @@ com_attach_subr(struct com_softc *sc)
 		== FIFO_TRIGGER_14) {
 			SET(sc->sc_hwflags, COM_HW_FIFO);
 
-			fifo_msg = "ns16550a, working fifo";
+			fifo_msg = "ns16550a";
 
 			/*
 			 * IIR changes into the EFR if LCR is set to LCR_EERS
@@ -588,9 +604,9 @@ com_attach_subr(struct com_softc *sc)
 if (sc->sc_fifolen == 0)
 	fifo_msg = "st16650, broken fifo";
 else if (sc->sc_fifolen == 32)
-	fifo_msg = "st16650a, working fifo";
+	fifo_msg = "st16650a";
 else
-	fifo_msg = "ns16550a, working fifo";
+	fifo_msg = "ns16550a";
 			}
 
 			/*
@@ -629,9 +645,9 @@ com_attach_subr(struct com_softc *sc)
 	CSR_WRITE_1(regsp, COM_REG_FIFO, fcr);
 
 if (sc->sc_fifolen == 64)
-	fifo_msg = "tl16c750, working fifo";
+	fifo_msg = "tl16c750";
 else
-	fifo_msg = "ns16750, working fifo";
+	fifo_msg = "ns16750";
 			}
 		} else
 			fifo_msg = "ns16550, broken fifo";
@@ -647,7 +663,11 @@ fifodelay:
 	 * printing it until now.
 	 */
 	delay(10);
-	aprint_normal(": %s\n", fifo_msg);
+	if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) {
+		aprint_normal(": %s, %d-byte FIFO\n", fifo_msg, sc->sc_fifolen);
+	} else {
+		aprint_normal(": %s\n", fifo_msg);
+	}
 	if (ISSET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE)) {
 		sc->sc_fifolen = 1;
 		aprint_normal_dev(sc->sc_dev, "txfifo disabled\n");

Index: src/sys/dev/ic/comreg.h
diff -u src/sys/dev/ic/comreg.h:1.26 src/sys/dev/ic/comreg.h:1.27
--- src/sys/dev/ic/comreg.h:1.26	Sun Oct 29 14:06:08 2017
+++ 

CVS commit: src/sys/dev/ic

2020-09-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Sep 27 16:44:24 UTC 2020

Modified Files:
src/sys/dev/ic: nvmereg.h

Log Message:
add definition of the bit indicating support for APSTA


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/ic/nvmereg.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/ic/nvmereg.h
diff -u src/sys/dev/ic/nvmereg.h:1.14 src/sys/dev/ic/nvmereg.h:1.15
--- src/sys/dev/ic/nvmereg.h:1.14	Sat Oct  5 23:27:20 2019
+++ src/sys/dev/ic/nvmereg.h	Sun Sep 27 16:44:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmereg.h,v 1.14 2019/10/05 23:27:20 mrg Exp $	*/
+/*	$NetBSD: nvmereg.h,v 1.15 2020/09/27 16:44:24 jdolecek Exp $	*/
 /*	$OpenBSD: nvmereg.h,v 1.10 2016/04/14 11:18:32 dlg Exp $ */
 
 /*
@@ -467,6 +467,7 @@ struct nvm_identify_controller {
 	   Configuration */
 	uint8_t		apsta;		/* Autonomous Power State Transition
 	   Attributes */
+#define	NVME_ID_CTRLR_APSTA_PRESENT	__BIT(0)
 
 	uint16_t	wctemp;		/* Warning Composite Temperature
 	   Threshold */



CVS commit: src/sys/dev/ic

2020-09-24 Thread Ryo Shimizu
Module Name:src
Committed By:   ryo
Date:   Thu Sep 24 09:59:11 UTC 2020

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
no need to swap pt.cmd.cdwXX at nvme_set_number_of_queues(). cmd.cdwXX will be 
swapped in nvme_pt_fill().


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.50 src/sys/dev/ic/nvme.c:1.51
--- src/sys/dev/ic/nvme.c:1.50	Tue Sep 22 11:53:10 2020
+++ src/sys/dev/ic/nvme.c	Thu Sep 24 09:59:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.50 2020/09/22 11:53:10 kardel Exp $	*/
+/*	$NetBSD: nvme.c,v 1.51 2020/09/24 09:59:11 ryo Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.50 2020/09/22 11:53:10 kardel Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.51 2020/09/24 09:59:11 ryo Exp $");
 
 #include 
 #include 
@@ -1624,8 +1624,8 @@ nvme_set_number_of_queues(struct nvme_so
 
 	memset(, 0, sizeof(pt));
 	pt.cmd.opcode = NVM_ADMIN_SET_FEATURES;
-	htolem32(, NVM_FEATURE_NUMBER_OF_QUEUES);
-	htolem32(, ((nq - 1) << 16) | (nq - 1));
+	pt.cmd.cdw10 = NVM_FEATURE_NUMBER_OF_QUEUES;
+	pt.cmd.cdw11 = ((nq - 1) << 16) | (nq - 1);
 
 	memset(, 0, sizeof(state));
 	state.pt = 



CVS commit: src/sys/dev/ic

2020-09-22 Thread Frank Kardel
Module Name:src
Committed By:   kardel
Date:   Tue Sep 22 11:53:10 UTC 2020

Modified Files:
src/sys/dev/ic: ld_nvme.c nvme.c

Log Message:
PR kern/55674:
move name space availability check from ld_nvme.c:ld_nvme_attach()
to nvme.c:nvme_rescan().
this avoids allocation of ld(4) instances for every possible
name space, even if it is not usable. it also reduces the device
node flood generated from that strategy.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ic/ld_nvme.c
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/ic/nvme.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/ic/ld_nvme.c
diff -u src/sys/dev/ic/ld_nvme.c:1.23 src/sys/dev/ic/ld_nvme.c:1.24
--- src/sys/dev/ic/ld_nvme.c:1.23	Tue Oct  1 10:59:49 2019
+++ src/sys/dev/ic/ld_nvme.c	Tue Sep 22 11:53:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_nvme.c,v 1.23 2019/10/01 10:59:49 mlelstv Exp $	*/
+/*	$NetBSD: ld_nvme.c,v 1.24 2020/09/22 11:53:10 kardel Exp $	*/
 
 /*-
  * Copyright (C) 2016 NONAKA Kimihiro 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.23 2019/10/01 10:59:49 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_nvme.c,v 1.24 2020/09/22 11:53:10 kardel Exp $");
 
 #include 
 #include 
@@ -86,7 +86,6 @@ ld_nvme_attach(device_t parent, device_t
 	struct nvme_attach_args *naa = aux;
 	struct nvme_namespace *ns;
 	struct nvm_namespace_format *f;
-	int error;
 
 	ld->sc_dv = self;
 	sc->sc_nvme = nsc;
@@ -95,28 +94,11 @@ ld_nvme_attach(device_t parent, device_t
 	aprint_naive("\n");
 	aprint_normal("\n");
 
-	error = nvme_ns_identify(sc->sc_nvme, sc->sc_nsid);
-	if (error) {
-		aprint_error_dev(self, "couldn't identify namespace\n");
-		return;
-	}
-
 	ns = nvme_ns_get(sc->sc_nvme, sc->sc_nsid);
 	KASSERT(ns);
-	f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
 
-	/*
-	 * NVME1.0e 6.11 Identify command
-	 *
-	 * LBADS values smaller than 9 are not supported, a value
-	 * of zero means that the format is not used.
-	 */
-	if (f->lbads < 9) {
-		if (f->lbads > 0)
-			aprint_error_dev(self,
-			"unsupported logical data size %u\n", f->lbads);
-		return;
-	}
+	f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
+	KASSERT(f->lbads >= 9); /* only valid LBS data sizes allowed here */
 
 	ld->sc_secsize = 1 << f->lbads;
 	ld->sc_secperunit = ns->ident->nsze;

Index: src/sys/dev/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.49 src/sys/dev/ic/nvme.c:1.50
--- src/sys/dev/ic/nvme.c:1.49	Tue Jul 28 15:59:19 2020
+++ src/sys/dev/ic/nvme.c	Tue Sep 22 11:53:10 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.49 2020/07/28 15:59:19 jdolecek Exp $	*/
+/*	$NetBSD: nvme.c,v 1.50 2020/09/22 11:53:10 kardel Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.49 2020/07/28 15:59:19 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.50 2020/09/22 11:53:10 kardel Exp $");
 
 #include 
 #include 
@@ -471,23 +471,52 @@ nvme_rescan(device_t self, const char *a
 {
 	struct nvme_softc *sc = device_private(self);
 	struct nvme_attach_args naa;
+	struct nvm_namespace_format *f;
+	struct nvme_namespace *ns;
 	uint64_t cap;
 	int ioq_entries = nvme_ioq_size;
 	int i;
+	int error;
 
 	cap = nvme_read8(sc, NVME_CAP);
 	if (ioq_entries > NVME_CAP_MQES(cap))
 		ioq_entries = NVME_CAP_MQES(cap);
 
-	for (i = 0; i < sc->sc_nn; i++) {
-		if (sc->sc_namespaces[i].dev)
+	for (i = 1; i <= sc->sc_nn; i++) {
+		if (sc->sc_namespaces[i - 1].dev)
+			continue;
+
+		/* identify to check for availability */
+		error = nvme_ns_identify(sc, i);
+		if (error) {
+			aprint_error_dev(self, "couldn't identify namespace #%d\n", i);
+			continue;
+		}
+
+		ns = nvme_ns_get(sc, i);
+		KASSERT(ns);
+
+		f = >ident->lbaf[NVME_ID_NS_FLBAS(ns->ident->flbas)];
+
+		/*
+		 * NVME1.0e 6.11 Identify command
+		 *
+		 * LBADS values smaller than 9 are not supported, a value
+		 * of zero means that the format is not used.
+		 */
+		if (f->lbads < 9) {
+			if (f->lbads > 0)
+aprint_error_dev(self,
+		 "unsupported logical data size %u\n", f->lbads);
 			continue;
+		}
+
 		memset(, 0, sizeof(naa));
-		naa.naa_nsid = i + 1;
+		naa.naa_nsid = i;
 		naa.naa_qentries = (ioq_entries - 1) * sc->sc_nq;
 		naa.naa_maxphys = sc->sc_mdts;
 		naa.naa_typename = sc->sc_modelname;
-		sc->sc_namespaces[i].dev = config_found(sc->sc_dev, ,
+		sc->sc_namespaces[i - 1].dev = config_found(sc->sc_dev, ,
 		nvme_print);
 	}
 	return 0;



CVS commit: src/sys/dev/ic

2020-09-21 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Sep 21 06:57:00 UTC 2020

Modified Files:
src/sys/dev/ic: rtl8169.c rtl81x9reg.h rtl81x9var.h

Log Message:
- Print chip revision. From OpenBSD.
- Rename RTK_HWREV_8168_SPIN[123] to RTK_HWREV_8168'B'_SPIN[123].
  Same as other *BSDs.
- Rename RTK_HWREV_8168G_SPIN4 to RTK_HWREV_8411B. Same as other *BSDs.
- Add definition of RTK_HWREV_8169_8110SCE.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/ic/rtl8169.c
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/ic/rtl81x9reg.h
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/ic/rtl81x9var.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/ic/rtl8169.c
diff -u src/sys/dev/ic/rtl8169.c:1.166 src/sys/dev/ic/rtl8169.c:1.167
--- src/sys/dev/ic/rtl8169.c:1.166	Fri Mar 13 04:08:07 2020
+++ src/sys/dev/ic/rtl8169.c	Mon Sep 21 06:57:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtl8169.c,v 1.166 2020/03/13 04:08:07 thorpej Exp $	*/
+/*	$NetBSD: rtl8169.c,v 1.167 2020/09/21 06:57:00 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998-2003
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.166 2020/03/13 04:08:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtl8169.c,v 1.167 2020/09/21 06:57:00 msaitoh Exp $");
 /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/re/if_re.c,v 1.20 2004/04/11 20:34:08 ru Exp $ */
 
 /*
@@ -172,6 +172,54 @@ static void re_miibus_statchg(struct ifn
 
 static void re_reset(struct rtk_softc *);
 
+static const struct re_revision {
+	uint32_t		re_chipid;
+	const char		*re_name;
+} re_revisions[] = {
+	{ RTK_HWREV_8100,	"RTL8100" },
+	{ RTK_HWREV_8100E,	"RTL8100E" },
+	{ RTK_HWREV_8100E_SPIN2, "RTL8100E 2" },
+	{ RTK_HWREV_8101,	"RTL8101" },
+	{ RTK_HWREV_8101E,	"RTL8101E" },
+	{ RTK_HWREV_8102E,	"RTL8102E" },
+	{ RTK_HWREV_8106E,	"RTL8106E" },
+	{ RTK_HWREV_8401E,	"RTL8401E" },
+	{ RTK_HWREV_8402,	"RTL8402" },
+	{ RTK_HWREV_8411,	"RTL8411" },
+	{ RTK_HWREV_8411B,	"RTL8411B" },
+	{ RTK_HWREV_8102EL,	"RTL8102EL" },
+	{ RTK_HWREV_8102EL_SPIN1, "RTL8102EL 1" },
+	{ RTK_HWREV_8103E,   "RTL8103E" },
+	{ RTK_HWREV_8110S,	"RTL8110S" },
+	{ RTK_HWREV_8139CPLUS,	"RTL8139C+" },
+	{ RTK_HWREV_8168B_SPIN1, "RTL8168 1" },
+	{ RTK_HWREV_8168B_SPIN2, "RTL8168 2" },
+	{ RTK_HWREV_8168B_SPIN3, "RTL8168 3" },
+	{ RTK_HWREV_8168C,	"RTL8168C/8111C" },
+	{ RTK_HWREV_8168C_SPIN2, "RTL8168C/8111C" },
+	{ RTK_HWREV_8168CP,	"RTL8168CP/8111CP" },
+	{ RTK_HWREV_8168F,	"RTL8168F/8111F" },
+	{ RTK_HWREV_8168G,	"RTL8168G/8111G" },
+	{ RTK_HWREV_8168GU,	"RTL8168GU/8111GU" },
+	{ RTK_HWREV_8168H,	"RTL8168H/8111H" },
+	{ RTK_HWREV_8105E,	"RTL8105E" },
+	{ RTK_HWREV_8105E_SPIN1, "RTL8105E" },
+	{ RTK_HWREV_8168D,	"RTL8168D/8111D" },
+	{ RTK_HWREV_8168DP,	"RTL8168DP/8111DP" },
+	{ RTK_HWREV_8168E,	"RTL8168E/8111E" },
+	{ RTK_HWREV_8168E_VL,	"RTL8168E/8111E-VL" },
+	{ RTK_HWREV_8168EP,	"RTL8168EP/8111EP" },
+	{ RTK_HWREV_8168FP,	"RTL8168FP/8117" },
+	{ RTK_HWREV_8169,	"RTL8169" },
+	{ RTK_HWREV_8169_8110SB, "RTL8169/8110SB" },
+	{ RTK_HWREV_8169_8110SBL, "RTL8169SBL" },
+	{ RTK_HWREV_8169_8110SC, "RTL8169/8110SCd" },
+	{ RTK_HWREV_8169_8110SCE, "RTL8169/8110SCe" },
+	{ RTK_HWREV_8169S,	"RTL8169S" },
+
+	{ 0, NULL }
+};
+
 static inline void
 re_set_bufaddr(struct re_desc *d, bus_addr_t addr)
 {
@@ -559,13 +607,26 @@ re_attach(struct rtk_softc *sc)
 	struct ifnet *ifp;
 	struct mii_data *mii = >mii;
 	int error = 0, i;
+	const struct re_revision *rr;
+	const char *re_name = NULL;
 
 	if ((sc->sc_quirk & RTKQ_8139CPLUS) == 0) {
-		uint32_t hwrev;
-
 		/* Revision of 8169/8169S/8110s in bits 30..26, 23 */
-		hwrev = CSR_READ_4(sc, RTK_TXCFG) & RTK_TXCFG_HWREV;
-		switch (hwrev) {
+		sc->sc_hwrev = CSR_READ_4(sc, RTK_TXCFG) & RTK_TXCFG_HWREV;
+
+		for (rr = re_revisions; rr->re_name != NULL; rr++) {
+			if (rr->re_chipid == sc->sc_hwrev)
+re_name = rr->re_name;
+		}
+
+		if (re_name == NULL)
+			aprint_normal_dev(sc->sc_dev,
+			"unknown ASIC (0x%04x)\n", sc->sc_hwrev >> 16);
+		else
+			aprint_normal_dev(sc->sc_dev,
+			"%s (0x%04x)\n", re_name, sc->sc_hwrev >> 16);
+
+		switch (sc->sc_hwrev) {
 		case RTK_HWREV_8169:
 			sc->sc_quirk |= RTKQ_8169NONS;
 			break;
@@ -576,9 +637,9 @@ re_attach(struct rtk_softc *sc)
 		case RTK_HWREV_8169_8110SC:
 			sc->sc_quirk |= RTKQ_MACLDPS;
 			break;
-		case RTK_HWREV_8168_SPIN1:
-		case RTK_HWREV_8168_SPIN2:
-		case RTK_HWREV_8168_SPIN3:
+		case RTK_HWREV_8168B_SPIN1:
+		case RTK_HWREV_8168B_SPIN2:
+		case RTK_HWREV_8168B_SPIN3:
 			sc->sc_quirk |= RTKQ_MACSTAT;
 			break;
 		case RTK_HWREV_8168C:
@@ -625,7 +686,7 @@ re_attach(struct rtk_softc *sc)
 		case RTK_HWREV_8168G:
 		case RTK_HWREV_8168G_SPIN1:
 		case RTK_HWREV_8168G_SPIN2:
-		case RTK_HWREV_8168G_SPIN4:
+		case RTK_HWREV_8411B:
 			sc->sc_quirk |= RTKQ_DESCV2 | RTKQ_NOEECMD |
 			RTKQ_MACSTAT | RTKQ_CMDSTOP | RTKQ_NOJUMBO | 
 			RTKQ_RXDV_GATED;
@@ -647,7 +708,7 @@ 

CVS commit: src/sys/dev/ic

2020-09-15 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Sep 15 17:21:39 UTC 2020

Modified Files:
src/sys/dev/ic: mpt_netbsd.c

Log Message:
max_devices is a 8bit value and zero is interpreted as 256. This value
can be reported by an mpt device emulated by VMware ESXi.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/ic/mpt_netbsd.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/ic/mpt_netbsd.c
diff -u src/sys/dev/ic/mpt_netbsd.c:1.36 src/sys/dev/ic/mpt_netbsd.c:1.37
--- src/sys/dev/ic/mpt_netbsd.c:1.36	Wed May  8 06:32:01 2019
+++ src/sys/dev/ic/mpt_netbsd.c	Tue Sep 15 17:21:39 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpt_netbsd.c,v 1.36 2019/05/08 06:32:01 cnst Exp $	*/
+/*	$NetBSD: mpt_netbsd.c,v 1.37 2020/09/15 17:21:39 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.36 2019/05/08 06:32:01 cnst Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpt_netbsd.c,v 1.37 2020/09/15 17:21:39 mlelstv Exp $");
 
 #include "bio.h"
 
@@ -150,7 +150,7 @@ mpt_scsipi_attach(mpt_softc_t *mpt)
 	chan->chan_channel = 0;
 	chan->chan_flags = 0;
 	chan->chan_nluns = 8;
-	chan->chan_ntargets = mpt->mpt_max_devices;
+	chan->chan_ntargets = mpt->mpt_max_devices ? mpt->mpt_max_devices : 256;
 	chan->chan_id = mpt->mpt_ini_id;
 
 	/*



CVS commit: src/sys/dev/ic

2020-09-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  7 10:45:23 UTC 2020

Modified Files:
src/sys/dev/ic: arn5008.c

Log Message:
in ar5008_set_viterbi_mask() be sure to initialise m[0].


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/ic/arn5008.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/ic/arn5008.c
diff -u src/sys/dev/ic/arn5008.c:1.17 src/sys/dev/ic/arn5008.c:1.18
--- src/sys/dev/ic/arn5008.c:1.17	Wed Jan 29 14:09:58 2020
+++ src/sys/dev/ic/arn5008.c	Mon Sep  7 10:45:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: arn5008.c,v 1.17 2020/01/29 14:09:58 thorpej Exp $	*/
+/*	$NetBSD: arn5008.c,v 1.18 2020/09/07 10:45:23 mrg Exp $	*/
 /*	$OpenBSD: ar5008.c,v 1.21 2012/08/25 12:14:31 kettenis Exp $	*/
 
 /*-
@@ -24,7 +24,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: arn5008.c,v 1.17 2020/01/29 14:09:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arn5008.c,v 1.18 2020/09/07 10:45:23 mrg Exp $");
 
 #include 
 #include 
@@ -2287,7 +2287,7 @@ ar5008_set_viterbi_mask(struct athn_soft
 	/* Compute viterbi mask. */
 	for (cur = 6100; cur >= 0; cur -= 100)
 		p[+cur / 100] = abs(cur - bin) < 75;
-	for (cur = -100; cur >= -6100; cur -= 100)
+	for (cur = 0; cur >= -6100; cur -= 100)
 		m[-cur / 100] = abs(cur - bin) < 75;
 
 	/* Write viterbi mask (XXX needs to be reworked). */



CVS commit: src/sys/dev/ic

2020-09-06 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Sep  7 00:32:28 UTC 2020

Modified Files:
src/sys/dev/ic: nslm7x.c

Log Message:
don't call printf %s with a NULL.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/dev/ic/nslm7x.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/ic/nslm7x.c
diff -u src/sys/dev/ic/nslm7x.c:1.73 src/sys/dev/ic/nslm7x.c:1.74
--- src/sys/dev/ic/nslm7x.c:1.73	Wed Jul 10 16:23:55 2019
+++ src/sys/dev/ic/nslm7x.c	Mon Sep  7 00:32:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nslm7x.c,v 1.73 2019/07/10 16:23:55 msaitoh Exp $ */
+/*	$NetBSD: nslm7x.c,v 1.74 2020/09/07 00:32:28 mrg Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.73 2019/07/10 16:23:55 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nslm7x.c,v 1.74 2020/09/07 00:32:28 mrg Exp $");
 
 #include 
 #include 
@@ -2556,7 +2556,8 @@ wb_attach(struct lm_softc *sc)
 	DPRINTF(("%s: winbond chip id 0x%x\n", __func__, sc->chipid));
 
 	if ((prod = wb_lookup(sc, wb_products, sc->chipid)) != NULL) {
-		switch (prod->str[0]) {
+		model = prod->str;
+		switch (model[0]) {
 		case 'W':
 			vendor = "Winbond";
 			break;
@@ -2570,7 +2571,6 @@ wb_attach(struct lm_softc *sc)
 			aprint_error_dev(dev, "Unknown model (%s)\n", model);
 			return -1;
 		}
-		model = prod->str;
 		sensors = prod->sensors;
 		sc->refresh_sensor_data = wb_refresh_sensor_data;
 		if (prod->extattach != NULL)



CVS commit: src/sys/dev/ic

2020-08-14 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Aug 14 09:28:29 UTC 2020

Modified Files:
src/sys/dev/ic: ld_icp.c

Log Message:
fix a bit that I missed in the device_t/softc split 8 years ago.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/dev/ic/ld_icp.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/ic/ld_icp.c
diff -u src/sys/dev/ic/ld_icp.c:1.31 src/sys/dev/ic/ld_icp.c:1.32
--- src/sys/dev/ic/ld_icp.c:1.31	Mon Feb 27 21:32:33 2017
+++ src/sys/dev/ic/ld_icp.c	Fri Aug 14 09:28:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ld_icp.c,v 1.31 2017/02/27 21:32:33 jdolecek Exp $	*/
+/*	$NetBSD: ld_icp.c,v 1.32 2020/08/14 09:28:29 chs Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ld_icp.c,v 1.31 2017/02/27 21:32:33 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_icp.c,v 1.32 2020/08/14 09:28:29 chs Exp $");
 
 #include 
 #include 
@@ -167,11 +167,12 @@ ld_icp_attach(device_t parent, device_t 
 static int
 ld_icp_detach(device_t dv, int flags)
 {
+	struct ld_softc *ldsc = device_private(dv);
 	int rv;
 
-	if ((rv = ldbegindetach((struct ld_softc *)dv, flags)) != 0)
+	if ((rv = ldbegindetach(ldsc, flags)) != 0)
 		return (rv);
-	ldenddetach((struct ld_softc *) dv);
+	ldenddetach(ldsc);
 
 	return (0);
 }
@@ -345,7 +346,7 @@ static void
 ld_icp_adjqparam(device_t dv, int openings)
 {
 
-	ldadjqparam((struct ld_softc *) dv, openings);
+	ldadjqparam(device_private(dv), openings);
 }
 
 MODULE(MODULE_CLASS_DRIVER, ld_icp, "ld");	/* no icp module yet */



CVS commit: src/sys/dev/ic

2020-08-14 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Fri Aug 14 09:26:40 UTC 2020

Modified Files:
src/sys/dev/ic: icp.c

Log Message:
restore the initialization of icp->icp_ccbs that I removed by mistake.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/ic/icp.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/ic/icp.c
diff -u src/sys/dev/ic/icp.c:1.33 src/sys/dev/ic/icp.c:1.34
--- src/sys/dev/ic/icp.c:1.33	Sun Nov 10 21:16:35 2019
+++ src/sys/dev/ic/icp.c	Fri Aug 14 09:26:40 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: icp.c,v 1.33 2019/11/10 21:16:35 chs Exp $	*/
+/*	$NetBSD: icp.c,v 1.34 2020/08/14 09:26:40 chs Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: icp.c,v 1.33 2019/11/10 21:16:35 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icp.c,v 1.34 2020/08/14 09:26:40 chs Exp $");
 
 #include 
 #include 
@@ -179,6 +179,7 @@ icp_init(struct icp_softc *icp, const ch
 	 * Allocate and initialize the command control blocks.
 	 */
 	ic = malloc(sizeof(*ic) * ICP_NCCBS, M_DEVBUF, M_WAITOK | M_ZERO);
+	icp->icp_ccbs = ic;
 	state++;
 
 	for (i = 0; i < ICP_NCCBS; i++, ic++) {



CVS commit: src/sys/dev/ic

2020-07-28 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jul 28 15:59:19 UTC 2020

Modified Files:
src/sys/dev/ic: nvme.c

Log Message:
say what is not configured in nvme_print()


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/dev/ic/nvme.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/ic/nvme.c
diff -u src/sys/dev/ic/nvme.c:1.48 src/sys/dev/ic/nvme.c:1.49
--- src/sys/dev/ic/nvme.c:1.48	Tue Apr  7 07:25:41 2020
+++ src/sys/dev/ic/nvme.c	Tue Jul 28 15:59:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme.c,v 1.48 2020/04/07 07:25:41 ryo Exp $	*/
+/*	$NetBSD: nvme.c,v 1.49 2020/07/28 15:59:19 jdolecek Exp $	*/
 /*	$OpenBSD: nvme.c,v 1.49 2016/04/18 05:59:50 dlg Exp $ */
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.48 2020/04/07 07:25:41 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme.c,v 1.49 2020/07/28 15:59:19 jdolecek Exp $");
 
 #include 
 #include 
@@ -499,7 +499,7 @@ nvme_print(void *aux, const char *pnp)
 	struct nvme_attach_args *naa = aux;
 
 	if (pnp)
-		aprint_normal("at %s", pnp);
+		aprint_normal("ld at %s", pnp);
 
 	if (naa->naa_nsid > 0)
 		aprint_normal(" nsid %d", naa->naa_nsid);



CVS commit: src/sys/dev/ic

2020-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 22 17:23:52 UTC 2020

Modified Files:
src/sys/dev/ic: bwfm.c bwfmvar.h

Log Message:
bwfm: Switch from pcq to pool_cache.

pcq_get is required to be serialized, but it's far from clear that it
is serialized here.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ic/bwfm.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/ic/bwfmvar.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.28 src/sys/dev/ic/bwfm.c:1.29
--- src/sys/dev/ic/bwfm.c:1.28	Wed Jul 22 17:21:25 2020
+++ src/sys/dev/ic/bwfm.c	Wed Jul 22 17:23:52 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.28 2020/07/22 17:21:25 riastradh Exp $ */
+/* $NetBSD: bwfm.c,v 1.29 2020/07/22 17:23:52 riastradh Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
@@ -319,7 +319,6 @@ bwfm_attach(struct bwfm_softc *sc)
 {
 	struct ieee80211com *ic = >sc_ic;
 	struct ifnet *ifp = >sc_if;
-	struct bwfm_task *t;
 	char fw_version[BWFM_DCMD_SMLEN];
 	uint32_t bandlist[3];
 	uint32_t tmp;
@@ -331,12 +330,10 @@ bwfm_attach(struct bwfm_softc *sc)
 		printf("%s: could not create workqueue\n", DEVNAME(sc));
 		return;
 	}
-	sc->sc_freetask = pcq_create(BWFM_TASK_COUNT, KM_SLEEP);
-	for (i = 0; i < BWFM_TASK_COUNT; i++) {
-		t = >sc_task[i];
-		t->t_sc = sc;
-		pcq_put(sc->sc_freetask, t);
-	}
+	sc->sc_freetask = pool_cache_init(sizeof(struct bwfm_task), 0, 0, 0,
+	"bwfmtask", NULL, IPL_NET /* XXX IPL_SOFTNET? */,
+	NULL, NULL, NULL);
+	pool_cache_prime(sc->sc_freetask, BWFM_TASK_COUNT);
 
 	/* Stop the device in case it was previously initialized */
 	bwfm_fwvar_cmd_set_int(sc, BWFM_C_DOWN, 1);
@@ -429,7 +426,7 @@ bwfm_attach(struct bwfm_softc *sc)
 	error = if_initialize(ifp);
 	if (error != 0) {
 		printf("%s: if_initialize failed(%d)\n", DEVNAME(sc), error);
-		pcq_destroy(sc->sc_freetask);
+		pool_cache_destroy(sc->sc_freetask);
 		workqueue_destroy(sc->sc_taskq);
 
 		return; /* Error */
@@ -469,7 +466,7 @@ bwfm_detach(struct bwfm_softc *sc, int f
 	if (sc->sc_taskq)
 		workqueue_destroy(sc->sc_taskq);
 	if (sc->sc_freetask)
-		pcq_destroy(sc->sc_freetask);
+		pool_cache_destroy(sc->sc_freetask);
 
 	return 0;
 }
@@ -780,12 +777,13 @@ bwfm_key_set(struct ieee80211com *ic, co
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return 0;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_KEY_SET;
 	t->t_key.key = wk;
 	memcpy(t->t_key.mac, mac, sizeof(t->t_key.mac));
@@ -871,12 +869,13 @@ bwfm_key_delete(struct ieee80211com *ic,
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return 0;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_KEY_DELETE;
 	t->t_key.key = wk;
 	memset(t->t_key.mac, 0, sizeof(t->t_key.mac));
@@ -905,12 +904,13 @@ bwfm_newstate(struct ieee80211com *ic, e
 	struct bwfm_softc *sc = ic->ic_ifp->if_softc;
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return EIO;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_NEWSTATE;
 	t->t_newstate.state = nstate;
 	t->t_newstate.arg = arg;
@@ -988,7 +988,7 @@ bwfm_task(struct work *wk, void *arg)
 		panic("bwfm: unknown task command %d", t->t_cmd);
 	}
 
-	pcq_put(sc->sc_freetask, t);
+	pool_cache_put(sc->sc_freetask, t);
 }
 
 int
@@ -2086,13 +2086,14 @@ bwfm_rx_event(struct bwfm_softc *sc, str
 {
 	struct bwfm_task *t;
 
-	t = pcq_get(sc->sc_freetask);
+	t = pool_cache_get(sc->sc_freetask, PR_NOWAIT);
 	if (t == NULL) {
 		m_freem(m);
 		printf("%s: no free tasks\n", DEVNAME(sc));
 		return;
 	}
 
+	t->t_sc = sc;
 	t->t_cmd = BWFM_TASK_RX_EVENT;
 	t->t_mbuf = m;
 	workqueue_enqueue(sc->sc_taskq, (struct work*)t, NULL);

Index: src/sys/dev/ic/bwfmvar.h
diff -u src/sys/dev/ic/bwfmvar.h:1.11 src/sys/dev/ic/bwfmvar.h:1.12
--- src/sys/dev/ic/bwfmvar.h:1.11	Wed Jul 22 17:21:25 2020
+++ src/sys/dev/ic/bwfmvar.h	Wed Jul 22 17:23:52 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfmvar.h,v 1.11 2020/07/22 17:21:25 riastradh Exp $ */
+/* $NetBSD: bwfmvar.h,v 1.12 2020/07/22 17:23:52 riastradh Exp $ */
 /* $OpenBSD: bwfmvar.h,v 1.1 2017/10/11 17:19:50 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -24,7 +24,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 
@@ -36,6 +35,7 @@
 
 struct ieee80211_key;
 struct mbuf;
+struct 

CVS commit: src/sys/dev/ic

2020-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 22 17:21:26 UTC 2020

Modified Files:
src/sys/dev/ic: bwfm.c bwfmreg.h bwfmvar.h

Log Message:
Add include guards and appropriate includes to bwfmreg.h, bwfmvar.h.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/ic/bwfm.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/bwfmreg.h
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/ic/bwfmvar.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.27 src/sys/dev/ic/bwfm.c:1.28
--- src/sys/dev/ic/bwfm.c:1.27	Wed Jul 22 17:18:49 2020
+++ src/sys/dev/ic/bwfm.c	Wed Jul 22 17:21:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.27 2020/07/22 17:18:49 riastradh Exp $ */
+/* $NetBSD: bwfm.c,v 1.28 2020/07/22 17:21:25 riastradh Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -40,6 +40,8 @@
 
 #include 
 
+#include 
+
 #include 
 #include 
 

Index: src/sys/dev/ic/bwfmreg.h
diff -u src/sys/dev/ic/bwfmreg.h:1.6 src/sys/dev/ic/bwfmreg.h:1.7
--- src/sys/dev/ic/bwfmreg.h:1.6	Mon Oct 28 06:37:51 2019
+++ src/sys/dev/ic/bwfmreg.h	Wed Jul 22 17:21:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfmreg.h,v 1.6 2019/10/28 06:37:51 mlelstv Exp $ */
+/* $NetBSD: bwfmreg.h,v 1.7 2020/07/22 17:21:25 riastradh Exp $ */
 /* $OpenBSD: bwfmreg.h,v 1.16 2018/02/07 21:44:09 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -17,6 +17,19 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifndef	_DEV_IC_BWFMREG_H
+#define	_DEV_IC_BWFMREG_H
+
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include 
+
 /* SDIO registers */
 #define BWFM_SDIO_FUNC1_SBADDRLOW		0x1000A
 #define BWFM_SDIO_FUNC1_SBADDRMID		0x1000B
@@ -785,3 +798,5 @@ struct bwfm_event {
 	struct bwfm_ethhdr hdr;
 	struct bwfm_event_msg msg;
 } __packed;
+
+#endif	/* _DEV_IC_BWFMREG_H */

Index: src/sys/dev/ic/bwfmvar.h
diff -u src/sys/dev/ic/bwfmvar.h:1.10 src/sys/dev/ic/bwfmvar.h:1.11
--- src/sys/dev/ic/bwfmvar.h:1.10	Sat May 30 15:55:47 2020
+++ src/sys/dev/ic/bwfmvar.h	Wed Jul 22 17:21:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfmvar.h,v 1.10 2020/05/30 15:55:47 jdolecek Exp $ */
+/* $NetBSD: bwfmvar.h,v 1.11 2020/07/22 17:21:25 riastradh Exp $ */
 /* $OpenBSD: bwfmvar.h,v 1.1 2017/10/11 17:19:50 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -17,8 +17,25 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#ifndef	_DEV_IC_BWFMVAR_H
+#define	_DEV_IC_BWFMVAR_H
+
+#include 
+
+#include 
+#include 
 #include 
-#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+
+struct ieee80211_key;
+struct mbuf;
 
 /* Chipcommon Core Chip IDs */
 #define BRCM_CC_43143_CHIP_ID		43143
@@ -245,3 +262,5 @@ void	bwfm_firmware_close(struct bwfm_fir
 void *	bwfm_firmware_data(struct bwfm_firmware_context *,
 	unsigned int, size_t *);
 const char *bwfm_firmware_description(unsigned int);
+
+#endif	/* _DEV_IC_BWFMVAR_H */



CVS commit: src/sys/dev/ic

2020-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jul 22 17:18:49 UTC 2020

Modified Files:
src/sys/dev/ic: bwfm.c

Log Message:
Sort #includes.  Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/ic/bwfm.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.26 src/sys/dev/ic/bwfm.c:1.27
--- src/sys/dev/ic/bwfm.c:1.26	Mon Jul 13 05:38:52 2020
+++ src/sys/dev/ic/bwfm.c	Wed Jul 22 17:18:49 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.26 2020/07/13 05:38:52 mrg Exp $ */
+/* $NetBSD: bwfm.c,v 1.27 2020/07/22 17:18:49 riastradh Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -18,21 +18,23 @@
  */
 
 #include 
-#include 
+#include 
+
 #include 
-#include 
 #include 
+#include 
+#include 
+#include 
 #include 
 #include 
-#include 
+#include 
 #include 
-#include 
 
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 
 #include 
 
@@ -381,7 +383,7 @@ bwfm_attach(struct bwfm_softc *sc)
 	sizeof(bandlist))) {
 		printf("%s: couldn't get supported band list\n", DEVNAME(sc));
 		return;
-	} 
+	}
 	const u_int nbands = le32toh(bandlist[0]);
 	for (i = 1; i <= MIN(nbands, __arraycount(bandlist) - 1); i++) {
 		switch (le32toh(bandlist[i])) {
@@ -430,7 +432,7 @@ bwfm_attach(struct bwfm_softc *sc)
 
 		return; /* Error */
 	}
-		
+
 	ieee80211_ifattach(ic);
 	sc->sc_newstate = ic->ic_newstate;
 	ic->ic_newstate = bwfm_newstate;
@@ -579,7 +581,7 @@ bwfm_init(struct ifnet *ifp)
 #ifdef BWFM_DEBUG
 	memset(evmask, 0xff, sizeof(evmask));
 #endif
-	
+
 	if (bwfm_fwvar_var_set_data(sc, "event_msgs", evmask, sizeof(evmask))) {
 		printf("%s: could not set event mask\n", DEVNAME(sc));
 		return EIO;



CVS commit: src/sys/dev/ic

2020-07-16 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Jul 16 14:41:04 UTC 2020

Modified Files:
src/sys/dev/ic: cissreg.h

Log Message:
make sure the alignment of ciss_cmd matches KASSERT() in ciss_cmd()


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/ic/cissreg.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/ic/cissreg.h
diff -u src/sys/dev/ic/cissreg.h:1.9 src/sys/dev/ic/cissreg.h:1.10
--- src/sys/dev/ic/cissreg.h:1.9	Thu Jul 16 14:39:33 2020
+++ src/sys/dev/ic/cissreg.h	Thu Jul 16 14:41:04 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cissreg.h,v 1.9 2020/07/16 14:39:33 jdolecek Exp $	*/
+/*	$NetBSD: cissreg.h,v 1.10 2020/07/16 14:41:04 jdolecek Exp $	*/
 /*	$OpenBSD: cissreg.h,v 1.11 2010/06/03 01:02:13 dlg Exp $	*/
 
 /*
@@ -535,8 +535,9 @@ struct ciss_ccb {
 	uint8_t			ccb_sg_tag;
 
 	struct ciss_error	ccb_err;
-	struct ciss_cmd		ccb_cmd __aligned(8);	/* followed by sgl */
+	struct ciss_cmd		ccb_cmd __aligned(16);	/* followed by sgl */
 };
+CTASSERT((offsetof(struct ciss_ccb, ccb_cmd) & 0xf) == 0);
 
 typedef TAILQ_HEAD(ciss_queue_head, ciss_ccb) ciss_queue_head;
 



CVS commit: src/sys/dev/ic

2020-07-16 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu Jul 16 14:39:33 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c cissreg.h

Log Message:
revert the conversion to STAILQ, it broke execution of commands


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/dev/ic/ciss.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ic/cissreg.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.49 src/sys/dev/ic/ciss.c:1.50
--- src/sys/dev/ic/ciss.c:1.49	Tue Jul 14 12:04:46 2020
+++ src/sys/dev/ic/ciss.c	Thu Jul 16 14:39:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.49 2020/07/14 12:04:46 jdolecek Exp $	*/
+/*	$NetBSD: ciss.c,v 1.50 2020/07/16 14:39:33 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.49 2020/07/14 12:04:46 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.50 2020/07/16 14:39:33 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -104,8 +104,8 @@ ciss_get_ccb(struct ciss_softc *sc)
 	struct ciss_ccb *ccb;
 
 	mutex_enter(>sc_mutex);
-	if ((ccb = STAILQ_FIRST(>sc_free_ccb))) {
-		STAILQ_REMOVE_HEAD(>sc_free_ccb, ccb_link);
+	if ((ccb = TAILQ_LAST(>sc_free_ccb, ciss_queue_head))) {
+		TAILQ_REMOVE(>sc_free_ccb, ccb, ccb_link);
 		ccb->ccb_state = CISS_CCB_READY;
 	}
 	mutex_exit(>sc_mutex);
@@ -117,7 +117,7 @@ ciss_put_ccb(struct ciss_softc *sc, stru
 {
 	ccb->ccb_state = CISS_CCB_FREE;
 	mutex_enter(>sc_mutex);
-	STAILQ_INSERT_HEAD(>sc_free_ccb, ccb, ccb_link);
+	TAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
 	mutex_exit(>sc_mutex);
 }
 
@@ -339,7 +339,7 @@ ciss_attach(struct ciss_softc *sc)
 		return -1;
 	}
 
-	STAILQ_INIT(>sc_free_ccb);
+	TAILQ_INIT(>sc_free_ccb);
 
 	maxfer = sc->maxsg * PAGE_SIZE;
 	for (i = 0; total > 0 && i < sc->maxcmd; i++, total -= sc->ccblen) {
@@ -363,7 +363,7 @@ ciss_attach(struct ciss_softc *sc)
 		>ccb_dmamap)))
 			break;
 
-		STAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
+		TAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
 	}
 
 	if (i < sc->maxcmd) {
@@ -536,7 +536,7 @@ ciss_enqueue(struct ciss_softc *sc, ciss
 	ccb = (struct ciss_ccb *) ((char *)sc->ccbs + (id >> 2) * sc->ccblen);
 	ccb->ccb_cmd.id = htole32(id);
 	ccb->ccb_cmd.id_hi = htole32(0);
-	STAILQ_INSERT_TAIL(q, ccb, ccb_link);
+	TAILQ_INSERT_TAIL(q, ccb, ccb_link);
 }
 
 static void
@@ -606,7 +606,7 @@ ciss_poll(struct ciss_softc *sc, struct 
 	ciss_queue_head q;
 	struct ciss_ccb *ccb1;
 
-	STAILQ_INIT();
+	TAILQ_INIT();
 	ms /= 10;
 
 	while (ms-- > 0) {
@@ -618,14 +618,14 @@ ciss_poll(struct ciss_softc *sc, struct 
 			ciss_completed_simple(sc, );
 		mutex_exit(>sc_mutex);
 
-		while (!STAILQ_EMPTY()) {
-			ccb1 = STAILQ_FIRST();
-			STAILQ_REMOVE_HEAD(, ccb_link);
+		while (!TAILQ_EMPTY()) {
+			ccb1 = TAILQ_FIRST();
+			TAILQ_REMOVE(, ccb1, ccb_link);
 
 			KASSERT(ccb1->ccb_state == CISS_CCB_ONQ);
 			ciss_done(sc, ccb1);
 			if (ccb1 == ccb) {
-KASSERT(STAILQ_EMPTY());
+KASSERT(TAILQ_EMPTY());
 return 0;
 			}
 		}
@@ -1249,9 +1249,9 @@ ciss_completed_process(struct ciss_softc
 {
 	struct ciss_ccb *ccb;
 
-	while (!STAILQ_EMPTY(q)) {
-		ccb = STAILQ_FIRST(q);
-		STAILQ_REMOVE_HEAD(q, ccb_link);
+	while (!TAILQ_EMPTY(q)) {
+		ccb = TAILQ_FIRST(q);
+		TAILQ_REMOVE(q, ccb, ccb_link);
 
 		if (ccb->ccb_state == CISS_CCB_POLL) {
 			ccb->ccb_state = CISS_CCB_ONQ;
@@ -1276,15 +1276,15 @@ ciss_intr_simple_intx(void *v)
 	if (!(bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_ISR) & sc->iem))
 		return 0;
 
-	STAILQ_INIT();
+	TAILQ_INIT();
 	mutex_enter(>sc_mutex);
 	ciss_completed_simple(sc, );
 	mutex_exit(>sc_mutex);
 
-	hit = (!STAILQ_EMPTY());
+	hit = (!TAILQ_EMPTY());
 	ciss_completed_process(sc, );
 
-	KASSERT(STAILQ_EMPTY());
+	KASSERT(TAILQ_EMPTY());
 	CISS_DPRINTF(CISS_D_INTR, ("exit\n"));
 
 	return hit;
@@ -1314,14 +1314,14 @@ ciss_intr_perf_msi(void *v)
 
 	CISS_DPRINTF(CISS_D_INTR, ("intr "));
 
-	STAILQ_INIT();
+	TAILQ_INIT();
 	mutex_enter(>sc_mutex);
 	ciss_completed_perf(sc, );
 	mutex_exit(>sc_mutex);
 
 	ciss_completed_process(sc, );
 
-	KASSERT(STAILQ_EMPTY());
+	KASSERT(TAILQ_EMPTY());
 	CISS_DPRINTF(CISS_D_INTR, ("exit"));
 
 	return 1;

Index: src/sys/dev/ic/cissreg.h
diff -u src/sys/dev/ic/cissreg.h:1.8 src/sys/dev/ic/cissreg.h:1.9
--- src/sys/dev/ic/cissreg.h:1.8	Tue Jul 14 11:44:52 2020
+++ src/sys/dev/ic/cissreg.h	Thu Jul 16 14:39:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cissreg.h,v 1.8 2020/07/14 11:44:52 jdolecek Exp $	*/
+/*	$NetBSD: cissreg.h,v 1.9 2020/07/16 14:39:33 jdolecek Exp $	*/
 /*	$OpenBSD: cissreg.h,v 1.11 2010/06/03 01:02:13 dlg Exp $	*/
 
 /*
@@ -516,7 +516,7 @@ struct ciss_error {
 } __packed;
 
 struct ciss_ccb {
-	STAILQ_ENTRY(ciss_ccb)	ccb_link;
+	TAILQ_ENTRY(ciss_ccb)	ccb_link;
 	paddr_t			ccb_cmdpa;
 	enum {
 		CISS_CCB_FREE	= 0x01,
@@ -538,5 +538,5 @@ struct ciss_ccb 

CVS commit: src/sys/dev/ic

2020-07-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jul 15 14:33:59 UTC 2020

Modified Files:
src/sys/dev/ic: cissvar.h

Log Message:
g/c unused sc_channel_raw, sc_adapter_raw


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/ic/cissvar.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/ic/cissvar.h
diff -u src/sys/dev/ic/cissvar.h:1.10 src/sys/dev/ic/cissvar.h:1.11
--- src/sys/dev/ic/cissvar.h:1.10	Tue Jul 14 12:04:46 2020
+++ src/sys/dev/ic/cissvar.h	Wed Jul 15 14:33:58 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cissvar.h,v 1.10 2020/07/14 12:04:46 jdolecek Exp $	*/
+/*	$NetBSD: cissvar.h,v 1.11 2020/07/15 14:33:58 jdolecek Exp $	*/
 /*	$OpenBSD: cissvar.h,v 1.15 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -47,9 +47,7 @@ struct ciss_softc {
 	int			sc_flush;
 
 	struct scsipi_channel	sc_channel;
-	struct scsipi_channel	*sc_channel_raw;
 	struct scsipi_adapter	sc_adapter;
-	struct scsipi_adapter	*sc_adapter_raw;
 	struct callout		sc_hb;
 
 	u_int	sc_flags;



CVS commit: src/sys/dev/ic

2020-07-14 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Wed Jul 15 01:42:27 UTC 2020

Modified Files:
src/sys/dev/ic: gem.c

Log Message:
G.C. comment.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/dev/ic/gem.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/ic/gem.c
diff -u src/sys/dev/ic/gem.c:1.130 src/sys/dev/ic/gem.c:1.131
--- src/sys/dev/ic/gem.c:1.130	Sun Mar 15 22:19:00 2020
+++ src/sys/dev/ic/gem.c	Wed Jul 15 01:42:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: gem.c,v 1.130 2020/03/15 22:19:00 thorpej Exp $ */
+/*	$NetBSD: gem.c,v 1.131 2020/07/15 01:42:27 msaitoh Exp $ */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.130 2020/03/15 22:19:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gem.c,v 1.131 2020/07/15 01:42:27 msaitoh Exp $");
 
 #include "opt_inet.h"
 
@@ -880,7 +880,7 @@ gem_reset_tx(struct gem_softc *sc)
 	bus_space_barrier(t, h, GEM_TX_CONFIG, 4, BUS_SPACE_BARRIER_WRITE);
 	/* Wait till it finishes */
 	if (!gem_bitwait(sc, h, GEM_TX_CONFIG, 1, 0))
-		aprint_error_dev(sc->sc_dev, "cannot disable tx dma\n"); /* OpenBSD 1.34 */
+		aprint_error_dev(sc->sc_dev, "cannot disable tx dma\n");
 	/* Wait 5ms extra. */
 	delay(5000);
 
@@ -889,7 +889,7 @@ gem_reset_tx(struct gem_softc *sc)
 	bus_space_barrier(t, h, GEM_RESET, 4, BUS_SPACE_BARRIER_WRITE);
 	/* Wait till it finishes */
 	if (!gem_bitwait(sc, h2, GEM_RESET, GEM_RESET_TX, 0)) {
-		aprint_error_dev(sc->sc_dev, "cannot reset transmitter\n"); /* OpenBSD 1.34 */
+		aprint_error_dev(sc->sc_dev, "cannot reset transmitter\n");
 		return (1);
 	}
 	return (0);



CVS commit: src/sys/dev/ic

2020-07-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jul 14 11:44:53 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c cissreg.h

Log Message:
remove ccb_sc to save memory, no need to store pointer to sc in ccb


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/dev/ic/ciss.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/cissreg.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.47 src/sys/dev/ic/ciss.c:1.48
--- src/sys/dev/ic/ciss.c:1.47	Tue Jul 14 11:39:02 2020
+++ src/sys/dev/ic/ciss.c	Tue Jul 14 11:44:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.47 2020/07/14 11:39:02 jdolecek Exp $	*/
+/*	$NetBSD: ciss.c,v 1.48 2020/07/14 11:44:52 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.47 2020/07/14 11:39:02 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.48 2020/07/14 11:44:52 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -83,11 +83,11 @@ static int	ciss_sync(struct ciss_softc *
 static void	ciss_heartbeat(void *v);
 static void	ciss_shutdown(void *v);
 
-static struct ciss_ccb *ciss_get_ccb(struct ciss_softc *sc);
-static void	ciss_put_ccb(struct ciss_ccb *ccb);
-static int	ciss_cmd(struct ciss_ccb *ccb, int flags, int wait);
-static int	ciss_done(struct ciss_ccb *ccb);
-static int	ciss_error(struct ciss_ccb *ccb);
+static struct ciss_ccb *ciss_get_ccb(struct ciss_softc *);
+static void	ciss_put_ccb(struct ciss_softc *, struct ciss_ccb *);
+static int	ciss_cmd(struct ciss_softc *, struct ciss_ccb *, int, int);
+static int	ciss_done(struct ciss_softc *, struct ciss_ccb *);
+static int	ciss_error(struct ciss_softc *, struct ciss_ccb *);
 struct ciss_ld *ciss_pdscan(struct ciss_softc *sc, int ld);
 static int	ciss_inq(struct ciss_softc *sc, struct ciss_inquiry *inq);
 int	ciss_ldid(struct ciss_softc *, int, struct ciss_ldid *);
@@ -118,10 +118,8 @@ ciss_get_ccb(struct ciss_softc *sc)
 }
 
 static void
-ciss_put_ccb(struct ciss_ccb *ccb)
+ciss_put_ccb(struct ciss_softc *sc, struct ciss_ccb *ccb)
 {
-	struct ciss_softc *sc = ccb->ccb_sc;
-
 	ccb->ccb_state = CISS_CCB_FREE;
 	mutex_enter(>sc_mutex);
 	STAILQ_INSERT_HEAD(>sc_free_ccb, ccb, ccb_link);
@@ -354,7 +352,6 @@ ciss_attach(struct ciss_softc *sc)
 		cmd = >ccb_cmd;
 		pa = sc->cmdseg[0].ds_addr + i * sc->ccblen;
 
-		ccb->ccb_sc = sc;
 		ccb->ccb_cmdpa = pa + offsetof(struct ciss_ccb, ccb_cmd);
 		ccb->ccb_state = CISS_CCB_FREE;
 
@@ -631,7 +628,7 @@ ciss_poll(struct ciss_softc *sc, struct 
 			STAILQ_REMOVE_HEAD(, ccb_link);
 
 			KASSERT(ccb1->ccb_state == CISS_CCB_ONQ);
-			ciss_done(ccb1);
+			ciss_done(sc, ccb1);
 			if (ccb1 == ccb) {
 KASSERT(STAILQ_EMPTY());
 return 0;
@@ -662,7 +659,7 @@ ciss_wait(struct ciss_softc *sc, struct 
 		}
 		mutex_exit(>sc_mutex);
 		if (ccb->ccb_state == CISS_CCB_ONQ) {
-			ciss_done(ccb);
+			ciss_done(sc, ccb);
 			return 0;
 		}
 		tohz = etick - getticks();
@@ -679,9 +676,8 @@ ciss_wait(struct ciss_softc *sc, struct 
  * instead of busy loop waiting
  */
 static int
-ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
+ciss_cmd(struct ciss_softc *sc, struct ciss_ccb *ccb, int flags, int wait)
 {
-	struct ciss_softc *sc = ccb->ccb_sc;
 	struct ciss_cmd *cmd = >ccb_cmd;
 	bus_dmamap_t dmap = ccb->ccb_dmamap;
 	u_int64_t addr;
@@ -704,7 +700,7 @@ ciss_cmd(struct ciss_ccb *ccb, int flags
 printf("more than %d dma segs\n", sc->maxsg);
 			else
 printf("error %d loading dma map\n", error);
-			ciss_put_ccb(ccb);
+			ciss_put_ccb(sc, ccb);
 			return (error);
 		}
 		cmd->sgin = dmap->dm_nsegs;
@@ -807,7 +803,7 @@ ciss_cmd(struct ciss_ccb *ccb, int flags
 		if (ccb->ccb_state != CISS_CCB_FREE) {
 			KASSERT(error);
 			ccb->ccb_err.cmd_stat = CISS_ERR_TMO;
-			error = ciss_done(ccb);
+			error = ciss_done(sc, ccb);
 		}
 
 		CISS_DPRINTF(CISS_D_CMD, ("done %d:%d",
@@ -824,9 +820,8 @@ ciss_cmd(struct ciss_ccb *ccb, int flags
 }
 
 static int
-ciss_done(struct ciss_ccb *ccb)
+ciss_done(struct ciss_softc *sc, struct ciss_ccb *ccb)
 {
-	struct ciss_softc *sc = ccb->ccb_sc;
 	struct scsipi_xfer *xs = ccb->ccb_xs;
 	struct ciss_cmd *cmd;
 	int error = 0;
@@ -842,7 +837,7 @@ ciss_done(struct ciss_ccb *ccb)
 	ccb->ccb_state = CISS_CCB_READY;
 
 	if (ccb->ccb_cmd.id & CISS_CMD_ERR)
-		error = ciss_error(ccb);
+		error = ciss_error(sc, ccb);
 
 	cmd = >ccb_cmd;
 	if (ccb->ccb_data) {
@@ -854,7 +849,7 @@ ciss_done(struct ciss_ccb *ccb)
 		ccb->ccb_data = NULL;
 	}
 
-	ciss_put_ccb(ccb);
+	ciss_put_ccb(sc, ccb);
 
 	if (xs) {
 		xs->resid = 0;
@@ -874,9 +869,8 @@ ciss_done(struct ciss_ccb *ccb)
 }
 
 static int
-ciss_error(struct ciss_ccb *ccb)
+ciss_error(struct ciss_softc *sc, struct ciss_ccb *ccb)
 {
-	struct ciss_softc *sc = ccb->ccb_sc;
 	struct ciss_error *err = >ccb_err;
 	struct scsipi_xfer *xs = ccb->ccb_xs;
 	

CVS commit: src/sys/dev/ic

2020-07-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jul 14 11:39:02 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c cissreg.h

Log Message:
use STAILQ for ccb lists to save some memory, doubly-linked list is not needed


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/ic/ciss.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/cissreg.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.46 src/sys/dev/ic/ciss.c:1.47
--- src/sys/dev/ic/ciss.c:1.46	Tue Jul 14 10:44:34 2020
+++ src/sys/dev/ic/ciss.c	Tue Jul 14 11:39:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.46 2020/07/14 10:44:34 jdolecek Exp $	*/
+/*	$NetBSD: ciss.c,v 1.47 2020/07/14 11:39:02 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.46 2020/07/14 10:44:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.47 2020/07/14 11:39:02 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -109,8 +109,8 @@ ciss_get_ccb(struct ciss_softc *sc)
 	struct ciss_ccb *ccb;
 
 	mutex_enter(>sc_mutex);
-	if ((ccb = TAILQ_LAST(>sc_free_ccb, ciss_queue_head))) {
-		TAILQ_REMOVE(>sc_free_ccb, ccb, ccb_link);
+	if ((ccb = STAILQ_FIRST(>sc_free_ccb))) {
+		STAILQ_REMOVE_HEAD(>sc_free_ccb, ccb_link);
 		ccb->ccb_state = CISS_CCB_READY;
 	}
 	mutex_exit(>sc_mutex);
@@ -124,7 +124,7 @@ ciss_put_ccb(struct ciss_ccb *ccb)
 
 	ccb->ccb_state = CISS_CCB_FREE;
 	mutex_enter(>sc_mutex);
-	TAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
+	STAILQ_INSERT_HEAD(>sc_free_ccb, ccb, ccb_link);
 	mutex_exit(>sc_mutex);
 }
 
@@ -346,7 +346,7 @@ ciss_attach(struct ciss_softc *sc)
 		return -1;
 	}
 
-	TAILQ_INIT(>sc_free_ccb);
+	STAILQ_INIT(>sc_free_ccb);
 
 	maxfer = sc->maxsg * PAGE_SIZE;
 	for (i = 0; total > 0 && i < sc->maxcmd; i++, total -= sc->ccblen) {
@@ -371,7 +371,7 @@ ciss_attach(struct ciss_softc *sc)
 		>ccb_dmamap)))
 			break;
 
-		TAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
+		STAILQ_INSERT_TAIL(>sc_free_ccb, ccb, ccb_link);
 	}
 
 	if (i < sc->maxcmd) {
@@ -544,7 +544,7 @@ ciss_enqueue(struct ciss_softc *sc, ciss
 	ccb = (struct ciss_ccb *) ((char *)sc->ccbs + (id >> 2) * sc->ccblen);
 	ccb->ccb_cmd.id = htole32(id);
 	ccb->ccb_cmd.id_hi = htole32(0);
-	TAILQ_INSERT_TAIL(q, ccb, ccb_link);
+	STAILQ_INSERT_TAIL(q, ccb, ccb_link);
 }
 
 static void
@@ -614,7 +614,7 @@ ciss_poll(struct ciss_softc *sc, struct 
 	ciss_queue_head q;
 	struct ciss_ccb *ccb1;
 
-	TAILQ_INIT();
+	STAILQ_INIT();
 	ms /= 10;
 
 	while (ms-- > 0) {
@@ -626,14 +626,14 @@ ciss_poll(struct ciss_softc *sc, struct 
 			ciss_completed_simple(sc, );
 		mutex_exit(>sc_mutex);
 
-		while (!TAILQ_EMPTY()) {
-			ccb1 = TAILQ_FIRST();
-			TAILQ_REMOVE(, ccb1, ccb_link);
+		while (!STAILQ_EMPTY()) {
+			ccb1 = STAILQ_FIRST();
+			STAILQ_REMOVE_HEAD(, ccb_link);
 
 			KASSERT(ccb1->ccb_state == CISS_CCB_ONQ);
 			ciss_done(ccb1);
 			if (ccb1 == ccb) {
-KASSERT(TAILQ_EMPTY());
+KASSERT(STAILQ_EMPTY());
 return 0;
 			}
 		}
@@ -1264,9 +1264,9 @@ ciss_completed_process(struct ciss_softc
 {
 	struct ciss_ccb *ccb;
 
-	while (!TAILQ_EMPTY(q)) {
-		ccb = TAILQ_FIRST(q);
-		TAILQ_REMOVE(q, ccb, ccb_link);
+	while (!STAILQ_EMPTY(q)) {
+		ccb = STAILQ_FIRST(q);
+		STAILQ_REMOVE_HEAD(q, ccb_link);
 
 		if (ccb->ccb_state == CISS_CCB_POLL) {
 			ccb->ccb_state = CISS_CCB_ONQ;
@@ -1291,15 +1291,15 @@ ciss_intr_simple_intx(void *v)
 	if (!(bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_ISR) & sc->iem))
 		return 0;
 
-	TAILQ_INIT();
+	STAILQ_INIT();
 	mutex_enter(>sc_mutex);
 	ciss_completed_simple(sc, );
 	mutex_exit(>sc_mutex);
 
-	hit = (!TAILQ_EMPTY());
+	hit = (!STAILQ_EMPTY());
 	ciss_completed_process(sc, );
 
-	KASSERT(TAILQ_EMPTY());
+	KASSERT(STAILQ_EMPTY());
 	CISS_DPRINTF(CISS_D_INTR, ("exit\n"));
 
 	return hit;
@@ -1329,14 +1329,14 @@ ciss_intr_perf_msi(void *v)
 
 	CISS_DPRINTF(CISS_D_INTR, ("intr "));
 
-	TAILQ_INIT();
+	STAILQ_INIT();
 	mutex_enter(>sc_mutex);
 	ciss_completed_perf(sc, );
 	mutex_exit(>sc_mutex);
 
 	ciss_completed_process(sc, );
 
-	KASSERT(TAILQ_EMPTY());
+	KASSERT(STAILQ_EMPTY());
 	CISS_DPRINTF(CISS_D_INTR, ("exit"));
 
 	return 1;

Index: src/sys/dev/ic/cissreg.h
diff -u src/sys/dev/ic/cissreg.h:1.6 src/sys/dev/ic/cissreg.h:1.7
--- src/sys/dev/ic/cissreg.h:1.6	Tue Jul 14 10:37:30 2020
+++ src/sys/dev/ic/cissreg.h	Tue Jul 14 11:39:02 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cissreg.h,v 1.6 2020/07/14 10:37:30 jdolecek Exp $	*/
+/*	$NetBSD: cissreg.h,v 1.7 2020/07/14 11:39:02 jdolecek Exp $	*/
 /*	$OpenBSD: cissreg.h,v 1.11 2010/06/03 01:02:13 dlg Exp $	*/
 
 /*
@@ -516,7 +516,7 @@ struct ciss_error {
 } __packed;
 
 struct ciss_ccb {
-	TAILQ_ENTRY(ciss_ccb)	ccb_link;
+	STAILQ_ENTRY(ciss_ccb)	ccb_link;
 	struct ciss_softc	*ccb_sc;
 	paddr_t			ccb_cmdpa;
 	enum {
@@ -539,5 +539,5 @@ struct 

CVS commit: src/sys/dev/ic

2020-07-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jul 14 10:44:34 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c

Log Message:
only copy the actual command length in ciss_scsi_cmd(), instead of always
copying CISS_MAX_CDB bytes

Fixes reading past buffer memory triggered e.g. on kernel dump, reported
by KASAN:
ASan: Unauthorized Access In ...: Addr ... [16 bytes, read, RedZonePartial]

also do not pre-zero the cdb before copying cmd to it, there is no need for it


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/ic/ciss.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.45 src/sys/dev/ic/ciss.c:1.46
--- src/sys/dev/ic/ciss.c:1.45	Tue Jul 14 10:38:06 2020
+++ src/sys/dev/ic/ciss.c	Tue Jul 14 10:44:34 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.45 2020/07/14 10:38:06 jdolecek Exp $	*/
+/*	$NetBSD: ciss.c,v 1.46 2020/07/14 10:44:34 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.45 2020/07/14 10:38:06 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.46 2020/07/14 10:44:34 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -1225,8 +1225,7 @@ ciss_scsi_cmd(struct scsipi_channel *cha
 		else if (xs->xs_control & XS_CTL_DATA_OUT)
 			cmd->flags |= CISS_CDB_OUT;
 		cmd->tmo = htole16(xs->timeout < 1000? 1 : xs->timeout / 1000);
-		memset(>cdb[0], 0, sizeof(cmd->cdb));
-		memcpy(>cdb[0], xs->cmd, CISS_MAX_CDB);
+		memcpy(>cdb[0], xs->cmd, xs->cmdlen);
 		CISS_DPRINTF(CISS_D_CMD, ("cmd=%02x %02x %02x %02x %02x %02x ",
 			 cmd->cdb[0], cmd->cdb[1], cmd->cdb[2],
 			 cmd->cdb[3], cmd->cdb[4], cmd->cdb[5]));



CVS commit: src/sys/dev/ic

2020-07-14 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue Jul 14 10:38:07 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c

Log Message:
g/c #if 0'ed ciss_scsi_raw_cmd()


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/ic/ciss.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.44 src/sys/dev/ic/ciss.c:1.45
--- src/sys/dev/ic/ciss.c:1.44	Tue Jul 14 10:37:30 2020
+++ src/sys/dev/ic/ciss.c	Tue Jul 14 10:38:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.44 2020/07/14 10:37:30 jdolecek Exp $	*/
+/*	$NetBSD: ciss.c,v 1.45 2020/07/14 10:38:06 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.44 2020/07/14 10:37:30 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.45 2020/07/14 10:38:06 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -1178,83 +1178,6 @@ ciss_pdscan(struct ciss_softc *sc, int l
 	return ldp;
 }
 
-#if 0
-static void
-ciss_scsi_raw_cmd(struct scsipi_channel *chan, scsipi_adapter_req_t req,
-	void *arg)/* TODO */
-{
-	struct scsipi_xfer *xs = (struct scsipi_xfer *) arg;
-	struct ciss_rawsoftc *rsc = device_private(
-	chan->chan_adapter->adapt_dev);
-	struct ciss_softc *sc = rsc->sc_softc;
-	struct ciss_ccb *ccb;
-	struct ciss_cmd *cmd;
-	int error;
-
-	CISS_DPRINTF(CISS_D_CMD, ("ciss_scsi_raw_cmd "));
-
-	switch (req)
-	{
-	case ADAPTER_REQ_RUN_XFER:
-		if (xs->cmdlen > CISS_MAX_CDB) {
-			CISS_DPRINTF(CISS_D_CMD, ("CDB too big %p ", xs));
-			memset(>sense, 0, sizeof(xs->sense));
-			printf("ciss driver stuffup in %s:%d: %s()\n",
-			   __FILE__, __LINE__, __func__);
-			xs->error = XS_DRIVER_STUFFUP;
-			scsipi_done(xs);
-			break;
-		}
-
-		error = 0;
-		xs->error = XS_NOERROR;
-
-		/* TODO check this target has not yet employed w/ any volume */
-
-		ccb = ciss_get_ccb(sc);
-		cmd = >ccb_cmd;
-		ccb->ccb_len = xs->datalen;
-		ccb->ccb_data = xs->data;
-		ccb->ccb_xs = xs;
-
-		cmd->cdblen = xs->cmdlen;
-		cmd->flags = CISS_CDB_CMD | CISS_CDB_SIMPL;
-		if (xs->xs_control & XS_CTL_DATA_IN)
-			cmd->flags |= CISS_CDB_IN;
-		else if (xs->xs_control & XS_CTL_DATA_OUT)
-			cmd->flags |= CISS_CDB_OUT;
-		cmd->tmo = xs->timeout < 1000? 1 : xs->timeout / 1000;
-		memset(>cdb[0], 0, sizeof(cmd->cdb));
-		memcpy(>cdb[0], xs->cmd, CISS_MAX_CDB);
-
-		if (ciss_cmd(ccb, BUS_DMA_WAITOK,
-		xs->xs_control & (XS_CTL_POLL|XS_CTL_NOSLEEP))) {
-			printf("ciss driver stuffup in %s:%d: %s()\n",
-			   __FILE__, __LINE__, __func__);
-			xs->error = XS_DRIVER_STUFFUP;
-			scsipi_done(xs);
-			break;
-		}
-
-		break;
-
-	case ADAPTER_REQ_GROW_RESOURCES:
-		/*
-		 * Not supported.
-		 */
-		break;
-
-	case ADAPTER_REQ_SET_XFER_MODE:
-		/*
-		 * We can't change the transfer mode, but at least let
-		 * scsipi know what the adapter has negociated.
-		 */
-		 /* Get xfer mode and return it */
-		break;
-	}
-}
-#endif
-
 static void
 ciss_scsi_cmd(struct scsipi_channel *chan, scsipi_adapter_req_t req,
 	void *arg)



CVS commit: src/sys/dev/ic

2020-07-12 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Mon Jul 13 05:38:52 UTC 2020

Modified Files:
src/sys/dev/ic: bwfm.c

Log Message:
move some of the patching of callbacks and other data after
ieee80211_ifattach() but before if_deferred_start_init().

may fix panic i saw in after restarting wpa_supplicant.

from mlelstv.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/ic/bwfm.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.25 src/sys/dev/ic/bwfm.c:1.26
--- src/sys/dev/ic/bwfm.c:1.25	Sat May 30 15:55:47 2020
+++ src/sys/dev/ic/bwfm.c	Mon Jul 13 05:38:52 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.25 2020/05/30 15:55:47 jdolecek Exp $ */
+/* $NetBSD: bwfm.c,v 1.26 2020/07/13 05:38:52 mrg Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -432,10 +432,6 @@ bwfm_attach(struct bwfm_softc *sc)
 	}
 		
 	ieee80211_ifattach(ic);
-	ifp->if_percpuq = if_percpuq_create(ifp);
-	if_deferred_start_init(ifp, NULL);
-	if_register(ifp);
-
 	sc->sc_newstate = ic->ic_newstate;
 	ic->ic_newstate = bwfm_newstate;
 	ic->ic_newassoc = bwfm_newassoc;
@@ -443,6 +439,10 @@ bwfm_attach(struct bwfm_softc *sc)
 	ic->ic_recv_mgmt = bwfm_recv_mgmt;
 	ic->ic_crypto.cs_key_set = bwfm_key_set;
 	ic->ic_crypto.cs_key_delete = bwfm_key_delete;
+
+	ifp->if_percpuq = if_percpuq_create(ifp);
+	if_deferred_start_init(ifp, NULL);
+	if_register(ifp);
 	ieee80211_media_init(ic, bwfm_media_change, ieee80211_media_status);
 
 	ieee80211_announce(ic);



CVS commit: src/sys/dev/ic

2020-07-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Jul 10 14:23:56 UTC 2020

Modified Files:
src/sys/dev/ic: ciss.c

Log Message:
remove write-only sc_ccbq, and unused sc_ccbdone


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/ic/ciss.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/ic/ciss.c
diff -u src/sys/dev/ic/ciss.c:1.42 src/sys/dev/ic/ciss.c:1.43
--- src/sys/dev/ic/ciss.c:1.42	Fri May 15 19:28:10 2020
+++ src/sys/dev/ic/ciss.c	Fri Jul 10 14:23:56 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ciss.c,v 1.42 2020/05/15 19:28:10 maxv Exp $	*/
+/*	$NetBSD: ciss.c,v 1.43 2020/07/10 14:23:56 jdolecek Exp $	*/
 /*	$OpenBSD: ciss.c,v 1.68 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.42 2020/05/15 19:28:10 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ciss.c,v 1.43 2020/07/10 14:23:56 jdolecek Exp $");
 
 #include "bio.h"
 
@@ -247,8 +247,6 @@ ciss_attach(struct ciss_softc *sc)
 		return -1;
 	}
 
-	TAILQ_INIT(>sc_ccbq);
-	TAILQ_INIT(>sc_ccbdone);
 	TAILQ_INIT(>sc_free_ccb);
 
 	maxfer = sc->maxsg * PAGE_SIZE;
@@ -594,9 +592,6 @@ ciss_cmd(struct ciss_ccb *ccb, int flags
 		bus_space_read_4(sc->sc_iot, sc->sc_ioh, CISS_IMR) | sc->iem);
 #endif
 
-	mutex_enter(>sc_mutex);
-	TAILQ_INSERT_TAIL(>sc_ccbq, ccb, ccb_link);
-	mutex_exit(>sc_mutex);
 	ccb->ccb_state = CISS_CCB_ONQ;
 	CISS_DPRINTF(CISS_D_CMD, ("submit=0x%x ", cmd->id));
 	if (sc->cfg.methods & (CISS_METH_FIFO64|CISS_METH_FIFO64_RRO)) {
@@ -660,9 +655,6 @@ ciss_done(struct ciss_ccb *ccb)
 	}
 
 	ccb->ccb_state = CISS_CCB_READY;
-	mutex_enter(>sc_mutex);
-	TAILQ_REMOVE(>sc_ccbq, ccb, ccb_link);
-	mutex_exit(>sc_mutex);
 
 	if (ccb->ccb_cmd.id & CISS_CMD_ERR)
 		error = ciss_error(ccb);



CVS commit: src/sys/dev/ic

2020-07-10 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Fri Jul 10 14:24:14 UTC 2020

Modified Files:
src/sys/dev/ic: cissvar.h

Log Message:
remove write-only sc_ccbq, and unused sc_ccbdone


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/ic/cissvar.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/ic/cissvar.h
diff -u src/sys/dev/ic/cissvar.h:1.7 src/sys/dev/ic/cissvar.h:1.8
--- src/sys/dev/ic/cissvar.h:1.7	Mon Feb 12 23:11:00 2018
+++ src/sys/dev/ic/cissvar.h	Fri Jul 10 14:24:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: cissvar.h,v 1.7 2018/02/12 23:11:00 joerg Exp $	*/
+/*	$NetBSD: cissvar.h,v 1.8 2020/07/10 14:24:14 jdolecek Exp $	*/
 /*	$OpenBSD: cissvar.h,v 1.15 2013/05/30 16:15:02 deraadt Exp $	*/
 
 /*
@@ -57,7 +57,7 @@ struct ciss_softc {
 
 	u_int	sc_flags;
 	int ccblen, maxcmd, maxsg, nbus, ndrives, maxunits;
-	ciss_queue_head	sc_free_ccb, sc_ccbq, sc_ccbdone;
+	ciss_queue_head		sc_free_ccb;
 	kcondvar_t		sc_condvar;
 
 	bus_dmamap_t		cmdmap;



CVS commit: src/sys/dev/ic

2020-06-27 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jun 27 13:34:20 UTC 2020

Modified Files:
src/sys/dev/ic: bcmgenet.c dm9000.c dwc_gmac.c

Log Message:
prop_data_data_nocopy -> prop_data_value


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/bcmgenet.c
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ic/dm9000.c
cvs rdiff -u -r1.70 -r1.71 src/sys/dev/ic/dwc_gmac.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/ic/bcmgenet.c
diff -u src/sys/dev/ic/bcmgenet.c:1.6 src/sys/dev/ic/bcmgenet.c:1.7
--- src/sys/dev/ic/bcmgenet.c:1.6	Mon May 25 19:49:28 2020
+++ src/sys/dev/ic/bcmgenet.c	Sat Jun 27 13:34:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bcmgenet.c,v 1.6 2020/05/25 19:49:28 jmcneill Exp $ */
+/* $NetBSD: bcmgenet.c,v 1.7 2020/06/27 13:34:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -34,7 +34,7 @@
 #include "opt_ddb.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.6 2020/05/25 19:49:28 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcmgenet.c,v 1.7 2020/06/27 13:34:20 jmcneill Exp $");
 
 #include 
 #include 
@@ -836,7 +836,7 @@ genet_get_eaddr(struct genet_softc *sc, 
 	if (eaprop != NULL) {
 		KASSERT(prop_object_type(eaprop) == PROP_TYPE_DATA);
 		KASSERT(prop_data_size(eaprop) == ETHER_ADDR_LEN);
-		memcpy(eaddr, prop_data_data_nocopy(eaprop),
+		memcpy(eaddr, prop_data_value(eaprop),
 		ETHER_ADDR_LEN);
 		return;
 	}

Index: src/sys/dev/ic/dm9000.c
diff -u src/sys/dev/ic/dm9000.c:1.28 src/sys/dev/ic/dm9000.c:1.29
--- src/sys/dev/ic/dm9000.c:1.28	Thu Apr  2 13:38:50 2020
+++ src/sys/dev/ic/dm9000.c	Sat Jun 27 13:34:20 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dm9000.c,v 1.28 2020/04/02 13:38:50 nisimura Exp $	*/
+/*	$NetBSD: dm9000.c,v 1.29 2020/06/27 13:34:20 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2009 Paul Fleischer
@@ -224,7 +224,7 @@ dme_attach(struct dme_softc *sc, const u
 		 */
 		KASSERT(prop_object_type(ea) == PROP_TYPE_DATA);
 		KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN);
-		memcpy(enaddr, prop_data_data_nocopy(ea), ETHER_ADDR_LEN);
+		memcpy(enaddr, prop_data_value(ea), ETHER_ADDR_LEN);
 		aprint_debug_dev(sc->sc_dev, "got MAC address!\n");
 	} else {
 		/*

Index: src/sys/dev/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.70 src/sys/dev/ic/dwc_gmac.c:1.71
--- src/sys/dev/ic/dwc_gmac.c:1.70	Sun May 17 21:50:47 2020
+++ src/sys/dev/ic/dwc_gmac.c	Sat Jun 27 13:34:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.70 2020/05/17 21:50:47 chs Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.71 2020/06/27 13:34:20 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.70 2020/05/17 21:50:47 chs Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.71 2020/06/27 13:34:20 jmcneill Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -202,7 +202,7 @@ dwc_gmac_attach(struct dwc_gmac_softc *s
 		 */
 		KASSERT(prop_object_type(ea) == PROP_TYPE_DATA);
 		KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN);
-		memcpy(enaddr, prop_data_data_nocopy(ea), ETHER_ADDR_LEN);
+		memcpy(enaddr, prop_data_value(ea), ETHER_ADDR_LEN);
 	} else {
 		/*
 		 * If we did not get an externaly configure address,



CVS commit: src/sys/dev/ic

2020-06-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 27 09:28:15 UTC 2020

Modified Files:
src/sys/dev/ic: aic79xx.c aic7xxx.c

Log Message:
small constify


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/ic/aic79xx.c
cvs rdiff -u -r1.140 -r1.141 src/sys/dev/ic/aic7xxx.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/ic/aic79xx.c
diff -u src/sys/dev/ic/aic79xx.c:1.54 src/sys/dev/ic/aic79xx.c:1.55
--- src/sys/dev/ic/aic79xx.c:1.54	Sat Jun 27 09:03:15 2020
+++ src/sys/dev/ic/aic79xx.c	Sat Jun 27 09:28:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aic79xx.c,v 1.54 2020/06/27 09:03:15 jdolecek Exp $	*/
+/*	$NetBSD: aic79xx.c,v 1.55 2020/06/27 09:28:15 jdolecek Exp $	*/
 
 /*
  * Core routines and tables shareable across OS platforms.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aic79xx.c,v 1.54 2020/06/27 09:03:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aic79xx.c,v 1.55 2020/06/27 09:28:15 jdolecek Exp $");
 
 #include 
 #include 
@@ -63,7 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: aic79xx.c,v 
 struct ahd_softc_tailq ahd_tailq = TAILQ_HEAD_INITIALIZER(ahd_tailq);
 
 /* Lookup Tables **/
-const char *ahd_chip_names[] =
+const char * const ahd_chip_names[] =
 {
 	"NONE",
 	"aic7901",
@@ -5983,14 +5983,14 @@ ahd_controller_info(struct ahd_softc *ah
 		ahd->scb_data.maxhscbs);
 }
 
-static const char *channel_strings[] = {
+static const char * const channel_strings[] = {
 	"Primary Low",
 	"Primary High",
 	"Secondary Low",
 	"Secondary High"
 };
 
-static const char *termstat_strings[] = {
+static const char * const termstat_strings[] = {
 	"Terminated Correctly",
 	"Over Terminated",
 	"Under Terminated",

Index: src/sys/dev/ic/aic7xxx.c
diff -u src/sys/dev/ic/aic7xxx.c:1.140 src/sys/dev/ic/aic7xxx.c:1.141
--- src/sys/dev/ic/aic7xxx.c:1.140	Sat Jun 27 09:03:15 2020
+++ src/sys/dev/ic/aic7xxx.c	Sat Jun 27 09:28:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $	*/
+/*	$NetBSD: aic7xxx.c,v 1.141 2020/06/27 09:28:15 jdolecek Exp $	*/
 
 /*
  * Core routines and tables shareable across OS platforms.
@@ -39,7 +39,7 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $
+ * $Id: aic7xxx.c,v 1.141 2020/06/27 09:28:15 jdolecek Exp $
  *
  * //depot/aic7xxx/aic7xxx/aic7xxx.c#112 $
  *
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aic7xxx.c,v 1.141 2020/06/27 09:28:15 jdolecek Exp $");
 
 #include 
 #include 
@@ -60,7 +60,7 @@ __KERNEL_RCSID(0, "$NetBSD: aic7xxx.c,v 
 struct ahc_softc_tailq ahc_tailq = TAILQ_HEAD_INITIALIZER(ahc_tailq);
 
 /* Lookup Tables **/
-const char *ahc_chip_names[] =
+const char * const ahc_chip_names[] =
 {
 	"NONE",
 	"aic7770",



CVS commit: src/sys/dev/ic

2020-06-27 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat Jun 27 09:03:15 UTC 2020

Modified Files:
src/sys/dev/ic: aic79xx.c aic7xxx.c

Log Message:
mark ahc_loadseq()/ahd_loadseq() as __noinline to avoid 'stack usage
might get unbounded' - seems the variable-length array using const variable
is misinterpreted as unbounded when inlined


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/dev/ic/aic79xx.c
cvs rdiff -u -r1.139 -r1.140 src/sys/dev/ic/aic7xxx.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/ic/aic79xx.c
diff -u src/sys/dev/ic/aic79xx.c:1.53 src/sys/dev/ic/aic79xx.c:1.54
--- src/sys/dev/ic/aic79xx.c:1.53	Fri Dec 27 09:45:26 2019
+++ src/sys/dev/ic/aic79xx.c	Sat Jun 27 09:03:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aic79xx.c,v 1.53 2019/12/27 09:45:26 msaitoh Exp $	*/
+/*	$NetBSD: aic79xx.c,v 1.54 2020/06/27 09:03:15 jdolecek Exp $	*/
 
 /*
  * Core routines and tables shareable across OS platforms.
@@ -49,7 +49,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aic79xx.c,v 1.53 2019/12/27 09:45:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aic79xx.c,v 1.54 2020/06/27 09:03:15 jdolecek Exp $");
 
 #include 
 #include 
@@ -8252,7 +8252,7 @@ ahd_dumpseq(struct ahd_softc* ahd)
 }
 #endif
 
-static void
+static void __noinline
 ahd_loadseq(struct ahd_softc *ahd)
 {
 	struct	cs cs_table[num_critical_sections];

Index: src/sys/dev/ic/aic7xxx.c
diff -u src/sys/dev/ic/aic7xxx.c:1.139 src/sys/dev/ic/aic7xxx.c:1.140
--- src/sys/dev/ic/aic7xxx.c:1.139	Fri Dec 27 09:45:26 2019
+++ src/sys/dev/ic/aic7xxx.c	Sat Jun 27 09:03:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: aic7xxx.c,v 1.139 2019/12/27 09:45:26 msaitoh Exp $	*/
+/*	$NetBSD: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $	*/
 
 /*
  * Core routines and tables shareable across OS platforms.
@@ -39,7 +39,7 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: aic7xxx.c,v 1.139 2019/12/27 09:45:26 msaitoh Exp $
+ * $Id: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $
  *
  * //depot/aic7xxx/aic7xxx/aic7xxx.c#112 $
  *
@@ -50,7 +50,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: aic7xxx.c,v 1.139 2019/12/27 09:45:26 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aic7xxx.c,v 1.140 2020/06/27 09:03:15 jdolecek Exp $");
 
 #include 
 #include 
@@ -6275,7 +6275,7 @@ ahc_dumpseq(struct ahc_softc* ahc)
 }
 #endif
 
-static void
+static void __noinline
 ahc_loadseq(struct ahc_softc *ahc)
 {
 	struct	cs cs_table[num_critical_sections];



CVS commit: src/sys/dev/ic

2020-06-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jun 24 20:17:55 UTC 2020

Modified Files:
src/sys/dev/ic: ibm561.c

Log Message:
actually stop using the stack variable


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/ic/ibm561.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/ic/ibm561.c
diff -u src/sys/dev/ic/ibm561.c:1.12 src/sys/dev/ic/ibm561.c:1.13
--- src/sys/dev/ic/ibm561.c:1.12	Wed Jun 24 19:55:25 2020
+++ src/sys/dev/ic/ibm561.c	Wed Jun 24 20:17:55 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ibm561.c,v 1.12 2020/06/24 19:55:25 jdolecek Exp $ */
+/* $NetBSD: ibm561.c,v 1.13 2020/06/24 20:17:55 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.12 2020/06/24 19:55:25 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.13 2020/06/24 20:17:55 jdolecek Exp $");
 
 #include 
 #include 
@@ -165,7 +165,7 @@ ibm561_cninit(
 	u_int8_t (*rd)(void *, u_int),
 	u_int dotclock)
 {
-	struct ibm561data tmp, *data = 
+	struct ibm561data *data = _console_data;
 	memset(data, 0x0, sizeof *data);
 	data->cookie = v;
 	data->ramdac_sched_update = sched_update;



CVS commit: src/sys/dev/ic

2020-06-24 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Wed Jun 24 19:55:25 UTC 2020

Modified Files:
src/sys/dev/ic: ibm561.c

Log Message:
avoid allocating almost 5k struct ibm561data on stack in ibm561_cninit();
it's too early for kmem_alloc(), so use static variable in BSS


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/ic/ibm561.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/ic/ibm561.c
diff -u src/sys/dev/ic/ibm561.c:1.11 src/sys/dev/ic/ibm561.c:1.12
--- src/sys/dev/ic/ibm561.c:1.11	Sun Feb 12 16:34:11 2012
+++ src/sys/dev/ic/ibm561.c	Wed Jun 24 19:55:25 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ibm561.c,v 1.11 2012/02/12 16:34:11 matt Exp $ */
+/* $NetBSD: ibm561.c,v 1.12 2020/06/24 19:55:25 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.11 2012/02/12 16:34:11 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibm561.c,v 1.12 2020/06/24 19:55:25 jdolecek Exp $");
 
 #include 
 #include 
@@ -155,7 +155,7 @@ ibm561_register(
  * initializing the console early on.
  */
 
-struct ibm561data *saved_console_data;
+static struct ibm561data saved_console_data;
 
 void
 ibm561_cninit(
@@ -172,9 +172,7 @@ ibm561_cninit(
 	data->ramdac_wr = wr;
 	data->ramdac_rd = rd;
 	ibm561_set_dotclock((struct ramdac_cookie *)data, dotclock);
-	saved_console_data = data;
 	ibm561_init((struct ramdac_cookie *)data);
-	saved_console_data = NULL;
 }
 
 void
@@ -394,7 +392,7 @@ ibm561_update(void *vp)
 
 	/* XXX see comment above ibm561_cninit() */
 	if (!data)
-		data = saved_console_data;
+		data = _console_data;
 
 	if (data->changed & CHANGED_WTYPE) {
 		ibm561_regbegin(data, IBM561_FB_WINTYPE);



CVS commit: src/sys/dev/ic

2020-06-03 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Jun  3 18:25:26 UTC 2020

Modified Files:
src/sys/dev/ic: wdc.c

Log Message:
Don't print an error message on spurious interrupt. Way too noisy for Xen.


To generate a diff of this commit:
cvs rdiff -u -r1.302 -r1.303 src/sys/dev/ic/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/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.302 src/sys/dev/ic/wdc.c:1.303
--- src/sys/dev/ic/wdc.c:1.302	Sat May 30 13:23:14 2020
+++ src/sys/dev/ic/wdc.c	Wed Jun  3 18:25:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.302 2020/05/30 13:23:14 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.303 2020/06/03 18:25:26 bouyer Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.302 2020/05/30 13:23:14 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.303 2020/06/03 18:25:26 bouyer Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -892,10 +892,8 @@ wdcintr(void *arg)
 		return (0);
 	}
 
-	if ((chp->ch_flags & ATACH_IRQ_WAIT) == 0) {
-		__wdcerror(chp, "irq not expected");
+	if ((chp->ch_flags & ATACH_IRQ_WAIT) == 0)
 		goto ignore;
-	}
 
 	xfer = ata_queue_get_active_xfer(chp);
 	if (xfer == NULL) {



CVS commit: src/sys/dev/ic

2020-05-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat May 30 14:03:08 UTC 2020

Modified Files:
src/sys/dev/ic: bwfm.c

Log Message:
reduce stack usage in bwfm_rx_event_cb(), can use KM_SLEEP because
this is called from workqueue handler (i.e. thread context)


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ic/bwfm.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/ic/bwfm.c
diff -u src/sys/dev/ic/bwfm.c:1.23 src/sys/dev/ic/bwfm.c:1.24
--- src/sys/dev/ic/bwfm.c:1.23	Sat May 30 13:41:58 2020
+++ src/sys/dev/ic/bwfm.c	Sat May 30 14:03:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: bwfm.c,v 1.23 2020/05/30 13:41:58 jdolecek Exp $ */
+/* $NetBSD: bwfm.c,v 1.24 2020/05/30 14:03:08 jdolecek Exp $ */
 /* $OpenBSD: bwfm.c,v 1.5 2017/10/16 22:27:16 patrick Exp $ */
 /*
  * Copyright (c) 2010-2016 Broadcom Corporation
@@ -2143,12 +2143,15 @@ bwfm_rx_event_cb(struct bwfm_softc *sc, 
 			union {
 struct bwfm_bss_info bss_info;
 uint8_t padding[BWFM_BSS_INFO_BUFLEN];
-			} bss_buf;
-			if (len > sizeof(bss_buf)) {
+			} *bss_buf;
+			if (len > sizeof(*bss_buf)) {
 printf("%s: bss_info buffer too big\n", DEVNAME(sc));
 			} else {
-memcpy(_buf, >bss_info[i], len);
-bwfm_scan_node(sc, _buf.bss_info, len);
+bss_buf = kmem_alloc(sizeof(*bss_buf),
+KM_SLEEP);
+memcpy(bss_buf, >bss_info[i], len);
+bwfm_scan_node(sc, _buf->bss_info, len);
+kmem_free(bss_buf, sizeof(*bss_buf));
 			}
 			len -= sizeof(*bss) + le32toh(bss->length);
 			bss = (void *)(((uintptr_t)bss) + le32toh(bss->length));



CVS commit: src/sys/dev/ic

2020-05-30 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sat May 30 13:23:14 UTC 2020

Modified Files:
src/sys/dev/ic: wdc.c

Log Message:
fix wdcprobe_with_reset() to avoid allocating big structures on stack


To generate a diff of this commit:
cvs rdiff -u -r1.301 -r1.302 src/sys/dev/ic/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/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.301 src/sys/dev/ic/wdc.c:1.302
--- src/sys/dev/ic/wdc.c:1.301	Thu May 21 09:24:17 2020
+++ src/sys/dev/ic/wdc.c	Sat May 30 13:23:14 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.301 2020/05/21 09:24:17 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.302 2020/05/30 13:23:14 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.301 2020/05/21 09:24:17 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.302 2020/05/30 13:23:14 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -70,6 +70,7 @@ __KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.30
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -489,24 +490,28 @@ int
 wdcprobe_with_reset(struct wdc_regs *wdr,
 void (*do_reset)(struct ata_channel *, int))
 {
-	struct wdc_softc wdc;
-	struct ata_channel ch;
+	struct wdc_softc *wdc;
+	struct ata_channel *ch;
 	int rv;
 
-	memset(, 0, sizeof(wdc));
-	memset(, 0, sizeof(ch));
-	ata_channel_init();
-	ch.ch_atac = _atac;
-	wdc.regs = wdr;
+	wdc = kmem_zalloc(sizeof(*wdc), KM_SLEEP);
+	ch = kmem_zalloc(sizeof(*ch), KM_SLEEP);
+
+	ata_channel_init(ch);
+	ch->ch_atac = >sc_atac;
+	wdc->regs = wdr;
 
 	/* check the MD reset method */
-	wdc.reset = (do_reset != NULL) ? do_reset : wdc_do_reset;
+	wdc->reset = (do_reset != NULL) ? do_reset : wdc_do_reset;
+
+	ata_channel_lock(ch);
+	rv = wdcprobe1(ch, 1);
+	ata_channel_unlock(ch);
 
-	ata_channel_lock();
-	rv = wdcprobe1(, 1);
-	ata_channel_unlock();
+	ata_channel_destroy(ch);
 
-	ata_channel_destroy();
+	kmem_free(ch, sizeof(*ch));
+	kmem_free(wdc, sizeof(*wdc));
 
 	return rv;
 }



CVS commit: src/sys/dev/ic

2020-05-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri May 29 09:05:20 UTC 2020

Modified Files:
src/sys/dev/ic: dm9000var.h

Log Message:
Make this compile again. Not tested.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/ic/dm9000var.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/ic/dm9000var.h
diff -u src/sys/dev/ic/dm9000var.h:1.6 src/sys/dev/ic/dm9000var.h:1.7
--- src/sys/dev/ic/dm9000var.h:1.6	Tue Mar 31 02:32:25 2020
+++ src/sys/dev/ic/dm9000var.h	Fri May 29 09:05:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: dm9000var.h,v 1.6 2020/03/31 02:32:25 nisimura Exp $	*/
+/*	$NetBSD: dm9000var.h,v 1.7 2020/05/29 09:05:19 rin Exp $	*/
 
 /*
  * Copyright (c) 2009 Paul Fleischer
@@ -66,6 +66,9 @@
 #include 
 #include 
 
+#include 
+#include 
+
 #define DM9000_MODE_8BIT 2
 #define DM9000_MODE_16BIT 0
 #define DM9000_MODE_32BIT 1



CVS commit: src/sys/dev/ic

2020-05-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 26 13:24:53 UTC 2020

Modified Files:
src/sys/dev/ic: com.c

Log Message:
Make the readahead-while-sending-output code conditional in
com_common_putc(), only erquest readahead before interrupts are enabled
and when called from comcnputc().
Fixes PR kern/55286.


To generate a diff of this commit:
cvs rdiff -u -r1.358 -r1.359 src/sys/dev/ic/com.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/ic/com.c
diff -u src/sys/dev/ic/com.c:1.358 src/sys/dev/ic/com.c:1.359
--- src/sys/dev/ic/com.c:1.358	Fri May  1 07:27:51 2020
+++ src/sys/dev/ic/com.c	Tue May 26 13:24:52 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.358 2020/05/01 07:27:51 simonb Exp $ */
+/* $NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2004, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.358 2020/05/01 07:27:51 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.359 2020/05/26 13:24:52 martin Exp $");
 
 #include "opt_com.h"
 #include "opt_ddb.h"
@@ -159,7 +159,7 @@ int	com_to_tiocm(struct com_softc *);
 void	com_iflush(struct com_softc *);
 
 int	com_common_getc(dev_t, struct com_regs *);
-static void	com_common_putc(dev_t, struct com_regs *, int);
+static void	com_common_putc(dev_t, struct com_regs *, int, int);
 
 int	cominit(struct com_regs *, int, int, int, tcflag_t);
 
@@ -2399,12 +2399,12 @@ com_common_getc(dev_t dev, struct com_re
 }
 
 static void
-com_common_putc(dev_t dev, struct com_regs *regsp, int c)
+com_common_putc(dev_t dev, struct com_regs *regsp, int c, int with_readahead)
 {
 	int s = splserial();
 	int cin, stat, timo;
 
-	if (com_readaheadcount < MAX_READAHEAD
+	if (with_readahead && com_readaheadcount < MAX_READAHEAD
 	 && ISSET(stat = CSR_READ_1(regsp, COM_REG_LSR), LSR_RXRDY)) {
 		int cn_trapped = 0;
 		cin = CSR_READ_1(regsp, COM_REG_RXDATA);
@@ -2572,7 +2572,7 @@ void
 comcnputc(dev_t dev, int c)
 {
 
-	com_common_putc(dev, _info.regs, c);
+	com_common_putc(dev, _info.regs, c, cold);
 }
 
 void
@@ -2641,7 +2641,7 @@ void
 com_kgdb_putc(void *arg, int c)
 {
 
-	com_common_putc(NODEV, , c);
+	com_common_putc(NODEV, , c, 0);
 }
 #endif /* KGDB */
 



CVS commit: src/sys/dev/ic

2020-05-21 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Thu May 21 09:24:17 UTC 2020

Modified Files:
src/sys/dev/ic: wdc.c

Log Message:
in wdctimeout(), do not schedule another timeout handler, as that only
creates race with eventual xfer resubmission - the c_intr()
method does all the necessary handling, including re-scheduling of the
timeout handler if appropriate

also make sure to clear ATACH_IRQ_WAIT before calling c_intr(), same
as real interrupt does; this is important so that eventual spurious timeout
would not interfere with xfer handling in the atabus thread

fixes another race in the atabus thread found by KASAN, reported by Paul Ripke


To generate a diff of this commit:
cvs rdiff -u -r1.300 -r1.301 src/sys/dev/ic/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/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.300 src/sys/dev/ic/wdc.c:1.301
--- src/sys/dev/ic/wdc.c:1.300	Tue May 19 08:21:29 2020
+++ src/sys/dev/ic/wdc.c	Thu May 21 09:24:17 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.300 2020/05/19 08:21:29 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.301 2020/05/21 09:24:17 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.300 2020/05/19 08:21:29 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.301 2020/05/21 09:24:17 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -1375,12 +1375,9 @@ wdctimeout(void *arg)
 	 * Call the interrupt routine. If we just missed an interrupt,
 	 * it will do what's needed. Else, it will take the needed
 	 * action (reset the device).
-	 * Before that we need to reinstall the timeout callback,
-	 * in case it will miss another irq while in this transfer
-	 * We arbitray chose it to be 1s
 	 */
-	callout_reset(>c_timo_callout, hz, wdctimeout, chp);
 	xfer->c_flags |= C_TIMEOU;
+	chp->ch_flags &= ~ATACH_IRQ_WAIT;
 	KASSERT(xfer->ops != NULL && xfer->ops->c_intr != NULL);
 	xfer->ops->c_intr(chp, xfer, 1);
 



CVS commit: src/sys/dev/ic

2020-05-19 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Tue May 19 08:21:30 UTC 2020

Modified Files:
src/sys/dev/ic: wdc.c

Log Message:
in wdctimeout() ignore timeout if not actually waiting for IRQ, to avoid
processing xfer which is not quite setup

in wdcintr() actually write the error message on invocation when
not waiting for IRQ even without ATADEBUG option, as usually that
is a driver bug; might revisit this if this ends up too noisy for
PCI-IDE which seems to ignore WDCTL_IDS and hence trigger irq even
for polled commands


To generate a diff of this commit:
cvs rdiff -u -r1.299 -r1.300 src/sys/dev/ic/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/ic/wdc.c
diff -u src/sys/dev/ic/wdc.c:1.299 src/sys/dev/ic/wdc.c:1.300
--- src/sys/dev/ic/wdc.c:1.299	Mon Apr 13 10:49:34 2020
+++ src/sys/dev/ic/wdc.c	Tue May 19 08:21:29 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: wdc.c,v 1.299 2020/04/13 10:49:34 jdolecek Exp $ */
+/*	$NetBSD: wdc.c,v 1.300 2020/05/19 08:21:29 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1998, 2001, 2003 Manuel Bouyer.  All rights reserved.
@@ -58,7 +58,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.299 2020/04/13 10:49:34 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wdc.c,v 1.300 2020/05/19 08:21:29 jdolecek Exp $");
 
 #include "opt_ata.h"
 #include "opt_wdc.h"
@@ -888,7 +888,7 @@ wdcintr(void *arg)
 	}
 
 	if ((chp->ch_flags & ATACH_IRQ_WAIT) == 0) {
-		ATADEBUG_PRINT(("wdcintr: irq not expected\n"), DEBUG_INTR);
+		__wdcerror(chp, "irq not expected");
 		goto ignore;
 	}
 
@@ -1346,6 +1346,11 @@ wdctimeout(void *arg)
 
 	callout_ack(>c_timo_callout);
 
+	if ((chp->ch_flags & ATACH_IRQ_WAIT) == 0) {
+		__wdcerror(chp, "timeout not expected without pending irq");
+		goto out;
+	}
+
 	xfer = ata_queue_get_active_xfer(chp);
 	KASSERT(xfer != NULL);
 



CVS commit: src/sys/dev/ic

2020-05-17 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun May 17 21:50:47 UTC 2020

Modified Files:
src/sys/dev/ic: dwc_gmac.c dwc_gmac_reg.h

Log Message:
Mask all the MMC counter interrupts if the MMC module is present.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/ic/dwc_gmac.c
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/ic/dwc_gmac_reg.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/ic/dwc_gmac.c
diff -u src/sys/dev/ic/dwc_gmac.c:1.69 src/sys/dev/ic/dwc_gmac.c:1.70
--- src/sys/dev/ic/dwc_gmac.c:1.69	Wed Jan 29 14:14:55 2020
+++ src/sys/dev/ic/dwc_gmac.c	Sun May 17 21:50:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac.c,v 1.69 2020/01/29 14:14:55 thorpej Exp $ */
+/* $NetBSD: dwc_gmac.c,v 1.70 2020/05/17 21:50:47 chs Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.69 2020/01/29 14:14:55 thorpej Exp $");
+__KERNEL_RCSID(1, "$NetBSD: dwc_gmac.c,v 1.70 2020/05/17 21:50:47 chs Exp $");
 
 /* #define	DWC_GMAC_DEBUG	1 */
 
@@ -254,6 +254,16 @@ dwc_gmac_attach(struct dwc_gmac_softc *s
 	} else {
 		sc->sc_descm = _methods_standard;
 	}
+	if (hwft & GMAC_DMA_FEAT_RMON) {
+		uint32_t val;
+
+		/* Mask all MMC interrupts */
+		val = 0x;
+		bus_space_write_4(sc->sc_bst, sc->sc_bsh,
+		GMAC_MMC_RX_INT_MSK, val);
+		bus_space_write_4(sc->sc_bst, sc->sc_bsh,
+		GMAC_MMC_TX_INT_MSK, val);
+	}
 
 	/*
 	 * Allocate Tx and Rx rings

Index: src/sys/dev/ic/dwc_gmac_reg.h
diff -u src/sys/dev/ic/dwc_gmac_reg.h:1.19 src/sys/dev/ic/dwc_gmac_reg.h:1.20
--- src/sys/dev/ic/dwc_gmac_reg.h:1.19	Mon Oct  8 17:09:31 2018
+++ src/sys/dev/ic/dwc_gmac_reg.h	Sun May 17 21:50:47 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc_gmac_reg.h,v 1.19 2018/10/08 17:09:31 martin Exp $ */
+/* $NetBSD: dwc_gmac_reg.h,v 1.20 2020/05/17 21:50:47 chs Exp $ */
 
 /*-
  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
@@ -79,6 +79,46 @@
 #define	AWIN_GMAC_MAC_FLOWCTRL_TFE	__BIT(1)
 #define	AWIN_GMAC_MAC_FLOWCTRL_BUSY	__BIT(0)
 
+#define	GMAC_MMC_CTRL			0x0100	/* MMC control */
+#define	GMAC_MMC_RX_INTR		0x0104	/* MMC RX interrupt */
+#define	GMAC_MMC_TX_INTR		0x0108	/* MMC TX interrupt */
+#define	GMAC_MMC_RX_INT_MSK		0x010c	/* MMC RX interrupt mask */
+#define	GMAC_MMC_TX_INT_MSK		0x0110	/* MMC TX interrupt mask */
+#define	GMAC_MMC_TXOCTETCNT_GB		0x0114	/* TX octet good+bad */
+#define	GMAC_MMC_TXFRMCNT_GB		0x0118	/* TX frame good+bad */
+#define	GMAC_MMC_TXUNDFLWERR		0x0148	/* TX underflow */
+#define	GMAC_MMC_TXCARERR		0x0160	/* TX carrier error */
+#define	GMAC_MMC_TXOCTETCNT_G		0x0164	/* TX octet good */
+#define	GMAC_MMC_TXFRMCNT_G		0x0168	/* TX frame good */
+#define	GMAC_MMC_RXFRMCNT_GB		0x0180	/* RX frame good+bad */
+#define	GMAC_MMC_RXOCTETCNT_GB		0x0184	/* RX octet good+bad */
+#define	GMAC_MMC_RXOCTETCNT_G		0x0188	/* RX octet good */
+#define	GMAC_MMC_RXMCFRMCNT_G		0x0190	/* RX mcast frame good */
+#define	GMAC_MMC_RXCRCERR		0x0194	/* RX CRC error */
+#define	GMAC_MMC_RXLENERR		0x01c8	/* RX length error */
+#define	GMAC_MMC_RXFIFOOVRFLW		0x01d4	/* RX FIFO overflow */
+#define	GMAC_MMC_IPC_INT_MSK		0x0200	/* RX csum offload intr mask */
+#define	GMAC_MMC_IPC_INTR		0x0208	/* RX csum offload interrupt */
+#define	GMAC_MMC_RXIPV4GFRM		0x0210	/* RX IPv4 good frame */
+#define	GMAC_MMC_RXIPV4HDERRFRM		0x0214	/* RX IPv4 header error */
+#define	GMAC_MMC_RXIPV6GFRM		0x0224	/* RX IPv6 good frame */
+#define	GMAC_MMC_RXIPV6HDERRFRM		0x0228	/* RX IPv6 header error */
+#define	GMAC_MMC_RXUDPERRFRM		0x0234	/* RX UDP csum error frame */
+#define	GMAC_MMC_RXTCPERRFRM		0x023c	/* RX TCP csum error frame */
+#define	GMAC_MMC_RXICMPERRFRM		0x0244	/* RX ICMP csum error frame */
+#define	GMAC_MMC_RXIPV4HDERROCT		0x0254	/* RX IPv4 header error octets */
+#define	GMAC_MMC_RXIPV6HDERROCT		0x0268	/* RX IPv6 header error octets */
+#define	GMAC_MMC_RXUDPERROCT		0x0274	/* RX UDP error octets */
+#define	GMAC_MMC_RXTCPERROCT		0x027c	/* RX TCP error octets */
+#define	GMAC_MMC_RXICMPERROCT		0x0280	/* RX ICMP error octets */
+
+#define	GMAC_MMC_CTRL_FHP		__BIT(5) /* Full-Half preset */
+#define	GMAC_MMC_CTRL_CP		__BIT(4) /* Counters preset */
+#define	GMAC_MMC_CTRL_MCF		__BIT(3) /* MMC counter freeze */
+#define	GMAC_MMC_CTRL_ROR		__BIT(2) /* reset on read */
+#define	GMAC_MMC_CTRL_CSR		__BIT(1) /* Counter stop rollover */
+#define	GMAC_MMC_CTRL_CR		__BIT(0) /* Counters reset */
+
 #define	AWIN_GMAC_DMA_BUSMODE		0x1000
 #define	AWIN_GMAC_DMA_TXPOLL		0x1004
 #define	AWIN_GMAC_DMA_RXPOLL		0x1008
@@ -128,7 +168,12 @@
 		burst len */
 #define	GMAC_BUSMODE_RESET		__BIT(0)
 
-#define	AWIN_GMAC_MII_IRQ		__BIT(0)
+#define	AWIN_GMAC_MRCOIS		__BIT(7) /* MMC RX csum offload intr */
+#define	AWIN_GMAC_MTIS			__BIT(6) /* MMC TX interrupt */
+#define	AWIN_GMAC_MRIS			__BIT(3) /* MMC RX interrupt */
+#define	AWIN_GMAC_MIS			

CVS commit: src/sys/dev/ic

2020-05-16 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sat May 16 23:06:40 UTC 2020

Modified Files:
src/sys/dev/ic: hpet.c

Log Message:
Store initial TSC/HPET readings for hpet0 only.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/ic/hpet.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/ic/hpet.c
diff -u src/sys/dev/ic/hpet.c:1.16 src/sys/dev/ic/hpet.c:1.17
--- src/sys/dev/ic/hpet.c:1.16	Fri May  8 22:01:54 2020
+++ src/sys/dev/ic/hpet.c	Sat May 16 23:06:40 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hpet.c,v 1.16 2020/05/08 22:01:54 ad Exp $ */
+/* $NetBSD: hpet.c,v 1.17 2020/05/16 23:06:40 ad Exp $ */
 
 /*
  * Copyright (c) 2006 Nicolas Joly
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.16 2020/05/08 22:01:54 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.17 2020/05/16 23:06:40 ad Exp $");
 
 #include 
 #include 
@@ -149,7 +149,7 @@ hpet_attach_subr(device_t dv)
 	sc->sc_adj = (int64_t)val * sc->sc_period / 1000;
 
 	/* Store attach-time values for computing TSC frequency later. */
-	if (cpu_hascounter()) {
+	if (cpu_hascounter() && sc == hpet0) {
 		(void)cpu_counter();
 		val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_MCOUNT_LO);
 		hpet_attach_tsc = cpu_counter();



CVS commit: src/sys/dev/ic

2020-05-11 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Mon May 11 14:55:20 UTC 2020

Modified Files:
src/sys/dev/ic: w83l518d.c w83l518d_sdmmc.c w83l518dvar.h

Log Message:
Make the driver endian-independent.
Add a quirk so that the bus front end can specify 1-bit only mode.
Remove unused isa includes.
Change the error returned for unsupported opcodes to ENOTSUP, so that
we can pass this back to sdmmc_mem, where it's handled since r1.72 of
  src/sys/dev/sdmmc/sdmmc_mem.c


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/ic/w83l518d.c \
src/sys/dev/ic/w83l518dvar.h
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/ic/w83l518d_sdmmc.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/ic/w83l518d.c
diff -u src/sys/dev/ic/w83l518d.c:1.2 src/sys/dev/ic/w83l518d.c:1.3
--- src/sys/dev/ic/w83l518d.c:1.2	Thu Aug 19 14:58:22 2010
+++ src/sys/dev/ic/w83l518d.c	Mon May 11 14:55:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518d.c,v 1.2 2010/08/19 14:58:22 jmcneill Exp $ */
+/* $NetBSD: w83l518d.c,v 1.3 2020/05/11 14:55:20 jdc Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v 1.2 2010/08/19 14:58:22 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v 1.3 2020/05/11 14:55:20 jdc Exp $");
 
 #include 
 #include 
@@ -39,9 +39,6 @@ __KERNEL_RCSID(0, "$NetBSD: w83l518d.c,v
 
 #include 
 
-#include 
-#include 
-
 #include 
 #include 
 #include 
Index: src/sys/dev/ic/w83l518dvar.h
diff -u src/sys/dev/ic/w83l518dvar.h:1.2 src/sys/dev/ic/w83l518dvar.h:1.3
--- src/sys/dev/ic/w83l518dvar.h:1.2	Thu Aug 19 14:58:22 2010
+++ src/sys/dev/ic/w83l518dvar.h	Mon May 11 14:55:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518dvar.h,v 1.2 2010/08/19 14:58:22 jmcneill Exp $ */
+/* $NetBSD: w83l518dvar.h,v 1.3 2020/05/11 14:55:20 jdc Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill 
@@ -44,6 +44,10 @@ struct wb_softc {
 	uint8_t			wb_sdmmc_clk;
 	uint8_t			wb_sdmmc_intsts;
 	callout_t		wb_sdmmc_callout;
+
+	/* quirks */
+#define	WB_QUIRK_1BIT	(1U << 0)
+	int			wb_quirks;
 };
 
 void	wb_attach(struct wb_softc *);

Index: src/sys/dev/ic/w83l518d_sdmmc.c
diff -u src/sys/dev/ic/w83l518d_sdmmc.c:1.3 src/sys/dev/ic/w83l518d_sdmmc.c:1.4
--- src/sys/dev/ic/w83l518d_sdmmc.c:1.3	Thu Oct  7 12:06:09 2010
+++ src/sys/dev/ic/w83l518d_sdmmc.c	Mon May 11 14:55:20 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: w83l518d_sdmmc.c,v 1.3 2010/10/07 12:06:09 kiyohara Exp $ */
+/* $NetBSD: w83l518d_sdmmc.c,v 1.4 2020/05/11 14:55:20 jdc Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: w83l518d_sdmmc.c,v 1.3 2010/10/07 12:06:09 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: w83l518d_sdmmc.c,v 1.4 2020/05/11 14:55:20 jdc Exp $");
 
 #include 
 #include 
@@ -43,9 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: w83l518d_sdm
 #include 
 #include 
 
-#include 
-#include 
-
 #include 
 #include 
 #include 
@@ -185,7 +182,8 @@ wb_sdmmc_attach(struct wb_softc *wb)
 	saa.saa_sch = wb;
 	saa.saa_clkmin = 375;
 	saa.saa_clkmax = 24000;
-	saa.saa_caps = SMC_CAPS_4BIT_MODE;
+	if (!ISSET(wb->wb_quirks, WB_QUIRK_1BIT))
+		saa.saa_caps = SMC_CAPS_4BIT_MODE;
 
 	wb->wb_sdmmc_dev = config_found(wb->wb_dev, , NULL);
 }
@@ -268,7 +266,7 @@ wb_sdmmc_write_protect(sdmmc_chipset_han
 static int
 wb_sdmmc_bus_power(sdmmc_chipset_handle_t sch, uint32_t ocr)
 {
-	REPORT(sch, "TRACE: sdmmc/bus_power(wb, ocr=%d)\n", ocr);
+	REPORT(sch, "TRACE: sdmmc/bus_power(wb, ocr=%x)\n", ocr);
 
 	return 0;
 }
@@ -334,10 +332,19 @@ wb_sdmmc_rsp_read_long(struct wb_softc *
 	}
 
 	for (i = 12; i >= 0; i -= 4) {
+#if BYTE_ORDER == LITTLE_ENDIAN
 		p[3] = wb_idx_read(wb, WB_INDEX_RESP(i + 0));
 		p[2] = wb_idx_read(wb, WB_INDEX_RESP(i + 1));
 		p[1] = wb_idx_read(wb, WB_INDEX_RESP(i + 2));
 		p[0] = wb_idx_read(wb, WB_INDEX_RESP(i + 3));
+#else
+		p[0] = wb_idx_read(wb, WB_INDEX_RESP(i + 0));
+		p[1] = wb_idx_read(wb, WB_INDEX_RESP(i + 1));
+		p[2] = wb_idx_read(wb, WB_INDEX_RESP(i + 2));
+		p[3] = wb_idx_read(wb, WB_INDEX_RESP(i + 3));
+#endif
+		REPORT(wb, "TRACE: sdmmc/read_long (%d) 0x%08x\n",
+		(12 - i) / 4, cmd->c_resp[(12 - i) / 4]);
 		p += 4;
 	}
 }
@@ -352,10 +359,19 @@ wb_sdmmc_rsp_read_short(struct wb_softc 
 		return;
 	}
 
+#if BYTE_ORDER == LITTLE_ENDIAN
 	p[3] = wb_idx_read(wb, WB_INDEX_RESP(12));
 	p[2] = wb_idx_read(wb, WB_INDEX_RESP(13));
 	p[1] = wb_idx_read(wb, WB_INDEX_RESP(14));
 	p[0] = wb_idx_read(wb, WB_INDEX_RESP(15));
+#else
+	p[0] = wb_idx_read(wb, WB_INDEX_RESP(12));
+	p[1] = wb_idx_read(wb, WB_INDEX_RESP(13));
+	p[2] = wb_idx_read(wb, WB_INDEX_RESP(14));
+	p[3] = wb_idx_read(wb, WB_INDEX_RESP(15));
+#endif
+	REPORT(wb, "TRACE: sdmmc/read_short 0x%08x\n",
+	cmd->c_resp[0]);
 }
 
 static int
@@ -430,8 +446,9 @@ wb_sdmmc_exec_command(sdmmc_chipset_hand
 	int s;
 
 	REPORT(wb, "TRACE: sdmmc/exec_command(wb, cmd) "
-	

  1   2   3   4   5   6   7   8   9   10   >