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
]);
129 static int mwifiex_process_rx(struct mwifiex_adapter
*adapter
)
134 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
135 if (adapter
->rx_processing
|| adapter
->rx_locked
) {
136 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
139 adapter
->rx_processing
= true;
140 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
143 /* Check for Rx data */
144 while ((skb
= skb_dequeue(&adapter
->rx_data_q
))) {
145 atomic_dec(&adapter
->rx_pending
);
146 if (adapter
->delay_main_work
&&
147 (atomic_read(&adapter
->rx_pending
) < LOW_RX_PENDING
)) {
148 adapter
->delay_main_work
= false;
149 queue_work(adapter
->workqueue
, &adapter
->main_work
);
151 mwifiex_handle_rx_packet(adapter
, skb
);
153 spin_lock_irqsave(&adapter
->rx_proc_lock
, flags
);
154 adapter
->rx_processing
= false;
155 spin_unlock_irqrestore(&adapter
->rx_proc_lock
, flags
);
164 * This function is the main procedure of the driver and handles various driver
165 * operations. It runs in a loop and provides the core functionalities.
167 * The main responsibilities of this function are -
168 * - Ensure concurrency control
169 * - Handle pending interrupts and call interrupt handlers
170 * - Wake up the card if required
171 * - Handle command responses and call response handlers
172 * - Handle events and call event handlers
173 * - Execute pending commands
174 * - Transmit pending data packets
176 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
182 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
184 /* Check if already processing */
185 if (adapter
->mwifiex_processing
) {
186 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
189 adapter
->mwifiex_processing
= true;
190 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
194 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
195 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
198 /* If we process interrupts first, it would increase RX pending
199 * even further. Avoid this by checking if rx_pending has
200 * crossed high threshold and schedule rx work queue
201 * and then process interrupts
203 if (atomic_read(&adapter
->rx_pending
) >= HIGH_RX_PENDING
) {
204 adapter
->delay_main_work
= true;
205 if (!adapter
->rx_processing
)
206 queue_work(adapter
->rx_workqueue
,
211 /* Handle pending interrupt if any */
212 if (adapter
->int_status
) {
213 if (adapter
->hs_activated
)
214 mwifiex_process_hs_config(adapter
);
215 if (adapter
->if_ops
.process_int_status
)
216 adapter
->if_ops
.process_int_status(adapter
);
219 if (adapter
->rx_work_enabled
&& adapter
->data_received
)
220 queue_work(adapter
->rx_workqueue
, &adapter
->rx_work
);
222 /* Need to wake up the card ? */
223 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
224 (adapter
->pm_wakeup_card_req
&&
225 !adapter
->pm_wakeup_fw_try
) &&
226 (is_command_pending(adapter
) ||
227 !mwifiex_wmm_lists_empty(adapter
))) {
228 adapter
->pm_wakeup_fw_try
= true;
229 adapter
->if_ops
.wakeup(adapter
);
233 if (IS_CARD_RX_RCVD(adapter
)) {
234 adapter
->data_received
= false;
235 adapter
->pm_wakeup_fw_try
= false;
236 if (adapter
->ps_state
== PS_STATE_SLEEP
)
237 adapter
->ps_state
= PS_STATE_AWAKE
;
239 /* We have tried to wakeup the card already */
240 if (adapter
->pm_wakeup_fw_try
)
242 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
243 adapter
->tx_lock_flag
)
246 if ((!adapter
->scan_chan_gap_enabled
&&
247 adapter
->scan_processing
) || adapter
->data_sent
||
248 mwifiex_wmm_lists_empty(adapter
)) {
249 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
250 (!is_command_pending(adapter
)))
255 /* Check Rx data for USB */
256 if (adapter
->iface_type
== MWIFIEX_USB
)
257 while ((skb
= skb_dequeue(&adapter
->usb_rx_data_q
)))
258 mwifiex_handle_rx_packet(adapter
, skb
);
260 /* Check for event */
261 if (adapter
->event_received
) {
262 adapter
->event_received
= false;
263 mwifiex_process_event(adapter
);
266 /* Check for Cmd Resp */
267 if (adapter
->cmd_resp_received
) {
268 adapter
->cmd_resp_received
= false;
269 mwifiex_process_cmdresp(adapter
);
271 /* call mwifiex back when init_fw is done */
272 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
273 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
274 mwifiex_init_fw_complete(adapter
);
278 /* Check if we need to confirm Sleep Request
279 received previously */
280 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
281 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
282 mwifiex_check_ps_cond(adapter
);
285 /* * The ps_state may have been changed during processing of
286 * Sleep Request event.
288 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
289 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
290 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
291 adapter
->tx_lock_flag
)
294 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
295 if (mwifiex_exec_next_cmd(adapter
) == -1) {
301 if ((adapter
->scan_chan_gap_enabled
||
302 !adapter
->scan_processing
) &&
303 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
304 mwifiex_wmm_process_tx(adapter
);
305 if (adapter
->hs_activated
) {
306 adapter
->is_hs_configured
= false;
307 mwifiex_hs_activated_event
309 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
314 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
315 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
316 mwifiex_wmm_lists_empty(adapter
)) {
317 if (!mwifiex_send_null_packet
318 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
319 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
320 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
321 adapter
->delay_null_pkt
= false;
322 adapter
->ps_state
= PS_STATE_SLEEP
;
328 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
329 if (!adapter
->delay_main_work
&&
330 (adapter
->int_status
|| IS_CARD_RX_RCVD(adapter
))) {
331 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
335 adapter
->mwifiex_processing
= false;
336 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
339 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
340 mwifiex_shutdown_drv(adapter
);
343 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
346 * This function frees the adapter structure.
348 * Additionally, this closes the netlink socket, frees the timers
349 * and private structures.
351 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
354 pr_err("%s: adapter is NULL\n", __func__
);
358 mwifiex_unregister(adapter
);
359 pr_debug("info: %s: free adapter\n", __func__
);
363 * This function cancels all works in the queue and destroys
364 * the main workqueue.
366 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
368 flush_workqueue(adapter
->workqueue
);
369 destroy_workqueue(adapter
->workqueue
);
370 adapter
->workqueue
= NULL
;
372 if (adapter
->rx_workqueue
) {
373 flush_workqueue(adapter
->rx_workqueue
);
374 destroy_workqueue(adapter
->rx_workqueue
);
375 adapter
->rx_workqueue
= NULL
;
380 * This function gets firmware and initializes it.
382 * The main initialization steps followed are -
383 * - Download the correct firmware to card
384 * - Issue the init commands to firmware
386 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
390 struct mwifiex_private
*priv
;
391 struct mwifiex_adapter
*adapter
= context
;
392 struct mwifiex_fw_image fw
;
393 struct semaphore
*sem
= adapter
->card_sem
;
394 bool init_failed
= false;
395 struct wireless_dev
*wdev
;
398 dev_err(adapter
->dev
,
399 "Failed to get firmware %s\n", adapter
->fw_name
);
403 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
404 adapter
->firmware
= firmware
;
405 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
406 fw
.fw_len
= adapter
->firmware
->size
;
408 if (adapter
->if_ops
.dnld_fw
)
409 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
411 ret
= mwifiex_dnld_fw(adapter
, &fw
);
415 dev_notice(adapter
->dev
, "WLAN FW is active\n");
418 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
420 dev_err(adapter
->dev
,
421 "Cal data request_firmware() failed\n");
424 /* enable host interrupt after fw dnld is successful */
425 if (adapter
->if_ops
.enable_int
) {
426 if (adapter
->if_ops
.enable_int(adapter
))
430 adapter
->init_wait_q_woken
= false;
431 ret
= mwifiex_init_fw(adapter
);
435 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
438 /* Wait for mwifiex_init to complete */
439 wait_event_interruptible(adapter
->init_wait_q
,
440 adapter
->init_wait_q_woken
);
441 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
444 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
445 if (mwifiex_register_cfg80211(adapter
)) {
446 dev_err(adapter
->dev
, "cannot register with cfg80211\n");
451 /* Create station interface by default */
452 wdev
= mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
453 NL80211_IFTYPE_STATION
, NULL
, NULL
);
455 dev_err(adapter
->dev
, "cannot create default STA interface\n");
461 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
462 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
466 wiphy_unregister(adapter
->wiphy
);
467 wiphy_free(adapter
->wiphy
);
469 if (adapter
->if_ops
.disable_int
)
470 adapter
->if_ops
.disable_int(adapter
);
472 pr_debug("info: %s: unregister device\n", __func__
);
473 if (adapter
->if_ops
.unregister_dev
)
474 adapter
->if_ops
.unregister_dev(adapter
);
476 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
477 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
478 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
479 adapter
->init_wait_q_woken
= false;
481 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
482 wait_event_interruptible(adapter
->init_wait_q
,
483 adapter
->init_wait_q_woken
);
485 adapter
->surprise_removed
= true;
486 mwifiex_terminate_workqueue(adapter
);
489 if (adapter
->cal_data
) {
490 release_firmware(adapter
->cal_data
);
491 adapter
->cal_data
= NULL
;
493 if (adapter
->firmware
) {
494 release_firmware(adapter
->firmware
);
495 adapter
->firmware
= NULL
;
498 mwifiex_free_adapter(adapter
);
504 * This function initializes the hardware and gets firmware.
506 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
510 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
511 adapter
->dev
, GFP_KERNEL
, adapter
,
514 dev_err(adapter
->dev
,
515 "request_firmware_nowait() returned error %d\n", ret
);
520 * CFG802.11 network device handler for open.
522 * Starts the data queue.
525 mwifiex_open(struct net_device
*dev
)
527 netif_tx_start_all_queues(dev
);
532 * CFG802.11 network device handler for close.
535 mwifiex_close(struct net_device
*dev
)
537 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
539 if (priv
->scan_request
) {
540 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
541 cfg80211_scan_done(priv
->scan_request
, 1);
542 priv
->scan_request
= NULL
;
543 priv
->scan_aborting
= true;
550 * Add buffer into wmm tx queue and queue work to transmit it.
552 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
554 struct netdev_queue
*txq
;
555 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
557 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
558 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
559 if (!netif_tx_queue_stopped(txq
)) {
560 netif_tx_stop_queue(txq
);
561 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
565 atomic_inc(&priv
->adapter
->tx_pending
);
566 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
568 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
574 * CFG802.11 network device handler for data transmission.
577 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
579 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
580 struct sk_buff
*new_skb
;
581 struct mwifiex_txinfo
*tx_info
;
583 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
584 jiffies
, priv
->bss_type
, priv
->bss_num
);
586 if (priv
->adapter
->surprise_removed
) {
588 priv
->stats
.tx_dropped
++;
591 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
592 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
594 priv
->stats
.tx_dropped
++;
597 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
598 dev_dbg(priv
->adapter
->dev
,
599 "data: Tx: insufficient skb headroom %d\n",
601 /* Insufficient skb headroom - allocate a new skb */
603 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
604 if (unlikely(!new_skb
)) {
605 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
607 priv
->stats
.tx_dropped
++;
612 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
616 tx_info
= MWIFIEX_SKB_TXCB(skb
);
617 memset(tx_info
, 0, sizeof(*tx_info
));
618 tx_info
->bss_num
= priv
->bss_num
;
619 tx_info
->bss_type
= priv
->bss_type
;
620 tx_info
->pkt_len
= skb
->len
;
622 /* Record the current time the packet was queued; used to
623 * determine the amount of time the packet was queued in
624 * the driver before it was sent to the firmware.
625 * The delay is then sent along with the packet to the
626 * firmware for aggregate delay calculation for stats and
627 * MSDU lifetime expiry.
629 __net_timestamp(skb
);
631 mwifiex_queue_tx_pkt(priv
, skb
);
637 * CFG802.11 network device handler for setting MAC address.
640 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
642 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
643 struct sockaddr
*hw_addr
= addr
;
646 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
648 /* Send request to firmware */
649 ret
= mwifiex_send_cmd(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
650 HostCmd_ACT_GEN_SET
, 0, NULL
, true);
653 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
655 dev_err(priv
->adapter
->dev
,
656 "set mac address failed: ret=%d\n", ret
);
658 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
664 * CFG802.11 network device handler for setting multicast list.
666 static void mwifiex_set_multicast_list(struct net_device
*dev
)
668 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
669 struct mwifiex_multicast_list mcast_list
;
671 if (dev
->flags
& IFF_PROMISC
) {
672 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
673 } else if (dev
->flags
& IFF_ALLMULTI
||
674 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
675 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
677 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
678 mcast_list
.num_multicast_addr
=
679 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
681 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
685 * CFG802.11 network device handler for transmission timeout.
688 mwifiex_tx_timeout(struct net_device
*dev
)
690 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
692 priv
->num_tx_timeout
++;
693 priv
->tx_timeout_cnt
++;
694 dev_err(priv
->adapter
->dev
,
695 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
696 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
697 mwifiex_set_trans_start(dev
);
699 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
700 priv
->adapter
->if_ops
.card_reset
) {
701 dev_err(priv
->adapter
->dev
,
702 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
703 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
708 * CFG802.11 network device handler for statistics retrieval.
710 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
712 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
718 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
,
719 void *accel_priv
, select_queue_fallback_t fallback
)
721 skb
->priority
= cfg80211_classify8021d(skb
, NULL
);
722 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
725 /* Network device handlers */
726 static const struct net_device_ops mwifiex_netdev_ops
= {
727 .ndo_open
= mwifiex_open
,
728 .ndo_stop
= mwifiex_close
,
729 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
730 .ndo_set_mac_address
= mwifiex_set_mac_address
,
731 .ndo_tx_timeout
= mwifiex_tx_timeout
,
732 .ndo_get_stats
= mwifiex_get_stats
,
733 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
734 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
738 * This function initializes the private structure parameters.
740 * The following wait queues are initialized -
742 * - Command wait queue
743 * - Statistics wait queue
745 * ...and the following default parameters are set -
746 * - Current key index : Set to 0
747 * - Rate index : Set to auto
748 * - Media connected : Set to disconnected
749 * - Adhoc link sensed : Set to false
750 * - Nick name : Set to null
751 * - Number of Tx timeout : Set to 0
752 * - Device address : Set to current address
754 * In addition, the CFG80211 work queue is also created.
756 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
757 struct net_device
*dev
)
759 dev
->netdev_ops
= &mwifiex_netdev_ops
;
760 dev
->destructor
= free_netdev
;
761 /* Initialize private structure */
762 priv
->current_key_index
= 0;
763 priv
->media_connected
= false;
764 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
765 memset(priv
->mgmt_ie
, 0,
766 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
767 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
768 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
769 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
770 priv
->rsn_idx
= MWIFIEX_AUTO_IDX_MASK
;
771 priv
->num_tx_timeout
= 0;
772 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
776 * This function check if command is pending.
778 int is_command_pending(struct mwifiex_adapter
*adapter
)
781 int is_cmd_pend_q_empty
;
783 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
784 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
785 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
787 return !is_cmd_pend_q_empty
;
791 * This is the RX work queue function.
793 * It handles the RX operations.
795 static void mwifiex_rx_work_queue(struct work_struct
*work
)
797 struct mwifiex_adapter
*adapter
=
798 container_of(work
, struct mwifiex_adapter
, rx_work
);
800 if (adapter
->surprise_removed
)
802 mwifiex_process_rx(adapter
);
806 * This is the main work queue function.
808 * It handles the main process, which in turn handles the complete
811 static void mwifiex_main_work_queue(struct work_struct
*work
)
813 struct mwifiex_adapter
*adapter
=
814 container_of(work
, struct mwifiex_adapter
, main_work
);
816 if (adapter
->surprise_removed
)
818 mwifiex_main_process(adapter
);
822 * This function adds the card.
824 * This function follows the following major steps to set up the device -
825 * - Initialize software. This includes probing the card, registering
826 * the interface operations table, and allocating/initializing the
828 * - Set up the netlink socket
829 * - Create and start the main work queue
830 * - Register the device
831 * - Initialize firmware and hardware
832 * - Add logical interfaces
835 mwifiex_add_card(void *card
, struct semaphore
*sem
,
836 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
838 struct mwifiex_adapter
*adapter
;
840 if (down_interruptible(sem
))
843 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
844 pr_err("%s: software init failed\n", __func__
);
848 adapter
->iface_type
= iface_type
;
849 adapter
->card_sem
= sem
;
851 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
852 adapter
->surprise_removed
= false;
853 init_waitqueue_head(&adapter
->init_wait_q
);
854 adapter
->is_suspended
= false;
855 adapter
->hs_activated
= false;
856 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
857 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
858 adapter
->cmd_wait_q
.status
= 0;
859 adapter
->scan_wait_q_woken
= false;
861 if (num_possible_cpus() > 1) {
862 adapter
->rx_work_enabled
= true;
863 pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
867 alloc_workqueue("MWIFIEX_WORK_QUEUE",
868 WQ_HIGHPRI
| WQ_MEM_RECLAIM
| WQ_UNBOUND
, 1);
869 if (!adapter
->workqueue
)
872 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
874 if (adapter
->rx_work_enabled
) {
875 adapter
->rx_workqueue
= alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
879 if (!adapter
->rx_workqueue
)
882 INIT_WORK(&adapter
->rx_work
, mwifiex_rx_work_queue
);
885 if (adapter
->if_ops
.iface_work
)
886 INIT_WORK(&adapter
->iface_work
, adapter
->if_ops
.iface_work
);
888 /* Register the device. Fill up the private data structure with relevant
889 information from the card. */
890 if (adapter
->if_ops
.register_dev(adapter
)) {
891 pr_err("%s: failed to register mwifiex device\n", __func__
);
892 goto err_registerdev
;
895 if (mwifiex_init_hw_fw(adapter
)) {
896 pr_err("%s: firmware init failed\n", __func__
);
903 pr_debug("info: %s: unregister device\n", __func__
);
904 if (adapter
->if_ops
.unregister_dev
)
905 adapter
->if_ops
.unregister_dev(adapter
);
906 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
907 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
908 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
909 adapter
->init_wait_q_woken
= false;
911 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
912 wait_event_interruptible(adapter
->init_wait_q
,
913 adapter
->init_wait_q_woken
);
916 adapter
->surprise_removed
= true;
917 mwifiex_terminate_workqueue(adapter
);
919 mwifiex_free_adapter(adapter
);
927 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
930 * This function removes the card.
932 * This function follows the following major steps to remove the device -
933 * - Stop data traffic
934 * - Shutdown firmware
935 * - Remove the logical interfaces
936 * - Terminate the work queue
937 * - Unregister the device
938 * - Free the adapter structure
940 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
942 struct mwifiex_private
*priv
= NULL
;
945 if (down_interruptible(sem
))
951 /* We can no longer handle interrupts once we start doing the teardown
953 if (adapter
->if_ops
.disable_int
)
954 adapter
->if_ops
.disable_int(adapter
);
956 adapter
->surprise_removed
= true;
959 for (i
= 0; i
< adapter
->priv_num
; i
++) {
960 priv
= adapter
->priv
[i
];
961 if (priv
&& priv
->netdev
) {
962 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
963 if (netif_carrier_ok(priv
->netdev
))
964 netif_carrier_off(priv
->netdev
);
968 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
969 adapter
->init_wait_q_woken
= false;
971 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
972 wait_event_interruptible(adapter
->init_wait_q
,
973 adapter
->init_wait_q_woken
);
974 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
975 if (atomic_read(&adapter
->rx_pending
) ||
976 atomic_read(&adapter
->tx_pending
) ||
977 atomic_read(&adapter
->cmd_pending
)) {
978 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
980 atomic_read(&adapter
->rx_pending
),
981 atomic_read(&adapter
->tx_pending
),
982 atomic_read(&adapter
->cmd_pending
));
985 for (i
= 0; i
< adapter
->priv_num
; i
++) {
986 priv
= adapter
->priv
[i
];
992 if (priv
->wdev
&& priv
->netdev
)
993 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
997 wiphy_unregister(adapter
->wiphy
);
998 wiphy_free(adapter
->wiphy
);
1000 mwifiex_terminate_workqueue(adapter
);
1002 /* Unregister device */
1003 dev_dbg(adapter
->dev
, "info: unregister device\n");
1004 if (adapter
->if_ops
.unregister_dev
)
1005 adapter
->if_ops
.unregister_dev(adapter
);
1006 /* Free adapter structure */
1007 dev_dbg(adapter
->dev
, "info: free adapter\n");
1008 mwifiex_free_adapter(adapter
);
1015 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1018 * This function initializes the module.
1020 * The debug FS is also initialized if configured.
1023 mwifiex_init_module(void)
1025 #ifdef CONFIG_DEBUG_FS
1026 mwifiex_debugfs_init();
1032 * This function cleans up the module.
1034 * The debug FS is removed if available.
1037 mwifiex_cleanup_module(void)
1039 #ifdef CONFIG_DEBUG_FS
1040 mwifiex_debugfs_remove();
1044 module_init(mwifiex_init_module
);
1045 module_exit(mwifiex_cleanup_module
);
1047 MODULE_AUTHOR("Marvell International Ltd.");
1048 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1049 MODULE_VERSION(VERSION
);
1050 MODULE_LICENSE("GPL v2");