devlink.h 72 KB

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