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