wmi_unified_concurrency_tlv.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (c) 2013-2020 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. #include <osdep.h>
  19. #include <wmi.h>
  20. #include <wmi_unified_priv.h>
  21. #include <wmi_unified_concurrency_api.h>
  22. /**
  23. * send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv() -enable/disable
  24. * mcc scheduler
  25. * @wmi_handle: wmi handle
  26. * @mcc_adaptive_scheduler: enable/disable
  27. *
  28. * This function enable/disable mcc adaptive scheduler in fw.
  29. *
  30. * Return: QDF_STATUS_SUCCESS for success or error code
  31. */
  32. static QDF_STATUS send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv(
  33. wmi_unified_t wmi_handle, uint32_t mcc_adaptive_scheduler,
  34. uint32_t pdev_id)
  35. {
  36. QDF_STATUS ret;
  37. wmi_buf_t buf = 0;
  38. wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *cmd = NULL;
  39. uint16_t len =
  40. sizeof(wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param);
  41. buf = wmi_buf_alloc(wmi_handle, len);
  42. if (!buf) {
  43. return QDF_STATUS_E_NOMEM;
  44. }
  45. cmd = (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param *)
  46. wmi_buf_data(buf);
  47. WMITLV_SET_HDR(&cmd->tlv_header,
  48. WMITLV_TAG_STRUC_wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param,
  49. WMITLV_GET_STRUCT_TLVLEN
  50. (wmi_resmgr_adaptive_ocs_enable_disable_cmd_fixed_param));
  51. cmd->enable = mcc_adaptive_scheduler;
  52. cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
  53. wmi_handle,
  54. pdev_id);
  55. wmi_mtrace(WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID, NO_SESSION, 0);
  56. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  57. WMI_RESMGR_ADAPTIVE_OCS_ENABLE_DISABLE_CMDID);
  58. if (QDF_IS_STATUS_ERROR(ret)) {
  59. wmi_err("Failed to send enable/disable MCC"
  60. " adaptive scheduler command");
  61. wmi_buf_free(buf);
  62. }
  63. return ret;
  64. }
  65. /**
  66. * send_set_mcc_channel_time_latency_cmd_tlv() -set MCC channel time latency
  67. * @wmi: wmi handle
  68. * @mcc_channel: mcc channel
  69. * @mcc_channel_time_latency: MCC channel time latency.
  70. *
  71. * Currently used to set time latency for an MCC vdev/adapter using operating
  72. * channel of it and channel number. The info is provided run time using
  73. * iwpriv command: iwpriv <wlan0 | p2p0> setMccLatency <latency in ms>.
  74. *
  75. * Return: CDF status
  76. */
  77. static QDF_STATUS send_set_mcc_channel_time_latency_cmd_tlv(
  78. wmi_unified_t wmi_handle,
  79. uint32_t mcc_channel_freq,
  80. uint32_t mcc_channel_time_latency)
  81. {
  82. QDF_STATUS ret;
  83. wmi_buf_t buf = 0;
  84. wmi_resmgr_set_chan_latency_cmd_fixed_param *cmdTL = NULL;
  85. uint16_t len = 0;
  86. uint8_t *buf_ptr = NULL;
  87. wmi_resmgr_chan_latency chan_latency;
  88. /* Note: we only support MCC time latency for a single channel */
  89. uint32_t num_channels = 1;
  90. uint32_t chan1_freq = mcc_channel_freq;
  91. uint32_t latency_chan1 = mcc_channel_time_latency;
  92. /* If 0ms latency is provided, then FW will set to a default.
  93. * Otherwise, latency must be at least 30ms.
  94. */
  95. if ((latency_chan1 > 0) &&
  96. (latency_chan1 < WMI_MCC_MIN_NON_ZERO_CHANNEL_LATENCY)) {
  97. WMI_LOGE("%s: Invalid time latency for Channel #1 = %dms "
  98. "Minimum is 30ms (or 0 to use default value by "
  99. "firmware)", __func__, latency_chan1);
  100. return QDF_STATUS_E_INVAL;
  101. }
  102. /* Set WMI CMD for channel time latency here */
  103. len = sizeof(wmi_resmgr_set_chan_latency_cmd_fixed_param) +
  104. WMI_TLV_HDR_SIZE + /*Place holder for chan_time_latency array */
  105. num_channels * sizeof(wmi_resmgr_chan_latency);
  106. buf = wmi_buf_alloc(wmi_handle, len);
  107. if (!buf) {
  108. return QDF_STATUS_E_NOMEM;
  109. }
  110. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  111. cmdTL = (wmi_resmgr_set_chan_latency_cmd_fixed_param *)
  112. wmi_buf_data(buf);
  113. WMITLV_SET_HDR(&cmdTL->tlv_header,
  114. WMITLV_TAG_STRUC_wmi_resmgr_set_chan_latency_cmd_fixed_param,
  115. WMITLV_GET_STRUCT_TLVLEN
  116. (wmi_resmgr_set_chan_latency_cmd_fixed_param));
  117. cmdTL->num_chans = num_channels;
  118. /* Update channel time latency information for home channel(s) */
  119. buf_ptr += sizeof(*cmdTL);
  120. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  121. num_channels * sizeof(wmi_resmgr_chan_latency));
  122. buf_ptr += WMI_TLV_HDR_SIZE;
  123. chan_latency.chan_mhz = chan1_freq;
  124. chan_latency.latency = latency_chan1;
  125. qdf_mem_copy(buf_ptr, &chan_latency, sizeof(chan_latency));
  126. wmi_mtrace(WMI_RESMGR_SET_CHAN_LATENCY_CMDID, NO_SESSION, 0);
  127. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  128. WMI_RESMGR_SET_CHAN_LATENCY_CMDID);
  129. if (QDF_IS_STATUS_ERROR(ret)) {
  130. WMI_LOGE("%s: Failed to send MCC Channel Time Latency command",
  131. __func__);
  132. wmi_buf_free(buf);
  133. QDF_ASSERT(0);
  134. }
  135. return ret;
  136. }
  137. /**
  138. * send_set_mcc_channel_time_quota_cmd_tlv() -set MCC channel time quota
  139. * @wmi: wmi handle
  140. * @adapter_1_chan_number: adapter 1 channel number
  141. * @adapter_1_quota: adapter 1 quota
  142. * @adapter_2_chan_number: adapter 2 channel number
  143. *
  144. * Return: CDF status
  145. */
  146. static QDF_STATUS send_set_mcc_channel_time_quota_cmd_tlv(
  147. wmi_unified_t wmi_handle,
  148. uint32_t adapter_1_chan_freq,
  149. uint32_t adapter_1_quota,
  150. uint32_t adapter_2_chan_freq)
  151. {
  152. QDF_STATUS ret;
  153. wmi_buf_t buf = 0;
  154. uint16_t len = 0;
  155. uint8_t *buf_ptr = NULL;
  156. wmi_resmgr_set_chan_time_quota_cmd_fixed_param *cmdTQ = NULL;
  157. wmi_resmgr_chan_time_quota chan_quota;
  158. uint32_t quota_chan1 = adapter_1_quota;
  159. /* Knowing quota of 1st chan., derive quota for 2nd chan. */
  160. uint32_t quota_chan2 = 100 - quota_chan1;
  161. /* Note: setting time quota for MCC requires info for 2 channels */
  162. uint32_t num_channels = 2;
  163. uint32_t chan1_freq = adapter_1_chan_freq;
  164. uint32_t chan2_freq = adapter_2_chan_freq;
  165. WMI_LOGD("%s: freq1:%dMHz, Quota1:%dms, "
  166. "freq2:%dMHz, Quota2:%dms", __func__,
  167. chan1_freq, quota_chan1, chan2_freq,
  168. quota_chan2);
  169. /*
  170. * Perform sanity check on time quota values provided.
  171. */
  172. if (quota_chan1 < WMI_MCC_MIN_CHANNEL_QUOTA ||
  173. quota_chan1 > WMI_MCC_MAX_CHANNEL_QUOTA) {
  174. WMI_LOGE("%s: Invalid time quota for Channel #1=%dms. Minimum "
  175. "is 20ms & maximum is 80ms", __func__, quota_chan1);
  176. return QDF_STATUS_E_INVAL;
  177. }
  178. /* Set WMI CMD for channel time quota here */
  179. len = sizeof(wmi_resmgr_set_chan_time_quota_cmd_fixed_param) +
  180. WMI_TLV_HDR_SIZE + /* Place holder for chan_time_quota array */
  181. num_channels * sizeof(wmi_resmgr_chan_time_quota);
  182. buf = wmi_buf_alloc(wmi_handle, len);
  183. if (!buf) {
  184. return QDF_STATUS_E_NOMEM;
  185. }
  186. buf_ptr = (uint8_t *) wmi_buf_data(buf);
  187. cmdTQ = (wmi_resmgr_set_chan_time_quota_cmd_fixed_param *)
  188. wmi_buf_data(buf);
  189. WMITLV_SET_HDR(&cmdTQ->tlv_header,
  190. WMITLV_TAG_STRUC_wmi_resmgr_set_chan_time_quota_cmd_fixed_param,
  191. WMITLV_GET_STRUCT_TLVLEN
  192. (wmi_resmgr_set_chan_time_quota_cmd_fixed_param));
  193. cmdTQ->num_chans = num_channels;
  194. /* Update channel time quota information for home channel(s) */
  195. buf_ptr += sizeof(*cmdTQ);
  196. WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_BYTE,
  197. num_channels * sizeof(wmi_resmgr_chan_time_quota));
  198. buf_ptr += WMI_TLV_HDR_SIZE;
  199. chan_quota.chan_mhz = chan1_freq;
  200. chan_quota.channel_time_quota = quota_chan1;
  201. qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
  202. /* Construct channel and quota record for the 2nd MCC mode. */
  203. buf_ptr += sizeof(chan_quota);
  204. chan_quota.chan_mhz = chan2_freq;
  205. chan_quota.channel_time_quota = quota_chan2;
  206. qdf_mem_copy(buf_ptr, &chan_quota, sizeof(chan_quota));
  207. wmi_mtrace(WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID, NO_SESSION, 0);
  208. ret = wmi_unified_cmd_send(wmi_handle, buf, len,
  209. WMI_RESMGR_SET_CHAN_TIME_QUOTA_CMDID);
  210. if (QDF_IS_STATUS_ERROR(ret)) {
  211. WMI_LOGE("Failed to send MCC Channel Time Quota command");
  212. wmi_buf_free(buf);
  213. QDF_ASSERT(0);
  214. }
  215. return ret;
  216. }
  217. void wmi_concurrency_attach_tlv(wmi_unified_t wmi_handle)
  218. {
  219. struct wmi_ops *ops = wmi_handle->ops;
  220. ops->send_set_enable_disable_mcc_adaptive_scheduler_cmd =
  221. send_set_enable_disable_mcc_adaptive_scheduler_cmd_tlv;
  222. ops->send_set_mcc_channel_time_latency_cmd =
  223. send_set_mcc_channel_time_latency_cmd_tlv;
  224. ops->send_set_mcc_channel_time_quota_cmd =
  225. send_set_mcc_channel_time_quota_cmd_tlv;
  226. }