blob: 1151497c0ec5fe719eb664e1885c33d91c065023 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01002/*
3 * include/net/devlink.h - Network physical device Netlink interface
4 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01006 */
7#ifndef _NET_DEVLINK_H_
8#define _NET_DEVLINK_H_
9
10#include <linux/device.h>
11#include <linux/slab.h>
12#include <linux/gfp.h>
13#include <linux/list.h>
14#include <linux/netdevice.h>
Jiri Pirkob8f97552019-03-24 11:14:37 +010015#include <linux/spinlock.h>
Jiri Pirko136bf272019-05-23 10:43:35 +020016#include <linux/workqueue.h>
Ido Schimmel0f420b62019-08-17 16:28:17 +030017#include <linux/refcount.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010018#include <net/net_namespace.h>
Jiri Pirko5a2e1062020-02-25 11:45:21 +010019#include <net/flow_offload.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010020#include <uapi/linux/devlink.h>
Jacob Keller12102432020-03-26 11:37:15 -070021#include <linux/xarray.h>
Jacob Kellerb44cfd42020-11-18 11:06:35 -080022#include <linux/firmware.h>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010023
Moshe Shemesha254c262020-10-07 09:00:45 +030024#define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
25 (__DEVLINK_RELOAD_LIMIT_MAX * __DEVLINK_RELOAD_ACTION_MAX)
26
27struct devlink_dev_stats {
28 u32 reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
Moshe Shemesh77069ba2020-10-07 09:00:46 +030029 u32 remote_reload_stats[DEVLINK_RELOAD_STATS_ARRAY_SIZE];
Moshe Shemesha254c262020-10-07 09:00:45 +030030};
31
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010032struct devlink_ops;
33
34struct devlink {
35 struct list_head list;
36 struct list_head port_list;
Dmytro Linkin4677efc2021-06-02 15:17:19 +030037 struct list_head rate_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020038 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020039 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010040 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030041 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030042 struct list_head region_list;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020043 struct list_head reporter_list;
Moshe Shemeshb587bda2019-04-29 12:41:45 +030044 struct mutex reporters_lock; /* protects reporter_list */
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020045 struct devlink_dpipe_headers *dpipe_headers;
Ido Schimmel0f420b62019-08-17 16:28:17 +030046 struct list_head trap_list;
47 struct list_head trap_group_list;
Ido Schimmel1e8c6612020-03-30 22:38:18 +030048 struct list_head trap_policer_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010049 const struct devlink_ops *ops;
Jacob Keller12102432020-03-26 11:37:15 -070050 struct xarray snapshot_ids;
Moshe Shemesha254c262020-10-07 09:00:45 +030051 struct devlink_dev_stats stats;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010052 struct device *dev;
53 possible_net_t _net;
Parav Pandit336ce1c2020-07-21 19:53:53 +030054 struct mutex lock; /* Serializes access to devlink instance specific objects such as
55 * port, sb, dpipe, resource, params, region, traps and more.
56 */
Jiri Pirkoa0c76342019-11-08 21:42:43 +010057 u8 reload_failed:1,
Leon Romanovskyd7907a22021-07-28 10:33:47 +030058 reload_enabled:1;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010059 char priv[0] __aligned(NETDEV_ALIGN);
60};
61
Parav Pandit378ef012019-07-08 23:17:35 -050062struct devlink_port_phys_attrs {
63 u32 port_number; /* Same value as "split group".
64 * A physical port which is visible to the user
65 * for a given port flavour.
66 */
Danielle Ratson71ad8d52020-07-09 16:18:16 +030067 u32 split_subport_number; /* If the port is split, this is the number of subport. */
Parav Pandit378ef012019-07-08 23:17:35 -050068};
69
Parav Panditff03e632020-09-09 07:50:35 +030070/**
71 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
Parav Pandit3a2d9582020-09-09 07:50:37 +030072 * @controller: Associated controller number
Parav Panditff03e632020-09-09 07:50:35 +030073 * @pf: Associated PCI PF number for this port.
Parav Pandit05b595e2020-09-09 07:50:36 +030074 * @external: when set, indicates if a port is for an external controller
Parav Panditff03e632020-09-09 07:50:35 +030075 */
Parav Pandit98fd2d62019-07-08 23:17:37 -050076struct devlink_port_pci_pf_attrs {
Parav Pandit3a2d9582020-09-09 07:50:37 +030077 u32 controller;
Parav Panditff03e632020-09-09 07:50:35 +030078 u16 pf;
Parav Pandit05b595e2020-09-09 07:50:36 +030079 u8 external:1;
Parav Pandit98fd2d62019-07-08 23:17:37 -050080};
81
Parav Panditff03e632020-09-09 07:50:35 +030082/**
83 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
Parav Pandit3a2d9582020-09-09 07:50:37 +030084 * @controller: Associated controller number
Parav Panditff03e632020-09-09 07:50:35 +030085 * @pf: Associated PCI PF number for this port.
86 * @vf: Associated PCI VF for of the PCI PF for this port.
Parav Pandit05b595e2020-09-09 07:50:36 +030087 * @external: when set, indicates if a port is for an external controller
Parav Panditff03e632020-09-09 07:50:35 +030088 */
Parav Pandite41b6bf2019-07-08 23:17:38 -050089struct devlink_port_pci_vf_attrs {
Parav Pandit3a2d9582020-09-09 07:50:37 +030090 u32 controller;
Parav Panditff03e632020-09-09 07:50:35 +030091 u16 pf;
92 u16 vf;
Parav Pandit05b595e2020-09-09 07:50:36 +030093 u8 external:1;
Parav Pandite41b6bf2019-07-08 23:17:38 -050094};
95
Danielle Ratson71ad8d52020-07-09 16:18:16 +030096/**
Parav Panditb8288832020-12-11 22:12:13 -080097 * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes
98 * @controller: Associated controller number
99 * @sf: Associated PCI SF for of the PCI PF for this port.
100 * @pf: Associated PCI PF number for this port.
Parav Pandita1ab3e42021-03-10 15:35:03 +0200101 * @external: when set, indicates if a port is for an external controller
Parav Panditb8288832020-12-11 22:12:13 -0800102 */
103struct devlink_port_pci_sf_attrs {
104 u32 controller;
105 u32 sf;
106 u16 pf;
Parav Pandita1ab3e42021-03-10 15:35:03 +0200107 u8 external:1;
Parav Panditb8288832020-12-11 22:12:13 -0800108};
109
110/**
Danielle Ratson71ad8d52020-07-09 16:18:16 +0300111 * struct devlink_port_attrs - devlink port object
112 * @flavour: flavour of the port
113 * @split: indicates if this is split port
Danielle Ratsona0f49b52020-07-09 16:18:20 +0300114 * @splittable: indicates if the port can be split.
Danielle Ratsona21cf0a2020-07-09 16:18:18 +0300115 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
Danielle Ratson71ad8d52020-07-09 16:18:16 +0300116 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
Parav Pandit2efbe6a2020-09-09 07:50:34 +0300117 * @phys: physical port attributes
118 * @pci_pf: PCI PF port attributes
119 * @pci_vf: PCI VF port attributes
Parav Panditb8288832020-12-11 22:12:13 -0800120 * @pci_sf: PCI SF port attributes
Danielle Ratson71ad8d52020-07-09 16:18:16 +0300121 */
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200122struct devlink_port_attrs {
Danielle Ratsona0f49b52020-07-09 16:18:20 +0300123 u8 split:1,
124 splittable:1;
Danielle Ratsona21cf0a2020-07-09 16:18:18 +0300125 u32 lanes;
Jiri Pirko5ec13802018-05-18 09:29:01 +0200126 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +0200127 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -0500128 union {
129 struct devlink_port_phys_attrs phys;
Parav Pandit98fd2d62019-07-08 23:17:37 -0500130 struct devlink_port_pci_pf_attrs pci_pf;
Parav Pandite41b6bf2019-07-08 23:17:38 -0500131 struct devlink_port_pci_vf_attrs pci_vf;
Parav Panditb8288832020-12-11 22:12:13 -0800132 struct devlink_port_pci_sf_attrs pci_sf;
Parav Pandit378ef012019-07-08 23:17:35 -0500133 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200134};
135
Dmytro Linkin4677efc2021-06-02 15:17:19 +0300136struct devlink_rate {
137 struct list_head list;
138 enum devlink_rate_type type;
139 struct devlink *devlink;
140 void *priv;
Dmytro Linkin1897db22021-06-02 15:17:22 +0300141 u64 tx_share;
142 u64 tx_max;
Dmytro Linkin4677efc2021-06-02 15:17:19 +0300143
Dmytro Linkind7555982021-06-02 15:17:28 +0300144 struct devlink_rate *parent;
Dmytro Linkina8ecb932021-06-02 15:17:25 +0300145 union {
146 struct devlink_port *devlink_port;
Dmytro Linkind7555982021-06-02 15:17:28 +0300147 struct {
148 char *name;
149 refcount_t refcnt;
150 };
Dmytro Linkina8ecb932021-06-02 15:17:25 +0300151 };
Dmytro Linkin4677efc2021-06-02 15:17:19 +0300152};
153
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100154struct devlink_port {
155 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +0530156 struct list_head param_list;
Andrew Lunn544e7c32020-10-04 18:12:54 +0200157 struct list_head region_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100158 struct devlink *devlink;
Parav Panditc7282b52019-08-30 05:39:44 -0500159 unsigned int index;
Jiri Pirkob8f97552019-03-24 11:14:37 +0100160 spinlock_t type_lock; /* Protects type and type_dev
161 * pointer consistency.
162 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100163 enum devlink_port_type type;
164 enum devlink_port_type desired_type;
165 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200166 struct devlink_port_attrs attrs;
Danielle Ratson46737a12020-07-09 16:18:15 +0300167 u8 attrs_set:1,
168 switch_port:1;
Jiri Pirko136bf272019-05-23 10:43:35 +0200169 struct delayed_work type_warn_dw;
Vladyslav Tarasiukf4f54162020-07-10 15:25:10 +0300170 struct list_head reporter_list;
171 struct mutex reporters_lock; /* Protects reporter_list */
Dmytro Linkin4677efc2021-06-02 15:17:19 +0300172
173 struct devlink_rate *devlink_rate;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100174};
175
Parav Panditcd76dcd2020-12-11 22:12:14 -0800176struct devlink_port_new_attrs {
177 enum devlink_port_flavour flavour;
178 unsigned int port_index;
179 u32 controller;
180 u32 sfnum;
181 u16 pfnum;
182 u8 port_index_valid:1,
183 controller_valid:1,
184 sfnum_valid:1;
185};
186
Jiri Pirkobf797472016-04-14 18:19:13 +0200187struct devlink_sb_pool_info {
188 enum devlink_sb_pool_type pool_type;
189 u32 size;
190 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -0800191 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +0200192};
193
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200194/**
195 * struct devlink_dpipe_field - dpipe field object
196 * @name: field name
197 * @id: index inside the headers field array
198 * @bitwidth: bitwidth
199 * @mapping_type: mapping type
200 */
201struct devlink_dpipe_field {
202 const char *name;
203 unsigned int id;
204 unsigned int bitwidth;
205 enum devlink_dpipe_field_mapping_type mapping_type;
206};
207
208/**
209 * struct devlink_dpipe_header - dpipe header object
210 * @name: header name
211 * @id: index, global/local detrmined by global bit
212 * @fields: fields
213 * @fields_count: number of fields
214 * @global: indicates if header is shared like most protocol header
215 * or driver specific
216 */
217struct devlink_dpipe_header {
218 const char *name;
219 unsigned int id;
220 struct devlink_dpipe_field *fields;
221 unsigned int fields_count;
222 bool global;
223};
224
225/**
226 * struct devlink_dpipe_match - represents match operation
227 * @type: type of match
228 * @header_index: header index (packets can have several headers of same
229 * type like in case of tunnels)
230 * @header: header
231 * @fieled_id: field index
232 */
233struct devlink_dpipe_match {
234 enum devlink_dpipe_match_type type;
235 unsigned int header_index;
236 struct devlink_dpipe_header *header;
237 unsigned int field_id;
238};
239
240/**
241 * struct devlink_dpipe_action - represents action operation
242 * @type: type of action
243 * @header_index: header index (packets can have several headers of same
244 * type like in case of tunnels)
245 * @header: header
246 * @fieled_id: field index
247 */
248struct devlink_dpipe_action {
249 enum devlink_dpipe_action_type type;
250 unsigned int header_index;
251 struct devlink_dpipe_header *header;
252 unsigned int field_id;
253};
254
255/**
256 * struct devlink_dpipe_value - represents value of match/action
257 * @action: action
258 * @match: match
259 * @mapping_value: in case the field has some mapping this value
260 * specified the mapping value
261 * @mapping_valid: specify if mapping value is valid
262 * @value_size: value size
263 * @value: value
264 * @mask: bit mask
265 */
266struct devlink_dpipe_value {
267 union {
268 struct devlink_dpipe_action *action;
269 struct devlink_dpipe_match *match;
270 };
271 unsigned int mapping_value;
272 bool mapping_valid;
273 unsigned int value_size;
274 void *value;
275 void *mask;
276};
277
278/**
279 * struct devlink_dpipe_entry - table entry object
280 * @index: index of the entry in the table
281 * @match_values: match values
282 * @matche_values_count: count of matches tuples
283 * @action_values: actions values
284 * @action_values_count: count of actions values
285 * @counter: value of counter
286 * @counter_valid: Specify if value is valid from hardware
287 */
288struct devlink_dpipe_entry {
289 u64 index;
290 struct devlink_dpipe_value *match_values;
291 unsigned int match_values_count;
292 struct devlink_dpipe_value *action_values;
293 unsigned int action_values_count;
294 u64 counter;
295 bool counter_valid;
296};
297
298/**
299 * struct devlink_dpipe_dump_ctx - context provided to driver in order
300 * to dump
301 * @info: info
302 * @cmd: devlink command
303 * @skb: skb
304 * @nest: top attribute
305 * @hdr: hdr
306 */
307struct devlink_dpipe_dump_ctx {
308 struct genl_info *info;
309 enum devlink_command cmd;
310 struct sk_buff *skb;
311 struct nlattr *nest;
312 void *hdr;
313};
314
315struct devlink_dpipe_table_ops;
316
317/**
318 * struct devlink_dpipe_table - table object
319 * @priv: private
320 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200321 * @counters_enabled: indicates if counters are active
322 * @counter_control_extern: indicates if counter control is in dpipe or
323 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100324 * @resource_valid: Indicate that the resource id is valid
325 * @resource_id: relative resource this table is related to
326 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200327 * @table_ops: table operations
328 * @rcu: rcu
329 */
330struct devlink_dpipe_table {
331 void *priv;
332 struct list_head list;
333 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200334 bool counters_enabled;
335 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100336 bool resource_valid;
337 u64 resource_id;
338 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200339 struct devlink_dpipe_table_ops *table_ops;
340 struct rcu_head rcu;
341};
342
343/**
344 * struct devlink_dpipe_table_ops - dpipe_table ops
345 * @actions_dump - dumps all tables actions
346 * @matches_dump - dumps all tables matches
347 * @entries_dump - dumps all active entries in the table
348 * @counters_set_update - when changing the counter status hardware sync
349 * maybe needed to allocate/free counter related
350 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200351 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200352 */
353struct devlink_dpipe_table_ops {
354 int (*actions_dump)(void *priv, struct sk_buff *skb);
355 int (*matches_dump)(void *priv, struct sk_buff *skb);
356 int (*entries_dump)(void *priv, bool counters_enabled,
357 struct devlink_dpipe_dump_ctx *dump_ctx);
358 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200359 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200360};
361
362/**
363 * struct devlink_dpipe_headers - dpipe headers
364 * @headers - header array can be shared (global bit) or driver specific
365 * @headers_count - count of headers
366 */
367struct devlink_dpipe_headers {
368 struct devlink_dpipe_header **headers;
369 unsigned int headers_count;
370};
371
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100372/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100373 * struct devlink_resource_size_params - resource's size parameters
374 * @size_min: minimum size which can be set
375 * @size_max: maximum size which can be set
376 * @size_granularity: size granularity
377 * @size_unit: resource's basic unit
378 */
379struct devlink_resource_size_params {
380 u64 size_min;
381 u64 size_max;
382 u64 size_granularity;
383 enum devlink_resource_unit unit;
384};
385
Jiri Pirko77d27092018-02-28 13:12:09 +0100386static inline void
387devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
388 u64 size_min, u64 size_max,
389 u64 size_granularity,
390 enum devlink_resource_unit unit)
391{
392 size_params->size_min = size_min;
393 size_params->size_max = size_max;
394 size_params->size_granularity = size_granularity;
395 size_params->unit = unit;
396}
397
Jiri Pirkofc56be42018-04-05 22:13:21 +0200398typedef u64 devlink_resource_occ_get_t(void *priv);
399
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100400/**
401 * struct devlink_resource - devlink resource
402 * @name: name of the resource
403 * @id: id, per devlink instance
404 * @size: size of the resource
405 * @size_new: updated size of the resource, reload is needed
406 * @size_valid: valid in case the total size of the resource is valid
407 * including its children
408 * @parent: parent resource
409 * @size_params: size parameters
410 * @list: parent list
411 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100412 */
413struct devlink_resource {
414 const char *name;
415 u64 id;
416 u64 size;
417 u64 size_new;
418 bool size_valid;
419 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100420 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100421 struct list_head list;
422 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200423 devlink_resource_occ_get_t *occ_get;
424 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100425};
426
427#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
428
Danielle Ratson321f7ab2021-01-21 15:10:23 +0200429#define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports"
430
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300431#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300432enum devlink_param_type {
433 DEVLINK_PARAM_TYPE_U8,
434 DEVLINK_PARAM_TYPE_U16,
435 DEVLINK_PARAM_TYPE_U32,
436 DEVLINK_PARAM_TYPE_STRING,
437 DEVLINK_PARAM_TYPE_BOOL,
438};
439
440union devlink_param_value {
441 u8 vu8;
442 u16 vu16;
443 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300444 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300445 bool vbool;
446};
447
448struct devlink_param_gset_ctx {
449 union devlink_param_value val;
450 enum devlink_param_cmode cmode;
451};
452
453/**
Shannon Nelson6700acc2020-09-17 18:13:24 -0700454 * struct devlink_flash_notify - devlink dev flash notify data
455 * @status_msg: current status string
456 * @component: firmware component being updated
457 * @done: amount of work completed of total amount
458 * @total: amount of work expected to be done
459 * @timeout: expected max timeout in seconds
460 *
461 * These are values to be given to userland to be displayed in order
462 * to show current activity in a firmware update process.
463 */
464struct devlink_flash_notify {
465 const char *status_msg;
466 const char *component;
467 unsigned long done;
468 unsigned long total;
469 unsigned long timeout;
470};
471
472/**
Moshe Shemesheabaef12018-07-04 14:30:28 +0300473 * struct devlink_param - devlink configuration parameter data
474 * @name: name of the parameter
475 * @generic: indicates if the parameter is generic or driver specific
476 * @type: parameter type
477 * @supported_cmodes: bitmap of supported configuration modes
478 * @get: get parameter value, used for runtime and permanent
479 * configuration modes
480 * @set: set parameter value, used for runtime and permanent
481 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300482 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300483 *
484 * This struct should be used by the driver to fill the data for
485 * a parameter it registers.
486 */
487struct devlink_param {
488 u32 id;
489 const char *name;
490 bool generic;
491 enum devlink_param_type type;
492 unsigned long supported_cmodes;
493 int (*get)(struct devlink *devlink, u32 id,
494 struct devlink_param_gset_ctx *ctx);
495 int (*set)(struct devlink *devlink, u32 id,
496 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300497 int (*validate)(struct devlink *devlink, u32 id,
498 union devlink_param_value val,
499 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300500};
501
502struct devlink_param_item {
503 struct list_head list;
504 const struct devlink_param *param;
505 union devlink_param_value driverinit_value;
506 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000507 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300508};
509
510enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300511 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
512 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300513 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300514 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530515 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530516 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530517 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000518 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100519 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000520 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
Moshe Shemesh195d9de2020-10-07 09:00:53 +0300521 DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
Parav Panditf13a5ad2021-08-10 16:24:15 +0300522 DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
Parav Pandit8ddaabe2021-08-10 16:24:16 +0300523 DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
Parav Pandit076b2a92021-08-10 16:24:17 +0300524 DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300525
526 /* add new param generic ids above here*/
527 __DEVLINK_PARAM_GENERIC_ID_MAX,
528 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
529};
530
Moshe Shemesh036467c2018-07-04 14:30:33 +0300531#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
532#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
533
534#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
535#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
536
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300537#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
538#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
539
Alex Veskerf6a698852018-07-12 15:13:17 +0300540#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
541#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
542
Vasundhara Volame3b51062018-10-04 11:13:44 +0530543#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
544#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
545
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530546#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
547#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
548
Vasundhara Volam16511782018-10-04 11:13:46 +0530549#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
550#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
551
Shalom Toledo846e9802018-12-03 07:58:59 +0000552#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
553#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
554
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100555#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
556 "reset_dev_on_drv_probe"
557#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
558
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000559#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
560#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
561
Moshe Shemesh195d9de2020-10-07 09:00:53 +0300562#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset"
563#define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
564
Parav Panditf13a5ad2021-08-10 16:24:15 +0300565#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME "enable_eth"
566#define DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE DEVLINK_PARAM_TYPE_BOOL
567
Parav Pandit8ddaabe2021-08-10 16:24:16 +0300568#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME "enable_rdma"
569#define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE DEVLINK_PARAM_TYPE_BOOL
570
Parav Pandit076b2a92021-08-10 16:24:17 +0300571#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME "enable_vnet"
572#define DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE DEVLINK_PARAM_TYPE_BOOL
573
Moshe Shemesh036467c2018-07-04 14:30:33 +0300574#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
575{ \
576 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
577 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
578 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
579 .generic = true, \
580 .supported_cmodes = _cmodes, \
581 .get = _get, \
582 .set = _set, \
583 .validate = _validate, \
584}
585
586#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
587{ \
588 .id = _id, \
589 .name = _name, \
590 .type = _type, \
591 .supported_cmodes = _cmodes, \
592 .get = _get, \
593 .set = _set, \
594 .validate = _validate, \
595}
596
Jakub Kicinski785bd552019-01-31 10:50:42 -0800597/* Part number, identifier of board design */
598#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
599/* Revision of board design */
600#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800601/* Maker of the board */
602#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800603
Shannon Nelson7d5aa9a2019-09-03 15:28:03 -0700604/* Part number, identifier of asic design */
605#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
606/* Revision of asic design */
607#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
608
609/* Overall FW version */
610#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800611/* Control processor FW version */
612#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
Vasundhara Volam2d9eade2020-03-27 15:04:51 +0530613/* FW interface specification version */
614#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800615/* Data path microcode controlling high-speed packet processing */
616#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
617/* UNDI software version */
618#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
619/* NCSI support/handler version */
620#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
Jacob Keller468672b2020-01-09 14:46:09 -0800621/* FW parameter set id */
622#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
Vasundhara Volam41c0d912020-01-27 04:56:25 -0500623/* RoCE FW version */
624#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
Jacob Kellerc90977a2020-03-11 18:58:16 -0700625/* Firmware bundle identifier */
626#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800627
Jacob Kellerbc75c052020-09-25 13:46:06 -0700628/**
629 * struct devlink_flash_update_params - Flash Update parameters
Jacob Kellerb44cfd42020-11-18 11:06:35 -0800630 * @fw: pointer to the firmware data to update from
Jacob Kellerbc75c052020-09-25 13:46:06 -0700631 * @component: the flash component to update
632 *
Jacob Kellerb44cfd42020-11-18 11:06:35 -0800633 * With the exception of fw, drivers must opt-in to parameters by
Jacob Kellerbc75c052020-09-25 13:46:06 -0700634 * setting the appropriate bit in the supported_flash_update_params field in
635 * their devlink_ops structure.
636 */
637struct devlink_flash_update_params {
Jacob Kellerb44cfd42020-11-18 11:06:35 -0800638 const struct firmware *fw;
Jacob Kellerbc75c052020-09-25 13:46:06 -0700639 const char *component;
Jacob Keller5d5b4122020-09-25 13:46:07 -0700640 u32 overwrite_mask;
Jacob Kellerbc75c052020-09-25 13:46:06 -0700641};
642
Jacob Keller5d5b4122020-09-25 13:46:07 -0700643#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
644#define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(1)
Jacob Keller22ec3d22020-09-25 13:46:05 -0700645
Alex Veskerb16ebe92018-07-12 15:13:08 +0300646struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800647struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300648
Jacob Kellere8937682020-03-26 11:37:08 -0700649/**
650 * struct devlink_region_ops - Region operations
651 * @name: region name
Jacob Kellera0a09f62020-03-26 11:37:09 -0700652 * @destructor: callback used to free snapshot memory when deleting
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700653 * @snapshot: callback to request an immediate snapshot. On success,
654 * the data variable must be updated to point to the snapshot data.
655 * The function will be called while the devlink instance lock is
656 * held.
Andrew Lunne14e05e2020-09-18 21:11:01 +0200657 * @priv: Pointer to driver private data for the region operation
Jacob Kellere8937682020-03-26 11:37:08 -0700658 */
659struct devlink_region_ops {
660 const char *name;
Jacob Kellera0a09f62020-03-26 11:37:09 -0700661 void (*destructor)(const void *data);
Andrew Lunnd4602a92020-09-18 21:11:02 +0200662 int (*snapshot)(struct devlink *devlink,
663 const struct devlink_region_ops *ops,
664 struct netlink_ext_ack *extack,
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700665 u8 **data);
Andrew Lunne14e05e2020-09-18 21:11:01 +0200666 void *priv;
Jacob Kellere8937682020-03-26 11:37:08 -0700667};
668
Andrew Lunn544e7c32020-10-04 18:12:54 +0200669/**
670 * struct devlink_port_region_ops - Region operations for a port
671 * @name: region name
672 * @destructor: callback used to free snapshot memory when deleting
673 * @snapshot: callback to request an immediate snapshot. On success,
674 * the data variable must be updated to point to the snapshot data.
675 * The function will be called while the devlink instance lock is
676 * held.
677 * @priv: Pointer to driver private data for the region operation
678 */
679struct devlink_port_region_ops {
680 const char *name;
681 void (*destructor)(const void *data);
682 int (*snapshot)(struct devlink_port *port,
683 const struct devlink_port_region_ops *ops,
684 struct netlink_ext_ack *extack,
685 u8 **data);
686 void *priv;
687};
688
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200689struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200690struct devlink_health_reporter;
691
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200692enum devlink_health_reporter_state {
693 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
694 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
695};
696
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200697/**
698 * struct devlink_health_reporter_ops - Reporter operations
699 * @name: reporter name
700 * @recover: callback to recover from reported error
701 * if priv_ctx is NULL, run a full recover
702 * @dump: callback to dump an object
703 * if priv_ctx is NULL, run a full dump
704 * @diagnose: callback to diagnose the current status
Jiri Pirkoe2ce94d2020-09-15 11:40:57 +0300705 * @test: callback to trigger a test event
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200706 */
707
708struct devlink_health_reporter_ops {
709 char *name;
710 int (*recover)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200711 void *priv_ctx, struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200712 int (*dump)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200713 struct devlink_fmsg *fmsg, void *priv_ctx,
714 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200715 int (*diagnose)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200716 struct devlink_fmsg *fmsg,
717 struct netlink_ext_ack *extack);
Jiri Pirkoe2ce94d2020-09-15 11:40:57 +0300718 int (*test)(struct devlink_health_reporter *reporter,
719 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200720};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200721
Ido Schimmel0f420b62019-08-17 16:28:17 +0300722/**
Ido Schimmel5b888232020-09-29 11:15:50 +0300723 * struct devlink_trap_metadata - Packet trap metadata.
724 * @trap_name: Trap name.
725 * @trap_group_name: Trap group name.
726 * @input_dev: Input netdevice.
727 * @fa_cookie: Flow action user cookie.
Ido Schimmel93e15592020-09-29 11:15:55 +0300728 * @trap_type: Trap type.
Ido Schimmel5b888232020-09-29 11:15:50 +0300729 */
730struct devlink_trap_metadata {
731 const char *trap_name;
732 const char *trap_group_name;
733 struct net_device *input_dev;
734 const struct flow_action_cookie *fa_cookie;
Ido Schimmel93e15592020-09-29 11:15:55 +0300735 enum devlink_trap_type trap_type;
Ido Schimmel5b888232020-09-29 11:15:50 +0300736};
737
738/**
Ido Schimmel1e8c6612020-03-30 22:38:18 +0300739 * struct devlink_trap_policer - Immutable packet trap policer attributes.
740 * @id: Policer identifier.
741 * @init_rate: Initial rate in packets / sec.
742 * @init_burst: Initial burst size in packets.
743 * @max_rate: Maximum rate.
744 * @min_rate: Minimum rate.
745 * @max_burst: Maximum burst size.
746 * @min_burst: Minimum burst size.
747 *
748 * Describes immutable attributes of packet trap policers that drivers register
749 * with devlink.
750 */
751struct devlink_trap_policer {
752 u32 id;
753 u64 init_rate;
754 u64 init_burst;
755 u64 max_rate;
756 u64 min_rate;
757 u64 max_burst;
758 u64 min_burst;
759};
760
761/**
Ido Schimmel0f420b62019-08-17 16:28:17 +0300762 * struct devlink_trap_group - Immutable packet trap group attributes.
763 * @name: Trap group name.
764 * @id: Trap group identifier.
765 * @generic: Whether the trap group is generic or not.
Ido Schimmelf9f54392020-03-30 22:38:21 +0300766 * @init_policer_id: Initial policer identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300767 *
768 * Describes immutable attributes of packet trap groups that drivers register
769 * with devlink.
770 */
771struct devlink_trap_group {
772 const char *name;
773 u16 id;
774 bool generic;
Ido Schimmelf9f54392020-03-30 22:38:21 +0300775 u32 init_policer_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300776};
777
778#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
Jiri Pirko85b05892020-02-25 11:45:19 +0100779#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
Ido Schimmel0f420b62019-08-17 16:28:17 +0300780
781/**
782 * struct devlink_trap - Immutable packet trap attributes.
783 * @type: Trap type.
784 * @init_action: Initial trap action.
785 * @generic: Whether the trap is generic or not.
786 * @id: Trap identifier.
787 * @name: Trap name.
Ido Schimmel107f1672020-03-22 20:48:30 +0200788 * @init_group_id: Initial group identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300789 * @metadata_cap: Metadata types that can be provided by the trap.
790 *
791 * Describes immutable attributes of packet traps that drivers register with
792 * devlink.
793 */
794struct devlink_trap {
795 enum devlink_trap_type type;
796 enum devlink_trap_action init_action;
797 bool generic;
798 u16 id;
799 const char *name;
Ido Schimmel107f1672020-03-22 20:48:30 +0200800 u16 init_group_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300801 u32 metadata_cap;
802};
803
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300804/* All traps must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800805 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300806 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300807enum devlink_trap_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300808 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
809 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
810 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
811 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
812 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
813 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
814 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
815 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
816 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
Amit Cohen6896cc42019-11-07 18:42:09 +0200817 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
818 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
819 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
820 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
821 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
822 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
823 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
824 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
825 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
Amit Cohen3b063ae2019-11-07 18:42:14 +0200826 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
827 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
828 DEVLINK_TRAP_GENERIC_ID_RPF,
829 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
830 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
831 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
Amit Cohen95f0ead2020-01-19 15:00:48 +0200832 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
Amit Cohen13c056e2020-01-19 15:00:54 +0200833 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
Amit Cohenc3cae492020-01-19 15:00:58 +0200834 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100835 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
836 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
Ido Schimmel515eac62020-05-29 21:36:41 +0300837 DEVLINK_TRAP_GENERIC_ID_STP,
838 DEVLINK_TRAP_GENERIC_ID_LACP,
839 DEVLINK_TRAP_GENERIC_ID_LLDP,
840 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
841 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
842 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
843 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
844 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
845 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
846 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
847 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
848 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300849 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
850 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
851 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
852 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
853 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
854 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
855 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
856 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
857 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
858 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
859 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
860 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
861 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
862 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
863 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
864 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
865 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
866 DEVLINK_TRAP_GENERIC_ID_UC_LB,
867 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
868 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
869 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
870 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
871 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
872 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
873 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
874 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
875 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
876 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
877 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
878 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel5eb18a22020-05-29 21:36:43 +0300879 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
880 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
Amit Cohen08e335f2020-08-03 19:11:33 +0300881 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
Ioana Ciornei10c24eb2020-10-01 18:11:45 +0300882 DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING,
883 DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING,
884 DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING,
885 DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING,
886 DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING,
887 DEVLINK_TRAP_GENERIC_ID_ARP_PARSING,
888 DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING,
889 DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING,
890 DEVLINK_TRAP_GENERIC_ID_GRE_PARSING,
891 DEVLINK_TRAP_GENERIC_ID_UDP_PARSING,
892 DEVLINK_TRAP_GENERIC_ID_TCP_PARSING,
893 DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING,
894 DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING,
895 DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING,
896 DEVLINK_TRAP_GENERIC_ID_GTP_PARSING,
897 DEVLINK_TRAP_GENERIC_ID_ESP_PARSING,
Ido Schimmelf0a50132020-11-23 09:12:28 +0200898 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_NEXTHOP,
Aya Levine78ab162021-01-26 15:24:06 -0800899 DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER,
Ido Schimmel391203a2019-08-17 16:28:18 +0300900
Ido Schimmel0f420b62019-08-17 16:28:17 +0300901 /* Add new generic trap IDs above */
902 __DEVLINK_TRAP_GENERIC_ID_MAX,
903 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
904};
905
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300906/* All trap groups must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800907 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300908 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300909enum devlink_trap_group_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300910 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
911 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
Ido Schimmel678eb192020-05-29 21:36:36 +0300912 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
Ido Schimmel391203a2019-08-17 16:28:18 +0300913 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
Amit Cohen13c056e2020-01-19 15:00:54 +0200914 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100915 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
Ido Schimmel515eac62020-05-29 21:36:41 +0300916 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
917 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
918 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
919 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300920 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
921 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
922 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
923 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
924 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
925 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
926 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
927 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
928 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
Ido Schimmelec4f5b32020-07-29 12:26:44 +0300929 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300930 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
931 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
932 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel5eb18a22020-05-29 21:36:43 +0300933 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
934 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
Ioana Ciornei10c24eb2020-10-01 18:11:45 +0300935 DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS,
Ido Schimmel391203a2019-08-17 16:28:18 +0300936
Ido Schimmel0f420b62019-08-17 16:28:17 +0300937 /* Add new generic trap group IDs above */
938 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
939 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
940 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
941};
942
Ido Schimmel391203a2019-08-17 16:28:18 +0300943#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
944 "source_mac_is_multicast"
945#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
946 "vlan_tag_mismatch"
947#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
948 "ingress_vlan_filter"
949#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
950 "ingress_spanning_tree_filter"
951#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
952 "port_list_is_empty"
953#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
954 "port_loopback_filter"
955#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
956 "blackhole_route"
957#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
958 "ttl_value_is_too_small"
959#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
960 "tail_drop"
Amit Cohen6896cc42019-11-07 18:42:09 +0200961#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
962 "non_ip"
963#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
964 "uc_dip_over_mc_dmac"
965#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
966 "dip_is_loopback_address"
967#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
968 "sip_is_mc"
969#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
970 "sip_is_loopback_address"
971#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
972 "ip_header_corrupted"
973#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
974 "ipv4_sip_is_limited_bc"
975#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
976 "ipv6_mc_dip_reserved_scope"
977#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
978 "ipv6_mc_dip_interface_local_scope"
Amit Cohen3b063ae2019-11-07 18:42:14 +0200979#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
980 "mtu_value_is_too_small"
981#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
982 "unresolved_neigh"
983#define DEVLINK_TRAP_GENERIC_NAME_RPF \
984 "mc_reverse_path_forwarding"
985#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
986 "reject_route"
987#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
988 "ipv4_lpm_miss"
989#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
990 "ipv6_lpm_miss"
Amit Cohen95f0ead2020-01-19 15:00:48 +0200991#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
992 "non_routable_packet"
Amit Cohen13c056e2020-01-19 15:00:54 +0200993#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
994 "decap_error"
Amit Cohenc3cae492020-01-19 15:00:58 +0200995#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
996 "overlay_smac_is_mc"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100997#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
998 "ingress_flow_action_drop"
999#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
1000 "egress_flow_action_drop"
Ido Schimmel515eac62020-05-29 21:36:41 +03001001#define DEVLINK_TRAP_GENERIC_NAME_STP \
1002 "stp"
1003#define DEVLINK_TRAP_GENERIC_NAME_LACP \
1004 "lacp"
1005#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
1006 "lldp"
1007#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
1008 "igmp_query"
1009#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
1010 "igmp_v1_report"
1011#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
1012 "igmp_v2_report"
1013#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
1014 "igmp_v3_report"
1015#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
1016 "igmp_v2_leave"
1017#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
1018 "mld_query"
1019#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
1020 "mld_v1_report"
1021#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
1022 "mld_v2_report"
1023#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
1024 "mld_v1_done"
Ido Schimmeld77cfd12020-05-29 21:36:42 +03001025#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
1026 "ipv4_dhcp"
1027#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
1028 "ipv6_dhcp"
1029#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
1030 "arp_request"
1031#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
1032 "arp_response"
1033#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
1034 "arp_overlay"
1035#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
1036 "ipv6_neigh_solicit"
1037#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
1038 "ipv6_neigh_advert"
1039#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
1040 "ipv4_bfd"
1041#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
1042 "ipv6_bfd"
1043#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
1044 "ipv4_ospf"
1045#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
1046 "ipv6_ospf"
1047#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
1048 "ipv4_bgp"
1049#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
1050 "ipv6_bgp"
1051#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
1052 "ipv4_vrrp"
1053#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
1054 "ipv6_vrrp"
1055#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
1056 "ipv4_pim"
1057#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
1058 "ipv6_pim"
1059#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
1060 "uc_loopback"
1061#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
1062 "local_route"
1063#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
1064 "external_route"
1065#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
1066 "ipv6_uc_dip_link_local_scope"
1067#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
1068 "ipv6_dip_all_nodes"
1069#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
1070 "ipv6_dip_all_routers"
1071#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
1072 "ipv6_router_solicit"
1073#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
1074 "ipv6_router_advert"
1075#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
1076 "ipv6_redirect"
1077#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
1078 "ipv4_router_alert"
1079#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
1080 "ipv6_router_alert"
1081#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
1082 "ptp_event"
1083#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
1084 "ptp_general"
Ido Schimmel5eb18a22020-05-29 21:36:43 +03001085#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
1086 "flow_action_sample"
1087#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
1088 "flow_action_trap"
Amit Cohen08e335f2020-08-03 19:11:33 +03001089#define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
1090 "early_drop"
Ioana Ciornei10c24eb2020-10-01 18:11:45 +03001091#define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \
1092 "vxlan_parsing"
1093#define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \
1094 "llc_snap_parsing"
1095#define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \
1096 "vlan_parsing"
1097#define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \
1098 "pppoe_ppp_parsing"
1099#define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \
1100 "mpls_parsing"
1101#define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \
1102 "arp_parsing"
1103#define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \
1104 "ip_1_parsing"
1105#define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \
1106 "ip_n_parsing"
1107#define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \
1108 "gre_parsing"
1109#define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \
1110 "udp_parsing"
1111#define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \
1112 "tcp_parsing"
1113#define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \
1114 "ipsec_parsing"
1115#define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \
1116 "sctp_parsing"
1117#define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \
1118 "dccp_parsing"
1119#define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \
1120 "gtp_parsing"
1121#define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \
1122 "esp_parsing"
Ido Schimmelf0a50132020-11-23 09:12:28 +02001123#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_NEXTHOP \
1124 "blackhole_nexthop"
Aya Levine78ab162021-01-26 15:24:06 -08001125#define DEVLINK_TRAP_GENERIC_NAME_DMAC_FILTER \
Aya Levine13e4532021-02-09 12:59:55 +02001126 "dmac_filter"
Ido Schimmel391203a2019-08-17 16:28:18 +03001127
1128#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
1129 "l2_drops"
1130#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
1131 "l3_drops"
Ido Schimmel678eb192020-05-29 21:36:36 +03001132#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
1133 "l3_exceptions"
Ido Schimmel391203a2019-08-17 16:28:18 +03001134#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
1135 "buffer_drops"
Amit Cohen13c056e2020-01-19 15:00:54 +02001136#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
1137 "tunnel_drops"
Jiri Pirkoecd942a2020-02-24 08:35:47 +01001138#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
1139 "acl_drops"
Ido Schimmel515eac62020-05-29 21:36:41 +03001140#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
1141 "stp"
1142#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
1143 "lacp"
1144#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
1145 "lldp"
1146#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
1147 "mc_snooping"
Ido Schimmeld77cfd12020-05-29 21:36:42 +03001148#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
1149 "dhcp"
1150#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
1151 "neigh_discovery"
1152#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
1153 "bfd"
1154#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
1155 "ospf"
1156#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
1157 "bgp"
1158#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
1159 "vrrp"
1160#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
1161 "pim"
1162#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
1163 "uc_loopback"
1164#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
1165 "local_delivery"
Ido Schimmelec4f5b32020-07-29 12:26:44 +03001166#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
1167 "external_delivery"
Ido Schimmeld77cfd12020-05-29 21:36:42 +03001168#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1169 "ipv6"
1170#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1171 "ptp_event"
1172#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1173 "ptp_general"
Ido Schimmel5eb18a22020-05-29 21:36:43 +03001174#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1175 "acl_sample"
1176#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1177 "acl_trap"
Ioana Ciornei10c24eb2020-10-01 18:11:45 +03001178#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \
1179 "parser_error_drops"
Ido Schimmel391203a2019-08-17 16:28:18 +03001180
Ido Schimmel107f1672020-03-22 20:48:30 +02001181#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
1182 _metadata_cap) \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001183 { \
1184 .type = DEVLINK_TRAP_TYPE_##_type, \
1185 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1186 .generic = true, \
1187 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
1188 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
Ido Schimmel107f1672020-03-22 20:48:30 +02001189 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001190 .metadata_cap = _metadata_cap, \
1191 }
1192
Ido Schimmel107f1672020-03-22 20:48:30 +02001193#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001194 _metadata_cap) \
1195 { \
1196 .type = DEVLINK_TRAP_TYPE_##_type, \
1197 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1198 .generic = false, \
1199 .id = _id, \
1200 .name = _name, \
Ido Schimmel107f1672020-03-22 20:48:30 +02001201 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001202 .metadata_cap = _metadata_cap, \
1203 }
1204
Ido Schimmelf9f54392020-03-30 22:38:21 +03001205#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001206 { \
1207 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
1208 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
1209 .generic = true, \
Ido Schimmelf9f54392020-03-30 22:38:21 +03001210 .init_policer_id = _policer_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001211 }
1212
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001213#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1214 _max_burst, _min_burst) \
1215 { \
1216 .id = _id, \
1217 .init_rate = _rate, \
1218 .init_burst = _burst, \
1219 .max_rate = _max_rate, \
1220 .min_rate = _min_rate, \
1221 .max_burst = _max_burst, \
1222 .min_burst = _min_burst, \
1223 }
1224
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001225struct devlink_ops {
Jacob Keller22ec3d22020-09-25 13:46:05 -07001226 /**
1227 * @supported_flash_update_params:
1228 * mask of parameters supported by the driver's .flash_update
1229 * implemementation.
1230 */
1231 u32 supported_flash_update_params;
Moshe Shemeshccdf0722020-10-07 09:00:43 +03001232 unsigned long reload_actions;
Moshe Shemeshdc64cc72020-10-07 09:00:44 +03001233 unsigned long reload_limits;
Jiri Pirko070c63f2019-10-03 11:49:39 +02001234 int (*reload_down)(struct devlink *devlink, bool netns_change,
Moshe Shemeshdc64cc72020-10-07 09:00:44 +03001235 enum devlink_reload_action action,
1236 enum devlink_reload_limit limit,
1237 struct netlink_ext_ack *extack);
Moshe Shemeshccdf0722020-10-07 09:00:43 +03001238 int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action,
Moshe Shemeshdc64cc72020-10-07 09:00:44 +03001239 enum devlink_reload_limit limit, u32 *actions_performed,
1240 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001241 int (*port_type_set)(struct devlink_port *devlink_port,
1242 enum devlink_port_type port_type);
1243 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -07001244 unsigned int count, struct netlink_ext_ack *extack);
1245 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
1246 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001247 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1248 u16 pool_index,
1249 struct devlink_sb_pool_info *pool_info);
1250 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1251 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001252 enum devlink_sb_threshold_type threshold_type,
1253 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001254 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1255 unsigned int sb_index, u16 pool_index,
1256 u32 *p_threshold);
1257 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1258 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001259 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001260 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1261 unsigned int sb_index,
1262 u16 tc_index,
1263 enum devlink_sb_pool_type pool_type,
1264 u16 *p_pool_index, u32 *p_threshold);
1265 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1266 unsigned int sb_index,
1267 u16 tc_index,
1268 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001269 u16 pool_index, u32 threshold,
1270 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +02001271 int (*sb_occ_snapshot)(struct devlink *devlink,
1272 unsigned int sb_index);
1273 int (*sb_occ_max_clear)(struct devlink *devlink,
1274 unsigned int sb_index);
1275 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1276 unsigned int sb_index, u16 pool_index,
1277 u32 *p_cur, u32 *p_max);
1278 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1279 unsigned int sb_index,
1280 u16 tc_index,
1281 enum devlink_sb_pool_type pool_type,
1282 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +03001283
1284 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001285 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1286 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +02001287 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001288 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1289 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +03001290 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1291 enum devlink_eswitch_encap_mode *p_encap_mode);
1292 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1293 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +03001294 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001295 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1296 struct netlink_ext_ack *extack);
Jacob Keller22ec3d22020-09-25 13:46:05 -07001297 /**
1298 * @flash_update: Device flash update function
1299 *
1300 * Used to perform a flash update for the device. The set of
1301 * parameters supported by the driver should be set in
1302 * supported_flash_update_params.
1303 */
Jacob Kellerbc75c052020-09-25 13:46:06 -07001304 int (*flash_update)(struct devlink *devlink,
1305 struct devlink_flash_update_params *params,
Jakub Kicinski76726cc2019-02-14 13:40:44 -08001306 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001307 /**
1308 * @trap_init: Trap initialization function.
1309 *
1310 * Should be used by device drivers to initialize the trap in the
1311 * underlying device. Drivers should also store the provided trap
1312 * context, so that they could efficiently pass it to
1313 * devlink_trap_report() when the trap is triggered.
1314 */
1315 int (*trap_init)(struct devlink *devlink,
1316 const struct devlink_trap *trap, void *trap_ctx);
1317 /**
1318 * @trap_fini: Trap de-initialization function.
1319 *
1320 * Should be used by device drivers to de-initialize the trap in the
1321 * underlying device.
1322 */
1323 void (*trap_fini)(struct devlink *devlink,
1324 const struct devlink_trap *trap, void *trap_ctx);
1325 /**
1326 * @trap_action_set: Trap action set function.
1327 */
1328 int (*trap_action_set)(struct devlink *devlink,
1329 const struct devlink_trap *trap,
Ido Schimmelc88e11e2020-08-03 19:11:34 +03001330 enum devlink_trap_action action,
1331 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001332 /**
1333 * @trap_group_init: Trap group initialization function.
1334 *
1335 * Should be used by device drivers to initialize the trap group in the
1336 * underlying device.
1337 */
1338 int (*trap_group_init)(struct devlink *devlink,
1339 const struct devlink_trap_group *group);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001340 /**
Ido Schimmelc0648752020-03-30 22:38:22 +03001341 * @trap_group_set: Trap group parameters set function.
1342 *
1343 * Note: @policer can be NULL when a policer is being unbound from
1344 * @group.
1345 */
1346 int (*trap_group_set)(struct devlink *devlink,
1347 const struct devlink_trap_group *group,
Ido Schimmelc88e11e2020-08-03 19:11:34 +03001348 const struct devlink_trap_policer *policer,
1349 struct netlink_ext_ack *extack);
Ido Schimmelc0648752020-03-30 22:38:22 +03001350 /**
Ioana Ciorneic50bf2b2020-10-01 18:11:46 +03001351 * @trap_group_action_set: Trap group action set function.
1352 *
1353 * If this callback is populated, it will take precedence over looping
1354 * over all traps in a group and calling .trap_action_set().
1355 */
1356 int (*trap_group_action_set)(struct devlink *devlink,
1357 const struct devlink_trap_group *group,
1358 enum devlink_trap_action action,
1359 struct netlink_ext_ack *extack);
1360 /**
Oleksandr Mazurddee9db2021-06-14 16:01:12 +03001361 * @trap_drop_counter_get: Trap drop counter get function.
1362 *
1363 * Should be used by device drivers to report number of packets
1364 * that have been dropped, and cannot be passed to the devlink
1365 * subsystem by the underlying device.
1366 */
1367 int (*trap_drop_counter_get)(struct devlink *devlink,
1368 const struct devlink_trap *trap,
1369 u64 *p_drops);
1370 /**
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001371 * @trap_policer_init: Trap policer initialization function.
1372 *
1373 * Should be used by device drivers to initialize the trap policer in
1374 * the underlying device.
1375 */
1376 int (*trap_policer_init)(struct devlink *devlink,
1377 const struct devlink_trap_policer *policer);
1378 /**
1379 * @trap_policer_fini: Trap policer de-initialization function.
1380 *
1381 * Should be used by device drivers to de-initialize the trap policer
1382 * in the underlying device.
1383 */
1384 void (*trap_policer_fini)(struct devlink *devlink,
1385 const struct devlink_trap_policer *policer);
1386 /**
1387 * @trap_policer_set: Trap policer parameters set function.
1388 */
1389 int (*trap_policer_set)(struct devlink *devlink,
1390 const struct devlink_trap_policer *policer,
1391 u64 rate, u64 burst,
1392 struct netlink_ext_ack *extack);
1393 /**
1394 * @trap_policer_counter_get: Trap policer counter get function.
1395 *
1396 * Should be used by device drivers to report number of packets dropped
1397 * by the policer.
1398 */
1399 int (*trap_policer_counter_get)(struct devlink *devlink,
1400 const struct devlink_trap_policer *policer,
1401 u64 *p_drops);
Parav Pandit2a916ec2020-06-19 03:32:48 +00001402 /**
1403 * @port_function_hw_addr_get: Port function's hardware address get function.
1404 *
1405 * Should be used by device drivers to report the hardware address of a function managed
1406 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1407 * function handling for a particular port.
1408 *
1409 * Note: @extack can be NULL when port notifier queries the port function.
1410 */
Leon Romanovsky82564f62021-08-08 14:41:21 +03001411 int (*port_function_hw_addr_get)(struct devlink_port *port, u8 *hw_addr,
1412 int *hw_addr_len,
Parav Pandit2a916ec2020-06-19 03:32:48 +00001413 struct netlink_ext_ack *extack);
Parav Pandita1e8ae92020-06-19 03:32:49 +00001414 /**
1415 * @port_function_hw_addr_set: Port function's hardware address set function.
1416 *
1417 * Should be used by device drivers to set the hardware address of a function managed
1418 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1419 * function handling for a particular port.
1420 */
Leon Romanovsky82564f62021-08-08 14:41:21 +03001421 int (*port_function_hw_addr_set)(struct devlink_port *port,
Parav Pandita1e8ae92020-06-19 03:32:49 +00001422 const u8 *hw_addr, int hw_addr_len,
1423 struct netlink_ext_ack *extack);
Parav Panditcd76dcd2020-12-11 22:12:14 -08001424 /**
1425 * port_new() - Add a new port function of a specified flavor
1426 * @devlink: Devlink instance
1427 * @attrs: attributes of the new port
1428 * @extack: extack for reporting error messages
1429 * @new_port_index: index of the new port
1430 *
1431 * Devlink core will call this device driver function upon user request
1432 * to create a new port function of a specified flavor and optional
1433 * attributes
1434 *
1435 * Notes:
1436 * - Called without devlink instance lock being held. Drivers must
1437 * implement own means of synchronization
1438 * - On success, drivers must register a port with devlink core
1439 *
1440 * Return: 0 on success, negative value otherwise.
1441 */
1442 int (*port_new)(struct devlink *devlink,
1443 const struct devlink_port_new_attrs *attrs,
1444 struct netlink_ext_ack *extack,
1445 unsigned int *new_port_index);
1446 /**
1447 * port_del() - Delete a port function
1448 * @devlink: Devlink instance
1449 * @port_index: port function index to delete
1450 * @extack: extack for reporting error messages
1451 *
1452 * Devlink core will call this device driver function upon user request
1453 * to delete a previously created port function
1454 *
1455 * Notes:
1456 * - Called without devlink instance lock being held. Drivers must
1457 * implement own means of synchronization
1458 * - On success, drivers must unregister the corresponding devlink
1459 * port
1460 *
1461 * Return: 0 on success, negative value otherwise.
1462 */
1463 int (*port_del)(struct devlink *devlink, unsigned int port_index,
1464 struct netlink_ext_ack *extack);
Parav Pandita556dde2020-12-11 22:12:15 -08001465 /**
1466 * port_fn_state_get() - Get the state of a port function
1467 * @devlink: Devlink instance
1468 * @port: The devlink port
1469 * @state: Admin configured state
1470 * @opstate: Current operational state
1471 * @extack: extack for reporting error messages
1472 *
1473 * Reports the admin and operational state of a devlink port function
1474 *
1475 * Return: 0 on success, negative value otherwise.
1476 */
Leon Romanovsky82564f62021-08-08 14:41:21 +03001477 int (*port_fn_state_get)(struct devlink_port *port,
Parav Pandita556dde2020-12-11 22:12:15 -08001478 enum devlink_port_fn_state *state,
1479 enum devlink_port_fn_opstate *opstate,
1480 struct netlink_ext_ack *extack);
1481 /**
1482 * port_fn_state_set() - Set the admin state of a port function
1483 * @devlink: Devlink instance
1484 * @port: The devlink port
1485 * @state: Admin state
1486 * @extack: extack for reporting error messages
1487 *
1488 * Set the admin state of a devlink port function
1489 *
1490 * Return: 0 on success, negative value otherwise.
1491 */
Leon Romanovsky82564f62021-08-08 14:41:21 +03001492 int (*port_fn_state_set)(struct devlink_port *port,
Parav Pandita556dde2020-12-11 22:12:15 -08001493 enum devlink_port_fn_state state,
1494 struct netlink_ext_ack *extack);
Dmytro Linkin1897db22021-06-02 15:17:22 +03001495
1496 /**
1497 * Rate control callbacks.
1498 */
1499 int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1500 u64 tx_share, struct netlink_ext_ack *extack);
1501 int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1502 u64 tx_max, struct netlink_ext_ack *extack);
Dmytro Linkina8ecb932021-06-02 15:17:25 +03001503 int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv,
1504 u64 tx_share, struct netlink_ext_ack *extack);
1505 int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv,
1506 u64 tx_max, struct netlink_ext_ack *extack);
1507 int (*rate_node_new)(struct devlink_rate *rate_node, void **priv,
1508 struct netlink_ext_ack *extack);
1509 int (*rate_node_del)(struct devlink_rate *rate_node, void *priv,
1510 struct netlink_ext_ack *extack);
Dmytro Linkind7555982021-06-02 15:17:28 +03001511 int (*rate_leaf_parent_set)(struct devlink_rate *child,
1512 struct devlink_rate *parent,
1513 void *priv_child, void *priv_parent,
1514 struct netlink_ext_ack *extack);
1515 int (*rate_node_parent_set)(struct devlink_rate *child,
1516 struct devlink_rate *parent,
1517 void *priv_child, void *priv_parent,
1518 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001519};
1520
1521static inline void *devlink_priv(struct devlink *devlink)
1522{
1523 BUG_ON(!devlink);
1524 return &devlink->priv;
1525}
1526
1527static inline struct devlink *priv_to_devlink(void *priv)
1528{
1529 BUG_ON(!priv);
1530 return container_of(priv, struct devlink, priv);
1531}
1532
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001533static inline struct devlink_port *
1534netdev_to_devlink_port(struct net_device *dev)
1535{
1536 if (dev->netdev_ops->ndo_get_devlink_port)
1537 return dev->netdev_ops->ndo_get_devlink_port(dev);
1538 return NULL;
1539}
1540
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001541static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1542{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001543 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1544
1545 if (devlink_port)
1546 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001547 return NULL;
1548}
1549
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001550struct ib_device;
1551
Jiri Pirko471f8942019-10-03 11:49:31 +02001552struct net *devlink_net(const struct devlink *devlink);
Leon Romanovsky26713452021-07-29 20:19:25 +03001553/* This call is intended for software devices that can create
1554 * devlink instances in other namespaces than init_net.
1555 *
1556 * Drivers that operate on real HW must use devlink_alloc() instead.
1557 */
1558struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
Leon Romanovsky919d13a2021-08-08 21:57:43 +03001559 size_t priv_size, struct net *net,
1560 struct device *dev);
Leon Romanovsky26713452021-07-29 20:19:25 +03001561static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
Leon Romanovsky919d13a2021-08-08 21:57:43 +03001562 size_t priv_size,
1563 struct device *dev)
Leon Romanovsky26713452021-07-29 20:19:25 +03001564{
Leon Romanovsky919d13a2021-08-08 21:57:43 +03001565 return devlink_alloc_ns(ops, priv_size, &init_net, dev);
Leon Romanovsky26713452021-07-29 20:19:25 +03001566}
Leon Romanovsky919d13a2021-08-08 21:57:43 +03001567int devlink_register(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001568void devlink_unregister(struct devlink *devlink);
Jiri Pirkoa0c76342019-11-08 21:42:43 +01001569void devlink_reload_enable(struct devlink *devlink);
1570void devlink_reload_disable(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001571void devlink_free(struct devlink *devlink);
1572int devlink_port_register(struct devlink *devlink,
1573 struct devlink_port *devlink_port,
1574 unsigned int port_index);
1575void devlink_port_unregister(struct devlink_port *devlink_port);
1576void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1577 struct net_device *netdev);
1578void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1579 struct ib_device *ibdev);
1580void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +02001581void devlink_port_attrs_set(struct devlink_port *devlink_port,
Danielle Ratson71ad8d52020-07-09 16:18:16 +03001582 struct devlink_port_attrs *devlink_port_attrs);
Parav Pandit3a2d9582020-09-09 07:50:37 +03001583void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1584 u16 pf, bool external);
1585void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
Parav Pandit05b595e2020-09-09 07:50:36 +03001586 u16 pf, u16 vf, bool external);
Parav Panditb8288832020-12-11 22:12:13 -08001587void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
Parav Pandita1ab3e42021-03-10 15:35:03 +02001588 u32 controller, u16 pf, u32 sf,
1589 bool external);
Dmytro Linkin4677efc2021-06-02 15:17:19 +03001590int devlink_rate_leaf_create(struct devlink_port *port, void *priv);
1591void devlink_rate_leaf_destroy(struct devlink_port *devlink_port);
Dmytro Linkina8ecb932021-06-02 15:17:25 +03001592void devlink_rate_nodes_destroy(struct devlink *devlink);
Jiri Pirkobf797472016-04-14 18:19:13 +02001593int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1594 u32 size, u16 ingress_pools_count,
1595 u16 egress_pools_count, u16 ingress_tc_count,
1596 u16 egress_tc_count);
1597void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001598int devlink_dpipe_table_register(struct devlink *devlink,
1599 const char *table_name,
1600 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +02001601 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001602void devlink_dpipe_table_unregister(struct devlink *devlink,
1603 const char *table_name);
1604int devlink_dpipe_headers_register(struct devlink *devlink,
1605 struct devlink_dpipe_headers *dpipe_headers);
1606void devlink_dpipe_headers_unregister(struct devlink *devlink);
1607bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1608 const char *table_name);
1609int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1610int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1611 struct devlink_dpipe_entry *entry);
1612int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +02001613void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001614int devlink_dpipe_action_put(struct sk_buff *skb,
1615 struct devlink_dpipe_action *action);
1616int devlink_dpipe_match_put(struct sk_buff *skb,
1617 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +02001618extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +02001619extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +02001620extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001621
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001622int devlink_resource_register(struct devlink *devlink,
1623 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001624 u64 resource_size,
1625 u64 resource_id,
1626 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +02001627 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001628void devlink_resources_unregister(struct devlink *devlink,
1629 struct devlink_resource *resource);
1630int devlink_resource_size_get(struct devlink *devlink,
1631 u64 resource_id,
1632 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +01001633int devlink_dpipe_table_resource_set(struct devlink *devlink,
1634 const char *table_name, u64 resource_id,
1635 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +02001636void devlink_resource_occ_get_register(struct devlink *devlink,
1637 u64 resource_id,
1638 devlink_resource_occ_get_t *occ_get,
1639 void *occ_get_priv);
1640void devlink_resource_occ_get_unregister(struct devlink *devlink,
1641 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +03001642int devlink_params_register(struct devlink *devlink,
1643 const struct devlink_param *params,
1644 size_t params_count);
1645void devlink_params_unregister(struct devlink *devlink,
1646 const struct devlink_param *params,
1647 size_t params_count);
Parav Panditb40c51e2021-08-10 16:24:19 +03001648int devlink_param_register(struct devlink *devlink,
1649 const struct devlink_param *param);
1650void devlink_param_unregister(struct devlink *devlink,
1651 const struct devlink_param *param);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +00001652void devlink_params_publish(struct devlink *devlink);
1653void devlink_params_unpublish(struct devlink *devlink);
Parav Pandit9c4a7662021-08-10 16:24:20 +03001654void devlink_param_publish(struct devlink *devlink,
1655 const struct devlink_param *param);
1656void devlink_param_unpublish(struct devlink *devlink,
1657 const struct devlink_param *param);
Vasundhara Volam39e61602019-01-28 18:00:20 +05301658int devlink_port_params_register(struct devlink_port *devlink_port,
1659 const struct devlink_param *params,
1660 size_t params_count);
1661void devlink_port_params_unregister(struct devlink_port *devlink_port,
1662 const struct devlink_param *params,
1663 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +03001664int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1665 union devlink_param_value *init_val);
1666int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1667 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +05301668int
1669devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1670 u32 param_id,
1671 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +05301672int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1673 u32 param_id,
1674 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +03001675void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +05301676void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1677 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +03001678void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1679 const char *src);
Jacob Kellere8937682020-03-26 11:37:08 -07001680struct devlink_region *
1681devlink_region_create(struct devlink *devlink,
1682 const struct devlink_region_ops *ops,
1683 u32 region_max_snapshots, u64 region_size);
Andrew Lunn544e7c32020-10-04 18:12:54 +02001684struct devlink_region *
1685devlink_port_region_create(struct devlink_port *port,
1686 const struct devlink_port_region_ops *ops,
1687 u32 region_max_snapshots, u64 region_size);
Alex Veskerb16ebe92018-07-12 15:13:08 +03001688void devlink_region_destroy(struct devlink_region *region);
Andrew Lunn544e7c32020-10-04 18:12:54 +02001689void devlink_port_region_destroy(struct devlink_region *region);
1690
Jacob Keller7ef19d32020-03-26 11:37:14 -07001691int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
Jacob Keller12102432020-03-26 11:37:15 -07001692void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
Jiri Pirko3a5e5232019-08-09 15:27:15 +02001693int devlink_region_snapshot_create(struct devlink_region *region,
Jacob Kellera0a09f62020-03-26 11:37:09 -07001694 u8 *data, u32 snapshot_id);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001695int devlink_info_serial_number_put(struct devlink_info_req *req,
1696 const char *sn);
1697int devlink_info_driver_name_put(struct devlink_info_req *req,
1698 const char *name);
Vasundhara Volamb5872cd2020-06-20 22:01:56 +05301699int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1700 const char *bsn);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -08001701int devlink_info_version_fixed_put(struct devlink_info_req *req,
1702 const char *version_name,
1703 const char *version_value);
1704int devlink_info_version_stored_put(struct devlink_info_req *req,
1705 const char *version_name,
1706 const char *version_value);
1707int devlink_info_version_running_put(struct devlink_info_req *req,
1708 const char *version_name,
1709 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001710
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001711int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1712int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1713
1714int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1715int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1716
1717int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1718 const char *name);
1719int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
Aya Levin573ed902020-02-11 14:32:42 -08001720int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1721 const char *name);
1722int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001723
1724int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1725int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1726int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1727int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1728int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
Aya Levin573ed902020-02-11 14:32:42 -08001729int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1730 u16 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001731
1732int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1733 bool value);
1734int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1735 u8 value);
1736int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1737 u32 value);
1738int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1739 u64 value);
1740int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1741 const char *value);
1742int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
Aya Levine2cde862019-11-12 14:07:49 +02001743 const void *value, u32 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001744
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001745struct devlink_health_reporter *
1746devlink_health_reporter_create(struct devlink *devlink,
1747 const struct devlink_health_reporter_ops *ops,
Eran Ben Elishaba7d16c2020-03-29 14:05:54 +03001748 u64 graceful_period, void *priv);
Vladyslav Tarasiuk15c724b2020-07-10 15:25:11 +03001749
1750struct devlink_health_reporter *
1751devlink_port_health_reporter_create(struct devlink_port *port,
1752 const struct devlink_health_reporter_ops *ops,
1753 u64 graceful_period, void *priv);
1754
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001755void
1756devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1757
Vladyslav Tarasiuk15c724b2020-07-10 15:25:11 +03001758void
1759devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
1760
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001761void *
1762devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +02001763int devlink_health_report(struct devlink_health_reporter *reporter,
1764 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001765void
1766devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1767 enum devlink_health_reporter_state state);
Vikas Gupta6181e5c2020-01-02 21:18:09 +05301768void
1769devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001770
Jiri Pirko2670ac22019-09-12 10:49:46 +02001771bool devlink_is_reload_failed(const struct devlink *devlink);
Moshe Shemesh77069ba2020-10-07 09:00:46 +03001772void devlink_remote_reload_actions_performed(struct devlink *devlink,
1773 enum devlink_reload_limit limit,
1774 u32 actions_performed);
Jiri Pirko2670ac22019-09-12 10:49:46 +02001775
Jiri Pirko191ed202019-06-04 15:40:40 +02001776void devlink_flash_update_status_notify(struct devlink *devlink,
1777 const char *status_msg,
1778 const char *component,
1779 unsigned long done,
1780 unsigned long total);
Shannon Nelsonf92970c2020-09-17 18:13:23 -07001781void devlink_flash_update_timeout_notify(struct devlink *devlink,
1782 const char *status_msg,
1783 const char *component,
1784 unsigned long timeout);
Jiri Pirko191ed202019-06-04 15:40:40 +02001785
Ido Schimmel0f420b62019-08-17 16:28:17 +03001786int devlink_traps_register(struct devlink *devlink,
1787 const struct devlink_trap *traps,
1788 size_t traps_count, void *priv);
1789void devlink_traps_unregister(struct devlink *devlink,
1790 const struct devlink_trap *traps,
1791 size_t traps_count);
Jiri Pirko5a2e1062020-02-25 11:45:21 +01001792void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1793 void *trap_ctx, struct devlink_port *in_devlink_port,
1794 const struct flow_action_cookie *fa_cookie);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001795void *devlink_trap_ctx_priv(void *trap_ctx);
Ido Schimmel95ad9552020-03-22 20:48:26 +02001796int devlink_trap_groups_register(struct devlink *devlink,
1797 const struct devlink_trap_group *groups,
1798 size_t groups_count);
1799void devlink_trap_groups_unregister(struct devlink *devlink,
1800 const struct devlink_trap_group *groups,
1801 size_t groups_count);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001802int
1803devlink_trap_policers_register(struct devlink *devlink,
1804 const struct devlink_trap_policer *policers,
1805 size_t policers_count);
1806void
1807devlink_trap_policers_unregister(struct devlink *devlink,
1808 const struct devlink_trap_policer *policers,
1809 size_t policers_count);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001810
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001811#if IS_ENABLED(CONFIG_NET_DEVLINK)
1812
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001813void devlink_compat_running_version(struct net_device *dev,
1814 char *buf, size_t len);
1815int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001816int devlink_compat_phys_port_name_get(struct net_device *dev,
1817 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001818int devlink_compat_switch_id_get(struct net_device *dev,
1819 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001820
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001821#else
1822
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001823static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001824devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1825{
1826}
Jakub Kicinski4eceba12019-02-14 13:40:45 -08001827
1828static inline int
1829devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1830{
1831 return -EOPNOTSUPP;
1832}
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001833
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001834static inline int
1835devlink_compat_phys_port_name_get(struct net_device *dev,
1836 char *name, size_t len)
1837{
1838 return -EOPNOTSUPP;
1839}
1840
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001841static inline int
1842devlink_compat_switch_id_get(struct net_device *dev,
1843 struct netdev_phys_item_id *ppid)
1844{
1845 return -EOPNOTSUPP;
1846}
1847
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001848#endif
1849
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001850#endif /* _NET_DEVLINK_H_ */