dpbp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. * dpbp_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. * @dpbp_id: DPBP 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 dpbp_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 dpbp_open(struct fsl_mc_io *mc_io,
  28. u32 cmd_flags,
  29. int dpbp_id,
  30. u16 *token)
  31. {
  32. struct fsl_mc_command cmd = { 0 };
  33. struct dpbp_cmd_open *cmd_params;
  34. int err;
  35. /* prepare command */
  36. cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
  37. cmd_flags, 0);
  38. cmd_params = (struct dpbp_cmd_open *)cmd.params;
  39. cmd_params->dpbp_id = cpu_to_le32(dpbp_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 err;
  47. }
  48. EXPORT_SYMBOL_GPL(dpbp_open);
  49. /**
  50. * dpbp_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 DPBP 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 dpbp_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(DPBP_CMDID_CLOSE, cmd_flags,
  67. token);
  68. /* send command to mc*/
  69. return mc_send_command(mc_io, &cmd);
  70. }
  71. EXPORT_SYMBOL_GPL(dpbp_close);
  72. /**
  73. * dpbp_enable() - Enable the DPBP.
  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 DPBP object
  77. *
  78. * Return: '0' on Success; Error code otherwise.
  79. */
  80. int dpbp_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(DPBP_CMDID_ENABLE, cmd_flags,
  87. token);
  88. /* send command to mc*/
  89. return mc_send_command(mc_io, &cmd);
  90. }
  91. EXPORT_SYMBOL_GPL(dpbp_enable);
  92. /**
  93. * dpbp_disable() - Disable the DPBP.
  94. * @mc_io: Pointer to MC portal's I/O object
  95. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  96. * @token: Token of DPBP object
  97. *
  98. * Return: '0' on Success; Error code otherwise.
  99. */
  100. int dpbp_disable(struct fsl_mc_io *mc_io,
  101. u32 cmd_flags,
  102. u16 token)
  103. {
  104. struct fsl_mc_command cmd = { 0 };
  105. /* prepare command */
  106. cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
  107. cmd_flags, token);
  108. /* send command to mc*/
  109. return mc_send_command(mc_io, &cmd);
  110. }
  111. EXPORT_SYMBOL_GPL(dpbp_disable);
  112. /**
  113. * dpbp_reset() - Reset the DPBP, returns the object to initial state.
  114. * @mc_io: Pointer to MC portal's I/O object
  115. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  116. * @token: Token of DPBP object
  117. *
  118. * Return: '0' on Success; Error code otherwise.
  119. */
  120. int dpbp_reset(struct fsl_mc_io *mc_io,
  121. u32 cmd_flags,
  122. u16 token)
  123. {
  124. struct fsl_mc_command cmd = { 0 };
  125. /* prepare command */
  126. cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
  127. cmd_flags, token);
  128. /* send command to mc*/
  129. return mc_send_command(mc_io, &cmd);
  130. }
  131. EXPORT_SYMBOL_GPL(dpbp_reset);
  132. /**
  133. * dpbp_get_attributes - Retrieve DPBP attributes.
  134. *
  135. * @mc_io: Pointer to MC portal's I/O object
  136. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  137. * @token: Token of DPBP object
  138. * @attr: Returned object's attributes
  139. *
  140. * Return: '0' on Success; Error code otherwise.
  141. */
  142. int dpbp_get_attributes(struct fsl_mc_io *mc_io,
  143. u32 cmd_flags,
  144. u16 token,
  145. struct dpbp_attr *attr)
  146. {
  147. struct fsl_mc_command cmd = { 0 };
  148. struct dpbp_rsp_get_attributes *rsp_params;
  149. int err;
  150. /* prepare command */
  151. cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
  152. cmd_flags, token);
  153. /* send command to mc*/
  154. err = mc_send_command(mc_io, &cmd);
  155. if (err)
  156. return err;
  157. /* retrieve response parameters */
  158. rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
  159. attr->bpid = le16_to_cpu(rsp_params->bpid);
  160. attr->id = le32_to_cpu(rsp_params->id);
  161. return 0;
  162. }
  163. EXPORT_SYMBOL_GPL(dpbp_get_attributes);