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