dpni.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /* Copyright 2013-2016 Freescale Semiconductor Inc.
  3. * Copyright 2016 NXP
  4. * Copyright 2020 NXP
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/errno.h>
  8. #include <linux/fsl/mc.h>
  9. #include "dpni.h"
  10. #include "dpni-cmd.h"
  11. /**
  12. * dpni_prepare_key_cfg() - function prepare extract parameters
  13. * @cfg: defining a full Key Generation profile (rule)
  14. * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
  15. *
  16. * This function has to be called before the following functions:
  17. * - dpni_set_rx_tc_dist()
  18. * - dpni_set_qos_table()
  19. *
  20. * Return: '0' on Success; Error code otherwise.
  21. */
  22. int dpni_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, u8 *key_cfg_buf)
  23. {
  24. int i, j;
  25. struct dpni_ext_set_rx_tc_dist *dpni_ext;
  26. struct dpni_dist_extract *extr;
  27. if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
  28. return -EINVAL;
  29. dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
  30. dpni_ext->num_extracts = cfg->num_extracts;
  31. for (i = 0; i < cfg->num_extracts; i++) {
  32. extr = &dpni_ext->extracts[i];
  33. switch (cfg->extracts[i].type) {
  34. case DPKG_EXTRACT_FROM_HDR:
  35. extr->prot = cfg->extracts[i].extract.from_hdr.prot;
  36. dpni_set_field(extr->efh_type, EFH_TYPE,
  37. cfg->extracts[i].extract.from_hdr.type);
  38. extr->size = cfg->extracts[i].extract.from_hdr.size;
  39. extr->offset = cfg->extracts[i].extract.from_hdr.offset;
  40. extr->field = cpu_to_le32(
  41. cfg->extracts[i].extract.from_hdr.field);
  42. extr->hdr_index =
  43. cfg->extracts[i].extract.from_hdr.hdr_index;
  44. break;
  45. case DPKG_EXTRACT_FROM_DATA:
  46. extr->size = cfg->extracts[i].extract.from_data.size;
  47. extr->offset =
  48. cfg->extracts[i].extract.from_data.offset;
  49. break;
  50. case DPKG_EXTRACT_FROM_PARSE:
  51. extr->size = cfg->extracts[i].extract.from_parse.size;
  52. extr->offset =
  53. cfg->extracts[i].extract.from_parse.offset;
  54. break;
  55. default:
  56. return -EINVAL;
  57. }
  58. extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
  59. dpni_set_field(extr->extract_type, EXTRACT_TYPE,
  60. cfg->extracts[i].type);
  61. for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
  62. extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
  63. extr->masks[j].offset =
  64. cfg->extracts[i].masks[j].offset;
  65. }
  66. }
  67. return 0;
  68. }
  69. /**
  70. * dpni_open() - Open a control session for the specified object
  71. * @mc_io: Pointer to MC portal's I/O object
  72. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  73. * @dpni_id: DPNI unique ID
  74. * @token: Returned token; use in subsequent API calls
  75. *
  76. * This function can be used to open a control session for an
  77. * already created object; an object may have been declared in
  78. * the DPL or by calling the dpni_create() function.
  79. * This function returns a unique authentication token,
  80. * associated with the specific object ID and the specific MC
  81. * portal; this token must be used in all subsequent commands for
  82. * this specific object.
  83. *
  84. * Return: '0' on Success; Error code otherwise.
  85. */
  86. int dpni_open(struct fsl_mc_io *mc_io,
  87. u32 cmd_flags,
  88. int dpni_id,
  89. u16 *token)
  90. {
  91. struct fsl_mc_command cmd = { 0 };
  92. struct dpni_cmd_open *cmd_params;
  93. int err;
  94. /* prepare command */
  95. cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
  96. cmd_flags,
  97. 0);
  98. cmd_params = (struct dpni_cmd_open *)cmd.params;
  99. cmd_params->dpni_id = cpu_to_le32(dpni_id);
  100. /* send command to mc*/
  101. err = mc_send_command(mc_io, &cmd);
  102. if (err)
  103. return err;
  104. /* retrieve response parameters */
  105. *token = mc_cmd_hdr_read_token(&cmd);
  106. return 0;
  107. }
  108. /**
  109. * dpni_close() - Close the control session of the object
  110. * @mc_io: Pointer to MC portal's I/O object
  111. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  112. * @token: Token of DPNI object
  113. *
  114. * After this function is called, no further operations are
  115. * allowed on the object without opening a new control session.
  116. *
  117. * Return: '0' on Success; Error code otherwise.
  118. */
  119. int dpni_close(struct fsl_mc_io *mc_io,
  120. u32 cmd_flags,
  121. u16 token)
  122. {
  123. struct fsl_mc_command cmd = { 0 };
  124. /* prepare command */
  125. cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
  126. cmd_flags,
  127. token);
  128. /* send command to mc*/
  129. return mc_send_command(mc_io, &cmd);
  130. }
  131. /**
  132. * dpni_set_pools() - Set buffer pools configuration
  133. * @mc_io: Pointer to MC portal's I/O object
  134. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  135. * @token: Token of DPNI object
  136. * @cfg: Buffer pools configuration
  137. *
  138. * mandatory for DPNI operation
  139. * warning:Allowed only when DPNI is disabled
  140. *
  141. * Return: '0' on Success; Error code otherwise.
  142. */
  143. int dpni_set_pools(struct fsl_mc_io *mc_io,
  144. u32 cmd_flags,
  145. u16 token,
  146. const struct dpni_pools_cfg *cfg)
  147. {
  148. struct fsl_mc_command cmd = { 0 };
  149. struct dpni_cmd_set_pools *cmd_params;
  150. int i;
  151. /* prepare command */
  152. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
  153. cmd_flags,
  154. token);
  155. cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
  156. cmd_params->num_dpbp = cfg->num_dpbp;
  157. for (i = 0; i < DPNI_MAX_DPBP; i++) {
  158. cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
  159. cmd_params->buffer_size[i] =
  160. cpu_to_le16(cfg->pools[i].buffer_size);
  161. cmd_params->backup_pool_mask |=
  162. DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
  163. }
  164. /* send command to mc*/
  165. return mc_send_command(mc_io, &cmd);
  166. }
  167. /**
  168. * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
  169. * @mc_io: Pointer to MC portal's I/O object
  170. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  171. * @token: Token of DPNI object
  172. *
  173. * Return: '0' on Success; Error code otherwise.
  174. */
  175. int dpni_enable(struct fsl_mc_io *mc_io,
  176. u32 cmd_flags,
  177. u16 token)
  178. {
  179. struct fsl_mc_command cmd = { 0 };
  180. /* prepare command */
  181. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
  182. cmd_flags,
  183. token);
  184. /* send command to mc*/
  185. return mc_send_command(mc_io, &cmd);
  186. }
  187. /**
  188. * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
  189. * @mc_io: Pointer to MC portal's I/O object
  190. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  191. * @token: Token of DPNI object
  192. *
  193. * Return: '0' on Success; Error code otherwise.
  194. */
  195. int dpni_disable(struct fsl_mc_io *mc_io,
  196. u32 cmd_flags,
  197. u16 token)
  198. {
  199. struct fsl_mc_command cmd = { 0 };
  200. /* prepare command */
  201. cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
  202. cmd_flags,
  203. token);
  204. /* send command to mc*/
  205. return mc_send_command(mc_io, &cmd);
  206. }
  207. /**
  208. * dpni_is_enabled() - Check if the DPNI is enabled.
  209. * @mc_io: Pointer to MC portal's I/O object
  210. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  211. * @token: Token of DPNI object
  212. * @en: Returns '1' if object is enabled; '0' otherwise
  213. *
  214. * Return: '0' on Success; Error code otherwise.
  215. */
  216. int dpni_is_enabled(struct fsl_mc_io *mc_io,
  217. u32 cmd_flags,
  218. u16 token,
  219. int *en)
  220. {
  221. struct fsl_mc_command cmd = { 0 };
  222. struct dpni_rsp_is_enabled *rsp_params;
  223. int err;
  224. /* prepare command */
  225. cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
  226. cmd_flags,
  227. token);
  228. /* send command to mc*/
  229. err = mc_send_command(mc_io, &cmd);
  230. if (err)
  231. return err;
  232. /* retrieve response parameters */
  233. rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
  234. *en = dpni_get_field(rsp_params->enabled, ENABLE);
  235. return 0;
  236. }
  237. /**
  238. * dpni_reset() - Reset the DPNI, returns the object to initial state.
  239. * @mc_io: Pointer to MC portal's I/O object
  240. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  241. * @token: Token of DPNI object
  242. *
  243. * Return: '0' on Success; Error code otherwise.
  244. */
  245. int dpni_reset(struct fsl_mc_io *mc_io,
  246. u32 cmd_flags,
  247. u16 token)
  248. {
  249. struct fsl_mc_command cmd = { 0 };
  250. /* prepare command */
  251. cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
  252. cmd_flags,
  253. token);
  254. /* send command to mc*/
  255. return mc_send_command(mc_io, &cmd);
  256. }
  257. /**
  258. * dpni_set_irq_enable() - Set overall interrupt state.
  259. * @mc_io: Pointer to MC portal's I/O object
  260. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  261. * @token: Token of DPNI object
  262. * @irq_index: The interrupt index to configure
  263. * @en: Interrupt state: - enable = 1, disable = 0
  264. *
  265. * Allows GPP software to control when interrupts are generated.
  266. * Each interrupt can have up to 32 causes. The enable/disable control's the
  267. * overall interrupt state. if the interrupt is disabled no causes will cause
  268. * an interrupt.
  269. *
  270. * Return: '0' on Success; Error code otherwise.
  271. */
  272. int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
  273. u32 cmd_flags,
  274. u16 token,
  275. u8 irq_index,
  276. u8 en)
  277. {
  278. struct fsl_mc_command cmd = { 0 };
  279. struct dpni_cmd_set_irq_enable *cmd_params;
  280. /* prepare command */
  281. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
  282. cmd_flags,
  283. token);
  284. cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
  285. dpni_set_field(cmd_params->enable, ENABLE, en);
  286. cmd_params->irq_index = irq_index;
  287. /* send command to mc*/
  288. return mc_send_command(mc_io, &cmd);
  289. }
  290. /**
  291. * dpni_get_irq_enable() - Get overall interrupt state
  292. * @mc_io: Pointer to MC portal's I/O object
  293. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  294. * @token: Token of DPNI object
  295. * @irq_index: The interrupt index to configure
  296. * @en: Returned interrupt state - enable = 1, disable = 0
  297. *
  298. * Return: '0' on Success; Error code otherwise.
  299. */
  300. int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
  301. u32 cmd_flags,
  302. u16 token,
  303. u8 irq_index,
  304. u8 *en)
  305. {
  306. struct fsl_mc_command cmd = { 0 };
  307. struct dpni_cmd_get_irq_enable *cmd_params;
  308. struct dpni_rsp_get_irq_enable *rsp_params;
  309. int err;
  310. /* prepare command */
  311. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
  312. cmd_flags,
  313. token);
  314. cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
  315. cmd_params->irq_index = irq_index;
  316. /* send command to mc*/
  317. err = mc_send_command(mc_io, &cmd);
  318. if (err)
  319. return err;
  320. /* retrieve response parameters */
  321. rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
  322. *en = dpni_get_field(rsp_params->enabled, ENABLE);
  323. return 0;
  324. }
  325. /**
  326. * dpni_set_irq_mask() - Set interrupt mask.
  327. * @mc_io: Pointer to MC portal's I/O object
  328. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  329. * @token: Token of DPNI object
  330. * @irq_index: The interrupt index to configure
  331. * @mask: event mask to trigger interrupt;
  332. * each bit:
  333. * 0 = ignore event
  334. * 1 = consider event for asserting IRQ
  335. *
  336. * Every interrupt can have up to 32 causes and the interrupt model supports
  337. * masking/unmasking each cause independently
  338. *
  339. * Return: '0' on Success; Error code otherwise.
  340. */
  341. int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
  342. u32 cmd_flags,
  343. u16 token,
  344. u8 irq_index,
  345. u32 mask)
  346. {
  347. struct fsl_mc_command cmd = { 0 };
  348. struct dpni_cmd_set_irq_mask *cmd_params;
  349. /* prepare command */
  350. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
  351. cmd_flags,
  352. token);
  353. cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
  354. cmd_params->mask = cpu_to_le32(mask);
  355. cmd_params->irq_index = irq_index;
  356. /* send command to mc*/
  357. return mc_send_command(mc_io, &cmd);
  358. }
  359. /**
  360. * dpni_get_irq_mask() - Get interrupt mask.
  361. * @mc_io: Pointer to MC portal's I/O object
  362. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  363. * @token: Token of DPNI object
  364. * @irq_index: The interrupt index to configure
  365. * @mask: Returned event mask to trigger interrupt
  366. *
  367. * Every interrupt can have up to 32 causes and the interrupt model supports
  368. * masking/unmasking each cause independently
  369. *
  370. * Return: '0' on Success; Error code otherwise.
  371. */
  372. int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
  373. u32 cmd_flags,
  374. u16 token,
  375. u8 irq_index,
  376. u32 *mask)
  377. {
  378. struct fsl_mc_command cmd = { 0 };
  379. struct dpni_cmd_get_irq_mask *cmd_params;
  380. struct dpni_rsp_get_irq_mask *rsp_params;
  381. int err;
  382. /* prepare command */
  383. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
  384. cmd_flags,
  385. token);
  386. cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
  387. cmd_params->irq_index = irq_index;
  388. /* send command to mc*/
  389. err = mc_send_command(mc_io, &cmd);
  390. if (err)
  391. return err;
  392. /* retrieve response parameters */
  393. rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
  394. *mask = le32_to_cpu(rsp_params->mask);
  395. return 0;
  396. }
  397. /**
  398. * dpni_get_irq_status() - Get the current status of any pending interrupts.
  399. * @mc_io: Pointer to MC portal's I/O object
  400. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  401. * @token: Token of DPNI object
  402. * @irq_index: The interrupt index to configure
  403. * @status: Returned interrupts status - one bit per cause:
  404. * 0 = no interrupt pending
  405. * 1 = interrupt pending
  406. *
  407. * Return: '0' on Success; Error code otherwise.
  408. */
  409. int dpni_get_irq_status(struct fsl_mc_io *mc_io,
  410. u32 cmd_flags,
  411. u16 token,
  412. u8 irq_index,
  413. u32 *status)
  414. {
  415. struct fsl_mc_command cmd = { 0 };
  416. struct dpni_cmd_get_irq_status *cmd_params;
  417. struct dpni_rsp_get_irq_status *rsp_params;
  418. int err;
  419. /* prepare command */
  420. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
  421. cmd_flags,
  422. token);
  423. cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
  424. cmd_params->status = cpu_to_le32(*status);
  425. cmd_params->irq_index = irq_index;
  426. /* send command to mc*/
  427. err = mc_send_command(mc_io, &cmd);
  428. if (err)
  429. return err;
  430. /* retrieve response parameters */
  431. rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
  432. *status = le32_to_cpu(rsp_params->status);
  433. return 0;
  434. }
  435. /**
  436. * dpni_clear_irq_status() - Clear a pending interrupt's status
  437. * @mc_io: Pointer to MC portal's I/O object
  438. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  439. * @token: Token of DPNI object
  440. * @irq_index: The interrupt index to configure
  441. * @status: bits to clear (W1C) - one bit per cause:
  442. * 0 = don't change
  443. * 1 = clear status bit
  444. *
  445. * Return: '0' on Success; Error code otherwise.
  446. */
  447. int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
  448. u32 cmd_flags,
  449. u16 token,
  450. u8 irq_index,
  451. u32 status)
  452. {
  453. struct fsl_mc_command cmd = { 0 };
  454. struct dpni_cmd_clear_irq_status *cmd_params;
  455. /* prepare command */
  456. cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
  457. cmd_flags,
  458. token);
  459. cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
  460. cmd_params->irq_index = irq_index;
  461. cmd_params->status = cpu_to_le32(status);
  462. /* send command to mc*/
  463. return mc_send_command(mc_io, &cmd);
  464. }
  465. /**
  466. * dpni_get_attributes() - Retrieve DPNI attributes.
  467. * @mc_io: Pointer to MC portal's I/O object
  468. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  469. * @token: Token of DPNI object
  470. * @attr: Object's attributes
  471. *
  472. * Return: '0' on Success; Error code otherwise.
  473. */
  474. int dpni_get_attributes(struct fsl_mc_io *mc_io,
  475. u32 cmd_flags,
  476. u16 token,
  477. struct dpni_attr *attr)
  478. {
  479. struct fsl_mc_command cmd = { 0 };
  480. struct dpni_rsp_get_attr *rsp_params;
  481. int err;
  482. /* prepare command */
  483. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
  484. cmd_flags,
  485. token);
  486. /* send command to mc*/
  487. err = mc_send_command(mc_io, &cmd);
  488. if (err)
  489. return err;
  490. /* retrieve response parameters */
  491. rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
  492. attr->options = le32_to_cpu(rsp_params->options);
  493. attr->num_queues = rsp_params->num_queues;
  494. attr->num_tcs = rsp_params->num_tcs;
  495. attr->mac_filter_entries = rsp_params->mac_filter_entries;
  496. attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
  497. attr->qos_entries = rsp_params->qos_entries;
  498. attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
  499. attr->qos_key_size = rsp_params->qos_key_size;
  500. attr->fs_key_size = rsp_params->fs_key_size;
  501. attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
  502. return 0;
  503. }
  504. /**
  505. * dpni_set_errors_behavior() - Set errors behavior
  506. * @mc_io: Pointer to MC portal's I/O object
  507. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  508. * @token: Token of DPNI object
  509. * @cfg: Errors configuration
  510. *
  511. * this function may be called numerous times with different
  512. * error masks
  513. *
  514. * Return: '0' on Success; Error code otherwise.
  515. */
  516. int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
  517. u32 cmd_flags,
  518. u16 token,
  519. struct dpni_error_cfg *cfg)
  520. {
  521. struct fsl_mc_command cmd = { 0 };
  522. struct dpni_cmd_set_errors_behavior *cmd_params;
  523. /* prepare command */
  524. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
  525. cmd_flags,
  526. token);
  527. cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
  528. cmd_params->errors = cpu_to_le32(cfg->errors);
  529. dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
  530. dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
  531. /* send command to mc*/
  532. return mc_send_command(mc_io, &cmd);
  533. }
  534. /**
  535. * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
  536. * @mc_io: Pointer to MC portal's I/O object
  537. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  538. * @token: Token of DPNI object
  539. * @qtype: Type of queue to retrieve configuration for
  540. * @layout: Returns buffer layout attributes
  541. *
  542. * Return: '0' on Success; Error code otherwise.
  543. */
  544. int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
  545. u32 cmd_flags,
  546. u16 token,
  547. enum dpni_queue_type qtype,
  548. struct dpni_buffer_layout *layout)
  549. {
  550. struct fsl_mc_command cmd = { 0 };
  551. struct dpni_cmd_get_buffer_layout *cmd_params;
  552. struct dpni_rsp_get_buffer_layout *rsp_params;
  553. int err;
  554. /* prepare command */
  555. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
  556. cmd_flags,
  557. token);
  558. cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
  559. cmd_params->qtype = qtype;
  560. /* send command to mc*/
  561. err = mc_send_command(mc_io, &cmd);
  562. if (err)
  563. return err;
  564. /* retrieve response parameters */
  565. rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
  566. layout->pass_timestamp = dpni_get_field(rsp_params->flags, PASS_TS);
  567. layout->pass_parser_result = dpni_get_field(rsp_params->flags, PASS_PR);
  568. layout->pass_frame_status = dpni_get_field(rsp_params->flags, PASS_FS);
  569. layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
  570. layout->data_align = le16_to_cpu(rsp_params->data_align);
  571. layout->data_head_room = le16_to_cpu(rsp_params->head_room);
  572. layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
  573. return 0;
  574. }
  575. /**
  576. * dpni_set_buffer_layout() - Set buffer layout configuration.
  577. * @mc_io: Pointer to MC portal's I/O object
  578. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  579. * @token: Token of DPNI object
  580. * @qtype: Type of queue this configuration applies to
  581. * @layout: Buffer layout configuration
  582. *
  583. * Return: '0' on Success; Error code otherwise.
  584. *
  585. * @warning Allowed only when DPNI is disabled
  586. */
  587. int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
  588. u32 cmd_flags,
  589. u16 token,
  590. enum dpni_queue_type qtype,
  591. const struct dpni_buffer_layout *layout)
  592. {
  593. struct fsl_mc_command cmd = { 0 };
  594. struct dpni_cmd_set_buffer_layout *cmd_params;
  595. /* prepare command */
  596. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
  597. cmd_flags,
  598. token);
  599. cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
  600. cmd_params->qtype = qtype;
  601. cmd_params->options = cpu_to_le16(layout->options);
  602. dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
  603. dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
  604. dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
  605. cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
  606. cmd_params->data_align = cpu_to_le16(layout->data_align);
  607. cmd_params->head_room = cpu_to_le16(layout->data_head_room);
  608. cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
  609. /* send command to mc*/
  610. return mc_send_command(mc_io, &cmd);
  611. }
  612. /**
  613. * dpni_set_offload() - Set DPNI offload configuration.
  614. * @mc_io: Pointer to MC portal's I/O object
  615. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  616. * @token: Token of DPNI object
  617. * @type: Type of DPNI offload
  618. * @config: Offload configuration.
  619. * For checksum offloads, non-zero value enables the offload
  620. *
  621. * Return: '0' on Success; Error code otherwise.
  622. *
  623. * @warning Allowed only when DPNI is disabled
  624. */
  625. int dpni_set_offload(struct fsl_mc_io *mc_io,
  626. u32 cmd_flags,
  627. u16 token,
  628. enum dpni_offload type,
  629. u32 config)
  630. {
  631. struct fsl_mc_command cmd = { 0 };
  632. struct dpni_cmd_set_offload *cmd_params;
  633. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
  634. cmd_flags,
  635. token);
  636. cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
  637. cmd_params->dpni_offload = type;
  638. cmd_params->config = cpu_to_le32(config);
  639. return mc_send_command(mc_io, &cmd);
  640. }
  641. int dpni_get_offload(struct fsl_mc_io *mc_io,
  642. u32 cmd_flags,
  643. u16 token,
  644. enum dpni_offload type,
  645. u32 *config)
  646. {
  647. struct fsl_mc_command cmd = { 0 };
  648. struct dpni_cmd_get_offload *cmd_params;
  649. struct dpni_rsp_get_offload *rsp_params;
  650. int err;
  651. /* prepare command */
  652. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
  653. cmd_flags,
  654. token);
  655. cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
  656. cmd_params->dpni_offload = type;
  657. /* send command to mc*/
  658. err = mc_send_command(mc_io, &cmd);
  659. if (err)
  660. return err;
  661. /* retrieve response parameters */
  662. rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
  663. *config = le32_to_cpu(rsp_params->config);
  664. return 0;
  665. }
  666. /**
  667. * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
  668. * for enqueue operations
  669. * @mc_io: Pointer to MC portal's I/O object
  670. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  671. * @token: Token of DPNI object
  672. * @qtype: Type of queue to receive QDID for
  673. * @qdid: Returned virtual QDID value that should be used as an argument
  674. * in all enqueue operations
  675. *
  676. * Return: '0' on Success; Error code otherwise.
  677. */
  678. int dpni_get_qdid(struct fsl_mc_io *mc_io,
  679. u32 cmd_flags,
  680. u16 token,
  681. enum dpni_queue_type qtype,
  682. u16 *qdid)
  683. {
  684. struct fsl_mc_command cmd = { 0 };
  685. struct dpni_cmd_get_qdid *cmd_params;
  686. struct dpni_rsp_get_qdid *rsp_params;
  687. int err;
  688. /* prepare command */
  689. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
  690. cmd_flags,
  691. token);
  692. cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
  693. cmd_params->qtype = qtype;
  694. /* send command to mc*/
  695. err = mc_send_command(mc_io, &cmd);
  696. if (err)
  697. return err;
  698. /* retrieve response parameters */
  699. rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
  700. *qdid = le16_to_cpu(rsp_params->qdid);
  701. return 0;
  702. }
  703. /**
  704. * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
  705. * @mc_io: Pointer to MC portal's I/O object
  706. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  707. * @token: Token of DPNI object
  708. * @data_offset: Tx data offset (from start of buffer)
  709. *
  710. * Return: '0' on Success; Error code otherwise.
  711. */
  712. int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
  713. u32 cmd_flags,
  714. u16 token,
  715. u16 *data_offset)
  716. {
  717. struct fsl_mc_command cmd = { 0 };
  718. struct dpni_rsp_get_tx_data_offset *rsp_params;
  719. int err;
  720. /* prepare command */
  721. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
  722. cmd_flags,
  723. token);
  724. /* send command to mc*/
  725. err = mc_send_command(mc_io, &cmd);
  726. if (err)
  727. return err;
  728. /* retrieve response parameters */
  729. rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
  730. *data_offset = le16_to_cpu(rsp_params->data_offset);
  731. return 0;
  732. }
  733. /**
  734. * dpni_set_link_cfg() - set the link configuration.
  735. * @mc_io: Pointer to MC portal's I/O object
  736. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  737. * @token: Token of DPNI object
  738. * @cfg: Link configuration
  739. *
  740. * Return: '0' on Success; Error code otherwise.
  741. */
  742. int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
  743. u32 cmd_flags,
  744. u16 token,
  745. const struct dpni_link_cfg *cfg)
  746. {
  747. struct fsl_mc_command cmd = { 0 };
  748. struct dpni_cmd_link_cfg *cmd_params;
  749. /* prepare command */
  750. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
  751. cmd_flags,
  752. token);
  753. cmd_params = (struct dpni_cmd_link_cfg *)cmd.params;
  754. cmd_params->rate = cpu_to_le32(cfg->rate);
  755. cmd_params->options = cpu_to_le64(cfg->options);
  756. /* send command to mc*/
  757. return mc_send_command(mc_io, &cmd);
  758. }
  759. /**
  760. * dpni_get_link_cfg() - return the link configuration
  761. * @mc_io: Pointer to MC portal's I/O object
  762. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  763. * @token: Token of DPNI object
  764. * @cfg: Link configuration from dpni object
  765. *
  766. * Return: '0' on Success; Error code otherwise.
  767. */
  768. int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
  769. u32 cmd_flags,
  770. u16 token,
  771. struct dpni_link_cfg *cfg)
  772. {
  773. struct fsl_mc_command cmd = { 0 };
  774. struct dpni_cmd_link_cfg *rsp_params;
  775. int err;
  776. /* prepare command */
  777. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
  778. cmd_flags,
  779. token);
  780. /* send command to mc*/
  781. err = mc_send_command(mc_io, &cmd);
  782. if (err)
  783. return err;
  784. /* retrieve response parameters */
  785. rsp_params = (struct dpni_cmd_link_cfg *)cmd.params;
  786. cfg->rate = le32_to_cpu(rsp_params->rate);
  787. cfg->options = le64_to_cpu(rsp_params->options);
  788. return err;
  789. }
  790. /**
  791. * dpni_get_link_state() - Return the link state (either up or down)
  792. * @mc_io: Pointer to MC portal's I/O object
  793. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  794. * @token: Token of DPNI object
  795. * @state: Returned link state;
  796. *
  797. * Return: '0' on Success; Error code otherwise.
  798. */
  799. int dpni_get_link_state(struct fsl_mc_io *mc_io,
  800. u32 cmd_flags,
  801. u16 token,
  802. struct dpni_link_state *state)
  803. {
  804. struct fsl_mc_command cmd = { 0 };
  805. struct dpni_rsp_get_link_state *rsp_params;
  806. int err;
  807. /* prepare command */
  808. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
  809. cmd_flags,
  810. token);
  811. /* send command to mc*/
  812. err = mc_send_command(mc_io, &cmd);
  813. if (err)
  814. return err;
  815. /* retrieve response parameters */
  816. rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
  817. state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
  818. state->rate = le32_to_cpu(rsp_params->rate);
  819. state->options = le64_to_cpu(rsp_params->options);
  820. return 0;
  821. }
  822. /**
  823. * dpni_set_max_frame_length() - Set the maximum received frame length.
  824. * @mc_io: Pointer to MC portal's I/O object
  825. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  826. * @token: Token of DPNI object
  827. * @max_frame_length: Maximum received frame length (in
  828. * bytes); frame is discarded if its
  829. * length exceeds this value
  830. *
  831. * Return: '0' on Success; Error code otherwise.
  832. */
  833. int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
  834. u32 cmd_flags,
  835. u16 token,
  836. u16 max_frame_length)
  837. {
  838. struct fsl_mc_command cmd = { 0 };
  839. struct dpni_cmd_set_max_frame_length *cmd_params;
  840. /* prepare command */
  841. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
  842. cmd_flags,
  843. token);
  844. cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
  845. cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
  846. /* send command to mc*/
  847. return mc_send_command(mc_io, &cmd);
  848. }
  849. /**
  850. * dpni_get_max_frame_length() - Get the maximum received frame length.
  851. * @mc_io: Pointer to MC portal's I/O object
  852. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  853. * @token: Token of DPNI object
  854. * @max_frame_length: Maximum received frame length (in
  855. * bytes); frame is discarded if its
  856. * length exceeds this value
  857. *
  858. * Return: '0' on Success; Error code otherwise.
  859. */
  860. int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
  861. u32 cmd_flags,
  862. u16 token,
  863. u16 *max_frame_length)
  864. {
  865. struct fsl_mc_command cmd = { 0 };
  866. struct dpni_rsp_get_max_frame_length *rsp_params;
  867. int err;
  868. /* prepare command */
  869. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
  870. cmd_flags,
  871. token);
  872. /* send command to mc*/
  873. err = mc_send_command(mc_io, &cmd);
  874. if (err)
  875. return err;
  876. /* retrieve response parameters */
  877. rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
  878. *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
  879. return 0;
  880. }
  881. /**
  882. * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
  883. * @mc_io: Pointer to MC portal's I/O object
  884. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  885. * @token: Token of DPNI object
  886. * @en: Set to '1' to enable; '0' to disable
  887. *
  888. * Return: '0' on Success; Error code otherwise.
  889. */
  890. int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
  891. u32 cmd_flags,
  892. u16 token,
  893. int en)
  894. {
  895. struct fsl_mc_command cmd = { 0 };
  896. struct dpni_cmd_set_multicast_promisc *cmd_params;
  897. /* prepare command */
  898. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
  899. cmd_flags,
  900. token);
  901. cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
  902. dpni_set_field(cmd_params->enable, ENABLE, en);
  903. /* send command to mc*/
  904. return mc_send_command(mc_io, &cmd);
  905. }
  906. /**
  907. * dpni_get_multicast_promisc() - Get multicast promiscuous mode
  908. * @mc_io: Pointer to MC portal's I/O object
  909. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  910. * @token: Token of DPNI object
  911. * @en: Returns '1' if enabled; '0' otherwise
  912. *
  913. * Return: '0' on Success; Error code otherwise.
  914. */
  915. int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
  916. u32 cmd_flags,
  917. u16 token,
  918. int *en)
  919. {
  920. struct fsl_mc_command cmd = { 0 };
  921. struct dpni_rsp_get_multicast_promisc *rsp_params;
  922. int err;
  923. /* prepare command */
  924. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
  925. cmd_flags,
  926. token);
  927. /* send command to mc*/
  928. err = mc_send_command(mc_io, &cmd);
  929. if (err)
  930. return err;
  931. /* retrieve response parameters */
  932. rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
  933. *en = dpni_get_field(rsp_params->enabled, ENABLE);
  934. return 0;
  935. }
  936. /**
  937. * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
  938. * @mc_io: Pointer to MC portal's I/O object
  939. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  940. * @token: Token of DPNI object
  941. * @en: Set to '1' to enable; '0' to disable
  942. *
  943. * Return: '0' on Success; Error code otherwise.
  944. */
  945. int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
  946. u32 cmd_flags,
  947. u16 token,
  948. int en)
  949. {
  950. struct fsl_mc_command cmd = { 0 };
  951. struct dpni_cmd_set_unicast_promisc *cmd_params;
  952. /* prepare command */
  953. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
  954. cmd_flags,
  955. token);
  956. cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
  957. dpni_set_field(cmd_params->enable, ENABLE, en);
  958. /* send command to mc*/
  959. return mc_send_command(mc_io, &cmd);
  960. }
  961. /**
  962. * dpni_get_unicast_promisc() - Get unicast promiscuous mode
  963. * @mc_io: Pointer to MC portal's I/O object
  964. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  965. * @token: Token of DPNI object
  966. * @en: Returns '1' if enabled; '0' otherwise
  967. *
  968. * Return: '0' on Success; Error code otherwise.
  969. */
  970. int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
  971. u32 cmd_flags,
  972. u16 token,
  973. int *en)
  974. {
  975. struct fsl_mc_command cmd = { 0 };
  976. struct dpni_rsp_get_unicast_promisc *rsp_params;
  977. int err;
  978. /* prepare command */
  979. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
  980. cmd_flags,
  981. token);
  982. /* send command to mc*/
  983. err = mc_send_command(mc_io, &cmd);
  984. if (err)
  985. return err;
  986. /* retrieve response parameters */
  987. rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
  988. *en = dpni_get_field(rsp_params->enabled, ENABLE);
  989. return 0;
  990. }
  991. /**
  992. * dpni_set_primary_mac_addr() - Set the primary MAC address
  993. * @mc_io: Pointer to MC portal's I/O object
  994. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  995. * @token: Token of DPNI object
  996. * @mac_addr: MAC address to set as primary address
  997. *
  998. * Return: '0' on Success; Error code otherwise.
  999. */
  1000. int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
  1001. u32 cmd_flags,
  1002. u16 token,
  1003. const u8 mac_addr[6])
  1004. {
  1005. struct fsl_mc_command cmd = { 0 };
  1006. struct dpni_cmd_set_primary_mac_addr *cmd_params;
  1007. int i;
  1008. /* prepare command */
  1009. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
  1010. cmd_flags,
  1011. token);
  1012. cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
  1013. for (i = 0; i < 6; i++)
  1014. cmd_params->mac_addr[i] = mac_addr[5 - i];
  1015. /* send command to mc*/
  1016. return mc_send_command(mc_io, &cmd);
  1017. }
  1018. /**
  1019. * dpni_get_primary_mac_addr() - Get the primary MAC address
  1020. * @mc_io: Pointer to MC portal's I/O object
  1021. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1022. * @token: Token of DPNI object
  1023. * @mac_addr: Returned MAC address
  1024. *
  1025. * Return: '0' on Success; Error code otherwise.
  1026. */
  1027. int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
  1028. u32 cmd_flags,
  1029. u16 token,
  1030. u8 mac_addr[6])
  1031. {
  1032. struct fsl_mc_command cmd = { 0 };
  1033. struct dpni_rsp_get_primary_mac_addr *rsp_params;
  1034. int i, err;
  1035. /* prepare command */
  1036. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
  1037. cmd_flags,
  1038. token);
  1039. /* send command to mc*/
  1040. err = mc_send_command(mc_io, &cmd);
  1041. if (err)
  1042. return err;
  1043. /* retrieve response parameters */
  1044. rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
  1045. for (i = 0; i < 6; i++)
  1046. mac_addr[5 - i] = rsp_params->mac_addr[i];
  1047. return 0;
  1048. }
  1049. /**
  1050. * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
  1051. * port the DPNI is attached to
  1052. * @mc_io: Pointer to MC portal's I/O object
  1053. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1054. * @token: Token of DPNI object
  1055. * @mac_addr: MAC address of the physical port, if any, otherwise 0
  1056. *
  1057. * The primary MAC address is not cleared by this operation.
  1058. *
  1059. * Return: '0' on Success; Error code otherwise.
  1060. */
  1061. int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
  1062. u32 cmd_flags,
  1063. u16 token,
  1064. u8 mac_addr[6])
  1065. {
  1066. struct fsl_mc_command cmd = { 0 };
  1067. struct dpni_rsp_get_port_mac_addr *rsp_params;
  1068. int i, err;
  1069. /* prepare command */
  1070. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
  1071. cmd_flags,
  1072. token);
  1073. /* send command to mc*/
  1074. err = mc_send_command(mc_io, &cmd);
  1075. if (err)
  1076. return err;
  1077. /* retrieve response parameters */
  1078. rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
  1079. for (i = 0; i < 6; i++)
  1080. mac_addr[5 - i] = rsp_params->mac_addr[i];
  1081. return 0;
  1082. }
  1083. /**
  1084. * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
  1085. * @mc_io: Pointer to MC portal's I/O object
  1086. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1087. * @token: Token of DPNI object
  1088. * @en: Set to '1' to enable; '0' to disable
  1089. *
  1090. * Return: '0' on Success; Error code otherwise.
  1091. */
  1092. int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
  1093. u32 cmd_flags,
  1094. u16 token,
  1095. u32 en)
  1096. {
  1097. struct dpni_cmd_enable_vlan_filter *cmd_params;
  1098. struct fsl_mc_command cmd = { 0 };
  1099. /* prepare command */
  1100. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
  1101. cmd_flags,
  1102. token);
  1103. cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
  1104. dpni_set_field(cmd_params->en, ENABLE, en);
  1105. /* send command to mc*/
  1106. return mc_send_command(mc_io, &cmd);
  1107. }
  1108. /**
  1109. * dpni_add_vlan_id() - Add VLAN ID filter
  1110. * @mc_io: Pointer to MC portal's I/O object
  1111. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1112. * @token: Token of DPNI object
  1113. * @vlan_id: VLAN ID to add
  1114. * @flags: 0 - tc_id and flow_id will be ignored.
  1115. * Pkt with this vlan_id will be passed to the next
  1116. * classification stages
  1117. * DPNI_VLAN_SET_QUEUE_ACTION
  1118. * Pkt with this vlan_id will be forward directly to
  1119. * queue defined by the tc_id and flow_id
  1120. *
  1121. * @tc_id: Traffic class selection (0-7)
  1122. * @flow_id: Selects the specific queue out of the set allocated for the
  1123. * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
  1124. *
  1125. * Return: '0' on Success; Error code otherwise.
  1126. */
  1127. int dpni_add_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1128. u16 vlan_id, u8 flags, u8 tc_id, u8 flow_id)
  1129. {
  1130. struct dpni_cmd_vlan_id *cmd_params;
  1131. struct fsl_mc_command cmd = { 0 };
  1132. /* prepare command */
  1133. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
  1134. cmd_flags,
  1135. token);
  1136. cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
  1137. cmd_params->flags = flags;
  1138. cmd_params->tc_id = tc_id;
  1139. cmd_params->flow_id = flow_id;
  1140. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  1141. /* send command to mc*/
  1142. return mc_send_command(mc_io, &cmd);
  1143. }
  1144. /**
  1145. * dpni_remove_vlan_id() - Remove VLAN ID filter
  1146. * @mc_io: Pointer to MC portal's I/O object
  1147. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1148. * @token: Token of DPNI object
  1149. * @vlan_id: VLAN ID to remove
  1150. *
  1151. * Return: '0' on Success; Error code otherwise.
  1152. */
  1153. int dpni_remove_vlan_id(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1154. u16 vlan_id)
  1155. {
  1156. struct dpni_cmd_vlan_id *cmd_params;
  1157. struct fsl_mc_command cmd = { 0 };
  1158. /* prepare command */
  1159. cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
  1160. cmd_flags,
  1161. token);
  1162. cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
  1163. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  1164. /* send command to mc*/
  1165. return mc_send_command(mc_io, &cmd);
  1166. }
  1167. /**
  1168. * dpni_add_mac_addr() - Add MAC address filter
  1169. * @mc_io: Pointer to MC portal's I/O object
  1170. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1171. * @token: Token of DPNI object
  1172. * @mac_addr: MAC address to add
  1173. *
  1174. * Return: '0' on Success; Error code otherwise.
  1175. */
  1176. int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
  1177. u32 cmd_flags,
  1178. u16 token,
  1179. const u8 mac_addr[6])
  1180. {
  1181. struct fsl_mc_command cmd = { 0 };
  1182. struct dpni_cmd_add_mac_addr *cmd_params;
  1183. int i;
  1184. /* prepare command */
  1185. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
  1186. cmd_flags,
  1187. token);
  1188. cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
  1189. for (i = 0; i < 6; i++)
  1190. cmd_params->mac_addr[i] = mac_addr[5 - i];
  1191. /* send command to mc*/
  1192. return mc_send_command(mc_io, &cmd);
  1193. }
  1194. /**
  1195. * dpni_remove_mac_addr() - Remove MAC address filter
  1196. * @mc_io: Pointer to MC portal's I/O object
  1197. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1198. * @token: Token of DPNI object
  1199. * @mac_addr: MAC address to remove
  1200. *
  1201. * Return: '0' on Success; Error code otherwise.
  1202. */
  1203. int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
  1204. u32 cmd_flags,
  1205. u16 token,
  1206. const u8 mac_addr[6])
  1207. {
  1208. struct fsl_mc_command cmd = { 0 };
  1209. struct dpni_cmd_remove_mac_addr *cmd_params;
  1210. int i;
  1211. /* prepare command */
  1212. cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
  1213. cmd_flags,
  1214. token);
  1215. cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
  1216. for (i = 0; i < 6; i++)
  1217. cmd_params->mac_addr[i] = mac_addr[5 - i];
  1218. /* send command to mc*/
  1219. return mc_send_command(mc_io, &cmd);
  1220. }
  1221. /**
  1222. * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
  1223. * @mc_io: Pointer to MC portal's I/O object
  1224. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1225. * @token: Token of DPNI object
  1226. * @unicast: Set to '1' to clear unicast addresses
  1227. * @multicast: Set to '1' to clear multicast addresses
  1228. *
  1229. * The primary MAC address is not cleared by this operation.
  1230. *
  1231. * Return: '0' on Success; Error code otherwise.
  1232. */
  1233. int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
  1234. u32 cmd_flags,
  1235. u16 token,
  1236. int unicast,
  1237. int multicast)
  1238. {
  1239. struct fsl_mc_command cmd = { 0 };
  1240. struct dpni_cmd_clear_mac_filters *cmd_params;
  1241. /* prepare command */
  1242. cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
  1243. cmd_flags,
  1244. token);
  1245. cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
  1246. dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
  1247. dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
  1248. /* send command to mc*/
  1249. return mc_send_command(mc_io, &cmd);
  1250. }
  1251. /**
  1252. * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
  1253. * @mc_io: Pointer to MC portal's I/O object
  1254. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1255. * @token: Token of DPNI object
  1256. * @tc_id: Traffic class selection (0-7)
  1257. * @cfg: Traffic class distribution configuration
  1258. *
  1259. * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
  1260. * first to prepare the key_cfg_iova parameter
  1261. *
  1262. * Return: '0' on Success; error code otherwise.
  1263. */
  1264. int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
  1265. u32 cmd_flags,
  1266. u16 token,
  1267. u8 tc_id,
  1268. const struct dpni_rx_tc_dist_cfg *cfg)
  1269. {
  1270. struct fsl_mc_command cmd = { 0 };
  1271. struct dpni_cmd_set_rx_tc_dist *cmd_params;
  1272. /* prepare command */
  1273. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
  1274. cmd_flags,
  1275. token);
  1276. cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
  1277. cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
  1278. cmd_params->tc_id = tc_id;
  1279. dpni_set_field(cmd_params->flags, DIST_MODE, cfg->dist_mode);
  1280. dpni_set_field(cmd_params->flags, MISS_ACTION, cfg->fs_cfg.miss_action);
  1281. cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
  1282. cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
  1283. /* send command to mc*/
  1284. return mc_send_command(mc_io, &cmd);
  1285. }
  1286. /**
  1287. * dpni_set_congestion_notification() - Set traffic class congestion
  1288. * notification configuration
  1289. * @mc_io: Pointer to MC portal's I/O object
  1290. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1291. * @token: Token of DPNI object
  1292. * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
  1293. * @tc_id: Traffic class selection (0-7)
  1294. * @cfg: Congestion notification configuration
  1295. *
  1296. * Return: '0' on Success; error code otherwise.
  1297. */
  1298. int dpni_set_congestion_notification(
  1299. struct fsl_mc_io *mc_io,
  1300. u32 cmd_flags,
  1301. u16 token,
  1302. enum dpni_queue_type qtype,
  1303. u8 tc_id,
  1304. const struct dpni_congestion_notification_cfg *cfg)
  1305. {
  1306. struct dpni_cmd_set_congestion_notification *cmd_params;
  1307. struct fsl_mc_command cmd = { 0 };
  1308. /* prepare command */
  1309. cmd.header =
  1310. mc_encode_cmd_header(DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
  1311. cmd_flags,
  1312. token);
  1313. cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
  1314. cmd_params->qtype = qtype;
  1315. cmd_params->tc = tc_id;
  1316. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  1317. cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
  1318. cmd_params->dest_priority = cfg->dest_cfg.priority;
  1319. dpni_set_field(cmd_params->type_units, DEST_TYPE,
  1320. cfg->dest_cfg.dest_type);
  1321. dpni_set_field(cmd_params->type_units, CONG_UNITS, cfg->units);
  1322. cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
  1323. cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
  1324. cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
  1325. cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
  1326. /* send command to mc*/
  1327. return mc_send_command(mc_io, &cmd);
  1328. }
  1329. /**
  1330. * dpni_set_queue() - Set queue parameters
  1331. * @mc_io: Pointer to MC portal's I/O object
  1332. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1333. * @token: Token of DPNI object
  1334. * @qtype: Type of queue - all queue types are supported, although
  1335. * the command is ignored for Tx
  1336. * @tc: Traffic class, in range 0 to NUM_TCS - 1
  1337. * @index: Selects the specific queue out of the set allocated for the
  1338. * same TC. Value must be in range 0 to NUM_QUEUES - 1
  1339. * @options: A combination of DPNI_QUEUE_OPT_ values that control what
  1340. * configuration options are set on the queue
  1341. * @queue: Queue structure
  1342. *
  1343. * Return: '0' on Success; Error code otherwise.
  1344. */
  1345. int dpni_set_queue(struct fsl_mc_io *mc_io,
  1346. u32 cmd_flags,
  1347. u16 token,
  1348. enum dpni_queue_type qtype,
  1349. u8 tc,
  1350. u8 index,
  1351. u8 options,
  1352. const struct dpni_queue *queue)
  1353. {
  1354. struct fsl_mc_command cmd = { 0 };
  1355. struct dpni_cmd_set_queue *cmd_params;
  1356. /* prepare command */
  1357. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
  1358. cmd_flags,
  1359. token);
  1360. cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
  1361. cmd_params->qtype = qtype;
  1362. cmd_params->tc = tc;
  1363. cmd_params->index = index;
  1364. cmd_params->options = options;
  1365. cmd_params->dest_id = cpu_to_le32(queue->destination.id);
  1366. cmd_params->dest_prio = queue->destination.priority;
  1367. dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
  1368. dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
  1369. dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
  1370. queue->destination.hold_active);
  1371. cmd_params->flc = cpu_to_le64(queue->flc.value);
  1372. cmd_params->user_context = cpu_to_le64(queue->user_context);
  1373. /* send command to mc */
  1374. return mc_send_command(mc_io, &cmd);
  1375. }
  1376. /**
  1377. * dpni_get_queue() - Get queue parameters
  1378. * @mc_io: Pointer to MC portal's I/O object
  1379. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1380. * @token: Token of DPNI object
  1381. * @qtype: Type of queue - all queue types are supported
  1382. * @tc: Traffic class, in range 0 to NUM_TCS - 1
  1383. * @index: Selects the specific queue out of the set allocated for the
  1384. * same TC. Value must be in range 0 to NUM_QUEUES - 1
  1385. * @queue: Queue configuration structure
  1386. * @qid: Queue identification
  1387. *
  1388. * Return: '0' on Success; Error code otherwise.
  1389. */
  1390. int dpni_get_queue(struct fsl_mc_io *mc_io,
  1391. u32 cmd_flags,
  1392. u16 token,
  1393. enum dpni_queue_type qtype,
  1394. u8 tc,
  1395. u8 index,
  1396. struct dpni_queue *queue,
  1397. struct dpni_queue_id *qid)
  1398. {
  1399. struct fsl_mc_command cmd = { 0 };
  1400. struct dpni_cmd_get_queue *cmd_params;
  1401. struct dpni_rsp_get_queue *rsp_params;
  1402. int err;
  1403. /* prepare command */
  1404. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
  1405. cmd_flags,
  1406. token);
  1407. cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
  1408. cmd_params->qtype = qtype;
  1409. cmd_params->tc = tc;
  1410. cmd_params->index = index;
  1411. /* send command to mc */
  1412. err = mc_send_command(mc_io, &cmd);
  1413. if (err)
  1414. return err;
  1415. /* retrieve response parameters */
  1416. rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
  1417. queue->destination.id = le32_to_cpu(rsp_params->dest_id);
  1418. queue->destination.priority = rsp_params->dest_prio;
  1419. queue->destination.type = dpni_get_field(rsp_params->flags,
  1420. DEST_TYPE);
  1421. queue->flc.stash_control = dpni_get_field(rsp_params->flags,
  1422. STASH_CTRL);
  1423. queue->destination.hold_active = dpni_get_field(rsp_params->flags,
  1424. HOLD_ACTIVE);
  1425. queue->flc.value = le64_to_cpu(rsp_params->flc);
  1426. queue->user_context = le64_to_cpu(rsp_params->user_context);
  1427. qid->fqid = le32_to_cpu(rsp_params->fqid);
  1428. qid->qdbin = le16_to_cpu(rsp_params->qdbin);
  1429. return 0;
  1430. }
  1431. /**
  1432. * dpni_get_statistics() - Get DPNI statistics
  1433. * @mc_io: Pointer to MC portal's I/O object
  1434. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1435. * @token: Token of DPNI object
  1436. * @page: Selects the statistics page to retrieve, see
  1437. * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
  1438. * @stat: Structure containing the statistics
  1439. *
  1440. * Return: '0' on Success; Error code otherwise.
  1441. */
  1442. int dpni_get_statistics(struct fsl_mc_io *mc_io,
  1443. u32 cmd_flags,
  1444. u16 token,
  1445. u8 page,
  1446. union dpni_statistics *stat)
  1447. {
  1448. struct fsl_mc_command cmd = { 0 };
  1449. struct dpni_cmd_get_statistics *cmd_params;
  1450. struct dpni_rsp_get_statistics *rsp_params;
  1451. int i, err;
  1452. /* prepare command */
  1453. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
  1454. cmd_flags,
  1455. token);
  1456. cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
  1457. cmd_params->page_number = page;
  1458. /* send command to mc */
  1459. err = mc_send_command(mc_io, &cmd);
  1460. if (err)
  1461. return err;
  1462. /* retrieve response parameters */
  1463. rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
  1464. for (i = 0; i < DPNI_STATISTICS_CNT; i++)
  1465. stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
  1466. return 0;
  1467. }
  1468. /**
  1469. * dpni_set_taildrop() - Set taildrop per queue or TC
  1470. * @mc_io: Pointer to MC portal's I/O object
  1471. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1472. * @token: Token of DPNI object
  1473. * @cg_point: Congestion point
  1474. * @qtype: Queue type on which the taildrop is configured.
  1475. * Only Rx queues are supported for now
  1476. * @tc: Traffic class to apply this taildrop to
  1477. * @index: Index of the queue if the DPNI supports multiple queues for
  1478. * traffic distribution. Ignored if CONGESTION_POINT is not 0.
  1479. * @taildrop: Taildrop structure
  1480. *
  1481. * Return: '0' on Success; Error code otherwise.
  1482. */
  1483. int dpni_set_taildrop(struct fsl_mc_io *mc_io,
  1484. u32 cmd_flags,
  1485. u16 token,
  1486. enum dpni_congestion_point cg_point,
  1487. enum dpni_queue_type qtype,
  1488. u8 tc,
  1489. u8 index,
  1490. struct dpni_taildrop *taildrop)
  1491. {
  1492. struct fsl_mc_command cmd = { 0 };
  1493. struct dpni_cmd_set_taildrop *cmd_params;
  1494. /* prepare command */
  1495. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
  1496. cmd_flags,
  1497. token);
  1498. cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
  1499. cmd_params->congestion_point = cg_point;
  1500. cmd_params->qtype = qtype;
  1501. cmd_params->tc = tc;
  1502. cmd_params->index = index;
  1503. dpni_set_field(cmd_params->enable, ENABLE, taildrop->enable);
  1504. cmd_params->units = taildrop->units;
  1505. cmd_params->threshold = cpu_to_le32(taildrop->threshold);
  1506. /* send command to mc */
  1507. return mc_send_command(mc_io, &cmd);
  1508. }
  1509. /**
  1510. * dpni_get_taildrop() - Get taildrop information
  1511. * @mc_io: Pointer to MC portal's I/O object
  1512. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1513. * @token: Token of DPNI object
  1514. * @cg_point: Congestion point
  1515. * @qtype: Queue type on which the taildrop is configured.
  1516. * Only Rx queues are supported for now
  1517. * @tc: Traffic class to apply this taildrop to
  1518. * @index: Index of the queue if the DPNI supports multiple queues for
  1519. * traffic distribution. Ignored if CONGESTION_POINT is not 0.
  1520. * @taildrop: Taildrop structure
  1521. *
  1522. * Return: '0' on Success; Error code otherwise.
  1523. */
  1524. int dpni_get_taildrop(struct fsl_mc_io *mc_io,
  1525. u32 cmd_flags,
  1526. u16 token,
  1527. enum dpni_congestion_point cg_point,
  1528. enum dpni_queue_type qtype,
  1529. u8 tc,
  1530. u8 index,
  1531. struct dpni_taildrop *taildrop)
  1532. {
  1533. struct fsl_mc_command cmd = { 0 };
  1534. struct dpni_cmd_get_taildrop *cmd_params;
  1535. struct dpni_rsp_get_taildrop *rsp_params;
  1536. int err;
  1537. /* prepare command */
  1538. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
  1539. cmd_flags,
  1540. token);
  1541. cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
  1542. cmd_params->congestion_point = cg_point;
  1543. cmd_params->qtype = qtype;
  1544. cmd_params->tc = tc;
  1545. cmd_params->index = index;
  1546. /* send command to mc */
  1547. err = mc_send_command(mc_io, &cmd);
  1548. if (err)
  1549. return err;
  1550. /* retrieve response parameters */
  1551. rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
  1552. taildrop->enable = dpni_get_field(rsp_params->enable, ENABLE);
  1553. taildrop->units = rsp_params->units;
  1554. taildrop->threshold = le32_to_cpu(rsp_params->threshold);
  1555. return 0;
  1556. }
  1557. /**
  1558. * dpni_get_api_version() - Get Data Path Network Interface API version
  1559. * @mc_io: Pointer to MC portal's I/O object
  1560. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1561. * @major_ver: Major version of data path network interface API
  1562. * @minor_ver: Minor version of data path network interface API
  1563. *
  1564. * Return: '0' on Success; Error code otherwise.
  1565. */
  1566. int dpni_get_api_version(struct fsl_mc_io *mc_io,
  1567. u32 cmd_flags,
  1568. u16 *major_ver,
  1569. u16 *minor_ver)
  1570. {
  1571. struct dpni_rsp_get_api_version *rsp_params;
  1572. struct fsl_mc_command cmd = { 0 };
  1573. int err;
  1574. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
  1575. cmd_flags, 0);
  1576. err = mc_send_command(mc_io, &cmd);
  1577. if (err)
  1578. return err;
  1579. rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
  1580. *major_ver = le16_to_cpu(rsp_params->major);
  1581. *minor_ver = le16_to_cpu(rsp_params->minor);
  1582. return 0;
  1583. }
  1584. /**
  1585. * dpni_set_rx_fs_dist() - Set Rx flow steering distribution
  1586. * @mc_io: Pointer to MC portal's I/O object
  1587. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1588. * @token: Token of DPNI object
  1589. * @cfg: Distribution configuration
  1590. *
  1591. * If the FS is already enabled with a previous call the classification
  1592. * key will be changed but all the table rules are kept. If the
  1593. * existing rules do not match the key the results will not be
  1594. * predictable. It is the user responsibility to keep key integrity.
  1595. * If cfg.enable is set to 1 the command will create a flow steering table
  1596. * and will classify packets according to this table. The packets that
  1597. * miss all the table rules will be classified according to settings
  1598. * made in dpni_set_rx_hash_dist()
  1599. * If cfg.enable is set to 0 the command will clear flow steering table.
  1600. * The packets will be classified according to settings made in
  1601. * dpni_set_rx_hash_dist()
  1602. *
  1603. * Return: '0' on Success; Error code otherwise.
  1604. */
  1605. int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io,
  1606. u32 cmd_flags,
  1607. u16 token,
  1608. const struct dpni_rx_dist_cfg *cfg)
  1609. {
  1610. struct dpni_cmd_set_rx_fs_dist *cmd_params;
  1611. struct fsl_mc_command cmd = { 0 };
  1612. /* prepare command */
  1613. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
  1614. cmd_flags,
  1615. token);
  1616. cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
  1617. cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
  1618. dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
  1619. cmd_params->tc = cfg->tc;
  1620. cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
  1621. cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
  1622. /* send command to mc*/
  1623. return mc_send_command(mc_io, &cmd);
  1624. }
  1625. /**
  1626. * dpni_set_rx_hash_dist() - Set Rx hash distribution
  1627. * @mc_io: Pointer to MC portal's I/O object
  1628. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1629. * @token: Token of DPNI object
  1630. * @cfg: Distribution configuration
  1631. * If cfg.enable is set to 1 the packets will be classified using a hash
  1632. * function based on the key received in cfg.key_cfg_iova parameter.
  1633. * If cfg.enable is set to 0 the packets will be sent to the default queue
  1634. *
  1635. * Return: '0' on Success; Error code otherwise.
  1636. */
  1637. int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io,
  1638. u32 cmd_flags,
  1639. u16 token,
  1640. const struct dpni_rx_dist_cfg *cfg)
  1641. {
  1642. struct dpni_cmd_set_rx_hash_dist *cmd_params;
  1643. struct fsl_mc_command cmd = { 0 };
  1644. /* prepare command */
  1645. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
  1646. cmd_flags,
  1647. token);
  1648. cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
  1649. cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
  1650. dpni_set_field(cmd_params->enable, RX_HASH_DIST_ENABLE, cfg->enable);
  1651. cmd_params->tc = cfg->tc;
  1652. cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
  1653. /* send command to mc*/
  1654. return mc_send_command(mc_io, &cmd);
  1655. }
  1656. /**
  1657. * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
  1658. * (to select a flow ID)
  1659. * @mc_io: Pointer to MC portal's I/O object
  1660. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1661. * @token: Token of DPNI object
  1662. * @tc_id: Traffic class selection (0-7)
  1663. * @index: Location in the FS table where to insert the entry.
  1664. * Only relevant if MASKING is enabled for FS
  1665. * classification on this DPNI, it is ignored for exact match.
  1666. * @cfg: Flow steering rule to add
  1667. * @action: Action to be taken as result of a classification hit
  1668. *
  1669. * Return: '0' on Success; Error code otherwise.
  1670. */
  1671. int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
  1672. u32 cmd_flags,
  1673. u16 token,
  1674. u8 tc_id,
  1675. u16 index,
  1676. const struct dpni_rule_cfg *cfg,
  1677. const struct dpni_fs_action_cfg *action)
  1678. {
  1679. struct dpni_cmd_add_fs_entry *cmd_params;
  1680. struct fsl_mc_command cmd = { 0 };
  1681. /* prepare command */
  1682. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
  1683. cmd_flags,
  1684. token);
  1685. cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
  1686. cmd_params->tc_id = tc_id;
  1687. cmd_params->key_size = cfg->key_size;
  1688. cmd_params->index = cpu_to_le16(index);
  1689. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1690. cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
  1691. cmd_params->options = cpu_to_le16(action->options);
  1692. cmd_params->flow_id = cpu_to_le16(action->flow_id);
  1693. cmd_params->flc = cpu_to_le64(action->flc);
  1694. /* send command to mc*/
  1695. return mc_send_command(mc_io, &cmd);
  1696. }
  1697. /**
  1698. * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
  1699. * traffic class
  1700. * @mc_io: Pointer to MC portal's I/O object
  1701. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1702. * @token: Token of DPNI object
  1703. * @tc_id: Traffic class selection (0-7)
  1704. * @cfg: Flow steering rule to remove
  1705. *
  1706. * Return: '0' on Success; Error code otherwise.
  1707. */
  1708. int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
  1709. u32 cmd_flags,
  1710. u16 token,
  1711. u8 tc_id,
  1712. const struct dpni_rule_cfg *cfg)
  1713. {
  1714. struct dpni_cmd_remove_fs_entry *cmd_params;
  1715. struct fsl_mc_command cmd = { 0 };
  1716. /* prepare command */
  1717. cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
  1718. cmd_flags,
  1719. token);
  1720. cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
  1721. cmd_params->tc_id = tc_id;
  1722. cmd_params->key_size = cfg->key_size;
  1723. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1724. cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
  1725. /* send command to mc*/
  1726. return mc_send_command(mc_io, &cmd);
  1727. }
  1728. /**
  1729. * dpni_set_qos_table() - Set QoS mapping table
  1730. * @mc_io: Pointer to MC portal's I/O object
  1731. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1732. * @token: Token of DPNI object
  1733. * @cfg: QoS table configuration
  1734. *
  1735. * This function and all QoS-related functions require that
  1736. *'max_tcs > 1' was set at DPNI creation.
  1737. *
  1738. * warning: Before calling this function, call dpkg_prepare_key_cfg() to
  1739. * prepare the key_cfg_iova parameter
  1740. *
  1741. * Return: '0' on Success; Error code otherwise.
  1742. */
  1743. int dpni_set_qos_table(struct fsl_mc_io *mc_io,
  1744. u32 cmd_flags,
  1745. u16 token,
  1746. const struct dpni_qos_tbl_cfg *cfg)
  1747. {
  1748. struct dpni_cmd_set_qos_table *cmd_params;
  1749. struct fsl_mc_command cmd = { 0 };
  1750. /* prepare command */
  1751. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
  1752. cmd_flags,
  1753. token);
  1754. cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
  1755. cmd_params->default_tc = cfg->default_tc;
  1756. cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
  1757. dpni_set_field(cmd_params->discard_on_miss, DISCARD_ON_MISS,
  1758. cfg->discard_on_miss);
  1759. /* send command to mc*/
  1760. return mc_send_command(mc_io, &cmd);
  1761. }
  1762. /**
  1763. * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
  1764. * @mc_io: Pointer to MC portal's I/O object
  1765. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1766. * @token: Token of DPNI object
  1767. * @cfg: QoS rule to add
  1768. * @tc_id: Traffic class selection (0-7)
  1769. * @index: Location in the QoS table where to insert the entry.
  1770. * Only relevant if MASKING is enabled for QoS classification on
  1771. * this DPNI, it is ignored for exact match.
  1772. *
  1773. * Return: '0' on Success; Error code otherwise.
  1774. */
  1775. int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
  1776. u32 cmd_flags,
  1777. u16 token,
  1778. const struct dpni_rule_cfg *cfg,
  1779. u8 tc_id,
  1780. u16 index)
  1781. {
  1782. struct dpni_cmd_add_qos_entry *cmd_params;
  1783. struct fsl_mc_command cmd = { 0 };
  1784. /* prepare command */
  1785. cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
  1786. cmd_flags,
  1787. token);
  1788. cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
  1789. cmd_params->tc_id = tc_id;
  1790. cmd_params->key_size = cfg->key_size;
  1791. cmd_params->index = cpu_to_le16(index);
  1792. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1793. cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
  1794. /* send command to mc*/
  1795. return mc_send_command(mc_io, &cmd);
  1796. }
  1797. /**
  1798. * dpni_remove_qos_entry() - Remove QoS mapping entry
  1799. * @mc_io: Pointer to MC portal's I/O object
  1800. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1801. * @token: Token of DPNI object
  1802. * @cfg: QoS rule to remove
  1803. *
  1804. * Return: '0' on Success; Error code otherwise.
  1805. */
  1806. int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
  1807. u32 cmd_flags,
  1808. u16 token,
  1809. const struct dpni_rule_cfg *cfg)
  1810. {
  1811. struct dpni_cmd_remove_qos_entry *cmd_params;
  1812. struct fsl_mc_command cmd = { 0 };
  1813. /* prepare command */
  1814. cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
  1815. cmd_flags,
  1816. token);
  1817. cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
  1818. cmd_params->key_size = cfg->key_size;
  1819. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1820. cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
  1821. /* send command to mc*/
  1822. return mc_send_command(mc_io, &cmd);
  1823. }
  1824. /**
  1825. * dpni_clear_qos_table() - Clear all QoS mapping entries
  1826. * @mc_io: Pointer to MC portal's I/O object
  1827. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1828. * @token: Token of DPNI object
  1829. *
  1830. * Following this function call, all frames are directed to
  1831. * the default traffic class (0)
  1832. *
  1833. * Return: '0' on Success; Error code otherwise.
  1834. */
  1835. int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
  1836. u32 cmd_flags,
  1837. u16 token)
  1838. {
  1839. struct fsl_mc_command cmd = { 0 };
  1840. /* prepare command */
  1841. cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
  1842. cmd_flags,
  1843. token);
  1844. /* send command to mc*/
  1845. return mc_send_command(mc_io, &cmd);
  1846. }
  1847. /**
  1848. * dpni_set_tx_shaping() - Set the transmit shaping
  1849. * @mc_io: Pointer to MC portal's I/O object
  1850. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1851. * @token: Token of DPNI object
  1852. * @tx_cr_shaper: TX committed rate shaping configuration
  1853. * @tx_er_shaper: TX excess rate shaping configuration
  1854. * @coupled: Committed and excess rate shapers are coupled
  1855. *
  1856. * Return: '0' on Success; Error code otherwise.
  1857. */
  1858. int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
  1859. u32 cmd_flags,
  1860. u16 token,
  1861. const struct dpni_tx_shaping_cfg *tx_cr_shaper,
  1862. const struct dpni_tx_shaping_cfg *tx_er_shaper,
  1863. int coupled)
  1864. {
  1865. struct dpni_cmd_set_tx_shaping *cmd_params;
  1866. struct fsl_mc_command cmd = { 0 };
  1867. /* prepare command */
  1868. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
  1869. cmd_flags,
  1870. token);
  1871. cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
  1872. cmd_params->tx_cr_max_burst_size = cpu_to_le16(tx_cr_shaper->max_burst_size);
  1873. cmd_params->tx_er_max_burst_size = cpu_to_le16(tx_er_shaper->max_burst_size);
  1874. cmd_params->tx_cr_rate_limit = cpu_to_le32(tx_cr_shaper->rate_limit);
  1875. cmd_params->tx_er_rate_limit = cpu_to_le32(tx_er_shaper->rate_limit);
  1876. dpni_set_field(cmd_params->coupled, COUPLED, coupled);
  1877. /* send command to mc*/
  1878. return mc_send_command(mc_io, &cmd);
  1879. }
  1880. /**
  1881. * dpni_get_single_step_cfg() - return current configuration for
  1882. * single step PTP
  1883. * @mc_io: Pointer to MC portal's I/O object
  1884. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1885. * @token: Token of DPNI object
  1886. * @ptp_cfg: ptp single step configuration
  1887. *
  1888. * Return: '0' on Success; Error code otherwise.
  1889. *
  1890. */
  1891. int dpni_get_single_step_cfg(struct fsl_mc_io *mc_io,
  1892. u32 cmd_flags,
  1893. u16 token,
  1894. struct dpni_single_step_cfg *ptp_cfg)
  1895. {
  1896. struct dpni_rsp_single_step_cfg *rsp_params;
  1897. struct fsl_mc_command cmd = { 0 };
  1898. int err;
  1899. /* prepare command */
  1900. cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SINGLE_STEP_CFG,
  1901. cmd_flags, token);
  1902. /* send command to mc*/
  1903. err = mc_send_command(mc_io, &cmd);
  1904. if (err)
  1905. return err;
  1906. /* read command response */
  1907. rsp_params = (struct dpni_rsp_single_step_cfg *)cmd.params;
  1908. ptp_cfg->offset = le16_to_cpu(rsp_params->offset);
  1909. ptp_cfg->en = dpni_get_field(le16_to_cpu(rsp_params->flags),
  1910. PTP_ENABLE) ? 1 : 0;
  1911. ptp_cfg->ch_update = dpni_get_field(le16_to_cpu(rsp_params->flags),
  1912. PTP_CH_UPDATE) ? 1 : 0;
  1913. ptp_cfg->peer_delay = le32_to_cpu(rsp_params->peer_delay);
  1914. ptp_cfg->ptp_onestep_reg_base =
  1915. le32_to_cpu(rsp_params->ptp_onestep_reg_base);
  1916. return err;
  1917. }
  1918. /**
  1919. * dpni_set_single_step_cfg() - enable/disable and configure single step PTP
  1920. * @mc_io: Pointer to MC portal's I/O object
  1921. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1922. * @token: Token of DPNI object
  1923. * @ptp_cfg: ptp single step configuration
  1924. *
  1925. * Return: '0' on Success; Error code otherwise.
  1926. *
  1927. * The function has effect only when dpni object is connected to a dpmac
  1928. * object. If the dpni is not connected to a dpmac the configuration will
  1929. * be stored inside and applied when connection is made.
  1930. */
  1931. int dpni_set_single_step_cfg(struct fsl_mc_io *mc_io,
  1932. u32 cmd_flags,
  1933. u16 token,
  1934. struct dpni_single_step_cfg *ptp_cfg)
  1935. {
  1936. struct dpni_cmd_single_step_cfg *cmd_params;
  1937. struct fsl_mc_command cmd = { 0 };
  1938. u16 flags;
  1939. /* prepare command */
  1940. cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_SINGLE_STEP_CFG,
  1941. cmd_flags, token);
  1942. cmd_params = (struct dpni_cmd_single_step_cfg *)cmd.params;
  1943. cmd_params->offset = cpu_to_le16(ptp_cfg->offset);
  1944. cmd_params->peer_delay = cpu_to_le32(ptp_cfg->peer_delay);
  1945. flags = le16_to_cpu(cmd_params->flags);
  1946. dpni_set_field(flags, PTP_ENABLE, !!ptp_cfg->en);
  1947. dpni_set_field(flags, PTP_CH_UPDATE, !!ptp_cfg->ch_update);
  1948. cmd_params->flags = cpu_to_le16(flags);
  1949. /* send command to mc*/
  1950. return mc_send_command(mc_io, &cmd);
  1951. }