wlan_osif_request_manager.h 8.6 KB

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