123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809 |
- /*
- * 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"
- #define MFG_FIRMWARE "/*(DEBLOBBED)*/"
- static unsigned int debug_mask = MWIFIEX_DEFAULT_DEBUG_MASK;
- module_param(debug_mask, uint, 0);
- MODULE_PARM_DESC(debug_mask, "bitmap for debug flags");
- const char driver_version[] = "mwifiex " VERSION " (%s) ";
- static char *cal_data_cfg;
- module_param(cal_data_cfg, charp, 0);
- static unsigned short driver_mode;
- module_param(driver_mode, ushort, 0);
- MODULE_PARM_DESC(driver_mode,
- "station=0x1(default), ap-sta=0x3, station-p2p=0x5, ap-sta-p2p=0x7");
- bool mfg_mode;
- module_param(mfg_mode, bool, 0);
- MODULE_PARM_DESC(mfg_mode, "manufacturing mode enable:1, disable: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));
- adapter->debug_mask = debug_mask;
- /* 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);
- setup_timer(&adapter->cmd_timer, mwifiex_cmd_timeout_func,
- (unsigned long)adapter);
- return 0;
- error:
- mwifiex_dbg(adapter, ERROR,
- "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]);
- }
- }
- if (adapter->nd_info) {
- for (i = 0 ; i < adapter->nd_info->n_matches ; i++)
- kfree(adapter->nd_info->matches[i]);
- kfree(adapter->nd_info);
- adapter->nd_info = NULL;
- }
- kfree(adapter->regd);
- kfree(adapter);
- return 0;
- }
- void mwifiex_queue_main_work(struct mwifiex_adapter *adapter)
- {
- unsigned long flags;
- spin_lock_irqsave(&adapter->main_proc_lock, flags);
- if (adapter->mwifiex_processing) {
- adapter->more_task_flag = true;
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- } else {
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- queue_work(adapter->workqueue, &adapter->main_work);
- }
- }
- EXPORT_SYMBOL_GPL(mwifiex_queue_main_work);
- static void mwifiex_queue_rx_work(struct mwifiex_adapter *adapter)
- {
- unsigned long flags;
- spin_lock_irqsave(&adapter->rx_proc_lock, flags);
- if (adapter->rx_processing) {
- spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
- } else {
- spin_unlock_irqrestore(&adapter->rx_proc_lock, flags);
- queue_work(adapter->rx_workqueue, &adapter->rx_work);
- }
- }
- static int mwifiex_process_rx(struct mwifiex_adapter *adapter)
- {
- unsigned long flags;
- struct sk_buff *skb;
- struct mwifiex_rxinfo *rx_info;
- 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 ||
- adapter->iface_type == MWIFIEX_USB) &&
- (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;
- mwifiex_queue_main_work(adapter);
- }
- rx_info = MWIFIEX_SKB_RXCB(skb);
- if (rx_info->buf_type == MWIFIEX_TYPE_AGGR_DATA) {
- if (adapter->if_ops.deaggr_pkt)
- adapter->if_ops.deaggr_pkt(adapter, skb);
- dev_kfree_skb_any(skb);
- } else {
- 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 long flags;
- spin_lock_irqsave(&adapter->main_proc_lock, flags);
- /* Check if already processing */
- if (adapter->mwifiex_processing || adapter->main_locked) {
- adapter->more_task_flag = true;
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- goto exit_main_proc;
- } else {
- adapter->mwifiex_processing = true;
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- }
- process_start:
- do {
- if ((adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING) ||
- (adapter->hw_status == MWIFIEX_HW_STATUS_NOT_READY))
- break;
- /* For non-USB interfaces, If we process interrupts first, it
- * would increase RX pending even further. Avoid this by
- * checking if rx_pending has crossed high threshold and
- * schedule rx work queue and then process interrupts.
- * For USB interface, there are no interrupts. We already have
- * HIGH_RX_PENDING check in usb.c
- */
- if (atomic_read(&adapter->rx_pending) >= HIGH_RX_PENDING &&
- adapter->iface_type != MWIFIEX_USB) {
- adapter->delay_main_work = true;
- mwifiex_queue_rx_work(adapter);
- break;
- }
- /* Handle pending interrupt if any */
- if (adapter->int_status) {
- if (adapter->hs_activated)
- mwifiex_process_hs_config(adapter);
- if (adapter->if_ops.process_int_status)
- adapter->if_ops.process_int_status(adapter);
- }
- if (adapter->rx_work_enabled && adapter->data_received)
- mwifiex_queue_rx_work(adapter);
- /* Need to wake up the card ? */
- if ((adapter->ps_state == PS_STATE_SLEEP) &&
- (adapter->pm_wakeup_card_req &&
- !adapter->pm_wakeup_fw_try) &&
- (is_command_pending(adapter) ||
- !skb_queue_empty(&adapter->tx_data_q) ||
- !mwifiex_bypass_txlist_empty(adapter) ||
- !mwifiex_wmm_lists_empty(adapter))) {
- adapter->pm_wakeup_fw_try = true;
- mod_timer(&adapter->wakeup_timer, jiffies + (HZ*3));
- adapter->if_ops.wakeup(adapter);
- continue;
- }
- if (IS_CARD_RX_RCVD(adapter)) {
- adapter->data_received = false;
- adapter->pm_wakeup_fw_try = false;
- del_timer(&adapter->wakeup_timer);
- if (adapter->ps_state == PS_STATE_SLEEP)
- adapter->ps_state = PS_STATE_AWAKE;
- } else {
- /* We have tried to wakeup the card already */
- if (adapter->pm_wakeup_fw_try)
- break;
- if (adapter->ps_state != PS_STATE_AWAKE)
- break;
- if (adapter->tx_lock_flag) {
- if (adapter->iface_type == MWIFIEX_USB) {
- if (!adapter->usb_mc_setup)
- break;
- } else
- break;
- }
- if ((!adapter->scan_chan_gap_enabled &&
- adapter->scan_processing) || adapter->data_sent ||
- mwifiex_is_tdls_chan_switching
- (mwifiex_get_priv(adapter,
- MWIFIEX_BSS_ROLE_STA)) ||
- (mwifiex_wmm_lists_empty(adapter) &&
- mwifiex_bypass_txlist_empty(adapter) &&
- skb_queue_empty(&adapter->tx_data_q))) {
- if (adapter->cmd_sent || adapter->curr_cmd ||
- !mwifiex_is_send_cmd_allowed
- (mwifiex_get_priv(adapter,
- MWIFIEX_BSS_ROLE_STA)) ||
- (!is_command_pending(adapter)))
- break;
- }
- }
- /* Check for event */
- if (adapter->event_received) {
- adapter->event_received = false;
- mwifiex_process_event(adapter);
- }
- /* Check for Cmd Resp */
- if (adapter->cmd_resp_received) {
- adapter->cmd_resp_received = false;
- mwifiex_process_cmdresp(adapter);
- /* call mwifiex back when init_fw is done */
- if (adapter->hw_status == MWIFIEX_HW_STATUS_INIT_DONE) {
- adapter->hw_status = MWIFIEX_HW_STATUS_READY;
- mwifiex_init_fw_complete(adapter);
- }
- }
- /* Check if we need to confirm Sleep Request
- received previously */
- if (adapter->ps_state == PS_STATE_PRE_SLEEP) {
- if (!adapter->cmd_sent && !adapter->curr_cmd)
- mwifiex_check_ps_cond(adapter);
- }
- /* * The ps_state may have been changed during processing of
- * Sleep Request event.
- */
- if ((adapter->ps_state == PS_STATE_SLEEP) ||
- (adapter->ps_state == PS_STATE_PRE_SLEEP) ||
- (adapter->ps_state == PS_STATE_SLEEP_CFM)) {
- continue;
- }
- if (adapter->tx_lock_flag) {
- if (adapter->iface_type == MWIFIEX_USB) {
- if (!adapter->usb_mc_setup)
- continue;
- } else
- continue;
- }
- if (!adapter->cmd_sent && !adapter->curr_cmd &&
- mwifiex_is_send_cmd_allowed
- (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
- if (mwifiex_exec_next_cmd(adapter) == -1) {
- ret = -1;
- break;
- }
- }
- /** If USB Multi channel setup ongoing,
- * wait for ready to tx data.
- */
- if (adapter->iface_type == MWIFIEX_USB &&
- adapter->usb_mc_setup)
- continue;
- if ((adapter->scan_chan_gap_enabled ||
- !adapter->scan_processing) &&
- !adapter->data_sent &&
- !skb_queue_empty(&adapter->tx_data_q)) {
- mwifiex_process_tx_queue(adapter);
- if (adapter->hs_activated) {
- adapter->is_hs_configured = false;
- mwifiex_hs_activated_event
- (mwifiex_get_priv
- (adapter, MWIFIEX_BSS_ROLE_ANY),
- false);
- }
- }
- if ((adapter->scan_chan_gap_enabled ||
- !adapter->scan_processing) &&
- !adapter->data_sent &&
- !mwifiex_bypass_txlist_empty(adapter) &&
- !mwifiex_is_tdls_chan_switching
- (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
- mwifiex_process_bypass_tx(adapter);
- if (adapter->hs_activated) {
- adapter->is_hs_configured = false;
- mwifiex_hs_activated_event
- (mwifiex_get_priv
- (adapter, MWIFIEX_BSS_ROLE_ANY),
- false);
- }
- }
- if ((adapter->scan_chan_gap_enabled ||
- !adapter->scan_processing) &&
- !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter) &&
- !mwifiex_is_tdls_chan_switching
- (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA))) {
- mwifiex_wmm_process_tx(adapter);
- if (adapter->hs_activated) {
- adapter->is_hs_configured = false;
- mwifiex_hs_activated_event
- (mwifiex_get_priv
- (adapter, MWIFIEX_BSS_ROLE_ANY),
- false);
- }
- }
- if (adapter->delay_null_pkt && !adapter->cmd_sent &&
- !adapter->curr_cmd && !is_command_pending(adapter) &&
- (mwifiex_wmm_lists_empty(adapter) &&
- mwifiex_bypass_txlist_empty(adapter) &&
- skb_queue_empty(&adapter->tx_data_q))) {
- if (!mwifiex_send_null_packet
- (mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
- MWIFIEX_TxPD_POWER_MGMT_NULL_PACKET |
- MWIFIEX_TxPD_POWER_MGMT_LAST_PACKET)) {
- adapter->delay_null_pkt = false;
- adapter->ps_state = PS_STATE_SLEEP;
- }
- break;
- }
- } while (true);
- spin_lock_irqsave(&adapter->main_proc_lock, flags);
- if (adapter->more_task_flag) {
- adapter->more_task_flag = false;
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- goto process_start;
- }
- adapter->mwifiex_processing = false;
- spin_unlock_irqrestore(&adapter->main_proc_lock, flags);
- exit_main_proc:
- if (adapter->hw_status == MWIFIEX_HW_STATUS_CLOSING)
- mwifiex_shutdown_drv(adapter);
- return ret;
- }
- EXPORT_SYMBOL_GPL(mwifiex_main_process);
- /*
- * This function frees the adapter structure.
- *
- * Additionally, this closes the netlink socket, frees the timers
- * and private structures.
- */
- static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
- {
- if (!adapter) {
- pr_err("%s: adapter is NULL\n", __func__);
- return;
- }
- mwifiex_unregister(adapter);
- pr_debug("info: %s: free adapter\n", __func__);
- }
- /*
- * This function cancels all works in the queue and destroys
- * the main workqueue.
- */
- static void mwifiex_terminate_workqueue(struct mwifiex_adapter *adapter)
- {
- if (adapter->workqueue) {
- flush_workqueue(adapter->workqueue);
- destroy_workqueue(adapter->workqueue);
- adapter->workqueue = NULL;
- }
- if (adapter->rx_workqueue) {
- flush_workqueue(adapter->rx_workqueue);
- destroy_workqueue(adapter->rx_workqueue);
- adapter->rx_workqueue = NULL;
- }
- }
- /*
- * This function gets firmware and initializes it.
- *
- * The main initialization steps followed are -
- * - Download the correct firmware to card
- * - Issue the init commands to firmware
- */
- static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
- {
- int ret;
- char fmt[64];
- struct mwifiex_private *priv;
- struct mwifiex_adapter *adapter = context;
- struct mwifiex_fw_image fw;
- struct semaphore *sem = adapter->card_sem;
- bool init_failed = false;
- struct wireless_dev *wdev;
- if (!firmware) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to get firmware %s\n", adapter->fw_name);
- goto err_dnld_fw;
- }
- memset(&fw, 0, sizeof(struct mwifiex_fw_image));
- adapter->firmware = firmware;
- fw.fw_buf = (u8 *) adapter->firmware->data;
- fw.fw_len = adapter->firmware->size;
- if (adapter->if_ops.dnld_fw) {
- ret = adapter->if_ops.dnld_fw(adapter, &fw);
- } else {
- ret = mwifiex_dnld_fw(adapter, &fw);
- }
- if (ret == -1)
- goto err_dnld_fw;
- mwifiex_dbg(adapter, MSG, "WLAN FW is active\n");
- if (cal_data_cfg) {
- if ((reject_firmware(&adapter->cal_data, cal_data_cfg,
- adapter->dev)) < 0)
- mwifiex_dbg(adapter, ERROR,
- "Cal data reject_firmware() failed\n");
- }
- /* enable host interrupt after fw dnld is successful */
- if (adapter->if_ops.enable_int) {
- if (adapter->if_ops.enable_int(adapter))
- goto err_dnld_fw;
- }
- adapter->init_wait_q_woken = false;
- ret = mwifiex_init_fw(adapter);
- if (ret == -1) {
- goto err_init_fw;
- } else if (!ret) {
- adapter->hw_status = MWIFIEX_HW_STATUS_READY;
- goto done;
- }
- /* Wait for mwifiex_init to complete */
- if (!adapter->mfg_mode) {
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
- goto err_init_fw;
- }
- priv = adapter->priv[MWIFIEX_BSS_ROLE_STA];
- if (!adapter->wiphy) {
- if (mwifiex_register_cfg80211(adapter)) {
- mwifiex_dbg(adapter, ERROR,
- "cannot register with cfg80211\n");
- goto err_init_fw;
- }
- }
- if (mwifiex_init_channel_scan_gap(adapter)) {
- mwifiex_dbg(adapter, ERROR,
- "could not init channel stats table\n");
- goto err_init_fw;
- }
- if (driver_mode) {
- driver_mode &= MWIFIEX_DRIVER_MODE_BITMASK;
- driver_mode |= MWIFIEX_DRIVER_MODE_STA;
- }
- rtnl_lock();
- /* Create station interface by default */
- wdev = mwifiex_add_virtual_intf(adapter->wiphy, "mlan%d", NET_NAME_ENUM,
- NL80211_IFTYPE_STATION, NULL, NULL);
- if (IS_ERR(wdev)) {
- mwifiex_dbg(adapter, ERROR,
- "cannot create default STA interface\n");
- rtnl_unlock();
- goto err_add_intf;
- }
- if (driver_mode & MWIFIEX_DRIVER_MODE_UAP) {
- wdev = mwifiex_add_virtual_intf(adapter->wiphy, "uap%d", NET_NAME_ENUM,
- NL80211_IFTYPE_AP, NULL, NULL);
- if (IS_ERR(wdev)) {
- mwifiex_dbg(adapter, ERROR,
- "cannot create AP interface\n");
- rtnl_unlock();
- goto err_add_intf;
- }
- }
- if (driver_mode & MWIFIEX_DRIVER_MODE_P2P) {
- wdev = mwifiex_add_virtual_intf(adapter->wiphy, "p2p%d", NET_NAME_ENUM,
- NL80211_IFTYPE_P2P_CLIENT, NULL,
- NULL);
- if (IS_ERR(wdev)) {
- mwifiex_dbg(adapter, ERROR,
- "cannot create p2p client interface\n");
- rtnl_unlock();
- goto err_add_intf;
- }
- }
- rtnl_unlock();
- mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
- mwifiex_dbg(adapter, MSG, "driver_version = %s\n", fmt);
- goto done;
- err_add_intf:
- vfree(adapter->chan_stats);
- wiphy_unregister(adapter->wiphy);
- wiphy_free(adapter->wiphy);
- err_init_fw:
- if (adapter->if_ops.disable_int)
- adapter->if_ops.disable_int(adapter);
- err_dnld_fw:
- mwifiex_dbg(adapter, ERROR,
- "info: %s: unregister device\n", __func__);
- if (adapter->if_ops.unregister_dev)
- adapter->if_ops.unregister_dev(adapter);
- if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
- pr_debug("info: %s: shutdown mwifiex\n", __func__);
- adapter->init_wait_q_woken = false;
- if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- }
- adapter->surprise_removed = true;
- mwifiex_terminate_workqueue(adapter);
- init_failed = true;
- done:
- if (adapter->cal_data) {
- release_firmware(adapter->cal_data);
- adapter->cal_data = NULL;
- }
- if (adapter->firmware) {
- release_firmware(adapter->firmware);
- adapter->firmware = NULL;
- }
- if (init_failed)
- mwifiex_free_adapter(adapter);
- up(sem);
- return;
- }
- /*
- * This function initializes the hardware and gets firmware.
- */
- static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter,
- bool req_fw_nowait)
- {
- int ret;
- /* Override default firmware with manufacturing one if
- * manufacturing mode is enabled
- */
- if (mfg_mode) {
- if (strlcpy(adapter->fw_name, MFG_FIRMWARE,
- sizeof(adapter->fw_name)) >=
- sizeof(adapter->fw_name)) {
- pr_err("%s: fw_name too long!\n", __func__);
- return -1;
- }
- }
- if (req_fw_nowait) {
- ret = reject_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
- adapter->dev, GFP_KERNEL, adapter,
- mwifiex_fw_dpc);
- if (ret < 0)
- mwifiex_dbg(adapter, ERROR,
- "request_firmware_nowait error %d\n", ret);
- } else {
- ret = reject_firmware(&adapter->firmware,
- adapter->fw_name,
- adapter->dev);
- if (ret < 0)
- mwifiex_dbg(adapter, ERROR,
- "request_firmware error %d\n", ret);
- else
- mwifiex_fw_dpc(adapter->firmware, (void *)adapter);
- }
- return ret;
- }
- /*
- * CFG802.11 network device handler for open.
- *
- * Starts the data queue.
- */
- static int
- mwifiex_open(struct net_device *dev)
- {
- netif_carrier_off(dev);
- return 0;
- }
- /*
- * CFG802.11 network device handler for close.
- */
- static int
- mwifiex_close(struct net_device *dev)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- if (priv->scan_request) {
- struct cfg80211_scan_info info = {
- .aborted = true,
- };
- mwifiex_dbg(priv->adapter, INFO,
- "aborting scan on ndo_stop\n");
- cfg80211_scan_done(priv->scan_request, &info);
- priv->scan_request = NULL;
- priv->scan_aborting = true;
- }
- if (priv->sched_scanning) {
- mwifiex_dbg(priv->adapter, INFO,
- "aborting bgscan on ndo_stop\n");
- mwifiex_stop_bg_scan(priv);
- cfg80211_sched_scan_stopped(priv->wdev.wiphy);
- }
- return 0;
- }
- static bool
- mwifiex_bypass_tx_queue(struct mwifiex_private *priv,
- struct sk_buff *skb)
- {
- struct ethhdr *eth_hdr = (struct ethhdr *)skb->data;
- if (ntohs(eth_hdr->h_proto) == ETH_P_PAE ||
- mwifiex_is_skb_mgmt_frame(skb) ||
- (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA &&
- ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
- (ntohs(eth_hdr->h_proto) == ETH_P_TDLS))) {
- mwifiex_dbg(priv->adapter, DATA,
- "bypass txqueue; eth type %#x, mgmt %d\n",
- ntohs(eth_hdr->h_proto),
- mwifiex_is_skb_mgmt_frame(skb));
- return true;
- }
- return false;
- }
- /*
- * Add buffer into wmm tx queue and queue work to transmit it.
- */
- int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb)
- {
- struct netdev_queue *txq;
- int index = mwifiex_1d_to_wmm_queue[skb->priority];
- if (atomic_inc_return(&priv->wmm_tx_pending[index]) >= MAX_TX_PENDING) {
- txq = netdev_get_tx_queue(priv->netdev, index);
- if (!netif_tx_queue_stopped(txq)) {
- netif_tx_stop_queue(txq);
- mwifiex_dbg(priv->adapter, DATA,
- "stop queue: %d\n", index);
- }
- }
- if (mwifiex_bypass_tx_queue(priv, skb)) {
- atomic_inc(&priv->adapter->tx_pending);
- atomic_inc(&priv->adapter->bypass_tx_pending);
- mwifiex_wmm_add_buf_bypass_txqueue(priv, skb);
- } else {
- atomic_inc(&priv->adapter->tx_pending);
- mwifiex_wmm_add_buf_txqueue(priv, skb);
- }
- mwifiex_queue_main_work(priv->adapter);
- return 0;
- }
- struct sk_buff *
- mwifiex_clone_skb_for_tx_status(struct mwifiex_private *priv,
- struct sk_buff *skb, u8 flag, u64 *cookie)
- {
- struct sk_buff *orig_skb = skb;
- struct mwifiex_txinfo *tx_info, *orig_tx_info;
- skb = skb_clone(skb, GFP_ATOMIC);
- if (skb) {
- unsigned long flags;
- int id;
- spin_lock_irqsave(&priv->ack_status_lock, flags);
- id = idr_alloc(&priv->ack_status_frames, orig_skb,
- 1, 0x10, GFP_ATOMIC);
- spin_unlock_irqrestore(&priv->ack_status_lock, flags);
- if (id >= 0) {
- tx_info = MWIFIEX_SKB_TXCB(skb);
- tx_info->ack_frame_id = id;
- tx_info->flags |= flag;
- orig_tx_info = MWIFIEX_SKB_TXCB(orig_skb);
- orig_tx_info->ack_frame_id = id;
- orig_tx_info->flags |= flag;
- if (flag == MWIFIEX_BUF_FLAG_ACTION_TX_STATUS && cookie)
- orig_tx_info->cookie = *cookie;
- } else if (skb_shared(skb)) {
- kfree_skb(orig_skb);
- } else {
- kfree_skb(skb);
- skb = orig_skb;
- }
- } else {
- /* couldn't clone -- lose tx status ... */
- skb = orig_skb;
- }
- return skb;
- }
- /*
- * CFG802.11 network device handler for data transmission.
- */
- static int
- mwifiex_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- struct sk_buff *new_skb;
- struct mwifiex_txinfo *tx_info;
- bool multicast;
- mwifiex_dbg(priv->adapter, DATA,
- "data: %lu BSS(%d-%d): Data <= kernel\n",
- jiffies, priv->bss_type, priv->bss_num);
- if (priv->adapter->surprise_removed) {
- kfree_skb(skb);
- priv->stats.tx_dropped++;
- return 0;
- }
- if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
- mwifiex_dbg(priv->adapter, ERROR,
- "Tx: bad skb len %d\n", skb->len);
- kfree_skb(skb);
- priv->stats.tx_dropped++;
- return 0;
- }
- if (skb_headroom(skb) < MWIFIEX_MIN_DATA_HEADER_LEN) {
- mwifiex_dbg(priv->adapter, DATA,
- "data: Tx: insufficient skb headroom %d\n",
- skb_headroom(skb));
- /* Insufficient skb headroom - allocate a new skb */
- new_skb =
- skb_realloc_headroom(skb, MWIFIEX_MIN_DATA_HEADER_LEN);
- if (unlikely(!new_skb)) {
- mwifiex_dbg(priv->adapter, ERROR,
- "Tx: cannot alloca new_skb\n");
- kfree_skb(skb);
- priv->stats.tx_dropped++;
- return 0;
- }
- kfree_skb(skb);
- skb = new_skb;
- mwifiex_dbg(priv->adapter, INFO,
- "info: new skb headroomd %d\n",
- skb_headroom(skb));
- }
- tx_info = MWIFIEX_SKB_TXCB(skb);
- memset(tx_info, 0, sizeof(*tx_info));
- tx_info->bss_num = priv->bss_num;
- tx_info->bss_type = priv->bss_type;
- tx_info->pkt_len = skb->len;
- multicast = is_multicast_ether_addr(skb->data);
- if (unlikely(!multicast && skb->sk &&
- skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS &&
- priv->adapter->fw_api_ver == MWIFIEX_FW_V15))
- skb = mwifiex_clone_skb_for_tx_status(priv,
- skb,
- MWIFIEX_BUF_FLAG_EAPOL_TX_STATUS, NULL);
- /* Record the current time the packet was queued; used to
- * determine the amount of time the packet was queued in
- * the driver before it was sent to the firmware.
- * The delay is then sent along with the packet to the
- * firmware for aggregate delay calculation for stats and
- * MSDU lifetime expiry.
- */
- __net_timestamp(skb);
- if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) &&
- priv->bss_type == MWIFIEX_BSS_TYPE_STA &&
- !ether_addr_equal_unaligned(priv->cfg_bssid, skb->data)) {
- if (priv->adapter->auto_tdls && priv->check_tdls_tx)
- mwifiex_tdls_check_tx(priv, skb);
- }
- mwifiex_queue_tx_pkt(priv, skb);
- return 0;
- }
- /*
- * CFG802.11 network device handler for setting MAC address.
- */
- static int
- mwifiex_set_mac_address(struct net_device *dev, void *addr)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- struct sockaddr *hw_addr = addr;
- int ret;
- memcpy(priv->curr_addr, hw_addr->sa_data, ETH_ALEN);
- /* Send request to firmware */
- ret = mwifiex_send_cmd(priv, HostCmd_CMD_802_11_MAC_ADDRESS,
- HostCmd_ACT_GEN_SET, 0, NULL, true);
- if (!ret)
- memcpy(priv->netdev->dev_addr, priv->curr_addr, ETH_ALEN);
- else
- mwifiex_dbg(priv->adapter, ERROR,
- "set mac address failed: ret=%d\n", ret);
- memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
- return ret;
- }
- /*
- * CFG802.11 network device handler for setting multicast list.
- */
- static void mwifiex_set_multicast_list(struct net_device *dev)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- struct mwifiex_multicast_list mcast_list;
- if (dev->flags & IFF_PROMISC) {
- mcast_list.mode = MWIFIEX_PROMISC_MODE;
- } else if (dev->flags & IFF_ALLMULTI ||
- netdev_mc_count(dev) > MWIFIEX_MAX_MULTICAST_LIST_SIZE) {
- mcast_list.mode = MWIFIEX_ALL_MULTI_MODE;
- } else {
- mcast_list.mode = MWIFIEX_MULTICAST_MODE;
- mcast_list.num_multicast_addr =
- mwifiex_copy_mcast_addr(&mcast_list, dev);
- }
- mwifiex_request_set_multicast_list(priv, &mcast_list);
- }
- /*
- * CFG802.11 network device handler for transmission timeout.
- */
- static void
- mwifiex_tx_timeout(struct net_device *dev)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- priv->num_tx_timeout++;
- priv->tx_timeout_cnt++;
- mwifiex_dbg(priv->adapter, ERROR,
- "%lu : Tx timeout(#%d), bss_type-num = %d-%d\n",
- jiffies, priv->tx_timeout_cnt, priv->bss_type,
- priv->bss_num);
- mwifiex_set_trans_start(dev);
- if (priv->tx_timeout_cnt > TX_TIMEOUT_THRESHOLD &&
- priv->adapter->if_ops.card_reset) {
- mwifiex_dbg(priv->adapter, ERROR,
- "tx_timeout_cnt exceeds threshold.\t"
- "Triggering card reset!\n");
- priv->adapter->if_ops.card_reset(priv->adapter);
- }
- }
- void mwifiex_multi_chan_resync(struct mwifiex_adapter *adapter)
- {
- struct usb_card_rec *card = adapter->card;
- struct mwifiex_private *priv;
- u16 tx_buf_size;
- int i, ret;
- card->mc_resync_flag = true;
- for (i = 0; i < MWIFIEX_TX_DATA_PORT; i++) {
- if (atomic_read(&card->port[i].tx_data_urb_pending)) {
- mwifiex_dbg(adapter, WARN, "pending data urb in sys\n");
- return;
- }
- }
- card->mc_resync_flag = false;
- tx_buf_size = 0xffff;
- priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
- ret = mwifiex_send_cmd(priv, HostCmd_CMD_RECONFIGURE_TX_BUFF,
- HostCmd_ACT_GEN_SET, 0, &tx_buf_size, false);
- if (ret)
- mwifiex_dbg(adapter, ERROR,
- "send reconfig tx buf size cmd err\n");
- }
- EXPORT_SYMBOL_GPL(mwifiex_multi_chan_resync);
- void mwifiex_drv_info_dump(struct mwifiex_adapter *adapter)
- {
- void *p;
- char drv_version[64];
- struct usb_card_rec *cardp;
- struct sdio_mmc_card *sdio_card;
- struct mwifiex_private *priv;
- int i, idx;
- struct netdev_queue *txq;
- struct mwifiex_debug_info *debug_info;
- if (adapter->drv_info_dump) {
- vfree(adapter->drv_info_dump);
- adapter->drv_info_dump = NULL;
- adapter->drv_info_size = 0;
- }
- mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump start===\n");
- adapter->drv_info_dump = vzalloc(MWIFIEX_DRV_INFO_SIZE_MAX);
- if (!adapter->drv_info_dump)
- return;
- p = (char *)(adapter->drv_info_dump);
- p += sprintf(p, "driver_name = " "\"mwifiex\"\n");
- mwifiex_drv_get_driver_version(adapter, drv_version,
- sizeof(drv_version) - 1);
- p += sprintf(p, "driver_version = %s\n", drv_version);
- if (adapter->iface_type == MWIFIEX_USB) {
- cardp = (struct usb_card_rec *)adapter->card;
- p += sprintf(p, "tx_cmd_urb_pending = %d\n",
- atomic_read(&cardp->tx_cmd_urb_pending));
- p += sprintf(p, "tx_data_urb_pending_port_0 = %d\n",
- atomic_read(&cardp->port[0].tx_data_urb_pending));
- p += sprintf(p, "tx_data_urb_pending_port_1 = %d\n",
- atomic_read(&cardp->port[1].tx_data_urb_pending));
- p += sprintf(p, "rx_cmd_urb_pending = %d\n",
- atomic_read(&cardp->rx_cmd_urb_pending));
- p += sprintf(p, "rx_data_urb_pending = %d\n",
- atomic_read(&cardp->rx_data_urb_pending));
- }
- p += sprintf(p, "tx_pending = %d\n",
- atomic_read(&adapter->tx_pending));
- p += sprintf(p, "rx_pending = %d\n",
- atomic_read(&adapter->rx_pending));
- if (adapter->iface_type == MWIFIEX_SDIO) {
- sdio_card = (struct sdio_mmc_card *)adapter->card;
- p += sprintf(p, "\nmp_rd_bitmap=0x%x curr_rd_port=0x%x\n",
- sdio_card->mp_rd_bitmap, sdio_card->curr_rd_port);
- p += sprintf(p, "mp_wr_bitmap=0x%x curr_wr_port=0x%x\n",
- sdio_card->mp_wr_bitmap, sdio_card->curr_wr_port);
- }
- for (i = 0; i < adapter->priv_num; i++) {
- if (!adapter->priv[i] || !adapter->priv[i]->netdev)
- continue;
- priv = adapter->priv[i];
- p += sprintf(p, "\n[interface : \"%s\"]\n",
- priv->netdev->name);
- p += sprintf(p, "wmm_tx_pending[0] = %d\n",
- atomic_read(&priv->wmm_tx_pending[0]));
- p += sprintf(p, "wmm_tx_pending[1] = %d\n",
- atomic_read(&priv->wmm_tx_pending[1]));
- p += sprintf(p, "wmm_tx_pending[2] = %d\n",
- atomic_read(&priv->wmm_tx_pending[2]));
- p += sprintf(p, "wmm_tx_pending[3] = %d\n",
- atomic_read(&priv->wmm_tx_pending[3]));
- p += sprintf(p, "media_state=\"%s\"\n", !priv->media_connected ?
- "Disconnected" : "Connected");
- p += sprintf(p, "carrier %s\n", (netif_carrier_ok(priv->netdev)
- ? "on" : "off"));
- for (idx = 0; idx < priv->netdev->num_tx_queues; idx++) {
- txq = netdev_get_tx_queue(priv->netdev, idx);
- p += sprintf(p, "tx queue %d:%s ", idx,
- netif_tx_queue_stopped(txq) ?
- "stopped" : "started");
- }
- p += sprintf(p, "\n%s: num_tx_timeout = %d\n",
- priv->netdev->name, priv->num_tx_timeout);
- }
- if (adapter->iface_type == MWIFIEX_SDIO ||
- adapter->iface_type == MWIFIEX_PCIE) {
- p += sprintf(p, "\n=== %s register dump===\n",
- adapter->iface_type == MWIFIEX_SDIO ?
- "SDIO" : "PCIE");
- if (adapter->if_ops.reg_dump)
- p += adapter->if_ops.reg_dump(adapter, p);
- }
- p += sprintf(p, "\n=== more debug information\n");
- debug_info = kzalloc(sizeof(*debug_info), GFP_KERNEL);
- if (debug_info) {
- for (i = 0; i < adapter->priv_num; i++) {
- if (!adapter->priv[i] || !adapter->priv[i]->netdev)
- continue;
- priv = adapter->priv[i];
- mwifiex_get_debug_info(priv, debug_info);
- p += mwifiex_debug_info_to_buffer(priv, p, debug_info);
- break;
- }
- kfree(debug_info);
- }
- adapter->drv_info_size = p - adapter->drv_info_dump;
- mwifiex_dbg(adapter, MSG, "===mwifiex driverinfo dump end===\n");
- }
- EXPORT_SYMBOL_GPL(mwifiex_drv_info_dump);
- void mwifiex_upload_device_dump(struct mwifiex_adapter *adapter)
- {
- u8 idx, *dump_data, *fw_dump_ptr;
- u32 dump_len;
- dump_len = (strlen("========Start dump driverinfo========\n") +
- adapter->drv_info_size +
- strlen("\n========End dump========\n"));
- for (idx = 0; idx < adapter->num_mem_types; idx++) {
- struct memory_type_mapping *entry =
- &adapter->mem_type_mapping_tbl[idx];
- if (entry->mem_ptr) {
- dump_len += (strlen("========Start dump ") +
- strlen(entry->mem_name) +
- strlen("========\n") +
- (entry->mem_size + 1) +
- strlen("\n========End dump========\n"));
- }
- }
- dump_data = vzalloc(dump_len + 1);
- if (!dump_data)
- goto done;
- fw_dump_ptr = dump_data;
- /* Dump all the memory data into single file, a userspace script will
- * be used to split all the memory data to multiple files
- */
- mwifiex_dbg(adapter, MSG,
- "== mwifiex dump information to /sys/class/devcoredump start");
- strcpy(fw_dump_ptr, "========Start dump driverinfo========\n");
- fw_dump_ptr += strlen("========Start dump driverinfo========\n");
- memcpy(fw_dump_ptr, adapter->drv_info_dump, adapter->drv_info_size);
- fw_dump_ptr += adapter->drv_info_size;
- strcpy(fw_dump_ptr, "\n========End dump========\n");
- fw_dump_ptr += strlen("\n========End dump========\n");
- for (idx = 0; idx < adapter->num_mem_types; idx++) {
- struct memory_type_mapping *entry =
- &adapter->mem_type_mapping_tbl[idx];
- if (entry->mem_ptr) {
- strcpy(fw_dump_ptr, "========Start dump ");
- fw_dump_ptr += strlen("========Start dump ");
- strcpy(fw_dump_ptr, entry->mem_name);
- fw_dump_ptr += strlen(entry->mem_name);
- strcpy(fw_dump_ptr, "========\n");
- fw_dump_ptr += strlen("========\n");
- memcpy(fw_dump_ptr, entry->mem_ptr, entry->mem_size);
- fw_dump_ptr += entry->mem_size;
- strcpy(fw_dump_ptr, "\n========End dump========\n");
- fw_dump_ptr += strlen("\n========End dump========\n");
- }
- }
- /* device dump data will be free in device coredump release function
- * after 5 min
- */
- dev_coredumpv(adapter->dev, dump_data, dump_len, GFP_KERNEL);
- mwifiex_dbg(adapter, MSG,
- "== mwifiex dump information to /sys/class/devcoredump end");
- done:
- for (idx = 0; idx < adapter->num_mem_types; idx++) {
- struct memory_type_mapping *entry =
- &adapter->mem_type_mapping_tbl[idx];
- if (entry->mem_ptr) {
- vfree(entry->mem_ptr);
- entry->mem_ptr = NULL;
- }
- entry->mem_size = 0;
- }
- if (adapter->drv_info_dump) {
- vfree(adapter->drv_info_dump);
- adapter->drv_info_dump = NULL;
- adapter->drv_info_size = 0;
- }
- }
- EXPORT_SYMBOL_GPL(mwifiex_upload_device_dump);
- /*
- * CFG802.11 network device handler for statistics retrieval.
- */
- static struct net_device_stats *mwifiex_get_stats(struct net_device *dev)
- {
- struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
- return &priv->stats;
- }
- static u16
- mwifiex_netdev_select_wmm_queue(struct net_device *dev, struct sk_buff *skb,
- void *accel_priv, select_queue_fallback_t fallback)
- {
- skb->priority = cfg80211_classify8021d(skb, NULL);
- return mwifiex_1d_to_wmm_queue[skb->priority];
- }
- /* Network device handlers */
- static const struct net_device_ops mwifiex_netdev_ops = {
- .ndo_open = mwifiex_open,
- .ndo_stop = mwifiex_close,
- .ndo_start_xmit = mwifiex_hard_start_xmit,
- .ndo_set_mac_address = mwifiex_set_mac_address,
- .ndo_validate_addr = eth_validate_addr,
- .ndo_tx_timeout = mwifiex_tx_timeout,
- .ndo_get_stats = mwifiex_get_stats,
- .ndo_set_rx_mode = mwifiex_set_multicast_list,
- .ndo_select_queue = mwifiex_netdev_select_wmm_queue,
- };
- /*
- * This function initializes the private structure parameters.
- *
- * The following wait queues are initialized -
- * - IOCTL wait queue
- * - Command wait queue
- * - Statistics wait queue
- *
- * ...and the following default parameters are set -
- * - Current key index : Set to 0
- * - Rate index : Set to auto
- * - Media connected : Set to disconnected
- * - Adhoc link sensed : Set to false
- * - Nick name : Set to null
- * - Number of Tx timeout : Set to 0
- * - Device address : Set to current address
- * - Rx histogram statistc : Set to 0
- *
- * In addition, the CFG80211 work queue is also created.
- */
- void mwifiex_init_priv_params(struct mwifiex_private *priv,
- struct net_device *dev)
- {
- dev->netdev_ops = &mwifiex_netdev_ops;
- dev->destructor = free_netdev;
- /* Initialize private structure */
- priv->current_key_index = 0;
- priv->media_connected = false;
- memset(priv->mgmt_ie, 0,
- sizeof(struct mwifiex_ie) * MAX_MGMT_IE_INDEX);
- priv->beacon_idx = MWIFIEX_AUTO_IDX_MASK;
- priv->proberesp_idx = MWIFIEX_AUTO_IDX_MASK;
- priv->assocresp_idx = MWIFIEX_AUTO_IDX_MASK;
- priv->gen_idx = MWIFIEX_AUTO_IDX_MASK;
- priv->num_tx_timeout = 0;
- ether_addr_copy(priv->curr_addr, priv->adapter->perm_addr);
- memcpy(dev->dev_addr, priv->curr_addr, ETH_ALEN);
- if (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA ||
- GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_UAP) {
- priv->hist_data = kmalloc(sizeof(*priv->hist_data), GFP_KERNEL);
- if (priv->hist_data)
- mwifiex_hist_data_reset(priv);
- }
- }
- /*
- * This function check if command is pending.
- */
- int is_command_pending(struct mwifiex_adapter *adapter)
- {
- unsigned long flags;
- int is_cmd_pend_q_empty;
- spin_lock_irqsave(&adapter->cmd_pending_q_lock, flags);
- is_cmd_pend_q_empty = list_empty(&adapter->cmd_pending_q);
- spin_unlock_irqrestore(&adapter->cmd_pending_q_lock, flags);
- return !is_cmd_pend_q_empty;
- }
- /*
- * This is the RX work queue function.
- *
- * It handles the RX operations.
- */
- static void mwifiex_rx_work_queue(struct work_struct *work)
- {
- struct mwifiex_adapter *adapter =
- container_of(work, struct mwifiex_adapter, rx_work);
- if (adapter->surprise_removed)
- return;
- mwifiex_process_rx(adapter);
- }
- /*
- * This is the main work queue function.
- *
- * It handles the main process, which in turn handles the complete
- * driver operations.
- */
- static void mwifiex_main_work_queue(struct work_struct *work)
- {
- struct mwifiex_adapter *adapter =
- container_of(work, struct mwifiex_adapter, main_work);
- if (adapter->surprise_removed)
- return;
- mwifiex_main_process(adapter);
- }
- /*
- * This function gets called during PCIe function level reset. Required
- * code is extracted from mwifiex_remove_card()
- */
- static int
- mwifiex_shutdown_sw(struct mwifiex_adapter *adapter, struct semaphore *sem)
- {
- struct mwifiex_private *priv;
- int i;
- if (!adapter)
- goto exit_return;
- if (down_interruptible(sem))
- goto exit_sem_err;
- priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
- mwifiex_deauthenticate(priv, NULL);
- /* We can no longer handle interrupts once we start doing the teardown
- * below.
- */
- if (adapter->if_ops.disable_int)
- adapter->if_ops.disable_int(adapter);
- adapter->surprise_removed = true;
- mwifiex_terminate_workqueue(adapter);
- /* Stop data */
- for (i = 0; i < adapter->priv_num; i++) {
- priv = adapter->priv[i];
- if (priv && priv->netdev) {
- mwifiex_stop_net_dev_queue(priv->netdev, adapter);
- if (netif_carrier_ok(priv->netdev))
- netif_carrier_off(priv->netdev);
- netif_device_detach(priv->netdev);
- }
- }
- mwifiex_dbg(adapter, CMD, "cmd: calling mwifiex_shutdown_drv...\n");
- adapter->init_wait_q_woken = false;
- if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- if (adapter->if_ops.down_dev)
- adapter->if_ops.down_dev(adapter);
- mwifiex_dbg(adapter, CMD, "cmd: mwifiex_shutdown_drv done\n");
- if (atomic_read(&adapter->rx_pending) ||
- atomic_read(&adapter->tx_pending) ||
- atomic_read(&adapter->cmd_pending)) {
- mwifiex_dbg(adapter, ERROR,
- "rx_pending=%d, tx_pending=%d,\t"
- "cmd_pending=%d\n",
- atomic_read(&adapter->rx_pending),
- atomic_read(&adapter->tx_pending),
- atomic_read(&adapter->cmd_pending));
- }
- for (i = 0; i < adapter->priv_num; i++) {
- priv = adapter->priv[i];
- if (!priv)
- continue;
- rtnl_lock();
- if (priv->netdev &&
- priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
- mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
- rtnl_unlock();
- }
- vfree(adapter->chan_stats);
- up(sem);
- exit_sem_err:
- mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
- exit_return:
- return 0;
- }
- /* This function gets called during PCIe function level reset. Required
- * code is extracted from mwifiex_add_card()
- */
- static int
- mwifiex_reinit_sw(struct mwifiex_adapter *adapter, struct semaphore *sem,
- struct mwifiex_if_ops *if_ops, u8 iface_type)
- {
- char fw_name[32];
- struct pcie_service_card *card = adapter->card;
- if (down_interruptible(sem))
- goto exit_sem_err;
- mwifiex_init_lock_list(adapter);
- if (adapter->if_ops.up_dev)
- adapter->if_ops.up_dev(adapter);
- adapter->iface_type = iface_type;
- adapter->card_sem = sem;
- adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
- adapter->surprise_removed = false;
- init_waitqueue_head(&adapter->init_wait_q);
- adapter->is_suspended = false;
- adapter->hs_activated = false;
- init_waitqueue_head(&adapter->hs_activate_wait_q);
- init_waitqueue_head(&adapter->cmd_wait_q.wait);
- adapter->cmd_wait_q.status = 0;
- adapter->scan_wait_q_woken = false;
- if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB)
- adapter->rx_work_enabled = true;
- adapter->workqueue =
- alloc_workqueue("MWIFIEX_WORK_QUEUE",
- WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
- if (!adapter->workqueue)
- goto err_kmalloc;
- INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
- if (adapter->rx_work_enabled) {
- adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
- WQ_HIGHPRI |
- WQ_MEM_RECLAIM |
- WQ_UNBOUND, 1);
- if (!adapter->rx_workqueue)
- goto err_kmalloc;
- INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
- }
- /* Register the device. Fill up the private data structure with
- * relevant information from the card. Some code extracted from
- * mwifiex_register_dev()
- */
- mwifiex_dbg(adapter, INFO, "%s, mwifiex_init_hw_fw()...\n", __func__);
- strcpy(fw_name, adapter->fw_name);
- strcpy(adapter->fw_name, PCIE8997_DEFAULT_WIFIFW_NAME);
- adapter->tx_buf_size = card->pcie.tx_buf_size;
- adapter->ext_scan = card->pcie.can_ext_scan;
- if (mwifiex_init_hw_fw(adapter, false)) {
- strcpy(adapter->fw_name, fw_name);
- mwifiex_dbg(adapter, ERROR,
- "%s: firmware init failed\n", __func__);
- goto err_init_fw;
- }
- strcpy(adapter->fw_name, fw_name);
- mwifiex_dbg(adapter, INFO, "%s, successful\n", __func__);
- up(sem);
- return 0;
- err_init_fw:
- mwifiex_dbg(adapter, ERROR, "info: %s: unregister device\n", __func__);
- if (adapter->if_ops.unregister_dev)
- adapter->if_ops.unregister_dev(adapter);
- if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
- mwifiex_dbg(adapter, ERROR,
- "info: %s: shutdown mwifiex\n", __func__);
- adapter->init_wait_q_woken = false;
- if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- }
- err_kmalloc:
- mwifiex_terminate_workqueue(adapter);
- adapter->surprise_removed = true;
- up(sem);
- exit_sem_err:
- mwifiex_dbg(adapter, INFO, "%s, error\n", __func__);
- return -1;
- }
- /* This function processes pre and post PCIe function level resets.
- * It performs software cleanup without touching PCIe specific code.
- * Also, during initialization PCIe stuff is skipped.
- */
- void mwifiex_do_flr(struct mwifiex_adapter *adapter, bool prepare)
- {
- struct mwifiex_if_ops if_ops;
- if (!prepare) {
- mwifiex_reinit_sw(adapter, adapter->card_sem, &if_ops,
- adapter->iface_type);
- } else {
- memcpy(&if_ops, &adapter->if_ops,
- sizeof(struct mwifiex_if_ops));
- mwifiex_shutdown_sw(adapter, adapter->card_sem);
- }
- }
- EXPORT_SYMBOL_GPL(mwifiex_do_flr);
- /*
- * This function adds the card.
- *
- * This function follows the following major steps to set up the device -
- * - Initialize software. This includes probing the card, registering
- * the interface operations table, and allocating/initializing the
- * adapter structure
- * - Set up the netlink socket
- * - Create and start the main work queue
- * - Register the device
- * - Initialize firmware and hardware
- * - Add logical interfaces
- */
- int
- mwifiex_add_card(void *card, struct semaphore *sem,
- struct mwifiex_if_ops *if_ops, u8 iface_type)
- {
- struct mwifiex_adapter *adapter;
- if (down_interruptible(sem))
- goto exit_sem_err;
- if (mwifiex_register(card, if_ops, (void **)&adapter)) {
- pr_err("%s: software init failed\n", __func__);
- goto err_init_sw;
- }
- adapter->iface_type = iface_type;
- adapter->card_sem = sem;
- adapter->hw_status = MWIFIEX_HW_STATUS_INITIALIZING;
- adapter->surprise_removed = false;
- init_waitqueue_head(&adapter->init_wait_q);
- adapter->is_suspended = false;
- adapter->hs_activated = false;
- init_waitqueue_head(&adapter->hs_activate_wait_q);
- init_waitqueue_head(&adapter->cmd_wait_q.wait);
- adapter->cmd_wait_q.status = 0;
- adapter->scan_wait_q_woken = false;
- if ((num_possible_cpus() > 1) || adapter->iface_type == MWIFIEX_USB) {
- adapter->rx_work_enabled = true;
- pr_notice("rx work enabled, cpus %d\n", num_possible_cpus());
- }
- adapter->workqueue =
- alloc_workqueue("MWIFIEX_WORK_QUEUE",
- WQ_HIGHPRI | WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
- if (!adapter->workqueue)
- goto err_kmalloc;
- INIT_WORK(&adapter->main_work, mwifiex_main_work_queue);
- if (adapter->rx_work_enabled) {
- adapter->rx_workqueue = alloc_workqueue("MWIFIEX_RX_WORK_QUEUE",
- WQ_HIGHPRI |
- WQ_MEM_RECLAIM |
- WQ_UNBOUND, 1);
- if (!adapter->rx_workqueue)
- goto err_kmalloc;
- INIT_WORK(&adapter->rx_work, mwifiex_rx_work_queue);
- }
- /* Register the device. Fill up the private data structure with relevant
- information from the card. */
- if (adapter->if_ops.register_dev(adapter)) {
- pr_err("%s: failed to register mwifiex device\n", __func__);
- goto err_registerdev;
- }
- if (mwifiex_init_hw_fw(adapter, true)) {
- pr_err("%s: firmware init failed\n", __func__);
- goto err_init_fw;
- }
- return 0;
- err_init_fw:
- pr_debug("info: %s: unregister device\n", __func__);
- if (adapter->if_ops.unregister_dev)
- adapter->if_ops.unregister_dev(adapter);
- if (adapter->hw_status == MWIFIEX_HW_STATUS_READY) {
- pr_debug("info: %s: shutdown mwifiex\n", __func__);
- adapter->init_wait_q_woken = false;
- if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- }
- err_registerdev:
- adapter->surprise_removed = true;
- mwifiex_terminate_workqueue(adapter);
- err_kmalloc:
- mwifiex_free_adapter(adapter);
- err_init_sw:
- up(sem);
- exit_sem_err:
- return -1;
- }
- EXPORT_SYMBOL_GPL(mwifiex_add_card);
- /*
- * This function removes the card.
- *
- * This function follows the following major steps to remove the device -
- * - Stop data traffic
- * - Shutdown firmware
- * - Remove the logical interfaces
- * - Terminate the work queue
- * - Unregister the device
- * - Free the adapter structure
- */
- int mwifiex_remove_card(struct mwifiex_adapter *adapter, struct semaphore *sem)
- {
- struct mwifiex_private *priv = NULL;
- int i;
- if (down_trylock(sem))
- goto exit_sem_err;
- if (!adapter)
- goto exit_remove;
- /* We can no longer handle interrupts once we start doing the teardown
- * below. */
- if (adapter->if_ops.disable_int)
- adapter->if_ops.disable_int(adapter);
- adapter->surprise_removed = true;
- mwifiex_terminate_workqueue(adapter);
- /* Stop data */
- for (i = 0; i < adapter->priv_num; i++) {
- priv = adapter->priv[i];
- if (priv && priv->netdev) {
- mwifiex_stop_net_dev_queue(priv->netdev, adapter);
- if (netif_carrier_ok(priv->netdev))
- netif_carrier_off(priv->netdev);
- }
- }
- mwifiex_dbg(adapter, CMD,
- "cmd: calling mwifiex_shutdown_drv...\n");
- adapter->init_wait_q_woken = false;
- if (mwifiex_shutdown_drv(adapter) == -EINPROGRESS)
- wait_event_interruptible(adapter->init_wait_q,
- adapter->init_wait_q_woken);
- mwifiex_dbg(adapter, CMD,
- "cmd: mwifiex_shutdown_drv done\n");
- if (atomic_read(&adapter->rx_pending) ||
- atomic_read(&adapter->tx_pending) ||
- atomic_read(&adapter->cmd_pending)) {
- mwifiex_dbg(adapter, ERROR,
- "rx_pending=%d, tx_pending=%d,\t"
- "cmd_pending=%d\n",
- atomic_read(&adapter->rx_pending),
- atomic_read(&adapter->tx_pending),
- atomic_read(&adapter->cmd_pending));
- }
- for (i = 0; i < adapter->priv_num; i++) {
- priv = adapter->priv[i];
- if (!priv)
- continue;
- rtnl_lock();
- if (priv->netdev &&
- priv->wdev.iftype != NL80211_IFTYPE_UNSPECIFIED)
- mwifiex_del_virtual_intf(adapter->wiphy, &priv->wdev);
- rtnl_unlock();
- }
- vfree(adapter->chan_stats);
- wiphy_unregister(adapter->wiphy);
- wiphy_free(adapter->wiphy);
- /* Unregister device */
- mwifiex_dbg(adapter, INFO,
- "info: unregister device\n");
- if (adapter->if_ops.unregister_dev)
- adapter->if_ops.unregister_dev(adapter);
- /* Free adapter structure */
- mwifiex_dbg(adapter, INFO,
- "info: free adapter\n");
- mwifiex_free_adapter(adapter);
- exit_remove:
- up(sem);
- exit_sem_err:
- return 0;
- }
- EXPORT_SYMBOL_GPL(mwifiex_remove_card);
- void _mwifiex_dbg(const struct mwifiex_adapter *adapter, int mask,
- const char *fmt, ...)
- {
- struct va_format vaf;
- va_list args;
- if (!adapter->dev || !(adapter->debug_mask & mask))
- return;
- va_start(args, fmt);
- vaf.fmt = fmt;
- vaf.va = &args;
- dev_info(adapter->dev, "%pV", &vaf);
- va_end(args);
- }
- EXPORT_SYMBOL_GPL(_mwifiex_dbg);
- /*
- * This function initializes the module.
- *
- * The debug FS is also initialized if configured.
- */
- static int
- mwifiex_init_module(void)
- {
- #ifdef CONFIG_DEBUG_FS
- mwifiex_debugfs_init();
- #endif
- return 0;
- }
- /*
- * This function cleans up the module.
- *
- * The debug FS is removed if available.
- */
- static void
- mwifiex_cleanup_module(void)
- {
- #ifdef CONFIG_DEBUG_FS
- mwifiex_debugfs_remove();
- #endif
- }
- module_init(mwifiex_init_module);
- module_exit(mwifiex_cleanup_module);
- MODULE_AUTHOR("Marvell International Ltd.");
- MODULE_DESCRIPTION("Marvell WiFi-Ex Driver version " VERSION);
- MODULE_VERSION(VERSION);
- MODULE_LICENSE("GPL v2");
|