wmi_unified_concurrency_tlv.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*
  2. * Copyright (c) 2013-2020 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-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. #include <osdep.h>
  20. #include <wmi.h>
  21. #include <wmi_unified_priv.h>
  22. #include <wmi_unified_concurrency_api.h>
  23. #ifdef WLAN_FEATURE_MCC_QUOTA
  24. #include <wlan_p2p_mcc_quota_public_struct.h>
  25. #endif
  26. /**
  27. * send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv() -enable/disable
  28. * mcc scheduler
  29. * @wmi_handle: wmi handle
  30. * @mcc_adaptive_scheduler: enable/disable
  31. * @pdev_id: pdev identifier
  32. *
  33. * This function enable/disable mcc adaptive scheduler in fw.
  34. *
  35. * Return: QDF_STATUS_SUCCESS for success or error code
  36. */
  37. static QDF_STATUS send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv(
  38. wmi_unified_t wmi_handle, uint32_t mcc_adaptive_scheduler,
  39. uint32_t pdev_id)
  40. {
  41. QDF_STATUS ret;
  42. wmi_buf_t buf = 0;
  43. wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *cmd = NULL;
  44. uint16_t len =
  45. sizeof(wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param);
  46. buf = wmi_buf_alloc(wmi_handle, len);
  47. if (!buf) {
  48. return QDF_STATUS_E_NOMEM;
  49. }
  50. cmd = (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *)
  51. wmi_buf_data(buf);
  52. WMITLV_SET_HDR(&cmd->tlv_header,
  53. WMITLV_TAG_STRUC_wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param,
  54. WMITLV_GET_STRUCT_TLVLEN
  55. (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param));
  56. cmd->enable = mcc_adaptive_scheduler;
  57. cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
  58. wmi_handle,
  59. pdev_id);
  60. wmi_mtrace(WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID, NO_SESSION, 0);
  61. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  62. WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
  63. if (QDF_IS_STATUS_ERROR(ret)) {
  64. wmi_err("Failed to send enable/disable MCC"
  65. " adaptive scheduler command");
  66. wmi_buf_free(buf);
  67. }
  68. return ret;
  69. }
  70. /**
  71. * send_set_mcc_channel_time_latency_cmd_tlv() -set MCC channel time latency
  72. * @wmi_handle: wmi handle
  73. * @mcc_channel_freq: mcc channel frequency in MHz
  74. * @mcc_channel_time_latency: MCC channel time latency.
  75. *
  76. * Currently used to set time latency for an MCC vdev/adapter using operating
  77. * channel of it and channel number. The info is provided run time using
  78. * iwpriv command: iwpriv <wlan0 | p2p0> setMccLatency <latency in ms>.
  79. *
  80. * Return: QDF status
  81. */
  82. static QDF_STATUS send_set_mcc_channel_time_latency_cmd_tlv(
  83. wmi_unified_t wmi_handle,
  84. uint32_t mcc_channel_freq,
  85. uint32_t mcc_channel_time_latency)
  86. {
  87. QDF_STATUS ret;
  88. wmi_buf_t buf = 0;
  89. wmi_resmgr_set_chan_latency_cmd_fixed_param *cmdTL = NULL;
  90. uint16_t len = 0;
  91. uint8_t *buf_ptr = NULL;
  92. wmi_resmgr_chan_latency chan_latency;
  93. /* Note: we only support MCC time latency for a single channel */
  94. uint32_t num_channels = 1;
  95. uint32_t chan1_freq = mcc_channel_freq;
  96. uint32_t latency_chan1 = mcc_channel_time_latency;
  97. /* If 0ms latency is provided, then FW will set to a default.
  98. * Otherwise, latency must be at least 30ms.
  99. */
  100. if ((latency_chan1 > 0) &&
  101. (latency_chan1 < WMI_MCC_MIN_NON_ZERO_CHANNEL_LATENCY)) {
  102. wmi_err("Invalid time latency for Channel #1 = %dms "
  103. "Minimum is 30ms (or 0 to use default value by "
  104. "firmware)", latency_chan1);
  105. return QDF_STATUS_E_INVAL;
  106. }
  107. /* Set WMI CMD for channel time latency here */
  108. len = sizeof(wmi_resmgr_set_chan_latency_cmd_fixed_param) +
  109. WMI_TLV_HDR_SIZE + /*Place holder for chan_time_latency array */
  110. num_channels * sizeof(wmi_resmgr_chan_latency);
  111. buf = wmi_buf_alloc(wmi_handle, len);
  112. if (!buf) {
  113. return QDF_STATUS_E_NOMEM;
  114. }
  115. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  116. cmdTL = (wmi_resmgr_set_chan_latency_cmd_fixed_param *)
  117. wmi_buf_data(buf);
  118. WMITLV_SET_HDR(&cmdTL->tlv_header,
  119. WMITLV_TAG_STRUC_wmi_resmgr_set_chan_latency_cmd_fixed_param,
  120. WMITLV_GET_STRUCT_TLVLEN
  121. (wmi_resmgr_set_chan_latency_cmd_fixed_param));
  122. cmdTL->num_chans = num_channels;
  123. /* Update channel time latency information for home channel(s) */
  124. buf_ptr += sizeof(*cmdTL);
  125. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  126. num_channels * sizeof(wmi_resmgr_chan_latency));
  127. buf_ptr += WMI_TLV_HDR_SIZE;
  128. chan_latency.chan_mhz = chan1_freq;
  129. chan_latency.latency = latency_chan1;
  130. qdf_mem_copy(buf_ptr, &chan_latency, sizeof(chan_latency));
  131. wmi_mtrace(WMI_RESMGR_SET_CHAN_LATENCY_CMDID, NO_SESSION, 0);
  132. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  133. WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
  134. if (QDF_IS_STATUS_ERROR(ret)) {
  135. wmi_err("Failed to send MCC Channel Time Latency command");
  136. wmi_buf_free(buf);
  137. QDF_ASSERT(0);
  138. }
  139. return ret;
  140. }
  141. /**
  142. * send_set_mcc_channel_time_quota_cmd_tlv() -set MCC channel time quota
  143. * @wmi_handle: wmi handle
  144. * @adapter_1_chan_freq: adapter 1 channel frequency in MHz
  145. * @adapter_1_quota: adapter 1 quota
  146. * @adapter_2_chan_freq: adapter 2 channel frequency in MHz
  147. *
  148. * Return: QDF status
  149. */
  150. static QDF_STATUS send_set_mcc_channel_time_quota_cmd_tlv(
  151. wmi_unified_t wmi_handle,
  152. uint32_t adapter_1_chan_freq,
  153. uint32_t adapter_1_quota,
  154. uint32_t adapter_2_chan_freq)
  155. {
  156. QDF_STATUS ret;
  157. wmi_buf_t buf = 0;
  158. uint16_t len = 0;
  159. uint8_t *buf_ptr = NULL;
  160. wmi_resmgr_set_chan_time_quota_cmd_fixed_param *cmdTQ = NULL;
  161. wmi_resmgr_chan_time_quota chan_quota;
  162. uint32_t quota_chan1 = adapter_1_quota;
  163. /* Knowing quota of 1st chan., derive quota for 2nd chan. */
  164. uint32_t quota_chan2 = 100 - quota_chan1;
  165. /* Note: setting time quota for MCC requires info for 2 channels */
  166. uint32_t num_channels = 2;
  167. uint32_t chan1_freq = adapter_1_chan_freq;
  168. uint32_t chan2_freq = adapter_2_chan_freq;
  169. wmi_debug("freq1:%dMHz, Quota1:%dms, freq2:%dMHz, Quota2:%dms",
  170. chan1_freq, quota_chan1, chan2_freq, quota_chan2);
  171. /*
  172. * Perform sanity check on time quota values provided.
  173. */
  174. if (quota_chan1 < WMI_MCC_MIN_CHANNEL_QUOTA ||
  175. quota_chan1 > WMI_MCC_MAX_CHANNEL_QUOTA) {
  176. wmi_err("Invalid time quota for Chan #1=%dms. Min: %dms, Max: %dms",
  177. quota_chan1, WMI_MCC_MIN_CHANNEL_QUOTA,
  178. WMI_MCC_MAX_CHANNEL_QUOTA);
  179. return QDF_STATUS_E_INVAL;
  180. }
  181. /* Set WMI CMD for channel time quota here */
  182. len = sizeof(wmi_resmgr_set_chan_time_quota_cmd_fixed_param) +
  183. WMI_TLV_HDR_SIZE + /* Place holder for chan_time_quota array */
  184. num_channels * sizeof(wmi_resmgr_chan_time_quota);
  185. buf = wmi_buf_alloc(wmi_handle, len);
  186. if (!buf) {
  187. return QDF_STATUS_E_NOMEM;
  188. }
  189. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  190. cmdTQ = (wmi_resmgr_set_chan_time_quota_cmd_fixed_param *)
  191. wmi_buf_data(buf);
  192. WMITLV_SET_HDR(&cmdTQ->tlv_header,
  193. WMITLV_TAG_STRUC_wmi_resmgr_set_chan_time_quota_cmd_fixed_param,
  194. WMITLV_GET_STRUCT_TLVLEN
  195. (wmi_resmgr_set_chan_time_quota_cmd_fixed_param));
  196. cmdTQ->num_chans = num_channels;
  197. /* Update channel time quota information for home channel(s) */
  198. buf_ptr += sizeof(*cmdTQ);
  199. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  200. num_channels * sizeof(wmi_resmgr_chan_time_quota));
  201. buf_ptr += WMI_TLV_HDR_SIZE;
  202. chan_quota.chan_mhz = chan1_freq;
  203. chan_quota.channel_time_quota = quota_chan1;
  204. qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
  205. /* Construct channel and quota record for the 2nd MCC mode. */
  206. buf_ptr += sizeof(chan_quota);
  207. chan_quota.chan_mhz = chan2_freq;
  208. chan_quota.channel_time_quota = quota_chan2;
  209. qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
  210. wmi_mtrace(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID, NO_SESSION, 0);
  211. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  212. WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
  213. if (QDF_IS_STATUS_ERROR(ret)) {
  214. wmi_err("Failed to send MCC Channel Time Quota command");
  215. wmi_buf_free(buf);
  216. QDF_ASSERT(0);
  217. }
  218. return ret;
  219. }
  220. #ifdef WLAN_FEATURE_MCC_QUOTA
  221. /**
  222. * convert_to_host_quota_type() - convert wmi quota type to host quota type
  223. * @quota_type: wmi target quota type
  224. *
  225. * Return: enum mcc_quota_type
  226. */
  227. static enum mcc_quota_type convert_to_host_quota_type(uint32_t quota_type)
  228. {
  229. switch (quota_type) {
  230. case WMI_RESMGR_QUOTA_TYPE_CLEAR:
  231. return QUOTA_TYPE_CLEAR;
  232. case WMI_RESMGR_QUOTA_TYPE_FIXED:
  233. return QUOTA_TYPE_FIXED;
  234. case WMI_RESMGR_QUOTA_TYPE_DYNAMIC:
  235. return QUOTA_TYPE_DYNAMIC;
  236. default:
  237. wmi_err("mcc quota unknown quota type %d", quota_type);
  238. return QUOTA_TYPE_UNKNOWN;
  239. }
  240. }
  241. /**
  242. * extract_mcc_quota_ev_param_tlv() - extract mcc quota information from wmi
  243. * event
  244. * @wmi_handle: wmi handle
  245. * @evt_buf: pointer to event buffer
  246. * @param: Pointer to hold mcc quota info
  247. *
  248. * Return: QDF_STATUS_SUCCESS for success or error code
  249. */
  250. static QDF_STATUS
  251. extract_mcc_quota_ev_param_tlv(wmi_unified_t wmi_handle,
  252. void *evt_buf, struct mcc_quota_info *param)
  253. {
  254. WMI_RESMGR_CHAN_TIME_QUOTA_CHANGED_EVENTID_param_tlvs *param_tlvs;
  255. wmi_resmgr_chan_time_quota_changed_event_fixed_param *fixed_param;
  256. uint8_t i;
  257. wmi_resmgr_chan_time_quota_tlv *wmi_mcc_quota_info;
  258. if (!param) {
  259. wmi_err("mcc quota information param is null");
  260. return QDF_STATUS_E_INVAL;
  261. }
  262. param_tlvs = evt_buf;
  263. if (!param_tlvs || !param_tlvs->fixed_param) {
  264. wmi_err("Invalid mcc quota event buffer");
  265. return QDF_STATUS_E_INVAL;
  266. }
  267. fixed_param = param_tlvs->fixed_param;
  268. wmi_debug("mcc quota type %d, num %d",
  269. fixed_param->quota_type, param_tlvs->num_chan_quota);
  270. param->type = convert_to_host_quota_type(fixed_param->quota_type);
  271. if (param->type == QUOTA_TYPE_UNKNOWN)
  272. return QDF_STATUS_E_INVAL;
  273. if (!param_tlvs->chan_quota) {
  274. param->num_chan_quota = 0;
  275. return QDF_STATUS_SUCCESS;
  276. }
  277. if (param_tlvs->num_chan_quota > MAX_MCC_QUOTA_CH_NUM)
  278. wmi_warn("mcc quota num %d unexpected",
  279. param_tlvs->num_chan_quota);
  280. param->num_chan_quota = qdf_min(param_tlvs->num_chan_quota,
  281. (uint32_t)MAX_MCC_QUOTA_CH_NUM);
  282. wmi_mcc_quota_info = param_tlvs->chan_quota;
  283. for (i = 0; i < param->num_chan_quota; i++) {
  284. param->chan_quota[i].chan_mhz =
  285. wmi_mcc_quota_info[i].chan_time_quota.chan_mhz;
  286. param->chan_quota[i].channel_time_quota =
  287. wmi_mcc_quota_info[i].chan_time_quota.channel_time_quota;
  288. wmi_debug("mcc quota [%d] chan %d, quota %d",
  289. i, param->chan_quota[i].chan_mhz,
  290. param->chan_quota[i].channel_time_quota);
  291. }
  292. return QDF_STATUS_SUCCESS;
  293. }
  294. static void wmi_mcc_quota_evt_attach_tlv(wmi_unified_t wmi_handle)
  295. {
  296. struct wmi_ops *ops = wmi_handle->ops;
  297. ops->extract_mcc_quota_ev_param = extract_mcc_quota_ev_param_tlv;
  298. }
  299. #else
  300. static inline void wmi_mcc_quota_evt_attach_tlv(wmi_unified_t wmi_handle)
  301. {
  302. }
  303. #endif
  304. void wmi_concurrency_attach_tlv(wmi_unified_t wmi_handle)
  305. {
  306. struct wmi_ops *ops = wmi_handle->ops;
  307. ops->send_set_enable_disable_mcc_adaptive_scheduler_cmd =
  308. send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv;
  309. ops->send_set_mcc_channel_time_latency_cmd =
  310. send_set_mcc_channel_time_latency_cmd_tlv;
  311. ops->send_set_mcc_channel_time_quota_cmd =
  312. send_set_mcc_channel_time_quota_cmd_tlv;
  313. wmi_mcc_quota_evt_attach_tlv(wmi_handle);
  314. }