devlink.h 23 KB

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