Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * This file is part of wl18xx
  4 *
  5 * Copyright (C) 2011 Texas Instruments Inc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include "../wlcore/cmd.h"
  9#include "../wlcore/debug.h"
 10#include "../wlcore/hw_ops.h"
 11
 12#include "cmd.h"
 13
 14int wl18xx_cmd_channel_switch(struct wl1271 *wl,
 15			      struct wl12xx_vif *wlvif,
 16			      struct ieee80211_channel_switch *ch_switch)
 17{
 18	struct wl18xx_cmd_channel_switch *cmd;
 19	u32 supported_rates;
 20	int ret;
 21
 22	wl1271_debug(DEBUG_ACX, "cmd channel switch (count=%d)",
 23		     ch_switch->count);
 24
 25	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 26	if (!cmd) {
 27		ret = -ENOMEM;
 28		goto out;
 29	}
 30
 31	cmd->role_id = wlvif->role_id;
 32	cmd->channel = ch_switch->chandef.chan->hw_value;
 33	cmd->switch_time = ch_switch->count;
 34	cmd->stop_tx = ch_switch->block_tx;
 35
 36	switch (ch_switch->chandef.chan->band) {
 37	case NL80211_BAND_2GHZ:
 38		cmd->band = WLCORE_BAND_2_4GHZ;
 39		break;
 40	case NL80211_BAND_5GHZ:
 41		cmd->band = WLCORE_BAND_5GHZ;
 42		break;
 43	default:
 44		wl1271_error("invalid channel switch band: %d",
 45			     ch_switch->chandef.chan->band);
 46		ret = -EINVAL;
 47		goto out_free;
 48	}
 49
 50	supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
 51	if (wlvif->bss_type == BSS_TYPE_STA_BSS)
 52		supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
 53	else
 54		supported_rates |=
 55			wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
 56	if (wlvif->p2p)
 57		supported_rates &= ~CONF_TX_CCK_RATES;
 58	cmd->local_supported_rates = cpu_to_le32(supported_rates);
 59	cmd->channel_type = wlvif->channel_type;
 60
 61	ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
 62	if (ret < 0) {
 63		wl1271_error("failed to send channel switch command");
 64		goto out_free;
 65	}
 66
 67out_free:
 68	kfree(cmd);
 69out:
 70	return ret;
 71}
 72
 73int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
 74{
 75	struct wl18xx_cmd_smart_config_start *cmd;
 76	int ret = 0;
 77
 78	wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
 79		     group_bitmap);
 80
 81	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 82	if (!cmd) {
 83		ret = -ENOMEM;
 84		goto out;
 85	}
 86
 87	cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
 88
 89	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
 90	if (ret < 0) {
 91		wl1271_error("failed to send smart config start command");
 92		goto out_free;
 93	}
 94
 95out_free:
 96	kfree(cmd);
 97out:
 98	return ret;
 99}
100
101int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
102{
103	struct wl1271_cmd_header *cmd;
104	int ret = 0;
105
106	wl1271_debug(DEBUG_CMD, "cmd smart config stop");
107
108	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
109	if (!cmd) {
110		ret = -ENOMEM;
111		goto out;
112	}
113
114	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
115	if (ret < 0) {
116		wl1271_error("failed to send smart config stop command");
117		goto out_free;
118	}
119
120out_free:
121	kfree(cmd);
122out:
123	return ret;
124}
125
126int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
127					  u8 key_len, u8 *key)
128{
129	struct wl18xx_cmd_smart_config_set_group_key *cmd;
130	int ret = 0;
131
132	wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
133		     group_id);
134
135	if (key_len != sizeof(cmd->key)) {
136		wl1271_error("invalid group key size: %d", key_len);
137		return -E2BIG;
138	}
139
140	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
141	if (!cmd) {
142		ret = -ENOMEM;
143		goto out;
144	}
145
146	cmd->group_id = cpu_to_le32(group_id);
147	memcpy(cmd->key, key, key_len);
148
149	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
150			      sizeof(*cmd), 0);
151	if (ret < 0) {
152		wl1271_error("failed to send smart config set group key cmd");
153		goto out_free;
154	}
155
156out_free:
157	kfree(cmd);
158out:
159	return ret;
160}
161
162int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
163{
164	struct wlcore_cmd_cac_start *cmd;
165	int ret = 0;
166
167	wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
168		     wlvif->channel, start ? "start" : "stop");
169
170	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
171	if (!cmd)
172		return -ENOMEM;
173
174	cmd->role_id = wlvif->role_id;
175	cmd->channel = wlvif->channel;
176	if (wlvif->band == NL80211_BAND_5GHZ)
177		cmd->band = WLCORE_BAND_5GHZ;
178	cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
179
180	ret = wl1271_cmd_send(wl,
181			      start ? CMD_CAC_START : CMD_CAC_STOP,
182			      cmd, sizeof(*cmd), 0);
183	if (ret < 0) {
184		wl1271_error("failed to send cac command");
185		goto out_free;
186	}
187
188out_free:
189	kfree(cmd);
190	return ret;
191}
192
193int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
194{
195	struct wl18xx_cmd_dfs_radar_debug *cmd;
196	int ret = 0;
197
198	wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
199		     channel);
200
201	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
202	if (!cmd)
203		return -ENOMEM;
204
205	cmd->channel = channel;
206
207	ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG,
208			      cmd, sizeof(*cmd), 0);
209	if (ret < 0) {
210		wl1271_error("failed to send radar detection debug command");
211		goto out_free;
212	}
213
214out_free:
215	kfree(cmd);
216	return ret;
217}
218
219int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
220{
221	struct wl18xx_cmd_dfs_master_restart *cmd;
222	int ret = 0;
223
224	wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
225		     wlvif->role_id);
226
227	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
228	if (!cmd)
229		return -ENOMEM;
230
231	cmd->role_id = wlvif->role_id;
232
233	ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART,
234			      cmd, sizeof(*cmd), 0);
235	if (ret < 0) {
236		wl1271_error("failed to send dfs master restart command");
237		goto out_free;
238	}
239out_free:
240	kfree(cmd);
241	return ret;
242}
v4.17
 
  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
 28int 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 (count=%d)",
 37		     ch_switch->count);
 38
 39	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 40	if (!cmd) {
 41		ret = -ENOMEM;
 42		goto out;
 43	}
 44
 45	cmd->role_id = wlvif->role_id;
 46	cmd->channel = ch_switch->chandef.chan->hw_value;
 47	cmd->switch_time = ch_switch->count;
 48	cmd->stop_tx = ch_switch->block_tx;
 49
 50	switch (ch_switch->chandef.chan->band) {
 51	case NL80211_BAND_2GHZ:
 52		cmd->band = WLCORE_BAND_2_4GHZ;
 53		break;
 54	case NL80211_BAND_5GHZ:
 55		cmd->band = WLCORE_BAND_5GHZ;
 56		break;
 57	default:
 58		wl1271_error("invalid channel switch band: %d",
 59			     ch_switch->chandef.chan->band);
 60		ret = -EINVAL;
 61		goto out_free;
 62	}
 63
 64	supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
 65	if (wlvif->bss_type == BSS_TYPE_STA_BSS)
 66		supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
 67	else
 68		supported_rates |=
 69			wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
 70	if (wlvif->p2p)
 71		supported_rates &= ~CONF_TX_CCK_RATES;
 72	cmd->local_supported_rates = cpu_to_le32(supported_rates);
 73	cmd->channel_type = wlvif->channel_type;
 74
 75	ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
 76	if (ret < 0) {
 77		wl1271_error("failed to send channel switch command");
 78		goto out_free;
 79	}
 80
 81out_free:
 82	kfree(cmd);
 83out:
 84	return ret;
 85}
 86
 87int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
 88{
 89	struct wl18xx_cmd_smart_config_start *cmd;
 90	int ret = 0;
 91
 92	wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
 93		     group_bitmap);
 94
 95	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
 96	if (!cmd) {
 97		ret = -ENOMEM;
 98		goto out;
 99	}
100
101	cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
102
103	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
104	if (ret < 0) {
105		wl1271_error("failed to send smart config start command");
106		goto out_free;
107	}
108
109out_free:
110	kfree(cmd);
111out:
112	return ret;
113}
114
115int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
116{
117	struct wl1271_cmd_header *cmd;
118	int ret = 0;
119
120	wl1271_debug(DEBUG_CMD, "cmd smart config stop");
121
122	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
123	if (!cmd) {
124		ret = -ENOMEM;
125		goto out;
126	}
127
128	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
129	if (ret < 0) {
130		wl1271_error("failed to send smart config stop command");
131		goto out_free;
132	}
133
134out_free:
135	kfree(cmd);
136out:
137	return ret;
138}
139
140int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
141					  u8 key_len, u8 *key)
142{
143	struct wl18xx_cmd_smart_config_set_group_key *cmd;
144	int ret = 0;
145
146	wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
147		     group_id);
148
149	if (key_len != sizeof(cmd->key)) {
150		wl1271_error("invalid group key size: %d", key_len);
151		return -E2BIG;
152	}
153
154	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
155	if (!cmd) {
156		ret = -ENOMEM;
157		goto out;
158	}
159
160	cmd->group_id = cpu_to_le32(group_id);
161	memcpy(cmd->key, key, key_len);
162
163	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
164			      sizeof(*cmd), 0);
165	if (ret < 0) {
166		wl1271_error("failed to send smart config set group key cmd");
167		goto out_free;
168	}
169
170out_free:
171	kfree(cmd);
172out:
173	return ret;
174}
175
176int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
177{
178	struct wlcore_cmd_cac_start *cmd;
179	int ret = 0;
180
181	wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
182		     wlvif->channel, start ? "start" : "stop");
183
184	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
185	if (!cmd)
186		return -ENOMEM;
187
188	cmd->role_id = wlvif->role_id;
189	cmd->channel = wlvif->channel;
190	if (wlvif->band == NL80211_BAND_5GHZ)
191		cmd->band = WLCORE_BAND_5GHZ;
192	cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
193
194	ret = wl1271_cmd_send(wl,
195			      start ? CMD_CAC_START : CMD_CAC_STOP,
196			      cmd, sizeof(*cmd), 0);
197	if (ret < 0) {
198		wl1271_error("failed to send cac command");
199		goto out_free;
200	}
201
202out_free:
203	kfree(cmd);
204	return ret;
205}
206
207int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
208{
209	struct wl18xx_cmd_dfs_radar_debug *cmd;
210	int ret = 0;
211
212	wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
213		     channel);
214
215	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
216	if (!cmd)
217		return -ENOMEM;
218
219	cmd->channel = channel;
220
221	ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG,
222			      cmd, sizeof(*cmd), 0);
223	if (ret < 0) {
224		wl1271_error("failed to send radar detection debug command");
225		goto out_free;
226	}
227
228out_free:
229	kfree(cmd);
230	return ret;
231}
232
233int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
234{
235	struct wl18xx_cmd_dfs_master_restart *cmd;
236	int ret = 0;
237
238	wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
239		     wlvif->role_id);
240
241	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
242	if (!cmd)
243		return -ENOMEM;
244
245	cmd->role_id = wlvif->role_id;
246
247	ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART,
248			      cmd, sizeof(*cmd), 0);
249	if (ret < 0) {
250		wl1271_error("failed to send dfs master restart command");
251		goto out_free;
252	}
253out_free:
254	kfree(cmd);
255	return ret;
256}