wmi_unified_concurrency_tlv.c 8.4 KB

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