aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/devlink.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/devlink.h')
-rw-r--r--include/net/devlink.h195
1 files changed, 195 insertions, 0 deletions
diff --git a/include/net/devlink.h b/include/net/devlink.h
index e336ea9c73df..b9b89d6604d4 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -27,6 +27,9 @@ struct devlink {
27 struct list_head sb_list; 27 struct list_head sb_list;
28 struct list_head dpipe_table_list; 28 struct list_head dpipe_table_list;
29 struct list_head resource_list; 29 struct list_head resource_list;
30 struct list_head param_list;
31 struct list_head region_list;
32 u32 snapshot_id;
30 struct devlink_dpipe_headers *dpipe_headers; 33 struct devlink_dpipe_headers *dpipe_headers;
31 const struct devlink_ops *ops; 34 const struct devlink_ops *ops;
32 struct device *dev; 35 struct device *dev;
@@ -295,6 +298,115 @@ struct devlink_resource {
295 298
296#define DEVLINK_RESOURCE_ID_PARENT_TOP 0 299#define DEVLINK_RESOURCE_ID_PARENT_TOP 0
297 300
301#define DEVLINK_PARAM_MAX_STRING_VALUE 32
302enum devlink_param_type {
303 DEVLINK_PARAM_TYPE_U8,
304 DEVLINK_PARAM_TYPE_U16,
305 DEVLINK_PARAM_TYPE_U32,
306 DEVLINK_PARAM_TYPE_STRING,
307 DEVLINK_PARAM_TYPE_BOOL,
308};
309
310union devlink_param_value {
311 u8 vu8;
312 u16 vu16;
313 u32 vu32;
314 const char *vstr;
315 bool vbool;
316};
317
318struct devlink_param_gset_ctx {
319 union devlink_param_value val;
320 enum devlink_param_cmode cmode;
321};
322
323/**
324 * struct devlink_param - devlink configuration parameter data
325 * @name: name of the parameter
326 * @generic: indicates if the parameter is generic or driver specific
327 * @type: parameter type
328 * @supported_cmodes: bitmap of supported configuration modes
329 * @get: get parameter value, used for runtime and permanent
330 * configuration modes
331 * @set: set parameter value, used for runtime and permanent
332 * configuration modes
333 * @validate: validate input value is applicable (within value range, etc.)
334 *
335 * This struct should be used by the driver to fill the data for
336 * a parameter it registers.
337 */
338struct devlink_param {
339 u32 id;
340 const char *name;
341 bool generic;
342 enum devlink_param_type type;
343 unsigned long supported_cmodes;
344 int (*get)(struct devlink *devlink, u32 id,
345 struct devlink_param_gset_ctx *ctx);
346 int (*set)(struct devlink *devlink, u32 id,
347 struct devlink_param_gset_ctx *ctx);
348 int (*validate)(struct devlink *devlink, u32 id,
349 union devlink_param_value val,
350 struct netlink_ext_ack *extack);
351};
352
353struct devlink_param_item {
354 struct list_head list;
355 const struct devlink_param *param;
356 union devlink_param_value driverinit_value;
357 bool driverinit_value_valid;
358};
359
360enum devlink_param_generic_id {
361 DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
362 DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
363 DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
364 DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
365
366 /* add new param generic ids above here*/
367 __DEVLINK_PARAM_GENERIC_ID_MAX,
368 DEVLINK_PARAM_GENERIC_ID_MAX = __DEVLINK_PARAM_GENERIC_ID_MAX - 1,
369};
370
371#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME "internal_error_reset"
372#define DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE DEVLINK_PARAM_TYPE_BOOL
373
374#define DEVLINK_PARAM_GENERIC_MAX_MACS_NAME "max_macs"
375#define DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE DEVLINK_PARAM_TYPE_U32
376
377#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME "enable_sriov"
378#define DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE DEVLINK_PARAM_TYPE_BOOL
379
380#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME "region_snapshot_enable"
381#define DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE DEVLINK_PARAM_TYPE_BOOL
382
383#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
384{ \
385 .id = DEVLINK_PARAM_GENERIC_ID_##_id, \
386 .name = DEVLINK_PARAM_GENERIC_##_id##_NAME, \
387 .type = DEVLINK_PARAM_GENERIC_##_id##_TYPE, \
388 .generic = true, \
389 .supported_cmodes = _cmodes, \
390 .get = _get, \
391 .set = _set, \
392 .validate = _validate, \
393}
394
395#define DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes, _get, _set, _validate) \
396{ \
397 .id = _id, \
398 .name = _name, \
399 .type = _type, \
400 .supported_cmodes = _cmodes, \
401 .get = _get, \
402 .set = _set, \
403 .validate = _validate, \
404}
405
406struct devlink_region;
407
408typedef void devlink_snapshot_data_dest_t(const void *data);
409
298struct devlink_ops { 410struct devlink_ops {
299 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack); 411 int (*reload)(struct devlink *devlink, struct netlink_ext_ack *extack);
300 int (*port_type_set)(struct devlink_port *devlink_port, 412 int (*port_type_set)(struct devlink_port *devlink_port,
@@ -430,6 +542,26 @@ void devlink_resource_occ_get_register(struct devlink *devlink,
430 void *occ_get_priv); 542 void *occ_get_priv);
431void devlink_resource_occ_get_unregister(struct devlink *devlink, 543void devlink_resource_occ_get_unregister(struct devlink *devlink,
432 u64 resource_id); 544 u64 resource_id);
545int devlink_params_register(struct devlink *devlink,
546 const struct devlink_param *params,
547 size_t params_count);
548void devlink_params_unregister(struct devlink *devlink,
549 const struct devlink_param *params,
550 size_t params_count);
551int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
552 union devlink_param_value *init_val);
553int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
554 union devlink_param_value init_val);
555void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
556struct devlink_region *devlink_region_create(struct devlink *devlink,
557 const char *region_name,
558 u32 region_max_snapshots,
559 u64 region_size);
560void devlink_region_destroy(struct devlink_region *region);
561u32 devlink_region_shapshot_id_get(struct devlink *devlink);
562int devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
563 u8 *data, u32 snapshot_id,
564 devlink_snapshot_data_dest_t *data_destructor);
433 565
434#else 566#else
435 567
@@ -622,6 +754,69 @@ devlink_resource_occ_get_unregister(struct devlink *devlink,
622{ 754{
623} 755}
624 756
757static inline int
758devlink_params_register(struct devlink *devlink,
759 const struct devlink_param *params,
760 size_t params_count)
761{
762 return 0;
763}
764
765static inline void
766devlink_params_unregister(struct devlink *devlink,
767 const struct devlink_param *params,
768 size_t params_count)
769{
770
771}
772
773static inline int
774devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
775 union devlink_param_value *init_val)
776{
777 return -EOPNOTSUPP;
778}
779
780static inline int
781devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
782 union devlink_param_value init_val)
783{
784 return -EOPNOTSUPP;
785}
786
787static inline void
788devlink_param_value_changed(struct devlink *devlink, u32 param_id)
789{
790}
791
792static inline struct devlink_region *
793devlink_region_create(struct devlink *devlink,
794 const char *region_name,
795 u32 region_max_snapshots,
796 u64 region_size)
797{
798 return NULL;
799}
800
801static inline void
802devlink_region_destroy(struct devlink_region *region)
803{
804}
805
806static inline u32
807devlink_region_shapshot_id_get(struct devlink *devlink)
808{
809 return 0;
810}
811
812static inline int
813devlink_region_snapshot_create(struct devlink_region *region, u64 data_len,
814 u8 *data, u32 snapshot_id,
815 devlink_snapshot_data_dest_t *data_destructor)
816{
817 return 0;
818}
819
625#endif 820#endif
626 821
627#endif /* _NET_DEVLINK_H_ */ 822#endif /* _NET_DEVLINK_H_ */