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 "/*(DEBLOBBED)*/"
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);
153 void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
157 spin_lock_irqsave(&adapter->main_proc_lock, flags);
158 if (adapter->mwifiex_processing) {
159 adapter->more_task_flag = true;
160 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
162 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
163 queue_work(adapter->workqueue, &adapter->main_work);
166 EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
168 static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
172 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
173 if (adapter->rx_processing) {
174 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
176 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
177 queue_work(adapter->rx_workqueue, &adapter->rx_work);
181 static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
185 struct mwifiex_rxinfo *rx_info;
187 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
188 if (adapter->rx_processing || adapter->rx_locked) {
189 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
192 adapter->rx_processing = true;
193 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
196 /* Check for Rx data */
197 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
198 atomic_dec(&adapter->rx_pending);
199 if ((adapter->delay_main_work ||
200 adapter->iface_type == MWIFIEX_USB) &&
201 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
202 if (adapter->if_ops.submit_rem_rx_urbs)
203 adapter->if_ops.submit_rem_rx_urbs(adapter);
204 adapter->delay_main_work = false;
205 mwifiex_queue_main_work(adapter);
207 rx_info = MWIFIEX_SKB_RXCB(skb);
208 if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) {
209 if (adapter->if_ops.deaggr_pkt)
210 adapter->if_ops.deaggr_pkt(adapter, skb);
211 dev_kfree_skb_any(skb);
213 mwifiex_handle_rx_packet(adapter, skb);
216 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
217 adapter->rx_processing = false;
218 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
227 * This function is the main procedure of the driver and handles various driver
228 * operations. It runs in a loop and provides the core functionalities.
230 * The main responsibilities of this function are -
231 * - Ensure concurrency control
232 * - Handle pending interrupts and call interrupt handlers
233 * - Wake up the card if required
234 * - Handle command responses and call response handlers
235 * - Handle events and call event handlers
236 * - Execute pending commands
237 * - Transmit pending data packets
239 int mwifiex_main_process(struct mwifiex_adapter *adapter)
244 spin_lock_irqsave(&adapter->main_proc_lock, flags);
246 /* Check if already processing */
247 if (adapter->mwifiex_processing || adapter->main_locked) {
248 adapter->more_task_flag = true;
249 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
252 adapter->mwifiex_processing = true;
253 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
257 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
258 (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_AWAKE)
312 if (adapter->tx_lock_flag) {
313 if (adapter->iface_type == MWIFIEX_USB) {
314 if (!adapter->usb_mc_setup)
320 if ((!adapter->scan_chan_gap_enabled &&
321 adapter->scan_processing) || adapter->data_sent ||
322 mwifiex_is_tdls_chan_switching
323 (mwifiex_get_priv(adapter,
324 MWIFIEX_BSS_ROLE_STA)) ||
325 (mwifiex_wmm_lists_empty(adapter) &&
326 mwifiex_bypass_txlist_empty(adapter) &&
327 skb_queue_empty(&adapter->tx_data_q))) {
328 if (adapter->cmd_sent || adapter->curr_cmd ||
329 !mwifiex_is_send_cmd_allowed
330 (mwifiex_get_priv(adapter,
331 MWIFIEX_BSS_ROLE_STA)) ||
332 (!is_command_pending(adapter)))
337 /* Check for event */
338 if (adapter->event_received) {
339 adapter->event_received = false;
340 mwifiex_process_event(adapter);
343 /* Check for Cmd Resp */
344 if (adapter->cmd_resp_received) {
345 adapter->cmd_resp_received = false;
346 mwifiex_process_cmdresp(adapter);
348 /* call mwifiex back when init_fw is done */
349 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
350 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
351 mwifiex_init_fw_complete(adapter);
355 /* Check if we need to confirm Sleep Request
356 received previously */
357 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
358 if (!adapter->cmd_sent && !adapter->curr_cmd)
359 mwifiex_check_ps_cond(adapter);
362 /* * The ps_state may have been changed during processing of
363 * Sleep Request event.
365 if ((adapter->ps_state == PS_STATE_SLEEP) ||
366 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
367 (adapter->ps_state == PS_STATE_SLEEP_CFM)) {
371 if (adapter->tx_lock_flag) {
372 if (adapter->iface_type == MWIFIEX_USB) {
373 if (!adapter->usb_mc_setup)
379 if (!adapter->cmd_sent && !adapter->curr_cmd &&
380 mwifiex_is_send_cmd_allowed
381 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
382 if (mwifiex_exec_next_cmd(adapter) == -1) {
388 /** If USB Multi channel setup ongoing,
389 * wait for ready to tx data.
391 if (adapter->iface_type == MWIFIEX_USB &&
392 adapter->usb_mc_setup)
395 if ((adapter->scan_chan_gap_enabled ||
396 !adapter->scan_processing) &&
397 !adapter->data_sent &&
398 !skb_queue_empty(&adapter->tx_data_q)) {
399 mwifiex_process_tx_queue(adapter);
400 if (adapter->hs_activated) {
401 adapter->is_hs_configured = false;
402 mwifiex_hs_activated_event
404 (adapter, MWIFIEX_BSS_ROLE_ANY),
409 if ((adapter->scan_chan_gap_enabled ||
410 !adapter->scan_processing) &&
411 !adapter->data_sent &&
412 !mwifiex_bypass_txlist_empty(adapter) &&
413 !mwifiex_is_tdls_chan_switching
414 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
415 mwifiex_process_bypass_tx(adapter);
416 if (adapter->hs_activated) {
417 adapter->is_hs_configured = false;
418 mwifiex_hs_activated_event
420 (adapter, MWIFIEX_BSS_ROLE_ANY),
425 if ((adapter->scan_chan_gap_enabled ||
426 !adapter->scan_processing) &&
427 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) &&
428 !mwifiex_is_tdls_chan_switching
429 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
430 mwifiex_wmm_process_tx(adapter);
431 if (adapter->hs_activated) {
432 adapter->is_hs_configured = false;
433 mwifiex_hs_activated_event
435 (adapter, MWIFIEX_BSS_ROLE_ANY),
440 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
441 !adapter->curr_cmd && !is_command_pending(adapter) &&
442 (mwifiex_wmm_lists_empty(adapter) &&
443 mwifiex_bypass_txlist_empty(adapter) &&
444 skb_queue_empty(&adapter->tx_data_q))) {
445 if (!mwifiex_send_null_packet
446 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
447 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
448 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
449 adapter->delay_null_pkt = false;
450 adapter->ps_state = PS_STATE_SLEEP;
456 spin_lock_irqsave(&adapter->main_proc_lock, flags);
457 if (adapter->more_task_flag) {
458 adapter->more_task_flag = false;
459 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
462 adapter->mwifiex_processing = false;
463 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
466 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
467 mwifiex_shutdown_drv(adapter);
470 EXPORT_SYMBOL_GPL(mwifiex_main_process);
473 * This function frees the adapter structure.
475 * Additionally, this closes the netlink socket, frees the timers
476 * and private structures.
478 static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
481 pr_err("%s: adapter is NULL\n", __func__);
485 mwifiex_unregister(adapter);
486 pr_debug("info: %s: free adapter\n", __func__);
490 * This function cancels all works in the queue and destroys
491 * the main workqueue.
493 static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
495 if (adapter->workqueue) {
496 flush_workqueue(adapter->workqueue);
497 destroy_workqueue(adapter->workqueue);
498 adapter->workqueue = NULL;
501 if (adapter->rx_workqueue) {
502 flush_workqueue(adapter->rx_workqueue);
503 destroy_workqueue(adapter->rx_workqueue);
504 adapter->rx_workqueue = NULL;
509 * This function gets firmware and initializes it.
511 * The main initialization steps followed are -
512 * - Download the correct firmware to card
513 * - Issue the init commands to firmware
515 static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
519 struct mwifiex_private *priv;
520 struct mwifiex_adapter *adapter = context;
521 struct mwifiex_fw_image fw;
522 struct semaphore *sem = adapter->card_sem;
523 bool init_failed = false;
524 struct wireless_dev *wdev;
527 mwifiex_dbg(adapter, ERROR,
528 "Failed to get firmware %s\n", adapter->fw_name);
532 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
533 adapter->firmware = firmware;
534 fw.fw_buf = (u8 *) adapter->firmware->data;
535 fw.fw_len = adapter->firmware->size;
537 if (adapter->if_ops.dnld_fw) {
538 ret = adapter->if_ops.dnld_fw(adapter, &fw);
540 ret = mwifiex_dnld_fw(adapter, &fw);
546 mwifiex_dbg(adapter, MSG, "WLAN FW is active\n");
549 if ((reject_firmware(&adapter->cal_data, cal_data_cfg,
551 mwifiex_dbg(adapter, ERROR,
552 "Cal data reject_firmware() failed\n");
555 /* enable host interrupt after fw dnld is successful */
556 if (adapter->if_ops.enable_int) {
557 if (adapter->if_ops.enable_int(adapter))
561 adapter->init_wait_q_woken = false;
562 ret = mwifiex_init_fw(adapter);
566 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
569 /* Wait for mwifiex_init to complete */
570 if (!adapter->mfg_mode) {
571 wait_event_interruptible(adapter->init_wait_q,
572 adapter->init_wait_q_woken);
573 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
577 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
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");
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, 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, 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,
625 mwifiex_dbg(adapter, ERROR,
626 "cannot create p2p client interface\n");
633 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
634 mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt);
638 vfree(adapter->chan_stats);
639 wiphy_unregister(adapter->wiphy);
640 wiphy_free(adapter->wiphy);
642 if (adapter->if_ops.disable_int)
643 adapter->if_ops.disable_int(adapter);
645 mwifiex_dbg(adapter, ERROR,
646 "info: %s: unregister device\n", __func__);
647 if (adapter->if_ops.unregister_dev)
648 adapter->if_ops.unregister_dev(adapter);
650 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
651 pr_debug("info: %s: shutdown mwifiex\n", __func__);
652 adapter->init_wait_q_woken = false;
654 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
655 wait_event_interruptible(adapter->init_wait_q,
656 adapter->init_wait_q_woken);
658 adapter->surprise_removed = true;
659 mwifiex_terminate_workqueue(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 mwifiex_free_adapter(adapter);
677 * This function initializes the hardware and gets firmware.
679 static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,
684 /* Override default firmware with manufacturing one if
685 * manufacturing mode is enabled
688 if (strlcpy(adapter->fw_name, MFG_FIRMWARE,
689 sizeof(adapter->fw_name)) >=
690 sizeof(adapter->fw_name)) {
691 pr_err("%s: fw_name too long!\n", __func__);
697 ret = reject_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
698 adapter->dev, GFP_KERNEL, adapter,
701 mwifiex_dbg(adapter, ERROR,
702 "request_firmware_nowait error %d\n", ret);
704 ret = reject_firmware(&adapter->firmware,
708 mwifiex_dbg(adapter, ERROR,
709 "request_firmware error %d\n", ret);
711 mwifiex_fw_dpc(adapter->firmware, (void *)adapter);
718 * CFG802.11 network device handler for open.
720 * Starts the data queue.
723 mwifiex_open(struct net_device *dev)
725 netif_carrier_off(dev);
731 * CFG802.11 network device handler for close.
734 mwifiex_close(struct net_device *dev)
736 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
738 if (priv->scan_request) {
739 struct cfg80211_scan_info info = {
743 mwifiex_dbg(priv->adapter, INFO,
744 "aborting scan on ndo_stop\n");
745 cfg80211_scan_done(priv->scan_request, &info);
746 priv->scan_request = NULL;
747 priv->scan_aborting = true;
750 if (priv->sched_scanning) {
751 mwifiex_dbg(priv->adapter, INFO,
752 "aborting bgscan on ndo_stop\n");
753 mwifiex_stop_bg_scan(priv);
754 cfg80211_sched_scan_stopped(priv->wdev.wiphy);
761 mwifiex_bypass_tx_queue(struct mwifiex_private *priv,
764 struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
766 if (ntohs(eth_hdr->h_proto) == ETH_P_PAE ||
767 mwifiex_is_skb_mgmt_frame(skb) ||
768 (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
769 ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
770 (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) {
771 mwifiex_dbg(priv->adapter, DATA,
772 "bypass txqueue; eth type %#x, mgmt %d\n",
773 ntohs(eth_hdr->h_proto),
774 mwifiex_is_skb_mgmt_frame(skb));
781 * Add buffer into wmm tx queue and queue work to transmit it.
783 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
785 struct netdev_queue *txq;
786 int index = mwifiex_1d_to_wmm_queue[skb->priority];
788 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
789 txq = netdev_get_tx_queue(priv->netdev, index);
790 if (!netif_tx_queue_stopped(txq)) {
791 netif_tx_stop_queue(txq);
792 mwifiex_dbg(priv->adapter, DATA,
793 "stop queue: %d\n", index);
797 if (mwifiex_bypass_tx_queue(priv, skb)) {
798 atomic_inc(&priv->adapter->tx_pending);
799 atomic_inc(&priv->adapter->bypass_tx_pending);
800 mwifiex_wmm_add_buf_bypass_txqueue(priv, skb);
802 atomic_inc(&priv->adapter->tx_pending);
803 mwifiex_wmm_add_buf_txqueue(priv, skb);
806 mwifiex_queue_main_work(priv->adapter);
812 mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
813 struct sk_buff *skb, u8 flag, u64 *cookie)
815 struct sk_buff *orig_skb = skb;
816 struct mwifiex_txinfo *tx_info, *orig_tx_info;
818 skb = skb_clone(skb, GFP_ATOMIC);
823 spin_lock_irqsave(&priv->ack_status_lock, flags);
824 id = idr_alloc(&priv->ack_status_frames, orig_skb,
825 1, 0x10, GFP_ATOMIC);
826 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
829 tx_info = MWIFIEX_SKB_TXCB(skb);
830 tx_info->ack_frame_id = id;
831 tx_info->flags |= flag;
832 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
833 orig_tx_info->ack_frame_id = id;
834 orig_tx_info->flags |= flag;
836 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
837 orig_tx_info->cookie = *cookie;
839 } else if (skb_shared(skb)) {
846 /* couldn't clone -- lose tx status ... */
854 * CFG802.11 network device handler for data transmission.
857 mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
859 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
860 struct sk_buff *new_skb;
861 struct mwifiex_txinfo *tx_info;
864 mwifiex_dbg(priv->adapter, DATA,
865 "data: %lu BSS(%d-%d): Data <= kernel\n",
866 jiffies, priv->bss_type, priv->bss_num);
868 if (priv->adapter->surprise_removed) {
870 priv->stats.tx_dropped++;
873 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
874 mwifiex_dbg(priv->adapter, ERROR,
875 "Tx: bad skb len %d\n", skb->len);
877 priv->stats.tx_dropped++;
880 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
881 mwifiex_dbg(priv->adapter, DATA,
882 "data: Tx: insufficient skb headroom %d\n",
884 /* Insufficient skb headroom - allocate a new skb */
886 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
887 if (unlikely(!new_skb)) {
888 mwifiex_dbg(priv->adapter, ERROR,
889 "Tx: cannot alloca new_skb\n");
891 priv->stats.tx_dropped++;
896 mwifiex_dbg(priv->adapter, INFO,
897 "info: new skb headroomd %d\n",
901 tx_info = MWIFIEX_SKB_TXCB(skb);
902 memset(tx_info, 0, sizeof(*tx_info));
903 tx_info->bss_num = priv->bss_num;
904 tx_info->bss_type = priv->bss_type;
905 tx_info->pkt_len = skb->len;
907 multicast = is_multicast_ether_addr(skb->data);
909 if (unlikely(!multicast && skb->sk &&
910 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
911 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
912 skb = mwifiex_clone_skb_for_tx_status(priv,
914 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
916 /* Record the current time the packet was queued; used to
917 * determine the amount of time the packet was queued in
918 * the driver before it was sent to the firmware.
919 * The delay is then sent along with the packet to the
920 * firmware for aggregate delay calculation for stats and
921 * MSDU lifetime expiry.
923 __net_timestamp(skb);
925 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
926 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
927 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
928 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
929 mwifiex_tdls_check_tx(priv, skb);
932 mwifiex_queue_tx_pkt(priv, skb);
938 * CFG802.11 network device handler for setting MAC address.
941 mwifiex_set_mac_address(struct net_device *dev, void *addr)
943 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
944 struct sockaddr *hw_addr = addr;
947 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
949 /* Send request to firmware */
950 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
951 HostCmd_ACT_GEN_SET, 0, NULL, true);
954 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
956 mwifiex_dbg(priv->adapter, ERROR,
957 "set mac address failed: ret=%d\n", ret);
959 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
965 * CFG802.11 network device handler for setting multicast list.
967 static void mwifiex_set_multicast_list(struct net_device *dev)
969 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
970 struct mwifiex_multicast_list mcast_list;
972 if (dev->flags & IFF_PROMISC) {
973 mcast_list.mode = MWIFIEX_PROMISC_MODE;
974 } else if (dev->flags & IFF_ALLMULTI ||
975 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
976 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
978 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
979 mcast_list.num_multicast_addr =
980 mwifiex_copy_mcast_addr(&mcast_list, dev);
982 mwifiex_request_set_multicast_list(priv, &mcast_list);
986 * CFG802.11 network device handler for transmission timeout.
989 mwifiex_tx_timeout(struct net_device *dev)
991 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
993 priv->num_tx_timeout++;
994 priv->tx_timeout_cnt++;
995 mwifiex_dbg(priv->adapter, ERROR,
996 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
997 jiffies, priv->tx_timeout_cnt, priv->bss_type,
999 mwifiex_set_trans_start(dev);
1001 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
1002 priv->adapter->if_ops.card_reset) {
1003 mwifiex_dbg(priv->adapter, ERROR,
1004 "tx_timeout_cnt exceeds threshold.\t"
1005 "Triggering card reset!\n");
1006 priv->adapter->if_ops.card_reset(priv->adapter);
1010 void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter)
1012 struct usb_card_rec *card = adapter->card;
1013 struct mwifiex_private *priv;
1017 card->mc_resync_flag = true;
1018 for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
1019 if (atomic_read(&card->port[i].tx_data_urb_pending)) {
1020 mwifiex_dbg(adapter, WARN, "pending data urb in sys\n");
1025 card->mc_resync_flag = false;
1026 tx_buf_size = 0xffff;
1027 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1028 ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
1029 HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false);
1031 mwifiex_dbg(adapter, ERROR,
1032 "send reconfig tx buf size cmd err\n");
1034 EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
1036 void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter)
1039 char drv_version[64];
1040 struct usb_card_rec *cardp;
1041 struct sdio_mmc_card *sdio_card;
1042 struct mwifiex_private *priv;
1044 struct netdev_queue *txq;
1045 struct mwifiex_debug_info *debug_info;
1047 if (adapter->drv_info_dump) {
1048 vfree(adapter->drv_info_dump);
1049 adapter->drv_info_dump = NULL;
1050 adapter->drv_info_size = 0;
1053 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
1055 adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
1057 if (!adapter->drv_info_dump)
1060 p = (char *)(adapter->drv_info_dump);
1061 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
1063 mwifiex_drv_get_driver_version(adapter, drv_version,
1064 sizeof(drv_version) - 1);
1065 p += sprintf(p, "driver_version = %s\n", drv_version);
1067 if (adapter->iface_type == MWIFIEX_USB) {
1068 cardp = (struct usb_card_rec *)adapter->card;
1069 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
1070 atomic_read(&cardp->tx_cmd_urb_pending));
1071 p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n",
1072 atomic_read(&cardp->port[0].tx_data_urb_pending));
1073 p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n",
1074 atomic_read(&cardp->port[1].tx_data_urb_pending));
1075 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
1076 atomic_read(&cardp->rx_cmd_urb_pending));
1077 p += sprintf(p, "rx_data_urb_pending = %d\n",
1078 atomic_read(&cardp->rx_data_urb_pending));
1081 p += sprintf(p, "tx_pending = %d\n",
1082 atomic_read(&adapter->tx_pending));
1083 p += sprintf(p, "rx_pending = %d\n",
1084 atomic_read(&adapter->rx_pending));
1086 if (adapter->iface_type == MWIFIEX_SDIO) {
1087 sdio_card = (struct sdio_mmc_card *)adapter->card;
1088 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
1089 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
1090 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
1091 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
1094 for (i = 0; i < adapter->priv_num; i++) {
1095 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1097 priv = adapter->priv[i];
1098 p += sprintf(p, "\n[interface : \"%s\"]\n",
1099 priv->netdev->name);
1100 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
1101 atomic_read(&priv->wmm_tx_pending[0]));
1102 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
1103 atomic_read(&priv->wmm_tx_pending[1]));
1104 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
1105 atomic_read(&priv->wmm_tx_pending[2]));
1106 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
1107 atomic_read(&priv->wmm_tx_pending[3]));
1108 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
1109 "Disconnected" : "Connected");
1110 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
1112 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
1113 txq = netdev_get_tx_queue(priv->netdev, idx);
1114 p += sprintf(p, "tx queue %d:%s ", idx,
1115 netif_tx_queue_stopped(txq) ?
1116 "stopped" : "started");
1118 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
1119 priv->netdev->name, priv->num_tx_timeout);
1122 if (adapter->iface_type == MWIFIEX_SDIO ||
1123 adapter->iface_type == MWIFIEX_PCIE) {
1124 p += sprintf(p, "\n=== %s register dump===\n",
1125 adapter->iface_type == MWIFIEX_SDIO ?
1127 if (adapter->if_ops.reg_dump)
1128 p += adapter->if_ops.reg_dump(adapter, p);
1130 p += sprintf(p, "\n=== more debug information\n");
1131 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
1133 for (i = 0; i < adapter->priv_num; i++) {
1134 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
1136 priv = adapter->priv[i];
1137 mwifiex_get_debug_info(priv, debug_info);
1138 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
1144 adapter->drv_info_size = p - adapter->drv_info_dump;
1145 mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
1147 EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
1149 void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)
1151 u8 idx, *dump_data, *fw_dump_ptr;
1154 dump_len = (strlen("========Start dump driverinfo========\n") +
1155 adapter->drv_info_size +
1156 strlen("\n========End dump========\n"));
1158 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1159 struct memory_type_mapping *entry =
1160 &adapter->mem_type_mapping_tbl[idx];
1162 if (entry->mem_ptr) {
1163 dump_len += (strlen("========Start dump ") +
1164 strlen(entry->mem_name) +
1165 strlen("========\n") +
1166 (entry->mem_size + 1) +
1167 strlen("\n========End dump========\n"));
1171 dump_data = vzalloc(dump_len + 1);
1175 fw_dump_ptr = dump_data;
1177 /* Dump all the memory data into single file, a userspace script will
1178 * be used to split all the memory data to multiple files
1180 mwifiex_dbg(adapter, MSG,
1181 "== mwifiex dump information to /sys/class/devcoredump start");
1183 strcpy(fw_dump_ptr, "========Start dump driverinfo========\n");
1184 fw_dump_ptr += strlen("========Start dump driverinfo========\n");
1185 memcpy(fw_dump_ptr, adapter->drv_info_dump, adapter->drv_info_size);
1186 fw_dump_ptr += adapter->drv_info_size;
1187 strcpy(fw_dump_ptr, "\n========End dump========\n");
1188 fw_dump_ptr += strlen("\n========End dump========\n");
1190 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1191 struct memory_type_mapping *entry =
1192 &adapter->mem_type_mapping_tbl[idx];
1194 if (entry->mem_ptr) {
1195 strcpy(fw_dump_ptr, "========Start dump ");
1196 fw_dump_ptr += strlen("========Start dump ");
1198 strcpy(fw_dump_ptr, entry->mem_name);
1199 fw_dump_ptr += strlen(entry->mem_name);
1201 strcpy(fw_dump_ptr, "========\n");
1202 fw_dump_ptr += strlen("========\n");
1204 memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
1205 fw_dump_ptr += entry->mem_size;
1207 strcpy(fw_dump_ptr, "\n========End dump========\n");
1208 fw_dump_ptr += strlen("\n========End dump========\n");
1212 /* device dump data will be free in device coredump release function
1215 dev_coredumpv(adapter->dev, dump_data, dump_len, GFP_KERNEL);
1216 mwifiex_dbg(adapter, MSG,
1217 "== mwifiex dump information to /sys/class/devcoredump end");
1220 for (idx = 0; idx < adapter->num_mem_types; idx++) {
1221 struct memory_type_mapping *entry =
1222 &adapter->mem_type_mapping_tbl[idx];
1224 if (entry->mem_ptr) {
1225 vfree(entry->mem_ptr);
1226 entry->mem_ptr = NULL;
1228 entry->mem_size = 0;
1231 if (adapter->drv_info_dump) {
1232 vfree(adapter->drv_info_dump);
1233 adapter->drv_info_dump = NULL;
1234 adapter->drv_info_size = 0;
1237 EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
1240 * CFG802.11 network device handler for statistics retrieval.
1242 static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
1244 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1246 return &priv->stats;
1250 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
1251 void *accel_priv, select_queue_fallback_t fallback)
1253 skb->priority = cfg80211_classify8021d(skb, NULL);
1254 return mwifiex_1d_to_wmm_queue[skb->priority];
1257 /* Network device handlers */
1258 static const struct net_device_ops mwifiex_netdev_ops = {
1259 .ndo_open = mwifiex_open,
1260 .ndo_stop = mwifiex_close,
1261 .ndo_start_xmit = mwifiex_hard_start_xmit,
1262 .ndo_set_mac_address = mwifiex_set_mac_address,
1263 .ndo_validate_addr = eth_validate_addr,
1264 .ndo_tx_timeout = mwifiex_tx_timeout,
1265 .ndo_get_stats = mwifiex_get_stats,
1266 .ndo_set_rx_mode = mwifiex_set_multicast_list,
1267 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
1271 * This function initializes the private structure parameters.
1273 * The following wait queues are initialized -
1274 * - IOCTL wait queue
1275 * - Command wait queue
1276 * - Statistics wait queue
1278 * ...and the following default parameters are set -
1279 * - Current key index : Set to 0
1280 * - Rate index : Set to auto
1281 * - Media connected : Set to disconnected
1282 * - Adhoc link sensed : Set to false
1283 * - Nick name : Set to null
1284 * - Number of Tx timeout : Set to 0
1285 * - Device address : Set to current address
1286 * - Rx histogram statistc : Set to 0
1288 * In addition, the CFG80211 work queue is also created.
1290 void mwifiex_init_priv_params(struct mwifiex_private *priv,
1291 struct net_device *dev)
1293 dev->netdev_ops = &mwifiex_netdev_ops;
1294 dev->destructor = free_netdev;
1295 /* Initialize private structure */
1296 priv->current_key_index = 0;
1297 priv->media_connected = false;
1298 memset(priv->mgmt_ie, 0,
1299 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
1300 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
1301 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
1302 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
1303 priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
1304 priv->num_tx_timeout = 0;
1305 ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
1306 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
1308 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
1309 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
1310 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
1311 if (priv->hist_data)
1312 mwifiex_hist_data_reset(priv);
1317 * This function check if command is pending.
1319 int is_command_pending(struct mwifiex_adapter *adapter)
1321 unsigned long flags;
1322 int is_cmd_pend_q_empty;
1324 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
1325 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
1326 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1328 return !is_cmd_pend_q_empty;
1332 * This is the RX work queue function.
1334 * It handles the RX operations.
1336 static void mwifiex_rx_work_queue(struct work_struct *work)
1338 struct mwifiex_adapter *adapter =
1339 container_of(work, struct mwifiex_adapter, rx_work);
1341 if (adapter->surprise_removed)
1343 mwifiex_process_rx(adapter);
1347 * This is the main work queue function.
1349 * It handles the main process, which in turn handles the complete
1350 * driver operations.
1352 static void mwifiex_main_work_queue(struct work_struct *work)
1354 struct mwifiex_adapter *adapter =
1355 container_of(work, struct mwifiex_adapter, main_work);
1357 if (adapter->surprise_removed)
1359 mwifiex_main_process(adapter);
1363 * This function gets called during PCIe function level reset. Required
1364 * code is extracted from mwifiex_remove_card()
1367 mwifiex_shutdown_sw(struct mwifiex_adapter *adapter, struct semaphore *sem)
1369 struct mwifiex_private *priv;
1375 if (down_interruptible(sem))
1378 priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
1379 mwifiex_deauthenticate(priv, NULL);
1381 /* We can no longer handle interrupts once we start doing the teardown
1384 if (adapter->if_ops.disable_int)
1385 adapter->if_ops.disable_int(adapter);
1387 adapter->surprise_removed = true;
1388 mwifiex_terminate_workqueue(adapter);
1391 for (i = 0; i < adapter->priv_num; i++) {
1392 priv = adapter->priv[i];
1393 if (priv && priv->netdev) {
1394 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1395 if (netif_carrier_ok(priv->netdev))
1396 netif_carrier_off(priv->netdev);
1397 netif_device_detach(priv->netdev);
1401 mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
1402 adapter->init_wait_q_woken = false;
1404 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1405 wait_event_interruptible(adapter->init_wait_q,
1406 adapter->init_wait_q_woken);
1407 if (adapter->if_ops.down_dev)
1408 adapter->if_ops.down_dev(adapter);
1410 mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
1411 if (atomic_read(&adapter->rx_pending) ||
1412 atomic_read(&adapter->tx_pending) ||
1413 atomic_read(&adapter->cmd_pending)) {
1414 mwifiex_dbg(adapter, ERROR,
1415 "rx_pending=%d, tx_pending=%d,\t"
1417 atomic_read(&adapter->rx_pending),
1418 atomic_read(&adapter->tx_pending),
1419 atomic_read(&adapter->cmd_pending));
1422 for (i = 0; i < adapter->priv_num; i++) {
1423 priv = adapter->priv[i];
1428 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1429 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
1432 vfree(adapter->chan_stats);
1436 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
1441 /* This function gets called during PCIe function level reset. Required
1442 * code is extracted from mwifiex_add_card()
1445 mwifiex_reinit_sw(struct mwifiex_adapter *adapter, struct semaphore *sem,
1446 struct mwifiex_if_ops *if_ops, u8 iface_type)
1449 struct pcie_service_card *card = adapter->card;
1451 if (down_interruptible(sem))
1454 mwifiex_init_lock_list(adapter);
1455 if (adapter->if_ops.up_dev)
1456 adapter->if_ops.up_dev(adapter);
1458 adapter->iface_type = iface_type;
1459 adapter->card_sem = sem;
1461 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1462 adapter->surprise_removed = false;
1463 init_waitqueue_head(&adapter->init_wait_q);
1464 adapter->is_suspended = false;
1465 adapter->hs_activated = false;
1466 init_waitqueue_head(&adapter->hs_activate_wait_q);
1467 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1468 adapter->cmd_wait_q.status = 0;
1469 adapter->scan_wait_q_woken = false;
1471 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
1472 adapter->rx_work_enabled = true;
1474 adapter->workqueue =
1475 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1476 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1477 if (!adapter->workqueue)
1480 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1482 if (adapter->rx_work_enabled) {
1483 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1487 if (!adapter->rx_workqueue)
1489 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1492 /* Register the device. Fill up the private data structure with
1493 * relevant information from the card. Some code extracted from
1494 * mwifiex_register_dev()
1496 mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__);
1497 strcpy(fw_name, adapter->fw_name);
1498 strcpy(adapter->fw_name, PCIE8997_DEFAULT_WIFIFW_NAME);
1500 adapter->tx_buf_size = card->pcie.tx_buf_size;
1501 adapter->ext_scan = card->pcie.can_ext_scan;
1502 if (mwifiex_init_hw_fw(adapter, false)) {
1503 strcpy(adapter->fw_name, fw_name);
1504 mwifiex_dbg(adapter, ERROR,
1505 "%s: firmware init failed\n", __func__);
1508 strcpy(adapter->fw_name, fw_name);
1509 mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
1514 mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__);
1515 if (adapter->if_ops.unregister_dev)
1516 adapter->if_ops.unregister_dev(adapter);
1517 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1518 mwifiex_dbg(adapter, ERROR,
1519 "info: %s: shutdown mwifiex\n", __func__);
1520 adapter->init_wait_q_woken = false;
1522 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1523 wait_event_interruptible(adapter->init_wait_q,
1524 adapter->init_wait_q_woken);
1528 mwifiex_terminate_workqueue(adapter);
1529 adapter->surprise_removed = true;
1532 mwifiex_dbg(adapter, INFO, "%s, error\n", __func__);
1537 /* This function processes pre and post PCIe function level resets.
1538 * It performs software cleanup without touching PCIe specific code.
1539 * Also, during initialization PCIe stuff is skipped.
1541 void mwifiex_do_flr(struct mwifiex_adapter *adapter, bool prepare)
1543 struct mwifiex_if_ops if_ops;
1546 mwifiex_reinit_sw(adapter, adapter->card_sem, &if_ops,
1547 adapter->iface_type);
1549 memcpy(&if_ops, &adapter->if_ops,
1550 sizeof(struct mwifiex_if_ops));
1551 mwifiex_shutdown_sw(adapter, adapter->card_sem);
1554 EXPORT_SYMBOL_GPL(mwifiex_do_flr);
1557 * This function adds the card.
1559 * This function follows the following major steps to set up the device -
1560 * - Initialize software. This includes probing the card, registering
1561 * the interface operations table, and allocating/initializing the
1563 * - Set up the netlink socket
1564 * - Create and start the main work queue
1565 * - Register the device
1566 * - Initialize firmware and hardware
1567 * - Add logical interfaces
1570 mwifiex_add_card(void *card, struct semaphore *sem,
1571 struct mwifiex_if_ops *if_ops, u8 iface_type)
1573 struct mwifiex_adapter *adapter;
1575 if (down_interruptible(sem))
1578 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
1579 pr_err("%s: software init failed\n", __func__);
1583 adapter->iface_type = iface_type;
1584 adapter->card_sem = sem;
1586 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1587 adapter->surprise_removed = false;
1588 init_waitqueue_head(&adapter->init_wait_q);
1589 adapter->is_suspended = false;
1590 adapter->hs_activated = false;
1591 init_waitqueue_head(&adapter->hs_activate_wait_q);
1592 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1593 adapter->cmd_wait_q.status = 0;
1594 adapter->scan_wait_q_woken = false;
1596 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
1597 adapter->rx_work_enabled = true;
1598 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1601 adapter->workqueue =
1602 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1603 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1604 if (!adapter->workqueue)
1607 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1609 if (adapter->rx_work_enabled) {
1610 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1614 if (!adapter->rx_workqueue)
1617 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1620 /* Register the device. Fill up the private data structure with relevant
1621 information from the card. */
1622 if (adapter->if_ops.register_dev(adapter)) {
1623 pr_err("%s: failed to register mwifiex device\n", __func__);
1624 goto err_registerdev;
1627 if (mwifiex_init_hw_fw(adapter, true)) {
1628 pr_err("%s: firmware init failed\n", __func__);
1635 pr_debug("info: %s: unregister device\n", __func__);
1636 if (adapter->if_ops.unregister_dev)
1637 adapter->if_ops.unregister_dev(adapter);
1638 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1639 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1640 adapter->init_wait_q_woken = false;
1642 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1643 wait_event_interruptible(adapter->init_wait_q,
1644 adapter->init_wait_q_woken);
1647 adapter->surprise_removed = true;
1648 mwifiex_terminate_workqueue(adapter);
1650 mwifiex_free_adapter(adapter);
1658 EXPORT_SYMBOL_GPL(mwifiex_add_card);
1661 * This function removes the card.
1663 * This function follows the following major steps to remove the device -
1664 * - Stop data traffic
1665 * - Shutdown firmware
1666 * - Remove the logical interfaces
1667 * - Terminate the work queue
1668 * - Unregister the device
1669 * - Free the adapter structure
1671 int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1673 struct mwifiex_private *priv = NULL;
1676 if (down_trylock(sem))
1682 /* We can no longer handle interrupts once we start doing the teardown
1684 if (adapter->if_ops.disable_int)
1685 adapter->if_ops.disable_int(adapter);
1687 adapter->surprise_removed = true;
1689 mwifiex_terminate_workqueue(adapter);
1692 for (i = 0; i < adapter->priv_num; i++) {
1693 priv = adapter->priv[i];
1694 if (priv && priv->netdev) {
1695 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1696 if (netif_carrier_ok(priv->netdev))
1697 netif_carrier_off(priv->netdev);
1701 mwifiex_dbg(adapter, CMD,
1702 "cmd: calling mwifiex_shutdown_drv...\n");
1703 adapter->init_wait_q_woken = false;
1705 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1706 wait_event_interruptible(adapter->init_wait_q,
1707 adapter->init_wait_q_woken);
1708 mwifiex_dbg(adapter, CMD,
1709 "cmd: mwifiex_shutdown_drv done\n");
1710 if (atomic_read(&adapter->rx_pending) ||
1711 atomic_read(&adapter->tx_pending) ||
1712 atomic_read(&adapter->cmd_pending)) {
1713 mwifiex_dbg(adapter, ERROR,
1714 "rx_pending=%d, tx_pending=%d,\t"
1716 atomic_read(&adapter->rx_pending),
1717 atomic_read(&adapter->tx_pending),
1718 atomic_read(&adapter->cmd_pending));
1721 for (i = 0; i < adapter->priv_num; i++) {
1722 priv = adapter->priv[i];
1729 priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
1730 mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
1733 vfree(adapter->chan_stats);
1735 wiphy_unregister(adapter->wiphy);
1736 wiphy_free(adapter->wiphy);
1738 /* Unregister device */
1739 mwifiex_dbg(adapter, INFO,
1740 "info: unregister device\n");
1741 if (adapter->if_ops.unregister_dev)
1742 adapter->if_ops.unregister_dev(adapter);
1743 /* Free adapter structure */
1744 mwifiex_dbg(adapter, INFO,
1745 "info: free adapter\n");
1746 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->dev || !(adapter->debug_mask & mask))
1764 va_start(args, fmt);
1769 dev_info(adapter->dev, "%pV", &vaf);
1773 EXPORT_SYMBOL_GPL(_mwifiex_dbg);
1776 * This function initializes the module.
1778 * The debug FS is also initialized if configured.
1781 mwifiex_init_module(void)
1783 #ifdef CONFIG_DEBUG_FS
1784 mwifiex_debugfs_init();
1790 * This function cleans up the module.
1792 * The debug FS is removed if available.
1795 mwifiex_cleanup_module(void)
1797 #ifdef CONFIG_DEBUG_FS
1798 mwifiex_debugfs_remove();
1802 module_init(mwifiex_init_module);
1803 module_exit(mwifiex_cleanup_module);
1805 MODULE_AUTHOR("Marvell International Ltd.");
1806 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1807 MODULE_VERSION(VERSION);
1808 MODULE_LICENSE("GPL v2");