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