wlan_osif_request_manager.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef __WLAN_OSIF_REQUEST_MANAGER_H__
  20. #define __WLAN_OSIF_REQUEST_MANAGER_H__
  21. /**
  22. * DOC: WLAN OSIF REQUEST MANAGER
  23. *
  24. * Many operations within the wlan driver occur in an asynchronous
  25. * manner. Requests are received by OSIF via one of the kernel
  26. * interfaces (ioctl, nl80211, virtual file system, etc.). The
  27. * requests are translated to an internal format and are then passed
  28. * to lower layers, usually via SME, for processing. For requests
  29. * which require a response, that response comes up from the lower
  30. * layers in a separate thread of execution, ultimately resulting in a
  31. * call to a callback function that was provided by OSIF as part of the
  32. * initial request. So a mechanism is needed to synchronize the
  33. * request and response. This framework provides that mechanism.
  34. *
  35. * Once the framework has been initialized, the typical sequence of
  36. * events is as follows:
  37. *
  38. * Request Thread:
  39. * 1. Create a &struct osif_request_params which describes the request.
  40. * 2. Call osif_request_alloc() to allocate a &struct osif_request.
  41. * 3. Call osif_request_priv() to get a pointer to the private data.
  42. * 4. Place any information which must be shared with the Response
  43. * Callback in the private data area.
  44. * 5. Call osif_request_cookie() to get the unique cookie assigned
  45. * to the request.
  46. * 6. Call the underlying request handling API, passing the cookie
  47. * as the callback's private context.
  48. * 7. Call osif_request_wait_for_response() to wait for the response
  49. * (or for the request to time out).
  50. * 8. Use the return status to see if the request was successful. If
  51. * it was, retrieve any response information from the private
  52. * structure and prepare a response for userspace.
  53. * 9. Call osif_request_put() to relinquish access to the request.
  54. * 10. Return status to the caller.
  55. *
  56. * Response Callback:
  57. * 1. Call osif_request_get() with the provided cookie to see if the
  58. * request structure is still valid. If it returns %NULL then
  59. * return since this means the request thread has already timed
  60. * out.
  61. * 2. Call osif_request_priv() to get access to the private data area.
  62. * 3. Write response data into the private data area.
  63. * 4. Call osif_request_complete() to indicate that the response is
  64. * ready to be processed by the request thread.
  65. * 5. Call osif_request_put() to relinquish the callback function's
  66. * reference to the request.
  67. */
  68. /* this is opaque to clients */
  69. struct osif_request;
  70. /**
  71. * typedef osif_request_dealloc() - Private data deallocation function
  72. * @priv: pointer to request private date
  73. */
  74. typedef void (*osif_request_dealloc)(void *priv);
  75. /**
  76. * struct osif_request_params - OSIF request parameters
  77. * @priv_size: Size of the private data area required to pass
  78. * information between the request thread and the response callback.
  79. * @timeout_ms: The amount of time to wait for a response in milliseconds.
  80. * @dealloc: Function to be called when the request is destroyed to
  81. * deallocate any allocations made in the private area of the
  82. * request struct. Can be %NULL if no private allocations are
  83. * made.
  84. */
  85. struct osif_request_params {
  86. uint32_t priv_size;
  87. uint32_t timeout_ms;
  88. osif_request_dealloc dealloc;
  89. };
  90. /**
  91. * osif_request_alloc() - Allocate a request struct
  92. * @params: parameter block that specifies the attributes of the
  93. * request
  94. *
  95. * This function will attempt to allocate a &struct osif_request with
  96. * the specified @params. If successful, the caller can then use
  97. * request struct to make an asynchronous request. Once the request is
  98. * no longer needed, the reference should be relinquished via a call
  99. * to osif_request_put().
  100. *
  101. * Return: A pointer to an allocated &struct osif_request (which also
  102. * contains room for the private buffer) if the allocation is
  103. * successful, %NULL if the allocation fails.
  104. */
  105. struct osif_request *osif_request_alloc(const struct osif_request_params *params);
  106. /**
  107. * osif_request_priv() - Get pointer to request private data
  108. * @request: The request struct that contains the private data
  109. *
  110. * This function will return a pointer to the private data area that
  111. * is part of the request struct. The caller must already have a valid
  112. * reference to @request from either osif_request_alloc() or
  113. * osif_request_get().
  114. *
  115. * Returns: pointer to the private data area. Note that this pointer
  116. * will always be an offset from the input @request pointer and hence
  117. * this function will never return %NULL.
  118. */
  119. void *osif_request_priv(struct osif_request *request);
  120. /**
  121. * osif_request_cookie() - Get cookie of a request
  122. * @request: The request struct associated with the request
  123. *
  124. * This function will return the unique cookie that has been assigned
  125. * to the request. This cookie can subsequently be passed to
  126. * osif_request_get() to retrieve the request.
  127. *
  128. * Note that the cookie is defined as a void pointer as it is intended
  129. * to be passed as an opaque context pointer from OSIF to underlying
  130. * layers when making a request, and subsequently passed back to OSIF
  131. * as an opaque pointer in an asynchronous callback.
  132. *
  133. * Returns: The cookie assigned to the request.
  134. */
  135. void *osif_request_cookie(struct osif_request *request);
  136. /**
  137. * osif_request_get() - Get a reference to a request struct
  138. * @cookie: The cookie of the request struct that needs to be
  139. * referenced
  140. *
  141. * This function will use the cookie to determine if the associated
  142. * request struct is valid, and if so, will increment the reference
  143. * count of the struct. This means the caller is guaranteed that the
  144. * request struct is valid and the underlying private data can be
  145. * dereferenced.
  146. *
  147. * Returns: The pointer to the request struct associated with @cookie
  148. * if the request is still valid, %NULL if the underlying request
  149. * struct is no longer valid.
  150. */
  151. struct osif_request *osif_request_get(void *cookie);
  152. /**
  153. * osif_request_put() - Release a reference to a request struct
  154. * @request: The request struct that no longer needs to be referenced
  155. *
  156. * This function will decrement the reference count of the struct, and
  157. * will clean up the request if this is the last reference. The caller
  158. * must already have a valid reference to @request, either from
  159. * osif_request_alloc() or osif_request_get().
  160. *
  161. * Returns: Nothing
  162. */
  163. void osif_request_put(struct osif_request *request);
  164. /**
  165. * osif_request_wait_for_response() - Wait for a response
  166. * @request: The request struct associated with the request
  167. *
  168. * This function will wait until either a response is received and
  169. * communicated via osif_request_complete(), or until the request
  170. * timeout period expires.
  171. *
  172. * Returns: 0 if a response was received, -ETIMEDOUT if the response
  173. * timed out.
  174. */
  175. int osif_request_wait_for_response(struct osif_request *request);
  176. /**
  177. * osif_request_complete() - Complete a request
  178. * @request: The request struct associated with the request
  179. *
  180. * This function is used to indicate that a response has been received
  181. * and that any information required by the request thread has been
  182. * copied into the private data area of the request struct. This will
  183. * unblock any osif_request_wait_for_response() that is pending on this
  184. * @request.
  185. *
  186. * Returns: Nothing
  187. */
  188. void osif_request_complete(struct osif_request *request);
  189. /**
  190. * osif_request_manager_init() - Initialize the OSIF Request Manager
  191. *
  192. * This function must be called during system initialization to
  193. * initialize the OSIF Request Manager.
  194. *
  195. * Returns: Nothing
  196. */
  197. void osif_request_manager_init(void);
  198. /**
  199. * osif_request_manager_deinit() - Deinitialize the OSIF Request Manager
  200. *
  201. * This function must be called during system shutdown to deinitialize
  202. * the OSIF Request Manager.
  203. *
  204. * Returns: Nothing
  205. */
  206. void osif_request_manager_deinit(void);
  207. #endif /* __WLAN_OSIF_REQUEST_MANAGER_H__ */