Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/net/devlink.h - Network physical device Netlink interface |
| 3 | * Copyright (c) 2016 Mellanox Technologies. All rights reserved. |
| 4 | * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | #ifndef _NET_DEVLINK_H_ |
| 12 | #define _NET_DEVLINK_H_ |
| 13 | |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/gfp.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/netdevice.h> |
| 19 | #include <net/net_namespace.h> |
| 20 | #include <uapi/linux/devlink.h> |
| 21 | |
| 22 | struct devlink_ops; |
| 23 | |
| 24 | struct devlink { |
| 25 | struct list_head list; |
| 26 | struct list_head port_list; |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 27 | struct list_head sb_list; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 28 | struct list_head dpipe_table_list; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 29 | struct list_head resource_list; |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 30 | struct list_head param_list; |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 31 | struct list_head region_list; |
Alex Vesker | ccadfa4 | 2018-07-12 15:13:09 +0300 | [diff] [blame^] | 32 | u32 snapshot_id; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 33 | struct devlink_dpipe_headers *dpipe_headers; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 34 | const struct devlink_ops *ops; |
| 35 | struct device *dev; |
| 36 | possible_net_t _net; |
Arkadi Sharshevsky | 2406e7e | 2018-01-15 08:59:02 +0100 | [diff] [blame] | 37 | struct mutex lock; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 38 | char priv[0] __aligned(NETDEV_ALIGN); |
| 39 | }; |
| 40 | |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 41 | struct devlink_port_attrs { |
| 42 | bool set; |
Jiri Pirko | 5ec1380 | 2018-05-18 09:29:01 +0200 | [diff] [blame] | 43 | enum devlink_port_flavour flavour; |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 44 | u32 port_number; /* same value as "split group" */ |
| 45 | bool split; |
| 46 | u32 split_subport_number; |
| 47 | }; |
| 48 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 49 | struct devlink_port { |
| 50 | struct list_head list; |
| 51 | struct devlink *devlink; |
| 52 | unsigned index; |
| 53 | bool registered; |
| 54 | enum devlink_port_type type; |
| 55 | enum devlink_port_type desired_type; |
| 56 | void *type_dev; |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 57 | struct devlink_port_attrs attrs; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 60 | struct devlink_sb_pool_info { |
| 61 | enum devlink_sb_pool_type pool_type; |
| 62 | u32 size; |
| 63 | enum devlink_sb_threshold_type threshold_type; |
| 64 | }; |
| 65 | |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 66 | /** |
| 67 | * struct devlink_dpipe_field - dpipe field object |
| 68 | * @name: field name |
| 69 | * @id: index inside the headers field array |
| 70 | * @bitwidth: bitwidth |
| 71 | * @mapping_type: mapping type |
| 72 | */ |
| 73 | struct devlink_dpipe_field { |
| 74 | const char *name; |
| 75 | unsigned int id; |
| 76 | unsigned int bitwidth; |
| 77 | enum devlink_dpipe_field_mapping_type mapping_type; |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * struct devlink_dpipe_header - dpipe header object |
| 82 | * @name: header name |
| 83 | * @id: index, global/local detrmined by global bit |
| 84 | * @fields: fields |
| 85 | * @fields_count: number of fields |
| 86 | * @global: indicates if header is shared like most protocol header |
| 87 | * or driver specific |
| 88 | */ |
| 89 | struct devlink_dpipe_header { |
| 90 | const char *name; |
| 91 | unsigned int id; |
| 92 | struct devlink_dpipe_field *fields; |
| 93 | unsigned int fields_count; |
| 94 | bool global; |
| 95 | }; |
| 96 | |
| 97 | /** |
| 98 | * struct devlink_dpipe_match - represents match operation |
| 99 | * @type: type of match |
| 100 | * @header_index: header index (packets can have several headers of same |
| 101 | * type like in case of tunnels) |
| 102 | * @header: header |
| 103 | * @fieled_id: field index |
| 104 | */ |
| 105 | struct devlink_dpipe_match { |
| 106 | enum devlink_dpipe_match_type type; |
| 107 | unsigned int header_index; |
| 108 | struct devlink_dpipe_header *header; |
| 109 | unsigned int field_id; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * struct devlink_dpipe_action - represents action operation |
| 114 | * @type: type of action |
| 115 | * @header_index: header index (packets can have several headers of same |
| 116 | * type like in case of tunnels) |
| 117 | * @header: header |
| 118 | * @fieled_id: field index |
| 119 | */ |
| 120 | struct devlink_dpipe_action { |
| 121 | enum devlink_dpipe_action_type type; |
| 122 | unsigned int header_index; |
| 123 | struct devlink_dpipe_header *header; |
| 124 | unsigned int field_id; |
| 125 | }; |
| 126 | |
| 127 | /** |
| 128 | * struct devlink_dpipe_value - represents value of match/action |
| 129 | * @action: action |
| 130 | * @match: match |
| 131 | * @mapping_value: in case the field has some mapping this value |
| 132 | * specified the mapping value |
| 133 | * @mapping_valid: specify if mapping value is valid |
| 134 | * @value_size: value size |
| 135 | * @value: value |
| 136 | * @mask: bit mask |
| 137 | */ |
| 138 | struct devlink_dpipe_value { |
| 139 | union { |
| 140 | struct devlink_dpipe_action *action; |
| 141 | struct devlink_dpipe_match *match; |
| 142 | }; |
| 143 | unsigned int mapping_value; |
| 144 | bool mapping_valid; |
| 145 | unsigned int value_size; |
| 146 | void *value; |
| 147 | void *mask; |
| 148 | }; |
| 149 | |
| 150 | /** |
| 151 | * struct devlink_dpipe_entry - table entry object |
| 152 | * @index: index of the entry in the table |
| 153 | * @match_values: match values |
| 154 | * @matche_values_count: count of matches tuples |
| 155 | * @action_values: actions values |
| 156 | * @action_values_count: count of actions values |
| 157 | * @counter: value of counter |
| 158 | * @counter_valid: Specify if value is valid from hardware |
| 159 | */ |
| 160 | struct devlink_dpipe_entry { |
| 161 | u64 index; |
| 162 | struct devlink_dpipe_value *match_values; |
| 163 | unsigned int match_values_count; |
| 164 | struct devlink_dpipe_value *action_values; |
| 165 | unsigned int action_values_count; |
| 166 | u64 counter; |
| 167 | bool counter_valid; |
| 168 | }; |
| 169 | |
| 170 | /** |
| 171 | * struct devlink_dpipe_dump_ctx - context provided to driver in order |
| 172 | * to dump |
| 173 | * @info: info |
| 174 | * @cmd: devlink command |
| 175 | * @skb: skb |
| 176 | * @nest: top attribute |
| 177 | * @hdr: hdr |
| 178 | */ |
| 179 | struct devlink_dpipe_dump_ctx { |
| 180 | struct genl_info *info; |
| 181 | enum devlink_command cmd; |
| 182 | struct sk_buff *skb; |
| 183 | struct nlattr *nest; |
| 184 | void *hdr; |
| 185 | }; |
| 186 | |
| 187 | struct devlink_dpipe_table_ops; |
| 188 | |
| 189 | /** |
| 190 | * struct devlink_dpipe_table - table object |
| 191 | * @priv: private |
| 192 | * @name: table name |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 193 | * @counters_enabled: indicates if counters are active |
| 194 | * @counter_control_extern: indicates if counter control is in dpipe or |
| 195 | * external tool |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 196 | * @resource_valid: Indicate that the resource id is valid |
| 197 | * @resource_id: relative resource this table is related to |
| 198 | * @resource_units: number of resource's unit consumed per table's entry |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 199 | * @table_ops: table operations |
| 200 | * @rcu: rcu |
| 201 | */ |
| 202 | struct devlink_dpipe_table { |
| 203 | void *priv; |
| 204 | struct list_head list; |
| 205 | const char *name; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 206 | bool counters_enabled; |
| 207 | bool counter_control_extern; |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 208 | bool resource_valid; |
| 209 | u64 resource_id; |
| 210 | u64 resource_units; |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 211 | struct devlink_dpipe_table_ops *table_ops; |
| 212 | struct rcu_head rcu; |
| 213 | }; |
| 214 | |
| 215 | /** |
| 216 | * struct devlink_dpipe_table_ops - dpipe_table ops |
| 217 | * @actions_dump - dumps all tables actions |
| 218 | * @matches_dump - dumps all tables matches |
| 219 | * @entries_dump - dumps all active entries in the table |
| 220 | * @counters_set_update - when changing the counter status hardware sync |
| 221 | * maybe needed to allocate/free counter related |
| 222 | * resources |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 223 | * @size_get - get size |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 224 | */ |
| 225 | struct devlink_dpipe_table_ops { |
| 226 | int (*actions_dump)(void *priv, struct sk_buff *skb); |
| 227 | int (*matches_dump)(void *priv, struct sk_buff *skb); |
| 228 | int (*entries_dump)(void *priv, bool counters_enabled, |
| 229 | struct devlink_dpipe_dump_ctx *dump_ctx); |
| 230 | int (*counters_set_update)(void *priv, bool enable); |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 231 | u64 (*size_get)(void *priv); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | /** |
| 235 | * struct devlink_dpipe_headers - dpipe headers |
| 236 | * @headers - header array can be shared (global bit) or driver specific |
| 237 | * @headers_count - count of headers |
| 238 | */ |
| 239 | struct devlink_dpipe_headers { |
| 240 | struct devlink_dpipe_header **headers; |
| 241 | unsigned int headers_count; |
| 242 | }; |
| 243 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 244 | /** |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 245 | * struct devlink_resource_size_params - resource's size parameters |
| 246 | * @size_min: minimum size which can be set |
| 247 | * @size_max: maximum size which can be set |
| 248 | * @size_granularity: size granularity |
| 249 | * @size_unit: resource's basic unit |
| 250 | */ |
| 251 | struct devlink_resource_size_params { |
| 252 | u64 size_min; |
| 253 | u64 size_max; |
| 254 | u64 size_granularity; |
| 255 | enum devlink_resource_unit unit; |
| 256 | }; |
| 257 | |
Jiri Pirko | 77d2709 | 2018-02-28 13:12:09 +0100 | [diff] [blame] | 258 | static inline void |
| 259 | devlink_resource_size_params_init(struct devlink_resource_size_params *size_params, |
| 260 | u64 size_min, u64 size_max, |
| 261 | u64 size_granularity, |
| 262 | enum devlink_resource_unit unit) |
| 263 | { |
| 264 | size_params->size_min = size_min; |
| 265 | size_params->size_max = size_max; |
| 266 | size_params->size_granularity = size_granularity; |
| 267 | size_params->unit = unit; |
| 268 | } |
| 269 | |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 270 | typedef u64 devlink_resource_occ_get_t(void *priv); |
| 271 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 272 | /** |
| 273 | * struct devlink_resource - devlink resource |
| 274 | * @name: name of the resource |
| 275 | * @id: id, per devlink instance |
| 276 | * @size: size of the resource |
| 277 | * @size_new: updated size of the resource, reload is needed |
| 278 | * @size_valid: valid in case the total size of the resource is valid |
| 279 | * including its children |
| 280 | * @parent: parent resource |
| 281 | * @size_params: size parameters |
| 282 | * @list: parent list |
| 283 | * @resource_list: list of child resources |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 284 | */ |
| 285 | struct devlink_resource { |
| 286 | const char *name; |
| 287 | u64 id; |
| 288 | u64 size; |
| 289 | u64 size_new; |
| 290 | bool size_valid; |
| 291 | struct devlink_resource *parent; |
Jiri Pirko | 77d2709 | 2018-02-28 13:12:09 +0100 | [diff] [blame] | 292 | struct devlink_resource_size_params size_params; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 293 | struct list_head list; |
| 294 | struct list_head resource_list; |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 295 | devlink_resource_occ_get_t *occ_get; |
| 296 | void *occ_get_priv; |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 |
| 300 | |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 301 | #define DEVLINK_PARAM_MAX_STRING_VALUE 32 |
| 302 | enum devlink_param_type { |
| 303 | DEVLINK_PARAM_TYPE_U8, |
| 304 | DEVLINK_PARAM_TYPE_U16, |
| 305 | DEVLINK_PARAM_TYPE_U32, |
| 306 | DEVLINK_PARAM_TYPE_STRING, |
| 307 | DEVLINK_PARAM_TYPE_BOOL, |
| 308 | }; |
| 309 | |
| 310 | union devlink_param_value { |
| 311 | u8 vu8; |
| 312 | u16 vu16; |
| 313 | u32 vu32; |
| 314 | const char *vstr; |
| 315 | bool vbool; |
| 316 | }; |
| 317 | |
| 318 | struct devlink_param_gset_ctx { |
| 319 | union devlink_param_value val; |
| 320 | enum devlink_param_cmode cmode; |
| 321 | }; |
| 322 | |
| 323 | /** |
| 324 | * struct devlink_param - devlink configuration parameter data |
| 325 | * @name: name of the parameter |
| 326 | * @generic: indicates if the parameter is generic or driver specific |
| 327 | * @type: parameter type |
| 328 | * @supported_cmodes: bitmap of supported configuration modes |
| 329 | * @get: get parameter value, used for runtime and permanent |
| 330 | * configuration modes |
| 331 | * @set: set parameter value, used for runtime and permanent |
| 332 | * configuration modes |
Moshe Shemesh | e3b7ca1 | 2018-07-04 14:30:30 +0300 | [diff] [blame] | 333 | * @validate: validate input value is applicable (within value range, etc.) |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 334 | * |
| 335 | * This struct should be used by the driver to fill the data for |
| 336 | * a parameter it registers. |
| 337 | */ |
| 338 | struct devlink_param { |
| 339 | u32 id; |
| 340 | const char *name; |
| 341 | bool generic; |
| 342 | enum devlink_param_type type; |
| 343 | unsigned long supported_cmodes; |
| 344 | int (*get)(struct devlink *devlink, u32 id, |
| 345 | struct devlink_param_gset_ctx *ctx); |
| 346 | int (*set)(struct devlink *devlink, u32 id, |
| 347 | struct devlink_param_gset_ctx *ctx); |
Moshe Shemesh | e3b7ca1 | 2018-07-04 14:30:30 +0300 | [diff] [blame] | 348 | int (*validate)(struct devlink *devlink, u32 id, |
| 349 | union devlink_param_value val, |
| 350 | struct netlink_ext_ack *extack); |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | struct devlink_param_item { |
| 354 | struct list_head list; |
| 355 | const struct devlink_param *param; |
| 356 | union devlink_param_value driverinit_value; |
| 357 | bool driverinit_value_valid; |
| 358 | }; |
| 359 | |
| 360 | enum devlink_param_generic_id { |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 361 | DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET, |
| 362 | DEVLINK_PARAM_GENERIC_ID_MAX_MACS, |
Vasundhara Volam | f567bcd | 2018-07-04 14:30:36 +0300 | [diff] [blame] | 363 | DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 364 | |
| 365 | /* add new param generic ids above here*/ |
| 366 | __DEVLINK_PARAM_GENERIC_ID_MAX, |
| 367 | DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1, |
| 368 | }; |
| 369 | |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 370 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset" |
| 371 | #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 372 | |
| 373 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs" |
| 374 | #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32 |
| 375 | |
Vasundhara Volam | f567bcd | 2018-07-04 14:30:36 +0300 | [diff] [blame] | 376 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov" |
| 377 | #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL |
| 378 | |
Moshe Shemesh | 036467c | 2018-07-04 14:30:33 +0300 | [diff] [blame] | 379 | #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ |
| 380 | { \ |
| 381 | .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ |
| 382 | .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \ |
| 383 | .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \ |
| 384 | .generic = true, \ |
| 385 | .supported_cmodes = _cmodes, \ |
| 386 | .get = _get, \ |
| 387 | .set = _set, \ |
| 388 | .validate = _validate, \ |
| 389 | } |
| 390 | |
| 391 | #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \ |
| 392 | { \ |
| 393 | .id = _id, \ |
| 394 | .name = _name, \ |
| 395 | .type = _type, \ |
| 396 | .supported_cmodes = _cmodes, \ |
| 397 | .get = _get, \ |
| 398 | .set = _set, \ |
| 399 | .validate = _validate, \ |
| 400 | } |
| 401 | |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 402 | struct devlink_region; |
| 403 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 404 | struct devlink_ops { |
David Ahern | ac0fc8a | 2018-06-05 08:14:09 -0700 | [diff] [blame] | 405 | int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 406 | int (*port_type_set)(struct devlink_port *devlink_port, |
| 407 | enum devlink_port_type port_type); |
| 408 | int (*port_split)(struct devlink *devlink, unsigned int port_index, |
David Ahern | ac0fc8a | 2018-06-05 08:14:09 -0700 | [diff] [blame] | 409 | unsigned int count, struct netlink_ext_ack *extack); |
| 410 | int (*port_unsplit)(struct devlink *devlink, unsigned int port_index, |
| 411 | struct netlink_ext_ack *extack); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 412 | int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index, |
| 413 | u16 pool_index, |
| 414 | struct devlink_sb_pool_info *pool_info); |
| 415 | int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index, |
| 416 | u16 pool_index, u32 size, |
| 417 | enum devlink_sb_threshold_type threshold_type); |
| 418 | int (*sb_port_pool_get)(struct devlink_port *devlink_port, |
| 419 | unsigned int sb_index, u16 pool_index, |
| 420 | u32 *p_threshold); |
| 421 | int (*sb_port_pool_set)(struct devlink_port *devlink_port, |
| 422 | unsigned int sb_index, u16 pool_index, |
| 423 | u32 threshold); |
| 424 | int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port, |
| 425 | unsigned int sb_index, |
| 426 | u16 tc_index, |
| 427 | enum devlink_sb_pool_type pool_type, |
| 428 | u16 *p_pool_index, u32 *p_threshold); |
| 429 | int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port, |
| 430 | unsigned int sb_index, |
| 431 | u16 tc_index, |
| 432 | enum devlink_sb_pool_type pool_type, |
| 433 | u16 pool_index, u32 threshold); |
Jiri Pirko | df38daf | 2016-04-14 18:19:14 +0200 | [diff] [blame] | 434 | int (*sb_occ_snapshot)(struct devlink *devlink, |
| 435 | unsigned int sb_index); |
| 436 | int (*sb_occ_max_clear)(struct devlink *devlink, |
| 437 | unsigned int sb_index); |
| 438 | int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port, |
| 439 | unsigned int sb_index, u16 pool_index, |
| 440 | u32 *p_cur, u32 *p_max); |
| 441 | int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port, |
| 442 | unsigned int sb_index, |
| 443 | u16 tc_index, |
| 444 | enum devlink_sb_pool_type pool_type, |
| 445 | u32 *p_cur, u32 *p_max); |
Or Gerlitz | 08f4b59 | 2016-07-01 14:51:01 +0300 | [diff] [blame] | 446 | |
| 447 | int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode); |
| 448 | int (*eswitch_mode_set)(struct devlink *devlink, u16 mode); |
Roi Dayan | 59bfde0 | 2016-11-22 23:09:57 +0200 | [diff] [blame] | 449 | int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode); |
| 450 | int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode); |
Roi Dayan | f43e9b0 | 2016-09-25 13:52:44 +0300 | [diff] [blame] | 451 | int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode); |
| 452 | int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode); |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 453 | }; |
| 454 | |
| 455 | static inline void *devlink_priv(struct devlink *devlink) |
| 456 | { |
| 457 | BUG_ON(!devlink); |
| 458 | return &devlink->priv; |
| 459 | } |
| 460 | |
| 461 | static inline struct devlink *priv_to_devlink(void *priv) |
| 462 | { |
| 463 | BUG_ON(!priv); |
| 464 | return container_of(priv, struct devlink, priv); |
| 465 | } |
| 466 | |
| 467 | struct ib_device; |
| 468 | |
| 469 | #if IS_ENABLED(CONFIG_NET_DEVLINK) |
| 470 | |
| 471 | struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size); |
| 472 | int devlink_register(struct devlink *devlink, struct device *dev); |
| 473 | void devlink_unregister(struct devlink *devlink); |
| 474 | void devlink_free(struct devlink *devlink); |
| 475 | int devlink_port_register(struct devlink *devlink, |
| 476 | struct devlink_port *devlink_port, |
| 477 | unsigned int port_index); |
| 478 | void devlink_port_unregister(struct devlink_port *devlink_port); |
| 479 | void devlink_port_type_eth_set(struct devlink_port *devlink_port, |
| 480 | struct net_device *netdev); |
| 481 | void devlink_port_type_ib_set(struct devlink_port *devlink_port, |
| 482 | struct ib_device *ibdev); |
| 483 | void devlink_port_type_clear(struct devlink_port *devlink_port); |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 484 | void devlink_port_attrs_set(struct devlink_port *devlink_port, |
Jiri Pirko | 5ec1380 | 2018-05-18 09:29:01 +0200 | [diff] [blame] | 485 | enum devlink_port_flavour flavour, |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 486 | u32 port_number, bool split, |
| 487 | u32 split_subport_number); |
Jiri Pirko | 08474c1 | 2018-05-18 09:29:02 +0200 | [diff] [blame] | 488 | int devlink_port_get_phys_port_name(struct devlink_port *devlink_port, |
| 489 | char *name, size_t len); |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 490 | int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, |
| 491 | u32 size, u16 ingress_pools_count, |
| 492 | u16 egress_pools_count, u16 ingress_tc_count, |
| 493 | u16 egress_tc_count); |
| 494 | void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 495 | int devlink_dpipe_table_register(struct devlink *devlink, |
| 496 | const char *table_name, |
| 497 | struct devlink_dpipe_table_ops *table_ops, |
Arkadi Sharshevsky | ffd3cdc | 2017-08-24 08:40:02 +0200 | [diff] [blame] | 498 | void *priv, bool counter_control_extern); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 499 | void devlink_dpipe_table_unregister(struct devlink *devlink, |
| 500 | const char *table_name); |
| 501 | int devlink_dpipe_headers_register(struct devlink *devlink, |
| 502 | struct devlink_dpipe_headers *dpipe_headers); |
| 503 | void devlink_dpipe_headers_unregister(struct devlink *devlink); |
| 504 | bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, |
| 505 | const char *table_name); |
| 506 | int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx); |
| 507 | int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, |
| 508 | struct devlink_dpipe_entry *entry); |
| 509 | 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] | 510 | void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry); |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 511 | int devlink_dpipe_action_put(struct sk_buff *skb, |
| 512 | struct devlink_dpipe_action *action); |
| 513 | int devlink_dpipe_match_put(struct sk_buff *skb, |
| 514 | struct devlink_dpipe_match *match); |
Arkadi Sharshevsky | 1177009 | 2017-08-24 08:39:59 +0200 | [diff] [blame] | 515 | extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; |
Arkadi Sharshevsky | 3fb886e | 2017-08-24 08:40:00 +0200 | [diff] [blame] | 516 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; |
Arkadi Sharshevsky | 1797f5b | 2017-08-31 17:59:12 +0200 | [diff] [blame] | 517 | extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 518 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 519 | int devlink_resource_register(struct devlink *devlink, |
| 520 | const char *resource_name, |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 521 | u64 resource_size, |
| 522 | u64 resource_id, |
| 523 | u64 parent_resource_id, |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 524 | const struct devlink_resource_size_params *size_params); |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 525 | void devlink_resources_unregister(struct devlink *devlink, |
| 526 | struct devlink_resource *resource); |
| 527 | int devlink_resource_size_get(struct devlink *devlink, |
| 528 | u64 resource_id, |
| 529 | u64 *p_resource_size); |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 530 | int devlink_dpipe_table_resource_set(struct devlink *devlink, |
| 531 | const char *table_name, u64 resource_id, |
| 532 | u64 resource_units); |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 533 | void devlink_resource_occ_get_register(struct devlink *devlink, |
| 534 | u64 resource_id, |
| 535 | devlink_resource_occ_get_t *occ_get, |
| 536 | void *occ_get_priv); |
| 537 | void devlink_resource_occ_get_unregister(struct devlink *devlink, |
| 538 | u64 resource_id); |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 539 | int devlink_params_register(struct devlink *devlink, |
| 540 | const struct devlink_param *params, |
| 541 | size_t params_count); |
| 542 | void devlink_params_unregister(struct devlink *devlink, |
| 543 | const struct devlink_param *params, |
| 544 | size_t params_count); |
Moshe Shemesh | ec01aeb | 2018-07-04 14:30:31 +0300 | [diff] [blame] | 545 | int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, |
| 546 | union devlink_param_value *init_val); |
| 547 | int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, |
| 548 | union devlink_param_value init_val); |
Moshe Shemesh | ea601e1 | 2018-07-04 14:30:32 +0300 | [diff] [blame] | 549 | void devlink_param_value_changed(struct devlink *devlink, u32 param_id); |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 550 | struct devlink_region *devlink_region_create(struct devlink *devlink, |
| 551 | const char *region_name, |
| 552 | u32 region_max_snapshots, |
| 553 | u64 region_size); |
| 554 | void devlink_region_destroy(struct devlink_region *region); |
Alex Vesker | ccadfa4 | 2018-07-12 15:13:09 +0300 | [diff] [blame^] | 555 | u32 devlink_region_shapshot_id_get(struct devlink *devlink); |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 556 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 557 | #else |
| 558 | |
| 559 | static inline struct devlink *devlink_alloc(const struct devlink_ops *ops, |
| 560 | size_t priv_size) |
| 561 | { |
| 562 | return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL); |
| 563 | } |
| 564 | |
| 565 | static inline int devlink_register(struct devlink *devlink, struct device *dev) |
| 566 | { |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static inline void devlink_unregister(struct devlink *devlink) |
| 571 | { |
| 572 | } |
| 573 | |
| 574 | static inline void devlink_free(struct devlink *devlink) |
| 575 | { |
| 576 | kfree(devlink); |
| 577 | } |
| 578 | |
| 579 | static inline int devlink_port_register(struct devlink *devlink, |
| 580 | struct devlink_port *devlink_port, |
| 581 | unsigned int port_index) |
| 582 | { |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static inline void devlink_port_unregister(struct devlink_port *devlink_port) |
| 587 | { |
| 588 | } |
| 589 | |
| 590 | static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port, |
| 591 | struct net_device *netdev) |
| 592 | { |
| 593 | } |
| 594 | |
| 595 | static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port, |
| 596 | struct ib_device *ibdev) |
| 597 | { |
| 598 | } |
| 599 | |
| 600 | static inline void devlink_port_type_clear(struct devlink_port *devlink_port) |
| 601 | { |
| 602 | } |
| 603 | |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 604 | static inline void devlink_port_attrs_set(struct devlink_port *devlink_port, |
Jiri Pirko | 5ec1380 | 2018-05-18 09:29:01 +0200 | [diff] [blame] | 605 | enum devlink_port_flavour flavour, |
Jiri Pirko | b9ffcba | 2018-05-18 09:29:00 +0200 | [diff] [blame] | 606 | u32 port_number, bool split, |
| 607 | u32 split_subport_number) |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 608 | { |
| 609 | } |
| 610 | |
Jiri Pirko | 08474c1 | 2018-05-18 09:29:02 +0200 | [diff] [blame] | 611 | static inline int |
| 612 | devlink_port_get_phys_port_name(struct devlink_port *devlink_port, |
| 613 | char *name, size_t len) |
| 614 | { |
| 615 | return -EOPNOTSUPP; |
| 616 | } |
| 617 | |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 618 | static inline int devlink_sb_register(struct devlink *devlink, |
| 619 | unsigned int sb_index, u32 size, |
| 620 | u16 ingress_pools_count, |
Jiri Pirko | de33efd | 2016-04-15 09:17:08 +0200 | [diff] [blame] | 621 | u16 egress_pools_count, |
| 622 | u16 ingress_tc_count, |
| 623 | u16 egress_tc_count) |
Jiri Pirko | bf79747 | 2016-04-14 18:19:13 +0200 | [diff] [blame] | 624 | { |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static inline void devlink_sb_unregister(struct devlink *devlink, |
| 629 | unsigned int sb_index) |
| 630 | { |
| 631 | } |
| 632 | |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 633 | static inline int |
| 634 | devlink_dpipe_table_register(struct devlink *devlink, |
| 635 | const char *table_name, |
| 636 | struct devlink_dpipe_table_ops *table_ops, |
David S. Miller | 790c605 | 2017-08-24 18:10:46 -0700 | [diff] [blame] | 637 | void *priv, bool counter_control_extern) |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 638 | { |
| 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static inline void devlink_dpipe_table_unregister(struct devlink *devlink, |
| 643 | const char *table_name) |
| 644 | { |
| 645 | } |
| 646 | |
| 647 | static inline int devlink_dpipe_headers_register(struct devlink *devlink, |
| 648 | struct devlink_dpipe_headers * |
| 649 | dpipe_headers) |
| 650 | { |
| 651 | return 0; |
| 652 | } |
| 653 | |
| 654 | static inline void devlink_dpipe_headers_unregister(struct devlink *devlink) |
| 655 | { |
| 656 | } |
| 657 | |
| 658 | static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, |
| 659 | const char *table_name) |
| 660 | { |
| 661 | return false; |
| 662 | } |
| 663 | |
| 664 | static inline int |
| 665 | devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx) |
| 666 | { |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static inline int |
| 671 | devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, |
| 672 | struct devlink_dpipe_entry *entry) |
| 673 | { |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static inline int |
| 678 | devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx) |
| 679 | { |
| 680 | return 0; |
| 681 | } |
| 682 | |
Arkadi Sharshevsky | 3580732 | 2017-08-24 08:40:03 +0200 | [diff] [blame] | 683 | static inline void |
| 684 | devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry) |
| 685 | { |
| 686 | } |
| 687 | |
Arkadi Sharshevsky | 1555d20 | 2017-03-28 17:24:10 +0200 | [diff] [blame] | 688 | static inline int |
| 689 | devlink_dpipe_action_put(struct sk_buff *skb, |
| 690 | struct devlink_dpipe_action *action) |
| 691 | { |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | static inline int |
| 696 | devlink_dpipe_match_put(struct sk_buff *skb, |
| 697 | struct devlink_dpipe_match *match) |
| 698 | { |
| 699 | return 0; |
| 700 | } |
| 701 | |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 702 | static inline int |
| 703 | devlink_resource_register(struct devlink *devlink, |
| 704 | const char *resource_name, |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 705 | u64 resource_size, |
| 706 | u64 resource_id, |
| 707 | u64 parent_resource_id, |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 708 | const struct devlink_resource_size_params *size_params) |
Arkadi Sharshevsky | d9f9b9a | 2018-01-15 08:59:03 +0100 | [diff] [blame] | 709 | { |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static inline void |
| 714 | devlink_resources_unregister(struct devlink *devlink, |
| 715 | struct devlink_resource *resource) |
| 716 | { |
| 717 | } |
| 718 | |
| 719 | static inline int |
| 720 | devlink_resource_size_get(struct devlink *devlink, u64 resource_id, |
| 721 | u64 *p_resource_size) |
| 722 | { |
| 723 | return -EOPNOTSUPP; |
| 724 | } |
| 725 | |
Arkadi Sharshevsky | 56dc7cd | 2018-01-15 08:59:05 +0100 | [diff] [blame] | 726 | static inline int |
| 727 | devlink_dpipe_table_resource_set(struct devlink *devlink, |
| 728 | const char *table_name, u64 resource_id, |
| 729 | u64 resource_units) |
| 730 | { |
| 731 | return -EOPNOTSUPP; |
| 732 | } |
| 733 | |
Jiri Pirko | fc56be4 | 2018-04-05 22:13:21 +0200 | [diff] [blame] | 734 | static inline void |
| 735 | devlink_resource_occ_get_register(struct devlink *devlink, |
| 736 | u64 resource_id, |
| 737 | devlink_resource_occ_get_t *occ_get, |
| 738 | void *occ_get_priv) |
| 739 | { |
| 740 | } |
| 741 | |
| 742 | static inline void |
| 743 | devlink_resource_occ_get_unregister(struct devlink *devlink, |
| 744 | u64 resource_id) |
| 745 | { |
| 746 | } |
| 747 | |
Moshe Shemesh | eabaef1 | 2018-07-04 14:30:28 +0300 | [diff] [blame] | 748 | static inline int |
| 749 | devlink_params_register(struct devlink *devlink, |
| 750 | const struct devlink_param *params, |
| 751 | size_t params_count) |
| 752 | { |
| 753 | return 0; |
| 754 | } |
| 755 | |
| 756 | static inline void |
| 757 | devlink_params_unregister(struct devlink *devlink, |
| 758 | const struct devlink_param *params, |
| 759 | size_t params_count) |
| 760 | { |
| 761 | |
| 762 | } |
| 763 | |
Moshe Shemesh | ec01aeb | 2018-07-04 14:30:31 +0300 | [diff] [blame] | 764 | static inline int |
| 765 | devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, |
| 766 | union devlink_param_value *init_val) |
| 767 | { |
| 768 | return -EOPNOTSUPP; |
| 769 | } |
| 770 | |
| 771 | static inline int |
| 772 | devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, |
| 773 | union devlink_param_value init_val) |
| 774 | { |
| 775 | return -EOPNOTSUPP; |
| 776 | } |
| 777 | |
Moshe Shemesh | ea601e1 | 2018-07-04 14:30:32 +0300 | [diff] [blame] | 778 | static inline void |
| 779 | devlink_param_value_changed(struct devlink *devlink, u32 param_id) |
| 780 | { |
Moshe Shemesh | ea601e1 | 2018-07-04 14:30:32 +0300 | [diff] [blame] | 781 | } |
| 782 | |
Alex Vesker | b16ebe9 | 2018-07-12 15:13:08 +0300 | [diff] [blame] | 783 | static inline struct devlink_region * |
| 784 | devlink_region_create(struct devlink *devlink, |
| 785 | const char *region_name, |
| 786 | u32 region_max_snapshots, |
| 787 | u64 region_size) |
| 788 | { |
| 789 | return NULL; |
| 790 | } |
| 791 | |
| 792 | static inline void |
| 793 | devlink_region_destroy(struct devlink_region *region) |
| 794 | { |
| 795 | } |
| 796 | |
Alex Vesker | ccadfa4 | 2018-07-12 15:13:09 +0300 | [diff] [blame^] | 797 | static inline u32 |
| 798 | devlink_region_shapshot_id_get(struct devlink *devlink) |
| 799 | { |
| 800 | return 0; |
| 801 | } |
| 802 | |
Jiri Pirko | bfcd3a4 | 2016-02-26 17:32:23 +0100 | [diff] [blame] | 803 | #endif |
| 804 | |
| 805 | #endif /* _NET_DEVLINK_H_ */ |