qcacmn: Add tlv formation of wmi power commands in common wmi layer

Move tlv formation of wmi power commands from umac to
common wmi layer.

Change-Id: Ie1940d8fafad600e8c245f24beec9e33c6bb6b54
CRs-Fixed: 982337
This commit is contained in:
Govind Singh
2016-02-26 18:09:36 +05:30
parent d3156ebc2a
commit 427ee5a914
2 changed files with 661 additions and 0 deletions

View File

@@ -1378,9 +1378,481 @@ end:
int32_t send_mgmt_cmd_tlv(wmi_unified_t wmi_handle,
struct wmi_mgmt_params *param)
{
wmi_buf_t buf;
wmi_mgmt_tx_send_cmd_fixed_param *cmd;
int32_t cmd_len;
uint64_t dma_addr;
struct wmi_desc_t *wmi_desc = NULL;
void *cdf_ctx = param->cdf_ctx;
uint8_t *bufp;
int32_t bufp_len = (param->frm_len < mgmt_tx_dl_frm_len) ? param->frm_len :
mgmt_tx_dl_frm_len;
cmd_len = sizeof(wmi_mgmt_tx_send_cmd_fixed_param) +
WMI_TLV_HDR_SIZE + roundup(bufp_len, sizeof(uint32_t));
buf = wmi_buf_alloc(wmi_handle, cmd_len);
if (!buf) {
WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
return CDF_STATUS_E_NOMEM;
}
cmd = (wmi_mgmt_tx_send_cmd_fixed_param *)wmi_buf_data(buf);
bufp = (uint8_t *) cmd;
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_mgmt_tx_send_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_mgmt_tx_send_cmd_fixed_param));
cmd->vdev_id = param->vdev_id;
wmi_desc = param->wmi_desc;
if (!wmi_desc) {
WMA_LOGE("%s: Failed to get wmi_desc", __func__);
goto err1;
}
wmi_desc->nbuf = param->tx_frame;
wmi_desc->tx_cmpl_cb = param->tx_complete_cb;
wmi_desc->ota_post_proc_cb = param->tx_ota_post_proc_cb;
cmd->desc_id = wmi_desc->desc_id;
cmd->chanfreq = param->chanfreq;
bufp += sizeof(wmi_mgmt_tx_send_cmd_fixed_param);
WMITLV_SET_HDR(bufp, WMITLV_TAG_ARRAY_BYTE, roundup(bufp_len,
sizeof(uint32_t)));
bufp += WMI_TLV_HDR_SIZE;
cdf_mem_copy(bufp, param->pdata, bufp_len);
cdf_nbuf_map_single(cdf_ctx, param->tx_frame, CDF_DMA_TO_DEVICE);
dma_addr = cdf_nbuf_get_frag_paddr_lo(param->tx_frame, 0);
cmd->paddr_lo = (uint32_t)(dma_addr & 0xffffffff);
#if defined(HELIUMPLUS_PADDR64)
cmd->paddr_hi = (uint32_t)((dma_addr >> 32) & 0x1F);
#endif
cmd->frame_len = param->frm_len;
cmd->buf_len = bufp_len;
if (wmi_unified_cmd_send(wmi_handle, buf, cmd_len,
WMI_MGMT_TX_SEND_CMDID)) {
WMA_LOGE("%s: Failed to send mgmt Tx", __func__);
goto err1;
}
return CDF_STATUS_SUCCESS;
err1:
wmi_buf_free(buf);
return CDF_STATUS_E_FAILURE;
}
/**
* send_modem_power_state_cmd_tlv() - set modem power state to fw
* @wmi_handle: wmi handle
* @param_value: parameter value
*
* Return: 0 for success or error code
*/
int32_t send_modem_power_state_cmd_tlv(wmi_unified_t wmi_handle,
uint32_t param_value)
{
int ret;
wmi_modem_power_state_cmd_param *cmd;
wmi_buf_t buf;
uint16_t len = sizeof(*cmd);
buf = wmi_buf_alloc(wmi_handle, len);
if (!buf) {
WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
return -ENOMEM;
}
cmd = (wmi_modem_power_state_cmd_param *) wmi_buf_data(buf);
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_modem_power_state_cmd_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_modem_power_state_cmd_param));
cmd->modem_power_state = param_value;
WMA_LOGD("%s: Setting cmd->modem_power_state = %u", __func__,
param_value);
ret = wmi_unified_cmd_send(wmi_handle, buf, len,
WMI_MODEM_POWER_STATE_CMDID);
if (ret != EOK) {
WMA_LOGE("Failed to send notify cmd ret = %d", ret);
wmi_buf_free(buf);
}
return ret;
}
/**
* send_set_sta_ps_mode_cmd_tlv() - set sta powersave mode in fw
* @wmi_handle: wmi handle
* @vdev_id: vdev id
* @val: value
*
* Return: 0 for success or error code.
*/
int32_t send_set_sta_ps_mode_cmd_tlv(wmi_unified_t wmi_handle,
uint32_t vdev_id, uint8_t val)
{
wmi_sta_powersave_mode_cmd_fixed_param *cmd;
wmi_buf_t buf;
int32_t len = sizeof(*cmd);
WMA_LOGD("Set Sta Mode Ps vdevId %d val %d", vdev_id, val);
buf = wmi_buf_alloc(wmi_handle, len);
if (!buf) {
WMA_LOGP("%s: Set Sta Mode Ps Mem Alloc Failed", __func__);
return -ENOMEM;
}
cmd = (wmi_sta_powersave_mode_cmd_fixed_param *) wmi_buf_data(buf);
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_sta_powersave_mode_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_sta_powersave_mode_cmd_fixed_param));
cmd->vdev_id = vdev_id;
if (val)
cmd->sta_ps_mode = WMI_STA_PS_MODE_ENABLED;
else
cmd->sta_ps_mode = WMI_STA_PS_MODE_DISABLED;
if (wmi_unified_cmd_send(wmi_handle, buf, len,
WMI_STA_POWERSAVE_MODE_CMDID)) {
WMA_LOGE("Set Sta Mode Ps Failed vdevId %d val %d",
vdev_id, val);
cdf_nbuf_free(buf);
return -EIO;
}
return 0;
}
/**
* send_set_mimops_cmd_tlv() - set MIMO powersave
* @wmi_handle: wmi handle
* @vdev_id: vdev id
* @value: value
*
* Return: CDF_STATUS_SUCCESS for success or error code.
*/
int32_t send_set_mimops_cmd_tlv(wmi_unified_t wmi_handle,
uint8_t vdev_id, int value)
{
int ret = CDF_STATUS_SUCCESS;
wmi_sta_smps_force_mode_cmd_fixed_param *cmd;
wmi_buf_t buf;
uint16_t len = sizeof(*cmd);
buf = wmi_buf_alloc(wmi_handle, len);
if (!buf) {
WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
return -ENOMEM;
}
cmd = (wmi_sta_smps_force_mode_cmd_fixed_param *) wmi_buf_data(buf);
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_sta_smps_force_mode_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_sta_smps_force_mode_cmd_fixed_param));
cmd->vdev_id = vdev_id;
switch (value) {
case 0:
cmd->forced_mode = WMI_SMPS_FORCED_MODE_NONE;
break;
case 1:
cmd->forced_mode = WMI_SMPS_FORCED_MODE_DISABLED;
break;
case 2:
cmd->forced_mode = WMI_SMPS_FORCED_MODE_STATIC;
break;
case 3:
cmd->forced_mode = WMI_SMPS_FORCED_MODE_DYNAMIC;
break;
default:
WMA_LOGE("%s:INVALID Mimo PS CONFIG", __func__);
return CDF_STATUS_E_FAILURE;
}
WMA_LOGD("Setting vdev %d value = %u", vdev_id, value);
ret = wmi_unified_cmd_send(wmi_handle, buf, len,
WMI_STA_SMPS_FORCE_MODE_CMDID);
if (ret < 0) {
WMA_LOGE("Failed to send set Mimo PS ret = %d", ret);
wmi_buf_free(buf);
}
return ret;
}
/**
* send_set_smps_params_cmd_tlv() - set smps params
* @wmi_handle: wmi handle
* @vdev_id: vdev id
* @value: value
*
* Return: CDF_STATUS_SUCCESS for success or error code.
*/
int32_t send_set_smps_params_cmd_tlv(wmi_unified_t wmi_handle, uint8_t vdev_id,
int value)
{
int ret = CDF_STATUS_SUCCESS;
wmi_sta_smps_param_cmd_fixed_param *cmd;
wmi_buf_t buf;
uint16_t len = sizeof(*cmd);
buf = wmi_buf_alloc(wmi_handle, len);
if (!buf) {
WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
return -ENOMEM;
}
cmd = (wmi_sta_smps_param_cmd_fixed_param *) wmi_buf_data(buf);
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_sta_smps_param_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_sta_smps_param_cmd_fixed_param));
cmd->vdev_id = vdev_id;
cmd->value = value & WMI_SMPS_MASK_LOWER_16BITS;
cmd->param =
(value >> WMI_SMPS_PARAM_VALUE_S) & WMI_SMPS_MASK_UPPER_3BITS;
WMA_LOGD("Setting vdev %d value = %x param %x", vdev_id, cmd->value,
cmd->param);
ret = wmi_unified_cmd_send(wmi_handle, buf, len,
WMI_STA_SMPS_PARAM_CMDID);
if (ret < 0) {
WMA_LOGE("Failed to send set Mimo PS ret = %d", ret);
wmi_buf_free(buf);
}
return ret;
}
/**
* send_set_p2pgo_noa_req_cmd_tlv() - send p2p go noa request to fw
* @wmi_handle: wmi handle
* @noa: p2p power save parameters
*
* Return: none
*/
int32_t send_set_p2pgo_noa_req_cmd_tlv(wmi_unified_t wmi_handle,
struct p2p_ps_params *noa)
{
wmi_p2p_set_noa_cmd_fixed_param *cmd;
wmi_p2p_noa_descriptor *noa_discriptor;
wmi_buf_t buf;
uint8_t *buf_ptr;
uint16_t len;
int32_t status;
uint32_t duration;
WMA_LOGD("%s: Enter", __func__);
len = sizeof(*cmd) + WMI_TLV_HDR_SIZE + sizeof(*noa_discriptor);
buf = wmi_buf_alloc(wmi_handle, len);
if (!buf) {
WMA_LOGE("Failed to allocate memory");
status = CDF_STATUS_E_FAILURE;
goto end;
}
buf_ptr = (uint8_t *) wmi_buf_data(buf);
cmd = (wmi_p2p_set_noa_cmd_fixed_param *) buf_ptr;
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_p2p_set_noa_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_p2p_set_noa_cmd_fixed_param));
duration = (noa->count == 1) ? noa->single_noa_duration : noa->duration;
cmd->vdev_id = noa->session_id;
cmd->enable = (duration) ? true : false;
cmd->num_noa = 1;
WMITLV_SET_HDR((buf_ptr + sizeof(wmi_p2p_set_noa_cmd_fixed_param)),
WMITLV_TAG_ARRAY_STRUC, sizeof(wmi_p2p_noa_descriptor));
noa_discriptor = (wmi_p2p_noa_descriptor *) (buf_ptr +
sizeof
(wmi_p2p_set_noa_cmd_fixed_param)
+ WMI_TLV_HDR_SIZE);
WMITLV_SET_HDR(&noa_discriptor->tlv_header,
WMITLV_TAG_STRUC_wmi_p2p_noa_descriptor,
WMITLV_GET_STRUCT_TLVLEN(wmi_p2p_noa_descriptor));
noa_discriptor->type_count = noa->count;
noa_discriptor->duration = duration;
noa_discriptor->interval = noa->interval;
noa_discriptor->start_time = 0;
WMA_LOGI("SET P2P GO NOA:vdev_id:%d count:%d duration:%d interval:%d",
cmd->vdev_id, noa->count, noa_discriptor->duration,
noa->interval);
status = wmi_unified_cmd_send(wmi_handle, buf, len,
WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID);
if (status != EOK) {
WMA_LOGE("Failed to send WMI_FWTEST_P2P_SET_NOA_PARAM_CMDID");
wmi_buf_free(buf);
}
end:
WMA_LOGD("%s: Exit", __func__);
return status;
}
/**
* send_set_p2pgo_oppps_req_cmd_tlv() - send p2p go opp power save request to fw
* @wmi_handle: wmi handle
* @noa: p2p opp power save parameters
*
* Return: none
*/
int32_t send_set_p2pgo_oppps_req_cmd_tlv(wmi_unified_t wmi_handle,
struct p2p_ps_params *oppps)
{
wmi_p2p_set_oppps_cmd_fixed_param *cmd;
wmi_buf_t buf;
int32_t status;
WMA_LOGD("%s: Enter", __func__);
buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
if (!buf) {
WMA_LOGE("Failed to allocate memory");
status = CDF_STATUS_E_FAILURE;
goto end;
}
cmd = (wmi_p2p_set_oppps_cmd_fixed_param *) wmi_buf_data(buf);
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_p2p_set_oppps_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_p2p_set_oppps_cmd_fixed_param));
cmd->vdev_id = oppps->session_id;
if (oppps->ctwindow)
WMI_UNIFIED_OPPPS_ATTR_ENABLED_SET(cmd);
WMI_UNIFIED_OPPPS_ATTR_CTWIN_SET(cmd, oppps->ctwindow);
WMA_LOGI("SET P2P GO OPPPS:vdev_id:%d ctwindow:%d",
cmd->vdev_id, oppps->ctwindow);
status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
WMI_P2P_SET_OPPPS_PARAM_CMDID);
if (status != EOK) {
WMA_LOGE("Failed to send WMI_P2P_SET_OPPPS_PARAM_CMDID");
wmi_buf_free(buf);
}
end:
WMA_LOGD("%s: Exit", __func__);
return status;
}
/**
* send_get_temperature_cmd_tlv() - get pdev temperature req
* @wmi_handle: wmi handle
*
* Return: CDF_STATUS_SUCCESS for success or error code.
*/
int32_t send_get_temperature_cmd_tlv(wmi_unified_t wmi_handle)
{
wmi_pdev_get_temperature_cmd_fixed_param *cmd;
wmi_buf_t wmi_buf;
uint32_t len = sizeof(wmi_pdev_get_temperature_cmd_fixed_param);
uint8_t *buf_ptr;
if (!wmi_handle) {
WMA_LOGE(FL("WMA is closed, can not issue cmd"));
return CDF_STATUS_E_INVAL;
}
wmi_buf = wmi_buf_alloc(wmi_handle, len);
if (!wmi_buf) {
WMA_LOGE(FL("wmi_buf_alloc failed"));
return CDF_STATUS_E_NOMEM;
}
buf_ptr = (uint8_t *) wmi_buf_data(wmi_buf);
cmd = (wmi_pdev_get_temperature_cmd_fixed_param *) buf_ptr;
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_pdev_get_temperature_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_pdev_get_temperature_cmd_fixed_param));
if (wmi_unified_cmd_send(wmi_handle, wmi_buf, len,
WMI_PDEV_GET_TEMPERATURE_CMDID)) {
WMA_LOGE(FL("failed to send get temperature command"));
wmi_buf_free(wmi_buf);
return CDF_STATUS_E_FAILURE;
}
return CDF_STATUS_SUCCESS;
}
/**
* send_set_sta_uapsd_auto_trig_cmd_tlv() - set uapsd auto trigger command
* @wmi_handle: wmi handle
* @vdevid: vdev id
* @peer_addr: peer mac address
* @auto_triggerparam: auto trigger parameters
* @num_ac: number of access category
*
* This function sets the trigger
* uapsd params such as service interval, delay interval
* and suspend interval which will be used by the firmware
* to send trigger frames periodically when there is no
* traffic on the transmit side.
*
* Return: 0 for success or error code.
*/
int32_t send_set_sta_uapsd_auto_trig_cmd_tlv(wmi_unified_t wmi_handle,
struct sta_uapsd_trig_params *param)
{
wmi_sta_uapsd_auto_trig_cmd_fixed_param *cmd;
int32_t ret;
uint32_t param_len = param->num_ac * sizeof(wmi_sta_uapsd_auto_trig_param);
uint32_t cmd_len = sizeof(*cmd) + param_len + WMI_TLV_HDR_SIZE;
uint32_t i;
wmi_buf_t buf;
uint8_t *buf_ptr;
buf = wmi_buf_alloc(wmi_handle, cmd_len);
if (!buf) {
WMA_LOGE("%s:wmi_buf_alloc failed", __func__);
return -ENOMEM;
}
buf_ptr = (uint8_t *) wmi_buf_data(buf);
cmd = (wmi_sta_uapsd_auto_trig_cmd_fixed_param *) buf_ptr;
WMITLV_SET_HDR(&cmd->tlv_header,
WMITLV_TAG_STRUC_wmi_sta_uapsd_auto_trig_cmd_fixed_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_sta_uapsd_auto_trig_cmd_fixed_param));
cmd->vdev_id = param->vdevid;
cmd->num_ac = param->num_ac;
WMI_CHAR_ARRAY_TO_MAC_ADDR(param->peer_addr, &cmd->peer_macaddr);
/* TLV indicating array of structures to follow */
buf_ptr += sizeof(*cmd);
WMITLV_SET_HDR(buf_ptr, WMITLV_TAG_ARRAY_STRUC, param_len);
buf_ptr += WMI_TLV_HDR_SIZE;
cdf_mem_copy(buf_ptr, param->auto_triggerparam, param_len);
/*
* Update tag and length for uapsd auto trigger params (this will take
* care of updating tag and length if it is not pre-filled by caller).
*/
for (i = 0; i < param->num_ac; i++) {
WMITLV_SET_HDR((buf_ptr +
(i * sizeof(wmi_sta_uapsd_auto_trig_param))),
WMITLV_TAG_STRUC_wmi_sta_uapsd_auto_trig_param,
WMITLV_GET_STRUCT_TLVLEN
(wmi_sta_uapsd_auto_trig_param));
}
ret = wmi_unified_cmd_send(wmi_handle, buf, cmd_len,
WMI_STA_UAPSD_AUTO_TRIG_CMDID);
if (ret != EOK) {
WMA_LOGE("Failed to send set uapsd param ret = %d", ret);
wmi_buf_free(buf);
}
return ret;
}
struct wmi_ops tlv_ops = {
.send_vdev_create_cmd = send_vdev_create_cmd_tlv,
.send_vdev_delete_cmd = send_vdev_delete_cmd_tlv,
@@ -1388,7 +1860,9 @@ struct wmi_ops tlv_ops = {
.send_peer_flush_tids_cmd = send_peer_flush_tids_cmd_tlv,
.send_peer_param_cmd = send_peer_param_cmd_tlv,
.send_vdev_up_cmd = send_vdev_up_cmd_tlv,
.send_vdev_stop_cmd = send_vdev_stop_cmd_tlv,
.send_peer_create_cmd = send_peer_create_cmd_tlv,
.send_peer_delete_cmd = send_peer_delete_cmd_tlv,
.send_green_ap_ps_cmd = send_green_ap_ps_cmd_tlv,
.send_pdev_utf_cmd = send_pdev_utf_cmd_tlv,
.send_pdev_param_cmd = send_pdev_param_cmd_tlv,
@@ -1407,6 +1881,15 @@ struct wmi_ops tlv_ops = {
.send_scan_start_cmd = send_scan_start_cmd_tlv,
.send_scan_stop_cmd = send_scan_stop_cmd_tlv,
.send_scan_chan_list_cmd = send_scan_chan_list_cmd_tlv,
.send_mgmt_cmd = send_mgmt_cmd_tlv,
.send_modem_power_state_cmd = send_modem_power_state_cmd_tlv,
.send_set_sta_ps_mode_cmd = send_set_sta_ps_mode_cmd_tlv,
.send_set_sta_uapsd_auto_trig_cmd = send_set_sta_uapsd_auto_trig_cmd_tlv,
.send_get_temperature_cmd = send_get_temperature_cmd_tlv,
.send_set_p2pgo_oppps_req_cmd = send_set_p2pgo_oppps_req_cmd_tlv,
.send_set_p2pgo_noa_req_cmd = send_set_p2pgo_noa_req_cmd_tlv,
.send_set_smps_params_cmd = send_set_smps_params_cmd_tlv,
.send_set_mimops_cmd = send_set_mimops_cmd_tlv,
/* TODO - Add other tlv apis here */
};