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) ";
29 static struct mwifiex_bss_attr mwifiex_bss_sta
[] = {
30 {MWIFIEX_BSS_TYPE_STA
, MWIFIEX_DATA_FRAME_TYPE_ETH_II
, true, 0, 0},
33 static int drv_mode
= DRV_MODE_STA
;
35 /* Supported drv_mode table */
36 static struct mwifiex_drv_mode mwifiex_drv_mode_tbl
[] = {
38 .drv_mode
= DRV_MODE_STA
,
39 .intf_num
= ARRAY_SIZE(mwifiex_bss_sta
),
40 .bss_attr
= mwifiex_bss_sta
,
45 * This function registers the device and performs all the necessary
48 * The following initialization operations are performed -
49 * - Allocate adapter structure
50 * - Save interface specific operations table in adapter
51 * - Call interface specific initialization routine
52 * - Allocate private structures
53 * - Set default adapter structure parameters
56 * In case of any errors during inittialization, this function also ensures
57 * proper cleanup before exiting.
59 static int mwifiex_register(void *card
, struct mwifiex_if_ops
*if_ops
,
60 struct mwifiex_drv_mode
*drv_mode_ptr
,
63 struct mwifiex_adapter
*adapter
;
66 adapter
= kzalloc(sizeof(struct mwifiex_adapter
), GFP_KERNEL
);
73 /* Save interface specific operations in adapter */
74 memmove(&adapter
->if_ops
, if_ops
, sizeof(struct mwifiex_if_ops
));
76 /* card specific initialization has been deferred until now .. */
77 if (adapter
->if_ops
.init_if(adapter
))
80 adapter
->priv_num
= 0;
81 for (i
= 0; i
< drv_mode_ptr
->intf_num
; i
++) {
82 adapter
->priv
[i
] = NULL
;
84 if (!drv_mode_ptr
->bss_attr
[i
].active
)
87 /* Allocate memory for private structure */
88 adapter
->priv
[i
] = kzalloc(sizeof(struct mwifiex_private
),
90 if (!adapter
->priv
[i
]) {
91 dev_err(adapter
->dev
, "%s: failed to alloc priv[%d]\n",
97 adapter
->priv
[i
]->adapter
= adapter
;
98 /* Save bss_type, frame_type & bss_priority */
99 adapter
->priv
[i
]->bss_type
= drv_mode_ptr
->bss_attr
[i
].bss_type
;
100 adapter
->priv
[i
]->frame_type
=
101 drv_mode_ptr
->bss_attr
[i
].frame_type
;
102 adapter
->priv
[i
]->bss_priority
=
103 drv_mode_ptr
->bss_attr
[i
].bss_priority
;
105 if (drv_mode_ptr
->bss_attr
[i
].bss_type
== MWIFIEX_BSS_TYPE_STA
)
106 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_STA
;
107 else if (drv_mode_ptr
->bss_attr
[i
].bss_type
==
108 MWIFIEX_BSS_TYPE_UAP
)
109 adapter
->priv
[i
]->bss_role
= MWIFIEX_BSS_ROLE_UAP
;
111 /* Save bss_index & bss_num */
112 adapter
->priv
[i
]->bss_index
= i
;
113 adapter
->priv
[i
]->bss_num
= drv_mode_ptr
->bss_attr
[i
].bss_num
;
115 adapter
->drv_mode
= drv_mode_ptr
;
117 if (mwifiex_init_lock_list(adapter
))
120 init_timer(&adapter
->cmd_timer
);
121 adapter
->cmd_timer
.function
= mwifiex_cmd_timeout_func
;
122 adapter
->cmd_timer
.data
= (unsigned long) adapter
;
127 dev_dbg(adapter
->dev
, "info: leave mwifiex_register with error\n");
129 mwifiex_free_lock_list(adapter
);
130 for (i
= 0; i
< drv_mode_ptr
->intf_num
; i
++)
131 kfree(adapter
->priv
[i
]);
138 * This function unregisters the device and performs all the necessary
141 * The following cleanup operations are performed -
143 * - Free beacon buffers
144 * - Free private structures
145 * - Free adapter structure
147 static int mwifiex_unregister(struct mwifiex_adapter
*adapter
)
151 del_timer(&adapter
->cmd_timer
);
153 /* Free private structures */
154 for (i
= 0; i
< adapter
->priv_num
; i
++) {
155 if (adapter
->priv
[i
]) {
156 mwifiex_free_curr_bcn(adapter
->priv
[i
]);
157 kfree(adapter
->priv
[i
]);
168 * This function is the main procedure of the driver and handles various driver
169 * operations. It runs in a loop and provides the core functionalities.
171 * The main responsibilities of this function are -
172 * - Ensure concurrency control
173 * - Handle pending interrupts and call interrupt handlers
174 * - Wake up the card if required
175 * - Handle command responses and call response handlers
176 * - Handle events and call event handlers
177 * - Execute pending commands
178 * - Transmit pending data packets
180 int mwifiex_main_process(struct mwifiex_adapter
*adapter
)
185 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
187 /* Check if already processing */
188 if (adapter
->mwifiex_processing
) {
189 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
192 adapter
->mwifiex_processing
= true;
193 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
197 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
) ||
198 (adapter
->hw_status
== MWIFIEX_HW_STATUS_NOT_READY
))
201 /* Handle pending interrupt if any */
202 if (adapter
->int_status
) {
203 if (adapter
->hs_activated
)
204 mwifiex_process_hs_config(adapter
);
205 adapter
->if_ops
.process_int_status(adapter
);
208 /* Need to wake up the card ? */
209 if ((adapter
->ps_state
== PS_STATE_SLEEP
) &&
210 (adapter
->pm_wakeup_card_req
&&
211 !adapter
->pm_wakeup_fw_try
) &&
212 (is_command_pending(adapter
)
213 || !mwifiex_wmm_lists_empty(adapter
))) {
214 adapter
->pm_wakeup_fw_try
= true;
215 adapter
->if_ops
.wakeup(adapter
);
218 if (IS_CARD_RX_RCVD(adapter
)) {
219 adapter
->pm_wakeup_fw_try
= false;
220 if (adapter
->ps_state
== PS_STATE_SLEEP
)
221 adapter
->ps_state
= PS_STATE_AWAKE
;
223 /* We have tried to wakeup the card already */
224 if (adapter
->pm_wakeup_fw_try
)
226 if (adapter
->ps_state
!= PS_STATE_AWAKE
||
227 adapter
->tx_lock_flag
)
230 if (adapter
->scan_processing
|| adapter
->data_sent
231 || mwifiex_wmm_lists_empty(adapter
)) {
232 if (adapter
->cmd_sent
|| adapter
->curr_cmd
233 || (!is_command_pending(adapter
)))
238 /* Check for Cmd Resp */
239 if (adapter
->cmd_resp_received
) {
240 adapter
->cmd_resp_received
= false;
241 mwifiex_process_cmdresp(adapter
);
243 /* call mwifiex back when init_fw is done */
244 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_INIT_DONE
) {
245 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
246 mwifiex_init_fw_complete(adapter
);
250 /* Check for event */
251 if (adapter
->event_received
) {
252 adapter
->event_received
= false;
253 mwifiex_process_event(adapter
);
256 /* Check if we need to confirm Sleep Request
257 received previously */
258 if (adapter
->ps_state
== PS_STATE_PRE_SLEEP
) {
259 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
)
260 mwifiex_check_ps_cond(adapter
);
263 /* * The ps_state may have been changed during processing of
264 * Sleep Request event.
266 if ((adapter
->ps_state
== PS_STATE_SLEEP
)
267 || (adapter
->ps_state
== PS_STATE_PRE_SLEEP
)
268 || (adapter
->ps_state
== PS_STATE_SLEEP_CFM
)
269 || adapter
->tx_lock_flag
)
272 if (!adapter
->cmd_sent
&& !adapter
->curr_cmd
) {
273 if (mwifiex_exec_next_cmd(adapter
) == -1) {
279 if (!adapter
->scan_processing
&& !adapter
->data_sent
&&
280 !mwifiex_wmm_lists_empty(adapter
)) {
281 mwifiex_wmm_process_tx(adapter
);
282 if (adapter
->hs_activated
) {
283 adapter
->is_hs_configured
= false;
284 mwifiex_hs_activated_event
286 (adapter
, MWIFIEX_BSS_ROLE_ANY
),
291 if (adapter
->delay_null_pkt
&& !adapter
->cmd_sent
&&
292 !adapter
->curr_cmd
&& !is_command_pending(adapter
)
293 && mwifiex_wmm_lists_empty(adapter
)) {
294 if (!mwifiex_send_null_packet
295 (mwifiex_get_priv(adapter
, MWIFIEX_BSS_ROLE_STA
),
296 MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET
|
297 MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET
)) {
298 adapter
->delay_null_pkt
= false;
299 adapter
->ps_state
= PS_STATE_SLEEP
;
305 if ((adapter
->int_status
) || IS_CARD_RX_RCVD(adapter
))
308 spin_lock_irqsave(&adapter
->main_proc_lock
, flags
);
309 adapter
->mwifiex_processing
= false;
310 spin_unlock_irqrestore(&adapter
->main_proc_lock
, flags
);
313 if (adapter
->hw_status
== MWIFIEX_HW_STATUS_CLOSING
)
314 mwifiex_shutdown_drv(adapter
);
319 * This function initializes the software.
321 * The main work includes allocating and initializing the adapter structure
322 * and initializing the private structures.
325 mwifiex_init_sw(void *card
, struct mwifiex_if_ops
*if_ops
, void **padapter
)
328 struct mwifiex_drv_mode
*drv_mode_ptr
;
330 /* find mwifiex_drv_mode entry from mwifiex_drv_mode_tbl */
332 for (i
= 0; i
< ARRAY_SIZE(mwifiex_drv_mode_tbl
); i
++) {
333 if (mwifiex_drv_mode_tbl
[i
].drv_mode
== drv_mode
) {
334 drv_mode_ptr
= &mwifiex_drv_mode_tbl
[i
];
340 pr_err("invalid drv_mode=%d\n", drv_mode
);
344 if (mwifiex_register(card
, if_ops
, drv_mode_ptr
, padapter
))
351 * This function frees the adapter structure.
353 * Additionally, this closes the netlink socket, frees the timers
354 * and private structures.
356 static void mwifiex_free_adapter(struct mwifiex_adapter
*adapter
)
359 pr_err("%s: adapter is NULL\n", __func__
);
363 mwifiex_unregister(adapter
);
364 pr_debug("info: %s: free adapter\n", __func__
);
368 * This function initializes the hardware and firmware.
370 * The main initialization steps followed are -
371 * - Download the correct firmware to card
372 * - Allocate and initialize the adapter structure
373 * - Initialize the private structures
374 * - Issue the init commands to firmware
376 static int mwifiex_init_hw_fw(struct mwifiex_adapter
*adapter
)
379 struct mwifiex_fw_image fw
;
381 memset(&fw
, 0, sizeof(struct mwifiex_fw_image
));
383 err
= request_firmware(&adapter
->firmware
, adapter
->fw_name
,
386 dev_err(adapter
->dev
, "request_firmware() returned"
387 " error code %#x\n", err
);
391 fw
.fw_buf
= (u8
*) adapter
->firmware
->data
;
392 fw
.fw_len
= adapter
->firmware
->size
;
394 ret
= mwifiex_dnld_fw(adapter
, &fw
);
398 dev_notice(adapter
->dev
, "WLAN FW is active\n");
400 adapter
->init_wait_q_woken
= false;
401 ret
= mwifiex_init_fw(adapter
);
405 adapter
->hw_status
= MWIFIEX_HW_STATUS_READY
;
408 /* Wait for mwifiex_init to complete */
409 wait_event_interruptible(adapter
->init_wait_q
,
410 adapter
->init_wait_q_woken
);
411 if (adapter
->hw_status
!= MWIFIEX_HW_STATUS_READY
) {
418 if (adapter
->firmware
)
419 release_firmware(adapter
->firmware
);
426 * This function fills a driver buffer.
428 * The function associates a given SKB with the provided driver buffer
429 * and also updates some of the SKB parameters, including IP header,
430 * priority and timestamp.
433 mwifiex_fill_buffer(struct sk_buff
*skb
)
440 eth
= (struct ethhdr
*) skb
->data
;
441 switch (eth
->h_proto
) {
442 case __constant_htons(ETH_P_IP
):
444 tid
= IPTOS_PREC(iph
->tos
);
445 pr_debug("data: packet type ETH_P_IP: %04x, tid=%#x prio=%#x\n",
446 eth
->h_proto
, tid
, skb
->priority
);
448 case __constant_htons(ETH_P_ARP
):
449 pr_debug("data: ARP packet: %04x\n", eth
->h_proto
);
453 /* Offset for TOS field in the IP header */
454 #define IPTOS_OFFSET 5
455 tid
= (tid
>> IPTOS_OFFSET
);
457 /* Record the current time the packet was queued; used to
458 determine the amount of time the packet was queued in
459 the driver before it was sent to the firmware.
460 The delay is then sent along with the packet to the
461 firmware for aggregate delay calculation for stats and
462 MSDU lifetime expiry.
464 do_gettimeofday(&tv
);
465 skb
->tstamp
= timeval_to_ktime(tv
);
469 * CFG802.11 network device handler for open.
471 * Starts the data queue.
474 mwifiex_open(struct net_device
*dev
)
476 netif_start_queue(dev
);
481 * CFG802.11 network device handler for close.
484 mwifiex_close(struct net_device
*dev
)
490 * CFG802.11 network device handler for data transmission.
493 mwifiex_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
495 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
496 struct sk_buff
*new_skb
;
497 struct mwifiex_txinfo
*tx_info
;
499 dev_dbg(priv
->adapter
->dev
, "data: %lu BSS(%d): Data <= kernel\n",
500 jiffies
, priv
->bss_index
);
502 if (priv
->adapter
->surprise_removed
) {
504 priv
->stats
.tx_dropped
++;
507 if (!skb
->len
|| (skb
->len
> ETH_FRAME_LEN
)) {
508 dev_err(priv
->adapter
->dev
, "Tx: bad skb len %d\n", skb
->len
);
510 priv
->stats
.tx_dropped
++;
513 if (skb_headroom(skb
) < MWIFIEX_MIN_DATA_HEADER_LEN
) {
514 dev_dbg(priv
->adapter
->dev
,
515 "data: Tx: insufficient skb headroom %d\n",
517 /* Insufficient skb headroom - allocate a new skb */
519 skb_realloc_headroom(skb
, MWIFIEX_MIN_DATA_HEADER_LEN
);
520 if (unlikely(!new_skb
)) {
521 dev_err(priv
->adapter
->dev
, "Tx: cannot alloca new_skb\n");
523 priv
->stats
.tx_dropped
++;
528 dev_dbg(priv
->adapter
->dev
, "info: new skb headroomd %d\n",
532 tx_info
= MWIFIEX_SKB_TXCB(skb
);
533 tx_info
->bss_index
= priv
->bss_index
;
534 mwifiex_fill_buffer(skb
);
536 mwifiex_wmm_add_buf_txqueue(priv
->adapter
, skb
);
537 atomic_inc(&priv
->adapter
->tx_pending
);
539 if (atomic_read(&priv
->adapter
->tx_pending
) >= MAX_TX_PENDING
) {
540 netif_stop_queue(priv
->netdev
);
541 dev
->trans_start
= jiffies
;
544 queue_work(priv
->adapter
->workqueue
, &priv
->adapter
->main_work
);
550 * CFG802.11 network device handler for setting MAC address.
553 mwifiex_set_mac_address(struct net_device
*dev
, void *addr
)
555 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
556 struct sockaddr
*hw_addr
= addr
;
559 memcpy(priv
->curr_addr
, hw_addr
->sa_data
, ETH_ALEN
);
561 /* Send request to firmware */
562 ret
= mwifiex_send_cmd_sync(priv
, HostCmd_CMD_802_11_MAC_ADDRESS
,
563 HostCmd_ACT_GEN_SET
, 0, NULL
);
566 memcpy(priv
->netdev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
568 dev_err(priv
->adapter
->dev
, "set mac address failed: ret=%d"
571 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
577 * CFG802.11 network device handler for setting multicast list.
579 static void mwifiex_set_multicast_list(struct net_device
*dev
)
581 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
582 struct mwifiex_multicast_list mcast_list
;
584 if (dev
->flags
& IFF_PROMISC
) {
585 mcast_list
.mode
= MWIFIEX_PROMISC_MODE
;
586 } else if (dev
->flags
& IFF_ALLMULTI
||
587 netdev_mc_count(dev
) > MWIFIEX_MAX_MULTICAST_LIST_SIZE
) {
588 mcast_list
.mode
= MWIFIEX_ALL_MULTI_MODE
;
590 mcast_list
.mode
= MWIFIEX_MULTICAST_MODE
;
591 if (netdev_mc_count(dev
))
592 mcast_list
.num_multicast_addr
=
593 mwifiex_copy_mcast_addr(&mcast_list
, dev
);
595 mwifiex_request_set_multicast_list(priv
, &mcast_list
);
599 * CFG802.11 network device handler for transmission timeout.
602 mwifiex_tx_timeout(struct net_device
*dev
)
604 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
606 dev_err(priv
->adapter
->dev
, "%lu : Tx timeout, bss_index=%d\n",
607 jiffies
, priv
->bss_index
);
608 dev
->trans_start
= jiffies
;
609 priv
->num_tx_timeout
++;
613 * CFG802.11 network device handler for statistics retrieval.
615 static struct net_device_stats
*mwifiex_get_stats(struct net_device
*dev
)
617 struct mwifiex_private
*priv
= mwifiex_netdev_get_priv(dev
);
622 /* Network device handlers */
623 static const struct net_device_ops mwifiex_netdev_ops
= {
624 .ndo_open
= mwifiex_open
,
625 .ndo_stop
= mwifiex_close
,
626 .ndo_start_xmit
= mwifiex_hard_start_xmit
,
627 .ndo_set_mac_address
= mwifiex_set_mac_address
,
628 .ndo_tx_timeout
= mwifiex_tx_timeout
,
629 .ndo_get_stats
= mwifiex_get_stats
,
630 .ndo_set_multicast_list
= mwifiex_set_multicast_list
,
634 * This function initializes the private structure parameters.
636 * The following wait queues are initialized -
638 * - Command wait queue
639 * - Statistics wait queue
641 * ...and the following default parameters are set -
642 * - Current key index : Set to 0
643 * - Rate index : Set to auto
644 * - Media connected : Set to disconnected
645 * - Adhoc link sensed : Set to false
646 * - Nick name : Set to null
647 * - Number of Tx timeout : Set to 0
648 * - Device address : Set to current address
650 * In addition, the CFG80211 work queue is also created.
653 mwifiex_init_priv_params(struct mwifiex_private
*priv
, struct net_device
*dev
)
655 dev
->netdev_ops
= &mwifiex_netdev_ops
;
656 /* Initialize private structure */
657 priv
->current_key_index
= 0;
658 priv
->media_connected
= false;
659 memset(&priv
->nick_name
, 0, sizeof(priv
->nick_name
));
660 priv
->num_tx_timeout
= 0;
661 priv
->workqueue
= create_singlethread_workqueue("cfg80211_wq");
662 INIT_WORK(&priv
->cfg_workqueue
, mwifiex_cfg80211_results
);
663 memcpy(dev
->dev_addr
, priv
->curr_addr
, ETH_ALEN
);
667 * This function adds a new logical interface.
669 * It allocates, initializes and registers the interface by performing
670 * the following opearations -
671 * - Allocate a new net device structure
672 * - Assign device name
673 * - Register the new device with CFG80211 subsystem
674 * - Initialize semaphore and private structure
675 * - Register the new device with kernel
676 * - Create the complete debug FS structure if configured
678 static struct mwifiex_private
*mwifiex_add_interface(
679 struct mwifiex_adapter
*adapter
,
680 u8 bss_index
, u8 bss_type
)
682 struct net_device
*dev
;
683 struct mwifiex_private
*priv
;
686 dev
= alloc_netdev_mq(sizeof(struct mwifiex_private
*), "mlan%d",
689 dev_err(adapter
->dev
, "no memory available for netdevice\n");
693 if (mwifiex_register_cfg80211(dev
, adapter
->priv
[bss_index
]->curr_addr
,
694 adapter
->priv
[bss_index
]) != 0) {
695 dev_err(adapter
->dev
, "cannot register netdevice with cfg80211\n");
698 /* Save the priv pointer in netdev */
699 priv
= adapter
->priv
[bss_index
];
700 mdev_priv
= netdev_priv(dev
);
701 *((unsigned long *) mdev_priv
) = (unsigned long) priv
;
705 sema_init(&priv
->async_sem
, 1);
706 priv
->scan_pending_on_block
= false;
708 mwifiex_init_priv_params(priv
, dev
);
710 SET_NETDEV_DEV(dev
, adapter
->dev
);
712 /* Register network device */
713 if (register_netdev(dev
)) {
714 dev_err(adapter
->dev
, "cannot register virtual network device\n");
718 dev_dbg(adapter
->dev
, "info: %s: Marvell 802.11 Adapter\n", dev
->name
);
719 #ifdef CONFIG_DEBUG_FS
720 mwifiex_dev_debugfs_init(priv
);
730 * This function removes a logical interface.
732 * It deregisters, resets and frees the interface by performing
733 * the following operations -
734 * - Disconnect the device if connected, send wireless event to
735 * notify applications.
736 * - Remove the debug FS structure if configured
737 * - Unregister the device from kernel
738 * - Free the net device structure
739 * - Cancel all works and destroy work queue
740 * - Unregister and free the wireless device from CFG80211 subsystem
743 mwifiex_remove_interface(struct mwifiex_adapter
*adapter
, u8 bss_index
)
745 struct net_device
*dev
;
746 struct mwifiex_private
*priv
= adapter
->priv
[bss_index
];
752 if (priv
->media_connected
)
753 priv
->media_connected
= false;
755 #ifdef CONFIG_DEBUG_FS
756 mwifiex_dev_debugfs_remove(priv
);
758 /* Last reference is our one */
759 dev_dbg(adapter
->dev
, "info: %s: refcnt = %d\n",
760 dev
->name
, netdev_refcnt_read(dev
));
762 if (dev
->reg_state
== NETREG_REGISTERED
)
763 unregister_netdev(dev
);
765 /* Clear the priv in adapter */
770 cancel_work_sync(&priv
->cfg_workqueue
);
771 flush_workqueue(priv
->workqueue
);
772 destroy_workqueue(priv
->workqueue
);
773 wiphy_unregister(priv
->wdev
->wiphy
);
774 wiphy_free(priv
->wdev
->wiphy
);
779 * This function check if command is pending.
781 int is_command_pending(struct mwifiex_adapter
*adapter
)
784 int is_cmd_pend_q_empty
;
786 spin_lock_irqsave(&adapter
->cmd_pending_q_lock
, flags
);
787 is_cmd_pend_q_empty
= list_empty(&adapter
->cmd_pending_q
);
788 spin_unlock_irqrestore(&adapter
->cmd_pending_q_lock
, flags
);
790 return !is_cmd_pend_q_empty
;
794 * This function returns the correct private structure pointer based
795 * upon the BSS number.
797 struct mwifiex_private
*
798 mwifiex_bss_index_to_priv(struct mwifiex_adapter
*adapter
, u8 bss_index
)
800 if (!adapter
|| (bss_index
>= adapter
->priv_num
))
802 return adapter
->priv
[bss_index
];
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 cancels all works in the queue and destroys
823 * the main workqueue.
826 mwifiex_terminate_workqueue(struct mwifiex_adapter
*adapter
)
828 flush_workqueue(adapter
->workqueue
);
829 destroy_workqueue(adapter
->workqueue
);
830 adapter
->workqueue
= NULL
;
834 * This function adds the card.
836 * This function follows the following major steps to set up the device -
837 * - Initialize software. This includes probing the card, registering
838 * the interface operations table, and allocating/initializing the
840 * - Set up the netlink socket
841 * - Create and start the main work queue
842 * - Register the device
843 * - Initialize firmware and hardware
844 * - Add logical interfaces
847 mwifiex_add_card(void *card
, struct semaphore
*sem
,
848 struct mwifiex_if_ops
*if_ops
)
851 struct mwifiex_adapter
*adapter
;
853 if (down_interruptible(sem
))
856 if (mwifiex_init_sw(card
, if_ops
, (void **)&adapter
)) {
857 pr_err("%s: software init failed\n", __func__
);
861 adapter
->hw_status
= MWIFIEX_HW_STATUS_INITIALIZING
;
862 adapter
->surprise_removed
= false;
863 init_waitqueue_head(&adapter
->init_wait_q
);
864 adapter
->is_suspended
= false;
865 adapter
->hs_activated
= false;
866 init_waitqueue_head(&adapter
->hs_activate_wait_q
);
867 adapter
->cmd_wait_q_required
= false;
868 init_waitqueue_head(&adapter
->cmd_wait_q
.wait
);
869 adapter
->cmd_wait_q
.condition
= false;
870 adapter
->cmd_wait_q
.status
= 0;
872 adapter
->workqueue
= create_workqueue("MWIFIEX_WORK_QUEUE");
873 if (!adapter
->workqueue
)
876 INIT_WORK(&adapter
->main_work
, mwifiex_main_work_queue
);
878 /* Register the device. Fill up the private data structure with relevant
879 information from the card and request for the required IRQ. */
880 if (adapter
->if_ops
.register_dev(adapter
)) {
881 pr_err("%s: failed to register mwifiex device\n", __func__
);
882 goto err_registerdev
;
885 if (mwifiex_init_hw_fw(adapter
)) {
886 pr_err("%s: firmware init failed\n", __func__
);
891 for (i
= 0; i
< adapter
->drv_mode
->intf_num
; i
++) {
892 if (!mwifiex_add_interface(adapter
, i
,
893 adapter
->drv_mode
->bss_attr
[i
].bss_type
)) {
903 for (i
= 0; i
< adapter
->priv_num
; i
++)
904 mwifiex_remove_interface(adapter
, i
);
906 pr_debug("info: %s: unregister device\n", __func__
);
907 adapter
->if_ops
.unregister_dev(adapter
);
909 adapter
->surprise_removed
= true;
910 mwifiex_terminate_workqueue(adapter
);
912 if ((adapter
->hw_status
== MWIFIEX_HW_STATUS_FW_READY
) ||
913 (adapter
->hw_status
== MWIFIEX_HW_STATUS_READY
)) {
914 pr_debug("info: %s: shutdown mwifiex\n", __func__
);
915 adapter
->init_wait_q_woken
= false;
917 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
918 wait_event_interruptible(adapter
->init_wait_q
,
919 adapter
->init_wait_q_woken
);
922 mwifiex_free_adapter(adapter
);
930 EXPORT_SYMBOL_GPL(mwifiex_add_card
);
933 * This function removes the card.
935 * This function follows the following major steps to remove the device -
936 * - Stop data traffic
937 * - Shutdown firmware
938 * - Remove the logical interfaces
939 * - Terminate the work queue
940 * - Unregister the device
941 * - Free the adapter structure
943 int mwifiex_remove_card(struct mwifiex_adapter
*adapter
, struct semaphore
*sem
)
945 struct mwifiex_private
*priv
= NULL
;
948 if (down_interruptible(sem
))
954 adapter
->surprise_removed
= true;
957 for (i
= 0; i
< adapter
->priv_num
; i
++) {
958 priv
= adapter
->priv
[i
];
960 if (!netif_queue_stopped(priv
->netdev
))
961 netif_stop_queue(priv
->netdev
);
962 if (netif_carrier_ok(priv
->netdev
))
963 netif_carrier_off(priv
->netdev
);
967 dev_dbg(adapter
->dev
, "cmd: calling mwifiex_shutdown_drv...\n");
968 adapter
->init_wait_q_woken
= false;
970 if (mwifiex_shutdown_drv(adapter
) == -EINPROGRESS
)
971 wait_event_interruptible(adapter
->init_wait_q
,
972 adapter
->init_wait_q_woken
);
973 dev_dbg(adapter
->dev
, "cmd: mwifiex_shutdown_drv done\n");
974 if (atomic_read(&adapter
->rx_pending
) ||
975 atomic_read(&adapter
->tx_pending
) ||
976 atomic_read(&adapter
->cmd_pending
)) {
977 dev_err(adapter
->dev
, "rx_pending=%d, tx_pending=%d, "
979 atomic_read(&adapter
->rx_pending
),
980 atomic_read(&adapter
->tx_pending
),
981 atomic_read(&adapter
->cmd_pending
));
984 /* Remove interface */
985 for (i
= 0; i
< adapter
->priv_num
; i
++)
986 mwifiex_remove_interface(adapter
, i
);
988 mwifiex_terminate_workqueue(adapter
);
990 /* Unregister device */
991 dev_dbg(adapter
->dev
, "info: unregister device\n");
992 adapter
->if_ops
.unregister_dev(adapter
);
993 /* Free adapter structure */
994 dev_dbg(adapter
->dev
, "info: free adapter\n");
995 mwifiex_free_adapter(adapter
);
1002 EXPORT_SYMBOL_GPL(mwifiex_remove_card
);
1005 * This function initializes the module.
1007 * The debug FS is also initialized if configured.
1010 mwifiex_init_module(void)
1012 #ifdef CONFIG_DEBUG_FS
1013 mwifiex_debugfs_init();
1019 * This function cleans up the module.
1021 * The debug FS is removed if available.
1024 mwifiex_cleanup_module(void)
1026 #ifdef CONFIG_DEBUG_FS
1027 mwifiex_debugfs_remove();
1031 module_init(mwifiex_init_module
);
1032 module_exit(mwifiex_cleanup_module
);
1034 MODULE_AUTHOR("Marvell International Ltd.");
1035 MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION
);
1036 MODULE_VERSION(VERSION
);
1037 MODULE_LICENSE("GPL v2");