devlink.h 75 KB

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