162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * include/net/devlink.h - Network physical device Netlink interface
462306a36Sopenharmony_ci * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
562306a36Sopenharmony_ci * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci#ifndef _NET_DEVLINK_H_
862306a36Sopenharmony_ci#define _NET_DEVLINK_H_
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/device.h>
1162306a36Sopenharmony_ci#include <linux/slab.h>
1262306a36Sopenharmony_ci#include <linux/gfp.h>
1362306a36Sopenharmony_ci#include <linux/list.h>
1462306a36Sopenharmony_ci#include <linux/netdevice.h>
1562306a36Sopenharmony_ci#include <linux/spinlock.h>
1662306a36Sopenharmony_ci#include <linux/workqueue.h>
1762306a36Sopenharmony_ci#include <linux/refcount.h>
1862306a36Sopenharmony_ci#include <net/net_namespace.h>
1962306a36Sopenharmony_ci#include <net/flow_offload.h>
2062306a36Sopenharmony_ci#include <uapi/linux/devlink.h>
2162306a36Sopenharmony_ci#include <linux/xarray.h>
2262306a36Sopenharmony_ci#include <linux/firmware.h>
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_cistruct devlink;
2562306a36Sopenharmony_cistruct devlink_linecard;
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_cistruct devlink_port_phys_attrs {
2862306a36Sopenharmony_ci	u32 port_number; /* Same value as "split group".
2962306a36Sopenharmony_ci			  * A physical port which is visible to the user
3062306a36Sopenharmony_ci			  * for a given port flavour.
3162306a36Sopenharmony_ci			  */
3262306a36Sopenharmony_ci	u32 split_subport_number; /* If the port is split, this is the number of subport. */
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**
3662306a36Sopenharmony_ci * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
3762306a36Sopenharmony_ci * @controller: Associated controller number
3862306a36Sopenharmony_ci * @pf: Associated PCI PF number for this port.
3962306a36Sopenharmony_ci * @external: when set, indicates if a port is for an external controller
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_cistruct devlink_port_pci_pf_attrs {
4262306a36Sopenharmony_ci	u32 controller;
4362306a36Sopenharmony_ci	u16 pf;
4462306a36Sopenharmony_ci	u8 external:1;
4562306a36Sopenharmony_ci};
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/**
4862306a36Sopenharmony_ci * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
4962306a36Sopenharmony_ci * @controller: Associated controller number
5062306a36Sopenharmony_ci * @pf: Associated PCI PF number for this port.
5162306a36Sopenharmony_ci * @vf: Associated PCI VF for of the PCI PF for this port.
5262306a36Sopenharmony_ci * @external: when set, indicates if a port is for an external controller
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_cistruct devlink_port_pci_vf_attrs {
5562306a36Sopenharmony_ci	u32 controller;
5662306a36Sopenharmony_ci	u16 pf;
5762306a36Sopenharmony_ci	u16 vf;
5862306a36Sopenharmony_ci	u8 external:1;
5962306a36Sopenharmony_ci};
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/**
6262306a36Sopenharmony_ci * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes
6362306a36Sopenharmony_ci * @controller: Associated controller number
6462306a36Sopenharmony_ci * @sf: Associated PCI SF for of the PCI PF for this port.
6562306a36Sopenharmony_ci * @pf: Associated PCI PF number for this port.
6662306a36Sopenharmony_ci * @external: when set, indicates if a port is for an external controller
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_cistruct devlink_port_pci_sf_attrs {
6962306a36Sopenharmony_ci	u32 controller;
7062306a36Sopenharmony_ci	u32 sf;
7162306a36Sopenharmony_ci	u16 pf;
7262306a36Sopenharmony_ci	u8 external:1;
7362306a36Sopenharmony_ci};
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci/**
7662306a36Sopenharmony_ci * struct devlink_port_attrs - devlink port object
7762306a36Sopenharmony_ci * @flavour: flavour of the port
7862306a36Sopenharmony_ci * @split: indicates if this is split port
7962306a36Sopenharmony_ci * @splittable: indicates if the port can be split.
8062306a36Sopenharmony_ci * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
8162306a36Sopenharmony_ci * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
8262306a36Sopenharmony_ci * @phys: physical port attributes
8362306a36Sopenharmony_ci * @pci_pf: PCI PF port attributes
8462306a36Sopenharmony_ci * @pci_vf: PCI VF port attributes
8562306a36Sopenharmony_ci * @pci_sf: PCI SF port attributes
8662306a36Sopenharmony_ci */
8762306a36Sopenharmony_cistruct devlink_port_attrs {
8862306a36Sopenharmony_ci	u8 split:1,
8962306a36Sopenharmony_ci	   splittable:1;
9062306a36Sopenharmony_ci	u32 lanes;
9162306a36Sopenharmony_ci	enum devlink_port_flavour flavour;
9262306a36Sopenharmony_ci	struct netdev_phys_item_id switch_id;
9362306a36Sopenharmony_ci	union {
9462306a36Sopenharmony_ci		struct devlink_port_phys_attrs phys;
9562306a36Sopenharmony_ci		struct devlink_port_pci_pf_attrs pci_pf;
9662306a36Sopenharmony_ci		struct devlink_port_pci_vf_attrs pci_vf;
9762306a36Sopenharmony_ci		struct devlink_port_pci_sf_attrs pci_sf;
9862306a36Sopenharmony_ci	};
9962306a36Sopenharmony_ci};
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistruct devlink_rate {
10262306a36Sopenharmony_ci	struct list_head list;
10362306a36Sopenharmony_ci	enum devlink_rate_type type;
10462306a36Sopenharmony_ci	struct devlink *devlink;
10562306a36Sopenharmony_ci	void *priv;
10662306a36Sopenharmony_ci	u64 tx_share;
10762306a36Sopenharmony_ci	u64 tx_max;
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci	struct devlink_rate *parent;
11062306a36Sopenharmony_ci	union {
11162306a36Sopenharmony_ci		struct devlink_port *devlink_port;
11262306a36Sopenharmony_ci		struct {
11362306a36Sopenharmony_ci			char *name;
11462306a36Sopenharmony_ci			refcount_t refcnt;
11562306a36Sopenharmony_ci		};
11662306a36Sopenharmony_ci	};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	u32 tx_priority;
11962306a36Sopenharmony_ci	u32 tx_weight;
12062306a36Sopenharmony_ci};
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_cistruct devlink_port {
12362306a36Sopenharmony_ci	struct list_head list;
12462306a36Sopenharmony_ci	struct list_head region_list;
12562306a36Sopenharmony_ci	struct devlink *devlink;
12662306a36Sopenharmony_ci	const struct devlink_port_ops *ops;
12762306a36Sopenharmony_ci	unsigned int index;
12862306a36Sopenharmony_ci	spinlock_t type_lock; /* Protects type and type_eth/ib
12962306a36Sopenharmony_ci			       * structures consistency.
13062306a36Sopenharmony_ci			       */
13162306a36Sopenharmony_ci	enum devlink_port_type type;
13262306a36Sopenharmony_ci	enum devlink_port_type desired_type;
13362306a36Sopenharmony_ci	union {
13462306a36Sopenharmony_ci		struct {
13562306a36Sopenharmony_ci			struct net_device *netdev;
13662306a36Sopenharmony_ci			int ifindex;
13762306a36Sopenharmony_ci			char ifname[IFNAMSIZ];
13862306a36Sopenharmony_ci		} type_eth;
13962306a36Sopenharmony_ci		struct {
14062306a36Sopenharmony_ci			struct ib_device *ibdev;
14162306a36Sopenharmony_ci		} type_ib;
14262306a36Sopenharmony_ci	};
14362306a36Sopenharmony_ci	struct devlink_port_attrs attrs;
14462306a36Sopenharmony_ci	u8 attrs_set:1,
14562306a36Sopenharmony_ci	   switch_port:1,
14662306a36Sopenharmony_ci	   registered:1,
14762306a36Sopenharmony_ci	   initialized:1;
14862306a36Sopenharmony_ci	struct delayed_work type_warn_dw;
14962306a36Sopenharmony_ci	struct list_head reporter_list;
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci	struct devlink_rate *devlink_rate;
15262306a36Sopenharmony_ci	struct devlink_linecard *linecard;
15362306a36Sopenharmony_ci};
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_cistruct devlink_port_new_attrs {
15662306a36Sopenharmony_ci	enum devlink_port_flavour flavour;
15762306a36Sopenharmony_ci	unsigned int port_index;
15862306a36Sopenharmony_ci	u32 controller;
15962306a36Sopenharmony_ci	u32 sfnum;
16062306a36Sopenharmony_ci	u16 pfnum;
16162306a36Sopenharmony_ci	u8 port_index_valid:1,
16262306a36Sopenharmony_ci	   controller_valid:1,
16362306a36Sopenharmony_ci	   sfnum_valid:1;
16462306a36Sopenharmony_ci};
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci/**
16762306a36Sopenharmony_ci * struct devlink_linecard_ops - Linecard operations
16862306a36Sopenharmony_ci * @provision: callback to provision the linecard slot with certain
16962306a36Sopenharmony_ci *	       type of linecard. As a result of this operation,
17062306a36Sopenharmony_ci *	       driver is expected to eventually (could be after
17162306a36Sopenharmony_ci *	       the function call returns) call one of:
17262306a36Sopenharmony_ci *	       devlink_linecard_provision_set()
17362306a36Sopenharmony_ci *	       devlink_linecard_provision_fail()
17462306a36Sopenharmony_ci * @unprovision: callback to unprovision the linecard slot. As a result
17562306a36Sopenharmony_ci *		 of this operation, driver is expected to eventually
17662306a36Sopenharmony_ci *		 (could be after the function call returns) call
17762306a36Sopenharmony_ci *	         devlink_linecard_provision_clear()
17862306a36Sopenharmony_ci *	         devlink_linecard_provision_fail()
17962306a36Sopenharmony_ci * @same_provision: callback to ask the driver if linecard is already
18062306a36Sopenharmony_ci *                  provisioned in the same way user asks this linecard to be
18162306a36Sopenharmony_ci *                  provisioned.
18262306a36Sopenharmony_ci * @types_count: callback to get number of supported types
18362306a36Sopenharmony_ci * @types_get: callback to get next type in list
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_cistruct devlink_linecard_ops {
18662306a36Sopenharmony_ci	int (*provision)(struct devlink_linecard *linecard, void *priv,
18762306a36Sopenharmony_ci			 const char *type, const void *type_priv,
18862306a36Sopenharmony_ci			 struct netlink_ext_ack *extack);
18962306a36Sopenharmony_ci	int (*unprovision)(struct devlink_linecard *linecard, void *priv,
19062306a36Sopenharmony_ci			   struct netlink_ext_ack *extack);
19162306a36Sopenharmony_ci	bool (*same_provision)(struct devlink_linecard *linecard, void *priv,
19262306a36Sopenharmony_ci			       const char *type, const void *type_priv);
19362306a36Sopenharmony_ci	unsigned int (*types_count)(struct devlink_linecard *linecard,
19462306a36Sopenharmony_ci				    void *priv);
19562306a36Sopenharmony_ci	void (*types_get)(struct devlink_linecard *linecard,
19662306a36Sopenharmony_ci			  void *priv, unsigned int index, const char **type,
19762306a36Sopenharmony_ci			  const void **type_priv);
19862306a36Sopenharmony_ci};
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_cistruct devlink_sb_pool_info {
20162306a36Sopenharmony_ci	enum devlink_sb_pool_type pool_type;
20262306a36Sopenharmony_ci	u32 size;
20362306a36Sopenharmony_ci	enum devlink_sb_threshold_type threshold_type;
20462306a36Sopenharmony_ci	u32 cell_size;
20562306a36Sopenharmony_ci};
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci/**
20862306a36Sopenharmony_ci * struct devlink_dpipe_field - dpipe field object
20962306a36Sopenharmony_ci * @name: field name
21062306a36Sopenharmony_ci * @id: index inside the headers field array
21162306a36Sopenharmony_ci * @bitwidth: bitwidth
21262306a36Sopenharmony_ci * @mapping_type: mapping type
21362306a36Sopenharmony_ci */
21462306a36Sopenharmony_cistruct devlink_dpipe_field {
21562306a36Sopenharmony_ci	const char *name;
21662306a36Sopenharmony_ci	unsigned int id;
21762306a36Sopenharmony_ci	unsigned int bitwidth;
21862306a36Sopenharmony_ci	enum devlink_dpipe_field_mapping_type mapping_type;
21962306a36Sopenharmony_ci};
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci/**
22262306a36Sopenharmony_ci * struct devlink_dpipe_header - dpipe header object
22362306a36Sopenharmony_ci * @name: header name
22462306a36Sopenharmony_ci * @id: index, global/local determined by global bit
22562306a36Sopenharmony_ci * @fields: fields
22662306a36Sopenharmony_ci * @fields_count: number of fields
22762306a36Sopenharmony_ci * @global: indicates if header is shared like most protocol header
22862306a36Sopenharmony_ci *	    or driver specific
22962306a36Sopenharmony_ci */
23062306a36Sopenharmony_cistruct devlink_dpipe_header {
23162306a36Sopenharmony_ci	const char *name;
23262306a36Sopenharmony_ci	unsigned int id;
23362306a36Sopenharmony_ci	struct devlink_dpipe_field *fields;
23462306a36Sopenharmony_ci	unsigned int fields_count;
23562306a36Sopenharmony_ci	bool global;
23662306a36Sopenharmony_ci};
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci/**
23962306a36Sopenharmony_ci * struct devlink_dpipe_match - represents match operation
24062306a36Sopenharmony_ci * @type: type of match
24162306a36Sopenharmony_ci * @header_index: header index (packets can have several headers of same
24262306a36Sopenharmony_ci *		  type like in case of tunnels)
24362306a36Sopenharmony_ci * @header: header
24462306a36Sopenharmony_ci * @field_id: field index
24562306a36Sopenharmony_ci */
24662306a36Sopenharmony_cistruct devlink_dpipe_match {
24762306a36Sopenharmony_ci	enum devlink_dpipe_match_type type;
24862306a36Sopenharmony_ci	unsigned int header_index;
24962306a36Sopenharmony_ci	struct devlink_dpipe_header *header;
25062306a36Sopenharmony_ci	unsigned int field_id;
25162306a36Sopenharmony_ci};
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci/**
25462306a36Sopenharmony_ci * struct devlink_dpipe_action - represents action operation
25562306a36Sopenharmony_ci * @type: type of action
25662306a36Sopenharmony_ci * @header_index: header index (packets can have several headers of same
25762306a36Sopenharmony_ci *		  type like in case of tunnels)
25862306a36Sopenharmony_ci * @header: header
25962306a36Sopenharmony_ci * @field_id: field index
26062306a36Sopenharmony_ci */
26162306a36Sopenharmony_cistruct devlink_dpipe_action {
26262306a36Sopenharmony_ci	enum devlink_dpipe_action_type type;
26362306a36Sopenharmony_ci	unsigned int header_index;
26462306a36Sopenharmony_ci	struct devlink_dpipe_header *header;
26562306a36Sopenharmony_ci	unsigned int field_id;
26662306a36Sopenharmony_ci};
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci/**
26962306a36Sopenharmony_ci * struct devlink_dpipe_value - represents value of match/action
27062306a36Sopenharmony_ci * @action: action
27162306a36Sopenharmony_ci * @match: match
27262306a36Sopenharmony_ci * @mapping_value: in case the field has some mapping this value
27362306a36Sopenharmony_ci *                 specified the mapping value
27462306a36Sopenharmony_ci * @mapping_valid: specify if mapping value is valid
27562306a36Sopenharmony_ci * @value_size: value size
27662306a36Sopenharmony_ci * @value: value
27762306a36Sopenharmony_ci * @mask: bit mask
27862306a36Sopenharmony_ci */
27962306a36Sopenharmony_cistruct devlink_dpipe_value {
28062306a36Sopenharmony_ci	union {
28162306a36Sopenharmony_ci		struct devlink_dpipe_action *action;
28262306a36Sopenharmony_ci		struct devlink_dpipe_match *match;
28362306a36Sopenharmony_ci	};
28462306a36Sopenharmony_ci	unsigned int mapping_value;
28562306a36Sopenharmony_ci	bool mapping_valid;
28662306a36Sopenharmony_ci	unsigned int value_size;
28762306a36Sopenharmony_ci	void *value;
28862306a36Sopenharmony_ci	void *mask;
28962306a36Sopenharmony_ci};
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci/**
29262306a36Sopenharmony_ci * struct devlink_dpipe_entry - table entry object
29362306a36Sopenharmony_ci * @index: index of the entry in the table
29462306a36Sopenharmony_ci * @match_values: match values
29562306a36Sopenharmony_ci * @match_values_count: count of matches tuples
29662306a36Sopenharmony_ci * @action_values: actions values
29762306a36Sopenharmony_ci * @action_values_count: count of actions values
29862306a36Sopenharmony_ci * @counter: value of counter
29962306a36Sopenharmony_ci * @counter_valid: Specify if value is valid from hardware
30062306a36Sopenharmony_ci */
30162306a36Sopenharmony_cistruct devlink_dpipe_entry {
30262306a36Sopenharmony_ci	u64 index;
30362306a36Sopenharmony_ci	struct devlink_dpipe_value *match_values;
30462306a36Sopenharmony_ci	unsigned int match_values_count;
30562306a36Sopenharmony_ci	struct devlink_dpipe_value *action_values;
30662306a36Sopenharmony_ci	unsigned int action_values_count;
30762306a36Sopenharmony_ci	u64 counter;
30862306a36Sopenharmony_ci	bool counter_valid;
30962306a36Sopenharmony_ci};
31062306a36Sopenharmony_ci
31162306a36Sopenharmony_ci/**
31262306a36Sopenharmony_ci * struct devlink_dpipe_dump_ctx - context provided to driver in order
31362306a36Sopenharmony_ci *				   to dump
31462306a36Sopenharmony_ci * @info: info
31562306a36Sopenharmony_ci * @cmd: devlink command
31662306a36Sopenharmony_ci * @skb: skb
31762306a36Sopenharmony_ci * @nest: top attribute
31862306a36Sopenharmony_ci * @hdr: hdr
31962306a36Sopenharmony_ci */
32062306a36Sopenharmony_cistruct devlink_dpipe_dump_ctx {
32162306a36Sopenharmony_ci	struct genl_info *info;
32262306a36Sopenharmony_ci	enum devlink_command cmd;
32362306a36Sopenharmony_ci	struct sk_buff *skb;
32462306a36Sopenharmony_ci	struct nlattr *nest;
32562306a36Sopenharmony_ci	void *hdr;
32662306a36Sopenharmony_ci};
32762306a36Sopenharmony_ci
32862306a36Sopenharmony_cistruct devlink_dpipe_table_ops;
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci/**
33162306a36Sopenharmony_ci * struct devlink_dpipe_table - table object
33262306a36Sopenharmony_ci * @priv: private
33362306a36Sopenharmony_ci * @name: table name
33462306a36Sopenharmony_ci * @counters_enabled: indicates if counters are active
33562306a36Sopenharmony_ci * @counter_control_extern: indicates if counter control is in dpipe or
33662306a36Sopenharmony_ci *			    external tool
33762306a36Sopenharmony_ci * @resource_valid: Indicate that the resource id is valid
33862306a36Sopenharmony_ci * @resource_id: relative resource this table is related to
33962306a36Sopenharmony_ci * @resource_units: number of resource's unit consumed per table's entry
34062306a36Sopenharmony_ci * @table_ops: table operations
34162306a36Sopenharmony_ci * @rcu: rcu
34262306a36Sopenharmony_ci */
34362306a36Sopenharmony_cistruct devlink_dpipe_table {
34462306a36Sopenharmony_ci	void *priv;
34562306a36Sopenharmony_ci	/* private: */
34662306a36Sopenharmony_ci	struct list_head list;
34762306a36Sopenharmony_ci	/* public: */
34862306a36Sopenharmony_ci	const char *name;
34962306a36Sopenharmony_ci	bool counters_enabled;
35062306a36Sopenharmony_ci	bool counter_control_extern;
35162306a36Sopenharmony_ci	bool resource_valid;
35262306a36Sopenharmony_ci	u64 resource_id;
35362306a36Sopenharmony_ci	u64 resource_units;
35462306a36Sopenharmony_ci	struct devlink_dpipe_table_ops *table_ops;
35562306a36Sopenharmony_ci	struct rcu_head rcu;
35662306a36Sopenharmony_ci};
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci/**
35962306a36Sopenharmony_ci * struct devlink_dpipe_table_ops - dpipe_table ops
36062306a36Sopenharmony_ci * @actions_dump: dumps all tables actions
36162306a36Sopenharmony_ci * @matches_dump: dumps all tables matches
36262306a36Sopenharmony_ci * @entries_dump: dumps all active entries in the table
36362306a36Sopenharmony_ci * @counters_set_update:  when changing the counter status hardware sync
36462306a36Sopenharmony_ci *			  maybe needed to allocate/free counter related
36562306a36Sopenharmony_ci *			  resources
36662306a36Sopenharmony_ci * @size_get: get size
36762306a36Sopenharmony_ci */
36862306a36Sopenharmony_cistruct devlink_dpipe_table_ops {
36962306a36Sopenharmony_ci	int (*actions_dump)(void *priv, struct sk_buff *skb);
37062306a36Sopenharmony_ci	int (*matches_dump)(void *priv, struct sk_buff *skb);
37162306a36Sopenharmony_ci	int (*entries_dump)(void *priv, bool counters_enabled,
37262306a36Sopenharmony_ci			    struct devlink_dpipe_dump_ctx *dump_ctx);
37362306a36Sopenharmony_ci	int (*counters_set_update)(void *priv, bool enable);
37462306a36Sopenharmony_ci	u64 (*size_get)(void *priv);
37562306a36Sopenharmony_ci};
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci/**
37862306a36Sopenharmony_ci * struct devlink_dpipe_headers - dpipe headers
37962306a36Sopenharmony_ci * @headers: header array can be shared (global bit) or driver specific
38062306a36Sopenharmony_ci * @headers_count: count of headers
38162306a36Sopenharmony_ci */
38262306a36Sopenharmony_cistruct devlink_dpipe_headers {
38362306a36Sopenharmony_ci	struct devlink_dpipe_header **headers;
38462306a36Sopenharmony_ci	unsigned int headers_count;
38562306a36Sopenharmony_ci};
38662306a36Sopenharmony_ci
38762306a36Sopenharmony_ci/**
38862306a36Sopenharmony_ci * struct devlink_resource_size_params - resource's size parameters
38962306a36Sopenharmony_ci * @size_min: minimum size which can be set
39062306a36Sopenharmony_ci * @size_max: maximum size which can be set
39162306a36Sopenharmony_ci * @size_granularity: size granularity
39262306a36Sopenharmony_ci * @unit: resource's basic unit
39362306a36Sopenharmony_ci */
39462306a36Sopenharmony_cistruct devlink_resource_size_params {
39562306a36Sopenharmony_ci	u64 size_min;
39662306a36Sopenharmony_ci	u64 size_max;
39762306a36Sopenharmony_ci	u64 size_granularity;
39862306a36Sopenharmony_ci	enum devlink_resource_unit unit;
39962306a36Sopenharmony_ci};
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_cistatic inline void
40262306a36Sopenharmony_cidevlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
40362306a36Sopenharmony_ci				  u64 size_min, u64 size_max,
40462306a36Sopenharmony_ci				  u64 size_granularity,
40562306a36Sopenharmony_ci				  enum devlink_resource_unit unit)
40662306a36Sopenharmony_ci{
40762306a36Sopenharmony_ci	size_params->size_min = size_min;
40862306a36Sopenharmony_ci	size_params->size_max = size_max;
40962306a36Sopenharmony_ci	size_params->size_granularity = size_granularity;
41062306a36Sopenharmony_ci	size_params->unit = unit;
41162306a36Sopenharmony_ci}
41262306a36Sopenharmony_ci
41362306a36Sopenharmony_citypedef u64 devlink_resource_occ_get_t(void *priv);
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_ci#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_ci#define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports"
41862306a36Sopenharmony_ci
41962306a36Sopenharmony_ci#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
42062306a36Sopenharmony_cienum devlink_param_type {
42162306a36Sopenharmony_ci	DEVLINK_PARAM_TYPE_U8,
42262306a36Sopenharmony_ci	DEVLINK_PARAM_TYPE_U16,
42362306a36Sopenharmony_ci	DEVLINK_PARAM_TYPE_U32,
42462306a36Sopenharmony_ci	DEVLINK_PARAM_TYPE_STRING,
42562306a36Sopenharmony_ci	DEVLINK_PARAM_TYPE_BOOL,
42662306a36Sopenharmony_ci};
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ciunion devlink_param_value {
42962306a36Sopenharmony_ci	u8 vu8;
43062306a36Sopenharmony_ci	u16 vu16;
43162306a36Sopenharmony_ci	u32 vu32;
43262306a36Sopenharmony_ci	char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
43362306a36Sopenharmony_ci	bool vbool;
43462306a36Sopenharmony_ci};
43562306a36Sopenharmony_ci
43662306a36Sopenharmony_cistruct devlink_param_gset_ctx {
43762306a36Sopenharmony_ci	union devlink_param_value val;
43862306a36Sopenharmony_ci	enum devlink_param_cmode cmode;
43962306a36Sopenharmony_ci};
44062306a36Sopenharmony_ci
44162306a36Sopenharmony_ci/**
44262306a36Sopenharmony_ci * struct devlink_flash_notify - devlink dev flash notify data
44362306a36Sopenharmony_ci * @status_msg: current status string
44462306a36Sopenharmony_ci * @component: firmware component being updated
44562306a36Sopenharmony_ci * @done: amount of work completed of total amount
44662306a36Sopenharmony_ci * @total: amount of work expected to be done
44762306a36Sopenharmony_ci * @timeout: expected max timeout in seconds
44862306a36Sopenharmony_ci *
44962306a36Sopenharmony_ci * These are values to be given to userland to be displayed in order
45062306a36Sopenharmony_ci * to show current activity in a firmware update process.
45162306a36Sopenharmony_ci */
45262306a36Sopenharmony_cistruct devlink_flash_notify {
45362306a36Sopenharmony_ci	const char *status_msg;
45462306a36Sopenharmony_ci	const char *component;
45562306a36Sopenharmony_ci	unsigned long done;
45662306a36Sopenharmony_ci	unsigned long total;
45762306a36Sopenharmony_ci	unsigned long timeout;
45862306a36Sopenharmony_ci};
45962306a36Sopenharmony_ci
46062306a36Sopenharmony_ci/**
46162306a36Sopenharmony_ci * struct devlink_param - devlink configuration parameter data
46262306a36Sopenharmony_ci * @id: devlink parameter id number
46362306a36Sopenharmony_ci * @name: name of the parameter
46462306a36Sopenharmony_ci * @generic: indicates if the parameter is generic or driver specific
46562306a36Sopenharmony_ci * @type: parameter type
46662306a36Sopenharmony_ci * @supported_cmodes: bitmap of supported configuration modes
46762306a36Sopenharmony_ci * @get: get parameter value, used for runtime and permanent
46862306a36Sopenharmony_ci *       configuration modes
46962306a36Sopenharmony_ci * @set: set parameter value, used for runtime and permanent
47062306a36Sopenharmony_ci *       configuration modes
47162306a36Sopenharmony_ci * @validate: validate input value is applicable (within value range, etc.)
47262306a36Sopenharmony_ci *
47362306a36Sopenharmony_ci * This struct should be used by the driver to fill the data for
47462306a36Sopenharmony_ci * a parameter it registers.
47562306a36Sopenharmony_ci */
47662306a36Sopenharmony_cistruct devlink_param {
47762306a36Sopenharmony_ci	u32 id;
47862306a36Sopenharmony_ci	const char *name;
47962306a36Sopenharmony_ci	bool generic;
48062306a36Sopenharmony_ci	enum devlink_param_type type;
48162306a36Sopenharmony_ci	unsigned long supported_cmodes;
48262306a36Sopenharmony_ci	int (*get)(struct devlink *devlink, u32 id,
48362306a36Sopenharmony_ci		   struct devlink_param_gset_ctx *ctx);
48462306a36Sopenharmony_ci	int (*set)(struct devlink *devlink, u32 id,
48562306a36Sopenharmony_ci		   struct devlink_param_gset_ctx *ctx);
48662306a36Sopenharmony_ci	int (*validate)(struct devlink *devlink, u32 id,
48762306a36Sopenharmony_ci			union devlink_param_value val,
48862306a36Sopenharmony_ci			struct netlink_ext_ack *extack);
48962306a36Sopenharmony_ci};
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_cistruct devlink_param_item {
49262306a36Sopenharmony_ci	struct list_head list;
49362306a36Sopenharmony_ci	const struct devlink_param *param;
49462306a36Sopenharmony_ci	union devlink_param_value driverinit_value;
49562306a36Sopenharmony_ci	bool driverinit_value_valid;
49662306a36Sopenharmony_ci	union devlink_param_value driverinit_value_new; /* Not reachable
49762306a36Sopenharmony_ci							 * until reload.
49862306a36Sopenharmony_ci							 */
49962306a36Sopenharmony_ci	bool driverinit_value_new_valid;
50062306a36Sopenharmony_ci};
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_cienum devlink_param_generic_id {
50362306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
50462306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
50562306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
50662306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
50762306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
50862306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
50962306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
51062306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
51162306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
51262306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
51362306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
51462306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
51562306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
51662306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
51762306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP,
51862306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE,
51962306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE,
52062306a36Sopenharmony_ci
52162306a36Sopenharmony_ci	/* add new param generic ids above here*/
52262306a36Sopenharmony_ci	__DEVLINK_PARAM_GENERIC_ID_MAX,
52362306a36Sopenharmony_ci	DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
52462306a36Sopenharmony_ci};
52562306a36Sopenharmony_ci
52662306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
52762306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
53062306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
53162306a36Sopenharmony_ci
53262306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
53362306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
53662306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
53962306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
54262306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
54562306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
54862306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
55162306a36Sopenharmony_ci	"reset_dev_on_drv_probe"
55262306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
55562306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset"
55862306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
55962306a36Sopenharmony_ci
56062306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME "enable_eth"
56162306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE DEVLINK_PARAM_TYPE_BOOL
56262306a36Sopenharmony_ci
56362306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME "enable_rdma"
56462306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE DEVLINK_PARAM_TYPE_BOOL
56562306a36Sopenharmony_ci
56662306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME "enable_vnet"
56762306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE DEVLINK_PARAM_TYPE_BOOL
56862306a36Sopenharmony_ci
56962306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_NAME "enable_iwarp"
57062306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_TYPE DEVLINK_PARAM_TYPE_BOOL
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_NAME "io_eq_size"
57362306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
57462306a36Sopenharmony_ci
57562306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size"
57662306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)	\
57962306a36Sopenharmony_ci{									\
58062306a36Sopenharmony_ci	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				\
58162306a36Sopenharmony_ci	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			\
58262306a36Sopenharmony_ci	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			\
58362306a36Sopenharmony_ci	.generic = true,						\
58462306a36Sopenharmony_ci	.supported_cmodes = _cmodes,					\
58562306a36Sopenharmony_ci	.get = _get,							\
58662306a36Sopenharmony_ci	.set = _set,							\
58762306a36Sopenharmony_ci	.validate = _validate,						\
58862306a36Sopenharmony_ci}
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_ci#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate)	\
59162306a36Sopenharmony_ci{									\
59262306a36Sopenharmony_ci	.id = _id,							\
59362306a36Sopenharmony_ci	.name = _name,							\
59462306a36Sopenharmony_ci	.type = _type,							\
59562306a36Sopenharmony_ci	.supported_cmodes = _cmodes,					\
59662306a36Sopenharmony_ci	.get = _get,							\
59762306a36Sopenharmony_ci	.set = _set,							\
59862306a36Sopenharmony_ci	.validate = _validate,						\
59962306a36Sopenharmony_ci}
60062306a36Sopenharmony_ci
60162306a36Sopenharmony_ci/* Part number, identifier of board design */
60262306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
60362306a36Sopenharmony_ci/* Revision of board design */
60462306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV	"board.rev"
60562306a36Sopenharmony_ci/* Maker of the board */
60662306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE	"board.manufacture"
60762306a36Sopenharmony_ci
60862306a36Sopenharmony_ci/* Part number, identifier of asic design */
60962306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID	"asic.id"
61062306a36Sopenharmony_ci/* Revision of asic design */
61162306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV	"asic.rev"
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_ci/* Overall FW version */
61462306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW		"fw"
61562306a36Sopenharmony_ci/* Control processor FW version */
61662306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT	"fw.mgmt"
61762306a36Sopenharmony_ci/* FW interface specification version */
61862306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API	"fw.mgmt.api"
61962306a36Sopenharmony_ci/* Data path microcode controlling high-speed packet processing */
62062306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_APP	"fw.app"
62162306a36Sopenharmony_ci/* UNDI software version */
62262306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI	"fw.undi"
62362306a36Sopenharmony_ci/* NCSI support/handler version */
62462306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI	"fw.ncsi"
62562306a36Sopenharmony_ci/* FW parameter set id */
62662306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID	"fw.psid"
62762306a36Sopenharmony_ci/* RoCE FW version */
62862306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE	"fw.roce"
62962306a36Sopenharmony_ci/* Firmware bundle identifier */
63062306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID	"fw.bundle_id"
63162306a36Sopenharmony_ci/* Bootloader */
63262306a36Sopenharmony_ci#define DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER	"fw.bootloader"
63362306a36Sopenharmony_ci
63462306a36Sopenharmony_ci/**
63562306a36Sopenharmony_ci * struct devlink_flash_update_params - Flash Update parameters
63662306a36Sopenharmony_ci * @fw: pointer to the firmware data to update from
63762306a36Sopenharmony_ci * @component: the flash component to update
63862306a36Sopenharmony_ci * @overwrite_mask: which types of flash update are supported (may be %0)
63962306a36Sopenharmony_ci *
64062306a36Sopenharmony_ci * With the exception of fw, drivers must opt-in to parameters by
64162306a36Sopenharmony_ci * setting the appropriate bit in the supported_flash_update_params field in
64262306a36Sopenharmony_ci * their devlink_ops structure.
64362306a36Sopenharmony_ci */
64462306a36Sopenharmony_cistruct devlink_flash_update_params {
64562306a36Sopenharmony_ci	const struct firmware *fw;
64662306a36Sopenharmony_ci	const char *component;
64762306a36Sopenharmony_ci	u32 overwrite_mask;
64862306a36Sopenharmony_ci};
64962306a36Sopenharmony_ci
65062306a36Sopenharmony_ci#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK	BIT(0)
65162306a36Sopenharmony_ci
65262306a36Sopenharmony_cistruct devlink_region;
65362306a36Sopenharmony_cistruct devlink_info_req;
65462306a36Sopenharmony_ci
65562306a36Sopenharmony_ci/**
65662306a36Sopenharmony_ci * struct devlink_region_ops - Region operations
65762306a36Sopenharmony_ci * @name: region name
65862306a36Sopenharmony_ci * @destructor: callback used to free snapshot memory when deleting
65962306a36Sopenharmony_ci * @snapshot: callback to request an immediate snapshot. On success,
66062306a36Sopenharmony_ci *            the data variable must be updated to point to the snapshot data.
66162306a36Sopenharmony_ci *            The function will be called while the devlink instance lock is
66262306a36Sopenharmony_ci *            held.
66362306a36Sopenharmony_ci * @read: callback to directly read a portion of the region. On success,
66462306a36Sopenharmony_ci *        the data pointer will be updated with the contents of the
66562306a36Sopenharmony_ci *        requested portion of the region. The function will be called
66662306a36Sopenharmony_ci *        while the devlink instance lock is held.
66762306a36Sopenharmony_ci * @priv: Pointer to driver private data for the region operation
66862306a36Sopenharmony_ci */
66962306a36Sopenharmony_cistruct devlink_region_ops {
67062306a36Sopenharmony_ci	const char *name;
67162306a36Sopenharmony_ci	void (*destructor)(const void *data);
67262306a36Sopenharmony_ci	int (*snapshot)(struct devlink *devlink,
67362306a36Sopenharmony_ci			const struct devlink_region_ops *ops,
67462306a36Sopenharmony_ci			struct netlink_ext_ack *extack,
67562306a36Sopenharmony_ci			u8 **data);
67662306a36Sopenharmony_ci	int (*read)(struct devlink *devlink,
67762306a36Sopenharmony_ci		    const struct devlink_region_ops *ops,
67862306a36Sopenharmony_ci		    struct netlink_ext_ack *extack,
67962306a36Sopenharmony_ci		    u64 offset, u32 size, u8 *data);
68062306a36Sopenharmony_ci	void *priv;
68162306a36Sopenharmony_ci};
68262306a36Sopenharmony_ci
68362306a36Sopenharmony_ci/**
68462306a36Sopenharmony_ci * struct devlink_port_region_ops - Region operations for a port
68562306a36Sopenharmony_ci * @name: region name
68662306a36Sopenharmony_ci * @destructor: callback used to free snapshot memory when deleting
68762306a36Sopenharmony_ci * @snapshot: callback to request an immediate snapshot. On success,
68862306a36Sopenharmony_ci *            the data variable must be updated to point to the snapshot data.
68962306a36Sopenharmony_ci *            The function will be called while the devlink instance lock is
69062306a36Sopenharmony_ci *            held.
69162306a36Sopenharmony_ci * @read: callback to directly read a portion of the region. On success,
69262306a36Sopenharmony_ci *        the data pointer will be updated with the contents of the
69362306a36Sopenharmony_ci *        requested portion of the region. The function will be called
69462306a36Sopenharmony_ci *        while the devlink instance lock is held.
69562306a36Sopenharmony_ci * @priv: Pointer to driver private data for the region operation
69662306a36Sopenharmony_ci */
69762306a36Sopenharmony_cistruct devlink_port_region_ops {
69862306a36Sopenharmony_ci	const char *name;
69962306a36Sopenharmony_ci	void (*destructor)(const void *data);
70062306a36Sopenharmony_ci	int (*snapshot)(struct devlink_port *port,
70162306a36Sopenharmony_ci			const struct devlink_port_region_ops *ops,
70262306a36Sopenharmony_ci			struct netlink_ext_ack *extack,
70362306a36Sopenharmony_ci			u8 **data);
70462306a36Sopenharmony_ci	int (*read)(struct devlink_port *port,
70562306a36Sopenharmony_ci		    const struct devlink_port_region_ops *ops,
70662306a36Sopenharmony_ci		    struct netlink_ext_ack *extack,
70762306a36Sopenharmony_ci		    u64 offset, u32 size, u8 *data);
70862306a36Sopenharmony_ci	void *priv;
70962306a36Sopenharmony_ci};
71062306a36Sopenharmony_ci
71162306a36Sopenharmony_cistruct devlink_fmsg;
71262306a36Sopenharmony_cistruct devlink_health_reporter;
71362306a36Sopenharmony_ci
71462306a36Sopenharmony_cienum devlink_health_reporter_state {
71562306a36Sopenharmony_ci	DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
71662306a36Sopenharmony_ci	DEVLINK_HEALTH_REPORTER_STATE_ERROR,
71762306a36Sopenharmony_ci};
71862306a36Sopenharmony_ci
71962306a36Sopenharmony_ci/**
72062306a36Sopenharmony_ci * struct devlink_health_reporter_ops - Reporter operations
72162306a36Sopenharmony_ci * @name: reporter name
72262306a36Sopenharmony_ci * @recover: callback to recover from reported error
72362306a36Sopenharmony_ci *           if priv_ctx is NULL, run a full recover
72462306a36Sopenharmony_ci * @dump: callback to dump an object
72562306a36Sopenharmony_ci *        if priv_ctx is NULL, run a full dump
72662306a36Sopenharmony_ci * @diagnose: callback to diagnose the current status
72762306a36Sopenharmony_ci * @test: callback to trigger a test event
72862306a36Sopenharmony_ci */
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_cistruct devlink_health_reporter_ops {
73162306a36Sopenharmony_ci	char *name;
73262306a36Sopenharmony_ci	int (*recover)(struct devlink_health_reporter *reporter,
73362306a36Sopenharmony_ci		       void *priv_ctx, struct netlink_ext_ack *extack);
73462306a36Sopenharmony_ci	int (*dump)(struct devlink_health_reporter *reporter,
73562306a36Sopenharmony_ci		    struct devlink_fmsg *fmsg, void *priv_ctx,
73662306a36Sopenharmony_ci		    struct netlink_ext_ack *extack);
73762306a36Sopenharmony_ci	int (*diagnose)(struct devlink_health_reporter *reporter,
73862306a36Sopenharmony_ci			struct devlink_fmsg *fmsg,
73962306a36Sopenharmony_ci			struct netlink_ext_ack *extack);
74062306a36Sopenharmony_ci	int (*test)(struct devlink_health_reporter *reporter,
74162306a36Sopenharmony_ci		    struct netlink_ext_ack *extack);
74262306a36Sopenharmony_ci};
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_ci/**
74562306a36Sopenharmony_ci * struct devlink_trap_metadata - Packet trap metadata.
74662306a36Sopenharmony_ci * @trap_name: Trap name.
74762306a36Sopenharmony_ci * @trap_group_name: Trap group name.
74862306a36Sopenharmony_ci * @input_dev: Input netdevice.
74962306a36Sopenharmony_ci * @dev_tracker: refcount tracker for @input_dev.
75062306a36Sopenharmony_ci * @fa_cookie: Flow action user cookie.
75162306a36Sopenharmony_ci * @trap_type: Trap type.
75262306a36Sopenharmony_ci */
75362306a36Sopenharmony_cistruct devlink_trap_metadata {
75462306a36Sopenharmony_ci	const char *trap_name;
75562306a36Sopenharmony_ci	const char *trap_group_name;
75662306a36Sopenharmony_ci
75762306a36Sopenharmony_ci	struct net_device *input_dev;
75862306a36Sopenharmony_ci	netdevice_tracker dev_tracker;
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_ci	const struct flow_action_cookie *fa_cookie;
76162306a36Sopenharmony_ci	enum devlink_trap_type trap_type;
76262306a36Sopenharmony_ci};
76362306a36Sopenharmony_ci
76462306a36Sopenharmony_ci/**
76562306a36Sopenharmony_ci * struct devlink_trap_policer - Immutable packet trap policer attributes.
76662306a36Sopenharmony_ci * @id: Policer identifier.
76762306a36Sopenharmony_ci * @init_rate: Initial rate in packets / sec.
76862306a36Sopenharmony_ci * @init_burst: Initial burst size in packets.
76962306a36Sopenharmony_ci * @max_rate: Maximum rate.
77062306a36Sopenharmony_ci * @min_rate: Minimum rate.
77162306a36Sopenharmony_ci * @max_burst: Maximum burst size.
77262306a36Sopenharmony_ci * @min_burst: Minimum burst size.
77362306a36Sopenharmony_ci *
77462306a36Sopenharmony_ci * Describes immutable attributes of packet trap policers that drivers register
77562306a36Sopenharmony_ci * with devlink.
77662306a36Sopenharmony_ci */
77762306a36Sopenharmony_cistruct devlink_trap_policer {
77862306a36Sopenharmony_ci	u32 id;
77962306a36Sopenharmony_ci	u64 init_rate;
78062306a36Sopenharmony_ci	u64 init_burst;
78162306a36Sopenharmony_ci	u64 max_rate;
78262306a36Sopenharmony_ci	u64 min_rate;
78362306a36Sopenharmony_ci	u64 max_burst;
78462306a36Sopenharmony_ci	u64 min_burst;
78562306a36Sopenharmony_ci};
78662306a36Sopenharmony_ci
78762306a36Sopenharmony_ci/**
78862306a36Sopenharmony_ci * struct devlink_trap_group - Immutable packet trap group attributes.
78962306a36Sopenharmony_ci * @name: Trap group name.
79062306a36Sopenharmony_ci * @id: Trap group identifier.
79162306a36Sopenharmony_ci * @generic: Whether the trap group is generic or not.
79262306a36Sopenharmony_ci * @init_policer_id: Initial policer identifier.
79362306a36Sopenharmony_ci *
79462306a36Sopenharmony_ci * Describes immutable attributes of packet trap groups that drivers register
79562306a36Sopenharmony_ci * with devlink.
79662306a36Sopenharmony_ci */
79762306a36Sopenharmony_cistruct devlink_trap_group {
79862306a36Sopenharmony_ci	const char *name;
79962306a36Sopenharmony_ci	u16 id;
80062306a36Sopenharmony_ci	bool generic;
80162306a36Sopenharmony_ci	u32 init_policer_id;
80262306a36Sopenharmony_ci};
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_ci#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT	BIT(0)
80562306a36Sopenharmony_ci#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE	BIT(1)
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ci/**
80862306a36Sopenharmony_ci * struct devlink_trap - Immutable packet trap attributes.
80962306a36Sopenharmony_ci * @type: Trap type.
81062306a36Sopenharmony_ci * @init_action: Initial trap action.
81162306a36Sopenharmony_ci * @generic: Whether the trap is generic or not.
81262306a36Sopenharmony_ci * @id: Trap identifier.
81362306a36Sopenharmony_ci * @name: Trap name.
81462306a36Sopenharmony_ci * @init_group_id: Initial group identifier.
81562306a36Sopenharmony_ci * @metadata_cap: Metadata types that can be provided by the trap.
81662306a36Sopenharmony_ci *
81762306a36Sopenharmony_ci * Describes immutable attributes of packet traps that drivers register with
81862306a36Sopenharmony_ci * devlink.
81962306a36Sopenharmony_ci */
82062306a36Sopenharmony_cistruct devlink_trap {
82162306a36Sopenharmony_ci	enum devlink_trap_type type;
82262306a36Sopenharmony_ci	enum devlink_trap_action init_action;
82362306a36Sopenharmony_ci	bool generic;
82462306a36Sopenharmony_ci	u16 id;
82562306a36Sopenharmony_ci	const char *name;
82662306a36Sopenharmony_ci	u16 init_group_id;
82762306a36Sopenharmony_ci	u32 metadata_cap;
82862306a36Sopenharmony_ci};
82962306a36Sopenharmony_ci
83062306a36Sopenharmony_ci/* All traps must be documented in
83162306a36Sopenharmony_ci * Documentation/networking/devlink/devlink-trap.rst
83262306a36Sopenharmony_ci */
83362306a36Sopenharmony_cienum devlink_trap_generic_id {
83462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
83562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
83662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
83762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
83862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
83962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
84062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
84162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
84262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
84362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
84462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
84562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_DIP_LB,
84662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_SIP_MC,
84762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_SIP_LB,
84862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
84962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
85062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
85162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
85262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
85362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
85462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_RPF,
85562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
85662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
85762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
85862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
85962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
86062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
86162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
86262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
86362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_STP,
86462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_LACP,
86562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_LLDP,
86662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
86762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
86862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
86962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
87062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
87162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
87262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
87362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
87462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
87562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
87662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
87762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
87862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
87962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
88062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
88162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
88262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
88362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
88462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
88562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
88662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
88762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
88862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
88962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
89062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
89162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
89262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_UC_LB,
89362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
89462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
89562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
89662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
89762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
89862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
89962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
90062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
90162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
90262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
90362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
90462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
90562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
90662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
90762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
90862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
90962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
91062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
91162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
91262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
91362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
91462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
91562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
91662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
91762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
91862306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
91962306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
92062306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
92162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
92262306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
92362306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
92462306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_NEXTHOP,
92562306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER,
92662306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_EAPOL,
92762306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_LOCKED_PORT,
92862306a36Sopenharmony_ci
92962306a36Sopenharmony_ci	/* Add new generic trap IDs above */
93062306a36Sopenharmony_ci	__DEVLINK_TRAP_GENERIC_ID_MAX,
93162306a36Sopenharmony_ci	DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
93262306a36Sopenharmony_ci};
93362306a36Sopenharmony_ci
93462306a36Sopenharmony_ci/* All trap groups must be documented in
93562306a36Sopenharmony_ci * Documentation/networking/devlink/devlink-trap.rst
93662306a36Sopenharmony_ci */
93762306a36Sopenharmony_cienum devlink_trap_group_generic_id {
93862306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
93962306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
94062306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
94162306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
94262306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
94362306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
94462306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
94562306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
94662306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
94762306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
94862306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
94962306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
95062306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
95162306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
95262306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
95362306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
95462306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
95562306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
95662306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
95762306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
95862306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
95962306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
96062306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
96162306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
96262306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
96362306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
96462306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_EAPOL,
96562306a36Sopenharmony_ci
96662306a36Sopenharmony_ci	/* Add new generic trap group IDs above */
96762306a36Sopenharmony_ci	__DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
96862306a36Sopenharmony_ci	DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
96962306a36Sopenharmony_ci		__DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
97062306a36Sopenharmony_ci};
97162306a36Sopenharmony_ci
97262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
97362306a36Sopenharmony_ci	"source_mac_is_multicast"
97462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
97562306a36Sopenharmony_ci	"vlan_tag_mismatch"
97662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
97762306a36Sopenharmony_ci	"ingress_vlan_filter"
97862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
97962306a36Sopenharmony_ci	"ingress_spanning_tree_filter"
98062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
98162306a36Sopenharmony_ci	"port_list_is_empty"
98262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
98362306a36Sopenharmony_ci	"port_loopback_filter"
98462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
98562306a36Sopenharmony_ci	"blackhole_route"
98662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
98762306a36Sopenharmony_ci	"ttl_value_is_too_small"
98862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
98962306a36Sopenharmony_ci	"tail_drop"
99062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
99162306a36Sopenharmony_ci	"non_ip"
99262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
99362306a36Sopenharmony_ci	"uc_dip_over_mc_dmac"
99462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
99562306a36Sopenharmony_ci	"dip_is_loopback_address"
99662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
99762306a36Sopenharmony_ci	"sip_is_mc"
99862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
99962306a36Sopenharmony_ci	"sip_is_loopback_address"
100062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
100162306a36Sopenharmony_ci	"ip_header_corrupted"
100262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
100362306a36Sopenharmony_ci	"ipv4_sip_is_limited_bc"
100462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
100562306a36Sopenharmony_ci	"ipv6_mc_dip_reserved_scope"
100662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
100762306a36Sopenharmony_ci	"ipv6_mc_dip_interface_local_scope"
100862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
100962306a36Sopenharmony_ci	"mtu_value_is_too_small"
101062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
101162306a36Sopenharmony_ci	"unresolved_neigh"
101262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_RPF \
101362306a36Sopenharmony_ci	"mc_reverse_path_forwarding"
101462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
101562306a36Sopenharmony_ci	"reject_route"
101662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
101762306a36Sopenharmony_ci	"ipv4_lpm_miss"
101862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
101962306a36Sopenharmony_ci	"ipv6_lpm_miss"
102062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
102162306a36Sopenharmony_ci	"non_routable_packet"
102262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
102362306a36Sopenharmony_ci	"decap_error"
102462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
102562306a36Sopenharmony_ci	"overlay_smac_is_mc"
102662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
102762306a36Sopenharmony_ci	"ingress_flow_action_drop"
102862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
102962306a36Sopenharmony_ci	"egress_flow_action_drop"
103062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_STP \
103162306a36Sopenharmony_ci	"stp"
103262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_LACP \
103362306a36Sopenharmony_ci	"lacp"
103462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
103562306a36Sopenharmony_ci	"lldp"
103662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
103762306a36Sopenharmony_ci	"igmp_query"
103862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
103962306a36Sopenharmony_ci	"igmp_v1_report"
104062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
104162306a36Sopenharmony_ci	"igmp_v2_report"
104262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
104362306a36Sopenharmony_ci	"igmp_v3_report"
104462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
104562306a36Sopenharmony_ci	"igmp_v2_leave"
104662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
104762306a36Sopenharmony_ci	"mld_query"
104862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
104962306a36Sopenharmony_ci	"mld_v1_report"
105062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
105162306a36Sopenharmony_ci	"mld_v2_report"
105262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
105362306a36Sopenharmony_ci	"mld_v1_done"
105462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
105562306a36Sopenharmony_ci	"ipv4_dhcp"
105662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
105762306a36Sopenharmony_ci	"ipv6_dhcp"
105862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
105962306a36Sopenharmony_ci	"arp_request"
106062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
106162306a36Sopenharmony_ci	"arp_response"
106262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
106362306a36Sopenharmony_ci	"arp_overlay"
106462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
106562306a36Sopenharmony_ci	"ipv6_neigh_solicit"
106662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
106762306a36Sopenharmony_ci	"ipv6_neigh_advert"
106862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
106962306a36Sopenharmony_ci	"ipv4_bfd"
107062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
107162306a36Sopenharmony_ci	"ipv6_bfd"
107262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
107362306a36Sopenharmony_ci	"ipv4_ospf"
107462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
107562306a36Sopenharmony_ci	"ipv6_ospf"
107662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
107762306a36Sopenharmony_ci	"ipv4_bgp"
107862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
107962306a36Sopenharmony_ci	"ipv6_bgp"
108062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
108162306a36Sopenharmony_ci	"ipv4_vrrp"
108262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
108362306a36Sopenharmony_ci	"ipv6_vrrp"
108462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
108562306a36Sopenharmony_ci	"ipv4_pim"
108662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
108762306a36Sopenharmony_ci	"ipv6_pim"
108862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
108962306a36Sopenharmony_ci	"uc_loopback"
109062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
109162306a36Sopenharmony_ci	"local_route"
109262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
109362306a36Sopenharmony_ci	"external_route"
109462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
109562306a36Sopenharmony_ci	"ipv6_uc_dip_link_local_scope"
109662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
109762306a36Sopenharmony_ci	"ipv6_dip_all_nodes"
109862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
109962306a36Sopenharmony_ci	"ipv6_dip_all_routers"
110062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
110162306a36Sopenharmony_ci	"ipv6_router_solicit"
110262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
110362306a36Sopenharmony_ci	"ipv6_router_advert"
110462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
110562306a36Sopenharmony_ci	"ipv6_redirect"
110662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
110762306a36Sopenharmony_ci	"ipv4_router_alert"
110862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
110962306a36Sopenharmony_ci	"ipv6_router_alert"
111062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
111162306a36Sopenharmony_ci	"ptp_event"
111262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
111362306a36Sopenharmony_ci	"ptp_general"
111462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
111562306a36Sopenharmony_ci	"flow_action_sample"
111662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
111762306a36Sopenharmony_ci	"flow_action_trap"
111862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
111962306a36Sopenharmony_ci	"early_drop"
112062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
112162306a36Sopenharmony_ci	"vxlan_parsing"
112262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
112362306a36Sopenharmony_ci	"llc_snap_parsing"
112462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
112562306a36Sopenharmony_ci	"vlan_parsing"
112662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
112762306a36Sopenharmony_ci	"pppoe_ppp_parsing"
112862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
112962306a36Sopenharmony_ci	"mpls_parsing"
113062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
113162306a36Sopenharmony_ci	"arp_parsing"
113262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
113362306a36Sopenharmony_ci	"ip_1_parsing"
113462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
113562306a36Sopenharmony_ci	"ip_n_parsing"
113662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
113762306a36Sopenharmony_ci	"gre_parsing"
113862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
113962306a36Sopenharmony_ci	"udp_parsing"
114062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
114162306a36Sopenharmony_ci	"tcp_parsing"
114262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
114362306a36Sopenharmony_ci	"ipsec_parsing"
114462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
114562306a36Sopenharmony_ci	"sctp_parsing"
114662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
114762306a36Sopenharmony_ci	"dccp_parsing"
114862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
114962306a36Sopenharmony_ci	"gtp_parsing"
115062306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
115162306a36Sopenharmony_ci	"esp_parsing"
115262306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_NEXTHOP \
115362306a36Sopenharmony_ci	"blackhole_nexthop"
115462306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_DMAC_FILTER \
115562306a36Sopenharmony_ci	"dmac_filter"
115662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_EAPOL \
115762306a36Sopenharmony_ci	"eapol"
115862306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC_NAME_LOCKED_PORT \
115962306a36Sopenharmony_ci	"locked_port"
116062306a36Sopenharmony_ci
116162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
116262306a36Sopenharmony_ci	"l2_drops"
116362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
116462306a36Sopenharmony_ci	"l3_drops"
116562306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
116662306a36Sopenharmony_ci	"l3_exceptions"
116762306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
116862306a36Sopenharmony_ci	"buffer_drops"
116962306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
117062306a36Sopenharmony_ci	"tunnel_drops"
117162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
117262306a36Sopenharmony_ci	"acl_drops"
117362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
117462306a36Sopenharmony_ci	"stp"
117562306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
117662306a36Sopenharmony_ci	"lacp"
117762306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
117862306a36Sopenharmony_ci	"lldp"
117962306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING  \
118062306a36Sopenharmony_ci	"mc_snooping"
118162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
118262306a36Sopenharmony_ci	"dhcp"
118362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
118462306a36Sopenharmony_ci	"neigh_discovery"
118562306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
118662306a36Sopenharmony_ci	"bfd"
118762306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
118862306a36Sopenharmony_ci	"ospf"
118962306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
119062306a36Sopenharmony_ci	"bgp"
119162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
119262306a36Sopenharmony_ci	"vrrp"
119362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
119462306a36Sopenharmony_ci	"pim"
119562306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
119662306a36Sopenharmony_ci	"uc_loopback"
119762306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
119862306a36Sopenharmony_ci	"local_delivery"
119962306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
120062306a36Sopenharmony_ci	"external_delivery"
120162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
120262306a36Sopenharmony_ci	"ipv6"
120362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
120462306a36Sopenharmony_ci	"ptp_event"
120562306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
120662306a36Sopenharmony_ci	"ptp_general"
120762306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
120862306a36Sopenharmony_ci	"acl_sample"
120962306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
121062306a36Sopenharmony_ci	"acl_trap"
121162306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
121262306a36Sopenharmony_ci	"parser_error_drops"
121362306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EAPOL \
121462306a36Sopenharmony_ci	"eapol"
121562306a36Sopenharmony_ci
121662306a36Sopenharmony_ci#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id,	      \
121762306a36Sopenharmony_ci			     _metadata_cap)				      \
121862306a36Sopenharmony_ci	{								      \
121962306a36Sopenharmony_ci		.type = DEVLINK_TRAP_TYPE_##_type,			      \
122062306a36Sopenharmony_ci		.init_action = DEVLINK_TRAP_ACTION_##_init_action,	      \
122162306a36Sopenharmony_ci		.generic = true,					      \
122262306a36Sopenharmony_ci		.id = DEVLINK_TRAP_GENERIC_ID_##_id,			      \
122362306a36Sopenharmony_ci		.name = DEVLINK_TRAP_GENERIC_NAME_##_id,		      \
122462306a36Sopenharmony_ci		.init_group_id = _group_id,				      \
122562306a36Sopenharmony_ci		.metadata_cap = _metadata_cap,				      \
122662306a36Sopenharmony_ci	}
122762306a36Sopenharmony_ci
122862306a36Sopenharmony_ci#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id,	      \
122962306a36Sopenharmony_ci			    _metadata_cap)				      \
123062306a36Sopenharmony_ci	{								      \
123162306a36Sopenharmony_ci		.type = DEVLINK_TRAP_TYPE_##_type,			      \
123262306a36Sopenharmony_ci		.init_action = DEVLINK_TRAP_ACTION_##_init_action,	      \
123362306a36Sopenharmony_ci		.generic = false,					      \
123462306a36Sopenharmony_ci		.id = _id,						      \
123562306a36Sopenharmony_ci		.name = _name,						      \
123662306a36Sopenharmony_ci		.init_group_id = _group_id,				      \
123762306a36Sopenharmony_ci		.metadata_cap = _metadata_cap,				      \
123862306a36Sopenharmony_ci	}
123962306a36Sopenharmony_ci
124062306a36Sopenharmony_ci#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id)			      \
124162306a36Sopenharmony_ci	{								      \
124262306a36Sopenharmony_ci		.name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id,		      \
124362306a36Sopenharmony_ci		.id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id,		      \
124462306a36Sopenharmony_ci		.generic = true,					      \
124562306a36Sopenharmony_ci		.init_policer_id = _policer_id,				      \
124662306a36Sopenharmony_ci	}
124762306a36Sopenharmony_ci
124862306a36Sopenharmony_ci#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate,	      \
124962306a36Sopenharmony_ci			     _max_burst, _min_burst)			      \
125062306a36Sopenharmony_ci	{								      \
125162306a36Sopenharmony_ci		.id = _id,						      \
125262306a36Sopenharmony_ci		.init_rate = _rate,					      \
125362306a36Sopenharmony_ci		.init_burst = _burst,					      \
125462306a36Sopenharmony_ci		.max_rate = _max_rate,					      \
125562306a36Sopenharmony_ci		.min_rate = _min_rate,					      \
125662306a36Sopenharmony_ci		.max_burst = _max_burst,				      \
125762306a36Sopenharmony_ci		.min_burst = _min_burst,				      \
125862306a36Sopenharmony_ci	}
125962306a36Sopenharmony_ci
126062306a36Sopenharmony_cienum {
126162306a36Sopenharmony_ci	/* device supports reload operations */
126262306a36Sopenharmony_ci	DEVLINK_F_RELOAD = 1UL << 0,
126362306a36Sopenharmony_ci};
126462306a36Sopenharmony_ci
126562306a36Sopenharmony_cistruct devlink_ops {
126662306a36Sopenharmony_ci	/**
126762306a36Sopenharmony_ci	 * @supported_flash_update_params:
126862306a36Sopenharmony_ci	 * mask of parameters supported by the driver's .flash_update
126962306a36Sopenharmony_ci	 * implementation.
127062306a36Sopenharmony_ci	 */
127162306a36Sopenharmony_ci	u32 supported_flash_update_params;
127262306a36Sopenharmony_ci	unsigned long reload_actions;
127362306a36Sopenharmony_ci	unsigned long reload_limits;
127462306a36Sopenharmony_ci	int (*reload_down)(struct devlink *devlink, bool netns_change,
127562306a36Sopenharmony_ci			   enum devlink_reload_action action,
127662306a36Sopenharmony_ci			   enum devlink_reload_limit limit,
127762306a36Sopenharmony_ci			   struct netlink_ext_ack *extack);
127862306a36Sopenharmony_ci	int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action,
127962306a36Sopenharmony_ci			 enum devlink_reload_limit limit, u32 *actions_performed,
128062306a36Sopenharmony_ci			 struct netlink_ext_ack *extack);
128162306a36Sopenharmony_ci	int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
128262306a36Sopenharmony_ci			   u16 pool_index,
128362306a36Sopenharmony_ci			   struct devlink_sb_pool_info *pool_info);
128462306a36Sopenharmony_ci	int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
128562306a36Sopenharmony_ci			   u16 pool_index, u32 size,
128662306a36Sopenharmony_ci			   enum devlink_sb_threshold_type threshold_type,
128762306a36Sopenharmony_ci			   struct netlink_ext_ack *extack);
128862306a36Sopenharmony_ci	int (*sb_port_pool_get)(struct devlink_port *devlink_port,
128962306a36Sopenharmony_ci				unsigned int sb_index, u16 pool_index,
129062306a36Sopenharmony_ci				u32 *p_threshold);
129162306a36Sopenharmony_ci	int (*sb_port_pool_set)(struct devlink_port *devlink_port,
129262306a36Sopenharmony_ci				unsigned int sb_index, u16 pool_index,
129362306a36Sopenharmony_ci				u32 threshold, struct netlink_ext_ack *extack);
129462306a36Sopenharmony_ci	int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
129562306a36Sopenharmony_ci				   unsigned int sb_index,
129662306a36Sopenharmony_ci				   u16 tc_index,
129762306a36Sopenharmony_ci				   enum devlink_sb_pool_type pool_type,
129862306a36Sopenharmony_ci				   u16 *p_pool_index, u32 *p_threshold);
129962306a36Sopenharmony_ci	int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
130062306a36Sopenharmony_ci				   unsigned int sb_index,
130162306a36Sopenharmony_ci				   u16 tc_index,
130262306a36Sopenharmony_ci				   enum devlink_sb_pool_type pool_type,
130362306a36Sopenharmony_ci				   u16 pool_index, u32 threshold,
130462306a36Sopenharmony_ci				   struct netlink_ext_ack *extack);
130562306a36Sopenharmony_ci	int (*sb_occ_snapshot)(struct devlink *devlink,
130662306a36Sopenharmony_ci			       unsigned int sb_index);
130762306a36Sopenharmony_ci	int (*sb_occ_max_clear)(struct devlink *devlink,
130862306a36Sopenharmony_ci				unsigned int sb_index);
130962306a36Sopenharmony_ci	int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
131062306a36Sopenharmony_ci				    unsigned int sb_index, u16 pool_index,
131162306a36Sopenharmony_ci				    u32 *p_cur, u32 *p_max);
131262306a36Sopenharmony_ci	int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
131362306a36Sopenharmony_ci				       unsigned int sb_index,
131462306a36Sopenharmony_ci				       u16 tc_index,
131562306a36Sopenharmony_ci				       enum devlink_sb_pool_type pool_type,
131662306a36Sopenharmony_ci				       u32 *p_cur, u32 *p_max);
131762306a36Sopenharmony_ci
131862306a36Sopenharmony_ci	int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
131962306a36Sopenharmony_ci	int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
132062306a36Sopenharmony_ci				struct netlink_ext_ack *extack);
132162306a36Sopenharmony_ci	int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
132262306a36Sopenharmony_ci	int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
132362306a36Sopenharmony_ci				       struct netlink_ext_ack *extack);
132462306a36Sopenharmony_ci	int (*eswitch_encap_mode_get)(struct devlink *devlink,
132562306a36Sopenharmony_ci				      enum devlink_eswitch_encap_mode *p_encap_mode);
132662306a36Sopenharmony_ci	int (*eswitch_encap_mode_set)(struct devlink *devlink,
132762306a36Sopenharmony_ci				      enum devlink_eswitch_encap_mode encap_mode,
132862306a36Sopenharmony_ci				      struct netlink_ext_ack *extack);
132962306a36Sopenharmony_ci	int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
133062306a36Sopenharmony_ci			struct netlink_ext_ack *extack);
133162306a36Sopenharmony_ci	/**
133262306a36Sopenharmony_ci	 * @flash_update: Device flash update function
133362306a36Sopenharmony_ci	 *
133462306a36Sopenharmony_ci	 * Used to perform a flash update for the device. The set of
133562306a36Sopenharmony_ci	 * parameters supported by the driver should be set in
133662306a36Sopenharmony_ci	 * supported_flash_update_params.
133762306a36Sopenharmony_ci	 */
133862306a36Sopenharmony_ci	int (*flash_update)(struct devlink *devlink,
133962306a36Sopenharmony_ci			    struct devlink_flash_update_params *params,
134062306a36Sopenharmony_ci			    struct netlink_ext_ack *extack);
134162306a36Sopenharmony_ci	/**
134262306a36Sopenharmony_ci	 * @trap_init: Trap initialization function.
134362306a36Sopenharmony_ci	 *
134462306a36Sopenharmony_ci	 * Should be used by device drivers to initialize the trap in the
134562306a36Sopenharmony_ci	 * underlying device. Drivers should also store the provided trap
134662306a36Sopenharmony_ci	 * context, so that they could efficiently pass it to
134762306a36Sopenharmony_ci	 * devlink_trap_report() when the trap is triggered.
134862306a36Sopenharmony_ci	 */
134962306a36Sopenharmony_ci	int (*trap_init)(struct devlink *devlink,
135062306a36Sopenharmony_ci			 const struct devlink_trap *trap, void *trap_ctx);
135162306a36Sopenharmony_ci	/**
135262306a36Sopenharmony_ci	 * @trap_fini: Trap de-initialization function.
135362306a36Sopenharmony_ci	 *
135462306a36Sopenharmony_ci	 * Should be used by device drivers to de-initialize the trap in the
135562306a36Sopenharmony_ci	 * underlying device.
135662306a36Sopenharmony_ci	 */
135762306a36Sopenharmony_ci	void (*trap_fini)(struct devlink *devlink,
135862306a36Sopenharmony_ci			  const struct devlink_trap *trap, void *trap_ctx);
135962306a36Sopenharmony_ci	/**
136062306a36Sopenharmony_ci	 * @trap_action_set: Trap action set function.
136162306a36Sopenharmony_ci	 */
136262306a36Sopenharmony_ci	int (*trap_action_set)(struct devlink *devlink,
136362306a36Sopenharmony_ci			       const struct devlink_trap *trap,
136462306a36Sopenharmony_ci			       enum devlink_trap_action action,
136562306a36Sopenharmony_ci			       struct netlink_ext_ack *extack);
136662306a36Sopenharmony_ci	/**
136762306a36Sopenharmony_ci	 * @trap_group_init: Trap group initialization function.
136862306a36Sopenharmony_ci	 *
136962306a36Sopenharmony_ci	 * Should be used by device drivers to initialize the trap group in the
137062306a36Sopenharmony_ci	 * underlying device.
137162306a36Sopenharmony_ci	 */
137262306a36Sopenharmony_ci	int (*trap_group_init)(struct devlink *devlink,
137362306a36Sopenharmony_ci			       const struct devlink_trap_group *group);
137462306a36Sopenharmony_ci	/**
137562306a36Sopenharmony_ci	 * @trap_group_set: Trap group parameters set function.
137662306a36Sopenharmony_ci	 *
137762306a36Sopenharmony_ci	 * Note: @policer can be NULL when a policer is being unbound from
137862306a36Sopenharmony_ci	 * @group.
137962306a36Sopenharmony_ci	 */
138062306a36Sopenharmony_ci	int (*trap_group_set)(struct devlink *devlink,
138162306a36Sopenharmony_ci			      const struct devlink_trap_group *group,
138262306a36Sopenharmony_ci			      const struct devlink_trap_policer *policer,
138362306a36Sopenharmony_ci			      struct netlink_ext_ack *extack);
138462306a36Sopenharmony_ci	/**
138562306a36Sopenharmony_ci	 * @trap_group_action_set: Trap group action set function.
138662306a36Sopenharmony_ci	 *
138762306a36Sopenharmony_ci	 * If this callback is populated, it will take precedence over looping
138862306a36Sopenharmony_ci	 * over all traps in a group and calling .trap_action_set().
138962306a36Sopenharmony_ci	 */
139062306a36Sopenharmony_ci	int (*trap_group_action_set)(struct devlink *devlink,
139162306a36Sopenharmony_ci				     const struct devlink_trap_group *group,
139262306a36Sopenharmony_ci				     enum devlink_trap_action action,
139362306a36Sopenharmony_ci				     struct netlink_ext_ack *extack);
139462306a36Sopenharmony_ci	/**
139562306a36Sopenharmony_ci	 * @trap_drop_counter_get: Trap drop counter get function.
139662306a36Sopenharmony_ci	 *
139762306a36Sopenharmony_ci	 * Should be used by device drivers to report number of packets
139862306a36Sopenharmony_ci	 * that have been dropped, and cannot be passed to the devlink
139962306a36Sopenharmony_ci	 * subsystem by the underlying device.
140062306a36Sopenharmony_ci	 */
140162306a36Sopenharmony_ci	int (*trap_drop_counter_get)(struct devlink *devlink,
140262306a36Sopenharmony_ci				     const struct devlink_trap *trap,
140362306a36Sopenharmony_ci				     u64 *p_drops);
140462306a36Sopenharmony_ci	/**
140562306a36Sopenharmony_ci	 * @trap_policer_init: Trap policer initialization function.
140662306a36Sopenharmony_ci	 *
140762306a36Sopenharmony_ci	 * Should be used by device drivers to initialize the trap policer in
140862306a36Sopenharmony_ci	 * the underlying device.
140962306a36Sopenharmony_ci	 */
141062306a36Sopenharmony_ci	int (*trap_policer_init)(struct devlink *devlink,
141162306a36Sopenharmony_ci				 const struct devlink_trap_policer *policer);
141262306a36Sopenharmony_ci	/**
141362306a36Sopenharmony_ci	 * @trap_policer_fini: Trap policer de-initialization function.
141462306a36Sopenharmony_ci	 *
141562306a36Sopenharmony_ci	 * Should be used by device drivers to de-initialize the trap policer
141662306a36Sopenharmony_ci	 * in the underlying device.
141762306a36Sopenharmony_ci	 */
141862306a36Sopenharmony_ci	void (*trap_policer_fini)(struct devlink *devlink,
141962306a36Sopenharmony_ci				  const struct devlink_trap_policer *policer);
142062306a36Sopenharmony_ci	/**
142162306a36Sopenharmony_ci	 * @trap_policer_set: Trap policer parameters set function.
142262306a36Sopenharmony_ci	 */
142362306a36Sopenharmony_ci	int (*trap_policer_set)(struct devlink *devlink,
142462306a36Sopenharmony_ci				const struct devlink_trap_policer *policer,
142562306a36Sopenharmony_ci				u64 rate, u64 burst,
142662306a36Sopenharmony_ci				struct netlink_ext_ack *extack);
142762306a36Sopenharmony_ci	/**
142862306a36Sopenharmony_ci	 * @trap_policer_counter_get: Trap policer counter get function.
142962306a36Sopenharmony_ci	 *
143062306a36Sopenharmony_ci	 * Should be used by device drivers to report number of packets dropped
143162306a36Sopenharmony_ci	 * by the policer.
143262306a36Sopenharmony_ci	 */
143362306a36Sopenharmony_ci	int (*trap_policer_counter_get)(struct devlink *devlink,
143462306a36Sopenharmony_ci					const struct devlink_trap_policer *policer,
143562306a36Sopenharmony_ci					u64 *p_drops);
143662306a36Sopenharmony_ci	/**
143762306a36Sopenharmony_ci	 * port_new() - Add a new port function of a specified flavor
143862306a36Sopenharmony_ci	 * @devlink: Devlink instance
143962306a36Sopenharmony_ci	 * @attrs: attributes of the new port
144062306a36Sopenharmony_ci	 * @extack: extack for reporting error messages
144162306a36Sopenharmony_ci	 * @devlink_port: pointer to store new devlink port pointer
144262306a36Sopenharmony_ci	 *
144362306a36Sopenharmony_ci	 * Devlink core will call this device driver function upon user request
144462306a36Sopenharmony_ci	 * to create a new port function of a specified flavor and optional
144562306a36Sopenharmony_ci	 * attributes
144662306a36Sopenharmony_ci	 *
144762306a36Sopenharmony_ci	 * Notes:
144862306a36Sopenharmony_ci	 *	- On success, drivers must register a port with devlink core
144962306a36Sopenharmony_ci	 *
145062306a36Sopenharmony_ci	 * Return: 0 on success, negative value otherwise.
145162306a36Sopenharmony_ci	 */
145262306a36Sopenharmony_ci	int (*port_new)(struct devlink *devlink,
145362306a36Sopenharmony_ci			const struct devlink_port_new_attrs *attrs,
145462306a36Sopenharmony_ci			struct netlink_ext_ack *extack,
145562306a36Sopenharmony_ci			struct devlink_port **devlink_port);
145662306a36Sopenharmony_ci
145762306a36Sopenharmony_ci	/**
145862306a36Sopenharmony_ci	 * Rate control callbacks.
145962306a36Sopenharmony_ci	 */
146062306a36Sopenharmony_ci	int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
146162306a36Sopenharmony_ci				      u64 tx_share, struct netlink_ext_ack *extack);
146262306a36Sopenharmony_ci	int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
146362306a36Sopenharmony_ci				    u64 tx_max, struct netlink_ext_ack *extack);
146462306a36Sopenharmony_ci	int (*rate_leaf_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
146562306a36Sopenharmony_ci					 u32 tx_priority, struct netlink_ext_ack *extack);
146662306a36Sopenharmony_ci	int (*rate_leaf_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
146762306a36Sopenharmony_ci				       u32 tx_weight, struct netlink_ext_ack *extack);
146862306a36Sopenharmony_ci	int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
146962306a36Sopenharmony_ci				      u64 tx_share, struct netlink_ext_ack *extack);
147062306a36Sopenharmony_ci	int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
147162306a36Sopenharmony_ci				    u64 tx_max, struct netlink_ext_ack *extack);
147262306a36Sopenharmony_ci	int (*rate_node_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv,
147362306a36Sopenharmony_ci					 u32 tx_priority, struct netlink_ext_ack *extack);
147462306a36Sopenharmony_ci	int (*rate_node_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv,
147562306a36Sopenharmony_ci				       u32 tx_weight, struct netlink_ext_ack *extack);
147662306a36Sopenharmony_ci	int (*rate_node_new)(struct devlink_rate *rate_node, void **priv,
147762306a36Sopenharmony_ci			     struct netlink_ext_ack *extack);
147862306a36Sopenharmony_ci	int (*rate_node_del)(struct devlink_rate *rate_node, void *priv,
147962306a36Sopenharmony_ci			     struct netlink_ext_ack *extack);
148062306a36Sopenharmony_ci	int (*rate_leaf_parent_set)(struct devlink_rate *child,
148162306a36Sopenharmony_ci				    struct devlink_rate *parent,
148262306a36Sopenharmony_ci				    void *priv_child, void *priv_parent,
148362306a36Sopenharmony_ci				    struct netlink_ext_ack *extack);
148462306a36Sopenharmony_ci	int (*rate_node_parent_set)(struct devlink_rate *child,
148562306a36Sopenharmony_ci				    struct devlink_rate *parent,
148662306a36Sopenharmony_ci				    void *priv_child, void *priv_parent,
148762306a36Sopenharmony_ci				    struct netlink_ext_ack *extack);
148862306a36Sopenharmony_ci	/**
148962306a36Sopenharmony_ci	 * selftests_check() - queries if selftest is supported
149062306a36Sopenharmony_ci	 * @devlink: devlink instance
149162306a36Sopenharmony_ci	 * @id: test index
149262306a36Sopenharmony_ci	 * @extack: extack for reporting error messages
149362306a36Sopenharmony_ci	 *
149462306a36Sopenharmony_ci	 * Return: true if test is supported by the driver
149562306a36Sopenharmony_ci	 */
149662306a36Sopenharmony_ci	bool (*selftest_check)(struct devlink *devlink, unsigned int id,
149762306a36Sopenharmony_ci			       struct netlink_ext_ack *extack);
149862306a36Sopenharmony_ci	/**
149962306a36Sopenharmony_ci	 * selftest_run() - Runs a selftest
150062306a36Sopenharmony_ci	 * @devlink: devlink instance
150162306a36Sopenharmony_ci	 * @id: test index
150262306a36Sopenharmony_ci	 * @extack: extack for reporting error messages
150362306a36Sopenharmony_ci	 *
150462306a36Sopenharmony_ci	 * Return: status of the test
150562306a36Sopenharmony_ci	 */
150662306a36Sopenharmony_ci	enum devlink_selftest_status
150762306a36Sopenharmony_ci	(*selftest_run)(struct devlink *devlink, unsigned int id,
150862306a36Sopenharmony_ci			struct netlink_ext_ack *extack);
150962306a36Sopenharmony_ci};
151062306a36Sopenharmony_ci
151162306a36Sopenharmony_civoid *devlink_priv(struct devlink *devlink);
151262306a36Sopenharmony_cistruct devlink *priv_to_devlink(void *priv);
151362306a36Sopenharmony_cistruct device *devlink_to_dev(const struct devlink *devlink);
151462306a36Sopenharmony_ci
151562306a36Sopenharmony_ci/* Devlink instance explicit locking */
151662306a36Sopenharmony_civoid devl_lock(struct devlink *devlink);
151762306a36Sopenharmony_ciint devl_trylock(struct devlink *devlink);
151862306a36Sopenharmony_civoid devl_unlock(struct devlink *devlink);
151962306a36Sopenharmony_civoid devl_assert_locked(struct devlink *devlink);
152062306a36Sopenharmony_cibool devl_lock_is_held(struct devlink *devlink);
152162306a36Sopenharmony_ci
152262306a36Sopenharmony_cistruct ib_device;
152362306a36Sopenharmony_ci
152462306a36Sopenharmony_cistruct net *devlink_net(const struct devlink *devlink);
152562306a36Sopenharmony_ci/* This call is intended for software devices that can create
152662306a36Sopenharmony_ci * devlink instances in other namespaces than init_net.
152762306a36Sopenharmony_ci *
152862306a36Sopenharmony_ci * Drivers that operate on real HW must use devlink_alloc() instead.
152962306a36Sopenharmony_ci */
153062306a36Sopenharmony_cistruct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
153162306a36Sopenharmony_ci				 size_t priv_size, struct net *net,
153262306a36Sopenharmony_ci				 struct device *dev);
153362306a36Sopenharmony_cistatic inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
153462306a36Sopenharmony_ci					    size_t priv_size,
153562306a36Sopenharmony_ci					    struct device *dev)
153662306a36Sopenharmony_ci{
153762306a36Sopenharmony_ci	return devlink_alloc_ns(ops, priv_size, &init_net, dev);
153862306a36Sopenharmony_ci}
153962306a36Sopenharmony_ci
154062306a36Sopenharmony_ciint devl_register(struct devlink *devlink);
154162306a36Sopenharmony_civoid devl_unregister(struct devlink *devlink);
154262306a36Sopenharmony_civoid devlink_register(struct devlink *devlink);
154362306a36Sopenharmony_civoid devlink_unregister(struct devlink *devlink);
154462306a36Sopenharmony_civoid devlink_free(struct devlink *devlink);
154562306a36Sopenharmony_ci
154662306a36Sopenharmony_ci/**
154762306a36Sopenharmony_ci * struct devlink_port_ops - Port operations
154862306a36Sopenharmony_ci * @port_split: Callback used to split the port into multiple ones.
154962306a36Sopenharmony_ci * @port_unsplit: Callback used to unsplit the port group back into
155062306a36Sopenharmony_ci *		  a single port.
155162306a36Sopenharmony_ci * @port_type_set: Callback used to set a type of a port.
155262306a36Sopenharmony_ci * @port_del: Callback used to delete selected port along with related function.
155362306a36Sopenharmony_ci *	      Devlink core calls this upon user request to delete
155462306a36Sopenharmony_ci *	      a port previously created by devlink_ops->port_new().
155562306a36Sopenharmony_ci * @port_fn_hw_addr_get: Callback used to set port function's hardware address.
155662306a36Sopenharmony_ci *			 Should be used by device drivers to report
155762306a36Sopenharmony_ci *			 the hardware address of a function managed
155862306a36Sopenharmony_ci *			 by the devlink port.
155962306a36Sopenharmony_ci * @port_fn_hw_addr_set: Callback used to set port function's hardware address.
156062306a36Sopenharmony_ci *			 Should be used by device drivers to set the hardware
156162306a36Sopenharmony_ci *			 address of a function managed by the devlink port.
156262306a36Sopenharmony_ci * @port_fn_roce_get: Callback used to get port function's RoCE capability.
156362306a36Sopenharmony_ci *		      Should be used by device drivers to report
156462306a36Sopenharmony_ci *		      the current state of RoCE capability of a function
156562306a36Sopenharmony_ci *		      managed by the devlink port.
156662306a36Sopenharmony_ci * @port_fn_roce_set: Callback used to set port function's RoCE capability.
156762306a36Sopenharmony_ci *		      Should be used by device drivers to enable/disable
156862306a36Sopenharmony_ci *		      RoCE capability of a function managed
156962306a36Sopenharmony_ci *		      by the devlink port.
157062306a36Sopenharmony_ci * @port_fn_migratable_get: Callback used to get port function's migratable
157162306a36Sopenharmony_ci *			    capability. Should be used by device drivers
157262306a36Sopenharmony_ci *			    to report the current state of migratable capability
157362306a36Sopenharmony_ci *			    of a function managed by the devlink port.
157462306a36Sopenharmony_ci * @port_fn_migratable_set: Callback used to set port function's migratable
157562306a36Sopenharmony_ci *			    capability. Should be used by device drivers
157662306a36Sopenharmony_ci *			    to enable/disable migratable capability of
157762306a36Sopenharmony_ci *			    a function managed by the devlink port.
157862306a36Sopenharmony_ci * @port_fn_state_get: Callback used to get port function's state.
157962306a36Sopenharmony_ci *		       Should be used by device drivers to report
158062306a36Sopenharmony_ci *		       the current admin and operational state of a
158162306a36Sopenharmony_ci *		       function managed by the devlink port.
158262306a36Sopenharmony_ci * @port_fn_state_set: Callback used to get port function's state.
158362306a36Sopenharmony_ci *		       Should be used by device drivers set
158462306a36Sopenharmony_ci *		       the admin state of a function managed
158562306a36Sopenharmony_ci *		       by the devlink port.
158662306a36Sopenharmony_ci * @port_fn_ipsec_crypto_get: Callback used to get port function's ipsec_crypto
158762306a36Sopenharmony_ci *			      capability. Should be used by device drivers
158862306a36Sopenharmony_ci *			      to report the current state of ipsec_crypto
158962306a36Sopenharmony_ci *			      capability of a function managed by the devlink
159062306a36Sopenharmony_ci *			      port.
159162306a36Sopenharmony_ci * @port_fn_ipsec_crypto_set: Callback used to set port function's ipsec_crypto
159262306a36Sopenharmony_ci *			      capability. Should be used by device drivers to
159362306a36Sopenharmony_ci *			      enable/disable ipsec_crypto capability of a
159462306a36Sopenharmony_ci *			      function managed by the devlink port.
159562306a36Sopenharmony_ci * @port_fn_ipsec_packet_get: Callback used to get port function's ipsec_packet
159662306a36Sopenharmony_ci *			      capability. Should be used by device drivers
159762306a36Sopenharmony_ci *			      to report the current state of ipsec_packet
159862306a36Sopenharmony_ci *			      capability of a function managed by the devlink
159962306a36Sopenharmony_ci *			      port.
160062306a36Sopenharmony_ci * @port_fn_ipsec_packet_set: Callback used to set port function's ipsec_packet
160162306a36Sopenharmony_ci *			      capability. Should be used by device drivers to
160262306a36Sopenharmony_ci *			      enable/disable ipsec_packet capability of a
160362306a36Sopenharmony_ci *			      function managed by the devlink port.
160462306a36Sopenharmony_ci *
160562306a36Sopenharmony_ci * Note: Driver should return -EOPNOTSUPP if it doesn't support
160662306a36Sopenharmony_ci * port function (@port_fn_*) handling for a particular port.
160762306a36Sopenharmony_ci */
160862306a36Sopenharmony_cistruct devlink_port_ops {
160962306a36Sopenharmony_ci	int (*port_split)(struct devlink *devlink, struct devlink_port *port,
161062306a36Sopenharmony_ci			  unsigned int count, struct netlink_ext_ack *extack);
161162306a36Sopenharmony_ci	int (*port_unsplit)(struct devlink *devlink, struct devlink_port *port,
161262306a36Sopenharmony_ci			    struct netlink_ext_ack *extack);
161362306a36Sopenharmony_ci	int (*port_type_set)(struct devlink_port *devlink_port,
161462306a36Sopenharmony_ci			     enum devlink_port_type port_type);
161562306a36Sopenharmony_ci	int (*port_del)(struct devlink *devlink, struct devlink_port *port,
161662306a36Sopenharmony_ci			struct netlink_ext_ack *extack);
161762306a36Sopenharmony_ci	int (*port_fn_hw_addr_get)(struct devlink_port *port, u8 *hw_addr,
161862306a36Sopenharmony_ci				   int *hw_addr_len,
161962306a36Sopenharmony_ci				   struct netlink_ext_ack *extack);
162062306a36Sopenharmony_ci	int (*port_fn_hw_addr_set)(struct devlink_port *port,
162162306a36Sopenharmony_ci				   const u8 *hw_addr, int hw_addr_len,
162262306a36Sopenharmony_ci				   struct netlink_ext_ack *extack);
162362306a36Sopenharmony_ci	int (*port_fn_roce_get)(struct devlink_port *devlink_port,
162462306a36Sopenharmony_ci				bool *is_enable,
162562306a36Sopenharmony_ci				struct netlink_ext_ack *extack);
162662306a36Sopenharmony_ci	int (*port_fn_roce_set)(struct devlink_port *devlink_port,
162762306a36Sopenharmony_ci				bool enable, struct netlink_ext_ack *extack);
162862306a36Sopenharmony_ci	int (*port_fn_migratable_get)(struct devlink_port *devlink_port,
162962306a36Sopenharmony_ci				      bool *is_enable,
163062306a36Sopenharmony_ci				      struct netlink_ext_ack *extack);
163162306a36Sopenharmony_ci	int (*port_fn_migratable_set)(struct devlink_port *devlink_port,
163262306a36Sopenharmony_ci				      bool enable,
163362306a36Sopenharmony_ci				      struct netlink_ext_ack *extack);
163462306a36Sopenharmony_ci	int (*port_fn_state_get)(struct devlink_port *port,
163562306a36Sopenharmony_ci				 enum devlink_port_fn_state *state,
163662306a36Sopenharmony_ci				 enum devlink_port_fn_opstate *opstate,
163762306a36Sopenharmony_ci				 struct netlink_ext_ack *extack);
163862306a36Sopenharmony_ci	int (*port_fn_state_set)(struct devlink_port *port,
163962306a36Sopenharmony_ci				 enum devlink_port_fn_state state,
164062306a36Sopenharmony_ci				 struct netlink_ext_ack *extack);
164162306a36Sopenharmony_ci	int (*port_fn_ipsec_crypto_get)(struct devlink_port *devlink_port,
164262306a36Sopenharmony_ci					bool *is_enable,
164362306a36Sopenharmony_ci					struct netlink_ext_ack *extack);
164462306a36Sopenharmony_ci	int (*port_fn_ipsec_crypto_set)(struct devlink_port *devlink_port,
164562306a36Sopenharmony_ci					bool enable,
164662306a36Sopenharmony_ci					struct netlink_ext_ack *extack);
164762306a36Sopenharmony_ci	int (*port_fn_ipsec_packet_get)(struct devlink_port *devlink_port,
164862306a36Sopenharmony_ci					bool *is_enable,
164962306a36Sopenharmony_ci					struct netlink_ext_ack *extack);
165062306a36Sopenharmony_ci	int (*port_fn_ipsec_packet_set)(struct devlink_port *devlink_port,
165162306a36Sopenharmony_ci					bool enable,
165262306a36Sopenharmony_ci					struct netlink_ext_ack *extack);
165362306a36Sopenharmony_ci};
165462306a36Sopenharmony_ci
165562306a36Sopenharmony_civoid devlink_port_init(struct devlink *devlink,
165662306a36Sopenharmony_ci		       struct devlink_port *devlink_port);
165762306a36Sopenharmony_civoid devlink_port_fini(struct devlink_port *devlink_port);
165862306a36Sopenharmony_ci
165962306a36Sopenharmony_ciint devl_port_register_with_ops(struct devlink *devlink,
166062306a36Sopenharmony_ci				struct devlink_port *devlink_port,
166162306a36Sopenharmony_ci				unsigned int port_index,
166262306a36Sopenharmony_ci				const struct devlink_port_ops *ops);
166362306a36Sopenharmony_ci
166462306a36Sopenharmony_cistatic inline int devl_port_register(struct devlink *devlink,
166562306a36Sopenharmony_ci				     struct devlink_port *devlink_port,
166662306a36Sopenharmony_ci				     unsigned int port_index)
166762306a36Sopenharmony_ci{
166862306a36Sopenharmony_ci	return devl_port_register_with_ops(devlink, devlink_port,
166962306a36Sopenharmony_ci					   port_index, NULL);
167062306a36Sopenharmony_ci}
167162306a36Sopenharmony_ci
167262306a36Sopenharmony_ciint devlink_port_register_with_ops(struct devlink *devlink,
167362306a36Sopenharmony_ci				   struct devlink_port *devlink_port,
167462306a36Sopenharmony_ci				   unsigned int port_index,
167562306a36Sopenharmony_ci				   const struct devlink_port_ops *ops);
167662306a36Sopenharmony_ci
167762306a36Sopenharmony_cistatic inline int devlink_port_register(struct devlink *devlink,
167862306a36Sopenharmony_ci					struct devlink_port *devlink_port,
167962306a36Sopenharmony_ci					unsigned int port_index)
168062306a36Sopenharmony_ci{
168162306a36Sopenharmony_ci	return devlink_port_register_with_ops(devlink, devlink_port,
168262306a36Sopenharmony_ci					      port_index, NULL);
168362306a36Sopenharmony_ci}
168462306a36Sopenharmony_ci
168562306a36Sopenharmony_civoid devl_port_unregister(struct devlink_port *devlink_port);
168662306a36Sopenharmony_civoid devlink_port_unregister(struct devlink_port *devlink_port);
168762306a36Sopenharmony_civoid devlink_port_type_eth_set(struct devlink_port *devlink_port);
168862306a36Sopenharmony_civoid devlink_port_type_ib_set(struct devlink_port *devlink_port,
168962306a36Sopenharmony_ci			      struct ib_device *ibdev);
169062306a36Sopenharmony_civoid devlink_port_type_clear(struct devlink_port *devlink_port);
169162306a36Sopenharmony_civoid devlink_port_attrs_set(struct devlink_port *devlink_port,
169262306a36Sopenharmony_ci			    struct devlink_port_attrs *devlink_port_attrs);
169362306a36Sopenharmony_civoid devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
169462306a36Sopenharmony_ci				   u16 pf, bool external);
169562306a36Sopenharmony_civoid devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
169662306a36Sopenharmony_ci				   u16 pf, u16 vf, bool external);
169762306a36Sopenharmony_civoid devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
169862306a36Sopenharmony_ci				   u32 controller, u16 pf, u32 sf,
169962306a36Sopenharmony_ci				   bool external);
170062306a36Sopenharmony_cistruct devlink_rate *
170162306a36Sopenharmony_cidevl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
170262306a36Sopenharmony_ci		      struct devlink_rate *parent);
170362306a36Sopenharmony_ciint
170462306a36Sopenharmony_cidevl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
170562306a36Sopenharmony_ci		      struct devlink_rate *parent);
170662306a36Sopenharmony_civoid devl_rate_leaf_destroy(struct devlink_port *devlink_port);
170762306a36Sopenharmony_civoid devl_rate_nodes_destroy(struct devlink *devlink);
170862306a36Sopenharmony_civoid devlink_port_linecard_set(struct devlink_port *devlink_port,
170962306a36Sopenharmony_ci			       struct devlink_linecard *linecard);
171062306a36Sopenharmony_cistruct devlink_linecard *
171162306a36Sopenharmony_cidevl_linecard_create(struct devlink *devlink, unsigned int linecard_index,
171262306a36Sopenharmony_ci		     const struct devlink_linecard_ops *ops, void *priv);
171362306a36Sopenharmony_civoid devl_linecard_destroy(struct devlink_linecard *linecard);
171462306a36Sopenharmony_civoid devlink_linecard_provision_set(struct devlink_linecard *linecard,
171562306a36Sopenharmony_ci				    const char *type);
171662306a36Sopenharmony_civoid devlink_linecard_provision_clear(struct devlink_linecard *linecard);
171762306a36Sopenharmony_civoid devlink_linecard_provision_fail(struct devlink_linecard *linecard);
171862306a36Sopenharmony_civoid devlink_linecard_activate(struct devlink_linecard *linecard);
171962306a36Sopenharmony_civoid devlink_linecard_deactivate(struct devlink_linecard *linecard);
172062306a36Sopenharmony_civoid devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
172162306a36Sopenharmony_ci				    struct devlink *nested_devlink);
172262306a36Sopenharmony_ciint devl_sb_register(struct devlink *devlink, unsigned int sb_index,
172362306a36Sopenharmony_ci		     u32 size, u16 ingress_pools_count,
172462306a36Sopenharmony_ci		     u16 egress_pools_count, u16 ingress_tc_count,
172562306a36Sopenharmony_ci		     u16 egress_tc_count);
172662306a36Sopenharmony_ciint devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
172762306a36Sopenharmony_ci			u32 size, u16 ingress_pools_count,
172862306a36Sopenharmony_ci			u16 egress_pools_count, u16 ingress_tc_count,
172962306a36Sopenharmony_ci			u16 egress_tc_count);
173062306a36Sopenharmony_civoid devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
173162306a36Sopenharmony_civoid devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
173262306a36Sopenharmony_ciint devl_dpipe_table_register(struct devlink *devlink,
173362306a36Sopenharmony_ci			      const char *table_name,
173462306a36Sopenharmony_ci			      struct devlink_dpipe_table_ops *table_ops,
173562306a36Sopenharmony_ci			      void *priv, bool counter_control_extern);
173662306a36Sopenharmony_civoid devl_dpipe_table_unregister(struct devlink *devlink,
173762306a36Sopenharmony_ci				 const char *table_name);
173862306a36Sopenharmony_civoid devl_dpipe_headers_register(struct devlink *devlink,
173962306a36Sopenharmony_ci				 struct devlink_dpipe_headers *dpipe_headers);
174062306a36Sopenharmony_civoid devl_dpipe_headers_unregister(struct devlink *devlink);
174162306a36Sopenharmony_cibool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
174262306a36Sopenharmony_ci					 const char *table_name);
174362306a36Sopenharmony_ciint devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
174462306a36Sopenharmony_ciint devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
174562306a36Sopenharmony_ci				   struct devlink_dpipe_entry *entry);
174662306a36Sopenharmony_ciint devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
174762306a36Sopenharmony_civoid devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
174862306a36Sopenharmony_ciint devlink_dpipe_action_put(struct sk_buff *skb,
174962306a36Sopenharmony_ci			     struct devlink_dpipe_action *action);
175062306a36Sopenharmony_ciint devlink_dpipe_match_put(struct sk_buff *skb,
175162306a36Sopenharmony_ci			    struct devlink_dpipe_match *match);
175262306a36Sopenharmony_ciextern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
175362306a36Sopenharmony_ciextern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
175462306a36Sopenharmony_ciextern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
175562306a36Sopenharmony_ci
175662306a36Sopenharmony_ciint devl_resource_register(struct devlink *devlink,
175762306a36Sopenharmony_ci			   const char *resource_name,
175862306a36Sopenharmony_ci			   u64 resource_size,
175962306a36Sopenharmony_ci			   u64 resource_id,
176062306a36Sopenharmony_ci			   u64 parent_resource_id,
176162306a36Sopenharmony_ci			   const struct devlink_resource_size_params *size_params);
176262306a36Sopenharmony_ciint devlink_resource_register(struct devlink *devlink,
176362306a36Sopenharmony_ci			      const char *resource_name,
176462306a36Sopenharmony_ci			      u64 resource_size,
176562306a36Sopenharmony_ci			      u64 resource_id,
176662306a36Sopenharmony_ci			      u64 parent_resource_id,
176762306a36Sopenharmony_ci			      const struct devlink_resource_size_params *size_params);
176862306a36Sopenharmony_civoid devl_resources_unregister(struct devlink *devlink);
176962306a36Sopenharmony_civoid devlink_resources_unregister(struct devlink *devlink);
177062306a36Sopenharmony_ciint devl_resource_size_get(struct devlink *devlink,
177162306a36Sopenharmony_ci			   u64 resource_id,
177262306a36Sopenharmony_ci			   u64 *p_resource_size);
177362306a36Sopenharmony_ciint devl_dpipe_table_resource_set(struct devlink *devlink,
177462306a36Sopenharmony_ci				  const char *table_name, u64 resource_id,
177562306a36Sopenharmony_ci				  u64 resource_units);
177662306a36Sopenharmony_civoid devl_resource_occ_get_register(struct devlink *devlink,
177762306a36Sopenharmony_ci				    u64 resource_id,
177862306a36Sopenharmony_ci				    devlink_resource_occ_get_t *occ_get,
177962306a36Sopenharmony_ci				    void *occ_get_priv);
178062306a36Sopenharmony_civoid devlink_resource_occ_get_register(struct devlink *devlink,
178162306a36Sopenharmony_ci				       u64 resource_id,
178262306a36Sopenharmony_ci				       devlink_resource_occ_get_t *occ_get,
178362306a36Sopenharmony_ci				       void *occ_get_priv);
178462306a36Sopenharmony_civoid devl_resource_occ_get_unregister(struct devlink *devlink,
178562306a36Sopenharmony_ci				      u64 resource_id);
178662306a36Sopenharmony_ci
178762306a36Sopenharmony_civoid devlink_resource_occ_get_unregister(struct devlink *devlink,
178862306a36Sopenharmony_ci					 u64 resource_id);
178962306a36Sopenharmony_ciint devl_params_register(struct devlink *devlink,
179062306a36Sopenharmony_ci			 const struct devlink_param *params,
179162306a36Sopenharmony_ci			 size_t params_count);
179262306a36Sopenharmony_ciint devlink_params_register(struct devlink *devlink,
179362306a36Sopenharmony_ci			    const struct devlink_param *params,
179462306a36Sopenharmony_ci			    size_t params_count);
179562306a36Sopenharmony_civoid devl_params_unregister(struct devlink *devlink,
179662306a36Sopenharmony_ci			    const struct devlink_param *params,
179762306a36Sopenharmony_ci			    size_t params_count);
179862306a36Sopenharmony_civoid devlink_params_unregister(struct devlink *devlink,
179962306a36Sopenharmony_ci			       const struct devlink_param *params,
180062306a36Sopenharmony_ci			       size_t params_count);
180162306a36Sopenharmony_ciint devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
180262306a36Sopenharmony_ci				    union devlink_param_value *val);
180362306a36Sopenharmony_civoid devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
180462306a36Sopenharmony_ci				     union devlink_param_value init_val);
180562306a36Sopenharmony_civoid devl_param_value_changed(struct devlink *devlink, u32 param_id);
180662306a36Sopenharmony_cistruct devlink_region *devl_region_create(struct devlink *devlink,
180762306a36Sopenharmony_ci					  const struct devlink_region_ops *ops,
180862306a36Sopenharmony_ci					  u32 region_max_snapshots,
180962306a36Sopenharmony_ci					  u64 region_size);
181062306a36Sopenharmony_cistruct devlink_region *
181162306a36Sopenharmony_cidevlink_region_create(struct devlink *devlink,
181262306a36Sopenharmony_ci		      const struct devlink_region_ops *ops,
181362306a36Sopenharmony_ci		      u32 region_max_snapshots, u64 region_size);
181462306a36Sopenharmony_cistruct devlink_region *
181562306a36Sopenharmony_cidevlink_port_region_create(struct devlink_port *port,
181662306a36Sopenharmony_ci			   const struct devlink_port_region_ops *ops,
181762306a36Sopenharmony_ci			   u32 region_max_snapshots, u64 region_size);
181862306a36Sopenharmony_civoid devl_region_destroy(struct devlink_region *region);
181962306a36Sopenharmony_civoid devlink_region_destroy(struct devlink_region *region);
182062306a36Sopenharmony_ciint devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
182162306a36Sopenharmony_civoid devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
182262306a36Sopenharmony_ciint devlink_region_snapshot_create(struct devlink_region *region,
182362306a36Sopenharmony_ci				   u8 *data, u32 snapshot_id);
182462306a36Sopenharmony_ciint devlink_info_serial_number_put(struct devlink_info_req *req,
182562306a36Sopenharmony_ci				   const char *sn);
182662306a36Sopenharmony_ciint devlink_info_board_serial_number_put(struct devlink_info_req *req,
182762306a36Sopenharmony_ci					 const char *bsn);
182862306a36Sopenharmony_ci
182962306a36Sopenharmony_cienum devlink_info_version_type {
183062306a36Sopenharmony_ci	DEVLINK_INFO_VERSION_TYPE_NONE,
183162306a36Sopenharmony_ci	DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update
183262306a36Sopenharmony_ci					      * component by name.
183362306a36Sopenharmony_ci					      */
183462306a36Sopenharmony_ci};
183562306a36Sopenharmony_ci
183662306a36Sopenharmony_ciint devlink_info_version_fixed_put(struct devlink_info_req *req,
183762306a36Sopenharmony_ci				   const char *version_name,
183862306a36Sopenharmony_ci				   const char *version_value);
183962306a36Sopenharmony_ciint devlink_info_version_stored_put(struct devlink_info_req *req,
184062306a36Sopenharmony_ci				    const char *version_name,
184162306a36Sopenharmony_ci				    const char *version_value);
184262306a36Sopenharmony_ciint devlink_info_version_stored_put_ext(struct devlink_info_req *req,
184362306a36Sopenharmony_ci					const char *version_name,
184462306a36Sopenharmony_ci					const char *version_value,
184562306a36Sopenharmony_ci					enum devlink_info_version_type version_type);
184662306a36Sopenharmony_ciint devlink_info_version_running_put(struct devlink_info_req *req,
184762306a36Sopenharmony_ci				     const char *version_name,
184862306a36Sopenharmony_ci				     const char *version_value);
184962306a36Sopenharmony_ciint devlink_info_version_running_put_ext(struct devlink_info_req *req,
185062306a36Sopenharmony_ci					 const char *version_name,
185162306a36Sopenharmony_ci					 const char *version_value,
185262306a36Sopenharmony_ci					 enum devlink_info_version_type version_type);
185362306a36Sopenharmony_ci
185462306a36Sopenharmony_ciint devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
185562306a36Sopenharmony_ciint devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
185662306a36Sopenharmony_ci
185762306a36Sopenharmony_ciint devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
185862306a36Sopenharmony_ciint devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
185962306a36Sopenharmony_ci
186062306a36Sopenharmony_ciint devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
186162306a36Sopenharmony_ci				     const char *name);
186262306a36Sopenharmony_ciint devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
186362306a36Sopenharmony_ciint devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
186462306a36Sopenharmony_ci					const char *name);
186562306a36Sopenharmony_ciint devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
186662306a36Sopenharmony_ci
186762306a36Sopenharmony_ciint devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
186862306a36Sopenharmony_ciint devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
186962306a36Sopenharmony_ciint devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
187062306a36Sopenharmony_ci			    u16 value_len);
187162306a36Sopenharmony_ci
187262306a36Sopenharmony_ciint devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
187362306a36Sopenharmony_ci			       bool value);
187462306a36Sopenharmony_ciint devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
187562306a36Sopenharmony_ci			     u8 value);
187662306a36Sopenharmony_ciint devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
187762306a36Sopenharmony_ci			      u32 value);
187862306a36Sopenharmony_ciint devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
187962306a36Sopenharmony_ci			      u64 value);
188062306a36Sopenharmony_ciint devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
188162306a36Sopenharmony_ci				 const char *value);
188262306a36Sopenharmony_ciint devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
188362306a36Sopenharmony_ci				 const void *value, u32 value_len);
188462306a36Sopenharmony_ci
188562306a36Sopenharmony_cistruct devlink_health_reporter *
188662306a36Sopenharmony_cidevl_port_health_reporter_create(struct devlink_port *port,
188762306a36Sopenharmony_ci				 const struct devlink_health_reporter_ops *ops,
188862306a36Sopenharmony_ci				 u64 graceful_period, void *priv);
188962306a36Sopenharmony_ci
189062306a36Sopenharmony_cistruct devlink_health_reporter *
189162306a36Sopenharmony_cidevlink_port_health_reporter_create(struct devlink_port *port,
189262306a36Sopenharmony_ci				    const struct devlink_health_reporter_ops *ops,
189362306a36Sopenharmony_ci				    u64 graceful_period, void *priv);
189462306a36Sopenharmony_ci
189562306a36Sopenharmony_cistruct devlink_health_reporter *
189662306a36Sopenharmony_cidevl_health_reporter_create(struct devlink *devlink,
189762306a36Sopenharmony_ci			    const struct devlink_health_reporter_ops *ops,
189862306a36Sopenharmony_ci			    u64 graceful_period, void *priv);
189962306a36Sopenharmony_ci
190062306a36Sopenharmony_cistruct devlink_health_reporter *
190162306a36Sopenharmony_cidevlink_health_reporter_create(struct devlink *devlink,
190262306a36Sopenharmony_ci			       const struct devlink_health_reporter_ops *ops,
190362306a36Sopenharmony_ci			       u64 graceful_period, void *priv);
190462306a36Sopenharmony_ci
190562306a36Sopenharmony_civoid
190662306a36Sopenharmony_cidevl_health_reporter_destroy(struct devlink_health_reporter *reporter);
190762306a36Sopenharmony_ci
190862306a36Sopenharmony_civoid
190962306a36Sopenharmony_cidevlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
191062306a36Sopenharmony_ci
191162306a36Sopenharmony_civoid *
191262306a36Sopenharmony_cidevlink_health_reporter_priv(struct devlink_health_reporter *reporter);
191362306a36Sopenharmony_ciint devlink_health_report(struct devlink_health_reporter *reporter,
191462306a36Sopenharmony_ci			  const char *msg, void *priv_ctx);
191562306a36Sopenharmony_civoid
191662306a36Sopenharmony_cidevlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
191762306a36Sopenharmony_ci				     enum devlink_health_reporter_state state);
191862306a36Sopenharmony_civoid
191962306a36Sopenharmony_cidevlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
192062306a36Sopenharmony_ci
192162306a36Sopenharmony_cibool devlink_is_reload_failed(const struct devlink *devlink);
192262306a36Sopenharmony_civoid devlink_remote_reload_actions_performed(struct devlink *devlink,
192362306a36Sopenharmony_ci					     enum devlink_reload_limit limit,
192462306a36Sopenharmony_ci					     u32 actions_performed);
192562306a36Sopenharmony_ci
192662306a36Sopenharmony_civoid devlink_flash_update_status_notify(struct devlink *devlink,
192762306a36Sopenharmony_ci					const char *status_msg,
192862306a36Sopenharmony_ci					const char *component,
192962306a36Sopenharmony_ci					unsigned long done,
193062306a36Sopenharmony_ci					unsigned long total);
193162306a36Sopenharmony_civoid devlink_flash_update_timeout_notify(struct devlink *devlink,
193262306a36Sopenharmony_ci					 const char *status_msg,
193362306a36Sopenharmony_ci					 const char *component,
193462306a36Sopenharmony_ci					 unsigned long timeout);
193562306a36Sopenharmony_ci
193662306a36Sopenharmony_ciint devl_traps_register(struct devlink *devlink,
193762306a36Sopenharmony_ci			const struct devlink_trap *traps,
193862306a36Sopenharmony_ci			size_t traps_count, void *priv);
193962306a36Sopenharmony_ciint devlink_traps_register(struct devlink *devlink,
194062306a36Sopenharmony_ci			   const struct devlink_trap *traps,
194162306a36Sopenharmony_ci			   size_t traps_count, void *priv);
194262306a36Sopenharmony_civoid devl_traps_unregister(struct devlink *devlink,
194362306a36Sopenharmony_ci			   const struct devlink_trap *traps,
194462306a36Sopenharmony_ci			   size_t traps_count);
194562306a36Sopenharmony_civoid devlink_traps_unregister(struct devlink *devlink,
194662306a36Sopenharmony_ci			      const struct devlink_trap *traps,
194762306a36Sopenharmony_ci			      size_t traps_count);
194862306a36Sopenharmony_civoid devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
194962306a36Sopenharmony_ci			 void *trap_ctx, struct devlink_port *in_devlink_port,
195062306a36Sopenharmony_ci			 const struct flow_action_cookie *fa_cookie);
195162306a36Sopenharmony_civoid *devlink_trap_ctx_priv(void *trap_ctx);
195262306a36Sopenharmony_ciint devl_trap_groups_register(struct devlink *devlink,
195362306a36Sopenharmony_ci			      const struct devlink_trap_group *groups,
195462306a36Sopenharmony_ci			      size_t groups_count);
195562306a36Sopenharmony_ciint devlink_trap_groups_register(struct devlink *devlink,
195662306a36Sopenharmony_ci				 const struct devlink_trap_group *groups,
195762306a36Sopenharmony_ci				 size_t groups_count);
195862306a36Sopenharmony_civoid devl_trap_groups_unregister(struct devlink *devlink,
195962306a36Sopenharmony_ci				 const struct devlink_trap_group *groups,
196062306a36Sopenharmony_ci				 size_t groups_count);
196162306a36Sopenharmony_civoid devlink_trap_groups_unregister(struct devlink *devlink,
196262306a36Sopenharmony_ci				    const struct devlink_trap_group *groups,
196362306a36Sopenharmony_ci				    size_t groups_count);
196462306a36Sopenharmony_ciint
196562306a36Sopenharmony_cidevl_trap_policers_register(struct devlink *devlink,
196662306a36Sopenharmony_ci			    const struct devlink_trap_policer *policers,
196762306a36Sopenharmony_ci			    size_t policers_count);
196862306a36Sopenharmony_civoid
196962306a36Sopenharmony_cidevl_trap_policers_unregister(struct devlink *devlink,
197062306a36Sopenharmony_ci			      const struct devlink_trap_policer *policers,
197162306a36Sopenharmony_ci			      size_t policers_count);
197262306a36Sopenharmony_ci
197362306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_NET_DEVLINK)
197462306a36Sopenharmony_ci
197562306a36Sopenharmony_cistruct devlink *__must_check devlink_try_get(struct devlink *devlink);
197662306a36Sopenharmony_civoid devlink_put(struct devlink *devlink);
197762306a36Sopenharmony_ci
197862306a36Sopenharmony_civoid devlink_compat_running_version(struct devlink *devlink,
197962306a36Sopenharmony_ci				    char *buf, size_t len);
198062306a36Sopenharmony_ciint devlink_compat_flash_update(struct devlink *devlink, const char *file_name);
198162306a36Sopenharmony_ciint devlink_compat_phys_port_name_get(struct net_device *dev,
198262306a36Sopenharmony_ci				      char *name, size_t len);
198362306a36Sopenharmony_ciint devlink_compat_switch_id_get(struct net_device *dev,
198462306a36Sopenharmony_ci				 struct netdev_phys_item_id *ppid);
198562306a36Sopenharmony_ci
198662306a36Sopenharmony_ciint devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port);
198762306a36Sopenharmony_cisize_t devlink_nl_port_handle_size(struct devlink_port *devlink_port);
198862306a36Sopenharmony_ci
198962306a36Sopenharmony_ci#else
199062306a36Sopenharmony_ci
199162306a36Sopenharmony_cistatic inline struct devlink *devlink_try_get(struct devlink *devlink)
199262306a36Sopenharmony_ci{
199362306a36Sopenharmony_ci	return NULL;
199462306a36Sopenharmony_ci}
199562306a36Sopenharmony_ci
199662306a36Sopenharmony_cistatic inline void devlink_put(struct devlink *devlink)
199762306a36Sopenharmony_ci{
199862306a36Sopenharmony_ci}
199962306a36Sopenharmony_ci
200062306a36Sopenharmony_cistatic inline void
200162306a36Sopenharmony_cidevlink_compat_running_version(struct devlink *devlink, char *buf, size_t len)
200262306a36Sopenharmony_ci{
200362306a36Sopenharmony_ci}
200462306a36Sopenharmony_ci
200562306a36Sopenharmony_cistatic inline int
200662306a36Sopenharmony_cidevlink_compat_flash_update(struct devlink *devlink, const char *file_name)
200762306a36Sopenharmony_ci{
200862306a36Sopenharmony_ci	return -EOPNOTSUPP;
200962306a36Sopenharmony_ci}
201062306a36Sopenharmony_ci
201162306a36Sopenharmony_cistatic inline int
201262306a36Sopenharmony_cidevlink_compat_phys_port_name_get(struct net_device *dev,
201362306a36Sopenharmony_ci				  char *name, size_t len)
201462306a36Sopenharmony_ci{
201562306a36Sopenharmony_ci	return -EOPNOTSUPP;
201662306a36Sopenharmony_ci}
201762306a36Sopenharmony_ci
201862306a36Sopenharmony_cistatic inline int
201962306a36Sopenharmony_cidevlink_compat_switch_id_get(struct net_device *dev,
202062306a36Sopenharmony_ci			     struct netdev_phys_item_id *ppid)
202162306a36Sopenharmony_ci{
202262306a36Sopenharmony_ci	return -EOPNOTSUPP;
202362306a36Sopenharmony_ci}
202462306a36Sopenharmony_ci
202562306a36Sopenharmony_cistatic inline int
202662306a36Sopenharmony_cidevlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port)
202762306a36Sopenharmony_ci{
202862306a36Sopenharmony_ci	return 0;
202962306a36Sopenharmony_ci}
203062306a36Sopenharmony_ci
203162306a36Sopenharmony_cistatic inline size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port)
203262306a36Sopenharmony_ci{
203362306a36Sopenharmony_ci	return 0;
203462306a36Sopenharmony_ci}
203562306a36Sopenharmony_ci
203662306a36Sopenharmony_ci#endif
203762306a36Sopenharmony_ci
203862306a36Sopenharmony_ci#endif /* _NET_DEVLINK_H_ */
2039