2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011-2014, Marvell International Ltd.
6 * This software file (the "File") is distributed by Marvell International
7 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
27 const char driver_version[] = "mwifiex " VERSION " (%s) ";
28 static char *cal_data_cfg;
29 module_param(cal_data_cfg, charp, 0);
31 static unsigned short driver_mode;
32 module_param(driver_mode, ushort, 0);
33 MODULE_PARM_DESC(driver_mode,
34 "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
37 * This function registers the device and performs all the necessary
40 * The following initialization operations are performed -
41 * - Allocate adapter structure
42 * - Save interface specific operations table in adapter
43 * - Call interface specific initialization routine
44 * - Allocate private structures
45 * - Set default adapter structure parameters
48 * In case of any errors during inittialization, this function also ensures
49 * proper cleanup before exiting.
51 static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
54 struct mwifiex_adapter *adapter;
57 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
64 /* Save interface specific operations in adapter */
65 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
67 /* card specific initialization has been deferred until now .. */
68 if (adapter->if_ops.init_if)
69 if (adapter->if_ops.init_if(adapter))
72 adapter->priv_num = 0;
74 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
75 /* Allocate memory for private structure */
77 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
78 if (!adapter->priv[i])
81 adapter->priv[i]->adapter = adapter;
84 mwifiex_init_lock_list(adapter);
86 setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
87 (unsigned long)adapter);
92 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
94 for (i = 0; i < adapter->priv_num; i++)
95 kfree(adapter->priv[i]);
103 * This function unregisters the device and performs all the necessary
106 * The following cleanup operations are performed -
108 * - Free beacon buffers
109 * - Free private structures
110 * - Free adapter structure
112 static int mwifiex_unregister(struct mwifiex_adapter *adapter)
116 if (adapter->if_ops.cleanup_if)
117 adapter->if_ops.cleanup_if(adapter);
119 del_timer_sync(&adapter->cmd_timer);
121 /* Free private structures */
122 for (i = 0; i < adapter->priv_num; i++) {
123 if (adapter->priv[i]) {
124 mwifiex_free_curr_bcn(adapter->priv[i]);
125 kfree(adapter->priv[i]);
129 vfree(adapter->chan_stats);
134 static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
139 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
140 if (adapter->rx_processing || adapter->rx_locked) {
141 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
144 adapter->rx_processing = true;
145 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
148 /* Check for Rx data */
149 while ((skb = skb_dequeue(&adapter->rx_data_q))) {
150 atomic_dec(&adapter->rx_pending);
151 if ((adapter->delay_main_work ||
152 adapter->iface_type == MWIFIEX_USB) &&
153 (atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
154 if (adapter->if_ops.submit_rem_rx_urbs)
155 adapter->if_ops.submit_rem_rx_urbs(adapter);
156 adapter->delay_main_work = false;
157 queue_work(adapter->workqueue, &adapter->main_work);
159 mwifiex_handle_rx_packet(adapter, skb);
161 spin_lock_irqsave(&adapter->rx_proc_lock, flags);
162 adapter->rx_processing = false;
163 spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
172 * This function is the main procedure of the driver and handles various driver
173 * operations. It runs in a loop and provides the core functionalities.
175 * The main responsibilities of this function are -
176 * - Ensure concurrency control
177 * - Handle pending interrupts and call interrupt handlers
178 * - Wake up the card if required
179 * - Handle command responses and call response handlers
180 * - Handle events and call event handlers
181 * - Execute pending commands
182 * - Transmit pending data packets
184 int mwifiex_main_process(struct mwifiex_adapter *adapter)
189 spin_lock_irqsave(&adapter->main_proc_lock, flags);
191 /* Check if already processing */
192 if (adapter->mwifiex_processing) {
193 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
196 adapter->mwifiex_processing = true;
197 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
201 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
202 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
205 /* For non-USB interfaces, If we process interrupts first, it
206 * would increase RX pending even further. Avoid this by
207 * checking if rx_pending has crossed high threshold and
208 * schedule rx work queue and then process interrupts.
209 * For USB interface, there are no interrupts. We already have
210 * HIGH_RX_PENDING check in usb.c
212 if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
213 adapter->iface_type != MWIFIEX_USB) {
214 adapter->delay_main_work = true;
215 if (!adapter->rx_processing)
216 queue_work(adapter->rx_workqueue,
221 /* Handle pending interrupt if any */
222 if (adapter->int_status) {
223 if (adapter->hs_activated)
224 mwifiex_process_hs_config(adapter);
225 if (adapter->if_ops.process_int_status)
226 adapter->if_ops.process_int_status(adapter);
229 if (adapter->rx_work_enabled && adapter->data_received)
230 queue_work(adapter->rx_workqueue, &adapter->rx_work);
232 /* Need to wake up the card ? */
233 if ((adapter->ps_state == PS_STATE_SLEEP) &&
234 (adapter->pm_wakeup_card_req &&
235 !adapter->pm_wakeup_fw_try) &&
236 (is_command_pending(adapter) ||
237 !mwifiex_wmm_lists_empty(adapter))) {
238 adapter->pm_wakeup_fw_try = true;
239 mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
240 adapter->if_ops.wakeup(adapter);
244 if (IS_CARD_RX_RCVD(adapter)) {
245 adapter->data_received = false;
246 adapter->pm_wakeup_fw_try = false;
247 del_timer_sync(&adapter->wakeup_timer);
248 if (adapter->ps_state == PS_STATE_SLEEP)
249 adapter->ps_state = PS_STATE_AWAKE;
251 /* We have tried to wakeup the card already */
252 if (adapter->pm_wakeup_fw_try)
254 if (adapter->ps_state != PS_STATE_AWAKE ||
255 adapter->tx_lock_flag)
258 if ((!adapter->scan_chan_gap_enabled &&
259 adapter->scan_processing) || adapter->data_sent ||
260 mwifiex_wmm_lists_empty(adapter)) {
261 if (adapter->cmd_sent || adapter->curr_cmd ||
262 (!is_command_pending(adapter)))
267 /* Check for event */
268 if (adapter->event_received) {
269 adapter->event_received = false;
270 mwifiex_process_event(adapter);
273 /* Check for Cmd Resp */
274 if (adapter->cmd_resp_received) {
275 adapter->cmd_resp_received = false;
276 mwifiex_process_cmdresp(adapter);
278 /* call mwifiex back when init_fw is done */
279 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
280 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
281 mwifiex_init_fw_complete(adapter);
285 /* Check if we need to confirm Sleep Request
286 received previously */
287 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
288 if (!adapter->cmd_sent && !adapter->curr_cmd)
289 mwifiex_check_ps_cond(adapter);
292 /* * The ps_state may have been changed during processing of
293 * Sleep Request event.
295 if ((adapter->ps_state == PS_STATE_SLEEP) ||
296 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
297 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
298 adapter->tx_lock_flag)
301 if (!adapter->cmd_sent && !adapter->curr_cmd) {
302 if (mwifiex_exec_next_cmd(adapter) == -1) {
308 if ((adapter->scan_chan_gap_enabled ||
309 !adapter->scan_processing) &&
310 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
311 mwifiex_wmm_process_tx(adapter);
312 if (adapter->hs_activated) {
313 adapter->is_hs_configured = false;
314 mwifiex_hs_activated_event
316 (adapter, MWIFIEX_BSS_ROLE_ANY),
321 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
322 !adapter->curr_cmd && !is_command_pending(adapter) &&
323 mwifiex_wmm_lists_empty(adapter)) {
324 if (!mwifiex_send_null_packet
325 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
326 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
327 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
328 adapter->delay_null_pkt = false;
329 adapter->ps_state = PS_STATE_SLEEP;
335 spin_lock_irqsave(&adapter->main_proc_lock, flags);
336 if (!adapter->delay_main_work &&
337 (adapter->int_status || IS_CARD_RX_RCVD(adapter))) {
338 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
342 adapter->mwifiex_processing = false;
343 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
346 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
347 mwifiex_shutdown_drv(adapter);
350 EXPORT_SYMBOL_GPL(mwifiex_main_process);
353 * This function frees the adapter structure.
355 * Additionally, this closes the netlink socket, frees the timers
356 * and private structures.
358 static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
361 pr_err("%s: adapter is NULL\n", __func__);
365 mwifiex_unregister(adapter);
366 pr_debug("info: %s: free adapter\n", __func__);
370 * This function cancels all works in the queue and destroys
371 * the main workqueue.
373 static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
375 flush_workqueue(adapter->workqueue);
376 destroy_workqueue(adapter->workqueue);
377 adapter->workqueue = NULL;
379 if (adapter->rx_workqueue) {
380 flush_workqueue(adapter->rx_workqueue);
381 destroy_workqueue(adapter->rx_workqueue);
382 adapter->rx_workqueue = NULL;
387 * This function gets firmware and initializes it.
389 * The main initialization steps followed are -
390 * - Download the correct firmware to card
391 * - Issue the init commands to firmware
393 static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
397 struct mwifiex_private *priv;
398 struct mwifiex_adapter *adapter = context;
399 struct mwifiex_fw_image fw;
400 struct semaphore *sem = adapter->card_sem;
401 bool init_failed = false;
402 struct wireless_dev *wdev;
405 dev_err(adapter->dev,
406 "Failed to get firmware %s\n", adapter->fw_name);
410 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
411 adapter->firmware = firmware;
412 fw.fw_buf = (u8 *) adapter->firmware->data;
413 fw.fw_len = adapter->firmware->size;
415 if (adapter->if_ops.dnld_fw)
416 ret = adapter->if_ops.dnld_fw(adapter, &fw);
418 ret = mwifiex_dnld_fw(adapter, &fw);
422 dev_notice(adapter->dev, "WLAN FW is active\n");
425 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
427 dev_err(adapter->dev,
428 "Cal data request_firmware() failed\n");
431 /* enable host interrupt after fw dnld is successful */
432 if (adapter->if_ops.enable_int) {
433 if (adapter->if_ops.enable_int(adapter))
437 adapter->init_wait_q_woken = false;
438 ret = mwifiex_init_fw(adapter);
442 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
445 /* Wait for mwifiex_init to complete */
446 wait_event_interruptible(adapter->init_wait_q,
447 adapter->init_wait_q_woken);
448 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
451 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
452 if (mwifiex_register_cfg80211(adapter)) {
453 dev_err(adapter->dev, "cannot register with cfg80211\n");
457 if (mwifiex_init_channel_scan_gap(adapter)) {
458 dev_err(adapter->dev, "could not init channel stats table\n");
463 driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
464 driver_mode |= MWIFIEX_DRIVER_MODE_STA;
468 /* Create station interface by default */
469 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
470 NL80211_IFTYPE_STATION, NULL, NULL);
472 dev_err(adapter->dev, "cannot create default STA interface\n");
477 if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
478 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d",
479 NL80211_IFTYPE_AP, NULL, NULL);
481 dev_err(adapter->dev, "cannot create AP interface\n");
487 if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
488 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d",
489 NL80211_IFTYPE_P2P_CLIENT, NULL,
492 dev_err(adapter->dev,
493 "cannot create p2p client interface\n");
500 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
501 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
505 wiphy_unregister(adapter->wiphy);
506 wiphy_free(adapter->wiphy);
508 if (adapter->if_ops.disable_int)
509 adapter->if_ops.disable_int(adapter);
511 pr_debug("info: %s: unregister device\n", __func__);
512 if (adapter->if_ops.unregister_dev)
513 adapter->if_ops.unregister_dev(adapter);
515 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
516 pr_debug("info: %s: shutdown mwifiex\n", __func__);
517 adapter->init_wait_q_woken = false;
519 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
520 wait_event_interruptible(adapter->init_wait_q,
521 adapter->init_wait_q_woken);
523 adapter->surprise_removed = true;
524 mwifiex_terminate_workqueue(adapter);
527 if (adapter->cal_data) {
528 release_firmware(adapter->cal_data);
529 adapter->cal_data = NULL;
531 if (adapter->firmware) {
532 release_firmware(adapter->firmware);
533 adapter->firmware = NULL;
536 mwifiex_free_adapter(adapter);
542 * This function initializes the hardware and gets firmware.
544 static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
548 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
549 adapter->dev, GFP_KERNEL, adapter,
552 dev_err(adapter->dev,
553 "request_firmware_nowait() returned error %d\n", ret);
558 * CFG802.11 network device handler for open.
560 * Starts the data queue.
563 mwifiex_open(struct net_device *dev)
565 netif_carrier_off(dev);
571 * CFG802.11 network device handler for close.
574 mwifiex_close(struct net_device *dev)
576 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
578 if (priv->scan_request) {
579 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
580 cfg80211_scan_done(priv->scan_request, 1);
581 priv->scan_request = NULL;
582 priv->scan_aborting = true;
589 * Add buffer into wmm tx queue and queue work to transmit it.
591 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
593 struct netdev_queue *txq;
594 int index = mwifiex_1d_to_wmm_queue[skb->priority];
596 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
597 txq = netdev_get_tx_queue(priv->netdev, index);
598 if (!netif_tx_queue_stopped(txq)) {
599 netif_tx_stop_queue(txq);
600 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
604 atomic_inc(&priv->adapter->tx_pending);
605 mwifiex_wmm_add_buf_txqueue(priv, skb);
607 queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
613 mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
614 struct sk_buff *skb, u8 flag, u64 *cookie)
616 struct sk_buff *orig_skb = skb;
617 struct mwifiex_txinfo *tx_info, *orig_tx_info;
619 skb = skb_clone(skb, GFP_ATOMIC);
624 spin_lock_irqsave(&priv->ack_status_lock, flags);
625 id = idr_alloc(&priv->ack_status_frames, orig_skb,
626 1, 0xff, GFP_ATOMIC);
627 spin_unlock_irqrestore(&priv->ack_status_lock, flags);
630 tx_info = MWIFIEX_SKB_TXCB(skb);
631 tx_info->ack_frame_id = id;
632 tx_info->flags |= flag;
633 orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
634 orig_tx_info->ack_frame_id = id;
635 orig_tx_info->flags |= flag;
637 if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
638 orig_tx_info->cookie = *cookie;
640 } else if (skb_shared(skb)) {
647 /* couldn't clone -- lose tx status ... */
655 * CFG802.11 network device handler for data transmission.
658 mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
660 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
661 struct sk_buff *new_skb;
662 struct mwifiex_txinfo *tx_info;
665 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
666 jiffies, priv->bss_type, priv->bss_num);
668 if (priv->adapter->surprise_removed) {
670 priv->stats.tx_dropped++;
673 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
674 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
676 priv->stats.tx_dropped++;
679 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
680 dev_dbg(priv->adapter->dev,
681 "data: Tx: insufficient skb headroom %d\n",
683 /* Insufficient skb headroom - allocate a new skb */
685 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
686 if (unlikely(!new_skb)) {
687 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
689 priv->stats.tx_dropped++;
694 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
698 tx_info = MWIFIEX_SKB_TXCB(skb);
699 memset(tx_info, 0, sizeof(*tx_info));
700 tx_info->bss_num = priv->bss_num;
701 tx_info->bss_type = priv->bss_type;
702 tx_info->pkt_len = skb->len;
704 multicast = is_multicast_ether_addr(skb->data);
706 if (unlikely(!multicast && skb->sk &&
707 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
708 priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
709 skb = mwifiex_clone_skb_for_tx_status(priv,
711 MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
713 /* Record the current time the packet was queued; used to
714 * determine the amount of time the packet was queued in
715 * the driver before it was sent to the firmware.
716 * The delay is then sent along with the packet to the
717 * firmware for aggregate delay calculation for stats and
718 * MSDU lifetime expiry.
720 __net_timestamp(skb);
722 if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
723 priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
724 !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
725 if (priv->adapter->auto_tdls && priv->check_tdls_tx)
726 mwifiex_tdls_check_tx(priv, skb);
729 mwifiex_queue_tx_pkt(priv, skb);
735 * CFG802.11 network device handler for setting MAC address.
738 mwifiex_set_mac_address(struct net_device *dev, void *addr)
740 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
741 struct sockaddr *hw_addr = addr;
744 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
746 /* Send request to firmware */
747 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
748 HostCmd_ACT_GEN_SET, 0, NULL, true);
751 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
753 dev_err(priv->adapter->dev,
754 "set mac address failed: ret=%d\n", ret);
756 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
762 * CFG802.11 network device handler for setting multicast list.
764 static void mwifiex_set_multicast_list(struct net_device *dev)
766 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
767 struct mwifiex_multicast_list mcast_list;
769 if (dev->flags & IFF_PROMISC) {
770 mcast_list.mode = MWIFIEX_PROMISC_MODE;
771 } else if (dev->flags & IFF_ALLMULTI ||
772 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
773 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
775 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
776 mcast_list.num_multicast_addr =
777 mwifiex_copy_mcast_addr(&mcast_list, dev);
779 mwifiex_request_set_multicast_list(priv, &mcast_list);
783 * CFG802.11 network device handler for transmission timeout.
786 mwifiex_tx_timeout(struct net_device *dev)
788 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
790 priv->num_tx_timeout++;
791 priv->tx_timeout_cnt++;
792 dev_err(priv->adapter->dev,
793 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
794 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
795 mwifiex_set_trans_start(dev);
797 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
798 priv->adapter->if_ops.card_reset) {
799 dev_err(priv->adapter->dev,
800 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
801 priv->adapter->if_ops.card_reset(priv->adapter);
805 void mwifiex_dump_drv_info(struct mwifiex_adapter *adapter)
808 char drv_version[64];
809 struct usb_card_rec *cardp;
810 struct sdio_mmc_card *sdio_card;
811 struct mwifiex_private *priv;
813 struct netdev_queue *txq;
814 struct mwifiex_debug_info *debug_info;
816 if (adapter->drv_info_dump) {
817 vfree(adapter->drv_info_dump);
818 adapter->drv_info_size = 0;
821 dev_info(adapter->dev, "=== DRIVER INFO DUMP START===\n");
823 adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
825 if (!adapter->drv_info_dump)
828 p = (char *)(adapter->drv_info_dump);
829 p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
831 mwifiex_drv_get_driver_version(adapter, drv_version,
832 sizeof(drv_version) - 1);
833 p += sprintf(p, "driver_version = %s\n", drv_version);
835 if (adapter->iface_type == MWIFIEX_USB) {
836 cardp = (struct usb_card_rec *)adapter->card;
837 p += sprintf(p, "tx_cmd_urb_pending = %d\n",
838 atomic_read(&cardp->tx_cmd_urb_pending));
839 p += sprintf(p, "tx_data_urb_pending = %d\n",
840 atomic_read(&cardp->tx_data_urb_pending));
841 p += sprintf(p, "rx_cmd_urb_pending = %d\n",
842 atomic_read(&cardp->rx_cmd_urb_pending));
843 p += sprintf(p, "rx_data_urb_pending = %d\n",
844 atomic_read(&cardp->rx_data_urb_pending));
847 p += sprintf(p, "tx_pending = %d\n",
848 atomic_read(&adapter->tx_pending));
849 p += sprintf(p, "rx_pending = %d\n",
850 atomic_read(&adapter->rx_pending));
852 if (adapter->iface_type == MWIFIEX_SDIO) {
853 sdio_card = (struct sdio_mmc_card *)adapter->card;
854 p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
855 sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
856 p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
857 sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
860 for (i = 0; i < adapter->priv_num; i++) {
861 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
863 priv = adapter->priv[i];
864 p += sprintf(p, "\n[interface : \"%s\"]\n",
866 p += sprintf(p, "wmm_tx_pending[0] = %d\n",
867 atomic_read(&priv->wmm_tx_pending[0]));
868 p += sprintf(p, "wmm_tx_pending[1] = %d\n",
869 atomic_read(&priv->wmm_tx_pending[1]));
870 p += sprintf(p, "wmm_tx_pending[2] = %d\n",
871 atomic_read(&priv->wmm_tx_pending[2]));
872 p += sprintf(p, "wmm_tx_pending[3] = %d\n",
873 atomic_read(&priv->wmm_tx_pending[3]));
874 p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
875 "Disconnected" : "Connected");
876 p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
878 for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
879 txq = netdev_get_tx_queue(priv->netdev, idx);
880 p += sprintf(p, "tx queue %d:%s ", idx,
881 netif_tx_queue_stopped(txq) ?
882 "stopped" : "started");
884 p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
885 priv->netdev->name, priv->num_tx_timeout);
888 if (adapter->iface_type == MWIFIEX_SDIO) {
889 p += sprintf(p, "\n=== SDIO register DUMP===\n");
890 if (adapter->if_ops.reg_dump)
891 p += adapter->if_ops.reg_dump(adapter, p);
894 p += sprintf(p, "\n=== MORE DEBUG INFORMATION\n");
895 debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
897 for (i = 0; i < adapter->priv_num; i++) {
898 if (!adapter->priv[i] || !adapter->priv[i]->netdev)
900 priv = adapter->priv[i];
901 mwifiex_get_debug_info(priv, debug_info);
902 p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
908 adapter->drv_info_size = p - adapter->drv_info_dump;
909 dev_info(adapter->dev, "=== DRIVER INFO DUMP END===\n");
911 EXPORT_SYMBOL_GPL(mwifiex_dump_drv_info);
914 * CFG802.11 network device handler for statistics retrieval.
916 static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
918 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
924 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
925 void *accel_priv, select_queue_fallback_t fallback)
927 skb->priority = cfg80211_classify8021d(skb, NULL);
928 return mwifiex_1d_to_wmm_queue[skb->priority];
931 /* Network device handlers */
932 static const struct net_device_ops mwifiex_netdev_ops = {
933 .ndo_open = mwifiex_open,
934 .ndo_stop = mwifiex_close,
935 .ndo_start_xmit = mwifiex_hard_start_xmit,
936 .ndo_set_mac_address = mwifiex_set_mac_address,
937 .ndo_tx_timeout = mwifiex_tx_timeout,
938 .ndo_get_stats = mwifiex_get_stats,
939 .ndo_set_rx_mode = mwifiex_set_multicast_list,
940 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
944 * This function initializes the private structure parameters.
946 * The following wait queues are initialized -
948 * - Command wait queue
949 * - Statistics wait queue
951 * ...and the following default parameters are set -
952 * - Current key index : Set to 0
953 * - Rate index : Set to auto
954 * - Media connected : Set to disconnected
955 * - Adhoc link sensed : Set to false
956 * - Nick name : Set to null
957 * - Number of Tx timeout : Set to 0
958 * - Device address : Set to current address
959 * - Rx histogram statistc : Set to 0
961 * In addition, the CFG80211 work queue is also created.
963 void mwifiex_init_priv_params(struct mwifiex_private *priv,
964 struct net_device *dev)
966 dev->netdev_ops = &mwifiex_netdev_ops;
967 dev->destructor = free_netdev;
968 /* Initialize private structure */
969 priv->current_key_index = 0;
970 priv->media_connected = false;
971 memset(priv->mgmt_ie, 0,
972 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
973 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
974 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
975 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
976 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
977 priv->num_tx_timeout = 0;
978 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
980 if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
981 GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
982 priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
984 mwifiex_hist_data_reset(priv);
989 * This function check if command is pending.
991 int is_command_pending(struct mwifiex_adapter *adapter)
994 int is_cmd_pend_q_empty;
996 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
997 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
998 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
1000 return !is_cmd_pend_q_empty;
1004 * This is the RX work queue function.
1006 * It handles the RX operations.
1008 static void mwifiex_rx_work_queue(struct work_struct *work)
1010 struct mwifiex_adapter *adapter =
1011 container_of(work, struct mwifiex_adapter, rx_work);
1013 if (adapter->surprise_removed)
1015 mwifiex_process_rx(adapter);
1019 * This is the main work queue function.
1021 * It handles the main process, which in turn handles the complete
1022 * driver operations.
1024 static void mwifiex_main_work_queue(struct work_struct *work)
1026 struct mwifiex_adapter *adapter =
1027 container_of(work, struct mwifiex_adapter, main_work);
1029 if (adapter->surprise_removed)
1031 mwifiex_main_process(adapter);
1035 * This function adds the card.
1037 * This function follows the following major steps to set up the device -
1038 * - Initialize software. This includes probing the card, registering
1039 * the interface operations table, and allocating/initializing the
1041 * - Set up the netlink socket
1042 * - Create and start the main work queue
1043 * - Register the device
1044 * - Initialize firmware and hardware
1045 * - Add logical interfaces
1048 mwifiex_add_card(void *card, struct semaphore *sem,
1049 struct mwifiex_if_ops *if_ops, u8 iface_type)
1051 struct mwifiex_adapter *adapter;
1053 if (down_interruptible(sem))
1056 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
1057 pr_err("%s: software init failed\n", __func__);
1061 adapter->iface_type = iface_type;
1062 adapter->card_sem = sem;
1064 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
1065 adapter->surprise_removed = false;
1066 init_waitqueue_head(&adapter->init_wait_q);
1067 adapter->is_suspended = false;
1068 adapter->hs_activated = false;
1069 init_waitqueue_head(&adapter->hs_activate_wait_q);
1070 init_waitqueue_head(&adapter->cmd_wait_q.wait);
1071 adapter->cmd_wait_q.status = 0;
1072 adapter->scan_wait_q_woken = false;
1074 if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
1075 adapter->rx_work_enabled = true;
1076 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
1079 adapter->workqueue =
1080 alloc_workqueue("MWIFIEX_WORK_QUEUE",
1081 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
1082 if (!adapter->workqueue)
1085 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
1087 if (adapter->rx_work_enabled) {
1088 adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
1092 if (!adapter->rx_workqueue)
1095 INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
1098 if (adapter->if_ops.iface_work)
1099 INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work);
1101 /* Register the device. Fill up the private data structure with relevant
1102 information from the card. */
1103 if (adapter->if_ops.register_dev(adapter)) {
1104 pr_err("%s: failed to register mwifiex device\n", __func__);
1105 goto err_registerdev;
1108 if (mwifiex_init_hw_fw(adapter)) {
1109 pr_err("%s: firmware init failed\n", __func__);
1116 pr_debug("info: %s: unregister device\n", __func__);
1117 if (adapter->if_ops.unregister_dev)
1118 adapter->if_ops.unregister_dev(adapter);
1119 if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
1120 pr_debug("info: %s: shutdown mwifiex\n", __func__);
1121 adapter->init_wait_q_woken = false;
1123 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1124 wait_event_interruptible(adapter->init_wait_q,
1125 adapter->init_wait_q_woken);
1128 adapter->surprise_removed = true;
1129 mwifiex_terminate_workqueue(adapter);
1131 mwifiex_free_adapter(adapter);
1139 EXPORT_SYMBOL_GPL(mwifiex_add_card);
1142 * This function removes the card.
1144 * This function follows the following major steps to remove the device -
1145 * - Stop data traffic
1146 * - Shutdown firmware
1147 * - Remove the logical interfaces
1148 * - Terminate the work queue
1149 * - Unregister the device
1150 * - Free the adapter structure
1152 int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
1154 struct mwifiex_private *priv = NULL;
1157 if (down_interruptible(sem))
1163 /* We can no longer handle interrupts once we start doing the teardown
1165 if (adapter->if_ops.disable_int)
1166 adapter->if_ops.disable_int(adapter);
1168 adapter->surprise_removed = true;
1170 mwifiex_terminate_workqueue(adapter);
1173 for (i = 0; i < adapter->priv_num; i++) {
1174 priv = adapter->priv[i];
1175 if (priv && priv->netdev) {
1176 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1177 if (netif_carrier_ok(priv->netdev))
1178 netif_carrier_off(priv->netdev);
1182 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
1183 adapter->init_wait_q_woken = false;
1185 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
1186 wait_event_interruptible(adapter->init_wait_q,
1187 adapter->init_wait_q_woken);
1188 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
1189 if (atomic_read(&adapter->rx_pending) ||
1190 atomic_read(&adapter->tx_pending) ||
1191 atomic_read(&adapter->cmd_pending)) {
1192 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
1194 atomic_read(&adapter->rx_pending),
1195 atomic_read(&adapter->tx_pending),
1196 atomic_read(&adapter->cmd_pending));
1199 for (i = 0; i < adapter->priv_num; i++) {
1200 priv = adapter->priv[i];
1206 if (priv->wdev && priv->netdev)
1207 mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev);
1211 wiphy_unregister(adapter->wiphy);
1212 wiphy_free(adapter->wiphy);
1214 /* Unregister device */
1215 dev_dbg(adapter->dev, "info: unregister device\n");
1216 if (adapter->if_ops.unregister_dev)
1217 adapter->if_ops.unregister_dev(adapter);
1218 /* Free adapter structure */
1219 dev_dbg(adapter->dev, "info: free adapter\n");
1220 mwifiex_free_adapter(adapter);
1227 EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1230 * This function initializes the module.
1232 * The debug FS is also initialized if configured.
1235 mwifiex_init_module(void)
1237 #ifdef CONFIG_DEBUG_FS
1238 mwifiex_debugfs_init();
1244 * This function cleans up the module.
1246 * The debug FS is removed if available.
1249 mwifiex_cleanup_module(void)
1251 #ifdef CONFIG_DEBUG_FS
1252 mwifiex_debugfs_remove();
1256 module_init(mwifiex_init_module);
1257 module_exit(mwifiex_cleanup_module);
1259 MODULE_AUTHOR("Marvell International Ltd.");
1260 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1261 MODULE_VERSION(VERSION);
1262 MODULE_LICENSE("GPL v2");