2060 lines · 71.8 KB · C
RawDownload
/* SPDX-License-Identifier: GPL-2.0-or-later *//* * include/net/devlink.h - Network physical device Netlink interface * Copyright (c) 2016 Mellanox Technologies. All rights reserved. * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com> */#ifndef _NET_DEVLINK_H_#define _NET_DEVLINK_H_ #include <linux/device.h>#include <linux/slab.h>#include <linux/gfp.h>#include <linux/list.h>#include <linux/netdevice.h>#include <linux/spinlock.h>#include <linux/workqueue.h>#include <linux/refcount.h>#include <net/net_namespace.h>#include <net/flow_offload.h>#include <uapi/linux/devlink.h>#include <linux/xarray.h>#include <linux/firmware.h> struct devlink;struct devlink_linecard; struct devlink_port_phys_attrs {	u32 port_number; /* Same value as "split group".			  * A physical port which is visible to the user			  * for a given port flavour.			  */	u32 split_subport_number; /* If the port is split, this is the number of subport. */}; /** * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes * @controller: Associated controller number * @pf: Associated PCI PF number for this port. * @external: when set, indicates if a port is for an external controller */struct devlink_port_pci_pf_attrs {	u32 controller;	u16 pf;	u8 external:1;}; /** * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes * @controller: Associated controller number * @pf: Associated PCI PF number for this port. * @vf: Associated PCI VF for of the PCI PF for this port. * @external: when set, indicates if a port is for an external controller */struct devlink_port_pci_vf_attrs {	u32 controller;	u16 pf;	u16 vf;	u8 external:1;}; /** * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes * @controller: Associated controller number * @sf: Associated PCI SF for of the PCI PF for this port. * @pf: Associated PCI PF number for this port. * @external: when set, indicates if a port is for an external controller */struct devlink_port_pci_sf_attrs {	u32 controller;	u32 sf;	u16 pf;	u8 external:1;}; /** * struct devlink_port_attrs - devlink port object * @flavour: flavour of the port * @split: indicates if this is split port * @splittable: indicates if the port can be split. * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink. * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL * @phys: physical port attributes * @pci_pf: PCI PF port attributes * @pci_vf: PCI VF port attributes * @pci_sf: PCI SF port attributes */struct devlink_port_attrs {	u8 split:1,	   splittable:1;	u32 lanes;	enum devlink_port_flavour flavour;	struct netdev_phys_item_id switch_id;	union {		struct devlink_port_phys_attrs phys;		struct devlink_port_pci_pf_attrs pci_pf;		struct devlink_port_pci_vf_attrs pci_vf;		struct devlink_port_pci_sf_attrs pci_sf;	};}; struct devlink_rate {	struct list_head list;	enum devlink_rate_type type;	struct devlink *devlink;	void *priv;	u64 tx_share;	u64 tx_max; 	struct devlink_rate *parent;	union {		struct devlink_port *devlink_port;		struct {			char *name;			refcount_t refcnt;		};	}; 	u32 tx_priority;	u32 tx_weight;}; struct devlink_port {	struct list_head list;	struct list_head region_list;	struct devlink *devlink;	const struct devlink_port_ops *ops;	unsigned int index;	spinlock_t type_lock; /* Protects type and type_eth/ib			       * structures consistency.			       */	enum devlink_port_type type;	enum devlink_port_type desired_type;	union {		struct {			struct net_device *netdev;			int ifindex;			char ifname[IFNAMSIZ];		} type_eth;		struct {			struct ib_device *ibdev;		} type_ib;	};	struct devlink_port_attrs attrs;	u8 attrs_set:1,	   switch_port:1,	   registered:1,	   initialized:1;	struct delayed_work type_warn_dw;	struct list_head reporter_list; 	struct devlink_rate *devlink_rate;	struct devlink_linecard *linecard;	u32 rel_index;}; struct devlink_port_new_attrs {	enum devlink_port_flavour flavour;	unsigned int port_index;	u32 controller;	u32 sfnum;	u16 pfnum;	u8 port_index_valid:1,	   controller_valid:1,	   sfnum_valid:1;}; /** * struct devlink_linecard_ops - Linecard operations * @provision: callback to provision the linecard slot with certain *	       type of linecard. As a result of this operation, *	       driver is expected to eventually (could be after *	       the function call returns) call one of: *	       devlink_linecard_provision_set() *	       devlink_linecard_provision_fail() * @unprovision: callback to unprovision the linecard slot. As a result *		 of this operation, driver is expected to eventually *		 (could be after the function call returns) call *	         devlink_linecard_provision_clear() *	         devlink_linecard_provision_fail() * @same_provision: callback to ask the driver if linecard is already *                  provisioned in the same way user asks this linecard to be *                  provisioned. * @types_count: callback to get number of supported types * @types_get: callback to get next type in list */struct devlink_linecard_ops {	int (*provision)(struct devlink_linecard *linecard, void *priv,			 const char *type, const void *type_priv,			 struct netlink_ext_ack *extack);	int (*unprovision)(struct devlink_linecard *linecard, void *priv,			   struct netlink_ext_ack *extack);	bool (*same_provision)(struct devlink_linecard *linecard, void *priv,			       const char *type, const void *type_priv);	unsigned int (*types_count)(struct devlink_linecard *linecard,				    void *priv);	void (*types_get)(struct devlink_linecard *linecard,			  void *priv, unsigned int index, const char **type,			  const void **type_priv);}; struct devlink_sb_pool_info {	enum devlink_sb_pool_type pool_type;	u32 size;	enum devlink_sb_threshold_type threshold_type;	u32 cell_size;}; /** * struct devlink_dpipe_field - dpipe field object * @name: field name * @id: index inside the headers field array * @bitwidth: bitwidth * @mapping_type: mapping type */struct devlink_dpipe_field {	const char *name;	unsigned int id;	unsigned int bitwidth;	enum devlink_dpipe_field_mapping_type mapping_type;}; /** * struct devlink_dpipe_header - dpipe header object * @name: header name * @id: index, global/local determined by global bit * @fields: fields * @fields_count: number of fields * @global: indicates if header is shared like most protocol header *	    or driver specific */struct devlink_dpipe_header {	const char *name;	unsigned int id;	struct devlink_dpipe_field *fields;	unsigned int fields_count;	bool global;}; /** * struct devlink_dpipe_match - represents match operation * @type: type of match * @header_index: header index (packets can have several headers of same *		  type like in case of tunnels) * @header: header * @field_id: field index */struct devlink_dpipe_match {	enum devlink_dpipe_match_type type;	unsigned int header_index;	struct devlink_dpipe_header *header;	unsigned int field_id;}; /** * struct devlink_dpipe_action - represents action operation * @type: type of action * @header_index: header index (packets can have several headers of same *		  type like in case of tunnels) * @header: header * @field_id: field index */struct devlink_dpipe_action {	enum devlink_dpipe_action_type type;	unsigned int header_index;	struct devlink_dpipe_header *header;	unsigned int field_id;}; /** * struct devlink_dpipe_value - represents value of match/action * @action: action * @match: match * @mapping_value: in case the field has some mapping this value *                 specified the mapping value * @mapping_valid: specify if mapping value is valid * @value_size: value size * @value: value * @mask: bit mask */struct devlink_dpipe_value {	union {		struct devlink_dpipe_action *action;		struct devlink_dpipe_match *match;	};	unsigned int mapping_value;	bool mapping_valid;	unsigned int value_size;	void *value;	void *mask;}; /** * struct devlink_dpipe_entry - table entry object * @index: index of the entry in the table * @match_values: match values * @match_values_count: count of matches tuples * @action_values: actions values * @action_values_count: count of actions values * @counter: value of counter * @counter_valid: Specify if value is valid from hardware */struct devlink_dpipe_entry {	u64 index;	struct devlink_dpipe_value *match_values;	unsigned int match_values_count;	struct devlink_dpipe_value *action_values;	unsigned int action_values_count;	u64 counter;	bool counter_valid;}; /** * struct devlink_dpipe_dump_ctx - context provided to driver in order *				   to dump * @info: info * @cmd: devlink command * @skb: skb * @nest: top attribute * @hdr: hdr */struct devlink_dpipe_dump_ctx {	struct genl_info *info;	enum devlink_command cmd;	struct sk_buff *skb;	struct nlattr *nest;	void *hdr;}; struct devlink_dpipe_table_ops; /** * struct devlink_dpipe_table - table object * @priv: private * @name: table name * @counters_enabled: indicates if counters are active * @counter_control_extern: indicates if counter control is in dpipe or *			    external tool * @resource_valid: Indicate that the resource id is valid * @resource_id: relative resource this table is related to * @resource_units: number of resource's unit consumed per table's entry * @table_ops: table operations * @rcu: rcu */struct devlink_dpipe_table {	void *priv;	/* private: */	struct list_head list;	/* public: */	const char *name;	bool counters_enabled;	bool counter_control_extern;	bool resource_valid;	u64 resource_id;	u64 resource_units;	const struct devlink_dpipe_table_ops *table_ops;	struct rcu_head rcu;}; /** * struct devlink_dpipe_table_ops - dpipe_table ops * @actions_dump: dumps all tables actions * @matches_dump: dumps all tables matches * @entries_dump: dumps all active entries in the table * @counters_set_update:  when changing the counter status hardware sync *			  maybe needed to allocate/free counter related *			  resources * @size_get: get size */struct devlink_dpipe_table_ops {	int (*actions_dump)(void *priv, struct sk_buff *skb);	int (*matches_dump)(void *priv, struct sk_buff *skb);	int (*entries_dump)(void *priv, bool counters_enabled,			    struct devlink_dpipe_dump_ctx *dump_ctx);	int (*counters_set_update)(void *priv, bool enable);	u64 (*size_get)(void *priv);}; /** * struct devlink_dpipe_headers - dpipe headers * @headers: header array can be shared (global bit) or driver specific * @headers_count: count of headers */struct devlink_dpipe_headers {	struct devlink_dpipe_header **headers;	unsigned int headers_count;}; /** * struct devlink_resource_size_params - resource's size parameters * @size_min: minimum size which can be set * @size_max: maximum size which can be set * @size_granularity: size granularity * @unit: resource's basic unit */struct devlink_resource_size_params {	u64 size_min;	u64 size_max;	u64 size_granularity;	enum devlink_resource_unit unit;}; static inline voiddevlink_resource_size_params_init(struct devlink_resource_size_params *size_params,				  u64 size_min, u64 size_max,				  u64 size_granularity,				  enum devlink_resource_unit unit){	size_params->size_min = size_min;	size_params->size_max = size_max;	size_params->size_granularity = size_granularity;	size_params->unit = unit;} typedef u64 devlink_resource_occ_get_t(void *priv); #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 #define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports" #define __DEVLINK_PARAM_MAX_STRING_VALUE 32enum devlink_param_type {	DEVLINK_PARAM_TYPE_U8,	DEVLINK_PARAM_TYPE_U16,	DEVLINK_PARAM_TYPE_U32,	DEVLINK_PARAM_TYPE_STRING,	DEVLINK_PARAM_TYPE_BOOL,}; union devlink_param_value {	u8 vu8;	u16 vu16;	u32 vu32;	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];	bool vbool;}; struct devlink_param_gset_ctx {	union devlink_param_value val;	enum devlink_param_cmode cmode;}; /** * struct devlink_flash_notify - devlink dev flash notify data * @status_msg: current status string * @component: firmware component being updated * @done: amount of work completed of total amount * @total: amount of work expected to be done * @timeout: expected max timeout in seconds * * These are values to be given to userland to be displayed in order * to show current activity in a firmware update process. */struct devlink_flash_notify {	const char *status_msg;	const char *component;	unsigned long done;	unsigned long total;	unsigned long timeout;}; /** * struct devlink_param - devlink configuration parameter data * @id: devlink parameter id number * @name: name of the parameter * @generic: indicates if the parameter is generic or driver specific * @type: parameter type * @supported_cmodes: bitmap of supported configuration modes * @get: get parameter value, used for runtime and permanent *       configuration modes * @set: set parameter value, used for runtime and permanent *       configuration modes * @validate: validate input value is applicable (within value range, etc.) * * This struct should be used by the driver to fill the data for * a parameter it registers. */struct devlink_param {	u32 id;	const char *name;	bool generic;	enum devlink_param_type type;	unsigned long supported_cmodes;	int (*get)(struct devlink *devlink, u32 id,		   struct devlink_param_gset_ctx *ctx);	int (*set)(struct devlink *devlink, u32 id,		   struct devlink_param_gset_ctx *ctx,		   struct netlink_ext_ack *extack);	int (*validate)(struct devlink *devlink, u32 id,			union devlink_param_value val,			struct netlink_ext_ack *extack);}; struct devlink_param_item {	struct list_head list;	const struct devlink_param *param;	union devlink_param_value driverinit_value;	bool driverinit_value_valid;	union devlink_param_value driverinit_value_new; /* Not reachable							 * until reload.							 */

Lines 1–500 of 2060.