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);
32 * This function registers the device and performs all the necessary
35 * The following initialization operations are performed -
36 * - Allocate adapter structure
37 * - Save interface specific operations table in adapter
38 * - Call interface specific initialization routine
39 * - Allocate private structures
40 * - Set default adapter structure parameters
43 * In case of any errors during inittialization, this function also ensures
44 * proper cleanup before exiting.
46 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
49 struct mwifiex_adapter
*adapter
;
52 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
59 /* Save interface specific operations in adapter */
60 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
62 /* card specific initialization has been deferred until now .. */
63 if (adapter
->if_ops
.init_if
)
64 if (adapter
->if_ops
.init_if(adapter
))
67 adapter
->priv_num
= 0;
69 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
70 /* Allocate memory for private structure */
72 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
73 if (!adapter
->priv
[i
])
76 adapter
->priv
[i
]->adapter
= adapter
;
79 mwifiex_init_lock_list(adapter
);
81 init_timer(&adapter
->cmd_timer
);
82 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
83 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
88 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
90 for (i
= 0; i
< adapter
->priv_num
; i
++)
91 kfree(adapter
->priv
[i
]);
99 * This function unregisters the device and performs all the necessary
102 * The following cleanup operations are performed -
104 * - Free beacon buffers
105 * - Free private structures
106 * - Free adapter structure
108 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
112 if (adapter
->if_ops
.cleanup_if
)
113 adapter
->if_ops
.cleanup_if(adapter
);
115 del_timer_sync(&adapter
->cmd_timer
);
117 /* Free private structures */
118 for (i
= 0; i
< adapter
->priv_num
; i
++) {
119 if (adapter
->priv
[i
]) {
120 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
121 kfree(adapter
->priv
[i
]);
125 vfree(adapter
->chan_stats
);
130 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
135 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
136 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
137 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
140 adapter
->rx_processing
= true;
141 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
144 /* Check for Rx data */
145 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
146 atomic_dec(&adapter
->rx_pending
);
147 if (adapter
->delay_main_work
&&
148 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
149 if (adapter
->if_ops
.submit_rem_rx_urbs
)
150 adapter
->if_ops
.submit_rem_rx_urbs(adapter
);
151 adapter
->delay_main_work
= false;
152 queue_work(adapter
->workqueue
, &adapter
->main_work
);
154 mwifiex_handle_rx_packet(adapter
, skb
);
156 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
157 adapter
->rx_processing
= false;
158 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
167 * This function is the main procedure of the driver and handles various driver
168 * operations. It runs in a loop and provides the core functionalities.
170 * The main responsibilities of this function are -
171 * - Ensure concurrency control
172 * - Handle pending interrupts and call interrupt handlers
173 * - Wake up the card if required
174 * - Handle command responses and call response handlers
175 * - Handle events and call event handlers
176 * - Execute pending commands
177 * - Transmit pending data packets
179 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
184 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
186 /* Check if already processing */
187 if (adapter
->mwifiex_processing
) {
188 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
191 adapter
->mwifiex_processing
= true;
192 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
196 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
197 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
200 /* If we process interrupts first, it would increase RX pending
201 * even further. Avoid this by checking if rx_pending has
202 * crossed high threshold and schedule rx work queue
203 * and then process interrupts
205 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
) {
206 adapter
->delay_main_work
= true;
207 if (!adapter
->rx_processing
)
208 queue_work(adapter
->rx_workqueue
,
213 /* Handle pending interrupt if any */
214 if (adapter
->int_status
) {
215 if (adapter
->hs_activated
)
216 mwifiex_process_hs_config(adapter
);
217 if (adapter
->if_ops
.process_int_status
)
218 adapter
->if_ops
.process_int_status(adapter
);
221 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
222 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
224 /* Need to wake up the card ? */
225 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
226 (adapter
->pm_wakeup_card_req
&&
227 !adapter
->pm_wakeup_fw_try
) &&
228 (is_command_pending(adapter
) ||
229 !mwifiex_wmm_lists_empty(adapter
))) {
230 adapter
->pm_wakeup_fw_try
= true;
231 adapter
->if_ops
.wakeup(adapter
);
235 if (IS_CARD_RX_RCVD(adapter
)) {
236 adapter
->data_received
= false;
237 adapter
->pm_wakeup_fw_try
= false;
238 if (adapter
->ps_state
== PS_STATE_SLEEP
)
239 adapter
->ps_state
= PS_STATE_AWAKE
;
241 /* We have tried to wakeup the card already */
242 if (adapter
->pm_wakeup_fw_try
)
244 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
245 adapter
->tx_lock_flag
)
248 if ((!adapter
->scan_chan_gap_enabled
&&
249 adapter
->scan_processing
) || adapter
->data_sent
||
250 mwifiex_wmm_lists_empty(adapter
)) {
251 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
252 (!is_command_pending(adapter
)))
257 /* Check for event */
258 if (adapter
->event_received
) {
259 adapter
->event_received
= false;
260 mwifiex_process_event(adapter
);
263 /* Check for Cmd Resp */
264 if (adapter
->cmd_resp_received
) {
265 adapter
->cmd_resp_received
= false;
266 mwifiex_process_cmdresp(adapter
);
268 /* call mwifiex back when init_fw is done */
269 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
270 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
271 mwifiex_init_fw_complete(adapter
);
275 /* Check if we need to confirm Sleep Request
276 received previously */
277 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
278 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
279 mwifiex_check_ps_cond(adapter
);
282 /* * The ps_state may have been changed during processing of
283 * Sleep Request event.
285 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
286 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
287 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
288 adapter
->tx_lock_flag
)
291 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
292 if (mwifiex_exec_next_cmd(adapter
) == -1) {
298 if ((adapter
->scan_chan_gap_enabled
||
299 !adapter
->scan_processing
) &&
300 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
301 mwifiex_wmm_process_tx(adapter
);
302 if (adapter
->hs_activated
) {
303 adapter
->is_hs_configured
= false;
304 mwifiex_hs_activated_event
306 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
311 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
312 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
313 mwifiex_wmm_lists_empty(adapter
)) {
314 if (!mwifiex_send_null_packet
315 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
316 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
317 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
318 adapter
->delay_null_pkt
= false;
319 adapter
->ps_state
= PS_STATE_SLEEP
;
325 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
326 if (!adapter
->delay_main_work
&&
327 (adapter
->int_status
|| IS_CARD_RX_RCVD(adapter
))) {
328 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
332 adapter
->mwifiex_processing
= false;
333 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
336 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
337 mwifiex_shutdown_drv(adapter
);
340 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
343 * This function frees the adapter structure.
345 * Additionally, this closes the netlink socket, frees the timers
346 * and private structures.
348 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
351 pr_err("%s: adapter is NULL\n", __func__
);
355 mwifiex_unregister(adapter
);
356 pr_debug("info: %s: free adapter\n", __func__
);
360 * This function cancels all works in the queue and destroys
361 * the main workqueue.
363 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
365 flush_workqueue(adapter
->workqueue
);
366 destroy_workqueue(adapter
->workqueue
);
367 adapter
->workqueue
= NULL
;
369 if (adapter
->rx_workqueue
) {
370 flush_workqueue(adapter
->rx_workqueue
);
371 destroy_workqueue(adapter
->rx_workqueue
);
372 adapter
->rx_workqueue
= NULL
;
377 * This function gets firmware and initializes it.
379 * The main initialization steps followed are -
380 * - Download the correct firmware to card
381 * - Issue the init commands to firmware
383 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
387 struct mwifiex_private
*priv
;
388 struct mwifiex_adapter
*adapter
= context
;
389 struct mwifiex_fw_image fw
;
390 struct semaphore
*sem
= adapter
->card_sem
;
391 bool init_failed
= false;
392 struct wireless_dev
*wdev
;
395 dev_err(adapter
->dev
,
396 "Failed to get firmware %s\n", adapter
->fw_name
);
400 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
401 adapter
->firmware
= firmware
;
402 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
403 fw
.fw_len
= adapter
->firmware
->size
;
405 if (adapter
->if_ops
.dnld_fw
)
406 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
408 ret
= mwifiex_dnld_fw(adapter
, &fw
);
412 dev_notice(adapter
->dev
, "WLAN FW is active\n");
415 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
417 dev_err(adapter
->dev
,
418 "Cal data request_firmware() failed\n");
421 /* enable host interrupt after fw dnld is successful */
422 if (adapter
->if_ops
.enable_int
) {
423 if (adapter
->if_ops
.enable_int(adapter
))
427 adapter
->init_wait_q_woken
= false;
428 ret
= mwifiex_init_fw(adapter
);
432 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
435 /* Wait for mwifiex_init to complete */
436 wait_event_interruptible(adapter
->init_wait_q
,
437 adapter
->init_wait_q_woken
);
438 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
441 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
442 if (mwifiex_register_cfg80211(adapter
)) {
443 dev_err(adapter
->dev
, "cannot register with cfg80211\n");
447 if (mwifiex_init_channel_scan_gap(adapter
)) {
448 dev_err(adapter
->dev
, "could not init channel stats table\n");
453 /* Create station interface by default */
454 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
455 NL80211_IFTYPE_STATION
, NULL
, NULL
);
457 dev_err(adapter
->dev
, "cannot create default STA interface\n");
463 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
464 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
468 wiphy_unregister(adapter
->wiphy
);
469 wiphy_free(adapter
->wiphy
);
471 if (adapter
->if_ops
.disable_int
)
472 adapter
->if_ops
.disable_int(adapter
);
474 pr_debug("info: %s: unregister device\n", __func__
);
475 if (adapter
->if_ops
.unregister_dev
)
476 adapter
->if_ops
.unregister_dev(adapter
);
478 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
479 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
480 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
481 adapter
->init_wait_q_woken
= false;
483 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
484 wait_event_interruptible(adapter
->init_wait_q
,
485 adapter
->init_wait_q_woken
);
487 adapter
->surprise_removed
= true;
488 mwifiex_terminate_workqueue(adapter
);
491 if (adapter
->cal_data
) {
492 release_firmware(adapter
->cal_data
);
493 adapter
->cal_data
= NULL
;
495 if (adapter
->firmware
) {
496 release_firmware(adapter
->firmware
);
497 adapter
->firmware
= NULL
;
500 mwifiex_free_adapter(adapter
);
506 * This function initializes the hardware and gets firmware.
508 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
512 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
513 adapter
->dev
, GFP_KERNEL
, adapter
,
516 dev_err(adapter
->dev
,
517 "request_firmware_nowait() returned error %d\n", ret
);
522 * CFG802.11 network device handler for open.
524 * Starts the data queue.
527 mwifiex_open(struct net_device
*dev
)
529 netif_tx_start_all_queues(dev
);
534 * CFG802.11 network device handler for close.
537 mwifiex_close(struct net_device
*dev
)
539 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
541 if (priv
->scan_request
) {
542 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
543 cfg80211_scan_done(priv
->scan_request
, 1);
544 priv
->scan_request
= NULL
;
545 priv
->scan_aborting
= true;
552 * Add buffer into wmm tx queue and queue work to transmit it.
554 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
556 struct netdev_queue
*txq
;
557 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
559 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
560 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
561 if (!netif_tx_queue_stopped(txq
)) {
562 netif_tx_stop_queue(txq
);
563 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
567 atomic_inc(&priv
->adapter
->tx_pending
);
568 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
570 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
576 * CFG802.11 network device handler for data transmission.
579 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
581 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
582 struct sk_buff
*new_skb
;
583 struct mwifiex_txinfo
*tx_info
;
585 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
586 jiffies
, priv
->bss_type
, priv
->bss_num
);
588 if (priv
->adapter
->surprise_removed
) {
590 priv
->stats
.tx_dropped
++;
593 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
594 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
596 priv
->stats
.tx_dropped
++;
599 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
600 dev_dbg(priv
->adapter
->dev
,
601 "data: Tx: insufficient skb headroom %d\n",
603 /* Insufficient skb headroom - allocate a new skb */
605 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
606 if (unlikely(!new_skb
)) {
607 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
609 priv
->stats
.tx_dropped
++;
614 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
618 tx_info
= MWIFIEX_SKB_TXCB(skb
);
619 memset(tx_info
, 0, sizeof(*tx_info
));
620 tx_info
->bss_num
= priv
->bss_num
;
621 tx_info
->bss_type
= priv
->bss_type
;
622 tx_info
->pkt_len
= skb
->len
;
624 /* Record the current time the packet was queued; used to
625 * determine the amount of time the packet was queued in
626 * the driver before it was sent to the firmware.
627 * The delay is then sent along with the packet to the
628 * firmware for aggregate delay calculation for stats and
629 * MSDU lifetime expiry.
631 __net_timestamp(skb
);
633 mwifiex_queue_tx_pkt(priv
, skb
);
639 * CFG802.11 network device handler for setting MAC address.
642 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
644 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
645 struct sockaddr
*hw_addr
= addr
;
648 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
650 /* Send request to firmware */
651 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
652 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
655 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
657 dev_err(priv
->adapter
->dev
,
658 "set mac address failed: ret=%d\n", ret
);
660 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
666 * CFG802.11 network device handler for setting multicast list.
668 static void mwifiex_set_multicast_list(struct net_device
*dev
)
670 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
671 struct mwifiex_multicast_list mcast_list
;
673 if (dev
->flags
& IFF_PROMISC
) {
674 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
675 } else if (dev
->flags
& IFF_ALLMULTI
||
676 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
677 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
679 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
680 mcast_list
.num_multicast_addr
=
681 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
683 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
687 * CFG802.11 network device handler for transmission timeout.
690 mwifiex_tx_timeout(struct net_device
*dev
)
692 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
694 priv
->num_tx_timeout
++;
695 priv
->tx_timeout_cnt
++;
696 dev_err(priv
->adapter
->dev
,
697 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
698 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
699 mwifiex_set_trans_start(dev
);
701 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
702 priv
->adapter
->if_ops
.card_reset
) {
703 dev_err(priv
->adapter
->dev
,
704 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
705 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
710 * CFG802.11 network device handler for statistics retrieval.
712 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
714 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
720 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
721 void *accel_priv
, select_queue_fallback_t fallback
)
723 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
724 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
727 /* Network device handlers */
728 static const struct net_device_ops mwifiex_netdev_ops
= {
729 .ndo_open
= mwifiex_open
,
730 .ndo_stop
= mwifiex_close
,
731 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
732 .ndo_set_mac_address
= mwifiex_set_mac_address
,
733 .ndo_tx_timeout
= mwifiex_tx_timeout
,
734 .ndo_get_stats
= mwifiex_get_stats
,
735 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
736 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
740 * This function initializes the private structure parameters.
742 * The following wait queues are initialized -
744 * - Command wait queue
745 * - Statistics wait queue
747 * ...and the following default parameters are set -
748 * - Current key index : Set to 0
749 * - Rate index : Set to auto
750 * - Media connected : Set to disconnected
751 * - Adhoc link sensed : Set to false
752 * - Nick name : Set to null
753 * - Number of Tx timeout : Set to 0
754 * - Device address : Set to current address
756 * In addition, the CFG80211 work queue is also created.
758 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
759 struct net_device
*dev
)
761 dev
->netdev_ops
= &mwifiex_netdev_ops
;
762 dev
->destructor
= free_netdev
;
763 /* Initialize private structure */
764 priv
->current_key_index
= 0;
765 priv
->media_connected
= false;
766 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
767 memset(priv
->mgmt_ie
, 0,
768 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
769 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
770 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
771 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
772 priv
->rsn_idx
= MWIFIEX_AUTO_IDX_MASK
;
773 priv
->num_tx_timeout
= 0;
774 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
778 * This function check if command is pending.
780 int is_command_pending(struct mwifiex_adapter
*adapter
)
783 int is_cmd_pend_q_empty
;
785 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
786 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
787 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
789 return !is_cmd_pend_q_empty
;
793 * This is the RX work queue function.
795 * It handles the RX operations.
797 static void mwifiex_rx_work_queue(struct work_struct
*work
)
799 struct mwifiex_adapter
*adapter
=
800 container_of(work
, struct mwifiex_adapter
, rx_work
);
802 if (adapter
->surprise_removed
)
804 mwifiex_process_rx(adapter
);
808 * This is the main work queue function.
810 * It handles the main process, which in turn handles the complete
813 static void mwifiex_main_work_queue(struct work_struct
*work
)
815 struct mwifiex_adapter
*adapter
=
816 container_of(work
, struct mwifiex_adapter
, main_work
);
818 if (adapter
->surprise_removed
)
820 mwifiex_main_process(adapter
);
824 * This function adds the card.
826 * This function follows the following major steps to set up the device -
827 * - Initialize software. This includes probing the card, registering
828 * the interface operations table, and allocating/initializing the
830 * - Set up the netlink socket
831 * - Create and start the main work queue
832 * - Register the device
833 * - Initialize firmware and hardware
834 * - Add logical interfaces
837 mwifiex_add_card(void *card
, struct semaphore
*sem
,
838 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
840 struct mwifiex_adapter
*adapter
;
842 if (down_interruptible(sem
))
845 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
846 pr_err("%s: software init failed\n", __func__
);
850 adapter
->iface_type
= iface_type
;
851 adapter
->card_sem
= sem
;
853 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
854 adapter
->surprise_removed
= false;
855 init_waitqueue_head(&adapter
->init_wait_q
);
856 adapter
->is_suspended
= false;
857 adapter
->hs_activated
= false;
858 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
859 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
860 adapter
->cmd_wait_q
.status
= 0;
861 adapter
->scan_wait_q_woken
= false;
863 if ((num_possible_cpus() > 1) || adapter
->iface_type
== MWIFIEX_USB
) {
864 adapter
->rx_work_enabled
= true;
865 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
869 alloc_workqueue("MWIFIEX_WORK_QUEUE",
870 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
871 if (!adapter
->workqueue
)
874 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
876 if (adapter
->rx_work_enabled
) {
877 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
881 if (!adapter
->rx_workqueue
)
884 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
887 if (adapter
->if_ops
.iface_work
)
888 INIT_WORK(&adapter
->iface_work
, adapter
->if_ops
.iface_work
);
890 /* Register the device. Fill up the private data structure with relevant
891 information from the card. */
892 if (adapter
->if_ops
.register_dev(adapter
)) {
893 pr_err("%s: failed to register mwifiex device\n", __func__
);
894 goto err_registerdev
;
897 if (mwifiex_init_hw_fw(adapter
)) {
898 pr_err("%s: firmware init failed\n", __func__
);
905 pr_debug("info: %s: unregister device\n", __func__
);
906 if (adapter
->if_ops
.unregister_dev
)
907 adapter
->if_ops
.unregister_dev(adapter
);
908 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
909 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
910 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
911 adapter
->init_wait_q_woken
= false;
913 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
914 wait_event_interruptible(adapter
->init_wait_q
,
915 adapter
->init_wait_q_woken
);
918 adapter
->surprise_removed
= true;
919 mwifiex_terminate_workqueue(adapter
);
921 mwifiex_free_adapter(adapter
);
929 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
932 * This function removes the card.
934 * This function follows the following major steps to remove the device -
935 * - Stop data traffic
936 * - Shutdown firmware
937 * - Remove the logical interfaces
938 * - Terminate the work queue
939 * - Unregister the device
940 * - Free the adapter structure
942 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
944 struct mwifiex_private
*priv
= NULL
;
947 if (down_interruptible(sem
))
953 /* We can no longer handle interrupts once we start doing the teardown
955 if (adapter
->if_ops
.disable_int
)
956 adapter
->if_ops
.disable_int(adapter
);
958 adapter
->surprise_removed
= true;
961 for (i
= 0; i
< adapter
->priv_num
; i
++) {
962 priv
= adapter
->priv
[i
];
963 if (priv
&& priv
->netdev
) {
964 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
965 if (netif_carrier_ok(priv
->netdev
))
966 netif_carrier_off(priv
->netdev
);
970 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
971 adapter
->init_wait_q_woken
= false;
973 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
974 wait_event_interruptible(adapter
->init_wait_q
,
975 adapter
->init_wait_q_woken
);
976 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
977 if (atomic_read(&adapter
->rx_pending
) ||
978 atomic_read(&adapter
->tx_pending
) ||
979 atomic_read(&adapter
->cmd_pending
)) {
980 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
982 atomic_read(&adapter
->rx_pending
),
983 atomic_read(&adapter
->tx_pending
),
984 atomic_read(&adapter
->cmd_pending
));
987 for (i
= 0; i
< adapter
->priv_num
; i
++) {
988 priv
= adapter
->priv
[i
];
994 if (priv
->wdev
&& priv
->netdev
)
995 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
999 wiphy_unregister(adapter
->wiphy
);
1000 wiphy_free(adapter
->wiphy
);
1002 mwifiex_terminate_workqueue(adapter
);
1004 /* Unregister device */
1005 dev_dbg(adapter
->dev
, "info: unregister device\n");
1006 if (adapter
->if_ops
.unregister_dev
)
1007 adapter
->if_ops
.unregister_dev(adapter
);
1008 /* Free adapter structure */
1009 dev_dbg(adapter
->dev
, "info: free adapter\n");
1010 mwifiex_free_adapter(adapter
);
1017 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1020 * This function initializes the module.
1022 * The debug FS is also initialized if configured.
1025 mwifiex_init_module(void)
1027 #ifdef CONFIG_DEBUG_FS
1028 mwifiex_debugfs_init();
1034 * This function cleans up the module.
1036 * The debug FS is removed if available.
1039 mwifiex_cleanup_module(void)
1041 #ifdef CONFIG_DEBUG_FS
1042 mwifiex_debugfs_remove();
1046 module_init(mwifiex_init_module
);
1047 module_exit(mwifiex_cleanup_module
);
1049 MODULE_AUTHOR("Marvell International Ltd.");
1050 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1051 MODULE_VERSION(VERSION
);
1052 MODULE_LICENSE("GPL v2");