From owner-svn-src-all@freebsd.org Wed Sep 4 13:47:39 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DC7F6F23D9; Wed, 4 Sep 2019 13:47:39 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46NlWH5QRfz4KGf; Wed, 4 Sep 2019 13:47:39 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9CBE11C6D9; Wed, 4 Sep 2019 13:47:39 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x84Dld6R017294; Wed, 4 Sep 2019 13:47:39 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x84Dlcds017291; Wed, 4 Sep 2019 13:47:38 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201909041347.x84Dlcds017291@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Wed, 4 Sep 2019 13:47:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r351812 - head/usr.sbin/mpsutil X-SVN-Group: head X-SVN-Commit-Author: avg X-SVN-Commit-Paths: head/usr.sbin/mpsutil X-SVN-Commit-Revision: 351812 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Sep 2019 13:47:39 -0000 Author: avg Date: Wed Sep 4 13:47:38 2019 New Revision: 351812 URL: https://svnweb.freebsd.org/changeset/base/351812 Log: mpsutil slot set status This code has been written as a proof of concept, but I think that it can be useful in general. It allows to set the status of an enclosure slot. Practically, this means controlling whatever slot status LEDs the enclosure provides. At present, the new command does not have sanity checks or any conveniences. That means that it is possible to issue the command for an invalid slot and an enclosure. But the worst I have seen happening is either the command failing or simply being ignored. Also, at the moment, the status has to be specified as a numeric bit mask. The bit definitions can be found in sys/dev/mps/mpi/mpi2_init.h, they are prefixed with MPI2_SEP_REQ_SLOTSTATUS_. The only way to address a slot is by the enclosure handle and the slot number. Both are readily available from mpsutil show commands. So, future enhancements could include alternative ways to address a slot (e.g., by a disk handle or a disk device name) and human friendly names for slot statuses. The new command is useful alternative to 'sas2ircu locate' command. First, sas2ircu is a proprietary blob. Second, it supports setting only locate / identify status bit. Tested on HP H220 running LSI IT firmware 20.x. Reviewed by: bapt MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D20535 Added: head/usr.sbin/mpsutil/mps_slot.c (contents, props changed) Modified: head/usr.sbin/mpsutil/Makefile head/usr.sbin/mpsutil/mps_cmd.c head/usr.sbin/mpsutil/mpsutil.h Modified: head/usr.sbin/mpsutil/Makefile ============================================================================== --- head/usr.sbin/mpsutil/Makefile Wed Sep 4 13:44:46 2019 (r351811) +++ head/usr.sbin/mpsutil/Makefile Wed Sep 4 13:47:38 2019 (r351812) @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= mpsutil -SRCS= mps_cmd.c mps_debug.c mps_flash.c mps_show.c mpsutil.c +SRCS= mps_cmd.c mps_debug.c mps_flash.c mps_show.c mps_slot.c mpsutil.c MAN= mpsutil.8 WARNS?= 3 Modified: head/usr.sbin/mpsutil/mps_cmd.c ============================================================================== --- head/usr.sbin/mpsutil/mps_cmd.c Wed Sep 4 13:44:46 2019 (r351811) +++ head/usr.sbin/mpsutil/mps_cmd.c Wed Sep 4 13:47:38 2019 (r351812) @@ -283,6 +283,29 @@ mps_map_btdh(int fd, uint16_t *devhandle, uint16_t *bu } int +mps_set_slot_status(int fd, U16 handle, U16 slot, U32 status) +{ + MPI2_SEP_REQUEST req; + MPI2_SEP_REPLY reply; + + bzero(&req, sizeof(req)); + req.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; + req.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; + req.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; + req.EnclosureHandle = handle; + req.Slot = slot; + req.SlotStatus = status; + + if (mps_pass_command(fd, &req, sizeof(req), &reply, sizeof(reply), + NULL, 0, NULL, 0, 30) != 0) + return (errno); + + if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) + return (EIO); + return (0); +} + +int mps_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header, U16 *IOCStatus) { Added: head/usr.sbin/mpsutil/mps_slot.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/mpsutil/mps_slot.c Wed Sep 4 13:47:38 2019 (r351812) @@ -0,0 +1,114 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2019 Andriy Gapon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__RCSID("$FreeBSD$"); + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mpsutil.h" + +MPS_TABLE(top, slot); + +static int +slot_set(int argc, char **argv) +{ + char *endptr; + unsigned long ux; + long x; + int error; + int fd; + U32 status; + U16 handle; + U16 slot; + + if (argc != 5) { + warnx("Incorrect number of arguments"); + return (EINVAL); + } + + if (strcmp(argv[1], "status") != 0) { + warnx("Invalid argument '%s', expecting 'status'", + argv[1]); + return (EINVAL); + } + + errno = 0; + x = strtol(argv[2], &endptr, 0); + if (*endptr != '\0' || errno != 0 || x < 0 || x > UINT16_MAX) { + warnx("Invalid enclosure handle argument '%s'", argv[2]); + return (EINVAL); + } + handle = x; + + errno = 0; + x = strtol(argv[3], &endptr, 0); + if (*endptr != '\0' || errno != 0 || x < 0 || x > UINT16_MAX) { + warnx("Invalid slot argument '%s'", argv[3]); + return (EINVAL); + } + slot = x; + + errno = 0; + ux = strtoul(argv[4], &endptr, 0); + if (*endptr != '\0' || errno != 0 || ux > UINT32_MAX) { + warnx("Invalid status argument '%s'", argv[4]); + return (EINVAL); + } + status = ux; + + fd = mps_open(mps_unit); + if (fd < 0) { + error = errno; + warn("mps_open"); + return (error); + } + + if (mps_set_slot_status(fd, handle, slot, status) != 0) { + warnx("Failed to set status"); + close(fd); + return (1); + } + + close(fd); + printf("Successfully set slot status\n"); + return (0); +} + +MPS_COMMAND(slot, set, slot_set, "status " + "", "Set status of the slot in the directly attached enclosure"); Modified: head/usr.sbin/mpsutil/mpsutil.h ============================================================================== --- head/usr.sbin/mpsutil/mpsutil.h Wed Sep 4 13:44:46 2019 (r351811) +++ head/usr.sbin/mpsutil/mpsutil.h Wed Sep 4 13:47:38 2019 (r351812) @@ -128,6 +128,7 @@ int mps_map_btdh(int fd, uint16_t *devhandle, uint16_t const char *mps_ioc_status(U16 IOCStatus); int mps_firmware_send(int fd, unsigned char *buf, uint32_t len, bool bios); int mps_firmware_get(int fd, unsigned char **buf, bool bios); +int mps_set_slot_status(int fd, U16 handle, U16 slot, U32 status); static __inline void * mps_read_man_page(int fd, U8 PageNumber, U16 *IOCStatus)