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