From 4366cfe9caf2d1938dcd9805545e03d310ec83b9 Mon Sep 17 00:00:00 2001 From: purplerain Date: Mon, 2 Oct 2023 04:00:10 +0000 Subject: [PATCH] sync code with last improvements from OpenBSD --- etc/rc | 6 ++- etc/skel/dot.version | 2 +- etc/skel/dot.xsession | 26 +++++++++- lib/libc/sys/sysctl.2 | 19 ++++++- lib/libcrypto/asn1/a_time_tm.c | 4 +- lib/libcrypto/man/ASRange_new.3 | 6 +-- lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 | 10 ++-- lib/libcrypto/man/IPAddressRange_new.3 | 13 +++-- lib/libcrypto/man/X509v3_addr_add_inherit.3 | 8 +-- lib/libcrypto/man/s2i_ASN1_INTEGER.3 | 9 ++-- regress/lib/libcrypto/x509/constraints.c | 3 +- sys/dev/pci/if_aq_pci.c | 25 ++++++--- sys/dev/sdmmc/sdhc.c | 19 +++++-- sys/dev/sdmmc/sdhcreg.h | 4 +- sys/dev/usb/ucom.c | 56 ++++++++++++++++++++- sys/dev/usb/ucomvar.h | 4 +- sys/dev/usb/usb_subr.c | 55 +++++++++++++++++++- sys/dev/usb/usbdi.h | 5 +- sys/kern/kern_sysctl.c | 13 ++++- sys/sys/sysctl.h | 4 +- 20 files changed, 247 insertions(+), 44 deletions(-) diff --git a/etc/rc b/etc/rc index ea30a76ae..9d87fac8c 100644 --- a/etc/rc +++ b/etc/rc @@ -1,4 +1,4 @@ -# $OpenBSD: rc,v 1.571 2023/04/26 14:28:09 phessler Exp $ +# $OpenBSD: rc,v 1.572 2023/10/01 20:15:23 naddy Exp $ # System startup script run by init on autoboot or after single-user. # Output and error are redirected to console by init, and the console is the @@ -137,6 +137,7 @@ make_keys() { local _isakmpd_pub=/etc/isakmpd/local.pub local _iked_key=/etc/iked/private/local.key local _iked_pub=/etc/iked/local.pub + local _ssh_pub=/etc/ssh/ssh_host_ed25519_key.pub _show_ssh_fp=false if [[ ! -f $_isakmpd_key ]]; then echo -n "openssl: generating isakmpd RSA keys... " @@ -162,7 +163,10 @@ make_keys() { fi fi + [[ -f $_ssh_pub ]] || _show_ssh_fp=true ssh-keygen -A + $_show_ssh_fp && ssh-keygen -lf $_ssh_pub | + (read sz fp comm type && echo "sshd: $type $fp") if [[ ! -f /etc/soii.key ]]; then openssl rand -hex 16 > /etc/soii.key && diff --git a/etc/skel/dot.version b/etc/skel/dot.version index e2d2ae9f7..8a32bb5c6 100644 --- a/etc/skel/dot.version +++ b/etc/skel/dot.version @@ -1 +1 @@ -# SecBSD 1.4-f463301edc: Thu Sep 28 00:00:00 UTC 2023 (Tezcatlipoca) +# SecBSD 1.4-d30837c: Mon Oct 2 02:35:45 UTC 2023 (Tezcatlipoca) diff --git a/etc/skel/dot.xsession b/etc/skel/dot.xsession index e261ba725..1ffb089b8 100644 --- a/etc/skel/dot.xsession +++ b/etc/skel/dot.xsession @@ -1,4 +1,4 @@ -# $SecBSD: dot.xsession,v 0.2 2022/12/21 00:00:00 secbsd Exp $ +# $SecBSD: dot.xsession,v 0.3 2023/10/02 03:12:22 purplerain Exp $ # # This file is for testing purposes only. @@ -8,6 +8,30 @@ if [ -x /usr/local/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ]; then eval `dbus-launch --sh-syntax --exit-with-x11` fi +# cwm + xenodm + termbar +# vi ~/.cwmrc to create default cwm configuration file +# configure according to your needs and save :wq! +# manual: https://man.openbsd.org/cwm.1 +# uncomment the next line to the line exec cwm +#exec xterm -geometry 320x1+0+0 -fa "Spleen:size=16" -bg "black" \ +# -fg grey -fs 12 -name termbar -class termbar \ +# -T termbar -e ~/.termbar & +# +#exec cwm +# rcctl enable xenodm +# rcctl start xenodm +# reboot + + +# MATE Desktop + xenodm +# pkg_add -v mate +# uncomment line below +#exec mate-session +# rcctl enable messagebus xenodm +# rcctl start messagebus xenodm +# reboot + + # XFCE Desktop + xenodm # pkg_add -v xfce xfce-extras consolekit2 # uncomment line below diff --git a/lib/libc/sys/sysctl.2 b/lib/libc/sys/sysctl.2 index 4f78c121a..17ecf7e85 100644 --- a/lib/libc/sys/sysctl.2 +++ b/lib/libc/sys/sysctl.2 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sysctl.2,v 1.52 2023/05/16 21:13:19 jmc Exp $ +.\" $OpenBSD: sysctl.2,v 1.53 2023/10/01 15:58:11 krw Exp $ .\" .\" Copyright (c) 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: May 16 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt SYSCTL 2 .Os .Sh NAME @@ -296,6 +296,7 @@ privileges may change the value. .It Dv HW_SENSORS Ta "node" Ta "not applicable" .It Dv HW_SETPERF Ta "integer" Ta "yes" .It Dv HW_SMT Ta "integer" Ta "yes" +.It DV HW_UCOMNAMES Ta "string" Ta "no" .It Dv HW_USERMEM Ta "integer" Ta "no" .It Dv HW_USERMEM64 Ta "int64_t" Ta "no" .It Dv HW_UUID Ta "string" Ta "no" @@ -396,6 +397,20 @@ is set to If set to 1, enable simultaneous multithreading (SMT) on CPUs that support it. Disabled by default. +.It Dv HW_UCOMNAMES Pq Va hw.ucomnames +A comma-separated list of currently attached +.Xr ucom 4 +devices in the following format: +.Pp +.Sm off +.D1 Sy ucom Ar N : Sy usb Ar bus.route.interface +.Sm on +.Pp +The +.Ar route +consists of five hexadecimal digits and identifies the port +containing the +.Ar interface . .It Dv HW_USERMEM The amount of available non-kernel memory in bytes. This variable is deprecated; use diff --git a/lib/libcrypto/asn1/a_time_tm.c b/lib/libcrypto/asn1/a_time_tm.c index 556e12a36..ea94d2f59 100644 --- a/lib/libcrypto/asn1/a_time_tm.c +++ b/lib/libcrypto/asn1/a_time_tm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_time_tm.c,v 1.30 2023/08/30 10:13:12 job Exp $ */ +/* $OpenBSD: a_time_tm.c,v 1.31 2023/10/01 22:14:36 tb Exp $ */ /* * Copyright (c) 2015 Bob Beck * @@ -503,7 +503,7 @@ ASN1_TIME_compare(const ASN1_TIME *t1, const ASN1_TIME *t2) if (ASN1_time_parse(t1->data, t1->length, &tm1, t1->type) == -1) return -2; - if (ASN1_time_parse(t1->data, t2->length, &tm2, t2->type) == -1) + if (ASN1_time_parse(t2->data, t2->length, &tm2, t2->type) == -1) return -2; return ASN1_time_tm_cmp(&tm1, &tm2); diff --git a/lib/libcrypto/man/ASRange_new.3 b/lib/libcrypto/man/ASRange_new.3 index 53da608cb..5d92a375f 100644 --- a/lib/libcrypto/man/ASRange_new.3 +++ b/lib/libcrypto/man/ASRange_new.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ASRange_new.3,v 1.6 2023/09/28 12:35:31 tb Exp $ +.\" $OpenBSD: ASRange_new.3,v 1.7 2023/10/01 05:20:41 tb Exp $ .\" .\" Copyright (c) 2023 Theo Buehler .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 28 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt ASRANGE_NEW 3 .Os .Sh NAME @@ -328,7 +328,7 @@ object or .Dv NULL if an error occurs. .Pp -The encoding functions +The decoding functions .Fn d2i_ASRange , .Fn d2i_ASIdOrRange , and diff --git a/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 b/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 index 40ed524ff..ba0e4b074 100644 --- a/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 +++ b/lib/libcrypto/man/EVP_CIPHER_CTX_ctrl.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: EVP_CIPHER_CTX_ctrl.3,v 1.1 2023/08/31 17:27:41 schwarze Exp $ +.\" $OpenBSD: EVP_CIPHER_CTX_ctrl.3,v 1.2 2023/10/01 18:23:50 tb Exp $ .\" full merge up to: OpenSSL 5211e094 Nov 11 14:39:11 2014 -0800 .\" .\" This file is a derived work. @@ -67,7 +67,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: August 31 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt EVP_CIPHER_CTX_CTRL 3 .Os .Sh NAME @@ -178,7 +178,9 @@ return the IV length of a cipher when passed an .Vt EVP_CIPHER_CTX or .Vt EVP_CIPHER . -It will return zero if the cipher does not use an IV. +They will return zero if the cipher does not use an IV. +.Fn EVP_CIPHER_CTX_iv_length +can fail and return \-1. The constant .Dv EVP_MAX_IV_LENGTH is the maximum IV length for all ciphers. @@ -220,6 +222,8 @@ return the key length. and .Fn EVP_CIPHER_iv_length return the IV length or zero if the cipher does not use an IV. +.Fn EVP_CIPHER_CTX_iv_length +can fail and return \-1. .Sh SEE ALSO .Xr evp 3 , .Xr EVP_CIPHER_nid 3 , diff --git a/lib/libcrypto/man/IPAddressRange_new.3 b/lib/libcrypto/man/IPAddressRange_new.3 index 6878000ef..3195ebfa9 100644 --- a/lib/libcrypto/man/IPAddressRange_new.3 +++ b/lib/libcrypto/man/IPAddressRange_new.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: IPAddressRange_new.3,v 1.6 2023/09/30 13:58:29 schwarze Exp $ +.\" $OpenBSD: IPAddressRange_new.3,v 1.8 2023/10/01 08:23:58 tb Exp $ .\" .\" Copyright (c) 2023 Theo Buehler .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 30 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt IPADDRESSRANGE_NEW 3 .Os .Sh NAME @@ -113,7 +113,8 @@ ASN.1 BIT STRING of bit size 32 or 128 bits, respectively. The bit size of a prefix is its prefix length; all insignificant zero bits are omitted from the encoding. -An address range is expressed as a pair of BIT STRINGs +Per section 2.1.2, +an address range is expressed as a pair of BIT STRINGs where all the least significant zero bits of the lower bound and all the least significant one bits of the upper bound are omitted. .Pp @@ -162,7 +163,7 @@ object with allocated, empty .Fa min and .Fa max , -thus representing the entire address space. +thus representing the entire address space invalidly as a non-prefix. .Pp .Fn IPAddressRange_free frees @@ -469,6 +470,10 @@ or a value <= 0 if an error occurs. RFC 3779: X.509 Extensions for IP Addresses and AS Identifiers: .Bl -dash -compact .It +section 2.1.1: Encoding of an IP Address or Prefix +.It +section 2.1.2: Encoding of a Range of IP Addresses +.It section 2.2.3: Syntax .It section 2.2.3.1: Type IPAddrBlocks diff --git a/lib/libcrypto/man/X509v3_addr_add_inherit.3 b/lib/libcrypto/man/X509v3_addr_add_inherit.3 index 68923b515..4b2d150c8 100644 --- a/lib/libcrypto/man/X509v3_addr_add_inherit.3 +++ b/lib/libcrypto/man/X509v3_addr_add_inherit.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: X509v3_addr_add_inherit.3,v 1.9 2023/09/30 16:01:18 tb Exp $ +.\" $OpenBSD: X509v3_addr_add_inherit.3,v 1.11 2023/10/01 22:46:21 tb Exp $ .\" .\" Copyright (c) 2023 Theo Buehler .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 30 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt X509V3_ADDR_ADD_INHERIT 3 .Os .Sh NAME @@ -271,7 +271,7 @@ Construct the first extension from RFC 3779, Appendix B. #include #include -const char *prefixes[6] = { +const char *prefixes[] = { "10.0.32/20", "10.0.64/24", "10.1/16", "10.2.48/20", "10.2.64/24", "10.3/16", }; @@ -339,7 +339,7 @@ main(void) if (!X509v3_addr_canonize(addrblocks)) errx(1, "X509v3_addr_canonize"); - /* Create the extension. The 1 indicates that it is critical. */ + /* Create the extension with the correct OID; mark it critical. */ ext = X509V3_EXT_i2d(NID_sbgp_ipAddrBlock, 1, addrblocks); if (ext == NULL) errx(1, "X509V3_EXT_i2d"); diff --git a/lib/libcrypto/man/s2i_ASN1_INTEGER.3 b/lib/libcrypto/man/s2i_ASN1_INTEGER.3 index 87a3d006a..0f0cf2919 100644 --- a/lib/libcrypto/man/s2i_ASN1_INTEGER.3 +++ b/lib/libcrypto/man/s2i_ASN1_INTEGER.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: s2i_ASN1_INTEGER.3,v 1.5 2023/05/12 08:12:09 tb Exp $ +.\" $OpenBSD: s2i_ASN1_INTEGER.3,v 1.6 2023/10/01 10:51:19 tb Exp $ .\" .\" Copyright (c) 2023 Theo Buehler .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 12 2023 $ +.Dd $Mdocdate: October 1 2023 $ .Dt I2S_ASN1_INTEGER 3 .Os .Sh NAME @@ -122,8 +122,8 @@ is then obtained with .Fn i2s_ASN1_OCTET_STRING converts the octets in .Fa aos -into a string where the octets are represented by pairs of colon-separated -hexadecimal digits. +into a string where the octets are colon-separated and +represented as pairs of uppercase hexadecimal digits. .Pp .Fn s2i_ASN1_OCTET_STRING converts the NUL-terminated string @@ -196,6 +196,7 @@ Error codes can sometimes be obtained by .Xr ASN1_INTEGER_new 3 , .Xr ASN1_INTEGER_to_BN 3 , .Xr ASN1_OCTET_STRING_new 3 , +.Xr crypto 3 , .Xr X509V3_get_d2i 3 .Sh HISTORY These functions first appeared in OpenSSL 0.9.4 and diff --git a/regress/lib/libcrypto/x509/constraints.c b/regress/lib/libcrypto/x509/constraints.c index 90b7ffbae..6677b58c1 100644 --- a/regress/lib/libcrypto/x509/constraints.c +++ b/regress/lib/libcrypto/x509/constraints.c @@ -1,4 +1,4 @@ -/* $OpenBSD: constraints.c,v 1.16 2023/09/29 15:53:59 beck Exp $ */ +/* $OpenBSD: constraints.c,v 1.17 2023/10/01 04:48:39 tb Exp $ */ /* * Copyright (c) 2020 Bob Beck * @@ -388,6 +388,7 @@ test_invalid_uri(void) done: return failure; } + static int test_valid_uri(void) { diff --git a/sys/dev/pci/if_aq_pci.c b/sys/dev/pci/if_aq_pci.c index 7632ea7a0..2378806b8 100644 --- a/sys/dev/pci/if_aq_pci.c +++ b/sys/dev/pci/if_aq_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_aq_pci.c,v 1.24 2023/09/19 14:14:35 jsg Exp $ */ +/* $OpenBSD: if_aq_pci.c,v 1.25 2023/10/01 09:03:14 kettenis Exp $ */ /* $NetBSD: if_aq.c,v 1.27 2021/06/16 00:21:18 riastradh Exp $ */ /* @@ -339,6 +339,8 @@ #define TPS_DATA_TCT_REG(i) (0x7110 + (i) * 4) #define TPS_DATA_TCT_CREDIT_MAX 0xFFF0000 #define TPS_DATA_TCT_WEIGHT 0x1FF +#define TPS2_DATA_TCT_CREDIT_MAX 0xFFFF0000 +#define TPS2_DATA_TCT_WEIGHT 0x7FFF /* TPS_DATA_TCT_REG[AQ_TRAFFICCLASS_NUM] 0x7210-0x7230 */ #define TPS_DESC_TCT_REG(i) (0x7210 + (i) * 4) #define TPS_DESC_TCT_CREDIT_MAX 0xFFF0000 @@ -346,6 +348,8 @@ #define AQ_HW_TXBUF_MAX 160 #define AQ_HW_RXBUF_MAX 320 +#define AQ2_HW_TXBUF_MAX 128 +#define AQ2_HW_RXBUF_MAX 192 #define TPO_HWCSUM_REG 0x7800 #define TPO_HWCSUM_L4CSUM_EN (1 << 0) @@ -2760,10 +2764,17 @@ aq_hw_qos_set(struct aq_softc *sc) AQ_WRITE_REG_BIT(sc, TPS_DESC_TC_ARB_MODE_REG, TPS_DESC_TC_ARB_MODE, 0); AQ_WRITE_REG_BIT(sc, TPS_DATA_TC_ARB_MODE_REG, TPS_DATA_TC_ARB_MODE, 0); - AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), - TPS_DATA_TCT_CREDIT_MAX, 0xfff); - AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), - TPS_DATA_TCT_WEIGHT, 0x64); + if (HWTYPE_AQ2_P(sc)) { + AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), + TPS2_DATA_TCT_CREDIT_MAX, 0xfff0); + AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), + TPS2_DATA_TCT_WEIGHT, 0x640); + } else { + AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), + TPS_DATA_TCT_CREDIT_MAX, 0xfff); + AQ_WRITE_REG_BIT(sc, TPS_DATA_TCT_REG(tc), + TPS_DATA_TCT_WEIGHT, 0x64); + } AQ_WRITE_REG_BIT(sc, TPS_DESC_TCT_REG(tc), TPS_DESC_TCT_CREDIT_MAX, 0x50); AQ_WRITE_REG_BIT(sc, TPS_DESC_TCT_REG(tc), @@ -2771,7 +2782,7 @@ aq_hw_qos_set(struct aq_softc *sc) /* Tx buf size */ tc = 0; - buff_size = AQ_HW_TXBUF_MAX; + buff_size = HWTYPE_AQ2_P(sc) ? AQ2_HW_TXBUF_MAX : AQ_HW_TXBUF_MAX; AQ_WRITE_REG_BIT(sc, TPB_TXB_BUFSIZE_REG(tc), TPB_TXB_BUFSIZE, buff_size); AQ_WRITE_REG_BIT(sc, TPB_TXB_THRESH_REG(tc), TPB_TXB_THRESH_HI, @@ -2781,7 +2792,7 @@ aq_hw_qos_set(struct aq_softc *sc) /* QoS Rx buf size per TC */ tc = 0; - buff_size = AQ_HW_RXBUF_MAX; + buff_size = HWTYPE_AQ2_P(sc) ? AQ2_HW_RXBUF_MAX : AQ_HW_RXBUF_MAX; AQ_WRITE_REG_BIT(sc, RPB_RXB_BUFSIZE_REG(tc), RPB_RXB_BUFSIZE, buff_size); AQ_WRITE_REG_BIT(sc, RPB_RXB_XOFF_REG(tc), RPB_RXB_XOFF_EN, 0); diff --git a/sys/dev/sdmmc/sdhc.c b/sys/dev/sdmmc/sdhc.c index dd6e634a3..b231c339e 100644 --- a/sys/dev/sdmmc/sdhc.c +++ b/sys/dev/sdmmc/sdhc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdhc.c,v 1.75 2023/04/19 02:01:02 dlg Exp $ */ +/* $OpenBSD: sdhc.c,v 1.76 2023/10/01 08:56:24 kettenis Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -244,6 +244,7 @@ sdhc_host_found(struct sdhc_softc *sc, bus_space_tag_t iot, struct sdmmcbus_attach_args saa; struct sdhc_host *hp; uint32_t caps; + int major, minor; int error = 1; int max_clock; @@ -310,8 +311,20 @@ sdhc_host_found(struct sdhc_softc *sc, bus_space_tag_t iot, goto err; } - printf("%s: SDHC %d.0, %d MHz base clock\n", DEVNAME(sc), - SDHC_SPEC_VERSION(hp->version) + 1, hp->clkbase / 1000); + switch (SDHC_SPEC_VERSION(hp->version)) { + case SDHC_SPEC_VERS_4_10: + major = 4, minor = 10; + break; + case SDHC_SPEC_VERS_4_20: + major = 4, minor = 20; + break; + default: + major = SDHC_SPEC_VERSION(hp->version) + 1, minor = 0; + break; + } + + printf("%s: SDHC %d.%02d, %d MHz base clock\n", DEVNAME(sc), + major, minor, hp->clkbase / 1000); /* * XXX Set the data timeout counter value according to diff --git a/sys/dev/sdmmc/sdhcreg.h b/sys/dev/sdmmc/sdhcreg.h index 9a8916886..8f98a6295 100644 --- a/sys/dev/sdmmc/sdhcreg.h +++ b/sys/dev/sdmmc/sdhcreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sdhcreg.h,v 1.9 2018/09/06 10:15:17 patrick Exp $ */ +/* $OpenBSD: sdhcreg.h,v 1.10 2023/10/01 08:56:24 kettenis Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -201,6 +201,8 @@ #define SDHC_HOST_CTL_VERSION 0xfe #define SDHC_SPEC_VERS_SHIFT 0 #define SDHC_SPEC_VERS_MASK 0xff +#define SDHC_SPEC_VERS_4_10 0x04 +#define SDHC_SPEC_VERS_4_20 0x05 #define SDHC_VENDOR_VERS_SHIFT 8 #define SDHC_VENDOR_VERS_MASK 0xff #define SDHC_SPEC_V1 0 diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index 02ce1534f..5cfd5d961 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ucom.c,v 1.75 2023/09/21 00:05:36 krw Exp $ */ +/* $OpenBSD: ucom.c,v 1.76 2023/10/01 15:58:11 krw Exp $ */ /* $NetBSD: ucom.c,v 1.49 2003/01/01 00:10:25 thorpej Exp $ */ /* @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -153,6 +154,9 @@ const struct cfattach ucom_ca = { ucom_detach, }; +static int ucom_change; +struct rwlock sysctl_ucomlock = RWLOCK_INITIALIZER("sysctlulk"); + void ucom_lock(struct ucom_softc *sc) { @@ -201,6 +205,7 @@ ucom_attach(struct device *parent, struct device *self, void *aux) sc->sc_tty = tp; sc->sc_cua = 0; + ucom_change = 1; rw_init(&sc->sc_lock, "ucomlk"); } @@ -273,6 +278,7 @@ ucom_detach(struct device *self, int flags) sc->sc_tty = NULL; } + ucom_change = 1; return (0); } @@ -1223,7 +1229,53 @@ ucom_cleanup(struct ucom_softc *sc) } } -#endif /* NUCOM > 0 */ +/* + * Update ucom names for export by sysctl. + */ +char * +sysctl_ucominit(void) +{ + static char *ucoms = NULL; + static size_t ucomslen = 0; + char name[34]; /* sizeof(dv_xname) + strlen(":usb000.00000.000,") */ + struct ucom_softc *sc; + int rslt; + unsigned int unit; + uint32_t route; + uint8_t bus, ifaceidx; + + KERNEL_ASSERT_LOCKED(); + + if (rw_enter(&sysctl_ucomlock, RW_WRITE|RW_INTR) != 0) + return NULL; + + if (ucoms == NULL || ucom_change) { + free(ucoms, M_SYSCTL, ucomslen); + ucomslen = ucom_cd.cd_ndevs * sizeof(name); + ucoms = malloc(ucomslen, M_SYSCTL, M_WAITOK | M_ZERO); + for (unit = 0; unit < ucom_cd.cd_ndevs; unit++) { + sc = ucom_cd.cd_devs[unit]; + if (sc == NULL || sc->sc_iface == NULL) + continue; + if (usbd_get_location(sc->sc_uparent, sc->sc_iface, + &bus, &route, &ifaceidx) == -1) + continue; + rslt = snprintf(name, sizeof(name), "%s:usb%u.%05x.%u,", + sc->sc_dev.dv_xname, bus, route, ifaceidx); + if (rslt < sizeof(name) && (strlen(ucoms) + rslt) < ucomslen) + strlcat(ucoms, name, ucomslen); + } + } + + /* Remove trailing ','. */ + if (strlen(ucoms)) + ucoms[strlen(ucoms) - 1] = '\0'; + + rw_exit_write(&sysctl_ucomlock); + + return ucoms; +} +#endif /* NUCOM > 0 */ int ucomprint(void *aux, const char *pnp) diff --git a/sys/dev/usb/ucomvar.h b/sys/dev/usb/ucomvar.h index 0877c2f0d..700c72304 100644 --- a/sys/dev/usb/ucomvar.h +++ b/sys/dev/usb/ucomvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ucomvar.h,v 1.19 2022/04/09 20:07:44 naddy Exp $ */ +/* $OpenBSD: ucomvar.h,v 1.20 2023/10/01 15:58:11 krw Exp $ */ /* $NetBSD: ucomvar.h,v 1.10 2001/12/31 12:15:21 augustss Exp $ */ /* @@ -99,5 +99,7 @@ struct ucom_attach_args { int ucomsubmatch(struct device *, void *, void *); +char *sysctl_ucominit(void); + int ucomprint(void *aux, const char *pnp); void ucom_status_change(struct ucom_softc *); diff --git a/sys/dev/usb/usb_subr.c b/sys/dev/usb/usb_subr.c index 3aaa6ab6b..633a676f2 100644 --- a/sys/dev/usb/usb_subr.c +++ b/sys/dev/usb/usb_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb_subr.c,v 1.159 2023/09/11 08:41:27 mvs Exp $ */ +/* $OpenBSD: usb_subr.c,v 1.160 2023/10/01 15:58:11 krw Exp $ */ /* $NetBSD: usb_subr.c,v 1.103 2003/01/10 11:19:13 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */ @@ -1330,6 +1330,59 @@ usbd_fill_deviceinfo(struct usbd_device *dev, struct usb_device_info *di) sizeof(di->udi_serial)); } +int +usbd_get_routestring(struct usbd_device *dev, uint32_t *route) +{ + struct usbd_device *hub; + uint32_t r; + uint8_t port; + + /* + * Calculate the Route String. Assume that there is no hub with + * more than 15 ports and that they all have a depth < 6. See + * section 8.9 of USB 3.1 Specification for more details. + */ + r = dev->powersrc ? dev->powersrc->portno : 0; + for (hub = dev->myhub; hub && hub->depth; hub = hub->myhub) { + port = hub->powersrc ? hub->powersrc->portno : 0; + if (port > 15) + return -1; + r <<= 4; + r |= port; + } + + *route = r; + return 0; +} + +int +usbd_get_location(struct usbd_device *dev, struct usbd_interface *iface, + uint8_t *bus, uint32_t *route, uint8_t *ifaceidx) +{ + int i; + uint32_t r; + + if (dev == NULL || usbd_is_dying(dev) || + dev->cdesc == NULL || + dev->cdesc->bNumInterfaces == 0 || + dev->bus == NULL || + dev->bus->usbctl == NULL || + dev->myhub == NULL || + dev->powersrc == NULL) + return -1; + + for(i = 0; i < dev->cdesc->bNumInterfaces; i++) { + if (iface == &dev->ifaces[i]) { + *bus = dev->bus->usbctl->dv_unit; + *route = (usbd_get_routestring(dev, &r)) ? 0 : r; + *ifaceidx = i; + return 0; + } + } + + return -1; +} + /* Retrieve a complete descriptor for a certain device and index. */ usb_config_descriptor_t * usbd_get_cdesc(struct usbd_device *dev, int index, u_int *lenp) diff --git a/sys/dev/usb/usbdi.h b/sys/dev/usb/usbdi.h index 030a6a5cd..1692e28d8 100644 --- a/sys/dev/usb/usbdi.h +++ b/sys/dev/usb/usbdi.h @@ -1,4 +1,4 @@ -/* $OpenBSD: usbdi.h,v 1.72 2022/02/16 06:23:42 anton Exp $ */ +/* $OpenBSD: usbdi.h,v 1.73 2023/10/01 15:58:12 krw Exp $ */ /* $NetBSD: usbdi.h,v 1.62 2002/07/11 21:14:35 augustss Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.h,v 1.18 1999/11/17 22:33:49 n_hibma Exp $ */ @@ -130,6 +130,9 @@ usb_device_descriptor_t *usbd_get_device_descriptor(struct usbd_device *dev); usbd_status usbd_set_interface(struct usbd_interface *, int); int usbd_get_no_alts(usb_config_descriptor_t *, int); void usbd_fill_deviceinfo(struct usbd_device *, struct usb_device_info *); +int usbd_get_routestring(struct usbd_device *, uint32_t *); +int usbd_get_location(struct usbd_device *, struct usbd_interface *, uint8_t *, + uint32_t *, uint8_t *); usb_config_descriptor_t *usbd_get_cdesc(struct usbd_device *, int, u_int *); int usbd_get_interface_altindex(struct usbd_interface *iface); diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index cee23eb7e..ee4149412 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.419 2023/09/16 09:33:27 mpi Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.420 2023/10/01 15:58:12 krw Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -86,6 +86,8 @@ #include +#include + #include #include #include @@ -116,6 +118,7 @@ #include "audio.h" #include "dt.h" #include "pf.h" +#include "ucom.h" #include "video.h" extern struct forkstat forkstat; @@ -768,6 +771,14 @@ hw_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case HW_ALLOWPOWERDOWN: return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen, &allowpowerdown)); +#if NUCOM > 0 + case HW_UCOMNAMES: { + const char *str = sysctl_ucominit(); + if (str == NULL) + return EINVAL; + return (sysctl_rdstring(oldp, oldlenp, newp, str)); + } +#endif /* NUCOM > 0 */ #ifdef __HAVE_CPU_TOPOLOGY case HW_SMT: return (sysctl_hwsmt(oldp, oldlenp, newp, newlen)); diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 083113087..7e9f19805 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.234 2023/07/04 11:14:00 jsg Exp $ */ +/* $OpenBSD: sysctl.h,v 1.235 2023/10/01 15:58:12 krw Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -949,6 +949,7 @@ struct kinfo_file { #define HW_NCPUONLINE 25 /* int: number of cpus being used */ #define HW_POWER 26 /* int: machine has wall-power */ #define HW_BATTERY 27 /* node: battery */ +#define HW_UCOMNAMES 28 /* strings: ucom names */ #define HW_MAXID 30 /* number of valid hw ids */ #define CTL_HW_NAMES { \ @@ -980,6 +981,7 @@ struct kinfo_file { { "ncpuonline", CTLTYPE_INT }, \ { "power", CTLTYPE_INT }, \ { "battery", CTLTYPE_NODE }, \ + { "ucomnames", CTLTYPE_STRING }, \ } /*