/*
 * desc-devlink.c - devlink format descriptions
 *
 * Descriptions of devlink messages and attributes for pretty print.
 */

#include <linux/devlink.h>

#include "utils.h"
#include "prettymsg.h"

static const struct pretty_nla_desc __info_desc[] = {
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_DRIVER_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_SERIAL_NUMBER),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_VERSION_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_VERSION_VALUE),
};

static const struct pretty_nla_desc __snapshot_desc[] = {
	NLATTR_DESC_STRING(DEVLINK_ATTR_REGION_NAME),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_SIZE),
	NLATTR_DESC_U32(DEVLINK_ATTR_REGION_SNAPSHOT_ID),
};

static const struct pretty_nla_desc __snapshots_desc[] = {
	NLATTR_DESC_STRING(DEVLINK_ATTR_REGION_NAME),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_SIZE),
	NLATTR_DESC_U32(DEVLINK_ATTR_REGION_SNAPSHOT_ID),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_SNAPSHOT, snapshot),
};

static const struct pretty_nla_desc __chunk_desc[] = {
	NLATTR_DESC_BINARY(DEVLINK_ATTR_REGION_CHUNK_DATA),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_CHUNK_ADDR),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_CHUNK_LEN),
};

static const struct pretty_nla_desc __chunks_desc[] = {
	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_CHUNK, chunk)
};

static const struct pretty_nla_desc __attr_desc[] = {
	NLATTR_DESC_INVALID(DEVLINK_ATTR_UNSPEC),
	NLATTR_DESC_STRING(DEVLINK_ATTR_BUS_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_DEV_NAME),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_INDEX),
	NLATTR_DESC_U16(DEVLINK_ATTR_PORT_TYPE),
	NLATTR_DESC_U16(DEVLINK_ATTR_PORT_DESIRED_TYPE),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_NETDEV_IFINDEX),
	NLATTR_DESC_STRING(DEVLINK_ATTR_PORT_NETDEV_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_PORT_IBDEV_NAME),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_SPLIT_COUNT),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_SPLIT_GROUP),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_INDEX),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_SIZE),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_INGRESS_POOL_COUNT),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_EGRESS_POOL_COUNT),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_INGRESS_TC_COUNT),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_EGRESS_TC_COUNT),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_POOL_INDEX),
	NLATTR_DESC_U8(DEVLINK_ATTR_SB_POOL_TYPE),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_POOL_SIZE),
	NLATTR_DESC_U8(DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_THRESHOLD),
	NLATTR_DESC_U16(DEVLINK_ATTR_SB_TC_INDEX),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_OCC_CUR),
	NLATTR_DESC_U32(DEVLINK_ATTR_SB_OCC_MAX),
	NLATTR_DESC_U16(DEVLINK_ATTR_ESWITCH_MODE),
	NLATTR_DESC_U8(DEVLINK_ATTR_ESWITCH_INLINE_MODE),

	//DEVLINK_ATTR_DPIPE_TABLES,		/* nested */
	//DEVLINK_ATTR_DPIPE_TABLE,		/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_DPIPE_TABLE_NAME),
	NLATTR_DESC_U64(DEVLINK_ATTR_DPIPE_TABLE_SIZE),
	//DEVLINK_ATTR_DPIPE_TABLE_MATCHES,	/* nested */
	//DEVLINK_ATTR_DPIPE_TABLE_ACTIONS,	/* nested */
	NLATTR_DESC_U8(DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED),

	//DEVLINK_ATTR_DPIPE_ENTRIES,		/* nested */
	//DEVLINK_ATTR_DPIPE_ENTRY,		/* nested */
	NLATTR_DESC_U64(DEVLINK_ATTR_DPIPE_ENTRY_INDEX),
	//DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES,	/* nested */
	//DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES,	/* nested */
	NLATTR_DESC_U64(DEVLINK_ATTR_DPIPE_ENTRY_COUNTER),

	//DEVLINK_ATTR_DPIPE_MATCH,		/* nested */
	//DEVLINK_ATTR_DPIPE_MATCH_VALUE,		/* nested */
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_MATCH_TYPE),

	//DEVLINK_ATTR_DPIPE_ACTION,		/* nested */
	//DEVLINK_ATTR_DPIPE_ACTION_VALUE,	/* nested */
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_ACTION_TYPE),

	//DEVLINK_ATTR_DPIPE_VALUE,
	//DEVLINK_ATTR_DPIPE_VALUE_MASK,
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_VALUE_MAPPING),

	//DEVLINK_ATTR_DPIPE_HEADERS,		/* nested */
	//DEVLINK_ATTR_DPIPE_HEADER,		/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_DPIPE_HEADER_NAME),
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_HEADER_ID),
	//DEVLINK_ATTR_DPIPE_HEADER_FIELDS,	/* nested */
	NLATTR_DESC_U8(DEVLINK_ATTR_DPIPE_HEADER_GLOBAL),
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_HEADER_INDEX),

	//DEVLINK_ATTR_DPIPE_FIELD,		/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_DPIPE_FIELD_NAME),
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_FIELD_ID),
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH),
	NLATTR_DESC_U32(DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE),

	//DEVLINK_ATTR_PAD,

	NLATTR_DESC_U8(DEVLINK_ATTR_ESWITCH_ENCAP_MODE),
	//DEVLINK_ATTR_RESOURCE_LIST,		/* nested */
	//DEVLINK_ATTR_RESOURCE,			/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_RESOURCE_NAME),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_ID),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_SIZE),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_SIZE_NEW),
	NLATTR_DESC_U8(DEVLINK_ATTR_RESOURCE_SIZE_VALID),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_SIZE_MIN),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_SIZE_MAX),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_SIZE_GRAN),
	NLATTR_DESC_U8(DEVLINK_ATTR_RESOURCE_UNIT),
	NLATTR_DESC_U64(DEVLINK_ATTR_RESOURCE_OCC),
	NLATTR_DESC_U64(DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID),
	NLATTR_DESC_U64(DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS),

	NLATTR_DESC_U16(DEVLINK_ATTR_PORT_FLAVOUR),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_NUMBER),
	NLATTR_DESC_U32(DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER),

	//DEVLINK_ATTR_PARAM,			/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_PARAM_NAME),
	NLATTR_DESC_FLAG(DEVLINK_ATTR_PARAM_GENERIC),
	NLATTR_DESC_U8(DEVLINK_ATTR_PARAM_TYPE),
	//DEVLINK_ATTR_PARAM_VALUES_LIST,		/* nested */
	//DEVLINK_ATTR_PARAM_VALUE,		/* nested */
	NLATTR_DESC_BINARY(DEVLINK_ATTR_PARAM_VALUE_DATA),
	NLATTR_DESC_U8(DEVLINK_ATTR_PARAM_VALUE_CMODE),

	NLATTR_DESC_STRING(DEVLINK_ATTR_REGION_NAME),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_SIZE),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_SNAPSHOTS, snapshots),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_SNAPSHOT, snapshot),
	NLATTR_DESC_U32(DEVLINK_ATTR_REGION_SNAPSHOT_ID),

	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_CHUNKS, chunks),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_REGION_CHUNK, chunk),
	NLATTR_DESC_BINARY(DEVLINK_ATTR_REGION_CHUNK_DATA),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_CHUNK_ADDR),
	NLATTR_DESC_U64(DEVLINK_ATTR_REGION_CHUNK_LEN),

	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_DRIVER_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_SERIAL_NUMBER),
        NLATTR_DESC_NESTED(DEVLINK_ATTR_INFO_VERSION_FIXED, info),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_INFO_VERSION_RUNNING, info),
	NLATTR_DESC_NESTED(DEVLINK_ATTR_INFO_VERSION_STORED, info),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_VERSION_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_INFO_VERSION_VALUE),

	NLATTR_DESC_U32(DEVLINK_ATTR_SB_POOL_CELL_SIZE),

	//DEVLINK_ATTR_FMSG,			/* nested */
	NLATTR_DESC_FLAG(DEVLINK_ATTR_FMSG_OBJ_NEST_START),
	NLATTR_DESC_FLAG(DEVLINK_ATTR_FMSG_PAIR_NEST_START),
	NLATTR_DESC_FLAG(DEVLINK_ATTR_FMSG_ARR_NEST_START),
	NLATTR_DESC_FLAG(DEVLINK_ATTR_FMSG_NEST_END),
	NLATTR_DESC_STRING(DEVLINK_ATTR_FMSG_OBJ_NAME),
	NLATTR_DESC_U8(DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE),
	NLATTR_DESC_BINARY(DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA),	/* dynamic */

	//DEVLINK_ATTR_HEALTH_REPORTER,			/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_HEALTH_REPORTER_NAME),
	NLATTR_DESC_U8(DEVLINK_ATTR_HEALTH_REPORTER_STATE),
	NLATTR_DESC_U64(DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT),
	NLATTR_DESC_U64(DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT),
	NLATTR_DESC_U64(DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS),
	NLATTR_DESC_U64(DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD),
	NLATTR_DESC_U8(DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER),

	NLATTR_DESC_STRING(DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME),
	NLATTR_DESC_STRING(DEVLINK_ATTR_FLASH_UPDATE_COMPONENT),
	NLATTR_DESC_STRING(DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG),
	NLATTR_DESC_U64(DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE),
	NLATTR_DESC_U64(DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL),

	NLATTR_DESC_U16(DEVLINK_ATTR_PORT_PCI_PF_NUMBER),
	NLATTR_DESC_U16(DEVLINK_ATTR_PORT_PCI_VF_NUMBER),

	//DEVLINK_ATTR_STATS,				/* nested */

	NLATTR_DESC_STRING(DEVLINK_ATTR_TRAP_NAME),
	NLATTR_DESC_U8(DEVLINK_ATTR_TRAP_ACTION),
	NLATTR_DESC_U8(DEVLINK_ATTR_TRAP_TYPE),
	NLATTR_DESC_FLAG(DEVLINK_ATTR_TRAP_GENERIC),
	//DEVLINK_ATTR_TRAP_METADATA,			/* nested */
	NLATTR_DESC_STRING(DEVLINK_ATTR_TRAP_GROUP_NAME),

	NLATTR_DESC_U8(DEVLINK_ATTR_RELOAD_FAILED),
	NLATTR_DESC_U64(DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS_NS),
};

const struct pretty_nlmsg_desc devlink_msg_desc[] = {
	NLMSG_DESC_INVALID(DEVLINK_CMD_UNSPEC),
	NLMSG_DESC(DEVLINK_CMD_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_SPLIT, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_UNSPLIT, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_POOL_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_POOL_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_POOL_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_POOL_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_PORT_POOL_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_PORT_POOL_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_PORT_POOL_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_PORT_POOL_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_TC_POOL_BIND_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_TC_POOL_BIND_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_TC_POOL_BIND_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_TC_POOL_BIND_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_OCC_SNAPSHOT, attr),
	NLMSG_DESC(DEVLINK_CMD_SB_OCC_MAX_CLEAR, attr),
	NLMSG_DESC(DEVLINK_CMD_ESWITCH_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_ESWITCH_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_ESWITCH_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_ESWITCH_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_DPIPE_TABLE_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_DPIPE_ENTRIES_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_DPIPE_HEADERS_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_RESOURCE_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_RESOURCE_DUMP, attr),
	NLMSG_DESC(DEVLINK_CMD_RELOAD, attr),
	NLMSG_DESC(DEVLINK_CMD_PARAM_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_PARAM_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_PARAM_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_PARAM_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_REGION_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_REGION_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_REGION_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_REGION_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_REGION_READ, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_PARAM_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_PARAM_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_PARAM_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_PORT_PARAM_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_INFO_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_RECOVER, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR, attr),
	NLMSG_DESC(DEVLINK_CMD_FLASH_UPDATE, attr),
	NLMSG_DESC(DEVLINK_CMD_FLASH_UPDATE_END, attr),
	NLMSG_DESC(DEVLINK_CMD_FLASH_UPDATE_STATUS, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_DEL, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_GROUP_GET, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_GROUP_SET, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_GROUP_NEW, attr),
	NLMSG_DESC(DEVLINK_CMD_TRAP_GROUP_DEL, attr),
};

const unsigned int devlink_msg_n_desc = ARRAY_SIZE(devlink_msg_desc);
