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 #include <linux/firmware.h> 23 24 struct devlink; 25 struct devlink_linecard; 26 27 struct devlink_port_phys_attrs { 28 u32 port_number; /* Same value as "split group". 29 * A physical port which is visible to the user 30 * for a given port flavour. 31 */ 32 u32 split_subport_number; /* If the port is split, this is the number of subport. */ 33 }; 34 35 /** 36 * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes 37 * @controller: Associated controller number 38 * @pf: Associated PCI PF number for this port. 39 * @external: when set, indicates if a port is for an external controller 40 */ 41 struct devlink_port_pci_pf_attrs { 42 u32 controller; 43 u16 pf; 44 u8 external:1; 45 }; 46 47 /** 48 * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes 49 * @controller: Associated controller number 50 * @pf: Associated PCI PF number for this port. 51 * @vf: Associated PCI VF for of the PCI PF for this port. 52 * @external: when set, indicates if a port is for an external controller 53 */ 54 struct devlink_port_pci_vf_attrs { 55 u32 controller; 56 u16 pf; 57 u16 vf; 58 u8 external:1; 59 }; 60 61 /** 62 * struct devlink_port_pci_sf_attrs - devlink port's PCI SF attributes 63 * @controller: Associated controller number 64 * @sf: Associated PCI SF for of the PCI PF for this port. 65 * @pf: Associated PCI PF number for this port. 66 * @external: when set, indicates if a port is for an external controller 67 */ 68 struct devlink_port_pci_sf_attrs { 69 u32 controller; 70 u32 sf; 71 u16 pf; 72 u8 external:1; 73 }; 74 75 /** 76 * struct devlink_port_attrs - devlink port object 77 * @flavour: flavour of the port 78 * @split: indicates if this is split port 79 * @splittable: indicates if the port can be split. 80 * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink. 81 * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL 82 * @phys: physical port attributes 83 * @pci_pf: PCI PF port attributes 84 * @pci_vf: PCI VF port attributes 85 * @pci_sf: PCI SF port attributes 86 */ 87 struct devlink_port_attrs { 88 u8 split:1, 89 splittable:1; 90 u32 lanes; 91 enum devlink_port_flavour flavour; 92 struct netdev_phys_item_id switch_id; 93 union { 94 struct devlink_port_phys_attrs phys; 95 struct devlink_port_pci_pf_attrs pci_pf; 96 struct devlink_port_pci_vf_attrs pci_vf; 97 struct devlink_port_pci_sf_attrs pci_sf; 98 }; 99 }; 100 101 struct devlink_rate { 102 struct list_head list; 103 enum devlink_rate_type type; 104 struct devlink *devlink; 105 void *priv; 106 u64 tx_share; 107 u64 tx_max; 108 109 struct devlink_rate *parent; 110 union { 111 struct devlink_port *devlink_port; 112 struct { 113 char *name; 114 refcount_t refcnt; 115 }; 116 }; 117 118 u32 tx_priority; 119 u32 tx_weight; 120 }; 121 122 struct devlink_port { 123 struct list_head list; 124 struct list_head region_list; 125 struct devlink *devlink; 126 unsigned int index; 127 spinlock_t type_lock; /* Protects type and type_eth/ib 128 * structures consistency. 129 */ 130 enum devlink_port_type type; 131 enum devlink_port_type desired_type; 132 union { 133 struct { 134 struct net_device *netdev; 135 int ifindex; 136 char ifname[IFNAMSIZ]; 137 } type_eth; 138 struct { 139 struct ib_device *ibdev; 140 } type_ib; 141 }; 142 struct devlink_port_attrs attrs; 143 u8 attrs_set:1, 144 switch_port:1, 145 registered:1, 146 initialized:1; 147 struct delayed_work type_warn_dw; 148 struct list_head reporter_list; 149 150 struct devlink_rate *devlink_rate; 151 struct devlink_linecard *linecard; 152 }; 153 154 struct devlink_port_new_attrs { 155 enum devlink_port_flavour flavour; 156 unsigned int port_index; 157 u32 controller; 158 u32 sfnum; 159 u16 pfnum; 160 u8 port_index_valid:1, 161 controller_valid:1, 162 sfnum_valid:1; 163 }; 164 165 /** 166 * struct devlink_linecard_ops - Linecard operations 167 * @provision: callback to provision the linecard slot with certain 168 * type of linecard. As a result of this operation, 169 * driver is expected to eventually (could be after 170 * the function call returns) call one of: 171 * devlink_linecard_provision_set() 172 * devlink_linecard_provision_fail() 173 * @unprovision: callback to unprovision the linecard slot. As a result 174 * of this operation, driver is expected to eventually 175 * (could be after the function call returns) call 176 * devlink_linecard_provision_clear() 177 * devlink_linecard_provision_fail() 178 * @same_provision: callback to ask the driver if linecard is already 179 * provisioned in the same way user asks this linecard to be 180 * provisioned. 181 * @types_count: callback to get number of supported types 182 * @types_get: callback to get next type in list 183 */ 184 struct devlink_linecard_ops { 185 int (*provision)(struct devlink_linecard *linecard, void *priv, 186 const char *type, const void *type_priv, 187 struct netlink_ext_ack *extack); 188 int (*unprovision)(struct devlink_linecard *linecard, void *priv, 189 struct netlink_ext_ack *extack); 190 bool (*same_provision)(struct devlink_linecard *linecard, void *priv, 191 const char *type, const void *type_priv); 192 unsigned int (*types_count)(struct devlink_linecard *linecard, 193 void *priv); 194 void (*types_get)(struct devlink_linecard *linecard, 195 void *priv, unsigned int index, const char **type, 196 const void **type_priv); 197 }; 198 199 struct devlink_sb_pool_info { 200 enum devlink_sb_pool_type pool_type; 201 u32 size; 202 enum devlink_sb_threshold_type threshold_type; 203 u32 cell_size; 204 }; 205 206 /** 207 * struct devlink_dpipe_field - dpipe field object 208 * @name: field name 209 * @id: index inside the headers field array 210 * @bitwidth: bitwidth 211 * @mapping_type: mapping type 212 */ 213 struct devlink_dpipe_field { 214 const char *name; 215 unsigned int id; 216 unsigned int bitwidth; 217 enum devlink_dpipe_field_mapping_type mapping_type; 218 }; 219 220 /** 221 * struct devlink_dpipe_header - dpipe header object 222 * @name: header name 223 * @id: index, global/local detrmined by global bit 224 * @fields: fields 225 * @fields_count: number of fields 226 * @global: indicates if header is shared like most protocol header 227 * or driver specific 228 */ 229 struct devlink_dpipe_header { 230 const char *name; 231 unsigned int id; 232 struct devlink_dpipe_field *fields; 233 unsigned int fields_count; 234 bool global; 235 }; 236 237 /** 238 * struct devlink_dpipe_match - represents match operation 239 * @type: type of match 240 * @header_index: header index (packets can have several headers of same 241 * type like in case of tunnels) 242 * @header: header 243 * @fieled_id: field index 244 */ 245 struct devlink_dpipe_match { 246 enum devlink_dpipe_match_type type; 247 unsigned int header_index; 248 struct devlink_dpipe_header *header; 249 unsigned int field_id; 250 }; 251 252 /** 253 * struct devlink_dpipe_action - represents action operation 254 * @type: type of action 255 * @header_index: header index (packets can have several headers of same 256 * type like in case of tunnels) 257 * @header: header 258 * @fieled_id: field index 259 */ 260 struct devlink_dpipe_action { 261 enum devlink_dpipe_action_type type; 262 unsigned int header_index; 263 struct devlink_dpipe_header *header; 264 unsigned int field_id; 265 }; 266 267 /** 268 * struct devlink_dpipe_value - represents value of match/action 269 * @action: action 270 * @match: match 271 * @mapping_value: in case the field has some mapping this value 272 * specified the mapping value 273 * @mapping_valid: specify if mapping value is valid 274 * @value_size: value size 275 * @value: value 276 * @mask: bit mask 277 */ 278 struct devlink_dpipe_value { 279 union { 280 struct devlink_dpipe_action *action; 281 struct devlink_dpipe_match *match; 282 }; 283 unsigned int mapping_value; 284 bool mapping_valid; 285 unsigned int value_size; 286 void *value; 287 void *mask; 288 }; 289 290 /** 291 * struct devlink_dpipe_entry - table entry object 292 * @index: index of the entry in the table 293 * @match_values: match values 294 * @matche_values_count: count of matches tuples 295 * @action_values: actions values 296 * @action_values_count: count of actions values 297 * @counter: value of counter 298 * @counter_valid: Specify if value is valid from hardware 299 */ 300 struct devlink_dpipe_entry { 301 u64 index; 302 struct devlink_dpipe_value *match_values; 303 unsigned int match_values_count; 304 struct devlink_dpipe_value *action_values; 305 unsigned int action_values_count; 306 u64 counter; 307 bool counter_valid; 308 }; 309 310 /** 311 * struct devlink_dpipe_dump_ctx - context provided to driver in order 312 * to dump 313 * @info: info 314 * @cmd: devlink command 315 * @skb: skb 316 * @nest: top attribute 317 * @hdr: hdr 318 */ 319 struct devlink_dpipe_dump_ctx { 320 struct genl_info *info; 321 enum devlink_command cmd; 322 struct sk_buff *skb; 323 struct nlattr *nest; 324 void *hdr; 325 }; 326 327 struct devlink_dpipe_table_ops; 328 329 /** 330 * struct devlink_dpipe_table - table object 331 * @priv: private 332 * @name: table name 333 * @counters_enabled: indicates if counters are active 334 * @counter_control_extern: indicates if counter control is in dpipe or 335 * external tool 336 * @resource_valid: Indicate that the resource id is valid 337 * @resource_id: relative resource this table is related to 338 * @resource_units: number of resource's unit consumed per table's entry 339 * @table_ops: table operations 340 * @rcu: rcu 341 */ 342 struct devlink_dpipe_table { 343 void *priv; 344 struct list_head list; 345 const char *name; 346 bool counters_enabled; 347 bool counter_control_extern; 348 bool resource_valid; 349 u64 resource_id; 350 u64 resource_units; 351 struct devlink_dpipe_table_ops *table_ops; 352 struct rcu_head rcu; 353 }; 354 355 /** 356 * struct devlink_dpipe_table_ops - dpipe_table ops 357 * @actions_dump - dumps all tables actions 358 * @matches_dump - dumps all tables matches 359 * @entries_dump - dumps all active entries in the table 360 * @counters_set_update - when changing the counter status hardware sync 361 * maybe needed to allocate/free counter related 362 * resources 363 * @size_get - get size 364 */ 365 struct devlink_dpipe_table_ops { 366 int (*actions_dump)(void *priv, struct sk_buff *skb); 367 int (*matches_dump)(void *priv, struct sk_buff *skb); 368 int (*entries_dump)(void *priv, bool counters_enabled, 369 struct devlink_dpipe_dump_ctx *dump_ctx); 370 int (*counters_set_update)(void *priv, bool enable); 371 u64 (*size_get)(void *priv); 372 }; 373 374 /** 375 * struct devlink_dpipe_headers - dpipe headers 376 * @headers - header array can be shared (global bit) or driver specific 377 * @headers_count - count of headers 378 */ 379 struct devlink_dpipe_headers { 380 struct devlink_dpipe_header **headers; 381 unsigned int headers_count; 382 }; 383 384 /** 385 * struct devlink_resource_size_params - resource's size parameters 386 * @size_min: minimum size which can be set 387 * @size_max: maximum size which can be set 388 * @size_granularity: size granularity 389 * @size_unit: resource's basic unit 390 */ 391 struct devlink_resource_size_params { 392 u64 size_min; 393 u64 size_max; 394 u64 size_granularity; 395 enum devlink_resource_unit unit; 396 }; 397 398 static inline void 399 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params, 400 u64 size_min, u64 size_max, 401 u64 size_granularity, 402 enum devlink_resource_unit unit) 403 { 404 size_params->size_min = size_min; 405 size_params->size_max = size_max; 406 size_params->size_granularity = size_granularity; 407 size_params->unit = unit; 408 } 409 410 typedef u64 devlink_resource_occ_get_t(void *priv); 411 412 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0 413 414 #define DEVLINK_RESOURCE_GENERIC_NAME_PORTS "physical_ports" 415 416 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32 417 enum devlink_param_type { 418 DEVLINK_PARAM_TYPE_U8, 419 DEVLINK_PARAM_TYPE_U16, 420 DEVLINK_PARAM_TYPE_U32, 421 DEVLINK_PARAM_TYPE_STRING, 422 DEVLINK_PARAM_TYPE_BOOL, 423 }; 424 425 union devlink_param_value { 426 u8 vu8; 427 u16 vu16; 428 u32 vu32; 429 char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE]; 430 bool vbool; 431 }; 432 433 struct devlink_param_gset_ctx { 434 union devlink_param_value val; 435 enum devlink_param_cmode cmode; 436 }; 437 438 /** 439 * struct devlink_flash_notify - devlink dev flash notify data 440 * @status_msg: current status string 441 * @component: firmware component being updated 442 * @done: amount of work completed of total amount 443 * @total: amount of work expected to be done 444 * @timeout: expected max timeout in seconds 445 * 446 * These are values to be given to userland to be displayed in order 447 * to show current activity in a firmware update process. 448 */ 449 struct devlink_flash_notify { 450 const char *status_msg; 451 const char *component; 452 unsigned long done; 453 unsigned long total; 454 unsigned long timeout; 455 }; 456 457 /** 458 * struct devlink_param - devlink configuration parameter data 459 * @name: name of the parameter 460 * @generic: indicates if the parameter is generic or driver specific 461 * @type: parameter type 462 * @supported_cmodes: bitmap of supported configuration modes 463 * @get: get parameter value, used for runtime and permanent 464 * configuration modes 465 * @set: set parameter value, used for runtime and permanent 466 * configuration modes 467 * @validate: validate input value is applicable (within value range, etc.) 468 * 469 * This struct should be used by the driver to fill the data for 470 * a parameter it registers. 471 */ 472 struct devlink_param { 473 u32 id; 474 const char *name; 475 bool generic; 476 enum devlink_param_type type; 477 unsigned long supported_cmodes; 478 int (*get)(struct devlink *devlink, u32 id, 479 struct devlink_param_gset_ctx *ctx); 480 int (*set)(struct devlink *devlink, u32 id, 481 struct devlink_param_gset_ctx *ctx); 482 int (*validate)(struct devlink *devlink, u32 id, 483 union devlink_param_value val, 484 struct netlink_ext_ack *extack); 485 }; 486 487 struct devlink_param_item { 488 struct list_head list; 489 const struct devlink_param *param; 490 union devlink_param_value driverinit_value; 491 bool driverinit_value_valid; 492 }; 493 494 enum devlink_param_generic_id { 495 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET, 496 DEVLINK_PARAM_GENERIC_ID_MAX_MACS, 497 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV, 498 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT, 499 DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI, 500 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX, 501 DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN, 502 DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY, 503 DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE, 504 DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE, 505 DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET, 506 DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH, 507 DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA, 508 DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET, 509 DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP, 510 DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE, 511 DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE, 512 513 /* add new param generic ids above here*/ 514 __DEVLINK_PARAM_GENERIC_ID_MAX, 515 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1, 516 }; 517 518 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset" 519 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL 520 521 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs" 522 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32 523 524 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov" 525 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL 526 527 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable" 528 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL 529 530 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari" 531 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL 532 533 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max" 534 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32 535 536 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min" 537 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32 538 539 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy" 540 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8 541 542 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME \ 543 "reset_dev_on_drv_probe" 544 #define DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE DEVLINK_PARAM_TYPE_U8 545 546 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME "enable_roce" 547 #define DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE DEVLINK_PARAM_TYPE_BOOL 548 549 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME "enable_remote_dev_reset" 550 #define DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL 551 552 #define DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME "enable_eth" 553 #define DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE DEVLINK_PARAM_TYPE_BOOL 554 555 #define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME "enable_rdma" 556 #define DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE DEVLINK_PARAM_TYPE_BOOL 557 558 #define DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME "enable_vnet" 559 #define DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE DEVLINK_PARAM_TYPE_BOOL 560 561 #define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_NAME "enable_iwarp" 562 #define DEVLINK_PARAM_GENERIC_ENABLE_IWARP_TYPE DEVLINK_PARAM_TYPE_BOOL 563 564 #define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_NAME "io_eq_size" 565 #define DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32 566 567 #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size" 568 #define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32 569 570 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \ 571 { \ 572 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \ 573 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \ 574 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \ 575 .generic = true, \ 576 .supported_cmodes = _cmodes, \ 577 .get = _get, \ 578 .set = _set, \ 579 .validate = _validate, \ 580 } 581 582 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \ 583 { \ 584 .id = _id, \ 585 .name = _name, \ 586 .type = _type, \ 587 .supported_cmodes = _cmodes, \ 588 .get = _get, \ 589 .set = _set, \ 590 .validate = _validate, \ 591 } 592 593 /* Part number, identifier of board design */ 594 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID "board.id" 595 /* Revision of board design */ 596 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV "board.rev" 597 /* Maker of the board */ 598 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_MANUFACTURE "board.manufacture" 599 600 /* Part number, identifier of asic design */ 601 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_ID "asic.id" 602 /* Revision of asic design */ 603 #define DEVLINK_INFO_VERSION_GENERIC_ASIC_REV "asic.rev" 604 605 /* Overall FW version */ 606 #define DEVLINK_INFO_VERSION_GENERIC_FW "fw" 607 /* Control processor FW version */ 608 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT "fw.mgmt" 609 /* FW interface specification version */ 610 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT_API "fw.mgmt.api" 611 /* Data path microcode controlling high-speed packet processing */ 612 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP "fw.app" 613 /* UNDI software version */ 614 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI "fw.undi" 615 /* NCSI support/handler version */ 616 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI "fw.ncsi" 617 /* FW parameter set id */ 618 #define DEVLINK_INFO_VERSION_GENERIC_FW_PSID "fw.psid" 619 /* RoCE FW version */ 620 #define DEVLINK_INFO_VERSION_GENERIC_FW_ROCE "fw.roce" 621 /* Firmware bundle identifier */ 622 #define DEVLINK_INFO_VERSION_GENERIC_FW_BUNDLE_ID "fw.bundle_id" 623 /* Bootloader */ 624 #define DEVLINK_INFO_VERSION_GENERIC_FW_BOOTLOADER "fw.bootloader" 625 626 /** 627 * struct devlink_flash_update_params - Flash Update parameters 628 * @fw: pointer to the firmware data to update from 629 * @component: the flash component to update 630 * 631 * With the exception of fw, drivers must opt-in to parameters by 632 * setting the appropriate bit in the supported_flash_update_params field in 633 * their devlink_ops structure. 634 */ 635 struct devlink_flash_update_params { 636 const struct firmware *fw; 637 const char *component; 638 u32 overwrite_mask; 639 }; 640 641 #define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK BIT(0) 642 643 struct devlink_region; 644 struct devlink_info_req; 645 646 /** 647 * struct devlink_region_ops - Region operations 648 * @name: region name 649 * @destructor: callback used to free snapshot memory when deleting 650 * @snapshot: callback to request an immediate snapshot. On success, 651 * the data variable must be updated to point to the snapshot data. 652 * The function will be called while the devlink instance lock is 653 * held. 654 * @read: callback to directly read a portion of the region. On success, 655 * the data pointer will be updated with the contents of the 656 * requested portion of the region. The function will be called 657 * while the devlink instance lock is held. 658 * @priv: Pointer to driver private data for the region operation 659 */ 660 struct devlink_region_ops { 661 const char *name; 662 void (*destructor)(const void *data); 663 int (*snapshot)(struct devlink *devlink, 664 const struct devlink_region_ops *ops, 665 struct netlink_ext_ack *extack, 666 u8 **data); 667 int (*read)(struct devlink *devlink, 668 const struct devlink_region_ops *ops, 669 struct netlink_ext_ack *extack, 670 u64 offset, u32 size, u8 *data); 671 void *priv; 672 }; 673 674 /** 675 * struct devlink_port_region_ops - Region operations for a port 676 * @name: region name 677 * @destructor: callback used to free snapshot memory when deleting 678 * @snapshot: callback to request an immediate snapshot. On success, 679 * the data variable must be updated to point to the snapshot data. 680 * The function will be called while the devlink instance lock is 681 * held. 682 * @read: callback to directly read a portion of the region. On success, 683 * the data pointer will be updated with the contents of the 684 * requested portion of the region. The function will be called 685 * while the devlink instance lock is held. 686 * @priv: Pointer to driver private data for the region operation 687 */ 688 struct devlink_port_region_ops { 689 const char *name; 690 void (*destructor)(const void *data); 691 int (*snapshot)(struct devlink_port *port, 692 const struct devlink_port_region_ops *ops, 693 struct netlink_ext_ack *extack, 694 u8 **data); 695 int (*read)(struct devlink_port *port, 696 const struct devlink_port_region_ops *ops, 697 struct netlink_ext_ack *extack, 698 u64 offset, u32 size, u8 *data); 699 void *priv; 700 }; 701 702 struct devlink_fmsg; 703 struct devlink_health_reporter; 704 705 enum devlink_health_reporter_state { 706 DEVLINK_HEALTH_REPORTER_STATE_HEALTHY, 707 DEVLINK_HEALTH_REPORTER_STATE_ERROR, 708 }; 709 710 /** 711 * struct devlink_health_reporter_ops - Reporter operations 712 * @name: reporter name 713 * @recover: callback to recover from reported error 714 * if priv_ctx is NULL, run a full recover 715 * @dump: callback to dump an object 716 * if priv_ctx is NULL, run a full dump 717 * @diagnose: callback to diagnose the current status 718 * @test: callback to trigger a test event 719 */ 720 721 struct devlink_health_reporter_ops { 722 char *name; 723 int (*recover)(struct devlink_health_reporter *reporter, 724 void *priv_ctx, struct netlink_ext_ack *extack); 725 int (*dump)(struct devlink_health_reporter *reporter, 726 struct devlink_fmsg *fmsg, void *priv_ctx, 727 struct netlink_ext_ack *extack); 728 int (*diagnose)(struct devlink_health_reporter *reporter, 729 struct devlink_fmsg *fmsg, 730 struct netlink_ext_ack *extack); 731 int (*test)(struct devlink_health_reporter *reporter, 732 struct netlink_ext_ack *extack); 733 }; 734 735 /** 736 * struct devlink_trap_metadata - Packet trap metadata. 737 * @trap_name: Trap name. 738 * @trap_group_name: Trap group name. 739 * @input_dev: Input netdevice. 740 * @dev_tracker: refcount tracker for @input_dev. 741 * @fa_cookie: Flow action user cookie. 742 * @trap_type: Trap type. 743 */ 744 struct devlink_trap_metadata { 745 const char *trap_name; 746 const char *trap_group_name; 747 748 struct net_device *input_dev; 749 netdevice_tracker dev_tracker; 750 751 const struct flow_action_cookie *fa_cookie; 752 enum devlink_trap_type trap_type; 753 }; 754 755 /** 756 * struct devlink_trap_policer - Immutable packet trap policer attributes. 757 * @id: Policer identifier. 758 * @init_rate: Initial rate in packets / sec. 759 * @init_burst: Initial burst size in packets. 760 * @max_rate: Maximum rate. 761 * @min_rate: Minimum rate. 762 * @max_burst: Maximum burst size. 763 * @min_burst: Minimum burst size. 764 * 765 * Describes immutable attributes of packet trap policers that drivers register 766 * with devlink. 767 */ 768 struct devlink_trap_policer { 769 u32 id; 770 u64 init_rate; 771 u64 init_burst; 772 u64 max_rate; 773 u64 min_rate; 774 u64 max_burst; 775 u64 min_burst; 776 }; 777 778 /** 779 * struct devlink_trap_group - Immutable packet trap group attributes. 780 * @name: Trap group name. 781 * @id: Trap group identifier. 782 * @generic: Whether the trap group is generic or not. 783 * @init_policer_id: Initial policer identifier. 784 * 785 * Describes immutable attributes of packet trap groups that drivers register 786 * with devlink. 787 */ 788 struct devlink_trap_group { 789 const char *name; 790 u16 id; 791 bool generic; 792 u32 init_policer_id; 793 }; 794 795 #define DEVLINK_TRAP_METADATA_TYPE_F_IN_PORT BIT(0) 796 #define DEVLINK_TRAP_METADATA_TYPE_F_FA_COOKIE BIT(1) 797 798 /** 799 * struct devlink_trap - Immutable packet trap attributes. 800 * @type: Trap type. 801 * @init_action: Initial trap action. 802 * @generic: Whether the trap is generic or not. 803 * @id: Trap identifier. 804 * @name: Trap name. 805 * @init_group_id: Initial group identifier. 806 * @metadata_cap: Metadata types that can be provided by the trap. 807 * 808 * Describes immutable attributes of packet traps that drivers register with 809 * devlink. 810 */ 811 struct devlink_trap { 812 enum devlink_trap_type type; 813 enum devlink_trap_action init_action; 814 bool generic; 815 u16 id; 816 const char *name; 817 u16 init_group_id; 818 u32 metadata_cap; 819 }; 820 821 /* All traps must be documented in 822 * Documentation/networking/devlink/devlink-trap.rst 823 */ 824 enum devlink_trap_generic_id { 825 DEVLINK_TRAP_GENERIC_ID_SMAC_MC, 826 DEVLINK_TRAP_GENERIC_ID_VLAN_TAG_MISMATCH, 827 DEVLINK_TRAP_GENERIC_ID_INGRESS_VLAN_FILTER, 828 DEVLINK_TRAP_GENERIC_ID_INGRESS_STP_FILTER, 829 DEVLINK_TRAP_GENERIC_ID_EMPTY_TX_LIST, 830 DEVLINK_TRAP_GENERIC_ID_PORT_LOOPBACK_FILTER, 831 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_ROUTE, 832 DEVLINK_TRAP_GENERIC_ID_TTL_ERROR, 833 DEVLINK_TRAP_GENERIC_ID_TAIL_DROP, 834 DEVLINK_TRAP_GENERIC_ID_NON_IP_PACKET, 835 DEVLINK_TRAP_GENERIC_ID_UC_DIP_MC_DMAC, 836 DEVLINK_TRAP_GENERIC_ID_DIP_LB, 837 DEVLINK_TRAP_GENERIC_ID_SIP_MC, 838 DEVLINK_TRAP_GENERIC_ID_SIP_LB, 839 DEVLINK_TRAP_GENERIC_ID_CORRUPTED_IP_HDR, 840 DEVLINK_TRAP_GENERIC_ID_IPV4_SIP_BC, 841 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_RESERVED_SCOPE, 842 DEVLINK_TRAP_GENERIC_ID_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE, 843 DEVLINK_TRAP_GENERIC_ID_MTU_ERROR, 844 DEVLINK_TRAP_GENERIC_ID_UNRESOLVED_NEIGH, 845 DEVLINK_TRAP_GENERIC_ID_RPF, 846 DEVLINK_TRAP_GENERIC_ID_REJECT_ROUTE, 847 DEVLINK_TRAP_GENERIC_ID_IPV4_LPM_UNICAST_MISS, 848 DEVLINK_TRAP_GENERIC_ID_IPV6_LPM_UNICAST_MISS, 849 DEVLINK_TRAP_GENERIC_ID_NON_ROUTABLE, 850 DEVLINK_TRAP_GENERIC_ID_DECAP_ERROR, 851 DEVLINK_TRAP_GENERIC_ID_OVERLAY_SMAC_MC, 852 DEVLINK_TRAP_GENERIC_ID_INGRESS_FLOW_ACTION_DROP, 853 DEVLINK_TRAP_GENERIC_ID_EGRESS_FLOW_ACTION_DROP, 854 DEVLINK_TRAP_GENERIC_ID_STP, 855 DEVLINK_TRAP_GENERIC_ID_LACP, 856 DEVLINK_TRAP_GENERIC_ID_LLDP, 857 DEVLINK_TRAP_GENERIC_ID_IGMP_QUERY, 858 DEVLINK_TRAP_GENERIC_ID_IGMP_V1_REPORT, 859 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_REPORT, 860 DEVLINK_TRAP_GENERIC_ID_IGMP_V3_REPORT, 861 DEVLINK_TRAP_GENERIC_ID_IGMP_V2_LEAVE, 862 DEVLINK_TRAP_GENERIC_ID_MLD_QUERY, 863 DEVLINK_TRAP_GENERIC_ID_MLD_V1_REPORT, 864 DEVLINK_TRAP_GENERIC_ID_MLD_V2_REPORT, 865 DEVLINK_TRAP_GENERIC_ID_MLD_V1_DONE, 866 DEVLINK_TRAP_GENERIC_ID_IPV4_DHCP, 867 DEVLINK_TRAP_GENERIC_ID_IPV6_DHCP, 868 DEVLINK_TRAP_GENERIC_ID_ARP_REQUEST, 869 DEVLINK_TRAP_GENERIC_ID_ARP_RESPONSE, 870 DEVLINK_TRAP_GENERIC_ID_ARP_OVERLAY, 871 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_SOLICIT, 872 DEVLINK_TRAP_GENERIC_ID_IPV6_NEIGH_ADVERT, 873 DEVLINK_TRAP_GENERIC_ID_IPV4_BFD, 874 DEVLINK_TRAP_GENERIC_ID_IPV6_BFD, 875 DEVLINK_TRAP_GENERIC_ID_IPV4_OSPF, 876 DEVLINK_TRAP_GENERIC_ID_IPV6_OSPF, 877 DEVLINK_TRAP_GENERIC_ID_IPV4_BGP, 878 DEVLINK_TRAP_GENERIC_ID_IPV6_BGP, 879 DEVLINK_TRAP_GENERIC_ID_IPV4_VRRP, 880 DEVLINK_TRAP_GENERIC_ID_IPV6_VRRP, 881 DEVLINK_TRAP_GENERIC_ID_IPV4_PIM, 882 DEVLINK_TRAP_GENERIC_ID_IPV6_PIM, 883 DEVLINK_TRAP_GENERIC_ID_UC_LB, 884 DEVLINK_TRAP_GENERIC_ID_LOCAL_ROUTE, 885 DEVLINK_TRAP_GENERIC_ID_EXTERNAL_ROUTE, 886 DEVLINK_TRAP_GENERIC_ID_IPV6_UC_DIP_LINK_LOCAL_SCOPE, 887 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_NODES, 888 DEVLINK_TRAP_GENERIC_ID_IPV6_DIP_ALL_ROUTERS, 889 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_SOLICIT, 890 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ADVERT, 891 DEVLINK_TRAP_GENERIC_ID_IPV6_REDIRECT, 892 DEVLINK_TRAP_GENERIC_ID_IPV4_ROUTER_ALERT, 893 DEVLINK_TRAP_GENERIC_ID_IPV6_ROUTER_ALERT, 894 DEVLINK_TRAP_GENERIC_ID_PTP_EVENT, 895 DEVLINK_TRAP_GENERIC_ID_PTP_GENERAL, 896 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_SAMPLE, 897 DEVLINK_TRAP_GENERIC_ID_FLOW_ACTION_TRAP, 898 DEVLINK_TRAP_GENERIC_ID_EARLY_DROP, 899 DEVLINK_TRAP_GENERIC_ID_VXLAN_PARSING, 900 DEVLINK_TRAP_GENERIC_ID_LLC_SNAP_PARSING, 901 DEVLINK_TRAP_GENERIC_ID_VLAN_PARSING, 902 DEVLINK_TRAP_GENERIC_ID_PPPOE_PPP_PARSING, 903 DEVLINK_TRAP_GENERIC_ID_MPLS_PARSING, 904 DEVLINK_TRAP_GENERIC_ID_ARP_PARSING, 905 DEVLINK_TRAP_GENERIC_ID_IP_1_PARSING, 906 DEVLINK_TRAP_GENERIC_ID_IP_N_PARSING, 907 DEVLINK_TRAP_GENERIC_ID_GRE_PARSING, 908 DEVLINK_TRAP_GENERIC_ID_UDP_PARSING, 909 DEVLINK_TRAP_GENERIC_ID_TCP_PARSING, 910 DEVLINK_TRAP_GENERIC_ID_IPSEC_PARSING, 911 DEVLINK_TRAP_GENERIC_ID_SCTP_PARSING, 912 DEVLINK_TRAP_GENERIC_ID_DCCP_PARSING, 913 DEVLINK_TRAP_GENERIC_ID_GTP_PARSING, 914 DEVLINK_TRAP_GENERIC_ID_ESP_PARSING, 915 DEVLINK_TRAP_GENERIC_ID_BLACKHOLE_NEXTHOP, 916 DEVLINK_TRAP_GENERIC_ID_DMAC_FILTER, 917 DEVLINK_TRAP_GENERIC_ID_EAPOL, 918 DEVLINK_TRAP_GENERIC_ID_LOCKED_PORT, 919 920 /* Add new generic trap IDs above */ 921 __DEVLINK_TRAP_GENERIC_ID_MAX, 922 DEVLINK_TRAP_GENERIC_ID_MAX = __DEVLINK_TRAP_GENERIC_ID_MAX - 1, 923 }; 924 925 /* All trap groups must be documented in 926 * Documentation/networking/devlink/devlink-trap.rst 927 */ 928 enum devlink_trap_group_generic_id { 929 DEVLINK_TRAP_GROUP_GENERIC_ID_L2_DROPS, 930 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_DROPS, 931 DEVLINK_TRAP_GROUP_GENERIC_ID_L3_EXCEPTIONS, 932 DEVLINK_TRAP_GROUP_GENERIC_ID_BUFFER_DROPS, 933 DEVLINK_TRAP_GROUP_GENERIC_ID_TUNNEL_DROPS, 934 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_DROPS, 935 DEVLINK_TRAP_GROUP_GENERIC_ID_STP, 936 DEVLINK_TRAP_GROUP_GENERIC_ID_LACP, 937 DEVLINK_TRAP_GROUP_GENERIC_ID_LLDP, 938 DEVLINK_TRAP_GROUP_GENERIC_ID_MC_SNOOPING, 939 DEVLINK_TRAP_GROUP_GENERIC_ID_DHCP, 940 DEVLINK_TRAP_GROUP_GENERIC_ID_NEIGH_DISCOVERY, 941 DEVLINK_TRAP_GROUP_GENERIC_ID_BFD, 942 DEVLINK_TRAP_GROUP_GENERIC_ID_OSPF, 943 DEVLINK_TRAP_GROUP_GENERIC_ID_BGP, 944 DEVLINK_TRAP_GROUP_GENERIC_ID_VRRP, 945 DEVLINK_TRAP_GROUP_GENERIC_ID_PIM, 946 DEVLINK_TRAP_GROUP_GENERIC_ID_UC_LB, 947 DEVLINK_TRAP_GROUP_GENERIC_ID_LOCAL_DELIVERY, 948 DEVLINK_TRAP_GROUP_GENERIC_ID_EXTERNAL_DELIVERY, 949 DEVLINK_TRAP_GROUP_GENERIC_ID_IPV6, 950 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_EVENT, 951 DEVLINK_TRAP_GROUP_GENERIC_ID_PTP_GENERAL, 952 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_SAMPLE, 953 DEVLINK_TRAP_GROUP_GENERIC_ID_ACL_TRAP, 954 DEVLINK_TRAP_GROUP_GENERIC_ID_PARSER_ERROR_DROPS, 955 DEVLINK_TRAP_GROUP_GENERIC_ID_EAPOL, 956 957 /* Add new generic trap group IDs above */ 958 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX, 959 DEVLINK_TRAP_GROUP_GENERIC_ID_MAX = 960 __DEVLINK_TRAP_GROUP_GENERIC_ID_MAX - 1, 961 }; 962 963 #define DEVLINK_TRAP_GENERIC_NAME_SMAC_MC \ 964 "source_mac_is_multicast" 965 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_TAG_MISMATCH \ 966 "vlan_tag_mismatch" 967 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_VLAN_FILTER \ 968 "ingress_vlan_filter" 969 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_STP_FILTER \ 970 "ingress_spanning_tree_filter" 971 #define DEVLINK_TRAP_GENERIC_NAME_EMPTY_TX_LIST \ 972 "port_list_is_empty" 973 #define DEVLINK_TRAP_GENERIC_NAME_PORT_LOOPBACK_FILTER \ 974 "port_loopback_filter" 975 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_ROUTE \ 976 "blackhole_route" 977 #define DEVLINK_TRAP_GENERIC_NAME_TTL_ERROR \ 978 "ttl_value_is_too_small" 979 #define DEVLINK_TRAP_GENERIC_NAME_TAIL_DROP \ 980 "tail_drop" 981 #define DEVLINK_TRAP_GENERIC_NAME_NON_IP_PACKET \ 982 "non_ip" 983 #define DEVLINK_TRAP_GENERIC_NAME_UC_DIP_MC_DMAC \ 984 "uc_dip_over_mc_dmac" 985 #define DEVLINK_TRAP_GENERIC_NAME_DIP_LB \ 986 "dip_is_loopback_address" 987 #define DEVLINK_TRAP_GENERIC_NAME_SIP_MC \ 988 "sip_is_mc" 989 #define DEVLINK_TRAP_GENERIC_NAME_SIP_LB \ 990 "sip_is_loopback_address" 991 #define DEVLINK_TRAP_GENERIC_NAME_CORRUPTED_IP_HDR \ 992 "ip_header_corrupted" 993 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_SIP_BC \ 994 "ipv4_sip_is_limited_bc" 995 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_RESERVED_SCOPE \ 996 "ipv6_mc_dip_reserved_scope" 997 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_MC_DIP_INTERFACE_LOCAL_SCOPE \ 998 "ipv6_mc_dip_interface_local_scope" 999 #define DEVLINK_TRAP_GENERIC_NAME_MTU_ERROR \ 1000 "mtu_value_is_too_small" 1001 #define DEVLINK_TRAP_GENERIC_NAME_UNRESOLVED_NEIGH \ 1002 "unresolved_neigh" 1003 #define DEVLINK_TRAP_GENERIC_NAME_RPF \ 1004 "mc_reverse_path_forwarding" 1005 #define DEVLINK_TRAP_GENERIC_NAME_REJECT_ROUTE \ 1006 "reject_route" 1007 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_LPM_UNICAST_MISS \ 1008 "ipv4_lpm_miss" 1009 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_LPM_UNICAST_MISS \ 1010 "ipv6_lpm_miss" 1011 #define DEVLINK_TRAP_GENERIC_NAME_NON_ROUTABLE \ 1012 "non_routable_packet" 1013 #define DEVLINK_TRAP_GENERIC_NAME_DECAP_ERROR \ 1014 "decap_error" 1015 #define DEVLINK_TRAP_GENERIC_NAME_OVERLAY_SMAC_MC \ 1016 "overlay_smac_is_mc" 1017 #define DEVLINK_TRAP_GENERIC_NAME_INGRESS_FLOW_ACTION_DROP \ 1018 "ingress_flow_action_drop" 1019 #define DEVLINK_TRAP_GENERIC_NAME_EGRESS_FLOW_ACTION_DROP \ 1020 "egress_flow_action_drop" 1021 #define DEVLINK_TRAP_GENERIC_NAME_STP \ 1022 "stp" 1023 #define DEVLINK_TRAP_GENERIC_NAME_LACP \ 1024 "lacp" 1025 #define DEVLINK_TRAP_GENERIC_NAME_LLDP \ 1026 "lldp" 1027 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_QUERY \ 1028 "igmp_query" 1029 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V1_REPORT \ 1030 "igmp_v1_report" 1031 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_REPORT \ 1032 "igmp_v2_report" 1033 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V3_REPORT \ 1034 "igmp_v3_report" 1035 #define DEVLINK_TRAP_GENERIC_NAME_IGMP_V2_LEAVE \ 1036 "igmp_v2_leave" 1037 #define DEVLINK_TRAP_GENERIC_NAME_MLD_QUERY \ 1038 "mld_query" 1039 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_REPORT \ 1040 "mld_v1_report" 1041 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V2_REPORT \ 1042 "mld_v2_report" 1043 #define DEVLINK_TRAP_GENERIC_NAME_MLD_V1_DONE \ 1044 "mld_v1_done" 1045 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_DHCP \ 1046 "ipv4_dhcp" 1047 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DHCP \ 1048 "ipv6_dhcp" 1049 #define DEVLINK_TRAP_GENERIC_NAME_ARP_REQUEST \ 1050 "arp_request" 1051 #define DEVLINK_TRAP_GENERIC_NAME_ARP_RESPONSE \ 1052 "arp_response" 1053 #define DEVLINK_TRAP_GENERIC_NAME_ARP_OVERLAY \ 1054 "arp_overlay" 1055 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_SOLICIT \ 1056 "ipv6_neigh_solicit" 1057 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_NEIGH_ADVERT \ 1058 "ipv6_neigh_advert" 1059 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BFD \ 1060 "ipv4_bfd" 1061 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BFD \ 1062 "ipv6_bfd" 1063 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_OSPF \ 1064 "ipv4_ospf" 1065 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_OSPF \ 1066 "ipv6_ospf" 1067 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_BGP \ 1068 "ipv4_bgp" 1069 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_BGP \ 1070 "ipv6_bgp" 1071 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_VRRP \ 1072 "ipv4_vrrp" 1073 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_VRRP \ 1074 "ipv6_vrrp" 1075 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_PIM \ 1076 "ipv4_pim" 1077 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_PIM \ 1078 "ipv6_pim" 1079 #define DEVLINK_TRAP_GENERIC_NAME_UC_LB \ 1080 "uc_loopback" 1081 #define DEVLINK_TRAP_GENERIC_NAME_LOCAL_ROUTE \ 1082 "local_route" 1083 #define DEVLINK_TRAP_GENERIC_NAME_EXTERNAL_ROUTE \ 1084 "external_route" 1085 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_UC_DIP_LINK_LOCAL_SCOPE \ 1086 "ipv6_uc_dip_link_local_scope" 1087 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_NODES \ 1088 "ipv6_dip_all_nodes" 1089 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_DIP_ALL_ROUTERS \ 1090 "ipv6_dip_all_routers" 1091 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_SOLICIT \ 1092 "ipv6_router_solicit" 1093 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ADVERT \ 1094 "ipv6_router_advert" 1095 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_REDIRECT \ 1096 "ipv6_redirect" 1097 #define DEVLINK_TRAP_GENERIC_NAME_IPV4_ROUTER_ALERT \ 1098 "ipv4_router_alert" 1099 #define DEVLINK_TRAP_GENERIC_NAME_IPV6_ROUTER_ALERT \ 1100 "ipv6_router_alert" 1101 #define DEVLINK_TRAP_GENERIC_NAME_PTP_EVENT \ 1102 "ptp_event" 1103 #define DEVLINK_TRAP_GENERIC_NAME_PTP_GENERAL \ 1104 "ptp_general" 1105 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_SAMPLE \ 1106 "flow_action_sample" 1107 #define DEVLINK_TRAP_GENERIC_NAME_FLOW_ACTION_TRAP \ 1108 "flow_action_trap" 1109 #define DEVLINK_TRAP_GENERIC_NAME_EARLY_DROP \ 1110 "early_drop" 1111 #define DEVLINK_TRAP_GENERIC_NAME_VXLAN_PARSING \ 1112 "vxlan_parsing" 1113 #define DEVLINK_TRAP_GENERIC_NAME_LLC_SNAP_PARSING \ 1114 "llc_snap_parsing" 1115 #define DEVLINK_TRAP_GENERIC_NAME_VLAN_PARSING \ 1116 "vlan_parsing" 1117 #define DEVLINK_TRAP_GENERIC_NAME_PPPOE_PPP_PARSING \ 1118 "pppoe_ppp_parsing" 1119 #define DEVLINK_TRAP_GENERIC_NAME_MPLS_PARSING \ 1120 "mpls_parsing" 1121 #define DEVLINK_TRAP_GENERIC_NAME_ARP_PARSING \ 1122 "arp_parsing" 1123 #define DEVLINK_TRAP_GENERIC_NAME_IP_1_PARSING \ 1124 "ip_1_parsing" 1125 #define DEVLINK_TRAP_GENERIC_NAME_IP_N_PARSING \ 1126 "ip_n_parsing" 1127 #define DEVLINK_TRAP_GENERIC_NAME_GRE_PARSING \ 1128 "gre_parsing" 1129 #define DEVLINK_TRAP_GENERIC_NAME_UDP_PARSING \ 1130 "udp_parsing" 1131 #define DEVLINK_TRAP_GENERIC_NAME_TCP_PARSING \ 1132 "tcp_parsing" 1133 #define DEVLINK_TRAP_GENERIC_NAME_IPSEC_PARSING \ 1134 "ipsec_parsing" 1135 #define DEVLINK_TRAP_GENERIC_NAME_SCTP_PARSING \ 1136 "sctp_parsing" 1137 #define DEVLINK_TRAP_GENERIC_NAME_DCCP_PARSING \ 1138 "dccp_parsing" 1139 #define DEVLINK_TRAP_GENERIC_NAME_GTP_PARSING \ 1140 "gtp_parsing" 1141 #define DEVLINK_TRAP_GENERIC_NAME_ESP_PARSING \ 1142 "esp_parsing" 1143 #define DEVLINK_TRAP_GENERIC_NAME_BLACKHOLE_NEXTHOP \ 1144 "blackhole_nexthop" 1145 #define DEVLINK_TRAP_GENERIC_NAME_DMAC_FILTER \ 1146 "dmac_filter" 1147 #define DEVLINK_TRAP_GENERIC_NAME_EAPOL \ 1148 "eapol" 1149 #define DEVLINK_TRAP_GENERIC_NAME_LOCKED_PORT \ 1150 "locked_port" 1151 1152 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L2_DROPS \ 1153 "l2_drops" 1154 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_DROPS \ 1155 "l3_drops" 1156 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_L3_EXCEPTIONS \ 1157 "l3_exceptions" 1158 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BUFFER_DROPS \ 1159 "buffer_drops" 1160 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_TUNNEL_DROPS \ 1161 "tunnel_drops" 1162 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_DROPS \ 1163 "acl_drops" 1164 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_STP \ 1165 "stp" 1166 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LACP \ 1167 "lacp" 1168 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LLDP \ 1169 "lldp" 1170 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_MC_SNOOPING \ 1171 "mc_snooping" 1172 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_DHCP \ 1173 "dhcp" 1174 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_NEIGH_DISCOVERY \ 1175 "neigh_discovery" 1176 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BFD \ 1177 "bfd" 1178 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_OSPF \ 1179 "ospf" 1180 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_BGP \ 1181 "bgp" 1182 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_VRRP \ 1183 "vrrp" 1184 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PIM \ 1185 "pim" 1186 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_UC_LB \ 1187 "uc_loopback" 1188 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_LOCAL_DELIVERY \ 1189 "local_delivery" 1190 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EXTERNAL_DELIVERY \ 1191 "external_delivery" 1192 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_IPV6 \ 1193 "ipv6" 1194 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_EVENT \ 1195 "ptp_event" 1196 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PTP_GENERAL \ 1197 "ptp_general" 1198 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_SAMPLE \ 1199 "acl_sample" 1200 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_ACL_TRAP \ 1201 "acl_trap" 1202 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_PARSER_ERROR_DROPS \ 1203 "parser_error_drops" 1204 #define DEVLINK_TRAP_GROUP_GENERIC_NAME_EAPOL \ 1205 "eapol" 1206 1207 #define DEVLINK_TRAP_GENERIC(_type, _init_action, _id, _group_id, \ 1208 _metadata_cap) \ 1209 { \ 1210 .type = DEVLINK_TRAP_TYPE_##_type, \ 1211 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ 1212 .generic = true, \ 1213 .id = DEVLINK_TRAP_GENERIC_ID_##_id, \ 1214 .name = DEVLINK_TRAP_GENERIC_NAME_##_id, \ 1215 .init_group_id = _group_id, \ 1216 .metadata_cap = _metadata_cap, \ 1217 } 1218 1219 #define DEVLINK_TRAP_DRIVER(_type, _init_action, _id, _name, _group_id, \ 1220 _metadata_cap) \ 1221 { \ 1222 .type = DEVLINK_TRAP_TYPE_##_type, \ 1223 .init_action = DEVLINK_TRAP_ACTION_##_init_action, \ 1224 .generic = false, \ 1225 .id = _id, \ 1226 .name = _name, \ 1227 .init_group_id = _group_id, \ 1228 .metadata_cap = _metadata_cap, \ 1229 } 1230 1231 #define DEVLINK_TRAP_GROUP_GENERIC(_id, _policer_id) \ 1232 { \ 1233 .name = DEVLINK_TRAP_GROUP_GENERIC_NAME_##_id, \ 1234 .id = DEVLINK_TRAP_GROUP_GENERIC_ID_##_id, \ 1235 .generic = true, \ 1236 .init_policer_id = _policer_id, \ 1237 } 1238 1239 #define DEVLINK_TRAP_POLICER(_id, _rate, _burst, _max_rate, _min_rate, \ 1240 _max_burst, _min_burst) \ 1241 { \ 1242 .id = _id, \ 1243 .init_rate = _rate, \ 1244 .init_burst = _burst, \ 1245 .max_rate = _max_rate, \ 1246 .min_rate = _min_rate, \ 1247 .max_burst = _max_burst, \ 1248 .min_burst = _min_burst, \ 1249 } 1250 1251 enum { 1252 /* device supports reload operations */ 1253 DEVLINK_F_RELOAD = 1UL << 0, 1254 }; 1255 1256 struct devlink_ops { 1257 /** 1258 * @supported_flash_update_params: 1259 * mask of parameters supported by the driver's .flash_update 1260 * implemementation. 1261 */ 1262 u32 supported_flash_update_params; 1263 unsigned long reload_actions; 1264 unsigned long reload_limits; 1265 int (*reload_down)(struct devlink *devlink, bool netns_change, 1266 enum devlink_reload_action action, 1267 enum devlink_reload_limit limit, 1268 struct netlink_ext_ack *extack); 1269 int (*reload_up)(struct devlink *devlink, enum devlink_reload_action action, 1270 enum devlink_reload_limit limit, u32 *actions_performed, 1271 struct netlink_ext_ack *extack); 1272 int (*port_type_set)(struct devlink_port *devlink_port, 1273 enum devlink_port_type port_type); 1274 int (*port_split)(struct devlink *devlink, struct devlink_port *port, 1275 unsigned int count, struct netlink_ext_ack *extack); 1276 int (*port_unsplit)(struct devlink *devlink, struct devlink_port *port, 1277 struct netlink_ext_ack *extack); 1278 int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index, 1279 u16 pool_index, 1280 struct devlink_sb_pool_info *pool_info); 1281 int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index, 1282 u16 pool_index, u32 size, 1283 enum devlink_sb_threshold_type threshold_type, 1284 struct netlink_ext_ack *extack); 1285 int (*sb_port_pool_get)(struct devlink_port *devlink_port, 1286 unsigned int sb_index, u16 pool_index, 1287 u32 *p_threshold); 1288 int (*sb_port_pool_set)(struct devlink_port *devlink_port, 1289 unsigned int sb_index, u16 pool_index, 1290 u32 threshold, struct netlink_ext_ack *extack); 1291 int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port, 1292 unsigned int sb_index, 1293 u16 tc_index, 1294 enum devlink_sb_pool_type pool_type, 1295 u16 *p_pool_index, u32 *p_threshold); 1296 int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port, 1297 unsigned int sb_index, 1298 u16 tc_index, 1299 enum devlink_sb_pool_type pool_type, 1300 u16 pool_index, u32 threshold, 1301 struct netlink_ext_ack *extack); 1302 int (*sb_occ_snapshot)(struct devlink *devlink, 1303 unsigned int sb_index); 1304 int (*sb_occ_max_clear)(struct devlink *devlink, 1305 unsigned int sb_index); 1306 int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port, 1307 unsigned int sb_index, u16 pool_index, 1308 u32 *p_cur, u32 *p_max); 1309 int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port, 1310 unsigned int sb_index, 1311 u16 tc_index, 1312 enum devlink_sb_pool_type pool_type, 1313 u32 *p_cur, u32 *p_max); 1314 1315 int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode); 1316 int (*eswitch_mode_set)(struct devlink *devlink, u16 mode, 1317 struct netlink_ext_ack *extack); 1318 int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode); 1319 int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode, 1320 struct netlink_ext_ack *extack); 1321 int (*eswitch_encap_mode_get)(struct devlink *devlink, 1322 enum devlink_eswitch_encap_mode *p_encap_mode); 1323 int (*eswitch_encap_mode_set)(struct devlink *devlink, 1324 enum devlink_eswitch_encap_mode encap_mode, 1325 struct netlink_ext_ack *extack); 1326 int (*info_get)(struct devlink *devlink, struct devlink_info_req *req, 1327 struct netlink_ext_ack *extack); 1328 /** 1329 * @flash_update: Device flash update function 1330 * 1331 * Used to perform a flash update for the device. The set of 1332 * parameters supported by the driver should be set in 1333 * supported_flash_update_params. 1334 */ 1335 int (*flash_update)(struct devlink *devlink, 1336 struct devlink_flash_update_params *params, 1337 struct netlink_ext_ack *extack); 1338 /** 1339 * @trap_init: Trap initialization function. 1340 * 1341 * Should be used by device drivers to initialize the trap in the 1342 * underlying device. Drivers should also store the provided trap 1343 * context, so that they could efficiently pass it to 1344 * devlink_trap_report() when the trap is triggered. 1345 */ 1346 int (*trap_init)(struct devlink *devlink, 1347 const struct devlink_trap *trap, void *trap_ctx); 1348 /** 1349 * @trap_fini: Trap de-initialization function. 1350 * 1351 * Should be used by device drivers to de-initialize the trap in the 1352 * underlying device. 1353 */ 1354 void (*trap_fini)(struct devlink *devlink, 1355 const struct devlink_trap *trap, void *trap_ctx); 1356 /** 1357 * @trap_action_set: Trap action set function. 1358 */ 1359 int (*trap_action_set)(struct devlink *devlink, 1360 const struct devlink_trap *trap, 1361 enum devlink_trap_action action, 1362 struct netlink_ext_ack *extack); 1363 /** 1364 * @trap_group_init: Trap group initialization function. 1365 * 1366 * Should be used by device drivers to initialize the trap group in the 1367 * underlying device. 1368 */ 1369 int (*trap_group_init)(struct devlink *devlink, 1370 const struct devlink_trap_group *group); 1371 /** 1372 * @trap_group_set: Trap group parameters set function. 1373 * 1374 * Note: @policer can be NULL when a policer is being unbound from 1375 * @group. 1376 */ 1377 int (*trap_group_set)(struct devlink *devlink, 1378 const struct devlink_trap_group *group, 1379 const struct devlink_trap_policer *policer, 1380 struct netlink_ext_ack *extack); 1381 /** 1382 * @trap_group_action_set: Trap group action set function. 1383 * 1384 * If this callback is populated, it will take precedence over looping 1385 * over all traps in a group and calling .trap_action_set(). 1386 */ 1387 int (*trap_group_action_set)(struct devlink *devlink, 1388 const struct devlink_trap_group *group, 1389 enum devlink_trap_action action, 1390 struct netlink_ext_ack *extack); 1391 /** 1392 * @trap_drop_counter_get: Trap drop counter get function. 1393 * 1394 * Should be used by device drivers to report number of packets 1395 * that have been dropped, and cannot be passed to the devlink 1396 * subsystem by the underlying device. 1397 */ 1398 int (*trap_drop_counter_get)(struct devlink *devlink, 1399 const struct devlink_trap *trap, 1400 u64 *p_drops); 1401 /** 1402 * @trap_policer_init: Trap policer initialization function. 1403 * 1404 * Should be used by device drivers to initialize the trap policer in 1405 * the underlying device. 1406 */ 1407 int (*trap_policer_init)(struct devlink *devlink, 1408 const struct devlink_trap_policer *policer); 1409 /** 1410 * @trap_policer_fini: Trap policer de-initialization function. 1411 * 1412 * Should be used by device drivers to de-initialize the trap policer 1413 * in the underlying device. 1414 */ 1415 void (*trap_policer_fini)(struct devlink *devlink, 1416 const struct devlink_trap_policer *policer); 1417 /** 1418 * @trap_policer_set: Trap policer parameters set function. 1419 */ 1420 int (*trap_policer_set)(struct devlink *devlink, 1421 const struct devlink_trap_policer *policer, 1422 u64 rate, u64 burst, 1423 struct netlink_ext_ack *extack); 1424 /** 1425 * @trap_policer_counter_get: Trap policer counter get function. 1426 * 1427 * Should be used by device drivers to report number of packets dropped 1428 * by the policer. 1429 */ 1430 int (*trap_policer_counter_get)(struct devlink *devlink, 1431 const struct devlink_trap_policer *policer, 1432 u64 *p_drops); 1433 /** 1434 * @port_function_hw_addr_get: Port function's hardware address get function. 1435 * 1436 * Should be used by device drivers to report the hardware address of a function managed 1437 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port 1438 * function handling for a particular port. 1439 * 1440 * Note: @extack can be NULL when port notifier queries the port function. 1441 */ 1442 int (*port_function_hw_addr_get)(struct devlink_port *port, u8 *hw_addr, 1443 int *hw_addr_len, 1444 struct netlink_ext_ack *extack); 1445 /** 1446 * @port_function_hw_addr_set: Port function's hardware address set function. 1447 * 1448 * Should be used by device drivers to set the hardware address of a function managed 1449 * by the devlink port. Driver should return -EOPNOTSUPP if it doesn't support port 1450 * function handling for a particular port. 1451 */ 1452 int (*port_function_hw_addr_set)(struct devlink_port *port, 1453 const u8 *hw_addr, int hw_addr_len, 1454 struct netlink_ext_ack *extack); 1455 /** 1456 * @port_fn_roce_get: Port function's roce get function. 1457 * 1458 * Query RoCE state of a function managed by the devlink port. 1459 * Return -EOPNOTSUPP if port function RoCE handling is not supported. 1460 */ 1461 int (*port_fn_roce_get)(struct devlink_port *devlink_port, 1462 bool *is_enable, 1463 struct netlink_ext_ack *extack); 1464 /** 1465 * @port_fn_roce_set: Port function's roce set function. 1466 * 1467 * Enable/Disable the RoCE state of a function managed by the devlink 1468 * port. 1469 * Return -EOPNOTSUPP if port function RoCE handling is not supported. 1470 */ 1471 int (*port_fn_roce_set)(struct devlink_port *devlink_port, 1472 bool enable, struct netlink_ext_ack *extack); 1473 /** 1474 * @port_fn_migratable_get: Port function's migratable get function. 1475 * 1476 * Query migratable state of a function managed by the devlink port. 1477 * Return -EOPNOTSUPP if port function migratable handling is not 1478 * supported. 1479 */ 1480 int (*port_fn_migratable_get)(struct devlink_port *devlink_port, 1481 bool *is_enable, 1482 struct netlink_ext_ack *extack); 1483 /** 1484 * @port_fn_migratable_set: Port function's migratable set function. 1485 * 1486 * Enable/Disable migratable state of a function managed by the devlink 1487 * port. 1488 * Return -EOPNOTSUPP if port function migratable handling is not 1489 * supported. 1490 */ 1491 int (*port_fn_migratable_set)(struct devlink_port *devlink_port, 1492 bool enable, 1493 struct netlink_ext_ack *extack); 1494 /** 1495 * port_new() - Add a new port function of a specified flavor 1496 * @devlink: Devlink instance 1497 * @attrs: attributes of the new port 1498 * @extack: extack for reporting error messages 1499 * @new_port_index: index of the new port 1500 * 1501 * Devlink core will call this device driver function upon user request 1502 * to create a new port function of a specified flavor and optional 1503 * attributes 1504 * 1505 * Notes: 1506 * - Called without devlink instance lock being held. Drivers must 1507 * implement own means of synchronization 1508 * - On success, drivers must register a port with devlink core 1509 * 1510 * Return: 0 on success, negative value otherwise. 1511 */ 1512 int (*port_new)(struct devlink *devlink, 1513 const struct devlink_port_new_attrs *attrs, 1514 struct netlink_ext_ack *extack, 1515 unsigned int *new_port_index); 1516 /** 1517 * port_del() - Delete a port function 1518 * @devlink: Devlink instance 1519 * @port_index: port function index to delete 1520 * @extack: extack for reporting error messages 1521 * 1522 * Devlink core will call this device driver function upon user request 1523 * to delete a previously created port function 1524 * 1525 * Notes: 1526 * - Called without devlink instance lock being held. Drivers must 1527 * implement own means of synchronization 1528 * - On success, drivers must unregister the corresponding devlink 1529 * port 1530 * 1531 * Return: 0 on success, negative value otherwise. 1532 */ 1533 int (*port_del)(struct devlink *devlink, unsigned int port_index, 1534 struct netlink_ext_ack *extack); 1535 /** 1536 * port_fn_state_get() - Get the state of a port function 1537 * @devlink: Devlink instance 1538 * @port: The devlink port 1539 * @state: Admin configured state 1540 * @opstate: Current operational state 1541 * @extack: extack for reporting error messages 1542 * 1543 * Reports the admin and operational state of a devlink port function 1544 * 1545 * Return: 0 on success, negative value otherwise. 1546 */ 1547 int (*port_fn_state_get)(struct devlink_port *port, 1548 enum devlink_port_fn_state *state, 1549 enum devlink_port_fn_opstate *opstate, 1550 struct netlink_ext_ack *extack); 1551 /** 1552 * port_fn_state_set() - Set the admin state of a port function 1553 * @devlink: Devlink instance 1554 * @port: The devlink port 1555 * @state: Admin state 1556 * @extack: extack for reporting error messages 1557 * 1558 * Set the admin state of a devlink port function 1559 * 1560 * Return: 0 on success, negative value otherwise. 1561 */ 1562 int (*port_fn_state_set)(struct devlink_port *port, 1563 enum devlink_port_fn_state state, 1564 struct netlink_ext_ack *extack); 1565 1566 /** 1567 * Rate control callbacks. 1568 */ 1569 int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv, 1570 u64 tx_share, struct netlink_ext_ack *extack); 1571 int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv, 1572 u64 tx_max, struct netlink_ext_ack *extack); 1573 int (*rate_leaf_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv, 1574 u32 tx_priority, struct netlink_ext_ack *extack); 1575 int (*rate_leaf_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv, 1576 u32 tx_weight, struct netlink_ext_ack *extack); 1577 int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv, 1578 u64 tx_share, struct netlink_ext_ack *extack); 1579 int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv, 1580 u64 tx_max, struct netlink_ext_ack *extack); 1581 int (*rate_node_tx_priority_set)(struct devlink_rate *devlink_rate, void *priv, 1582 u32 tx_priority, struct netlink_ext_ack *extack); 1583 int (*rate_node_tx_weight_set)(struct devlink_rate *devlink_rate, void *priv, 1584 u32 tx_weight, struct netlink_ext_ack *extack); 1585 int (*rate_node_new)(struct devlink_rate *rate_node, void **priv, 1586 struct netlink_ext_ack *extack); 1587 int (*rate_node_del)(struct devlink_rate *rate_node, void *priv, 1588 struct netlink_ext_ack *extack); 1589 int (*rate_leaf_parent_set)(struct devlink_rate *child, 1590 struct devlink_rate *parent, 1591 void *priv_child, void *priv_parent, 1592 struct netlink_ext_ack *extack); 1593 int (*rate_node_parent_set)(struct devlink_rate *child, 1594 struct devlink_rate *parent, 1595 void *priv_child, void *priv_parent, 1596 struct netlink_ext_ack *extack); 1597 /** 1598 * selftests_check() - queries if selftest is supported 1599 * @devlink: devlink instance 1600 * @id: test index 1601 * @extack: extack for reporting error messages 1602 * 1603 * Return: true if test is supported by the driver 1604 */ 1605 bool (*selftest_check)(struct devlink *devlink, unsigned int id, 1606 struct netlink_ext_ack *extack); 1607 /** 1608 * selftest_run() - Runs a selftest 1609 * @devlink: devlink instance 1610 * @id: test index 1611 * @extack: extack for reporting error messages 1612 * 1613 * Return: status of the test 1614 */ 1615 enum devlink_selftest_status 1616 (*selftest_run)(struct devlink *devlink, unsigned int id, 1617 struct netlink_ext_ack *extack); 1618 }; 1619 1620 void *devlink_priv(struct devlink *devlink); 1621 struct devlink *priv_to_devlink(void *priv); 1622 struct device *devlink_to_dev(const struct devlink *devlink); 1623 1624 /* Devlink instance explicit locking */ 1625 void devl_lock(struct devlink *devlink); 1626 int devl_trylock(struct devlink *devlink); 1627 void devl_unlock(struct devlink *devlink); 1628 void devl_assert_locked(struct devlink *devlink); 1629 bool devl_lock_is_held(struct devlink *devlink); 1630 1631 struct ib_device; 1632 1633 struct net *devlink_net(const struct devlink *devlink); 1634 /* This call is intended for software devices that can create 1635 * devlink instances in other namespaces than init_net. 1636 * 1637 * Drivers that operate on real HW must use devlink_alloc() instead. 1638 */ 1639 struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, 1640 size_t priv_size, struct net *net, 1641 struct device *dev); 1642 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops, 1643 size_t priv_size, 1644 struct device *dev) 1645 { 1646 return devlink_alloc_ns(ops, priv_size, &init_net, dev); 1647 } 1648 1649 int devl_register(struct devlink *devlink); 1650 void devl_unregister(struct devlink *devlink); 1651 void devlink_register(struct devlink *devlink); 1652 void devlink_unregister(struct devlink *devlink); 1653 void devlink_free(struct devlink *devlink); 1654 void devlink_port_init(struct devlink *devlink, 1655 struct devlink_port *devlink_port); 1656 void devlink_port_fini(struct devlink_port *devlink_port); 1657 int devl_port_register(struct devlink *devlink, 1658 struct devlink_port *devlink_port, 1659 unsigned int port_index); 1660 int devlink_port_register(struct devlink *devlink, 1661 struct devlink_port *devlink_port, 1662 unsigned int port_index); 1663 void devl_port_unregister(struct devlink_port *devlink_port); 1664 void devlink_port_unregister(struct devlink_port *devlink_port); 1665 void devlink_port_type_eth_set(struct devlink_port *devlink_port); 1666 void devlink_port_type_ib_set(struct devlink_port *devlink_port, 1667 struct ib_device *ibdev); 1668 void devlink_port_type_clear(struct devlink_port *devlink_port); 1669 void devlink_port_attrs_set(struct devlink_port *devlink_port, 1670 struct devlink_port_attrs *devlink_port_attrs); 1671 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 controller, 1672 u16 pf, bool external); 1673 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller, 1674 u16 pf, u16 vf, bool external); 1675 void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, 1676 u32 controller, u16 pf, u32 sf, 1677 bool external); 1678 struct devlink_rate * 1679 devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name, 1680 struct devlink_rate *parent); 1681 int 1682 devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv, 1683 struct devlink_rate *parent); 1684 void devl_rate_leaf_destroy(struct devlink_port *devlink_port); 1685 void devl_rate_nodes_destroy(struct devlink *devlink); 1686 void devlink_port_linecard_set(struct devlink_port *devlink_port, 1687 struct devlink_linecard *linecard); 1688 struct devlink_linecard * 1689 devl_linecard_create(struct devlink *devlink, unsigned int linecard_index, 1690 const struct devlink_linecard_ops *ops, void *priv); 1691 void devl_linecard_destroy(struct devlink_linecard *linecard); 1692 void devlink_linecard_provision_set(struct devlink_linecard *linecard, 1693 const char *type); 1694 void devlink_linecard_provision_clear(struct devlink_linecard *linecard); 1695 void devlink_linecard_provision_fail(struct devlink_linecard *linecard); 1696 void devlink_linecard_activate(struct devlink_linecard *linecard); 1697 void devlink_linecard_deactivate(struct devlink_linecard *linecard); 1698 void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, 1699 struct devlink *nested_devlink); 1700 int devl_sb_register(struct devlink *devlink, unsigned int sb_index, 1701 u32 size, u16 ingress_pools_count, 1702 u16 egress_pools_count, u16 ingress_tc_count, 1703 u16 egress_tc_count); 1704 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, 1705 u32 size, u16 ingress_pools_count, 1706 u16 egress_pools_count, u16 ingress_tc_count, 1707 u16 egress_tc_count); 1708 void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index); 1709 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); 1710 int devl_dpipe_table_register(struct devlink *devlink, 1711 const char *table_name, 1712 struct devlink_dpipe_table_ops *table_ops, 1713 void *priv, bool counter_control_extern); 1714 void devl_dpipe_table_unregister(struct devlink *devlink, 1715 const char *table_name); 1716 void devl_dpipe_headers_register(struct devlink *devlink, 1717 struct devlink_dpipe_headers *dpipe_headers); 1718 void devl_dpipe_headers_unregister(struct devlink *devlink); 1719 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, 1720 const char *table_name); 1721 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx); 1722 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx, 1723 struct devlink_dpipe_entry *entry); 1724 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx); 1725 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry); 1726 int devlink_dpipe_action_put(struct sk_buff *skb, 1727 struct devlink_dpipe_action *action); 1728 int devlink_dpipe_match_put(struct sk_buff *skb, 1729 struct devlink_dpipe_match *match); 1730 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; 1731 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; 1732 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; 1733 1734 int devl_resource_register(struct devlink *devlink, 1735 const char *resource_name, 1736 u64 resource_size, 1737 u64 resource_id, 1738 u64 parent_resource_id, 1739 const struct devlink_resource_size_params *size_params); 1740 int devlink_resource_register(struct devlink *devlink, 1741 const char *resource_name, 1742 u64 resource_size, 1743 u64 resource_id, 1744 u64 parent_resource_id, 1745 const struct devlink_resource_size_params *size_params); 1746 void devl_resources_unregister(struct devlink *devlink); 1747 void devlink_resources_unregister(struct devlink *devlink); 1748 int devl_resource_size_get(struct devlink *devlink, 1749 u64 resource_id, 1750 u64 *p_resource_size); 1751 int devl_dpipe_table_resource_set(struct devlink *devlink, 1752 const char *table_name, u64 resource_id, 1753 u64 resource_units); 1754 int devlink_dpipe_table_resource_set(struct devlink *devlink, 1755 const char *table_name, u64 resource_id, 1756 u64 resource_units); 1757 void devl_resource_occ_get_register(struct devlink *devlink, 1758 u64 resource_id, 1759 devlink_resource_occ_get_t *occ_get, 1760 void *occ_get_priv); 1761 void devlink_resource_occ_get_register(struct devlink *devlink, 1762 u64 resource_id, 1763 devlink_resource_occ_get_t *occ_get, 1764 void *occ_get_priv); 1765 void devl_resource_occ_get_unregister(struct devlink *devlink, 1766 u64 resource_id); 1767 1768 void devlink_resource_occ_get_unregister(struct devlink *devlink, 1769 u64 resource_id); 1770 int devl_params_register(struct devlink *devlink, 1771 const struct devlink_param *params, 1772 size_t params_count); 1773 int devlink_params_register(struct devlink *devlink, 1774 const struct devlink_param *params, 1775 size_t params_count); 1776 void devl_params_unregister(struct devlink *devlink, 1777 const struct devlink_param *params, 1778 size_t params_count); 1779 void devlink_params_unregister(struct devlink *devlink, 1780 const struct devlink_param *params, 1781 size_t params_count); 1782 int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id, 1783 union devlink_param_value *init_val); 1784 void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id, 1785 union devlink_param_value init_val); 1786 void devl_param_value_changed(struct devlink *devlink, u32 param_id); 1787 struct devlink_region *devl_region_create(struct devlink *devlink, 1788 const struct devlink_region_ops *ops, 1789 u32 region_max_snapshots, 1790 u64 region_size); 1791 struct devlink_region * 1792 devlink_region_create(struct devlink *devlink, 1793 const struct devlink_region_ops *ops, 1794 u32 region_max_snapshots, u64 region_size); 1795 struct devlink_region * 1796 devlink_port_region_create(struct devlink_port *port, 1797 const struct devlink_port_region_ops *ops, 1798 u32 region_max_snapshots, u64 region_size); 1799 void devl_region_destroy(struct devlink_region *region); 1800 void devlink_region_destroy(struct devlink_region *region); 1801 void devlink_port_region_destroy(struct devlink_region *region); 1802 1803 int devlink_region_snapshot_id_get(struct devlink *devlink, u32 *id); 1804 void devlink_region_snapshot_id_put(struct devlink *devlink, u32 id); 1805 int devlink_region_snapshot_create(struct devlink_region *region, 1806 u8 *data, u32 snapshot_id); 1807 int devlink_info_serial_number_put(struct devlink_info_req *req, 1808 const char *sn); 1809 int devlink_info_board_serial_number_put(struct devlink_info_req *req, 1810 const char *bsn); 1811 1812 enum devlink_info_version_type { 1813 DEVLINK_INFO_VERSION_TYPE_NONE, 1814 DEVLINK_INFO_VERSION_TYPE_COMPONENT, /* May be used as flash update 1815 * component by name. 1816 */ 1817 }; 1818 1819 int devlink_info_version_fixed_put(struct devlink_info_req *req, 1820 const char *version_name, 1821 const char *version_value); 1822 int devlink_info_version_stored_put(struct devlink_info_req *req, 1823 const char *version_name, 1824 const char *version_value); 1825 int devlink_info_version_stored_put_ext(struct devlink_info_req *req, 1826 const char *version_name, 1827 const char *version_value, 1828 enum devlink_info_version_type version_type); 1829 int devlink_info_version_running_put(struct devlink_info_req *req, 1830 const char *version_name, 1831 const char *version_value); 1832 int devlink_info_version_running_put_ext(struct devlink_info_req *req, 1833 const char *version_name, 1834 const char *version_value, 1835 enum devlink_info_version_type version_type); 1836 1837 int devlink_fmsg_obj_nest_start(struct devlink_fmsg *fmsg); 1838 int devlink_fmsg_obj_nest_end(struct devlink_fmsg *fmsg); 1839 1840 int devlink_fmsg_pair_nest_start(struct devlink_fmsg *fmsg, const char *name); 1841 int devlink_fmsg_pair_nest_end(struct devlink_fmsg *fmsg); 1842 1843 int devlink_fmsg_arr_pair_nest_start(struct devlink_fmsg *fmsg, 1844 const char *name); 1845 int devlink_fmsg_arr_pair_nest_end(struct devlink_fmsg *fmsg); 1846 int devlink_fmsg_binary_pair_nest_start(struct devlink_fmsg *fmsg, 1847 const char *name); 1848 int devlink_fmsg_binary_pair_nest_end(struct devlink_fmsg *fmsg); 1849 1850 int devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value); 1851 int devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value); 1852 int devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value, 1853 u16 value_len); 1854 1855 int devlink_fmsg_bool_pair_put(struct devlink_fmsg *fmsg, const char *name, 1856 bool value); 1857 int devlink_fmsg_u8_pair_put(struct devlink_fmsg *fmsg, const char *name, 1858 u8 value); 1859 int devlink_fmsg_u32_pair_put(struct devlink_fmsg *fmsg, const char *name, 1860 u32 value); 1861 int devlink_fmsg_u64_pair_put(struct devlink_fmsg *fmsg, const char *name, 1862 u64 value); 1863 int devlink_fmsg_string_pair_put(struct devlink_fmsg *fmsg, const char *name, 1864 const char *value); 1865 int devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name, 1866 const void *value, u32 value_len); 1867 1868 struct devlink_health_reporter * 1869 devl_port_health_reporter_create(struct devlink_port *port, 1870 const struct devlink_health_reporter_ops *ops, 1871 u64 graceful_period, void *priv); 1872 1873 struct devlink_health_reporter * 1874 devlink_port_health_reporter_create(struct devlink_port *port, 1875 const struct devlink_health_reporter_ops *ops, 1876 u64 graceful_period, void *priv); 1877 1878 struct devlink_health_reporter * 1879 devl_health_reporter_create(struct devlink *devlink, 1880 const struct devlink_health_reporter_ops *ops, 1881 u64 graceful_period, void *priv); 1882 1883 struct devlink_health_reporter * 1884 devlink_health_reporter_create(struct devlink *devlink, 1885 const struct devlink_health_reporter_ops *ops, 1886 u64 graceful_period, void *priv); 1887 1888 void 1889 devl_health_reporter_destroy(struct devlink_health_reporter *reporter); 1890 1891 void 1892 devlink_health_reporter_destroy(struct devlink_health_reporter *reporter); 1893 1894 void * 1895 devlink_health_reporter_priv(struct devlink_health_reporter *reporter); 1896 int devlink_health_report(struct devlink_health_reporter *reporter, 1897 const char *msg, void *priv_ctx); 1898 void 1899 devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, 1900 enum devlink_health_reporter_state state); 1901 void 1902 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter); 1903 1904 bool devlink_is_reload_failed(const struct devlink *devlink); 1905 void devlink_remote_reload_actions_performed(struct devlink *devlink, 1906 enum devlink_reload_limit limit, 1907 u32 actions_performed); 1908 1909 void devlink_flash_update_status_notify(struct devlink *devlink, 1910 const char *status_msg, 1911 const char *component, 1912 unsigned long done, 1913 unsigned long total); 1914 void devlink_flash_update_timeout_notify(struct devlink *devlink, 1915 const char *status_msg, 1916 const char *component, 1917 unsigned long timeout); 1918 1919 int devl_traps_register(struct devlink *devlink, 1920 const struct devlink_trap *traps, 1921 size_t traps_count, void *priv); 1922 int devlink_traps_register(struct devlink *devlink, 1923 const struct devlink_trap *traps, 1924 size_t traps_count, void *priv); 1925 void devl_traps_unregister(struct devlink *devlink, 1926 const struct devlink_trap *traps, 1927 size_t traps_count); 1928 void devlink_traps_unregister(struct devlink *devlink, 1929 const struct devlink_trap *traps, 1930 size_t traps_count); 1931 void devlink_trap_report(struct devlink *devlink, struct sk_buff *skb, 1932 void *trap_ctx, struct devlink_port *in_devlink_port, 1933 const struct flow_action_cookie *fa_cookie); 1934 void *devlink_trap_ctx_priv(void *trap_ctx); 1935 int devl_trap_groups_register(struct devlink *devlink, 1936 const struct devlink_trap_group *groups, 1937 size_t groups_count); 1938 int devlink_trap_groups_register(struct devlink *devlink, 1939 const struct devlink_trap_group *groups, 1940 size_t groups_count); 1941 void devl_trap_groups_unregister(struct devlink *devlink, 1942 const struct devlink_trap_group *groups, 1943 size_t groups_count); 1944 void devlink_trap_groups_unregister(struct devlink *devlink, 1945 const struct devlink_trap_group *groups, 1946 size_t groups_count); 1947 int 1948 devl_trap_policers_register(struct devlink *devlink, 1949 const struct devlink_trap_policer *policers, 1950 size_t policers_count); 1951 void 1952 devl_trap_policers_unregister(struct devlink *devlink, 1953 const struct devlink_trap_policer *policers, 1954 size_t policers_count); 1955 1956 #if IS_ENABLED(CONFIG_NET_DEVLINK) 1957 1958 struct devlink *__must_check devlink_try_get(struct devlink *devlink); 1959 void devlink_put(struct devlink *devlink); 1960 1961 void devlink_compat_running_version(struct devlink *devlink, 1962 char *buf, size_t len); 1963 int devlink_compat_flash_update(struct devlink *devlink, const char *file_name); 1964 int devlink_compat_phys_port_name_get(struct net_device *dev, 1965 char *name, size_t len); 1966 int devlink_compat_switch_id_get(struct net_device *dev, 1967 struct netdev_phys_item_id *ppid); 1968 1969 int devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port); 1970 size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port); 1971 1972 #else 1973 1974 static inline struct devlink *devlink_try_get(struct devlink *devlink) 1975 { 1976 return NULL; 1977 } 1978 1979 static inline void devlink_put(struct devlink *devlink) 1980 { 1981 } 1982 1983 static inline void 1984 devlink_compat_running_version(struct devlink *devlink, char *buf, size_t len) 1985 { 1986 } 1987 1988 static inline int 1989 devlink_compat_flash_update(struct devlink *devlink, const char *file_name) 1990 { 1991 return -EOPNOTSUPP; 1992 } 1993 1994 static inline int 1995 devlink_compat_phys_port_name_get(struct net_device *dev, 1996 char *name, size_t len) 1997 { 1998 return -EOPNOTSUPP; 1999 } 2000 2001 static inline int 2002 devlink_compat_switch_id_get(struct net_device *dev, 2003 struct netdev_phys_item_id *ppid) 2004 { 2005 return -EOPNOTSUPP; 2006 } 2007 2008 static inline int 2009 devlink_nl_port_handle_fill(struct sk_buff *msg, struct devlink_port *devlink_port) 2010 { 2011 return 0; 2012 } 2013 2014 static inline size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port) 2015 { 2016 return 0; 2017 } 2018 2019 #endif 2020 2021 #endif /* _NET_DEVLINK_H_ */ 2022