dpcon.c 5.7 KB

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