6b417f141fd62cee18904058a1a72254105e4742
[linux-2.6-microblaze.git] / include / net / devlink.h
1 /*
2  * include/net/devlink.h - Network physical device Netlink interface
3  * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  */
11 #ifndef _NET_DEVLINK_H_
12 #define _NET_DEVLINK_H_
13
14 #include <linux/device.h>
15 #include <linux/slab.h>
16 #include <linux/gfp.h>
17 #include <linux/list.h>
18 #include <linux/netdevice.h>
19 #include <net/net_namespace.h>
20 #include <uapi/linux/devlink.h>
21
22 struct devlink_ops;
23
24 struct devlink {
25         struct list_head list;
26         struct list_head port_list;
27         struct list_head sb_list;
28         struct list_head dpipe_table_list;
29         struct list_head resource_list;
30         struct list_head param_list;
31         struct list_head region_list;
32         u32 snapshot_id;
33         struct 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
41 struct devlink_port_attrs {
42         bool set;
43         enum devlink_port_flavour flavour;
44         u32 port_number; /* same value as "split group" */
45         bool split;
46         u32 split_subport_number;
47 };
48
49 struct devlink_port {
50         struct list_head list;
51         struct list_head param_list;
52         struct devlink *devlink;
53         unsigned index;
54         bool registered;
55         enum devlink_port_type type;
56         enum devlink_port_type desired_type;
57         void *type_dev;
58         struct devlink_port_attrs attrs;
59 };
60
61 struct devlink_sb_pool_info {
62         enum devlink_sb_pool_type pool_type;
63         u32 size;
64         enum devlink_sb_threshold_type threshold_type;
65 };
66
67 /**
68  * struct devlink_dpipe_field - dpipe field object
69  * @name: field name
70  * @id: index inside the headers field array
71  * @bitwidth: bitwidth
72  * @mapping_type: mapping type
73  */
74 struct devlink_dpipe_field {
75         const char *name;
76         unsigned int id;
77         unsigned int bitwidth;
78         enum devlink_dpipe_field_mapping_type mapping_type;
79 };
80
81 /**
82  * struct devlink_dpipe_header - dpipe header object
83  * @name: header name
84  * @id: index, global/local detrmined by global bit
85  * @fields: fields
86  * @fields_count: number of fields
87  * @global: indicates if header is shared like most protocol header
88  *          or driver specific
89  */
90 struct devlink_dpipe_header {
91         const char *name;
92         unsigned int id;
93         struct devlink_dpipe_field *fields;
94         unsigned int fields_count;
95         bool global;
96 };
97
98 /**
99  * struct devlink_dpipe_match - represents match operation
100  * @type: type of match
101  * @header_index: header index (packets can have several headers of same
102  *                type like in case of tunnels)
103  * @header: header
104  * @fieled_id: field index
105  */
106 struct devlink_dpipe_match {
107         enum devlink_dpipe_match_type type;
108         unsigned int header_index;
109         struct devlink_dpipe_header *header;
110         unsigned int field_id;
111 };
112
113 /**
114  * struct devlink_dpipe_action - represents action operation
115  * @type: type of action
116  * @header_index: header index (packets can have several headers of same
117  *                type like in case of tunnels)
118  * @header: header
119  * @fieled_id: field index
120  */
121 struct devlink_dpipe_action {
122         enum devlink_dpipe_action_type type;
123         unsigned int header_index;
124         struct devlink_dpipe_header *header;
125         unsigned int field_id;
126 };
127
128 /**
129  * struct devlink_dpipe_value - represents value of match/action
130  * @action: action
131  * @match: match
132  * @mapping_value: in case the field has some mapping this value
133  *                 specified the mapping value
134  * @mapping_valid: specify if mapping value is valid
135  * @value_size: value size
136  * @value: value
137  * @mask: bit mask
138  */
139 struct devlink_dpipe_value {
140         union {
141                 struct devlink_dpipe_action *action;
142                 struct devlink_dpipe_match *match;
143         };
144         unsigned int mapping_value;
145         bool mapping_valid;
146         unsigned int value_size;
147         void *value;
148         void *mask;
149 };
150
151 /**
152  * struct devlink_dpipe_entry - table entry object
153  * @index: index of the entry in the table
154  * @match_values: match values
155  * @matche_values_count: count of matches tuples
156  * @action_values: actions values
157  * @action_values_count: count of actions values
158  * @counter: value of counter
159  * @counter_valid: Specify if value is valid from hardware
160  */
161 struct devlink_dpipe_entry {
162         u64 index;
163         struct devlink_dpipe_value *match_values;
164         unsigned int match_values_count;
165         struct devlink_dpipe_value *action_values;
166         unsigned int action_values_count;
167         u64 counter;
168         bool counter_valid;
169 };
170
171 /**
172  * struct devlink_dpipe_dump_ctx - context provided to driver in order
173  *                                 to dump
174  * @info: info
175  * @cmd: devlink command
176  * @skb: skb
177  * @nest: top attribute
178  * @hdr: hdr
179  */
180 struct devlink_dpipe_dump_ctx {
181         struct genl_info *info;
182         enum devlink_command cmd;
183         struct sk_buff *skb;
184         struct nlattr *nest;
185         void *hdr;
186 };
187
188 struct devlink_dpipe_table_ops;
189
190 /**
191  * struct devlink_dpipe_table - table object
192  * @priv: private
193  * @name: table name
194  * @counters_enabled: indicates if counters are active
195  * @counter_control_extern: indicates if counter control is in dpipe or
196  *                          external tool
197  * @resource_valid: Indicate that the resource id is valid
198  * @resource_id: relative resource this table is related to
199  * @resource_units: number of resource's unit consumed per table's entry
200  * @table_ops: table operations
201  * @rcu: rcu
202  */
203 struct devlink_dpipe_table {
204         void *priv;
205         struct list_head list;
206         const char *name;
207         bool counters_enabled;
208         bool counter_control_extern;
209         bool resource_valid;
210         u64 resource_id;
211         u64 resource_units;
212         struct devlink_dpipe_table_ops *table_ops;
213         struct rcu_head rcu;
214 };
215
216 /**
217  * struct devlink_dpipe_table_ops - dpipe_table ops
218  * @actions_dump - dumps all tables actions
219  * @matches_dump - dumps all tables matches
220  * @entries_dump - dumps all active entries in the table
221  * @counters_set_update - when changing the counter status hardware sync
222  *                        maybe needed to allocate/free counter related
223  *                        resources
224  * @size_get - get size
225  */
226 struct devlink_dpipe_table_ops {
227         int (*actions_dump)(void *priv, struct sk_buff *skb);
228         int (*matches_dump)(void *priv, struct sk_buff *skb);
229         int (*entries_dump)(void *priv, bool counters_enabled,
230                             struct devlink_dpipe_dump_ctx *dump_ctx);
231         int (*counters_set_update)(void *priv, bool enable);
232         u64 (*size_get)(void *priv);
233 };
234
235 /**
236  * struct devlink_dpipe_headers - dpipe headers
237  * @headers - header array can be shared (global bit) or driver specific
238  * @headers_count - count of headers
239  */
240 struct devlink_dpipe_headers {
241         struct devlink_dpipe_header **headers;
242         unsigned int headers_count;
243 };
244
245 /**
246  * struct devlink_resource_size_params - resource's size parameters
247  * @size_min: minimum size which can be set
248  * @size_max: maximum size which can be set
249  * @size_granularity: size granularity
250  * @size_unit: resource's basic unit
251  */
252 struct devlink_resource_size_params {
253         u64 size_min;
254         u64 size_max;
255         u64 size_granularity;
256         enum devlink_resource_unit unit;
257 };
258
259 static inline void
260 devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
261                                   u64 size_min, u64 size_max,
262                                   u64 size_granularity,
263                                   enum devlink_resource_unit unit)
264 {
265         size_params->size_min = size_min;
266         size_params->size_max = size_max;
267         size_params->size_granularity = size_granularity;
268         size_params->unit = unit;
269 }
270
271 typedef u64 devlink_resource_occ_get_t(void *priv);
272
273 /**
274  * struct devlink_resource - devlink resource
275  * @name: name of the resource
276  * @id: id, per devlink instance
277  * @size: size of the resource
278  * @size_new: updated size of the resource, reload is needed
279  * @size_valid: valid in case the total size of the resource is valid
280  *              including its children
281  * @parent: parent resource
282  * @size_params: size parameters
283  * @list: parent list
284  * @resource_list: list of child resources
285  */
286 struct devlink_resource {
287         const char *name;
288         u64 id;
289         u64 size;
290         u64 size_new;
291         bool size_valid;
292         struct devlink_resource *parent;
293         struct devlink_resource_size_params size_params;
294         struct list_head list;
295         struct list_head resource_list;
296         devlink_resource_occ_get_t *occ_get;
297         void *occ_get_priv;
298 };
299
300 #define DEVLINK_RESOURCE_ID_PARENT_TOP 0
301
302 #define __DEVLINK_PARAM_MAX_STRING_VALUE 32
303 enum devlink_param_type {
304         DEVLINK_PARAM_TYPE_U8,
305         DEVLINK_PARAM_TYPE_U16,
306         DEVLINK_PARAM_TYPE_U32,
307         DEVLINK_PARAM_TYPE_STRING,
308         DEVLINK_PARAM_TYPE_BOOL,
309 };
310
311 union devlink_param_value {
312         u8 vu8;
313         u16 vu16;
314         u32 vu32;
315         char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
316         bool vbool;
317 };
318
319 struct devlink_param_gset_ctx {
320         union devlink_param_value val;
321         enum devlink_param_cmode cmode;
322 };
323
324 /**
325  * struct devlink_param - devlink configuration parameter data
326  * @name: name of the parameter
327  * @generic: indicates if the parameter is generic or driver specific
328  * @type: parameter type
329  * @supported_cmodes: bitmap of supported configuration modes
330  * @get: get parameter value, used for runtime and permanent
331  *       configuration modes
332  * @set: set parameter value, used for runtime and permanent
333  *       configuration modes
334  * @validate: validate input value is applicable (within value range, etc.)
335  *
336  * This struct should be used by the driver to fill the data for
337  * a parameter it registers.
338  */
339 struct devlink_param {
340         u32 id;
341         const char *name;
342         bool generic;
343         enum devlink_param_type type;
344         unsigned long supported_cmodes;
345         int (*get)(struct devlink *devlink, u32 id,
346                    struct devlink_param_gset_ctx *ctx);
347         int (*set)(struct devlink *devlink, u32 id,
348                    struct devlink_param_gset_ctx *ctx);
349         int (*validate)(struct devlink *devlink, u32 id,
350                         union devlink_param_value val,
351                         struct netlink_ext_ack *extack);
352 };
353
354 struct devlink_param_item {
355         struct list_head list;
356         const struct devlink_param *param;
357         union devlink_param_value driverinit_value;
358         bool driverinit_value_valid;
359 };
360
361 enum devlink_param_generic_id {
362         DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
363         DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
364         DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
365         DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
366         DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
367         DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
368         DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
369         DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
370         DEVLINK_PARAM_GENERIC_ID_WOL,
371
372         /* add new param generic ids above here*/
373         __DEVLINK_PARAM_GENERIC_ID_MAX,
374         DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
375 };
376
377 enum devlink_param_wol_types {
378         DEVLINK_PARAM_WAKE_MAGIC = (1 << 0),
379 };
380
381 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
382 #define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
383
384 #define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
385 #define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
386
387 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
388 #define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
389
390 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
391 #define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
392
393 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME "ignore_ari"
394 #define DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE DEVLINK_PARAM_TYPE_BOOL
395
396 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME "msix_vec_per_pf_max"
397 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE DEVLINK_PARAM_TYPE_U32
398
399 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME "msix_vec_per_pf_min"
400 #define DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE DEVLINK_PARAM_TYPE_U32
401
402 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME "fw_load_policy"
403 #define DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE DEVLINK_PARAM_TYPE_U8
404
405 #define DEVLINK_PARAM_GENERIC_WOL_NAME "wake_on_lan"
406 #define DEVLINK_PARAM_GENERIC_WOL_TYPE DEVLINK_PARAM_TYPE_U8
407
408 #define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate)      \
409 {                                                                       \
410         .id = DEVLINK_PARAM_GENERIC_ID_##_id,                           \
411         .name = DEVLINK_PARAM_GENERIC_##_id##_NAME,                     \
412         .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,                     \
413         .generic = true,                                                \
414         .supported_cmodes = _cmodes,                                    \
415         .get = _get,                                                    \
416         .set = _set,                                                    \
417         .validate = _validate,                                          \
418 }
419
420 #define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
421 {                                                                       \
422         .id = _id,                                                      \
423         .name = _name,                                                  \
424         .type = _type,                                                  \
425         .supported_cmodes = _cmodes,                                    \
426         .get = _get,                                                    \
427         .set = _set,                                                    \
428         .validate = _validate,                                          \
429 }
430
431 /* Part number, identifier of board design */
432 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID   "board.id"
433 /* Revision of board design */
434 #define DEVLINK_INFO_VERSION_GENERIC_BOARD_REV  "board.rev"
435
436 /* Control processor FW version */
437 #define DEVLINK_INFO_VERSION_GENERIC_FW_MGMT    "fw.mgmt"
438 /* Data path microcode controlling high-speed packet processing */
439 #define DEVLINK_INFO_VERSION_GENERIC_FW_APP     "fw.app"
440 /* UNDI software version */
441 #define DEVLINK_INFO_VERSION_GENERIC_FW_UNDI    "fw.undi"
442 /* NCSI support/handler version */
443 #define DEVLINK_INFO_VERSION_GENERIC_FW_NCSI    "fw.ncsi"
444
445 struct devlink_region;
446 struct devlink_info_req;
447
448 typedef void devlink_snapshot_data_dest_t(const void *data);
449
450 struct devlink_ops {
451         int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
452         int (*port_type_set)(struct devlink_port *devlink_port,
453                              enum devlink_port_type port_type);
454         int (*port_split)(struct devlink *devlink, unsigned int port_index,
455                           unsigned int count, struct netlink_ext_ack *extack);
456         int (*port_unsplit)(struct devlink *devlink, unsigned int port_index,
457                             struct netlink_ext_ack *extack);
458         int (*sb_pool_get)(struct devlink *devlink, unsigned int sb_index,
459                            u16 pool_index,
460                            struct devlink_sb_pool_info *pool_info);
461         int (*sb_pool_set)(struct devlink *devlink, unsigned int sb_index,
462                            u16 pool_index, u32 size,
463                            enum devlink_sb_threshold_type threshold_type);
464         int (*sb_port_pool_get)(struct devlink_port *devlink_port,
465                                 unsigned int sb_index, u16 pool_index,
466                                 u32 *p_threshold);
467         int (*sb_port_pool_set)(struct devlink_port *devlink_port,
468                                 unsigned int sb_index, u16 pool_index,
469                                 u32 threshold);
470         int (*sb_tc_pool_bind_get)(struct devlink_port *devlink_port,
471                                    unsigned int sb_index,
472                                    u16 tc_index,
473                                    enum devlink_sb_pool_type pool_type,
474                                    u16 *p_pool_index, u32 *p_threshold);
475         int (*sb_tc_pool_bind_set)(struct devlink_port *devlink_port,
476                                    unsigned int sb_index,
477                                    u16 tc_index,
478                                    enum devlink_sb_pool_type pool_type,
479                                    u16 pool_index, u32 threshold);
480         int (*sb_occ_snapshot)(struct devlink *devlink,
481                                unsigned int sb_index);
482         int (*sb_occ_max_clear)(struct devlink *devlink,
483                                 unsigned int sb_index);
484         int (*sb_occ_port_pool_get)(struct devlink_port *devlink_port,
485                                     unsigned int sb_index, u16 pool_index,
486                                     u32 *p_cur, u32 *p_max);
487         int (*sb_occ_tc_port_bind_get)(struct devlink_port *devlink_port,
488                                        unsigned int sb_index,
489                                        u16 tc_index,
490                                        enum devlink_sb_pool_type pool_type,
491                                        u32 *p_cur, u32 *p_max);
492
493         int (*eswitch_mode_get)(struct devlink *devlink, u16 *p_mode);
494         int (*eswitch_mode_set)(struct devlink *devlink, u16 mode,
495                                 struct netlink_ext_ack *extack);
496         int (*eswitch_inline_mode_get)(struct devlink *devlink, u8 *p_inline_mode);
497         int (*eswitch_inline_mode_set)(struct devlink *devlink, u8 inline_mode,
498                                        struct netlink_ext_ack *extack);
499         int (*eswitch_encap_mode_get)(struct devlink *devlink, u8 *p_encap_mode);
500         int (*eswitch_encap_mode_set)(struct devlink *devlink, u8 encap_mode,
501                                       struct netlink_ext_ack *extack);
502         int (*info_get)(struct devlink *devlink, struct devlink_info_req *req,
503                         struct netlink_ext_ack *extack);
504 };
505
506 static inline void *devlink_priv(struct devlink *devlink)
507 {
508         BUG_ON(!devlink);
509         return &devlink->priv;
510 }
511
512 static inline struct devlink *priv_to_devlink(void *priv)
513 {
514         BUG_ON(!priv);
515         return container_of(priv, struct devlink, priv);
516 }
517
518 struct ib_device;
519
520 #if IS_ENABLED(CONFIG_NET_DEVLINK)
521
522 struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
523 int devlink_register(struct devlink *devlink, struct device *dev);
524 void devlink_unregister(struct devlink *devlink);
525 void devlink_free(struct devlink *devlink);
526 int devlink_port_register(struct devlink *devlink,
527                           struct devlink_port *devlink_port,
528                           unsigned int port_index);
529 void devlink_port_unregister(struct devlink_port *devlink_port);
530 void devlink_port_type_eth_set(struct devlink_port *devlink_port,
531                                struct net_device *netdev);
532 void devlink_port_type_ib_set(struct devlink_port *devlink_port,
533                               struct ib_device *ibdev);
534 void devlink_port_type_clear(struct devlink_port *devlink_port);
535 void devlink_port_attrs_set(struct devlink_port *devlink_port,
536                             enum devlink_port_flavour flavour,
537                             u32 port_number, bool split,
538                             u32 split_subport_number);
539 int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
540                                     char *name, size_t len);
541 int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
542                         u32 size, u16 ingress_pools_count,
543                         u16 egress_pools_count, u16 ingress_tc_count,
544                         u16 egress_tc_count);
545 void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
546 int devlink_dpipe_table_register(struct devlink *devlink,
547                                  const char *table_name,
548                                  struct devlink_dpipe_table_ops *table_ops,
549                                  void *priv, bool counter_control_extern);
550 void devlink_dpipe_table_unregister(struct devlink *devlink,
551                                     const char *table_name);
552 int devlink_dpipe_headers_register(struct devlink *devlink,
553                                    struct devlink_dpipe_headers *dpipe_headers);
554 void devlink_dpipe_headers_unregister(struct devlink *devlink);
555 bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
556                                          const char *table_name);
557 int devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx);
558 int devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
559                                    struct devlink_dpipe_entry *entry);
560 int devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx);
561 void devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry);
562 int devlink_dpipe_action_put(struct sk_buff *skb,
563                              struct devlink_dpipe_action *action);
564 int devlink_dpipe_match_put(struct sk_buff *skb,
565                             struct devlink_dpipe_match *match);
566 extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
567 extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
568 extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
569
570 int devlink_resource_register(struct devlink *devlink,
571                               const char *resource_name,
572                               u64 resource_size,
573                               u64 resource_id,
574                               u64 parent_resource_id,
575                               const struct devlink_resource_size_params *size_params);
576 void devlink_resources_unregister(struct devlink *devlink,
577                                   struct devlink_resource *resource);
578 int devlink_resource_size_get(struct devlink *devlink,
579                               u64 resource_id,
580                               u64 *p_resource_size);
581 int devlink_dpipe_table_resource_set(struct devlink *devlink,
582                                      const char *table_name, u64 resource_id,
583                                      u64 resource_units);
584 void devlink_resource_occ_get_register(struct devlink *devlink,
585                                        u64 resource_id,
586                                        devlink_resource_occ_get_t *occ_get,
587                                        void *occ_get_priv);
588 void devlink_resource_occ_get_unregister(struct devlink *devlink,
589                                          u64 resource_id);
590 int devlink_params_register(struct devlink *devlink,
591                             const struct devlink_param *params,
592                             size_t params_count);
593 void devlink_params_unregister(struct devlink *devlink,
594                                const struct devlink_param *params,
595                                size_t params_count);
596 int devlink_port_params_register(struct devlink_port *devlink_port,
597                                  const struct devlink_param *params,
598                                  size_t params_count);
599 void devlink_port_params_unregister(struct devlink_port *devlink_port,
600                                     const struct devlink_param *params,
601                                     size_t params_count);
602 int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
603                                        union devlink_param_value *init_val);
604 int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
605                                        union devlink_param_value init_val);
606 int
607 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
608                                         u32 param_id,
609                                         union devlink_param_value *init_val);
610 int devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
611                                             u32 param_id,
612                                             union devlink_param_value init_val);
613 void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
614 void devlink_port_param_value_changed(struct devlink_port *devlink_port,
615                                       u32 param_id);
616 void devlink_param_value_str_fill(union devlink_param_value *dst_val,
617                                   const char *src);
618 struct devlink_region *devlink_region_create(struct devlink *devlink,
619                                              const char *region_name,
620                                              u32 region_max_snapshots,
621                                              u64 region_size);
622 void devlink_region_destroy(struct devlink_region *region);
623 u32 devlink_region_shapshot_id_get(struct devlink *devlink);
624 int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
625                                    u8 *data, u32 snapshot_id,
626                                    devlink_snapshot_data_dest_t *data_destructor);
627 int devlink_info_serial_number_put(struct devlink_info_req *req,
628                                    const char *sn);
629 int devlink_info_driver_name_put(struct devlink_info_req *req,
630                                  const char *name);
631 int devlink_info_version_fixed_put(struct devlink_info_req *req,
632                                    const char *version_name,
633                                    const char *version_value);
634 int devlink_info_version_stored_put(struct devlink_info_req *req,
635                                     const char *version_name,
636                                     const char *version_value);
637 int devlink_info_version_running_put(struct devlink_info_req *req,
638                                      const char *version_name,
639                                      const char *version_value);
640
641 #else
642
643 static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
644                                             size_t priv_size)
645 {
646         return kzalloc(sizeof(struct devlink) + priv_size, GFP_KERNEL);
647 }
648
649 static inline int devlink_register(struct devlink *devlink, struct device *dev)
650 {
651         return 0;
652 }
653
654 static inline void devlink_unregister(struct devlink *devlink)
655 {
656 }
657
658 static inline void devlink_free(struct devlink *devlink)
659 {
660         kfree(devlink);
661 }
662
663 static inline int devlink_port_register(struct devlink *devlink,
664                                         struct devlink_port *devlink_port,
665                                         unsigned int port_index)
666 {
667         return 0;
668 }
669
670 static inline void devlink_port_unregister(struct devlink_port *devlink_port)
671 {
672 }
673
674 static inline void devlink_port_type_eth_set(struct devlink_port *devlink_port,
675                                              struct net_device *netdev)
676 {
677 }
678
679 static inline void devlink_port_type_ib_set(struct devlink_port *devlink_port,
680                                             struct ib_device *ibdev)
681 {
682 }
683
684 static inline void devlink_port_type_clear(struct devlink_port *devlink_port)
685 {
686 }
687
688 static inline void devlink_port_attrs_set(struct devlink_port *devlink_port,
689                                           enum devlink_port_flavour flavour,
690                                           u32 port_number, bool split,
691                                           u32 split_subport_number)
692 {
693 }
694
695 static inline int
696 devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
697                                 char *name, size_t len)
698 {
699         return -EOPNOTSUPP;
700 }
701
702 static inline int devlink_sb_register(struct devlink *devlink,
703                                       unsigned int sb_index, u32 size,
704                                       u16 ingress_pools_count,
705                                       u16 egress_pools_count,
706                                       u16 ingress_tc_count,
707                                       u16 egress_tc_count)
708 {
709         return 0;
710 }
711
712 static inline void devlink_sb_unregister(struct devlink *devlink,
713                                          unsigned int sb_index)
714 {
715 }
716
717 static inline int
718 devlink_dpipe_table_register(struct devlink *devlink,
719                              const char *table_name,
720                              struct devlink_dpipe_table_ops *table_ops,
721                              void *priv, bool counter_control_extern)
722 {
723         return 0;
724 }
725
726 static inline void devlink_dpipe_table_unregister(struct devlink *devlink,
727                                                   const char *table_name)
728 {
729 }
730
731 static inline int devlink_dpipe_headers_register(struct devlink *devlink,
732                                                  struct devlink_dpipe_headers *
733                                                  dpipe_headers)
734 {
735         return 0;
736 }
737
738 static inline void devlink_dpipe_headers_unregister(struct devlink *devlink)
739 {
740 }
741
742 static inline bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
743                                                        const char *table_name)
744 {
745         return false;
746 }
747
748 static inline int
749 devlink_dpipe_entry_ctx_prepare(struct devlink_dpipe_dump_ctx *dump_ctx)
750 {
751         return 0;
752 }
753
754 static inline int
755 devlink_dpipe_entry_ctx_append(struct devlink_dpipe_dump_ctx *dump_ctx,
756                                struct devlink_dpipe_entry *entry)
757 {
758         return 0;
759 }
760
761 static inline int
762 devlink_dpipe_entry_ctx_close(struct devlink_dpipe_dump_ctx *dump_ctx)
763 {
764         return 0;
765 }
766
767 static inline void
768 devlink_dpipe_entry_clear(struct devlink_dpipe_entry *entry)
769 {
770 }
771
772 static inline int
773 devlink_dpipe_action_put(struct sk_buff *skb,
774                          struct devlink_dpipe_action *action)
775 {
776         return 0;
777 }
778
779 static inline int
780 devlink_dpipe_match_put(struct sk_buff *skb,
781                         struct devlink_dpipe_match *match)
782 {
783         return 0;
784 }
785
786 static inline int
787 devlink_resource_register(struct devlink *devlink,
788                           const char *resource_name,
789                           u64 resource_size,
790                           u64 resource_id,
791                           u64 parent_resource_id,
792                           const struct devlink_resource_size_params *size_params)
793 {
794         return 0;
795 }
796
797 static inline void
798 devlink_resources_unregister(struct devlink *devlink,
799                              struct devlink_resource *resource)
800 {
801 }
802
803 static inline int
804 devlink_resource_size_get(struct devlink *devlink, u64 resource_id,
805                           u64 *p_resource_size)
806 {
807         return -EOPNOTSUPP;
808 }
809
810 static inline int
811 devlink_dpipe_table_resource_set(struct devlink *devlink,
812                                  const char *table_name, u64 resource_id,
813                                  u64 resource_units)
814 {
815         return -EOPNOTSUPP;
816 }
817
818 static inline void
819 devlink_resource_occ_get_register(struct devlink *devlink,
820                                   u64 resource_id,
821                                   devlink_resource_occ_get_t *occ_get,
822                                   void *occ_get_priv)
823 {
824 }
825
826 static inline void
827 devlink_resource_occ_get_unregister(struct devlink *devlink,
828                                     u64 resource_id)
829 {
830 }
831
832 static inline int
833 devlink_params_register(struct devlink *devlink,
834                         const struct devlink_param *params,
835                         size_t params_count)
836 {
837         return 0;
838 }
839
840 static inline void
841 devlink_params_unregister(struct devlink *devlink,
842                           const struct devlink_param *params,
843                           size_t params_count)
844 {
845
846 }
847
848 static inline int
849 devlink_port_params_register(struct devlink_port *devlink_port,
850                              const struct devlink_param *params,
851                              size_t params_count)
852 {
853         return 0;
854 }
855
856 static inline void
857 devlink_port_params_unregister(struct devlink_port *devlink_port,
858                                const struct devlink_param *params,
859                                size_t params_count)
860 {
861 }
862
863 static inline int
864 devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
865                                    union devlink_param_value *init_val)
866 {
867         return -EOPNOTSUPP;
868 }
869
870 static inline int
871 devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
872                                    union devlink_param_value init_val)
873 {
874         return -EOPNOTSUPP;
875 }
876
877 static inline int
878 devlink_port_param_driverinit_value_get(struct devlink_port *devlink_port,
879                                         u32 param_id,
880                                         union devlink_param_value *init_val)
881 {
882         return -EOPNOTSUPP;
883 }
884
885 static inline int
886 devlink_port_param_driverinit_value_set(struct devlink_port *devlink_port,
887                                         u32 param_id,
888                                         union devlink_param_value init_val)
889 {
890         return -EOPNOTSUPP;
891 }
892
893 static inline void
894 devlink_param_value_changed(struct devlink *devlink, u32 param_id)
895 {
896 }
897
898 static inline void
899 devlink_port_param_value_changed(struct devlink_port *devlink_port,
900                                  u32 param_id)
901 {
902 }
903
904 static inline void
905 devlink_param_value_str_fill(union devlink_param_value *dst_val,
906                              const char *src)
907 {
908 }
909
910 static inline struct devlink_region *
911 devlink_region_create(struct devlink *devlink,
912                       const char *region_name,
913                       u32 region_max_snapshots,
914                       u64 region_size)
915 {
916         return NULL;
917 }
918
919 static inline void
920 devlink_region_destroy(struct devlink_region *region)
921 {
922 }
923
924 static inline u32
925 devlink_region_shapshot_id_get(struct devlink *devlink)
926 {
927         return 0;
928 }
929
930 static inline int
931 devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
932                                u8 *data, u32 snapshot_id,
933                                devlink_snapshot_data_dest_t *data_destructor)
934 {
935         return 0;
936 }
937
938 static inline int
939 devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
940 {
941         return 0;
942 }
943
944 static inline int
945 devlink_info_serial_number_put(struct devlink_info_req *req, const char *sn)
946 {
947         return 0;
948 }
949
950 static inline int
951 devlink_info_version_fixed_put(struct devlink_info_req *req,
952                                const char *version_name,
953                                const char *version_value)
954 {
955         return 0;
956 }
957
958 static inline int
959 devlink_info_version_stored_put(struct devlink_info_req *req,
960                                 const char *version_name,
961                                 const char *version_value)
962 {
963         return 0;
964 }
965
966 static inline int
967 devlink_info_version_running_put(struct devlink_info_req *req,
968                                  const char *version_name,
969                                  const char *version_value)
970 {
971         return 0;
972 }
973 #endif
974
975 #endif /* _NET_DEVLINK_H_ */