2 * Marvell Wireless LAN device driver: major functions
4 * Copyright (C) 2011, 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
;
38 if (adapter
->surprise_removed
)
41 if (adapter
->scan_delay_cnt
== MWIFIEX_MAX_SCAN_DELAY_CNT
) {
43 * Abort scan operation by cancelling all pending scan
46 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
47 list_for_each_entry_safe(cmd_node
, tmp_node
,
48 &adapter
->scan_pending_q
, list
) {
49 list_del(&cmd_node
->list
);
50 mwifiex_insert_cmd_to_free_q(adapter
, cmd_node
);
52 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
, flags
);
54 spin_lock_irqsave(&adapter
->mwifiex_cmd_lock
, flags
);
55 adapter
->scan_processing
= false;
56 adapter
->scan_delay_cnt
= 0;
57 adapter
->empty_tx_q_cnt
= 0;
58 spin_unlock_irqrestore(&adapter
->mwifiex_cmd_lock
, flags
);
60 if (priv
->scan_request
) {
61 dev_dbg(adapter
->dev
, "info: aborting scan\n");
62 cfg80211_scan_done(priv
->scan_request
, 1);
63 priv
->scan_request
= NULL
;
65 priv
->scan_aborting
= false;
66 dev_dbg(adapter
->dev
, "info: scan already aborted\n");
71 if (!atomic_read(&priv
->adapter
->is_tx_received
)) {
72 adapter
->empty_tx_q_cnt
++;
73 if (adapter
->empty_tx_q_cnt
== MWIFIEX_MAX_EMPTY_TX_Q_CNT
) {
75 * No Tx traffic for 200msec. Get scan command from
76 * scan pending queue and put to cmd pending queue to
77 * resume scan operation
79 adapter
->scan_delay_cnt
= 0;
80 adapter
->empty_tx_q_cnt
= 0;
81 spin_lock_irqsave(&adapter
->scan_pending_q_lock
, flags
);
82 cmd_node
= list_first_entry(&adapter
->scan_pending_q
,
83 struct cmd_ctrl_node
, list
);
84 list_del(&cmd_node
->list
);
85 spin_unlock_irqrestore(&adapter
->scan_pending_q_lock
,
88 mwifiex_insert_cmd_to_pending_q(adapter
, cmd_node
,
90 queue_work(adapter
->workqueue
, &adapter
->main_work
);
94 adapter
->empty_tx_q_cnt
= 0;
97 /* Delay scan operation further by 20msec */
98 mod_timer(&priv
->scan_delay_timer
, jiffies
+
99 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC
));
100 adapter
->scan_delay_cnt
++;
103 if (atomic_read(&priv
->adapter
->is_tx_received
))
104 atomic_set(&priv
->adapter
->is_tx_received
, false);
110 * This function registers the device and performs all the necessary
113 * The following initialization operations are performed -
114 * - Allocate adapter structure
115 * - Save interface specific operations table in adapter
116 * - Call interface specific initialization routine
117 * - Allocate private structures
118 * - Set default adapter structure parameters
121 * In case of any errors during inittialization, this function also ensures
122 * proper cleanup before exiting.
124 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
127 struct mwifiex_adapter
*adapter
;
130 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
135 adapter
->card
= card
;
137 /* Save interface specific operations in adapter */
138 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
140 /* card specific initialization has been deferred until now .. */
141 if (adapter
->if_ops
.init_if
)
142 if (adapter
->if_ops
.init_if(adapter
))
145 adapter
->priv_num
= 0;
147 for (i
= 0; i
< MWIFIEX_MAX_BSS_NUM
; i
++) {
148 /* Allocate memory for private structure */
150 kzalloc(sizeof(struct mwifiex_private
), GFP_KERNEL
);
151 if (!adapter
->priv
[i
])
154 adapter
->priv
[i
]->adapter
= adapter
;
157 setup_timer(&adapter
->priv
[i
]->scan_delay_timer
,
159 (unsigned long)adapter
->priv
[i
]);
161 mwifiex_init_lock_list(adapter
);
163 init_timer(&adapter
->cmd_timer
);
164 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
165 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
170 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
172 for (i
= 0; i
< adapter
->priv_num
; i
++)
173 kfree(adapter
->priv
[i
]);
181 * This function unregisters the device and performs all the necessary
184 * The following cleanup operations are performed -
186 * - Free beacon buffers
187 * - Free private structures
188 * - Free adapter structure
190 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
194 del_timer(&adapter
->cmd_timer
);
196 /* Free private structures */
197 for (i
= 0; i
< adapter
->priv_num
; i
++) {
198 if (adapter
->priv
[i
]) {
199 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
200 kfree(adapter
->priv
[i
]);
211 * This function is the main procedure of the driver and handles various driver
212 * operations. It runs in a loop and provides the core functionalities.
214 * The main responsibilities of this function are -
215 * - Ensure concurrency control
216 * - Handle pending interrupts and call interrupt handlers
217 * - Wake up the card if required
218 * - Handle command responses and call response handlers
219 * - Handle events and call event handlers
220 * - Execute pending commands
221 * - Transmit pending data packets
223 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
229 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
231 /* Check if already processing */
232 if (adapter
->mwifiex_processing
) {
233 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
236 adapter
->mwifiex_processing
= true;
237 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
241 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
242 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
245 /* Handle pending interrupt if any */
246 if (adapter
->int_status
) {
247 if (adapter
->hs_activated
)
248 mwifiex_process_hs_config(adapter
);
249 if (adapter
->if_ops
.process_int_status
)
250 adapter
->if_ops
.process_int_status(adapter
);
253 /* Need to wake up the card ? */
254 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
255 (adapter
->pm_wakeup_card_req
&&
256 !adapter
->pm_wakeup_fw_try
) &&
257 (is_command_pending(adapter
) ||
258 !mwifiex_wmm_lists_empty(adapter
))) {
259 adapter
->pm_wakeup_fw_try
= true;
260 adapter
->if_ops
.wakeup(adapter
);
264 if (IS_CARD_RX_RCVD(adapter
)) {
265 adapter
->pm_wakeup_fw_try
= false;
266 if (adapter
->ps_state
== PS_STATE_SLEEP
)
267 adapter
->ps_state
= PS_STATE_AWAKE
;
269 /* We have tried to wakeup the card already */
270 if (adapter
->pm_wakeup_fw_try
)
272 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
273 adapter
->tx_lock_flag
)
276 if ((adapter
->scan_processing
&&
277 !adapter
->scan_delay_cnt
) || adapter
->data_sent
||
278 mwifiex_wmm_lists_empty(adapter
)) {
279 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
280 (!is_command_pending(adapter
)))
285 /* Check Rx data for USB */
286 if (adapter
->iface_type
== MWIFIEX_USB
)
287 while ((skb
= skb_dequeue(&adapter
->usb_rx_data_q
)))
288 mwifiex_handle_rx_packet(adapter
, skb
);
290 /* Check for Cmd Resp */
291 if (adapter
->cmd_resp_received
) {
292 adapter
->cmd_resp_received
= false;
293 mwifiex_process_cmdresp(adapter
);
295 /* call mwifiex back when init_fw is done */
296 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
297 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
298 mwifiex_init_fw_complete(adapter
);
302 /* Check for event */
303 if (adapter
->event_received
) {
304 adapter
->event_received
= false;
305 mwifiex_process_event(adapter
);
308 /* Check if we need to confirm Sleep Request
309 received previously */
310 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
311 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
312 mwifiex_check_ps_cond(adapter
);
315 /* * The ps_state may have been changed during processing of
316 * Sleep Request event.
318 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
319 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
320 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
321 adapter
->tx_lock_flag
)
324 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
325 if (mwifiex_exec_next_cmd(adapter
) == -1) {
331 if ((!adapter
->scan_processing
|| adapter
->scan_delay_cnt
) &&
332 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
333 mwifiex_wmm_process_tx(adapter
);
334 if (adapter
->hs_activated
) {
335 adapter
->is_hs_configured
= false;
336 mwifiex_hs_activated_event
338 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
343 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
344 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
345 mwifiex_wmm_lists_empty(adapter
)) {
346 if (!mwifiex_send_null_packet
347 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
348 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
349 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
350 adapter
->delay_null_pkt
= false;
351 adapter
->ps_state
= PS_STATE_SLEEP
;
357 if ((adapter
->int_status
) || IS_CARD_RX_RCVD(adapter
))
360 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
361 adapter
->mwifiex_processing
= false;
362 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
365 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
366 mwifiex_shutdown_drv(adapter
);
369 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
372 * This function frees the adapter structure.
374 * Additionally, this closes the netlink socket, frees the timers
375 * and private structures.
377 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
380 pr_err("%s: adapter is NULL\n", __func__
);
384 mwifiex_unregister(adapter
);
385 pr_debug("info: %s: free adapter\n", __func__
);
389 * This function gets firmware and initializes it.
391 * The main initialization steps followed are -
392 * - Download the correct firmware to card
393 * - Issue the init commands to firmware
395 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
399 struct mwifiex_private
*priv
;
400 struct mwifiex_adapter
*adapter
= context
;
401 struct mwifiex_fw_image fw
;
404 dev_err(adapter
->dev
,
405 "Failed to get firmware %s\n", adapter
->fw_name
);
409 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
410 adapter
->firmware
= firmware
;
411 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
412 fw
.fw_len
= adapter
->firmware
->size
;
414 if (adapter
->if_ops
.dnld_fw
)
415 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
417 ret
= mwifiex_dnld_fw(adapter
, &fw
);
421 dev_notice(adapter
->dev
, "WLAN FW is active\n");
424 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
426 dev_err(adapter
->dev
,
427 "Cal data request_firmware() failed\n");
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 if (!mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
453 NL80211_IFTYPE_STATION
, NULL
, NULL
)) {
454 dev_err(adapter
->dev
, "cannot create default STA interface\n");
458 /* Create AP interface by default */
459 if (!mwifiex_add_virtual_intf(adapter
->wiphy
, "uap%d",
460 NL80211_IFTYPE_AP
, NULL
, NULL
)) {
461 dev_err(adapter
->dev
, "cannot create default AP interface\n");
465 /* Create P2P interface by default */
466 if (!mwifiex_add_virtual_intf(adapter
->wiphy
, "p2p%d",
467 NL80211_IFTYPE_P2P_CLIENT
, NULL
, NULL
)) {
468 dev_err(adapter
->dev
, "cannot create default P2P interface\n");
473 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
474 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
478 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
481 pr_debug("info: %s: unregister device\n", __func__
);
482 adapter
->if_ops
.unregister_dev(adapter
);
484 if (adapter
->cal_data
) {
485 release_firmware(adapter
->cal_data
);
486 adapter
->cal_data
= NULL
;
488 release_firmware(adapter
->firmware
);
489 complete(&adapter
->fw_load
);
494 * This function initializes the hardware and gets firmware.
496 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
500 init_completion(&adapter
->fw_load
);
501 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
502 adapter
->dev
, GFP_KERNEL
, adapter
,
505 dev_err(adapter
->dev
,
506 "request_firmware_nowait() returned error %d\n", ret
);
511 * CFG802.11 network device handler for open.
513 * Starts the data queue.
516 mwifiex_open(struct net_device
*dev
)
518 netif_tx_start_all_queues(dev
);
523 * CFG802.11 network device handler for close.
526 mwifiex_close(struct net_device
*dev
)
528 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
530 if (priv
->scan_request
) {
531 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
532 cfg80211_scan_done(priv
->scan_request
, 1);
533 priv
->scan_request
= NULL
;
534 priv
->scan_aborting
= true;
541 * Add buffer into wmm tx queue and queue work to transmit it.
543 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
545 struct netdev_queue
*txq
;
546 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
548 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
549 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
550 if (!netif_tx_queue_stopped(txq
)) {
551 netif_tx_stop_queue(txq
);
552 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
556 atomic_inc(&priv
->adapter
->tx_pending
);
557 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
559 if (priv
->adapter
->scan_delay_cnt
)
560 atomic_set(&priv
->adapter
->is_tx_received
, true);
562 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
568 * CFG802.11 network device handler for data transmission.
571 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
573 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
574 struct sk_buff
*new_skb
;
575 struct mwifiex_txinfo
*tx_info
;
578 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
579 jiffies
, priv
->bss_type
, priv
->bss_num
);
581 if (priv
->adapter
->surprise_removed
) {
583 priv
->stats
.tx_dropped
++;
586 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
587 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
589 priv
->stats
.tx_dropped
++;
592 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
593 dev_dbg(priv
->adapter
->dev
,
594 "data: Tx: insufficient skb headroom %d\n",
596 /* Insufficient skb headroom - allocate a new skb */
598 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
599 if (unlikely(!new_skb
)) {
600 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
602 priv
->stats
.tx_dropped
++;
607 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
611 tx_info
= MWIFIEX_SKB_TXCB(skb
);
612 tx_info
->bss_num
= priv
->bss_num
;
613 tx_info
->bss_type
= priv
->bss_type
;
615 /* Record the current time the packet was queued; used to
616 * determine the amount of time the packet was queued in
617 * the driver before it was sent to the firmware.
618 * The delay is then sent along with the packet to the
619 * firmware for aggregate delay calculation for stats and
620 * MSDU lifetime expiry.
622 do_gettimeofday(&tv
);
623 skb
->tstamp
= timeval_to_ktime(tv
);
625 mwifiex_queue_tx_pkt(priv
, skb
);
631 * CFG802.11 network device handler for setting MAC address.
634 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
636 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
637 struct sockaddr
*hw_addr
= addr
;
640 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
642 /* Send request to firmware */
643 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
644 HostCmd_ACT_GEN_SET
, 0, NULL
);
647 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
649 dev_err(priv
->adapter
->dev
,
650 "set mac address failed: ret=%d\n", ret
);
652 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
658 * CFG802.11 network device handler for setting multicast list.
660 static void mwifiex_set_multicast_list(struct net_device
*dev
)
662 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
663 struct mwifiex_multicast_list mcast_list
;
665 if (dev
->flags
& IFF_PROMISC
) {
666 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
667 } else if (dev
->flags
& IFF_ALLMULTI
||
668 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
669 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
671 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
672 mcast_list
.num_multicast_addr
=
673 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
675 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
679 * CFG802.11 network device handler for transmission timeout.
682 mwifiex_tx_timeout(struct net_device
*dev
)
684 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
686 priv
->num_tx_timeout
++;
687 priv
->tx_timeout_cnt
++;
688 dev_err(priv
->adapter
->dev
,
689 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
690 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
691 mwifiex_set_trans_start(dev
);
693 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
694 priv
->adapter
->if_ops
.card_reset
) {
695 dev_err(priv
->adapter
->dev
,
696 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
697 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
702 * CFG802.11 network device handler for statistics retrieval.
704 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
706 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
712 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
)
714 skb
->priority
= cfg80211_classify8021d(skb
);
715 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
718 /* Network device handlers */
719 static const struct net_device_ops mwifiex_netdev_ops
= {
720 .ndo_open
= mwifiex_open
,
721 .ndo_stop
= mwifiex_close
,
722 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
723 .ndo_set_mac_address
= mwifiex_set_mac_address
,
724 .ndo_tx_timeout
= mwifiex_tx_timeout
,
725 .ndo_get_stats
= mwifiex_get_stats
,
726 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
727 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
731 * This function initializes the private structure parameters.
733 * The following wait queues are initialized -
735 * - Command wait queue
736 * - Statistics wait queue
738 * ...and the following default parameters are set -
739 * - Current key index : Set to 0
740 * - Rate index : Set to auto
741 * - Media connected : Set to disconnected
742 * - Adhoc link sensed : Set to false
743 * - Nick name : Set to null
744 * - Number of Tx timeout : Set to 0
745 * - Device address : Set to current address
747 * In addition, the CFG80211 work queue is also created.
749 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
750 struct net_device
*dev
)
752 dev
->netdev_ops
= &mwifiex_netdev_ops
;
753 dev
->destructor
= free_netdev
;
754 /* Initialize private structure */
755 priv
->current_key_index
= 0;
756 priv
->media_connected
= false;
757 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
758 memset(priv
->mgmt_ie
, 0,
759 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
760 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
761 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
762 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
763 priv
->rsn_idx
= MWIFIEX_AUTO_IDX_MASK
;
764 priv
->num_tx_timeout
= 0;
765 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
769 * This function check if command is pending.
771 int is_command_pending(struct mwifiex_adapter
*adapter
)
774 int is_cmd_pend_q_empty
;
776 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
777 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
778 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
780 return !is_cmd_pend_q_empty
;
784 * This is the main work queue function.
786 * It handles the main process, which in turn handles the complete
789 static void mwifiex_main_work_queue(struct work_struct
*work
)
791 struct mwifiex_adapter
*adapter
=
792 container_of(work
, struct mwifiex_adapter
, main_work
);
794 if (adapter
->surprise_removed
)
796 mwifiex_main_process(adapter
);
800 * This function cancels all works in the queue and destroys
801 * the main workqueue.
804 mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
806 flush_workqueue(adapter
->workqueue
);
807 destroy_workqueue(adapter
->workqueue
);
808 adapter
->workqueue
= NULL
;
812 * This function adds the card.
814 * This function follows the following major steps to set up the device -
815 * - Initialize software. This includes probing the card, registering
816 * the interface operations table, and allocating/initializing the
818 * - Set up the netlink socket
819 * - Create and start the main work queue
820 * - Register the device
821 * - Initialize firmware and hardware
822 * - Add logical interfaces
825 mwifiex_add_card(void *card
, struct semaphore
*sem
,
826 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
828 struct mwifiex_adapter
*adapter
;
830 if (down_interruptible(sem
))
833 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
834 pr_err("%s: software init failed\n", __func__
);
838 adapter
->iface_type
= iface_type
;
840 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
841 adapter
->surprise_removed
= false;
842 init_waitqueue_head(&adapter
->init_wait_q
);
843 adapter
->is_suspended
= false;
844 adapter
->hs_activated
= false;
845 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
846 adapter
->cmd_wait_q_required
= false;
847 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
848 adapter
->cmd_wait_q
.status
= 0;
849 adapter
->scan_wait_q_woken
= false;
851 adapter
->workqueue
= create_workqueue("MWIFIEX_WORK_QUEUE");
852 if (!adapter
->workqueue
)
855 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
857 /* Register the device. Fill up the private data structure with relevant
858 information from the card and request for the required IRQ. */
859 if (adapter
->if_ops
.register_dev(adapter
)) {
860 pr_err("%s: failed to register mwifiex device\n", __func__
);
861 goto err_registerdev
;
864 if (mwifiex_init_hw_fw(adapter
)) {
865 pr_err("%s: firmware init failed\n", __func__
);
873 pr_debug("info: %s: unregister device\n", __func__
);
874 if (adapter
->if_ops
.unregister_dev
)
875 adapter
->if_ops
.unregister_dev(adapter
);
877 adapter
->surprise_removed
= true;
878 mwifiex_terminate_workqueue(adapter
);
880 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
881 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
882 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
883 adapter
->init_wait_q_woken
= false;
885 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
886 wait_event_interruptible(adapter
->init_wait_q
,
887 adapter
->init_wait_q_woken
);
890 mwifiex_free_adapter(adapter
);
898 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
901 * This function removes the card.
903 * This function follows the following major steps to remove the device -
904 * - Stop data traffic
905 * - Shutdown firmware
906 * - Remove the logical interfaces
907 * - Terminate the work queue
908 * - Unregister the device
909 * - Free the adapter structure
911 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
913 struct mwifiex_private
*priv
= NULL
;
916 if (down_interruptible(sem
))
922 adapter
->surprise_removed
= true;
925 for (i
= 0; i
< adapter
->priv_num
; i
++) {
926 priv
= adapter
->priv
[i
];
927 if (priv
&& priv
->netdev
) {
928 mwifiex_stop_net_dev_queue(priv
->netdev
, adapter
);
929 if (netif_carrier_ok(priv
->netdev
))
930 netif_carrier_off(priv
->netdev
);
934 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
935 adapter
->init_wait_q_woken
= false;
937 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
938 wait_event_interruptible(adapter
->init_wait_q
,
939 adapter
->init_wait_q_woken
);
940 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
941 if (atomic_read(&adapter
->rx_pending
) ||
942 atomic_read(&adapter
->tx_pending
) ||
943 atomic_read(&adapter
->cmd_pending
)) {
944 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
946 atomic_read(&adapter
->rx_pending
),
947 atomic_read(&adapter
->tx_pending
),
948 atomic_read(&adapter
->cmd_pending
));
951 for (i
= 0; i
< adapter
->priv_num
; i
++) {
952 priv
= adapter
->priv
[i
];
958 if (priv
->wdev
&& priv
->netdev
)
959 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
963 priv
= adapter
->priv
[0];
964 if (!priv
|| !priv
->wdev
)
967 wiphy_unregister(priv
->wdev
->wiphy
);
968 wiphy_free(priv
->wdev
->wiphy
);
970 for (i
= 0; i
< adapter
->priv_num
; i
++) {
971 priv
= adapter
->priv
[i
];
976 mwifiex_terminate_workqueue(adapter
);
978 /* Unregister device */
979 dev_dbg(adapter
->dev
, "info: unregister device\n");
980 if (adapter
->if_ops
.unregister_dev
)
981 adapter
->if_ops
.unregister_dev(adapter
);
982 /* Free adapter structure */
983 dev_dbg(adapter
->dev
, "info: free adapter\n");
984 mwifiex_free_adapter(adapter
);
991 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
994 * This function initializes the module.
996 * The debug FS is also initialized if configured.
999 mwifiex_init_module(void)
1001 #ifdef CONFIG_DEBUG_FS
1002 mwifiex_debugfs_init();
1008 * This function cleans up the module.
1010 * The debug FS is removed if available.
1013 mwifiex_cleanup_module(void)
1015 #ifdef CONFIG_DEBUG_FS
1016 mwifiex_debugfs_remove();
1020 module_init(mwifiex_init_module
);
1021 module_exit(mwifiex_cleanup_module
);
1023 MODULE_AUTHOR("Marvell International Ltd.");
1024 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1025 MODULE_VERSION(VERSION
);
1026 MODULE_LICENSE("GPL v2");