From e0721d5ae1542c80097f6fcd487736fdfe601233 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Mon, 27 Jul 2020 00:00:34 +0300 Subject: 13003 console: multiple issues related to colors and font loading and switching Reviewed by: Robert Mustacchi Approved by: Dan McDonald --- usr/src/uts/common/sys/font.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/uts/common/sys/font.h b/usr/src/uts/common/sys/font.h index 5733686bf3..f8f154f428 100644 --- a/usr/src/uts/common/sys/font.h +++ b/usr/src/uts/common/sys/font.h @@ -84,9 +84,11 @@ typedef struct bitmap_data { } bitmap_data_t; typedef enum { - FONT_AUTO, - FONT_MANUAL, - FONT_BOOT + FONT_AUTO, /* This font is loaded by software */ + FONT_MANUAL, /* This font is loaded manually by user */ + FONT_BOOT, /* This font was passed to kernel by bootloader */ + FONT_BUILTIN, /* This font was built in at compile time */ + FONT_RELOAD /* This font is marked to be re-read from file */ } FONT_FLAGS; struct fontlist { -- cgit v1.2.3 From 2ad530425ac9cd3f429e64463a85f6f58703061c Mon Sep 17 00:00:00 2001 From: Dan McDonald Date: Thu, 13 Aug 2020 12:54:05 -0400 Subject: 12976 system panics with error in IP module Reviewed by: Andy Fiddaman Reviewed by: Paul Winder Approved by: Robert Mustacchi --- usr/src/uts/common/inet/ip/ipclassifier.c | 9 ++++++- usr/src/uts/common/inet/tcp/tcp.c | 40 +++++++++++++++++++++++++------ usr/src/uts/common/inet/tcp/tcp_output.c | 20 ++++++++++++---- usr/src/uts/common/sys/socket_proto.h | 10 ++++++++ 4 files changed, 67 insertions(+), 12 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/uts/common/inet/ip/ipclassifier.c b/usr/src/uts/common/inet/ip/ipclassifier.c index 09cafcb4e7..26cc629cca 100644 --- a/usr/src/uts/common/inet/ip/ipclassifier.c +++ b/usr/src/uts/common/inet/ip/ipclassifier.c @@ -21,6 +21,7 @@ /* * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2019 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2020 Joyent, Inc. */ /* @@ -2745,7 +2746,11 @@ conn_get_socket_info(conn_t *connp, mib2_socketInfoEntry_t *sie) return (NULL); } - mutex_exit(&connp->conn_lock); + /* + * Continue to hold conn_lock because we don't want to race with an + * in-progress close, which will have set-to-NULL (and destroyed + * upper_handle, aka sonode (and vnode)) BEFORE setting CONN_CLOSING. + */ if (connp->conn_upper_handle != NULL) { vn = (*connp->conn_upcalls->su_get_vnode) @@ -2757,6 +2762,8 @@ conn_get_socket_info(conn_t *connp, mib2_socketInfoEntry_t *sie) flags |= MIB2_SOCKINFO_STREAM; } + mutex_exit(&connp->conn_lock); + if (vn == NULL || VOP_GETATTR(vn, &attr, 0, CRED(), NULL) != 0) { if (vn != NULL) VN_RELE(vn); diff --git a/usr/src/uts/common/inet/tcp/tcp.c b/usr/src/uts/common/inet/tcp/tcp.c index eef7ded43a..6cae350878 100644 --- a/usr/src/uts/common/inet/tcp/tcp.c +++ b/usr/src/uts/common/inet/tcp/tcp.c @@ -21,10 +21,10 @@ /* * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved. - * Copyright 2019 Joyent, Inc. * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2013, 2017 by Delphix. All rights reserved. * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved. + * Copyright 2020 Joyent, Inc. */ /* Copyright (c) 1990 Mentat Inc. */ @@ -1019,10 +1019,23 @@ finish: /* If we have an upper handle (socket), release it */ if (IPCL_IS_NONSTR(connp)) { - ASSERT(connp->conn_upper_handle != NULL); - (*connp->conn_upcalls->su_closed)(connp->conn_upper_handle); + sock_upcalls_t *upcalls = connp->conn_upcalls; + sock_upper_handle_t handle = connp->conn_upper_handle; + + ASSERT(upcalls != NULL); + ASSERT(upcalls->su_closed != NULL); + ASSERT(handle != NULL); + /* + * Set these to NULL first because closed() will free upper + * structures. Acquire conn_lock because an external caller + * like conn_get_socket_info() will upcall if these are + * non-NULL. + */ + mutex_enter(&connp->conn_lock); connp->conn_upper_handle = NULL; connp->conn_upcalls = NULL; + mutex_exit(&connp->conn_lock); + upcalls->su_closed(handle); } } @@ -1421,13 +1434,26 @@ tcp_free(tcp_t *tcp) * nothing to do other than clearing the field. */ if (connp->conn_upper_handle != NULL) { + sock_upcalls_t *upcalls = connp->conn_upcalls; + sock_upper_handle_t handle = connp->conn_upper_handle; + + /* + * Set these to NULL first because closed() will free upper + * structures. Acquire conn_lock because an external caller + * like conn_get_socket_info() will upcall if these are + * non-NULL. + */ + mutex_enter(&connp->conn_lock); + connp->conn_upper_handle = NULL; + connp->conn_upcalls = NULL; + mutex_exit(&connp->conn_lock); if (IPCL_IS_NONSTR(connp)) { - (*connp->conn_upcalls->su_closed)( - connp->conn_upper_handle); + ASSERT(upcalls != NULL); + ASSERT(upcalls->su_closed != NULL); + ASSERT(handle != NULL); + upcalls->su_closed(handle); tcp->tcp_detached = B_TRUE; } - connp->conn_upper_handle = NULL; - connp->conn_upcalls = NULL; } } diff --git a/usr/src/uts/common/inet/tcp/tcp_output.c b/usr/src/uts/common/inet/tcp/tcp_output.c index 7a0472f3dd..086668f435 100644 --- a/usr/src/uts/common/inet/tcp/tcp_output.c +++ b/usr/src/uts/common/inet/tcp/tcp_output.c @@ -22,7 +22,7 @@ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2017 by Delphix. All rights reserved. - * Copyright 2019 Joyent, Inc. + * Copyright 2020 Joyent, Inc. */ /* This file contains all TCP output processing functions. */ @@ -1677,11 +1677,23 @@ finish: /* non-STREAM socket, release the upper handle */ if (IPCL_IS_NONSTR(connp)) { - ASSERT(connp->conn_upper_handle != NULL); - (*connp->conn_upcalls->su_closed) - (connp->conn_upper_handle); + sock_upcalls_t *upcalls = connp->conn_upcalls; + sock_upper_handle_t handle = connp->conn_upper_handle; + + ASSERT(upcalls != NULL); + ASSERT(upcalls->su_closed != NULL); + ASSERT(handle != NULL); + /* + * Set these to NULL first because closed() will free + * upper structures. Acquire conn_lock because an + * external caller like conn_get_socket_info() will + * upcall if these are non-NULL. + */ + mutex_enter(&connp->conn_lock); connp->conn_upper_handle = NULL; connp->conn_upcalls = NULL; + mutex_exit(&connp->conn_lock); + upcalls->su_closed(handle); } } diff --git a/usr/src/uts/common/sys/socket_proto.h b/usr/src/uts/common/sys/socket_proto.h index 4e1a4a0f35..825d0501c7 100644 --- a/usr/src/uts/common/sys/socket_proto.h +++ b/usr/src/uts/common/sys/socket_proto.h @@ -21,6 +21,7 @@ /* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2019 OmniOS Community Edition (OmniOSce) Association. + * Copyright 2020 Joyent, Inc. */ #ifndef _SYS_SOCKET_PROTO_H_ @@ -202,7 +203,16 @@ struct sock_upcalls_s { void (*su_signal_oob)(sock_upper_handle_t, ssize_t); void (*su_zcopy_notify)(sock_upper_handle_t); void (*su_set_error)(sock_upper_handle_t, int); + /* + * NOTE: This function frees upper handle items. Caller cannot + * rely on them after this upcall. + */ void (*su_closed)(sock_upper_handle_t); + /* + * NOTE: This function MUST be implemented without using lower-level + * downcalls or accesses. This allows callers to ensure su_closed() + * upcalls can happen indepdently or concurrently. + */ vnode_t *(*su_get_vnode)(sock_upper_handle_t); }; -- cgit v1.2.3 From df8c2508aa717e719c0726c616d47f2c94a58dab Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Wed, 9 Sep 2020 22:30:42 -0700 Subject: 13119 Want support for SMBIOS 3.4 Change-Id: I88fd5a7e8f5b49b806f27d550bf49921b5fb8a28 --- usr/src/cmd/smbios/smbios.c | 22 +- usr/src/common/smbios/smb_info.c | 42 ++- usr/src/common/smbios/smb_open.c | 1 + usr/src/test/util-tests/tests/smbios/smbios.c | 19 +- usr/src/test/util-tests/tests/smbios/smbios_test.h | 5 + .../util-tests/tests/smbios/smbios_test_slot.c | 375 ++++++++++++++++++--- usr/src/uts/common/sys/smbios.h | 38 ++- usr/src/uts/common/sys/smbios_impl.h | 18 + 8 files changed, 466 insertions(+), 54 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/cmd/smbios/smbios.c b/usr/src/cmd/smbios/smbios.c index 5597e04fc5..dedfe29e9c 100644 --- a/usr/src/cmd/smbios/smbios.c +++ b/usr/src/cmd/smbios/smbios.c @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2017, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -716,7 +717,7 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) oprintf(fp, " Slot Peer %u:\n", i); oprintf(fp, " Segment group: %u\n", peer[i].smblp_group); - oprintf(fp, " Bus/Device/Function: %u/%u/%u", + oprintf(fp, " Bus/Device/Function: %u/%u/%u\n", peer[i].smblp_bus, peer[i].smblp_device, peer[i].smblp_function); oprintf(fp, " Electrical width: %u\n", @@ -725,6 +726,25 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) smbios_info_slot_peers_free(shp, npeers, peer); } + + if (s.smbl_info != 0) { + if (s.smbl_type >= SMB_SLT_PCIE && + s.smbl_type <= SMB_SLT_PCIEG6P) { + oprintf(fp, " PCIe Generation: %d\n", s.smbl_info); + } else { + oprintf(fp, " Slot Type: 0x%x\n", s.smbl_info); + } + } + + if (s.smbl_pwidth != 0) { + desc_printf(smbios_slot_width_desc(s.smbl_pwidth), + fp, " Physical Width: 0x%x", s.smbl_pwidth); + } + + if (s.smbl_pitch != 0) { + oprintf(fp, " Slot Pitch: %u.%u mm\n", s.smbl_pitch / 100, + s.smbl_pitch % 100); + } } static void diff --git a/usr/src/common/smbios/smb_info.c b/usr/src/common/smbios/smb_info.c index 47c19e7fcb..9aba4deba8 100644 --- a/usr/src/common/smbios/smb_info.c +++ b/usr/src/common/smbios/smb_info.c @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright 2019 Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -231,14 +232,25 @@ smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) return (smb_strptr(stp, 0)); } +static void +smb_info_bcopy_offset(const smb_header_t *hp, void *dst, size_t dstlen, + size_t offset) +{ + if (offset >= hp->smbh_len) { + bzero(dst, dstlen); + } else if (offset + dstlen > hp->smbh_len) { + size_t nvalid = MIN(hp->smbh_len - offset, dstlen); + bcopy((char *)hp + offset, dst, nvalid); + bzero((char *)dst + nvalid, dstlen - nvalid); + } else { + bcopy((char *)hp + offset, dst, dstlen); + } +} + static void smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) { - if (dstlen > hp->smbh_len) { - bcopy(hp, dst, hp->smbh_len); - bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len); - } else - bcopy(hp, dst, dstlen); + return (smb_info_bcopy_offset(hp, dst, dstlen, 0)); } smbios_entry_point_t @@ -674,6 +686,8 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) { const smb_struct_t *stp = smb_lookup_id(shp, id); smb_slot_t s; + smb_slot_cont_t cont; + size_t off; if (stp == NULL) return (-1); /* errno is set for us */ @@ -701,6 +715,24 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) sp->smbl_npeers = s.smbsl_npeers; } + if (!smb_libgteq(shp, SMB_VERSION_34)) { + return (0); + } + + /* + * In SMBIOS 3.4, several members were added to follow the variable + * number of peers. These are defined to start at byte 0x14 + 5 * + * npeers. If the table is from before 3.4, we simple zero things out. + * Otherwise we check if the length covers the peers and this addendum + * to include it as the table length is allowed to be less than this and + * not include it. + */ + off = SMB_SLOT_CONT_START + 5 * s.smbsl_npeers; + smb_info_bcopy_offset(stp->smbst_hdr, &cont, sizeof (cont), off); + sp->smbl_info = cont.smbsl_info; + sp->smbl_pwidth = cont.smbsl_pwidth; + sp->smbl_pitch = cont.smbsl_pitch; + return (0); } diff --git a/usr/src/common/smbios/smb_open.c b/usr/src/common/smbios/smb_open.c index 372b2b619b..6747c84499 100644 --- a/usr/src/common/smbios/smb_open.c +++ b/usr/src/common/smbios/smb_open.c @@ -231,6 +231,7 @@ smbios_bufopen(const smbios_entry_t *ep, const void *buf, size_t len, case SMB_VERSION_31: case SMB_VERSION_32: case SMB_VERSION_33: + case SMB_VERSION_34: break; default: return (smb_open_error(shp, errp, ESMB_VERSION)); diff --git a/usr/src/test/util-tests/tests/smbios/smbios.c b/usr/src/test/util-tests/tests/smbios/smbios.c index 364cb9344f..429d4f81be 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios.c +++ b/usr/src/test/util-tests/tests/smbios/smbios.c @@ -11,6 +11,7 @@ /* * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company */ /* @@ -219,7 +220,23 @@ static const smbios_test_t smbios_tests[] = { .st_mktable = smbios_test_slot_mktable, .st_canopen = B_TRUE, .st_verify = smbios_test_slot_verify, - .st_desc = "slot tests" + .st_desc = "slot 3.2" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_34, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_slot_mktable_34_nopeers, + .st_canopen = B_TRUE, + .st_verify = smbios_test_slot_verify_34_nopeers, + .st_desc = "slot 3.4 without peers" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_34, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_slot_mktable_34_peers, + .st_canopen = B_TRUE, + .st_verify = smbios_test_slot_verify_34_peers, + .st_desc = "slot 3.4 with peers" }, { .st_entry = SMBIOS_ENTRY_POINT_30, .st_tvers = SMB_VERSION, diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test.h b/usr/src/test/util-tests/tests/smbios/smbios_test.h index 62baed7813..c6490f1d13 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test.h +++ b/usr/src/test/util-tests/tests/smbios/smbios_test.h @@ -11,6 +11,7 @@ /* * Copyright 2019 Robert Mustacchi + * Copyright 2020 Oxide Computer Company */ #ifndef _SMBIOS_TEST_H @@ -78,7 +79,11 @@ typedef struct smbios_test { * Test functions */ extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *); +extern boolean_t smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *); +extern boolean_t smbios_test_slot_mktable_34_peers(smbios_test_table_t *); extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); +extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *); +extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *); extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c index d84cc10e91..95a709a088 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c +++ b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c @@ -11,6 +11,7 @@ /* * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company */ /* @@ -20,6 +21,29 @@ #include "smbios_test.h" static const char *smbios_test_name = "The One Slot"; +static uint8_t smbios_slot_bus = 0x42; +static uint8_t smbios_slot_df = 0x23; +static uint8_t smbios_slot_info = 0x65; +static uint16_t smbios_slot_pitch = 0x12af; + +static void +smbios_test_slot_fill(smb_slot_t *slot) +{ + bzero(slot, sizeof (smb_slot_t)); + slot->smbsl_hdr.smbh_type = SMB_TYPE_SLOT; + slot->smbsl_hdr.smbh_len = sizeof (smb_slot_t); + slot->smbsl_name = 1; + slot->smbsl_type = SMB_SLT_PCIE3G16; + slot->smbsl_width = SMB_SLW_16X; + slot->smbsl_length = SMB_SLL_SHORT; + slot->smbsl_id = htole16(1); + slot->smbsl_ch1 = SMB_SLCH1_33V; + slot->smbsl_ch2 = SMB_SLCH2_PME; + slot->smbsl_sg = htole16(1); + slot->smbsl_bus = smbios_slot_bus; + slot->smbsl_df = smbios_slot_df; + slot->smbsl_dbw = SMB_SLW_16X; +} boolean_t smbios_test_slot_mktable(smbios_test_table_t *table) @@ -28,21 +52,11 @@ smbios_test_slot_mktable(smbios_test_table_t *table) smb_slot_peer_t peers[2]; const uint8_t endstring = 0; - slot.smbsl_hdr.smbh_type = SMB_TYPE_SLOT; - slot.smbsl_hdr.smbh_len = sizeof (smb_slot_t) + sizeof (peers); - - slot.smbsl_name = 1; - slot.smbsl_type = SMB_SLT_PCIE3G16; - slot.smbsl_width = SMB_SLW_16X; - slot.smbsl_length = SMB_SLL_SHORT; - slot.smbsl_id = htole16(1); - slot.smbsl_ch1 = SMB_SLCH1_33V; - slot.smbsl_ch2 = SMB_SLCH2_PME; - slot.smbsl_sg = htole16(1); - slot.smbsl_bus = 0x42; - slot.smbsl_df = 0x23; - slot.smbsl_dbw = SMB_SLW_16X; + smbios_test_slot_fill(&slot); + + slot.smbsl_hdr.smbh_len += sizeof (peers); slot.smbsl_npeers = 2; + peers[0].smbspb_group_no = htole16(1); peers[0].smbspb_bus = 0x42; peers[0].smbspb_df = 0x42; @@ -64,6 +78,121 @@ smbios_test_slot_mktable(smbios_test_table_t *table) return (B_TRUE); } +/* + * 3.4 introduced additional data after peers. This verison constructs a variant + * with no peers. + */ +boolean_t +smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *table) +{ + smb_slot_t slot; + smb_slot_cont_t cont; + const uint8_t endstring = 0; + + smbios_test_slot_fill(&slot); + slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + sizeof (cont); + + cont.smbsl_info = smbios_slot_info; + cont.smbsl_pwidth = SMB_SLW_32X; + cont.smbsl_pitch = htole16(smbios_slot_pitch); + + (void) smbios_test_table_append(table, &slot, sizeof (slot)); + /* + * Append a raw zero to fill in the gaps that the peers would have had + * so the cont structure starts at the right offset. + */ + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); + (void) smbios_test_table_append_string(table, smbios_test_name); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_eot(table); + return (B_TRUE); +} + +boolean_t +smbios_test_slot_mktable_34_peers(smbios_test_table_t *table) +{ + smb_slot_t slot; + smb_slot_cont_t cont; + smb_slot_peer_t peers[1]; + const uint8_t endstring = 0; + + smbios_test_slot_fill(&slot); + slot.smbsl_npeers = 1; + slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + 5 * slot.smbsl_npeers + + sizeof (cont); + + peers[0].smbspb_group_no = htole16(1); + peers[0].smbspb_bus = 0x42; + peers[0].smbspb_df = 0x9a; + peers[0].smbspb_width = SMB_SLW_8X; + + cont.smbsl_info = smbios_slot_info; + cont.smbsl_pwidth = SMB_SLW_32X; + cont.smbsl_pitch = htole16(smbios_slot_pitch); + + (void) smbios_test_table_append(table, &slot, sizeof (slot)); + (void) smbios_test_table_append_raw(table, peers, sizeof (peers)); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); + (void) smbios_test_table_append_string(table, smbios_test_name); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_eot(table); + return (B_TRUE); +} + + +static boolean_t +smbios_test_slot_common(smbios_slot_t *slot) +{ + uint_t errs = 0; + + if (strcmp(slot->smbl_name, smbios_test_name) != 0) { + warnx("slot name mismatch, expected %s, found %s", + smbios_test_name, slot->smbl_name); + errs++; + } + + if (slot->smbl_type != SMB_SLT_PCIE3G16) { + warnx("incorrect slot type, found %u", slot->smbl_type); + errs++; + } + + if (slot->smbl_width != SMB_SLW_16X) { + warnx("incorrect slot width, found %u", slot->smbl_width); + errs++; + } + + if (slot->smbl_length != SMB_SLL_SHORT) { + warnx("incorrect slot length, found %u", slot->smbl_length); + errs++; + } + + if (slot->smbl_dbw != SMB_SLW_16X) { + warnx("incorrect slot data bus width, found %u", + slot->smbl_dbw); + errs++; + } + + if (slot->smbl_bus != smbios_slot_bus) { + warnx("incorrect slot bus id, found 0x%x\n", slot->smbl_bus); + } + + if (slot->smbl_df != smbios_slot_df) { + warnx("incorrect slot df id, found 0x%x\n", slot->smbl_df); + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + boolean_t smbios_test_slot_verify(smbios_hdl_t *hdl) { @@ -85,32 +214,7 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) return (B_FALSE); } - /* - * Verify everything we'd expect about the slot. - */ - if (strcmp(slot.smbl_name, smbios_test_name) != 0) { - warnx("slot name mismatch, expected %s, found %s", - smbios_test_name, slot.smbl_name); - errs++; - } - - if (slot.smbl_type != SMB_SLT_PCIE3G16) { - warnx("incorrect slot type, found %u", slot.smbl_type); - errs++; - } - - if (slot.smbl_width != SMB_SLW_16X) { - warnx("incorrect slot width, found %u", slot.smbl_width); - errs++; - } - - if (slot.smbl_length != SMB_SLL_SHORT) { - warnx("incorrect slot length, found %u", slot.smbl_length); - errs++; - } - - if (slot.smbl_dbw != SMB_SLW_16X) { - warnx("incorrect slot data bus width, found %u", slot.smbl_dbw); + if (!smbios_test_slot_common(&slot)) { errs++; } @@ -127,8 +231,7 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) } if (npeers != 2) { - warnx("got wrong number of slot peers: %u\n", - npeers); + warnx("got wrong number of slot peers: %u", npeers); return (B_FALSE); } @@ -180,6 +283,194 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) smbios_info_slot_peers_free(hdl, npeers, peers); + if (slot.smbl_info != 0) { + warnx("found wrong slot info: 0x%x", slot.smbl_info); + errs++; + } + + if (slot.smbl_pwidth != 0) { + warnx("found wrong slot physical width: 0x%x", + slot.smbl_pwidth); + errs++; + } + + if (slot.smbl_pitch != 0) { + warnx("found wrong slot pitch: 0x%x", slot.smbl_pitch); + errs++; + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + +boolean_t +smbios_test_slot_verify_34_nopeers(smbios_hdl_t *hdl) +{ + smbios_struct_t sp; + smbios_slot_t slot; + uint_t npeers; + smbios_slot_peer_t *peers; + uint_t errs = 0; + + if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { + warnx("failed to lookup SMBIOS slot: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { + warnx("failed to get SMBIOS slot info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (!smbios_test_slot_common(&slot)) { + errs++; + } + + if (slot.smbl_npeers != 0) { + warnx("incorrect number of slot peers, found %u", + slot.smbl_npeers); + errs++; + } + + if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { + warnx("failed to get SMBIOS peer info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (npeers != 0) { + warnx("got wrong number of slot peers: %u", npeers); + errs++; + } + + if (peers != NULL) { + warnx("expected NULL peers pointer, but found %p", peers); + errs++; + } + + smbios_info_slot_peers_free(hdl, npeers, peers); + + if (slot.smbl_info != smbios_slot_info) { + warnx("found wrong slot info: 0x%x, expected 0x%x", + slot.smbl_info, smbios_slot_info); + errs++; + } + + if (slot.smbl_pwidth != SMB_SLW_32X) { + warnx("found wrong slot physical width: 0x%x, expected 0x%x", + slot.smbl_pwidth, SMB_SLW_32X); + errs++; + } + + if (slot.smbl_pitch != smbios_slot_pitch) { + warnx("found wrong slot pitch: 0x%x, expected 0x%x", + slot.smbl_pitch, smbios_slot_pitch); + errs++; + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + +boolean_t +smbios_test_slot_verify_34_peers(smbios_hdl_t *hdl) +{ + smbios_struct_t sp; + smbios_slot_t slot; + uint_t npeers; + smbios_slot_peer_t *peers; + uint_t errs = 0; + + if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { + warnx("failed to lookup SMBIOS slot: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { + warnx("failed to get SMBIOS slot info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (!smbios_test_slot_common(&slot)) { + errs++; + } + + if (slot.smbl_npeers != 1) { + warnx("incorrect number of slot peers, found %u", + slot.smbl_npeers); + errs++; + } + + if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { + warnx("failed to get SMBIOS peer info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (npeers != 1) { + warnx("got wrong number of slot peers: %u", npeers); + errs++; + } + + if (peers[0].smblp_group != 1) { + warnx("incorrect group for peer 0: %u", peers[0].smblp_group); + errs++; + } + + if (peers[0].smblp_data_width != SMB_SLW_8X) { + warnx("incorrect data width for peer 0: %u", + peers[0].smblp_data_width); + errs++; + } + + if (peers[0].smblp_bus != 0x42) { + warnx("incorrect PCI bus for peer 0: %u", + peers[0].smblp_bus); + errs++; + } + + if (peers[0].smblp_device != (0x9a >> 3)) { + warnx("incorrect PCI device for peer 0: %u", + peers[0].smblp_device); + errs++; + } + + if (peers[0].smblp_function != (0x9a & 0x7)) { + warnx("incorrect PCI function for peer 0: %u", + peers[0].smblp_function); + errs++; + } + + smbios_info_slot_peers_free(hdl, npeers, peers); + + if (slot.smbl_info != smbios_slot_info) { + warnx("found wrong slot info: 0x%x, expected 0x%x", + slot.smbl_info, smbios_slot_info); + errs++; + } + + if (slot.smbl_pwidth != SMB_SLW_32X) { + warnx("found wrong slot physical width: 0x%x, expected 0x%x", + slot.smbl_pwidth, SMB_SLW_32X); + errs++; + } + + if (slot.smbl_pitch != smbios_slot_pitch) { + warnx("found wrong slot pitch: 0x%x, expected 0x%x", + slot.smbl_pitch, smbios_slot_pitch); + errs++; + } + if (errs > 0) { return (B_FALSE); } diff --git a/usr/src/uts/common/sys/smbios.h b/usr/src/uts/common/sys/smbios.h index 55048d549d..debe1fe72d 100644 --- a/usr/src/uts/common/sys/smbios.h +++ b/usr/src/uts/common/sys/smbios.h @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -527,6 +528,8 @@ typedef struct smbios_processor { #define SMB_PRU_BGA1392 0x3A /* Socket BGA1392 */ #define SMB_PRU_BGA1510 0x3B /* Socket BGA1510 */ #define SMB_PRU_BGA1528 0x3C /* Socket BGA1528 */ +#define SMB_PRU_LGA4189 0x3D /* Socket LGA4189 */ +#define SMB_PRU_LGA1200 0x3E /* Socket LGA1200 */ #define SMB_PRC_RESERVED 0x0001 /* reserved */ #define SMB_PRC_UNKNOWN 0x0002 /* unknown */ @@ -944,6 +947,9 @@ typedef struct smbios_slot { uint8_t smbl_df; /* device/function number */ uint8_t smbl_dbw; /* data bus width */ uint8_t smbl_npeers; /* PCIe bifurcation peers */ + uint8_t smbl_info; /* slot info */ + uint8_t smbl_pwidth; /* slot physical width */ + uint32_t smbl_pitch; /* slot pitch in 10um */ } smbios_slot_t; #define SMB_SLT_OTHER 0x01 /* other */ @@ -976,8 +982,8 @@ typedef struct smbios_slot { #define SMB_SLT_MXM_V 0x1C /* MXM Type IV */ #define SMB_SLT_MXM3_A 0x1D /* MXM 3.0 Type A */ #define SMB_SLT_MXM3_B 0x1E /* MXM 3.0 Type B */ -#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 */ -#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 */ +#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 U.2) */ +#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 (U.2) */ /* * These lines must be on one line for the string generating code. */ @@ -986,6 +992,11 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE_M52_WOBSKO 0x22 /* PCI Express Mini 52-pin without bottom-side keep-outs */ /* END CSTYLED */ #define SMB_SLT_PCIE_M76 0x23 /* PCI Express Mini 72-pin */ +#define SMB_SLT_PCIEG4_SFF 0x24 /* PCI Express Gen 4 SFF-8639 (U.2) */ +#define SMB_SLT_PCIEG5_SFF 0x25 /* PCI Express Gen 5 SFF-8639 (U.2) */ +#define SMB_SLT_OCP3_SFF 0x26 /* OCP NIC 3.0 Small Form Factor */ +#define SMB_SLT_OCP3_LFF 0x27 /* OCP NIC 3.0 Large Form Factor */ +#define SMB_SLT_OCP_PRE 0x28 /* OCP NIC prior to 3.0 */ #define SMB_SLT_CXL1 0x30 /* CXL Flexbus 1.0 */ #define SMB_SLT_PC98_C20 0xA0 /* PC-98/C20 */ #define SMB_SLT_PC98_C24 0xA1 /* PC-98/C24 */ @@ -1016,6 +1027,15 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE4G4 0xBB /* PCI Exp. Gen 4 x4 */ #define SMB_SLT_PCIE4G8 0xBC /* PCI Exp. Gen 4 x8 */ #define SMB_SLT_PCIE4G16 0xBD /* PCI Exp. Gen 4 x16 */ +#define SMB_SLT_PCIE5G 0xBE /* PCI Exp. Gen 5 */ +#define SMB_SLT_PCIE5G1 0xBF /* PCI Exp. Gen 5 x1 */ +#define SMB_SLT_PCIE5G2 0xC0 /* PCI Exp. Gen 5 x2 */ +#define SMB_SLT_PCIE5G4 0xC1 /* PCI Exp. Gen 5 x4 */ +#define SMB_SLT_PCIE5G8 0xC2 /* PCI Exp. Gen 5 x8 */ +#define SMB_SLT_PCIE5G16 0xC3 /* PCI Exp. Gen 5 x16 */ +#define SMB_SLT_PCIEG6P 0xC4 /* PCI Exp. Gen 6+ */ +#define SMB_SLT_EDSFF_E1 0xC5 /* Ent. and DC 1U E1 Form Factor */ +#define SMB_SLT_EDSFF_E3 0xC6 /* Ent. and DC 3" E3 Form Factor */ #define SMB_SLW_OTHER 0x01 /* other */ #define SMB_SLW_UNKNOWN 0x02 /* unknown */ @@ -1041,6 +1061,8 @@ typedef struct smbios_slot { #define SMB_SLL_UNKNOWN 0x02 /* unknown */ #define SMB_SLL_SHORT 0x03 /* short length */ #define SMB_SLL_LONG 0x04 /* long length */ +#define SMB_SLL_2IN5 0x05 /* 2.5" drive form factor */ +#define SMB_SLL_3IN5 0x06 /* 3.5" drive form factor */ #define SMB_SLCH1_UNKNOWN 0x01 /* characteristics unknown */ #define SMB_SLCH1_5V 0x02 /* provides 5.0V */ @@ -1055,6 +1077,9 @@ typedef struct smbios_slot { #define SMB_SLCH2_HOTPLUG 0x02 /* slot supports hot-plug devices */ #define SMB_SLCH2_SMBUS 0x04 /* slot supports SMBus signal */ #define SMB_SLCH2_BIFUR 0x08 /* slot supports PCIe bifurcation */ +#define SMB_SLCH2_SURPREM 0x10 /* slot supports surprise removal */ +#define SMB_SLCH2_CXL1 0x20 /* Flexbus slot, CXL 1.0 capable */ +#define SMB_SLCH2_CXL2 0x40 /* Flexbus slot, CXL 2.0 capable */ /* * SMBIOS 7.10.9 Slot Peer Devices @@ -1178,7 +1203,7 @@ typedef struct smbios_memarray { #define SMB_MAL_PC98C24 0xA1 /* PC-98/C24 add-on card */ #define SMB_MAL_PC98E 0xA2 /* PC-98/E add-on card */ #define SMB_MAL_PC98LB 0xA3 /* PC-98/Local bus add-on card */ -#define SMB_MAL_CXL1 0xA4 /* CXL Flexbus 1.0 add-on card */ +#define SMB_MAL_CXL1 0xA4 /* CXL add-on card */ #define SMB_MAU_OTHER 0x01 /* other */ #define SMB_MAU_UNKNOWN 0x02 /* unknown */ @@ -1285,6 +1310,8 @@ typedef struct smbios_memdevice { #define SMB_MDT_LOGNV 0x1F /* Logical non-volatile device */ #define SMB_MDT_HBM 0x20 /* High Bandwidth Memory */ #define SMB_MDT_HBM2 0x21 /* High Bandwidth Memory 2 */ +#define SMB_MDT_DDR5 0x22 /* DDR5 */ +#define SMB_MDT_LPDDR5 0x23 /* LPDDR5 */ #define SMB_MDF_OTHER 0x0002 /* other */ #define SMB_MDF_UNKNOWN 0x0004 /* unknown */ @@ -1313,7 +1340,7 @@ typedef struct smbios_memdevice { #define SMB_MTECH_NVDIMM_N 0x04 /* NVDIMM-N */ #define SMB_MTECH_NVDIMM_F 0x05 /* NVDIMM-F */ #define SMB_MTECH_NVDIMM_P 0x06 /* NVDIMM-P */ -#define SMB_MTECH_INTCPM 0x07 /* Intel Optane DC Persistent Memory */ +#define SMB_MTECH_INTCPM 0x07 /* Intel Optane persistent memory */ #define SMB_MOMC_RESERVED 0x01 /* reserved */ #define SMB_MOMC_OTHER 0x02 /* other */ @@ -1838,7 +1865,8 @@ typedef struct smbios_memdevice_ext { #define SMB_VERSION_31 0x0301 /* SMBIOS encoding for DMTF spec 3.1 */ #define SMB_VERSION_32 0x0302 /* SMBIOS encoding for DMTF spec 3.2 */ #define SMB_VERSION_33 0x0303 /* SMBIOS encoding for DMTF spec 3.3 */ -#define SMB_VERSION SMB_VERSION_33 /* SMBIOS latest version definitions */ +#define SMB_VERSION_34 0x0304 /* SMBIOS encoding for DMTF spec 3.4 */ +#define SMB_VERSION SMB_VERSION_34 /* SMBIOS latest version definitions */ #define SMB_O_NOCKSUM 0x1 /* do not verify header checksums */ #define SMB_O_NOVERS 0x2 /* do not verify header versions */ diff --git a/usr/src/uts/common/sys/smbios_impl.h b/usr/src/uts/common/sys/smbios_impl.h index 69ca79e94f..4b951b702f 100644 --- a/usr/src/uts/common/sys/smbios_impl.h +++ b/usr/src/uts/common/sys/smbios_impl.h @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -250,8 +251,25 @@ typedef struct smb_slot { uint8_t smbsl_dbw; /* Data bus width */ uint8_t smbsl_npeers; /* Peer bdf groups */ smb_slot_peer_t smbsl_peers[]; /* bifurcation peers */ + /* There are later additions in 3.4+, see smbios_slot_cont_t */ } smb_slot_t; +/* + * After the variable number of smbsl_peers, the smbios_slot has continued in + * size and has the following members defined as of version 3.4. These occur + * starting at byte 14 + 5 * smbsl_npeers. + */ +typedef struct smb_slot_cont { + uint8_t smbsl_info; /* slot info */ + uint8_t smbsl_pwidth; /* slot physical width */ + uint16_t smbsl_pitch; /* slot pitch */ +} smb_slot_cont_t; + +/* + * The first byte that the smb_slot_cont_t is defined to start at. + */ +#define SMB_SLOT_CONT_START 0x14 + /* * SMBIOS implementation structure for SMB_TYPE_OBDEVS. */ -- cgit v1.2.3 From 374fc6954a786a037fbb28b1cd6fd62d05d13a37 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Thu, 10 Sep 2020 08:38:39 -0700 Subject: backout: 13119, 13121 (mistaken integration) --- usr/src/cmd/mdb/intel/amd64/Makefile | 2 +- usr/src/cmd/mdb/intel/amd64/libsmbios/Makefile | 27 -- usr/src/cmd/mdb/intel/ia32/Makefile | 2 +- usr/src/cmd/mdb/intel/ia32/libsmbios/Makefile | 26 -- usr/src/cmd/mdb/intel/modules/smbios/smbios.c | 2 +- usr/src/cmd/smbios/smbios.c | 22 +- usr/src/common/smbios/smb_info.c | 42 +-- usr/src/common/smbios/smb_open.c | 1 - usr/src/pkg/manifests/developer-debug-mdb.mf | 3 - usr/src/test/util-tests/tests/smbios/smbios.c | 19 +- usr/src/test/util-tests/tests/smbios/smbios_test.h | 5 - .../util-tests/tests/smbios/smbios_test_slot.c | 375 +++------------------ usr/src/uts/common/sys/smbios.h | 38 +-- usr/src/uts/common/sys/smbios_impl.h | 18 - 14 files changed, 57 insertions(+), 525 deletions(-) delete mode 100644 usr/src/cmd/mdb/intel/amd64/libsmbios/Makefile delete mode 100644 usr/src/cmd/mdb/intel/ia32/libsmbios/Makefile (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/cmd/mdb/intel/amd64/Makefile b/usr/src/cmd/mdb/intel/amd64/Makefile index 39d3574f15..6ddc6b59d5 100644 --- a/usr/src/cmd/mdb/intel/amd64/Makefile +++ b/usr/src/cmd/mdb/intel/amd64/Makefile @@ -27,7 +27,7 @@ include ../../Makefile.common MODULES = $(COMMON_MODULES_PROC) $(COMMON_MODULES_KVM) -MODULES += disk_label uhci libsmbios +MODULES += disk_label uhci SUBDIRS = mdb mdb_ks kmdb libstandctf libstand .WAIT $(MODULES) diff --git a/usr/src/cmd/mdb/intel/amd64/libsmbios/Makefile b/usr/src/cmd/mdb/intel/amd64/libsmbios/Makefile deleted file mode 100644 index a04ca7df17..0000000000 --- a/usr/src/cmd/mdb/intel/amd64/libsmbios/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2020 Oxide Computer Company -# - -MODULE = libsmbios.so -MDBTGT = proc - -MODSRCS = smbios.c - -include ../../../../Makefile.cmd -include ../../../../Makefile.cmd.64 -include ../../Makefile.amd64 -include ../../../Makefile.module - -MODSRCS_DIR = ../../modules/smbios -LDLIBS += -lsmbios diff --git a/usr/src/cmd/mdb/intel/ia32/Makefile b/usr/src/cmd/mdb/intel/ia32/Makefile index 9d8f9efe87..cb544a52d2 100644 --- a/usr/src/cmd/mdb/intel/ia32/Makefile +++ b/usr/src/cmd/mdb/intel/ia32/Makefile @@ -28,7 +28,7 @@ include ../../Makefile.common MODULES = $(COMMON_MODULES_PROC) $(COMMON_MODULES_PROC_32BIT) -MODULES += disk_label libsmbios +MODULES += disk_label SUBDIRS = mdb .WAIT $(MODULES) diff --git a/usr/src/cmd/mdb/intel/ia32/libsmbios/Makefile b/usr/src/cmd/mdb/intel/ia32/libsmbios/Makefile deleted file mode 100644 index 14491786c2..0000000000 --- a/usr/src/cmd/mdb/intel/ia32/libsmbios/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# -# This file and its contents are supplied under the terms of the -# Common Development and Distribution License ("CDDL"), version 1.0. -# You may only use this file in accordance with the terms of version -# 1.0 of the CDDL. -# -# A full copy of the text of the CDDL should have accompanied this -# source. A copy of the CDDL is also available via the Internet at -# http://www.illumos.org/license/CDDL. -# - -# -# Copyright 2020 Oxide Computer Company -# - -MODULE = libsmbios.so -MDBTGT = proc - -MODSRCS = smbios.c - -include ../../../../Makefile.cmd -include ../../Makefile.ia32 -include ../../../Makefile.module - -MODSRCS_DIR = ../../modules/smbios -LDLIBS += -lsmbios diff --git a/usr/src/cmd/mdb/intel/modules/smbios/smbios.c b/usr/src/cmd/mdb/intel/modules/smbios/smbios.c index 1b692d45b1..429a5fba0e 100644 --- a/usr/src/cmd/mdb/intel/modules/smbios/smbios.c +++ b/usr/src/cmd/mdb/intel/modules/smbios/smbios.c @@ -28,7 +28,7 @@ * _KERNEL. Therefore we have to manually declare an extern delaration for * strerror(). */ -extern char *strerror(int); +extern const char *strerror(int); /* * Take an existing smbios_hdl_t from a dump and slurp out its memory so we can diff --git a/usr/src/cmd/smbios/smbios.c b/usr/src/cmd/smbios/smbios.c index dedfe29e9c..5597e04fc5 100644 --- a/usr/src/cmd/smbios/smbios.c +++ b/usr/src/cmd/smbios/smbios.c @@ -22,7 +22,6 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2017, Joyent, Inc. - * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -717,7 +716,7 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) oprintf(fp, " Slot Peer %u:\n", i); oprintf(fp, " Segment group: %u\n", peer[i].smblp_group); - oprintf(fp, " Bus/Device/Function: %u/%u/%u\n", + oprintf(fp, " Bus/Device/Function: %u/%u/%u", peer[i].smblp_bus, peer[i].smblp_device, peer[i].smblp_function); oprintf(fp, " Electrical width: %u\n", @@ -726,25 +725,6 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) smbios_info_slot_peers_free(shp, npeers, peer); } - - if (s.smbl_info != 0) { - if (s.smbl_type >= SMB_SLT_PCIE && - s.smbl_type <= SMB_SLT_PCIEG6P) { - oprintf(fp, " PCIe Generation: %d\n", s.smbl_info); - } else { - oprintf(fp, " Slot Type: 0x%x\n", s.smbl_info); - } - } - - if (s.smbl_pwidth != 0) { - desc_printf(smbios_slot_width_desc(s.smbl_pwidth), - fp, " Physical Width: 0x%x", s.smbl_pwidth); - } - - if (s.smbl_pitch != 0) { - oprintf(fp, " Slot Pitch: %u.%u mm\n", s.smbl_pitch / 100, - s.smbl_pitch % 100); - } } static void diff --git a/usr/src/common/smbios/smb_info.c b/usr/src/common/smbios/smb_info.c index 9aba4deba8..47c19e7fcb 100644 --- a/usr/src/common/smbios/smb_info.c +++ b/usr/src/common/smbios/smb_info.c @@ -22,7 +22,6 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright 2019 Joyent, Inc. - * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -232,25 +231,14 @@ smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) return (smb_strptr(stp, 0)); } -static void -smb_info_bcopy_offset(const smb_header_t *hp, void *dst, size_t dstlen, - size_t offset) -{ - if (offset >= hp->smbh_len) { - bzero(dst, dstlen); - } else if (offset + dstlen > hp->smbh_len) { - size_t nvalid = MIN(hp->smbh_len - offset, dstlen); - bcopy((char *)hp + offset, dst, nvalid); - bzero((char *)dst + nvalid, dstlen - nvalid); - } else { - bcopy((char *)hp + offset, dst, dstlen); - } -} - static void smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) { - return (smb_info_bcopy_offset(hp, dst, dstlen, 0)); + if (dstlen > hp->smbh_len) { + bcopy(hp, dst, hp->smbh_len); + bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len); + } else + bcopy(hp, dst, dstlen); } smbios_entry_point_t @@ -686,8 +674,6 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) { const smb_struct_t *stp = smb_lookup_id(shp, id); smb_slot_t s; - smb_slot_cont_t cont; - size_t off; if (stp == NULL) return (-1); /* errno is set for us */ @@ -715,24 +701,6 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) sp->smbl_npeers = s.smbsl_npeers; } - if (!smb_libgteq(shp, SMB_VERSION_34)) { - return (0); - } - - /* - * In SMBIOS 3.4, several members were added to follow the variable - * number of peers. These are defined to start at byte 0x14 + 5 * - * npeers. If the table is from before 3.4, we simple zero things out. - * Otherwise we check if the length covers the peers and this addendum - * to include it as the table length is allowed to be less than this and - * not include it. - */ - off = SMB_SLOT_CONT_START + 5 * s.smbsl_npeers; - smb_info_bcopy_offset(stp->smbst_hdr, &cont, sizeof (cont), off); - sp->smbl_info = cont.smbsl_info; - sp->smbl_pwidth = cont.smbsl_pwidth; - sp->smbl_pitch = cont.smbsl_pitch; - return (0); } diff --git a/usr/src/common/smbios/smb_open.c b/usr/src/common/smbios/smb_open.c index 6747c84499..372b2b619b 100644 --- a/usr/src/common/smbios/smb_open.c +++ b/usr/src/common/smbios/smb_open.c @@ -231,7 +231,6 @@ smbios_bufopen(const smbios_entry_t *ep, const void *buf, size_t len, case SMB_VERSION_31: case SMB_VERSION_32: case SMB_VERSION_33: - case SMB_VERSION_34: break; default: return (smb_open_error(shp, errp, ESMB_VERSION)); diff --git a/usr/src/pkg/manifests/developer-debug-mdb.mf b/usr/src/pkg/manifests/developer-debug-mdb.mf index 63c7982c3c..af99982b2c 100644 --- a/usr/src/pkg/manifests/developer-debug-mdb.mf +++ b/usr/src/pkg/manifests/developer-debug-mdb.mf @@ -216,8 +216,6 @@ file path=usr/lib/mdb/proc/$(ARCH64)/libnvpair.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libproc.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libpython$(PYTHON_VERSION).so group=sys \ mode=0555 -$(i386_ONLY)file path=usr/lib/mdb/proc/$(ARCH64)/libsmbios.so group=sys \ - mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libsysevent.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libtopo.so group=sys mode=0555 file path=usr/lib/mdb/proc/$(ARCH64)/libumem.so group=sys mode=0555 @@ -232,7 +230,6 @@ file path=usr/lib/mdb/proc/libcmdutils.so group=sys mode=0555 file path=usr/lib/mdb/proc/libnvpair.so group=sys mode=0555 file path=usr/lib/mdb/proc/libproc.so group=sys mode=0555 file path=usr/lib/mdb/proc/libpython$(PYTHON_VERSION).so group=sys mode=0555 -$(i386_ONLY)file path=usr/lib/mdb/proc/libsmbios.so group=sys mode=0555 file path=usr/lib/mdb/proc/libsysevent.so group=sys mode=0555 file path=usr/lib/mdb/proc/libtopo.so group=sys mode=0555 file path=usr/lib/mdb/proc/libumem.so group=sys mode=0555 diff --git a/usr/src/test/util-tests/tests/smbios/smbios.c b/usr/src/test/util-tests/tests/smbios/smbios.c index 429d4f81be..364cb9344f 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios.c +++ b/usr/src/test/util-tests/tests/smbios/smbios.c @@ -11,7 +11,6 @@ /* * Copyright (c) 2018, Joyent, Inc. - * Copyright 2020 Oxide Computer Company */ /* @@ -220,23 +219,7 @@ static const smbios_test_t smbios_tests[] = { .st_mktable = smbios_test_slot_mktable, .st_canopen = B_TRUE, .st_verify = smbios_test_slot_verify, - .st_desc = "slot 3.2" - }, { - .st_entry = SMBIOS_ENTRY_POINT_30, - .st_tvers = SMB_VERSION_34, - .st_libvers = SMB_VERSION, - .st_mktable = smbios_test_slot_mktable_34_nopeers, - .st_canopen = B_TRUE, - .st_verify = smbios_test_slot_verify_34_nopeers, - .st_desc = "slot 3.4 without peers" - }, { - .st_entry = SMBIOS_ENTRY_POINT_30, - .st_tvers = SMB_VERSION_34, - .st_libvers = SMB_VERSION, - .st_mktable = smbios_test_slot_mktable_34_peers, - .st_canopen = B_TRUE, - .st_verify = smbios_test_slot_verify_34_peers, - .st_desc = "slot 3.4 with peers" + .st_desc = "slot tests" }, { .st_entry = SMBIOS_ENTRY_POINT_30, .st_tvers = SMB_VERSION, diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test.h b/usr/src/test/util-tests/tests/smbios/smbios_test.h index c6490f1d13..62baed7813 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test.h +++ b/usr/src/test/util-tests/tests/smbios/smbios_test.h @@ -11,7 +11,6 @@ /* * Copyright 2019 Robert Mustacchi - * Copyright 2020 Oxide Computer Company */ #ifndef _SMBIOS_TEST_H @@ -79,11 +78,7 @@ typedef struct smbios_test { * Test functions */ extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *); -extern boolean_t smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *); -extern boolean_t smbios_test_slot_mktable_34_peers(smbios_test_table_t *); extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); -extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *); -extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *); extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c index 95a709a088..d84cc10e91 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c +++ b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c @@ -11,7 +11,6 @@ /* * Copyright (c) 2018, Joyent, Inc. - * Copyright 2020 Oxide Computer Company */ /* @@ -21,29 +20,6 @@ #include "smbios_test.h" static const char *smbios_test_name = "The One Slot"; -static uint8_t smbios_slot_bus = 0x42; -static uint8_t smbios_slot_df = 0x23; -static uint8_t smbios_slot_info = 0x65; -static uint16_t smbios_slot_pitch = 0x12af; - -static void -smbios_test_slot_fill(smb_slot_t *slot) -{ - bzero(slot, sizeof (smb_slot_t)); - slot->smbsl_hdr.smbh_type = SMB_TYPE_SLOT; - slot->smbsl_hdr.smbh_len = sizeof (smb_slot_t); - slot->smbsl_name = 1; - slot->smbsl_type = SMB_SLT_PCIE3G16; - slot->smbsl_width = SMB_SLW_16X; - slot->smbsl_length = SMB_SLL_SHORT; - slot->smbsl_id = htole16(1); - slot->smbsl_ch1 = SMB_SLCH1_33V; - slot->smbsl_ch2 = SMB_SLCH2_PME; - slot->smbsl_sg = htole16(1); - slot->smbsl_bus = smbios_slot_bus; - slot->smbsl_df = smbios_slot_df; - slot->smbsl_dbw = SMB_SLW_16X; -} boolean_t smbios_test_slot_mktable(smbios_test_table_t *table) @@ -52,11 +28,21 @@ smbios_test_slot_mktable(smbios_test_table_t *table) smb_slot_peer_t peers[2]; const uint8_t endstring = 0; - smbios_test_slot_fill(&slot); - - slot.smbsl_hdr.smbh_len += sizeof (peers); + slot.smbsl_hdr.smbh_type = SMB_TYPE_SLOT; + slot.smbsl_hdr.smbh_len = sizeof (smb_slot_t) + sizeof (peers); + + slot.smbsl_name = 1; + slot.smbsl_type = SMB_SLT_PCIE3G16; + slot.smbsl_width = SMB_SLW_16X; + slot.smbsl_length = SMB_SLL_SHORT; + slot.smbsl_id = htole16(1); + slot.smbsl_ch1 = SMB_SLCH1_33V; + slot.smbsl_ch2 = SMB_SLCH2_PME; + slot.smbsl_sg = htole16(1); + slot.smbsl_bus = 0x42; + slot.smbsl_df = 0x23; + slot.smbsl_dbw = SMB_SLW_16X; slot.smbsl_npeers = 2; - peers[0].smbspb_group_no = htole16(1); peers[0].smbspb_bus = 0x42; peers[0].smbspb_df = 0x42; @@ -78,121 +64,6 @@ smbios_test_slot_mktable(smbios_test_table_t *table) return (B_TRUE); } -/* - * 3.4 introduced additional data after peers. This verison constructs a variant - * with no peers. - */ -boolean_t -smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *table) -{ - smb_slot_t slot; - smb_slot_cont_t cont; - const uint8_t endstring = 0; - - smbios_test_slot_fill(&slot); - slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + sizeof (cont); - - cont.smbsl_info = smbios_slot_info; - cont.smbsl_pwidth = SMB_SLW_32X; - cont.smbsl_pitch = htole16(smbios_slot_pitch); - - (void) smbios_test_table_append(table, &slot, sizeof (slot)); - /* - * Append a raw zero to fill in the gaps that the peers would have had - * so the cont structure starts at the right offset. - */ - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); - (void) smbios_test_table_append_string(table, smbios_test_name); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - smbios_test_table_append_eot(table); - return (B_TRUE); -} - -boolean_t -smbios_test_slot_mktable_34_peers(smbios_test_table_t *table) -{ - smb_slot_t slot; - smb_slot_cont_t cont; - smb_slot_peer_t peers[1]; - const uint8_t endstring = 0; - - smbios_test_slot_fill(&slot); - slot.smbsl_npeers = 1; - slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + 5 * slot.smbsl_npeers + - sizeof (cont); - - peers[0].smbspb_group_no = htole16(1); - peers[0].smbspb_bus = 0x42; - peers[0].smbspb_df = 0x9a; - peers[0].smbspb_width = SMB_SLW_8X; - - cont.smbsl_info = smbios_slot_info; - cont.smbsl_pwidth = SMB_SLW_32X; - cont.smbsl_pitch = htole16(smbios_slot_pitch); - - (void) smbios_test_table_append(table, &slot, sizeof (slot)); - (void) smbios_test_table_append_raw(table, peers, sizeof (peers)); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); - (void) smbios_test_table_append_string(table, smbios_test_name); - (void) smbios_test_table_append_raw(table, &endstring, - sizeof (endstring)); - smbios_test_table_append_eot(table); - return (B_TRUE); -} - - -static boolean_t -smbios_test_slot_common(smbios_slot_t *slot) -{ - uint_t errs = 0; - - if (strcmp(slot->smbl_name, smbios_test_name) != 0) { - warnx("slot name mismatch, expected %s, found %s", - smbios_test_name, slot->smbl_name); - errs++; - } - - if (slot->smbl_type != SMB_SLT_PCIE3G16) { - warnx("incorrect slot type, found %u", slot->smbl_type); - errs++; - } - - if (slot->smbl_width != SMB_SLW_16X) { - warnx("incorrect slot width, found %u", slot->smbl_width); - errs++; - } - - if (slot->smbl_length != SMB_SLL_SHORT) { - warnx("incorrect slot length, found %u", slot->smbl_length); - errs++; - } - - if (slot->smbl_dbw != SMB_SLW_16X) { - warnx("incorrect slot data bus width, found %u", - slot->smbl_dbw); - errs++; - } - - if (slot->smbl_bus != smbios_slot_bus) { - warnx("incorrect slot bus id, found 0x%x\n", slot->smbl_bus); - } - - if (slot->smbl_df != smbios_slot_df) { - warnx("incorrect slot df id, found 0x%x\n", slot->smbl_df); - } - - if (errs > 0) { - return (B_FALSE); - } - - return (B_TRUE); -} - boolean_t smbios_test_slot_verify(smbios_hdl_t *hdl) { @@ -214,7 +85,32 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) return (B_FALSE); } - if (!smbios_test_slot_common(&slot)) { + /* + * Verify everything we'd expect about the slot. + */ + if (strcmp(slot.smbl_name, smbios_test_name) != 0) { + warnx("slot name mismatch, expected %s, found %s", + smbios_test_name, slot.smbl_name); + errs++; + } + + if (slot.smbl_type != SMB_SLT_PCIE3G16) { + warnx("incorrect slot type, found %u", slot.smbl_type); + errs++; + } + + if (slot.smbl_width != SMB_SLW_16X) { + warnx("incorrect slot width, found %u", slot.smbl_width); + errs++; + } + + if (slot.smbl_length != SMB_SLL_SHORT) { + warnx("incorrect slot length, found %u", slot.smbl_length); + errs++; + } + + if (slot.smbl_dbw != SMB_SLW_16X) { + warnx("incorrect slot data bus width, found %u", slot.smbl_dbw); errs++; } @@ -231,7 +127,8 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) } if (npeers != 2) { - warnx("got wrong number of slot peers: %u", npeers); + warnx("got wrong number of slot peers: %u\n", + npeers); return (B_FALSE); } @@ -283,194 +180,6 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) smbios_info_slot_peers_free(hdl, npeers, peers); - if (slot.smbl_info != 0) { - warnx("found wrong slot info: 0x%x", slot.smbl_info); - errs++; - } - - if (slot.smbl_pwidth != 0) { - warnx("found wrong slot physical width: 0x%x", - slot.smbl_pwidth); - errs++; - } - - if (slot.smbl_pitch != 0) { - warnx("found wrong slot pitch: 0x%x", slot.smbl_pitch); - errs++; - } - - if (errs > 0) { - return (B_FALSE); - } - - return (B_TRUE); -} - -boolean_t -smbios_test_slot_verify_34_nopeers(smbios_hdl_t *hdl) -{ - smbios_struct_t sp; - smbios_slot_t slot; - uint_t npeers; - smbios_slot_peer_t *peers; - uint_t errs = 0; - - if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { - warnx("failed to lookup SMBIOS slot: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { - warnx("failed to get SMBIOS slot info: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (!smbios_test_slot_common(&slot)) { - errs++; - } - - if (slot.smbl_npeers != 0) { - warnx("incorrect number of slot peers, found %u", - slot.smbl_npeers); - errs++; - } - - if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { - warnx("failed to get SMBIOS peer info: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (npeers != 0) { - warnx("got wrong number of slot peers: %u", npeers); - errs++; - } - - if (peers != NULL) { - warnx("expected NULL peers pointer, but found %p", peers); - errs++; - } - - smbios_info_slot_peers_free(hdl, npeers, peers); - - if (slot.smbl_info != smbios_slot_info) { - warnx("found wrong slot info: 0x%x, expected 0x%x", - slot.smbl_info, smbios_slot_info); - errs++; - } - - if (slot.smbl_pwidth != SMB_SLW_32X) { - warnx("found wrong slot physical width: 0x%x, expected 0x%x", - slot.smbl_pwidth, SMB_SLW_32X); - errs++; - } - - if (slot.smbl_pitch != smbios_slot_pitch) { - warnx("found wrong slot pitch: 0x%x, expected 0x%x", - slot.smbl_pitch, smbios_slot_pitch); - errs++; - } - - if (errs > 0) { - return (B_FALSE); - } - - return (B_TRUE); -} - -boolean_t -smbios_test_slot_verify_34_peers(smbios_hdl_t *hdl) -{ - smbios_struct_t sp; - smbios_slot_t slot; - uint_t npeers; - smbios_slot_peer_t *peers; - uint_t errs = 0; - - if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { - warnx("failed to lookup SMBIOS slot: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { - warnx("failed to get SMBIOS slot info: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (!smbios_test_slot_common(&slot)) { - errs++; - } - - if (slot.smbl_npeers != 1) { - warnx("incorrect number of slot peers, found %u", - slot.smbl_npeers); - errs++; - } - - if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { - warnx("failed to get SMBIOS peer info: %s", - smbios_errmsg(smbios_errno(hdl))); - return (B_FALSE); - } - - if (npeers != 1) { - warnx("got wrong number of slot peers: %u", npeers); - errs++; - } - - if (peers[0].smblp_group != 1) { - warnx("incorrect group for peer 0: %u", peers[0].smblp_group); - errs++; - } - - if (peers[0].smblp_data_width != SMB_SLW_8X) { - warnx("incorrect data width for peer 0: %u", - peers[0].smblp_data_width); - errs++; - } - - if (peers[0].smblp_bus != 0x42) { - warnx("incorrect PCI bus for peer 0: %u", - peers[0].smblp_bus); - errs++; - } - - if (peers[0].smblp_device != (0x9a >> 3)) { - warnx("incorrect PCI device for peer 0: %u", - peers[0].smblp_device); - errs++; - } - - if (peers[0].smblp_function != (0x9a & 0x7)) { - warnx("incorrect PCI function for peer 0: %u", - peers[0].smblp_function); - errs++; - } - - smbios_info_slot_peers_free(hdl, npeers, peers); - - if (slot.smbl_info != smbios_slot_info) { - warnx("found wrong slot info: 0x%x, expected 0x%x", - slot.smbl_info, smbios_slot_info); - errs++; - } - - if (slot.smbl_pwidth != SMB_SLW_32X) { - warnx("found wrong slot physical width: 0x%x, expected 0x%x", - slot.smbl_pwidth, SMB_SLW_32X); - errs++; - } - - if (slot.smbl_pitch != smbios_slot_pitch) { - warnx("found wrong slot pitch: 0x%x, expected 0x%x", - slot.smbl_pitch, smbios_slot_pitch); - errs++; - } - if (errs > 0) { return (B_FALSE); } diff --git a/usr/src/uts/common/sys/smbios.h b/usr/src/uts/common/sys/smbios.h index debe1fe72d..55048d549d 100644 --- a/usr/src/uts/common/sys/smbios.h +++ b/usr/src/uts/common/sys/smbios.h @@ -22,7 +22,6 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. - * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -528,8 +527,6 @@ typedef struct smbios_processor { #define SMB_PRU_BGA1392 0x3A /* Socket BGA1392 */ #define SMB_PRU_BGA1510 0x3B /* Socket BGA1510 */ #define SMB_PRU_BGA1528 0x3C /* Socket BGA1528 */ -#define SMB_PRU_LGA4189 0x3D /* Socket LGA4189 */ -#define SMB_PRU_LGA1200 0x3E /* Socket LGA1200 */ #define SMB_PRC_RESERVED 0x0001 /* reserved */ #define SMB_PRC_UNKNOWN 0x0002 /* unknown */ @@ -947,9 +944,6 @@ typedef struct smbios_slot { uint8_t smbl_df; /* device/function number */ uint8_t smbl_dbw; /* data bus width */ uint8_t smbl_npeers; /* PCIe bifurcation peers */ - uint8_t smbl_info; /* slot info */ - uint8_t smbl_pwidth; /* slot physical width */ - uint32_t smbl_pitch; /* slot pitch in 10um */ } smbios_slot_t; #define SMB_SLT_OTHER 0x01 /* other */ @@ -982,8 +976,8 @@ typedef struct smbios_slot { #define SMB_SLT_MXM_V 0x1C /* MXM Type IV */ #define SMB_SLT_MXM3_A 0x1D /* MXM 3.0 Type A */ #define SMB_SLT_MXM3_B 0x1E /* MXM 3.0 Type B */ -#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 U.2) */ -#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 (U.2) */ +#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 */ +#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 */ /* * These lines must be on one line for the string generating code. */ @@ -992,11 +986,6 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE_M52_WOBSKO 0x22 /* PCI Express Mini 52-pin without bottom-side keep-outs */ /* END CSTYLED */ #define SMB_SLT_PCIE_M76 0x23 /* PCI Express Mini 72-pin */ -#define SMB_SLT_PCIEG4_SFF 0x24 /* PCI Express Gen 4 SFF-8639 (U.2) */ -#define SMB_SLT_PCIEG5_SFF 0x25 /* PCI Express Gen 5 SFF-8639 (U.2) */ -#define SMB_SLT_OCP3_SFF 0x26 /* OCP NIC 3.0 Small Form Factor */ -#define SMB_SLT_OCP3_LFF 0x27 /* OCP NIC 3.0 Large Form Factor */ -#define SMB_SLT_OCP_PRE 0x28 /* OCP NIC prior to 3.0 */ #define SMB_SLT_CXL1 0x30 /* CXL Flexbus 1.0 */ #define SMB_SLT_PC98_C20 0xA0 /* PC-98/C20 */ #define SMB_SLT_PC98_C24 0xA1 /* PC-98/C24 */ @@ -1027,15 +1016,6 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE4G4 0xBB /* PCI Exp. Gen 4 x4 */ #define SMB_SLT_PCIE4G8 0xBC /* PCI Exp. Gen 4 x8 */ #define SMB_SLT_PCIE4G16 0xBD /* PCI Exp. Gen 4 x16 */ -#define SMB_SLT_PCIE5G 0xBE /* PCI Exp. Gen 5 */ -#define SMB_SLT_PCIE5G1 0xBF /* PCI Exp. Gen 5 x1 */ -#define SMB_SLT_PCIE5G2 0xC0 /* PCI Exp. Gen 5 x2 */ -#define SMB_SLT_PCIE5G4 0xC1 /* PCI Exp. Gen 5 x4 */ -#define SMB_SLT_PCIE5G8 0xC2 /* PCI Exp. Gen 5 x8 */ -#define SMB_SLT_PCIE5G16 0xC3 /* PCI Exp. Gen 5 x16 */ -#define SMB_SLT_PCIEG6P 0xC4 /* PCI Exp. Gen 6+ */ -#define SMB_SLT_EDSFF_E1 0xC5 /* Ent. and DC 1U E1 Form Factor */ -#define SMB_SLT_EDSFF_E3 0xC6 /* Ent. and DC 3" E3 Form Factor */ #define SMB_SLW_OTHER 0x01 /* other */ #define SMB_SLW_UNKNOWN 0x02 /* unknown */ @@ -1061,8 +1041,6 @@ typedef struct smbios_slot { #define SMB_SLL_UNKNOWN 0x02 /* unknown */ #define SMB_SLL_SHORT 0x03 /* short length */ #define SMB_SLL_LONG 0x04 /* long length */ -#define SMB_SLL_2IN5 0x05 /* 2.5" drive form factor */ -#define SMB_SLL_3IN5 0x06 /* 3.5" drive form factor */ #define SMB_SLCH1_UNKNOWN 0x01 /* characteristics unknown */ #define SMB_SLCH1_5V 0x02 /* provides 5.0V */ @@ -1077,9 +1055,6 @@ typedef struct smbios_slot { #define SMB_SLCH2_HOTPLUG 0x02 /* slot supports hot-plug devices */ #define SMB_SLCH2_SMBUS 0x04 /* slot supports SMBus signal */ #define SMB_SLCH2_BIFUR 0x08 /* slot supports PCIe bifurcation */ -#define SMB_SLCH2_SURPREM 0x10 /* slot supports surprise removal */ -#define SMB_SLCH2_CXL1 0x20 /* Flexbus slot, CXL 1.0 capable */ -#define SMB_SLCH2_CXL2 0x40 /* Flexbus slot, CXL 2.0 capable */ /* * SMBIOS 7.10.9 Slot Peer Devices @@ -1203,7 +1178,7 @@ typedef struct smbios_memarray { #define SMB_MAL_PC98C24 0xA1 /* PC-98/C24 add-on card */ #define SMB_MAL_PC98E 0xA2 /* PC-98/E add-on card */ #define SMB_MAL_PC98LB 0xA3 /* PC-98/Local bus add-on card */ -#define SMB_MAL_CXL1 0xA4 /* CXL add-on card */ +#define SMB_MAL_CXL1 0xA4 /* CXL Flexbus 1.0 add-on card */ #define SMB_MAU_OTHER 0x01 /* other */ #define SMB_MAU_UNKNOWN 0x02 /* unknown */ @@ -1310,8 +1285,6 @@ typedef struct smbios_memdevice { #define SMB_MDT_LOGNV 0x1F /* Logical non-volatile device */ #define SMB_MDT_HBM 0x20 /* High Bandwidth Memory */ #define SMB_MDT_HBM2 0x21 /* High Bandwidth Memory 2 */ -#define SMB_MDT_DDR5 0x22 /* DDR5 */ -#define SMB_MDT_LPDDR5 0x23 /* LPDDR5 */ #define SMB_MDF_OTHER 0x0002 /* other */ #define SMB_MDF_UNKNOWN 0x0004 /* unknown */ @@ -1340,7 +1313,7 @@ typedef struct smbios_memdevice { #define SMB_MTECH_NVDIMM_N 0x04 /* NVDIMM-N */ #define SMB_MTECH_NVDIMM_F 0x05 /* NVDIMM-F */ #define SMB_MTECH_NVDIMM_P 0x06 /* NVDIMM-P */ -#define SMB_MTECH_INTCPM 0x07 /* Intel Optane persistent memory */ +#define SMB_MTECH_INTCPM 0x07 /* Intel Optane DC Persistent Memory */ #define SMB_MOMC_RESERVED 0x01 /* reserved */ #define SMB_MOMC_OTHER 0x02 /* other */ @@ -1865,8 +1838,7 @@ typedef struct smbios_memdevice_ext { #define SMB_VERSION_31 0x0301 /* SMBIOS encoding for DMTF spec 3.1 */ #define SMB_VERSION_32 0x0302 /* SMBIOS encoding for DMTF spec 3.2 */ #define SMB_VERSION_33 0x0303 /* SMBIOS encoding for DMTF spec 3.3 */ -#define SMB_VERSION_34 0x0304 /* SMBIOS encoding for DMTF spec 3.4 */ -#define SMB_VERSION SMB_VERSION_34 /* SMBIOS latest version definitions */ +#define SMB_VERSION SMB_VERSION_33 /* SMBIOS latest version definitions */ #define SMB_O_NOCKSUM 0x1 /* do not verify header checksums */ #define SMB_O_NOVERS 0x2 /* do not verify header versions */ diff --git a/usr/src/uts/common/sys/smbios_impl.h b/usr/src/uts/common/sys/smbios_impl.h index 4b951b702f..69ca79e94f 100644 --- a/usr/src/uts/common/sys/smbios_impl.h +++ b/usr/src/uts/common/sys/smbios_impl.h @@ -22,7 +22,6 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. - * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -251,25 +250,8 @@ typedef struct smb_slot { uint8_t smbsl_dbw; /* Data bus width */ uint8_t smbsl_npeers; /* Peer bdf groups */ smb_slot_peer_t smbsl_peers[]; /* bifurcation peers */ - /* There are later additions in 3.4+, see smbios_slot_cont_t */ } smb_slot_t; -/* - * After the variable number of smbsl_peers, the smbios_slot has continued in - * size and has the following members defined as of version 3.4. These occur - * starting at byte 14 + 5 * smbsl_npeers. - */ -typedef struct smb_slot_cont { - uint8_t smbsl_info; /* slot info */ - uint8_t smbsl_pwidth; /* slot physical width */ - uint16_t smbsl_pitch; /* slot pitch */ -} smb_slot_cont_t; - -/* - * The first byte that the smb_slot_cont_t is defined to start at. - */ -#define SMB_SLOT_CONT_START 0x14 - /* * SMBIOS implementation structure for SMB_TYPE_OBDEVS. */ -- cgit v1.2.3 From 1045e13a248d94941f864998aa859970ae3a4154 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Fri, 24 Jul 2020 11:42:23 -0700 Subject: 13079 Add ksensor support for voltage and current sensors Reviewed by: Andy Fiddaman Reviewed by: Paul Winder Approved by: Dan McDonald --- .../lib/fm/topo/modules/common/pcibus/pci_sensor.c | 61 +++++++---- .../fm/topo/modules/common/shared/topo_sensor.c | 117 ++++++++++++--------- .../fm/topo/modules/common/shared/topo_sensor.h | 4 +- usr/src/lib/fm/topo/modules/i86pc/chip/chip_temp.c | 4 +- .../lib/fm/topo/modules/i86pc/chipset/chipset.c | 2 +- .../test/os-tests/tests/ksensor/ksensor_basic.c | 111 ++++++++++++------- usr/src/test/os-tests/tests/ksensor/ksensor_err.c | 24 ++--- .../test/os-tests/tests/ksensor/ksensor_sread.c | 12 +-- .../test/os-tests/tests/ksensor/ksensor_stress.ksh | 2 +- usr/src/uts/common/io/igb/igb_sensor.c | 17 +-- usr/src/uts/common/io/ksensor/ksensor_drv.c | 16 +-- usr/src/uts/common/io/ksensor/ksensor_test.c | 76 ++++++++++--- usr/src/uts/common/mapfiles/ksensor.mapfile | 4 +- usr/src/uts/common/os/ksensor.c | 40 +++++-- usr/src/uts/common/sys/ksensor_impl.h | 2 +- usr/src/uts/common/sys/sensors.h | 62 ++++++----- usr/src/uts/intel/io/amdf17nbdf/amdf17nbdf.c | 21 ++-- usr/src/uts/intel/io/amdnbtemp/amdnbtemp.c | 10 +- usr/src/uts/intel/io/coretemp/coretemp.c | 12 +-- usr/src/uts/intel/io/pchtemp/pchtemp.c | 10 +- 20 files changed, 384 insertions(+), 223 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/lib/fm/topo/modules/common/pcibus/pci_sensor.c b/usr/src/lib/fm/topo/modules/common/pcibus/pci_sensor.c index bb2cf6d344..390017fd4a 100644 --- a/usr/src/lib/fm/topo/modules/common/pcibus/pci_sensor.c +++ b/usr/src/lib/fm/topo/modules/common/pcibus/pci_sensor.c @@ -29,27 +29,14 @@ #include #include -int -pci_create_dev_sensors(topo_mod_t *mod, tnode_t *dev) +static const char *pci_sensor_types[] = { "current", "voltage", "temperature" }; + +static int +pci_create_dev_scandir(topo_mod_t *mod, tnode_t *dev, const char *path) { int ret; DIR *d; - char path[PATH_MAX]; - topo_instance_t binst, dinst; struct dirent *ent; - tnode_t *parent = topo_node_parent(dev); - - binst = topo_node_instance(parent); - dinst = topo_node_instance(dev); - - if (snprintf(path, sizeof (path), "/dev/sensors/temperature/pci/%x.%x", - binst, dinst) >= sizeof (path)) { - topo_mod_dprintf(mod, "failed to construct temp sensor " - "directory path, path too long"); - return (topo_mod_seterrno(mod, EMOD_UKNOWN_ENUM)); - } - - topo_mod_dprintf(mod, "searching for sensors in %s", path); d = opendir(path); if (d == NULL) { @@ -72,24 +59,54 @@ pci_create_dev_sensors(topo_mod_t *mod, tnode_t *dev) if (snprintf(spath, sizeof (spath), "%s/%s", path, ent->d_name) >= sizeof (spath)) { - topo_mod_dprintf(mod, "failed to construct temp sensor " - "path for %s/%s, path too long", path, ent->d_name); + topo_mod_dprintf(mod, "failed to construct sensor path " + "for %s/%s, path too long", path, ent->d_name); ret = topo_mod_seterrno(mod, EMOD_UKNOWN_ENUM); goto out; } topo_mod_dprintf(mod, "attempting to create sensor at %s", spath); - if ((ret = topo_sensor_create_temp_sensor(mod, dev, spath, + if ((ret = topo_sensor_create_scalar_sensor(mod, dev, spath, ent->d_name)) < 0) { goto out; } - } + ret = 0; out: (void) closedir(d); - return (ret); } + +int +pci_create_dev_sensors(topo_mod_t *mod, tnode_t *dev) +{ + uint_t i; + char path[PATH_MAX]; + topo_instance_t binst, dinst; + tnode_t *parent = topo_node_parent(dev); + + binst = topo_node_instance(parent); + dinst = topo_node_instance(dev); + + for (i = 0; i < ARRAY_SIZE(pci_sensor_types); i++) { + int ret; + + if (snprintf(path, sizeof (path), "/dev/sensors/%s/pci/%x.%x", + pci_sensor_types[i], binst, dinst) >= sizeof (path)) { + topo_mod_dprintf(mod, "failed to construct %s sensor " + "directory path, path too long", + pci_sensor_types[i]); + return (topo_mod_seterrno(mod, EMOD_UKNOWN_ENUM)); + } + + topo_mod_dprintf(mod, "searching for sensors in %s", path); + if ((ret = pci_create_dev_scandir(mod, dev, path)) != 0) { + return (ret); + } + } + + return (0); +} diff --git a/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.c b/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.c index c9e56e9e1f..a716c57a66 100644 --- a/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.c +++ b/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.c @@ -11,13 +11,14 @@ /* * Copyright 2019, Joyent, Inc. + * Copyright 2020 Oxide Computer Company */ /* * This file provides routines to interact with the kernel sensor framework. * Currently, modules that require interacting with a kernel sensor need to * build this file as part of the module. This takes care of all the work of - * setting up and creating the temperature sensor, given a path to that sensor. + * setting up and creating the sensor, given a path to that sensor. */ #include @@ -31,21 +32,21 @@ #include #include -#define TOPO_METH_TOPO_SENSOR_TEMP "topo_sensor_temp_reading" -#define TOPO_METH_TOPO_SENSOR_TEMP_DESC "Kernel Temperature Reading" -#define TOPO_METH_TOPO_SENSOR_TEMP_VERSION 0 +#define TOPO_METH_TOPO_SENSOR_SCALAR "topo_sensor_scalar_reading" +#define TOPO_METH_TOPO_SENSOR_SCALAR_DESC "Kernel Sensor Scalar Reading" +#define TOPO_METH_TOPO_SENSOR_SCALAR_VERSION 0 static int -topo_sensor_temp_read(topo_mod_t *mod, tnode_t *node, topo_version_t vers, +topo_sensor_scalar_read(topo_mod_t *mod, tnode_t *node, topo_version_t vers, nvlist_t *in, nvlist_t **out) { int fd = -1, ret; nvlist_t *args, *nvl; char *path; - sensor_ioctl_temperature_t temp; - double degrees; + sensor_ioctl_scalar_t scalar; + double value; - if (vers != TOPO_METH_TOPO_SENSOR_TEMP_VERSION) { + if (vers != TOPO_METH_TOPO_SENSOR_SCALAR_VERSION) { return (topo_mod_seterrno(mod, ETOPO_METHOD_VERNEW)); } @@ -62,31 +63,30 @@ topo_sensor_temp_read(topo_mod_t *mod, tnode_t *node, topo_version_t vers, return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); } - (void) memset(&temp, '\0', sizeof (temp)); - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - topo_mod_dprintf(mod, "failed to read temperature sensor " - "%s: %s", path, strerror(errno)); + (void) memset(&scalar, '\0', sizeof (scalar)); + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + topo_mod_dprintf(mod, "failed to read sensor %s: %s", path, + strerror(errno)); ret = topo_mod_seterrno(mod, EMOD_UNKNOWN); goto out; } /* * Check to see if we need to change the value to get it into an - * accurate reading. Positive values indicate that the temperature - * reading is in a fractional number of degrees and that each degree - * contains temp.sit_gran steps. A negative number means that the - * temperature reading represents temp.sit_gran degrees. + * accurate reading. Positive granularities indicate that the sensor + * reading is in a fractional number of units and that each unit + * contains scalar.sis_gran steps. A negative number means that the + * sensor reading represents scalar.sis_gran units. */ - degrees = (double)temp.sit_temp; - if (temp.sit_gran > 1) { - degrees /= (double)temp.sit_gran; - } else if (temp.sit_gran < -1) { - degrees *= (double)labs(temp.sit_gran); + value = (double)scalar.sis_value; + if (scalar.sis_gran > 1) { + value /= (double)scalar.sis_gran; + } else if (scalar.sis_gran < -1) { + value *= (double)labs(scalar.sis_gran); } if (topo_mod_nvalloc(mod, &nvl, NV_UNIQUE_NAME) != 0) { - topo_mod_dprintf(mod, "failed to allocate output temperature " - "nvl"); + topo_mod_dprintf(mod, "failed to allocate output nvl"); ret = topo_mod_seterrno(mod, EMOD_NOMEM); goto out; } @@ -94,9 +94,9 @@ topo_sensor_temp_read(topo_mod_t *mod, tnode_t *node, topo_version_t vers, if (nvlist_add_string(nvl, TOPO_PROP_VAL_NAME, TOPO_SENSOR_READING) != 0 || nvlist_add_uint32(nvl, TOPO_PROP_VAL_TYPE, TOPO_TYPE_DOUBLE) != 0 || - nvlist_add_double(nvl, TOPO_PROP_VAL_VAL, degrees) != 0) { + nvlist_add_double(nvl, TOPO_PROP_VAL_VAL, value) != 0) { topo_mod_dprintf(mod, "failed to add members to output " - "temperature nvlist"); + "sensor nvlist"); nvlist_free(nvl); ret = topo_mod_seterrno(mod, EMOD_NOMEM); goto out; @@ -111,35 +111,40 @@ out: return (ret); } -static const topo_method_t topo_sensor_temp_fac_methods[] = { - { TOPO_METH_TOPO_SENSOR_TEMP, TOPO_METH_TOPO_SENSOR_TEMP_DESC, - TOPO_METH_TOPO_SENSOR_TEMP_VERSION, TOPO_STABILITY_INTERNAL, - topo_sensor_temp_read }, +static const topo_method_t topo_sensor_scalar_fac_methods[] = { + { TOPO_METH_TOPO_SENSOR_SCALAR, TOPO_METH_TOPO_SENSOR_SCALAR_DESC, + TOPO_METH_TOPO_SENSOR_SCALAR_VERSION, TOPO_STABILITY_INTERNAL, + topo_sensor_scalar_read }, { NULL } }; static topo_sensor_unit_t -topo_sensor_units(const sensor_ioctl_temperature_t *temp) +topo_sensor_units(const sensor_ioctl_scalar_t *scalar) { - switch (temp->sit_unit) { + switch (scalar->sis_unit) { case SENSOR_UNIT_CELSIUS: return (TOPO_SENSOR_UNITS_DEGREES_C); case SENSOR_UNIT_FAHRENHEIT: return (TOPO_SENSOR_UNITS_DEGREES_F); case SENSOR_UNIT_KELVIN: return (TOPO_SENSOR_UNITS_DEGREES_K); + case SENSOR_UNIT_VOLTS: + return (TOPO_SENSOR_UNITS_VOLTS); + case SENSOR_UNIT_AMPS: + return (TOPO_SENSOR_UNITS_AMPS); default: return (TOPO_SENSOR_UNITS_UNSPECIFIED); } } int -topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, +topo_sensor_create_scalar_sensor(topo_mod_t *mod, tnode_t *pnode, const char *path, const char *fname) { int fd, ret, err; sensor_ioctl_kind_t sik; - sensor_ioctl_temperature_t temp; + sensor_ioctl_scalar_t scalar; + uint32_t topo_type; tnode_t *fnode = NULL; topo_pgroup_info_t pgi; nvlist_t *reader_arg = NULL; @@ -148,16 +153,16 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, topo_node_name(pnode), path); (void) memset(&sik, '\0', sizeof (sik)); - (void) memset(&temp, '\0', sizeof (temp)); + (void) memset(&scalar, '\0', sizeof (scalar)); if ((fd = open(path, O_RDONLY)) < 0) { topo_mod_dprintf(mod, "failed to open sensor path %s: %s", path, strerror(errno)); /* - * We always try to create temperature sensors; however, they - * may not exist or be supported on the system in question. - * Therefore ENOENT is totally acceptable. + * We always try to create sensors; however, they may not exist + * or be supported on the system in question. Therefore ENOENT + * is totally acceptable. */ if (errno == ENOENT) { return (0); @@ -165,23 +170,34 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); } - if (ioctl(fd, SENSOR_IOCTL_TYPE, &sik) != 0) { + if (ioctl(fd, SENSOR_IOCTL_KIND, &sik) != 0) { topo_mod_dprintf(mod, "failed to verify sensor kind for sensor " "%s: %s", path, strerror(errno)); ret = topo_mod_seterrno(mod, EMOD_UNKNOWN); goto out; } - if (sik.sik_kind != SENSOR_KIND_TEMPERATURE) { - topo_mod_dprintf(mod, "sensor kind for %s is not temperature, " - "found 0x%x", path, sik.sik_kind); + switch (sik.sik_kind) { + case SENSOR_KIND_TEMPERATURE: + topo_type = TOPO_SENSOR_TYPE_TEMP; + break; + case SENSOR_KIND_VOLTAGE: + topo_type = TOPO_SENSOR_TYPE_VOLTAGE; + break; + case SENSOR_KIND_CURRENT: + topo_type = TOPO_SENSOR_TYPE_CURRENT; + break; + default: + topo_mod_dprintf(mod, "unknown sensor kind for %s, found 0x%x", + path, sik.sik_kind); ret = topo_mod_seterrno(mod, EMOD_UNKNOWN); goto out; + } - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - topo_mod_dprintf(mod, "failed to read temperature sensor " - "%s: %s", path, strerror(errno)); + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + topo_mod_dprintf(mod, "failed to read scalar sensor %s: %s", + path, strerror(errno)); ret = topo_mod_seterrno(mod, EMOD_UNKNOWN); goto out; } @@ -191,7 +207,7 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, if ((fnode = topo_node_facbind(mod, pnode, fname, TOPO_FAC_TYPE_SENSOR)) == NULL) { - topo_mod_dprintf(mod, "failed to bind temperature facility " + topo_mod_dprintf(mod, "failed to bind sensor facility " "node to %s: %d", path, topo_mod_errno(mod)); ret = -1; goto out; @@ -213,10 +229,9 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, TOPO_SENSOR_CLASS, TOPO_PROP_IMMUTABLE, TOPO_SENSOR_CLASS_THRESHOLD, &err) != 0 || topo_prop_set_uint32(fnode, TOPO_PGROUP_FACILITY, - TOPO_FACILITY_TYPE, TOPO_PROP_IMMUTABLE, TOPO_SENSOR_TYPE_TEMP, - &err) != 0 || + TOPO_FACILITY_TYPE, TOPO_PROP_IMMUTABLE, topo_type, &err) != 0 || topo_prop_set_uint32(fnode, TOPO_PGROUP_FACILITY, - TOPO_SENSOR_UNITS, TOPO_PROP_IMMUTABLE, topo_sensor_units(&temp), + TOPO_SENSOR_UNITS, TOPO_PROP_IMMUTABLE, topo_sensor_units(&scalar), &err) != 0) { topo_mod_dprintf(mod, "failed to set properties for sensor " "%s: %s", path, topo_strerror(err)); @@ -225,7 +240,7 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, } - if (topo_method_register(mod, fnode, topo_sensor_temp_fac_methods) < + if (topo_method_register(mod, fnode, topo_sensor_scalar_fac_methods) < 0) { topo_mod_dprintf(mod, "failed to register reading methods on " "%s", path); @@ -241,7 +256,7 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, } if (topo_prop_method_register(fnode, TOPO_PGROUP_FACILITY, - TOPO_SENSOR_READING, TOPO_TYPE_DOUBLE, TOPO_METH_TOPO_SENSOR_TEMP, + TOPO_SENSOR_READING, TOPO_TYPE_DOUBLE, TOPO_METH_TOPO_SENSOR_SCALAR, reader_arg, &err) != 0) { topo_mod_dprintf(mod, "failed to set argument for sensor %s: " "%s", path, topo_strerror(err)); @@ -249,6 +264,8 @@ topo_sensor_create_temp_sensor(topo_mod_t *mod, tnode_t *pnode, goto out; } + topo_mod_dprintf(mod, "created sensor at %s", path); + nvlist_free(reader_arg); return (0); out: diff --git a/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.h b/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.h index ff6e1ea92e..753dcbd8d8 100644 --- a/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.h +++ b/usr/src/lib/fm/topo/modules/common/shared/topo_sensor.h @@ -24,8 +24,8 @@ extern "C" { #endif -extern int topo_sensor_create_temp_sensor(topo_mod_t *, tnode_t *, const char *, - const char *); +extern int topo_sensor_create_scalar_sensor(topo_mod_t *, tnode_t *, + const char *, const char *); #ifdef __cplusplus } diff --git a/usr/src/lib/fm/topo/modules/i86pc/chip/chip_temp.c b/usr/src/lib/fm/topo/modules/i86pc/chip/chip_temp.c index 89f8d57fb6..f06190bb46 100644 --- a/usr/src/lib/fm/topo/modules/i86pc/chip/chip_temp.c +++ b/usr/src/lib/fm/topo/modules/i86pc/chip/chip_temp.c @@ -71,7 +71,7 @@ chip_create_core_temp_sensor(topo_mod_t *mod, tnode_t *pnode) } } - return (topo_sensor_create_temp_sensor(mod, pnode, buf, "temp")); + return (topo_sensor_create_scalar_sensor(mod, pnode, buf, "temp")); } int @@ -87,5 +87,5 @@ chip_create_chip_temp_sensor(topo_mod_t *mod, tnode_t *pnode) return (topo_mod_seterrno(mod, EMOD_UNKNOWN)); } - return (topo_sensor_create_temp_sensor(mod, pnode, buf, "temp")); + return (topo_sensor_create_scalar_sensor(mod, pnode, buf, "temp")); } diff --git a/usr/src/lib/fm/topo/modules/i86pc/chipset/chipset.c b/usr/src/lib/fm/topo/modules/i86pc/chipset/chipset.c index cc306b4b2f..2f3781c932 100644 --- a/usr/src/lib/fm/topo/modules/i86pc/chipset/chipset.c +++ b/usr/src/lib/fm/topo/modules/i86pc/chipset/chipset.c @@ -136,7 +136,7 @@ topo_chipset_enum(topo_mod_t *mod, tnode_t *pnode, const char *name, /* * Finally, create the temperature sensor. */ - if ((ret = topo_sensor_create_temp_sensor(mod, tn, + if ((ret = topo_sensor_create_scalar_sensor(mod, tn, topo_chipset_temp_sensor, "temp")) != 0) { topo_mod_dprintf(mod, "failed to create chipset temperature " "sensor"); diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c b/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c index 35590df264..22f79d18a7 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_basic.c @@ -26,66 +26,101 @@ #include #include #include +#include -static const char *ksensor_path = "/dev/sensors/test/test.temp.0.1"; +typedef struct sensor_test { + const char *st_path; + uint64_t st_kind; + uint32_t st_unit; + int32_t st_gran; + uint32_t st_prec; + int64_t st_val; +} sensor_test_t; -int -main(void) +/* + * These values come from the dummy sensors in the ksensor_test driver. + */ +static sensor_test_t ksensor_basic_tests[] = { + { "/dev/sensors/test/test.temp.0.1", SENSOR_KIND_TEMPERATURE, + SENSOR_UNIT_CELSIUS, 4, -2, 23 }, + { "/dev/sensors/test/test.volt.0.1", SENSOR_KIND_VOLTAGE, + SENSOR_UNIT_VOLTS, 1000, 0, 3300 }, + { "/dev/sensors/test/test.current.0.1", SENSOR_KIND_CURRENT, + SENSOR_UNIT_AMPS, 10, 0, 5 }, +}; + +static boolean_t +ksensor_basic(sensor_test_t *st) { sensor_ioctl_kind_t kind; - sensor_ioctl_temperature_t temp; - int ret = 0; + sensor_ioctl_scalar_t scalar; + int fd; - int fd = open(ksensor_path, O_RDONLY); + fd = open(st->st_path, O_RDONLY); if (fd < 0) { - err(EXIT_FAILURE, "TEST FAILED: failed to open %s", - ksensor_path); + warn("TEST FAILED: failed to open %s", st->st_path); + return (B_FALSE); } arc4random_buf(&kind, sizeof (kind)); - arc4random_buf(&temp, sizeof (temp)); + arc4random_buf(&scalar, sizeof (scalar)); + + if (ioctl(fd, SENSOR_IOCTL_KIND, &kind) != 0) { + warn("TEST FAILED: %s: failed to get sensor kind", st->st_path); + goto err; + } - if (ioctl(fd, SENSOR_IOCTL_TYPE, &kind) != 0) { - warn("TEST FAILED: failed to get sensor type"); - ret = EXIT_FAILURE; + if (kind.sik_kind != st->st_kind) { + warnx("TEST FAILED: %s: expected kind %" PRIu64 ", found kind %" + PRIu64, st->st_path, st->st_kind, kind); + goto err; } - if (kind.sik_kind != SENSOR_KIND_TEMPERATURE) { - warnx("TEST FAILED: expected temperature sensor, found kind %d", - kind); - ret = EXIT_FAILURE; + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + warn("TEST FAILED: %s: failed to read sensor", st->st_path); + goto err; } - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - warn("TEST FAILED: failed to get sensor temperature"); - ret = EXIT_FAILURE; + if (scalar.sis_unit != st->st_unit) { + warnx("TEST FAILED: %s: expected unit %" PRIu32 ", but found " + "%" PRIu32, st->st_path, st->st_unit, scalar.sis_unit); + goto err; } - /* - * These values come from the dummy temperature sensor in ksensor_test. - */ - if (temp.sit_unit != SENSOR_UNIT_CELSIUS) { - warnx("TEST FAILED: expected temp unit %" PRIu32 ", but found " - "%" PRIu32, SENSOR_UNIT_CELSIUS, temp.sit_unit); - ret = EXIT_FAILURE; + if (scalar.sis_gran != st->st_gran) { + warnx("TEST FAILED: %s: expected gran %" PRId32 ", but found " + "%" PRId32, st->st_path, st->st_gran, scalar.sis_gran); + goto err; } - if (temp.sit_gran != 4) { - warnx("TEST FAILED: expected temp gran %" PRId32 ", but found " - "%" PRId32, 4, temp.sit_gran); - ret = EXIT_FAILURE; + if (scalar.sis_prec != st->st_prec) { + warnx("TEST FAILED: %s: expected prec %" PRIu32 ", but found " + "%" PRIu32, st->st_path, st->st_prec, scalar.sis_prec); + goto err; } - if (temp.sit_prec != -2) { - warnx("TEST FAILED: expected temp prec %" PRId32 ", but found " - "%" PRId32, -2, temp.sit_prec); - ret = EXIT_FAILURE; + if (scalar.sis_value != st->st_val) { + warnx("TEST FAILED: %s: expected value %" PRId64 ", but found " + "%" PRId64, st->st_path, st->st_val, scalar.sis_value); + goto err; } - if (temp.sit_temp != 23) { - warnx("TEST FAILED: expected temp %" PRId64 ", but found " - "%" PRId64, 23, temp.sit_temp); - ret = EXIT_FAILURE; + return (B_TRUE); +err: + (void) close(fd); + return (B_FALSE); +} + +int +main(void) +{ + size_t i; + int ret = EXIT_SUCCESS; + + for (i = 0; i < ARRAY_SIZE(ksensor_basic_tests); i++) { + if (!ksensor_basic(&ksensor_basic_tests[i])) { + ret = EXIT_FAILURE; + } } return (ret); diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_err.c b/usr/src/test/os-tests/tests/ksensor/ksensor_err.c index 2818327f78..784dc477d8 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_err.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_err.c @@ -39,20 +39,20 @@ error_kind(int fd, int exp) arc4random_buf(&alt_kind, sizeof (alt_kind)); (void) memcpy(&kind, &alt_kind, sizeof (alt_kind)); - if (ioctl(fd, SENSOR_IOCTL_TYPE, &kind) == 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE succeeded on EIO " + if (ioctl(fd, SENSOR_IOCTL_KIND, &kind) == 0) { + warnx("TEST FAILED: SENSOR_IOCTL_KIND succeeded on EIO " "sensor"); error_exit = EXIT_FAILURE; } if (errno != exp) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE got errno %d, " + warnx("TEST FAILED: SENSOR_IOCTL_KIND got errno %d, " "expected %d", errno, exp); error_exit = EXIT_FAILURE; } if (memcmp(&kind, &alt_kind, sizeof (alt_kind)) != 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TYPE modified data on error"); + warnx("TEST FAILED: SENSOR_IOCTL_KIND modified data on error"); error_exit = EXIT_FAILURE; } } @@ -60,25 +60,25 @@ error_kind(int fd, int exp) static void error_temp(int fd, int exp) { - sensor_ioctl_temperature_t temp, alt_temp; + sensor_ioctl_scalar_t scalar, alt_scalar; - arc4random_buf(&alt_temp, sizeof (alt_temp)); - (void) memcpy(&temp, &alt_temp, sizeof (alt_temp)); + arc4random_buf(&alt_scalar, sizeof (alt_scalar)); + (void) memcpy(&scalar, &alt_scalar, sizeof (alt_scalar)); - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) == 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE suceeded on " + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) == 0) { + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR suceeded on " "EIO sensor"); error_exit = EXIT_FAILURE; } if (errno != exp) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE got errno %d, " + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR got errno %d, " "expected %d", errno, EIO); error_exit = EXIT_FAILURE; } - if (memcmp(&temp, &alt_temp, sizeof (alt_temp)) != 0) { - warnx("TEST FAILED: SENSIOR_IOCTL_TEMPERATURE modified " + if (memcmp(&scalar, &alt_scalar, sizeof (alt_scalar)) != 0) { + warnx("TEST FAILED: SENSIOR_IOCTL_SCALAR modified " "data on error"); error_exit = EXIT_FAILURE; } diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c b/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c index fef8b78f73..42be85f10e 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_sread.c @@ -58,7 +58,7 @@ main(int argc, const char *argv[]) char buf[PATH_MAX]; uint32_t sens, inst; struct timespec ts; - sensor_ioctl_temperature_t temp; + sensor_ioctl_scalar_t scalar; /* 0s based */ sens = arc4random_uniform(nsensors); @@ -73,15 +73,15 @@ main(int argc, const char *argv[]) goto wait; } - bzero(&temp, sizeof (temp)); - if (ioctl(fd, SENSOR_IOCTL_TEMPERATURE, &temp) != 0) { - warn("failed to get sensor temp on %s", buf); + bzero(&scalar, sizeof (scalar)); + if (ioctl(fd, SENSOR_IOCTL_SCALAR, &scalar) != 0) { + warn("failed to get sensor temperature on %s", buf); } - if (temp.sit_unit != SENSOR_UNIT_CELSIUS) { + if (scalar.sis_unit != SENSOR_UNIT_CELSIUS) { warnx("data from sensor %s looks off, expected sensor " "to indicate Celsius, but instead %u", - temp.sit_unit); + scalar.sis_unit); } (void) close(fd); diff --git a/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh b/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh index 805e464eb0..9a27a151ff 100644 --- a/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh +++ b/usr/src/test/os-tests/tests/ksensor/ksensor_stress.ksh @@ -50,7 +50,7 @@ fi if [[ ! -L "$sensor_base/test.temp.0.1" ]]; then - printf "missing ksensor test data, ksensor_temp driver loaded\n" 2>&1 + printf "missing ksensor test data, ksensor_tstp driver loaded?\n" 2>&1 exit 1 fi diff --git a/usr/src/uts/common/io/igb/igb_sensor.c b/usr/src/uts/common/io/igb/igb_sensor.c index b233af2a92..3b41a853c0 100644 --- a/usr/src/uts/common/io/igb/igb_sensor.c +++ b/usr/src/uts/common/io/igb/igb_sensor.c @@ -72,7 +72,7 @@ #define EMC1413_REG_EXT3_DIODE_LO 0x2b static int -igb_sensor_reg_temp(void *arg, sensor_ioctl_temperature_t *temp) +igb_sensor_reg_temperature(void *arg, sensor_ioctl_scalar_t *scalar) { igb_t *igb = arg; uint32_t reg; @@ -87,17 +87,17 @@ igb_sensor_reg_temp(void *arg, sensor_ioctl_temperature_t *temp) return (EIO); } - temp->sit_unit = SENSOR_UNIT_CELSIUS; - temp->sit_gran = E1000_THMJT_RESOLUTION; - temp->sit_prec = E1000_THMJT_PRECISION; - temp->sit_temp = E1000_THMJT_TEMP(reg); + scalar->sis_unit = SENSOR_UNIT_CELSIUS; + scalar->sis_gran = E1000_THMJT_RESOLUTION; + scalar->sis_prec = E1000_THMJT_PRECISION; + scalar->sis_value = E1000_THMJT_TEMP(reg); return (0); } static const ksensor_ops_t igb_sensor_reg_ops = { .kso_kind = ksensor_kind_temperature, - .kso_temp = igb_sensor_reg_temp + .kso_scalar = igb_sensor_reg_temperature }; static boolean_t @@ -106,8 +106,9 @@ igb_sensors_create_minors(igb_t *igb) int ret; igb_sensors_t *sp = &igb->igb_sensors; - if ((ret = ksensor_create_temp_pcidev(igb->dip, &igb_sensor_reg_ops, - igb, "builtin", &sp->isn_reg_ksensor)) != 0) { + if ((ret = ksensor_create_scalar_pcidev(igb->dip, + SENSOR_KIND_TEMPERATURE, &igb_sensor_reg_ops, igb, "builtin", + &sp->isn_reg_ksensor)) != 0) { igb_log(igb, IGB_LOG_ERROR, "failed to create main sensor: %d", ret); return (B_FALSE); diff --git a/usr/src/uts/common/io/ksensor/ksensor_drv.c b/usr/src/uts/common/io/ksensor/ksensor_drv.c index 6810e11758..70e99287a2 100644 --- a/usr/src/uts/common/io/ksensor/ksensor_drv.c +++ b/usr/src/uts/common/io/ksensor/ksensor_drv.c @@ -90,15 +90,15 @@ ksensor_ioctl_kind(minor_t min, intptr_t arg, int mode) } static int -ksensor_ioctl_temp(minor_t min, intptr_t arg, int mode) +ksensor_ioctl_scalar(minor_t min, intptr_t arg, int mode) { int ret; - sensor_ioctl_temperature_t temp; + sensor_ioctl_scalar_t scalar; - bzero(&temp, sizeof (temp)); - ret = ksensor_op_temperature((id_t)min, &temp); + bzero(&scalar, sizeof (scalar)); + ret = ksensor_op_scalar((id_t)min, &scalar); if (ret == 0) { - if (ddi_copyout(&temp, (void *)arg, sizeof (temp), + if (ddi_copyout(&scalar, (void *)arg, sizeof (scalar), mode & FKIOCTL) != 0) { ret = EFAULT; } @@ -118,10 +118,10 @@ ksensor_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, m = getminor(dev); switch (cmd) { - case SENSOR_IOCTL_TYPE: + case SENSOR_IOCTL_KIND: return (ksensor_ioctl_kind(m, arg, mode)); - case SENSOR_IOCTL_TEMPERATURE: - return (ksensor_ioctl_temp(m, arg, mode)); + case SENSOR_IOCTL_SCALAR: + return (ksensor_ioctl_scalar(m, arg, mode)); default: return (ENOTTY); } diff --git a/usr/src/uts/common/io/ksensor/ksensor_test.c b/usr/src/uts/common/io/ksensor/ksensor_test.c index ea71ab5559..a98a8b77eb 100644 --- a/usr/src/uts/common/io/ksensor/ksensor_test.c +++ b/usr/src/uts/common/io/ksensor/ksensor_test.c @@ -32,21 +32,53 @@ typedef struct ksensor_test { id_t kt_sensor3; id_t kt_sensor4; id_t kt_sensor5; + id_t kt_volt; + id_t kt_current; } ksensor_test_t; static int -ksensor_test_temperature(void *arg, sensor_ioctl_temperature_t *temp) +ksensor_test_temp(void *arg, sensor_ioctl_scalar_t *scalar) { - temp->sit_unit = SENSOR_UNIT_CELSIUS; - temp->sit_gran = 4; - temp->sit_prec = -2; - temp->sit_temp = 23; + scalar->sis_unit = SENSOR_UNIT_CELSIUS; + scalar->sis_gran = 4; + scalar->sis_prec = -2; + scalar->sis_value = 23; return (0); } static const ksensor_ops_t ksensor_test_temp_ops = { - ksensor_kind_temperature, - ksensor_test_temperature + .kso_kind = ksensor_kind_temperature, + .kso_scalar = ksensor_test_temp +}; + +static int +ksensor_test_volt(void *arg, sensor_ioctl_scalar_t *scalar) +{ + scalar->sis_unit = SENSOR_UNIT_VOLTS; + scalar->sis_gran = 1000; + scalar->sis_prec = 0; + scalar->sis_value = 3300; + return (0); +} + +static const ksensor_ops_t ksensor_test_volt_ops = { + .kso_kind = ksensor_kind_voltage, + .kso_scalar = ksensor_test_volt +}; + +static int +ksensor_test_current(void *arg, sensor_ioctl_scalar_t *scalar) +{ + scalar->sis_unit = SENSOR_UNIT_AMPS; + scalar->sis_gran = 10; + scalar->sis_prec = 0; + scalar->sis_value = 5; + return (0); +} + +static const ksensor_ops_t ksensor_test_current_ops = { + .kso_kind = ksensor_kind_current, + .kso_scalar = ksensor_test_current }; static int @@ -56,14 +88,14 @@ ksensor_test_kind_eio(void *arg, sensor_ioctl_kind_t *kindp) } static int -ksensor_test_temp_eio(void *arg, sensor_ioctl_temperature_t *tempp) +ksensor_test_temp_eio(void *arg, sensor_ioctl_scalar_t *scalar) { return (EIO); } static const ksensor_ops_t ksensor_test_eio_ops = { - ksensor_test_kind_eio, - ksensor_test_temp_eio + .kso_kind = ksensor_test_kind_eio, + .kso_scalar = ksensor_test_temp_eio }; static int @@ -107,7 +139,7 @@ ksensor_test_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) ddi_get_instance(dip)); if ((ret = ksensor_create(dip, &ksensor_test_temp_ops, NULL, buf, "ddi_sensor:test", &kt->kt_sensor3)) != 0) { - dev_err(dip, CE_WARN, "failed to attatch sensor %s: %d", buf, + dev_err(dip, CE_WARN, "failed to attach sensor %s: %d", buf, ret); goto err; } @@ -116,7 +148,7 @@ ksensor_test_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) ddi_get_instance(dip)); if ((ret = ksensor_create(dip, &ksensor_test_temp_ops, NULL, buf, "ddi_sensor:test", &kt->kt_sensor4)) != 0) { - dev_err(dip, CE_WARN, "failed to attatch sensor %s: %d", buf, + dev_err(dip, CE_WARN, "failed to attach sensor %s: %d", buf, ret); goto err; } @@ -125,7 +157,25 @@ ksensor_test_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) ddi_get_instance(dip)); if ((ret = ksensor_create(dip, &ksensor_test_eio_ops, NULL, buf, "ddi_sensor:test", &kt->kt_sensor5)) != 0) { - dev_err(dip, CE_WARN, "failed to attatch sensor %s: %d", buf, + dev_err(dip, CE_WARN, "failed to attach sensor %s: %d", buf, + ret); + goto err; + } + + (void) snprintf(buf, sizeof (buf), "test.volt.%d.1", + ddi_get_instance(dip)); + if ((ret = ksensor_create(dip, &ksensor_test_volt_ops, NULL, buf, + "ddi_sensor:test", &kt->kt_volt)) != 0) { + dev_err(dip, CE_WARN, "failed to attach sensor %s: %d", buf, + ret); + goto err; + } + + (void) snprintf(buf, sizeof (buf), "test.current.%d.1", + ddi_get_instance(dip)); + if ((ret = ksensor_create(dip, &ksensor_test_current_ops, NULL, buf, + "ddi_sensor:test", &kt->kt_current)) != 0) { + dev_err(dip, CE_WARN, "failed to attach sensor %s: %d", buf, ret); goto err; } diff --git a/usr/src/uts/common/mapfiles/ksensor.mapfile b/usr/src/uts/common/mapfiles/ksensor.mapfile index 0374c957f7..51b65a2b9d 100644 --- a/usr/src/uts/common/mapfiles/ksensor.mapfile +++ b/usr/src/uts/common/mapfiles/ksensor.mapfile @@ -36,8 +36,10 @@ $mapfile_version 2 SYMBOL_SCOPE { global: ksensor_create { FLAGS = EXTERN }; - ksensor_create_temp_pcidev { FLAGS = EXTERN }; + ksensor_create_scalar_pcidev { FLAGS = EXTERN }; ksensor_remove { FLAGS = EXTERN }; + ksensor_kind_current { FLAGS = EXTERN }; ksensor_kind_temperature { FLAGS = EXTERN }; + ksensor_kind_voltage { FLAGS = EXTERN }; }; diff --git a/usr/src/uts/common/os/ksensor.c b/usr/src/uts/common/os/ksensor.c index c89cad4206..491fbcc7cd 100644 --- a/usr/src/uts/common/os/ksensor.c +++ b/usr/src/uts/common/os/ksensor.c @@ -544,14 +544,29 @@ ksensor_create(dev_info_t *dip, const ksensor_ops_t *ops, void *arg, } int -ksensor_create_temp_pcidev(dev_info_t *dip, const ksensor_ops_t *ops, - void *arg, const char *name, id_t *idp) +ksensor_create_scalar_pcidev(dev_info_t *dip, uint_t kind, + const ksensor_ops_t *ops, void *arg, const char *name, id_t *idp) { char *pci_name, *type; + const char *class; int *regs, ret; uint_t nregs; uint16_t bus, dev; + switch (kind) { + case SENSOR_KIND_TEMPERATURE: + class = "ddi_sensor:temperature:pci"; + break; + case SENSOR_KIND_VOLTAGE: + class = "ddi_sensor:voltage:pci"; + break; + case SENSOR_KIND_CURRENT: + class = "ddi_sensor:current:pci"; + break; + default: + return (ENOTSUP); + } + if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, "device_type", &type) != DDI_PROP_SUCCESS) { return (EINVAL); @@ -579,8 +594,7 @@ ksensor_create_temp_pcidev(dev_info_t *dip, const ksensor_ops_t *ops, pci_name = kmem_asprintf("%x.%x:%s", bus, dev, name); - ret = ksensor_create(dip, ops, arg, pci_name, - "ddi_sensor:temperature:pci", idp); + ret = ksensor_create(dip, ops, arg, pci_name, class, idp); strfree(pci_name); return (ret); } @@ -750,7 +764,7 @@ ksensor_op_kind(id_t id, sensor_ioctl_kind_t *kind) } int -ksensor_op_temperature(id_t id, sensor_ioctl_temperature_t *temp) +ksensor_op_scalar(id_t id, sensor_ioctl_scalar_t *scalar) { int ret; ksensor_t *sensor; @@ -759,7 +773,7 @@ ksensor_op_temperature(id_t id, sensor_ioctl_temperature_t *temp) return (ret); } - ret = sensor->ksensor_ops->kso_temp(sensor->ksensor_arg, temp); + ret = sensor->ksensor_ops->kso_scalar(sensor->ksensor_arg, scalar); ksensor_release(sensor); return (ret); @@ -831,6 +845,20 @@ ksensor_kind_temperature(void *unused, sensor_ioctl_kind_t *k) return (0); } +int +ksensor_kind_current(void *unused, sensor_ioctl_kind_t *k) +{ + k->sik_kind = SENSOR_KIND_CURRENT; + return (0); +} + +int +ksensor_kind_voltage(void *unused, sensor_ioctl_kind_t *k) +{ + k->sik_kind = SENSOR_KIND_VOLTAGE; + return (0); +} + void ksensor_init(void) { diff --git a/usr/src/uts/common/sys/ksensor_impl.h b/usr/src/uts/common/sys/ksensor_impl.h index 8d91973bc3..7407a264a2 100644 --- a/usr/src/uts/common/sys/ksensor_impl.h +++ b/usr/src/uts/common/sys/ksensor_impl.h @@ -35,7 +35,7 @@ extern void ksensor_init(void); * Operations vectors. */ extern int ksensor_op_kind(id_t, sensor_ioctl_kind_t *); -extern int ksensor_op_temperature(id_t, sensor_ioctl_temperature_t *); +extern int ksensor_op_scalar(id_t, sensor_ioctl_scalar_t *); /* * Registration callbacks. diff --git a/usr/src/uts/common/sys/sensors.h b/usr/src/uts/common/sys/sensors.h index a39dfca239..a5d830a933 100644 --- a/usr/src/uts/common/sys/sensors.h +++ b/usr/src/uts/common/sys/sensors.h @@ -33,6 +33,8 @@ extern "C" { */ #define SENSOR_KIND_UNKNOWN 0x00 #define SENSOR_KIND_TEMPERATURE 0x01 +#define SENSOR_KIND_VOLTAGE 0x02 +#define SENSOR_KIND_CURRENT 0x03 /* * Lists of units that senors may have. @@ -41,52 +43,60 @@ extern "C" { #define SENSOR_UNIT_CELSIUS 0x01 #define SENSOR_UNIT_FAHRENHEIT 0x02 #define SENSOR_UNIT_KELVIN 0x03 +#define SENSOR_UNIT_VOLTS 0x04 +#define SENSOR_UNIT_AMPS 0x05 #define SENSOR_IOCTL (('s' << 24) | ('e' << 16) | ('n' << 8)) /* * Ask the sensor what kind of sensor it is. */ -#define SENSOR_IOCTL_TYPE (SENSOR_IOCTL | 0x01) +#define SENSOR_IOCTL_KIND (SENSOR_IOCTL | 0x01) typedef struct sensor_ioctl_kind { uint64_t sik_kind; } sensor_ioctl_kind_t; /* - * Ask the sensor for a temperature measurement. The sensor is responsible for - * returning the units it's in. A temperature measurement is broken down into a + * Ask the sensor for a scalar measurement. The sensor is responsible for + * returning the units it's in. A scalar measurement is broken down into a * signed value and a notion of its granularity. The sit_gran member indicates - * the granularity: the number of increments per degree in the temperature - * measurement (the sit_temp member). sit_gran is signed and the sign indicates - * whether one needs to multiply or divide the granularity. For example, a - * value that set sit_gran to 10 would mean that the value in sit_temp was in - * 10ths of a degree and that to get the actual value in degrees, one would - * divide by 10. On the other hand, a negative value means that we effectively - * have to multiply to get there. For example, a value of -2 would indicate that - * each value in sit_temp indicated two degrees and to get the temperature in - * degrees you would multiply sit_temp by two. + * the granularity: the number of increments per unit in the measurement (the + * sit_value member). sit_gran is signed and the sign indicates whether one + * needs to multiply or divide the granularity. The sit_prec member describes a + * +/- value (taking sit_gran into account) that describes the precision of the + * sensor. + * + * For example, consider a temperature sensor that set sit_gran to 10. This + * would mean that the value in sit_value was in 10ths of a degree and that to + * get the actual value in degrees, one would divide by 10. On the other hand, a + * negative value means that we effectively have to multiply to get there. For + * example, a value of -2 would indicate that each value in sit_value indicated + * two degrees and to get the temperature in degrees you would multiply + * sit_value * by two. */ -#define SENSOR_IOCTL_TEMPERATURE (SENSOR_IOCTL | 0x02) +#define SENSOR_IOCTL_SCALAR (SENSOR_IOCTL | 0x02) -typedef struct sensor_ioctl_temperature { - uint32_t sit_unit; - int32_t sit_gran; - uint32_t sit_prec; - uint32_t sit_pad; - int64_t sit_temp; -} sensor_ioctl_temperature_t; +typedef struct sensor_ioctl_scalar { + uint32_t sis_unit; + int32_t sis_gran; + uint32_t sis_prec; + uint32_t sis_pad; + int64_t sis_value; +} sensor_ioctl_scalar_t; #ifdef _KERNEL typedef int (*ksensor_kind_f)(void *, sensor_ioctl_kind_t *); -typedef int (*ksensor_temp_f)(void *, sensor_ioctl_temperature_t *); +typedef int (*ksensor_scalar_f)(void *, sensor_ioctl_scalar_t *); typedef struct { - ksensor_kind_f kso_kind; - ksensor_temp_f kso_temp; + ksensor_kind_f kso_kind; + ksensor_scalar_f kso_scalar; } ksensor_ops_t; extern int ksensor_kind_temperature(void *, sensor_ioctl_kind_t *); +extern int ksensor_kind_voltage(void *, sensor_ioctl_kind_t *); +extern int ksensor_kind_current(void *, sensor_ioctl_kind_t *); /* * Create a sensor where the class and name is supplied. @@ -95,11 +105,11 @@ extern int ksensor_create(dev_info_t *, const ksensor_ops_t *, void *, const char *, const char *, id_t *); /* - * Create a temperature sensor for a PCI device. If this is not a device-wide + * Create a scalar sensor for a PCI device. If this is not a device-wide * (e.g. per-function) sensor, this should not be used. */ -extern int ksensor_create_temp_pcidev(dev_info_t *, const ksensor_ops_t *, - void *, const char *, id_t *); +extern int ksensor_create_scalar_pcidev(dev_info_t *, uint_t, + const ksensor_ops_t *, void *, const char *, id_t *); /* * Remove a named or all sensors from this driver. diff --git a/usr/src/uts/intel/io/amdf17nbdf/amdf17nbdf.c b/usr/src/uts/intel/io/amdf17nbdf/amdf17nbdf.c index 6b7da6a99a..7be8a4a9f8 100644 --- a/usr/src/uts/intel/io/amdf17nbdf/amdf17nbdf.c +++ b/usr/src/uts/intel/io/amdf17nbdf/amdf17nbdf.c @@ -684,13 +684,14 @@ amdf17nbdf_ioctl_kind(intptr_t arg, int mode) } static int -amdf17nbdf_ioctl_temp(amdf17nbdf_t *nbdf, minor_t minor, intptr_t arg, int mode) +amdf17nbdf_ioctl_scalar(amdf17nbdf_t *nbdf, minor_t minor, intptr_t arg, + int mode) { amdf17nb_t *nb; hrtime_t diff; - sensor_ioctl_temperature_t temp; + sensor_ioctl_scalar_t scalar; - bzero(&temp, sizeof (temp)); + bzero(&scalar, sizeof (scalar)); mutex_enter(&nbdf->amd_nbdf_lock); nb = amdf17nbdf_lookup_nb(nbdf, minor); @@ -710,12 +711,12 @@ amdf17nbdf_ioctl_temp(amdf17nbdf_t *nbdf, minor_t minor, intptr_t arg, int mode) } } - temp.sit_unit = SENSOR_UNIT_CELSIUS; - temp.sit_temp = nb->amd_nb_temp; - temp.sit_gran = AMDF17_THERMAL_GRANULARITY; + scalar.sis_unit = SENSOR_UNIT_CELSIUS; + scalar.sis_value = nb->amd_nb_temp; + scalar.sis_gran = AMDF17_THERMAL_GRANULARITY; mutex_exit(&nbdf->amd_nbdf_lock); - if (ddi_copyout(&temp, (void *)arg, sizeof (temp), + if (ddi_copyout(&scalar, (void *)arg, sizeof (scalar), mode & FKIOCTL) != 0) { return (EFAULT); } @@ -737,10 +738,10 @@ amdf17nbdf_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, m = getminor(dev); switch (cmd) { - case SENSOR_IOCTL_TYPE: + case SENSOR_IOCTL_KIND: return (amdf17nbdf_ioctl_kind(arg, mode)); - case SENSOR_IOCTL_TEMPERATURE: - return (amdf17nbdf_ioctl_temp(nbdf, m, arg, mode)); + case SENSOR_IOCTL_SCALAR: + return (amdf17nbdf_ioctl_scalar(nbdf, m, arg, mode)); default: return (ENOTTY); } diff --git a/usr/src/uts/intel/io/amdnbtemp/amdnbtemp.c b/usr/src/uts/intel/io/amdnbtemp/amdnbtemp.c index 1330f8563f..17934520fd 100644 --- a/usr/src/uts/intel/io/amdnbtemp/amdnbtemp.c +++ b/usr/src/uts/intel/io/amdnbtemp/amdnbtemp.c @@ -103,7 +103,7 @@ typedef struct amdnbtemp { static void *amdnbtemp_state; static int -amdnbtemp_read(void *arg, sensor_ioctl_temperature_t *temp) +amdnbtemp_read(void *arg, sensor_ioctl_scalar_t *scalar) { amdnbtemp_t *at = arg; @@ -120,9 +120,9 @@ amdnbtemp_read(void *arg, sensor_ioctl_temperature_t *temp) at->at_temp -= AMDNBTEMP_TEMP_ADJUST; } - temp->sit_unit = SENSOR_UNIT_CELSIUS; - temp->sit_gran = AMDNBTEMP_GRANULARITY; - temp->sit_temp = at->at_temp; + scalar->sis_unit = SENSOR_UNIT_CELSIUS; + scalar->sis_gran = AMDNBTEMP_GRANULARITY; + scalar->sis_value = at->at_temp; mutex_exit(&at->at_mutex); return (0); @@ -130,7 +130,7 @@ amdnbtemp_read(void *arg, sensor_ioctl_temperature_t *temp) static const ksensor_ops_t amdnbtemp_temp_ops = { .kso_kind = ksensor_kind_temperature, - .kso_temp = amdnbtemp_read + .kso_scalar = amdnbtemp_read }; static void diff --git a/usr/src/uts/intel/io/coretemp/coretemp.c b/usr/src/uts/intel/io/coretemp/coretemp.c index ee2d143554..bea8078002 100644 --- a/usr/src/uts/intel/io/coretemp/coretemp.c +++ b/usr/src/uts/intel/io/coretemp/coretemp.c @@ -259,7 +259,7 @@ coretemp_update(coretemp_t *ct, coretemp_sensor_t *sensor, cmi_hdl_t hdl) } static int -coretemp_read(void *arg, sensor_ioctl_temperature_t *sit) +coretemp_read(void *arg, sensor_ioctl_scalar_t *scalar) { coretemp_sensor_t *sensor = arg; coretemp_t *ct = sensor->cs_coretemp; @@ -313,10 +313,10 @@ coretemp_read(void *arg, sensor_ioctl_temperature_t *sit) sensor->cs_temperature = sensor->cs_tjmax - reading; sensor->cs_resolution = resolution; - sit->sit_unit = SENSOR_UNIT_CELSIUS; - sit->sit_temp = sensor->cs_temperature; - sit->sit_gran = CORETEMP_GRANULARITY; - sit->sit_prec = sensor->cs_resolution; + scalar->sis_unit = SENSOR_UNIT_CELSIUS; + scalar->sis_value = sensor->cs_temperature; + scalar->sis_gran = CORETEMP_GRANULARITY; + scalar->sis_prec = sensor->cs_resolution; mutex_exit(&ct->coretemp_mutex); return (0); @@ -324,7 +324,7 @@ coretemp_read(void *arg, sensor_ioctl_temperature_t *sit) static const ksensor_ops_t coretemp_temp_ops = { .kso_kind = ksensor_kind_temperature, - .kso_temp = coretemp_read + .kso_scalar = coretemp_read }; static void diff --git a/usr/src/uts/intel/io/pchtemp/pchtemp.c b/usr/src/uts/intel/io/pchtemp/pchtemp.c index 4aeb098112..2cfd7ae806 100644 --- a/usr/src/uts/intel/io/pchtemp/pchtemp.c +++ b/usr/src/uts/intel/io/pchtemp/pchtemp.c @@ -137,7 +137,7 @@ pchtemp_read_check(pchtemp_t *pch) } static int -pchtemp_read(void *arg, sensor_ioctl_temperature_t *sit) +pchtemp_read(void *arg, sensor_ioctl_scalar_t *scalar) { uint16_t temp, ctt, tahv, talv; uint8_t tsel; @@ -175,9 +175,9 @@ pchtemp_read(void *arg, sensor_ioctl_temperature_t *sit) } pch->pcht_temp = (temp & PCHTEMP_REG_TEMP_TSR) - PCHTEMP_TEMP_OFFSET; - sit->sit_unit = SENSOR_UNIT_CELSIUS; - sit->sit_gran = PCHTEMP_TEMP_RESOLUTION; - sit->sit_temp = pch->pcht_temp; + scalar->sis_unit = SENSOR_UNIT_CELSIUS; + scalar->sis_gran = PCHTEMP_TEMP_RESOLUTION; + scalar->sis_value = pch->pcht_temp; mutex_exit(&pch->pcht_mutex); return (0); @@ -185,7 +185,7 @@ pchtemp_read(void *arg, sensor_ioctl_temperature_t *sit) static const ksensor_ops_t pchtemp_temp_ops = { .kso_kind = ksensor_kind_temperature, - .kso_temp = pchtemp_read + .kso_scalar = pchtemp_read }; static void -- cgit v1.2.3 From c6795799963479a5ddb9b97ebb4cf6c1c97c1fba Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Wed, 9 Sep 2020 22:30:42 -0700 Subject: 13119 Want support for SMBIOS 3.4 Reviewed by: C Fraire Reviewed by: Toomas Soome Approved by: Dan McDonald --- usr/src/cmd/smbios/smbios.c | 22 +- usr/src/common/smbios/smb_info.c | 42 ++- usr/src/common/smbios/smb_open.c | 1 + usr/src/test/util-tests/tests/smbios/smbios.c | 19 +- usr/src/test/util-tests/tests/smbios/smbios_test.h | 5 + .../util-tests/tests/smbios/smbios_test_slot.c | 375 ++++++++++++++++++--- usr/src/uts/common/sys/smbios.h | 38 ++- usr/src/uts/common/sys/smbios_impl.h | 18 + 8 files changed, 466 insertions(+), 54 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/cmd/smbios/smbios.c b/usr/src/cmd/smbios/smbios.c index 5597e04fc5..dedfe29e9c 100644 --- a/usr/src/cmd/smbios/smbios.c +++ b/usr/src/cmd/smbios/smbios.c @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2017, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -716,7 +717,7 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) oprintf(fp, " Slot Peer %u:\n", i); oprintf(fp, " Segment group: %u\n", peer[i].smblp_group); - oprintf(fp, " Bus/Device/Function: %u/%u/%u", + oprintf(fp, " Bus/Device/Function: %u/%u/%u\n", peer[i].smblp_bus, peer[i].smblp_device, peer[i].smblp_function); oprintf(fp, " Electrical width: %u\n", @@ -725,6 +726,25 @@ print_slot(smbios_hdl_t *shp, id_t id, FILE *fp) smbios_info_slot_peers_free(shp, npeers, peer); } + + if (s.smbl_info != 0) { + if (s.smbl_type >= SMB_SLT_PCIE && + s.smbl_type <= SMB_SLT_PCIEG6P) { + oprintf(fp, " PCIe Generation: %d\n", s.smbl_info); + } else { + oprintf(fp, " Slot Type: 0x%x\n", s.smbl_info); + } + } + + if (s.smbl_pwidth != 0) { + desc_printf(smbios_slot_width_desc(s.smbl_pwidth), + fp, " Physical Width: 0x%x", s.smbl_pwidth); + } + + if (s.smbl_pitch != 0) { + oprintf(fp, " Slot Pitch: %u.%u mm\n", s.smbl_pitch / 100, + s.smbl_pitch % 100); + } } static void diff --git a/usr/src/common/smbios/smb_info.c b/usr/src/common/smbios/smb_info.c index 47c19e7fcb..9aba4deba8 100644 --- a/usr/src/common/smbios/smb_info.c +++ b/usr/src/common/smbios/smb_info.c @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright 2019 Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -231,14 +232,25 @@ smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n) return (smb_strptr(stp, 0)); } +static void +smb_info_bcopy_offset(const smb_header_t *hp, void *dst, size_t dstlen, + size_t offset) +{ + if (offset >= hp->smbh_len) { + bzero(dst, dstlen); + } else if (offset + dstlen > hp->smbh_len) { + size_t nvalid = MIN(hp->smbh_len - offset, dstlen); + bcopy((char *)hp + offset, dst, nvalid); + bzero((char *)dst + nvalid, dstlen - nvalid); + } else { + bcopy((char *)hp + offset, dst, dstlen); + } +} + static void smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen) { - if (dstlen > hp->smbh_len) { - bcopy(hp, dst, hp->smbh_len); - bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len); - } else - bcopy(hp, dst, dstlen); + return (smb_info_bcopy_offset(hp, dst, dstlen, 0)); } smbios_entry_point_t @@ -674,6 +686,8 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) { const smb_struct_t *stp = smb_lookup_id(shp, id); smb_slot_t s; + smb_slot_cont_t cont; + size_t off; if (stp == NULL) return (-1); /* errno is set for us */ @@ -701,6 +715,24 @@ smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp) sp->smbl_npeers = s.smbsl_npeers; } + if (!smb_libgteq(shp, SMB_VERSION_34)) { + return (0); + } + + /* + * In SMBIOS 3.4, several members were added to follow the variable + * number of peers. These are defined to start at byte 0x14 + 5 * + * npeers. If the table is from before 3.4, we simple zero things out. + * Otherwise we check if the length covers the peers and this addendum + * to include it as the table length is allowed to be less than this and + * not include it. + */ + off = SMB_SLOT_CONT_START + 5 * s.smbsl_npeers; + smb_info_bcopy_offset(stp->smbst_hdr, &cont, sizeof (cont), off); + sp->smbl_info = cont.smbsl_info; + sp->smbl_pwidth = cont.smbsl_pwidth; + sp->smbl_pitch = cont.smbsl_pitch; + return (0); } diff --git a/usr/src/common/smbios/smb_open.c b/usr/src/common/smbios/smb_open.c index 372b2b619b..6747c84499 100644 --- a/usr/src/common/smbios/smb_open.c +++ b/usr/src/common/smbios/smb_open.c @@ -231,6 +231,7 @@ smbios_bufopen(const smbios_entry_t *ep, const void *buf, size_t len, case SMB_VERSION_31: case SMB_VERSION_32: case SMB_VERSION_33: + case SMB_VERSION_34: break; default: return (smb_open_error(shp, errp, ESMB_VERSION)); diff --git a/usr/src/test/util-tests/tests/smbios/smbios.c b/usr/src/test/util-tests/tests/smbios/smbios.c index 364cb9344f..429d4f81be 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios.c +++ b/usr/src/test/util-tests/tests/smbios/smbios.c @@ -11,6 +11,7 @@ /* * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company */ /* @@ -219,7 +220,23 @@ static const smbios_test_t smbios_tests[] = { .st_mktable = smbios_test_slot_mktable, .st_canopen = B_TRUE, .st_verify = smbios_test_slot_verify, - .st_desc = "slot tests" + .st_desc = "slot 3.2" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_34, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_slot_mktable_34_nopeers, + .st_canopen = B_TRUE, + .st_verify = smbios_test_slot_verify_34_nopeers, + .st_desc = "slot 3.4 without peers" + }, { + .st_entry = SMBIOS_ENTRY_POINT_30, + .st_tvers = SMB_VERSION_34, + .st_libvers = SMB_VERSION, + .st_mktable = smbios_test_slot_mktable_34_peers, + .st_canopen = B_TRUE, + .st_verify = smbios_test_slot_verify_34_peers, + .st_desc = "slot 3.4 with peers" }, { .st_entry = SMBIOS_ENTRY_POINT_30, .st_tvers = SMB_VERSION, diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test.h b/usr/src/test/util-tests/tests/smbios/smbios_test.h index 62baed7813..c6490f1d13 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test.h +++ b/usr/src/test/util-tests/tests/smbios/smbios_test.h @@ -11,6 +11,7 @@ /* * Copyright 2019 Robert Mustacchi + * Copyright 2020 Oxide Computer Company */ #ifndef _SMBIOS_TEST_H @@ -78,7 +79,11 @@ typedef struct smbios_test { * Test functions */ extern boolean_t smbios_test_slot_mktable(smbios_test_table_t *); +extern boolean_t smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *); +extern boolean_t smbios_test_slot_mktable_34_peers(smbios_test_table_t *); extern boolean_t smbios_test_slot_verify(smbios_hdl_t *); +extern boolean_t smbios_test_slot_verify_34_nopeers(smbios_hdl_t *); +extern boolean_t smbios_test_slot_verify_34_peers(smbios_hdl_t *); extern boolean_t smbios_test_badvers_mktable(smbios_test_table_t *); extern boolean_t smbios_test_memdevice_mktable_32(smbios_test_table_t *); diff --git a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c index d84cc10e91..95a709a088 100644 --- a/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c +++ b/usr/src/test/util-tests/tests/smbios/smbios_test_slot.c @@ -11,6 +11,7 @@ /* * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company */ /* @@ -20,6 +21,29 @@ #include "smbios_test.h" static const char *smbios_test_name = "The One Slot"; +static uint8_t smbios_slot_bus = 0x42; +static uint8_t smbios_slot_df = 0x23; +static uint8_t smbios_slot_info = 0x65; +static uint16_t smbios_slot_pitch = 0x12af; + +static void +smbios_test_slot_fill(smb_slot_t *slot) +{ + bzero(slot, sizeof (smb_slot_t)); + slot->smbsl_hdr.smbh_type = SMB_TYPE_SLOT; + slot->smbsl_hdr.smbh_len = sizeof (smb_slot_t); + slot->smbsl_name = 1; + slot->smbsl_type = SMB_SLT_PCIE3G16; + slot->smbsl_width = SMB_SLW_16X; + slot->smbsl_length = SMB_SLL_SHORT; + slot->smbsl_id = htole16(1); + slot->smbsl_ch1 = SMB_SLCH1_33V; + slot->smbsl_ch2 = SMB_SLCH2_PME; + slot->smbsl_sg = htole16(1); + slot->smbsl_bus = smbios_slot_bus; + slot->smbsl_df = smbios_slot_df; + slot->smbsl_dbw = SMB_SLW_16X; +} boolean_t smbios_test_slot_mktable(smbios_test_table_t *table) @@ -28,21 +52,11 @@ smbios_test_slot_mktable(smbios_test_table_t *table) smb_slot_peer_t peers[2]; const uint8_t endstring = 0; - slot.smbsl_hdr.smbh_type = SMB_TYPE_SLOT; - slot.smbsl_hdr.smbh_len = sizeof (smb_slot_t) + sizeof (peers); - - slot.smbsl_name = 1; - slot.smbsl_type = SMB_SLT_PCIE3G16; - slot.smbsl_width = SMB_SLW_16X; - slot.smbsl_length = SMB_SLL_SHORT; - slot.smbsl_id = htole16(1); - slot.smbsl_ch1 = SMB_SLCH1_33V; - slot.smbsl_ch2 = SMB_SLCH2_PME; - slot.smbsl_sg = htole16(1); - slot.smbsl_bus = 0x42; - slot.smbsl_df = 0x23; - slot.smbsl_dbw = SMB_SLW_16X; + smbios_test_slot_fill(&slot); + + slot.smbsl_hdr.smbh_len += sizeof (peers); slot.smbsl_npeers = 2; + peers[0].smbspb_group_no = htole16(1); peers[0].smbspb_bus = 0x42; peers[0].smbspb_df = 0x42; @@ -64,6 +78,121 @@ smbios_test_slot_mktable(smbios_test_table_t *table) return (B_TRUE); } +/* + * 3.4 introduced additional data after peers. This verison constructs a variant + * with no peers. + */ +boolean_t +smbios_test_slot_mktable_34_nopeers(smbios_test_table_t *table) +{ + smb_slot_t slot; + smb_slot_cont_t cont; + const uint8_t endstring = 0; + + smbios_test_slot_fill(&slot); + slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + sizeof (cont); + + cont.smbsl_info = smbios_slot_info; + cont.smbsl_pwidth = SMB_SLW_32X; + cont.smbsl_pitch = htole16(smbios_slot_pitch); + + (void) smbios_test_table_append(table, &slot, sizeof (slot)); + /* + * Append a raw zero to fill in the gaps that the peers would have had + * so the cont structure starts at the right offset. + */ + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); + (void) smbios_test_table_append_string(table, smbios_test_name); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_eot(table); + return (B_TRUE); +} + +boolean_t +smbios_test_slot_mktable_34_peers(smbios_test_table_t *table) +{ + smb_slot_t slot; + smb_slot_cont_t cont; + smb_slot_peer_t peers[1]; + const uint8_t endstring = 0; + + smbios_test_slot_fill(&slot); + slot.smbsl_npeers = 1; + slot.smbsl_hdr.smbh_len = SMB_SLOT_CONT_START + 5 * slot.smbsl_npeers + + sizeof (cont); + + peers[0].smbspb_group_no = htole16(1); + peers[0].smbspb_bus = 0x42; + peers[0].smbspb_df = 0x9a; + peers[0].smbspb_width = SMB_SLW_8X; + + cont.smbsl_info = smbios_slot_info; + cont.smbsl_pwidth = SMB_SLW_32X; + cont.smbsl_pitch = htole16(smbios_slot_pitch); + + (void) smbios_test_table_append(table, &slot, sizeof (slot)); + (void) smbios_test_table_append_raw(table, peers, sizeof (peers)); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + (void) smbios_test_table_append_raw(table, &cont, sizeof (cont)); + (void) smbios_test_table_append_string(table, smbios_test_name); + (void) smbios_test_table_append_raw(table, &endstring, + sizeof (endstring)); + smbios_test_table_append_eot(table); + return (B_TRUE); +} + + +static boolean_t +smbios_test_slot_common(smbios_slot_t *slot) +{ + uint_t errs = 0; + + if (strcmp(slot->smbl_name, smbios_test_name) != 0) { + warnx("slot name mismatch, expected %s, found %s", + smbios_test_name, slot->smbl_name); + errs++; + } + + if (slot->smbl_type != SMB_SLT_PCIE3G16) { + warnx("incorrect slot type, found %u", slot->smbl_type); + errs++; + } + + if (slot->smbl_width != SMB_SLW_16X) { + warnx("incorrect slot width, found %u", slot->smbl_width); + errs++; + } + + if (slot->smbl_length != SMB_SLL_SHORT) { + warnx("incorrect slot length, found %u", slot->smbl_length); + errs++; + } + + if (slot->smbl_dbw != SMB_SLW_16X) { + warnx("incorrect slot data bus width, found %u", + slot->smbl_dbw); + errs++; + } + + if (slot->smbl_bus != smbios_slot_bus) { + warnx("incorrect slot bus id, found 0x%x\n", slot->smbl_bus); + } + + if (slot->smbl_df != smbios_slot_df) { + warnx("incorrect slot df id, found 0x%x\n", slot->smbl_df); + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + boolean_t smbios_test_slot_verify(smbios_hdl_t *hdl) { @@ -85,32 +214,7 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) return (B_FALSE); } - /* - * Verify everything we'd expect about the slot. - */ - if (strcmp(slot.smbl_name, smbios_test_name) != 0) { - warnx("slot name mismatch, expected %s, found %s", - smbios_test_name, slot.smbl_name); - errs++; - } - - if (slot.smbl_type != SMB_SLT_PCIE3G16) { - warnx("incorrect slot type, found %u", slot.smbl_type); - errs++; - } - - if (slot.smbl_width != SMB_SLW_16X) { - warnx("incorrect slot width, found %u", slot.smbl_width); - errs++; - } - - if (slot.smbl_length != SMB_SLL_SHORT) { - warnx("incorrect slot length, found %u", slot.smbl_length); - errs++; - } - - if (slot.smbl_dbw != SMB_SLW_16X) { - warnx("incorrect slot data bus width, found %u", slot.smbl_dbw); + if (!smbios_test_slot_common(&slot)) { errs++; } @@ -127,8 +231,7 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) } if (npeers != 2) { - warnx("got wrong number of slot peers: %u\n", - npeers); + warnx("got wrong number of slot peers: %u", npeers); return (B_FALSE); } @@ -180,6 +283,194 @@ smbios_test_slot_verify(smbios_hdl_t *hdl) smbios_info_slot_peers_free(hdl, npeers, peers); + if (slot.smbl_info != 0) { + warnx("found wrong slot info: 0x%x", slot.smbl_info); + errs++; + } + + if (slot.smbl_pwidth != 0) { + warnx("found wrong slot physical width: 0x%x", + slot.smbl_pwidth); + errs++; + } + + if (slot.smbl_pitch != 0) { + warnx("found wrong slot pitch: 0x%x", slot.smbl_pitch); + errs++; + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + +boolean_t +smbios_test_slot_verify_34_nopeers(smbios_hdl_t *hdl) +{ + smbios_struct_t sp; + smbios_slot_t slot; + uint_t npeers; + smbios_slot_peer_t *peers; + uint_t errs = 0; + + if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { + warnx("failed to lookup SMBIOS slot: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { + warnx("failed to get SMBIOS slot info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (!smbios_test_slot_common(&slot)) { + errs++; + } + + if (slot.smbl_npeers != 0) { + warnx("incorrect number of slot peers, found %u", + slot.smbl_npeers); + errs++; + } + + if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { + warnx("failed to get SMBIOS peer info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (npeers != 0) { + warnx("got wrong number of slot peers: %u", npeers); + errs++; + } + + if (peers != NULL) { + warnx("expected NULL peers pointer, but found %p", peers); + errs++; + } + + smbios_info_slot_peers_free(hdl, npeers, peers); + + if (slot.smbl_info != smbios_slot_info) { + warnx("found wrong slot info: 0x%x, expected 0x%x", + slot.smbl_info, smbios_slot_info); + errs++; + } + + if (slot.smbl_pwidth != SMB_SLW_32X) { + warnx("found wrong slot physical width: 0x%x, expected 0x%x", + slot.smbl_pwidth, SMB_SLW_32X); + errs++; + } + + if (slot.smbl_pitch != smbios_slot_pitch) { + warnx("found wrong slot pitch: 0x%x, expected 0x%x", + slot.smbl_pitch, smbios_slot_pitch); + errs++; + } + + if (errs > 0) { + return (B_FALSE); + } + + return (B_TRUE); +} + +boolean_t +smbios_test_slot_verify_34_peers(smbios_hdl_t *hdl) +{ + smbios_struct_t sp; + smbios_slot_t slot; + uint_t npeers; + smbios_slot_peer_t *peers; + uint_t errs = 0; + + if (smbios_lookup_type(hdl, SMB_TYPE_SLOT, &sp) == -1) { + warnx("failed to lookup SMBIOS slot: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (smbios_info_slot(hdl, sp.smbstr_id, &slot) != 0) { + warnx("failed to get SMBIOS slot info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (!smbios_test_slot_common(&slot)) { + errs++; + } + + if (slot.smbl_npeers != 1) { + warnx("incorrect number of slot peers, found %u", + slot.smbl_npeers); + errs++; + } + + if (smbios_info_slot_peers(hdl, sp.smbstr_id, &npeers, &peers) != 0) { + warnx("failed to get SMBIOS peer info: %s", + smbios_errmsg(smbios_errno(hdl))); + return (B_FALSE); + } + + if (npeers != 1) { + warnx("got wrong number of slot peers: %u", npeers); + errs++; + } + + if (peers[0].smblp_group != 1) { + warnx("incorrect group for peer 0: %u", peers[0].smblp_group); + errs++; + } + + if (peers[0].smblp_data_width != SMB_SLW_8X) { + warnx("incorrect data width for peer 0: %u", + peers[0].smblp_data_width); + errs++; + } + + if (peers[0].smblp_bus != 0x42) { + warnx("incorrect PCI bus for peer 0: %u", + peers[0].smblp_bus); + errs++; + } + + if (peers[0].smblp_device != (0x9a >> 3)) { + warnx("incorrect PCI device for peer 0: %u", + peers[0].smblp_device); + errs++; + } + + if (peers[0].smblp_function != (0x9a & 0x7)) { + warnx("incorrect PCI function for peer 0: %u", + peers[0].smblp_function); + errs++; + } + + smbios_info_slot_peers_free(hdl, npeers, peers); + + if (slot.smbl_info != smbios_slot_info) { + warnx("found wrong slot info: 0x%x, expected 0x%x", + slot.smbl_info, smbios_slot_info); + errs++; + } + + if (slot.smbl_pwidth != SMB_SLW_32X) { + warnx("found wrong slot physical width: 0x%x, expected 0x%x", + slot.smbl_pwidth, SMB_SLW_32X); + errs++; + } + + if (slot.smbl_pitch != smbios_slot_pitch) { + warnx("found wrong slot pitch: 0x%x, expected 0x%x", + slot.smbl_pitch, smbios_slot_pitch); + errs++; + } + if (errs > 0) { return (B_FALSE); } diff --git a/usr/src/uts/common/sys/smbios.h b/usr/src/uts/common/sys/smbios.h index 55048d549d..b8b470b79a 100644 --- a/usr/src/uts/common/sys/smbios.h +++ b/usr/src/uts/common/sys/smbios.h @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -527,6 +528,8 @@ typedef struct smbios_processor { #define SMB_PRU_BGA1392 0x3A /* Socket BGA1392 */ #define SMB_PRU_BGA1510 0x3B /* Socket BGA1510 */ #define SMB_PRU_BGA1528 0x3C /* Socket BGA1528 */ +#define SMB_PRU_LGA4189 0x3D /* Socket LGA4189 */ +#define SMB_PRU_LGA1200 0x3E /* Socket LGA1200 */ #define SMB_PRC_RESERVED 0x0001 /* reserved */ #define SMB_PRC_UNKNOWN 0x0002 /* unknown */ @@ -944,6 +947,9 @@ typedef struct smbios_slot { uint8_t smbl_df; /* device/function number */ uint8_t smbl_dbw; /* data bus width */ uint8_t smbl_npeers; /* PCIe bifurcation peers */ + uint8_t smbl_info; /* slot info */ + uint8_t smbl_pwidth; /* slot physical width */ + uint32_t smbl_pitch; /* slot pitch in 10um */ } smbios_slot_t; #define SMB_SLT_OTHER 0x01 /* other */ @@ -976,8 +982,8 @@ typedef struct smbios_slot { #define SMB_SLT_MXM_V 0x1C /* MXM Type IV */ #define SMB_SLT_MXM3_A 0x1D /* MXM 3.0 Type A */ #define SMB_SLT_MXM3_B 0x1E /* MXM 3.0 Type B */ -#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 */ -#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 */ +#define SMB_SLT_PCIEG2_SFF 0x1F /* PCI Express Gen 2 SFF-8639 (U.2) */ +#define SMB_SLT_PCIEG3_SFF 0x20 /* PCI Express Gen 3 SFF-8639 (U.2) */ /* * These lines must be on one line for the string generating code. */ @@ -986,6 +992,11 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE_M52_WOBSKO 0x22 /* PCI Express Mini 52-pin without bottom-side keep-outs */ /* END CSTYLED */ #define SMB_SLT_PCIE_M76 0x23 /* PCI Express Mini 72-pin */ +#define SMB_SLT_PCIEG4_SFF 0x24 /* PCI Express Gen 4 SFF-8639 (U.2) */ +#define SMB_SLT_PCIEG5_SFF 0x25 /* PCI Express Gen 5 SFF-8639 (U.2) */ +#define SMB_SLT_OCP3_SFF 0x26 /* OCP NIC 3.0 Small Form Factor */ +#define SMB_SLT_OCP3_LFF 0x27 /* OCP NIC 3.0 Large Form Factor */ +#define SMB_SLT_OCP_PRE 0x28 /* OCP NIC prior to 3.0 */ #define SMB_SLT_CXL1 0x30 /* CXL Flexbus 1.0 */ #define SMB_SLT_PC98_C20 0xA0 /* PC-98/C20 */ #define SMB_SLT_PC98_C24 0xA1 /* PC-98/C24 */ @@ -1016,6 +1027,15 @@ typedef struct smbios_slot { #define SMB_SLT_PCIE4G4 0xBB /* PCI Exp. Gen 4 x4 */ #define SMB_SLT_PCIE4G8 0xBC /* PCI Exp. Gen 4 x8 */ #define SMB_SLT_PCIE4G16 0xBD /* PCI Exp. Gen 4 x16 */ +#define SMB_SLT_PCIE5G 0xBE /* PCI Exp. Gen 5 */ +#define SMB_SLT_PCIE5G1 0xBF /* PCI Exp. Gen 5 x1 */ +#define SMB_SLT_PCIE5G2 0xC0 /* PCI Exp. Gen 5 x2 */ +#define SMB_SLT_PCIE5G4 0xC1 /* PCI Exp. Gen 5 x4 */ +#define SMB_SLT_PCIE5G8 0xC2 /* PCI Exp. Gen 5 x8 */ +#define SMB_SLT_PCIE5G16 0xC3 /* PCI Exp. Gen 5 x16 */ +#define SMB_SLT_PCIEG6P 0xC4 /* PCI Exp. Gen 6+ */ +#define SMB_SLT_EDSFF_E1 0xC5 /* Ent. and DC 1U E1 Form Factor */ +#define SMB_SLT_EDSFF_E3 0xC6 /* Ent. and DC 3" E3 Form Factor */ #define SMB_SLW_OTHER 0x01 /* other */ #define SMB_SLW_UNKNOWN 0x02 /* unknown */ @@ -1041,6 +1061,8 @@ typedef struct smbios_slot { #define SMB_SLL_UNKNOWN 0x02 /* unknown */ #define SMB_SLL_SHORT 0x03 /* short length */ #define SMB_SLL_LONG 0x04 /* long length */ +#define SMB_SLL_2IN5 0x05 /* 2.5" drive form factor */ +#define SMB_SLL_3IN5 0x06 /* 3.5" drive form factor */ #define SMB_SLCH1_UNKNOWN 0x01 /* characteristics unknown */ #define SMB_SLCH1_5V 0x02 /* provides 5.0V */ @@ -1055,6 +1077,9 @@ typedef struct smbios_slot { #define SMB_SLCH2_HOTPLUG 0x02 /* slot supports hot-plug devices */ #define SMB_SLCH2_SMBUS 0x04 /* slot supports SMBus signal */ #define SMB_SLCH2_BIFUR 0x08 /* slot supports PCIe bifurcation */ +#define SMB_SLCH2_SURPREM 0x10 /* slot supports surprise removal */ +#define SMB_SLCH2_CXL1 0x20 /* Flexbus slot, CXL 1.0 capable */ +#define SMB_SLCH2_CXL2 0x40 /* Flexbus slot, CXL 2.0 capable */ /* * SMBIOS 7.10.9 Slot Peer Devices @@ -1178,7 +1203,7 @@ typedef struct smbios_memarray { #define SMB_MAL_PC98C24 0xA1 /* PC-98/C24 add-on card */ #define SMB_MAL_PC98E 0xA2 /* PC-98/E add-on card */ #define SMB_MAL_PC98LB 0xA3 /* PC-98/Local bus add-on card */ -#define SMB_MAL_CXL1 0xA4 /* CXL Flexbus 1.0 add-on card */ +#define SMB_MAL_CXL1 0xA4 /* CXL add-on card */ #define SMB_MAU_OTHER 0x01 /* other */ #define SMB_MAU_UNKNOWN 0x02 /* unknown */ @@ -1285,6 +1310,8 @@ typedef struct smbios_memdevice { #define SMB_MDT_LOGNV 0x1F /* Logical non-volatile device */ #define SMB_MDT_HBM 0x20 /* High Bandwidth Memory */ #define SMB_MDT_HBM2 0x21 /* High Bandwidth Memory 2 */ +#define SMB_MDT_DDR5 0x22 /* DDR5 */ +#define SMB_MDT_LPDDR5 0x23 /* LPDDR5 */ #define SMB_MDF_OTHER 0x0002 /* other */ #define SMB_MDF_UNKNOWN 0x0004 /* unknown */ @@ -1313,7 +1340,7 @@ typedef struct smbios_memdevice { #define SMB_MTECH_NVDIMM_N 0x04 /* NVDIMM-N */ #define SMB_MTECH_NVDIMM_F 0x05 /* NVDIMM-F */ #define SMB_MTECH_NVDIMM_P 0x06 /* NVDIMM-P */ -#define SMB_MTECH_INTCPM 0x07 /* Intel Optane DC Persistent Memory */ +#define SMB_MTECH_INTCPM 0x07 /* Intel Optane persistent memory */ #define SMB_MOMC_RESERVED 0x01 /* reserved */ #define SMB_MOMC_OTHER 0x02 /* other */ @@ -1838,7 +1865,8 @@ typedef struct smbios_memdevice_ext { #define SMB_VERSION_31 0x0301 /* SMBIOS encoding for DMTF spec 3.1 */ #define SMB_VERSION_32 0x0302 /* SMBIOS encoding for DMTF spec 3.2 */ #define SMB_VERSION_33 0x0303 /* SMBIOS encoding for DMTF spec 3.3 */ -#define SMB_VERSION SMB_VERSION_33 /* SMBIOS latest version definitions */ +#define SMB_VERSION_34 0x0304 /* SMBIOS encoding for DMTF spec 3.4 */ +#define SMB_VERSION SMB_VERSION_34 /* SMBIOS latest version definitions */ #define SMB_O_NOCKSUM 0x1 /* do not verify header checksums */ #define SMB_O_NOVERS 0x2 /* do not verify header versions */ diff --git a/usr/src/uts/common/sys/smbios_impl.h b/usr/src/uts/common/sys/smbios_impl.h index 69ca79e94f..4b951b702f 100644 --- a/usr/src/uts/common/sys/smbios_impl.h +++ b/usr/src/uts/common/sys/smbios_impl.h @@ -22,6 +22,7 @@ /* * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. * Copyright (c) 2018, Joyent, Inc. + * Copyright 2020 Oxide Computer Company * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -250,8 +251,25 @@ typedef struct smb_slot { uint8_t smbsl_dbw; /* Data bus width */ uint8_t smbsl_npeers; /* Peer bdf groups */ smb_slot_peer_t smbsl_peers[]; /* bifurcation peers */ + /* There are later additions in 3.4+, see smbios_slot_cont_t */ } smb_slot_t; +/* + * After the variable number of smbsl_peers, the smbios_slot has continued in + * size and has the following members defined as of version 3.4. These occur + * starting at byte 14 + 5 * smbsl_npeers. + */ +typedef struct smb_slot_cont { + uint8_t smbsl_info; /* slot info */ + uint8_t smbsl_pwidth; /* slot physical width */ + uint16_t smbsl_pitch; /* slot pitch */ +} smb_slot_cont_t; + +/* + * The first byte that the smb_slot_cont_t is defined to start at. + */ +#define SMB_SLOT_CONT_START 0x14 + /* * SMBIOS implementation structure for SMB_TYPE_OBDEVS. */ -- cgit v1.2.3 From b7a7784945b3504d0b69ea02a08e1cddb5578907 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Sat, 5 Sep 2020 22:23:36 +0000 Subject: 13111 Want futimes(), lutimes() and timespec/timeval conversion macros Reviewed by: Robert Mustacchi Reviewed by: Marco van Wieringen Approved by: Dan McDonald --- usr/src/lib/libc/port/mapfile-vers | 6 + usr/src/lib/libc/port/sys/utimesys.c | 28 +- usr/src/man/man2/Makefile | 5 + usr/src/man/man2/utimes.2 | 58 ++- usr/src/man/man3head/Makefile | 9 + usr/src/man/man3head/timespec.3head | 106 +++++ usr/src/man/man3lib/libc.3lib | 251 +++++----- usr/src/pkg/manifests/system-header.mf | 7 + usr/src/pkg/manifests/system-kernel.man2.inc | 5 +- usr/src/pkg/manifests/system-test-libctest.mf | 3 + usr/src/prototypes/prototype.man3x | 2 +- usr/src/test/libc-tests/cfg/symbols/sys_time_h.cfg | 14 + usr/src/test/libc-tests/runfiles/default.run | 3 + usr/src/test/libc-tests/tests/Makefile | 4 +- usr/src/test/libc-tests/tests/utimes.c | 521 +++++++++++++++++++++ usr/src/uts/common/sys/time.h | 27 +- 16 files changed, 893 insertions(+), 156 deletions(-) create mode 100644 usr/src/man/man3head/timespec.3head create mode 100644 usr/src/test/libc-tests/tests/utimes.c (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 6a4c274258..be5b7e73bf 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -78,6 +78,12 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.34 { + protected: + futimes; + lutimes; +} ILLUMOS_0.33; + SYMBOL_VERSION ILLUMOS_0.33 { protected: c16rtomb; diff --git a/usr/src/lib/libc/port/sys/utimesys.c b/usr/src/lib/libc/port/sys/utimesys.c index dc917f27ae..55e53dbb53 100644 --- a/usr/src/lib/libc/port/sys/utimesys.c +++ b/usr/src/lib/libc/port/sys/utimesys.c @@ -24,6 +24,10 @@ * Use is subject to license terms. */ +/* + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + */ + #include "lint.h" #include #include @@ -67,8 +71,8 @@ utime(const char *path, const struct utimbuf *times) return (utimensat(AT_FDCWD, path, tsp, 0)); } -int -utimes(const char *path, const struct timeval times[2]) +static int +utimes_impl(const char *path, const struct timeval times[2], int flag) { struct timeval ltimes[2]; timespec_t ts[2]; @@ -86,7 +90,19 @@ utimes(const char *path, const struct timeval times[2]) ts[1].tv_nsec = ltimes[1].tv_usec * 1000; tsp = ts; } - return (utimensat(AT_FDCWD, path, tsp, 0)); + return (utimensat(AT_FDCWD, path, tsp, flag)); +} + +int +utimes(const char *path, const struct timeval times[2]) +{ + return (utimes_impl(path, times, 0)); +} + +int +lutimes(const char *path, const struct timeval times[2]) +{ + return (utimes_impl(path, times, AT_SYMLINK_NOFOLLOW)); } #pragma weak _futimesat = futimesat @@ -115,3 +131,9 @@ futimesat(int fd, const char *path, const struct timeval times[2]) return (utimensat(fd, path, tsp, 0)); } + +int +futimes(int fd, const struct timeval times[2]) +{ + return (futimesat(fd, NULL, times)); +} diff --git a/usr/src/man/man2/Makefile b/usr/src/man/man2/Makefile index 556de2d03b..8f664a56fc 100644 --- a/usr/src/man/man2/Makefile +++ b/usr/src/man/man2/Makefile @@ -15,6 +15,7 @@ # Copyright 2013 Nexenta Systems, Inc. All rights reserved. # Copyright (c) 2018, Joyent, Inc. All rights reserved. # Copyright 2017 Peter Tribble +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # include $(SRC)/Makefile.master @@ -196,6 +197,7 @@ MANLINKS= _Exit.2 \ fstat.2 \ fstatat.2 \ fstatvfs.2 \ + futimes.2 \ futimesat.2 \ futimens.2 \ getaudit_addr.2 \ @@ -213,6 +215,7 @@ MANLINKS= _Exit.2 \ lchown.2 \ linkat.2 \ lstat.2 \ + lutimes.2 \ mkdirat.2 \ mknodat.2 \ openat.2 \ @@ -396,7 +399,9 @@ umount2.2 := LINKSRC = umount.2 unlinkat.2 := LINKSRC = unlink.2 futimens.2 := LINKSRC = utimes.2 +futimes.2 := LINKSRC = utimes.2 futimesat.2 := LINKSRC = utimes.2 +lutimes.2 := LINKSRC = utimes.2 utimensat.2 := LINKSRC = utimes.2 vforkx.2 := LINKSRC = vfork.2 diff --git a/usr/src/man/man2/utimes.2 b/usr/src/man/man2/utimes.2 index 69eee29879..404fea7180 100644 --- a/usr/src/man/man2/utimes.2 +++ b/usr/src/man/man2/utimes.2 @@ -43,18 +43,28 @@ .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright (c) 2014, Joyent, Inc. +.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association. .\" -.TH UTIMES 2 "Dec 20, 2014" +.TH UTIMES 2 "Sep 06, 2020" .SH NAME -utimes, futimesat \- set file access and modification times +utimes, lutimes, futimes, futimesat, utimens, utimensat \- set file access and modification times .SH SYNOPSIS -.LP .nf #include \fBint\fR \fButimes\fR(\fBconst char *\fR\fIpath\fR, \fBconst struct timeval\fR \fItimes\fR[2]); .fi +.LP +.nf +\fBint\fR \fBlutimes\fR(\fBconst char *\fR\fIpath\fR, \fBconst struct timeval\fR \fItimes\fR[2]); +.fi + +.LP +.nf +\fBint\fR \fBfutimes\fR(\fBint\fR \fIfildes\fR, \fBconst struct timeval\fR \fItimes\fR[2]); +.fi + .LP .nf \fBint\fR \fBfutimesat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR, @@ -65,18 +75,27 @@ utimes, futimesat \- set file access and modification times .nf #include -\fBint\fR \fBfutimens\fR(\fBint\fR \fIfiledes\fR, \fBconst timespec_t\fR \fInstimes[2]\fR); +\fBint\fR \fBfutimens\fR(\fBint\fR \fIfildes\fR, \fBconst timespec_t\fR \fInstimes[2]\fR); -\fBint\fR \fButimensat\fR(\fBint\fR \fIfiledes\fR, \fBconst char *\fR\fIpath\fR, +\fBint\fR \fButimensat\fR(\fBint\fR \fIfildes\fR, \fBconst char *\fR\fIpath\fR, \fBconst timespec_t\fR \fInstimes[2]\fR, \fBint\fR \fIflag\fR); .SH DESCRIPTION -.LP The \fButimes()\fR function sets the access and modification times of the file pointed to by the \fIpath\fR argument to the value of the \fItimes\fR argument. It allows time specifications accurate to the microsecond. .sp .LP +The \fBlutimes()\fR function operates like \fButimes()\fR except if \fIpath\fR +points to a symbolic link; in that case \fBlutimes()\fR changes the access and +modifications times of the link, while \fButimes()\fR changes the file that +is referenced by the link. +.sp +.LP +The \fBfutimes()\fR function sets the access and modification times of the +file referenced by the file descriptor \fIfildes\fR. +.sp +.LP The \fBfutimesat()\fR function also sets access and modification times. See \fBfsattr\fR(5). If \fIpath\fR is a relative path name, however, \fBfutimesat()\fR resolves the path relative to the \fIfildes\fR argument @@ -84,7 +103,7 @@ rather than the current working directory. If \fIfildes\fR is set to \fBAT_FDCWD\fR, defined in <\fBfcntl.h\fR>, \fBfutimesat()\fR resolves the path relative to the current working directory. If \fIpath\fR is a null pointer, \fBfutimesat()\fR sets the access and modification times on the file referenced -by \fIfildes\fR. The \fIfildes\fR argument is ignored even when +by \fIfildes\fR. The \fIfildes\fR argument is ignored if \fBfutimesat()\fR is provided with an absolute path. .sp .LP @@ -107,28 +126,28 @@ The \fBfutimens()\fR and \fButimensat()\fR functions also set access and modification times; however, instead of taking \fBstruct timeval\fR, they take \fBtimespec_t\fR which allows for nanosecond granularity. The \fBfutimens()\fR function sets the access and modification times on the file descriptor -referenced by \fIfiledes\fR. +referenced by \fIfildes\fR. .sp .LP The \fButimensat()\fR function determines the file to set the access and -modification times in an similar way to \fBfutemsat()\fR. If the argument -\fIpath\fR is an absolute path, then the argument \fIfiledes\fR is ignored; +modification times in an similar way to \fBfutimesat()\fR. If the argument +\fIpath\fR is an absolute path, then the argument \fIfildes\fR is ignored; otherwise, \fIpath\fR is interpreted as a path relative to the directory -specified by \fIfiledes\fR. If \fIfiledes\fR is set to \fBAT_FDCWD\fR, then +specified by \fIfildes\fR. If \fIfildes\fR is set to \fBAT_FDCWD\fR, then \fIpath\fR is resolved relative to the current working directory. The behavior when encountering symbolic links may be controlled by the value of the \fIflag\fR argument. If the value of flag is the constant \fBAT_SYMLINK_NOFOLLOW\fR, then when a symbolic link is encountered while resolving a path, it will not be followed. Otherwise, the value of \fIflag\fR -should be \fB0\fR. +should be \fB0\fR. Note that, unlike \fBfutimesat()\fR, \fButimensat()\fR +does not accept a null pointer for the \fIpath\fR argument. .SH RETURN VALUES -.LP Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is returned, \fBerrno\fR is set to indicate the error, and the file times will not be affected. .SH ERRORS -.LP -The \fButimes()\fR, \fBfutimesat()\fR, \fBfutimens()\fR, and \fButimensat()\fR +The \fButimes()\fR, \fBlutimes()\fR, \fBfutimes()\fR, \fBfutimesat()\fR, +\fBfutimens()\fR, and \fButimensat()\fR functions will fail if: .sp .ne 2 @@ -147,9 +166,7 @@ process does not match the owner of the file and write access is denied. \fB\fBEFAULT\fR\fR .ad .RS 16n -The \fIpath\fR or \fItimes\fR argument points to an illegal address. For -\fBfutimesat()\fR, \fIpath\fR might have the value \fINULL\fR if the -\fIfildes\fR argument refers to a valid open file descriptor. +The \fIpath\fR or \fItimes\fR argument points to an illegal address. .RE .sp @@ -159,6 +176,7 @@ The \fIpath\fR or \fItimes\fR argument points to an illegal address. For .ad .RS 16n A signal was caught during the execution of the \fButimes()\fR, +\fBlutimes()\fR, \fBfutimes()\fR, \fBfutimesat()\fR, \fBfutimens()\fR, or \fButimensat()\fR functions. .RE @@ -270,7 +288,6 @@ length exceeds {\fIPATH_MAX\fR}. .RE .SH ATTRIBUTES -.LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -290,6 +307,5 @@ Standard See below. .LP For \fButimes()\fR, \fButimensat()\fR and \fBfutimensat()\fR, see \fBstandards\fR(5). .SH SEE ALSO -.LP -\fBfutimens\fR(2), \fBstat\fR(2), \fButime\fR(2), \fBattributes\fR(5), +fBstat\fR(2), \fButime\fR(2), \fBattributes\fR(5), \fBfsattr\fR(5), \fBstandards\fR(5) diff --git a/usr/src/man/man3head/Makefile b/usr/src/man/man3head/Makefile index fdc94ef4ef..8e1e75e6fb 100644 --- a/usr/src/man/man3head/Makefile +++ b/usr/src/man/man3head/Makefile @@ -13,6 +13,7 @@ # Copyright 2011, Richard Lowe # Copyright 2013 Nexenta Systems, Inc. All rights reserved. # Copyright 2014 Garrett D'Amore +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # include $(SRC)/Makefile.master @@ -93,6 +94,7 @@ MANFILES= acct.h.3head \ time.h.3head \ timeb.h.3head \ times.h.3head \ + timespec.3head \ types.h.3head \ types32.h.3head \ uchar.h.3head \ @@ -273,6 +275,9 @@ MANLINKS += acct.3head \ time.3head \ timeb.3head \ times.3head \ + timeval.3head \ + TIMEVAL_TO_TIMESPEC.3head \ + TIMESPEC_TO_TIMEVAL.3head \ types.3head \ types32.3head \ ucontext.3head \ @@ -451,6 +456,10 @@ tgmath.3head := LINKSRC = tgmath.h.3head time.3head := LINKSRC = time.h.3head timeb.3head := LINKSRC = timeb.h.3head times.3head := LINKSRC = times.h.3head +timespec.3head := LINKSRC = time.h.3head +timeval.3head := LINKSRC = timespec.3head +TIMEVAL_TO_TIMESPEC.3head := LINKSRC = timespec.3head +TIMESPEC_TO_TIMEVAL.3head := LINKSRC = timespec.3head types.3head := LINKSRC = types.h.3head types32.3head := LINKSRC = types32.h.3head ucontext.3head := LINKSRC = ucontext.h.3head diff --git a/usr/src/man/man3head/timespec.3head b/usr/src/man/man3head/timespec.3head new file mode 100644 index 0000000000..54aaab14f5 --- /dev/null +++ b/usr/src/man/man3head/timespec.3head @@ -0,0 +1,106 @@ +.\" +.\" This file and its contents are supplied under the terms of the +.\" Common Development and Distribution License ("CDDL"), version 1.0. +.\" You may only use this file in accordance with the terms of version +.\" 1.0 of the CDDL. +.\" +.\" A full copy of the text of the CDDL should have accompanied this +.\" source. A copy of the CDDL is also available via the Internet at +.\" http://www.illumos.org/license/CDDL. +.\" +.\" +.\" Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +.\" +.Dd Sep 06, 2020 +.Dt timespec 3HEAD +.Os +.Sh NAME +.Nm timespec , +.Nm timeval , +.Nm TIMESPEC_TO_TIMEVAL , +.Nm TIMEVAL_TO_TIMESPEC +.Nd time structures and conversion +.Sh SYNOPSIS +.In sys/time.h +.Ft void +.Fo TIMESPEC_TO_TIMEVAL +.Fa "struct timeval *tv" +.Fa "const struct timespec *ts" +.Fc +.Ft void +.Fo TIMEVAL_TO_TIMESPEC +.Fa "const struct timeval *tv" +.Fa "struct timespec *ts" +.Fc +.Sh DESCRIPTION +The +.Vt timeval +and +.Vt timespec +structures are declared in the +.In time.h +and +.In sys/time.h +headers respectively: +.Bd -literal -offset indent +typedef struct timespec { + time_t tv_sec; /* seconds */ + long tv_nsec; /* and nanoseconds */ +} timespec_t; + +struct timeval { + time_t tv_sec; /* seconds */ + suseconds_t tv_usec; /* and microseconds */ +}; +.Ed +.Pp +In both cases, the +.Fa tv_sec +member represents elapsed time in whole seconds. +The +.Fa tv_nsec +and +.Fa tv_usec +members represent the rest of the elapsed time in nanoseconds and +microseconds respectively, depending on the structure. +.Pp +The +.Dv TIMEVAL_TO_TIMESPEC +macro can be used to convert a +.Vt struct timeval +structure to a +.Vt struct timespec +structure, while the +.Dv TIMESPEC_TO_TIMEVAL +macro works in the opposite direction. +.Pp +When converting from a +.Vt struct timespec +to a +.Vt struct timeval +structure, the +.Fa tv_nsec +member is truncated, losing precision. +When converting from a +.Vt struct timeval +to a +.Vt struct timespec +structure, the +.Fa tv_usec +member is multiplied by 1000 to reach the precision of the target +structure. +The +.Fa tv_sec +member is always preserved, no matter which conversion is performed. +.Pp +Note that the +.Dv TIMEVAL_TO_TIMESPEC +and +.Dv TIMESPEC_TO_TIMEVAL +macros are non-standard but are commonly found on UNIX and UNIX-like systems. +.Sh INTERFACE STABILITY +.Sy Committed +.Sh MT-LEVEL +.Sy MT-Safe +.Sh SEE ALSO +.Xr time.h 3HEAD diff --git a/usr/src/man/man3lib/libc.3lib b/usr/src/man/man3lib/libc.3lib index 83df10408b..9bdf613acf 100644 --- a/usr/src/man/man3lib/libc.3lib +++ b/usr/src/man/man3lib/libc.3lib @@ -7,7 +7,7 @@ .\" See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .\" Copyright 2011 by Delphix. All rights reserved. -.TH LIBC 3LIB "Feb 14, 2020" +.TH LIBC 3LIB "Sep 06, 2020" .SH NAME libc \- C library .SH DESCRIPTION @@ -261,130 +261,131 @@ l l . \fBftok\fR \fBftruncate\fR \fBftrylockfile\fR \fBftw\fR \fBfunc_to_decimal\fR \fBfunlockfile\fR -\fBfutimens\fR \fBfutimesat\fR -\fBfwide\fR \fBfwprintf\fR -\fBfwrite\fR \fBfwscanf\fR -\fBgconvert\fR \fBgcvt\fR -\fBgetacct\fR \fBgetattrat\fR -\fBgetc\fR \fBgetc_unlocked\fR -\fBgetchar\fR \fBgetchar_unlocked\fR -\fBgetcontext\fR \fBgetcpuid\fR -\fBgetcwd\fR \fBgetdate\fR -\fBgetdate_err\fR \fBgetdents\fR -\fBgetdtablesize\fR \fBgetegid\fR -\fBgetenv\fR \fBgeteuid\fR -\fBgetexecname\fR \fBgetextmntent\fR -\fBgetgid\fR \fBgetgrent\fR -\fBgetgrent_r\fR \fBgetgrgid\fR -\fBgetgrgid_r\fR \fBgetgrnam\fR -\fBgetgrnam_r\fR \fBgetgroups\fR -\fBgethomelgroup\fR \fBgethostid\fR -\fBgethostname\fR \fBgethrtime\fR -\fBgethrvtime\fR \fBgetisax\fR -\fBgetitimer\fR \fBgetloadavg\fR -\fBgetlogin\fR \fBgetlogin_r\fR -\fBgetmntany\fR \fBgetmntent\fR -\fBgetmsg\fR \fBget_nprocs\fR -\fBget_nprocs_conf\fR \fBgetnetgrent\fR -\fBgetnetgrent_r\fR \fBgetopt\fR -\fBgetopt_clip\fR \fBgetopt_long\fR -\fBgetopt_long_only\fR \fBgetpagesize\fR -\fBgetpagesizes\fR \fBgetpass\fR -\fBgetpassphrase\fR \fBgetpeerucred\fR -\fBgetpflags\fR \fBgetpgid\fR -\fBgetpgrp\fR \fBgetpid\fR -\fBgetpmsg\fR \fBgetppid\fR -\fBgetppriv\fR \fBgetpriority\fR -\fBgetprogname\fR \fBgetprojid\fR -\fBgetpw\fR \fBgetpwent\fR -\fBgetpwent_r\fR \fBgetpwnam\fR -\fBgetpwnam_r\fR \fBgetpwuid\fR -\fBgetpwuid_r\fR \fBgetrctl\fR -\fBgetrlimit\fR \fBgetrusage\fR -\fBgets\fR \fBgetsid\fR -\fBgetspent\fR \fBgetspent_r\fR -\fBgetspnam\fR \fBgetspnam_r\fR -\fBgetsubopt\fR \fBgettaskid\fR -\fBgettext\fR \fBgettimeofday\fR -\fBgettxt\fR \fBgetuid\fR -\fBgetusershell\fR \fBgetustack\fR -\fBgetutent\fR \fBgetutid\fR -\fBgetutline\fR \fBgetutmp\fR -\fBgetutmpx\fR \fBgetutxent\fR -\fBgetutxid\fR \fBgetutxline\fR -\fBgetvfsany\fR \fBgetvfsent\fR -\fBgetvfsfile\fR \fBgetvfsspec\fR -\fBgetw\fR \fBgetwc\fR -\fBgetwc_l\fR \fBgetwchar\fR -\fBgetwchar_l\fR \fBgetwd\fR -\fBgetwidth\fR \fBgetws\fR -\fBgetzoneid\fR \fBgetzoneidbyname\fR -\fBgetzonenamebyid\fR \fBglob\fR -\fBglobfree\fR \fBgmtime\fR -\fBgmtime_r\fR \fBgrantpt\fR -\fBgsignal\fR \fBhasmntopt\fR -\fBhcreate\fR \fBhdestroy\fR -\fBhsearch\fR \fBiconv\fR -\fBiconv_close\fR \fBiconv_open\fR -\fBimaxabs\fR \fBimaxdiv\fR -\fBindex\fR \fBinitgroups\fR -\fBinitstate\fR \fBinnetgr\fR -\fBinsque\fR \fBioctl\fR -\fBis_system_labeled\fR \fBisaexec\fR -\fBisalnum\fR \fBisalnum_l\fR -\fBisalpha\fR \fBisalpha_l\fR -\fBisascii\fR \fBisastream\fR -\fBisatty\fR \fBisblank\fR -\fBisblank_l\fR \fBiscntrl\fR -\fBiscntrl_l\fR \fBisdigit\fR -\fBisdigit_l\fR \fBisenglish\fR -\fBisgraph\fR \fBisgraph_l\fR -\fBisideogram\fR \fBislower\fR -\fBislower_l\fR \fBisnan\fR -\fBisnand\fR \fBisnanf\fR -\fBisnumber\fR \fBisphonogram\fR -\fBisprint\fR \fBisprint_l\fR -\fBispunct\fR \fBispunct_l\fR -\fBissetugid\fR \fBisspace\fR -\fBisspace_l\fR \fBisspecial\fR -\fBisupper\fR \fBisupper_l\fR -\fBiswalnum\fR \fBiswalnum_l\fR -\fBiswalpha\fR \fBiswalpha_l\fR -\fBiswblank\fR \fBiswblank_l\fR -\fBiswcntrl\fR \fBiswcntrl_l\fR -\fBiswctype\fR \fBiswctype_l\fR -\fBiswdigit\fR \fBiswdigit_l\fR -\fBiswideogram\fR \fBiswideogram_l\fR -\fBiswgraph\fR \fBiswgraph_l\fR -\fBiswhexnumber\fR \fBiswhexnumber_l\fR -\fBiswlower\fR \fBiswlower_l\fR -\fBiswnumber\fR \fBiswnumber_l\fR -\fBiswphonogram\fR \fBiswphonogram_l\fR -\fBiswprint\fR \fBiswprint_l\fR -\fBiswpunct\fR \fBiswpunct_l\fR -\fBiswspace\fR \fBiswspace_l\fR -\fBiswspecial\fR \fBiswspecial_l\fR -\fBiswupper\fR \fBiswupper_l\fR -\fBiswxdigit\fR \fBiswxdigit_l\fR -\fBisxdigit\fR \fBisxdigit_l\fR -\fBjrand48\fR \fBkill\fR -\fBkillpg\fR \fBl64a\fR -\fBlabs\fR \fBladd\fR -\fBlchown\fR \fBlckpwdf\fR -\fBlcong48\fR \fBldexp\fR -\fBldivide\fR \fBlexp10\fR -\fBlfind\fR \fBlfmt\fR -\fBlink\fR \fBlinkat\fR -\fBlio_listio\fR \fBllabs\fR -\fBlldiv\fR \fBllog10\fR -\fBllseek\fR \fBlltostr\fR -\fBlocaleconv\fR \fBlocaltime\fR -\fBlocaltime_r\fR \fBlockf\fR -\fBlogb\fR \fBlone\fR -\fBlongjmp\fR \fBlrand48\fR -\fBlsearch\fR \fBlseek\fR -\fBlshiftl\fR \fBlstat\fR -\fBlsub\fR \fBlten\fR +\fBfutimens\fR \fBfutimes\fR +\fBfutimesat\fR \fBfwide\fR +\fBfwprintf\fR \fBfwrite\fR +\fBfwscanf\fR \fBgconvert\fR +\fBgcvt\fR \fBgetacct\fR +\fBgetattrat\fR \fBgetc\fR +\fBgetc_unlocked\fR \fBgetchar\fR +\fBgetchar_unlocked\fR \fBgetcontext\fR +\fBgetcpuid\fR \fBgetcwd\fR +\fBgetdate\fR \fBgetdate_err\fR +\fBgetdents\fR \fBgetdtablesize\fR +\fBgetegid\fR \fBgetenv\fR +\fBgeteuid\fR \fBgetexecname\fR +\fBgetextmntent\fR \fBgetgid\fR +\fBgetgrent\fR \fBgetgrent_r\fR +\fBgetgrgid\fR \fBgetgrgid_r\fR +\fBgetgrnam\fR \fBgetgrnam_r\fR +\fBgetgroups\fR \fBgethomelgroup\fR +\fBgethostid\fR \fBgethostname\fR +\fBgethrtime\fR \fBgethrvtime\fR +\fBgetisax\fR \fBgetitimer\fR +\fBgetloadavg\fR \fBgetlogin\fR +\fBgetlogin_r\fR \fBgetmntany\fR +\fBgetmntent\fR \fBgetmsg\fR +\fBget_nprocs\fR \fBget_nprocs_conf\fR +\fBgetnetgrent\fR \fBgetnetgrent_r\fR +\fBgetopt\fR \fBgetopt_clip\fR +\fBgetopt_long\fR \fBgetopt_long_only\fR +\fBgetpagesize\fR \fBgetpagesizes\fR +\fBgetpass\fR \fBgetpassphrase\fR +\fBgetpeerucred\fR \fBgetpflags\fR +\fBgetpgid\fR \fBgetpgrp\fR +\fBgetpid\fR \fBgetpmsg\fR +\fBgetppid\fR \fBgetppriv\fR +\fBgetpriority\fR \fBgetprogname\fR +\fBgetprojid\fR \fBgetpw\fR +\fBgetpwent\fR \fBgetpwent_r\fR +\fBgetpwnam\fR \fBgetpwnam_r\fR +\fBgetpwuid\fR \fBgetpwuid_r\fR +\fBgetrctl\fR \fBgetrlimit\fR +\fBgetrusage\fR \fBgets\fR +\fBgetsid\fR \fBgetspent\fR +\fBgetspent_r\fR \fBgetspnam\fR +\fBgetspnam_r\fR \fBgetsubopt\fR +\fBgettaskid\fR \fBgettext\fR +\fBgettimeofday\fR \fBgettxt\fR +\fBgetuid\fR \fBgetusershell\fR +\fBgetustack\fR \fBgetutent\fR +\fBgetutid\fR \fBgetutline\fR +\fBgetutmp\fR \fBgetutmpx\fR +\fBgetutxent\fR \fBgetutxid\fR +\fBgetutxline\fR \fBgetvfsany\fR +\fBgetvfsent\fR \fBgetvfsfile\fR +\fBgetvfsspec\fR \fBgetw\fR +\fBgetwc\fR \fBgetwc_l\fR +\fBgetwchar\fR \fBgetwchar_l\fR +\fBgetwd\fR \fBgetwidth\fR +\fBgetws\fR \fBgetzoneid\fR +\fBgetzoneidbyname\fR \fBgetzonenamebyid\fR +\fBglob\fR \fBglobfree\fR +\fBgmtime\fR \fBgmtime_r\fR +\fBgrantpt\fR \fBgsignal\fR +\fBhasmntopt\fR \fBhcreate\fR +\fBhdestroy\fR \fBhsearch\fR +\fBiconv\fR \fBiconv_close\fR +\fBiconv_open\fR \fBimaxabs\fR +\fBimaxdiv\fR \fBindex\fR +\fBinitgroups\fR \fBinitstate\fR +\fBinnetgr\fR \fBinsque\fR +\fBioctl\fR \fBis_system_labeled\fR +\fBisaexec\fR \fBisalnum\fR +\fBisalnum_l\fR \fBisalpha\fR +\fBisalpha_l\fR \fBisascii\fR +\fBisastream\fR \fBisatty\fR +\fBisblank\fR \fBisblank_l\fR +\fBiscntrl\fR \fBiscntrl_l\fR +\fBisdigit\fR \fBisdigit_l\fR +\fBisenglish\fR \fBisgraph\fR +\fBisgraph_l\fR \fBisideogram\fR +\fBislower\fR \fBislower_l\fR +\fBisnan\fR \fBisnand\fR +\fBisnanf\fR \fBisnumber\fR +\fBisphonogram\fR \fBisprint\fR +\fBisprint_l\fR \fBispunct\fR +\fBispunct_l\fR \fBissetugid\fR +\fBisspace\fR \fBisspace_l\fR +\fBisspecial\fR \fBisupper\fR +\fBisupper_l\fR \fBiswalnum\fR +\fBiswalnum_l\fR \fBiswalpha\fR +\fBiswalpha_l\fR \fBiswblank\fR +\fBiswblank_l\fR \fBiswcntrl\fR +\fBiswcntrl_l\fR \fBiswctype\fR +\fBiswctype_l\fR \fBiswdigit\fR +\fBiswdigit_l\fR \fBiswideogram\fR +\fBiswideogram_l\fR \fBiswgraph\fR +\fBiswgraph_l\fR \fBiswhexnumber\fR +\fBiswhexnumber_l\fR \fBiswlower\fR +\fBiswlower_l\fR \fBiswnumber\fR +\fBiswnumber_l\fR \fBiswphonogram\fR +\fBiswphonogram_l\fR \fBiswprint\fR +\fBiswprint_l\fR \fBiswpunct\fR +\fBiswpunct_l\fR \fBiswspace\fR +\fBiswspace_l\fR \fBiswspecial\fR +\fBiswspecial_l\fR \fBiswupper\fR +\fBiswupper_l\fR \fBiswxdigit\fR +\fBiswxdigit_l\fR \fBisxdigit\fR +\fBisxdigit_l\fR \fBjrand48\fR +\fBkill\fR \fBkillpg\fR +\fBl64a\fR \fBlabs\fR +\fBladd\fR \fBlchown\fR +\fBlckpwdf\fR \fBlcong48\fR +\fBldexp\fR \fBldivide\fR +\fBlexp10\fR \fBlfind\fR +\fBlfmt\fR \fBlink\fR +\fBlinkat\fR \fBlio_listio\fR +\fBllabs\fR \fBlldiv\fR +\fBllog10\fR \fBllseek\fR +\fBlltostr\fR \fBlocaleconv\fR +\fBlocaltime\fR \fBlocaltime_r\fR +\fBlockf\fR \fBlogb\fR +\fBlone\fR \fBlongjmp\fR +\fBlrand48\fR \fBlsearch\fR +\fBlseek\fR \fBlshiftl\fR +\fBlstat\fR \fBlsub\fR +\fBlten\fR \fBlutimes\fR \fBlzero\fR \fBmadvise\fR \fBmakecontext\fR \fBmakeutx\fR \fBmalloc\fR \fBmblen\fR diff --git a/usr/src/pkg/manifests/system-header.mf b/usr/src/pkg/manifests/system-header.mf index 8a5436aba7..d9d94487f0 100644 --- a/usr/src/pkg/manifests/system-header.mf +++ b/usr/src/pkg/manifests/system-header.mf @@ -28,6 +28,7 @@ # Copyright 2016 Hans Rosenfeld # Copyright 2020 Joyent, Inc. # Copyright 2019 Peter Tribble. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # set name=pkg.fmri value=pkg:/system/header@$(PKGVERS) @@ -1909,6 +1910,7 @@ file path=usr/share/man/man3head/tgmath.h.3head file path=usr/share/man/man3head/time.h.3head file path=usr/share/man/man3head/timeb.h.3head file path=usr/share/man/man3head/times.h.3head +file path=usr/share/man/man3head/timespec.3head file path=usr/share/man/man3head/types.h.3head file path=usr/share/man/man3head/types32.h.3head file path=usr/share/man/man3head/uchar.h.3head @@ -2113,6 +2115,10 @@ link path=usr/share/man/man3head/TAILQ_NEXT.3head target=queue.h.3head link path=usr/share/man/man3head/TAILQ_PREV.3head target=queue.h.3head link path=usr/share/man/man3head/TAILQ_REMOVE.3head target=queue.h.3head link path=usr/share/man/man3head/TAILQ_SWAP.3head target=queue.h.3head +link path=usr/share/man/man3head/TIMESPEC_TO_TIMEVAL.3head \ + target=timespec.3head +link path=usr/share/man/man3head/TIMEVAL_TO_TIMESPEC.3head \ + target=timespec.3head link path=usr/share/man/man3head/acct.3head target=acct.h.3head link path=usr/share/man/man3head/aio.3head target=aio.h.3head link path=usr/share/man/man3head/ar.3head target=ar.h.3head @@ -2186,6 +2192,7 @@ link path=usr/share/man/man3head/tgmath.3head target=tgmath.h.3head link path=usr/share/man/man3head/time.3head target=time.h.3head link path=usr/share/man/man3head/timeb.3head target=timeb.h.3head link path=usr/share/man/man3head/times.3head target=times.h.3head +link path=usr/share/man/man3head/timeval.3head target=timespec.3head link path=usr/share/man/man3head/types.3head target=types.h.3head link path=usr/share/man/man3head/types32.3head target=types32.h.3head link path=usr/share/man/man3head/ucontext.3head target=ucontext.h.3head diff --git a/usr/src/pkg/manifests/system-kernel.man2.inc b/usr/src/pkg/manifests/system-kernel.man2.inc index e5e1ace483..6a45a39b55 100644 --- a/usr/src/pkg/manifests/system-kernel.man2.inc +++ b/usr/src/pkg/manifests/system-kernel.man2.inc @@ -15,6 +15,7 @@ # Copyright 2013, OmniTI Computer Consulting, Inc. # Copyright 2017 Peter Tribble # Copyright 2018, Joyent, Inc. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # file path=usr/share/man/man2/Intro.2 @@ -192,6 +193,7 @@ link path=usr/share/man/man2/fstat.2 target=stat.2 link path=usr/share/man/man2/fstatat.2 target=stat.2 link path=usr/share/man/man2/fstatvfs.2 target=statvfs.2 link path=usr/share/man/man2/futimens.2 target=utimes.2 +link path=usr/share/man/man2/futimes.2 target=utimes.2 link path=usr/share/man/man2/futimesat.2 target=utimes.2 link path=usr/share/man/man2/getaudit_addr.2 target=getaudit.2 link path=usr/share/man/man2/getegid.2 target=getuid.2 @@ -205,9 +207,10 @@ link path=usr/share/man/man2/getprojid.2 target=settaskid.2 link path=usr/share/man/man2/getrctl.2 target=setrctl.2 link path=usr/share/man/man2/gettaskid.2 target=settaskid.2 link path=usr/share/man/man2/intro.2 target=Intro.2 -link path=usr/share/man/man2/linkat.2 target=link.2 link path=usr/share/man/man2/lchown.2 target=chown.2 +link path=usr/share/man/man2/linkat.2 target=link.2 link path=usr/share/man/man2/lstat.2 target=stat.2 +link path=usr/share/man/man2/lutimes.2 target=utimes.2 link path=usr/share/man/man2/mkdirat.2 target=mkdir.2 link path=usr/share/man/man2/mknodat.2 target=mknod.2 link path=usr/share/man/man2/openat.2 target=open.2 diff --git a/usr/src/pkg/manifests/system-test-libctest.mf b/usr/src/pkg/manifests/system-test-libctest.mf index 659006a358..3145beeadc 100644 --- a/usr/src/pkg/manifests/system-test-libctest.mf +++ b/usr/src/pkg/manifests/system-test-libctest.mf @@ -14,6 +14,7 @@ # Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved. # Copyright 2015 Garrett D'Amore # Copyright 2018 Joyent, Inc. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # set name=pkg.fmri value=pkg:/system/test/libctest@$(PKGVERS) @@ -189,6 +190,8 @@ file path=opt/libc-tests/tests/timespec_get.32 mode=0555 file path=opt/libc-tests/tests/timespec_get.64 mode=0555 file path=opt/libc-tests/tests/uchar.32 mode=0555 file path=opt/libc-tests/tests/uchar.64 mode=0555 +file path=opt/libc-tests/tests/utimes.32 mode=0555 +file path=opt/libc-tests/tests/utimes.64 mode=0555 file path=opt/libc-tests/tests/wcsncasecmp-7344.32 mode=0555 file path=opt/libc-tests/tests/wcsncasecmp-7344.64 mode=0555 file path=opt/libc-tests/tests/wcsncasecmp-7350.32 mode=0555 diff --git a/usr/src/prototypes/prototype.man3x b/usr/src/prototypes/prototype.man3x index 598315f959..3604b4a0e2 100644 --- a/usr/src/prototypes/prototype.man3x +++ b/usr/src/prototypes/prototype.man3x @@ -59,7 +59,7 @@ A Reason why ERRNO1 could occur. A Reason why ERRNO2 could occur. .El .Sh INTERFACE STABILITY -.\" Indicate the stability per attribute(5). One of: +.\" Indicate the stability per attributes(5). One of: .\" .Sy Committed .\" .Sy Uncommitted .\" .Sy Volatile diff --git a/usr/src/test/libc-tests/cfg/symbols/sys_time_h.cfg b/usr/src/test/libc-tests/cfg/symbols/sys_time_h.cfg index afed10a6bb..8ca9bacb9d 100644 --- a/usr/src/test/libc-tests/cfg/symbols/sys_time_h.cfg +++ b/usr/src/test/libc-tests/cfg/symbols/sys_time_h.cfg @@ -11,6 +11,7 @@ # # Copyright 2015 Garrett D'Amore +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # # @@ -40,3 +41,16 @@ func | utimes |\ int |\ const char *; const struct timeval [2] |\ sys/time.h | -POSIX+ -XPG3+ SUS+ + +func | lutimes |\ + int |\ + const char *; const struct timeval [2] |\ + sys/time.h | -ALL + +func | futimes |\ + int |\ + int; const struct timeval [2] |\ + sys/time.h | -ALL + +define | TIMEVAL_TO_TIMESPEC | | sys/time.h | -ALL +define | TIMESPEC_TO_TIMEVAL | | sys/time.h | -ALL diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index 0ad4526774..bada7ea85b 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -13,6 +13,7 @@ # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2014 Garrett D'Amore # Copyright 2019 Joyent, Inc. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # [DEFAULT] @@ -124,6 +125,8 @@ timeout = 600 [/opt/libc-tests/tests/timespec_get.64] [/opt/libc-tests/tests/uchar.32] [/opt/libc-tests/tests/uchar.64] +[/opt/libc-tests/tests/utimes.32] +[/opt/libc-tests/tests/utimes.64] # # root privs required for priority changes diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index 0b460ff2f2..54a9a23572 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -13,6 +13,7 @@ # Copyright (c) 2012 by Delphix. All rights reserved. # Copyright 2015 Garrett D'Amore # Copyright 2019 Joyent, Inc. +# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. # SUBDIRS = \ @@ -52,7 +53,8 @@ PROGS = \ wcsncasecmp \ wcsncasecmp-7344 \ wcsncasecmp-7350 \ - uchar + uchar \ + utimes SCRIPTS = \ quick_exit \ diff --git a/usr/src/test/libc-tests/tests/utimes.c b/usr/src/test/libc-tests/tests/utimes.c new file mode 100644 index 0000000000..7585289fe6 --- /dev/null +++ b/usr/src/test/libc-tests/tests/utimes.c @@ -0,0 +1,521 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. + */ + +/* + * Test the implementation of the various *utimes() and *utimens() functions + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +timespec_t testtimes[] = { + { + .tv_sec = 1280793678, + .tv_nsec = 123456789 + }, + { + .tv_sec = 1492732800, + .tv_nsec = 17 + }, + { + .tv_sec = 1320796855, + .tv_nsec = 9 + }, + { + .tv_sec = 1498953611, + .tv_nsec = 987654321 + } +}; + +enum ttype { + UTIMES, + LUTIMES, + FUTIMES, + FUTIMESAT, + FUTIMENS, + UTIMENSAT +}; + +static bool +compare_times(struct stat *st, bool trunc, timespec_t *atim, timespec_t *mtim, + bool invert) +{ + bool ret = true; + + if (st->st_atim.tv_sec != atim->tv_sec) { + ret = false; + } else if (st->st_atim.tv_nsec != ( + trunc ? atim->tv_nsec / 1000 * 1000 : atim->tv_nsec)) { + ret = false; + } else if (st->st_mtim.tv_sec != mtim->tv_sec) { + ret = false; + } else if (st->st_mtim.tv_nsec != ( + trunc ? mtim->tv_nsec / 1000 * 1000 : mtim->tv_nsec)) { + ret = false; + } + + if ((!ret && !invert) || (ret && invert)) { + printf(" actual atime: %ld.%.9ld\n", + st->st_atim.tv_sec, st->st_atim.tv_nsec); + printf(" actual mtime: %ld.%.9ld\n", + st->st_mtim.tv_sec, st->st_mtim.tv_nsec); + } + + return (ret); +} + +static bool +compare_filetime(char *path, bool trunc, timespec_t *atim, timespec_t *mtim, + bool invert) +{ + struct stat st; + + if (stat(path, &st) == -1) + err(EXIT_FAILURE, "stat %s", path); + + return (compare_times(&st, trunc, atim, mtim, invert)); +} + +static bool +compare_linktime(char *path, bool trunc, timespec_t *atim, timespec_t *mtim, + bool invert) +{ + struct stat st; + + if (lstat(path, &st) == -1) + err(EXIT_FAILURE, "lstat %s", path); + + return (compare_times(&st, trunc, atim, mtim, invert)); +} + +static bool +reset(char *path, timespec_t *atim, timespec_t *mtim) +{ + if (utimes(path, NULL) == -1) + err(EXIT_FAILURE, "utimes reset"); + if (compare_filetime(path, true, atim, mtim, true)) { + warnx("reset failed"); + return (false); + } + return (true); +} + +static bool +reset_link(char *lpath, timespec_t *atim, timespec_t *mtim) +{ + if (lutimes(lpath, NULL) == -1) + err(EXIT_FAILURE, "lutimes reset"); + if (compare_linktime(lpath, true, atim, mtim, true)) { + warnx("link reset failed"); + return (false); + } + return (true); +} + +static bool +runtest(enum ttype fn, char *dir, timespec_t *atim, timespec_t *mtim) +{ + char path[MAXPATHLEN + 1]; + char lpath[MAXPATHLEN + 1]; + struct timespec ts[2]; + struct timeval tv[2]; + int fd, lfd, dfd, ret = true; + + ts[0] = *atim; + ts[1] = *mtim; + TIMESPEC_TO_TIMEVAL(&tv[0], &ts[0]); + TIMESPEC_TO_TIMEVAL(&tv[1], &ts[1]); + + if (snprintf(path, sizeof (path), "%s/file", dir) >= sizeof (path)) + err(EXIT_FAILURE, "snprintf failed to build file path"); + + if ((fd = open(path, O_CREAT, 0644)) == -1) + err(EXIT_FAILURE, "open file %s", path); + + if (snprintf(lpath, sizeof (lpath), "%s/link", dir) >= sizeof (path)) + err(EXIT_FAILURE, "snprintf failed to build link path"); + + if (symlink(path, lpath) == -1) + err(EXIT_FAILURE, "link(%s)", lpath); + + if ((lfd = open(lpath, O_RDWR)) == -1) + err(EXIT_FAILURE, "open link(%s)", lpath); + + if ((dfd = open(dir, O_DIRECTORY|O_RDONLY)) == -1) + err(EXIT_FAILURE, "open dir(%s)", dir); + + switch (fn) { + case UTIMES: + printf("..... utimes()\n"); + + if (utimes(path, tv) == -1) + err(EXIT_FAILURE, "utimes(%s)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed on file"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (utimes(lpath, tv) == -1) + err(EXIT_FAILURE, "utimes(%s), link", lpath); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed on file through link"); + ret = false; + } + + break; + + case LUTIMES: + printf("..... lutimes()\n"); + + /* Use lutimes() against a plain file */ + if (lutimes(path, tv) == -1) + err(EXIT_FAILURE, "lutimes(%s)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed on file"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* Set the time on the link, not on the target */ + if (lutimes(lpath, tv) == -1) + err(EXIT_FAILURE, "lutimes(%s)", lpath); + if (!compare_linktime(lpath, true, atim, mtim, false)) { + warnx("link time is incorrect"); + ret = false; + } + if (compare_filetime(path, true, atim, mtim, true)) { + warnx("target time was updated incorrectly"); + ret = false; + } + + /* Reset the time on the path and link to the current time */ + if (!reset(path, atim, mtim) || !reset_link(lpath, atim, mtim)) + ret = false; + + /* and modify the target */ + if (utimes(path, tv) == -1) + err(EXIT_FAILURE, "utimes(%s)", path); + /* Now the target should match but the link should not */ + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("target time is incorrect"); + ret = false; + } + if (compare_linktime(lpath, true, atim, mtim, true)) { + warnx("link time was updated incorrectly"); + ret = false; + } + break; + + case FUTIMES: + printf("..... futimes()\n"); + + if (futimes(fd, tv) == -1) + err(EXIT_FAILURE, "futimes(%s)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed on file"); + ret = false; + } + + break; + + case FUTIMESAT: { + int rfd; + printf("..... futimesat()\n"); + + /* NULL path, should modify the file for 'fd' */ + if (futimesat(fd, NULL, tv) == -1) + err(EXIT_FAILURE, "futimesat(fd, NULL)"); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed with null path"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* random descriptor, FQ path, descriptor is ignored */ + if ((rfd = open("/dev/null", O_RDONLY)) == -1) + err(EXIT_FAILURE, "open(/dev/null)"); + if (futimesat(rfd, path, tv) == -1) + err(EXIT_FAILURE, "futimesat(dnfd, %s)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed with random descriptor and fq path"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (futimesat(rfd, lpath, tv) == -1) + err(EXIT_FAILURE, "futimesat(dnfd, %s), link", lpath); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed through link with " + "random descriptor, fq path"); + ret = false; + } + + (void) close(rfd); + + if (!reset(path, atim, mtim)) + ret = false; + + /* relative to a directory */ + if (futimesat(dfd, "file", tv) == -1) + err(EXIT_FAILURE, "futimesat(dir, file)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed relative to a directory"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (futimesat(dfd, "link", tv) == -1) + err(EXIT_FAILURE, "futimesat(dir, link)"); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed through link relative to a directory"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* AT_FDCWD */ + if (fchdir(dfd) == -1) + err(EXIT_FAILURE, "fchdir(%s)", dir); + if (futimesat(AT_FDCWD, "file", tv) == -1) + err(EXIT_FAILURE, "futimesat(AT_FDCWD, file)", path); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed with AT_FDCWD relative"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (futimesat(AT_FDCWD, "link", tv) == -1) + err(EXIT_FAILURE, "futimesat(AT_FDCWD, link)"); + if (!compare_filetime(path, true, atim, mtim, false)) { + warnx("failed through link with AT_FDCWD relative"); + ret = false; + } + + break; + } + + case FUTIMENS: + printf("..... futimens()\n"); + if (futimens(fd, ts) == -1) + err(EXIT_FAILURE, "futimesns(%s)", path); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed with plain file fd"); + ret = false; + } + + break; + + case UTIMENSAT: { + int rfd; + + printf("..... utimensat()\n"); + + /* NULL path, expect EFAULT (cf. futimesat()) */ + if (utimensat(fd, NULL, ts, 0) != -1 || errno != EFAULT) { + warnx("null path should return EFAULT but got %d/%s", + errno, strerror(errno)); + ret = false; + } + + /* random descriptor, FQ path, descriptor is ignored */ + if ((rfd = open("/dev/null", O_RDONLY)) == -1) + err(EXIT_FAILURE, "open(/dev/null)"); + if (utimensat(rfd, path, ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(dnfd, %s)", path); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed with random descriptor, fq path"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (utimensat(rfd, lpath, ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(dnfd, link %s)", lpath); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed against link with random descriptor, " + "fq path"); + ret = false; + } + + (void) close(rfd); + + if (!reset(path, atim, mtim)) + ret = false; + + /* relative to a directory */ + if (utimensat(dfd, "file", ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(dir, file)", path); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed relative to a directory"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (utimensat(dfd, "link", ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(dir, link)", path); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed through link relative to a directory"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* AT_FDCWD */ + if (fchdir(dfd) == -1) + err(EXIT_FAILURE, "fchdir(%s)", dir); + if (utimensat(AT_FDCWD, "file", ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(AT_FDCWD, file)"); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed with AT_FDCWD relative"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* repeat against symbolic link path */ + if (utimensat(AT_FDCWD, "link", ts, 0) == -1) + err(EXIT_FAILURE, "utimensat(AT_FDCWD, link)"); + if (!compare_filetime(path, false, atim, mtim, false)) { + warnx("failed through link with AT_FDCWD relative"); + ret = false; + } + + if (!reset(path, atim, mtim)) + ret = false; + + /* + * Check that none of the above operations have changed the + * timestamp on the link. + */ + if (compare_linktime(lpath, true, atim, mtim, true)) { + warnx("link timestamp was unexpectedly modified"); + ret = false; + } + + /* Set the time on the link, not on the target */ + if (utimensat(AT_FDCWD, "link", ts, AT_SYMLINK_NOFOLLOW) == -1) + err(EXIT_FAILURE, "utimensat(AT_FDCWD, lflag)"); + if (!compare_linktime(lpath, false, atim, mtim, false)) { + warnx("link time is incorrect"); + ret = false; + } + if (compare_filetime(path, false, atim, mtim, true)) { + warnx("target time was updated incorrectly"); + ret = false; + } + } + break; + } + + (void) close(dfd); + (void) close(lfd); + (void) close(fd); + + if (unlink(lpath) == -1) + err(EXIT_FAILURE, "unlink(%s)", lpath); + if (unlink(path) == -1) + err(EXIT_FAILURE, "unlink(%s)", path); + + if (!ret) + warnx("Test failed"); + + return (ret); +} + +static bool +runtests(char *dir, timespec_t *atim, timespec_t *mtim) +{ + bool ret = true; + + printf("Testing:\n... atime: %ld.%.9ld\n... mtime: %ld.%.9ld\n", + atim->tv_sec, atim->tv_nsec, mtim->tv_sec, mtim->tv_nsec); + + if (!runtest(UTIMES, dir, atim, mtim)) + ret = false; + if (!runtest(LUTIMES, dir, atim, mtim)) + ret = false; + if (!runtest(FUTIMES, dir, atim, mtim)) + ret = false; + if (!runtest(FUTIMESAT, dir, atim, mtim)) + ret = false; + if (!runtest(FUTIMENS, dir, atim, mtim)) + ret = false; + if (!runtest(UTIMENSAT, dir, atim, mtim)) + ret = false; + + return (ret); +} + +int +main(void) +{ + char dir[] = "/tmp/utimes.XXXXXX"; + int ret = EXIT_SUCCESS; + int i; + + if (mkdtemp(dir) == NULL) + err(EXIT_FAILURE, "failed to create temporary directory"); + + for (i = 0; i < ARRAY_SIZE(testtimes); i += 2) { + if (!runtests(dir, &testtimes[i], &testtimes[i + 1])) + ret = EXIT_FAILURE; + } + + /* + * Some tests will have changed directory into 'dir' to test the + * AT_FDCWD case. Change back to / to avoid EBUSY when removing dir. + */ + if (chdir("/") == -1) + err(EXIT_FAILURE, "chdir(/)"); + if (rmdir(dir) == -1) + err(EXIT_FAILURE, "rmdir %s", dir); + + return (ret); +} diff --git a/usr/src/uts/common/sys/time.h b/usr/src/uts/common/sys/time.h index 8a36f622c3..8ec74d4ecd 100644 --- a/usr/src/uts/common/sys/time.h +++ b/usr/src/uts/common/sys/time.h @@ -15,6 +15,8 @@ * Use is subject to license terms. * * Copyright 2013 Nexenta Systems, Inc. All rights reserved. + * + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association. */ /* @@ -356,14 +358,14 @@ extern todinfo_t utc_to_tod(time_t); extern time_t tod_to_utc(todinfo_t); extern int hr_clock_lock(void); extern void hr_clock_unlock(int); -extern hrtime_t gethrtime(void); -extern hrtime_t gethrtime_unscaled(void); +extern hrtime_t gethrtime(void); +extern hrtime_t gethrtime_unscaled(void); extern hrtime_t gethrtime_max(void); extern hrtime_t gethrtime_waitfree(void); extern void scalehrtime(hrtime_t *); extern uint64_t unscalehrtime(hrtime_t); -extern void gethrestime(timespec_t *); -extern time_t gethrestime_sec(void); +extern void gethrestime(timespec_t *); +extern time_t gethrestime_sec(void); extern void gethrestime_lasttick(timespec_t *); extern void hrt2ts(hrtime_t, timestruc_t *); extern hrtime_t ts2hrt(const timestruc_t *); @@ -399,6 +401,7 @@ int futimesat(int, const char *, const struct timeval *); int getitimer(int, struct itimerval *); int utimes(const char *, const struct timeval *); + #if defined(_XPG4_2) int setitimer(int, const struct itimerval *_RESTRICT_KYWD, struct itimerval *_RESTRICT_KYWD); @@ -409,6 +412,22 @@ int setitimer(int, struct itimerval *_RESTRICT_KYWD, #endif /* !defined(_KERNEL) ... defined(_XPG4_2) */ +#if !defined(_KERNEL) && !defined(_STRICT_SYMBOLS) +int futimes(int, const struct timeval *); +int lutimes(const char *, const struct timeval *); + +#define TIMESPEC_TO_TIMEVAL(tv, ts) { \ + (tv)->tv_sec = (ts)->tv_sec; \ + (tv)->tv_usec = (ts)->tv_nsec / 1000; \ +} + +#define TIMEVAL_TO_TIMESPEC(tv, ts) { \ + (ts)->tv_sec = (tv)->tv_sec; \ + (ts)->tv_nsec = (tv)->tv_usec * 1000; \ +} + +#endif /* !defined(_KERNEL) && !defined(_STRICT_SYMBOLS) */ + /* * gettimeofday() and settimeofday() were included in SVr4 due to their * common use in BSD based applications. They were to be included exactly -- cgit v1.2.3 From fd147c98dbdbc9e5ac99fa51cb608e8eeb1f16f1 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Tue, 15 Sep 2020 00:04:46 -0700 Subject: 13168 reality should reflect the mac_prop_id_t comment Reviewed by: Dan McDonald Reviewed by: Patrick Mooney Reviewed by: Toomas Soome Approved by: Hans Rosenfeld --- usr/src/uts/common/sys/mac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'usr/src/uts/common/sys') diff --git a/usr/src/uts/common/sys/mac.h b/usr/src/uts/common/sys/mac.h index 00d9901719..e90df8746c 100644 --- a/usr/src/uts/common/sys/mac.h +++ b/usr/src/uts/common/sys/mac.h @@ -162,6 +162,7 @@ typedef enum { * Please append properties to the end of this list. Do not reorder the list. */ typedef enum { + MAC_PROP_PRIVATE = -1, MAC_PROP_DUPLEX = 0x00000001, MAC_PROP_SPEED, MAC_PROP_STATUS, @@ -239,8 +240,7 @@ typedef enum { MAC_PROP_ADV_50GFDX_CAP, MAC_PROP_EN_50GFDX_CAP, MAC_PROP_EN_FEC_CAP, - MAC_PROP_ADV_FEC_CAP, - MAC_PROP_PRIVATE = -1 + MAC_PROP_ADV_FEC_CAP } mac_prop_id_t; /* -- cgit v1.2.3