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.
26 #define MFG_FIRMWARE "mwifiex_mfg.bin"
28 static unsigned int debug_mask
= MWIFIEX_DEFAULT_DEBUG_MASK
;
29 module_param(debug_mask
, uint
, 0);
30 MODULE_PARM_DESC(debug_mask
, "bitmap for debug flags");
32 const char driver_version
[] = "mwifiex " VERSION
" (%s) ";
33 static char *cal_data_cfg
;
34 module_param(cal_data_cfg
, charp
, 0);
36 static unsigned short driver_mode
;
37 module_param(driver_mode
, ushort
, 0);
38 MODULE_PARM_DESC(driver_mode
,
39 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
42 module_param(mfg_mode
, bool, 0);
43 MODULE_PARM_DESC(mfg_mode
, "manufacturing mode enable:1, disable:0");
46 * This function registers the device and performs all the necessary
49 * The following initialization operations are performed -
50 * - Allocate adapter structure
51 * - Save interface specific operations table in adapter
52 * - Call interface specific initialization routine
53 * - Allocate private structures
54 * - Set default adapter structure parameters
57 * In case of any errors during inittialization, this function also ensures
58 * proper cleanup before exiting.
60 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
63 struct mwifiex_adapter
*adapter
;
66 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
73 /* Save interface specific operations in adapter */
74 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
75 adapter
->debug_mask
= debug_mask
;
77 /* card specific initialization has been deferred until now .. */
78 if (adapter
->if_ops
.init_if
)
79 if (adapter
->if_ops
.init_if(adapter
))
82 adapter
->priv_num
= 0;
84 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
85 /* Allocate memory for private structure */
87 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
88 if (!adapter
->priv
[i
])
91 adapter
->priv
[i
]->adapter
= adapter
;
94 mwifiex_init_lock_list(adapter
);
96 setup_timer(&adapter
->cmd_timer
, mwifiex_cmd_timeout_func
,
97 (unsigned long)adapter
);
102 mwifiex_dbg(adapter
, ERROR
,
103 "info: leave mwifiex_register with error\n");
105 for (i
= 0; i
< adapter
->priv_num
; i
++)
106 kfree(adapter
->priv
[i
]);
114 * This function unregisters the device and performs all the necessary
117 * The following cleanup operations are performed -
119 * - Free beacon buffers
120 * - Free private structures
121 * - Free adapter structure
123 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
127 if (adapter
->if_ops
.cleanup_if
)
128 adapter
->if_ops
.cleanup_if(adapter
);
130 del_timer_sync(&adapter
->cmd_timer
);
132 /* Free private structures */
133 for (i
= 0; i
< adapter
->priv_num
; i
++) {
134 if (adapter
->priv
[i
]) {
135 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
136 kfree(adapter
->priv
[i
]);
140 if (adapter
->nd_info
) {
141 for (i
= 0 ; i
< adapter
->nd_info
->n_matches
; i
++)
142 kfree(adapter
->nd_info
->matches
[i
]);
143 kfree(adapter
->nd_info
);
144 adapter
->nd_info
= NULL
;
147 kfree(adapter
->regd
);
149 vfree(adapter
->chan_stats
);
154 void mwifiex_queue_main_work(struct mwifiex_adapter
*adapter
)
158 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
159 if (adapter
->mwifiex_processing
) {
160 adapter
->more_task_flag
= true;
161 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
163 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
164 queue_work(adapter
->workqueue
, &adapter
->main_work
);
167 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work
);
169 static void mwifiex_queue_rx_work(struct mwifiex_adapter
*adapter
)
173 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
174 if (adapter
->rx_processing
) {
175 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
177 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
178 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
182 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
186 struct mwifiex_rxinfo
*rx_info
;
188 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
189 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
190 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
193 adapter
->rx_processing
= true;
194 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
197 /* Check for Rx data */
198 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
199 atomic_dec(&adapter
->rx_pending
);
200 if ((adapter
->delay_main_work
||
201 adapter
->iface_type
== MWIFIEX_USB
) &&
202 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
203 if (adapter
->if_ops
.submit_rem_rx_urbs
)
204 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
205 adapter
->delay_main_work
= false;
206 mwifiex_queue_main_work(adapter
);
208 rx_info
= MWIFIEX_SKB_RXCB(skb
);
209 if (rx_info
->buf_type
== MWIFIEX_TYPE_AGGR_DATA
) {
210 if (adapter
->if_ops
.deaggr_pkt
)
211 adapter
->if_ops
.deaggr_pkt(adapter
, skb
);
212 dev_kfree_skb_any(skb
);
214 mwifiex_handle_rx_packet(adapter
, skb
);
217 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
218 adapter
->rx_processing
= false;
219 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
228 * This function is the main procedure of the driver and handles various driver
229 * operations. It runs in a loop and provides the core functionalities.
231 * The main responsibilities of this function are -
232 * - Ensure concurrency control
233 * - Handle pending interrupts and call interrupt handlers
234 * - Wake up the card if required
235 * - Handle command responses and call response handlers
236 * - Handle events and call event handlers
237 * - Execute pending commands
238 * - Transmit pending data packets
240 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
245 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
247 /* Check if already processing */
248 if (adapter
->mwifiex_processing
|| adapter
->main_locked
) {
249 adapter
->more_task_flag
= true;
250 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
253 adapter
->mwifiex_processing
= true;
254 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
258 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
)
261 /* For non-USB interfaces, If we process interrupts first, it
262 * would increase RX pending even further. Avoid this by
263 * checking if rx_pending has crossed high threshold and
264 * schedule rx work queue and then process interrupts.
265 * For USB interface, there are no interrupts. We already have
266 * HIGH_RX_PENDING check in usb.c
268 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
&&
269 adapter
->iface_type
!= MWIFIEX_USB
) {
270 adapter
->delay_main_work
= true;
271 mwifiex_queue_rx_work(adapter
);
275 /* Handle pending interrupt if any */
276 if (adapter
->int_status
) {
277 if (adapter
->hs_activated
)
278 mwifiex_process_hs_config(adapter
);
279 if (adapter
->if_ops
.process_int_status
)
280 adapter
->if_ops
.process_int_status(adapter
);
283 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
284 mwifiex_queue_rx_work(adapter
);
286 /* Need to wake up the card ? */
287 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
288 (adapter
->pm_wakeup_card_req
&&
289 !adapter
->pm_wakeup_fw_try
) &&
290 (is_command_pending(adapter
) ||
291 !skb_queue_empty(&adapter
->tx_data_q
) ||
292 !mwifiex_bypass_txlist_empty(adapter
) ||
293 !mwifiex_wmm_lists_empty(adapter
))) {
294 adapter
->pm_wakeup_fw_try
= true;
295 mod_timer(&adapter
->wakeup_timer
, jiffies
+ (HZ
*3));
296 adapter
->if_ops
.wakeup(adapter
);
300 if (IS_CARD_RX_RCVD(adapter
)) {
301 adapter
->data_received
= false;
302 adapter
->pm_wakeup_fw_try
= false;
303 del_timer(&adapter
->wakeup_timer
);
304 if (adapter
->ps_state
== PS_STATE_SLEEP
)
305 adapter
->ps_state
= PS_STATE_AWAKE
;
307 /* We have tried to wakeup the card already */
308 if (adapter
->pm_wakeup_fw_try
)
310 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
311 mwifiex_check_ps_cond(adapter
);
313 if (adapter
->ps_state
!= PS_STATE_AWAKE
)
315 if (adapter
->tx_lock_flag
) {
316 if (adapter
->iface_type
== MWIFIEX_USB
) {
317 if (!adapter
->usb_mc_setup
)
323 if ((!adapter
->scan_chan_gap_enabled
&&
324 adapter
->scan_processing
) || adapter
->data_sent
||
325 mwifiex_is_tdls_chan_switching
326 (mwifiex_get_priv(adapter
,
327 MWIFIEX_BSS_ROLE_STA
)) ||
328 (mwifiex_wmm_lists_empty(adapter
) &&
329 mwifiex_bypass_txlist_empty(adapter
) &&
330 skb_queue_empty(&adapter
->tx_data_q
))) {
331 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
332 !mwifiex_is_send_cmd_allowed
333 (mwifiex_get_priv(adapter
,
334 MWIFIEX_BSS_ROLE_STA
)) ||
335 (!is_command_pending(adapter
)))
340 /* Check for event */
341 if (adapter
->event_received
) {
342 adapter
->event_received
= false;
343 mwifiex_process_event(adapter
);
346 /* Check for Cmd Resp */
347 if (adapter
->cmd_resp_received
) {
348 adapter
->cmd_resp_received
= false;
349 mwifiex_process_cmdresp(adapter
);
351 /* call mwifiex back when init_fw is done */
352 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
353 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
354 mwifiex_init_fw_complete(adapter
);
358 /* Check if we need to confirm Sleep Request
359 received previously */
360 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
361 mwifiex_check_ps_cond(adapter
);
363 /* * The ps_state may have been changed during processing of
364 * Sleep Request event.
366 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
367 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
368 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)) {
372 if (adapter
->tx_lock_flag
) {
373 if (adapter
->iface_type
== MWIFIEX_USB
) {
374 if (!adapter
->usb_mc_setup
)
380 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
&&
381 mwifiex_is_send_cmd_allowed
382 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
383 if (mwifiex_exec_next_cmd(adapter
) == -1) {
389 /** If USB Multi channel setup ongoing,
390 * wait for ready to tx data.
392 if (adapter
->iface_type
== MWIFIEX_USB
&&
393 adapter
->usb_mc_setup
)
396 if ((adapter
->scan_chan_gap_enabled
||
397 !adapter
->scan_processing
) &&
398 !adapter
->data_sent
&&
399 !skb_queue_empty(&adapter
->tx_data_q
)) {
400 mwifiex_process_tx_queue(adapter
);
401 if (adapter
->hs_activated
) {
402 adapter
->is_hs_configured
= false;
403 mwifiex_hs_activated_event
405 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
410 if ((adapter
->scan_chan_gap_enabled
||
411 !adapter
->scan_processing
) &&
412 !adapter
->data_sent
&&
413 !mwifiex_bypass_txlist_empty(adapter
) &&
414 !mwifiex_is_tdls_chan_switching
415 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
416 mwifiex_process_bypass_tx(adapter
);
417 if (adapter
->hs_activated
) {
418 adapter
->is_hs_configured
= false;
419 mwifiex_hs_activated_event
421 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
426 if ((adapter
->scan_chan_gap_enabled
||
427 !adapter
->scan_processing
) &&
428 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
) &&
429 !mwifiex_is_tdls_chan_switching
430 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
))) {
431 mwifiex_wmm_process_tx(adapter
);
432 if (adapter
->hs_activated
) {
433 adapter
->is_hs_configured
= false;
434 mwifiex_hs_activated_event
436 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
441 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
442 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
443 (mwifiex_wmm_lists_empty(adapter
) &&
444 mwifiex_bypass_txlist_empty(adapter
) &&
445 skb_queue_empty(&adapter
->tx_data_q
))) {
446 if (!mwifiex_send_null_packet
447 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
448 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
449 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
450 adapter
->delay_null_pkt
= false;
451 adapter
->ps_state
= PS_STATE_SLEEP
;
457 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
458 if (adapter
->more_task_flag
) {
459 adapter
->more_task_flag
= false;
460 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
463 adapter
->mwifiex_processing
= false;
464 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
468 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
471 * This function frees the adapter structure.
473 * Additionally, this closes the netlink socket, frees the timers
474 * and private structures.
476 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
479 pr_err("%s: adapter is NULL\n", __func__
);
483 mwifiex_unregister(adapter
);
484 pr_debug("info: %s: free adapter\n", __func__
);
488 * This function cancels all works in the queue and destroys
489 * the main workqueue.
491 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
493 if (adapter
->workqueue
) {
494 flush_workqueue(adapter
->workqueue
);
495 destroy_workqueue(adapter
->workqueue
);
496 adapter
->workqueue
= NULL
;
499 if (adapter
->rx_workqueue
) {
500 flush_workqueue(adapter
->rx_workqueue
);
501 destroy_workqueue(adapter
->rx_workqueue
);
502 adapter
->rx_workqueue
= NULL
;
507 * This function gets firmware and initializes it.
509 * The main initialization steps followed are -
510 * - Download the correct firmware to card
511 * - Issue the init commands to firmware
513 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
517 struct mwifiex_adapter
*adapter
= context
;
518 struct mwifiex_fw_image fw
;
519 bool init_failed
= false;
520 struct wireless_dev
*wdev
;
521 struct completion
*fw_done
= adapter
->fw_done
;
524 mwifiex_dbg(adapter
, ERROR
,
525 "Failed to get firmware %s\n", adapter
->fw_name
);
529 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
530 adapter
->firmware
= firmware
;
531 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
532 fw
.fw_len
= adapter
->firmware
->size
;
534 if (adapter
->if_ops
.dnld_fw
) {
535 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
537 ret
= mwifiex_dnld_fw(adapter
, &fw
);
543 mwifiex_dbg(adapter
, MSG
, "WLAN FW is active\n");
546 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
548 mwifiex_dbg(adapter
, ERROR
,
549 "Cal data request_firmware() failed\n");
552 /* enable host interrupt after fw dnld is successful */
553 if (adapter
->if_ops
.enable_int
) {
554 if (adapter
->if_ops
.enable_int(adapter
))
558 adapter
->init_wait_q_woken
= false;
559 ret
= mwifiex_init_fw(adapter
);
563 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
566 /* Wait for mwifiex_init to complete */
567 if (!adapter
->mfg_mode
) {
568 wait_event_interruptible(adapter
->init_wait_q
,
569 adapter
->init_wait_q_woken
);
570 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
574 if (!adapter
->wiphy
) {
575 if (mwifiex_register_cfg80211(adapter
)) {
576 mwifiex_dbg(adapter
, ERROR
,
577 "cannot register with cfg80211\n");
582 if (mwifiex_init_channel_scan_gap(adapter
)) {
583 mwifiex_dbg(adapter
, ERROR
,
584 "could not init channel stats table\n");
589 driver_mode
&= MWIFIEX_DRIVER_MODE_BITMASK
;
590 driver_mode
|= MWIFIEX_DRIVER_MODE_STA
;
594 /* Create station interface by default */
595 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d", NET_NAME_ENUM
,
596 NL80211_IFTYPE_STATION
, NULL
, NULL
);
598 mwifiex_dbg(adapter
, ERROR
,
599 "cannot create default STA interface\n");
604 if (driver_mode
& MWIFIEX_DRIVER_MODE_UAP
) {
605 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d", NET_NAME_ENUM
,
606 NL80211_IFTYPE_AP
, NULL
, NULL
);
608 mwifiex_dbg(adapter
, ERROR
,
609 "cannot create AP interface\n");
615 if (driver_mode
& MWIFIEX_DRIVER_MODE_P2P
) {
616 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d", NET_NAME_ENUM
,
617 NL80211_IFTYPE_P2P_CLIENT
, NULL
,
620 mwifiex_dbg(adapter
, ERROR
,
621 "cannot create p2p client interface\n");
628 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
629 mwifiex_dbg(adapter
, MSG
, "driver_version = %s\n", fmt
);
633 wiphy_unregister(adapter
->wiphy
);
634 wiphy_free(adapter
->wiphy
);
636 if (adapter
->if_ops
.disable_int
)
637 adapter
->if_ops
.disable_int(adapter
);
639 mwifiex_dbg(adapter
, ERROR
,
640 "info: %s: unregister device\n", __func__
);
641 if (adapter
->if_ops
.unregister_dev
)
642 adapter
->if_ops
.unregister_dev(adapter
);
644 adapter
->surprise_removed
= true;
645 mwifiex_terminate_workqueue(adapter
);
647 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
648 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
649 mwifiex_shutdown_drv(adapter
);
654 if (adapter
->cal_data
) {
655 release_firmware(adapter
->cal_data
);
656 adapter
->cal_data
= NULL
;
658 if (adapter
->firmware
) {
659 release_firmware(adapter
->firmware
);
660 adapter
->firmware
= NULL
;
663 mwifiex_free_adapter(adapter
);
664 /* Tell all current and future waiters we're finished */
665 complete_all(fw_done
);
670 * This function initializes the hardware and gets firmware.
672 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
,
677 /* Override default firmware with manufacturing one if
678 * manufacturing mode is enabled
681 if (strlcpy(adapter
->fw_name
, MFG_FIRMWARE
,
682 sizeof(adapter
->fw_name
)) >=
683 sizeof(adapter
->fw_name
)) {
684 pr_err("%s: fw_name too long!\n", __func__
);
690 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
691 adapter
->dev
, GFP_KERNEL
, adapter
,
694 mwifiex_dbg(adapter
, ERROR
,
695 "request_firmware_nowait error %d\n", ret
);
697 ret
= request_firmware(&adapter
->firmware
,
701 mwifiex_dbg(adapter
, ERROR
,
702 "request_firmware error %d\n", ret
);
704 mwifiex_fw_dpc(adapter
->firmware
, (void *)adapter
);
711 * CFG802.11 network device handler for open.
713 * Starts the data queue.
716 mwifiex_open(struct net_device
*dev
)
718 netif_carrier_off(dev
);
724 * CFG802.11 network device handler for close.
727 mwifiex_close(struct net_device
*dev
)
729 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
731 if (priv
->scan_request
) {
732 struct cfg80211_scan_info info
= {
736 mwifiex_dbg(priv
->adapter
, INFO
,
737 "aborting scan on ndo_stop\n");
738 cfg80211_scan_done(priv
->scan_request
, &info
);
739 priv
->scan_request
= NULL
;
740 priv
->scan_aborting
= true;
743 if (priv
->sched_scanning
) {
744 mwifiex_dbg(priv
->adapter
, INFO
,
745 "aborting bgscan on ndo_stop\n");
746 mwifiex_stop_bg_scan(priv
);
747 cfg80211_sched_scan_stopped(priv
->wdev
.wiphy
);
754 mwifiex_bypass_tx_queue(struct mwifiex_private
*priv
,
757 struct ethhdr
*eth_hdr
= (struct ethhdr
*)skb
->data
;
759 if (ntohs(eth_hdr
->h_proto
) == ETH_P_PAE
||
760 mwifiex_is_skb_mgmt_frame(skb
) ||
761 (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
&&
762 ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
763 (ntohs(eth_hdr
->h_proto
) == ETH_P_TDLS
))) {
764 mwifiex_dbg(priv
->adapter
, DATA
,
765 "bypass txqueue; eth type %#x, mgmt %d\n",
766 ntohs(eth_hdr
->h_proto
),
767 mwifiex_is_skb_mgmt_frame(skb
));
774 * Add buffer into wmm tx queue and queue work to transmit it.
776 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
778 struct netdev_queue
*txq
;
779 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
781 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
782 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
783 if (!netif_tx_queue_stopped(txq
)) {
784 netif_tx_stop_queue(txq
);
785 mwifiex_dbg(priv
->adapter
, DATA
,
786 "stop queue: %d\n", index
);
790 if (mwifiex_bypass_tx_queue(priv
, skb
)) {
791 atomic_inc(&priv
->adapter
->tx_pending
);
792 atomic_inc(&priv
->adapter
->bypass_tx_pending
);
793 mwifiex_wmm_add_buf_bypass_txqueue(priv
, skb
);
795 atomic_inc(&priv
->adapter
->tx_pending
);
796 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
799 mwifiex_queue_main_work(priv
->adapter
);
805 mwifiex_clone_skb_for_tx_status(struct mwifiex_private
*priv
,
806 struct sk_buff
*skb
, u8 flag
, u64
*cookie
)
808 struct sk_buff
*orig_skb
= skb
;
809 struct mwifiex_txinfo
*tx_info
, *orig_tx_info
;
811 skb
= skb_clone(skb
, GFP_ATOMIC
);
816 spin_lock_irqsave(&priv
->ack_status_lock
, flags
);
817 id
= idr_alloc(&priv
->ack_status_frames
, orig_skb
,
818 1, 0x10, GFP_ATOMIC
);
819 spin_unlock_irqrestore(&priv
->ack_status_lock
, flags
);
822 tx_info
= MWIFIEX_SKB_TXCB(skb
);
823 tx_info
->ack_frame_id
= id
;
824 tx_info
->flags
|= flag
;
825 orig_tx_info
= MWIFIEX_SKB_TXCB(orig_skb
);
826 orig_tx_info
->ack_frame_id
= id
;
827 orig_tx_info
->flags
|= flag
;
829 if (flag
== MWIFIEX_BUF_FLAG_ACTION_TX_STATUS
&& cookie
)
830 orig_tx_info
->cookie
= *cookie
;
832 } else if (skb_shared(skb
)) {
839 /* couldn't clone -- lose tx status ... */
847 * CFG802.11 network device handler for data transmission.
850 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
852 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
853 struct sk_buff
*new_skb
;
854 struct mwifiex_txinfo
*tx_info
;
857 mwifiex_dbg(priv
->adapter
, DATA
,
858 "data: %lu BSS(%d-%d): Data <= kernel\n",
859 jiffies
, priv
->bss_type
, priv
->bss_num
);
861 if (priv
->adapter
->surprise_removed
) {
863 priv
->stats
.tx_dropped
++;
866 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
867 mwifiex_dbg(priv
->adapter
, ERROR
,
868 "Tx: bad skb len %d\n", skb
->len
);
870 priv
->stats
.tx_dropped
++;
873 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
874 mwifiex_dbg(priv
->adapter
, DATA
,
875 "data: Tx: insufficient skb headroom %d\n",
877 /* Insufficient skb headroom - allocate a new skb */
879 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
880 if (unlikely(!new_skb
)) {
881 mwifiex_dbg(priv
->adapter
, ERROR
,
882 "Tx: cannot alloca new_skb\n");
884 priv
->stats
.tx_dropped
++;
889 mwifiex_dbg(priv
->adapter
, INFO
,
890 "info: new skb headroomd %d\n",
894 tx_info
= MWIFIEX_SKB_TXCB(skb
);
895 memset(tx_info
, 0, sizeof(*tx_info
));
896 tx_info
->bss_num
= priv
->bss_num
;
897 tx_info
->bss_type
= priv
->bss_type
;
898 tx_info
->pkt_len
= skb
->len
;
900 multicast
= is_multicast_ether_addr(skb
->data
);
902 if (unlikely(!multicast
&& skb
->sk
&&
903 skb_shinfo(skb
)->tx_flags
& SKBTX_WIFI_STATUS
&&
904 priv
->adapter
->fw_api_ver
== MWIFIEX_FW_V15
))
905 skb
= mwifiex_clone_skb_for_tx_status(priv
,
907 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS
, NULL
);
909 /* Record the current time the packet was queued; used to
910 * determine the amount of time the packet was queued in
911 * the driver before it was sent to the firmware.
912 * The delay is then sent along with the packet to the
913 * firmware for aggregate delay calculation for stats and
914 * MSDU lifetime expiry.
916 __net_timestamp(skb
);
918 if (ISSUPP_TDLS_ENABLED(priv
->adapter
->fw_cap_info
) &&
919 priv
->bss_type
== MWIFIEX_BSS_TYPE_STA
&&
920 !ether_addr_equal_unaligned(priv
->cfg_bssid
, skb
->data
)) {
921 if (priv
->adapter
->auto_tdls
&& priv
->check_tdls_tx
)
922 mwifiex_tdls_check_tx(priv
, skb
);
925 mwifiex_queue_tx_pkt(priv
, skb
);
931 * CFG802.11 network device handler for setting MAC address.
934 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
936 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
937 struct sockaddr
*hw_addr
= addr
;
940 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
942 /* Send request to firmware */
943 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
944 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
947 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
949 mwifiex_dbg(priv
->adapter
, ERROR
,
950 "set mac address failed: ret=%d\n", ret
);
952 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
958 * CFG802.11 network device handler for setting multicast list.
960 static void mwifiex_set_multicast_list(struct net_device
*dev
)
962 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
963 struct mwifiex_multicast_list mcast_list
;
965 if (dev
->flags
& IFF_PROMISC
) {
966 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
967 } else if (dev
->flags
& IFF_ALLMULTI
||
968 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
969 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
971 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
972 mcast_list
.num_multicast_addr
=
973 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
975 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
979 * CFG802.11 network device handler for transmission timeout.
982 mwifiex_tx_timeout(struct net_device
*dev
)
984 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
986 priv
->num_tx_timeout
++;
987 priv
->tx_timeout_cnt
++;
988 mwifiex_dbg(priv
->adapter
, ERROR
,
989 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
990 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
,
992 mwifiex_set_trans_start(dev
);
994 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
995 priv
->adapter
->if_ops
.card_reset
) {
996 mwifiex_dbg(priv
->adapter
, ERROR
,
997 "tx_timeout_cnt exceeds threshold.\t"
998 "Triggering card reset!\n");
999 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
1003 void mwifiex_multi_chan_resync(struct mwifiex_adapter
*adapter
)
1005 struct usb_card_rec
*card
= adapter
->card
;
1006 struct mwifiex_private
*priv
;
1010 card
->mc_resync_flag
= true;
1011 for (i
= 0; i
< MWIFIEX_TX_DATA_PORT
; i
++) {
1012 if (atomic_read(&card
->port
[i
].tx_data_urb_pending
)) {
1013 mwifiex_dbg(adapter
, WARN
, "pending data urb in sys\n");
1018 card
->mc_resync_flag
= false;
1019 tx_buf_size
= 0xffff;
1020 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1021 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_RECONFIGURE_TX_BUFF
,
1022 HostCmd_ACT_GEN_SET
, 0, &tx_buf_size
, false);
1024 mwifiex_dbg(adapter
, ERROR
,
1025 "send reconfig tx buf size cmd err\n");
1027 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync
);
1029 int mwifiex_drv_info_dump(struct mwifiex_adapter
*adapter
, void **drv_info
)
1032 char drv_version
[64];
1033 struct usb_card_rec
*cardp
;
1034 struct sdio_mmc_card
*sdio_card
;
1035 struct mwifiex_private
*priv
;
1037 struct netdev_queue
*txq
;
1038 struct mwifiex_debug_info
*debug_info
;
1039 void *drv_info_dump
;
1041 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump start===\n");
1043 /* memory allocate here should be free in mwifiex_upload_device_dump*/
1044 drv_info_dump
= vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX
);
1049 p
= (char *)(drv_info_dump
);
1050 p
+= sprintf(p
, "driver_name = " "\"mwifiex\"\n");
1052 mwifiex_drv_get_driver_version(adapter
, drv_version
,
1053 sizeof(drv_version
) - 1);
1054 p
+= sprintf(p
, "driver_version = %s\n", drv_version
);
1056 if (adapter
->iface_type
== MWIFIEX_USB
) {
1057 cardp
= (struct usb_card_rec
*)adapter
->card
;
1058 p
+= sprintf(p
, "tx_cmd_urb_pending = %d\n",
1059 atomic_read(&cardp
->tx_cmd_urb_pending
));
1060 p
+= sprintf(p
, "tx_data_urb_pending_port_0 = %d\n",
1061 atomic_read(&cardp
->port
[0].tx_data_urb_pending
));
1062 p
+= sprintf(p
, "tx_data_urb_pending_port_1 = %d\n",
1063 atomic_read(&cardp
->port
[1].tx_data_urb_pending
));
1064 p
+= sprintf(p
, "rx_cmd_urb_pending = %d\n",
1065 atomic_read(&cardp
->rx_cmd_urb_pending
));
1066 p
+= sprintf(p
, "rx_data_urb_pending = %d\n",
1067 atomic_read(&cardp
->rx_data_urb_pending
));
1070 p
+= sprintf(p
, "tx_pending = %d\n",
1071 atomic_read(&adapter
->tx_pending
));
1072 p
+= sprintf(p
, "rx_pending = %d\n",
1073 atomic_read(&adapter
->rx_pending
));
1075 if (adapter
->iface_type
== MWIFIEX_SDIO
) {
1076 sdio_card
= (struct sdio_mmc_card
*)adapter
->card
;
1077 p
+= sprintf(p
, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1078 sdio_card
->mp_rd_bitmap
, sdio_card
->curr_rd_port
);
1079 p
+= sprintf(p
, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1080 sdio_card
->mp_wr_bitmap
, sdio_card
->curr_wr_port
);
1083 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1084 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1086 priv
= adapter
->priv
[i
];
1087 p
+= sprintf(p
, "\n[interface : \"%s\"]\n",
1088 priv
->netdev
->name
);
1089 p
+= sprintf(p
, "wmm_tx_pending[0] = %d\n",
1090 atomic_read(&priv
->wmm_tx_pending
[0]));
1091 p
+= sprintf(p
, "wmm_tx_pending[1] = %d\n",
1092 atomic_read(&priv
->wmm_tx_pending
[1]));
1093 p
+= sprintf(p
, "wmm_tx_pending[2] = %d\n",
1094 atomic_read(&priv
->wmm_tx_pending
[2]));
1095 p
+= sprintf(p
, "wmm_tx_pending[3] = %d\n",
1096 atomic_read(&priv
->wmm_tx_pending
[3]));
1097 p
+= sprintf(p
, "media_state=\"%s\"\n", !priv
->media_connected
?
1098 "Disconnected" : "Connected");
1099 p
+= sprintf(p
, "carrier %s\n", (netif_carrier_ok(priv
->netdev
)
1101 for (idx
= 0; idx
< priv
->netdev
->num_tx_queues
; idx
++) {
1102 txq
= netdev_get_tx_queue(priv
->netdev
, idx
);
1103 p
+= sprintf(p
, "tx queue %d:%s ", idx
,
1104 netif_tx_queue_stopped(txq
) ?
1105 "stopped" : "started");
1107 p
+= sprintf(p
, "\n%s: num_tx_timeout = %d\n",
1108 priv
->netdev
->name
, priv
->num_tx_timeout
);
1111 if (adapter
->iface_type
== MWIFIEX_SDIO
||
1112 adapter
->iface_type
== MWIFIEX_PCIE
) {
1113 p
+= sprintf(p
, "\n=== %s register dump===\n",
1114 adapter
->iface_type
== MWIFIEX_SDIO
?
1116 if (adapter
->if_ops
.reg_dump
)
1117 p
+= adapter
->if_ops
.reg_dump(adapter
, p
);
1119 p
+= sprintf(p
, "\n=== more debug information\n");
1120 debug_info
= kzalloc(sizeof(*debug_info
), GFP_KERNEL
);
1122 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1123 if (!adapter
->priv
[i
] || !adapter
->priv
[i
]->netdev
)
1125 priv
= adapter
->priv
[i
];
1126 mwifiex_get_debug_info(priv
, debug_info
);
1127 p
+= mwifiex_debug_info_to_buffer(priv
, p
, debug_info
);
1133 mwifiex_dbg(adapter
, MSG
, "===mwifiex driverinfo dump end===\n");
1134 *drv_info
= drv_info_dump
;
1135 return p
- drv_info_dump
;
1137 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump
);
1139 void mwifiex_upload_device_dump(struct mwifiex_adapter
*adapter
, void *drv_info
,
1142 u8 idx
, *dump_data
, *fw_dump_ptr
;
1145 dump_len
= (strlen("========Start dump driverinfo========\n") +
1147 strlen("\n========End dump========\n"));
1149 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1150 struct memory_type_mapping
*entry
=
1151 &adapter
->mem_type_mapping_tbl
[idx
];
1153 if (entry
->mem_ptr
) {
1154 dump_len
+= (strlen("========Start dump ") +
1155 strlen(entry
->mem_name
) +
1156 strlen("========\n") +
1157 (entry
->mem_size
+ 1) +
1158 strlen("\n========End dump========\n"));
1162 dump_data
= vzalloc(dump_len
+ 1);
1166 fw_dump_ptr
= dump_data
;
1168 /* Dump all the memory data into single file, a userspace script will
1169 * be used to split all the memory data to multiple files
1171 mwifiex_dbg(adapter
, MSG
,
1172 "== mwifiex dump information to /sys/class/devcoredump start");
1174 strcpy(fw_dump_ptr
, "========Start dump driverinfo========\n");
1175 fw_dump_ptr
+= strlen("========Start dump driverinfo========\n");
1176 memcpy(fw_dump_ptr
, drv_info
, drv_info_size
);
1177 fw_dump_ptr
+= drv_info_size
;
1178 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1179 fw_dump_ptr
+= strlen("\n========End dump========\n");
1181 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1182 struct memory_type_mapping
*entry
=
1183 &adapter
->mem_type_mapping_tbl
[idx
];
1185 if (entry
->mem_ptr
) {
1186 strcpy(fw_dump_ptr
, "========Start dump ");
1187 fw_dump_ptr
+= strlen("========Start dump ");
1189 strcpy(fw_dump_ptr
, entry
->mem_name
);
1190 fw_dump_ptr
+= strlen(entry
->mem_name
);
1192 strcpy(fw_dump_ptr
, "========\n");
1193 fw_dump_ptr
+= strlen("========\n");
1195 memcpy(fw_dump_ptr
, entry
->mem_ptr
, entry
->mem_size
);
1196 fw_dump_ptr
+= entry
->mem_size
;
1198 strcpy(fw_dump_ptr
, "\n========End dump========\n");
1199 fw_dump_ptr
+= strlen("\n========End dump========\n");
1203 /* device dump data will be free in device coredump release function
1206 dev_coredumpv(adapter
->dev
, dump_data
, dump_len
, GFP_KERNEL
);
1207 mwifiex_dbg(adapter
, MSG
,
1208 "== mwifiex dump information to /sys/class/devcoredump end");
1211 for (idx
= 0; idx
< adapter
->num_mem_types
; idx
++) {
1212 struct memory_type_mapping
*entry
=
1213 &adapter
->mem_type_mapping_tbl
[idx
];
1215 vfree(entry
->mem_ptr
);
1216 entry
->mem_ptr
= NULL
;
1217 entry
->mem_size
= 0;
1222 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump
);
1225 * CFG802.11 network device handler for statistics retrieval.
1227 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
1229 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
1231 return &priv
->stats
;
1235 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
1236 void *accel_priv
, select_queue_fallback_t fallback
)
1238 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
1239 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
1242 /* Network device handlers */
1243 static const struct net_device_ops mwifiex_netdev_ops
= {
1244 .ndo_open
= mwifiex_open
,
1245 .ndo_stop
= mwifiex_close
,
1246 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
1247 .ndo_set_mac_address
= mwifiex_set_mac_address
,
1248 .ndo_validate_addr
= eth_validate_addr
,
1249 .ndo_tx_timeout
= mwifiex_tx_timeout
,
1250 .ndo_get_stats
= mwifiex_get_stats
,
1251 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
1252 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
1256 * This function initializes the private structure parameters.
1258 * The following wait queues are initialized -
1259 * - IOCTL wait queue
1260 * - Command wait queue
1261 * - Statistics wait queue
1263 * ...and the following default parameters are set -
1264 * - Current key index : Set to 0
1265 * - Rate index : Set to auto
1266 * - Media connected : Set to disconnected
1267 * - Adhoc link sensed : Set to false
1268 * - Nick name : Set to null
1269 * - Number of Tx timeout : Set to 0
1270 * - Device address : Set to current address
1271 * - Rx histogram statistc : Set to 0
1273 * In addition, the CFG80211 work queue is also created.
1275 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
1276 struct net_device
*dev
)
1278 dev
->netdev_ops
= &mwifiex_netdev_ops
;
1279 dev
->destructor
= free_netdev
;
1280 /* Initialize private structure */
1281 priv
->current_key_index
= 0;
1282 priv
->media_connected
= false;
1283 memset(priv
->mgmt_ie
, 0,
1284 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
1285 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
1286 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1287 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
1288 priv
->gen_idx
= MWIFIEX_AUTO_IDX_MASK
;
1289 priv
->num_tx_timeout
= 0;
1290 ether_addr_copy(priv
->curr_addr
, priv
->adapter
->perm_addr
);
1291 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
1293 if (GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_STA
||
1294 GET_BSS_ROLE(priv
) == MWIFIEX_BSS_ROLE_UAP
) {
1295 priv
->hist_data
= kmalloc(sizeof(*priv
->hist_data
), GFP_KERNEL
);
1296 if (priv
->hist_data
)
1297 mwifiex_hist_data_reset(priv
);
1302 * This function check if command is pending.
1304 int is_command_pending(struct mwifiex_adapter
*adapter
)
1306 unsigned long flags
;
1307 int is_cmd_pend_q_empty
;
1309 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
1310 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
1311 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
1313 return !is_cmd_pend_q_empty
;
1317 * This is the RX work queue function.
1319 * It handles the RX operations.
1321 static void mwifiex_rx_work_queue(struct work_struct
*work
)
1323 struct mwifiex_adapter
*adapter
=
1324 container_of(work
, struct mwifiex_adapter
, rx_work
);
1326 if (adapter
->surprise_removed
)
1328 mwifiex_process_rx(adapter
);
1332 * This is the main work queue function.
1334 * It handles the main process, which in turn handles the complete
1335 * driver operations.
1337 static void mwifiex_main_work_queue(struct work_struct
*work
)
1339 struct mwifiex_adapter
*adapter
=
1340 container_of(work
, struct mwifiex_adapter
, main_work
);
1342 if (adapter
->surprise_removed
)
1344 mwifiex_main_process(adapter
);
1348 * This function gets called during PCIe function level reset. Required
1349 * code is extracted from mwifiex_remove_card()
1352 mwifiex_shutdown_sw(struct mwifiex_adapter
*adapter
)
1354 struct mwifiex_private
*priv
;
1360 wait_for_completion(adapter
->fw_done
);
1361 /* Caller should ensure we aren't suspending while this happens */
1362 reinit_completion(adapter
->fw_done
);
1364 priv
= mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_ANY
);
1365 mwifiex_deauthenticate(priv
, NULL
);
1367 /* We can no longer handle interrupts once we start doing the teardown
1370 if (adapter
->if_ops
.disable_int
)
1371 adapter
->if_ops
.disable_int(adapter
);
1373 adapter
->surprise_removed
= true;
1374 mwifiex_terminate_workqueue(adapter
);
1377 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1378 priv
= adapter
->priv
[i
];
1379 if (priv
&& priv
->netdev
) {
1380 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1381 if (netif_carrier_ok(priv
->netdev
))
1382 netif_carrier_off(priv
->netdev
);
1383 netif_device_detach(priv
->netdev
);
1387 mwifiex_dbg(adapter
, CMD
, "cmd: calling mwifiex_shutdown_drv...\n");
1389 mwifiex_shutdown_drv(adapter
);
1390 if (adapter
->if_ops
.down_dev
)
1391 adapter
->if_ops
.down_dev(adapter
);
1393 mwifiex_dbg(adapter
, CMD
, "cmd: mwifiex_shutdown_drv done\n");
1394 if (atomic_read(&adapter
->rx_pending
) ||
1395 atomic_read(&adapter
->tx_pending
) ||
1396 atomic_read(&adapter
->cmd_pending
)) {
1397 mwifiex_dbg(adapter
, ERROR
,
1398 "rx_pending=%d, tx_pending=%d,\t"
1400 atomic_read(&adapter
->rx_pending
),
1401 atomic_read(&adapter
->tx_pending
),
1402 atomic_read(&adapter
->cmd_pending
));
1405 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1406 priv
= adapter
->priv
[i
];
1411 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1412 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1416 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1420 EXPORT_SYMBOL_GPL(mwifiex_shutdown_sw
);
1422 /* This function gets called during PCIe function level reset. Required
1423 * code is extracted from mwifiex_add_card()
1426 mwifiex_reinit_sw(struct mwifiex_adapter
*adapter
)
1428 mwifiex_init_lock_list(adapter
);
1429 if (adapter
->if_ops
.up_dev
)
1430 adapter
->if_ops
.up_dev(adapter
);
1432 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1433 adapter
->surprise_removed
= false;
1434 init_waitqueue_head(&adapter
->init_wait_q
);
1435 adapter
->is_suspended
= false;
1436 adapter
->hs_activated
= false;
1437 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1438 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1439 adapter
->cmd_wait_q
.status
= 0;
1440 adapter
->scan_wait_q_woken
= false;
1442 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
)
1443 adapter
->rx_work_enabled
= true;
1445 adapter
->workqueue
=
1446 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1447 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1448 if (!adapter
->workqueue
)
1451 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1453 if (adapter
->rx_work_enabled
) {
1454 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1458 if (!adapter
->rx_workqueue
)
1460 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1463 /* Register the device. Fill up the private data structure with
1464 * relevant information from the card. Some code extracted from
1465 * mwifiex_register_dev()
1467 mwifiex_dbg(adapter
, INFO
, "%s, mwifiex_init_hw_fw()...\n", __func__
);
1469 if (mwifiex_init_hw_fw(adapter
, false)) {
1470 mwifiex_dbg(adapter
, ERROR
,
1471 "%s: firmware init failed\n", __func__
);
1474 mwifiex_dbg(adapter
, INFO
, "%s, successful\n", __func__
);
1476 complete_all(adapter
->fw_done
);
1480 mwifiex_dbg(adapter
, ERROR
, "info: %s: unregister device\n", __func__
);
1481 if (adapter
->if_ops
.unregister_dev
)
1482 adapter
->if_ops
.unregister_dev(adapter
);
1485 adapter
->surprise_removed
= true;
1486 mwifiex_terminate_workqueue(adapter
);
1487 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1488 mwifiex_dbg(adapter
, ERROR
,
1489 "info: %s: shutdown mwifiex\n", __func__
);
1490 mwifiex_shutdown_drv(adapter
);
1493 complete_all(adapter
->fw_done
);
1494 mwifiex_dbg(adapter
, INFO
, "%s, error\n", __func__
);
1498 EXPORT_SYMBOL_GPL(mwifiex_reinit_sw
);
1500 static irqreturn_t
mwifiex_irq_wakeup_handler(int irq
, void *priv
)
1502 struct mwifiex_adapter
*adapter
= priv
;
1504 if (adapter
->irq_wakeup
>= 0) {
1505 dev_dbg(adapter
->dev
, "%s: wake by wifi", __func__
);
1506 adapter
->wake_by_wifi
= true;
1507 disable_irq_nosync(irq
);
1510 /* Notify PM core we are wakeup source */
1511 pm_wakeup_event(adapter
->dev
, 0);
1516 static void mwifiex_probe_of(struct mwifiex_adapter
*adapter
)
1519 struct device
*dev
= adapter
->dev
;
1524 adapter
->dt_node
= dev
->of_node
;
1525 adapter
->irq_wakeup
= irq_of_parse_and_map(adapter
->dt_node
, 0);
1526 if (!adapter
->irq_wakeup
) {
1527 dev_dbg(dev
, "fail to parse irq_wakeup from device tree\n");
1531 ret
= devm_request_irq(dev
, adapter
->irq_wakeup
,
1532 mwifiex_irq_wakeup_handler
, IRQF_TRIGGER_LOW
,
1533 "wifi_wake", adapter
);
1535 dev_err(dev
, "Failed to request irq_wakeup %d (%d)\n",
1536 adapter
->irq_wakeup
, ret
);
1540 disable_irq(adapter
->irq_wakeup
);
1541 if (device_init_wakeup(dev
, true)) {
1542 dev_err(dev
, "fail to init wakeup for mwifiex\n");
1548 adapter
->irq_wakeup
= -1;
1552 * This function adds the card.
1554 * This function follows the following major steps to set up the device -
1555 * - Initialize software. This includes probing the card, registering
1556 * the interface operations table, and allocating/initializing the
1558 * - Set up the netlink socket
1559 * - Create and start the main work queue
1560 * - Register the device
1561 * - Initialize firmware and hardware
1562 * - Add logical interfaces
1565 mwifiex_add_card(void *card
, struct completion
*fw_done
,
1566 struct mwifiex_if_ops
*if_ops
, u8 iface_type
,
1569 struct mwifiex_adapter
*adapter
;
1571 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
1572 pr_err("%s: software init failed\n", __func__
);
1577 mwifiex_probe_of(adapter
);
1579 adapter
->iface_type
= iface_type
;
1580 adapter
->fw_done
= fw_done
;
1582 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
1583 adapter
->surprise_removed
= false;
1584 init_waitqueue_head(&adapter
->init_wait_q
);
1585 adapter
->is_suspended
= false;
1586 adapter
->hs_activated
= false;
1587 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
1588 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
1589 adapter
->cmd_wait_q
.status
= 0;
1590 adapter
->scan_wait_q_woken
= false;
1592 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
1593 adapter
->rx_work_enabled
= true;
1594 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1597 adapter
->workqueue
=
1598 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1599 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
1600 if (!adapter
->workqueue
)
1603 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
1605 if (adapter
->rx_work_enabled
) {
1606 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1610 if (!adapter
->rx_workqueue
)
1613 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
1616 /* Register the device. Fill up the private data structure with relevant
1617 information from the card. */
1618 if (adapter
->if_ops
.register_dev(adapter
)) {
1619 pr_err("%s: failed to register mwifiex device\n", __func__
);
1620 goto err_registerdev
;
1623 if (mwifiex_init_hw_fw(adapter
, true)) {
1624 pr_err("%s: firmware init failed\n", __func__
);
1631 pr_debug("info: %s: unregister device\n", __func__
);
1632 if (adapter
->if_ops
.unregister_dev
)
1633 adapter
->if_ops
.unregister_dev(adapter
);
1635 adapter
->surprise_removed
= true;
1636 mwifiex_terminate_workqueue(adapter
);
1637 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
) {
1638 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
1639 mwifiex_shutdown_drv(adapter
);
1642 mwifiex_free_adapter(adapter
);
1648 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
1651 * This function removes the card.
1653 * This function follows the following major steps to remove the device -
1654 * - Stop data traffic
1655 * - Shutdown firmware
1656 * - Remove the logical interfaces
1657 * - Terminate the work queue
1658 * - Unregister the device
1659 * - Free the adapter structure
1661 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
)
1663 struct mwifiex_private
*priv
= NULL
;
1669 /* We can no longer handle interrupts once we start doing the teardown
1671 if (adapter
->if_ops
.disable_int
)
1672 adapter
->if_ops
.disable_int(adapter
);
1674 adapter
->surprise_removed
= true;
1676 mwifiex_terminate_workqueue(adapter
);
1679 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1680 priv
= adapter
->priv
[i
];
1681 if (priv
&& priv
->netdev
) {
1682 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
1683 if (netif_carrier_ok(priv
->netdev
))
1684 netif_carrier_off(priv
->netdev
);
1688 mwifiex_dbg(adapter
, CMD
,
1689 "cmd: calling mwifiex_shutdown_drv...\n");
1691 mwifiex_shutdown_drv(adapter
);
1692 mwifiex_dbg(adapter
, CMD
,
1693 "cmd: mwifiex_shutdown_drv done\n");
1694 if (atomic_read(&adapter
->rx_pending
) ||
1695 atomic_read(&adapter
->tx_pending
) ||
1696 atomic_read(&adapter
->cmd_pending
)) {
1697 mwifiex_dbg(adapter
, ERROR
,
1698 "rx_pending=%d, tx_pending=%d,\t"
1700 atomic_read(&adapter
->rx_pending
),
1701 atomic_read(&adapter
->tx_pending
),
1702 atomic_read(&adapter
->cmd_pending
));
1705 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1706 priv
= adapter
->priv
[i
];
1713 priv
->wdev
.iftype
!= NL80211_IFTYPE_UNSPECIFIED
)
1714 mwifiex_del_virtual_intf(adapter
->wiphy
, &priv
->wdev
);
1718 wiphy_unregister(adapter
->wiphy
);
1719 wiphy_free(adapter
->wiphy
);
1721 /* Unregister device */
1722 mwifiex_dbg(adapter
, INFO
,
1723 "info: unregister device\n");
1724 if (adapter
->if_ops
.unregister_dev
)
1725 adapter
->if_ops
.unregister_dev(adapter
);
1726 /* Free adapter structure */
1727 mwifiex_dbg(adapter
, INFO
,
1728 "info: free adapter\n");
1729 mwifiex_free_adapter(adapter
);
1734 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1736 void _mwifiex_dbg(const struct mwifiex_adapter
*adapter
, int mask
,
1737 const char *fmt
, ...)
1739 struct va_format vaf
;
1742 if (!adapter
->dev
|| !(adapter
->debug_mask
& mask
))
1745 va_start(args
, fmt
);
1750 dev_info(adapter
->dev
, "%pV", &vaf
);
1754 EXPORT_SYMBOL_GPL(_mwifiex_dbg
);
1757 * This function initializes the module.
1759 * The debug FS is also initialized if configured.
1762 mwifiex_init_module(void)
1764 #ifdef CONFIG_DEBUG_FS
1765 mwifiex_debugfs_init();
1771 * This function cleans up the module.
1773 * The debug FS is removed if available.
1776 mwifiex_cleanup_module(void)
1778 #ifdef CONFIG_DEBUG_FS
1779 mwifiex_debugfs_remove();
1783 module_init(mwifiex_init_module
);
1784 module_exit(mwifiex_cleanup_module
);
1786 MODULE_AUTHOR("Marvell International Ltd.");
1787 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1788 MODULE_VERSION(VERSION
);
1789 MODULE_LICENSE("GPL v2");