dpbp.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. * dpbp_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. * @dpbp_id: DPBP 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 dpbp_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 dpbp_open(struct fsl_mc_io *mc_io,
  27. u32 cmd_flags,
  28. int dpbp_id,
  29. u16 *token)
  30. {
  31. struct fsl_mc_command cmd = { 0 };
  32. struct dpbp_cmd_open *cmd_params;
  33. int err;
  34. /* prepare command */
  35. cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
  36. cmd_flags, 0);
  37. cmd_params = (struct dpbp_cmd_open *)cmd.params;
  38. cmd_params->dpbp_id = cpu_to_le32(dpbp_id);
  39. /* send command to mc*/
  40. err = mc_send_command(mc_io, &cmd);
  41. if (err)
  42. return err;
  43. /* retrieve response parameters */
  44. *token = mc_cmd_hdr_read_token(&cmd);
  45. return err;
  46. }
  47. EXPORT_SYMBOL_GPL(dpbp_open);
  48. /**
  49. * dpbp_close() - Close the control session of the object
  50. * @mc_io: Pointer to MC portal's I/O object
  51. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  52. * @token: Token of DPBP object
  53. *
  54. * After this function is called, no further operations are
  55. * allowed on the object without opening a new control session.
  56. *
  57. * Return: '0' on Success; Error code otherwise.
  58. */
  59. int dpbp_close(struct fsl_mc_io *mc_io,
  60. u32 cmd_flags,
  61. u16 token)
  62. {
  63. struct fsl_mc_command cmd = { 0 };
  64. /* prepare command */
  65. cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
  66. token);
  67. /* send command to mc*/
  68. return mc_send_command(mc_io, &cmd);
  69. }
  70. EXPORT_SYMBOL_GPL(dpbp_close);
  71. /**
  72. * dpbp_enable() - Enable the DPBP.
  73. * @mc_io: Pointer to MC portal's I/O object
  74. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  75. * @token: Token of DPBP object
  76. *
  77. * Return: '0' on Success; Error code otherwise.
  78. */
  79. int dpbp_enable(struct fsl_mc_io *mc_io,
  80. u32 cmd_flags,
  81. u16 token)
  82. {
  83. struct fsl_mc_command cmd = { 0 };
  84. /* prepare command */
  85. cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
  86. token);
  87. /* send command to mc*/
  88. return mc_send_command(mc_io, &cmd);
  89. }
  90. EXPORT_SYMBOL_GPL(dpbp_enable);
  91. /**
  92. * dpbp_disable() - Disable the DPBP.
  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 DPBP object
  96. *
  97. * Return: '0' on Success; Error code otherwise.
  98. */
  99. int dpbp_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(DPBP_CMDID_DISABLE,
  106. cmd_flags, token);
  107. /* send command to mc*/
  108. return mc_send_command(mc_io, &cmd);
  109. }
  110. EXPORT_SYMBOL_GPL(dpbp_disable);
  111. /**
  112. * dpbp_reset() - Reset the DPBP, returns the object to initial state.
  113. * @mc_io: Pointer to MC portal's I/O object
  114. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  115. * @token: Token of DPBP object
  116. *
  117. * Return: '0' on Success; Error code otherwise.
  118. */
  119. int dpbp_reset(struct fsl_mc_io *mc_io,
  120. u32 cmd_flags,
  121. u16 token)
  122. {
  123. struct fsl_mc_command cmd = { 0 };
  124. /* prepare command */
  125. cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
  126. cmd_flags, token);
  127. /* send command to mc*/
  128. return mc_send_command(mc_io, &cmd);
  129. }
  130. EXPORT_SYMBOL_GPL(dpbp_reset);
  131. /**
  132. * dpbp_get_attributes - Retrieve DPBP attributes.
  133. *
  134. * @mc_io: Pointer to MC portal's I/O object
  135. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  136. * @token: Token of DPBP object
  137. * @attr: Returned object's attributes
  138. *
  139. * Return: '0' on Success; Error code otherwise.
  140. */
  141. int dpbp_get_attributes(struct fsl_mc_io *mc_io,
  142. u32 cmd_flags,
  143. u16 token,
  144. struct dpbp_attr *attr)
  145. {
  146. struct fsl_mc_command cmd = { 0 };
  147. struct dpbp_rsp_get_attributes *rsp_params;
  148. int err;
  149. /* prepare command */
  150. cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
  151. cmd_flags, token);
  152. /* send command to mc*/
  153. err = mc_send_command(mc_io, &cmd);
  154. if (err)
  155. return err;
  156. /* retrieve response parameters */
  157. rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
  158. attr->bpid = le16_to_cpu(rsp_params->bpid);
  159. attr->id = le32_to_cpu(rsp_params->id);
  160. return 0;
  161. }
  162. EXPORT_SYMBOL_GPL(dpbp_get_attributes);