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