From nobody Sun Feb 8 23:04:07 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 261422DCC05 for ; Fri, 6 Feb 2026 15:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770392574; cv=none; b=DE5B2KBCSJAAct6lm7yj0sRCK5EODx7EjSkQVZ37zCIzcIENinUChLV++qvBmbCWvHs8eBkFPtPU+dkKhaDztCXzGCLsXtb02pjbhx4CLOd9felabXNWugJ9f6KBNzNa4ErktinzeRwQFnHcGjKC8S4TYsL3FguN9BiSLohTHa0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770392574; c=relaxed/simple; bh=nk6FBo5oHu46xrfexvRbcHaZ0aBYk3+ins4qA5pSGSc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CIaCA+XUsaAV0PlpoRs+0uf4MbVY+m2ZrDwxvxS0PzkwDeC7ejWrYqR9YN0+eG/OKRPy0ZDax05lKOCmZFnF0a9UQsZWq4BqNcL0VmKu4rh0tz1wDYkQsniOSzdeuMeM7o4tudOCN8wwfutbWcQBOnU6WmVyZIWR1Vf+U3At4pk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HU0wY6hW; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HU0wY6hW" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-8c70c6b2bcaso226535285a.3 for ; Fri, 06 Feb 2026 07:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770392573; x=1770997373; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4CrpLjsEJ97mU1tWann7pmgOTRqhJQHSEffGujRvSNk=; b=HU0wY6hWTxEEE0K9XCjtI/Rk365WjHwSEXj+oL1zebQJxhqUGPH4noh9H/CppEiDP1 1PoGUlavq9qs2TqI9JQKdWm6u+pW3fhBggU2zJeM1V4OhvUYTWd41xK5B/gKnI48YkxF YRQNCLBUa8cDqeLNYjdmXoFURFy/52eQblmnlbFmIsFO5RpblMgk3KEXK5Bn+jLnUBTK 78PjEZWwH59OO+3tQbHjEhynMOHHJJPluRPj0ylSQTRJKTZkB6O9yWtt5yZxhuiiz9k/ JgEFHkNnCTVNW2VmnBYEoAaahsLH8FdW+RP0CUD7SSp7z6te+CMFgTcupQVD+IZXhRt0 +fuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770392573; x=1770997373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4CrpLjsEJ97mU1tWann7pmgOTRqhJQHSEffGujRvSNk=; b=Yu8VB7teaREw4VooKMALBeDRLlBEzC9HmEBIEwe/8ZpkC2NVP1gZcn2BTvJRbPzjNg rdnUYrxxh2r+tqg1HUA0di7vr6nisnTHGcgp3pPy5ggQxDeon+S+hbMT+RpKaRV8tSmN BFhUViayYNPIVDyZMVFNlSLbTIBH+HIhHHaZBgRij5ppAfhk1bdOEZTia1iX/qXhbsAr afvUn9XvuegRsJvcqqS6wK1pm+BYzUfpu4kFUxaPR1Ku+DtIK9DFazVftUoS46nejdCv esO8pT2yJWwZD7eZEuHhE0Q5G3HawsOOZD/mvnLNuDnYCghwkE97PQTANkXGNhT879ur 8/+Q== X-Forwarded-Encrypted: i=1; AJvYcCW9vdG30HwlU81MucM8APg1vW9l7YncM6hJFU9mHDWjl9JOPjNMNVvjNLv6cJiFqAfLMIcDv/XfARig1CQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyUGOP6lkWtnEiWj0zjp+QpqGkHaZ+boO9j/c1rh/wUFkprh6w0 CzyLaaBmT3Z8pOgQvMlb70xMknrTzNUqpAKo50ClvvNdFyOqPRpGx2DE X-Gm-Gg: AZuq6aILL/WmuirPhfyjlLBNUCEh3dn71piyrm1C4qwrY9Uyw4Tgefv4Nhi3FaRqC4w tQL0TxovENaaAx3l/N1mJL4VmbRnCPg6kAOQMfljn/3+DxOA667PVHQWALIZw9rvNGXA4UaITpg wjm1k4Jr+fH4l2uxVQgaNU4Ybg1IX4AfPOIgX6hOGjQQ/gZWhq/aGHG4+29vg4zBU6fNl7BRDYh lg8cbAErOHZzSVXmEalGVVZvodarvbg6uPT3UlsOPWQmoMo7+ic9hIvksQx4rdWecU6oG3nhfxG OLUBEbnyAmJhYgEgPJHkAcTLf4AZ8dulPkEnUtBOWFrNFPP85JrDW1+cSm5aPYCBpFvYqkM9IRn nAU2AeQHm5rHhF9azuVynjoMEeVe9GVVy6RiSnS2/RcBJyRTTAWw6OWFUHZULGM/i0BGC/SCceX JxDrAzUKtvoemMXQHOreVzpMbWjXVvIHU2eDKdWCyTO4ZN X-Received: by 2002:a05:620a:462c:b0:8b2:598d:6e66 with SMTP id af79cd13be357-8caef30bf03mr378659585a.22.1770392573045; Fri, 06 Feb 2026 07:42:53 -0800 (PST) Received: from PF5YBGDS.localdomain ([163.114.130.1]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8caf9eea0c0sm181499185a.42.2026.02.06.07.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 07:42:52 -0800 (PST) From: mike.marciniszyn@gmail.com To: Alexander Duyck , Jakub Kicinski , kernel-team@meta.com, Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Russell King , Jacob Keller , Mohsin Bashir , Lee Trager , "Mike Marciniszyn (Meta)" , Dan Carpenter , Pei Xiao , Stanislav Fomichev , Kuniyuki Iwashima , Samiullah Khawaja , Ahmed Zaki , Alexander Lobakin Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v12 4/5] eth fbnic: TLV support for use by MBX self test Date: Fri, 6 Feb 2026 10:42:44 -0500 Message-ID: <20260206154246.814-5-mike.marciniszyn@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260206154246.814-1-mike.marciniszyn@gmail.com> References: <20260206154246.814-1-mike.marciniszyn@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Marciniszyn (Meta)" The TLV (Type-Value-Length) self uses a known set of data to create a TLV message. These routines support the MBX self test by creating the test messages and parsing the response message coming back from the firmware. Signed-off-by: Mike Marciniszyn (Meta) --- diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c b/drivers/net/ethe= rnet/meta/fbnic/fbnic_tlv.c index 517ed8b2f1cb..c55d4f76a5fc 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c @@ -551,6 +551,172 @@ int fbnic_tlv_parser_error(void *opaque, struct fbnic= _tlv_msg **results) return -EBADMSG; } +#define FBNIC_TLV_TEST_STRING_LEN 32 + +struct fbnic_tlv_test { + u64 test_u64; + s64 test_s64; + u32 test_u32; + s32 test_s32; + u16 test_u16; + s16 test_s16; + u8 test_mac[ETH_ALEN]; + u8 test_mac_array[4][ETH_ALEN]; + u8 test_true; + u8 test_false; + char test_string[FBNIC_TLV_TEST_STRING_LEN]; +}; + +static struct fbnic_tlv_test test_struct; + +const struct fbnic_tlv_index fbnic_tlv_test_index[] =3D { + FBNIC_TLV_ATTR_U64(FBNIC_TLV_TEST_MSG_U64), + FBNIC_TLV_ATTR_S64(FBNIC_TLV_TEST_MSG_S64), + FBNIC_TLV_ATTR_U32(FBNIC_TLV_TEST_MSG_U32), + FBNIC_TLV_ATTR_S32(FBNIC_TLV_TEST_MSG_S32), + FBNIC_TLV_ATTR_U32(FBNIC_TLV_TEST_MSG_U16), + FBNIC_TLV_ATTR_S32(FBNIC_TLV_TEST_MSG_S16), + FBNIC_TLV_ATTR_MAC_ADDR(FBNIC_TLV_TEST_MSG_MAC_ADDR), + FBNIC_TLV_ATTR_FLAG(FBNIC_TLV_TEST_MSG_FLAG_TRUE), + FBNIC_TLV_ATTR_FLAG(FBNIC_TLV_TEST_MSG_FLAG_FALSE), + FBNIC_TLV_ATTR_STRING(FBNIC_TLV_TEST_MSG_STRING, + FBNIC_TLV_TEST_STRING_LEN), + FBNIC_TLV_ATTR_ARRAY(FBNIC_TLV_TEST_MSG_ARRAY), + FBNIC_TLV_ATTR_NESTED(FBNIC_TLV_TEST_MSG_NESTED), + FBNIC_TLV_ATTR_LAST +}; + +static void fbnic_tlv_test_struct_init(void) +{ + int i =3D FBNIC_TLV_TEST_STRING_LEN - 1; + + /* Populate the struct with random data */ + get_random_once(&test_struct, + offsetof(struct fbnic_tlv_test, test_string) + i); + + /* Force true/false to their expected values */ + test_struct.test_false =3D false; + test_struct.test_true =3D true; + + /* Convert test_string to a true ASCII string */ + test_struct.test_string[i] =3D '\0'; + while (i--) { + /* Force characters into displayable range */ + if (test_struct.test_string[i] < 64 || + test_struct.test_string[i] >=3D 96) { + test_struct.test_string[i] %=3D 32; + test_struct.test_string[i] +=3D 64; + } + } +} + +static int fbnic_tlv_test_attr_data(struct fbnic_tlv_msg *msg) +{ + struct fbnic_tlv_msg *array; + int err, i; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U64, + test_struct.test_u64); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S64, + test_struct.test_s64); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U32, + test_struct.test_u32); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S32, + test_struct.test_s32); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U16, + test_struct.test_u16); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S16, + test_struct.test_s16); + if (err) + return err; + + err =3D fbnic_tlv_attr_put_value(msg, FBNIC_TLV_TEST_MSG_MAC_ADDR, + test_struct.test_mac, ETH_ALEN); + if (err) + return err; + + /* Start MAC address array */ + array =3D fbnic_tlv_attr_nest_start(msg, FBNIC_TLV_TEST_MSG_ARRAY); + if (!array) + return -ENOSPC; + + for (i =3D 0; i < 4; i++) { + err =3D fbnic_tlv_attr_put_value(array, + FBNIC_TLV_TEST_MSG_MAC_ADDR, + test_struct.test_mac_array[i], + ETH_ALEN); + if (err) + return err; + } + + /* Close array */ + fbnic_tlv_attr_nest_stop(msg); + + err =3D fbnic_tlv_attr_put_flag(msg, FBNIC_TLV_TEST_MSG_FLAG_TRUE); + if (err) + return err; + + return fbnic_tlv_attr_put_string(msg, FBNIC_TLV_TEST_MSG_STRING, + test_struct.test_string); +} + +/** + * fbnic_tlv_test_create - Allocate a test message and fill it w/ data + * @fbd: FBNIC device structure + * + * Return: NULL on failure to allocate or pointer to new TLV test message. + **/ +struct fbnic_tlv_msg *fbnic_tlv_test_create(struct fbnic_dev *fbd) +{ + struct fbnic_tlv_msg *msg, *nest; + int err; + + msg =3D fbnic_tlv_msg_alloc(FBNIC_TLV_MSG_ID_TEST); + if (!msg) + return NULL; + + /* Randomize struct data */ + fbnic_tlv_test_struct_init(); + + /* Add first level of data to message */ + err =3D fbnic_tlv_test_attr_data(msg); + if (err) + goto free_message; + + /* Start second level nested */ + nest =3D fbnic_tlv_attr_nest_start(msg, FBNIC_TLV_TEST_MSG_NESTED); + if (!nest) + goto free_message; + + /* Add nested data */ + err =3D fbnic_tlv_test_attr_data(nest); + if (err) + goto free_message; + + /* Close nest and report full message */ + fbnic_tlv_attr_nest_stop(msg); + + return msg; +free_message: + free_page((unsigned long)msg); + return NULL; +} + void fbnic_tlv_attr_addr_copy(u8 *dest, struct fbnic_tlv_msg *src) { u8 *mac_addr; @@ -558,3 +724,113 @@ void fbnic_tlv_attr_addr_copy(u8 *dest, struct fbnic_= tlv_msg *src) mac_addr =3D fbnic_tlv_attr_get_value_ptr(src); memcpy(dest, mac_addr, ETH_ALEN); } + +/** + * fbnic_tlv_parser_test_attr - Function loading test attributes into stru= cture + * @str: Test structure to load + * @results: Pointer to results array + * + * Copies attributes into structure. Any attribute that doesn't exist in t= he + * results array is not populated. + **/ +static void fbnic_tlv_parser_test_attr(struct fbnic_tlv_test *str, + struct fbnic_tlv_msg **results) +{ + struct fbnic_tlv_msg *array_results[4]; + struct fbnic_tlv_msg *attr; + char *string =3D NULL; + int i, err; + + str->test_u64 =3D fta_get_uint(results, FBNIC_TLV_TEST_MSG_U64); + str->test_u32 =3D fta_get_uint(results, FBNIC_TLV_TEST_MSG_U32); + str->test_u16 =3D fta_get_uint(results, FBNIC_TLV_TEST_MSG_U16); + + str->test_s64 =3D fta_get_sint(results, FBNIC_TLV_TEST_MSG_S64); + str->test_s32 =3D fta_get_sint(results, FBNIC_TLV_TEST_MSG_S32); + str->test_s16 =3D fta_get_sint(results, FBNIC_TLV_TEST_MSG_S16); + + attr =3D results[FBNIC_TLV_TEST_MSG_MAC_ADDR]; + if (attr) + fbnic_tlv_attr_addr_copy(str->test_mac, attr); + + attr =3D results[FBNIC_TLV_TEST_MSG_ARRAY]; + if (attr) { + int len =3D le16_to_cpu(attr->hdr.len) / sizeof(u32) - 1; + + err =3D fbnic_tlv_attr_parse_array(&attr[1], len, + array_results, + fbnic_tlv_test_index, + FBNIC_TLV_TEST_MSG_MAC_ADDR, + 4); + if (!err) { + for (i =3D 0; i < 4 && array_results[i]; i++) + fbnic_tlv_attr_addr_copy(str->test_mac_array[i], + array_results[i]); + } + } + + str->test_true =3D !!results[FBNIC_TLV_TEST_MSG_FLAG_TRUE]; + str->test_false =3D !!results[FBNIC_TLV_TEST_MSG_FLAG_FALSE]; + + attr =3D results[FBNIC_TLV_TEST_MSG_STRING]; + if (attr) { + string =3D fbnic_tlv_attr_get_value_ptr(attr); + strscpy(str->test_string, string, FBNIC_TLV_TEST_STRING_LEN); + } +} + +static void fbnic_tlv_test_dump(struct fbnic_tlv_test *value, char *prefix) +{ + print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 16, 1, + value, sizeof(*value), true); +} + +/** + * fbnic_tlv_parser_test - Function for parsing and testing test message + * @opaque: Unused value + * @results: Results of parser output + * + * Return: negative value on error, or 0 on success. + * + * Parses attributes to structures and compares the structure to the + * expected test value that should have been used to populate the message. + * + * Used to verify message generation and parser are working correctly. + **/ +int fbnic_tlv_parser_test(void *opaque, struct fbnic_tlv_msg **results) +{ + struct fbnic_tlv_msg *nest_results[FBNIC_TLV_RESULTS_MAX] =3D { 0 }; + struct fbnic_tlv_test result_struct; + struct fbnic_tlv_msg *attr; + int err; + + memset(&result_struct, 0, sizeof(result_struct)); + fbnic_tlv_parser_test_attr(&result_struct, results); + + if (memcmp(&test_struct, &result_struct, sizeof(test_struct))) { + fbnic_tlv_test_dump(&result_struct, "fbnic: found - "); + fbnic_tlv_test_dump(&test_struct, "fbnic: expected - "); + return -EINVAL; + } + + attr =3D results[FBNIC_TLV_TEST_MSG_NESTED]; + if (!attr) + return -EINVAL; + + err =3D fbnic_tlv_attr_parse(&attr[1], + le16_to_cpu(attr->hdr.len) / sizeof(u32) - 1, + nest_results, fbnic_tlv_test_index); + if (err) + return err; + + memset(&result_struct, 0, sizeof(result_struct)); + fbnic_tlv_parser_test_attr(&result_struct, nest_results); + + if (memcmp(&test_struct, &result_struct, sizeof(test_struct))) { + fbnic_tlv_test_dump(&result_struct, "fbnic: found - "); + fbnic_tlv_test_dump(&test_struct, "fbnic: expected - "); + return -EINVAL; + } + + return 0; +} diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h b/drivers/net/ethe= rnet/meta/fbnic/fbnic_tlv.h index 3508b46ebdd0..ee663a03b2aa 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_tlv.h @@ -8,6 +8,7 @@ #include #include #include +struct fbnic_dev; #define FBNIC_TLV_MSG_ALIGN(len) ALIGN(len, sizeof(u32)) #define FBNIC_TLV_MSG_SIZE(len) \ @@ -153,6 +154,31 @@ int fbnic_tlv_parser_error(void *opaque, struct fbnic_= tlv_msg **results); #define fta_get_str(_results, _id, _dst, _dstsize) \ fbnic_tlv_attr_get_string(_results[_id], _dst, _dstsize) +#define FBNIC_TLV_MSG_ID_TEST 0 + +enum fbnic_tlv_test_attr_id { + FBNIC_TLV_TEST_MSG_U64, + FBNIC_TLV_TEST_MSG_S64, + FBNIC_TLV_TEST_MSG_U32, + FBNIC_TLV_TEST_MSG_S32, + FBNIC_TLV_TEST_MSG_U16, + FBNIC_TLV_TEST_MSG_S16, + FBNIC_TLV_TEST_MSG_MAC_ADDR, + FBNIC_TLV_TEST_MSG_FLAG_TRUE, + FBNIC_TLV_TEST_MSG_FLAG_FALSE, + FBNIC_TLV_TEST_MSG_STRING, + FBNIC_TLV_TEST_MSG_NESTED, + FBNIC_TLV_TEST_MSG_ARRAY, + FBNIC_TLV_TEST_MSG_MAX +}; + +extern const struct fbnic_tlv_index fbnic_tlv_test_index[]; +struct fbnic_tlv_msg *fbnic_tlv_test_create(struct fbnic_dev *fbd); +int fbnic_tlv_parser_test(void *opaque, struct fbnic_tlv_msg **results); + +#define FBNIC_TLV_MSG_TEST \ + FBNIC_TLV_PARSER(TEST, fbnic_tlv_test_index, \ + fbnic_tlv_parser_test) #define FBNIC_TLV_MSG_ERROR \ FBNIC_TLV_PARSER(UNKNOWN, NULL, fbnic_tlv_parser_error) #endif /* _FBNIC_TLV_H_ */ -- 2.43.0