1fcab1890SEliad Peller /* 2fcab1890SEliad Peller * This file is part of wl18xx 3fcab1890SEliad Peller * 4fcab1890SEliad Peller * Copyright (C) 2011 Texas Instruments Inc. 5fcab1890SEliad Peller * 6fcab1890SEliad Peller * This program is free software; you can redistribute it and/or 7fcab1890SEliad Peller * modify it under the terms of the GNU General Public License 8fcab1890SEliad Peller * version 2 as published by the Free Software Foundation. 9fcab1890SEliad Peller * 10fcab1890SEliad Peller * This program is distributed in the hope that it will be useful, but 11fcab1890SEliad Peller * WITHOUT ANY WARRANTY; without even the implied warranty of 12fcab1890SEliad Peller * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13fcab1890SEliad Peller * General Public License for more details. 14fcab1890SEliad Peller * 15fcab1890SEliad Peller * You should have received a copy of the GNU General Public License 16fcab1890SEliad Peller * along with this program; if not, write to the Free Software 17fcab1890SEliad Peller * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18fcab1890SEliad Peller * 02110-1301 USA 19fcab1890SEliad Peller * 20fcab1890SEliad Peller */ 21fcab1890SEliad Peller 22fcab1890SEliad Peller #include "../wlcore/cmd.h" 23fcab1890SEliad Peller #include "../wlcore/debug.h" 24fcab1890SEliad Peller #include "../wlcore/hw_ops.h" 25fcab1890SEliad Peller 26fcab1890SEliad Peller #include "cmd.h" 27fcab1890SEliad Peller 28fcab1890SEliad Peller int wl18xx_cmd_channel_switch(struct wl1271 *wl, 29fcab1890SEliad Peller struct wl12xx_vif *wlvif, 30fcab1890SEliad Peller struct ieee80211_channel_switch *ch_switch) 31fcab1890SEliad Peller { 32fcab1890SEliad Peller struct wl18xx_cmd_channel_switch *cmd; 33fcab1890SEliad Peller u32 supported_rates; 34fcab1890SEliad Peller int ret; 35fcab1890SEliad Peller 36fcab1890SEliad Peller wl1271_debug(DEBUG_ACX, "cmd channel switch"); 37fcab1890SEliad Peller 38fcab1890SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 39fcab1890SEliad Peller if (!cmd) { 40fcab1890SEliad Peller ret = -ENOMEM; 41fcab1890SEliad Peller goto out; 42fcab1890SEliad Peller } 43fcab1890SEliad Peller 44fcab1890SEliad Peller cmd->role_id = wlvif->role_id; 4585220d71SJohannes Berg cmd->channel = ch_switch->chandef.chan->hw_value; 46fcab1890SEliad Peller cmd->switch_time = ch_switch->count; 47fcab1890SEliad Peller cmd->stop_tx = ch_switch->block_tx; 48fcab1890SEliad Peller 4985220d71SJohannes Berg switch (ch_switch->chandef.chan->band) { 50fcab1890SEliad Peller case IEEE80211_BAND_2GHZ: 51fcab1890SEliad Peller cmd->band = WLCORE_BAND_2_4GHZ; 52fcab1890SEliad Peller break; 53fcab1890SEliad Peller case IEEE80211_BAND_5GHZ: 54fcab1890SEliad Peller cmd->band = WLCORE_BAND_5GHZ; 55fcab1890SEliad Peller break; 56fcab1890SEliad Peller default: 57fcab1890SEliad Peller wl1271_error("invalid channel switch band: %d", 5885220d71SJohannes Berg ch_switch->chandef.chan->band); 59fcab1890SEliad Peller ret = -EINVAL; 60fcab1890SEliad Peller goto out_free; 61fcab1890SEliad Peller } 62fcab1890SEliad Peller 63fcab1890SEliad Peller supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | 64fcab1890SEliad Peller wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); 65fcab1890SEliad Peller if (wlvif->p2p) 66fcab1890SEliad Peller supported_rates &= ~CONF_TX_CCK_RATES; 67fcab1890SEliad Peller cmd->local_supported_rates = cpu_to_le32(supported_rates); 68fcab1890SEliad Peller cmd->channel_type = wlvif->channel_type; 69fcab1890SEliad Peller 70fcab1890SEliad Peller ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0); 71fcab1890SEliad Peller if (ret < 0) { 72fcab1890SEliad Peller wl1271_error("failed to send channel switch command"); 73fcab1890SEliad Peller goto out_free; 74fcab1890SEliad Peller } 75fcab1890SEliad Peller 76fcab1890SEliad Peller out_free: 77fcab1890SEliad Peller kfree(cmd); 78fcab1890SEliad Peller out: 79fcab1890SEliad Peller return ret; 80fcab1890SEliad Peller } 81ccb1df94SEliad Peller 82ccb1df94SEliad Peller int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap) 83ccb1df94SEliad Peller { 84ccb1df94SEliad Peller struct wl18xx_cmd_smart_config_start *cmd; 85ccb1df94SEliad Peller int ret = 0; 86ccb1df94SEliad Peller 87ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x", 88ccb1df94SEliad Peller group_bitmap); 89ccb1df94SEliad Peller 90ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 91ccb1df94SEliad Peller if (!cmd) { 92ccb1df94SEliad Peller ret = -ENOMEM; 93ccb1df94SEliad Peller goto out; 94ccb1df94SEliad Peller } 95ccb1df94SEliad Peller 96ccb1df94SEliad Peller cmd->group_id_bitmask = cpu_to_le32(group_bitmap); 97ccb1df94SEliad Peller 98ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0); 99ccb1df94SEliad Peller if (ret < 0) { 100ccb1df94SEliad Peller wl1271_error("failed to send smart config start command"); 101ccb1df94SEliad Peller goto out_free; 102ccb1df94SEliad Peller } 103ccb1df94SEliad Peller 104ccb1df94SEliad Peller out_free: 105ccb1df94SEliad Peller kfree(cmd); 106ccb1df94SEliad Peller out: 107ccb1df94SEliad Peller return ret; 108ccb1df94SEliad Peller } 109ccb1df94SEliad Peller 110ccb1df94SEliad Peller int wl18xx_cmd_smart_config_stop(struct wl1271 *wl) 111ccb1df94SEliad Peller { 112ccb1df94SEliad Peller struct wl1271_cmd_header *cmd; 113ccb1df94SEliad Peller int ret = 0; 114ccb1df94SEliad Peller 115ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config stop"); 116ccb1df94SEliad Peller 117ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 118ccb1df94SEliad Peller if (!cmd) { 119ccb1df94SEliad Peller ret = -ENOMEM; 120ccb1df94SEliad Peller goto out; 121ccb1df94SEliad Peller } 122ccb1df94SEliad Peller 123ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0); 124ccb1df94SEliad Peller if (ret < 0) { 125ccb1df94SEliad Peller wl1271_error("failed to send smart config stop command"); 126ccb1df94SEliad Peller goto out_free; 127ccb1df94SEliad Peller } 128ccb1df94SEliad Peller 129ccb1df94SEliad Peller out_free: 130ccb1df94SEliad Peller kfree(cmd); 131ccb1df94SEliad Peller out: 132ccb1df94SEliad Peller return ret; 133ccb1df94SEliad Peller } 134ccb1df94SEliad Peller 135ccb1df94SEliad Peller int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id, 136ccb1df94SEliad Peller u8 key_len, u8 *key) 137ccb1df94SEliad Peller { 138ccb1df94SEliad Peller struct wl18xx_cmd_smart_config_set_group_key *cmd; 139ccb1df94SEliad Peller int ret = 0; 140ccb1df94SEliad Peller 141ccb1df94SEliad Peller wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x", 142ccb1df94SEliad Peller group_id); 143ccb1df94SEliad Peller 144ccb1df94SEliad Peller if (key_len != sizeof(cmd->key)) { 145ccb1df94SEliad Peller wl1271_error("invalid group key size: %d", key_len); 146ccb1df94SEliad Peller return -E2BIG; 147ccb1df94SEliad Peller } 148ccb1df94SEliad Peller 149ccb1df94SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 150ccb1df94SEliad Peller if (!cmd) { 151ccb1df94SEliad Peller ret = -ENOMEM; 152ccb1df94SEliad Peller goto out; 153ccb1df94SEliad Peller } 154ccb1df94SEliad Peller 155ccb1df94SEliad Peller cmd->group_id = cpu_to_le32(group_id); 156ccb1df94SEliad Peller memcpy(cmd->key, key, key_len); 157ccb1df94SEliad Peller 158ccb1df94SEliad Peller ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd, 159ccb1df94SEliad Peller sizeof(*cmd), 0); 160ccb1df94SEliad Peller if (ret < 0) { 161ccb1df94SEliad Peller wl1271_error("failed to send smart config set group key cmd"); 162ccb1df94SEliad Peller goto out_free; 163ccb1df94SEliad Peller } 164ccb1df94SEliad Peller 165ccb1df94SEliad Peller out_free: 166ccb1df94SEliad Peller kfree(cmd); 167ccb1df94SEliad Peller out: 168ccb1df94SEliad Peller return ret; 169ccb1df94SEliad Peller } 170750e9d15SEliad Peller 171750e9d15SEliad Peller int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start) 172750e9d15SEliad Peller { 173750e9d15SEliad Peller struct wlcore_cmd_cac_start *cmd; 174750e9d15SEliad Peller int ret = 0; 175750e9d15SEliad Peller 176750e9d15SEliad Peller wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s", 177750e9d15SEliad Peller wlvif->channel, start ? "start" : "stop"); 178750e9d15SEliad Peller 179750e9d15SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 180750e9d15SEliad Peller if (!cmd) 181750e9d15SEliad Peller return -ENOMEM; 182750e9d15SEliad Peller 183750e9d15SEliad Peller cmd->role_id = wlvif->role_id; 184750e9d15SEliad Peller cmd->channel = wlvif->channel; 185750e9d15SEliad Peller if (wlvif->band == IEEE80211_BAND_5GHZ) 186750e9d15SEliad Peller cmd->band = WLCORE_BAND_5GHZ; 187750e9d15SEliad Peller cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type); 188750e9d15SEliad Peller 189750e9d15SEliad Peller ret = wl1271_cmd_send(wl, 190750e9d15SEliad Peller start ? CMD_CAC_START : CMD_CAC_STOP, 191750e9d15SEliad Peller cmd, sizeof(*cmd), 0); 192750e9d15SEliad Peller if (ret < 0) { 193750e9d15SEliad Peller wl1271_error("failed to send cac command"); 194750e9d15SEliad Peller goto out_free; 195750e9d15SEliad Peller } 196750e9d15SEliad Peller 197750e9d15SEliad Peller out_free: 198750e9d15SEliad Peller kfree(cmd); 199750e9d15SEliad Peller return ret; 200750e9d15SEliad Peller } 201*e7d32324SEliad Peller 202*e7d32324SEliad Peller int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel) 203*e7d32324SEliad Peller { 204*e7d32324SEliad Peller struct wl18xx_cmd_dfs_radar_debug *cmd; 205*e7d32324SEliad Peller int ret = 0; 206*e7d32324SEliad Peller 207*e7d32324SEliad Peller wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)", 208*e7d32324SEliad Peller channel); 209*e7d32324SEliad Peller 210*e7d32324SEliad Peller cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 211*e7d32324SEliad Peller if (!cmd) 212*e7d32324SEliad Peller return -ENOMEM; 213*e7d32324SEliad Peller 214*e7d32324SEliad Peller cmd->channel = channel; 215*e7d32324SEliad Peller 216*e7d32324SEliad Peller ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG, 217*e7d32324SEliad Peller cmd, sizeof(*cmd), 0); 218*e7d32324SEliad Peller if (ret < 0) { 219*e7d32324SEliad Peller wl1271_error("failed to send radar detection debug command"); 220*e7d32324SEliad Peller goto out_free; 221*e7d32324SEliad Peller } 222*e7d32324SEliad Peller 223*e7d32324SEliad Peller out_free: 224*e7d32324SEliad Peller kfree(cmd); 225*e7d32324SEliad Peller return ret; 226*e7d32324SEliad Peller } 227