blob: 7794e1601772876ff72bd775d4058abc1d4e33d5 [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>
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010022
23struct devlink_ops;
24
25struct devlink {
26 struct list_head list;
27 struct list_head port_list;
Jiri Pirkobf797472016-04-14 18:19:13 +020028 struct list_head sb_list;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020029 struct list_head dpipe_table_list;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +010030 struct list_head resource_list;
Moshe Shemesheabaef12018-07-04 14:30:28 +030031 struct list_head param_list;
Alex Veskerb16ebe92018-07-12 15:13:08 +030032 struct list_head region_list;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +020033 struct list_head reporter_list;
Moshe Shemeshb587bda2019-04-29 12:41:45 +030034 struct mutex reporters_lock; /* protects reporter_list */
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +020035 struct devlink_dpipe_headers *dpipe_headers;
Ido Schimmel0f420b62019-08-17 16:28:17 +030036 struct list_head trap_list;
37 struct list_head trap_group_list;
Ido Schimmel1e8c6612020-03-30 22:38:18 +030038 struct list_head trap_policer_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010039 const struct devlink_ops *ops;
Jacob Keller12102432020-03-26 11:37:15 -070040 struct xarray snapshot_ids;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010041 struct device *dev;
42 possible_net_t _net;
Parav Pandit336ce1c2020-07-21 19:53:53 +030043 struct mutex lock; /* Serializes access to devlink instance specific objects such as
44 * port, sb, dpipe, resource, params, region, traps and more.
45 */
Jiri Pirkoa0c76342019-11-08 21:42:43 +010046 u8 reload_failed:1,
47 reload_enabled:1,
48 registered:1;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +010049 char priv[0] __aligned(NETDEV_ALIGN);
50};
51
Parav Pandit378ef012019-07-08 23:17:35 -050052struct devlink_port_phys_attrs {
53 u32 port_number; /* Same value as "split group".
54 * A physical port which is visible to the user
55 * for a given port flavour.
56 */
Danielle Ratson71ad8d52020-07-09 16:18:16 +030057 u32 split_subport_number; /* If the port is split, this is the number of subport. */
Parav Pandit378ef012019-07-08 23:17:35 -050058};
59
Parav Panditff03e632020-09-09 07:50:35 +030060/**
61 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
Parav Pandit3a2d9582020-09-09 07:50:37 +030062 * @controller: Associated controller number
Parav Panditff03e632020-09-09 07:50:35 +030063 * @pf: Associated PCI PF number for this port.
Parav Pandit05b595e2020-09-09 07:50:36 +030064 * @external: when set, indicates if a port is for an external controller
Parav Panditff03e632020-09-09 07:50:35 +030065 */
Parav Pandit98fd2d62019-07-08 23:17:37 -050066struct devlink_port_pci_pf_attrs {
Parav Pandit3a2d9582020-09-09 07:50:37 +030067 u32 controller;
Parav Panditff03e632020-09-09 07:50:35 +030068 u16 pf;
Parav Pandit05b595e2020-09-09 07:50:36 +030069 u8 external:1;
Parav Pandit98fd2d62019-07-08 23:17:37 -050070};
71
Parav Panditff03e632020-09-09 07:50:35 +030072/**
73 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
Parav Pandit3a2d9582020-09-09 07:50:37 +030074 * @controller: Associated controller number
Parav Panditff03e632020-09-09 07:50:35 +030075 * @pf: Associated PCI PF number for this port.
76 * @vf: Associated PCI VF for of the PCI PF for this port.
Parav Pandit05b595e2020-09-09 07:50:36 +030077 * @external: when set, indicates if a port is for an external controller
Parav Panditff03e632020-09-09 07:50:35 +030078 */
Parav Pandite41b6bf2019-07-08 23:17:38 -050079struct devlink_port_pci_vf_attrs {
Parav Pandit3a2d9582020-09-09 07:50:37 +030080 u32 controller;
Parav Panditff03e632020-09-09 07:50:35 +030081 u16 pf;
82 u16 vf;
Parav Pandit05b595e2020-09-09 07:50:36 +030083 u8 external:1;
Parav Pandite41b6bf2019-07-08 23:17:38 -050084};
85
Danielle Ratson71ad8d52020-07-09 16:18:16 +030086/**
87 * struct devlink_port_attrs - devlink port object
88 * @flavour: flavour of the port
89 * @split: indicates if this is split port
Danielle Ratsona0f49b52020-07-09 16:18:20 +030090 * @splittable: indicates if the port can be split.
Danielle Ratsona21cf0a2020-07-09 16:18:18 +030091 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink.
Danielle Ratson71ad8d52020-07-09 16:18:16 +030092 * @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 +030093 * @phys: physical port attributes
94 * @pci_pf: PCI PF port attributes
95 * @pci_vf: PCI VF port attributes
Danielle Ratson71ad8d52020-07-09 16:18:16 +030096 */
Jiri Pirkob9ffcba2018-05-18 09:29:00 +020097struct devlink_port_attrs {
Danielle Ratsona0f49b52020-07-09 16:18:20 +030098 u8 split:1,
99 splittable:1;
Danielle Ratsona21cf0a2020-07-09 16:18:18 +0300100 u32 lanes;
Jiri Pirko5ec13802018-05-18 09:29:01 +0200101 enum devlink_port_flavour flavour;
Jiri Pirkobec52672019-04-03 14:24:16 +0200102 struct netdev_phys_item_id switch_id;
Parav Pandit378ef012019-07-08 23:17:35 -0500103 union {
104 struct devlink_port_phys_attrs phys;
Parav Pandit98fd2d62019-07-08 23:17:37 -0500105 struct devlink_port_pci_pf_attrs pci_pf;
Parav Pandite41b6bf2019-07-08 23:17:38 -0500106 struct devlink_port_pci_vf_attrs pci_vf;
Parav Pandit378ef012019-07-08 23:17:35 -0500107 };
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200108};
109
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100110struct devlink_port {
111 struct list_head list;
Vasundhara Volam39e61602019-01-28 18:00:20 +0530112 struct list_head param_list;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100113 struct devlink *devlink;
Parav Panditc7282b52019-08-30 05:39:44 -0500114 unsigned int index;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100115 bool registered;
Jiri Pirkob8f97552019-03-24 11:14:37 +0100116 spinlock_t type_lock; /* Protects type and type_dev
117 * pointer consistency.
118 */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100119 enum devlink_port_type type;
120 enum devlink_port_type desired_type;
121 void *type_dev;
Jiri Pirkob9ffcba2018-05-18 09:29:00 +0200122 struct devlink_port_attrs attrs;
Danielle Ratson46737a12020-07-09 16:18:15 +0300123 u8 attrs_set:1,
124 switch_port:1;
Jiri Pirko136bf272019-05-23 10:43:35 +0200125 struct delayed_work type_warn_dw;
Vladyslav Tarasiukf4f54162020-07-10 15:25:10 +0300126 struct list_head reporter_list;
127 struct mutex reporters_lock; /* Protects reporter_list */
Jiri Pirkobfcd3a42016-02-26 17:32:23 +0100128};
129
Jiri Pirkobf797472016-04-14 18:19:13 +0200130struct devlink_sb_pool_info {
131 enum devlink_sb_pool_type pool_type;
132 u32 size;
133 enum devlink_sb_threshold_type threshold_type;
Jakub Kicinskibff57312019-02-01 17:56:28 -0800134 u32 cell_size;
Jiri Pirkobf797472016-04-14 18:19:13 +0200135};
136
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200137/**
138 * struct devlink_dpipe_field - dpipe field object
139 * @name: field name
140 * @id: index inside the headers field array
141 * @bitwidth: bitwidth
142 * @mapping_type: mapping type
143 */
144struct devlink_dpipe_field {
145 const char *name;
146 unsigned int id;
147 unsigned int bitwidth;
148 enum devlink_dpipe_field_mapping_type mapping_type;
149};
150
151/**
152 * struct devlink_dpipe_header - dpipe header object
153 * @name: header name
154 * @id: index, global/local detrmined by global bit
155 * @fields: fields
156 * @fields_count: number of fields
157 * @global: indicates if header is shared like most protocol header
158 * or driver specific
159 */
160struct devlink_dpipe_header {
161 const char *name;
162 unsigned int id;
163 struct devlink_dpipe_field *fields;
164 unsigned int fields_count;
165 bool global;
166};
167
168/**
169 * struct devlink_dpipe_match - represents match operation
170 * @type: type of match
171 * @header_index: header index (packets can have several headers of same
172 * type like in case of tunnels)
173 * @header: header
174 * @fieled_id: field index
175 */
176struct devlink_dpipe_match {
177 enum devlink_dpipe_match_type type;
178 unsigned int header_index;
179 struct devlink_dpipe_header *header;
180 unsigned int field_id;
181};
182
183/**
184 * struct devlink_dpipe_action - represents action operation
185 * @type: type of action
186 * @header_index: header index (packets can have several headers of same
187 * type like in case of tunnels)
188 * @header: header
189 * @fieled_id: field index
190 */
191struct devlink_dpipe_action {
192 enum devlink_dpipe_action_type type;
193 unsigned int header_index;
194 struct devlink_dpipe_header *header;
195 unsigned int field_id;
196};
197
198/**
199 * struct devlink_dpipe_value - represents value of match/action
200 * @action: action
201 * @match: match
202 * @mapping_value: in case the field has some mapping this value
203 * specified the mapping value
204 * @mapping_valid: specify if mapping value is valid
205 * @value_size: value size
206 * @value: value
207 * @mask: bit mask
208 */
209struct devlink_dpipe_value {
210 union {
211 struct devlink_dpipe_action *action;
212 struct devlink_dpipe_match *match;
213 };
214 unsigned int mapping_value;
215 bool mapping_valid;
216 unsigned int value_size;
217 void *value;
218 void *mask;
219};
220
221/**
222 * struct devlink_dpipe_entry - table entry object
223 * @index: index of the entry in the table
224 * @match_values: match values
225 * @matche_values_count: count of matches tuples
226 * @action_values: actions values
227 * @action_values_count: count of actions values
228 * @counter: value of counter
229 * @counter_valid: Specify if value is valid from hardware
230 */
231struct devlink_dpipe_entry {
232 u64 index;
233 struct devlink_dpipe_value *match_values;
234 unsigned int match_values_count;
235 struct devlink_dpipe_value *action_values;
236 unsigned int action_values_count;
237 u64 counter;
238 bool counter_valid;
239};
240
241/**
242 * struct devlink_dpipe_dump_ctx - context provided to driver in order
243 * to dump
244 * @info: info
245 * @cmd: devlink command
246 * @skb: skb
247 * @nest: top attribute
248 * @hdr: hdr
249 */
250struct devlink_dpipe_dump_ctx {
251 struct genl_info *info;
252 enum devlink_command cmd;
253 struct sk_buff *skb;
254 struct nlattr *nest;
255 void *hdr;
256};
257
258struct devlink_dpipe_table_ops;
259
260/**
261 * struct devlink_dpipe_table - table object
262 * @priv: private
263 * @name: table name
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200264 * @counters_enabled: indicates if counters are active
265 * @counter_control_extern: indicates if counter control is in dpipe or
266 * external tool
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100267 * @resource_valid: Indicate that the resource id is valid
268 * @resource_id: relative resource this table is related to
269 * @resource_units: number of resource's unit consumed per table's entry
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200270 * @table_ops: table operations
271 * @rcu: rcu
272 */
273struct devlink_dpipe_table {
274 void *priv;
275 struct list_head list;
276 const char *name;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200277 bool counters_enabled;
278 bool counter_control_extern;
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +0100279 bool resource_valid;
280 u64 resource_id;
281 u64 resource_units;
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200282 struct devlink_dpipe_table_ops *table_ops;
283 struct rcu_head rcu;
284};
285
286/**
287 * struct devlink_dpipe_table_ops - dpipe_table ops
288 * @actions_dump - dumps all tables actions
289 * @matches_dump - dumps all tables matches
290 * @entries_dump - dumps all active entries in the table
291 * @counters_set_update - when changing the counter status hardware sync
292 * maybe needed to allocate/free counter related
293 * resources
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200294 * @size_get - get size
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200295 */
296struct devlink_dpipe_table_ops {
297 int (*actions_dump)(void *priv, struct sk_buff *skb);
298 int (*matches_dump)(void *priv, struct sk_buff *skb);
299 int (*entries_dump)(void *priv, bool counters_enabled,
300 struct devlink_dpipe_dump_ctx *dump_ctx);
301 int (*counters_set_update)(void *priv, bool enable);
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +0200302 u64 (*size_get)(void *priv);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +0200303};
304
305/**
306 * struct devlink_dpipe_headers - dpipe headers
307 * @headers - header array can be shared (global bit) or driver specific
308 * @headers_count - count of headers
309 */
310struct devlink_dpipe_headers {
311 struct devlink_dpipe_header **headers;
312 unsigned int headers_count;
313};
314
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100315/**
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100316 * struct devlink_resource_size_params - resource's size parameters
317 * @size_min: minimum size which can be set
318 * @size_max: maximum size which can be set
319 * @size_granularity: size granularity
320 * @size_unit: resource's basic unit
321 */
322struct devlink_resource_size_params {
323 u64 size_min;
324 u64 size_max;
325 u64 size_granularity;
326 enum devlink_resource_unit unit;
327};
328
Jiri Pirko77d27092018-02-28 13:12:09 +0100329static inline void
330devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
331 u64 size_min, u64 size_max,
332 u64 size_granularity,
333 enum devlink_resource_unit unit)
334{
335 size_params->size_min = size_min;
336 size_params->size_max = size_max;
337 size_params->size_granularity = size_granularity;
338 size_params->unit = unit;
339}
340
Jiri Pirkofc56be42018-04-05 22:13:21 +0200341typedef u64 devlink_resource_occ_get_t(void *priv);
342
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100343/**
344 * struct devlink_resource - devlink resource
345 * @name: name of the resource
346 * @id: id, per devlink instance
347 * @size: size of the resource
348 * @size_new: updated size of the resource, reload is needed
349 * @size_valid: valid in case the total size of the resource is valid
350 * including its children
351 * @parent: parent resource
352 * @size_params: size parameters
353 * @list: parent list
354 * @resource_list: list of child resources
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100355 */
356struct devlink_resource {
357 const char *name;
358 u64 id;
359 u64 size;
360 u64 size_new;
361 bool size_valid;
362 struct devlink_resource *parent;
Jiri Pirko77d27092018-02-28 13:12:09 +0100363 struct devlink_resource_size_params size_params;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100364 struct list_head list;
365 struct list_head resource_list;
Jiri Pirkofc56be42018-04-05 22:13:21 +0200366 devlink_resource_occ_get_t *occ_get;
367 void *occ_get_priv;
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +0100368};
369
370#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
371
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300372#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
Moshe Shemesheabaef12018-07-04 14:30:28 +0300373enum devlink_param_type {
374 DEVLINK_PARAM_TYPE_U8,
375 DEVLINK_PARAM_TYPE_U16,
376 DEVLINK_PARAM_TYPE_U32,
377 DEVLINK_PARAM_TYPE_STRING,
378 DEVLINK_PARAM_TYPE_BOOL,
379};
380
381union devlink_param_value {
382 u8 vu8;
383 u16 vu16;
384 u32 vu32;
Moshe Shemeshbde74ad12018-10-10 16:09:27 +0300385 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
Moshe Shemesheabaef12018-07-04 14:30:28 +0300386 bool vbool;
387};
388
389struct devlink_param_gset_ctx {
390 union devlink_param_value val;
391 enum devlink_param_cmode cmode;
392};
393
394/**
Shannon Nelson6700acc2020-09-17 18:13:24 -0700395 * struct devlink_flash_notify - devlink dev flash notify data
396 * @status_msg: current status string
397 * @component: firmware component being updated
398 * @done: amount of work completed of total amount
399 * @total: amount of work expected to be done
400 * @timeout: expected max timeout in seconds
401 *
402 * These are values to be given to userland to be displayed in order
403 * to show current activity in a firmware update process.
404 */
405struct devlink_flash_notify {
406 const char *status_msg;
407 const char *component;
408 unsigned long done;
409 unsigned long total;
410 unsigned long timeout;
411};
412
413/**
Moshe Shemesheabaef12018-07-04 14:30:28 +0300414 * struct devlink_param - devlink configuration parameter data
415 * @name: name of the parameter
416 * @generic: indicates if the parameter is generic or driver specific
417 * @type: parameter type
418 * @supported_cmodes: bitmap of supported configuration modes
419 * @get: get parameter value, used for runtime and permanent
420 * configuration modes
421 * @set: set parameter value, used for runtime and permanent
422 * configuration modes
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300423 * @validate: validate input value is applicable (within value range, etc.)
Moshe Shemesheabaef12018-07-04 14:30:28 +0300424 *
425 * This struct should be used by the driver to fill the data for
426 * a parameter it registers.
427 */
428struct devlink_param {
429 u32 id;
430 const char *name;
431 bool generic;
432 enum devlink_param_type type;
433 unsigned long supported_cmodes;
434 int (*get)(struct devlink *devlink, u32 id,
435 struct devlink_param_gset_ctx *ctx);
436 int (*set)(struct devlink *devlink, u32 id,
437 struct devlink_param_gset_ctx *ctx);
Moshe Shemeshe3b7ca12018-07-04 14:30:30 +0300438 int (*validate)(struct devlink *devlink, u32 id,
439 union devlink_param_value val,
440 struct netlink_ext_ack *extack);
Moshe Shemesheabaef12018-07-04 14:30:28 +0300441};
442
443struct devlink_param_item {
444 struct list_head list;
445 const struct devlink_param *param;
446 union devlink_param_value driverinit_value;
447 bool driverinit_value_valid;
Jiri Pirko7c62cfb2019-02-07 11:22:45 +0000448 bool published;
Moshe Shemesheabaef12018-07-04 14:30:28 +0300449};
450
451enum devlink_param_generic_id {
Moshe Shemesh036467c2018-07-04 14:30:33 +0300452 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
453 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300454 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
Alex Veskerf6a698852018-07-12 15:13:17 +0300455 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
Vasundhara Volame3b51062018-10-04 11:13:44 +0530456 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530457 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
Vasundhara Volam16511782018-10-04 11:13:46 +0530458 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
Shalom Toledo846e9802018-12-03 07:58:59 +0000459 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100460 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000461 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
Moshe Shemesheabaef12018-07-04 14:30:28 +0300462
463 /* add new param generic ids above here*/
464 __DEVLINK_PARAM_GENERIC_ID_MAX,
465 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
466};
467
Moshe Shemesh036467c2018-07-04 14:30:33 +0300468#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
469#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
470
471#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
472#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
473
Vasundhara Volamf567bcd2018-07-04 14:30:36 +0300474#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
475#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
476
Alex Veskerf6a698852018-07-12 15:13:17 +0300477#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
478#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
479
Vasundhara Volame3b51062018-10-04 11:13:44 +0530480#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
481#define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
482
Vasundhara Volamf61cba42018-10-04 11:13:45 +0530483#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
484#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
485
Vasundhara Volam16511782018-10-04 11:13:46 +0530486#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
487#define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
488
Shalom Toledo846e9802018-12-03 07:58:59 +0000489#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
490#define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
491
Dirk van der Merwe5bbd21d2019-09-09 00:54:18 +0100492#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \
493 "reset_dev_on_drv_probe"
494#define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8
495
Michael Guralnik6c7295e2019-11-08 23:45:20 +0000496#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce"
497#define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL
498
Moshe Shemesh036467c2018-07-04 14:30:33 +0300499#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
500{ \
501 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
502 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
503 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
504 .generic = true, \
505 .supported_cmodes = _cmodes, \
506 .get = _get, \
507 .set = _set, \
508 .validate = _validate, \
509}
510
511#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
512{ \
513 .id = _id, \
514 .name = _name, \
515 .type = _type, \
516 .supported_cmodes = _cmodes, \
517 .get = _get, \
518 .set = _set, \
519 .validate = _validate, \
520}
521
Jakub Kicinski785bd552019-01-31 10:50:42 -0800522/* Part number, identifier of board design */
523#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id"
524/* Revision of board design */
525#define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev"
Jakub Kicinski14fd1902019-02-10 19:35:29 -0800526/* Maker of the board */
527#define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800528
Shannon Nelson7d5aa9a2019-09-03 15:28:03 -0700529/* Part number, identifier of asic design */
530#define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id"
531/* Revision of asic design */
532#define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev"
533
534/* Overall FW version */
535#define DEVLINK_INFO_VERSION_GENERIC_FW "fw"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800536/* Control processor FW version */
537#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt"
Vasundhara Volam2d9eade2020-03-27 15:04:51 +0530538/* FW interface specification version */
539#define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800540/* Data path microcode controlling high-speed packet processing */
541#define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app"
542/* UNDI software version */
543#define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi"
544/* NCSI support/handler version */
545#define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi"
Jacob Keller468672b2020-01-09 14:46:09 -0800546/* FW parameter set id */
547#define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid"
Vasundhara Volam41c0d912020-01-27 04:56:25 -0500548/* RoCE FW version */
549#define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce"
Jacob Kellerc90977a2020-03-11 18:58:16 -0700550/* Firmware bundle identifier */
551#define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id"
Jakub Kicinski785bd552019-01-31 10:50:42 -0800552
Jacob Kellerbc75c052020-09-25 13:46:06 -0700553/**
554 * struct devlink_flash_update_params - Flash Update parameters
555 * @file_name: the name of the flash firmware file to update from
556 * @component: the flash component to update
557 *
558 * With the exception of file_name, drivers must opt-in to parameters by
559 * setting the appropriate bit in the supported_flash_update_params field in
560 * their devlink_ops structure.
561 */
562struct devlink_flash_update_params {
563 const char *file_name;
564 const char *component;
565};
566
Jacob Keller22ec3d22020-09-25 13:46:05 -0700567#define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0)
568
Alex Veskerb16ebe92018-07-12 15:13:08 +0300569struct devlink_region;
Jakub Kicinskif9cf2282019-01-31 10:50:40 -0800570struct devlink_info_req;
Alex Veskerb16ebe92018-07-12 15:13:08 +0300571
Jacob Kellere8937682020-03-26 11:37:08 -0700572/**
573 * struct devlink_region_ops - Region operations
574 * @name: region name
Jacob Kellera0a09f62020-03-26 11:37:09 -0700575 * @destructor: callback used to free snapshot memory when deleting
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700576 * @snapshot: callback to request an immediate snapshot. On success,
577 * the data variable must be updated to point to the snapshot data.
578 * The function will be called while the devlink instance lock is
579 * held.
Andrew Lunne14e05e2020-09-18 21:11:01 +0200580 * @priv: Pointer to driver private data for the region operation
Jacob Kellere8937682020-03-26 11:37:08 -0700581 */
582struct devlink_region_ops {
583 const char *name;
Jacob Kellera0a09f62020-03-26 11:37:09 -0700584 void (*destructor)(const void *data);
Andrew Lunnd4602a92020-09-18 21:11:02 +0200585 int (*snapshot)(struct devlink *devlink,
586 const struct devlink_region_ops *ops,
587 struct netlink_ext_ack *extack,
Jacob Kellerb9a17abf2020-03-26 11:37:16 -0700588 u8 **data);
Andrew Lunne14e05e2020-09-18 21:11:01 +0200589 void *priv;
Jacob Kellere8937682020-03-26 11:37:08 -0700590};
591
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200592struct devlink_fmsg;
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200593struct devlink_health_reporter;
594
Eran Ben Elisha3167b272019-03-03 10:57:30 +0200595enum devlink_health_reporter_state {
596 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY,
597 DEVLINK_HEALTH_REPORTER_STATE_ERROR,
598};
599
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200600/**
601 * struct devlink_health_reporter_ops - Reporter operations
602 * @name: reporter name
603 * @recover: callback to recover from reported error
604 * if priv_ctx is NULL, run a full recover
605 * @dump: callback to dump an object
606 * if priv_ctx is NULL, run a full dump
607 * @diagnose: callback to diagnose the current status
Jiri Pirkoe2ce94d2020-09-15 11:40:57 +0300608 * @test: callback to trigger a test event
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200609 */
610
611struct devlink_health_reporter_ops {
612 char *name;
613 int (*recover)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200614 void *priv_ctx, struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200615 int (*dump)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200616 struct devlink_fmsg *fmsg, void *priv_ctx,
617 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200618 int (*diagnose)(struct devlink_health_reporter *reporter,
Jiri Pirkoe7a98102019-10-10 15:18:49 +0200619 struct devlink_fmsg *fmsg,
620 struct netlink_ext_ack *extack);
Jiri Pirkoe2ce94d2020-09-15 11:40:57 +0300621 int (*test)(struct devlink_health_reporter *reporter,
622 struct netlink_ext_ack *extack);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +0200623};
Eran Ben Elisha1db64e82019-02-07 11:36:32 +0200624
Ido Schimmel0f420b62019-08-17 16:28:17 +0300625/**
Ido Schimmel1e8c6612020-03-30 22:38:18 +0300626 * struct devlink_trap_policer - Immutable packet trap policer attributes.
627 * @id: Policer identifier.
628 * @init_rate: Initial rate in packets / sec.
629 * @init_burst: Initial burst size in packets.
630 * @max_rate: Maximum rate.
631 * @min_rate: Minimum rate.
632 * @max_burst: Maximum burst size.
633 * @min_burst: Minimum burst size.
634 *
635 * Describes immutable attributes of packet trap policers that drivers register
636 * with devlink.
637 */
638struct devlink_trap_policer {
639 u32 id;
640 u64 init_rate;
641 u64 init_burst;
642 u64 max_rate;
643 u64 min_rate;
644 u64 max_burst;
645 u64 min_burst;
646};
647
648/**
Ido Schimmel0f420b62019-08-17 16:28:17 +0300649 * struct devlink_trap_group - Immutable packet trap group attributes.
650 * @name: Trap group name.
651 * @id: Trap group identifier.
652 * @generic: Whether the trap group is generic or not.
Ido Schimmelf9f54392020-03-30 22:38:21 +0300653 * @init_policer_id: Initial policer identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300654 *
655 * Describes immutable attributes of packet trap groups that drivers register
656 * with devlink.
657 */
658struct devlink_trap_group {
659 const char *name;
660 u16 id;
661 bool generic;
Ido Schimmelf9f54392020-03-30 22:38:21 +0300662 u32 init_policer_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300663};
664
665#define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0)
Jiri Pirko85b05892020-02-25 11:45:19 +0100666#define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1)
Ido Schimmel0f420b62019-08-17 16:28:17 +0300667
668/**
669 * struct devlink_trap - Immutable packet trap attributes.
670 * @type: Trap type.
671 * @init_action: Initial trap action.
672 * @generic: Whether the trap is generic or not.
673 * @id: Trap identifier.
674 * @name: Trap name.
Ido Schimmel107f1672020-03-22 20:48:30 +0200675 * @init_group_id: Initial group identifier.
Ido Schimmel0f420b62019-08-17 16:28:17 +0300676 * @metadata_cap: Metadata types that can be provided by the trap.
677 *
678 * Describes immutable attributes of packet traps that drivers register with
679 * devlink.
680 */
681struct devlink_trap {
682 enum devlink_trap_type type;
683 enum devlink_trap_action init_action;
684 bool generic;
685 u16 id;
686 const char *name;
Ido Schimmel107f1672020-03-22 20:48:30 +0200687 u16 init_group_id;
Ido Schimmel0f420b62019-08-17 16:28:17 +0300688 u32 metadata_cap;
689};
690
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300691/* All traps must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800692 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300693 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300694enum devlink_trap_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300695 DEVLINK_TRAP_GENERIC_ID_SMAC_MC,
696 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH,
697 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER,
698 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER,
699 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST,
700 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER,
701 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE,
702 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR,
703 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP,
Amit Cohen6896cc42019-11-07 18:42:09 +0200704 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET,
705 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC,
706 DEVLINK_TRAP_GENERIC_ID_DIP_LB,
707 DEVLINK_TRAP_GENERIC_ID_SIP_MC,
708 DEVLINK_TRAP_GENERIC_ID_SIP_LB,
709 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR,
710 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC,
711 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE,
712 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE,
Amit Cohen3b063ae2019-11-07 18:42:14 +0200713 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR,
714 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH,
715 DEVLINK_TRAP_GENERIC_ID_RPF,
716 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE,
717 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS,
718 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS,
Amit Cohen95f0ead2020-01-19 15:00:48 +0200719 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE,
Amit Cohen13c056e2020-01-19 15:00:54 +0200720 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR,
Amit Cohenc3cae492020-01-19 15:00:58 +0200721 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100722 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP,
723 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP,
Ido Schimmel515eac62020-05-29 21:36:41 +0300724 DEVLINK_TRAP_GENERIC_ID_STP,
725 DEVLINK_TRAP_GENERIC_ID_LACP,
726 DEVLINK_TRAP_GENERIC_ID_LLDP,
727 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY,
728 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT,
729 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT,
730 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT,
731 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE,
732 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY,
733 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT,
734 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT,
735 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300736 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP,
737 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP,
738 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST,
739 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE,
740 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY,
741 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT,
742 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT,
743 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD,
744 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD,
745 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF,
746 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF,
747 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP,
748 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP,
749 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP,
750 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP,
751 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM,
752 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM,
753 DEVLINK_TRAP_GENERIC_ID_UC_LB,
754 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE,
755 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE,
756 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE,
757 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES,
758 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS,
759 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT,
760 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT,
761 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT,
762 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT,
763 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT,
764 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT,
765 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel5eb18a22020-05-29 21:36:43 +0300766 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE,
767 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP,
Amit Cohen08e335f2020-08-03 19:11:33 +0300768 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP,
Ido Schimmel391203a2019-08-17 16:28:18 +0300769
Ido Schimmel0f420b62019-08-17 16:28:17 +0300770 /* Add new generic trap IDs above */
771 __DEVLINK_TRAP_GENERIC_ID_MAX,
772 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1,
773};
774
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300775/* All trap groups must be documented in
Jacob Kellerf4bdd712020-01-09 14:46:10 -0800776 * Documentation/networking/devlink/devlink-trap.rst
Ido Schimmelf3047ca2019-08-17 16:28:19 +0300777 */
Ido Schimmel0f420b62019-08-17 16:28:17 +0300778enum devlink_trap_group_generic_id {
Ido Schimmel391203a2019-08-17 16:28:18 +0300779 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS,
780 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS,
Ido Schimmel678eb192020-05-29 21:36:36 +0300781 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS,
Ido Schimmel391203a2019-08-17 16:28:18 +0300782 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS,
Amit Cohen13c056e2020-01-19 15:00:54 +0200783 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS,
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100784 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS,
Ido Schimmel515eac62020-05-29 21:36:41 +0300785 DEVLINK_TRAP_GROUP_GENERIC_ID_STP,
786 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP,
787 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP,
788 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300789 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP,
790 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY,
791 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD,
792 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF,
793 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP,
794 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP,
795 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM,
796 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB,
797 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY,
Ido Schimmelec4f5b32020-07-29 12:26:44 +0300798 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY,
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300799 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6,
800 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT,
801 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL,
Ido Schimmel5eb18a22020-05-29 21:36:43 +0300802 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE,
803 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP,
Ido Schimmel391203a2019-08-17 16:28:18 +0300804
Ido Schimmel0f420b62019-08-17 16:28:17 +0300805 /* Add new generic trap group IDs above */
806 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX,
807 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX =
808 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1,
809};
810
Ido Schimmel391203a2019-08-17 16:28:18 +0300811#define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \
812 "source_mac_is_multicast"
813#define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \
814 "vlan_tag_mismatch"
815#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \
816 "ingress_vlan_filter"
817#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \
818 "ingress_spanning_tree_filter"
819#define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \
820 "port_list_is_empty"
821#define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \
822 "port_loopback_filter"
823#define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \
824 "blackhole_route"
825#define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \
826 "ttl_value_is_too_small"
827#define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \
828 "tail_drop"
Amit Cohen6896cc42019-11-07 18:42:09 +0200829#define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \
830 "non_ip"
831#define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \
832 "uc_dip_over_mc_dmac"
833#define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \
834 "dip_is_loopback_address"
835#define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \
836 "sip_is_mc"
837#define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \
838 "sip_is_loopback_address"
839#define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \
840 "ip_header_corrupted"
841#define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \
842 "ipv4_sip_is_limited_bc"
843#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \
844 "ipv6_mc_dip_reserved_scope"
845#define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \
846 "ipv6_mc_dip_interface_local_scope"
Amit Cohen3b063ae2019-11-07 18:42:14 +0200847#define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \
848 "mtu_value_is_too_small"
849#define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \
850 "unresolved_neigh"
851#define DEVLINK_TRAP_GENERIC_NAME_RPF \
852 "mc_reverse_path_forwarding"
853#define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \
854 "reject_route"
855#define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \
856 "ipv4_lpm_miss"
857#define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \
858 "ipv6_lpm_miss"
Amit Cohen95f0ead2020-01-19 15:00:48 +0200859#define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \
860 "non_routable_packet"
Amit Cohen13c056e2020-01-19 15:00:54 +0200861#define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \
862 "decap_error"
Amit Cohenc3cae492020-01-19 15:00:58 +0200863#define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \
864 "overlay_smac_is_mc"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100865#define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \
866 "ingress_flow_action_drop"
867#define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \
868 "egress_flow_action_drop"
Ido Schimmel515eac62020-05-29 21:36:41 +0300869#define DEVLINK_TRAP_GENERIC_NAME_STP \
870 "stp"
871#define DEVLINK_TRAP_GENERIC_NAME_LACP \
872 "lacp"
873#define DEVLINK_TRAP_GENERIC_NAME_LLDP \
874 "lldp"
875#define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \
876 "igmp_query"
877#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \
878 "igmp_v1_report"
879#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \
880 "igmp_v2_report"
881#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \
882 "igmp_v3_report"
883#define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \
884 "igmp_v2_leave"
885#define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \
886 "mld_query"
887#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \
888 "mld_v1_report"
889#define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \
890 "mld_v2_report"
891#define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \
892 "mld_v1_done"
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300893#define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \
894 "ipv4_dhcp"
895#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \
896 "ipv6_dhcp"
897#define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \
898 "arp_request"
899#define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \
900 "arp_response"
901#define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \
902 "arp_overlay"
903#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \
904 "ipv6_neigh_solicit"
905#define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \
906 "ipv6_neigh_advert"
907#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \
908 "ipv4_bfd"
909#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \
910 "ipv6_bfd"
911#define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \
912 "ipv4_ospf"
913#define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \
914 "ipv6_ospf"
915#define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \
916 "ipv4_bgp"
917#define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \
918 "ipv6_bgp"
919#define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \
920 "ipv4_vrrp"
921#define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \
922 "ipv6_vrrp"
923#define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \
924 "ipv4_pim"
925#define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \
926 "ipv6_pim"
927#define DEVLINK_TRAP_GENERIC_NAME_UC_LB \
928 "uc_loopback"
929#define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \
930 "local_route"
931#define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \
932 "external_route"
933#define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \
934 "ipv6_uc_dip_link_local_scope"
935#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \
936 "ipv6_dip_all_nodes"
937#define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \
938 "ipv6_dip_all_routers"
939#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \
940 "ipv6_router_solicit"
941#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \
942 "ipv6_router_advert"
943#define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \
944 "ipv6_redirect"
945#define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \
946 "ipv4_router_alert"
947#define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \
948 "ipv6_router_alert"
949#define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \
950 "ptp_event"
951#define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \
952 "ptp_general"
Ido Schimmel5eb18a22020-05-29 21:36:43 +0300953#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \
954 "flow_action_sample"
955#define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \
956 "flow_action_trap"
Amit Cohen08e335f2020-08-03 19:11:33 +0300957#define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \
958 "early_drop"
Ido Schimmel391203a2019-08-17 16:28:18 +0300959
960#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \
961 "l2_drops"
962#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \
963 "l3_drops"
Ido Schimmel678eb192020-05-29 21:36:36 +0300964#define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \
965 "l3_exceptions"
Ido Schimmel391203a2019-08-17 16:28:18 +0300966#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \
967 "buffer_drops"
Amit Cohen13c056e2020-01-19 15:00:54 +0200968#define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \
969 "tunnel_drops"
Jiri Pirkoecd942a2020-02-24 08:35:47 +0100970#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \
971 "acl_drops"
Ido Schimmel515eac62020-05-29 21:36:41 +0300972#define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \
973 "stp"
974#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \
975 "lacp"
976#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \
977 "lldp"
978#define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \
979 "mc_snooping"
Ido Schimmeld77cfd12020-05-29 21:36:42 +0300980#define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \
981 "dhcp"
982#define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \
983 "neigh_discovery"
984#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \
985 "bfd"
986#define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \
987 "ospf"
988#define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \
989 "bgp"
990#define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \
991 "vrrp"
992#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \
993 "pim"
994#define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \
995 "uc_loopback"
996#define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \
997 "local_delivery"
Ido Schimmelec4f5b32020-07-29 12:26:44 +0300998#define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \
999 "external_delivery"
Ido Schimmeld77cfd12020-05-29 21:36:42 +03001000#define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \
1001 "ipv6"
1002#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \
1003 "ptp_event"
1004#define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \
1005 "ptp_general"
Ido Schimmel5eb18a22020-05-29 21:36:43 +03001006#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \
1007 "acl_sample"
1008#define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \
1009 "acl_trap"
Ido Schimmel391203a2019-08-17 16:28:18 +03001010
Ido Schimmel107f1672020-03-22 20:48:30 +02001011#define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \
1012 _metadata_cap) \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001013 { \
1014 .type = DEVLINK_TRAP_TYPE_##_type, \
1015 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1016 .generic = true, \
1017 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \
1018 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \
Ido Schimmel107f1672020-03-22 20:48:30 +02001019 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001020 .metadata_cap = _metadata_cap, \
1021 }
1022
Ido Schimmel107f1672020-03-22 20:48:30 +02001023#define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001024 _metadata_cap) \
1025 { \
1026 .type = DEVLINK_TRAP_TYPE_##_type, \
1027 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \
1028 .generic = false, \
1029 .id = _id, \
1030 .name = _name, \
Ido Schimmel107f1672020-03-22 20:48:30 +02001031 .init_group_id = _group_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001032 .metadata_cap = _metadata_cap, \
1033 }
1034
Ido Schimmelf9f54392020-03-30 22:38:21 +03001035#define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001036 { \
1037 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \
1038 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \
1039 .generic = true, \
Ido Schimmelf9f54392020-03-30 22:38:21 +03001040 .init_policer_id = _policer_id, \
Ido Schimmel0f420b62019-08-17 16:28:17 +03001041 }
1042
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001043#define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \
1044 _max_burst, _min_burst) \
1045 { \
1046 .id = _id, \
1047 .init_rate = _rate, \
1048 .init_burst = _burst, \
1049 .max_rate = _max_rate, \
1050 .min_rate = _min_rate, \
1051 .max_burst = _max_burst, \
1052 .min_burst = _min_burst, \
1053 }
1054
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001055struct devlink_ops {
Jacob Keller22ec3d22020-09-25 13:46:05 -07001056 /**
1057 * @supported_flash_update_params:
1058 * mask of parameters supported by the driver's .flash_update
1059 * implemementation.
1060 */
1061 u32 supported_flash_update_params;
Jiri Pirko070c63f2019-10-03 11:49:39 +02001062 int (*reload_down)(struct devlink *devlink, bool netns_change,
Jiri Pirko97691062019-09-12 10:49:45 +02001063 struct netlink_ext_ack *extack);
1064 int (*reload_up)(struct devlink *devlink,
1065 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001066 int (*port_type_set)(struct devlink_port *devlink_port,
1067 enum devlink_port_type port_type);
1068 int (*port_split)(struct devlink *devlink, unsigned int port_index,
David Ahernac0fc8a2018-06-05 08:14:09 -07001069 unsigned int count, struct netlink_ext_ack *extack);
1070 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
1071 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001072 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
1073 u16 pool_index,
1074 struct devlink_sb_pool_info *pool_info);
1075 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
1076 u16 pool_index, u32 size,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001077 enum devlink_sb_threshold_type threshold_type,
1078 struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001079 int (*sb_port_pool_get)(struct devlink_port *devlink_port,
1080 unsigned int sb_index, u16 pool_index,
1081 u32 *p_threshold);
1082 int (*sb_port_pool_set)(struct devlink_port *devlink_port,
1083 unsigned int sb_index, u16 pool_index,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001084 u32 threshold, struct netlink_ext_ack *extack);
Jiri Pirkobf797472016-04-14 18:19:13 +02001085 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
1086 unsigned int sb_index,
1087 u16 tc_index,
1088 enum devlink_sb_pool_type pool_type,
1089 u16 *p_pool_index, u32 *p_threshold);
1090 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
1091 unsigned int sb_index,
1092 u16 tc_index,
1093 enum devlink_sb_pool_type pool_type,
Ido Schimmelf2ad1a52019-04-22 12:08:39 +00001094 u16 pool_index, u32 threshold,
1095 struct netlink_ext_ack *extack);
Jiri Pirkodf38daf2016-04-14 18:19:14 +02001096 int (*sb_occ_snapshot)(struct devlink *devlink,
1097 unsigned int sb_index);
1098 int (*sb_occ_max_clear)(struct devlink *devlink,
1099 unsigned int sb_index);
1100 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
1101 unsigned int sb_index, u16 pool_index,
1102 u32 *p_cur, u32 *p_max);
1103 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
1104 unsigned int sb_index,
1105 u16 tc_index,
1106 enum devlink_sb_pool_type pool_type,
1107 u32 *p_cur, u32 *p_max);
Or Gerlitz08f4b592016-07-01 14:51:01 +03001108
1109 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001110 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
1111 struct netlink_ext_ack *extack);
Roi Dayan59bfde02016-11-22 23:09:57 +02001112 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
Eli Britsteindb7ff192018-08-15 16:02:18 +03001113 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
1114 struct netlink_ext_ack *extack);
Leon Romanovsky98fdbea2019-06-12 15:20:11 +03001115 int (*eswitch_encap_mode_get)(struct devlink *devlink,
1116 enum devlink_eswitch_encap_mode *p_encap_mode);
1117 int (*eswitch_encap_mode_set)(struct devlink *devlink,
1118 enum devlink_eswitch_encap_mode encap_mode,
Eli Britsteindb7ff192018-08-15 16:02:18 +03001119 struct netlink_ext_ack *extack);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001120 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
1121 struct netlink_ext_ack *extack);
Jacob Keller22ec3d22020-09-25 13:46:05 -07001122 /**
1123 * @flash_update: Device flash update function
1124 *
1125 * Used to perform a flash update for the device. The set of
1126 * parameters supported by the driver should be set in
1127 * supported_flash_update_params.
1128 */
Jacob Kellerbc75c052020-09-25 13:46:06 -07001129 int (*flash_update)(struct devlink *devlink,
1130 struct devlink_flash_update_params *params,
Jakub Kicinski76726cc2019-02-14 13:40:44 -08001131 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001132 /**
1133 * @trap_init: Trap initialization function.
1134 *
1135 * Should be used by device drivers to initialize the trap in the
1136 * underlying device. Drivers should also store the provided trap
1137 * context, so that they could efficiently pass it to
1138 * devlink_trap_report() when the trap is triggered.
1139 */
1140 int (*trap_init)(struct devlink *devlink,
1141 const struct devlink_trap *trap, void *trap_ctx);
1142 /**
1143 * @trap_fini: Trap de-initialization function.
1144 *
1145 * Should be used by device drivers to de-initialize the trap in the
1146 * underlying device.
1147 */
1148 void (*trap_fini)(struct devlink *devlink,
1149 const struct devlink_trap *trap, void *trap_ctx);
1150 /**
1151 * @trap_action_set: Trap action set function.
1152 */
1153 int (*trap_action_set)(struct devlink *devlink,
1154 const struct devlink_trap *trap,
Ido Schimmelc88e11e2020-08-03 19:11:34 +03001155 enum devlink_trap_action action,
1156 struct netlink_ext_ack *extack);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001157 /**
1158 * @trap_group_init: Trap group initialization function.
1159 *
1160 * Should be used by device drivers to initialize the trap group in the
1161 * underlying device.
1162 */
1163 int (*trap_group_init)(struct devlink *devlink,
1164 const struct devlink_trap_group *group);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001165 /**
Ido Schimmelc0648752020-03-30 22:38:22 +03001166 * @trap_group_set: Trap group parameters set function.
1167 *
1168 * Note: @policer can be NULL when a policer is being unbound from
1169 * @group.
1170 */
1171 int (*trap_group_set)(struct devlink *devlink,
1172 const struct devlink_trap_group *group,
Ido Schimmelc88e11e2020-08-03 19:11:34 +03001173 const struct devlink_trap_policer *policer,
1174 struct netlink_ext_ack *extack);
Ido Schimmelc0648752020-03-30 22:38:22 +03001175 /**
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001176 * @trap_policer_init: Trap policer initialization function.
1177 *
1178 * Should be used by device drivers to initialize the trap policer in
1179 * the underlying device.
1180 */
1181 int (*trap_policer_init)(struct devlink *devlink,
1182 const struct devlink_trap_policer *policer);
1183 /**
1184 * @trap_policer_fini: Trap policer de-initialization function.
1185 *
1186 * Should be used by device drivers to de-initialize the trap policer
1187 * in the underlying device.
1188 */
1189 void (*trap_policer_fini)(struct devlink *devlink,
1190 const struct devlink_trap_policer *policer);
1191 /**
1192 * @trap_policer_set: Trap policer parameters set function.
1193 */
1194 int (*trap_policer_set)(struct devlink *devlink,
1195 const struct devlink_trap_policer *policer,
1196 u64 rate, u64 burst,
1197 struct netlink_ext_ack *extack);
1198 /**
1199 * @trap_policer_counter_get: Trap policer counter get function.
1200 *
1201 * Should be used by device drivers to report number of packets dropped
1202 * by the policer.
1203 */
1204 int (*trap_policer_counter_get)(struct devlink *devlink,
1205 const struct devlink_trap_policer *policer,
1206 u64 *p_drops);
Parav Pandit2a916ec2020-06-19 03:32:48 +00001207 /**
1208 * @port_function_hw_addr_get: Port function's hardware address get function.
1209 *
1210 * Should be used by device drivers to report the hardware address of a function managed
1211 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1212 * function handling for a particular port.
1213 *
1214 * Note: @extack can be NULL when port notifier queries the port function.
1215 */
1216 int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port,
1217 u8 *hw_addr, int *hw_addr_len,
1218 struct netlink_ext_ack *extack);
Parav Pandita1e8ae92020-06-19 03:32:49 +00001219 /**
1220 * @port_function_hw_addr_set: Port function's hardware address set function.
1221 *
1222 * Should be used by device drivers to set the hardware address of a function managed
1223 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port
1224 * function handling for a particular port.
1225 */
1226 int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port,
1227 const u8 *hw_addr, int hw_addr_len,
1228 struct netlink_ext_ack *extack);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001229};
1230
1231static inline void *devlink_priv(struct devlink *devlink)
1232{
1233 BUG_ON(!devlink);
1234 return &devlink->priv;
1235}
1236
1237static inline struct devlink *priv_to_devlink(void *priv)
1238{
1239 BUG_ON(!priv);
1240 return container_of(priv, struct devlink, priv);
1241}
1242
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001243static inline struct devlink_port *
1244netdev_to_devlink_port(struct net_device *dev)
1245{
1246 if (dev->netdev_ops->ndo_get_devlink_port)
1247 return dev->netdev_ops->ndo_get_devlink_port(dev);
1248 return NULL;
1249}
1250
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001251static inline struct devlink *netdev_to_devlink(struct net_device *dev)
1252{
Jiri Pirko5dc37bb2019-03-28 13:56:36 +01001253 struct devlink_port *devlink_port = netdev_to_devlink_port(dev);
1254
1255 if (devlink_port)
1256 return devlink_port->devlink;
Jakub Kicinskib473b0d2019-02-25 19:34:03 -08001257 return NULL;
1258}
1259
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001260struct ib_device;
1261
Jiri Pirko471f8942019-10-03 11:49:31 +02001262struct net *devlink_net(const struct devlink *devlink);
Jiri Pirko8273fd82019-10-05 08:10:31 +02001263void devlink_net_set(struct devlink *devlink, struct net *net);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001264struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
1265int devlink_register(struct devlink *devlink, struct device *dev);
1266void devlink_unregister(struct devlink *devlink);
Jiri Pirkoa0c76342019-11-08 21:42:43 +01001267void devlink_reload_enable(struct devlink *devlink);
1268void devlink_reload_disable(struct devlink *devlink);
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001269void devlink_free(struct devlink *devlink);
1270int devlink_port_register(struct devlink *devlink,
1271 struct devlink_port *devlink_port,
1272 unsigned int port_index);
1273void devlink_port_unregister(struct devlink_port *devlink_port);
1274void devlink_port_type_eth_set(struct devlink_port *devlink_port,
1275 struct net_device *netdev);
1276void devlink_port_type_ib_set(struct devlink_port *devlink_port,
1277 struct ib_device *ibdev);
1278void devlink_port_type_clear(struct devlink_port *devlink_port);
Jiri Pirkob9ffcba2018-05-18 09:29:00 +02001279void devlink_port_attrs_set(struct devlink_port *devlink_port,
Danielle Ratson71ad8d52020-07-09 16:18:16 +03001280 struct devlink_port_attrs *devlink_port_attrs);
Parav Pandit3a2d9582020-09-09 07:50:37 +03001281void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller,
1282 u16 pf, bool external);
1283void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
Parav Pandit05b595e2020-09-09 07:50:36 +03001284 u16 pf, u16 vf, bool external);
Jiri Pirkobf797472016-04-14 18:19:13 +02001285int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
1286 u32 size, u16 ingress_pools_count,
1287 u16 egress_pools_count, u16 ingress_tc_count,
1288 u16 egress_tc_count);
1289void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001290int devlink_dpipe_table_register(struct devlink *devlink,
1291 const char *table_name,
1292 struct devlink_dpipe_table_ops *table_ops,
Arkadi Sharshevskyffd3cdc2017-08-24 08:40:02 +02001293 void *priv, bool counter_control_extern);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001294void devlink_dpipe_table_unregister(struct devlink *devlink,
1295 const char *table_name);
1296int devlink_dpipe_headers_register(struct devlink *devlink,
1297 struct devlink_dpipe_headers *dpipe_headers);
1298void devlink_dpipe_headers_unregister(struct devlink *devlink);
1299bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
1300 const char *table_name);
1301int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
1302int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
1303 struct devlink_dpipe_entry *entry);
1304int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
Arkadi Sharshevsky35807322017-08-24 08:40:03 +02001305void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
Arkadi Sharshevsky1555d202017-03-28 17:24:10 +02001306int devlink_dpipe_action_put(struct sk_buff *skb,
1307 struct devlink_dpipe_action *action);
1308int devlink_dpipe_match_put(struct sk_buff *skb,
1309 struct devlink_dpipe_match *match);
Arkadi Sharshevsky11770092017-08-24 08:39:59 +02001310extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
Arkadi Sharshevsky3fb886e2017-08-24 08:40:00 +02001311extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
Arkadi Sharshevsky1797f5b2017-08-31 17:59:12 +02001312extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001313
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001314int devlink_resource_register(struct devlink *devlink,
1315 const char *resource_name,
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001316 u64 resource_size,
1317 u64 resource_id,
1318 u64 parent_resource_id,
Jiri Pirkofc56be42018-04-05 22:13:21 +02001319 const struct devlink_resource_size_params *size_params);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001320void devlink_resources_unregister(struct devlink *devlink,
1321 struct devlink_resource *resource);
1322int devlink_resource_size_get(struct devlink *devlink,
1323 u64 resource_id,
1324 u64 *p_resource_size);
Arkadi Sharshevsky56dc7cd2018-01-15 08:59:05 +01001325int devlink_dpipe_table_resource_set(struct devlink *devlink,
1326 const char *table_name, u64 resource_id,
1327 u64 resource_units);
Jiri Pirkofc56be42018-04-05 22:13:21 +02001328void devlink_resource_occ_get_register(struct devlink *devlink,
1329 u64 resource_id,
1330 devlink_resource_occ_get_t *occ_get,
1331 void *occ_get_priv);
1332void devlink_resource_occ_get_unregister(struct devlink *devlink,
1333 u64 resource_id);
Moshe Shemesheabaef12018-07-04 14:30:28 +03001334int devlink_params_register(struct devlink *devlink,
1335 const struct devlink_param *params,
1336 size_t params_count);
1337void devlink_params_unregister(struct devlink *devlink,
1338 const struct devlink_param *params,
1339 size_t params_count);
Jiri Pirko7c62cfb2019-02-07 11:22:45 +00001340void devlink_params_publish(struct devlink *devlink);
1341void devlink_params_unpublish(struct devlink *devlink);
Vasundhara Volam39e61602019-01-28 18:00:20 +05301342int devlink_port_params_register(struct devlink_port *devlink_port,
1343 const struct devlink_param *params,
1344 size_t params_count);
1345void devlink_port_params_unregister(struct devlink_port *devlink_port,
1346 const struct devlink_param *params,
1347 size_t params_count);
Moshe Shemeshec01aeb2018-07-04 14:30:31 +03001348int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
1349 union devlink_param_value *init_val);
1350int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
1351 union devlink_param_value init_val);
Vasundhara Volamffd19b92019-01-28 18:00:23 +05301352int
1353devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
1354 u32 param_id,
1355 union devlink_param_value *init_val);
Vasundhara Volam5473a7b2019-01-28 18:00:24 +05301356int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
1357 u32 param_id,
1358 union devlink_param_value init_val);
Moshe Shemeshea601e12018-07-04 14:30:32 +03001359void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
Vasundhara Volamc1e5786d2019-01-28 18:00:25 +05301360void devlink_port_param_value_changed(struct devlink_port *devlink_port,
1361 u32 param_id);
Moshe Shemeshbde74ad12018-10-10 16:09:27 +03001362void devlink_param_value_str_fill(union devlink_param_value *dst_val,
1363 const char *src);
Jacob Kellere8937682020-03-26 11:37:08 -07001364struct devlink_region *
1365devlink_region_create(struct devlink *devlink,
1366 const struct devlink_region_ops *ops,
1367 u32 region_max_snapshots, u64 region_size);
Alex Veskerb16ebe92018-07-12 15:13:08 +03001368void devlink_region_destroy(struct devlink_region *region);
Jacob Keller7ef19d32020-03-26 11:37:14 -07001369int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id);
Jacob Keller12102432020-03-26 11:37:15 -07001370void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id);
Jiri Pirko3a5e5232019-08-09 15:27:15 +02001371int devlink_region_snapshot_create(struct devlink_region *region,
Jacob Kellera0a09f62020-03-26 11:37:09 -07001372 u8 *data, u32 snapshot_id);
Jakub Kicinskif9cf2282019-01-31 10:50:40 -08001373int devlink_info_serial_number_put(struct devlink_info_req *req,
1374 const char *sn);
1375int devlink_info_driver_name_put(struct devlink_info_req *req,
1376 const char *name);
Vasundhara Volamb5872cd2020-06-20 22:01:56 +05301377int devlink_info_board_serial_number_put(struct devlink_info_req *req,
1378 const char *bsn);
Jakub Kicinskifc6fae72019-01-31 10:50:41 -08001379int devlink_info_version_fixed_put(struct devlink_info_req *req,
1380 const char *version_name,
1381 const char *version_value);
1382int devlink_info_version_stored_put(struct devlink_info_req *req,
1383 const char *version_name,
1384 const char *version_value);
1385int devlink_info_version_running_put(struct devlink_info_req *req,
1386 const char *version_name,
1387 const char *version_value);
Arkadi Sharshevskyd9f9b9a2018-01-15 08:59:03 +01001388
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001389int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg);
1390int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg);
1391
1392int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name);
1393int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg);
1394
1395int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg,
1396 const char *name);
1397int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg);
Aya Levin573ed902020-02-11 14:32:42 -08001398int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg,
1399 const char *name);
1400int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001401
1402int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value);
1403int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value);
1404int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value);
1405int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value);
1406int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value);
Aya Levin573ed902020-02-11 14:32:42 -08001407int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
1408 u16 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001409
1410int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name,
1411 bool value);
1412int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name,
1413 u8 value);
1414int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name,
1415 u32 value);
1416int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name,
1417 u64 value);
1418int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name,
1419 const char *value);
1420int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
Aya Levine2cde862019-11-12 14:07:49 +02001421 const void *value, u32 value_len);
Eran Ben Elisha1db64e82019-02-07 11:36:32 +02001422
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001423struct devlink_health_reporter *
1424devlink_health_reporter_create(struct devlink *devlink,
1425 const struct devlink_health_reporter_ops *ops,
Eran Ben Elishaba7d16c2020-03-29 14:05:54 +03001426 u64 graceful_period, void *priv);
Vladyslav Tarasiuk15c724b2020-07-10 15:25:11 +03001427
1428struct devlink_health_reporter *
1429devlink_port_health_reporter_create(struct devlink_port *port,
1430 const struct devlink_health_reporter_ops *ops,
1431 u64 graceful_period, void *priv);
1432
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001433void
1434devlink_health_reporter_destroy(struct devlink_health_reporter *reporter);
1435
Vladyslav Tarasiuk15c724b2020-07-10 15:25:11 +03001436void
1437devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter);
1438
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001439void *
1440devlink_health_reporter_priv(struct devlink_health_reporter *reporter);
Eran Ben Elishac8e1da02019-02-07 11:36:34 +02001441int devlink_health_report(struct devlink_health_reporter *reporter,
1442 const char *msg, void *priv_ctx);
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001443void
1444devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
1445 enum devlink_health_reporter_state state);
Vikas Gupta6181e5c2020-01-02 21:18:09 +05301446void
1447devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
Eran Ben Elishaa0bdcc52019-02-07 11:36:33 +02001448
Jiri Pirko2670ac22019-09-12 10:49:46 +02001449bool devlink_is_reload_failed(const struct devlink *devlink);
1450
Jiri Pirko191ed202019-06-04 15:40:40 +02001451void devlink_flash_update_begin_notify(struct devlink *devlink);
1452void devlink_flash_update_end_notify(struct devlink *devlink);
1453void devlink_flash_update_status_notify(struct devlink *devlink,
1454 const char *status_msg,
1455 const char *component,
1456 unsigned long done,
1457 unsigned long total);
Shannon Nelsonf92970c2020-09-17 18:13:23 -07001458void devlink_flash_update_timeout_notify(struct devlink *devlink,
1459 const char *status_msg,
1460 const char *component,
1461 unsigned long timeout);
Jiri Pirko191ed202019-06-04 15:40:40 +02001462
Ido Schimmel0f420b62019-08-17 16:28:17 +03001463int devlink_traps_register(struct devlink *devlink,
1464 const struct devlink_trap *traps,
1465 size_t traps_count, void *priv);
1466void devlink_traps_unregister(struct devlink *devlink,
1467 const struct devlink_trap *traps,
1468 size_t traps_count);
Jiri Pirko5a2e1062020-02-25 11:45:21 +01001469void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb,
1470 void *trap_ctx, struct devlink_port *in_devlink_port,
1471 const struct flow_action_cookie *fa_cookie);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001472void *devlink_trap_ctx_priv(void *trap_ctx);
Ido Schimmel95ad9552020-03-22 20:48:26 +02001473int devlink_trap_groups_register(struct devlink *devlink,
1474 const struct devlink_trap_group *groups,
1475 size_t groups_count);
1476void devlink_trap_groups_unregister(struct devlink *devlink,
1477 const struct devlink_trap_group *groups,
1478 size_t groups_count);
Ido Schimmel1e8c6612020-03-30 22:38:18 +03001479int
1480devlink_trap_policers_register(struct devlink *devlink,
1481 const struct devlink_trap_policer *policers,
1482 size_t policers_count);
1483void
1484devlink_trap_policers_unregister(struct devlink *devlink,
1485 const struct devlink_trap_policer *policers,
1486 size_t policers_count);
Ido Schimmel0f420b62019-08-17 16:28:17 +03001487
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001488#if IS_ENABLED(CONFIG_NET_DEVLINK)
1489
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001490void devlink_compat_running_version(struct net_device *dev,
1491 char *buf, size_t len);
1492int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001493int devlink_compat_phys_port_name_get(struct net_device *dev,
1494 char *name, size_t len);
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001495int devlink_compat_switch_id_get(struct net_device *dev,
1496 struct netdev_phys_item_id *ppid);
Jakub Kicinskif4b6bcc2019-02-25 19:34:02 -08001497
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001498#else
1499
Eran Ben Elisha3167b272019-03-03 10:57:30 +02001500static inline void
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001501devlink_compat_running_version(struct net_device *dev, char *buf, size_t len)
1502{
1503}
Jakub Kicinski4eceba12019-02-14 13:40:45 -08001504
1505static inline int
1506devlink_compat_flash_update(struct net_device *dev, const char *file_name)
1507{
1508 return -EOPNOTSUPP;
1509}
Jiri Pirkof6b19b32019-03-24 11:14:38 +01001510
Jiri Pirkoaf3836d2019-03-28 13:56:37 +01001511static inline int
1512devlink_compat_phys_port_name_get(struct net_device *dev,
1513 char *name, size_t len)
1514{
1515 return -EOPNOTSUPP;
1516}
1517
Jiri Pirko7e1146e2019-04-03 14:24:17 +02001518static inline int
1519devlink_compat_switch_id_get(struct net_device *dev,
1520 struct netdev_phys_item_id *ppid)
1521{
1522 return -EOPNOTSUPP;
1523}
1524
Jakub Kicinskiddb6e992019-01-31 10:50:47 -08001525#endif
1526
Jiri Pirkobfcd3a42016-02-26 17:32:23 +01001527#endif /* _NET_DEVLINK_H_ */