aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2011-12-12 14:19:43 -0500
committerJohn W. Linville <linville@tuxdriver.com>2011-12-12 14:19:43 -0500
commitf2abba4921b945a6f8aca36fcba634c22797ba78 (patch)
tree77b06167aba97c7400759547fffdb38805ff6bd6
parentdfd56b8b38fff3586f36232db58e1e9f7885a605 (diff)
parentb6a27d1e6b8e163dee054c9cd03639c62756c2e2 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next into for-davem
-rw-r--r--Documentation/feature-removal-schedule.txt3
-rw-r--r--drivers/bcma/host_pci.c32
-rw-r--r--drivers/bluetooth/Kconfig6
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c15
-rw-r--r--drivers/bluetooth/btusb.c3
-rw-r--r--drivers/bluetooth/hci_vhci.c8
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_calib.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h42
-rw-r--r--drivers/net/wireless/ath/ath9k/htc_drv_main.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c6
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c204
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c21
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c2
-rw-r--r--drivers/net/wireless/iwlegacy/common.c5
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c51
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rx.c16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rxon.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.h20
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c15
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h62
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h41
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-mac80211.c15
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-shared.h76
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-testmode.c (renamed from drivers/net/wireless/iwlwifi/iwl-sv-open.c)162
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-testmode.h34
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-ucode.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-ucode.c)163
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c4
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c2
-rw-r--r--drivers/net/wireless/wl12xx/Kconfig10
-rw-r--r--drivers/net/wireless/wl12xx/Makefile3
-rw-r--r--drivers/net/wireless/wl12xx/acx.c146
-rw-r--r--drivers/net/wireless/wl12xx/acx.h83
-rw-r--r--drivers/net/wireless/wl12xx/boot.c15
-rw-r--r--drivers/net/wireless/wl12xx/cmd.c368
-rw-r--r--drivers/net/wireless/wl12xx/cmd.h50
-rw-r--r--drivers/net/wireless/wl12xx/conf.h4
-rw-r--r--drivers/net/wireless/wl12xx/debug.h101
-rw-r--r--drivers/net/wireless/wl12xx/debugfs.c141
-rw-r--r--drivers/net/wireless/wl12xx/event.c214
-rw-r--r--drivers/net/wireless/wl12xx/event.h3
-rw-r--r--drivers/net/wireless/wl12xx/init.c458
-rw-r--r--drivers/net/wireless/wl12xx/init.h7
-rw-r--r--drivers/net/wireless/wl12xx/io.c12
-rw-r--r--drivers/net/wireless/wl12xx/io.h23
-rw-r--r--drivers/net/wireless/wl12xx/main.c1949
-rw-r--r--drivers/net/wireless/wl12xx/ps.c56
-rw-r--r--drivers/net/wireless/wl12xx/ps.h9
-rw-r--r--drivers/net/wireless/wl12xx/reg.h2
-rw-r--r--drivers/net/wireless/wl12xx/rx.c34
-rw-r--r--drivers/net/wireless/wl12xx/scan.c102
-rw-r--r--drivers/net/wireless/wl12xx/scan.h8
-rw-r--r--drivers/net/wireless/wl12xx/sdio.c259
-rw-r--r--drivers/net/wireless/wl12xx/sdio_test.c543
-rw-r--r--drivers/net/wireless/wl12xx/spi.c214
-rw-r--r--drivers/net/wireless/wl12xx/testmode.c76
-rw-r--r--drivers/net/wireless/wl12xx/tx.c373
-rw-r--r--drivers/net/wireless/wl12xx/tx.h11
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx.h377
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_80211.h5
-rw-r--r--drivers/net/wireless/wl12xx/wl12xx_platform_data.c4
-rw-r--r--include/linux/ieee80211.h17
-rw-r--r--include/linux/nl80211.h2
-rw-r--r--include/linux/wl12xx.h5
-rw-r--r--include/net/bluetooth/bluetooth.h5
-rw-r--r--include/net/bluetooth/hci.h38
-rw-r--r--include/net/bluetooth/hci_core.h28
-rw-r--r--include/net/bluetooth/l2cap.h2
-rw-r--r--include/net/bluetooth/mgmt.h49
-rw-r--r--include/net/cfg80211.h11
-rw-r--r--net/bluetooth/bnep/core.c8
-rw-r--r--net/bluetooth/cmtp/core.c5
-rw-r--r--net/bluetooth/hci_conn.c2
-rw-r--r--net/bluetooth/hci_core.c31
-rw-r--r--net/bluetooth/hci_event.c152
-rw-r--r--net/bluetooth/l2cap_core.c101
-rw-r--r--net/bluetooth/l2cap_sock.c16
-rw-r--r--net/bluetooth/mgmt.c660
-rw-r--r--net/bluetooth/smp.c32
-rw-r--r--net/mac80211/agg-rx.c2
-rw-r--r--net/mac80211/agg-tx.c26
-rw-r--r--net/mac80211/ht.c6
-rw-r--r--net/mac80211/ibss.c101
-rw-r--r--net/mac80211/ieee80211_i.h1
-rw-r--r--net/mac80211/main.c3
-rw-r--r--net/mac80211/rx.c16
-rw-r--r--net/mac80211/tx.c5
-rw-r--r--net/mac80211/util.c5
-rw-r--r--net/wireless/Kconfig7
-rw-r--r--net/wireless/chan.c12
-rw-r--r--net/wireless/nl80211.c32
98 files changed, 4633 insertions, 3467 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 3d849122b5b1..33f7327d0451 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -263,8 +263,7 @@ Who: Ravikiran Thirumalai <kiran@scalex86.org>
263 263
264What: Code that is now under CONFIG_WIRELESS_EXT_SYSFS 264What: Code that is now under CONFIG_WIRELESS_EXT_SYSFS
265 (in net/core/net-sysfs.c) 265 (in net/core/net-sysfs.c)
266When: After the only user (hal) has seen a release with the patches 266When: 3.5
267 for enough time, probably some time in 2010.
268Why: Over 1K .text/.data size reduction, data is available in other 267Why: Over 1K .text/.data size reduction, data is available in other
269 ways (ioctls) 268 ways (ioctls)
270Who: Johannes Berg <johannes@sipsolutions.net> 269Who: Johannes Berg <johannes@sipsolutions.net>
diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
index 1b51d8b7ac80..b0994c0e05dc 100644
--- a/drivers/bcma/host_pci.c
+++ b/drivers/bcma/host_pci.c
@@ -21,48 +21,58 @@ static void bcma_host_pci_switch_core(struct bcma_device *core)
21 pr_debug("Switched to core: 0x%X\n", core->id.id); 21 pr_debug("Switched to core: 0x%X\n", core->id.id);
22} 22}
23 23
24static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset) 24/* Provides access to the requested core. Returns base offset that has to be
25 * used. It makes use of fixed windows when possible. */
26static u16 bcma_host_pci_provide_access_to_core(struct bcma_device *core)
25{ 27{
28 switch (core->id.id) {
29 case BCMA_CORE_CHIPCOMMON:
30 return 3 * BCMA_CORE_SIZE;
31 case BCMA_CORE_PCIE:
32 return 2 * BCMA_CORE_SIZE;
33 }
34
26 if (core->bus->mapped_core != core) 35 if (core->bus->mapped_core != core)
27 bcma_host_pci_switch_core(core); 36 bcma_host_pci_switch_core(core);
37 return 0;
38}
39
40static u8 bcma_host_pci_read8(struct bcma_device *core, u16 offset)
41{
42 offset += bcma_host_pci_provide_access_to_core(core);
28 return ioread8(core->bus->mmio + offset); 43 return ioread8(core->bus->mmio + offset);
29} 44}
30 45
31static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset) 46static u16 bcma_host_pci_read16(struct bcma_device *core, u16 offset)
32{ 47{
33 if (core->bus->mapped_core != core) 48 offset += bcma_host_pci_provide_access_to_core(core);
34 bcma_host_pci_switch_core(core);
35 return ioread16(core->bus->mmio + offset); 49 return ioread16(core->bus->mmio + offset);
36} 50}
37 51
38static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset) 52static u32 bcma_host_pci_read32(struct bcma_device *core, u16 offset)
39{ 53{
40 if (core->bus->mapped_core != core) 54 offset += bcma_host_pci_provide_access_to_core(core);
41 bcma_host_pci_switch_core(core);
42 return ioread32(core->bus->mmio + offset); 55 return ioread32(core->bus->mmio + offset);
43} 56}
44 57
45static void bcma_host_pci_write8(struct bcma_device *core, u16 offset, 58static void bcma_host_pci_write8(struct bcma_device *core, u16 offset,
46 u8 value) 59 u8 value)
47{ 60{
48 if (core->bus->mapped_core != core) 61 offset += bcma_host_pci_provide_access_to_core(core);
49 bcma_host_pci_switch_core(core);
50 iowrite8(value, core->bus->mmio + offset); 62 iowrite8(value, core->bus->mmio + offset);
51} 63}
52 64
53static void bcma_host_pci_write16(struct bcma_device *core, u16 offset, 65static void bcma_host_pci_write16(struct bcma_device *core, u16 offset,
54 u16 value) 66 u16 value)
55{ 67{
56 if (core->bus->mapped_core != core) 68 offset += bcma_host_pci_provide_access_to_core(core);
57 bcma_host_pci_switch_core(core);
58 iowrite16(value, core->bus->mmio + offset); 69 iowrite16(value, core->bus->mmio + offset);
59} 70}
60 71
61static void bcma_host_pci_write32(struct bcma_device *core, u16 offset, 72static void bcma_host_pci_write32(struct bcma_device *core, u16 offset,
62 u32 value) 73 u32 value)
63{ 74{
64 if (core->bus->mapped_core != core) 75 offset += bcma_host_pci_provide_access_to_core(core);
65 bcma_host_pci_switch_core(core);
66 iowrite32(value, core->bus->mmio + offset); 76 iowrite32(value, core->bus->mmio + offset);
67} 77}
68 78
diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 11b41fd40c27..5ccf142ef0b8 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -188,7 +188,7 @@ config BT_MRVL
188 The core driver to support Marvell Bluetooth devices. 188 The core driver to support Marvell Bluetooth devices.
189 189
190 This driver is required if you want to support 190 This driver is required if you want to support
191 Marvell Bluetooth devices, such as 8688/8787. 191 Marvell Bluetooth devices, such as 8688/8787/8797.
192 192
193 Say Y here to compile Marvell Bluetooth driver 193 Say Y here to compile Marvell Bluetooth driver
194 into the kernel or say M to compile it as module. 194 into the kernel or say M to compile it as module.
@@ -201,8 +201,8 @@ config BT_MRVL_SDIO
201 The driver for Marvell Bluetooth chipsets with SDIO interface. 201 The driver for Marvell Bluetooth chipsets with SDIO interface.
202 202
203 This driver is required if you want to use Marvell Bluetooth 203 This driver is required if you want to use Marvell Bluetooth
204 devices with SDIO interface. Currently SD8688/SD8787 chipsets are 204 devices with SDIO interface. Currently SD8688/SD8787/SD8797
205 supported. 205 chipsets are supported.
206 206
207 Say Y here to compile support for Marvell BT-over-SDIO driver 207 Say Y here to compile support for Marvell BT-over-SDIO driver
208 into the kernel or say M to compile it as module. 208 into the kernel or say M to compile it as module.
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 9ef48167e2cf..27b74b0d547b 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -65,7 +65,7 @@ static const struct btmrvl_sdio_card_reg btmrvl_reg_8688 = {
65 .io_port_1 = 0x01, 65 .io_port_1 = 0x01,
66 .io_port_2 = 0x02, 66 .io_port_2 = 0x02,
67}; 67};
68static const struct btmrvl_sdio_card_reg btmrvl_reg_8787 = { 68static const struct btmrvl_sdio_card_reg btmrvl_reg_87xx = {
69 .cfg = 0x00, 69 .cfg = 0x00,
70 .host_int_mask = 0x02, 70 .host_int_mask = 0x02,
71 .host_intstatus = 0x03, 71 .host_intstatus = 0x03,
@@ -92,7 +92,14 @@ static const struct btmrvl_sdio_device btmrvl_sdio_sd8688 = {
92static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = { 92static const struct btmrvl_sdio_device btmrvl_sdio_sd8787 = {
93 .helper = NULL, 93 .helper = NULL,
94 .firmware = "mrvl/sd8787_uapsta.bin", 94 .firmware = "mrvl/sd8787_uapsta.bin",
95 .reg = &btmrvl_reg_8787, 95 .reg = &btmrvl_reg_87xx,
96 .sd_blksz_fw_dl = 256,
97};
98
99static const struct btmrvl_sdio_device btmrvl_sdio_sd8797 = {
100 .helper = NULL,
101 .firmware = "mrvl/sd8797_uapsta.bin",
102 .reg = &btmrvl_reg_87xx,
96 .sd_blksz_fw_dl = 256, 103 .sd_blksz_fw_dl = 256,
97}; 104};
98 105
@@ -103,6 +110,9 @@ static const struct sdio_device_id btmrvl_sdio_ids[] = {
103 /* Marvell SD8787 Bluetooth device */ 110 /* Marvell SD8787 Bluetooth device */
104 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A), 111 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A),
105 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 }, 112 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 },
113 /* Marvell SD8797 Bluetooth device */
114 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912A),
115 .driver_data = (unsigned long) &btmrvl_sdio_sd8797 },
106 116
107 { } /* Terminating entry */ 117 { } /* Terminating entry */
108}; 118};
@@ -1076,3 +1086,4 @@ MODULE_LICENSE("GPL v2");
1076MODULE_FIRMWARE("sd8688_helper.bin"); 1086MODULE_FIRMWARE("sd8688_helper.bin");
1077MODULE_FIRMWARE("sd8688.bin"); 1087MODULE_FIRMWARE("sd8688.bin");
1078MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin"); 1088MODULE_FIRMWARE("mrvl/sd8787_uapsta.bin");
1089MODULE_FIRMWARE("mrvl/sd8797_uapsta.bin");
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 2bd87d45f1c2..ea5ad1cbbd3d 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -785,9 +785,8 @@ skip_waking:
785 usb_mark_last_busy(data->udev); 785 usb_mark_last_busy(data->udev);
786 } 786 }
787 787
788 usb_free_urb(urb);
789
790done: 788done:
789 usb_free_urb(urb);
791 return err; 790 return err;
792} 791}
793 792
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 2e302a11ab55..2ed6ab1c6e1b 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -41,6 +41,8 @@
41 41
42#define VERSION "1.3" 42#define VERSION "1.3"
43 43
44static bool amp;
45
44struct vhci_data { 46struct vhci_data {
45 struct hci_dev *hdev; 47 struct hci_dev *hdev;
46 48
@@ -239,6 +241,9 @@ static int vhci_open(struct inode *inode, struct file *file)
239 hdev->bus = HCI_VIRTUAL; 241 hdev->bus = HCI_VIRTUAL;
240 hdev->driver_data = data; 242 hdev->driver_data = data;
241 243
244 if (amp)
245 hdev->dev_type = HCI_AMP;
246
242 hdev->open = vhci_open_dev; 247 hdev->open = vhci_open_dev;
243 hdev->close = vhci_close_dev; 248 hdev->close = vhci_close_dev;
244 hdev->flush = vhci_flush; 249 hdev->flush = vhci_flush;
@@ -303,6 +308,9 @@ static void __exit vhci_exit(void)
303module_init(vhci_init); 308module_init(vhci_init);
304module_exit(vhci_exit); 309module_exit(vhci_exit);
305 310
311module_param(amp, bool, 0644);
312MODULE_PARM_DESC(amp, "Create AMP controller device");
313
306MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 314MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
307MODULE_DESCRIPTION("Bluetooth virtual HCI driver ver " VERSION); 315MODULE_DESCRIPTION("Bluetooth virtual HCI driver ver " VERSION);
308MODULE_VERSION(VERSION); 316MODULE_VERSION(VERSION);
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_calib.c b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
index 88279e325dca..157337febc2b 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
@@ -203,7 +203,7 @@ static void ar9002_hw_iqcalibrate(struct ath_hw *ah, u8 numChains)
203 i); 203 i);
204 204
205 ath_dbg(common, ATH_DBG_CALIBRATE, 205 ath_dbg(common, ATH_DBG_CALIBRATE,
206 "Orignal: Chn %diq_corr_meas = 0x%08x\n", 206 "Original: Chn %d iq_corr_meas = 0x%08x\n",
207 i, ah->totalIqCorrMeas[i]); 207 i, ah->totalIqCorrMeas[i]);
208 208
209 iqCorrNeg = 0; 209 iqCorrNeg = 0;
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index ddeba8693fab..23b3a6c57800 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -226,7 +226,7 @@ static void ar9003_hw_iqcalibrate(struct ath_hw *ah, u8 numChains)
226 i); 226 i);
227 227
228 ath_dbg(common, ATH_DBG_CALIBRATE, 228 ath_dbg(common, ATH_DBG_CALIBRATE,
229 "Orignal: Chn %diq_corr_meas = 0x%08x\n", 229 "Original: Chn %d iq_corr_meas = 0x%08x\n",
230 i, ah->totalIqCorrMeas[i]); 230 i, ah->totalIqCorrMeas[i]);
231 231
232 iqCorrNeg = 0; 232 iqCorrNeg = 0;
diff --git a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
index 259a6f312afb..dc2054f0378e 100644
--- a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
@@ -41,24 +41,24 @@ static const u32 ar9462_pciephy_clkreq_enable_L1_2p0[][2] = {
41 41
42static const u32 ar9462_2p0_baseband_postamble[][5] = { 42static const u32 ar9462_2p0_baseband_postamble[][5] = {
43 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */ 43 /* Addr 5G_HT20 5G_HT40 2G_HT40 2G_HT20 */
44 {0x00009810, 0xd00a8005, 0xd00a8005, 0xd00a8011, 0xd00a8011}, 44 {0x00009810, 0xd00a8005, 0xd00a8005, 0xd00a8011, 0xd00a800d},
45 {0x00009820, 0x206a022e, 0x206a022e, 0x206a012e, 0x206a012e}, 45 {0x00009820, 0x206a022e, 0x206a022e, 0x206a012e, 0x206a01ae},
46 {0x00009824, 0x5ac640de, 0x5ac640d0, 0x5ac640d0, 0x5ac640de}, 46 {0x00009824, 0x5ac640de, 0x5ac640d0, 0x5ac640d0, 0x63c640da},
47 {0x00009828, 0x0796be89, 0x0696b081, 0x0696b881, 0x0796be89}, 47 {0x00009828, 0x0796be89, 0x0696b081, 0x0696b881, 0x09143e81},
48 {0x0000982c, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4}, 48 {0x0000982c, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4, 0x05eea6d4},
49 {0x00009830, 0x0000059c, 0x0000059c, 0x0000119c, 0x0000119c}, 49 {0x00009830, 0x0000059c, 0x0000059c, 0x0000119c, 0x0000119c},
50 {0x00009c00, 0x000000c4, 0x000000c4, 0x000000c4, 0x000000c4}, 50 {0x00009c00, 0x000000c4, 0x000000c4, 0x000000c4, 0x000000c4},
51 {0x00009e00, 0x0372111a, 0x0372111a, 0x037216a0, 0x037216a0}, 51 {0x00009e00, 0x0372111a, 0x0372111a, 0x037216a0, 0x037216a0},
52 {0x00009e04, 0x001c2020, 0x001c2020, 0x001c2020, 0x001c2020}, 52 {0x00009e04, 0x001c2020, 0x001c2020, 0x001c2020, 0x001c2020},
53 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000e2}, 53 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000d8},
54 {0x00009e10, 0x92c88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x92c84d2e}, 54 {0x00009e10, 0x92c88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x7ec86d2e},
55 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3379605e, 0x33795d5e}, 55 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3376605e, 0x33795d5e},
56 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 56 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
57 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 57 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
58 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 58 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce},
59 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021}, 59 {0x00009e2c, 0x0000001c, 0x0000001c, 0x00000021, 0x00000021},
60 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c782}, 60 {0x00009e3c, 0xcf946220, 0xcf946220, 0xcfd5c782, 0xcfd5c282},
61 {0x00009e44, 0xfe321e27, 0xfe321e27, 0xfe291e27, 0xfe291e27}, 61 {0x00009e44, 0x62321e27, 0x62321e27, 0xfe291e27, 0xfe291e27},
62 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012}, 62 {0x00009e48, 0x5030201a, 0x5030201a, 0x50302012, 0x50302012},
63 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000}, 63 {0x00009fc8, 0x0003f000, 0x0003f000, 0x0001a000, 0x0001a000},
64 {0x0000a204, 0x013187c0, 0x013187c4, 0x013187c4, 0x013187c0}, 64 {0x0000a204, 0x013187c0, 0x013187c4, 0x013187c4, 0x013187c0},
@@ -81,6 +81,15 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
81 {0x0000a2d0, 0x00041981, 0x00041981, 0x00041981, 0x00041982}, 81 {0x0000a2d0, 0x00041981, 0x00041981, 0x00041981, 0x00041982},
82 {0x0000a2d8, 0x7999a83b, 0x7999a83b, 0x7999a83b, 0x7999a83b}, 82 {0x0000a2d8, 0x7999a83b, 0x7999a83b, 0x7999a83b, 0x7999a83b},
83 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 83 {0x0000a358, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
84 {0x0000a3a4, 0x00000010, 0x00000010, 0x00000000, 0x00000000},
85 {0x0000a3a8, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa, 0xaaaaaaaa},
86 {0x0000a3ac, 0xaaaaaa00, 0xaaaaaa30, 0xaaaaaa00, 0xaaaaaa00},
87 {0x0000a41c, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce},
88 {0x0000a420, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce},
89 {0x0000a424, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce},
90 {0x0000a428, 0x000001ce, 0x000001ce, 0x000001ce, 0x000001ce},
91 {0x0000a42c, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce},
92 {0x0000a430, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce, 0x1ce739ce},
84 {0x0000a830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c}, 93 {0x0000a830, 0x0000019c, 0x0000019c, 0x0000019c, 0x0000019c},
85 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000}, 94 {0x0000ae04, 0x001c0000, 0x001c0000, 0x001c0000, 0x00100000},
86 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 95 {0x0000ae18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
@@ -1107,11 +1116,11 @@ static const u32 ar9462_2p0_baseband_core[][2] = {
1107 {0x00009e30, 0x06336f77}, 1116 {0x00009e30, 0x06336f77},
1108 {0x00009e34, 0x6af6532f}, 1117 {0x00009e34, 0x6af6532f},
1109 {0x00009e38, 0x0cc80c00}, 1118 {0x00009e38, 0x0cc80c00},
1110 {0x00009e40, 0x0d261820}, 1119 {0x00009e40, 0x15262820},
1111 {0x00009e4c, 0x00001004}, 1120 {0x00009e4c, 0x00001004},
1112 {0x00009e50, 0x00ff03f1}, 1121 {0x00009e50, 0x00ff03f1},
1113 {0x00009e54, 0xe4c355c7}, 1122 {0x00009e54, 0xe4c555c2},
1114 {0x00009e58, 0xfd897735}, 1123 {0x00009e58, 0xfd857722},
1115 {0x00009e5c, 0xe9198724}, 1124 {0x00009e5c, 0xe9198724},
1116 {0x00009fc0, 0x803e4788}, 1125 {0x00009fc0, 0x803e4788},
1117 {0x00009fc4, 0x0001efb5}, 1126 {0x00009fc4, 0x0001efb5},
@@ -1142,9 +1151,6 @@ static const u32 ar9462_2p0_baseband_core[][2] = {
1142 {0x0000a398, 0x001f0e0f}, 1151 {0x0000a398, 0x001f0e0f},
1143 {0x0000a39c, 0x0075393f}, 1152 {0x0000a39c, 0x0075393f},
1144 {0x0000a3a0, 0xb79f6427}, 1153 {0x0000a3a0, 0xb79f6427},
1145 {0x0000a3a4, 0x00000000},
1146 {0x0000a3a8, 0xaaaaaaaa},
1147 {0x0000a3ac, 0x3c466478},
1148 {0x0000a3c0, 0x20202020}, 1154 {0x0000a3c0, 0x20202020},
1149 {0x0000a3c4, 0x22222220}, 1155 {0x0000a3c4, 0x22222220},
1150 {0x0000a3c8, 0x20200020}, 1156 {0x0000a3c8, 0x20200020},
@@ -1167,12 +1173,6 @@ static const u32 ar9462_2p0_baseband_core[][2] = {
1167 {0x0000a40c, 0x00820820}, 1173 {0x0000a40c, 0x00820820},
1168 {0x0000a414, 0x1ce739ce}, 1174 {0x0000a414, 0x1ce739ce},
1169 {0x0000a418, 0x2d001dce}, 1175 {0x0000a418, 0x2d001dce},
1170 {0x0000a41c, 0x1ce739ce},
1171 {0x0000a420, 0x000001ce},
1172 {0x0000a424, 0x1ce739ce},
1173 {0x0000a428, 0x000001ce},
1174 {0x0000a42c, 0x1ce739ce},
1175 {0x0000a430, 0x1ce739ce},
1176 {0x0000a434, 0x00000000}, 1176 {0x0000a434, 0x00000000},
1177 {0x0000a438, 0x00001801}, 1177 {0x0000a438, 0x00001801},
1178 {0x0000a43c, 0x00100000}, 1178 {0x0000a43c, 0x00100000},
diff --git a/drivers/net/wireless/ath/ath9k/htc_drv_main.c b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
index 0b9a0e8a4958..f8ce4ea6f65c 100644
--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
@@ -808,7 +808,8 @@ void ath9k_htc_ani_work(struct work_struct *work)
808 } 808 }
809 809
810 /* Verify whether we must check ANI */ 810 /* Verify whether we must check ANI */
811 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) { 811 if (ah->config.enable_ani &&
812 (timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
812 aniflag = true; 813 aniflag = true;
813 common->ani.checkani_timer = timestamp; 814 common->ani.checkani_timer = timestamp;
814 } 815 }
@@ -838,7 +839,7 @@ set_timer:
838 * short calibration and long calibration. 839 * short calibration and long calibration.
839 */ 840 */
840 cal_interval = ATH_LONG_CALINTERVAL; 841 cal_interval = ATH_LONG_CALINTERVAL;
841 if (priv->ah->config.enable_ani) 842 if (ah->config.enable_ani)
842 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL); 843 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
843 if (!common->ani.caldone) 844 if (!common->ani.caldone)
844 cal_interval = min(cal_interval, (u32)short_cal_interval); 845 cal_interval = min(cal_interval, (u32)short_cal_interval);
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index caf572cf270f..7f8fc65f2cb4 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -504,7 +504,7 @@ static int ath9k_hw_post_init(struct ath_hw *ah)
504 return ecode; 504 return ecode;
505 } 505 }
506 506
507 if (!AR_SREV_9100(ah) && !AR_SREV_9340(ah)) { 507 if (ah->config.enable_ani) {
508 ath9k_hw_ani_setup(ah); 508 ath9k_hw_ani_setup(ah);
509 ath9k_hw_ani_init(ah); 509 ath9k_hw_ani_init(ah);
510 } 510 }
@@ -610,6 +610,10 @@ static int __ath9k_hw_init(struct ath_hw *ah)
610 if (!AR_SREV_9300_20_OR_LATER(ah)) 610 if (!AR_SREV_9300_20_OR_LATER(ah))
611 ah->ani_function &= ~ATH9K_ANI_MRC_CCK; 611 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
612 612
613 /* disable ANI for 9340 */
614 if (AR_SREV_9340(ah))
615 ah->config.enable_ani = false;
616
613 ath9k_hw_init_mode_regs(ah); 617 ath9k_hw_init_mode_regs(ah);
614 618
615 if (!ah->is_pciexpress) 619 if (!ah->is_pciexpress)
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index c9c3b1889965..36968c046119 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -1110,7 +1110,6 @@ bool ath9k_hw_disable(struct ath_hw *ah);
1110void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test); 1110void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test);
1111void ath9k_hw_setopmode(struct ath_hw *ah); 1111void ath9k_hw_setopmode(struct ath_hw *ah);
1112void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1); 1112void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1);
1113void ath9k_hw_setbssidmask(struct ath_hw *ah);
1114void ath9k_hw_write_associd(struct ath_hw *ah); 1113void ath9k_hw_write_associd(struct ath_hw *ah);
1115u32 ath9k_hw_gettsf32(struct ath_hw *ah); 1114u32 ath9k_hw_gettsf32(struct ath_hw *ah);
1116u64 ath9k_hw_gettsf64(struct ath_hw *ah); 1115u64 ath9k_hw_gettsf64(struct ath_hw *ah);
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index e9711e2b48c6..41b72faca77f 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -258,6 +258,8 @@ static void setup_ht_cap(struct ath_softc *sc,
258 258
259 if (AR_SREV_9330(ah) || AR_SREV_9485(ah)) 259 if (AR_SREV_9330(ah) || AR_SREV_9485(ah))
260 max_streams = 1; 260 max_streams = 1;
261 else if (AR_SREV_9462(ah))
262 max_streams = 2;
261 else if (AR_SREV_9300_20_OR_LATER(ah)) 263 else if (AR_SREV_9300_20_OR_LATER(ah))
262 max_streams = 3; 264 max_streams = 3;
263 else 265 else
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index fd59c1f25c43..5007297c9447 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -118,7 +118,7 @@ void ath9k_ps_restore(struct ath_softc *sc)
118 if (--sc->ps_usecount != 0) 118 if (--sc->ps_usecount != 0)
119 goto unlock; 119 goto unlock;
120 120
121 if (sc->ps_idle) 121 if (sc->ps_idle && (sc->ps_flags & PS_WAIT_FOR_TX_ACK))
122 mode = ATH9K_PM_FULL_SLEEP; 122 mode = ATH9K_PM_FULL_SLEEP;
123 else if (sc->ps_enabled && 123 else if (sc->ps_enabled &&
124 !(sc->ps_flags & (PS_WAIT_FOR_BEACON | 124 !(sc->ps_flags & (PS_WAIT_FOR_BEACON |
@@ -332,7 +332,8 @@ static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
332 hchan = ah->curchan; 332 hchan = ah->curchan;
333 } 333 }
334 334
335 if (fastcc && !ath9k_hw_check_alive(ah)) 335 if (fastcc && (ah->chip_fullsleep ||
336 !ath9k_hw_check_alive(ah)))
336 fastcc = false; 337 fastcc = false;
337 338
338 if (!ath_prepare_reset(sc, retry_tx, flush)) 339 if (!ath_prepare_reset(sc, retry_tx, flush))
@@ -561,7 +562,6 @@ void ath_ani_calibrate(unsigned long data)
561 /* Long calibration runs independently of short calibration. */ 562 /* Long calibration runs independently of short calibration. */
562 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) { 563 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
563 longcal = true; 564 longcal = true;
564 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
565 common->ani.longcal_timer = timestamp; 565 common->ani.longcal_timer = timestamp;
566 } 566 }
567 567
@@ -569,8 +569,6 @@ void ath_ani_calibrate(unsigned long data)
569 if (!common->ani.caldone) { 569 if (!common->ani.caldone) {
570 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) { 570 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
571 shortcal = true; 571 shortcal = true;
572 ath_dbg(common, ATH_DBG_ANI,
573 "shortcal @%lu\n", jiffies);
574 common->ani.shortcal_timer = timestamp; 572 common->ani.shortcal_timer = timestamp;
575 common->ani.resetcal_timer = timestamp; 573 common->ani.resetcal_timer = timestamp;
576 } 574 }
@@ -584,8 +582,9 @@ void ath_ani_calibrate(unsigned long data)
584 } 582 }
585 583
586 /* Verify whether we must check ANI */ 584 /* Verify whether we must check ANI */
587 if ((timestamp - common->ani.checkani_timer) >= 585 if (sc->sc_ah->config.enable_ani
588 ah->config.ani_poll_interval) { 586 && (timestamp - common->ani.checkani_timer) >=
587 ah->config.ani_poll_interval) {
589 aniflag = true; 588 aniflag = true;
590 common->ani.checkani_timer = timestamp; 589 common->ani.checkani_timer = timestamp;
591 } 590 }
@@ -605,6 +604,11 @@ void ath_ani_calibrate(unsigned long data)
605 ah->rxchainmask, longcal); 604 ah->rxchainmask, longcal);
606 } 605 }
607 606
607 ath_dbg(common, ATH_DBG_ANI,
608 "Calibration @%lu finished: %s %s %s, caldone: %s\n", jiffies,
609 longcal ? "long" : "", shortcal ? "short" : "",
610 aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
611
608 ath9k_ps_restore(sc); 612 ath9k_ps_restore(sc);
609 613
610set_timer: 614set_timer:
@@ -886,82 +890,6 @@ chip_reset:
886#undef SCHED_INTR 890#undef SCHED_INTR
887} 891}
888 892
889static void ath_radio_enable(struct ath_softc *sc, struct ieee80211_hw *hw)
890{
891 struct ath_hw *ah = sc->sc_ah;
892 struct ath_common *common = ath9k_hw_common(ah);
893 struct ieee80211_channel *channel = hw->conf.channel;
894 int r;
895
896 ath9k_ps_wakeup(sc);
897 spin_lock_bh(&sc->sc_pcu_lock);
898 atomic_set(&ah->intr_ref_cnt, -1);
899
900 ath9k_hw_configpcipowersave(ah, false);
901
902 if (!ah->curchan)
903 ah->curchan = ath9k_cmn_get_curchannel(sc->hw, ah);
904
905 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
906 if (r) {
907 ath_err(common,
908 "Unable to reset channel (%u MHz), reset status %d\n",
909 channel->center_freq, r);
910 }
911
912 ath_complete_reset(sc, true);
913
914 /* Enable LED */
915 ath9k_hw_cfg_output(ah, ah->led_pin,
916 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
917 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
918
919 spin_unlock_bh(&sc->sc_pcu_lock);
920
921 ath9k_ps_restore(sc);
922}
923
924void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw)
925{
926 struct ath_hw *ah = sc->sc_ah;
927 struct ieee80211_channel *channel = hw->conf.channel;
928 int r;
929
930 ath9k_ps_wakeup(sc);
931
932 ath_cancel_work(sc);
933
934 spin_lock_bh(&sc->sc_pcu_lock);
935
936 /*
937 * Keep the LED on when the radio is disabled
938 * during idle unassociated state.
939 */
940 if (!sc->ps_idle) {
941 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
942 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
943 }
944
945 ath_prepare_reset(sc, false, true);
946
947 if (!ah->curchan)
948 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
949
950 r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
951 if (r) {
952 ath_err(ath9k_hw_common(sc->sc_ah),
953 "Unable to reset channel (%u MHz), reset status %d\n",
954 channel->center_freq, r);
955 }
956
957 ath9k_hw_phy_disable(ah);
958
959 ath9k_hw_configpcipowersave(ah, true);
960
961 spin_unlock_bh(&sc->sc_pcu_lock);
962 ath9k_ps_restore(sc);
963}
964
965static int ath_reset(struct ath_softc *sc, bool retry_tx) 893static int ath_reset(struct ath_softc *sc, bool retry_tx)
966{ 894{
967 int r; 895 int r;
@@ -1097,6 +1025,9 @@ static int ath9k_start(struct ieee80211_hw *hw)
1097 * and then setup of the interrupt mask. 1025 * and then setup of the interrupt mask.
1098 */ 1026 */
1099 spin_lock_bh(&sc->sc_pcu_lock); 1027 spin_lock_bh(&sc->sc_pcu_lock);
1028
1029 atomic_set(&ah->intr_ref_cnt, -1);
1030
1100 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false); 1031 r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1101 if (r) { 1032 if (r) {
1102 ath_err(common, 1033 ath_err(common,
@@ -1138,6 +1069,18 @@ static int ath9k_start(struct ieee80211_hw *hw)
1138 goto mutex_unlock; 1069 goto mutex_unlock;
1139 } 1070 }
1140 1071
1072 if (ah->led_pin >= 0) {
1073 ath9k_hw_cfg_output(ah, ah->led_pin,
1074 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1075 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1076 }
1077
1078 /*
1079 * Reset key cache to sane defaults (all entries cleared) instead of
1080 * semi-random values after suspend/resume.
1081 */
1082 ath9k_cmn_init_crypto(sc->sc_ah);
1083
1141 spin_unlock_bh(&sc->sc_pcu_lock); 1084 spin_unlock_bh(&sc->sc_pcu_lock);
1142 1085
1143 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) && 1086 if ((ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE) &&
@@ -1183,6 +1126,13 @@ static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1183 } 1126 }
1184 } 1127 }
1185 1128
1129 /*
1130 * Cannot tx while the hardware is in full sleep, it first needs a full
1131 * chip reset to recover from that
1132 */
1133 if (unlikely(sc->sc_ah->power_mode == ATH9K_PM_FULL_SLEEP))
1134 goto exit;
1135
1186 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) { 1136 if (unlikely(sc->sc_ah->power_mode != ATH9K_PM_AWAKE)) {
1187 /* 1137 /*
1188 * We are using PS-Poll and mac80211 can request TX while in 1138 * We are using PS-Poll and mac80211 can request TX while in
@@ -1229,6 +1179,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
1229 struct ath_softc *sc = hw->priv; 1179 struct ath_softc *sc = hw->priv;
1230 struct ath_hw *ah = sc->sc_ah; 1180 struct ath_hw *ah = sc->sc_ah;
1231 struct ath_common *common = ath9k_hw_common(ah); 1181 struct ath_common *common = ath9k_hw_common(ah);
1182 bool prev_idle;
1232 1183
1233 mutex_lock(&sc->mutex); 1184 mutex_lock(&sc->mutex);
1234 1185
@@ -1259,35 +1210,45 @@ static void ath9k_stop(struct ieee80211_hw *hw)
1259 * before setting the invalid flag. */ 1210 * before setting the invalid flag. */
1260 ath9k_hw_disable_interrupts(ah); 1211 ath9k_hw_disable_interrupts(ah);
1261 1212
1262 if (!(sc->sc_flags & SC_OP_INVALID)) { 1213 spin_unlock_bh(&sc->sc_pcu_lock);
1263 ath_drain_all_txq(sc, false); 1214
1264 ath_stoprecv(sc); 1215 /* we can now sync irq and kill any running tasklets, since we already
1265 ath9k_hw_phy_disable(ah); 1216 * disabled interrupts and not holding a spin lock */
1266 } else 1217 synchronize_irq(sc->irq);
1267 sc->rx.rxlink = NULL; 1218 tasklet_kill(&sc->intr_tq);
1219 tasklet_kill(&sc->bcon_tasklet);
1220
1221 prev_idle = sc->ps_idle;
1222 sc->ps_idle = true;
1223
1224 spin_lock_bh(&sc->sc_pcu_lock);
1225
1226 if (ah->led_pin >= 0) {
1227 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1228 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1229 }
1230
1231 ath_prepare_reset(sc, false, true);
1268 1232
1269 if (sc->rx.frag) { 1233 if (sc->rx.frag) {
1270 dev_kfree_skb_any(sc->rx.frag); 1234 dev_kfree_skb_any(sc->rx.frag);
1271 sc->rx.frag = NULL; 1235 sc->rx.frag = NULL;
1272 } 1236 }
1273 1237
1274 /* disable HAL and put h/w to sleep */ 1238 if (!ah->curchan)
1275 ath9k_hw_disable(ah); 1239 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1276 1240
1277 spin_unlock_bh(&sc->sc_pcu_lock); 1241 ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
1242 ath9k_hw_phy_disable(ah);
1278 1243
1279 /* we can now sync irq and kill any running tasklets, since we already 1244 ath9k_hw_configpcipowersave(ah, true);
1280 * disabled interrupts and not holding a spin lock */
1281 synchronize_irq(sc->irq);
1282 tasklet_kill(&sc->intr_tq);
1283 tasklet_kill(&sc->bcon_tasklet);
1284 1245
1285 ath9k_ps_restore(sc); 1246 spin_unlock_bh(&sc->sc_pcu_lock);
1286 1247
1287 sc->ps_idle = true; 1248 ath9k_ps_restore(sc);
1288 ath_radio_disable(sc, hw);
1289 1249
1290 sc->sc_flags |= SC_OP_INVALID; 1250 sc->sc_flags |= SC_OP_INVALID;
1251 sc->ps_idle = prev_idle;
1291 1252
1292 mutex_unlock(&sc->mutex); 1253 mutex_unlock(&sc->mutex);
1293 1254
@@ -1627,8 +1588,8 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1627 struct ath_hw *ah = sc->sc_ah; 1588 struct ath_hw *ah = sc->sc_ah;
1628 struct ath_common *common = ath9k_hw_common(ah); 1589 struct ath_common *common = ath9k_hw_common(ah);
1629 struct ieee80211_conf *conf = &hw->conf; 1590 struct ieee80211_conf *conf = &hw->conf;
1630 bool disable_radio = false;
1631 1591
1592 ath9k_ps_wakeup(sc);
1632 mutex_lock(&sc->mutex); 1593 mutex_lock(&sc->mutex);
1633 1594
1634 /* 1595 /*
@@ -1639,13 +1600,8 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1639 */ 1600 */
1640 if (changed & IEEE80211_CONF_CHANGE_IDLE) { 1601 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1641 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE); 1602 sc->ps_idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1642 if (!sc->ps_idle) { 1603 if (sc->ps_idle)
1643 ath_radio_enable(sc, hw); 1604 ath_cancel_work(sc);
1644 ath_dbg(common, ATH_DBG_CONFIG,
1645 "not-idle: enabling radio\n");
1646 } else {
1647 disable_radio = true;
1648 }
1649 } 1605 }
1650 1606
1651 /* 1607 /*
@@ -1752,18 +1708,12 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1752 ath_dbg(common, ATH_DBG_CONFIG, 1708 ath_dbg(common, ATH_DBG_CONFIG,
1753 "Set power: %d\n", conf->power_level); 1709 "Set power: %d\n", conf->power_level);
1754 sc->config.txpowlimit = 2 * conf->power_level; 1710 sc->config.txpowlimit = 2 * conf->power_level;
1755 ath9k_ps_wakeup(sc);
1756 ath9k_cmn_update_txpow(ah, sc->curtxpow, 1711 ath9k_cmn_update_txpow(ah, sc->curtxpow,
1757 sc->config.txpowlimit, &sc->curtxpow); 1712 sc->config.txpowlimit, &sc->curtxpow);
1758 ath9k_ps_restore(sc);
1759 }
1760
1761 if (disable_radio) {
1762 ath_dbg(common, ATH_DBG_CONFIG, "idle: disabling radio\n");
1763 ath_radio_disable(sc, hw);
1764 } 1713 }
1765 1714
1766 mutex_unlock(&sc->mutex); 1715 mutex_unlock(&sc->mutex);
1716 ath9k_ps_restore(sc);
1767 1717
1768 return 0; 1718 return 0;
1769} 1719}
@@ -2331,9 +2281,6 @@ static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
2331 return; 2281 return;
2332 } 2282 }
2333 2283
2334 if (drop)
2335 timeout = 1;
2336
2337 for (j = 0; j < timeout; j++) { 2284 for (j = 0; j < timeout; j++) {
2338 bool npend = false; 2285 bool npend = false;
2339 2286
@@ -2351,21 +2298,22 @@ static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
2351 } 2298 }
2352 2299
2353 if (!npend) 2300 if (!npend)
2354 goto out; 2301 break;
2355 } 2302 }
2356 2303
2357 ath9k_ps_wakeup(sc); 2304 if (drop) {
2358 spin_lock_bh(&sc->sc_pcu_lock); 2305 ath9k_ps_wakeup(sc);
2359 drain_txq = ath_drain_all_txq(sc, false); 2306 spin_lock_bh(&sc->sc_pcu_lock);
2360 spin_unlock_bh(&sc->sc_pcu_lock); 2307 drain_txq = ath_drain_all_txq(sc, false);
2308 spin_unlock_bh(&sc->sc_pcu_lock);
2361 2309
2362 if (!drain_txq) 2310 if (!drain_txq)
2363 ath_reset(sc, false); 2311 ath_reset(sc, false);
2364 2312
2365 ath9k_ps_restore(sc); 2313 ath9k_ps_restore(sc);
2366 ieee80211_wake_queues(hw); 2314 ieee80211_wake_queues(hw);
2315 }
2367 2316
2368out:
2369 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0); 2317 ieee80211_queue_delayed_work(hw, &sc->tx_complete_work, 0);
2370 mutex_unlock(&sc->mutex); 2318 mutex_unlock(&sc->mutex);
2371} 2319}
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index 2dcdf63cb390..a439edc5dc06 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -307,12 +307,11 @@ static int ath_pci_suspend(struct device *device)
307 struct ieee80211_hw *hw = pci_get_drvdata(pdev); 307 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
308 struct ath_softc *sc = hw->priv; 308 struct ath_softc *sc = hw->priv;
309 309
310 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 1);
311
312 /* The device has to be moved to FULLSLEEP forcibly. 310 /* The device has to be moved to FULLSLEEP forcibly.
313 * Otherwise the chip never moved to full sleep, 311 * Otherwise the chip never moved to full sleep,
314 * when no interface is up. 312 * when no interface is up.
315 */ 313 */
314 ath9k_hw_disable(sc->sc_ah);
316 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP); 315 ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_FULL_SLEEP);
317 316
318 return 0; 317 return 0;
@@ -321,8 +320,6 @@ static int ath_pci_suspend(struct device *device)
321static int ath_pci_resume(struct device *device) 320static int ath_pci_resume(struct device *device)
322{ 321{
323 struct pci_dev *pdev = to_pci_dev(device); 322 struct pci_dev *pdev = to_pci_dev(device);
324 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
325 struct ath_softc *sc = hw->priv;
326 u32 val; 323 u32 val;
327 324
328 /* 325 /*
@@ -334,22 +331,6 @@ static int ath_pci_resume(struct device *device)
334 if ((val & 0x0000ff00) != 0) 331 if ((val & 0x0000ff00) != 0)
335 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); 332 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
336 333
337 ath9k_ps_wakeup(sc);
338 /* Enable LED */
339 ath9k_hw_cfg_output(sc->sc_ah, sc->sc_ah->led_pin,
340 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
341 ath9k_hw_set_gpio(sc->sc_ah, sc->sc_ah->led_pin, 0);
342
343 /*
344 * Reset key cache to sane defaults (all entries cleared) instead of
345 * semi-random values after suspend/resume.
346 */
347 ath9k_cmn_init_crypto(sc->sc_ah);
348 ath9k_ps_restore(sc);
349
350 sc->ps_idle = true;
351 ath_radio_disable(sc, hw);
352
353 return 0; 334 return 0;
354} 335}
355 336
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index 80639e3e4ac9..9e65c3198ca7 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -1954,7 +1954,7 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
1954 skb_pull(skb, padsize); 1954 skb_pull(skb, padsize);
1955 } 1955 }
1956 1956
1957 if (sc->ps_flags & PS_WAIT_FOR_TX_ACK) { 1957 if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) {
1958 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK; 1958 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
1959 ath_dbg(common, ATH_DBG_PS, 1959 ath_dbg(common, ATH_DBG_PS,
1960 "Going back to sleep after having received TX status (0x%lx)\n", 1960 "Going back to sleep after having received TX status (0x%lx)\n",
diff --git a/drivers/net/wireless/iwlegacy/common.c b/drivers/net/wireless/iwlegacy/common.c
index 7e2924f332a7..881ba043770a 100644
--- a/drivers/net/wireless/iwlegacy/common.c
+++ b/drivers/net/wireless/iwlegacy/common.c
@@ -2786,9 +2786,8 @@ il_tx_queue_alloc(struct il_priv *il, struct il_tx_queue *txq, u32 id)
2786 /* Driver ilate data, only for Tx (not command) queues, 2786 /* Driver ilate data, only for Tx (not command) queues,
2787 * not shared with device. */ 2787 * not shared with device. */
2788 if (id != il->cmd_queue) { 2788 if (id != il->cmd_queue) {
2789 txq->txb = 2789 txq->txb = kcalloc(TFD_QUEUE_SIZE_MAX, sizeof(txq->txb[0]),
2790 kzalloc(sizeof(txq->txb[0]) * TFD_QUEUE_SIZE_MAX, 2790 GFP_KERNEL);
2791 GFP_KERNEL);
2792 if (!txq->txb) { 2791 if (!txq->txb) {
2793 IL_ERR("kmalloc for auxiliary BD " 2792 IL_ERR("kmalloc for auxiliary BD "
2794 "structures failed\n"); 2793 "structures failed\n");
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index a7ab280994c8..86344cefd32f 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -1,7 +1,7 @@
1# WIFI 1# WIFI
2obj-$(CONFIG_IWLWIFI) += iwlwifi.o 2obj-$(CONFIG_IWLWIFI) += iwlwifi.o
3iwlwifi-objs := iwl-agn.o iwl-agn-rs.o iwl-mac80211.o 3iwlwifi-objs := iwl-agn.o iwl-agn-rs.o iwl-mac80211.o
4iwlwifi-objs += iwl-agn-ucode.o iwl-agn-tx.o 4iwlwifi-objs += iwl-ucode.o iwl-agn-tx.o
5iwlwifi-objs += iwl-agn-lib.o iwl-agn-calib.o iwl-io.o 5iwlwifi-objs += iwl-agn-lib.o iwl-agn-calib.o iwl-io.o
6iwlwifi-objs += iwl-agn-tt.o iwl-agn-sta.o iwl-agn-rx.o 6iwlwifi-objs += iwl-agn-tt.o iwl-agn-sta.o iwl-agn-rx.o
7 7
@@ -18,7 +18,7 @@ iwlwifi-objs += iwl-trans-pcie.o iwl-trans-pcie-rx.o iwl-trans-pcie-tx.o
18 18
19iwlwifi-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o 19iwlwifi-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
20iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o 20iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o
21iwlwifi-$(CONFIG_IWLWIFI_DEVICE_SVTOOL) += iwl-sv-open.o 21iwlwifi-$(CONFIG_IWLWIFI_DEVICE_SVTOOL) += iwl-testmode.o
22 22
23CFLAGS_iwl-devtrace.o := -I$(src) 23CFLAGS_iwl-devtrace.o := -I$(src)
24 24
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index 0bc962217351..575d1bb8e8cc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -934,57 +934,6 @@ u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
934 return ant; 934 return ant;
935} 935}
936 936
937/* notification wait support */
938void iwlagn_init_notification_wait(struct iwl_priv *priv,
939 struct iwl_notification_wait *wait_entry,
940 u8 cmd,
941 void (*fn)(struct iwl_priv *priv,
942 struct iwl_rx_packet *pkt,
943 void *data),
944 void *fn_data)
945{
946 wait_entry->fn = fn;
947 wait_entry->fn_data = fn_data;
948 wait_entry->cmd = cmd;
949 wait_entry->triggered = false;
950 wait_entry->aborted = false;
951
952 spin_lock_bh(&priv->notif_wait_lock);
953 list_add(&wait_entry->list, &priv->notif_waits);
954 spin_unlock_bh(&priv->notif_wait_lock);
955}
956
957int iwlagn_wait_notification(struct iwl_priv *priv,
958 struct iwl_notification_wait *wait_entry,
959 unsigned long timeout)
960{
961 int ret;
962
963 ret = wait_event_timeout(priv->notif_waitq,
964 wait_entry->triggered || wait_entry->aborted,
965 timeout);
966
967 spin_lock_bh(&priv->notif_wait_lock);
968 list_del(&wait_entry->list);
969 spin_unlock_bh(&priv->notif_wait_lock);
970
971 if (wait_entry->aborted)
972 return -EIO;
973
974 /* return value is always >= 0 */
975 if (ret <= 0)
976 return -ETIMEDOUT;
977 return 0;
978}
979
980void iwlagn_remove_notification(struct iwl_priv *priv,
981 struct iwl_notification_wait *wait_entry)
982{
983 spin_lock_bh(&priv->notif_wait_lock);
984 list_del(&wait_entry->list);
985 spin_unlock_bh(&priv->notif_wait_lock);
986}
987
988#ifdef CONFIG_PM_SLEEP 937#ifdef CONFIG_PM_SLEEP
989static void iwlagn_convert_p1k(u16 *p1k, __le16 *out) 938static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
990{ 939{
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c b/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
index 087fd52e5727..90c55ea4cc39 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
@@ -1131,9 +1131,9 @@ void iwl_setup_rx_handlers(struct iwl_priv *priv)
1131 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; 1131 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
1132 1132
1133 /* set up notification wait support */ 1133 /* set up notification wait support */
1134 spin_lock_init(&priv->notif_wait_lock); 1134 spin_lock_init(&priv->shrd->notif_wait_lock);
1135 INIT_LIST_HEAD(&priv->notif_waits); 1135 INIT_LIST_HEAD(&priv->shrd->notif_waits);
1136 init_waitqueue_head(&priv->notif_waitq); 1136 init_waitqueue_head(&priv->shrd->notif_waitq);
1137 1137
1138 /* Set up BT Rx handlers */ 1138 /* Set up BT Rx handlers */
1139 if (priv->cfg->lib->bt_rx_handler_setup) 1139 if (priv->cfg->lib->bt_rx_handler_setup)
@@ -1152,11 +1152,11 @@ int iwl_rx_dispatch(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
1152 * even if the RX handler consumes the RXB we have 1152 * even if the RX handler consumes the RXB we have
1153 * access to it in the notification wait entry. 1153 * access to it in the notification wait entry.
1154 */ 1154 */
1155 if (!list_empty(&priv->notif_waits)) { 1155 if (!list_empty(&priv->shrd->notif_waits)) {
1156 struct iwl_notification_wait *w; 1156 struct iwl_notification_wait *w;
1157 1157
1158 spin_lock(&priv->notif_wait_lock); 1158 spin_lock(&priv->shrd->notif_wait_lock);
1159 list_for_each_entry(w, &priv->notif_waits, list) { 1159 list_for_each_entry(w, &priv->shrd->notif_waits, list) {
1160 if (w->cmd != pkt->hdr.cmd) 1160 if (w->cmd != pkt->hdr.cmd)
1161 continue; 1161 continue;
1162 IWL_DEBUG_RX(priv, 1162 IWL_DEBUG_RX(priv,
@@ -1167,9 +1167,9 @@ int iwl_rx_dispatch(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb,
1167 if (w->fn) 1167 if (w->fn)
1168 w->fn(priv, pkt, w->fn_data); 1168 w->fn(priv, pkt, w->fn_data);
1169 } 1169 }
1170 spin_unlock(&priv->notif_wait_lock); 1170 spin_unlock(&priv->shrd->notif_wait_lock);
1171 1171
1172 wake_up_all(&priv->notif_waitq); 1172 wake_up_all(&priv->shrd->notif_waitq);
1173 } 1173 }
1174 1174
1175 if (priv->pre_rx_handler) 1175 if (priv->pre_rx_handler)
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
index 00b38711c15d..466e4ab544f7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
@@ -60,7 +60,7 @@ static int iwlagn_disable_pan(struct iwl_priv *priv,
60 u8 old_dev_type = send->dev_type; 60 u8 old_dev_type = send->dev_type;
61 int ret; 61 int ret;
62 62
63 iwlagn_init_notification_wait(priv, &disable_wait, 63 iwl_init_notification_wait(priv->shrd, &disable_wait,
64 REPLY_WIPAN_DEACTIVATION_COMPLETE, 64 REPLY_WIPAN_DEACTIVATION_COMPLETE,
65 NULL, NULL); 65 NULL, NULL);
66 66
@@ -74,9 +74,9 @@ static int iwlagn_disable_pan(struct iwl_priv *priv,
74 74
75 if (ret) { 75 if (ret) {
76 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); 76 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
77 iwlagn_remove_notification(priv, &disable_wait); 77 iwl_remove_notification(priv->shrd, &disable_wait);
78 } else { 78 } else {
79 ret = iwlagn_wait_notification(priv, &disable_wait, HZ); 79 ret = iwl_wait_notification(priv->shrd, &disable_wait, HZ);
80 if (ret) 80 if (ret)
81 IWL_ERR(priv, "Timed out waiting for PAN disable\n"); 81 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
82 } 82 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 4d20be9dea39..daf010dad70c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1232,14 +1232,14 @@ int iwl_alive_start(struct iwl_priv *priv)
1232 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS; 1232 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
1233 priv->cur_rssi_ctx = NULL; 1233 priv->cur_rssi_ctx = NULL;
1234 1234
1235 iwlagn_send_prio_tbl(priv); 1235 iwl_send_prio_tbl(trans(priv));
1236 1236
1237 /* FIXME: w/a to force change uCode BT state machine */ 1237 /* FIXME: w/a to force change uCode BT state machine */
1238 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, 1238 ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_OPEN,
1239 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 1239 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
1240 if (ret) 1240 if (ret)
1241 return ret; 1241 return ret;
1242 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE, 1242 ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_CLOSE,
1243 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 1243 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
1244 if (ret) 1244 if (ret)
1245 return ret; 1245 return ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h
index 2f446a353514..f2f10702754d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
@@ -108,8 +108,8 @@ void iwlagn_config_ht40(struct ieee80211_conf *conf,
108int iwlagn_rx_calib_result(struct iwl_priv *priv, 108int iwlagn_rx_calib_result(struct iwl_priv *priv,
109 struct iwl_rx_mem_buffer *rxb, 109 struct iwl_rx_mem_buffer *rxb,
110 struct iwl_device_cmd *cmd); 110 struct iwl_device_cmd *cmd);
111int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type); 111int iwl_send_bt_env(struct iwl_trans *trans, u8 action, u8 type);
112void iwlagn_send_prio_tbl(struct iwl_priv *priv); 112void iwl_send_prio_tbl(struct iwl_trans *trans);
113int iwlagn_run_init_ucode(struct iwl_priv *priv); 113int iwlagn_run_init_ucode(struct iwl_priv *priv);
114int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv, 114int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
115 enum iwl_ucode_type ucode_type); 115 enum iwl_ucode_type ucode_type);
@@ -356,22 +356,6 @@ static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
356void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv); 356void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv);
357void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac); 357void iwl_eeprom_get_mac(const struct iwl_priv *priv, u8 *mac);
358 358
359/* notification wait support */
360void __acquires(wait_entry)
361iwlagn_init_notification_wait(struct iwl_priv *priv,
362 struct iwl_notification_wait *wait_entry,
363 u8 cmd,
364 void (*fn)(struct iwl_priv *priv,
365 struct iwl_rx_packet *pkt,
366 void *data),
367 void *fn_data);
368int __must_check __releases(wait_entry)
369iwlagn_wait_notification(struct iwl_priv *priv,
370 struct iwl_notification_wait *wait_entry,
371 unsigned long timeout);
372void __releases(wait_entry)
373iwlagn_remove_notification(struct iwl_priv *priv,
374 struct iwl_notification_wait *wait_entry);
375extern int iwlagn_init_alive_start(struct iwl_priv *priv); 359extern int iwlagn_init_alive_start(struct iwl_priv *priv);
376extern int iwl_alive_start(struct iwl_priv *priv); 360extern int iwl_alive_start(struct iwl_priv *priv);
377/* svtool */ 361/* svtool */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index b24623b3bdb3..3b6f48bfe0e3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -836,19 +836,6 @@ void iwl_print_rx_config_cmd(struct iwl_priv *priv,
836} 836}
837#endif 837#endif
838 838
839static void iwlagn_abort_notification_waits(struct iwl_priv *priv)
840{
841 unsigned long flags;
842 struct iwl_notification_wait *wait_entry;
843
844 spin_lock_irqsave(&priv->notif_wait_lock, flags);
845 list_for_each_entry(wait_entry, &priv->notif_waits, list)
846 wait_entry->aborted = true;
847 spin_unlock_irqrestore(&priv->notif_wait_lock, flags);
848
849 wake_up_all(&priv->notif_waitq);
850}
851
852void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand) 839void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
853{ 840{
854 unsigned int reload_msec; 841 unsigned int reload_msec;
@@ -860,7 +847,7 @@ void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
860 /* Cancel currently queued command. */ 847 /* Cancel currently queued command. */
861 clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status); 848 clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
862 849
863 iwlagn_abort_notification_waits(priv); 850 iwl_abort_notification_waits(priv->shrd);
864 851
865 /* Keep the restart process from trying to send host 852 /* Keep the restart process from trying to send host
866 * commands by clearing the ready bit */ 853 * commands by clearing the ready bit */
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 44a7bdd7ccfd..f8fc2393dd4c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -134,48 +134,43 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
134 */ 134 */
135 135
136/* 0x0000000F - 0x00000001 */ 136/* 0x0000000F - 0x00000001 */
137#define IWL_DL_INFO (1 << 0) 137#define IWL_DL_INFO 0x00000001
138#define IWL_DL_MAC80211 (1 << 1) 138#define IWL_DL_MAC80211 0x00000002
139#define IWL_DL_HCMD (1 << 2) 139#define IWL_DL_HCMD 0x00000004
140#define IWL_DL_STATE (1 << 3) 140#define IWL_DL_STATE 0x00000008
141/* 0x000000F0 - 0x00000010 */ 141/* 0x000000F0 - 0x00000010 */
142#define IWL_DL_MACDUMP (1 << 4) 142#define IWL_DL_EEPROM 0x00000040
143#define IWL_DL_HCMD_DUMP (1 << 5) 143#define IWL_DL_RADIO 0x00000080
144#define IWL_DL_EEPROM (1 << 6)
145#define IWL_DL_RADIO (1 << 7)
146/* 0x00000F00 - 0x00000100 */ 144/* 0x00000F00 - 0x00000100 */
147#define IWL_DL_POWER (1 << 8) 145#define IWL_DL_POWER 0x00000100
148#define IWL_DL_TEMP (1 << 9) 146#define IWL_DL_TEMP 0x00000200
149/* reserved (1 << 10) */ 147#define IWL_DL_SCAN 0x00000800
150#define IWL_DL_SCAN (1 << 11)
151/* 0x0000F000 - 0x00001000 */ 148/* 0x0000F000 - 0x00001000 */
152#define IWL_DL_ASSOC (1 << 12) 149#define IWL_DL_ASSOC 0x00001000
153#define IWL_DL_DROP (1 << 13) 150#define IWL_DL_DROP 0x00002000
154/* reserved (1 << 14) */ 151#define IWL_DL_COEX 0x00008000
155#define IWL_DL_COEX (1 << 15)
156/* 0x000F0000 - 0x00010000 */ 152/* 0x000F0000 - 0x00010000 */
157#define IWL_DL_FW (1 << 16) 153#define IWL_DL_FW 0x00010000
158#define IWL_DL_RF_KILL (1 << 17) 154#define IWL_DL_RF_KILL 0x00020000
159#define IWL_DL_FW_ERRORS (1 << 18) 155#define IWL_DL_FW_ERRORS 0x00040000
160#define IWL_DL_LED (1 << 19) 156#define IWL_DL_LED 0x00080000
161/* 0x00F00000 - 0x00100000 */ 157/* 0x00F00000 - 0x00100000 */
162#define IWL_DL_RATE (1 << 20) 158#define IWL_DL_RATE 0x00100000
163#define IWL_DL_CALIB (1 << 21) 159#define IWL_DL_CALIB 0x00200000
164#define IWL_DL_WEP (1 << 22) 160#define IWL_DL_WEP 0x00400000
165#define IWL_DL_TX (1 << 23) 161#define IWL_DL_TX 0x00800000
166/* 0x0F000000 - 0x01000000 */ 162/* 0x0F000000 - 0x01000000 */
167#define IWL_DL_RX (1 << 24) 163#define IWL_DL_RX 0x01000000
168#define IWL_DL_ISR (1 << 25) 164#define IWL_DL_ISR 0x02000000
169#define IWL_DL_HT (1 << 26) 165#define IWL_DL_HT 0x04000000
170/* 0xF0000000 - 0x10000000 */ 166/* 0xF0000000 - 0x10000000 */
171#define IWL_DL_11H (1 << 28) 167#define IWL_DL_11H 0x10000000
172#define IWL_DL_STATS (1 << 29) 168#define IWL_DL_STATS 0x20000000
173#define IWL_DL_TX_REPLY (1 << 30) 169#define IWL_DL_TX_REPLY 0x40000000
174#define IWL_DL_TX_QUEUES (1 << 31) 170#define IWL_DL_TX_QUEUES 0x80000000
175 171
176#define IWL_DEBUG_INFO(p, f, a...) IWL_DEBUG(p, IWL_DL_INFO, f, ## a) 172#define IWL_DEBUG_INFO(p, f, a...) IWL_DEBUG(p, IWL_DL_INFO, f, ## a)
177#define IWL_DEBUG_MAC80211(p, f, a...) IWL_DEBUG(p, IWL_DL_MAC80211, f, ## a) 173#define IWL_DEBUG_MAC80211(p, f, a...) IWL_DEBUG(p, IWL_DL_MAC80211, f, ## a)
178#define IWL_DEBUG_MACDUMP(p, f, a...) IWL_DEBUG(p, IWL_DL_MACDUMP, f, ## a)
179#define IWL_DEBUG_TEMP(p, f, a...) IWL_DEBUG(p, IWL_DL_TEMP, f, ## a) 174#define IWL_DEBUG_TEMP(p, f, a...) IWL_DEBUG(p, IWL_DL_TEMP, f, ## a)
180#define IWL_DEBUG_SCAN(p, f, a...) IWL_DEBUG(p, IWL_DL_SCAN, f, ## a) 175#define IWL_DEBUG_SCAN(p, f, a...) IWL_DEBUG(p, IWL_DL_SCAN, f, ## a)
181#define IWL_DEBUG_RX(p, f, a...) IWL_DEBUG(p, IWL_DL_RX, f, ## a) 176#define IWL_DEBUG_RX(p, f, a...) IWL_DEBUG(p, IWL_DL_RX, f, ## a)
@@ -184,7 +179,6 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
184#define IWL_DEBUG_LED(p, f, a...) IWL_DEBUG(p, IWL_DL_LED, f, ## a) 179#define IWL_DEBUG_LED(p, f, a...) IWL_DEBUG(p, IWL_DL_LED, f, ## a)
185#define IWL_DEBUG_WEP(p, f, a...) IWL_DEBUG(p, IWL_DL_WEP, f, ## a) 180#define IWL_DEBUG_WEP(p, f, a...) IWL_DEBUG(p, IWL_DL_WEP, f, ## a)
186#define IWL_DEBUG_HC(p, f, a...) IWL_DEBUG(p, IWL_DL_HCMD, f, ## a) 181#define IWL_DEBUG_HC(p, f, a...) IWL_DEBUG(p, IWL_DL_HCMD, f, ## a)
187#define IWL_DEBUG_HC_DUMP(p, f, a...) IWL_DEBUG(p, IWL_DL_HCMD_DUMP, f, ## a)
188#define IWL_DEBUG_EEPROM(p, f, a...) IWL_DEBUG(p, IWL_DL_EEPROM, f, ## a) 182#define IWL_DEBUG_EEPROM(p, f, a...) IWL_DEBUG(p, IWL_DL_EEPROM, f, ## a)
189#define IWL_DEBUG_CALIB(p, f, a...) IWL_DEBUG(p, IWL_DL_CALIB, f, ## a) 183#define IWL_DEBUG_CALIB(p, f, a...) IWL_DEBUG(p, IWL_DL_CALIB, f, ## a)
190#define IWL_DEBUG_FW(p, f, a...) IWL_DEBUG(p, IWL_DL_FW, f, ## a) 184#define IWL_DEBUG_FW(p, f, a...) IWL_DEBUG(p, IWL_DL_FW, f, ## a)
@@ -206,8 +200,6 @@ static inline void iwl_dbgfs_unregister(struct iwl_priv *priv)
206#define IWL_DEBUG_STATS_LIMIT(p, f, a...) \ 200#define IWL_DEBUG_STATS_LIMIT(p, f, a...) \
207 IWL_DEBUG_LIMIT(p, IWL_DL_STATS, f, ## a) 201 IWL_DEBUG_LIMIT(p, IWL_DL_STATS, f, ## a)
208#define IWL_DEBUG_TX_REPLY(p, f, a...) IWL_DEBUG(p, IWL_DL_TX_REPLY, f, ## a) 202#define IWL_DEBUG_TX_REPLY(p, f, a...) IWL_DEBUG(p, IWL_DL_TX_REPLY, f, ## a)
209#define IWL_DEBUG_TX_REPLY_LIMIT(p, f, a...) \
210 IWL_DEBUG_LIMIT(p, IWL_DL_TX_REPLY, f, ## a)
211#define IWL_DEBUG_TX_QUEUES(p, f, a...) IWL_DEBUG(p, IWL_DL_TX_QUEUES, f, ## a) 203#define IWL_DEBUG_TX_QUEUES(p, f, a...) IWL_DEBUG(p, IWL_DL_TX_QUEUES, f, ## a)
212#define IWL_DEBUG_RADIO(p, f, a...) IWL_DEBUG(p, IWL_DL_RADIO, f, ## a) 204#define IWL_DEBUG_RADIO(p, f, a...) IWL_DEBUG(p, IWL_DL_RADIO, f, ## a)
213#define IWL_DEBUG_POWER(p, f, a...) IWL_DEBUG(p, IWL_DL_POWER, f, ## a) 205#define IWL_DEBUG_POWER(p, f, a...) IWL_DEBUG(p, IWL_DL_POWER, f, ## a)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index 68b04f5b10ce..ccbcab40e78f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -234,11 +234,12 @@ static ssize_t iwl_dbgfs_sram_read(struct file *file,
234 234
235 /* default is to dump the entire data segment */ 235 /* default is to dump the entire data segment */
236 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) { 236 if (!priv->dbgfs_sram_offset && !priv->dbgfs_sram_len) {
237 struct iwl_trans *trans = trans(priv);
237 priv->dbgfs_sram_offset = 0x800000; 238 priv->dbgfs_sram_offset = 0x800000;
238 if (priv->ucode_type == IWL_UCODE_INIT) 239 if (trans->shrd->ucode_type == IWL_UCODE_INIT)
239 priv->dbgfs_sram_len = trans(priv)->ucode_init.data.len; 240 priv->dbgfs_sram_len = trans->ucode_init.data.len;
240 else 241 else
241 priv->dbgfs_sram_len = trans(priv)->ucode_rt.data.len; 242 priv->dbgfs_sram_len = trans->ucode_rt.data.len;
242 } 243 }
243 len = priv->dbgfs_sram_len; 244 len = priv->dbgfs_sram_len;
244 245
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 0c95ad3048a0..6f6a647d34f6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -689,35 +689,6 @@ struct iwl_force_reset {
689 */ 689 */
690#define IWLAGN_EXT_BEACON_TIME_POS 22 690#define IWLAGN_EXT_BEACON_TIME_POS 22
691 691
692/**
693 * struct iwl_notification_wait - notification wait entry
694 * @list: list head for global list
695 * @fn: function called with the notification
696 * @cmd: command ID
697 *
698 * This structure is not used directly, to wait for a
699 * notification declare it on the stack, and call
700 * iwlagn_init_notification_wait() with appropriate
701 * parameters. Then do whatever will cause the ucode
702 * to notify the driver, and to wait for that then
703 * call iwlagn_wait_notification().
704 *
705 * Each notification is one-shot. If at some point we
706 * need to support multi-shot notifications (which
707 * can't be allocated on the stack) we need to modify
708 * the code for them.
709 */
710struct iwl_notification_wait {
711 struct list_head list;
712
713 void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
714 void *data);
715 void *fn_data;
716
717 u8 cmd;
718 bool triggered, aborted;
719};
720
721struct iwl_rxon_context { 692struct iwl_rxon_context {
722 struct ieee80211_vif *vif; 693 struct ieee80211_vif *vif;
723 694
@@ -790,6 +761,12 @@ struct iwl_testmode_trace {
790 dma_addr_t dma_addr; 761 dma_addr_t dma_addr;
791 bool trace_enabled; 762 bool trace_enabled;
792}; 763};
764struct iwl_testmode_sram {
765 u32 buff_size;
766 u32 num_chunks;
767 u8 *buff_addr;
768 bool sram_readed;
769};
793#endif 770#endif
794 771
795struct iwl_wipan_noa_data { 772struct iwl_wipan_noa_data {
@@ -883,7 +860,6 @@ struct iwl_priv {
883 u32 ucode_ver; /* version of ucode, copy of 860 u32 ucode_ver; /* version of ucode, copy of
884 iwl_ucode.ver */ 861 iwl_ucode.ver */
885 862
886 enum iwl_ucode_type ucode_type;
887 char firmware_name[25]; 863 char firmware_name[25];
888 864
889 struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX]; 865 struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
@@ -987,10 +963,6 @@ struct iwl_priv {
987 /* counts reply_tx error */ 963 /* counts reply_tx error */
988 struct reply_tx_error_statistics reply_tx_stats; 964 struct reply_tx_error_statistics reply_tx_stats;
989 struct reply_agg_tx_error_statistics reply_agg_tx_stats; 965 struct reply_agg_tx_error_statistics reply_agg_tx_stats;
990 /* notification wait support */
991 struct list_head notif_waits;
992 spinlock_t notif_wait_lock;
993 wait_queue_head_t notif_waitq;
994 966
995 /* remain-on-channel offload support */ 967 /* remain-on-channel offload support */
996 struct ieee80211_channel *hw_roc_channel; 968 struct ieee80211_channel *hw_roc_channel;
@@ -1070,6 +1042,7 @@ struct iwl_priv {
1070 bool led_registered; 1042 bool led_registered;
1071#ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL 1043#ifdef CONFIG_IWLWIFI_DEVICE_SVTOOL
1072 struct iwl_testmode_trace testmode_trace; 1044 struct iwl_testmode_trace testmode_trace;
1045 struct iwl_testmode_sram testmode_sram;
1073 u32 tm_fixed_rate; 1046 u32 tm_fixed_rate;
1074#endif 1047#endif
1075 1048
diff --git a/drivers/net/wireless/iwlwifi/iwl-mac80211.c b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
index 05b1f0d2f387..55308b88faac 100644
--- a/drivers/net/wireless/iwlwifi/iwl-mac80211.c
+++ b/drivers/net/wireless/iwlwifi/iwl-mac80211.c
@@ -481,15 +481,11 @@ static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
481{ 481{
482 struct iwl_priv *priv = hw->priv; 482 struct iwl_priv *priv = hw->priv;
483 483
484 IWL_DEBUG_MACDUMP(priv, "enter\n");
485
486 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, 484 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
487 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); 485 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
488 486
489 if (iwlagn_tx_skb(priv, skb)) 487 if (iwlagn_tx_skb(priv, skb))
490 dev_kfree_skb_any(skb); 488 dev_kfree_skb_any(skb);
491
492 IWL_DEBUG_MACDUMP(priv, "leave\n");
493} 489}
494 490
495static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw, 491static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
@@ -521,6 +517,17 @@ static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
521 return -EOPNOTSUPP; 517 return -EOPNOTSUPP;
522 } 518 }
523 519
520 switch (key->cipher) {
521 case WLAN_CIPHER_SUITE_TKIP:
522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
523 /* fall through */
524 case WLAN_CIPHER_SUITE_CCMP:
525 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
526 break;
527 default:
528 break;
529 }
530
524 /* 531 /*
525 * We could program these keys into the hardware as well, but we 532 * We could program these keys into the hardware as well, but we
526 * don't expect much multicast traffic in IBSS and having keys 533 * don't expect much multicast traffic in IBSS and having keys
diff --git a/drivers/net/wireless/iwlwifi/iwl-shared.h b/drivers/net/wireless/iwlwifi/iwl-shared.h
index 30af95b19f78..39aa9cf5b847 100644
--- a/drivers/net/wireless/iwlwifi/iwl-shared.h
+++ b/drivers/net/wireless/iwlwifi/iwl-shared.h
@@ -257,6 +257,52 @@ struct iwl_tid_data {
257}; 257};
258 258
259/** 259/**
260 * enum iwl_ucode_type
261 *
262 * The type of ucode currently loaded on the hardware.
263 *
264 * @IWL_UCODE_NONE: No ucode loaded
265 * @IWL_UCODE_REGULAR: Normal runtime ucode
266 * @IWL_UCODE_INIT: Initial ucode
267 * @IWL_UCODE_WOWLAN: Wake on Wireless enabled ucode
268 */
269enum iwl_ucode_type {
270 IWL_UCODE_NONE,
271 IWL_UCODE_REGULAR,
272 IWL_UCODE_INIT,
273 IWL_UCODE_WOWLAN,
274};
275
276/**
277 * struct iwl_notification_wait - notification wait entry
278 * @list: list head for global list
279 * @fn: function called with the notification
280 * @cmd: command ID
281 *
282 * This structure is not used directly, to wait for a
283 * notification declare it on the stack, and call
284 * iwlagn_init_notification_wait() with appropriate
285 * parameters. Then do whatever will cause the ucode
286 * to notify the driver, and to wait for that then
287 * call iwlagn_wait_notification().
288 *
289 * Each notification is one-shot. If at some point we
290 * need to support multi-shot notifications (which
291 * can't be allocated on the stack) we need to modify
292 * the code for them.
293 */
294struct iwl_notification_wait {
295 struct list_head list;
296
297 void (*fn)(struct iwl_priv *priv, struct iwl_rx_packet *pkt,
298 void *data);
299 void *fn_data;
300
301 u8 cmd;
302 bool triggered, aborted;
303};
304
305/**
260 * struct iwl_shared - shared fields for all the layers of the driver 306 * struct iwl_shared - shared fields for all the layers of the driver
261 * 307 *
262 * @dbg_level_dev: dbg level set per device. Prevails on 308 * @dbg_level_dev: dbg level set per device. Prevails on
@@ -273,6 +319,10 @@ struct iwl_tid_data {
273 * @sta_lock: protects the station table. 319 * @sta_lock: protects the station table.
274 * If lock and sta_lock are needed, lock must be acquired first. 320 * If lock and sta_lock are needed, lock must be acquired first.
275 * @mutex: 321 * @mutex:
322 * @ucode_type: indicator of loaded ucode image
323 * @notif_waits: things waiting for notification
324 * @notif_wait_lock: lock protecting notification
325 * @notif_waitq: head of notification wait queue
276 */ 326 */
277struct iwl_shared { 327struct iwl_shared {
278#ifdef CONFIG_IWLWIFI_DEBUG 328#ifdef CONFIG_IWLWIFI_DEBUG
@@ -300,6 +350,14 @@ struct iwl_shared {
300 struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT]; 350 struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
301 351
302 wait_queue_head_t wait_command_queue; 352 wait_queue_head_t wait_command_queue;
353
354 /* ucode related variables */
355 enum iwl_ucode_type ucode_type;
356
357 /* notification wait support */
358 struct list_head notif_waits;
359 spinlock_t notif_wait_lock;
360 wait_queue_head_t notif_waitq;
303}; 361};
304 362
305/*Whatever _m is (iwl_trans, iwl_priv, iwl_bus, these macros will work */ 363/*Whatever _m is (iwl_trans, iwl_priv, iwl_bus, these macros will work */
@@ -443,6 +501,24 @@ bool iwl_check_for_ct_kill(struct iwl_priv *priv);
443void iwl_stop_sw_queue(struct iwl_priv *priv, u8 ac); 501void iwl_stop_sw_queue(struct iwl_priv *priv, u8 ac);
444void iwl_wake_sw_queue(struct iwl_priv *priv, u8 ac); 502void iwl_wake_sw_queue(struct iwl_priv *priv, u8 ac);
445 503
504/* notification wait support */
505void iwl_abort_notification_waits(struct iwl_shared *shrd);
506void __acquires(wait_entry)
507iwl_init_notification_wait(struct iwl_shared *shrd,
508 struct iwl_notification_wait *wait_entry,
509 u8 cmd,
510 void (*fn)(struct iwl_priv *priv,
511 struct iwl_rx_packet *pkt,
512 void *data),
513 void *fn_data);
514int __must_check __releases(wait_entry)
515iwl_wait_notification(struct iwl_shared *shrd,
516 struct iwl_notification_wait *wait_entry,
517 unsigned long timeout);
518void __releases(wait_entry)
519iwl_remove_notification(struct iwl_shared *shrd,
520 struct iwl_notification_wait *wait_entry);
521
446#ifdef CONFIG_IWLWIFI_DEBUGFS 522#ifdef CONFIG_IWLWIFI_DEBUGFS
447void iwl_reset_traffic_log(struct iwl_priv *priv); 523void iwl_reset_traffic_log(struct iwl_priv *priv);
448#endif /* CONFIG_IWLWIFI_DEBUGFS */ 524#endif /* CONFIG_IWLWIFI_DEBUGFS */
diff --git a/drivers/net/wireless/iwlwifi/iwl-sv-open.c b/drivers/net/wireless/iwlwifi/iwl-testmode.c
index be16cafbbc27..ff72dbcfd52d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sv-open.c
+++ b/drivers/net/wireless/iwlwifi/iwl-testmode.c
@@ -106,6 +106,10 @@ struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
106 [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, }, 106 [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, },
107 107
108 [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, }, 108 [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, },
109
110 [IWL_TM_ATTR_SRAM_ADDR] = { .type = NLA_U32, },
111 [IWL_TM_ATTR_SRAM_SIZE] = { .type = NLA_U32, },
112 [IWL_TM_ATTR_SRAM_DUMP] = { .type = NLA_UNSPEC, },
109}; 113};
110 114
111/* 115/*
@@ -177,6 +181,18 @@ void iwl_testmode_init(struct iwl_priv *priv)
177{ 181{
178 priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt; 182 priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
179 priv->testmode_trace.trace_enabled = false; 183 priv->testmode_trace.trace_enabled = false;
184 priv->testmode_sram.sram_readed = false;
185}
186
187static void iwl_sram_cleanup(struct iwl_priv *priv)
188{
189 if (priv->testmode_sram.sram_readed) {
190 kfree(priv->testmode_sram.buff_addr);
191 priv->testmode_sram.buff_addr = NULL;
192 priv->testmode_sram.buff_size = 0;
193 priv->testmode_sram.num_chunks = 0;
194 priv->testmode_sram.sram_readed = false;
195 }
180} 196}
181 197
182static void iwl_trace_cleanup(struct iwl_priv *priv) 198static void iwl_trace_cleanup(struct iwl_priv *priv)
@@ -201,6 +217,7 @@ static void iwl_trace_cleanup(struct iwl_priv *priv)
201void iwl_testmode_cleanup(struct iwl_priv *priv) 217void iwl_testmode_cleanup(struct iwl_priv *priv)
202{ 218{
203 iwl_trace_cleanup(priv); 219 iwl_trace_cleanup(priv);
220 iwl_sram_cleanup(priv);
204} 221}
205 222
206/* 223/*
@@ -356,7 +373,7 @@ static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
356 struct iwl_notification_wait calib_wait; 373 struct iwl_notification_wait calib_wait;
357 int ret; 374 int ret;
358 375
359 iwlagn_init_notification_wait(priv, &calib_wait, 376 iwl_init_notification_wait(priv->shrd, &calib_wait,
360 CALIBRATION_COMPLETE_NOTIFICATION, 377 CALIBRATION_COMPLETE_NOTIFICATION,
361 NULL, NULL); 378 NULL, NULL);
362 ret = iwlagn_init_alive_start(priv); 379 ret = iwlagn_init_alive_start(priv);
@@ -366,14 +383,14 @@ static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
366 goto cfg_init_calib_error; 383 goto cfg_init_calib_error;
367 } 384 }
368 385
369 ret = iwlagn_wait_notification(priv, &calib_wait, 2 * HZ); 386 ret = iwl_wait_notification(priv->shrd, &calib_wait, 2 * HZ);
370 if (ret) 387 if (ret)
371 IWL_DEBUG_INFO(priv, "Error detecting" 388 IWL_DEBUG_INFO(priv, "Error detecting"
372 " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret); 389 " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
373 return ret; 390 return ret;
374 391
375cfg_init_calib_error: 392cfg_init_calib_error:
376 iwlagn_remove_notification(priv, &calib_wait); 393 iwl_remove_notification(priv->shrd, &calib_wait);
377 return ret; 394 return ret;
378} 395}
379 396
@@ -446,6 +463,21 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
446 "Error starting the device: %d\n", status); 463 "Error starting the device: %d\n", status);
447 break; 464 break;
448 465
466 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
467 iwl_scan_cancel_timeout(priv, 200);
468 iwl_trans_stop_device(trans(priv));
469 status = iwlagn_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
470 if (status) {
471 IWL_DEBUG_INFO(priv,
472 "Error loading WOWLAN ucode: %d\n", status);
473 break;
474 }
475 status = iwl_alive_start(priv);
476 if (status)
477 IWL_DEBUG_INFO(priv,
478 "Error starting the device: %d\n", status);
479 break;
480
449 case IWL_TM_CMD_APP2DEV_GET_EEPROM: 481 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
450 if (priv->eeprom) { 482 if (priv->eeprom) {
451 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 483 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
@@ -558,7 +590,7 @@ static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb)
558 } 590 }
559 priv->testmode_trace.num_chunks = 591 priv->testmode_trace.num_chunks =
560 DIV_ROUND_UP(priv->testmode_trace.buff_size, 592 DIV_ROUND_UP(priv->testmode_trace.buff_size,
561 TRACE_CHUNK_SIZE); 593 DUMP_CHUNK_SIZE);
562 break; 594 break;
563 595
564 case IWL_TM_CMD_APP2DEV_END_TRACE: 596 case IWL_TM_CMD_APP2DEV_END_TRACE:
@@ -590,15 +622,15 @@ static int iwl_testmode_trace_dump(struct ieee80211_hw *hw, struct nlattr **tb,
590 idx = cb->args[4]; 622 idx = cb->args[4];
591 if (idx >= priv->testmode_trace.num_chunks) 623 if (idx >= priv->testmode_trace.num_chunks)
592 return -ENOENT; 624 return -ENOENT;
593 length = TRACE_CHUNK_SIZE; 625 length = DUMP_CHUNK_SIZE;
594 if (((idx + 1) == priv->testmode_trace.num_chunks) && 626 if (((idx + 1) == priv->testmode_trace.num_chunks) &&
595 (priv->testmode_trace.buff_size % TRACE_CHUNK_SIZE)) 627 (priv->testmode_trace.buff_size % DUMP_CHUNK_SIZE))
596 length = priv->testmode_trace.buff_size % 628 length = priv->testmode_trace.buff_size %
597 TRACE_CHUNK_SIZE; 629 DUMP_CHUNK_SIZE;
598 630
599 NLA_PUT(skb, IWL_TM_ATTR_TRACE_DUMP, length, 631 NLA_PUT(skb, IWL_TM_ATTR_TRACE_DUMP, length,
600 priv->testmode_trace.trace_addr + 632 priv->testmode_trace.trace_addr +
601 (TRACE_CHUNK_SIZE * idx)); 633 (DUMP_CHUNK_SIZE * idx));
602 idx++; 634 idx++;
603 cb->args[4] = idx; 635 cb->args[4] = idx;
604 return 0; 636 return 0;
@@ -644,6 +676,110 @@ static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb)
644 return 0; 676 return 0;
645} 677}
646 678
679/*
680 * This function handles the user application commands for SRAM data dump
681 *
682 * It retrieves the mandatory fields IWL_TM_ATTR_SRAM_ADDR and
683 * IWL_TM_ATTR_SRAM_SIZE to decide the memory area for SRAM data reading
684 *
685 * Several error will be retured, -EBUSY if the SRAM data retrieved by
686 * previous command has not been delivered to userspace, or -ENOMSG if
687 * the mandatory fields (IWL_TM_ATTR_SRAM_ADDR,IWL_TM_ATTR_SRAM_SIZE)
688 * are missing, or -ENOMEM if the buffer allocation fails.
689 *
690 * Otherwise 0 is replied indicating the success of the SRAM reading.
691 *
692 * @hw: ieee80211_hw object that represents the device
693 * @tb: gnl message fields from the user space
694 */
695static int iwl_testmode_sram(struct ieee80211_hw *hw, struct nlattr **tb)
696{
697 struct iwl_priv *priv = hw->priv;
698 u32 base, ofs, size, maxsize;
699
700 if (priv->testmode_sram.sram_readed)
701 return -EBUSY;
702
703 if (!tb[IWL_TM_ATTR_SRAM_ADDR]) {
704 IWL_DEBUG_INFO(priv, "Error finding SRAM offset address\n");
705 return -ENOMSG;
706 }
707 ofs = nla_get_u32(tb[IWL_TM_ATTR_SRAM_ADDR]);
708 if (!tb[IWL_TM_ATTR_SRAM_SIZE]) {
709 IWL_DEBUG_INFO(priv, "Error finding size for SRAM reading\n");
710 return -ENOMSG;
711 }
712 size = nla_get_u32(tb[IWL_TM_ATTR_SRAM_SIZE]);
713 switch (priv->shrd->ucode_type) {
714 case IWL_UCODE_REGULAR:
715 maxsize = trans(priv)->ucode_rt.data.len;
716 break;
717 case IWL_UCODE_INIT:
718 maxsize = trans(priv)->ucode_init.data.len;
719 break;
720 case IWL_UCODE_WOWLAN:
721 maxsize = trans(priv)->ucode_wowlan.data.len;
722 break;
723 case IWL_UCODE_NONE:
724 IWL_DEBUG_INFO(priv, "Error, uCode does not been loaded\n");
725 return -ENOSYS;
726 default:
727 IWL_DEBUG_INFO(priv, "Error, unsupported uCode type\n");
728 return -ENOSYS;
729 }
730 if ((ofs + size) > maxsize) {
731 IWL_DEBUG_INFO(priv, "Invalid offset/size: out of range\n");
732 return -EINVAL;
733 }
734 priv->testmode_sram.buff_size = (size / 4) * 4;
735 priv->testmode_sram.buff_addr =
736 kmalloc(priv->testmode_sram.buff_size, GFP_KERNEL);
737 if (priv->testmode_sram.buff_addr == NULL) {
738 IWL_DEBUG_INFO(priv, "Error allocating memory\n");
739 return -ENOMEM;
740 }
741 base = 0x800000;
742 _iwl_read_targ_mem_words(bus(priv), base + ofs,
743 priv->testmode_sram.buff_addr,
744 priv->testmode_sram.buff_size / 4);
745 priv->testmode_sram.num_chunks =
746 DIV_ROUND_UP(priv->testmode_sram.buff_size, DUMP_CHUNK_SIZE);
747 priv->testmode_sram.sram_readed = true;
748 return 0;
749}
750
751static int iwl_testmode_sram_dump(struct ieee80211_hw *hw, struct nlattr **tb,
752 struct sk_buff *skb,
753 struct netlink_callback *cb)
754{
755 struct iwl_priv *priv = hw->priv;
756 int idx, length;
757
758 if (priv->testmode_sram.sram_readed) {
759 idx = cb->args[4];
760 if (idx >= priv->testmode_sram.num_chunks) {
761 iwl_sram_cleanup(priv);
762 return -ENOENT;
763 }
764 length = DUMP_CHUNK_SIZE;
765 if (((idx + 1) == priv->testmode_sram.num_chunks) &&
766 (priv->testmode_sram.buff_size % DUMP_CHUNK_SIZE))
767 length = priv->testmode_sram.buff_size %
768 DUMP_CHUNK_SIZE;
769
770 NLA_PUT(skb, IWL_TM_ATTR_SRAM_DUMP, length,
771 priv->testmode_sram.buff_addr +
772 (DUMP_CHUNK_SIZE * idx));
773 idx++;
774 cb->args[4] = idx;
775 return 0;
776 } else
777 return -EFAULT;
778
779 nla_put_failure:
780 return -ENOBUFS;
781}
782
647 783
648/* The testmode gnl message handler that takes the gnl message from the 784/* The testmode gnl message handler that takes the gnl message from the
649 * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then 785 * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
@@ -705,6 +841,7 @@ int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
705 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW: 841 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
706 case IWL_TM_CMD_APP2DEV_GET_EEPROM: 842 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
707 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ: 843 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
844 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
708 IWL_DEBUG_INFO(priv, "testmode cmd to driver\n"); 845 IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
709 result = iwl_testmode_driver(hw, tb); 846 result = iwl_testmode_driver(hw, tb);
710 break; 847 break;
@@ -721,6 +858,11 @@ int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
721 result = iwl_testmode_ownership(hw, tb); 858 result = iwl_testmode_ownership(hw, tb);
722 break; 859 break;
723 860
861 case IWL_TM_CMD_APP2DEV_READ_SRAM:
862 IWL_DEBUG_INFO(priv, "testmode sram read cmd to driver\n");
863 result = iwl_testmode_sram(hw, tb);
864 break;
865
724 default: 866 default:
725 IWL_DEBUG_INFO(priv, "Unknown testmode command\n"); 867 IWL_DEBUG_INFO(priv, "Unknown testmode command\n");
726 result = -ENOSYS; 868 result = -ENOSYS;
@@ -769,6 +911,10 @@ int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
769 IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n"); 911 IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n");
770 result = iwl_testmode_trace_dump(hw, tb, skb, cb); 912 result = iwl_testmode_trace_dump(hw, tb, skb, cb);
771 break; 913 break;
914 case IWL_TM_CMD_APP2DEV_DUMP_SRAM:
915 IWL_DEBUG_INFO(priv, "testmode sram dump cmd to driver\n");
916 result = iwl_testmode_sram_dump(hw, tb, skb, cb);
917 break;
772 default: 918 default:
773 result = -EINVAL; 919 result = -EINVAL;
774 break; 920 break;
diff --git a/drivers/net/wireless/iwlwifi/iwl-testmode.h b/drivers/net/wireless/iwlwifi/iwl-testmode.h
index 177964850b7c..deedd27c5f3d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-testmode.h
+++ b/drivers/net/wireless/iwlwifi/iwl-testmode.h
@@ -103,14 +103,22 @@
103 * @IWL_TM_CMD_DEV2APP_EEPROM_RSP: 103 * @IWL_TM_CMD_DEV2APP_EEPROM_RSP:
104 * commands from kernel space to carry the eeprom response 104 * commands from kernel space to carry the eeprom response
105 * to user application 105 * to user application
106 *
106 * @IWL_TM_CMD_APP2DEV_OWNERSHIP: 107 * @IWL_TM_CMD_APP2DEV_OWNERSHIP:
107 * commands from user application to own change the ownership of the uCode 108 * commands from user application to own change the ownership of the uCode
108 * if application has the ownership, the only host command from 109 * if application has the ownership, the only host command from
109 * testmode will deliver to uCode. Default owner is driver 110 * testmode will deliver to uCode. Default owner is driver
111 *
110 * @IWL_TM_CMD_APP2DEV_INDIRECT_REG_READ32: 112 * @IWL_TM_CMD_APP2DEV_INDIRECT_REG_READ32:
111 * @IWL_TM_CMD_APP2DEV_INDIRECT_REG_WRITE32: 113 * @IWL_TM_CMD_APP2DEV_INDIRECT_REG_WRITE32:
112 * commands from user applicaiton to indirectly access peripheral register 114 * commands from user applicaiton to indirectly access peripheral register
113 * 115 *
116 * @IWL_TM_CMD_APP2DEV_READ_SRAM:
117 * @IWL_TM_CMD_APP2DEV_DUMP_SRAM:
118 * commands from user applicaiton to read data in sram
119 *
120 * @IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW: load Weak On Wireless LAN uCode image
121 *
114 */ 122 */
115enum iwl_tm_cmd_t { 123enum iwl_tm_cmd_t {
116 IWL_TM_CMD_APP2DEV_UCODE = 1, 124 IWL_TM_CMD_APP2DEV_UCODE = 1,
@@ -132,7 +140,10 @@ enum iwl_tm_cmd_t {
132 IWL_TM_CMD_APP2DEV_OWNERSHIP = 17, 140 IWL_TM_CMD_APP2DEV_OWNERSHIP = 17,
133 IWL_TM_CMD_APP2DEV_INDIRECT_REG_READ32 = 18, 141 IWL_TM_CMD_APP2DEV_INDIRECT_REG_READ32 = 18,
134 IWL_TM_CMD_APP2DEV_INDIRECT_REG_WRITE32 = 19, 142 IWL_TM_CMD_APP2DEV_INDIRECT_REG_WRITE32 = 19,
135 IWL_TM_CMD_MAX = 20, 143 IWL_TM_CMD_APP2DEV_READ_SRAM = 20,
144 IWL_TM_CMD_APP2DEV_DUMP_SRAM = 21,
145 IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW = 22,
146 IWL_TM_CMD_MAX = 23,
136}; 147};
137 148
138/* 149/*
@@ -202,6 +213,18 @@ enum iwl_tm_cmd_t {
202 * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_OWNERSHIP, 213 * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_OWNERSHIP,
203 * The mandatory fields are: 214 * The mandatory fields are:
204 * IWL_TM_ATTR_UCODE_OWNER for the new owner 215 * IWL_TM_ATTR_UCODE_OWNER for the new owner
216 *
217 * @IWL_TM_ATTR_SRAM_ADDR:
218 * @IWL_TM_ATTR_SRAM_SIZE:
219 * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_READ_SRAM,
220 * The mandatory fields are:
221 * IWL_TM_ATTR_SRAM_ADDR for the address in sram
222 * IWL_TM_ATTR_SRAM_SIZE for the buffer size of data reading
223 *
224 * @IWL_TM_ATTR_SRAM_DUMP:
225 * When IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_DUMP_SRAM,
226 * IWL_TM_ATTR_SRAM_DUMP for the data in sram
227 *
205 */ 228 */
206enum iwl_tm_attr_t { 229enum iwl_tm_attr_t {
207 IWL_TM_ATTR_NOT_APPLICABLE = 0, 230 IWL_TM_ATTR_NOT_APPLICABLE = 0,
@@ -219,7 +242,10 @@ enum iwl_tm_attr_t {
219 IWL_TM_ATTR_TRACE_DUMP = 12, 242 IWL_TM_ATTR_TRACE_DUMP = 12,
220 IWL_TM_ATTR_FIXRATE = 13, 243 IWL_TM_ATTR_FIXRATE = 13,
221 IWL_TM_ATTR_UCODE_OWNER = 14, 244 IWL_TM_ATTR_UCODE_OWNER = 14,
222 IWL_TM_ATTR_MAX = 15, 245 IWL_TM_ATTR_SRAM_ADDR = 15,
246 IWL_TM_ATTR_SRAM_SIZE = 16,
247 IWL_TM_ATTR_SRAM_DUMP = 17,
248 IWL_TM_ATTR_MAX = 18,
223}; 249};
224 250
225/* uCode trace buffer */ 251/* uCode trace buffer */
@@ -227,6 +253,8 @@ enum iwl_tm_attr_t {
227#define TRACE_BUFF_SIZE_MIN 0x20000 253#define TRACE_BUFF_SIZE_MIN 0x20000
228#define TRACE_BUFF_SIZE_DEF TRACE_BUFF_SIZE_MIN 254#define TRACE_BUFF_SIZE_DEF TRACE_BUFF_SIZE_MIN
229#define TRACE_BUFF_PADD 0x2000 255#define TRACE_BUFF_PADD 0x2000
230#define TRACE_CHUNK_SIZE (PAGE_SIZE - 1024) 256
257/* Maximum data size of each dump it packet */
258#define DUMP_CHUNK_SIZE (PAGE_SIZE - 1024)
231 259
232#endif 260#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
index ee126f844a5c..becd92173ddd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
@@ -595,7 +595,7 @@ static void iwl_dump_nic_error_log(struct iwl_trans *trans)
595 IWL_TRANS_GET_PCIE_TRANS(trans); 595 IWL_TRANS_GET_PCIE_TRANS(trans);
596 596
597 base = priv->device_pointers.error_event_table; 597 base = priv->device_pointers.error_event_table;
598 if (priv->ucode_type == IWL_UCODE_INIT) { 598 if (trans->shrd->ucode_type == IWL_UCODE_INIT) {
599 if (!base) 599 if (!base)
600 base = priv->init_errlog_ptr; 600 base = priv->init_errlog_ptr;
601 } else { 601 } else {
@@ -607,7 +607,7 @@ static void iwl_dump_nic_error_log(struct iwl_trans *trans)
607 IWL_ERR(trans, 607 IWL_ERR(trans,
608 "Not valid error log pointer 0x%08X for %s uCode\n", 608 "Not valid error log pointer 0x%08X for %s uCode\n",
609 base, 609 base,
610 (priv->ucode_type == IWL_UCODE_INIT) 610 (trans->shrd->ucode_type == IWL_UCODE_INIT)
611 ? "Init" : "RT"); 611 ? "Init" : "RT");
612 return; 612 return;
613 } 613 }
@@ -710,7 +710,7 @@ static int iwl_print_event_log(struct iwl_trans *trans, u32 start_idx,
710 return pos; 710 return pos;
711 711
712 base = priv->device_pointers.log_event_table; 712 base = priv->device_pointers.log_event_table;
713 if (priv->ucode_type == IWL_UCODE_INIT) { 713 if (trans->shrd->ucode_type == IWL_UCODE_INIT) {
714 if (!base) 714 if (!base)
715 base = priv->init_evtlog_ptr; 715 base = priv->init_evtlog_ptr;
716 } else { 716 } else {
@@ -824,7 +824,7 @@ int iwl_dump_nic_event_log(struct iwl_trans *trans, bool full_log,
824 struct iwl_priv *priv = priv(trans); 824 struct iwl_priv *priv = priv(trans);
825 825
826 base = priv->device_pointers.log_event_table; 826 base = priv->device_pointers.log_event_table;
827 if (priv->ucode_type == IWL_UCODE_INIT) { 827 if (trans->shrd->ucode_type == IWL_UCODE_INIT) {
828 logsize = priv->init_evtlog_size; 828 logsize = priv->init_evtlog_size;
829 if (!base) 829 if (!base)
830 base = priv->init_evtlog_ptr; 830 base = priv->init_evtlog_ptr;
@@ -838,7 +838,7 @@ int iwl_dump_nic_event_log(struct iwl_trans *trans, bool full_log,
838 IWL_ERR(trans, 838 IWL_ERR(trans,
839 "Invalid event log pointer 0x%08X for %s uCode\n", 839 "Invalid event log pointer 0x%08X for %s uCode\n",
840 base, 840 base,
841 (priv->ucode_type == IWL_UCODE_INIT) 841 (trans->shrd->ucode_type == IWL_UCODE_INIT)
842 ? "Init" : "RT"); 842 ? "Init" : "RT");
843 return -EINVAL; 843 return -EINVAL;
844 } 844 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index 50227ebc0ee2..4a29b8ab998e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -220,13 +220,6 @@ struct fw_img {
220 struct fw_desc data; /* firmware data image */ 220 struct fw_desc data; /* firmware data image */
221}; 221};
222 222
223enum iwl_ucode_type {
224 IWL_UCODE_NONE,
225 IWL_UCODE_REGULAR,
226 IWL_UCODE_INIT,
227 IWL_UCODE_WOWLAN,
228};
229
230/** 223/**
231 * struct iwl_trans - transport common data 224 * struct iwl_trans - transport common data
232 * @ops - pointer to iwl_trans_ops 225 * @ops - pointer to iwl_trans_ops
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c b/drivers/net/wireless/iwlwifi/iwl-ucode.c
index 76949106dafc..b365de457b1b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
+++ b/drivers/net/wireless/iwlwifi/iwl-ucode.c
@@ -122,7 +122,7 @@ int iwl_alloc_fw_desc(struct iwl_bus *bus, struct fw_desc *desc,
122/* 122/*
123 * ucode 123 * ucode
124 */ 124 */
125static int iwlagn_load_section(struct iwl_trans *trans, const char *name, 125static int iwl_load_section(struct iwl_trans *trans, const char *name,
126 struct fw_desc *image, u32 dst_addr) 126 struct fw_desc *image, u32 dst_addr)
127{ 127{
128 struct iwl_bus *bus = bus(trans); 128 struct iwl_bus *bus = bus(trans);
@@ -188,7 +188,7 @@ static inline struct fw_img *iwl_get_ucode_image(struct iwl_trans *trans,
188 return NULL; 188 return NULL;
189} 189}
190 190
191static int iwlagn_load_given_ucode(struct iwl_trans *trans, 191static int iwl_load_given_ucode(struct iwl_trans *trans,
192 enum iwl_ucode_type ucode_type) 192 enum iwl_ucode_type ucode_type)
193{ 193{
194 int ret = 0; 194 int ret = 0;
@@ -201,19 +201,19 @@ static int iwlagn_load_given_ucode(struct iwl_trans *trans,
201 return -EINVAL; 201 return -EINVAL;
202 } 202 }
203 203
204 ret = iwlagn_load_section(trans, "INST", &image->code, 204 ret = iwl_load_section(trans, "INST", &image->code,
205 IWLAGN_RTC_INST_LOWER_BOUND); 205 IWLAGN_RTC_INST_LOWER_BOUND);
206 if (ret) 206 if (ret)
207 return ret; 207 return ret;
208 208
209 return iwlagn_load_section(trans, "DATA", &image->data, 209 return iwl_load_section(trans, "DATA", &image->data,
210 IWLAGN_RTC_DATA_LOWER_BOUND); 210 IWLAGN_RTC_DATA_LOWER_BOUND);
211} 211}
212 212
213/* 213/*
214 * Calibration 214 * Calibration
215 */ 215 */
216static int iwlagn_set_Xtal_calib(struct iwl_priv *priv) 216static int iwl_set_Xtal_calib(struct iwl_priv *priv)
217{ 217{
218 struct iwl_calib_xtal_freq_cmd cmd; 218 struct iwl_calib_xtal_freq_cmd cmd;
219 __le16 *xtal_calib = 219 __le16 *xtal_calib =
@@ -225,7 +225,7 @@ static int iwlagn_set_Xtal_calib(struct iwl_priv *priv)
225 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); 225 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
226} 226}
227 227
228static int iwlagn_set_temperature_offset_calib(struct iwl_priv *priv) 228static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
229{ 229{
230 struct iwl_calib_temperature_offset_cmd cmd; 230 struct iwl_calib_temperature_offset_cmd cmd;
231 __le16 *offset_calib = 231 __le16 *offset_calib =
@@ -242,7 +242,7 @@ static int iwlagn_set_temperature_offset_calib(struct iwl_priv *priv)
242 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); 242 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
243} 243}
244 244
245static int iwlagn_set_temperature_offset_calib_v2(struct iwl_priv *priv) 245static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv)
246{ 246{
247 struct iwl_calib_temperature_offset_v2_cmd cmd; 247 struct iwl_calib_temperature_offset_v2_cmd cmd;
248 __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv, 248 __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv,
@@ -277,7 +277,7 @@ static int iwlagn_set_temperature_offset_calib_v2(struct iwl_priv *priv)
277 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd)); 277 return iwl_calib_set(priv, (void *)&cmd, sizeof(cmd));
278} 278}
279 279
280static int iwlagn_send_calib_cfg(struct iwl_priv *priv) 280static int iwl_send_calib_cfg(struct iwl_trans *trans)
281{ 281{
282 struct iwl_calib_cfg_cmd calib_cfg_cmd; 282 struct iwl_calib_cfg_cmd calib_cfg_cmd;
283 struct iwl_host_cmd cmd = { 283 struct iwl_host_cmd cmd = {
@@ -293,7 +293,7 @@ static int iwlagn_send_calib_cfg(struct iwl_priv *priv)
293 calib_cfg_cmd.ucd_calib_cfg.flags = 293 calib_cfg_cmd.ucd_calib_cfg.flags =
294 IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK; 294 IWL_CALIB_CFG_FLAG_SEND_COMPLETE_NTFY_MSK;
295 295
296 return iwl_trans_send_cmd(trans(priv), &cmd); 296 return iwl_trans_send_cmd(trans, &cmd);
297} 297}
298 298
299int iwlagn_rx_calib_result(struct iwl_priv *priv, 299int iwlagn_rx_calib_result(struct iwl_priv *priv,
@@ -326,14 +326,14 @@ int iwlagn_init_alive_start(struct iwl_priv *priv)
326 * no need to close the envlope since we are going 326 * no need to close the envlope since we are going
327 * to load the runtime uCode later. 327 * to load the runtime uCode later.
328 */ 328 */
329 ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN, 329 ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_OPEN,
330 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2); 330 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
331 if (ret) 331 if (ret)
332 return ret; 332 return ret;
333 333
334 } 334 }
335 335
336 ret = iwlagn_send_calib_cfg(priv); 336 ret = iwl_send_calib_cfg(trans(priv));
337 if (ret) 337 if (ret)
338 return ret; 338 return ret;
339 339
@@ -343,15 +343,15 @@ int iwlagn_init_alive_start(struct iwl_priv *priv)
343 */ 343 */
344 if (priv->cfg->need_temp_offset_calib) { 344 if (priv->cfg->need_temp_offset_calib) {
345 if (priv->cfg->temp_offset_v2) 345 if (priv->cfg->temp_offset_v2)
346 return iwlagn_set_temperature_offset_calib_v2(priv); 346 return iwl_set_temperature_offset_calib_v2(priv);
347 else 347 else
348 return iwlagn_set_temperature_offset_calib(priv); 348 return iwl_set_temperature_offset_calib(priv);
349 } 349 }
350 350
351 return 0; 351 return 0;
352} 352}
353 353
354static int iwlagn_send_wimax_coex(struct iwl_priv *priv) 354static int iwl_send_wimax_coex(struct iwl_priv *priv)
355{ 355{
356 struct iwl_wimax_coex_cmd coex_cmd; 356 struct iwl_wimax_coex_cmd coex_cmd;
357 357
@@ -379,7 +379,7 @@ static int iwlagn_send_wimax_coex(struct iwl_priv *priv)
379 sizeof(coex_cmd), &coex_cmd); 379 sizeof(coex_cmd), &coex_cmd);
380} 380}
381 381
382static const u8 iwlagn_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = { 382static const u8 iwl_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
383 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | 383 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
384 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)), 384 (0 << IWL_BT_COEX_PRIO_TBL_SHARED_ANTENNA_POS)),
385 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) | 385 ((BT_COEX_PRIO_TBL_PRIO_BYPASS << IWL_BT_COEX_PRIO_TBL_PRIO_POS) |
@@ -401,42 +401,42 @@ static const u8 iwlagn_bt_prio_tbl[BT_COEX_PRIO_TBL_EVT_MAX] = {
401 0, 0, 0, 0, 0, 0, 0 401 0, 0, 0, 0, 0, 0, 0
402}; 402};
403 403
404void iwlagn_send_prio_tbl(struct iwl_priv *priv) 404void iwl_send_prio_tbl(struct iwl_trans *trans)
405{ 405{
406 struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd; 406 struct iwl_bt_coex_prio_table_cmd prio_tbl_cmd;
407 407
408 memcpy(prio_tbl_cmd.prio_tbl, iwlagn_bt_prio_tbl, 408 memcpy(prio_tbl_cmd.prio_tbl, iwl_bt_prio_tbl,
409 sizeof(iwlagn_bt_prio_tbl)); 409 sizeof(iwl_bt_prio_tbl));
410 if (iwl_trans_send_cmd_pdu(trans(priv), 410 if (iwl_trans_send_cmd_pdu(trans,
411 REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC, 411 REPLY_BT_COEX_PRIO_TABLE, CMD_SYNC,
412 sizeof(prio_tbl_cmd), &prio_tbl_cmd)) 412 sizeof(prio_tbl_cmd), &prio_tbl_cmd))
413 IWL_ERR(priv, "failed to send BT prio tbl command\n"); 413 IWL_ERR(trans, "failed to send BT prio tbl command\n");
414} 414}
415 415
416int iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type) 416int iwl_send_bt_env(struct iwl_trans *trans, u8 action, u8 type)
417{ 417{
418 struct iwl_bt_coex_prot_env_cmd env_cmd; 418 struct iwl_bt_coex_prot_env_cmd env_cmd;
419 int ret; 419 int ret;
420 420
421 env_cmd.action = action; 421 env_cmd.action = action;
422 env_cmd.type = type; 422 env_cmd.type = type;
423 ret = iwl_trans_send_cmd_pdu(trans(priv), 423 ret = iwl_trans_send_cmd_pdu(trans,
424 REPLY_BT_COEX_PROT_ENV, CMD_SYNC, 424 REPLY_BT_COEX_PROT_ENV, CMD_SYNC,
425 sizeof(env_cmd), &env_cmd); 425 sizeof(env_cmd), &env_cmd);
426 if (ret) 426 if (ret)
427 IWL_ERR(priv, "failed to send BT env command\n"); 427 IWL_ERR(trans, "failed to send BT env command\n");
428 return ret; 428 return ret;
429} 429}
430 430
431 431
432static int iwlagn_alive_notify(struct iwl_priv *priv) 432static int iwl_alive_notify(struct iwl_priv *priv)
433{ 433{
434 struct iwl_rxon_context *ctx; 434 struct iwl_rxon_context *ctx;
435 int ret; 435 int ret;
436 436
437 if (!priv->tx_cmd_pool) 437 if (!priv->tx_cmd_pool)
438 priv->tx_cmd_pool = 438 priv->tx_cmd_pool =
439 kmem_cache_create("iwlagn_dev_cmd", 439 kmem_cache_create("iwl_dev_cmd",
440 sizeof(struct iwl_device_cmd), 440 sizeof(struct iwl_device_cmd),
441 sizeof(void *), 0, NULL); 441 sizeof(void *), 0, NULL);
442 442
@@ -447,12 +447,12 @@ static int iwlagn_alive_notify(struct iwl_priv *priv)
447 for_each_context(priv, ctx) 447 for_each_context(priv, ctx)
448 ctx->last_tx_rejected = false; 448 ctx->last_tx_rejected = false;
449 449
450 ret = iwlagn_send_wimax_coex(priv); 450 ret = iwl_send_wimax_coex(priv);
451 if (ret) 451 if (ret)
452 return ret; 452 return ret;
453 453
454 if (!priv->cfg->no_xtal_calib) { 454 if (!priv->cfg->no_xtal_calib) {
455 ret = iwlagn_set_Xtal_calib(priv); 455 ret = iwl_set_Xtal_calib(priv);
456 if (ret) 456 if (ret)
457 return ret; 457 return ret;
458 } 458 }
@@ -548,7 +548,7 @@ struct iwlagn_alive_data {
548 u8 subtype; 548 u8 subtype;
549}; 549};
550 550
551static void iwlagn_alive_fn(struct iwl_priv *priv, 551static void iwl_alive_fn(struct iwl_priv *priv,
552 struct iwl_rx_packet *pkt, 552 struct iwl_rx_packet *pkt,
553 void *data) 553 void *data)
554{ 554{
@@ -571,6 +571,70 @@ static void iwlagn_alive_fn(struct iwl_priv *priv,
571 alive_data->valid = palive->is_valid == UCODE_VALID_OK; 571 alive_data->valid = palive->is_valid == UCODE_VALID_OK;
572} 572}
573 573
574/* notification wait support */
575void iwl_init_notification_wait(struct iwl_shared *shrd,
576 struct iwl_notification_wait *wait_entry,
577 u8 cmd,
578 void (*fn)(struct iwl_priv *priv,
579 struct iwl_rx_packet *pkt,
580 void *data),
581 void *fn_data)
582{
583 wait_entry->fn = fn;
584 wait_entry->fn_data = fn_data;
585 wait_entry->cmd = cmd;
586 wait_entry->triggered = false;
587 wait_entry->aborted = false;
588
589 spin_lock_bh(&shrd->notif_wait_lock);
590 list_add(&wait_entry->list, &shrd->notif_waits);
591 spin_unlock_bh(&shrd->notif_wait_lock);
592}
593
594int iwl_wait_notification(struct iwl_shared *shrd,
595 struct iwl_notification_wait *wait_entry,
596 unsigned long timeout)
597{
598 int ret;
599
600 ret = wait_event_timeout(shrd->notif_waitq,
601 wait_entry->triggered || wait_entry->aborted,
602 timeout);
603
604 spin_lock_bh(&shrd->notif_wait_lock);
605 list_del(&wait_entry->list);
606 spin_unlock_bh(&shrd->notif_wait_lock);
607
608 if (wait_entry->aborted)
609 return -EIO;
610
611 /* return value is always >= 0 */
612 if (ret <= 0)
613 return -ETIMEDOUT;
614 return 0;
615}
616
617void iwl_remove_notification(struct iwl_shared *shrd,
618 struct iwl_notification_wait *wait_entry)
619{
620 spin_lock_bh(&shrd->notif_wait_lock);
621 list_del(&wait_entry->list);
622 spin_unlock_bh(&shrd->notif_wait_lock);
623}
624
625void iwl_abort_notification_waits(struct iwl_shared *shrd)
626{
627 unsigned long flags;
628 struct iwl_notification_wait *wait_entry;
629
630 spin_lock_irqsave(&shrd->notif_wait_lock, flags);
631 list_for_each_entry(wait_entry, &shrd->notif_waits, list)
632 wait_entry->aborted = true;
633 spin_unlock_irqrestore(&shrd->notif_wait_lock, flags);
634
635 wake_up_all(&shrd->notif_waitq);
636}
637
574#define UCODE_ALIVE_TIMEOUT HZ 638#define UCODE_ALIVE_TIMEOUT HZ
575#define UCODE_CALIB_TIMEOUT (2*HZ) 639#define UCODE_CALIB_TIMEOUT (2*HZ)
576 640
@@ -579,41 +643,43 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
579{ 643{
580 struct iwl_notification_wait alive_wait; 644 struct iwl_notification_wait alive_wait;
581 struct iwlagn_alive_data alive_data; 645 struct iwlagn_alive_data alive_data;
646 struct iwl_trans *trans = trans(priv);
582 int ret; 647 int ret;
583 enum iwl_ucode_type old_type; 648 enum iwl_ucode_type old_type;
584 649
585 ret = iwl_trans_start_device(trans(priv)); 650 ret = iwl_trans_start_device(trans);
586 if (ret) 651 if (ret)
587 return ret; 652 return ret;
588 653
589 iwlagn_init_notification_wait(priv, &alive_wait, REPLY_ALIVE, 654 iwl_init_notification_wait(trans->shrd, &alive_wait, REPLY_ALIVE,
590 iwlagn_alive_fn, &alive_data); 655 iwl_alive_fn, &alive_data);
591 656
592 old_type = priv->ucode_type; 657 old_type = trans->shrd->ucode_type;
593 priv->ucode_type = ucode_type; 658 trans->shrd->ucode_type = ucode_type;
594 659
595 ret = iwlagn_load_given_ucode(trans(priv), ucode_type); 660 ret = iwl_load_given_ucode(trans, ucode_type);
596 if (ret) { 661 if (ret) {
597 priv->ucode_type = old_type; 662 trans->shrd->ucode_type = old_type;
598 iwlagn_remove_notification(priv, &alive_wait); 663 iwl_remove_notification(trans->shrd, &alive_wait);
599 return ret; 664 return ret;
600 } 665 }
601 666
602 iwl_trans_kick_nic(trans(priv)); 667 iwl_trans_kick_nic(trans);
603 668
604 /* 669 /*
605 * Some things may run in the background now, but we 670 * Some things may run in the background now, but we
606 * just wait for the ALIVE notification here. 671 * just wait for the ALIVE notification here.
607 */ 672 */
608 ret = iwlagn_wait_notification(priv, &alive_wait, UCODE_ALIVE_TIMEOUT); 673 ret = iwl_wait_notification(trans->shrd, &alive_wait,
674 UCODE_ALIVE_TIMEOUT);
609 if (ret) { 675 if (ret) {
610 priv->ucode_type = old_type; 676 trans->shrd->ucode_type = old_type;
611 return ret; 677 return ret;
612 } 678 }
613 679
614 if (!alive_data.valid) { 680 if (!alive_data.valid) {
615 IWL_ERR(priv, "Loaded ucode is not valid!\n"); 681 IWL_ERR(priv, "Loaded ucode is not valid!\n");
616 priv->ucode_type = old_type; 682 trans->shrd->ucode_type = old_type;
617 return -EIO; 683 return -EIO;
618 } 684 }
619 685
@@ -623,9 +689,9 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
623 * skip it for WoWLAN. 689 * skip it for WoWLAN.
624 */ 690 */
625 if (ucode_type != IWL_UCODE_WOWLAN) { 691 if (ucode_type != IWL_UCODE_WOWLAN) {
626 ret = iwl_verify_ucode(trans(priv), ucode_type); 692 ret = iwl_verify_ucode(trans, ucode_type);
627 if (ret) { 693 if (ret) {
628 priv->ucode_type = old_type; 694 trans->shrd->ucode_type = old_type;
629 return ret; 695 return ret;
630 } 696 }
631 697
@@ -633,11 +699,11 @@ int iwlagn_load_ucode_wait_alive(struct iwl_priv *priv,
633 msleep(5); 699 msleep(5);
634 } 700 }
635 701
636 ret = iwlagn_alive_notify(priv); 702 ret = iwl_alive_notify(priv);
637 if (ret) { 703 if (ret) {
638 IWL_WARN(priv, 704 IWL_WARN(priv,
639 "Could not complete ALIVE transition: %d\n", ret); 705 "Could not complete ALIVE transition: %d\n", ret);
640 priv->ucode_type = old_type; 706 trans->shrd->ucode_type = old_type;
641 return ret; 707 return ret;
642 } 708 }
643 709
@@ -655,10 +721,10 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv)
655 if (!trans(priv)->ucode_init.code.len) 721 if (!trans(priv)->ucode_init.code.len)
656 return 0; 722 return 0;
657 723
658 if (priv->ucode_type != IWL_UCODE_NONE) 724 if (priv->shrd->ucode_type != IWL_UCODE_NONE)
659 return 0; 725 return 0;
660 726
661 iwlagn_init_notification_wait(priv, &calib_wait, 727 iwl_init_notification_wait(priv->shrd, &calib_wait,
662 CALIBRATION_COMPLETE_NOTIFICATION, 728 CALIBRATION_COMPLETE_NOTIFICATION,
663 NULL, NULL); 729 NULL, NULL);
664 730
@@ -675,12 +741,13 @@ int iwlagn_run_init_ucode(struct iwl_priv *priv)
675 * Some things may run in the background now, but we 741 * Some things may run in the background now, but we
676 * just wait for the calibration complete notification. 742 * just wait for the calibration complete notification.
677 */ 743 */
678 ret = iwlagn_wait_notification(priv, &calib_wait, UCODE_CALIB_TIMEOUT); 744 ret = iwl_wait_notification(priv->shrd, &calib_wait,
745 UCODE_CALIB_TIMEOUT);
679 746
680 goto out; 747 goto out;
681 748
682 error: 749 error:
683 iwlagn_remove_notification(priv, &calib_wait); 750 iwl_remove_notification(priv->shrd, &calib_wait);
684 out: 751 out:
685 /* Whatever happened, stop the device */ 752 /* Whatever happened, stop the device */
686 iwl_trans_stop_device(trans(priv)); 753 iwl_trans_stop_device(trans(priv));
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index edd317fa7c0a..c3e1aa7c1a80 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -831,11 +831,11 @@ static int rt2x00lib_probe_hw_modes(struct rt2x00_dev *rt2x00dev,
831 if (spec->supported_rates & SUPPORT_RATE_OFDM) 831 if (spec->supported_rates & SUPPORT_RATE_OFDM)
832 num_rates += 8; 832 num_rates += 8;
833 833
834 channels = kzalloc(sizeof(*channels) * spec->num_channels, GFP_KERNEL); 834 channels = kcalloc(spec->num_channels, sizeof(*channels), GFP_KERNEL);
835 if (!channels) 835 if (!channels)
836 return -ENOMEM; 836 return -ENOMEM;
837 837
838 rates = kzalloc(sizeof(*rates) * num_rates, GFP_KERNEL); 838 rates = kcalloc(num_rates, sizeof(*rates), GFP_KERNEL);
839 if (!rates) 839 if (!rates)
840 goto exit_free_channels; 840 goto exit_free_channels;
841 841
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
index fa393dfe136c..931d97979b04 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
@@ -262,10 +262,10 @@ int rtl92c_download_fw(struct ieee80211_hw *hw)
262 u32 fwsize; 262 u32 fwsize;
263 enum version_8192c version = rtlhal->version; 263 enum version_8192c version = rtlhal->version;
264 264
265 pr_info("Loading firmware file %s\n", rtlpriv->cfg->fw_name);
266 if (!rtlhal->pfirmware) 265 if (!rtlhal->pfirmware)
267 return 1; 266 return 1;
268 267
268 pr_info("Loading firmware file %s\n", rtlpriv->cfg->fw_name);
269 pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware; 269 pfwheader = (struct rtl92c_firmware_header *)rtlhal->pfirmware;
270 pfwdata = (u8 *) rtlhal->pfirmware; 270 pfwdata = (u8 *) rtlhal->pfirmware;
271 fwsize = rtlhal->fwsize; 271 fwsize = rtlhal->fwsize;
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
index 3fe388b87c2e..af08c8609c63 100644
--- a/drivers/net/wireless/wl12xx/Kconfig
+++ b/drivers/net/wireless/wl12xx/Kconfig
@@ -42,16 +42,6 @@ config WL12XX_SDIO
42 If you choose to build a module, it'll be called wl12xx_sdio. 42 If you choose to build a module, it'll be called wl12xx_sdio.
43 Say N if unsure. 43 Say N if unsure.
44 44
45config WL12XX_SDIO_TEST
46 tristate "TI wl12xx SDIO testing support"
47 depends on WL12XX && MMC && WL12XX_SDIO
48 default n
49 ---help---
50 This module adds support for the SDIO bus testing with the
51 TI wl12xx chipsets. You probably don't want this unless you are
52 testing a new hardware platform. Select this if you want to test the
53 SDIO bus which is connected to the wl12xx chip.
54
55config WL12XX_PLATFORM_DATA 45config WL12XX_PLATFORM_DATA
56 bool 46 bool
57 depends on WL12XX_SDIO != n || WL1251_SDIO != n 47 depends on WL12XX_SDIO != n || WL1251_SDIO != n
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
index 621b3483ca2c..fe67262ba19f 100644
--- a/drivers/net/wireless/wl12xx/Makefile
+++ b/drivers/net/wireless/wl12xx/Makefile
@@ -3,14 +3,11 @@ wl12xx-objs = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
3 3
4wl12xx_spi-objs = spi.o 4wl12xx_spi-objs = spi.o
5wl12xx_sdio-objs = sdio.o 5wl12xx_sdio-objs = sdio.o
6wl12xx_sdio_test-objs = sdio_test.o
7 6
8wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o 7wl12xx-$(CONFIG_NL80211_TESTMODE) += testmode.o
9obj-$(CONFIG_WL12XX) += wl12xx.o 8obj-$(CONFIG_WL12XX) += wl12xx.o
10obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o 9obj-$(CONFIG_WL12XX_SPI) += wl12xx_spi.o
11obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o 10obj-$(CONFIG_WL12XX_SDIO) += wl12xx_sdio.o
12 11
13obj-$(CONFIG_WL12XX_SDIO_TEST) += wl12xx_sdio_test.o
14
15# small builtin driver bit 12# small builtin driver bit
16obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o 13obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wl12xx_platform_data.o
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c
index ca044a743191..bde1d862bdd5 100644
--- a/drivers/net/wireless/wl12xx/acx.c
+++ b/drivers/net/wireless/wl12xx/acx.c
@@ -29,11 +29,12 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include "wl12xx.h" 31#include "wl12xx.h"
32#include "debug.h"
32#include "wl12xx_80211.h" 33#include "wl12xx_80211.h"
33#include "reg.h" 34#include "reg.h"
34#include "ps.h" 35#include "ps.h"
35 36
36int wl1271_acx_wake_up_conditions(struct wl1271 *wl) 37int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif)
37{ 38{
38 struct acx_wake_up_condition *wake_up; 39 struct acx_wake_up_condition *wake_up;
39 int ret; 40 int ret;
@@ -46,7 +47,7 @@ int wl1271_acx_wake_up_conditions(struct wl1271 *wl)
46 goto out; 47 goto out;
47 } 48 }
48 49
49 wake_up->role_id = wl->role_id; 50 wake_up->role_id = wlvif->role_id;
50 wake_up->wake_up_event = wl->conf.conn.wake_up_event; 51 wake_up->wake_up_event = wl->conf.conn.wake_up_event;
51 wake_up->listen_interval = wl->conf.conn.listen_interval; 52 wake_up->listen_interval = wl->conf.conn.listen_interval;
52 53
@@ -84,7 +85,8 @@ out:
84 return ret; 85 return ret;
85} 86}
86 87
87int wl1271_acx_tx_power(struct wl1271 *wl, int power) 88int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
89 int power)
88{ 90{
89 struct acx_current_tx_power *acx; 91 struct acx_current_tx_power *acx;
90 int ret; 92 int ret;
@@ -100,7 +102,7 @@ int wl1271_acx_tx_power(struct wl1271 *wl, int power)
100 goto out; 102 goto out;
101 } 103 }
102 104
103 acx->role_id = wl->role_id; 105 acx->role_id = wlvif->role_id;
104 acx->current_tx_power = power * 10; 106 acx->current_tx_power = power * 10;
105 107
106 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx)); 108 ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
@@ -114,7 +116,7 @@ out:
114 return ret; 116 return ret;
115} 117}
116 118
117int wl1271_acx_feature_cfg(struct wl1271 *wl) 119int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
118{ 120{
119 struct acx_feature_config *feature; 121 struct acx_feature_config *feature;
120 int ret; 122 int ret;
@@ -128,7 +130,7 @@ int wl1271_acx_feature_cfg(struct wl1271 *wl)
128 } 130 }
129 131
130 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */ 132 /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
131 feature->role_id = wl->role_id; 133 feature->role_id = wlvif->role_id;
132 feature->data_flow_options = 0; 134 feature->data_flow_options = 0;
133 feature->options = 0; 135 feature->options = 0;
134 136
@@ -210,7 +212,8 @@ out:
210 return ret; 212 return ret;
211} 213}
212 214
213int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time) 215int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
216 enum acx_slot_type slot_time)
214{ 217{
215 struct acx_slot *slot; 218 struct acx_slot *slot;
216 int ret; 219 int ret;
@@ -223,7 +226,7 @@ int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
223 goto out; 226 goto out;
224 } 227 }
225 228
226 slot->role_id = wl->role_id; 229 slot->role_id = wlvif->role_id;
227 slot->wone_index = STATION_WONE_INDEX; 230 slot->wone_index = STATION_WONE_INDEX;
228 slot->slot_time = slot_time; 231 slot->slot_time = slot_time;
229 232
@@ -238,8 +241,8 @@ out:
238 return ret; 241 return ret;
239} 242}
240 243
241int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, 244int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
242 void *mc_list, u32 mc_list_len) 245 bool enable, void *mc_list, u32 mc_list_len)
243{ 246{
244 struct acx_dot11_grp_addr_tbl *acx; 247 struct acx_dot11_grp_addr_tbl *acx;
245 int ret; 248 int ret;
@@ -253,7 +256,7 @@ int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
253 } 256 }
254 257
255 /* MAC filtering */ 258 /* MAC filtering */
256 acx->role_id = wl->role_id; 259 acx->role_id = wlvif->role_id;
257 acx->enabled = enable; 260 acx->enabled = enable;
258 acx->num_groups = mc_list_len; 261 acx->num_groups = mc_list_len;
259 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN); 262 memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
@@ -270,7 +273,8 @@ out:
270 return ret; 273 return ret;
271} 274}
272 275
273int wl1271_acx_service_period_timeout(struct wl1271 *wl) 276int wl1271_acx_service_period_timeout(struct wl1271 *wl,
277 struct wl12xx_vif *wlvif)
274{ 278{
275 struct acx_rx_timeout *rx_timeout; 279 struct acx_rx_timeout *rx_timeout;
276 int ret; 280 int ret;
@@ -283,7 +287,7 @@ int wl1271_acx_service_period_timeout(struct wl1271 *wl)
283 287
284 wl1271_debug(DEBUG_ACX, "acx service period timeout"); 288 wl1271_debug(DEBUG_ACX, "acx service period timeout");
285 289
286 rx_timeout->role_id = wl->role_id; 290 rx_timeout->role_id = wlvif->role_id;
287 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout); 291 rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
288 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout); 292 rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
289 293
@@ -300,7 +304,8 @@ out:
300 return ret; 304 return ret;
301} 305}
302 306
303int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold) 307int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
308 u32 rts_threshold)
304{ 309{
305 struct acx_rts_threshold *rts; 310 struct acx_rts_threshold *rts;
306 int ret; 311 int ret;
@@ -320,7 +325,7 @@ int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold)
320 goto out; 325 goto out;
321 } 326 }
322 327
323 rts->role_id = wl->role_id; 328 rts->role_id = wlvif->role_id;
324 rts->threshold = cpu_to_le16((u16)rts_threshold); 329 rts->threshold = cpu_to_le16((u16)rts_threshold);
325 330
326 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts)); 331 ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
@@ -363,7 +368,8 @@ out:
363 return ret; 368 return ret;
364} 369}
365 370
366int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter) 371int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
372 bool enable_filter)
367{ 373{
368 struct acx_beacon_filter_option *beacon_filter = NULL; 374 struct acx_beacon_filter_option *beacon_filter = NULL;
369 int ret = 0; 375 int ret = 0;
@@ -380,7 +386,7 @@ int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
380 goto out; 386 goto out;
381 } 387 }
382 388
383 beacon_filter->role_id = wl->role_id; 389 beacon_filter->role_id = wlvif->role_id;
384 beacon_filter->enable = enable_filter; 390 beacon_filter->enable = enable_filter;
385 391
386 /* 392 /*
@@ -401,7 +407,8 @@ out:
401 return ret; 407 return ret;
402} 408}
403 409
404int wl1271_acx_beacon_filter_table(struct wl1271 *wl) 410int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
411 struct wl12xx_vif *wlvif)
405{ 412{
406 struct acx_beacon_filter_ie_table *ie_table; 413 struct acx_beacon_filter_ie_table *ie_table;
407 int i, idx = 0; 414 int i, idx = 0;
@@ -417,7 +424,7 @@ int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
417 } 424 }
418 425
419 /* configure default beacon pass-through rules */ 426 /* configure default beacon pass-through rules */
420 ie_table->role_id = wl->role_id; 427 ie_table->role_id = wlvif->role_id;
421 ie_table->num_ie = 0; 428 ie_table->num_ie = 0;
422 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) { 429 for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
423 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]); 430 struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
@@ -458,7 +465,8 @@ out:
458 465
459#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff 466#define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
460 467
461int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable) 468int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
469 bool enable)
462{ 470{
463 struct acx_conn_monit_params *acx; 471 struct acx_conn_monit_params *acx;
464 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE; 472 u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
@@ -479,7 +487,7 @@ int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
479 timeout = wl->conf.conn.bss_lose_timeout; 487 timeout = wl->conf.conn.bss_lose_timeout;
480 } 488 }
481 489
482 acx->role_id = wl->role_id; 490 acx->role_id = wlvif->role_id;
483 acx->synch_fail_thold = cpu_to_le32(threshold); 491 acx->synch_fail_thold = cpu_to_le32(threshold);
484 acx->bss_lose_timeout = cpu_to_le32(timeout); 492 acx->bss_lose_timeout = cpu_to_le32(timeout);
485 493
@@ -582,7 +590,7 @@ out:
582 return ret; 590 return ret;
583} 591}
584 592
585int wl1271_acx_bcn_dtim_options(struct wl1271 *wl) 593int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
586{ 594{
587 struct acx_beacon_broadcast *bb; 595 struct acx_beacon_broadcast *bb;
588 int ret; 596 int ret;
@@ -595,7 +603,7 @@ int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
595 goto out; 603 goto out;
596 } 604 }
597 605
598 bb->role_id = wl->role_id; 606 bb->role_id = wlvif->role_id;
599 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout); 607 bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
600 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout); 608 bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
601 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps; 609 bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
@@ -612,7 +620,7 @@ out:
612 return ret; 620 return ret;
613} 621}
614 622
615int wl1271_acx_aid(struct wl1271 *wl, u16 aid) 623int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
616{ 624{
617 struct acx_aid *acx_aid; 625 struct acx_aid *acx_aid;
618 int ret; 626 int ret;
@@ -625,7 +633,7 @@ int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
625 goto out; 633 goto out;
626 } 634 }
627 635
628 acx_aid->role_id = wl->role_id; 636 acx_aid->role_id = wlvif->role_id;
629 acx_aid->aid = cpu_to_le16(aid); 637 acx_aid->aid = cpu_to_le16(aid);
630 638
631 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid)); 639 ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
@@ -668,7 +676,8 @@ out:
668 return ret; 676 return ret;
669} 677}
670 678
671int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble) 679int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
680 enum acx_preamble_type preamble)
672{ 681{
673 struct acx_preamble *acx; 682 struct acx_preamble *acx;
674 int ret; 683 int ret;
@@ -681,7 +690,7 @@ int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
681 goto out; 690 goto out;
682 } 691 }
683 692
684 acx->role_id = wl->role_id; 693 acx->role_id = wlvif->role_id;
685 acx->preamble = preamble; 694 acx->preamble = preamble;
686 695
687 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx)); 696 ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
@@ -695,7 +704,7 @@ out:
695 return ret; 704 return ret;
696} 705}
697 706
698int wl1271_acx_cts_protect(struct wl1271 *wl, 707int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
699 enum acx_ctsprotect_type ctsprotect) 708 enum acx_ctsprotect_type ctsprotect)
700{ 709{
701 struct acx_ctsprotect *acx; 710 struct acx_ctsprotect *acx;
@@ -709,7 +718,7 @@ int wl1271_acx_cts_protect(struct wl1271 *wl,
709 goto out; 718 goto out;
710 } 719 }
711 720
712 acx->role_id = wl->role_id; 721 acx->role_id = wlvif->role_id;
713 acx->ctsprotect = ctsprotect; 722 acx->ctsprotect = ctsprotect;
714 723
715 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx)); 724 ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
@@ -739,7 +748,7 @@ int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
739 return 0; 748 return 0;
740} 749}
741 750
742int wl1271_acx_sta_rate_policies(struct wl1271 *wl) 751int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
743{ 752{
744 struct acx_rate_policy *acx; 753 struct acx_rate_policy *acx;
745 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf; 754 struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
@@ -755,11 +764,11 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
755 } 764 }
756 765
757 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x", 766 wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
758 wl->basic_rate, wl->rate_set); 767 wlvif->basic_rate, wlvif->rate_set);
759 768
760 /* configure one basic rate class */ 769 /* configure one basic rate class */
761 acx->rate_policy_idx = cpu_to_le32(ACX_TX_BASIC_RATE); 770 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
762 acx->rate_policy.enabled_rates = cpu_to_le32(wl->basic_rate); 771 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
763 acx->rate_policy.short_retry_limit = c->short_retry_limit; 772 acx->rate_policy.short_retry_limit = c->short_retry_limit;
764 acx->rate_policy.long_retry_limit = c->long_retry_limit; 773 acx->rate_policy.long_retry_limit = c->long_retry_limit;
765 acx->rate_policy.aflags = c->aflags; 774 acx->rate_policy.aflags = c->aflags;
@@ -771,8 +780,8 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
771 } 780 }
772 781
773 /* configure one AP supported rate class */ 782 /* configure one AP supported rate class */
774 acx->rate_policy_idx = cpu_to_le32(ACX_TX_AP_FULL_RATE); 783 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
775 acx->rate_policy.enabled_rates = cpu_to_le32(wl->rate_set); 784 acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->rate_set);
776 acx->rate_policy.short_retry_limit = c->short_retry_limit; 785 acx->rate_policy.short_retry_limit = c->short_retry_limit;
777 acx->rate_policy.long_retry_limit = c->long_retry_limit; 786 acx->rate_policy.long_retry_limit = c->long_retry_limit;
778 acx->rate_policy.aflags = c->aflags; 787 acx->rate_policy.aflags = c->aflags;
@@ -788,7 +797,7 @@ int wl1271_acx_sta_rate_policies(struct wl1271 *wl)
788 * (p2p packets should always go out with OFDM rates, even 797 * (p2p packets should always go out with OFDM rates, even
789 * if we are currently connected to 11b AP) 798 * if we are currently connected to 11b AP)
790 */ 799 */
791 acx->rate_policy_idx = cpu_to_le32(ACX_TX_BASIC_RATE_P2P); 800 acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
792 acx->rate_policy.enabled_rates = 801 acx->rate_policy.enabled_rates =
793 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P); 802 cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
794 acx->rate_policy.short_retry_limit = c->short_retry_limit; 803 acx->rate_policy.short_retry_limit = c->short_retry_limit;
@@ -839,8 +848,8 @@ out:
839 return ret; 848 return ret;
840} 849}
841 850
842int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 851int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
843 u8 aifsn, u16 txop) 852 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
844{ 853{
845 struct acx_ac_cfg *acx; 854 struct acx_ac_cfg *acx;
846 int ret = 0; 855 int ret = 0;
@@ -855,7 +864,7 @@ int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
855 goto out; 864 goto out;
856 } 865 }
857 866
858 acx->role_id = wl->role_id; 867 acx->role_id = wlvif->role_id;
859 acx->ac = ac; 868 acx->ac = ac;
860 acx->cw_min = cw_min; 869 acx->cw_min = cw_min;
861 acx->cw_max = cpu_to_le16(cw_max); 870 acx->cw_max = cpu_to_le16(cw_max);
@@ -873,7 +882,8 @@ out:
873 return ret; 882 return ret;
874} 883}
875 884
876int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, 885int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
886 u8 queue_id, u8 channel_type,
877 u8 tsid, u8 ps_scheme, u8 ack_policy, 887 u8 tsid, u8 ps_scheme, u8 ack_policy,
878 u32 apsd_conf0, u32 apsd_conf1) 888 u32 apsd_conf0, u32 apsd_conf1)
879{ 889{
@@ -889,7 +899,7 @@ int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
889 goto out; 899 goto out;
890 } 900 }
891 901
892 acx->role_id = wl->role_id; 902 acx->role_id = wlvif->role_id;
893 acx->queue_id = queue_id; 903 acx->queue_id = queue_id;
894 acx->channel_type = channel_type; 904 acx->channel_type = channel_type;
895 acx->tsid = tsid; 905 acx->tsid = tsid;
@@ -1098,7 +1108,8 @@ out:
1098 return ret; 1108 return ret;
1099} 1109}
1100 1110
1101int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable) 1111int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1112 bool enable)
1102{ 1113{
1103 struct wl1271_acx_bet_enable *acx = NULL; 1114 struct wl1271_acx_bet_enable *acx = NULL;
1104 int ret = 0; 1115 int ret = 0;
@@ -1114,7 +1125,7 @@ int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
1114 goto out; 1125 goto out;
1115 } 1126 }
1116 1127
1117 acx->role_id = wl->role_id; 1128 acx->role_id = wlvif->role_id;
1118 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE; 1129 acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
1119 acx->max_consecutive = wl->conf.conn.bet_max_consecutive; 1130 acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
1120 1131
@@ -1129,7 +1140,8 @@ out:
1129 return ret; 1140 return ret;
1130} 1141}
1131 1142
1132int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address) 1143int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1144 u8 enable, __be32 address)
1133{ 1145{
1134 struct wl1271_acx_arp_filter *acx; 1146 struct wl1271_acx_arp_filter *acx;
1135 int ret; 1147 int ret;
@@ -1142,7 +1154,7 @@ int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address)
1142 goto out; 1154 goto out;
1143 } 1155 }
1144 1156
1145 acx->role_id = wl->role_id; 1157 acx->role_id = wlvif->role_id;
1146 acx->version = ACX_IPV4_VERSION; 1158 acx->version = ACX_IPV4_VERSION;
1147 acx->enable = enable; 1159 acx->enable = enable;
1148 1160
@@ -1189,7 +1201,8 @@ out:
1189 return ret; 1201 return ret;
1190} 1202}
1191 1203
1192int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable) 1204int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1205 bool enable)
1193{ 1206{
1194 struct wl1271_acx_keep_alive_mode *acx = NULL; 1207 struct wl1271_acx_keep_alive_mode *acx = NULL;
1195 int ret = 0; 1208 int ret = 0;
@@ -1202,7 +1215,7 @@ int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
1202 goto out; 1215 goto out;
1203 } 1216 }
1204 1217
1205 acx->role_id = wl->role_id; 1218 acx->role_id = wlvif->role_id;
1206 acx->enabled = enable; 1219 acx->enabled = enable;
1207 1220
1208 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx)); 1221 ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
@@ -1216,7 +1229,8 @@ out:
1216 return ret; 1229 return ret;
1217} 1230}
1218 1231
1219int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid) 1232int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1233 u8 index, u8 tpl_valid)
1220{ 1234{
1221 struct wl1271_acx_keep_alive_config *acx = NULL; 1235 struct wl1271_acx_keep_alive_config *acx = NULL;
1222 int ret = 0; 1236 int ret = 0;
@@ -1229,7 +1243,7 @@ int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
1229 goto out; 1243 goto out;
1230 } 1244 }
1231 1245
1232 acx->role_id = wl->role_id; 1246 acx->role_id = wlvif->role_id;
1233 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval); 1247 acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
1234 acx->index = index; 1248 acx->index = index;
1235 acx->tpl_validation = tpl_valid; 1249 acx->tpl_validation = tpl_valid;
@@ -1247,8 +1261,8 @@ out:
1247 return ret; 1261 return ret;
1248} 1262}
1249 1263
1250int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, 1264int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1251 s16 thold, u8 hyst) 1265 bool enable, s16 thold, u8 hyst)
1252{ 1266{
1253 struct wl1271_acx_rssi_snr_trigger *acx = NULL; 1267 struct wl1271_acx_rssi_snr_trigger *acx = NULL;
1254 int ret = 0; 1268 int ret = 0;
@@ -1261,9 +1275,9 @@ int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
1261 goto out; 1275 goto out;
1262 } 1276 }
1263 1277
1264 wl->last_rssi_event = -1; 1278 wlvif->last_rssi_event = -1;
1265 1279
1266 acx->role_id = wl->role_id; 1280 acx->role_id = wlvif->role_id;
1267 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing); 1281 acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
1268 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON; 1282 acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
1269 acx->type = WL1271_ACX_TRIG_TYPE_EDGE; 1283 acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
@@ -1288,7 +1302,8 @@ out:
1288 return ret; 1302 return ret;
1289} 1303}
1290 1304
1291int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl) 1305int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1306 struct wl12xx_vif *wlvif)
1292{ 1307{
1293 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL; 1308 struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
1294 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger; 1309 struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
@@ -1302,7 +1317,7 @@ int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
1302 goto out; 1317 goto out;
1303 } 1318 }
1304 1319
1305 acx->role_id = wl->role_id; 1320 acx->role_id = wlvif->role_id;
1306 acx->rssi_beacon = c->avg_weight_rssi_beacon; 1321 acx->rssi_beacon = c->avg_weight_rssi_beacon;
1307 acx->rssi_data = c->avg_weight_rssi_data; 1322 acx->rssi_data = c->avg_weight_rssi_data;
1308 acx->snr_beacon = c->avg_weight_snr_beacon; 1323 acx->snr_beacon = c->avg_weight_snr_beacon;
@@ -1367,6 +1382,7 @@ out:
1367} 1382}
1368 1383
1369int wl1271_acx_set_ht_information(struct wl1271 *wl, 1384int wl1271_acx_set_ht_information(struct wl1271 *wl,
1385 struct wl12xx_vif *wlvif,
1370 u16 ht_operation_mode) 1386 u16 ht_operation_mode)
1371{ 1387{
1372 struct wl1271_acx_ht_information *acx; 1388 struct wl1271_acx_ht_information *acx;
@@ -1380,7 +1396,7 @@ int wl1271_acx_set_ht_information(struct wl1271 *wl,
1380 goto out; 1396 goto out;
1381 } 1397 }
1382 1398
1383 acx->role_id = wl->role_id; 1399 acx->role_id = wlvif->role_id;
1384 acx->ht_protection = 1400 acx->ht_protection =
1385 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION); 1401 (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
1386 acx->rifs_mode = 0; 1402 acx->rifs_mode = 0;
@@ -1402,7 +1418,8 @@ out:
1402} 1418}
1403 1419
1404/* Configure BA session initiator/receiver parameters setting in the FW. */ 1420/* Configure BA session initiator/receiver parameters setting in the FW. */
1405int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl) 1421int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1422 struct wl12xx_vif *wlvif)
1406{ 1423{
1407 struct wl1271_acx_ba_initiator_policy *acx; 1424 struct wl1271_acx_ba_initiator_policy *acx;
1408 int ret; 1425 int ret;
@@ -1416,7 +1433,7 @@ int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl)
1416 } 1433 }
1417 1434
1418 /* set for the current role */ 1435 /* set for the current role */
1419 acx->role_id = wl->role_id; 1436 acx->role_id = wlvif->role_id;
1420 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap; 1437 acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
1421 acx->win_size = wl->conf.ht.tx_ba_win_size; 1438 acx->win_size = wl->conf.ht.tx_ba_win_size;
1422 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout; 1439 acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
@@ -1494,7 +1511,8 @@ out:
1494 return ret; 1511 return ret;
1495} 1512}
1496 1513
1497int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable) 1514int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1515 bool enable)
1498{ 1516{
1499 struct wl1271_acx_ps_rx_streaming *rx_streaming; 1517 struct wl1271_acx_ps_rx_streaming *rx_streaming;
1500 u32 conf_queues, enable_queues; 1518 u32 conf_queues, enable_queues;
@@ -1523,7 +1541,7 @@ int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable)
1523 if (!(conf_queues & BIT(i))) 1541 if (!(conf_queues & BIT(i)))
1524 continue; 1542 continue;
1525 1543
1526 rx_streaming->role_id = wl->role_id; 1544 rx_streaming->role_id = wlvif->role_id;
1527 rx_streaming->tid = i; 1545 rx_streaming->tid = i;
1528 rx_streaming->enable = enable_queues & BIT(i); 1546 rx_streaming->enable = enable_queues & BIT(i);
1529 rx_streaming->period = wl->conf.rx_streaming.interval; 1547 rx_streaming->period = wl->conf.rx_streaming.interval;
@@ -1542,7 +1560,7 @@ out:
1542 return ret; 1560 return ret;
1543} 1561}
1544 1562
1545int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl) 1563int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1546{ 1564{
1547 struct wl1271_acx_ap_max_tx_retry *acx = NULL; 1565 struct wl1271_acx_ap_max_tx_retry *acx = NULL;
1548 int ret; 1566 int ret;
@@ -1553,7 +1571,7 @@ int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl)
1553 if (!acx) 1571 if (!acx)
1554 return -ENOMEM; 1572 return -ENOMEM;
1555 1573
1556 acx->role_id = wl->role_id; 1574 acx->role_id = wlvif->role_id;
1557 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries); 1575 acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
1558 1576
1559 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx)); 1577 ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
@@ -1567,7 +1585,7 @@ out:
1567 return ret; 1585 return ret;
1568} 1586}
1569 1587
1570int wl1271_acx_config_ps(struct wl1271 *wl) 1588int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1571{ 1589{
1572 struct wl1271_acx_config_ps *config_ps; 1590 struct wl1271_acx_config_ps *config_ps;
1573 int ret; 1591 int ret;
@@ -1582,7 +1600,7 @@ int wl1271_acx_config_ps(struct wl1271 *wl)
1582 1600
1583 config_ps->exit_retries = wl->conf.conn.psm_exit_retries; 1601 config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
1584 config_ps->enter_retries = wl->conf.conn.psm_entry_retries; 1602 config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
1585 config_ps->null_data_rate = cpu_to_le32(wl->basic_rate); 1603 config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
1586 1604
1587 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps, 1605 ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
1588 sizeof(*config_ps)); 1606 sizeof(*config_ps));
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h
index e3f93b4b3429..b2d85bea6378 100644
--- a/drivers/net/wireless/wl12xx/acx.h
+++ b/drivers/net/wireless/wl12xx/acx.h
@@ -654,11 +654,6 @@ struct acx_rate_class {
654 u8 reserved; 654 u8 reserved;
655}; 655};
656 656
657#define ACX_TX_BASIC_RATE 0
658#define ACX_TX_AP_FULL_RATE 1
659#define ACX_TX_BASIC_RATE_P2P 2
660#define ACX_TX_AP_MODE_MGMT_RATE 4
661#define ACX_TX_AP_MODE_BCST_RATE 5
662struct acx_rate_policy { 657struct acx_rate_policy {
663 struct acx_header header; 658 struct acx_header header;
664 659
@@ -1234,39 +1229,49 @@ enum {
1234}; 1229};
1235 1230
1236 1231
1237int wl1271_acx_wake_up_conditions(struct wl1271 *wl); 1232int wl1271_acx_wake_up_conditions(struct wl1271 *wl,
1233 struct wl12xx_vif *wlvif);
1238int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth); 1234int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
1239int wl1271_acx_tx_power(struct wl1271 *wl, int power); 1235int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1240int wl1271_acx_feature_cfg(struct wl1271 *wl); 1236 int power);
1237int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1241int wl1271_acx_mem_map(struct wl1271 *wl, 1238int wl1271_acx_mem_map(struct wl1271 *wl,
1242 struct acx_header *mem_map, size_t len); 1239 struct acx_header *mem_map, size_t len);
1243int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl); 1240int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
1244int wl1271_acx_pd_threshold(struct wl1271 *wl); 1241int wl1271_acx_pd_threshold(struct wl1271 *wl);
1245int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time); 1242int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1246int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable, 1243 enum acx_slot_type slot_time);
1247 void *mc_list, u32 mc_list_len); 1244int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1248int wl1271_acx_service_period_timeout(struct wl1271 *wl); 1245 bool enable, void *mc_list, u32 mc_list_len);
1249int wl1271_acx_rts_threshold(struct wl1271 *wl, u32 rts_threshold); 1246int wl1271_acx_service_period_timeout(struct wl1271 *wl,
1247 struct wl12xx_vif *wlvif);
1248int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1249 u32 rts_threshold);
1250int wl1271_acx_dco_itrim_params(struct wl1271 *wl); 1250int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
1251int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter); 1251int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1252int wl1271_acx_beacon_filter_table(struct wl1271 *wl); 1252 bool enable_filter);
1253int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable); 1253int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
1254 struct wl12xx_vif *wlvif);
1255int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1256 bool enable);
1254int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable); 1257int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
1255int wl12xx_acx_sg_cfg(struct wl1271 *wl); 1258int wl12xx_acx_sg_cfg(struct wl1271 *wl);
1256int wl1271_acx_cca_threshold(struct wl1271 *wl); 1259int wl1271_acx_cca_threshold(struct wl1271 *wl);
1257int wl1271_acx_bcn_dtim_options(struct wl1271 *wl); 1260int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1258int wl1271_acx_aid(struct wl1271 *wl, u16 aid); 1261int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid);
1259int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask); 1262int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
1260int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble); 1263int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1261int wl1271_acx_cts_protect(struct wl1271 *wl, 1264 enum acx_preamble_type preamble);
1265int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1262 enum acx_ctsprotect_type ctsprotect); 1266 enum acx_ctsprotect_type ctsprotect);
1263int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); 1267int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
1264int wl1271_acx_sta_rate_policies(struct wl1271 *wl); 1268int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1265int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c, 1269int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
1266 u8 idx); 1270 u8 idx);
1267int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max, 1271int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1268 u8 aifsn, u16 txop); 1272 u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop);
1269int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type, 1273int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1274 u8 queue_id, u8 channel_type,
1270 u8 tsid, u8 ps_scheme, u8 ack_policy, 1275 u8 tsid, u8 ps_scheme, u8 ack_policy,
1271 u32 apsd_conf0, u32 apsd_conf1); 1276 u32 apsd_conf0, u32 apsd_conf1);
1272int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold); 1277int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
@@ -1276,26 +1281,34 @@ int wl1271_acx_init_mem_config(struct wl1271 *wl);
1276int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap); 1281int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
1277int wl1271_acx_init_rx_interrupt(struct wl1271 *wl); 1282int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
1278int wl1271_acx_smart_reflex(struct wl1271 *wl); 1283int wl1271_acx_smart_reflex(struct wl1271 *wl);
1279int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable); 1284int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1280int wl1271_acx_arp_ip_filter(struct wl1271 *wl, u8 enable, __be32 address); 1285 bool enable);
1286int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1287 u8 enable, __be32 address);
1281int wl1271_acx_pm_config(struct wl1271 *wl); 1288int wl1271_acx_pm_config(struct wl1271 *wl);
1282int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable); 1289int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *vif,
1283int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid); 1290 bool enable);
1284int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable, 1291int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1285 s16 thold, u8 hyst); 1292 u8 index, u8 tpl_valid);
1286int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl); 1293int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1294 bool enable, s16 thold, u8 hyst);
1295int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
1296 struct wl12xx_vif *wlvif);
1287int wl1271_acx_set_ht_capabilities(struct wl1271 *wl, 1297int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
1288 struct ieee80211_sta_ht_cap *ht_cap, 1298 struct ieee80211_sta_ht_cap *ht_cap,
1289 bool allow_ht_operation, u8 hlid); 1299 bool allow_ht_operation, u8 hlid);
1290int wl1271_acx_set_ht_information(struct wl1271 *wl, 1300int wl1271_acx_set_ht_information(struct wl1271 *wl,
1301 struct wl12xx_vif *wlvif,
1291 u16 ht_operation_mode); 1302 u16 ht_operation_mode);
1292int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl); 1303int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
1304 struct wl12xx_vif *wlvif);
1293int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index, 1305int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
1294 u16 ssn, bool enable, u8 peer_hlid); 1306 u16 ssn, bool enable, u8 peer_hlid);
1295int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime); 1307int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime);
1296int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, bool enable); 1308int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1297int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl); 1309 bool enable);
1298int wl1271_acx_config_ps(struct wl1271 *wl); 1310int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1311int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1299int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr); 1312int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
1300int wl1271_acx_fm_coex(struct wl1271 *wl); 1313int wl1271_acx_fm_coex(struct wl1271 *wl);
1301int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl); 1314int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl);
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c
index 681337914976..8f9cf5a816ea 100644
--- a/drivers/net/wireless/wl12xx/boot.c
+++ b/drivers/net/wireless/wl12xx/boot.c
@@ -25,6 +25,7 @@
25#include <linux/wl12xx.h> 25#include <linux/wl12xx.h>
26#include <linux/export.h> 26#include <linux/export.h>
27 27
28#include "debug.h"
28#include "acx.h" 29#include "acx.h"
29#include "reg.h" 30#include "reg.h"
30#include "boot.h" 31#include "boot.h"
@@ -347,6 +348,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
347 nvs_ptr += 3; 348 nvs_ptr += 3;
348 349
349 for (i = 0; i < burst_len; i++) { 350 for (i = 0; i < burst_len; i++) {
351 if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
352 goto out_badnvs;
353
350 val = (nvs_ptr[0] | (nvs_ptr[1] << 8) 354 val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
351 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24)); 355 | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
352 356
@@ -358,6 +362,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
358 nvs_ptr += 4; 362 nvs_ptr += 4;
359 dest_addr += 4; 363 dest_addr += 4;
360 } 364 }
365
366 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
367 goto out_badnvs;
361 } 368 }
362 369
363 /* 370 /*
@@ -369,6 +376,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
369 */ 376 */
370 nvs_ptr = (u8 *)wl->nvs + 377 nvs_ptr = (u8 *)wl->nvs +
371 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4); 378 ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
379
380 if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
381 goto out_badnvs;
382
372 nvs_len -= nvs_ptr - (u8 *)wl->nvs; 383 nvs_len -= nvs_ptr - (u8 *)wl->nvs;
373 384
374 /* Now we must set the partition correctly */ 385 /* Now we must set the partition correctly */
@@ -384,6 +395,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
384 395
385 kfree(nvs_aligned); 396 kfree(nvs_aligned);
386 return 0; 397 return 0;
398
399out_badnvs:
400 wl1271_error("nvs data is malformed");
401 return -EILSEQ;
387} 402}
388 403
389static void wl1271_boot_enable_interrupts(struct wl1271 *wl) 404static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c
index a52299e548fa..e0d217979485 100644
--- a/drivers/net/wireless/wl12xx/cmd.c
+++ b/drivers/net/wireless/wl12xx/cmd.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31#include "wl12xx.h" 31#include "wl12xx.h"
32#include "debug.h"
32#include "reg.h" 33#include "reg.h"
33#include "io.h" 34#include "io.h"
34#include "acx.h" 35#include "acx.h"
@@ -120,6 +121,11 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
120 if (!wl->nvs) 121 if (!wl->nvs)
121 return -ENODEV; 122 return -ENODEV;
122 123
124 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
125 wl1271_warning("FEM index from INI out of bounds");
126 return -EINVAL;
127 }
128
123 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); 129 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
124 if (!gen_parms) 130 if (!gen_parms)
125 return -ENOMEM; 131 return -ENOMEM;
@@ -143,6 +149,12 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
143 gp->tx_bip_fem_manufacturer = 149 gp->tx_bip_fem_manufacturer =
144 gen_parms->general_params.tx_bip_fem_manufacturer; 150 gen_parms->general_params.tx_bip_fem_manufacturer;
145 151
152 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
153 wl1271_warning("FEM index from FW out of bounds");
154 ret = -EINVAL;
155 goto out;
156 }
157
146 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", 158 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
147 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); 159 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
148 160
@@ -162,6 +174,11 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
162 if (!wl->nvs) 174 if (!wl->nvs)
163 return -ENODEV; 175 return -ENODEV;
164 176
177 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
178 wl1271_warning("FEM index from ini out of bounds");
179 return -EINVAL;
180 }
181
165 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL); 182 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
166 if (!gen_parms) 183 if (!gen_parms)
167 return -ENOMEM; 184 return -ENOMEM;
@@ -186,6 +203,12 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
186 gp->tx_bip_fem_manufacturer = 203 gp->tx_bip_fem_manufacturer =
187 gen_parms->general_params.tx_bip_fem_manufacturer; 204 gen_parms->general_params.tx_bip_fem_manufacturer;
188 205
206 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
207 wl1271_warning("FEM index from FW out of bounds");
208 ret = -EINVAL;
209 goto out;
210 }
211
189 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n", 212 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
190 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer); 213 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
191 214
@@ -358,7 +381,8 @@ static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
358 return 0; 381 return 0;
359} 382}
360 383
361int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id) 384int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
385 u8 *role_id)
362{ 386{
363 struct wl12xx_cmd_role_enable *cmd; 387 struct wl12xx_cmd_role_enable *cmd;
364 int ret; 388 int ret;
@@ -381,7 +405,7 @@ int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id)
381 goto out_free; 405 goto out_free;
382 } 406 }
383 407
384 memcpy(cmd->mac_address, wl->mac_addr, ETH_ALEN); 408 memcpy(cmd->mac_address, addr, ETH_ALEN);
385 cmd->role_type = role_type; 409 cmd->role_type = role_type;
386 410
387 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); 411 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
@@ -433,37 +457,41 @@ out:
433 return ret; 457 return ret;
434} 458}
435 459
436static int wl12xx_allocate_link(struct wl1271 *wl, u8 *hlid) 460int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
437{ 461{
438 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS); 462 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
439 if (link >= WL12XX_MAX_LINKS) 463 if (link >= WL12XX_MAX_LINKS)
440 return -EBUSY; 464 return -EBUSY;
441 465
442 __set_bit(link, wl->links_map); 466 __set_bit(link, wl->links_map);
467 __set_bit(link, wlvif->links_map);
443 *hlid = link; 468 *hlid = link;
444 return 0; 469 return 0;
445} 470}
446 471
447static void wl12xx_free_link(struct wl1271 *wl, u8 *hlid) 472void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
448{ 473{
449 if (*hlid == WL12XX_INVALID_LINK_ID) 474 if (*hlid == WL12XX_INVALID_LINK_ID)
450 return; 475 return;
451 476
452 __clear_bit(*hlid, wl->links_map); 477 __clear_bit(*hlid, wl->links_map);
478 __clear_bit(*hlid, wlvif->links_map);
453 *hlid = WL12XX_INVALID_LINK_ID; 479 *hlid = WL12XX_INVALID_LINK_ID;
454} 480}
455 481
456static int wl12xx_get_new_session_id(struct wl1271 *wl) 482static int wl12xx_get_new_session_id(struct wl1271 *wl,
483 struct wl12xx_vif *wlvif)
457{ 484{
458 if (wl->session_counter >= SESSION_COUNTER_MAX) 485 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
459 wl->session_counter = 0; 486 wlvif->session_counter = 0;
460 487
461 wl->session_counter++; 488 wlvif->session_counter++;
462 489
463 return wl->session_counter; 490 return wlvif->session_counter;
464} 491}
465 492
466int wl12xx_cmd_role_start_dev(struct wl1271 *wl) 493static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
494 struct wl12xx_vif *wlvif)
467{ 495{
468 struct wl12xx_cmd_role_start *cmd; 496 struct wl12xx_cmd_role_start *cmd;
469 int ret; 497 int ret;
@@ -474,20 +502,20 @@ int wl12xx_cmd_role_start_dev(struct wl1271 *wl)
474 goto out; 502 goto out;
475 } 503 }
476 504
477 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wl->dev_role_id); 505 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
478 506
479 cmd->role_id = wl->dev_role_id; 507 cmd->role_id = wlvif->dev_role_id;
480 if (wl->band == IEEE80211_BAND_5GHZ) 508 if (wlvif->band == IEEE80211_BAND_5GHZ)
481 cmd->band = WL12XX_BAND_5GHZ; 509 cmd->band = WL12XX_BAND_5GHZ;
482 cmd->channel = wl->channel; 510 cmd->channel = wlvif->channel;
483 511
484 if (wl->dev_hlid == WL12XX_INVALID_LINK_ID) { 512 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
485 ret = wl12xx_allocate_link(wl, &wl->dev_hlid); 513 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
486 if (ret) 514 if (ret)
487 goto out_free; 515 goto out_free;
488 } 516 }
489 cmd->device.hlid = wl->dev_hlid; 517 cmd->device.hlid = wlvif->dev_hlid;
490 cmd->device.session = wl->session_counter; 518 cmd->device.session = wlvif->session_counter;
491 519
492 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", 520 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
493 cmd->role_id, cmd->device.hlid, cmd->device.session); 521 cmd->role_id, cmd->device.hlid, cmd->device.session);
@@ -502,9 +530,7 @@ int wl12xx_cmd_role_start_dev(struct wl1271 *wl)
502 530
503err_hlid: 531err_hlid:
504 /* clear links on error */ 532 /* clear links on error */
505 __clear_bit(wl->dev_hlid, wl->links_map); 533 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
506 wl->dev_hlid = WL12XX_INVALID_LINK_ID;
507
508 534
509out_free: 535out_free:
510 kfree(cmd); 536 kfree(cmd);
@@ -513,12 +539,13 @@ out:
513 return ret; 539 return ret;
514} 540}
515 541
516int wl12xx_cmd_role_stop_dev(struct wl1271 *wl) 542static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
543 struct wl12xx_vif *wlvif)
517{ 544{
518 struct wl12xx_cmd_role_stop *cmd; 545 struct wl12xx_cmd_role_stop *cmd;
519 int ret; 546 int ret;
520 547
521 if (WARN_ON(wl->dev_hlid == WL12XX_INVALID_LINK_ID)) 548 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
522 return -EINVAL; 549 return -EINVAL;
523 550
524 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 551 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -529,7 +556,7 @@ int wl12xx_cmd_role_stop_dev(struct wl1271 *wl)
529 556
530 wl1271_debug(DEBUG_CMD, "cmd role stop dev"); 557 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
531 558
532 cmd->role_id = wl->dev_role_id; 559 cmd->role_id = wlvif->dev_role_id;
533 cmd->disc_type = DISCONNECT_IMMEDIATE; 560 cmd->disc_type = DISCONNECT_IMMEDIATE;
534 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 561 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
535 562
@@ -545,7 +572,7 @@ int wl12xx_cmd_role_stop_dev(struct wl1271 *wl)
545 goto out_free; 572 goto out_free;
546 } 573 }
547 574
548 wl12xx_free_link(wl, &wl->dev_hlid); 575 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
549 576
550out_free: 577out_free:
551 kfree(cmd); 578 kfree(cmd);
@@ -554,8 +581,9 @@ out:
554 return ret; 581 return ret;
555} 582}
556 583
557int wl12xx_cmd_role_start_sta(struct wl1271 *wl) 584int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
558{ 585{
586 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
559 struct wl12xx_cmd_role_start *cmd; 587 struct wl12xx_cmd_role_start *cmd;
560 int ret; 588 int ret;
561 589
@@ -565,33 +593,33 @@ int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
565 goto out; 593 goto out;
566 } 594 }
567 595
568 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wl->role_id); 596 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
569 597
570 cmd->role_id = wl->role_id; 598 cmd->role_id = wlvif->role_id;
571 if (wl->band == IEEE80211_BAND_5GHZ) 599 if (wlvif->band == IEEE80211_BAND_5GHZ)
572 cmd->band = WL12XX_BAND_5GHZ; 600 cmd->band = WL12XX_BAND_5GHZ;
573 cmd->channel = wl->channel; 601 cmd->channel = wlvif->channel;
574 cmd->sta.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 602 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
575 cmd->sta.beacon_interval = cpu_to_le16(wl->beacon_int); 603 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
576 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; 604 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
577 cmd->sta.ssid_len = wl->ssid_len; 605 cmd->sta.ssid_len = wlvif->ssid_len;
578 memcpy(cmd->sta.ssid, wl->ssid, wl->ssid_len); 606 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
579 memcpy(cmd->sta.bssid, wl->bssid, ETH_ALEN); 607 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
580 cmd->sta.local_rates = cpu_to_le32(wl->rate_set); 608 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
581 609
582 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) { 610 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
583 ret = wl12xx_allocate_link(wl, &wl->sta_hlid); 611 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
584 if (ret) 612 if (ret)
585 goto out_free; 613 goto out_free;
586 } 614 }
587 cmd->sta.hlid = wl->sta_hlid; 615 cmd->sta.hlid = wlvif->sta.hlid;
588 cmd->sta.session = wl12xx_get_new_session_id(wl); 616 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
589 cmd->sta.remote_rates = cpu_to_le32(wl->rate_set); 617 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
590 618
591 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 619 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
592 "basic_rate_set: 0x%x, remote_rates: 0x%x", 620 "basic_rate_set: 0x%x, remote_rates: 0x%x",
593 wl->role_id, cmd->sta.hlid, cmd->sta.session, 621 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
594 wl->basic_rate_set, wl->rate_set); 622 wlvif->basic_rate_set, wlvif->rate_set);
595 623
596 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 624 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
597 if (ret < 0) { 625 if (ret < 0) {
@@ -603,7 +631,7 @@ int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
603 631
604err_hlid: 632err_hlid:
605 /* clear links on error. */ 633 /* clear links on error. */
606 wl12xx_free_link(wl, &wl->sta_hlid); 634 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
607 635
608out_free: 636out_free:
609 kfree(cmd); 637 kfree(cmd);
@@ -613,12 +641,12 @@ out:
613} 641}
614 642
615/* use this function to stop ibss as well */ 643/* use this function to stop ibss as well */
616int wl12xx_cmd_role_stop_sta(struct wl1271 *wl) 644int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
617{ 645{
618 struct wl12xx_cmd_role_stop *cmd; 646 struct wl12xx_cmd_role_stop *cmd;
619 int ret; 647 int ret;
620 648
621 if (WARN_ON(wl->sta_hlid == WL12XX_INVALID_LINK_ID)) 649 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
622 return -EINVAL; 650 return -EINVAL;
623 651
624 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 652 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -627,9 +655,9 @@ int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
627 goto out; 655 goto out;
628 } 656 }
629 657
630 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wl->role_id); 658 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
631 659
632 cmd->role_id = wl->role_id; 660 cmd->role_id = wlvif->role_id;
633 cmd->disc_type = DISCONNECT_IMMEDIATE; 661 cmd->disc_type = DISCONNECT_IMMEDIATE;
634 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 662 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
635 663
@@ -639,7 +667,7 @@ int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
639 goto out_free; 667 goto out_free;
640 } 668 }
641 669
642 wl12xx_free_link(wl, &wl->sta_hlid); 670 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
643 671
644out_free: 672out_free:
645 kfree(cmd); 673 kfree(cmd);
@@ -648,16 +676,17 @@ out:
648 return ret; 676 return ret;
649} 677}
650 678
651int wl12xx_cmd_role_start_ap(struct wl1271 *wl) 679int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
652{ 680{
653 struct wl12xx_cmd_role_start *cmd; 681 struct wl12xx_cmd_role_start *cmd;
654 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 682 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
683 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
655 int ret; 684 int ret;
656 685
657 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wl->role_id); 686 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
658 687
659 /* trying to use hidden SSID with an old hostapd version */ 688 /* trying to use hidden SSID with an old hostapd version */
660 if (wl->ssid_len == 0 && !bss_conf->hidden_ssid) { 689 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
661 wl1271_error("got a null SSID from beacon/bss"); 690 wl1271_error("got a null SSID from beacon/bss");
662 ret = -EINVAL; 691 ret = -EINVAL;
663 goto out; 692 goto out;
@@ -669,30 +698,30 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
669 goto out; 698 goto out;
670 } 699 }
671 700
672 ret = wl12xx_allocate_link(wl, &wl->ap_global_hlid); 701 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
673 if (ret < 0) 702 if (ret < 0)
674 goto out_free; 703 goto out_free;
675 704
676 ret = wl12xx_allocate_link(wl, &wl->ap_bcast_hlid); 705 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
677 if (ret < 0) 706 if (ret < 0)
678 goto out_free_global; 707 goto out_free_global;
679 708
680 cmd->role_id = wl->role_id; 709 cmd->role_id = wlvif->role_id;
681 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); 710 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
682 cmd->ap.bss_index = WL1271_AP_BSS_INDEX; 711 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
683 cmd->ap.global_hlid = wl->ap_global_hlid; 712 cmd->ap.global_hlid = wlvif->ap.global_hlid;
684 cmd->ap.broadcast_hlid = wl->ap_bcast_hlid; 713 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
685 cmd->ap.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 714 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
686 cmd->ap.beacon_interval = cpu_to_le16(wl->beacon_int); 715 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
687 cmd->ap.dtim_interval = bss_conf->dtim_period; 716 cmd->ap.dtim_interval = bss_conf->dtim_period;
688 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; 717 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
689 cmd->channel = wl->channel; 718 cmd->channel = wlvif->channel;
690 719
691 if (!bss_conf->hidden_ssid) { 720 if (!bss_conf->hidden_ssid) {
692 /* take the SSID from the beacon for backward compatibility */ 721 /* take the SSID from the beacon for backward compatibility */
693 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; 722 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
694 cmd->ap.ssid_len = wl->ssid_len; 723 cmd->ap.ssid_len = wlvif->ssid_len;
695 memcpy(cmd->ap.ssid, wl->ssid, wl->ssid_len); 724 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
696 } else { 725 } else {
697 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; 726 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
698 cmd->ap.ssid_len = bss_conf->ssid_len; 727 cmd->ap.ssid_len = bss_conf->ssid_len;
@@ -701,7 +730,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
701 730
702 cmd->ap.local_rates = cpu_to_le32(0xffffffff); 731 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
703 732
704 switch (wl->band) { 733 switch (wlvif->band) {
705 case IEEE80211_BAND_2GHZ: 734 case IEEE80211_BAND_2GHZ:
706 cmd->band = RADIO_BAND_2_4GHZ; 735 cmd->band = RADIO_BAND_2_4GHZ;
707 break; 736 break;
@@ -709,7 +738,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
709 cmd->band = RADIO_BAND_5GHZ; 738 cmd->band = RADIO_BAND_5GHZ;
710 break; 739 break;
711 default: 740 default:
712 wl1271_warning("ap start - unknown band: %d", (int)wl->band); 741 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
713 cmd->band = RADIO_BAND_2_4GHZ; 742 cmd->band = RADIO_BAND_2_4GHZ;
714 break; 743 break;
715 } 744 }
@@ -723,10 +752,10 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
723 goto out_free; 752 goto out_free;
724 753
725out_free_bcast: 754out_free_bcast:
726 wl12xx_free_link(wl, &wl->ap_bcast_hlid); 755 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
727 756
728out_free_global: 757out_free_global:
729 wl12xx_free_link(wl, &wl->ap_global_hlid); 758 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
730 759
731out_free: 760out_free:
732 kfree(cmd); 761 kfree(cmd);
@@ -735,7 +764,7 @@ out:
735 return ret; 764 return ret;
736} 765}
737 766
738int wl12xx_cmd_role_stop_ap(struct wl1271 *wl) 767int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
739{ 768{
740 struct wl12xx_cmd_role_stop *cmd; 769 struct wl12xx_cmd_role_stop *cmd;
741 int ret; 770 int ret;
@@ -746,9 +775,9 @@ int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
746 goto out; 775 goto out;
747 } 776 }
748 777
749 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wl->role_id); 778 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
750 779
751 cmd->role_id = wl->role_id; 780 cmd->role_id = wlvif->role_id;
752 781
753 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); 782 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
754 if (ret < 0) { 783 if (ret < 0) {
@@ -756,8 +785,8 @@ int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
756 goto out_free; 785 goto out_free;
757 } 786 }
758 787
759 wl12xx_free_link(wl, &wl->ap_bcast_hlid); 788 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
760 wl12xx_free_link(wl, &wl->ap_global_hlid); 789 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
761 790
762out_free: 791out_free:
763 kfree(cmd); 792 kfree(cmd);
@@ -766,10 +795,11 @@ out:
766 return ret; 795 return ret;
767} 796}
768 797
769int wl12xx_cmd_role_start_ibss(struct wl1271 *wl) 798int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
770{ 799{
800 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
771 struct wl12xx_cmd_role_start *cmd; 801 struct wl12xx_cmd_role_start *cmd;
772 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 802 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
773 int ret; 803 int ret;
774 804
775 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -778,35 +808,36 @@ int wl12xx_cmd_role_start_ibss(struct wl1271 *wl)
778 goto out; 808 goto out;
779 } 809 }
780 810
781 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wl->role_id); 811 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
782 812
783 cmd->role_id = wl->role_id; 813 cmd->role_id = wlvif->role_id;
784 if (wl->band == IEEE80211_BAND_5GHZ) 814 if (wlvif->band == IEEE80211_BAND_5GHZ)
785 cmd->band = WL12XX_BAND_5GHZ; 815 cmd->band = WL12XX_BAND_5GHZ;
786 cmd->channel = wl->channel; 816 cmd->channel = wlvif->channel;
787 cmd->ibss.basic_rate_set = cpu_to_le32(wl->basic_rate_set); 817 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
788 cmd->ibss.beacon_interval = cpu_to_le16(wl->beacon_int); 818 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
789 cmd->ibss.dtim_interval = bss_conf->dtim_period; 819 cmd->ibss.dtim_interval = bss_conf->dtim_period;
790 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; 820 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
791 cmd->ibss.ssid_len = wl->ssid_len; 821 cmd->ibss.ssid_len = wlvif->ssid_len;
792 memcpy(cmd->ibss.ssid, wl->ssid, wl->ssid_len); 822 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
793 memcpy(cmd->ibss.bssid, wl->bssid, ETH_ALEN); 823 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
794 cmd->sta.local_rates = cpu_to_le32(wl->rate_set); 824 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
795 825
796 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) { 826 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
797 ret = wl12xx_allocate_link(wl, &wl->sta_hlid); 827 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
798 if (ret) 828 if (ret)
799 goto out_free; 829 goto out_free;
800 } 830 }
801 cmd->ibss.hlid = wl->sta_hlid; 831 cmd->ibss.hlid = wlvif->sta.hlid;
802 cmd->ibss.remote_rates = cpu_to_le32(wl->rate_set); 832 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
803 833
804 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " 834 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
805 "basic_rate_set: 0x%x, remote_rates: 0x%x", 835 "basic_rate_set: 0x%x, remote_rates: 0x%x",
806 wl->role_id, cmd->sta.hlid, cmd->sta.session, 836 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
807 wl->basic_rate_set, wl->rate_set); 837 wlvif->basic_rate_set, wlvif->rate_set);
808 838
809 wl1271_debug(DEBUG_CMD, "wl->bssid = %pM", wl->bssid); 839 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
840 vif->bss_conf.bssid);
810 841
811 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); 842 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
812 if (ret < 0) { 843 if (ret < 0) {
@@ -818,7 +849,7 @@ int wl12xx_cmd_role_start_ibss(struct wl1271 *wl)
818 849
819err_hlid: 850err_hlid:
820 /* clear links on error. */ 851 /* clear links on error. */
821 wl12xx_free_link(wl, &wl->sta_hlid); 852 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
822 853
823out_free: 854out_free:
824 kfree(cmd); 855 kfree(cmd);
@@ -962,7 +993,8 @@ out:
962 return ret; 993 return ret;
963} 994}
964 995
965int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode) 996int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
997 u8 ps_mode)
966{ 998{
967 struct wl1271_cmd_ps_params *ps_params = NULL; 999 struct wl1271_cmd_ps_params *ps_params = NULL;
968 int ret = 0; 1000 int ret = 0;
@@ -975,7 +1007,7 @@ int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
975 goto out; 1007 goto out;
976 } 1008 }
977 1009
978 ps_params->role_id = wl->role_id; 1010 ps_params->role_id = wlvif->role_id;
979 ps_params->ps_mode = ps_mode; 1011 ps_params->ps_mode = ps_mode;
980 1012
981 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, 1013 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
@@ -1030,7 +1062,7 @@ out:
1030 return ret; 1062 return ret;
1031} 1063}
1032 1064
1033int wl1271_cmd_build_null_data(struct wl1271 *wl) 1065int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1034{ 1066{
1035 struct sk_buff *skb = NULL; 1067 struct sk_buff *skb = NULL;
1036 int size; 1068 int size;
@@ -1038,11 +1070,12 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
1038 int ret = -ENOMEM; 1070 int ret = -ENOMEM;
1039 1071
1040 1072
1041 if (wl->bss_type == BSS_TYPE_IBSS) { 1073 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1042 size = sizeof(struct wl12xx_null_data_template); 1074 size = sizeof(struct wl12xx_null_data_template);
1043 ptr = NULL; 1075 ptr = NULL;
1044 } else { 1076 } else {
1045 skb = ieee80211_nullfunc_get(wl->hw, wl->vif); 1077 skb = ieee80211_nullfunc_get(wl->hw,
1078 wl12xx_wlvif_to_vif(wlvif));
1046 if (!skb) 1079 if (!skb)
1047 goto out; 1080 goto out;
1048 size = skb->len; 1081 size = skb->len;
@@ -1050,7 +1083,7 @@ int wl1271_cmd_build_null_data(struct wl1271 *wl)
1050 } 1083 }
1051 1084
1052 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0, 1085 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
1053 wl->basic_rate); 1086 wlvif->basic_rate);
1054 1087
1055out: 1088out:
1056 dev_kfree_skb(skb); 1089 dev_kfree_skb(skb);
@@ -1061,19 +1094,21 @@ out:
1061 1094
1062} 1095}
1063 1096
1064int wl1271_cmd_build_klv_null_data(struct wl1271 *wl) 1097int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1098 struct wl12xx_vif *wlvif)
1065{ 1099{
1100 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1066 struct sk_buff *skb = NULL; 1101 struct sk_buff *skb = NULL;
1067 int ret = -ENOMEM; 1102 int ret = -ENOMEM;
1068 1103
1069 skb = ieee80211_nullfunc_get(wl->hw, wl->vif); 1104 skb = ieee80211_nullfunc_get(wl->hw, vif);
1070 if (!skb) 1105 if (!skb)
1071 goto out; 1106 goto out;
1072 1107
1073 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, 1108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
1074 skb->data, skb->len, 1109 skb->data, skb->len,
1075 CMD_TEMPL_KLV_IDX_NULL_DATA, 1110 CMD_TEMPL_KLV_IDX_NULL_DATA,
1076 wl->basic_rate); 1111 wlvif->basic_rate);
1077 1112
1078out: 1113out:
1079 dev_kfree_skb(skb); 1114 dev_kfree_skb(skb);
@@ -1084,32 +1119,35 @@ out:
1084 1119
1085} 1120}
1086 1121
1087int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid) 1122int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1123 u16 aid)
1088{ 1124{
1125 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1089 struct sk_buff *skb; 1126 struct sk_buff *skb;
1090 int ret = 0; 1127 int ret = 0;
1091 1128
1092 skb = ieee80211_pspoll_get(wl->hw, wl->vif); 1129 skb = ieee80211_pspoll_get(wl->hw, vif);
1093 if (!skb) 1130 if (!skb)
1094 goto out; 1131 goto out;
1095 1132
1096 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data, 1133 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
1097 skb->len, 0, wl->basic_rate_set); 1134 skb->len, 0, wlvif->basic_rate_set);
1098 1135
1099out: 1136out:
1100 dev_kfree_skb(skb); 1137 dev_kfree_skb(skb);
1101 return ret; 1138 return ret;
1102} 1139}
1103 1140
1104int wl1271_cmd_build_probe_req(struct wl1271 *wl, 1141int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1105 const u8 *ssid, size_t ssid_len, 1142 const u8 *ssid, size_t ssid_len,
1106 const u8 *ie, size_t ie_len, u8 band) 1143 const u8 *ie, size_t ie_len, u8 band)
1107{ 1144{
1145 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1108 struct sk_buff *skb; 1146 struct sk_buff *skb;
1109 int ret; 1147 int ret;
1110 u32 rate; 1148 u32 rate;
1111 1149
1112 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len, 1150 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1113 ie, ie_len); 1151 ie, ie_len);
1114 if (!skb) { 1152 if (!skb) {
1115 ret = -ENOMEM; 1153 ret = -ENOMEM;
@@ -1118,7 +1156,7 @@ int wl1271_cmd_build_probe_req(struct wl1271 *wl,
1118 1156
1119 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len); 1157 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1120 1158
1121 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 1159 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1122 if (band == IEEE80211_BAND_2GHZ) 1160 if (band == IEEE80211_BAND_2GHZ)
1123 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, 1161 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1124 skb->data, skb->len, 0, rate); 1162 skb->data, skb->len, 0, rate);
@@ -1132,20 +1170,22 @@ out:
1132} 1170}
1133 1171
1134struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, 1172struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1173 struct wl12xx_vif *wlvif,
1135 struct sk_buff *skb) 1174 struct sk_buff *skb)
1136{ 1175{
1176 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1137 int ret; 1177 int ret;
1138 u32 rate; 1178 u32 rate;
1139 1179
1140 if (!skb) 1180 if (!skb)
1141 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif); 1181 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1142 if (!skb) 1182 if (!skb)
1143 goto out; 1183 goto out;
1144 1184
1145 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len); 1185 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1146 1186
1147 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[wl->band]); 1187 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1148 if (wl->band == IEEE80211_BAND_2GHZ) 1188 if (wlvif->band == IEEE80211_BAND_2GHZ)
1149 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, 1189 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1150 skb->data, skb->len, 0, rate); 1190 skb->data, skb->len, 0, rate);
1151 else 1191 else
@@ -1159,9 +1199,11 @@ out:
1159 return skb; 1199 return skb;
1160} 1200}
1161 1201
1162int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr) 1202int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1203 __be32 ip_addr)
1163{ 1204{
1164 int ret; 1205 int ret;
1206 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1165 struct wl12xx_arp_rsp_template tmpl; 1207 struct wl12xx_arp_rsp_template tmpl;
1166 struct ieee80211_hdr_3addr *hdr; 1208 struct ieee80211_hdr_3addr *hdr;
1167 struct arphdr *arp_hdr; 1209 struct arphdr *arp_hdr;
@@ -1173,8 +1215,8 @@ int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
1173 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 1215 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1174 IEEE80211_STYPE_DATA | 1216 IEEE80211_STYPE_DATA |
1175 IEEE80211_FCTL_TODS); 1217 IEEE80211_FCTL_TODS);
1176 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN); 1218 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1177 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN); 1219 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1178 memset(hdr->addr3, 0xff, ETH_ALEN); 1220 memset(hdr->addr3, 0xff, ETH_ALEN);
1179 1221
1180 /* llc layer */ 1222 /* llc layer */
@@ -1190,25 +1232,26 @@ int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
1190 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); 1232 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1191 1233
1192 /* arp payload */ 1234 /* arp payload */
1193 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN); 1235 memcpy(tmpl.sender_hw, vif->addr, ETH_ALEN);
1194 tmpl.sender_ip = ip_addr; 1236 tmpl.sender_ip = ip_addr;
1195 1237
1196 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, 1238 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1197 &tmpl, sizeof(tmpl), 0, 1239 &tmpl, sizeof(tmpl), 0,
1198 wl->basic_rate); 1240 wlvif->basic_rate);
1199 1241
1200 return ret; 1242 return ret;
1201} 1243}
1202 1244
1203int wl1271_build_qos_null_data(struct wl1271 *wl) 1245int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1204{ 1246{
1247 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1205 struct ieee80211_qos_hdr template; 1248 struct ieee80211_qos_hdr template;
1206 1249
1207 memset(&template, 0, sizeof(template)); 1250 memset(&template, 0, sizeof(template));
1208 1251
1209 memcpy(template.addr1, wl->bssid, ETH_ALEN); 1252 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1210 memcpy(template.addr2, wl->mac_addr, ETH_ALEN); 1253 memcpy(template.addr2, vif->addr, ETH_ALEN);
1211 memcpy(template.addr3, wl->bssid, ETH_ALEN); 1254 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1212 1255
1213 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | 1256 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1214 IEEE80211_STYPE_QOS_NULLFUNC | 1257 IEEE80211_STYPE_QOS_NULLFUNC |
@@ -1219,7 +1262,7 @@ int wl1271_build_qos_null_data(struct wl1271 *wl)
1219 1262
1220 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template, 1263 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
1221 sizeof(template), 0, 1264 sizeof(template), 0,
1222 wl->basic_rate); 1265 wlvif->basic_rate);
1223} 1266}
1224 1267
1225int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) 1268int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
@@ -1253,7 +1296,8 @@ out:
1253 return ret; 1296 return ret;
1254} 1297}
1255 1298
1256int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 1299int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1300 u16 action, u8 id, u8 key_type,
1257 u8 key_size, const u8 *key, const u8 *addr, 1301 u8 key_size, const u8 *key, const u8 *addr,
1258 u32 tx_seq_32, u16 tx_seq_16) 1302 u32 tx_seq_32, u16 tx_seq_16)
1259{ 1303{
@@ -1261,7 +1305,7 @@ int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1261 int ret = 0; 1305 int ret = 0;
1262 1306
1263 /* hlid might have already been deleted */ 1307 /* hlid might have already been deleted */
1264 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) 1308 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1265 return 0; 1309 return 0;
1266 1310
1267 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 1311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
@@ -1270,7 +1314,7 @@ int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1270 goto out; 1314 goto out;
1271 } 1315 }
1272 1316
1273 cmd->hlid = wl->sta_hlid; 1317 cmd->hlid = wlvif->sta.hlid;
1274 1318
1275 if (key_type == KEY_WEP) 1319 if (key_type == KEY_WEP)
1276 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; 1320 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
@@ -1321,9 +1365,10 @@ out:
1321 * TODO: merge with sta/ibss into 1 set_key function. 1365 * TODO: merge with sta/ibss into 1 set_key function.
1322 * note there are slight diffs 1366 * note there are slight diffs
1323 */ 1367 */
1324int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 1368int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1325 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 1369 u16 action, u8 id, u8 key_type,
1326 u16 tx_seq_16) 1370 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1371 u16 tx_seq_16)
1327{ 1372{
1328 struct wl1271_cmd_set_keys *cmd; 1373 struct wl1271_cmd_set_keys *cmd;
1329 int ret = 0; 1374 int ret = 0;
@@ -1333,7 +1378,7 @@ int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1333 if (!cmd) 1378 if (!cmd)
1334 return -ENOMEM; 1379 return -ENOMEM;
1335 1380
1336 if (hlid == wl->ap_bcast_hlid) { 1381 if (hlid == wlvif->ap.bcast_hlid) {
1337 if (key_type == KEY_WEP) 1382 if (key_type == KEY_WEP)
1338 lid_type = WEP_DEFAULT_LID_TYPE; 1383 lid_type = WEP_DEFAULT_LID_TYPE;
1339 else 1384 else
@@ -1411,7 +1456,8 @@ out:
1411 return ret; 1456 return ret;
1412} 1457}
1413 1458
1414int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid) 1459int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1460 struct ieee80211_sta *sta, u8 hlid)
1415{ 1461{
1416 struct wl12xx_cmd_add_peer *cmd; 1462 struct wl12xx_cmd_add_peer *cmd;
1417 int i, ret; 1463 int i, ret;
@@ -1438,13 +1484,13 @@ int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
1438 else 1484 else
1439 cmd->psd_type[i] = WL1271_PSD_LEGACY; 1485 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1440 1486
1441 sta_rates = sta->supp_rates[wl->band]; 1487 sta_rates = sta->supp_rates[wlvif->band];
1442 if (sta->ht_cap.ht_supported) 1488 if (sta->ht_cap.ht_supported)
1443 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET; 1489 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1444 1490
1445 cmd->supported_rates = 1491 cmd->supported_rates =
1446 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, 1492 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1447 wl->band)); 1493 wlvif->band));
1448 1494
1449 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", 1495 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1450 cmd->supported_rates, sta->uapsd_queues); 1496 cmd->supported_rates, sta->uapsd_queues);
@@ -1584,12 +1630,13 @@ out:
1584 return ret; 1630 return ret;
1585} 1631}
1586 1632
1587static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id) 1633static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1634 u8 role_id)
1588{ 1635{
1589 struct wl12xx_cmd_roc *cmd; 1636 struct wl12xx_cmd_roc *cmd;
1590 int ret = 0; 1637 int ret = 0;
1591 1638
1592 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wl->channel, role_id); 1639 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1593 1640
1594 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) 1641 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1595 return -EINVAL; 1642 return -EINVAL;
@@ -1601,8 +1648,8 @@ static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id)
1601 } 1648 }
1602 1649
1603 cmd->role_id = role_id; 1650 cmd->role_id = role_id;
1604 cmd->channel = wl->channel; 1651 cmd->channel = wlvif->channel;
1605 switch (wl->band) { 1652 switch (wlvif->band) {
1606 case IEEE80211_BAND_2GHZ: 1653 case IEEE80211_BAND_2GHZ:
1607 cmd->band = RADIO_BAND_2_4GHZ; 1654 cmd->band = RADIO_BAND_2_4GHZ;
1608 break; 1655 break;
@@ -1610,7 +1657,7 @@ static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id)
1610 cmd->band = RADIO_BAND_5GHZ; 1657 cmd->band = RADIO_BAND_5GHZ;
1611 break; 1658 break;
1612 default: 1659 default:
1613 wl1271_error("roc - unknown band: %d", (int)wl->band); 1660 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1614 ret = -EINVAL; 1661 ret = -EINVAL;
1615 goto out_free; 1662 goto out_free;
1616 } 1663 }
@@ -1657,14 +1704,14 @@ out:
1657 return ret; 1704 return ret;
1658} 1705}
1659 1706
1660int wl12xx_roc(struct wl1271 *wl, u8 role_id) 1707int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1661{ 1708{
1662 int ret = 0; 1709 int ret = 0;
1663 1710
1664 if (WARN_ON(test_bit(role_id, wl->roc_map))) 1711 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1665 return 0; 1712 return 0;
1666 1713
1667 ret = wl12xx_cmd_roc(wl, role_id); 1714 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1668 if (ret < 0) 1715 if (ret < 0)
1669 goto out; 1716 goto out;
1670 1717
@@ -1753,3 +1800,50 @@ out_free:
1753out: 1800out:
1754 return ret; 1801 return ret;
1755} 1802}
1803
1804/* start dev role and roc on its channel */
1805int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1806{
1807 int ret;
1808
1809 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1810 wlvif->bss_type == BSS_TYPE_IBSS)))
1811 return -EINVAL;
1812
1813 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1814 if (ret < 0)
1815 goto out;
1816
1817 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1818 if (ret < 0)
1819 goto out_stop;
1820
1821 return 0;
1822
1823out_stop:
1824 wl12xx_cmd_role_stop_dev(wl, wlvif);
1825out:
1826 return ret;
1827}
1828
1829/* croc dev hlid, and stop the role */
1830int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1831{
1832 int ret;
1833
1834 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1835 wlvif->bss_type == BSS_TYPE_IBSS)))
1836 return -EINVAL;
1837
1838 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1839 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1840 if (ret < 0)
1841 goto out;
1842 }
1843
1844 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
1845 if (ret < 0)
1846 goto out;
1847out:
1848 return ret;
1849}
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/cmd.h
index b7bd42769aa7..3f7d0b93c24d 100644
--- a/drivers/net/wireless/wl12xx/cmd.h
+++ b/drivers/net/wireless/wl12xx/cmd.h
@@ -36,45 +36,54 @@ int wl128x_cmd_general_parms(struct wl1271 *wl);
36int wl1271_cmd_radio_parms(struct wl1271 *wl); 36int wl1271_cmd_radio_parms(struct wl1271 *wl);
37int wl128x_cmd_radio_parms(struct wl1271 *wl); 37int wl128x_cmd_radio_parms(struct wl1271 *wl);
38int wl1271_cmd_ext_radio_parms(struct wl1271 *wl); 38int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
39int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id); 39int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
40 u8 *role_id);
40int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id); 41int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
41int wl12xx_cmd_role_start_dev(struct wl1271 *wl); 42int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
42int wl12xx_cmd_role_stop_dev(struct wl1271 *wl); 43int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
43int wl12xx_cmd_role_start_sta(struct wl1271 *wl); 44int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
44int wl12xx_cmd_role_stop_sta(struct wl1271 *wl); 45int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
45int wl12xx_cmd_role_start_ap(struct wl1271 *wl); 46int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif);
46int wl12xx_cmd_role_stop_ap(struct wl1271 *wl); 47int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
47int wl12xx_cmd_role_start_ibss(struct wl1271 *wl); 48int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
48int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer); 49int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
49int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len); 50int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
50int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len); 51int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
51int wl1271_cmd_data_path(struct wl1271 *wl, bool enable); 52int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
52int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode); 53int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
54 u8 ps_mode);
53int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer, 55int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
54 size_t len); 56 size_t len);
55int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id, 57int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
56 void *buf, size_t buf_len, int index, u32 rates); 58 void *buf, size_t buf_len, int index, u32 rates);
57int wl1271_cmd_build_null_data(struct wl1271 *wl); 59int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif);
58int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid); 60int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
59int wl1271_cmd_build_probe_req(struct wl1271 *wl, 61 u16 aid);
62int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
60 const u8 *ssid, size_t ssid_len, 63 const u8 *ssid, size_t ssid_len,
61 const u8 *ie, size_t ie_len, u8 band); 64 const u8 *ie, size_t ie_len, u8 band);
62struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, 65struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
66 struct wl12xx_vif *wlvif,
63 struct sk_buff *skb); 67 struct sk_buff *skb);
64int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr); 68int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
65int wl1271_build_qos_null_data(struct wl1271 *wl); 69 __be32 ip_addr);
66int wl1271_cmd_build_klv_null_data(struct wl1271 *wl); 70int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif);
71int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
72 struct wl12xx_vif *wlvif);
67int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid); 73int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid);
68int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 74int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
75 u16 action, u8 id, u8 key_type,
69 u8 key_size, const u8 *key, const u8 *addr, 76 u8 key_size, const u8 *key, const u8 *addr,
70 u32 tx_seq_32, u16 tx_seq_16); 77 u32 tx_seq_32, u16 tx_seq_16);
71int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 78int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
79 u16 action, u8 id, u8 key_type,
72 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 80 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
73 u16 tx_seq_16); 81 u16 tx_seq_16);
74int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid); 82int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid);
75int wl12xx_roc(struct wl1271 *wl, u8 role_id); 83int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id);
76int wl12xx_croc(struct wl1271 *wl, u8 role_id); 84int wl12xx_croc(struct wl1271 *wl, u8 role_id);
77int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid); 85int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
86 struct ieee80211_sta *sta, u8 hlid);
78int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid); 87int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid);
79int wl12xx_cmd_config_fwlog(struct wl1271 *wl); 88int wl12xx_cmd_config_fwlog(struct wl1271 *wl);
80int wl12xx_cmd_start_fwlog(struct wl1271 *wl); 89int wl12xx_cmd_start_fwlog(struct wl1271 *wl);
@@ -82,6 +91,9 @@ int wl12xx_cmd_stop_fwlog(struct wl1271 *wl);
82int wl12xx_cmd_channel_switch(struct wl1271 *wl, 91int wl12xx_cmd_channel_switch(struct wl1271 *wl,
83 struct ieee80211_channel_switch *ch_switch); 92 struct ieee80211_channel_switch *ch_switch);
84int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl); 93int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl);
94int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif,
95 u8 *hlid);
96void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid);
85 97
86enum wl1271_commands { 98enum wl1271_commands {
87 CMD_INTERROGATE = 1, /*use this to read information elements*/ 99 CMD_INTERROGATE = 1, /*use this to read information elements*/
diff --git a/drivers/net/wireless/wl12xx/conf.h b/drivers/net/wireless/wl12xx/conf.h
index 04bb8fbf93f9..1bcfb017058d 100644
--- a/drivers/net/wireless/wl12xx/conf.h
+++ b/drivers/net/wireless/wl12xx/conf.h
@@ -440,6 +440,10 @@ struct conf_rx_settings {
440 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ 440 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
441 CONF_HW_BIT_RATE_54MBPS) 441 CONF_HW_BIT_RATE_54MBPS)
442 442
443#define CONF_TX_CCK_RATES (CONF_HW_BIT_RATE_1MBPS | \
444 CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
445 CONF_HW_BIT_RATE_11MBPS)
446
443#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \ 447#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS | \
444 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \ 448 CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS | \
445 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \ 449 CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS | \
diff --git a/drivers/net/wireless/wl12xx/debug.h b/drivers/net/wireless/wl12xx/debug.h
new file mode 100644
index 000000000000..b85fd8c41e8f
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/debug.h
@@ -0,0 +1,101 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2011 Texas Instruments. All rights reserved.
5 * Copyright (C) 2008-2009 Nokia Corporation
6 *
7 * Contact: Luciano Coelho <coelho@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#ifndef __DEBUG_H__
26#define __DEBUG_H__
27
28#include <linux/bitops.h>
29#include <linux/printk.h>
30
31#define DRIVER_NAME "wl12xx"
32#define DRIVER_PREFIX DRIVER_NAME ": "
33
34enum {
35 DEBUG_NONE = 0,
36 DEBUG_IRQ = BIT(0),
37 DEBUG_SPI = BIT(1),
38 DEBUG_BOOT = BIT(2),
39 DEBUG_MAILBOX = BIT(3),
40 DEBUG_TESTMODE = BIT(4),
41 DEBUG_EVENT = BIT(5),
42 DEBUG_TX = BIT(6),
43 DEBUG_RX = BIT(7),
44 DEBUG_SCAN = BIT(8),
45 DEBUG_CRYPT = BIT(9),
46 DEBUG_PSM = BIT(10),
47 DEBUG_MAC80211 = BIT(11),
48 DEBUG_CMD = BIT(12),
49 DEBUG_ACX = BIT(13),
50 DEBUG_SDIO = BIT(14),
51 DEBUG_FILTERS = BIT(15),
52 DEBUG_ADHOC = BIT(16),
53 DEBUG_AP = BIT(17),
54 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
55 DEBUG_ALL = ~0,
56};
57
58extern u32 wl12xx_debug_level;
59
60#define DEBUG_DUMP_LIMIT 1024
61
62#define wl1271_error(fmt, arg...) \
63 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
64
65#define wl1271_warning(fmt, arg...) \
66 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
67
68#define wl1271_notice(fmt, arg...) \
69 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
70
71#define wl1271_info(fmt, arg...) \
72 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
73
74#define wl1271_debug(level, fmt, arg...) \
75 do { \
76 if (level & wl12xx_debug_level) \
77 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
78 } while (0)
79
80/* TODO: use pr_debug_hex_dump when it becomes available */
81#define wl1271_dump(level, prefix, buf, len) \
82 do { \
83 if (level & wl12xx_debug_level) \
84 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
85 DUMP_PREFIX_OFFSET, 16, 1, \
86 buf, \
87 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
88 0); \
89 } while (0)
90
91#define wl1271_dump_ascii(level, prefix, buf, len) \
92 do { \
93 if (level & wl12xx_debug_level) \
94 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
95 DUMP_PREFIX_OFFSET, 16, 1, \
96 buf, \
97 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
98 true); \
99 } while (0)
100
101#endif /* __DEBUG_H__ */
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
index 3999fd528302..2e14b436101f 100644
--- a/drivers/net/wireless/wl12xx/debugfs.c
+++ b/drivers/net/wireless/wl12xx/debugfs.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28 28
29#include "wl12xx.h" 29#include "wl12xx.h"
30#include "debug.h"
30#include "acx.h" 31#include "acx.h"
31#include "ps.h" 32#include "ps.h"
32#include "io.h" 33#include "io.h"
@@ -346,29 +347,14 @@ static ssize_t driver_state_read(struct file *file, char __user *user_buf,
346 DRIVER_STATE_PRINT_INT(tx_results_count); 347 DRIVER_STATE_PRINT_INT(tx_results_count);
347 DRIVER_STATE_PRINT_LHEX(flags); 348 DRIVER_STATE_PRINT_LHEX(flags);
348 DRIVER_STATE_PRINT_INT(tx_blocks_freed); 349 DRIVER_STATE_PRINT_INT(tx_blocks_freed);
349 DRIVER_STATE_PRINT_INT(tx_security_last_seq_lsb);
350 DRIVER_STATE_PRINT_INT(rx_counter); 350 DRIVER_STATE_PRINT_INT(rx_counter);
351 DRIVER_STATE_PRINT_INT(session_counter);
352 DRIVER_STATE_PRINT_INT(state); 351 DRIVER_STATE_PRINT_INT(state);
353 DRIVER_STATE_PRINT_INT(bss_type);
354 DRIVER_STATE_PRINT_INT(channel); 352 DRIVER_STATE_PRINT_INT(channel);
355 DRIVER_STATE_PRINT_HEX(rate_set);
356 DRIVER_STATE_PRINT_HEX(basic_rate_set);
357 DRIVER_STATE_PRINT_HEX(basic_rate);
358 DRIVER_STATE_PRINT_INT(band); 353 DRIVER_STATE_PRINT_INT(band);
359 DRIVER_STATE_PRINT_INT(beacon_int);
360 DRIVER_STATE_PRINT_INT(psm_entry_retry);
361 DRIVER_STATE_PRINT_INT(ps_poll_failures);
362 DRIVER_STATE_PRINT_INT(power_level); 354 DRIVER_STATE_PRINT_INT(power_level);
363 DRIVER_STATE_PRINT_INT(rssi_thold);
364 DRIVER_STATE_PRINT_INT(last_rssi_event);
365 DRIVER_STATE_PRINT_INT(sg_enabled); 355 DRIVER_STATE_PRINT_INT(sg_enabled);
366 DRIVER_STATE_PRINT_INT(enable_11a); 356 DRIVER_STATE_PRINT_INT(enable_11a);
367 DRIVER_STATE_PRINT_INT(noise); 357 DRIVER_STATE_PRINT_INT(noise);
368 DRIVER_STATE_PRINT_LHEX(ap_hlid_map[0]);
369 DRIVER_STATE_PRINT_INT(last_tx_hlid);
370 DRIVER_STATE_PRINT_INT(ba_support);
371 DRIVER_STATE_PRINT_HEX(ba_rx_bitmap);
372 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map); 358 DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
373 DRIVER_STATE_PRINT_LHEX(ap_ps_map); 359 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
374 DRIVER_STATE_PRINT_HEX(quirks); 360 DRIVER_STATE_PRINT_HEX(quirks);
@@ -399,6 +385,115 @@ static const struct file_operations driver_state_ops = {
399 .llseek = default_llseek, 385 .llseek = default_llseek,
400}; 386};
401 387
388static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
389 size_t count, loff_t *ppos)
390{
391 struct wl1271 *wl = file->private_data;
392 struct wl12xx_vif *wlvif;
393 int ret, res = 0;
394 const int buf_size = 4096;
395 char *buf;
396 char tmp_buf[64];
397
398 buf = kzalloc(buf_size, GFP_KERNEL);
399 if (!buf)
400 return -ENOMEM;
401
402 mutex_lock(&wl->mutex);
403
404#define VIF_STATE_PRINT(x, fmt) \
405 (res += scnprintf(buf + res, buf_size - res, \
406 #x " = " fmt "\n", wlvif->x))
407
408#define VIF_STATE_PRINT_LONG(x) VIF_STATE_PRINT(x, "%ld")
409#define VIF_STATE_PRINT_INT(x) VIF_STATE_PRINT(x, "%d")
410#define VIF_STATE_PRINT_STR(x) VIF_STATE_PRINT(x, "%s")
411#define VIF_STATE_PRINT_LHEX(x) VIF_STATE_PRINT(x, "0x%lx")
412#define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
413#define VIF_STATE_PRINT_HEX(x) VIF_STATE_PRINT(x, "0x%x")
414
415#define VIF_STATE_PRINT_NSTR(x, len) \
416 do { \
417 memset(tmp_buf, 0, sizeof(tmp_buf)); \
418 memcpy(tmp_buf, wlvif->x, \
419 min_t(u8, len, sizeof(tmp_buf) - 1)); \
420 res += scnprintf(buf + res, buf_size - res, \
421 #x " = %s\n", tmp_buf); \
422 } while (0)
423
424 wl12xx_for_each_wlvif(wl, wlvif) {
425 VIF_STATE_PRINT_INT(role_id);
426 VIF_STATE_PRINT_INT(bss_type);
427 VIF_STATE_PRINT_LHEX(flags);
428 VIF_STATE_PRINT_INT(p2p);
429 VIF_STATE_PRINT_INT(dev_role_id);
430 VIF_STATE_PRINT_INT(dev_hlid);
431
432 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
433 wlvif->bss_type == BSS_TYPE_IBSS) {
434 VIF_STATE_PRINT_INT(sta.hlid);
435 VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
436 VIF_STATE_PRINT_INT(sta.basic_rate_idx);
437 VIF_STATE_PRINT_INT(sta.ap_rate_idx);
438 VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
439 } else {
440 VIF_STATE_PRINT_INT(ap.global_hlid);
441 VIF_STATE_PRINT_INT(ap.bcast_hlid);
442 VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
443 VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
444 VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
445 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
446 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
447 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
448 VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
449 }
450 VIF_STATE_PRINT_INT(last_tx_hlid);
451 VIF_STATE_PRINT_LHEX(links_map[0]);
452 VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
453 VIF_STATE_PRINT_INT(band);
454 VIF_STATE_PRINT_INT(channel);
455 VIF_STATE_PRINT_HEX(bitrate_masks[0]);
456 VIF_STATE_PRINT_HEX(bitrate_masks[1]);
457 VIF_STATE_PRINT_HEX(basic_rate_set);
458 VIF_STATE_PRINT_HEX(basic_rate);
459 VIF_STATE_PRINT_HEX(rate_set);
460 VIF_STATE_PRINT_INT(beacon_int);
461 VIF_STATE_PRINT_INT(default_key);
462 VIF_STATE_PRINT_INT(aid);
463 VIF_STATE_PRINT_INT(session_counter);
464 VIF_STATE_PRINT_INT(ps_poll_failures);
465 VIF_STATE_PRINT_INT(psm_entry_retry);
466 VIF_STATE_PRINT_INT(power_level);
467 VIF_STATE_PRINT_INT(rssi_thold);
468 VIF_STATE_PRINT_INT(last_rssi_event);
469 VIF_STATE_PRINT_INT(ba_support);
470 VIF_STATE_PRINT_INT(ba_allowed);
471 VIF_STATE_PRINT_LLHEX(tx_security_seq);
472 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
473 }
474
475#undef VIF_STATE_PRINT_INT
476#undef VIF_STATE_PRINT_LONG
477#undef VIF_STATE_PRINT_HEX
478#undef VIF_STATE_PRINT_LHEX
479#undef VIF_STATE_PRINT_LLHEX
480#undef VIF_STATE_PRINT_STR
481#undef VIF_STATE_PRINT_NSTR
482#undef VIF_STATE_PRINT
483
484 mutex_unlock(&wl->mutex);
485
486 ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
487 kfree(buf);
488 return ret;
489}
490
491static const struct file_operations vifs_state_ops = {
492 .read = vifs_state_read,
493 .open = wl1271_open_file_generic,
494 .llseek = default_llseek,
495};
496
402static ssize_t dtim_interval_read(struct file *file, char __user *user_buf, 497static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
403 size_t count, loff_t *ppos) 498 size_t count, loff_t *ppos)
404{ 499{
@@ -520,6 +615,7 @@ static ssize_t rx_streaming_interval_write(struct file *file,
520 size_t count, loff_t *ppos) 615 size_t count, loff_t *ppos)
521{ 616{
522 struct wl1271 *wl = file->private_data; 617 struct wl1271 *wl = file->private_data;
618 struct wl12xx_vif *wlvif;
523 unsigned long value; 619 unsigned long value;
524 int ret; 620 int ret;
525 621
@@ -543,7 +639,9 @@ static ssize_t rx_streaming_interval_write(struct file *file,
543 if (ret < 0) 639 if (ret < 0)
544 goto out; 640 goto out;
545 641
546 wl1271_recalc_rx_streaming(wl); 642 wl12xx_for_each_wlvif_sta(wl, wlvif) {
643 wl1271_recalc_rx_streaming(wl, wlvif);
644 }
547 645
548 wl1271_ps_elp_sleep(wl); 646 wl1271_ps_elp_sleep(wl);
549out: 647out:
@@ -572,6 +670,7 @@ static ssize_t rx_streaming_always_write(struct file *file,
572 size_t count, loff_t *ppos) 670 size_t count, loff_t *ppos)
573{ 671{
574 struct wl1271 *wl = file->private_data; 672 struct wl1271 *wl = file->private_data;
673 struct wl12xx_vif *wlvif;
575 unsigned long value; 674 unsigned long value;
576 int ret; 675 int ret;
577 676
@@ -595,7 +694,9 @@ static ssize_t rx_streaming_always_write(struct file *file,
595 if (ret < 0) 694 if (ret < 0)
596 goto out; 695 goto out;
597 696
598 wl1271_recalc_rx_streaming(wl); 697 wl12xx_for_each_wlvif_sta(wl, wlvif) {
698 wl1271_recalc_rx_streaming(wl, wlvif);
699 }
599 700
600 wl1271_ps_elp_sleep(wl); 701 wl1271_ps_elp_sleep(wl);
601out: 702out:
@@ -624,6 +725,7 @@ static ssize_t beacon_filtering_write(struct file *file,
624 size_t count, loff_t *ppos) 725 size_t count, loff_t *ppos)
625{ 726{
626 struct wl1271 *wl = file->private_data; 727 struct wl1271 *wl = file->private_data;
728 struct wl12xx_vif *wlvif;
627 char buf[10]; 729 char buf[10];
628 size_t len; 730 size_t len;
629 unsigned long value; 731 unsigned long value;
@@ -646,7 +748,9 @@ static ssize_t beacon_filtering_write(struct file *file,
646 if (ret < 0) 748 if (ret < 0)
647 goto out; 749 goto out;
648 750
649 ret = wl1271_acx_beacon_filter_opt(wl, !!value); 751 wl12xx_for_each_wlvif(wl, wlvif) {
752 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
753 }
650 754
651 wl1271_ps_elp_sleep(wl); 755 wl1271_ps_elp_sleep(wl);
652out: 756out:
@@ -770,6 +874,7 @@ static int wl1271_debugfs_add_files(struct wl1271 *wl,
770 DEBUGFS_ADD(gpio_power, rootdir); 874 DEBUGFS_ADD(gpio_power, rootdir);
771 DEBUGFS_ADD(start_recovery, rootdir); 875 DEBUGFS_ADD(start_recovery, rootdir);
772 DEBUGFS_ADD(driver_state, rootdir); 876 DEBUGFS_ADD(driver_state, rootdir);
877 DEBUGFS_ADD(vifs_state, rootdir);
773 DEBUGFS_ADD(dtim_interval, rootdir); 878 DEBUGFS_ADD(dtim_interval, rootdir);
774 DEBUGFS_ADD(beacon_interval, rootdir); 879 DEBUGFS_ADD(beacon_interval, rootdir);
775 DEBUGFS_ADD(beacon_filtering, rootdir); 880 DEBUGFS_ADD(beacon_filtering, rootdir);
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c
index 674ad2a9e409..00ce794eebae 100644
--- a/drivers/net/wireless/wl12xx/event.c
+++ b/drivers/net/wireless/wl12xx/event.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "wl12xx.h" 24#include "wl12xx.h"
25#include "debug.h"
25#include "reg.h" 26#include "reg.h"
26#include "io.h" 27#include "io.h"
27#include "event.h" 28#include "event.h"
@@ -31,12 +32,16 @@
31 32
32void wl1271_pspoll_work(struct work_struct *work) 33void wl1271_pspoll_work(struct work_struct *work)
33{ 34{
35 struct ieee80211_vif *vif;
36 struct wl12xx_vif *wlvif;
34 struct delayed_work *dwork; 37 struct delayed_work *dwork;
35 struct wl1271 *wl; 38 struct wl1271 *wl;
36 int ret; 39 int ret;
37 40
38 dwork = container_of(work, struct delayed_work, work); 41 dwork = container_of(work, struct delayed_work, work);
39 wl = container_of(dwork, struct wl1271, pspoll_work); 42 wlvif = container_of(dwork, struct wl12xx_vif, pspoll_work);
43 vif = container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
44 wl = wlvif->wl;
40 45
41 wl1271_debug(DEBUG_EVENT, "pspoll work"); 46 wl1271_debug(DEBUG_EVENT, "pspoll work");
42 47
@@ -45,10 +50,10 @@ void wl1271_pspoll_work(struct work_struct *work)
45 if (unlikely(wl->state == WL1271_STATE_OFF)) 50 if (unlikely(wl->state == WL1271_STATE_OFF))
46 goto out; 51 goto out;
47 52
48 if (!test_and_clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags)) 53 if (!test_and_clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags))
49 goto out; 54 goto out;
50 55
51 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 56 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
52 goto out; 57 goto out;
53 58
54 /* 59 /*
@@ -60,31 +65,33 @@ void wl1271_pspoll_work(struct work_struct *work)
60 if (ret < 0) 65 if (ret < 0)
61 goto out; 66 goto out;
62 67
63 wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, wl->basic_rate, true); 68 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
69 wlvif->basic_rate, true);
64 70
65 wl1271_ps_elp_sleep(wl); 71 wl1271_ps_elp_sleep(wl);
66out: 72out:
67 mutex_unlock(&wl->mutex); 73 mutex_unlock(&wl->mutex);
68}; 74};
69 75
70static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl) 76static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl,
77 struct wl12xx_vif *wlvif)
71{ 78{
72 int delay = wl->conf.conn.ps_poll_recovery_period; 79 int delay = wl->conf.conn.ps_poll_recovery_period;
73 int ret; 80 int ret;
74 81
75 wl->ps_poll_failures++; 82 wlvif->ps_poll_failures++;
76 if (wl->ps_poll_failures == 1) 83 if (wlvif->ps_poll_failures == 1)
77 wl1271_info("AP with dysfunctional ps-poll, " 84 wl1271_info("AP with dysfunctional ps-poll, "
78 "trying to work around it."); 85 "trying to work around it.");
79 86
80 /* force active mode receive data from the AP */ 87 /* force active mode receive data from the AP */
81 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) { 88 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
82 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 89 ret = wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
83 wl->basic_rate, true); 90 wlvif->basic_rate, true);
84 if (ret < 0) 91 if (ret < 0)
85 return; 92 return;
86 set_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); 93 set_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
87 ieee80211_queue_delayed_work(wl->hw, &wl->pspoll_work, 94 ieee80211_queue_delayed_work(wl->hw, &wlvif->pspoll_work,
88 msecs_to_jiffies(delay)); 95 msecs_to_jiffies(delay));
89 } 96 }
90 97
@@ -97,6 +104,7 @@ static void wl1271_event_pspoll_delivery_fail(struct wl1271 *wl)
97} 104}
98 105
99static int wl1271_event_ps_report(struct wl1271 *wl, 106static int wl1271_event_ps_report(struct wl1271 *wl,
107 struct wl12xx_vif *wlvif,
100 struct event_mailbox *mbox, 108 struct event_mailbox *mbox,
101 bool *beacon_loss) 109 bool *beacon_loss)
102{ 110{
@@ -109,41 +117,37 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
109 case EVENT_ENTER_POWER_SAVE_FAIL: 117 case EVENT_ENTER_POWER_SAVE_FAIL:
110 wl1271_debug(DEBUG_PSM, "PSM entry failed"); 118 wl1271_debug(DEBUG_PSM, "PSM entry failed");
111 119
112 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { 120 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
113 /* remain in active mode */ 121 /* remain in active mode */
114 wl->psm_entry_retry = 0; 122 wlvif->psm_entry_retry = 0;
115 break; 123 break;
116 } 124 }
117 125
118 if (wl->psm_entry_retry < total_retries) { 126 if (wlvif->psm_entry_retry < total_retries) {
119 wl->psm_entry_retry++; 127 wlvif->psm_entry_retry++;
120 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 128 ret = wl1271_ps_set_mode(wl, wlvif,
121 wl->basic_rate, true); 129 STATION_POWER_SAVE_MODE,
130 wlvif->basic_rate, true);
122 } else { 131 } else {
123 wl1271_info("No ack to nullfunc from AP."); 132 wl1271_info("No ack to nullfunc from AP.");
124 wl->psm_entry_retry = 0; 133 wlvif->psm_entry_retry = 0;
125 *beacon_loss = true; 134 *beacon_loss = true;
126 } 135 }
127 break; 136 break;
128 case EVENT_ENTER_POWER_SAVE_SUCCESS: 137 case EVENT_ENTER_POWER_SAVE_SUCCESS:
129 wl->psm_entry_retry = 0; 138 wlvif->psm_entry_retry = 0;
130
131 /* enable beacon filtering */
132 ret = wl1271_acx_beacon_filter_opt(wl, true);
133 if (ret < 0)
134 break;
135 139
136 /* 140 /*
137 * BET has only a minor effect in 5GHz and masks 141 * BET has only a minor effect in 5GHz and masks
138 * channel switch IEs, so we only enable BET on 2.4GHz 142 * channel switch IEs, so we only enable BET on 2.4GHz
139 */ 143 */
140 if (wl->band == IEEE80211_BAND_2GHZ) 144 if (wlvif->band == IEEE80211_BAND_2GHZ)
141 /* enable beacon early termination */ 145 /* enable beacon early termination */
142 ret = wl1271_acx_bet_enable(wl, true); 146 ret = wl1271_acx_bet_enable(wl, wlvif, true);
143 147
144 if (wl->ps_compl) { 148 if (wlvif->ps_compl) {
145 complete(wl->ps_compl); 149 complete(wlvif->ps_compl);
146 wl->ps_compl = NULL; 150 wlvif->ps_compl = NULL;
147 } 151 }
148 break; 152 break;
149 default: 153 default:
@@ -154,39 +158,44 @@ static int wl1271_event_ps_report(struct wl1271 *wl,
154} 158}
155 159
156static void wl1271_event_rssi_trigger(struct wl1271 *wl, 160static void wl1271_event_rssi_trigger(struct wl1271 *wl,
161 struct wl12xx_vif *wlvif,
157 struct event_mailbox *mbox) 162 struct event_mailbox *mbox)
158{ 163{
164 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
159 enum nl80211_cqm_rssi_threshold_event event; 165 enum nl80211_cqm_rssi_threshold_event event;
160 s8 metric = mbox->rssi_snr_trigger_metric[0]; 166 s8 metric = mbox->rssi_snr_trigger_metric[0];
161 167
162 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric); 168 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
163 169
164 if (metric <= wl->rssi_thold) 170 if (metric <= wlvif->rssi_thold)
165 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW; 171 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
166 else 172 else
167 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH; 173 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
168 174
169 if (event != wl->last_rssi_event) 175 if (event != wlvif->last_rssi_event)
170 ieee80211_cqm_rssi_notify(wl->vif, event, GFP_KERNEL); 176 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
171 wl->last_rssi_event = event; 177 wlvif->last_rssi_event = event;
172} 178}
173 179
174static void wl1271_stop_ba_event(struct wl1271 *wl) 180static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
175{ 181{
176 if (wl->bss_type != BSS_TYPE_AP_BSS) { 182 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
177 if (!wl->ba_rx_bitmap) 183
184 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
185 if (!wlvif->sta.ba_rx_bitmap)
178 return; 186 return;
179 ieee80211_stop_rx_ba_session(wl->vif, wl->ba_rx_bitmap, 187 ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
180 wl->bssid); 188 vif->bss_conf.bssid);
181 } else { 189 } else {
182 int i; 190 u8 hlid;
183 struct wl1271_link *lnk; 191 struct wl1271_link *lnk;
184 for (i = WL1271_AP_STA_HLID_START; i < AP_MAX_LINKS; i++) { 192 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
185 lnk = &wl->links[i]; 193 WL12XX_MAX_LINKS) {
186 if (!wl1271_is_active_sta(wl, i) || !lnk->ba_bitmap) 194 lnk = &wl->links[hlid];
195 if (!lnk->ba_bitmap)
187 continue; 196 continue;
188 197
189 ieee80211_stop_rx_ba_session(wl->vif, 198 ieee80211_stop_rx_ba_session(vif,
190 lnk->ba_bitmap, 199 lnk->ba_bitmap,
191 lnk->addr); 200 lnk->addr);
192 } 201 }
@@ -196,14 +205,23 @@ static void wl1271_stop_ba_event(struct wl1271 *wl)
196static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl, 205static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
197 u8 enable) 206 u8 enable)
198{ 207{
208 struct ieee80211_vif *vif;
209 struct wl12xx_vif *wlvif;
210
199 if (enable) { 211 if (enable) {
200 /* disable dynamic PS when requested by the firmware */ 212 /* disable dynamic PS when requested by the firmware */
201 ieee80211_disable_dyn_ps(wl->vif); 213 wl12xx_for_each_wlvif_sta(wl, wlvif) {
214 vif = wl12xx_wlvif_to_vif(wlvif);
215 ieee80211_disable_dyn_ps(vif);
216 }
202 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); 217 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
203 } else { 218 } else {
204 ieee80211_enable_dyn_ps(wl->vif);
205 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags); 219 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
206 wl1271_recalc_rx_streaming(wl); 220 wl12xx_for_each_wlvif_sta(wl, wlvif) {
221 vif = wl12xx_wlvif_to_vif(wlvif);
222 ieee80211_enable_dyn_ps(vif);
223 wl1271_recalc_rx_streaming(wl, wlvif);
224 }
207 } 225 }
208 226
209} 227}
@@ -217,10 +235,11 @@ static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
217 235
218static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox) 236static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
219{ 237{
238 struct ieee80211_vif *vif;
239 struct wl12xx_vif *wlvif;
220 int ret; 240 int ret;
221 u32 vector; 241 u32 vector;
222 bool beacon_loss = false; 242 bool beacon_loss = false;
223 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
224 bool disconnect_sta = false; 243 bool disconnect_sta = false;
225 unsigned long sta_bitmap = 0; 244 unsigned long sta_bitmap = 0;
226 245
@@ -234,7 +253,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
234 wl1271_debug(DEBUG_EVENT, "status: 0x%x", 253 wl1271_debug(DEBUG_EVENT, "status: 0x%x",
235 mbox->scheduled_scan_status); 254 mbox->scheduled_scan_status);
236 255
237 wl1271_scan_stm(wl); 256 wl1271_scan_stm(wl, wl->scan_vif);
238 } 257 }
239 258
240 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) { 259 if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
@@ -253,8 +272,7 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
253 } 272 }
254 } 273 }
255 274
256 if (vector & SOFT_GEMINI_SENSE_EVENT_ID && 275 if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
257 wl->bss_type == BSS_TYPE_STA_BSS)
258 wl12xx_event_soft_gemini_sense(wl, 276 wl12xx_event_soft_gemini_sense(wl,
259 mbox->soft_gemini_sense_info); 277 mbox->soft_gemini_sense_info);
260 278
@@ -267,40 +285,54 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
267 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack. 285 * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
268 * 286 *
269 */ 287 */
270 if ((vector & BSS_LOSE_EVENT_ID) && !is_ap) { 288 if (vector & BSS_LOSE_EVENT_ID) {
289 /* TODO: check for multi-role */
271 wl1271_info("Beacon loss detected."); 290 wl1271_info("Beacon loss detected.");
272 291
273 /* indicate to the stack, that beacons have been lost */ 292 /* indicate to the stack, that beacons have been lost */
274 beacon_loss = true; 293 beacon_loss = true;
275 } 294 }
276 295
277 if ((vector & PS_REPORT_EVENT_ID) && !is_ap) { 296 if (vector & PS_REPORT_EVENT_ID) {
278 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT"); 297 wl1271_debug(DEBUG_EVENT, "PS_REPORT_EVENT");
279 ret = wl1271_event_ps_report(wl, mbox, &beacon_loss); 298 wl12xx_for_each_wlvif_sta(wl, wlvif) {
280 if (ret < 0) 299 ret = wl1271_event_ps_report(wl, wlvif,
281 return ret; 300 mbox, &beacon_loss);
301 if (ret < 0)
302 return ret;
303 }
282 } 304 }
283 305
284 if ((vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID) && !is_ap) 306 if (vector & PSPOLL_DELIVERY_FAILURE_EVENT_ID)
285 wl1271_event_pspoll_delivery_fail(wl); 307 wl12xx_for_each_wlvif_sta(wl, wlvif) {
308 wl1271_event_pspoll_delivery_fail(wl, wlvif);
309 }
286 310
287 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { 311 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
312 /* TODO: check actual multi-role support */
288 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT"); 313 wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
289 if (wl->vif) 314 wl12xx_for_each_wlvif_sta(wl, wlvif) {
290 wl1271_event_rssi_trigger(wl, mbox); 315 wl1271_event_rssi_trigger(wl, wlvif, mbox);
316 }
291 } 317 }
292 318
293 if ((vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID)) { 319 if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
320 u8 role_id = mbox->role_id;
294 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. " 321 wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
295 "ba_allowed = 0x%x", mbox->rx_ba_allowed); 322 "ba_allowed = 0x%x, role_id=%d",
323 mbox->rx_ba_allowed, role_id);
296 324
297 wl->ba_allowed = !!mbox->rx_ba_allowed; 325 wl12xx_for_each_wlvif(wl, wlvif) {
326 if (role_id != 0xff && role_id != wlvif->role_id)
327 continue;
298 328
299 if (wl->vif && !wl->ba_allowed) 329 wlvif->ba_allowed = !!mbox->rx_ba_allowed;
300 wl1271_stop_ba_event(wl); 330 if (!wlvif->ba_allowed)
331 wl1271_stop_ba_event(wl, wlvif);
332 }
301 } 333 }
302 334
303 if ((vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) && !is_ap) { 335 if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
304 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. " 336 wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
305 "status = 0x%x", 337 "status = 0x%x",
306 mbox->channel_switch_status); 338 mbox->channel_switch_status);
@@ -309,50 +341,65 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
309 * 1) channel switch complete with status=0 341 * 1) channel switch complete with status=0
310 * 2) channel switch failed status=1 342 * 2) channel switch failed status=1
311 */ 343 */
312 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags) && 344
313 (wl->vif)) 345 /* TODO: configure only the relevant vif */
314 ieee80211_chswitch_done(wl->vif, 346 wl12xx_for_each_wlvif_sta(wl, wlvif) {
315 mbox->channel_switch_status ? false : true); 347 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
348 bool success;
349
350 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
351 &wl->flags))
352 continue;
353
354 success = mbox->channel_switch_status ? false : true;
355 ieee80211_chswitch_done(vif, success);
356 }
316 } 357 }
317 358
318 if ((vector & DUMMY_PACKET_EVENT_ID)) { 359 if ((vector & DUMMY_PACKET_EVENT_ID)) {
319 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID"); 360 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
320 if (wl->vif) 361 wl1271_tx_dummy_packet(wl);
321 wl1271_tx_dummy_packet(wl);
322 } 362 }
323 363
324 /* 364 /*
325 * "TX retries exceeded" has a different meaning according to mode. 365 * "TX retries exceeded" has a different meaning according to mode.
326 * In AP mode the offending station is disconnected. 366 * In AP mode the offending station is disconnected.
327 */ 367 */
328 if ((vector & MAX_TX_RETRY_EVENT_ID) && is_ap) { 368 if (vector & MAX_TX_RETRY_EVENT_ID) {
329 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID"); 369 wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
330 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded); 370 sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
331 disconnect_sta = true; 371 disconnect_sta = true;
332 } 372 }
333 373
334 if ((vector & INACTIVE_STA_EVENT_ID) && is_ap) { 374 if (vector & INACTIVE_STA_EVENT_ID) {
335 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID"); 375 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
336 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status); 376 sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
337 disconnect_sta = true; 377 disconnect_sta = true;
338 } 378 }
339 379
340 if (is_ap && disconnect_sta) { 380 if (disconnect_sta) {
341 u32 num_packets = wl->conf.tx.max_tx_retries; 381 u32 num_packets = wl->conf.tx.max_tx_retries;
342 struct ieee80211_sta *sta; 382 struct ieee80211_sta *sta;
343 const u8 *addr; 383 const u8 *addr;
344 int h; 384 int h;
345 385
346 for (h = find_first_bit(&sta_bitmap, AP_MAX_LINKS); 386 for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
347 h < AP_MAX_LINKS; 387 bool found = false;
348 h = find_next_bit(&sta_bitmap, AP_MAX_LINKS, h+1)) { 388 /* find the ap vif connected to this sta */
349 if (!wl1271_is_active_sta(wl, h)) 389 wl12xx_for_each_wlvif_ap(wl, wlvif) {
390 if (!test_bit(h, wlvif->ap.sta_hlid_map))
391 continue;
392 found = true;
393 break;
394 }
395 if (!found)
350 continue; 396 continue;
351 397
398 vif = wl12xx_wlvif_to_vif(wlvif);
352 addr = wl->links[h].addr; 399 addr = wl->links[h].addr;
353 400
354 rcu_read_lock(); 401 rcu_read_lock();
355 sta = ieee80211_find_sta(wl->vif, addr); 402 sta = ieee80211_find_sta(vif, addr);
356 if (sta) { 403 if (sta) {
357 wl1271_debug(DEBUG_EVENT, "remove sta %d", h); 404 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
358 ieee80211_report_low_ack(sta, num_packets); 405 ieee80211_report_low_ack(sta, num_packets);
@@ -361,8 +408,11 @@ static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
361 } 408 }
362 } 409 }
363 410
364 if (wl->vif && beacon_loss) 411 if (beacon_loss)
365 ieee80211_connection_loss(wl->vif); 412 wl12xx_for_each_wlvif_sta(wl, wlvif) {
413 vif = wl12xx_wlvif_to_vif(wlvif);
414 ieee80211_connection_loss(vif);
415 }
366 416
367 return 0; 417 return 0;
368} 418}
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/event.h
index 49c1a0ede5b1..1d878ba47bf4 100644
--- a/drivers/net/wireless/wl12xx/event.h
+++ b/drivers/net/wireless/wl12xx/event.h
@@ -132,7 +132,4 @@ void wl1271_event_mbox_config(struct wl1271 *wl);
132int wl1271_event_handle(struct wl1271 *wl, u8 mbox); 132int wl1271_event_handle(struct wl1271 *wl, u8 mbox);
133void wl1271_pspoll_work(struct work_struct *work); 133void wl1271_pspoll_work(struct work_struct *work);
134 134
135/* Functions from main.c */
136bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid);
137
138#endif 135#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c
index 04db64c94e9a..88891cdfdd4a 100644
--- a/drivers/net/wireless/wl12xx/init.c
+++ b/drivers/net/wireless/wl12xx/init.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27 27
28#include "debug.h"
28#include "init.h" 29#include "init.h"
29#include "wl12xx_80211.h" 30#include "wl12xx_80211.h"
30#include "acx.h" 31#include "acx.h"
@@ -33,7 +34,7 @@
33#include "tx.h" 34#include "tx.h"
34#include "io.h" 35#include "io.h"
35 36
36int wl1271_sta_init_templates_config(struct wl1271 *wl) 37int wl1271_init_templates_config(struct wl1271 *wl)
37{ 38{
38 int ret, i; 39 int ret, i;
39 40
@@ -64,7 +65,7 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
64 65
65 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL, 66 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
66 sizeof 67 sizeof
67 (struct wl12xx_qos_null_data_template), 68 (struct ieee80211_qos_hdr),
68 0, WL1271_RATE_AUTOMATIC); 69 0, WL1271_RATE_AUTOMATIC);
69 if (ret < 0) 70 if (ret < 0)
70 return ret; 71 return ret;
@@ -88,10 +89,33 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
88 if (ret < 0) 89 if (ret < 0)
89 return ret; 90 return ret;
90 91
92 /*
93 * Put very large empty placeholders for all templates. These
94 * reserve memory for later.
95 */
96 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
97 WL1271_CMD_TEMPL_MAX_SIZE,
98 0, WL1271_RATE_AUTOMATIC);
99 if (ret < 0)
100 return ret;
101
102 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
103 WL1271_CMD_TEMPL_MAX_SIZE,
104 0, WL1271_RATE_AUTOMATIC);
105 if (ret < 0)
106 return ret;
107
108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
109 sizeof
110 (struct wl12xx_disconn_template),
111 0, WL1271_RATE_AUTOMATIC);
112 if (ret < 0)
113 return ret;
114
91 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { 115 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
92 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL, 116 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
93 WL1271_CMD_TEMPL_DFLT_SIZE, i, 117 sizeof(struct ieee80211_qos_hdr),
94 WL1271_RATE_AUTOMATIC); 118 i, WL1271_RATE_AUTOMATIC);
95 if (ret < 0) 119 if (ret < 0)
96 return ret; 120 return ret;
97 } 121 }
@@ -99,7 +123,8 @@ int wl1271_sta_init_templates_config(struct wl1271 *wl)
99 return 0; 123 return 0;
100} 124}
101 125
102static int wl1271_ap_init_deauth_template(struct wl1271 *wl) 126static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
127 struct wl12xx_vif *wlvif)
103{ 128{
104 struct wl12xx_disconn_template *tmpl; 129 struct wl12xx_disconn_template *tmpl;
105 int ret; 130 int ret;
@@ -114,7 +139,7 @@ static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
114 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT | 139 tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
115 IEEE80211_STYPE_DEAUTH); 140 IEEE80211_STYPE_DEAUTH);
116 141
117 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 142 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
118 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, 143 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
119 tmpl, sizeof(*tmpl), 0, rate); 144 tmpl, sizeof(*tmpl), 0, rate);
120 145
@@ -123,8 +148,10 @@ out:
123 return ret; 148 return ret;
124} 149}
125 150
126static int wl1271_ap_init_null_template(struct wl1271 *wl) 151static int wl1271_ap_init_null_template(struct wl1271 *wl,
152 struct ieee80211_vif *vif)
127{ 153{
154 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
128 struct ieee80211_hdr_3addr *nullfunc; 155 struct ieee80211_hdr_3addr *nullfunc;
129 int ret; 156 int ret;
130 u32 rate; 157 u32 rate;
@@ -141,10 +168,10 @@ static int wl1271_ap_init_null_template(struct wl1271 *wl)
141 168
142 /* nullfunc->addr1 is filled by FW */ 169 /* nullfunc->addr1 is filled by FW */
143 170
144 memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN); 171 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
145 memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN); 172 memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
146 173
147 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 174 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
148 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc, 175 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
149 sizeof(*nullfunc), 0, rate); 176 sizeof(*nullfunc), 0, rate);
150 177
@@ -153,8 +180,10 @@ out:
153 return ret; 180 return ret;
154} 181}
155 182
156static int wl1271_ap_init_qos_null_template(struct wl1271 *wl) 183static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
184 struct ieee80211_vif *vif)
157{ 185{
186 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
158 struct ieee80211_qos_hdr *qosnull; 187 struct ieee80211_qos_hdr *qosnull;
159 int ret; 188 int ret;
160 u32 rate; 189 u32 rate;
@@ -171,10 +200,10 @@ static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
171 200
172 /* qosnull->addr1 is filled by FW */ 201 /* qosnull->addr1 is filled by FW */
173 202
174 memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN); 203 memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
175 memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN); 204 memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
176 205
177 rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 206 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
178 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull, 207 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
179 sizeof(*qosnull), 0, rate); 208 sizeof(*qosnull), 0, rate);
180 209
@@ -183,93 +212,59 @@ out:
183 return ret; 212 return ret;
184} 213}
185 214
186static int wl1271_ap_init_templates_config(struct wl1271 *wl) 215static int wl12xx_init_rx_config(struct wl1271 *wl)
187{ 216{
188 int ret; 217 int ret;
189 218
190 /* 219 ret = wl1271_acx_rx_msdu_life_time(wl);
191 * Put very large empty placeholders for all templates. These
192 * reserve memory for later.
193 */
194 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
195 WL1271_CMD_TEMPL_MAX_SIZE,
196 0, WL1271_RATE_AUTOMATIC);
197 if (ret < 0)
198 return ret;
199
200 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
201 WL1271_CMD_TEMPL_MAX_SIZE,
202 0, WL1271_RATE_AUTOMATIC);
203 if (ret < 0)
204 return ret;
205
206 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
207 sizeof
208 (struct wl12xx_disconn_template),
209 0, WL1271_RATE_AUTOMATIC);
210 if (ret < 0)
211 return ret;
212
213 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
214 sizeof(struct wl12xx_null_data_template),
215 0, WL1271_RATE_AUTOMATIC);
216 if (ret < 0)
217 return ret;
218
219 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
220 sizeof
221 (struct wl12xx_qos_null_data_template),
222 0, WL1271_RATE_AUTOMATIC);
223 if (ret < 0) 220 if (ret < 0)
224 return ret; 221 return ret;
225 222
226 return 0; 223 return 0;
227} 224}
228 225
229static int wl12xx_init_rx_config(struct wl1271 *wl) 226int wl1271_init_phy_config(struct wl1271 *wl)
230{ 227{
231 int ret; 228 int ret;
232 229
233 ret = wl1271_acx_rx_msdu_life_time(wl); 230 ret = wl1271_acx_pd_threshold(wl);
234 if (ret < 0) 231 if (ret < 0)
235 return ret; 232 return ret;
236 233
237 return 0; 234 return 0;
238} 235}
239 236
240int wl1271_init_phy_config(struct wl1271 *wl) 237static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
238 struct wl12xx_vif *wlvif)
241{ 239{
242 int ret; 240 int ret;
243 241
244 ret = wl1271_acx_pd_threshold(wl); 242 ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
245 if (ret < 0)
246 return ret;
247
248 ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
249 if (ret < 0) 243 if (ret < 0)
250 return ret; 244 return ret;
251 245
252 ret = wl1271_acx_service_period_timeout(wl); 246 ret = wl1271_acx_service_period_timeout(wl, wlvif);
253 if (ret < 0) 247 if (ret < 0)
254 return ret; 248 return ret;
255 249
256 ret = wl1271_acx_rts_threshold(wl, wl->hw->wiphy->rts_threshold); 250 ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
257 if (ret < 0) 251 if (ret < 0)
258 return ret; 252 return ret;
259 253
260 return 0; 254 return 0;
261} 255}
262 256
263static int wl1271_init_beacon_filter(struct wl1271 *wl) 257static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
258 struct wl12xx_vif *wlvif)
264{ 259{
265 int ret; 260 int ret;
266 261
267 /* disable beacon filtering at this stage */ 262 ret = wl1271_acx_beacon_filter_table(wl, wlvif);
268 ret = wl1271_acx_beacon_filter_opt(wl, false);
269 if (ret < 0) 263 if (ret < 0)
270 return ret; 264 return ret;
271 265
272 ret = wl1271_acx_beacon_filter_table(wl); 266 /* enable beacon filtering */
267 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
273 if (ret < 0) 268 if (ret < 0)
274 return ret; 269 return ret;
275 270
@@ -302,11 +297,12 @@ int wl1271_init_energy_detection(struct wl1271 *wl)
302 return 0; 297 return 0;
303} 298}
304 299
305static int wl1271_init_beacon_broadcast(struct wl1271 *wl) 300static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
301 struct wl12xx_vif *wlvif)
306{ 302{
307 int ret; 303 int ret;
308 304
309 ret = wl1271_acx_bcn_dtim_options(wl); 305 ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
310 if (ret < 0) 306 if (ret < 0)
311 return ret; 307 return ret;
312 308
@@ -327,7 +323,8 @@ static int wl12xx_init_fwlog(struct wl1271 *wl)
327 return 0; 323 return 0;
328} 324}
329 325
330static int wl1271_sta_hw_init(struct wl1271 *wl) 326/* generic sta initialization (non vif-specific) */
327static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
331{ 328{
332 int ret; 329 int ret;
333 330
@@ -338,25 +335,7 @@ static int wl1271_sta_hw_init(struct wl1271 *wl)
338 } 335 }
339 336
340 /* PS config */ 337 /* PS config */
341 ret = wl1271_acx_config_ps(wl); 338 ret = wl12xx_acx_config_ps(wl, wlvif);
342 if (ret < 0)
343 return ret;
344
345 ret = wl1271_sta_init_templates_config(wl);
346 if (ret < 0)
347 return ret;
348
349 ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
350 if (ret < 0)
351 return ret;
352
353 /* Initialize connection monitoring thresholds */
354 ret = wl1271_acx_conn_monit_params(wl, false);
355 if (ret < 0)
356 return ret;
357
358 /* Beacon filtering */
359 ret = wl1271_init_beacon_filter(wl);
360 if (ret < 0) 339 if (ret < 0)
361 return ret; 340 return ret;
362 341
@@ -365,103 +344,61 @@ static int wl1271_sta_hw_init(struct wl1271 *wl)
365 if (ret < 0) 344 if (ret < 0)
366 return ret; 345 return ret;
367 346
368 /* Beacons and broadcast settings */ 347 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
369 ret = wl1271_init_beacon_broadcast(wl);
370 if (ret < 0)
371 return ret;
372
373 /* Configure for ELP power saving */
374 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
375 if (ret < 0)
376 return ret;
377
378 /* Configure rssi/snr averaging weights */
379 ret = wl1271_acx_rssi_snr_avg_weights(wl);
380 if (ret < 0)
381 return ret;
382
383 ret = wl1271_acx_sta_rate_policies(wl);
384 if (ret < 0)
385 return ret;
386
387 ret = wl12xx_acx_mem_cfg(wl);
388 if (ret < 0)
389 return ret;
390
391 /* Configure the FW logger */
392 ret = wl12xx_init_fwlog(wl);
393 if (ret < 0) 348 if (ret < 0)
394 return ret; 349 return ret;
395 350
396 return 0; 351 return 0;
397} 352}
398 353
399static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl) 354static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
355 struct ieee80211_vif *vif)
400{ 356{
357 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
401 int ret, i; 358 int ret, i;
402 359
403 /* disable all keep-alive templates */ 360 /* disable all keep-alive templates */
404 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) { 361 for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
405 ret = wl1271_acx_keep_alive_config(wl, i, 362 ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
406 ACX_KEEP_ALIVE_TPL_INVALID); 363 ACX_KEEP_ALIVE_TPL_INVALID);
407 if (ret < 0) 364 if (ret < 0)
408 return ret; 365 return ret;
409 } 366 }
410 367
411 /* disable the keep-alive feature */ 368 /* disable the keep-alive feature */
412 ret = wl1271_acx_keep_alive_mode(wl, false); 369 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
413 if (ret < 0) 370 if (ret < 0)
414 return ret; 371 return ret;
415 372
416 return 0; 373 return 0;
417} 374}
418 375
419static int wl1271_ap_hw_init(struct wl1271 *wl) 376/* generic ap initialization (non vif-specific) */
377static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
420{ 378{
421 int ret; 379 int ret;
422 380
423 ret = wl1271_ap_init_templates_config(wl); 381 ret = wl1271_init_ap_rates(wl, wlvif);
424 if (ret < 0)
425 return ret;
426
427 /* Configure for power always on */
428 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
429 if (ret < 0)
430 return ret;
431
432 ret = wl1271_init_ap_rates(wl);
433 if (ret < 0)
434 return ret;
435
436 ret = wl1271_acx_ap_max_tx_retry(wl);
437 if (ret < 0)
438 return ret;
439
440 ret = wl12xx_acx_mem_cfg(wl);
441 if (ret < 0)
442 return ret;
443
444 /* initialize Tx power */
445 ret = wl1271_acx_tx_power(wl, wl->power_level);
446 if (ret < 0) 382 if (ret < 0)
447 return ret; 383 return ret;
448 384
449 return 0; 385 return 0;
450} 386}
451 387
452int wl1271_ap_init_templates(struct wl1271 *wl) 388int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
453{ 389{
390 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
454 int ret; 391 int ret;
455 392
456 ret = wl1271_ap_init_deauth_template(wl); 393 ret = wl1271_ap_init_deauth_template(wl, wlvif);
457 if (ret < 0) 394 if (ret < 0)
458 return ret; 395 return ret;
459 396
460 ret = wl1271_ap_init_null_template(wl); 397 ret = wl1271_ap_init_null_template(wl, vif);
461 if (ret < 0) 398 if (ret < 0)
462 return ret; 399 return ret;
463 400
464 ret = wl1271_ap_init_qos_null_template(wl); 401 ret = wl1271_ap_init_qos_null_template(wl, vif);
465 if (ret < 0) 402 if (ret < 0)
466 return ret; 403 return ret;
467 404
@@ -469,43 +406,45 @@ int wl1271_ap_init_templates(struct wl1271 *wl)
469 * when operating as AP we want to receive external beacons for 406 * when operating as AP we want to receive external beacons for
470 * configuring ERP protection. 407 * configuring ERP protection.
471 */ 408 */
472 ret = wl1271_acx_beacon_filter_opt(wl, false); 409 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
473 if (ret < 0) 410 if (ret < 0)
474 return ret; 411 return ret;
475 412
476 return 0; 413 return 0;
477} 414}
478 415
479static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl) 416static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
417 struct ieee80211_vif *vif)
480{ 418{
481 return wl1271_ap_init_templates(wl); 419 return wl1271_ap_init_templates(wl, vif);
482} 420}
483 421
484int wl1271_init_ap_rates(struct wl1271 *wl) 422int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
485{ 423{
486 int i, ret; 424 int i, ret;
487 struct conf_tx_rate_class rc; 425 struct conf_tx_rate_class rc;
488 u32 supported_rates; 426 u32 supported_rates;
489 427
490 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x", wl->basic_rate_set); 428 wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
429 wlvif->basic_rate_set);
491 430
492 if (wl->basic_rate_set == 0) 431 if (wlvif->basic_rate_set == 0)
493 return -EINVAL; 432 return -EINVAL;
494 433
495 rc.enabled_rates = wl->basic_rate_set; 434 rc.enabled_rates = wlvif->basic_rate_set;
496 rc.long_retry_limit = 10; 435 rc.long_retry_limit = 10;
497 rc.short_retry_limit = 10; 436 rc.short_retry_limit = 10;
498 rc.aflags = 0; 437 rc.aflags = 0;
499 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_MGMT_RATE); 438 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
500 if (ret < 0) 439 if (ret < 0)
501 return ret; 440 return ret;
502 441
503 /* use the min basic rate for AP broadcast/multicast */ 442 /* use the min basic rate for AP broadcast/multicast */
504 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 443 rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
505 rc.short_retry_limit = 10; 444 rc.short_retry_limit = 10;
506 rc.long_retry_limit = 10; 445 rc.long_retry_limit = 10;
507 rc.aflags = 0; 446 rc.aflags = 0;
508 ret = wl1271_acx_ap_rate_policy(wl, &rc, ACX_TX_AP_MODE_BCST_RATE); 447 ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
509 if (ret < 0) 448 if (ret < 0)
510 return ret; 449 return ret;
511 450
@@ -513,7 +452,7 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
513 * If the basic rates contain OFDM rates, use OFDM only 452 * If the basic rates contain OFDM rates, use OFDM only
514 * rates for unicast TX as well. Else use all supported rates. 453 * rates for unicast TX as well. Else use all supported rates.
515 */ 454 */
516 if ((wl->basic_rate_set & CONF_TX_OFDM_RATES)) 455 if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
517 supported_rates = CONF_TX_OFDM_RATES; 456 supported_rates = CONF_TX_OFDM_RATES;
518 else 457 else
519 supported_rates = CONF_TX_AP_ENABLED_RATES; 458 supported_rates = CONF_TX_AP_ENABLED_RATES;
@@ -527,7 +466,8 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
527 rc.short_retry_limit = 10; 466 rc.short_retry_limit = 10;
528 rc.long_retry_limit = 10; 467 rc.long_retry_limit = 10;
529 rc.aflags = 0; 468 rc.aflags = 0;
530 ret = wl1271_acx_ap_rate_policy(wl, &rc, i); 469 ret = wl1271_acx_ap_rate_policy(wl, &rc,
470 wlvif->ap.ucast_rate_idx[i]);
531 if (ret < 0) 471 if (ret < 0)
532 return ret; 472 return ret;
533 } 473 }
@@ -535,24 +475,23 @@ int wl1271_init_ap_rates(struct wl1271 *wl)
535 return 0; 475 return 0;
536} 476}
537 477
538static int wl1271_set_ba_policies(struct wl1271 *wl) 478static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
539{ 479{
540 /* Reset the BA RX indicators */ 480 /* Reset the BA RX indicators */
541 wl->ba_rx_bitmap = 0; 481 wlvif->ba_allowed = true;
542 wl->ba_allowed = true;
543 wl->ba_rx_session_count = 0; 482 wl->ba_rx_session_count = 0;
544 483
545 /* BA is supported in STA/AP modes */ 484 /* BA is supported in STA/AP modes */
546 if (wl->bss_type != BSS_TYPE_AP_BSS && 485 if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
547 wl->bss_type != BSS_TYPE_STA_BSS) { 486 wlvif->bss_type != BSS_TYPE_STA_BSS) {
548 wl->ba_support = false; 487 wlvif->ba_support = false;
549 return 0; 488 return 0;
550 } 489 }
551 490
552 wl->ba_support = true; 491 wlvif->ba_support = true;
553 492
554 /* 802.11n initiator BA session setting */ 493 /* 802.11n initiator BA session setting */
555 return wl12xx_acx_set_ba_initiator_policy(wl); 494 return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
556} 495}
557 496
558int wl1271_chip_specific_init(struct wl1271 *wl) 497int wl1271_chip_specific_init(struct wl1271 *wl)
@@ -562,7 +501,7 @@ int wl1271_chip_specific_init(struct wl1271 *wl)
562 if (wl->chip.id == CHIP_ID_1283_PG20) { 501 if (wl->chip.id == CHIP_ID_1283_PG20) {
563 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE; 502 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
564 503
565 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) 504 if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
566 /* Enable SDIO padding */ 505 /* Enable SDIO padding */
567 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK; 506 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
568 507
@@ -575,13 +514,150 @@ out:
575 return ret; 514 return ret;
576} 515}
577 516
517/* vif-specifc initialization */
518static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
519{
520 int ret;
578 521
579int wl1271_hw_init(struct wl1271 *wl) 522 ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
523 if (ret < 0)
524 return ret;
525
526 /* Initialize connection monitoring thresholds */
527 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
528 if (ret < 0)
529 return ret;
530
531 /* Beacon filtering */
532 ret = wl1271_init_sta_beacon_filter(wl, wlvif);
533 if (ret < 0)
534 return ret;
535
536 /* Beacons and broadcast settings */
537 ret = wl1271_init_beacon_broadcast(wl, wlvif);
538 if (ret < 0)
539 return ret;
540
541 /* Configure rssi/snr averaging weights */
542 ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
543 if (ret < 0)
544 return ret;
545
546 return 0;
547}
548
549/* vif-specific intialization */
550static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
551{
552 int ret;
553
554 ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
555 if (ret < 0)
556 return ret;
557
558 /* initialize Tx power */
559 ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
560 if (ret < 0)
561 return ret;
562
563 return 0;
564}
565
566int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
580{ 567{
568 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
581 struct conf_tx_ac_category *conf_ac; 569 struct conf_tx_ac_category *conf_ac;
582 struct conf_tx_tid *conf_tid; 570 struct conf_tx_tid *conf_tid;
571 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
583 int ret, i; 572 int ret, i;
584 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 573
574 /*
575 * consider all existing roles before configuring psm.
576 * TODO: reconfigure on interface removal.
577 */
578 if (!wl->ap_count) {
579 if (is_ap) {
580 /* Configure for power always on */
581 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
582 if (ret < 0)
583 return ret;
584 } else if (!wl->sta_count) {
585 /* Configure for ELP power saving */
586 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
587 if (ret < 0)
588 return ret;
589 }
590 }
591
592 /* Mode specific init */
593 if (is_ap) {
594 ret = wl1271_ap_hw_init(wl, wlvif);
595 if (ret < 0)
596 return ret;
597
598 ret = wl12xx_init_ap_role(wl, wlvif);
599 if (ret < 0)
600 return ret;
601 } else {
602 ret = wl1271_sta_hw_init(wl, wlvif);
603 if (ret < 0)
604 return ret;
605
606 ret = wl12xx_init_sta_role(wl, wlvif);
607 if (ret < 0)
608 return ret;
609 }
610
611 wl12xx_init_phy_vif_config(wl, wlvif);
612
613 /* Default TID/AC configuration */
614 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
615 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
616 conf_ac = &wl->conf.tx.ac_conf[i];
617 ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
618 conf_ac->cw_min, conf_ac->cw_max,
619 conf_ac->aifsn, conf_ac->tx_op_limit);
620 if (ret < 0)
621 return ret;
622
623 conf_tid = &wl->conf.tx.tid_conf[i];
624 ret = wl1271_acx_tid_cfg(wl, wlvif,
625 conf_tid->queue_id,
626 conf_tid->channel_type,
627 conf_tid->tsid,
628 conf_tid->ps_scheme,
629 conf_tid->ack_policy,
630 conf_tid->apsd_conf[0],
631 conf_tid->apsd_conf[1]);
632 if (ret < 0)
633 return ret;
634 }
635
636 /* Configure HW encryption */
637 ret = wl1271_acx_feature_cfg(wl, wlvif);
638 if (ret < 0)
639 return ret;
640
641 /* Mode specific init - post mem init */
642 if (is_ap)
643 ret = wl1271_ap_hw_init_post_mem(wl, vif);
644 else
645 ret = wl1271_sta_hw_init_post_mem(wl, vif);
646
647 if (ret < 0)
648 return ret;
649
650 /* Configure initiator BA sessions policies */
651 ret = wl1271_set_ba_policies(wl, wlvif);
652 if (ret < 0)
653 return ret;
654
655 return 0;
656}
657
658int wl1271_hw_init(struct wl1271 *wl)
659{
660 int ret;
585 661
586 if (wl->chip.id == CHIP_ID_1283_PG20) 662 if (wl->chip.id == CHIP_ID_1283_PG20)
587 ret = wl128x_cmd_general_parms(wl); 663 ret = wl128x_cmd_general_parms(wl);
@@ -602,12 +678,17 @@ int wl1271_hw_init(struct wl1271 *wl)
602 if (ret < 0) 678 if (ret < 0)
603 return ret; 679 return ret;
604 680
605 /* Mode specific init */ 681 /* Init templates */
606 if (is_ap) 682 ret = wl1271_init_templates_config(wl);
607 ret = wl1271_ap_hw_init(wl); 683 if (ret < 0)
608 else 684 return ret;
609 ret = wl1271_sta_hw_init(wl); 685
686 ret = wl12xx_acx_mem_cfg(wl);
687 if (ret < 0)
688 return ret;
610 689
690 /* Configure the FW logger */
691 ret = wl12xx_init_fwlog(wl);
611 if (ret < 0) 692 if (ret < 0)
612 return ret; 693 return ret;
613 694
@@ -655,61 +736,20 @@ int wl1271_hw_init(struct wl1271 *wl)
655 if (ret < 0) 736 if (ret < 0)
656 goto out_free_memmap; 737 goto out_free_memmap;
657 738
658 /* Default TID/AC configuration */
659 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
660 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
661 conf_ac = &wl->conf.tx.ac_conf[i];
662 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
663 conf_ac->cw_max, conf_ac->aifsn,
664 conf_ac->tx_op_limit);
665 if (ret < 0)
666 goto out_free_memmap;
667
668 conf_tid = &wl->conf.tx.tid_conf[i];
669 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
670 conf_tid->channel_type,
671 conf_tid->tsid,
672 conf_tid->ps_scheme,
673 conf_tid->ack_policy,
674 conf_tid->apsd_conf[0],
675 conf_tid->apsd_conf[1]);
676 if (ret < 0)
677 goto out_free_memmap;
678 }
679
680 /* Enable data path */ 739 /* Enable data path */
681 ret = wl1271_cmd_data_path(wl, 1); 740 ret = wl1271_cmd_data_path(wl, 1);
682 if (ret < 0) 741 if (ret < 0)
683 goto out_free_memmap; 742 goto out_free_memmap;
684 743
685 /* Configure HW encryption */
686 ret = wl1271_acx_feature_cfg(wl);
687 if (ret < 0)
688 goto out_free_memmap;
689
690 /* configure PM */ 744 /* configure PM */
691 ret = wl1271_acx_pm_config(wl); 745 ret = wl1271_acx_pm_config(wl);
692 if (ret < 0) 746 if (ret < 0)
693 goto out_free_memmap; 747 goto out_free_memmap;
694 748
695 /* Mode specific init - post mem init */
696 if (is_ap)
697 ret = wl1271_ap_hw_init_post_mem(wl);
698 else
699 ret = wl1271_sta_hw_init_post_mem(wl);
700
701 if (ret < 0)
702 goto out_free_memmap;
703
704 ret = wl12xx_acx_set_rate_mgmt_params(wl); 749 ret = wl12xx_acx_set_rate_mgmt_params(wl);
705 if (ret < 0) 750 if (ret < 0)
706 goto out_free_memmap; 751 goto out_free_memmap;
707 752
708 /* Configure initiator BA sessions policies */
709 ret = wl1271_set_ba_policies(wl);
710 if (ret < 0)
711 goto out_free_memmap;
712
713 /* configure hangover */ 753 /* configure hangover */
714 ret = wl12xx_acx_config_hangover(wl); 754 ret = wl12xx_acx_config_hangover(wl);
715 if (ret < 0) 755 if (ret < 0)
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/init.h
index 3a3c230fd292..81140b81f654 100644
--- a/drivers/net/wireless/wl12xx/init.h
+++ b/drivers/net/wireless/wl12xx/init.h
@@ -27,13 +27,14 @@
27#include "wl12xx.h" 27#include "wl12xx.h"
28 28
29int wl1271_hw_init_power_auth(struct wl1271 *wl); 29int wl1271_hw_init_power_auth(struct wl1271 *wl);
30int wl1271_sta_init_templates_config(struct wl1271 *wl); 30int wl1271_init_templates_config(struct wl1271 *wl);
31int wl1271_init_phy_config(struct wl1271 *wl); 31int wl1271_init_phy_config(struct wl1271 *wl);
32int wl1271_init_pta(struct wl1271 *wl); 32int wl1271_init_pta(struct wl1271 *wl);
33int wl1271_init_energy_detection(struct wl1271 *wl); 33int wl1271_init_energy_detection(struct wl1271 *wl);
34int wl1271_chip_specific_init(struct wl1271 *wl); 34int wl1271_chip_specific_init(struct wl1271 *wl);
35int wl1271_hw_init(struct wl1271 *wl); 35int wl1271_hw_init(struct wl1271 *wl);
36int wl1271_init_ap_rates(struct wl1271 *wl); 36int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif);
37int wl1271_ap_init_templates(struct wl1271 *wl); 37int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif);
38int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif);
38 39
39#endif 40#endif
diff --git a/drivers/net/wireless/wl12xx/io.c b/drivers/net/wireless/wl12xx/io.c
index c2da66f45046..079ad380e8ff 100644
--- a/drivers/net/wireless/wl12xx/io.c
+++ b/drivers/net/wireless/wl12xx/io.c
@@ -24,8 +24,10 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
27#include <linux/interrupt.h>
27 28
28#include "wl12xx.h" 29#include "wl12xx.h"
30#include "debug.h"
29#include "wl12xx_80211.h" 31#include "wl12xx_80211.h"
30#include "io.h" 32#include "io.h"
31#include "tx.h" 33#include "tx.h"
@@ -46,7 +48,7 @@
46bool wl1271_set_block_size(struct wl1271 *wl) 48bool wl1271_set_block_size(struct wl1271 *wl)
47{ 49{
48 if (wl->if_ops->set_block_size) { 50 if (wl->if_ops->set_block_size) {
49 wl->if_ops->set_block_size(wl, WL12XX_BUS_BLOCK_SIZE); 51 wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
50 return true; 52 return true;
51 } 53 }
52 54
@@ -55,12 +57,12 @@ bool wl1271_set_block_size(struct wl1271 *wl)
55 57
56void wl1271_disable_interrupts(struct wl1271 *wl) 58void wl1271_disable_interrupts(struct wl1271 *wl)
57{ 59{
58 wl->if_ops->disable_irq(wl); 60 disable_irq(wl->irq);
59} 61}
60 62
61void wl1271_enable_interrupts(struct wl1271 *wl) 63void wl1271_enable_interrupts(struct wl1271 *wl)
62{ 64{
63 wl->if_ops->enable_irq(wl); 65 enable_irq(wl->irq);
64} 66}
65 67
66/* Set the SPI partitions to access the chip addresses 68/* Set the SPI partitions to access the chip addresses
@@ -128,13 +130,13 @@ EXPORT_SYMBOL_GPL(wl1271_set_partition);
128void wl1271_io_reset(struct wl1271 *wl) 130void wl1271_io_reset(struct wl1271 *wl)
129{ 131{
130 if (wl->if_ops->reset) 132 if (wl->if_ops->reset)
131 wl->if_ops->reset(wl); 133 wl->if_ops->reset(wl->dev);
132} 134}
133 135
134void wl1271_io_init(struct wl1271 *wl) 136void wl1271_io_init(struct wl1271 *wl)
135{ 137{
136 if (wl->if_ops->init) 138 if (wl->if_ops->init)
137 wl->if_ops->init(wl); 139 wl->if_ops->init(wl->dev);
138} 140}
139 141
140void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val) 142void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
diff --git a/drivers/net/wireless/wl12xx/io.h b/drivers/net/wireless/wl12xx/io.h
index e839341dfafe..d398cbcea986 100644
--- a/drivers/net/wireless/wl12xx/io.h
+++ b/drivers/net/wireless/wl12xx/io.h
@@ -51,23 +51,17 @@ void wl1271_enable_interrupts(struct wl1271 *wl);
51void wl1271_io_reset(struct wl1271 *wl); 51void wl1271_io_reset(struct wl1271 *wl);
52void wl1271_io_init(struct wl1271 *wl); 52void wl1271_io_init(struct wl1271 *wl);
53 53
54static inline struct device *wl1271_wl_to_dev(struct wl1271 *wl)
55{
56 return wl->if_ops->dev(wl);
57}
58
59
60/* Raw target IO, address is not translated */ 54/* Raw target IO, address is not translated */
61static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf, 55static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
62 size_t len, bool fixed) 56 size_t len, bool fixed)
63{ 57{
64 wl->if_ops->write(wl, addr, buf, len, fixed); 58 wl->if_ops->write(wl->dev, addr, buf, len, fixed);
65} 59}
66 60
67static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf, 61static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
68 size_t len, bool fixed) 62 size_t len, bool fixed)
69{ 63{
70 wl->if_ops->read(wl, addr, buf, len, fixed); 64 wl->if_ops->read(wl->dev, addr, buf, len, fixed);
71} 65}
72 66
73static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr) 67static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
@@ -155,13 +149,13 @@ static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
155 149
156static inline void wl1271_power_off(struct wl1271 *wl) 150static inline void wl1271_power_off(struct wl1271 *wl)
157{ 151{
158 wl->if_ops->power(wl, false); 152 wl->if_ops->power(wl->dev, false);
159 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 153 clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
160} 154}
161 155
162static inline int wl1271_power_on(struct wl1271 *wl) 156static inline int wl1271_power_on(struct wl1271 *wl)
163{ 157{
164 int ret = wl->if_ops->power(wl, true); 158 int ret = wl->if_ops->power(wl->dev, true);
165 if (ret == 0) 159 if (ret == 0)
166 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags); 160 set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
167 161
@@ -176,15 +170,10 @@ u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
176int wl1271_set_partition(struct wl1271 *wl, 170int wl1271_set_partition(struct wl1271 *wl,
177 struct wl1271_partition_set *p); 171 struct wl1271_partition_set *p);
178 172
173bool wl1271_set_block_size(struct wl1271 *wl);
174
179/* Functions from wl1271_main.c */ 175/* Functions from wl1271_main.c */
180 176
181int wl1271_register_hw(struct wl1271 *wl);
182void wl1271_unregister_hw(struct wl1271 *wl);
183int wl1271_init_ieee80211(struct wl1271 *wl);
184struct ieee80211_hw *wl1271_alloc_hw(void);
185int wl1271_free_hw(struct wl1271 *wl);
186irqreturn_t wl1271_irq(int irq, void *data);
187bool wl1271_set_block_size(struct wl1271 *wl);
188int wl1271_tx_dummy_packet(struct wl1271 *wl); 177int wl1271_tx_dummy_packet(struct wl1271 *wl);
189 178
190#endif 179#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c
index 884f82b63219..2f7bfa86c8cd 100644
--- a/drivers/net/wireless/wl12xx/main.c
+++ b/drivers/net/wireless/wl12xx/main.c
@@ -32,8 +32,10 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/wl12xx.h> 33#include <linux/wl12xx.h>
34#include <linux/sched.h> 34#include <linux/sched.h>
35#include <linux/interrupt.h>
35 36
36#include "wl12xx.h" 37#include "wl12xx.h"
38#include "debug.h"
37#include "wl12xx_80211.h" 39#include "wl12xx_80211.h"
38#include "reg.h" 40#include "reg.h"
39#include "io.h" 41#include "io.h"
@@ -377,42 +379,30 @@ static char *fwlog_param;
377static bool bug_on_recovery; 379static bool bug_on_recovery;
378 380
379static void __wl1271_op_remove_interface(struct wl1271 *wl, 381static void __wl1271_op_remove_interface(struct wl1271 *wl,
382 struct ieee80211_vif *vif,
380 bool reset_tx_queues); 383 bool reset_tx_queues);
381static void wl1271_free_ap_keys(struct wl1271 *wl); 384static void wl1271_op_stop(struct ieee80211_hw *hw);
382 385static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
383
384static void wl1271_device_release(struct device *dev)
385{
386
387}
388
389static struct platform_device wl1271_device = {
390 .name = "wl1271",
391 .id = -1,
392
393 /* device model insists to have a release function */
394 .dev = {
395 .release = wl1271_device_release,
396 },
397};
398 386
399static DEFINE_MUTEX(wl_list_mutex); 387static DEFINE_MUTEX(wl_list_mutex);
400static LIST_HEAD(wl_list); 388static LIST_HEAD(wl_list);
401 389
402static int wl1271_check_operstate(struct wl1271 *wl, unsigned char operstate) 390static int wl1271_check_operstate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
391 unsigned char operstate)
403{ 392{
404 int ret; 393 int ret;
394
405 if (operstate != IF_OPER_UP) 395 if (operstate != IF_OPER_UP)
406 return 0; 396 return 0;
407 397
408 if (test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags)) 398 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
409 return 0; 399 return 0;
410 400
411 ret = wl12xx_cmd_set_peer_state(wl, wl->sta_hlid); 401 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
412 if (ret < 0) 402 if (ret < 0)
413 return ret; 403 return ret;
414 404
415 wl12xx_croc(wl, wl->role_id); 405 wl12xx_croc(wl, wlvif->role_id);
416 406
417 wl1271_info("Association completed."); 407 wl1271_info("Association completed.");
418 return 0; 408 return 0;
@@ -426,6 +416,7 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
426 struct ieee80211_hw *hw; 416 struct ieee80211_hw *hw;
427 struct wl1271 *wl; 417 struct wl1271 *wl;
428 struct wl1271 *wl_temp; 418 struct wl1271 *wl_temp;
419 struct wl12xx_vif *wlvif;
429 int ret = 0; 420 int ret = 0;
430 421
431 /* Check that this notification is for us. */ 422 /* Check that this notification is for us. */
@@ -459,17 +450,18 @@ static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
459 if (wl->state == WL1271_STATE_OFF) 450 if (wl->state == WL1271_STATE_OFF)
460 goto out; 451 goto out;
461 452
462 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 453 wl12xx_for_each_wlvif_sta(wl, wlvif) {
463 goto out; 454 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
464 455 continue;
465 ret = wl1271_ps_elp_wakeup(wl);
466 if (ret < 0)
467 goto out;
468 456
469 wl1271_check_operstate(wl, dev->operstate); 457 ret = wl1271_ps_elp_wakeup(wl);
458 if (ret < 0)
459 goto out;
470 460
471 wl1271_ps_elp_sleep(wl); 461 wl1271_check_operstate(wl, wlvif, dev->operstate);
472 462
463 wl1271_ps_elp_sleep(wl);
464 }
473out: 465out:
474 mutex_unlock(&wl->mutex); 466 mutex_unlock(&wl->mutex);
475 467
@@ -498,19 +490,20 @@ static int wl1271_reg_notify(struct wiphy *wiphy,
498 return 0; 490 return 0;
499} 491}
500 492
501static int wl1271_set_rx_streaming(struct wl1271 *wl, bool enable) 493static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
494 bool enable)
502{ 495{
503 int ret = 0; 496 int ret = 0;
504 497
505 /* we should hold wl->mutex */ 498 /* we should hold wl->mutex */
506 ret = wl1271_acx_ps_rx_streaming(wl, enable); 499 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
507 if (ret < 0) 500 if (ret < 0)
508 goto out; 501 goto out;
509 502
510 if (enable) 503 if (enable)
511 set_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); 504 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
512 else 505 else
513 clear_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags); 506 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
514out: 507out:
515 return ret; 508 return ret;
516} 509}
@@ -519,25 +512,25 @@ out:
519 * this function is being called when the rx_streaming interval 512 * this function is being called when the rx_streaming interval
520 * has beed changed or rx_streaming should be disabled 513 * has beed changed or rx_streaming should be disabled
521 */ 514 */
522int wl1271_recalc_rx_streaming(struct wl1271 *wl) 515int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
523{ 516{
524 int ret = 0; 517 int ret = 0;
525 int period = wl->conf.rx_streaming.interval; 518 int period = wl->conf.rx_streaming.interval;
526 519
527 /* don't reconfigure if rx_streaming is disabled */ 520 /* don't reconfigure if rx_streaming is disabled */
528 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) 521 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
529 goto out; 522 goto out;
530 523
531 /* reconfigure/disable according to new streaming_period */ 524 /* reconfigure/disable according to new streaming_period */
532 if (period && 525 if (period &&
533 test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) && 526 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
534 (wl->conf.rx_streaming.always || 527 (wl->conf.rx_streaming.always ||
535 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) 528 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
536 ret = wl1271_set_rx_streaming(wl, true); 529 ret = wl1271_set_rx_streaming(wl, wlvif, true);
537 else { 530 else {
538 ret = wl1271_set_rx_streaming(wl, false); 531 ret = wl1271_set_rx_streaming(wl, wlvif, false);
539 /* don't cancel_work_sync since we might deadlock */ 532 /* don't cancel_work_sync since we might deadlock */
540 del_timer_sync(&wl->rx_streaming_timer); 533 del_timer_sync(&wlvif->rx_streaming_timer);
541 } 534 }
542out: 535out:
543 return ret; 536 return ret;
@@ -546,13 +539,14 @@ out:
546static void wl1271_rx_streaming_enable_work(struct work_struct *work) 539static void wl1271_rx_streaming_enable_work(struct work_struct *work)
547{ 540{
548 int ret; 541 int ret;
549 struct wl1271 *wl = 542 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
550 container_of(work, struct wl1271, rx_streaming_enable_work); 543 rx_streaming_enable_work);
544 struct wl1271 *wl = wlvif->wl;
551 545
552 mutex_lock(&wl->mutex); 546 mutex_lock(&wl->mutex);
553 547
554 if (test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags) || 548 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
555 !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 549 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
556 (!wl->conf.rx_streaming.always && 550 (!wl->conf.rx_streaming.always &&
557 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) 551 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
558 goto out; 552 goto out;
@@ -564,12 +558,12 @@ static void wl1271_rx_streaming_enable_work(struct work_struct *work)
564 if (ret < 0) 558 if (ret < 0)
565 goto out; 559 goto out;
566 560
567 ret = wl1271_set_rx_streaming(wl, true); 561 ret = wl1271_set_rx_streaming(wl, wlvif, true);
568 if (ret < 0) 562 if (ret < 0)
569 goto out_sleep; 563 goto out_sleep;
570 564
571 /* stop it after some time of inactivity */ 565 /* stop it after some time of inactivity */
572 mod_timer(&wl->rx_streaming_timer, 566 mod_timer(&wlvif->rx_streaming_timer,
573 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration)); 567 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
574 568
575out_sleep: 569out_sleep:
@@ -581,19 +575,20 @@ out:
581static void wl1271_rx_streaming_disable_work(struct work_struct *work) 575static void wl1271_rx_streaming_disable_work(struct work_struct *work)
582{ 576{
583 int ret; 577 int ret;
584 struct wl1271 *wl = 578 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
585 container_of(work, struct wl1271, rx_streaming_disable_work); 579 rx_streaming_disable_work);
580 struct wl1271 *wl = wlvif->wl;
586 581
587 mutex_lock(&wl->mutex); 582 mutex_lock(&wl->mutex);
588 583
589 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags)) 584 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
590 goto out; 585 goto out;
591 586
592 ret = wl1271_ps_elp_wakeup(wl); 587 ret = wl1271_ps_elp_wakeup(wl);
593 if (ret < 0) 588 if (ret < 0)
594 goto out; 589 goto out;
595 590
596 ret = wl1271_set_rx_streaming(wl, false); 591 ret = wl1271_set_rx_streaming(wl, wlvif, false);
597 if (ret) 592 if (ret)
598 goto out_sleep; 593 goto out_sleep;
599 594
@@ -605,8 +600,9 @@ out:
605 600
606static void wl1271_rx_streaming_timer(unsigned long data) 601static void wl1271_rx_streaming_timer(unsigned long data)
607{ 602{
608 struct wl1271 *wl = (struct wl1271 *)data; 603 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
609 ieee80211_queue_work(wl->hw, &wl->rx_streaming_disable_work); 604 struct wl1271 *wl = wlvif->wl;
605 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
610} 606}
611 607
612static void wl1271_conf_init(struct wl1271 *wl) 608static void wl1271_conf_init(struct wl1271 *wl)
@@ -645,9 +641,7 @@ static void wl1271_conf_init(struct wl1271 *wl)
645 641
646static int wl1271_plt_init(struct wl1271 *wl) 642static int wl1271_plt_init(struct wl1271 *wl)
647{ 643{
648 struct conf_tx_ac_category *conf_ac; 644 int ret;
649 struct conf_tx_tid *conf_tid;
650 int ret, i;
651 645
652 if (wl->chip.id == CHIP_ID_1283_PG20) 646 if (wl->chip.id == CHIP_ID_1283_PG20)
653 ret = wl128x_cmd_general_parms(wl); 647 ret = wl128x_cmd_general_parms(wl);
@@ -676,10 +670,6 @@ static int wl1271_plt_init(struct wl1271 *wl)
676 if (ret < 0) 670 if (ret < 0)
677 return ret; 671 return ret;
678 672
679 ret = wl1271_sta_init_templates_config(wl);
680 if (ret < 0)
681 return ret;
682
683 ret = wl1271_acx_init_mem_config(wl); 673 ret = wl1271_acx_init_mem_config(wl);
684 if (ret < 0) 674 if (ret < 0)
685 return ret; 675 return ret;
@@ -689,61 +679,10 @@ static int wl1271_plt_init(struct wl1271 *wl)
689 if (ret < 0) 679 if (ret < 0)
690 goto out_free_memmap; 680 goto out_free_memmap;
691 681
692 ret = wl1271_acx_dco_itrim_params(wl);
693 if (ret < 0)
694 goto out_free_memmap;
695
696 /* Initialize connection monitoring thresholds */
697 ret = wl1271_acx_conn_monit_params(wl, false);
698 if (ret < 0)
699 goto out_free_memmap;
700
701 /* Bluetooth WLAN coexistence */
702 ret = wl1271_init_pta(wl);
703 if (ret < 0)
704 goto out_free_memmap;
705
706 /* FM WLAN coexistence */
707 ret = wl1271_acx_fm_coex(wl);
708 if (ret < 0)
709 goto out_free_memmap;
710
711 /* Energy detection */
712 ret = wl1271_init_energy_detection(wl);
713 if (ret < 0)
714 goto out_free_memmap;
715
716 ret = wl12xx_acx_mem_cfg(wl); 682 ret = wl12xx_acx_mem_cfg(wl);
717 if (ret < 0) 683 if (ret < 0)
718 goto out_free_memmap; 684 goto out_free_memmap;
719 685
720 /* Default fragmentation threshold */
721 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
722 if (ret < 0)
723 goto out_free_memmap;
724
725 /* Default TID/AC configuration */
726 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
727 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
728 conf_ac = &wl->conf.tx.ac_conf[i];
729 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
730 conf_ac->cw_max, conf_ac->aifsn,
731 conf_ac->tx_op_limit);
732 if (ret < 0)
733 goto out_free_memmap;
734
735 conf_tid = &wl->conf.tx.tid_conf[i];
736 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
737 conf_tid->channel_type,
738 conf_tid->tsid,
739 conf_tid->ps_scheme,
740 conf_tid->ack_policy,
741 conf_tid->apsd_conf[0],
742 conf_tid->apsd_conf[1]);
743 if (ret < 0)
744 goto out_free_memmap;
745 }
746
747 /* Enable data path */ 686 /* Enable data path */
748 ret = wl1271_cmd_data_path(wl, 1); 687 ret = wl1271_cmd_data_path(wl, 1);
749 if (ret < 0) 688 if (ret < 0)
@@ -768,14 +707,12 @@ static int wl1271_plt_init(struct wl1271 *wl)
768 return ret; 707 return ret;
769} 708}
770 709
771static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts) 710static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
711 struct wl12xx_vif *wlvif,
712 u8 hlid, u8 tx_pkts)
772{ 713{
773 bool fw_ps, single_sta; 714 bool fw_ps, single_sta;
774 715
775 /* only regulate station links */
776 if (hlid < WL1271_AP_STA_HLID_START)
777 return;
778
779 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 716 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
780 single_sta = (wl->active_sta_count == 1); 717 single_sta = (wl->active_sta_count == 1);
781 718
@@ -784,7 +721,7 @@ static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts)
784 * packets in FW or if the STA is awake. 721 * packets in FW or if the STA is awake.
785 */ 722 */
786 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS) 723 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
787 wl1271_ps_link_end(wl, hlid); 724 wl12xx_ps_link_end(wl, wlvif, hlid);
788 725
789 /* 726 /*
790 * Start high-level PS if the STA is asleep with enough blocks in FW. 727 * Start high-level PS if the STA is asleep with enough blocks in FW.
@@ -792,24 +729,14 @@ static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_pkts)
792 * case FW-memory congestion is not a problem. 729 * case FW-memory congestion is not a problem.
793 */ 730 */
794 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 731 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
795 wl1271_ps_link_start(wl, hlid, true); 732 wl12xx_ps_link_start(wl, wlvif, hlid, true);
796}
797
798bool wl1271_is_active_sta(struct wl1271 *wl, u8 hlid)
799{
800 int id;
801
802 /* global/broadcast "stations" are always active */
803 if (hlid < WL1271_AP_STA_HLID_START)
804 return true;
805
806 id = hlid - WL1271_AP_STA_HLID_START;
807 return test_bit(id, wl->ap_hlid_map);
808} 733}
809 734
810static void wl12xx_irq_update_links_status(struct wl1271 *wl, 735static void wl12xx_irq_update_links_status(struct wl1271 *wl,
736 struct wl12xx_vif *wlvif,
811 struct wl12xx_fw_status *status) 737 struct wl12xx_fw_status *status)
812{ 738{
739 struct wl1271_link *lnk;
813 u32 cur_fw_ps_map; 740 u32 cur_fw_ps_map;
814 u8 hlid, cnt; 741 u8 hlid, cnt;
815 742
@@ -825,25 +752,22 @@ static void wl12xx_irq_update_links_status(struct wl1271 *wl,
825 wl->ap_fw_ps_map = cur_fw_ps_map; 752 wl->ap_fw_ps_map = cur_fw_ps_map;
826 } 753 }
827 754
828 for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) { 755 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
829 if (!wl1271_is_active_sta(wl, hlid)) 756 lnk = &wl->links[hlid];
830 continue; 757 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
831
832 cnt = status->tx_lnk_free_pkts[hlid] -
833 wl->links[hlid].prev_freed_pkts;
834 758
835 wl->links[hlid].prev_freed_pkts = 759 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
836 status->tx_lnk_free_pkts[hlid]; 760 lnk->allocated_pkts -= cnt;
837 wl->links[hlid].allocated_pkts -= cnt;
838 761
839 wl12xx_irq_ps_regulate_link(wl, hlid, 762 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
840 wl->links[hlid].allocated_pkts); 763 lnk->allocated_pkts);
841 } 764 }
842} 765}
843 766
844static void wl12xx_fw_status(struct wl1271 *wl, 767static void wl12xx_fw_status(struct wl1271 *wl,
845 struct wl12xx_fw_status *status) 768 struct wl12xx_fw_status *status)
846{ 769{
770 struct wl12xx_vif *wlvif;
847 struct timespec ts; 771 struct timespec ts;
848 u32 old_tx_blk_count = wl->tx_blocks_available; 772 u32 old_tx_blk_count = wl->tx_blocks_available;
849 int avail, freed_blocks; 773 int avail, freed_blocks;
@@ -898,8 +822,9 @@ static void wl12xx_fw_status(struct wl1271 *wl,
898 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 822 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
899 823
900 /* for AP update num of allocated TX blocks per link and ps status */ 824 /* for AP update num of allocated TX blocks per link and ps status */
901 if (wl->bss_type == BSS_TYPE_AP_BSS) 825 wl12xx_for_each_wlvif_ap(wl, wlvif) {
902 wl12xx_irq_update_links_status(wl, status); 826 wl12xx_irq_update_links_status(wl, wlvif, status);
827 }
903 828
904 /* update the host-chipset time offset */ 829 /* update the host-chipset time offset */
905 getnstimeofday(&ts); 830 getnstimeofday(&ts);
@@ -932,7 +857,7 @@ static void wl1271_netstack_work(struct work_struct *work)
932 857
933#define WL1271_IRQ_MAX_LOOPS 256 858#define WL1271_IRQ_MAX_LOOPS 256
934 859
935irqreturn_t wl1271_irq(int irq, void *cookie) 860static irqreturn_t wl1271_irq(int irq, void *cookie)
936{ 861{
937 int ret; 862 int ret;
938 u32 intr; 863 u32 intr;
@@ -1054,7 +979,6 @@ out:
1054 979
1055 return IRQ_HANDLED; 980 return IRQ_HANDLED;
1056} 981}
1057EXPORT_SYMBOL_GPL(wl1271_irq);
1058 982
1059static int wl1271_fetch_firmware(struct wl1271 *wl) 983static int wl1271_fetch_firmware(struct wl1271 *wl)
1060{ 984{
@@ -1069,10 +993,10 @@ static int wl1271_fetch_firmware(struct wl1271 *wl)
1069 993
1070 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name); 994 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1071 995
1072 ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl)); 996 ret = request_firmware(&fw, fw_name, wl->dev);
1073 997
1074 if (ret < 0) { 998 if (ret < 0) {
1075 wl1271_error("could not get firmware: %d", ret); 999 wl1271_error("could not get firmware %s: %d", fw_name, ret);
1076 return ret; 1000 return ret;
1077 } 1001 }
1078 1002
@@ -1107,10 +1031,11 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
1107 const struct firmware *fw; 1031 const struct firmware *fw;
1108 int ret; 1032 int ret;
1109 1033
1110 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl)); 1034 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
1111 1035
1112 if (ret < 0) { 1036 if (ret < 0) {
1113 wl1271_error("could not get nvs file: %d", ret); 1037 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1038 ret);
1114 return ret; 1039 return ret;
1115 } 1040 }
1116 1041
@@ -1217,11 +1142,13 @@ static void wl1271_recovery_work(struct work_struct *work)
1217{ 1142{
1218 struct wl1271 *wl = 1143 struct wl1271 *wl =
1219 container_of(work, struct wl1271, recovery_work); 1144 container_of(work, struct wl1271, recovery_work);
1145 struct wl12xx_vif *wlvif;
1146 struct ieee80211_vif *vif;
1220 1147
1221 mutex_lock(&wl->mutex); 1148 mutex_lock(&wl->mutex);
1222 1149
1223 if (wl->state != WL1271_STATE_ON) 1150 if (wl->state != WL1271_STATE_ON)
1224 goto out; 1151 goto out_unlock;
1225 1152
1226 /* Avoid a recursive recovery */ 1153 /* Avoid a recursive recovery */
1227 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); 1154 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
@@ -1238,9 +1165,12 @@ static void wl1271_recovery_work(struct work_struct *work)
1238 * in the firmware during recovery. This doens't hurt if the network is 1165 * in the firmware during recovery. This doens't hurt if the network is
1239 * not encrypted. 1166 * not encrypted.
1240 */ 1167 */
1241 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 1168 wl12xx_for_each_wlvif(wl, wlvif) {
1242 test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 1169 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
1243 wl->tx_security_seq += WL1271_TX_SQN_POST_RECOVERY_PADDING; 1170 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1171 wlvif->tx_security_seq +=
1172 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1173 }
1244 1174
1245 /* Prevent spurious TX during FW restart */ 1175 /* Prevent spurious TX during FW restart */
1246 ieee80211_stop_queues(wl->hw); 1176 ieee80211_stop_queues(wl->hw);
@@ -1251,7 +1181,14 @@ static void wl1271_recovery_work(struct work_struct *work)
1251 } 1181 }
1252 1182
1253 /* reboot the chipset */ 1183 /* reboot the chipset */
1254 __wl1271_op_remove_interface(wl, false); 1184 while (!list_empty(&wl->wlvif_list)) {
1185 wlvif = list_first_entry(&wl->wlvif_list,
1186 struct wl12xx_vif, list);
1187 vif = wl12xx_wlvif_to_vif(wlvif);
1188 __wl1271_op_remove_interface(wl, vif, false);
1189 }
1190 mutex_unlock(&wl->mutex);
1191 wl1271_op_stop(wl->hw);
1255 1192
1256 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags); 1193 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1257 1194
@@ -1262,8 +1199,8 @@ static void wl1271_recovery_work(struct work_struct *work)
1262 * to restart the HW. 1199 * to restart the HW.
1263 */ 1200 */
1264 ieee80211_wake_queues(wl->hw); 1201 ieee80211_wake_queues(wl->hw);
1265 1202 return;
1266out: 1203out_unlock:
1267 mutex_unlock(&wl->mutex); 1204 mutex_unlock(&wl->mutex);
1268} 1205}
1269 1206
@@ -1318,7 +1255,16 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1318 /* 0. read chip id from CHIP_ID */ 1255 /* 0. read chip id from CHIP_ID */
1319 wl->chip.id = wl1271_read32(wl, CHIP_ID_B); 1256 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
1320 1257
1321 /* 1. check if chip id is valid */ 1258 /*
1259 * For wl127x based devices we could use the default block
1260 * size (512 bytes), but due to a bug in the sdio driver, we
1261 * need to set it explicitly after the chip is powered on. To
1262 * simplify the code and since the performance impact is
1263 * negligible, we use the same block size for all different
1264 * chip types.
1265 */
1266 if (!wl1271_set_block_size(wl))
1267 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1322 1268
1323 switch (wl->chip.id) { 1269 switch (wl->chip.id) {
1324 case CHIP_ID_1271_PG10: 1270 case CHIP_ID_1271_PG10:
@@ -1328,7 +1274,9 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1328 ret = wl1271_setup(wl); 1274 ret = wl1271_setup(wl);
1329 if (ret < 0) 1275 if (ret < 0)
1330 goto out; 1276 goto out;
1277 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1331 break; 1278 break;
1279
1332 case CHIP_ID_1271_PG20: 1280 case CHIP_ID_1271_PG20:
1333 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", 1281 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1334 wl->chip.id); 1282 wl->chip.id);
@@ -1336,7 +1284,9 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1336 ret = wl1271_setup(wl); 1284 ret = wl1271_setup(wl);
1337 if (ret < 0) 1285 if (ret < 0)
1338 goto out; 1286 goto out;
1287 wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1339 break; 1288 break;
1289
1340 case CHIP_ID_1283_PG20: 1290 case CHIP_ID_1283_PG20:
1341 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)", 1291 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1342 wl->chip.id); 1292 wl->chip.id);
@@ -1344,9 +1294,6 @@ static int wl1271_chip_wakeup(struct wl1271 *wl)
1344 ret = wl1271_setup(wl); 1294 ret = wl1271_setup(wl);
1345 if (ret < 0) 1295 if (ret < 0)
1346 goto out; 1296 goto out;
1347
1348 if (wl1271_set_block_size(wl))
1349 wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
1350 break; 1297 break;
1351 case CHIP_ID_1283_PG10: 1298 case CHIP_ID_1283_PG10:
1352 default: 1299 default:
@@ -1389,8 +1336,6 @@ int wl1271_plt_start(struct wl1271 *wl)
1389 goto out; 1336 goto out;
1390 } 1337 }
1391 1338
1392 wl->bss_type = BSS_TYPE_STA_BSS;
1393
1394 while (retries) { 1339 while (retries) {
1395 retries--; 1340 retries--;
1396 ret = wl1271_chip_wakeup(wl); 1341 ret = wl1271_chip_wakeup(wl);
@@ -1482,33 +1427,34 @@ int wl1271_plt_stop(struct wl1271 *wl)
1482static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 1427static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1483{ 1428{
1484 struct wl1271 *wl = hw->priv; 1429 struct wl1271 *wl = hw->priv;
1430 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1431 struct ieee80211_vif *vif = info->control.vif;
1432 struct wl12xx_vif *wlvif = NULL;
1485 unsigned long flags; 1433 unsigned long flags;
1486 int q, mapping; 1434 int q, mapping;
1487 u8 hlid = 0; 1435 u8 hlid;
1436
1437 if (vif)
1438 wlvif = wl12xx_vif_to_data(vif);
1488 1439
1489 mapping = skb_get_queue_mapping(skb); 1440 mapping = skb_get_queue_mapping(skb);
1490 q = wl1271_tx_get_queue(mapping); 1441 q = wl1271_tx_get_queue(mapping);
1491 1442
1492 if (wl->bss_type == BSS_TYPE_AP_BSS) 1443 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
1493 hlid = wl12xx_tx_get_hlid_ap(wl, skb);
1494 1444
1495 spin_lock_irqsave(&wl->wl_lock, flags); 1445 spin_lock_irqsave(&wl->wl_lock, flags);
1496 1446
1497 /* queue the packet */ 1447 /* queue the packet */
1498 if (wl->bss_type == BSS_TYPE_AP_BSS) { 1448 if (hlid == WL12XX_INVALID_LINK_ID ||
1499 if (!wl1271_is_active_sta(wl, hlid)) { 1449 (wlvif && !test_bit(hlid, wlvif->links_map))) {
1500 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", 1450 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
1501 hlid, q); 1451 dev_kfree_skb(skb);
1502 dev_kfree_skb(skb); 1452 goto out;
1503 goto out;
1504 }
1505
1506 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1507 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1508 } else {
1509 skb_queue_tail(&wl->tx_queue[q], skb);
1510 } 1453 }
1511 1454
1455 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1456 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1457
1512 wl->tx_queue_count[q]++; 1458 wl->tx_queue_count[q]++;
1513 1459
1514 /* 1460 /*
@@ -1609,13 +1555,14 @@ static struct notifier_block wl1271_dev_notifier = {
1609}; 1555};
1610 1556
1611#ifdef CONFIG_PM 1557#ifdef CONFIG_PM
1612static int wl1271_configure_suspend_sta(struct wl1271 *wl) 1558static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1559 struct wl12xx_vif *wlvif)
1613{ 1560{
1614 int ret = 0; 1561 int ret = 0;
1615 1562
1616 mutex_lock(&wl->mutex); 1563 mutex_lock(&wl->mutex);
1617 1564
1618 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 1565 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1619 goto out_unlock; 1566 goto out_unlock;
1620 1567
1621 ret = wl1271_ps_elp_wakeup(wl); 1568 ret = wl1271_ps_elp_wakeup(wl);
@@ -1623,12 +1570,12 @@ static int wl1271_configure_suspend_sta(struct wl1271 *wl)
1623 goto out_unlock; 1570 goto out_unlock;
1624 1571
1625 /* enter psm if needed*/ 1572 /* enter psm if needed*/
1626 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) { 1573 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
1627 DECLARE_COMPLETION_ONSTACK(compl); 1574 DECLARE_COMPLETION_ONSTACK(compl);
1628 1575
1629 wl->ps_compl = &compl; 1576 wlvif->ps_compl = &compl;
1630 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 1577 ret = wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE,
1631 wl->basic_rate, true); 1578 wlvif->basic_rate, true);
1632 if (ret < 0) 1579 if (ret < 0)
1633 goto out_sleep; 1580 goto out_sleep;
1634 1581
@@ -1660,20 +1607,21 @@ out:
1660 1607
1661} 1608}
1662 1609
1663static int wl1271_configure_suspend_ap(struct wl1271 *wl) 1610static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1611 struct wl12xx_vif *wlvif)
1664{ 1612{
1665 int ret = 0; 1613 int ret = 0;
1666 1614
1667 mutex_lock(&wl->mutex); 1615 mutex_lock(&wl->mutex);
1668 1616
1669 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 1617 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1670 goto out_unlock; 1618 goto out_unlock;
1671 1619
1672 ret = wl1271_ps_elp_wakeup(wl); 1620 ret = wl1271_ps_elp_wakeup(wl);
1673 if (ret < 0) 1621 if (ret < 0)
1674 goto out_unlock; 1622 goto out_unlock;
1675 1623
1676 ret = wl1271_acx_beacon_filter_opt(wl, true); 1624 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
1677 1625
1678 wl1271_ps_elp_sleep(wl); 1626 wl1271_ps_elp_sleep(wl);
1679out_unlock: 1627out_unlock:
@@ -1682,20 +1630,22 @@ out_unlock:
1682 1630
1683} 1631}
1684 1632
1685static int wl1271_configure_suspend(struct wl1271 *wl) 1633static int wl1271_configure_suspend(struct wl1271 *wl,
1634 struct wl12xx_vif *wlvif)
1686{ 1635{
1687 if (wl->bss_type == BSS_TYPE_STA_BSS) 1636 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1688 return wl1271_configure_suspend_sta(wl); 1637 return wl1271_configure_suspend_sta(wl, wlvif);
1689 if (wl->bss_type == BSS_TYPE_AP_BSS) 1638 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1690 return wl1271_configure_suspend_ap(wl); 1639 return wl1271_configure_suspend_ap(wl, wlvif);
1691 return 0; 1640 return 0;
1692} 1641}
1693 1642
1694static void wl1271_configure_resume(struct wl1271 *wl) 1643static void wl1271_configure_resume(struct wl1271 *wl,
1644 struct wl12xx_vif *wlvif)
1695{ 1645{
1696 int ret; 1646 int ret;
1697 bool is_sta = wl->bss_type == BSS_TYPE_STA_BSS; 1647 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
1698 bool is_ap = wl->bss_type == BSS_TYPE_AP_BSS; 1648 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
1699 1649
1700 if (!is_sta && !is_ap) 1650 if (!is_sta && !is_ap)
1701 return; 1651 return;
@@ -1707,11 +1657,11 @@ static void wl1271_configure_resume(struct wl1271 *wl)
1707 1657
1708 if (is_sta) { 1658 if (is_sta) {
1709 /* exit psm if it wasn't configured */ 1659 /* exit psm if it wasn't configured */
1710 if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) 1660 if (!test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags))
1711 wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 1661 wl1271_ps_set_mode(wl, wlvif, STATION_ACTIVE_MODE,
1712 wl->basic_rate, true); 1662 wlvif->basic_rate, true);
1713 } else if (is_ap) { 1663 } else if (is_ap) {
1714 wl1271_acx_beacon_filter_opt(wl, false); 1664 wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1715 } 1665 }
1716 1666
1717 wl1271_ps_elp_sleep(wl); 1667 wl1271_ps_elp_sleep(wl);
@@ -1723,16 +1673,19 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1723 struct cfg80211_wowlan *wow) 1673 struct cfg80211_wowlan *wow)
1724{ 1674{
1725 struct wl1271 *wl = hw->priv; 1675 struct wl1271 *wl = hw->priv;
1676 struct wl12xx_vif *wlvif;
1726 int ret; 1677 int ret;
1727 1678
1728 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow); 1679 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1729 WARN_ON(!wow || !wow->any); 1680 WARN_ON(!wow || !wow->any);
1730 1681
1731 wl->wow_enabled = true; 1682 wl->wow_enabled = true;
1732 ret = wl1271_configure_suspend(wl); 1683 wl12xx_for_each_wlvif(wl, wlvif) {
1733 if (ret < 0) { 1684 ret = wl1271_configure_suspend(wl, wlvif);
1734 wl1271_warning("couldn't prepare device to suspend"); 1685 if (ret < 0) {
1735 return ret; 1686 wl1271_warning("couldn't prepare device to suspend");
1687 return ret;
1688 }
1736 } 1689 }
1737 /* flush any remaining work */ 1690 /* flush any remaining work */
1738 wl1271_debug(DEBUG_MAC80211, "flushing remaining works"); 1691 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
@@ -1751,7 +1704,9 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1751 1704
1752 wl1271_enable_interrupts(wl); 1705 wl1271_enable_interrupts(wl);
1753 flush_work(&wl->tx_work); 1706 flush_work(&wl->tx_work);
1754 flush_delayed_work(&wl->pspoll_work); 1707 wl12xx_for_each_wlvif(wl, wlvif) {
1708 flush_delayed_work(&wlvif->pspoll_work);
1709 }
1755 flush_delayed_work(&wl->elp_work); 1710 flush_delayed_work(&wl->elp_work);
1756 1711
1757 return 0; 1712 return 0;
@@ -1760,6 +1715,7 @@ static int wl1271_op_suspend(struct ieee80211_hw *hw,
1760static int wl1271_op_resume(struct ieee80211_hw *hw) 1715static int wl1271_op_resume(struct ieee80211_hw *hw)
1761{ 1716{
1762 struct wl1271 *wl = hw->priv; 1717 struct wl1271 *wl = hw->priv;
1718 struct wl12xx_vif *wlvif;
1763 unsigned long flags; 1719 unsigned long flags;
1764 bool run_irq_work = false; 1720 bool run_irq_work = false;
1765 1721
@@ -1783,7 +1739,9 @@ static int wl1271_op_resume(struct ieee80211_hw *hw)
1783 wl1271_irq(0, wl); 1739 wl1271_irq(0, wl);
1784 wl1271_enable_interrupts(wl); 1740 wl1271_enable_interrupts(wl);
1785 } 1741 }
1786 wl1271_configure_resume(wl); 1742 wl12xx_for_each_wlvif(wl, wlvif) {
1743 wl1271_configure_resume(wl, wlvif);
1744 }
1787 wl->wow_enabled = false; 1745 wl->wow_enabled = false;
1788 1746
1789 return 0; 1747 return 0;
@@ -1810,20 +1768,119 @@ static int wl1271_op_start(struct ieee80211_hw *hw)
1810 1768
1811static void wl1271_op_stop(struct ieee80211_hw *hw) 1769static void wl1271_op_stop(struct ieee80211_hw *hw)
1812{ 1770{
1771 struct wl1271 *wl = hw->priv;
1772 int i;
1773
1813 wl1271_debug(DEBUG_MAC80211, "mac80211 stop"); 1774 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1775
1776 mutex_lock(&wl->mutex);
1777 if (wl->state == WL1271_STATE_OFF) {
1778 mutex_unlock(&wl->mutex);
1779 return;
1780 }
1781 /*
1782 * this must be before the cancel_work calls below, so that the work
1783 * functions don't perform further work.
1784 */
1785 wl->state = WL1271_STATE_OFF;
1786 mutex_unlock(&wl->mutex);
1787
1788 mutex_lock(&wl_list_mutex);
1789 list_del(&wl->list);
1790 mutex_unlock(&wl_list_mutex);
1791
1792 wl1271_disable_interrupts(wl);
1793 wl1271_flush_deferred_work(wl);
1794 cancel_delayed_work_sync(&wl->scan_complete_work);
1795 cancel_work_sync(&wl->netstack_work);
1796 cancel_work_sync(&wl->tx_work);
1797 cancel_delayed_work_sync(&wl->elp_work);
1798
1799 /* let's notify MAC80211 about the remaining pending TX frames */
1800 wl12xx_tx_reset(wl, true);
1801 mutex_lock(&wl->mutex);
1802
1803 wl1271_power_off(wl);
1804
1805 wl->band = IEEE80211_BAND_2GHZ;
1806
1807 wl->rx_counter = 0;
1808 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1809 wl->tx_blocks_available = 0;
1810 wl->tx_allocated_blocks = 0;
1811 wl->tx_results_count = 0;
1812 wl->tx_packets_count = 0;
1813 wl->time_offset = 0;
1814 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1815 wl->ap_fw_ps_map = 0;
1816 wl->ap_ps_map = 0;
1817 wl->sched_scanning = false;
1818 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1819 memset(wl->links_map, 0, sizeof(wl->links_map));
1820 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1821 wl->active_sta_count = 0;
1822
1823 /* The system link is always allocated */
1824 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1825
1826 /*
1827 * this is performed after the cancel_work calls and the associated
1828 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1829 * get executed before all these vars have been reset.
1830 */
1831 wl->flags = 0;
1832
1833 wl->tx_blocks_freed = 0;
1834
1835 for (i = 0; i < NUM_TX_QUEUES; i++) {
1836 wl->tx_pkts_freed[i] = 0;
1837 wl->tx_allocated_pkts[i] = 0;
1838 }
1839
1840 wl1271_debugfs_reset(wl);
1841
1842 kfree(wl->fw_status);
1843 wl->fw_status = NULL;
1844 kfree(wl->tx_res_if);
1845 wl->tx_res_if = NULL;
1846 kfree(wl->target_mem_map);
1847 wl->target_mem_map = NULL;
1848
1849 mutex_unlock(&wl->mutex);
1814} 1850}
1815 1851
1816static u8 wl12xx_get_role_type(struct wl1271 *wl) 1852static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1817{ 1853{
1818 switch (wl->bss_type) { 1854 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1855 WL12XX_MAX_RATE_POLICIES);
1856 if (policy >= WL12XX_MAX_RATE_POLICIES)
1857 return -EBUSY;
1858
1859 __set_bit(policy, wl->rate_policies_map);
1860 *idx = policy;
1861 return 0;
1862}
1863
1864static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1865{
1866 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1867 return;
1868
1869 __clear_bit(*idx, wl->rate_policies_map);
1870 *idx = WL12XX_MAX_RATE_POLICIES;
1871}
1872
1873static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1874{
1875 switch (wlvif->bss_type) {
1819 case BSS_TYPE_AP_BSS: 1876 case BSS_TYPE_AP_BSS:
1820 if (wl->p2p) 1877 if (wlvif->p2p)
1821 return WL1271_ROLE_P2P_GO; 1878 return WL1271_ROLE_P2P_GO;
1822 else 1879 else
1823 return WL1271_ROLE_AP; 1880 return WL1271_ROLE_AP;
1824 1881
1825 case BSS_TYPE_STA_BSS: 1882 case BSS_TYPE_STA_BSS:
1826 if (wl->p2p) 1883 if (wlvif->p2p)
1827 return WL1271_ROLE_P2P_CL; 1884 return WL1271_ROLE_P2P_CL;
1828 else 1885 else
1829 return WL1271_ROLE_STA; 1886 return WL1271_ROLE_STA;
@@ -1832,78 +1889,95 @@ static u8 wl12xx_get_role_type(struct wl1271 *wl)
1832 return WL1271_ROLE_IBSS; 1889 return WL1271_ROLE_IBSS;
1833 1890
1834 default: 1891 default:
1835 wl1271_error("invalid bss_type: %d", wl->bss_type); 1892 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
1836 } 1893 }
1837 return WL12XX_INVALID_ROLE_TYPE; 1894 return WL12XX_INVALID_ROLE_TYPE;
1838} 1895}
1839 1896
1840static int wl1271_op_add_interface(struct ieee80211_hw *hw, 1897static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1841 struct ieee80211_vif *vif)
1842{ 1898{
1843 struct wl1271 *wl = hw->priv; 1899 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1844 struct wiphy *wiphy = hw->wiphy; 1900 int i;
1845 int retries = WL1271_BOOT_RETRIES;
1846 int ret = 0;
1847 u8 role_type;
1848 bool booted = false;
1849
1850 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1851 ieee80211_vif_type_p2p(vif), vif->addr);
1852
1853 mutex_lock(&wl->mutex);
1854 if (wl->vif) {
1855 wl1271_debug(DEBUG_MAC80211,
1856 "multiple vifs are not supported yet");
1857 ret = -EBUSY;
1858 goto out;
1859 }
1860 1901
1861 /* 1902 /* clear everything but the persistent data */
1862 * in some very corner case HW recovery scenarios its possible to 1903 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
1863 * get here before __wl1271_op_remove_interface is complete, so
1864 * opt out if that is the case.
1865 */
1866 if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
1867 ret = -EBUSY;
1868 goto out;
1869 }
1870 1904
1871 switch (ieee80211_vif_type_p2p(vif)) { 1905 switch (ieee80211_vif_type_p2p(vif)) {
1872 case NL80211_IFTYPE_P2P_CLIENT: 1906 case NL80211_IFTYPE_P2P_CLIENT:
1873 wl->p2p = 1; 1907 wlvif->p2p = 1;
1874 /* fall-through */ 1908 /* fall-through */
1875 case NL80211_IFTYPE_STATION: 1909 case NL80211_IFTYPE_STATION:
1876 wl->bss_type = BSS_TYPE_STA_BSS; 1910 wlvif->bss_type = BSS_TYPE_STA_BSS;
1877 wl->set_bss_type = BSS_TYPE_STA_BSS;
1878 break; 1911 break;
1879 case NL80211_IFTYPE_ADHOC: 1912 case NL80211_IFTYPE_ADHOC:
1880 wl->bss_type = BSS_TYPE_IBSS; 1913 wlvif->bss_type = BSS_TYPE_IBSS;
1881 wl->set_bss_type = BSS_TYPE_STA_BSS;
1882 break; 1914 break;
1883 case NL80211_IFTYPE_P2P_GO: 1915 case NL80211_IFTYPE_P2P_GO:
1884 wl->p2p = 1; 1916 wlvif->p2p = 1;
1885 /* fall-through */ 1917 /* fall-through */
1886 case NL80211_IFTYPE_AP: 1918 case NL80211_IFTYPE_AP:
1887 wl->bss_type = BSS_TYPE_AP_BSS; 1919 wlvif->bss_type = BSS_TYPE_AP_BSS;
1888 break; 1920 break;
1889 default: 1921 default:
1890 ret = -EOPNOTSUPP; 1922 wlvif->bss_type = MAX_BSS_TYPE;
1891 goto out; 1923 return -EOPNOTSUPP;
1892 } 1924 }
1893 1925
1894 role_type = wl12xx_get_role_type(wl); 1926 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
1895 if (role_type == WL12XX_INVALID_ROLE_TYPE) { 1927 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
1896 ret = -EINVAL; 1928 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
1897 goto out; 1929
1930 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1931 wlvif->bss_type == BSS_TYPE_IBSS) {
1932 /* init sta/ibss data */
1933 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
1934 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1935 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1936 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1937 } else {
1938 /* init ap data */
1939 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1940 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
1941 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1942 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1943 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1944 wl12xx_allocate_rate_policy(wl,
1945 &wlvif->ap.ucast_rate_idx[i]);
1898 } 1946 }
1899 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
1900 1947
1901 if (wl->state != WL1271_STATE_OFF) { 1948 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1902 wl1271_error("cannot start because not in off state: %d", 1949 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
1903 wl->state); 1950 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1904 ret = -EBUSY; 1951 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
1905 goto out; 1952 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
1906 } 1953 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1954
1955 /*
1956 * mac80211 configures some values globally, while we treat them
1957 * per-interface. thus, on init, we have to copy them from wl
1958 */
1959 wlvif->band = wl->band;
1960 wlvif->channel = wl->channel;
1961 wlvif->power_level = wl->power_level;
1962
1963 INIT_WORK(&wlvif->rx_streaming_enable_work,
1964 wl1271_rx_streaming_enable_work);
1965 INIT_WORK(&wlvif->rx_streaming_disable_work,
1966 wl1271_rx_streaming_disable_work);
1967 INIT_DELAYED_WORK(&wlvif->pspoll_work, wl1271_pspoll_work);
1968 INIT_LIST_HEAD(&wlvif->list);
1969
1970 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
1971 (unsigned long) wlvif);
1972 return 0;
1973}
1974
1975static bool wl12xx_init_fw(struct wl1271 *wl)
1976{
1977 int retries = WL1271_BOOT_RETRIES;
1978 bool booted = false;
1979 struct wiphy *wiphy = wl->hw->wiphy;
1980 int ret;
1907 1981
1908 while (retries) { 1982 while (retries) {
1909 retries--; 1983 retries--;
@@ -1915,25 +1989,6 @@ static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1915 if (ret < 0) 1989 if (ret < 0)
1916 goto power_off; 1990 goto power_off;
1917 1991
1918 if (wl->bss_type == BSS_TYPE_STA_BSS ||
1919 wl->bss_type == BSS_TYPE_IBSS) {
1920 /*
1921 * The device role is a special role used for
1922 * rx and tx frames prior to association (as
1923 * the STA role can get packets only from
1924 * its associated bssid)
1925 */
1926 ret = wl12xx_cmd_role_enable(wl,
1927 WL1271_ROLE_DEVICE,
1928 &wl->dev_role_id);
1929 if (ret < 0)
1930 goto irq_disable;
1931 }
1932
1933 ret = wl12xx_cmd_role_enable(wl, role_type, &wl->role_id);
1934 if (ret < 0)
1935 goto irq_disable;
1936
1937 ret = wl1271_hw_init(wl); 1992 ret = wl1271_hw_init(wl);
1938 if (ret < 0) 1993 if (ret < 0)
1939 goto irq_disable; 1994 goto irq_disable;
@@ -1964,9 +2019,6 @@ power_off:
1964 goto out; 2019 goto out;
1965 } 2020 }
1966 2021
1967 wl->vif = vif;
1968 wl->state = WL1271_STATE_ON;
1969 set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
1970 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str); 2022 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1971 2023
1972 /* update hw/fw version info in wiphy struct */ 2024 /* update hw/fw version info in wiphy struct */
@@ -1984,7 +2036,110 @@ power_off:
1984 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported", 2036 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1985 wl->enable_11a ? "" : "not "); 2037 wl->enable_11a ? "" : "not ");
1986 2038
2039 wl->state = WL1271_STATE_ON;
1987out: 2040out:
2041 return booted;
2042}
2043
2044static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2045 struct ieee80211_vif *vif)
2046{
2047 struct wl1271 *wl = hw->priv;
2048 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2049 int ret = 0;
2050 u8 role_type;
2051 bool booted = false;
2052
2053 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
2054 ieee80211_vif_type_p2p(vif), vif->addr);
2055
2056 mutex_lock(&wl->mutex);
2057 ret = wl1271_ps_elp_wakeup(wl);
2058 if (ret < 0)
2059 goto out_unlock;
2060
2061 if (wl->vif) {
2062 wl1271_debug(DEBUG_MAC80211,
2063 "multiple vifs are not supported yet");
2064 ret = -EBUSY;
2065 goto out;
2066 }
2067
2068 /*
2069 * in some very corner case HW recovery scenarios its possible to
2070 * get here before __wl1271_op_remove_interface is complete, so
2071 * opt out if that is the case.
2072 */
2073 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2074 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
2075 ret = -EBUSY;
2076 goto out;
2077 }
2078
2079 ret = wl12xx_init_vif_data(wl, vif);
2080 if (ret < 0)
2081 goto out;
2082
2083 wlvif->wl = wl;
2084 role_type = wl12xx_get_role_type(wl, wlvif);
2085 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2086 ret = -EINVAL;
2087 goto out;
2088 }
2089
2090 /*
2091 * TODO: after the nvs issue will be solved, move this block
2092 * to start(), and make sure here the driver is ON.
2093 */
2094 if (wl->state == WL1271_STATE_OFF) {
2095 /*
2096 * we still need this in order to configure the fw
2097 * while uploading the nvs
2098 */
2099 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
2100
2101 booted = wl12xx_init_fw(wl);
2102 if (!booted) {
2103 ret = -EINVAL;
2104 goto out;
2105 }
2106 }
2107
2108 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2109 wlvif->bss_type == BSS_TYPE_IBSS) {
2110 /*
2111 * The device role is a special role used for
2112 * rx and tx frames prior to association (as
2113 * the STA role can get packets only from
2114 * its associated bssid)
2115 */
2116 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2117 WL1271_ROLE_DEVICE,
2118 &wlvif->dev_role_id);
2119 if (ret < 0)
2120 goto out;
2121 }
2122
2123 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2124 role_type, &wlvif->role_id);
2125 if (ret < 0)
2126 goto out;
2127
2128 ret = wl1271_init_vif_specific(wl, vif);
2129 if (ret < 0)
2130 goto out;
2131
2132 wl->vif = vif;
2133 list_add(&wlvif->list, &wl->wlvif_list);
2134 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
2135
2136 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2137 wl->ap_count++;
2138 else
2139 wl->sta_count++;
2140out:
2141 wl1271_ps_elp_sleep(wl);
2142out_unlock:
1988 mutex_unlock(&wl->mutex); 2143 mutex_unlock(&wl->mutex);
1989 2144
1990 mutex_lock(&wl_list_mutex); 2145 mutex_lock(&wl_list_mutex);
@@ -1996,29 +2151,34 @@ out:
1996} 2151}
1997 2152
1998static void __wl1271_op_remove_interface(struct wl1271 *wl, 2153static void __wl1271_op_remove_interface(struct wl1271 *wl,
2154 struct ieee80211_vif *vif,
1999 bool reset_tx_queues) 2155 bool reset_tx_queues)
2000{ 2156{
2001 int ret, i; 2157 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2158 int i, ret;
2002 2159
2003 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface"); 2160 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
2004 2161
2162 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2163 return;
2164
2165 wl->vif = NULL;
2166
2005 /* because of hardware recovery, we may get here twice */ 2167 /* because of hardware recovery, we may get here twice */
2006 if (wl->state != WL1271_STATE_ON) 2168 if (wl->state != WL1271_STATE_ON)
2007 return; 2169 return;
2008 2170
2009 wl1271_info("down"); 2171 wl1271_info("down");
2010 2172
2011 mutex_lock(&wl_list_mutex);
2012 list_del(&wl->list);
2013 mutex_unlock(&wl_list_mutex);
2014
2015 /* enable dyn ps just in case (if left on due to fw crash etc) */ 2173 /* enable dyn ps just in case (if left on due to fw crash etc) */
2016 if (wl->bss_type == BSS_TYPE_STA_BSS) 2174 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
2017 ieee80211_enable_dyn_ps(wl->vif); 2175 ieee80211_enable_dyn_ps(vif);
2018 2176
2019 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) { 2177 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2178 wl->scan_vif == vif) {
2020 wl->scan.state = WL1271_SCAN_STATE_IDLE; 2179 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2021 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 2180 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
2181 wl->scan_vif = NULL;
2022 wl->scan.req = NULL; 2182 wl->scan.req = NULL;
2023 ieee80211_scan_completed(wl->hw, true); 2183 ieee80211_scan_completed(wl->hw, true);
2024 } 2184 }
@@ -2029,13 +2189,13 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
2029 if (ret < 0) 2189 if (ret < 0)
2030 goto deinit; 2190 goto deinit;
2031 2191
2032 if (wl->bss_type == BSS_TYPE_STA_BSS) { 2192 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
2033 ret = wl12xx_cmd_role_disable(wl, &wl->dev_role_id); 2193 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
2034 if (ret < 0) 2194 if (ret < 0)
2035 goto deinit; 2195 goto deinit;
2036 } 2196 }
2037 2197
2038 ret = wl12xx_cmd_role_disable(wl, &wl->role_id); 2198 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
2039 if (ret < 0) 2199 if (ret < 0)
2040 goto deinit; 2200 goto deinit;
2041 2201
@@ -2043,120 +2203,82 @@ static void __wl1271_op_remove_interface(struct wl1271 *wl,
2043 } 2203 }
2044deinit: 2204deinit:
2045 /* clear all hlids (except system_hlid) */ 2205 /* clear all hlids (except system_hlid) */
2046 wl->sta_hlid = WL12XX_INVALID_LINK_ID; 2206 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
2047 wl->dev_hlid = WL12XX_INVALID_LINK_ID; 2207
2048 wl->ap_bcast_hlid = WL12XX_INVALID_LINK_ID; 2208 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2049 wl->ap_global_hlid = WL12XX_INVALID_LINK_ID; 2209 wlvif->bss_type == BSS_TYPE_IBSS) {
2210 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2211 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2212 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2213 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2214 } else {
2215 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2216 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2217 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2218 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2219 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2220 wl12xx_free_rate_policy(wl,
2221 &wlvif->ap.ucast_rate_idx[i]);
2222 }
2050 2223
2051 /* 2224 wl12xx_tx_reset_wlvif(wl, wlvif);
2052 * this must be before the cancel_work calls below, so that the work 2225 wl1271_free_ap_keys(wl, wlvif);
2053 * functions don't perform further work. 2226 if (wl->last_wlvif == wlvif)
2054 */ 2227 wl->last_wlvif = NULL;
2055 wl->state = WL1271_STATE_OFF; 2228 list_del(&wlvif->list);
2229 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
2230 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
2231 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
2232
2233 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2234 wl->ap_count--;
2235 else
2236 wl->sta_count--;
2056 2237
2057 mutex_unlock(&wl->mutex); 2238 mutex_unlock(&wl->mutex);
2058 2239 del_timer_sync(&wlvif->rx_streaming_timer);
2059 wl1271_disable_interrupts(wl); 2240 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2060 wl1271_flush_deferred_work(wl); 2241 cancel_work_sync(&wlvif->rx_streaming_disable_work);
2061 cancel_delayed_work_sync(&wl->scan_complete_work); 2242 cancel_delayed_work_sync(&wlvif->pspoll_work);
2062 cancel_work_sync(&wl->netstack_work);
2063 cancel_work_sync(&wl->tx_work);
2064 del_timer_sync(&wl->rx_streaming_timer);
2065 cancel_work_sync(&wl->rx_streaming_enable_work);
2066 cancel_work_sync(&wl->rx_streaming_disable_work);
2067 cancel_delayed_work_sync(&wl->pspoll_work);
2068 cancel_delayed_work_sync(&wl->elp_work);
2069 2243
2070 mutex_lock(&wl->mutex); 2244 mutex_lock(&wl->mutex);
2071
2072 /* let's notify MAC80211 about the remaining pending TX frames */
2073 wl1271_tx_reset(wl, reset_tx_queues);
2074 wl1271_power_off(wl);
2075
2076 memset(wl->bssid, 0, ETH_ALEN);
2077 memset(wl->ssid, 0, IEEE80211_MAX_SSID_LEN + 1);
2078 wl->ssid_len = 0;
2079 wl->bss_type = MAX_BSS_TYPE;
2080 wl->set_bss_type = MAX_BSS_TYPE;
2081 wl->p2p = 0;
2082 wl->band = IEEE80211_BAND_2GHZ;
2083
2084 wl->rx_counter = 0;
2085 wl->psm_entry_retry = 0;
2086 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
2087 wl->tx_blocks_available = 0;
2088 wl->tx_allocated_blocks = 0;
2089 wl->tx_results_count = 0;
2090 wl->tx_packets_count = 0;
2091 wl->time_offset = 0;
2092 wl->session_counter = 0;
2093 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2094 wl->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
2095 wl->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
2096 wl->vif = NULL;
2097 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2098 wl1271_free_ap_keys(wl);
2099 memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
2100 wl->ap_fw_ps_map = 0;
2101 wl->ap_ps_map = 0;
2102 wl->sched_scanning = false;
2103 wl->role_id = WL12XX_INVALID_ROLE_ID;
2104 wl->dev_role_id = WL12XX_INVALID_ROLE_ID;
2105 memset(wl->roles_map, 0, sizeof(wl->roles_map));
2106 memset(wl->links_map, 0, sizeof(wl->links_map));
2107 memset(wl->roc_map, 0, sizeof(wl->roc_map));
2108 wl->active_sta_count = 0;
2109
2110 /* The system link is always allocated */
2111 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
2112
2113 /*
2114 * this is performed after the cancel_work calls and the associated
2115 * mutex_lock, so that wl1271_op_add_interface does not accidentally
2116 * get executed before all these vars have been reset.
2117 */
2118 wl->flags = 0;
2119
2120 wl->tx_blocks_freed = 0;
2121
2122 for (i = 0; i < NUM_TX_QUEUES; i++) {
2123 wl->tx_pkts_freed[i] = 0;
2124 wl->tx_allocated_pkts[i] = 0;
2125 }
2126
2127 wl1271_debugfs_reset(wl);
2128
2129 kfree(wl->fw_status);
2130 wl->fw_status = NULL;
2131 kfree(wl->tx_res_if);
2132 wl->tx_res_if = NULL;
2133 kfree(wl->target_mem_map);
2134 wl->target_mem_map = NULL;
2135} 2245}
2136 2246
2137static void wl1271_op_remove_interface(struct ieee80211_hw *hw, 2247static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2138 struct ieee80211_vif *vif) 2248 struct ieee80211_vif *vif)
2139{ 2249{
2140 struct wl1271 *wl = hw->priv; 2250 struct wl1271 *wl = hw->priv;
2251 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2252 struct wl12xx_vif *iter;
2141 2253
2142 mutex_lock(&wl->mutex); 2254 mutex_lock(&wl->mutex);
2255
2256 if (wl->state == WL1271_STATE_OFF ||
2257 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2258 goto out;
2259
2143 /* 2260 /*
2144 * wl->vif can be null here if someone shuts down the interface 2261 * wl->vif can be null here if someone shuts down the interface
2145 * just when hardware recovery has been started. 2262 * just when hardware recovery has been started.
2146 */ 2263 */
2147 if (wl->vif) { 2264 wl12xx_for_each_wlvif(wl, iter) {
2148 WARN_ON(wl->vif != vif); 2265 if (iter != wlvif)
2149 __wl1271_op_remove_interface(wl, true); 2266 continue;
2150 }
2151 2267
2268 __wl1271_op_remove_interface(wl, vif, true);
2269 break;
2270 }
2271 WARN_ON(iter != wlvif);
2272out:
2152 mutex_unlock(&wl->mutex); 2273 mutex_unlock(&wl->mutex);
2153 cancel_work_sync(&wl->recovery_work); 2274 cancel_work_sync(&wl->recovery_work);
2154} 2275}
2155 2276
2156static int wl1271_join(struct wl1271 *wl, bool set_assoc) 2277static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2278 bool set_assoc)
2157{ 2279{
2158 int ret; 2280 int ret;
2159 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 2281 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
2160 2282
2161 /* 2283 /*
2162 * One of the side effects of the JOIN command is that is clears 2284 * One of the side effects of the JOIN command is that is clears
@@ -2167,20 +2289,20 @@ static int wl1271_join(struct wl1271 *wl, bool set_assoc)
2167 * Keep the below message for now, unless it starts bothering 2289 * Keep the below message for now, unless it starts bothering
2168 * users who really like to roam a lot :) 2290 * users who really like to roam a lot :)
2169 */ 2291 */
2170 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2292 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2171 wl1271_info("JOIN while associated."); 2293 wl1271_info("JOIN while associated.");
2172 2294
2173 if (set_assoc) 2295 if (set_assoc)
2174 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags); 2296 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
2175 2297
2176 if (is_ibss) 2298 if (is_ibss)
2177 ret = wl12xx_cmd_role_start_ibss(wl); 2299 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
2178 else 2300 else
2179 ret = wl12xx_cmd_role_start_sta(wl); 2301 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
2180 if (ret < 0) 2302 if (ret < 0)
2181 goto out; 2303 goto out;
2182 2304
2183 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2305 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2184 goto out; 2306 goto out;
2185 2307
2186 /* 2308 /*
@@ -2189,19 +2311,20 @@ static int wl1271_join(struct wl1271 *wl, bool set_assoc)
2189 * the join. The acx_aid starts the keep-alive process, and the order 2311 * the join. The acx_aid starts the keep-alive process, and the order
2190 * of the commands below is relevant. 2312 * of the commands below is relevant.
2191 */ 2313 */
2192 ret = wl1271_acx_keep_alive_mode(wl, true); 2314 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
2193 if (ret < 0) 2315 if (ret < 0)
2194 goto out; 2316 goto out;
2195 2317
2196 ret = wl1271_acx_aid(wl, wl->aid); 2318 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
2197 if (ret < 0) 2319 if (ret < 0)
2198 goto out; 2320 goto out;
2199 2321
2200 ret = wl1271_cmd_build_klv_null_data(wl); 2322 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
2201 if (ret < 0) 2323 if (ret < 0)
2202 goto out; 2324 goto out;
2203 2325
2204 ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA, 2326 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2327 CMD_TEMPL_KLV_IDX_NULL_DATA,
2205 ACX_KEEP_ALIVE_TPL_VALID); 2328 ACX_KEEP_ALIVE_TPL_VALID);
2206 if (ret < 0) 2329 if (ret < 0)
2207 goto out; 2330 goto out;
@@ -2210,34 +2333,34 @@ out:
2210 return ret; 2333 return ret;
2211} 2334}
2212 2335
2213static int wl1271_unjoin(struct wl1271 *wl) 2336static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2214{ 2337{
2215 int ret; 2338 int ret;
2216 2339
2217 if (test_and_clear_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags)) { 2340 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
2341 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2342
2218 wl12xx_cmd_stop_channel_switch(wl); 2343 wl12xx_cmd_stop_channel_switch(wl);
2219 ieee80211_chswitch_done(wl->vif, false); 2344 ieee80211_chswitch_done(vif, false);
2220 } 2345 }
2221 2346
2222 /* to stop listening to a channel, we disconnect */ 2347 /* to stop listening to a channel, we disconnect */
2223 ret = wl12xx_cmd_role_stop_sta(wl); 2348 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
2224 if (ret < 0) 2349 if (ret < 0)
2225 goto out; 2350 goto out;
2226 2351
2227 memset(wl->bssid, 0, ETH_ALEN);
2228
2229 /* reset TX security counters on a clean disconnect */ 2352 /* reset TX security counters on a clean disconnect */
2230 wl->tx_security_last_seq_lsb = 0; 2353 wlvif->tx_security_last_seq_lsb = 0;
2231 wl->tx_security_seq = 0; 2354 wlvif->tx_security_seq = 0;
2232 2355
2233out: 2356out:
2234 return ret; 2357 return ret;
2235} 2358}
2236 2359
2237static void wl1271_set_band_rate(struct wl1271 *wl) 2360static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2238{ 2361{
2239 wl->basic_rate_set = wl->bitrate_masks[wl->band]; 2362 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
2240 wl->rate_set = wl->basic_rate_set; 2363 wlvif->rate_set = wlvif->basic_rate_set;
2241} 2364}
2242 2365
2243static bool wl12xx_is_roc(struct wl1271 *wl) 2366static bool wl12xx_is_roc(struct wl1271 *wl)
@@ -2251,27 +2374,25 @@ static bool wl12xx_is_roc(struct wl1271 *wl)
2251 return true; 2374 return true;
2252} 2375}
2253 2376
2254static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle) 2377static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2378 bool idle)
2255{ 2379{
2256 int ret; 2380 int ret;
2257 2381
2258 if (idle) { 2382 if (idle) {
2259 /* no need to croc if we weren't busy (e.g. during boot) */ 2383 /* no need to croc if we weren't busy (e.g. during boot) */
2260 if (wl12xx_is_roc(wl)) { 2384 if (wl12xx_is_roc(wl)) {
2261 ret = wl12xx_croc(wl, wl->dev_role_id); 2385 ret = wl12xx_stop_dev(wl, wlvif);
2262 if (ret < 0)
2263 goto out;
2264
2265 ret = wl12xx_cmd_role_stop_dev(wl);
2266 if (ret < 0) 2386 if (ret < 0)
2267 goto out; 2387 goto out;
2268 } 2388 }
2269 wl->rate_set = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 2389 wlvif->rate_set =
2270 ret = wl1271_acx_sta_rate_policies(wl); 2390 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2391 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2271 if (ret < 0) 2392 if (ret < 0)
2272 goto out; 2393 goto out;
2273 ret = wl1271_acx_keep_alive_config( 2394 ret = wl1271_acx_keep_alive_config(
2274 wl, CMD_TEMPL_KLV_IDX_NULL_DATA, 2395 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
2275 ACX_KEEP_ALIVE_TPL_INVALID); 2396 ACX_KEEP_ALIVE_TPL_INVALID);
2276 if (ret < 0) 2397 if (ret < 0)
2277 goto out; 2398 goto out;
@@ -2283,11 +2404,7 @@ static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
2283 ieee80211_sched_scan_stopped(wl->hw); 2404 ieee80211_sched_scan_stopped(wl->hw);
2284 } 2405 }
2285 2406
2286 ret = wl12xx_cmd_role_start_dev(wl); 2407 ret = wl12xx_start_dev(wl, wlvif);
2287 if (ret < 0)
2288 goto out;
2289
2290 ret = wl12xx_roc(wl, wl->dev_role_id);
2291 if (ret < 0) 2408 if (ret < 0)
2292 goto out; 2409 goto out;
2293 clear_bit(WL1271_FLAG_IDLE, &wl->flags); 2410 clear_bit(WL1271_FLAG_IDLE, &wl->flags);
@@ -2297,61 +2414,22 @@ out:
2297 return ret; 2414 return ret;
2298} 2415}
2299 2416
2300static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed) 2417static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2418 struct ieee80211_conf *conf, u32 changed)
2301{ 2419{
2302 struct wl1271 *wl = hw->priv; 2420 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2303 struct ieee80211_conf *conf = &hw->conf; 2421 int channel, ret;
2304 int channel, ret = 0;
2305 bool is_ap;
2306 2422
2307 channel = ieee80211_frequency_to_channel(conf->channel->center_freq); 2423 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2308 2424
2309 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2310 " changed 0x%x",
2311 channel,
2312 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2313 conf->power_level,
2314 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2315 changed);
2316
2317 /*
2318 * mac80211 will go to idle nearly immediately after transmitting some
2319 * frames, such as the deauth. To make sure those frames reach the air,
2320 * wait here until the TX queue is fully flushed.
2321 */
2322 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2323 (conf->flags & IEEE80211_CONF_IDLE))
2324 wl1271_tx_flush(wl);
2325
2326 mutex_lock(&wl->mutex);
2327
2328 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2329 /* we support configuring the channel and band while off */
2330 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2331 wl->band = conf->channel->band;
2332 wl->channel = channel;
2333 }
2334
2335 if ((changed & IEEE80211_CONF_CHANGE_POWER))
2336 wl->power_level = conf->power_level;
2337
2338 goto out;
2339 }
2340
2341 is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2342
2343 ret = wl1271_ps_elp_wakeup(wl);
2344 if (ret < 0)
2345 goto out;
2346
2347 /* if the channel changes while joined, join again */ 2425 /* if the channel changes while joined, join again */
2348 if (changed & IEEE80211_CONF_CHANGE_CHANNEL && 2426 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2349 ((wl->band != conf->channel->band) || 2427 ((wlvif->band != conf->channel->band) ||
2350 (wl->channel != channel))) { 2428 (wlvif->channel != channel))) {
2351 /* send all pending packets */ 2429 /* send all pending packets */
2352 wl1271_tx_work_locked(wl); 2430 wl1271_tx_work_locked(wl);
2353 wl->band = conf->channel->band; 2431 wlvif->band = conf->channel->band;
2354 wl->channel = channel; 2432 wlvif->channel = channel;
2355 2433
2356 if (!is_ap) { 2434 if (!is_ap) {
2357 /* 2435 /*
@@ -2360,24 +2438,27 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2360 * possible rate for the band as a fixed rate for 2438 * possible rate for the band as a fixed rate for
2361 * association frames and other control messages. 2439 * association frames and other control messages.
2362 */ 2440 */
2363 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) 2441 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2364 wl1271_set_band_rate(wl); 2442 wl1271_set_band_rate(wl, wlvif);
2365 2443
2366 wl->basic_rate = 2444 wlvif->basic_rate =
2367 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 2445 wl1271_tx_min_rate_get(wl,
2368 ret = wl1271_acx_sta_rate_policies(wl); 2446 wlvif->basic_rate_set);
2447 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2369 if (ret < 0) 2448 if (ret < 0)
2370 wl1271_warning("rate policy for channel " 2449 wl1271_warning("rate policy for channel "
2371 "failed %d", ret); 2450 "failed %d", ret);
2372 2451
2373 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 2452 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2453 &wlvif->flags)) {
2374 if (wl12xx_is_roc(wl)) { 2454 if (wl12xx_is_roc(wl)) {
2375 /* roaming */ 2455 /* roaming */
2376 ret = wl12xx_croc(wl, wl->dev_role_id); 2456 ret = wl12xx_croc(wl,
2457 wlvif->dev_role_id);
2377 if (ret < 0) 2458 if (ret < 0)
2378 goto out_sleep; 2459 return ret;
2379 } 2460 }
2380 ret = wl1271_join(wl, false); 2461 ret = wl1271_join(wl, wlvif, false);
2381 if (ret < 0) 2462 if (ret < 0)
2382 wl1271_warning("cmd join on channel " 2463 wl1271_warning("cmd join on channel "
2383 "failed %d", ret); 2464 "failed %d", ret);
@@ -2389,64 +2470,112 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2389 */ 2470 */
2390 if (wl12xx_is_roc(wl) && 2471 if (wl12xx_is_roc(wl) &&
2391 !(conf->flags & IEEE80211_CONF_IDLE)) { 2472 !(conf->flags & IEEE80211_CONF_IDLE)) {
2392 ret = wl12xx_croc(wl, wl->dev_role_id); 2473 ret = wl12xx_stop_dev(wl, wlvif);
2393 if (ret < 0) 2474 if (ret < 0)
2394 goto out_sleep; 2475 return ret;
2395 2476
2396 ret = wl12xx_roc(wl, wl->dev_role_id); 2477 ret = wl12xx_start_dev(wl, wlvif);
2397 if (ret < 0) 2478 if (ret < 0)
2398 wl1271_warning("roc failed %d", 2479 return ret;
2399 ret);
2400 } 2480 }
2401 } 2481 }
2402 } 2482 }
2403 } 2483 }
2404 2484
2405 if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) {
2406 ret = wl1271_sta_handle_idle(wl,
2407 conf->flags & IEEE80211_CONF_IDLE);
2408 if (ret < 0)
2409 wl1271_warning("idle mode change failed %d", ret);
2410 }
2411
2412 /* 2485 /*
2413 * if mac80211 changes the PSM mode, make sure the mode is not 2486 * if mac80211 changes the PSM mode, make sure the mode is not
2414 * incorrectly changed after the pspoll failure active window. 2487 * incorrectly changed after the pspoll failure active window.
2415 */ 2488 */
2416 if (changed & IEEE80211_CONF_CHANGE_PS) 2489 if (changed & IEEE80211_CONF_CHANGE_PS)
2417 clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags); 2490 clear_bit(WLVIF_FLAG_PSPOLL_FAILURE, &wlvif->flags);
2418 2491
2419 if (conf->flags & IEEE80211_CONF_PS && 2492 if (conf->flags & IEEE80211_CONF_PS &&
2420 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { 2493 !test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
2421 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); 2494 set_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
2422 2495
2423 /* 2496 /*
2424 * We enter PSM only if we're already associated. 2497 * We enter PSM only if we're already associated.
2425 * If we're not, we'll enter it when joining an SSID, 2498 * If we're not, we'll enter it when joining an SSID,
2426 * through the bss_info_changed() hook. 2499 * through the bss_info_changed() hook.
2427 */ 2500 */
2428 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 2501 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
2429 wl1271_debug(DEBUG_PSM, "psm enabled"); 2502 wl1271_debug(DEBUG_PSM, "psm enabled");
2430 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE, 2503 ret = wl1271_ps_set_mode(wl, wlvif,
2431 wl->basic_rate, true); 2504 STATION_POWER_SAVE_MODE,
2505 wlvif->basic_rate, true);
2432 } 2506 }
2433 } else if (!(conf->flags & IEEE80211_CONF_PS) && 2507 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2434 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) { 2508 test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags)) {
2435 wl1271_debug(DEBUG_PSM, "psm disabled"); 2509 wl1271_debug(DEBUG_PSM, "psm disabled");
2436 2510
2437 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags); 2511 clear_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags);
2438 2512
2439 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) 2513 if (test_bit(WLVIF_FLAG_PSM, &wlvif->flags))
2440 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE, 2514 ret = wl1271_ps_set_mode(wl, wlvif,
2441 wl->basic_rate, true); 2515 STATION_ACTIVE_MODE,
2516 wlvif->basic_rate, true);
2442 } 2517 }
2443 2518
2444 if (conf->power_level != wl->power_level) { 2519 if (conf->power_level != wlvif->power_level) {
2445 ret = wl1271_acx_tx_power(wl, conf->power_level); 2520 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
2446 if (ret < 0) 2521 if (ret < 0)
2447 goto out_sleep; 2522 return ret;
2523
2524 wlvif->power_level = conf->power_level;
2525 }
2526
2527 return 0;
2528}
2529
2530static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2531{
2532 struct wl1271 *wl = hw->priv;
2533 struct wl12xx_vif *wlvif;
2534 struct ieee80211_conf *conf = &hw->conf;
2535 int channel, ret = 0;
2536
2537 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2538
2539 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2540 " changed 0x%x",
2541 channel,
2542 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2543 conf->power_level,
2544 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2545 changed);
2546
2547 /*
2548 * mac80211 will go to idle nearly immediately after transmitting some
2549 * frames, such as the deauth. To make sure those frames reach the air,
2550 * wait here until the TX queue is fully flushed.
2551 */
2552 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2553 (conf->flags & IEEE80211_CONF_IDLE))
2554 wl1271_tx_flush(wl);
2555
2556 mutex_lock(&wl->mutex);
2448 2557
2558 /* we support configuring the channel and band even while off */
2559 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2560 wl->band = conf->channel->band;
2561 wl->channel = channel;
2562 }
2563
2564 if (changed & IEEE80211_CONF_CHANGE_POWER)
2449 wl->power_level = conf->power_level; 2565 wl->power_level = conf->power_level;
2566
2567 if (unlikely(wl->state == WL1271_STATE_OFF))
2568 goto out;
2569
2570 ret = wl1271_ps_elp_wakeup(wl);
2571 if (ret < 0)
2572 goto out;
2573
2574 /* configure each interface */
2575 wl12xx_for_each_wlvif(wl, wlvif) {
2576 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2577 if (ret < 0)
2578 goto out_sleep;
2450 } 2579 }
2451 2580
2452out_sleep: 2581out_sleep:
@@ -2509,6 +2638,8 @@ static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2509{ 2638{
2510 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast; 2639 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2511 struct wl1271 *wl = hw->priv; 2640 struct wl1271 *wl = hw->priv;
2641 struct wl12xx_vif *wlvif;
2642
2512 int ret; 2643 int ret;
2513 2644
2514 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x" 2645 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
@@ -2526,15 +2657,20 @@ static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2526 if (ret < 0) 2657 if (ret < 0)
2527 goto out; 2658 goto out;
2528 2659
2529 if (wl->bss_type != BSS_TYPE_AP_BSS) { 2660 wl12xx_for_each_wlvif(wl, wlvif) {
2530 if (*total & FIF_ALLMULTI) 2661 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2531 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0); 2662 if (*total & FIF_ALLMULTI)
2532 else if (fp) 2663 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2533 ret = wl1271_acx_group_address_tbl(wl, fp->enabled, 2664 false,
2534 fp->mc_list, 2665 NULL, 0);
2535 fp->mc_list_length); 2666 else if (fp)
2536 if (ret < 0) 2667 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2537 goto out_sleep; 2668 fp->enabled,
2669 fp->mc_list,
2670 fp->mc_list_length);
2671 if (ret < 0)
2672 goto out_sleep;
2673 }
2538 } 2674 }
2539 2675
2540 /* 2676 /*
@@ -2551,9 +2687,10 @@ out:
2551 kfree(fp); 2687 kfree(fp);
2552} 2688}
2553 2689
2554static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type, 2690static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2555 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, 2691 u8 id, u8 key_type, u8 key_size,
2556 u16 tx_seq_16) 2692 const u8 *key, u8 hlid, u32 tx_seq_32,
2693 u16 tx_seq_16)
2557{ 2694{
2558 struct wl1271_ap_key *ap_key; 2695 struct wl1271_ap_key *ap_key;
2559 int i; 2696 int i;
@@ -2568,10 +2705,10 @@ static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2568 * an existing key. 2705 * an existing key.
2569 */ 2706 */
2570 for (i = 0; i < MAX_NUM_KEYS; i++) { 2707 for (i = 0; i < MAX_NUM_KEYS; i++) {
2571 if (wl->recorded_ap_keys[i] == NULL) 2708 if (wlvif->ap.recorded_keys[i] == NULL)
2572 break; 2709 break;
2573 2710
2574 if (wl->recorded_ap_keys[i]->id == id) { 2711 if (wlvif->ap.recorded_keys[i]->id == id) {
2575 wl1271_warning("trying to record key replacement"); 2712 wl1271_warning("trying to record key replacement");
2576 return -EINVAL; 2713 return -EINVAL;
2577 } 2714 }
@@ -2592,21 +2729,21 @@ static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2592 ap_key->tx_seq_32 = tx_seq_32; 2729 ap_key->tx_seq_32 = tx_seq_32;
2593 ap_key->tx_seq_16 = tx_seq_16; 2730 ap_key->tx_seq_16 = tx_seq_16;
2594 2731
2595 wl->recorded_ap_keys[i] = ap_key; 2732 wlvif->ap.recorded_keys[i] = ap_key;
2596 return 0; 2733 return 0;
2597} 2734}
2598 2735
2599static void wl1271_free_ap_keys(struct wl1271 *wl) 2736static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2600{ 2737{
2601 int i; 2738 int i;
2602 2739
2603 for (i = 0; i < MAX_NUM_KEYS; i++) { 2740 for (i = 0; i < MAX_NUM_KEYS; i++) {
2604 kfree(wl->recorded_ap_keys[i]); 2741 kfree(wlvif->ap.recorded_keys[i]);
2605 wl->recorded_ap_keys[i] = NULL; 2742 wlvif->ap.recorded_keys[i] = NULL;
2606 } 2743 }
2607} 2744}
2608 2745
2609static int wl1271_ap_init_hwenc(struct wl1271 *wl) 2746static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2610{ 2747{
2611 int i, ret = 0; 2748 int i, ret = 0;
2612 struct wl1271_ap_key *key; 2749 struct wl1271_ap_key *key;
@@ -2614,15 +2751,15 @@ static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2614 2751
2615 for (i = 0; i < MAX_NUM_KEYS; i++) { 2752 for (i = 0; i < MAX_NUM_KEYS; i++) {
2616 u8 hlid; 2753 u8 hlid;
2617 if (wl->recorded_ap_keys[i] == NULL) 2754 if (wlvif->ap.recorded_keys[i] == NULL)
2618 break; 2755 break;
2619 2756
2620 key = wl->recorded_ap_keys[i]; 2757 key = wlvif->ap.recorded_keys[i];
2621 hlid = key->hlid; 2758 hlid = key->hlid;
2622 if (hlid == WL12XX_INVALID_LINK_ID) 2759 if (hlid == WL12XX_INVALID_LINK_ID)
2623 hlid = wl->ap_bcast_hlid; 2760 hlid = wlvif->ap.bcast_hlid;
2624 2761
2625 ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE, 2762 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2626 key->id, key->key_type, 2763 key->id, key->key_type,
2627 key->key_size, key->key, 2764 key->key_size, key->key,
2628 hlid, key->tx_seq_32, 2765 hlid, key->tx_seq_32,
@@ -2635,23 +2772,24 @@ static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2635 } 2772 }
2636 2773
2637 if (wep_key_added) { 2774 if (wep_key_added) {
2638 ret = wl12xx_cmd_set_default_wep_key(wl, wl->default_key, 2775 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
2639 wl->ap_bcast_hlid); 2776 wlvif->ap.bcast_hlid);
2640 if (ret < 0) 2777 if (ret < 0)
2641 goto out; 2778 goto out;
2642 } 2779 }
2643 2780
2644out: 2781out:
2645 wl1271_free_ap_keys(wl); 2782 wl1271_free_ap_keys(wl, wlvif);
2646 return ret; 2783 return ret;
2647} 2784}
2648 2785
2649static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type, 2786static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2787 u16 action, u8 id, u8 key_type,
2650 u8 key_size, const u8 *key, u32 tx_seq_32, 2788 u8 key_size, const u8 *key, u32 tx_seq_32,
2651 u16 tx_seq_16, struct ieee80211_sta *sta) 2789 u16 tx_seq_16, struct ieee80211_sta *sta)
2652{ 2790{
2653 int ret; 2791 int ret;
2654 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 2792 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2655 2793
2656 if (is_ap) { 2794 if (is_ap) {
2657 struct wl1271_station *wl_sta; 2795 struct wl1271_station *wl_sta;
@@ -2661,10 +2799,10 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2661 wl_sta = (struct wl1271_station *)sta->drv_priv; 2799 wl_sta = (struct wl1271_station *)sta->drv_priv;
2662 hlid = wl_sta->hlid; 2800 hlid = wl_sta->hlid;
2663 } else { 2801 } else {
2664 hlid = wl->ap_bcast_hlid; 2802 hlid = wlvif->ap.bcast_hlid;
2665 } 2803 }
2666 2804
2667 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 2805 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
2668 /* 2806 /*
2669 * We do not support removing keys after AP shutdown. 2807 * We do not support removing keys after AP shutdown.
2670 * Pretend we do to make mac80211 happy. 2808 * Pretend we do to make mac80211 happy.
@@ -2672,12 +2810,12 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2672 if (action != KEY_ADD_OR_REPLACE) 2810 if (action != KEY_ADD_OR_REPLACE)
2673 return 0; 2811 return 0;
2674 2812
2675 ret = wl1271_record_ap_key(wl, id, 2813 ret = wl1271_record_ap_key(wl, wlvif, id,
2676 key_type, key_size, 2814 key_type, key_size,
2677 key, hlid, tx_seq_32, 2815 key, hlid, tx_seq_32,
2678 tx_seq_16); 2816 tx_seq_16);
2679 } else { 2817 } else {
2680 ret = wl1271_cmd_set_ap_key(wl, action, 2818 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
2681 id, key_type, key_size, 2819 id, key_type, key_size,
2682 key, hlid, tx_seq_32, 2820 key, hlid, tx_seq_32,
2683 tx_seq_16); 2821 tx_seq_16);
@@ -2718,10 +2856,10 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2718 2856
2719 /* don't remove key if hlid was already deleted */ 2857 /* don't remove key if hlid was already deleted */
2720 if (action == KEY_REMOVE && 2858 if (action == KEY_REMOVE &&
2721 wl->sta_hlid == WL12XX_INVALID_LINK_ID) 2859 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
2722 return 0; 2860 return 0;
2723 2861
2724 ret = wl1271_cmd_set_sta_key(wl, action, 2862 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
2725 id, key_type, key_size, 2863 id, key_type, key_size,
2726 key, addr, tx_seq_32, 2864 key, addr, tx_seq_32,
2727 tx_seq_16); 2865 tx_seq_16);
@@ -2731,8 +2869,8 @@ static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2731 /* the default WEP key needs to be configured at least once */ 2869 /* the default WEP key needs to be configured at least once */
2732 if (key_type == KEY_WEP) { 2870 if (key_type == KEY_WEP) {
2733 ret = wl12xx_cmd_set_default_wep_key(wl, 2871 ret = wl12xx_cmd_set_default_wep_key(wl,
2734 wl->default_key, 2872 wlvif->default_key,
2735 wl->sta_hlid); 2873 wlvif->sta.hlid);
2736 if (ret < 0) 2874 if (ret < 0)
2737 return ret; 2875 return ret;
2738 } 2876 }
@@ -2747,6 +2885,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2747 struct ieee80211_key_conf *key_conf) 2885 struct ieee80211_key_conf *key_conf)
2748{ 2886{
2749 struct wl1271 *wl = hw->priv; 2887 struct wl1271 *wl = hw->priv;
2888 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2750 int ret; 2889 int ret;
2751 u32 tx_seq_32 = 0; 2890 u32 tx_seq_32 = 0;
2752 u16 tx_seq_16 = 0; 2891 u16 tx_seq_16 = 0;
@@ -2782,20 +2921,20 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2782 key_type = KEY_TKIP; 2921 key_type = KEY_TKIP;
2783 2922
2784 key_conf->hw_key_idx = key_conf->keyidx; 2923 key_conf->hw_key_idx = key_conf->keyidx;
2785 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2924 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2786 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2925 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2787 break; 2926 break;
2788 case WLAN_CIPHER_SUITE_CCMP: 2927 case WLAN_CIPHER_SUITE_CCMP:
2789 key_type = KEY_AES; 2928 key_type = KEY_AES;
2790 2929
2791 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 2930 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2792 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2931 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2793 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2932 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2794 break; 2933 break;
2795 case WL1271_CIPHER_SUITE_GEM: 2934 case WL1271_CIPHER_SUITE_GEM:
2796 key_type = KEY_GEM; 2935 key_type = KEY_GEM;
2797 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq); 2936 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
2798 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq); 2937 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
2799 break; 2938 break;
2800 default: 2939 default:
2801 wl1271_error("Unknown key algo 0x%x", key_conf->cipher); 2940 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
@@ -2806,7 +2945,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2806 2945
2807 switch (cmd) { 2946 switch (cmd) {
2808 case SET_KEY: 2947 case SET_KEY:
2809 ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE, 2948 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2810 key_conf->keyidx, key_type, 2949 key_conf->keyidx, key_type,
2811 key_conf->keylen, key_conf->key, 2950 key_conf->keylen, key_conf->key,
2812 tx_seq_32, tx_seq_16, sta); 2951 tx_seq_32, tx_seq_16, sta);
@@ -2817,7 +2956,7 @@ static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2817 break; 2956 break;
2818 2957
2819 case DISABLE_KEY: 2958 case DISABLE_KEY:
2820 ret = wl1271_set_key(wl, KEY_REMOVE, 2959 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
2821 key_conf->keyidx, key_type, 2960 key_conf->keyidx, key_type,
2822 key_conf->keylen, key_conf->key, 2961 key_conf->keylen, key_conf->key,
2823 0, 0, sta); 2962 0, 0, sta);
@@ -2847,6 +2986,8 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2847 struct cfg80211_scan_request *req) 2986 struct cfg80211_scan_request *req)
2848{ 2987{
2849 struct wl1271 *wl = hw->priv; 2988 struct wl1271 *wl = hw->priv;
2989 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2990
2850 int ret; 2991 int ret;
2851 u8 *ssid = NULL; 2992 u8 *ssid = NULL;
2852 size_t len = 0; 2993 size_t len = 0;
@@ -2876,16 +3017,15 @@ static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2876 3017
2877 /* cancel ROC before scanning */ 3018 /* cancel ROC before scanning */
2878 if (wl12xx_is_roc(wl)) { 3019 if (wl12xx_is_roc(wl)) {
2879 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 3020 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
2880 /* don't allow scanning right now */ 3021 /* don't allow scanning right now */
2881 ret = -EBUSY; 3022 ret = -EBUSY;
2882 goto out_sleep; 3023 goto out_sleep;
2883 } 3024 }
2884 wl12xx_croc(wl, wl->dev_role_id); 3025 wl12xx_stop_dev(wl, wlvif);
2885 wl12xx_cmd_role_stop_dev(wl);
2886 } 3026 }
2887 3027
2888 ret = wl1271_scan(hw->priv, ssid, len, req); 3028 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
2889out_sleep: 3029out_sleep:
2890 wl1271_ps_elp_sleep(wl); 3030 wl1271_ps_elp_sleep(wl);
2891out: 3031out:
@@ -2921,6 +3061,7 @@ static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
2921 } 3061 }
2922 wl->scan.state = WL1271_SCAN_STATE_IDLE; 3062 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2923 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 3063 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
3064 wl->scan_vif = NULL;
2924 wl->scan.req = NULL; 3065 wl->scan.req = NULL;
2925 ieee80211_scan_completed(wl->hw, true); 3066 ieee80211_scan_completed(wl->hw, true);
2926 3067
@@ -2938,6 +3079,7 @@ static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2938 struct ieee80211_sched_scan_ies *ies) 3079 struct ieee80211_sched_scan_ies *ies)
2939{ 3080{
2940 struct wl1271 *wl = hw->priv; 3081 struct wl1271 *wl = hw->priv;
3082 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2941 int ret; 3083 int ret;
2942 3084
2943 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start"); 3085 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
@@ -2948,11 +3090,11 @@ static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2948 if (ret < 0) 3090 if (ret < 0)
2949 goto out; 3091 goto out;
2950 3092
2951 ret = wl1271_scan_sched_scan_config(wl, req, ies); 3093 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
2952 if (ret < 0) 3094 if (ret < 0)
2953 goto out_sleep; 3095 goto out_sleep;
2954 3096
2955 ret = wl1271_scan_sched_scan_start(wl); 3097 ret = wl1271_scan_sched_scan_start(wl, wlvif);
2956 if (ret < 0) 3098 if (ret < 0)
2957 goto out_sleep; 3099 goto out_sleep;
2958 3100
@@ -3017,6 +3159,7 @@ out:
3017static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3159static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3018{ 3160{
3019 struct wl1271 *wl = hw->priv; 3161 struct wl1271 *wl = hw->priv;
3162 struct wl12xx_vif *wlvif;
3020 int ret = 0; 3163 int ret = 0;
3021 3164
3022 mutex_lock(&wl->mutex); 3165 mutex_lock(&wl->mutex);
@@ -3030,10 +3173,11 @@ static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3030 if (ret < 0) 3173 if (ret < 0)
3031 goto out; 3174 goto out;
3032 3175
3033 ret = wl1271_acx_rts_threshold(wl, value); 3176 wl12xx_for_each_wlvif(wl, wlvif) {
3034 if (ret < 0) 3177 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3035 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret); 3178 if (ret < 0)
3036 3179 wl1271_warning("set rts threshold failed: %d", ret);
3180 }
3037 wl1271_ps_elp_sleep(wl); 3181 wl1271_ps_elp_sleep(wl);
3038 3182
3039out: 3183out:
@@ -3042,9 +3186,10 @@ out:
3042 return ret; 3186 return ret;
3043} 3187}
3044 3188
3045static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb, 3189static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
3046 int offset) 3190 int offset)
3047{ 3191{
3192 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3048 u8 ssid_len; 3193 u8 ssid_len;
3049 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset, 3194 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3050 skb->len - offset); 3195 skb->len - offset);
@@ -3060,8 +3205,8 @@ static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
3060 return -EINVAL; 3205 return -EINVAL;
3061 } 3206 }
3062 3207
3063 wl->ssid_len = ssid_len; 3208 wlvif->ssid_len = ssid_len;
3064 memcpy(wl->ssid, ptr+2, ssid_len); 3209 memcpy(wlvif->ssid, ptr+2, ssid_len);
3065 return 0; 3210 return 0;
3066} 3211}
3067 3212
@@ -3096,18 +3241,40 @@ static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3096 skb_trim(skb, skb->len - len); 3241 skb_trim(skb, skb->len - len);
3097} 3242}
3098 3243
3099static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, 3244static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3100 u8 *probe_rsp_data, 3245 struct ieee80211_vif *vif)
3101 size_t probe_rsp_len, 3246{
3102 u32 rates) 3247 struct sk_buff *skb;
3248 int ret;
3249
3250 skb = ieee80211_proberesp_get(wl->hw, vif);
3251 if (!skb)
3252 return -EOPNOTSUPP;
3253
3254 ret = wl1271_cmd_template_set(wl,
3255 CMD_TEMPL_AP_PROBE_RESPONSE,
3256 skb->data,
3257 skb->len, 0,
3258 rates);
3259
3260 dev_kfree_skb(skb);
3261 return ret;
3262}
3263
3264static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3265 struct ieee80211_vif *vif,
3266 u8 *probe_rsp_data,
3267 size_t probe_rsp_len,
3268 u32 rates)
3103{ 3269{
3104 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf; 3270 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3271 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3105 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE]; 3272 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3106 int ssid_ie_offset, ie_offset, templ_len; 3273 int ssid_ie_offset, ie_offset, templ_len;
3107 const u8 *ptr; 3274 const u8 *ptr;
3108 3275
3109 /* no need to change probe response if the SSID is set correctly */ 3276 /* no need to change probe response if the SSID is set correctly */
3110 if (wl->ssid_len > 0) 3277 if (wlvif->ssid_len > 0)
3111 return wl1271_cmd_template_set(wl, 3278 return wl1271_cmd_template_set(wl,
3112 CMD_TEMPL_AP_PROBE_RESPONSE, 3279 CMD_TEMPL_AP_PROBE_RESPONSE,
3113 probe_rsp_data, 3280 probe_rsp_data,
@@ -3153,16 +3320,18 @@ static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl,
3153} 3320}
3154 3321
3155static int wl1271_bss_erp_info_changed(struct wl1271 *wl, 3322static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3323 struct ieee80211_vif *vif,
3156 struct ieee80211_bss_conf *bss_conf, 3324 struct ieee80211_bss_conf *bss_conf,
3157 u32 changed) 3325 u32 changed)
3158{ 3326{
3327 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3159 int ret = 0; 3328 int ret = 0;
3160 3329
3161 if (changed & BSS_CHANGED_ERP_SLOT) { 3330 if (changed & BSS_CHANGED_ERP_SLOT) {
3162 if (bss_conf->use_short_slot) 3331 if (bss_conf->use_short_slot)
3163 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT); 3332 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
3164 else 3333 else
3165 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG); 3334 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
3166 if (ret < 0) { 3335 if (ret < 0) {
3167 wl1271_warning("Set slot time failed %d", ret); 3336 wl1271_warning("Set slot time failed %d", ret);
3168 goto out; 3337 goto out;
@@ -3171,16 +3340,18 @@ static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3171 3340
3172 if (changed & BSS_CHANGED_ERP_PREAMBLE) { 3341 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3173 if (bss_conf->use_short_preamble) 3342 if (bss_conf->use_short_preamble)
3174 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT); 3343 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
3175 else 3344 else
3176 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG); 3345 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
3177 } 3346 }
3178 3347
3179 if (changed & BSS_CHANGED_ERP_CTS_PROT) { 3348 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3180 if (bss_conf->use_cts_prot) 3349 if (bss_conf->use_cts_prot)
3181 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE); 3350 ret = wl1271_acx_cts_protect(wl, wlvif,
3351 CTSPROTECT_ENABLE);
3182 else 3352 else
3183 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE); 3353 ret = wl1271_acx_cts_protect(wl, wlvif,
3354 CTSPROTECT_DISABLE);
3184 if (ret < 0) { 3355 if (ret < 0) {
3185 wl1271_warning("Set ctsprotect failed %d", ret); 3356 wl1271_warning("Set ctsprotect failed %d", ret);
3186 goto out; 3357 goto out;
@@ -3196,14 +3367,23 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3196 struct ieee80211_bss_conf *bss_conf, 3367 struct ieee80211_bss_conf *bss_conf,
3197 u32 changed) 3368 u32 changed)
3198{ 3369{
3199 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 3370 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3371 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3200 int ret = 0; 3372 int ret = 0;
3201 3373
3202 if ((changed & BSS_CHANGED_BEACON_INT)) { 3374 if ((changed & BSS_CHANGED_BEACON_INT)) {
3203 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d", 3375 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3204 bss_conf->beacon_int); 3376 bss_conf->beacon_int);
3205 3377
3206 wl->beacon_int = bss_conf->beacon_int; 3378 wlvif->beacon_int = bss_conf->beacon_int;
3379 }
3380
3381 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3382 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3383 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3384 wl1271_debug(DEBUG_AP, "probe response updated");
3385 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3386 }
3207 } 3387 }
3208 3388
3209 if ((changed & BSS_CHANGED_BEACON)) { 3389 if ((changed & BSS_CHANGED_BEACON)) {
@@ -3214,17 +3394,19 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3214 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif); 3394 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3215 u16 tmpl_id; 3395 u16 tmpl_id;
3216 3396
3217 if (!beacon) 3397 if (!beacon) {
3398 ret = -EINVAL;
3218 goto out; 3399 goto out;
3400 }
3219 3401
3220 wl1271_debug(DEBUG_MASTER, "beacon updated"); 3402 wl1271_debug(DEBUG_MASTER, "beacon updated");
3221 3403
3222 ret = wl1271_ssid_set(wl, beacon, ieoffset); 3404 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3223 if (ret < 0) { 3405 if (ret < 0) {
3224 dev_kfree_skb(beacon); 3406 dev_kfree_skb(beacon);
3225 goto out; 3407 goto out;
3226 } 3408 }
3227 min_rate = wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3409 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3228 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON : 3410 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3229 CMD_TEMPL_BEACON; 3411 CMD_TEMPL_BEACON;
3230 ret = wl1271_cmd_template_set(wl, tmpl_id, 3412 ret = wl1271_cmd_template_set(wl, tmpl_id,
@@ -3236,6 +3418,13 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3236 goto out; 3418 goto out;
3237 } 3419 }
3238 3420
3421 /*
3422 * In case we already have a probe-resp beacon set explicitly
3423 * by usermode, don't use the beacon data.
3424 */
3425 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3426 goto end_bcn;
3427
3239 /* remove TIM ie from probe response */ 3428 /* remove TIM ie from probe response */
3240 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset); 3429 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3241 3430
@@ -3254,7 +3443,7 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3254 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 3443 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3255 IEEE80211_STYPE_PROBE_RESP); 3444 IEEE80211_STYPE_PROBE_RESP);
3256 if (is_ap) 3445 if (is_ap)
3257 ret = wl1271_ap_set_probe_resp_tmpl(wl, 3446 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3258 beacon->data, 3447 beacon->data,
3259 beacon->len, 3448 beacon->len,
3260 min_rate); 3449 min_rate);
@@ -3264,12 +3453,15 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3264 beacon->data, 3453 beacon->data,
3265 beacon->len, 0, 3454 beacon->len, 0,
3266 min_rate); 3455 min_rate);
3456end_bcn:
3267 dev_kfree_skb(beacon); 3457 dev_kfree_skb(beacon);
3268 if (ret < 0) 3458 if (ret < 0)
3269 goto out; 3459 goto out;
3270 } 3460 }
3271 3461
3272out: 3462out:
3463 if (ret != 0)
3464 wl1271_error("beacon info change failed: %d", ret);
3273 return ret; 3465 return ret;
3274} 3466}
3275 3467
@@ -3279,23 +3471,24 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3279 struct ieee80211_bss_conf *bss_conf, 3471 struct ieee80211_bss_conf *bss_conf,
3280 u32 changed) 3472 u32 changed)
3281{ 3473{
3474 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3282 int ret = 0; 3475 int ret = 0;
3283 3476
3284 if ((changed & BSS_CHANGED_BASIC_RATES)) { 3477 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3285 u32 rates = bss_conf->basic_rates; 3478 u32 rates = bss_conf->basic_rates;
3286 3479
3287 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates, 3480 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
3288 wl->band); 3481 wlvif->band);
3289 wl->basic_rate = wl1271_tx_min_rate_get(wl, 3482 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
3290 wl->basic_rate_set); 3483 wlvif->basic_rate_set);
3291 3484
3292 ret = wl1271_init_ap_rates(wl); 3485 ret = wl1271_init_ap_rates(wl, wlvif);
3293 if (ret < 0) { 3486 if (ret < 0) {
3294 wl1271_error("AP rate policy change failed %d", ret); 3487 wl1271_error("AP rate policy change failed %d", ret);
3295 goto out; 3488 goto out;
3296 } 3489 }
3297 3490
3298 ret = wl1271_ap_init_templates(wl); 3491 ret = wl1271_ap_init_templates(wl, vif);
3299 if (ret < 0) 3492 if (ret < 0)
3300 goto out; 3493 goto out;
3301 } 3494 }
@@ -3306,38 +3499,40 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3306 3499
3307 if ((changed & BSS_CHANGED_BEACON_ENABLED)) { 3500 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3308 if (bss_conf->enable_beacon) { 3501 if (bss_conf->enable_beacon) {
3309 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 3502 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3310 ret = wl12xx_cmd_role_start_ap(wl); 3503 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
3311 if (ret < 0) 3504 if (ret < 0)
3312 goto out; 3505 goto out;
3313 3506
3314 ret = wl1271_ap_init_hwenc(wl); 3507 ret = wl1271_ap_init_hwenc(wl, wlvif);
3315 if (ret < 0) 3508 if (ret < 0)
3316 goto out; 3509 goto out;
3317 3510
3318 set_bit(WL1271_FLAG_AP_STARTED, &wl->flags); 3511 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3319 wl1271_debug(DEBUG_AP, "started AP"); 3512 wl1271_debug(DEBUG_AP, "started AP");
3320 } 3513 }
3321 } else { 3514 } else {
3322 if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) { 3515 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3323 ret = wl12xx_cmd_role_stop_ap(wl); 3516 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
3324 if (ret < 0) 3517 if (ret < 0)
3325 goto out; 3518 goto out;
3326 3519
3327 clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags); 3520 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3521 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3522 &wlvif->flags);
3328 wl1271_debug(DEBUG_AP, "stopped AP"); 3523 wl1271_debug(DEBUG_AP, "stopped AP");
3329 } 3524 }
3330 } 3525 }
3331 } 3526 }
3332 3527
3333 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); 3528 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3334 if (ret < 0) 3529 if (ret < 0)
3335 goto out; 3530 goto out;
3336 3531
3337 /* Handle HT information change */ 3532 /* Handle HT information change */
3338 if ((changed & BSS_CHANGED_HT) && 3533 if ((changed & BSS_CHANGED_HT) &&
3339 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { 3534 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3340 ret = wl1271_acx_set_ht_information(wl, 3535 ret = wl1271_acx_set_ht_information(wl, wlvif,
3341 bss_conf->ht_operation_mode); 3536 bss_conf->ht_operation_mode);
3342 if (ret < 0) { 3537 if (ret < 0) {
3343 wl1271_warning("Set ht information failed %d", ret); 3538 wl1271_warning("Set ht information failed %d", ret);
@@ -3355,8 +3550,9 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3355 struct ieee80211_bss_conf *bss_conf, 3550 struct ieee80211_bss_conf *bss_conf,
3356 u32 changed) 3551 u32 changed)
3357{ 3552{
3553 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3358 bool do_join = false, set_assoc = false; 3554 bool do_join = false, set_assoc = false;
3359 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 3555 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
3360 bool ibss_joined = false; 3556 bool ibss_joined = false;
3361 u32 sta_rate_set = 0; 3557 u32 sta_rate_set = 0;
3362 int ret; 3558 int ret;
@@ -3373,14 +3569,13 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3373 3569
3374 if (changed & BSS_CHANGED_IBSS) { 3570 if (changed & BSS_CHANGED_IBSS) {
3375 if (bss_conf->ibss_joined) { 3571 if (bss_conf->ibss_joined) {
3376 set_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags); 3572 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
3377 ibss_joined = true; 3573 ibss_joined = true;
3378 } else { 3574 } else {
3379 if (test_and_clear_bit(WL1271_FLAG_IBSS_JOINED, 3575 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3380 &wl->flags)) { 3576 &wlvif->flags)) {
3381 wl1271_unjoin(wl); 3577 wl1271_unjoin(wl, wlvif);
3382 wl12xx_cmd_role_start_dev(wl); 3578 wl12xx_start_dev(wl, wlvif);
3383 wl12xx_roc(wl, wl->dev_role_id);
3384 } 3579 }
3385 } 3580 }
3386 } 3581 }
@@ -3396,46 +3591,40 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3396 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s", 3591 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3397 bss_conf->enable_beacon ? "enabled" : "disabled"); 3592 bss_conf->enable_beacon ? "enabled" : "disabled");
3398 3593
3399 if (bss_conf->enable_beacon)
3400 wl->set_bss_type = BSS_TYPE_IBSS;
3401 else
3402 wl->set_bss_type = BSS_TYPE_STA_BSS;
3403 do_join = true; 3594 do_join = true;
3404 } 3595 }
3405 3596
3597 if (changed & BSS_CHANGED_IDLE) {
3598 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3599 if (ret < 0)
3600 wl1271_warning("idle mode change failed %d", ret);
3601 }
3602
3406 if ((changed & BSS_CHANGED_CQM)) { 3603 if ((changed & BSS_CHANGED_CQM)) {
3407 bool enable = false; 3604 bool enable = false;
3408 if (bss_conf->cqm_rssi_thold) 3605 if (bss_conf->cqm_rssi_thold)
3409 enable = true; 3606 enable = true;
3410 ret = wl1271_acx_rssi_snr_trigger(wl, enable, 3607 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
3411 bss_conf->cqm_rssi_thold, 3608 bss_conf->cqm_rssi_thold,
3412 bss_conf->cqm_rssi_hyst); 3609 bss_conf->cqm_rssi_hyst);
3413 if (ret < 0) 3610 if (ret < 0)
3414 goto out; 3611 goto out;
3415 wl->rssi_thold = bss_conf->cqm_rssi_thold; 3612 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
3416 } 3613 }
3417 3614
3418 if ((changed & BSS_CHANGED_BSSID) && 3615 if (changed & BSS_CHANGED_BSSID)
3419 /* 3616 if (!is_zero_ether_addr(bss_conf->bssid)) {
3420 * Now we know the correct bssid, so we send a new join command 3617 ret = wl12xx_cmd_build_null_data(wl, wlvif);
3421 * and enable the BSSID filter
3422 */
3423 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
3424 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
3425
3426 if (!is_zero_ether_addr(wl->bssid)) {
3427 ret = wl1271_cmd_build_null_data(wl);
3428 if (ret < 0) 3618 if (ret < 0)
3429 goto out; 3619 goto out;
3430 3620
3431 ret = wl1271_build_qos_null_data(wl); 3621 ret = wl1271_build_qos_null_data(wl, vif);
3432 if (ret < 0) 3622 if (ret < 0)
3433 goto out; 3623 goto out;
3434 3624
3435 /* Need to update the BSSID (for filtering etc) */ 3625 /* Need to update the BSSID (for filtering etc) */
3436 do_join = true; 3626 do_join = true;
3437 } 3627 }
3438 }
3439 3628
3440 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) { 3629 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3441 rcu_read_lock(); 3630 rcu_read_lock();
@@ -3459,26 +3648,28 @@ sta_not_found:
3459 if (bss_conf->assoc) { 3648 if (bss_conf->assoc) {
3460 u32 rates; 3649 u32 rates;
3461 int ieoffset; 3650 int ieoffset;
3462 wl->aid = bss_conf->aid; 3651 wlvif->aid = bss_conf->aid;
3463 set_assoc = true; 3652 set_assoc = true;
3464 3653
3465 wl->ps_poll_failures = 0; 3654 wlvif->ps_poll_failures = 0;
3466 3655
3467 /* 3656 /*
3468 * use basic rates from AP, and determine lowest rate 3657 * use basic rates from AP, and determine lowest rate
3469 * to use with control frames. 3658 * to use with control frames.
3470 */ 3659 */
3471 rates = bss_conf->basic_rates; 3660 rates = bss_conf->basic_rates;
3472 wl->basic_rate_set = 3661 wlvif->basic_rate_set =
3473 wl1271_tx_enabled_rates_get(wl, rates, 3662 wl1271_tx_enabled_rates_get(wl, rates,
3474 wl->band); 3663 wlvif->band);
3475 wl->basic_rate = 3664 wlvif->basic_rate =
3476 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3665 wl1271_tx_min_rate_get(wl,
3666 wlvif->basic_rate_set);
3477 if (sta_rate_set) 3667 if (sta_rate_set)
3478 wl->rate_set = wl1271_tx_enabled_rates_get(wl, 3668 wlvif->rate_set =
3669 wl1271_tx_enabled_rates_get(wl,
3479 sta_rate_set, 3670 sta_rate_set,
3480 wl->band); 3671 wlvif->band);
3481 ret = wl1271_acx_sta_rate_policies(wl); 3672 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3482 if (ret < 0) 3673 if (ret < 0)
3483 goto out; 3674 goto out;
3484 3675
@@ -3488,53 +3679,56 @@ sta_not_found:
3488 * updates it by itself when the first beacon is 3679 * updates it by itself when the first beacon is
3489 * received after a join. 3680 * received after a join.
3490 */ 3681 */
3491 ret = wl1271_cmd_build_ps_poll(wl, wl->aid); 3682 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
3492 if (ret < 0) 3683 if (ret < 0)
3493 goto out; 3684 goto out;
3494 3685
3495 /* 3686 /*
3496 * Get a template for hardware connection maintenance 3687 * Get a template for hardware connection maintenance
3497 */ 3688 */
3498 dev_kfree_skb(wl->probereq); 3689 dev_kfree_skb(wlvif->probereq);
3499 wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL); 3690 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
3691 wlvif,
3692 NULL);
3500 ieoffset = offsetof(struct ieee80211_mgmt, 3693 ieoffset = offsetof(struct ieee80211_mgmt,
3501 u.probe_req.variable); 3694 u.probe_req.variable);
3502 wl1271_ssid_set(wl, wl->probereq, ieoffset); 3695 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
3503 3696
3504 /* enable the connection monitoring feature */ 3697 /* enable the connection monitoring feature */
3505 ret = wl1271_acx_conn_monit_params(wl, true); 3698 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
3506 if (ret < 0) 3699 if (ret < 0)
3507 goto out; 3700 goto out;
3508 } else { 3701 } else {
3509 /* use defaults when not associated */ 3702 /* use defaults when not associated */
3510 bool was_assoc = 3703 bool was_assoc =
3511 !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED, 3704 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3512 &wl->flags); 3705 &wlvif->flags);
3513 bool was_ifup = 3706 bool was_ifup =
3514 !!test_and_clear_bit(WL1271_FLAG_STA_STATE_SENT, 3707 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3515 &wl->flags); 3708 &wlvif->flags);
3516 wl->aid = 0; 3709 wlvif->aid = 0;
3517 3710
3518 /* free probe-request template */ 3711 /* free probe-request template */
3519 dev_kfree_skb(wl->probereq); 3712 dev_kfree_skb(wlvif->probereq);
3520 wl->probereq = NULL; 3713 wlvif->probereq = NULL;
3521 3714
3522 /* re-enable dynamic ps - just in case */ 3715 /* re-enable dynamic ps - just in case */
3523 ieee80211_enable_dyn_ps(wl->vif); 3716 ieee80211_enable_dyn_ps(vif);
3524 3717
3525 /* revert back to minimum rates for the current band */ 3718 /* revert back to minimum rates for the current band */
3526 wl1271_set_band_rate(wl); 3719 wl1271_set_band_rate(wl, wlvif);
3527 wl->basic_rate = 3720 wlvif->basic_rate =
3528 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3721 wl1271_tx_min_rate_get(wl,
3529 ret = wl1271_acx_sta_rate_policies(wl); 3722 wlvif->basic_rate_set);
3723 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3530 if (ret < 0) 3724 if (ret < 0)
3531 goto out; 3725 goto out;
3532 3726
3533 /* disable connection monitor features */ 3727 /* disable connection monitor features */
3534 ret = wl1271_acx_conn_monit_params(wl, false); 3728 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
3535 3729
3536 /* Disable the keep-alive feature */ 3730 /* Disable the keep-alive feature */
3537 ret = wl1271_acx_keep_alive_mode(wl, false); 3731 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
3538 if (ret < 0) 3732 if (ret < 0)
3539 goto out; 3733 goto out;
3540 3734
@@ -3546,7 +3740,7 @@ sta_not_found:
3546 * no IF_OPER_UP notification. 3740 * no IF_OPER_UP notification.
3547 */ 3741 */
3548 if (!was_ifup) { 3742 if (!was_ifup) {
3549 ret = wl12xx_croc(wl, wl->role_id); 3743 ret = wl12xx_croc(wl, wlvif->role_id);
3550 if (ret < 0) 3744 if (ret < 0)
3551 goto out; 3745 goto out;
3552 } 3746 }
@@ -3555,17 +3749,16 @@ sta_not_found:
3555 * roaming on the same channel. until we will 3749 * roaming on the same channel. until we will
3556 * have a better flow...) 3750 * have a better flow...)
3557 */ 3751 */
3558 if (test_bit(wl->dev_role_id, wl->roc_map)) { 3752 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3559 ret = wl12xx_croc(wl, wl->dev_role_id); 3753 ret = wl12xx_croc(wl,
3754 wlvif->dev_role_id);
3560 if (ret < 0) 3755 if (ret < 0)
3561 goto out; 3756 goto out;
3562 } 3757 }
3563 3758
3564 wl1271_unjoin(wl); 3759 wl1271_unjoin(wl, wlvif);
3565 if (!(conf_flags & IEEE80211_CONF_IDLE)) { 3760 if (!(conf_flags & IEEE80211_CONF_IDLE))
3566 wl12xx_cmd_role_start_dev(wl); 3761 wl12xx_start_dev(wl, wlvif);
3567 wl12xx_roc(wl, wl->dev_role_id);
3568 }
3569 } 3762 }
3570 } 3763 }
3571 } 3764 }
@@ -3576,27 +3769,28 @@ sta_not_found:
3576 3769
3577 if (bss_conf->ibss_joined) { 3770 if (bss_conf->ibss_joined) {
3578 u32 rates = bss_conf->basic_rates; 3771 u32 rates = bss_conf->basic_rates;
3579 wl->basic_rate_set = 3772 wlvif->basic_rate_set =
3580 wl1271_tx_enabled_rates_get(wl, rates, 3773 wl1271_tx_enabled_rates_get(wl, rates,
3581 wl->band); 3774 wlvif->band);
3582 wl->basic_rate = 3775 wlvif->basic_rate =
3583 wl1271_tx_min_rate_get(wl, wl->basic_rate_set); 3776 wl1271_tx_min_rate_get(wl,
3777 wlvif->basic_rate_set);
3584 3778
3585 /* by default, use 11b + OFDM rates */ 3779 /* by default, use 11b + OFDM rates */
3586 wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES; 3780 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3587 ret = wl1271_acx_sta_rate_policies(wl); 3781 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3588 if (ret < 0) 3782 if (ret < 0)
3589 goto out; 3783 goto out;
3590 } 3784 }
3591 } 3785 }
3592 3786
3593 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed); 3787 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3594 if (ret < 0) 3788 if (ret < 0)
3595 goto out; 3789 goto out;
3596 3790
3597 if (changed & BSS_CHANGED_ARP_FILTER) { 3791 if (changed & BSS_CHANGED_ARP_FILTER) {
3598 __be32 addr = bss_conf->arp_addr_list[0]; 3792 __be32 addr = bss_conf->arp_addr_list[0];
3599 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS); 3793 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
3600 3794
3601 if (bss_conf->arp_addr_cnt == 1 && 3795 if (bss_conf->arp_addr_cnt == 1 &&
3602 bss_conf->arp_filter_enabled) { 3796 bss_conf->arp_filter_enabled) {
@@ -3606,24 +3800,24 @@ sta_not_found:
3606 * isn't being set (when sending), so we have to 3800 * isn't being set (when sending), so we have to
3607 * reconfigure the template upon every ip change. 3801 * reconfigure the template upon every ip change.
3608 */ 3802 */
3609 ret = wl1271_cmd_build_arp_rsp(wl, addr); 3803 ret = wl1271_cmd_build_arp_rsp(wl, wlvif, addr);
3610 if (ret < 0) { 3804 if (ret < 0) {
3611 wl1271_warning("build arp rsp failed: %d", ret); 3805 wl1271_warning("build arp rsp failed: %d", ret);
3612 goto out; 3806 goto out;
3613 } 3807 }
3614 3808
3615 ret = wl1271_acx_arp_ip_filter(wl, 3809 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
3616 ACX_ARP_FILTER_ARP_FILTERING, 3810 ACX_ARP_FILTER_ARP_FILTERING,
3617 addr); 3811 addr);
3618 } else 3812 } else
3619 ret = wl1271_acx_arp_ip_filter(wl, 0, addr); 3813 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
3620 3814
3621 if (ret < 0) 3815 if (ret < 0)
3622 goto out; 3816 goto out;
3623 } 3817 }
3624 3818
3625 if (do_join) { 3819 if (do_join) {
3626 ret = wl1271_join(wl, set_assoc); 3820 ret = wl1271_join(wl, wlvif, set_assoc);
3627 if (ret < 0) { 3821 if (ret < 0) {
3628 wl1271_warning("cmd join failed %d", ret); 3822 wl1271_warning("cmd join failed %d", ret);
3629 goto out; 3823 goto out;
@@ -3631,35 +3825,31 @@ sta_not_found:
3631 3825
3632 /* ROC until connected (after EAPOL exchange) */ 3826 /* ROC until connected (after EAPOL exchange) */
3633 if (!is_ibss) { 3827 if (!is_ibss) {
3634 ret = wl12xx_roc(wl, wl->role_id); 3828 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
3635 if (ret < 0) 3829 if (ret < 0)
3636 goto out; 3830 goto out;
3637 3831
3638 wl1271_check_operstate(wl, 3832 wl1271_check_operstate(wl, wlvif,
3639 ieee80211_get_operstate(vif)); 3833 ieee80211_get_operstate(vif));
3640 } 3834 }
3641 /* 3835 /*
3642 * stop device role if started (we might already be in 3836 * stop device role if started (we might already be in
3643 * STA role). TODO: make it better. 3837 * STA role). TODO: make it better.
3644 */ 3838 */
3645 if (wl->dev_role_id != WL12XX_INVALID_ROLE_ID) { 3839 if (wlvif->dev_role_id != WL12XX_INVALID_ROLE_ID) {
3646 ret = wl12xx_croc(wl, wl->dev_role_id); 3840 ret = wl12xx_stop_dev(wl, wlvif);
3647 if (ret < 0)
3648 goto out;
3649
3650 ret = wl12xx_cmd_role_stop_dev(wl);
3651 if (ret < 0) 3841 if (ret < 0)
3652 goto out; 3842 goto out;
3653 } 3843 }
3654 3844
3655 /* If we want to go in PSM but we're not there yet */ 3845 /* If we want to go in PSM but we're not there yet */
3656 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) && 3846 if (test_bit(WLVIF_FLAG_PSM_REQUESTED, &wlvif->flags) &&
3657 !test_bit(WL1271_FLAG_PSM, &wl->flags)) { 3847 !test_bit(WLVIF_FLAG_PSM, &wlvif->flags)) {
3658 enum wl1271_cmd_ps_mode mode; 3848 enum wl1271_cmd_ps_mode mode;
3659 3849
3660 mode = STATION_POWER_SAVE_MODE; 3850 mode = STATION_POWER_SAVE_MODE;
3661 ret = wl1271_ps_set_mode(wl, mode, 3851 ret = wl1271_ps_set_mode(wl, wlvif, mode,
3662 wl->basic_rate, 3852 wlvif->basic_rate,
3663 true); 3853 true);
3664 if (ret < 0) 3854 if (ret < 0)
3665 goto out; 3855 goto out;
@@ -3673,7 +3863,7 @@ sta_not_found:
3673 ret = wl1271_acx_set_ht_capabilities(wl, 3863 ret = wl1271_acx_set_ht_capabilities(wl,
3674 &sta_ht_cap, 3864 &sta_ht_cap,
3675 true, 3865 true,
3676 wl->sta_hlid); 3866 wlvif->sta.hlid);
3677 if (ret < 0) { 3867 if (ret < 0) {
3678 wl1271_warning("Set ht cap true failed %d", 3868 wl1271_warning("Set ht cap true failed %d",
3679 ret); 3869 ret);
@@ -3685,7 +3875,7 @@ sta_not_found:
3685 ret = wl1271_acx_set_ht_capabilities(wl, 3875 ret = wl1271_acx_set_ht_capabilities(wl,
3686 &sta_ht_cap, 3876 &sta_ht_cap,
3687 false, 3877 false,
3688 wl->sta_hlid); 3878 wlvif->sta.hlid);
3689 if (ret < 0) { 3879 if (ret < 0) {
3690 wl1271_warning("Set ht cap false failed %d", 3880 wl1271_warning("Set ht cap false failed %d",
3691 ret); 3881 ret);
@@ -3697,7 +3887,7 @@ sta_not_found:
3697 /* Handle HT information change. Done after join. */ 3887 /* Handle HT information change. Done after join. */
3698 if ((changed & BSS_CHANGED_HT) && 3888 if ((changed & BSS_CHANGED_HT) &&
3699 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) { 3889 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3700 ret = wl1271_acx_set_ht_information(wl, 3890 ret = wl1271_acx_set_ht_information(wl, wlvif,
3701 bss_conf->ht_operation_mode); 3891 bss_conf->ht_operation_mode);
3702 if (ret < 0) { 3892 if (ret < 0) {
3703 wl1271_warning("Set ht information failed %d", ret); 3893 wl1271_warning("Set ht information failed %d", ret);
@@ -3715,7 +3905,8 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3715 u32 changed) 3905 u32 changed)
3716{ 3906{
3717 struct wl1271 *wl = hw->priv; 3907 struct wl1271 *wl = hw->priv;
3718 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 3908 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3909 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3719 int ret; 3910 int ret;
3720 3911
3721 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", 3912 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
@@ -3726,6 +3917,9 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3726 if (unlikely(wl->state == WL1271_STATE_OFF)) 3917 if (unlikely(wl->state == WL1271_STATE_OFF))
3727 goto out; 3918 goto out;
3728 3919
3920 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
3921 goto out;
3922
3729 ret = wl1271_ps_elp_wakeup(wl); 3923 ret = wl1271_ps_elp_wakeup(wl);
3730 if (ret < 0) 3924 if (ret < 0)
3731 goto out; 3925 goto out;
@@ -3746,6 +3940,7 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3746 const struct ieee80211_tx_queue_params *params) 3940 const struct ieee80211_tx_queue_params *params)
3747{ 3941{
3748 struct wl1271 *wl = hw->priv; 3942 struct wl1271 *wl = hw->priv;
3943 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3749 u8 ps_scheme; 3944 u8 ps_scheme;
3750 int ret = 0; 3945 int ret = 0;
3751 3946
@@ -3792,13 +3987,13 @@ static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
3792 * the txop is confed in units of 32us by the mac80211, 3987 * the txop is confed in units of 32us by the mac80211,
3793 * we need us 3988 * we need us
3794 */ 3989 */
3795 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue), 3990 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3796 params->cw_min, params->cw_max, 3991 params->cw_min, params->cw_max,
3797 params->aifs, params->txop << 5); 3992 params->aifs, params->txop << 5);
3798 if (ret < 0) 3993 if (ret < 0)
3799 goto out_sleep; 3994 goto out_sleep;
3800 3995
3801 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue), 3996 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
3802 CONF_CHANNEL_TYPE_EDCF, 3997 CONF_CHANNEL_TYPE_EDCF,
3803 wl1271_tx_get_queue(queue), 3998 wl1271_tx_get_queue(queue),
3804 ps_scheme, CONF_ACK_POLICY_LEGACY, 3999 ps_scheme, CONF_ACK_POLICY_LEGACY,
@@ -3861,43 +4056,43 @@ static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3861} 4056}
3862 4057
3863static int wl1271_allocate_sta(struct wl1271 *wl, 4058static int wl1271_allocate_sta(struct wl1271 *wl,
3864 struct ieee80211_sta *sta, 4059 struct wl12xx_vif *wlvif,
3865 u8 *hlid) 4060 struct ieee80211_sta *sta)
3866{ 4061{
3867 struct wl1271_station *wl_sta; 4062 struct wl1271_station *wl_sta;
3868 int id; 4063 int ret;
3869 4064
3870 id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS); 4065
3871 if (id >= AP_MAX_STATIONS) { 4066 if (wl->active_sta_count >= AP_MAX_STATIONS) {
3872 wl1271_warning("could not allocate HLID - too much stations"); 4067 wl1271_warning("could not allocate HLID - too much stations");
3873 return -EBUSY; 4068 return -EBUSY;
3874 } 4069 }
3875 4070
3876 wl_sta = (struct wl1271_station *)sta->drv_priv; 4071 wl_sta = (struct wl1271_station *)sta->drv_priv;
3877 set_bit(id, wl->ap_hlid_map); 4072 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
3878 wl_sta->hlid = WL1271_AP_STA_HLID_START + id; 4073 if (ret < 0) {
3879 *hlid = wl_sta->hlid; 4074 wl1271_warning("could not allocate HLID - too many links");
4075 return -EBUSY;
4076 }
4077
4078 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
3880 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN); 4079 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
3881 wl->active_sta_count++; 4080 wl->active_sta_count++;
3882 return 0; 4081 return 0;
3883} 4082}
3884 4083
3885void wl1271_free_sta(struct wl1271 *wl, u8 hlid) 4084void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
3886{ 4085{
3887 int id = hlid - WL1271_AP_STA_HLID_START; 4086 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
3888
3889 if (hlid < WL1271_AP_STA_HLID_START)
3890 return;
3891
3892 if (!test_bit(id, wl->ap_hlid_map))
3893 return; 4087 return;
3894 4088
3895 clear_bit(id, wl->ap_hlid_map); 4089 clear_bit(hlid, wlvif->ap.sta_hlid_map);
3896 memset(wl->links[hlid].addr, 0, ETH_ALEN); 4090 memset(wl->links[hlid].addr, 0, ETH_ALEN);
3897 wl->links[hlid].ba_bitmap = 0; 4091 wl->links[hlid].ba_bitmap = 0;
3898 wl1271_tx_reset_link_queues(wl, hlid); 4092 wl1271_tx_reset_link_queues(wl, hlid);
3899 __clear_bit(hlid, &wl->ap_ps_map); 4093 __clear_bit(hlid, &wl->ap_ps_map);
3900 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 4094 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
4095 wl12xx_free_link(wl, wlvif, &hlid);
3901 wl->active_sta_count--; 4096 wl->active_sta_count--;
3902} 4097}
3903 4098
@@ -3906,6 +4101,8 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3906 struct ieee80211_sta *sta) 4101 struct ieee80211_sta *sta)
3907{ 4102{
3908 struct wl1271 *wl = hw->priv; 4103 struct wl1271 *wl = hw->priv;
4104 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4105 struct wl1271_station *wl_sta;
3909 int ret = 0; 4106 int ret = 0;
3910 u8 hlid; 4107 u8 hlid;
3911 4108
@@ -3914,20 +4111,23 @@ static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3914 if (unlikely(wl->state == WL1271_STATE_OFF)) 4111 if (unlikely(wl->state == WL1271_STATE_OFF))
3915 goto out; 4112 goto out;
3916 4113
3917 if (wl->bss_type != BSS_TYPE_AP_BSS) 4114 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
3918 goto out; 4115 goto out;
3919 4116
3920 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid); 4117 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
3921 4118
3922 ret = wl1271_allocate_sta(wl, sta, &hlid); 4119 ret = wl1271_allocate_sta(wl, wlvif, sta);
3923 if (ret < 0) 4120 if (ret < 0)
3924 goto out; 4121 goto out;
3925 4122
4123 wl_sta = (struct wl1271_station *)sta->drv_priv;
4124 hlid = wl_sta->hlid;
4125
3926 ret = wl1271_ps_elp_wakeup(wl); 4126 ret = wl1271_ps_elp_wakeup(wl);
3927 if (ret < 0) 4127 if (ret < 0)
3928 goto out_free_sta; 4128 goto out_free_sta;
3929 4129
3930 ret = wl12xx_cmd_add_peer(wl, sta, hlid); 4130 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
3931 if (ret < 0) 4131 if (ret < 0)
3932 goto out_sleep; 4132 goto out_sleep;
3933 4133
@@ -3944,7 +4144,7 @@ out_sleep:
3944 4144
3945out_free_sta: 4145out_free_sta:
3946 if (ret < 0) 4146 if (ret < 0)
3947 wl1271_free_sta(wl, hlid); 4147 wl1271_free_sta(wl, wlvif, hlid);
3948 4148
3949out: 4149out:
3950 mutex_unlock(&wl->mutex); 4150 mutex_unlock(&wl->mutex);
@@ -3956,6 +4156,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3956 struct ieee80211_sta *sta) 4156 struct ieee80211_sta *sta)
3957{ 4157{
3958 struct wl1271 *wl = hw->priv; 4158 struct wl1271 *wl = hw->priv;
4159 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3959 struct wl1271_station *wl_sta; 4160 struct wl1271_station *wl_sta;
3960 int ret = 0, id; 4161 int ret = 0, id;
3961 4162
@@ -3964,14 +4165,14 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3964 if (unlikely(wl->state == WL1271_STATE_OFF)) 4165 if (unlikely(wl->state == WL1271_STATE_OFF))
3965 goto out; 4166 goto out;
3966 4167
3967 if (wl->bss_type != BSS_TYPE_AP_BSS) 4168 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
3968 goto out; 4169 goto out;
3969 4170
3970 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid); 4171 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
3971 4172
3972 wl_sta = (struct wl1271_station *)sta->drv_priv; 4173 wl_sta = (struct wl1271_station *)sta->drv_priv;
3973 id = wl_sta->hlid - WL1271_AP_STA_HLID_START; 4174 id = wl_sta->hlid;
3974 if (WARN_ON(!test_bit(id, wl->ap_hlid_map))) 4175 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
3975 goto out; 4176 goto out;
3976 4177
3977 ret = wl1271_ps_elp_wakeup(wl); 4178 ret = wl1271_ps_elp_wakeup(wl);
@@ -3982,7 +4183,7 @@ static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3982 if (ret < 0) 4183 if (ret < 0)
3983 goto out_sleep; 4184 goto out_sleep;
3984 4185
3985 wl1271_free_sta(wl, wl_sta->hlid); 4186 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
3986 4187
3987out_sleep: 4188out_sleep:
3988 wl1271_ps_elp_sleep(wl); 4189 wl1271_ps_elp_sleep(wl);
@@ -3999,6 +4200,7 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
3999 u8 buf_size) 4200 u8 buf_size)
4000{ 4201{
4001 struct wl1271 *wl = hw->priv; 4202 struct wl1271 *wl = hw->priv;
4203 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4002 int ret; 4204 int ret;
4003 u8 hlid, *ba_bitmap; 4205 u8 hlid, *ba_bitmap;
4004 4206
@@ -4016,10 +4218,10 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4016 goto out; 4218 goto out;
4017 } 4219 }
4018 4220
4019 if (wl->bss_type == BSS_TYPE_STA_BSS) { 4221 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
4020 hlid = wl->sta_hlid; 4222 hlid = wlvif->sta.hlid;
4021 ba_bitmap = &wl->ba_rx_bitmap; 4223 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
4022 } else if (wl->bss_type == BSS_TYPE_AP_BSS) { 4224 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
4023 struct wl1271_station *wl_sta; 4225 struct wl1271_station *wl_sta;
4024 4226
4025 wl_sta = (struct wl1271_station *)sta->drv_priv; 4227 wl_sta = (struct wl1271_station *)sta->drv_priv;
@@ -4039,7 +4241,7 @@ static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4039 4241
4040 switch (action) { 4242 switch (action) {
4041 case IEEE80211_AMPDU_RX_START: 4243 case IEEE80211_AMPDU_RX_START:
4042 if (!wl->ba_support || !wl->ba_allowed) { 4244 if (!wlvif->ba_support || !wlvif->ba_allowed) {
4043 ret = -ENOTSUPP; 4245 ret = -ENOTSUPP;
4044 break; 4246 break;
4045 } 4247 }
@@ -4108,8 +4310,9 @@ static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4108 struct ieee80211_vif *vif, 4310 struct ieee80211_vif *vif,
4109 const struct cfg80211_bitrate_mask *mask) 4311 const struct cfg80211_bitrate_mask *mask)
4110{ 4312{
4313 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4111 struct wl1271 *wl = hw->priv; 4314 struct wl1271 *wl = hw->priv;
4112 int i; 4315 int i, ret = 0;
4113 4316
4114 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x", 4317 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4115 mask->control[NL80211_BAND_2GHZ].legacy, 4318 mask->control[NL80211_BAND_2GHZ].legacy,
@@ -4118,19 +4321,39 @@ static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4118 mutex_lock(&wl->mutex); 4321 mutex_lock(&wl->mutex);
4119 4322
4120 for (i = 0; i < IEEE80211_NUM_BANDS; i++) 4323 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4121 wl->bitrate_masks[i] = 4324 wlvif->bitrate_masks[i] =
4122 wl1271_tx_enabled_rates_get(wl, 4325 wl1271_tx_enabled_rates_get(wl,
4123 mask->control[i].legacy, 4326 mask->control[i].legacy,
4124 i); 4327 i);
4328
4329 if (unlikely(wl->state == WL1271_STATE_OFF))
4330 goto out;
4331
4332 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4333 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4334
4335 ret = wl1271_ps_elp_wakeup(wl);
4336 if (ret < 0)
4337 goto out;
4338
4339 wl1271_set_band_rate(wl, wlvif);
4340 wlvif->basic_rate =
4341 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4342 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4343
4344 wl1271_ps_elp_sleep(wl);
4345 }
4346out:
4125 mutex_unlock(&wl->mutex); 4347 mutex_unlock(&wl->mutex);
4126 4348
4127 return 0; 4349 return ret;
4128} 4350}
4129 4351
4130static void wl12xx_op_channel_switch(struct ieee80211_hw *hw, 4352static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4131 struct ieee80211_channel_switch *ch_switch) 4353 struct ieee80211_channel_switch *ch_switch)
4132{ 4354{
4133 struct wl1271 *wl = hw->priv; 4355 struct wl1271 *wl = hw->priv;
4356 struct wl12xx_vif *wlvif;
4134 int ret; 4357 int ret;
4135 4358
4136 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch"); 4359 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
@@ -4138,19 +4361,24 @@ static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4138 mutex_lock(&wl->mutex); 4361 mutex_lock(&wl->mutex);
4139 4362
4140 if (unlikely(wl->state == WL1271_STATE_OFF)) { 4363 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4141 mutex_unlock(&wl->mutex); 4364 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4142 ieee80211_chswitch_done(wl->vif, false); 4365 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4143 return; 4366 ieee80211_chswitch_done(vif, false);
4367 }
4368 goto out;
4144 } 4369 }
4145 4370
4146 ret = wl1271_ps_elp_wakeup(wl); 4371 ret = wl1271_ps_elp_wakeup(wl);
4147 if (ret < 0) 4372 if (ret < 0)
4148 goto out; 4373 goto out;
4149 4374
4150 ret = wl12xx_cmd_channel_switch(wl, ch_switch); 4375 /* TODO: change mac80211 to pass vif as param */
4376 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4377 ret = wl12xx_cmd_channel_switch(wl, ch_switch);
4151 4378
4152 if (!ret) 4379 if (!ret)
4153 set_bit(WL1271_FLAG_CS_PROGRESS, &wl->flags); 4380 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4381 }
4154 4382
4155 wl1271_ps_elp_sleep(wl); 4383 wl1271_ps_elp_sleep(wl);
4156 4384
@@ -4170,10 +4398,6 @@ static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4170 4398
4171 /* packets are considered pending if in the TX queue or the FW */ 4399 /* packets are considered pending if in the TX queue or the FW */
4172 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0); 4400 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
4173
4174 /* the above is appropriate for STA mode for PS purposes */
4175 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
4176
4177out: 4401out:
4178 mutex_unlock(&wl->mutex); 4402 mutex_unlock(&wl->mutex);
4179 4403
@@ -4604,7 +4828,7 @@ static struct bin_attribute fwlog_attr = {
4604 .read = wl1271_sysfs_read_fwlog, 4828 .read = wl1271_sysfs_read_fwlog,
4605}; 4829};
4606 4830
4607int wl1271_register_hw(struct wl1271 *wl) 4831static int wl1271_register_hw(struct wl1271 *wl)
4608{ 4832{
4609 int ret; 4833 int ret;
4610 4834
@@ -4645,9 +4869,8 @@ int wl1271_register_hw(struct wl1271 *wl)
4645 4869
4646 return 0; 4870 return 0;
4647} 4871}
4648EXPORT_SYMBOL_GPL(wl1271_register_hw);
4649 4872
4650void wl1271_unregister_hw(struct wl1271 *wl) 4873static void wl1271_unregister_hw(struct wl1271 *wl)
4651{ 4874{
4652 if (wl->state == WL1271_STATE_PLT) 4875 if (wl->state == WL1271_STATE_PLT)
4653 __wl1271_plt_stop(wl); 4876 __wl1271_plt_stop(wl);
@@ -4657,9 +4880,8 @@ void wl1271_unregister_hw(struct wl1271 *wl)
4657 wl->mac80211_registered = false; 4880 wl->mac80211_registered = false;
4658 4881
4659} 4882}
4660EXPORT_SYMBOL_GPL(wl1271_unregister_hw);
4661 4883
4662int wl1271_init_ieee80211(struct wl1271 *wl) 4884static int wl1271_init_ieee80211(struct wl1271 *wl)
4663{ 4885{
4664 static const u32 cipher_suites[] = { 4886 static const u32 cipher_suites[] = {
4665 WLAN_CIPHER_SUITE_WEP40, 4887 WLAN_CIPHER_SUITE_WEP40,
@@ -4736,27 +4958,33 @@ int wl1271_init_ieee80211(struct wl1271 *wl)
4736 4958
4737 wl->hw->wiphy->reg_notifier = wl1271_reg_notify; 4959 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
4738 4960
4739 SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl)); 4961 /* the FW answers probe-requests in AP-mode */
4962 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
4963 wl->hw->wiphy->probe_resp_offload =
4964 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
4965 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
4966 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
4967
4968 SET_IEEE80211_DEV(wl->hw, wl->dev);
4740 4969
4741 wl->hw->sta_data_size = sizeof(struct wl1271_station); 4970 wl->hw->sta_data_size = sizeof(struct wl1271_station);
4971 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
4742 4972
4743 wl->hw->max_rx_aggregation_subframes = 8; 4973 wl->hw->max_rx_aggregation_subframes = 8;
4744 4974
4745 return 0; 4975 return 0;
4746} 4976}
4747EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
4748 4977
4749#define WL1271_DEFAULT_CHANNEL 0 4978#define WL1271_DEFAULT_CHANNEL 0
4750 4979
4751struct ieee80211_hw *wl1271_alloc_hw(void) 4980static struct ieee80211_hw *wl1271_alloc_hw(void)
4752{ 4981{
4753 struct ieee80211_hw *hw; 4982 struct ieee80211_hw *hw;
4754 struct platform_device *plat_dev = NULL;
4755 struct wl1271 *wl; 4983 struct wl1271 *wl;
4756 int i, j, ret; 4984 int i, j, ret;
4757 unsigned int order; 4985 unsigned int order;
4758 4986
4759 BUILD_BUG_ON(AP_MAX_LINKS > WL12XX_MAX_LINKS); 4987 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
4760 4988
4761 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops); 4989 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
4762 if (!hw) { 4990 if (!hw) {
@@ -4765,41 +4993,26 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4765 goto err_hw_alloc; 4993 goto err_hw_alloc;
4766 } 4994 }
4767 4995
4768 plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
4769 if (!plat_dev) {
4770 wl1271_error("could not allocate platform_device");
4771 ret = -ENOMEM;
4772 goto err_plat_alloc;
4773 }
4774
4775 wl = hw->priv; 4996 wl = hw->priv;
4776 memset(wl, 0, sizeof(*wl)); 4997 memset(wl, 0, sizeof(*wl));
4777 4998
4778 INIT_LIST_HEAD(&wl->list); 4999 INIT_LIST_HEAD(&wl->list);
5000 INIT_LIST_HEAD(&wl->wlvif_list);
4779 5001
4780 wl->hw = hw; 5002 wl->hw = hw;
4781 wl->plat_dev = plat_dev;
4782
4783 for (i = 0; i < NUM_TX_QUEUES; i++)
4784 skb_queue_head_init(&wl->tx_queue[i]);
4785 5003
4786 for (i = 0; i < NUM_TX_QUEUES; i++) 5004 for (i = 0; i < NUM_TX_QUEUES; i++)
4787 for (j = 0; j < AP_MAX_LINKS; j++) 5005 for (j = 0; j < WL12XX_MAX_LINKS; j++)
4788 skb_queue_head_init(&wl->links[j].tx_queue[i]); 5006 skb_queue_head_init(&wl->links[j].tx_queue[i]);
4789 5007
4790 skb_queue_head_init(&wl->deferred_rx_queue); 5008 skb_queue_head_init(&wl->deferred_rx_queue);
4791 skb_queue_head_init(&wl->deferred_tx_queue); 5009 skb_queue_head_init(&wl->deferred_tx_queue);
4792 5010
4793 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work); 5011 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
4794 INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
4795 INIT_WORK(&wl->netstack_work, wl1271_netstack_work); 5012 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
4796 INIT_WORK(&wl->tx_work, wl1271_tx_work); 5013 INIT_WORK(&wl->tx_work, wl1271_tx_work);
4797 INIT_WORK(&wl->recovery_work, wl1271_recovery_work); 5014 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
4798 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work); 5015 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
4799 INIT_WORK(&wl->rx_streaming_enable_work,
4800 wl1271_rx_streaming_enable_work);
4801 INIT_WORK(&wl->rx_streaming_disable_work,
4802 wl1271_rx_streaming_disable_work);
4803 5016
4804 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq"); 5017 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
4805 if (!wl->freezable_wq) { 5018 if (!wl->freezable_wq) {
@@ -4808,41 +5021,21 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4808 } 5021 }
4809 5022
4810 wl->channel = WL1271_DEFAULT_CHANNEL; 5023 wl->channel = WL1271_DEFAULT_CHANNEL;
4811 wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
4812 wl->default_key = 0;
4813 wl->rx_counter = 0; 5024 wl->rx_counter = 0;
4814 wl->psm_entry_retry = 0;
4815 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 5025 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
4816 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
4817 wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
4818 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
4819 wl->band = IEEE80211_BAND_2GHZ; 5026 wl->band = IEEE80211_BAND_2GHZ;
4820 wl->vif = NULL; 5027 wl->vif = NULL;
4821 wl->flags = 0; 5028 wl->flags = 0;
4822 wl->sg_enabled = true; 5029 wl->sg_enabled = true;
4823 wl->hw_pg_ver = -1; 5030 wl->hw_pg_ver = -1;
4824 wl->bss_type = MAX_BSS_TYPE;
4825 wl->set_bss_type = MAX_BSS_TYPE;
4826 wl->last_tx_hlid = 0;
4827 wl->ap_ps_map = 0; 5031 wl->ap_ps_map = 0;
4828 wl->ap_fw_ps_map = 0; 5032 wl->ap_fw_ps_map = 0;
4829 wl->quirks = 0; 5033 wl->quirks = 0;
4830 wl->platform_quirks = 0; 5034 wl->platform_quirks = 0;
4831 wl->sched_scanning = false; 5035 wl->sched_scanning = false;
4832 wl->tx_security_seq = 0;
4833 wl->tx_security_last_seq_lsb = 0;
4834 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; 5036 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
4835 wl->role_id = WL12XX_INVALID_ROLE_ID;
4836 wl->system_hlid = WL12XX_SYSTEM_HLID; 5037 wl->system_hlid = WL12XX_SYSTEM_HLID;
4837 wl->sta_hlid = WL12XX_INVALID_LINK_ID;
4838 wl->dev_role_id = WL12XX_INVALID_ROLE_ID;
4839 wl->dev_hlid = WL12XX_INVALID_LINK_ID;
4840 wl->session_counter = 0;
4841 wl->ap_bcast_hlid = WL12XX_INVALID_LINK_ID;
4842 wl->ap_global_hlid = WL12XX_INVALID_LINK_ID;
4843 wl->active_sta_count = 0; 5038 wl->active_sta_count = 0;
4844 setup_timer(&wl->rx_streaming_timer, wl1271_rx_streaming_timer,
4845 (unsigned long) wl);
4846 wl->fwlog_size = 0; 5039 wl->fwlog_size = 0;
4847 init_waitqueue_head(&wl->fwlog_waitq); 5040 init_waitqueue_head(&wl->fwlog_waitq);
4848 5041
@@ -4860,8 +5053,6 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4860 5053
4861 /* Apply default driver configuration. */ 5054 /* Apply default driver configuration. */
4862 wl1271_conf_init(wl); 5055 wl1271_conf_init(wl);
4863 wl->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
4864 wl->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
4865 5056
4866 order = get_order(WL1271_AGGR_BUFFER_SIZE); 5057 order = get_order(WL1271_AGGR_BUFFER_SIZE);
4867 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); 5058 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
@@ -4883,49 +5074,8 @@ struct ieee80211_hw *wl1271_alloc_hw(void)
4883 goto err_dummy_packet; 5074 goto err_dummy_packet;
4884 } 5075 }
4885 5076
4886 /* Register platform device */
4887 ret = platform_device_register(wl->plat_dev);
4888 if (ret) {
4889 wl1271_error("couldn't register platform device");
4890 goto err_fwlog;
4891 }
4892 dev_set_drvdata(&wl->plat_dev->dev, wl);
4893
4894 /* Create sysfs file to control bt coex state */
4895 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4896 if (ret < 0) {
4897 wl1271_error("failed to create sysfs file bt_coex_state");
4898 goto err_platform;
4899 }
4900
4901 /* Create sysfs file to get HW PG version */
4902 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4903 if (ret < 0) {
4904 wl1271_error("failed to create sysfs file hw_pg_ver");
4905 goto err_bt_coex_state;
4906 }
4907
4908 /* Create sysfs file for the FW log */
4909 ret = device_create_bin_file(&wl->plat_dev->dev, &fwlog_attr);
4910 if (ret < 0) {
4911 wl1271_error("failed to create sysfs file fwlog");
4912 goto err_hw_pg_ver;
4913 }
4914
4915 return hw; 5077 return hw;
4916 5078
4917err_hw_pg_ver:
4918 device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4919
4920err_bt_coex_state:
4921 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4922
4923err_platform:
4924 platform_device_unregister(wl->plat_dev);
4925
4926err_fwlog:
4927 free_page((unsigned long)wl->fwlog);
4928
4929err_dummy_packet: 5079err_dummy_packet:
4930 dev_kfree_skb(wl->dummy_packet); 5080 dev_kfree_skb(wl->dummy_packet);
4931 5081
@@ -4937,18 +5087,14 @@ err_wq:
4937 5087
4938err_hw: 5088err_hw:
4939 wl1271_debugfs_exit(wl); 5089 wl1271_debugfs_exit(wl);
4940 kfree(plat_dev);
4941
4942err_plat_alloc:
4943 ieee80211_free_hw(hw); 5090 ieee80211_free_hw(hw);
4944 5091
4945err_hw_alloc: 5092err_hw_alloc:
4946 5093
4947 return ERR_PTR(ret); 5094 return ERR_PTR(ret);
4948} 5095}
4949EXPORT_SYMBOL_GPL(wl1271_alloc_hw);
4950 5096
4951int wl1271_free_hw(struct wl1271 *wl) 5097static int wl1271_free_hw(struct wl1271 *wl)
4952{ 5098{
4953 /* Unblock any fwlog readers */ 5099 /* Unblock any fwlog readers */
4954 mutex_lock(&wl->mutex); 5100 mutex_lock(&wl->mutex);
@@ -4956,17 +5102,15 @@ int wl1271_free_hw(struct wl1271 *wl)
4956 wake_up_interruptible_all(&wl->fwlog_waitq); 5102 wake_up_interruptible_all(&wl->fwlog_waitq);
4957 mutex_unlock(&wl->mutex); 5103 mutex_unlock(&wl->mutex);
4958 5104
4959 device_remove_bin_file(&wl->plat_dev->dev, &fwlog_attr); 5105 device_remove_bin_file(wl->dev, &fwlog_attr);
4960 5106
4961 device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver); 5107 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
4962 5108
4963 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state); 5109 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
4964 platform_device_unregister(wl->plat_dev);
4965 free_page((unsigned long)wl->fwlog); 5110 free_page((unsigned long)wl->fwlog);
4966 dev_kfree_skb(wl->dummy_packet); 5111 dev_kfree_skb(wl->dummy_packet);
4967 free_pages((unsigned long)wl->aggr_buf, 5112 free_pages((unsigned long)wl->aggr_buf,
4968 get_order(WL1271_AGGR_BUFFER_SIZE)); 5113 get_order(WL1271_AGGR_BUFFER_SIZE));
4969 kfree(wl->plat_dev);
4970 5114
4971 wl1271_debugfs_exit(wl); 5115 wl1271_debugfs_exit(wl);
4972 5116
@@ -4983,7 +5127,174 @@ int wl1271_free_hw(struct wl1271 *wl)
4983 5127
4984 return 0; 5128 return 0;
4985} 5129}
4986EXPORT_SYMBOL_GPL(wl1271_free_hw); 5130
5131static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5132{
5133 struct wl1271 *wl = cookie;
5134 unsigned long flags;
5135
5136 wl1271_debug(DEBUG_IRQ, "IRQ");
5137
5138 /* complete the ELP completion */
5139 spin_lock_irqsave(&wl->wl_lock, flags);
5140 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5141 if (wl->elp_compl) {
5142 complete(wl->elp_compl);
5143 wl->elp_compl = NULL;
5144 }
5145
5146 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5147 /* don't enqueue a work right now. mark it as pending */
5148 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5149 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5150 disable_irq_nosync(wl->irq);
5151 pm_wakeup_event(wl->dev, 0);
5152 spin_unlock_irqrestore(&wl->wl_lock, flags);
5153 return IRQ_HANDLED;
5154 }
5155 spin_unlock_irqrestore(&wl->wl_lock, flags);
5156
5157 return IRQ_WAKE_THREAD;
5158}
5159
5160static int __devinit wl12xx_probe(struct platform_device *pdev)
5161{
5162 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5163 struct ieee80211_hw *hw;
5164 struct wl1271 *wl;
5165 unsigned long irqflags;
5166 int ret = -ENODEV;
5167
5168 hw = wl1271_alloc_hw();
5169 if (IS_ERR(hw)) {
5170 wl1271_error("can't allocate hw");
5171 ret = PTR_ERR(hw);
5172 goto out;
5173 }
5174
5175 wl = hw->priv;
5176 wl->irq = platform_get_irq(pdev, 0);
5177 wl->ref_clock = pdata->board_ref_clock;
5178 wl->tcxo_clock = pdata->board_tcxo_clock;
5179 wl->platform_quirks = pdata->platform_quirks;
5180 wl->set_power = pdata->set_power;
5181 wl->dev = &pdev->dev;
5182 wl->if_ops = pdata->ops;
5183
5184 platform_set_drvdata(pdev, wl);
5185
5186 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5187 irqflags = IRQF_TRIGGER_RISING;
5188 else
5189 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5190
5191 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5192 irqflags,
5193 pdev->name, wl);
5194 if (ret < 0) {
5195 wl1271_error("request_irq() failed: %d", ret);
5196 goto out_free_hw;
5197 }
5198
5199 ret = enable_irq_wake(wl->irq);
5200 if (!ret) {
5201 wl->irq_wake_enabled = true;
5202 device_init_wakeup(wl->dev, 1);
5203 if (pdata->pwr_in_suspend)
5204 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5205
5206 }
5207 disable_irq(wl->irq);
5208
5209 ret = wl1271_init_ieee80211(wl);
5210 if (ret)
5211 goto out_irq;
5212
5213 ret = wl1271_register_hw(wl);
5214 if (ret)
5215 goto out_irq;
5216
5217 /* Create sysfs file to control bt coex state */
5218 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5219 if (ret < 0) {
5220 wl1271_error("failed to create sysfs file bt_coex_state");
5221 goto out_irq;
5222 }
5223
5224 /* Create sysfs file to get HW PG version */
5225 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5226 if (ret < 0) {
5227 wl1271_error("failed to create sysfs file hw_pg_ver");
5228 goto out_bt_coex_state;
5229 }
5230
5231 /* Create sysfs file for the FW log */
5232 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5233 if (ret < 0) {
5234 wl1271_error("failed to create sysfs file fwlog");
5235 goto out_hw_pg_ver;
5236 }
5237
5238 return 0;
5239
5240out_hw_pg_ver:
5241 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5242
5243out_bt_coex_state:
5244 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5245
5246out_irq:
5247 free_irq(wl->irq, wl);
5248
5249out_free_hw:
5250 wl1271_free_hw(wl);
5251
5252out:
5253 return ret;
5254}
5255
5256static int __devexit wl12xx_remove(struct platform_device *pdev)
5257{
5258 struct wl1271 *wl = platform_get_drvdata(pdev);
5259
5260 if (wl->irq_wake_enabled) {
5261 device_init_wakeup(wl->dev, 0);
5262 disable_irq_wake(wl->irq);
5263 }
5264 wl1271_unregister_hw(wl);
5265 free_irq(wl->irq, wl);
5266 wl1271_free_hw(wl);
5267
5268 return 0;
5269}
5270
5271static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
5272 { "wl12xx", 0 },
5273 { } /* Terminating Entry */
5274};
5275MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
5276
5277static struct platform_driver wl12xx_driver = {
5278 .probe = wl12xx_probe,
5279 .remove = __devexit_p(wl12xx_remove),
5280 .id_table = wl12xx_id_table,
5281 .driver = {
5282 .name = "wl12xx_driver",
5283 .owner = THIS_MODULE,
5284 }
5285};
5286
5287static int __init wl12xx_init(void)
5288{
5289 return platform_driver_register(&wl12xx_driver);
5290}
5291module_init(wl12xx_init);
5292
5293static void __exit wl12xx_exit(void)
5294{
5295 platform_driver_unregister(&wl12xx_driver);
5296}
5297module_exit(wl12xx_exit);
4987 5298
4988u32 wl12xx_debug_level = DEBUG_NONE; 5299u32 wl12xx_debug_level = DEBUG_NONE;
4989EXPORT_SYMBOL_GPL(wl12xx_debug_level); 5300EXPORT_SYMBOL_GPL(wl12xx_debug_level);
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/ps.c
index c15ebf2efd40..a7a11088dd31 100644
--- a/drivers/net/wireless/wl12xx/ps.c
+++ b/drivers/net/wireless/wl12xx/ps.c
@@ -25,6 +25,7 @@
25#include "ps.h" 25#include "ps.h"
26#include "io.h" 26#include "io.h"
27#include "tx.h" 27#include "tx.h"
28#include "debug.h"
28 29
29#define WL1271_WAKEUP_TIMEOUT 500 30#define WL1271_WAKEUP_TIMEOUT 500
30 31
@@ -32,6 +33,7 @@ void wl1271_elp_work(struct work_struct *work)
32{ 33{
33 struct delayed_work *dwork; 34 struct delayed_work *dwork;
34 struct wl1271 *wl; 35 struct wl1271 *wl;
36 struct wl12xx_vif *wlvif;
35 37
36 dwork = container_of(work, struct delayed_work, work); 38 dwork = container_of(work, struct delayed_work, work);
37 wl = container_of(dwork, struct wl1271, elp_work); 39 wl = container_of(dwork, struct wl1271, elp_work);
@@ -47,11 +49,15 @@ void wl1271_elp_work(struct work_struct *work)
47 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) 49 if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
48 goto out; 50 goto out;
49 51
50 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) || 52 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
51 (!test_bit(WL1271_FLAG_PSM, &wl->flags) &&
52 !test_bit(WL1271_FLAG_IDLE, &wl->flags)))
53 goto out; 53 goto out;
54 54
55 wl12xx_for_each_wlvif(wl, wlvif) {
56 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags) &&
57 !test_bit(WL1271_FLAG_IDLE, &wl->flags))
58 goto out;
59 }
60
55 wl1271_debug(DEBUG_PSM, "chip to elp"); 61 wl1271_debug(DEBUG_PSM, "chip to elp");
56 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); 62 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
57 set_bit(WL1271_FLAG_IN_ELP, &wl->flags); 63 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
@@ -65,13 +71,17 @@ out:
65/* Routines to toggle sleep mode while in ELP */ 71/* Routines to toggle sleep mode while in ELP */
66void wl1271_ps_elp_sleep(struct wl1271 *wl) 72void wl1271_ps_elp_sleep(struct wl1271 *wl)
67{ 73{
74 struct wl12xx_vif *wlvif;
75
68 /* we shouldn't get consecutive sleep requests */ 76 /* we shouldn't get consecutive sleep requests */
69 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))) 77 if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
70 return; 78 return;
71 79
72 if (!test_bit(WL1271_FLAG_PSM, &wl->flags) && 80 wl12xx_for_each_wlvif(wl, wlvif) {
73 !test_bit(WL1271_FLAG_IDLE, &wl->flags)) 81 if (!test_bit(WLVIF_FLAG_PSM, &wlvif->flags) &&
74 return; 82 !test_bit(WL1271_FLAG_IDLE, &wl->flags))
83 return;
84 }
75 85
76 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, 86 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
77 msecs_to_jiffies(ELP_ENTRY_DELAY)); 87 msecs_to_jiffies(ELP_ENTRY_DELAY));
@@ -143,8 +153,8 @@ out:
143 return 0; 153 return 0;
144} 154}
145 155
146int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 156int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
147 u32 rates, bool send) 157 enum wl1271_cmd_ps_mode mode, u32 rates, bool send)
148{ 158{
149 int ret; 159 int ret;
150 160
@@ -152,39 +162,34 @@ int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
152 case STATION_POWER_SAVE_MODE: 162 case STATION_POWER_SAVE_MODE:
153 wl1271_debug(DEBUG_PSM, "entering psm"); 163 wl1271_debug(DEBUG_PSM, "entering psm");
154 164
155 ret = wl1271_acx_wake_up_conditions(wl); 165 ret = wl1271_acx_wake_up_conditions(wl, wlvif);
156 if (ret < 0) { 166 if (ret < 0) {
157 wl1271_error("couldn't set wake up conditions"); 167 wl1271_error("couldn't set wake up conditions");
158 return ret; 168 return ret;
159 } 169 }
160 170
161 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); 171 ret = wl1271_cmd_ps_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
162 if (ret < 0) 172 if (ret < 0)
163 return ret; 173 return ret;
164 174
165 set_bit(WL1271_FLAG_PSM, &wl->flags); 175 set_bit(WLVIF_FLAG_PSM, &wlvif->flags);
166 break; 176 break;
167 case STATION_ACTIVE_MODE: 177 case STATION_ACTIVE_MODE:
168 default: 178 default:
169 wl1271_debug(DEBUG_PSM, "leaving psm"); 179 wl1271_debug(DEBUG_PSM, "leaving psm");
170 180
171 /* disable beacon early termination */ 181 /* disable beacon early termination */
172 if (wl->band == IEEE80211_BAND_2GHZ) { 182 if (wlvif->band == IEEE80211_BAND_2GHZ) {
173 ret = wl1271_acx_bet_enable(wl, false); 183 ret = wl1271_acx_bet_enable(wl, wlvif, false);
174 if (ret < 0) 184 if (ret < 0)
175 return ret; 185 return ret;
176 } 186 }
177 187
178 /* disable beacon filtering */ 188 ret = wl1271_cmd_ps_mode(wl, wlvif, STATION_ACTIVE_MODE);
179 ret = wl1271_acx_beacon_filter_opt(wl, false);
180 if (ret < 0)
181 return ret;
182
183 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
184 if (ret < 0) 189 if (ret < 0)
185 return ret; 190 return ret;
186 191
187 clear_bit(WL1271_FLAG_PSM, &wl->flags); 192 clear_bit(WLVIF_FLAG_PSM, &wlvif->flags);
188 break; 193 break;
189 } 194 }
190 195
@@ -223,9 +228,11 @@ static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
223 wl1271_handle_tx_low_watermark(wl); 228 wl1271_handle_tx_low_watermark(wl);
224} 229}
225 230
226void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues) 231void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
232 u8 hlid, bool clean_queues)
227{ 233{
228 struct ieee80211_sta *sta; 234 struct ieee80211_sta *sta;
235 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
229 236
230 if (test_bit(hlid, &wl->ap_ps_map)) 237 if (test_bit(hlid, &wl->ap_ps_map))
231 return; 238 return;
@@ -235,7 +242,7 @@ void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues)
235 clean_queues); 242 clean_queues);
236 243
237 rcu_read_lock(); 244 rcu_read_lock();
238 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); 245 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
239 if (!sta) { 246 if (!sta) {
240 wl1271_error("could not find sta %pM for starting ps", 247 wl1271_error("could not find sta %pM for starting ps",
241 wl->links[hlid].addr); 248 wl->links[hlid].addr);
@@ -253,9 +260,10 @@ void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues)
253 __set_bit(hlid, &wl->ap_ps_map); 260 __set_bit(hlid, &wl->ap_ps_map);
254} 261}
255 262
256void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid) 263void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
257{ 264{
258 struct ieee80211_sta *sta; 265 struct ieee80211_sta *sta;
266 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
259 267
260 if (!test_bit(hlid, &wl->ap_ps_map)) 268 if (!test_bit(hlid, &wl->ap_ps_map))
261 return; 269 return;
@@ -265,7 +273,7 @@ void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid)
265 __clear_bit(hlid, &wl->ap_ps_map); 273 __clear_bit(hlid, &wl->ap_ps_map);
266 274
267 rcu_read_lock(); 275 rcu_read_lock();
268 sta = ieee80211_find_sta(wl->vif, wl->links[hlid].addr); 276 sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
269 if (!sta) { 277 if (!sta) {
270 wl1271_error("could not find sta %pM for ending ps", 278 wl1271_error("could not find sta %pM for ending ps",
271 wl->links[hlid].addr); 279 wl->links[hlid].addr);
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/ps.h
index 25eb9bc9b628..a12052f02026 100644
--- a/drivers/net/wireless/wl12xx/ps.h
+++ b/drivers/net/wireless/wl12xx/ps.h
@@ -27,13 +27,14 @@
27#include "wl12xx.h" 27#include "wl12xx.h"
28#include "acx.h" 28#include "acx.h"
29 29
30int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, 30int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
31 u32 rates, bool send); 31 enum wl1271_cmd_ps_mode mode, u32 rates, bool send);
32void wl1271_ps_elp_sleep(struct wl1271 *wl); 32void wl1271_ps_elp_sleep(struct wl1271 *wl);
33int wl1271_ps_elp_wakeup(struct wl1271 *wl); 33int wl1271_ps_elp_wakeup(struct wl1271 *wl);
34void wl1271_elp_work(struct work_struct *work); 34void wl1271_elp_work(struct work_struct *work);
35void wl1271_ps_link_start(struct wl1271 *wl, u8 hlid, bool clean_queues); 35void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
36void wl1271_ps_link_end(struct wl1271 *wl, u8 hlid); 36 u8 hlid, bool clean_queues);
37void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
37 38
38#define WL1271_PS_COMPLETE_TIMEOUT 500 39#define WL1271_PS_COMPLETE_TIMEOUT 500
39 40
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h
index 3f570f397586..df34d5977b98 100644
--- a/drivers/net/wireless/wl12xx/reg.h
+++ b/drivers/net/wireless/wl12xx/reg.h
@@ -408,7 +408,7 @@
408 408
409 409
410/* Firmware image load chunk size */ 410/* Firmware image load chunk size */
411#define CHUNK_SIZE 512 411#define CHUNK_SIZE 16384
412 412
413/* Firmware image header size */ 413/* Firmware image header size */
414#define FW_HDR_SIZE 8 414#define FW_HDR_SIZE 8
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c
index dee4cfe9ccc1..8c277c0cb372 100644
--- a/drivers/net/wireless/wl12xx/rx.c
+++ b/drivers/net/wireless/wl12xx/rx.c
@@ -25,9 +25,11 @@
25#include <linux/sched.h> 25#include <linux/sched.h>
26 26
27#include "wl12xx.h" 27#include "wl12xx.h"
28#include "debug.h"
28#include "acx.h" 29#include "acx.h"
29#include "reg.h" 30#include "reg.h"
30#include "rx.h" 31#include "rx.h"
32#include "tx.h"
31#include "io.h" 33#include "io.h"
32 34
33static u8 wl12xx_rx_get_mem_block(struct wl12xx_fw_status *status, 35static u8 wl12xx_rx_get_mem_block(struct wl12xx_fw_status *status,
@@ -96,7 +98,7 @@ static void wl1271_rx_status(struct wl1271 *wl,
96} 98}
97 99
98static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length, 100static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
99 bool unaligned) 101 bool unaligned, u8 *hlid)
100{ 102{
101 struct wl1271_rx_descriptor *desc; 103 struct wl1271_rx_descriptor *desc;
102 struct sk_buff *skb; 104 struct sk_buff *skb;
@@ -159,6 +161,7 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
159 * payload aligned to 4 bytes. 161 * payload aligned to 4 bytes.
160 */ 162 */
161 memcpy(buf, data + sizeof(*desc), length - sizeof(*desc)); 163 memcpy(buf, data + sizeof(*desc), length - sizeof(*desc));
164 *hlid = desc->hlid;
162 165
163 hdr = (struct ieee80211_hdr *)skb->data; 166 hdr = (struct ieee80211_hdr *)skb->data;
164 if (ieee80211_is_beacon(hdr->frame_control)) 167 if (ieee80211_is_beacon(hdr->frame_control))
@@ -169,10 +172,10 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
169 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon); 172 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
170 173
171 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; 174 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
172 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d", skb, 175 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
173 skb->len - desc->pad_len, 176 skb->len - desc->pad_len,
174 beacon ? "beacon" : "", 177 beacon ? "beacon" : "",
175 seq_num); 178 seq_num, *hlid);
176 179
177 skb_trim(skb, skb->len - desc->pad_len); 180 skb_trim(skb, skb->len - desc->pad_len);
178 181
@@ -185,6 +188,7 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
185void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status) 188void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
186{ 189{
187 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; 190 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
191 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
188 u32 buf_size; 192 u32 buf_size;
189 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 193 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
190 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 194 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
@@ -192,8 +196,7 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
192 u32 mem_block; 196 u32 mem_block;
193 u32 pkt_length; 197 u32 pkt_length;
194 u32 pkt_offset; 198 u32 pkt_offset;
195 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 199 u8 hlid;
196 bool had_data = false;
197 bool unaligned = false; 200 bool unaligned = false;
198 201
199 while (drv_rx_counter != fw_rx_counter) { 202 while (drv_rx_counter != fw_rx_counter) {
@@ -253,8 +256,11 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
253 */ 256 */
254 if (wl1271_rx_handle_data(wl, 257 if (wl1271_rx_handle_data(wl,
255 wl->aggr_buf + pkt_offset, 258 wl->aggr_buf + pkt_offset,
256 pkt_length, unaligned) == 1) 259 pkt_length, unaligned,
257 had_data = true; 260 &hlid) == 1) {
261 WARN_ON(hlid >= WL12XX_MAX_LINKS);
262 __set_bit(hlid, active_hlids);
263 }
258 264
259 wl->rx_counter++; 265 wl->rx_counter++;
260 drv_rx_counter++; 266 drv_rx_counter++;
@@ -270,17 +276,5 @@ void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
270 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION) 276 if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
271 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter); 277 wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
272 278
273 if (!is_ap && wl->conf.rx_streaming.interval && had_data && 279 wl12xx_rearm_rx_streaming(wl, active_hlids);
274 (wl->conf.rx_streaming.always ||
275 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) {
276 u32 timeout = wl->conf.rx_streaming.duration;
277
278 /* restart rx streaming */
279 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
280 ieee80211_queue_work(wl->hw,
281 &wl->rx_streaming_enable_work);
282
283 mod_timer(&wl->rx_streaming_timer,
284 jiffies + msecs_to_jiffies(timeout));
285 }
286} 280}
diff --git a/drivers/net/wireless/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c
index fc29c671cf3b..8599dab1fe2a 100644
--- a/drivers/net/wireless/wl12xx/scan.c
+++ b/drivers/net/wireless/wl12xx/scan.c
@@ -24,6 +24,7 @@
24#include <linux/ieee80211.h> 24#include <linux/ieee80211.h>
25 25
26#include "wl12xx.h" 26#include "wl12xx.h"
27#include "debug.h"
27#include "cmd.h" 28#include "cmd.h"
28#include "scan.h" 29#include "scan.h"
29#include "acx.h" 30#include "acx.h"
@@ -34,6 +35,8 @@ void wl1271_scan_complete_work(struct work_struct *work)
34{ 35{
35 struct delayed_work *dwork; 36 struct delayed_work *dwork;
36 struct wl1271 *wl; 37 struct wl1271 *wl;
38 struct ieee80211_vif *vif;
39 struct wl12xx_vif *wlvif;
37 int ret; 40 int ret;
38 bool is_sta, is_ibss; 41 bool is_sta, is_ibss;
39 42
@@ -50,28 +53,31 @@ void wl1271_scan_complete_work(struct work_struct *work)
50 if (wl->scan.state == WL1271_SCAN_STATE_IDLE) 53 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
51 goto out; 54 goto out;
52 55
56 vif = wl->scan_vif;
57 wlvif = wl12xx_vif_to_data(vif);
58
53 wl->scan.state = WL1271_SCAN_STATE_IDLE; 59 wl->scan.state = WL1271_SCAN_STATE_IDLE;
54 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 60 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
55 wl->scan.req = NULL; 61 wl->scan.req = NULL;
62 wl->scan_vif = NULL;
56 63
57 ret = wl1271_ps_elp_wakeup(wl); 64 ret = wl1271_ps_elp_wakeup(wl);
58 if (ret < 0) 65 if (ret < 0)
59 goto out; 66 goto out;
60 67
61 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { 68 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
62 /* restore hardware connection monitoring template */ 69 /* restore hardware connection monitoring template */
63 wl1271_cmd_build_ap_probe_req(wl, wl->probereq); 70 wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
64 } 71 }
65 72
66 /* return to ROC if needed */ 73 /* return to ROC if needed */
67 is_sta = (wl->bss_type == BSS_TYPE_STA_BSS); 74 is_sta = (wlvif->bss_type == BSS_TYPE_STA_BSS);
68 is_ibss = (wl->bss_type == BSS_TYPE_IBSS); 75 is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
69 if (((is_sta && !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) || 76 if (((is_sta && !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) ||
70 (is_ibss && !test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags))) && 77 (is_ibss && !test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags))) &&
71 !test_bit(wl->dev_role_id, wl->roc_map)) { 78 !test_bit(wlvif->dev_role_id, wl->roc_map)) {
72 /* restore remain on channel */ 79 /* restore remain on channel */
73 wl12xx_cmd_role_start_dev(wl); 80 wl12xx_start_dev(wl, wlvif);
74 wl12xx_roc(wl, wl->dev_role_id);
75 } 81 }
76 wl1271_ps_elp_sleep(wl); 82 wl1271_ps_elp_sleep(wl);
77 83
@@ -155,9 +161,11 @@ static int wl1271_get_scan_channels(struct wl1271 *wl,
155 161
156#define WL1271_NOTHING_TO_SCAN 1 162#define WL1271_NOTHING_TO_SCAN 1
157 163
158static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band, 164static int wl1271_scan_send(struct wl1271 *wl, struct ieee80211_vif *vif,
159 bool passive, u32 basic_rate) 165 enum ieee80211_band band,
166 bool passive, u32 basic_rate)
160{ 167{
168 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
161 struct wl1271_cmd_scan *cmd; 169 struct wl1271_cmd_scan *cmd;
162 struct wl1271_cmd_trigger_scan_to *trigger; 170 struct wl1271_cmd_trigger_scan_to *trigger;
163 int ret; 171 int ret;
@@ -177,11 +185,11 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
177 if (passive) 185 if (passive)
178 scan_options |= WL1271_SCAN_OPT_PASSIVE; 186 scan_options |= WL1271_SCAN_OPT_PASSIVE;
179 187
180 if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) { 188 if (WARN_ON(wlvif->role_id == WL12XX_INVALID_ROLE_ID)) {
181 ret = -EINVAL; 189 ret = -EINVAL;
182 goto out; 190 goto out;
183 } 191 }
184 cmd->params.role_id = wl->role_id; 192 cmd->params.role_id = wlvif->role_id;
185 cmd->params.scan_options = cpu_to_le16(scan_options); 193 cmd->params.scan_options = cpu_to_le16(scan_options);
186 194
187 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req, 195 cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
@@ -194,7 +202,6 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
194 202
195 cmd->params.tx_rate = cpu_to_le32(basic_rate); 203 cmd->params.tx_rate = cpu_to_le32(basic_rate);
196 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs; 204 cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
197 cmd->params.tx_rate = cpu_to_le32(basic_rate);
198 cmd->params.tid_trigger = 0; 205 cmd->params.tid_trigger = 0;
199 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; 206 cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
200 207
@@ -208,11 +215,11 @@ static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band,
208 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len); 215 memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
209 } 216 }
210 217
211 memcpy(cmd->addr, wl->mac_addr, ETH_ALEN); 218 memcpy(cmd->addr, vif->addr, ETH_ALEN);
212 219
213 ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len, 220 ret = wl1271_cmd_build_probe_req(wl, wlvif, wl->scan.ssid,
214 wl->scan.req->ie, wl->scan.req->ie_len, 221 wl->scan.ssid_len, wl->scan.req->ie,
215 band); 222 wl->scan.req->ie_len, band);
216 if (ret < 0) { 223 if (ret < 0) {
217 wl1271_error("PROBE request template failed"); 224 wl1271_error("PROBE request template failed");
218 goto out; 225 goto out;
@@ -241,11 +248,12 @@ out:
241 return ret; 248 return ret;
242} 249}
243 250
244void wl1271_scan_stm(struct wl1271 *wl) 251void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif)
245{ 252{
253 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
246 int ret = 0; 254 int ret = 0;
247 enum ieee80211_band band; 255 enum ieee80211_band band;
248 u32 rate; 256 u32 rate, mask;
249 257
250 switch (wl->scan.state) { 258 switch (wl->scan.state) {
251 case WL1271_SCAN_STATE_IDLE: 259 case WL1271_SCAN_STATE_IDLE:
@@ -253,47 +261,59 @@ void wl1271_scan_stm(struct wl1271 *wl)
253 261
254 case WL1271_SCAN_STATE_2GHZ_ACTIVE: 262 case WL1271_SCAN_STATE_2GHZ_ACTIVE:
255 band = IEEE80211_BAND_2GHZ; 263 band = IEEE80211_BAND_2GHZ;
256 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 264 mask = wlvif->bitrate_masks[band];
257 ret = wl1271_scan_send(wl, band, false, rate); 265 if (wl->scan.req->no_cck) {
266 mask &= ~CONF_TX_CCK_RATES;
267 if (!mask)
268 mask = CONF_TX_RATE_MASK_BASIC_P2P;
269 }
270 rate = wl1271_tx_min_rate_get(wl, mask);
271 ret = wl1271_scan_send(wl, vif, band, false, rate);
258 if (ret == WL1271_NOTHING_TO_SCAN) { 272 if (ret == WL1271_NOTHING_TO_SCAN) {
259 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE; 273 wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
260 wl1271_scan_stm(wl); 274 wl1271_scan_stm(wl, vif);
261 } 275 }
262 276
263 break; 277 break;
264 278
265 case WL1271_SCAN_STATE_2GHZ_PASSIVE: 279 case WL1271_SCAN_STATE_2GHZ_PASSIVE:
266 band = IEEE80211_BAND_2GHZ; 280 band = IEEE80211_BAND_2GHZ;
267 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 281 mask = wlvif->bitrate_masks[band];
268 ret = wl1271_scan_send(wl, band, true, rate); 282 if (wl->scan.req->no_cck) {
283 mask &= ~CONF_TX_CCK_RATES;
284 if (!mask)
285 mask = CONF_TX_RATE_MASK_BASIC_P2P;
286 }
287 rate = wl1271_tx_min_rate_get(wl, mask);
288 ret = wl1271_scan_send(wl, vif, band, true, rate);
269 if (ret == WL1271_NOTHING_TO_SCAN) { 289 if (ret == WL1271_NOTHING_TO_SCAN) {
270 if (wl->enable_11a) 290 if (wl->enable_11a)
271 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE; 291 wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
272 else 292 else
273 wl->scan.state = WL1271_SCAN_STATE_DONE; 293 wl->scan.state = WL1271_SCAN_STATE_DONE;
274 wl1271_scan_stm(wl); 294 wl1271_scan_stm(wl, vif);
275 } 295 }
276 296
277 break; 297 break;
278 298
279 case WL1271_SCAN_STATE_5GHZ_ACTIVE: 299 case WL1271_SCAN_STATE_5GHZ_ACTIVE:
280 band = IEEE80211_BAND_5GHZ; 300 band = IEEE80211_BAND_5GHZ;
281 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 301 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
282 ret = wl1271_scan_send(wl, band, false, rate); 302 ret = wl1271_scan_send(wl, vif, band, false, rate);
283 if (ret == WL1271_NOTHING_TO_SCAN) { 303 if (ret == WL1271_NOTHING_TO_SCAN) {
284 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE; 304 wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
285 wl1271_scan_stm(wl); 305 wl1271_scan_stm(wl, vif);
286 } 306 }
287 307
288 break; 308 break;
289 309
290 case WL1271_SCAN_STATE_5GHZ_PASSIVE: 310 case WL1271_SCAN_STATE_5GHZ_PASSIVE:
291 band = IEEE80211_BAND_5GHZ; 311 band = IEEE80211_BAND_5GHZ;
292 rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); 312 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
293 ret = wl1271_scan_send(wl, band, true, rate); 313 ret = wl1271_scan_send(wl, vif, band, true, rate);
294 if (ret == WL1271_NOTHING_TO_SCAN) { 314 if (ret == WL1271_NOTHING_TO_SCAN) {
295 wl->scan.state = WL1271_SCAN_STATE_DONE; 315 wl->scan.state = WL1271_SCAN_STATE_DONE;
296 wl1271_scan_stm(wl); 316 wl1271_scan_stm(wl, vif);
297 } 317 }
298 318
299 break; 319 break;
@@ -317,7 +337,8 @@ void wl1271_scan_stm(struct wl1271 *wl)
317 } 337 }
318} 338}
319 339
320int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, 340int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
341 const u8 *ssid, size_t ssid_len,
321 struct cfg80211_scan_request *req) 342 struct cfg80211_scan_request *req)
322{ 343{
323 /* 344 /*
@@ -338,6 +359,7 @@ int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
338 wl->scan.ssid_len = 0; 359 wl->scan.ssid_len = 0;
339 } 360 }
340 361
362 wl->scan_vif = vif;
341 wl->scan.req = req; 363 wl->scan.req = req;
342 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); 364 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
343 365
@@ -346,7 +368,7 @@ int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
346 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, 368 ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
347 msecs_to_jiffies(WL1271_SCAN_TIMEOUT)); 369 msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
348 370
349 wl1271_scan_stm(wl); 371 wl1271_scan_stm(wl, vif);
350 372
351 return 0; 373 return 0;
352} 374}
@@ -550,6 +572,9 @@ wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
550 * so they're used in probe requests. 572 * so they're used in probe requests.
551 */ 573 */
552 for (i = 0; i < req->n_ssids; i++) { 574 for (i = 0; i < req->n_ssids; i++) {
575 if (!req->ssids[i].ssid_len)
576 continue;
577
553 for (j = 0; j < cmd->n_ssids; j++) 578 for (j = 0; j < cmd->n_ssids; j++)
554 if (!memcmp(req->ssids[i].ssid, 579 if (!memcmp(req->ssids[i].ssid,
555 cmd->ssids[j].ssid, 580 cmd->ssids[j].ssid,
@@ -585,6 +610,7 @@ out:
585} 610}
586 611
587int wl1271_scan_sched_scan_config(struct wl1271 *wl, 612int wl1271_scan_sched_scan_config(struct wl1271 *wl,
613 struct wl12xx_vif *wlvif,
588 struct cfg80211_sched_scan_request *req, 614 struct cfg80211_sched_scan_request *req,
589 struct ieee80211_sched_scan_ies *ies) 615 struct ieee80211_sched_scan_ies *ies)
590{ 616{
@@ -631,7 +657,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
631 } 657 }
632 658
633 if (!force_passive && cfg->active[0]) { 659 if (!force_passive && cfg->active[0]) {
634 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, 660 ret = wl1271_cmd_build_probe_req(wl, wlvif, req->ssids[0].ssid,
635 req->ssids[0].ssid_len, 661 req->ssids[0].ssid_len,
636 ies->ie[IEEE80211_BAND_2GHZ], 662 ies->ie[IEEE80211_BAND_2GHZ],
637 ies->len[IEEE80211_BAND_2GHZ], 663 ies->len[IEEE80211_BAND_2GHZ],
@@ -643,7 +669,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
643 } 669 }
644 670
645 if (!force_passive && cfg->active[1]) { 671 if (!force_passive && cfg->active[1]) {
646 ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, 672 ret = wl1271_cmd_build_probe_req(wl, wlvif, req->ssids[0].ssid,
647 req->ssids[0].ssid_len, 673 req->ssids[0].ssid_len,
648 ies->ie[IEEE80211_BAND_5GHZ], 674 ies->ie[IEEE80211_BAND_5GHZ],
649 ies->len[IEEE80211_BAND_5GHZ], 675 ies->len[IEEE80211_BAND_5GHZ],
@@ -667,14 +693,14 @@ out:
667 return ret; 693 return ret;
668} 694}
669 695
670int wl1271_scan_sched_scan_start(struct wl1271 *wl) 696int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
671{ 697{
672 struct wl1271_cmd_sched_scan_start *start; 698 struct wl1271_cmd_sched_scan_start *start;
673 int ret = 0; 699 int ret = 0;
674 700
675 wl1271_debug(DEBUG_CMD, "cmd periodic scan start"); 701 wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
676 702
677 if (wl->bss_type != BSS_TYPE_STA_BSS) 703 if (wlvif->bss_type != BSS_TYPE_STA_BSS)
678 return -EOPNOTSUPP; 704 return -EOPNOTSUPP;
679 705
680 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags)) 706 if (!test_bit(WL1271_FLAG_IDLE, &wl->flags))
diff --git a/drivers/net/wireless/wl12xx/scan.h b/drivers/net/wireless/wl12xx/scan.h
index 92115156522f..a7ed43dc08c9 100644
--- a/drivers/net/wireless/wl12xx/scan.h
+++ b/drivers/net/wireless/wl12xx/scan.h
@@ -26,18 +26,20 @@
26 26
27#include "wl12xx.h" 27#include "wl12xx.h"
28 28
29int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, 29int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
30 const u8 *ssid, size_t ssid_len,
30 struct cfg80211_scan_request *req); 31 struct cfg80211_scan_request *req);
31int wl1271_scan_stop(struct wl1271 *wl); 32int wl1271_scan_stop(struct wl1271 *wl);
32int wl1271_scan_build_probe_req(struct wl1271 *wl, 33int wl1271_scan_build_probe_req(struct wl1271 *wl,
33 const u8 *ssid, size_t ssid_len, 34 const u8 *ssid, size_t ssid_len,
34 const u8 *ie, size_t ie_len, u8 band); 35 const u8 *ie, size_t ie_len, u8 band);
35void wl1271_scan_stm(struct wl1271 *wl); 36void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif);
36void wl1271_scan_complete_work(struct work_struct *work); 37void wl1271_scan_complete_work(struct work_struct *work);
37int wl1271_scan_sched_scan_config(struct wl1271 *wl, 38int wl1271_scan_sched_scan_config(struct wl1271 *wl,
39 struct wl12xx_vif *wlvif,
38 struct cfg80211_sched_scan_request *req, 40 struct cfg80211_sched_scan_request *req,
39 struct ieee80211_sched_scan_ies *ies); 41 struct ieee80211_sched_scan_ies *ies);
40int wl1271_scan_sched_scan_start(struct wl1271 *wl); 42int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
41void wl1271_scan_sched_scan_stop(struct wl1271 *wl); 43void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
42void wl1271_scan_sched_scan_results(struct wl1271 *wl); 44void wl1271_scan_sched_scan_results(struct wl1271 *wl);
43 45
diff --git a/drivers/net/wireless/wl12xx/sdio.c b/drivers/net/wireless/wl12xx/sdio.c
index 516a8980723c..468a50553fac 100644
--- a/drivers/net/wireless/wl12xx/sdio.c
+++ b/drivers/net/wireless/wl12xx/sdio.c
@@ -24,6 +24,7 @@
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/platform_device.h>
27#include <linux/mmc/sdio_func.h> 28#include <linux/mmc/sdio_func.h>
28#include <linux/mmc/sdio_ids.h> 29#include <linux/mmc/sdio_ids.h>
29#include <linux/mmc/card.h> 30#include <linux/mmc/card.h>
@@ -44,107 +45,67 @@
44#define SDIO_DEVICE_ID_TI_WL1271 0x4076 45#define SDIO_DEVICE_ID_TI_WL1271 0x4076
45#endif 46#endif
46 47
48struct wl12xx_sdio_glue {
49 struct device *dev;
50 struct platform_device *core;
51};
52
47static const struct sdio_device_id wl1271_devices[] __devinitconst = { 53static const struct sdio_device_id wl1271_devices[] __devinitconst = {
48 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) }, 54 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
49 {} 55 {}
50}; 56};
51MODULE_DEVICE_TABLE(sdio, wl1271_devices); 57MODULE_DEVICE_TABLE(sdio, wl1271_devices);
52 58
53static void wl1271_sdio_set_block_size(struct wl1271 *wl, unsigned int blksz) 59static void wl1271_sdio_set_block_size(struct device *child,
54{ 60 unsigned int blksz)
55 sdio_claim_host(wl->if_priv);
56 sdio_set_block_size(wl->if_priv, blksz);
57 sdio_release_host(wl->if_priv);
58}
59
60static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
61{
62 return wl->if_priv;
63}
64
65static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
66{
67 return &(wl_to_func(wl)->dev);
68}
69
70static irqreturn_t wl1271_hardirq(int irq, void *cookie)
71{ 61{
72 struct wl1271 *wl = cookie; 62 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
73 unsigned long flags; 63 struct sdio_func *func = dev_to_sdio_func(glue->dev);
74 64
75 wl1271_debug(DEBUG_IRQ, "IRQ"); 65 sdio_claim_host(func);
76 66 sdio_set_block_size(func, blksz);
77 /* complete the ELP completion */ 67 sdio_release_host(func);
78 spin_lock_irqsave(&wl->wl_lock, flags);
79 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
80 if (wl->elp_compl) {
81 complete(wl->elp_compl);
82 wl->elp_compl = NULL;
83 }
84
85 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
86 /* don't enqueue a work right now. mark it as pending */
87 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
88 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
89 disable_irq_nosync(wl->irq);
90 pm_wakeup_event(wl1271_sdio_wl_to_dev(wl), 0);
91 spin_unlock_irqrestore(&wl->wl_lock, flags);
92 return IRQ_HANDLED;
93 }
94 spin_unlock_irqrestore(&wl->wl_lock, flags);
95
96 return IRQ_WAKE_THREAD;
97}
98
99static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
100{
101 disable_irq(wl->irq);
102}
103
104static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
105{
106 enable_irq(wl->irq);
107} 68}
108 69
109static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf, 70static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
110 size_t len, bool fixed) 71 size_t len, bool fixed)
111{ 72{
112 int ret; 73 int ret;
113 struct sdio_func *func = wl_to_func(wl); 74 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
75 struct sdio_func *func = dev_to_sdio_func(glue->dev);
114 76
115 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 77 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
116 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); 78 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
117 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x", 79 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
118 addr, ((u8 *)buf)[0]); 80 addr, ((u8 *)buf)[0]);
119 } else { 81 } else {
120 if (fixed) 82 if (fixed)
121 ret = sdio_readsb(func, buf, addr, len); 83 ret = sdio_readsb(func, buf, addr, len);
122 else 84 else
123 ret = sdio_memcpy_fromio(func, buf, addr, len); 85 ret = sdio_memcpy_fromio(func, buf, addr, len);
124 86
125 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes", 87 dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
126 addr, len); 88 addr, len);
127 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
128 } 89 }
129 90
130 if (ret) 91 if (ret)
131 wl1271_error("sdio read failed (%d)", ret); 92 dev_err(child->parent, "sdio read failed (%d)\n", ret);
132} 93}
133 94
134static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf, 95static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
135 size_t len, bool fixed) 96 size_t len, bool fixed)
136{ 97{
137 int ret; 98 int ret;
138 struct sdio_func *func = wl_to_func(wl); 99 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
100 struct sdio_func *func = dev_to_sdio_func(glue->dev);
139 101
140 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) { 102 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
141 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); 103 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
142 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x", 104 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
143 addr, ((u8 *)buf)[0]); 105 addr, ((u8 *)buf)[0]);
144 } else { 106 } else {
145 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes", 107 dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
146 addr, len); 108 addr, len);
147 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
148 109
149 if (fixed) 110 if (fixed)
150 ret = sdio_writesb(func, addr, buf, len); 111 ret = sdio_writesb(func, addr, buf, len);
@@ -153,13 +114,13 @@ static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
153 } 114 }
154 115
155 if (ret) 116 if (ret)
156 wl1271_error("sdio write failed (%d)", ret); 117 dev_err(child->parent, "sdio write failed (%d)\n", ret);
157} 118}
158 119
159static int wl1271_sdio_power_on(struct wl1271 *wl) 120static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
160{ 121{
161 struct sdio_func *func = wl_to_func(wl);
162 int ret; 122 int ret;
123 struct sdio_func *func = dev_to_sdio_func(glue->dev);
163 124
164 /* If enabled, tell runtime PM not to power off the card */ 125 /* If enabled, tell runtime PM not to power off the card */
165 if (pm_runtime_enabled(&func->dev)) { 126 if (pm_runtime_enabled(&func->dev)) {
@@ -180,10 +141,10 @@ out:
180 return ret; 141 return ret;
181} 142}
182 143
183static int wl1271_sdio_power_off(struct wl1271 *wl) 144static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
184{ 145{
185 struct sdio_func *func = wl_to_func(wl);
186 int ret; 146 int ret;
147 struct sdio_func *func = dev_to_sdio_func(glue->dev);
187 148
188 sdio_disable_func(func); 149 sdio_disable_func(func);
189 sdio_release_host(func); 150 sdio_release_host(func);
@@ -200,46 +161,43 @@ static int wl1271_sdio_power_off(struct wl1271 *wl)
200 return ret; 161 return ret;
201} 162}
202 163
203static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable) 164static int wl12xx_sdio_set_power(struct device *child, bool enable)
204{ 165{
166 struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
167
205 if (enable) 168 if (enable)
206 return wl1271_sdio_power_on(wl); 169 return wl12xx_sdio_power_on(glue);
207 else 170 else
208 return wl1271_sdio_power_off(wl); 171 return wl12xx_sdio_power_off(glue);
209} 172}
210 173
211static struct wl1271_if_operations sdio_ops = { 174static struct wl1271_if_operations sdio_ops = {
212 .read = wl1271_sdio_raw_read, 175 .read = wl12xx_sdio_raw_read,
213 .write = wl1271_sdio_raw_write, 176 .write = wl12xx_sdio_raw_write,
214 .power = wl1271_sdio_set_power, 177 .power = wl12xx_sdio_set_power,
215 .dev = wl1271_sdio_wl_to_dev,
216 .enable_irq = wl1271_sdio_enable_interrupts,
217 .disable_irq = wl1271_sdio_disable_interrupts,
218 .set_block_size = wl1271_sdio_set_block_size, 178 .set_block_size = wl1271_sdio_set_block_size,
219}; 179};
220 180
221static int __devinit wl1271_probe(struct sdio_func *func, 181static int __devinit wl1271_probe(struct sdio_func *func,
222 const struct sdio_device_id *id) 182 const struct sdio_device_id *id)
223{ 183{
224 struct ieee80211_hw *hw; 184 struct wl12xx_platform_data *wlan_data;
225 const struct wl12xx_platform_data *wlan_data; 185 struct wl12xx_sdio_glue *glue;
226 struct wl1271 *wl; 186 struct resource res[1];
227 unsigned long irqflags;
228 mmc_pm_flag_t mmcflags; 187 mmc_pm_flag_t mmcflags;
229 int ret; 188 int ret = -ENOMEM;
230 189
231 /* We are only able to handle the wlan function */ 190 /* We are only able to handle the wlan function */
232 if (func->num != 0x02) 191 if (func->num != 0x02)
233 return -ENODEV; 192 return -ENODEV;
234 193
235 hw = wl1271_alloc_hw(); 194 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
236 if (IS_ERR(hw)) 195 if (!glue) {
237 return PTR_ERR(hw); 196 dev_err(&func->dev, "can't allocate glue\n");
238 197 goto out;
239 wl = hw->priv; 198 }
240 199
241 wl->if_priv = func; 200 glue->dev = &func->dev;
242 wl->if_ops = &sdio_ops;
243 201
244 /* Grab access to FN0 for ELP reg. */ 202 /* Grab access to FN0 for ELP reg. */
245 func->card->quirks |= MMC_QUIRK_LENIENT_FN0; 203 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
@@ -250,80 +208,79 @@ static int __devinit wl1271_probe(struct sdio_func *func,
250 wlan_data = wl12xx_get_platform_data(); 208 wlan_data = wl12xx_get_platform_data();
251 if (IS_ERR(wlan_data)) { 209 if (IS_ERR(wlan_data)) {
252 ret = PTR_ERR(wlan_data); 210 ret = PTR_ERR(wlan_data);
253 wl1271_error("missing wlan platform data: %d", ret); 211 dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
254 goto out_free; 212 goto out_free_glue;
255 } 213 }
256 214
257 wl->irq = wlan_data->irq; 215 /* if sdio can keep power while host is suspended, enable wow */
258 wl->ref_clock = wlan_data->board_ref_clock; 216 mmcflags = sdio_get_host_pm_caps(func);
259 wl->tcxo_clock = wlan_data->board_tcxo_clock; 217 dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
260 wl->platform_quirks = wlan_data->platform_quirks;
261 218
262 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 219 if (mmcflags & MMC_PM_KEEP_POWER)
263 irqflags = IRQF_TRIGGER_RISING; 220 wlan_data->pwr_in_suspend = true;
264 else 221
265 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT; 222 wlan_data->ops = &sdio_ops;
266
267 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq,
268 irqflags,
269 DRIVER_NAME, wl);
270 if (ret < 0) {
271 wl1271_error("request_irq() failed: %d", ret);
272 goto out_free;
273 }
274 223
275 ret = enable_irq_wake(wl->irq); 224 sdio_set_drvdata(func, glue);
276 if (!ret) {
277 wl->irq_wake_enabled = true;
278 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 1);
279 225
280 /* if sdio can keep power while host is suspended, enable wow */ 226 /* Tell PM core that we don't need the card to be powered now */
281 mmcflags = sdio_get_host_pm_caps(func); 227 pm_runtime_put_noidle(&func->dev);
282 wl1271_debug(DEBUG_SDIO, "sdio PM caps = 0x%x", mmcflags);
283 228
284 if (mmcflags & MMC_PM_KEEP_POWER) 229 glue->core = platform_device_alloc("wl12xx", -1);
285 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY; 230 if (!glue->core) {
231 dev_err(glue->dev, "can't allocate platform_device");
232 ret = -ENOMEM;
233 goto out_free_glue;
286 } 234 }
287 disable_irq(wl->irq);
288 235
289 ret = wl1271_init_ieee80211(wl); 236 glue->core->dev.parent = &func->dev;
290 if (ret)
291 goto out_irq;
292 237
293 ret = wl1271_register_hw(wl); 238 memset(res, 0x00, sizeof(res));
294 if (ret)
295 goto out_irq;
296 239
297 sdio_set_drvdata(func, wl); 240 res[0].start = wlan_data->irq;
241 res[0].flags = IORESOURCE_IRQ;
242 res[0].name = "irq";
298 243
299 /* Tell PM core that we don't need the card to be powered now */ 244 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
300 pm_runtime_put_noidle(&func->dev); 245 if (ret) {
246 dev_err(glue->dev, "can't add resources\n");
247 goto out_dev_put;
248 }
301 249
250 ret = platform_device_add_data(glue->core, wlan_data,
251 sizeof(*wlan_data));
252 if (ret) {
253 dev_err(glue->dev, "can't add platform data\n");
254 goto out_dev_put;
255 }
256
257 ret = platform_device_add(glue->core);
258 if (ret) {
259 dev_err(glue->dev, "can't add platform device\n");
260 goto out_dev_put;
261 }
302 return 0; 262 return 0;
303 263
304 out_irq: 264out_dev_put:
305 free_irq(wl->irq, wl); 265 platform_device_put(glue->core);
306 266
307 out_free: 267out_free_glue:
308 wl1271_free_hw(wl); 268 kfree(glue);
309 269
270out:
310 return ret; 271 return ret;
311} 272}
312 273
313static void __devexit wl1271_remove(struct sdio_func *func) 274static void __devexit wl1271_remove(struct sdio_func *func)
314{ 275{
315 struct wl1271 *wl = sdio_get_drvdata(func); 276 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
316 277
317 /* Undo decrement done above in wl1271_probe */ 278 /* Undo decrement done above in wl1271_probe */
318 pm_runtime_get_noresume(&func->dev); 279 pm_runtime_get_noresume(&func->dev);
319 280
320 wl1271_unregister_hw(wl); 281 platform_device_del(glue->core);
321 if (wl->irq_wake_enabled) { 282 platform_device_put(glue->core);
322 device_init_wakeup(wl1271_sdio_wl_to_dev(wl), 0); 283 kfree(glue);
323 disable_irq_wake(wl->irq);
324 }
325 free_irq(wl->irq, wl);
326 wl1271_free_hw(wl);
327} 284}
328 285
329#ifdef CONFIG_PM 286#ifdef CONFIG_PM
@@ -332,20 +289,21 @@ static int wl1271_suspend(struct device *dev)
332 /* Tell MMC/SDIO core it's OK to power down the card 289 /* Tell MMC/SDIO core it's OK to power down the card
333 * (if it isn't already), but not to remove it completely */ 290 * (if it isn't already), but not to remove it completely */
334 struct sdio_func *func = dev_to_sdio_func(dev); 291 struct sdio_func *func = dev_to_sdio_func(dev);
335 struct wl1271 *wl = sdio_get_drvdata(func); 292 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
293 struct wl1271 *wl = platform_get_drvdata(glue->core);
336 mmc_pm_flag_t sdio_flags; 294 mmc_pm_flag_t sdio_flags;
337 int ret = 0; 295 int ret = 0;
338 296
339 wl1271_debug(DEBUG_MAC80211, "wl1271 suspend. wow_enabled: %d", 297 dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
340 wl->wow_enabled); 298 wl->wow_enabled);
341 299
342 /* check whether sdio should keep power */ 300 /* check whether sdio should keep power */
343 if (wl->wow_enabled) { 301 if (wl->wow_enabled) {
344 sdio_flags = sdio_get_host_pm_caps(func); 302 sdio_flags = sdio_get_host_pm_caps(func);
345 303
346 if (!(sdio_flags & MMC_PM_KEEP_POWER)) { 304 if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
347 wl1271_error("can't keep power while host " 305 dev_err(dev, "can't keep power while host "
348 "is suspended"); 306 "is suspended\n");
349 ret = -EINVAL; 307 ret = -EINVAL;
350 goto out; 308 goto out;
351 } 309 }
@@ -353,7 +311,7 @@ static int wl1271_suspend(struct device *dev)
353 /* keep power while host suspended */ 311 /* keep power while host suspended */
354 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); 312 ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
355 if (ret) { 313 if (ret) {
356 wl1271_error("error while trying to keep power"); 314 dev_err(dev, "error while trying to keep power\n");
357 goto out; 315 goto out;
358 } 316 }
359 317
@@ -367,9 +325,10 @@ out:
367static int wl1271_resume(struct device *dev) 325static int wl1271_resume(struct device *dev)
368{ 326{
369 struct sdio_func *func = dev_to_sdio_func(dev); 327 struct sdio_func *func = dev_to_sdio_func(dev);
370 struct wl1271 *wl = sdio_get_drvdata(func); 328 struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
329 struct wl1271 *wl = platform_get_drvdata(glue->core);
371 330
372 wl1271_debug(DEBUG_MAC80211, "wl1271 resume"); 331 dev_dbg(dev, "wl1271 resume\n");
373 if (wl->wow_enabled) { 332 if (wl->wow_enabled) {
374 /* claim back host */ 333 /* claim back host */
375 sdio_claim_host(func); 334 sdio_claim_host(func);
diff --git a/drivers/net/wireless/wl12xx/sdio_test.c b/drivers/net/wireless/wl12xx/sdio_test.c
deleted file mode 100644
index f25d5d9212e7..000000000000
--- a/drivers/net/wireless/wl12xx/sdio_test.c
+++ /dev/null
@@ -1,543 +0,0 @@
1/*
2 * SDIO testing driver for wl12xx
3 *
4 * Copyright (C) 2010 Nokia Corporation
5 *
6 * Contact: Roger Quadros <roger.quadros@nokia.com>
7 *
8 * wl12xx read/write routines taken from the main module
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 *
24 */
25
26#include <linux/irq.h>
27#include <linux/module.h>
28#include <linux/crc7.h>
29#include <linux/vmalloc.h>
30#include <linux/mmc/sdio_func.h>
31#include <linux/mmc/sdio_ids.h>
32#include <linux/mmc/card.h>
33#include <linux/mmc/host.h>
34#include <linux/gpio.h>
35#include <linux/wl12xx.h>
36#include <linux/kthread.h>
37#include <linux/firmware.h>
38#include <linux/pm_runtime.h>
39
40#include "wl12xx.h"
41#include "io.h"
42#include "boot.h"
43
44#ifndef SDIO_VENDOR_ID_TI
45#define SDIO_VENDOR_ID_TI 0x0097
46#endif
47
48#ifndef SDIO_DEVICE_ID_TI_WL1271
49#define SDIO_DEVICE_ID_TI_WL1271 0x4076
50#endif
51
52static bool rx, tx;
53
54module_param(rx, bool, S_IRUGO | S_IWUSR);
55MODULE_PARM_DESC(rx, "Perform rx test. Default (0). "
56 "This test continuously reads data from the SDIO device.\n");
57
58module_param(tx, bool, S_IRUGO | S_IWUSR);
59MODULE_PARM_DESC(tx, "Perform tx test. Default (0). "
60 "This test continuously writes data to the SDIO device.\n");
61
62struct wl1271_test {
63 struct wl1271 wl;
64 struct task_struct *test_task;
65};
66
67static const struct sdio_device_id wl1271_devices[] = {
68 { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
69 {}
70};
71
72static inline struct sdio_func *wl_to_func(struct wl1271 *wl)
73{
74 return wl->if_priv;
75}
76
77static struct device *wl1271_sdio_wl_to_dev(struct wl1271 *wl)
78{
79 return &(wl_to_func(wl)->dev);
80}
81
82static void wl1271_sdio_raw_read(struct wl1271 *wl, int addr, void *buf,
83 size_t len, bool fixed)
84{
85 int ret = 0;
86 struct sdio_func *func = wl_to_func(wl);
87
88 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
89 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
90 wl1271_debug(DEBUG_SDIO, "sdio read 52 addr 0x%x, byte 0x%02x",
91 addr, ((u8 *)buf)[0]);
92 } else {
93 if (fixed)
94 ret = sdio_readsb(func, buf, addr, len);
95 else
96 ret = sdio_memcpy_fromio(func, buf, addr, len);
97
98 wl1271_debug(DEBUG_SDIO, "sdio read 53 addr 0x%x, %zu bytes",
99 addr, len);
100 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
101 }
102
103 if (ret)
104 wl1271_error("sdio read failed (%d)", ret);
105}
106
107static void wl1271_sdio_raw_write(struct wl1271 *wl, int addr, void *buf,
108 size_t len, bool fixed)
109{
110 int ret = 0;
111 struct sdio_func *func = wl_to_func(wl);
112
113 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
114 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
115 wl1271_debug(DEBUG_SDIO, "sdio write 52 addr 0x%x, byte 0x%02x",
116 addr, ((u8 *)buf)[0]);
117 } else {
118 wl1271_debug(DEBUG_SDIO, "sdio write 53 addr 0x%x, %zu bytes",
119 addr, len);
120 wl1271_dump_ascii(DEBUG_SDIO, "data: ", buf, len);
121
122 if (fixed)
123 ret = sdio_writesb(func, addr, buf, len);
124 else
125 ret = sdio_memcpy_toio(func, addr, buf, len);
126 }
127 if (ret)
128 wl1271_error("sdio write failed (%d)", ret);
129
130}
131
132static int wl1271_sdio_set_power(struct wl1271 *wl, bool enable)
133{
134 struct sdio_func *func = wl_to_func(wl);
135 int ret;
136
137 /* Let the SDIO stack handle wlan_enable control, so we
138 * keep host claimed while wlan is in use to keep wl1271
139 * alive.
140 */
141 if (enable) {
142 /* Power up the card */
143 ret = pm_runtime_get_sync(&func->dev);
144 if (ret < 0)
145 goto out;
146
147 /* Runtime PM might be disabled, power up the card manually */
148 ret = mmc_power_restore_host(func->card->host);
149 if (ret < 0)
150 goto out;
151
152 sdio_claim_host(func);
153 sdio_enable_func(func);
154 } else {
155 sdio_disable_func(func);
156 sdio_release_host(func);
157
158 /* Runtime PM might be disabled, power off the card manually */
159 ret = mmc_power_save_host(func->card->host);
160 if (ret < 0)
161 goto out;
162
163 /* Power down the card */
164 ret = pm_runtime_put_sync(&func->dev);
165 }
166
167out:
168 return ret;
169}
170
171static void wl1271_sdio_disable_interrupts(struct wl1271 *wl)
172{
173}
174
175static void wl1271_sdio_enable_interrupts(struct wl1271 *wl)
176{
177}
178
179
180static struct wl1271_if_operations sdio_ops = {
181 .read = wl1271_sdio_raw_read,
182 .write = wl1271_sdio_raw_write,
183 .power = wl1271_sdio_set_power,
184 .dev = wl1271_sdio_wl_to_dev,
185 .enable_irq = wl1271_sdio_enable_interrupts,
186 .disable_irq = wl1271_sdio_disable_interrupts,
187};
188
189static void wl1271_fw_wakeup(struct wl1271 *wl)
190{
191 u32 elp_reg;
192
193 elp_reg = ELPCTRL_WAKE_UP;
194 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
195}
196
197static int wl1271_fetch_firmware(struct wl1271 *wl)
198{
199 const struct firmware *fw;
200 int ret;
201
202 if (wl->chip.id == CHIP_ID_1283_PG20)
203 ret = request_firmware(&fw, WL128X_FW_NAME,
204 wl1271_wl_to_dev(wl));
205 else
206 ret = request_firmware(&fw, WL127X_FW_NAME,
207 wl1271_wl_to_dev(wl));
208
209 if (ret < 0) {
210 wl1271_error("could not get firmware: %d", ret);
211 return ret;
212 }
213
214 if (fw->size % 4) {
215 wl1271_error("firmware size is not multiple of 32 bits: %zu",
216 fw->size);
217 ret = -EILSEQ;
218 goto out;
219 }
220
221 wl->fw_len = fw->size;
222 wl->fw = vmalloc(wl->fw_len);
223
224 if (!wl->fw) {
225 wl1271_error("could not allocate memory for the firmware");
226 ret = -ENOMEM;
227 goto out;
228 }
229
230 memcpy(wl->fw, fw->data, wl->fw_len);
231
232 ret = 0;
233
234out:
235 release_firmware(fw);
236
237 return ret;
238}
239
240static int wl1271_fetch_nvs(struct wl1271 *wl)
241{
242 const struct firmware *fw;
243 int ret;
244
245 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
246
247 if (ret < 0) {
248 wl1271_error("could not get nvs file: %d", ret);
249 return ret;
250 }
251
252 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
253
254 if (!wl->nvs) {
255 wl1271_error("could not allocate memory for the nvs file");
256 ret = -ENOMEM;
257 goto out;
258 }
259
260 wl->nvs_len = fw->size;
261
262out:
263 release_firmware(fw);
264
265 return ret;
266}
267
268static int wl1271_chip_wakeup(struct wl1271 *wl)
269{
270 struct wl1271_partition_set partition;
271 int ret;
272
273 msleep(WL1271_PRE_POWER_ON_SLEEP);
274 ret = wl1271_power_on(wl);
275 if (ret)
276 return ret;
277
278 msleep(WL1271_POWER_ON_SLEEP);
279
280 /* We don't need a real memory partition here, because we only want
281 * to use the registers at this point. */
282 memset(&partition, 0, sizeof(partition));
283 partition.reg.start = REGISTERS_BASE;
284 partition.reg.size = REGISTERS_DOWN_SIZE;
285 wl1271_set_partition(wl, &partition);
286
287 /* ELP module wake up */
288 wl1271_fw_wakeup(wl);
289
290 /* whal_FwCtrl_BootSm() */
291
292 /* 0. read chip id from CHIP_ID */
293 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
294
295 /* 1. check if chip id is valid */
296
297 switch (wl->chip.id) {
298 case CHIP_ID_1271_PG10:
299 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
300 wl->chip.id);
301 break;
302 case CHIP_ID_1271_PG20:
303 wl1271_notice("chip id 0x%x (1271 PG20)",
304 wl->chip.id);
305 break;
306 case CHIP_ID_1283_PG20:
307 wl1271_notice("chip id 0x%x (1283 PG20)",
308 wl->chip.id);
309 break;
310 case CHIP_ID_1283_PG10:
311 default:
312 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
313 return -ENODEV;
314 }
315
316 return ret;
317}
318
319static struct wl1271_partition_set part_down = {
320 .mem = {
321 .start = 0x00000000,
322 .size = 0x000177c0
323 },
324 .reg = {
325 .start = REGISTERS_BASE,
326 .size = 0x00008800
327 },
328 .mem2 = {
329 .start = 0x00000000,
330 .size = 0x00000000
331 },
332 .mem3 = {
333 .start = 0x00000000,
334 .size = 0x00000000
335 },
336};
337
338static int tester(void *data)
339{
340 struct wl1271 *wl = data;
341 struct sdio_func *func = wl_to_func(wl);
342 struct device *pdev = &func->dev;
343 int ret = 0;
344 bool rx_started = 0;
345 bool tx_started = 0;
346 uint8_t *tx_buf, *rx_buf;
347 int test_size = PAGE_SIZE;
348 u32 addr = 0;
349 struct wl1271_partition_set partition;
350
351 /* We assume chip is powered up and firmware fetched */
352
353 memcpy(&partition, &part_down, sizeof(partition));
354 partition.mem.start = addr;
355 wl1271_set_partition(wl, &partition);
356
357 tx_buf = kmalloc(test_size, GFP_KERNEL);
358 rx_buf = kmalloc(test_size, GFP_KERNEL);
359 if (!tx_buf || !rx_buf) {
360 dev_err(pdev,
361 "Could not allocate memory. Test will not run.\n");
362 ret = -ENOMEM;
363 goto free;
364 }
365
366 memset(tx_buf, 0x5a, test_size);
367
368 /* write something in data area so we can read it back */
369 wl1271_write(wl, addr, tx_buf, test_size, false);
370
371 while (!kthread_should_stop()) {
372 if (rx && !rx_started) {
373 dev_info(pdev, "starting rx test\n");
374 rx_started = 1;
375 } else if (!rx && rx_started) {
376 dev_info(pdev, "stopping rx test\n");
377 rx_started = 0;
378 }
379
380 if (tx && !tx_started) {
381 dev_info(pdev, "starting tx test\n");
382 tx_started = 1;
383 } else if (!tx && tx_started) {
384 dev_info(pdev, "stopping tx test\n");
385 tx_started = 0;
386 }
387
388 if (rx_started)
389 wl1271_read(wl, addr, rx_buf, test_size, false);
390
391 if (tx_started)
392 wl1271_write(wl, addr, tx_buf, test_size, false);
393
394 if (!rx_started && !tx_started)
395 msleep(100);
396 }
397
398free:
399 kfree(tx_buf);
400 kfree(rx_buf);
401 return ret;
402}
403
404static int __devinit wl1271_probe(struct sdio_func *func,
405 const struct sdio_device_id *id)
406{
407 const struct wl12xx_platform_data *wlan_data;
408 struct wl1271 *wl;
409 struct wl1271_test *wl_test;
410 int ret = 0;
411
412 /* wl1271 has 2 sdio functions we handle just the wlan part */
413 if (func->num != 0x02)
414 return -ENODEV;
415
416 wl_test = kzalloc(sizeof(struct wl1271_test), GFP_KERNEL);
417 if (!wl_test) {
418 dev_err(&func->dev, "Could not allocate memory\n");
419 return -ENOMEM;
420 }
421
422 wl = &wl_test->wl;
423
424 wl->if_priv = func;
425 wl->if_ops = &sdio_ops;
426
427 /* Grab access to FN0 for ELP reg. */
428 func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
429
430 /* Use block mode for transferring over one block size of data */
431 func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
432
433 wlan_data = wl12xx_get_platform_data();
434 if (IS_ERR(wlan_data)) {
435 ret = PTR_ERR(wlan_data);
436 dev_err(&func->dev, "missing wlan platform data: %d\n", ret);
437 goto out_free;
438 }
439
440 wl->irq = wlan_data->irq;
441 wl->ref_clock = wlan_data->board_ref_clock;
442 wl->tcxo_clock = wlan_data->board_tcxo_clock;
443
444 sdio_set_drvdata(func, wl_test);
445
446 /* power up the device */
447 ret = wl1271_chip_wakeup(wl);
448 if (ret) {
449 dev_err(&func->dev, "could not wake up chip\n");
450 goto out_free;
451 }
452
453 if (wl->fw == NULL) {
454 ret = wl1271_fetch_firmware(wl);
455 if (ret < 0) {
456 dev_err(&func->dev, "firmware fetch error\n");
457 goto out_off;
458 }
459 }
460
461 /* fetch NVS */
462 if (wl->nvs == NULL) {
463 ret = wl1271_fetch_nvs(wl);
464 if (ret < 0) {
465 dev_err(&func->dev, "NVS fetch error\n");
466 goto out_off;
467 }
468 }
469
470 ret = wl1271_load_firmware(wl);
471 if (ret < 0) {
472 dev_err(&func->dev, "firmware load error: %d\n", ret);
473 goto out_free;
474 }
475
476 dev_info(&func->dev, "initialized\n");
477
478 /* I/O testing will be done in the tester thread */
479
480 wl_test->test_task = kthread_run(tester, wl, "sdio_tester");
481 if (IS_ERR(wl_test->test_task)) {
482 dev_err(&func->dev, "unable to create kernel thread\n");
483 ret = PTR_ERR(wl_test->test_task);
484 goto out_free;
485 }
486
487 return 0;
488
489out_off:
490 /* power off the chip */
491 wl1271_power_off(wl);
492
493out_free:
494 kfree(wl_test);
495 return ret;
496}
497
498static void __devexit wl1271_remove(struct sdio_func *func)
499{
500 struct wl1271_test *wl_test = sdio_get_drvdata(func);
501
502 /* stop the I/O test thread */
503 kthread_stop(wl_test->test_task);
504
505 /* power off the chip */
506 wl1271_power_off(&wl_test->wl);
507
508 vfree(wl_test->wl.fw);
509 wl_test->wl.fw = NULL;
510 kfree(wl_test->wl.nvs);
511 wl_test->wl.nvs = NULL;
512
513 kfree(wl_test);
514}
515
516static struct sdio_driver wl1271_sdio_driver = {
517 .name = "wl12xx_sdio_test",
518 .id_table = wl1271_devices,
519 .probe = wl1271_probe,
520 .remove = __devexit_p(wl1271_remove),
521};
522
523static int __init wl1271_init(void)
524{
525 int ret;
526
527 ret = sdio_register_driver(&wl1271_sdio_driver);
528 if (ret < 0)
529 pr_err("failed to register sdio driver: %d\n", ret);
530
531 return ret;
532}
533module_init(wl1271_init);
534
535static void __exit wl1271_exit(void)
536{
537 sdio_unregister_driver(&wl1271_sdio_driver);
538}
539module_exit(wl1271_exit);
540
541MODULE_LICENSE("GPL");
542MODULE_AUTHOR("Roger Quadros <roger.quadros@nokia.com>");
543
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
index 12421a64d891..92caa7ce6053 100644
--- a/drivers/net/wireless/wl12xx/spi.c
+++ b/drivers/net/wireless/wl12xx/spi.c
@@ -27,6 +27,7 @@
27#include <linux/crc7.h> 27#include <linux/crc7.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/wl12xx.h> 29#include <linux/wl12xx.h>
30#include <linux/platform_device.h>
30#include <linux/slab.h> 31#include <linux/slab.h>
31 32
32#include "wl12xx.h" 33#include "wl12xx.h"
@@ -69,35 +70,22 @@
69 70
70#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE) 71#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
71 72
72static inline struct spi_device *wl_to_spi(struct wl1271 *wl) 73struct wl12xx_spi_glue {
73{ 74 struct device *dev;
74 return wl->if_priv; 75 struct platform_device *core;
75} 76};
76
77static struct device *wl1271_spi_wl_to_dev(struct wl1271 *wl)
78{
79 return &(wl_to_spi(wl)->dev);
80}
81
82static void wl1271_spi_disable_interrupts(struct wl1271 *wl)
83{
84 disable_irq(wl->irq);
85}
86
87static void wl1271_spi_enable_interrupts(struct wl1271 *wl)
88{
89 enable_irq(wl->irq);
90}
91 77
92static void wl1271_spi_reset(struct wl1271 *wl) 78static void wl12xx_spi_reset(struct device *child)
93{ 79{
80 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
94 u8 *cmd; 81 u8 *cmd;
95 struct spi_transfer t; 82 struct spi_transfer t;
96 struct spi_message m; 83 struct spi_message m;
97 84
98 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 85 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
99 if (!cmd) { 86 if (!cmd) {
100 wl1271_error("could not allocate cmd for spi reset"); 87 dev_err(child->parent,
88 "could not allocate cmd for spi reset\n");
101 return; 89 return;
102 } 90 }
103 91
@@ -110,21 +98,22 @@ static void wl1271_spi_reset(struct wl1271 *wl)
110 t.len = WSPI_INIT_CMD_LEN; 98 t.len = WSPI_INIT_CMD_LEN;
111 spi_message_add_tail(&t, &m); 99 spi_message_add_tail(&t, &m);
112 100
113 spi_sync(wl_to_spi(wl), &m); 101 spi_sync(to_spi_device(glue->dev), &m);
114 102
115 wl1271_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
116 kfree(cmd); 103 kfree(cmd);
117} 104}
118 105
119static void wl1271_spi_init(struct wl1271 *wl) 106static void wl12xx_spi_init(struct device *child)
120{ 107{
108 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
121 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd; 109 u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
122 struct spi_transfer t; 110 struct spi_transfer t;
123 struct spi_message m; 111 struct spi_message m;
124 112
125 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL); 113 cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
126 if (!cmd) { 114 if (!cmd) {
127 wl1271_error("could not allocate cmd for spi init"); 115 dev_err(child->parent,
116 "could not allocate cmd for spi init\n");
128 return; 117 return;
129 } 118 }
130 119
@@ -165,15 +154,16 @@ static void wl1271_spi_init(struct wl1271 *wl)
165 t.len = WSPI_INIT_CMD_LEN; 154 t.len = WSPI_INIT_CMD_LEN;
166 spi_message_add_tail(&t, &m); 155 spi_message_add_tail(&t, &m);
167 156
168 spi_sync(wl_to_spi(wl), &m); 157 spi_sync(to_spi_device(glue->dev), &m);
169 wl1271_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
170 kfree(cmd); 158 kfree(cmd);
171} 159}
172 160
173#define WL1271_BUSY_WORD_TIMEOUT 1000 161#define WL1271_BUSY_WORD_TIMEOUT 1000
174 162
175static int wl1271_spi_read_busy(struct wl1271 *wl) 163static int wl12xx_spi_read_busy(struct device *child)
176{ 164{
165 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
166 struct wl1271 *wl = dev_get_drvdata(child);
177 struct spi_transfer t[1]; 167 struct spi_transfer t[1];
178 struct spi_message m; 168 struct spi_message m;
179 u32 *busy_buf; 169 u32 *busy_buf;
@@ -194,20 +184,22 @@ static int wl1271_spi_read_busy(struct wl1271 *wl)
194 t[0].len = sizeof(u32); 184 t[0].len = sizeof(u32);
195 t[0].cs_change = true; 185 t[0].cs_change = true;
196 spi_message_add_tail(&t[0], &m); 186 spi_message_add_tail(&t[0], &m);
197 spi_sync(wl_to_spi(wl), &m); 187 spi_sync(to_spi_device(glue->dev), &m);
198 188
199 if (*busy_buf & 0x1) 189 if (*busy_buf & 0x1)
200 return 0; 190 return 0;
201 } 191 }
202 192
203 /* The SPI bus is unresponsive, the read failed. */ 193 /* The SPI bus is unresponsive, the read failed. */
204 wl1271_error("SPI read busy-word timeout!\n"); 194 dev_err(child->parent, "SPI read busy-word timeout!\n");
205 return -ETIMEDOUT; 195 return -ETIMEDOUT;
206} 196}
207 197
208static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf, 198static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
209 size_t len, bool fixed) 199 size_t len, bool fixed)
210{ 200{
201 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
202 struct wl1271 *wl = dev_get_drvdata(child);
211 struct spi_transfer t[2]; 203 struct spi_transfer t[2];
212 struct spi_message m; 204 struct spi_message m;
213 u32 *busy_buf; 205 u32 *busy_buf;
@@ -243,10 +235,10 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
243 t[1].cs_change = true; 235 t[1].cs_change = true;
244 spi_message_add_tail(&t[1], &m); 236 spi_message_add_tail(&t[1], &m);
245 237
246 spi_sync(wl_to_spi(wl), &m); 238 spi_sync(to_spi_device(glue->dev), &m);
247 239
248 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) && 240 if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
249 wl1271_spi_read_busy(wl)) { 241 wl12xx_spi_read_busy(child)) {
250 memset(buf, 0, chunk_len); 242 memset(buf, 0, chunk_len);
251 return; 243 return;
252 } 244 }
@@ -259,10 +251,7 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
259 t[0].cs_change = true; 251 t[0].cs_change = true;
260 spi_message_add_tail(&t[0], &m); 252 spi_message_add_tail(&t[0], &m);
261 253
262 spi_sync(wl_to_spi(wl), &m); 254 spi_sync(to_spi_device(glue->dev), &m);
263
264 wl1271_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
265 wl1271_dump(DEBUG_SPI, "spi_read buf <- ", buf, chunk_len);
266 255
267 if (!fixed) 256 if (!fixed)
268 addr += chunk_len; 257 addr += chunk_len;
@@ -271,9 +260,10 @@ static void wl1271_spi_raw_read(struct wl1271 *wl, int addr, void *buf,
271 } 260 }
272} 261}
273 262
274static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf, 263static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
275 size_t len, bool fixed) 264 size_t len, bool fixed)
276{ 265{
266 struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
277 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS]; 267 struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
278 struct spi_message m; 268 struct spi_message m;
279 u32 commands[WSPI_MAX_NUM_OF_CHUNKS]; 269 u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
@@ -308,9 +298,6 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
308 t[i].len = chunk_len; 298 t[i].len = chunk_len;
309 spi_message_add_tail(&t[i++], &m); 299 spi_message_add_tail(&t[i++], &m);
310 300
311 wl1271_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
312 wl1271_dump(DEBUG_SPI, "spi_write buf -> ", buf, chunk_len);
313
314 if (!fixed) 301 if (!fixed)
315 addr += chunk_len; 302 addr += chunk_len;
316 buf += chunk_len; 303 buf += chunk_len;
@@ -318,72 +305,41 @@ static void wl1271_spi_raw_write(struct wl1271 *wl, int addr, void *buf,
318 cmd++; 305 cmd++;
319 } 306 }
320 307
321 spi_sync(wl_to_spi(wl), &m); 308 spi_sync(to_spi_device(glue->dev), &m);
322}
323
324static irqreturn_t wl1271_hardirq(int irq, void *cookie)
325{
326 struct wl1271 *wl = cookie;
327 unsigned long flags;
328
329 wl1271_debug(DEBUG_IRQ, "IRQ");
330
331 /* complete the ELP completion */
332 spin_lock_irqsave(&wl->wl_lock, flags);
333 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
334 if (wl->elp_compl) {
335 complete(wl->elp_compl);
336 wl->elp_compl = NULL;
337 }
338 spin_unlock_irqrestore(&wl->wl_lock, flags);
339
340 return IRQ_WAKE_THREAD;
341}
342
343static int wl1271_spi_set_power(struct wl1271 *wl, bool enable)
344{
345 if (wl->set_power)
346 wl->set_power(enable);
347
348 return 0;
349} 309}
350 310
351static struct wl1271_if_operations spi_ops = { 311static struct wl1271_if_operations spi_ops = {
352 .read = wl1271_spi_raw_read, 312 .read = wl12xx_spi_raw_read,
353 .write = wl1271_spi_raw_write, 313 .write = wl12xx_spi_raw_write,
354 .reset = wl1271_spi_reset, 314 .reset = wl12xx_spi_reset,
355 .init = wl1271_spi_init, 315 .init = wl12xx_spi_init,
356 .power = wl1271_spi_set_power,
357 .dev = wl1271_spi_wl_to_dev,
358 .enable_irq = wl1271_spi_enable_interrupts,
359 .disable_irq = wl1271_spi_disable_interrupts,
360 .set_block_size = NULL, 316 .set_block_size = NULL,
361}; 317};
362 318
363static int __devinit wl1271_probe(struct spi_device *spi) 319static int __devinit wl1271_probe(struct spi_device *spi)
364{ 320{
321 struct wl12xx_spi_glue *glue;
365 struct wl12xx_platform_data *pdata; 322 struct wl12xx_platform_data *pdata;
366 struct ieee80211_hw *hw; 323 struct resource res[1];
367 struct wl1271 *wl; 324 int ret = -ENOMEM;
368 unsigned long irqflags;
369 int ret;
370 325
371 pdata = spi->dev.platform_data; 326 pdata = spi->dev.platform_data;
372 if (!pdata) { 327 if (!pdata) {
373 wl1271_error("no platform data"); 328 dev_err(&spi->dev, "no platform data\n");
374 return -ENODEV; 329 return -ENODEV;
375 } 330 }
376 331
377 hw = wl1271_alloc_hw(); 332 pdata->ops = &spi_ops;
378 if (IS_ERR(hw))
379 return PTR_ERR(hw);
380 333
381 wl = hw->priv; 334 glue = kzalloc(sizeof(*glue), GFP_KERNEL);
335 if (!glue) {
336 dev_err(&spi->dev, "can't allocate glue\n");
337 goto out;
338 }
382 339
383 dev_set_drvdata(&spi->dev, wl); 340 glue->dev = &spi->dev;
384 wl->if_priv = spi;
385 341
386 wl->if_ops = &spi_ops; 342 spi_set_drvdata(spi, glue);
387 343
388 /* This is the only SPI value that we need to set here, the rest 344 /* This is the only SPI value that we need to set here, the rest
389 * comes from the board-peripherals file */ 345 * comes from the board-peripherals file */
@@ -391,69 +347,61 @@ static int __devinit wl1271_probe(struct spi_device *spi)
391 347
392 ret = spi_setup(spi); 348 ret = spi_setup(spi);
393 if (ret < 0) { 349 if (ret < 0) {
394 wl1271_error("spi_setup failed"); 350 dev_err(glue->dev, "spi_setup failed\n");
395 goto out_free; 351 goto out_free_glue;
396 } 352 }
397 353
398 wl->set_power = pdata->set_power; 354 glue->core = platform_device_alloc("wl12xx", -1);
399 if (!wl->set_power) { 355 if (!glue->core) {
400 wl1271_error("set power function missing in platform data"); 356 dev_err(glue->dev, "can't allocate platform_device\n");
401 ret = -ENODEV; 357 ret = -ENOMEM;
402 goto out_free; 358 goto out_free_glue;
403 } 359 }
404 360
405 wl->ref_clock = pdata->board_ref_clock; 361 glue->core->dev.parent = &spi->dev;
406 wl->tcxo_clock = pdata->board_tcxo_clock;
407 wl->platform_quirks = pdata->platform_quirks;
408 362
409 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) 363 memset(res, 0x00, sizeof(res));
410 irqflags = IRQF_TRIGGER_RISING;
411 else
412 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
413 364
414 wl->irq = spi->irq; 365 res[0].start = spi->irq;
415 if (wl->irq < 0) { 366 res[0].flags = IORESOURCE_IRQ;
416 wl1271_error("irq missing in platform data"); 367 res[0].name = "irq";
417 ret = -ENODEV;
418 goto out_free;
419 }
420 368
421 ret = request_threaded_irq(wl->irq, wl1271_hardirq, wl1271_irq, 369 ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
422 irqflags, 370 if (ret) {
423 DRIVER_NAME, wl); 371 dev_err(glue->dev, "can't add resources\n");
424 if (ret < 0) { 372 goto out_dev_put;
425 wl1271_error("request_irq() failed: %d", ret);
426 goto out_free;
427 } 373 }
428 374
429 disable_irq(wl->irq); 375 ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
430 376 if (ret) {
431 ret = wl1271_init_ieee80211(wl); 377 dev_err(glue->dev, "can't add platform data\n");
432 if (ret) 378 goto out_dev_put;
433 goto out_irq; 379 }
434 380
435 ret = wl1271_register_hw(wl); 381 ret = platform_device_add(glue->core);
436 if (ret) 382 if (ret) {
437 goto out_irq; 383 dev_err(glue->dev, "can't register platform device\n");
384 goto out_dev_put;
385 }
438 386
439 return 0; 387 return 0;
440 388
441 out_irq: 389out_dev_put:
442 free_irq(wl->irq, wl); 390 platform_device_put(glue->core);
443
444 out_free:
445 wl1271_free_hw(wl);
446 391
392out_free_glue:
393 kfree(glue);
394out:
447 return ret; 395 return ret;
448} 396}
449 397
450static int __devexit wl1271_remove(struct spi_device *spi) 398static int __devexit wl1271_remove(struct spi_device *spi)
451{ 399{
452 struct wl1271 *wl = dev_get_drvdata(&spi->dev); 400 struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
453 401
454 wl1271_unregister_hw(wl); 402 platform_device_del(glue->core);
455 free_irq(wl->irq, wl); 403 platform_device_put(glue->core);
456 wl1271_free_hw(wl); 404 kfree(glue);
457 405
458 return 0; 406 return 0;
459} 407}
diff --git a/drivers/net/wireless/wl12xx/testmode.c b/drivers/net/wireless/wl12xx/testmode.c
index 4ae8effaee22..978cf2de713d 100644
--- a/drivers/net/wireless/wl12xx/testmode.c
+++ b/drivers/net/wireless/wl12xx/testmode.c
@@ -26,8 +26,10 @@
26#include <net/genetlink.h> 26#include <net/genetlink.h>
27 27
28#include "wl12xx.h" 28#include "wl12xx.h"
29#include "debug.h"
29#include "acx.h" 30#include "acx.h"
30#include "reg.h" 31#include "reg.h"
32#include "ps.h"
31 33
32#define WL1271_TM_MAX_DATA_LENGTH 1024 34#define WL1271_TM_MAX_DATA_LENGTH 1024
33 35
@@ -87,31 +89,47 @@ static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
87 return -EMSGSIZE; 89 return -EMSGSIZE;
88 90
89 mutex_lock(&wl->mutex); 91 mutex_lock(&wl->mutex);
90 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
91 mutex_unlock(&wl->mutex);
92 92
93 if (wl->state == WL1271_STATE_OFF) {
94 ret = -EINVAL;
95 goto out;
96 }
97
98 ret = wl1271_ps_elp_wakeup(wl);
99 if (ret < 0)
100 goto out;
101
102 ret = wl1271_cmd_test(wl, buf, buf_len, answer);
93 if (ret < 0) { 103 if (ret < 0) {
94 wl1271_warning("testmode cmd test failed: %d", ret); 104 wl1271_warning("testmode cmd test failed: %d", ret);
95 return ret; 105 goto out_sleep;
96 } 106 }
97 107
98 if (answer) { 108 if (answer) {
99 len = nla_total_size(buf_len); 109 len = nla_total_size(buf_len);
100 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len); 110 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
101 if (!skb) 111 if (!skb) {
102 return -ENOMEM; 112 ret = -ENOMEM;
113 goto out_sleep;
114 }
103 115
104 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf); 116 NLA_PUT(skb, WL1271_TM_ATTR_DATA, buf_len, buf);
105 ret = cfg80211_testmode_reply(skb); 117 ret = cfg80211_testmode_reply(skb);
106 if (ret < 0) 118 if (ret < 0)
107 return ret; 119 goto out_sleep;
108 } 120 }
109 121
110 return 0; 122out_sleep:
123 wl1271_ps_elp_sleep(wl);
124out:
125 mutex_unlock(&wl->mutex);
126
127 return ret;
111 128
112nla_put_failure: 129nla_put_failure:
113 kfree_skb(skb); 130 kfree_skb(skb);
114 return -EMSGSIZE; 131 ret = -EMSGSIZE;
132 goto out_sleep;
115} 133}
116 134
117static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[]) 135static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
@@ -128,33 +146,53 @@ static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
128 146
129 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]); 147 ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
130 148
149 mutex_lock(&wl->mutex);
150
151 if (wl->state == WL1271_STATE_OFF) {
152 ret = -EINVAL;
153 goto out;
154 }
155
156 ret = wl1271_ps_elp_wakeup(wl);
157 if (ret < 0)
158 goto out;
159
131 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 160 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
132 if (!cmd) 161 if (!cmd) {
133 return -ENOMEM; 162 ret = -ENOMEM;
163 goto out_sleep;
164 }
134 165
135 mutex_lock(&wl->mutex);
136 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd)); 166 ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
137 mutex_unlock(&wl->mutex);
138
139 if (ret < 0) { 167 if (ret < 0) {
140 wl1271_warning("testmode cmd interrogate failed: %d", ret); 168 wl1271_warning("testmode cmd interrogate failed: %d", ret);
141 kfree(cmd); 169 goto out_free;
142 return ret;
143 } 170 }
144 171
145 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd)); 172 skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
146 if (!skb) { 173 if (!skb) {
147 kfree(cmd); 174 ret = -ENOMEM;
148 return -ENOMEM; 175 goto out_free;
149 } 176 }
150 177
151 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd); 178 NLA_PUT(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd);
179 ret = cfg80211_testmode_reply(skb);
180 if (ret < 0)
181 goto out_free;
182
183out_free:
184 kfree(cmd);
185out_sleep:
186 wl1271_ps_elp_sleep(wl);
187out:
188 mutex_unlock(&wl->mutex);
152 189
153 return 0; 190 return ret;
154 191
155nla_put_failure: 192nla_put_failure:
156 kfree_skb(skb); 193 kfree_skb(skb);
157 return -EMSGSIZE; 194 ret = -EMSGSIZE;
195 goto out_free;
158} 196}
159 197
160static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[]) 198static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c
index bad9e29d49b0..7d727ee6ddf6 100644
--- a/drivers/net/wireless/wl12xx/tx.c
+++ b/drivers/net/wireless/wl12xx/tx.c
@@ -26,22 +26,24 @@
26#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
27 27
28#include "wl12xx.h" 28#include "wl12xx.h"
29#include "debug.h"
29#include "io.h" 30#include "io.h"
30#include "reg.h" 31#include "reg.h"
31#include "ps.h" 32#include "ps.h"
32#include "tx.h" 33#include "tx.h"
33#include "event.h" 34#include "event.h"
34 35
35static int wl1271_set_default_wep_key(struct wl1271 *wl, u8 id) 36static int wl1271_set_default_wep_key(struct wl1271 *wl,
37 struct wl12xx_vif *wlvif, u8 id)
36{ 38{
37 int ret; 39 int ret;
38 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS); 40 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
39 41
40 if (is_ap) 42 if (is_ap)
41 ret = wl12xx_cmd_set_default_wep_key(wl, id, 43 ret = wl12xx_cmd_set_default_wep_key(wl, id,
42 wl->ap_bcast_hlid); 44 wlvif->ap.bcast_hlid);
43 else 45 else
44 ret = wl12xx_cmd_set_default_wep_key(wl, id, wl->sta_hlid); 46 ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid);
45 47
46 if (ret < 0) 48 if (ret < 0)
47 return ret; 49 return ret;
@@ -76,7 +78,8 @@ static void wl1271_free_tx_id(struct wl1271 *wl, int id)
76} 78}
77 79
78static int wl1271_tx_update_filters(struct wl1271 *wl, 80static int wl1271_tx_update_filters(struct wl1271 *wl,
79 struct sk_buff *skb) 81 struct wl12xx_vif *wlvif,
82 struct sk_buff *skb)
80{ 83{
81 struct ieee80211_hdr *hdr; 84 struct ieee80211_hdr *hdr;
82 int ret; 85 int ret;
@@ -92,15 +95,11 @@ static int wl1271_tx_update_filters(struct wl1271 *wl,
92 if (!ieee80211_is_auth(hdr->frame_control)) 95 if (!ieee80211_is_auth(hdr->frame_control))
93 return 0; 96 return 0;
94 97
95 if (wl->dev_hlid != WL12XX_INVALID_LINK_ID) 98 if (wlvif->dev_hlid != WL12XX_INVALID_LINK_ID)
96 goto out; 99 goto out;
97 100
98 wl1271_debug(DEBUG_CMD, "starting device role for roaming"); 101 wl1271_debug(DEBUG_CMD, "starting device role for roaming");
99 ret = wl12xx_cmd_role_start_dev(wl); 102 ret = wl12xx_start_dev(wl, wlvif);
100 if (ret < 0)
101 goto out;
102
103 ret = wl12xx_roc(wl, wl->dev_role_id);
104 if (ret < 0) 103 if (ret < 0)
105 goto out; 104 goto out;
106out: 105out:
@@ -123,18 +122,16 @@ static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
123 wl1271_acx_set_inconnection_sta(wl, hdr->addr1); 122 wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
124} 123}
125 124
126static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid) 125static void wl1271_tx_regulate_link(struct wl1271 *wl,
126 struct wl12xx_vif *wlvif,
127 u8 hlid)
127{ 128{
128 bool fw_ps, single_sta; 129 bool fw_ps, single_sta;
129 u8 tx_pkts; 130 u8 tx_pkts;
130 131
131 /* only regulate station links */ 132 if (WARN_ON(!test_bit(hlid, wlvif->links_map)))
132 if (hlid < WL1271_AP_STA_HLID_START)
133 return; 133 return;
134 134
135 if (WARN_ON(!wl1271_is_active_sta(wl, hlid)))
136 return;
137
138 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map); 135 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
139 tx_pkts = wl->links[hlid].allocated_pkts; 136 tx_pkts = wl->links[hlid].allocated_pkts;
140 single_sta = (wl->active_sta_count == 1); 137 single_sta = (wl->active_sta_count == 1);
@@ -146,7 +143,7 @@ static void wl1271_tx_regulate_link(struct wl1271 *wl, u8 hlid)
146 * case FW-memory congestion is not a problem. 143 * case FW-memory congestion is not a problem.
147 */ 144 */
148 if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS) 145 if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
149 wl1271_ps_link_start(wl, hlid, true); 146 wl12xx_ps_link_start(wl, wlvif, hlid, true);
150} 147}
151 148
152bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb) 149bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
@@ -154,7 +151,8 @@ bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
154 return wl->dummy_packet == skb; 151 return wl->dummy_packet == skb;
155} 152}
156 153
157u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb) 154u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
155 struct sk_buff *skb)
158{ 156{
159 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb); 157 struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
160 158
@@ -167,49 +165,51 @@ u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb)
167 } else { 165 } else {
168 struct ieee80211_hdr *hdr; 166 struct ieee80211_hdr *hdr;
169 167
170 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) 168 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
171 return wl->system_hlid; 169 return wl->system_hlid;
172 170
173 hdr = (struct ieee80211_hdr *)skb->data; 171 hdr = (struct ieee80211_hdr *)skb->data;
174 if (ieee80211_is_mgmt(hdr->frame_control)) 172 if (ieee80211_is_mgmt(hdr->frame_control))
175 return wl->ap_global_hlid; 173 return wlvif->ap.global_hlid;
176 else 174 else
177 return wl->ap_bcast_hlid; 175 return wlvif->ap.bcast_hlid;
178 } 176 }
179} 177}
180 178
181static u8 wl1271_tx_get_hlid(struct wl1271 *wl, struct sk_buff *skb) 179u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
180 struct sk_buff *skb)
182{ 181{
183 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 182 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
184 183
185 if (wl12xx_is_dummy_packet(wl, skb)) 184 if (!wlvif || wl12xx_is_dummy_packet(wl, skb))
186 return wl->system_hlid; 185 return wl->system_hlid;
187 186
188 if (wl->bss_type == BSS_TYPE_AP_BSS) 187 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
189 return wl12xx_tx_get_hlid_ap(wl, skb); 188 return wl12xx_tx_get_hlid_ap(wl, wlvif, skb);
190 189
191 wl1271_tx_update_filters(wl, skb); 190 wl1271_tx_update_filters(wl, wlvif, skb);
192 191
193 if ((test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) || 192 if ((test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
194 test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags)) && 193 test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) &&
195 !ieee80211_is_auth(hdr->frame_control) && 194 !ieee80211_is_auth(hdr->frame_control) &&
196 !ieee80211_is_assoc_req(hdr->frame_control)) 195 !ieee80211_is_assoc_req(hdr->frame_control))
197 return wl->sta_hlid; 196 return wlvif->sta.hlid;
198 else 197 else
199 return wl->dev_hlid; 198 return wlvif->dev_hlid;
200} 199}
201 200
202static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl, 201static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
203 unsigned int packet_length) 202 unsigned int packet_length)
204{ 203{
205 if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT) 204 if (wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT)
206 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
207 else
208 return ALIGN(packet_length, WL1271_TX_ALIGN_TO); 205 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
206 else
207 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
209} 208}
210 209
211static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra, 210static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
212 u32 buf_offset, u8 hlid) 211 struct sk_buff *skb, u32 extra, u32 buf_offset,
212 u8 hlid)
213{ 213{
214 struct wl1271_tx_hw_descr *desc; 214 struct wl1271_tx_hw_descr *desc;
215 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; 215 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
@@ -217,6 +217,7 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
217 u32 total_blocks; 217 u32 total_blocks;
218 int id, ret = -EBUSY, ac; 218 int id, ret = -EBUSY, ac;
219 u32 spare_blocks = wl->tx_spare_blocks; 219 u32 spare_blocks = wl->tx_spare_blocks;
220 bool is_dummy = false;
220 221
221 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) 222 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
222 return -EAGAIN; 223 return -EAGAIN;
@@ -231,8 +232,10 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
231 len = wl12xx_calc_packet_alignment(wl, total_len); 232 len = wl12xx_calc_packet_alignment(wl, total_len);
232 233
233 /* in case of a dummy packet, use default amount of spare mem blocks */ 234 /* in case of a dummy packet, use default amount of spare mem blocks */
234 if (unlikely(wl12xx_is_dummy_packet(wl, skb))) 235 if (unlikely(wl12xx_is_dummy_packet(wl, skb))) {
236 is_dummy = true;
235 spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT; 237 spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
238 }
236 239
237 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE + 240 total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
238 spare_blocks; 241 spare_blocks;
@@ -257,8 +260,9 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
257 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 260 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
258 wl->tx_allocated_pkts[ac]++; 261 wl->tx_allocated_pkts[ac]++;
259 262
260 if (wl->bss_type == BSS_TYPE_AP_BSS && 263 if (!is_dummy && wlvif &&
261 hlid >= WL1271_AP_STA_HLID_START) 264 wlvif->bss_type == BSS_TYPE_AP_BSS &&
265 test_bit(hlid, wlvif->ap.sta_hlid_map))
262 wl->links[hlid].allocated_pkts++; 266 wl->links[hlid].allocated_pkts++;
263 267
264 ret = 0; 268 ret = 0;
@@ -273,15 +277,16 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct sk_buff *skb, u32 extra,
273 return ret; 277 return ret;
274} 278}
275 279
276static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb, 280static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
277 u32 extra, struct ieee80211_tx_info *control, 281 struct sk_buff *skb, u32 extra,
278 u8 hlid) 282 struct ieee80211_tx_info *control, u8 hlid)
279{ 283{
280 struct timespec ts; 284 struct timespec ts;
281 struct wl1271_tx_hw_descr *desc; 285 struct wl1271_tx_hw_descr *desc;
282 int aligned_len, ac, rate_idx; 286 int aligned_len, ac, rate_idx;
283 s64 hosttime; 287 s64 hosttime;
284 u16 tx_attr; 288 u16 tx_attr = 0;
289 bool is_dummy;
285 290
286 desc = (struct wl1271_tx_hw_descr *) skb->data; 291 desc = (struct wl1271_tx_hw_descr *) skb->data;
287 292
@@ -298,7 +303,8 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
298 hosttime = (timespec_to_ns(&ts) >> 10); 303 hosttime = (timespec_to_ns(&ts) >> 10);
299 desc->start_time = cpu_to_le32(hosttime - wl->time_offset); 304 desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
300 305
301 if (wl->bss_type != BSS_TYPE_AP_BSS) 306 is_dummy = wl12xx_is_dummy_packet(wl, skb);
307 if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS)
302 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU); 308 desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
303 else 309 else
304 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU); 310 desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
@@ -307,39 +313,42 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
307 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 313 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
308 desc->tid = skb->priority; 314 desc->tid = skb->priority;
309 315
310 if (wl12xx_is_dummy_packet(wl, skb)) { 316 if (is_dummy) {
311 /* 317 /*
312 * FW expects the dummy packet to have an invalid session id - 318 * FW expects the dummy packet to have an invalid session id -
313 * any session id that is different than the one set in the join 319 * any session id that is different than the one set in the join
314 */ 320 */
315 tx_attr = ((~wl->session_counter) << 321 tx_attr = (SESSION_COUNTER_INVALID <<
316 TX_HW_ATTR_OFST_SESSION_COUNTER) & 322 TX_HW_ATTR_OFST_SESSION_COUNTER) &
317 TX_HW_ATTR_SESSION_COUNTER; 323 TX_HW_ATTR_SESSION_COUNTER;
318 324
319 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ; 325 tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
320 } else { 326 } else if (wlvif) {
321 /* configure the tx attributes */ 327 /* configure the tx attributes */
322 tx_attr = 328 tx_attr = wlvif->session_counter <<
323 wl->session_counter << TX_HW_ATTR_OFST_SESSION_COUNTER; 329 TX_HW_ATTR_OFST_SESSION_COUNTER;
324 } 330 }
325 331
326 desc->hlid = hlid; 332 desc->hlid = hlid;
327 333 if (is_dummy || !wlvif)
328 if (wl->bss_type != BSS_TYPE_AP_BSS) { 334 rate_idx = 0;
335 else if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
329 /* if the packets are destined for AP (have a STA entry) 336 /* if the packets are destined for AP (have a STA entry)
330 send them with AP rate policies, otherwise use default 337 send them with AP rate policies, otherwise use default
331 basic rates */ 338 basic rates */
332 if (control->control.sta) 339 if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
333 rate_idx = ACX_TX_AP_FULL_RATE; 340 rate_idx = wlvif->sta.p2p_rate_idx;
341 else if (control->control.sta)
342 rate_idx = wlvif->sta.ap_rate_idx;
334 else 343 else
335 rate_idx = ACX_TX_BASIC_RATE; 344 rate_idx = wlvif->sta.basic_rate_idx;
336 } else { 345 } else {
337 if (hlid == wl->ap_global_hlid) 346 if (hlid == wlvif->ap.global_hlid)
338 rate_idx = ACX_TX_AP_MODE_MGMT_RATE; 347 rate_idx = wlvif->ap.mgmt_rate_idx;
339 else if (hlid == wl->ap_bcast_hlid) 348 else if (hlid == wlvif->ap.bcast_hlid)
340 rate_idx = ACX_TX_AP_MODE_BCST_RATE; 349 rate_idx = wlvif->ap.bcast_rate_idx;
341 else 350 else
342 rate_idx = ac; 351 rate_idx = wlvif->ap.ucast_rate_idx[ac];
343 } 352 }
344 353
345 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY; 354 tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
@@ -379,20 +388,24 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct sk_buff *skb,
379} 388}
380 389
381/* caller must hold wl->mutex */ 390/* caller must hold wl->mutex */
382static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb, 391static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
383 u32 buf_offset) 392 struct sk_buff *skb, u32 buf_offset)
384{ 393{
385 struct ieee80211_tx_info *info; 394 struct ieee80211_tx_info *info;
386 u32 extra = 0; 395 u32 extra = 0;
387 int ret = 0; 396 int ret = 0;
388 u32 total_len; 397 u32 total_len;
389 u8 hlid; 398 u8 hlid;
399 bool is_dummy;
390 400
391 if (!skb) 401 if (!skb)
392 return -EINVAL; 402 return -EINVAL;
393 403
394 info = IEEE80211_SKB_CB(skb); 404 info = IEEE80211_SKB_CB(skb);
395 405
406 /* TODO: handle dummy packets on multi-vifs */
407 is_dummy = wl12xx_is_dummy_packet(wl, skb);
408
396 if (info->control.hw_key && 409 if (info->control.hw_key &&
397 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) 410 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
398 extra = WL1271_TKIP_IV_SPACE; 411 extra = WL1271_TKIP_IV_SPACE;
@@ -405,29 +418,28 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
405 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) || 418 is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
406 (cipher == WLAN_CIPHER_SUITE_WEP104); 419 (cipher == WLAN_CIPHER_SUITE_WEP104);
407 420
408 if (unlikely(is_wep && wl->default_key != idx)) { 421 if (unlikely(is_wep && wlvif->default_key != idx)) {
409 ret = wl1271_set_default_wep_key(wl, idx); 422 ret = wl1271_set_default_wep_key(wl, wlvif, idx);
410 if (ret < 0) 423 if (ret < 0)
411 return ret; 424 return ret;
412 wl->default_key = idx; 425 wlvif->default_key = idx;
413 } 426 }
414 } 427 }
415 428 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
416 hlid = wl1271_tx_get_hlid(wl, skb);
417 if (hlid == WL12XX_INVALID_LINK_ID) { 429 if (hlid == WL12XX_INVALID_LINK_ID) {
418 wl1271_error("invalid hlid. dropping skb 0x%p", skb); 430 wl1271_error("invalid hlid. dropping skb 0x%p", skb);
419 return -EINVAL; 431 return -EINVAL;
420 } 432 }
421 433
422 ret = wl1271_tx_allocate(wl, skb, extra, buf_offset, hlid); 434 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid);
423 if (ret < 0) 435 if (ret < 0)
424 return ret; 436 return ret;
425 437
426 wl1271_tx_fill_hdr(wl, skb, extra, info, hlid); 438 wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
427 439
428 if (wl->bss_type == BSS_TYPE_AP_BSS) { 440 if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
429 wl1271_tx_ap_update_inconnection_sta(wl, skb); 441 wl1271_tx_ap_update_inconnection_sta(wl, skb);
430 wl1271_tx_regulate_link(wl, hlid); 442 wl1271_tx_regulate_link(wl, wlvif, hlid);
431 } 443 }
432 444
433 /* 445 /*
@@ -444,7 +456,7 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct sk_buff *skb,
444 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len); 456 memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
445 457
446 /* Revert side effects in the dummy packet skb, so it can be reused */ 458 /* Revert side effects in the dummy packet skb, so it can be reused */
447 if (wl12xx_is_dummy_packet(wl, skb)) 459 if (is_dummy)
448 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 460 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
449 461
450 return total_len; 462 return total_len;
@@ -522,19 +534,18 @@ static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
522 return &queues[q]; 534 return &queues[q];
523} 535}
524 536
525static struct sk_buff *wl1271_sta_skb_dequeue(struct wl1271 *wl) 537static struct sk_buff *wl12xx_lnk_skb_dequeue(struct wl1271 *wl,
538 struct wl1271_link *lnk)
526{ 539{
527 struct sk_buff *skb = NULL; 540 struct sk_buff *skb;
528 unsigned long flags; 541 unsigned long flags;
529 struct sk_buff_head *queue; 542 struct sk_buff_head *queue;
530 543
531 queue = wl1271_select_queue(wl, wl->tx_queue); 544 queue = wl1271_select_queue(wl, lnk->tx_queue);
532 if (!queue) 545 if (!queue)
533 goto out; 546 return NULL;
534 547
535 skb = skb_dequeue(queue); 548 skb = skb_dequeue(queue);
536
537out:
538 if (skb) { 549 if (skb) {
539 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 550 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
540 spin_lock_irqsave(&wl->wl_lock, flags); 551 spin_lock_irqsave(&wl->wl_lock, flags);
@@ -545,43 +556,33 @@ out:
545 return skb; 556 return skb;
546} 557}
547 558
548static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl) 559static struct sk_buff *wl12xx_vif_skb_dequeue(struct wl1271 *wl,
560 struct wl12xx_vif *wlvif)
549{ 561{
550 struct sk_buff *skb = NULL; 562 struct sk_buff *skb = NULL;
551 unsigned long flags;
552 int i, h, start_hlid; 563 int i, h, start_hlid;
553 struct sk_buff_head *queue;
554 564
555 /* start from the link after the last one */ 565 /* start from the link after the last one */
556 start_hlid = (wl->last_tx_hlid + 1) % AP_MAX_LINKS; 566 start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS;
557 567
558 /* dequeue according to AC, round robin on each link */ 568 /* dequeue according to AC, round robin on each link */
559 for (i = 0; i < AP_MAX_LINKS; i++) { 569 for (i = 0; i < WL12XX_MAX_LINKS; i++) {
560 h = (start_hlid + i) % AP_MAX_LINKS; 570 h = (start_hlid + i) % WL12XX_MAX_LINKS;
561 571
562 /* only consider connected stations */ 572 /* only consider connected stations */
563 if (h >= WL1271_AP_STA_HLID_START && 573 if (!test_bit(h, wlvif->links_map))
564 !test_bit(h - WL1271_AP_STA_HLID_START, wl->ap_hlid_map))
565 continue; 574 continue;
566 575
567 queue = wl1271_select_queue(wl, wl->links[h].tx_queue); 576 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[h]);
568 if (!queue) 577 if (!skb)
569 continue; 578 continue;
570 579
571 skb = skb_dequeue(queue); 580 wlvif->last_tx_hlid = h;
572 if (skb) 581 break;
573 break;
574 } 582 }
575 583
576 if (skb) { 584 if (!skb)
577 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 585 wlvif->last_tx_hlid = 0;
578 wl->last_tx_hlid = h;
579 spin_lock_irqsave(&wl->wl_lock, flags);
580 wl->tx_queue_count[q]--;
581 spin_unlock_irqrestore(&wl->wl_lock, flags);
582 } else {
583 wl->last_tx_hlid = 0;
584 }
585 586
586 return skb; 587 return skb;
587} 588}
@@ -589,12 +590,32 @@ static struct sk_buff *wl1271_ap_skb_dequeue(struct wl1271 *wl)
589static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl) 590static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
590{ 591{
591 unsigned long flags; 592 unsigned long flags;
593 struct wl12xx_vif *wlvif = wl->last_wlvif;
592 struct sk_buff *skb = NULL; 594 struct sk_buff *skb = NULL;
593 595
594 if (wl->bss_type == BSS_TYPE_AP_BSS) 596 if (wlvif) {
595 skb = wl1271_ap_skb_dequeue(wl); 597 wl12xx_for_each_wlvif_continue(wl, wlvif) {
596 else 598 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
597 skb = wl1271_sta_skb_dequeue(wl); 599 if (skb) {
600 wl->last_wlvif = wlvif;
601 break;
602 }
603 }
604 }
605
606 /* do another pass */
607 if (!skb) {
608 wl12xx_for_each_wlvif(wl, wlvif) {
609 skb = wl12xx_vif_skb_dequeue(wl, wlvif);
610 if (skb) {
611 wl->last_wlvif = wlvif;
612 break;
613 }
614 }
615 }
616
617 if (!skb)
618 skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[wl->system_hlid]);
598 619
599 if (!skb && 620 if (!skb &&
600 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) { 621 test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
@@ -610,21 +631,21 @@ static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
610 return skb; 631 return skb;
611} 632}
612 633
613static void wl1271_skb_queue_head(struct wl1271 *wl, struct sk_buff *skb) 634static void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif,
635 struct sk_buff *skb)
614{ 636{
615 unsigned long flags; 637 unsigned long flags;
616 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 638 int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
617 639
618 if (wl12xx_is_dummy_packet(wl, skb)) { 640 if (wl12xx_is_dummy_packet(wl, skb)) {
619 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags); 641 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
620 } else if (wl->bss_type == BSS_TYPE_AP_BSS) { 642 } else {
621 u8 hlid = wl1271_tx_get_hlid(wl, skb); 643 u8 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
622 skb_queue_head(&wl->links[hlid].tx_queue[q], skb); 644 skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
623 645
624 /* make sure we dequeue the same packet next time */ 646 /* make sure we dequeue the same packet next time */
625 wl->last_tx_hlid = (hlid + AP_MAX_LINKS - 1) % AP_MAX_LINKS; 647 wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) %
626 } else { 648 WL12XX_MAX_LINKS;
627 skb_queue_head(&wl->tx_queue[q], skb);
628 } 649 }
629 650
630 spin_lock_irqsave(&wl->wl_lock, flags); 651 spin_lock_irqsave(&wl->wl_lock, flags);
@@ -639,29 +660,71 @@ static bool wl1271_tx_is_data_present(struct sk_buff *skb)
639 return ieee80211_is_data_present(hdr->frame_control); 660 return ieee80211_is_data_present(hdr->frame_control);
640} 661}
641 662
663void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids)
664{
665 struct wl12xx_vif *wlvif;
666 u32 timeout;
667 u8 hlid;
668
669 if (!wl->conf.rx_streaming.interval)
670 return;
671
672 if (!wl->conf.rx_streaming.always &&
673 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))
674 return;
675
676 timeout = wl->conf.rx_streaming.duration;
677 wl12xx_for_each_wlvif_sta(wl, wlvif) {
678 bool found = false;
679 for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) {
680 if (test_bit(hlid, wlvif->links_map)) {
681 found = true;
682 break;
683 }
684 }
685
686 if (!found)
687 continue;
688
689 /* enable rx streaming */
690 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
691 ieee80211_queue_work(wl->hw,
692 &wlvif->rx_streaming_enable_work);
693
694 mod_timer(&wlvif->rx_streaming_timer,
695 jiffies + msecs_to_jiffies(timeout));
696 }
697}
698
642void wl1271_tx_work_locked(struct wl1271 *wl) 699void wl1271_tx_work_locked(struct wl1271 *wl)
643{ 700{
701 struct wl12xx_vif *wlvif;
644 struct sk_buff *skb; 702 struct sk_buff *skb;
703 struct wl1271_tx_hw_descr *desc;
645 u32 buf_offset = 0; 704 u32 buf_offset = 0;
646 bool sent_packets = false; 705 bool sent_packets = false;
647 bool had_data = false; 706 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
648 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
649 int ret; 707 int ret;
650 708
651 if (unlikely(wl->state == WL1271_STATE_OFF)) 709 if (unlikely(wl->state == WL1271_STATE_OFF))
652 return; 710 return;
653 711
654 while ((skb = wl1271_skb_dequeue(wl))) { 712 while ((skb = wl1271_skb_dequeue(wl))) {
655 if (wl1271_tx_is_data_present(skb)) 713 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
656 had_data = true; 714 bool has_data = false;
657 715
658 ret = wl1271_prepare_tx_frame(wl, skb, buf_offset); 716 wlvif = NULL;
717 if (!wl12xx_is_dummy_packet(wl, skb) && info->control.vif)
718 wlvif = wl12xx_vif_to_data(info->control.vif);
719
720 has_data = wlvif && wl1271_tx_is_data_present(skb);
721 ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset);
659 if (ret == -EAGAIN) { 722 if (ret == -EAGAIN) {
660 /* 723 /*
661 * Aggregation buffer is full. 724 * Aggregation buffer is full.
662 * Flush buffer and try again. 725 * Flush buffer and try again.
663 */ 726 */
664 wl1271_skb_queue_head(wl, skb); 727 wl1271_skb_queue_head(wl, wlvif, skb);
665 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf, 728 wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
666 buf_offset, true); 729 buf_offset, true);
667 sent_packets = true; 730 sent_packets = true;
@@ -672,7 +735,7 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
672 * Firmware buffer is full. 735 * Firmware buffer is full.
673 * Queue back last skb, and stop aggregating. 736 * Queue back last skb, and stop aggregating.
674 */ 737 */
675 wl1271_skb_queue_head(wl, skb); 738 wl1271_skb_queue_head(wl, wlvif, skb);
676 /* No work left, avoid scheduling redundant tx work */ 739 /* No work left, avoid scheduling redundant tx work */
677 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags); 740 set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
678 goto out_ack; 741 goto out_ack;
@@ -682,6 +745,10 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
682 } 745 }
683 buf_offset += ret; 746 buf_offset += ret;
684 wl->tx_packets_count++; 747 wl->tx_packets_count++;
748 if (has_data) {
749 desc = (struct wl1271_tx_hw_descr *) skb->data;
750 __set_bit(desc->hlid, active_hlids);
751 }
685 } 752 }
686 753
687out_ack: 754out_ack:
@@ -701,19 +768,7 @@ out_ack:
701 768
702 wl1271_handle_tx_low_watermark(wl); 769 wl1271_handle_tx_low_watermark(wl);
703 } 770 }
704 if (!is_ap && wl->conf.rx_streaming.interval && had_data && 771 wl12xx_rearm_rx_streaming(wl, active_hlids);
705 (wl->conf.rx_streaming.always ||
706 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))) {
707 u32 timeout = wl->conf.rx_streaming.duration;
708
709 /* enable rx streaming */
710 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
711 ieee80211_queue_work(wl->hw,
712 &wl->rx_streaming_enable_work);
713
714 mod_timer(&wl->rx_streaming_timer,
715 jiffies + msecs_to_jiffies(timeout));
716 }
717} 772}
718 773
719void wl1271_tx_work(struct work_struct *work) 774void wl1271_tx_work(struct work_struct *work)
@@ -737,6 +792,8 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
737 struct wl1271_tx_hw_res_descr *result) 792 struct wl1271_tx_hw_res_descr *result)
738{ 793{
739 struct ieee80211_tx_info *info; 794 struct ieee80211_tx_info *info;
795 struct ieee80211_vif *vif;
796 struct wl12xx_vif *wlvif;
740 struct sk_buff *skb; 797 struct sk_buff *skb;
741 int id = result->id; 798 int id = result->id;
742 int rate = -1; 799 int rate = -1;
@@ -756,11 +813,16 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
756 return; 813 return;
757 } 814 }
758 815
816 /* info->control is valid as long as we don't update info->status */
817 vif = info->control.vif;
818 wlvif = wl12xx_vif_to_data(vif);
819
759 /* update the TX status info */ 820 /* update the TX status info */
760 if (result->status == TX_SUCCESS) { 821 if (result->status == TX_SUCCESS) {
761 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 822 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
762 info->flags |= IEEE80211_TX_STAT_ACK; 823 info->flags |= IEEE80211_TX_STAT_ACK;
763 rate = wl1271_rate_to_idx(result->rate_class_index, wl->band); 824 rate = wl1271_rate_to_idx(result->rate_class_index,
825 wlvif->band);
764 retries = result->ack_failures; 826 retries = result->ack_failures;
765 } else if (result->status == TX_RETRY_EXCEEDED) { 827 } else if (result->status == TX_RETRY_EXCEEDED) {
766 wl->stats.excessive_retries++; 828 wl->stats.excessive_retries++;
@@ -783,14 +845,14 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
783 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP || 845 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
784 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) { 846 info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
785 u8 fw_lsb = result->tx_security_sequence_number_lsb; 847 u8 fw_lsb = result->tx_security_sequence_number_lsb;
786 u8 cur_lsb = wl->tx_security_last_seq_lsb; 848 u8 cur_lsb = wlvif->tx_security_last_seq_lsb;
787 849
788 /* 850 /*
789 * update security sequence number, taking care of potential 851 * update security sequence number, taking care of potential
790 * wrap-around 852 * wrap-around
791 */ 853 */
792 wl->tx_security_seq += (fw_lsb - cur_lsb + 256) % 256; 854 wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff;
793 wl->tx_security_last_seq_lsb = fw_lsb; 855 wlvif->tx_security_last_seq_lsb = fw_lsb;
794 } 856 }
795 857
796 /* remove private header from packet */ 858 /* remove private header from packet */
@@ -886,39 +948,30 @@ void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
886} 948}
887 949
888/* caller must hold wl->mutex and TX must be stopped */ 950/* caller must hold wl->mutex and TX must be stopped */
889void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues) 951void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
890{ 952{
891 int i; 953 int i;
892 struct sk_buff *skb;
893 struct ieee80211_tx_info *info;
894 954
895 /* TX failure */ 955 /* TX failure */
896 if (wl->bss_type == BSS_TYPE_AP_BSS) { 956 for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) {
897 for (i = 0; i < AP_MAX_LINKS; i++) { 957 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
898 wl1271_free_sta(wl, i); 958 wl1271_free_sta(wl, wlvif, i);
899 wl1271_tx_reset_link_queues(wl, i); 959 else
900 wl->links[i].allocated_pkts = 0; 960 wlvif->sta.ba_rx_bitmap = 0;
901 wl->links[i].prev_freed_pkts = 0;
902 }
903
904 wl->last_tx_hlid = 0;
905 } else {
906 for (i = 0; i < NUM_TX_QUEUES; i++) {
907 while ((skb = skb_dequeue(&wl->tx_queue[i]))) {
908 wl1271_debug(DEBUG_TX, "freeing skb 0x%p",
909 skb);
910
911 if (!wl12xx_is_dummy_packet(wl, skb)) {
912 info = IEEE80211_SKB_CB(skb);
913 info->status.rates[0].idx = -1;
914 info->status.rates[0].count = 0;
915 ieee80211_tx_status_ni(wl->hw, skb);
916 }
917 }
918 }
919 961
920 wl->ba_rx_bitmap = 0; 962 wl1271_tx_reset_link_queues(wl, i);
963 wl->links[i].allocated_pkts = 0;
964 wl->links[i].prev_freed_pkts = 0;
921 } 965 }
966 wlvif->last_tx_hlid = 0;
967
968}
969/* caller must hold wl->mutex and TX must be stopped */
970void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
971{
972 int i;
973 struct sk_buff *skb;
974 struct ieee80211_tx_info *info;
922 975
923 for (i = 0; i < NUM_TX_QUEUES; i++) 976 for (i = 0; i < NUM_TX_QUEUES; i++)
924 wl->tx_queue_count[i] = 0; 977 wl->tx_queue_count[i] = 0;
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/tx.h
index dc4f09adf088..2dbb24e6d541 100644
--- a/drivers/net/wireless/wl12xx/tx.h
+++ b/drivers/net/wireless/wl12xx/tx.h
@@ -206,18 +206,23 @@ static inline int wl1271_tx_total_queue_count(struct wl1271 *wl)
206void wl1271_tx_work(struct work_struct *work); 206void wl1271_tx_work(struct work_struct *work);
207void wl1271_tx_work_locked(struct wl1271 *wl); 207void wl1271_tx_work_locked(struct wl1271 *wl);
208void wl1271_tx_complete(struct wl1271 *wl); 208void wl1271_tx_complete(struct wl1271 *wl);
209void wl1271_tx_reset(struct wl1271 *wl, bool reset_tx_queues); 209void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
210void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
210void wl1271_tx_flush(struct wl1271 *wl); 211void wl1271_tx_flush(struct wl1271 *wl);
211u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band); 212u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
212u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set, 213u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
213 enum ieee80211_band rate_band); 214 enum ieee80211_band rate_band);
214u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set); 215u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set);
215u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct sk_buff *skb); 216u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
217 struct sk_buff *skb);
218u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
219 struct sk_buff *skb);
216void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid); 220void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
217void wl1271_handle_tx_low_watermark(struct wl1271 *wl); 221void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
218bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb); 222bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
223void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
219 224
220/* from main.c */ 225/* from main.c */
221void wl1271_free_sta(struct wl1271 *wl, u8 hlid); 226void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
222 227
223#endif 228#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
index 1ec90fc7505e..f1c911774bfd 100644
--- a/drivers/net/wireless/wl12xx/wl12xx.h
+++ b/drivers/net/wireless/wl12xx/wl12xx.h
@@ -35,9 +35,6 @@
35#include "conf.h" 35#include "conf.h"
36#include "ini.h" 36#include "ini.h"
37 37
38#define DRIVER_NAME "wl1271"
39#define DRIVER_PREFIX DRIVER_NAME ": "
40
41/* 38/*
42 * FW versions support BA 11n 39 * FW versions support BA 11n
43 * versions marks x.x.x.50-60.x 40 * versions marks x.x.x.50-60.x
@@ -45,73 +42,6 @@
45#define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50 42#define WL12XX_BA_SUPPORT_FW_COST_VER2_START 50
46#define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60 43#define WL12XX_BA_SUPPORT_FW_COST_VER2_END 60
47 44
48enum {
49 DEBUG_NONE = 0,
50 DEBUG_IRQ = BIT(0),
51 DEBUG_SPI = BIT(1),
52 DEBUG_BOOT = BIT(2),
53 DEBUG_MAILBOX = BIT(3),
54 DEBUG_TESTMODE = BIT(4),
55 DEBUG_EVENT = BIT(5),
56 DEBUG_TX = BIT(6),
57 DEBUG_RX = BIT(7),
58 DEBUG_SCAN = BIT(8),
59 DEBUG_CRYPT = BIT(9),
60 DEBUG_PSM = BIT(10),
61 DEBUG_MAC80211 = BIT(11),
62 DEBUG_CMD = BIT(12),
63 DEBUG_ACX = BIT(13),
64 DEBUG_SDIO = BIT(14),
65 DEBUG_FILTERS = BIT(15),
66 DEBUG_ADHOC = BIT(16),
67 DEBUG_AP = BIT(17),
68 DEBUG_MASTER = (DEBUG_ADHOC | DEBUG_AP),
69 DEBUG_ALL = ~0,
70};
71
72extern u32 wl12xx_debug_level;
73
74#define DEBUG_DUMP_LIMIT 1024
75
76#define wl1271_error(fmt, arg...) \
77 pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
78
79#define wl1271_warning(fmt, arg...) \
80 pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
81
82#define wl1271_notice(fmt, arg...) \
83 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
84
85#define wl1271_info(fmt, arg...) \
86 pr_info(DRIVER_PREFIX fmt "\n", ##arg)
87
88#define wl1271_debug(level, fmt, arg...) \
89 do { \
90 if (level & wl12xx_debug_level) \
91 pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
92 } while (0)
93
94/* TODO: use pr_debug_hex_dump when it will be available */
95#define wl1271_dump(level, prefix, buf, len) \
96 do { \
97 if (level & wl12xx_debug_level) \
98 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
99 DUMP_PREFIX_OFFSET, 16, 1, \
100 buf, \
101 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
102 0); \
103 } while (0)
104
105#define wl1271_dump_ascii(level, prefix, buf, len) \
106 do { \
107 if (level & wl12xx_debug_level) \
108 print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
109 DUMP_PREFIX_OFFSET, 16, 1, \
110 buf, \
111 min_t(size_t, len, DEBUG_DUMP_LIMIT), \
112 true); \
113 } while (0)
114
115#define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin" 45#define WL127X_FW_NAME "ti-connectivity/wl127x-fw-3.bin"
116#define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin" 46#define WL128X_FW_NAME "ti-connectivity/wl128x-fw-3.bin"
117 47
@@ -142,16 +72,12 @@ extern u32 wl12xx_debug_level;
142#define WL12XX_INVALID_ROLE_ID 0xff 72#define WL12XX_INVALID_ROLE_ID 0xff
143#define WL12XX_INVALID_LINK_ID 0xff 73#define WL12XX_INVALID_LINK_ID 0xff
144 74
75#define WL12XX_MAX_RATE_POLICIES 16
76
145/* Defined by FW as 0. Will not be freed or allocated. */ 77/* Defined by FW as 0. Will not be freed or allocated. */
146#define WL12XX_SYSTEM_HLID 0 78#define WL12XX_SYSTEM_HLID 0
147 79
148/* 80/*
149 * TODO: we currently don't support multirole. remove
150 * this constant from the code when we do.
151 */
152#define WL1271_AP_STA_HLID_START 3
153
154/*
155 * When in AP-mode, we allow (at least) this number of packets 81 * When in AP-mode, we allow (at least) this number of packets
156 * to be transmitted to FW for a STA in PS-mode. Only when packets are 82 * to be transmitted to FW for a STA in PS-mode. Only when packets are
157 * present in the FW buffers it will wake the sleeping STA. We want to put 83 * present in the FW buffers it will wake the sleeping STA. We want to put
@@ -236,13 +162,6 @@ struct wl1271_stats {
236 162
237#define AP_MAX_STATIONS 8 163#define AP_MAX_STATIONS 8
238 164
239/* Broadcast and Global links + system link + links to stations */
240/*
241 * TODO: when WL1271_AP_STA_HLID_START is no longer constant, change all
242 * the places that use this.
243 */
244#define AP_MAX_LINKS (AP_MAX_STATIONS + WL1271_AP_STA_HLID_START)
245
246/* FW status registers */ 165/* FW status registers */
247struct wl12xx_fw_status { 166struct wl12xx_fw_status {
248 __le32 intr; 167 __le32 intr;
@@ -299,17 +218,14 @@ struct wl1271_scan {
299}; 218};
300 219
301struct wl1271_if_operations { 220struct wl1271_if_operations {
302 void (*read)(struct wl1271 *wl, int addr, void *buf, size_t len, 221 void (*read)(struct device *child, int addr, void *buf, size_t len,
303 bool fixed); 222 bool fixed);
304 void (*write)(struct wl1271 *wl, int addr, void *buf, size_t len, 223 void (*write)(struct device *child, int addr, void *buf, size_t len,
305 bool fixed); 224 bool fixed);
306 void (*reset)(struct wl1271 *wl); 225 void (*reset)(struct device *child);
307 void (*init)(struct wl1271 *wl); 226 void (*init)(struct device *child);
308 int (*power)(struct wl1271 *wl, bool enable); 227 int (*power)(struct device *child, bool enable);
309 struct device* (*dev)(struct wl1271 *wl); 228 void (*set_block_size) (struct device *child, unsigned int blksz);
310 void (*enable_irq)(struct wl1271 *wl);
311 void (*disable_irq)(struct wl1271 *wl);
312 void (*set_block_size) (struct wl1271 *wl, unsigned int blksz);
313}; 229};
314 230
315#define MAX_NUM_KEYS 14 231#define MAX_NUM_KEYS 14
@@ -326,29 +242,33 @@ struct wl1271_ap_key {
326}; 242};
327 243
328enum wl12xx_flags { 244enum wl12xx_flags {
329 WL1271_FLAG_STA_ASSOCIATED,
330 WL1271_FLAG_IBSS_JOINED,
331 WL1271_FLAG_GPIO_POWER, 245 WL1271_FLAG_GPIO_POWER,
332 WL1271_FLAG_TX_QUEUE_STOPPED, 246 WL1271_FLAG_TX_QUEUE_STOPPED,
333 WL1271_FLAG_TX_PENDING, 247 WL1271_FLAG_TX_PENDING,
334 WL1271_FLAG_IN_ELP, 248 WL1271_FLAG_IN_ELP,
335 WL1271_FLAG_ELP_REQUESTED, 249 WL1271_FLAG_ELP_REQUESTED,
336 WL1271_FLAG_PSM,
337 WL1271_FLAG_PSM_REQUESTED,
338 WL1271_FLAG_IRQ_RUNNING, 250 WL1271_FLAG_IRQ_RUNNING,
339 WL1271_FLAG_IDLE, 251 WL1271_FLAG_IDLE,
340 WL1271_FLAG_PSPOLL_FAILURE,
341 WL1271_FLAG_STA_STATE_SENT,
342 WL1271_FLAG_FW_TX_BUSY, 252 WL1271_FLAG_FW_TX_BUSY,
343 WL1271_FLAG_AP_STARTED,
344 WL1271_FLAG_IF_INITIALIZED,
345 WL1271_FLAG_DUMMY_PACKET_PENDING, 253 WL1271_FLAG_DUMMY_PACKET_PENDING,
346 WL1271_FLAG_SUSPENDED, 254 WL1271_FLAG_SUSPENDED,
347 WL1271_FLAG_PENDING_WORK, 255 WL1271_FLAG_PENDING_WORK,
348 WL1271_FLAG_SOFT_GEMINI, 256 WL1271_FLAG_SOFT_GEMINI,
349 WL1271_FLAG_RX_STREAMING_STARTED,
350 WL1271_FLAG_RECOVERY_IN_PROGRESS, 257 WL1271_FLAG_RECOVERY_IN_PROGRESS,
351 WL1271_FLAG_CS_PROGRESS, 258};
259
260enum wl12xx_vif_flags {
261 WLVIF_FLAG_INITIALIZED,
262 WLVIF_FLAG_STA_ASSOCIATED,
263 WLVIF_FLAG_IBSS_JOINED,
264 WLVIF_FLAG_AP_STARTED,
265 WLVIF_FLAG_PSM,
266 WLVIF_FLAG_PSM_REQUESTED,
267 WLVIF_FLAG_STA_STATE_SENT,
268 WLVIF_FLAG_RX_STREAMING_STARTED,
269 WLVIF_FLAG_PSPOLL_FAILURE,
270 WLVIF_FLAG_CS_PROGRESS,
271 WLVIF_FLAG_AP_PROBE_RESP_SET,
352}; 272};
353 273
354struct wl1271_link { 274struct wl1271_link {
@@ -366,10 +286,11 @@ struct wl1271_link {
366}; 286};
367 287
368struct wl1271 { 288struct wl1271 {
369 struct platform_device *plat_dev;
370 struct ieee80211_hw *hw; 289 struct ieee80211_hw *hw;
371 bool mac80211_registered; 290 bool mac80211_registered;
372 291
292 struct device *dev;
293
373 void *if_priv; 294 void *if_priv;
374 295
375 struct wl1271_if_operations *if_ops; 296 struct wl1271_if_operations *if_ops;
@@ -399,25 +320,20 @@ struct wl1271 {
399 320
400 s8 hw_pg_ver; 321 s8 hw_pg_ver;
401 322
402 u8 bssid[ETH_ALEN];
403 u8 mac_addr[ETH_ALEN]; 323 u8 mac_addr[ETH_ALEN];
404 u8 bss_type;
405 u8 set_bss_type;
406 u8 p2p; /* we are using p2p role */
407 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
408 u8 ssid_len;
409 int channel; 324 int channel;
410 u8 role_id;
411 u8 dev_role_id;
412 u8 system_hlid; 325 u8 system_hlid;
413 u8 sta_hlid;
414 u8 dev_hlid;
415 u8 ap_global_hlid;
416 u8 ap_bcast_hlid;
417 326
418 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)]; 327 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
419 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)]; 328 unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
420 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)]; 329 unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
330 unsigned long rate_policies_map[
331 BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
332
333 struct list_head wlvif_list;
334
335 u8 sta_count;
336 u8 ap_count;
421 337
422 struct wl1271_acx_mem_map *target_mem_map; 338 struct wl1271_acx_mem_map *target_mem_map;
423 339
@@ -440,11 +356,7 @@ struct wl1271 {
440 /* Time-offset between host and chipset clocks */ 356 /* Time-offset between host and chipset clocks */
441 s64 time_offset; 357 s64 time_offset;
442 358
443 /* Session counter for the chipset */
444 int session_counter;
445
446 /* Frames scheduled for transmission, not handled yet */ 359 /* Frames scheduled for transmission, not handled yet */
447 struct sk_buff_head tx_queue[NUM_TX_QUEUES];
448 int tx_queue_count[NUM_TX_QUEUES]; 360 int tx_queue_count[NUM_TX_QUEUES];
449 long stopped_queues_map; 361 long stopped_queues_map;
450 362
@@ -462,17 +374,6 @@ struct wl1271 {
462 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS]; 374 struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
463 int tx_frames_cnt; 375 int tx_frames_cnt;
464 376
465 /*
466 * Security sequence number
467 * bits 0-15: lower 16 bits part of sequence number
468 * bits 16-47: higher 32 bits part of sequence number
469 * bits 48-63: not in use
470 */
471 u64 tx_security_seq;
472
473 /* 8 bits of the last sequence number in use */
474 u8 tx_security_last_seq_lsb;
475
476 /* FW Rx counter */ 377 /* FW Rx counter */
477 u32 rx_counter; 378 u32 rx_counter;
478 379
@@ -507,59 +408,21 @@ struct wl1271 {
507 u32 mbox_ptr[2]; 408 u32 mbox_ptr[2];
508 409
509 /* Are we currently scanning */ 410 /* Are we currently scanning */
411 struct ieee80211_vif *scan_vif;
510 struct wl1271_scan scan; 412 struct wl1271_scan scan;
511 struct delayed_work scan_complete_work; 413 struct delayed_work scan_complete_work;
512 414
513 bool sched_scanning; 415 bool sched_scanning;
514 416
515 /* probe-req template for the current AP */
516 struct sk_buff *probereq;
517
518 /* Our association ID */
519 u16 aid;
520
521 /*
522 * currently configured rate set:
523 * bits 0-15 - 802.11abg rates
524 * bits 16-23 - 802.11n MCS index mask
525 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
526 */
527 u32 basic_rate_set;
528 u32 basic_rate;
529 u32 rate_set;
530 u32 bitrate_masks[IEEE80211_NUM_BANDS];
531
532 /* The current band */ 417 /* The current band */
533 enum ieee80211_band band; 418 enum ieee80211_band band;
534 419
535 /* Beaconing interval (needed for ad-hoc) */
536 u32 beacon_int;
537
538 /* Default key (for WEP) */
539 u32 default_key;
540
541 /* Rx Streaming */
542 struct work_struct rx_streaming_enable_work;
543 struct work_struct rx_streaming_disable_work;
544 struct timer_list rx_streaming_timer;
545
546 struct completion *elp_compl; 420 struct completion *elp_compl;
547 struct completion *ps_compl;
548 struct delayed_work elp_work; 421 struct delayed_work elp_work;
549 struct delayed_work pspoll_work;
550
551 /* counter for ps-poll delivery failures */
552 int ps_poll_failures;
553
554 /* retry counter for PSM entries */
555 u8 psm_entry_retry;
556 422
557 /* in dBm */ 423 /* in dBm */
558 int power_level; 424 int power_level;
559 425
560 int rssi_thold;
561 int last_rssi_event;
562
563 struct wl1271_stats stats; 426 struct wl1271_stats stats;
564 427
565 __le32 buffer_32; 428 __le32 buffer_32;
@@ -583,20 +446,9 @@ struct wl1271 {
583 /* Most recently reported noise in dBm */ 446 /* Most recently reported noise in dBm */
584 s8 noise; 447 s8 noise;
585 448
586 /* map for HLIDs of associated stations - when operating in AP mode */
587 unsigned long ap_hlid_map[BITS_TO_LONGS(AP_MAX_STATIONS)];
588
589 /* recoreded keys for AP-mode - set here before AP startup */
590 struct wl1271_ap_key *recorded_ap_keys[MAX_NUM_KEYS];
591
592 /* bands supported by this instance of wl12xx */ 449 /* bands supported by this instance of wl12xx */
593 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; 450 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
594 451
595 /* RX BA constraint value */
596 bool ba_support;
597 u8 ba_rx_bitmap;
598 bool ba_allowed;
599
600 int tcxo_clock; 452 int tcxo_clock;
601 453
602 /* 454 /*
@@ -610,10 +462,7 @@ struct wl1271 {
610 * AP-mode - links indexed by HLID. The global and broadcast links 462 * AP-mode - links indexed by HLID. The global and broadcast links
611 * are always active. 463 * are always active.
612 */ 464 */
613 struct wl1271_link links[AP_MAX_LINKS]; 465 struct wl1271_link links[WL12XX_MAX_LINKS];
614
615 /* the hlid of the link where the last transmitted skb came from */
616 int last_tx_hlid;
617 466
618 /* AP-mode - a bitmap of links currently in PS mode according to FW */ 467 /* AP-mode - a bitmap of links currently in PS mode according to FW */
619 u32 ap_fw_ps_map; 468 u32 ap_fw_ps_map;
@@ -632,21 +481,173 @@ struct wl1271 {
632 481
633 /* AP-mode - number of currently connected stations */ 482 /* AP-mode - number of currently connected stations */
634 int active_sta_count; 483 int active_sta_count;
484
485 /* last wlvif we transmitted from */
486 struct wl12xx_vif *last_wlvif;
635}; 487};
636 488
637struct wl1271_station { 489struct wl1271_station {
638 u8 hlid; 490 u8 hlid;
639}; 491};
640 492
493struct wl12xx_vif {
494 struct wl1271 *wl;
495 struct list_head list;
496 unsigned long flags;
497 u8 bss_type;
498 u8 p2p; /* we are using p2p role */
499 u8 role_id;
500
501 /* sta/ibss specific */
502 u8 dev_role_id;
503 u8 dev_hlid;
504
505 union {
506 struct {
507 u8 hlid;
508 u8 ba_rx_bitmap;
509
510 u8 basic_rate_idx;
511 u8 ap_rate_idx;
512 u8 p2p_rate_idx;
513 } sta;
514 struct {
515 u8 global_hlid;
516 u8 bcast_hlid;
517
518 /* HLIDs bitmap of associated stations */
519 unsigned long sta_hlid_map[BITS_TO_LONGS(
520 WL12XX_MAX_LINKS)];
521
522 /* recoreded keys - set here before AP startup */
523 struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
524
525 u8 mgmt_rate_idx;
526 u8 bcast_rate_idx;
527 u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
528 } ap;
529 };
530
531 /* the hlid of the last transmitted skb */
532 int last_tx_hlid;
533
534 unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
535
536 u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
537 u8 ssid_len;
538
539 /* The current band */
540 enum ieee80211_band band;
541 int channel;
542
543 u32 bitrate_masks[IEEE80211_NUM_BANDS];
544 u32 basic_rate_set;
545
546 /*
547 * currently configured rate set:
548 * bits 0-15 - 802.11abg rates
549 * bits 16-23 - 802.11n MCS index mask
550 * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
551 */
552 u32 basic_rate;
553 u32 rate_set;
554
555 /* probe-req template for the current AP */
556 struct sk_buff *probereq;
557
558 /* Beaconing interval (needed for ad-hoc) */
559 u32 beacon_int;
560
561 /* Default key (for WEP) */
562 u32 default_key;
563
564 /* Our association ID */
565 u16 aid;
566
567 /* Session counter for the chipset */
568 int session_counter;
569
570 struct completion *ps_compl;
571 struct delayed_work pspoll_work;
572
573 /* counter for ps-poll delivery failures */
574 int ps_poll_failures;
575
576 /* retry counter for PSM entries */
577 u8 psm_entry_retry;
578
579 /* in dBm */
580 int power_level;
581
582 int rssi_thold;
583 int last_rssi_event;
584
585 /* RX BA constraint value */
586 bool ba_support;
587 bool ba_allowed;
588
589 /* Rx Streaming */
590 struct work_struct rx_streaming_enable_work;
591 struct work_struct rx_streaming_disable_work;
592 struct timer_list rx_streaming_timer;
593
594 /*
595 * This struct must be last!
596 * data that has to be saved acrossed reconfigs (e.g. recovery)
597 * should be declared in this struct.
598 */
599 struct {
600 u8 persistent[0];
601 /*
602 * Security sequence number
603 * bits 0-15: lower 16 bits part of sequence number
604 * bits 16-47: higher 32 bits part of sequence number
605 * bits 48-63: not in use
606 */
607 u64 tx_security_seq;
608
609 /* 8 bits of the last sequence number in use */
610 u8 tx_security_last_seq_lsb;
611 };
612};
613
614static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
615{
616 return (struct wl12xx_vif *)vif->drv_priv;
617}
618
619static inline
620struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
621{
622 return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
623}
624
625#define wl12xx_for_each_wlvif(wl, wlvif) \
626 list_for_each_entry(wlvif, &wl->wlvif_list, list)
627
628#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
629 list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
630
631#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type) \
632 wl12xx_for_each_wlvif(wl, wlvif) \
633 if (wlvif->bss_type == _bss_type)
634
635#define wl12xx_for_each_wlvif_sta(wl, wlvif) \
636 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
637
638#define wl12xx_for_each_wlvif_ap(wl, wlvif) \
639 wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
640
641int wl1271_plt_start(struct wl1271 *wl); 641int wl1271_plt_start(struct wl1271 *wl);
642int wl1271_plt_stop(struct wl1271 *wl); 642int wl1271_plt_stop(struct wl1271 *wl);
643int wl1271_recalc_rx_streaming(struct wl1271 *wl); 643int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
644void wl12xx_queue_recovery_work(struct wl1271 *wl); 644void wl12xx_queue_recovery_work(struct wl1271 *wl);
645size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen); 645size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
646 646
647#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */ 647#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
648 648
649#define SESSION_COUNTER_MAX 7 /* maximum value for the session counter */ 649#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
650#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
650 651
651#define WL1271_DEFAULT_POWER_LEVEL 0 652#define WL1271_DEFAULT_POWER_LEVEL 0
652 653
@@ -669,8 +670,8 @@ size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
669/* Each RX/TX transaction requires an end-of-transaction transfer */ 670/* Each RX/TX transaction requires an end-of-transaction transfer */
670#define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0) 671#define WL12XX_QUIRK_END_OF_TRANSACTION BIT(0)
671 672
672/* WL128X requires aggregated packets to be aligned to the SDIO block size */ 673/* wl127x and SPI don't support SDIO block size alignment */
673#define WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT BIT(2) 674#define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT BIT(2)
674 675
675/* Older firmwares did not implement the FW logger over bus feature */ 676/* Older firmwares did not implement the FW logger over bus feature */
676#define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4) 677#define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED BIT(4)
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
index f7971d3b0898..8f0ffaf62309 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_80211.h
+++ b/drivers/net/wireless/wl12xx/wl12xx_80211.h
@@ -116,11 +116,6 @@ struct wl12xx_ps_poll_template {
116 u8 ta[ETH_ALEN]; 116 u8 ta[ETH_ALEN];
117} __packed; 117} __packed;
118 118
119struct wl12xx_qos_null_data_template {
120 struct ieee80211_header header;
121 __le16 qos_ctl;
122} __packed;
123
124struct wl12xx_arp_rsp_template { 119struct wl12xx_arp_rsp_template {
125 struct ieee80211_hdr_3addr hdr; 120 struct ieee80211_hdr_3addr hdr;
126 121
diff --git a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
index 973b11060a8f..3c96b332184e 100644
--- a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
+++ b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
@@ -2,7 +2,7 @@
2#include <linux/err.h> 2#include <linux/err.h>
3#include <linux/wl12xx.h> 3#include <linux/wl12xx.h>
4 4
5static const struct wl12xx_platform_data *platform_data; 5static struct wl12xx_platform_data *platform_data;
6 6
7int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data) 7int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
8{ 8{
@@ -18,7 +18,7 @@ int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
18 return 0; 18 return 0;
19} 19}
20 20
21const struct wl12xx_platform_data *wl12xx_get_platform_data(void) 21struct wl12xx_platform_data *wl12xx_get_platform_data(void)
22{ 22{
23 if (!platform_data) 23 if (!platform_data)
24 return ERR_PTR(-ENODEV); 24 return ERR_PTR(-ENODEV);
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index 66cedf6eb5c2..17f2a768e2ad 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1695,6 +1695,23 @@ static inline bool ieee80211_is_robust_mgmt_frame(struct ieee80211_hdr *hdr)
1695} 1695}
1696 1696
1697/** 1697/**
1698 * ieee80211_is_public_action - check if frame is a public action frame
1699 * @hdr: the frame
1700 * @len: length of the frame
1701 */
1702static inline bool ieee80211_is_public_action(struct ieee80211_hdr *hdr,
1703 size_t len)
1704{
1705 struct ieee80211_mgmt *mgmt = (void *)hdr;
1706
1707 if (len < IEEE80211_MIN_ACTION_SIZE)
1708 return false;
1709 if (!ieee80211_is_action(hdr->frame_control))
1710 return false;
1711 return mgmt->u.action.category == WLAN_CATEGORY_PUBLIC;
1712}
1713
1714/**
1698 * ieee80211_fhss_chan_to_freq - get channel frequency 1715 * ieee80211_fhss_chan_to_freq - get channel frequency
1699 * @channel: the FHSS channel 1716 * @channel: the FHSS channel
1700 * 1717 *
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index f51e3bf93a96..a18760684fc9 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -2785,9 +2785,11 @@ enum nl80211_ap_sme_features {
2785 * @NL80211_FEATURE_SK_TX_STATUS: This driver supports reflecting back 2785 * @NL80211_FEATURE_SK_TX_STATUS: This driver supports reflecting back
2786 * TX status to the socket error queue when requested with the 2786 * TX status to the socket error queue when requested with the
2787 * socket option. 2787 * socket option.
2788 * @NL80211_FEATURE_HT_IBSS: This driver supports IBSS with HT datarates.
2788 */ 2789 */
2789enum nl80211_feature_flags { 2790enum nl80211_feature_flags {
2790 NL80211_FEATURE_SK_TX_STATUS = 1 << 0, 2791 NL80211_FEATURE_SK_TX_STATUS = 1 << 0,
2792 NL80211_FEATURE_HT_IBSS = 1 << 1,
2791}; 2793};
2792 2794
2793/** 2795/**
diff --git a/include/linux/wl12xx.h b/include/linux/wl12xx.h
index 4b697395326e..0d6373195d32 100644
--- a/include/linux/wl12xx.h
+++ b/include/linux/wl12xx.h
@@ -54,6 +54,9 @@ struct wl12xx_platform_data {
54 int board_ref_clock; 54 int board_ref_clock;
55 int board_tcxo_clock; 55 int board_tcxo_clock;
56 unsigned long platform_quirks; 56 unsigned long platform_quirks;
57 bool pwr_in_suspend;
58
59 struct wl1271_if_operations *ops;
57}; 60};
58 61
59/* Platform does not support level trigger interrupts */ 62/* Platform does not support level trigger interrupts */
@@ -73,6 +76,6 @@ int wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
73 76
74#endif 77#endif
75 78
76const struct wl12xx_platform_data *wl12xx_get_platform_data(void); 79struct wl12xx_platform_data *wl12xx_get_platform_data(void);
77 80
78#endif 81#endif
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 835f3b229b84..980e59f37d4f 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -36,6 +36,11 @@
36#define PF_BLUETOOTH AF_BLUETOOTH 36#define PF_BLUETOOTH AF_BLUETOOTH
37#endif 37#endif
38 38
39/* Bluetooth versions */
40#define BLUETOOTH_VER_1_1 1
41#define BLUETOOTH_VER_1_2 2
42#define BLUETOOTH_VER_2_0 3
43
39/* Reserv for core and drivers use */ 44/* Reserv for core and drivers use */
40#define BT_SKB_RESERVE 8 45#define BT_SKB_RESERVE 8
41 46
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 139ce2aa6eee..67ad98430348 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -88,6 +88,14 @@ enum {
88 HCI_RESET, 88 HCI_RESET,
89}; 89};
90 90
91/*
92 * BR/EDR and/or LE controller flags: the flags defined here should represent
93 * states from the controller.
94 */
95enum {
96 HCI_LE_SCAN,
97};
98
91/* HCI ioctl defines */ 99/* HCI ioctl defines */
92#define HCIDEVUP _IOW('H', 201, int) 100#define HCIDEVUP _IOW('H', 201, int)
93#define HCIDEVDOWN _IOW('H', 202, int) 101#define HCIDEVDOWN _IOW('H', 202, int)
@@ -453,6 +461,14 @@ struct hci_rp_user_confirm_reply {
453 461
454#define HCI_OP_USER_CONFIRM_NEG_REPLY 0x042d 462#define HCI_OP_USER_CONFIRM_NEG_REPLY 0x042d
455 463
464#define HCI_OP_USER_PASSKEY_REPLY 0x042e
465struct hci_cp_user_passkey_reply {
466 bdaddr_t bdaddr;
467 __le32 passkey;
468} __packed;
469
470#define HCI_OP_USER_PASSKEY_NEG_REPLY 0x042f
471
456#define HCI_OP_REMOTE_OOB_DATA_REPLY 0x0430 472#define HCI_OP_REMOTE_OOB_DATA_REPLY 0x0430
457struct hci_cp_remote_oob_data_reply { 473struct hci_cp_remote_oob_data_reply {
458 bdaddr_t bdaddr; 474 bdaddr_t bdaddr;
@@ -669,6 +685,12 @@ struct hci_rp_read_local_oob_data {
669 685
670#define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58 686#define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58
671 687
688#define HCI_OP_READ_FLOW_CONTROL_MODE 0x0c66
689struct hci_rp_read_flow_control_mode {
690 __u8 status;
691 __u8 mode;
692} __packed;
693
672#define HCI_OP_WRITE_LE_HOST_SUPPORTED 0x0c6d 694#define HCI_OP_WRITE_LE_HOST_SUPPORTED 0x0c6d
673struct hci_cp_write_le_host_supported { 695struct hci_cp_write_le_host_supported {
674 __u8 le; 696 __u8 le;
@@ -760,6 +782,15 @@ struct hci_rp_le_read_buffer_size {
760 __u8 le_max_pkt; 782 __u8 le_max_pkt;
761} __packed; 783} __packed;
762 784
785#define HCI_OP_LE_SET_SCAN_PARAM 0x200b
786struct hci_cp_le_set_scan_param {
787 __u8 type;
788 __le16 interval;
789 __le16 window;
790 __u8 own_address_type;
791 __u8 filter_policy;
792} __packed;
793
763#define HCI_OP_LE_SET_SCAN_ENABLE 0x200c 794#define HCI_OP_LE_SET_SCAN_ENABLE 0x200c
764struct hci_cp_le_set_scan_enable { 795struct hci_cp_le_set_scan_enable {
765 __u8 enable; 796 __u8 enable;
@@ -1076,6 +1107,11 @@ struct hci_ev_user_confirm_req {
1076 __le32 passkey; 1107 __le32 passkey;
1077} __packed; 1108} __packed;
1078 1109
1110#define HCI_EV_USER_PASSKEY_REQUEST 0x34
1111struct hci_ev_user_passkey_req {
1112 bdaddr_t bdaddr;
1113} __packed;
1114
1079#define HCI_EV_REMOTE_OOB_DATA_REQUEST 0x35 1115#define HCI_EV_REMOTE_OOB_DATA_REQUEST 0x35
1080struct hci_ev_remote_oob_data_request { 1116struct hci_ev_remote_oob_data_request {
1081 bdaddr_t bdaddr; 1117 bdaddr_t bdaddr;
@@ -1331,4 +1367,6 @@ struct hci_inquiry_req {
1331}; 1367};
1332#define IREQ_CACHE_FLUSH 0x0001 1368#define IREQ_CACHE_FLUSH 0x0001
1333 1369
1370extern int enable_hs;
1371
1334#endif /* __HCI_H */ 1372#endif /* __HCI_H */
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index f333e7682607..ea4395f1d260 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -170,6 +170,8 @@ struct hci_dev {
170 __u32 amp_max_flush_to; 170 __u32 amp_max_flush_to;
171 __u32 amp_be_flush_to; 171 __u32 amp_be_flush_to;
172 172
173 __u8 flow_ctl_mode;
174
173 unsigned int auto_accept_delay; 175 unsigned int auto_accept_delay;
174 176
175 unsigned long quirks; 177 unsigned long quirks;
@@ -250,6 +252,8 @@ struct hci_dev {
250 252
251 struct module *owner; 253 struct module *owner;
252 254
255 unsigned long dev_flags;
256
253 int (*open)(struct hci_dev *hdev); 257 int (*open)(struct hci_dev *hdev);
254 int (*close)(struct hci_dev *hdev); 258 int (*close)(struct hci_dev *hdev);
255 int (*flush)(struct hci_dev *hdev); 259 int (*flush)(struct hci_dev *hdev);
@@ -917,11 +921,13 @@ int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
917int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); 921int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
918int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 922int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
919 u8 persistent); 923 u8 persistent);
920int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 924int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
921int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 925 u8 addr_type);
922int mgmt_disconnect_failed(struct hci_dev *hdev); 926int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
923int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type, 927 u8 addr_type);
924 u8 status); 928int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
929int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
930 u8 addr_type, u8 status);
925int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 931int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
926int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 932int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
927 u8 status); 933 u8 status);
@@ -933,14 +939,20 @@ int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
933 u8 status); 939 u8 status);
934int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, 940int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
935 bdaddr_t *bdaddr, u8 status); 941 bdaddr_t *bdaddr, u8 status);
942int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr);
943int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
944 u8 status);
945int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
946 bdaddr_t *bdaddr, u8 status);
936int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status); 947int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
937int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 948int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
938int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash, 949int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
939 u8 *randomizer, u8 status); 950 u8 *randomizer, u8 status);
940int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type, 951int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
941 u8 *dev_class, s8 rssi, u8 *eir); 952 u8 addr_type, u8 *dev_class, s8 rssi, u8 *eir);
942int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name); 953int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name);
943int mgmt_inquiry_failed(struct hci_dev *hdev, u8 status); 954int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
955int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
944int mgmt_discovering(struct hci_dev *hdev, u8 discovering); 956int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
945int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr); 957int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
946int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr); 958int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 875021ad0675..30719eb2e77c 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -792,7 +792,6 @@ static inline __u8 __ctrl_size(struct l2cap_chan *chan)
792} 792}
793 793
794extern int disable_ertm; 794extern int disable_ertm;
795extern int enable_hs;
796 795
797int l2cap_init_sockets(void); 796int l2cap_init_sockets(void);
798void l2cap_cleanup_sockets(void); 797void l2cap_cleanup_sockets(void);
@@ -810,5 +809,6 @@ int l2cap_chan_connect(struct l2cap_chan *chan);
810int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 809int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
811 u32 priority); 810 u32 priority);
812void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 811void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
812int l2cap_chan_check_security(struct l2cap_chan *chan);
813 813
814#endif /* __L2CAP_H */ 814#endif /* __L2CAP_H */
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 3e320c9cae8f..3b6880690a78 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -23,6 +23,23 @@
23 23
24#define MGMT_INDEX_NONE 0xFFFF 24#define MGMT_INDEX_NONE 0xFFFF
25 25
26#define MGMT_STATUS_SUCCESS 0x00
27#define MGMT_STATUS_UNKNOWN_COMMAND 0x01
28#define MGMT_STATUS_NOT_CONNECTED 0x02
29#define MGMT_STATUS_FAILED 0x03
30#define MGMT_STATUS_CONNECT_FAILED 0x04
31#define MGMT_STATUS_AUTH_FAILED 0x05
32#define MGMT_STATUS_NOT_PAIRED 0x06
33#define MGMT_STATUS_NO_RESOURCES 0x07
34#define MGMT_STATUS_TIMEOUT 0x08
35#define MGMT_STATUS_ALREADY_CONNECTED 0x09
36#define MGMT_STATUS_BUSY 0x0a
37#define MGMT_STATUS_REJECTED 0x0b
38#define MGMT_STATUS_NOT_SUPPORTED 0x0c
39#define MGMT_STATUS_INVALID_PARAMS 0x0d
40#define MGMT_STATUS_DISCONNECTED 0x0e
41#define MGMT_STATUS_NOT_POWERED 0x0f
42
26struct mgmt_hdr { 43struct mgmt_hdr {
27 __le16 opcode; 44 __le16 opcode;
28 __le16 index; 45 __le16 index;
@@ -119,6 +136,10 @@ struct mgmt_cp_remove_keys {
119 bdaddr_t bdaddr; 136 bdaddr_t bdaddr;
120 __u8 disconnect; 137 __u8 disconnect;
121} __packed; 138} __packed;
139struct mgmt_rp_remove_keys {
140 bdaddr_t bdaddr;
141 __u8 status;
142};
122 143
123#define MGMT_OP_DISCONNECT 0x000F 144#define MGMT_OP_DISCONNECT 0x000F
124struct mgmt_cp_disconnect { 145struct mgmt_cp_disconnect {
@@ -126,11 +147,12 @@ struct mgmt_cp_disconnect {
126} __packed; 147} __packed;
127struct mgmt_rp_disconnect { 148struct mgmt_rp_disconnect {
128 bdaddr_t bdaddr; 149 bdaddr_t bdaddr;
150 __u8 status;
129} __packed; 151} __packed;
130 152
131#define MGMT_ADDR_BREDR 0x00 153#define MGMT_ADDR_BREDR 0x00
132#define MGMT_ADDR_LE 0x01 154#define MGMT_ADDR_LE_PUBLIC 0x01
133#define MGMT_ADDR_BREDR_LE 0x02 155#define MGMT_ADDR_LE_RANDOM 0x02
134#define MGMT_ADDR_INVALID 0xff 156#define MGMT_ADDR_INVALID 0xff
135 157
136struct mgmt_addr_info { 158struct mgmt_addr_info {
@@ -167,11 +189,11 @@ struct mgmt_cp_set_io_capability {
167 189
168#define MGMT_OP_PAIR_DEVICE 0x0014 190#define MGMT_OP_PAIR_DEVICE 0x0014
169struct mgmt_cp_pair_device { 191struct mgmt_cp_pair_device {
170 bdaddr_t bdaddr; 192 struct mgmt_addr_info addr;
171 __u8 io_cap; 193 __u8 io_cap;
172} __packed; 194} __packed;
173struct mgmt_rp_pair_device { 195struct mgmt_rp_pair_device {
174 bdaddr_t bdaddr; 196 struct mgmt_addr_info addr;
175 __u8 status; 197 __u8 status;
176} __packed; 198} __packed;
177 199
@@ -210,6 +232,9 @@ struct mgmt_cp_remove_remote_oob_data {
210} __packed; 232} __packed;
211 233
212#define MGMT_OP_START_DISCOVERY 0x001B 234#define MGMT_OP_START_DISCOVERY 0x001B
235struct mgmt_cp_start_discovery {
236 __u8 type;
237} __packed;
213 238
214#define MGMT_OP_STOP_DISCOVERY 0x001C 239#define MGMT_OP_STOP_DISCOVERY 0x001C
215 240
@@ -228,6 +253,17 @@ struct mgmt_cp_set_fast_connectable {
228 __u8 enable; 253 __u8 enable;
229} __packed; 254} __packed;
230 255
256#define MGMT_OP_USER_PASSKEY_REPLY 0x0020
257struct mgmt_cp_user_passkey_reply {
258 bdaddr_t bdaddr;
259 __le32 passkey;
260} __packed;
261
262#define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x0021
263struct mgmt_cp_user_passkey_neg_reply {
264 bdaddr_t bdaddr;
265} __packed;
266
231#define MGMT_EV_CMD_COMPLETE 0x0001 267#define MGMT_EV_CMD_COMPLETE 0x0001
232struct mgmt_ev_cmd_complete { 268struct mgmt_ev_cmd_complete {
233 __le16 opcode; 269 __le16 opcode;
@@ -322,3 +358,8 @@ struct mgmt_ev_device_blocked {
322struct mgmt_ev_device_unblocked { 358struct mgmt_ev_device_unblocked {
323 bdaddr_t bdaddr; 359 bdaddr_t bdaddr;
324} __packed; 360} __packed;
361
362#define MGMT_EV_USER_PASSKEY_REQUEST 0x0017
363struct mgmt_ev_user_passkey_request {
364 bdaddr_t bdaddr;
365} __packed;
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index f0e82b2e4227..3de1c39d03e5 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1149,6 +1149,7 @@ struct cfg80211_ibss_params {
1149 u8 *ssid; 1149 u8 *ssid;
1150 u8 *bssid; 1150 u8 *bssid;
1151 struct ieee80211_channel *channel; 1151 struct ieee80211_channel *channel;
1152 enum nl80211_channel_type channel_type;
1152 u8 *ie; 1153 u8 *ie;
1153 u8 ssid_len, ie_len; 1154 u8 ssid_len, ie_len;
1154 u16 beacon_interval; 1155 u16 beacon_interval;
@@ -3267,6 +3268,16 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
3267 const u8 *frame, size_t len, 3268 const u8 *frame, size_t len,
3268 int freq, gfp_t gfp); 3269 int freq, gfp_t gfp);
3269 3270
3271/*
3272 * cfg80211_can_beacon_sec_chan - test if ht40 on extension channel can be used
3273 * @wiphy: the wiphy
3274 * @chan: main channel
3275 * @channel_type: HT mode
3276 */
3277int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
3278 struct ieee80211_channel *chan,
3279 enum nl80211_channel_type channel_type);
3280
3270/* Logging, debugging and troubleshooting/diagnostic helpers. */ 3281/* Logging, debugging and troubleshooting/diagnostic helpers. */
3271 3282
3272/* wiphy_printk helpers, similar to dev_printk */ 3283/* wiphy_printk helpers, similar to dev_printk */
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index a6cd856046ab..42d53b85a808 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -77,17 +77,12 @@ static struct bnep_session *__bnep_get_session(u8 *dst)
77 77
78static void __bnep_link_session(struct bnep_session *s) 78static void __bnep_link_session(struct bnep_session *s)
79{ 79{
80 /* It's safe to call __module_get() here because sessions are added
81 by the socket layer which has to hold the reference to this module.
82 */
83 __module_get(THIS_MODULE);
84 list_add(&s->list, &bnep_session_list); 80 list_add(&s->list, &bnep_session_list);
85} 81}
86 82
87static void __bnep_unlink_session(struct bnep_session *s) 83static void __bnep_unlink_session(struct bnep_session *s)
88{ 84{
89 list_del(&s->list); 85 list_del(&s->list);
90 module_put(THIS_MODULE);
91} 86}
92 87
93static int bnep_send(struct bnep_session *s, void *data, size_t len) 88static int bnep_send(struct bnep_session *s, void *data, size_t len)
@@ -528,6 +523,7 @@ static int bnep_session(void *arg)
528 523
529 up_write(&bnep_session_sem); 524 up_write(&bnep_session_sem);
530 free_netdev(dev); 525 free_netdev(dev);
526 module_put_and_exit(0);
531 return 0; 527 return 0;
532} 528}
533 529
@@ -614,9 +610,11 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
614 610
615 __bnep_link_session(s); 611 __bnep_link_session(s);
616 612
613 __module_get(THIS_MODULE);
617 s->task = kthread_run(bnep_session, s, "kbnepd %s", dev->name); 614 s->task = kthread_run(bnep_session, s, "kbnepd %s", dev->name);
618 if (IS_ERR(s->task)) { 615 if (IS_ERR(s->task)) {
619 /* Session thread start failed, gotta cleanup. */ 616 /* Session thread start failed, gotta cleanup. */
617 module_put(THIS_MODULE);
620 unregister_netdev(dev); 618 unregister_netdev(dev);
621 __bnep_unlink_session(s); 619 __bnep_unlink_session(s);
622 err = PTR_ERR(s->task); 620 err = PTR_ERR(s->task);
diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
index 9e8940b24bba..6c9c1fd601ca 100644
--- a/net/bluetooth/cmtp/core.c
+++ b/net/bluetooth/cmtp/core.c
@@ -65,14 +65,12 @@ static struct cmtp_session *__cmtp_get_session(bdaddr_t *bdaddr)
65 65
66static void __cmtp_link_session(struct cmtp_session *session) 66static void __cmtp_link_session(struct cmtp_session *session)
67{ 67{
68 __module_get(THIS_MODULE);
69 list_add(&session->list, &cmtp_session_list); 68 list_add(&session->list, &cmtp_session_list);
70} 69}
71 70
72static void __cmtp_unlink_session(struct cmtp_session *session) 71static void __cmtp_unlink_session(struct cmtp_session *session)
73{ 72{
74 list_del(&session->list); 73 list_del(&session->list);
75 module_put(THIS_MODULE);
76} 74}
77 75
78static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci) 76static void __cmtp_copy_session(struct cmtp_session *session, struct cmtp_conninfo *ci)
@@ -325,6 +323,7 @@ static int cmtp_session(void *arg)
325 up_write(&cmtp_session_sem); 323 up_write(&cmtp_session_sem);
326 324
327 kfree(session); 325 kfree(session);
326 module_put_and_exit(0);
328 return 0; 327 return 0;
329} 328}
330 329
@@ -374,9 +373,11 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
374 373
375 __cmtp_link_session(session); 374 __cmtp_link_session(session);
376 375
376 __module_get(THIS_MODULE);
377 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d", 377 session->task = kthread_run(cmtp_session, session, "kcmtpd_ctr_%d",
378 session->num); 378 session->num);
379 if (IS_ERR(session->task)) { 379 if (IS_ERR(session->task)) {
380 module_put(THIS_MODULE);
380 err = PTR_ERR(session->task); 381 err = PTR_ERR(session->task);
381 goto unlink; 382 goto unlink;
382 } 383 }
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index de0b93e45980..b328ac611ccd 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -123,7 +123,7 @@ static void hci_acl_connect_cancel(struct hci_conn *conn)
123 123
124 BT_DBG("%p", conn); 124 BT_DBG("%p", conn);
125 125
126 if (conn->hdev->hci_ver < 2) 126 if (conn->hdev->hci_ver < BLUETOOTH_VER_1_2)
127 return; 127 return;
128 128
129 bacpy(&cp.bdaddr, &conn->dst); 129 bacpy(&cp.bdaddr, &conn->dst);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index fb3feeb185d7..ce3727ecc0c4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -54,6 +54,8 @@
54 54
55#define AUTO_OFF_TIMEOUT 2000 55#define AUTO_OFF_TIMEOUT 2000
56 56
57int enable_hs;
58
57static void hci_cmd_task(unsigned long arg); 59static void hci_cmd_task(unsigned long arg);
58static void hci_rx_task(unsigned long arg); 60static void hci_rx_task(unsigned long arg);
59static void hci_tx_task(unsigned long arg); 61static void hci_tx_task(unsigned long arg);
@@ -228,18 +230,6 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
228 /* Read Buffer Size (ACL mtu, max pkt, etc.) */ 230 /* Read Buffer Size (ACL mtu, max pkt, etc.) */
229 hci_send_cmd(hdev, HCI_OP_READ_BUFFER_SIZE, 0, NULL); 231 hci_send_cmd(hdev, HCI_OP_READ_BUFFER_SIZE, 0, NULL);
230 232
231#if 0
232 /* Host buffer size */
233 {
234 struct hci_cp_host_buffer_size cp;
235 cp.acl_mtu = cpu_to_le16(HCI_MAX_ACL_SIZE);
236 cp.sco_mtu = HCI_MAX_SCO_SIZE;
237 cp.acl_max_pkt = cpu_to_le16(0xffff);
238 cp.sco_max_pkt = cpu_to_le16(0xffff);
239 hci_send_cmd(hdev, HCI_OP_HOST_BUFFER_SIZE, sizeof(cp), &cp);
240 }
241#endif
242
243 /* Read BD Address */ 233 /* Read BD Address */
244 hci_send_cmd(hdev, HCI_OP_READ_BD_ADDR, 0, NULL); 234 hci_send_cmd(hdev, HCI_OP_READ_BD_ADDR, 0, NULL);
245 235
@@ -521,8 +511,9 @@ int hci_dev_open(__u16 dev)
521 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) 511 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
522 set_bit(HCI_RAW, &hdev->flags); 512 set_bit(HCI_RAW, &hdev->flags);
523 513
524 /* Treat all non BR/EDR controllers as raw devices for now */ 514 /* Treat all non BR/EDR controllers as raw devices if
525 if (hdev->dev_type != HCI_BREDR) 515 enable_hs is not set */
516 if (hdev->dev_type != HCI_BREDR && !enable_hs)
526 set_bit(HCI_RAW, &hdev->flags); 517 set_bit(HCI_RAW, &hdev->flags);
527 518
528 if (hdev->open(hdev)) { 519 if (hdev->open(hdev)) {
@@ -1336,14 +1327,12 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
1336{ 1327{
1337 struct bdaddr_list *entry; 1328 struct bdaddr_list *entry;
1338 1329
1339 if (bacmp(bdaddr, BDADDR_ANY) == 0) { 1330 if (bacmp(bdaddr, BDADDR_ANY) == 0)
1340 return hci_blacklist_clear(hdev); 1331 return hci_blacklist_clear(hdev);
1341 }
1342 1332
1343 entry = hci_blacklist_lookup(hdev, bdaddr); 1333 entry = hci_blacklist_lookup(hdev, bdaddr);
1344 if (!entry) { 1334 if (!entry)
1345 return -ENOENT; 1335 return -ENOENT;
1346 }
1347 1336
1348 list_del(&entry->list); 1337 list_del(&entry->list);
1349 kfree(entry); 1338 kfree(entry);
@@ -1451,12 +1440,13 @@ int hci_register_dev(struct hci_dev *hdev)
1451 1440
1452 sprintf(hdev->name, "hci%d", id); 1441 sprintf(hdev->name, "hci%d", id);
1453 hdev->id = id; 1442 hdev->id = id;
1454 list_add(&hdev->list, head); 1443 list_add_tail(&hdev->list, head);
1455 1444
1456 atomic_set(&hdev->refcnt, 1); 1445 atomic_set(&hdev->refcnt, 1);
1457 spin_lock_init(&hdev->lock); 1446 spin_lock_init(&hdev->lock);
1458 1447
1459 hdev->flags = 0; 1448 hdev->flags = 0;
1449 hdev->dev_flags = 0;
1460 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); 1450 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
1461 hdev->esco_type = (ESCO_HV1); 1451 hdev->esco_type = (ESCO_HV1);
1462 hdev->link_mode = (HCI_LM_ACCEPT); 1452 hdev->link_mode = (HCI_LM_ACCEPT);
@@ -2614,3 +2604,6 @@ int hci_cancel_inquiry(struct hci_dev *hdev)
2614 2604
2615 return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL); 2605 return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
2616} 2606}
2607
2608module_param(enable_hs, bool, 0644);
2609MODULE_PARM_DESC(enable_hs, "Enable High Speed");
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a89cf1f24e47..35cb56ed3b0b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -55,8 +55,12 @@ static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
55 55
56 BT_DBG("%s status 0x%x", hdev->name, status); 56 BT_DBG("%s status 0x%x", hdev->name, status);
57 57
58 if (status) 58 if (status) {
59 hci_dev_lock(hdev);
60 mgmt_stop_discovery_failed(hdev, status);
61 hci_dev_unlock(hdev);
59 return; 62 return;
63 }
60 64
61 clear_bit(HCI_INQUIRY, &hdev->flags); 65 clear_bit(HCI_INQUIRY, &hdev->flags);
62 66
@@ -190,6 +194,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
190 clear_bit(HCI_RESET, &hdev->flags); 194 clear_bit(HCI_RESET, &hdev->flags);
191 195
192 hci_req_complete(hdev, HCI_OP_RESET, status); 196 hci_req_complete(hdev, HCI_OP_RESET, status);
197
198 hdev->dev_flags = 0;
193} 199}
194 200
195static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) 201static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -494,7 +500,7 @@ static void hci_setup_event_mask(struct hci_dev *hdev)
494 500
495 /* CSR 1.1 dongles does not accept any bitfield so don't try to set 501 /* CSR 1.1 dongles does not accept any bitfield so don't try to set
496 * any event mask for pre 1.2 devices */ 502 * any event mask for pre 1.2 devices */
497 if (hdev->lmp_ver <= 1) 503 if (hdev->hci_ver < BLUETOOTH_VER_1_2)
498 return; 504 return;
499 505
500 events[4] |= 0x01; /* Flow Specification Complete */ 506 events[4] |= 0x01; /* Flow Specification Complete */
@@ -558,7 +564,7 @@ static void hci_setup(struct hci_dev *hdev)
558{ 564{
559 hci_setup_event_mask(hdev); 565 hci_setup_event_mask(hdev);
560 566
561 if (hdev->lmp_ver > 1) 567 if (hdev->hci_ver > BLUETOOTH_VER_1_1)
562 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL); 568 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
563 569
564 if (hdev->features[6] & LMP_SIMPLE_PAIR) { 570 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
@@ -713,6 +719,21 @@ static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
713 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status); 719 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status);
714} 720}
715 721
722static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
723 struct sk_buff *skb)
724{
725 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
726
727 BT_DBG("%s status 0x%x", hdev->name, rp->status);
728
729 if (rp->status)
730 return;
731
732 hdev->flow_ctl_mode = rp->mode;
733
734 hci_req_complete(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, rp->status);
735}
736
716static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) 737static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
717{ 738{
718 struct hci_rp_read_buffer_size *rp = (void *) skb->data; 739 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
@@ -927,6 +948,37 @@ static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
927 hci_dev_unlock(hdev); 948 hci_dev_unlock(hdev);
928} 949}
929 950
951static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
952{
953 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
954
955 BT_DBG("%s status 0x%x", hdev->name, rp->status);
956
957 hci_dev_lock(hdev);
958
959 if (test_bit(HCI_MGMT, &hdev->flags))
960 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr,
961 rp->status);
962
963 hci_dev_unlock(hdev);
964}
965
966static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
967 struct sk_buff *skb)
968{
969 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
970
971 BT_DBG("%s status 0x%x", hdev->name, rp->status);
972
973 hci_dev_lock(hdev);
974
975 if (test_bit(HCI_MGMT, &hdev->flags))
976 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
977 rp->status);
978
979 hci_dev_unlock(hdev);
980}
981
930static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev, 982static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
931 struct sk_buff *skb) 983 struct sk_buff *skb)
932{ 984{
@@ -940,6 +992,13 @@ static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
940 hci_dev_unlock(hdev); 992 hci_dev_unlock(hdev);
941} 993}
942 994
995static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
996{
997 __u8 status = *((__u8 *) skb->data);
998
999 BT_DBG("%s status 0x%x", hdev->name, status);
1000}
1001
943static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, 1002static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
944 struct sk_buff *skb) 1003 struct sk_buff *skb)
945{ 1004{
@@ -956,12 +1015,16 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
956 return; 1015 return;
957 1016
958 if (cp->enable == 0x01) { 1017 if (cp->enable == 0x01) {
1018 set_bit(HCI_LE_SCAN, &hdev->dev_flags);
1019
959 del_timer(&hdev->adv_timer); 1020 del_timer(&hdev->adv_timer);
960 1021
961 hci_dev_lock(hdev); 1022 hci_dev_lock(hdev);
962 hci_adv_entries_clear(hdev); 1023 hci_adv_entries_clear(hdev);
963 hci_dev_unlock(hdev); 1024 hci_dev_unlock(hdev);
964 } else if (cp->enable == 0x00) { 1025 } else if (cp->enable == 0x00) {
1026 clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
1027
965 mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT); 1028 mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT);
966 } 1029 }
967} 1030}
@@ -1014,7 +1077,7 @@ static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1014 hci_conn_check_pending(hdev); 1077 hci_conn_check_pending(hdev);
1015 hci_dev_lock(hdev); 1078 hci_dev_lock(hdev);
1016 if (test_bit(HCI_MGMT, &hdev->flags)) 1079 if (test_bit(HCI_MGMT, &hdev->flags))
1017 mgmt_inquiry_failed(hdev, status); 1080 mgmt_start_discovery_failed(hdev, status);
1018 hci_dev_unlock(hdev); 1081 hci_dev_unlock(hdev);
1019 return; 1082 return;
1020 } 1083 }
@@ -1437,7 +1500,7 @@ static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *
1437 data.rssi = 0x00; 1500 data.rssi = 0x00;
1438 data.ssp_mode = 0x00; 1501 data.ssp_mode = 0x00;
1439 hci_inquiry_cache_update(hdev, &data); 1502 hci_inquiry_cache_update(hdev, &data);
1440 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 1503 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
1441 info->dev_class, 0, NULL); 1504 info->dev_class, 0, NULL);
1442 } 1505 }
1443 1506
@@ -1472,7 +1535,8 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1472 conn->state = BT_CONFIG; 1535 conn->state = BT_CONFIG;
1473 hci_conn_hold(conn); 1536 hci_conn_hold(conn);
1474 conn->disc_timeout = HCI_DISCONN_TIMEOUT; 1537 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
1475 mgmt_connected(hdev, &ev->bdaddr, conn->type); 1538 mgmt_connected(hdev, &ev->bdaddr, conn->type,
1539 conn->dst_type);
1476 } else 1540 } else
1477 conn->state = BT_CONNECTED; 1541 conn->state = BT_CONNECTED;
1478 1542
@@ -1494,7 +1558,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1494 } 1558 }
1495 1559
1496 /* Set packet type for incoming connection */ 1560 /* Set packet type for incoming connection */
1497 if (!conn->out && hdev->hci_ver < 3) { 1561 if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) {
1498 struct hci_cp_change_conn_ptype cp; 1562 struct hci_cp_change_conn_ptype cp;
1499 cp.handle = ev->handle; 1563 cp.handle = ev->handle;
1500 cp.pkt_type = cpu_to_le16(conn->pkt_type); 1564 cp.pkt_type = cpu_to_le16(conn->pkt_type);
@@ -1505,7 +1569,7 @@ static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1505 conn->state = BT_CLOSED; 1569 conn->state = BT_CLOSED;
1506 if (conn->type == ACL_LINK) 1570 if (conn->type == ACL_LINK)
1507 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type, 1571 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
1508 ev->status); 1572 conn->dst_type, ev->status);
1509 } 1573 }
1510 1574
1511 if (conn->type == ACL_LINK) 1575 if (conn->type == ACL_LINK)
@@ -1604,26 +1668,27 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
1604 1668
1605 BT_DBG("%s status %d", hdev->name, ev->status); 1669 BT_DBG("%s status %d", hdev->name, ev->status);
1606 1670
1607 if (ev->status) {
1608 hci_dev_lock(hdev);
1609 mgmt_disconnect_failed(hdev);
1610 hci_dev_unlock(hdev);
1611 return;
1612 }
1613
1614 hci_dev_lock(hdev); 1671 hci_dev_lock(hdev);
1615 1672
1616 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); 1673 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1617 if (!conn) 1674 if (!conn)
1618 goto unlock; 1675 goto unlock;
1619 1676
1620 conn->state = BT_CLOSED; 1677 if (ev->status == 0)
1678 conn->state = BT_CLOSED;
1621 1679
1622 if (conn->type == ACL_LINK || conn->type == LE_LINK) 1680 if (conn->type == ACL_LINK || conn->type == LE_LINK) {
1623 mgmt_disconnected(hdev, &conn->dst, conn->type); 1681 if (ev->status != 0)
1682 mgmt_disconnect_failed(hdev, &conn->dst, ev->status);
1683 else
1684 mgmt_disconnected(hdev, &conn->dst, conn->type,
1685 conn->dst_type);
1686 }
1624 1687
1625 hci_proto_disconn_cfm(conn, ev->reason); 1688 if (ev->status == 0) {
1626 hci_conn_del(conn); 1689 hci_proto_disconn_cfm(conn, ev->reason);
1690 hci_conn_del(conn);
1691 }
1627 1692
1628unlock: 1693unlock:
1629 hci_dev_unlock(hdev); 1694 hci_dev_unlock(hdev);
@@ -1961,6 +2026,10 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
1961 hci_cc_write_ca_timeout(hdev, skb); 2026 hci_cc_write_ca_timeout(hdev, skb);
1962 break; 2027 break;
1963 2028
2029 case HCI_OP_READ_FLOW_CONTROL_MODE:
2030 hci_cc_read_flow_control_mode(hdev, skb);
2031 break;
2032
1964 case HCI_OP_READ_LOCAL_AMP_INFO: 2033 case HCI_OP_READ_LOCAL_AMP_INFO:
1965 hci_cc_read_local_amp_info(hdev, skb); 2034 hci_cc_read_local_amp_info(hdev, skb);
1966 break; 2035 break;
@@ -2009,6 +2078,17 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
2009 hci_cc_user_confirm_neg_reply(hdev, skb); 2078 hci_cc_user_confirm_neg_reply(hdev, skb);
2010 break; 2079 break;
2011 2080
2081 case HCI_OP_USER_PASSKEY_REPLY:
2082 hci_cc_user_passkey_reply(hdev, skb);
2083 break;
2084
2085 case HCI_OP_USER_PASSKEY_NEG_REPLY:
2086 hci_cc_user_passkey_neg_reply(hdev, skb);
2087
2088 case HCI_OP_LE_SET_SCAN_PARAM:
2089 hci_cc_le_set_scan_param(hdev, skb);
2090 break;
2091
2012 case HCI_OP_LE_SET_SCAN_ENABLE: 2092 case HCI_OP_LE_SET_SCAN_ENABLE:
2013 hci_cc_le_set_scan_enable(hdev, skb); 2093 hci_cc_le_set_scan_enable(hdev, skb);
2014 break; 2094 break;
@@ -2096,7 +2176,7 @@ static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2096 2176
2097 case HCI_OP_DISCONNECT: 2177 case HCI_OP_DISCONNECT:
2098 if (ev->status != 0) 2178 if (ev->status != 0)
2099 mgmt_disconnect_failed(hdev); 2179 mgmt_disconnect_failed(hdev, NULL, ev->status);
2100 break; 2180 break;
2101 2181
2102 case HCI_OP_LE_CREATE_CONN: 2182 case HCI_OP_LE_CREATE_CONN:
@@ -2444,7 +2524,7 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
2444 data.rssi = info->rssi; 2524 data.rssi = info->rssi;
2445 data.ssp_mode = 0x00; 2525 data.ssp_mode = 0x00;
2446 hci_inquiry_cache_update(hdev, &data); 2526 hci_inquiry_cache_update(hdev, &data);
2447 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 2527 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2448 info->dev_class, info->rssi, 2528 info->dev_class, info->rssi,
2449 NULL); 2529 NULL);
2450 } 2530 }
@@ -2461,7 +2541,7 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
2461 data.rssi = info->rssi; 2541 data.rssi = info->rssi;
2462 data.ssp_mode = 0x00; 2542 data.ssp_mode = 0x00;
2463 hci_inquiry_cache_update(hdev, &data); 2543 hci_inquiry_cache_update(hdev, &data);
2464 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 2544 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2465 info->dev_class, info->rssi, 2545 info->dev_class, info->rssi,
2466 NULL); 2546 NULL);
2467 } 2547 }
@@ -2604,7 +2684,7 @@ static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct
2604 data.rssi = info->rssi; 2684 data.rssi = info->rssi;
2605 data.ssp_mode = 0x01; 2685 data.ssp_mode = 0x01;
2606 hci_inquiry_cache_update(hdev, &data); 2686 hci_inquiry_cache_update(hdev, &data);
2607 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 2687 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2608 info->dev_class, info->rssi, info->data); 2688 info->dev_class, info->rssi, info->data);
2609 } 2689 }
2610 2690
@@ -2768,6 +2848,21 @@ unlock:
2768 hci_dev_unlock(hdev); 2848 hci_dev_unlock(hdev);
2769} 2849}
2770 2850
2851static inline void hci_user_passkey_request_evt(struct hci_dev *hdev,
2852 struct sk_buff *skb)
2853{
2854 struct hci_ev_user_passkey_req *ev = (void *) skb->data;
2855
2856 BT_DBG("%s", hdev->name);
2857
2858 hci_dev_lock(hdev);
2859
2860 if (test_bit(HCI_MGMT, &hdev->flags))
2861 mgmt_user_passkey_request(hdev, &ev->bdaddr);
2862
2863 hci_dev_unlock(hdev);
2864}
2865
2771static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2866static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2772{ 2867{
2773 struct hci_ev_simple_pair_complete *ev = (void *) skb->data; 2868 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
@@ -2868,14 +2963,15 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
2868 } 2963 }
2869 2964
2870 if (ev->status) { 2965 if (ev->status) {
2871 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type, ev->status); 2966 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
2967 conn->dst_type, ev->status);
2872 hci_proto_connect_cfm(conn, ev->status); 2968 hci_proto_connect_cfm(conn, ev->status);
2873 conn->state = BT_CLOSED; 2969 conn->state = BT_CLOSED;
2874 hci_conn_del(conn); 2970 hci_conn_del(conn);
2875 goto unlock; 2971 goto unlock;
2876 } 2972 }
2877 2973
2878 mgmt_connected(hdev, &ev->bdaddr, conn->type); 2974 mgmt_connected(hdev, &ev->bdaddr, conn->type, conn->dst_type);
2879 2975
2880 conn->sec_level = BT_SECURITY_LOW; 2976 conn->sec_level = BT_SECURITY_LOW;
2881 conn->handle = __le16_to_cpu(ev->handle); 2977 conn->handle = __le16_to_cpu(ev->handle);
@@ -3106,6 +3202,10 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3106 hci_user_confirm_request_evt(hdev, skb); 3202 hci_user_confirm_request_evt(hdev, skb);
3107 break; 3203 break;
3108 3204
3205 case HCI_EV_USER_PASSKEY_REQUEST:
3206 hci_user_passkey_request_evt(hdev, skb);
3207 break;
3208
3109 case HCI_EV_SIMPLE_PAIR_COMPLETE: 3209 case HCI_EV_SIMPLE_PAIR_COMPLETE:
3110 hci_simple_pair_complete_evt(hdev, skb); 3210 hci_simple_pair_complete_evt(hdev, skb);
3111 break; 3211 break;
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index e8a6837996cf..014fdec17113 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -57,7 +57,6 @@
57#include <net/bluetooth/smp.h> 57#include <net/bluetooth/smp.h>
58 58
59int disable_ertm; 59int disable_ertm;
60int enable_hs;
61 60
62static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN; 61static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
63static u8 l2cap_fixed_chan[8] = { L2CAP_FC_L2CAP, }; 62static u8 l2cap_fixed_chan[8] = { L2CAP_FC_L2CAP, };
@@ -97,7 +96,6 @@ static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16
97 return c; 96 return c;
98 } 97 }
99 return NULL; 98 return NULL;
100
101} 99}
102 100
103static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid) 101static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid)
@@ -154,12 +152,9 @@ static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src)
154 152
155 list_for_each_entry(c, &chan_list, global_l) { 153 list_for_each_entry(c, &chan_list, global_l) {
156 if (c->sport == psm && !bacmp(&bt_sk(c->sk)->src, src)) 154 if (c->sport == psm && !bacmp(&bt_sk(c->sk)->src, src))
157 goto found; 155 return c;
158 } 156 }
159 157 return NULL;
160 c = NULL;
161found:
162 return c;
163} 158}
164 159
165int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm) 160int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
@@ -234,8 +229,37 @@ static void l2cap_clear_timer(struct l2cap_chan *chan, struct timer_list *timer)
234 chan_put(chan); 229 chan_put(chan);
235} 230}
236 231
232static char *state_to_string(int state)
233{
234 switch(state) {
235 case BT_CONNECTED:
236 return "BT_CONNECTED";
237 case BT_OPEN:
238 return "BT_OPEN";
239 case BT_BOUND:
240 return "BT_BOUND";
241 case BT_LISTEN:
242 return "BT_LISTEN";
243 case BT_CONNECT:
244 return "BT_CONNECT";
245 case BT_CONNECT2:
246 return "BT_CONNECT2";
247 case BT_CONFIG:
248 return "BT_CONFIG";
249 case BT_DISCONN:
250 return "BT_DISCONN";
251 case BT_CLOSED:
252 return "BT_CLOSED";
253 }
254
255 return "invalid state";
256}
257
237static void l2cap_state_change(struct l2cap_chan *chan, int state) 258static void l2cap_state_change(struct l2cap_chan *chan, int state)
238{ 259{
260 BT_DBG("%p %s -> %s", chan, state_to_string(chan->state),
261 state_to_string(state));
262
239 chan->state = state; 263 chan->state = state;
240 chan->ops->state_change(chan->data, state); 264 chan->ops->state_change(chan->data, state);
241} 265}
@@ -518,7 +542,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
518} 542}
519 543
520/* Service level security */ 544/* Service level security */
521static inline int l2cap_check_security(struct l2cap_chan *chan) 545int l2cap_chan_check_security(struct l2cap_chan *chan)
522{ 546{
523 struct l2cap_conn *conn = chan->conn; 547 struct l2cap_conn *conn = chan->conn;
524 __u8 auth_type; 548 __u8 auth_type;
@@ -664,7 +688,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
664 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)) 688 if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
665 return; 689 return;
666 690
667 if (l2cap_check_security(chan) && 691 if (l2cap_chan_check_security(chan) &&
668 __l2cap_no_conn_pending(chan)) { 692 __l2cap_no_conn_pending(chan)) {
669 struct l2cap_conn_req req; 693 struct l2cap_conn_req req;
670 req.scid = cpu_to_le16(chan->scid); 694 req.scid = cpu_to_le16(chan->scid);
@@ -754,7 +778,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
754 if (chan->state == BT_CONNECT) { 778 if (chan->state == BT_CONNECT) {
755 struct l2cap_conn_req req; 779 struct l2cap_conn_req req;
756 780
757 if (!l2cap_check_security(chan) || 781 if (!l2cap_chan_check_security(chan) ||
758 !__l2cap_no_conn_pending(chan)) { 782 !__l2cap_no_conn_pending(chan)) {
759 bh_unlock_sock(sk); 783 bh_unlock_sock(sk);
760 continue; 784 continue;
@@ -787,7 +811,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
787 rsp.scid = cpu_to_le16(chan->dcid); 811 rsp.scid = cpu_to_le16(chan->dcid);
788 rsp.dcid = cpu_to_le16(chan->scid); 812 rsp.dcid = cpu_to_le16(chan->scid);
789 813
790 if (l2cap_check_security(chan)) { 814 if (l2cap_chan_check_security(chan)) {
791 if (bt_sk(sk)->defer_setup) { 815 if (bt_sk(sk)->defer_setup) {
792 struct sock *parent = bt_sk(sk)->parent; 816 struct sock *parent = bt_sk(sk)->parent;
793 rsp.result = cpu_to_le16(L2CAP_CR_PEND); 817 rsp.result = cpu_to_le16(L2CAP_CR_PEND);
@@ -1181,7 +1205,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
1181 if (hcon->state == BT_CONNECTED) { 1205 if (hcon->state == BT_CONNECTED) {
1182 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) { 1206 if (chan->chan_type != L2CAP_CHAN_CONN_ORIENTED) {
1183 __clear_chan_timer(chan); 1207 __clear_chan_timer(chan);
1184 if (l2cap_check_security(chan)) 1208 if (l2cap_chan_check_security(chan))
1185 l2cap_state_change(chan, BT_CONNECTED); 1209 l2cap_state_change(chan, BT_CONNECTED);
1186 } else 1210 } else
1187 l2cap_do_start(chan); 1211 l2cap_do_start(chan);
@@ -1318,14 +1342,12 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq)
1318 if (!skb) 1342 if (!skb)
1319 return; 1343 return;
1320 1344
1321 do { 1345 while (bt_cb(skb)->tx_seq != tx_seq) {
1322 if (bt_cb(skb)->tx_seq == tx_seq)
1323 break;
1324
1325 if (skb_queue_is_last(&chan->tx_q, skb)) 1346 if (skb_queue_is_last(&chan->tx_q, skb))
1326 return; 1347 return;
1327 1348
1328 } while ((skb = skb_queue_next(&chan->tx_q, skb))); 1349 skb = skb_queue_next(&chan->tx_q, skb);
1350 }
1329 1351
1330 if (chan->remote_max_tx && 1352 if (chan->remote_max_tx &&
1331 bt_cb(skb)->retries == chan->remote_max_tx) { 1353 bt_cb(skb)->retries == chan->remote_max_tx) {
@@ -1906,7 +1928,7 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
1906{ 1928{
1907 struct l2cap_conf_efs efs; 1929 struct l2cap_conf_efs efs;
1908 1930
1909 switch(chan->mode) { 1931 switch (chan->mode) {
1910 case L2CAP_MODE_ERTM: 1932 case L2CAP_MODE_ERTM:
1911 efs.id = chan->local_id; 1933 efs.id = chan->local_id;
1912 efs.stype = chan->local_stype; 1934 efs.stype = chan->local_stype;
@@ -2606,7 +2628,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
2606 chan->ident = cmd->ident; 2628 chan->ident = cmd->ident;
2607 2629
2608 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) { 2630 if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE) {
2609 if (l2cap_check_security(chan)) { 2631 if (l2cap_chan_check_security(chan)) {
2610 if (bt_sk(sk)->defer_setup) { 2632 if (bt_sk(sk)->defer_setup) {
2611 l2cap_state_change(chan, BT_CONNECT2); 2633 l2cap_state_change(chan, BT_CONNECT2);
2612 result = L2CAP_CR_PEND; 2634 result = L2CAP_CR_PEND;
@@ -3019,7 +3041,7 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
3019 3041
3020 /* don't delete l2cap channel if sk is owned by user */ 3042 /* don't delete l2cap channel if sk is owned by user */
3021 if (sock_owned_by_user(sk)) { 3043 if (sock_owned_by_user(sk)) {
3022 l2cap_state_change(chan,BT_DISCONN); 3044 l2cap_state_change(chan, BT_DISCONN);
3023 __clear_chan_timer(chan); 3045 __clear_chan_timer(chan);
3024 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT); 3046 __set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
3025 bh_unlock_sock(sk); 3047 bh_unlock_sock(sk);
@@ -3562,14 +3584,10 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
3562 bt_cb(skb)->sar = sar; 3584 bt_cb(skb)->sar = sar;
3563 3585
3564 next_skb = skb_peek(&chan->srej_q); 3586 next_skb = skb_peek(&chan->srej_q);
3565 if (!next_skb) {
3566 __skb_queue_tail(&chan->srej_q, skb);
3567 return 0;
3568 }
3569 3587
3570 tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq); 3588 tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq);
3571 3589
3572 do { 3590 while (next_skb) {
3573 if (bt_cb(next_skb)->tx_seq == tx_seq) 3591 if (bt_cb(next_skb)->tx_seq == tx_seq)
3574 return -EINVAL; 3592 return -EINVAL;
3575 3593
@@ -3582,9 +3600,10 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
3582 } 3600 }
3583 3601
3584 if (skb_queue_is_last(&chan->srej_q, next_skb)) 3602 if (skb_queue_is_last(&chan->srej_q, next_skb))
3585 break; 3603 next_skb = NULL;
3586 3604 else
3587 } while ((next_skb = skb_queue_next(&chan->srej_q, next_skb))); 3605 next_skb = skb_queue_next(&chan->srej_q, next_skb);
3606 }
3588 3607
3589 __skb_queue_tail(&chan->srej_q, skb); 3608 __skb_queue_tail(&chan->srej_q, skb);
3590 3609
@@ -3788,7 +3807,7 @@ static void l2cap_resend_srejframe(struct l2cap_chan *chan, u16 tx_seq)
3788 } 3807 }
3789} 3808}
3790 3809
3791static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq) 3810static int l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
3792{ 3811{
3793 struct srej_list *new; 3812 struct srej_list *new;
3794 u32 control; 3813 u32 control;
@@ -3799,6 +3818,9 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
3799 l2cap_send_sframe(chan, control); 3818 l2cap_send_sframe(chan, control);
3800 3819
3801 new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC); 3820 new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC);
3821 if (!new)
3822 return -ENOMEM;
3823
3802 new->tx_seq = chan->expected_tx_seq; 3824 new->tx_seq = chan->expected_tx_seq;
3803 3825
3804 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); 3826 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq);
@@ -3807,6 +3829,8 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
3807 } 3829 }
3808 3830
3809 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); 3831 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq);
3832
3833 return 0;
3810} 3834}
3811 3835
3812static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb) 3836static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb)
@@ -3877,7 +3901,12 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_cont
3877 return 0; 3901 return 0;
3878 } 3902 }
3879 } 3903 }
3880 l2cap_send_srejframe(chan, tx_seq); 3904
3905 err = l2cap_send_srejframe(chan, tx_seq);
3906 if (err < 0) {
3907 l2cap_send_disconn_req(chan->conn, chan, -err);
3908 return err;
3909 }
3881 } 3910 }
3882 } else { 3911 } else {
3883 expected_tx_seq_offset = __seq_offset(chan, 3912 expected_tx_seq_offset = __seq_offset(chan,
@@ -3899,7 +3928,11 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_cont
3899 3928
3900 set_bit(CONN_SEND_PBIT, &chan->conn_state); 3929 set_bit(CONN_SEND_PBIT, &chan->conn_state);
3901 3930
3902 l2cap_send_srejframe(chan, tx_seq); 3931 err = l2cap_send_srejframe(chan, tx_seq);
3932 if (err < 0) {
3933 l2cap_send_disconn_req(chan->conn, chan, -err);
3934 return err;
3935 }
3903 3936
3904 __clear_ack_timer(chan); 3937 __clear_ack_timer(chan);
3905 } 3938 }
@@ -3928,11 +3961,12 @@ expected:
3928 l2cap_retransmit_frames(chan); 3961 l2cap_retransmit_frames(chan);
3929 } 3962 }
3930 3963
3931 __set_ack_timer(chan);
3932 3964
3933 chan->num_acked = (chan->num_acked + 1) % num_to_ack; 3965 chan->num_acked = (chan->num_acked + 1) % num_to_ack;
3934 if (chan->num_acked == num_to_ack - 1) 3966 if (chan->num_acked == num_to_ack - 1)
3935 l2cap_send_ack(chan); 3967 l2cap_send_ack(chan);
3968 else
3969 __set_ack_timer(chan);
3936 3970
3937 return 0; 3971 return 0;
3938 3972
@@ -4768,6 +4802,3 @@ void l2cap_exit(void)
4768 4802
4769module_param(disable_ertm, bool, 0644); 4803module_param(disable_ertm, bool, 0644);
4770MODULE_PARM_DESC(disable_ertm, "Disable enhanced retransmission mode"); 4804MODULE_PARM_DESC(disable_ertm, "Disable enhanced retransmission mode");
4771
4772module_param(enable_hs, bool, 0644);
4773MODULE_PARM_DESC(enable_hs, "Enable High Speed");
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index e2e785c74630..f73704321a77 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -626,8 +626,13 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
626 626
627 chan->sec_level = sec.level; 627 chan->sec_level = sec.level;
628 628
629 if (!chan->conn)
630 break;
631
629 conn = chan->conn; 632 conn = chan->conn;
630 if (conn && chan->scid == L2CAP_CID_LE_DATA) { 633
634 /*change security for LE channels */
635 if (chan->scid == L2CAP_CID_LE_DATA) {
631 if (!conn->hcon->out) { 636 if (!conn->hcon->out) {
632 err = -EINVAL; 637 err = -EINVAL;
633 break; 638 break;
@@ -635,9 +640,14 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
635 640
636 if (smp_conn_security(conn, sec.level)) 641 if (smp_conn_security(conn, sec.level))
637 break; 642 break;
638
639 err = 0;
640 sk->sk_state = BT_CONFIG; 643 sk->sk_state = BT_CONFIG;
644
645 /* or for ACL link, under defer_setup time */
646 } else if (sk->sk_state == BT_CONNECT2 &&
647 bt_sk(sk)->defer_setup) {
648 err = l2cap_chan_check_security(chan);
649 } else {
650 err = -EINVAL;
641 } 651 }
642 break; 652 break;
643 653
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 94739d3c4f59..1ce549bae241 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -22,6 +22,7 @@
22 22
23/* Bluetooth HCI Management interface */ 23/* Bluetooth HCI Management interface */
24 24
25#include <linux/kernel.h>
25#include <linux/uaccess.h> 26#include <linux/uaccess.h>
26#include <linux/module.h> 27#include <linux/module.h>
27#include <asm/unaligned.h> 28#include <asm/unaligned.h>
@@ -44,6 +45,79 @@ struct pending_cmd {
44 void *user_data; 45 void *user_data;
45}; 46};
46 47
48/* HCI to MGMT error code conversion table */
49static u8 mgmt_status_table[] = {
50 MGMT_STATUS_SUCCESS,
51 MGMT_STATUS_UNKNOWN_COMMAND, /* Unknown Command */
52 MGMT_STATUS_NOT_CONNECTED, /* No Connection */
53 MGMT_STATUS_FAILED, /* Hardware Failure */
54 MGMT_STATUS_CONNECT_FAILED, /* Page Timeout */
55 MGMT_STATUS_AUTH_FAILED, /* Authentication Failed */
56 MGMT_STATUS_NOT_PAIRED, /* PIN or Key Missing */
57 MGMT_STATUS_NO_RESOURCES, /* Memory Full */
58 MGMT_STATUS_TIMEOUT, /* Connection Timeout */
59 MGMT_STATUS_NO_RESOURCES, /* Max Number of Connections */
60 MGMT_STATUS_NO_RESOURCES, /* Max Number of SCO Connections */
61 MGMT_STATUS_ALREADY_CONNECTED, /* ACL Connection Exists */
62 MGMT_STATUS_BUSY, /* Command Disallowed */
63 MGMT_STATUS_NO_RESOURCES, /* Rejected Limited Resources */
64 MGMT_STATUS_REJECTED, /* Rejected Security */
65 MGMT_STATUS_REJECTED, /* Rejected Personal */
66 MGMT_STATUS_TIMEOUT, /* Host Timeout */
67 MGMT_STATUS_NOT_SUPPORTED, /* Unsupported Feature */
68 MGMT_STATUS_INVALID_PARAMS, /* Invalid Parameters */
69 MGMT_STATUS_DISCONNECTED, /* OE User Ended Connection */
70 MGMT_STATUS_NO_RESOURCES, /* OE Low Resources */
71 MGMT_STATUS_DISCONNECTED, /* OE Power Off */
72 MGMT_STATUS_DISCONNECTED, /* Connection Terminated */
73 MGMT_STATUS_BUSY, /* Repeated Attempts */
74 MGMT_STATUS_REJECTED, /* Pairing Not Allowed */
75 MGMT_STATUS_FAILED, /* Unknown LMP PDU */
76 MGMT_STATUS_NOT_SUPPORTED, /* Unsupported Remote Feature */
77 MGMT_STATUS_REJECTED, /* SCO Offset Rejected */
78 MGMT_STATUS_REJECTED, /* SCO Interval Rejected */
79 MGMT_STATUS_REJECTED, /* Air Mode Rejected */
80 MGMT_STATUS_INVALID_PARAMS, /* Invalid LMP Parameters */
81 MGMT_STATUS_FAILED, /* Unspecified Error */
82 MGMT_STATUS_NOT_SUPPORTED, /* Unsupported LMP Parameter Value */
83 MGMT_STATUS_FAILED, /* Role Change Not Allowed */
84 MGMT_STATUS_TIMEOUT, /* LMP Response Timeout */
85 MGMT_STATUS_FAILED, /* LMP Error Transaction Collision */
86 MGMT_STATUS_FAILED, /* LMP PDU Not Allowed */
87 MGMT_STATUS_REJECTED, /* Encryption Mode Not Accepted */
88 MGMT_STATUS_FAILED, /* Unit Link Key Used */
89 MGMT_STATUS_NOT_SUPPORTED, /* QoS Not Supported */
90 MGMT_STATUS_TIMEOUT, /* Instant Passed */
91 MGMT_STATUS_NOT_SUPPORTED, /* Pairing Not Supported */
92 MGMT_STATUS_FAILED, /* Transaction Collision */
93 MGMT_STATUS_INVALID_PARAMS, /* Unacceptable Parameter */
94 MGMT_STATUS_REJECTED, /* QoS Rejected */
95 MGMT_STATUS_NOT_SUPPORTED, /* Classification Not Supported */
96 MGMT_STATUS_REJECTED, /* Insufficient Security */
97 MGMT_STATUS_INVALID_PARAMS, /* Parameter Out Of Range */
98 MGMT_STATUS_BUSY, /* Role Switch Pending */
99 MGMT_STATUS_FAILED, /* Slot Violation */
100 MGMT_STATUS_FAILED, /* Role Switch Failed */
101 MGMT_STATUS_INVALID_PARAMS, /* EIR Too Large */
102 MGMT_STATUS_NOT_SUPPORTED, /* Simple Pairing Not Supported */
103 MGMT_STATUS_BUSY, /* Host Busy Pairing */
104 MGMT_STATUS_REJECTED, /* Rejected, No Suitable Channel */
105 MGMT_STATUS_BUSY, /* Controller Busy */
106 MGMT_STATUS_INVALID_PARAMS, /* Unsuitable Connection Interval */
107 MGMT_STATUS_TIMEOUT, /* Directed Advertising Timeout */
108 MGMT_STATUS_AUTH_FAILED, /* Terminated Due to MIC Failure */
109 MGMT_STATUS_CONNECT_FAILED, /* Connection Establishment Failed */
110 MGMT_STATUS_CONNECT_FAILED, /* MAC Connection Failed */
111};
112
113static u8 mgmt_status(u8 hci_status)
114{
115 if (hci_status < ARRAY_SIZE(mgmt_status_table))
116 return mgmt_status_table[hci_status];
117
118 return MGMT_STATUS_FAILED;
119}
120
47static int cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status) 121static int cmd_status(struct sock *sk, u16 index, u16 cmd, u8 status)
48{ 122{
49 struct sk_buff *skb; 123 struct sk_buff *skb;
@@ -178,7 +252,8 @@ static int read_controller_info(struct sock *sk, u16 index)
178 252
179 hdev = hci_dev_get(index); 253 hdev = hci_dev_get(index);
180 if (!hdev) 254 if (!hdev)
181 return cmd_status(sk, index, MGMT_OP_READ_INFO, ENODEV); 255 return cmd_status(sk, index, MGMT_OP_READ_INFO,
256 MGMT_STATUS_INVALID_PARAMS);
182 257
183 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags)) 258 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
184 cancel_delayed_work_sync(&hdev->power_off); 259 cancel_delayed_work_sync(&hdev->power_off);
@@ -291,6 +366,15 @@ static void mgmt_pending_remove(struct pending_cmd *cmd)
291 mgmt_pending_free(cmd); 366 mgmt_pending_free(cmd);
292} 367}
293 368
369static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
370{
371 struct mgmt_mode rp;
372
373 rp.val = val;
374
375 return cmd_complete(sk, index, opcode, &rp, sizeof(rp));
376}
377
294static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len) 378static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
295{ 379{
296 struct mgmt_mode *cp; 380 struct mgmt_mode *cp;
@@ -303,22 +387,25 @@ static int set_powered(struct sock *sk, u16 index, unsigned char *data, u16 len)
303 BT_DBG("request for hci%u", index); 387 BT_DBG("request for hci%u", index);
304 388
305 if (len != sizeof(*cp)) 389 if (len != sizeof(*cp))
306 return cmd_status(sk, index, MGMT_OP_SET_POWERED, EINVAL); 390 return cmd_status(sk, index, MGMT_OP_SET_POWERED,
391 MGMT_STATUS_INVALID_PARAMS);
307 392
308 hdev = hci_dev_get(index); 393 hdev = hci_dev_get(index);
309 if (!hdev) 394 if (!hdev)
310 return cmd_status(sk, index, MGMT_OP_SET_POWERED, ENODEV); 395 return cmd_status(sk, index, MGMT_OP_SET_POWERED,
396 MGMT_STATUS_INVALID_PARAMS);
311 397
312 hci_dev_lock_bh(hdev); 398 hci_dev_lock_bh(hdev);
313 399
314 up = test_bit(HCI_UP, &hdev->flags); 400 up = test_bit(HCI_UP, &hdev->flags);
315 if ((cp->val && up) || (!cp->val && !up)) { 401 if ((cp->val && up) || (!cp->val && !up)) {
316 err = cmd_status(sk, index, MGMT_OP_SET_POWERED, EALREADY); 402 err = send_mode_rsp(sk, index, MGMT_OP_SET_POWERED, cp->val);
317 goto failed; 403 goto failed;
318 } 404 }
319 405
320 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) { 406 if (mgmt_pending_find(MGMT_OP_SET_POWERED, hdev)) {
321 err = cmd_status(sk, index, MGMT_OP_SET_POWERED, EBUSY); 407 err = cmd_status(sk, index, MGMT_OP_SET_POWERED,
408 MGMT_STATUS_BUSY);
322 goto failed; 409 goto failed;
323 } 410 }
324 411
@@ -355,28 +442,33 @@ static int set_discoverable(struct sock *sk, u16 index, unsigned char *data,
355 BT_DBG("request for hci%u", index); 442 BT_DBG("request for hci%u", index);
356 443
357 if (len != sizeof(*cp)) 444 if (len != sizeof(*cp))
358 return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, EINVAL); 445 return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
446 MGMT_STATUS_INVALID_PARAMS);
359 447
360 hdev = hci_dev_get(index); 448 hdev = hci_dev_get(index);
361 if (!hdev) 449 if (!hdev)
362 return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENODEV); 450 return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
451 MGMT_STATUS_INVALID_PARAMS);
363 452
364 hci_dev_lock_bh(hdev); 453 hci_dev_lock_bh(hdev);
365 454
366 if (!test_bit(HCI_UP, &hdev->flags)) { 455 if (!test_bit(HCI_UP, &hdev->flags)) {
367 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, ENETDOWN); 456 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
457 MGMT_STATUS_NOT_POWERED);
368 goto failed; 458 goto failed;
369 } 459 }
370 460
371 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 461 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
372 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 462 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
373 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, EBUSY); 463 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
464 MGMT_STATUS_BUSY);
374 goto failed; 465 goto failed;
375 } 466 }
376 467
377 if (cp->val == test_bit(HCI_ISCAN, &hdev->flags) && 468 if (cp->val == test_bit(HCI_ISCAN, &hdev->flags) &&
378 test_bit(HCI_PSCAN, &hdev->flags)) { 469 test_bit(HCI_PSCAN, &hdev->flags)) {
379 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, EALREADY); 470 err = send_mode_rsp(sk, index, MGMT_OP_SET_DISCOVERABLE,
471 cp->val);
380 goto failed; 472 goto failed;
381 } 473 }
382 474
@@ -421,27 +513,32 @@ static int set_connectable(struct sock *sk, u16 index, unsigned char *data,
421 BT_DBG("request for hci%u", index); 513 BT_DBG("request for hci%u", index);
422 514
423 if (len != sizeof(*cp)) 515 if (len != sizeof(*cp))
424 return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, EINVAL); 516 return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
517 MGMT_STATUS_INVALID_PARAMS);
425 518
426 hdev = hci_dev_get(index); 519 hdev = hci_dev_get(index);
427 if (!hdev) 520 if (!hdev)
428 return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENODEV); 521 return cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
522 MGMT_STATUS_INVALID_PARAMS);
429 523
430 hci_dev_lock_bh(hdev); 524 hci_dev_lock_bh(hdev);
431 525
432 if (!test_bit(HCI_UP, &hdev->flags)) { 526 if (!test_bit(HCI_UP, &hdev->flags)) {
433 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, ENETDOWN); 527 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
528 MGMT_STATUS_NOT_POWERED);
434 goto failed; 529 goto failed;
435 } 530 }
436 531
437 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 532 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
438 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 533 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
439 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, EBUSY); 534 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
535 MGMT_STATUS_BUSY);
440 goto failed; 536 goto failed;
441 } 537 }
442 538
443 if (cp->val == test_bit(HCI_PSCAN, &hdev->flags)) { 539 if (cp->val == test_bit(HCI_PSCAN, &hdev->flags)) {
444 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, EALREADY); 540 err = send_mode_rsp(sk, index, MGMT_OP_SET_CONNECTABLE,
541 cp->val);
445 goto failed; 542 goto failed;
446 } 543 }
447 544
@@ -496,15 +593,6 @@ static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
496 return 0; 593 return 0;
497} 594}
498 595
499static int send_mode_rsp(struct sock *sk, u16 opcode, u16 index, u8 val)
500{
501 struct mgmt_mode rp;
502
503 rp.val = val;
504
505 return cmd_complete(sk, index, opcode, &rp, sizeof(rp));
506}
507
508static int set_pairable(struct sock *sk, u16 index, unsigned char *data, 596static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
509 u16 len) 597 u16 len)
510{ 598{
@@ -517,11 +605,13 @@ static int set_pairable(struct sock *sk, u16 index, unsigned char *data,
517 BT_DBG("request for hci%u", index); 605 BT_DBG("request for hci%u", index);
518 606
519 if (len != sizeof(*cp)) 607 if (len != sizeof(*cp))
520 return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE, EINVAL); 608 return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE,
609 MGMT_STATUS_INVALID_PARAMS);
521 610
522 hdev = hci_dev_get(index); 611 hdev = hci_dev_get(index);
523 if (!hdev) 612 if (!hdev)
524 return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE, ENODEV); 613 return cmd_status(sk, index, MGMT_OP_SET_PAIRABLE,
614 MGMT_STATUS_INVALID_PARAMS);
525 615
526 hci_dev_lock_bh(hdev); 616 hci_dev_lock_bh(hdev);
527 617
@@ -730,11 +820,13 @@ static int add_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
730 BT_DBG("request for hci%u", index); 820 BT_DBG("request for hci%u", index);
731 821
732 if (len != sizeof(*cp)) 822 if (len != sizeof(*cp))
733 return cmd_status(sk, index, MGMT_OP_ADD_UUID, EINVAL); 823 return cmd_status(sk, index, MGMT_OP_ADD_UUID,
824 MGMT_STATUS_INVALID_PARAMS);
734 825
735 hdev = hci_dev_get(index); 826 hdev = hci_dev_get(index);
736 if (!hdev) 827 if (!hdev)
737 return cmd_status(sk, index, MGMT_OP_ADD_UUID, ENODEV); 828 return cmd_status(sk, index, MGMT_OP_ADD_UUID,
829 MGMT_STATUS_INVALID_PARAMS);
738 830
739 hci_dev_lock_bh(hdev); 831 hci_dev_lock_bh(hdev);
740 832
@@ -779,11 +871,13 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
779 BT_DBG("request for hci%u", index); 871 BT_DBG("request for hci%u", index);
780 872
781 if (len != sizeof(*cp)) 873 if (len != sizeof(*cp))
782 return cmd_status(sk, index, MGMT_OP_REMOVE_UUID, EINVAL); 874 return cmd_status(sk, index, MGMT_OP_REMOVE_UUID,
875 MGMT_STATUS_INVALID_PARAMS);
783 876
784 hdev = hci_dev_get(index); 877 hdev = hci_dev_get(index);
785 if (!hdev) 878 if (!hdev)
786 return cmd_status(sk, index, MGMT_OP_REMOVE_UUID, ENODEV); 879 return cmd_status(sk, index, MGMT_OP_REMOVE_UUID,
880 MGMT_STATUS_INVALID_PARAMS);
787 881
788 hci_dev_lock_bh(hdev); 882 hci_dev_lock_bh(hdev);
789 883
@@ -805,7 +899,8 @@ static int remove_uuid(struct sock *sk, u16 index, unsigned char *data, u16 len)
805 } 899 }
806 900
807 if (found == 0) { 901 if (found == 0) {
808 err = cmd_status(sk, index, MGMT_OP_REMOVE_UUID, ENOENT); 902 err = cmd_status(sk, index, MGMT_OP_REMOVE_UUID,
903 MGMT_STATUS_INVALID_PARAMS);
809 goto unlock; 904 goto unlock;
810 } 905 }
811 906
@@ -838,11 +933,13 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
838 BT_DBG("request for hci%u", index); 933 BT_DBG("request for hci%u", index);
839 934
840 if (len != sizeof(*cp)) 935 if (len != sizeof(*cp))
841 return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS, EINVAL); 936 return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS,
937 MGMT_STATUS_INVALID_PARAMS);
842 938
843 hdev = hci_dev_get(index); 939 hdev = hci_dev_get(index);
844 if (!hdev) 940 if (!hdev)
845 return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS, ENODEV); 941 return cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS,
942 MGMT_STATUS_INVALID_PARAMS);
846 943
847 hci_dev_lock_bh(hdev); 944 hci_dev_lock_bh(hdev);
848 945
@@ -870,11 +967,13 @@ static int set_service_cache(struct sock *sk, u16 index, unsigned char *data,
870 cp = (void *) data; 967 cp = (void *) data;
871 968
872 if (len != sizeof(*cp)) 969 if (len != sizeof(*cp))
873 return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE, EINVAL); 970 return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE,
971 MGMT_STATUS_INVALID_PARAMS);
874 972
875 hdev = hci_dev_get(index); 973 hdev = hci_dev_get(index);
876 if (!hdev) 974 if (!hdev)
877 return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE, ENODEV); 975 return cmd_status(sk, index, MGMT_OP_SET_SERVICE_CACHE,
976 MGMT_STATUS_INVALID_PARAMS);
878 977
879 hci_dev_lock_bh(hdev); 978 hci_dev_lock_bh(hdev);
880 979
@@ -914,7 +1013,8 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
914 cp = (void *) data; 1013 cp = (void *) data;
915 1014
916 if (len < sizeof(*cp)) 1015 if (len < sizeof(*cp))
917 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS, EINVAL); 1016 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
1017 MGMT_STATUS_INVALID_PARAMS);
918 1018
919 key_count = get_unaligned_le16(&cp->key_count); 1019 key_count = get_unaligned_le16(&cp->key_count);
920 1020
@@ -923,12 +1023,14 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
923 if (expected_len != len) { 1023 if (expected_len != len) {
924 BT_ERR("load_link_keys: expected %u bytes, got %u bytes", 1024 BT_ERR("load_link_keys: expected %u bytes, got %u bytes",
925 len, expected_len); 1025 len, expected_len);
926 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS, EINVAL); 1026 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
1027 MGMT_STATUS_INVALID_PARAMS);
927 } 1028 }
928 1029
929 hdev = hci_dev_get(index); 1030 hdev = hci_dev_get(index);
930 if (!hdev) 1031 if (!hdev)
931 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS, ENODEV); 1032 return cmd_status(sk, index, MGMT_OP_LOAD_LINK_KEYS,
1033 MGMT_STATUS_INVALID_PARAMS);
932 1034
933 BT_DBG("hci%u debug_keys %u key_count %u", index, cp->debug_keys, 1035 BT_DBG("hci%u debug_keys %u key_count %u", index, cp->debug_keys,
934 key_count); 1036 key_count);
@@ -951,6 +1053,8 @@ static int load_link_keys(struct sock *sk, u16 index, unsigned char *data,
951 key->pin_len); 1053 key->pin_len);
952 } 1054 }
953 1055
1056 cmd_complete(sk, index, MGMT_OP_LOAD_LINK_KEYS, NULL, 0);
1057
954 hci_dev_unlock_bh(hdev); 1058 hci_dev_unlock_bh(hdev);
955 hci_dev_put(hdev); 1059 hci_dev_put(hdev);
956 1060
@@ -962,41 +1066,64 @@ static int remove_keys(struct sock *sk, u16 index, unsigned char *data,
962{ 1066{
963 struct hci_dev *hdev; 1067 struct hci_dev *hdev;
964 struct mgmt_cp_remove_keys *cp; 1068 struct mgmt_cp_remove_keys *cp;
1069 struct mgmt_rp_remove_keys rp;
1070 struct hci_cp_disconnect dc;
1071 struct pending_cmd *cmd;
965 struct hci_conn *conn; 1072 struct hci_conn *conn;
966 int err; 1073 int err;
967 1074
968 cp = (void *) data; 1075 cp = (void *) data;
969 1076
970 if (len != sizeof(*cp)) 1077 if (len != sizeof(*cp))
971 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, EINVAL); 1078 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS,
1079 MGMT_STATUS_INVALID_PARAMS);
972 1080
973 hdev = hci_dev_get(index); 1081 hdev = hci_dev_get(index);
974 if (!hdev) 1082 if (!hdev)
975 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, ENODEV); 1083 return cmd_status(sk, index, MGMT_OP_REMOVE_KEYS,
1084 MGMT_STATUS_INVALID_PARAMS);
976 1085
977 hci_dev_lock_bh(hdev); 1086 hci_dev_lock_bh(hdev);
978 1087
1088 memset(&rp, 0, sizeof(rp));
1089 bacpy(&rp.bdaddr, &cp->bdaddr);
1090 rp.status = MGMT_STATUS_FAILED;
1091
979 err = hci_remove_link_key(hdev, &cp->bdaddr); 1092 err = hci_remove_link_key(hdev, &cp->bdaddr);
980 if (err < 0) { 1093 if (err < 0) {
981 err = cmd_status(sk, index, MGMT_OP_REMOVE_KEYS, -err); 1094 rp.status = MGMT_STATUS_NOT_PAIRED;
982 goto unlock; 1095 goto unlock;
983 } 1096 }
984 1097
985 err = 0; 1098 if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) {
986 1099 err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp,
987 if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) 1100 sizeof(rp));
988 goto unlock; 1101 goto unlock;
1102 }
989 1103
990 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); 1104 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
991 if (conn) { 1105 if (!conn) {
992 struct hci_cp_disconnect dc; 1106 err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp,
1107 sizeof(rp));
1108 goto unlock;
1109 }
993 1110
994 put_unaligned_le16(conn->handle, &dc.handle); 1111 cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_KEYS, hdev, cp, sizeof(*cp));
995 dc.reason = 0x13; /* Remote User Terminated Connection */ 1112 if (!cmd) {
996 err = hci_send_cmd(hdev, HCI_OP_DISCONNECT, sizeof(dc), &dc); 1113 err = -ENOMEM;
1114 goto unlock;
997 } 1115 }
998 1116
1117 put_unaligned_le16(conn->handle, &dc.handle);
1118 dc.reason = 0x13; /* Remote User Terminated Connection */
1119 err = hci_send_cmd(hdev, HCI_OP_DISCONNECT, sizeof(dc), &dc);
1120 if (err < 0)
1121 mgmt_pending_remove(cmd);
1122
999unlock: 1123unlock:
1124 if (err < 0)
1125 err = cmd_complete(sk, index, MGMT_OP_REMOVE_KEYS, &rp,
1126 sizeof(rp));
1000 hci_dev_unlock_bh(hdev); 1127 hci_dev_unlock_bh(hdev);
1001 hci_dev_put(hdev); 1128 hci_dev_put(hdev);
1002 1129
@@ -1017,21 +1144,25 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
1017 cp = (void *) data; 1144 cp = (void *) data;
1018 1145
1019 if (len != sizeof(*cp)) 1146 if (len != sizeof(*cp))
1020 return cmd_status(sk, index, MGMT_OP_DISCONNECT, EINVAL); 1147 return cmd_status(sk, index, MGMT_OP_DISCONNECT,
1148 MGMT_STATUS_INVALID_PARAMS);
1021 1149
1022 hdev = hci_dev_get(index); 1150 hdev = hci_dev_get(index);
1023 if (!hdev) 1151 if (!hdev)
1024 return cmd_status(sk, index, MGMT_OP_DISCONNECT, ENODEV); 1152 return cmd_status(sk, index, MGMT_OP_DISCONNECT,
1153 MGMT_STATUS_INVALID_PARAMS);
1025 1154
1026 hci_dev_lock_bh(hdev); 1155 hci_dev_lock_bh(hdev);
1027 1156
1028 if (!test_bit(HCI_UP, &hdev->flags)) { 1157 if (!test_bit(HCI_UP, &hdev->flags)) {
1029 err = cmd_status(sk, index, MGMT_OP_DISCONNECT, ENETDOWN); 1158 err = cmd_status(sk, index, MGMT_OP_DISCONNECT,
1159 MGMT_STATUS_NOT_POWERED);
1030 goto failed; 1160 goto failed;
1031 } 1161 }
1032 1162
1033 if (mgmt_pending_find(MGMT_OP_DISCONNECT, hdev)) { 1163 if (mgmt_pending_find(MGMT_OP_DISCONNECT, hdev)) {
1034 err = cmd_status(sk, index, MGMT_OP_DISCONNECT, EBUSY); 1164 err = cmd_status(sk, index, MGMT_OP_DISCONNECT,
1165 MGMT_STATUS_BUSY);
1035 goto failed; 1166 goto failed;
1036 } 1167 }
1037 1168
@@ -1040,7 +1171,8 @@ static int disconnect(struct sock *sk, u16 index, unsigned char *data, u16 len)
1040 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr); 1171 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->bdaddr);
1041 1172
1042 if (!conn) { 1173 if (!conn) {
1043 err = cmd_status(sk, index, MGMT_OP_DISCONNECT, ENOTCONN); 1174 err = cmd_status(sk, index, MGMT_OP_DISCONNECT,
1175 MGMT_STATUS_NOT_CONNECTED);
1044 goto failed; 1176 goto failed;
1045 } 1177 }
1046 1178
@@ -1064,11 +1196,18 @@ failed:
1064 return err; 1196 return err;
1065} 1197}
1066 1198
1067static u8 link_to_mgmt(u8 link_type) 1199static u8 link_to_mgmt(u8 link_type, u8 addr_type)
1068{ 1200{
1069 switch (link_type) { 1201 switch (link_type) {
1070 case LE_LINK: 1202 case LE_LINK:
1071 return MGMT_ADDR_LE; 1203 switch (addr_type) {
1204 case ADDR_LE_DEV_PUBLIC:
1205 return MGMT_ADDR_LE_PUBLIC;
1206 case ADDR_LE_DEV_RANDOM:
1207 return MGMT_ADDR_LE_RANDOM;
1208 default:
1209 return MGMT_ADDR_INVALID;
1210 }
1072 case ACL_LINK: 1211 case ACL_LINK:
1073 return MGMT_ADDR_BREDR; 1212 return MGMT_ADDR_BREDR;
1074 default: 1213 default:
@@ -1090,7 +1229,8 @@ static int get_connections(struct sock *sk, u16 index)
1090 1229
1091 hdev = hci_dev_get(index); 1230 hdev = hci_dev_get(index);
1092 if (!hdev) 1231 if (!hdev)
1093 return cmd_status(sk, index, MGMT_OP_GET_CONNECTIONS, ENODEV); 1232 return cmd_status(sk, index, MGMT_OP_GET_CONNECTIONS,
1233 MGMT_STATUS_INVALID_PARAMS);
1094 1234
1095 hci_dev_lock_bh(hdev); 1235 hci_dev_lock_bh(hdev);
1096 1236
@@ -1111,7 +1251,7 @@ static int get_connections(struct sock *sk, u16 index)
1111 i = 0; 1251 i = 0;
1112 list_for_each_entry(c, &hdev->conn_hash.list, list) { 1252 list_for_each_entry(c, &hdev->conn_hash.list, list) {
1113 bacpy(&rp->addr[i].bdaddr, &c->dst); 1253 bacpy(&rp->addr[i].bdaddr, &c->dst);
1114 rp->addr[i].type = link_to_mgmt(c->type); 1254 rp->addr[i].type = link_to_mgmt(c->type, c->dst_type);
1115 if (rp->addr[i].type == MGMT_ADDR_INVALID) 1255 if (rp->addr[i].type == MGMT_ADDR_INVALID)
1116 continue; 1256 continue;
1117 i++; 1257 i++;
@@ -1164,22 +1304,26 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
1164 cp = (void *) data; 1304 cp = (void *) data;
1165 1305
1166 if (len != sizeof(*cp)) 1306 if (len != sizeof(*cp))
1167 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, EINVAL); 1307 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1308 MGMT_STATUS_INVALID_PARAMS);
1168 1309
1169 hdev = hci_dev_get(index); 1310 hdev = hci_dev_get(index);
1170 if (!hdev) 1311 if (!hdev)
1171 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENODEV); 1312 return cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1313 MGMT_STATUS_INVALID_PARAMS);
1172 1314
1173 hci_dev_lock_bh(hdev); 1315 hci_dev_lock_bh(hdev);
1174 1316
1175 if (!test_bit(HCI_UP, &hdev->flags)) { 1317 if (!test_bit(HCI_UP, &hdev->flags)) {
1176 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENETDOWN); 1318 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1319 MGMT_STATUS_NOT_POWERED);
1177 goto failed; 1320 goto failed;
1178 } 1321 }
1179 1322
1180 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); 1323 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1181 if (!conn) { 1324 if (!conn) {
1182 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, ENOTCONN); 1325 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1326 MGMT_STATUS_NOT_CONNECTED);
1183 goto failed; 1327 goto failed;
1184 } 1328 }
1185 1329
@@ -1191,7 +1335,7 @@ static int pin_code_reply(struct sock *sk, u16 index, unsigned char *data,
1191 err = send_pin_code_neg_reply(sk, index, hdev, &ncp); 1335 err = send_pin_code_neg_reply(sk, index, hdev, &ncp);
1192 if (err >= 0) 1336 if (err >= 0)
1193 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, 1337 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1194 EINVAL); 1338 MGMT_STATUS_INVALID_PARAMS);
1195 1339
1196 goto failed; 1340 goto failed;
1197 } 1341 }
@@ -1230,18 +1374,18 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, unsigned char *data,
1230 1374
1231 if (len != sizeof(*cp)) 1375 if (len != sizeof(*cp))
1232 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, 1376 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
1233 EINVAL); 1377 MGMT_STATUS_INVALID_PARAMS);
1234 1378
1235 hdev = hci_dev_get(index); 1379 hdev = hci_dev_get(index);
1236 if (!hdev) 1380 if (!hdev)
1237 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, 1381 return cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
1238 ENODEV); 1382 MGMT_STATUS_INVALID_PARAMS);
1239 1383
1240 hci_dev_lock_bh(hdev); 1384 hci_dev_lock_bh(hdev);
1241 1385
1242 if (!test_bit(HCI_UP, &hdev->flags)) { 1386 if (!test_bit(HCI_UP, &hdev->flags)) {
1243 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, 1387 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
1244 ENETDOWN); 1388 MGMT_STATUS_NOT_POWERED);
1245 goto failed; 1389 goto failed;
1246 } 1390 }
1247 1391
@@ -1265,11 +1409,13 @@ static int set_io_capability(struct sock *sk, u16 index, unsigned char *data,
1265 cp = (void *) data; 1409 cp = (void *) data;
1266 1410
1267 if (len != sizeof(*cp)) 1411 if (len != sizeof(*cp))
1268 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, EINVAL); 1412 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY,
1413 MGMT_STATUS_INVALID_PARAMS);
1269 1414
1270 hdev = hci_dev_get(index); 1415 hdev = hci_dev_get(index);
1271 if (!hdev) 1416 if (!hdev)
1272 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY, ENODEV); 1417 return cmd_status(sk, index, MGMT_OP_SET_IO_CAPABILITY,
1418 MGMT_STATUS_INVALID_PARAMS);
1273 1419
1274 hci_dev_lock_bh(hdev); 1420 hci_dev_lock_bh(hdev);
1275 1421
@@ -1307,7 +1453,8 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
1307 struct mgmt_rp_pair_device rp; 1453 struct mgmt_rp_pair_device rp;
1308 struct hci_conn *conn = cmd->user_data; 1454 struct hci_conn *conn = cmd->user_data;
1309 1455
1310 bacpy(&rp.bdaddr, &conn->dst); 1456 bacpy(&rp.addr.bdaddr, &conn->dst);
1457 rp.addr.type = link_to_mgmt(conn->type, conn->dst_type);
1311 rp.status = status; 1458 rp.status = status;
1312 1459
1313 cmd_complete(cmd->sk, cmd->index, MGMT_OP_PAIR_DEVICE, &rp, sizeof(rp)); 1460 cmd_complete(cmd->sk, cmd->index, MGMT_OP_PAIR_DEVICE, &rp, sizeof(rp));
@@ -1325,27 +1472,22 @@ static void pairing_complete(struct pending_cmd *cmd, u8 status)
1325static void pairing_complete_cb(struct hci_conn *conn, u8 status) 1472static void pairing_complete_cb(struct hci_conn *conn, u8 status)
1326{ 1473{
1327 struct pending_cmd *cmd; 1474 struct pending_cmd *cmd;
1328 struct hci_dev *hdev = conn->hdev;
1329 1475
1330 BT_DBG("status %u", status); 1476 BT_DBG("status %u", status);
1331 1477
1332 hci_dev_lock_bh(hdev);
1333
1334 cmd = find_pairing(conn); 1478 cmd = find_pairing(conn);
1335 if (!cmd) 1479 if (!cmd)
1336 BT_DBG("Unable to find a pending command"); 1480 BT_DBG("Unable to find a pending command");
1337 else 1481 else
1338 pairing_complete(cmd, status); 1482 pairing_complete(cmd, status);
1339
1340 hci_dev_unlock_bh(hdev);
1341} 1483}
1342 1484
1343static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len) 1485static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
1344{ 1486{
1345 struct hci_dev *hdev; 1487 struct hci_dev *hdev;
1346 struct mgmt_cp_pair_device *cp; 1488 struct mgmt_cp_pair_device *cp;
1489 struct mgmt_rp_pair_device rp;
1347 struct pending_cmd *cmd; 1490 struct pending_cmd *cmd;
1348 struct adv_entry *entry;
1349 u8 sec_level, auth_type; 1491 u8 sec_level, auth_type;
1350 struct hci_conn *conn; 1492 struct hci_conn *conn;
1351 int err; 1493 int err;
@@ -1355,11 +1497,13 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
1355 cp = (void *) data; 1497 cp = (void *) data;
1356 1498
1357 if (len != sizeof(*cp)) 1499 if (len != sizeof(*cp))
1358 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, EINVAL); 1500 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE,
1501 MGMT_STATUS_INVALID_PARAMS);
1359 1502
1360 hdev = hci_dev_get(index); 1503 hdev = hci_dev_get(index);
1361 if (!hdev) 1504 if (!hdev)
1362 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, ENODEV); 1505 return cmd_status(sk, index, MGMT_OP_PAIR_DEVICE,
1506 MGMT_STATUS_INVALID_PARAMS);
1363 1507
1364 hci_dev_lock_bh(hdev); 1508 hci_dev_lock_bh(hdev);
1365 1509
@@ -1369,22 +1513,29 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
1369 else 1513 else
1370 auth_type = HCI_AT_DEDICATED_BONDING_MITM; 1514 auth_type = HCI_AT_DEDICATED_BONDING_MITM;
1371 1515
1372 entry = hci_find_adv_entry(hdev, &cp->bdaddr); 1516 if (cp->addr.type == MGMT_ADDR_BREDR)
1373 if (entry) 1517 conn = hci_connect(hdev, ACL_LINK, &cp->addr.bdaddr, sec_level,
1374 conn = hci_connect(hdev, LE_LINK, &cp->bdaddr, sec_level,
1375 auth_type); 1518 auth_type);
1376 else 1519 else
1377 conn = hci_connect(hdev, ACL_LINK, &cp->bdaddr, sec_level, 1520 conn = hci_connect(hdev, LE_LINK, &cp->addr.bdaddr, sec_level,
1378 auth_type); 1521 auth_type);
1379 1522
1523 memset(&rp, 0, sizeof(rp));
1524 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
1525 rp.addr.type = cp->addr.type;
1526
1380 if (IS_ERR(conn)) { 1527 if (IS_ERR(conn)) {
1381 err = PTR_ERR(conn); 1528 rp.status = -PTR_ERR(conn);
1529 err = cmd_complete(sk, index, MGMT_OP_PAIR_DEVICE,
1530 &rp, sizeof(rp));
1382 goto unlock; 1531 goto unlock;
1383 } 1532 }
1384 1533
1385 if (conn->connect_cfm_cb) { 1534 if (conn->connect_cfm_cb) {
1386 hci_conn_put(conn); 1535 hci_conn_put(conn);
1387 err = cmd_status(sk, index, MGMT_OP_PAIR_DEVICE, EBUSY); 1536 rp.status = EBUSY;
1537 err = cmd_complete(sk, index, MGMT_OP_PAIR_DEVICE,
1538 &rp, sizeof(rp));
1388 goto unlock; 1539 goto unlock;
1389 } 1540 }
1390 1541
@@ -1396,7 +1547,7 @@ static int pair_device(struct sock *sk, u16 index, unsigned char *data, u16 len)
1396 } 1547 }
1397 1548
1398 /* For LE, just connecting isn't a proof that the pairing finished */ 1549 /* For LE, just connecting isn't a proof that the pairing finished */
1399 if (!entry) 1550 if (cp->addr.type == MGMT_ADDR_BREDR)
1400 conn->connect_cfm_cb = pairing_complete_cb; 1551 conn->connect_cfm_cb = pairing_complete_cb;
1401 1552
1402 conn->security_cfm_cb = pairing_complete_cb; 1553 conn->security_cfm_cb = pairing_complete_cb;
@@ -1417,56 +1568,138 @@ unlock:
1417 return err; 1568 return err;
1418} 1569}
1419 1570
1420static int user_confirm_reply(struct sock *sk, u16 index, unsigned char *data, 1571static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
1421 u16 len, int success) 1572 u16 mgmt_op, u16 hci_op, __le32 passkey)
1422{ 1573{
1423 struct mgmt_cp_user_confirm_reply *cp = (void *) data;
1424 u16 mgmt_op, hci_op;
1425 struct pending_cmd *cmd; 1574 struct pending_cmd *cmd;
1426 struct hci_dev *hdev; 1575 struct hci_dev *hdev;
1576 struct hci_conn *conn;
1427 int err; 1577 int err;
1428 1578
1429 BT_DBG("");
1430
1431 if (success) {
1432 mgmt_op = MGMT_OP_USER_CONFIRM_REPLY;
1433 hci_op = HCI_OP_USER_CONFIRM_REPLY;
1434 } else {
1435 mgmt_op = MGMT_OP_USER_CONFIRM_NEG_REPLY;
1436 hci_op = HCI_OP_USER_CONFIRM_NEG_REPLY;
1437 }
1438
1439 if (len != sizeof(*cp))
1440 return cmd_status(sk, index, mgmt_op, EINVAL);
1441
1442 hdev = hci_dev_get(index); 1579 hdev = hci_dev_get(index);
1443 if (!hdev) 1580 if (!hdev)
1444 return cmd_status(sk, index, mgmt_op, ENODEV); 1581 return cmd_status(sk, index, mgmt_op,
1582 MGMT_STATUS_INVALID_PARAMS);
1445 1583
1446 hci_dev_lock_bh(hdev); 1584 hci_dev_lock_bh(hdev);
1447 1585
1448 if (!test_bit(HCI_UP, &hdev->flags)) { 1586 if (!test_bit(HCI_UP, &hdev->flags)) {
1449 err = cmd_status(sk, index, mgmt_op, ENETDOWN); 1587 err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_NOT_POWERED);
1450 goto failed; 1588 goto done;
1451 } 1589 }
1452 1590
1453 cmd = mgmt_pending_add(sk, mgmt_op, hdev, data, len); 1591 /*
1592 * Check for an existing ACL link, if present pair via
1593 * HCI commands.
1594 *
1595 * If no ACL link is present, check for an LE link and if
1596 * present, pair via the SMP engine.
1597 *
1598 * If neither ACL nor LE links are present, fail with error.
1599 */
1600 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, bdaddr);
1601 if (!conn) {
1602 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, bdaddr);
1603 if (!conn) {
1604 err = cmd_status(sk, index, mgmt_op,
1605 MGMT_STATUS_NOT_CONNECTED);
1606 goto done;
1607 }
1608
1609 /* Continue with pairing via SMP */
1610
1611 err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_SUCCESS);
1612 goto done;
1613 }
1614
1615 cmd = mgmt_pending_add(sk, mgmt_op, hdev, bdaddr, sizeof(*bdaddr));
1454 if (!cmd) { 1616 if (!cmd) {
1455 err = -ENOMEM; 1617 err = -ENOMEM;
1456 goto failed; 1618 goto done;
1457 } 1619 }
1458 1620
1459 err = hci_send_cmd(hdev, hci_op, sizeof(cp->bdaddr), &cp->bdaddr); 1621 /* Continue with pairing via HCI */
1622 if (hci_op == HCI_OP_USER_PASSKEY_REPLY) {
1623 struct hci_cp_user_passkey_reply cp;
1624
1625 bacpy(&cp.bdaddr, bdaddr);
1626 cp.passkey = passkey;
1627 err = hci_send_cmd(hdev, hci_op, sizeof(cp), &cp);
1628 } else
1629 err = hci_send_cmd(hdev, hci_op, sizeof(*bdaddr), bdaddr);
1630
1460 if (err < 0) 1631 if (err < 0)
1461 mgmt_pending_remove(cmd); 1632 mgmt_pending_remove(cmd);
1462 1633
1463failed: 1634done:
1464 hci_dev_unlock_bh(hdev); 1635 hci_dev_unlock_bh(hdev);
1465 hci_dev_put(hdev); 1636 hci_dev_put(hdev);
1466 1637
1467 return err; 1638 return err;
1468} 1639}
1469 1640
1641static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len)
1642{
1643 struct mgmt_cp_user_confirm_reply *cp = (void *) data;
1644
1645 BT_DBG("");
1646
1647 if (len != sizeof(*cp))
1648 return cmd_status(sk, index, MGMT_OP_USER_CONFIRM_REPLY,
1649 MGMT_STATUS_INVALID_PARAMS);
1650
1651 return user_pairing_resp(sk, index, &cp->bdaddr,
1652 MGMT_OP_USER_CONFIRM_REPLY,
1653 HCI_OP_USER_CONFIRM_REPLY, 0);
1654}
1655
1656static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data,
1657 u16 len)
1658{
1659 struct mgmt_cp_user_confirm_reply *cp = (void *) data;
1660
1661 BT_DBG("");
1662
1663 if (len != sizeof(*cp))
1664 return cmd_status(sk, index, MGMT_OP_USER_CONFIRM_NEG_REPLY,
1665 MGMT_STATUS_INVALID_PARAMS);
1666
1667 return user_pairing_resp(sk, index, &cp->bdaddr,
1668 MGMT_OP_USER_CONFIRM_NEG_REPLY,
1669 HCI_OP_USER_CONFIRM_NEG_REPLY, 0);
1670}
1671
1672static int user_passkey_reply(struct sock *sk, u16 index, void *data, u16 len)
1673{
1674 struct mgmt_cp_user_passkey_reply *cp = (void *) data;
1675
1676 BT_DBG("");
1677
1678 if (len != sizeof(*cp))
1679 return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_REPLY,
1680 EINVAL);
1681
1682 return user_pairing_resp(sk, index, &cp->bdaddr,
1683 MGMT_OP_USER_PASSKEY_REPLY,
1684 HCI_OP_USER_PASSKEY_REPLY, cp->passkey);
1685}
1686
1687static int user_passkey_neg_reply(struct sock *sk, u16 index, void *data,
1688 u16 len)
1689{
1690 struct mgmt_cp_user_passkey_neg_reply *cp = (void *) data;
1691
1692 BT_DBG("");
1693
1694 if (len != sizeof(*cp))
1695 return cmd_status(sk, index, MGMT_OP_USER_PASSKEY_NEG_REPLY,
1696 EINVAL);
1697
1698 return user_pairing_resp(sk, index, &cp->bdaddr,
1699 MGMT_OP_USER_PASSKEY_NEG_REPLY,
1700 HCI_OP_USER_PASSKEY_NEG_REPLY, 0);
1701}
1702
1470static int set_local_name(struct sock *sk, u16 index, unsigned char *data, 1703static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
1471 u16 len) 1704 u16 len)
1472{ 1705{
@@ -1479,11 +1712,13 @@ static int set_local_name(struct sock *sk, u16 index, unsigned char *data,
1479 BT_DBG(""); 1712 BT_DBG("");
1480 1713
1481 if (len != sizeof(*mgmt_cp)) 1714 if (len != sizeof(*mgmt_cp))
1482 return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, EINVAL); 1715 return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME,
1716 MGMT_STATUS_INVALID_PARAMS);
1483 1717
1484 hdev = hci_dev_get(index); 1718 hdev = hci_dev_get(index);
1485 if (!hdev) 1719 if (!hdev)
1486 return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME, ENODEV); 1720 return cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME,
1721 MGMT_STATUS_INVALID_PARAMS);
1487 1722
1488 hci_dev_lock_bh(hdev); 1723 hci_dev_lock_bh(hdev);
1489 1724
@@ -1517,24 +1752,25 @@ static int read_local_oob_data(struct sock *sk, u16 index)
1517 hdev = hci_dev_get(index); 1752 hdev = hci_dev_get(index);
1518 if (!hdev) 1753 if (!hdev)
1519 return cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, 1754 return cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
1520 ENODEV); 1755 MGMT_STATUS_INVALID_PARAMS);
1521 1756
1522 hci_dev_lock_bh(hdev); 1757 hci_dev_lock_bh(hdev);
1523 1758
1524 if (!test_bit(HCI_UP, &hdev->flags)) { 1759 if (!test_bit(HCI_UP, &hdev->flags)) {
1525 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, 1760 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
1526 ENETDOWN); 1761 MGMT_STATUS_NOT_POWERED);
1527 goto unlock; 1762 goto unlock;
1528 } 1763 }
1529 1764
1530 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) { 1765 if (!(hdev->features[6] & LMP_SIMPLE_PAIR)) {
1531 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, 1766 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
1532 EOPNOTSUPP); 1767 MGMT_STATUS_NOT_SUPPORTED);
1533 goto unlock; 1768 goto unlock;
1534 } 1769 }
1535 1770
1536 if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) { 1771 if (mgmt_pending_find(MGMT_OP_READ_LOCAL_OOB_DATA, hdev)) {
1537 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, EBUSY); 1772 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
1773 MGMT_STATUS_BUSY);
1538 goto unlock; 1774 goto unlock;
1539 } 1775 }
1540 1776
@@ -1566,19 +1802,20 @@ static int add_remote_oob_data(struct sock *sk, u16 index, unsigned char *data,
1566 1802
1567 if (len != sizeof(*cp)) 1803 if (len != sizeof(*cp))
1568 return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, 1804 return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
1569 EINVAL); 1805 MGMT_STATUS_INVALID_PARAMS);
1570 1806
1571 hdev = hci_dev_get(index); 1807 hdev = hci_dev_get(index);
1572 if (!hdev) 1808 if (!hdev)
1573 return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, 1809 return cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
1574 ENODEV); 1810 MGMT_STATUS_INVALID_PARAMS);
1575 1811
1576 hci_dev_lock_bh(hdev); 1812 hci_dev_lock_bh(hdev);
1577 1813
1578 err = hci_add_remote_oob_data(hdev, &cp->bdaddr, cp->hash, 1814 err = hci_add_remote_oob_data(hdev, &cp->bdaddr, cp->hash,
1579 cp->randomizer); 1815 cp->randomizer);
1580 if (err < 0) 1816 if (err < 0)
1581 err = cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, -err); 1817 err = cmd_status(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA,
1818 MGMT_STATUS_FAILED);
1582 else 1819 else
1583 err = cmd_complete(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, NULL, 1820 err = cmd_complete(sk, index, MGMT_OP_ADD_REMOTE_OOB_DATA, NULL,
1584 0); 1821 0);
@@ -1600,19 +1837,19 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
1600 1837
1601 if (len != sizeof(*cp)) 1838 if (len != sizeof(*cp))
1602 return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 1839 return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
1603 EINVAL); 1840 MGMT_STATUS_INVALID_PARAMS);
1604 1841
1605 hdev = hci_dev_get(index); 1842 hdev = hci_dev_get(index);
1606 if (!hdev) 1843 if (!hdev)
1607 return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 1844 return cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
1608 ENODEV); 1845 MGMT_STATUS_INVALID_PARAMS);
1609 1846
1610 hci_dev_lock_bh(hdev); 1847 hci_dev_lock_bh(hdev);
1611 1848
1612 err = hci_remove_remote_oob_data(hdev, &cp->bdaddr); 1849 err = hci_remove_remote_oob_data(hdev, &cp->bdaddr);
1613 if (err < 0) 1850 if (err < 0)
1614 err = cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 1851 err = cmd_status(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
1615 -err); 1852 MGMT_STATUS_INVALID_PARAMS);
1616 else 1853 else
1617 err = cmd_complete(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA, 1854 err = cmd_complete(sk, index, MGMT_OP_REMOVE_REMOTE_OOB_DATA,
1618 NULL, 0); 1855 NULL, 0);
@@ -1623,22 +1860,30 @@ static int remove_remote_oob_data(struct sock *sk, u16 index,
1623 return err; 1860 return err;
1624} 1861}
1625 1862
1626static int start_discovery(struct sock *sk, u16 index) 1863static int start_discovery(struct sock *sk, u16 index,
1864 unsigned char *data, u16 len)
1627{ 1865{
1866 struct mgmt_cp_start_discovery *cp = (void *) data;
1628 struct pending_cmd *cmd; 1867 struct pending_cmd *cmd;
1629 struct hci_dev *hdev; 1868 struct hci_dev *hdev;
1630 int err; 1869 int err;
1631 1870
1632 BT_DBG("hci%u", index); 1871 BT_DBG("hci%u", index);
1633 1872
1873 if (len != sizeof(*cp))
1874 return cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
1875 MGMT_STATUS_INVALID_PARAMS);
1876
1634 hdev = hci_dev_get(index); 1877 hdev = hci_dev_get(index);
1635 if (!hdev) 1878 if (!hdev)
1636 return cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENODEV); 1879 return cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
1880 MGMT_STATUS_INVALID_PARAMS);
1637 1881
1638 hci_dev_lock_bh(hdev); 1882 hci_dev_lock_bh(hdev);
1639 1883
1640 if (!test_bit(HCI_UP, &hdev->flags)) { 1884 if (!test_bit(HCI_UP, &hdev->flags)) {
1641 err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY, ENETDOWN); 1885 err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
1886 MGMT_STATUS_NOT_POWERED);
1642 goto failed; 1887 goto failed;
1643 } 1888 }
1644 1889
@@ -1669,7 +1914,8 @@ static int stop_discovery(struct sock *sk, u16 index)
1669 1914
1670 hdev = hci_dev_get(index); 1915 hdev = hci_dev_get(index);
1671 if (!hdev) 1916 if (!hdev)
1672 return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY, ENODEV); 1917 return cmd_status(sk, index, MGMT_OP_STOP_DISCOVERY,
1918 MGMT_STATUS_INVALID_PARAMS);
1673 1919
1674 hci_dev_lock_bh(hdev); 1920 hci_dev_lock_bh(hdev);
1675 1921
@@ -1701,18 +1947,19 @@ static int block_device(struct sock *sk, u16 index, unsigned char *data,
1701 1947
1702 if (len != sizeof(*cp)) 1948 if (len != sizeof(*cp))
1703 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE, 1949 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
1704 EINVAL); 1950 MGMT_STATUS_INVALID_PARAMS);
1705 1951
1706 hdev = hci_dev_get(index); 1952 hdev = hci_dev_get(index);
1707 if (!hdev) 1953 if (!hdev)
1708 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE, 1954 return cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
1709 ENODEV); 1955 MGMT_STATUS_INVALID_PARAMS);
1710 1956
1711 hci_dev_lock_bh(hdev); 1957 hci_dev_lock_bh(hdev);
1712 1958
1713 err = hci_blacklist_add(hdev, &cp->bdaddr); 1959 err = hci_blacklist_add(hdev, &cp->bdaddr);
1714 if (err < 0) 1960 if (err < 0)
1715 err = cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE, -err); 1961 err = cmd_status(sk, index, MGMT_OP_BLOCK_DEVICE,
1962 MGMT_STATUS_FAILED);
1716 else 1963 else
1717 err = cmd_complete(sk, index, MGMT_OP_BLOCK_DEVICE, 1964 err = cmd_complete(sk, index, MGMT_OP_BLOCK_DEVICE,
1718 NULL, 0); 1965 NULL, 0);
@@ -1734,19 +1981,20 @@ static int unblock_device(struct sock *sk, u16 index, unsigned char *data,
1734 1981
1735 if (len != sizeof(*cp)) 1982 if (len != sizeof(*cp))
1736 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE, 1983 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1737 EINVAL); 1984 MGMT_STATUS_INVALID_PARAMS);
1738 1985
1739 hdev = hci_dev_get(index); 1986 hdev = hci_dev_get(index);
1740 if (!hdev) 1987 if (!hdev)
1741 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE, 1988 return cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1742 ENODEV); 1989 MGMT_STATUS_INVALID_PARAMS);
1743 1990
1744 hci_dev_lock_bh(hdev); 1991 hci_dev_lock_bh(hdev);
1745 1992
1746 err = hci_blacklist_del(hdev, &cp->bdaddr); 1993 err = hci_blacklist_del(hdev, &cp->bdaddr);
1747 1994
1748 if (err < 0) 1995 if (err < 0)
1749 err = cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE, -err); 1996 err = cmd_status(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1997 MGMT_STATUS_INVALID_PARAMS);
1750 else 1998 else
1751 err = cmd_complete(sk, index, MGMT_OP_UNBLOCK_DEVICE, 1999 err = cmd_complete(sk, index, MGMT_OP_UNBLOCK_DEVICE,
1752 NULL, 0); 2000 NULL, 0);
@@ -1770,12 +2018,12 @@ static int set_fast_connectable(struct sock *sk, u16 index,
1770 2018
1771 if (len != sizeof(*cp)) 2019 if (len != sizeof(*cp))
1772 return cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE, 2020 return cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE,
1773 EINVAL); 2021 MGMT_STATUS_INVALID_PARAMS);
1774 2022
1775 hdev = hci_dev_get(index); 2023 hdev = hci_dev_get(index);
1776 if (!hdev) 2024 if (!hdev)
1777 return cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE, 2025 return cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE,
1778 ENODEV); 2026 MGMT_STATUS_INVALID_PARAMS);
1779 2027
1780 hci_dev_lock(hdev); 2028 hci_dev_lock(hdev);
1781 2029
@@ -1793,14 +2041,14 @@ static int set_fast_connectable(struct sock *sk, u16 index,
1793 sizeof(acp), &acp); 2041 sizeof(acp), &acp);
1794 if (err < 0) { 2042 if (err < 0) {
1795 err = cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE, 2043 err = cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE,
1796 -err); 2044 MGMT_STATUS_FAILED);
1797 goto done; 2045 goto done;
1798 } 2046 }
1799 2047
1800 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type); 2048 err = hci_send_cmd(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE, 1, &type);
1801 if (err < 0) { 2049 if (err < 0) {
1802 err = cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE, 2050 err = cmd_status(sk, index, MGMT_OP_SET_FAST_CONNECTABLE,
1803 -err); 2051 MGMT_STATUS_FAILED);
1804 goto done; 2052 goto done;
1805 } 2053 }
1806 2054
@@ -1903,10 +2151,18 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1903 err = pair_device(sk, index, buf + sizeof(*hdr), len); 2151 err = pair_device(sk, index, buf + sizeof(*hdr), len);
1904 break; 2152 break;
1905 case MGMT_OP_USER_CONFIRM_REPLY: 2153 case MGMT_OP_USER_CONFIRM_REPLY:
1906 err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len, 1); 2154 err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len);
1907 break; 2155 break;
1908 case MGMT_OP_USER_CONFIRM_NEG_REPLY: 2156 case MGMT_OP_USER_CONFIRM_NEG_REPLY:
1909 err = user_confirm_reply(sk, index, buf + sizeof(*hdr), len, 0); 2157 err = user_confirm_neg_reply(sk, index, buf + sizeof(*hdr),
2158 len);
2159 break;
2160 case MGMT_OP_USER_PASSKEY_REPLY:
2161 err = user_passkey_reply(sk, index, buf + sizeof(*hdr), len);
2162 break;
2163 case MGMT_OP_USER_PASSKEY_NEG_REPLY:
2164 err = user_passkey_neg_reply(sk, index, buf + sizeof(*hdr),
2165 len);
1910 break; 2166 break;
1911 case MGMT_OP_SET_LOCAL_NAME: 2167 case MGMT_OP_SET_LOCAL_NAME:
1912 err = set_local_name(sk, index, buf + sizeof(*hdr), len); 2168 err = set_local_name(sk, index, buf + sizeof(*hdr), len);
@@ -1922,7 +2178,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1922 len); 2178 len);
1923 break; 2179 break;
1924 case MGMT_OP_START_DISCOVERY: 2180 case MGMT_OP_START_DISCOVERY:
1925 err = start_discovery(sk, index); 2181 err = start_discovery(sk, index, buf + sizeof(*hdr), len);
1926 break; 2182 break;
1927 case MGMT_OP_STOP_DISCOVERY: 2183 case MGMT_OP_STOP_DISCOVERY:
1928 err = stop_discovery(sk, index); 2184 err = stop_discovery(sk, index);
@@ -1939,7 +2195,8 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
1939 break; 2195 break;
1940 default: 2196 default:
1941 BT_DBG("Unknown op %u", opcode); 2197 BT_DBG("Unknown op %u", opcode);
1942 err = cmd_status(sk, index, opcode, 0x01); 2198 err = cmd_status(sk, index, opcode,
2199 MGMT_STATUS_UNKNOWN_COMMAND);
1943 break; 2200 break;
1944 } 2201 }
1945 2202
@@ -2062,13 +2319,15 @@ int mgmt_connectable(struct hci_dev *hdev, u8 connectable)
2062 2319
2063int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status) 2320int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status)
2064{ 2321{
2322 u8 mgmt_err = mgmt_status(status);
2323
2065 if (scan & SCAN_PAGE) 2324 if (scan & SCAN_PAGE)
2066 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev, 2325 mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev,
2067 cmd_status_rsp, &status); 2326 cmd_status_rsp, &mgmt_err);
2068 2327
2069 if (scan & SCAN_INQUIRY) 2328 if (scan & SCAN_INQUIRY)
2070 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev, 2329 mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev,
2071 cmd_status_rsp, &status); 2330 cmd_status_rsp, &mgmt_err);
2072 2331
2073 return 0; 2332 return 0;
2074} 2333}
@@ -2089,12 +2348,13 @@ int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2089 return mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); 2348 return mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
2090} 2349}
2091 2350
2092int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type) 2351int mgmt_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2352 u8 addr_type)
2093{ 2353{
2094 struct mgmt_addr_info ev; 2354 struct mgmt_addr_info ev;
2095 2355
2096 bacpy(&ev.bdaddr, bdaddr); 2356 bacpy(&ev.bdaddr, bdaddr);
2097 ev.type = link_to_mgmt(link_type); 2357 ev.type = link_to_mgmt(link_type, addr_type);
2098 2358
2099 return mgmt_event(MGMT_EV_CONNECTED, hdev, &ev, sizeof(ev), NULL); 2359 return mgmt_event(MGMT_EV_CONNECTED, hdev, &ev, sizeof(ev), NULL);
2100} 2360}
@@ -2106,6 +2366,7 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data)
2106 struct mgmt_rp_disconnect rp; 2366 struct mgmt_rp_disconnect rp;
2107 2367
2108 bacpy(&rp.bdaddr, &cp->bdaddr); 2368 bacpy(&rp.bdaddr, &cp->bdaddr);
2369 rp.status = 0;
2109 2370
2110 cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, &rp, sizeof(rp)); 2371 cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT, &rp, sizeof(rp));
2111 2372
@@ -2115,7 +2376,25 @@ static void disconnect_rsp(struct pending_cmd *cmd, void *data)
2115 mgmt_pending_remove(cmd); 2376 mgmt_pending_remove(cmd);
2116} 2377}
2117 2378
2118int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) 2379static void remove_keys_rsp(struct pending_cmd *cmd, void *data)
2380{
2381 u8 *status = data;
2382 struct mgmt_cp_remove_keys *cp = cmd->param;
2383 struct mgmt_rp_remove_keys rp;
2384
2385 memset(&rp, 0, sizeof(rp));
2386 bacpy(&rp.bdaddr, &cp->bdaddr);
2387 if (status != NULL)
2388 rp.status = *status;
2389
2390 cmd_complete(cmd->sk, cmd->index, MGMT_OP_REMOVE_KEYS, &rp,
2391 sizeof(rp));
2392
2393 mgmt_pending_remove(cmd);
2394}
2395
2396int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2397 u8 addr_type)
2119{ 2398{
2120 struct mgmt_addr_info ev; 2399 struct mgmt_addr_info ev;
2121 struct sock *sk = NULL; 2400 struct sock *sk = NULL;
@@ -2124,40 +2403,53 @@ int mgmt_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
2124 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk); 2403 mgmt_pending_foreach(MGMT_OP_DISCONNECT, hdev, disconnect_rsp, &sk);
2125 2404
2126 bacpy(&ev.bdaddr, bdaddr); 2405 bacpy(&ev.bdaddr, bdaddr);
2127 ev.type = link_to_mgmt(type); 2406 ev.type = link_to_mgmt(link_type, addr_type);
2128 2407
2129 err = mgmt_event(MGMT_EV_DISCONNECTED, hdev, &ev, sizeof(ev), sk); 2408 err = mgmt_event(MGMT_EV_DISCONNECTED, hdev, &ev, sizeof(ev), sk);
2130 2409
2131 if (sk) 2410 if (sk)
2132 sock_put(sk); 2411 sock_put(sk);
2133 2412
2413 mgmt_pending_foreach(MGMT_OP_REMOVE_KEYS, hdev, remove_keys_rsp, NULL);
2414
2134 return err; 2415 return err;
2135} 2416}
2136 2417
2137int mgmt_disconnect_failed(struct hci_dev *hdev) 2418int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status)
2138{ 2419{
2139 struct pending_cmd *cmd; 2420 struct pending_cmd *cmd;
2421 u8 mgmt_err = mgmt_status(status);
2140 int err; 2422 int err;
2141 2423
2142 cmd = mgmt_pending_find(MGMT_OP_DISCONNECT, hdev); 2424 cmd = mgmt_pending_find(MGMT_OP_DISCONNECT, hdev);
2143 if (!cmd) 2425 if (!cmd)
2144 return -ENOENT; 2426 return -ENOENT;
2145 2427
2146 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_DISCONNECT, EIO); 2428 if (bdaddr) {
2429 struct mgmt_rp_disconnect rp;
2430
2431 bacpy(&rp.bdaddr, bdaddr);
2432 rp.status = status;
2433
2434 err = cmd_complete(cmd->sk, cmd->index, MGMT_OP_DISCONNECT,
2435 &rp, sizeof(rp));
2436 } else
2437 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_DISCONNECT,
2438 mgmt_err);
2147 2439
2148 mgmt_pending_remove(cmd); 2440 mgmt_pending_remove(cmd);
2149 2441
2150 return err; 2442 return err;
2151} 2443}
2152 2444
2153int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type, 2445int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2154 u8 status) 2446 u8 addr_type, u8 status)
2155{ 2447{
2156 struct mgmt_ev_connect_failed ev; 2448 struct mgmt_ev_connect_failed ev;
2157 2449
2158 bacpy(&ev.addr.bdaddr, bdaddr); 2450 bacpy(&ev.addr.bdaddr, bdaddr);
2159 ev.addr.type = link_to_mgmt(type); 2451 ev.addr.type = link_to_mgmt(link_type, addr_type);
2160 ev.status = status; 2452 ev.status = mgmt_status(status);
2161 2453
2162 return mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL); 2454 return mgmt_event(MGMT_EV_CONNECT_FAILED, hdev, &ev, sizeof(ev), NULL);
2163} 2455}
@@ -2185,7 +2477,7 @@ int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2185 return -ENOENT; 2477 return -ENOENT;
2186 2478
2187 bacpy(&rp.bdaddr, bdaddr); 2479 bacpy(&rp.bdaddr, bdaddr);
2188 rp.status = status; 2480 rp.status = mgmt_status(status);
2189 2481
2190 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, &rp, 2482 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_REPLY, &rp,
2191 sizeof(rp)); 2483 sizeof(rp));
@@ -2207,7 +2499,7 @@ int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2207 return -ENOENT; 2499 return -ENOENT;
2208 2500
2209 bacpy(&rp.bdaddr, bdaddr); 2501 bacpy(&rp.bdaddr, bdaddr);
2210 rp.status = status; 2502 rp.status = mgmt_status(status);
2211 2503
2212 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY, &rp, 2504 err = cmd_complete(cmd->sk, hdev->id, MGMT_OP_PIN_CODE_NEG_REPLY, &rp,
2213 sizeof(rp)); 2505 sizeof(rp));
@@ -2232,7 +2524,19 @@ int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
2232 NULL); 2524 NULL);
2233} 2525}
2234 2526
2235static int confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 2527int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr)
2528{
2529 struct mgmt_ev_user_passkey_request ev;
2530
2531 BT_DBG("%s", hdev->name);
2532
2533 bacpy(&ev.bdaddr, bdaddr);
2534
2535 return mgmt_event(MGMT_EV_USER_PASSKEY_REQUEST, hdev, &ev, sizeof(ev),
2536 NULL);
2537}
2538
2539static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2236 u8 status, u8 opcode) 2540 u8 status, u8 opcode)
2237{ 2541{
2238 struct pending_cmd *cmd; 2542 struct pending_cmd *cmd;
@@ -2244,7 +2548,7 @@ static int confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2244 return -ENOENT; 2548 return -ENOENT;
2245 2549
2246 bacpy(&rp.bdaddr, bdaddr); 2550 bacpy(&rp.bdaddr, bdaddr);
2247 rp.status = status; 2551 rp.status = mgmt_status(status);
2248 err = cmd_complete(cmd->sk, hdev->id, opcode, &rp, sizeof(rp)); 2552 err = cmd_complete(cmd->sk, hdev->id, opcode, &rp, sizeof(rp));
2249 2553
2250 mgmt_pending_remove(cmd); 2554 mgmt_pending_remove(cmd);
@@ -2255,23 +2559,37 @@ static int confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2255int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 2559int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2256 u8 status) 2560 u8 status)
2257{ 2561{
2258 return confirm_reply_complete(hdev, bdaddr, status, 2562 return user_pairing_resp_complete(hdev, bdaddr, status,
2259 MGMT_OP_USER_CONFIRM_REPLY); 2563 MGMT_OP_USER_CONFIRM_REPLY);
2260} 2564}
2261 2565
2262int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, 2566int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
2263 bdaddr_t *bdaddr, u8 status) 2567 bdaddr_t *bdaddr, u8 status)
2264{ 2568{
2265 return confirm_reply_complete(hdev, bdaddr, status, 2569 return user_pairing_resp_complete(hdev, bdaddr, status,
2266 MGMT_OP_USER_CONFIRM_NEG_REPLY); 2570 MGMT_OP_USER_CONFIRM_NEG_REPLY);
2267} 2571}
2268 2572
2573int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2574 u8 status)
2575{
2576 return user_pairing_resp_complete(hdev, bdaddr, status,
2577 MGMT_OP_USER_PASSKEY_REPLY);
2578}
2579
2580int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
2581 bdaddr_t *bdaddr, u8 status)
2582{
2583 return user_pairing_resp_complete(hdev, bdaddr, status,
2584 MGMT_OP_USER_PASSKEY_NEG_REPLY);
2585}
2586
2269int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status) 2587int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status)
2270{ 2588{
2271 struct mgmt_ev_auth_failed ev; 2589 struct mgmt_ev_auth_failed ev;
2272 2590
2273 bacpy(&ev.bdaddr, bdaddr); 2591 bacpy(&ev.bdaddr, bdaddr);
2274 ev.status = status; 2592 ev.status = mgmt_status(status);
2275 2593
2276 return mgmt_event(MGMT_EV_AUTH_FAILED, hdev, &ev, sizeof(ev), NULL); 2594 return mgmt_event(MGMT_EV_AUTH_FAILED, hdev, &ev, sizeof(ev), NULL);
2277} 2595}
@@ -2291,7 +2609,7 @@ int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status)
2291 2609
2292 if (status) { 2610 if (status) {
2293 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME, 2611 err = cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_LOCAL_NAME,
2294 EIO); 2612 mgmt_status(status));
2295 goto failed; 2613 goto failed;
2296 } 2614 }
2297 2615
@@ -2326,7 +2644,8 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
2326 2644
2327 if (status) { 2645 if (status) {
2328 err = cmd_status(cmd->sk, hdev->id, 2646 err = cmd_status(cmd->sk, hdev->id,
2329 MGMT_OP_READ_LOCAL_OOB_DATA, EIO); 2647 MGMT_OP_READ_LOCAL_OOB_DATA,
2648 mgmt_status(status));
2330 } else { 2649 } else {
2331 struct mgmt_rp_read_local_oob_data rp; 2650 struct mgmt_rp_read_local_oob_data rp;
2332 2651
@@ -2343,15 +2662,15 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
2343 return err; 2662 return err;
2344} 2663}
2345 2664
2346int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type, 2665int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2347 u8 *dev_class, s8 rssi, u8 *eir) 2666 u8 addr_type, u8 *dev_class, s8 rssi, u8 *eir)
2348{ 2667{
2349 struct mgmt_ev_device_found ev; 2668 struct mgmt_ev_device_found ev;
2350 2669
2351 memset(&ev, 0, sizeof(ev)); 2670 memset(&ev, 0, sizeof(ev));
2352 2671
2353 bacpy(&ev.addr.bdaddr, bdaddr); 2672 bacpy(&ev.addr.bdaddr, bdaddr);
2354 ev.addr.type = link_to_mgmt(type); 2673 ev.addr.type = link_to_mgmt(link_type, addr_type);
2355 ev.rssi = rssi; 2674 ev.rssi = rssi;
2356 2675
2357 if (eir) 2676 if (eir)
@@ -2375,7 +2694,7 @@ int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name)
2375 return mgmt_event(MGMT_EV_REMOTE_NAME, hdev, &ev, sizeof(ev), NULL); 2694 return mgmt_event(MGMT_EV_REMOTE_NAME, hdev, &ev, sizeof(ev), NULL);
2376} 2695}
2377 2696
2378int mgmt_inquiry_failed(struct hci_dev *hdev, u8 status) 2697int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status)
2379{ 2698{
2380 struct pending_cmd *cmd; 2699 struct pending_cmd *cmd;
2381 int err; 2700 int err;
@@ -2384,6 +2703,21 @@ int mgmt_inquiry_failed(struct hci_dev *hdev, u8 status)
2384 if (!cmd) 2703 if (!cmd)
2385 return -ENOENT; 2704 return -ENOENT;
2386 2705
2706 err = cmd_status(cmd->sk, hdev->id, cmd->opcode, mgmt_status(status));
2707 mgmt_pending_remove(cmd);
2708
2709 return err;
2710}
2711
2712int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status)
2713{
2714 struct pending_cmd *cmd;
2715 int err;
2716
2717 cmd = mgmt_pending_find(MGMT_OP_STOP_DISCOVERY, hdev);
2718 if (!cmd)
2719 return -ENOENT;
2720
2387 err = cmd_status(cmd->sk, hdev->id, cmd->opcode, status); 2721 err = cmd_status(cmd->sk, hdev->id, cmd->opcode, status);
2388 mgmt_pending_remove(cmd); 2722 mgmt_pending_remove(cmd);
2389 2723
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 94e94ca35384..0b96737d0ad3 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -232,6 +232,18 @@ static u8 check_enc_key_size(struct l2cap_conn *conn, __u8 max_key_size)
232 return 0; 232 return 0;
233} 233}
234 234
235static void smp_failure(struct l2cap_conn *conn, u8 reason, u8 send)
236{
237 if (send)
238 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason),
239 &reason);
240
241 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->hcon->pend);
242 mgmt_auth_failed(conn->hcon->hdev, conn->dst, reason);
243 del_timer(&conn->security_timer);
244 smp_chan_destroy(conn);
245}
246
235static void confirm_work(struct work_struct *work) 247static void confirm_work(struct work_struct *work)
236{ 248{
237 struct smp_chan *smp = container_of(work, struct smp_chan, confirm); 249 struct smp_chan *smp = container_of(work, struct smp_chan, confirm);
@@ -270,8 +282,7 @@ static void confirm_work(struct work_struct *work)
270 return; 282 return;
271 283
272error: 284error:
273 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), &reason); 285 smp_failure(conn, reason, 1);
274 smp_chan_destroy(conn);
275} 286}
276 287
277static void random_work(struct work_struct *work) 288static void random_work(struct work_struct *work)
@@ -354,8 +365,7 @@ static void random_work(struct work_struct *work)
354 return; 365 return;
355 366
356error: 367error:
357 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), &reason); 368 smp_failure(conn, reason, 1);
358 smp_chan_destroy(conn);
359} 369}
360 370
361static struct smp_chan *smp_chan_create(struct l2cap_conn *conn) 371static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
@@ -379,7 +389,15 @@ static struct smp_chan *smp_chan_create(struct l2cap_conn *conn)
379 389
380void smp_chan_destroy(struct l2cap_conn *conn) 390void smp_chan_destroy(struct l2cap_conn *conn)
381{ 391{
382 kfree(conn->smp_chan); 392 struct smp_chan *smp = conn->smp_chan;
393
394 clear_bit(HCI_CONN_LE_SMP_PEND, &conn->hcon->pend);
395
396 if (smp->tfm)
397 crypto_free_blkcipher(smp->tfm);
398
399 kfree(smp);
400 conn->smp_chan = NULL;
383 hci_conn_put(conn->hcon); 401 hci_conn_put(conn->hcon);
384} 402}
385 403
@@ -647,6 +665,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
647 break; 665 break;
648 666
649 case SMP_CMD_PAIRING_FAIL: 667 case SMP_CMD_PAIRING_FAIL:
668 smp_failure(conn, skb->data[0], 0);
650 reason = 0; 669 reason = 0;
651 err = -EPERM; 670 err = -EPERM;
652 break; 671 break;
@@ -692,8 +711,7 @@ int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb)
692 711
693done: 712done:
694 if (reason) 713 if (reason)
695 smp_send_cmd(conn, SMP_CMD_PAIRING_FAIL, sizeof(reason), 714 smp_failure(conn, reason, 1);
696 &reason);
697 715
698 kfree_skb(skb); 716 kfree_skb(skb);
699 return err; 717 return err;
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index e844e5a38408..96debba2c407 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -185,6 +185,8 @@ static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *d
185 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 185 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
186 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 186 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
187 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 187 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
188 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
189 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
188 190
189 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 191 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
190 IEEE80211_STYPE_ACTION); 192 IEEE80211_STYPE_ACTION);
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index 2c2e9519a2e7..c45fa5df0d41 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -83,6 +83,8 @@ static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
83 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 83 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
84 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 84 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
85 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 85 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
86 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
87 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
86 88
87 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 89 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
88 IEEE80211_STYPE_ACTION); 90 IEEE80211_STYPE_ACTION);
@@ -419,7 +421,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
419 if (sdata->vif.type != NL80211_IFTYPE_STATION && 421 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
420 sdata->vif.type != NL80211_IFTYPE_MESH_POINT && 422 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
421 sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 423 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
422 sdata->vif.type != NL80211_IFTYPE_AP) 424 sdata->vif.type != NL80211_IFTYPE_AP &&
425 sdata->vif.type != NL80211_IFTYPE_ADHOC)
423 return -EINVAL; 426 return -EINVAL;
424 427
425 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) { 428 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
@@ -430,6 +433,27 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
430 return -EINVAL; 433 return -EINVAL;
431 } 434 }
432 435
436 /*
437 * 802.11n-2009 11.5.1.1: If the initiating STA is an HT STA, is a
438 * member of an IBSS, and has no other existing Block Ack agreement
439 * with the recipient STA, then the initiating STA shall transmit a
440 * Probe Request frame to the recipient STA and shall not transmit an
441 * ADDBA Request frame unless it receives a Probe Response frame
442 * from the recipient within dot11ADDBAFailureTimeout.
443 *
444 * The probe request mechanism for ADDBA is currently not implemented,
445 * but we only build up Block Ack session with HT STAs. This information
446 * is set when we receive a bss info from a probe response or a beacon.
447 */
448 if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
449 !sta->sta.ht_cap.ht_supported) {
450#ifdef CONFIG_MAC80211_HT_DEBUG
451 printk(KERN_DEBUG "BA request denied - IBSS STA %pM"
452 "does not advertise HT support\n", pubsta->addr);
453#endif /* CONFIG_MAC80211_HT_DEBUG */
454 return -EINVAL;
455 }
456
433 spin_lock_bh(&sta->lock); 457 spin_lock_bh(&sta->lock);
434 458
435 /* we have tried too many times, receiver does not want A-MPDU */ 459 /* we have tried too many times, receiver does not want A-MPDU */
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index d3eafaefb16b..0fd9c2a7f242 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -47,7 +47,9 @@ void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
47 int i; 47 int i;
48 48
49 if (sdata->vif.type != NL80211_IFTYPE_STATION) { 49 if (sdata->vif.type != NL80211_IFTYPE_STATION) {
50 WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION); 50 /* AP interfaces call this code when adding new stations,
51 * so just silently ignore non station interfaces.
52 */
51 return; 53 return;
52 } 54 }
53 55
@@ -282,6 +284,8 @@ void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
282 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 284 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
283 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 285 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
284 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); 286 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
287 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
288 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
285 289
286 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 290 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
287 IEEE80211_STYPE_ACTION); 291 IEEE80211_STYPE_ACTION);
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 7d84af70132f..3f830ac159e5 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -77,6 +77,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
77 struct cfg80211_bss *bss; 77 struct cfg80211_bss *bss;
78 u32 bss_change; 78 u32 bss_change;
79 u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; 79 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
80 enum nl80211_channel_type channel_type;
80 81
81 lockdep_assert_held(&ifibss->mtx); 82 lockdep_assert_held(&ifibss->mtx);
82 83
@@ -105,8 +106,16 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
105 106
106 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0; 107 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
107 108
108 local->oper_channel = chan; 109 channel_type = ifibss->channel_type;
109 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT)); 110 if (channel_type > NL80211_CHAN_HT20 &&
111 !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
112 channel_type = NL80211_CHAN_HT20;
113 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
114 /* can only fail due to HT40+/- mismatch */
115 channel_type = NL80211_CHAN_HT20;
116 WARN_ON(!ieee80211_set_channel_type(local, sdata,
117 NL80211_CHAN_HT20));
118 }
110 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 119 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
111 120
112 sband = local->hw.wiphy->bands[chan->band]; 121 sband = local->hw.wiphy->bands[chan->band];
@@ -172,6 +181,19 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
172 memcpy(skb_put(skb, ifibss->ie_len), 181 memcpy(skb_put(skb, ifibss->ie_len),
173 ifibss->ie, ifibss->ie_len); 182 ifibss->ie, ifibss->ie_len);
174 183
184 /* add HT capability and information IEs */
185 if (channel_type && sband->ht_cap.ht_supported) {
186 pos = skb_put(skb, 4 +
187 sizeof(struct ieee80211_ht_cap) +
188 sizeof(struct ieee80211_ht_info));
189 pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
190 sband->ht_cap.cap);
191 pos = ieee80211_ie_build_ht_info(pos,
192 &sband->ht_cap,
193 chan,
194 channel_type);
195 }
196
175 if (local->hw.queues >= 4) { 197 if (local->hw.queues >= 4) {
176 pos = skb_put(skb, 9); 198 pos = skb_put(skb, 9);
177 *pos++ = WLAN_EID_VENDOR_SPECIFIC; 199 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
@@ -195,6 +217,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
195 bss_change |= BSS_CHANGED_BEACON; 217 bss_change |= BSS_CHANGED_BEACON;
196 bss_change |= BSS_CHANGED_BEACON_ENABLED; 218 bss_change |= BSS_CHANGED_BEACON_ENABLED;
197 bss_change |= BSS_CHANGED_BASIC_RATES; 219 bss_change |= BSS_CHANGED_BASIC_RATES;
220 bss_change |= BSS_CHANGED_HT;
198 bss_change |= BSS_CHANGED_IBSS; 221 bss_change |= BSS_CHANGED_IBSS;
199 sdata->vif.bss_conf.ibss_joined = true; 222 sdata->vif.bss_conf.ibss_joined = true;
200 ieee80211_bss_info_change_notify(sdata, bss_change); 223 ieee80211_bss_info_change_notify(sdata, bss_change);
@@ -268,6 +291,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
268 u64 beacon_timestamp, rx_timestamp; 291 u64 beacon_timestamp, rx_timestamp;
269 u32 supp_rates = 0; 292 u32 supp_rates = 0;
270 enum ieee80211_band band = rx_status->band; 293 enum ieee80211_band band = rx_status->band;
294 struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
295 bool rates_updated = false;
271 296
272 if (elems->ds_params && elems->ds_params_len == 1) 297 if (elems->ds_params && elems->ds_params_len == 1)
273 freq = ieee80211_channel_to_frequency(elems->ds_params[0], 298 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
@@ -307,7 +332,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
307 prev_rates, 332 prev_rates,
308 sta->sta.supp_rates[band]); 333 sta->sta.supp_rates[band]);
309#endif 334#endif
310 rate_control_rate_init(sta); 335 rates_updated = true;
311 } 336 }
312 } else 337 } else
313 sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid, 338 sta = ieee80211_ibss_add_sta(sdata, mgmt->bssid,
@@ -318,6 +343,39 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
318 if (sta && elems->wmm_info) 343 if (sta && elems->wmm_info)
319 set_sta_flag(sta, WLAN_STA_WME); 344 set_sta_flag(sta, WLAN_STA_WME);
320 345
346 if (sta && elems->ht_info_elem && elems->ht_cap_elem &&
347 sdata->u.ibss.channel_type != NL80211_CHAN_NO_HT) {
348 /* we both use HT */
349 struct ieee80211_sta_ht_cap sta_ht_cap_new;
350 enum nl80211_channel_type channel_type =
351 ieee80211_ht_info_to_channel_type(
352 elems->ht_info_elem);
353
354 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
355 elems->ht_cap_elem,
356 &sta_ht_cap_new);
357
358 /*
359 * fall back to HT20 if we don't use or use
360 * the other extension channel
361 */
362 if ((channel_type == NL80211_CHAN_HT40MINUS ||
363 channel_type == NL80211_CHAN_HT40PLUS) &&
364 channel_type != sdata->u.ibss.channel_type)
365 sta_ht_cap_new.cap &=
366 ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
367
368 if (memcmp(&sta->sta.ht_cap, &sta_ht_cap_new,
369 sizeof(sta_ht_cap_new))) {
370 memcpy(&sta->sta.ht_cap, &sta_ht_cap_new,
371 sizeof(sta_ht_cap_new));
372 rates_updated = true;
373 }
374 }
375
376 if (sta && rates_updated)
377 rate_control_rate_init(sta);
378
321 rcu_read_unlock(); 379 rcu_read_unlock();
322 } 380 }
323 381
@@ -896,12 +954,18 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
896 struct cfg80211_ibss_params *params) 954 struct cfg80211_ibss_params *params)
897{ 955{
898 struct sk_buff *skb; 956 struct sk_buff *skb;
957 u32 changed = 0;
899 958
900 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom + 959 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
901 36 /* bitrates */ + 960 sizeof(struct ieee80211_hdr_3addr) +
902 34 /* SSID */ + 961 12 /* struct ieee80211_mgmt.u.beacon */ +
903 3 /* DS params */ + 962 2 + IEEE80211_MAX_SSID_LEN /* max SSID */ +
904 4 /* IBSS params */ + 963 2 + 8 /* max Supported Rates */ +
964 3 /* max DS params */ +
965 4 /* IBSS params */ +
966 2 + (IEEE80211_MAX_SUPP_RATES - 8) +
967 2 + sizeof(struct ieee80211_ht_cap) +
968 2 + sizeof(struct ieee80211_ht_info) +
905 params->ie_len); 969 params->ie_len);
906 if (!skb) 970 if (!skb)
907 return -ENOMEM; 971 return -ENOMEM;
@@ -922,13 +986,15 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
922 sdata->vif.bss_conf.beacon_int = params->beacon_interval; 986 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
923 987
924 sdata->u.ibss.channel = params->channel; 988 sdata->u.ibss.channel = params->channel;
989 sdata->u.ibss.channel_type = params->channel_type;
925 sdata->u.ibss.fixed_channel = params->channel_fixed; 990 sdata->u.ibss.fixed_channel = params->channel_fixed;
926 991
927 /* fix ourselves to that channel now already */ 992 /* fix ourselves to that channel now already */
928 if (params->channel_fixed) { 993 if (params->channel_fixed) {
929 sdata->local->oper_channel = params->channel; 994 sdata->local->oper_channel = params->channel;
930 WARN_ON(!ieee80211_set_channel_type(sdata->local, sdata, 995 if (!ieee80211_set_channel_type(sdata->local, sdata,
931 NL80211_CHAN_NO_HT)); 996 params->channel_type))
997 return -EINVAL;
932 } 998 }
933 999
934 if (params->ie) { 1000 if (params->ie) {
@@ -951,6 +1017,23 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
951 ieee80211_recalc_idle(sdata->local); 1017 ieee80211_recalc_idle(sdata->local);
952 mutex_unlock(&sdata->local->mtx); 1018 mutex_unlock(&sdata->local->mtx);
953 1019
1020 /*
1021 * 802.11n-2009 9.13.3.1: In an IBSS, the HT Protection field is
1022 * reserved, but an HT STA shall protect HT transmissions as though
1023 * the HT Protection field were set to non-HT mixed mode.
1024 *
1025 * In an IBSS, the RIFS Mode field of the HT Operation element is
1026 * also reserved, but an HT STA shall operate as though this field
1027 * were set to 1.
1028 */
1029
1030 sdata->vif.bss_conf.ht_operation_mode |=
1031 IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED
1032 | IEEE80211_HT_PARAM_RIFS_MODE;
1033
1034 changed |= BSS_CHANGED_HT;
1035 ieee80211_bss_info_change_notify(sdata, changed);
1036
954 ieee80211_queue_work(&sdata->local->hw, &sdata->work); 1037 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
955 1038
956 return 0; 1039 return 0;
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index bdefa6ba3f4c..96fe75410bbe 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -474,6 +474,7 @@ struct ieee80211_if_ibss {
474 u8 ssid_len, ie_len; 474 u8 ssid_len, ie_len;
475 u8 *ie; 475 u8 *ie;
476 struct ieee80211_channel *channel; 476 struct ieee80211_channel *channel;
477 enum nl80211_channel_type channel_type;
477 478
478 unsigned long ibss_join_req; 479 unsigned long ibss_join_req;
479 /* probe response/beacon for IBSS */ 480 /* probe response/beacon for IBSS */
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 24cc50b963a9..60198ac664a0 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -570,7 +570,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
570 WIPHY_FLAG_OFFCHAN_TX | 570 WIPHY_FLAG_OFFCHAN_TX |
571 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 571 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
572 572
573 wiphy->features = NL80211_FEATURE_SK_TX_STATUS; 573 wiphy->features = NL80211_FEATURE_SK_TX_STATUS |
574 NL80211_FEATURE_HT_IBSS;
574 575
575 if (!ops->set_key) 576 if (!ops->set_key)
576 wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 577 wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index daf5cde65b30..7d226417ef46 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2237,7 +2237,8 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
2237 if (sdata->vif.type != NL80211_IFTYPE_STATION && 2237 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2238 sdata->vif.type != NL80211_IFTYPE_MESH_POINT && 2238 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2239 sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 2239 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
2240 sdata->vif.type != NL80211_IFTYPE_AP) 2240 sdata->vif.type != NL80211_IFTYPE_AP &&
2241 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2241 break; 2242 break;
2242 2243
2243 /* verify action_code is present */ 2244 /* verify action_code is present */
@@ -2796,10 +2797,17 @@ static int prepare_for_handlers(struct ieee80211_rx_data *rx,
2796 return 0; 2797 return 0;
2797 } else if (!ieee80211_bssid_match(bssid, 2798 } else if (!ieee80211_bssid_match(bssid,
2798 sdata->vif.addr)) { 2799 sdata->vif.addr)) {
2800 /*
2801 * Accept public action frames even when the
2802 * BSSID doesn't match, this is used for P2P
2803 * and location updates. Note that mac80211
2804 * itself never looks at these frames.
2805 */
2806 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2807 ieee80211_is_public_action(hdr, skb->len))
2808 return 1;
2799 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) && 2809 if (!(status->rx_flags & IEEE80211_RX_IN_SCAN) &&
2800 !ieee80211_is_beacon(hdr->frame_control) && 2810 !ieee80211_is_beacon(hdr->frame_control))
2801 !(ieee80211_is_action(hdr->frame_control) &&
2802 sdata->vif.p2p))
2803 return 0; 2811 return 0;
2804 status->rx_flags &= ~IEEE80211_RX_RA_MATCH; 2812 status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
2805 } 2813 }
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index c4cb4a536e27..e74652d38245 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -1332,8 +1332,11 @@ static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1332 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)) 1332 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
1333 CALL_TXH(ieee80211_tx_h_rate_ctrl); 1333 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1334 1334
1335 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) 1335 if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
1336 __skb_queue_tail(&tx->skbs, tx->skb);
1337 tx->skb = NULL;
1336 goto txh_done; 1338 goto txh_done;
1339 }
1337 1340
1338 CALL_TXH(ieee80211_tx_h_michael_mic_add); 1341 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1339 CALL_TXH(ieee80211_tx_h_sequence); 1342 CALL_TXH(ieee80211_tx_h_sequence);
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 5243c2cadeef..ac7ea2949de0 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -1587,6 +1587,11 @@ u8 *ieee80211_ie_build_ht_info(u8 *pos,
1587 } 1587 }
1588 if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) 1588 if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1589 ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY; 1589 ht_info->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
1590
1591 /*
1592 * Note: According to 802.11n-2009 9.13.3.1, HT Protection field and
1593 * RIFS Mode are reserved in IBSS mode, therefore keep them at 0
1594 */
1590 ht_info->operation_mode = 0x0000; 1595 ht_info->operation_mode = 0x0000;
1591 ht_info->stbc_param = 0x0000; 1596 ht_info->stbc_param = 0x0000;
1592 1597
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 1f1ef70f34f2..2e4444fedbe0 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -121,15 +121,16 @@ config CFG80211_WEXT
121 121
122config WIRELESS_EXT_SYSFS 122config WIRELESS_EXT_SYSFS
123 bool "Wireless extensions sysfs files" 123 bool "Wireless extensions sysfs files"
124 default y
125 depends on WEXT_CORE && SYSFS 124 depends on WEXT_CORE && SYSFS
126 help 125 help
127 This option enables the deprecated wireless statistics 126 This option enables the deprecated wireless statistics
128 files in /sys/class/net/*/wireless/. The same information 127 files in /sys/class/net/*/wireless/. The same information
129 is available via the ioctls as well. 128 is available via the ioctls as well.
130 129
131 Say Y if you have programs using it, like old versions of 130 Say N. If you know you have ancient tools requiring it,
132 hal. 131 like very old versions of hal (prior to 0.5.12 release),
132 say Y and update the tools as soon as possible as this
133 option will be removed soon.
133 134
134config LIB80211 135config LIB80211
135 tristate "Common routines for IEEE802.11 drivers" 136 tristate "Common routines for IEEE802.11 drivers"
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 17cd0c04d139..2fcfe0993ca2 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -6,6 +6,7 @@
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 */ 7 */
8 8
9#include <linux/export.h>
9#include <net/cfg80211.h> 10#include <net/cfg80211.h>
10#include "core.h" 11#include "core.h"
11 12
@@ -44,9 +45,9 @@ rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
44 return chan; 45 return chan;
45} 46}
46 47
47static bool can_beacon_sec_chan(struct wiphy *wiphy, 48int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
48 struct ieee80211_channel *chan, 49 struct ieee80211_channel *chan,
49 enum nl80211_channel_type channel_type) 50 enum nl80211_channel_type channel_type)
50{ 51{
51 struct ieee80211_channel *sec_chan; 52 struct ieee80211_channel *sec_chan;
52 int diff; 53 int diff;
@@ -75,6 +76,7 @@ static bool can_beacon_sec_chan(struct wiphy *wiphy,
75 76
76 return true; 77 return true;
77} 78}
79EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
78 80
79int cfg80211_set_freq(struct cfg80211_registered_device *rdev, 81int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
80 struct wireless_dev *wdev, int freq, 82 struct wireless_dev *wdev, int freq,
@@ -109,8 +111,8 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
109 switch (channel_type) { 111 switch (channel_type) {
110 case NL80211_CHAN_HT40PLUS: 112 case NL80211_CHAN_HT40PLUS:
111 case NL80211_CHAN_HT40MINUS: 113 case NL80211_CHAN_HT40MINUS:
112 if (!can_beacon_sec_chan(&rdev->wiphy, chan, 114 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
113 channel_type)) { 115 channel_type)) {
114 printk(KERN_DEBUG 116 printk(KERN_DEBUG
115 "cfg80211: Secondary channel not " 117 "cfg80211: Secondary channel not "
116 "allowed to initiate communication\n"); 118 "allowed to initiate communication\n");
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 8a9b4d817ae6..ba439664c2e0 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -4682,13 +4682,41 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
4682 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 4682 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
4683 } 4683 }
4684 4684
4685 ibss.channel = ieee80211_get_channel(wiphy, 4685 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
4686 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); 4686 enum nl80211_channel_type channel_type;
4687
4688 channel_type = nla_get_u32(
4689 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
4690 if (channel_type != NL80211_CHAN_NO_HT &&
4691 channel_type != NL80211_CHAN_HT20 &&
4692 channel_type != NL80211_CHAN_HT40MINUS &&
4693 channel_type != NL80211_CHAN_HT40PLUS)
4694 return -EINVAL;
4695
4696 if (channel_type != NL80211_CHAN_NO_HT &&
4697 !(wiphy->features & NL80211_FEATURE_HT_IBSS))
4698 return -EINVAL;
4699
4700 ibss.channel_type = channel_type;
4701 } else {
4702 ibss.channel_type = NL80211_CHAN_NO_HT;
4703 }
4704
4705 ibss.channel = rdev_freq_to_chan(rdev,
4706 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
4707 ibss.channel_type);
4687 if (!ibss.channel || 4708 if (!ibss.channel ||
4688 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || 4709 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
4689 ibss.channel->flags & IEEE80211_CHAN_DISABLED) 4710 ibss.channel->flags & IEEE80211_CHAN_DISABLED)
4690 return -EINVAL; 4711 return -EINVAL;
4691 4712
4713 /* Both channels should be able to initiate communication */
4714 if ((ibss.channel_type == NL80211_CHAN_HT40PLUS ||
4715 ibss.channel_type == NL80211_CHAN_HT40MINUS) &&
4716 !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel,
4717 ibss.channel_type))
4718 return -EINVAL;
4719
4692 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; 4720 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
4693 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; 4721 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4694 4722