Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 2 | /* |
| 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 Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 6 | */ |
| 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 Pirko | b8f9755 | 2019-03-24 11:14:37 +0100 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
Jiri Pirko | 136bf27 | 2019-05-23 10:43:35 +0200 | [diff] [blame] | 16 | #include <linux/workqueue.h> |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 17 | #include <linux/refcount.h> |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Jiri Pirko | 5a2e106 | 2020-02-25 11:45:21 +0100 | [diff] [blame] | 19 | #include <net/flow_offload.h> |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 20 | #include <uapi/linux/devlink.h> |
Jacob Keller | 1210243 | 2020-03-26 11:37:15 -0700 | [diff] [blame] | 21 | #include <linux/xarray.h> |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 22 | |
| 23 | struct devlink_ops; |
| 24 | |
| 25 | struct devlink { |
| 26 | struct list_head list; |
| 27 | struct list_head port_list; |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 28 | struct list_head sb_list; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 29 | struct list_head dpipe_table_list; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 30 | struct list_head resource_list; |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 31 | struct list_head param_list; |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 32 | struct list_head region_list; |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 33 | struct list_head reporter_list; |
Moshe Shemesh | b587bda | 2019-04-29 12:41:45 +0300 | [diff] [blame] | 34 | struct mutex reporters_lock; /* protects reporter_list */ |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 35 | struct devlink_dpipe_headers *dpipe_headers; |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 36 | struct list_head trap_list; |
| 37 | struct list_head trap_group_list; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 38 | const struct devlink_ops *ops; |
Jacob Keller | 1210243 | 2020-03-26 11:37:15 -0700 | [diff] [blame] | 39 | struct xarray snapshot_ids; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 40 | struct device *dev; |
| 41 | possible_net_t _net; |
Arkadi Sharshevsky | 2406e7e | 2018-01-15 08:59:02 +0100 | [diff] [blame] | 42 | struct mutex lock; |
Jiri Pirko | a0c7634 | 2019-11-08 21:42:43 +0100 | [diff] [blame] | 43 | u8 reload_failed:1, |
| 44 | reload_enabled:1, |
| 45 | registered:1; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 46 | char priv[0] __aligned(NETDEV_ALIGN); |
| 47 | }; |
| 48 | |
Parav Pandit | 378ef01 | 2019-07-08 23:17:35 -0500 | [diff] [blame] | 49 | struct devlink_port_phys_attrs { |
| 50 | u32 port_number; /* Same value as "split group". |
| 51 | * A physical port which is visible to the user |
| 52 | * for a given port flavour. |
| 53 | */ |
| 54 | u32 split_subport_number; |
| 55 | }; |
| 56 | |
Parav Pandit | 98fd2d6 | 2019-07-08 23:17:37 -0500 | [diff] [blame] | 57 | struct devlink_port_pci_pf_attrs { |
| 58 | u16 pf; /* Associated PCI PF for this port. */ |
| 59 | }; |
| 60 | |
Parav Pandit | e41b6bf | 2019-07-08 23:17:38 -0500 | [diff] [blame] | 61 | struct devlink_port_pci_vf_attrs { |
| 62 | u16 pf; /* Associated PCI PF for this port. */ |
| 63 | u16 vf; /* Associated PCI VF for of the PCI PF for this port. */ |
| 64 | }; |
| 65 | |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 66 | struct devlink_port_attrs { |
Jiri Pirko | 407dd70 | 2019-04-03 14:24:15 +0200 | [diff] [blame] | 67 | u8 set:1, |
Jiri Pirko | bec5267 | 2019-04-03 14:24:16 +0200 | [diff] [blame] | 68 | split:1, |
| 69 | switch_port:1; |
Jiri Pirko | 5ec1380 | 2018-05-18 09:29:01 +0200 | [diff] [blame] | 70 | enum devlink_port_flavour flavour; |
Jiri Pirko | bec5267 | 2019-04-03 14:24:16 +0200 | [diff] [blame] | 71 | struct netdev_phys_item_id switch_id; |
Parav Pandit | 378ef01 | 2019-07-08 23:17:35 -0500 | [diff] [blame] | 72 | union { |
| 73 | struct devlink_port_phys_attrs phys; |
Parav Pandit | 98fd2d6 | 2019-07-08 23:17:37 -0500 | [diff] [blame] | 74 | struct devlink_port_pci_pf_attrs pci_pf; |
Parav Pandit | e41b6bf | 2019-07-08 23:17:38 -0500 | [diff] [blame] | 75 | struct devlink_port_pci_vf_attrs pci_vf; |
Parav Pandit | 378ef01 | 2019-07-08 23:17:35 -0500 | [diff] [blame] | 76 | }; |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 77 | }; |
| 78 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 79 | struct devlink_port { |
| 80 | struct list_head list; |
Vasundhara Volam | 39e6160 | 2019-01-28 18:00:20 +0530 | [diff] [blame] | 81 | struct list_head param_list; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 82 | struct devlink *devlink; |
Parav Pandit | c7282b5 | 2019-08-30 05:39:44 -0500 | [diff] [blame] | 83 | unsigned int index; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 84 | bool registered; |
Jiri Pirko | b8f9755 | 2019-03-24 11:14:37 +0100 | [diff] [blame] | 85 | spinlock_t type_lock; /* Protects type and type_dev |
| 86 | * pointer consistency. |
| 87 | */ |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 88 | enum devlink_port_type type; |
| 89 | enum devlink_port_type desired_type; |
| 90 | void *type_dev; |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 91 | struct devlink_port_attrs attrs; |
Jiri Pirko | 136bf27 | 2019-05-23 10:43:35 +0200 | [diff] [blame] | 92 | struct delayed_work type_warn_dw; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 95 | struct devlink_sb_pool_info { |
| 96 | enum devlink_sb_pool_type pool_type; |
| 97 | u32 size; |
| 98 | enum devlink_sb_threshold_type threshold_type; |
Jakub Kicinski | bff5731 | 2019-02-01 17:56:28 -0800 | [diff] [blame] | 99 | u32 cell_size; |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 100 | }; |
| 101 | |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 102 | /** |
| 103 | * struct devlink_dpipe_field - dpipe field object |
| 104 | * @name: field name |
| 105 | * @id: index inside the headers field array |
| 106 | * @bitwidth: bitwidth |
| 107 | * @mapping_type: mapping type |
| 108 | */ |
| 109 | struct devlink_dpipe_field { |
| 110 | const char *name; |
| 111 | unsigned int id; |
| 112 | unsigned int bitwidth; |
| 113 | enum devlink_dpipe_field_mapping_type mapping_type; |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * struct devlink_dpipe_header - dpipe header object |
| 118 | * @name: header name |
| 119 | * @id: index, global/local detrmined by global bit |
| 120 | * @fields: fields |
| 121 | * @fields_count: number of fields |
| 122 | * @global: indicates if header is shared like most protocol header |
| 123 | * or driver specific |
| 124 | */ |
| 125 | struct devlink_dpipe_header { |
| 126 | const char *name; |
| 127 | unsigned int id; |
| 128 | struct devlink_dpipe_field *fields; |
| 129 | unsigned int fields_count; |
| 130 | bool global; |
| 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * struct devlink_dpipe_match - represents match operation |
| 135 | * @type: type of match |
| 136 | * @header_index: header index (packets can have several headers of same |
| 137 | * type like in case of tunnels) |
| 138 | * @header: header |
| 139 | * @fieled_id: field index |
| 140 | */ |
| 141 | struct devlink_dpipe_match { |
| 142 | enum devlink_dpipe_match_type type; |
| 143 | unsigned int header_index; |
| 144 | struct devlink_dpipe_header *header; |
| 145 | unsigned int field_id; |
| 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * struct devlink_dpipe_action - represents action operation |
| 150 | * @type: type of action |
| 151 | * @header_index: header index (packets can have several headers of same |
| 152 | * type like in case of tunnels) |
| 153 | * @header: header |
| 154 | * @fieled_id: field index |
| 155 | */ |
| 156 | struct devlink_dpipe_action { |
| 157 | enum devlink_dpipe_action_type type; |
| 158 | unsigned int header_index; |
| 159 | struct devlink_dpipe_header *header; |
| 160 | unsigned int field_id; |
| 161 | }; |
| 162 | |
| 163 | /** |
| 164 | * struct devlink_dpipe_value - represents value of match/action |
| 165 | * @action: action |
| 166 | * @match: match |
| 167 | * @mapping_value: in case the field has some mapping this value |
| 168 | * specified the mapping value |
| 169 | * @mapping_valid: specify if mapping value is valid |
| 170 | * @value_size: value size |
| 171 | * @value: value |
| 172 | * @mask: bit mask |
| 173 | */ |
| 174 | struct devlink_dpipe_value { |
| 175 | union { |
| 176 | struct devlink_dpipe_action *action; |
| 177 | struct devlink_dpipe_match *match; |
| 178 | }; |
| 179 | unsigned int mapping_value; |
| 180 | bool mapping_valid; |
| 181 | unsigned int value_size; |
| 182 | void *value; |
| 183 | void *mask; |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * struct devlink_dpipe_entry - table entry object |
| 188 | * @index: index of the entry in the table |
| 189 | * @match_values: match values |
| 190 | * @matche_values_count: count of matches tuples |
| 191 | * @action_values: actions values |
| 192 | * @action_values_count: count of actions values |
| 193 | * @counter: value of counter |
| 194 | * @counter_valid: Specify if value is valid from hardware |
| 195 | */ |
| 196 | struct devlink_dpipe_entry { |
| 197 | u64 index; |
| 198 | struct devlink_dpipe_value *match_values; |
| 199 | unsigned int match_values_count; |
| 200 | struct devlink_dpipe_value *action_values; |
| 201 | unsigned int action_values_count; |
| 202 | u64 counter; |
| 203 | bool counter_valid; |
| 204 | }; |
| 205 | |
| 206 | /** |
| 207 | * struct devlink_dpipe_dump_ctx - context provided to driver in order |
| 208 | * to dump |
| 209 | * @info: info |
| 210 | * @cmd: devlink command |
| 211 | * @skb: skb |
| 212 | * @nest: top attribute |
| 213 | * @hdr: hdr |
| 214 | */ |
| 215 | struct devlink_dpipe_dump_ctx { |
| 216 | struct genl_info *info; |
| 217 | enum devlink_command cmd; |
| 218 | struct sk_buff *skb; |
| 219 | struct nlattr *nest; |
| 220 | void *hdr; |
| 221 | }; |
| 222 | |
| 223 | struct devlink_dpipe_table_ops; |
| 224 | |
| 225 | /** |
| 226 | * struct devlink_dpipe_table - table object |
| 227 | * @priv: private |
| 228 | * @name: table name |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 229 | * @counters_enabled: indicates if counters are active |
| 230 | * @counter_control_extern: indicates if counter control is in dpipe or |
| 231 | * external tool |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 232 | * @resource_valid: Indicate that the resource id is valid |
| 233 | * @resource_id: relative resource this table is related to |
| 234 | * @resource_units: number of resource's unit consumed per table's entry |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 235 | * @table_ops: table operations |
| 236 | * @rcu: rcu |
| 237 | */ |
| 238 | struct devlink_dpipe_table { |
| 239 | void *priv; |
| 240 | struct list_head list; |
| 241 | const char *name; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 242 | bool counters_enabled; |
| 243 | bool counter_control_extern; |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 244 | bool resource_valid; |
| 245 | u64 resource_id; |
| 246 | u64 resource_units; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 247 | struct devlink_dpipe_table_ops *table_ops; |
| 248 | struct rcu_head rcu; |
| 249 | }; |
| 250 | |
| 251 | /** |
| 252 | * struct devlink_dpipe_table_ops - dpipe_table ops |
| 253 | * @actions_dump - dumps all tables actions |
| 254 | * @matches_dump - dumps all tables matches |
| 255 | * @entries_dump - dumps all active entries in the table |
| 256 | * @counters_set_update - when changing the counter status hardware sync |
| 257 | * maybe needed to allocate/free counter related |
| 258 | * resources |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 259 | * @size_get - get size |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 260 | */ |
| 261 | struct devlink_dpipe_table_ops { |
| 262 | int (*actions_dump)(void *priv, struct sk_buff *skb); |
| 263 | int (*matches_dump)(void *priv, struct sk_buff *skb); |
| 264 | int (*entries_dump)(void *priv, bool counters_enabled, |
| 265 | struct devlink_dpipe_dump_ctx *dump_ctx); |
| 266 | int (*counters_set_update)(void *priv, bool enable); |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 267 | u64 (*size_get)(void *priv); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /** |
| 271 | * struct devlink_dpipe_headers - dpipe headers |
| 272 | * @headers - header array can be shared (global bit) or driver specific |
| 273 | * @headers_count - count of headers |
| 274 | */ |
| 275 | struct devlink_dpipe_headers { |
| 276 | struct devlink_dpipe_header **headers; |
| 277 | unsigned int headers_count; |
| 278 | }; |
| 279 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 280 | /** |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 281 | * struct devlink_resource_size_params - resource's size parameters |
| 282 | * @size_min: minimum size which can be set |
| 283 | * @size_max: maximum size which can be set |
| 284 | * @size_granularity: size granularity |
| 285 | * @size_unit: resource's basic unit |
| 286 | */ |
| 287 | struct devlink_resource_size_params { |
| 288 | u64 size_min; |
| 289 | u64 size_max; |
| 290 | u64 size_granularity; |
| 291 | enum devlink_resource_unit unit; |
| 292 | }; |
| 293 | |
Jiri Pirko | 77d2709 | 2018-02-28 13:12:09 +0100 | [diff] [blame] | 294 | static inline void |
| 295 | devlink_resource_size_params_init(struct devlink_resource_size_params *size_params, |
| 296 | u64 size_min, u64 size_max, |
| 297 | u64 size_granularity, |
| 298 | enum devlink_resource_unit unit) |
| 299 | { |
| 300 | size_params->size_min = size_min; |
| 301 | size_params->size_max = size_max; |
| 302 | size_params->size_granularity = size_granularity; |
| 303 | size_params->unit = unit; |
| 304 | } |
| 305 | |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 306 | typedef u64 devlink_resource_occ_get_t(void *priv); |
| 307 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 308 | /** |
| 309 | * struct devlink_resource - devlink resource |
| 310 | * @name: name of the resource |
| 311 | * @id: id, per devlink instance |
| 312 | * @size: size of the resource |
| 313 | * @size_new: updated size of the resource, reload is needed |
| 314 | * @size_valid: valid in case the total size of the resource is valid |
| 315 | * including its children |
| 316 | * @parent: parent resource |
| 317 | * @size_params: size parameters |
| 318 | * @list: parent list |
| 319 | * @resource_list: list of child resources |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 320 | */ |
| 321 | struct devlink_resource { |
| 322 | const char *name; |
| 323 | u64 id; |
| 324 | u64 size; |
| 325 | u64 size_new; |
| 326 | bool size_valid; |
| 327 | struct devlink_resource *parent; |
Jiri Pirko | 77d2709 | 2018-02-28 13:12:09 +0100 | [diff] [blame] | 328 | struct devlink_resource_size_params size_params; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 329 | struct list_head list; |
| 330 | struct list_head resource_list; |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 331 | devlink_resource_occ_get_t *occ_get; |
| 332 | void *occ_get_priv; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 333 | }; |
| 334 | |
| 335 | #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 |
| 336 | |
Moshe Shemesh | bde74ad1 | 2018-10-10 16:09:27 +0300 | [diff] [blame] | 337 | #define __DEVLINK_PARAM_MAX_STRING_VALUE 32 |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 338 | enum devlink_param_type { |
| 339 | DEVLINK_PARAM_TYPE_U8, |
| 340 | DEVLINK_PARAM_TYPE_U16, |
| 341 | DEVLINK_PARAM_TYPE_U32, |
| 342 | DEVLINK_PARAM_TYPE_STRING, |
| 343 | DEVLINK_PARAM_TYPE_BOOL, |
| 344 | }; |
| 345 | |
| 346 | union devlink_param_value { |
| 347 | u8 vu8; |
| 348 | u16 vu16; |
| 349 | u32 vu32; |
Moshe Shemesh | bde74ad1 | 2018-10-10 16:09:27 +0300 | [diff] [blame] | 350 | char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE]; |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 351 | bool vbool; |
| 352 | }; |
| 353 | |
| 354 | struct devlink_param_gset_ctx { |
| 355 | union devlink_param_value val; |
| 356 | enum devlink_param_cmode cmode; |
| 357 | }; |
| 358 | |
| 359 | /** |
| 360 | * struct devlink_param - devlink configuration parameter data |
| 361 | * @name: name of the parameter |
| 362 | * @generic: indicates if the parameter is generic or driver specific |
| 363 | * @type: parameter type |
| 364 | * @supported_cmodes: bitmap of supported configuration modes |
| 365 | * @get: get parameter value, used for runtime and permanent |
| 366 | * configuration modes |
| 367 | * @set: set parameter value, used for runtime and permanent |
| 368 | * configuration modes |
Moshe Shemesh | e3b7ca1 | 2018-07-04 14:30:30 +0300 | [diff] [blame] | 369 | * @validate: validate input value is applicable (within value range, etc.) |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 370 | * |
| 371 | * This struct should be used by the driver to fill the data for |
| 372 | * a parameter it registers. |
| 373 | */ |
| 374 | struct devlink_param { |
| 375 | u32 id; |
| 376 | const char *name; |
| 377 | bool generic; |
| 378 | enum devlink_param_type type; |
| 379 | unsigned long supported_cmodes; |
| 380 | int (*get)(struct devlink *devlink, u32 id, |
| 381 | struct devlink_param_gset_ctx *ctx); |
| 382 | int (*set)(struct devlink *devlink, u32 id, |
| 383 | struct devlink_param_gset_ctx *ctx); |
Moshe Shemesh | e3b7ca1 | 2018-07-04 14:30:30 +0300 | [diff] [blame] | 384 | int (*validate)(struct devlink *devlink, u32 id, |
| 385 | union devlink_param_value val, |
| 386 | struct netlink_ext_ack *extack); |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | struct devlink_param_item { |
| 390 | struct list_head list; |
| 391 | const struct devlink_param *param; |
| 392 | union devlink_param_value driverinit_value; |
| 393 | bool driverinit_value_valid; |
Jiri Pirko | 7c62cfb | 2019-02-07 11:22:45 +0000 | [diff] [blame] | 394 | bool published; |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | enum devlink_param_generic_id { |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 398 | DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET, |
| 399 | DEVLINK_PARAM_GENERIC_ID_MAX_MACS, |
Vasundhara Volam | f567bcd | 2018-07-04 14:30:36 +0300 | [diff] [blame] | 400 | DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, |
Alex Vesker | f6a69885 | 2018-07-12 15:13:17 +0300 | [diff] [blame] | 401 | DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT, |
Vasundhara Volam | e3b5106 | 2018-10-04 11:13:44 +0530 | [diff] [blame] | 402 | DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, |
Vasundhara Volam | f61cba4 | 2018-10-04 11:13:45 +0530 | [diff] [blame] | 403 | DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX, |
Vasundhara Volam | 1651178 | 2018-10-04 11:13:46 +0530 | [diff] [blame] | 404 | DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN, |
Shalom Toledo | 846e980 | 2018-12-03 07:58:59 +0000 | [diff] [blame] | 405 | DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY, |
Dirk van der Merwe | 5bbd21d | 2019-09-09 00:54:18 +0100 | [diff] [blame] | 406 | DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE, |
Michael Guralnik | 6c7295e | 2019-11-08 23:45:20 +0000 | [diff] [blame] | 407 | DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE, |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 408 | |
| 409 | /* add new param generic ids above here*/ |
| 410 | __DEVLINK_PARAM_GENERIC_ID_MAX, |
| 411 | DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1, |
| 412 | }; |
| 413 | |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 414 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset" |
| 415 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 416 | |
| 417 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs" |
| 418 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32 |
| 419 | |
Vasundhara Volam | f567bcd | 2018-07-04 14:30:36 +0300 | [diff] [blame] | 420 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov" |
| 421 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 422 | |
Alex Vesker | f6a69885 | 2018-07-12 15:13:17 +0300 | [diff] [blame] | 423 | #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable" |
| 424 | #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 425 | |
Vasundhara Volam | e3b5106 | 2018-10-04 11:13:44 +0530 | [diff] [blame] | 426 | #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari" |
| 427 | #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 428 | |
Vasundhara Volam | f61cba4 | 2018-10-04 11:13:45 +0530 | [diff] [blame] | 429 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max" |
| 430 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32 |
| 431 | |
Vasundhara Volam | 1651178 | 2018-10-04 11:13:46 +0530 | [diff] [blame] | 432 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min" |
| 433 | #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32 |
| 434 | |
Shalom Toledo | 846e980 | 2018-12-03 07:58:59 +0000 | [diff] [blame] | 435 | #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy" |
| 436 | #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8 |
| 437 | |
Dirk van der Merwe | 5bbd21d | 2019-09-09 00:54:18 +0100 | [diff] [blame] | 438 | #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \ |
| 439 | "reset_dev_on_drv_probe" |
| 440 | #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8 |
| 441 | |
Michael Guralnik | 6c7295e | 2019-11-08 23:45:20 +0000 | [diff] [blame] | 442 | #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce" |
| 443 | #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 444 | |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 445 | #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ |
| 446 | { \ |
| 447 | .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ |
| 448 | .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \ |
| 449 | .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \ |
| 450 | .generic = true, \ |
| 451 | .supported_cmodes = _cmodes, \ |
| 452 | .get = _get, \ |
| 453 | .set = _set, \ |
| 454 | .validate = _validate, \ |
| 455 | } |
| 456 | |
| 457 | #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \ |
| 458 | { \ |
| 459 | .id = _id, \ |
| 460 | .name = _name, \ |
| 461 | .type = _type, \ |
| 462 | .supported_cmodes = _cmodes, \ |
| 463 | .get = _get, \ |
| 464 | .set = _set, \ |
| 465 | .validate = _validate, \ |
| 466 | } |
| 467 | |
Jakub Kicinski | 785bd55 | 2019-01-31 10:50:42 -0800 | [diff] [blame] | 468 | /* Part number, identifier of board design */ |
| 469 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id" |
| 470 | /* Revision of board design */ |
| 471 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev" |
Jakub Kicinski | 14fd190 | 2019-02-10 19:35:29 -0800 | [diff] [blame] | 472 | /* Maker of the board */ |
| 473 | #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture" |
Jakub Kicinski | 785bd55 | 2019-01-31 10:50:42 -0800 | [diff] [blame] | 474 | |
Shannon Nelson | 7d5aa9a | 2019-09-03 15:28:03 -0700 | [diff] [blame] | 475 | /* Part number, identifier of asic design */ |
| 476 | #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id" |
| 477 | /* Revision of asic design */ |
| 478 | #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev" |
| 479 | |
| 480 | /* Overall FW version */ |
| 481 | #define DEVLINK_INFO_VERSION_GENERIC_FW "fw" |
Jakub Kicinski | 785bd55 | 2019-01-31 10:50:42 -0800 | [diff] [blame] | 482 | /* Control processor FW version */ |
| 483 | #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt" |
| 484 | /* Data path microcode controlling high-speed packet processing */ |
| 485 | #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app" |
| 486 | /* UNDI software version */ |
| 487 | #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi" |
| 488 | /* NCSI support/handler version */ |
| 489 | #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi" |
Jacob Keller | 468672b | 2020-01-09 14:46:09 -0800 | [diff] [blame] | 490 | /* FW parameter set id */ |
| 491 | #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid" |
Vasundhara Volam | 41c0d91 | 2020-01-27 04:56:25 -0500 | [diff] [blame] | 492 | /* RoCE FW version */ |
| 493 | #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce" |
Jacob Keller | c90977a | 2020-03-11 18:58:16 -0700 | [diff] [blame] | 494 | /* Firmware bundle identifier */ |
| 495 | #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id" |
Jakub Kicinski | 785bd55 | 2019-01-31 10:50:42 -0800 | [diff] [blame] | 496 | |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 497 | struct devlink_region; |
Jakub Kicinski | f9cf228 | 2019-01-31 10:50:40 -0800 | [diff] [blame] | 498 | struct devlink_info_req; |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 499 | |
Jacob Keller | e893768 | 2020-03-26 11:37:08 -0700 | [diff] [blame] | 500 | /** |
| 501 | * struct devlink_region_ops - Region operations |
| 502 | * @name: region name |
Jacob Keller | a0a09f6 | 2020-03-26 11:37:09 -0700 | [diff] [blame] | 503 | * @destructor: callback used to free snapshot memory when deleting |
Jacob Keller | b9a17abf | 2020-03-26 11:37:16 -0700 | [diff] [blame^] | 504 | * @snapshot: callback to request an immediate snapshot. On success, |
| 505 | * the data variable must be updated to point to the snapshot data. |
| 506 | * The function will be called while the devlink instance lock is |
| 507 | * held. |
Jacob Keller | e893768 | 2020-03-26 11:37:08 -0700 | [diff] [blame] | 508 | */ |
| 509 | struct devlink_region_ops { |
| 510 | const char *name; |
Jacob Keller | a0a09f6 | 2020-03-26 11:37:09 -0700 | [diff] [blame] | 511 | void (*destructor)(const void *data); |
Jacob Keller | b9a17abf | 2020-03-26 11:37:16 -0700 | [diff] [blame^] | 512 | int (*snapshot)(struct devlink *devlink, struct netlink_ext_ack *extack, |
| 513 | u8 **data); |
Jacob Keller | e893768 | 2020-03-26 11:37:08 -0700 | [diff] [blame] | 514 | }; |
| 515 | |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 516 | struct devlink_fmsg; |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 517 | struct devlink_health_reporter; |
| 518 | |
Eran Ben Elisha | 3167b27 | 2019-03-03 10:57:30 +0200 | [diff] [blame] | 519 | enum devlink_health_reporter_state { |
| 520 | DEVLINK_HEALTH_REPORTER_STATE_HEALTHY, |
| 521 | DEVLINK_HEALTH_REPORTER_STATE_ERROR, |
| 522 | }; |
| 523 | |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 524 | /** |
| 525 | * struct devlink_health_reporter_ops - Reporter operations |
| 526 | * @name: reporter name |
| 527 | * @recover: callback to recover from reported error |
| 528 | * if priv_ctx is NULL, run a full recover |
| 529 | * @dump: callback to dump an object |
| 530 | * if priv_ctx is NULL, run a full dump |
| 531 | * @diagnose: callback to diagnose the current status |
| 532 | */ |
| 533 | |
| 534 | struct devlink_health_reporter_ops { |
| 535 | char *name; |
| 536 | int (*recover)(struct devlink_health_reporter *reporter, |
Jiri Pirko | e7a9810 | 2019-10-10 15:18:49 +0200 | [diff] [blame] | 537 | void *priv_ctx, struct netlink_ext_ack *extack); |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 538 | int (*dump)(struct devlink_health_reporter *reporter, |
Jiri Pirko | e7a9810 | 2019-10-10 15:18:49 +0200 | [diff] [blame] | 539 | struct devlink_fmsg *fmsg, void *priv_ctx, |
| 540 | struct netlink_ext_ack *extack); |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 541 | int (*diagnose)(struct devlink_health_reporter *reporter, |
Jiri Pirko | e7a9810 | 2019-10-10 15:18:49 +0200 | [diff] [blame] | 542 | struct devlink_fmsg *fmsg, |
| 543 | struct netlink_ext_ack *extack); |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 544 | }; |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 545 | |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 546 | /** |
| 547 | * struct devlink_trap_group - Immutable packet trap group attributes. |
| 548 | * @name: Trap group name. |
| 549 | * @id: Trap group identifier. |
| 550 | * @generic: Whether the trap group is generic or not. |
| 551 | * |
| 552 | * Describes immutable attributes of packet trap groups that drivers register |
| 553 | * with devlink. |
| 554 | */ |
| 555 | struct devlink_trap_group { |
| 556 | const char *name; |
| 557 | u16 id; |
| 558 | bool generic; |
| 559 | }; |
| 560 | |
| 561 | #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0) |
Jiri Pirko | 85b0589 | 2020-02-25 11:45:19 +0100 | [diff] [blame] | 562 | #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1) |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * struct devlink_trap - Immutable packet trap attributes. |
| 566 | * @type: Trap type. |
| 567 | * @init_action: Initial trap action. |
| 568 | * @generic: Whether the trap is generic or not. |
| 569 | * @id: Trap identifier. |
| 570 | * @name: Trap name. |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 571 | * @init_group_id: Initial group identifier. |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 572 | * @metadata_cap: Metadata types that can be provided by the trap. |
| 573 | * |
| 574 | * Describes immutable attributes of packet traps that drivers register with |
| 575 | * devlink. |
| 576 | */ |
| 577 | struct devlink_trap { |
| 578 | enum devlink_trap_type type; |
| 579 | enum devlink_trap_action init_action; |
| 580 | bool generic; |
| 581 | u16 id; |
| 582 | const char *name; |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 583 | u16 init_group_id; |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 584 | u32 metadata_cap; |
| 585 | }; |
| 586 | |
Ido Schimmel | f3047ca | 2019-08-17 16:28:19 +0300 | [diff] [blame] | 587 | /* All traps must be documented in |
Jacob Keller | f4bdd71 | 2020-01-09 14:46:10 -0800 | [diff] [blame] | 588 | * Documentation/networking/devlink/devlink-trap.rst |
Ido Schimmel | f3047ca | 2019-08-17 16:28:19 +0300 | [diff] [blame] | 589 | */ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 590 | enum devlink_trap_generic_id { |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 591 | DEVLINK_TRAP_GENERIC_ID_SMAC_MC, |
| 592 | DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH, |
| 593 | DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER, |
| 594 | DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER, |
| 595 | DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST, |
| 596 | DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER, |
| 597 | DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE, |
| 598 | DEVLINK_TRAP_GENERIC_ID_TTL_ERROR, |
| 599 | DEVLINK_TRAP_GENERIC_ID_TAIL_DROP, |
Amit Cohen | 6896cc4 | 2019-11-07 18:42:09 +0200 | [diff] [blame] | 600 | DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET, |
| 601 | DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC, |
| 602 | DEVLINK_TRAP_GENERIC_ID_DIP_LB, |
| 603 | DEVLINK_TRAP_GENERIC_ID_SIP_MC, |
| 604 | DEVLINK_TRAP_GENERIC_ID_SIP_LB, |
| 605 | DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR, |
| 606 | DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC, |
| 607 | DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE, |
| 608 | DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE, |
Amit Cohen | 3b063ae | 2019-11-07 18:42:14 +0200 | [diff] [blame] | 609 | DEVLINK_TRAP_GENERIC_ID_MTU_ERROR, |
| 610 | DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH, |
| 611 | DEVLINK_TRAP_GENERIC_ID_RPF, |
| 612 | DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE, |
| 613 | DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS, |
| 614 | DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS, |
Amit Cohen | 95f0ead | 2020-01-19 15:00:48 +0200 | [diff] [blame] | 615 | DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE, |
Amit Cohen | 13c056e | 2020-01-19 15:00:54 +0200 | [diff] [blame] | 616 | DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR, |
Amit Cohen | c3cae49 | 2020-01-19 15:00:58 +0200 | [diff] [blame] | 617 | DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC, |
Jiri Pirko | ecd942a | 2020-02-24 08:35:47 +0100 | [diff] [blame] | 618 | DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP, |
| 619 | DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP, |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 620 | |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 621 | /* Add new generic trap IDs above */ |
| 622 | __DEVLINK_TRAP_GENERIC_ID_MAX, |
| 623 | DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1, |
| 624 | }; |
| 625 | |
Ido Schimmel | f3047ca | 2019-08-17 16:28:19 +0300 | [diff] [blame] | 626 | /* All trap groups must be documented in |
Jacob Keller | f4bdd71 | 2020-01-09 14:46:10 -0800 | [diff] [blame] | 627 | * Documentation/networking/devlink/devlink-trap.rst |
Ido Schimmel | f3047ca | 2019-08-17 16:28:19 +0300 | [diff] [blame] | 628 | */ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 629 | enum devlink_trap_group_generic_id { |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 630 | DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS, |
| 631 | DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS, |
| 632 | DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS, |
Amit Cohen | 13c056e | 2020-01-19 15:00:54 +0200 | [diff] [blame] | 633 | DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS, |
Jiri Pirko | ecd942a | 2020-02-24 08:35:47 +0100 | [diff] [blame] | 634 | DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS, |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 635 | |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 636 | /* Add new generic trap group IDs above */ |
| 637 | __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX, |
| 638 | DEVLINK_TRAP_GROUP_GENERIC_ID_MAX = |
| 639 | __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1, |
| 640 | }; |
| 641 | |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 642 | #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \ |
| 643 | "source_mac_is_multicast" |
| 644 | #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \ |
| 645 | "vlan_tag_mismatch" |
| 646 | #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \ |
| 647 | "ingress_vlan_filter" |
| 648 | #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \ |
| 649 | "ingress_spanning_tree_filter" |
| 650 | #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \ |
| 651 | "port_list_is_empty" |
| 652 | #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \ |
| 653 | "port_loopback_filter" |
| 654 | #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \ |
| 655 | "blackhole_route" |
| 656 | #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \ |
| 657 | "ttl_value_is_too_small" |
| 658 | #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \ |
| 659 | "tail_drop" |
Amit Cohen | 6896cc4 | 2019-11-07 18:42:09 +0200 | [diff] [blame] | 660 | #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \ |
| 661 | "non_ip" |
| 662 | #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \ |
| 663 | "uc_dip_over_mc_dmac" |
| 664 | #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \ |
| 665 | "dip_is_loopback_address" |
| 666 | #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \ |
| 667 | "sip_is_mc" |
| 668 | #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \ |
| 669 | "sip_is_loopback_address" |
| 670 | #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \ |
| 671 | "ip_header_corrupted" |
| 672 | #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \ |
| 673 | "ipv4_sip_is_limited_bc" |
| 674 | #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \ |
| 675 | "ipv6_mc_dip_reserved_scope" |
| 676 | #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \ |
| 677 | "ipv6_mc_dip_interface_local_scope" |
Amit Cohen | 3b063ae | 2019-11-07 18:42:14 +0200 | [diff] [blame] | 678 | #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \ |
| 679 | "mtu_value_is_too_small" |
| 680 | #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \ |
| 681 | "unresolved_neigh" |
| 682 | #define DEVLINK_TRAP_GENERIC_NAME_RPF \ |
| 683 | "mc_reverse_path_forwarding" |
| 684 | #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \ |
| 685 | "reject_route" |
| 686 | #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \ |
| 687 | "ipv4_lpm_miss" |
| 688 | #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \ |
| 689 | "ipv6_lpm_miss" |
Amit Cohen | 95f0ead | 2020-01-19 15:00:48 +0200 | [diff] [blame] | 690 | #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \ |
| 691 | "non_routable_packet" |
Amit Cohen | 13c056e | 2020-01-19 15:00:54 +0200 | [diff] [blame] | 692 | #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \ |
| 693 | "decap_error" |
Amit Cohen | c3cae49 | 2020-01-19 15:00:58 +0200 | [diff] [blame] | 694 | #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \ |
| 695 | "overlay_smac_is_mc" |
Jiri Pirko | ecd942a | 2020-02-24 08:35:47 +0100 | [diff] [blame] | 696 | #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \ |
| 697 | "ingress_flow_action_drop" |
| 698 | #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \ |
| 699 | "egress_flow_action_drop" |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 700 | |
| 701 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \ |
| 702 | "l2_drops" |
| 703 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \ |
| 704 | "l3_drops" |
| 705 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \ |
| 706 | "buffer_drops" |
Amit Cohen | 13c056e | 2020-01-19 15:00:54 +0200 | [diff] [blame] | 707 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \ |
| 708 | "tunnel_drops" |
Jiri Pirko | ecd942a | 2020-02-24 08:35:47 +0100 | [diff] [blame] | 709 | #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \ |
| 710 | "acl_drops" |
Ido Schimmel | 391203a | 2019-08-17 16:28:18 +0300 | [diff] [blame] | 711 | |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 712 | #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \ |
| 713 | _metadata_cap) \ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 714 | { \ |
| 715 | .type = DEVLINK_TRAP_TYPE_##_type, \ |
| 716 | .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ |
| 717 | .generic = true, \ |
| 718 | .id = DEVLINK_TRAP_GENERIC_ID_##_id, \ |
| 719 | .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \ |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 720 | .init_group_id = _group_id, \ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 721 | .metadata_cap = _metadata_cap, \ |
| 722 | } |
| 723 | |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 724 | #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 725 | _metadata_cap) \ |
| 726 | { \ |
| 727 | .type = DEVLINK_TRAP_TYPE_##_type, \ |
| 728 | .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ |
| 729 | .generic = false, \ |
| 730 | .id = _id, \ |
| 731 | .name = _name, \ |
Ido Schimmel | 107f167 | 2020-03-22 20:48:30 +0200 | [diff] [blame] | 732 | .init_group_id = _group_id, \ |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 733 | .metadata_cap = _metadata_cap, \ |
| 734 | } |
| 735 | |
| 736 | #define DEVLINK_TRAP_GROUP_GENERIC(_id) \ |
| 737 | { \ |
| 738 | .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \ |
| 739 | .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \ |
| 740 | .generic = true, \ |
| 741 | } |
| 742 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 743 | struct devlink_ops { |
Jiri Pirko | 070c63f | 2019-10-03 11:49:39 +0200 | [diff] [blame] | 744 | int (*reload_down)(struct devlink *devlink, bool netns_change, |
Jiri Pirko | 9769106 | 2019-09-12 10:49:45 +0200 | [diff] [blame] | 745 | struct netlink_ext_ack *extack); |
| 746 | int (*reload_up)(struct devlink *devlink, |
| 747 | struct netlink_ext_ack *extack); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 748 | int (*port_type_set)(struct devlink_port *devlink_port, |
| 749 | enum devlink_port_type port_type); |
| 750 | int (*port_split)(struct devlink *devlink, unsigned int port_index, |
David Ahern | ac0fc8a | 2018-06-05 08:14:09 -0700 | [diff] [blame] | 751 | unsigned int count, struct netlink_ext_ack *extack); |
| 752 | int (*port_unsplit)(struct devlink *devlink, unsigned int port_index, |
| 753 | struct netlink_ext_ack *extack); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 754 | int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index, |
| 755 | u16 pool_index, |
| 756 | struct devlink_sb_pool_info *pool_info); |
| 757 | int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index, |
| 758 | u16 pool_index, u32 size, |
Ido Schimmel | f2ad1a5 | 2019-04-22 12:08:39 +0000 | [diff] [blame] | 759 | enum devlink_sb_threshold_type threshold_type, |
| 760 | struct netlink_ext_ack *extack); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 761 | int (*sb_port_pool_get)(struct devlink_port *devlink_port, |
| 762 | unsigned int sb_index, u16 pool_index, |
| 763 | u32 *p_threshold); |
| 764 | int (*sb_port_pool_set)(struct devlink_port *devlink_port, |
| 765 | unsigned int sb_index, u16 pool_index, |
Ido Schimmel | f2ad1a5 | 2019-04-22 12:08:39 +0000 | [diff] [blame] | 766 | u32 threshold, struct netlink_ext_ack *extack); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 767 | int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port, |
| 768 | unsigned int sb_index, |
| 769 | u16 tc_index, |
| 770 | enum devlink_sb_pool_type pool_type, |
| 771 | u16 *p_pool_index, u32 *p_threshold); |
| 772 | int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port, |
| 773 | unsigned int sb_index, |
| 774 | u16 tc_index, |
| 775 | enum devlink_sb_pool_type pool_type, |
Ido Schimmel | f2ad1a5 | 2019-04-22 12:08:39 +0000 | [diff] [blame] | 776 | u16 pool_index, u32 threshold, |
| 777 | struct netlink_ext_ack *extack); |
Jiri Pirko | df38daf | 2016-04-14 18:19:14 +0200 | [diff] [blame] | 778 | int (*sb_occ_snapshot)(struct devlink *devlink, |
| 779 | unsigned int sb_index); |
| 780 | int (*sb_occ_max_clear)(struct devlink *devlink, |
| 781 | unsigned int sb_index); |
| 782 | int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port, |
| 783 | unsigned int sb_index, u16 pool_index, |
| 784 | u32 *p_cur, u32 *p_max); |
| 785 | int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port, |
| 786 | unsigned int sb_index, |
| 787 | u16 tc_index, |
| 788 | enum devlink_sb_pool_type pool_type, |
| 789 | u32 *p_cur, u32 *p_max); |
Or Gerlitz | 08f4b59 | 2016-07-01 14:51:01 +0300 | [diff] [blame] | 790 | |
| 791 | int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode); |
Eli Britstein | db7ff19 | 2018-08-15 16:02:18 +0300 | [diff] [blame] | 792 | int (*eswitch_mode_set)(struct devlink *devlink, u16 mode, |
| 793 | struct netlink_ext_ack *extack); |
Roi Dayan | 59bfde0 | 2016-11-22 23:09:57 +0200 | [diff] [blame] | 794 | int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode); |
Eli Britstein | db7ff19 | 2018-08-15 16:02:18 +0300 | [diff] [blame] | 795 | int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode, |
| 796 | struct netlink_ext_ack *extack); |
Leon Romanovsky | 98fdbea | 2019-06-12 15:20:11 +0300 | [diff] [blame] | 797 | int (*eswitch_encap_mode_get)(struct devlink *devlink, |
| 798 | enum devlink_eswitch_encap_mode *p_encap_mode); |
| 799 | int (*eswitch_encap_mode_set)(struct devlink *devlink, |
| 800 | enum devlink_eswitch_encap_mode encap_mode, |
Eli Britstein | db7ff19 | 2018-08-15 16:02:18 +0300 | [diff] [blame] | 801 | struct netlink_ext_ack *extack); |
Jakub Kicinski | f9cf228 | 2019-01-31 10:50:40 -0800 | [diff] [blame] | 802 | int (*info_get)(struct devlink *devlink, struct devlink_info_req *req, |
| 803 | struct netlink_ext_ack *extack); |
Jakub Kicinski | 76726cc | 2019-02-14 13:40:44 -0800 | [diff] [blame] | 804 | int (*flash_update)(struct devlink *devlink, const char *file_name, |
| 805 | const char *component, |
| 806 | struct netlink_ext_ack *extack); |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 807 | /** |
| 808 | * @trap_init: Trap initialization function. |
| 809 | * |
| 810 | * Should be used by device drivers to initialize the trap in the |
| 811 | * underlying device. Drivers should also store the provided trap |
| 812 | * context, so that they could efficiently pass it to |
| 813 | * devlink_trap_report() when the trap is triggered. |
| 814 | */ |
| 815 | int (*trap_init)(struct devlink *devlink, |
| 816 | const struct devlink_trap *trap, void *trap_ctx); |
| 817 | /** |
| 818 | * @trap_fini: Trap de-initialization function. |
| 819 | * |
| 820 | * Should be used by device drivers to de-initialize the trap in the |
| 821 | * underlying device. |
| 822 | */ |
| 823 | void (*trap_fini)(struct devlink *devlink, |
| 824 | const struct devlink_trap *trap, void *trap_ctx); |
| 825 | /** |
| 826 | * @trap_action_set: Trap action set function. |
| 827 | */ |
| 828 | int (*trap_action_set)(struct devlink *devlink, |
| 829 | const struct devlink_trap *trap, |
| 830 | enum devlink_trap_action action); |
| 831 | /** |
| 832 | * @trap_group_init: Trap group initialization function. |
| 833 | * |
| 834 | * Should be used by device drivers to initialize the trap group in the |
| 835 | * underlying device. |
| 836 | */ |
| 837 | int (*trap_group_init)(struct devlink *devlink, |
| 838 | const struct devlink_trap_group *group); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | static inline void *devlink_priv(struct devlink *devlink) |
| 842 | { |
| 843 | BUG_ON(!devlink); |
| 844 | return &devlink->priv; |
| 845 | } |
| 846 | |
| 847 | static inline struct devlink *priv_to_devlink(void *priv) |
| 848 | { |
| 849 | BUG_ON(!priv); |
| 850 | return container_of(priv, struct devlink, priv); |
| 851 | } |
| 852 | |
Jiri Pirko | 5dc37bb | 2019-03-28 13:56:36 +0100 | [diff] [blame] | 853 | static inline struct devlink_port * |
| 854 | netdev_to_devlink_port(struct net_device *dev) |
| 855 | { |
| 856 | if (dev->netdev_ops->ndo_get_devlink_port) |
| 857 | return dev->netdev_ops->ndo_get_devlink_port(dev); |
| 858 | return NULL; |
| 859 | } |
| 860 | |
Jakub Kicinski | b473b0d | 2019-02-25 19:34:03 -0800 | [diff] [blame] | 861 | static inline struct devlink *netdev_to_devlink(struct net_device *dev) |
| 862 | { |
Jiri Pirko | 5dc37bb | 2019-03-28 13:56:36 +0100 | [diff] [blame] | 863 | struct devlink_port *devlink_port = netdev_to_devlink_port(dev); |
| 864 | |
| 865 | if (devlink_port) |
| 866 | return devlink_port->devlink; |
Jakub Kicinski | b473b0d | 2019-02-25 19:34:03 -0800 | [diff] [blame] | 867 | return NULL; |
| 868 | } |
| 869 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 870 | struct ib_device; |
| 871 | |
Jiri Pirko | 471f894 | 2019-10-03 11:49:31 +0200 | [diff] [blame] | 872 | struct net *devlink_net(const struct devlink *devlink); |
Jiri Pirko | 8273fd8 | 2019-10-05 08:10:31 +0200 | [diff] [blame] | 873 | void devlink_net_set(struct devlink *devlink, struct net *net); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 874 | struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size); |
| 875 | int devlink_register(struct devlink *devlink, struct device *dev); |
| 876 | void devlink_unregister(struct devlink *devlink); |
Jiri Pirko | a0c7634 | 2019-11-08 21:42:43 +0100 | [diff] [blame] | 877 | void devlink_reload_enable(struct devlink *devlink); |
| 878 | void devlink_reload_disable(struct devlink *devlink); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 879 | void devlink_free(struct devlink *devlink); |
| 880 | int devlink_port_register(struct devlink *devlink, |
| 881 | struct devlink_port *devlink_port, |
| 882 | unsigned int port_index); |
| 883 | void devlink_port_unregister(struct devlink_port *devlink_port); |
| 884 | void devlink_port_type_eth_set(struct devlink_port *devlink_port, |
| 885 | struct net_device *netdev); |
| 886 | void devlink_port_type_ib_set(struct devlink_port *devlink_port, |
| 887 | struct ib_device *ibdev); |
| 888 | void devlink_port_type_clear(struct devlink_port *devlink_port); |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 889 | void devlink_port_attrs_set(struct devlink_port *devlink_port, |
Jiri Pirko | 5ec1380 | 2018-05-18 09:29:01 +0200 | [diff] [blame] | 890 | enum devlink_port_flavour flavour, |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 891 | u32 port_number, bool split, |
Jiri Pirko | bec5267 | 2019-04-03 14:24:16 +0200 | [diff] [blame] | 892 | u32 split_subport_number, |
| 893 | const unsigned char *switch_id, |
| 894 | unsigned char switch_id_len); |
Parav Pandit | 98fd2d6 | 2019-07-08 23:17:37 -0500 | [diff] [blame] | 895 | void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, |
| 896 | const unsigned char *switch_id, |
| 897 | unsigned char switch_id_len, u16 pf); |
Parav Pandit | e41b6bf | 2019-07-08 23:17:38 -0500 | [diff] [blame] | 898 | void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, |
| 899 | const unsigned char *switch_id, |
| 900 | unsigned char switch_id_len, |
| 901 | u16 pf, u16 vf); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 902 | int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, |
| 903 | u32 size, u16 ingress_pools_count, |
| 904 | u16 egress_pools_count, u16 ingress_tc_count, |
| 905 | u16 egress_tc_count); |
| 906 | void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 907 | int devlink_dpipe_table_register(struct devlink *devlink, |
| 908 | const char *table_name, |
| 909 | struct devlink_dpipe_table_ops *table_ops, |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 910 | void *priv, bool counter_control_extern); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 911 | void devlink_dpipe_table_unregister(struct devlink *devlink, |
| 912 | const char *table_name); |
| 913 | int devlink_dpipe_headers_register(struct devlink *devlink, |
| 914 | struct devlink_dpipe_headers *dpipe_headers); |
| 915 | void devlink_dpipe_headers_unregister(struct devlink *devlink); |
| 916 | bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, |
| 917 | const char *table_name); |
| 918 | int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx); |
| 919 | int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, |
| 920 | struct devlink_dpipe_entry *entry); |
| 921 | int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx); |
Arkadi Sharshevsky | 3580732 | 2017-08-24 08:40:03 +0200 | [diff] [blame] | 922 | void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 923 | int devlink_dpipe_action_put(struct sk_buff *skb, |
| 924 | struct devlink_dpipe_action *action); |
| 925 | int devlink_dpipe_match_put(struct sk_buff *skb, |
| 926 | struct devlink_dpipe_match *match); |
Arkadi Sharshevsky | 1177009 | 2017-08-24 08:39:59 +0200 | [diff] [blame] | 927 | extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; |
Arkadi Sharshevsky | 3fb886e | 2017-08-24 08:40:00 +0200 | [diff] [blame] | 928 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; |
Arkadi Sharshevsky | 1797f5b | 2017-08-31 17:59:12 +0200 | [diff] [blame] | 929 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 930 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 931 | int devlink_resource_register(struct devlink *devlink, |
| 932 | const char *resource_name, |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 933 | u64 resource_size, |
| 934 | u64 resource_id, |
| 935 | u64 parent_resource_id, |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 936 | const struct devlink_resource_size_params *size_params); |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 937 | void devlink_resources_unregister(struct devlink *devlink, |
| 938 | struct devlink_resource *resource); |
| 939 | int devlink_resource_size_get(struct devlink *devlink, |
| 940 | u64 resource_id, |
| 941 | u64 *p_resource_size); |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 942 | int devlink_dpipe_table_resource_set(struct devlink *devlink, |
| 943 | const char *table_name, u64 resource_id, |
| 944 | u64 resource_units); |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 945 | void devlink_resource_occ_get_register(struct devlink *devlink, |
| 946 | u64 resource_id, |
| 947 | devlink_resource_occ_get_t *occ_get, |
| 948 | void *occ_get_priv); |
| 949 | void devlink_resource_occ_get_unregister(struct devlink *devlink, |
| 950 | u64 resource_id); |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 951 | int devlink_params_register(struct devlink *devlink, |
| 952 | const struct devlink_param *params, |
| 953 | size_t params_count); |
| 954 | void devlink_params_unregister(struct devlink *devlink, |
| 955 | const struct devlink_param *params, |
| 956 | size_t params_count); |
Jiri Pirko | 7c62cfb | 2019-02-07 11:22:45 +0000 | [diff] [blame] | 957 | void devlink_params_publish(struct devlink *devlink); |
| 958 | void devlink_params_unpublish(struct devlink *devlink); |
Vasundhara Volam | 39e6160 | 2019-01-28 18:00:20 +0530 | [diff] [blame] | 959 | int devlink_port_params_register(struct devlink_port *devlink_port, |
| 960 | const struct devlink_param *params, |
| 961 | size_t params_count); |
| 962 | void devlink_port_params_unregister(struct devlink_port *devlink_port, |
| 963 | const struct devlink_param *params, |
| 964 | size_t params_count); |
Moshe Shemesh | ec01aeb | 2018-07-04 14:30:31 +0300 | [diff] [blame] | 965 | int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, |
| 966 | union devlink_param_value *init_val); |
| 967 | int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, |
| 968 | union devlink_param_value init_val); |
Vasundhara Volam | ffd19b9 | 2019-01-28 18:00:23 +0530 | [diff] [blame] | 969 | int |
| 970 | devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port, |
| 971 | u32 param_id, |
| 972 | union devlink_param_value *init_val); |
Vasundhara Volam | 5473a7b | 2019-01-28 18:00:24 +0530 | [diff] [blame] | 973 | int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port, |
| 974 | u32 param_id, |
| 975 | union devlink_param_value init_val); |
Moshe Shemesh | ea601e1 | 2018-07-04 14:30:32 +0300 | [diff] [blame] | 976 | void devlink_param_value_changed(struct devlink *devlink, u32 param_id); |
Vasundhara Volam | c1e5786d | 2019-01-28 18:00:25 +0530 | [diff] [blame] | 977 | void devlink_port_param_value_changed(struct devlink_port *devlink_port, |
| 978 | u32 param_id); |
Moshe Shemesh | bde74ad1 | 2018-10-10 16:09:27 +0300 | [diff] [blame] | 979 | void devlink_param_value_str_fill(union devlink_param_value *dst_val, |
| 980 | const char *src); |
Jacob Keller | e893768 | 2020-03-26 11:37:08 -0700 | [diff] [blame] | 981 | struct devlink_region * |
| 982 | devlink_region_create(struct devlink *devlink, |
| 983 | const struct devlink_region_ops *ops, |
| 984 | u32 region_max_snapshots, u64 region_size); |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 985 | void devlink_region_destroy(struct devlink_region *region); |
Jacob Keller | 7ef19d3 | 2020-03-26 11:37:14 -0700 | [diff] [blame] | 986 | int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id); |
Jacob Keller | 1210243 | 2020-03-26 11:37:15 -0700 | [diff] [blame] | 987 | void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id); |
Jiri Pirko | 3a5e523 | 2019-08-09 15:27:15 +0200 | [diff] [blame] | 988 | int devlink_region_snapshot_create(struct devlink_region *region, |
Jacob Keller | a0a09f6 | 2020-03-26 11:37:09 -0700 | [diff] [blame] | 989 | u8 *data, u32 snapshot_id); |
Jakub Kicinski | f9cf228 | 2019-01-31 10:50:40 -0800 | [diff] [blame] | 990 | int devlink_info_serial_number_put(struct devlink_info_req *req, |
| 991 | const char *sn); |
| 992 | int devlink_info_driver_name_put(struct devlink_info_req *req, |
| 993 | const char *name); |
Jakub Kicinski | fc6fae7 | 2019-01-31 10:50:41 -0800 | [diff] [blame] | 994 | int devlink_info_version_fixed_put(struct devlink_info_req *req, |
| 995 | const char *version_name, |
| 996 | const char *version_value); |
| 997 | int devlink_info_version_stored_put(struct devlink_info_req *req, |
| 998 | const char *version_name, |
| 999 | const char *version_value); |
| 1000 | int devlink_info_version_running_put(struct devlink_info_req *req, |
| 1001 | const char *version_name, |
| 1002 | const char *version_value); |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 1003 | |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 1004 | int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg); |
| 1005 | int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg); |
| 1006 | |
| 1007 | int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name); |
| 1008 | int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg); |
| 1009 | |
| 1010 | int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg, |
| 1011 | const char *name); |
| 1012 | int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg); |
Aya Levin | 573ed90 | 2020-02-11 14:32:42 -0800 | [diff] [blame] | 1013 | int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg, |
| 1014 | const char *name); |
| 1015 | int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg); |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 1016 | |
| 1017 | int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value); |
| 1018 | int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value); |
| 1019 | int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value); |
| 1020 | int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value); |
| 1021 | int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value); |
Aya Levin | 573ed90 | 2020-02-11 14:32:42 -0800 | [diff] [blame] | 1022 | int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value, |
| 1023 | u16 value_len); |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 1024 | |
| 1025 | int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name, |
| 1026 | bool value); |
| 1027 | int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name, |
| 1028 | u8 value); |
| 1029 | int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name, |
| 1030 | u32 value); |
| 1031 | int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name, |
| 1032 | u64 value); |
| 1033 | int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name, |
| 1034 | const char *value); |
| 1035 | int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, |
Aya Levin | e2cde86 | 2019-11-12 14:07:49 +0200 | [diff] [blame] | 1036 | const void *value, u32 value_len); |
Eran Ben Elisha | 1db64e8 | 2019-02-07 11:36:32 +0200 | [diff] [blame] | 1037 | |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 1038 | struct devlink_health_reporter * |
| 1039 | devlink_health_reporter_create(struct devlink *devlink, |
| 1040 | const struct devlink_health_reporter_ops *ops, |
| 1041 | u64 graceful_period, bool auto_recover, |
| 1042 | void *priv); |
| 1043 | void |
| 1044 | devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); |
| 1045 | |
| 1046 | void * |
| 1047 | devlink_health_reporter_priv(struct devlink_health_reporter *reporter); |
Eran Ben Elisha | c8e1da0 | 2019-02-07 11:36:34 +0200 | [diff] [blame] | 1048 | int devlink_health_report(struct devlink_health_reporter *reporter, |
| 1049 | const char *msg, void *priv_ctx); |
Eran Ben Elisha | 3167b27 | 2019-03-03 10:57:30 +0200 | [diff] [blame] | 1050 | void |
| 1051 | devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, |
| 1052 | enum devlink_health_reporter_state state); |
Vikas Gupta | 6181e5c | 2020-01-02 21:18:09 +0530 | [diff] [blame] | 1053 | void |
| 1054 | devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter); |
Eran Ben Elisha | a0bdcc5 | 2019-02-07 11:36:33 +0200 | [diff] [blame] | 1055 | |
Jiri Pirko | 2670ac2 | 2019-09-12 10:49:46 +0200 | [diff] [blame] | 1056 | bool devlink_is_reload_failed(const struct devlink *devlink); |
| 1057 | |
Jiri Pirko | 191ed20 | 2019-06-04 15:40:40 +0200 | [diff] [blame] | 1058 | void devlink_flash_update_begin_notify(struct devlink *devlink); |
| 1059 | void devlink_flash_update_end_notify(struct devlink *devlink); |
| 1060 | void devlink_flash_update_status_notify(struct devlink *devlink, |
| 1061 | const char *status_msg, |
| 1062 | const char *component, |
| 1063 | unsigned long done, |
| 1064 | unsigned long total); |
| 1065 | |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 1066 | int devlink_traps_register(struct devlink *devlink, |
| 1067 | const struct devlink_trap *traps, |
| 1068 | size_t traps_count, void *priv); |
| 1069 | void devlink_traps_unregister(struct devlink *devlink, |
| 1070 | const struct devlink_trap *traps, |
| 1071 | size_t traps_count); |
Jiri Pirko | 5a2e106 | 2020-02-25 11:45:21 +0100 | [diff] [blame] | 1072 | void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, |
| 1073 | void *trap_ctx, struct devlink_port *in_devlink_port, |
| 1074 | const struct flow_action_cookie *fa_cookie); |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 1075 | void *devlink_trap_ctx_priv(void *trap_ctx); |
Ido Schimmel | 95ad955 | 2020-03-22 20:48:26 +0200 | [diff] [blame] | 1076 | int devlink_trap_groups_register(struct devlink *devlink, |
| 1077 | const struct devlink_trap_group *groups, |
| 1078 | size_t groups_count); |
| 1079 | void devlink_trap_groups_unregister(struct devlink *devlink, |
| 1080 | const struct devlink_trap_group *groups, |
| 1081 | size_t groups_count); |
Ido Schimmel | 0f420b6 | 2019-08-17 16:28:17 +0300 | [diff] [blame] | 1082 | |
Jiri Pirko | f6b19b3 | 2019-03-24 11:14:38 +0100 | [diff] [blame] | 1083 | #if IS_ENABLED(CONFIG_NET_DEVLINK) |
| 1084 | |
Jakub Kicinski | f4b6bcc | 2019-02-25 19:34:02 -0800 | [diff] [blame] | 1085 | void devlink_compat_running_version(struct net_device *dev, |
| 1086 | char *buf, size_t len); |
| 1087 | int devlink_compat_flash_update(struct net_device *dev, const char *file_name); |
Jiri Pirko | af3836d | 2019-03-28 13:56:37 +0100 | [diff] [blame] | 1088 | int devlink_compat_phys_port_name_get(struct net_device *dev, |
| 1089 | char *name, size_t len); |
Jiri Pirko | 7e1146e | 2019-04-03 14:24:17 +0200 | [diff] [blame] | 1090 | int devlink_compat_switch_id_get(struct net_device *dev, |
| 1091 | struct netdev_phys_item_id *ppid); |
Jakub Kicinski | f4b6bcc | 2019-02-25 19:34:02 -0800 | [diff] [blame] | 1092 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 1093 | #else |
| 1094 | |
Eran Ben Elisha | 3167b27 | 2019-03-03 10:57:30 +0200 | [diff] [blame] | 1095 | static inline void |
Jakub Kicinski | ddb6e99 | 2019-01-31 10:50:47 -0800 | [diff] [blame] | 1096 | devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) |
| 1097 | { |
| 1098 | } |
Jakub Kicinski | 4eceba1 | 2019-02-14 13:40:45 -0800 | [diff] [blame] | 1099 | |
| 1100 | static inline int |
| 1101 | devlink_compat_flash_update(struct net_device *dev, const char *file_name) |
| 1102 | { |
| 1103 | return -EOPNOTSUPP; |
| 1104 | } |
Jiri Pirko | f6b19b3 | 2019-03-24 11:14:38 +0100 | [diff] [blame] | 1105 | |
Jiri Pirko | af3836d | 2019-03-28 13:56:37 +0100 | [diff] [blame] | 1106 | static inline int |
| 1107 | devlink_compat_phys_port_name_get(struct net_device *dev, |
| 1108 | char *name, size_t len) |
| 1109 | { |
| 1110 | return -EOPNOTSUPP; |
| 1111 | } |
| 1112 | |
Jiri Pirko | 7e1146e | 2019-04-03 14:24:17 +0200 | [diff] [blame] | 1113 | static inline int |
| 1114 | devlink_compat_switch_id_get(struct net_device *dev, |
| 1115 | struct netdev_phys_item_id *ppid) |
| 1116 | { |
| 1117 | return -EOPNOTSUPP; |
| 1118 | } |
| 1119 | |
Jakub Kicinski | ddb6e99 | 2019-01-31 10:50:47 -0800 | [diff] [blame] | 1120 | #endif |
| 1121 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 1122 | #endif /* _NET_DEVLINK_H_ */ |