aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2014-06-02 14:17:35 -0400
committerDavid S. Miller <davem@davemloft.net>2014-06-02 14:17:35 -0400
commit31595de219e8a1a2ed7aeccbe4f18e44f2d2db00 (patch)
tree7fde4fc831867b18e384953a18f50919ccc9245f
parent73f156a6e8c1074ac6327e0abd1169e95eb66463 (diff)
parentfcb2c0d6cf75750e2912b09a3d0a782c90e2b1a0 (diff)
Merge branch 'for-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next
John W. Linville says: ==================== pull request: wireless-next 2014-06-02 Please pull this remaining batch of updates intended for the 3.16 stream... For the mac80211 bits, Johannes says: "The remainder for -next right now is mostly fixes, and a handful of small new things like some CSA infrastructure, the regdb script mW/dBm conversion change and sending wiphy notifications." For the bluetooth bits, Gustavo says: "Some more patches for 3.16. There is nothing really special here, just a bunch of clean ups, fixes plus some small improvements. Please pull." For the nfc bits, Samuel says: "We have: - Felica (Type3) tags support for trf7970a - Type 4b tags support for port100 - st21nfca DTS typo fix - A few sparse warning fixes" For the atheros bits, Kalle says: "Ben added support for setting antenna configurations. Michal improved warm reset so that we would not need to fall back to cold reset that often, an issue where ath10k stripped protected flag while in monitor mode and made module initialisation asynchronous to fix the problems with firmware loading when the driver is linked to the kernel. Luca removed unused channel_switch_beacon callbacks both from ath9k and ath10k. Marek fixed Protected Management Frames (PMF) when using Action Frames. Also we had other small fixes everywhere in the driver." Along with that, there are a handful of updates to a variety of drivers. This includes updates to at76c50x-usb, ath9k, b43, brcmfmac, mwifiex, rsi, rtlwifi, and wil6210. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/devicetree/bindings/net/nfc/st21nfca.txt2
-rw-r--r--drivers/bluetooth/btusb.c155
-rw-r--r--drivers/net/wireless/at76c50x-usb.c127
-rw-r--r--drivers/net/wireless/at76c50x-usb.h25
-rw-r--r--drivers/net/wireless/ath/ath10k/bmi.h3
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.c27
-rw-r--r--drivers/net/wireless/ath/ath10k/ce.h2
-rw-r--r--drivers/net/wireless/ath/ath10k/core.c277
-rw-r--r--drivers/net/wireless/ath/ath10k/core.h8
-rw-r--r--drivers/net/wireless/ath/ath10k/htc.c6
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.c42
-rw-r--r--drivers/net/wireless/ath/ath10k/htt.h18
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_rx.c92
-rw-r--r--drivers/net/wireless/ath/ath10k/htt_tx.c8
-rw-r--r--drivers/net/wireless/ath/ath10k/mac.c212
-rw-r--r--drivers/net/wireless/ath/ath10k/pci.c103
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.c26
-rw-r--r--drivers/net/wireless/ath/ath10k/wmi.h6
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/dfs.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/dfs_debug.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c25
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c27
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c24
-rw-r--r--drivers/net/wireless/ath/wcn36xx/smd.c3
-rw-r--r--drivers/net/wireless/ath/wil6210/cfg80211.c1
-rw-r--r--drivers/net/wireless/ath/wil6210/debugfs.c4
-rw-r--r--drivers/net/wireless/ath/wil6210/main.c35
-rw-r--r--drivers/net/wireless/ath/wil6210/netdev.c14
-rw-r--r--drivers/net/wireless/ath/wil6210/pcie_bus.c2
-rw-r--r--drivers/net/wireless/ath/wil6210/rx_reorder.c9
-rw-r--r--drivers/net/wireless/ath/wil6210/txrx.c28
-rw-r--r--drivers/net/wireless/ath/wil6210/wil6210.h6
-rw-r--r--drivers/net/wireless/ath/wil6210/wmi.c25
-rw-r--r--drivers/net/wireless/b43/main.c7
-rw-r--r--drivers/net/wireless/b43/phy_common.c5
-rw-r--r--drivers/net/wireless/b43/phy_common.h3
-rw-r--r--drivers/net/wireless/b43/phy_n.c17
-rw-r--r--drivers/net/wireless/b43/phy_n.h1
-rw-r--r--drivers/net/wireless/b43/tables_nphy.c80
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/Makefile2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c7
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c283
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/firmware.c (renamed from drivers/net/wireless/brcm80211/brcmfmac/nvram.c)112
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/firmware.h (renamed from drivers/net/wireless/brcm80211/brcmfmac/nvram.h)24
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c269
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c11
-rw-r--r--drivers/net/wireless/brcm80211/brcmutil/d11.c2
-rw-r--r--drivers/net/wireless/mwifiex/fw.h2
-rw-r--r--drivers/net/wireless/mwifiex/main.h2
-rw-r--r--drivers/net/wireless/mwifiex/scan.c29
-rw-r--r--drivers/net/wireless/mwifiex/wmm.c1
-rw-r--r--drivers/net/wireless/rsi/rsi_common.h2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c3
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8723be/trx.c1
-rw-r--r--drivers/nfc/port100.c36
-rw-r--r--drivers/nfc/trf7970a.c13
-rw-r--r--include/linux/ieee80211.h1
-rw-r--r--include/net/bluetooth/hci.h21
-rw-r--r--include/net/bluetooth/hci_core.h11
-rw-r--r--include/net/bluetooth/mgmt.h15
-rw-r--r--include/net/bluetooth/rfcomm.h6
-rw-r--r--include/net/mac80211.h46
-rw-r--r--net/bluetooth/hci_conn.c3
-rw-r--r--net/bluetooth/hci_core.c64
-rw-r--r--net/bluetooth/hci_event.c61
-rw-r--r--net/bluetooth/mgmt.c236
-rw-r--r--net/bluetooth/rfcomm/core.c2
-rw-r--r--net/bluetooth/rfcomm/tty.c20
-rw-r--r--net/bluetooth/smp.c153
-rw-r--r--net/bluetooth/smp.h30
-rw-r--r--net/mac80211/debugfs_netdev.c6
-rw-r--r--net/mac80211/driver-ops.h53
-rw-r--r--net/mac80211/ibss.c1
-rw-r--r--net/mac80211/iface.c2
-rw-r--r--net/mac80211/sta_info.c1
-rw-r--r--net/mac80211/status.c25
-rw-r--r--net/mac80211/trace.h85
-rw-r--r--net/nfc/digital_core.c6
-rw-r--r--net/nfc/digital_dep.c5
-rw-r--r--net/nfc/digital_technology.c2
-rw-r--r--net/nfc/rawsock.c4
-rw-r--r--net/wireless/core.c5
-rw-r--r--net/wireless/genregdb.awk14
-rw-r--r--net/wireless/nl80211.c21
-rw-r--r--net/wireless/nl80211.h3
88 files changed, 2174 insertions, 997 deletions
diff --git a/Documentation/devicetree/bindings/net/nfc/st21nfca.txt b/Documentation/devicetree/bindings/net/nfc/st21nfca.txt
index 4724fe669172..e4faa2e8dfeb 100644
--- a/Documentation/devicetree/bindings/net/nfc/st21nfca.txt
+++ b/Documentation/devicetree/bindings/net/nfc/st21nfca.txt
@@ -1,7 +1,7 @@
1* STMicroelectronics SAS. ST21NFCA NFC Controller 1* STMicroelectronics SAS. ST21NFCA NFC Controller
2 2
3Required properties: 3Required properties:
4- compatible: Should be "st,st21nfca-i2c". 4- compatible: Should be "st,st21nfca_i2c".
5- clock-frequency: I²C work frequency. 5- clock-frequency: I²C work frequency.
6- reg: address on the bus 6- reg: address on the bus
7- interrupt-parent: phandle for the interrupt gpio controller 7- interrupt-parent: phandle for the interrupt gpio controller
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index a7dfbf9a3afb..a1c80b0c7663 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -49,6 +49,7 @@ static struct usb_driver btusb_driver;
49#define BTUSB_WRONG_SCO_MTU 0x40 49#define BTUSB_WRONG_SCO_MTU 0x40
50#define BTUSB_ATH3012 0x80 50#define BTUSB_ATH3012 0x80
51#define BTUSB_INTEL 0x100 51#define BTUSB_INTEL 0x100
52#define BTUSB_BCM_PATCHRAM 0x200
52 53
53static const struct usb_device_id btusb_table[] = { 54static const struct usb_device_id btusb_table[] = {
54 /* Generic Bluetooth USB device */ 55 /* Generic Bluetooth USB device */
@@ -111,7 +112,8 @@ static const struct usb_device_id btusb_table[] = {
111 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) }, 112 { USB_VENDOR_AND_INTERFACE_INFO(0x0489, 0xff, 0x01, 0x01) },
112 113
113 /* Broadcom devices with vendor specific id */ 114 /* Broadcom devices with vendor specific id */
114 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01) }, 115 { USB_VENDOR_AND_INTERFACE_INFO(0x0a5c, 0xff, 0x01, 0x01),
116 .driver_info = BTUSB_BCM_PATCHRAM },
115 117
116 /* Belkin F8065bf - Broadcom based */ 118 /* Belkin F8065bf - Broadcom based */
117 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) }, 119 { USB_VENDOR_AND_INTERFACE_INFO(0x050d, 0xff, 0x01, 0x01) },
@@ -1381,6 +1383,154 @@ exit_mfg_deactivate:
1381 return 0; 1383 return 0;
1382} 1384}
1383 1385
1386static int btusb_setup_bcm_patchram(struct hci_dev *hdev)
1387{
1388 struct btusb_data *data = hci_get_drvdata(hdev);
1389 struct usb_device *udev = data->udev;
1390 char fw_name[64];
1391 const struct firmware *fw;
1392 const u8 *fw_ptr;
1393 size_t fw_size;
1394 const struct hci_command_hdr *cmd;
1395 const u8 *cmd_param;
1396 u16 opcode;
1397 struct sk_buff *skb;
1398 struct hci_rp_read_local_version *ver;
1399 long ret;
1400
1401 snprintf(fw_name, sizeof(fw_name), "brcm/%s-%04x-%04x.hcd",
1402 udev->product ? udev->product : "BCM",
1403 le16_to_cpu(udev->descriptor.idVendor),
1404 le16_to_cpu(udev->descriptor.idProduct));
1405
1406 ret = request_firmware(&fw, fw_name, &hdev->dev);
1407 if (ret < 0) {
1408 BT_INFO("%s: BCM: patch %s not found", hdev->name,
1409 fw_name);
1410 return 0;
1411 }
1412
1413 /* Reset */
1414 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
1415 if (IS_ERR(skb)) {
1416 ret = PTR_ERR(skb);
1417 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
1418 goto done;
1419 }
1420 kfree_skb(skb);
1421
1422 /* Read Local Version Info */
1423 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
1424 HCI_INIT_TIMEOUT);
1425 if (IS_ERR(skb)) {
1426 ret = PTR_ERR(skb);
1427 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
1428 hdev->name, ret);
1429 goto done;
1430 }
1431
1432 if (skb->len != sizeof(*ver)) {
1433 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
1434 hdev->name);
1435 kfree_skb(skb);
1436 ret = -EIO;
1437 goto done;
1438 }
1439
1440 ver = (struct hci_rp_read_local_version *) skb->data;
1441 BT_INFO("%s: BCM: patching hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
1442 "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
1443 ver->lmp_ver, ver->lmp_subver);
1444 kfree_skb(skb);
1445
1446 /* Start Download */
1447 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
1448 if (IS_ERR(skb)) {
1449 ret = PTR_ERR(skb);
1450 BT_ERR("%s: BCM: Download Minidrv command failed (%ld)",
1451 hdev->name, ret);
1452 goto reset_fw;
1453 }
1454 kfree_skb(skb);
1455
1456 /* 50 msec delay after Download Minidrv completes */
1457 msleep(50);
1458
1459 fw_ptr = fw->data;
1460 fw_size = fw->size;
1461
1462 while (fw_size >= sizeof(*cmd)) {
1463 cmd = (struct hci_command_hdr *) fw_ptr;
1464 fw_ptr += sizeof(*cmd);
1465 fw_size -= sizeof(*cmd);
1466
1467 if (fw_size < cmd->plen) {
1468 BT_ERR("%s: BCM: patch %s is corrupted",
1469 hdev->name, fw_name);
1470 ret = -EINVAL;
1471 goto reset_fw;
1472 }
1473
1474 cmd_param = fw_ptr;
1475 fw_ptr += cmd->plen;
1476 fw_size -= cmd->plen;
1477
1478 opcode = le16_to_cpu(cmd->opcode);
1479
1480 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
1481 HCI_INIT_TIMEOUT);
1482 if (IS_ERR(skb)) {
1483 ret = PTR_ERR(skb);
1484 BT_ERR("%s: BCM: patch command %04x failed (%ld)",
1485 hdev->name, opcode, ret);
1486 goto reset_fw;
1487 }
1488 kfree_skb(skb);
1489 }
1490
1491 /* 250 msec delay after Launch Ram completes */
1492 msleep(250);
1493
1494reset_fw:
1495 /* Reset */
1496 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
1497 if (IS_ERR(skb)) {
1498 ret = PTR_ERR(skb);
1499 BT_ERR("%s: HCI_OP_RESET failed (%ld)", hdev->name, ret);
1500 goto done;
1501 }
1502 kfree_skb(skb);
1503
1504 /* Read Local Version Info */
1505 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
1506 HCI_INIT_TIMEOUT);
1507 if (IS_ERR(skb)) {
1508 ret = PTR_ERR(skb);
1509 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION failed (%ld)",
1510 hdev->name, ret);
1511 goto done;
1512 }
1513
1514 if (skb->len != sizeof(*ver)) {
1515 BT_ERR("%s: HCI_OP_READ_LOCAL_VERSION event length mismatch",
1516 hdev->name);
1517 kfree_skb(skb);
1518 ret = -EIO;
1519 goto done;
1520 }
1521
1522 ver = (struct hci_rp_read_local_version *) skb->data;
1523 BT_INFO("%s: BCM: firmware hci_ver=%02x hci_rev=%04x lmp_ver=%02x "
1524 "lmp_subver=%04x", hdev->name, ver->hci_ver, ver->hci_rev,
1525 ver->lmp_ver, ver->lmp_subver);
1526 kfree_skb(skb);
1527
1528done:
1529 release_firmware(fw);
1530
1531 return ret;
1532}
1533
1384static int btusb_probe(struct usb_interface *intf, 1534static int btusb_probe(struct usb_interface *intf,
1385 const struct usb_device_id *id) 1535 const struct usb_device_id *id)
1386{ 1536{
@@ -1486,6 +1636,9 @@ static int btusb_probe(struct usb_interface *intf,
1486 if (id->driver_info & BTUSB_BCM92035) 1636 if (id->driver_info & BTUSB_BCM92035)
1487 hdev->setup = btusb_setup_bcm92035; 1637 hdev->setup = btusb_setup_bcm92035;
1488 1638
1639 if (id->driver_info & BTUSB_BCM_PATCHRAM)
1640 hdev->setup = btusb_setup_bcm_patchram;
1641
1489 if (id->driver_info & BTUSB_INTEL) 1642 if (id->driver_info & BTUSB_INTEL)
1490 hdev->setup = btusb_setup_intel; 1643 hdev->setup = btusb_setup_intel;
1491 1644
diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
index 99b3bfa717d5..10fd12ec85be 100644
--- a/drivers/net/wireless/at76c50x-usb.c
+++ b/drivers/net/wireless/at76c50x-usb.c
@@ -365,15 +365,15 @@ static inline unsigned long at76_get_timeout(struct dfu_status *s)
365static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size, 365static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
366 int manifest_sync_timeout) 366 int manifest_sync_timeout)
367{ 367{
368 u8 *block;
369 struct dfu_status dfu_stat_buf;
370 int ret = 0; 368 int ret = 0;
371 int need_dfu_state = 1; 369 int need_dfu_state = 1;
372 int is_done = 0; 370 int is_done = 0;
373 u8 dfu_state = 0;
374 u32 dfu_timeout = 0; 371 u32 dfu_timeout = 0;
375 int bsize = 0; 372 int bsize = 0;
376 int blockno = 0; 373 int blockno = 0;
374 struct dfu_status *dfu_stat_buf = NULL;
375 u8 *dfu_state = NULL;
376 u8 *block = NULL;
377 377
378 at76_dbg(DBG_DFU, "%s( %p, %u, %d)", __func__, buf, size, 378 at76_dbg(DBG_DFU, "%s( %p, %u, %d)", __func__, buf, size,
379 manifest_sync_timeout); 379 manifest_sync_timeout);
@@ -383,13 +383,28 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
383 return -EINVAL; 383 return -EINVAL;
384 } 384 }
385 385
386 dfu_stat_buf = kmalloc(sizeof(struct dfu_status), GFP_KERNEL);
387 if (!dfu_stat_buf) {
388 ret = -ENOMEM;
389 goto exit;
390 }
391
386 block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL); 392 block = kmalloc(FW_BLOCK_SIZE, GFP_KERNEL);
387 if (!block) 393 if (!block) {
388 return -ENOMEM; 394 ret = -ENOMEM;
395 goto exit;
396 }
397
398 dfu_state = kmalloc(sizeof(u8), GFP_KERNEL);
399 if (!dfu_state) {
400 ret = -ENOMEM;
401 goto exit;
402 }
403 *dfu_state = 0;
389 404
390 do { 405 do {
391 if (need_dfu_state) { 406 if (need_dfu_state) {
392 ret = at76_dfu_get_state(udev, &dfu_state); 407 ret = at76_dfu_get_state(udev, dfu_state);
393 if (ret < 0) { 408 if (ret < 0) {
394 dev_err(&udev->dev, 409 dev_err(&udev->dev,
395 "cannot get DFU state: %d\n", ret); 410 "cannot get DFU state: %d\n", ret);
@@ -398,13 +413,13 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
398 need_dfu_state = 0; 413 need_dfu_state = 0;
399 } 414 }
400 415
401 switch (dfu_state) { 416 switch (*dfu_state) {
402 case STATE_DFU_DOWNLOAD_SYNC: 417 case STATE_DFU_DOWNLOAD_SYNC:
403 at76_dbg(DBG_DFU, "STATE_DFU_DOWNLOAD_SYNC"); 418 at76_dbg(DBG_DFU, "STATE_DFU_DOWNLOAD_SYNC");
404 ret = at76_dfu_get_status(udev, &dfu_stat_buf); 419 ret = at76_dfu_get_status(udev, dfu_stat_buf);
405 if (ret >= 0) { 420 if (ret >= 0) {
406 dfu_state = dfu_stat_buf.state; 421 *dfu_state = dfu_stat_buf->state;
407 dfu_timeout = at76_get_timeout(&dfu_stat_buf); 422 dfu_timeout = at76_get_timeout(dfu_stat_buf);
408 need_dfu_state = 0; 423 need_dfu_state = 0;
409 } else 424 } else
410 dev_err(&udev->dev, 425 dev_err(&udev->dev,
@@ -447,12 +462,12 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
447 case STATE_DFU_MANIFEST_SYNC: 462 case STATE_DFU_MANIFEST_SYNC:
448 at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST_SYNC"); 463 at76_dbg(DBG_DFU, "STATE_DFU_MANIFEST_SYNC");
449 464
450 ret = at76_dfu_get_status(udev, &dfu_stat_buf); 465 ret = at76_dfu_get_status(udev, dfu_stat_buf);
451 if (ret < 0) 466 if (ret < 0)
452 break; 467 break;
453 468
454 dfu_state = dfu_stat_buf.state; 469 *dfu_state = dfu_stat_buf->state;
455 dfu_timeout = at76_get_timeout(&dfu_stat_buf); 470 dfu_timeout = at76_get_timeout(dfu_stat_buf);
456 need_dfu_state = 0; 471 need_dfu_state = 0;
457 472
458 /* override the timeout from the status response, 473 /* override the timeout from the status response,
@@ -484,14 +499,17 @@ static int at76_usbdfu_download(struct usb_device *udev, u8 *buf, u32 size,
484 break; 499 break;
485 500
486 default: 501 default:
487 at76_dbg(DBG_DFU, "DFU UNKNOWN STATE (%d)", dfu_state); 502 at76_dbg(DBG_DFU, "DFU UNKNOWN STATE (%d)", *dfu_state);
488 ret = -EINVAL; 503 ret = -EINVAL;
489 break; 504 break;
490 } 505 }
491 } while (!is_done && (ret >= 0)); 506 } while (!is_done && (ret >= 0));
492 507
493exit: 508exit:
509 kfree(dfu_state);
494 kfree(block); 510 kfree(block);
511 kfree(dfu_stat_buf);
512
495 if (ret >= 0) 513 if (ret >= 0)
496 ret = 0; 514 ret = 0;
497 515
@@ -1277,6 +1295,7 @@ static int at76_load_external_fw(struct usb_device *udev, struct fwentry *fwe)
1277 dev_err(&udev->dev, 1295 dev_err(&udev->dev,
1278 "loading %dth firmware block failed: %d\n", 1296 "loading %dth firmware block failed: %d\n",
1279 blockno, ret); 1297 blockno, ret);
1298 ret = -EIO;
1280 goto exit; 1299 goto exit;
1281 } 1300 }
1282 buf += bsize; 1301 buf += bsize;
@@ -2020,6 +2039,44 @@ static void at76_configure_filter(struct ieee80211_hw *hw,
2020 ieee80211_queue_work(hw, &priv->work_set_promisc); 2039 ieee80211_queue_work(hw, &priv->work_set_promisc);
2021} 2040}
2022 2041
2042static int at76_set_wep(struct at76_priv *priv)
2043{
2044 int ret = 0;
2045 struct mib_mac_wep *mib_data = &priv->mib_buf.data.wep_mib;
2046
2047 priv->mib_buf.type = MIB_MAC_WEP;
2048 priv->mib_buf.size = sizeof(struct mib_mac_wep);
2049 priv->mib_buf.index = 0;
2050
2051 memset(mib_data, 0, sizeof(*mib_data));
2052
2053 if (priv->wep_enabled) {
2054 if (priv->wep_keys_len[priv->wep_key_id] > WEP_SMALL_KEY_LEN)
2055 mib_data->encryption_level = 2;
2056 else
2057 mib_data->encryption_level = 1;
2058
2059 /* always exclude unencrypted if WEP is active */
2060 mib_data->exclude_unencrypted = 1;
2061 } else {
2062 mib_data->exclude_unencrypted = 0;
2063 mib_data->encryption_level = 0;
2064 }
2065
2066 mib_data->privacy_invoked = priv->wep_enabled;
2067 mib_data->wep_default_key_id = priv->wep_key_id;
2068 memcpy(mib_data->wep_default_keyvalue, priv->wep_keys,
2069 sizeof(priv->wep_keys));
2070
2071 ret = at76_set_mib(priv, &priv->mib_buf);
2072
2073 if (ret < 0)
2074 wiphy_err(priv->hw->wiphy,
2075 "set_mib (wep) failed: %d\n", ret);
2076
2077 return ret;
2078}
2079
2023static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 2080static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2024 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 2081 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2025 struct ieee80211_key_conf *key) 2082 struct ieee80211_key_conf *key)
@@ -2062,7 +2119,7 @@ static int at76_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2062 priv->wep_enabled = 1; 2119 priv->wep_enabled = 1;
2063 } 2120 }
2064 2121
2065 at76_startup_device(priv); 2122 at76_set_wep(priv);
2066 2123
2067 mutex_unlock(&priv->mtx); 2124 mutex_unlock(&priv->mtx);
2068 2125
@@ -2330,16 +2387,22 @@ static int at76_probe(struct usb_interface *interface,
2330 struct usb_device *udev; 2387 struct usb_device *udev;
2331 int op_mode; 2388 int op_mode;
2332 int need_ext_fw = 0; 2389 int need_ext_fw = 0;
2333 struct mib_fw_version fwv; 2390 struct mib_fw_version *fwv = NULL;
2334 int board_type = (int)id->driver_info; 2391 int board_type = (int)id->driver_info;
2335 2392
2336 udev = usb_get_dev(interface_to_usbdev(interface)); 2393 udev = usb_get_dev(interface_to_usbdev(interface));
2337 2394
2395 fwv = kmalloc(sizeof(*fwv), GFP_KERNEL);
2396 if (!fwv) {
2397 ret = -ENOMEM;
2398 goto exit;
2399 }
2400
2338 /* Load firmware into kernel memory */ 2401 /* Load firmware into kernel memory */
2339 fwe = at76_load_firmware(udev, board_type); 2402 fwe = at76_load_firmware(udev, board_type);
2340 if (!fwe) { 2403 if (!fwe) {
2341 ret = -ENOENT; 2404 ret = -ENOENT;
2342 goto error; 2405 goto exit;
2343 } 2406 }
2344 2407
2345 op_mode = at76_get_op_mode(udev); 2408 op_mode = at76_get_op_mode(udev);
@@ -2353,7 +2416,7 @@ static int at76_probe(struct usb_interface *interface,
2353 dev_err(&interface->dev, 2416 dev_err(&interface->dev,
2354 "cannot handle a device in HW_CONFIG_MODE\n"); 2417 "cannot handle a device in HW_CONFIG_MODE\n");
2355 ret = -EBUSY; 2418 ret = -EBUSY;
2356 goto error; 2419 goto exit;
2357 } 2420 }
2358 2421
2359 if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH 2422 if (op_mode != OPMODE_NORMAL_NIC_WITH_FLASH
@@ -2366,10 +2429,10 @@ static int at76_probe(struct usb_interface *interface,
2366 dev_err(&interface->dev, 2429 dev_err(&interface->dev,
2367 "error %d downloading internal firmware\n", 2430 "error %d downloading internal firmware\n",
2368 ret); 2431 ret);
2369 goto error; 2432 goto exit;
2370 } 2433 }
2371 usb_put_dev(udev); 2434 usb_put_dev(udev);
2372 return ret; 2435 goto exit;
2373 } 2436 }
2374 2437
2375 /* Internal firmware already inside the device. Get firmware 2438 /* Internal firmware already inside the device. Get firmware
@@ -2382,8 +2445,8 @@ static int at76_probe(struct usb_interface *interface,
2382 * query the device for the fw version */ 2445 * query the device for the fw version */
2383 if ((fwe->fw_version.major > 0 || fwe->fw_version.minor >= 100) 2446 if ((fwe->fw_version.major > 0 || fwe->fw_version.minor >= 100)
2384 || (op_mode == OPMODE_NORMAL_NIC_WITH_FLASH)) { 2447 || (op_mode == OPMODE_NORMAL_NIC_WITH_FLASH)) {
2385 ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv)); 2448 ret = at76_get_mib(udev, MIB_FW_VERSION, fwv, sizeof(*fwv));
2386 if (ret < 0 || (fwv.major | fwv.minor) == 0) 2449 if (ret < 0 || (fwv->major | fwv->minor) == 0)
2387 need_ext_fw = 1; 2450 need_ext_fw = 1;
2388 } else 2451 } else
2389 /* No way to check firmware version, reload to be sure */ 2452 /* No way to check firmware version, reload to be sure */
@@ -2394,37 +2457,37 @@ static int at76_probe(struct usb_interface *interface,
2394 "downloading external firmware\n"); 2457 "downloading external firmware\n");
2395 2458
2396 ret = at76_load_external_fw(udev, fwe); 2459 ret = at76_load_external_fw(udev, fwe);
2397 if (ret) 2460 if (ret < 0)
2398 goto error; 2461 goto exit;
2399 2462
2400 /* Re-check firmware version */ 2463 /* Re-check firmware version */
2401 ret = at76_get_mib(udev, MIB_FW_VERSION, &fwv, sizeof(fwv)); 2464 ret = at76_get_mib(udev, MIB_FW_VERSION, fwv, sizeof(*fwv));
2402 if (ret < 0) { 2465 if (ret < 0) {
2403 dev_err(&interface->dev, 2466 dev_err(&interface->dev,
2404 "error %d getting firmware version\n", ret); 2467 "error %d getting firmware version\n", ret);
2405 goto error; 2468 goto exit;
2406 } 2469 }
2407 } 2470 }
2408 2471
2409 priv = at76_alloc_new_device(udev); 2472 priv = at76_alloc_new_device(udev);
2410 if (!priv) { 2473 if (!priv) {
2411 ret = -ENOMEM; 2474 ret = -ENOMEM;
2412 goto error; 2475 goto exit;
2413 } 2476 }
2414 2477
2415 usb_set_intfdata(interface, priv); 2478 usb_set_intfdata(interface, priv);
2416 2479
2417 memcpy(&priv->fw_version, &fwv, sizeof(struct mib_fw_version)); 2480 memcpy(&priv->fw_version, fwv, sizeof(struct mib_fw_version));
2418 priv->board_type = board_type; 2481 priv->board_type = board_type;
2419 2482
2420 ret = at76_init_new_device(priv, interface); 2483 ret = at76_init_new_device(priv, interface);
2421 if (ret < 0) 2484 if (ret < 0)
2422 at76_delete_device(priv); 2485 at76_delete_device(priv);
2423 2486
2424 return ret; 2487exit:
2425 2488 kfree(fwv);
2426error: 2489 if (ret < 0)
2427 usb_put_dev(udev); 2490 usb_put_dev(udev);
2428 return ret; 2491 return ret;
2429} 2492}
2430 2493
diff --git a/drivers/net/wireless/at76c50x-usb.h b/drivers/net/wireless/at76c50x-usb.h
index f14a65473fe8..4718aa59f051 100644
--- a/drivers/net/wireless/at76c50x-usb.h
+++ b/drivers/net/wireless/at76c50x-usb.h
@@ -219,18 +219,6 @@ struct at76_req_join {
219 u8 reserved; 219 u8 reserved;
220} __packed; 220} __packed;
221 221
222struct set_mib_buffer {
223 u8 type;
224 u8 size;
225 u8 index;
226 u8 reserved;
227 union {
228 u8 byte;
229 __le16 word;
230 u8 addr[ETH_ALEN];
231 } data;
232} __packed;
233
234struct mib_local { 222struct mib_local {
235 u16 reserved0; 223 u16 reserved0;
236 u8 beacon_enable; 224 u8 beacon_enable;
@@ -334,6 +322,19 @@ struct mib_mdomain {
334 u8 channel_list[14]; /* 0 for invalid channels */ 322 u8 channel_list[14]; /* 0 for invalid channels */
335} __packed; 323} __packed;
336 324
325struct set_mib_buffer {
326 u8 type;
327 u8 size;
328 u8 index;
329 u8 reserved;
330 union {
331 u8 byte;
332 __le16 word;
333 u8 addr[ETH_ALEN];
334 struct mib_mac_wep wep_mib;
335 } data;
336} __packed;
337
337struct at76_fw_header { 338struct at76_fw_header {
338 __le32 crc; /* CRC32 of the whole image */ 339 __le32 crc; /* CRC32 of the whole image */
339 __le32 board_type; /* firmware compatibility code */ 340 __le32 board_type; /* firmware compatibility code */
diff --git a/drivers/net/wireless/ath/ath10k/bmi.h b/drivers/net/wireless/ath/ath10k/bmi.h
index 3a9bdf51c96a..111ab701465c 100644
--- a/drivers/net/wireless/ath/ath10k/bmi.h
+++ b/drivers/net/wireless/ath/ath10k/bmi.h
@@ -201,7 +201,8 @@ int ath10k_bmi_write_memory(struct ath10k *ar, u32 address,
201 \ 201 \
202 addr = host_interest_item_address(HI_ITEM(item)); \ 202 addr = host_interest_item_address(HI_ITEM(item)); \
203 ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \ 203 ret = ath10k_bmi_read_memory(ar, addr, (u8 *)&tmp, 4); \
204 *val = __le32_to_cpu(tmp); \ 204 if (!ret) \
205 *val = __le32_to_cpu(tmp); \
205 ret; \ 206 ret; \
206 }) 207 })
207 208
diff --git a/drivers/net/wireless/ath/ath10k/ce.c b/drivers/net/wireless/ath/ath10k/ce.c
index 1e4cad8632b5..d185dc0cd12b 100644
--- a/drivers/net/wireless/ath/ath10k/ce.c
+++ b/drivers/net/wireless/ath/ath10k/ce.c
@@ -329,6 +329,33 @@ exit:
329 return ret; 329 return ret;
330} 330}
331 331
332void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe)
333{
334 struct ath10k *ar = pipe->ar;
335 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
336 struct ath10k_ce_ring *src_ring = pipe->src_ring;
337 u32 ctrl_addr = pipe->ctrl_addr;
338
339 lockdep_assert_held(&ar_pci->ce_lock);
340
341 /*
342 * This function must be called only if there is an incomplete
343 * scatter-gather transfer (before index register is updated)
344 * that needs to be cleaned up.
345 */
346 if (WARN_ON_ONCE(src_ring->write_index == src_ring->sw_index))
347 return;
348
349 if (WARN_ON_ONCE(src_ring->write_index ==
350 ath10k_ce_src_ring_write_index_get(ar, ctrl_addr)))
351 return;
352
353 src_ring->write_index--;
354 src_ring->write_index &= src_ring->nentries_mask;
355
356 src_ring->per_transfer_context[src_ring->write_index] = NULL;
357}
358
332int ath10k_ce_send(struct ath10k_ce_pipe *ce_state, 359int ath10k_ce_send(struct ath10k_ce_pipe *ce_state,
333 void *per_transfer_context, 360 void *per_transfer_context,
334 u32 buffer, 361 u32 buffer,
diff --git a/drivers/net/wireless/ath/ath10k/ce.h b/drivers/net/wireless/ath/ath10k/ce.h
index fd0bc3561e42..7a5a36fc59c1 100644
--- a/drivers/net/wireless/ath/ath10k/ce.h
+++ b/drivers/net/wireless/ath/ath10k/ce.h
@@ -160,6 +160,8 @@ int ath10k_ce_send_nolock(struct ath10k_ce_pipe *ce_state,
160 unsigned int transfer_id, 160 unsigned int transfer_id,
161 unsigned int flags); 161 unsigned int flags);
162 162
163void __ath10k_ce_send_revert(struct ath10k_ce_pipe *pipe);
164
163void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state, 165void ath10k_ce_send_cb_register(struct ath10k_ce_pipe *ce_state,
164 void (*send_cb)(struct ath10k_ce_pipe *), 166 void (*send_cb)(struct ath10k_ce_pipe *),
165 int disable_interrupts); 167 int disable_interrupts);
diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index 75b3dfbd6509..82017f56e661 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -58,36 +58,6 @@ static void ath10k_send_suspend_complete(struct ath10k *ar)
58 complete(&ar->target_suspend); 58 complete(&ar->target_suspend);
59} 59}
60 60
61static int ath10k_init_connect_htc(struct ath10k *ar)
62{
63 int status;
64
65 status = ath10k_wmi_connect_htc_service(ar);
66 if (status)
67 goto conn_fail;
68
69 /* Start HTC */
70 status = ath10k_htc_start(&ar->htc);
71 if (status)
72 goto conn_fail;
73
74 /* Wait for WMI event to be ready */
75 status = ath10k_wmi_wait_for_service_ready(ar);
76 if (status <= 0) {
77 ath10k_warn("wmi service ready event not received");
78 status = -ETIMEDOUT;
79 goto timeout;
80 }
81
82 ath10k_dbg(ATH10K_DBG_BOOT, "boot wmi ready\n");
83 return 0;
84
85timeout:
86 ath10k_htc_stop(&ar->htc);
87conn_fail:
88 return status;
89}
90
91static int ath10k_init_configure_target(struct ath10k *ar) 61static int ath10k_init_configure_target(struct ath10k *ar)
92{ 62{
93 u32 param_host; 63 u32 param_host;
@@ -681,7 +651,8 @@ static void ath10k_core_restart(struct work_struct *work)
681 switch (ar->state) { 651 switch (ar->state) {
682 case ATH10K_STATE_ON: 652 case ATH10K_STATE_ON:
683 ar->state = ATH10K_STATE_RESTARTING; 653 ar->state = ATH10K_STATE_RESTARTING;
684 ath10k_halt(ar); 654 del_timer_sync(&ar->scan.timeout);
655 ath10k_reset_scan((unsigned long)ar);
685 ieee80211_restart_hw(ar->hw); 656 ieee80211_restart_hw(ar->hw);
686 break; 657 break;
687 case ATH10K_STATE_OFF: 658 case ATH10K_STATE_OFF:
@@ -690,6 +661,8 @@ static void ath10k_core_restart(struct work_struct *work)
690 ath10k_warn("cannot restart a device that hasn't been started\n"); 661 ath10k_warn("cannot restart a device that hasn't been started\n");
691 break; 662 break;
692 case ATH10K_STATE_RESTARTING: 663 case ATH10K_STATE_RESTARTING:
664 /* hw restart might be requested from multiple places */
665 break;
693 case ATH10K_STATE_RESTARTED: 666 case ATH10K_STATE_RESTARTED:
694 ar->state = ATH10K_STATE_WEDGED; 667 ar->state = ATH10K_STATE_WEDGED;
695 /* fall through */ 668 /* fall through */
@@ -701,70 +674,6 @@ static void ath10k_core_restart(struct work_struct *work)
701 mutex_unlock(&ar->conf_mutex); 674 mutex_unlock(&ar->conf_mutex);
702} 675}
703 676
704struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
705 const struct ath10k_hif_ops *hif_ops)
706{
707 struct ath10k *ar;
708
709 ar = ath10k_mac_create();
710 if (!ar)
711 return NULL;
712
713 ar->ath_common.priv = ar;
714 ar->ath_common.hw = ar->hw;
715
716 ar->p2p = !!ath10k_p2p;
717 ar->dev = dev;
718
719 ar->hif.priv = hif_priv;
720 ar->hif.ops = hif_ops;
721
722 init_completion(&ar->scan.started);
723 init_completion(&ar->scan.completed);
724 init_completion(&ar->scan.on_channel);
725 init_completion(&ar->target_suspend);
726
727 init_completion(&ar->install_key_done);
728 init_completion(&ar->vdev_setup_done);
729
730 setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
731
732 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
733 if (!ar->workqueue)
734 goto err_wq;
735
736 mutex_init(&ar->conf_mutex);
737 spin_lock_init(&ar->data_lock);
738
739 INIT_LIST_HEAD(&ar->peers);
740 init_waitqueue_head(&ar->peer_mapping_wq);
741
742 init_completion(&ar->offchan_tx_completed);
743 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
744 skb_queue_head_init(&ar->offchan_tx_queue);
745
746 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
747 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
748
749 INIT_WORK(&ar->restart_work, ath10k_core_restart);
750
751 return ar;
752
753err_wq:
754 ath10k_mac_destroy(ar);
755 return NULL;
756}
757EXPORT_SYMBOL(ath10k_core_create);
758
759void ath10k_core_destroy(struct ath10k *ar)
760{
761 flush_workqueue(ar->workqueue);
762 destroy_workqueue(ar->workqueue);
763
764 ath10k_mac_destroy(ar);
765}
766EXPORT_SYMBOL(ath10k_core_destroy);
767
768int ath10k_core_start(struct ath10k *ar) 677int ath10k_core_start(struct ath10k *ar)
769{ 678{
770 int status; 679 int status;
@@ -805,10 +714,28 @@ int ath10k_core_start(struct ath10k *ar)
805 goto err; 714 goto err;
806 } 715 }
807 716
717 status = ath10k_htt_init(ar);
718 if (status) {
719 ath10k_err("failed to init htt: %d\n", status);
720 goto err_wmi_detach;
721 }
722
723 status = ath10k_htt_tx_alloc(&ar->htt);
724 if (status) {
725 ath10k_err("failed to alloc htt tx: %d\n", status);
726 goto err_wmi_detach;
727 }
728
729 status = ath10k_htt_rx_alloc(&ar->htt);
730 if (status) {
731 ath10k_err("failed to alloc htt rx: %d\n", status);
732 goto err_htt_tx_detach;
733 }
734
808 status = ath10k_hif_start(ar); 735 status = ath10k_hif_start(ar);
809 if (status) { 736 if (status) {
810 ath10k_err("could not start HIF: %d\n", status); 737 ath10k_err("could not start HIF: %d\n", status);
811 goto err_wmi_detach; 738 goto err_htt_rx_detach;
812 } 739 }
813 740
814 status = ath10k_htc_wait_target(&ar->htc); 741 status = ath10k_htc_wait_target(&ar->htc);
@@ -817,15 +744,30 @@ int ath10k_core_start(struct ath10k *ar)
817 goto err_hif_stop; 744 goto err_hif_stop;
818 } 745 }
819 746
820 status = ath10k_htt_attach(ar); 747 status = ath10k_htt_connect(&ar->htt);
821 if (status) { 748 if (status) {
822 ath10k_err("could not attach htt (%d)\n", status); 749 ath10k_err("failed to connect htt (%d)\n", status);
823 goto err_hif_stop; 750 goto err_hif_stop;
824 } 751 }
825 752
826 status = ath10k_init_connect_htc(ar); 753 status = ath10k_wmi_connect(ar);
827 if (status) 754 if (status) {
828 goto err_htt_detach; 755 ath10k_err("could not connect wmi: %d\n", status);
756 goto err_hif_stop;
757 }
758
759 status = ath10k_htc_start(&ar->htc);
760 if (status) {
761 ath10k_err("failed to start htc: %d\n", status);
762 goto err_hif_stop;
763 }
764
765 status = ath10k_wmi_wait_for_service_ready(ar);
766 if (status <= 0) {
767 ath10k_warn("wmi service ready event not received");
768 status = -ETIMEDOUT;
769 goto err_htc_stop;
770 }
829 771
830 ath10k_dbg(ATH10K_DBG_BOOT, "firmware %s booted\n", 772 ath10k_dbg(ATH10K_DBG_BOOT, "firmware %s booted\n",
831 ar->hw->wiphy->fw_version); 773 ar->hw->wiphy->fw_version);
@@ -833,23 +775,25 @@ int ath10k_core_start(struct ath10k *ar)
833 status = ath10k_wmi_cmd_init(ar); 775 status = ath10k_wmi_cmd_init(ar);
834 if (status) { 776 if (status) {
835 ath10k_err("could not send WMI init command (%d)\n", status); 777 ath10k_err("could not send WMI init command (%d)\n", status);
836 goto err_disconnect_htc; 778 goto err_htc_stop;
837 } 779 }
838 780
839 status = ath10k_wmi_wait_for_unified_ready(ar); 781 status = ath10k_wmi_wait_for_unified_ready(ar);
840 if (status <= 0) { 782 if (status <= 0) {
841 ath10k_err("wmi unified ready event not received\n"); 783 ath10k_err("wmi unified ready event not received\n");
842 status = -ETIMEDOUT; 784 status = -ETIMEDOUT;
843 goto err_disconnect_htc; 785 goto err_htc_stop;
844 } 786 }
845 787
846 status = ath10k_htt_attach_target(&ar->htt); 788 status = ath10k_htt_setup(&ar->htt);
847 if (status) 789 if (status) {
848 goto err_disconnect_htc; 790 ath10k_err("failed to setup htt: %d\n", status);
791 goto err_htc_stop;
792 }
849 793
850 status = ath10k_debug_start(ar); 794 status = ath10k_debug_start(ar);
851 if (status) 795 if (status)
852 goto err_disconnect_htc; 796 goto err_htc_stop;
853 797
854 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1; 798 ar->free_vdev_map = (1 << TARGET_NUM_VDEVS) - 1;
855 INIT_LIST_HEAD(&ar->arvifs); 799 INIT_LIST_HEAD(&ar->arvifs);
@@ -868,12 +812,14 @@ int ath10k_core_start(struct ath10k *ar)
868 812
869 return 0; 813 return 0;
870 814
871err_disconnect_htc: 815err_htc_stop:
872 ath10k_htc_stop(&ar->htc); 816 ath10k_htc_stop(&ar->htc);
873err_htt_detach:
874 ath10k_htt_detach(&ar->htt);
875err_hif_stop: 817err_hif_stop:
876 ath10k_hif_stop(ar); 818 ath10k_hif_stop(ar);
819err_htt_rx_detach:
820 ath10k_htt_rx_free(&ar->htt);
821err_htt_tx_detach:
822 ath10k_htt_tx_free(&ar->htt);
877err_wmi_detach: 823err_wmi_detach:
878 ath10k_wmi_detach(ar); 824 ath10k_wmi_detach(ar);
879err: 825err:
@@ -913,7 +859,9 @@ void ath10k_core_stop(struct ath10k *ar)
913 859
914 ath10k_debug_stop(ar); 860 ath10k_debug_stop(ar);
915 ath10k_htc_stop(&ar->htc); 861 ath10k_htc_stop(&ar->htc);
916 ath10k_htt_detach(&ar->htt); 862 ath10k_hif_stop(ar);
863 ath10k_htt_tx_free(&ar->htt);
864 ath10k_htt_rx_free(&ar->htt);
917 ath10k_wmi_detach(ar); 865 ath10k_wmi_detach(ar);
918} 866}
919EXPORT_SYMBOL(ath10k_core_stop); 867EXPORT_SYMBOL(ath10k_core_stop);
@@ -1005,22 +953,15 @@ static int ath10k_core_check_chip_id(struct ath10k *ar)
1005 return 0; 953 return 0;
1006} 954}
1007 955
1008int ath10k_core_register(struct ath10k *ar, u32 chip_id) 956static void ath10k_core_register_work(struct work_struct *work)
1009{ 957{
958 struct ath10k *ar = container_of(work, struct ath10k, register_work);
1010 int status; 959 int status;
1011 960
1012 ar->chip_id = chip_id;
1013
1014 status = ath10k_core_check_chip_id(ar);
1015 if (status) {
1016 ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
1017 return status;
1018 }
1019
1020 status = ath10k_core_probe_fw(ar); 961 status = ath10k_core_probe_fw(ar);
1021 if (status) { 962 if (status) {
1022 ath10k_err("could not probe fw (%d)\n", status); 963 ath10k_err("could not probe fw (%d)\n", status);
1023 return status; 964 goto err;
1024 } 965 }
1025 966
1026 status = ath10k_mac_register(ar); 967 status = ath10k_mac_register(ar);
@@ -1035,18 +976,43 @@ int ath10k_core_register(struct ath10k *ar, u32 chip_id)
1035 goto err_unregister_mac; 976 goto err_unregister_mac;
1036 } 977 }
1037 978
1038 return 0; 979 set_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags);
980 return;
1039 981
1040err_unregister_mac: 982err_unregister_mac:
1041 ath10k_mac_unregister(ar); 983 ath10k_mac_unregister(ar);
1042err_release_fw: 984err_release_fw:
1043 ath10k_core_free_firmware_files(ar); 985 ath10k_core_free_firmware_files(ar);
1044 return status; 986err:
987 device_release_driver(ar->dev);
988 return;
989}
990
991int ath10k_core_register(struct ath10k *ar, u32 chip_id)
992{
993 int status;
994
995 ar->chip_id = chip_id;
996
997 status = ath10k_core_check_chip_id(ar);
998 if (status) {
999 ath10k_err("Unsupported chip id 0x%08x\n", ar->chip_id);
1000 return status;
1001 }
1002
1003 queue_work(ar->workqueue, &ar->register_work);
1004
1005 return 0;
1045} 1006}
1046EXPORT_SYMBOL(ath10k_core_register); 1007EXPORT_SYMBOL(ath10k_core_register);
1047 1008
1048void ath10k_core_unregister(struct ath10k *ar) 1009void ath10k_core_unregister(struct ath10k *ar)
1049{ 1010{
1011 cancel_work_sync(&ar->register_work);
1012
1013 if (!test_bit(ATH10K_FLAG_CORE_REGISTERED, &ar->dev_flags))
1014 return;
1015
1050 /* We must unregister from mac80211 before we stop HTC and HIF. 1016 /* We must unregister from mac80211 before we stop HTC and HIF.
1051 * Otherwise we will fail to submit commands to FW and mac80211 will be 1017 * Otherwise we will fail to submit commands to FW and mac80211 will be
1052 * unhappy about callback failures. */ 1018 * unhappy about callback failures. */
@@ -1058,6 +1024,71 @@ void ath10k_core_unregister(struct ath10k *ar)
1058} 1024}
1059EXPORT_SYMBOL(ath10k_core_unregister); 1025EXPORT_SYMBOL(ath10k_core_unregister);
1060 1026
1027struct ath10k *ath10k_core_create(void *hif_priv, struct device *dev,
1028 const struct ath10k_hif_ops *hif_ops)
1029{
1030 struct ath10k *ar;
1031
1032 ar = ath10k_mac_create();
1033 if (!ar)
1034 return NULL;
1035
1036 ar->ath_common.priv = ar;
1037 ar->ath_common.hw = ar->hw;
1038
1039 ar->p2p = !!ath10k_p2p;
1040 ar->dev = dev;
1041
1042 ar->hif.priv = hif_priv;
1043 ar->hif.ops = hif_ops;
1044
1045 init_completion(&ar->scan.started);
1046 init_completion(&ar->scan.completed);
1047 init_completion(&ar->scan.on_channel);
1048 init_completion(&ar->target_suspend);
1049
1050 init_completion(&ar->install_key_done);
1051 init_completion(&ar->vdev_setup_done);
1052
1053 setup_timer(&ar->scan.timeout, ath10k_reset_scan, (unsigned long)ar);
1054
1055 ar->workqueue = create_singlethread_workqueue("ath10k_wq");
1056 if (!ar->workqueue)
1057 goto err_wq;
1058
1059 mutex_init(&ar->conf_mutex);
1060 spin_lock_init(&ar->data_lock);
1061
1062 INIT_LIST_HEAD(&ar->peers);
1063 init_waitqueue_head(&ar->peer_mapping_wq);
1064
1065 init_completion(&ar->offchan_tx_completed);
1066 INIT_WORK(&ar->offchan_tx_work, ath10k_offchan_tx_work);
1067 skb_queue_head_init(&ar->offchan_tx_queue);
1068
1069 INIT_WORK(&ar->wmi_mgmt_tx_work, ath10k_mgmt_over_wmi_tx_work);
1070 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
1071
1072 INIT_WORK(&ar->register_work, ath10k_core_register_work);
1073 INIT_WORK(&ar->restart_work, ath10k_core_restart);
1074
1075 return ar;
1076
1077err_wq:
1078 ath10k_mac_destroy(ar);
1079 return NULL;
1080}
1081EXPORT_SYMBOL(ath10k_core_create);
1082
1083void ath10k_core_destroy(struct ath10k *ar)
1084{
1085 flush_workqueue(ar->workqueue);
1086 destroy_workqueue(ar->workqueue);
1087
1088 ath10k_mac_destroy(ar);
1089}
1090EXPORT_SYMBOL(ath10k_core_destroy);
1091
1061MODULE_AUTHOR("Qualcomm Atheros"); 1092MODULE_AUTHOR("Qualcomm Atheros");
1062MODULE_DESCRIPTION("Core module for QCA988X PCIe devices."); 1093MODULE_DESCRIPTION("Core module for QCA988X PCIe devices.");
1063MODULE_LICENSE("Dual BSD/GPL"); 1094MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index 2c1dfd719146..68ceef61933d 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -335,6 +335,7 @@ enum ath10k_dev_flags {
335 /* Indicates that ath10k device is during CAC phase of DFS */ 335 /* Indicates that ath10k device is during CAC phase of DFS */
336 ATH10K_CAC_RUNNING, 336 ATH10K_CAC_RUNNING,
337 ATH10K_FLAG_FIRST_BOOT_DONE, 337 ATH10K_FLAG_FIRST_BOOT_DONE,
338 ATH10K_FLAG_CORE_REGISTERED,
338}; 339};
339 340
340struct ath10k { 341struct ath10k {
@@ -440,6 +441,12 @@ struct ath10k {
440 bool radar_enabled; 441 bool radar_enabled;
441 int num_started_vdevs; 442 int num_started_vdevs;
442 443
444 /* Protected by conf-mutex */
445 u8 supp_tx_chainmask;
446 u8 supp_rx_chainmask;
447 u8 cfg_tx_chainmask;
448 u8 cfg_rx_chainmask;
449
443 struct wmi_pdev_set_wmm_params_arg wmm_params; 450 struct wmi_pdev_set_wmm_params_arg wmm_params;
444 struct completion install_key_done; 451 struct completion install_key_done;
445 452
@@ -470,6 +477,7 @@ struct ath10k {
470 477
471 enum ath10k_state state; 478 enum ath10k_state state;
472 479
480 struct work_struct register_work;
473 struct work_struct restart_work; 481 struct work_struct restart_work;
474 482
475 /* cycle count is reported twice for each visited channel during scan. 483 /* cycle count is reported twice for each visited channel during scan.
diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
index 5b58dbb17416..e493db4b4a41 100644
--- a/drivers/net/wireless/ath/ath10k/htc.c
+++ b/drivers/net/wireless/ath/ath10k/htc.c
@@ -830,17 +830,11 @@ int ath10k_htc_start(struct ath10k_htc *htc)
830 return 0; 830 return 0;
831} 831}
832 832
833/*
834 * stop HTC communications, i.e. stop interrupt reception, and flush all
835 * queued buffers
836 */
837void ath10k_htc_stop(struct ath10k_htc *htc) 833void ath10k_htc_stop(struct ath10k_htc *htc)
838{ 834{
839 spin_lock_bh(&htc->tx_lock); 835 spin_lock_bh(&htc->tx_lock);
840 htc->stopped = true; 836 htc->stopped = true;
841 spin_unlock_bh(&htc->tx_lock); 837 spin_unlock_bh(&htc->tx_lock);
842
843 ath10k_hif_stop(htc->ar);
844} 838}
845 839
846/* registered target arrival callback from the HIF layer */ 840/* registered target arrival callback from the HIF layer */
diff --git a/drivers/net/wireless/ath/ath10k/htt.c b/drivers/net/wireless/ath/ath10k/htt.c
index 69697af59ce0..19c12cc8d663 100644
--- a/drivers/net/wireless/ath/ath10k/htt.c
+++ b/drivers/net/wireless/ath/ath10k/htt.c
@@ -22,7 +22,7 @@
22#include "core.h" 22#include "core.h"
23#include "debug.h" 23#include "debug.h"
24 24
25static int ath10k_htt_htc_attach(struct ath10k_htt *htt) 25int ath10k_htt_connect(struct ath10k_htt *htt)
26{ 26{
27 struct ath10k_htc_svc_conn_req conn_req; 27 struct ath10k_htc_svc_conn_req conn_req;
28 struct ath10k_htc_svc_conn_resp conn_resp; 28 struct ath10k_htc_svc_conn_resp conn_resp;
@@ -48,39 +48,14 @@ static int ath10k_htt_htc_attach(struct ath10k_htt *htt)
48 return 0; 48 return 0;
49} 49}
50 50
51int ath10k_htt_attach(struct ath10k *ar) 51int ath10k_htt_init(struct ath10k *ar)
52{ 52{
53 struct ath10k_htt *htt = &ar->htt; 53 struct ath10k_htt *htt = &ar->htt;
54 int ret;
55 54
56 htt->ar = ar; 55 htt->ar = ar;
57 htt->max_throughput_mbps = 800; 56 htt->max_throughput_mbps = 800;
58 57
59 /* 58 /*
60 * Connect to HTC service.
61 * This has to be done before calling ath10k_htt_rx_attach,
62 * since ath10k_htt_rx_attach involves sending a rx ring configure
63 * message to the target.
64 */
65 ret = ath10k_htt_htc_attach(htt);
66 if (ret) {
67 ath10k_err("could not attach htt htc (%d)\n", ret);
68 goto err_htc_attach;
69 }
70
71 ret = ath10k_htt_tx_attach(htt);
72 if (ret) {
73 ath10k_err("could not attach htt tx (%d)\n", ret);
74 goto err_htc_attach;
75 }
76
77 ret = ath10k_htt_rx_attach(htt);
78 if (ret) {
79 ath10k_err("could not attach htt rx (%d)\n", ret);
80 goto err_rx_attach;
81 }
82
83 /*
84 * Prefetch enough data to satisfy target 59 * Prefetch enough data to satisfy target
85 * classification engine. 60 * classification engine.
86 * This is for LL chips. HL chips will probably 61 * This is for LL chips. HL chips will probably
@@ -93,11 +68,6 @@ int ath10k_htt_attach(struct ath10k *ar)
93 2; /* ip4 dscp or ip6 priority */ 68 2; /* ip4 dscp or ip6 priority */
94 69
95 return 0; 70 return 0;
96
97err_rx_attach:
98 ath10k_htt_tx_detach(htt);
99err_htc_attach:
100 return ret;
101} 71}
102 72
103#define HTT_TARGET_VERSION_TIMEOUT_HZ (3*HZ) 73#define HTT_TARGET_VERSION_TIMEOUT_HZ (3*HZ)
@@ -117,7 +87,7 @@ static int ath10k_htt_verify_version(struct ath10k_htt *htt)
117 return 0; 87 return 0;
118} 88}
119 89
120int ath10k_htt_attach_target(struct ath10k_htt *htt) 90int ath10k_htt_setup(struct ath10k_htt *htt)
121{ 91{
122 int status; 92 int status;
123 93
@@ -140,9 +110,3 @@ int ath10k_htt_attach_target(struct ath10k_htt *htt)
140 110
141 return ath10k_htt_send_rx_ring_cfg_ll(htt); 111 return ath10k_htt_send_rx_ring_cfg_ll(htt);
142} 112}
143
144void ath10k_htt_detach(struct ath10k_htt *htt)
145{
146 ath10k_htt_rx_detach(htt);
147 ath10k_htt_tx_detach(htt);
148}
diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/ath/ath10k/htt.h
index 645a563e3fb9..9a263462c793 100644
--- a/drivers/net/wireless/ath/ath10k/htt.h
+++ b/drivers/net/wireless/ath/ath10k/htt.h
@@ -1328,14 +1328,16 @@ struct htt_rx_desc {
1328#define HTT_LOG2_MAX_CACHE_LINE_SIZE 7 /* 2^7 = 128 */ 1328#define HTT_LOG2_MAX_CACHE_LINE_SIZE 7 /* 2^7 = 128 */
1329#define HTT_MAX_CACHE_LINE_SIZE_MASK ((1 << HTT_LOG2_MAX_CACHE_LINE_SIZE) - 1) 1329#define HTT_MAX_CACHE_LINE_SIZE_MASK ((1 << HTT_LOG2_MAX_CACHE_LINE_SIZE) - 1)
1330 1330
1331int ath10k_htt_attach(struct ath10k *ar); 1331int ath10k_htt_connect(struct ath10k_htt *htt);
1332int ath10k_htt_attach_target(struct ath10k_htt *htt); 1332int ath10k_htt_init(struct ath10k *ar);
1333void ath10k_htt_detach(struct ath10k_htt *htt); 1333int ath10k_htt_setup(struct ath10k_htt *htt);
1334 1334
1335int ath10k_htt_tx_attach(struct ath10k_htt *htt); 1335int ath10k_htt_tx_alloc(struct ath10k_htt *htt);
1336void ath10k_htt_tx_detach(struct ath10k_htt *htt); 1336void ath10k_htt_tx_free(struct ath10k_htt *htt);
1337int ath10k_htt_rx_attach(struct ath10k_htt *htt); 1337
1338void ath10k_htt_rx_detach(struct ath10k_htt *htt); 1338int ath10k_htt_rx_alloc(struct ath10k_htt *htt);
1339void ath10k_htt_rx_free(struct ath10k_htt *htt);
1340
1339void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb); 1341void ath10k_htt_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb);
1340void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb); 1342void ath10k_htt_t2h_msg_handler(struct ath10k *ar, struct sk_buff *skb);
1341int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt); 1343int ath10k_htt_h2t_ver_req_msg(struct ath10k_htt *htt);
diff --git a/drivers/net/wireless/ath/ath10k/htt_rx.c b/drivers/net/wireless/ath/ath10k/htt_rx.c
index f85a3cf6da31..6c102b1312ff 100644
--- a/drivers/net/wireless/ath/ath10k/htt_rx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_rx.c
@@ -225,10 +225,26 @@ static void ath10k_htt_rx_ring_refill_retry(unsigned long arg)
225 ath10k_htt_rx_msdu_buff_replenish(htt); 225 ath10k_htt_rx_msdu_buff_replenish(htt);
226} 226}
227 227
228void ath10k_htt_rx_detach(struct ath10k_htt *htt) 228static void ath10k_htt_rx_ring_clean_up(struct ath10k_htt *htt)
229{ 229{
230 int sw_rd_idx = htt->rx_ring.sw_rd_idx.msdu_payld; 230 struct sk_buff *skb;
231 int i;
232
233 for (i = 0; i < htt->rx_ring.size; i++) {
234 skb = htt->rx_ring.netbufs_ring[i];
235 if (!skb)
236 continue;
237
238 dma_unmap_single(htt->ar->dev, ATH10K_SKB_CB(skb)->paddr,
239 skb->len + skb_tailroom(skb),
240 DMA_FROM_DEVICE);
241 dev_kfree_skb_any(skb);
242 htt->rx_ring.netbufs_ring[i] = NULL;
243 }
244}
231 245
246void ath10k_htt_rx_free(struct ath10k_htt *htt)
247{
232 del_timer_sync(&htt->rx_ring.refill_retry_timer); 248 del_timer_sync(&htt->rx_ring.refill_retry_timer);
233 tasklet_kill(&htt->rx_replenish_task); 249 tasklet_kill(&htt->rx_replenish_task);
234 tasklet_kill(&htt->txrx_compl_task); 250 tasklet_kill(&htt->txrx_compl_task);
@@ -236,18 +252,7 @@ void ath10k_htt_rx_detach(struct ath10k_htt *htt)
236 skb_queue_purge(&htt->tx_compl_q); 252 skb_queue_purge(&htt->tx_compl_q);
237 skb_queue_purge(&htt->rx_compl_q); 253 skb_queue_purge(&htt->rx_compl_q);
238 254
239 while (sw_rd_idx != __le32_to_cpu(*(htt->rx_ring.alloc_idx.vaddr))) { 255 ath10k_htt_rx_ring_clean_up(htt);
240 struct sk_buff *skb =
241 htt->rx_ring.netbufs_ring[sw_rd_idx];
242 struct ath10k_skb_cb *cb = ATH10K_SKB_CB(skb);
243
244 dma_unmap_single(htt->ar->dev, cb->paddr,
245 skb->len + skb_tailroom(skb),
246 DMA_FROM_DEVICE);
247 dev_kfree_skb_any(htt->rx_ring.netbufs_ring[sw_rd_idx]);
248 sw_rd_idx++;
249 sw_rd_idx &= htt->rx_ring.size_mask;
250 }
251 256
252 dma_free_coherent(htt->ar->dev, 257 dma_free_coherent(htt->ar->dev,
253 (htt->rx_ring.size * 258 (htt->rx_ring.size *
@@ -277,6 +282,7 @@ static inline struct sk_buff *ath10k_htt_rx_netbuf_pop(struct ath10k_htt *htt)
277 282
278 idx = htt->rx_ring.sw_rd_idx.msdu_payld; 283 idx = htt->rx_ring.sw_rd_idx.msdu_payld;
279 msdu = htt->rx_ring.netbufs_ring[idx]; 284 msdu = htt->rx_ring.netbufs_ring[idx];
285 htt->rx_ring.netbufs_ring[idx] = NULL;
280 286
281 idx++; 287 idx++;
282 idx &= htt->rx_ring.size_mask; 288 idx &= htt->rx_ring.size_mask;
@@ -306,6 +312,7 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
306 int msdu_len, msdu_chaining = 0; 312 int msdu_len, msdu_chaining = 0;
307 struct sk_buff *msdu; 313 struct sk_buff *msdu;
308 struct htt_rx_desc *rx_desc; 314 struct htt_rx_desc *rx_desc;
315 bool corrupted = false;
309 316
310 lockdep_assert_held(&htt->rx_ring.lock); 317 lockdep_assert_held(&htt->rx_ring.lock);
311 318
@@ -399,7 +406,6 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
399 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0), 406 msdu_len = MS(__le32_to_cpu(rx_desc->msdu_start.info0),
400 RX_MSDU_START_INFO0_MSDU_LENGTH); 407 RX_MSDU_START_INFO0_MSDU_LENGTH);
401 msdu_chained = rx_desc->frag_info.ring2_more_count; 408 msdu_chained = rx_desc->frag_info.ring2_more_count;
402 msdu_chaining = msdu_chained;
403 409
404 if (msdu_len_invalid) 410 if (msdu_len_invalid)
405 msdu_len = 0; 411 msdu_len = 0;
@@ -427,11 +433,15 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
427 433
428 msdu->next = next; 434 msdu->next = next;
429 msdu = next; 435 msdu = next;
436 msdu_chaining = 1;
430 } 437 }
431 438
432 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) & 439 last_msdu = __le32_to_cpu(rx_desc->msdu_end.info0) &
433 RX_MSDU_END_INFO0_LAST_MSDU; 440 RX_MSDU_END_INFO0_LAST_MSDU;
434 441
442 if (msdu_chaining && !last_msdu)
443 corrupted = true;
444
435 if (last_msdu) { 445 if (last_msdu) {
436 msdu->next = NULL; 446 msdu->next = NULL;
437 break; 447 break;
@@ -447,6 +457,20 @@ static int ath10k_htt_rx_amsdu_pop(struct ath10k_htt *htt,
447 msdu_chaining = -1; 457 msdu_chaining = -1;
448 458
449 /* 459 /*
460 * Apparently FW sometimes reports weird chained MSDU sequences with
461 * more than one rx descriptor. This seems like a bug but needs more
462 * analyzing. For the time being fix it by dropping such sequences to
463 * avoid blowing up the host system.
464 */
465 if (corrupted) {
466 ath10k_warn("failed to pop chained msdus, dropping\n");
467 ath10k_htt_rx_free_msdu_chain(*head_msdu);
468 *head_msdu = NULL;
469 *tail_msdu = NULL;
470 msdu_chaining = -EINVAL;
471 }
472
473 /*
450 * Don't refill the ring yet. 474 * Don't refill the ring yet.
451 * 475 *
452 * First, the elements popped here are still in use - it is not 476 * First, the elements popped here are still in use - it is not
@@ -468,7 +492,7 @@ static void ath10k_htt_rx_replenish_task(unsigned long ptr)
468 ath10k_htt_rx_msdu_buff_replenish(htt); 492 ath10k_htt_rx_msdu_buff_replenish(htt);
469} 493}
470 494
471int ath10k_htt_rx_attach(struct ath10k_htt *htt) 495int ath10k_htt_rx_alloc(struct ath10k_htt *htt)
472{ 496{
473 dma_addr_t paddr; 497 dma_addr_t paddr;
474 void *vaddr; 498 void *vaddr;
@@ -494,7 +518,7 @@ int ath10k_htt_rx_attach(struct ath10k_htt *htt)
494 htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt); 518 htt->rx_ring.fill_level = ath10k_htt_rx_ring_fill_level(htt);
495 519
496 htt->rx_ring.netbufs_ring = 520 htt->rx_ring.netbufs_ring =
497 kmalloc(htt->rx_ring.size * sizeof(struct sk_buff *), 521 kzalloc(htt->rx_ring.size * sizeof(struct sk_buff *),
498 GFP_KERNEL); 522 GFP_KERNEL);
499 if (!htt->rx_ring.netbufs_ring) 523 if (!htt->rx_ring.netbufs_ring)
500 goto err_netbuf; 524 goto err_netbuf;
@@ -754,17 +778,30 @@ static void ath10k_htt_rx_h_rates(struct ath10k *ar,
754static void ath10k_htt_rx_h_protected(struct ath10k_htt *htt, 778static void ath10k_htt_rx_h_protected(struct ath10k_htt *htt,
755 struct ieee80211_rx_status *rx_status, 779 struct ieee80211_rx_status *rx_status,
756 struct sk_buff *skb, 780 struct sk_buff *skb,
757 enum htt_rx_mpdu_encrypt_type enctype) 781 enum htt_rx_mpdu_encrypt_type enctype,
782 enum rx_msdu_decap_format fmt,
783 bool dot11frag)
758{ 784{
759 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 785 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
760 786
787 rx_status->flag &= ~(RX_FLAG_DECRYPTED |
788 RX_FLAG_IV_STRIPPED |
789 RX_FLAG_MMIC_STRIPPED);
761 790
762 if (enctype == HTT_RX_MPDU_ENCRYPT_NONE) { 791 if (enctype == HTT_RX_MPDU_ENCRYPT_NONE)
763 rx_status->flag &= ~(RX_FLAG_DECRYPTED | 792 return;
764 RX_FLAG_IV_STRIPPED | 793
765 RX_FLAG_MMIC_STRIPPED); 794 /*
795 * There's no explicit rx descriptor flag to indicate whether a given
796 * frame has been decrypted or not. We're forced to use the decap
797 * format as an implicit indication. However fragmentation rx is always
798 * raw and it probably never reports undecrypted raws.
799 *
800 * This makes sure sniffed frames are reported as-is without stripping
801 * the protected flag.
802 */
803 if (fmt == RX_MSDU_DECAP_RAW && !dot11frag)
766 return; 804 return;
767 }
768 805
769 rx_status->flag |= RX_FLAG_DECRYPTED | 806 rx_status->flag |= RX_FLAG_DECRYPTED |
770 RX_FLAG_IV_STRIPPED | 807 RX_FLAG_IV_STRIPPED |
@@ -918,7 +955,8 @@ static void ath10k_htt_rx_amsdu(struct ath10k_htt *htt,
918 } 955 }
919 956
920 skb_in = skb; 957 skb_in = skb;
921 ath10k_htt_rx_h_protected(htt, rx_status, skb_in, enctype); 958 ath10k_htt_rx_h_protected(htt, rx_status, skb_in, enctype, fmt,
959 false);
922 skb = skb->next; 960 skb = skb->next;
923 skb_in->next = NULL; 961 skb_in->next = NULL;
924 962
@@ -1000,7 +1038,7 @@ static void ath10k_htt_rx_msdu(struct ath10k_htt *htt,
1000 break; 1038 break;
1001 } 1039 }
1002 1040
1003 ath10k_htt_rx_h_protected(htt, rx_status, skb, enctype); 1041 ath10k_htt_rx_h_protected(htt, rx_status, skb, enctype, fmt, false);
1004 1042
1005 ath10k_process_rx(htt->ar, rx_status, skb); 1043 ath10k_process_rx(htt->ar, rx_status, skb);
1006} 1044}
@@ -1288,6 +1326,7 @@ static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1288 } 1326 }
1289 1327
1290 /* FIXME: implement signal strength */ 1328 /* FIXME: implement signal strength */
1329 rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
1291 1330
1292 hdr = (struct ieee80211_hdr *)msdu_head->data; 1331 hdr = (struct ieee80211_hdr *)msdu_head->data;
1293 rxd = (void *)msdu_head->data - sizeof(*rxd); 1332 rxd = (void *)msdu_head->data - sizeof(*rxd);
@@ -1306,7 +1345,8 @@ static void ath10k_htt_rx_frag_handler(struct ath10k_htt *htt,
1306 1345
1307 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0), 1346 enctype = MS(__le32_to_cpu(rxd->mpdu_start.info0),
1308 RX_MPDU_START_INFO0_ENCRYPT_TYPE); 1347 RX_MPDU_START_INFO0_ENCRYPT_TYPE);
1309 ath10k_htt_rx_h_protected(htt, rx_status, msdu_head, enctype); 1348 ath10k_htt_rx_h_protected(htt, rx_status, msdu_head, enctype, fmt,
1349 true);
1310 msdu_head->ip_summed = ath10k_htt_rx_get_csum_state(msdu_head); 1350 msdu_head->ip_summed = ath10k_htt_rx_get_csum_state(msdu_head);
1311 1351
1312 if (tkip_mic_err) 1352 if (tkip_mic_err)
diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireless/ath/ath10k/htt_tx.c
index 7a3e2e40dd5c..7064354d1f4f 100644
--- a/drivers/net/wireless/ath/ath10k/htt_tx.c
+++ b/drivers/net/wireless/ath/ath10k/htt_tx.c
@@ -83,7 +83,7 @@ void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id)
83 __clear_bit(msdu_id, htt->used_msdu_ids); 83 __clear_bit(msdu_id, htt->used_msdu_ids);
84} 84}
85 85
86int ath10k_htt_tx_attach(struct ath10k_htt *htt) 86int ath10k_htt_tx_alloc(struct ath10k_htt *htt)
87{ 87{
88 spin_lock_init(&htt->tx_lock); 88 spin_lock_init(&htt->tx_lock);
89 init_waitqueue_head(&htt->empty_tx_wq); 89 init_waitqueue_head(&htt->empty_tx_wq);
@@ -120,7 +120,7 @@ int ath10k_htt_tx_attach(struct ath10k_htt *htt)
120 return 0; 120 return 0;
121} 121}
122 122
123static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt) 123static void ath10k_htt_tx_free_pending(struct ath10k_htt *htt)
124{ 124{
125 struct htt_tx_done tx_done = {0}; 125 struct htt_tx_done tx_done = {0};
126 int msdu_id; 126 int msdu_id;
@@ -141,9 +141,9 @@ static void ath10k_htt_tx_cleanup_pending(struct ath10k_htt *htt)
141 spin_unlock_bh(&htt->tx_lock); 141 spin_unlock_bh(&htt->tx_lock);
142} 142}
143 143
144void ath10k_htt_tx_detach(struct ath10k_htt *htt) 144void ath10k_htt_tx_free(struct ath10k_htt *htt)
145{ 145{
146 ath10k_htt_tx_cleanup_pending(htt); 146 ath10k_htt_tx_free_pending(htt);
147 kfree(htt->pending_tx); 147 kfree(htt->pending_tx);
148 kfree(htt->used_msdu_ids); 148 kfree(htt->used_msdu_ids);
149 dma_pool_destroy(htt->tx_pool); 149 dma_pool_destroy(htt->tx_pool);
diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
index 7026f021ccbb..a21080028c54 100644
--- a/drivers/net/wireless/ath/ath10k/mac.c
+++ b/drivers/net/wireless/ath/ath10k/mac.c
@@ -54,7 +54,10 @@ static int ath10k_send_key(struct ath10k_vif *arvif,
54 switch (key->cipher) { 54 switch (key->cipher) {
55 case WLAN_CIPHER_SUITE_CCMP: 55 case WLAN_CIPHER_SUITE_CCMP:
56 arg.key_cipher = WMI_CIPHER_AES_CCM; 56 arg.key_cipher = WMI_CIPHER_AES_CCM;
57 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX; 57 if (arvif->vdev_type == WMI_VDEV_TYPE_AP)
58 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
59 else
60 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
58 break; 61 break;
59 case WLAN_CIPHER_SUITE_TKIP: 62 case WLAN_CIPHER_SUITE_TKIP:
60 arg.key_cipher = WMI_CIPHER_TKIP; 63 arg.key_cipher = WMI_CIPHER_TKIP;
@@ -1888,8 +1891,13 @@ static void ath10k_tx_wep_key_work(struct work_struct *work)
1888 wep_key_work); 1891 wep_key_work);
1889 int ret, keyidx = arvif->def_wep_key_newidx; 1892 int ret, keyidx = arvif->def_wep_key_newidx;
1890 1893
1894 mutex_lock(&arvif->ar->conf_mutex);
1895
1896 if (arvif->ar->state != ATH10K_STATE_ON)
1897 goto unlock;
1898
1891 if (arvif->def_wep_key_idx == keyidx) 1899 if (arvif->def_wep_key_idx == keyidx)
1892 return; 1900 goto unlock;
1893 1901
1894 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n", 1902 ath10k_dbg(ATH10K_DBG_MAC, "mac vdev %d set keyidx %d\n",
1895 arvif->vdev_id, keyidx); 1903 arvif->vdev_id, keyidx);
@@ -1902,10 +1910,13 @@ static void ath10k_tx_wep_key_work(struct work_struct *work)
1902 ath10k_warn("failed to update wep key index for vdev %d: %d\n", 1910 ath10k_warn("failed to update wep key index for vdev %d: %d\n",
1903 arvif->vdev_id, 1911 arvif->vdev_id,
1904 ret); 1912 ret);
1905 return; 1913 goto unlock;
1906 } 1914 }
1907 1915
1908 arvif->def_wep_key_idx = keyidx; 1916 arvif->def_wep_key_idx = keyidx;
1917
1918unlock:
1919 mutex_unlock(&arvif->ar->conf_mutex);
1909} 1920}
1910 1921
1911static void ath10k_tx_h_update_wep_key(struct sk_buff *skb) 1922static void ath10k_tx_h_update_wep_key(struct sk_buff *skb)
@@ -2286,9 +2297,19 @@ static void ath10k_tx(struct ieee80211_hw *hw,
2286 ath10k_tx_htt(ar, skb); 2297 ath10k_tx_htt(ar, skb);
2287} 2298}
2288 2299
2289/* 2300/* Must not be called with conf_mutex held as workers can use that also. */
2290 * Initialize various parameters with default vaules. 2301static void ath10k_drain_tx(struct ath10k *ar)
2291 */ 2302{
2303 /* make sure rcu-protected mac80211 tx path itself is drained */
2304 synchronize_net();
2305
2306 ath10k_offchan_tx_purge(ar);
2307 ath10k_mgmt_over_wmi_tx_purge(ar);
2308
2309 cancel_work_sync(&ar->offchan_tx_work);
2310 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2311}
2312
2292void ath10k_halt(struct ath10k *ar) 2313void ath10k_halt(struct ath10k *ar)
2293{ 2314{
2294 struct ath10k_vif *arvif; 2315 struct ath10k_vif *arvif;
@@ -2303,19 +2324,12 @@ void ath10k_halt(struct ath10k *ar)
2303 } 2324 }
2304 2325
2305 del_timer_sync(&ar->scan.timeout); 2326 del_timer_sync(&ar->scan.timeout);
2306 ath10k_offchan_tx_purge(ar); 2327 ath10k_reset_scan((unsigned long)ar);
2307 ath10k_mgmt_over_wmi_tx_purge(ar);
2308 ath10k_peer_cleanup_all(ar); 2328 ath10k_peer_cleanup_all(ar);
2309 ath10k_core_stop(ar); 2329 ath10k_core_stop(ar);
2310 ath10k_hif_power_down(ar); 2330 ath10k_hif_power_down(ar);
2311 2331
2312 spin_lock_bh(&ar->data_lock); 2332 spin_lock_bh(&ar->data_lock);
2313 if (ar->scan.in_progress) {
2314 del_timer(&ar->scan.timeout);
2315 ar->scan.in_progress = false;
2316 ieee80211_scan_completed(ar->hw, true);
2317 }
2318
2319 list_for_each_entry(arvif, &ar->arvifs, list) { 2333 list_for_each_entry(arvif, &ar->arvifs, list) {
2320 if (!arvif->beacon) 2334 if (!arvif->beacon)
2321 continue; 2335 continue;
@@ -2329,46 +2343,125 @@ void ath10k_halt(struct ath10k *ar)
2329 spin_unlock_bh(&ar->data_lock); 2343 spin_unlock_bh(&ar->data_lock);
2330} 2344}
2331 2345
2346static int ath10k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2347{
2348 struct ath10k *ar = hw->priv;
2349
2350 mutex_lock(&ar->conf_mutex);
2351
2352 if (ar->cfg_tx_chainmask) {
2353 *tx_ant = ar->cfg_tx_chainmask;
2354 *rx_ant = ar->cfg_rx_chainmask;
2355 } else {
2356 *tx_ant = ar->supp_tx_chainmask;
2357 *rx_ant = ar->supp_rx_chainmask;
2358 }
2359
2360 mutex_unlock(&ar->conf_mutex);
2361
2362 return 0;
2363}
2364
2365static int __ath10k_set_antenna(struct ath10k *ar, u32 tx_ant, u32 rx_ant)
2366{
2367 int ret;
2368
2369 lockdep_assert_held(&ar->conf_mutex);
2370
2371 ar->cfg_tx_chainmask = tx_ant;
2372 ar->cfg_rx_chainmask = rx_ant;
2373
2374 if ((ar->state != ATH10K_STATE_ON) &&
2375 (ar->state != ATH10K_STATE_RESTARTED))
2376 return 0;
2377
2378 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->tx_chain_mask,
2379 tx_ant);
2380 if (ret) {
2381 ath10k_warn("failed to set tx-chainmask: %d, req 0x%x\n",
2382 ret, tx_ant);
2383 return ret;
2384 }
2385
2386 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->rx_chain_mask,
2387 rx_ant);
2388 if (ret) {
2389 ath10k_warn("failed to set rx-chainmask: %d, req 0x%x\n",
2390 ret, rx_ant);
2391 return ret;
2392 }
2393
2394 return 0;
2395}
2396
2397static int ath10k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
2398{
2399 struct ath10k *ar = hw->priv;
2400 int ret;
2401
2402 mutex_lock(&ar->conf_mutex);
2403 ret = __ath10k_set_antenna(ar, tx_ant, rx_ant);
2404 mutex_unlock(&ar->conf_mutex);
2405 return ret;
2406}
2407
2332static int ath10k_start(struct ieee80211_hw *hw) 2408static int ath10k_start(struct ieee80211_hw *hw)
2333{ 2409{
2334 struct ath10k *ar = hw->priv; 2410 struct ath10k *ar = hw->priv;
2335 int ret = 0; 2411 int ret = 0;
2336 2412
2413 /*
2414 * This makes sense only when restarting hw. It is harmless to call
2415 * uncoditionally. This is necessary to make sure no HTT/WMI tx
2416 * commands will be submitted while restarting.
2417 */
2418 ath10k_drain_tx(ar);
2419
2337 mutex_lock(&ar->conf_mutex); 2420 mutex_lock(&ar->conf_mutex);
2338 2421
2339 if (ar->state != ATH10K_STATE_OFF && 2422 switch (ar->state) {
2340 ar->state != ATH10K_STATE_RESTARTING) { 2423 case ATH10K_STATE_OFF:
2424 ar->state = ATH10K_STATE_ON;
2425 break;
2426 case ATH10K_STATE_RESTARTING:
2427 ath10k_halt(ar);
2428 ar->state = ATH10K_STATE_RESTARTED;
2429 break;
2430 case ATH10K_STATE_ON:
2431 case ATH10K_STATE_RESTARTED:
2432 case ATH10K_STATE_WEDGED:
2433 WARN_ON(1);
2341 ret = -EINVAL; 2434 ret = -EINVAL;
2342 goto exit; 2435 goto err;
2343 } 2436 }
2344 2437
2345 ret = ath10k_hif_power_up(ar); 2438 ret = ath10k_hif_power_up(ar);
2346 if (ret) { 2439 if (ret) {
2347 ath10k_err("Could not init hif: %d\n", ret); 2440 ath10k_err("Could not init hif: %d\n", ret);
2348 ar->state = ATH10K_STATE_OFF; 2441 goto err_off;
2349 goto exit;
2350 } 2442 }
2351 2443
2352 ret = ath10k_core_start(ar); 2444 ret = ath10k_core_start(ar);
2353 if (ret) { 2445 if (ret) {
2354 ath10k_err("Could not init core: %d\n", ret); 2446 ath10k_err("Could not init core: %d\n", ret);
2355 ath10k_hif_power_down(ar); 2447 goto err_power_down;
2356 ar->state = ATH10K_STATE_OFF;
2357 goto exit;
2358 } 2448 }
2359 2449
2360 if (ar->state == ATH10K_STATE_OFF)
2361 ar->state = ATH10K_STATE_ON;
2362 else if (ar->state == ATH10K_STATE_RESTARTING)
2363 ar->state = ATH10K_STATE_RESTARTED;
2364
2365 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1); 2450 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->pmf_qos, 1);
2366 if (ret) 2451 if (ret) {
2367 ath10k_warn("failed to enable PMF QOS: %d\n", ret); 2452 ath10k_warn("failed to enable PMF QOS: %d\n", ret);
2453 goto err_core_stop;
2454 }
2368 2455
2369 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1); 2456 ret = ath10k_wmi_pdev_set_param(ar, ar->wmi.pdev_param->dynamic_bw, 1);
2370 if (ret) 2457 if (ret) {
2371 ath10k_warn("failed to enable dynamic BW: %d\n", ret); 2458 ath10k_warn("failed to enable dynamic BW: %d\n", ret);
2459 goto err_core_stop;
2460 }
2461
2462 if (ar->cfg_tx_chainmask)
2463 __ath10k_set_antenna(ar, ar->cfg_tx_chainmask,
2464 ar->cfg_rx_chainmask);
2372 2465
2373 /* 2466 /*
2374 * By default FW set ARP frames ac to voice (6). In that case ARP 2467 * By default FW set ARP frames ac to voice (6). In that case ARP
@@ -2384,14 +2477,25 @@ static int ath10k_start(struct ieee80211_hw *hw)
2384 if (ret) { 2477 if (ret) {
2385 ath10k_warn("failed to set arp ac override parameter: %d\n", 2478 ath10k_warn("failed to set arp ac override parameter: %d\n",
2386 ret); 2479 ret);
2387 goto exit; 2480 goto err_core_stop;
2388 } 2481 }
2389 2482
2390 ar->num_started_vdevs = 0; 2483 ar->num_started_vdevs = 0;
2391 ath10k_regd_update(ar); 2484 ath10k_regd_update(ar);
2392 ret = 0;
2393 2485
2394exit: 2486 mutex_unlock(&ar->conf_mutex);
2487 return 0;
2488
2489err_core_stop:
2490 ath10k_core_stop(ar);
2491
2492err_power_down:
2493 ath10k_hif_power_down(ar);
2494
2495err_off:
2496 ar->state = ATH10K_STATE_OFF;
2497
2498err:
2395 mutex_unlock(&ar->conf_mutex); 2499 mutex_unlock(&ar->conf_mutex);
2396 return ret; 2500 return ret;
2397} 2501}
@@ -2400,19 +2504,15 @@ static void ath10k_stop(struct ieee80211_hw *hw)
2400{ 2504{
2401 struct ath10k *ar = hw->priv; 2505 struct ath10k *ar = hw->priv;
2402 2506
2507 ath10k_drain_tx(ar);
2508
2403 mutex_lock(&ar->conf_mutex); 2509 mutex_lock(&ar->conf_mutex);
2404 if (ar->state == ATH10K_STATE_ON || 2510 if (ar->state != ATH10K_STATE_OFF) {
2405 ar->state == ATH10K_STATE_RESTARTED ||
2406 ar->state == ATH10K_STATE_WEDGED)
2407 ath10k_halt(ar); 2511 ath10k_halt(ar);
2408 2512 ar->state = ATH10K_STATE_OFF;
2409 ar->state = ATH10K_STATE_OFF; 2513 }
2410 mutex_unlock(&ar->conf_mutex); 2514 mutex_unlock(&ar->conf_mutex);
2411 2515
2412 ath10k_mgmt_over_wmi_tx_purge(ar);
2413
2414 cancel_work_sync(&ar->offchan_tx_work);
2415 cancel_work_sync(&ar->wmi_mgmt_tx_work);
2416 cancel_work_sync(&ar->restart_work); 2516 cancel_work_sync(&ar->restart_work);
2417} 2517}
2418 2518
@@ -2925,7 +3025,12 @@ static void ath10k_bss_info_changed(struct ieee80211_hw *hw,
2925 arvif->u.ap.hidden_ssid = info->hidden_ssid; 3025 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2926 } 3026 }
2927 3027
2928 if (changed & BSS_CHANGED_BSSID) { 3028 /*
3029 * Firmware manages AP self-peer internally so make sure to not create
3030 * it in driver. Otherwise AP self-peer deletion may timeout later.
3031 */
3032 if (changed & BSS_CHANGED_BSSID &&
3033 vif->type != NL80211_IFTYPE_AP) {
2929 if (!is_zero_ether_addr(info->bssid)) { 3034 if (!is_zero_ether_addr(info->bssid)) {
2930 ath10k_dbg(ATH10K_DBG_MAC, 3035 ath10k_dbg(ATH10K_DBG_MAC,
2931 "mac vdev %d create peer %pM\n", 3036 "mac vdev %d create peer %pM\n",
@@ -4142,14 +4247,6 @@ static int ath10k_set_bitrate_mask(struct ieee80211_hw *hw,
4142 fixed_nss, force_sgi); 4247 fixed_nss, force_sgi);
4143} 4248}
4144 4249
4145static void ath10k_channel_switch_beacon(struct ieee80211_hw *hw,
4146 struct ieee80211_vif *vif,
4147 struct cfg80211_chan_def *chandef)
4148{
4149 /* there's no need to do anything here. vif->csa_active is enough */
4150 return;
4151}
4152
4153static void ath10k_sta_rc_update(struct ieee80211_hw *hw, 4250static void ath10k_sta_rc_update(struct ieee80211_hw *hw,
4154 struct ieee80211_vif *vif, 4251 struct ieee80211_vif *vif,
4155 struct ieee80211_sta *sta, 4252 struct ieee80211_sta *sta,
@@ -4253,10 +4350,11 @@ static const struct ieee80211_ops ath10k_ops = {
4253 .set_frag_threshold = ath10k_set_frag_threshold, 4350 .set_frag_threshold = ath10k_set_frag_threshold,
4254 .flush = ath10k_flush, 4351 .flush = ath10k_flush,
4255 .tx_last_beacon = ath10k_tx_last_beacon, 4352 .tx_last_beacon = ath10k_tx_last_beacon,
4353 .set_antenna = ath10k_set_antenna,
4354 .get_antenna = ath10k_get_antenna,
4256 .restart_complete = ath10k_restart_complete, 4355 .restart_complete = ath10k_restart_complete,
4257 .get_survey = ath10k_get_survey, 4356 .get_survey = ath10k_get_survey,
4258 .set_bitrate_mask = ath10k_set_bitrate_mask, 4357 .set_bitrate_mask = ath10k_set_bitrate_mask,
4259 .channel_switch_beacon = ath10k_channel_switch_beacon,
4260 .sta_rc_update = ath10k_sta_rc_update, 4358 .sta_rc_update = ath10k_sta_rc_update,
4261 .get_tsf = ath10k_get_tsf, 4359 .get_tsf = ath10k_get_tsf,
4262#ifdef CONFIG_PM 4360#ifdef CONFIG_PM
@@ -4602,6 +4700,18 @@ int ath10k_mac_register(struct ath10k *ar)
4602 BIT(NL80211_IFTYPE_ADHOC) | 4700 BIT(NL80211_IFTYPE_ADHOC) |
4603 BIT(NL80211_IFTYPE_AP); 4701 BIT(NL80211_IFTYPE_AP);
4604 4702
4703 if (test_bit(ATH10K_FW_FEATURE_WMI_10X, ar->fw_features)) {
4704 /* TODO: Have to deal with 2x2 chips if/when the come out. */
4705 ar->supp_tx_chainmask = TARGET_10X_TX_CHAIN_MASK;
4706 ar->supp_rx_chainmask = TARGET_10X_RX_CHAIN_MASK;
4707 } else {
4708 ar->supp_tx_chainmask = TARGET_TX_CHAIN_MASK;
4709 ar->supp_rx_chainmask = TARGET_RX_CHAIN_MASK;
4710 }
4711
4712 ar->hw->wiphy->available_antennas_rx = ar->supp_rx_chainmask;
4713 ar->hw->wiphy->available_antennas_tx = ar->supp_tx_chainmask;
4714
4605 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features)) 4715 if (!test_bit(ATH10K_FW_FEATURE_NO_P2P, ar->fw_features))
4606 ar->hw->wiphy->interface_modes |= 4716 ar->hw->wiphy->interface_modes |=
4607 BIT(NL80211_IFTYPE_P2P_CLIENT) | 4717 BIT(NL80211_IFTYPE_P2P_CLIENT) |
diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
index 66b1f3017f2b..d0004d59c97e 100644
--- a/drivers/net/wireless/ath/ath10k/pci.c
+++ b/drivers/net/wireless/ath/ath10k/pci.c
@@ -59,6 +59,7 @@ MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)");
59 59
60/* how long wait to wait for target to initialise, in ms */ 60/* how long wait to wait for target to initialise, in ms */
61#define ATH10K_PCI_TARGET_WAIT 3000 61#define ATH10K_PCI_TARGET_WAIT 3000
62#define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3
62 63
63#define QCA988X_2_0_DEVICE_ID (0x003c) 64#define QCA988X_2_0_DEVICE_ID (0x003c)
64 65
@@ -761,17 +762,21 @@ static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
761 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id]; 762 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
762 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl; 763 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
763 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring; 764 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
764 unsigned int nentries_mask = src_ring->nentries_mask; 765 unsigned int nentries_mask;
765 unsigned int sw_index = src_ring->sw_index; 766 unsigned int sw_index;
766 unsigned int write_index = src_ring->write_index; 767 unsigned int write_index;
767 int err, i; 768 int err, i = 0;
768 769
769 spin_lock_bh(&ar_pci->ce_lock); 770 spin_lock_bh(&ar_pci->ce_lock);
770 771
772 nentries_mask = src_ring->nentries_mask;
773 sw_index = src_ring->sw_index;
774 write_index = src_ring->write_index;
775
771 if (unlikely(CE_RING_DELTA(nentries_mask, 776 if (unlikely(CE_RING_DELTA(nentries_mask,
772 write_index, sw_index - 1) < n_items)) { 777 write_index, sw_index - 1) < n_items)) {
773 err = -ENOBUFS; 778 err = -ENOBUFS;
774 goto unlock; 779 goto err;
775 } 780 }
776 781
777 for (i = 0; i < n_items - 1; i++) { 782 for (i = 0; i < n_items - 1; i++) {
@@ -788,7 +793,7 @@ static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
788 items[i].transfer_id, 793 items[i].transfer_id,
789 CE_SEND_FLAG_GATHER); 794 CE_SEND_FLAG_GATHER);
790 if (err) 795 if (err)
791 goto unlock; 796 goto err;
792 } 797 }
793 798
794 /* `i` is equal to `n_items -1` after for() */ 799 /* `i` is equal to `n_items -1` after for() */
@@ -806,10 +811,15 @@ static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
806 items[i].transfer_id, 811 items[i].transfer_id,
807 0); 812 0);
808 if (err) 813 if (err)
809 goto unlock; 814 goto err;
815
816 spin_unlock_bh(&ar_pci->ce_lock);
817 return 0;
818
819err:
820 for (; i > 0; i--)
821 __ath10k_ce_send_revert(ce_pipe);
810 822
811 err = 0;
812unlock:
813 spin_unlock_bh(&ar_pci->ce_lock); 823 spin_unlock_bh(&ar_pci->ce_lock);
814 return err; 824 return err;
815} 825}
@@ -1271,6 +1281,9 @@ static void ath10k_pci_hif_stop(struct ath10k *ar)
1271 1281
1272 ath10k_dbg(ATH10K_DBG_BOOT, "boot hif stop\n"); 1282 ath10k_dbg(ATH10K_DBG_BOOT, "boot hif stop\n");
1273 1283
1284 if (WARN_ON(!ar_pci->started))
1285 return;
1286
1274 ret = ath10k_ce_disable_interrupts(ar); 1287 ret = ath10k_ce_disable_interrupts(ar);
1275 if (ret) 1288 if (ret)
1276 ath10k_warn("failed to disable CE interrupts: %d\n", ret); 1289 ath10k_warn("failed to disable CE interrupts: %d\n", ret);
@@ -1802,6 +1815,26 @@ static void ath10k_pci_fw_interrupt_handler(struct ath10k *ar)
1802 ath10k_pci_sleep(ar); 1815 ath10k_pci_sleep(ar);
1803} 1816}
1804 1817
1818/* this function effectively clears target memory controller assert line */
1819static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
1820{
1821 u32 val;
1822
1823 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1824 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
1825 val | SOC_RESET_CONTROL_SI0_RST_MASK);
1826 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1827
1828 msleep(10);
1829
1830 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1831 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
1832 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
1833 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1834
1835 msleep(10);
1836}
1837
1805static int ath10k_pci_warm_reset(struct ath10k *ar) 1838static int ath10k_pci_warm_reset(struct ath10k *ar)
1806{ 1839{
1807 int ret = 0; 1840 int ret = 0;
@@ -1860,6 +1893,8 @@ static int ath10k_pci_warm_reset(struct ath10k *ar)
1860 SOC_RESET_CONTROL_ADDRESS); 1893 SOC_RESET_CONTROL_ADDRESS);
1861 msleep(10); 1894 msleep(10);
1862 1895
1896 ath10k_pci_warm_reset_si0(ar);
1897
1863 /* debug */ 1898 /* debug */
1864 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + 1899 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1865 PCIE_INTR_CAUSE_ADDRESS); 1900 PCIE_INTR_CAUSE_ADDRESS);
@@ -1988,6 +2023,28 @@ err:
1988 return ret; 2023 return ret;
1989} 2024}
1990 2025
2026static int ath10k_pci_hif_power_up_warm(struct ath10k *ar)
2027{
2028 int i, ret;
2029
2030 /*
2031 * Sometime warm reset succeeds after retries.
2032 *
2033 * FIXME: It might be possible to tune ath10k_pci_warm_reset() to work
2034 * at first try.
2035 */
2036 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2037 ret = __ath10k_pci_hif_power_up(ar, false);
2038 if (ret == 0)
2039 break;
2040
2041 ath10k_warn("failed to warm reset (attempt %d out of %d): %d\n",
2042 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS, ret);
2043 }
2044
2045 return ret;
2046}
2047
1991static int ath10k_pci_hif_power_up(struct ath10k *ar) 2048static int ath10k_pci_hif_power_up(struct ath10k *ar)
1992{ 2049{
1993 int ret; 2050 int ret;
@@ -1999,10 +2056,10 @@ static int ath10k_pci_hif_power_up(struct ath10k *ar)
1999 * preferred (and safer) way to perform a device reset is through a 2056 * preferred (and safer) way to perform a device reset is through a
2000 * warm reset. 2057 * warm reset.
2001 * 2058 *
2002 * Warm reset doesn't always work though (notably after a firmware 2059 * Warm reset doesn't always work though so fall back to cold reset may
2003 * crash) so fall back to cold reset if necessary. 2060 * be necessary.
2004 */ 2061 */
2005 ret = __ath10k_pci_hif_power_up(ar, false); 2062 ret = ath10k_pci_hif_power_up_warm(ar);
2006 if (ret) { 2063 if (ret) {
2007 ath10k_warn("failed to power up target using warm reset: %d\n", 2064 ath10k_warn("failed to power up target using warm reset: %d\n",
2008 ret); 2065 ret);
@@ -2196,10 +2253,7 @@ static void ath10k_pci_early_irq_tasklet(unsigned long data)
2196 if (fw_ind & FW_IND_EVENT_PENDING) { 2253 if (fw_ind & FW_IND_EVENT_PENDING) {
2197 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 2254 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS,
2198 fw_ind & ~FW_IND_EVENT_PENDING); 2255 fw_ind & ~FW_IND_EVENT_PENDING);
2199 2256 ath10k_pci_hif_dump_area(ar);
2200 /* Some structures are unavailable during early boot or at
2201 * driver teardown so just print that the device has crashed. */
2202 ath10k_warn("device crashed - no diagnostics available\n");
2203 } 2257 }
2204 2258
2205 ath10k_pci_sleep(ar); 2259 ath10k_pci_sleep(ar);
@@ -2476,6 +2530,9 @@ static int ath10k_pci_wait_for_target_init(struct ath10k *ar)
2476 2530
2477 if (val & FW_IND_EVENT_PENDING) { 2531 if (val & FW_IND_EVENT_PENDING) {
2478 ath10k_warn("device has crashed during init\n"); 2532 ath10k_warn("device has crashed during init\n");
2533 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS,
2534 val & ~FW_IND_EVENT_PENDING);
2535 ath10k_pci_hif_dump_area(ar);
2479 ret = -ECOMM; 2536 ret = -ECOMM;
2480 goto out; 2537 goto out;
2481 } 2538 }
@@ -2602,18 +2659,6 @@ static int ath10k_pci_probe(struct pci_dev *pdev,
2602 2659
2603 pci_set_drvdata(pdev, ar); 2660 pci_set_drvdata(pdev, ar);
2604 2661
2605 /*
2606 * Without any knowledge of the Host, the Target may have been reset or
2607 * power cycled and its Config Space may no longer reflect the PCI
2608 * address space that was assigned earlier by the PCI infrastructure.
2609 * Refresh it now.
2610 */
2611 ret = pci_assign_resource(pdev, BAR_NUM);
2612 if (ret) {
2613 ath10k_err("failed to assign PCI space: %d\n", ret);
2614 goto err_ar;
2615 }
2616
2617 ret = pci_enable_device(pdev); 2662 ret = pci_enable_device(pdev);
2618 if (ret) { 2663 if (ret) {
2619 ath10k_err("failed to enable PCI device: %d\n", ret); 2664 ath10k_err("failed to enable PCI device: %d\n", ret);
@@ -2725,8 +2770,6 @@ static void ath10k_pci_remove(struct pci_dev *pdev)
2725 if (!ar_pci) 2770 if (!ar_pci)
2726 return; 2771 return;
2727 2772
2728 tasklet_kill(&ar_pci->msi_fw_err);
2729
2730 ath10k_core_unregister(ar); 2773 ath10k_core_unregister(ar);
2731 ath10k_pci_free_ce(ar); 2774 ath10k_pci_free_ce(ar);
2732 2775
diff --git a/drivers/net/wireless/ath/ath10k/wmi.c b/drivers/net/wireless/ath/ath10k/wmi.c
index 72cc4f20d102..4b7782a529ac 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.c
+++ b/drivers/net/wireless/ath/ath10k/wmi.c
@@ -639,6 +639,7 @@ int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
639 struct sk_buff *wmi_skb; 639 struct sk_buff *wmi_skb;
640 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 640 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
641 int len; 641 int len;
642 u32 buf_len = skb->len;
642 u16 fc; 643 u16 fc;
643 644
644 hdr = (struct ieee80211_hdr *)skb->data; 645 hdr = (struct ieee80211_hdr *)skb->data;
@@ -648,6 +649,15 @@ int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
648 return -EINVAL; 649 return -EINVAL;
649 650
650 len = sizeof(cmd->hdr) + skb->len; 651 len = sizeof(cmd->hdr) + skb->len;
652
653 if ((ieee80211_is_action(hdr->frame_control) ||
654 ieee80211_is_deauth(hdr->frame_control) ||
655 ieee80211_is_disassoc(hdr->frame_control)) &&
656 ieee80211_has_protected(hdr->frame_control)) {
657 len += IEEE80211_CCMP_MIC_LEN;
658 buf_len += IEEE80211_CCMP_MIC_LEN;
659 }
660
651 len = round_up(len, 4); 661 len = round_up(len, 4);
652 662
653 wmi_skb = ath10k_wmi_alloc_skb(len); 663 wmi_skb = ath10k_wmi_alloc_skb(len);
@@ -659,7 +669,7 @@ int ath10k_wmi_mgmt_tx(struct ath10k *ar, struct sk_buff *skb)
659 cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id); 669 cmd->hdr.vdev_id = __cpu_to_le32(ATH10K_SKB_CB(skb)->vdev_id);
660 cmd->hdr.tx_rate = 0; 670 cmd->hdr.tx_rate = 0;
661 cmd->hdr.tx_power = 0; 671 cmd->hdr.tx_power = 0;
662 cmd->hdr.buf_len = __cpu_to_le32((u32)(skb->len)); 672 cmd->hdr.buf_len = __cpu_to_le32(buf_len);
663 673
664 memcpy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr), ETH_ALEN); 674 memcpy(cmd->hdr.peer_macaddr.addr, ieee80211_get_DA(hdr), ETH_ALEN);
665 memcpy(cmd->buf, skb->data, skb->len); 675 memcpy(cmd->buf, skb->data, skb->len);
@@ -957,10 +967,16 @@ static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
957 * frames with Protected Bit set. */ 967 * frames with Protected Bit set. */
958 if (ieee80211_has_protected(hdr->frame_control) && 968 if (ieee80211_has_protected(hdr->frame_control) &&
959 !ieee80211_is_auth(hdr->frame_control)) { 969 !ieee80211_is_auth(hdr->frame_control)) {
960 status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED | 970 status->flag |= RX_FLAG_DECRYPTED;
961 RX_FLAG_MMIC_STRIPPED; 971
962 hdr->frame_control = __cpu_to_le16(fc & 972 if (!ieee80211_is_action(hdr->frame_control) &&
973 !ieee80211_is_deauth(hdr->frame_control) &&
974 !ieee80211_is_disassoc(hdr->frame_control)) {
975 status->flag |= RX_FLAG_IV_STRIPPED |
976 RX_FLAG_MMIC_STRIPPED;
977 hdr->frame_control = __cpu_to_le16(fc &
963 ~IEEE80211_FCTL_PROTECTED); 978 ~IEEE80211_FCTL_PROTECTED);
979 }
964 } 980 }
965 981
966 ath10k_dbg(ATH10K_DBG_MGMT, 982 ath10k_dbg(ATH10K_DBG_MGMT,
@@ -2359,7 +2375,7 @@ void ath10k_wmi_detach(struct ath10k *ar)
2359 ar->wmi.num_mem_chunks = 0; 2375 ar->wmi.num_mem_chunks = 0;
2360} 2376}
2361 2377
2362int ath10k_wmi_connect_htc_service(struct ath10k *ar) 2378int ath10k_wmi_connect(struct ath10k *ar)
2363{ 2379{
2364 int status; 2380 int status;
2365 struct ath10k_htc_svc_conn_req conn_req; 2381 struct ath10k_htc_svc_conn_req conn_req;
diff --git a/drivers/net/wireless/ath/ath10k/wmi.h b/drivers/net/wireless/ath/ath10k/wmi.h
index ae838221af65..89ef3b3749eb 100644
--- a/drivers/net/wireless/ath/ath10k/wmi.h
+++ b/drivers/net/wireless/ath/ath10k/wmi.h
@@ -2323,9 +2323,9 @@ struct wmi_pdev_param_map {
2323#define WMI_PDEV_PARAM_UNSUPPORTED 0 2323#define WMI_PDEV_PARAM_UNSUPPORTED 0
2324 2324
2325enum wmi_pdev_param { 2325enum wmi_pdev_param {
2326 /* TX chian mask */ 2326 /* TX chain mask */
2327 WMI_PDEV_PARAM_TX_CHAIN_MASK = 0x1, 2327 WMI_PDEV_PARAM_TX_CHAIN_MASK = 0x1,
2328 /* RX chian mask */ 2328 /* RX chain mask */
2329 WMI_PDEV_PARAM_RX_CHAIN_MASK, 2329 WMI_PDEV_PARAM_RX_CHAIN_MASK,
2330 /* TX power limit for 2G Radio */ 2330 /* TX power limit for 2G Radio */
2331 WMI_PDEV_PARAM_TXPOWER_LIMIT2G, 2331 WMI_PDEV_PARAM_TXPOWER_LIMIT2G,
@@ -4259,7 +4259,7 @@ void ath10k_wmi_detach(struct ath10k *ar);
4259int ath10k_wmi_wait_for_service_ready(struct ath10k *ar); 4259int ath10k_wmi_wait_for_service_ready(struct ath10k *ar);
4260int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar); 4260int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar);
4261 4261
4262int ath10k_wmi_connect_htc_service(struct ath10k *ar); 4262int ath10k_wmi_connect(struct ath10k *ar);
4263int ath10k_wmi_pdev_set_channel(struct ath10k *ar, 4263int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
4264 const struct wmi_channel_arg *); 4264 const struct wmi_channel_arg *);
4265int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt); 4265int ath10k_wmi_pdev_suspend_target(struct ath10k *ar, u32 suspend_opt);
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index b20469425865..2ca8f7e06174 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -770,6 +770,7 @@ struct ath_softc {
770 struct ath_ant_comb ant_comb; 770 struct ath_ant_comb ant_comb;
771 u8 ant_tx, ant_rx; 771 u8 ant_tx, ant_rx;
772 struct dfs_pattern_detector *dfs_detector; 772 struct dfs_pattern_detector *dfs_detector;
773 u64 dfs_prev_pulse_ts;
773 u32 wow_enabled; 774 u32 wow_enabled;
774 /* relay(fs) channel for spectral scan */ 775 /* relay(fs) channel for spectral scan */
775 struct rchan *rfs_chan_spec_scan; 776 struct rchan *rfs_chan_spec_scan;
diff --git a/drivers/net/wireless/ath/ath9k/dfs.c b/drivers/net/wireless/ath/ath9k/dfs.c
index e0c740dcfea8..726271c7c330 100644
--- a/drivers/net/wireless/ath/ath9k/dfs.c
+++ b/drivers/net/wireless/ath/ath9k/dfs.c
@@ -178,14 +178,12 @@ void ath9k_dfs_process_phyerr(struct ath_softc *sc, void *data,
178 pe.ts = mactime; 178 pe.ts = mactime;
179 if (ath9k_postprocess_radar_event(sc, &ard, &pe)) { 179 if (ath9k_postprocess_radar_event(sc, &ard, &pe)) {
180 struct dfs_pattern_detector *pd = sc->dfs_detector; 180 struct dfs_pattern_detector *pd = sc->dfs_detector;
181#ifdef CONFIG_ATH9K_DEBUGFS
182 ath_dbg(common, DFS, 181 ath_dbg(common, DFS,
183 "ath9k_dfs_process_phyerr: channel=%d, ts=%llu, " 182 "ath9k_dfs_process_phyerr: channel=%d, ts=%llu, "
184 "width=%d, rssi=%d, delta_ts=%llu\n", 183 "width=%d, rssi=%d, delta_ts=%llu\n",
185 pe.freq, pe.ts, pe.width, pe.rssi, 184 pe.freq, pe.ts, pe.width, pe.rssi,
186 pe.ts - sc->debug.stats.dfs_stats.last_ts); 185 pe.ts - sc->dfs_prev_pulse_ts);
187 sc->debug.stats.dfs_stats.last_ts = pe.ts; 186 sc->dfs_prev_pulse_ts = pe.ts;
188#endif
189 DFS_STAT_INC(sc, pulses_processed); 187 DFS_STAT_INC(sc, pulses_processed);
190 if (pd != NULL && pd->add_pulse(pd, &pe)) { 188 if (pd != NULL && pd->add_pulse(pd, &pe)) {
191 DFS_STAT_INC(sc, radar_detected); 189 DFS_STAT_INC(sc, radar_detected);
diff --git a/drivers/net/wireless/ath/ath9k/dfs_debug.h b/drivers/net/wireless/ath/ath9k/dfs_debug.h
index d9486867a5e0..7936c9126a20 100644
--- a/drivers/net/wireless/ath/ath9k/dfs_debug.h
+++ b/drivers/net/wireless/ath/ath9k/dfs_debug.h
@@ -51,7 +51,6 @@ struct ath_dfs_stats {
51 /* pattern detection stats */ 51 /* pattern detection stats */
52 u32 pulses_processed; 52 u32 pulses_processed;
53 u32 radar_detected; 53 u32 radar_detected;
54 u64 last_ts;
55}; 54};
56 55
57#if defined(CONFIG_ATH9K_DFS_DEBUGFS) 56#if defined(CONFIG_ATH9K_DFS_DEBUGFS)
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index 1af77081181e..0246b990fe87 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -61,6 +61,10 @@ static int ath9k_ps_enable;
61module_param_named(ps_enable, ath9k_ps_enable, int, 0444); 61module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
62MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave"); 62MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
63 63
64static int ath9k_use_chanctx;
65module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
66MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
67
64bool is_ath9k_unloaded; 68bool is_ath9k_unloaded;
65 69
66#ifdef CONFIG_MAC80211_LEDS 70#ifdef CONFIG_MAC80211_LEDS
@@ -646,8 +650,7 @@ static void ath9k_init_txpower_limits(struct ath_softc *sc)
646} 650}
647 651
648static const struct ieee80211_iface_limit if_limits[] = { 652static const struct ieee80211_iface_limit if_limits[] = {
649 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) | 653 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
650 BIT(NL80211_IFTYPE_WDS) },
651 { .max = 8, .types = 654 { .max = 8, .types =
652#ifdef CONFIG_MAC80211_MESH 655#ifdef CONFIG_MAC80211_MESH
653 BIT(NL80211_IFTYPE_MESH_POINT) | 656 BIT(NL80211_IFTYPE_MESH_POINT) |
@@ -657,6 +660,10 @@ static const struct ieee80211_iface_limit if_limits[] = {
657 BIT(NL80211_IFTYPE_P2P_GO) }, 660 BIT(NL80211_IFTYPE_P2P_GO) },
658}; 661};
659 662
663static const struct ieee80211_iface_limit wds_limits[] = {
664 { .max = 2048, .types = BIT(NL80211_IFTYPE_WDS) },
665};
666
660static const struct ieee80211_iface_limit if_dfs_limits[] = { 667static const struct ieee80211_iface_limit if_dfs_limits[] = {
661 { .max = 1, .types = BIT(NL80211_IFTYPE_AP) | 668 { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
662#ifdef CONFIG_MAC80211_MESH 669#ifdef CONFIG_MAC80211_MESH
@@ -673,6 +680,13 @@ static const struct ieee80211_iface_combination if_comb[] = {
673 .num_different_channels = 1, 680 .num_different_channels = 1,
674 .beacon_int_infra_match = true, 681 .beacon_int_infra_match = true,
675 }, 682 },
683 {
684 .limits = wds_limits,
685 .n_limits = ARRAY_SIZE(wds_limits),
686 .max_interfaces = 2048,
687 .num_different_channels = 1,
688 .beacon_int_infra_match = true,
689 },
676#ifdef CONFIG_ATH9K_DFS_CERTIFIED 690#ifdef CONFIG_ATH9K_DFS_CERTIFIED
677 { 691 {
678 .limits = if_dfs_limits, 692 .limits = if_dfs_limits,
@@ -722,12 +736,15 @@ static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
722 BIT(NL80211_IFTYPE_P2P_GO) | 736 BIT(NL80211_IFTYPE_P2P_GO) |
723 BIT(NL80211_IFTYPE_P2P_CLIENT) | 737 BIT(NL80211_IFTYPE_P2P_CLIENT) |
724 BIT(NL80211_IFTYPE_AP) | 738 BIT(NL80211_IFTYPE_AP) |
725 BIT(NL80211_IFTYPE_WDS) |
726 BIT(NL80211_IFTYPE_STATION) | 739 BIT(NL80211_IFTYPE_STATION) |
727 BIT(NL80211_IFTYPE_ADHOC) | 740 BIT(NL80211_IFTYPE_ADHOC) |
728 BIT(NL80211_IFTYPE_MESH_POINT); 741 BIT(NL80211_IFTYPE_MESH_POINT);
729 hw->wiphy->iface_combinations = if_comb; 742 hw->wiphy->iface_combinations = if_comb;
730 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 743 if (!ath9k_use_chanctx) {
744 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
745 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_WDS);
746 } else
747 hw->wiphy->n_iface_combinations = 1;
731 } 748 }
732 749
733 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 750 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 6965ceac7bc6..62ac95d6bb9d 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -1757,7 +1757,6 @@ out:
1757void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif) 1757void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1758{ 1758{
1759 struct ath_vif *avp = (void *)vif->drv_priv; 1759 struct ath_vif *avp = (void *)vif->drv_priv;
1760 unsigned long flags;
1761 u32 tsf; 1760 u32 tsf;
1762 1761
1763 if (!sc->p2p_ps_timer) 1762 if (!sc->p2p_ps_timer)
@@ -1767,14 +1766,9 @@ void ath9k_update_p2p_ps(struct ath_softc *sc, struct ieee80211_vif *vif)
1767 return; 1766 return;
1768 1767
1769 sc->p2p_ps_vif = avp; 1768 sc->p2p_ps_vif = avp;
1770 1769 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1771 spin_lock_irqsave(&sc->sc_pm_lock, flags); 1770 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1772 if (!(sc->ps_flags & PS_BEACON_SYNC)) { 1771 ath9k_update_p2p_ps_timer(sc, avp);
1773 tsf = ath9k_hw_gettsf32(sc->sc_ah);
1774 ieee80211_parse_p2p_noa(&vif->bss_conf.p2p_noa_attr, &avp->noa, tsf);
1775 ath9k_update_p2p_ps_timer(sc, avp);
1776 }
1777 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1778} 1772}
1779 1773
1780static void ath9k_bss_info_changed(struct ieee80211_hw *hw, 1774static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
@@ -1791,6 +1785,7 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1791 struct ath_hw *ah = sc->sc_ah; 1785 struct ath_hw *ah = sc->sc_ah;
1792 struct ath_common *common = ath9k_hw_common(ah); 1786 struct ath_common *common = ath9k_hw_common(ah);
1793 struct ath_vif *avp = (void *)vif->drv_priv; 1787 struct ath_vif *avp = (void *)vif->drv_priv;
1788 unsigned long flags;
1794 int slottime; 1789 int slottime;
1795 1790
1796 ath9k_ps_wakeup(sc); 1791 ath9k_ps_wakeup(sc);
@@ -1853,7 +1848,10 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1853 1848
1854 if (changed & BSS_CHANGED_P2P_PS) { 1849 if (changed & BSS_CHANGED_P2P_PS) {
1855 spin_lock_bh(&sc->sc_pcu_lock); 1850 spin_lock_bh(&sc->sc_pcu_lock);
1856 ath9k_update_p2p_ps(sc, vif); 1851 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1852 if (!(sc->ps_flags & PS_BEACON_SYNC))
1853 ath9k_update_p2p_ps(sc, vif);
1854 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1857 spin_unlock_bh(&sc->sc_pcu_lock); 1855 spin_unlock_bh(&sc->sc_pcu_lock);
1858 } 1856 }
1859 1857
@@ -2232,14 +2230,6 @@ static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
2232 clear_bit(ATH_OP_SCANNING, &common->op_flags); 2230 clear_bit(ATH_OP_SCANNING, &common->op_flags);
2233} 2231}
2234 2232
2235static void ath9k_channel_switch_beacon(struct ieee80211_hw *hw,
2236 struct ieee80211_vif *vif,
2237 struct cfg80211_chan_def *chandef)
2238{
2239 /* depend on vif->csa_active only */
2240 return;
2241}
2242
2243struct ieee80211_ops ath9k_ops = { 2233struct ieee80211_ops ath9k_ops = {
2244 .tx = ath9k_tx, 2234 .tx = ath9k_tx,
2245 .start = ath9k_start, 2235 .start = ath9k_start,
@@ -2287,5 +2277,4 @@ struct ieee80211_ops ath9k_ops = {
2287#endif 2277#endif
2288 .sw_scan_start = ath9k_sw_scan_start, 2278 .sw_scan_start = ath9k_sw_scan_start,
2289 .sw_scan_complete = ath9k_sw_scan_complete, 2279 .sw_scan_complete = ath9k_sw_scan_complete,
2290 .channel_switch_beacon = ath9k_channel_switch_beacon,
2291}; 2280};
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index 43ae199601f7..9105a92364f7 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -34,7 +34,8 @@ static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
34 * buffer (or rx fifo). This can incorrectly acknowledge packets 34 * buffer (or rx fifo). This can incorrectly acknowledge packets
35 * to a sender if last desc is self-linked. 35 * to a sender if last desc is self-linked.
36 */ 36 */
37static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf) 37static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf,
38 bool flush)
38{ 39{
39 struct ath_hw *ah = sc->sc_ah; 40 struct ath_hw *ah = sc->sc_ah;
40 struct ath_common *common = ath9k_hw_common(ah); 41 struct ath_common *common = ath9k_hw_common(ah);
@@ -59,18 +60,19 @@ static void ath_rx_buf_link(struct ath_softc *sc, struct ath_rxbuf *bf)
59 common->rx_bufsize, 60 common->rx_bufsize,
60 0); 61 0);
61 62
62 if (sc->rx.rxlink == NULL) 63 if (sc->rx.rxlink)
63 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
64 else
65 *sc->rx.rxlink = bf->bf_daddr; 64 *sc->rx.rxlink = bf->bf_daddr;
65 else if (!flush)
66 ath9k_hw_putrxbuf(ah, bf->bf_daddr);
66 67
67 sc->rx.rxlink = &ds->ds_link; 68 sc->rx.rxlink = &ds->ds_link;
68} 69}
69 70
70static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf) 71static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_rxbuf *bf,
72 bool flush)
71{ 73{
72 if (sc->rx.buf_hold) 74 if (sc->rx.buf_hold)
73 ath_rx_buf_link(sc, sc->rx.buf_hold); 75 ath_rx_buf_link(sc, sc->rx.buf_hold, flush);
74 76
75 sc->rx.buf_hold = bf; 77 sc->rx.buf_hold = bf;
76} 78}
@@ -442,7 +444,7 @@ int ath_startrecv(struct ath_softc *sc)
442 sc->rx.buf_hold = NULL; 444 sc->rx.buf_hold = NULL;
443 sc->rx.rxlink = NULL; 445 sc->rx.rxlink = NULL;
444 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) { 446 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
445 ath_rx_buf_link(sc, bf); 447 ath_rx_buf_link(sc, bf, false);
446 } 448 }
447 449
448 /* We could have deleted elements so the list may be empty now */ 450 /* We could have deleted elements so the list may be empty now */
@@ -1118,12 +1120,12 @@ requeue_drop_frag:
1118requeue: 1120requeue:
1119 list_add_tail(&bf->list, &sc->rx.rxbuf); 1121 list_add_tail(&bf->list, &sc->rx.rxbuf);
1120 1122
1121 if (edma) { 1123 if (!edma) {
1122 ath_rx_edma_buf_link(sc, qtype); 1124 ath_rx_buf_relink(sc, bf, flush);
1123 } else {
1124 ath_rx_buf_relink(sc, bf);
1125 if (!flush) 1125 if (!flush)
1126 ath9k_hw_rxena(ah); 1126 ath9k_hw_rxena(ah);
1127 } else if (!flush) {
1128 ath_rx_edma_buf_link(sc, qtype);
1127 } 1129 }
1128 1130
1129 if (!budget--) 1131 if (!budget--)
diff --git a/drivers/net/wireless/ath/wcn36xx/smd.c b/drivers/net/wireless/ath/wcn36xx/smd.c
index 7bf0ef8a1f56..63986931829e 100644
--- a/drivers/net/wireless/ath/wcn36xx/smd.c
+++ b/drivers/net/wireless/ath/wcn36xx/smd.c
@@ -2068,7 +2068,7 @@ static void wcn36xx_smd_rsp_process(struct wcn36xx *wcn, void *buf, size_t len)
2068 if (!msg_ind) 2068 if (!msg_ind)
2069 goto nomem; 2069 goto nomem;
2070 msg_ind->msg_len = len; 2070 msg_ind->msg_len = len;
2071 msg_ind->msg = kmalloc(len, GFP_KERNEL); 2071 msg_ind->msg = kmemdup(buf, len, GFP_KERNEL);
2072 if (!msg_ind->msg) { 2072 if (!msg_ind->msg) {
2073 kfree(msg_ind); 2073 kfree(msg_ind);
2074nomem: 2074nomem:
@@ -2080,7 +2080,6 @@ nomem:
2080 msg_header->msg_type); 2080 msg_header->msg_type);
2081 break; 2081 break;
2082 } 2082 }
2083 memcpy(msg_ind->msg, buf, len);
2084 mutex_lock(&wcn->hal_ind_mutex); 2083 mutex_lock(&wcn->hal_ind_mutex);
2085 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue); 2084 list_add_tail(&msg_ind->list, &wcn->hal_ind_queue);
2086 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work); 2085 queue_work(wcn->hal_ind_wq, &wcn->hal_ind_work);
diff --git a/drivers/net/wireless/ath/wil6210/cfg80211.c b/drivers/net/wireless/ath/wil6210/cfg80211.c
index 6e699d050d1e..820d4ebd9322 100644
--- a/drivers/net/wireless/ath/wil6210/cfg80211.c
+++ b/drivers/net/wireless/ath/wil6210/cfg80211.c
@@ -288,6 +288,7 @@ static int wil_cfg80211_scan(struct wiphy *wiphy,
288 } 288 }
289 289
290 wil->scan_request = request; 290 wil->scan_request = request;
291 mod_timer(&wil->scan_timer, jiffies + WIL6210_SCAN_TO);
291 292
292 memset(&cmd, 0, sizeof(cmd)); 293 memset(&cmd, 0, sizeof(cmd));
293 cmd.cmd.num_channels = 0; 294 cmd.cmd.num_channels = 0;
diff --git a/drivers/net/wireless/ath/wil6210/debugfs.c b/drivers/net/wireless/ath/wil6210/debugfs.c
index ecdabe4adec3..8d4bc4bfb664 100644
--- a/drivers/net/wireless/ath/wil6210/debugfs.c
+++ b/drivers/net/wireless/ath/wil6210/debugfs.c
@@ -35,7 +35,7 @@ static void wil_print_vring(struct seq_file *s, struct wil6210_priv *wil,
35 void __iomem *x = wmi_addr(wil, vring->hwtail); 35 void __iomem *x = wmi_addr(wil, vring->hwtail);
36 36
37 seq_printf(s, "VRING %s = {\n", name); 37 seq_printf(s, "VRING %s = {\n", name);
38 seq_printf(s, " pa = 0x%016llx\n", (unsigned long long)vring->pa); 38 seq_printf(s, " pa = %pad\n", &vring->pa);
39 seq_printf(s, " va = 0x%p\n", vring->va); 39 seq_printf(s, " va = 0x%p\n", vring->va);
40 seq_printf(s, " size = %d\n", vring->size); 40 seq_printf(s, " size = %d\n", vring->size);
41 seq_printf(s, " swtail = %d\n", vring->swtail); 41 seq_printf(s, " swtail = %d\n", vring->swtail);
@@ -473,7 +473,7 @@ static int wil_txdesc_debugfs_show(struct seq_file *s, void *data)
473 u[0], u[1], u[2], u[3]); 473 u[0], u[1], u[2], u[3]);
474 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n", 474 seq_printf(s, " DMA = 0x%08x 0x%08x 0x%08x 0x%08x\n",
475 u[4], u[5], u[6], u[7]); 475 u[4], u[5], u[6], u[7]);
476 seq_printf(s, " SKB = %p\n", skb); 476 seq_printf(s, " SKB = 0x%p\n", skb);
477 477
478 if (skb) { 478 if (skb) {
479 skb_get(skb); 479 skb_get(skb);
diff --git a/drivers/net/wireless/ath/wil6210/main.c b/drivers/net/wireless/ath/wil6210/main.c
index 670cc6de3b4c..11e6d9d22eae 100644
--- a/drivers/net/wireless/ath/wil6210/main.c
+++ b/drivers/net/wireless/ath/wil6210/main.c
@@ -150,6 +150,15 @@ static void wil_connect_timer_fn(ulong x)
150 schedule_work(&wil->disconnect_worker); 150 schedule_work(&wil->disconnect_worker);
151} 151}
152 152
153static void wil_scan_timer_fn(ulong x)
154{
155 struct wil6210_priv *wil = (void *)x;
156
157 clear_bit(wil_status_fwready, &wil->status);
158 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
159 schedule_work(&wil->fw_error_worker);
160}
161
153static void wil_fw_error_worker(struct work_struct *work) 162static void wil_fw_error_worker(struct work_struct *work)
154{ 163{
155 struct wil6210_priv *wil = container_of(work, 164 struct wil6210_priv *wil = container_of(work,
@@ -161,12 +170,30 @@ static void wil_fw_error_worker(struct work_struct *work)
161 if (no_fw_recovery) 170 if (no_fw_recovery)
162 return; 171 return;
163 172
173 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
174 * passed since last recovery attempt
175 */
176 if (time_is_after_jiffies(wil->last_fw_recovery +
177 WIL6210_FW_RECOVERY_TO))
178 wil->recovery_count++;
179 else
180 wil->recovery_count = 1; /* fw was alive for a long time */
181
182 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
183 wil_err(wil, "too many recovery attempts (%d), giving up\n",
184 wil->recovery_count);
185 return;
186 }
187
188 wil->last_fw_recovery = jiffies;
189
164 mutex_lock(&wil->mutex); 190 mutex_lock(&wil->mutex);
165 switch (wdev->iftype) { 191 switch (wdev->iftype) {
166 case NL80211_IFTYPE_STATION: 192 case NL80211_IFTYPE_STATION:
167 case NL80211_IFTYPE_P2P_CLIENT: 193 case NL80211_IFTYPE_P2P_CLIENT:
168 case NL80211_IFTYPE_MONITOR: 194 case NL80211_IFTYPE_MONITOR:
169 wil_info(wil, "fw error recovery started...\n"); 195 wil_info(wil, "fw error recovery started (try %d)...\n",
196 wil->recovery_count);
170 wil_reset(wil); 197 wil_reset(wil);
171 198
172 /* need to re-allocate Rx ring after reset */ 199 /* need to re-allocate Rx ring after reset */
@@ -230,6 +257,7 @@ int wil_priv_init(struct wil6210_priv *wil)
230 257
231 wil->pending_connect_cid = -1; 258 wil->pending_connect_cid = -1;
232 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil); 259 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
260 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
233 261
234 INIT_WORK(&wil->connect_worker, wil_connect_worker); 262 INIT_WORK(&wil->connect_worker, wil_connect_worker);
235 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker); 263 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
@@ -249,6 +277,8 @@ int wil_priv_init(struct wil6210_priv *wil)
249 return -EAGAIN; 277 return -EAGAIN;
250 } 278 }
251 279
280 wil->last_fw_recovery = jiffies;
281
252 return 0; 282 return 0;
253} 283}
254 284
@@ -260,6 +290,7 @@ void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
260 290
261void wil_priv_deinit(struct wil6210_priv *wil) 291void wil_priv_deinit(struct wil6210_priv *wil)
262{ 292{
293 del_timer_sync(&wil->scan_timer);
263 cancel_work_sync(&wil->disconnect_worker); 294 cancel_work_sync(&wil->disconnect_worker);
264 cancel_work_sync(&wil->fw_error_worker); 295 cancel_work_sync(&wil->fw_error_worker);
265 mutex_lock(&wil->mutex); 296 mutex_lock(&wil->mutex);
@@ -391,6 +422,7 @@ int wil_reset(struct wil6210_priv *wil)
391 if (wil->scan_request) { 422 if (wil->scan_request) {
392 wil_dbg_misc(wil, "Abort scan_request 0x%p\n", 423 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
393 wil->scan_request); 424 wil->scan_request);
425 del_timer_sync(&wil->scan_timer);
394 cfg80211_scan_done(wil->scan_request, true); 426 cfg80211_scan_done(wil->scan_request, true);
395 wil->scan_request = NULL; 427 wil->scan_request = NULL;
396 } 428 }
@@ -520,6 +552,7 @@ static int __wil_down(struct wil6210_priv *wil)
520 napi_disable(&wil->napi_tx); 552 napi_disable(&wil->napi_tx);
521 553
522 if (wil->scan_request) { 554 if (wil->scan_request) {
555 del_timer_sync(&wil->scan_timer);
523 cfg80211_scan_done(wil->scan_request, true); 556 cfg80211_scan_done(wil->scan_request, true);
524 wil->scan_request = NULL; 557 wil->scan_request = NULL;
525 } 558 }
diff --git a/drivers/net/wireless/ath/wil6210/netdev.c b/drivers/net/wireless/ath/wil6210/netdev.c
index fdcaeb820e75..106b6dcb773a 100644
--- a/drivers/net/wireless/ath/wil6210/netdev.c
+++ b/drivers/net/wireless/ath/wil6210/netdev.c
@@ -32,12 +32,26 @@ static int wil_stop(struct net_device *ndev)
32 return wil_down(wil); 32 return wil_down(wil);
33} 33}
34 34
35static int wil_change_mtu(struct net_device *ndev, int new_mtu)
36{
37 struct wil6210_priv *wil = ndev_to_wil(ndev);
38
39 if (new_mtu < 68 || new_mtu > IEEE80211_MAX_DATA_LEN_DMG)
40 return -EINVAL;
41
42 wil_dbg_misc(wil, "change MTU %d -> %d\n", ndev->mtu, new_mtu);
43 ndev->mtu = new_mtu;
44
45 return 0;
46}
47
35static const struct net_device_ops wil_netdev_ops = { 48static const struct net_device_ops wil_netdev_ops = {
36 .ndo_open = wil_open, 49 .ndo_open = wil_open,
37 .ndo_stop = wil_stop, 50 .ndo_stop = wil_stop,
38 .ndo_start_xmit = wil_start_xmit, 51 .ndo_start_xmit = wil_start_xmit,
39 .ndo_set_mac_address = eth_mac_addr, 52 .ndo_set_mac_address = eth_mac_addr,
40 .ndo_validate_addr = eth_validate_addr, 53 .ndo_validate_addr = eth_validate_addr,
54 .ndo_change_mtu = wil_change_mtu,
41}; 55};
42 56
43static int wil6210_netdev_poll_rx(struct napi_struct *napi, int budget) 57static int wil6210_netdev_poll_rx(struct napi_struct *napi, int budget)
diff --git a/drivers/net/wireless/ath/wil6210/pcie_bus.c b/drivers/net/wireless/ath/wil6210/pcie_bus.c
index 066088418307..1e2e07b9d13d 100644
--- a/drivers/net/wireless/ath/wil6210/pcie_bus.c
+++ b/drivers/net/wireless/ath/wil6210/pcie_bus.c
@@ -138,7 +138,7 @@ static int wil_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
138 goto err_release_reg; 138 goto err_release_reg;
139 } 139 }
140 /* rollback to err_iounmap */ 140 /* rollback to err_iounmap */
141 dev_info(&pdev->dev, "CSR at %pR -> %p\n", &pdev->resource[0], csr); 141 dev_info(&pdev->dev, "CSR at %pR -> 0x%p\n", &pdev->resource[0], csr);
142 142
143 wil = wil_if_alloc(dev, csr); 143 wil = wil_if_alloc(dev, csr);
144 if (IS_ERR(wil)) { 144 if (IS_ERR(wil)) {
diff --git a/drivers/net/wireless/ath/wil6210/rx_reorder.c b/drivers/net/wireless/ath/wil6210/rx_reorder.c
index ec29954bd44d..747ae1275877 100644
--- a/drivers/net/wireless/ath/wil6210/rx_reorder.c
+++ b/drivers/net/wireless/ath/wil6210/rx_reorder.c
@@ -49,10 +49,17 @@ static void wil_release_reorder_frames(struct wil6210_priv *wil,
49{ 49{
50 int index; 50 int index;
51 51
52 while (seq_less(r->head_seq_num, hseq)) { 52 /* note: this function is never called with
53 * hseq preceding r->head_seq_num, i.e it is always true
54 * !seq_less(hseq, r->head_seq_num)
55 * and thus on loop exit it should be
56 * r->head_seq_num == hseq
57 */
58 while (seq_less(r->head_seq_num, hseq) && r->stored_mpdu_num) {
53 index = reorder_index(r, r->head_seq_num); 59 index = reorder_index(r, r->head_seq_num);
54 wil_release_reorder_frame(wil, r, index); 60 wil_release_reorder_frame(wil, r, index);
55 } 61 }
62 r->head_seq_num = hseq;
56} 63}
57 64
58static void wil_reorder_release(struct wil6210_priv *wil, 65static void wil_reorder_release(struct wil6210_priv *wil,
diff --git a/drivers/net/wireless/ath/wil6210/txrx.c b/drivers/net/wireless/ath/wil6210/txrx.c
index c8c547457eb4..0784ef3d4ce2 100644
--- a/drivers/net/wireless/ath/wil6210/txrx.c
+++ b/drivers/net/wireless/ath/wil6210/txrx.c
@@ -64,6 +64,22 @@ static inline int wil_vring_avail_tx(struct vring *vring)
64 return vring->size - used - 1; 64 return vring->size - used - 1;
65} 65}
66 66
67/**
68 * wil_vring_wmark_low - low watermark for available descriptor space
69 */
70static inline int wil_vring_wmark_low(struct vring *vring)
71{
72 return vring->size/8;
73}
74
75/**
76 * wil_vring_wmark_high - high watermark for available descriptor space
77 */
78static inline int wil_vring_wmark_high(struct vring *vring)
79{
80 return vring->size/4;
81}
82
67static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring) 83static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring)
68{ 84{
69 struct device *dev = wil_to_dev(wil); 85 struct device *dev = wil_to_dev(wil);
@@ -98,8 +114,8 @@ static int wil_vring_alloc(struct wil6210_priv *wil, struct vring *vring)
98 _d->dma.status = TX_DMA_STATUS_DU; 114 _d->dma.status = TX_DMA_STATUS_DU;
99 } 115 }
100 116
101 wil_dbg_misc(wil, "vring[%d] 0x%p:0x%016llx 0x%p\n", vring->size, 117 wil_dbg_misc(wil, "vring[%d] 0x%p:%pad 0x%p\n", vring->size,
102 vring->va, (unsigned long long)vring->pa, vring->ctx); 118 vring->va, &vring->pa, vring->ctx);
103 119
104 return 0; 120 return 0;
105} 121}
@@ -880,8 +896,8 @@ static int wil_tx_vring(struct wil6210_priv *wil, struct vring *vring,
880 pa = dma_map_single(dev, skb->data, 896 pa = dma_map_single(dev, skb->data,
881 skb_headlen(skb), DMA_TO_DEVICE); 897 skb_headlen(skb), DMA_TO_DEVICE);
882 898
883 wil_dbg_txrx(wil, "Tx skb %d bytes %p -> %#08llx\n", skb_headlen(skb), 899 wil_dbg_txrx(wil, "Tx skb %d bytes 0x%p -> %pad\n", skb_headlen(skb),
884 skb->data, (unsigned long long)pa); 900 skb->data, &pa);
885 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1, 901 wil_hex_dump_txrx("Tx ", DUMP_PREFIX_OFFSET, 16, 1,
886 skb->data, skb_headlen(skb), false); 902 skb->data, skb_headlen(skb), false);
887 903
@@ -1007,7 +1023,7 @@ netdev_tx_t wil_start_xmit(struct sk_buff *skb, struct net_device *ndev)
1007 rc = wil_tx_vring(wil, vring, skb); 1023 rc = wil_tx_vring(wil, vring, skb);
1008 1024
1009 /* do we still have enough room in the vring? */ 1025 /* do we still have enough room in the vring? */
1010 if (wil_vring_avail_tx(vring) < vring->size/8) 1026 if (wil_vring_avail_tx(vring) < wil_vring_wmark_low(vring))
1011 netif_tx_stop_all_queues(wil_to_ndev(wil)); 1027 netif_tx_stop_all_queues(wil_to_ndev(wil));
1012 1028
1013 switch (rc) { 1029 switch (rc) {
@@ -1116,7 +1132,7 @@ int wil_tx_complete(struct wil6210_priv *wil, int ringid)
1116 done++; 1132 done++;
1117 } 1133 }
1118 } 1134 }
1119 if (wil_vring_avail_tx(vring) > vring->size/4) 1135 if (wil_vring_avail_tx(vring) > wil_vring_wmark_high(vring))
1120 netif_tx_wake_all_queues(wil_to_ndev(wil)); 1136 netif_tx_wake_all_queues(wil_to_ndev(wil));
1121 1137
1122 return done; 1138 return done;
diff --git a/drivers/net/wireless/ath/wil6210/wil6210.h b/drivers/net/wireless/ath/wil6210/wil6210.h
index 3427ac4a4fa1..e25edc52398f 100644
--- a/drivers/net/wireless/ath/wil6210/wil6210.h
+++ b/drivers/net/wireless/ath/wil6210/wil6210.h
@@ -40,6 +40,9 @@ static inline u32 WIL_GET_BITS(u32 x, int b0, int b1)
40#define WIL6210_MAX_CID (8) /* HW limit */ 40#define WIL6210_MAX_CID (8) /* HW limit */
41#define WIL6210_NAPI_BUDGET (16) /* arbitrary */ 41#define WIL6210_NAPI_BUDGET (16) /* arbitrary */
42#define WIL6210_ITR_TRSH (10000) /* arbitrary - about 15 IRQs/msec */ 42#define WIL6210_ITR_TRSH (10000) /* arbitrary - about 15 IRQs/msec */
43#define WIL6210_FW_RECOVERY_RETRIES (5) /* try to recover this many times */
44#define WIL6210_FW_RECOVERY_TO msecs_to_jiffies(5000)
45#define WIL6210_SCAN_TO msecs_to_jiffies(10000)
43 46
44/* Hardware definitions begin */ 47/* Hardware definitions begin */
45 48
@@ -361,6 +364,8 @@ struct wil6210_priv {
361 u32 fw_version; 364 u32 fw_version;
362 u32 hw_version; 365 u32 hw_version;
363 u8 n_mids; /* number of additional MIDs as reported by FW */ 366 u8 n_mids; /* number of additional MIDs as reported by FW */
367 int recovery_count; /* num of FW recovery attempts in a short time */
368 unsigned long last_fw_recovery; /* jiffies of last fw recovery */
364 /* profile */ 369 /* profile */
365 u32 monitor_flags; 370 u32 monitor_flags;
366 u32 secure_pcp; /* create secure PCP? */ 371 u32 secure_pcp; /* create secure PCP? */
@@ -382,6 +387,7 @@ struct wil6210_priv {
382 struct work_struct disconnect_worker; 387 struct work_struct disconnect_worker;
383 struct work_struct fw_error_worker; /* for FW error recovery */ 388 struct work_struct fw_error_worker; /* for FW error recovery */
384 struct timer_list connect_timer; 389 struct timer_list connect_timer;
390 struct timer_list scan_timer; /* detect scan timeout */
385 int pending_connect_cid; 391 int pending_connect_cid;
386 struct list_head pending_wmi_ev; 392 struct list_head pending_wmi_ev;
387 /* 393 /*
diff --git a/drivers/net/wireless/ath/wil6210/wmi.c b/drivers/net/wireless/ath/wil6210/wmi.c
index e9a11cb3428a..6cc0e182cc70 100644
--- a/drivers/net/wireless/ath/wil6210/wmi.c
+++ b/drivers/net/wireless/ath/wil6210/wmi.c
@@ -351,6 +351,7 @@ static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
351 bool aborted = (data->status != WMI_SCAN_SUCCESS); 351 bool aborted = (data->status != WMI_SCAN_SUCCESS);
352 352
353 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", data->status); 353 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", data->status);
354 del_timer_sync(&wil->scan_timer);
354 cfg80211_scan_done(wil->scan_request, aborted); 355 cfg80211_scan_done(wil->scan_request, aborted);
355 wil->scan_request = NULL; 356 wil->scan_request = NULL;
356 } else { 357 } else {
@@ -658,21 +659,27 @@ void wmi_recv_cmd(struct wil6210_priv *wil)
658 u8 *cmd; 659 u8 *cmd;
659 void __iomem *src; 660 void __iomem *src;
660 ulong flags; 661 ulong flags;
662 unsigned n;
661 663
662 if (!test_bit(wil_status_reset_done, &wil->status)) { 664 if (!test_bit(wil_status_reset_done, &wil->status)) {
663 wil_err(wil, "Reset not completed\n"); 665 wil_err(wil, "Reset not completed\n");
664 return; 666 return;
665 } 667 }
666 668
667 for (;;) { 669 for (n = 0;; n++) {
668 u16 len; 670 u16 len;
669 671
670 r->head = ioread32(wil->csr + HOST_MBOX + 672 r->head = ioread32(wil->csr + HOST_MBOX +
671 offsetof(struct wil6210_mbox_ctl, rx.head)); 673 offsetof(struct wil6210_mbox_ctl, rx.head));
672 if (r->tail == r->head) 674 if (r->tail == r->head) {
675 if (n == 0)
676 wil_dbg_wmi(wil, "No events?\n");
673 return; 677 return;
678 }
674 679
675 /* read cmd from tail */ 680 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
681 r->head, r->tail);
682 /* read cmd descriptor from tail */
676 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail), 683 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
677 sizeof(struct wil6210_mbox_ring_desc)); 684 sizeof(struct wil6210_mbox_ring_desc));
678 if (d_tail.sync == 0) { 685 if (d_tail.sync == 0) {
@@ -680,13 +687,18 @@ void wmi_recv_cmd(struct wil6210_priv *wil)
680 return; 687 return;
681 } 688 }
682 689
690 /* read cmd header from descriptor */
683 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) { 691 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
684 wil_err(wil, "Mbox evt at 0x%08x?\n", 692 wil_err(wil, "Mbox evt at 0x%08x?\n",
685 le32_to_cpu(d_tail.addr)); 693 le32_to_cpu(d_tail.addr));
686 return; 694 return;
687 } 695 }
688
689 len = le16_to_cpu(hdr.len); 696 len = le16_to_cpu(hdr.len);
697 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
698 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
699 hdr.flags);
700
701 /* read cmd buffer from descriptor */
690 src = wmi_buffer(wil, d_tail.addr) + 702 src = wmi_buffer(wil, d_tail.addr) +
691 sizeof(struct wil6210_mbox_hdr); 703 sizeof(struct wil6210_mbox_hdr);
692 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event, 704 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
@@ -702,9 +714,6 @@ void wmi_recv_cmd(struct wil6210_priv *wil)
702 iowrite32(0, wil->csr + HOSTADDR(r->tail) + 714 iowrite32(0, wil->csr + HOSTADDR(r->tail) +
703 offsetof(struct wil6210_mbox_ring_desc, sync)); 715 offsetof(struct wil6210_mbox_ring_desc, sync));
704 /* indicate */ 716 /* indicate */
705 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
706 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
707 hdr.flags);
708 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) && 717 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
709 (len >= sizeof(struct wil6210_mbox_hdr_wmi))) { 718 (len >= sizeof(struct wil6210_mbox_hdr_wmi))) {
710 struct wil6210_mbox_hdr_wmi *wmi = &evt->event.wmi; 719 struct wil6210_mbox_hdr_wmi *wmi = &evt->event.wmi;
@@ -734,6 +743,8 @@ void wmi_recv_cmd(struct wil6210_priv *wil)
734 wil_dbg_wmi(wil, "queue_work -> %d\n", q); 743 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
735 } 744 }
736 } 745 }
746 if (n > 1)
747 wil_dbg_wmi(wil, "%s -> %d events processed\n", __func__, n);
737} 748}
738 749
739int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len, 750int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 3d67e6b08e1c..32538ac5f7e4 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -3742,7 +3742,9 @@ static int b43_switch_band(struct b43_wldev *dev,
3742 b43dbg(dev->wl, "Switching to %s GHz band\n", 3742 b43dbg(dev->wl, "Switching to %s GHz band\n",
3743 band_to_string(chan->band)); 3743 band_to_string(chan->band));
3744 3744
3745 b43_software_rfkill(dev, true); 3745 /* Some new devices don't need disabling radio for band switching */
3746 if (!(phy->type == B43_PHYTYPE_N && phy->rev >= 3))
3747 b43_software_rfkill(dev, true);
3746 3748
3747 phy->gmode = gmode; 3749 phy->gmode = gmode;
3748 b43_phy_put_into_reset(dev); 3750 b43_phy_put_into_reset(dev);
@@ -5164,6 +5166,7 @@ static void b43_supported_bands(struct b43_wldev *dev, bool *have_2ghz_phy,
5164static int b43_wireless_core_attach(struct b43_wldev *dev) 5166static int b43_wireless_core_attach(struct b43_wldev *dev)
5165{ 5167{
5166 struct b43_wl *wl = dev->wl; 5168 struct b43_wl *wl = dev->wl;
5169 struct b43_phy *phy = &dev->phy;
5167 int err; 5170 int err;
5168 u32 tmp; 5171 u32 tmp;
5169 bool have_2ghz_phy = false, have_5ghz_phy = false; 5172 bool have_2ghz_phy = false, have_5ghz_phy = false;
@@ -5181,6 +5184,8 @@ static int b43_wireless_core_attach(struct b43_wldev *dev)
5181 goto out; 5184 goto out;
5182 } 5185 }
5183 5186
5187 phy->do_full_init = true;
5188
5184 /* Try to guess supported bands for the first init needs */ 5189 /* Try to guess supported bands for the first init needs */
5185 switch (dev->dev->bus_type) { 5190 switch (dev->dev->bus_type) {
5186#ifdef CONFIG_B43_BCMA 5191#ifdef CONFIG_B43_BCMA
diff --git a/drivers/net/wireless/b43/phy_common.c b/drivers/net/wireless/b43/phy_common.c
index fb0ddddde16b..08244b3b327e 100644
--- a/drivers/net/wireless/b43/phy_common.c
+++ b/drivers/net/wireless/b43/phy_common.c
@@ -98,11 +98,14 @@ int b43_phy_init(struct b43_wldev *dev)
98 98
99 phy->ops->switch_analog(dev, true); 99 phy->ops->switch_analog(dev, true);
100 b43_software_rfkill(dev, false); 100 b43_software_rfkill(dev, false);
101
101 err = ops->init(dev); 102 err = ops->init(dev);
102 if (err) { 103 if (err) {
103 b43err(dev->wl, "PHY init failed\n"); 104 b43err(dev->wl, "PHY init failed\n");
104 goto err_block_rf; 105 goto err_block_rf;
105 } 106 }
107 phy->do_full_init = false;
108
106 /* Make sure to switch hardware and firmware (SHM) to 109 /* Make sure to switch hardware and firmware (SHM) to
107 * the default channel. */ 110 * the default channel. */
108 err = b43_switch_channel(dev, ops->get_default_chan(dev)); 111 err = b43_switch_channel(dev, ops->get_default_chan(dev));
@@ -114,6 +117,7 @@ int b43_phy_init(struct b43_wldev *dev)
114 return 0; 117 return 0;
115 118
116err_phy_exit: 119err_phy_exit:
120 phy->do_full_init = true;
117 if (ops->exit) 121 if (ops->exit)
118 ops->exit(dev); 122 ops->exit(dev);
119err_block_rf: 123err_block_rf:
@@ -127,6 +131,7 @@ void b43_phy_exit(struct b43_wldev *dev)
127 const struct b43_phy_operations *ops = dev->phy.ops; 131 const struct b43_phy_operations *ops = dev->phy.ops;
128 132
129 b43_software_rfkill(dev, true); 133 b43_software_rfkill(dev, true);
134 dev->phy.do_full_init = true;
130 if (ops->exit) 135 if (ops->exit)
131 ops->exit(dev); 136 ops->exit(dev);
132} 137}
diff --git a/drivers/net/wireless/b43/phy_common.h b/drivers/net/wireless/b43/phy_common.h
index 47b55855c37d..4ad6240d9ff4 100644
--- a/drivers/net/wireless/b43/phy_common.h
+++ b/drivers/net/wireless/b43/phy_common.h
@@ -234,6 +234,9 @@ struct b43_phy {
234 /* Is GMODE (2 GHz mode) bit enabled? */ 234 /* Is GMODE (2 GHz mode) bit enabled? */
235 bool gmode; 235 bool gmode;
236 236
237 /* After power reset full init has to be performed */
238 bool do_full_init;
239
237 /* Analog Type */ 240 /* Analog Type */
238 u8 analog; 241 u8 analog;
239 /* B43_PHYTYPE_ */ 242 /* B43_PHYTYPE_ */
diff --git a/drivers/net/wireless/b43/phy_n.c b/drivers/net/wireless/b43/phy_n.c
index 41dab89a2942..86569f6a8705 100644
--- a/drivers/net/wireless/b43/phy_n.c
+++ b/drivers/net/wireless/b43/phy_n.c
@@ -700,13 +700,11 @@ static void b43_radio_2057_init_post(struct b43_wldev *dev)
700 b43_radio_mask(dev, R2057_RFPLL_MISC_CAL_RESETN, ~0x78); 700 b43_radio_mask(dev, R2057_RFPLL_MISC_CAL_RESETN, ~0x78);
701 b43_radio_mask(dev, R2057_XTAL_CONFIG2, ~0x80); 701 b43_radio_mask(dev, R2057_XTAL_CONFIG2, ~0x80);
702 702
703 if (dev->phy.n->init_por) { 703 if (dev->phy.do_full_init) {
704 b43_radio_2057_rcal(dev); 704 b43_radio_2057_rcal(dev);
705 b43_radio_2057_rccal(dev); 705 b43_radio_2057_rccal(dev);
706 } 706 }
707 b43_radio_mask(dev, R2057_RFPLL_MASTER, ~0x8); 707 b43_radio_mask(dev, R2057_RFPLL_MASTER, ~0x8);
708
709 dev->phy.n->init_por = false;
710} 708}
711 709
712/* http://bcm-v4.sipsolutions.net/802.11/Radio/2057/Init */ 710/* http://bcm-v4.sipsolutions.net/802.11/Radio/2057/Init */
@@ -1028,7 +1026,7 @@ static void b43_radio_init2056_post(struct b43_wldev *dev)
1028 b43_radio_mask(dev, B2056_SYN_COM_RESET, ~0x2); 1026 b43_radio_mask(dev, B2056_SYN_COM_RESET, ~0x2);
1029 b43_radio_mask(dev, B2056_SYN_PLL_MAST2, ~0xFC); 1027 b43_radio_mask(dev, B2056_SYN_PLL_MAST2, ~0xFC);
1030 b43_radio_mask(dev, B2056_SYN_RCCAL_CTRL0, ~0x1); 1028 b43_radio_mask(dev, B2056_SYN_RCCAL_CTRL0, ~0x1);
1031 if (dev->phy.n->init_por) 1029 if (dev->phy.do_full_init)
1032 b43_radio_2056_rcal(dev); 1030 b43_radio_2056_rcal(dev);
1033} 1031}
1034 1032
@@ -1041,8 +1039,6 @@ static void b43_radio_init2056(struct b43_wldev *dev)
1041 b43_radio_init2056_pre(dev); 1039 b43_radio_init2056_pre(dev);
1042 b2056_upload_inittabs(dev, 0, 0); 1040 b2056_upload_inittabs(dev, 0, 0);
1043 b43_radio_init2056_post(dev); 1041 b43_radio_init2056_post(dev);
1044
1045 dev->phy.n->init_por = false;
1046} 1042}
1047 1043
1048/************************************************** 1044/**************************************************
@@ -5561,7 +5557,6 @@ static void b43_nphy_op_prepare_structs(struct b43_wldev *dev)
5561 nphy->hang_avoid = (phy->rev == 3 || phy->rev == 4); 5557 nphy->hang_avoid = (phy->rev == 3 || phy->rev == 4);
5562 nphy->spur_avoid = (phy->rev >= 3) ? 5558 nphy->spur_avoid = (phy->rev >= 3) ?
5563 B43_SPUR_AVOID_AUTO : B43_SPUR_AVOID_DISABLE; 5559 B43_SPUR_AVOID_AUTO : B43_SPUR_AVOID_DISABLE;
5564 nphy->init_por = true;
5565 nphy->gain_boost = true; /* this way we follow wl, assume it is true */ 5560 nphy->gain_boost = true; /* this way we follow wl, assume it is true */
5566 nphy->txrx_chain = 2; /* sth different than 0 and 1 for now */ 5561 nphy->txrx_chain = 2; /* sth different than 0 and 1 for now */
5567 nphy->phyrxchain = 3; /* to avoid b43_nphy_set_rx_core_state like wl */ 5562 nphy->phyrxchain = 3; /* to avoid b43_nphy_set_rx_core_state like wl */
@@ -5602,8 +5597,6 @@ static void b43_nphy_op_prepare_structs(struct b43_wldev *dev)
5602 nphy->ipa2g_on = sprom->fem.ghz2.extpa_gain == 2; 5597 nphy->ipa2g_on = sprom->fem.ghz2.extpa_gain == 2;
5603 nphy->ipa5g_on = sprom->fem.ghz5.extpa_gain == 2; 5598 nphy->ipa5g_on = sprom->fem.ghz5.extpa_gain == 2;
5604 } 5599 }
5605
5606 nphy->init_por = true;
5607} 5600}
5608 5601
5609static void b43_nphy_op_free(struct b43_wldev *dev) 5602static void b43_nphy_op_free(struct b43_wldev *dev)
@@ -5714,10 +5707,12 @@ static void b43_nphy_op_software_rfkill(struct b43_wldev *dev,
5714 } 5707 }
5715 } else { 5708 } else {
5716 if (dev->phy.rev >= 7) { 5709 if (dev->phy.rev >= 7) {
5717 b43_radio_2057_init(dev); 5710 if (!dev->phy.radio_on)
5711 b43_radio_2057_init(dev);
5718 b43_switch_channel(dev, dev->phy.channel); 5712 b43_switch_channel(dev, dev->phy.channel);
5719 } else if (dev->phy.rev >= 3) { 5713 } else if (dev->phy.rev >= 3) {
5720 b43_radio_init2056(dev); 5714 if (!dev->phy.radio_on)
5715 b43_radio_init2056(dev);
5721 b43_switch_channel(dev, dev->phy.channel); 5716 b43_switch_channel(dev, dev->phy.channel);
5722 } else { 5717 } else {
5723 b43_radio_init2055(dev); 5718 b43_radio_init2055(dev);
diff --git a/drivers/net/wireless/b43/phy_n.h b/drivers/net/wireless/b43/phy_n.h
index 9a5b6bc27d24..ecfbf66dbc3b 100644
--- a/drivers/net/wireless/b43/phy_n.h
+++ b/drivers/net/wireless/b43/phy_n.h
@@ -931,7 +931,6 @@ struct b43_phy_n {
931 u16 papd_epsilon_offset[2]; 931 u16 papd_epsilon_offset[2];
932 s32 preamble_override; 932 s32 preamble_override;
933 u32 bb_mult_save; 933 u32 bb_mult_save;
934 bool init_por;
935 934
936 bool gain_boost; 935 bool gain_boost;
937 bool elna_gain_config; 936 bool elna_gain_config;
diff --git a/drivers/net/wireless/b43/tables_nphy.c b/drivers/net/wireless/b43/tables_nphy.c
index 50d03ffeac8c..4047c05e3807 100644
--- a/drivers/net/wireless/b43/tables_nphy.c
+++ b/drivers/net/wireless/b43/tables_nphy.c
@@ -3042,30 +3042,32 @@ static void b43_nphy_tables_init_rev3(struct b43_wldev *dev)
3042 antswlut = sprom->fem.ghz2.antswlut; 3042 antswlut = sprom->fem.ghz2.antswlut;
3043 3043
3044 /* Static tables */ 3044 /* Static tables */
3045 ntab_upload(dev, B43_NTAB_FRAMESTRUCT_R3, b43_ntab_framestruct_r3); 3045 if (dev->phy.do_full_init) {
3046 ntab_upload(dev, B43_NTAB_PILOT_R3, b43_ntab_pilot_r3); 3046 ntab_upload(dev, B43_NTAB_FRAMESTRUCT_R3, b43_ntab_framestruct_r3);
3047 ntab_upload(dev, B43_NTAB_TMAP_R3, b43_ntab_tmap_r3); 3047 ntab_upload(dev, B43_NTAB_PILOT_R3, b43_ntab_pilot_r3);
3048 ntab_upload(dev, B43_NTAB_INTLEVEL_R3, b43_ntab_intlevel_r3); 3048 ntab_upload(dev, B43_NTAB_TMAP_R3, b43_ntab_tmap_r3);
3049 ntab_upload(dev, B43_NTAB_TDTRN_R3, b43_ntab_tdtrn_r3); 3049 ntab_upload(dev, B43_NTAB_INTLEVEL_R3, b43_ntab_intlevel_r3);
3050 ntab_upload(dev, B43_NTAB_NOISEVAR_R3, b43_ntab_noisevar_r3); 3050 ntab_upload(dev, B43_NTAB_TDTRN_R3, b43_ntab_tdtrn_r3);
3051 ntab_upload(dev, B43_NTAB_MCS_R3, b43_ntab_mcs_r3); 3051 ntab_upload(dev, B43_NTAB_NOISEVAR_R3, b43_ntab_noisevar_r3);
3052 ntab_upload(dev, B43_NTAB_TDI20A0_R3, b43_ntab_tdi20a0_r3); 3052 ntab_upload(dev, B43_NTAB_MCS_R3, b43_ntab_mcs_r3);
3053 ntab_upload(dev, B43_NTAB_TDI20A1_R3, b43_ntab_tdi20a1_r3); 3053 ntab_upload(dev, B43_NTAB_TDI20A0_R3, b43_ntab_tdi20a0_r3);
3054 ntab_upload(dev, B43_NTAB_TDI40A0_R3, b43_ntab_tdi40a0_r3); 3054 ntab_upload(dev, B43_NTAB_TDI20A1_R3, b43_ntab_tdi20a1_r3);
3055 ntab_upload(dev, B43_NTAB_TDI40A1_R3, b43_ntab_tdi40a1_r3); 3055 ntab_upload(dev, B43_NTAB_TDI40A0_R3, b43_ntab_tdi40a0_r3);
3056 ntab_upload(dev, B43_NTAB_PILOTLT_R3, b43_ntab_pilotlt_r3); 3056 ntab_upload(dev, B43_NTAB_TDI40A1_R3, b43_ntab_tdi40a1_r3);
3057 ntab_upload(dev, B43_NTAB_CHANEST_R3, b43_ntab_channelest_r3); 3057 ntab_upload(dev, B43_NTAB_PILOTLT_R3, b43_ntab_pilotlt_r3);
3058 ntab_upload(dev, B43_NTAB_FRAMELT_R3, b43_ntab_framelookup_r3); 3058 ntab_upload(dev, B43_NTAB_CHANEST_R3, b43_ntab_channelest_r3);
3059 ntab_upload(dev, B43_NTAB_C0_ESTPLT_R3, b43_ntab_estimatepowerlt0_r3); 3059 ntab_upload(dev, B43_NTAB_FRAMELT_R3, b43_ntab_framelookup_r3);
3060 ntab_upload(dev, B43_NTAB_C1_ESTPLT_R3, b43_ntab_estimatepowerlt1_r3); 3060 ntab_upload(dev, B43_NTAB_C0_ESTPLT_R3, b43_ntab_estimatepowerlt0_r3);
3061 ntab_upload(dev, B43_NTAB_C0_ADJPLT_R3, b43_ntab_adjustpower0_r3); 3061 ntab_upload(dev, B43_NTAB_C1_ESTPLT_R3, b43_ntab_estimatepowerlt1_r3);
3062 ntab_upload(dev, B43_NTAB_C1_ADJPLT_R3, b43_ntab_adjustpower1_r3); 3062 ntab_upload(dev, B43_NTAB_C0_ADJPLT_R3, b43_ntab_adjustpower0_r3);
3063 ntab_upload(dev, B43_NTAB_C0_GAINCTL_R3, b43_ntab_gainctl0_r3); 3063 ntab_upload(dev, B43_NTAB_C1_ADJPLT_R3, b43_ntab_adjustpower1_r3);
3064 ntab_upload(dev, B43_NTAB_C1_GAINCTL_R3, b43_ntab_gainctl1_r3); 3064 ntab_upload(dev, B43_NTAB_C0_GAINCTL_R3, b43_ntab_gainctl0_r3);
3065 ntab_upload(dev, B43_NTAB_C0_IQLT_R3, b43_ntab_iqlt0_r3); 3065 ntab_upload(dev, B43_NTAB_C1_GAINCTL_R3, b43_ntab_gainctl1_r3);
3066 ntab_upload(dev, B43_NTAB_C1_IQLT_R3, b43_ntab_iqlt1_r3); 3066 ntab_upload(dev, B43_NTAB_C0_IQLT_R3, b43_ntab_iqlt0_r3);
3067 ntab_upload(dev, B43_NTAB_C0_LOFEEDTH_R3, b43_ntab_loftlt0_r3); 3067 ntab_upload(dev, B43_NTAB_C1_IQLT_R3, b43_ntab_iqlt1_r3);
3068 ntab_upload(dev, B43_NTAB_C1_LOFEEDTH_R3, b43_ntab_loftlt1_r3); 3068 ntab_upload(dev, B43_NTAB_C0_LOFEEDTH_R3, b43_ntab_loftlt0_r3);
3069 ntab_upload(dev, B43_NTAB_C1_LOFEEDTH_R3, b43_ntab_loftlt1_r3);
3070 }
3069 3071
3070 /* Volatile tables */ 3072 /* Volatile tables */
3071 if (antswlut < ARRAY_SIZE(b43_ntab_antswctl_r3)) 3073 if (antswlut < ARRAY_SIZE(b43_ntab_antswctl_r3))
@@ -3078,20 +3080,22 @@ static void b43_nphy_tables_init_rev3(struct b43_wldev *dev)
3078static void b43_nphy_tables_init_rev0(struct b43_wldev *dev) 3080static void b43_nphy_tables_init_rev0(struct b43_wldev *dev)
3079{ 3081{
3080 /* Static tables */ 3082 /* Static tables */
3081 ntab_upload(dev, B43_NTAB_FRAMESTRUCT, b43_ntab_framestruct); 3083 if (dev->phy.do_full_init) {
3082 ntab_upload(dev, B43_NTAB_FRAMELT, b43_ntab_framelookup); 3084 ntab_upload(dev, B43_NTAB_FRAMESTRUCT, b43_ntab_framestruct);
3083 ntab_upload(dev, B43_NTAB_TMAP, b43_ntab_tmap); 3085 ntab_upload(dev, B43_NTAB_FRAMELT, b43_ntab_framelookup);
3084 ntab_upload(dev, B43_NTAB_TDTRN, b43_ntab_tdtrn); 3086 ntab_upload(dev, B43_NTAB_TMAP, b43_ntab_tmap);
3085 ntab_upload(dev, B43_NTAB_INTLEVEL, b43_ntab_intlevel); 3087 ntab_upload(dev, B43_NTAB_TDTRN, b43_ntab_tdtrn);
3086 ntab_upload(dev, B43_NTAB_PILOT, b43_ntab_pilot); 3088 ntab_upload(dev, B43_NTAB_INTLEVEL, b43_ntab_intlevel);
3087 ntab_upload(dev, B43_NTAB_TDI20A0, b43_ntab_tdi20a0); 3089 ntab_upload(dev, B43_NTAB_PILOT, b43_ntab_pilot);
3088 ntab_upload(dev, B43_NTAB_TDI20A1, b43_ntab_tdi20a1); 3090 ntab_upload(dev, B43_NTAB_TDI20A0, b43_ntab_tdi20a0);
3089 ntab_upload(dev, B43_NTAB_TDI40A0, b43_ntab_tdi40a0); 3091 ntab_upload(dev, B43_NTAB_TDI20A1, b43_ntab_tdi20a1);
3090 ntab_upload(dev, B43_NTAB_TDI40A1, b43_ntab_tdi40a1); 3092 ntab_upload(dev, B43_NTAB_TDI40A0, b43_ntab_tdi40a0);
3091 ntab_upload(dev, B43_NTAB_CHANEST, b43_ntab_channelest); 3093 ntab_upload(dev, B43_NTAB_TDI40A1, b43_ntab_tdi40a1);
3092 ntab_upload(dev, B43_NTAB_MCS, b43_ntab_mcs); 3094 ntab_upload(dev, B43_NTAB_CHANEST, b43_ntab_channelest);
3093 ntab_upload(dev, B43_NTAB_NOISEVAR10, b43_ntab_noisevar10); 3095 ntab_upload(dev, B43_NTAB_MCS, b43_ntab_mcs);
3094 ntab_upload(dev, B43_NTAB_NOISEVAR11, b43_ntab_noisevar11); 3096 ntab_upload(dev, B43_NTAB_NOISEVAR10, b43_ntab_noisevar10);
3097 ntab_upload(dev, B43_NTAB_NOISEVAR11, b43_ntab_noisevar11);
3098 }
3095 3099
3096 /* Volatile tables */ 3100 /* Volatile tables */
3097 ntab_upload(dev, B43_NTAB_BDI, b43_ntab_bdi); 3101 ntab_upload(dev, B43_NTAB_BDI, b43_ntab_bdi);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/Makefile b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
index 1d2ceac3a221..98e67c18f276 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/Makefile
+++ b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
@@ -33,7 +33,7 @@ brcmfmac-objs += \
33 bcdc.o \ 33 bcdc.o \
34 dhd_common.o \ 34 dhd_common.o \
35 dhd_linux.o \ 35 dhd_linux.o \
36 nvram.o \ 36 firmware.o \
37 btcoex.o 37 btcoex.o
38brcmfmac-$(CONFIG_BRCMFMAC_SDIO) += \ 38brcmfmac-$(CONFIG_BRCMFMAC_SDIO) += \
39 dhd_sdio.o \ 39 dhd_sdio.o \
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h b/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
index c5dcd82e884b..7735328fff21 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
@@ -63,7 +63,6 @@ struct brcmf_bus_dcmd {
63 */ 63 */
64struct brcmf_bus_ops { 64struct brcmf_bus_ops {
65 int (*preinit)(struct device *dev); 65 int (*preinit)(struct device *dev);
66 int (*init)(struct device *dev);
67 void (*stop)(struct device *dev); 66 void (*stop)(struct device *dev);
68 int (*txdata)(struct device *dev, struct sk_buff *skb); 67 int (*txdata)(struct device *dev, struct sk_buff *skb);
69 int (*txctl)(struct device *dev, unsigned char *msg, uint len); 68 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
@@ -114,11 +113,6 @@ static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
114 return bus->ops->preinit(bus->dev); 113 return bus->ops->preinit(bus->dev);
115} 114}
116 115
117static inline int brcmf_bus_init(struct brcmf_bus *bus)
118{
119 return bus->ops->init(bus->dev);
120}
121
122static inline void brcmf_bus_stop(struct brcmf_bus *bus) 116static inline void brcmf_bus_stop(struct brcmf_bus *bus)
123{ 117{
124 bus->ops->stop(bus->dev); 118 bus->ops->stop(bus->dev);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
index 4cacc3d85212..09dd8c13d844 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
@@ -916,13 +916,6 @@ int brcmf_bus_start(struct device *dev)
916 916
917 brcmf_dbg(TRACE, "\n"); 917 brcmf_dbg(TRACE, "\n");
918 918
919 /* Bring up the bus */
920 ret = brcmf_bus_init(bus_if);
921 if (ret != 0) {
922 brcmf_err("brcmf_sdbrcm_bus_init failed %d\n", ret);
923 return ret;
924 }
925
926 /* add primary networking interface */ 919 /* add primary networking interface */
927 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL); 920 ifp = brcmf_add_if(drvr, 0, 0, "wlan%d", NULL);
928 if (IS_ERR(ifp)) 921 if (IS_ERR(ifp))
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 13c89a0c4ba7..8fa0dbbbda72 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -42,7 +42,7 @@
42#include <soc.h> 42#include <soc.h>
43#include "sdio_host.h" 43#include "sdio_host.h"
44#include "chip.h" 44#include "chip.h"
45#include "nvram.h" 45#include "firmware.h"
46 46
47#define DCMD_RESP_TIMEOUT 2000 /* In milli second */ 47#define DCMD_RESP_TIMEOUT 2000 /* In milli second */
48 48
@@ -632,43 +632,28 @@ static const struct brcmf_firmware_names brcmf_fwname_data[] = {
632 { BCM4354_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4354) } 632 { BCM4354_CHIP_ID, 0xFFFFFFFF, BRCMF_FIRMWARE_NVRAM(BCM4354) }
633}; 633};
634 634
635 635static const char *brcmf_sdio_get_fwname(struct brcmf_chip *ci,
636static const struct firmware *brcmf_sdio_get_fw(struct brcmf_sdio *bus, 636 enum brcmf_firmware_type type)
637 enum brcmf_firmware_type type)
638{ 637{
639 const struct firmware *fw; 638 int i;
640 const char *name;
641 int err, i;
642 639
643 for (i = 0; i < ARRAY_SIZE(brcmf_fwname_data); i++) { 640 for (i = 0; i < ARRAY_SIZE(brcmf_fwname_data); i++) {
644 if (brcmf_fwname_data[i].chipid == bus->ci->chip && 641 if (brcmf_fwname_data[i].chipid == ci->chip &&
645 brcmf_fwname_data[i].revmsk & BIT(bus->ci->chiprev)) { 642 brcmf_fwname_data[i].revmsk & BIT(ci->chiprev)) {
646 switch (type) { 643 switch (type) {
647 case BRCMF_FIRMWARE_BIN: 644 case BRCMF_FIRMWARE_BIN:
648 name = brcmf_fwname_data[i].bin; 645 return brcmf_fwname_data[i].bin;
649 break;
650 case BRCMF_FIRMWARE_NVRAM: 646 case BRCMF_FIRMWARE_NVRAM:
651 name = brcmf_fwname_data[i].nv; 647 return brcmf_fwname_data[i].nv;
652 break;
653 default: 648 default:
654 brcmf_err("invalid firmware type (%d)\n", type); 649 brcmf_err("invalid firmware type (%d)\n", type);
655 return NULL; 650 return NULL;
656 } 651 }
657 goto found;
658 } 652 }
659 } 653 }
660 brcmf_err("Unknown chipid %d [%d]\n", 654 brcmf_err("Unknown chipid %d [%d]\n",
661 bus->ci->chip, bus->ci->chiprev); 655 ci->chip, ci->chiprev);
662 return NULL; 656 return NULL;
663
664found:
665 err = request_firmware(&fw, name, &bus->sdiodev->func[2]->dev);
666 if ((err) || (!fw)) {
667 brcmf_err("fail to request firmware %s (%d)\n", name, err);
668 return NULL;
669 }
670
671 return fw;
672} 657}
673 658
674static void pkt_align(struct sk_buff *p, int len, int align) 659static void pkt_align(struct sk_buff *p, int len, int align)
@@ -3278,20 +3263,13 @@ static int brcmf_sdio_download_code_file(struct brcmf_sdio *bus,
3278} 3263}
3279 3264
3280static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus, 3265static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus,
3281 const struct firmware *nv) 3266 void *vars, u32 varsz)
3282{ 3267{
3283 void *vars;
3284 u32 varsz;
3285 int address; 3268 int address;
3286 int err; 3269 int err;
3287 3270
3288 brcmf_dbg(TRACE, "Enter\n"); 3271 brcmf_dbg(TRACE, "Enter\n");
3289 3272
3290 vars = brcmf_nvram_strip(nv, &varsz);
3291
3292 if (vars == NULL)
3293 return -EINVAL;
3294
3295 address = bus->ci->ramsize - varsz + bus->ci->rambase; 3273 address = bus->ci->ramsize - varsz + bus->ci->rambase;
3296 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz); 3274 err = brcmf_sdiod_ramrw(bus->sdiodev, true, address, vars, varsz);
3297 if (err) 3275 if (err)
@@ -3300,15 +3278,14 @@ static int brcmf_sdio_download_nvram(struct brcmf_sdio *bus,
3300 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz)) 3278 else if (!brcmf_sdio_verifymemory(bus->sdiodev, address, vars, varsz))
3301 err = -EIO; 3279 err = -EIO;
3302 3280
3303 brcmf_nvram_free(vars);
3304
3305 return err; 3281 return err;
3306} 3282}
3307 3283
3308static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus) 3284static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
3285 const struct firmware *fw,
3286 void *nvram, u32 nvlen)
3309{ 3287{
3310 int bcmerror = -EFAULT; 3288 int bcmerror = -EFAULT;
3311 const struct firmware *fw;
3312 u32 rstvec; 3289 u32 rstvec;
3313 3290
3314 sdio_claim_host(bus->sdiodev->func[1]); 3291 sdio_claim_host(bus->sdiodev->func[1]);
@@ -3317,12 +3294,6 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus)
3317 /* Keep arm in reset */ 3294 /* Keep arm in reset */
3318 brcmf_chip_enter_download(bus->ci); 3295 brcmf_chip_enter_download(bus->ci);
3319 3296
3320 fw = brcmf_sdio_get_fw(bus, BRCMF_FIRMWARE_BIN);
3321 if (fw == NULL) {
3322 bcmerror = -ENOENT;
3323 goto err;
3324 }
3325
3326 rstvec = get_unaligned_le32(fw->data); 3297 rstvec = get_unaligned_le32(fw->data);
3327 brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec); 3298 brcmf_dbg(SDIO, "firmware rstvec: %x\n", rstvec);
3328 3299
@@ -3330,17 +3301,12 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus)
3330 release_firmware(fw); 3301 release_firmware(fw);
3331 if (bcmerror) { 3302 if (bcmerror) {
3332 brcmf_err("dongle image file download failed\n"); 3303 brcmf_err("dongle image file download failed\n");
3304 brcmf_fw_nvram_free(nvram);
3333 goto err; 3305 goto err;
3334 } 3306 }
3335 3307
3336 fw = brcmf_sdio_get_fw(bus, BRCMF_FIRMWARE_NVRAM); 3308 bcmerror = brcmf_sdio_download_nvram(bus, nvram, nvlen);
3337 if (fw == NULL) { 3309 brcmf_fw_nvram_free(nvram);
3338 bcmerror = -ENOENT;
3339 goto err;
3340 }
3341
3342 bcmerror = brcmf_sdio_download_nvram(bus, fw);
3343 release_firmware(fw);
3344 if (bcmerror) { 3310 if (bcmerror) {
3345 brcmf_err("dongle nvram file download failed\n"); 3311 brcmf_err("dongle nvram file download failed\n");
3346 goto err; 3312 goto err;
@@ -3490,97 +3456,6 @@ done:
3490 return err; 3456 return err;
3491} 3457}
3492 3458
3493static int brcmf_sdio_bus_init(struct device *dev)
3494{
3495 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
3496 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
3497 struct brcmf_sdio *bus = sdiodev->bus;
3498 int err, ret = 0;
3499 u8 saveclk;
3500
3501 brcmf_dbg(TRACE, "Enter\n");
3502
3503 /* try to download image and nvram to the dongle */
3504 if (bus_if->state == BRCMF_BUS_DOWN) {
3505 bus->alp_only = true;
3506 err = brcmf_sdio_download_firmware(bus);
3507 if (err)
3508 return err;
3509 bus->alp_only = false;
3510 }
3511
3512 if (!bus->sdiodev->bus_if->drvr)
3513 return 0;
3514
3515 /* Start the watchdog timer */
3516 bus->sdcnt.tickcnt = 0;
3517 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
3518
3519 sdio_claim_host(bus->sdiodev->func[1]);
3520
3521 /* Make sure backplane clock is on, needed to generate F2 interrupt */
3522 brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
3523 if (bus->clkstate != CLK_AVAIL)
3524 goto exit;
3525
3526 /* Force clocks on backplane to be sure F2 interrupt propagates */
3527 saveclk = brcmf_sdiod_regrb(bus->sdiodev,
3528 SBSDIO_FUNC1_CHIPCLKCSR, &err);
3529 if (!err) {
3530 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
3531 (saveclk | SBSDIO_FORCE_HT), &err);
3532 }
3533 if (err) {
3534 brcmf_err("Failed to force clock for F2: err %d\n", err);
3535 goto exit;
3536 }
3537
3538 /* Enable function 2 (frame transfers) */
3539 w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
3540 offsetof(struct sdpcmd_regs, tosbmailboxdata));
3541 err = sdio_enable_func(bus->sdiodev->func[SDIO_FUNC_2]);
3542
3543
3544 brcmf_dbg(INFO, "enable F2: err=%d\n", err);
3545
3546 /* If F2 successfully enabled, set core and enable interrupts */
3547 if (!err) {
3548 /* Set up the interrupt mask and enable interrupts */
3549 bus->hostintmask = HOSTINTMASK;
3550 w_sdreg32(bus, bus->hostintmask,
3551 offsetof(struct sdpcmd_regs, hostintmask));
3552
3553 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_WATERMARK, 8, &err);
3554 } else {
3555 /* Disable F2 again */
3556 sdio_disable_func(bus->sdiodev->func[SDIO_FUNC_2]);
3557 ret = -ENODEV;
3558 }
3559
3560 if (brcmf_chip_sr_capable(bus->ci)) {
3561 brcmf_sdio_sr_init(bus);
3562 } else {
3563 /* Restore previous clock setting */
3564 brcmf_sdiod_regwb(bus->sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
3565 saveclk, &err);
3566 }
3567
3568 if (ret == 0) {
3569 ret = brcmf_sdiod_intr_register(bus->sdiodev);
3570 if (ret != 0)
3571 brcmf_err("intr register failed:%d\n", ret);
3572 }
3573
3574 /* If we didn't come up, turn off backplane clock */
3575 if (ret != 0)
3576 brcmf_sdio_clkctl(bus, CLK_NONE, false);
3577
3578exit:
3579 sdio_release_host(bus->sdiodev->func[1]);
3580
3581 return ret;
3582}
3583
3584void brcmf_sdio_isr(struct brcmf_sdio *bus) 3459void brcmf_sdio_isr(struct brcmf_sdio *bus)
3585{ 3460{
3586 brcmf_dbg(TRACE, "Enter\n"); 3461 brcmf_dbg(TRACE, "Enter\n");
@@ -4020,13 +3895,114 @@ brcmf_sdio_watchdog(unsigned long data)
4020static struct brcmf_bus_ops brcmf_sdio_bus_ops = { 3895static struct brcmf_bus_ops brcmf_sdio_bus_ops = {
4021 .stop = brcmf_sdio_bus_stop, 3896 .stop = brcmf_sdio_bus_stop,
4022 .preinit = brcmf_sdio_bus_preinit, 3897 .preinit = brcmf_sdio_bus_preinit,
4023 .init = brcmf_sdio_bus_init,
4024 .txdata = brcmf_sdio_bus_txdata, 3898 .txdata = brcmf_sdio_bus_txdata,
4025 .txctl = brcmf_sdio_bus_txctl, 3899 .txctl = brcmf_sdio_bus_txctl,
4026 .rxctl = brcmf_sdio_bus_rxctl, 3900 .rxctl = brcmf_sdio_bus_rxctl,
4027 .gettxq = brcmf_sdio_bus_gettxq, 3901 .gettxq = brcmf_sdio_bus_gettxq,
4028}; 3902};
4029 3903
3904static void brcmf_sdio_firmware_callback(struct device *dev,
3905 const struct firmware *code,
3906 void *nvram, u32 nvram_len)
3907{
3908 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
3909 struct brcmf_sdio_dev *sdiodev = bus_if->bus_priv.sdio;
3910 struct brcmf_sdio *bus = sdiodev->bus;
3911 int err = 0;
3912 u8 saveclk;
3913
3914 brcmf_dbg(TRACE, "Enter: dev=%s\n", dev_name(dev));
3915
3916 /* try to download image and nvram to the dongle */
3917 if (bus_if->state == BRCMF_BUS_DOWN) {
3918 bus->alp_only = true;
3919 err = brcmf_sdio_download_firmware(bus, code, nvram, nvram_len);
3920 if (err)
3921 goto fail;
3922 bus->alp_only = false;
3923 }
3924
3925 if (!bus_if->drvr)
3926 return;
3927
3928 /* Start the watchdog timer */
3929 bus->sdcnt.tickcnt = 0;
3930 brcmf_sdio_wd_timer(bus, BRCMF_WD_POLL_MS);
3931
3932 sdio_claim_host(sdiodev->func[1]);
3933
3934 /* Make sure backplane clock is on, needed to generate F2 interrupt */
3935 brcmf_sdio_clkctl(bus, CLK_AVAIL, false);
3936 if (bus->clkstate != CLK_AVAIL)
3937 goto release;
3938
3939 /* Force clocks on backplane to be sure F2 interrupt propagates */
3940 saveclk = brcmf_sdiod_regrb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, &err);
3941 if (!err) {
3942 brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
3943 (saveclk | SBSDIO_FORCE_HT), &err);
3944 }
3945 if (err) {
3946 brcmf_err("Failed to force clock for F2: err %d\n", err);
3947 goto release;
3948 }
3949
3950 /* Enable function 2 (frame transfers) */
3951 w_sdreg32(bus, SDPCM_PROT_VERSION << SMB_DATA_VERSION_SHIFT,
3952 offsetof(struct sdpcmd_regs, tosbmailboxdata));
3953 err = sdio_enable_func(sdiodev->func[SDIO_FUNC_2]);
3954
3955
3956 brcmf_dbg(INFO, "enable F2: err=%d\n", err);
3957
3958 /* If F2 successfully enabled, set core and enable interrupts */
3959 if (!err) {
3960 /* Set up the interrupt mask and enable interrupts */
3961 bus->hostintmask = HOSTINTMASK;
3962 w_sdreg32(bus, bus->hostintmask,
3963 offsetof(struct sdpcmd_regs, hostintmask));
3964
3965 brcmf_sdiod_regwb(sdiodev, SBSDIO_WATERMARK, 8, &err);
3966 } else {
3967 /* Disable F2 again */
3968 sdio_disable_func(sdiodev->func[SDIO_FUNC_2]);
3969 goto release;
3970 }
3971
3972 if (brcmf_chip_sr_capable(bus->ci)) {
3973 brcmf_sdio_sr_init(bus);
3974 } else {
3975 /* Restore previous clock setting */
3976 brcmf_sdiod_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR,
3977 saveclk, &err);
3978 }
3979
3980 if (err == 0) {
3981 err = brcmf_sdiod_intr_register(sdiodev);
3982 if (err != 0)
3983 brcmf_err("intr register failed:%d\n", err);
3984 }
3985
3986 /* If we didn't come up, turn off backplane clock */
3987 if (err != 0)
3988 brcmf_sdio_clkctl(bus, CLK_NONE, false);
3989
3990 sdio_release_host(sdiodev->func[1]);
3991
3992 err = brcmf_bus_start(dev);
3993 if (err != 0) {
3994 brcmf_err("dongle is not responding\n");
3995 goto fail;
3996 }
3997 return;
3998
3999release:
4000 sdio_release_host(sdiodev->func[1]);
4001fail:
4002 brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), err);
4003 device_release_driver(dev);
4004}
4005
4030struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev) 4006struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4031{ 4007{
4032 int ret; 4008 int ret;
@@ -4110,8 +4086,13 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4110 goto fail; 4086 goto fail;
4111 } 4087 }
4112 4088
4089 /* Query the F2 block size, set roundup accordingly */
4090 bus->blocksize = bus->sdiodev->func[2]->cur_blksize;
4091 bus->roundup = min(max_roundup, bus->blocksize);
4092
4113 /* Allocate buffers */ 4093 /* Allocate buffers */
4114 if (bus->sdiodev->bus_if->maxctl) { 4094 if (bus->sdiodev->bus_if->maxctl) {
4095 bus->sdiodev->bus_if->maxctl += bus->roundup;
4115 bus->rxblen = 4096 bus->rxblen =
4116 roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN), 4097 roundup((bus->sdiodev->bus_if->maxctl + SDPCM_HDRLEN),
4117 ALIGNMENT) + bus->head_align; 4098 ALIGNMENT) + bus->head_align;
@@ -4139,10 +4120,6 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4139 bus->idletime = BRCMF_IDLE_INTERVAL; 4120 bus->idletime = BRCMF_IDLE_INTERVAL;
4140 bus->idleclock = BRCMF_IDLE_ACTIVE; 4121 bus->idleclock = BRCMF_IDLE_ACTIVE;
4141 4122
4142 /* Query the F2 block size, set roundup accordingly */
4143 bus->blocksize = bus->sdiodev->func[2]->cur_blksize;
4144 bus->roundup = min(max_roundup, bus->blocksize);
4145
4146 /* SR state */ 4123 /* SR state */
4147 bus->sleeping = false; 4124 bus->sleeping = false;
4148 bus->sr_enabled = false; 4125 bus->sr_enabled = false;
@@ -4150,10 +4127,14 @@ struct brcmf_sdio *brcmf_sdio_probe(struct brcmf_sdio_dev *sdiodev)
4150 brcmf_sdio_debugfs_create(bus); 4127 brcmf_sdio_debugfs_create(bus);
4151 brcmf_dbg(INFO, "completed!!\n"); 4128 brcmf_dbg(INFO, "completed!!\n");
4152 4129
4153 /* if firmware path present try to download and bring up bus */ 4130 ret = brcmf_fw_get_firmwares(sdiodev->dev, BRCMF_FW_REQUEST_NVRAM,
4154 ret = brcmf_bus_start(bus->sdiodev->dev); 4131 brcmf_sdio_get_fwname(bus->ci,
4132 BRCMF_FIRMWARE_BIN),
4133 brcmf_sdio_get_fwname(bus->ci,
4134 BRCMF_FIRMWARE_NVRAM),
4135 brcmf_sdio_firmware_callback);
4155 if (ret != 0) { 4136 if (ret != 0) {
4156 brcmf_err("dongle is not responding\n"); 4137 brcmf_err("async firmware request failed: %d\n", ret);
4157 goto fail; 4138 goto fail;
4158 } 4139 }
4159 4140
@@ -4173,9 +4154,7 @@ void brcmf_sdio_remove(struct brcmf_sdio *bus)
4173 /* De-register interrupt handler */ 4154 /* De-register interrupt handler */
4174 brcmf_sdiod_intr_unregister(bus->sdiodev); 4155 brcmf_sdiod_intr_unregister(bus->sdiodev);
4175 4156
4176 if (bus->sdiodev->bus_if->drvr) { 4157 brcmf_detach(bus->sdiodev->dev);
4177 brcmf_detach(bus->sdiodev->dev);
4178 }
4179 4158
4180 cancel_work_sync(&bus->datawork); 4159 cancel_work_sync(&bus->datawork);
4181 if (bus->brcmf_wq) 4160 if (bus->brcmf_wq)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/nvram.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
index 5c450d11dbc9..7b7d237c1ddb 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/nvram.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
@@ -16,10 +16,11 @@
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/device.h>
19#include <linux/firmware.h> 20#include <linux/firmware.h>
20 21
21#include "dhd_dbg.h" 22#include "dhd_dbg.h"
22#include "nvram.h" 23#include "firmware.h"
23 24
24enum nvram_parser_state { 25enum nvram_parser_state {
25 IDLE, 26 IDLE,
@@ -187,7 +188,7 @@ static int brcmf_init_nvram_parser(struct nvram_parser *nvp,
187 * and converts newlines to NULs. Shortens buffer as needed and pads with NULs. 188 * and converts newlines to NULs. Shortens buffer as needed and pads with NULs.
188 * End of buffer is completed with token identifying length of buffer. 189 * End of buffer is completed with token identifying length of buffer.
189 */ 190 */
190void *brcmf_nvram_strip(const struct firmware *nv, u32 *new_length) 191static void *brcmf_fw_nvram_strip(const struct firmware *nv, u32 *new_length)
191{ 192{
192 struct nvram_parser nvp; 193 struct nvram_parser nvp;
193 u32 pad; 194 u32 pad;
@@ -219,8 +220,113 @@ void *brcmf_nvram_strip(const struct firmware *nv, u32 *new_length)
219 return nvp.nvram; 220 return nvp.nvram;
220} 221}
221 222
222void brcmf_nvram_free(void *nvram) 223void brcmf_fw_nvram_free(void *nvram)
223{ 224{
224 kfree(nvram); 225 kfree(nvram);
225} 226}
226 227
228struct brcmf_fw {
229 struct device *dev;
230 u16 flags;
231 const struct firmware *code;
232 const char *nvram_name;
233 void (*done)(struct device *dev, const struct firmware *fw,
234 void *nvram_image, u32 nvram_len);
235};
236
237static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
238{
239 struct brcmf_fw *fwctx = ctx;
240 u32 nvram_length = 0;
241 void *nvram = NULL;
242
243 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(fwctx->dev));
244 if (!fw && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
245 goto fail;
246
247 if (fw) {
248 nvram = brcmf_fw_nvram_strip(fw, &nvram_length);
249 release_firmware(fw);
250 if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
251 goto fail;
252 }
253
254 fwctx->done(fwctx->dev, fwctx->code, nvram, nvram_length);
255 kfree(fwctx);
256 return;
257
258fail:
259 brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev));
260 if (fwctx->code)
261 release_firmware(fwctx->code);
262 device_release_driver(fwctx->dev);
263 kfree(fwctx);
264}
265
266static void brcmf_fw_request_code_done(const struct firmware *fw, void *ctx)
267{
268 struct brcmf_fw *fwctx = ctx;
269 int ret;
270
271 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(fwctx->dev));
272 if (!fw)
273 goto fail;
274
275 /* only requested code so done here */
276 if (!(fwctx->flags & BRCMF_FW_REQUEST_NVRAM)) {
277 fwctx->done(fwctx->dev, fw, NULL, 0);
278 kfree(fwctx);
279 return;
280 }
281 fwctx->code = fw;
282 ret = request_firmware_nowait(THIS_MODULE, true, fwctx->nvram_name,
283 fwctx->dev, GFP_KERNEL, fwctx,
284 brcmf_fw_request_nvram_done);
285
286 if (!ret)
287 return;
288
289 /* when nvram is optional call .done() callback here */
290 if (fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL) {
291 fwctx->done(fwctx->dev, fw, NULL, 0);
292 kfree(fwctx);
293 return;
294 }
295
296 /* failed nvram request */
297 release_firmware(fw);
298fail:
299 brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev));
300 device_release_driver(fwctx->dev);
301 kfree(fwctx);
302}
303
304int brcmf_fw_get_firmwares(struct device *dev, u16 flags,
305 const char *code, const char *nvram,
306 void (*fw_cb)(struct device *dev,
307 const struct firmware *fw,
308 void *nvram_image, u32 nvram_len))
309{
310 struct brcmf_fw *fwctx;
311
312 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
313 if (!fw_cb || !code)
314 return -EINVAL;
315
316 if ((flags & BRCMF_FW_REQUEST_NVRAM) && !nvram)
317 return -EINVAL;
318
319 fwctx = kzalloc(sizeof(*fwctx), GFP_KERNEL);
320 if (!fwctx)
321 return -ENOMEM;
322
323 fwctx->dev = dev;
324 fwctx->flags = flags;
325 fwctx->done = fw_cb;
326 if (flags & BRCMF_FW_REQUEST_NVRAM)
327 fwctx->nvram_name = nvram;
328
329 return request_firmware_nowait(THIS_MODULE, true, code, dev,
330 GFP_KERNEL, fwctx,
331 brcmf_fw_request_code_done);
332}
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/nvram.h b/drivers/net/wireless/brcm80211/brcmfmac/firmware.h
index d454580928c9..6431bfd7afff 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/nvram.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.h
@@ -13,12 +13,24 @@
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16#ifndef BRCMFMAC_NVRAM_H 16#ifndef BRCMFMAC_FIRMWARE_H
17#define BRCMFMAC_NVRAM_H 17#define BRCMFMAC_FIRMWARE_H
18 18
19#define BRCMF_FW_REQUEST 0x000F
20#define BRCMF_FW_REQUEST_NVRAM 0x0001
21#define BRCMF_FW_REQ_FLAGS 0x00F0
22#define BRCMF_FW_REQ_NV_OPTIONAL 0x0010
19 23
20void *brcmf_nvram_strip(const struct firmware *nv, u32 *new_length); 24void brcmf_fw_nvram_free(void *nvram);
21void brcmf_nvram_free(void *nvram); 25/*
22 26 * Request firmware(s) asynchronously. When the asynchronous request
27 * fails it will not use the callback, but call device_release_driver()
28 * instead which will call the driver .remove() callback.
29 */
30int brcmf_fw_get_firmwares(struct device *dev, u16 flags,
31 const char *code, const char *nvram,
32 void (*fw_cb)(struct device *dev,
33 const struct firmware *fw,
34 void *nvram_image, u32 nvram_len));
23 35
24#endif /* BRCMFMAC_NVRAM_H */ 36#endif /* BRCMFMAC_FIRMWARE_H */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index 3ce0e7cfd027..6db51a666f61 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -25,6 +25,7 @@
25#include <dhd_bus.h> 25#include <dhd_bus.h>
26#include <dhd_dbg.h> 26#include <dhd_dbg.h>
27 27
28#include "firmware.h"
28#include "usb_rdl.h" 29#include "usb_rdl.h"
29#include "usb.h" 30#include "usb.h"
30 31
@@ -61,12 +62,6 @@ struct brcmf_usb_image {
61 u8 *image; 62 u8 *image;
62 int image_len; 63 int image_len;
63}; 64};
64static struct list_head fw_image_list;
65
66struct intr_transfer_buf {
67 u32 notification;
68 u32 reserved;
69};
70 65
71struct brcmf_usbdev_info { 66struct brcmf_usbdev_info {
72 struct brcmf_usbdev bus_pub; /* MUST BE FIRST */ 67 struct brcmf_usbdev bus_pub; /* MUST BE FIRST */
@@ -75,7 +70,7 @@ struct brcmf_usbdev_info {
75 struct list_head rx_postq; 70 struct list_head rx_postq;
76 struct list_head tx_freeq; 71 struct list_head tx_freeq;
77 struct list_head tx_postq; 72 struct list_head tx_postq;
78 uint rx_pipe, tx_pipe, intr_pipe, rx_pipe2; 73 uint rx_pipe, tx_pipe, rx_pipe2;
79 74
80 int rx_low_watermark; 75 int rx_low_watermark;
81 int tx_low_watermark; 76 int tx_low_watermark;
@@ -87,7 +82,7 @@ struct brcmf_usbdev_info {
87 struct brcmf_usbreq *tx_reqs; 82 struct brcmf_usbreq *tx_reqs;
88 struct brcmf_usbreq *rx_reqs; 83 struct brcmf_usbreq *rx_reqs;
89 84
90 u8 *image; /* buffer for combine fw and nvram */ 85 const u8 *image; /* buffer for combine fw and nvram */
91 int image_len; 86 int image_len;
92 87
93 struct usb_device *usbdev; 88 struct usb_device *usbdev;
@@ -104,10 +99,6 @@ struct brcmf_usbdev_info {
104 ulong ctl_op; 99 ulong ctl_op;
105 100
106 struct urb *bulk_urb; /* used for FW download */ 101 struct urb *bulk_urb; /* used for FW download */
107 struct urb *intr_urb; /* URB for interrupt endpoint */
108 int intr_size; /* Size of interrupt message */
109 int interval; /* Interrupt polling interval */
110 struct intr_transfer_buf intr; /* Data buffer for interrupt endpoint */
111}; 102};
112 103
113static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo, 104static void brcmf_usb_rx_refill(struct brcmf_usbdev_info *devinfo,
@@ -531,39 +522,6 @@ brcmf_usb_state_change(struct brcmf_usbdev_info *devinfo, int state)
531 } 522 }
532} 523}
533 524
534static void
535brcmf_usb_intr_complete(struct urb *urb)
536{
537 struct brcmf_usbdev_info *devinfo =
538 (struct brcmf_usbdev_info *)urb->context;
539 int err;
540
541 brcmf_dbg(USB, "Enter, urb->status=%d\n", urb->status);
542
543 if (devinfo == NULL)
544 return;
545
546 if (unlikely(urb->status)) {
547 if (urb->status == -ENOENT ||
548 urb->status == -ESHUTDOWN ||
549 urb->status == -ENODEV) {
550 brcmf_usb_state_change(devinfo,
551 BRCMFMAC_USB_STATE_DOWN);
552 }
553 }
554
555 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_DOWN) {
556 brcmf_err("intr cb when DBUS down, ignoring\n");
557 return;
558 }
559
560 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) {
561 err = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
562 if (err)
563 brcmf_err("usb_submit_urb, err=%d\n", err);
564 }
565}
566
567static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb) 525static int brcmf_usb_tx(struct device *dev, struct sk_buff *skb)
568{ 526{
569 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 527 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
@@ -619,7 +577,6 @@ static int brcmf_usb_up(struct device *dev)
619{ 577{
620 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev); 578 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(dev);
621 u16 ifnum; 579 u16 ifnum;
622 int ret;
623 580
624 brcmf_dbg(USB, "Enter\n"); 581 brcmf_dbg(USB, "Enter\n");
625 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP) 582 if (devinfo->bus_pub.state == BRCMFMAC_USB_STATE_UP)
@@ -628,23 +585,6 @@ static int brcmf_usb_up(struct device *dev)
628 /* Success, indicate devinfo is fully up */ 585 /* Success, indicate devinfo is fully up */
629 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_UP); 586 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_UP);
630 587
631 if (devinfo->intr_urb) {
632 usb_fill_int_urb(devinfo->intr_urb, devinfo->usbdev,
633 devinfo->intr_pipe,
634 &devinfo->intr,
635 devinfo->intr_size,
636 (usb_complete_t)brcmf_usb_intr_complete,
637 devinfo,
638 devinfo->interval);
639
640 ret = usb_submit_urb(devinfo->intr_urb, GFP_ATOMIC);
641 if (ret) {
642 brcmf_err("USB_SUBMIT_URB failed with status %d\n",
643 ret);
644 return -EINVAL;
645 }
646 }
647
648 if (devinfo->ctl_urb) { 588 if (devinfo->ctl_urb) {
649 devinfo->ctl_in_pipe = usb_rcvctrlpipe(devinfo->usbdev, 0); 589 devinfo->ctl_in_pipe = usb_rcvctrlpipe(devinfo->usbdev, 0);
650 devinfo->ctl_out_pipe = usb_sndctrlpipe(devinfo->usbdev, 0); 590 devinfo->ctl_out_pipe = usb_sndctrlpipe(devinfo->usbdev, 0);
@@ -681,8 +621,6 @@ static void brcmf_usb_down(struct device *dev)
681 return; 621 return;
682 622
683 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN); 623 brcmf_usb_state_change(devinfo, BRCMFMAC_USB_STATE_DOWN);
684 if (devinfo->intr_urb)
685 usb_kill_urb(devinfo->intr_urb);
686 624
687 if (devinfo->ctl_urb) 625 if (devinfo->ctl_urb)
688 usb_kill_urb(devinfo->ctl_urb); 626 usb_kill_urb(devinfo->ctl_urb);
@@ -1021,7 +959,7 @@ brcmf_usb_fw_download(struct brcmf_usbdev_info *devinfo)
1021 } 959 }
1022 960
1023 err = brcmf_usb_dlstart(devinfo, 961 err = brcmf_usb_dlstart(devinfo,
1024 devinfo->image, devinfo->image_len); 962 (u8 *)devinfo->image, devinfo->image_len);
1025 if (err == 0) 963 if (err == 0)
1026 err = brcmf_usb_dlrun(devinfo); 964 err = brcmf_usb_dlrun(devinfo);
1027 return err; 965 return err;
@@ -1036,7 +974,6 @@ static void brcmf_usb_detach(struct brcmf_usbdev_info *devinfo)
1036 brcmf_usb_free_q(&devinfo->rx_freeq, false); 974 brcmf_usb_free_q(&devinfo->rx_freeq, false);
1037 brcmf_usb_free_q(&devinfo->tx_freeq, false); 975 brcmf_usb_free_q(&devinfo->tx_freeq, false);
1038 976
1039 usb_free_urb(devinfo->intr_urb);
1040 usb_free_urb(devinfo->ctl_urb); 977 usb_free_urb(devinfo->ctl_urb);
1041 usb_free_urb(devinfo->bulk_urb); 978 usb_free_urb(devinfo->bulk_urb);
1042 979
@@ -1080,68 +1017,20 @@ static int check_file(const u8 *headers)
1080 return -1; 1017 return -1;
1081} 1018}
1082 1019
1083static int brcmf_usb_get_fw(struct brcmf_usbdev_info *devinfo) 1020static const char *brcmf_usb_get_fwname(struct brcmf_usbdev_info *devinfo)
1084{ 1021{
1085 s8 *fwname;
1086 const struct firmware *fw;
1087 struct brcmf_usb_image *fw_image;
1088 int err;
1089
1090 brcmf_dbg(USB, "Enter\n");
1091 switch (devinfo->bus_pub.devid) { 1022 switch (devinfo->bus_pub.devid) {
1092 case 43143: 1023 case 43143:
1093 fwname = BRCMF_USB_43143_FW_NAME; 1024 return BRCMF_USB_43143_FW_NAME;
1094 break;
1095 case 43235: 1025 case 43235:
1096 case 43236: 1026 case 43236:
1097 case 43238: 1027 case 43238:
1098 fwname = BRCMF_USB_43236_FW_NAME; 1028 return BRCMF_USB_43236_FW_NAME;
1099 break;
1100 case 43242: 1029 case 43242:
1101 fwname = BRCMF_USB_43242_FW_NAME; 1030 return BRCMF_USB_43242_FW_NAME;
1102 break;
1103 default: 1031 default:
1104 return -EINVAL; 1032 return NULL;
1105 break;
1106 }
1107 brcmf_dbg(USB, "Loading FW %s\n", fwname);
1108 list_for_each_entry(fw_image, &fw_image_list, list) {
1109 if (fw_image->fwname == fwname) {
1110 devinfo->image = fw_image->image;
1111 devinfo->image_len = fw_image->image_len;
1112 return 0;
1113 }
1114 }
1115 /* fw image not yet loaded. Load it now and add to list */
1116 err = request_firmware(&fw, fwname, devinfo->dev);
1117 if (!fw) {
1118 brcmf_err("fail to request firmware %s\n", fwname);
1119 return err;
1120 }
1121 if (check_file(fw->data) < 0) {
1122 brcmf_err("invalid firmware %s\n", fwname);
1123 return -EINVAL;
1124 } 1033 }
1125
1126 fw_image = kzalloc(sizeof(*fw_image), GFP_ATOMIC);
1127 if (!fw_image)
1128 return -ENOMEM;
1129 INIT_LIST_HEAD(&fw_image->list);
1130 list_add_tail(&fw_image->list, &fw_image_list);
1131 fw_image->fwname = fwname;
1132 fw_image->image = vmalloc(fw->size);
1133 if (!fw_image->image)
1134 return -ENOMEM;
1135
1136 memcpy(fw_image->image, fw->data, fw->size);
1137 fw_image->image_len = fw->size;
1138
1139 release_firmware(fw);
1140
1141 devinfo->image = fw_image->image;
1142 devinfo->image_len = fw_image->image_len;
1143
1144 return 0;
1145} 1034}
1146 1035
1147 1036
@@ -1186,11 +1075,6 @@ struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1186 goto error; 1075 goto error;
1187 devinfo->tx_freecount = ntxq; 1076 devinfo->tx_freecount = ntxq;
1188 1077
1189 devinfo->intr_urb = usb_alloc_urb(0, GFP_ATOMIC);
1190 if (!devinfo->intr_urb) {
1191 brcmf_err("usb_alloc_urb (intr) failed\n");
1192 goto error;
1193 }
1194 devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC); 1078 devinfo->ctl_urb = usb_alloc_urb(0, GFP_ATOMIC);
1195 if (!devinfo->ctl_urb) { 1079 if (!devinfo->ctl_urb) {
1196 brcmf_err("usb_alloc_urb (ctl) failed\n"); 1080 brcmf_err("usb_alloc_urb (ctl) failed\n");
@@ -1202,16 +1086,6 @@ struct brcmf_usbdev *brcmf_usb_attach(struct brcmf_usbdev_info *devinfo,
1202 goto error; 1086 goto error;
1203 } 1087 }
1204 1088
1205 if (!brcmf_usb_dlneeded(devinfo))
1206 return &devinfo->bus_pub;
1207
1208 brcmf_dbg(USB, "Start fw downloading\n");
1209 if (brcmf_usb_get_fw(devinfo))
1210 goto error;
1211
1212 if (brcmf_usb_fw_download(devinfo))
1213 goto error;
1214
1215 return &devinfo->bus_pub; 1089 return &devinfo->bus_pub;
1216 1090
1217error: 1091error:
@@ -1222,18 +1096,77 @@ error:
1222 1096
1223static struct brcmf_bus_ops brcmf_usb_bus_ops = { 1097static struct brcmf_bus_ops brcmf_usb_bus_ops = {
1224 .txdata = brcmf_usb_tx, 1098 .txdata = brcmf_usb_tx,
1225 .init = brcmf_usb_up,
1226 .stop = brcmf_usb_down, 1099 .stop = brcmf_usb_down,
1227 .txctl = brcmf_usb_tx_ctlpkt, 1100 .txctl = brcmf_usb_tx_ctlpkt,
1228 .rxctl = brcmf_usb_rx_ctlpkt, 1101 .rxctl = brcmf_usb_rx_ctlpkt,
1229}; 1102};
1230 1103
1104static int brcmf_usb_bus_setup(struct brcmf_usbdev_info *devinfo)
1105{
1106 int ret;
1107
1108 /* Attach to the common driver interface */
1109 ret = brcmf_attach(devinfo->dev);
1110 if (ret) {
1111 brcmf_err("brcmf_attach failed\n");
1112 return ret;
1113 }
1114
1115 ret = brcmf_usb_up(devinfo->dev);
1116 if (ret)
1117 goto fail;
1118
1119 ret = brcmf_bus_start(devinfo->dev);
1120 if (ret)
1121 goto fail;
1122
1123 return 0;
1124fail:
1125 brcmf_detach(devinfo->dev);
1126 return ret;
1127}
1128
1129static void brcmf_usb_probe_phase2(struct device *dev,
1130 const struct firmware *fw,
1131 void *nvram, u32 nvlen)
1132{
1133 struct brcmf_bus *bus = dev_get_drvdata(dev);
1134 struct brcmf_usbdev_info *devinfo;
1135 int ret;
1136
1137 brcmf_dbg(USB, "Start fw downloading\n");
1138 ret = check_file(fw->data);
1139 if (ret < 0) {
1140 brcmf_err("invalid firmware\n");
1141 release_firmware(fw);
1142 goto error;
1143 }
1144
1145 devinfo = bus->bus_priv.usb->devinfo;
1146 devinfo->image = fw->data;
1147 devinfo->image_len = fw->size;
1148
1149 ret = brcmf_usb_fw_download(devinfo);
1150 release_firmware(fw);
1151 if (ret)
1152 goto error;
1153
1154 ret = brcmf_usb_bus_setup(devinfo);
1155 if (ret)
1156 goto error;
1157
1158 return;
1159error:
1160 brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), ret);
1161 device_release_driver(dev);
1162}
1163
1231static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo) 1164static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
1232{ 1165{
1233 struct brcmf_bus *bus = NULL; 1166 struct brcmf_bus *bus = NULL;
1234 struct brcmf_usbdev *bus_pub = NULL; 1167 struct brcmf_usbdev *bus_pub = NULL;
1235 int ret;
1236 struct device *dev = devinfo->dev; 1168 struct device *dev = devinfo->dev;
1169 int ret;
1237 1170
1238 brcmf_dbg(USB, "Enter\n"); 1171 brcmf_dbg(USB, "Enter\n");
1239 bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ); 1172 bus_pub = brcmf_usb_attach(devinfo, BRCMF_USB_NRXQ, BRCMF_USB_NTXQ);
@@ -1256,21 +1189,16 @@ static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
1256 bus->proto_type = BRCMF_PROTO_BCDC; 1189 bus->proto_type = BRCMF_PROTO_BCDC;
1257 bus->always_use_fws_queue = true; 1190 bus->always_use_fws_queue = true;
1258 1191
1259 /* Attach to the common driver interface */ 1192 if (!brcmf_usb_dlneeded(devinfo)) {
1260 ret = brcmf_attach(dev); 1193 ret = brcmf_usb_bus_setup(devinfo);
1261 if (ret) { 1194 if (ret)
1262 brcmf_err("brcmf_attach failed\n"); 1195 goto fail;
1263 goto fail;
1264 }
1265
1266 ret = brcmf_bus_start(dev);
1267 if (ret) {
1268 brcmf_err("dongle is not responding\n");
1269 brcmf_detach(dev);
1270 goto fail;
1271 } 1196 }
1272 1197 /* request firmware here */
1198 brcmf_fw_get_firmwares(dev, 0, brcmf_usb_get_fwname(devinfo), NULL,
1199 brcmf_usb_probe_phase2);
1273 return 0; 1200 return 0;
1201
1274fail: 1202fail:
1275 /* Release resources in reverse order */ 1203 /* Release resources in reverse order */
1276 kfree(bus); 1204 kfree(bus);
@@ -1358,9 +1286,6 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1358 goto fail; 1286 goto fail;
1359 } 1287 }
1360 1288
1361 endpoint_num = endpoint->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
1362 devinfo->intr_pipe = usb_rcvintpipe(usb, endpoint_num);
1363
1364 devinfo->rx_pipe = 0; 1289 devinfo->rx_pipe = 0;
1365 devinfo->rx_pipe2 = 0; 1290 devinfo->rx_pipe2 = 0;
1366 devinfo->tx_pipe = 0; 1291 devinfo->tx_pipe = 0;
@@ -1392,16 +1317,9 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1392 } 1317 }
1393 } 1318 }
1394 1319
1395 /* Allocate interrupt URB and data buffer */ 1320 if (usb->speed == USB_SPEED_SUPER)
1396 /* RNDIS says 8-byte intr, our old drivers used 4-byte */ 1321 brcmf_dbg(USB, "Broadcom super speed USB wireless device detected\n");
1397 if (IFEPDESC(usb, CONTROL_IF, 0).wMaxPacketSize == cpu_to_le16(16)) 1322 else if (usb->speed == USB_SPEED_HIGH)
1398 devinfo->intr_size = 8;
1399 else
1400 devinfo->intr_size = 4;
1401
1402 devinfo->interval = IFEPDESC(usb, CONTROL_IF, 0).bInterval;
1403
1404 if (usb->speed == USB_SPEED_HIGH)
1405 brcmf_dbg(USB, "Broadcom high speed USB wireless device detected\n"); 1323 brcmf_dbg(USB, "Broadcom high speed USB wireless device detected\n");
1406 else 1324 else
1407 brcmf_dbg(USB, "Broadcom full speed USB wireless device detected\n"); 1325 brcmf_dbg(USB, "Broadcom full speed USB wireless device detected\n");
@@ -1456,23 +1374,18 @@ static int brcmf_usb_resume(struct usb_interface *intf)
1456 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); 1374 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1457 1375
1458 brcmf_dbg(USB, "Enter\n"); 1376 brcmf_dbg(USB, "Enter\n");
1459 if (!brcmf_attach(devinfo->dev)) 1377 return brcmf_usb_bus_setup(devinfo);
1460 return brcmf_bus_start(&usb->dev);
1461
1462 return 0;
1463} 1378}
1464 1379
1465static int brcmf_usb_reset_resume(struct usb_interface *intf) 1380static int brcmf_usb_reset_resume(struct usb_interface *intf)
1466{ 1381{
1467 struct usb_device *usb = interface_to_usbdev(intf); 1382 struct usb_device *usb = interface_to_usbdev(intf);
1468 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev); 1383 struct brcmf_usbdev_info *devinfo = brcmf_usb_get_businfo(&usb->dev);
1469
1470 brcmf_dbg(USB, "Enter\n"); 1384 brcmf_dbg(USB, "Enter\n");
1471 1385
1472 if (!brcmf_usb_fw_download(devinfo)) 1386 return brcmf_fw_get_firmwares(&usb->dev, 0,
1473 return brcmf_usb_resume(intf); 1387 brcmf_usb_get_fwname(devinfo), NULL,
1474 1388 brcmf_usb_probe_phase2);
1475 return -EIO;
1476} 1389}
1477 1390
1478#define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c 1391#define BRCMF_USB_VENDOR_ID_BROADCOM 0x0a5c
@@ -1507,16 +1420,6 @@ static struct usb_driver brcmf_usbdrvr = {
1507 .disable_hub_initiated_lpm = 1, 1420 .disable_hub_initiated_lpm = 1,
1508}; 1421};
1509 1422
1510static void brcmf_release_fw(struct list_head *q)
1511{
1512 struct brcmf_usb_image *fw_image, *next;
1513
1514 list_for_each_entry_safe(fw_image, next, q, list) {
1515 vfree(fw_image->image);
1516 list_del_init(&fw_image->list);
1517 }
1518}
1519
1520static int brcmf_usb_reset_device(struct device *dev, void *notused) 1423static int brcmf_usb_reset_device(struct device *dev, void *notused)
1521{ 1424{
1522 /* device past is the usb interface so we 1425 /* device past is the usb interface so we
@@ -1535,12 +1438,10 @@ void brcmf_usb_exit(void)
1535 ret = driver_for_each_device(drv, NULL, NULL, 1438 ret = driver_for_each_device(drv, NULL, NULL,
1536 brcmf_usb_reset_device); 1439 brcmf_usb_reset_device);
1537 usb_deregister(&brcmf_usbdrvr); 1440 usb_deregister(&brcmf_usbdrvr);
1538 brcmf_release_fw(&fw_image_list);
1539} 1441}
1540 1442
1541void brcmf_usb_register(void) 1443void brcmf_usb_register(void)
1542{ 1444{
1543 brcmf_dbg(USB, "Enter\n"); 1445 brcmf_dbg(USB, "Enter\n");
1544 INIT_LIST_HEAD(&fw_image_list);
1545 usb_register(&brcmf_usbdrvr); 1446 usb_register(&brcmf_usbdrvr);
1546} 1447}
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 92cb29a2003f..d8fa276e368b 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -341,8 +341,8 @@ static u8 brcmf_mw_to_qdbm(u16 mw)
341 return qdbm; 341 return qdbm;
342} 342}
343 343
344u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf, 344static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
345 struct cfg80211_chan_def *ch) 345 struct cfg80211_chan_def *ch)
346{ 346{
347 struct brcmu_chan ch_inf; 347 struct brcmu_chan ch_inf;
348 s32 primary_offset; 348 s32 primary_offset;
@@ -640,6 +640,9 @@ s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
640 if (err) 640 if (err)
641 brcmf_err("Scan abort failed\n"); 641 brcmf_err("Scan abort failed\n");
642 } 642 }
643
644 brcmf_set_mpc(ifp, 1);
645
643 /* 646 /*
644 * e-scan can be initiated by scheduled scan 647 * e-scan can be initiated by scheduled scan
645 * which takes precedence. 648 * which takes precedence.
@@ -649,12 +652,10 @@ s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
649 cfg->sched_escan = false; 652 cfg->sched_escan = false;
650 if (!aborted) 653 if (!aborted)
651 cfg80211_sched_scan_results(cfg_to_wiphy(cfg)); 654 cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
652 brcmf_set_mpc(ifp, 1);
653 } else if (scan_request) { 655 } else if (scan_request) {
654 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n", 656 brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
655 aborted ? "Aborted" : "Done"); 657 aborted ? "Aborted" : "Done");
656 cfg80211_scan_done(scan_request, aborted); 658 cfg80211_scan_done(scan_request, aborted);
657 brcmf_set_mpc(ifp, 1);
658 } 659 }
659 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) 660 if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
660 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n"); 661 brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
@@ -3178,7 +3179,7 @@ brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
3178 } 3179 }
3179 3180
3180 if (!request->n_ssids || !request->n_match_sets) { 3181 if (!request->n_ssids || !request->n_match_sets) {
3181 brcmf_err("Invalid sched scan req!! n_ssids:%d\n", 3182 brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
3182 request->n_ssids); 3183 request->n_ssids);
3183 return -EINVAL; 3184 return -EINVAL;
3184 } 3185 }
diff --git a/drivers/net/wireless/brcm80211/brcmutil/d11.c b/drivers/net/wireless/brcm80211/brcmutil/d11.c
index 6cbc33d0fc19..2b2522bdd8eb 100644
--- a/drivers/net/wireless/brcm80211/brcmutil/d11.c
+++ b/drivers/net/wireless/brcm80211/brcmutil/d11.c
@@ -54,6 +54,7 @@ static void brcmu_d11n_encchspec(struct brcmu_chan *ch)
54 if (ch->bw == BRCMU_CHAN_BW_20) 54 if (ch->bw == BRCMU_CHAN_BW_20)
55 ch->sb = BRCMU_CHAN_SB_NONE; 55 ch->sb = BRCMU_CHAN_SB_NONE;
56 56
57 ch->chspec = 0;
57 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_CH_MASK, 58 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_CH_MASK,
58 BRCMU_CHSPEC_CH_SHIFT, ch->chnum); 59 BRCMU_CHSPEC_CH_SHIFT, ch->chnum);
59 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_D11N_SB_MASK, 60 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_D11N_SB_MASK,
@@ -61,7 +62,6 @@ static void brcmu_d11n_encchspec(struct brcmu_chan *ch)
61 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_D11N_BW_MASK, 62 brcmu_maskset16(&ch->chspec, BRCMU_CHSPEC_D11N_BW_MASK,
62 0, d11n_bw(ch->bw)); 63 0, d11n_bw(ch->bw));
63 64
64 ch->chspec &= ~BRCMU_CHSPEC_D11N_BND_MASK;
65 if (ch->chnum <= CH_MAX_2G_CHANNEL) 65 if (ch->chnum <= CH_MAX_2G_CHANNEL)
66 ch->chspec |= BRCMU_CHSPEC_D11N_BND_2G; 66 ch->chspec |= BRCMU_CHSPEC_D11N_BND_2G;
67 else 67 else
diff --git a/drivers/net/wireless/mwifiex/fw.h b/drivers/net/wireless/mwifiex/fw.h
index 42eaeda1dc82..3175dd04834b 100644
--- a/drivers/net/wireless/mwifiex/fw.h
+++ b/drivers/net/wireless/mwifiex/fw.h
@@ -405,7 +405,7 @@ enum P2P_MODES {
405#define HS_CFG_CANCEL 0xffffffff 405#define HS_CFG_CANCEL 0xffffffff
406#define HS_CFG_COND_DEF 0x00000000 406#define HS_CFG_COND_DEF 0x00000000
407#define HS_CFG_GPIO_DEF 0xff 407#define HS_CFG_GPIO_DEF 0xff
408#define HS_CFG_GAP_DEF 0 408#define HS_CFG_GAP_DEF 0xff
409#define HS_CFG_COND_BROADCAST_DATA 0x00000001 409#define HS_CFG_COND_BROADCAST_DATA 0x00000001
410#define HS_CFG_COND_UNICAST_DATA 0x00000002 410#define HS_CFG_COND_UNICAST_DATA 0x00000002
411#define HS_CFG_COND_MAC_EVENT 0x00000004 411#define HS_CFG_COND_MAC_EVENT 0x00000004
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index 3f25feb1508e..1398afa84064 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -1099,7 +1099,7 @@ mwifiex_11h_get_csa_closed_channel(struct mwifiex_private *priv)
1099 return 0; 1099 return 0;
1100 1100
1101 /* Clear csa channel, if DFS channel move time has passed */ 1101 /* Clear csa channel, if DFS channel move time has passed */
1102 if (jiffies > priv->csa_expire_time) { 1102 if (time_after(jiffies, priv->csa_expire_time)) {
1103 priv->csa_chan = 0; 1103 priv->csa_chan = 0;
1104 priv->csa_expire_time = 0; 1104 priv->csa_expire_time = 0;
1105 } 1105 }
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index d75f4ebd4bdc..45c5b3450cf5 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -1738,6 +1738,19 @@ mwifiex_parse_single_response_buf(struct mwifiex_private *priv, u8 **bss_info,
1738 return 0; 1738 return 0;
1739} 1739}
1740 1740
1741static void mwifiex_complete_scan(struct mwifiex_private *priv)
1742{
1743 struct mwifiex_adapter *adapter = priv->adapter;
1744
1745 if (adapter->curr_cmd->wait_q_enabled) {
1746 adapter->cmd_wait_q.status = 0;
1747 if (!priv->scan_request) {
1748 dev_dbg(adapter->dev, "complete internal scan\n");
1749 mwifiex_complete_cmd(adapter, adapter->curr_cmd);
1750 }
1751 }
1752}
1753
1741static void mwifiex_check_next_scan_command(struct mwifiex_private *priv) 1754static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1742{ 1755{
1743 struct mwifiex_adapter *adapter = priv->adapter; 1756 struct mwifiex_adapter *adapter = priv->adapter;
@@ -1751,16 +1764,9 @@ static void mwifiex_check_next_scan_command(struct mwifiex_private *priv)
1751 adapter->scan_processing = false; 1764 adapter->scan_processing = false;
1752 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags); 1765 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
1753 1766
1754 /* Need to indicate IOCTL complete */ 1767 if (!adapter->ext_scan)
1755 if (adapter->curr_cmd->wait_q_enabled) { 1768 mwifiex_complete_scan(priv);
1756 adapter->cmd_wait_q.status = 0; 1769
1757 if (!priv->scan_request) {
1758 dev_dbg(adapter->dev,
1759 "complete internal scan\n");
1760 mwifiex_complete_cmd(adapter,
1761 adapter->curr_cmd);
1762 }
1763 }
1764 if (priv->report_scan_result) 1770 if (priv->report_scan_result)
1765 priv->report_scan_result = false; 1771 priv->report_scan_result = false;
1766 1772
@@ -1965,6 +1971,9 @@ int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1965int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv) 1971int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv)
1966{ 1972{
1967 dev_dbg(priv->adapter->dev, "info: EXT scan returns successfully\n"); 1973 dev_dbg(priv->adapter->dev, "info: EXT scan returns successfully\n");
1974
1975 mwifiex_complete_scan(priv);
1976
1968 return 0; 1977 return 0;
1969} 1978}
1970 1979
diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
index 6d9738a5dc31..d3671d009f6c 100644
--- a/drivers/net/wireless/mwifiex/wmm.c
+++ b/drivers/net/wireless/mwifiex/wmm.c
@@ -163,6 +163,7 @@ void mwifiex_ralist_add(struct mwifiex_private *priv, const u8 *ra)
163 if (!mwifiex_queuing_ra_based(priv)) { 163 if (!mwifiex_queuing_ra_based(priv)) {
164 if (mwifiex_get_tdls_link_status(priv, ra) == 164 if (mwifiex_get_tdls_link_status(priv, ra) ==
165 TDLS_SETUP_COMPLETE) { 165 TDLS_SETUP_COMPLETE) {
166 ra_list->tdls_link = true;
166 ra_list->is_11n_enabled = 167 ra_list->is_11n_enabled =
167 mwifiex_tdls_peer_11n_enabled(priv, ra); 168 mwifiex_tdls_peer_11n_enabled(priv, ra);
168 } else { 169 } else {
diff --git a/drivers/net/wireless/rsi/rsi_common.h b/drivers/net/wireless/rsi/rsi_common.h
index f2f70784d4ad..d3fbe33d2324 100644
--- a/drivers/net/wireless/rsi/rsi_common.h
+++ b/drivers/net/wireless/rsi/rsi_common.h
@@ -63,7 +63,7 @@ static inline int rsi_create_kthread(struct rsi_common *common,
63 u8 *name) 63 u8 *name)
64{ 64{
65 init_completion(&thread->completion); 65 init_completion(&thread->completion);
66 thread->task = kthread_run(func_ptr, common, name); 66 thread->task = kthread_run(func_ptr, common, "%s", name);
67 if (IS_ERR(thread->task)) 67 if (IS_ERR(thread->task))
68 return (int)PTR_ERR(thread->task); 68 return (int)PTR_ERR(thread->task);
69 69
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index c61311084d7e..361435f8608a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -395,9 +395,6 @@ static struct usb_driver rtl8192cu_driver = {
395 /* .resume = rtl_usb_resume, */ 395 /* .resume = rtl_usb_resume, */
396 /* .reset_resume = rtl8192c_resume, */ 396 /* .reset_resume = rtl8192c_resume, */
397#endif /* CONFIG_PM */ 397#endif /* CONFIG_PM */
398#ifdef CONFIG_AUTOSUSPEND
399 .supports_autosuspend = 1,
400#endif
401 .disable_hub_initiated_lpm = 1, 398 .disable_hub_initiated_lpm = 1,
402}; 399};
403 400
diff --git a/drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c b/drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c
index 48fee1be78c2..5b4a714f3c8c 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c
+++ b/drivers/net/wireless/rtlwifi/rtl8723ae/hal_bt_coexist.c
@@ -32,7 +32,6 @@
32#include "dm.h" 32#include "dm.h"
33#include "fw.h" 33#include "fw.h"
34#include "../rtl8723com/fw_common.h" 34#include "../rtl8723com/fw_common.h"
35#include "../rtl8723com/fw_common.h"
36#include "phy.h" 35#include "phy.h"
37#include "reg.h" 36#include "reg.h"
38#include "hal_btc.h" 37#include "hal_btc.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8723be/trx.c b/drivers/net/wireless/rtlwifi/rtl8723be/trx.c
index e0a0d8c8fed5..969eaea5eddd 100644
--- a/drivers/net/wireless/rtlwifi/rtl8723be/trx.c
+++ b/drivers/net/wireless/rtlwifi/rtl8723be/trx.c
@@ -33,7 +33,6 @@
33#include "trx.h" 33#include "trx.h"
34#include "led.h" 34#include "led.h"
35#include "dm.h" 35#include "dm.h"
36#include "phy.h"
37 36
38static u8 _rtl8723be_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue) 37static u8 _rtl8723be_map_hwqueue_to_fwqueue(struct sk_buff *skb, u8 hw_queue)
39{ 38{
diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c
index b7a372af5eb7..4ac4d31f6c59 100644
--- a/drivers/nfc/port100.c
+++ b/drivers/nfc/port100.c
@@ -28,7 +28,8 @@
28 NFC_PROTO_MIFARE_MASK | \ 28 NFC_PROTO_MIFARE_MASK | \
29 NFC_PROTO_FELICA_MASK | \ 29 NFC_PROTO_FELICA_MASK | \
30 NFC_PROTO_NFC_DEP_MASK | \ 30 NFC_PROTO_NFC_DEP_MASK | \
31 NFC_PROTO_ISO14443_MASK) 31 NFC_PROTO_ISO14443_MASK | \
32 NFC_PROTO_ISO14443_B_MASK)
32 33
33#define PORT100_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC | \ 34#define PORT100_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC | \
34 NFC_DIGITAL_DRV_CAPS_TG_CRC) 35 NFC_DIGITAL_DRV_CAPS_TG_CRC)
@@ -120,6 +121,7 @@ struct port100_in_rf_setting {
120#define PORT100_COMM_TYPE_IN_212F 0x01 121#define PORT100_COMM_TYPE_IN_212F 0x01
121#define PORT100_COMM_TYPE_IN_424F 0x02 122#define PORT100_COMM_TYPE_IN_424F 0x02
122#define PORT100_COMM_TYPE_IN_106A 0x03 123#define PORT100_COMM_TYPE_IN_106A 0x03
124#define PORT100_COMM_TYPE_IN_106B 0x07
123 125
124static const struct port100_in_rf_setting in_rf_settings[] = { 126static const struct port100_in_rf_setting in_rf_settings[] = {
125 [NFC_DIGITAL_RF_TECH_212F] = { 127 [NFC_DIGITAL_RF_TECH_212F] = {
@@ -140,6 +142,12 @@ static const struct port100_in_rf_setting in_rf_settings[] = {
140 .in_recv_set_number = 15, 142 .in_recv_set_number = 15,
141 .in_recv_comm_type = PORT100_COMM_TYPE_IN_106A, 143 .in_recv_comm_type = PORT100_COMM_TYPE_IN_106A,
142 }, 144 },
145 [NFC_DIGITAL_RF_TECH_106B] = {
146 .in_send_set_number = 3,
147 .in_send_comm_type = PORT100_COMM_TYPE_IN_106B,
148 .in_recv_set_number = 15,
149 .in_recv_comm_type = PORT100_COMM_TYPE_IN_106B,
150 },
143 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */ 151 /* Ensures the array has NFC_DIGITAL_RF_TECH_LAST elements */
144 [NFC_DIGITAL_RF_TECH_LAST] = { 0 }, 152 [NFC_DIGITAL_RF_TECH_LAST] = { 0 },
145}; 153};
@@ -340,6 +348,32 @@ in_protocols[][PORT100_IN_MAX_NUM_PROTOCOLS + 1] = {
340 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED] = { 348 [NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED] = {
341 { PORT100_IN_PROT_END, 0 }, 349 { PORT100_IN_PROT_END, 0 },
342 }, 350 },
351 [NFC_DIGITAL_FRAMING_NFCB] = {
352 { PORT100_IN_PROT_INITIAL_GUARD_TIME, 20 },
353 { PORT100_IN_PROT_ADD_CRC, 1 },
354 { PORT100_IN_PROT_CHECK_CRC, 1 },
355 { PORT100_IN_PROT_MULTI_CARD, 0 },
356 { PORT100_IN_PROT_ADD_PARITY, 0 },
357 { PORT100_IN_PROT_CHECK_PARITY, 0 },
358 { PORT100_IN_PROT_BITWISE_AC_RECV_MODE, 0 },
359 { PORT100_IN_PROT_VALID_BIT_NUMBER, 8 },
360 { PORT100_IN_PROT_CRYPTO1, 0 },
361 { PORT100_IN_PROT_ADD_SOF, 1 },
362 { PORT100_IN_PROT_CHECK_SOF, 1 },
363 { PORT100_IN_PROT_ADD_EOF, 1 },
364 { PORT100_IN_PROT_CHECK_EOF, 1 },
365 { PORT100_IN_PROT_DEAF_TIME, 4 },
366 { PORT100_IN_PROT_CRM, 0 },
367 { PORT100_IN_PROT_CRM_MIN_LEN, 0 },
368 { PORT100_IN_PROT_T1_TAG_FRAME, 0 },
369 { PORT100_IN_PROT_RFCA, 0 },
370 { PORT100_IN_PROT_GUARD_TIME_AT_INITIATOR, 6 },
371 { PORT100_IN_PROT_END, 0 },
372 },
373 [NFC_DIGITAL_FRAMING_NFCB_T4T] = {
374 /* nfc_digital_framing_nfcb */
375 { PORT100_IN_PROT_END, 0 },
376 },
343 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */ 377 /* Ensures the array has NFC_DIGITAL_FRAMING_LAST elements */
344 [NFC_DIGITAL_FRAMING_LAST] = { 378 [NFC_DIGITAL_FRAMING_LAST] = {
345 { PORT100_IN_PROT_END, 0 }, 379 { PORT100_IN_PROT_END, 0 },
diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index efb36593ecb4..3b78b031e617 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -105,7 +105,8 @@
105 105
106#define TRF7970A_SUPPORTED_PROTOCOLS \ 106#define TRF7970A_SUPPORTED_PROTOCOLS \
107 (NFC_PROTO_MIFARE_MASK | NFC_PROTO_ISO14443_MASK | \ 107 (NFC_PROTO_MIFARE_MASK | NFC_PROTO_ISO14443_MASK | \
108 NFC_PROTO_ISO14443_B_MASK | NFC_PROTO_ISO15693_MASK) 108 NFC_PROTO_ISO14443_B_MASK | NFC_PROTO_FELICA_MASK | \
109 NFC_PROTO_ISO15693_MASK)
109 110
110#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */ 111#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */
111 112
@@ -867,6 +868,14 @@ static int trf7970a_config_rf_tech(struct trf7970a *trf, int tech)
867 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443B_106; 868 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443B_106;
868 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_ASK10; 869 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_ASK10;
869 break; 870 break;
871 case NFC_DIGITAL_RF_TECH_212F:
872 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_212;
873 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_ASK10;
874 break;
875 case NFC_DIGITAL_RF_TECH_424F:
876 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_424;
877 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_ASK10;
878 break;
870 case NFC_DIGITAL_RF_TECH_ISO15693: 879 case NFC_DIGITAL_RF_TECH_ISO15693:
871 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648; 880 trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648;
872 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_OOK; 881 trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_DEPTH_OOK;
@@ -898,6 +907,8 @@ static int trf7970a_config_framing(struct trf7970a *trf, int framing)
898 case NFC_DIGITAL_FRAMING_NFCA_T4T: 907 case NFC_DIGITAL_FRAMING_NFCA_T4T:
899 case NFC_DIGITAL_FRAMING_NFCB: 908 case NFC_DIGITAL_FRAMING_NFCB:
900 case NFC_DIGITAL_FRAMING_NFCB_T4T: 909 case NFC_DIGITAL_FRAMING_NFCB_T4T:
910 case NFC_DIGITAL_FRAMING_NFCF:
911 case NFC_DIGITAL_FRAMING_NFCF_T3T:
901 case NFC_DIGITAL_FRAMING_ISO15693_INVENTORY: 912 case NFC_DIGITAL_FRAMING_ISO15693_INVENTORY:
902 case NFC_DIGITAL_FRAMING_ISO15693_T5T: 913 case NFC_DIGITAL_FRAMING_ISO15693_T5T:
903 trf->tx_cmd = TRF7970A_CMD_TRANSMIT; 914 trf->tx_cmd = TRF7970A_CMD_TRANSMIT;
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f194ccb8539c..6bff13f74050 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1711,6 +1711,7 @@ enum ieee80211_eid {
1711 WLAN_EID_RRM_ENABLED_CAPABILITIES = 70, 1711 WLAN_EID_RRM_ENABLED_CAPABILITIES = 70,
1712 WLAN_EID_MULTIPLE_BSSID = 71, 1712 WLAN_EID_MULTIPLE_BSSID = 71,
1713 WLAN_EID_BSS_COEX_2040 = 72, 1713 WLAN_EID_BSS_COEX_2040 = 72,
1714 WLAN_EID_BSS_INTOLERANT_CHL_REPORT = 73,
1714 WLAN_EID_OVERLAP_BSS_SCAN_PARAM = 74, 1715 WLAN_EID_OVERLAP_BSS_SCAN_PARAM = 74,
1715 WLAN_EID_RIC_DESCRIPTOR = 75, 1716 WLAN_EID_RIC_DESCRIPTOR = 75,
1716 WLAN_EID_MMIE = 76, 1717 WLAN_EID_MMIE = 76,
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 4261a67682c0..16587dcd6a91 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1054,6 +1054,17 @@ struct hci_cp_write_page_scan_activity {
1054 __le16 window; 1054 __le16 window;
1055} __packed; 1055} __packed;
1056 1056
1057#define HCI_OP_READ_TX_POWER 0x0c2d
1058struct hci_cp_read_tx_power {
1059 __le16 handle;
1060 __u8 type;
1061} __packed;
1062struct hci_rp_read_tx_power {
1063 __u8 status;
1064 __le16 handle;
1065 __s8 tx_power;
1066} __packed;
1067
1057#define HCI_OP_READ_PAGE_SCAN_TYPE 0x0c46 1068#define HCI_OP_READ_PAGE_SCAN_TYPE 0x0c46
1058struct hci_rp_read_page_scan_type { 1069struct hci_rp_read_page_scan_type {
1059 __u8 status; 1070 __u8 status;
@@ -1064,6 +1075,16 @@ struct hci_rp_read_page_scan_type {
1064 #define PAGE_SCAN_TYPE_STANDARD 0x00 1075 #define PAGE_SCAN_TYPE_STANDARD 0x00
1065 #define PAGE_SCAN_TYPE_INTERLACED 0x01 1076 #define PAGE_SCAN_TYPE_INTERLACED 0x01
1066 1077
1078#define HCI_OP_READ_RSSI 0x1405
1079struct hci_cp_read_rssi {
1080 __le16 handle;
1081} __packed;
1082struct hci_rp_read_rssi {
1083 __u8 status;
1084 __le16 handle;
1085 __s8 rssi;
1086} __packed;
1087
1067#define HCI_OP_READ_LOCAL_AMP_INFO 0x1409 1088#define HCI_OP_READ_LOCAL_AMP_INFO 0x1409
1068struct hci_rp_read_local_amp_info { 1089struct hci_rp_read_local_amp_info {
1069 __u8 status; 1090 __u8 status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d73f41855ada..b386bf17e6c2 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -145,6 +145,10 @@ struct oob_data {
145/* Default LE RPA expiry time, 15 minutes */ 145/* Default LE RPA expiry time, 15 minutes */
146#define HCI_DEFAULT_RPA_TIMEOUT (15 * 60) 146#define HCI_DEFAULT_RPA_TIMEOUT (15 * 60)
147 147
148/* Default min/max age of connection information (1s/3s) */
149#define DEFAULT_CONN_INFO_MIN_AGE 1000
150#define DEFAULT_CONN_INFO_MAX_AGE 3000
151
148struct amp_assoc { 152struct amp_assoc {
149 __u16 len; 153 __u16 len;
150 __u16 offset; 154 __u16 offset;
@@ -200,6 +204,8 @@ struct hci_dev {
200 __u16 le_conn_min_interval; 204 __u16 le_conn_min_interval;
201 __u16 le_conn_max_interval; 205 __u16 le_conn_max_interval;
202 __u16 discov_interleaved_timeout; 206 __u16 discov_interleaved_timeout;
207 __u16 conn_info_min_age;
208 __u16 conn_info_max_age;
203 __u8 ssp_debug_mode; 209 __u8 ssp_debug_mode;
204 210
205 __u16 devid_source; 211 __u16 devid_source;
@@ -374,8 +380,13 @@ struct hci_conn {
374 __u16 setting; 380 __u16 setting;
375 __u16 le_conn_min_interval; 381 __u16 le_conn_min_interval;
376 __u16 le_conn_max_interval; 382 __u16 le_conn_max_interval;
383 __s8 rssi;
384 __s8 tx_power;
385 __s8 max_tx_power;
377 unsigned long flags; 386 unsigned long flags;
378 387
388 unsigned long conn_info_timestamp;
389
379 __u8 remote_cap; 390 __u8 remote_cap;
380 __u8 remote_auth; 391 __u8 remote_auth;
381 __u8 remote_id; 392 __u8 remote_id;
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index d4b571c2f9fd..bcffc9ae0c89 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -181,6 +181,9 @@ struct mgmt_cp_load_link_keys {
181} __packed; 181} __packed;
182#define MGMT_LOAD_LINK_KEYS_SIZE 3 182#define MGMT_LOAD_LINK_KEYS_SIZE 3
183 183
184#define MGMT_LTK_UNAUTHENTICATED 0x00
185#define MGMT_LTK_AUTHENTICATED 0x01
186
184struct mgmt_ltk_info { 187struct mgmt_ltk_info {
185 struct mgmt_addr_info addr; 188 struct mgmt_addr_info addr;
186 __u8 type; 189 __u8 type;
@@ -409,6 +412,18 @@ struct mgmt_cp_load_irks {
409} __packed; 412} __packed;
410#define MGMT_LOAD_IRKS_SIZE 2 413#define MGMT_LOAD_IRKS_SIZE 2
411 414
415#define MGMT_OP_GET_CONN_INFO 0x0031
416struct mgmt_cp_get_conn_info {
417 struct mgmt_addr_info addr;
418} __packed;
419#define MGMT_GET_CONN_INFO_SIZE MGMT_ADDR_INFO_SIZE
420struct mgmt_rp_get_conn_info {
421 struct mgmt_addr_info addr;
422 __s8 rssi;
423 __s8 tx_power;
424 __s8 max_tx_power;
425} __packed;
426
412#define MGMT_EV_CMD_COMPLETE 0x0001 427#define MGMT_EV_CMD_COMPLETE 0x0001
413struct mgmt_ev_cmd_complete { 428struct mgmt_ev_cmd_complete {
414 __le16 opcode; 429 __le16 opcode;
diff --git a/include/net/bluetooth/rfcomm.h b/include/net/bluetooth/rfcomm.h
index 2611cc389d7d..578b83127af1 100644
--- a/include/net/bluetooth/rfcomm.h
+++ b/include/net/bluetooth/rfcomm.h
@@ -173,7 +173,7 @@ struct rfcomm_dlc {
173 struct sk_buff_head tx_queue; 173 struct sk_buff_head tx_queue;
174 struct timer_list timer; 174 struct timer_list timer;
175 175
176 spinlock_t lock; 176 struct mutex lock;
177 unsigned long state; 177 unsigned long state;
178 unsigned long flags; 178 unsigned long flags;
179 atomic_t refcnt; 179 atomic_t refcnt;
@@ -244,8 +244,8 @@ int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
244void rfcomm_dlc_accept(struct rfcomm_dlc *d); 244void rfcomm_dlc_accept(struct rfcomm_dlc *d);
245struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel); 245struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel);
246 246
247#define rfcomm_dlc_lock(d) spin_lock(&d->lock) 247#define rfcomm_dlc_lock(d) mutex_lock(&d->lock)
248#define rfcomm_dlc_unlock(d) spin_unlock(&d->lock) 248#define rfcomm_dlc_unlock(d) mutex_unlock(&d->lock)
249 249
250static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d) 250static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
251{ 251{
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 2c78997bc48d..421b6ecb4b2c 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -189,6 +189,43 @@ struct ieee80211_chanctx_conf {
189}; 189};
190 190
191/** 191/**
192 * enum ieee80211_chanctx_switch_mode - channel context switch mode
193 * @CHANCTX_SWMODE_REASSIGN_VIF: Both old and new contexts already
194 * exist (and will continue to exist), but the virtual interface
195 * needs to be switched from one to the other.
196 * @CHANCTX_SWMODE_SWAP_CONTEXTS: The old context exists but will stop
197 * to exist with this call, the new context doesn't exist but
198 * will be active after this call, the virtual interface switches
199 * from the old to the new (note that the driver may of course
200 * implement this as an on-the-fly chandef switch of the existing
201 * hardware context, but the mac80211 pointer for the old context
202 * will cease to exist and only the new one will later be used
203 * for changes/removal.)
204 */
205enum ieee80211_chanctx_switch_mode {
206 CHANCTX_SWMODE_REASSIGN_VIF,
207 CHANCTX_SWMODE_SWAP_CONTEXTS,
208};
209
210/**
211 * struct ieee80211_vif_chanctx_switch - vif chanctx switch information
212 *
213 * This is structure is used to pass information about a vif that
214 * needs to switch from one chanctx to another. The
215 * &ieee80211_chanctx_switch_mode defines how the switch should be
216 * done.
217 *
218 * @vif: the vif that should be switched from old_ctx to new_ctx
219 * @old_ctx: the old context to which the vif was assigned
220 * @new_ctx: the new context to which the vif must be assigned
221 */
222struct ieee80211_vif_chanctx_switch {
223 struct ieee80211_vif *vif;
224 struct ieee80211_chanctx_conf *old_ctx;
225 struct ieee80211_chanctx_conf *new_ctx;
226};
227
228/**
192 * enum ieee80211_bss_change - BSS change notification flags 229 * enum ieee80211_bss_change - BSS change notification flags
193 * 230 *
194 * These flags are used with the bss_info_changed() callback 231 * These flags are used with the bss_info_changed() callback
@@ -2736,6 +2773,11 @@ enum ieee80211_roc_type {
2736 * to vif. Possible use is for hw queue remapping. 2773 * to vif. Possible use is for hw queue remapping.
2737 * @unassign_vif_chanctx: Notifies device driver about channel context being 2774 * @unassign_vif_chanctx: Notifies device driver about channel context being
2738 * unbound from vif. 2775 * unbound from vif.
2776 * @switch_vif_chanctx: switch a number of vifs from one chanctx to
2777 * another, as specified in the list of
2778 * @ieee80211_vif_chanctx_switch passed to the driver, according
2779 * to the mode defined in &ieee80211_chanctx_switch_mode.
2780 *
2739 * @start_ap: Start operation on the AP interface, this is called after all the 2781 * @start_ap: Start operation on the AP interface, this is called after all the
2740 * information in bss_conf is set and beacon can be retrieved. A channel 2782 * information in bss_conf is set and beacon can be retrieved. A channel
2741 * context is bound before this is called. Note that if the driver uses 2783 * context is bound before this is called. Note that if the driver uses
@@ -2952,6 +2994,10 @@ struct ieee80211_ops {
2952 void (*unassign_vif_chanctx)(struct ieee80211_hw *hw, 2994 void (*unassign_vif_chanctx)(struct ieee80211_hw *hw,
2953 struct ieee80211_vif *vif, 2995 struct ieee80211_vif *vif,
2954 struct ieee80211_chanctx_conf *ctx); 2996 struct ieee80211_chanctx_conf *ctx);
2997 int (*switch_vif_chanctx)(struct ieee80211_hw *hw,
2998 struct ieee80211_vif_chanctx_switch *vifs,
2999 int n_vifs,
3000 enum ieee80211_chanctx_switch_mode mode);
2955 3001
2956 void (*restart_complete)(struct ieee80211_hw *hw); 3002 void (*restart_complete)(struct ieee80211_hw *hw);
2957 3003
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 095943c02d6e..8671bc79a35b 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -28,6 +28,7 @@
28 28
29#include <net/bluetooth/bluetooth.h> 29#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h> 30#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/l2cap.h>
31 32
32#include "smp.h" 33#include "smp.h"
33#include "a2mp.h" 34#include "a2mp.h"
@@ -407,6 +408,8 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
407 conn->io_capability = hdev->io_capability; 408 conn->io_capability = hdev->io_capability;
408 conn->remote_auth = 0xff; 409 conn->remote_auth = 0xff;
409 conn->key_type = 0xff; 410 conn->key_type = 0xff;
411 conn->tx_power = HCI_TX_POWER_INVALID;
412 conn->max_tx_power = HCI_TX_POWER_INVALID;
410 413
411 set_bit(HCI_CONN_POWER_SAVE, &conn->flags); 414 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
412 conn->disc_timeout = HCI_DISCONN_TIMEOUT; 415 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d31f144860d1..0a43cce9a914 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -34,6 +34,7 @@
34 34
35#include <net/bluetooth/bluetooth.h> 35#include <net/bluetooth/bluetooth.h>
36#include <net/bluetooth/hci_core.h> 36#include <net/bluetooth/hci_core.h>
37#include <net/bluetooth/l2cap.h>
37 38
38#include "smp.h" 39#include "smp.h"
39 40
@@ -579,6 +580,62 @@ static int sniff_max_interval_get(void *data, u64 *val)
579DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get, 580DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get,
580 sniff_max_interval_set, "%llu\n"); 581 sniff_max_interval_set, "%llu\n");
581 582
583static int conn_info_min_age_set(void *data, u64 val)
584{
585 struct hci_dev *hdev = data;
586
587 if (val == 0 || val > hdev->conn_info_max_age)
588 return -EINVAL;
589
590 hci_dev_lock(hdev);
591 hdev->conn_info_min_age = val;
592 hci_dev_unlock(hdev);
593
594 return 0;
595}
596
597static int conn_info_min_age_get(void *data, u64 *val)
598{
599 struct hci_dev *hdev = data;
600
601 hci_dev_lock(hdev);
602 *val = hdev->conn_info_min_age;
603 hci_dev_unlock(hdev);
604
605 return 0;
606}
607
608DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get,
609 conn_info_min_age_set, "%llu\n");
610
611static int conn_info_max_age_set(void *data, u64 val)
612{
613 struct hci_dev *hdev = data;
614
615 if (val == 0 || val < hdev->conn_info_min_age)
616 return -EINVAL;
617
618 hci_dev_lock(hdev);
619 hdev->conn_info_max_age = val;
620 hci_dev_unlock(hdev);
621
622 return 0;
623}
624
625static int conn_info_max_age_get(void *data, u64 *val)
626{
627 struct hci_dev *hdev = data;
628
629 hci_dev_lock(hdev);
630 *val = hdev->conn_info_max_age;
631 hci_dev_unlock(hdev);
632
633 return 0;
634}
635
636DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get,
637 conn_info_max_age_set, "%llu\n");
638
582static int identity_show(struct seq_file *f, void *p) 639static int identity_show(struct seq_file *f, void *p)
583{ 640{
584 struct hci_dev *hdev = f->private; 641 struct hci_dev *hdev = f->private;
@@ -1754,6 +1811,11 @@ static int __hci_init(struct hci_dev *hdev)
1754 &blacklist_fops); 1811 &blacklist_fops);
1755 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops); 1812 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
1756 1813
1814 debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev,
1815 &conn_info_min_age_fops);
1816 debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev,
1817 &conn_info_max_age_fops);
1818
1757 if (lmp_bredr_capable(hdev)) { 1819 if (lmp_bredr_capable(hdev)) {
1758 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, 1820 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
1759 hdev, &inquiry_cache_fops); 1821 hdev, &inquiry_cache_fops);
@@ -3789,6 +3851,8 @@ struct hci_dev *hci_alloc_dev(void)
3789 3851
3790 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; 3852 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
3791 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; 3853 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
3854 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE;
3855 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE;
3792 3856
3793 mutex_init(&hdev->lock); 3857 mutex_init(&hdev->lock);
3794 mutex_init(&hdev->req_lock); 3858 mutex_init(&hdev->req_lock);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index ca19fd4bbb8f..3454807a40c5 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1245,6 +1245,59 @@ static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
1245 amp_write_rem_assoc_continue(hdev, rp->phy_handle); 1245 amp_write_rem_assoc_continue(hdev, rp->phy_handle);
1246} 1246}
1247 1247
1248static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
1249{
1250 struct hci_rp_read_rssi *rp = (void *) skb->data;
1251 struct hci_conn *conn;
1252
1253 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1254
1255 if (rp->status)
1256 return;
1257
1258 hci_dev_lock(hdev);
1259
1260 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1261 if (conn)
1262 conn->rssi = rp->rssi;
1263
1264 hci_dev_unlock(hdev);
1265}
1266
1267static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
1268{
1269 struct hci_cp_read_tx_power *sent;
1270 struct hci_rp_read_tx_power *rp = (void *) skb->data;
1271 struct hci_conn *conn;
1272
1273 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1274
1275 if (rp->status)
1276 return;
1277
1278 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
1279 if (!sent)
1280 return;
1281
1282 hci_dev_lock(hdev);
1283
1284 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1285 if (!conn)
1286 goto unlock;
1287
1288 switch (sent->type) {
1289 case 0x00:
1290 conn->tx_power = rp->tx_power;
1291 break;
1292 case 0x01:
1293 conn->max_tx_power = rp->tx_power;
1294 break;
1295 }
1296
1297unlock:
1298 hci_dev_unlock(hdev);
1299}
1300
1248static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) 1301static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1249{ 1302{
1250 BT_DBG("%s status 0x%2.2x", hdev->name, status); 1303 BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -2637,6 +2690,14 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2637 hci_cc_write_remote_amp_assoc(hdev, skb); 2690 hci_cc_write_remote_amp_assoc(hdev, skb);
2638 break; 2691 break;
2639 2692
2693 case HCI_OP_READ_RSSI:
2694 hci_cc_read_rssi(hdev, skb);
2695 break;
2696
2697 case HCI_OP_READ_TX_POWER:
2698 hci_cc_read_tx_power(hdev, skb);
2699 break;
2700
2640 default: 2701 default:
2641 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); 2702 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
2642 break; 2703 break;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 54abbce3a39e..5e9c21a5525f 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -29,12 +29,13 @@
29 29
30#include <net/bluetooth/bluetooth.h> 30#include <net/bluetooth/bluetooth.h>
31#include <net/bluetooth/hci_core.h> 31#include <net/bluetooth/hci_core.h>
32#include <net/bluetooth/l2cap.h>
32#include <net/bluetooth/mgmt.h> 33#include <net/bluetooth/mgmt.h>
33 34
34#include "smp.h" 35#include "smp.h"
35 36
36#define MGMT_VERSION 1 37#define MGMT_VERSION 1
37#define MGMT_REVISION 5 38#define MGMT_REVISION 6
38 39
39static const u16 mgmt_commands[] = { 40static const u16 mgmt_commands[] = {
40 MGMT_OP_READ_INDEX_LIST, 41 MGMT_OP_READ_INDEX_LIST,
@@ -83,6 +84,7 @@ static const u16 mgmt_commands[] = {
83 MGMT_OP_SET_DEBUG_KEYS, 84 MGMT_OP_SET_DEBUG_KEYS,
84 MGMT_OP_SET_PRIVACY, 85 MGMT_OP_SET_PRIVACY,
85 MGMT_OP_LOAD_IRKS, 86 MGMT_OP_LOAD_IRKS,
87 MGMT_OP_GET_CONN_INFO,
86}; 88};
87 89
88static const u16 mgmt_events[] = { 90static const u16 mgmt_events[] = {
@@ -4532,7 +4534,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
4532 4534
4533 for (i = 0; i < key_count; i++) { 4535 for (i = 0; i < key_count; i++) {
4534 struct mgmt_ltk_info *key = &cp->keys[i]; 4536 struct mgmt_ltk_info *key = &cp->keys[i];
4535 u8 type, addr_type; 4537 u8 type, addr_type, authenticated;
4536 4538
4537 if (key->addr.type == BDADDR_LE_PUBLIC) 4539 if (key->addr.type == BDADDR_LE_PUBLIC)
4538 addr_type = ADDR_LE_DEV_PUBLIC; 4540 addr_type = ADDR_LE_DEV_PUBLIC;
@@ -4544,8 +4546,13 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
4544 else 4546 else
4545 type = HCI_SMP_LTK_SLAVE; 4547 type = HCI_SMP_LTK_SLAVE;
4546 4548
4549 if (key->type == MGMT_LTK_UNAUTHENTICATED)
4550 authenticated = 0x00;
4551 else
4552 authenticated = 0x01;
4553
4547 hci_add_ltk(hdev, &key->addr.bdaddr, addr_type, type, 4554 hci_add_ltk(hdev, &key->addr.bdaddr, addr_type, type,
4548 key->type, key->val, key->enc_size, key->ediv, 4555 authenticated, key->val, key->enc_size, key->ediv,
4549 key->rand); 4556 key->rand);
4550 } 4557 }
4551 4558
@@ -4557,6 +4564,218 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
4557 return err; 4564 return err;
4558} 4565}
4559 4566
4567struct cmd_conn_lookup {
4568 struct hci_conn *conn;
4569 bool valid_tx_power;
4570 u8 mgmt_status;
4571};
4572
4573static void get_conn_info_complete(struct pending_cmd *cmd, void *data)
4574{
4575 struct cmd_conn_lookup *match = data;
4576 struct mgmt_cp_get_conn_info *cp;
4577 struct mgmt_rp_get_conn_info rp;
4578 struct hci_conn *conn = cmd->user_data;
4579
4580 if (conn != match->conn)
4581 return;
4582
4583 cp = (struct mgmt_cp_get_conn_info *) cmd->param;
4584
4585 memset(&rp, 0, sizeof(rp));
4586 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
4587 rp.addr.type = cp->addr.type;
4588
4589 if (!match->mgmt_status) {
4590 rp.rssi = conn->rssi;
4591
4592 if (match->valid_tx_power) {
4593 rp.tx_power = conn->tx_power;
4594 rp.max_tx_power = conn->max_tx_power;
4595 } else {
4596 rp.tx_power = HCI_TX_POWER_INVALID;
4597 rp.max_tx_power = HCI_TX_POWER_INVALID;
4598 }
4599 }
4600
4601 cmd_complete(cmd->sk, cmd->index, MGMT_OP_GET_CONN_INFO,
4602 match->mgmt_status, &rp, sizeof(rp));
4603
4604 hci_conn_drop(conn);
4605
4606 mgmt_pending_remove(cmd);
4607}
4608
4609static void conn_info_refresh_complete(struct hci_dev *hdev, u8 status)
4610{
4611 struct hci_cp_read_rssi *cp;
4612 struct hci_conn *conn;
4613 struct cmd_conn_lookup match;
4614 u16 handle;
4615
4616 BT_DBG("status 0x%02x", status);
4617
4618 hci_dev_lock(hdev);
4619
4620 /* TX power data is valid in case request completed successfully,
4621 * otherwise we assume it's not valid. At the moment we assume that
4622 * either both or none of current and max values are valid to keep code
4623 * simple.
4624 */
4625 match.valid_tx_power = !status;
4626
4627 /* Commands sent in request are either Read RSSI or Read Transmit Power
4628 * Level so we check which one was last sent to retrieve connection
4629 * handle. Both commands have handle as first parameter so it's safe to
4630 * cast data on the same command struct.
4631 *
4632 * First command sent is always Read RSSI and we fail only if it fails.
4633 * In other case we simply override error to indicate success as we
4634 * already remembered if TX power value is actually valid.
4635 */
4636 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_RSSI);
4637 if (!cp) {
4638 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
4639 status = 0;
4640 }
4641
4642 if (!cp) {
4643 BT_ERR("invalid sent_cmd in response");
4644 goto unlock;
4645 }
4646
4647 handle = __le16_to_cpu(cp->handle);
4648 conn = hci_conn_hash_lookup_handle(hdev, handle);
4649 if (!conn) {
4650 BT_ERR("unknown handle (%d) in response", handle);
4651 goto unlock;
4652 }
4653
4654 match.conn = conn;
4655 match.mgmt_status = mgmt_status(status);
4656
4657 /* Cache refresh is complete, now reply for mgmt request for given
4658 * connection only.
4659 */
4660 mgmt_pending_foreach(MGMT_OP_GET_CONN_INFO, hdev,
4661 get_conn_info_complete, &match);
4662
4663unlock:
4664 hci_dev_unlock(hdev);
4665}
4666
4667static int get_conn_info(struct sock *sk, struct hci_dev *hdev, void *data,
4668 u16 len)
4669{
4670 struct mgmt_cp_get_conn_info *cp = data;
4671 struct mgmt_rp_get_conn_info rp;
4672 struct hci_conn *conn;
4673 unsigned long conn_info_age;
4674 int err = 0;
4675
4676 BT_DBG("%s", hdev->name);
4677
4678 memset(&rp, 0, sizeof(rp));
4679 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
4680 rp.addr.type = cp->addr.type;
4681
4682 if (!bdaddr_type_is_valid(cp->addr.type))
4683 return cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO,
4684 MGMT_STATUS_INVALID_PARAMS,
4685 &rp, sizeof(rp));
4686
4687 hci_dev_lock(hdev);
4688
4689 if (!hdev_is_powered(hdev)) {
4690 err = cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO,
4691 MGMT_STATUS_NOT_POWERED, &rp, sizeof(rp));
4692 goto unlock;
4693 }
4694
4695 if (cp->addr.type == BDADDR_BREDR)
4696 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
4697 &cp->addr.bdaddr);
4698 else
4699 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr);
4700
4701 if (!conn || conn->state != BT_CONNECTED) {
4702 err = cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO,
4703 MGMT_STATUS_NOT_CONNECTED, &rp, sizeof(rp));
4704 goto unlock;
4705 }
4706
4707 /* To avoid client trying to guess when to poll again for information we
4708 * calculate conn info age as random value between min/max set in hdev.
4709 */
4710 conn_info_age = hdev->conn_info_min_age +
4711 prandom_u32_max(hdev->conn_info_max_age -
4712 hdev->conn_info_min_age);
4713
4714 /* Query controller to refresh cached values if they are too old or were
4715 * never read.
4716 */
4717 if (time_after(jiffies, conn->conn_info_timestamp +
4718 msecs_to_jiffies(conn_info_age)) ||
4719 !conn->conn_info_timestamp) {
4720 struct hci_request req;
4721 struct hci_cp_read_tx_power req_txp_cp;
4722 struct hci_cp_read_rssi req_rssi_cp;
4723 struct pending_cmd *cmd;
4724
4725 hci_req_init(&req, hdev);
4726 req_rssi_cp.handle = cpu_to_le16(conn->handle);
4727 hci_req_add(&req, HCI_OP_READ_RSSI, sizeof(req_rssi_cp),
4728 &req_rssi_cp);
4729
4730 /* For LE links TX power does not change thus we don't need to
4731 * query for it once value is known.
4732 */
4733 if (!bdaddr_type_is_le(cp->addr.type) ||
4734 conn->tx_power == HCI_TX_POWER_INVALID) {
4735 req_txp_cp.handle = cpu_to_le16(conn->handle);
4736 req_txp_cp.type = 0x00;
4737 hci_req_add(&req, HCI_OP_READ_TX_POWER,
4738 sizeof(req_txp_cp), &req_txp_cp);
4739 }
4740
4741 /* Max TX power needs to be read only once per connection */
4742 if (conn->max_tx_power == HCI_TX_POWER_INVALID) {
4743 req_txp_cp.handle = cpu_to_le16(conn->handle);
4744 req_txp_cp.type = 0x01;
4745 hci_req_add(&req, HCI_OP_READ_TX_POWER,
4746 sizeof(req_txp_cp), &req_txp_cp);
4747 }
4748
4749 err = hci_req_run(&req, conn_info_refresh_complete);
4750 if (err < 0)
4751 goto unlock;
4752
4753 cmd = mgmt_pending_add(sk, MGMT_OP_GET_CONN_INFO, hdev,
4754 data, len);
4755 if (!cmd) {
4756 err = -ENOMEM;
4757 goto unlock;
4758 }
4759
4760 hci_conn_hold(conn);
4761 cmd->user_data = conn;
4762
4763 conn->conn_info_timestamp = jiffies;
4764 } else {
4765 /* Cache is valid, just reply with values cached in hci_conn */
4766 rp.rssi = conn->rssi;
4767 rp.tx_power = conn->tx_power;
4768 rp.max_tx_power = conn->max_tx_power;
4769
4770 err = cmd_complete(sk, hdev->id, MGMT_OP_GET_CONN_INFO,
4771 MGMT_STATUS_SUCCESS, &rp, sizeof(rp));
4772 }
4773
4774unlock:
4775 hci_dev_unlock(hdev);
4776 return err;
4777}
4778
4560static const struct mgmt_handler { 4779static const struct mgmt_handler {
4561 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data, 4780 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
4562 u16 data_len); 4781 u16 data_len);
@@ -4612,6 +4831,7 @@ static const struct mgmt_handler {
4612 { set_debug_keys, false, MGMT_SETTING_SIZE }, 4831 { set_debug_keys, false, MGMT_SETTING_SIZE },
4613 { set_privacy, false, MGMT_SET_PRIVACY_SIZE }, 4832 { set_privacy, false, MGMT_SET_PRIVACY_SIZE },
4614 { load_irks, true, MGMT_LOAD_IRKS_SIZE }, 4833 { load_irks, true, MGMT_LOAD_IRKS_SIZE },
4834 { get_conn_info, false, MGMT_GET_CONN_INFO_SIZE },
4615}; 4835};
4616 4836
4617 4837
@@ -5007,6 +5227,14 @@ void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
5007 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); 5227 mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
5008} 5228}
5009 5229
5230static u8 mgmt_ltk_type(struct smp_ltk *ltk)
5231{
5232 if (ltk->authenticated)
5233 return MGMT_LTK_AUTHENTICATED;
5234
5235 return MGMT_LTK_UNAUTHENTICATED;
5236}
5237
5010void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent) 5238void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
5011{ 5239{
5012 struct mgmt_ev_new_long_term_key ev; 5240 struct mgmt_ev_new_long_term_key ev;
@@ -5032,7 +5260,7 @@ void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent)
5032 5260
5033 bacpy(&ev.key.addr.bdaddr, &key->bdaddr); 5261 bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
5034 ev.key.addr.type = link_to_bdaddr(LE_LINK, key->bdaddr_type); 5262 ev.key.addr.type = link_to_bdaddr(LE_LINK, key->bdaddr_type);
5035 ev.key.type = key->authenticated; 5263 ev.key.type = mgmt_ltk_type(key);
5036 ev.key.enc_size = key->enc_size; 5264 ev.key.enc_size = key->enc_size;
5037 ev.key.ediv = key->ediv; 5265 ev.key.ediv = key->ediv;
5038 ev.key.rand = key->rand; 5266 ev.key.rand = key->rand;
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index cf620260affa..754b6fe4f742 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -307,7 +307,7 @@ struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio)
307 setup_timer(&d->timer, rfcomm_dlc_timeout, (unsigned long)d); 307 setup_timer(&d->timer, rfcomm_dlc_timeout, (unsigned long)d);
308 308
309 skb_queue_head_init(&d->tx_queue); 309 skb_queue_head_init(&d->tx_queue);
310 spin_lock_init(&d->lock); 310 mutex_init(&d->lock);
311 atomic_set(&d->refcnt, 1); 311 atomic_set(&d->refcnt, 1);
312 312
313 rfcomm_dlc_clear_state(d); 313 rfcomm_dlc_clear_state(d);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 403ec09f480a..8e385a0ae60e 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -70,7 +70,7 @@ struct rfcomm_dev {
70}; 70};
71 71
72static LIST_HEAD(rfcomm_dev_list); 72static LIST_HEAD(rfcomm_dev_list);
73static DEFINE_SPINLOCK(rfcomm_dev_lock); 73static DEFINE_MUTEX(rfcomm_dev_lock);
74 74
75static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb); 75static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc, struct sk_buff *skb);
76static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err); 76static void rfcomm_dev_state_change(struct rfcomm_dlc *dlc, int err);
@@ -96,9 +96,9 @@ static void rfcomm_dev_destruct(struct tty_port *port)
96 if (dev->tty_dev) 96 if (dev->tty_dev)
97 tty_unregister_device(rfcomm_tty_driver, dev->id); 97 tty_unregister_device(rfcomm_tty_driver, dev->id);
98 98
99 spin_lock(&rfcomm_dev_lock); 99 mutex_lock(&rfcomm_dev_lock);
100 list_del(&dev->list); 100 list_del(&dev->list);
101 spin_unlock(&rfcomm_dev_lock); 101 mutex_unlock(&rfcomm_dev_lock);
102 102
103 kfree(dev); 103 kfree(dev);
104 104
@@ -161,14 +161,14 @@ static struct rfcomm_dev *rfcomm_dev_get(int id)
161{ 161{
162 struct rfcomm_dev *dev; 162 struct rfcomm_dev *dev;
163 163
164 spin_lock(&rfcomm_dev_lock); 164 mutex_lock(&rfcomm_dev_lock);
165 165
166 dev = __rfcomm_dev_lookup(id); 166 dev = __rfcomm_dev_lookup(id);
167 167
168 if (dev && !tty_port_get(&dev->port)) 168 if (dev && !tty_port_get(&dev->port))
169 dev = NULL; 169 dev = NULL;
170 170
171 spin_unlock(&rfcomm_dev_lock); 171 mutex_unlock(&rfcomm_dev_lock);
172 172
173 return dev; 173 return dev;
174} 174}
@@ -224,7 +224,7 @@ static struct rfcomm_dev *__rfcomm_dev_add(struct rfcomm_dev_req *req,
224 if (!dev) 224 if (!dev)
225 return ERR_PTR(-ENOMEM); 225 return ERR_PTR(-ENOMEM);
226 226
227 spin_lock(&rfcomm_dev_lock); 227 mutex_lock(&rfcomm_dev_lock);
228 228
229 if (req->dev_id < 0) { 229 if (req->dev_id < 0) {
230 dev->id = 0; 230 dev->id = 0;
@@ -305,11 +305,11 @@ static struct rfcomm_dev *__rfcomm_dev_add(struct rfcomm_dev_req *req,
305 holds reference to this module. */ 305 holds reference to this module. */
306 __module_get(THIS_MODULE); 306 __module_get(THIS_MODULE);
307 307
308 spin_unlock(&rfcomm_dev_lock); 308 mutex_unlock(&rfcomm_dev_lock);
309 return dev; 309 return dev;
310 310
311out: 311out:
312 spin_unlock(&rfcomm_dev_lock); 312 mutex_unlock(&rfcomm_dev_lock);
313 kfree(dev); 313 kfree(dev);
314 return ERR_PTR(err); 314 return ERR_PTR(err);
315} 315}
@@ -524,7 +524,7 @@ static int rfcomm_get_dev_list(void __user *arg)
524 524
525 di = dl->dev_info; 525 di = dl->dev_info;
526 526
527 spin_lock(&rfcomm_dev_lock); 527 mutex_lock(&rfcomm_dev_lock);
528 528
529 list_for_each_entry(dev, &rfcomm_dev_list, list) { 529 list_for_each_entry(dev, &rfcomm_dev_list, list) {
530 if (!tty_port_get(&dev->port)) 530 if (!tty_port_get(&dev->port))
@@ -540,7 +540,7 @@ static int rfcomm_get_dev_list(void __user *arg)
540 break; 540 break;
541 } 541 }
542 542
543 spin_unlock(&rfcomm_dev_lock); 543 mutex_unlock(&rfcomm_dev_lock);
544 544
545 dl->dev_num = n; 545 dl->dev_num = n;
546 size = sizeof(*dl) + n * sizeof(*di); 546 size = sizeof(*dl) + n * sizeof(*di);
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index dfb4e1161c10..4f9662d0fd81 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -35,6 +35,33 @@
35 35
36#define AUTH_REQ_MASK 0x07 36#define AUTH_REQ_MASK 0x07
37 37
38#define SMP_FLAG_TK_VALID 1
39#define SMP_FLAG_CFM_PENDING 2
40#define SMP_FLAG_MITM_AUTH 3
41#define SMP_FLAG_COMPLETE 4
42#define SMP_FLAG_INITIATOR 5
43
44struct smp_chan {
45 struct l2cap_conn *conn;
46 u8 preq[7]; /* SMP Pairing Request */
47 u8 prsp[7]; /* SMP Pairing Response */
48 u8 prnd[16]; /* SMP Pairing Random (local) */
49 u8 rrnd[16]; /* SMP Pairing Random (remote) */
50 u8 pcnf[16]; /* SMP Pairing Confirm */
51 u8 tk[16]; /* SMP Temporary Key */
52 u8 enc_key_size;
53 u8 remote_key_dist;
54 bdaddr_t id_addr;
55 u8 id_addr_type;
56 u8 irk[16];
57 struct smp_csrk *csrk;
58 struct smp_csrk *slave_csrk;
59 struct smp_ltk *ltk;
60 struct smp_ltk *slave_ltk;
61 struct smp_irk *remote_irk;
62 unsigned long flags;
63};
64
38static inline void swap128(const u8 src[16], u8 dst[16]) 65static inline void swap128(const u8 src[16], u8 dst[16])
39{ 66{
40 int i; 67 int i;
@@ -369,7 +396,7 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
369 396
370 /* Initialize key for JUST WORKS */ 397 /* Initialize key for JUST WORKS */
371 memset(smp->tk, 0, sizeof(smp->tk)); 398 memset(smp->tk, 0, sizeof(smp->tk));
372 clear_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); 399 clear_bit(SMP_FLAG_TK_VALID, &smp->flags);
373 400
374 BT_DBG("tk_request: auth:%d lcl:%d rem:%d", auth, local_io, remote_io); 401 BT_DBG("tk_request: auth:%d lcl:%d rem:%d", auth, local_io, remote_io);
375 402
@@ -388,19 +415,18 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
388 method = JUST_WORKS; 415 method = JUST_WORKS;
389 416
390 /* Don't confirm locally initiated pairing attempts */ 417 /* Don't confirm locally initiated pairing attempts */
391 if (method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, 418 if (method == JUST_CFM && test_bit(SMP_FLAG_INITIATOR, &smp->flags))
392 &smp->smp_flags))
393 method = JUST_WORKS; 419 method = JUST_WORKS;
394 420
395 /* If Just Works, Continue with Zero TK */ 421 /* If Just Works, Continue with Zero TK */
396 if (method == JUST_WORKS) { 422 if (method == JUST_WORKS) {
397 set_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); 423 set_bit(SMP_FLAG_TK_VALID, &smp->flags);
398 return 0; 424 return 0;
399 } 425 }
400 426
401 /* Not Just Works/Confirm results in MITM Authentication */ 427 /* Not Just Works/Confirm results in MITM Authentication */
402 if (method != JUST_CFM) 428 if (method != JUST_CFM)
403 set_bit(SMP_FLAG_MITM_AUTH, &smp->smp_flags); 429 set_bit(SMP_FLAG_MITM_AUTH, &smp->flags);
404 430
405 /* If both devices have Keyoard-Display I/O, the master 431 /* If both devices have Keyoard-Display I/O, the master
406 * Confirms and the slave Enters the passkey. 432 * Confirms and the slave Enters the passkey.
@@ -419,7 +445,7 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
419 passkey %= 1000000; 445 passkey %= 1000000;
420 put_unaligned_le32(passkey, smp->tk); 446 put_unaligned_le32(passkey, smp->tk);
421 BT_DBG("PassKey: %d", passkey); 447 BT_DBG("PassKey: %d", passkey);
422 set_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); 448 set_bit(SMP_FLAG_TK_VALID, &smp->flags);
423 } 449 }
424 450
425 hci_dev_lock(hcon->hdev); 451 hci_dev_lock(hcon->hdev);
@@ -441,15 +467,13 @@ static int tk_request(struct l2cap_conn *conn, u8 remote_oob, u8 auth,
441 return ret; 467 return ret;
442} 468}
443 469
444static void confirm_work(struct work_struct *work) 470static u8 smp_confirm(struct smp_chan *smp)
445{ 471{
446 struct smp_chan *smp = container_of(work, struct smp_chan, confirm);
447 struct l2cap_conn *conn = smp->conn; 472 struct l2cap_conn *conn = smp->conn;
448 struct hci_dev *hdev = conn->hcon->hdev; 473 struct hci_dev *hdev = conn->hcon->hdev;
449 struct crypto_blkcipher *tfm = hdev->tfm_aes; 474 struct crypto_blkcipher *tfm = hdev->tfm_aes;
450 struct smp_cmd_pairing_confirm cp; 475 struct smp_cmd_pairing_confirm cp;
451 int ret; 476 int ret;
452 u8 reason;
453 477
454 BT_DBG("conn %p", conn); 478 BT_DBG("conn %p", conn);
455 479
@@ -463,35 +487,27 @@ static void confirm_work(struct work_struct *work)
463 487
464 hci_dev_unlock(hdev); 488 hci_dev_unlock(hdev);
465 489
466 if (ret) { 490 if (ret)
467 reason = SMP_UNSPECIFIED; 491 return SMP_UNSPECIFIED;
468 goto error;
469 }
470 492
471 clear_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); 493 clear_bit(SMP_FLAG_CFM_PENDING, &smp->flags);
472 494
473 smp_send_cmd(smp->conn, SMP_CMD_PAIRING_CONFIRM, sizeof(cp), &cp); 495 smp_send_cmd(smp->conn, SMP_CMD_PAIRING_CONFIRM, sizeof(cp), &cp);
474 496
475 return; 497 return 0;
476
477error:
478 smp_failure(conn, reason);
479} 498}
480 499
481static void random_work(struct work_struct *work) 500static u8 smp_random(struct smp_chan *smp)
482{ 501{
483 struct smp_chan *smp = container_of(work, struct smp_chan, random);
484 struct l2cap_conn *conn = smp->conn; 502 struct l2cap_conn *conn = smp->conn;
485 struct hci_conn *hcon = conn->hcon; 503 struct hci_conn *hcon = conn->hcon;
486 struct hci_dev *hdev = hcon->hdev; 504 struct hci_dev *hdev = hcon->hdev;
487 struct crypto_blkcipher *tfm = hdev->tfm_aes; 505 struct crypto_blkcipher *tfm = hdev->tfm_aes;
488 u8 reason, confirm[16]; 506 u8 confirm[16];
489 int ret; 507 int ret;
490 508
491 if (IS_ERR_OR_NULL(tfm)) { 509 if (IS_ERR_OR_NULL(tfm))
492 reason = SMP_UNSPECIFIED; 510 return SMP_UNSPECIFIED;
493 goto error;
494 }
495 511
496 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); 512 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
497 513
@@ -504,15 +520,12 @@ static void random_work(struct work_struct *work)
504 520
505 hci_dev_unlock(hdev); 521 hci_dev_unlock(hdev);
506 522
507 if (ret) { 523 if (ret)
508 reason = SMP_UNSPECIFIED; 524 return SMP_UNSPECIFIED;
509 goto error;
510 }
511 525
512 if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) { 526 if (memcmp(smp->pcnf, confirm, sizeof(smp->pcnf)) != 0) {
513 BT_ERR("Pairing failed (confirmation values mismatch)"); 527 BT_ERR("Pairing failed (confirmation values mismatch)");
514 reason = SMP_CONFIRM_FAILED; 528 return SMP_CONFIRM_FAILED;
515 goto error;
516 } 529 }
517 530
518 if (hcon->out) { 531 if (hcon->out) {
@@ -525,10 +538,8 @@ static void random_work(struct work_struct *work)
525 memset(stk + smp->enc_key_size, 0, 538 memset(stk + smp->enc_key_size, 0,
526 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size); 539 SMP_MAX_ENC_KEY_SIZE - smp->enc_key_size);
527 540
528 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags)) { 541 if (test_and_set_bit(HCI_CONN_ENCRYPT_PEND, &hcon->flags))
529 reason = SMP_UNSPECIFIED; 542 return SMP_UNSPECIFIED;
530 goto error;
531 }
532 543
533 hci_le_start_enc(hcon, ediv, rand, stk); 544 hci_le_start_enc(hcon, ediv, rand, stk);
534 hcon->enc_key_size = smp->enc_key_size; 545 hcon->enc_key_size = smp->enc_key_size;
@@ -550,10 +561,7 @@ static void random_work(struct work_struct *work)
550 ediv, rand); 561 ediv, rand);
551 } 562 }
552 563
553 return; 564 return 0;
554
555error:
556 smp_failure(conn, reason);
557} 565}
558 566
559static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) 567static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
@@ -564,9 +572,6 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
564 if (!smp) 572 if (!smp)
565 return NULL; 573 return NULL;
566 574
567 INIT_WORK(&smp->confirm, confirm_work);
568 INIT_WORK(&smp->random, random_work);
569
570 smp->conn = conn; 575 smp->conn = conn;
571 conn->smp_chan = smp; 576 conn->smp_chan = smp;
572 conn->hcon->smp_conn = conn; 577 conn->hcon->smp_conn = conn;
@@ -583,7 +588,7 @@ void smp_chan_destroy(struct l2cap_conn *conn)
583 588
584 BUG_ON(!smp); 589 BUG_ON(!smp);
585 590
586 complete = test_bit(SMP_FLAG_COMPLETE, &smp->smp_flags); 591 complete = test_bit(SMP_FLAG_COMPLETE, &smp->flags);
587 mgmt_smp_complete(conn->hcon, complete); 592 mgmt_smp_complete(conn->hcon, complete);
588 593
589 kfree(smp->csrk); 594 kfree(smp->csrk);
@@ -634,7 +639,7 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey)
634 put_unaligned_le32(value, smp->tk); 639 put_unaligned_le32(value, smp->tk);
635 /* Fall Through */ 640 /* Fall Through */
636 case MGMT_OP_USER_CONFIRM_REPLY: 641 case MGMT_OP_USER_CONFIRM_REPLY:
637 set_bit(SMP_FLAG_TK_VALID, &smp->smp_flags); 642 set_bit(SMP_FLAG_TK_VALID, &smp->flags);
638 break; 643 break;
639 case MGMT_OP_USER_PASSKEY_NEG_REPLY: 644 case MGMT_OP_USER_PASSKEY_NEG_REPLY:
640 case MGMT_OP_USER_CONFIRM_NEG_REPLY: 645 case MGMT_OP_USER_CONFIRM_NEG_REPLY:
@@ -646,8 +651,11 @@ int smp_user_confirm_reply(struct hci_conn *hcon, u16 mgmt_op, __le32 passkey)
646 } 651 }
647 652
648 /* If it is our turn to send Pairing Confirm, do so now */ 653 /* If it is our turn to send Pairing Confirm, do so now */
649 if (test_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags)) 654 if (test_bit(SMP_FLAG_CFM_PENDING, &smp->flags)) {
650 queue_work(hcon->hdev->workqueue, &smp->confirm); 655 u8 rsp = smp_confirm(smp);
656 if (rsp)
657 smp_failure(conn, rsp);
658 }
651 659
652 return 0; 660 return 0;
653} 661}
@@ -656,14 +664,13 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
656{ 664{
657 struct smp_cmd_pairing rsp, *req = (void *) skb->data; 665 struct smp_cmd_pairing rsp, *req = (void *) skb->data;
658 struct smp_chan *smp; 666 struct smp_chan *smp;
659 u8 key_size; 667 u8 key_size, auth;
660 u8 auth = SMP_AUTH_NONE;
661 int ret; 668 int ret;
662 669
663 BT_DBG("conn %p", conn); 670 BT_DBG("conn %p", conn);
664 671
665 if (skb->len < sizeof(*req)) 672 if (skb->len < sizeof(*req))
666 return SMP_UNSPECIFIED; 673 return SMP_INVALID_PARAMS;
667 674
668 if (conn->hcon->link_mode & HCI_LM_MASTER) 675 if (conn->hcon->link_mode & HCI_LM_MASTER)
669 return SMP_CMD_NOTSUPP; 676 return SMP_CMD_NOTSUPP;
@@ -681,8 +688,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
681 skb_pull(skb, sizeof(*req)); 688 skb_pull(skb, sizeof(*req));
682 689
683 /* We didn't start the pairing, so match remote */ 690 /* We didn't start the pairing, so match remote */
684 if (req->auth_req & SMP_AUTH_BONDING) 691 auth = req->auth_req;
685 auth = req->auth_req;
686 692
687 conn->hcon->pending_sec_level = authreq_to_seclevel(auth); 693 conn->hcon->pending_sec_level = authreq_to_seclevel(auth);
688 694
@@ -704,7 +710,7 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)
704 if (ret) 710 if (ret)
705 return SMP_UNSPECIFIED; 711 return SMP_UNSPECIFIED;
706 712
707 clear_bit(SMP_FLAG_INITIATOR, &smp->smp_flags); 713 clear_bit(SMP_FLAG_INITIATOR, &smp->flags);
708 714
709 return 0; 715 return 0;
710} 716}
@@ -713,14 +719,13 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
713{ 719{
714 struct smp_cmd_pairing *req, *rsp = (void *) skb->data; 720 struct smp_cmd_pairing *req, *rsp = (void *) skb->data;
715 struct smp_chan *smp = conn->smp_chan; 721 struct smp_chan *smp = conn->smp_chan;
716 struct hci_dev *hdev = conn->hcon->hdev;
717 u8 key_size, auth = SMP_AUTH_NONE; 722 u8 key_size, auth = SMP_AUTH_NONE;
718 int ret; 723 int ret;
719 724
720 BT_DBG("conn %p", conn); 725 BT_DBG("conn %p", conn);
721 726
722 if (skb->len < sizeof(*rsp)) 727 if (skb->len < sizeof(*rsp))
723 return SMP_UNSPECIFIED; 728 return SMP_INVALID_PARAMS;
724 729
725 if (!(conn->hcon->link_mode & HCI_LM_MASTER)) 730 if (!(conn->hcon->link_mode & HCI_LM_MASTER))
726 return SMP_CMD_NOTSUPP; 731 return SMP_CMD_NOTSUPP;
@@ -753,11 +758,11 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
753 if (ret) 758 if (ret)
754 return SMP_UNSPECIFIED; 759 return SMP_UNSPECIFIED;
755 760
756 set_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); 761 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags);
757 762
758 /* Can't compose response until we have been confirmed */ 763 /* Can't compose response until we have been confirmed */
759 if (test_bit(SMP_FLAG_TK_VALID, &smp->smp_flags)) 764 if (test_bit(SMP_FLAG_TK_VALID, &smp->flags))
760 queue_work(hdev->workqueue, &smp->confirm); 765 return smp_confirm(smp);
761 766
762 return 0; 767 return 0;
763} 768}
@@ -765,12 +770,11 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)
765static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb) 770static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
766{ 771{
767 struct smp_chan *smp = conn->smp_chan; 772 struct smp_chan *smp = conn->smp_chan;
768 struct hci_dev *hdev = conn->hcon->hdev;
769 773
770 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave"); 774 BT_DBG("conn %p %s", conn, conn->hcon->out ? "master" : "slave");
771 775
772 if (skb->len < sizeof(smp->pcnf)) 776 if (skb->len < sizeof(smp->pcnf))
773 return SMP_UNSPECIFIED; 777 return SMP_INVALID_PARAMS;
774 778
775 memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf)); 779 memcpy(smp->pcnf, skb->data, sizeof(smp->pcnf));
776 skb_pull(skb, sizeof(smp->pcnf)); 780 skb_pull(skb, sizeof(smp->pcnf));
@@ -778,10 +782,10 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
778 if (conn->hcon->out) 782 if (conn->hcon->out)
779 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd), 783 smp_send_cmd(conn, SMP_CMD_PAIRING_RANDOM, sizeof(smp->prnd),
780 smp->prnd); 784 smp->prnd);
781 else if (test_bit(SMP_FLAG_TK_VALID, &smp->smp_flags)) 785 else if (test_bit(SMP_FLAG_TK_VALID, &smp->flags))
782 queue_work(hdev->workqueue, &smp->confirm); 786 return smp_confirm(smp);
783 else 787 else
784 set_bit(SMP_FLAG_CFM_PENDING, &smp->smp_flags); 788 set_bit(SMP_FLAG_CFM_PENDING, &smp->flags);
785 789
786 return 0; 790 return 0;
787} 791}
@@ -789,19 +793,16 @@ static u8 smp_cmd_pairing_confirm(struct l2cap_conn *conn, struct sk_buff *skb)
789static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb) 793static u8 smp_cmd_pairing_random(struct l2cap_conn *conn, struct sk_buff *skb)
790{ 794{
791 struct smp_chan *smp = conn->smp_chan; 795 struct smp_chan *smp = conn->smp_chan;
792 struct hci_dev *hdev = conn->hcon->hdev;
793 796
794 BT_DBG("conn %p", conn); 797 BT_DBG("conn %p", conn);
795 798
796 if (skb->len < sizeof(smp->rrnd)) 799 if (skb->len < sizeof(smp->rrnd))
797 return SMP_UNSPECIFIED; 800 return SMP_INVALID_PARAMS;
798 801
799 memcpy(smp->rrnd, skb->data, sizeof(smp->rrnd)); 802 memcpy(smp->rrnd, skb->data, sizeof(smp->rrnd));
800 skb_pull(skb, sizeof(smp->rrnd)); 803 skb_pull(skb, sizeof(smp->rrnd));
801 804
802 queue_work(hdev->workqueue, &smp->random); 805 return smp_random(smp);
803
804 return 0;
805} 806}
806 807
807static u8 smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level) 808static u8 smp_ltk_encrypt(struct l2cap_conn *conn, u8 sec_level)
@@ -836,7 +837,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
836 BT_DBG("conn %p", conn); 837 BT_DBG("conn %p", conn);
837 838
838 if (skb->len < sizeof(*rp)) 839 if (skb->len < sizeof(*rp))
839 return SMP_UNSPECIFIED; 840 return SMP_INVALID_PARAMS;
840 841
841 if (!(conn->hcon->link_mode & HCI_LM_MASTER)) 842 if (!(conn->hcon->link_mode & HCI_LM_MASTER))
842 return SMP_CMD_NOTSUPP; 843 return SMP_CMD_NOTSUPP;
@@ -861,7 +862,7 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)
861 862
862 smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp); 863 smp_send_cmd(conn, SMP_CMD_PAIRING_REQ, sizeof(cp), &cp);
863 864
864 clear_bit(SMP_FLAG_INITIATOR, &smp->smp_flags); 865 clear_bit(SMP_FLAG_INITIATOR, &smp->flags);
865 866
866 return 0; 867 return 0;
867} 868}
@@ -928,7 +929,7 @@ int smp_conn_security(struct hci_conn *hcon, __u8 sec_level)
928 smp_send_cmd(conn, SMP_CMD_SECURITY_REQ, sizeof(cp), &cp); 929 smp_send_cmd(conn, SMP_CMD_SECURITY_REQ, sizeof(cp), &cp);
929 } 930 }
930 931
931 set_bit(SMP_FLAG_INITIATOR, &smp->smp_flags); 932 set_bit(SMP_FLAG_INITIATOR, &smp->flags);
932 933
933done: 934done:
934 hcon->pending_sec_level = sec_level; 935 hcon->pending_sec_level = sec_level;
@@ -944,7 +945,7 @@ static int smp_cmd_encrypt_info(struct l2cap_conn *conn, struct sk_buff *skb)
944 BT_DBG("conn %p", conn); 945 BT_DBG("conn %p", conn);
945 946
946 if (skb->len < sizeof(*rp)) 947 if (skb->len < sizeof(*rp))
947 return SMP_UNSPECIFIED; 948 return SMP_INVALID_PARAMS;
948 949
949 /* Ignore this PDU if it wasn't requested */ 950 /* Ignore this PDU if it wasn't requested */
950 if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY)) 951 if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY))
@@ -969,7 +970,7 @@ static int smp_cmd_master_ident(struct l2cap_conn *conn, struct sk_buff *skb)
969 BT_DBG("conn %p", conn); 970 BT_DBG("conn %p", conn);
970 971
971 if (skb->len < sizeof(*rp)) 972 if (skb->len < sizeof(*rp))
972 return SMP_UNSPECIFIED; 973 return SMP_INVALID_PARAMS;
973 974
974 /* Ignore this PDU if it wasn't requested */ 975 /* Ignore this PDU if it wasn't requested */
975 if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY)) 976 if (!(smp->remote_key_dist & SMP_DIST_ENC_KEY))
@@ -1001,7 +1002,7 @@ static int smp_cmd_ident_info(struct l2cap_conn *conn, struct sk_buff *skb)
1001 BT_DBG(""); 1002 BT_DBG("");
1002 1003
1003 if (skb->len < sizeof(*info)) 1004 if (skb->len < sizeof(*info))
1004 return SMP_UNSPECIFIED; 1005 return SMP_INVALID_PARAMS;
1005 1006
1006 /* Ignore this PDU if it wasn't requested */ 1007 /* Ignore this PDU if it wasn't requested */
1007 if (!(smp->remote_key_dist & SMP_DIST_ID_KEY)) 1008 if (!(smp->remote_key_dist & SMP_DIST_ID_KEY))
@@ -1025,7 +1026,7 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn,
1025 BT_DBG(""); 1026 BT_DBG("");
1026 1027
1027 if (skb->len < sizeof(*info)) 1028 if (skb->len < sizeof(*info))
1028 return SMP_UNSPECIFIED; 1029 return SMP_INVALID_PARAMS;
1029 1030
1030 /* Ignore this PDU if it wasn't requested */ 1031 /* Ignore this PDU if it wasn't requested */
1031 if (!(smp->remote_key_dist & SMP_DIST_ID_KEY)) 1032 if (!(smp->remote_key_dist & SMP_DIST_ID_KEY))
@@ -1075,7 +1076,7 @@ static int smp_cmd_sign_info(struct l2cap_conn *conn, struct sk_buff *skb)
1075 BT_DBG("conn %p", conn); 1076 BT_DBG("conn %p", conn);
1076 1077
1077 if (skb->len < sizeof(*rp)) 1078 if (skb->len < sizeof(*rp))
1078 return SMP_UNSPECIFIED; 1079 return SMP_INVALID_PARAMS;
1079 1080
1080 /* Ignore this PDU if it wasn't requested */ 1081 /* Ignore this PDU if it wasn't requested */
1081 if (!(smp->remote_key_dist & SMP_DIST_SIGN)) 1082 if (!(smp->remote_key_dist & SMP_DIST_SIGN))
@@ -1358,7 +1359,7 @@ int smp_distribute_keys(struct l2cap_conn *conn)
1358 1359
1359 clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags); 1360 clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->flags);
1360 cancel_delayed_work_sync(&conn->security_timer); 1361 cancel_delayed_work_sync(&conn->security_timer);
1361 set_bit(SMP_FLAG_COMPLETE, &smp->smp_flags); 1362 set_bit(SMP_FLAG_COMPLETE, &smp->flags);
1362 smp_notify_keys(conn); 1363 smp_notify_keys(conn);
1363 1364
1364 smp_chan_destroy(conn); 1365 smp_chan_destroy(conn);
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index 1277147a9150..5a8dc36460a1 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -111,39 +111,11 @@ struct smp_cmd_security_req {
111#define SMP_CMD_NOTSUPP 0x07 111#define SMP_CMD_NOTSUPP 0x07
112#define SMP_UNSPECIFIED 0x08 112#define SMP_UNSPECIFIED 0x08
113#define SMP_REPEATED_ATTEMPTS 0x09 113#define SMP_REPEATED_ATTEMPTS 0x09
114#define SMP_INVALID_PARAMS 0x0a
114 115
115#define SMP_MIN_ENC_KEY_SIZE 7 116#define SMP_MIN_ENC_KEY_SIZE 7
116#define SMP_MAX_ENC_KEY_SIZE 16 117#define SMP_MAX_ENC_KEY_SIZE 16
117 118
118#define SMP_FLAG_TK_VALID 1
119#define SMP_FLAG_CFM_PENDING 2
120#define SMP_FLAG_MITM_AUTH 3
121#define SMP_FLAG_COMPLETE 4
122#define SMP_FLAG_INITIATOR 5
123
124struct smp_chan {
125 struct l2cap_conn *conn;
126 u8 preq[7]; /* SMP Pairing Request */
127 u8 prsp[7]; /* SMP Pairing Response */
128 u8 prnd[16]; /* SMP Pairing Random (local) */
129 u8 rrnd[16]; /* SMP Pairing Random (remote) */
130 u8 pcnf[16]; /* SMP Pairing Confirm */
131 u8 tk[16]; /* SMP Temporary Key */
132 u8 enc_key_size;
133 u8 remote_key_dist;
134 bdaddr_t id_addr;
135 u8 id_addr_type;
136 u8 irk[16];
137 struct smp_csrk *csrk;
138 struct smp_csrk *slave_csrk;
139 struct smp_ltk *ltk;
140 struct smp_ltk *slave_ltk;
141 struct smp_irk *remote_irk;
142 unsigned long smp_flags;
143 struct work_struct confirm;
144 struct work_struct random;
145};
146
147/* SMP Commands */ 119/* SMP Commands */
148bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level); 120bool smp_sufficient_security(struct hci_conn *hcon, u8 sec_level);
149int smp_conn_security(struct hci_conn *hcon, __u8 sec_level); 121int smp_conn_security(struct hci_conn *hcon, __u8 sec_level);
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 40a648938985..e205ebabfa50 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -34,8 +34,7 @@ static ssize_t ieee80211_if_read(
34 ssize_t ret = -EINVAL; 34 ssize_t ret = -EINVAL;
35 35
36 read_lock(&dev_base_lock); 36 read_lock(&dev_base_lock);
37 if (sdata->dev->reg_state == NETREG_REGISTERED) 37 ret = (*format)(sdata, buf, sizeof(buf));
38 ret = (*format)(sdata, buf, sizeof(buf));
39 read_unlock(&dev_base_lock); 38 read_unlock(&dev_base_lock);
40 39
41 if (ret >= 0) 40 if (ret >= 0)
@@ -62,8 +61,7 @@ static ssize_t ieee80211_if_write(
62 61
63 ret = -ENODEV; 62 ret = -ENODEV;
64 rtnl_lock(); 63 rtnl_lock();
65 if (sdata->dev->reg_state == NETREG_REGISTERED) 64 ret = (*write)(sdata, buf, count);
66 ret = (*write)(sdata, buf, count);
67 rtnl_unlock(); 65 rtnl_unlock();
68 66
69 return ret; 67 return ret;
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 696ef78b1fb7..bd782dcffcc7 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -1048,6 +1048,59 @@ static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
1048 trace_drv_return_void(local); 1048 trace_drv_return_void(local);
1049} 1049}
1050 1050
1051static inline int
1052drv_switch_vif_chanctx(struct ieee80211_local *local,
1053 struct ieee80211_vif_chanctx_switch *vifs,
1054 int n_vifs,
1055 enum ieee80211_chanctx_switch_mode mode)
1056{
1057 int ret = 0;
1058 int i;
1059
1060 if (!local->ops->switch_vif_chanctx)
1061 return -EOPNOTSUPP;
1062
1063 for (i = 0; i < n_vifs; i++) {
1064 struct ieee80211_chanctx *new_ctx =
1065 container_of(vifs[i].new_ctx,
1066 struct ieee80211_chanctx,
1067 conf);
1068 struct ieee80211_chanctx *old_ctx =
1069 container_of(vifs[i].old_ctx,
1070 struct ieee80211_chanctx,
1071 conf);
1072
1073 WARN_ON_ONCE(!old_ctx->driver_present);
1074 WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
1075 new_ctx->driver_present) ||
1076 (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
1077 !new_ctx->driver_present));
1078 }
1079
1080 trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
1081 ret = local->ops->switch_vif_chanctx(&local->hw,
1082 vifs, n_vifs, mode);
1083 trace_drv_return_int(local, ret);
1084
1085 if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
1086 for (i = 0; i < n_vifs; i++) {
1087 struct ieee80211_chanctx *new_ctx =
1088 container_of(vifs[i].new_ctx,
1089 struct ieee80211_chanctx,
1090 conf);
1091 struct ieee80211_chanctx *old_ctx =
1092 container_of(vifs[i].old_ctx,
1093 struct ieee80211_chanctx,
1094 conf);
1095
1096 new_ctx->driver_present = true;
1097 old_ctx->driver_present = false;
1098 }
1099 }
1100
1101 return ret;
1102}
1103
1051static inline int drv_start_ap(struct ieee80211_local *local, 1104static inline int drv_start_ap(struct ieee80211_local *local,
1052 struct ieee80211_sub_if_data *sdata) 1105 struct ieee80211_sub_if_data *sdata)
1053{ 1106{
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 1bbac94da58d..18ee0a256b1e 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -1677,6 +1677,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
1677 sdata->u.ibss.control_port = params->control_port; 1677 sdata->u.ibss.control_port = params->control_port;
1678 sdata->u.ibss.userspace_handles_dfs = params->userspace_handles_dfs; 1678 sdata->u.ibss.userspace_handles_dfs = params->userspace_handles_dfs;
1679 sdata->u.ibss.basic_rates = params->basic_rates; 1679 sdata->u.ibss.basic_rates = params->basic_rates;
1680 sdata->u.ibss.last_scan_completed = jiffies;
1680 1681
1681 /* fix basic_rates if channel does not support these rates */ 1682 /* fix basic_rates if channel does not support these rates */
1682 rate_flags = ieee80211_chandef_rate_flags(&params->chandef); 1683 rate_flags = ieee80211_chandef_rate_flags(&params->chandef);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 79fc98815da8..81a8e2a0b6aa 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -399,6 +399,7 @@ int ieee80211_add_virtual_monitor(struct ieee80211_local *local)
399 sdata->vif.type = NL80211_IFTYPE_MONITOR; 399 sdata->vif.type = NL80211_IFTYPE_MONITOR;
400 snprintf(sdata->name, IFNAMSIZ, "%s-monitor", 400 snprintf(sdata->name, IFNAMSIZ, "%s-monitor",
401 wiphy_name(local->hw.wiphy)); 401 wiphy_name(local->hw.wiphy));
402 sdata->wdev.iftype = NL80211_IFTYPE_MONITOR;
402 403
403 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; 404 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
404 405
@@ -1285,6 +1286,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
1285 sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE); 1286 sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE);
1286 sdata->control_port_no_encrypt = false; 1287 sdata->control_port_no_encrypt = false;
1287 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; 1288 sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
1289 sdata->vif.bss_conf.idle = true;
1288 1290
1289 sdata->noack_map = 0; 1291 sdata->noack_map = 0;
1290 1292
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 632d372bb511..a9b46d8ea22f 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -240,6 +240,7 @@ void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
240 240
241 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr); 241 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
242 242
243 kfree(rcu_dereference_raw(sta->sta.rates));
243 kfree(sta); 244 kfree(sta);
244} 245}
245 246
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 60cb7a665976..ba29ebc86141 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -541,6 +541,23 @@ static void ieee80211_tx_latency_end_msrmnt(struct ieee80211_local *local,
541 */ 541 */
542#define STA_LOST_PKT_THRESHOLD 50 542#define STA_LOST_PKT_THRESHOLD 50
543 543
544static void ieee80211_lost_packet(struct sta_info *sta, struct sk_buff *skb)
545{
546 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
547
548 /* This packet was aggregated but doesn't carry status info */
549 if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
550 !(info->flags & IEEE80211_TX_STAT_AMPDU))
551 return;
552
553 if (++sta->lost_packets < STA_LOST_PKT_THRESHOLD)
554 return;
555
556 cfg80211_cqm_pktloss_notify(sta->sdata->dev, sta->sta.addr,
557 sta->lost_packets, GFP_ATOMIC);
558 sta->lost_packets = 0;
559}
560
544void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb) 561void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
545{ 562{
546 struct sk_buff *skb2; 563 struct sk_buff *skb2;
@@ -680,12 +697,8 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
680 if (info->flags & IEEE80211_TX_STAT_ACK) { 697 if (info->flags & IEEE80211_TX_STAT_ACK) {
681 if (sta->lost_packets) 698 if (sta->lost_packets)
682 sta->lost_packets = 0; 699 sta->lost_packets = 0;
683 } else if (++sta->lost_packets >= STA_LOST_PKT_THRESHOLD) { 700 } else {
684 cfg80211_cqm_pktloss_notify(sta->sdata->dev, 701 ieee80211_lost_packet(sta, skb);
685 sta->sta.addr,
686 sta->lost_packets,
687 GFP_ATOMIC);
688 sta->lost_packets = 0;
689 } 702 }
690 } 703 }
691 704
diff --git a/net/mac80211/trace.h b/net/mac80211/trace.h
index 762e4cd16386..cfe1a0688b5c 100644
--- a/net/mac80211/trace.h
+++ b/net/mac80211/trace.h
@@ -1389,6 +1389,91 @@ TRACE_EVENT(drv_change_chanctx,
1389 ) 1389 )
1390); 1390);
1391 1391
1392#if !defined(__TRACE_VIF_ENTRY)
1393#define __TRACE_VIF_ENTRY
1394struct trace_vif_entry {
1395 enum nl80211_iftype vif_type;
1396 bool p2p;
1397 char vif_name[IFNAMSIZ];
1398} __packed;
1399
1400struct trace_chandef_entry {
1401 u32 control_freq;
1402 u32 chan_width;
1403 u32 center_freq1;
1404 u32 center_freq2;
1405} __packed;
1406
1407struct trace_switch_entry {
1408 struct trace_vif_entry vif;
1409 struct trace_chandef_entry old_chandef;
1410 struct trace_chandef_entry new_chandef;
1411} __packed;
1412
1413#define SWITCH_ENTRY_ASSIGN(to, from) local_vifs[i].to = vifs[i].from
1414#endif
1415
1416TRACE_EVENT(drv_switch_vif_chanctx,
1417 TP_PROTO(struct ieee80211_local *local,
1418 struct ieee80211_vif_chanctx_switch *vifs,
1419 int n_vifs, enum ieee80211_chanctx_switch_mode mode),
1420 TP_ARGS(local, vifs, n_vifs, mode),
1421
1422 TP_STRUCT__entry(
1423 LOCAL_ENTRY
1424 __field(int, n_vifs)
1425 __field(u32, mode)
1426 __dynamic_array(u8, vifs,
1427 sizeof(struct trace_switch_entry) * n_vifs)
1428 ),
1429
1430 TP_fast_assign(
1431 LOCAL_ASSIGN;
1432 __entry->n_vifs = n_vifs;
1433 __entry->mode = mode;
1434 {
1435 struct trace_switch_entry *local_vifs =
1436 __get_dynamic_array(vifs);
1437 int i;
1438
1439 for (i = 0; i < n_vifs; i++) {
1440 struct ieee80211_sub_if_data *sdata;
1441
1442 sdata = container_of(vifs[i].vif,
1443 struct ieee80211_sub_if_data,
1444 vif);
1445
1446 SWITCH_ENTRY_ASSIGN(vif.vif_type, vif->type);
1447 SWITCH_ENTRY_ASSIGN(vif.p2p, vif->p2p);
1448 strncpy(local_vifs[i].vif.vif_name,
1449 sdata->name,
1450 sizeof(local_vifs[i].vif.vif_name));
1451 SWITCH_ENTRY_ASSIGN(old_chandef.control_freq,
1452 old_ctx->def.chan->center_freq);
1453 SWITCH_ENTRY_ASSIGN(old_chandef.chan_width,
1454 old_ctx->def.width);
1455 SWITCH_ENTRY_ASSIGN(old_chandef.center_freq1,
1456 old_ctx->def.center_freq1);
1457 SWITCH_ENTRY_ASSIGN(old_chandef.center_freq2,
1458 old_ctx->def.center_freq2);
1459 SWITCH_ENTRY_ASSIGN(new_chandef.control_freq,
1460 new_ctx->def.chan->center_freq);
1461 SWITCH_ENTRY_ASSIGN(new_chandef.chan_width,
1462 new_ctx->def.width);
1463 SWITCH_ENTRY_ASSIGN(new_chandef.center_freq1,
1464 new_ctx->def.center_freq1);
1465 SWITCH_ENTRY_ASSIGN(new_chandef.center_freq2,
1466 new_ctx->def.center_freq2);
1467 }
1468 }
1469 ),
1470
1471 TP_printk(
1472 LOCAL_PR_FMT " n_vifs:%d mode:%d",
1473 LOCAL_PR_ARG, __entry->n_vifs, __entry->mode
1474 )
1475);
1476
1392DECLARE_EVENT_CLASS(local_sdata_chanctx, 1477DECLARE_EVENT_CLASS(local_sdata_chanctx,
1393 TP_PROTO(struct ieee80211_local *local, 1478 TP_PROTO(struct ieee80211_local *local,
1394 struct ieee80211_sub_if_data *sdata, 1479 struct ieee80211_sub_if_data *sdata,
diff --git a/net/nfc/digital_core.c b/net/nfc/digital_core.c
index b105cfb00e76..a6ce3c627e4e 100644
--- a/net/nfc/digital_core.c
+++ b/net/nfc/digital_core.c
@@ -386,6 +386,8 @@ int digital_target_found(struct nfc_digital_dev *ddev,
386 386
387void digital_poll_next_tech(struct nfc_digital_dev *ddev) 387void digital_poll_next_tech(struct nfc_digital_dev *ddev)
388{ 388{
389 u8 rand_mod;
390
389 digital_switch_rf(ddev, 0); 391 digital_switch_rf(ddev, 0);
390 392
391 mutex_lock(&ddev->poll_lock); 393 mutex_lock(&ddev->poll_lock);
@@ -395,8 +397,8 @@ void digital_poll_next_tech(struct nfc_digital_dev *ddev)
395 return; 397 return;
396 } 398 }
397 399
398 ddev->poll_tech_index = (ddev->poll_tech_index + 1) % 400 get_random_bytes(&rand_mod, sizeof(rand_mod));
399 ddev->poll_tech_count; 401 ddev->poll_tech_index = rand_mod % ddev->poll_tech_count;
400 402
401 mutex_unlock(&ddev->poll_lock); 403 mutex_unlock(&ddev->poll_lock);
402 404
diff --git a/net/nfc/digital_dep.c b/net/nfc/digital_dep.c
index d4ed25ff723f..171cb9949ab5 100644
--- a/net/nfc/digital_dep.c
+++ b/net/nfc/digital_dep.c
@@ -224,9 +224,8 @@ int digital_in_send_atr_req(struct nfc_digital_dev *ddev,
224 224
225 ddev->skb_add_crc(skb); 225 ddev->skb_add_crc(skb);
226 226
227 digital_in_send_cmd(ddev, skb, 500, digital_in_recv_atr_res, target); 227 return digital_in_send_cmd(ddev, skb, 500, digital_in_recv_atr_res,
228 228 target);
229 return 0;
230} 229}
231 230
232static int digital_in_send_rtox(struct nfc_digital_dev *ddev, 231static int digital_in_send_rtox(struct nfc_digital_dev *ddev,
diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
index 12a233e9ece5..c2c1c0189b7c 100644
--- a/net/nfc/digital_technology.c
+++ b/net/nfc/digital_technology.c
@@ -613,7 +613,7 @@ exit:
613 digital_poll_next_tech(ddev); 613 digital_poll_next_tech(ddev);
614} 614}
615 615
616int digital_in_send_attrib_req(struct nfc_digital_dev *ddev, 616static int digital_in_send_attrib_req(struct nfc_digital_dev *ddev,
617 struct nfc_target *target, 617 struct nfc_target *target,
618 struct digital_sensb_res *sensb_res) 618 struct digital_sensb_res *sensb_res)
619{ 619{
diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
index 8627c75063e2..55eefee311eb 100644
--- a/net/nfc/rawsock.c
+++ b/net/nfc/rawsock.c
@@ -31,14 +31,14 @@ static struct nfc_sock_list raw_sk_list = {
31 .lock = __RW_LOCK_UNLOCKED(raw_sk_list.lock) 31 .lock = __RW_LOCK_UNLOCKED(raw_sk_list.lock)
32}; 32};
33 33
34void nfc_sock_link(struct nfc_sock_list *l, struct sock *sk) 34static void nfc_sock_link(struct nfc_sock_list *l, struct sock *sk)
35{ 35{
36 write_lock(&l->lock); 36 write_lock(&l->lock);
37 sk_add_node(sk, &l->head); 37 sk_add_node(sk, &l->head);
38 write_unlock(&l->lock); 38 write_unlock(&l->lock);
39} 39}
40 40
41void nfc_sock_unlink(struct nfc_sock_list *l, struct sock *sk) 41static void nfc_sock_unlink(struct nfc_sock_list *l, struct sock *sk)
42{ 42{
43 write_lock(&l->lock); 43 write_lock(&l->lock);
44 sk_del_node_init(sk); 44 sk_del_node_init(sk);
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d03d8bdb29ca..a1c40654dd9b 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -130,7 +130,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
130 newname)) 130 newname))
131 pr_err("failed to rename debugfs dir to %s!\n", newname); 131 pr_err("failed to rename debugfs dir to %s!\n", newname);
132 132
133 nl80211_notify_dev_rename(rdev); 133 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
134 134
135 return 0; 135 return 0;
136} 136}
@@ -660,6 +660,8 @@ int wiphy_register(struct wiphy *wiphy)
660 return res; 660 return res;
661 } 661 }
662 662
663 nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
664
663 return 0; 665 return 0;
664} 666}
665EXPORT_SYMBOL(wiphy_register); 667EXPORT_SYMBOL(wiphy_register);
@@ -698,6 +700,7 @@ void wiphy_unregister(struct wiphy *wiphy)
698 rfkill_unregister(rdev->rfkill); 700 rfkill_unregister(rdev->rfkill);
699 701
700 rtnl_lock(); 702 rtnl_lock();
703 nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
701 rdev->wiphy.registered = false; 704 rdev->wiphy.registered = false;
702 705
703 WARN_ON(!list_empty(&rdev->wdev_list)); 706 WARN_ON(!list_empty(&rdev->wdev_list));
diff --git a/net/wireless/genregdb.awk b/net/wireless/genregdb.awk
index b35da8dc85de..40c37fc5b67c 100644
--- a/net/wireless/genregdb.awk
+++ b/net/wireless/genregdb.awk
@@ -68,17 +68,7 @@ function parse_reg_rule()
68 sub(/,/, "", units) 68 sub(/,/, "", units)
69 dfs_cac = $9 69 dfs_cac = $9
70 if (units == "mW") { 70 if (units == "mW") {
71 if (power == 100) { 71 power = 10 * log(power)/log(10)
72 power = 20
73 } else if (power == 200) {
74 power = 23
75 } else if (power == 500) {
76 power = 27
77 } else if (power == 1000) {
78 power = 30
79 } else {
80 print "Unknown power value in database!"
81 }
82 } else { 72 } else {
83 dfs_cac = $8 73 dfs_cac = $8
84 } 74 }
@@ -117,7 +107,7 @@ function parse_reg_rule()
117 107
118 } 108 }
119 flags = flags "0" 109 flags = flags "0"
120 printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %d, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags 110 printf "\t\tREG_RULE_EXT(%d, %d, %d, %d, %.0f, %d, %s),\n", start, end, bw, gain, power, dfs_cac, flags
121 rules++ 111 rules++
122} 112}
123 113
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 62bdb1adaa4d..ba4f1723c83a 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1226,6 +1226,7 @@ struct nl80211_dump_wiphy_state {
1226}; 1226};
1227 1227
1228static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, 1228static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1229 enum nl80211_commands cmd,
1229 struct sk_buff *msg, u32 portid, u32 seq, 1230 struct sk_buff *msg, u32 portid, u32 seq,
1230 int flags, struct nl80211_dump_wiphy_state *state) 1231 int flags, struct nl80211_dump_wiphy_state *state)
1231{ 1232{
@@ -1240,7 +1241,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1240 rdev->wiphy.mgmt_stypes; 1241 rdev->wiphy.mgmt_stypes;
1241 u32 features; 1242 u32 features;
1242 1243
1243 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); 1244 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
1244 if (!hdr) 1245 if (!hdr)
1245 return -ENOBUFS; 1246 return -ENOBUFS;
1246 1247
@@ -1254,6 +1255,9 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1254 cfg80211_rdev_list_generation)) 1255 cfg80211_rdev_list_generation))
1255 goto nla_put_failure; 1256 goto nla_put_failure;
1256 1257
1258 if (cmd != NL80211_CMD_NEW_WIPHY)
1259 goto finish;
1260
1257 switch (state->split_start) { 1261 switch (state->split_start) {
1258 case 0: 1262 case 0:
1259 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, 1263 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
@@ -1682,6 +1686,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1682 state->split_start = 0; 1686 state->split_start = 0;
1683 break; 1687 break;
1684 } 1688 }
1689 finish:
1685 return genlmsg_end(msg, hdr); 1690 return genlmsg_end(msg, hdr);
1686 1691
1687 nla_put_failure: 1692 nla_put_failure:
@@ -1756,7 +1761,8 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1756 continue; 1761 continue;
1757 /* attempt to fit multiple wiphy data chunks into the skb */ 1762 /* attempt to fit multiple wiphy data chunks into the skb */
1758 do { 1763 do {
1759 ret = nl80211_send_wiphy(rdev, skb, 1764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1765 skb,
1760 NETLINK_CB(cb->skb).portid, 1766 NETLINK_CB(cb->skb).portid,
1761 cb->nlh->nlmsg_seq, 1767 cb->nlh->nlmsg_seq,
1762 NLM_F_MULTI, state); 1768 NLM_F_MULTI, state);
@@ -1811,7 +1817,8 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1811 if (!msg) 1817 if (!msg)
1812 return -ENOMEM; 1818 return -ENOMEM;
1813 1819
1814 if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0, 1820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1821 info->snd_portid, info->snd_seq, 0,
1815 &state) < 0) { 1822 &state) < 0) {
1816 nlmsg_free(msg); 1823 nlmsg_free(msg);
1817 return -ENOBUFS; 1824 return -ENOBUFS;
@@ -10101,16 +10108,20 @@ static const struct genl_ops nl80211_ops[] = {
10101 10108
10102/* notification functions */ 10109/* notification functions */
10103 10110
10104void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) 10111void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10112 enum nl80211_commands cmd)
10105{ 10113{
10106 struct sk_buff *msg; 10114 struct sk_buff *msg;
10107 struct nl80211_dump_wiphy_state state = {}; 10115 struct nl80211_dump_wiphy_state state = {};
10108 10116
10117 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10118 cmd != NL80211_CMD_DEL_WIPHY);
10119
10109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 10120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10110 if (!msg) 10121 if (!msg)
10111 return; 10122 return;
10112 10123
10113 if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { 10124 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
10114 nlmsg_free(msg); 10125 nlmsg_free(msg);
10115 return; 10126 return;
10116 } 10127 }
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index 1e6df9630f42..49c9a482dd12 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -5,7 +5,8 @@
5 5
6int nl80211_init(void); 6int nl80211_init(void);
7void nl80211_exit(void); 7void nl80211_exit(void);
8void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev); 8void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
9 enum nl80211_commands cmd);
9void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, 10void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
10 struct wireless_dev *wdev); 11 struct wireless_dev *wdev);
11struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, 12struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,