xref: /openbmc/linux/drivers/net/wireless/ti/wl18xx/cmd.c (revision b34e08d5)
1 /*
2  * This file is part of wl18xx
3  *
4  * Copyright (C) 2011 Texas Instruments Inc.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21 
22 #include "../wlcore/cmd.h"
23 #include "../wlcore/debug.h"
24 #include "../wlcore/hw_ops.h"
25 
26 #include "cmd.h"
27 
28 int wl18xx_cmd_channel_switch(struct wl1271 *wl,
29 			      struct wl12xx_vif *wlvif,
30 			      struct ieee80211_channel_switch *ch_switch)
31 {
32 	struct wl18xx_cmd_channel_switch *cmd;
33 	u32 supported_rates;
34 	int ret;
35 
36 	wl1271_debug(DEBUG_ACX, "cmd channel switch");
37 
38 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
39 	if (!cmd) {
40 		ret = -ENOMEM;
41 		goto out;
42 	}
43 
44 	cmd->role_id = wlvif->role_id;
45 	cmd->channel = ch_switch->chandef.chan->hw_value;
46 	cmd->switch_time = ch_switch->count;
47 	cmd->stop_tx = ch_switch->block_tx;
48 
49 	switch (ch_switch->chandef.chan->band) {
50 	case IEEE80211_BAND_2GHZ:
51 		cmd->band = WLCORE_BAND_2_4GHZ;
52 		break;
53 	case IEEE80211_BAND_5GHZ:
54 		cmd->band = WLCORE_BAND_5GHZ;
55 		break;
56 	default:
57 		wl1271_error("invalid channel switch band: %d",
58 			     ch_switch->chandef.chan->band);
59 		ret = -EINVAL;
60 		goto out_free;
61 	}
62 
63 	supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES |
64 			  wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
65 	if (wlvif->p2p)
66 		supported_rates &= ~CONF_TX_CCK_RATES;
67 	cmd->local_supported_rates = cpu_to_le32(supported_rates);
68 	cmd->channel_type = wlvif->channel_type;
69 
70 	ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
71 	if (ret < 0) {
72 		wl1271_error("failed to send channel switch command");
73 		goto out_free;
74 	}
75 
76 out_free:
77 	kfree(cmd);
78 out:
79 	return ret;
80 }
81