CVS commit: src/sys/net

2022-11-24 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Nov 25 06:18:42 UTC 2022

Modified Files:
src/sys/net: if.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.527 -r1.528 src/sys/net/if.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/if.c
diff -u src/sys/net/if.c:1.527 src/sys/net/if.c:1.528
--- src/sys/net/if.c:1.527	Mon Oct 24 08:11:25 2022
+++ src/sys/net/if.c	Fri Nov 25 06:18:42 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.527 2022/10/24 08:11:25 msaitoh Exp $	*/
+/*	$NetBSD: if.c,v 1.528 2022/11/25 06:18:42 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.527 2022/10/24 08:11:25 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.528 2022/11/25 06:18:42 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -367,18 +367,21 @@ ifinit_post(void)
 ifnet_t *
 if_alloc(u_char type)
 {
+
 	return kmem_zalloc(sizeof(ifnet_t), KM_SLEEP);
 }
 
 void
 if_free(ifnet_t *ifp)
 {
+
 	kmem_free(ifp, sizeof(ifnet_t));
 }
 
 void
 if_initname(struct ifnet *ifp, const char *name, int unit)
 {
+
 	(void)snprintf(ifp->if_xname, sizeof(ifp->if_xname),
 	"%s%d", name, unit);
 }
@@ -483,7 +486,8 @@ if_dl_create(const struct ifnet *ifp, co
 
 	namelen = strlen(ifp->if_xname);
 	addrlen = ifp->if_addrlen;
-	socksize = roundup(sockaddr_dl_measure(namelen, addrlen), sizeof(long));
+	socksize = roundup(sockaddr_dl_measure(namelen, addrlen),
+	sizeof(long));
 	ifasize = sizeof(*ifa) + 2 * socksize;
 	ifa = malloc(ifasize, M_IFADDR, M_WAITOK | M_ZERO);
 
@@ -641,8 +645,7 @@ if_getindex(ifnet_t *ifp)
 	char xnamebuf[HOOKNAMSIZ];
 
 	ifp->if_index_gen = index_gen++;
-	snprintf(xnamebuf, sizeof(xnamebuf),
-	"%s-lshk", ifp->if_xname);
+	snprintf(xnamebuf, sizeof(xnamebuf), "%s-lshk", ifp->if_xname);
 	ifp->if_linkstate_hooks = simplehook_create(IPL_NET,
 	xnamebuf);
 
@@ -669,9 +672,8 @@ if_getindex(ifnet_t *ifp)
 			 * slot in ifindex2ifnet[], then there
 			 * there are too many (>65535) interfaces.
 			 */
-			if (hitlimit) {
+			if (hitlimit)
 panic("too many interfaces");
-			}
 			hitlimit = true;
 			if_index = 1;
 		}
@@ -1064,8 +1066,9 @@ if_snd_is_used(struct ifnet *ifp)
 {
 
 	return ALTQ_IS_ENABLED(&ifp->if_snd) ||
-		ifp->if_transmit == if_transmit ||
-		ifp->if_transmit == NULL || ifp->if_transmit == if_nulltransmit;
+	ifp->if_transmit == if_transmit ||
+	ifp->if_transmit == NULL ||
+	ifp->if_transmit == if_nulltransmit;
 }
 
 /*
@@ -1224,7 +1227,8 @@ if_is_deactivated(const struct ifnet *if
 }
 
 void
-if_purgeaddrs(struct ifnet *ifp, int family, void (*purgeaddr)(struct ifaddr *))
+if_purgeaddrs(struct ifnet *ifp, int family,
+void (*purgeaddr)(struct ifaddr *))
 {
 	struct ifaddr *ifa, *nifa;
 	int s;
@@ -1504,7 +1508,8 @@ restart:
 		 * addresses.  (Protocols which might store ifnet
 		 * pointers are marked with PR_PURGEIF.)
 		 */
-		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+		{
 			so.so_proto = pr;
 			if (pr->pr_usrreqs && pr->pr_flags & PR_PURGEIF)
 (void)(*pr->pr_usrreqs->pr_purgeif)(&so, ifp);
@@ -1567,9 +1572,9 @@ static int
 if_clone_create(const char *name)
 {
 	struct if_clone *ifc;
-	int unit;
 	struct ifnet *ifp;
 	struct psref psref;
+	int unit;
 
 	KASSERT(mutex_owned(&if_clone_mtx));
 
@@ -1753,8 +1758,7 @@ if_clone_list(int buf_count, char *buffe
 		goto out;
 	}
 
-	count = (if_cloners_count < buf_count) ?
-	if_cloners_count : buf_count;
+	count = (if_cloners_count < buf_count) ? if_cloners_count : buf_count;
 
 	for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0;
 	 ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) {
@@ -1844,7 +1848,8 @@ ifa_remove(struct ifnet *ifp, struct ifa
 	 * if_is_deactivated indicates ifa_remove is called from if_detach
 	 * where it is safe even if IFNET_LOCK isn't held.
 	 */
-	KASSERT(!if_is_mpsafe(ifp) || if_is_deactivated(ifp) || IFNET_LOCKED(ifp));
+	KASSERT(!if_is_mpsafe(ifp) || if_is_deactivated(ifp) ||
+	IFNET_LOCKED(ifp));
 
 	TAILQ_REMOVE(&ifp->if_addrlist, ifa, ifa_list);
 	IFADDR_WRITER_REMOVE(ifa);
@@ -1889,6 +1894,7 @@ ifa_held(struct ifaddr *ifa)
 static inline int
 equal(const struct sockaddr *sa1, const struct sockaddr *sa2)
 {
+
 	return sockaddr_cmp(sa1, sa2) == 0;
 }
 
@@ -2005,7 +2011,8 @@ ifa_ifwithnet(const struct sockaddr *add
 		IFNET_READER_FOREACH(ifp) {
 			if (if_is_deactivated(ifp))
 continue;
-			ifa = at_ifawithnet((const struct sockaddr_at *)addr, ifp);
+			ifa = at_ifawithnet((const struct sockaddr_at *)addr,
+			ifp);
 			if (ifa == NULL)
 continue;
 			sat2 = (struct sockaddr_at *)ifa->ifa_addr;
@@ -2041,7 +2048,7 @@ ifa_ifwithnet(const struct sockaddr *add
 			}
 

CVS commit: src/sys/net

2022-11-24 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Fri Nov 25 06:18:42 UTC 2022

Modified Files:
src/sys/net: if.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.527 -r1.528 src/sys/net/if.c

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



CVS commit: src/sys/dev/i2c

2022-11-24 Thread Brad Spencer
Module Name:src
Committed By:   brad
Date:   Thu Nov 24 21:07:05 UTC 2022

Modified Files:
src/sys/dev/i2c: bmx280.c

Log Message:
Mention where in the datasheet the compensation algorithms came from.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/bmx280.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/i2c/bmx280.c
diff -u src/sys/dev/i2c/bmx280.c:1.3 src/sys/dev/i2c/bmx280.c:1.4
--- src/sys/dev/i2c/bmx280.c:1.3	Wed Nov 23 23:45:29 2022
+++ src/sys/dev/i2c/bmx280.c	Thu Nov 24 21:07:05 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: bmx280.c,v 1.3 2022/11/23 23:45:29 brad Exp $	*/
+/*	$NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $	*/
 
 /*
  * Copyright (c) 2022 Brad Spencer 
@@ -17,7 +17,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.3 2022/11/23 23:45:29 brad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.4 2022/11/24 21:07:05 brad Exp $");
 
 /*
   Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and
@@ -643,8 +643,13 @@ out:
 	sc->sc_sme = NULL;
 }
 
-/* The conversion algorithms are taken from the Bosch datasheet for
- * the BMX280 and adapted to the envsys infrastructure.
+/* The conversion algorithms are taken from the BMP280 datasheet.  The
+ * same algorithms are used with the BME280.
+ *
+ * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
+ *
+ * Section 3.11.3, page 21
+ *
  */
 
 static int32_t



CVS commit: src/sys/dev/i2c

2022-11-24 Thread Brad Spencer
Module Name:src
Committed By:   brad
Date:   Thu Nov 24 21:07:05 UTC 2022

Modified Files:
src/sys/dev/i2c: bmx280.c

Log Message:
Mention where in the datasheet the compensation algorithms came from.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/bmx280.c

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



CVS commit: src/sys/arch/x86/pci

2022-11-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Nov 24 21:03:38 UTC 2022

Modified Files:
src/sys/arch/x86/pci: amdzentemp.c

Log Message:
match zen3 "cezanne" (ryzen 5000-series APU.)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/pci/amdzentemp.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/x86/pci/amdzentemp.c
diff -u src/sys/arch/x86/pci/amdzentemp.c:1.15 src/sys/arch/x86/pci/amdzentemp.c:1.16
--- src/sys/arch/x86/pci/amdzentemp.c:1.15	Sat Oct  1 15:50:05 2022
+++ src/sys/arch/x86/pci/amdzentemp.c	Thu Nov 24 21:03:38 2022
@@ -1,4 +1,4 @@
-/*  $NetBSD: amdzentemp.c,v 1.15 2022/10/01 15:50:05 msaitoh Exp $ */
+/*  $NetBSD: amdzentemp.c,v 1.16 2022/11/24 21:03:38 mrg Exp $ */
 /*  $OpenBSD: kate.c,v 1.2 2008/03/27 04:52:03 cnst Exp $   */
 
 /*
@@ -53,7 +53,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdzentemp.c,v 1.15 2022/10/01 15:50:05 msaitoh Exp $ ");
+__KERNEL_RCSID(0, "$NetBSD: amdzentemp.c,v 1.16 2022/11/24 21:03:38 mrg Exp $ ");
 
 #include 
 #include 
@@ -398,6 +398,7 @@ amdzentemp_probe_ccd_sensors19h(struct a
 	switch (model) {
 	case 0x00 ... 0x0f: /* Zen3 EPYC "Milan" */
 	case 0x20 ... 0x2f: /* Zen3 Ryzen "Vermeer" */
+	case 0x50 ... 0x5f: /* Zen3 Ryzen "Cezanne" */
 		maxreg = 8;
 		break;
 	case 0x60 ... 0x6f: /* Zen4 Ryzen "Raphael" */



CVS commit: src/sys/arch/x86/pci

2022-11-24 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Nov 24 21:03:38 UTC 2022

Modified Files:
src/sys/arch/x86/pci: amdzentemp.c

Log Message:
match zen3 "cezanne" (ryzen 5000-series APU.)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/pci/amdzentemp.c

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



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

2022-11-24 Thread Brad Spencer
Taylor R Campbell  writes:

[snip]

> The issue here isn't the duration of the delay -- just the mechanism.
> Sleeping for 35ms with kpause(9) is fine, but busy-waiting on the CPU
> for 35ms with delay(9) is not (unless HZ is set to something absurdly
> low like 10 instead of the usual 100, but I doubt that's an important
> use-case to consider here).
>
> In this case, you should use:
>
>   kpause("bmx280", /*intr*/false, MAX(1, mstohz(35)), NULL);

All understood..  the above, however, was not quite right either.  That
delay is related to the over sampling that is set and wasn't a fixed
value.  I made adjustments to scale the amount of time actually needed
to wait with the over sampling setting.  This is the proper thing that
needed to be done in this case.  I do agree that kpause is a better
thing to use here too..  no doubt..

There wasn't any real documentation about this, but it clearly was
something that needed to be considered.  The only reference was a single
table that listed some of the typical and max durations for just *SOME*
of the over sampling setting (worse, yet, this table was removed from
later versions of the docs).  It left out a lot and did not include any
sort of formula.  Though some experimentation I can up with one that
should be workable and allowed for some tuning if it wasn't quite right.

>> was, as one might say, a "surprising development" as the documentation
>> really does not hint that this sort of thing goes on (or was even
>> possible to do).
>
> Can you put a link to the documentation in the source code, and cite
> the sections where you get the complicated formulas like in
> bmx280_compensate_P_int64?

Ya, I can do that.  The three compensation formulas are pulled mostly
literally from the docs.  All I really did was changed the types to
match the kernel names and unglobal'ed some of the variables for the
factory calibration settings.  Peeking at Adafruit's Ardunio code, they
did the same thing.






-- 
Brad Spencer - b...@anduin.eldar.org - KC8VKS - http://anduin.eldar.org


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

2022-11-24 Thread Taylor R Campbell
> Date: Wed, 23 Nov 2022 01:42:13 -0500
> From: Brad Spencer 
> 
> Simon Burge  writes:
> 
> > +   delay(35000);
> >
> > This will spin for 35 milliseconds (per sensor read if I read this
> > correctly).  Can you please look at using kpause(9) for this delay?
> > See some other i2c drivers for examples of this.
> 
> Probably possible, may be a couple of days before I can get to
> it (or not, depends on how holiday prep goes)...
> 
> I have used some of the cv_timedwait stuff in the past and didn't know
> about kpause which seems to be suited to what I need to do.  Almost all
> sensor chips require some sort of wait after a command is sent, but this
> one was particularly frustrating about it.

The issue here isn't the duration of the delay -- just the mechanism.
Sleeping for 35ms with kpause(9) is fine, but busy-waiting on the CPU
for 35ms with delay(9) is not (unless HZ is set to something absurdly
low like 10 instead of the usual 100, but I doubt that's an important
use-case to consider here).

In this case, you should use:

kpause("bmx280", /*intr*/false, MAX(1, mstohz(35)), NULL);

> This
> was, as one might say, a "surprising development" as the documentation
> really does not hint that this sort of thing goes on (or was even
> possible to do).

Can you put a link to the documentation in the source code, and cite
the sections where you get the complicated formulas like in
bmx280_compensate_P_int64?