CVS commit: src/sys/arch/arm/cortex

2023-11-11 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov 11 17:35:45 UTC 2023

Modified Files:
src/sys/arch/arm/cortex: gicv3_its.c

Log Message:
gicv3_its: assorted minor improvements

- KASSERT that the command queue is not stalled due to async error
  before issuing more commands.
- implement gits_command_int under #if 0 (useful for troubleshooting)
- protect command queue with its_lock consistently
- KASSERT for 32-bit MSI that upper bits are 0
- KASSERT return value of gicv3_its_msi_alloc_lpi
- KASSERT that safe conditions for writing to CBASER are met
- move CWRITER initialization to before CBASER
- fix alignment of tables for the 16KB page size case


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/cortex/gicv3_its.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/arch/arm/cortex/gicv3_its.c
diff -u src/sys/arch/arm/cortex/gicv3_its.c:1.34 src/sys/arch/arm/cortex/gicv3_its.c:1.35
--- src/sys/arch/arm/cortex/gicv3_its.c:1.34	Sun Oct 31 17:24:11 2021
+++ src/sys/arch/arm/cortex/gicv3_its.c	Sat Nov 11 17:35:45 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3_its.c,v 1.34 2021/10/31 17:24:11 skrll Exp $ */
+/* $NetBSD: gicv3_its.c,v 1.35 2023/11/11 17:35:45 tnn Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #define _INTR_PRIVATE
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.34 2021/10/31 17:24:11 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.35 2023/11/11 17:35:45 tnn Exp $");
 
 #include 
 #include 
@@ -117,6 +117,11 @@ gits_command(struct gicv3_its *its, cons
 
 	cwriter = gits_read_8(its, GITS_CWRITER);
 	woff = cwriter & GITS_CWRITER_Offset;
+#ifdef DIAGNOSTIC
+	uint64_t creadr = gits_read_8(its, GITS_CREADR);
+	KASSERT(!ISSET(creadr, GITS_CREADR_Stalled));
+	KASSERT(((woff + sizeof(cmd->dw)) & (its->its_cmd.len - 1)) != (creadr & GITS_CREADR_Offset));
+#endif
 
 	uint64_t *dw = (uint64_t *)(its->its_cmd.base + woff);
 	for (int i = 0; i < __arraycount(cmd->dw); i++)
@@ -256,6 +261,26 @@ gits_command_sync(struct gicv3_its *its,
 	gits_command(its, );
 }
 
+#if 0
+static inline void
+gits_command_int(struct gicv3_its *its, uint32_t deviceid, uint32_t eventid)
+{
+	struct gicv3_its_command cmd;
+
+	/*
+	 * Translate the deviceid and eventid into an icid and pintid through
+	 * the device table and ITT. Mark the pintid as pending
+	 * on the redistributor.
+	 * If the interrupt is not configured the command queue stalls.
+	 */
+	memset(, 0, sizeof(cmd));
+	cmd.dw[0] = GITS_CMD_INT | ((uint64_t)deviceid << 32);
+	cmd.dw[1] = eventid;
+
+	gits_command(its, );
+}
+#endif
+
 static inline int
 gits_wait(struct gicv3_its *its)
 {
@@ -358,8 +383,10 @@ gicv3_its_device_map(struct gicv3_its *i
 	 * Map the device to the ITT
 	 */
 	const u_int id_bits = __SHIFTOUT(typer, GITS_TYPER_ID_bits) + 1;
+	mutex_enter(its->its_lock);
 	gits_command_mapd(its, devid, dev->dev_itt.segs[0].ds_addr, id_bits - 1, true);
 	gits_wait(its);
+	mutex_exit(its->its_lock);
 
 	return 0;
 }
@@ -391,6 +418,7 @@ gicv3_its_msi_enable(struct gicv3_its *i
 		pci_conf_write(pc, tag, off + PCI_MSI_MDATA64,
 		lpi - its->its_pic->pic_irqbase);
 	} else {
+		KASSERT((addr >> 32) == 0);
 		pci_conf_write(pc, tag, off + PCI_MSI_MADDR,
 		addr & 0x);
 		pci_conf_write(pc, tag, off + PCI_MSI_MDATA,
@@ -485,8 +513,10 @@ gicv3_its_msi_alloc(struct arm_pci_msi *
 		return NULL;
 
 	vectors = kmem_alloc(sizeof(*vectors) * *count, KM_SLEEP);
+	mutex_enter(its->its_lock);
 	for (n = 0; n < *count; n++) {
 		const int lpi = gicv3_its_msi_alloc_lpi(its, pa);
+		KASSERT(lpi >= 0);
 		vectors[n] = ARM_PCI_INTR_MSI |
 		__SHIFTIN(lpi, ARM_PCI_INTR_IRQ) |
 		__SHIFTIN(n, ARM_PCI_INTR_MSI_VEC) |
@@ -508,6 +538,7 @@ gicv3_its_msi_alloc(struct arm_pci_msi *
 		gits_command_sync(its, its->its_rdbase[cpu_index(ci)]);
 	}
 	gits_wait(its);
+	mutex_exit(its->its_lock);
 
 	return vectors;
 }
@@ -555,8 +586,10 @@ gicv3_its_msix_alloc(struct arm_pci_msi 
 	}
 
 	vectors = kmem_alloc(sizeof(*vectors) * *count, KM_SLEEP);
+	mutex_enter(its->its_lock);
 	for (n = 0; n < *count; n++) {
 		const int lpi = gicv3_its_msi_alloc_lpi(its, pa);
+		KASSERT(lpi >= 0);
 		const int msix_vec = table_indexes ? table_indexes[n] : n;
 		vectors[msix_vec] = ARM_PCI_INTR_MSIX |
 		__SHIFTIN(lpi, ARM_PCI_INTR_IRQ) |
@@ -578,6 +611,7 @@ gicv3_its_msix_alloc(struct arm_pci_msi 
 		gits_command_sync(its, its->its_rdbase[cpu_index(ci)]);
 	}
 	gits_wait(its);
+	mutex_exit(its->its_lock);
 
 	bus_space_unmap(bst, bsh, bsz);
 
@@ -638,14 +672,17 @@ gicv3_its_command_init(struct gicv3_soft
 
 	gicv3_dma_alloc(sc, >its_cmd, GITS_COMMANDS_SIZE, GITS_COMMANDS_ALIGN);
 
+	KASSERT((gits_read_4(its, GITS_CTLR) & GITS_CTLR_Enabled) == 0);
+	KASSERT((gits_read_4(its, GITS_CTLR) & GITS_CTLR_Quiescent) != 0);
+
 	cbaser = its->its_cmd.segs[0].ds_addr;
 	cbaser |= 

CVS commit: src/sys/arch/arm/cortex

2023-11-11 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Nov 11 17:35:45 UTC 2023

Modified Files:
src/sys/arch/arm/cortex: gicv3_its.c

Log Message:
gicv3_its: assorted minor improvements

- KASSERT that the command queue is not stalled due to async error
  before issuing more commands.
- implement gits_command_int under #if 0 (useful for troubleshooting)
- protect command queue with its_lock consistently
- KASSERT for 32-bit MSI that upper bits are 0
- KASSERT return value of gicv3_its_msi_alloc_lpi
- KASSERT that safe conditions for writing to CBASER are met
- move CWRITER initialization to before CBASER
- fix alignment of tables for the 16KB page size case


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/arch/arm/cortex/gicv3_its.c

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



CVS commit: [thorpej-altq-separation] src/sys

2023-11-11 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Nov 11 13:16:31 UTC 2023

Modified Files:
src/sys/altq [thorpej-altq-separation]: altq_blue.c altq_cbq.c
altq_cdnr.c altq_conf.c altq_fifoq.c altq_hfsc.c altq_jobs.c
altq_priq.c altq_red.c altq_rio.c altq_subr.c altq_wfq.c if_altq.h
src/sys/net [thorpej-altq-separation]: if.c if.h if_bridge.c
if_ethersubr.c if_vlan.c
src/sys/net80211 [thorpej-altq-separation]: ieee80211_input.c

Log Message:
Mostly de-tangle ifnet::if_snd from ifaltq, in a way that's minimally-
invasive to the ALTQ code itself.

The point of this is to lay the groundwork for future changes to ifqueue,
which among other benefits, will also hide the ALTQ ABI from drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.6.1 src/sys/altq/altq_blue.c
cvs rdiff -u -r1.39 -r1.39.6.1 src/sys/altq/altq_cbq.c
cvs rdiff -u -r1.22 -r1.22.6.1 src/sys/altq/altq_cdnr.c \
src/sys/altq/altq_conf.c
cvs rdiff -u -r1.18 -r1.18.6.1 src/sys/altq/altq_fifoq.c
cvs rdiff -u -r1.30 -r1.30.6.1 src/sys/altq/altq_hfsc.c
cvs rdiff -u -r1.12 -r1.12.6.1 src/sys/altq/altq_jobs.c
cvs rdiff -u -r1.28 -r1.28.6.1 src/sys/altq/altq_priq.c
cvs rdiff -u -r1.35 -r1.35.6.1 src/sys/altq/altq_red.c
cvs rdiff -u -r1.25 -r1.25.6.1 src/sys/altq/altq_rio.c
cvs rdiff -u -r1.33 -r1.33.46.1 src/sys/altq/altq_subr.c
cvs rdiff -u -r1.23 -r1.23.6.1 src/sys/altq/altq_wfq.c
cvs rdiff -u -r1.16 -r1.16.4.1 src/sys/altq/if_altq.h
cvs rdiff -u -r1.529 -r1.529.2.1 src/sys/net/if.c
cvs rdiff -u -r1.305 -r1.305.2.1 src/sys/net/if.h
cvs rdiff -u -r1.189 -r1.189.6.1 src/sys/net/if_bridge.c
cvs rdiff -u -r1.326 -r1.326.2.1 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.171 -r1.171.2.1 src/sys/net/if_vlan.c
cvs rdiff -u -r1.117 -r1.117.4.1 src/sys/net80211/ieee80211_input.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/altq/altq_blue.c
diff -u src/sys/altq/altq_blue.c:1.26 src/sys/altq/altq_blue.c:1.26.6.1
--- src/sys/altq/altq_blue.c:1.26	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_blue.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_blue.c,v 1.26 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_blue.c,v 1.26.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_blue.c,v 1.15 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.26 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.26.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -221,7 +221,7 @@ blueioctl(dev_t dev, ioctlcmd_t cmd, voi
 			break;
 		}
 
-		rqp->rq_ifq = >if_snd;
+		rqp->rq_ifq = ifp->if_snd.ifq_altq;
 		qtail(rqp->rq_q) = NULL;
 		qlen(rqp->rq_q) = 0;
 		qlimit(rqp->rq_q) = BLUE_LIMIT;
@@ -397,7 +397,7 @@ blue_enqueue(struct ifaltq *ifq, struct 
 	pktattr.pattr_hdr = m->m_pkthdr.pattr_hdr;
 
 	if (blue_addq(rqp->rq_blue, rqp->rq_q, m, ) == 0)
-		ifq->ifq_len++;
+		ALTQ_INC_LEN(ifq);
 	else
 		error = ENOBUFS;
 	return error;
@@ -618,7 +618,7 @@ blue_dequeue(struct ifaltq * ifq, int op
 
 	m = blue_getq(rqp->rq_blue, rqp->rq_q);
 	if (m != NULL)
-		ifq->ifq_len--;
+		ALTQ_DEC_LEN(ifq);
 	return m;
 }
 
@@ -652,7 +652,7 @@ blue_request(struct ifaltq *ifq, int req
 	case ALTRQ_PURGE:
 		_flushq(rqp->rq_q);
 		if (ALTQ_IS_ENABLED(ifq))
-			ifq->ifq_len = 0;
+			ALTQ_SET_LEN(ifq, 0);
 		break;
 	}
 	return (0);

Index: src/sys/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.39 src/sys/altq/altq_cbq.c:1.39.6.1
--- src/sys/altq/altq_cbq.c:1.39	Fri Dec 31 20:22:48 2021
+++ src/sys/altq/altq_cbq.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.39 2021/12/31 20:22:48 andvar Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.39.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.39 2021/12/31 20:22:48 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.39.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -542,7 +542,7 @@ cbq_enqueue(struct ifaltq *ifq, struct m
 
 	/* successfully queued. */
 	++cbqp->cbq_qlen;
-	IFQ_INC_LEN(ifq);
+	ALTQ_INC_LEN(ifq);
 	return (0);
 }
 
@@ -556,7 +556,7 @@ cbq_dequeue(struct ifaltq *ifq, int op)
 
 	if (m && op == ALTDQ_REMOVE) {
 		--cbqp->cbq_qlen;  /* decrement # of packets in cbq */
-		IFQ_DEC_LEN(ifq);
+		ALTQ_DEC_LEN(ifq);
 
 		/* Update the class. */
 		rmc_update_class_util(>ifnp);
@@ -602,7 +602,7 @@ cbq_purge(cbq_state_t *cbqp)
 		if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
 			rmc_dropall(cl);
 	if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
-		cbqp->ifnp.ifq_->ifq_len = 0;
+		ALTQ_SET_LEN(cbqp->ifnp.ifq_, 0);
 }
 #ifdef ALTQ3_COMPAT
 
@@ -909,12 +909,12 @@ cbq_ifattach(struct cbq_interface *iface
  	

CVS commit: [thorpej-altq-separation] src/sys

2023-11-11 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Nov 11 13:16:31 UTC 2023

Modified Files:
src/sys/altq [thorpej-altq-separation]: altq_blue.c altq_cbq.c
altq_cdnr.c altq_conf.c altq_fifoq.c altq_hfsc.c altq_jobs.c
altq_priq.c altq_red.c altq_rio.c altq_subr.c altq_wfq.c if_altq.h
src/sys/net [thorpej-altq-separation]: if.c if.h if_bridge.c
if_ethersubr.c if_vlan.c
src/sys/net80211 [thorpej-altq-separation]: ieee80211_input.c

Log Message:
Mostly de-tangle ifnet::if_snd from ifaltq, in a way that's minimally-
invasive to the ALTQ code itself.

The point of this is to lay the groundwork for future changes to ifqueue,
which among other benefits, will also hide the ALTQ ABI from drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.6.1 src/sys/altq/altq_blue.c
cvs rdiff -u -r1.39 -r1.39.6.1 src/sys/altq/altq_cbq.c
cvs rdiff -u -r1.22 -r1.22.6.1 src/sys/altq/altq_cdnr.c \
src/sys/altq/altq_conf.c
cvs rdiff -u -r1.18 -r1.18.6.1 src/sys/altq/altq_fifoq.c
cvs rdiff -u -r1.30 -r1.30.6.1 src/sys/altq/altq_hfsc.c
cvs rdiff -u -r1.12 -r1.12.6.1 src/sys/altq/altq_jobs.c
cvs rdiff -u -r1.28 -r1.28.6.1 src/sys/altq/altq_priq.c
cvs rdiff -u -r1.35 -r1.35.6.1 src/sys/altq/altq_red.c
cvs rdiff -u -r1.25 -r1.25.6.1 src/sys/altq/altq_rio.c
cvs rdiff -u -r1.33 -r1.33.46.1 src/sys/altq/altq_subr.c
cvs rdiff -u -r1.23 -r1.23.6.1 src/sys/altq/altq_wfq.c
cvs rdiff -u -r1.16 -r1.16.4.1 src/sys/altq/if_altq.h
cvs rdiff -u -r1.529 -r1.529.2.1 src/sys/net/if.c
cvs rdiff -u -r1.305 -r1.305.2.1 src/sys/net/if.h
cvs rdiff -u -r1.189 -r1.189.6.1 src/sys/net/if_bridge.c
cvs rdiff -u -r1.326 -r1.326.2.1 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.171 -r1.171.2.1 src/sys/net/if_vlan.c
cvs rdiff -u -r1.117 -r1.117.4.1 src/sys/net80211/ieee80211_input.c

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