~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/wireless/wl12xx/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <linux/vmalloc.h>
31
31
#include <linux/platform_device.h>
32
32
#include <linux/slab.h>
 
33
#include <linux/wl12xx.h>
33
34
 
34
35
#include "wl12xx.h"
35
36
#include "wl12xx_80211.h"
50
51
 
51
52
static struct conf_drv_settings default_conf = {
52
53
        .sg = {
53
 
                .params = {
 
54
                .sta_params = {
54
55
                        [CONF_SG_BT_PER_THRESHOLD]                  = 7500,
55
56
                        [CONF_SG_HV3_MAX_OVERRIDE]                  = 0,
56
57
                        [CONF_SG_BT_NFS_SAMPLE_INTERVAL]            = 400,
57
 
                        [CONF_SG_BT_LOAD_RATIO]                     = 50,
 
58
                        [CONF_SG_BT_LOAD_RATIO]                     = 200,
58
59
                        [CONF_SG_AUTO_PS_MODE]                      = 1,
59
60
                        [CONF_SG_AUTO_SCAN_PROBE_REQ]               = 170,
60
61
                        [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3]   = 50,
100
101
                        [CONF_SG_DHCP_TIME]                         = 5000,
101
102
                        [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP]  = 100,
102
103
                },
 
104
                .ap_params = {
 
105
                        [CONF_SG_BT_PER_THRESHOLD]                  = 7500,
 
106
                        [CONF_SG_HV3_MAX_OVERRIDE]                  = 0,
 
107
                        [CONF_SG_BT_NFS_SAMPLE_INTERVAL]            = 400,
 
108
                        [CONF_SG_BT_LOAD_RATIO]                     = 50,
 
109
                        [CONF_SG_AUTO_PS_MODE]                      = 1,
 
110
                        [CONF_SG_AUTO_SCAN_PROBE_REQ]               = 170,
 
111
                        [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3]   = 50,
 
112
                        [CONF_SG_ANTENNA_CONFIGURATION]             = 0,
 
113
                        [CONF_SG_BEACON_MISS_PERCENT]               = 60,
 
114
                        [CONF_SG_RATE_ADAPT_THRESH]                 = 64,
 
115
                        [CONF_SG_RATE_ADAPT_SNR]                    = 1,
 
116
                        [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR]      = 10,
 
117
                        [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR]      = 25,
 
118
                        [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR]      = 25,
 
119
                        [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR]       = 20,
 
120
                        [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR]       = 25,
 
121
                        [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR]       = 25,
 
122
                        [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR]     = 7,
 
123
                        [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR]     = 25,
 
124
                        [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR]     = 25,
 
125
                        [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR]      = 8,
 
126
                        [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR]      = 25,
 
127
                        [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR]      = 25,
 
128
                        [CONF_SG_RXT]                               = 1200,
 
129
                        [CONF_SG_TXT]                               = 1000,
 
130
                        [CONF_SG_ADAPTIVE_RXT_TXT]                  = 1,
 
131
                        [CONF_SG_PS_POLL_TIMEOUT]                   = 10,
 
132
                        [CONF_SG_UPSD_TIMEOUT]                      = 10,
 
133
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
 
134
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
 
135
                        [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
 
136
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR]  = 8,
 
137
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR]  = 20,
 
138
                        [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR]  = 15,
 
139
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR]         = 20,
 
140
                        [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR]         = 50,
 
141
                        [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR]         = 10,
 
142
                        [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3]  = 200,
 
143
                        [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
 
144
                        [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME]         = 75,
 
145
                        [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME]       = 15,
 
146
                        [CONF_SG_HV3_MAX_SERVED]                    = 6,
 
147
                        [CONF_SG_DHCP_TIME]                         = 5000,
 
148
                        [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP]  = 100,
 
149
                        [CONF_SG_TEMP_PARAM_1]                      = 0,
 
150
                        [CONF_SG_TEMP_PARAM_2]                      = 0,
 
151
                        [CONF_SG_TEMP_PARAM_3]                      = 0,
 
152
                        [CONF_SG_TEMP_PARAM_4]                      = 0,
 
153
                        [CONF_SG_TEMP_PARAM_5]                      = 0,
 
154
                        [CONF_SG_AP_BEACON_MISS_TX]                 = 3,
 
155
                        [CONF_SG_RX_WINDOW_LENGTH]                  = 6,
 
156
                        [CONF_SG_AP_CONNECTION_PROTECTION_TIME]     = 50,
 
157
                        [CONF_SG_TEMP_PARAM_6]                      = 1,
 
158
                },
103
159
                .state = CONF_SG_PROTECTIVE,
104
160
        },
105
161
        .rx = {
107
163
                .packet_detection_threshold  = 0,
108
164
                .ps_poll_timeout             = 15,
109
165
                .upsd_timeout                = 15,
110
 
                .rts_threshold               = 2347,
 
166
                .rts_threshold               = IEEE80211_MAX_RTS_THRESHOLD,
111
167
                .rx_cca_threshold            = 0,
112
168
                .irq_blk_threshold           = 0xFFFF,
113
169
                .irq_pkt_threshold           = 0,
116
172
        },
117
173
        .tx = {
118
174
                .tx_energy_detection         = 0,
119
 
                .rc_conf                     = {
 
175
                .sta_rc_conf                 = {
120
176
                        .enabled_rates       = 0,
121
177
                        .short_retry_limit   = 10,
122
178
                        .long_retry_limit    = 10,
123
 
                        .aflags              = 0
 
179
                        .aflags              = 0,
124
180
                },
125
181
                .ac_conf_count               = 4,
126
182
                .ac_conf                     = {
153
209
                                .tx_op_limit = 1504,
154
210
                        },
155
211
                },
 
212
                .ap_max_tx_retries = 100,
156
213
                .tid_conf_count = 4,
157
214
                .tid_conf = {
158
215
                        [CONF_TX_AC_BE] = {
193
250
                .tx_compl_threshold          = 4,
194
251
                .basic_rate                  = CONF_HW_BIT_RATE_1MBPS,
195
252
                .basic_rate_5                = CONF_HW_BIT_RATE_6MBPS,
 
253
                .tmpl_short_retry_limit      = 10,
 
254
                .tmpl_long_retry_limit       = 10,
196
255
        },
197
256
        .conn = {
198
257
                .wake_up_event               = CONF_WAKE_UP_EVENT_DTIM,
199
258
                .listen_interval             = 1,
200
259
                .bcn_filt_mode               = CONF_BCN_FILT_MODE_ENABLED,
201
 
                .bcn_filt_ie_count           = 1,
 
260
                .bcn_filt_ie_count           = 2,
202
261
                .bcn_filt_ie = {
203
262
                        [0] = {
204
263
                                .ie          = WLAN_EID_CHANNEL_SWITCH,
205
264
                                .rule        = CONF_BCN_RULE_PASS_ON_APPEARANCE,
206
 
                        }
 
265
                        },
 
266
                        [1] = {
 
267
                                .ie          = WLAN_EID_HT_INFORMATION,
 
268
                                .rule        = CONF_BCN_RULE_PASS_ON_CHANGE,
 
269
                        },
207
270
                },
208
271
                .synch_fail_thold            = 10,
209
272
                .bss_lose_timeout            = 100,
213
276
                .ps_poll_threshold           = 10,
214
277
                .ps_poll_recovery_period     = 700,
215
278
                .bet_enable                  = CONF_BET_MODE_ENABLE,
216
 
                .bet_max_consecutive         = 10,
 
279
                .bet_max_consecutive         = 50,
217
280
                .psm_entry_retries           = 5,
 
281
                .psm_exit_retries            = 16,
218
282
                .psm_entry_nullfunc_retries  = 3,
219
283
                .psm_entry_hangover_period   = 1,
220
284
                .keep_alive_interval         = 55000,
233
297
                .avg_weight_rssi_beacon       = 20,
234
298
                .avg_weight_rssi_data         = 10,
235
299
                .avg_weight_snr_beacon        = 20,
236
 
                .avg_weight_snr_data          = 10
 
300
                .avg_weight_snr_data          = 10,
237
301
        },
238
302
        .scan = {
239
303
                .min_dwell_time_active        = 7500,
240
304
                .max_dwell_time_active        = 30000,
241
 
                .min_dwell_time_passive       = 30000,
242
 
                .max_dwell_time_passive       = 60000,
 
305
                .min_dwell_time_passive       = 100000,
 
306
                .max_dwell_time_passive       = 100000,
243
307
                .num_probe_reqs               = 2,
244
308
        },
 
309
        .sched_scan = {
 
310
                /* sched_scan requires dwell times in TU instead of TU/1000 */
 
311
                .min_dwell_time_active = 8,
 
312
                .max_dwell_time_active = 30,
 
313
                .dwell_time_passive    = 100,
 
314
                .dwell_time_dfs        = 150,
 
315
                .num_probe_reqs        = 2,
 
316
                .rssi_threshold        = -90,
 
317
                .snr_threshold         = 0,
 
318
        },
245
319
        .rf = {
246
320
                .tx_per_channel_power_compensation_2 = {
247
321
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252
326
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253
327
                },
254
328
        },
 
329
        .ht = {
 
330
                .tx_ba_win_size = 64,
 
331
                .inactivity_timeout = 10000,
 
332
        },
 
333
        .mem_wl127x = {
 
334
                .num_stations                 = 1,
 
335
                .ssid_profiles                = 1,
 
336
                .rx_block_num                 = 70,
 
337
                .tx_min_block_num             = 40,
 
338
                .dynamic_memory               = 1,
 
339
                .min_req_tx_blocks            = 100,
 
340
                .min_req_rx_blocks            = 22,
 
341
                .tx_min                       = 27,
 
342
        },
 
343
        .mem_wl128x = {
 
344
                .num_stations                 = 1,
 
345
                .ssid_profiles                = 1,
 
346
                .rx_block_num                 = 40,
 
347
                .tx_min_block_num             = 40,
 
348
                .dynamic_memory               = 1,
 
349
                .min_req_tx_blocks            = 45,
 
350
                .min_req_rx_blocks            = 22,
 
351
                .tx_min                       = 27,
 
352
        },
 
353
        .fm_coex = {
 
354
                .enable                       = true,
 
355
                .swallow_period               = 5,
 
356
                .n_divider_fref_set_1         = 0xff,       /* default */
 
357
                .n_divider_fref_set_2         = 12,
 
358
                .m_divider_fref_set_1         = 148,
 
359
                .m_divider_fref_set_2         = 0xffff,     /* default */
 
360
                .coex_pll_stabilization_time  = 0xffffffff, /* default */
 
361
                .ldo_stabilization_time       = 0xffff,     /* default */
 
362
                .fm_disturbed_band_margin     = 0xff,       /* default */
 
363
                .swallow_clk_diff             = 0xff,       /* default */
 
364
        },
 
365
        .hci_io_ds = HCI_IO_DS_6MA,
255
366
};
256
367
 
257
 
static void __wl1271_op_remove_interface(struct wl1271 *wl);
 
368
static void __wl1271_op_remove_interface(struct wl1271 *wl,
 
369
                                         bool reset_tx_queues);
 
370
static void wl1271_free_ap_keys(struct wl1271 *wl);
258
371
 
259
372
 
260
373
static void wl1271_device_release(struct device *dev)
272
385
        },
273
386
};
274
387
 
 
388
static DEFINE_MUTEX(wl_list_mutex);
275
389
static LIST_HEAD(wl_list);
276
390
 
277
391
static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
302
416
                return NOTIFY_DONE;
303
417
 
304
418
        wl_temp = hw->priv;
 
419
        mutex_lock(&wl_list_mutex);
305
420
        list_for_each_entry(wl, &wl_list, list) {
306
421
                if (wl == wl_temp)
307
422
                        break;
308
423
        }
 
424
        mutex_unlock(&wl_list_mutex);
309
425
        if (wl != wl_temp)
310
426
                return NOTIFY_DONE;
311
427
 
317
433
        if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
318
434
                goto out;
319
435
 
320
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
436
        ret = wl1271_ps_elp_wakeup(wl);
321
437
        if (ret < 0)
322
438
                goto out;
323
439
 
381
497
        struct conf_tx_tid *conf_tid;
382
498
        int ret, i;
383
499
 
384
 
        ret = wl1271_cmd_general_parms(wl);
385
 
        if (ret < 0)
386
 
                return ret;
387
 
 
388
 
        ret = wl1271_cmd_radio_parms(wl);
389
 
        if (ret < 0)
390
 
                return ret;
391
 
 
392
 
        ret = wl1271_cmd_ext_radio_parms(wl);
393
 
        if (ret < 0)
394
 
                return ret;
395
 
 
396
 
        ret = wl1271_init_templates_config(wl);
 
500
        if (wl->chip.id == CHIP_ID_1283_PG20)
 
501
                ret = wl128x_cmd_general_parms(wl);
 
502
        else
 
503
                ret = wl1271_cmd_general_parms(wl);
 
504
        if (ret < 0)
 
505
                return ret;
 
506
 
 
507
        if (wl->chip.id == CHIP_ID_1283_PG20)
 
508
                ret = wl128x_cmd_radio_parms(wl);
 
509
        else
 
510
                ret = wl1271_cmd_radio_parms(wl);
 
511
        if (ret < 0)
 
512
                return ret;
 
513
 
 
514
        if (wl->chip.id != CHIP_ID_1283_PG20) {
 
515
                ret = wl1271_cmd_ext_radio_parms(wl);
 
516
                if (ret < 0)
 
517
                        return ret;
 
518
        }
 
519
        if (ret < 0)
 
520
                return ret;
 
521
 
 
522
        /* Chip-specific initializations */
 
523
        ret = wl1271_chip_specific_init(wl);
 
524
        if (ret < 0)
 
525
                return ret;
 
526
 
 
527
        ret = wl1271_sta_init_templates_config(wl);
397
528
        if (ret < 0)
398
529
                return ret;
399
530
 
420
551
        if (ret < 0)
421
552
                goto out_free_memmap;
422
553
 
 
554
        /* FM WLAN coexistence */
 
555
        ret = wl1271_acx_fm_coex(wl);
 
556
        if (ret < 0)
 
557
                goto out_free_memmap;
 
558
 
423
559
        /* Energy detection */
424
560
        ret = wl1271_init_energy_detection(wl);
425
561
        if (ret < 0)
426
562
                goto out_free_memmap;
427
563
 
 
564
        ret = wl1271_acx_sta_mem_cfg(wl);
 
565
        if (ret < 0)
 
566
                goto out_free_memmap;
 
567
 
428
568
        /* Default fragmentation threshold */
429
569
        ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
430
570
        if (ret < 0)
476
616
        return ret;
477
617
}
478
618
 
 
619
static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks)
 
620
{
 
621
        bool fw_ps;
 
622
 
 
623
        /* only regulate station links */
 
624
        if (hlid < WL1271_AP_STA_HLID_START)
 
625
                return;
 
626
 
 
627
        fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
 
628
 
 
629
        /*
 
630
         * Wake up from high level PS if the STA is asleep with too little
 
631
         * blocks in FW or if the STA is awake.
 
632
         */
 
633
        if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS)
 
634
                wl1271_ps_link_end(wl, hlid);
 
635
 
 
636
        /* Start high-level PS if the STA is asleep with enough blocks in FW */
 
637
        else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
 
638
                wl1271_ps_link_start(wl, hlid, true);
 
639
}
 
640
 
 
641
static void wl1271_irq_update_links_status(struct wl1271 *wl,
 
642
                                       struct wl1271_fw_ap_status *status)
 
643
{
 
644
        u32 cur_fw_ps_map;
 
645
        u8 hlid;
 
646
 
 
647
        cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
 
648
        if (wl->ap_fw_ps_map != cur_fw_ps_map) {
 
649
                wl1271_debug(DEBUG_PSM,
 
650
                             "link ps prev 0x%x cur 0x%x changed 0x%x",
 
651
                             wl->ap_fw_ps_map, cur_fw_ps_map,
 
652
                             wl->ap_fw_ps_map ^ cur_fw_ps_map);
 
653
 
 
654
                wl->ap_fw_ps_map = cur_fw_ps_map;
 
655
        }
 
656
 
 
657
        for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) {
 
658
                u8 cnt = status->tx_lnk_free_blks[hlid] -
 
659
                        wl->links[hlid].prev_freed_blks;
 
660
 
 
661
                wl->links[hlid].prev_freed_blks =
 
662
                        status->tx_lnk_free_blks[hlid];
 
663
                wl->links[hlid].allocated_blks -= cnt;
 
664
 
 
665
                wl1271_irq_ps_regulate_link(wl, hlid,
 
666
                                            wl->links[hlid].allocated_blks);
 
667
        }
 
668
}
 
669
 
479
670
static void wl1271_fw_status(struct wl1271 *wl,
480
 
                             struct wl1271_fw_status *status)
 
671
                             struct wl1271_fw_full_status *full_status)
481
672
{
 
673
        struct wl1271_fw_common_status *status = &full_status->common;
482
674
        struct timespec ts;
483
 
        u32 total = 0;
 
675
        u32 old_tx_blk_count = wl->tx_blocks_available;
 
676
        u32 freed_blocks = 0;
484
677
        int i;
485
678
 
486
 
        wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
 
679
        if (wl->bss_type == BSS_TYPE_AP_BSS) {
 
680
                wl1271_raw_read(wl, FW_STATUS_ADDR, status,
 
681
                                sizeof(struct wl1271_fw_ap_status), false);
 
682
        } else {
 
683
                wl1271_raw_read(wl, FW_STATUS_ADDR, status,
 
684
                                sizeof(struct wl1271_fw_sta_status), false);
 
685
        }
487
686
 
488
687
        wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
489
688
                     "drv_rx_counter = %d, tx_results_counter = %d)",
494
693
 
495
694
        /* update number of available TX blocks */
496
695
        for (i = 0; i < NUM_TX_QUEUES; i++) {
497
 
                u32 cnt = le32_to_cpu(status->tx_released_blks[i]) -
498
 
                        wl->tx_blocks_freed[i];
 
696
                freed_blocks += le32_to_cpu(status->tx_released_blks[i]) -
 
697
                                wl->tx_blocks_freed[i];
499
698
 
500
699
                wl->tx_blocks_freed[i] =
501
700
                        le32_to_cpu(status->tx_released_blks[i]);
502
 
                wl->tx_blocks_available += cnt;
503
 
                total += cnt;
 
701
        }
 
702
 
 
703
        wl->tx_allocated_blocks -= freed_blocks;
 
704
 
 
705
        if (wl->bss_type == BSS_TYPE_AP_BSS) {
 
706
                /* Update num of allocated TX blocks per link and ps status */
 
707
                wl1271_irq_update_links_status(wl, &full_status->ap);
 
708
                wl->tx_blocks_available += freed_blocks;
 
709
        } else {
 
710
                int avail = full_status->sta.tx_total - wl->tx_allocated_blocks;
 
711
 
 
712
                /*
 
713
                 * The FW might change the total number of TX memblocks before
 
714
                 * we get a notification about blocks being released. Thus, the
 
715
                 * available blocks calculation might yield a temporary result
 
716
                 * which is lower than the actual available blocks. Keeping in
 
717
                 * mind that only blocks that were allocated can be moved from
 
718
                 * TX to RX, tx_blocks_available should never decrease here.
 
719
                 */
 
720
                wl->tx_blocks_available = max((int)wl->tx_blocks_available,
 
721
                                              avail);
504
722
        }
505
723
 
506
724
        /* if more blocks are available now, tx work can be scheduled */
507
 
        if (total)
 
725
        if (wl->tx_blocks_available > old_tx_blk_count)
508
726
                clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
509
727
 
510
728
        /* update the host-chipset time offset */
513
731
                (s64)le32_to_cpu(status->fw_localtime);
514
732
}
515
733
 
516
 
#define WL1271_IRQ_MAX_LOOPS 10
517
 
 
518
 
static void wl1271_irq_work(struct work_struct *work)
 
734
static void wl1271_flush_deferred_work(struct wl1271 *wl)
 
735
{
 
736
        struct sk_buff *skb;
 
737
 
 
738
        /* Pass all received frames to the network stack */
 
739
        while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
 
740
                ieee80211_rx_ni(wl->hw, skb);
 
741
 
 
742
        /* Return sent skbs to the network stack */
 
743
        while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
 
744
                ieee80211_tx_status(wl->hw, skb);
 
745
}
 
746
 
 
747
static void wl1271_netstack_work(struct work_struct *work)
 
748
{
 
749
        struct wl1271 *wl =
 
750
                container_of(work, struct wl1271, netstack_work);
 
751
 
 
752
        do {
 
753
                wl1271_flush_deferred_work(wl);
 
754
        } while (skb_queue_len(&wl->deferred_rx_queue));
 
755
}
 
756
 
 
757
#define WL1271_IRQ_MAX_LOOPS 256
 
758
 
 
759
irqreturn_t wl1271_irq(int irq, void *cookie)
519
760
{
520
761
        int ret;
521
762
        u32 intr;
522
763
        int loopcount = WL1271_IRQ_MAX_LOOPS;
 
764
        struct wl1271 *wl = (struct wl1271 *)cookie;
 
765
        bool done = false;
 
766
        unsigned int defer_count;
523
767
        unsigned long flags;
524
 
        struct wl1271 *wl =
525
 
                container_of(work, struct wl1271, irq_work);
 
768
 
 
769
        /* TX might be handled here, avoid redundant work */
 
770
        set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
 
771
        cancel_work_sync(&wl->tx_work);
 
772
 
 
773
        /*
 
774
         * In case edge triggered interrupt must be used, we cannot iterate
 
775
         * more than once without introducing race conditions with the hardirq.
 
776
         */
 
777
        if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
 
778
                loopcount = 1;
526
779
 
527
780
        mutex_lock(&wl->mutex);
528
781
 
531
784
        if (unlikely(wl->state == WL1271_STATE_OFF))
532
785
                goto out;
533
786
 
534
 
        ret = wl1271_ps_elp_wakeup(wl, true);
 
787
        ret = wl1271_ps_elp_wakeup(wl);
535
788
        if (ret < 0)
536
789
                goto out;
537
790
 
538
 
        spin_lock_irqsave(&wl->wl_lock, flags);
539
 
        while (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags) && loopcount) {
540
 
                clear_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags);
541
 
                spin_unlock_irqrestore(&wl->wl_lock, flags);
542
 
                loopcount--;
 
791
        while (!done && loopcount--) {
 
792
                /*
 
793
                 * In order to avoid a race with the hardirq, clear the flag
 
794
                 * before acknowledging the chip. Since the mutex is held,
 
795
                 * wl1271_ps_elp_wakeup cannot be called concurrently.
 
796
                 */
 
797
                clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
 
798
                smp_mb__after_clear_bit();
543
799
 
544
800
                wl1271_fw_status(wl, wl->fw_status);
545
 
                intr = le32_to_cpu(wl->fw_status->intr);
 
801
                intr = le32_to_cpu(wl->fw_status->common.intr);
 
802
                intr &= WL1271_INTR_MASK;
546
803
                if (!intr) {
547
 
                        wl1271_debug(DEBUG_IRQ, "Zero interrupt received.");
548
 
                        spin_lock_irqsave(&wl->wl_lock, flags);
 
804
                        done = true;
549
805
                        continue;
550
806
                }
551
807
 
552
 
                intr &= WL1271_INTR_MASK;
553
 
 
554
808
                if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
555
809
                        wl1271_error("watchdog interrupt received! "
556
810
                                     "starting recovery.");
560
814
                        goto out;
561
815
                }
562
816
 
563
 
                if (intr & WL1271_ACX_INTR_DATA) {
 
817
                if (likely(intr & WL1271_ACX_INTR_DATA)) {
564
818
                        wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
565
819
 
566
 
                        /* check for tx results */
567
 
                        if (wl->fw_status->tx_results_counter !=
568
 
                            (wl->tx_results_count & 0xff))
569
 
                                wl1271_tx_complete(wl);
 
820
                        wl1271_rx(wl, &wl->fw_status->common);
570
821
 
571
822
                        /* Check if any tx blocks were freed */
 
823
                        spin_lock_irqsave(&wl->wl_lock, flags);
572
824
                        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
573
825
                            wl->tx_queue_count) {
 
826
                                spin_unlock_irqrestore(&wl->wl_lock, flags);
574
827
                                /*
575
828
                                 * In order to avoid starvation of the TX path,
576
829
                                 * call the work function directly.
577
830
                                 */
578
831
                                wl1271_tx_work_locked(wl);
 
832
                        } else {
 
833
                                spin_unlock_irqrestore(&wl->wl_lock, flags);
579
834
                        }
580
835
 
581
 
                        wl1271_rx(wl, wl->fw_status);
 
836
                        /* check for tx results */
 
837
                        if (wl->fw_status->common.tx_results_counter !=
 
838
                            (wl->tx_results_count & 0xff))
 
839
                                wl1271_tx_complete(wl);
 
840
 
 
841
                        /* Make sure the deferred queues don't get too long */
 
842
                        defer_count = skb_queue_len(&wl->deferred_tx_queue) +
 
843
                                      skb_queue_len(&wl->deferred_rx_queue);
 
844
                        if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
 
845
                                wl1271_flush_deferred_work(wl);
582
846
                }
583
847
 
584
848
                if (intr & WL1271_ACX_INTR_EVENT_A) {
597
861
 
598
862
                if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
599
863
                        wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
600
 
 
601
 
                spin_lock_irqsave(&wl->wl_lock, flags);
602
864
        }
603
865
 
604
 
        if (test_bit(WL1271_FLAG_IRQ_PENDING, &wl->flags))
605
 
                ieee80211_queue_work(wl->hw, &wl->irq_work);
606
 
        else
607
 
                clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
608
 
        spin_unlock_irqrestore(&wl->wl_lock, flags);
609
 
 
610
866
        wl1271_ps_elp_sleep(wl);
611
867
 
612
868
out:
 
869
        spin_lock_irqsave(&wl->wl_lock, flags);
 
870
        /* In case TX was not handled here, queue TX work */
 
871
        clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
 
872
        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
 
873
            wl->tx_queue_count)
 
874
                ieee80211_queue_work(wl->hw, &wl->tx_work);
 
875
        spin_unlock_irqrestore(&wl->wl_lock, flags);
 
876
 
613
877
        mutex_unlock(&wl->mutex);
 
878
 
 
879
        return IRQ_HANDLED;
614
880
}
 
881
EXPORT_SYMBOL_GPL(wl1271_irq);
615
882
 
616
883
static int wl1271_fetch_firmware(struct wl1271 *wl)
617
884
{
618
885
        const struct firmware *fw;
 
886
        const char *fw_name;
619
887
        int ret;
620
888
 
621
 
        ret = request_firmware(&fw, WL1271_FW_NAME, wl1271_wl_to_dev(wl));
 
889
        switch (wl->bss_type) {
 
890
        case BSS_TYPE_AP_BSS:
 
891
                if (wl->chip.id == CHIP_ID_1283_PG20)
 
892
                        fw_name = WL128X_AP_FW_NAME;
 
893
                else
 
894
                        fw_name = WL127X_AP_FW_NAME;
 
895
                break;
 
896
        case BSS_TYPE_IBSS:
 
897
        case BSS_TYPE_STA_BSS:
 
898
                if (wl->chip.id == CHIP_ID_1283_PG20)
 
899
                        fw_name = WL128X_FW_NAME;
 
900
                else
 
901
                        fw_name = WL1271_FW_NAME;
 
902
                break;
 
903
        default:
 
904
                wl1271_error("no compatible firmware for bss_type %d",
 
905
                             wl->bss_type);
 
906
                return -EINVAL;
 
907
        }
 
908
 
 
909
        wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
 
910
 
 
911
        ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl));
622
912
 
623
913
        if (ret < 0) {
624
914
                wl1271_error("could not get firmware: %d", ret);
632
922
                goto out;
633
923
        }
634
924
 
 
925
        vfree(wl->fw);
635
926
        wl->fw_len = fw->size;
636
927
        wl->fw = vmalloc(wl->fw_len);
637
928
 
642
933
        }
643
934
 
644
935
        memcpy(wl->fw, fw->data, wl->fw_len);
645
 
 
 
936
        wl->fw_bss_type = wl->bss_type;
646
937
        ret = 0;
647
938
 
648
939
out:
656
947
        const struct firmware *fw;
657
948
        int ret;
658
949
 
659
 
        ret = request_firmware(&fw, WL1271_NVS_NAME, wl1271_wl_to_dev(wl));
 
950
        ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
660
951
 
661
952
        if (ret < 0) {
662
953
                wl1271_error("could not get nvs file: %d", ret);
663
954
                return ret;
664
955
        }
665
956
 
666
 
        wl->nvs = kmemdup(fw->data, sizeof(struct wl1271_nvs_file), GFP_KERNEL);
 
957
        wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
667
958
 
668
959
        if (!wl->nvs) {
669
960
                wl1271_error("could not allocate memory for the nvs file");
689
980
        if (wl->state != WL1271_STATE_ON)
690
981
                goto out;
691
982
 
692
 
        wl1271_info("Hardware recovery in progress.");
 
983
        wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
 
984
                    wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
693
985
 
694
986
        if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
695
987
                ieee80211_connection_loss(wl->vif);
696
988
 
 
989
        /* Prevent spurious TX during FW restart */
 
990
        ieee80211_stop_queues(wl->hw);
 
991
 
 
992
        if (wl->sched_scanning) {
 
993
                ieee80211_sched_scan_stopped(wl->hw);
 
994
                wl->sched_scanning = false;
 
995
        }
 
996
 
697
997
        /* reboot the chipset */
698
 
        __wl1271_op_remove_interface(wl);
 
998
        __wl1271_op_remove_interface(wl, false);
699
999
        ieee80211_restart_hw(wl->hw);
700
1000
 
 
1001
        /*
 
1002
         * Its safe to enable TX now - the queues are stopped after a request
 
1003
         * to restart the HW.
 
1004
         */
 
1005
        ieee80211_wake_queues(wl->hw);
 
1006
 
701
1007
out:
702
1008
        mutex_unlock(&wl->mutex);
703
1009
}
768
1074
                wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
769
1075
                             wl->chip.id);
770
1076
 
771
 
                ret = wl1271_setup(wl);
772
 
                if (ret < 0)
773
 
                        goto out;
774
 
                break;
 
1077
                /* end-of-transaction flag should be set in wl127x AP mode */
 
1078
                if (wl->bss_type == BSS_TYPE_AP_BSS)
 
1079
                        wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
 
1080
 
 
1081
                ret = wl1271_setup(wl);
 
1082
                if (ret < 0)
 
1083
                        goto out;
 
1084
                break;
 
1085
        case CHIP_ID_1283_PG20:
 
1086
                wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
 
1087
                             wl->chip.id);
 
1088
 
 
1089
                ret = wl1271_setup(wl);
 
1090
                if (ret < 0)
 
1091
                        goto out;
 
1092
                if (wl1271_set_block_size(wl))
 
1093
                        wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
 
1094
                break;
 
1095
        case CHIP_ID_1283_PG10:
775
1096
        default:
776
1097
                wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
777
1098
                ret = -ENODEV;
778
1099
                goto out;
779
1100
        }
780
1101
 
781
 
        if (wl->fw == NULL) {
 
1102
        /* Make sure the firmware type matches the BSS type */
 
1103
        if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) {
782
1104
                ret = wl1271_fetch_firmware(wl);
783
1105
                if (ret < 0)
784
1106
                        goto out;
795
1117
        return ret;
796
1118
}
797
1119
 
 
1120
static unsigned int wl1271_get_fw_ver_quirks(struct wl1271 *wl)
 
1121
{
 
1122
        unsigned int quirks = 0;
 
1123
        unsigned int *fw_ver = wl->chip.fw_ver;
 
1124
 
 
1125
        /* Only for wl127x */
 
1126
        if ((fw_ver[FW_VER_CHIP] == FW_VER_CHIP_WL127X) &&
 
1127
            /* Check STA version */
 
1128
            (((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
 
1129
              (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_STA_MIN)) ||
 
1130
             /* Check AP version */
 
1131
             ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP) &&
 
1132
              (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_1_SPARE_AP_MIN))))
 
1133
                quirks |= WL12XX_QUIRK_USE_2_SPARE_BLOCKS;
 
1134
 
 
1135
        return quirks;
 
1136
}
 
1137
 
798
1138
int wl1271_plt_start(struct wl1271 *wl)
799
1139
{
800
1140
        int retries = WL1271_BOOT_RETRIES;
811
1151
                goto out;
812
1152
        }
813
1153
 
 
1154
        wl->bss_type = BSS_TYPE_STA_BSS;
 
1155
 
814
1156
        while (retries) {
815
1157
                retries--;
816
1158
                ret = wl1271_chip_wakeup(wl);
827
1169
 
828
1170
                wl->state = WL1271_STATE_PLT;
829
1171
                wl1271_notice("firmware booted in PLT mode (%s)",
830
 
                              wl->chip.fw_ver);
 
1172
                              wl->chip.fw_ver_str);
 
1173
 
 
1174
                /* Check if any quirks are needed with older fw versions */
 
1175
                wl->quirks |= wl1271_get_fw_ver_quirks(wl);
831
1176
                goto out;
832
1177
 
833
1178
irq_disable:
834
 
                wl1271_disable_interrupts(wl);
835
1179
                mutex_unlock(&wl->mutex);
836
1180
                /* Unlocking the mutex in the middle of handling is
837
1181
                   inherently unsafe. In this case we deem it safe to do,
840
1184
                   work function will not do anything.) Also, any other
841
1185
                   possible concurrent operations will fail due to the
842
1186
                   current state, hence the wl1271 struct should be safe. */
843
 
                cancel_work_sync(&wl->irq_work);
 
1187
                wl1271_disable_interrupts(wl);
 
1188
                wl1271_flush_deferred_work(wl);
 
1189
                cancel_work_sync(&wl->netstack_work);
844
1190
                mutex_lock(&wl->mutex);
845
1191
power_off:
846
1192
                wl1271_power_off(wl);
854
1200
        return ret;
855
1201
}
856
1202
 
857
 
int wl1271_plt_stop(struct wl1271 *wl)
 
1203
static int __wl1271_plt_stop(struct wl1271 *wl)
858
1204
{
859
1205
        int ret = 0;
860
1206
 
861
 
        mutex_lock(&wl->mutex);
862
 
 
863
1207
        wl1271_notice("power down");
864
1208
 
865
1209
        if (wl->state != WL1271_STATE_PLT) {
869
1213
                goto out;
870
1214
        }
871
1215
 
872
 
        wl1271_disable_interrupts(wl);
873
1216
        wl1271_power_off(wl);
874
1217
 
875
1218
        wl->state = WL1271_STATE_OFF;
876
1219
        wl->rx_counter = 0;
877
1220
 
 
1221
        mutex_unlock(&wl->mutex);
 
1222
        wl1271_disable_interrupts(wl);
 
1223
        wl1271_flush_deferred_work(wl);
 
1224
        cancel_work_sync(&wl->netstack_work);
 
1225
        cancel_work_sync(&wl->recovery_work);
 
1226
        mutex_lock(&wl->mutex);
878
1227
out:
 
1228
        return ret;
 
1229
}
 
1230
 
 
1231
int wl1271_plt_stop(struct wl1271 *wl)
 
1232
{
 
1233
        int ret;
 
1234
 
 
1235
        mutex_lock(&wl->mutex);
 
1236
        ret = __wl1271_plt_stop(wl);
879
1237
        mutex_unlock(&wl->mutex);
880
 
 
881
 
        cancel_work_sync(&wl->irq_work);
882
 
        cancel_work_sync(&wl->recovery_work);
883
 
 
884
1238
        return ret;
885
1239
}
886
1240
 
887
 
static int wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 
1241
static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
888
1242
{
889
1243
        struct wl1271 *wl = hw->priv;
890
 
        struct ieee80211_conf *conf = &hw->conf;
891
 
        struct ieee80211_tx_info *txinfo = IEEE80211_SKB_CB(skb);
892
 
        struct ieee80211_sta *sta = txinfo->control.sta;
893
1244
        unsigned long flags;
894
1245
        int q;
895
 
 
896
 
        /*
897
 
         * peek into the rates configured in the STA entry.
898
 
         * The rates set after connection stage, The first block only BG sets:
899
 
         * the compare is for bit 0-16 of sta_rate_set. The second block add
900
 
         * HT rates in case of HT supported.
901
 
         */
902
 
        spin_lock_irqsave(&wl->wl_lock, flags);
903
 
        if (sta &&
904
 
            (sta->supp_rates[conf->channel->band] !=
905
 
            (wl->sta_rate_set & HW_BG_RATES_MASK))) {
906
 
                wl->sta_rate_set = sta->supp_rates[conf->channel->band];
907
 
                set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
908
 
        }
909
 
 
910
 
#ifdef CONFIG_WL12XX_HT
911
 
        if (sta &&
912
 
            sta->ht_cap.ht_supported &&
913
 
            ((wl->sta_rate_set >> HW_HT_RATES_OFFSET) !=
914
 
              sta->ht_cap.mcs.rx_mask[0])) {
915
 
                /* Clean MCS bits before setting them */
916
 
                wl->sta_rate_set &= HW_BG_RATES_MASK;
917
 
                wl->sta_rate_set |=
918
 
                        (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
919
 
                set_bit(WL1271_FLAG_STA_RATES_CHANGED, &wl->flags);
920
 
        }
921
 
#endif
922
 
        wl->tx_queue_count++;
923
 
        spin_unlock_irqrestore(&wl->wl_lock, flags);
924
 
 
925
 
        /* queue the packet */
 
1246
        u8 hlid = 0;
 
1247
 
926
1248
        q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
927
 
        skb_queue_tail(&wl->tx_queue[q], skb);
928
 
 
929
 
        /*
930
 
         * The chip specific setup must run before the first TX packet -
931
 
         * before that, the tx_work will not be initialized!
932
 
         */
933
 
 
934
 
        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
935
 
                ieee80211_queue_work(wl->hw, &wl->tx_work);
 
1249
 
 
1250
        if (wl->bss_type == BSS_TYPE_AP_BSS)
 
1251
                hlid = wl1271_tx_get_hlid(skb);
 
1252
 
 
1253
        spin_lock_irqsave(&wl->wl_lock, flags);
 
1254
 
 
1255
        wl->tx_queue_count++;
936
1256
 
937
1257
        /*
938
1258
         * The workqueue is slow to process the tx_queue and we need stop
940
1260
         */
941
1261
        if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
942
1262
                wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
943
 
 
944
 
                spin_lock_irqsave(&wl->wl_lock, flags);
945
1263
                ieee80211_stop_queues(wl->hw);
946
1264
                set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
947
 
                spin_unlock_irqrestore(&wl->wl_lock, flags);
948
 
        }
949
 
 
950
 
        return NETDEV_TX_OK;
951
 
}
 
1265
        }
 
1266
 
 
1267
        /* queue the packet */
 
1268
        if (wl->bss_type == BSS_TYPE_AP_BSS) {
 
1269
                wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
 
1270
                skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
 
1271
        } else {
 
1272
                skb_queue_tail(&wl->tx_queue[q], skb);
 
1273
        }
 
1274
 
 
1275
        /*
 
1276
         * The chip specific setup must run before the first TX packet -
 
1277
         * before that, the tx_work will not be initialized!
 
1278
         */
 
1279
 
 
1280
        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
 
1281
            !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
 
1282
                ieee80211_queue_work(wl->hw, &wl->tx_work);
 
1283
 
 
1284
        spin_unlock_irqrestore(&wl->wl_lock, flags);
 
1285
}
 
1286
 
 
1287
int wl1271_tx_dummy_packet(struct wl1271 *wl)
 
1288
{
 
1289
        unsigned long flags;
 
1290
 
 
1291
        spin_lock_irqsave(&wl->wl_lock, flags);
 
1292
        set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
 
1293
        wl->tx_queue_count++;
 
1294
        spin_unlock_irqrestore(&wl->wl_lock, flags);
 
1295
 
 
1296
        /* The FW is low on RX memory blocks, so send the dummy packet asap */
 
1297
        if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
 
1298
                wl1271_tx_work_locked(wl);
 
1299
 
 
1300
        /*
 
1301
         * If the FW TX is busy, TX work will be scheduled by the threaded
 
1302
         * interrupt handler function
 
1303
         */
 
1304
        return 0;
 
1305
}
 
1306
 
 
1307
/*
 
1308
 * The size of the dummy packet should be at least 1400 bytes. However, in
 
1309
 * order to minimize the number of bus transactions, aligning it to 512 bytes
 
1310
 * boundaries could be beneficial, performance wise
 
1311
 */
 
1312
#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
 
1313
 
 
1314
static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
 
1315
{
 
1316
        struct sk_buff *skb;
 
1317
        struct ieee80211_hdr_3addr *hdr;
 
1318
        unsigned int dummy_packet_size;
 
1319
 
 
1320
        dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
 
1321
                            sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
 
1322
 
 
1323
        skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
 
1324
        if (!skb) {
 
1325
                wl1271_warning("Failed to allocate a dummy packet skb");
 
1326
                return NULL;
 
1327
        }
 
1328
 
 
1329
        skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
 
1330
 
 
1331
        hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
 
1332
        memset(hdr, 0, sizeof(*hdr));
 
1333
        hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
 
1334
                                         IEEE80211_STYPE_NULLFUNC |
 
1335
                                         IEEE80211_FCTL_TODS);
 
1336
 
 
1337
        memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
 
1338
 
 
1339
        /* Dummy packets require the TID to be management */
 
1340
        skb->priority = WL1271_TID_MGMT;
 
1341
 
 
1342
        /* Initialize all fields that might be used */
 
1343
        skb_set_queue_mapping(skb, 0);
 
1344
        memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
 
1345
 
 
1346
        return skb;
 
1347
}
 
1348
 
952
1349
 
953
1350
static struct notifier_block wl1271_dev_notifier = {
954
1351
        .notifier_call = wl1271_dev_notify,
955
1352
};
956
1353
 
 
1354
#ifdef CONFIG_PM
 
1355
static int wl1271_configure_suspend(struct wl1271 *wl)
 
1356
{
 
1357
        int ret;
 
1358
 
 
1359
        if (wl->bss_type != BSS_TYPE_STA_BSS)
 
1360
                return 0;
 
1361
 
 
1362
        mutex_lock(&wl->mutex);
 
1363
 
 
1364
        ret = wl1271_ps_elp_wakeup(wl);
 
1365
        if (ret < 0)
 
1366
                goto out_unlock;
 
1367
 
 
1368
        /* enter psm if needed*/
 
1369
        if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
 
1370
                DECLARE_COMPLETION_ONSTACK(compl);
 
1371
 
 
1372
                wl->ps_compl = &compl;
 
1373
                ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
 
1374
                                   wl->basic_rate, true);
 
1375
                if (ret < 0)
 
1376
                        goto out_sleep;
 
1377
 
 
1378
                /* we must unlock here so we will be able to get events */
 
1379
                wl1271_ps_elp_sleep(wl);
 
1380
                mutex_unlock(&wl->mutex);
 
1381
 
 
1382
                ret = wait_for_completion_timeout(
 
1383
                        &compl, msecs_to_jiffies(WL1271_PS_COMPLETE_TIMEOUT));
 
1384
                if (ret <= 0) {
 
1385
                        wl1271_warning("couldn't enter ps mode!");
 
1386
                        ret = -EBUSY;
 
1387
                        goto out;
 
1388
                }
 
1389
 
 
1390
                /* take mutex again, and wakeup */
 
1391
                mutex_lock(&wl->mutex);
 
1392
 
 
1393
                ret = wl1271_ps_elp_wakeup(wl);
 
1394
                if (ret < 0)
 
1395
                        goto out_unlock;
 
1396
        }
 
1397
out_sleep:
 
1398
        wl1271_ps_elp_sleep(wl);
 
1399
out_unlock:
 
1400
        mutex_unlock(&wl->mutex);
 
1401
out:
 
1402
        return ret;
 
1403
 
 
1404
}
 
1405
 
 
1406
static void wl1271_configure_resume(struct wl1271 *wl)
 
1407
{
 
1408
        int ret;
 
1409
 
 
1410
        if (wl->bss_type != BSS_TYPE_STA_BSS)
 
1411
                return;
 
1412
 
 
1413
        mutex_lock(&wl->mutex);
 
1414
        ret = wl1271_ps_elp_wakeup(wl);
 
1415
        if (ret < 0)
 
1416
                goto out;
 
1417
 
 
1418
        /* exit psm if it wasn't configured */
 
1419
        if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
 
1420
                wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
 
1421
                                   wl->basic_rate, true);
 
1422
 
 
1423
        wl1271_ps_elp_sleep(wl);
 
1424
out:
 
1425
        mutex_unlock(&wl->mutex);
 
1426
}
 
1427
 
 
1428
static int wl1271_op_suspend(struct ieee80211_hw *hw,
 
1429
                            struct cfg80211_wowlan *wow)
 
1430
{
 
1431
        struct wl1271 *wl = hw->priv;
 
1432
        wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
 
1433
        wl->wow_enabled = !!wow;
 
1434
        if (wl->wow_enabled) {
 
1435
                int ret;
 
1436
                ret = wl1271_configure_suspend(wl);
 
1437
                if (ret < 0) {
 
1438
                        wl1271_warning("couldn't prepare device to suspend");
 
1439
                        return ret;
 
1440
                }
 
1441
                /* flush any remaining work */
 
1442
                wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
 
1443
                flush_delayed_work(&wl->scan_complete_work);
 
1444
 
 
1445
                /*
 
1446
                 * disable and re-enable interrupts in order to flush
 
1447
                 * the threaded_irq
 
1448
                 */
 
1449
                wl1271_disable_interrupts(wl);
 
1450
 
 
1451
                /*
 
1452
                 * set suspended flag to avoid triggering a new threaded_irq
 
1453
                 * work. no need for spinlock as interrupts are disabled.
 
1454
                 */
 
1455
                set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
 
1456
 
 
1457
                wl1271_enable_interrupts(wl);
 
1458
                flush_work(&wl->tx_work);
 
1459
                flush_delayed_work(&wl->pspoll_work);
 
1460
                flush_delayed_work(&wl->elp_work);
 
1461
        }
 
1462
        return 0;
 
1463
}
 
1464
 
 
1465
static int wl1271_op_resume(struct ieee80211_hw *hw)
 
1466
{
 
1467
        struct wl1271 *wl = hw->priv;
 
1468
        wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
 
1469
                     wl->wow_enabled);
 
1470
 
 
1471
        /*
 
1472
         * re-enable irq_work enqueuing, and call irq_work directly if
 
1473
         * there is a pending work.
 
1474
         */
 
1475
        if (wl->wow_enabled) {
 
1476
                struct wl1271 *wl = hw->priv;
 
1477
                unsigned long flags;
 
1478
                bool run_irq_work = false;
 
1479
 
 
1480
                spin_lock_irqsave(&wl->wl_lock, flags);
 
1481
                clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
 
1482
                if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
 
1483
                        run_irq_work = true;
 
1484
                spin_unlock_irqrestore(&wl->wl_lock, flags);
 
1485
 
 
1486
                if (run_irq_work) {
 
1487
                        wl1271_debug(DEBUG_MAC80211,
 
1488
                                     "run postponed irq_work directly");
 
1489
                        wl1271_irq(0, wl);
 
1490
                        wl1271_enable_interrupts(wl);
 
1491
                }
 
1492
 
 
1493
                wl1271_configure_resume(wl);
 
1494
        }
 
1495
 
 
1496
        return 0;
 
1497
}
 
1498
#endif
 
1499
 
957
1500
static int wl1271_op_start(struct ieee80211_hw *hw)
958
1501
{
959
1502
        wl1271_debug(DEBUG_MAC80211, "mac80211 start");
967
1510
         *
968
1511
         * The MAC address is first known when the corresponding interface
969
1512
         * is added. That is where we will initialize the hardware.
 
1513
         *
 
1514
         * In addition, we currently have different firmwares for AP and managed
 
1515
         * operation. We will know which to boot according to interface type.
970
1516
         */
971
1517
 
972
1518
        return 0;
997
1543
                goto out;
998
1544
        }
999
1545
 
 
1546
        /*
 
1547
         * in some very corner case HW recovery scenarios its possible to
 
1548
         * get here before __wl1271_op_remove_interface is complete, so
 
1549
         * opt out if that is the case.
 
1550
         */
 
1551
        if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
 
1552
                ret = -EBUSY;
 
1553
                goto out;
 
1554
        }
 
1555
 
1000
1556
        switch (vif->type) {
1001
1557
        case NL80211_IFTYPE_STATION:
1002
1558
                wl->bss_type = BSS_TYPE_STA_BSS;
1006
1562
                wl->bss_type = BSS_TYPE_IBSS;
1007
1563
                wl->set_bss_type = BSS_TYPE_STA_BSS;
1008
1564
                break;
 
1565
        case NL80211_IFTYPE_AP:
 
1566
                wl->bss_type = BSS_TYPE_AP_BSS;
 
1567
                break;
1009
1568
        default:
1010
1569
                ret = -EOPNOTSUPP;
1011
1570
                goto out;
1038
1597
                break;
1039
1598
 
1040
1599
irq_disable:
1041
 
                wl1271_disable_interrupts(wl);
1042
1600
                mutex_unlock(&wl->mutex);
1043
1601
                /* Unlocking the mutex in the middle of handling is
1044
1602
                   inherently unsafe. In this case we deem it safe to do,
1047
1605
                   work function will not do anything.) Also, any other
1048
1606
                   possible concurrent operations will fail due to the
1049
1607
                   current state, hence the wl1271 struct should be safe. */
1050
 
                cancel_work_sync(&wl->irq_work);
 
1608
                wl1271_disable_interrupts(wl);
 
1609
                wl1271_flush_deferred_work(wl);
 
1610
                cancel_work_sync(&wl->netstack_work);
1051
1611
                mutex_lock(&wl->mutex);
1052
1612
power_off:
1053
1613
                wl1271_power_off(wl);
1061
1621
 
1062
1622
        wl->vif = vif;
1063
1623
        wl->state = WL1271_STATE_ON;
1064
 
        wl1271_info("firmware booted (%s)", wl->chip.fw_ver);
 
1624
        set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
 
1625
        wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1065
1626
 
1066
1627
        /* update hw/fw version info in wiphy struct */
1067
1628
        wiphy->hw_version = wl->chip.id;
1068
 
        strncpy(wiphy->fw_version, wl->chip.fw_ver,
 
1629
        strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1069
1630
                sizeof(wiphy->fw_version));
1070
1631
 
 
1632
        /* Check if any quirks are needed with older fw versions */
 
1633
        wl->quirks |= wl1271_get_fw_ver_quirks(wl);
 
1634
 
1071
1635
        /*
1072
1636
         * Now we know if 11a is supported (info from the NVS), so disable
1073
1637
         * 11a channels if not supported
1081
1645
out:
1082
1646
        mutex_unlock(&wl->mutex);
1083
1647
 
 
1648
        mutex_lock(&wl_list_mutex);
1084
1649
        if (!ret)
1085
1650
                list_add(&wl->list, &wl_list);
 
1651
        mutex_unlock(&wl_list_mutex);
1086
1652
 
1087
1653
        return ret;
1088
1654
}
1089
1655
 
1090
 
static void __wl1271_op_remove_interface(struct wl1271 *wl)
 
1656
static void __wl1271_op_remove_interface(struct wl1271 *wl,
 
1657
                                         bool reset_tx_queues)
1091
1658
{
1092
1659
        int i;
1093
1660
 
1094
1661
        wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1095
1662
 
 
1663
        /* because of hardware recovery, we may get here twice */
 
1664
        if (wl->state != WL1271_STATE_ON)
 
1665
                return;
 
1666
 
1096
1667
        wl1271_info("down");
1097
1668
 
 
1669
        mutex_lock(&wl_list_mutex);
1098
1670
        list_del(&wl->list);
1099
 
 
1100
 
        WARN_ON(wl->state != WL1271_STATE_ON);
 
1671
        mutex_unlock(&wl_list_mutex);
1101
1672
 
1102
1673
        /* enable dyn ps just in case (if left on due to fw crash etc) */
1103
1674
        if (wl->bss_type == BSS_TYPE_STA_BSS)
1105
1676
 
1106
1677
        if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
1107
1678
                wl->scan.state = WL1271_SCAN_STATE_IDLE;
1108
 
                kfree(wl->scan.scanned_ch);
1109
 
                wl->scan.scanned_ch = NULL;
 
1679
                memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
1110
1680
                wl->scan.req = NULL;
1111
1681
                ieee80211_scan_completed(wl->hw, true);
1112
1682
        }
1113
1683
 
 
1684
        /*
 
1685
         * this must be before the cancel_work calls below, so that the work
 
1686
         * functions don't perform further work.
 
1687
         */
1114
1688
        wl->state = WL1271_STATE_OFF;
1115
1689
 
 
1690
        mutex_unlock(&wl->mutex);
 
1691
 
1116
1692
        wl1271_disable_interrupts(wl);
1117
 
 
1118
 
        mutex_unlock(&wl->mutex);
1119
 
 
 
1693
        wl1271_flush_deferred_work(wl);
1120
1694
        cancel_delayed_work_sync(&wl->scan_complete_work);
1121
 
        cancel_work_sync(&wl->irq_work);
 
1695
        cancel_work_sync(&wl->netstack_work);
1122
1696
        cancel_work_sync(&wl->tx_work);
1123
1697
        cancel_delayed_work_sync(&wl->pspoll_work);
1124
1698
        cancel_delayed_work_sync(&wl->elp_work);
1126
1700
        mutex_lock(&wl->mutex);
1127
1701
 
1128
1702
        /* let's notify MAC80211 about the remaining pending TX frames */
1129
 
        wl1271_tx_reset(wl);
 
1703
        wl1271_tx_reset(wl, reset_tx_queues);
1130
1704
        wl1271_power_off(wl);
1131
1705
 
1132
1706
        memset(wl->bssid, 0, ETH_ALEN);
1140
1714
        wl->psm_entry_retry = 0;
1141
1715
        wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1142
1716
        wl->tx_blocks_available = 0;
 
1717
        wl->tx_allocated_blocks = 0;
1143
1718
        wl->tx_results_count = 0;
1144
1719
        wl->tx_packets_count = 0;
1145
1720
        wl->tx_security_last_seq = 0;
1147
1722
        wl->time_offset = 0;
1148
1723
        wl->session_counter = 0;
1149
1724
        wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1150
 
        wl->sta_rate_set = 0;
1151
 
        wl->flags = 0;
1152
1725
        wl->vif = NULL;
1153
1726
        wl->filters = 0;
 
1727
        wl1271_free_ap_keys(wl);
 
1728
        memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
 
1729
        wl->ap_fw_ps_map = 0;
 
1730
        wl->ap_ps_map = 0;
 
1731
        wl->sched_scanning = false;
 
1732
 
 
1733
        /*
 
1734
         * this is performed after the cancel_work calls and the associated
 
1735
         * mutex_lock, so that wl1271_op_add_interface does not accidentally
 
1736
         * get executed before all these vars have been reset.
 
1737
         */
 
1738
        wl->flags = 0;
1154
1739
 
1155
1740
        for (i = 0; i < NUM_TX_QUEUES; i++)
1156
1741
                wl->tx_blocks_freed[i] = 0;
1177
1762
         */
1178
1763
        if (wl->vif) {
1179
1764
                WARN_ON(wl->vif != vif);
1180
 
                __wl1271_op_remove_interface(wl);
 
1765
                __wl1271_op_remove_interface(wl, true);
1181
1766
        }
1182
1767
 
1183
1768
        mutex_unlock(&wl->mutex);
1184
1769
        cancel_work_sync(&wl->recovery_work);
1185
1770
}
1186
1771
 
1187
 
static void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
 
1772
void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
1188
1773
{
1189
 
        wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
1190
 
        wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
 
1774
        wl1271_set_default_filters(wl);
1191
1775
 
1192
1776
        /* combine requested filters with current filter config */
1193
1777
        filters = wl->filters | filters;
1248
1832
         * One of the side effects of the JOIN command is that is clears
1249
1833
         * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
1250
1834
         * to a WPA/WPA2 access point will therefore kill the data-path.
1251
 
         * Currently there is no supported scenario for JOIN during
1252
 
         * association - if it becomes a supported scenario, the WPA/WPA2 keys
1253
 
         * must be handled somehow.
1254
 
         *
 
1835
         * Currently the only valid scenario for JOIN during association
 
1836
         * is on roaming, in which case we will also be given new keys.
 
1837
         * Keep the below message for now, unless it starts bothering
 
1838
         * users who really like to roam a lot :)
1255
1839
         */
1256
1840
        if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1257
1841
                wl1271_info("JOIN while associated.");
1307
1891
        clear_bit(WL1271_FLAG_JOINED, &wl->flags);
1308
1892
        memset(wl->bssid, 0, ETH_ALEN);
1309
1893
 
1310
 
        /* stop filterting packets based on bssid */
 
1894
        /* stop filtering packets based on bssid */
1311
1895
        wl1271_configure_filters(wl, FIF_OTHER_BSS);
1312
1896
 
1313
1897
out:
1322
1906
                wl->basic_rate_set = wl->conf.tx.basic_rate_5;
1323
1907
}
1324
1908
 
1325
 
static u32 wl1271_min_rate_get(struct wl1271 *wl)
1326
 
{
1327
 
        int i;
1328
 
        u32 rate = 0;
1329
 
 
1330
 
        if (!wl->basic_rate_set) {
1331
 
                WARN_ON(1);
1332
 
                wl->basic_rate_set = wl->conf.tx.basic_rate;
1333
 
        }
1334
 
 
1335
 
        for (i = 0; !rate; i++) {
1336
 
                if ((wl->basic_rate_set >> i) & 0x1)
1337
 
                        rate = 1 << i;
1338
 
        }
1339
 
 
1340
 
        return rate;
1341
 
}
1342
 
 
1343
 
static int wl1271_handle_idle(struct wl1271 *wl, bool idle)
 
1909
static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
1344
1910
{
1345
1911
        int ret;
1346
1912
 
1350
1916
                        if (ret < 0)
1351
1917
                                goto out;
1352
1918
                }
1353
 
                wl->rate_set = wl1271_min_rate_get(wl);
1354
 
                wl->sta_rate_set = 0;
1355
 
                ret = wl1271_acx_rate_policies(wl);
 
1919
                wl->rate_set = wl1271_tx_min_rate_get(wl);
 
1920
                ret = wl1271_acx_sta_rate_policies(wl);
1356
1921
                if (ret < 0)
1357
1922
                        goto out;
1358
1923
                ret = wl1271_acx_keep_alive_config(
1366
1931
                wl->session_counter++;
1367
1932
                if (wl->session_counter >= SESSION_COUNTER_MAX)
1368
1933
                        wl->session_counter = 0;
 
1934
 
 
1935
                /* The current firmware only supports sched_scan in idle */
 
1936
                if (wl->sched_scanning) {
 
1937
                        wl1271_scan_sched_scan_stop(wl);
 
1938
                        ieee80211_sched_scan_stopped(wl->hw);
 
1939
                }
 
1940
 
1369
1941
                ret = wl1271_dummy_join(wl);
1370
1942
                if (ret < 0)
1371
1943
                        goto out;
1381
1953
        struct wl1271 *wl = hw->priv;
1382
1954
        struct ieee80211_conf *conf = &hw->conf;
1383
1955
        int channel, ret = 0;
 
1956
        bool is_ap;
1384
1957
 
1385
1958
        channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
1386
1959
 
1387
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s",
 
1960
        wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
 
1961
                     " changed 0x%x",
1388
1962
                     channel,
1389
1963
                     conf->flags & IEEE80211_CONF_PS ? "on" : "off",
1390
1964
                     conf->power_level,
1391
 
                     conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use");
 
1965
                     conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
 
1966
                         changed);
1392
1967
 
1393
1968
        /*
1394
1969
         * mac80211 will go to idle nearly immediately after transmitting some
1402
1977
        mutex_lock(&wl->mutex);
1403
1978
 
1404
1979
        if (unlikely(wl->state == WL1271_STATE_OFF)) {
1405
 
                ret = -EAGAIN;
 
1980
                /* we support configuring the channel and band while off */
 
1981
                if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
 
1982
                        wl->band = conf->channel->band;
 
1983
                        wl->channel = channel;
 
1984
                }
 
1985
 
1406
1986
                goto out;
1407
1987
        }
1408
1988
 
1409
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
1989
        is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
 
1990
 
 
1991
        ret = wl1271_ps_elp_wakeup(wl);
1410
1992
        if (ret < 0)
1411
1993
                goto out;
1412
1994
 
1417
1999
                wl->band = conf->channel->band;
1418
2000
                wl->channel = channel;
1419
2001
 
1420
 
                /*
1421
 
                 * FIXME: the mac80211 should really provide a fixed rate
1422
 
                 * to use here. for now, just use the smallest possible rate
1423
 
                 * for the band as a fixed rate for association frames and
1424
 
                 * other control messages.
1425
 
                 */
1426
 
                if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1427
 
                        wl1271_set_band_rate(wl);
1428
 
 
1429
 
                wl->basic_rate = wl1271_min_rate_get(wl);
1430
 
                ret = wl1271_acx_rate_policies(wl);
1431
 
                if (ret < 0)
1432
 
                        wl1271_warning("rate policy for update channel "
1433
 
                                       "failed %d", ret);
1434
 
 
1435
 
                if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
1436
 
                        ret = wl1271_join(wl, false);
 
2002
                if (!is_ap) {
 
2003
                        /*
 
2004
                         * FIXME: the mac80211 should really provide a fixed
 
2005
                         * rate to use here. for now, just use the smallest
 
2006
                         * possible rate for the band as a fixed rate for
 
2007
                         * association frames and other control messages.
 
2008
                         */
 
2009
                        if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
 
2010
                                wl1271_set_band_rate(wl);
 
2011
 
 
2012
                        wl->basic_rate = wl1271_tx_min_rate_get(wl);
 
2013
                        ret = wl1271_acx_sta_rate_policies(wl);
1437
2014
                        if (ret < 0)
1438
 
                                wl1271_warning("cmd join to update channel "
 
2015
                                wl1271_warning("rate policy for channel "
1439
2016
                                               "failed %d", ret);
 
2017
 
 
2018
                        if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
 
2019
                                ret = wl1271_join(wl, false);
 
2020
                                if (ret < 0)
 
2021
                                        wl1271_warning("cmd join on channel "
 
2022
                                                       "failed %d", ret);
 
2023
                        }
1440
2024
                }
1441
2025
        }
1442
2026
 
1443
 
        if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1444
 
                ret = wl1271_handle_idle(wl, conf->flags & IEEE80211_CONF_IDLE);
 
2027
        if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) {
 
2028
                ret = wl1271_sta_handle_idle(wl,
 
2029
                                        conf->flags & IEEE80211_CONF_IDLE);
1445
2030
                if (ret < 0)
1446
2031
                        wl1271_warning("idle mode change failed %d", ret);
1447
2032
        }
1548
2133
        struct wl1271 *wl = hw->priv;
1549
2134
        int ret;
1550
2135
 
1551
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter");
 
2136
        wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
 
2137
                     " total %x", changed, *total);
1552
2138
 
1553
2139
        mutex_lock(&wl->mutex);
1554
2140
 
1558
2144
        if (unlikely(wl->state == WL1271_STATE_OFF))
1559
2145
                goto out;
1560
2146
 
1561
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
2147
        ret = wl1271_ps_elp_wakeup(wl);
1562
2148
        if (ret < 0)
1563
2149
                goto out;
1564
2150
 
1565
 
 
1566
 
        if (*total & FIF_ALLMULTI)
1567
 
                ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
1568
 
        else if (fp)
1569
 
                ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
1570
 
                                                   fp->mc_list,
1571
 
                                                   fp->mc_list_length);
1572
 
        if (ret < 0)
1573
 
                goto out_sleep;
 
2151
        if (wl->bss_type != BSS_TYPE_AP_BSS) {
 
2152
                if (*total & FIF_ALLMULTI)
 
2153
                        ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
 
2154
                else if (fp)
 
2155
                        ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
 
2156
                                                           fp->mc_list,
 
2157
                                                           fp->mc_list_length);
 
2158
                if (ret < 0)
 
2159
                        goto out_sleep;
 
2160
        }
1574
2161
 
1575
2162
        /* determine, whether supported filter values have changed */
1576
2163
        if (changed == 0)
1593
2180
        kfree(fp);
1594
2181
}
1595
2182
 
 
2183
static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
 
2184
                        u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
 
2185
                        u16 tx_seq_16)
 
2186
{
 
2187
        struct wl1271_ap_key *ap_key;
 
2188
        int i;
 
2189
 
 
2190
        wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
 
2191
 
 
2192
        if (key_size > MAX_KEY_SIZE)
 
2193
                return -EINVAL;
 
2194
 
 
2195
        /*
 
2196
         * Find next free entry in ap_keys. Also check we are not replacing
 
2197
         * an existing key.
 
2198
         */
 
2199
        for (i = 0; i < MAX_NUM_KEYS; i++) {
 
2200
                if (wl->recorded_ap_keys[i] == NULL)
 
2201
                        break;
 
2202
 
 
2203
                if (wl->recorded_ap_keys[i]->id == id) {
 
2204
                        wl1271_warning("trying to record key replacement");
 
2205
                        return -EINVAL;
 
2206
                }
 
2207
        }
 
2208
 
 
2209
        if (i == MAX_NUM_KEYS)
 
2210
                return -EBUSY;
 
2211
 
 
2212
        ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
 
2213
        if (!ap_key)
 
2214
                return -ENOMEM;
 
2215
 
 
2216
        ap_key->id = id;
 
2217
        ap_key->key_type = key_type;
 
2218
        ap_key->key_size = key_size;
 
2219
        memcpy(ap_key->key, key, key_size);
 
2220
        ap_key->hlid = hlid;
 
2221
        ap_key->tx_seq_32 = tx_seq_32;
 
2222
        ap_key->tx_seq_16 = tx_seq_16;
 
2223
 
 
2224
        wl->recorded_ap_keys[i] = ap_key;
 
2225
        return 0;
 
2226
}
 
2227
 
 
2228
static void wl1271_free_ap_keys(struct wl1271 *wl)
 
2229
{
 
2230
        int i;
 
2231
 
 
2232
        for (i = 0; i < MAX_NUM_KEYS; i++) {
 
2233
                kfree(wl->recorded_ap_keys[i]);
 
2234
                wl->recorded_ap_keys[i] = NULL;
 
2235
        }
 
2236
}
 
2237
 
 
2238
static int wl1271_ap_init_hwenc(struct wl1271 *wl)
 
2239
{
 
2240
        int i, ret = 0;
 
2241
        struct wl1271_ap_key *key;
 
2242
        bool wep_key_added = false;
 
2243
 
 
2244
        for (i = 0; i < MAX_NUM_KEYS; i++) {
 
2245
                if (wl->recorded_ap_keys[i] == NULL)
 
2246
                        break;
 
2247
 
 
2248
                key = wl->recorded_ap_keys[i];
 
2249
                ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE,
 
2250
                                            key->id, key->key_type,
 
2251
                                            key->key_size, key->key,
 
2252
                                            key->hlid, key->tx_seq_32,
 
2253
                                            key->tx_seq_16);
 
2254
                if (ret < 0)
 
2255
                        goto out;
 
2256
 
 
2257
                if (key->key_type == KEY_WEP)
 
2258
                        wep_key_added = true;
 
2259
        }
 
2260
 
 
2261
        if (wep_key_added) {
 
2262
                ret = wl1271_cmd_set_ap_default_wep_key(wl, wl->default_key);
 
2263
                if (ret < 0)
 
2264
                        goto out;
 
2265
        }
 
2266
 
 
2267
out:
 
2268
        wl1271_free_ap_keys(wl);
 
2269
        return ret;
 
2270
}
 
2271
 
 
2272
static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
 
2273
                       u8 key_size, const u8 *key, u32 tx_seq_32,
 
2274
                       u16 tx_seq_16, struct ieee80211_sta *sta)
 
2275
{
 
2276
        int ret;
 
2277
        bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
 
2278
 
 
2279
        if (is_ap) {
 
2280
                struct wl1271_station *wl_sta;
 
2281
                u8 hlid;
 
2282
 
 
2283
                if (sta) {
 
2284
                        wl_sta = (struct wl1271_station *)sta->drv_priv;
 
2285
                        hlid = wl_sta->hlid;
 
2286
                } else {
 
2287
                        hlid = WL1271_AP_BROADCAST_HLID;
 
2288
                }
 
2289
 
 
2290
                if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
 
2291
                        /*
 
2292
                         * We do not support removing keys after AP shutdown.
 
2293
                         * Pretend we do to make mac80211 happy.
 
2294
                         */
 
2295
                        if (action != KEY_ADD_OR_REPLACE)
 
2296
                                return 0;
 
2297
 
 
2298
                        ret = wl1271_record_ap_key(wl, id,
 
2299
                                             key_type, key_size,
 
2300
                                             key, hlid, tx_seq_32,
 
2301
                                             tx_seq_16);
 
2302
                } else {
 
2303
                        ret = wl1271_cmd_set_ap_key(wl, action,
 
2304
                                             id, key_type, key_size,
 
2305
                                             key, hlid, tx_seq_32,
 
2306
                                             tx_seq_16);
 
2307
                }
 
2308
 
 
2309
                if (ret < 0)
 
2310
                        return ret;
 
2311
        } else {
 
2312
                const u8 *addr;
 
2313
                static const u8 bcast_addr[ETH_ALEN] = {
 
2314
                        0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 
2315
                };
 
2316
 
 
2317
                addr = sta ? sta->addr : bcast_addr;
 
2318
 
 
2319
                if (is_zero_ether_addr(addr)) {
 
2320
                        /* We dont support TX only encryption */
 
2321
                        return -EOPNOTSUPP;
 
2322
                }
 
2323
 
 
2324
                /* The wl1271 does not allow to remove unicast keys - they
 
2325
                   will be cleared automatically on next CMD_JOIN. Ignore the
 
2326
                   request silently, as we dont want the mac80211 to emit
 
2327
                   an error message. */
 
2328
                if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
 
2329
                        return 0;
 
2330
 
 
2331
                ret = wl1271_cmd_set_sta_key(wl, action,
 
2332
                                             id, key_type, key_size,
 
2333
                                             key, addr, tx_seq_32,
 
2334
                                             tx_seq_16);
 
2335
                if (ret < 0)
 
2336
                        return ret;
 
2337
 
 
2338
                /* the default WEP key needs to be configured at least once */
 
2339
                if (key_type == KEY_WEP) {
 
2340
                        ret = wl1271_cmd_set_sta_default_wep_key(wl,
 
2341
                                                        wl->default_key);
 
2342
                        if (ret < 0)
 
2343
                                return ret;
 
2344
                }
 
2345
        }
 
2346
 
 
2347
        return 0;
 
2348
}
 
2349
 
1596
2350
static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1597
2351
                             struct ieee80211_vif *vif,
1598
2352
                             struct ieee80211_sta *sta,
1599
2353
                             struct ieee80211_key_conf *key_conf)
1600
2354
{
1601
2355
        struct wl1271 *wl = hw->priv;
1602
 
        const u8 *addr;
1603
2356
        int ret;
1604
2357
        u32 tx_seq_32 = 0;
1605
2358
        u16 tx_seq_16 = 0;
1606
2359
        u8 key_type;
1607
2360
 
1608
 
        static const u8 bcast_addr[ETH_ALEN] =
1609
 
                { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1610
 
 
1611
2361
        wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
1612
2362
 
1613
 
        addr = sta ? sta->addr : bcast_addr;
1614
 
 
1615
 
        wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
1616
 
        wl1271_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
 
2363
        wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
1617
2364
        wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
1618
2365
                     key_conf->cipher, key_conf->keyidx,
1619
2366
                     key_conf->keylen, key_conf->flags);
1620
2367
        wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
1621
2368
 
1622
 
        if (is_zero_ether_addr(addr)) {
1623
 
                /* We dont support TX only encryption */
1624
 
                ret = -EOPNOTSUPP;
1625
 
                goto out;
1626
 
        }
1627
 
 
1628
2369
        mutex_lock(&wl->mutex);
1629
2370
 
1630
2371
        if (unlikely(wl->state == WL1271_STATE_OFF)) {
1632
2373
                goto out_unlock;
1633
2374
        }
1634
2375
 
1635
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
2376
        ret = wl1271_ps_elp_wakeup(wl);
1636
2377
        if (ret < 0)
1637
2378
                goto out_unlock;
1638
2379
 
1671
2412
 
1672
2413
        switch (cmd) {
1673
2414
        case SET_KEY:
1674
 
                ret = wl1271_cmd_set_key(wl, KEY_ADD_OR_REPLACE,
1675
 
                                         key_conf->keyidx, key_type,
1676
 
                                         key_conf->keylen, key_conf->key,
1677
 
                                         addr, tx_seq_32, tx_seq_16);
 
2415
                ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE,
 
2416
                                 key_conf->keyidx, key_type,
 
2417
                                 key_conf->keylen, key_conf->key,
 
2418
                                 tx_seq_32, tx_seq_16, sta);
1678
2419
                if (ret < 0) {
1679
2420
                        wl1271_error("Could not add or replace key");
1680
2421
                        goto out_sleep;
1681
2422
                }
1682
 
 
1683
 
                /* the default WEP key needs to be configured at least once */
1684
 
                if (key_type == KEY_WEP) {
1685
 
                        ret = wl1271_cmd_set_default_wep_key(wl,
1686
 
                                                             wl->default_key);
1687
 
                        if (ret < 0)
1688
 
                                goto out_sleep;
1689
 
                }
1690
2423
                break;
1691
2424
 
1692
2425
        case DISABLE_KEY:
1693
 
                /* The wl1271 does not allow to remove unicast keys - they
1694
 
                   will be cleared automatically on next CMD_JOIN. Ignore the
1695
 
                   request silently, as we dont want the mac80211 to emit
1696
 
                   an error message. */
1697
 
                if (!is_broadcast_ether_addr(addr))
1698
 
                        break;
1699
 
 
1700
 
                ret = wl1271_cmd_set_key(wl, KEY_REMOVE,
1701
 
                                         key_conf->keyidx, key_type,
1702
 
                                         key_conf->keylen, key_conf->key,
1703
 
                                         addr, 0, 0);
 
2426
                ret = wl1271_set_key(wl, KEY_REMOVE,
 
2427
                                     key_conf->keyidx, key_type,
 
2428
                                     key_conf->keylen, key_conf->key,
 
2429
                                     0, 0, sta);
1704
2430
                if (ret < 0) {
1705
2431
                        wl1271_error("Could not remove key");
1706
2432
                        goto out_sleep;
1719
2445
out_unlock:
1720
2446
        mutex_unlock(&wl->mutex);
1721
2447
 
1722
 
out:
1723
2448
        return ret;
1724
2449
}
1725
2450
 
1751
2476
                goto out;
1752
2477
        }
1753
2478
 
1754
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
2479
        ret = wl1271_ps_elp_wakeup(wl);
1755
2480
        if (ret < 0)
1756
2481
                goto out;
1757
2482
 
1765
2490
        return ret;
1766
2491
}
1767
2492
 
 
2493
static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
 
2494
                                      struct ieee80211_vif *vif,
 
2495
                                      struct cfg80211_sched_scan_request *req,
 
2496
                                      struct ieee80211_sched_scan_ies *ies)
 
2497
{
 
2498
        struct wl1271 *wl = hw->priv;
 
2499
        int ret;
 
2500
 
 
2501
        wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
 
2502
 
 
2503
        mutex_lock(&wl->mutex);
 
2504
 
 
2505
        ret = wl1271_ps_elp_wakeup(wl);
 
2506
        if (ret < 0)
 
2507
                goto out;
 
2508
 
 
2509
        ret = wl1271_scan_sched_scan_config(wl, req, ies);
 
2510
        if (ret < 0)
 
2511
                goto out_sleep;
 
2512
 
 
2513
        ret = wl1271_scan_sched_scan_start(wl);
 
2514
        if (ret < 0)
 
2515
                goto out_sleep;
 
2516
 
 
2517
        wl->sched_scanning = true;
 
2518
 
 
2519
out_sleep:
 
2520
        wl1271_ps_elp_sleep(wl);
 
2521
out:
 
2522
        mutex_unlock(&wl->mutex);
 
2523
        return ret;
 
2524
}
 
2525
 
 
2526
static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
 
2527
                                      struct ieee80211_vif *vif)
 
2528
{
 
2529
        struct wl1271 *wl = hw->priv;
 
2530
        int ret;
 
2531
 
 
2532
        wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
 
2533
 
 
2534
        mutex_lock(&wl->mutex);
 
2535
 
 
2536
        ret = wl1271_ps_elp_wakeup(wl);
 
2537
        if (ret < 0)
 
2538
                goto out;
 
2539
 
 
2540
        wl1271_scan_sched_scan_stop(wl);
 
2541
 
 
2542
        wl1271_ps_elp_sleep(wl);
 
2543
out:
 
2544
        mutex_unlock(&wl->mutex);
 
2545
}
 
2546
 
1768
2547
static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
1769
2548
{
1770
2549
        struct wl1271 *wl = hw->priv;
1777
2556
                goto out;
1778
2557
        }
1779
2558
 
1780
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
2559
        ret = wl1271_ps_elp_wakeup(wl);
1781
2560
        if (ret < 0)
1782
2561
                goto out;
1783
2562
 
1784
 
        ret = wl1271_acx_frag_threshold(wl, (u16)value);
 
2563
        ret = wl1271_acx_frag_threshold(wl, value);
1785
2564
        if (ret < 0)
1786
2565
                wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
1787
2566
 
1805
2584
                goto out;
1806
2585
        }
1807
2586
 
1808
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
2587
        ret = wl1271_ps_elp_wakeup(wl);
1809
2588
        if (ret < 0)
1810
2589
                goto out;
1811
2590
 
1812
 
        ret = wl1271_acx_rts_threshold(wl, (u16) value);
 
2591
        ret = wl1271_acx_rts_threshold(wl, value);
1813
2592
        if (ret < 0)
1814
2593
                wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
1815
2594
 
1821
2600
        return ret;
1822
2601
}
1823
2602
 
1824
 
static void wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
 
2603
static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
1825
2604
                            int offset)
1826
2605
{
1827
 
        u8 *ptr = skb->data + offset;
1828
 
 
1829
 
        /* find the location of the ssid in the beacon */
1830
 
        while (ptr < skb->data + skb->len) {
1831
 
                if (ptr[0] == WLAN_EID_SSID) {
1832
 
                        wl->ssid_len = ptr[1];
1833
 
                        memcpy(wl->ssid, ptr+2, wl->ssid_len);
1834
 
                        return;
1835
 
                }
1836
 
                ptr += (ptr[1] + 2);
1837
 
        }
1838
 
        wl1271_error("No SSID in IEs!\n");
 
2606
        u8 ssid_len;
 
2607
        const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
 
2608
                                         skb->len - offset);
 
2609
 
 
2610
        if (!ptr) {
 
2611
                wl1271_error("No SSID in IEs!");
 
2612
                return -ENOENT;
 
2613
        }
 
2614
 
 
2615
        ssid_len = ptr[1];
 
2616
        if (ssid_len > IEEE80211_MAX_SSID_LEN) {
 
2617
                wl1271_error("SSID is too long!");
 
2618
                return -EINVAL;
 
2619
        }
 
2620
 
 
2621
        wl->ssid_len = ssid_len;
 
2622
        memcpy(wl->ssid, ptr+2, ssid_len);
 
2623
        return 0;
1839
2624
}
1840
2625
 
1841
 
static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
1842
 
                                       struct ieee80211_vif *vif,
 
2626
static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
1843
2627
                                       struct ieee80211_bss_conf *bss_conf,
1844
2628
                                       u32 changed)
1845
2629
{
1846
 
        enum wl1271_cmd_ps_mode mode;
1847
 
        struct wl1271 *wl = hw->priv;
1848
 
        struct ieee80211_sta *sta = ieee80211_find_sta(vif, bss_conf->bssid);
1849
 
        bool do_join = false;
1850
 
        bool set_assoc = false;
1851
 
        int ret;
1852
 
 
1853
 
        wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed");
1854
 
 
1855
 
        mutex_lock(&wl->mutex);
1856
 
 
1857
 
        if (unlikely(wl->state == WL1271_STATE_OFF))
1858
 
                goto out;
1859
 
 
1860
 
        ret = wl1271_ps_elp_wakeup(wl, false);
1861
 
        if (ret < 0)
1862
 
                goto out;
1863
 
 
1864
 
        if ((changed & BSS_CHANGED_BEACON_INT) &&
1865
 
            (wl->bss_type == BSS_TYPE_IBSS)) {
1866
 
                wl1271_debug(DEBUG_ADHOC, "ad-hoc beacon interval updated: %d",
 
2630
        int ret = 0;
 
2631
 
 
2632
        if (changed & BSS_CHANGED_ERP_SLOT) {
 
2633
                if (bss_conf->use_short_slot)
 
2634
                        ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
 
2635
                else
 
2636
                        ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
 
2637
                if (ret < 0) {
 
2638
                        wl1271_warning("Set slot time failed %d", ret);
 
2639
                        goto out;
 
2640
                }
 
2641
        }
 
2642
 
 
2643
        if (changed & BSS_CHANGED_ERP_PREAMBLE) {
 
2644
                if (bss_conf->use_short_preamble)
 
2645
                        wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
 
2646
                else
 
2647
                        wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
 
2648
        }
 
2649
 
 
2650
        if (changed & BSS_CHANGED_ERP_CTS_PROT) {
 
2651
                if (bss_conf->use_cts_prot)
 
2652
                        ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
 
2653
                else
 
2654
                        ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
 
2655
                if (ret < 0) {
 
2656
                        wl1271_warning("Set ctsprotect failed %d", ret);
 
2657
                        goto out;
 
2658
                }
 
2659
        }
 
2660
 
 
2661
out:
 
2662
        return ret;
 
2663
}
 
2664
 
 
2665
static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
 
2666
                                          struct ieee80211_vif *vif,
 
2667
                                          struct ieee80211_bss_conf *bss_conf,
 
2668
                                          u32 changed)
 
2669
{
 
2670
        bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
 
2671
        int ret = 0;
 
2672
 
 
2673
        if ((changed & BSS_CHANGED_BEACON_INT)) {
 
2674
                wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
1867
2675
                        bss_conf->beacon_int);
1868
2676
 
1869
2677
                wl->beacon_int = bss_conf->beacon_int;
1870
 
                do_join = true;
1871
 
        }
1872
 
 
1873
 
        if ((changed & BSS_CHANGED_BEACON) &&
1874
 
            (wl->bss_type == BSS_TYPE_IBSS)) {
1875
 
                struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1876
 
 
1877
 
                wl1271_debug(DEBUG_ADHOC, "ad-hoc beacon updated");
1878
 
 
1879
 
                if (beacon) {
1880
 
                        struct ieee80211_hdr *hdr;
1881
 
                        int ieoffset = offsetof(struct ieee80211_mgmt,
1882
 
                                                u.beacon.variable);
1883
 
 
1884
 
                        wl1271_ssid_set(wl, beacon, ieoffset);
1885
 
 
1886
 
                        ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON,
1887
 
                                                      beacon->data,
1888
 
                                                      beacon->len, 0,
1889
 
                                                      wl1271_min_rate_get(wl));
1890
 
 
1891
 
                        if (ret < 0) {
1892
 
                                dev_kfree_skb(beacon);
1893
 
                                goto out_sleep;
1894
 
                        }
1895
 
 
1896
 
                        hdr = (struct ieee80211_hdr *) beacon->data;
1897
 
                        hdr->frame_control = cpu_to_le16(
1898
 
                                IEEE80211_FTYPE_MGMT |
1899
 
                                IEEE80211_STYPE_PROBE_RESP);
1900
 
 
1901
 
                        ret = wl1271_cmd_template_set(wl,
1902
 
                                                      CMD_TEMPL_PROBE_RESPONSE,
1903
 
                                                      beacon->data,
1904
 
                                                      beacon->len, 0,
1905
 
                                                      wl1271_min_rate_get(wl));
1906
 
                        dev_kfree_skb(beacon);
 
2678
        }
 
2679
 
 
2680
        if ((changed & BSS_CHANGED_BEACON)) {
 
2681
                struct ieee80211_hdr *hdr;
 
2682
                int ieoffset = offsetof(struct ieee80211_mgmt,
 
2683
                                        u.beacon.variable);
 
2684
                struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
 
2685
                u16 tmpl_id;
 
2686
 
 
2687
                if (!beacon)
 
2688
                        goto out;
 
2689
 
 
2690
                wl1271_debug(DEBUG_MASTER, "beacon updated");
 
2691
 
 
2692
                ret = wl1271_ssid_set(wl, beacon, ieoffset);
 
2693
                if (ret < 0) {
 
2694
                        dev_kfree_skb(beacon);
 
2695
                        goto out;
 
2696
                }
 
2697
                tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
 
2698
                                  CMD_TEMPL_BEACON;
 
2699
                ret = wl1271_cmd_template_set(wl, tmpl_id,
 
2700
                                              beacon->data,
 
2701
                                              beacon->len, 0,
 
2702
                                              wl1271_tx_min_rate_get(wl));
 
2703
                if (ret < 0) {
 
2704
                        dev_kfree_skb(beacon);
 
2705
                        goto out;
 
2706
                }
 
2707
 
 
2708
                hdr = (struct ieee80211_hdr *) beacon->data;
 
2709
                hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
 
2710
                                                 IEEE80211_STYPE_PROBE_RESP);
 
2711
 
 
2712
                tmpl_id = is_ap ? CMD_TEMPL_AP_PROBE_RESPONSE :
 
2713
                                  CMD_TEMPL_PROBE_RESPONSE;
 
2714
                ret = wl1271_cmd_template_set(wl,
 
2715
                                              tmpl_id,
 
2716
                                              beacon->data,
 
2717
                                              beacon->len, 0,
 
2718
                                              wl1271_tx_min_rate_get(wl));
 
2719
                dev_kfree_skb(beacon);
 
2720
                if (ret < 0)
 
2721
                        goto out;
 
2722
        }
 
2723
 
 
2724
out:
 
2725
        return ret;
 
2726
}
 
2727
 
 
2728
/* AP mode changes */
 
2729
static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
 
2730
                                       struct ieee80211_vif *vif,
 
2731
                                       struct ieee80211_bss_conf *bss_conf,
 
2732
                                       u32 changed)
 
2733
{
 
2734
        int ret = 0;
 
2735
 
 
2736
        if ((changed & BSS_CHANGED_BASIC_RATES)) {
 
2737
                u32 rates = bss_conf->basic_rates;
 
2738
 
 
2739
                wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates);
 
2740
                wl->basic_rate = wl1271_tx_min_rate_get(wl);
 
2741
 
 
2742
                ret = wl1271_init_ap_rates(wl);
 
2743
                if (ret < 0) {
 
2744
                        wl1271_error("AP rate policy change failed %d", ret);
 
2745
                        goto out;
 
2746
                }
 
2747
 
 
2748
                ret = wl1271_ap_init_templates(wl);
 
2749
                if (ret < 0)
 
2750
                        goto out;
 
2751
        }
 
2752
 
 
2753
        ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
 
2754
        if (ret < 0)
 
2755
                goto out;
 
2756
 
 
2757
        if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
 
2758
                if (bss_conf->enable_beacon) {
 
2759
                        if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
 
2760
                                ret = wl1271_cmd_start_bss(wl);
 
2761
                                if (ret < 0)
 
2762
                                        goto out;
 
2763
 
 
2764
                                set_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
 
2765
                                wl1271_debug(DEBUG_AP, "started AP");
 
2766
 
 
2767
                                ret = wl1271_ap_init_hwenc(wl);
 
2768
                                if (ret < 0)
 
2769
                                        goto out;
 
2770
                        }
 
2771
                } else {
 
2772
                        if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
 
2773
                                ret = wl1271_cmd_stop_bss(wl);
 
2774
                                if (ret < 0)
 
2775
                                        goto out;
 
2776
 
 
2777
                                clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
 
2778
                                wl1271_debug(DEBUG_AP, "stopped AP");
 
2779
                        }
 
2780
                }
 
2781
        }
 
2782
 
 
2783
        if (changed & BSS_CHANGED_IBSS) {
 
2784
                wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
 
2785
                             bss_conf->ibss_joined);
 
2786
 
 
2787
                if (bss_conf->ibss_joined) {
 
2788
                        u32 rates = bss_conf->basic_rates;
 
2789
                        wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
 
2790
                                                                         rates);
 
2791
                        wl->basic_rate = wl1271_tx_min_rate_get(wl);
 
2792
 
 
2793
                        /* by default, use 11b rates */
 
2794
                        wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
 
2795
                        ret = wl1271_acx_sta_rate_policies(wl);
1907
2796
                        if (ret < 0)
1908
 
                                goto out_sleep;
1909
 
 
1910
 
                        /* Need to update the SSID (for filtering etc) */
1911
 
                        do_join = true;
 
2797
                                goto out;
1912
2798
                }
1913
2799
        }
1914
2800
 
1915
 
        if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1916
 
            (wl->bss_type == BSS_TYPE_IBSS)) {
 
2801
        ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
 
2802
        if (ret < 0)
 
2803
                goto out;
 
2804
out:
 
2805
        return;
 
2806
}
 
2807
 
 
2808
/* STA/IBSS mode changes */
 
2809
static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
 
2810
                                        struct ieee80211_vif *vif,
 
2811
                                        struct ieee80211_bss_conf *bss_conf,
 
2812
                                        u32 changed)
 
2813
{
 
2814
        bool do_join = false, set_assoc = false;
 
2815
        bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS);
 
2816
        u32 sta_rate_set = 0;
 
2817
        int ret;
 
2818
        struct ieee80211_sta *sta;
 
2819
        bool sta_exists = false;
 
2820
        struct ieee80211_sta_ht_cap sta_ht_cap;
 
2821
 
 
2822
        if (is_ibss) {
 
2823
                ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
 
2824
                                                     changed);
 
2825
                if (ret < 0)
 
2826
                        goto out;
 
2827
        }
 
2828
 
 
2829
        if ((changed & BSS_CHANGED_BEACON_INT)  && is_ibss)
 
2830
                do_join = true;
 
2831
 
 
2832
        /* Need to update the SSID (for filtering etc) */
 
2833
        if ((changed & BSS_CHANGED_BEACON) && is_ibss)
 
2834
                do_join = true;
 
2835
 
 
2836
        if ((changed & BSS_CHANGED_BEACON_ENABLED) && is_ibss) {
1917
2837
                wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
1918
2838
                             bss_conf->enable_beacon ? "enabled" : "disabled");
1919
2839
 
1924
2844
                do_join = true;
1925
2845
        }
1926
2846
 
1927
 
        if (changed & BSS_CHANGED_CQM) {
 
2847
        if ((changed & BSS_CHANGED_CQM)) {
1928
2848
                bool enable = false;
1929
2849
                if (bss_conf->cqm_rssi_thold)
1930
2850
                        enable = true;
1942
2862
             * and enable the BSSID filter
1943
2863
             */
1944
2864
            memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
1945
 
                        memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
 
2865
                memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
1946
2866
 
 
2867
                if (!is_zero_ether_addr(wl->bssid)) {
1947
2868
                        ret = wl1271_cmd_build_null_data(wl);
1948
2869
                        if (ret < 0)
1949
 
                                goto out_sleep;
 
2870
                                goto out;
1950
2871
 
1951
2872
                        ret = wl1271_build_qos_null_data(wl);
1952
2873
                        if (ret < 0)
1953
 
                                goto out_sleep;
 
2874
                                goto out;
1954
2875
 
1955
2876
                        /* filter out all packets not from this BSSID */
1956
2877
                        wl1271_configure_filters(wl, 0);
1957
2878
 
1958
2879
                        /* Need to update the BSSID (for filtering etc) */
1959
2880
                        do_join = true;
1960
 
        }
1961
 
 
1962
 
        if (changed & BSS_CHANGED_ASSOC) {
 
2881
                }
 
2882
        }
 
2883
 
 
2884
        rcu_read_lock();
 
2885
        sta = ieee80211_find_sta(vif, bss_conf->bssid);
 
2886
        if (sta)  {
 
2887
                /* save the supp_rates of the ap */
 
2888
                sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
 
2889
                if (sta->ht_cap.ht_supported)
 
2890
                        sta_rate_set |=
 
2891
                            (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
 
2892
                sta_ht_cap = sta->ht_cap;
 
2893
                sta_exists = true;
 
2894
        }
 
2895
        rcu_read_unlock();
 
2896
 
 
2897
        if (sta_exists) {
 
2898
                /* handle new association with HT and HT information change */
 
2899
                if ((changed & BSS_CHANGED_HT) &&
 
2900
                    (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
 
2901
                        ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
 
2902
                                                             true);
 
2903
                        if (ret < 0) {
 
2904
                                wl1271_warning("Set ht cap true failed %d",
 
2905
                                               ret);
 
2906
                                goto out;
 
2907
                        }
 
2908
                        ret = wl1271_acx_set_ht_information(wl,
 
2909
                                                bss_conf->ht_operation_mode);
 
2910
                        if (ret < 0) {
 
2911
                                wl1271_warning("Set ht information failed %d",
 
2912
                                               ret);
 
2913
                                goto out;
 
2914
                        }
 
2915
                }
 
2916
                /* handle new association without HT and disassociation */
 
2917
                else if (changed & BSS_CHANGED_ASSOC) {
 
2918
                        ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
 
2919
                                                             false);
 
2920
                        if (ret < 0) {
 
2921
                                wl1271_warning("Set ht cap false failed %d",
 
2922
                                               ret);
 
2923
                                goto out;
 
2924
                        }
 
2925
                }
 
2926
        }
 
2927
 
 
2928
        if ((changed & BSS_CHANGED_ASSOC)) {
1963
2929
                if (bss_conf->assoc) {
1964
2930
                        u32 rates;
1965
2931
                        int ieoffset;
1975
2941
                        rates = bss_conf->basic_rates;
1976
2942
                        wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
1977
2943
                                                                         rates);
1978
 
                        wl->basic_rate = wl1271_min_rate_get(wl);
1979
 
                        ret = wl1271_acx_rate_policies(wl);
 
2944
                        wl->basic_rate = wl1271_tx_min_rate_get(wl);
 
2945
                        if (sta_rate_set)
 
2946
                                wl->rate_set = wl1271_tx_enabled_rates_get(wl,
 
2947
                                                                sta_rate_set);
 
2948
                        ret = wl1271_acx_sta_rate_policies(wl);
1980
2949
                        if (ret < 0)
1981
 
                                goto out_sleep;
 
2950
                                goto out;
1982
2951
 
1983
2952
                        /*
1984
2953
                         * with wl1271, we don't need to update the
1988
2957
                         */
1989
2958
                        ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
1990
2959
                        if (ret < 0)
1991
 
                                goto out_sleep;
 
2960
                                goto out;
1992
2961
 
1993
2962
                        /*
1994
2963
                         * Get a template for hardware connection maintenance
2002
2971
                        /* enable the connection monitoring feature */
2003
2972
                        ret = wl1271_acx_conn_monit_params(wl, true);
2004
2973
                        if (ret < 0)
2005
 
                                goto out_sleep;
 
2974
                                goto out;
2006
2975
 
2007
2976
                        /* If we want to go in PSM but we're not there yet */
2008
2977
                        if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
2009
2978
                            !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
 
2979
                                enum wl1271_cmd_ps_mode mode;
 
2980
 
2010
2981
                                mode = STATION_POWER_SAVE_MODE;
2011
2982
                                ret = wl1271_ps_set_mode(wl, mode,
2012
2983
                                                         wl->basic_rate,
2013
2984
                                                         true);
2014
2985
                                if (ret < 0)
2015
 
                                        goto out_sleep;
 
2986
                                        goto out;
2016
2987
                        }
2017
2988
                } else {
2018
2989
                        /* use defaults when not associated */
 
2990
                        bool was_assoc =
 
2991
                            !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED,
 
2992
                                                 &wl->flags);
2019
2993
                        clear_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags);
2020
 
                        clear_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
2021
2994
                        wl->aid = 0;
2022
2995
 
2023
2996
                        /* free probe-request template */
2029
3002
 
2030
3003
                        /* revert back to minimum rates for the current band */
2031
3004
                        wl1271_set_band_rate(wl);
2032
 
                        wl->basic_rate = wl1271_min_rate_get(wl);
2033
 
                        ret = wl1271_acx_rate_policies(wl);
 
3005
                        wl->basic_rate = wl1271_tx_min_rate_get(wl);
 
3006
                        ret = wl1271_acx_sta_rate_policies(wl);
2034
3007
                        if (ret < 0)
2035
 
                                goto out_sleep;
 
3008
                                goto out;
2036
3009
 
2037
3010
                        /* disable connection monitor features */
2038
3011
                        ret = wl1271_acx_conn_monit_params(wl, false);
2040
3013
                        /* Disable the keep-alive feature */
2041
3014
                        ret = wl1271_acx_keep_alive_mode(wl, false);
2042
3015
                        if (ret < 0)
2043
 
                                goto out_sleep;
 
3016
                                goto out;
2044
3017
 
2045
3018
                        /* restore the bssid filter and go to dummy bssid */
2046
 
                        wl1271_unjoin(wl);
2047
 
                        wl1271_dummy_join(wl);
2048
 
                }
2049
 
 
2050
 
        }
2051
 
 
2052
 
        if (changed & BSS_CHANGED_ERP_SLOT) {
2053
 
                if (bss_conf->use_short_slot)
2054
 
                        ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
2055
 
                else
2056
 
                        ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
2057
 
                if (ret < 0) {
2058
 
                        wl1271_warning("Set slot time failed %d", ret);
2059
 
                        goto out_sleep;
2060
 
                }
2061
 
        }
2062
 
 
2063
 
        if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2064
 
                if (bss_conf->use_short_preamble)
2065
 
                        wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
2066
 
                else
2067
 
                        wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
2068
 
        }
2069
 
 
2070
 
        if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2071
 
                if (bss_conf->use_cts_prot)
2072
 
                        ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
2073
 
                else
2074
 
                        ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
2075
 
                if (ret < 0) {
2076
 
                        wl1271_warning("Set ctsprotect failed %d", ret);
2077
 
                        goto out_sleep;
2078
 
                }
2079
 
        }
2080
 
 
2081
 
        /*
2082
 
         * Takes care of: New association with HT enable,
2083
 
         *                HT information change in beacon.
2084
 
         */
2085
 
        if (sta &&
2086
 
            (changed & BSS_CHANGED_HT) &&
2087
 
            (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
2088
 
                ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true);
2089
 
                if (ret < 0) {
2090
 
                        wl1271_warning("Set ht cap true failed %d", ret);
2091
 
                        goto out_sleep;
2092
 
                }
2093
 
                        ret = wl1271_acx_set_ht_information(wl,
2094
 
                                bss_conf->ht_operation_mode);
2095
 
                if (ret < 0) {
2096
 
                        wl1271_warning("Set ht information failed %d", ret);
2097
 
                        goto out_sleep;
2098
 
                }
2099
 
        }
2100
 
        /*
2101
 
         * Takes care of: New association without HT,
2102
 
         *                Disassociation.
2103
 
         */
2104
 
        else if (sta && (changed & BSS_CHANGED_ASSOC)) {
2105
 
                ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, false);
2106
 
                if (ret < 0) {
2107
 
                        wl1271_warning("Set ht cap false failed %d", ret);
2108
 
                        goto out_sleep;
2109
 
                }
2110
 
        }
 
3019
                        if (was_assoc) {
 
3020
                                wl1271_unjoin(wl);
 
3021
                                wl1271_dummy_join(wl);
 
3022
                        }
 
3023
                }
 
3024
        }
 
3025
 
 
3026
        ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
 
3027
        if (ret < 0)
 
3028
                goto out;
2111
3029
 
2112
3030
        if (changed & BSS_CHANGED_ARP_FILTER) {
2113
3031
                __be32 addr = bss_conf->arp_addr_list[0];
2124
3042
                        ret = wl1271_cmd_build_arp_rsp(wl, addr);
2125
3043
                        if (ret < 0) {
2126
3044
                                wl1271_warning("build arp rsp failed: %d", ret);
2127
 
                                goto out_sleep;
 
3045
                                goto out;
2128
3046
                        }
2129
3047
 
2130
3048
                        ret = wl1271_acx_arp_ip_filter(wl,
2131
 
                                (ACX_ARP_FILTER_ARP_FILTERING |
2132
 
                                 ACX_ARP_FILTER_AUTO_ARP),
 
3049
                                ACX_ARP_FILTER_ARP_FILTERING,
2133
3050
                                addr);
2134
3051
                } else
2135
3052
                        ret = wl1271_acx_arp_ip_filter(wl, 0, addr);
2136
3053
 
2137
3054
                if (ret < 0)
2138
 
                        goto out_sleep;
 
3055
                        goto out;
2139
3056
        }
2140
3057
 
2141
3058
        if (do_join) {
2142
3059
                ret = wl1271_join(wl, set_assoc);
2143
3060
                if (ret < 0) {
2144
3061
                        wl1271_warning("cmd join failed %d", ret);
2145
 
                        goto out_sleep;
 
3062
                        goto out;
2146
3063
                }
2147
3064
        }
2148
3065
 
2149
 
out_sleep:
 
3066
out:
 
3067
        return;
 
3068
}
 
3069
 
 
3070
static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
 
3071
                                       struct ieee80211_vif *vif,
 
3072
                                       struct ieee80211_bss_conf *bss_conf,
 
3073
                                       u32 changed)
 
3074
{
 
3075
        struct wl1271 *wl = hw->priv;
 
3076
        bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
 
3077
        int ret;
 
3078
 
 
3079
        wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
 
3080
                     (int)changed);
 
3081
 
 
3082
        mutex_lock(&wl->mutex);
 
3083
 
 
3084
        if (unlikely(wl->state == WL1271_STATE_OFF))
 
3085
                goto out;
 
3086
 
 
3087
        ret = wl1271_ps_elp_wakeup(wl);
 
3088
        if (ret < 0)
 
3089
                goto out;
 
3090
 
 
3091
        if (is_ap)
 
3092
                wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
 
3093
        else
 
3094
                wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
 
3095
 
2150
3096
        wl1271_ps_elp_sleep(wl);
2151
3097
 
2152
3098
out:
2158
3104
{
2159
3105
        struct wl1271 *wl = hw->priv;
2160
3106
        u8 ps_scheme;
2161
 
        int ret;
 
3107
        int ret = 0;
2162
3108
 
2163
3109
        mutex_lock(&wl->mutex);
2164
3110
 
2165
3111
        wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
2166
3112
 
2167
 
        if (unlikely(wl->state == WL1271_STATE_OFF)) {
2168
 
                ret = -EAGAIN;
 
3113
        if (params->uapsd)
 
3114
                ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
 
3115
        else
 
3116
                ps_scheme = CONF_PS_SCHEME_LEGACY;
 
3117
 
 
3118
        if (wl->state == WL1271_STATE_OFF) {
 
3119
                /*
 
3120
                 * If the state is off, the parameters will be recorded and
 
3121
                 * configured on init. This happens in AP-mode.
 
3122
                 */
 
3123
                struct conf_tx_ac_category *conf_ac =
 
3124
                        &wl->conf.tx.ac_conf[wl1271_tx_get_queue(queue)];
 
3125
                struct conf_tx_tid *conf_tid =
 
3126
                        &wl->conf.tx.tid_conf[wl1271_tx_get_queue(queue)];
 
3127
 
 
3128
                conf_ac->ac = wl1271_tx_get_queue(queue);
 
3129
                conf_ac->cw_min = (u8)params->cw_min;
 
3130
                conf_ac->cw_max = params->cw_max;
 
3131
                conf_ac->aifsn = params->aifs;
 
3132
                conf_ac->tx_op_limit = params->txop << 5;
 
3133
 
 
3134
                conf_tid->queue_id = wl1271_tx_get_queue(queue);
 
3135
                conf_tid->channel_type = CONF_CHANNEL_TYPE_EDCF;
 
3136
                conf_tid->tsid = wl1271_tx_get_queue(queue);
 
3137
                conf_tid->ps_scheme = ps_scheme;
 
3138
                conf_tid->ack_policy = CONF_ACK_POLICY_LEGACY;
 
3139
                conf_tid->apsd_conf[0] = 0;
 
3140
                conf_tid->apsd_conf[1] = 0;
2169
3141
                goto out;
2170
3142
        }
2171
3143
 
2172
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
3144
        ret = wl1271_ps_elp_wakeup(wl);
2173
3145
        if (ret < 0)
2174
3146
                goto out;
2175
3147
 
2176
 
        /* the txop is confed in units of 32us by the mac80211, we need us */
 
3148
        /*
 
3149
         * the txop is confed in units of 32us by the mac80211,
 
3150
         * we need us
 
3151
         */
2177
3152
        ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
2178
3153
                                params->cw_min, params->cw_max,
2179
3154
                                params->aifs, params->txop << 5);
2180
3155
        if (ret < 0)
2181
3156
                goto out_sleep;
2182
3157
 
2183
 
        if (params->uapsd)
2184
 
                ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
2185
 
        else
2186
 
                ps_scheme = CONF_PS_SCHEME_LEGACY;
2187
 
 
2188
3158
        ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
2189
3159
                                 CONF_CHANNEL_TYPE_EDCF,
2190
3160
                                 wl1271_tx_get_queue(queue),
2191
 
                                 ps_scheme, CONF_ACK_POLICY_LEGACY, 0, 0);
2192
 
        if (ret < 0)
2193
 
                goto out_sleep;
 
3161
                                 ps_scheme, CONF_ACK_POLICY_LEGACY,
 
3162
                                 0, 0);
2194
3163
 
2195
3164
out_sleep:
2196
3165
        wl1271_ps_elp_sleep(wl);
2215
3184
        if (unlikely(wl->state == WL1271_STATE_OFF))
2216
3185
                goto out;
2217
3186
 
2218
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
3187
        ret = wl1271_ps_elp_wakeup(wl);
2219
3188
        if (ret < 0)
2220
3189
                goto out;
2221
3190
 
2247
3216
        return 0;
2248
3217
}
2249
3218
 
 
3219
static int wl1271_allocate_sta(struct wl1271 *wl,
 
3220
                             struct ieee80211_sta *sta,
 
3221
                             u8 *hlid)
 
3222
{
 
3223
        struct wl1271_station *wl_sta;
 
3224
        int id;
 
3225
 
 
3226
        id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS);
 
3227
        if (id >= AP_MAX_STATIONS) {
 
3228
                wl1271_warning("could not allocate HLID - too much stations");
 
3229
                return -EBUSY;
 
3230
        }
 
3231
 
 
3232
        wl_sta = (struct wl1271_station *)sta->drv_priv;
 
3233
        __set_bit(id, wl->ap_hlid_map);
 
3234
        wl_sta->hlid = WL1271_AP_STA_HLID_START + id;
 
3235
        *hlid = wl_sta->hlid;
 
3236
        memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
 
3237
        return 0;
 
3238
}
 
3239
 
 
3240
static void wl1271_free_sta(struct wl1271 *wl, u8 hlid)
 
3241
{
 
3242
        int id = hlid - WL1271_AP_STA_HLID_START;
 
3243
 
 
3244
        if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
 
3245
                return;
 
3246
 
 
3247
        __clear_bit(id, wl->ap_hlid_map);
 
3248
        memset(wl->links[hlid].addr, 0, ETH_ALEN);
 
3249
        wl1271_tx_reset_link_queues(wl, hlid);
 
3250
        __clear_bit(hlid, &wl->ap_ps_map);
 
3251
        __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
 
3252
}
 
3253
 
 
3254
static int wl1271_op_sta_add(struct ieee80211_hw *hw,
 
3255
                             struct ieee80211_vif *vif,
 
3256
                             struct ieee80211_sta *sta)
 
3257
{
 
3258
        struct wl1271 *wl = hw->priv;
 
3259
        int ret = 0;
 
3260
        u8 hlid;
 
3261
 
 
3262
        mutex_lock(&wl->mutex);
 
3263
 
 
3264
        if (unlikely(wl->state == WL1271_STATE_OFF))
 
3265
                goto out;
 
3266
 
 
3267
        if (wl->bss_type != BSS_TYPE_AP_BSS)
 
3268
                goto out;
 
3269
 
 
3270
        wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
 
3271
 
 
3272
        ret = wl1271_allocate_sta(wl, sta, &hlid);
 
3273
        if (ret < 0)
 
3274
                goto out;
 
3275
 
 
3276
        ret = wl1271_ps_elp_wakeup(wl);
 
3277
        if (ret < 0)
 
3278
                goto out_free_sta;
 
3279
 
 
3280
        ret = wl1271_cmd_add_sta(wl, sta, hlid);
 
3281
        if (ret < 0)
 
3282
                goto out_sleep;
 
3283
 
 
3284
out_sleep:
 
3285
        wl1271_ps_elp_sleep(wl);
 
3286
 
 
3287
out_free_sta:
 
3288
        if (ret < 0)
 
3289
                wl1271_free_sta(wl, hlid);
 
3290
 
 
3291
out:
 
3292
        mutex_unlock(&wl->mutex);
 
3293
        return ret;
 
3294
}
 
3295
 
 
3296
static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
 
3297
                                struct ieee80211_vif *vif,
 
3298
                                struct ieee80211_sta *sta)
 
3299
{
 
3300
        struct wl1271 *wl = hw->priv;
 
3301
        struct wl1271_station *wl_sta;
 
3302
        int ret = 0, id;
 
3303
 
 
3304
        mutex_lock(&wl->mutex);
 
3305
 
 
3306
        if (unlikely(wl->state == WL1271_STATE_OFF))
 
3307
                goto out;
 
3308
 
 
3309
        if (wl->bss_type != BSS_TYPE_AP_BSS)
 
3310
                goto out;
 
3311
 
 
3312
        wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
 
3313
 
 
3314
        wl_sta = (struct wl1271_station *)sta->drv_priv;
 
3315
        id = wl_sta->hlid - WL1271_AP_STA_HLID_START;
 
3316
        if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
 
3317
                goto out;
 
3318
 
 
3319
        ret = wl1271_ps_elp_wakeup(wl);
 
3320
        if (ret < 0)
 
3321
                goto out;
 
3322
 
 
3323
        ret = wl1271_cmd_remove_sta(wl, wl_sta->hlid);
 
3324
        if (ret < 0)
 
3325
                goto out_sleep;
 
3326
 
 
3327
        wl1271_free_sta(wl, wl_sta->hlid);
 
3328
 
 
3329
out_sleep:
 
3330
        wl1271_ps_elp_sleep(wl);
 
3331
 
 
3332
out:
 
3333
        mutex_unlock(&wl->mutex);
 
3334
        return ret;
 
3335
}
 
3336
 
 
3337
static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
 
3338
                                  struct ieee80211_vif *vif,
 
3339
                                  enum ieee80211_ampdu_mlme_action action,
 
3340
                                  struct ieee80211_sta *sta, u16 tid, u16 *ssn,
 
3341
                                  u8 buf_size)
 
3342
{
 
3343
        struct wl1271 *wl = hw->priv;
 
3344
        int ret;
 
3345
 
 
3346
        mutex_lock(&wl->mutex);
 
3347
 
 
3348
        if (unlikely(wl->state == WL1271_STATE_OFF)) {
 
3349
                ret = -EAGAIN;
 
3350
                goto out;
 
3351
        }
 
3352
 
 
3353
        ret = wl1271_ps_elp_wakeup(wl);
 
3354
        if (ret < 0)
 
3355
                goto out;
 
3356
 
 
3357
        switch (action) {
 
3358
        case IEEE80211_AMPDU_RX_START:
 
3359
                if (wl->ba_support) {
 
3360
                        ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn,
 
3361
                                                                 true);
 
3362
                        if (!ret)
 
3363
                                wl->ba_rx_bitmap |= BIT(tid);
 
3364
                } else {
 
3365
                        ret = -ENOTSUPP;
 
3366
                }
 
3367
                break;
 
3368
 
 
3369
        case IEEE80211_AMPDU_RX_STOP:
 
3370
                ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false);
 
3371
                if (!ret)
 
3372
                        wl->ba_rx_bitmap &= ~BIT(tid);
 
3373
                break;
 
3374
 
 
3375
        /*
 
3376
         * The BA initiator session management in FW independently.
 
3377
         * Falling break here on purpose for all TX APDU commands.
 
3378
         */
 
3379
        case IEEE80211_AMPDU_TX_START:
 
3380
        case IEEE80211_AMPDU_TX_STOP:
 
3381
        case IEEE80211_AMPDU_TX_OPERATIONAL:
 
3382
                ret = -EINVAL;
 
3383
                break;
 
3384
 
 
3385
        default:
 
3386
                wl1271_error("Incorrect ampdu action id=%x\n", action);
 
3387
                ret = -EINVAL;
 
3388
        }
 
3389
 
 
3390
        wl1271_ps_elp_sleep(wl);
 
3391
 
 
3392
out:
 
3393
        mutex_unlock(&wl->mutex);
 
3394
 
 
3395
        return ret;
 
3396
}
 
3397
 
 
3398
static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
 
3399
{
 
3400
        struct wl1271 *wl = hw->priv;
 
3401
        bool ret = false;
 
3402
 
 
3403
        mutex_lock(&wl->mutex);
 
3404
 
 
3405
        if (unlikely(wl->state == WL1271_STATE_OFF))
 
3406
                goto out;
 
3407
 
 
3408
        /* packets are considered pending if in the TX queue or the FW */
 
3409
        ret = (wl->tx_queue_count > 0) || (wl->tx_frames_cnt > 0);
 
3410
 
 
3411
        /* the above is appropriate for STA mode for PS purposes */
 
3412
        WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
 
3413
 
 
3414
out:
 
3415
        mutex_unlock(&wl->mutex);
 
3416
 
 
3417
        return ret;
 
3418
}
 
3419
 
2250
3420
/* can't be const, mac80211 writes to this */
2251
3421
static struct ieee80211_rate wl1271_rates[] = {
2252
3422
        { .bitrate = 10,
2305
3475
        { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
2306
3476
        { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
2307
3477
        { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
 
3478
        { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
2308
3479
};
2309
3480
 
2310
3481
/* mapping to indexes for wl1271_rates */
2342
3513
 
2343
3514
#ifdef CONFIG_WL12XX_HT
2344
3515
#define WL12XX_HT_CAP { \
2345
 
        .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20, \
 
3516
        .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
 
3517
               (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
2346
3518
        .ht_supported = true, \
2347
3519
        .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
2348
3520
        .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
2481
3653
        .stop = wl1271_op_stop,
2482
3654
        .add_interface = wl1271_op_add_interface,
2483
3655
        .remove_interface = wl1271_op_remove_interface,
 
3656
#ifdef CONFIG_PM
 
3657
        .suspend = wl1271_op_suspend,
 
3658
        .resume = wl1271_op_resume,
 
3659
#endif
2484
3660
        .config = wl1271_op_config,
2485
3661
        .prepare_multicast = wl1271_op_prepare_multicast,
2486
3662
        .configure_filter = wl1271_op_configure_filter,
2487
3663
        .tx = wl1271_op_tx,
2488
3664
        .set_key = wl1271_op_set_key,
2489
3665
        .hw_scan = wl1271_op_hw_scan,
 
3666
        .sched_scan_start = wl1271_op_sched_scan_start,
 
3667
        .sched_scan_stop = wl1271_op_sched_scan_stop,
2490
3668
        .bss_info_changed = wl1271_op_bss_info_changed,
2491
3669
        .set_frag_threshold = wl1271_op_set_frag_threshold,
2492
3670
        .set_rts_threshold = wl1271_op_set_rts_threshold,
2493
3671
        .conf_tx = wl1271_op_conf_tx,
2494
3672
        .get_tsf = wl1271_op_get_tsf,
2495
3673
        .get_survey = wl1271_op_get_survey,
 
3674
        .sta_add = wl1271_op_sta_add,
 
3675
        .sta_remove = wl1271_op_sta_remove,
 
3676
        .ampdu_action = wl1271_op_ampdu_action,
 
3677
        .tx_frames_pending = wl1271_tx_frames_pending,
2496
3678
        CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
2497
3679
};
2498
3680
 
2543
3725
        unsigned long res;
2544
3726
        int ret;
2545
3727
 
2546
 
        ret = strict_strtoul(buf, 10, &res);
2547
 
 
 
3728
        ret = kstrtoul(buf, 10, &res);
2548
3729
        if (ret < 0) {
2549
3730
                wl1271_warning("incorrect value written to bt_coex_mode");
2550
3731
                return count;
2562
3743
        if (wl->state == WL1271_STATE_OFF)
2563
3744
                goto out;
2564
3745
 
2565
 
        ret = wl1271_ps_elp_wakeup(wl, false);
 
3746
        ret = wl1271_ps_elp_wakeup(wl);
2566
3747
        if (ret < 0)
2567
3748
                goto out;
2568
3749
 
2607
3788
        if (wl->mac80211_registered)
2608
3789
                return 0;
2609
3790
 
 
3791
        ret = wl1271_fetch_nvs(wl);
 
3792
        if (ret == 0) {
 
3793
                /* NOTE: The wl->nvs->nvs element must be first, in
 
3794
                 * order to simplify the casting, we assume it is at
 
3795
                 * the beginning of the wl->nvs structure.
 
3796
                 */
 
3797
                u8 *nvs_ptr = (u8 *)wl->nvs;
 
3798
 
 
3799
                wl->mac_addr[0] = nvs_ptr[11];
 
3800
                wl->mac_addr[1] = nvs_ptr[10];
 
3801
                wl->mac_addr[2] = nvs_ptr[6];
 
3802
                wl->mac_addr[3] = nvs_ptr[5];
 
3803
                wl->mac_addr[4] = nvs_ptr[4];
 
3804
                wl->mac_addr[5] = nvs_ptr[3];
 
3805
        }
 
3806
 
2610
3807
        SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
2611
3808
 
2612
3809
        ret = ieee80211_register_hw(wl->hw);
2629
3826
 
2630
3827
void wl1271_unregister_hw(struct wl1271 *wl)
2631
3828
{
 
3829
        if (wl->state == WL1271_STATE_PLT)
 
3830
                __wl1271_plt_stop(wl);
 
3831
 
2632
3832
        unregister_netdevice_notifier(&wl1271_dev_notifier);
2633
3833
        ieee80211_unregister_hw(wl->hw);
2634
3834
        wl->mac80211_registered = false;
2661
3861
                IEEE80211_HW_SUPPORTS_UAPSD |
2662
3862
                IEEE80211_HW_HAS_RATE_CONTROL |
2663
3863
                IEEE80211_HW_CONNECTION_MONITOR |
2664
 
                IEEE80211_HW_SUPPORTS_CQM_RSSI;
 
3864
                IEEE80211_HW_SUPPORTS_CQM_RSSI |
 
3865
                IEEE80211_HW_REPORTS_TX_ACK_STATUS |
 
3866
                IEEE80211_HW_SPECTRUM_MGMT |
 
3867
                IEEE80211_HW_AP_LINK_PS;
2665
3868
 
2666
3869
        wl->hw->wiphy->cipher_suites = cipher_suites;
2667
3870
        wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
2668
3871
 
2669
3872
        wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2670
 
                BIT(NL80211_IFTYPE_ADHOC);
 
3873
                BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
2671
3874
        wl->hw->wiphy->max_scan_ssids = 1;
2672
3875
        /*
2673
3876
         * Maximum length of elements in scanning probe request templates
2676
3879
         */
2677
3880
        wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
2678
3881
                        sizeof(struct ieee80211_header);
2679
 
        wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1271_band_2ghz;
2680
 
        wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &wl1271_band_5ghz;
 
3882
 
 
3883
        /* make sure all our channels fit in the scanned_ch bitmask */
 
3884
        BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
 
3885
                     ARRAY_SIZE(wl1271_channels_5ghz) >
 
3886
                     WL1271_MAX_CHANNELS);
 
3887
        /*
 
3888
         * We keep local copies of the band structs because we need to
 
3889
         * modify them on a per-device basis.
 
3890
         */
 
3891
        memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
 
3892
               sizeof(wl1271_band_2ghz));
 
3893
        memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
 
3894
               sizeof(wl1271_band_5ghz));
 
3895
 
 
3896
        wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
 
3897
                &wl->bands[IEEE80211_BAND_2GHZ];
 
3898
        wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
 
3899
                &wl->bands[IEEE80211_BAND_5GHZ];
2681
3900
 
2682
3901
        wl->hw->queues = 4;
2683
3902
        wl->hw->max_rates = 1;
2686
3905
 
2687
3906
        SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
2688
3907
 
 
3908
        wl->hw->sta_data_size = sizeof(struct wl1271_station);
 
3909
 
 
3910
        wl->hw->max_rx_aggregation_subframes = 8;
 
3911
 
2689
3912
        return 0;
2690
3913
}
2691
3914
EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
2697
3920
        struct ieee80211_hw *hw;
2698
3921
        struct platform_device *plat_dev = NULL;
2699
3922
        struct wl1271 *wl;
2700
 
        int i, ret;
 
3923
        int i, j, ret;
2701
3924
        unsigned int order;
2702
3925
 
2703
3926
        hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
2725
3948
        for (i = 0; i < NUM_TX_QUEUES; i++)
2726
3949
                skb_queue_head_init(&wl->tx_queue[i]);
2727
3950
 
 
3951
        for (i = 0; i < NUM_TX_QUEUES; i++)
 
3952
                for (j = 0; j < AP_MAX_LINKS; j++)
 
3953
                        skb_queue_head_init(&wl->links[j].tx_queue[i]);
 
3954
 
 
3955
        skb_queue_head_init(&wl->deferred_rx_queue);
 
3956
        skb_queue_head_init(&wl->deferred_tx_queue);
 
3957
 
2728
3958
        INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
2729
3959
        INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
2730
 
        INIT_WORK(&wl->irq_work, wl1271_irq_work);
 
3960
        INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
2731
3961
        INIT_WORK(&wl->tx_work, wl1271_tx_work);
2732
3962
        INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
2733
3963
        INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
2735
3965
        wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
2736
3966
        wl->default_key = 0;
2737
3967
        wl->rx_counter = 0;
2738
 
        wl->rx_config = WL1271_DEFAULT_RX_CONFIG;
2739
 
        wl->rx_filter = WL1271_DEFAULT_RX_FILTER;
 
3968
        wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG;
 
3969
        wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER;
2740
3970
        wl->psm_entry_retry = 0;
2741
3971
        wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
2742
3972
        wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
2743
3973
        wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
2744
3974
        wl->rate_set = CONF_TX_RATE_MASK_BASIC;
2745
 
        wl->sta_rate_set = 0;
2746
3975
        wl->band = IEEE80211_BAND_2GHZ;
2747
3976
        wl->vif = NULL;
2748
3977
        wl->flags = 0;
2749
3978
        wl->sg_enabled = true;
2750
3979
        wl->hw_pg_ver = -1;
 
3980
        wl->bss_type = MAX_BSS_TYPE;
 
3981
        wl->set_bss_type = MAX_BSS_TYPE;
 
3982
        wl->fw_bss_type = MAX_BSS_TYPE;
 
3983
        wl->last_tx_hlid = 0;
 
3984
        wl->ap_ps_map = 0;
 
3985
        wl->ap_fw_ps_map = 0;
 
3986
        wl->quirks = 0;
 
3987
        wl->platform_quirks = 0;
 
3988
        wl->sched_scanning = false;
2751
3989
 
2752
3990
        memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
2753
3991
        for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
2768
4006
                goto err_hw;
2769
4007
        }
2770
4008
 
 
4009
        wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
 
4010
        if (!wl->dummy_packet) {
 
4011
                ret = -ENOMEM;
 
4012
                goto err_aggr;
 
4013
        }
 
4014
 
2771
4015
        /* Register platform device */
2772
4016
        ret = platform_device_register(wl->plat_dev);
2773
4017
        if (ret) {
2774
4018
                wl1271_error("couldn't register platform device");
2775
 
                goto err_aggr;
 
4019
                goto err_dummy_packet;
2776
4020
        }
2777
4021
        dev_set_drvdata(&wl->plat_dev->dev, wl);
2778
4022
 
2798
4042
err_platform:
2799
4043
        platform_device_unregister(wl->plat_dev);
2800
4044
 
 
4045
err_dummy_packet:
 
4046
        dev_kfree_skb(wl->dummy_packet);
 
4047
 
2801
4048
err_aggr:
2802
4049
        free_pages((unsigned long)wl->aggr_buf, order);
2803
4050
 
2817
4064
int wl1271_free_hw(struct wl1271 *wl)
2818
4065
{
2819
4066
        platform_device_unregister(wl->plat_dev);
 
4067
        dev_kfree_skb(wl->dummy_packet);
2820
4068
        free_pages((unsigned long)wl->aggr_buf,
2821
4069
                        get_order(WL1271_AGGR_BUFFER_SIZE));
2822
4070
        kfree(wl->plat_dev);
2837
4085
}
2838
4086
EXPORT_SYMBOL_GPL(wl1271_free_hw);
2839
4087
 
2840
 
u32 wl12xx_debug_level;
 
4088
u32 wl12xx_debug_level = DEBUG_NONE;
2841
4089
EXPORT_SYMBOL_GPL(wl12xx_debug_level);
2842
 
module_param_named(debug_level, wl12xx_debug_level, uint, DEBUG_NONE);
 
4090
module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
2843
4091
MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
2844
4092
 
2845
4093
MODULE_LICENSE("GPL");
2846
 
MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
 
4094
MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
2847
4095
MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");