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