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 void scan_delay_timer_fn(unsigned long data)
33 struct mwifiex_private *priv = (struct mwifiex_private *)data;
34 struct mwifiex_adapter *adapter = priv->adapter;
35 struct cmd_ctrl_node *cmd_node, *tmp_node;
36 spinlock_t *scan_q_lock = &adapter->scan_pending_q_lock;
39 if (adapter->surprise_removed)
42 if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT ||
43 !adapter->scan_processing) {
45 * Abort scan operation by cancelling all pending scan
48 spin_lock_irqsave(scan_q_lock, flags);
49 list_for_each_entry_safe(cmd_node, tmp_node,
50 &adapter->scan_pending_q, list) {
51 list_del(&cmd_node->list);
52 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
54 spin_unlock_irqrestore(scan_q_lock, flags);
56 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
57 adapter->scan_processing = false;
58 adapter->scan_delay_cnt = 0;
59 adapter->empty_tx_q_cnt = 0;
60 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock, flags);
62 if (priv->scan_request) {
63 dev_dbg(adapter->dev, "info: aborting scan\n");
64 cfg80211_scan_done(priv->scan_request, 1);
65 priv->scan_request = NULL;
67 priv->scan_aborting = false;
68 dev_dbg(adapter->dev, "info: scan already aborted\n");
73 if (!atomic_read(&priv->adapter->is_tx_received)) {
74 adapter->empty_tx_q_cnt++;
75 if (adapter->empty_tx_q_cnt == MWIFIEX_MAX_EMPTY_TX_Q_CNT) {
77 * No Tx traffic for 200msec. Get scan command from
78 * scan pending queue and put to cmd pending queue to
79 * resume scan operation
81 adapter->scan_delay_cnt = 0;
82 adapter->empty_tx_q_cnt = 0;
83 spin_lock_irqsave(scan_q_lock, flags);
85 if (list_empty(&adapter->scan_pending_q)) {
86 spin_unlock_irqrestore(scan_q_lock, flags);
90 cmd_node = list_first_entry(&adapter->scan_pending_q,
91 struct cmd_ctrl_node, list);
92 list_del(&cmd_node->list);
93 spin_unlock_irqrestore(scan_q_lock, flags);
95 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
97 queue_work(adapter->workqueue, &adapter->main_work);
101 adapter->empty_tx_q_cnt = 0;
104 /* Delay scan operation further by 20msec */
105 mod_timer(&priv->scan_delay_timer, jiffies +
106 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
107 adapter->scan_delay_cnt++;
110 if (atomic_read(&priv->adapter->is_tx_received))
111 atomic_set(&priv->adapter->is_tx_received, false);
117 * This function registers the device and performs all the necessary
120 * The following initialization operations are performed -
121 * - Allocate adapter structure
122 * - Save interface specific operations table in adapter
123 * - Call interface specific initialization routine
124 * - Allocate private structures
125 * - Set default adapter structure parameters
128 * In case of any errors during inittialization, this function also ensures
129 * proper cleanup before exiting.
131 static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
134 struct mwifiex_adapter *adapter;
137 adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
142 adapter->card = card;
144 /* Save interface specific operations in adapter */
145 memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
147 /* card specific initialization has been deferred until now .. */
148 if (adapter->if_ops.init_if)
149 if (adapter->if_ops.init_if(adapter))
152 adapter->priv_num = 0;
154 for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
155 /* Allocate memory for private structure */
157 kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
158 if (!adapter->priv[i])
161 adapter->priv[i]->adapter = adapter;
164 setup_timer(&adapter->priv[i]->scan_delay_timer,
166 (unsigned long)adapter->priv[i]);
168 mwifiex_init_lock_list(adapter);
170 init_timer(&adapter->cmd_timer);
171 adapter->cmd_timer.function = mwifiex_cmd_timeout_func;
172 adapter->cmd_timer.data = (unsigned long) adapter;
177 dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
179 for (i = 0; i < adapter->priv_num; i++)
180 kfree(adapter->priv[i]);
188 * This function unregisters the device and performs all the necessary
191 * The following cleanup operations are performed -
193 * - Free beacon buffers
194 * - Free private structures
195 * - Free adapter structure
197 static int mwifiex_unregister(struct mwifiex_adapter *adapter)
201 if (adapter->if_ops.cleanup_if)
202 adapter->if_ops.cleanup_if(adapter);
204 del_timer_sync(&adapter->cmd_timer);
206 /* Free private structures */
207 for (i = 0; i < adapter->priv_num; i++) {
208 if (adapter->priv[i]) {
209 mwifiex_free_curr_bcn(adapter->priv[i]);
210 del_timer_sync(&adapter->priv[i]->scan_delay_timer);
211 kfree(adapter->priv[i]);
222 * This function is the main procedure of the driver and handles various driver
223 * operations. It runs in a loop and provides the core functionalities.
225 * The main responsibilities of this function are -
226 * - Ensure concurrency control
227 * - Handle pending interrupts and call interrupt handlers
228 * - Wake up the card if required
229 * - Handle command responses and call response handlers
230 * - Handle events and call event handlers
231 * - Execute pending commands
232 * - Transmit pending data packets
234 int mwifiex_main_process(struct mwifiex_adapter *adapter)
240 spin_lock_irqsave(&adapter->main_proc_lock, flags);
242 /* Check if already processing */
243 if (adapter->mwifiex_processing) {
244 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
247 adapter->mwifiex_processing = true;
248 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
252 if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
253 (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
256 /* Handle pending interrupt if any */
257 if (adapter->int_status) {
258 if (adapter->hs_activated)
259 mwifiex_process_hs_config(adapter);
260 if (adapter->if_ops.process_int_status)
261 adapter->if_ops.process_int_status(adapter);
264 /* Need to wake up the card ? */
265 if ((adapter->ps_state == PS_STATE_SLEEP) &&
266 (adapter->pm_wakeup_card_req &&
267 !adapter->pm_wakeup_fw_try) &&
268 (is_command_pending(adapter) ||
269 !mwifiex_wmm_lists_empty(adapter))) {
270 adapter->pm_wakeup_fw_try = true;
271 adapter->if_ops.wakeup(adapter);
275 if (IS_CARD_RX_RCVD(adapter)) {
276 adapter->pm_wakeup_fw_try = false;
277 if (adapter->ps_state == PS_STATE_SLEEP)
278 adapter->ps_state = PS_STATE_AWAKE;
280 /* We have tried to wakeup the card already */
281 if (adapter->pm_wakeup_fw_try)
283 if (adapter->ps_state != PS_STATE_AWAKE ||
284 adapter->tx_lock_flag)
287 if ((adapter->scan_processing &&
288 !adapter->scan_delay_cnt) || adapter->data_sent ||
289 mwifiex_wmm_lists_empty(adapter)) {
290 if (adapter->cmd_sent || adapter->curr_cmd ||
291 (!is_command_pending(adapter)))
296 /* Check Rx data for USB */
297 if (adapter->iface_type == MWIFIEX_USB)
298 while ((skb = skb_dequeue(&adapter->usb_rx_data_q)))
299 mwifiex_handle_rx_packet(adapter, skb);
301 /* Check for event */
302 if (adapter->event_received) {
303 adapter->event_received = false;
304 mwifiex_process_event(adapter);
307 /* Check for Cmd Resp */
308 if (adapter->cmd_resp_received) {
309 adapter->cmd_resp_received = false;
310 mwifiex_process_cmdresp(adapter);
312 /* call mwifiex back when init_fw is done */
313 if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
314 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
315 mwifiex_init_fw_complete(adapter);
319 /* Check if we need to confirm Sleep Request
320 received previously */
321 if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
322 if (!adapter->cmd_sent && !adapter->curr_cmd)
323 mwifiex_check_ps_cond(adapter);
326 /* * The ps_state may have been changed during processing of
327 * Sleep Request event.
329 if ((adapter->ps_state == PS_STATE_SLEEP) ||
330 (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
331 (adapter->ps_state == PS_STATE_SLEEP_CFM) ||
332 adapter->tx_lock_flag)
335 if (!adapter->cmd_sent && !adapter->curr_cmd) {
336 if (mwifiex_exec_next_cmd(adapter) == -1) {
342 if ((!adapter->scan_processing || adapter->scan_delay_cnt) &&
343 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
344 mwifiex_wmm_process_tx(adapter);
345 if (adapter->hs_activated) {
346 adapter->is_hs_configured = false;
347 mwifiex_hs_activated_event
349 (adapter, MWIFIEX_BSS_ROLE_ANY),
354 if (adapter->delay_null_pkt && !adapter->cmd_sent &&
355 !adapter->curr_cmd && !is_command_pending(adapter) &&
356 mwifiex_wmm_lists_empty(adapter)) {
357 if (!mwifiex_send_null_packet
358 (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
359 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
360 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
361 adapter->delay_null_pkt = false;
362 adapter->ps_state = PS_STATE_SLEEP;
368 spin_lock_irqsave(&adapter->main_proc_lock, flags);
369 if ((adapter->int_status) || IS_CARD_RX_RCVD(adapter)) {
370 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
374 adapter->mwifiex_processing = false;
375 spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
378 if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
379 mwifiex_shutdown_drv(adapter);
382 EXPORT_SYMBOL_GPL(mwifiex_main_process);
385 * This function frees the adapter structure.
387 * Additionally, this closes the netlink socket, frees the timers
388 * and private structures.
390 static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
393 pr_err("%s: adapter is NULL\n", __func__);
397 mwifiex_unregister(adapter);
398 pr_debug("info: %s: free adapter\n", __func__);
402 * This function cancels all works in the queue and destroys
403 * the main workqueue.
405 static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
407 flush_workqueue(adapter->workqueue);
408 destroy_workqueue(adapter->workqueue);
409 adapter->workqueue = NULL;
413 * This function gets firmware and initializes it.
415 * The main initialization steps followed are -
416 * - Download the correct firmware to card
417 * - Issue the init commands to firmware
419 static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
423 struct mwifiex_private *priv;
424 struct mwifiex_adapter *adapter = context;
425 struct mwifiex_fw_image fw;
426 struct semaphore *sem = adapter->card_sem;
427 bool init_failed = false;
428 struct wireless_dev *wdev;
431 dev_err(adapter->dev,
432 "Failed to get firmware %s\n", adapter->fw_name);
436 memset(&fw, 0, sizeof(struct mwifiex_fw_image));
437 adapter->firmware = firmware;
438 fw.fw_buf = (u8 *) adapter->firmware->data;
439 fw.fw_len = adapter->firmware->size;
441 if (adapter->if_ops.dnld_fw)
442 ret = adapter->if_ops.dnld_fw(adapter, &fw);
444 ret = mwifiex_dnld_fw(adapter, &fw);
448 dev_notice(adapter->dev, "WLAN FW is active\n");
451 if ((request_firmware(&adapter->cal_data, cal_data_cfg,
453 dev_err(adapter->dev,
454 "Cal data request_firmware() failed\n");
457 /* enable host interrupt after fw dnld is successful */
458 if (adapter->if_ops.enable_int) {
459 if (adapter->if_ops.enable_int(adapter))
463 adapter->init_wait_q_woken = false;
464 ret = mwifiex_init_fw(adapter);
468 adapter->hw_status = MWIFIEX_HW_STATUS_READY;
471 /* Wait for mwifiex_init to complete */
472 wait_event_interruptible(adapter->init_wait_q,
473 adapter->init_wait_q_woken);
474 if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
477 priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
478 if (mwifiex_register_cfg80211(adapter)) {
479 dev_err(adapter->dev, "cannot register with cfg80211\n");
484 /* Create station interface by default */
485 wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d",
486 NL80211_IFTYPE_STATION, NULL, NULL);
488 dev_err(adapter->dev, "cannot create default STA interface\n");
494 mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
495 dev_notice(adapter->dev, "driver_version = %s\n", fmt);
499 wiphy_unregister(adapter->wiphy);
500 wiphy_free(adapter->wiphy);
502 if (adapter->if_ops.disable_int)
503 adapter->if_ops.disable_int(adapter);
505 pr_debug("info: %s: unregister device\n", __func__);
506 if (adapter->if_ops.unregister_dev)
507 adapter->if_ops.unregister_dev(adapter);
509 if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) ||
510 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
511 pr_debug("info: %s: shutdown mwifiex\n", __func__);
512 adapter->init_wait_q_woken = false;
514 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
515 wait_event_interruptible(adapter->init_wait_q,
516 adapter->init_wait_q_woken);
518 adapter->surprise_removed = true;
519 mwifiex_terminate_workqueue(adapter);
522 if (adapter->cal_data) {
523 release_firmware(adapter->cal_data);
524 adapter->cal_data = NULL;
526 if (adapter->firmware) {
527 release_firmware(adapter->firmware);
528 adapter->firmware = NULL;
531 mwifiex_free_adapter(adapter);
537 * This function initializes the hardware and gets firmware.
539 static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
543 ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
544 adapter->dev, GFP_KERNEL, adapter,
547 dev_err(adapter->dev,
548 "request_firmware_nowait() returned error %d\n", ret);
553 * CFG802.11 network device handler for open.
555 * Starts the data queue.
558 mwifiex_open(struct net_device *dev)
560 netif_tx_start_all_queues(dev);
565 * CFG802.11 network device handler for close.
568 mwifiex_close(struct net_device *dev)
570 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
572 if (priv->scan_request) {
573 dev_dbg(priv->adapter->dev, "aborting scan on ndo_stop\n");
574 cfg80211_scan_done(priv->scan_request, 1);
575 priv->scan_request = NULL;
576 priv->scan_aborting = true;
583 * Add buffer into wmm tx queue and queue work to transmit it.
585 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
587 struct netdev_queue *txq;
588 int index = mwifiex_1d_to_wmm_queue[skb->priority];
590 if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
591 txq = netdev_get_tx_queue(priv->netdev, index);
592 if (!netif_tx_queue_stopped(txq)) {
593 netif_tx_stop_queue(txq);
594 dev_dbg(priv->adapter->dev, "stop queue: %d\n", index);
598 atomic_inc(&priv->adapter->tx_pending);
599 mwifiex_wmm_add_buf_txqueue(priv, skb);
601 if (priv->adapter->scan_delay_cnt)
602 atomic_set(&priv->adapter->is_tx_received, true);
604 queue_work(priv->adapter->workqueue, &priv->adapter->main_work);
610 * CFG802.11 network device handler for data transmission.
613 mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
615 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
616 struct sk_buff *new_skb;
617 struct mwifiex_txinfo *tx_info;
619 dev_dbg(priv->adapter->dev, "data: %lu BSS(%d-%d): Data <= kernel\n",
620 jiffies, priv->bss_type, priv->bss_num);
622 if (priv->adapter->surprise_removed) {
624 priv->stats.tx_dropped++;
627 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
628 dev_err(priv->adapter->dev, "Tx: bad skb len %d\n", skb->len);
630 priv->stats.tx_dropped++;
633 if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
634 dev_dbg(priv->adapter->dev,
635 "data: Tx: insufficient skb headroom %d\n",
637 /* Insufficient skb headroom - allocate a new skb */
639 skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
640 if (unlikely(!new_skb)) {
641 dev_err(priv->adapter->dev, "Tx: cannot alloca new_skb\n");
643 priv->stats.tx_dropped++;
648 dev_dbg(priv->adapter->dev, "info: new skb headroomd %d\n",
652 tx_info = MWIFIEX_SKB_TXCB(skb);
653 memset(tx_info, 0, sizeof(*tx_info));
654 tx_info->bss_num = priv->bss_num;
655 tx_info->bss_type = priv->bss_type;
656 tx_info->pkt_len = skb->len;
658 /* Record the current time the packet was queued; used to
659 * determine the amount of time the packet was queued in
660 * the driver before it was sent to the firmware.
661 * The delay is then sent along with the packet to the
662 * firmware for aggregate delay calculation for stats and
663 * MSDU lifetime expiry.
665 __net_timestamp(skb);
667 mwifiex_queue_tx_pkt(priv, skb);
673 * CFG802.11 network device handler for setting MAC address.
676 mwifiex_set_mac_address(struct net_device *dev, void *addr)
678 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
679 struct sockaddr *hw_addr = addr;
682 memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
684 /* Send request to firmware */
685 ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
686 HostCmd_ACT_GEN_SET, 0, NULL, true);
689 memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
691 dev_err(priv->adapter->dev,
692 "set mac address failed: ret=%d\n", ret);
694 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
700 * CFG802.11 network device handler for setting multicast list.
702 static void mwifiex_set_multicast_list(struct net_device *dev)
704 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
705 struct mwifiex_multicast_list mcast_list;
707 if (dev->flags & IFF_PROMISC) {
708 mcast_list.mode = MWIFIEX_PROMISC_MODE;
709 } else if (dev->flags & IFF_ALLMULTI ||
710 netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
711 mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
713 mcast_list.mode = MWIFIEX_MULTICAST_MODE;
714 mcast_list.num_multicast_addr =
715 mwifiex_copy_mcast_addr(&mcast_list, dev);
717 mwifiex_request_set_multicast_list(priv, &mcast_list);
721 * CFG802.11 network device handler for transmission timeout.
724 mwifiex_tx_timeout(struct net_device *dev)
726 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
728 priv->num_tx_timeout++;
729 priv->tx_timeout_cnt++;
730 dev_err(priv->adapter->dev,
731 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
732 jiffies, priv->tx_timeout_cnt, priv->bss_type, priv->bss_num);
733 mwifiex_set_trans_start(dev);
735 if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
736 priv->adapter->if_ops.card_reset) {
737 dev_err(priv->adapter->dev,
738 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
739 priv->adapter->if_ops.card_reset(priv->adapter);
744 * CFG802.11 network device handler for statistics retrieval.
746 static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
748 struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
754 mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
755 void *accel_priv, select_queue_fallback_t fallback)
757 skb->priority = cfg80211_classify8021d(skb, NULL);
758 return mwifiex_1d_to_wmm_queue[skb->priority];
761 /* Network device handlers */
762 static const struct net_device_ops mwifiex_netdev_ops = {
763 .ndo_open = mwifiex_open,
764 .ndo_stop = mwifiex_close,
765 .ndo_start_xmit = mwifiex_hard_start_xmit,
766 .ndo_set_mac_address = mwifiex_set_mac_address,
767 .ndo_tx_timeout = mwifiex_tx_timeout,
768 .ndo_get_stats = mwifiex_get_stats,
769 .ndo_set_rx_mode = mwifiex_set_multicast_list,
770 .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
774 * This function initializes the private structure parameters.
776 * The following wait queues are initialized -
778 * - Command wait queue
779 * - Statistics wait queue
781 * ...and the following default parameters are set -
782 * - Current key index : Set to 0
783 * - Rate index : Set to auto
784 * - Media connected : Set to disconnected
785 * - Adhoc link sensed : Set to false
786 * - Nick name : Set to null
787 * - Number of Tx timeout : Set to 0
788 * - Device address : Set to current address
790 * In addition, the CFG80211 work queue is also created.
792 void mwifiex_init_priv_params(struct mwifiex_private *priv,
793 struct net_device *dev)
795 dev->netdev_ops = &mwifiex_netdev_ops;
796 dev->destructor = free_netdev;
797 /* Initialize private structure */
798 priv->current_key_index = 0;
799 priv->media_connected = false;
800 memset(&priv->nick_name, 0, sizeof(priv->nick_name));
801 memset(priv->mgmt_ie, 0,
802 sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
803 priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
804 priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
805 priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
806 priv->rsn_idx = MWIFIEX_AUTO_IDX_MASK;
807 priv->num_tx_timeout = 0;
808 memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
812 * This function check if command is pending.
814 int is_command_pending(struct mwifiex_adapter *adapter)
817 int is_cmd_pend_q_empty;
819 spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
820 is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
821 spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
823 return !is_cmd_pend_q_empty;
827 * This is the main work queue function.
829 * It handles the main process, which in turn handles the complete
832 static void mwifiex_main_work_queue(struct work_struct *work)
834 struct mwifiex_adapter *adapter =
835 container_of(work, struct mwifiex_adapter, main_work);
837 if (adapter->surprise_removed)
839 mwifiex_main_process(adapter);
843 * This function adds the card.
845 * This function follows the following major steps to set up the device -
846 * - Initialize software. This includes probing the card, registering
847 * the interface operations table, and allocating/initializing the
849 * - Set up the netlink socket
850 * - Create and start the main work queue
851 * - Register the device
852 * - Initialize firmware and hardware
853 * - Add logical interfaces
856 mwifiex_add_card(void *card, struct semaphore *sem,
857 struct mwifiex_if_ops *if_ops, u8 iface_type)
859 struct mwifiex_adapter *adapter;
861 if (down_interruptible(sem))
864 if (mwifiex_register(card, if_ops, (void **)&adapter)) {
865 pr_err("%s: software init failed\n", __func__);
869 adapter->iface_type = iface_type;
870 adapter->card_sem = sem;
872 adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
873 adapter->surprise_removed = false;
874 init_waitqueue_head(&adapter->init_wait_q);
875 adapter->is_suspended = false;
876 adapter->hs_activated = false;
877 init_waitqueue_head(&adapter->hs_activate_wait_q);
878 init_waitqueue_head(&adapter->cmd_wait_q.wait);
879 adapter->cmd_wait_q.status = 0;
880 adapter->scan_wait_q_woken = false;
883 alloc_workqueue("MWIFIEX_WORK_QUEUE",
884 WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
885 if (!adapter->workqueue)
888 INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
889 if (adapter->if_ops.iface_work)
890 INIT_WORK(&adapter->iface_work, adapter->if_ops.iface_work);
892 /* Register the device. Fill up the private data structure with relevant
893 information from the card. */
894 if (adapter->if_ops.register_dev(adapter)) {
895 pr_err("%s: failed to register mwifiex device\n", __func__);
896 goto err_registerdev;
899 if (mwifiex_init_hw_fw(adapter)) {
900 pr_err("%s: firmware init failed\n", __func__);
907 pr_debug("info: %s: unregister device\n", __func__);
908 if (adapter->if_ops.unregister_dev)
909 adapter->if_ops.unregister_dev(adapter);
910 if ((adapter->hw_status == MWIFIEX_HW_STATUS_FW_READY) ||
911 (adapter->hw_status == MWIFIEX_HW_STATUS_READY)) {
912 pr_debug("info: %s: shutdown mwifiex\n", __func__);
913 adapter->init_wait_q_woken = false;
915 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
916 wait_event_interruptible(adapter->init_wait_q,
917 adapter->init_wait_q_woken);
920 adapter->surprise_removed = true;
921 mwifiex_terminate_workqueue(adapter);
923 mwifiex_free_adapter(adapter);
931 EXPORT_SYMBOL_GPL(mwifiex_add_card);
934 * This function removes the card.
936 * This function follows the following major steps to remove the device -
937 * - Stop data traffic
938 * - Shutdown firmware
939 * - Remove the logical interfaces
940 * - Terminate the work queue
941 * - Unregister the device
942 * - Free the adapter structure
944 int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
946 struct mwifiex_private *priv = NULL;
949 if (down_interruptible(sem))
955 /* We can no longer handle interrupts once we start doing the teardown
957 if (adapter->if_ops.disable_int)
958 adapter->if_ops.disable_int(adapter);
960 adapter->surprise_removed = true;
963 for (i = 0; i < adapter->priv_num; i++) {
964 priv = adapter->priv[i];
965 if (priv && priv->netdev) {
966 mwifiex_stop_net_dev_queue(priv->netdev, adapter);
967 if (netif_carrier_ok(priv->netdev))
968 netif_carrier_off(priv->netdev);
972 dev_dbg(adapter->dev, "cmd: calling mwifiex_shutdown_drv...\n");
973 adapter->init_wait_q_woken = false;
975 if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
976 wait_event_interruptible(adapter->init_wait_q,
977 adapter->init_wait_q_woken);
978 dev_dbg(adapter->dev, "cmd: mwifiex_shutdown_drv done\n");
979 if (atomic_read(&adapter->rx_pending) ||
980 atomic_read(&adapter->tx_pending) ||
981 atomic_read(&adapter->cmd_pending)) {
982 dev_err(adapter->dev, "rx_pending=%d, tx_pending=%d, "
984 atomic_read(&adapter->rx_pending),
985 atomic_read(&adapter->tx_pending),
986 atomic_read(&adapter->cmd_pending));
989 for (i = 0; i < adapter->priv_num; i++) {
990 priv = adapter->priv[i];
996 if (priv->wdev && priv->netdev)
997 mwifiex_del_virtual_intf(adapter->wiphy, priv->wdev);
1001 wiphy_unregister(adapter->wiphy);
1002 wiphy_free(adapter->wiphy);
1004 mwifiex_terminate_workqueue(adapter);
1006 /* Unregister device */
1007 dev_dbg(adapter->dev, "info: unregister device\n");
1008 if (adapter->if_ops.unregister_dev)
1009 adapter->if_ops.unregister_dev(adapter);
1010 /* Free adapter structure */
1011 dev_dbg(adapter->dev, "info: free adapter\n");
1012 mwifiex_free_adapter(adapter);
1019 EXPORT_SYMBOL_GPL(mwifiex_remove_card);
1022 * This function initializes the module.
1024 * The debug FS is also initialized if configured.
1027 mwifiex_init_module(void)
1029 #ifdef CONFIG_DEBUG_FS
1030 mwifiex_debugfs_init();
1036 * This function cleans up the module.
1038 * The debug FS is removed if available.
1041 mwifiex_cleanup_module(void)
1043 #ifdef CONFIG_DEBUG_FS
1044 mwifiex_debugfs_remove();
1048 module_init(mwifiex_init_module);
1049 module_exit(mwifiex_cleanup_module);
1051 MODULE_AUTHOR("Marvell International Ltd.");
1052 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
1053 MODULE_VERSION(VERSION);
1054 MODULE_LICENSE("GPL v2");