From nobody Wed Sep 17 08:46:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42309C4167B for ; Wed, 21 Dec 2022 05:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234265AbiLUFW6 (ORCPT ); Wed, 21 Dec 2022 00:22:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbiLUFWz (ORCPT ); Wed, 21 Dec 2022 00:22:55 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D16DD205C4; Tue, 20 Dec 2022 21:22:53 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id ED0E53200928; Wed, 21 Dec 2022 00:22:51 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 21 Dec 2022 00:22:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pjd.dev; h=cc:cc :content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1671600171; x=1671686571; bh=sL 2oxNr011h7ZeJ2PosuMIR2/IGZMgP1eqdnxe/YkgM=; b=J8twjOE5bulwy00Gf9 lsqxSQz8vvJeYXmGvteGkxEnewW0YMzDTySrzpEFxbxuFpxtlBVtGN87kfIX/Iug qUyv0AYStuiAUJMYkGlD82QvGinaMlKECiz2aKjMUSR0EJzpCz7OH5+MaVZ/IL9F 99JLNzpmc52Pk1lz/9Vx7qIhGNYGClYqGW+PU7PUvaVpeBKwgIjlDaeKU0ett6MO L+VUzf1ZQUtfLsuu72D79Q+IgW2Z02PKNOGz7ef9/mrnXZfLresTgJjvxRtaGB6x wZjH+HaARHdLK+kI14pm8ViWikAsGUhEj3s0cKCDyDqjwalthLTgqVNXsa9UEOk9 eXFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671600171; x=1671686571; bh=sL2oxNr011h7Z eJ2PosuMIR2/IGZMgP1eqdnxe/YkgM=; b=ZHhWAQ+Y7dMLl4lxM3oe5Lt3CRXv4 Ls0b1HXfluhw4vomW62VviyrU2YKPk0pkMTPY3ckl/oVDzXf54sFqhZfDXpxeEGY 4fAbdPdxovnFrxIqkpfU0r5Ua4+65aVt83+Yf8okKKObXc4U+uYJPd2a8KghibIH E0wutnKEAMt5u9Lx/TkImmMA6za1shaQXtGHvPL2R9JQ93tl3vXdaGmJNkmIigrs f+HJKUXUM7GH+ccMJI9Kl4jUKagDWNui9brJHvBYzrQwKXB5yWaXJm+9LiKOlC9A Y5E67G/aeCczghq8pYsabAwZO/A5NDnEvGIMr87qMtsuanK3H/se7dvhA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeejgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecumhhishhsihhnghcuvffquchfihgvlhguucdlfedtmd enogetfedtuddqtdduucdludehmdenucfjughrpefhvfevufffkffojghfggfgsedtkeer tdertddtnecuhfhrohhmpefrvghtvghrucffvghlvghvohhrhigrshcuoehpvghtvghrse hpjhgurdguvghvqeenucggtffrrghtthgvrhhnpeektdeileejieehiedujeehleduueej keekjeeggfettdevieevhfeggfeuffeiteenucffohhmrghinhepkhgvrhhnvghlrdhorh hgpdhgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpehpvghtvghrsehpjhgurdguvghv X-ME-Proxy: Feedback-ID: i9e814621:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Dec 2022 00:22:51 -0500 (EST) From: Peter Delevoryas Cc: peter@pjd.dev, sam@mendozajonas.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joel@jms.id.au, gwshan@linux.vnet.ibm.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] net/ncsi: Simplify Kconfig/dts control flow Date: Tue, 20 Dec 2022 21:22:44 -0800 Message-Id: <20221221052246.519674-2-peter@pjd.dev> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221221052246.519674-1-peter@pjd.dev> References: <20221221052246.519674-1-peter@pjd.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Background: 1. CONFIG_NCSI_OEM_CMD_KEEP_PHY If this is enabled, we send an extra OEM Intel command in the probe sequence immediately after discovering a channel (e.g. after "Clear Initial State"). 2. CONFIG_NCSI_OEM_CMD_GET_MAC If this is enabled, we send one of 3 OEM "Get MAC Address" commands from Broadcom, Mellanox (Nvidida), and Intel in the *configuration* sequence for a channel. 3. mellanox,multi-host (or mlx,multi-host) Introduced by this patch: https://lore.kernel.org/all/20200108234341.2590674-1-vijaykhemka@fb.com/ Which was actually originally from cosmo.chou@quantatw.com: https://github.com/facebook/openbmc-linux/commit/9f132a10ec48db84613519258c= d8a317fb9c8f1b Cosmo claimed that the Nvidia ConnectX-4 and ConnectX-6 NIC's don't respond to Get Version ID, et. al in the probe sequence unless you send the Set MC Affinity command first. Problem Statement: We've been using a combination of #ifdef code blocks and IS_ENABLED() conditions to conditionally send these OEM commands. It makes adding any new code around these commands hard to understand. Solution: In this patch, I just want to remove the conditionally compiled blocks of code, and always use IS_ENABLED(...) to do dynamic control flow. I don't think the small amount of code this adds to non-users of the OEM Kconfigs is a big deal. Signed-off-by: Peter Delevoryas --- net/ncsi/ncsi-manage.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index 80713febfac6..f56795769893 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -689,8 +689,6 @@ static int set_one_vid(struct ncsi_dev_priv *ndp, struc= t ncsi_channel *nc, return 0; } =20 -#if IS_ENABLED(CONFIG_NCSI_OEM_CMD_KEEP_PHY) - static int ncsi_oem_keep_phy_intel(struct ncsi_cmd_arg *nca) { unsigned char data[NCSI_OEM_INTEL_CMD_KEEP_PHY_LEN]; @@ -716,10 +714,6 @@ static int ncsi_oem_keep_phy_intel(struct ncsi_cmd_arg= *nca) return ret; } =20 -#endif - -#if IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) - /* NCSI OEM Command APIs */ static int ncsi_oem_gma_handler_bcm(struct ncsi_cmd_arg *nca) { @@ -856,8 +850,6 @@ static int ncsi_gma_handler(struct ncsi_cmd_arg *nca, u= nsigned int mf_id) return nch->handler(nca); } =20 -#endif /* CONFIG_NCSI_OEM_CMD_GET_MAC */ - /* Determine if a given channel from the channel_queue should be used for = Tx */ static bool ncsi_channel_is_tx(struct ncsi_dev_priv *ndp, struct ncsi_channel *nc) @@ -1039,20 +1031,18 @@ static void ncsi_configure_channel(struct ncsi_dev_= priv *ndp) goto error; } =20 - nd->state =3D ncsi_dev_state_config_oem_gma; + nd->state =3D IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) + ? ncsi_dev_state_config_oem_gma + : ncsi_dev_state_config_clear_vids; break; case ncsi_dev_state_config_oem_gma: nd->state =3D ncsi_dev_state_config_clear_vids; - ret =3D -1; =20 -#if IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) nca.type =3D NCSI_PKT_CMD_OEM; nca.package =3D np->id; nca.channel =3D nc->id; ndp->pending_req_num =3D 1; ret =3D ncsi_gma_handler(&nca, nc->version.mf_id); -#endif /* CONFIG_NCSI_OEM_CMD_GET_MAC */ - if (ret < 0) schedule_work(&ndp->work); =20 @@ -1404,7 +1394,6 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *= ndp) =20 schedule_work(&ndp->work); break; -#if IS_ENABLED(CONFIG_NCSI_OEM_CMD_GET_MAC) case ncsi_dev_state_probe_mlx_gma: ndp->pending_req_num =3D 1; =20 @@ -1429,7 +1418,6 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *= ndp) =20 nd->state =3D ncsi_dev_state_probe_cis; break; -#endif /* CONFIG_NCSI_OEM_CMD_GET_MAC */ case ncsi_dev_state_probe_cis: ndp->pending_req_num =3D NCSI_RESERVED_CHANNEL; =20 @@ -1447,7 +1435,6 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *= ndp) if (IS_ENABLED(CONFIG_NCSI_OEM_CMD_KEEP_PHY)) nd->state =3D ncsi_dev_state_probe_keep_phy; break; -#if IS_ENABLED(CONFIG_NCSI_OEM_CMD_KEEP_PHY) case ncsi_dev_state_probe_keep_phy: ndp->pending_req_num =3D 1; =20 @@ -1460,7 +1447,6 @@ static void ncsi_probe_channel(struct ncsi_dev_priv *= ndp) =20 nd->state =3D ncsi_dev_state_probe_gvi; break; -#endif /* CONFIG_NCSI_OEM_CMD_KEEP_PHY */ case ncsi_dev_state_probe_gvi: case ncsi_dev_state_probe_gc: case ncsi_dev_state_probe_gls: --=20 2.30.2 From nobody Wed Sep 17 08:46:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 222C7C4167B for ; Wed, 21 Dec 2022 05:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234400AbiLUFXF (ORCPT ); Wed, 21 Dec 2022 00:23:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234040AbiLUFW5 (ORCPT ); Wed, 21 Dec 2022 00:22:57 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E530201A1; Tue, 20 Dec 2022 21:22:56 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id F0C85320077A; Wed, 21 Dec 2022 00:22:54 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 21 Dec 2022 00:22:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pjd.dev; h=cc:cc :content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1671600174; x=1671686574; bh=zN 958PcJz/PV3DsW6WEQWLRBp7oQ21G6ASIhZz2zjz8=; b=gTkvPPKBsVQewxvhoO 8i/LZtepYyhu1NIwV3uA35RL1ygeNwI4BuoROiciJiUr5QeM397aGaR0XIvCYY3Z PSRPtSqC2msRmu+7jt430lys3xY6usvzFfUoC+XhRTxoDmzU3jkTVcF8zGdaU7y2 hXzwQEzpD7ViGKvUqi56tNUX1Pe8LmGci2/74/pVpWWvnM0SQuxZz7rTnluTDHN4 RKqVPdO8SjfsG1bnqB7tXkX0vkl7X0Gp+3lqrzIAhnWbysI9hESvI8sOJyvW0Cb6 xpf25MEiMCgoQLIH2v/mApVCSJOKU7DkbwU4g1/6v7FRAdJ7gut/5KnmTN+vBFBH UiRw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671600174; x=1671686574; bh=zN958PcJz/PV3 DsW6WEQWLRBp7oQ21G6ASIhZz2zjz8=; b=goS9Fz9lczB92xHHmz3DfJJgyc1NZ +MD9j/Ma9yFMfZqEv1aqFvaRUogfZzuY74GfIE9pWH8WFqzsJ4syUSk7029OMPNH Qapr8FmxwHM5XURupeDribwstO7s6b6+j1Ey66ByzU2K0N/NZPKimj12UMn0RqbD 3oPVyoqFYhaigQOKWqbKkwoU3QDgLPkVi3cZfAIMHecoiSOvVLmn/oukwKHXOK3I yvabyUN2ehuFJv2/nGiAZVfgESwaOsQsz9NJLp7cjpATfEu3I4t5xNulB9AmA9FU 3jtVMhW74wETm+eF1FN1FKVfLYnkW/Q4ByE/wy9pq+4aV/yuashsxsJdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeejgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecumhhishhsihhnghcuvffquchfihgvlhguucdlfedtmd enogetfedtuddqtdduucdludehmdenucfjughrpefhvfevufffkffojghfggfgsedtkeer tdertddtnecuhfhrohhmpefrvghtvghrucffvghlvghvohhrhigrshcuoehpvghtvghrse hpjhgurdguvghvqeenucggtffrrghtthgvrhhnpeeliedvteeuieekuefhieeghfehueff heeutdduueejiedvfedtudevgeevhfffhfenucffohhmrghinhepughmthhfrdhorhhgpd ifihhkihhpvgguihgrrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomhepphgvthgvrhesphhjugdruggvvh X-ME-Proxy: Feedback-ID: i9e814621:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Dec 2022 00:22:54 -0500 (EST) From: Peter Delevoryas Cc: peter@pjd.dev, sam@mendozajonas.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joel@jms.id.au, gwshan@linux.vnet.ibm.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] net/ncsi: Fix netlink major/minor version numbers Date: Tue, 20 Dec 2022 21:22:45 -0800 Message-Id: <20221221052246.519674-3-peter@pjd.dev> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221221052246.519674-1-peter@pjd.dev> References: <20221221052246.519674-1-peter@pjd.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The netlink interface for major and minor version numbers doesn't actually return the major and minor version numbers. It reports a u32 that contains the (major, minor, update, alpha1) components as the major version number, and then alpha2 as the minor version number. For whatever reason, the u32 byte order was reversed (ntohl): maybe it was assumed that the encoded value was a single big-endian u32, and alpha2 was the minor version. The correct way to get the supported NC-SI version from the network controller is to parse the Get Version ID response as described in 8.4.44 of the NC-SI spec[1]. Get Version ID Response Packet Format Bits +--------+--------+--------+--------+ Bytes | 31..24 | 23..16 | 15..8 | 7..0 | +-------+--------+--------+--------+--------+ | 0..15 | NC-SI Header | +-------+--------+--------+--------+--------+ | 16..19| Response code | Reason code | +-------+--------+--------+--------+--------+ |20..23 | Major | Minor | Update | Alpha1 | +-------+--------+--------+--------+--------+ |24..27 | reserved | Alpha2 | +-------+--------+--------+--------+--------+ | .... other stuff .... | The major, minor, and update fields are all binary-coded decimal (BCD) encoded [2]. The spec provides examples below the Get Version ID response format in section 8.4.44.1, but for practical purposes, this is an example from a live network card: root@bmc:~# ncsi-util 0x15 NC-SI Command Response: cmd: GET_VERSION_ID(0x15) Response: COMMAND_COMPLETED(0x0000) Reason: NO_ERROR(0x0000) Payload length =3D 40 20: 0xf1 0xf1 0xf0 0x00 <<<<<<<<< (major, minor, update, alpha1) 24: 0x00 0x00 0x00 0x00 <<<<<<<<< (_, _, _, alpha2) 28: 0x6d 0x6c 0x78 0x30 32: 0x2e 0x31 0x00 0x00 36: 0x00 0x00 0x00 0x00 40: 0x16 0x1d 0x07 0xd2 44: 0x10 0x1d 0x15 0xb3 48: 0x00 0x17 0x15 0xb3 52: 0x00 0x00 0x81 0x19 This should be parsed as "1.1.0". "f" in the upper-nibble means to ignore it, contributing zero. If both nibbles are "f", I think the whole field is supposed to be ignored. Major and minor are "required", meaning they're not supposed to be "ff", but the update field is "optional" so I think it can be ff. I think the simplest thing to do is just set the major and minor to zero instead of juggling some conditional logic or something. bcd2bin() from "include/linux/bcd.h" seems to assume both nibbles are 0-9, so I've provided a custom BCD decoding function. Alpha1 and alpha2 are ISO/IEC 8859-1 encoded, which just means ASCII characters as far as I can tell, although the full encoding table for non-alphabetic characters is slightly different (I think). I imagine the alpha fields are just supposed to be alphabetic characters, but I haven't seen any network cards actually report a non-zero value for either. If people wrote software against this netlink behavior, and were parsing the major and minor versions themselves from the u32, then this would definitely break their code. [1] https://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.= 0.0.pdf [2] https://en.wikipedia.org/wiki/Binary-coded_decimal [2] https://en.wikipedia.org/wiki/ISO/IEC_8859-1 Signed-off-by: Peter Delevoryas Fixes: 138635cc27c9 ("net/ncsi: NCSI response packet handler") --- net/ncsi/internal.h | 7 +++++-- net/ncsi/ncsi-netlink.c | 4 ++-- net/ncsi/ncsi-pkt.h | 7 +++++-- net/ncsi/ncsi-rsp.c | 26 ++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h index 03757e76bb6b..374412ed780b 100644 --- a/net/ncsi/internal.h +++ b/net/ncsi/internal.h @@ -105,8 +105,11 @@ enum { =20 =20 struct ncsi_channel_version { - u32 version; /* Supported BCD encoded NCSI version */ - u32 alpha2; /* Supported BCD encoded NCSI version */ + u8 major; /* NCSI version major */ + u8 minor; /* NCSI version minor */ + u8 update; /* NCSI version update */ + char alpha1; /* NCSI version alpha1 */ + char alpha2; /* NCSI version alpha2 */ u8 fw_name[12]; /* Firmware name string */ u32 fw_version; /* Firmware version */ u16 pci_ids[4]; /* PCI identification */ diff --git a/net/ncsi/ncsi-netlink.c b/net/ncsi/ncsi-netlink.c index c189b4c8a182..db350b8f5d88 100644 --- a/net/ncsi/ncsi-netlink.c +++ b/net/ncsi/ncsi-netlink.c @@ -71,8 +71,8 @@ static int ncsi_write_channel_info(struct sk_buff *skb, if (nc =3D=3D nc->package->preferred_channel) nla_put_flag(skb, NCSI_CHANNEL_ATTR_FORCED); =20 - nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MAJOR, nc->version.version); - nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MINOR, nc->version.alpha2); + nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MAJOR, nc->version.major); + nla_put_u32(skb, NCSI_CHANNEL_ATTR_VERSION_MINOR, nc->version.minor); nla_put_string(skb, NCSI_CHANNEL_ATTR_VERSION_STR, nc->version.fw_name); =20 vid_nest =3D nla_nest_start_noflag(skb, NCSI_CHANNEL_ATTR_VLAN_LIST); diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h index ba66c7dc3a21..c9d1da34dc4d 100644 --- a/net/ncsi/ncsi-pkt.h +++ b/net/ncsi/ncsi-pkt.h @@ -197,9 +197,12 @@ struct ncsi_rsp_gls_pkt { /* Get Version ID */ struct ncsi_rsp_gvi_pkt { struct ncsi_rsp_pkt_hdr rsp; /* Response header */ - __be32 ncsi_version; /* NCSI version */ + unsigned char major; /* NCSI version major */ + unsigned char minor; /* NCSI version minor */ + unsigned char update; /* NCSI version update */ + unsigned char alpha1; /* NCSI version alpha1 */ unsigned char reserved[3]; /* Reserved */ - unsigned char alpha2; /* NCSI version */ + unsigned char alpha2; /* NCSI version alpha2 */ unsigned char fw_name[12]; /* f/w name string */ __be32 fw_version; /* f/w version */ __be16 pci_ids[4]; /* PCI IDs */ diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index 6447a09932f5..7a805b86a12d 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -19,6 +19,19 @@ #include "ncsi-pkt.h" #include "ncsi-netlink.h" =20 +/* Nibbles within [0xA, 0xF] add zero "0" to the returned value. + * Optional fields (encoded as 0xFF) will default to zero. + */ +static u8 decode_bcd_u8(u8 x) +{ + int lo =3D x & 0xF; + int hi =3D x >> 4; + + lo =3D lo < 0xA ? lo : 0; + hi =3D hi < 0xA ? hi : 0; + return lo + hi * 10; +} + static int ncsi_validate_rsp_pkt(struct ncsi_request *nr, unsigned short payload) { @@ -804,9 +817,18 @@ static int ncsi_rsp_handler_gvi(struct ncsi_request *n= r) if (!nc) return -ENODEV; =20 - /* Update to channel's version info */ + /* Update channel's version info + * + * Major, minor, and update fields are supposed to be + * unsigned integers encoded as packed BCD. + * + * Alpha1 and alpha2 are ISO/IEC 8859-1 characters. + */ ncv =3D &nc->version; - ncv->version =3D ntohl(rsp->ncsi_version); + ncv->major =3D decode_bcd_u8(rsp->major); + ncv->minor =3D decode_bcd_u8(rsp->minor); + ncv->update =3D decode_bcd_u8(rsp->update); + ncv->alpha1 =3D rsp->alpha1; ncv->alpha2 =3D rsp->alpha2; memcpy(ncv->fw_name, rsp->fw_name, 12); ncv->fw_version =3D ntohl(rsp->fw_version); --=20 2.30.2 From nobody Wed Sep 17 08:46:22 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AD62C4332F for ; Wed, 21 Dec 2022 05:23:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234309AbiLUFXJ (ORCPT ); Wed, 21 Dec 2022 00:23:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbiLUFW7 (ORCPT ); Wed, 21 Dec 2022 00:22:59 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1950205E4; Tue, 20 Dec 2022 21:22:58 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id C4BFB320092A; Wed, 21 Dec 2022 00:22:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 21 Dec 2022 00:22:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pjd.dev; h=cc:cc :content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1671600177; x=1671686577; bh=Zg fj7AjLpkv1KMNUdbs3vZmEHCz6Q1TCgnvxZx4jkhQ=; b=Kxi9icXfAj7jIkrwcc HyM5pl9gUlYpsn/l+wKIQ8QS267FnwPqcSoCKmm9uQqa0r74o9WWeR6ImzZGvsht EmaxWGx4sMsXy3tYGGB81FoldaPGRMYqANUKPfbRopLVAP66VRSZty+Bc7+0sPi4 8bt50qsZkQ/0Pl6/hyXSfcmPctYTwC/gsOVEyD/kFRrv4n5jUlBvxnOGlj3MoRqF L3Zah2S/Le2ZcmoL6HcDzXacMl7SVNTlipQ8/Ib7tRO9lrFEuumGvTCgqqlKngvz hcwBujO8Wv8v+agjbsEgGERkYsG79EjqPCTWC+LjLevdjKg4Vs3fh+p9MOExzYcj BrFg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671600177; x=1671686577; bh=Zgfj7AjLpkv1K MNUdbs3vZmEHCz6Q1TCgnvxZx4jkhQ=; b=VJNIvomz9x7pRvkHUQAXfH5U4mEg2 PBzdTMsxgTqpX6Kx+zNXomNtPFflj6Ptn9EzLqDoTrUyEbDO4+mqxyFEB1/a+py4 xnFEzvADEWnfOeLwzljCSd/gy0Dmcb9N7BIZd6omKKMyzIF0gRdvg4NWPDSOqPum GYboQZTlUcZfYTzL0BUVDSFYtH5DAJM0ZvEoMxmJWOGXAoqMWnqM8Wuk2fLvwIb3 PSZEOb4n5pSzs0ENZcC81nhsY9Y5qZoJxY1Fjoc8TlAA6eAh+Q66EvzTk1QJOh53 cmUvgzlbBTyyE/FEPN88bAXFPoPfpDNce/vsT+auFREbtg64YeVFRcpUA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeejgdekfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecumhhishhsihhnghcuvffquchfihgvlhguucdlfedtmd enogetfedtuddqtdduucdludehmdenucfjughrpefhvfevufffkffojghfggfgsedtkeer tdertddtnecuhfhrohhmpefrvghtvghrucffvghlvghvohhrhigrshcuoehpvghtvghrse hpjhgurdguvghvqeenucggtffrrghtthgvrhhnpeefjeejlefggeefueehfeekieetgeeh teffhedvtdfgfeevjeefudejjeejjeelkeenucffohhmrghinhepughmthhfrdhorhhgpd hgihhthhhusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpehpvghtvghrsehpjhgurdguvghv X-ME-Proxy: Feedback-ID: i9e814621:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Dec 2022 00:22:56 -0500 (EST) From: Peter Delevoryas Cc: peter@pjd.dev, sam@mendozajonas.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joel@jms.id.au, gwshan@linux.vnet.ibm.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] net/ncsi: Add NC-SI 1.2 Get MC MAC Address command Date: Tue, 20 Dec 2022 21:22:46 -0800 Message-Id: <20221221052246.519674-4-peter@pjd.dev> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221221052246.519674-1-peter@pjd.dev> References: <20221221052246.519674-1-peter@pjd.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This change adds support for the NC-SI 1.2 Get MC MAC Address command, specified here: https://www.dmtf.org/sites/default/files/standards/documents/DSP0222_1.2WIP= 90_0.pdf It serves the exact same function as the existing OEM Get MAC Address commands, so if a channel reports that it supports NC-SI 1.2, we prefer to use the standard command rather than the OEM command. Verified with an invalid MAC address and 2 valid ones: [ 55.137072] ftgmac100 1e690000.ftgmac eth0: NCSI: Received 3 provisioned= MAC addresses [ 55.137614] ftgmac100 1e690000.ftgmac eth0: NCSI: MAC address 0: 00:00:0= 0:00:00:00 [ 55.138026] ftgmac100 1e690000.ftgmac eth0: NCSI: MAC address 1: fa:ce:b= 0:0c:20:22 [ 55.138528] ftgmac100 1e690000.ftgmac eth0: NCSI: MAC address 2: fa:ce:b= 0:0c:20:23 [ 55.139241] ftgmac100 1e690000.ftgmac eth0: NCSI: Unable to assign 00:00= :00:00:00:00 to device [ 55.140098] ftgmac100 1e690000.ftgmac eth0: NCSI: Set MAC address to fa:= ce:b0:0c:20:22 IMPORTANT NOTE: The code I'm submitting here is parsing the MAC addresses as if they are transmitted in *reverse* order. This is different from how every other NC-SI command is parsed in the Linux kernel, even though the spec describes the format in the same way for every command. The *reason* for this is that I was able to test this code against the new 200G Broadcom NIC, which reports that it supports NC-SI 1.2 in Get Version ID and successfully responds to this command. It transmits the MAC addresses in reverse byte order. Nvidia's new 200G NIC doesn't support NC-SI 1.2 yet. I don't know how they're planning to implement it. Why did Broadcom do this? Well, they have some of the core NC-SI specification maintainers there, and at some point they must have decided that everyone (Linux kernel folks and Nvidia and previous Broadcom firmware authors) is interpreting the specification incorrectly. They created a 2nd edition of their OEM Get MAC Address command that returns the MAC address in reverse order: https://github.com/facebook/openbmc-linux/commit/a4a3a45809c6d43582a12a25bc= 45b95a79a4c034 That was never upstreamed, but it's supposed to replace the version we have in the upstream 6.x kernel today. So, to summarize: I chose the reverse encoding because that's what the first NC-SI 1.2 supported NIC is doing, and apparently that might be the correct way to interpret the spec as we go forward. Signed-off-by: Peter Delevoryas --- net/ncsi/ncsi-cmd.c | 3 ++- net/ncsi/ncsi-manage.c | 9 +++++++-- net/ncsi/ncsi-pkt.h | 10 ++++++++++ net/ncsi/ncsi-rsp.c | 45 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c index dda8b76b7798..7be177f55173 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -269,7 +269,8 @@ static struct ncsi_cmd_handler { { NCSI_PKT_CMD_GPS, 0, ncsi_cmd_handler_default }, { NCSI_PKT_CMD_OEM, -1, ncsi_cmd_handler_oem }, { NCSI_PKT_CMD_PLDM, 0, NULL }, - { NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default } + { NCSI_PKT_CMD_GPUUID, 0, ncsi_cmd_handler_default }, + { NCSI_PKT_CMD_GMCMA, 0, ncsi_cmd_handler_default } }; =20 static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c index f56795769893..bc1887a2543d 100644 --- a/net/ncsi/ncsi-manage.c +++ b/net/ncsi/ncsi-manage.c @@ -1038,11 +1038,16 @@ static void ncsi_configure_channel(struct ncsi_dev_= priv *ndp) case ncsi_dev_state_config_oem_gma: nd->state =3D ncsi_dev_state_config_clear_vids; =20 - nca.type =3D NCSI_PKT_CMD_OEM; nca.package =3D np->id; nca.channel =3D nc->id; ndp->pending_req_num =3D 1; - ret =3D ncsi_gma_handler(&nca, nc->version.mf_id); + if (nc->version.major >=3D 1 && nc->version.minor >=3D 2) { + nca.type =3D NCSI_PKT_CMD_GMCMA; + ret =3D ncsi_xmit_cmd(&nca); + } else { + nca.type =3D NCSI_PKT_CMD_OEM; + ret =3D ncsi_gma_handler(&nca, nc->version.mf_id); + } if (ret < 0) schedule_work(&ndp->work); =20 diff --git a/net/ncsi/ncsi-pkt.h b/net/ncsi/ncsi-pkt.h index c9d1da34dc4d..f2f3b5c1b941 100644 --- a/net/ncsi/ncsi-pkt.h +++ b/net/ncsi/ncsi-pkt.h @@ -338,6 +338,14 @@ struct ncsi_rsp_gpuuid_pkt { __be32 checksum; }; =20 +/* Get MC MAC Address */ +struct ncsi_rsp_gmcma_pkt { + struct ncsi_rsp_pkt_hdr rsp; + unsigned char address_count; + unsigned char reserved[3]; + unsigned char addresses[][ETH_ALEN]; +}; + /* AEN: Link State Change */ struct ncsi_aen_lsc_pkt { struct ncsi_aen_pkt_hdr aen; /* AEN header */ @@ -398,6 +406,7 @@ struct ncsi_aen_hncdsc_pkt { #define NCSI_PKT_CMD_GPUUID 0x52 /* Get package UUID */ #define NCSI_PKT_CMD_QPNPR 0x56 /* Query Pending NC PLDM request */ #define NCSI_PKT_CMD_SNPR 0x57 /* Send NC PLDM Reply */ +#define NCSI_PKT_CMD_GMCMA 0x58 /* Get MC MAC Address */ =20 =20 /* NCSI packet responses */ @@ -433,6 +442,7 @@ struct ncsi_aen_hncdsc_pkt { #define NCSI_PKT_RSP_GPUUID (NCSI_PKT_CMD_GPUUID + 0x80) #define NCSI_PKT_RSP_QPNPR (NCSI_PKT_CMD_QPNPR + 0x80) #define NCSI_PKT_RSP_SNPR (NCSI_PKT_CMD_SNPR + 0x80) +#define NCSI_PKT_RSP_GMCMA (NCSI_PKT_CMD_GMCMA + 0x80) =20 /* NCSI response code/reason */ #define NCSI_PKT_RSP_C_COMPLETED 0x0000 /* Command Completed */ diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c index 7a805b86a12d..28a042688d0b 100644 --- a/net/ncsi/ncsi-rsp.c +++ b/net/ncsi/ncsi-rsp.c @@ -1140,6 +1140,48 @@ static int ncsi_rsp_handler_netlink(struct ncsi_requ= est *nr) return ret; } =20 +static int ncsi_rsp_handler_gmcma(struct ncsi_request *nr) +{ + struct ncsi_dev_priv *ndp =3D nr->ndp; + struct net_device *ndev =3D ndp->ndev.dev; + struct ncsi_rsp_gmcma_pkt *rsp; + struct sockaddr saddr; + int ret =3D -1; + int i; + int j; + + rsp =3D (struct ncsi_rsp_gmcma_pkt *)skb_network_header(nr->rsp); + saddr.sa_family =3D ndev->type; + ndev->priv_flags |=3D IFF_LIVE_ADDR_CHANGE; + + netdev_warn(ndev, "NCSI: Received %d provisioned MAC addresses\n", + rsp->address_count); + for (i =3D 0; i < rsp->address_count; i++) { + netdev_warn(ndev, "NCSI: MAC address %d: " + "%02x:%02x:%02x:%02x:%02x:%02x\n", i, + rsp->addresses[i][5], rsp->addresses[i][4], + rsp->addresses[i][3], rsp->addresses[i][2], + rsp->addresses[i][1], rsp->addresses[i][0]); + } + + for (i =3D 0; i < rsp->address_count; i++) { + for (j =3D 0; j < ETH_ALEN; j++) { + saddr.sa_data[j] =3D rsp->addresses[i][ETH_ALEN - j - 1]; + } + ret =3D ndev->netdev_ops->ndo_set_mac_address(ndev, &saddr); + if (ret < 0) { + netdev_warn(ndev, "NCSI: Unable to assign %pM to " + "device\n", saddr.sa_data); + continue; + } + netdev_warn(ndev, "NCSI: Set MAC address to %pM\n", saddr.sa_data); + break; + } + + ndp->gma_flag =3D ret =3D=3D 0; + return ret; +} + static struct ncsi_rsp_handler { unsigned char type; int payload; @@ -1176,7 +1218,8 @@ static struct ncsi_rsp_handler { { NCSI_PKT_RSP_PLDM, -1, ncsi_rsp_handler_pldm }, { NCSI_PKT_RSP_GPUUID, 20, ncsi_rsp_handler_gpuuid }, { NCSI_PKT_RSP_QPNPR, -1, ncsi_rsp_handler_pldm }, - { NCSI_PKT_RSP_SNPR, -1, ncsi_rsp_handler_pldm } + { NCSI_PKT_RSP_SNPR, -1, ncsi_rsp_handler_pldm }, + { NCSI_PKT_RSP_GMCMA, -1, ncsi_rsp_handler_gmcma }, }; =20 int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev, --=20 2.30.2