xref: /openbmc/linux/drivers/net/wireless/ti/wl18xx/cmd.c (revision 750e9d15)
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 
82 int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
83 {
84 	struct wl18xx_cmd_smart_config_start *cmd;
85 	int ret = 0;
86 
87 	wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
88 		     group_bitmap);
89 
90 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
91 	if (!cmd) {
92 		ret = -ENOMEM;
93 		goto out;
94 	}
95 
96 	cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
97 
98 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
99 	if (ret < 0) {
100 		wl1271_error("failed to send smart config start command");
101 		goto out_free;
102 	}
103 
104 out_free:
105 	kfree(cmd);
106 out:
107 	return ret;
108 }
109 
110 int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
111 {
112 	struct wl1271_cmd_header *cmd;
113 	int ret = 0;
114 
115 	wl1271_debug(DEBUG_CMD, "cmd smart config stop");
116 
117 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
118 	if (!cmd) {
119 		ret = -ENOMEM;
120 		goto out;
121 	}
122 
123 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
124 	if (ret < 0) {
125 		wl1271_error("failed to send smart config stop command");
126 		goto out_free;
127 	}
128 
129 out_free:
130 	kfree(cmd);
131 out:
132 	return ret;
133 }
134 
135 int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
136 					  u8 key_len, u8 *key)
137 {
138 	struct wl18xx_cmd_smart_config_set_group_key *cmd;
139 	int ret = 0;
140 
141 	wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
142 		     group_id);
143 
144 	if (key_len != sizeof(cmd->key)) {
145 		wl1271_error("invalid group key size: %d", key_len);
146 		return -E2BIG;
147 	}
148 
149 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
150 	if (!cmd) {
151 		ret = -ENOMEM;
152 		goto out;
153 	}
154 
155 	cmd->group_id = cpu_to_le32(group_id);
156 	memcpy(cmd->key, key, key_len);
157 
158 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
159 			      sizeof(*cmd), 0);
160 	if (ret < 0) {
161 		wl1271_error("failed to send smart config set group key cmd");
162 		goto out_free;
163 	}
164 
165 out_free:
166 	kfree(cmd);
167 out:
168 	return ret;
169 }
170 
171 int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
172 {
173 	struct wlcore_cmd_cac_start *cmd;
174 	int ret = 0;
175 
176 	wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
177 		     wlvif->channel, start ? "start" : "stop");
178 
179 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
180 	if (!cmd)
181 		return -ENOMEM;
182 
183 	cmd->role_id = wlvif->role_id;
184 	cmd->channel = wlvif->channel;
185 	if (wlvif->band == IEEE80211_BAND_5GHZ)
186 		cmd->band = WLCORE_BAND_5GHZ;
187 	cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
188 
189 	ret = wl1271_cmd_send(wl,
190 			      start ? CMD_CAC_START : CMD_CAC_STOP,
191 			      cmd, sizeof(*cmd), 0);
192 	if (ret < 0) {
193 		wl1271_error("failed to send cac command");
194 		goto out_free;
195 	}
196 
197 out_free:
198 	kfree(cmd);
199 	return ret;
200 }
201