dpseci.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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_is_enabled() - Check if the DPSECI is enabled.
  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. * @en: Returns '1' if object is enabled; '0' otherwise
  99. *
  100. * Return: '0' on success, error code otherwise
  101. */
  102. int dpseci_is_enabled(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  103. int *en)
  104. {
  105. struct fsl_mc_command cmd = { 0 };
  106. struct dpseci_rsp_is_enabled *rsp_params;
  107. int err;
  108. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
  109. cmd_flags,
  110. token);
  111. err = mc_send_command(mc_io, &cmd);
  112. if (err)
  113. return err;
  114. rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
  115. *en = dpseci_get_field(rsp_params->is_enabled, ENABLE);
  116. return 0;
  117. }
  118. /**
  119. * dpseci_get_attributes() - Retrieve DPSECI attributes
  120. * @mc_io: Pointer to MC portal's I/O object
  121. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  122. * @token: Token of DPSECI object
  123. * @attr: Returned object's attributes
  124. *
  125. * Return: '0' on success, error code otherwise
  126. */
  127. int dpseci_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  128. struct dpseci_attr *attr)
  129. {
  130. struct fsl_mc_command cmd = { 0 };
  131. struct dpseci_rsp_get_attributes *rsp_params;
  132. int err;
  133. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
  134. cmd_flags,
  135. token);
  136. err = mc_send_command(mc_io, &cmd);
  137. if (err)
  138. return err;
  139. rsp_params = (struct dpseci_rsp_get_attributes *)cmd.params;
  140. attr->id = le32_to_cpu(rsp_params->id);
  141. attr->num_tx_queues = rsp_params->num_tx_queues;
  142. attr->num_rx_queues = rsp_params->num_rx_queues;
  143. attr->options = le32_to_cpu(rsp_params->options);
  144. return 0;
  145. }
  146. /**
  147. * dpseci_set_rx_queue() - Set Rx queue configuration
  148. * @mc_io: Pointer to MC portal's I/O object
  149. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  150. * @token: Token of DPSECI object
  151. * @queue: Select the queue relative to number of priorities configured at
  152. * DPSECI creation; use DPSECI_ALL_QUEUES to configure all
  153. * Rx queues identically.
  154. * @cfg: Rx queue configuration
  155. *
  156. * Return: '0' on success, error code otherwise
  157. */
  158. int dpseci_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  159. u8 queue, const struct dpseci_rx_queue_cfg *cfg)
  160. {
  161. struct fsl_mc_command cmd = { 0 };
  162. struct dpseci_cmd_queue *cmd_params;
  163. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
  164. cmd_flags,
  165. token);
  166. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  167. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  168. cmd_params->priority = cfg->dest_cfg.priority;
  169. cmd_params->queue = queue;
  170. dpseci_set_field(cmd_params->dest_type, DEST_TYPE,
  171. cfg->dest_cfg.dest_type);
  172. cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
  173. cmd_params->options = cpu_to_le32(cfg->options);
  174. dpseci_set_field(cmd_params->order_preservation_en, ORDER_PRESERVATION,
  175. cfg->order_preservation_en);
  176. return mc_send_command(mc_io, &cmd);
  177. }
  178. /**
  179. * dpseci_get_rx_queue() - Retrieve Rx queue attributes
  180. * @mc_io: Pointer to MC portal's I/O object
  181. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  182. * @token: Token of DPSECI object
  183. * @queue: Select the queue relative to number of priorities configured at
  184. * DPSECI creation
  185. * @attr: Returned Rx queue attributes
  186. *
  187. * Return: '0' on success, error code otherwise
  188. */
  189. int dpseci_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  190. u8 queue, struct dpseci_rx_queue_attr *attr)
  191. {
  192. struct fsl_mc_command cmd = { 0 };
  193. struct dpseci_cmd_queue *cmd_params;
  194. int err;
  195. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
  196. cmd_flags,
  197. token);
  198. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  199. cmd_params->queue = queue;
  200. err = mc_send_command(mc_io, &cmd);
  201. if (err)
  202. return err;
  203. attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
  204. attr->dest_cfg.priority = cmd_params->priority;
  205. attr->dest_cfg.dest_type = dpseci_get_field(cmd_params->dest_type,
  206. DEST_TYPE);
  207. attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
  208. attr->fqid = le32_to_cpu(cmd_params->fqid);
  209. attr->order_preservation_en =
  210. dpseci_get_field(cmd_params->order_preservation_en,
  211. ORDER_PRESERVATION);
  212. return 0;
  213. }
  214. /**
  215. * dpseci_get_tx_queue() - Retrieve Tx queue attributes
  216. * @mc_io: Pointer to MC portal's I/O object
  217. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  218. * @token: Token of DPSECI object
  219. * @queue: Select the queue relative to number of priorities configured at
  220. * DPSECI creation
  221. * @attr: Returned Tx queue attributes
  222. *
  223. * Return: '0' on success, error code otherwise
  224. */
  225. int dpseci_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  226. u8 queue, struct dpseci_tx_queue_attr *attr)
  227. {
  228. struct fsl_mc_command cmd = { 0 };
  229. struct dpseci_cmd_queue *cmd_params;
  230. struct dpseci_rsp_get_tx_queue *rsp_params;
  231. int err;
  232. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
  233. cmd_flags,
  234. token);
  235. cmd_params = (struct dpseci_cmd_queue *)cmd.params;
  236. cmd_params->queue = queue;
  237. err = mc_send_command(mc_io, &cmd);
  238. if (err)
  239. return err;
  240. rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
  241. attr->fqid = le32_to_cpu(rsp_params->fqid);
  242. attr->priority = rsp_params->priority;
  243. return 0;
  244. }
  245. /**
  246. * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes
  247. * @mc_io: Pointer to MC portal's I/O object
  248. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  249. * @token: Token of DPSECI object
  250. * @attr: Returned SEC attributes
  251. *
  252. * Return: '0' on success, error code otherwise
  253. */
  254. int dpseci_get_sec_attr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  255. struct dpseci_sec_attr *attr)
  256. {
  257. struct fsl_mc_command cmd = { 0 };
  258. struct dpseci_rsp_get_sec_attr *rsp_params;
  259. int err;
  260. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
  261. cmd_flags,
  262. token);
  263. err = mc_send_command(mc_io, &cmd);
  264. if (err)
  265. return err;
  266. rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
  267. attr->ip_id = le16_to_cpu(rsp_params->ip_id);
  268. attr->major_rev = rsp_params->major_rev;
  269. attr->minor_rev = rsp_params->minor_rev;
  270. attr->era = rsp_params->era;
  271. attr->deco_num = rsp_params->deco_num;
  272. attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
  273. attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
  274. attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
  275. attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
  276. attr->crc_acc_num = rsp_params->crc_acc_num;
  277. attr->pk_acc_num = rsp_params->pk_acc_num;
  278. attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
  279. attr->rng_acc_num = rsp_params->rng_acc_num;
  280. attr->md_acc_num = rsp_params->md_acc_num;
  281. attr->arc4_acc_num = rsp_params->arc4_acc_num;
  282. attr->des_acc_num = rsp_params->des_acc_num;
  283. attr->aes_acc_num = rsp_params->aes_acc_num;
  284. attr->ccha_acc_num = rsp_params->ccha_acc_num;
  285. attr->ptha_acc_num = rsp_params->ptha_acc_num;
  286. return 0;
  287. }
  288. /**
  289. * dpseci_get_api_version() - Get Data Path SEC Interface API version
  290. * @mc_io: Pointer to MC portal's I/O object
  291. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  292. * @major_ver: Major version of data path sec API
  293. * @minor_ver: Minor version of data path sec API
  294. *
  295. * Return: '0' on success, error code otherwise
  296. */
  297. int dpseci_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
  298. u16 *major_ver, u16 *minor_ver)
  299. {
  300. struct fsl_mc_command cmd = { 0 };
  301. struct dpseci_rsp_get_api_version *rsp_params;
  302. int err;
  303. cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
  304. cmd_flags, 0);
  305. err = mc_send_command(mc_io, &cmd);
  306. if (err)
  307. return err;
  308. rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
  309. *major_ver = le16_to_cpu(rsp_params->major);
  310. *minor_ver = le16_to_cpu(rsp_params->minor);
  311. return 0;
  312. }
  313. /**
  314. * dpseci_set_congestion_notification() - Set congestion group
  315. * notification configuration
  316. * @mc_io: Pointer to MC portal's I/O object
  317. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  318. * @token: Token of DPSECI object
  319. * @cfg: congestion notification configuration
  320. *
  321. * Return: '0' on success, error code otherwise
  322. */
  323. int dpseci_set_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
  324. u16 token, const struct dpseci_congestion_notification_cfg *cfg)
  325. {
  326. struct fsl_mc_command cmd = { 0 };
  327. struct dpseci_cmd_congestion_notification *cmd_params;
  328. cmd.header = mc_encode_cmd_header(
  329. DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
  330. cmd_flags,
  331. token);
  332. cmd_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
  333. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  334. cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
  335. cmd_params->priority = cfg->dest_cfg.priority;
  336. dpseci_set_field(cmd_params->options, CGN_DEST_TYPE,
  337. cfg->dest_cfg.dest_type);
  338. dpseci_set_field(cmd_params->options, CGN_UNITS, cfg->units);
  339. cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
  340. cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
  341. cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
  342. cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
  343. return mc_send_command(mc_io, &cmd);
  344. }
  345. /**
  346. * dpseci_get_congestion_notification() - Get congestion group notification
  347. * configuration
  348. * @mc_io: Pointer to MC portal's I/O object
  349. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  350. * @token: Token of DPSECI object
  351. * @cfg: congestion notification configuration
  352. *
  353. * Return: '0' on success, error code otherwise
  354. */
  355. int dpseci_get_congestion_notification(struct fsl_mc_io *mc_io, u32 cmd_flags,
  356. u16 token, struct dpseci_congestion_notification_cfg *cfg)
  357. {
  358. struct fsl_mc_command cmd = { 0 };
  359. struct dpseci_cmd_congestion_notification *rsp_params;
  360. int err;
  361. cmd.header = mc_encode_cmd_header(
  362. DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
  363. cmd_flags,
  364. token);
  365. err = mc_send_command(mc_io, &cmd);
  366. if (err)
  367. return err;
  368. rsp_params = (struct dpseci_cmd_congestion_notification *)cmd.params;
  369. cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
  370. cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
  371. cfg->dest_cfg.priority = rsp_params->priority;
  372. cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->options,
  373. CGN_DEST_TYPE);
  374. cfg->units = dpseci_get_field(rsp_params->options, CGN_UNITS);
  375. cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
  376. cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
  377. cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
  378. cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
  379. return 0;
  380. }