drivers/net/ethernet/meta/fbnic/fbnic_tlv.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/meta/fbnic/fbnic_tlv.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/meta/fbnic/fbnic_tlv.c
Extension
.c
Size
23036 bytes
Lines
837
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

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[] = {
	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 = 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 = false;
	test_struct.test_true = true;

	/* Convert test_string to a true ASCII string */
	test_struct.test_string[i] = '\0';
	while (i--) {
		/* Force characters into displayable range */
		if (test_struct.test_string[i] < 64 ||
		    test_struct.test_string[i] >= 96) {
			test_struct.test_string[i] %= 32;
			test_struct.test_string[i] += 64;
		}
	}
}

static int fbnic_tlv_test_attr_data(struct fbnic_tlv_msg *msg)
{
	struct fbnic_tlv_msg *array;
	int err, i;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U64,
				     test_struct.test_u64);
	if (err)
		return err;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S64,
				     test_struct.test_s64);
	if (err)
		return err;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U32,
				     test_struct.test_u32);
	if (err)
		return err;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S32,
				     test_struct.test_s32);
	if (err)
		return err;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_U16,
				     test_struct.test_u16);
	if (err)
		return err;

	err = fbnic_tlv_attr_put_int(msg, FBNIC_TLV_TEST_MSG_S16,
				     test_struct.test_s16);
	if (err)

Annotation

Implementation Notes