/*
* Marvell Wireless LAN device driver: major functions
*
* Copyright (C) 2011-2014, Marvell International Ltd.
*
* This software file (the "File") is distributed by Marvell International
* Ltd. under the terms of the GNU General Public License Version 2, June 1991
* (the "License"). You may use, redistribute and/or modify this File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
* worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*/
#include "main.h"
#include "wmm.h"
#include "cfg80211.h"
#include "11n.h"
#define VERSION "1.0"
const char driver_version[] = "mwifiex " VERSION " (%s) ";
static char *cal_data_cfg;
module_param(cal_data_cfg, charp, 0);
/*
* This function registers the device and performs all the necessary
* initializations.
*
* The following initialization operations are performed -
* - Allocate adapter structure
* - Save interface specific operations table in adapter
* - Call interface specific initialization routine
* - Allocate private structures
* - Set default adapter structure parameters
* - Initialize locks
*
* In case of any errors during inittialization, this function also ensures
* proper cleanup before exiting.
*/
static int mwifiex_register(void *card, struct mwifiex_if_ops *if_ops,
void **padapter)
{
struct mwifiex_adapter *adapter;
int i;
adapter = kzalloc(sizeof(struct mwifiex_adapter), GFP_KERNEL);
if (!adapter)
return -ENOMEM;
*padapter = adapter;
adapter->card = card;
/* Save interface specific operations in adapter */
memmove(&adapter->if_ops, if_ops, sizeof(struct mwifiex_if_ops));
/* card specific initialization has been deferred until now .. */
if (adapter->if_ops.init_if)
if (adapter->if_ops.init_if(adapter))
goto error;
adapter->priv_num = 0;
for (i = 0; i < MWIFIEX_MAX_BSS_NUM; i++) {
/* Allocate memory for private structure */
adapter->priv[i] =
kzalloc(sizeof(struct mwifiex_private), GFP_KERNEL);
if (!adapter->priv[i])
goto error;
adapter->priv[i]->adapter = adapter;
adapter->priv_num++;
}
mwifiex_init_lock_list(adapter);
init_timer(&adapter->cmd_timer);
adapter->cmd_timer.function = mwifiex_cmd_timeout_func;
adapter->cmd_timer.data = (unsigned long) adapter;
return 0;
error:
dev_dbg(adapter->dev, "info: leave mwifiex_register with error\n");
for (i = 0; i < adapter->priv_num; i++)
kfree(adapter->priv[i]);
kfree(adapter);
return -1;
}
/*
* This function unregisters the device and performs all the necessary
* cleanups.
*
* The following cleanup operations are performed -
* - Free the timers
* - Free beacon buffers
* - Free private structures
* - Free adapter structure
*/
static int mwifiex_unregister(struct mwifiex_adapter *adapter)
{
s32 i;
if (adapter->if_ops.cleanup_if)
adapter->if_ops.cleanup_if(adapter);
del_timer_sync(&adapter->cmd_timer);
/* Free private structures */
for (i = 0; i < adapter->priv_num; i++) {
if (adapter->priv[i]) {
mwifiex_free_curr_bcn(adapter->priv[i]);
kfree(adapter->priv[i]);
}
}
vfree(adapter->chan_stats);
kfree(adapter);
return 0;
}
static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
{
unsigned long flags;
struct sk_buff *skb;
spin_lock_irqsave(&adapter->rx_proc_lock, flags);
if (adapter->rx_processing || adapter->rx_locked) {
spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
goto exit_rx_proc;
} else {
adapter->rx_processing = true;
spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
}
/* Check for Rx data */
while ((skb = skb_dequeue(&adapter->rx_data_q))) {
atomic_dec(&adapter->rx_pending);
if (adapter->delay_main_work &&
(atomic_read(&adapter->rx_pending) < LOW_RX_PENDING)) {
if (adapter->if_ops.submit_rem_rx_urbs)
adapter->if_ops.submit_rem_rx_urbs(adapter);
adapter->delay_main_work = false;
queue_work(adapter->workqueue, &adapter->main_work);
}
mwifiex_handle_rx_packet(adapter, skb);
}
spin_lock_irqsave(&adapter->rx_proc_lock, flags);
adapter->rx_processing = false;
spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
exit_rx_proc:
return 0;
}
/*
* The main process.
*
* This function is the main procedure of the driver and handles various driver
* operations. It runs in a loop and provides the core functionalities.
*
* The main responsibilities of this function are -
* - Ensure concurrency control
* - Handle pending interrupts and call interrupt handlers
* - Wake up the card if required
* - Handle command responses and call response handlers
* - Handle events and call event handlers
* - Execute pending commands
* - Transmit pending data packets
*/
int mwifiex_main_process(struct mwifiex_adapter *adapter)
{
int ret = 0;
unsigned