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

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/meta/fbnic/fbnic_tlv.h
Extension
.h
Size
6688 bytes
Lines
186
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_hdr {
#if defined(__LITTLE_ENDIAN_BITFIELD)
	u16 type		: 12; /* 0 .. 11  Type / ID */
	u16 rsvd		: 2;  /* 12 .. 13 Reserved for future use */
	u16 cannot_ignore	: 1;  /* 14	  Attribute can be ignored */
	u16 is_msg		: 1;  /* 15	  Header belongs to message */
#elif defined(__BIG_ENDIAN_BITFIELD)
	u16 is_msg		: 1;  /* 15	  Header belongs to message */
	u16 cannot_ignore	: 1;  /* 14	  Attribute can be ignored */
	u16 rsvd		: 2;  /* 13 .. 12 Reserved for future use */
	u16 type		: 12; /* 11 .. 0  Type / ID */
#else
#error "Missing defines from byteorder.h"
#endif
	__le16 len;		/* 16 .. 32	length including TLV header */
};

#define FBNIC_TLV_RESULTS_MAX		32

struct fbnic_tlv_msg {
	struct fbnic_tlv_hdr	hdr;
	__le32			value[];
};

#define FBNIC_TLV_MSG_ID_UNKNOWN		USHRT_MAX

enum fbnic_tlv_type {
	FBNIC_TLV_STRING,
	FBNIC_TLV_FLAG,
	FBNIC_TLV_UNSIGNED,
	FBNIC_TLV_SIGNED,
	FBNIC_TLV_BINARY,
	FBNIC_TLV_NESTED,
	FBNIC_TLV_ARRAY,
	__FBNIC_TLV_MAX_TYPE
};

/* TLV Index
 * Defines the relationship between the attribute IDs and their types.
 * For each entry in the index there will be a size and type associated
 * with it so that we can use this to parse the data and verify it matches
 * the expected layout.
 */
struct fbnic_tlv_index {
	u16			id;
	u16			len;
	enum fbnic_tlv_type	type;
};

#define TLV_MAX_DATA			((PAGE_SIZE - 512) & 0xFFFF)
#define FBNIC_TLV_ATTR_ID_UNKNOWN	USHRT_MAX
#define FBNIC_TLV_ATTR_STRING(id, len)	{ id, len, FBNIC_TLV_STRING }
#define FBNIC_TLV_ATTR_FLAG(id)		{ id, 0, FBNIC_TLV_FLAG }
#define FBNIC_TLV_ATTR_U32(id)		{ id, sizeof(u32), FBNIC_TLV_UNSIGNED }
#define FBNIC_TLV_ATTR_U64(id)		{ id, sizeof(u64), FBNIC_TLV_UNSIGNED }
#define FBNIC_TLV_ATTR_S32(id)		{ id, sizeof(s32), FBNIC_TLV_SIGNED }
#define FBNIC_TLV_ATTR_S64(id)		{ id, sizeof(s64), FBNIC_TLV_SIGNED }
#define FBNIC_TLV_ATTR_MAC_ADDR(id)	{ id, ETH_ALEN, FBNIC_TLV_BINARY }
#define FBNIC_TLV_ATTR_NESTED(id)	{ id, 0, FBNIC_TLV_NESTED }
#define FBNIC_TLV_ATTR_ARRAY(id)	{ id, 0, FBNIC_TLV_ARRAY }
#define FBNIC_TLV_ATTR_RAW_DATA(id)	{ id, TLV_MAX_DATA, FBNIC_TLV_BINARY }
#define FBNIC_TLV_ATTR_LAST		{ FBNIC_TLV_ATTR_ID_UNKNOWN, 0, 0 }

struct fbnic_tlv_parser {
	u16				id;
	const struct fbnic_tlv_index	*attr;
	int				(*func)(void *opaque,
						struct fbnic_tlv_msg **results);
};

#define FBNIC_TLV_PARSER(id, attr, func) { FBNIC_TLV_MSG_ID_##id, attr, func }

static inline void *
fbnic_tlv_attr_get_value_ptr(struct fbnic_tlv_msg *attr)
{
	return (void *)&attr->value[0];
}

static inline bool fbnic_tlv_attr_get_bool(struct fbnic_tlv_msg *attr)
{
	return !!attr;
}

u64 fbnic_tlv_attr_get_unsigned(struct fbnic_tlv_msg *attr, u64 def);
s64 fbnic_tlv_attr_get_signed(struct fbnic_tlv_msg *attr, s64 def);
ssize_t fbnic_tlv_attr_get_string(struct fbnic_tlv_msg *attr, char *dst,
				  size_t dstsize);
struct fbnic_tlv_msg *fbnic_tlv_msg_alloc(u16 msg_id);
int fbnic_tlv_attr_put_flag(struct fbnic_tlv_msg *msg, const u16 attr_id);
int fbnic_tlv_attr_put_value(struct fbnic_tlv_msg *msg, const u16 attr_id,

Annotation

Implementation Notes