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 if (adapter
->if_ops
.cleanup_if
)
195 adapter
->if_ops
.cleanup_if(adapter
);
197 del_timer(&adapter
->cmd_timer
);
199 /* Free private structures */
200 for (i
= 0; i
< adapter
->priv_num
; i
++) {
201 if (adapter
->priv
[i
]) {
202 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
203 del_timer_sync(&adapter
->priv
[i
]->scan_delay_timer
);
204 kfree(adapter
->priv
[i
]);
215 * This function is the main procedure of the driver and handles various driver
216 * operations. It runs in a loop and provides the core functionalities.
218 * The main responsibilities of this function are -
219 * - Ensure concurrency control
220 * - Handle pending interrupts and call interrupt handlers
221 * - Wake up the card if required
222 * - Handle command responses and call response handlers
223 * - Handle events and call event handlers
224 * - Execute pending commands
225 * - Transmit pending data packets
227 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
233 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
235 /* Check if already processing */
236 if (adapter
->mwifiex_processing
) {
237 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
240 adapter
->mwifiex_processing
= true;
241 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
245 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
246 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
249 /* Handle pending interrupt if any */
250 if (adapter
->int_status
) {
251 if (adapter
->hs_activated
)
252 mwifiex_process_hs_config(adapter
);
253 if (adapter
->if_ops
.process_int_status
)
254 adapter
->if_ops
.process_int_status(adapter
);
257 /* Need to wake up the card ? */
258 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
259 (adapter
->pm_wakeup_card_req
&&
260 !adapter
->pm_wakeup_fw_try
) &&
261 (is_command_pending(adapter
) ||
262 !mwifiex_wmm_lists_empty(adapter
))) {
263 adapter
->pm_wakeup_fw_try
= true;
264 adapter
->if_ops
.wakeup(adapter
);
268 if (IS_CARD_RX_RCVD(adapter
)) {
269 adapter
->pm_wakeup_fw_try
= false;
270 if (adapter
->ps_state
== PS_STATE_SLEEP
)
271 adapter
->ps_state
= PS_STATE_AWAKE
;
273 /* We have tried to wakeup the card already */
274 if (adapter
->pm_wakeup_fw_try
)
276 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
277 adapter
->tx_lock_flag
)
280 if ((adapter
->scan_processing
&&
281 !adapter
->scan_delay_cnt
) || adapter
->data_sent
||
282 mwifiex_wmm_lists_empty(adapter
)) {
283 if (adapter
->cmd_sent
|| adapter
->curr_cmd
||
284 (!is_command_pending(adapter
)))
289 /* Check Rx data for USB */
290 if (adapter
->iface_type
== MWIFIEX_USB
)
291 while ((skb
= skb_dequeue(&adapter
->usb_rx_data_q
)))
292 mwifiex_handle_rx_packet(adapter
, skb
);
294 /* Check for Cmd Resp */
295 if (adapter
->cmd_resp_received
) {
296 adapter
->cmd_resp_received
= false;
297 mwifiex_process_cmdresp(adapter
);
299 /* call mwifiex back when init_fw is done */
300 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
301 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
302 mwifiex_init_fw_complete(adapter
);
306 /* Check for event */
307 if (adapter
->event_received
) {
308 adapter
->event_received
= false;
309 mwifiex_process_event(adapter
);
312 /* Check if we need to confirm Sleep Request
313 received previously */
314 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
315 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
316 mwifiex_check_ps_cond(adapter
);
319 /* * The ps_state may have been changed during processing of
320 * Sleep Request event.
322 if ((adapter
->ps_state
== PS_STATE_SLEEP
) ||
323 (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) ||
324 (adapter
->ps_state
== PS_STATE_SLEEP_CFM
) ||
325 adapter
->tx_lock_flag
)
328 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
329 if (mwifiex_exec_next_cmd(adapter
) == -1) {
335 if ((!adapter
->scan_processing
|| adapter
->scan_delay_cnt
) &&
336 !adapter
->data_sent
&& !mwifiex_wmm_lists_empty(adapter
)) {
337 mwifiex_wmm_process_tx(adapter
);
338 if (adapter
->hs_activated
) {
339 adapter
->is_hs_configured
= false;
340 mwifiex_hs_activated_event
342 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
347 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
348 !adapter
->curr_cmd
&& !is_command_pending(adapter
) &&
349 mwifiex_wmm_lists_empty(adapter
)) {
350 if (!mwifiex_send_null_packet
351 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
352 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
353 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
354 adapter
->delay_null_pkt
= false;
355 adapter
->ps_state
= PS_STATE_SLEEP
;
361 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
362 if ((adapter
->int_status
) || IS_CARD_RX_RCVD(adapter
)) {
363 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
367 adapter
->mwifiex_processing
= false;
368 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
371 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
372 mwifiex_shutdown_drv(adapter
);
375 EXPORT_SYMBOL_GPL(mwifiex_main_process
);
378 * This function frees the adapter structure.
380 * Additionally, this closes the netlink socket, frees the timers
381 * and private structures.
383 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
386 pr_err("%s: adapter is NULL\n", __func__
);
390 mwifiex_unregister(adapter
);
391 pr_debug("info: %s: free adapter\n", __func__
);
395 * This function cancels all works in the queue and destroys
396 * the main workqueue.
398 static void mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
400 flush_workqueue(adapter
->workqueue
);
401 destroy_workqueue(adapter
->workqueue
);
402 adapter
->workqueue
= NULL
;
406 * This function gets firmware and initializes it.
408 * The main initialization steps followed are -
409 * - Download the correct firmware to card
410 * - Issue the init commands to firmware
412 static void mwifiex_fw_dpc(const struct firmware
*firmware
, void *context
)
416 struct mwifiex_private
*priv
;
417 struct mwifiex_adapter
*adapter
= context
;
418 struct mwifiex_fw_image fw
;
419 struct semaphore
*sem
= adapter
->card_sem
;
420 bool init_failed
= false;
423 dev_err(adapter
->dev
,
424 "Failed to get firmware %s\n", adapter
->fw_name
);
428 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
429 adapter
->firmware
= firmware
;
430 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
431 fw
.fw_len
= adapter
->firmware
->size
;
433 if (adapter
->if_ops
.dnld_fw
)
434 ret
= adapter
->if_ops
.dnld_fw(adapter
, &fw
);
436 ret
= mwifiex_dnld_fw(adapter
, &fw
);
440 dev_notice(adapter
->dev
, "WLAN FW is active\n");
443 if ((request_firmware(&adapter
->cal_data
, cal_data_cfg
,
445 dev_err(adapter
->dev
,
446 "Cal data request_firmware() failed\n");
449 /* enable host interrupt after fw dnld is successful */
450 if (adapter
->if_ops
.enable_int
) {
451 if (adapter
->if_ops
.enable_int(adapter
))
455 adapter
->init_wait_q_woken
= false;
456 ret
= mwifiex_init_fw(adapter
);
460 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
463 /* Wait for mwifiex_init to complete */
464 wait_event_interruptible(adapter
->init_wait_q
,
465 adapter
->init_wait_q_woken
);
466 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
)
469 priv
= adapter
->priv
[MWIFIEX_BSS_ROLE_STA
];
470 if (mwifiex_register_cfg80211(adapter
)) {
471 dev_err(adapter
->dev
, "cannot register with cfg80211\n");
472 goto err_register_cfg80211
;
476 /* Create station interface by default */
477 if (!mwifiex_add_virtual_intf(adapter
->wiphy
, "mlan%d",
478 NL80211_IFTYPE_STATION
, NULL
, NULL
)) {
479 dev_err(adapter
->dev
, "cannot create default STA interface\n");
484 mwifiex_drv_get_driver_version(adapter
, fmt
, sizeof(fmt
) - 1);
485 dev_notice(adapter
->dev
, "driver_version = %s\n", fmt
);
489 for (i
= 0; i
< adapter
->priv_num
; i
++) {
490 priv
= adapter
->priv
[i
];
495 if (priv
->wdev
&& priv
->netdev
)
496 mwifiex_del_virtual_intf(adapter
->wiphy
, priv
->wdev
);
499 err_register_cfg80211
:
500 wiphy_unregister(adapter
->wiphy
);
501 wiphy_free(adapter
->wiphy
);
503 if (adapter
->if_ops
.disable_int
)
504 adapter
->if_ops
.disable_int(adapter
);
506 pr_debug("info: %s: unregister device\n", __func__
);
507 if (adapter
->if_ops
.unregister_dev
)
508 adapter
->if_ops
.unregister_dev(adapter
);
510 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
511 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
512 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
513 adapter
->init_wait_q_woken
= false;
515 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
516 wait_event_interruptible(adapter
->init_wait_q
,
517 adapter
->init_wait_q_woken
);
519 adapter
->surprise_removed
= true;
520 mwifiex_terminate_workqueue(adapter
);
523 if (adapter
->cal_data
) {
524 release_firmware(adapter
->cal_data
);
525 adapter
->cal_data
= NULL
;
527 if (adapter
->firmware
) {
528 release_firmware(adapter
->firmware
);
529 adapter
->firmware
= NULL
;
531 complete(&adapter
->fw_load
);
533 mwifiex_free_adapter(adapter
);
539 * This function initializes the hardware and gets firmware.
541 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
545 init_completion(&adapter
->fw_load
);
546 ret
= request_firmware_nowait(THIS_MODULE
, 1, adapter
->fw_name
,
547 adapter
->dev
, GFP_KERNEL
, adapter
,
550 dev_err(adapter
->dev
,
551 "request_firmware_nowait() returned error %d\n", ret
);
556 * CFG802.11 network device handler for open.
558 * Starts the data queue.
561 mwifiex_open(struct net_device
*dev
)
563 netif_tx_start_all_queues(dev
);
568 * CFG802.11 network device handler for close.
571 mwifiex_close(struct net_device
*dev
)
573 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
575 if (priv
->scan_request
) {
576 dev_dbg(priv
->adapter
->dev
, "aborting scan on ndo_stop\n");
577 cfg80211_scan_done(priv
->scan_request
, 1);
578 priv
->scan_request
= NULL
;
579 priv
->scan_aborting
= true;
586 * Add buffer into wmm tx queue and queue work to transmit it.
588 int mwifiex_queue_tx_pkt(struct mwifiex_private
*priv
, struct sk_buff
*skb
)
590 struct netdev_queue
*txq
;
591 int index
= mwifiex_1d_to_wmm_queue
[skb
->priority
];
593 if (atomic_inc_return(&priv
->wmm_tx_pending
[index
]) >= MAX_TX_PENDING
) {
594 txq
= netdev_get_tx_queue(priv
->netdev
, index
);
595 if (!netif_tx_queue_stopped(txq
)) {
596 netif_tx_stop_queue(txq
);
597 dev_dbg(priv
->adapter
->dev
, "stop queue: %d\n", index
);
601 atomic_inc(&priv
->adapter
->tx_pending
);
602 mwifiex_wmm_add_buf_txqueue(priv
, skb
);
604 if (priv
->adapter
->scan_delay_cnt
)
605 atomic_set(&priv
->adapter
->is_tx_received
, true);
607 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
613 * CFG802.11 network device handler for data transmission.
616 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
618 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
619 struct sk_buff
*new_skb
;
620 struct mwifiex_txinfo
*tx_info
;
623 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d-%d): Data <= kernel\n",
624 jiffies
, priv
->bss_type
, priv
->bss_num
);
626 if (priv
->adapter
->surprise_removed
) {
628 priv
->stats
.tx_dropped
++;
631 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
632 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
634 priv
->stats
.tx_dropped
++;
637 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
638 dev_dbg(priv
->adapter
->dev
,
639 "data: Tx: insufficient skb headroom %d\n",
641 /* Insufficient skb headroom - allocate a new skb */
643 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
644 if (unlikely(!new_skb
)) {
645 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
647 priv
->stats
.tx_dropped
++;
652 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
656 tx_info
= MWIFIEX_SKB_TXCB(skb
);
657 memset(tx_info
, 0, sizeof(*tx_info
));
658 tx_info
->bss_num
= priv
->bss_num
;
659 tx_info
->bss_type
= priv
->bss_type
;
661 /* Record the current time the packet was queued; used to
662 * determine the amount of time the packet was queued in
663 * the driver before it was sent to the firmware.
664 * The delay is then sent along with the packet to the
665 * firmware for aggregate delay calculation for stats and
666 * MSDU lifetime expiry.
668 do_gettimeofday(&tv
);
669 skb
->tstamp
= timeval_to_ktime(tv
);
671 mwifiex_queue_tx_pkt(priv
, skb
);
677 * CFG802.11 network device handler for setting MAC address.
680 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
682 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
683 struct sockaddr
*hw_addr
= addr
;
686 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
688 /* Send request to firmware */
689 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
690 HostCmd_ACT_GEN_SET
, 0, NULL
);
693 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
695 dev_err(priv
->adapter
->dev
,
696 "set mac address failed: ret=%d\n", ret
);
698 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
704 * CFG802.11 network device handler for setting multicast list.
706 static void mwifiex_set_multicast_list(struct net_device
*dev
)
708 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
709 struct mwifiex_multicast_list mcast_list
;
711 if (dev
->flags
& IFF_PROMISC
) {
712 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
713 } else if (dev
->flags
& IFF_ALLMULTI
||
714 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
715 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
717 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
718 mcast_list
.num_multicast_addr
=
719 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
721 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
725 * CFG802.11 network device handler for transmission timeout.
728 mwifiex_tx_timeout(struct net_device
*dev
)
730 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
732 priv
->num_tx_timeout
++;
733 priv
->tx_timeout_cnt
++;
734 dev_err(priv
->adapter
->dev
,
735 "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
736 jiffies
, priv
->tx_timeout_cnt
, priv
->bss_type
, priv
->bss_num
);
737 mwifiex_set_trans_start(dev
);
739 if (priv
->tx_timeout_cnt
> TX_TIMEOUT_THRESHOLD
&&
740 priv
->adapter
->if_ops
.card_reset
) {
741 dev_err(priv
->adapter
->dev
,
742 "tx_timeout_cnt exceeds threshold. Triggering card reset!\n");
743 priv
->adapter
->if_ops
.card_reset(priv
->adapter
);
748 * CFG802.11 network device handler for statistics retrieval.
750 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
752 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
758 mwifiex_netdev_select_wmm_queue(struct net_device
*dev
, struct sk_buff
*skb
)
760 skb
->priority
= cfg80211_classify8021d(skb
);
761 return mwifiex_1d_to_wmm_queue
[skb
->priority
];
764 /* Network device handlers */
765 static const struct net_device_ops mwifiex_netdev_ops
= {
766 .ndo_open
= mwifiex_open
,
767 .ndo_stop
= mwifiex_close
,
768 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
769 .ndo_set_mac_address
= mwifiex_set_mac_address
,
770 .ndo_tx_timeout
= mwifiex_tx_timeout
,
771 .ndo_get_stats
= mwifiex_get_stats
,
772 .ndo_set_rx_mode
= mwifiex_set_multicast_list
,
773 .ndo_select_queue
= mwifiex_netdev_select_wmm_queue
,
777 * This function initializes the private structure parameters.
779 * The following wait queues are initialized -
781 * - Command wait queue
782 * - Statistics wait queue
784 * ...and the following default parameters are set -
785 * - Current key index : Set to 0
786 * - Rate index : Set to auto
787 * - Media connected : Set to disconnected
788 * - Adhoc link sensed : Set to false
789 * - Nick name : Set to null
790 * - Number of Tx timeout : Set to 0
791 * - Device address : Set to current address
793 * In addition, the CFG80211 work queue is also created.
795 void mwifiex_init_priv_params(struct mwifiex_private
*priv
,
796 struct net_device
*dev
)
798 dev
->netdev_ops
= &mwifiex_netdev_ops
;
799 dev
->destructor
= free_netdev
;
800 /* Initialize private structure */
801 priv
->current_key_index
= 0;
802 priv
->media_connected
= false;
803 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
804 memset(priv
->mgmt_ie
, 0,
805 sizeof(struct mwifiex_ie
) * MAX_MGMT_IE_INDEX
);
806 priv
->beacon_idx
= MWIFIEX_AUTO_IDX_MASK
;
807 priv
->proberesp_idx
= MWIFIEX_AUTO_IDX_MASK
;
808 priv
->assocresp_idx
= MWIFIEX_AUTO_IDX_MASK
;
809 priv
->rsn_idx
= MWIFIEX_AUTO_IDX_MASK
;
810 priv
->num_tx_timeout
= 0;
811 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
815 * This function check if command is pending.
817 int is_command_pending(struct mwifiex_adapter
*adapter
)
820 int is_cmd_pend_q_empty
;
822 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
823 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
824 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
826 return !is_cmd_pend_q_empty
;
830 * This is the main work queue function.
832 * It handles the main process, which in turn handles the complete
835 static void mwifiex_main_work_queue(struct work_struct
*work
)
837 struct mwifiex_adapter
*adapter
=
838 container_of(work
, struct mwifiex_adapter
, main_work
);
840 if (adapter
->surprise_removed
)
842 mwifiex_main_process(adapter
);
846 * This function adds the card.
848 * This function follows the following major steps to set up the device -
849 * - Initialize software. This includes probing the card, registering
850 * the interface operations table, and allocating/initializing the
852 * - Set up the netlink socket
853 * - Create and start the main work queue
854 * - Register the device
855 * - Initialize firmware and hardware
856 * - Add logical interfaces
859 mwifiex_add_card(void *card
, struct semaphore
*sem
,
860 struct mwifiex_if_ops
*if_ops
, u8 iface_type
)
862 struct mwifiex_adapter
*adapter
;
864 if (down_interruptible(sem
))
867 if (mwifiex_register(card
, if_ops
, (void **)&adapter
)) {
868 pr_err("%s: software init failed\n", __func__
);
872 adapter
->iface_type
= iface_type
;
873 adapter
->card_sem
= sem
;
875 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
876 adapter
->surprise_removed
= false;
877 init_waitqueue_head(&adapter
->init_wait_q
);
878 adapter
->is_suspended
= false;
879 adapter
->hs_activated
= false;
880 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
881 adapter
->cmd_wait_q_required
= false;
882 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
883 adapter
->cmd_wait_q
.status
= 0;
884 adapter
->scan_wait_q_woken
= false;
886 adapter
->workqueue
= create_workqueue("MWIFIEX_WORK_QUEUE");
887 if (!adapter
->workqueue
)
890 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
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 priv
= adapter
->priv
[0];
1002 if (!priv
|| !priv
->wdev
)
1005 wiphy_unregister(priv
->wdev
->wiphy
);
1006 wiphy_free(priv
->wdev
->wiphy
);
1008 for (i
= 0; i
< adapter
->priv_num
; i
++) {
1009 priv
= adapter
->priv
[i
];
1014 mwifiex_terminate_workqueue(adapter
);
1016 /* Unregister device */
1017 dev_dbg(adapter
->dev
, "info: unregister device\n");
1018 if (adapter
->if_ops
.unregister_dev
)
1019 adapter
->if_ops
.unregister_dev(adapter
);
1020 /* Free adapter structure */
1021 dev_dbg(adapter
->dev
, "info: free adapter\n");
1022 mwifiex_free_adapter(adapter
);
1029 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1032 * This function initializes the module.
1034 * The debug FS is also initialized if configured.
1037 mwifiex_init_module(void)
1039 #ifdef CONFIG_DEBUG_FS
1040 mwifiex_debugfs_init();
1046 * This function cleans up the module.
1048 * The debug FS is removed if available.
1051 mwifiex_cleanup_module(void)
1053 #ifdef CONFIG_DEBUG_FS
1054 mwifiex_debugfs_remove();
1058 module_init(mwifiex_init_module
);
1059 module_exit(mwifiex_cleanup_module
);
1061 MODULE_AUTHOR("Marvell International Ltd.");
1062 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1063 MODULE_VERSION(VERSION
);
1064 MODULE_LICENSE("GPL v2");