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 #include <linux/xarray.h> 22 23 struct devlink_ops; 24 25 struct devlink { 26 struct list_head list; 27 struct list_head port_list; 28 struct list_head sb_list; 29 struct list_head dpipe_table_list; 30 struct list_head resource_list; 31 struct list_head param_list; 32 struct list_head region_list; 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 struct list_head trap_policer_list; 39 const struct devlink_ops *ops; 40 struct xarray snapshot_ids; 41 struct device *dev; 42 possible_net_t _net; 43 struct mutex lock; /* Serializes access to devlink instance specific objects such as 44 * port, sb, dpipe, resource, params, region, traps and more. 45 */ 46 u8 reload_failed:1, 47 reload_enabled:1, 48 registered:1; 49 char priv[0] __aligned(NETDEV_ALIGN); 50 }; 51 52 struct devlink_port_phys_attrs { 53 u32 port_number; /* Same value as "split group". 54 * A physical port which is visible to the user 55 * for a given port flavour. 56 */ 57 u32 split_subport_number; /* If the port is split, this is the number of subport. */ 58 }; 59 60 /** 61 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes 62 * @controller: Associated controller number 63 * @pf: Associated PCI PF number for this port. 64 * @external: when set, indicates if a port is for an external controller 65 */ 66 struct devlink_port_pci_pf_attrs { 67 u32 controller; 68 u16 pf; 69 u8 external:1; 70 }; 71 72 /** 73 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes 74 * @controller: Associated controller number 75 * @pf: Associated PCI PF number for this port. 76 * @vf: Associated PCI VF for of the PCI PF for this port. 77 * @external: when set, indicates if a port is for an external controller 78 */ 79 struct devlink_port_pci_vf_attrs { 80 u32 controller; 81 u16 pf; 82 u16 vf; 83 u8 external:1; 84 }; 85 86 /** 87 * struct devlink_port_attrs - devlink port object 88 * @flavour: flavour of the port 89 * @split: indicates if this is split port 90 * @splittable: indicates if the port can be split. 91 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink. 92 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL 93 * @phys: physical port attributes 94 * @pci_pf: PCI PF port attributes 95 * @pci_vf: PCI VF port attributes 96 */ 97 struct devlink_port_attrs { 98 u8 split:1, 99 splittable:1; 100 u32 lanes; 101 enum devlink_port_flavour flavour; 102 struct netdev_phys_item_id switch_id; 103 union { 104 struct devlink_port_phys_attrs phys; 105 struct devlink_port_pci_pf_attrs pci_pf; 106 struct devlink_port_pci_vf_attrs pci_vf; 107 }; 108 }; 109 110 struct devlink_port { 111 struct list_head list; 112 struct list_head param_list; 113 struct devlink *devlink; 114 unsigned int index; 115 bool registered; 116 spinlock_t type_lock; /* Protects type and type_dev 117 * pointer consistency. 118 */ 119 enum devlink_port_type type; 120 enum devlink_port_type desired_type; 121 void *type_dev; 122 struct devlink_port_attrs attrs; 123 u8 attrs_set:1, 124 switch_port:1; 125 struct delayed_work type_warn_dw; 126 struct list_head reporter_list; 127 struct mutex reporters_lock; /* Protects reporter_list */ 128 }; 129 130 struct devlink_sb_pool_info { 131 enum devlink_sb_pool_type pool_type; 132 u32 size; 133 enum devlink_sb_threshold_type threshold_type; 134 u32 cell_size; 135 }; 136 137 /** 138 * struct devlink_dpipe_field - dpipe field object 139 * @name: field name 140 * @id: index inside the headers field array 141 * @bitwidth: bitwidth 142 * @mapping_type: mapping type 143 */ 144 struct devlink_dpipe_field { 145 const char *name; 146 unsigned int id; 147 unsigned int bitwidth; 148 enum devlink_dpipe_field_mapping_type mapping_type; 149 }; 150 151 /** 152 * struct devlink_dpipe_header - dpipe header object 153 * @name: header name 154 * @id: index, global/local detrmined by global bit 155 * @fields: fields 156 * @fields_count: number of fields 157 * @global: indicates if header is shared like most protocol header 158 * or driver specific 159 */ 160 struct devlink_dpipe_header { 161 const char *name; 162 unsigned int id; 163 struct devlink_dpipe_field *fields; 164 unsigned int fields_count; 165 bool global; 166 }; 167 168 /** 169 * struct devlink_dpipe_match - represents match operation 170 * @type: type of match 171 * @header_index: header index (packets can have several headers of same 172 * type like in case of tunnels) 173 * @header: header 174 * @fieled_id: field index 175 */ 176 struct devlink_dpipe_match { 177 enum devlink_dpipe_match_type type; 178 unsigned int header_index; 179 struct devlink_dpipe_header *header; 180 unsigned int field_id; 181 }; 182 183 /** 184 * struct devlink_dpipe_action - represents action operation 185 * @type: type of action 186 * @header_index: header index (packets can have several headers of same 187 * type like in case of tunnels) 188 * @header: header 189 * @fieled_id: field index 190 */ 191 struct devlink_dpipe_action { 192 enum devlink_dpipe_action_type type; 193 unsigned int header_index; 194 struct devlink_dpipe_header *header; 195 unsigned int field_id; 196 }; 197 198 /** 199 * struct devlink_dpipe_value - represents value of match/action 200 * @action: action 201 * @match: match 202 * @mapping_value: in case the field has some mapping this value 203 * specified the mapping value 204 * @mapping_valid: specify if mapping value is valid 205 * @value_size: value size 206 * @value: value 207 * @mask: bit mask 208 */ 209 struct devlink_dpipe_value { 210 union { 211 struct devlink_dpipe_action *action; 212 struct devlink_dpipe_match *match; 213 }; 214 unsigned int mapping_value; 215 bool mapping_valid; 216 unsigned int value_size; 217 void *value; 218 void *mask; 219 }; 220 221 /** 222 * struct devlink_dpipe_entry - table entry object 223 * @index: index of the entry in the table 224 * @match_values: match values 225 * @matche_values_count: count of matches tuples 226 * @action_values: actions values 227 * @action_values_count: count of actions values 228 * @counter: value of counter 229 * @counter_valid: Specify if value is valid from hardware 230 */ 231 struct devlink_dpipe_entry { 232 u64 index; 233 struct devlink_dpipe_value *match_values; 234 unsigned int match_values_count; 235 struct devlink_dpipe_value *action_values; 236 unsigned int action_values_count; 237 u64 counter; 238 bool counter_valid; 239 }; 240 241 /** 242 * struct devlink_dpipe_dump_ctx - context provided to driver in order 243 * to dump 244 * @info: info 245 * @cmd: devlink command 246 * @skb: skb 247 * @nest: top attribute 248 * @hdr: hdr 249 */ 250 struct devlink_dpipe_dump_ctx { 251 struct genl_info *info; 252 enum devlink_command cmd; 253 struct sk_buff *skb; 254 struct nlattr *nest; 255 void *hdr; 256 }; 257 258 struct devlink_dpipe_table_ops; 259 260 /** 261 * struct devlink_dpipe_table - table object 262 * @priv: private 263 * @name: table name 264 * @counters_enabled: indicates if counters are active 265 * @counter_control_extern: indicates if counter control is in dpipe or 266 * external tool 267 * @resource_valid: Indicate that the resource id is valid 268 * @resource_id: relative resource this table is related to 269 * @resource_units: number of resource's unit consumed per table's entry 270 * @table_ops: table operations 271 * @rcu: rcu 272 */ 273 struct devlink_dpipe_table { 274 void *priv; 275 struct list_head list; 276 const char *name; 277 bool counters_enabled; 278 bool counter_control_extern; 279 bool resource_valid; 280 u64 resource_id; 281 u64 resource_units; 282 struct devlink_dpipe_table_ops *table_ops; 283 struct rcu_head rcu; 284 }; 285 286 /** 287 * struct devlink_dpipe_table_ops - dpipe_table ops 288 * @actions_dump - dumps all tables actions 289 * @matches_dump - dumps all tables matches 290 * @entries_dump - dumps all active entries in the table 291 * @counters_set_update - when changing the counter status hardware sync 292 * maybe needed to allocate/free counter related 293 * resources 294 * @size_get - get size 295 */ 296 struct devlink_dpipe_table_ops { 297 int (*actions_dump)(void *priv, struct sk_buff *skb); 298 int (*matches_dump)(void *priv, struct sk_buff *skb); 299 int (*entries_dump)(void *priv, bool counters_enabled, 300 struct devlink_dpipe_dump_ctx *dump_ctx); 301 int (*counters_set_update)(void *priv, bool enable); 302 u64 (*size_get)(void *priv); 303 }; 304 305 /** 306 * struct devlink_dpipe_headers - dpipe headers 307 * @headers - header array can be shared (global bit) or driver specific 308 * @headers_count - count of headers 309 */ 310 struct devlink_dpipe_headers { 311 struct devlink_dpipe_header **headers; 312 unsigned int headers_count; 313 }; 314 315 /** 316 * struct devlink_resource_size_params - resource's size parameters 317 * @size_min: minimum size which can be set 318 * @size_max: maximum size which can be set 319 * @size_granularity: size granularity 320 * @size_unit: resource's basic unit 321 */ 322 struct devlink_resource_size_params { 323 u64 size_min; 324 u64 size_max; 325 u64 size_granularity; 326 enum devlink_resource_unit unit; 327 }; 328 329 static inline void 330 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params, 331 u64 size_min, u64 size_max, 332 u64 size_granularity, 333 enum devlink_resource_unit unit) 334 { 335 size_params->size_min = size_min; 336 size_params->size_max = size_max; 337 size_params->size_granularity = size_granularity; 338 size_params->unit = unit; 339 } 340 341 typedef u64 devlink_resource_occ_get_t(void *priv); 342 343 /** 344 * struct devlink_resource - devlink resource 345 * @name: name of the resource 346 * @id: id, per devlink instance 347 * @size: size of the resource 348 * @size_new: updated size of the resource, reload is needed 349 * @size_valid: valid in case the total size of the resource is valid 350 * including its children 351 * @parent: parent resource 352 * @size_params: size parameters 353 * @list: parent list 354 * @resource_list: list of child resources 355 */ 356 struct devlink_resource { 357 const char *name; 358 u64 id; 359 u64 size; 360 u64 size_new; 361 bool size_valid; 362 struct devlink_resource *parent; 363 struct devlink_resource_size_params size_params; 364 struct list_head list; 365 struct list_head resource_list; 366 devlink_resource_occ_get_t *occ_get; 367 void *occ_get_priv; 368 }; 369 370 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 371 372 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32 373 enum devlink_param_type { 374 DEVLINK_PARAM_TYPE_U8, 375 DEVLINK_PARAM_TYPE_U16, 376 DEVLINK_PARAM_TYPE_U32, 377 DEVLINK_PARAM_TYPE_STRING, 378 DEVLINK_PARAM_TYPE_BOOL, 379 }; 380 381 union devlink_param_value { 382 u8 vu8; 383 u16 vu16; 384 u32 vu32; 385 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE]; 386 bool vbool; 387 }; 388 389 struct devlink_param_gset_ctx { 390 union devlink_param_value val; 391 enum devlink_param_cmode cmode; 392 }; 393 394 /** 395 * struct devlink_flash_notify - devlink dev flash notify data 396 * @status_msg: current status string 397 * @component: firmware component being updated 398 * @done: amount of work completed of total amount 399 * @total: amount of work expected to be done 400 * @timeout: expected max timeout in seconds 401 * 402 * These are values to be given to userland to be displayed in order 403 * to show current activity in a firmware update process. 404 */ 405 struct devlink_flash_notify { 406 const char *status_msg; 407 const char *component; 408 unsigned long done; 409 unsigned long total; 410 unsigned long timeout; 411 }; 412 413 /** 414 * struct devlink_param - devlink configuration parameter data 415 * @name: name of the parameter 416 * @generic: indicates if the parameter is generic or driver specific 417 * @type: parameter type 418 * @supported_cmodes: bitmap of supported configuration modes 419 * @get: get parameter value, used for runtime and permanent 420 * configuration modes 421 * @set: set parameter value, used for runtime and permanent 422 * configuration modes 423 * @validate: validate input value is applicable (within value range, etc.) 424 * 425 * This struct should be used by the driver to fill the data for 426 * a parameter it registers. 427 */ 428 struct devlink_param { 429 u32 id; 430 const char *name; 431 bool generic; 432 enum devlink_param_type type; 433 unsigned long supported_cmodes; 434 int (*get)(struct devlink *devlink, u32 id, 435 struct devlink_param_gset_ctx *ctx); 436 int (*set)(struct devlink *devlink, u32 id, 437 struct devlink_param_gset_ctx *ctx); 438 int (*validate)(struct devlink *devlink, u32 id, 439 union devlink_param_value val, 440 struct netlink_ext_ack *extack); 441 }; 442 443 struct devlink_param_item { 444 struct list_head list; 445 const struct devlink_param *param; 446 union devlink_param_value driverinit_value; 447 bool driverinit_value_valid; 448 bool published; 449 }; 450 451 enum devlink_param_generic_id { 452 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET, 453 DEVLINK_PARAM_GENERIC_ID_MAX_MACS, 454 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, 455 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT, 456 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, 457 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX, 458 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN, 459 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY, 460 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE, 461 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE, 462 463 /* add new param generic ids above here*/ 464 __DEVLINK_PARAM_GENERIC_ID_MAX, 465 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1, 466 }; 467 468 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset" 469 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL 470 471 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs" 472 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32 473 474 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov" 475 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL 476 477 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable" 478 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL 479 480 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari" 481 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL 482 483 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max" 484 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32 485 486 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min" 487 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32 488 489 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy" 490 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8 491 492 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \ 493 "reset_dev_on_drv_probe" 494 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8 495 496 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce" 497 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL 498 499 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ 500 { \ 501 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ 502 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \ 503 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \ 504 .generic = true, \ 505 .supported_cmodes = _cmodes, \ 506 .get = _get, \ 507 .set = _set, \ 508 .validate = _validate, \ 509 } 510 511 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \ 512 { \ 513 .id = _id, \ 514 .name = _name, \ 515 .type = _type, \ 516 .supported_cmodes = _cmodes, \ 517 .get = _get, \ 518 .set = _set, \ 519 .validate = _validate, \ 520 } 521 522 /* Part number, identifier of board design */ 523 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id" 524 /* Revision of board design */ 525 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev" 526 /* Maker of the board */ 527 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture" 528 529 /* Part number, identifier of asic design */ 530 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id" 531 /* Revision of asic design */ 532 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev" 533 534 /* Overall FW version */ 535 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw" 536 /* Control processor FW version */ 537 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt" 538 /* FW interface specification version */ 539 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api" 540 /* Data path microcode controlling high-speed packet processing */ 541 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app" 542 /* UNDI software version */ 543 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi" 544 /* NCSI support/handler version */ 545 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi" 546 /* FW parameter set id */ 547 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid" 548 /* RoCE FW version */ 549 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce" 550 /* Firmware bundle identifier */ 551 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id" 552 553 /** 554 * struct devlink_flash_update_params - Flash Update parameters 555 * @file_name: the name of the flash firmware file to update from 556 * @component: the flash component to update 557 * 558 * With the exception of file_name, drivers must opt-in to parameters by 559 * setting the appropriate bit in the supported_flash_update_params field in 560 * their devlink_ops structure. 561 */ 562 struct devlink_flash_update_params { 563 const char *file_name; 564 const char *component; 565 u32 overwrite_mask; 566 }; 567 568 #define DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT BIT(0) 569 #define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(1) 570 571 struct devlink_region; 572 struct devlink_info_req; 573 574 /** 575 * struct devlink_region_ops - Region operations 576 * @name: region name 577 * @destructor: callback used to free snapshot memory when deleting 578 * @snapshot: callback to request an immediate snapshot. On success, 579 * the data variable must be updated to point to the snapshot data. 580 * The function will be called while the devlink instance lock is 581 * held. 582 * @priv: Pointer to driver private data for the region operation 583 */ 584 struct devlink_region_ops { 585 const char *name; 586 void (*destructor)(const void *data); 587 int (*snapshot)(struct devlink *devlink, 588 const struct devlink_region_ops *ops, 589 struct netlink_ext_ack *extack, 590 u8 **data); 591 void *priv; 592 }; 593 594 struct devlink_fmsg; 595 struct devlink_health_reporter; 596 597 enum devlink_health_reporter_state { 598 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY, 599 DEVLINK_HEALTH_REPORTER_STATE_ERROR, 600 }; 601 602 /** 603 * struct devlink_health_reporter_ops - Reporter operations 604 * @name: reporter name 605 * @recover: callback to recover from reported error 606 * if priv_ctx is NULL, run a full recover 607 * @dump: callback to dump an object 608 * if priv_ctx is NULL, run a full dump 609 * @diagnose: callback to diagnose the current status 610 * @test: callback to trigger a test event 611 */ 612 613 struct devlink_health_reporter_ops { 614 char *name; 615 int (*recover)(struct devlink_health_reporter *reporter, 616 void *priv_ctx, struct netlink_ext_ack *extack); 617 int (*dump)(struct devlink_health_reporter *reporter, 618 struct devlink_fmsg *fmsg, void *priv_ctx, 619 struct netlink_ext_ack *extack); 620 int (*diagnose)(struct devlink_health_reporter *reporter, 621 struct devlink_fmsg *fmsg, 622 struct netlink_ext_ack *extack); 623 int (*test)(struct devlink_health_reporter *reporter, 624 struct netlink_ext_ack *extack); 625 }; 626 627 /** 628 * struct devlink_trap_policer - Immutable packet trap policer attributes. 629 * @id: Policer identifier. 630 * @init_rate: Initial rate in packets / sec. 631 * @init_burst: Initial burst size in packets. 632 * @max_rate: Maximum rate. 633 * @min_rate: Minimum rate. 634 * @max_burst: Maximum burst size. 635 * @min_burst: Minimum burst size. 636 * 637 * Describes immutable attributes of packet trap policers that drivers register 638 * with devlink. 639 */ 640 struct devlink_trap_policer { 641 u32 id; 642 u64 init_rate; 643 u64 init_burst; 644 u64 max_rate; 645 u64 min_rate; 646 u64 max_burst; 647 u64 min_burst; 648 }; 649 650 /** 651 * struct devlink_trap_group - Immutable packet trap group attributes. 652 * @name: Trap group name. 653 * @id: Trap group identifier. 654 * @generic: Whether the trap group is generic or not. 655 * @init_policer_id: Initial policer identifier. 656 * 657 * Describes immutable attributes of packet trap groups that drivers register 658 * with devlink. 659 */ 660 struct devlink_trap_group { 661 const char *name; 662 u16 id; 663 bool generic; 664 u32 init_policer_id; 665 }; 666 667 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0) 668 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1) 669 670 /** 671 * struct devlink_trap - Immutable packet trap attributes. 672 * @type: Trap type. 673 * @init_action: Initial trap action. 674 * @generic: Whether the trap is generic or not. 675 * @id: Trap identifier. 676 * @name: Trap name. 677 * @init_group_id: Initial group identifier. 678 * @metadata_cap: Metadata types that can be provided by the trap. 679 * 680 * Describes immutable attributes of packet traps that drivers register with 681 * devlink. 682 */ 683 struct devlink_trap { 684 enum devlink_trap_type type; 685 enum devlink_trap_action init_action; 686 bool generic; 687 u16 id; 688 const char *name; 689 u16 init_group_id; 690 u32 metadata_cap; 691 }; 692 693 /* All traps must be documented in 694 * Documentation/networking/devlink/devlink-trap.rst 695 */ 696 enum devlink_trap_generic_id { 697 DEVLINK_TRAP_GENERIC_ID_SMAC_MC, 698 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH, 699 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER, 700 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER, 701 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST, 702 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER, 703 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE, 704 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR, 705 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP, 706 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET, 707 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC, 708 DEVLINK_TRAP_GENERIC_ID_DIP_LB, 709 DEVLINK_TRAP_GENERIC_ID_SIP_MC, 710 DEVLINK_TRAP_GENERIC_ID_SIP_LB, 711 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR, 712 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC, 713 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE, 714 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE, 715 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR, 716 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH, 717 DEVLINK_TRAP_GENERIC_ID_RPF, 718 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE, 719 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS, 720 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS, 721 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE, 722 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR, 723 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC, 724 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP, 725 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP, 726 DEVLINK_TRAP_GENERIC_ID_STP, 727 DEVLINK_TRAP_GENERIC_ID_LACP, 728 DEVLINK_TRAP_GENERIC_ID_LLDP, 729 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY, 730 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT, 731 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT, 732 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT, 733 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE, 734 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY, 735 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT, 736 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT, 737 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE, 738 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP, 739 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP, 740 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST, 741 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE, 742 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY, 743 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT, 744 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT, 745 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD, 746 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD, 747 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF, 748 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF, 749 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP, 750 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP, 751 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP, 752 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP, 753 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM, 754 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM, 755 DEVLINK_TRAP_GENERIC_ID_UC_LB, 756 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE, 757 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE, 758 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE, 759 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES, 760 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS, 761 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT, 762 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT, 763 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT, 764 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT, 765 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT, 766 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT, 767 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL, 768 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE, 769 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP, 770 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP, 771 772 /* Add new generic trap IDs above */ 773 __DEVLINK_TRAP_GENERIC_ID_MAX, 774 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1, 775 }; 776 777 /* All trap groups must be documented in 778 * Documentation/networking/devlink/devlink-trap.rst 779 */ 780 enum devlink_trap_group_generic_id { 781 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS, 782 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS, 783 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS, 784 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS, 785 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS, 786 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS, 787 DEVLINK_TRAP_GROUP_GENERIC_ID_STP, 788 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP, 789 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP, 790 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING, 791 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP, 792 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY, 793 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD, 794 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF, 795 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP, 796 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP, 797 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM, 798 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB, 799 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY, 800 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY, 801 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6, 802 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT, 803 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL, 804 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE, 805 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP, 806 807 /* Add new generic trap group IDs above */ 808 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX, 809 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX = 810 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1, 811 }; 812 813 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \ 814 "source_mac_is_multicast" 815 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \ 816 "vlan_tag_mismatch" 817 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \ 818 "ingress_vlan_filter" 819 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \ 820 "ingress_spanning_tree_filter" 821 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \ 822 "port_list_is_empty" 823 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \ 824 "port_loopback_filter" 825 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \ 826 "blackhole_route" 827 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \ 828 "ttl_value_is_too_small" 829 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \ 830 "tail_drop" 831 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \ 832 "non_ip" 833 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \ 834 "uc_dip_over_mc_dmac" 835 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \ 836 "dip_is_loopback_address" 837 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \ 838 "sip_is_mc" 839 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \ 840 "sip_is_loopback_address" 841 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \ 842 "ip_header_corrupted" 843 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \ 844 "ipv4_sip_is_limited_bc" 845 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \ 846 "ipv6_mc_dip_reserved_scope" 847 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \ 848 "ipv6_mc_dip_interface_local_scope" 849 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \ 850 "mtu_value_is_too_small" 851 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \ 852 "unresolved_neigh" 853 #define DEVLINK_TRAP_GENERIC_NAME_RPF \ 854 "mc_reverse_path_forwarding" 855 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \ 856 "reject_route" 857 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \ 858 "ipv4_lpm_miss" 859 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \ 860 "ipv6_lpm_miss" 861 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \ 862 "non_routable_packet" 863 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \ 864 "decap_error" 865 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \ 866 "overlay_smac_is_mc" 867 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \ 868 "ingress_flow_action_drop" 869 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \ 870 "egress_flow_action_drop" 871 #define DEVLINK_TRAP_GENERIC_NAME_STP \ 872 "stp" 873 #define DEVLINK_TRAP_GENERIC_NAME_LACP \ 874 "lacp" 875 #define DEVLINK_TRAP_GENERIC_NAME_LLDP \ 876 "lldp" 877 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \ 878 "igmp_query" 879 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \ 880 "igmp_v1_report" 881 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \ 882 "igmp_v2_report" 883 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \ 884 "igmp_v3_report" 885 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \ 886 "igmp_v2_leave" 887 #define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \ 888 "mld_query" 889 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \ 890 "mld_v1_report" 891 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \ 892 "mld_v2_report" 893 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \ 894 "mld_v1_done" 895 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \ 896 "ipv4_dhcp" 897 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \ 898 "ipv6_dhcp" 899 #define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \ 900 "arp_request" 901 #define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \ 902 "arp_response" 903 #define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \ 904 "arp_overlay" 905 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \ 906 "ipv6_neigh_solicit" 907 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \ 908 "ipv6_neigh_advert" 909 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \ 910 "ipv4_bfd" 911 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \ 912 "ipv6_bfd" 913 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \ 914 "ipv4_ospf" 915 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \ 916 "ipv6_ospf" 917 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \ 918 "ipv4_bgp" 919 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \ 920 "ipv6_bgp" 921 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \ 922 "ipv4_vrrp" 923 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \ 924 "ipv6_vrrp" 925 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \ 926 "ipv4_pim" 927 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \ 928 "ipv6_pim" 929 #define DEVLINK_TRAP_GENERIC_NAME_UC_LB \ 930 "uc_loopback" 931 #define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \ 932 "local_route" 933 #define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \ 934 "external_route" 935 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \ 936 "ipv6_uc_dip_link_local_scope" 937 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \ 938 "ipv6_dip_all_nodes" 939 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \ 940 "ipv6_dip_all_routers" 941 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \ 942 "ipv6_router_solicit" 943 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \ 944 "ipv6_router_advert" 945 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \ 946 "ipv6_redirect" 947 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \ 948 "ipv4_router_alert" 949 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \ 950 "ipv6_router_alert" 951 #define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \ 952 "ptp_event" 953 #define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \ 954 "ptp_general" 955 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \ 956 "flow_action_sample" 957 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \ 958 "flow_action_trap" 959 #define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \ 960 "early_drop" 961 962 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \ 963 "l2_drops" 964 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \ 965 "l3_drops" 966 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \ 967 "l3_exceptions" 968 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \ 969 "buffer_drops" 970 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \ 971 "tunnel_drops" 972 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \ 973 "acl_drops" 974 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \ 975 "stp" 976 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \ 977 "lacp" 978 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \ 979 "lldp" 980 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \ 981 "mc_snooping" 982 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \ 983 "dhcp" 984 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \ 985 "neigh_discovery" 986 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \ 987 "bfd" 988 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \ 989 "ospf" 990 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \ 991 "bgp" 992 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \ 993 "vrrp" 994 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \ 995 "pim" 996 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \ 997 "uc_loopback" 998 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \ 999 "local_delivery" 1000 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \ 1001 "external_delivery" 1002 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \ 1003 "ipv6" 1004 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \ 1005 "ptp_event" 1006 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \ 1007 "ptp_general" 1008 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \ 1009 "acl_sample" 1010 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \ 1011 "acl_trap" 1012 1013 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \ 1014 _metadata_cap) \ 1015 { \ 1016 .type = DEVLINK_TRAP_TYPE_##_type, \ 1017 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ 1018 .generic = true, \ 1019 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \ 1020 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \ 1021 .init_group_id = _group_id, \ 1022 .metadata_cap = _metadata_cap, \ 1023 } 1024 1025 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \ 1026 _metadata_cap) \ 1027 { \ 1028 .type = DEVLINK_TRAP_TYPE_##_type, \ 1029 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ 1030 .generic = false, \ 1031 .id = _id, \ 1032 .name = _name, \ 1033 .init_group_id = _group_id, \ 1034 .metadata_cap = _metadata_cap, \ 1035 } 1036 1037 #define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \ 1038 { \ 1039 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \ 1040 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \ 1041 .generic = true, \ 1042 .init_policer_id = _policer_id, \ 1043 } 1044 1045 #define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \ 1046 _max_burst, _min_burst) \ 1047 { \ 1048 .id = _id, \ 1049 .init_rate = _rate, \ 1050 .init_burst = _burst, \ 1051 .max_rate = _max_rate, \ 1052 .min_rate = _min_rate, \ 1053 .max_burst = _max_burst, \ 1054 .min_burst = _min_burst, \ 1055 } 1056 1057 struct devlink_ops { 1058 /** 1059 * @supported_flash_update_params: 1060 * mask of parameters supported by the driver's .flash_update 1061 * implemementation. 1062 */ 1063 u32 supported_flash_update_params; 1064 int (*reload_down)(struct devlink *devlink, bool netns_change, 1065 struct netlink_ext_ack *extack); 1066 int (*reload_up)(struct devlink *devlink, 1067 struct netlink_ext_ack *extack); 1068 int (*port_type_set)(struct devlink_port *devlink_port, 1069 enum devlink_port_type port_type); 1070 int (*port_split)(struct devlink *devlink, unsigned int port_index, 1071 unsigned int count, struct netlink_ext_ack *extack); 1072 int (*port_unsplit)(struct devlink *devlink, unsigned int port_index, 1073 struct netlink_ext_ack *extack); 1074 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index, 1075 u16 pool_index, 1076 struct devlink_sb_pool_info *pool_info); 1077 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index, 1078 u16 pool_index, u32 size, 1079 enum devlink_sb_threshold_type threshold_type, 1080 struct netlink_ext_ack *extack); 1081 int (*sb_port_pool_get)(struct devlink_port *devlink_port, 1082 unsigned int sb_index, u16 pool_index, 1083 u32 *p_threshold); 1084 int (*sb_port_pool_set)(struct devlink_port *devlink_port, 1085 unsigned int sb_index, u16 pool_index, 1086 u32 threshold, struct netlink_ext_ack *extack); 1087 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port, 1088 unsigned int sb_index, 1089 u16 tc_index, 1090 enum devlink_sb_pool_type pool_type, 1091 u16 *p_pool_index, u32 *p_threshold); 1092 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port, 1093 unsigned int sb_index, 1094 u16 tc_index, 1095 enum devlink_sb_pool_type pool_type, 1096 u16 pool_index, u32 threshold, 1097 struct netlink_ext_ack *extack); 1098 int (*sb_occ_snapshot)(struct devlink *devlink, 1099 unsigned int sb_index); 1100 int (*sb_occ_max_clear)(struct devlink *devlink, 1101 unsigned int sb_index); 1102 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port, 1103 unsigned int sb_index, u16 pool_index, 1104 u32 *p_cur, u32 *p_max); 1105 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port, 1106 unsigned int sb_index, 1107 u16 tc_index, 1108 enum devlink_sb_pool_type pool_type, 1109 u32 *p_cur, u32 *p_max); 1110 1111 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode); 1112 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode, 1113 struct netlink_ext_ack *extack); 1114 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode); 1115 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode, 1116 struct netlink_ext_ack *extack); 1117 int (*eswitch_encap_mode_get)(struct devlink *devlink, 1118 enum devlink_eswitch_encap_mode *p_encap_mode); 1119 int (*eswitch_encap_mode_set)(struct devlink *devlink, 1120 enum devlink_eswitch_encap_mode encap_mode, 1121 struct netlink_ext_ack *extack); 1122 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req, 1123 struct netlink_ext_ack *extack); 1124 /** 1125 * @flash_update: Device flash update function 1126 * 1127 * Used to perform a flash update for the device. The set of 1128 * parameters supported by the driver should be set in 1129 * supported_flash_update_params. 1130 */ 1131 int (*flash_update)(struct devlink *devlink, 1132 struct devlink_flash_update_params *params, 1133 struct netlink_ext_ack *extack); 1134 /** 1135 * @trap_init: Trap initialization function. 1136 * 1137 * Should be used by device drivers to initialize the trap in the 1138 * underlying device. Drivers should also store the provided trap 1139 * context, so that they could efficiently pass it to 1140 * devlink_trap_report() when the trap is triggered. 1141 */ 1142 int (*trap_init)(struct devlink *devlink, 1143 const struct devlink_trap *trap, void *trap_ctx); 1144 /** 1145 * @trap_fini: Trap de-initialization function. 1146 * 1147 * Should be used by device drivers to de-initialize the trap in the 1148 * underlying device. 1149 */ 1150 void (*trap_fini)(struct devlink *devlink, 1151 const struct devlink_trap *trap, void *trap_ctx); 1152 /** 1153 * @trap_action_set: Trap action set function. 1154 */ 1155 int (*trap_action_set)(struct devlink *devlink, 1156 const struct devlink_trap *trap, 1157 enum devlink_trap_action action, 1158 struct netlink_ext_ack *extack); 1159 /** 1160 * @trap_group_init: Trap group initialization function. 1161 * 1162 * Should be used by device drivers to initialize the trap group in the 1163 * underlying device. 1164 */ 1165 int (*trap_group_init)(struct devlink *devlink, 1166 const struct devlink_trap_group *group); 1167 /** 1168 * @trap_group_set: Trap group parameters set function. 1169 * 1170 * Note: @policer can be NULL when a policer is being unbound from 1171 * @group. 1172 */ 1173 int (*trap_group_set)(struct devlink *devlink, 1174 const struct devlink_trap_group *group, 1175 const struct devlink_trap_policer *policer, 1176 struct netlink_ext_ack *extack); 1177 /** 1178 * @trap_policer_init: Trap policer initialization function. 1179 * 1180 * Should be used by device drivers to initialize the trap policer in 1181 * the underlying device. 1182 */ 1183 int (*trap_policer_init)(struct devlink *devlink, 1184 const struct devlink_trap_policer *policer); 1185 /** 1186 * @trap_policer_fini: Trap policer de-initialization function. 1187 * 1188 * Should be used by device drivers to de-initialize the trap policer 1189 * in the underlying device. 1190 */ 1191 void (*trap_policer_fini)(struct devlink *devlink, 1192 const struct devlink_trap_policer *policer); 1193 /** 1194 * @trap_policer_set: Trap policer parameters set function. 1195 */ 1196 int (*trap_policer_set)(struct devlink *devlink, 1197 const struct devlink_trap_policer *policer, 1198 u64 rate, u64 burst, 1199 struct netlink_ext_ack *extack); 1200 /** 1201 * @trap_policer_counter_get: Trap policer counter get function. 1202 * 1203 * Should be used by device drivers to report number of packets dropped 1204 * by the policer. 1205 */ 1206 int (*trap_policer_counter_get)(struct devlink *devlink, 1207 const struct devlink_trap_policer *policer, 1208 u64 *p_drops); 1209 /** 1210 * @port_function_hw_addr_get: Port function's hardware address get function. 1211 * 1212 * Should be used by device drivers to report the hardware address of a function managed 1213 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port 1214 * function handling for a particular port. 1215 * 1216 * Note: @extack can be NULL when port notifier queries the port function. 1217 */ 1218 int (*port_function_hw_addr_get)(struct devlink *devlink, struct devlink_port *port, 1219 u8 *hw_addr, int *hw_addr_len, 1220 struct netlink_ext_ack *extack); 1221 /** 1222 * @port_function_hw_addr_set: Port function's hardware address set function. 1223 * 1224 * Should be used by device drivers to set the hardware address of a function managed 1225 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port 1226 * function handling for a particular port. 1227 */ 1228 int (*port_function_hw_addr_set)(struct devlink *devlink, struct devlink_port *port, 1229 const u8 *hw_addr, int hw_addr_len, 1230 struct netlink_ext_ack *extack); 1231 }; 1232 1233 static inline void *devlink_priv(struct devlink *devlink) 1234 { 1235 BUG_ON(!devlink); 1236 return &devlink->priv; 1237 } 1238 1239 static inline struct devlink *priv_to_devlink(void *priv) 1240 { 1241 BUG_ON(!priv); 1242 return container_of(priv, struct devlink, priv); 1243 } 1244 1245 static inline struct devlink_port * 1246 netdev_to_devlink_port(struct net_device *dev) 1247 { 1248 if (dev->netdev_ops->ndo_get_devlink_port) 1249 return dev->netdev_ops->ndo_get_devlink_port(dev); 1250 return NULL; 1251 } 1252 1253 static inline struct devlink *netdev_to_devlink(struct net_device *dev) 1254 { 1255 struct devlink_port *devlink_port = netdev_to_devlink_port(dev); 1256 1257 if (devlink_port) 1258 return devlink_port->devlink; 1259 return NULL; 1260 } 1261 1262 struct ib_device; 1263 1264 struct net *devlink_net(const struct devlink *devlink); 1265 void devlink_net_set(struct devlink *devlink, struct net *net); 1266 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size); 1267 int devlink_register(struct devlink *devlink, struct device *dev); 1268 void devlink_unregister(struct devlink *devlink); 1269 void devlink_reload_enable(struct devlink *devlink); 1270 void devlink_reload_disable(struct devlink *devlink); 1271 void devlink_free(struct devlink *devlink); 1272 int devlink_port_register(struct devlink *devlink, 1273 struct devlink_port *devlink_port, 1274 unsigned int port_index); 1275 void devlink_port_unregister(struct devlink_port *devlink_port); 1276 void devlink_port_type_eth_set(struct devlink_port *devlink_port, 1277 struct net_device *netdev); 1278 void devlink_port_type_ib_set(struct devlink_port *devlink_port, 1279 struct ib_device *ibdev); 1280 void devlink_port_type_clear(struct devlink_port *devlink_port); 1281 void devlink_port_attrs_set(struct devlink_port *devlink_port, 1282 struct devlink_port_attrs *devlink_port_attrs); 1283 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller, 1284 u16 pf, bool external); 1285 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller, 1286 u16 pf, u16 vf, bool external); 1287 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, 1288 u32 size, u16 ingress_pools_count, 1289 u16 egress_pools_count, u16 ingress_tc_count, 1290 u16 egress_tc_count); 1291 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); 1292 int devlink_dpipe_table_register(struct devlink *devlink, 1293 const char *table_name, 1294 struct devlink_dpipe_table_ops *table_ops, 1295 void *priv, bool counter_control_extern); 1296 void devlink_dpipe_table_unregister(struct devlink *devlink, 1297 const char *table_name); 1298 int devlink_dpipe_headers_register(struct devlink *devlink, 1299 struct devlink_dpipe_headers *dpipe_headers); 1300 void devlink_dpipe_headers_unregister(struct devlink *devlink); 1301 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, 1302 const char *table_name); 1303 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx); 1304 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, 1305 struct devlink_dpipe_entry *entry); 1306 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx); 1307 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry); 1308 int devlink_dpipe_action_put(struct sk_buff *skb, 1309 struct devlink_dpipe_action *action); 1310 int devlink_dpipe_match_put(struct sk_buff *skb, 1311 struct devlink_dpipe_match *match); 1312 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; 1313 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; 1314 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; 1315 1316 int devlink_resource_register(struct devlink *devlink, 1317 const char *resource_name, 1318 u64 resource_size, 1319 u64 resource_id, 1320 u64 parent_resource_id, 1321 const struct devlink_resource_size_params *size_params); 1322 void devlink_resources_unregister(struct devlink *devlink, 1323 struct devlink_resource *resource); 1324 int devlink_resource_size_get(struct devlink *devlink, 1325 u64 resource_id, 1326 u64 *p_resource_size); 1327 int devlink_dpipe_table_resource_set(struct devlink *devlink, 1328 const char *table_name, u64 resource_id, 1329 u64 resource_units); 1330 void devlink_resource_occ_get_register(struct devlink *devlink, 1331 u64 resource_id, 1332 devlink_resource_occ_get_t *occ_get, 1333 void *occ_get_priv); 1334 void devlink_resource_occ_get_unregister(struct devlink *devlink, 1335 u64 resource_id); 1336 int devlink_params_register(struct devlink *devlink, 1337 const struct devlink_param *params, 1338 size_t params_count); 1339 void devlink_params_unregister(struct devlink *devlink, 1340 const struct devlink_param *params, 1341 size_t params_count); 1342 void devlink_params_publish(struct devlink *devlink); 1343 void devlink_params_unpublish(struct devlink *devlink); 1344 int devlink_port_params_register(struct devlink_port *devlink_port, 1345 const struct devlink_param *params, 1346 size_t params_count); 1347 void devlink_port_params_unregister(struct devlink_port *devlink_port, 1348 const struct devlink_param *params, 1349 size_t params_count); 1350 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, 1351 union devlink_param_value *init_val); 1352 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, 1353 union devlink_param_value init_val); 1354 int 1355 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port, 1356 u32 param_id, 1357 union devlink_param_value *init_val); 1358 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port, 1359 u32 param_id, 1360 union devlink_param_value init_val); 1361 void devlink_param_value_changed(struct devlink *devlink, u32 param_id); 1362 void devlink_port_param_value_changed(struct devlink_port *devlink_port, 1363 u32 param_id); 1364 void devlink_param_value_str_fill(union devlink_param_value *dst_val, 1365 const char *src); 1366 struct devlink_region * 1367 devlink_region_create(struct devlink *devlink, 1368 const struct devlink_region_ops *ops, 1369 u32 region_max_snapshots, u64 region_size); 1370 void devlink_region_destroy(struct devlink_region *region); 1371 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id); 1372 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id); 1373 int devlink_region_snapshot_create(struct devlink_region *region, 1374 u8 *data, u32 snapshot_id); 1375 int devlink_info_serial_number_put(struct devlink_info_req *req, 1376 const char *sn); 1377 int devlink_info_driver_name_put(struct devlink_info_req *req, 1378 const char *name); 1379 int devlink_info_board_serial_number_put(struct devlink_info_req *req, 1380 const char *bsn); 1381 int devlink_info_version_fixed_put(struct devlink_info_req *req, 1382 const char *version_name, 1383 const char *version_value); 1384 int devlink_info_version_stored_put(struct devlink_info_req *req, 1385 const char *version_name, 1386 const char *version_value); 1387 int devlink_info_version_running_put(struct devlink_info_req *req, 1388 const char *version_name, 1389 const char *version_value); 1390 1391 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg); 1392 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg); 1393 1394 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name); 1395 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg); 1396 1397 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg, 1398 const char *name); 1399 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg); 1400 int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg, 1401 const char *name); 1402 int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg); 1403 1404 int devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value); 1405 int devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value); 1406 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value); 1407 int devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value); 1408 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value); 1409 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value, 1410 u16 value_len); 1411 1412 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name, 1413 bool value); 1414 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name, 1415 u8 value); 1416 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name, 1417 u32 value); 1418 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name, 1419 u64 value); 1420 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name, 1421 const char *value); 1422 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, 1423 const void *value, u32 value_len); 1424 1425 struct devlink_health_reporter * 1426 devlink_health_reporter_create(struct devlink *devlink, 1427 const struct devlink_health_reporter_ops *ops, 1428 u64 graceful_period, void *priv); 1429 1430 struct devlink_health_reporter * 1431 devlink_port_health_reporter_create(struct devlink_port *port, 1432 const struct devlink_health_reporter_ops *ops, 1433 u64 graceful_period, void *priv); 1434 1435 void 1436 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); 1437 1438 void 1439 devlink_port_health_reporter_destroy(struct devlink_health_reporter *reporter); 1440 1441 void * 1442 devlink_health_reporter_priv(struct devlink_health_reporter *reporter); 1443 int devlink_health_report(struct devlink_health_reporter *reporter, 1444 const char *msg, void *priv_ctx); 1445 void 1446 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, 1447 enum devlink_health_reporter_state state); 1448 void 1449 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter); 1450 1451 bool devlink_is_reload_failed(const struct devlink *devlink); 1452 1453 void devlink_flash_update_begin_notify(struct devlink *devlink); 1454 void devlink_flash_update_end_notify(struct devlink *devlink); 1455 void devlink_flash_update_status_notify(struct devlink *devlink, 1456 const char *status_msg, 1457 const char *component, 1458 unsigned long done, 1459 unsigned long total); 1460 void devlink_flash_update_timeout_notify(struct devlink *devlink, 1461 const char *status_msg, 1462 const char *component, 1463 unsigned long timeout); 1464 1465 int devlink_traps_register(struct devlink *devlink, 1466 const struct devlink_trap *traps, 1467 size_t traps_count, void *priv); 1468 void devlink_traps_unregister(struct devlink *devlink, 1469 const struct devlink_trap *traps, 1470 size_t traps_count); 1471 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, 1472 void *trap_ctx, struct devlink_port *in_devlink_port, 1473 const struct flow_action_cookie *fa_cookie); 1474 void *devlink_trap_ctx_priv(void *trap_ctx); 1475 int devlink_trap_groups_register(struct devlink *devlink, 1476 const struct devlink_trap_group *groups, 1477 size_t groups_count); 1478 void devlink_trap_groups_unregister(struct devlink *devlink, 1479 const struct devlink_trap_group *groups, 1480 size_t groups_count); 1481 int 1482 devlink_trap_policers_register(struct devlink *devlink, 1483 const struct devlink_trap_policer *policers, 1484 size_t policers_count); 1485 void 1486 devlink_trap_policers_unregister(struct devlink *devlink, 1487 const struct devlink_trap_policer *policers, 1488 size_t policers_count); 1489 1490 #if IS_ENABLED(CONFIG_NET_DEVLINK) 1491 1492 void devlink_compat_running_version(struct net_device *dev, 1493 char *buf, size_t len); 1494 int devlink_compat_flash_update(struct net_device *dev, const char *file_name); 1495 int devlink_compat_phys_port_name_get(struct net_device *dev, 1496 char *name, size_t len); 1497 int devlink_compat_switch_id_get(struct net_device *dev, 1498 struct netdev_phys_item_id *ppid); 1499 1500 #else 1501 1502 static inline void 1503 devlink_compat_running_version(struct net_device *dev, char *buf, size_t len) 1504 { 1505 } 1506 1507 static inline int 1508 devlink_compat_flash_update(struct net_device *dev, const char *file_name) 1509 { 1510 return -EOPNOTSUPP; 1511 } 1512 1513 static inline int 1514 devlink_compat_phys_port_name_get(struct net_device *dev, 1515 char *name, size_t len) 1516 { 1517 return -EOPNOTSUPP; 1518 } 1519 1520 static inline int 1521 devlink_compat_switch_id_get(struct net_device *dev, 1522 struct netdev_phys_item_id *ppid) 1523 { 1524 return -EOPNOTSUPP; 1525 } 1526 1527 #endif 1528 1529 #endif /* _NET_DEVLINK_H_ */ 1530