CVS commit: src/sys/dev/onewire
Module Name:src Committed By: mlelstv Date: Mon Dec 11 13:30:33 UTC 2023 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: Don't unregister envsys when not registered. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/onewire/owtemp.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/onewire/owtemp.c diff -u src/sys/dev/onewire/owtemp.c:1.21 src/sys/dev/onewire/owtemp.c:1.22 --- src/sys/dev/onewire/owtemp.c:1.21 Tue Oct 10 19:21:38 2023 +++ src/sys/dev/onewire/owtemp.c Mon Dec 11 13:30:33 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: owtemp.c,v 1.21 2023/10/10 19:21:38 kardel Exp $ */ +/* $NetBSD: owtemp.c,v 1.22 2023/12/11 13:30:33 mlelstv Exp $ */ /* $OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ /*- @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.21 2023/10/10 19:21:38 kardel Exp $"); +__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.22 2023/12/11 13:30:33 mlelstv Exp $"); #include #include @@ -161,6 +161,7 @@ owtemp_attach(device_t parent, device_t "%s S/N %012" PRIx64, sc->sc_chipname, ONEWIRE_ROM_SN(sc->sc_rom)); if (sysmon_envsys_sensor_attach(sc->sc_sme, >sc_sensor)) { sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } @@ -172,6 +173,7 @@ owtemp_attach(device_t parent, device_t if (sysmon_envsys_register(sc->sc_sme)) { aprint_error_dev(self, "unable to register with sysmon\n"); sysmon_envsys_destroy(sc->sc_sme); + sc->sc_sme = NULL; return; } @@ -183,7 +185,8 @@ owtemp_detach(device_t self, int flags) { struct owtemp_softc *sc = device_private(self); - sysmon_envsys_unregister(sc->sc_sme); + if (sc->sc_sme != NULL) + sysmon_envsys_unregister(sc->sc_sme); evcnt_detach(>sc_ev_rsterr); evcnt_detach(>sc_ev_update); evcnt_detach(>sc_ev_crcerr);
CVS commit: src/sys/dev/onewire
Module Name:src Committed By: mlelstv Date: Mon Dec 11 13:30:33 UTC 2023 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: Don't unregister envsys when not registered. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/sys/dev/onewire/owtemp.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/onewire
Module Name:src Committed By: kardel Date: Tue Oct 10 19:21:39 UTC 2023 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: PR kern/57088: add missing "onewire" link dependency Thanks Lloyd for pointing me to this PR as I independently fixed the missing module functionality (and also missing the link dependency). To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/onewire/owtemp.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/onewire
Module Name:src Committed By: kardel Date: Tue Oct 10 19:21:39 UTC 2023 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: PR kern/57088: add missing "onewire" link dependency Thanks Lloyd for pointing me to this PR as I independently fixed the missing module functionality (and also missing the link dependency). To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/dev/onewire/owtemp.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/onewire/owtemp.c diff -u src/sys/dev/onewire/owtemp.c:1.20 src/sys/dev/onewire/owtemp.c:1.21 --- src/sys/dev/onewire/owtemp.c:1.20 Sun Aug 27 13:20:09 2023 +++ src/sys/dev/onewire/owtemp.c Tue Oct 10 19:21:38 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: owtemp.c,v 1.20 2023/08/27 13:20:09 kardel Exp $ */ +/* $NetBSD: owtemp.c,v 1.21 2023/10/10 19:21:38 kardel Exp $ */ /* $OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ /*- @@ -51,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.20 2023/08/27 13:20:09 kardel Exp $"); +__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.21 2023/10/10 19:21:38 kardel Exp $"); #include #include @@ -318,7 +318,7 @@ owtemp_decode_ds1920(const uint8_t *buf) return (temp + 27315); } -MODULE(MODULE_CLASS_DRIVER, owtemp, NULL); +MODULE(MODULE_CLASS_DRIVER, owtemp, "onewire"); #ifdef _MODULE #include "ioconf.c"
CVS commit: src/sys/dev/onewire
Module Name:src Committed By: ad Date: Sat Nov 30 23:06:52 UTC 2019 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: Make owtemp reliable for me: - Don't do the calculation if there is a CRC error. - If we get any kind of error during a refresh, retry up to three times. - Add event counters to report what's going on. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/dev/onewire/owtemp.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/onewire
Module Name:src Committed By: ad Date: Sat Nov 30 23:06:52 UTC 2019 Modified Files: src/sys/dev/onewire: owtemp.c Log Message: Make owtemp reliable for me: - Don't do the calculation if there is a CRC error. - If we get any kind of error during a refresh, retry up to three times. - Add event counters to report what's going on. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/sys/dev/onewire/owtemp.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/onewire/owtemp.c diff -u src/sys/dev/onewire/owtemp.c:1.18 src/sys/dev/onewire/owtemp.c:1.19 --- src/sys/dev/onewire/owtemp.c:1.18 Fri Oct 25 16:25:14 2019 +++ src/sys/dev/onewire/owtemp.c Sat Nov 30 23:06:52 2019 @@ -1,6 +1,35 @@ -/* $NetBSD: owtemp.c,v 1.18 2019/10/25 16:25:14 martin Exp $ */ +/* $NetBSD: owtemp.c,v 1.19 2019/11/30 23:06:52 ad Exp $ */ /* $OpenBSD: owtemp.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ +/*- + * Copyright (c) 2019 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + /* * Copyright (c) 2006 Alexander Yurchenko * @@ -22,7 +51,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.18 2019/10/25 16:25:14 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: owtemp.c,v 1.19 2019/11/30 23:06:52 ad Exp $"); #include #include @@ -51,14 +80,20 @@ struct owtemp_softc { uint32_t (*sc_owtemp_decode)(const uint8_t *); intsc_dying; + + struct evcnt sc_ev_update; + struct evcnt sc_ev_rsterr; + struct evcnt sc_ev_crcerr; }; static int owtemp_match(device_t, cfdata_t, void *); static void owtemp_attach(device_t, device_t, void *); static int owtemp_detach(device_t, int); static int owtemp_activate(device_t, enum devact); - -static void owtemp_update(void *); +static bool owtemp_update(struct owtemp_softc *sc, uint32_t *temp); +static void owtemp_refresh(struct sysmon_envsys *, envsys_data_t *); +static uint32_t owtemp_decode_ds18b20(const uint8_t *); +static uint32_t owtemp_decode_ds1920(const uint8_t *); CFATTACH_DECL_NEW(owtemp, sizeof(struct owtemp_softc), owtemp_match, owtemp_attach, owtemp_detach, owtemp_activate); @@ -71,10 +106,7 @@ static const struct onewire_matchfam owt { ONEWIRE_FAMILY_DS1822 }, }; -static void owtemp_refresh(struct sysmon_envsys *, envsys_data_t *); - -static uint32_t owtemp_decode_ds18b20(const uint8_t *); -static uint32_t owtemp_decode_ds1920(const uint8_t *); +int owtemp_retries = 3; static int owtemp_match(device_t parent, cfdata_t match, void *aux) @@ -110,6 +142,13 @@ owtemp_attach(device_t parent, device_t break; } + evcnt_attach_dynamic(>sc_ev_update, EVCNT_TYPE_MISC, NULL, + device_xname(self), "update"); + evcnt_attach_dynamic(>sc_ev_rsterr, EVCNT_TYPE_MISC, NULL, + device_xname(self), "reset error"); + evcnt_attach_dynamic(>sc_ev_crcerr, EVCNT_TYPE_MISC, NULL, + device_xname(self), "crc error"); + sc->sc_sme = sysmon_envsys_create(); /* Initialize sensor */ @@ -144,6 +183,9 @@ owtemp_detach(device_t self, int flags) struct owtemp_softc *sc = device_private(self); sysmon_envsys_unregister(sc->sc_sme); + evcnt_detach(>sc_ev_rsterr); + evcnt_detach(>sc_ev_update); + evcnt_detach(>sc_ev_crcerr); return 0; } @@ -162,18 +204,12 @@ owtemp_activate(device_t self, enum deva } } -static void -owtemp_update(void *arg) +static bool +owtemp_update(struct owtemp_softc *sc, uint32_t *temp) { - struct owtemp_softc *sc = arg; u_int8_t data[9]; - onewire_lock(sc->sc_onewire); -
CVS commit: src/sys/dev/onewire
Module Name:src Committed By: martin Date: Fri Oct 25 16:25:14 UTC 2019 Modified Files: src/sys/dev/onewire: onewire.c onewirereg.h owtemp.c Log Message: PR kern/54617: onewire(4): - Alter locking strategy to avoid deadlock on detach. - Auto bus probe chews CPU. Increase interval from 3s to 10s. - Put temp sensor S/N in dev description so it can be identified. - Use mutex/condvar. Patch from Andrew Doran. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/onewire/onewire.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/onewire/onewirereg.h cvs rdiff -u -r1.17 -r1.18 src/sys/dev/onewire/owtemp.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/onewire/onewire.c diff -u src/sys/dev/onewire/onewire.c:1.16 src/sys/dev/onewire/onewire.c:1.17 --- src/sys/dev/onewire/onewire.c:1.16 Fri Jul 25 08:10:38 2014 +++ src/sys/dev/onewire/onewire.c Fri Oct 25 16:25:14 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: onewire.c,v 1.16 2014/07/25 08:10:38 dholland Exp $ */ +/* $NetBSD: onewire.c,v 1.17 2019/10/25 16:25:14 martin Exp $ */ /* $OpenBSD: onewire.c,v 1.1 2006/03/04 16:27:03 grange Exp $ */ /* @@ -18,7 +18,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: onewire.c,v 1.16 2014/07/25 08:10:38 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: onewire.c,v 1.17 2019/10/25 16:25:14 martin Exp $"); /* * 1-Wire bus driver. @@ -30,8 +30,7 @@ __KERNEL_RCSID(0, "$NetBSD: onewire.c,v #include #include #include -#include -#include +#include #include #include #include @@ -45,18 +44,16 @@ __KERNEL_RCSID(0, "$NetBSD: onewire.c,v #define DPRINTF(x) #endif -//#define ONEWIRE_MAXDEVS 256 -#define ONEWIRE_MAXDEVS 8 -#define ONEWIRE_SCANTIME 3 +int onewire_maxdevs = 8; +int onewire_scantime = 10; /* was 3 seconds - too often */ struct onewire_softc { device_t sc_dev; - struct onewire_bus * sc_bus; - krwlock_t sc_rwlock; + kmutex_t sc_lock; + kcondvar_t sc_scancv; struct lwp * sc_thread; TAILQ_HEAD(, onewire_device) sc_devs; - intsc_dying; }; @@ -64,7 +61,7 @@ struct onewire_device { TAILQ_ENTRY(onewire_device) d_list; device_t d_dev; u_int64_t d_rom; - intd_present; + boold_present; }; static int onewire_match(device_t, cfdata_t, void *); @@ -79,21 +76,6 @@ static void onewire_scan(struct onewire_ CFATTACH_DECL_NEW(onewire, sizeof(struct onewire_softc), onewire_match, onewire_attach, onewire_detach, onewire_activate); -const struct cdevsw onewire_cdevsw = { - .d_open = noopen, - .d_close = noclose, - .d_read = noread, - .d_write = nowrite, - .d_ioctl = noioctl, - .d_stop = nostop, - .d_tty = notty, - .d_poll = nopoll, - .d_mmap = nommap, - .d_kqfilter = nokqfilter, - .d_discard = nodiscard, - .d_flag = D_OTHER -}; - extern struct cfdriver onewire_cd; static int @@ -110,14 +92,19 @@ onewire_attach(device_t parent, device_t sc->sc_dev = self; sc->sc_bus = oba->oba_bus; - rw_init(>sc_rwlock); + mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE); + cv_init(>sc_scancv, "owscan"); TAILQ_INIT(>sc_devs); aprint_normal("\n"); - if (kthread_create(PRI_NONE, 0, NULL, onewire_thread, sc, - >sc_thread, "%s", device_xname(self)) != 0) + if (kthread_create(PRI_NONE, KTHREAD_MUSTJOIN | KTHREAD_MPSAFE, NULL, + onewire_thread, sc, >sc_thread, "%s", device_xname(self)) != 0) { aprint_error_dev(self, "can't create kernel thread\n"); + /* Normally the kthread destroys these. */ + mutex_destroy(>sc_lock); + cv_destroy(>sc_scancv); + } } static int @@ -126,17 +113,17 @@ onewire_detach(device_t self, int flags) struct onewire_softc *sc = device_private(self); int rv; - sc->sc_dying = 1; if (sc->sc_thread != NULL) { - wakeup(sc->sc_thread); - tsleep(>sc_dying, PWAIT, "owdt", 0); + mutex_enter(>sc_lock); + sc->sc_dying = 1; + cv_broadcast(>sc_scancv); + mutex_exit(>sc_lock); + /* Must no longer touch sc_lock nor sc_scancv. */ + kthread_join(sc->sc_thread); } - onewire_lock(sc); //rv = config_detach_children(self, flags); rv = 0; /* XXX riz */ - onewire_unlock(sc); - rw_destroy(>sc_rwlock); return rv; } @@ -170,7 +157,7 @@ onewire_print(void *aux, const char *pnp (uint)ONEWIRE_ROM_FAMILY_TYPE(oa->oa_rom)); else aprint_normal("\"%s\"", famname); - aprint_normal(" sn %012llx", ONEWIRE_ROM_SN(oa->oa_rom)); + aprint_normal(" sn %012" PRIx64, ONEWIRE_ROM_SN(oa->oa_rom)); if (pnp != NULL) aprint_normal(" at %s", pnp); @@ -192,7 +179,7 @@ onewire_lock(void *arg) { struct onewire_softc *sc = arg; - rw_enter(>sc_rwlock, RW_WRITER); + mutex_enter(>sc_lock); } void @@ -200,7 +187,7 @@ onewire_unlock(void *arg) { struct onewire_softc *sc = arg; - rw_exit(>sc_rwlock); + mutex_exit(>sc_lock); } int @@ -209,6 +196,8 @@ onewire_reset(void *arg) struct onewire_softc *sc = arg; struct onewire_bus *bus = sc->sc_bus; + KASSERT(mutex_owned(>sc_lock)); +
CVS commit: src/sys/dev/onewire
Module Name:src Committed By: martin Date: Fri Oct 25 16:25:14 UTC 2019 Modified Files: src/sys/dev/onewire: onewire.c onewirereg.h owtemp.c Log Message: PR kern/54617: onewire(4): - Alter locking strategy to avoid deadlock on detach. - Auto bus probe chews CPU. Increase interval from 3s to 10s. - Put temp sensor S/N in dev description so it can be identified. - Use mutex/condvar. Patch from Andrew Doran. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/onewire/onewire.c cvs rdiff -u -r1.3 -r1.4 src/sys/dev/onewire/onewirereg.h cvs rdiff -u -r1.17 -r1.18 src/sys/dev/onewire/owtemp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.