Module Name:    src
Committed By:   thorpej
Date:           Sat Sep  3 02:07:33 UTC 2022

Modified Files:
        src/sys/net: netisr_dispatch.h
        src/sys/netcan: can.c can_proto.c can_var.h
        src/sys/rump/net/lib/libnetcan: netcan_component.c

Log Message:
Convert CAN from a legacy netisr to pktqueue.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/net/netisr_dispatch.h
cvs rdiff -u -r1.11 -r1.12 src/sys/netcan/can.c
cvs rdiff -u -r1.2 -r1.3 src/sys/netcan/can_proto.c src/sys/netcan/can_var.h
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libnetcan/netcan_component.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/net/netisr_dispatch.h
diff -u src/sys/net/netisr_dispatch.h:1.22 src/sys/net/netisr_dispatch.h:1.23
--- src/sys/net/netisr_dispatch.h:1.22	Sat Sep  3 01:48:22 2022
+++ src/sys/net/netisr_dispatch.h	Sat Sep  3 02:07:32 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: netisr_dispatch.h,v 1.22 2022/09/03 01:48:22 thorpej Exp $ */
+/* $NetBSD: netisr_dispatch.h,v 1.23 2022/09/03 02:07:32 thorpej Exp $ */
 
 #ifndef _NET_NETISR_DISPATCH_H_
 #define _NET_NETISR_DISPATCH_H_
@@ -30,8 +30,5 @@
 #ifdef MPLS
 	DONETISR(NETISR_MPLS,mplsintr);
 #endif
-#ifdef CAN
-	DONETISR(NETISR_CAN,canintr);
-#endif
 
 #endif /* !_NET_NETISR_DISPATCH_H_ */

Index: src/sys/netcan/can.c
diff -u src/sys/netcan/can.c:1.11 src/sys/netcan/can.c:1.12
--- src/sys/netcan/can.c:1.11	Fri Dec 31 14:24:51 2021
+++ src/sys/netcan/can.c	Sat Sep  3 02:07:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: can.c,v 1.11 2021/12/31 14:24:51 riastradh Exp $	*/
+/*	$NetBSD: can.c,v 1.12 2022/09/03 02:07:32 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.11 2021/12/31 14:24:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.12 2022/09/03 02:07:32 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: can.c,v 1.11
 
 #include <net/if.h>
 #include <net/if_types.h>
-#include <net/netisr.h>
+#include <net/pktqueue.h>
 #include <net/route.h>
 #include <net/bpf.h> 
 
@@ -61,7 +61,7 @@ struct canpcb canrawpcb;
 
 struct	canpcbtable cbtable;
 
-struct ifqueue	canintrq;
+pktqueue_t *		can_pktq		__read_mostly;
 int	canqmaxlen = IFQ_MAXLEN;
 
 int can_copy_output = 0;
@@ -86,11 +86,14 @@ static int can_output(struct mbuf *, str
 
 static int can_control(struct socket *, u_long, void *, struct ifnet *);
 
+static void canintr(void *);
+
 void
 can_init(void)
 {
-	canintrq.ifq_maxlen = canqmaxlen;
-	IFQ_LOCK_INIT(&canintrq);
+	can_pktq = pktq_create(canqmaxlen, canintr, NULL);
+	KASSERT(can_pktq != NULL);
+
 	can_pcbinit(&cbtable, canhashsize, canhashsize);
 }
 
@@ -290,30 +293,21 @@ can_mbuf_tag_clean(struct mbuf *m)
 void
 can_input(struct ifnet *ifp, struct mbuf *m)
 {
-	struct ifqueue *inq;
-
 	if ((ifp->if_flags & IFF_UP) == 0) {
 		m_freem(m);
 		return;
 	}
 
-	inq = &canintrq;
-	
-	IFQ_LOCK(inq);
-	if (IF_QFULL(inq)) {
-		IF_DROP(inq);
-		IFQ_UNLOCK(inq);
+	const int pktlen = m->m_pkthdr.len;
+	if (__predict_false(!pktq_enqueue(can_pktq, m, 0))) {
 		m_freem(m);
 	} else {
-		IF_ENQUEUE(inq, m);
-		IFQ_UNLOCK(inq);
-		if_statadd2(ifp, if_ipackets, 1, if_ibytes, m->m_pkthdr.len);
-		schednetisr(NETISR_CAN);
+		if_statadd2(ifp, if_ipackets, 1, if_ibytes, pktlen);
 	}
 }
 
-void
-canintr(void)
+static void
+canintr(void *arg __unused)
 {
 	int		rcv_ifindex;
 	struct mbuf    *m;
@@ -324,14 +318,7 @@ canintr(void)
 	struct canpcb	*sender_canp;
 
 	mutex_enter(softnet_lock);
-	for (;;) {
-		IFQ_LOCK(&canintrq);
-		IF_DEQUEUE(&canintrq, m);
-		IFQ_UNLOCK(&canintrq);
-
-		if (m == NULL)	/* no more queued packets */
-			break;
-
+	while ((m = pktq_dequeue(can_pktq)) != NULL) {
 #if 0
 		m_claim(m, &can_rx_mowner);
 #endif

Index: src/sys/netcan/can_proto.c
diff -u src/sys/netcan/can_proto.c:1.2 src/sys/netcan/can_proto.c:1.3
--- src/sys/netcan/can_proto.c:1.2	Sat May 27 21:02:56 2017
+++ src/sys/netcan/can_proto.c	Sat Sep  3 02:07:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: can_proto.c,v 1.2 2017/05/27 21:02:56 bouyer Exp $	*/
+/*	$NetBSD: can_proto.c,v 1.3 2022/09/03 02:07:32 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: can_proto.c,v 1.2 2017/05/27 21:02:56 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: can_proto.c,v 1.3 2022/09/03 02:07:32 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -68,7 +68,6 @@ struct domain candomain = {
 	.dom_externalize = NULL, .dom_dispose = NULL,
 	.dom_protosw = cansw,
 	.dom_protoswNPROTOSW = &cansw[__arraycount(cansw)],
-	.dom_ifqueues = { &canintrq, NULL },
 	.dom_link = { NULL },
 	.dom_mowner = MOWNER_INIT("",""),
 	.dom_sa_cmpofs = offsetof(struct sockaddr_can, can_ifindex),
Index: src/sys/netcan/can_var.h
diff -u src/sys/netcan/can_var.h:1.2 src/sys/netcan/can_var.h:1.3
--- src/sys/netcan/can_var.h:1.2	Sat May 27 21:02:56 2017
+++ src/sys/netcan/can_var.h	Sat Sep  3 02:07:32 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: can_var.h,v 1.2 2017/05/27 21:02:56 bouyer Exp $	*/
+/*	$NetBSD: can_var.h,v 1.3 2022/09/03 02:07:32 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
@@ -54,7 +54,6 @@ struct canif_softc {
 	uint32_t csc_linkmodes;
 };
 
-extern struct ifqueue canintrq;
 extern struct domain candomain;
 
 extern const struct pr_usrreqs can_usrreqs;
@@ -67,7 +66,6 @@ void can_input(struct ifnet *, struct mb
 void *can_ctlinput(int, struct sockaddr *, void *);
 int can_ctloutput(int, struct socket *, struct sockopt *);
 void can_init(void);
-void canintr(void);
 void can_bpf_mtap(struct ifnet *, struct mbuf *, bool);
 
 #endif

Index: src/sys/rump/net/lib/libnetcan/netcan_component.c
diff -u src/sys/rump/net/lib/libnetcan/netcan_component.c:1.3 src/sys/rump/net/lib/libnetcan/netcan_component.c:1.4
--- src/sys/rump/net/lib/libnetcan/netcan_component.c:1.3	Tue Jul 21 18:38:18 2020
+++ src/sys/rump/net/lib/libnetcan/netcan_component.c	Sat Sep  3 02:07:33 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: netcan_component.c,v 1.3 2020/07/21 18:38:18 pgoyette Exp $	*/
+/*	$NetBSD: netcan_component.c,v 1.4 2022/09/03 02:07:33 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netcan_component.c,v 1.3 2020/07/21 18:38:18 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netcan_component.c,v 1.4 2022/09/03 02:07:33 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/domain.h>
@@ -42,5 +42,4 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET)
 	extern struct domain candomain;
 
 	domain_attach(&candomain);
-	rump_netisr_register(NETISR_CAN, canintr);
 }

Reply via email to