cmd.c revision b50a62bb39c66e6ed5f1f581bb32644936f08cf3
1/* 2 * This file is part of wl1271 3 * 4 * Copyright (C) 2009-2010 Nokia Corporation 5 * 6 * Contact: Luciano Coelho <luciano.coelho@nokia.com> 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * version 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA 21 * 22 */ 23 24#include <linux/module.h> 25#include <linux/platform_device.h> 26#include <linux/spi/spi.h> 27#include <linux/etherdevice.h> 28#include <linux/ieee80211.h> 29#include <linux/slab.h> 30 31#include "wlcore.h" 32#include "debug.h" 33#include "io.h" 34#include "acx.h" 35#include "wl12xx_80211.h" 36#include "cmd.h" 37#include "event.h" 38#include "tx.h" 39#include "hw_ops.h" 40 41#define WL1271_CMD_FAST_POLL_COUNT 50 42#define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20 43 44/* 45 * send command to firmware 46 * 47 * @wl: wl struct 48 * @id: command id 49 * @buf: buffer containing the command, must work with dma 50 * @len: length of the buffer 51 * return the cmd status code on success. 52 */ 53static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf, 54 size_t len, size_t res_len) 55{ 56 struct wl1271_cmd_header *cmd; 57 unsigned long timeout; 58 u32 intr; 59 int ret; 60 u16 status; 61 u16 poll_count = 0; 62 63 if (WARN_ON(unlikely(wl->state == WLCORE_STATE_RESTARTING))) 64 return -EIO; 65 66 cmd = buf; 67 cmd->id = cpu_to_le16(id); 68 cmd->status = 0; 69 70 WARN_ON(len % 4 != 0); 71 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags)); 72 73 ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false); 74 if (ret < 0) 75 return ret; 76 77 /* 78 * TODO: we just need this because one bit is in a different 79 * place. Is there any better way? 80 */ 81 ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len); 82 if (ret < 0) 83 return ret; 84 85 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); 86 87 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); 88 if (ret < 0) 89 return ret; 90 91 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { 92 if (time_after(jiffies, timeout)) { 93 wl1271_error("command complete timeout"); 94 return -ETIMEDOUT; 95 } 96 97 poll_count++; 98 if (poll_count < WL1271_CMD_FAST_POLL_COUNT) 99 udelay(10); 100 else 101 msleep(1); 102 103 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); 104 if (ret < 0) 105 return ret; 106 } 107 108 /* read back the status code of the command */ 109 if (res_len == 0) 110 res_len = sizeof(struct wl1271_cmd_header); 111 112 ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false); 113 if (ret < 0) 114 return ret; 115 116 status = le16_to_cpu(cmd->status); 117 118 ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK, 119 WL1271_ACX_INTR_CMD_COMPLETE); 120 if (ret < 0) 121 return ret; 122 123 return status; 124} 125 126/* 127 * send command to fw and return cmd status on success 128 * valid_rets contains a bitmap of allowed error codes 129 */ 130int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf, size_t len, 131 size_t res_len, unsigned long valid_rets) 132{ 133 int ret = __wlcore_cmd_send(wl, id, buf, len, res_len); 134 135 if (ret < 0) 136 goto fail; 137 138 /* success is always a valid status */ 139 valid_rets |= BIT(CMD_STATUS_SUCCESS); 140 141 if (ret >= MAX_COMMAND_STATUS || 142 !test_bit(ret, &valid_rets)) { 143 wl1271_error("command execute failure %d", ret); 144 ret = -EIO; 145 goto fail; 146 } 147 return ret; 148fail: 149 wl12xx_queue_recovery_work(wl); 150 return ret; 151} 152EXPORT_SYMBOL_GPL(wl1271_cmd_send); 153 154/* 155 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS 156 * return 0 on success. 157 */ 158int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, 159 size_t res_len) 160{ 161 int ret = wlcore_cmd_send_failsafe(wl, id, buf, len, res_len, 0); 162 163 if (ret < 0) 164 return ret; 165 return 0; 166} 167 168/* 169 * Poll the mailbox event field until any of the bits in the mask is set or a 170 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) 171 */ 172int wlcore_cmd_wait_for_event_or_timeout(struct wl1271 *wl, 173 u32 mask, bool *timeout) 174{ 175 u32 *events_vector; 176 u32 event; 177 unsigned long timeout_time; 178 u16 poll_count = 0; 179 int ret = 0; 180 181 *timeout = false; 182 183 events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA); 184 if (!events_vector) 185 return -ENOMEM; 186 187 timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); 188 189 do { 190 if (time_after(jiffies, timeout_time)) { 191 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", 192 (int)mask); 193 *timeout = true; 194 goto out; 195 } 196 197 poll_count++; 198 if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT) 199 usleep_range(50, 51); 200 else 201 usleep_range(1000, 5000); 202 203 /* read from both event fields */ 204 ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector, 205 sizeof(*events_vector), false); 206 if (ret < 0) 207 goto out; 208 209 event = *events_vector & mask; 210 211 ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector, 212 sizeof(*events_vector), false); 213 if (ret < 0) 214 goto out; 215 216 event |= *events_vector & mask; 217 } while (!event); 218 219out: 220 kfree(events_vector); 221 return ret; 222} 223EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout); 224 225int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type, 226 u8 *role_id) 227{ 228 struct wl12xx_cmd_role_enable *cmd; 229 int ret; 230 231 wl1271_debug(DEBUG_CMD, "cmd role enable"); 232 233 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID)) 234 return -EBUSY; 235 236 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 237 if (!cmd) { 238 ret = -ENOMEM; 239 goto out; 240 } 241 242 /* get role id */ 243 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES); 244 if (cmd->role_id >= WL12XX_MAX_ROLES) { 245 ret = -EBUSY; 246 goto out_free; 247 } 248 249 memcpy(cmd->mac_address, addr, ETH_ALEN); 250 cmd->role_type = role_type; 251 252 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); 253 if (ret < 0) { 254 wl1271_error("failed to initiate cmd role enable"); 255 goto out_free; 256 } 257 258 __set_bit(cmd->role_id, wl->roles_map); 259 *role_id = cmd->role_id; 260 261out_free: 262 kfree(cmd); 263 264out: 265 return ret; 266} 267 268int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id) 269{ 270 struct wl12xx_cmd_role_disable *cmd; 271 int ret; 272 273 wl1271_debug(DEBUG_CMD, "cmd role disable"); 274 275 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID)) 276 return -ENOENT; 277 278 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 279 if (!cmd) { 280 ret = -ENOMEM; 281 goto out; 282 } 283 cmd->role_id = *role_id; 284 285 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0); 286 if (ret < 0) { 287 wl1271_error("failed to initiate cmd role disable"); 288 goto out_free; 289 } 290 291 __clear_bit(*role_id, wl->roles_map); 292 *role_id = WL12XX_INVALID_ROLE_ID; 293 294out_free: 295 kfree(cmd); 296 297out: 298 return ret; 299} 300 301static int wlcore_get_new_session_id(struct wl1271 *wl, u8 hlid) 302{ 303 if (wl->session_ids[hlid] >= SESSION_COUNTER_MAX) 304 wl->session_ids[hlid] = 0; 305 306 wl->session_ids[hlid]++; 307 308 return wl->session_ids[hlid]; 309} 310 311int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) 312{ 313 unsigned long flags; 314 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS); 315 if (link >= WL12XX_MAX_LINKS) 316 return -EBUSY; 317 318 wl->session_ids[link] = wlcore_get_new_session_id(wl, link); 319 320 /* these bits are used by op_tx */ 321 spin_lock_irqsave(&wl->wl_lock, flags); 322 __set_bit(link, wl->links_map); 323 __set_bit(link, wlvif->links_map); 324 spin_unlock_irqrestore(&wl->wl_lock, flags); 325 326 /* take the last "freed packets" value from the current FW status */ 327 wl->links[link].prev_freed_pkts = 328 wl->fw_status_2->counters.tx_lnk_free_pkts[link]; 329 *hlid = link; 330 return 0; 331} 332 333void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) 334{ 335 unsigned long flags; 336 337 if (*hlid == WL12XX_INVALID_LINK_ID) 338 return; 339 340 /* these bits are used by op_tx */ 341 spin_lock_irqsave(&wl->wl_lock, flags); 342 __clear_bit(*hlid, wl->links_map); 343 __clear_bit(*hlid, wlvif->links_map); 344 spin_unlock_irqrestore(&wl->wl_lock, flags); 345 346 wl->links[*hlid].allocated_pkts = 0; 347 wl->links[*hlid].prev_freed_pkts = 0; 348 wl->links[*hlid].ba_bitmap = 0; 349 memset(wl->links[*hlid].addr, 0, ETH_ALEN); 350 351 /* 352 * At this point op_tx() will not add more packets to the queues. We 353 * can purge them. 354 */ 355 wl1271_tx_reset_link_queues(wl, *hlid); 356 357 *hlid = WL12XX_INVALID_LINK_ID; 358} 359 360static u8 wlcore_get_native_channel_type(u8 nl_channel_type) 361{ 362 switch (nl_channel_type) { 363 case NL80211_CHAN_NO_HT: 364 return WLCORE_CHAN_NO_HT; 365 case NL80211_CHAN_HT20: 366 return WLCORE_CHAN_HT20; 367 case NL80211_CHAN_HT40MINUS: 368 return WLCORE_CHAN_HT40MINUS; 369 case NL80211_CHAN_HT40PLUS: 370 return WLCORE_CHAN_HT40PLUS; 371 default: 372 WARN_ON(1); 373 return WLCORE_CHAN_NO_HT; 374 } 375} 376 377static int wl12xx_cmd_role_start_dev(struct wl1271 *wl, 378 struct wl12xx_vif *wlvif, 379 enum ieee80211_band band, 380 int channel) 381{ 382 struct wl12xx_cmd_role_start *cmd; 383 int ret; 384 385 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 386 if (!cmd) { 387 ret = -ENOMEM; 388 goto out; 389 } 390 391 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id); 392 393 cmd->role_id = wlvif->dev_role_id; 394 if (band == IEEE80211_BAND_5GHZ) 395 cmd->band = WLCORE_BAND_5GHZ; 396 cmd->channel = channel; 397 398 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) { 399 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid); 400 if (ret) 401 goto out_free; 402 } 403 cmd->device.hlid = wlvif->dev_hlid; 404 cmd->device.session = wl->session_ids[wlvif->dev_hlid]; 405 406 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", 407 cmd->role_id, cmd->device.hlid, cmd->device.session); 408 409 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 410 if (ret < 0) { 411 wl1271_error("failed to initiate cmd role enable"); 412 goto err_hlid; 413 } 414 415 goto out_free; 416 417err_hlid: 418 /* clear links on error */ 419 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); 420 421out_free: 422 kfree(cmd); 423 424out: 425 return ret; 426} 427 428static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl, 429 struct wl12xx_vif *wlvif) 430{ 431 struct wl12xx_cmd_role_stop *cmd; 432 int ret; 433 434 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID)) 435 return -EINVAL; 436 437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 438 if (!cmd) { 439 ret = -ENOMEM; 440 goto out; 441 } 442 443 wl1271_debug(DEBUG_CMD, "cmd role stop dev"); 444 445 cmd->role_id = wlvif->dev_role_id; 446 cmd->disc_type = DISCONNECT_IMMEDIATE; 447 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 448 449 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); 450 if (ret < 0) { 451 wl1271_error("failed to initiate cmd role stop"); 452 goto out_free; 453 } 454 455 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); 456 457out_free: 458 kfree(cmd); 459 460out: 461 return ret; 462} 463 464int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) 465{ 466 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 467 struct wl12xx_cmd_role_start *cmd; 468 u32 supported_rates; 469 int ret; 470 471 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 472 if (!cmd) { 473 ret = -ENOMEM; 474 goto out; 475 } 476 477 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id); 478 479 cmd->role_id = wlvif->role_id; 480 if (wlvif->band == IEEE80211_BAND_5GHZ) 481 cmd->band = WLCORE_BAND_5GHZ; 482 cmd->channel = wlvif->channel; 483 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); 484 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int); 485 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; 486 cmd->sta.ssid_len = wlvif->ssid_len; 487 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len); 488 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN); 489 490 supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | 491 wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); 492 if (wlvif->p2p) 493 supported_rates &= ~CONF_TX_CCK_RATES; 494 495 cmd->sta.local_rates = cpu_to_le32(supported_rates); 496 497 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); 498 499 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { 500 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); 501 if (ret) 502 goto out_free; 503 } 504 cmd->sta.hlid = wlvif->sta.hlid; 505 cmd->sta.session = wl->session_ids[wlvif->sta.hlid]; 506 /* 507 * We don't have the correct remote rates in this stage, and there 508 * is no way to update them later, so use our supported rates instead. 509 * The fw will take the configured rate policies into account anyway. 510 */ 511 cmd->sta.remote_rates = cpu_to_le32(supported_rates); 512 513 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 514 "basic_rate_set: 0x%x, remote_rates: 0x%x", 515 wlvif->role_id, cmd->sta.hlid, cmd->sta.session, 516 wlvif->basic_rate_set, wlvif->rate_set); 517 518 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 519 if (ret < 0) { 520 wl1271_error("failed to initiate cmd role start sta"); 521 goto err_hlid; 522 } 523 524 wlvif->sta.role_chan_type = wlvif->channel_type; 525 goto out_free; 526 527err_hlid: 528 /* clear links on error. */ 529 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); 530 531out_free: 532 kfree(cmd); 533 534out: 535 return ret; 536} 537 538/* use this function to stop ibss as well */ 539int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) 540{ 541 struct wl12xx_cmd_role_stop *cmd; 542 int ret; 543 544 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)) 545 return -EINVAL; 546 547 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 548 if (!cmd) { 549 ret = -ENOMEM; 550 goto out; 551 } 552 553 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id); 554 555 cmd->role_id = wlvif->role_id; 556 cmd->disc_type = DISCONNECT_IMMEDIATE; 557 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 558 559 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); 560 if (ret < 0) { 561 wl1271_error("failed to initiate cmd role stop sta"); 562 goto out_free; 563 } 564 565 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); 566 567out_free: 568 kfree(cmd); 569 570out: 571 return ret; 572} 573 574int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) 575{ 576 struct wl12xx_cmd_role_start *cmd; 577 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 578 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 579 u32 supported_rates; 580 int ret; 581 582 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id); 583 584 /* trying to use hidden SSID with an old hostapd version */ 585 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) { 586 wl1271_error("got a null SSID from beacon/bss"); 587 ret = -EINVAL; 588 goto out; 589 } 590 591 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 592 if (!cmd) { 593 ret = -ENOMEM; 594 goto out; 595 } 596 597 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid); 598 if (ret < 0) 599 goto out_free; 600 601 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid); 602 if (ret < 0) 603 goto out_free_global; 604 605 cmd->role_id = wlvif->role_id; 606 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); 607 cmd->ap.bss_index = WL1271_AP_BSS_INDEX; 608 cmd->ap.global_hlid = wlvif->ap.global_hlid; 609 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid; 610 cmd->ap.global_session_id = wl->session_ids[wlvif->ap.global_hlid]; 611 cmd->ap.bcast_session_id = wl->session_ids[wlvif->ap.bcast_hlid]; 612 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); 613 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int); 614 cmd->ap.dtim_interval = bss_conf->dtim_period; 615 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; 616 /* FIXME: Change when adding DFS */ 617 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */ 618 cmd->ap.wmm = wlvif->wmm_enabled; 619 cmd->channel = wlvif->channel; 620 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); 621 622 if (!bss_conf->hidden_ssid) { 623 /* take the SSID from the beacon for backward compatibility */ 624 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; 625 cmd->ap.ssid_len = wlvif->ssid_len; 626 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len); 627 } else { 628 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; 629 cmd->ap.ssid_len = bss_conf->ssid_len; 630 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len); 631 } 632 633 supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | 634 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif); 635 if (wlvif->p2p) 636 supported_rates &= ~CONF_TX_CCK_RATES; 637 638 wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x", 639 supported_rates); 640 641 cmd->ap.local_rates = cpu_to_le32(supported_rates); 642 643 switch (wlvif->band) { 644 case IEEE80211_BAND_2GHZ: 645 cmd->band = WLCORE_BAND_2_4GHZ; 646 break; 647 case IEEE80211_BAND_5GHZ: 648 cmd->band = WLCORE_BAND_5GHZ; 649 break; 650 default: 651 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band); 652 cmd->band = WLCORE_BAND_2_4GHZ; 653 break; 654 } 655 656 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 657 if (ret < 0) { 658 wl1271_error("failed to initiate cmd role start ap"); 659 goto out_free_bcast; 660 } 661 662 goto out_free; 663 664out_free_bcast: 665 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); 666 667out_free_global: 668 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); 669 670out_free: 671 kfree(cmd); 672 673out: 674 return ret; 675} 676 677int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) 678{ 679 struct wl12xx_cmd_role_stop *cmd; 680 int ret; 681 682 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 683 if (!cmd) { 684 ret = -ENOMEM; 685 goto out; 686 } 687 688 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id); 689 690 cmd->role_id = wlvif->role_id; 691 692 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); 693 if (ret < 0) { 694 wl1271_error("failed to initiate cmd role stop ap"); 695 goto out_free; 696 } 697 698 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); 699 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); 700 701out_free: 702 kfree(cmd); 703 704out: 705 return ret; 706} 707 708int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif) 709{ 710 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 711 struct wl12xx_cmd_role_start *cmd; 712 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 713 int ret; 714 715 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 716 if (!cmd) { 717 ret = -ENOMEM; 718 goto out; 719 } 720 721 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id); 722 723 cmd->role_id = wlvif->role_id; 724 if (wlvif->band == IEEE80211_BAND_5GHZ) 725 cmd->band = WLCORE_BAND_5GHZ; 726 cmd->channel = wlvif->channel; 727 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); 728 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int); 729 cmd->ibss.dtim_interval = bss_conf->dtim_period; 730 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; 731 cmd->ibss.ssid_len = wlvif->ssid_len; 732 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len); 733 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN); 734 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); 735 736 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { 737 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); 738 if (ret) 739 goto out_free; 740 } 741 cmd->ibss.hlid = wlvif->sta.hlid; 742 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set); 743 744 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 745 "basic_rate_set: 0x%x, remote_rates: 0x%x", 746 wlvif->role_id, cmd->sta.hlid, cmd->sta.session, 747 wlvif->basic_rate_set, wlvif->rate_set); 748 749 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM", 750 vif->bss_conf.bssid); 751 752 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 753 if (ret < 0) { 754 wl1271_error("failed to initiate cmd role enable"); 755 goto err_hlid; 756 } 757 758 goto out_free; 759 760err_hlid: 761 /* clear links on error. */ 762 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); 763 764out_free: 765 kfree(cmd); 766 767out: 768 return ret; 769} 770 771 772/** 773 * send test command to firmware 774 * 775 * @wl: wl struct 776 * @buf: buffer containing the command, with all headers, must work with dma 777 * @len: length of the buffer 778 * @answer: is answer needed 779 */ 780int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) 781{ 782 int ret; 783 size_t res_len = 0; 784 785 wl1271_debug(DEBUG_CMD, "cmd test"); 786 787 if (answer) 788 res_len = buf_len; 789 790 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); 791 792 if (ret < 0) { 793 wl1271_warning("TEST command failed"); 794 return ret; 795 } 796 797 return ret; 798} 799EXPORT_SYMBOL_GPL(wl1271_cmd_test); 800 801/** 802 * read acx from firmware 803 * 804 * @wl: wl struct 805 * @id: acx id 806 * @buf: buffer for the response, including all headers, must work with dma 807 * @len: length of buf 808 */ 809int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len) 810{ 811 struct acx_header *acx = buf; 812 int ret; 813 814 wl1271_debug(DEBUG_CMD, "cmd interrogate"); 815 816 acx->id = cpu_to_le16(id); 817 818 /* payload length, does not include any headers */ 819 acx->len = cpu_to_le16(len - sizeof(*acx)); 820 821 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len); 822 if (ret < 0) 823 wl1271_error("INTERROGATE command failed"); 824 825 return ret; 826} 827 828/** 829 * write acx value to firmware 830 * 831 * @wl: wl struct 832 * @id: acx id 833 * @buf: buffer containing acx, including all headers, must work with dma 834 * @len: length of buf 835 * @valid_rets: bitmap of valid cmd status codes (i.e. return values). 836 * return the cmd status on success. 837 */ 838int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf, 839 size_t len, unsigned long valid_rets) 840{ 841 struct acx_header *acx = buf; 842 int ret; 843 844 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id); 845 846 acx->id = cpu_to_le16(id); 847 848 /* payload length, does not include any headers */ 849 acx->len = cpu_to_le16(len - sizeof(*acx)); 850 851 ret = wlcore_cmd_send_failsafe(wl, CMD_CONFIGURE, acx, len, 0, 852 valid_rets); 853 if (ret < 0) { 854 wl1271_warning("CONFIGURE command NOK"); 855 return ret; 856 } 857 858 return ret; 859} 860 861/* 862 * wrapper for wlcore_cmd_configure that accepts only success status. 863 * return 0 on success 864 */ 865int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) 866{ 867 int ret = wlcore_cmd_configure_failsafe(wl, id, buf, len, 0); 868 869 if (ret < 0) 870 return ret; 871 return 0; 872} 873EXPORT_SYMBOL_GPL(wl1271_cmd_configure); 874 875int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) 876{ 877 struct cmd_enabledisable_path *cmd; 878 int ret; 879 u16 cmd_rx, cmd_tx; 880 881 wl1271_debug(DEBUG_CMD, "cmd data path"); 882 883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 884 if (!cmd) { 885 ret = -ENOMEM; 886 goto out; 887 } 888 889 /* the channel here is only used for calibration, so hardcoded to 1 */ 890 cmd->channel = 1; 891 892 if (enable) { 893 cmd_rx = CMD_ENABLE_RX; 894 cmd_tx = CMD_ENABLE_TX; 895 } else { 896 cmd_rx = CMD_DISABLE_RX; 897 cmd_tx = CMD_DISABLE_TX; 898 } 899 900 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); 901 if (ret < 0) { 902 wl1271_error("rx %s cmd for channel %d failed", 903 enable ? "start" : "stop", cmd->channel); 904 goto out; 905 } 906 907 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", 908 enable ? "start" : "stop", cmd->channel); 909 910 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); 911 if (ret < 0) { 912 wl1271_error("tx %s cmd for channel %d failed", 913 enable ? "start" : "stop", cmd->channel); 914 goto out; 915 } 916 917 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", 918 enable ? "start" : "stop", cmd->channel); 919 920out: 921 kfree(cmd); 922 return ret; 923} 924EXPORT_SYMBOL_GPL(wl1271_cmd_data_path); 925 926int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, 927 u8 ps_mode, u16 auto_ps_timeout) 928{ 929 struct wl1271_cmd_ps_params *ps_params = NULL; 930 int ret = 0; 931 932 wl1271_debug(DEBUG_CMD, "cmd set ps mode"); 933 934 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); 935 if (!ps_params) { 936 ret = -ENOMEM; 937 goto out; 938 } 939 940 ps_params->role_id = wlvif->role_id; 941 ps_params->ps_mode = ps_mode; 942 ps_params->auto_ps_timeout = auto_ps_timeout; 943 944 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 945 sizeof(*ps_params), 0); 946 if (ret < 0) { 947 wl1271_error("cmd set_ps_mode failed"); 948 goto out; 949 } 950 951out: 952 kfree(ps_params); 953 return ret; 954} 955 956int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id, 957 u16 template_id, void *buf, size_t buf_len, 958 int index, u32 rates) 959{ 960 struct wl1271_cmd_template_set *cmd; 961 int ret = 0; 962 963 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)", 964 template_id, role_id); 965 966 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); 967 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); 968 969 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 970 if (!cmd) { 971 ret = -ENOMEM; 972 goto out; 973 } 974 975 /* during initialization wlvif is NULL */ 976 cmd->role_id = role_id; 977 cmd->len = cpu_to_le16(buf_len); 978 cmd->template_type = template_id; 979 cmd->enabled_rates = cpu_to_le32(rates); 980 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; 981 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; 982 cmd->index = index; 983 984 if (buf) 985 memcpy(cmd->template_data, buf, buf_len); 986 987 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); 988 if (ret < 0) { 989 wl1271_warning("cmd set_template failed: %d", ret); 990 goto out_free; 991 } 992 993out_free: 994 kfree(cmd); 995 996out: 997 return ret; 998} 999 1000int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1001{ 1002 struct sk_buff *skb = NULL; 1003 int size; 1004 void *ptr; 1005 int ret = -ENOMEM; 1006 1007 1008 if (wlvif->bss_type == BSS_TYPE_IBSS) { 1009 size = sizeof(struct wl12xx_null_data_template); 1010 ptr = NULL; 1011 } else { 1012 skb = ieee80211_nullfunc_get(wl->hw, 1013 wl12xx_wlvif_to_vif(wlvif)); 1014 if (!skb) 1015 goto out; 1016 size = skb->len; 1017 ptr = skb->data; 1018 } 1019 1020 ret = wl1271_cmd_template_set(wl, wlvif->role_id, 1021 CMD_TEMPL_NULL_DATA, ptr, size, 0, 1022 wlvif->basic_rate); 1023 1024out: 1025 dev_kfree_skb(skb); 1026 if (ret) 1027 wl1271_warning("cmd buld null data failed %d", ret); 1028 1029 return ret; 1030 1031} 1032 1033int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl, 1034 struct wl12xx_vif *wlvif) 1035{ 1036 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1037 struct sk_buff *skb = NULL; 1038 int ret = -ENOMEM; 1039 1040 skb = ieee80211_nullfunc_get(wl->hw, vif); 1041 if (!skb) 1042 goto out; 1043 1044 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV, 1045 skb->data, skb->len, 1046 wlvif->sta.klv_template_id, 1047 wlvif->basic_rate); 1048 1049out: 1050 dev_kfree_skb(skb); 1051 if (ret) 1052 wl1271_warning("cmd build klv null data failed %d", ret); 1053 1054 return ret; 1055 1056} 1057 1058int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1059 u16 aid) 1060{ 1061 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1062 struct sk_buff *skb; 1063 int ret = 0; 1064 1065 skb = ieee80211_pspoll_get(wl->hw, vif); 1066 if (!skb) 1067 goto out; 1068 1069 ret = wl1271_cmd_template_set(wl, wlvif->role_id, 1070 CMD_TEMPL_PS_POLL, skb->data, 1071 skb->len, 0, wlvif->basic_rate_set); 1072 1073out: 1074 dev_kfree_skb(skb); 1075 return ret; 1076} 1077 1078int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1079 u8 role_id, u8 band, 1080 const u8 *ssid, size_t ssid_len, 1081 const u8 *ie, size_t ie_len, bool sched_scan) 1082{ 1083 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1084 struct sk_buff *skb; 1085 int ret; 1086 u32 rate; 1087 u16 template_id_2_4 = wl->scan_templ_id_2_4; 1088 u16 template_id_5 = wl->scan_templ_id_5; 1089 1090 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len, 1091 ie, ie_len); 1092 if (!skb) { 1093 ret = -ENOMEM; 1094 goto out; 1095 } 1096 1097 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); 1098 1099 if (sched_scan && 1100 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) { 1101 template_id_2_4 = wl->sched_scan_templ_id_2_4; 1102 template_id_5 = wl->sched_scan_templ_id_5; 1103 } 1104 1105 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]); 1106 if (band == IEEE80211_BAND_2GHZ) 1107 ret = wl1271_cmd_template_set(wl, role_id, 1108 template_id_2_4, 1109 skb->data, skb->len, 0, rate); 1110 else 1111 ret = wl1271_cmd_template_set(wl, role_id, 1112 template_id_5, 1113 skb->data, skb->len, 0, rate); 1114 1115out: 1116 dev_kfree_skb(skb); 1117 return ret; 1118} 1119EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req); 1120 1121struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, 1122 struct wl12xx_vif *wlvif, 1123 struct sk_buff *skb) 1124{ 1125 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1126 int ret; 1127 u32 rate; 1128 1129 if (!skb) 1130 skb = ieee80211_ap_probereq_get(wl->hw, vif); 1131 if (!skb) 1132 goto out; 1133 1134 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); 1135 1136 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]); 1137 if (wlvif->band == IEEE80211_BAND_2GHZ) 1138 ret = wl1271_cmd_template_set(wl, wlvif->role_id, 1139 CMD_TEMPL_CFG_PROBE_REQ_2_4, 1140 skb->data, skb->len, 0, rate); 1141 else 1142 ret = wl1271_cmd_template_set(wl, wlvif->role_id, 1143 CMD_TEMPL_CFG_PROBE_REQ_5, 1144 skb->data, skb->len, 0, rate); 1145 1146 if (ret < 0) 1147 wl1271_error("Unable to set ap probe request template."); 1148 1149out: 1150 return skb; 1151} 1152 1153int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1154{ 1155 int ret, extra = 0; 1156 u16 fc; 1157 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1158 struct sk_buff *skb; 1159 struct wl12xx_arp_rsp_template *tmpl; 1160 struct ieee80211_hdr_3addr *hdr; 1161 struct arphdr *arp_hdr; 1162 1163 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) + 1164 WL1271_EXTRA_SPACE_MAX); 1165 if (!skb) { 1166 wl1271_error("failed to allocate buffer for arp rsp template"); 1167 return -ENOMEM; 1168 } 1169 1170 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX); 1171 1172 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl)); 1173 memset(tmpl, 0, sizeof(*tmpl)); 1174 1175 /* llc layer */ 1176 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header)); 1177 tmpl->llc_type = cpu_to_be16(ETH_P_ARP); 1178 1179 /* arp header */ 1180 arp_hdr = &tmpl->arp_hdr; 1181 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); 1182 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); 1183 arp_hdr->ar_hln = ETH_ALEN; 1184 arp_hdr->ar_pln = 4; 1185 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); 1186 1187 /* arp payload */ 1188 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN); 1189 tmpl->sender_ip = wlvif->ip_addr; 1190 1191 /* encryption space */ 1192 switch (wlvif->encryption_type) { 1193 case KEY_TKIP: 1194 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) 1195 extra = WL1271_EXTRA_SPACE_TKIP; 1196 break; 1197 case KEY_AES: 1198 extra = WL1271_EXTRA_SPACE_AES; 1199 break; 1200 case KEY_NONE: 1201 case KEY_WEP: 1202 case KEY_GEM: 1203 extra = 0; 1204 break; 1205 default: 1206 wl1271_warning("Unknown encryption type: %d", 1207 wlvif->encryption_type); 1208 ret = -EINVAL; 1209 goto out; 1210 } 1211 1212 if (extra) { 1213 u8 *space = skb_push(skb, extra); 1214 memset(space, 0, extra); 1215 } 1216 1217 /* QoS header - BE */ 1218 if (wlvif->sta.qos) 1219 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16)); 1220 1221 /* mac80211 header */ 1222 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr)); 1223 memset(hdr, 0, sizeof(*hdr)); 1224 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS; 1225 if (wlvif->sta.qos) 1226 fc |= IEEE80211_STYPE_QOS_DATA; 1227 else 1228 fc |= IEEE80211_STYPE_DATA; 1229 if (wlvif->encryption_type != KEY_NONE) 1230 fc |= IEEE80211_FCTL_PROTECTED; 1231 1232 hdr->frame_control = cpu_to_le16(fc); 1233 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN); 1234 memcpy(hdr->addr2, vif->addr, ETH_ALEN); 1235 memset(hdr->addr3, 0xff, ETH_ALEN); 1236 1237 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP, 1238 skb->data, skb->len, 0, 1239 wlvif->basic_rate); 1240out: 1241 dev_kfree_skb(skb); 1242 return ret; 1243} 1244 1245int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif) 1246{ 1247 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); 1248 struct ieee80211_qos_hdr template; 1249 1250 memset(&template, 0, sizeof(template)); 1251 1252 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN); 1253 memcpy(template.addr2, vif->addr, ETH_ALEN); 1254 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN); 1255 1256 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 1257 IEEE80211_STYPE_QOS_NULLFUNC | 1258 IEEE80211_FCTL_TODS); 1259 1260 /* FIXME: not sure what priority to use here */ 1261 template.qos_ctrl = cpu_to_le16(0); 1262 1263 return wl1271_cmd_template_set(wl, wlvif->role_id, 1264 CMD_TEMPL_QOS_NULL_DATA, &template, 1265 sizeof(template), 0, 1266 wlvif->basic_rate); 1267} 1268 1269int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) 1270{ 1271 struct wl1271_cmd_set_keys *cmd; 1272 int ret = 0; 1273 1274 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); 1275 1276 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1277 if (!cmd) { 1278 ret = -ENOMEM; 1279 goto out; 1280 } 1281 1282 cmd->hlid = hlid; 1283 cmd->key_id = id; 1284 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; 1285 cmd->key_action = cpu_to_le16(KEY_SET_ID); 1286 cmd->key_type = KEY_WEP; 1287 1288 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); 1289 if (ret < 0) { 1290 wl1271_warning("cmd set_default_wep_key failed: %d", ret); 1291 goto out; 1292 } 1293 1294out: 1295 kfree(cmd); 1296 1297 return ret; 1298} 1299 1300int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1301 u16 action, u8 id, u8 key_type, 1302 u8 key_size, const u8 *key, const u8 *addr, 1303 u32 tx_seq_32, u16 tx_seq_16) 1304{ 1305 struct wl1271_cmd_set_keys *cmd; 1306 int ret = 0; 1307 1308 /* hlid might have already been deleted */ 1309 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) 1310 return 0; 1311 1312 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1313 if (!cmd) { 1314 ret = -ENOMEM; 1315 goto out; 1316 } 1317 1318 cmd->hlid = wlvif->sta.hlid; 1319 1320 if (key_type == KEY_WEP) 1321 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; 1322 else if (is_broadcast_ether_addr(addr)) 1323 cmd->lid_key_type = BROADCAST_LID_TYPE; 1324 else 1325 cmd->lid_key_type = UNICAST_LID_TYPE; 1326 1327 cmd->key_action = cpu_to_le16(action); 1328 cmd->key_size = key_size; 1329 cmd->key_type = key_type; 1330 1331 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); 1332 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); 1333 1334 cmd->key_id = id; 1335 1336 if (key_type == KEY_TKIP) { 1337 /* 1338 * We get the key in the following form: 1339 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) 1340 * but the target is expecting: 1341 * TKIP - RX MIC - TX MIC 1342 */ 1343 memcpy(cmd->key, key, 16); 1344 memcpy(cmd->key + 16, key + 24, 8); 1345 memcpy(cmd->key + 24, key + 16, 8); 1346 1347 } else { 1348 memcpy(cmd->key, key, key_size); 1349 } 1350 1351 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); 1352 1353 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); 1354 if (ret < 0) { 1355 wl1271_warning("could not set keys"); 1356 goto out; 1357 } 1358 1359out: 1360 kfree(cmd); 1361 1362 return ret; 1363} 1364 1365/* 1366 * TODO: merge with sta/ibss into 1 set_key function. 1367 * note there are slight diffs 1368 */ 1369int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1370 u16 action, u8 id, u8 key_type, 1371 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 1372 u16 tx_seq_16) 1373{ 1374 struct wl1271_cmd_set_keys *cmd; 1375 int ret = 0; 1376 u8 lid_type; 1377 1378 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1379 if (!cmd) 1380 return -ENOMEM; 1381 1382 if (hlid == wlvif->ap.bcast_hlid) { 1383 if (key_type == KEY_WEP) 1384 lid_type = WEP_DEFAULT_LID_TYPE; 1385 else 1386 lid_type = BROADCAST_LID_TYPE; 1387 } else { 1388 lid_type = UNICAST_LID_TYPE; 1389 } 1390 1391 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" 1392 " hlid: %d", (int)action, (int)id, (int)lid_type, 1393 (int)key_type, (int)hlid); 1394 1395 cmd->lid_key_type = lid_type; 1396 cmd->hlid = hlid; 1397 cmd->key_action = cpu_to_le16(action); 1398 cmd->key_size = key_size; 1399 cmd->key_type = key_type; 1400 cmd->key_id = id; 1401 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); 1402 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); 1403 1404 if (key_type == KEY_TKIP) { 1405 /* 1406 * We get the key in the following form: 1407 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) 1408 * but the target is expecting: 1409 * TKIP - RX MIC - TX MIC 1410 */ 1411 memcpy(cmd->key, key, 16); 1412 memcpy(cmd->key + 16, key + 24, 8); 1413 memcpy(cmd->key + 24, key + 16, 8); 1414 } else { 1415 memcpy(cmd->key, key, key_size); 1416 } 1417 1418 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); 1419 1420 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); 1421 if (ret < 0) { 1422 wl1271_warning("could not set ap keys"); 1423 goto out; 1424 } 1425 1426out: 1427 kfree(cmd); 1428 return ret; 1429} 1430 1431int wl12xx_cmd_set_peer_state(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1432 u8 hlid) 1433{ 1434 struct wl12xx_cmd_set_peer_state *cmd; 1435 int ret = 0; 1436 1437 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid); 1438 1439 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1440 if (!cmd) { 1441 ret = -ENOMEM; 1442 goto out; 1443 } 1444 1445 cmd->hlid = hlid; 1446 cmd->state = WL1271_CMD_STA_STATE_CONNECTED; 1447 1448 /* wmm param is valid only for station role */ 1449 if (wlvif->bss_type == BSS_TYPE_STA_BSS) 1450 cmd->wmm = wlvif->wmm_enabled; 1451 1452 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0); 1453 if (ret < 0) { 1454 wl1271_error("failed to send set peer state command"); 1455 goto out_free; 1456 } 1457 1458out_free: 1459 kfree(cmd); 1460 1461out: 1462 return ret; 1463} 1464 1465int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1466 struct ieee80211_sta *sta, u8 hlid) 1467{ 1468 struct wl12xx_cmd_add_peer *cmd; 1469 int i, ret; 1470 u32 sta_rates; 1471 1472 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid); 1473 1474 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1475 if (!cmd) { 1476 ret = -ENOMEM; 1477 goto out; 1478 } 1479 1480 memcpy(cmd->addr, sta->addr, ETH_ALEN); 1481 cmd->bss_index = WL1271_AP_BSS_INDEX; 1482 cmd->aid = sta->aid; 1483 cmd->hlid = hlid; 1484 cmd->sp_len = sta->max_sp; 1485 cmd->wmm = sta->wme ? 1 : 0; 1486 cmd->session_id = wl->session_ids[hlid]; 1487 1488 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++) 1489 if (sta->wme && (sta->uapsd_queues & BIT(i))) 1490 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = 1491 WL1271_PSD_UPSD_TRIGGER; 1492 else 1493 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = 1494 WL1271_PSD_LEGACY; 1495 1496 1497 sta_rates = sta->supp_rates[wlvif->band]; 1498 if (sta->ht_cap.ht_supported) 1499 sta_rates |= 1500 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) | 1501 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET); 1502 1503 cmd->supported_rates = 1504 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, 1505 wlvif->band)); 1506 1507 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", 1508 cmd->supported_rates, sta->uapsd_queues); 1509 1510 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0); 1511 if (ret < 0) { 1512 wl1271_error("failed to initiate cmd add peer"); 1513 goto out_free; 1514 } 1515 1516out_free: 1517 kfree(cmd); 1518 1519out: 1520 return ret; 1521} 1522 1523int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid) 1524{ 1525 struct wl12xx_cmd_remove_peer *cmd; 1526 int ret; 1527 bool timeout = false; 1528 1529 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid); 1530 1531 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1532 if (!cmd) { 1533 ret = -ENOMEM; 1534 goto out; 1535 } 1536 1537 cmd->hlid = hlid; 1538 /* We never send a deauth, mac80211 is in charge of this */ 1539 cmd->reason_opcode = 0; 1540 cmd->send_deauth_flag = 0; 1541 1542 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0); 1543 if (ret < 0) { 1544 wl1271_error("failed to initiate cmd remove peer"); 1545 goto out_free; 1546 } 1547 1548 ret = wl->ops->wait_for_event(wl, 1549 WLCORE_EVENT_PEER_REMOVE_COMPLETE, 1550 &timeout); 1551 1552 /* 1553 * We are ok with a timeout here. The event is sometimes not sent 1554 * due to a firmware bug. In case of another error (like SDIO timeout) 1555 * queue a recovery. 1556 */ 1557 if (ret) 1558 wl12xx_queue_recovery_work(wl); 1559 1560out_free: 1561 kfree(cmd); 1562 1563out: 1564 return ret; 1565} 1566 1567static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band, u16 ch) 1568{ 1569 int idx = -1; 1570 1571 switch (band) { 1572 case IEEE80211_BAND_5GHZ: 1573 if (ch >= 8 && ch <= 16) 1574 idx = ((ch-8)/4 + 18); 1575 else if (ch >= 34 && ch <= 64) 1576 idx = ((ch-34)/2 + 3 + 18); 1577 else if (ch >= 100 && ch <= 140) 1578 idx = ((ch-100)/4 + 15 + 18); 1579 else if (ch >= 149 && ch <= 165) 1580 idx = ((ch-149)/4 + 26 + 18); 1581 else 1582 idx = -1; 1583 break; 1584 case IEEE80211_BAND_2GHZ: 1585 if (ch >= 1 && ch <= 14) 1586 idx = ch - 1; 1587 else 1588 idx = -1; 1589 break; 1590 default: 1591 wl1271_error("get reg conf ch idx - unknown band: %d", 1592 (int)band); 1593 } 1594 1595 return idx; 1596} 1597 1598void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, 1599 enum ieee80211_band band) 1600{ 1601 int ch_bit_idx = 0; 1602 1603 if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) 1604 return; 1605 1606 ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel); 1607 1608 if (ch_bit_idx > 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) 1609 set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending); 1610} 1611 1612int wlcore_cmd_regdomain_config_locked(struct wl1271 *wl) 1613{ 1614 struct wl12xx_cmd_regdomain_dfs_config *cmd = NULL; 1615 int ret = 0, i, b, ch_bit_idx; 1616 struct ieee80211_channel *channel; 1617 u32 tmp_ch_bitmap[2]; 1618 u16 ch; 1619 struct wiphy *wiphy = wl->hw->wiphy; 1620 struct ieee80211_supported_band *band; 1621 bool timeout = false; 1622 1623 if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) 1624 return 0; 1625 1626 wl1271_debug(DEBUG_CMD, "cmd reg domain config"); 1627 1628 memset(tmp_ch_bitmap, 0, sizeof(tmp_ch_bitmap)); 1629 1630 for (b = IEEE80211_BAND_2GHZ; b <= IEEE80211_BAND_5GHZ; b++) { 1631 band = wiphy->bands[b]; 1632 for (i = 0; i < band->n_channels; i++) { 1633 channel = &band->channels[i]; 1634 ch = channel->hw_value; 1635 1636 if (channel->flags & (IEEE80211_CHAN_DISABLED | 1637 IEEE80211_CHAN_RADAR | 1638 IEEE80211_CHAN_PASSIVE_SCAN)) 1639 continue; 1640 1641 ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch); 1642 if (ch_bit_idx < 0) 1643 continue; 1644 1645 set_bit(ch_bit_idx, (long *)tmp_ch_bitmap); 1646 } 1647 } 1648 1649 tmp_ch_bitmap[0] |= wl->reg_ch_conf_pending[0]; 1650 tmp_ch_bitmap[1] |= wl->reg_ch_conf_pending[1]; 1651 1652 if (!memcmp(tmp_ch_bitmap, wl->reg_ch_conf_last, sizeof(tmp_ch_bitmap))) 1653 goto out; 1654 1655 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1656 if (!cmd) { 1657 ret = -ENOMEM; 1658 goto out; 1659 } 1660 1661 cmd->ch_bit_map1 = cpu_to_le32(tmp_ch_bitmap[0]); 1662 cmd->ch_bit_map2 = cpu_to_le32(tmp_ch_bitmap[1]); 1663 1664 wl1271_debug(DEBUG_CMD, 1665 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x", 1666 cmd->ch_bit_map1, cmd->ch_bit_map2); 1667 1668 ret = wl1271_cmd_send(wl, CMD_DFS_CHANNEL_CONFIG, cmd, sizeof(*cmd), 0); 1669 if (ret < 0) { 1670 wl1271_error("failed to send reg domain dfs config"); 1671 goto out; 1672 } 1673 1674 ret = wl->ops->wait_for_event(wl, 1675 WLCORE_EVENT_DFS_CONFIG_COMPLETE, 1676 &timeout); 1677 if (ret < 0 || timeout) { 1678 wl1271_error("reg domain conf %serror", 1679 timeout ? "completion " : ""); 1680 ret = timeout ? -ETIMEDOUT : ret; 1681 goto out; 1682 } 1683 1684 memcpy(wl->reg_ch_conf_last, tmp_ch_bitmap, sizeof(tmp_ch_bitmap)); 1685 memset(wl->reg_ch_conf_pending, 0, sizeof(wl->reg_ch_conf_pending)); 1686 1687out: 1688 kfree(cmd); 1689 return ret; 1690} 1691 1692int wl12xx_cmd_config_fwlog(struct wl1271 *wl) 1693{ 1694 struct wl12xx_cmd_config_fwlog *cmd; 1695 int ret = 0; 1696 1697 wl1271_debug(DEBUG_CMD, "cmd config firmware logger"); 1698 1699 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1700 if (!cmd) { 1701 ret = -ENOMEM; 1702 goto out; 1703 } 1704 1705 cmd->logger_mode = wl->conf.fwlog.mode; 1706 cmd->log_severity = wl->conf.fwlog.severity; 1707 cmd->timestamp = wl->conf.fwlog.timestamp; 1708 cmd->output = wl->conf.fwlog.output; 1709 cmd->threshold = wl->conf.fwlog.threshold; 1710 1711 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0); 1712 if (ret < 0) { 1713 wl1271_error("failed to send config firmware logger command"); 1714 goto out_free; 1715 } 1716 1717out_free: 1718 kfree(cmd); 1719 1720out: 1721 return ret; 1722} 1723 1724int wl12xx_cmd_start_fwlog(struct wl1271 *wl) 1725{ 1726 struct wl12xx_cmd_start_fwlog *cmd; 1727 int ret = 0; 1728 1729 wl1271_debug(DEBUG_CMD, "cmd start firmware logger"); 1730 1731 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1732 if (!cmd) { 1733 ret = -ENOMEM; 1734 goto out; 1735 } 1736 1737 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0); 1738 if (ret < 0) { 1739 wl1271_error("failed to send start firmware logger command"); 1740 goto out_free; 1741 } 1742 1743out_free: 1744 kfree(cmd); 1745 1746out: 1747 return ret; 1748} 1749 1750int wl12xx_cmd_stop_fwlog(struct wl1271 *wl) 1751{ 1752 struct wl12xx_cmd_stop_fwlog *cmd; 1753 int ret = 0; 1754 1755 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger"); 1756 1757 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1758 if (!cmd) { 1759 ret = -ENOMEM; 1760 goto out; 1761 } 1762 1763 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0); 1764 if (ret < 0) { 1765 wl1271_error("failed to send stop firmware logger command"); 1766 goto out_free; 1767 } 1768 1769out_free: 1770 kfree(cmd); 1771 1772out: 1773 return ret; 1774} 1775 1776static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1777 u8 role_id, enum ieee80211_band band, u8 channel) 1778{ 1779 struct wl12xx_cmd_roc *cmd; 1780 int ret = 0; 1781 1782 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", channel, role_id); 1783 1784 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) 1785 return -EINVAL; 1786 1787 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1788 if (!cmd) { 1789 ret = -ENOMEM; 1790 goto out; 1791 } 1792 1793 cmd->role_id = role_id; 1794 cmd->channel = channel; 1795 switch (band) { 1796 case IEEE80211_BAND_2GHZ: 1797 cmd->band = WLCORE_BAND_2_4GHZ; 1798 break; 1799 case IEEE80211_BAND_5GHZ: 1800 cmd->band = WLCORE_BAND_5GHZ; 1801 break; 1802 default: 1803 wl1271_error("roc - unknown band: %d", (int)wlvif->band); 1804 ret = -EINVAL; 1805 goto out_free; 1806 } 1807 1808 1809 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0); 1810 if (ret < 0) { 1811 wl1271_error("failed to send ROC command"); 1812 goto out_free; 1813 } 1814 1815out_free: 1816 kfree(cmd); 1817 1818out: 1819 return ret; 1820} 1821 1822static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id) 1823{ 1824 struct wl12xx_cmd_croc *cmd; 1825 int ret = 0; 1826 1827 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id); 1828 1829 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1830 if (!cmd) { 1831 ret = -ENOMEM; 1832 goto out; 1833 } 1834 cmd->role_id = role_id; 1835 1836 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd, 1837 sizeof(*cmd), 0); 1838 if (ret < 0) { 1839 wl1271_error("failed to send ROC command"); 1840 goto out_free; 1841 } 1842 1843out_free: 1844 kfree(cmd); 1845 1846out: 1847 return ret; 1848} 1849 1850int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id, 1851 enum ieee80211_band band, u8 channel) 1852{ 1853 int ret = 0; 1854 1855 if (WARN_ON(test_bit(role_id, wl->roc_map))) 1856 return 0; 1857 1858 ret = wl12xx_cmd_roc(wl, wlvif, role_id, band, channel); 1859 if (ret < 0) 1860 goto out; 1861 1862 __set_bit(role_id, wl->roc_map); 1863out: 1864 return ret; 1865} 1866 1867int wl12xx_croc(struct wl1271 *wl, u8 role_id) 1868{ 1869 int ret = 0; 1870 1871 if (WARN_ON(!test_bit(role_id, wl->roc_map))) 1872 return 0; 1873 1874 ret = wl12xx_cmd_croc(wl, role_id); 1875 if (ret < 0) 1876 goto out; 1877 1878 __clear_bit(role_id, wl->roc_map); 1879 1880 /* 1881 * Rearm the tx watchdog when removing the last ROC. This prevents 1882 * recoveries due to just finished ROCs - when Tx hasn't yet had 1883 * a chance to get out. 1884 */ 1885 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) 1886 wl12xx_rearm_tx_watchdog_locked(wl); 1887out: 1888 return ret; 1889} 1890 1891int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1892{ 1893 struct wl12xx_cmd_stop_channel_switch *cmd; 1894 int ret; 1895 1896 wl1271_debug(DEBUG_ACX, "cmd stop channel switch"); 1897 1898 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1899 if (!cmd) { 1900 ret = -ENOMEM; 1901 goto out; 1902 } 1903 1904 cmd->role_id = wlvif->role_id; 1905 1906 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0); 1907 if (ret < 0) { 1908 wl1271_error("failed to stop channel switch command"); 1909 goto out_free; 1910 } 1911 1912out_free: 1913 kfree(cmd); 1914 1915out: 1916 return ret; 1917} 1918 1919/* start dev role and roc on its channel */ 1920int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1921 enum ieee80211_band band, int channel) 1922{ 1923 int ret; 1924 1925 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || 1926 wlvif->bss_type == BSS_TYPE_IBSS))) 1927 return -EINVAL; 1928 1929 ret = wl12xx_cmd_role_enable(wl, 1930 wl12xx_wlvif_to_vif(wlvif)->addr, 1931 WL1271_ROLE_DEVICE, 1932 &wlvif->dev_role_id); 1933 if (ret < 0) 1934 goto out; 1935 1936 ret = wl12xx_cmd_role_start_dev(wl, wlvif, band, channel); 1937 if (ret < 0) 1938 goto out_disable; 1939 1940 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id, band, channel); 1941 if (ret < 0) 1942 goto out_stop; 1943 1944 return 0; 1945 1946out_stop: 1947 wl12xx_cmd_role_stop_dev(wl, wlvif); 1948out_disable: 1949 wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); 1950out: 1951 return ret; 1952} 1953 1954/* croc dev hlid, and stop the role */ 1955int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1956{ 1957 int ret; 1958 1959 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || 1960 wlvif->bss_type == BSS_TYPE_IBSS))) 1961 return -EINVAL; 1962 1963 /* flush all pending packets */ 1964 ret = wlcore_tx_work_locked(wl); 1965 if (ret < 0) 1966 goto out; 1967 1968 if (test_bit(wlvif->dev_role_id, wl->roc_map)) { 1969 ret = wl12xx_croc(wl, wlvif->dev_role_id); 1970 if (ret < 0) 1971 goto out; 1972 } 1973 1974 ret = wl12xx_cmd_role_stop_dev(wl, wlvif); 1975 if (ret < 0) 1976 goto out; 1977 1978 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); 1979 if (ret < 0) 1980 goto out; 1981 1982out: 1983 return ret; 1984} 1985