wlan_osif_request_manager.h 8.4 KB

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