123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733 |
- /*
- * Marvell Wireless LAN device driver: PCIE specific handling
- *
- * 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 <linux/firmware.h>
- #include "decl.h"
- #include "ioctl.h"
- #include "util.h"
- #include "fw.h"
- #include "main.h"
- #include "wmm.h"
- #include "11n.h"
- #include "pcie.h"
- #define PCIE_VERSION "1.0"
- #define DRV_NAME "Marvell mwifiex PCIe"
- static u8 user_rmmod;
- static struct mwifiex_if_ops pcie_ops;
- static struct semaphore add_remove_card_sem;
- static struct memory_type_mapping mem_type_mapping_tbl[] = {
- {"ITCM", NULL, 0, 0xF0},
- {"DTCM", NULL, 0, 0xF1},
- {"SQRAM", NULL, 0, 0xF2},
- {"IRAM", NULL, 0, 0xF3},
- {"APU", NULL, 0, 0xF4},
- {"CIU", NULL, 0, 0xF5},
- {"ICU", NULL, 0, 0xF6},
- {"MAC", NULL, 0, 0xF7},
- };
- static int
- mwifiex_map_pci_memory(struct mwifiex_adapter *adapter, struct sk_buff *skb,
- size_t size, int flags)
- {
- struct pcie_service_card *card = adapter->card;
- struct mwifiex_dma_mapping mapping;
- mapping.addr = pci_map_single(card->dev, skb->data, size, flags);
- if (pci_dma_mapping_error(card->dev, mapping.addr)) {
- mwifiex_dbg(adapter, ERROR, "failed to map pci memory!\n");
- return -1;
- }
- mapping.len = size;
- mwifiex_store_mapping(skb, &mapping);
- return 0;
- }
- static void mwifiex_unmap_pci_memory(struct mwifiex_adapter *adapter,
- struct sk_buff *skb, int flags)
- {
- struct pcie_service_card *card = adapter->card;
- struct mwifiex_dma_mapping mapping;
- mwifiex_get_mapping(skb, &mapping);
- pci_unmap_single(card->dev, mapping.addr, mapping.len, flags);
- }
- /*
- * This function reads sleep cookie and checks if FW is ready
- */
- static bool mwifiex_pcie_ok_to_access_hw(struct mwifiex_adapter *adapter)
- {
- u32 *cookie_addr;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- if (!reg->sleep_cookie)
- return true;
- if (card->sleep_cookie_vbase) {
- cookie_addr = (u32 *)card->sleep_cookie_vbase;
- mwifiex_dbg(adapter, INFO,
- "info: ACCESS_HW: sleep cookie=0x%x\n",
- *cookie_addr);
- if (*cookie_addr == FW_AWAKE_COOKIE)
- return true;
- }
- return false;
- }
- #ifdef CONFIG_PM_SLEEP
- /*
- * Kernel needs to suspend all functions separately. Therefore all
- * registered functions must have drivers with suspend and resume
- * methods. Failing that the kernel simply removes the whole card.
- *
- * If already not suspended, this function allocates and sends a host
- * sleep activate request to the firmware and turns off the traffic.
- */
- static int mwifiex_pcie_suspend(struct device *dev)
- {
- struct mwifiex_adapter *adapter;
- struct pcie_service_card *card;
- int hs_actived;
- struct pci_dev *pdev = to_pci_dev(dev);
- if (pdev) {
- card = pci_get_drvdata(pdev);
- if (!card || !card->adapter) {
- pr_err("Card or adapter structure is not valid\n");
- return 0;
- }
- } else {
- pr_err("PCIE device is not specified\n");
- return 0;
- }
- adapter = card->adapter;
- hs_actived = mwifiex_enable_hs(adapter);
- /* Indicate device suspended */
- adapter->is_suspended = true;
- adapter->hs_enabling = false;
- return 0;
- }
- /*
- * Kernel needs to suspend all functions separately. Therefore all
- * registered functions must have drivers with suspend and resume
- * methods. Failing that the kernel simply removes the whole card.
- *
- * If already not resumed, this function turns on the traffic and
- * sends a host sleep cancel request to the firmware.
- */
- static int mwifiex_pcie_resume(struct device *dev)
- {
- struct mwifiex_adapter *adapter;
- struct pcie_service_card *card;
- struct pci_dev *pdev = to_pci_dev(dev);
- if (pdev) {
- card = pci_get_drvdata(pdev);
- if (!card || !card->adapter) {
- pr_err("Card or adapter structure is not valid\n");
- return 0;
- }
- } else {
- pr_err("PCIE device is not specified\n");
- return 0;
- }
- adapter = card->adapter;
- if (!adapter->is_suspended) {
- mwifiex_dbg(adapter, WARN,
- "Device already resumed\n");
- return 0;
- }
- adapter->is_suspended = false;
- mwifiex_cancel_hs(mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_STA),
- MWIFIEX_ASYNC_CMD);
- return 0;
- }
- #endif
- /*
- * This function probes an mwifiex device and registers it. It allocates
- * the card structure, enables PCIE function number and initiates the
- * device registration and initialization procedure by adding a logical
- * interface.
- */
- static int mwifiex_pcie_probe(struct pci_dev *pdev,
- const struct pci_device_id *ent)
- {
- struct pcie_service_card *card;
- pr_debug("info: vendor=0x%4.04X device=0x%4.04X rev=%d\n",
- pdev->vendor, pdev->device, pdev->revision);
- card = kzalloc(sizeof(struct pcie_service_card), GFP_KERNEL);
- if (!card)
- return -ENOMEM;
- card->dev = pdev;
- if (ent->driver_data) {
- struct mwifiex_pcie_device *data = (void *)ent->driver_data;
- card->pcie.firmware = data->firmware;
- card->pcie.reg = data->reg;
- card->pcie.blksz_fw_dl = data->blksz_fw_dl;
- card->pcie.tx_buf_size = data->tx_buf_size;
- card->pcie.can_dump_fw = data->can_dump_fw;
- card->pcie.can_ext_scan = data->can_ext_scan;
- }
- if (mwifiex_add_card(card, &add_remove_card_sem, &pcie_ops,
- MWIFIEX_PCIE)) {
- pr_err("%s failed\n", __func__);
- kfree(card);
- return -1;
- }
- return 0;
- }
- /*
- * This function removes the interface and frees up the card structure.
- */
- static void mwifiex_pcie_remove(struct pci_dev *pdev)
- {
- struct pcie_service_card *card;
- struct mwifiex_adapter *adapter;
- struct mwifiex_private *priv;
- card = pci_get_drvdata(pdev);
- if (!card)
- return;
- adapter = card->adapter;
- if (!adapter || !adapter->priv_num)
- return;
- if (user_rmmod) {
- #ifdef CONFIG_PM_SLEEP
- if (adapter->is_suspended)
- mwifiex_pcie_resume(&pdev->dev);
- #endif
- mwifiex_deauthenticate_all(adapter);
- priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
- mwifiex_disable_auto_ds(priv);
- mwifiex_init_shutdown_fw(priv, MWIFIEX_FUNC_SHUTDOWN);
- }
- mwifiex_remove_card(card->adapter, &add_remove_card_sem);
- }
- static void mwifiex_pcie_shutdown(struct pci_dev *pdev)
- {
- user_rmmod = 1;
- mwifiex_pcie_remove(pdev);
- return;
- }
- static const struct pci_device_id mwifiex_ids[] = {
- {
- PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8766P,
- PCI_ANY_ID, PCI_ANY_ID, 0, 0,
- .driver_data = (unsigned long) &mwifiex_pcie8766,
- },
- {
- PCIE_VENDOR_ID_MARVELL, PCIE_DEVICE_ID_MARVELL_88W8897,
- PCI_ANY_ID, PCI_ANY_ID, 0, 0,
- .driver_data = (unsigned long) &mwifiex_pcie8897,
- },
- {},
- };
- MODULE_DEVICE_TABLE(pci, mwifiex_ids);
- #ifdef CONFIG_PM_SLEEP
- /* Power Management Hooks */
- static SIMPLE_DEV_PM_OPS(mwifiex_pcie_pm_ops, mwifiex_pcie_suspend,
- mwifiex_pcie_resume);
- #endif
- /* PCI Device Driver */
- static struct pci_driver __refdata mwifiex_pcie = {
- .name = "mwifiex_pcie",
- .id_table = mwifiex_ids,
- .probe = mwifiex_pcie_probe,
- .remove = mwifiex_pcie_remove,
- #ifdef CONFIG_PM_SLEEP
- .driver = {
- .pm = &mwifiex_pcie_pm_ops,
- },
- #endif
- .shutdown = mwifiex_pcie_shutdown,
- };
- /*
- * This function writes data into PCIE card register.
- */
- static int mwifiex_write_reg(struct mwifiex_adapter *adapter, int reg, u32 data)
- {
- struct pcie_service_card *card = adapter->card;
- iowrite32(data, card->pci_mmap1 + reg);
- return 0;
- }
- /*
- * This function reads data from PCIE card register.
- */
- static int mwifiex_read_reg(struct mwifiex_adapter *adapter, int reg, u32 *data)
- {
- struct pcie_service_card *card = adapter->card;
- *data = ioread32(card->pci_mmap1 + reg);
- return 0;
- }
- /* This function reads u8 data from PCIE card register. */
- static int mwifiex_read_reg_byte(struct mwifiex_adapter *adapter,
- int reg, u8 *data)
- {
- struct pcie_service_card *card = adapter->card;
- *data = ioread8(card->pci_mmap1 + reg);
- return 0;
- }
- /*
- * This function adds delay loop to ensure FW is awake before proceeding.
- */
- static void mwifiex_pcie_dev_wakeup_delay(struct mwifiex_adapter *adapter)
- {
- int i = 0;
- while (mwifiex_pcie_ok_to_access_hw(adapter)) {
- i++;
- usleep_range(10, 20);
- /* 50ms max wait */
- if (i == 5000)
- break;
- }
- return;
- }
- static void mwifiex_delay_for_sleep_cookie(struct mwifiex_adapter *adapter,
- u32 max_delay_loop_cnt)
- {
- struct pcie_service_card *card = adapter->card;
- u8 *buffer;
- u32 sleep_cookie, count;
- for (count = 0; count < max_delay_loop_cnt; count++) {
- buffer = card->cmdrsp_buf->data - INTF_HEADER_LEN;
- sleep_cookie = *(u32 *)buffer;
- if (sleep_cookie == MWIFIEX_DEF_SLEEP_COOKIE) {
- mwifiex_dbg(adapter, INFO,
- "sleep cookie found at count %d\n", count);
- break;
- }
- usleep_range(20, 30);
- }
- if (count >= max_delay_loop_cnt)
- mwifiex_dbg(adapter, INFO,
- "max count reached while accessing sleep cookie\n");
- }
- /* This function wakes up the card by reading fw_status register. */
- static int mwifiex_pm_wakeup_card(struct mwifiex_adapter *adapter)
- {
- u32 fw_status;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- mwifiex_dbg(adapter, EVENT,
- "event: Wakeup device...\n");
- if (reg->sleep_cookie)
- mwifiex_pcie_dev_wakeup_delay(adapter);
- /* Reading fw_status register will wakeup device */
- if (mwifiex_read_reg(adapter, reg->fw_status, &fw_status)) {
- mwifiex_dbg(adapter, ERROR,
- "Reading fw_status register failed\n");
- return -1;
- }
- if (reg->sleep_cookie) {
- mwifiex_pcie_dev_wakeup_delay(adapter);
- mwifiex_dbg(adapter, INFO,
- "PCIE wakeup: Setting PS_STATE_AWAKE\n");
- adapter->ps_state = PS_STATE_AWAKE;
- }
- return 0;
- }
- /*
- * This function is called after the card has woken up.
- *
- * The card configuration register is reset.
- */
- static int mwifiex_pm_wakeup_card_complete(struct mwifiex_adapter *adapter)
- {
- mwifiex_dbg(adapter, CMD,
- "cmd: Wakeup device completed\n");
- return 0;
- }
- /*
- * This function disables the host interrupt.
- *
- * The host interrupt mask is read, the disable bit is reset and
- * written back to the card host interrupt mask register.
- */
- static int mwifiex_pcie_disable_host_int(struct mwifiex_adapter *adapter)
- {
- if (mwifiex_pcie_ok_to_access_hw(adapter)) {
- if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
- 0x00000000)) {
- mwifiex_dbg(adapter, ERROR,
- "Disable host interrupt failed\n");
- return -1;
- }
- }
- return 0;
- }
- /*
- * This function enables the host interrupt.
- *
- * The host interrupt enable mask is written to the card
- * host interrupt mask register.
- */
- static int mwifiex_pcie_enable_host_int(struct mwifiex_adapter *adapter)
- {
- if (mwifiex_pcie_ok_to_access_hw(adapter)) {
- /* Simply write the mask to the register */
- if (mwifiex_write_reg(adapter, PCIE_HOST_INT_MASK,
- HOST_INTR_MASK)) {
- mwifiex_dbg(adapter, ERROR,
- "Enable host interrupt failed\n");
- return -1;
- }
- }
- return 0;
- }
- /*
- * This function initializes TX buffer ring descriptors
- */
- static int mwifiex_init_txq_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- int i;
- for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
- card->tx_buf_list[i] = NULL;
- if (reg->pfu_enabled) {
- card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
- (sizeof(*desc2) * i);
- desc2 = card->txbd_ring[i];
- memset(desc2, 0, sizeof(*desc2));
- } else {
- card->txbd_ring[i] = (void *)card->txbd_ring_vbase +
- (sizeof(*desc) * i);
- desc = card->txbd_ring[i];
- memset(desc, 0, sizeof(*desc));
- }
- }
- return 0;
- }
- /* This function initializes RX buffer ring descriptors. Each SKB is allocated
- * here and after mapping PCI memory, its physical address is assigned to
- * PCIE Rx buffer descriptor's physical address.
- */
- static int mwifiex_init_rxq_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- struct sk_buff *skb;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- dma_addr_t buf_pa;
- int i;
- for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
- /* Allocate skb here so that firmware can DMA data from it */
- skb = mwifiex_alloc_dma_align_buf(MWIFIEX_RX_DATA_BUF_SIZE,
- GFP_KERNEL | GFP_DMA);
- if (!skb) {
- mwifiex_dbg(adapter, ERROR,
- "Unable to allocate skb for RX ring.\n");
- kfree(card->rxbd_ring_vbase);
- return -ENOMEM;
- }
- if (mwifiex_map_pci_memory(adapter, skb,
- MWIFIEX_RX_DATA_BUF_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
- mwifiex_dbg(adapter, INFO,
- "info: RX ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
- skb, skb->len, skb->data, (u32)buf_pa,
- (u32)((u64)buf_pa >> 32));
- card->rx_buf_list[i] = skb;
- if (reg->pfu_enabled) {
- card->rxbd_ring[i] = (void *)card->rxbd_ring_vbase +
- (sizeof(*desc2) * i);
- desc2 = card->rxbd_ring[i];
- desc2->paddr = buf_pa;
- desc2->len = (u16)skb->len;
- desc2->frag_len = (u16)skb->len;
- desc2->flags = reg->ring_flag_eop | reg->ring_flag_sop;
- desc2->offset = 0;
- } else {
- card->rxbd_ring[i] = (void *)(card->rxbd_ring_vbase +
- (sizeof(*desc) * i));
- desc = card->rxbd_ring[i];
- desc->paddr = buf_pa;
- desc->len = (u16)skb->len;
- desc->flags = 0;
- }
- }
- return 0;
- }
- /* This function initializes event buffer ring descriptors. Each SKB is
- * allocated here and after mapping PCI memory, its physical address is assigned
- * to PCIE Rx buffer descriptor's physical address
- */
- static int mwifiex_pcie_init_evt_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- struct mwifiex_evt_buf_desc *desc;
- struct sk_buff *skb;
- dma_addr_t buf_pa;
- int i;
- for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
- /* Allocate skb here so that firmware can DMA data from it */
- skb = dev_alloc_skb(MAX_EVENT_SIZE);
- if (!skb) {
- mwifiex_dbg(adapter, ERROR,
- "Unable to allocate skb for EVENT buf.\n");
- kfree(card->evtbd_ring_vbase);
- return -ENOMEM;
- }
- skb_put(skb, MAX_EVENT_SIZE);
- if (mwifiex_map_pci_memory(adapter, skb, MAX_EVENT_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
- mwifiex_dbg(adapter, EVENT,
- "info: EVT ring: skb=%p len=%d data=%p buf_pa=%#x:%x\n",
- skb, skb->len, skb->data, (u32)buf_pa,
- (u32)((u64)buf_pa >> 32));
- card->evt_buf_list[i] = skb;
- card->evtbd_ring[i] = (void *)(card->evtbd_ring_vbase +
- (sizeof(*desc) * i));
- desc = card->evtbd_ring[i];
- desc->paddr = buf_pa;
- desc->len = (u16)skb->len;
- desc->flags = 0;
- }
- return 0;
- }
- /* This function cleans up TX buffer rings. If any of the buffer list has valid
- * SKB address, associated SKB is freed.
- */
- static void mwifiex_cleanup_txq_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- struct sk_buff *skb;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- int i;
- for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
- if (reg->pfu_enabled) {
- desc2 = card->txbd_ring[i];
- if (card->tx_buf_list[i]) {
- skb = card->tx_buf_list[i];
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_TODEVICE);
- dev_kfree_skb_any(skb);
- }
- memset(desc2, 0, sizeof(*desc2));
- } else {
- desc = card->txbd_ring[i];
- if (card->tx_buf_list[i]) {
- skb = card->tx_buf_list[i];
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_TODEVICE);
- dev_kfree_skb_any(skb);
- }
- memset(desc, 0, sizeof(*desc));
- }
- card->tx_buf_list[i] = NULL;
- }
- return;
- }
- /* This function cleans up RX buffer rings. If any of the buffer list has valid
- * SKB address, associated SKB is freed.
- */
- static void mwifiex_cleanup_rxq_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- struct sk_buff *skb;
- int i;
- for (i = 0; i < MWIFIEX_MAX_TXRX_BD; i++) {
- if (reg->pfu_enabled) {
- desc2 = card->rxbd_ring[i];
- if (card->rx_buf_list[i]) {
- skb = card->rx_buf_list[i];
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_FROMDEVICE);
- dev_kfree_skb_any(skb);
- }
- memset(desc2, 0, sizeof(*desc2));
- } else {
- desc = card->rxbd_ring[i];
- if (card->rx_buf_list[i]) {
- skb = card->rx_buf_list[i];
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_FROMDEVICE);
- dev_kfree_skb_any(skb);
- }
- memset(desc, 0, sizeof(*desc));
- }
- card->rx_buf_list[i] = NULL;
- }
- return;
- }
- /* This function cleans up event buffer rings. If any of the buffer list has
- * valid SKB address, associated SKB is freed.
- */
- static void mwifiex_cleanup_evt_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- struct mwifiex_evt_buf_desc *desc;
- struct sk_buff *skb;
- int i;
- for (i = 0; i < MWIFIEX_MAX_EVT_BD; i++) {
- desc = card->evtbd_ring[i];
- if (card->evt_buf_list[i]) {
- skb = card->evt_buf_list[i];
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_FROMDEVICE);
- dev_kfree_skb_any(skb);
- }
- card->evt_buf_list[i] = NULL;
- memset(desc, 0, sizeof(*desc));
- }
- return;
- }
- /* This function creates buffer descriptor ring for TX
- */
- static int mwifiex_pcie_create_txbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- /*
- * driver maintaines the write pointer and firmware maintaines the read
- * pointer. The write pointer starts at 0 (zero) while the read pointer
- * starts at zero with rollover bit set
- */
- card->txbd_wrptr = 0;
- if (reg->pfu_enabled)
- card->txbd_rdptr = 0;
- else
- card->txbd_rdptr |= reg->tx_rollover_ind;
- /* allocate shared memory for the BD ring and divide the same in to
- several descriptors */
- if (reg->pfu_enabled)
- card->txbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
- MWIFIEX_MAX_TXRX_BD;
- else
- card->txbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
- MWIFIEX_MAX_TXRX_BD;
- mwifiex_dbg(adapter, INFO,
- "info: txbd_ring: Allocating %d bytes\n",
- card->txbd_ring_size);
- card->txbd_ring_vbase = pci_alloc_consistent(card->dev,
- card->txbd_ring_size,
- &card->txbd_ring_pbase);
- if (!card->txbd_ring_vbase) {
- mwifiex_dbg(adapter, ERROR,
- "allocate consistent memory (%d bytes) failed!\n",
- card->txbd_ring_size);
- return -ENOMEM;
- }
- mwifiex_dbg(adapter, DATA,
- "info: txbd_ring - base: %p, pbase: %#x:%x, len: %x\n",
- card->txbd_ring_vbase, (unsigned int)card->txbd_ring_pbase,
- (u32)((u64)card->txbd_ring_pbase >> 32),
- card->txbd_ring_size);
- return mwifiex_init_txq_ring(adapter);
- }
- static int mwifiex_pcie_delete_txbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- mwifiex_cleanup_txq_ring(adapter);
- if (card->txbd_ring_vbase)
- pci_free_consistent(card->dev, card->txbd_ring_size,
- card->txbd_ring_vbase,
- card->txbd_ring_pbase);
- card->txbd_ring_size = 0;
- card->txbd_wrptr = 0;
- card->txbd_rdptr = 0 | reg->tx_rollover_ind;
- card->txbd_ring_vbase = NULL;
- card->txbd_ring_pbase = 0;
- return 0;
- }
- /*
- * This function creates buffer descriptor ring for RX
- */
- static int mwifiex_pcie_create_rxbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- /*
- * driver maintaines the read pointer and firmware maintaines the write
- * pointer. The write pointer starts at 0 (zero) while the read pointer
- * starts at zero with rollover bit set
- */
- card->rxbd_wrptr = 0;
- card->rxbd_rdptr = reg->rx_rollover_ind;
- if (reg->pfu_enabled)
- card->rxbd_ring_size = sizeof(struct mwifiex_pfu_buf_desc) *
- MWIFIEX_MAX_TXRX_BD;
- else
- card->rxbd_ring_size = sizeof(struct mwifiex_pcie_buf_desc) *
- MWIFIEX_MAX_TXRX_BD;
- mwifiex_dbg(adapter, INFO,
- "info: rxbd_ring: Allocating %d bytes\n",
- card->rxbd_ring_size);
- card->rxbd_ring_vbase = pci_alloc_consistent(card->dev,
- card->rxbd_ring_size,
- &card->rxbd_ring_pbase);
- if (!card->rxbd_ring_vbase) {
- mwifiex_dbg(adapter, ERROR,
- "allocate consistent memory (%d bytes) failed!\n",
- card->rxbd_ring_size);
- return -ENOMEM;
- }
- mwifiex_dbg(adapter, DATA,
- "info: rxbd_ring - base: %p, pbase: %#x:%x, len: %#x\n",
- card->rxbd_ring_vbase, (u32)card->rxbd_ring_pbase,
- (u32)((u64)card->rxbd_ring_pbase >> 32),
- card->rxbd_ring_size);
- return mwifiex_init_rxq_ring(adapter);
- }
- /*
- * This function deletes Buffer descriptor ring for RX
- */
- static int mwifiex_pcie_delete_rxbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- mwifiex_cleanup_rxq_ring(adapter);
- if (card->rxbd_ring_vbase)
- pci_free_consistent(card->dev, card->rxbd_ring_size,
- card->rxbd_ring_vbase,
- card->rxbd_ring_pbase);
- card->rxbd_ring_size = 0;
- card->rxbd_wrptr = 0;
- card->rxbd_rdptr = 0 | reg->rx_rollover_ind;
- card->rxbd_ring_vbase = NULL;
- card->rxbd_ring_pbase = 0;
- return 0;
- }
- /*
- * This function creates buffer descriptor ring for Events
- */
- static int mwifiex_pcie_create_evtbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- /*
- * driver maintaines the read pointer and firmware maintaines the write
- * pointer. The write pointer starts at 0 (zero) while the read pointer
- * starts at zero with rollover bit set
- */
- card->evtbd_wrptr = 0;
- card->evtbd_rdptr = reg->evt_rollover_ind;
- card->evtbd_ring_size = sizeof(struct mwifiex_evt_buf_desc) *
- MWIFIEX_MAX_EVT_BD;
- mwifiex_dbg(adapter, INFO,
- "info: evtbd_ring: Allocating %d bytes\n",
- card->evtbd_ring_size);
- card->evtbd_ring_vbase = pci_alloc_consistent(card->dev,
- card->evtbd_ring_size,
- &card->evtbd_ring_pbase);
- if (!card->evtbd_ring_vbase) {
- mwifiex_dbg(adapter, ERROR,
- "allocate consistent memory (%d bytes) failed!\n",
- card->evtbd_ring_size);
- return -ENOMEM;
- }
- mwifiex_dbg(adapter, EVENT,
- "info: CMDRSP/EVT bd_ring - base: %p pbase: %#x:%x len: %#x\n",
- card->evtbd_ring_vbase, (u32)card->evtbd_ring_pbase,
- (u32)((u64)card->evtbd_ring_pbase >> 32),
- card->evtbd_ring_size);
- return mwifiex_pcie_init_evt_ring(adapter);
- }
- /*
- * This function deletes Buffer descriptor ring for Events
- */
- static int mwifiex_pcie_delete_evtbd_ring(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- mwifiex_cleanup_evt_ring(adapter);
- if (card->evtbd_ring_vbase)
- pci_free_consistent(card->dev, card->evtbd_ring_size,
- card->evtbd_ring_vbase,
- card->evtbd_ring_pbase);
- card->evtbd_wrptr = 0;
- card->evtbd_rdptr = 0 | reg->evt_rollover_ind;
- card->evtbd_ring_size = 0;
- card->evtbd_ring_vbase = NULL;
- card->evtbd_ring_pbase = 0;
- return 0;
- }
- /*
- * This function allocates a buffer for CMDRSP
- */
- static int mwifiex_pcie_alloc_cmdrsp_buf(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- struct sk_buff *skb;
- /* Allocate memory for receiving command response data */
- skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
- if (!skb) {
- mwifiex_dbg(adapter, ERROR,
- "Unable to allocate skb for command response data.\n");
- return -ENOMEM;
- }
- skb_put(skb, MWIFIEX_UPLD_SIZE);
- if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- card->cmdrsp_buf = skb;
- return 0;
- }
- /*
- * This function deletes a buffer for CMDRSP
- */
- static int mwifiex_pcie_delete_cmdrsp_buf(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card;
- if (!adapter)
- return 0;
- card = adapter->card;
- if (card && card->cmdrsp_buf) {
- mwifiex_unmap_pci_memory(adapter, card->cmdrsp_buf,
- PCI_DMA_FROMDEVICE);
- dev_kfree_skb_any(card->cmdrsp_buf);
- }
- if (card && card->cmd_buf) {
- mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
- PCI_DMA_TODEVICE);
- }
- return 0;
- }
- /*
- * This function allocates a buffer for sleep cookie
- */
- static int mwifiex_pcie_alloc_sleep_cookie_buf(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- card->sleep_cookie_vbase = pci_alloc_consistent(card->dev, sizeof(u32),
- &card->sleep_cookie_pbase);
- if (!card->sleep_cookie_vbase) {
- mwifiex_dbg(adapter, ERROR,
- "pci_alloc_consistent failed!\n");
- return -ENOMEM;
- }
- /* Init val of Sleep Cookie */
- *(u32 *)card->sleep_cookie_vbase = FW_AWAKE_COOKIE;
- mwifiex_dbg(adapter, INFO,
- "alloc_scook: sleep cookie=0x%x\n",
- *((u32 *)card->sleep_cookie_vbase));
- return 0;
- }
- /*
- * This function deletes buffer for sleep cookie
- */
- static int mwifiex_pcie_delete_sleep_cookie_buf(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card;
- if (!adapter)
- return 0;
- card = adapter->card;
- if (card && card->sleep_cookie_vbase) {
- pci_free_consistent(card->dev, sizeof(u32),
- card->sleep_cookie_vbase,
- card->sleep_cookie_pbase);
- card->sleep_cookie_vbase = NULL;
- }
- return 0;
- }
- /* This function flushes the TX buffer descriptor ring
- * This function defined as handler is also called while cleaning TXRX
- * during disconnect/ bss stop.
- */
- static int mwifiex_clean_pcie_ring_buf(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- if (!mwifiex_pcie_txbd_empty(card, card->txbd_rdptr)) {
- card->txbd_flush = 1;
- /* write pointer already set at last send
- * send dnld-rdy intr again, wait for completion.
- */
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_DNLD_RDY)) {
- mwifiex_dbg(adapter, ERROR,
- "failed to assert dnld-rdy interrupt.\n");
- return -1;
- }
- }
- return 0;
- }
- /*
- * This function unmaps and frees downloaded data buffer
- */
- static int mwifiex_pcie_send_data_complete(struct mwifiex_adapter *adapter)
- {
- struct sk_buff *skb;
- u32 wrdoneidx, rdptr, num_tx_buffs, unmap_count = 0;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- mwifiex_pm_wakeup_card(adapter);
- /* Read the TX ring read pointer set by firmware */
- if (mwifiex_read_reg(adapter, reg->tx_rdptr, &rdptr)) {
- mwifiex_dbg(adapter, ERROR,
- "SEND COMP: failed to read reg->tx_rdptr\n");
- return -1;
- }
- mwifiex_dbg(adapter, DATA,
- "SEND COMP: rdptr_prev=0x%x, rdptr=0x%x\n",
- card->txbd_rdptr, rdptr);
- num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
- /* free from previous txbd_rdptr to current txbd_rdptr */
- while (((card->txbd_rdptr & reg->tx_mask) !=
- (rdptr & reg->tx_mask)) ||
- ((card->txbd_rdptr & reg->tx_rollover_ind) !=
- (rdptr & reg->tx_rollover_ind))) {
- wrdoneidx = (card->txbd_rdptr & reg->tx_mask) >>
- reg->tx_start_ptr;
- skb = card->tx_buf_list[wrdoneidx];
- if (skb) {
- mwifiex_dbg(adapter, DATA,
- "SEND COMP: Detach skb %p at txbd_rdidx=%d\n",
- skb, wrdoneidx);
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_TODEVICE);
- unmap_count++;
- if (card->txbd_flush)
- mwifiex_write_data_complete(adapter, skb, 0,
- -1);
- else
- mwifiex_write_data_complete(adapter, skb, 0, 0);
- }
- card->tx_buf_list[wrdoneidx] = NULL;
- if (reg->pfu_enabled) {
- desc2 = card->txbd_ring[wrdoneidx];
- memset(desc2, 0, sizeof(*desc2));
- } else {
- desc = card->txbd_ring[wrdoneidx];
- memset(desc, 0, sizeof(*desc));
- }
- switch (card->dev->device) {
- case PCIE_DEVICE_ID_MARVELL_88W8766P:
- card->txbd_rdptr++;
- break;
- case PCIE_DEVICE_ID_MARVELL_88W8897:
- card->txbd_rdptr += reg->ring_tx_start_ptr;
- break;
- }
- if ((card->txbd_rdptr & reg->tx_mask) == num_tx_buffs)
- card->txbd_rdptr = ((card->txbd_rdptr &
- reg->tx_rollover_ind) ^
- reg->tx_rollover_ind);
- }
- if (unmap_count)
- adapter->data_sent = false;
- if (card->txbd_flush) {
- if (mwifiex_pcie_txbd_empty(card, card->txbd_rdptr))
- card->txbd_flush = 0;
- else
- mwifiex_clean_pcie_ring_buf(adapter);
- }
- return 0;
- }
- /* This function sends data buffer to device. First 4 bytes of payload
- * are filled with payload length and payload type. Then this payload
- * is mapped to PCI device memory. Tx ring pointers are advanced accordingly.
- * Download ready interrupt to FW is deffered if Tx ring is not full and
- * additional payload can be accomodated.
- * Caller must ensure tx_param parameter to this function is not NULL.
- */
- static int
- mwifiex_pcie_send_data(struct mwifiex_adapter *adapter, struct sk_buff *skb,
- struct mwifiex_tx_param *tx_param)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- u32 wrindx, num_tx_buffs, rx_val;
- int ret;
- dma_addr_t buf_pa;
- struct mwifiex_pcie_buf_desc *desc = NULL;
- struct mwifiex_pfu_buf_desc *desc2 = NULL;
- __le16 *tmp;
- if (!(skb->data && skb->len)) {
- mwifiex_dbg(adapter, ERROR,
- "%s(): invalid parameter <%p, %#x>\n",
- __func__, skb->data, skb->len);
- return -1;
- }
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- mwifiex_pm_wakeup_card(adapter);
- num_tx_buffs = MWIFIEX_MAX_TXRX_BD << reg->tx_start_ptr;
- mwifiex_dbg(adapter, DATA,
- "info: SEND DATA: <Rd: %#x, Wr: %#x>\n",
- card->txbd_rdptr, card->txbd_wrptr);
- if (mwifiex_pcie_txbd_not_full(card)) {
- u8 *payload;
- adapter->data_sent = true;
- payload = skb->data;
- tmp = (__le16 *)&payload[0];
- *tmp = cpu_to_le16((u16)skb->len);
- tmp = (__le16 *)&payload[2];
- *tmp = cpu_to_le16(MWIFIEX_TYPE_DATA);
- if (mwifiex_map_pci_memory(adapter, skb, skb->len,
- PCI_DMA_TODEVICE))
- return -1;
- wrindx = (card->txbd_wrptr & reg->tx_mask) >> reg->tx_start_ptr;
- buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
- card->tx_buf_list[wrindx] = skb;
- if (reg->pfu_enabled) {
- desc2 = card->txbd_ring[wrindx];
- desc2->paddr = buf_pa;
- desc2->len = (u16)skb->len;
- desc2->frag_len = (u16)skb->len;
- desc2->offset = 0;
- desc2->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
- MWIFIEX_BD_FLAG_LAST_DESC;
- } else {
- desc = card->txbd_ring[wrindx];
- desc->paddr = buf_pa;
- desc->len = (u16)skb->len;
- desc->flags = MWIFIEX_BD_FLAG_FIRST_DESC |
- MWIFIEX_BD_FLAG_LAST_DESC;
- }
- switch (card->dev->device) {
- case PCIE_DEVICE_ID_MARVELL_88W8766P:
- card->txbd_wrptr++;
- break;
- case PCIE_DEVICE_ID_MARVELL_88W8897:
- card->txbd_wrptr += reg->ring_tx_start_ptr;
- break;
- }
- if ((card->txbd_wrptr & reg->tx_mask) == num_tx_buffs)
- card->txbd_wrptr = ((card->txbd_wrptr &
- reg->tx_rollover_ind) ^
- reg->tx_rollover_ind);
- rx_val = card->rxbd_rdptr & reg->rx_wrap_mask;
- /* Write the TX ring write pointer in to reg->tx_wrptr */
- if (mwifiex_write_reg(adapter, reg->tx_wrptr,
- card->txbd_wrptr | rx_val)) {
- mwifiex_dbg(adapter, ERROR,
- "SEND DATA: failed to write reg->tx_wrptr\n");
- ret = -1;
- goto done_unmap;
- }
- if ((mwifiex_pcie_txbd_not_full(card)) &&
- tx_param->next_pkt_len) {
- /* have more packets and TxBD still can hold more */
- mwifiex_dbg(adapter, DATA,
- "SEND DATA: delay dnld-rdy interrupt.\n");
- adapter->data_sent = false;
- } else {
- /* Send the TX ready interrupt */
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_DNLD_RDY)) {
- mwifiex_dbg(adapter, ERROR,
- "SEND DATA: failed to assert dnld-rdy interrupt.\n");
- ret = -1;
- goto done_unmap;
- }
- }
- mwifiex_dbg(adapter, DATA,
- "info: SEND DATA: Updated <Rd: %#x, Wr:\t"
- "%#x> and sent packet to firmware successfully\n",
- card->txbd_rdptr, card->txbd_wrptr);
- } else {
- mwifiex_dbg(adapter, DATA,
- "info: TX Ring full, can't send packets to fw\n");
- adapter->data_sent = true;
- /* Send the TX ready interrupt */
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_DNLD_RDY))
- mwifiex_dbg(adapter, ERROR,
- "SEND DATA: failed to assert door-bell intr\n");
- return -EBUSY;
- }
- return -EINPROGRESS;
- done_unmap:
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- card->tx_buf_list[wrindx] = NULL;
- if (reg->pfu_enabled)
- memset(desc2, 0, sizeof(*desc2));
- else
- memset(desc, 0, sizeof(*desc));
- return ret;
- }
- /*
- * This function handles received buffer ring and
- * dispatches packets to upper
- */
- static int mwifiex_pcie_process_recv_data(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- u32 wrptr, rd_index, tx_val;
- dma_addr_t buf_pa;
- int ret = 0;
- struct sk_buff *skb_tmp = NULL;
- struct mwifiex_pcie_buf_desc *desc;
- struct mwifiex_pfu_buf_desc *desc2;
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- mwifiex_pm_wakeup_card(adapter);
- /* Read the RX ring Write pointer set by firmware */
- if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
- mwifiex_dbg(adapter, ERROR,
- "RECV DATA: failed to read reg->rx_wrptr\n");
- ret = -1;
- goto done;
- }
- card->rxbd_wrptr = wrptr;
- while (((wrptr & reg->rx_mask) !=
- (card->rxbd_rdptr & reg->rx_mask)) ||
- ((wrptr & reg->rx_rollover_ind) ==
- (card->rxbd_rdptr & reg->rx_rollover_ind))) {
- struct sk_buff *skb_data;
- u16 rx_len;
- __le16 pkt_len;
- rd_index = card->rxbd_rdptr & reg->rx_mask;
- skb_data = card->rx_buf_list[rd_index];
- /* If skb allocation was failed earlier for Rx packet,
- * rx_buf_list[rd_index] would have been left with a NULL.
- */
- if (!skb_data)
- return -ENOMEM;
- mwifiex_unmap_pci_memory(adapter, skb_data, PCI_DMA_FROMDEVICE);
- card->rx_buf_list[rd_index] = NULL;
- /* Get data length from interface header -
- * first 2 bytes for len, next 2 bytes is for type
- */
- pkt_len = *((__le16 *)skb_data->data);
- rx_len = le16_to_cpu(pkt_len);
- if (WARN_ON(rx_len <= INTF_HEADER_LEN ||
- rx_len > MWIFIEX_RX_DATA_BUF_SIZE)) {
- mwifiex_dbg(adapter, ERROR,
- "Invalid RX len %d, Rd=%#x, Wr=%#x\n",
- rx_len, card->rxbd_rdptr, wrptr);
- dev_kfree_skb_any(skb_data);
- } else {
- skb_put(skb_data, rx_len);
- mwifiex_dbg(adapter, DATA,
- "info: RECV DATA: Rd=%#x, Wr=%#x, Len=%d\n",
- card->rxbd_rdptr, wrptr, rx_len);
- skb_pull(skb_data, INTF_HEADER_LEN);
- if (adapter->rx_work_enabled) {
- skb_queue_tail(&adapter->rx_data_q, skb_data);
- adapter->data_received = true;
- atomic_inc(&adapter->rx_pending);
- } else {
- mwifiex_handle_rx_packet(adapter, skb_data);
- }
- }
- skb_tmp = mwifiex_alloc_dma_align_buf(MWIFIEX_RX_DATA_BUF_SIZE,
- GFP_KERNEL | GFP_DMA);
- if (!skb_tmp) {
- mwifiex_dbg(adapter, ERROR,
- "Unable to allocate skb.\n");
- return -ENOMEM;
- }
- if (mwifiex_map_pci_memory(adapter, skb_tmp,
- MWIFIEX_RX_DATA_BUF_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- buf_pa = MWIFIEX_SKB_DMA_ADDR(skb_tmp);
- mwifiex_dbg(adapter, INFO,
- "RECV DATA: Attach new sk_buff %p at rxbd_rdidx=%d\n",
- skb_tmp, rd_index);
- card->rx_buf_list[rd_index] = skb_tmp;
- if (reg->pfu_enabled) {
- desc2 = card->rxbd_ring[rd_index];
- desc2->paddr = buf_pa;
- desc2->len = skb_tmp->len;
- desc2->frag_len = skb_tmp->len;
- desc2->offset = 0;
- desc2->flags = reg->ring_flag_sop | reg->ring_flag_eop;
- } else {
- desc = card->rxbd_ring[rd_index];
- desc->paddr = buf_pa;
- desc->len = skb_tmp->len;
- desc->flags = 0;
- }
- if ((++card->rxbd_rdptr & reg->rx_mask) ==
- MWIFIEX_MAX_TXRX_BD) {
- card->rxbd_rdptr = ((card->rxbd_rdptr &
- reg->rx_rollover_ind) ^
- reg->rx_rollover_ind);
- }
- mwifiex_dbg(adapter, DATA,
- "info: RECV DATA: <Rd: %#x, Wr: %#x>\n",
- card->rxbd_rdptr, wrptr);
- tx_val = card->txbd_wrptr & reg->tx_wrap_mask;
- /* Write the RX ring read pointer in to reg->rx_rdptr */
- if (mwifiex_write_reg(adapter, reg->rx_rdptr,
- card->rxbd_rdptr | tx_val)) {
- mwifiex_dbg(adapter, DATA,
- "RECV DATA: failed to write reg->rx_rdptr\n");
- ret = -1;
- goto done;
- }
- /* Read the RX ring Write pointer set by firmware */
- if (mwifiex_read_reg(adapter, reg->rx_wrptr, &wrptr)) {
- mwifiex_dbg(adapter, ERROR,
- "RECV DATA: failed to read reg->rx_wrptr\n");
- ret = -1;
- goto done;
- }
- mwifiex_dbg(adapter, DATA,
- "info: RECV DATA: Rcvd packet from fw successfully\n");
- card->rxbd_wrptr = wrptr;
- }
- done:
- return ret;
- }
- /*
- * This function downloads the boot command to device
- */
- static int
- mwifiex_pcie_send_boot_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
- {
- dma_addr_t buf_pa;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- if (!(skb->data && skb->len)) {
- mwifiex_dbg(adapter, ERROR,
- "Invalid parameter in %s <%p. len %d>\n",
- __func__, skb->data, skb->len);
- return -1;
- }
- if (mwifiex_map_pci_memory(adapter, skb, skb->len , PCI_DMA_TODEVICE))
- return -1;
- buf_pa = MWIFIEX_SKB_DMA_ADDR(skb);
- /* Write the lower 32bits of the physical address to low command
- * address scratch register
- */
- if (mwifiex_write_reg(adapter, reg->cmd_addr_lo, (u32)buf_pa)) {
- mwifiex_dbg(adapter, ERROR,
- "%s: failed to write download command to boot code.\n",
- __func__);
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- return -1;
- }
- /* Write the upper 32bits of the physical address to high command
- * address scratch register
- */
- if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
- (u32)((u64)buf_pa >> 32))) {
- mwifiex_dbg(adapter, ERROR,
- "%s: failed to write download command to boot code.\n",
- __func__);
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- return -1;
- }
- /* Write the command length to cmd_size scratch register */
- if (mwifiex_write_reg(adapter, reg->cmd_size, skb->len)) {
- mwifiex_dbg(adapter, ERROR,
- "%s: failed to write command len to cmd_size scratch reg\n",
- __func__);
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- return -1;
- }
- /* Ring the door bell */
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_DOOR_BELL)) {
- mwifiex_dbg(adapter, ERROR,
- "%s: failed to assert door-bell intr\n", __func__);
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- return -1;
- }
- return 0;
- }
- /* This function init rx port in firmware which in turn enables to receive data
- * from device before transmitting any packet.
- */
- static int mwifiex_pcie_init_fw_port(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- int tx_wrap = card->txbd_wrptr & reg->tx_wrap_mask;
- /* Write the RX ring read pointer in to reg->rx_rdptr */
- if (mwifiex_write_reg(adapter, reg->rx_rdptr, card->rxbd_rdptr |
- tx_wrap)) {
- mwifiex_dbg(adapter, ERROR,
- "RECV DATA: failed to write reg->rx_rdptr\n");
- return -1;
- }
- return 0;
- }
- /* This function downloads commands to the device
- */
- static int
- mwifiex_pcie_send_cmd(struct mwifiex_adapter *adapter, struct sk_buff *skb)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- int ret = 0;
- dma_addr_t cmd_buf_pa, cmdrsp_buf_pa;
- u8 *payload = (u8 *)skb->data;
- if (!(skb->data && skb->len)) {
- mwifiex_dbg(adapter, ERROR,
- "Invalid parameter in %s <%p, %#x>\n",
- __func__, skb->data, skb->len);
- return -1;
- }
- /* Make sure a command response buffer is available */
- if (!card->cmdrsp_buf) {
- mwifiex_dbg(adapter, ERROR,
- "No response buffer available, send command failed\n");
- return -EBUSY;
- }
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- mwifiex_pm_wakeup_card(adapter);
- adapter->cmd_sent = true;
- *(__le16 *)&payload[0] = cpu_to_le16((u16)skb->len);
- *(__le16 *)&payload[2] = cpu_to_le16(MWIFIEX_TYPE_CMD);
- if (mwifiex_map_pci_memory(adapter, skb, skb->len, PCI_DMA_TODEVICE))
- return -1;
- card->cmd_buf = skb;
- /* To send a command, the driver will:
- 1. Write the 64bit physical address of the data buffer to
- cmd response address low + cmd response address high
- 2. Ring the door bell (i.e. set the door bell interrupt)
- In response to door bell interrupt, the firmware will perform
- the DMA of the command packet (first header to obtain the total
- length and then rest of the command).
- */
- if (card->cmdrsp_buf) {
- cmdrsp_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmdrsp_buf);
- /* Write the lower 32bits of the cmdrsp buffer physical
- address */
- if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo,
- (u32)cmdrsp_buf_pa)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write download cmd to boot code.\n");
- ret = -1;
- goto done;
- }
- /* Write the upper 32bits of the cmdrsp buffer physical
- address */
- if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi,
- (u32)((u64)cmdrsp_buf_pa >> 32))) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write download cmd to boot code.\n");
- ret = -1;
- goto done;
- }
- }
- cmd_buf_pa = MWIFIEX_SKB_DMA_ADDR(card->cmd_buf);
- /* Write the lower 32bits of the physical address to reg->cmd_addr_lo */
- if (mwifiex_write_reg(adapter, reg->cmd_addr_lo,
- (u32)cmd_buf_pa)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write download cmd to boot code.\n");
- ret = -1;
- goto done;
- }
- /* Write the upper 32bits of the physical address to reg->cmd_addr_hi */
- if (mwifiex_write_reg(adapter, reg->cmd_addr_hi,
- (u32)((u64)cmd_buf_pa >> 32))) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write download cmd to boot code.\n");
- ret = -1;
- goto done;
- }
- /* Write the command length to reg->cmd_size */
- if (mwifiex_write_reg(adapter, reg->cmd_size,
- card->cmd_buf->len)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write cmd len to reg->cmd_size\n");
- ret = -1;
- goto done;
- }
- /* Ring the door bell */
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_DOOR_BELL)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to assert door-bell intr\n");
- ret = -1;
- goto done;
- }
- done:
- if (ret)
- adapter->cmd_sent = false;
- return 0;
- }
- /*
- * This function handles command complete interrupt
- */
- static int mwifiex_pcie_process_cmd_complete(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- struct sk_buff *skb = card->cmdrsp_buf;
- int count = 0;
- u16 rx_len;
- __le16 pkt_len;
- mwifiex_dbg(adapter, CMD,
- "info: Rx CMD Response\n");
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_FROMDEVICE);
- /* Unmap the command as a response has been received. */
- if (card->cmd_buf) {
- mwifiex_unmap_pci_memory(adapter, card->cmd_buf,
- PCI_DMA_TODEVICE);
- card->cmd_buf = NULL;
- }
- pkt_len = *((__le16 *)skb->data);
- rx_len = le16_to_cpu(pkt_len);
- skb_trim(skb, rx_len);
- skb_pull(skb, INTF_HEADER_LEN);
- if (!adapter->curr_cmd) {
- if (adapter->ps_state == PS_STATE_SLEEP_CFM) {
- mwifiex_process_sleep_confirm_resp(adapter, skb->data,
- skb->len);
- mwifiex_pcie_enable_host_int(adapter);
- if (mwifiex_write_reg(adapter,
- PCIE_CPU_INT_EVENT,
- CPU_INTR_SLEEP_CFM_DONE)) {
- mwifiex_dbg(adapter, ERROR,
- "Write register failed\n");
- return -1;
- }
- mwifiex_delay_for_sleep_cookie(adapter,
- MWIFIEX_MAX_DELAY_COUNT);
- while (reg->sleep_cookie && (count++ < 10) &&
- mwifiex_pcie_ok_to_access_hw(adapter))
- usleep_range(50, 60);
- } else {
- mwifiex_dbg(adapter, ERROR,
- "There is no command but got cmdrsp\n");
- }
- memcpy(adapter->upld_buf, skb->data,
- min_t(u32, MWIFIEX_SIZE_OF_CMD_BUFFER, skb->len));
- skb_push(skb, INTF_HEADER_LEN);
- if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- } else if (mwifiex_pcie_ok_to_access_hw(adapter)) {
- adapter->curr_cmd->resp_skb = skb;
- adapter->cmd_resp_received = true;
- /* Take the pointer and set it to CMD node and will
- return in the response complete callback */
- card->cmdrsp_buf = NULL;
- /* Clear the cmd-rsp buffer address in scratch registers. This
- will prevent firmware from writing to the same response
- buffer again. */
- if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_lo, 0)) {
- mwifiex_dbg(adapter, ERROR,
- "cmd_done: failed to clear cmd_rsp_addr_lo\n");
- return -1;
- }
- /* Write the upper 32bits of the cmdrsp buffer physical
- address */
- if (mwifiex_write_reg(adapter, reg->cmdrsp_addr_hi, 0)) {
- mwifiex_dbg(adapter, ERROR,
- "cmd_done: failed to clear cmd_rsp_addr_hi\n");
- return -1;
- }
- }
- return 0;
- }
- /*
- * Command Response processing complete handler
- */
- static int mwifiex_pcie_cmdrsp_complete(struct mwifiex_adapter *adapter,
- struct sk_buff *skb)
- {
- struct pcie_service_card *card = adapter->card;
- if (skb) {
- card->cmdrsp_buf = skb;
- skb_push(card->cmdrsp_buf, INTF_HEADER_LEN);
- if (mwifiex_map_pci_memory(adapter, skb, MWIFIEX_UPLD_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- }
- return 0;
- }
- /*
- * This function handles firmware event ready interrupt
- */
- static int mwifiex_pcie_process_event_ready(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
- u32 wrptr, event;
- struct mwifiex_evt_buf_desc *desc;
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- mwifiex_pm_wakeup_card(adapter);
- if (adapter->event_received) {
- mwifiex_dbg(adapter, EVENT,
- "info: Event being processed,\t"
- "do not process this interrupt just yet\n");
- return 0;
- }
- if (rdptr >= MWIFIEX_MAX_EVT_BD) {
- mwifiex_dbg(adapter, ERROR,
- "info: Invalid read pointer...\n");
- return -1;
- }
- /* Read the event ring write pointer set by firmware */
- if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
- mwifiex_dbg(adapter, ERROR,
- "EventReady: failed to read reg->evt_wrptr\n");
- return -1;
- }
- mwifiex_dbg(adapter, EVENT,
- "info: EventReady: Initial <Rd: 0x%x, Wr: 0x%x>",
- card->evtbd_rdptr, wrptr);
- if (((wrptr & MWIFIEX_EVTBD_MASK) != (card->evtbd_rdptr
- & MWIFIEX_EVTBD_MASK)) ||
- ((wrptr & reg->evt_rollover_ind) ==
- (card->evtbd_rdptr & reg->evt_rollover_ind))) {
- struct sk_buff *skb_cmd;
- __le16 data_len = 0;
- u16 evt_len;
- mwifiex_dbg(adapter, INFO,
- "info: Read Index: %d\n", rdptr);
- skb_cmd = card->evt_buf_list[rdptr];
- mwifiex_unmap_pci_memory(adapter, skb_cmd, PCI_DMA_FROMDEVICE);
- /* Take the pointer and set it to event pointer in adapter
- and will return back after event handling callback */
- card->evt_buf_list[rdptr] = NULL;
- desc = card->evtbd_ring[rdptr];
- memset(desc, 0, sizeof(*desc));
- event = *(u32 *) &skb_cmd->data[INTF_HEADER_LEN];
- adapter->event_cause = event;
- /* The first 4bytes will be the event transfer header
- len is 2 bytes followed by type which is 2 bytes */
- memcpy(&data_len, skb_cmd->data, sizeof(__le16));
- evt_len = le16_to_cpu(data_len);
- skb_trim(skb_cmd, evt_len);
- skb_pull(skb_cmd, INTF_HEADER_LEN);
- mwifiex_dbg(adapter, EVENT,
- "info: Event length: %d\n", evt_len);
- if ((evt_len > 0) && (evt_len < MAX_EVENT_SIZE))
- memcpy(adapter->event_body, skb_cmd->data +
- MWIFIEX_EVENT_HEADER_LEN, evt_len -
- MWIFIEX_EVENT_HEADER_LEN);
- adapter->event_received = true;
- adapter->event_skb = skb_cmd;
- /* Do not update the event read pointer here, wait till the
- buffer is released. This is just to make things simpler,
- we need to find a better method of managing these buffers.
- */
- } else {
- if (mwifiex_write_reg(adapter, PCIE_CPU_INT_EVENT,
- CPU_INTR_EVENT_DONE)) {
- mwifiex_dbg(adapter, ERROR,
- "Write register failed\n");
- return -1;
- }
- }
- return 0;
- }
- /*
- * Event processing complete handler
- */
- static int mwifiex_pcie_event_complete(struct mwifiex_adapter *adapter,
- struct sk_buff *skb)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- int ret = 0;
- u32 rdptr = card->evtbd_rdptr & MWIFIEX_EVTBD_MASK;
- u32 wrptr;
- struct mwifiex_evt_buf_desc *desc;
- if (!skb)
- return 0;
- if (rdptr >= MWIFIEX_MAX_EVT_BD) {
- mwifiex_dbg(adapter, ERROR,
- "event_complete: Invalid rdptr 0x%x\n",
- rdptr);
- return -EINVAL;
- }
- /* Read the event ring write pointer set by firmware */
- if (mwifiex_read_reg(adapter, reg->evt_wrptr, &wrptr)) {
- mwifiex_dbg(adapter, ERROR,
- "event_complete: failed to read reg->evt_wrptr\n");
- return -1;
- }
- if (!card->evt_buf_list[rdptr]) {
- skb_push(skb, INTF_HEADER_LEN);
- if (mwifiex_map_pci_memory(adapter, skb,
- MAX_EVENT_SIZE,
- PCI_DMA_FROMDEVICE))
- return -1;
- card->evt_buf_list[rdptr] = skb;
- desc = card->evtbd_ring[rdptr];
- desc->paddr = MWIFIEX_SKB_DMA_ADDR(skb);
- desc->len = (u16)skb->len;
- desc->flags = 0;
- skb = NULL;
- } else {
- mwifiex_dbg(adapter, ERROR,
- "info: ERROR: buf still valid at index %d, <%p, %p>\n",
- rdptr, card->evt_buf_list[rdptr], skb);
- }
- if ((++card->evtbd_rdptr & MWIFIEX_EVTBD_MASK) == MWIFIEX_MAX_EVT_BD) {
- card->evtbd_rdptr = ((card->evtbd_rdptr &
- reg->evt_rollover_ind) ^
- reg->evt_rollover_ind);
- }
- mwifiex_dbg(adapter, EVENT,
- "info: Updated <Rd: 0x%x, Wr: 0x%x>",
- card->evtbd_rdptr, wrptr);
- /* Write the event ring read pointer in to reg->evt_rdptr */
- if (mwifiex_write_reg(adapter, reg->evt_rdptr,
- card->evtbd_rdptr)) {
- mwifiex_dbg(adapter, ERROR,
- "event_complete: failed to read reg->evt_rdptr\n");
- return -1;
- }
- mwifiex_dbg(adapter, EVENT,
- "info: Check Events Again\n");
- ret = mwifiex_pcie_process_event_ready(adapter);
- return ret;
- }
- /*
- * This function downloads the firmware to the card.
- *
- * Firmware is downloaded to the card in blocks. Every block download
- * is tested for CRC errors, and retried a number of times before
- * returning failure.
- */
- static int mwifiex_prog_fw_w_helper(struct mwifiex_adapter *adapter,
- struct mwifiex_fw_image *fw)
- {
- int ret;
- u8 *firmware = fw->fw_buf;
- u32 firmware_len = fw->fw_len;
- u32 offset = 0;
- struct sk_buff *skb;
- u32 txlen, tx_blocks = 0, tries, len;
- u32 block_retry_cnt = 0;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- if (!firmware || !firmware_len) {
- mwifiex_dbg(adapter, ERROR,
- "No firmware image found! Terminating download\n");
- return -1;
- }
- mwifiex_dbg(adapter, INFO,
- "info: Downloading FW image (%d bytes)\n",
- firmware_len);
- if (mwifiex_pcie_disable_host_int(adapter)) {
- mwifiex_dbg(adapter, ERROR,
- "%s: Disabling interrupts failed.\n", __func__);
- return -1;
- }
- skb = dev_alloc_skb(MWIFIEX_UPLD_SIZE);
- if (!skb) {
- ret = -ENOMEM;
- goto done;
- }
- /* Perform firmware data transfer */
- do {
- u32 ireg_intr = 0;
- /* More data? */
- if (offset >= firmware_len)
- break;
- for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
- ret = mwifiex_read_reg(adapter, reg->cmd_size,
- &len);
- if (ret) {
- mwifiex_dbg(adapter, FATAL,
- "Failed reading len from boot code\n");
- goto done;
- }
- if (len)
- break;
- usleep_range(10, 20);
- }
- if (!len) {
- break;
- } else if (len > MWIFIEX_UPLD_SIZE) {
- mwifiex_dbg(adapter, ERROR,
- "FW download failure @ %d, invalid length %d\n",
- offset, len);
- ret = -1;
- goto done;
- }
- txlen = len;
- if (len & BIT(0)) {
- block_retry_cnt++;
- if (block_retry_cnt > MAX_WRITE_IOMEM_RETRY) {
- mwifiex_dbg(adapter, ERROR,
- "FW download failure @ %d, over max\t"
- "retry count\n", offset);
- ret = -1;
- goto done;
- }
- mwifiex_dbg(adapter, ERROR,
- "FW CRC error indicated by the\t"
- "helper: len = 0x%04X, txlen = %d\n",
- len, txlen);
- len &= ~BIT(0);
- /* Setting this to 0 to resend from same offset */
- txlen = 0;
- } else {
- block_retry_cnt = 0;
- /* Set blocksize to transfer - checking for
- last block */
- if (firmware_len - offset < txlen)
- txlen = firmware_len - offset;
- mwifiex_dbg(adapter, INFO, ".");
- tx_blocks = (txlen + card->pcie.blksz_fw_dl - 1) /
- card->pcie.blksz_fw_dl;
- /* Copy payload to buffer */
- memmove(skb->data, &firmware[offset], txlen);
- }
- skb_put(skb, MWIFIEX_UPLD_SIZE - skb->len);
- skb_trim(skb, tx_blocks * card->pcie.blksz_fw_dl);
- /* Send the boot command to device */
- if (mwifiex_pcie_send_boot_cmd(adapter, skb)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to send firmware download command\n");
- ret = -1;
- goto done;
- }
- /* Wait for the command done interrupt */
- do {
- if (mwifiex_read_reg(adapter, PCIE_CPU_INT_STATUS,
- &ireg_intr)) {
- mwifiex_dbg(adapter, ERROR,
- "%s: Failed to read\t"
- "interrupt status during fw dnld.\n",
- __func__);
- mwifiex_unmap_pci_memory(adapter, skb,
- PCI_DMA_TODEVICE);
- ret = -1;
- goto done;
- }
- } while ((ireg_intr & CPU_INTR_DOOR_BELL) ==
- CPU_INTR_DOOR_BELL);
- mwifiex_unmap_pci_memory(adapter, skb, PCI_DMA_TODEVICE);
- offset += txlen;
- } while (true);
- mwifiex_dbg(adapter, MSG,
- "info: FW download over, size %d bytes\n", offset);
- ret = 0;
- done:
- dev_kfree_skb_any(skb);
- return ret;
- }
- /*
- * This function checks the firmware status in card.
- *
- * The winner interface is also determined by this function.
- */
- static int
- mwifiex_check_fw_status(struct mwifiex_adapter *adapter, u32 poll_num)
- {
- int ret = 0;
- u32 firmware_stat, winner_status;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- u32 tries;
- /* Mask spurios interrupts */
- if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS_MASK,
- HOST_INTR_MASK)) {
- mwifiex_dbg(adapter, ERROR,
- "Write register failed\n");
- return -1;
- }
- mwifiex_dbg(adapter, INFO,
- "Setting driver ready signature\n");
- if (mwifiex_write_reg(adapter, reg->drv_rdy,
- FIRMWARE_READY_PCIE)) {
- mwifiex_dbg(adapter, ERROR,
- "Failed to write driver ready signature\n");
- return -1;
- }
- /* Wait for firmware initialization event */
- for (tries = 0; tries < poll_num; tries++) {
- if (mwifiex_read_reg(adapter, reg->fw_status,
- &firmware_stat))
- ret = -1;
- else
- ret = 0;
- if (ret)
- continue;
- if (firmware_stat == FIRMWARE_READY_PCIE) {
- ret = 0;
- break;
- } else {
- msleep(100);
- ret = -1;
- }
- }
- if (ret) {
- if (mwifiex_read_reg(adapter, reg->fw_status,
- &winner_status))
- ret = -1;
- else if (!winner_status) {
- mwifiex_dbg(adapter, INFO,
- "PCI-E is the winner\n");
- adapter->winner = 1;
- } else {
- mwifiex_dbg(adapter, ERROR,
- "PCI-E is not the winner <%#x,%d>, exit dnld\n",
- ret, adapter->winner);
- }
- }
- return ret;
- }
- /*
- * This function reads the interrupt status from card.
- */
- static void mwifiex_interrupt_status(struct mwifiex_adapter *adapter)
- {
- u32 pcie_ireg;
- unsigned long flags;
- if (!mwifiex_pcie_ok_to_access_hw(adapter))
- return;
- if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS, &pcie_ireg)) {
- mwifiex_dbg(adapter, ERROR, "Read register failed\n");
- return;
- }
- if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
- mwifiex_pcie_disable_host_int(adapter);
- /* Clear the pending interrupts */
- if (mwifiex_write_reg(adapter, PCIE_HOST_INT_STATUS,
- ~pcie_ireg)) {
- mwifiex_dbg(adapter, ERROR,
- "Write register failed\n");
- return;
- }
- spin_lock_irqsave(&adapter->int_lock, flags);
- adapter->int_status |= pcie_ireg;
- spin_unlock_irqrestore(&adapter->int_lock, flags);
- if (!adapter->pps_uapsd_mode &&
- adapter->ps_state == PS_STATE_SLEEP &&
- mwifiex_pcie_ok_to_access_hw(adapter)) {
- /* Potentially for PCIe we could get other
- * interrupts like shared. Don't change power
- * state until cookie is set */
- adapter->ps_state = PS_STATE_AWAKE;
- adapter->pm_wakeup_fw_try = false;
- del_timer(&adapter->wakeup_timer);
- }
- }
- }
- /*
- * Interrupt handler for PCIe root port
- *
- * This function reads the interrupt status from firmware and assigns
- * the main process in workqueue which will handle the interrupt.
- */
- static irqreturn_t mwifiex_pcie_interrupt(int irq, void *context)
- {
- struct pci_dev *pdev = (struct pci_dev *)context;
- struct pcie_service_card *card;
- struct mwifiex_adapter *adapter;
- if (!pdev) {
- pr_debug("info: %s: pdev is NULL\n", (u8 *)pdev);
- goto exit;
- }
- card = pci_get_drvdata(pdev);
- if (!card || !card->adapter) {
- pr_debug("info: %s: card=%p adapter=%p\n", __func__, card,
- card ? card->adapter : NULL);
- goto exit;
- }
- adapter = card->adapter;
- if (adapter->surprise_removed)
- goto exit;
- mwifiex_interrupt_status(adapter);
- mwifiex_queue_main_work(adapter);
- exit:
- return IRQ_HANDLED;
- }
- /*
- * This function checks the current interrupt status.
- *
- * The following interrupts are checked and handled by this function -
- * - Data sent
- * - Command sent
- * - Command received
- * - Packets received
- * - Events received
- *
- * In case of Rx packets received, the packets are uploaded from card to
- * host and processed accordingly.
- */
- static int mwifiex_process_int_status(struct mwifiex_adapter *adapter)
- {
- int ret;
- u32 pcie_ireg;
- unsigned long flags;
- spin_lock_irqsave(&adapter->int_lock, flags);
- /* Clear out unused interrupts */
- pcie_ireg = adapter->int_status;
- adapter->int_status = 0;
- spin_unlock_irqrestore(&adapter->int_lock, flags);
- while (pcie_ireg & HOST_INTR_MASK) {
- if (pcie_ireg & HOST_INTR_DNLD_DONE) {
- pcie_ireg &= ~HOST_INTR_DNLD_DONE;
- mwifiex_dbg(adapter, INTR,
- "info: TX DNLD Done\n");
- ret = mwifiex_pcie_send_data_complete(adapter);
- if (ret)
- return ret;
- }
- if (pcie_ireg & HOST_INTR_UPLD_RDY) {
- pcie_ireg &= ~HOST_INTR_UPLD_RDY;
- mwifiex_dbg(adapter, INTR,
- "info: Rx DATA\n");
- ret = mwifiex_pcie_process_recv_data(adapter);
- if (ret)
- return ret;
- }
- if (pcie_ireg & HOST_INTR_EVENT_RDY) {
- pcie_ireg &= ~HOST_INTR_EVENT_RDY;
- mwifiex_dbg(adapter, INTR,
- "info: Rx EVENT\n");
- ret = mwifiex_pcie_process_event_ready(adapter);
- if (ret)
- return ret;
- }
- if (pcie_ireg & HOST_INTR_CMD_DONE) {
- pcie_ireg &= ~HOST_INTR_CMD_DONE;
- if (adapter->cmd_sent) {
- mwifiex_dbg(adapter, INTR,
- "info: CMD sent Interrupt\n");
- adapter->cmd_sent = false;
- }
- /* Handle command response */
- ret = mwifiex_pcie_process_cmd_complete(adapter);
- if (ret)
- return ret;
- }
- if (mwifiex_pcie_ok_to_access_hw(adapter)) {
- if (mwifiex_read_reg(adapter, PCIE_HOST_INT_STATUS,
- &pcie_ireg)) {
- mwifiex_dbg(adapter, ERROR,
- "Read register failed\n");
- return -1;
- }
- if ((pcie_ireg != 0xFFFFFFFF) && (pcie_ireg)) {
- if (mwifiex_write_reg(adapter,
- PCIE_HOST_INT_STATUS,
- ~pcie_ireg)) {
- mwifiex_dbg(adapter, ERROR,
- "Write register failed\n");
- return -1;
- }
- }
- }
- }
- mwifiex_dbg(adapter, INTR,
- "info: cmd_sent=%d data_sent=%d\n",
- adapter->cmd_sent, adapter->data_sent);
- if (adapter->ps_state != PS_STATE_SLEEP)
- mwifiex_pcie_enable_host_int(adapter);
- return 0;
- }
- /*
- * This function downloads data from driver to card.
- *
- * Both commands and data packets are transferred to the card by this
- * function.
- *
- * This function adds the PCIE specific header to the front of the buffer
- * before transferring. The header contains the length of the packet and
- * the type. The firmware handles the packets based upon this set type.
- */
- static int mwifiex_pcie_host_to_card(struct mwifiex_adapter *adapter, u8 type,
- struct sk_buff *skb,
- struct mwifiex_tx_param *tx_param)
- {
- if (!skb) {
- mwifiex_dbg(adapter, ERROR,
- "Passed NULL skb to %s\n", __func__);
- return -1;
- }
- if (type == MWIFIEX_TYPE_DATA)
- return mwifiex_pcie_send_data(adapter, skb, tx_param);
- else if (type == MWIFIEX_TYPE_CMD)
- return mwifiex_pcie_send_cmd(adapter, skb);
- return 0;
- }
- /* This function read/write firmware */
- static enum rdwr_status
- mwifiex_pcie_rdwr_firmware(struct mwifiex_adapter *adapter, u8 doneflag)
- {
- int ret, tries;
- u8 ctrl_data;
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- ret = mwifiex_write_reg(adapter, reg->fw_dump_ctrl, FW_DUMP_HOST_READY);
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "PCIE write err\n");
- return RDWR_STATUS_FAILURE;
- }
- for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
- mwifiex_read_reg_byte(adapter, reg->fw_dump_ctrl, &ctrl_data);
- if (ctrl_data == FW_DUMP_DONE)
- return RDWR_STATUS_SUCCESS;
- if (doneflag && ctrl_data == doneflag)
- return RDWR_STATUS_DONE;
- if (ctrl_data != FW_DUMP_HOST_READY) {
- mwifiex_dbg(adapter, WARN,
- "The ctrl reg was changed, re-try again!\n");
- ret = mwifiex_write_reg(adapter, reg->fw_dump_ctrl,
- FW_DUMP_HOST_READY);
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "PCIE write err\n");
- return RDWR_STATUS_FAILURE;
- }
- }
- usleep_range(100, 200);
- }
- mwifiex_dbg(adapter, ERROR, "Fail to pull ctrl_data\n");
- return RDWR_STATUS_FAILURE;
- }
- /* This function dump firmware memory to file */
- static void mwifiex_pcie_fw_dump(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *creg = card->pcie.reg;
- unsigned int reg, reg_start, reg_end;
- u8 *dbg_ptr, *end_ptr, dump_num, idx, i, read_reg, doneflag = 0;
- enum rdwr_status stat;
- u32 memory_size;
- int ret;
- if (!card->pcie.can_dump_fw)
- return;
- for (idx = 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) {
- struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
- if (entry->mem_ptr) {
- vfree(entry->mem_ptr);
- entry->mem_ptr = NULL;
- }
- entry->mem_size = 0;
- }
- mwifiex_dbg(adapter, DUMP, "== mwifiex firmware dump start ==\n");
- /* Read the number of the memories which will dump */
- stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
- if (stat == RDWR_STATUS_FAILURE)
- return;
- reg = creg->fw_dump_start;
- mwifiex_read_reg_byte(adapter, reg, &dump_num);
- /* Read the length of every memory which will dump */
- for (idx = 0; idx < dump_num; idx++) {
- struct memory_type_mapping *entry = &mem_type_mapping_tbl[idx];
- stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
- if (stat == RDWR_STATUS_FAILURE)
- return;
- memory_size = 0;
- reg = creg->fw_dump_start;
- for (i = 0; i < 4; i++) {
- mwifiex_read_reg_byte(adapter, reg, &read_reg);
- memory_size |= (read_reg << (i * 8));
- reg++;
- }
- if (memory_size == 0) {
- mwifiex_dbg(adapter, MSG, "Firmware dump Finished!\n");
- ret = mwifiex_write_reg(adapter, creg->fw_dump_ctrl,
- FW_DUMP_READ_DONE);
- if (ret) {
- mwifiex_dbg(adapter, ERROR, "PCIE write err\n");
- return;
- }
- break;
- }
- mwifiex_dbg(adapter, DUMP,
- "%s_SIZE=0x%x\n", entry->mem_name, memory_size);
- entry->mem_ptr = vmalloc(memory_size + 1);
- entry->mem_size = memory_size;
- if (!entry->mem_ptr) {
- mwifiex_dbg(adapter, ERROR,
- "Vmalloc %s failed\n", entry->mem_name);
- return;
- }
- dbg_ptr = entry->mem_ptr;
- end_ptr = dbg_ptr + memory_size;
- doneflag = entry->done_flag;
- mwifiex_dbg(adapter, DUMP, "Start %s output, please wait...\n",
- entry->mem_name);
- do {
- stat = mwifiex_pcie_rdwr_firmware(adapter, doneflag);
- if (RDWR_STATUS_FAILURE == stat)
- return;
- reg_start = creg->fw_dump_start;
- reg_end = creg->fw_dump_end;
- for (reg = reg_start; reg <= reg_end; reg++) {
- mwifiex_read_reg_byte(adapter, reg, dbg_ptr);
- if (dbg_ptr < end_ptr) {
- dbg_ptr++;
- } else {
- mwifiex_dbg(adapter, ERROR,
- "Allocated buf not enough\n");
- return;
- }
- }
- if (stat != RDWR_STATUS_DONE)
- continue;
- mwifiex_dbg(adapter, DUMP,
- "%s done: size=0x%tx\n",
- entry->mem_name, dbg_ptr - entry->mem_ptr);
- break;
- } while (true);
- }
- mwifiex_dbg(adapter, DUMP, "== mwifiex firmware dump end ==\n");
- }
- static void mwifiex_pcie_device_dump_work(struct mwifiex_adapter *adapter)
- {
- mwifiex_drv_info_dump(adapter);
- mwifiex_pcie_fw_dump(adapter);
- mwifiex_upload_device_dump(adapter);
- }
- static unsigned long iface_work_flags;
- static struct mwifiex_adapter *save_adapter;
- static void mwifiex_pcie_work(struct work_struct *work)
- {
- if (test_and_clear_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP,
- &iface_work_flags))
- mwifiex_pcie_device_dump_work(save_adapter);
- }
- static DECLARE_WORK(pcie_work, mwifiex_pcie_work);
- /* This function dumps FW information */
- static void mwifiex_pcie_device_dump(struct mwifiex_adapter *adapter)
- {
- save_adapter = adapter;
- if (test_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags))
- return;
- set_bit(MWIFIEX_IFACE_WORK_DEVICE_DUMP, &iface_work_flags);
- schedule_work(&pcie_work);
- }
- /*
- * This function initializes the PCI-E host memory space, WCB rings, etc.
- *
- * The following initializations steps are followed -
- * - Allocate TXBD ring buffers
- * - Allocate RXBD ring buffers
- * - Allocate event BD ring buffers
- * - Allocate command response ring buffer
- * - Allocate sleep cookie buffer
- */
- static int mwifiex_pcie_init(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- int ret;
- struct pci_dev *pdev = card->dev;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- pci_set_drvdata(pdev, card);
- ret = pci_enable_device(pdev);
- if (ret)
- goto err_enable_dev;
- pci_set_master(pdev);
- mwifiex_dbg(adapter, INFO,
- "try set_consistent_dma_mask(32)\n");
- ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "set_dma_mask(32) failed\n");
- goto err_set_dma_mask;
- }
- ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "set_consistent_dma_mask(64) failed\n");
- goto err_set_dma_mask;
- }
- ret = pci_request_region(pdev, 0, DRV_NAME);
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "req_reg(0) error\n");
- goto err_req_region0;
- }
- card->pci_mmap = pci_iomap(pdev, 0, 0);
- if (!card->pci_mmap) {
- mwifiex_dbg(adapter, ERROR, "iomap(0) error\n");
- ret = -EIO;
- goto err_iomap0;
- }
- ret = pci_request_region(pdev, 2, DRV_NAME);
- if (ret) {
- mwifiex_dbg(adapter, ERROR, "req_reg(2) error\n");
- goto err_req_region2;
- }
- card->pci_mmap1 = pci_iomap(pdev, 2, 0);
- if (!card->pci_mmap1) {
- mwifiex_dbg(adapter, ERROR,
- "iomap(2) error\n");
- ret = -EIO;
- goto err_iomap2;
- }
- mwifiex_dbg(adapter, INFO,
- "PCI memory map Virt0: %p PCI memory map Virt2: %p\n",
- card->pci_mmap, card->pci_mmap1);
- card->cmdrsp_buf = NULL;
- ret = mwifiex_pcie_create_txbd_ring(adapter);
- if (ret)
- goto err_cre_txbd;
- ret = mwifiex_pcie_create_rxbd_ring(adapter);
- if (ret)
- goto err_cre_rxbd;
- ret = mwifiex_pcie_create_evtbd_ring(adapter);
- if (ret)
- goto err_cre_evtbd;
- ret = mwifiex_pcie_alloc_cmdrsp_buf(adapter);
- if (ret)
- goto err_alloc_cmdbuf;
- if (reg->sleep_cookie) {
- ret = mwifiex_pcie_alloc_sleep_cookie_buf(adapter);
- if (ret)
- goto err_alloc_cookie;
- } else {
- card->sleep_cookie_vbase = NULL;
- }
- return ret;
- err_alloc_cookie:
- mwifiex_pcie_delete_cmdrsp_buf(adapter);
- err_alloc_cmdbuf:
- mwifiex_pcie_delete_evtbd_ring(adapter);
- err_cre_evtbd:
- mwifiex_pcie_delete_rxbd_ring(adapter);
- err_cre_rxbd:
- mwifiex_pcie_delete_txbd_ring(adapter);
- err_cre_txbd:
- pci_iounmap(pdev, card->pci_mmap1);
- err_iomap2:
- pci_release_region(pdev, 2);
- err_req_region2:
- pci_iounmap(pdev, card->pci_mmap);
- err_iomap0:
- pci_release_region(pdev, 0);
- err_req_region0:
- err_set_dma_mask:
- pci_disable_device(pdev);
- err_enable_dev:
- pci_set_drvdata(pdev, NULL);
- return ret;
- }
- /*
- * This function cleans up the allocated card buffers.
- *
- * The following are freed by this function -
- * - TXBD ring buffers
- * - RXBD ring buffers
- * - Event BD ring buffers
- * - Command response ring buffer
- * - Sleep cookie buffer
- */
- static void mwifiex_pcie_cleanup(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- struct pci_dev *pdev = card->dev;
- const struct mwifiex_pcie_card_reg *reg = card->pcie.reg;
- if (user_rmmod) {
- mwifiex_dbg(adapter, INFO,
- "Clearing driver ready signature\n");
- if (mwifiex_write_reg(adapter, reg->drv_rdy, 0x00000000))
- mwifiex_dbg(adapter, ERROR,
- "Failed to write driver not-ready signature\n");
- }
- if (pdev) {
- pci_iounmap(pdev, card->pci_mmap);
- pci_iounmap(pdev, card->pci_mmap1);
- pci_disable_device(pdev);
- pci_release_region(pdev, 2);
- pci_release_region(pdev, 0);
- pci_set_drvdata(pdev, NULL);
- }
- kfree(card);
- }
- /*
- * This function registers the PCIE device.
- *
- * PCIE IRQ is claimed, block size is set and driver data is initialized.
- */
- static int mwifiex_register_dev(struct mwifiex_adapter *adapter)
- {
- int ret;
- struct pcie_service_card *card = adapter->card;
- struct pci_dev *pdev = card->dev;
- /* save adapter pointer in card */
- card->adapter = adapter;
- ret = request_irq(pdev->irq, mwifiex_pcie_interrupt, IRQF_SHARED,
- "MRVL_PCIE", pdev);
- if (ret) {
- mwifiex_dbg(adapter, ERROR,
- "request_irq failed: ret=%d\n", ret);
- adapter->card = NULL;
- return -1;
- }
- adapter->dev = &pdev->dev;
- adapter->tx_buf_size = card->pcie.tx_buf_size;
- adapter->mem_type_mapping_tbl = mem_type_mapping_tbl;
- adapter->num_mem_types = ARRAY_SIZE(mem_type_mapping_tbl);
- strcpy(adapter->fw_name, card->pcie.firmware);
- adapter->ext_scan = card->pcie.can_ext_scan;
- return 0;
- }
- /*
- * This function unregisters the PCIE device.
- *
- * The PCIE IRQ is released, the function is disabled and driver
- * data is set to null.
- */
- static void mwifiex_unregister_dev(struct mwifiex_adapter *adapter)
- {
- struct pcie_service_card *card = adapter->card;
- const struct mwifiex_pcie_card_reg *reg;
- if (card) {
- mwifiex_dbg(adapter, INFO,
- "%s(): calling free_irq()\n", __func__);
- free_irq(card->dev->irq, card->dev);
- reg = card->pcie.reg;
- if (reg->sleep_cookie)
- mwifiex_pcie_delete_sleep_cookie_buf(adapter);
- mwifiex_pcie_delete_cmdrsp_buf(adapter);
- mwifiex_pcie_delete_evtbd_ring(adapter);
- mwifiex_pcie_delete_rxbd_ring(adapter);
- mwifiex_pcie_delete_txbd_ring(adapter);
- card->cmdrsp_buf = NULL;
- }
- }
- static struct mwifiex_if_ops pcie_ops = {
- .init_if = mwifiex_pcie_init,
- .cleanup_if = mwifiex_pcie_cleanup,
- .check_fw_status = mwifiex_check_fw_status,
- .prog_fw = mwifiex_prog_fw_w_helper,
- .register_dev = mwifiex_register_dev,
- .unregister_dev = mwifiex_unregister_dev,
- .enable_int = mwifiex_pcie_enable_host_int,
- .process_int_status = mwifiex_process_int_status,
- .host_to_card = mwifiex_pcie_host_to_card,
- .wakeup = mwifiex_pm_wakeup_card,
- .wakeup_complete = mwifiex_pm_wakeup_card_complete,
- /* PCIE specific */
- .cmdrsp_complete = mwifiex_pcie_cmdrsp_complete,
- .event_complete = mwifiex_pcie_event_complete,
- .update_mp_end_port = NULL,
- .cleanup_mpa_buf = NULL,
- .init_fw_port = mwifiex_pcie_init_fw_port,
- .clean_pcie_ring = mwifiex_clean_pcie_ring_buf,
- .device_dump = mwifiex_pcie_device_dump,
- };
- /*
- * This function initializes the PCIE driver module.
- *
- * This initiates the semaphore and registers the device with
- * PCIE bus.
- */
- static int mwifiex_pcie_init_module(void)
- {
- int ret;
- pr_debug("Marvell PCIe Driver\n");
- sema_init(&add_remove_card_sem, 1);
- /* Clear the flag in case user removes the card. */
- user_rmmod = 0;
- ret = pci_register_driver(&mwifiex_pcie);
- if (ret)
- pr_err("Driver register failed!\n");
- else
- pr_debug("info: Driver registered successfully!\n");
- return ret;
- }
- /*
- * This function cleans up the PCIE driver.
- *
- * The following major steps are followed for cleanup -
- * - Resume the device if its suspended
- * - Disconnect the device if connected
- * - Shutdown the firmware
- * - Unregister the device from PCIE bus.
- */
- static void mwifiex_pcie_cleanup_module(void)
- {
- if (!down_interruptible(&add_remove_card_sem))
- up(&add_remove_card_sem);
- /* Set the flag as user is removing this module. */
- user_rmmod = 1;
- cancel_work_sync(&pcie_work);
- pci_unregister_driver(&mwifiex_pcie);
- }
- module_init(mwifiex_pcie_init_module);
- module_exit(mwifiex_pcie_cleanup_module);
- MODULE_AUTHOR("Marvell International Ltd.");
- MODULE_DESCRIPTION("Marvell WiFi-Ex PCI-Express Driver version " PCIE_VERSION);
- MODULE_VERSION(PCIE_VERSION);
- MODULE_LICENSE("GPL v2");
- /*(DEBLOBBED)*/
|