dpio.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright 2013-2016 Freescale Semiconductor Inc.
  4. * Copyright 2016 NXP
  5. *
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/fsl/mc.h>
  9. #include "dpio.h"
  10. #include "dpio-cmd.h"
  11. /*
  12. * Data Path I/O Portal API
  13. * Contains initialization APIs and runtime control APIs for DPIO
  14. */
  15. /**
  16. * dpio_open() - Open a control session for the specified object
  17. * @mc_io: Pointer to MC portal's I/O object
  18. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  19. * @dpio_id: DPIO unique ID
  20. * @token: Returned token; use in subsequent API calls
  21. *
  22. * This function can be used to open a control session for an
  23. * already created object; an object may have been declared in
  24. * the DPL or by calling the dpio_create() function.
  25. * This function returns a unique authentication token,
  26. * associated with the specific object ID and the specific MC
  27. * portal; this token must be used in all subsequent commands for
  28. * this specific object.
  29. *
  30. * Return: '0' on Success; Error code otherwise.
  31. */
  32. int dpio_open(struct fsl_mc_io *mc_io,
  33. u32 cmd_flags,
  34. int dpio_id,
  35. u16 *token)
  36. {
  37. struct fsl_mc_command cmd = { 0 };
  38. struct dpio_cmd_open *dpio_cmd;
  39. int err;
  40. /* prepare command */
  41. cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
  42. cmd_flags,
  43. 0);
  44. dpio_cmd = (struct dpio_cmd_open *)cmd.params;
  45. dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
  46. err = mc_send_command(mc_io, &cmd);
  47. if (err)
  48. return err;
  49. /* retrieve response parameters */
  50. *token = mc_cmd_hdr_read_token(&cmd);
  51. return 0;
  52. }
  53. /**
  54. * dpio_close() - Close the control session of the object
  55. * @mc_io: Pointer to MC portal's I/O object
  56. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  57. * @token: Token of DPIO object
  58. *
  59. * Return: '0' on Success; Error code otherwise.
  60. */
  61. int dpio_close(struct fsl_mc_io *mc_io,
  62. u32 cmd_flags,
  63. u16 token)
  64. {
  65. struct fsl_mc_command cmd = { 0 };
  66. /* prepare command */
  67. cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
  68. cmd_flags,
  69. token);
  70. return mc_send_command(mc_io, &cmd);
  71. }
  72. /**
  73. * dpio_enable() - Enable the DPIO, allow I/O portal operations.
  74. * @mc_io: Pointer to MC portal's I/O object
  75. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  76. * @token: Token of DPIO object
  77. *
  78. * Return: '0' on Success; Error code otherwise
  79. */
  80. int dpio_enable(struct fsl_mc_io *mc_io,
  81. u32 cmd_flags,
  82. u16 token)
  83. {
  84. struct fsl_mc_command cmd = { 0 };
  85. /* prepare command */
  86. cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
  87. cmd_flags,
  88. token);
  89. return mc_send_command(mc_io, &cmd);
  90. }
  91. /**
  92. * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
  93. * @mc_io: Pointer to MC portal's I/O object
  94. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  95. * @token: Token of DPIO object
  96. *
  97. * Return: '0' on Success; Error code otherwise
  98. */
  99. int dpio_disable(struct fsl_mc_io *mc_io,
  100. u32 cmd_flags,
  101. u16 token)
  102. {
  103. struct fsl_mc_command cmd = { 0 };
  104. /* prepare command */
  105. cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
  106. cmd_flags,
  107. token);
  108. return mc_send_command(mc_io, &cmd);
  109. }
  110. /**
  111. * dpio_get_attributes() - Retrieve DPIO attributes
  112. * @mc_io: Pointer to MC portal's I/O object
  113. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  114. * @token: Token of DPIO object
  115. * @attr: Returned object's attributes
  116. *
  117. * Return: '0' on Success; Error code otherwise
  118. */
  119. int dpio_get_attributes(struct fsl_mc_io *mc_io,
  120. u32 cmd_flags,
  121. u16 token,
  122. struct dpio_attr *attr)
  123. {
  124. struct fsl_mc_command cmd = { 0 };
  125. struct dpio_rsp_get_attr *dpio_rsp;
  126. int err;
  127. /* prepare command */
  128. cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
  129. cmd_flags,
  130. token);
  131. err = mc_send_command(mc_io, &cmd);
  132. if (err)
  133. return err;
  134. /* retrieve response parameters */
  135. dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
  136. attr->id = le32_to_cpu(dpio_rsp->id);
  137. attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
  138. attr->num_priorities = dpio_rsp->num_priorities;
  139. attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
  140. attr->qbman_portal_ce_offset =
  141. le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
  142. attr->qbman_portal_ci_offset =
  143. le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
  144. attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
  145. return 0;
  146. }
  147. int dpio_set_stashing_destination(struct fsl_mc_io *mc_io,
  148. u32 cmd_flags,
  149. u16 token,
  150. u8 sdest)
  151. {
  152. struct fsl_mc_command cmd = { 0 };
  153. struct dpio_stashing_dest *dpio_cmd;
  154. cmd.header = mc_encode_cmd_header(DPIO_CMDID_SET_STASHING_DEST,
  155. cmd_flags, token);
  156. dpio_cmd = (struct dpio_stashing_dest *)cmd.params;
  157. dpio_cmd->sdest = sdest;
  158. return mc_send_command(mc_io, &cmd);
  159. }
  160. /**
  161. * dpio_get_api_version - Get Data Path I/O API version
  162. * @mc_io: Pointer to MC portal's DPIO object
  163. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  164. * @major_ver: Major version of DPIO API
  165. * @minor_ver: Minor version of DPIO API
  166. *
  167. * Return: '0' on Success; Error code otherwise
  168. */
  169. int dpio_get_api_version(struct fsl_mc_io *mc_io,
  170. u32 cmd_flags,
  171. u16 *major_ver,
  172. u16 *minor_ver)
  173. {
  174. struct fsl_mc_command cmd = { 0 };
  175. int err;
  176. /* prepare command */
  177. cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
  178. cmd_flags, 0);
  179. err = mc_send_command(mc_io, &cmd);
  180. if (err)
  181. return err;
  182. /* retrieve response parameters */
  183. mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  184. return 0;
  185. }
  186. /**
  187. * dpio_reset() - Reset the DPIO, returns the object to initial state.
  188. * @mc_io: Pointer to MC portal's I/O object
  189. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  190. * @token: Token of DPIO object
  191. *
  192. * Return: '0' on Success; Error code otherwise.
  193. */
  194. int dpio_reset(struct fsl_mc_io *mc_io,
  195. u32 cmd_flags,
  196. u16 token)
  197. {
  198. struct fsl_mc_command cmd = { 0 };
  199. /* prepare command */
  200. cmd.header = mc_encode_cmd_header(DPIO_CMDID_RESET,
  201. cmd_flags,
  202. token);
  203. /* send command to mc*/
  204. return mc_send_command(mc_io, &cmd);
  205. }