dpcon.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright 2013-2016 Freescale Semiconductor Inc.
  4. *
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/fsl/mc.h>
  8. #include "fsl-mc-private.h"
  9. /**
  10. * dpcon_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. * @dpcon_id: DPCON 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
  17. * already created object; an object may have been declared in
  18. * the DPL or by calling the dpcon_create() function.
  19. * This function returns a unique authentication token,
  20. * associated with the specific object ID and the specific MC
  21. * portal; this token must be used in all subsequent commands for
  22. * this specific object.
  23. *
  24. * Return: '0' on Success; Error code otherwise.
  25. */
  26. int dpcon_open(struct fsl_mc_io *mc_io,
  27. u32 cmd_flags,
  28. int dpcon_id,
  29. u16 *token)
  30. {
  31. struct fsl_mc_command cmd = { 0 };
  32. struct dpcon_cmd_open *dpcon_cmd;
  33. int err;
  34. /* prepare command */
  35. cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
  36. cmd_flags,
  37. 0);
  38. dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
  39. dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
  40. /* send command to mc*/
  41. err = mc_send_command(mc_io, &cmd);
  42. if (err)
  43. return err;
  44. /* retrieve response parameters */
  45. *token = mc_cmd_hdr_read_token(&cmd);
  46. return 0;
  47. }
  48. EXPORT_SYMBOL_GPL(dpcon_open);
  49. /**
  50. * dpcon_close() - Close the control session of the object
  51. * @mc_io: Pointer to MC portal's I/O object
  52. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  53. * @token: Token of DPCON object
  54. *
  55. * After this function is called, no further operations are
  56. * allowed on the object without opening a new control session.
  57. *
  58. * Return: '0' on Success; Error code otherwise.
  59. */
  60. int dpcon_close(struct fsl_mc_io *mc_io,
  61. u32 cmd_flags,
  62. u16 token)
  63. {
  64. struct fsl_mc_command cmd = { 0 };
  65. /* prepare command */
  66. cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
  67. cmd_flags,
  68. token);
  69. /* send command to mc*/
  70. return mc_send_command(mc_io, &cmd);
  71. }
  72. EXPORT_SYMBOL_GPL(dpcon_close);
  73. /**
  74. * dpcon_enable() - Enable the DPCON
  75. * @mc_io: Pointer to MC portal's I/O object
  76. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  77. * @token: Token of DPCON object
  78. *
  79. * Return: '0' on Success; Error code otherwise
  80. */
  81. int dpcon_enable(struct fsl_mc_io *mc_io,
  82. u32 cmd_flags,
  83. u16 token)
  84. {
  85. struct fsl_mc_command cmd = { 0 };
  86. /* prepare command */
  87. cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
  88. cmd_flags,
  89. token);
  90. /* send command to mc*/
  91. return mc_send_command(mc_io, &cmd);
  92. }
  93. EXPORT_SYMBOL_GPL(dpcon_enable);
  94. /**
  95. * dpcon_disable() - Disable the DPCON
  96. * @mc_io: Pointer to MC portal's I/O object
  97. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  98. * @token: Token of DPCON object
  99. *
  100. * Return: '0' on Success; Error code otherwise
  101. */
  102. int dpcon_disable(struct fsl_mc_io *mc_io,
  103. u32 cmd_flags,
  104. u16 token)
  105. {
  106. struct fsl_mc_command cmd = { 0 };
  107. /* prepare command */
  108. cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
  109. cmd_flags,
  110. token);
  111. /* send command to mc*/
  112. return mc_send_command(mc_io, &cmd);
  113. }
  114. EXPORT_SYMBOL_GPL(dpcon_disable);
  115. /**
  116. * dpcon_reset() - Reset the DPCON, returns the object to initial state.
  117. * @mc_io: Pointer to MC portal's I/O object
  118. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  119. * @token: Token of DPCON object
  120. *
  121. * Return: '0' on Success; Error code otherwise.
  122. */
  123. int dpcon_reset(struct fsl_mc_io *mc_io,
  124. u32 cmd_flags,
  125. u16 token)
  126. {
  127. struct fsl_mc_command cmd = { 0 };
  128. /* prepare command */
  129. cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
  130. cmd_flags, token);
  131. /* send command to mc*/
  132. return mc_send_command(mc_io, &cmd);
  133. }
  134. EXPORT_SYMBOL_GPL(dpcon_reset);
  135. /**
  136. * dpcon_get_attributes() - Retrieve DPCON attributes.
  137. * @mc_io: Pointer to MC portal's I/O object
  138. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  139. * @token: Token of DPCON object
  140. * @attr: Object's attributes
  141. *
  142. * Return: '0' on Success; Error code otherwise.
  143. */
  144. int dpcon_get_attributes(struct fsl_mc_io *mc_io,
  145. u32 cmd_flags,
  146. u16 token,
  147. struct dpcon_attr *attr)
  148. {
  149. struct fsl_mc_command cmd = { 0 };
  150. struct dpcon_rsp_get_attr *dpcon_rsp;
  151. int err;
  152. /* prepare command */
  153. cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
  154. cmd_flags,
  155. token);
  156. /* send command to mc*/
  157. err = mc_send_command(mc_io, &cmd);
  158. if (err)
  159. return err;
  160. /* retrieve response parameters */
  161. dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
  162. attr->id = le32_to_cpu(dpcon_rsp->id);
  163. attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
  164. attr->num_priorities = dpcon_rsp->num_priorities;
  165. return 0;
  166. }
  167. EXPORT_SYMBOL_GPL(dpcon_get_attributes);
  168. /**
  169. * dpcon_set_notification() - Set DPCON notification destination
  170. * @mc_io: Pointer to MC portal's I/O object
  171. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  172. * @token: Token of DPCON object
  173. * @cfg: Notification parameters
  174. *
  175. * Return: '0' on Success; Error code otherwise
  176. */
  177. int dpcon_set_notification(struct fsl_mc_io *mc_io,
  178. u32 cmd_flags,
  179. u16 token,
  180. struct dpcon_notification_cfg *cfg)
  181. {
  182. struct fsl_mc_command cmd = { 0 };
  183. struct dpcon_cmd_set_notification *dpcon_cmd;
  184. /* prepare command */
  185. cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
  186. cmd_flags,
  187. token);
  188. dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
  189. dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
  190. dpcon_cmd->priority = cfg->priority;
  191. dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
  192. /* send command to mc*/
  193. return mc_send_command(mc_io, &cmd);
  194. }
  195. EXPORT_SYMBOL_GPL(dpcon_set_notification);