From nobody Thu Jan 27 02:05:39 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id BEB03196CA71; Thu, 27 Jan 2022 02:05:39 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JkkSz54Ghz3qw5; Thu, 27 Jan 2022 02:05:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643249139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YewHpRjp64TE+HS/tqtAmhpm9YqIYqTOFhN1LpNdxhA=; b=rj7pAEnckOWUBbtXxt0kD7vSEB44S+s6UbG1ST032z4Xia6+CjErdTRG2P+DHp4dvpOh7e dVcv5BkrLygS+WuPVD34johgpqwUOUxPOAq6A5jLkk9zkefZKqmvB1t9iJpOjRQvAB2vGT HL1No7Juhi8hYttCPlhNpdbXWdj1GR6L5Tm+tKTRvaEgRPmtyXDQe49LJE5XE9eQRfSP4O wW5Kbci8iIPa8QKFGykr1AR8qwh03RjMV+2DX0A4ujHDtAUGGymRjOf9ZhxSB28osf+oVF EXVEtdspNJMCZWDrbgCd2HFiiyAzBZRcVX7vb+6WoUr/+2s+DTb2mMubTJgFXw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8E51E5F92; Thu, 27 Jan 2022 02:05:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20R25dpf049958; Thu, 27 Jan 2022 02:05:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20R25dU3049957; Thu, 27 Jan 2022 02:05:39 GMT (envelope-from git) Date: Thu, 27 Jan 2022 02:05:39 GMT Message-Id: <202201270205.20R25dU3049957@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: bbed4b4b1a26 - stable/13 - sesutil: Avoid setting reserved bits. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: bbed4b4b1a26f59da0e09cda70f9632e6171bb6e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643249139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YewHpRjp64TE+HS/tqtAmhpm9YqIYqTOFhN1LpNdxhA=; b=dIRU/WpttHX6bgi3S4LTAh7qFQjR7UXGjdPbLPZtHyUS0xJ8YPQj4U8VkJij7U8NpJf6jc 1xJdPpnfQgYjEuCw3KP7OVIuH0YEbmUCNlMIwpz/drNr5KSQimEdXSIPu63CZGK6u8xpT1 x4F8J8tReE1CV8EWIiI7Mc0D8/G8DdDrerWUoExoUYyTjH5mz4TjHmrvGJJj6nLMk+6lYZ yT2ka2FNom2tzoqjXJZ+wSE1nSpaHx3PoDZiCzvM9zPa/8y1w236djZYEBn21disYreioG gCMXk+WJ2FJVo41IbfEqCIUQbkKi+WzOpV3Ro2rbK/yG8j0V6+0fXnagHuK8QQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643249139; a=rsa-sha256; cv=none; b=JPoAIqeLjsMpgRlt6CZk5nbMPFydNpLAYMLF6NH9Q6uh4wiE4107EAgJBgbbZ6v8o+bKk9 Y/XZhDy5SQjGKeT/4Wi4SEPaC50E+aZOUWrq7/2dGmp/GwgrcXtlE2kHiuVaFbOTat64zK drqGlFTYyqHtiB3CEHbnmI4eZJm7KASA9LROXGDnelGuAAr+bnpL6qSFNfHrzWvJE8f3iq PSwdYq4cAdUS6f1H+KPjXqgtT2hvUMbB6Wz/SrpKbsmclO67eU4gxVMih7U5a4+DaBW237 /KgaarEwQFj+ZAkIPUisMlr0Icw5k0v6fav6B6Yh8OHkTwiHQFkpwLTyQN7Vpw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=bbed4b4b1a26f59da0e09cda70f9632e6171bb6e commit bbed4b4b1a26f59da0e09cda70f9632e6171bb6e Author: Alexander Motin AuthorDate: 2022-01-13 18:45:28 +0000 Commit: Alexander Motin CommitDate: 2022-01-27 00:52:19 +0000 sesutil: Avoid setting reserved bits. Weird side of SES specification is that some bits have different meaning or semantics in status and control pages. This patch fixes non-zero writes into reserved fields, that caused errors on some enclosures when trying to control locate/fault LEDs, keeping other bits unchanged. MFC after: 2 weeks Sposonred by: iXsystems, Inc. (cherry picked from commit 2e19fae49fd4ab2360971463cee99a62198973b1) --- sys/cam/scsi/scsi_ses.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/sesutil/sesutil.c | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/sys/cam/scsi/scsi_ses.h b/sys/cam/scsi/scsi_ses.h index 86cc88ad27f1..8a1c7118f99a 100644 --- a/sys/cam/scsi/scsi_ses.h +++ b/sys/cam/scsi/scsi_ses.h @@ -2058,6 +2058,50 @@ union ses_status_element { uint8_t bytes[4]; }; +/* + * Convert element status into control as much as possible. + * Some bits have different meaning in status and control, + * while others have the same and should be preserved. + */ +static inline void +ses_status_to_ctrl(uint8_t type, uint8_t *bytes) +{ + /* Updated to SES4r5. */ + static const uint8_t mask[][4] = { + { 0x60, 0x00, 0x00, 0x00 }, /* UNSPECIFIED */ + { 0x60, 0x00, 0x4e, 0x3c }, /* DEVICE */ + { 0x60, 0xc0, 0x00, 0x60 }, /* POWER */ + { 0x60, 0xc0, 0x00, 0x60 }, /* COOLING/FAN */ + { 0x60, 0xc0, 0x00, 0x80 }, /* THERM */ + { 0x60, 0xc0, 0x00, 0x01 }, /* DOORLOCK */ + { 0x60, 0xc0, 0x00, 0x5f }, /* ALARM */ + { 0x60, 0xf0, 0x01, 0x00 }, /* ESSC */ + { 0x60, 0xc0, 0x00, 0x00 }, /* SCC */ + { 0x60, 0xc0, 0x00, 0x00 }, /* NVRAM */ + { 0x60, 0x00, 0x00, 0x00 }, /* INV_OP_REASON */ + { 0x60, 0x00, 0x00, 0xe0 }, /* UPS */ + { 0x60, 0xc0, 0xff, 0xff }, /* DISPLAY */ + { 0x60, 0xc0, 0x00, 0x00 }, /* KEYPAD */ + { 0x60, 0x80, 0x00, 0xff }, /* ENCLOSURE */ + { 0x60, 0xc0, 0x00, 0x10 }, /* SCSIXVR */ + { 0x60, 0x80, 0xff, 0xff }, /* LANGUAGE */ + { 0x60, 0xc0, 0x00, 0x01 }, /* COMPORT */ + { 0x60, 0xc0, 0x00, 0x00 }, /* VOM */ + { 0x60, 0xc0, 0x00, 0x00 }, /* AMMETER */ + { 0x60, 0xc0, 0x00, 0x01 }, /* SCSI_TGT */ + { 0x60, 0xc0, 0x00, 0x01 }, /* SCSI_INI*/ + { 0x60, 0xc0, 0x00, 0x00 }, /* SUBENC */ + { 0x60, 0xff, 0x4e, 0x3c }, /* ARRAY_DEV */ + { 0x60, 0xc0, 0x00, 0x00 }, /* SAS_EXP */ + { 0x60, 0x80, 0x00, 0x40 }, /* SAS_CONN */ + }; + + if (type >= sizeof(mask) / sizeof(mask[0])) + type = 0; + for (int i = 0; i < 4; i++) + bytes[i] &= mask[type][i]; +} + /*===================== SCSI SES Status Diagnostic Page =====================*/ struct ses_status_page { struct ses_page_hdr hdr; diff --git a/usr.sbin/sesutil/sesutil.c b/usr.sbin/sesutil/sesutil.c index b365988e27d4..3164116a8fdc 100644 --- a/usr.sbin/sesutil/sesutil.c +++ b/usr.sbin/sesutil/sesutil.c @@ -138,10 +138,11 @@ do_led(int fd, unsigned int idx, elm_type_t type, bool onoff, bool setfault) close(fd); xo_err(EXIT_FAILURE, "ENCIOC_GETELMSTAT"); } - slot = (struct ses_ctrl_dev_slot *) &o.cstat[0]; + ses_status_to_ctrl(type, &o.cstat[0]); switch (type) { case ELMTYP_DEVICE: case ELMTYP_ARRAY_DEV: + slot = (struct ses_ctrl_dev_slot *) &o.cstat[0]; ses_ctrl_common_set_select(&slot->common, 1); if (setfault) ses_ctrl_dev_slot_set_rqst_fault(slot, state);