1*2b27bdccSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2fcab1890SEliad Peller /* 3fcab1890SEliad Peller * This file is part of wl18xx 4fcab1890SEliad Peller * 5fcab1890SEliad Peller * Copyright (C) 2011 Texas Instruments Inc. 6fcab1890SEliad Peller */ 7fcab1890SEliad Peller 8fcab1890SEliad Peller #include "../wlcore/cmd.h" 9fcab1890SEliad Peller #include "../wlcore/debug.h" 10fcab1890SEliad Peller #include "../wlcore/hw_ops.h" 11fcab1890SEliad Peller 12fcab1890SEliad Peller #include "cmd.h" 13fcab1890SEliad Peller 14fcab1890SEliad Peller int wl18xx_cmd_channel_switch(struct wl1271 *wl, 15fcab1890SEliad Peller struct wl12xx_vif *wlvif, 16fcab1890SEliad Peller struct ieee80211_channel_switch *ch_switch) 17fcab1890SEliad Peller { 18fcab1890SEliad Peller struct wl18xx_cmd_channel_switch *cmd; 19fcab1890SEliad Peller u32 supported_rates; 20fcab1890SEliad Peller int ret; 21fcab1890SEliad Peller 22534719f4SEliad Peller wl1271_debug(DEBUG_ACX, "cmd channel switch (count=%d)", 23534719f4SEliad Peller ch_switch->count); 24fcab1890SEliad Peller 25fcab1890SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 26fcab1890SEliad Peller if (!cmd) { 27fcab1890SEliad Peller ret = -ENOMEM; 28fcab1890SEliad Peller goto out; 29fcab1890SEliad Peller } 30fcab1890SEliad Peller 31fcab1890SEliad Peller cmd->role_id = wlvif->role_id; 3285220d71SJohannes Berg cmd->channel = ch_switch->chandef.chan->hw_value; 33fcab1890SEliad Peller cmd->switch_time = ch_switch->count; 34fcab1890SEliad Peller cmd->stop_tx = ch_switch->block_tx; 35fcab1890SEliad Peller 3685220d71SJohannes Berg switch (ch_switch->chandef.chan->band) { 3757fbcce3SJohannes Berg case NL80211_BAND_2GHZ: 38fcab1890SEliad Peller cmd->band = WLCORE_BAND_2_4GHZ; 39fcab1890SEliad Peller break; 4057fbcce3SJohannes Berg case NL80211_BAND_5GHZ: 41fcab1890SEliad Peller cmd->band = WLCORE_BAND_5GHZ; 42fcab1890SEliad Peller break; 43fcab1890SEliad Peller default: 44fcab1890SEliad Peller wl1271_error("invalid channel switch band: %d", 4585220d71SJohannes Berg ch_switch->chandef.chan->band); 46fcab1890SEliad Peller ret = -EINVAL; 47fcab1890SEliad Peller goto out_free; 48fcab1890SEliad Peller } 49fcab1890SEliad Peller 50534719f4SEliad Peller supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES; 51534719f4SEliad Peller if (wlvif->bss_type == BSS_TYPE_STA_BSS) 52534719f4SEliad Peller supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); 53534719f4SEliad Peller else 54534719f4SEliad Peller supported_rates |= 55534719f4SEliad Peller wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif); 56fcab1890SEliad Peller if (wlvif->p2p) 57fcab1890SEliad Peller supported_rates &= ~CONF_TX_CCK_RATES; 58fcab1890SEliad Peller cmd->local_supported_rates = cpu_to_le32(supported_rates); 59fcab1890SEliad Peller cmd->channel_type = wlvif->channel_type; 60fcab1890SEliad Peller 61fcab1890SEliad Peller ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0); 62fcab1890SEliad Peller if (ret < 0) { 63fcab1890SEliad Peller wl1271_error("failed to send channel switch command"); 64fcab1890SEliad Peller goto out_free; 65fcab1890SEliad Peller } 66fcab1890SEliad Peller 67fcab1890SEliad Peller out_free: 68fcab1890SEliad Peller kfree(cmd); 69fcab1890SEliad Peller out: 70fcab1890SEliad Peller return ret; 71fcab1890SEliad Peller } 72ccb1df94SEliad Peller 73ccb1df94SEliad Peller int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap) 74ccb1df94SEliad Peller { 75ccb1df94SEliad Peller struct wl18xx_cmd_smart_config_start *cmd; 76ccb1df94SEliad Peller int ret = 0; 77ccb1df94SEliad Peller 78ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x", 79ccb1df94SEliad Peller group_bitmap); 80ccb1df94SEliad Peller 81ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 82ccb1df94SEliad Peller if (!cmd) { 83ccb1df94SEliad Peller ret = -ENOMEM; 84ccb1df94SEliad Peller goto out; 85ccb1df94SEliad Peller } 86ccb1df94SEliad Peller 87ccb1df94SEliad Peller cmd->group_id_bitmask = cpu_to_le32(group_bitmap); 88ccb1df94SEliad Peller 89ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0); 90ccb1df94SEliad Peller if (ret < 0) { 91ccb1df94SEliad Peller wl1271_error("failed to send smart config start command"); 92ccb1df94SEliad Peller goto out_free; 93ccb1df94SEliad Peller } 94ccb1df94SEliad Peller 95ccb1df94SEliad Peller out_free: 96ccb1df94SEliad Peller kfree(cmd); 97ccb1df94SEliad Peller out: 98ccb1df94SEliad Peller return ret; 99ccb1df94SEliad Peller } 100ccb1df94SEliad Peller 101ccb1df94SEliad Peller int wl18xx_cmd_smart_config_stop(struct wl1271 *wl) 102ccb1df94SEliad Peller { 103ccb1df94SEliad Peller struct wl1271_cmd_header *cmd; 104ccb1df94SEliad Peller int ret = 0; 105ccb1df94SEliad Peller 106ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config stop"); 107ccb1df94SEliad Peller 108ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 109ccb1df94SEliad Peller if (!cmd) { 110ccb1df94SEliad Peller ret = -ENOMEM; 111ccb1df94SEliad Peller goto out; 112ccb1df94SEliad Peller } 113ccb1df94SEliad Peller 114ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0); 115ccb1df94SEliad Peller if (ret < 0) { 116ccb1df94SEliad Peller wl1271_error("failed to send smart config stop command"); 117ccb1df94SEliad Peller goto out_free; 118ccb1df94SEliad Peller } 119ccb1df94SEliad Peller 120ccb1df94SEliad Peller out_free: 121ccb1df94SEliad Peller kfree(cmd); 122ccb1df94SEliad Peller out: 123ccb1df94SEliad Peller return ret; 124ccb1df94SEliad Peller } 125ccb1df94SEliad Peller 126ccb1df94SEliad Peller int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id, 127ccb1df94SEliad Peller u8 key_len, u8 *key) 128ccb1df94SEliad Peller { 129ccb1df94SEliad Peller struct wl18xx_cmd_smart_config_set_group_key *cmd; 130ccb1df94SEliad Peller int ret = 0; 131ccb1df94SEliad Peller 132ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x", 133ccb1df94SEliad Peller group_id); 134ccb1df94SEliad Peller 135ccb1df94SEliad Peller if (key_len != sizeof(cmd->key)) { 136ccb1df94SEliad Peller wl1271_error("invalid group key size: %d", key_len); 137ccb1df94SEliad Peller return -E2BIG; 138ccb1df94SEliad Peller } 139ccb1df94SEliad Peller 140ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 141ccb1df94SEliad Peller if (!cmd) { 142ccb1df94SEliad Peller ret = -ENOMEM; 143ccb1df94SEliad Peller goto out; 144ccb1df94SEliad Peller } 145ccb1df94SEliad Peller 146ccb1df94SEliad Peller cmd->group_id = cpu_to_le32(group_id); 147ccb1df94SEliad Peller memcpy(cmd->key, key, key_len); 148ccb1df94SEliad Peller 149ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd, 150ccb1df94SEliad Peller sizeof(*cmd), 0); 151ccb1df94SEliad Peller if (ret < 0) { 152ccb1df94SEliad Peller wl1271_error("failed to send smart config set group key cmd"); 153ccb1df94SEliad Peller goto out_free; 154ccb1df94SEliad Peller } 155ccb1df94SEliad Peller 156ccb1df94SEliad Peller out_free: 157ccb1df94SEliad Peller kfree(cmd); 158ccb1df94SEliad Peller out: 159ccb1df94SEliad Peller return ret; 160ccb1df94SEliad Peller } 161750e9d15SEliad Peller 162750e9d15SEliad Peller int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start) 163750e9d15SEliad Peller { 164750e9d15SEliad Peller struct wlcore_cmd_cac_start *cmd; 165750e9d15SEliad Peller int ret = 0; 166750e9d15SEliad Peller 167750e9d15SEliad Peller wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s", 168750e9d15SEliad Peller wlvif->channel, start ? "start" : "stop"); 169750e9d15SEliad Peller 170750e9d15SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 171750e9d15SEliad Peller if (!cmd) 172750e9d15SEliad Peller return -ENOMEM; 173750e9d15SEliad Peller 174750e9d15SEliad Peller cmd->role_id = wlvif->role_id; 175750e9d15SEliad Peller cmd->channel = wlvif->channel; 17657fbcce3SJohannes Berg if (wlvif->band == NL80211_BAND_5GHZ) 177750e9d15SEliad Peller cmd->band = WLCORE_BAND_5GHZ; 178750e9d15SEliad Peller cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type); 179750e9d15SEliad Peller 180750e9d15SEliad Peller ret = wl1271_cmd_send(wl, 181750e9d15SEliad Peller start ? CMD_CAC_START : CMD_CAC_STOP, 182750e9d15SEliad Peller cmd, sizeof(*cmd), 0); 183750e9d15SEliad Peller if (ret < 0) { 184750e9d15SEliad Peller wl1271_error("failed to send cac command"); 185750e9d15SEliad Peller goto out_free; 186750e9d15SEliad Peller } 187750e9d15SEliad Peller 188750e9d15SEliad Peller out_free: 189750e9d15SEliad Peller kfree(cmd); 190750e9d15SEliad Peller return ret; 191750e9d15SEliad Peller } 192e7d32324SEliad Peller 193e7d32324SEliad Peller int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel) 194e7d32324SEliad Peller { 195e7d32324SEliad Peller struct wl18xx_cmd_dfs_radar_debug *cmd; 196e7d32324SEliad Peller int ret = 0; 197e7d32324SEliad Peller 198e7d32324SEliad Peller wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)", 199e7d32324SEliad Peller channel); 200e7d32324SEliad Peller 201e7d32324SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 202e7d32324SEliad Peller if (!cmd) 203e7d32324SEliad Peller return -ENOMEM; 204e7d32324SEliad Peller 205e7d32324SEliad Peller cmd->channel = channel; 206e7d32324SEliad Peller 207e7d32324SEliad Peller ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG, 208e7d32324SEliad Peller cmd, sizeof(*cmd), 0); 209e7d32324SEliad Peller if (ret < 0) { 210e7d32324SEliad Peller wl1271_error("failed to send radar detection debug command"); 211e7d32324SEliad Peller goto out_free; 212e7d32324SEliad Peller } 213e7d32324SEliad Peller 214e7d32324SEliad Peller out_free: 215e7d32324SEliad Peller kfree(cmd); 216e7d32324SEliad Peller return ret; 217e7d32324SEliad Peller } 218830513abSEliad Peller 219830513abSEliad Peller int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif) 220830513abSEliad Peller { 221830513abSEliad Peller struct wl18xx_cmd_dfs_master_restart *cmd; 222830513abSEliad Peller int ret = 0; 223830513abSEliad Peller 224830513abSEliad Peller wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)", 225830513abSEliad Peller wlvif->role_id); 226830513abSEliad Peller 227830513abSEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 228830513abSEliad Peller if (!cmd) 229830513abSEliad Peller return -ENOMEM; 230830513abSEliad Peller 231830513abSEliad Peller cmd->role_id = wlvif->role_id; 232830513abSEliad Peller 233830513abSEliad Peller ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART, 234830513abSEliad Peller cmd, sizeof(*cmd), 0); 235830513abSEliad Peller if (ret < 0) { 236830513abSEliad Peller wl1271_error("failed to send dfs master restart command"); 237830513abSEliad Peller goto out_free; 238830513abSEliad Peller } 239830513abSEliad Peller out_free: 240830513abSEliad Peller kfree(cmd); 241830513abSEliad Peller return ret; 242830513abSEliad Peller } 243