2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. 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.
27 static unsigned int debug_mask
= MWIFIEX_DEFAULT_DEBUG_MASK
;
28 module_param(debug_mask
, uint
, 0);
29 MODULE_PARM_DESC(debug_mask
, "bitmap for debug flags");
31 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
32 static char *cal_data_cfg
;
33 module_param(cal_data_cfg
, charp
, 0);
35 static unsigned short driver_mode
;
36 module_param(driver_mode
, ushort
, 0);
37 MODULE_PARM_DESC(driver_mode
,
38 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
41 * This function registers the device and performs all the necessary
44 * The following initialization operations are performed -
45 * - Allocate adapter structure
46 * - Save interface specific operations table in adapter
47 * - Call interface specific initialization routine
48 * - Allocate private structures
49 * - Set default adapter structure parameters
52 * In case of any errors during inittialization, this function also ensures
53 * proper cleanup before exiting.
55 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
58 struct mwifiex_adapter
*adapter
;
61 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
68 /* Save interface specific operations in adapter */
69 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
70 adapter
->debug_mask
= debug_mask
;
72 /* card specific initialization has been deferred until now .. */
73 if (adapter
->if_ops
.init_if
)
74 if (adapter
->if_ops
.init_if(adapter
))
77 adapter
->priv_num
= 0;
79 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
80 /* Allocate memory for private structure */
82 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
83 if (!adapter
->priv
[i
])
86 adapter
->priv
[i
]->adapter
= adapter
;
89 mwifiex_init_lock_list(adapter
);
91 setup_timer(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
,
92 (unsigned long)adapter
);
97 mwifiex_dbg(adapter
, ERROR
,
98 "info: leave mwifiex_register with error\n");
100 for (i
= 0; i
< adapter
->priv_num
; i
++)
101 kfree(adapter
->priv
[i
]);
109 * This function unregisters the device and performs all the necessary
112 * The following cleanup operations are performed -
114 * - Free beacon buffers
115 * - Free private structures
116 * - Free adapter structure
118 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
122 if (adapter
->if_ops
.cleanup_if
)
123 adapter
->if_ops
.cleanup_if(adapter
);
125 del_timer_sync(&adapter
->cmd_timer
);
127 /* Free private structures */
128 for (i
= 0; i
< adapter
->priv_num
; i
++) {
129 if (adapter
->priv
[i
]) {
130 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
131 kfree(adapter
->priv
[i
]);
135 vfree(adapter
->chan_stats
);
140 void mwifiex_queue_main_work(struct mwifiex_adapter
*adapter
)
144 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
145 if (adapter
->mwifiex_processing
) {
146 adapter
->more_task_flag
= true;
147 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
149 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
150 queue_work(adapter
->workqueue
, &adapter
->main_work
);
153 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work
);
155 static void mwifiex_queue_rx_work(struct mwifiex_adapter
*adapter
)
159 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
160 if (adapter
->rx_processing
) {
161 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
163 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
164 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
168 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
172 struct mwifiex_rxinfo
*rx_info
;
174 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
175 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
176 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
179 adapter
->rx_processing
= true;
180 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
183 /* Check for Rx data */
184 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
185 atomic_dec(&adapter
->rx_pending
);
186 if ((adapter
->delay_main_work
||
187 adapter
->iface_type
== MWIFIEX_USB
) &&
188 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
189 if (adapter
->if_ops
.submit_rem_rx_urbs
)
190 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
191 adapter
->delay_main_work
= false;
192 mwifiex_queue_main_work(adapter
);
194 rx_info
= MWIFIEX_SKB_RXCB(skb
);
195 if (rx_info
->buf_type
== MWIFIEX_TYPE_AGGR_DATA
) {
196 if (adapter
->if_ops
.deaggr_pkt
)
197 adapter
->if_ops
.deaggr_pkt(adapter
, skb
);
198 dev_kfree_skb_any(skb
);
200 mwifiex_handle_rx_packet(adapter
, skb
);
203 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
204 adapter
->rx_processing
= false;
205 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
214 * This function is the main procedure of the driver and handles various driver
215 * operations. It runs in a loop and provides the core functionalities.
217 * The main responsibilities of this function are -
218 * - Ensure concurrency control
219 * - Handle pending interrupts and call interrupt handlers
220 * - Wake up the card if required
221 * - Handle command responses and call response handlers
222 * - Handle events and call event handlers
223 * - Execute pending commands
224 * - Transmit pending data packets
226 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
231 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
233 /* Check if already processing */
234 if (adapter
->mwifiex_processing
|| adapter
->main_locked
) {
235 adapter
->more_task_flag
= true;
236 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
239 adapter
->mwifiex_processing
= true;
240 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
244 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
245 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
248 /* For non-USB interfaces, If we process interrupts first, it
249 * would increase RX pending even further. Avoid this by
250 * checking if rx_pending has crossed high threshold and
251 * schedule rx work queue and then process interrupts.
252 * For USB interface, there are no interrupts. We already have
253 * HIGH_RX_PENDING check in usb.c
255 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
256 adapter
->iface_type
!= MWIFIEX_USB
) {
257 adapter
->delay_main_work
= true;
258 mwifiex_queue_rx_work(adapter
);
262 /* Handle pending interrupt if any */
263 if (adapter
->int_status
) {
264 if (adapter
->hs_activated
)
265 mwifiex_process_hs_config(adapter
);
266 if (adapter
->if_ops
.process_int_status
)
267 adapter
->if_ops
.process_int_status(adapter
);
270 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
271 mwifiex_queue_rx_work(adapter
);
273 /* Need to wake up the card ? */
274 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
275 (adapter
->pm_wakeup_card_req
&&
276 !adapter
->pm_wakeup_fw_try
) &&
277 (is_command_pending(adapter
) ||
278 !skb_queue_empty(&adapter
->tx_data_q
) ||
279 !mwifiex_bypass_txlist_empty(adapter
) ||
280 !mwifiex_wmm_lists_empty(adapter
))) {
281 adapter
->pm_wakeup_fw_try
= true;
282 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
283 adapter
->if_ops
.wakeup(adapter
);
287 if (IS_CARD_RX_RCVD(adapter
)) {
288 adapter
->data_received
= false;
289 adapter
->pm_wakeup_fw_try
= false;
290 del_timer(&adapter
->wakeup_timer
);
291 if (adapter
->ps_state
== PS_STATE_SLEEP
)
292 adapter
->ps_state
= PS_STATE_AWAKE
;
294 /* We have tried to wakeup the card already */
295 if (adapter
->pm_wakeup_fw_try
)
297 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
299 if (adapter
->tx_lock_flag
) {
300 if (adapter
->iface_type
== MWIFIEX_USB
) {
301 if (!adapter
->usb_mc_setup
)
307 if ((!adapter
->scan_chan_gap_enabled
&&
308 adapter
->scan_processing
) || adapter
->data_sent
||
309 mwifiex_is_tdls_chan_switching
310 (mwifiex_get_priv(adapter
,
311 MWIFIEX_BSS_ROLE_STA
)) ||
312 (mwifiex_wmm_lists_empty(adapter
) &&
313 mwifiex_bypass_txlist_empty(adapter
) &&
314 skb_queue_empty(&adapter
->tx_data_q
))) {
315 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
316 !mwifiex_is_send_cmd_allowed
317 (mwifiex_get_priv(adapter
,
318 MWIFIEX_BSS_ROLE_STA
)) ||
319 (!is_command_pending(adapter
)))
324 /* Check for event */
325 if (adapter
->event_received
) {
326 adapter
->event_received
= false;
327 mwifiex_process_event(adapter
);
330 /* Check for Cmd Resp */
331 if (adapter
->cmd_resp_received
) {
332 adapter
->cmd_resp_received
= false;
333 mwifiex_process_cmdresp(adapter
);
335 /* call mwifiex back when init_fw is done */
336 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
337 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
338 mwifiex_init_fw_complete(adapter
);
342 /* Check if we need to confirm Sleep Request
343 received previously */
344 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
345 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
346 mwifiex_check_ps_cond(adapter
);
349 /* * The ps_state may have been changed during processing of
350 * Sleep Request event.
352 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
353 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
354 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)) {
358 if (adapter
->tx_lock_flag
) {
359 if (adapter
->iface_type
== MWIFIEX_USB
) {
360 if (!adapter
->usb_mc_setup
)
366 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
367 mwifiex_is_send_cmd_allowed
368 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
369 if (mwifiex_exec_next_cmd(adapter
) == -1) {
375 /** If USB Multi channel setup ongoing,
376 * wait for ready to tx data.
378 if (adapter
->iface_type
== MWIFIEX_USB
&&
379 adapter
->usb_mc_setup
)
382 if ((adapter
->scan_chan_gap_enabled
||
383 !adapter
->scan_processing
) &&
384 !adapter
->data_sent
&&
385 !skb_queue_empty(&adapter
->tx_data_q
)) {
386 mwifiex_process_tx_queue(adapter
);
387 if (adapter
->hs_activated
) {
388 adapter
->is_hs_configured
= false;
389 mwifiex_hs_activated_event
391 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
396 if ((adapter
->scan_chan_gap_enabled
||
397 !adapter
->scan_processing
) &&
398 !adapter
->data_sent
&&
399 !mwifiex_bypass_txlist_empty(adapter
) &&
400 !mwifiex_is_tdls_chan_switching
401 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
402 mwifiex_process_bypass_tx(adapter
);
403 if (adapter
->hs_activated
) {
404 adapter
->is_hs_configured
= false;
405 mwifiex_hs_activated_event
407 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
412 if ((adapter
->scan_chan_gap_enabled
||
413 !adapter
->scan_processing
) &&
414 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
) &&
415 !mwifiex_is_tdls_chan_switching
416 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
417 mwifiex_wmm_process_tx(adapter
);
418 if (adapter
->hs_activated
) {
419 adapter
->is_hs_configured
= false;
420 mwifiex_hs_activated_event
422 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
427 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
428 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
429 (mwifiex_wmm_lists_empty(adapter
) &&
430 mwifiex_bypass_txlist_empty(adapter
) &&
431 skb_queue_empty(&adapter
->tx_data_q
))) {
432 if (!mwifiex_send_null_packet
433 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
434 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
435 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
436 adapter
->delay_null_pkt
= false;
437 adapter
->ps_state
= PS_STATE_SLEEP
;
443 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
444 if (adapter
->more_task_flag
) {
445 adapter
->more_task_flag
= false;
446 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
449 adapter
->mwifiex_processing
= false;
450 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
453 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
454 mwifiex_shutdown_drv(adapter
);
457 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
460 * This function frees the adapter structure.
462 * Additionally, this closes the netlink socket, frees the timers
463 * and private structures.
465 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
468 pr_err("%s: adapter is NULL\n", __func__
);
472 mwifiex_unregister(adapter
);
473 pr_debug("info: %s: free adapter\n", __func__
);
477 * This function cancels all works in the queue and destroys
478 * the main workqueue.
480 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
482 flush_workqueue(adapter
->workqueue
);
483 destroy_workqueue(adapter
->workqueue
);
484 adapter
->workqueue
= NULL
;
486 if (adapter
->rx_workqueue
) {
487 flush_workqueue(adapter
->rx_workqueue
);
488 destroy_workqueue(adapter
->rx_workqueue
);
489 adapter
->rx_workqueue
= NULL
;
494 * This function gets firmware and initializes it.
496 * The main initialization steps followed are -
497 * - Download the correct firmware to card
498 * - Issue the init commands to firmware
500 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
504 struct mwifiex_private
*priv
;
505 struct mwifiex_adapter
*adapter
= context
;
506 struct mwifiex_fw_image fw
;
507 struct semaphore
*sem
= adapter
->card_sem
;
508 bool init_failed
= false;
509 struct wireless_dev
*wdev
;
512 mwifiex_dbg(adapter
, ERROR
,
513 "Failed to get firmware %s\n", adapter
->fw_name
);
517 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
518 adapter
->firmware
= firmware
;
519 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
520 fw
.fw_len
= adapter
->firmware
->size
;
522 if (adapter
->if_ops
.dnld_fw
)
523 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
525 ret
= mwifiex_dnld_fw(adapter
, &fw
);
529 mwifiex_dbg(adapter
, MSG
, "WLAN FW is active\n");
532 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
534 mwifiex_dbg(adapter
, ERROR
,
535 "Cal data request_firmware() failed\n");
538 /* enable host interrupt after fw dnld is successful */
539 if (adapter
->if_ops
.enable_int
) {
540 if (adapter
->if_ops
.enable_int(adapter
))
544 adapter
->init_wait_q_woken
= false;
545 ret
= mwifiex_init_fw(adapter
);
549 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
552 /* Wait for mwifiex_init to complete */
553 wait_event_interruptible(adapter
->init_wait_q
,
554 adapter
->init_wait_q_woken
);
555 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
558 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
559 if (mwifiex_register_cfg80211(adapter
)) {
560 mwifiex_dbg(adapter
, ERROR
,
561 "cannot register with cfg80211\n");
565 if (mwifiex_init_channel_scan_gap(adapter
)) {
566 mwifiex_dbg(adapter
, ERROR
,
567 "could not init channel stats table\n");
572 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
573 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
577 /* Create station interface by default */
578 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d", NET_NAME_ENUM
,
579 NL80211_IFTYPE_STATION
, NULL
, NULL
);
581 mwifiex_dbg(adapter
, ERROR
,
582 "cannot create default STA interface\n");
587 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
588 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d", NET_NAME_ENUM
,
589 NL80211_IFTYPE_AP
, NULL
, NULL
);
591 mwifiex_dbg(adapter
, ERROR
,
592 "cannot create AP interface\n");
598 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
599 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d", NET_NAME_ENUM
,
600 NL80211_IFTYPE_P2P_CLIENT
, NULL
,
603 mwifiex_dbg(adapter
, ERROR
,
604 "cannot create p2p client interface\n");
611 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
612 mwifiex_dbg(adapter
, MSG
, "driver_version = %s\n", fmt
);
616 wiphy_unregister(adapter
->wiphy
);
617 wiphy_free(adapter
->wiphy
);
619 if (adapter
->if_ops
.disable_int
)
620 adapter
->if_ops
.disable_int(adapter
);
622 mwifiex_dbg(adapter
, ERROR
,
623 "info: %s: unregister device\n", __func__
);
624 if (adapter
->if_ops
.unregister_dev
)
625 adapter
->if_ops
.unregister_dev(adapter
);
627 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
628 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
629 adapter
->init_wait_q_woken
= false;
631 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
632 wait_event_interruptible(adapter
->init_wait_q
,
633 adapter
->init_wait_q_woken
);
635 adapter
->surprise_removed
= true;
636 mwifiex_terminate_workqueue(adapter
);
639 if (adapter
->cal_data
) {
640 release_firmware(adapter
->cal_data
);
641 adapter
->cal_data
= NULL
;
643 if (adapter
->firmware
) {
644 release_firmware(adapter
->firmware
);
645 adapter
->firmware
= NULL
;
648 mwifiex_free_adapter(adapter
);
654 * This function initializes the hardware and gets firmware.
656 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
660 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
661 adapter
->dev
, GFP_KERNEL
, adapter
,
664 mwifiex_dbg(adapter
, ERROR
,
665 "request_firmware_nowait error %d\n", ret
);
670 * CFG802.11 network device handler for open.
672 * Starts the data queue.
675 mwifiex_open(struct net_device
*dev
)
677 netif_carrier_off(dev
);
683 * CFG802.11 network device handler for close.
686 mwifiex_close(struct net_device
*dev
)
688 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
690 if (priv
->scan_request
) {
691 mwifiex_dbg(priv
->adapter
, INFO
,
692 "aborting scan on ndo_stop\n");
693 cfg80211_scan_done(priv
->scan_request
, 1);
694 priv
->scan_request
= NULL
;
695 priv
->scan_aborting
= true;
702 mwifiex_bypass_tx_queue(struct mwifiex_private
*priv
,
705 struct ethhdr
*eth_hdr
= (struct ethhdr
*)skb
->data
;
707 if (ntohs(eth_hdr
->h_proto
) == ETH_P_PAE
||
708 mwifiex_is_skb_mgmt_frame(skb
) ||
709 (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
&&
710 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
711 (ntohs(eth_hdr
->h_proto
) == ETH_P_TDLS
))) {
712 mwifiex_dbg(priv
->adapter
, DATA
,
713 "bypass txqueue; eth type %#x, mgmt %d\n",
714 ntohs(eth_hdr
->h_proto
),
715 mwifiex_is_skb_mgmt_frame(skb
));
722 * Add buffer into wmm tx queue and queue work to transmit it.
724 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
726 struct netdev_queue
*txq
;
727 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
729 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
730 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
731 if (!netif_tx_queue_stopped(txq
)) {
732 netif_tx_stop_queue(txq
);
733 mwifiex_dbg(priv
->adapter
, DATA
,
734 "stop queue: %d\n", index
);
738 if (mwifiex_bypass_tx_queue(priv
, skb
)) {
739 atomic_inc(&priv
->adapter
->tx_pending
);
740 atomic_inc(&priv
->adapter
->bypass_tx_pending
);
741 mwifiex_wmm_add_buf_bypass_txqueue(priv
, skb
);
743 atomic_inc(&priv
->adapter
->tx_pending
);
744 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
747 mwifiex_queue_main_work(priv
->adapter
);
753 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
754 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
756 struct sk_buff
*orig_skb
= skb
;
757 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
759 skb
= skb_clone(skb
, GFP_ATOMIC
);
764 spin_lock_irqsave(&priv
->ack_status_lock
, flags
);
765 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
766 1, 0xff, GFP_ATOMIC
);
767 spin_unlock_irqrestore(&priv
->ack_status_lock
, flags
);
770 tx_info
= MWIFIEX_SKB_TXCB(skb
);
771 tx_info
->ack_frame_id
= id
;
772 tx_info
->flags
|= flag
;
773 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
774 orig_tx_info
->ack_frame_id
= id
;
775 orig_tx_info
->flags
|= flag
;
777 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
778 orig_tx_info
->cookie
= *cookie
;
780 } else if (skb_shared(skb
)) {
787 /* couldn't clone -- lose tx status ... */
795 * CFG802.11 network device handler for data transmission.
798 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
800 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
801 struct sk_buff
*new_skb
;
802 struct mwifiex_txinfo
*tx_info
;
805 mwifiex_dbg(priv
->adapter
, DATA
,
806 "data: %lu BSS(%d-%d): Data <= kernel\n",
807 jiffies
, priv
->bss_type
, priv
->bss_num
);
809 if (priv
->adapter
->surprise_removed
) {
811 priv
->stats
.tx_dropped
++;
814 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
815 mwifiex_dbg(priv
->adapter
, ERROR
,
816 "Tx: bad skb len %d\n", skb
->len
);
818 priv
->stats
.tx_dropped
++;
821 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
822 mwifiex_dbg(priv
->adapter
, DATA
,
823 "data: Tx: insufficient skb headroom %d\n",
825 /* Insufficient skb headroom - allocate a new skb */
827 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
828 if (unlikely(!new_skb
)) {
829 mwifiex_dbg(priv
->adapter
, ERROR
,
830 "Tx: cannot alloca new_skb\n");
832 priv
->stats
.tx_dropped
++;
837 mwifiex_dbg(priv
->adapter
, INFO
,
838 "info: new skb headroomd %d\n",
842 tx_info
= MWIFIEX_SKB_TXCB(skb
);
843 memset(tx_info
, 0, sizeof(*tx_info
));
844 tx_info
->bss_num
= priv
->bss_num
;
845 tx_info
->bss_type
= priv
->bss_type
;
846 tx_info
->pkt_len
= skb
->len
;
848 multicast
= is_multicast_ether_addr(skb
->data
);
850 if (unlikely(!multicast
&& skb
->sk
&&
851 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
852 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
853 skb
= mwifiex_clone_skb_for_tx_status(priv
,
855 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
857 /* Record the current time the packet was queued; used to
858 * determine the amount of time the packet was queued in
859 * the driver before it was sent to the firmware.
860 * The delay is then sent along with the packet to the
861 * firmware for aggregate delay calculation for stats and
862 * MSDU lifetime expiry.
864 __net_timestamp(skb
);
866 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
867 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
868 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
869 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
870 mwifiex_tdls_check_tx(priv
, skb
);
873 mwifiex_queue_tx_pkt(priv
, skb
);
879 * CFG802.11 network device handler for setting MAC address.
882 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
884 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
885 struct sockaddr
*hw_addr
= addr
;
888 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
890 /* Send request to firmware */
891 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
892 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
895 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
897 mwifiex_dbg(priv
->adapter
, ERROR
,
898 "set mac address failed: ret=%d\n", ret
);
900 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
906 * CFG802.11 network device handler for setting multicast list.
908 static void mwifiex_set_multicast_list(struct net_device
*dev
)
910 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
911 struct mwifiex_multicast_list mcast_list
;
913 if (dev
->flags
& IFF_PROMISC
) {
914 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
915 } else if (dev
->flags
& IFF_ALLMULTI
||
916 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
917 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
919 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
920 mcast_list
.num_multicast_addr
=
921 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
923 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
927 * CFG802.11 network device handler for transmission timeout.
930 mwifiex_tx_timeout(struct net_device
*dev
)
932 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
934 priv
->num_tx_timeout
++;
935 priv
->tx_timeout_cnt
++;
936 mwifiex_dbg(priv
->adapter
, ERROR
,
937 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
938 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
,
940 mwifiex_set_trans_start(dev
);
942 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
943 priv
->adapter
->if_ops
.card_reset
) {
944 mwifiex_dbg(priv
->adapter
, ERROR
,
945 "tx_timeout_cnt exceeds threshold.\t"
946 "Triggering card reset!\n");
947 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
951 void mwifiex_multi_chan_resync(struct mwifiex_adapter
*adapter
)
953 struct usb_card_rec
*card
= adapter
->card
;
954 struct mwifiex_private
*priv
;
958 card
->mc_resync_flag
= true;
959 for (i
= 0; i
< MWIFIEX_TX_DATA_PORT
; i
++) {
960 if (atomic_read(&card
->port
[i
].tx_data_urb_pending
)) {
961 mwifiex_dbg(adapter
, WARN
, "pending data urb in sys\n");
966 card
->mc_resync_flag
= false;
967 tx_buf_size
= 0xffff;
968 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
969 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_RECONFIGURE_TX_BUFF
,
970 HostCmd_ACT_GEN_SET
, 0, &tx_buf_size
, false);
972 mwifiex_dbg(adapter
, ERROR
,
973 "send reconfig tx buf size cmd err\n");
975 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync
);
977 void mwifiex_drv_info_dump(struct mwifiex_adapter
*adapter
)
980 char drv_version
[64];
981 struct usb_card_rec
*cardp
;
982 struct sdio_mmc_card
*sdio_card
;
983 struct mwifiex_private
*priv
;
985 struct netdev_queue
*txq
;
986 struct mwifiex_debug_info
*debug_info
;
988 if (adapter
->drv_info_dump
) {
989 vfree(adapter
->drv_info_dump
);
990 adapter
->drv_info_dump
= NULL
;
991 adapter
->drv_info_size
= 0;
994 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump start===\n");
996 adapter
->drv_info_dump
= vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX
);
998 if (!adapter
->drv_info_dump
)
1001 p
= (char *)(adapter
->drv_info_dump
);
1002 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
1004 mwifiex_drv_get_driver_version(adapter
, drv_version
,
1005 sizeof(drv_version
) - 1);
1006 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
1008 if (adapter
->iface_type
== MWIFIEX_USB
) {
1009 cardp
= (struct usb_card_rec
*)adapter
->card
;
1010 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
1011 atomic_read(&cardp
->tx_cmd_urb_pending
));
1012 p
+= sprintf(p
, "tx_data_urb_pending_port_0 = %d\n",
1013 atomic_read(&cardp
->port
[0].tx_data_urb_pending
));
1014 p
+= sprintf(p
, "tx_data_urb_pending_port_1 = %d\n",
1015 atomic_read(&cardp
->port
[1].tx_data_urb_pending
));
1016 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
1017 atomic_read(&cardp
->rx_cmd_urb_pending
));
1018 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
1019 atomic_read(&cardp
->rx_data_urb_pending
));
1022 p
+= sprintf(p
, "tx_pending = %d\n",
1023 atomic_read(&adapter
->tx_pending
));
1024 p
+= sprintf(p
, "rx_pending = %d\n",
1025 atomic_read(&adapter
->rx_pending
));
1027 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1028 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
1029 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1030 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
1031 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1032 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
1035 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1036 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1038 priv
= adapter
->priv
[i
];
1039 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
1040 priv
->netdev
->name
);
1041 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
1042 atomic_read(&priv
->wmm_tx_pending
[0]));
1043 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
1044 atomic_read(&priv
->wmm_tx_pending
[1]));
1045 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
1046 atomic_read(&priv
->wmm_tx_pending
[2]));
1047 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
1048 atomic_read(&priv
->wmm_tx_pending
[3]));
1049 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
1050 "Disconnected" : "Connected");
1051 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
1053 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
1054 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
1055 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
1056 netif_tx_queue_stopped(txq
) ?
1057 "stopped" : "started");
1059 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
1060 priv
->netdev
->name
, priv
->num_tx_timeout
);
1063 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1064 p
+= sprintf(p
, "\n=== SDIO register dump===\n");
1065 if (adapter
->if_ops
.reg_dump
)
1066 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
1069 p
+= sprintf(p
, "\n=== more debug information\n");
1070 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
1072 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1073 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1075 priv
= adapter
->priv
[i
];
1076 mwifiex_get_debug_info(priv
, debug_info
);
1077 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
1083 adapter
->drv_info_size
= p
- adapter
->drv_info_dump
;
1084 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump end===\n");
1086 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump
);
1088 void mwifiex_upload_device_dump(struct mwifiex_adapter
*adapter
)
1090 u8 idx
, *dump_data
, *fw_dump_ptr
;
1093 dump_len
= (strlen("========Start dump driverinfo========\n") +
1094 adapter
->drv_info_size
+
1095 strlen("\n========End dump========\n"));
1097 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1098 struct memory_type_mapping
*entry
=
1099 &adapter
->mem_type_mapping_tbl
[idx
];
1101 if (entry
->mem_ptr
) {
1102 dump_len
+= (strlen("========Start dump ") +
1103 strlen(entry
->mem_name
) +
1104 strlen("========\n") +
1105 (entry
->mem_size
+ 1) +
1106 strlen("\n========End dump========\n"));
1110 dump_data
= vzalloc(dump_len
+ 1);
1114 fw_dump_ptr
= dump_data
;
1116 /* Dump all the memory data into single file, a userspace script will
1117 * be used to split all the memory data to multiple files
1119 mwifiex_dbg(adapter
, MSG
,
1120 "== mwifiex dump information to /sys/class/devcoredump start");
1122 strcpy(fw_dump_ptr
, "========Start dump driverinfo========\n");
1123 fw_dump_ptr
+= strlen("========Start dump driverinfo========\n");
1124 memcpy(fw_dump_ptr
, adapter
->drv_info_dump
, adapter
->drv_info_size
);
1125 fw_dump_ptr
+= adapter
->drv_info_size
;
1126 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1127 fw_dump_ptr
+= strlen("\n========End dump========\n");
1129 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1130 struct memory_type_mapping
*entry
=
1131 &adapter
->mem_type_mapping_tbl
[idx
];
1133 if (entry
->mem_ptr
) {
1134 strcpy(fw_dump_ptr
, "========Start dump ");
1135 fw_dump_ptr
+= strlen("========Start dump ");
1137 strcpy(fw_dump_ptr
, entry
->mem_name
);
1138 fw_dump_ptr
+= strlen(entry
->mem_name
);
1140 strcpy(fw_dump_ptr
, "========\n");
1141 fw_dump_ptr
+= strlen("========\n");
1143 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1144 fw_dump_ptr
+= entry
->mem_size
;
1146 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1147 fw_dump_ptr
+= strlen("\n========End dump========\n");
1151 /* device dump data will be free in device coredump release function
1154 dev_coredumpv(adapter
->dev
, dump_data
, dump_len
, GFP_KERNEL
);
1155 mwifiex_dbg(adapter
, MSG
,
1156 "== mwifiex dump information to /sys/class/devcoredump end");
1159 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1160 struct memory_type_mapping
*entry
=
1161 &adapter
->mem_type_mapping_tbl
[idx
];
1163 if (entry
->mem_ptr
) {
1164 vfree(entry
->mem_ptr
);
1165 entry
->mem_ptr
= NULL
;
1167 entry
->mem_size
= 0;
1170 if (adapter
->drv_info_dump
) {
1171 vfree(adapter
->drv_info_dump
);
1172 adapter
->drv_info_dump
= NULL
;
1173 adapter
->drv_info_size
= 0;
1176 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump
);
1179 * CFG802.11 network device handler for statistics retrieval.
1181 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
1183 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1185 return &priv
->stats
;
1189 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1190 void *accel_priv
, select_queue_fallback_t fallback
)
1192 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1193 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
1196 /* Network device handlers */
1197 static const struct net_device_ops mwifiex_netdev_ops
= {
1198 .ndo_open
= mwifiex_open
,
1199 .ndo_stop
= mwifiex_close
,
1200 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
1201 .ndo_set_mac_address
= mwifiex_set_mac_address
,
1202 .ndo_validate_addr
= eth_validate_addr
,
1203 .ndo_tx_timeout
= mwifiex_tx_timeout
,
1204 .ndo_get_stats
= mwifiex_get_stats
,
1205 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
1206 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
1210 * This function initializes the private structure parameters.
1212 * The following wait queues are initialized -
1213 * - IOCTL wait queue
1214 * - Command wait queue
1215 * - Statistics wait queue
1217 * ...and the following default parameters are set -
1218 * - Current key index : Set to 0
1219 * - Rate index : Set to auto
1220 * - Media connected : Set to disconnected
1221 * - Adhoc link sensed : Set to false
1222 * - Nick name : Set to null
1223 * - Number of Tx timeout : Set to 0
1224 * - Device address : Set to current address
1225 * - Rx histogram statistc : Set to 0
1227 * In addition, the CFG80211 work queue is also created.
1229 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
1230 struct net_device
*dev
)
1232 dev
->netdev_ops
= &mwifiex_netdev_ops
;
1233 dev
->destructor
= free_netdev
;
1234 /* Initialize private structure */
1235 priv
->current_key_index
= 0;
1236 priv
->media_connected
= false;
1237 memset(priv
->mgmt_ie
, 0,
1238 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
1239 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
1240 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1241 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1242 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
1243 priv
->num_tx_timeout
= 0;
1244 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
1245 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
1247 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
1248 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
1249 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
1250 if (priv
->hist_data
)
1251 mwifiex_hist_data_reset(priv
);
1256 * This function check if command is pending.
1258 int is_command_pending(struct mwifiex_adapter
*adapter
)
1260 unsigned long flags
;
1261 int is_cmd_pend_q_empty
;
1263 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1264 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1265 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1267 return !is_cmd_pend_q_empty
;
1271 * This is the RX work queue function.
1273 * It handles the RX operations.
1275 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1277 struct mwifiex_adapter
*adapter
=
1278 container_of(work
, struct mwifiex_adapter
, rx_work
);
1280 if (adapter
->surprise_removed
)
1282 mwifiex_process_rx(adapter
);
1286 * This is the main work queue function.
1288 * It handles the main process, which in turn handles the complete
1289 * driver operations.
1291 static void mwifiex_main_work_queue(struct work_struct
*work
)
1293 struct mwifiex_adapter
*adapter
=
1294 container_of(work
, struct mwifiex_adapter
, main_work
);
1296 if (adapter
->surprise_removed
)
1298 mwifiex_main_process(adapter
);
1302 * This function adds the card.
1304 * This function follows the following major steps to set up the device -
1305 * - Initialize software. This includes probing the card, registering
1306 * the interface operations table, and allocating/initializing the
1308 * - Set up the netlink socket
1309 * - Create and start the main work queue
1310 * - Register the device
1311 * - Initialize firmware and hardware
1312 * - Add logical interfaces
1315 mwifiex_add_card(void *card
, struct semaphore
*sem
,
1316 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
1318 struct mwifiex_adapter
*adapter
;
1320 if (down_interruptible(sem
))
1323 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
1324 pr_err("%s: software init failed\n", __func__
);
1328 adapter
->iface_type
= iface_type
;
1329 adapter
->card_sem
= sem
;
1331 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1332 adapter
->surprise_removed
= false;
1333 init_waitqueue_head(&adapter
->init_wait_q
);
1334 adapter
->is_suspended
= false;
1335 adapter
->hs_activated
= false;
1336 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1337 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1338 adapter
->cmd_wait_q
.status
= 0;
1339 adapter
->scan_wait_q_woken
= false;
1341 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
1342 adapter
->rx_work_enabled
= true;
1343 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1346 adapter
->workqueue
=
1347 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1348 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1349 if (!adapter
->workqueue
)
1352 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1354 if (adapter
->rx_work_enabled
) {
1355 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1359 if (!adapter
->rx_workqueue
)
1362 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1365 /* Register the device. Fill up the private data structure with relevant
1366 information from the card. */
1367 if (adapter
->if_ops
.register_dev(adapter
)) {
1368 pr_err("%s: failed to register mwifiex device\n", __func__
);
1369 goto err_registerdev
;
1372 if (mwifiex_init_hw_fw(adapter
)) {
1373 pr_err("%s: firmware init failed\n", __func__
);
1380 pr_debug("info: %s: unregister device\n", __func__
);
1381 if (adapter
->if_ops
.unregister_dev
)
1382 adapter
->if_ops
.unregister_dev(adapter
);
1383 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1384 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1385 adapter
->init_wait_q_woken
= false;
1387 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
1388 wait_event_interruptible(adapter
->init_wait_q
,
1389 adapter
->init_wait_q_woken
);
1392 adapter
->surprise_removed
= true;
1393 mwifiex_terminate_workqueue(adapter
);
1395 mwifiex_free_adapter(adapter
);
1403 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1406 * This function removes the card.
1408 * This function follows the following major steps to remove the device -
1409 * - Stop data traffic
1410 * - Shutdown firmware
1411 * - Remove the logical interfaces
1412 * - Terminate the work queue
1413 * - Unregister the device
1414 * - Free the adapter structure
1416 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
1418 struct mwifiex_private
*priv
= NULL
;
1421 if (down_interruptible(sem
))
1427 /* We can no longer handle interrupts once we start doing the teardown
1429 if (adapter
->if_ops
.disable_int
)
1430 adapter
->if_ops
.disable_int(adapter
);
1432 adapter
->surprise_removed
= true;
1434 mwifiex_terminate_workqueue(adapter
);
1437 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1438 priv
= adapter
->priv
[i
];
1439 if (priv
&& priv
->netdev
) {
1440 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1441 if (netif_carrier_ok(priv
->netdev
))
1442 netif_carrier_off(priv
->netdev
);
1446 mwifiex_dbg(adapter
, CMD
,
1447 "cmd: calling mwifiex_shutdown_drv...\n");
1448 adapter
->init_wait_q_woken
= false;
1450 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
1451 wait_event_interruptible(adapter
->init_wait_q
,
1452 adapter
->init_wait_q_woken
);
1453 mwifiex_dbg(adapter
, CMD
,
1454 "cmd: mwifiex_shutdown_drv done\n");
1455 if (atomic_read(&adapter
->rx_pending
) ||
1456 atomic_read(&adapter
->tx_pending
) ||
1457 atomic_read(&adapter
->cmd_pending
)) {
1458 mwifiex_dbg(adapter
, ERROR
,
1459 "rx_pending=%d, tx_pending=%d,\t"
1461 atomic_read(&adapter
->rx_pending
),
1462 atomic_read(&adapter
->tx_pending
),
1463 atomic_read(&adapter
->cmd_pending
));
1466 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1467 priv
= adapter
->priv
[i
];
1474 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1475 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1479 wiphy_unregister(adapter
->wiphy
);
1480 wiphy_free(adapter
->wiphy
);
1482 /* Unregister device */
1483 mwifiex_dbg(adapter
, INFO
,
1484 "info: unregister device\n");
1485 if (adapter
->if_ops
.unregister_dev
)
1486 adapter
->if_ops
.unregister_dev(adapter
);
1487 /* Free adapter structure */
1488 mwifiex_dbg(adapter
, INFO
,
1489 "info: free adapter\n");
1490 mwifiex_free_adapter(adapter
);
1497 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1499 void _mwifiex_dbg(const struct mwifiex_adapter
*adapter
, int mask
,
1500 const char *fmt
, ...)
1502 struct va_format vaf
;
1505 if (!adapter
->dev
|| !(adapter
->debug_mask
& mask
))
1508 va_start(args
, fmt
);
1513 dev_info(adapter
->dev
, "%pV", &vaf
);
1517 EXPORT_SYMBOL_GPL(_mwifiex_dbg
);
1520 * This function initializes the module.
1522 * The debug FS is also initialized if configured.
1525 mwifiex_init_module(void)
1527 #ifdef CONFIG_DEBUG_FS
1528 mwifiex_debugfs_init();
1534 * This function cleans up the module.
1536 * The debug FS is removed if available.
1539 mwifiex_cleanup_module(void)
1541 #ifdef CONFIG_DEBUG_FS
1542 mwifiex_debugfs_remove();
1546 module_init(mwifiex_init_module
);
1547 module_exit(mwifiex_cleanup_module
);
1549 MODULE_AUTHOR("Marvell International Ltd.");
1550 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1551 MODULE_VERSION(VERSION
);
1552 MODULE_LICENSE("GPL v2");