2 * NXP Wireless LAN device driver: major functions
4 * Copyright 2011-2020 NXP
6 * This software file (the "File") is distributed by NXP
7 * under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include <linux/suspend.h>
28 #define MFG_FIRMWARE "mwifiex_mfg.bin"
30 static unsigned int debug_mask
= MWIFIEX_DEFAULT_DEBUG_MASK
;
31 module_param(debug_mask
, uint
, 0);
32 MODULE_PARM_DESC(debug_mask
, "bitmap for debug flags");
34 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
35 static char *cal_data_cfg
;
36 module_param(cal_data_cfg
, charp
, 0);
38 static unsigned short driver_mode
;
39 module_param(driver_mode
, ushort
, 0);
40 MODULE_PARM_DESC(driver_mode
,
41 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
44 module_param(mfg_mode
, bool, 0);
45 MODULE_PARM_DESC(mfg_mode
, "manufacturing mode enable:1, disable:0");
48 module_param(aggr_ctrl
, bool, 0000);
49 MODULE_PARM_DESC(aggr_ctrl
, "usb tx aggregation enable:1, disable:0");
52 * This function registers the device and performs all the necessary
55 * The following initialization operations are performed -
56 * - Allocate adapter structure
57 * - Save interface specific operations table in adapter
58 * - Call interface specific initialization routine
59 * - Allocate private structures
60 * - Set default adapter structure parameters
63 * In case of any errors during inittialization, this function also ensures
64 * proper cleanup before exiting.
66 static int mwifiex_register(void *card
, struct device
*dev
,
67 struct mwifiex_if_ops
*if_ops
, void **padapter
)
69 struct mwifiex_adapter
*adapter
;
72 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
80 /* Save interface specific operations in adapter */
81 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
82 adapter
->debug_mask
= debug_mask
;
84 /* card specific initialization has been deferred until now .. */
85 if (adapter
->if_ops
.init_if
)
86 if (adapter
->if_ops
.init_if(adapter
))
89 adapter
->priv_num
= 0;
91 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
92 /* Allocate memory for private structure */
94 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
95 if (!adapter
->priv
[i
])
98 adapter
->priv
[i
]->adapter
= adapter
;
101 mwifiex_init_lock_list(adapter
);
103 timer_setup(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
, 0);
108 mwifiex_dbg(adapter
, ERROR
,
109 "info: leave mwifiex_register with error\n");
111 for (i
= 0; i
< adapter
->priv_num
; i
++)
112 kfree(adapter
->priv
[i
]);
120 * This function unregisters the device and performs all the necessary
123 * The following cleanup operations are performed -
125 * - Free beacon buffers
126 * - Free private structures
127 * - Free adapter structure
129 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
133 if (adapter
->if_ops
.cleanup_if
)
134 adapter
->if_ops
.cleanup_if(adapter
);
136 del_timer_sync(&adapter
->cmd_timer
);
138 /* Free private structures */
139 for (i
= 0; i
< adapter
->priv_num
; i
++) {
140 if (adapter
->priv
[i
]) {
141 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
142 kfree(adapter
->priv
[i
]);
146 if (adapter
->nd_info
) {
147 for (i
= 0 ; i
< adapter
->nd_info
->n_matches
; i
++)
148 kfree(adapter
->nd_info
->matches
[i
]);
149 kfree(adapter
->nd_info
);
150 adapter
->nd_info
= NULL
;
153 kfree(adapter
->regd
);
159 void mwifiex_queue_main_work(struct mwifiex_adapter
*adapter
)
163 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
164 if (adapter
->mwifiex_processing
) {
165 adapter
->more_task_flag
= true;
166 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
168 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
169 queue_work(adapter
->workqueue
, &adapter
->main_work
);
172 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work
);
174 static void mwifiex_queue_rx_work(struct mwifiex_adapter
*adapter
)
176 spin_lock_bh(&adapter
->rx_proc_lock
);
177 if (adapter
->rx_processing
) {
178 spin_unlock_bh(&adapter
->rx_proc_lock
);
180 spin_unlock_bh(&adapter
->rx_proc_lock
);
181 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
185 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
188 struct mwifiex_rxinfo
*rx_info
;
190 spin_lock_bh(&adapter
->rx_proc_lock
);
191 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
192 spin_unlock_bh(&adapter
->rx_proc_lock
);
195 adapter
->rx_processing
= true;
196 spin_unlock_bh(&adapter
->rx_proc_lock
);
199 /* Check for Rx data */
200 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
201 atomic_dec(&adapter
->rx_pending
);
202 if ((adapter
->delay_main_work
||
203 adapter
->iface_type
== MWIFIEX_USB
) &&
204 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
205 if (adapter
->if_ops
.submit_rem_rx_urbs
)
206 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
207 adapter
->delay_main_work
= false;
208 mwifiex_queue_main_work(adapter
);
210 rx_info
= MWIFIEX_SKB_RXCB(skb
);
211 if (rx_info
->buf_type
== MWIFIEX_TYPE_AGGR_DATA
) {
212 if (adapter
->if_ops
.deaggr_pkt
)
213 adapter
->if_ops
.deaggr_pkt(adapter
, skb
);
214 dev_kfree_skb_any(skb
);
216 mwifiex_handle_rx_packet(adapter
, skb
);
219 spin_lock_bh(&adapter
->rx_proc_lock
);
220 adapter
->rx_processing
= false;
221 spin_unlock_bh(&adapter
->rx_proc_lock
);
230 * This function is the main procedure of the driver and handles various driver
231 * operations. It runs in a loop and provides the core functionalities.
233 * The main responsibilities of this function are -
234 * - Ensure concurrency control
235 * - Handle pending interrupts and call interrupt handlers
236 * - Wake up the card if required
237 * - Handle command responses and call response handlers
238 * - Handle events and call event handlers
239 * - Execute pending commands
240 * - Transmit pending data packets
242 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
247 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
249 /* Check if already processing */
250 if (adapter
->mwifiex_processing
|| adapter
->main_locked
) {
251 adapter
->more_task_flag
= true;
252 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
255 adapter
->mwifiex_processing
= true;
256 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
260 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
263 /* For non-USB interfaces, If we process interrupts first, it
264 * would increase RX pending even further. Avoid this by
265 * checking if rx_pending has crossed high threshold and
266 * schedule rx work queue and then process interrupts.
267 * For USB interface, there are no interrupts. We already have
268 * HIGH_RX_PENDING check in usb.c
270 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
271 adapter
->iface_type
!= MWIFIEX_USB
) {
272 adapter
->delay_main_work
= true;
273 mwifiex_queue_rx_work(adapter
);
277 /* Handle pending interrupt if any */
278 if (adapter
->int_status
) {
279 if (adapter
->hs_activated
)
280 mwifiex_process_hs_config(adapter
);
281 if (adapter
->if_ops
.process_int_status
)
282 adapter
->if_ops
.process_int_status(adapter
);
285 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
286 mwifiex_queue_rx_work(adapter
);
288 /* Need to wake up the card ? */
289 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
290 (adapter
->pm_wakeup_card_req
&&
291 !adapter
->pm_wakeup_fw_try
) &&
292 (is_command_pending(adapter
) ||
293 !skb_queue_empty(&adapter
->tx_data_q
) ||
294 !mwifiex_bypass_txlist_empty(adapter
) ||
295 !mwifiex_wmm_lists_empty(adapter
))) {
296 adapter
->pm_wakeup_fw_try
= true;
297 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
298 adapter
->if_ops
.wakeup(adapter
);
302 if (IS_CARD_RX_RCVD(adapter
)) {
303 adapter
->data_received
= false;
304 adapter
->pm_wakeup_fw_try
= false;
305 del_timer(&adapter
->wakeup_timer
);
306 if (adapter
->ps_state
== PS_STATE_SLEEP
)
307 adapter
->ps_state
= PS_STATE_AWAKE
;
309 /* We have tried to wakeup the card already */
310 if (adapter
->pm_wakeup_fw_try
)
312 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
313 mwifiex_check_ps_cond(adapter
);
315 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
317 if (adapter
->tx_lock_flag
) {
318 if (adapter
->iface_type
== MWIFIEX_USB
) {
319 if (!adapter
->usb_mc_setup
)
325 if ((!adapter
->scan_chan_gap_enabled
&&
326 adapter
->scan_processing
) || adapter
->data_sent
||
327 mwifiex_is_tdls_chan_switching
328 (mwifiex_get_priv(adapter
,
329 MWIFIEX_BSS_ROLE_STA
)) ||
330 (mwifiex_wmm_lists_empty(adapter
) &&
331 mwifiex_bypass_txlist_empty(adapter
) &&
332 skb_queue_empty(&adapter
->tx_data_q
))) {
333 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
334 !mwifiex_is_send_cmd_allowed
335 (mwifiex_get_priv(adapter
,
336 MWIFIEX_BSS_ROLE_STA
)) ||
337 (!is_command_pending(adapter
)))
342 /* Check for event */
343 if (adapter
->event_received
) {
344 adapter
->event_received
= false;
345 mwifiex_process_event(adapter
);
348 /* Check for Cmd Resp */
349 if (adapter
->cmd_resp_received
) {
350 adapter
->cmd_resp_received
= false;
351 mwifiex_process_cmdresp(adapter
);
353 /* call mwifiex back when init_fw is done */
354 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
355 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
356 mwifiex_init_fw_complete(adapter
);
360 /* Check if we need to confirm Sleep Request
361 received previously */
362 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
363 mwifiex_check_ps_cond(adapter
);
365 /* * The ps_state may have been changed during processing of
366 * Sleep Request event.
368 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
369 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
370 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)) {
374 if (adapter
->tx_lock_flag
) {
375 if (adapter
->iface_type
== MWIFIEX_USB
) {
376 if (!adapter
->usb_mc_setup
)
382 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
383 mwifiex_is_send_cmd_allowed
384 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
385 if (mwifiex_exec_next_cmd(adapter
) == -1) {
391 /** If USB Multi channel setup ongoing,
392 * wait for ready to tx data.
394 if (adapter
->iface_type
== MWIFIEX_USB
&&
395 adapter
->usb_mc_setup
)
398 if ((adapter
->scan_chan_gap_enabled
||
399 !adapter
->scan_processing
) &&
400 !adapter
->data_sent
&&
401 !skb_queue_empty(&adapter
->tx_data_q
)) {
402 mwifiex_process_tx_queue(adapter
);
403 if (adapter
->hs_activated
) {
404 clear_bit(MWIFIEX_IS_HS_CONFIGURED
,
405 &adapter
->work_flags
);
406 mwifiex_hs_activated_event
408 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
413 if ((adapter
->scan_chan_gap_enabled
||
414 !adapter
->scan_processing
) &&
415 !adapter
->data_sent
&&
416 !mwifiex_bypass_txlist_empty(adapter
) &&
417 !mwifiex_is_tdls_chan_switching
418 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
419 mwifiex_process_bypass_tx(adapter
);
420 if (adapter
->hs_activated
) {
421 clear_bit(MWIFIEX_IS_HS_CONFIGURED
,
422 &adapter
->work_flags
);
423 mwifiex_hs_activated_event
425 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
430 if ((adapter
->scan_chan_gap_enabled
||
431 !adapter
->scan_processing
) &&
432 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
) &&
433 !mwifiex_is_tdls_chan_switching
434 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
435 mwifiex_wmm_process_tx(adapter
);
436 if (adapter
->hs_activated
) {
437 clear_bit(MWIFIEX_IS_HS_CONFIGURED
,
438 &adapter
->work_flags
);
439 mwifiex_hs_activated_event
441 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
446 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
447 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
448 (mwifiex_wmm_lists_empty(adapter
) &&
449 mwifiex_bypass_txlist_empty(adapter
) &&
450 skb_queue_empty(&adapter
->tx_data_q
))) {
451 if (!mwifiex_send_null_packet
452 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
453 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
454 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
455 adapter
->delay_null_pkt
= false;
456 adapter
->ps_state
= PS_STATE_SLEEP
;
462 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
463 if (adapter
->more_task_flag
) {
464 adapter
->more_task_flag
= false;
465 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
468 adapter
->mwifiex_processing
= false;
469 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
473 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
476 * This function frees the adapter structure.
478 * Additionally, this closes the netlink socket, frees the timers
479 * and private structures.
481 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
484 pr_err("%s: adapter is NULL\n", __func__
);
488 mwifiex_unregister(adapter
);
489 pr_debug("info: %s: free adapter\n", __func__
);
493 * This function cancels all works in the queue and destroys
494 * the main workqueue.
496 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
498 if (adapter
->workqueue
) {
499 flush_workqueue(adapter
->workqueue
);
500 destroy_workqueue(adapter
->workqueue
);
501 adapter
->workqueue
= NULL
;
504 if (adapter
->rx_workqueue
) {
505 flush_workqueue(adapter
->rx_workqueue
);
506 destroy_workqueue(adapter
->rx_workqueue
);
507 adapter
->rx_workqueue
= NULL
;
512 * This function gets firmware and initializes it.
514 * The main initialization steps followed are -
515 * - Download the correct firmware to card
516 * - Issue the init commands to firmware
518 static int _mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
522 struct mwifiex_adapter
*adapter
= context
;
523 struct mwifiex_fw_image fw
;
524 bool init_failed
= false;
525 struct wireless_dev
*wdev
;
526 struct completion
*fw_done
= adapter
->fw_done
;
529 mwifiex_dbg(adapter
, ERROR
,
530 "Failed to get firmware %s\n", adapter
->fw_name
);
534 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
535 adapter
->firmware
= firmware
;
536 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
537 fw
.fw_len
= adapter
->firmware
->size
;
539 if (adapter
->if_ops
.dnld_fw
) {
540 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
542 ret
= mwifiex_dnld_fw(adapter
, &fw
);
548 mwifiex_dbg(adapter
, MSG
, "WLAN FW is active\n");
551 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
553 mwifiex_dbg(adapter
, ERROR
,
554 "Cal data request_firmware() failed\n");
557 /* enable host interrupt after fw dnld is successful */
558 if (adapter
->if_ops
.enable_int
) {
559 if (adapter
->if_ops
.enable_int(adapter
))
563 adapter
->init_wait_q_woken
= false;
564 ret
= mwifiex_init_fw(adapter
);
568 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
571 /* Wait for mwifiex_init to complete */
572 if (!adapter
->mfg_mode
) {
573 wait_event_interruptible(adapter
->init_wait_q
,
574 adapter
->init_wait_q_woken
);
575 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
579 if (!adapter
->wiphy
) {
580 if (mwifiex_register_cfg80211(adapter
)) {
581 mwifiex_dbg(adapter
, ERROR
,
582 "cannot register with cfg80211\n");
587 if (mwifiex_init_channel_scan_gap(adapter
)) {
588 mwifiex_dbg(adapter
, ERROR
,
589 "could not init channel stats table\n");
590 goto err_init_chan_scan
;
594 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
595 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
599 /* Create station interface by default */
600 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d", NET_NAME_ENUM
,
601 NL80211_IFTYPE_STATION
, NULL
);
603 mwifiex_dbg(adapter
, ERROR
,
604 "cannot create default STA interface\n");
609 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
610 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d", NET_NAME_ENUM
,
611 NL80211_IFTYPE_AP
, NULL
);
613 mwifiex_dbg(adapter
, ERROR
,
614 "cannot create AP interface\n");
620 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
621 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d", NET_NAME_ENUM
,
622 NL80211_IFTYPE_P2P_CLIENT
, NULL
);
624 mwifiex_dbg(adapter
, ERROR
,
625 "cannot create p2p client interface\n");
632 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
633 mwifiex_dbg(adapter
, MSG
, "driver_version = %s\n", fmt
);
634 adapter
->is_up
= true;
638 vfree(adapter
->chan_stats
);
640 wiphy_unregister(adapter
->wiphy
);
641 wiphy_free(adapter
->wiphy
);
643 if (adapter
->if_ops
.disable_int
)
644 adapter
->if_ops
.disable_int(adapter
);
646 mwifiex_dbg(adapter
, ERROR
,
647 "info: %s: unregister device\n", __func__
);
648 if (adapter
->if_ops
.unregister_dev
)
649 adapter
->if_ops
.unregister_dev(adapter
);
651 set_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
652 mwifiex_terminate_workqueue(adapter
);
654 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
655 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
656 mwifiex_shutdown_drv(adapter
);
657 mwifiex_free_cmd_buffers(adapter
);
662 if (adapter
->cal_data
) {
663 release_firmware(adapter
->cal_data
);
664 adapter
->cal_data
= NULL
;
666 if (adapter
->firmware
) {
667 release_firmware(adapter
->firmware
);
668 adapter
->firmware
= NULL
;
671 if (adapter
->irq_wakeup
>= 0)
672 device_init_wakeup(adapter
->dev
, false);
673 mwifiex_free_adapter(adapter
);
675 /* Tell all current and future waiters we're finished */
676 complete_all(fw_done
);
678 return init_failed
? -EIO
: 0;
681 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
683 _mwifiex_fw_dpc(firmware
, context
);
687 * This function gets the firmware and (if called asynchronously) kicks off the
690 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
,
695 /* Override default firmware with manufacturing one if
696 * manufacturing mode is enabled
699 if (strlcpy(adapter
->fw_name
, MFG_FIRMWARE
,
700 sizeof(adapter
->fw_name
)) >=
701 sizeof(adapter
->fw_name
)) {
702 pr_err("%s: fw_name too long!\n", __func__
);
708 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
709 adapter
->dev
, GFP_KERNEL
, adapter
,
712 ret
= request_firmware(&adapter
->firmware
,
718 mwifiex_dbg(adapter
, ERROR
, "request_firmware%s error %d\n",
719 req_fw_nowait
? "_nowait" : "", ret
);
724 * CFG802.11 network device handler for open.
726 * Starts the data queue.
729 mwifiex_open(struct net_device
*dev
)
731 netif_carrier_off(dev
);
737 * CFG802.11 network device handler for close.
740 mwifiex_close(struct net_device
*dev
)
742 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
744 if (priv
->scan_request
) {
745 struct cfg80211_scan_info info
= {
749 mwifiex_dbg(priv
->adapter
, INFO
,
750 "aborting scan on ndo_stop\n");
751 cfg80211_scan_done(priv
->scan_request
, &info
);
752 priv
->scan_request
= NULL
;
753 priv
->scan_aborting
= true;
756 if (priv
->sched_scanning
) {
757 mwifiex_dbg(priv
->adapter
, INFO
,
758 "aborting bgscan on ndo_stop\n");
759 mwifiex_stop_bg_scan(priv
);
760 cfg80211_sched_scan_stopped(priv
->wdev
.wiphy
, 0);
767 mwifiex_bypass_tx_queue(struct mwifiex_private
*priv
,
770 struct ethhdr
*eth_hdr
= (struct ethhdr
*)skb
->data
;
772 if (ntohs(eth_hdr
->h_proto
) == ETH_P_PAE
||
773 mwifiex_is_skb_mgmt_frame(skb
) ||
774 (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
&&
775 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
776 (ntohs(eth_hdr
->h_proto
) == ETH_P_TDLS
))) {
777 mwifiex_dbg(priv
->adapter
, DATA
,
778 "bypass txqueue; eth type %#x, mgmt %d\n",
779 ntohs(eth_hdr
->h_proto
),
780 mwifiex_is_skb_mgmt_frame(skb
));
787 * Add buffer into wmm tx queue and queue work to transmit it.
789 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
791 struct netdev_queue
*txq
;
792 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
794 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
795 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
796 if (!netif_tx_queue_stopped(txq
)) {
797 netif_tx_stop_queue(txq
);
798 mwifiex_dbg(priv
->adapter
, DATA
,
799 "stop queue: %d\n", index
);
803 if (mwifiex_bypass_tx_queue(priv
, skb
)) {
804 atomic_inc(&priv
->adapter
->tx_pending
);
805 atomic_inc(&priv
->adapter
->bypass_tx_pending
);
806 mwifiex_wmm_add_buf_bypass_txqueue(priv
, skb
);
808 atomic_inc(&priv
->adapter
->tx_pending
);
809 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
812 mwifiex_queue_main_work(priv
->adapter
);
818 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
819 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
821 struct sk_buff
*orig_skb
= skb
;
822 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
824 skb
= skb_clone(skb
, GFP_ATOMIC
);
828 spin_lock_bh(&priv
->ack_status_lock
);
829 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
830 1, 0x10, GFP_ATOMIC
);
831 spin_unlock_bh(&priv
->ack_status_lock
);
834 tx_info
= MWIFIEX_SKB_TXCB(skb
);
835 tx_info
->ack_frame_id
= id
;
836 tx_info
->flags
|= flag
;
837 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
838 orig_tx_info
->ack_frame_id
= id
;
839 orig_tx_info
->flags
|= flag
;
841 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
842 orig_tx_info
->cookie
= *cookie
;
844 } else if (skb_shared(skb
)) {
851 /* couldn't clone -- lose tx status ... */
859 * CFG802.11 network device handler for data transmission.
862 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
864 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
865 struct sk_buff
*new_skb
;
866 struct mwifiex_txinfo
*tx_info
;
869 mwifiex_dbg(priv
->adapter
, DATA
,
870 "data: %lu BSS(%d-%d): Data <= kernel\n",
871 jiffies
, priv
->bss_type
, priv
->bss_num
);
873 if (test_bit(MWIFIEX_SURPRISE_REMOVED
, &priv
->adapter
->work_flags
)) {
875 priv
->stats
.tx_dropped
++;
878 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
879 mwifiex_dbg(priv
->adapter
, ERROR
,
880 "Tx: bad skb len %d\n", skb
->len
);
882 priv
->stats
.tx_dropped
++;
885 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
886 mwifiex_dbg(priv
->adapter
, DATA
,
887 "data: Tx: insufficient skb headroom %d\n",
889 /* Insufficient skb headroom - allocate a new skb */
891 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
892 if (unlikely(!new_skb
)) {
893 mwifiex_dbg(priv
->adapter
, ERROR
,
894 "Tx: cannot alloca new_skb\n");
896 priv
->stats
.tx_dropped
++;
901 mwifiex_dbg(priv
->adapter
, INFO
,
902 "info: new skb headroomd %d\n",
906 tx_info
= MWIFIEX_SKB_TXCB(skb
);
907 memset(tx_info
, 0, sizeof(*tx_info
));
908 tx_info
->bss_num
= priv
->bss_num
;
909 tx_info
->bss_type
= priv
->bss_type
;
910 tx_info
->pkt_len
= skb
->len
;
912 multicast
= is_multicast_ether_addr(skb
->data
);
914 if (unlikely(!multicast
&& skb
->sk
&&
915 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
916 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
917 skb
= mwifiex_clone_skb_for_tx_status(priv
,
919 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
921 /* Record the current time the packet was queued; used to
922 * determine the amount of time the packet was queued in
923 * the driver before it was sent to the firmware.
924 * The delay is then sent along with the packet to the
925 * firmware for aggregate delay calculation for stats and
926 * MSDU lifetime expiry.
928 __net_timestamp(skb
);
930 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
931 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
932 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
933 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
934 mwifiex_tdls_check_tx(priv
, skb
);
937 mwifiex_queue_tx_pkt(priv
, skb
);
942 int mwifiex_set_mac_address(struct mwifiex_private
*priv
,
943 struct net_device
*dev
, bool external
,
947 u64 mac_addr
, old_mac_addr
;
949 old_mac_addr
= ether_addr_to_u64(priv
->curr_addr
);
952 mac_addr
= ether_addr_to_u64(new_mac
);
954 /* Internal mac address change */
955 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_ANY
)
958 mac_addr
= old_mac_addr
;
960 if (priv
->bss_type
== MWIFIEX_BSS_TYPE_P2P
) {
961 mac_addr
|= BIT_ULL(MWIFIEX_MAC_LOCAL_ADMIN_BIT
);
962 mac_addr
+= priv
->bss_num
;
963 } else if (priv
->adapter
->priv
[0] != priv
) {
964 /* Set mac address based on bss_type/bss_num */
965 mac_addr
^= BIT_ULL(priv
->bss_type
+ 8);
966 mac_addr
+= priv
->bss_num
;
970 u64_to_ether_addr(mac_addr
, priv
->curr_addr
);
972 /* Send request to firmware */
973 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
974 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
977 u64_to_ether_addr(old_mac_addr
, priv
->curr_addr
);
978 mwifiex_dbg(priv
->adapter
, ERROR
,
979 "set mac address failed: ret=%d\n", ret
);
983 ether_addr_copy(dev
->dev_addr
, priv
->curr_addr
);
987 /* CFG802.11 network device handler for setting MAC address.
990 mwifiex_ndo_set_mac_address(struct net_device
*dev
, void *addr
)
992 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
993 struct sockaddr
*hw_addr
= addr
;
995 return mwifiex_set_mac_address(priv
, dev
, true, hw_addr
->sa_data
);
999 * CFG802.11 network device handler for setting multicast list.
1001 static void mwifiex_set_multicast_list(struct net_device
*dev
)
1003 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1004 struct mwifiex_multicast_list mcast_list
;
1006 if (dev
->flags
& IFF_PROMISC
) {
1007 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
1008 } else if (dev
->flags
& IFF_ALLMULTI
||
1009 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
1010 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
1012 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
1013 mcast_list
.num_multicast_addr
=
1014 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
1016 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
1020 * CFG802.11 network device handler for transmission timeout.
1023 mwifiex_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
1025 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1027 priv
->num_tx_timeout
++;
1028 priv
->tx_timeout_cnt
++;
1029 mwifiex_dbg(priv
->adapter
, ERROR
,
1030 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
1031 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
,
1033 mwifiex_set_trans_start(dev
);
1035 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
1036 priv
->adapter
->if_ops
.card_reset
) {
1037 mwifiex_dbg(priv
->adapter
, ERROR
,
1038 "tx_timeout_cnt exceeds threshold.\t"
1039 "Triggering card reset!\n");
1040 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
1044 void mwifiex_multi_chan_resync(struct mwifiex_adapter
*adapter
)
1046 struct usb_card_rec
*card
= adapter
->card
;
1047 struct mwifiex_private
*priv
;
1051 card
->mc_resync_flag
= true;
1052 for (i
= 0; i
< MWIFIEX_TX_DATA_PORT
; i
++) {
1053 if (atomic_read(&card
->port
[i
].tx_data_urb_pending
)) {
1054 mwifiex_dbg(adapter
, WARN
, "pending data urb in sys\n");
1059 card
->mc_resync_flag
= false;
1060 tx_buf_size
= 0xffff;
1061 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1062 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_RECONFIGURE_TX_BUFF
,
1063 HostCmd_ACT_GEN_SET
, 0, &tx_buf_size
, false);
1065 mwifiex_dbg(adapter
, ERROR
,
1066 "send reconfig tx buf size cmd err\n");
1068 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync
);
1070 void mwifiex_upload_device_dump(struct mwifiex_adapter
*adapter
)
1072 /* Dump all the memory data into single file, a userspace script will
1073 * be used to split all the memory data to multiple files
1075 mwifiex_dbg(adapter
, MSG
,
1076 "== mwifiex dump information to /sys/class/devcoredump start\n");
1077 dev_coredumpv(adapter
->dev
, adapter
->devdump_data
, adapter
->devdump_len
,
1079 mwifiex_dbg(adapter
, MSG
,
1080 "== mwifiex dump information to /sys/class/devcoredump end\n");
1082 /* Device dump data will be freed in device coredump release function
1083 * after 5 min. Here reset adapter->devdump_data and ->devdump_len
1084 * to avoid it been accidentally reused.
1086 adapter
->devdump_data
= NULL
;
1087 adapter
->devdump_len
= 0;
1089 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump
);
1091 void mwifiex_drv_info_dump(struct mwifiex_adapter
*adapter
)
1094 char drv_version
[64];
1095 struct usb_card_rec
*cardp
;
1096 struct sdio_mmc_card
*sdio_card
;
1097 struct mwifiex_private
*priv
;
1099 struct netdev_queue
*txq
;
1100 struct mwifiex_debug_info
*debug_info
;
1102 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump start===\n");
1104 p
= adapter
->devdump_data
;
1105 strcpy(p
, "========Start dump driverinfo========\n");
1106 p
+= strlen("========Start dump driverinfo========\n");
1107 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
1109 mwifiex_drv_get_driver_version(adapter
, drv_version
,
1110 sizeof(drv_version
) - 1);
1111 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
1113 if (adapter
->iface_type
== MWIFIEX_USB
) {
1114 cardp
= (struct usb_card_rec
*)adapter
->card
;
1115 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
1116 atomic_read(&cardp
->tx_cmd_urb_pending
));
1117 p
+= sprintf(p
, "tx_data_urb_pending_port_0 = %d\n",
1118 atomic_read(&cardp
->port
[0].tx_data_urb_pending
));
1119 p
+= sprintf(p
, "tx_data_urb_pending_port_1 = %d\n",
1120 atomic_read(&cardp
->port
[1].tx_data_urb_pending
));
1121 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
1122 atomic_read(&cardp
->rx_cmd_urb_pending
));
1123 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
1124 atomic_read(&cardp
->rx_data_urb_pending
));
1127 p
+= sprintf(p
, "tx_pending = %d\n",
1128 atomic_read(&adapter
->tx_pending
));
1129 p
+= sprintf(p
, "rx_pending = %d\n",
1130 atomic_read(&adapter
->rx_pending
));
1132 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1133 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
1134 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1135 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
1136 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1137 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
1140 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1141 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1143 priv
= adapter
->priv
[i
];
1144 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
1145 priv
->netdev
->name
);
1146 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
1147 atomic_read(&priv
->wmm_tx_pending
[0]));
1148 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
1149 atomic_read(&priv
->wmm_tx_pending
[1]));
1150 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
1151 atomic_read(&priv
->wmm_tx_pending
[2]));
1152 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
1153 atomic_read(&priv
->wmm_tx_pending
[3]));
1154 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
1155 "Disconnected" : "Connected");
1156 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
1158 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
1159 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
1160 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
1161 netif_tx_queue_stopped(txq
) ?
1162 "stopped" : "started");
1164 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
1165 priv
->netdev
->name
, priv
->num_tx_timeout
);
1168 if (adapter
->iface_type
== MWIFIEX_SDIO
||
1169 adapter
->iface_type
== MWIFIEX_PCIE
) {
1170 p
+= sprintf(p
, "\n=== %s register dump===\n",
1171 adapter
->iface_type
== MWIFIEX_SDIO
?
1173 if (adapter
->if_ops
.reg_dump
)
1174 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
1176 p
+= sprintf(p
, "\n=== more debug information\n");
1177 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
1179 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1180 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1182 priv
= adapter
->priv
[i
];
1183 mwifiex_get_debug_info(priv
, debug_info
);
1184 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
1190 strcpy(p
, "\n========End dump========\n");
1191 p
+= strlen("\n========End dump========\n");
1192 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump end===\n");
1193 adapter
->devdump_len
= p
- (char *)adapter
->devdump_data
;
1195 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump
);
1197 void mwifiex_prepare_fw_dump_info(struct mwifiex_adapter
*adapter
)
1203 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1204 struct memory_type_mapping
*entry
=
1205 &adapter
->mem_type_mapping_tbl
[idx
];
1207 if (entry
->mem_ptr
) {
1208 dump_len
+= (strlen("========Start dump ") +
1209 strlen(entry
->mem_name
) +
1210 strlen("========\n") +
1211 (entry
->mem_size
+ 1) +
1212 strlen("\n========End dump========\n"));
1216 if (dump_len
+ 1 + adapter
->devdump_len
> MWIFIEX_FW_DUMP_SIZE
) {
1217 /* Realloc in case buffer overflow */
1218 fw_dump_ptr
= vzalloc(dump_len
+ 1 + adapter
->devdump_len
);
1219 mwifiex_dbg(adapter
, MSG
, "Realloc device dump data.\n");
1221 vfree(adapter
->devdump_data
);
1222 mwifiex_dbg(adapter
, ERROR
,
1223 "vzalloc devdump data failure!\n");
1227 memmove(fw_dump_ptr
, adapter
->devdump_data
,
1228 adapter
->devdump_len
);
1229 vfree(adapter
->devdump_data
);
1230 adapter
->devdump_data
= fw_dump_ptr
;
1233 fw_dump_ptr
= (char *)adapter
->devdump_data
+ adapter
->devdump_len
;
1235 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1236 struct memory_type_mapping
*entry
=
1237 &adapter
->mem_type_mapping_tbl
[idx
];
1239 if (entry
->mem_ptr
) {
1240 strcpy(fw_dump_ptr
, "========Start dump ");
1241 fw_dump_ptr
+= strlen("========Start dump ");
1243 strcpy(fw_dump_ptr
, entry
->mem_name
);
1244 fw_dump_ptr
+= strlen(entry
->mem_name
);
1246 strcpy(fw_dump_ptr
, "========\n");
1247 fw_dump_ptr
+= strlen("========\n");
1249 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1250 fw_dump_ptr
+= entry
->mem_size
;
1252 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1253 fw_dump_ptr
+= strlen("\n========End dump========\n");
1257 adapter
->devdump_len
= fw_dump_ptr
- (char *)adapter
->devdump_data
;
1259 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1260 struct memory_type_mapping
*entry
=
1261 &adapter
->mem_type_mapping_tbl
[idx
];
1263 vfree(entry
->mem_ptr
);
1264 entry
->mem_ptr
= NULL
;
1265 entry
->mem_size
= 0;
1268 EXPORT_SYMBOL_GPL(mwifiex_prepare_fw_dump_info
);
1271 * CFG802.11 network device handler for statistics retrieval.
1273 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
1275 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1277 return &priv
->stats
;
1281 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1282 struct net_device
*sb_dev
)
1284 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1285 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
1288 /* Network device handlers */
1289 static const struct net_device_ops mwifiex_netdev_ops
= {
1290 .ndo_open
= mwifiex_open
,
1291 .ndo_stop
= mwifiex_close
,
1292 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
1293 .ndo_set_mac_address
= mwifiex_ndo_set_mac_address
,
1294 .ndo_validate_addr
= eth_validate_addr
,
1295 .ndo_tx_timeout
= mwifiex_tx_timeout
,
1296 .ndo_get_stats
= mwifiex_get_stats
,
1297 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
1298 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
1302 * This function initializes the private structure parameters.
1304 * The following wait queues are initialized -
1305 * - IOCTL wait queue
1306 * - Command wait queue
1307 * - Statistics wait queue
1309 * ...and the following default parameters are set -
1310 * - Current key index : Set to 0
1311 * - Rate index : Set to auto
1312 * - Media connected : Set to disconnected
1313 * - Adhoc link sensed : Set to false
1314 * - Nick name : Set to null
1315 * - Number of Tx timeout : Set to 0
1316 * - Device address : Set to current address
1317 * - Rx histogram statistc : Set to 0
1319 * In addition, the CFG80211 work queue is also created.
1321 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
1322 struct net_device
*dev
)
1324 dev
->netdev_ops
= &mwifiex_netdev_ops
;
1325 dev
->needs_free_netdev
= true;
1326 /* Initialize private structure */
1327 priv
->current_key_index
= 0;
1328 priv
->media_connected
= false;
1329 memset(priv
->mgmt_ie
, 0,
1330 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
1331 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
1332 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1333 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1334 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
1335 priv
->num_tx_timeout
= 0;
1336 if (is_valid_ether_addr(dev
->dev_addr
))
1337 ether_addr_copy(priv
->curr_addr
, dev
->dev_addr
);
1339 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
1341 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
1342 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
1343 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
1344 if (priv
->hist_data
)
1345 mwifiex_hist_data_reset(priv
);
1350 * This function check if command is pending.
1352 int is_command_pending(struct mwifiex_adapter
*adapter
)
1354 int is_cmd_pend_q_empty
;
1356 spin_lock_bh(&adapter
->cmd_pending_q_lock
);
1357 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1358 spin_unlock_bh(&adapter
->cmd_pending_q_lock
);
1360 return !is_cmd_pend_q_empty
;
1364 * This is the RX work queue function.
1366 * It handles the RX operations.
1368 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1370 struct mwifiex_adapter
*adapter
=
1371 container_of(work
, struct mwifiex_adapter
, rx_work
);
1373 if (test_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
))
1375 mwifiex_process_rx(adapter
);
1379 * This is the main work queue function.
1381 * It handles the main process, which in turn handles the complete
1382 * driver operations.
1384 static void mwifiex_main_work_queue(struct work_struct
*work
)
1386 struct mwifiex_adapter
*adapter
=
1387 container_of(work
, struct mwifiex_adapter
, main_work
);
1389 if (test_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
))
1391 mwifiex_main_process(adapter
);
1394 /* Common teardown code used for both device removal and reset */
1395 static void mwifiex_uninit_sw(struct mwifiex_adapter
*adapter
)
1397 struct mwifiex_private
*priv
;
1400 /* We can no longer handle interrupts once we start doing the teardown
1403 if (adapter
->if_ops
.disable_int
)
1404 adapter
->if_ops
.disable_int(adapter
);
1406 set_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
1407 mwifiex_terminate_workqueue(adapter
);
1408 adapter
->int_status
= 0;
1411 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1412 priv
= adapter
->priv
[i
];
1413 if (priv
&& priv
->netdev
) {
1414 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1415 if (netif_carrier_ok(priv
->netdev
))
1416 netif_carrier_off(priv
->netdev
);
1417 netif_device_detach(priv
->netdev
);
1421 mwifiex_dbg(adapter
, CMD
, "cmd: calling mwifiex_shutdown_drv...\n");
1422 mwifiex_shutdown_drv(adapter
);
1423 mwifiex_dbg(adapter
, CMD
, "cmd: mwifiex_shutdown_drv done\n");
1425 if (atomic_read(&adapter
->rx_pending
) ||
1426 atomic_read(&adapter
->tx_pending
) ||
1427 atomic_read(&adapter
->cmd_pending
)) {
1428 mwifiex_dbg(adapter
, ERROR
,
1429 "rx_pending=%d, tx_pending=%d,\t"
1431 atomic_read(&adapter
->rx_pending
),
1432 atomic_read(&adapter
->tx_pending
),
1433 atomic_read(&adapter
->cmd_pending
));
1436 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1437 priv
= adapter
->priv
[i
];
1442 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1443 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1447 wiphy_unregister(adapter
->wiphy
);
1448 wiphy_free(adapter
->wiphy
);
1449 adapter
->wiphy
= NULL
;
1451 vfree(adapter
->chan_stats
);
1452 mwifiex_free_cmd_buffers(adapter
);
1456 * This function gets called during PCIe function level reset.
1458 int mwifiex_shutdown_sw(struct mwifiex_adapter
*adapter
)
1460 struct mwifiex_private
*priv
;
1465 wait_for_completion(adapter
->fw_done
);
1466 /* Caller should ensure we aren't suspending while this happens */
1467 reinit_completion(adapter
->fw_done
);
1469 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1470 mwifiex_deauthenticate(priv
, NULL
);
1472 mwifiex_uninit_sw(adapter
);
1473 adapter
->is_up
= false;
1475 if (adapter
->if_ops
.down_dev
)
1476 adapter
->if_ops
.down_dev(adapter
);
1480 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw
);
1482 /* This function gets called during PCIe function level reset. Required
1483 * code is extracted from mwifiex_add_card()
1486 mwifiex_reinit_sw(struct mwifiex_adapter
*adapter
)
1490 mwifiex_init_lock_list(adapter
);
1491 if (adapter
->if_ops
.up_dev
)
1492 adapter
->if_ops
.up_dev(adapter
);
1494 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1495 clear_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
1496 init_waitqueue_head(&adapter
->init_wait_q
);
1497 clear_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
);
1498 adapter
->hs_activated
= false;
1499 clear_bit(MWIFIEX_IS_CMD_TIMEDOUT
, &adapter
->work_flags
);
1500 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1501 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1502 adapter
->cmd_wait_q
.status
= 0;
1503 adapter
->scan_wait_q_woken
= false;
1505 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
)
1506 adapter
->rx_work_enabled
= true;
1508 adapter
->workqueue
=
1509 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1510 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1511 if (!adapter
->workqueue
)
1514 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1516 if (adapter
->rx_work_enabled
) {
1517 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1521 if (!adapter
->rx_workqueue
)
1523 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1526 /* Register the device. Fill up the private data structure with
1527 * relevant information from the card. Some code extracted from
1528 * mwifiex_register_dev()
1530 mwifiex_dbg(adapter
, INFO
, "%s, mwifiex_init_hw_fw()...\n", __func__
);
1532 if (mwifiex_init_hw_fw(adapter
, false)) {
1533 mwifiex_dbg(adapter
, ERROR
,
1534 "%s: firmware init failed\n", __func__
);
1538 /* _mwifiex_fw_dpc() does its own cleanup */
1539 ret
= _mwifiex_fw_dpc(adapter
->firmware
, adapter
);
1541 pr_err("Failed to bring up adapter: %d\n", ret
);
1544 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1549 mwifiex_dbg(adapter
, ERROR
, "info: %s: unregister device\n", __func__
);
1550 if (adapter
->if_ops
.unregister_dev
)
1551 adapter
->if_ops
.unregister_dev(adapter
);
1554 set_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
1555 mwifiex_terminate_workqueue(adapter
);
1556 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1557 mwifiex_dbg(adapter
, ERROR
,
1558 "info: %s: shutdown mwifiex\n", __func__
);
1559 mwifiex_shutdown_drv(adapter
);
1560 mwifiex_free_cmd_buffers(adapter
);
1563 complete_all(adapter
->fw_done
);
1564 mwifiex_dbg(adapter
, INFO
, "%s, error\n", __func__
);
1568 EXPORT_SYMBOL_GPL(mwifiex_reinit_sw
);
1570 static irqreturn_t
mwifiex_irq_wakeup_handler(int irq
, void *priv
)
1572 struct mwifiex_adapter
*adapter
= priv
;
1574 dev_dbg(adapter
->dev
, "%s: wake by wifi", __func__
);
1575 adapter
->wake_by_wifi
= true;
1576 disable_irq_nosync(irq
);
1578 /* Notify PM core we are wakeup source */
1579 pm_wakeup_event(adapter
->dev
, 0);
1585 static void mwifiex_probe_of(struct mwifiex_adapter
*adapter
)
1588 struct device
*dev
= adapter
->dev
;
1593 adapter
->dt_node
= dev
->of_node
;
1594 adapter
->irq_wakeup
= irq_of_parse_and_map(adapter
->dt_node
, 0);
1595 if (!adapter
->irq_wakeup
) {
1596 dev_dbg(dev
, "fail to parse irq_wakeup from device tree\n");
1600 ret
= devm_request_irq(dev
, adapter
->irq_wakeup
,
1601 mwifiex_irq_wakeup_handler
, IRQF_TRIGGER_LOW
,
1602 "wifi_wake", adapter
);
1604 dev_err(dev
, "Failed to request irq_wakeup %d (%d)\n",
1605 adapter
->irq_wakeup
, ret
);
1609 disable_irq(adapter
->irq_wakeup
);
1610 if (device_init_wakeup(dev
, true)) {
1611 dev_err(dev
, "fail to init wakeup for mwifiex\n");
1617 adapter
->irq_wakeup
= -1;
1621 * This function adds the card.
1623 * This function follows the following major steps to set up the device -
1624 * - Initialize software. This includes probing the card, registering
1625 * the interface operations table, and allocating/initializing the
1627 * - Set up the netlink socket
1628 * - Create and start the main work queue
1629 * - Register the device
1630 * - Initialize firmware and hardware
1631 * - Add logical interfaces
1634 mwifiex_add_card(void *card
, struct completion
*fw_done
,
1635 struct mwifiex_if_ops
*if_ops
, u8 iface_type
,
1638 struct mwifiex_adapter
*adapter
;
1640 if (mwifiex_register(card
, dev
, if_ops
, (void **)&adapter
)) {
1641 pr_err("%s: software init failed\n", __func__
);
1645 mwifiex_probe_of(adapter
);
1647 adapter
->iface_type
= iface_type
;
1648 adapter
->fw_done
= fw_done
;
1650 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1651 clear_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
1652 init_waitqueue_head(&adapter
->init_wait_q
);
1653 clear_bit(MWIFIEX_IS_SUSPENDED
, &adapter
->work_flags
);
1654 adapter
->hs_activated
= false;
1655 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1656 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1657 adapter
->cmd_wait_q
.status
= 0;
1658 adapter
->scan_wait_q_woken
= false;
1660 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
)
1661 adapter
->rx_work_enabled
= true;
1663 adapter
->workqueue
=
1664 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1665 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1666 if (!adapter
->workqueue
)
1669 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1671 if (adapter
->rx_work_enabled
) {
1672 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1676 if (!adapter
->rx_workqueue
)
1679 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1682 /* Register the device. Fill up the private data structure with relevant
1683 information from the card. */
1684 if (adapter
->if_ops
.register_dev(adapter
)) {
1685 pr_err("%s: failed to register mwifiex device\n", __func__
);
1686 goto err_registerdev
;
1689 if (mwifiex_init_hw_fw(adapter
, true)) {
1690 pr_err("%s: firmware init failed\n", __func__
);
1697 pr_debug("info: %s: unregister device\n", __func__
);
1698 if (adapter
->if_ops
.unregister_dev
)
1699 adapter
->if_ops
.unregister_dev(adapter
);
1701 set_bit(MWIFIEX_SURPRISE_REMOVED
, &adapter
->work_flags
);
1702 mwifiex_terminate_workqueue(adapter
);
1703 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1704 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1705 mwifiex_shutdown_drv(adapter
);
1706 mwifiex_free_cmd_buffers(adapter
);
1709 if (adapter
->irq_wakeup
>= 0)
1710 device_init_wakeup(adapter
->dev
, false);
1711 mwifiex_free_adapter(adapter
);
1717 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1720 * This function removes the card.
1722 * This function follows the following major steps to remove the device -
1723 * - Stop data traffic
1724 * - Shutdown firmware
1725 * - Remove the logical interfaces
1726 * - Terminate the work queue
1727 * - Unregister the device
1728 * - Free the adapter structure
1730 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
)
1736 mwifiex_uninit_sw(adapter
);
1738 if (adapter
->irq_wakeup
>= 0)
1739 device_init_wakeup(adapter
->dev
, false);
1741 /* Unregister device */
1742 mwifiex_dbg(adapter
, INFO
,
1743 "info: unregister device\n");
1744 if (adapter
->if_ops
.unregister_dev
)
1745 adapter
->if_ops
.unregister_dev(adapter
);
1746 /* Free adapter structure */
1747 mwifiex_dbg(adapter
, INFO
,
1748 "info: free adapter\n");
1749 mwifiex_free_adapter(adapter
);
1753 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1755 void _mwifiex_dbg(const struct mwifiex_adapter
*adapter
, int mask
,
1756 const char *fmt
, ...)
1758 struct va_format vaf
;
1761 if (!(adapter
->debug_mask
& mask
))
1764 va_start(args
, fmt
);
1770 dev_info(adapter
->dev
, "%pV", &vaf
);
1772 pr_info("%pV", &vaf
);
1776 EXPORT_SYMBOL_GPL(_mwifiex_dbg
);
1779 * This function initializes the module.
1781 * The debug FS is also initialized if configured.
1784 mwifiex_init_module(void)
1786 #ifdef CONFIG_DEBUG_FS
1787 mwifiex_debugfs_init();
1793 * This function cleans up the module.
1795 * The debug FS is removed if available.
1798 mwifiex_cleanup_module(void)
1800 #ifdef CONFIG_DEBUG_FS
1801 mwifiex_debugfs_remove();
1805 module_init(mwifiex_init_module
);
1806 module_exit(mwifiex_cleanup_module
);
1808 MODULE_AUTHOR("Marvell International Ltd.");
1809 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1810 MODULE_VERSION(VERSION
);
1811 MODULE_LICENSE("GPL v2");