dpseci.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright 2013-2016 Freescale Semiconductor Inc.
  4. * Copyright 2017-2018 NXP
  5. */
  6. #include <linux/fsl/mc.h>
  7. #include "dpseci.h"
  8. #include "dpseci_cmd.h"
  9. /**
  10. * dpseci_open() - Open a control session for the specified object
  11. * @mc_io: Pointer to MC portal's I/O object
  12. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  13. * @dpseci_id: DPSECI unique ID
  14. * @token: Returned token; use in subsequent API calls
  15. *
  16. * This function can be used to open a control session for an already created
  17. * object; an object may have been declared statically in the DPL
  18. * or created dynamically.
  19. * This function returns a unique authentication token, associated with the
  20. * specific object ID and the specific MC portal; this token must be used in all
  21. * subsequent commands for this specific object.
  22. *
  23. * Return: '0' on success, error code otherwise
  24. */
  25. int dpseci_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpseci_id,
  26. u16 *token)
  27. {
  28. struct fsl_mc_command cmd = { 0 };
  29. struct dpseci_cmd_open *cmd_params;
  30. int err;
  31. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
  32. cmd_flags,
  33. 0);
  34. cmd_params = (struct dpseci_cmd_open *)cmd.params;
  35. cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
  36. err = mc_send_command(mc_io, &cmd);
  37. if (err)
  38. return err;
  39. *token = mc_cmd_hdr_read_token(&cmd);
  40. return 0;
  41. }
  42. /**
  43. * dpseci_close() - Close the control session of the object
  44. * @mc_io: Pointer to MC portal's I/O object
  45. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  46. * @token: Token of DPSECI object
  47. *
  48. * After this function is called, no further operations are allowed on the
  49. * object without opening a new control session.
  50. *
  51. * Return: '0' on success, error code otherwise
  52. */
  53. int dpseci_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  54. {
  55. struct fsl_mc_command cmd = { 0 };
  56. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
  57. cmd_flags,
  58. token);
  59. return mc_send_command(mc_io, &cmd);
  60. }
  61. /**
  62. * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames
  63. * @mc_io: Pointer to MC portal's I/O object
  64. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  65. * @token: Token of DPSECI object
  66. *
  67. * Return: '0' on success, error code otherwise
  68. */
  69. int dpseci_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  70. {
  71. struct fsl_mc_command cmd = { 0 };
  72. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
  73. cmd_flags,
  74. token);
  75. return mc_send_command(mc_io, &cmd);
  76. }
  77. /**
  78. * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames
  79. * @mc_io: Pointer to MC portal's I/O object
  80. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  81. * @token: Token of DPSECI object
  82. *
  83. * Return: '0' on success, error code otherwise
  84. */
  85. int dpseci_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  86. {
  87. struct fsl_mc_command cmd = { 0 };
  88. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
  89. cmd_flags,
  90. token);
  91. return mc_send_command(mc_io, &cmd);
  92. }
  93. /**
  94. * dpseci_reset() - Reset the DPSECI, returns the object to initial state
  95. * @mc_io: Pointer to MC portal's I/O object
  96. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  97. * @token: Token of DPSECI object
  98. *
  99. * Return: '0' on success, error code otherwise
  100. */
  101. int dpseci_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  102. {
  103. struct fsl_mc_command cmd = { 0 };
  104. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
  105. cmd_flags,
  106. token);
  107. return mc_send_command(mc_io, &cmd);
  108. }
  109. /**
  110. * dpseci_is_enabled() - Check if the DPSECI is enabled.
  111. * @mc_io: Pointer to MC portal's I/O object
  112. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  113. * @token: Token of DPSECI object
  114. * @en: Returns '1' if object is enabled; '0' otherwise
  115. *
  116. * Return: '0' on success, error code otherwise
  117. */
  118. int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  119. int *en)
  120. {
  121. struct fsl_mc_command cmd = { 0 };
  122. struct dpseci_rsp_is_enabled *rsp_params;
  123. int err;
  124. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
  125. cmd_flags,
  126. token);
  127. err = mc_send_command(mc_io, &cmd);
  128. if (err)
  129. return err;
  130. rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
  131. *en = dpseci_get_field(rsp_params->is_enabled, ENABLE);
  132. return 0;
  133. }
  134. /**
  135. * dpseci_get_attributes() - Retrieve DPSECI attributes
  136. * @mc_io: Pointer to MC portal's I/O object
  137. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  138. * @token: Token of DPSECI object
  139. * @attr: Returned object's attributes
  140. *
  141. * Return: '0' on success, error code otherwise
  142. */
  143. int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  144. struct dpseci_attr *attr)
  145. {
  146. struct fsl_mc_command cmd = { 0 };
  147. struct dpseci_rsp_get_attributes *rsp_params;
  148. int err;
  149. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
  150. cmd_flags,
  151. token);
  152. err = mc_send_command(mc_io, &cmd);
  153. if (err)
  154. return err;
  155. rsp_params = (struct dpseci_rsp_get_attributes *)cmd.params;
  156. attr->id = le32_to_cpu(rsp_params->id);
  157. attr->num_tx_queues = rsp_params->num_tx_queues;
  158. attr->num_rx_queues = rsp_params->num_rx_queues;
  159. attr->options = le32_to_cpu(rsp_params->options);
  160. return 0;
  161. }
  162. /**
  163. * dpseci_set_rx_queue() - Set Rx queue configuration
  164. * @mc_io: Pointer to MC portal's I/O object
  165. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  166. * @token: Token of DPSECI object
  167. * @queue: Select the queue relative to number of priorities configured at
  168. * DPSECI creation; use DPSECI_ALL_QUEUES to configure all
  169. * Rx queues identically.
  170. * @cfg: Rx queue configuration
  171. *
  172. * Return: '0' on success, error code otherwise
  173. */
  174. int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  175. u8 queue, const struct dpseci_rx_queue_cfg *cfg)
  176. {
  177. struct fsl_mc_command cmd = { 0 };
  178. struct dpseci_cmd_queue *cmd_params;
  179. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
  180. cmd_flags,
  181. token);
  182. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  183. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  184. cmd_params->priority = cfg->dest_cfg.priority;
  185. cmd_params->queue = queue;
  186. dpseci_set_field(cmd_params->dest_type, DEST_TYPE,
  187. cfg->dest_cfg.dest_type);
  188. cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
  189. cmd_params->options = cpu_to_le32(cfg->options);
  190. dpseci_set_field(cmd_params->order_preservation_en, ORDER_PRESERVATION,
  191. cfg->order_preservation_en);
  192. return mc_send_command(mc_io, &cmd);
  193. }
  194. /**
  195. * dpseci_get_rx_queue() - Retrieve Rx queue attributes
  196. * @mc_io: Pointer to MC portal's I/O object
  197. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  198. * @token: Token of DPSECI object
  199. * @queue: Select the queue relative to number of priorities configured at
  200. * DPSECI creation
  201. * @attr: Returned Rx queue attributes
  202. *
  203. * Return: '0' on success, error code otherwise
  204. */
  205. int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  206. u8 queue, struct dpseci_rx_queue_attr *attr)
  207. {
  208. struct fsl_mc_command cmd = { 0 };
  209. struct dpseci_cmd_queue *cmd_params;
  210. int err;
  211. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
  212. cmd_flags,
  213. token);
  214. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  215. cmd_params->queue = queue;
  216. err = mc_send_command(mc_io, &cmd);
  217. if (err)
  218. return err;
  219. attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
  220. attr->dest_cfg.priority = cmd_params->priority;
  221. attr->dest_cfg.dest_type = dpseci_get_field(cmd_params->dest_type,
  222. DEST_TYPE);
  223. attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
  224. attr->fqid = le32_to_cpu(cmd_params->fqid);
  225. attr->order_preservation_en =
  226. dpseci_get_field(cmd_params->order_preservation_en,
  227. ORDER_PRESERVATION);
  228. return 0;
  229. }
  230. /**
  231. * dpseci_get_tx_queue() - Retrieve Tx queue attributes
  232. * @mc_io: Pointer to MC portal's I/O object
  233. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  234. * @token: Token of DPSECI object
  235. * @queue: Select the queue relative to number of priorities configured at
  236. * DPSECI creation
  237. * @attr: Returned Tx queue attributes
  238. *
  239. * Return: '0' on success, error code otherwise
  240. */
  241. int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  242. u8 queue, struct dpseci_tx_queue_attr *attr)
  243. {
  244. struct fsl_mc_command cmd = { 0 };
  245. struct dpseci_cmd_queue *cmd_params;
  246. struct dpseci_rsp_get_tx_queue *rsp_params;
  247. int err;
  248. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
  249. cmd_flags,
  250. token);
  251. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  252. cmd_params->queue = queue;
  253. err = mc_send_command(mc_io, &cmd);
  254. if (err)
  255. return err;
  256. rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
  257. attr->fqid = le32_to_cpu(rsp_params->fqid);
  258. attr->priority = rsp_params->priority;
  259. return 0;
  260. }
  261. /**
  262. * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
  263. * @mc_io: Pointer to MC portal's I/O object
  264. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  265. * @token: Token of DPSECI object
  266. * @attr: Returned SEC attributes
  267. *
  268. * Return: '0' on success, error code otherwise
  269. */
  270. int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  271. struct dpseci_sec_attr *attr)
  272. {
  273. struct fsl_mc_command cmd = { 0 };
  274. struct dpseci_rsp_get_sec_attr *rsp_params;
  275. int err;
  276. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
  277. cmd_flags,
  278. token);
  279. err = mc_send_command(mc_io, &cmd);
  280. if (err)
  281. return err;
  282. rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
  283. attr->ip_id = le16_to_cpu(rsp_params->ip_id);
  284. attr->major_rev = rsp_params->major_rev;
  285. attr->minor_rev = rsp_params->minor_rev;
  286. attr->era = rsp_params->era;
  287. attr->deco_num = rsp_params->deco_num;
  288. attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
  289. attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
  290. attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
  291. attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
  292. attr->crc_acc_num = rsp_params->crc_acc_num;
  293. attr->pk_acc_num = rsp_params->pk_acc_num;
  294. attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
  295. attr->rng_acc_num = rsp_params->rng_acc_num;
  296. attr->md_acc_num = rsp_params->md_acc_num;
  297. attr->arc4_acc_num = rsp_params->arc4_acc_num;
  298. attr->des_acc_num = rsp_params->des_acc_num;
  299. attr->aes_acc_num = rsp_params->aes_acc_num;
  300. attr->ccha_acc_num = rsp_params->ccha_acc_num;
  301. attr->ptha_acc_num = rsp_params->ptha_acc_num;
  302. return 0;
  303. }
  304. /**
  305. * dpseci_get_api_version() - Get Data Path SEC Interface API version
  306. * @mc_io: Pointer to MC portal's I/O object
  307. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  308. * @major_ver: Major version of data path sec API
  309. * @minor_ver: Minor version of data path sec API
  310. *
  311. * Return: '0' on success, error code otherwise
  312. */
  313. int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
  314. u16 *major_ver, u16 *minor_ver)
  315. {
  316. struct fsl_mc_command cmd = { 0 };
  317. struct dpseci_rsp_get_api_version *rsp_params;
  318. int err;
  319. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
  320. cmd_flags, 0);
  321. err = mc_send_command(mc_io, &cmd);
  322. if (err)
  323. return err;
  324. rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
  325. *major_ver = le16_to_cpu(rsp_params->major);
  326. *minor_ver = le16_to_cpu(rsp_params->minor);
  327. return 0;
  328. }
  329. /**
  330. * dpseci_set_congestion_notification() - Set congestion group
  331. * notification configuration
  332. * @mc_io: Pointer to MC portal's I/O object
  333. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  334. * @token: Token of DPSECI object
  335. * @cfg: congestion notification configuration
  336. *
  337. * Return: '0' on success, error code otherwise
  338. */
  339. int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
  340. u16 token, const struct dpseci_congestion_notification_cfg *cfg)
  341. {
  342. struct fsl_mc_command cmd = { 0 };
  343. struct dpseci_cmd_congestion_notification *cmd_params;
  344. cmd.header = mc_encode_cmd_header(
  345. DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
  346. cmd_flags,
  347. token);
  348. cmd_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
  349. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  350. cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
  351. cmd_params->priority = cfg->dest_cfg.priority;
  352. dpseci_set_field(cmd_params->options, CGN_DEST_TYPE,
  353. cfg->dest_cfg.dest_type);
  354. dpseci_set_field(cmd_params->options, CGN_UNITS, cfg->units);
  355. cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
  356. cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
  357. cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
  358. cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
  359. return mc_send_command(mc_io, &cmd);
  360. }
  361. /**
  362. * dpseci_get_congestion_notification() - Get congestion group notification
  363. * configuration
  364. * @mc_io: Pointer to MC portal's I/O object
  365. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  366. * @token: Token of DPSECI object
  367. * @cfg: congestion notification configuration
  368. *
  369. * Return: '0' on success, error code otherwise
  370. */
  371. int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
  372. u16 token, struct dpseci_congestion_notification_cfg *cfg)
  373. {
  374. struct fsl_mc_command cmd = { 0 };
  375. struct dpseci_cmd_congestion_notification *rsp_params;
  376. int err;
  377. cmd.header = mc_encode_cmd_header(
  378. DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
  379. cmd_flags,
  380. token);
  381. err = mc_send_command(mc_io, &cmd);
  382. if (err)
  383. return err;
  384. rsp_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
  385. cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
  386. cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
  387. cfg->dest_cfg.priority = rsp_params->priority;
  388. cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->options,
  389. CGN_DEST_TYPE);
  390. cfg->units = dpseci_get_field(rsp_params->options, CGN_UNITS);
  391. cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
  392. cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
  393. cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
  394. cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
  395. return 0;
  396. }