pci.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408
  1. /*
  2. * Copyright (c) 2005-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/pci.h>
  18. #include <linux/module.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/bitops.h>
  22. #include "core.h"
  23. #include "debug.h"
  24. #include "targaddrs.h"
  25. #include "bmi.h"
  26. #include "hif.h"
  27. #include "htc.h"
  28. #include "ce.h"
  29. #include "pci.h"
  30. enum ath10k_pci_reset_mode {
  31. ATH10K_PCI_RESET_AUTO = 0,
  32. ATH10K_PCI_RESET_WARM_ONLY = 1,
  33. };
  34. static unsigned int ath10k_pci_irq_mode = ATH10K_PCI_IRQ_AUTO;
  35. static unsigned int ath10k_pci_reset_mode = ATH10K_PCI_RESET_AUTO;
  36. module_param_named(irq_mode, ath10k_pci_irq_mode, uint, 0644);
  37. MODULE_PARM_DESC(irq_mode, "0: auto, 1: legacy, 2: msi (default: 0)");
  38. module_param_named(reset_mode, ath10k_pci_reset_mode, uint, 0644);
  39. MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)");
  40. /* how long wait to wait for target to initialise, in ms */
  41. #define ATH10K_PCI_TARGET_WAIT 3000
  42. #define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3
  43. static const struct pci_device_id ath10k_pci_id_table[] = {
  44. { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
  45. { PCI_VDEVICE(ATHEROS, QCA6164_2_1_DEVICE_ID) }, /* PCI-E QCA6164 V2.1 */
  46. { PCI_VDEVICE(ATHEROS, QCA6174_2_1_DEVICE_ID) }, /* PCI-E QCA6174 V2.1 */
  47. { PCI_VDEVICE(ATHEROS, QCA99X0_2_0_DEVICE_ID) }, /* PCI-E QCA99X0 V2 */
  48. { PCI_VDEVICE(ATHEROS, QCA9888_2_0_DEVICE_ID) }, /* PCI-E QCA9888 V2 */
  49. { PCI_VDEVICE(ATHEROS, QCA9984_1_0_DEVICE_ID) }, /* PCI-E QCA9984 V1 */
  50. { PCI_VDEVICE(ATHEROS, QCA9377_1_0_DEVICE_ID) }, /* PCI-E QCA9377 V1 */
  51. { PCI_VDEVICE(ATHEROS, QCA9887_1_0_DEVICE_ID) }, /* PCI-E QCA9887 */
  52. {0}
  53. };
  54. static const struct ath10k_pci_supp_chip ath10k_pci_supp_chips[] = {
  55. /* QCA988X pre 2.0 chips are not supported because they need some nasty
  56. * hacks. ath10k doesn't have them and these devices crash horribly
  57. * because of that.
  58. */
  59. { QCA988X_2_0_DEVICE_ID, QCA988X_HW_2_0_CHIP_ID_REV },
  60. { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
  61. { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
  62. { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
  63. { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
  64. { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
  65. { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
  66. { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
  67. { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
  68. { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
  69. { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
  70. { QCA99X0_2_0_DEVICE_ID, QCA99X0_HW_2_0_CHIP_ID_REV },
  71. { QCA9984_1_0_DEVICE_ID, QCA9984_HW_1_0_CHIP_ID_REV },
  72. { QCA9888_2_0_DEVICE_ID, QCA9888_HW_2_0_CHIP_ID_REV },
  73. { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_0_CHIP_ID_REV },
  74. { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_1_CHIP_ID_REV },
  75. { QCA9887_1_0_DEVICE_ID, QCA9887_HW_1_0_CHIP_ID_REV },
  76. };
  77. static void ath10k_pci_buffer_cleanup(struct ath10k *ar);
  78. static int ath10k_pci_cold_reset(struct ath10k *ar);
  79. static int ath10k_pci_safe_chip_reset(struct ath10k *ar);
  80. static int ath10k_pci_init_irq(struct ath10k *ar);
  81. static int ath10k_pci_deinit_irq(struct ath10k *ar);
  82. static int ath10k_pci_request_irq(struct ath10k *ar);
  83. static void ath10k_pci_free_irq(struct ath10k *ar);
  84. static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
  85. struct ath10k_ce_pipe *rx_pipe,
  86. struct bmi_xfer *xfer);
  87. static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar);
  88. static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
  89. static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  90. static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
  91. static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
  92. static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  93. static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
  94. static struct ce_attr host_ce_config_wlan[] = {
  95. /* CE0: host->target HTC control and raw streams */
  96. {
  97. .flags = CE_ATTR_FLAGS,
  98. .src_nentries = 16,
  99. .src_sz_max = 256,
  100. .dest_nentries = 0,
  101. .send_cb = ath10k_pci_htc_tx_cb,
  102. },
  103. /* CE1: target->host HTT + HTC control */
  104. {
  105. .flags = CE_ATTR_FLAGS,
  106. .src_nentries = 0,
  107. .src_sz_max = 2048,
  108. .dest_nentries = 512,
  109. .recv_cb = ath10k_pci_htt_htc_rx_cb,
  110. },
  111. /* CE2: target->host WMI */
  112. {
  113. .flags = CE_ATTR_FLAGS,
  114. .src_nentries = 0,
  115. .src_sz_max = 2048,
  116. .dest_nentries = 128,
  117. .recv_cb = ath10k_pci_htc_rx_cb,
  118. },
  119. /* CE3: host->target WMI */
  120. {
  121. .flags = CE_ATTR_FLAGS,
  122. .src_nentries = 32,
  123. .src_sz_max = 2048,
  124. .dest_nentries = 0,
  125. .send_cb = ath10k_pci_htc_tx_cb,
  126. },
  127. /* CE4: host->target HTT */
  128. {
  129. .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
  130. .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
  131. .src_sz_max = 256,
  132. .dest_nentries = 0,
  133. .send_cb = ath10k_pci_htt_tx_cb,
  134. },
  135. /* CE5: target->host HTT (HIF->HTT) */
  136. {
  137. .flags = CE_ATTR_FLAGS,
  138. .src_nentries = 0,
  139. .src_sz_max = 512,
  140. .dest_nentries = 512,
  141. .recv_cb = ath10k_pci_htt_rx_cb,
  142. },
  143. /* CE6: target autonomous hif_memcpy */
  144. {
  145. .flags = CE_ATTR_FLAGS,
  146. .src_nentries = 0,
  147. .src_sz_max = 0,
  148. .dest_nentries = 0,
  149. },
  150. /* CE7: ce_diag, the Diagnostic Window */
  151. {
  152. .flags = CE_ATTR_FLAGS,
  153. .src_nentries = 2,
  154. .src_sz_max = DIAG_TRANSFER_LIMIT,
  155. .dest_nentries = 2,
  156. },
  157. /* CE8: target->host pktlog */
  158. {
  159. .flags = CE_ATTR_FLAGS,
  160. .src_nentries = 0,
  161. .src_sz_max = 2048,
  162. .dest_nentries = 128,
  163. .recv_cb = ath10k_pci_pktlog_rx_cb,
  164. },
  165. /* CE9 target autonomous qcache memcpy */
  166. {
  167. .flags = CE_ATTR_FLAGS,
  168. .src_nentries = 0,
  169. .src_sz_max = 0,
  170. .dest_nentries = 0,
  171. },
  172. /* CE10: target autonomous hif memcpy */
  173. {
  174. .flags = CE_ATTR_FLAGS,
  175. .src_nentries = 0,
  176. .src_sz_max = 0,
  177. .dest_nentries = 0,
  178. },
  179. /* CE11: target autonomous hif memcpy */
  180. {
  181. .flags = CE_ATTR_FLAGS,
  182. .src_nentries = 0,
  183. .src_sz_max = 0,
  184. .dest_nentries = 0,
  185. },
  186. };
  187. /* Target firmware's Copy Engine configuration. */
  188. static struct ce_pipe_config target_ce_config_wlan[] = {
  189. /* CE0: host->target HTC control and raw streams */
  190. {
  191. .pipenum = __cpu_to_le32(0),
  192. .pipedir = __cpu_to_le32(PIPEDIR_OUT),
  193. .nentries = __cpu_to_le32(32),
  194. .nbytes_max = __cpu_to_le32(256),
  195. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  196. .reserved = __cpu_to_le32(0),
  197. },
  198. /* CE1: target->host HTT + HTC control */
  199. {
  200. .pipenum = __cpu_to_le32(1),
  201. .pipedir = __cpu_to_le32(PIPEDIR_IN),
  202. .nentries = __cpu_to_le32(32),
  203. .nbytes_max = __cpu_to_le32(2048),
  204. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  205. .reserved = __cpu_to_le32(0),
  206. },
  207. /* CE2: target->host WMI */
  208. {
  209. .pipenum = __cpu_to_le32(2),
  210. .pipedir = __cpu_to_le32(PIPEDIR_IN),
  211. .nentries = __cpu_to_le32(64),
  212. .nbytes_max = __cpu_to_le32(2048),
  213. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  214. .reserved = __cpu_to_le32(0),
  215. },
  216. /* CE3: host->target WMI */
  217. {
  218. .pipenum = __cpu_to_le32(3),
  219. .pipedir = __cpu_to_le32(PIPEDIR_OUT),
  220. .nentries = __cpu_to_le32(32),
  221. .nbytes_max = __cpu_to_le32(2048),
  222. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  223. .reserved = __cpu_to_le32(0),
  224. },
  225. /* CE4: host->target HTT */
  226. {
  227. .pipenum = __cpu_to_le32(4),
  228. .pipedir = __cpu_to_le32(PIPEDIR_OUT),
  229. .nentries = __cpu_to_le32(256),
  230. .nbytes_max = __cpu_to_le32(256),
  231. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  232. .reserved = __cpu_to_le32(0),
  233. },
  234. /* NB: 50% of src nentries, since tx has 2 frags */
  235. /* CE5: target->host HTT (HIF->HTT) */
  236. {
  237. .pipenum = __cpu_to_le32(5),
  238. .pipedir = __cpu_to_le32(PIPEDIR_IN),
  239. .nentries = __cpu_to_le32(32),
  240. .nbytes_max = __cpu_to_le32(512),
  241. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  242. .reserved = __cpu_to_le32(0),
  243. },
  244. /* CE6: Reserved for target autonomous hif_memcpy */
  245. {
  246. .pipenum = __cpu_to_le32(6),
  247. .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
  248. .nentries = __cpu_to_le32(32),
  249. .nbytes_max = __cpu_to_le32(4096),
  250. .flags = __cpu_to_le32(CE_ATTR_FLAGS),
  251. .reserved = __cpu_to_le32(0),
  252. },
  253. /* CE7 used only by Host */
  254. {
  255. .pipenum = __cpu_to_le32(7),
  256. .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
  257. .nentries = __cpu_to_le32(0),
  258. .nbytes_max = __cpu_to_le32(0),
  259. .flags = __cpu_to_le32(0),
  260. .reserved = __cpu_to_le32(0),
  261. },
  262. /* CE8 target->host packtlog */
  263. {
  264. .pipenum = __cpu_to_le32(8),
  265. .pipedir = __cpu_to_le32(PIPEDIR_IN),
  266. .nentries = __cpu_to_le32(64),
  267. .nbytes_max = __cpu_to_le32(2048),
  268. .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
  269. .reserved = __cpu_to_le32(0),
  270. },
  271. /* CE9 target autonomous qcache memcpy */
  272. {
  273. .pipenum = __cpu_to_le32(9),
  274. .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
  275. .nentries = __cpu_to_le32(32),
  276. .nbytes_max = __cpu_to_le32(2048),
  277. .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
  278. .reserved = __cpu_to_le32(0),
  279. },
  280. /* It not necessary to send target wlan configuration for CE10 & CE11
  281. * as these CEs are not actively used in target.
  282. */
  283. };
  284. /*
  285. * Map from service/endpoint to Copy Engine.
  286. * This table is derived from the CE_PCI TABLE, above.
  287. * It is passed to the Target at startup for use by firmware.
  288. */
  289. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  290. {
  291. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  292. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  293. __cpu_to_le32(3),
  294. },
  295. {
  296. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  297. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  298. __cpu_to_le32(2),
  299. },
  300. {
  301. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  302. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  303. __cpu_to_le32(3),
  304. },
  305. {
  306. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  307. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  308. __cpu_to_le32(2),
  309. },
  310. {
  311. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  312. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  313. __cpu_to_le32(3),
  314. },
  315. {
  316. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  317. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  318. __cpu_to_le32(2),
  319. },
  320. {
  321. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  322. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  323. __cpu_to_le32(3),
  324. },
  325. {
  326. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  327. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  328. __cpu_to_le32(2),
  329. },
  330. {
  331. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  332. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  333. __cpu_to_le32(3),
  334. },
  335. {
  336. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  337. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  338. __cpu_to_le32(2),
  339. },
  340. {
  341. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  342. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  343. __cpu_to_le32(0),
  344. },
  345. {
  346. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  347. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  348. __cpu_to_le32(1),
  349. },
  350. { /* not used */
  351. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  352. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  353. __cpu_to_le32(0),
  354. },
  355. { /* not used */
  356. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  357. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  358. __cpu_to_le32(1),
  359. },
  360. {
  361. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  362. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  363. __cpu_to_le32(4),
  364. },
  365. {
  366. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  367. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  368. __cpu_to_le32(5),
  369. },
  370. /* (Additions here) */
  371. { /* must be last */
  372. __cpu_to_le32(0),
  373. __cpu_to_le32(0),
  374. __cpu_to_le32(0),
  375. },
  376. };
  377. static bool ath10k_pci_is_awake(struct ath10k *ar)
  378. {
  379. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  380. u32 val = ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
  381. RTC_STATE_ADDRESS);
  382. return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
  383. }
  384. static void __ath10k_pci_wake(struct ath10k *ar)
  385. {
  386. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  387. lockdep_assert_held(&ar_pci->ps_lock);
  388. ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake reg refcount %lu awake %d\n",
  389. ar_pci->ps_wake_refcount, ar_pci->ps_awake);
  390. iowrite32(PCIE_SOC_WAKE_V_MASK,
  391. ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
  392. PCIE_SOC_WAKE_ADDRESS);
  393. }
  394. static void __ath10k_pci_sleep(struct ath10k *ar)
  395. {
  396. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  397. lockdep_assert_held(&ar_pci->ps_lock);
  398. ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep reg refcount %lu awake %d\n",
  399. ar_pci->ps_wake_refcount, ar_pci->ps_awake);
  400. iowrite32(PCIE_SOC_WAKE_RESET,
  401. ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
  402. PCIE_SOC_WAKE_ADDRESS);
  403. ar_pci->ps_awake = false;
  404. }
  405. static int ath10k_pci_wake_wait(struct ath10k *ar)
  406. {
  407. int tot_delay = 0;
  408. int curr_delay = 5;
  409. while (tot_delay < PCIE_WAKE_TIMEOUT) {
  410. if (ath10k_pci_is_awake(ar)) {
  411. if (tot_delay > PCIE_WAKE_LATE_US)
  412. ath10k_warn(ar, "device wakeup took %d ms which is unusally long, otherwise it works normally.\n",
  413. tot_delay / 1000);
  414. return 0;
  415. }
  416. udelay(curr_delay);
  417. tot_delay += curr_delay;
  418. if (curr_delay < 50)
  419. curr_delay += 5;
  420. }
  421. return -ETIMEDOUT;
  422. }
  423. static int ath10k_pci_force_wake(struct ath10k *ar)
  424. {
  425. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  426. unsigned long flags;
  427. int ret = 0;
  428. if (ar_pci->pci_ps)
  429. return ret;
  430. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  431. if (!ar_pci->ps_awake) {
  432. iowrite32(PCIE_SOC_WAKE_V_MASK,
  433. ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
  434. PCIE_SOC_WAKE_ADDRESS);
  435. ret = ath10k_pci_wake_wait(ar);
  436. if (ret == 0)
  437. ar_pci->ps_awake = true;
  438. }
  439. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  440. return ret;
  441. }
  442. static void ath10k_pci_force_sleep(struct ath10k *ar)
  443. {
  444. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  445. unsigned long flags;
  446. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  447. iowrite32(PCIE_SOC_WAKE_RESET,
  448. ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
  449. PCIE_SOC_WAKE_ADDRESS);
  450. ar_pci->ps_awake = false;
  451. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  452. }
  453. static int ath10k_pci_wake(struct ath10k *ar)
  454. {
  455. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  456. unsigned long flags;
  457. int ret = 0;
  458. if (ar_pci->pci_ps == 0)
  459. return ret;
  460. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  461. ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake refcount %lu awake %d\n",
  462. ar_pci->ps_wake_refcount, ar_pci->ps_awake);
  463. /* This function can be called very frequently. To avoid excessive
  464. * CPU stalls for MMIO reads use a cache var to hold the device state.
  465. */
  466. if (!ar_pci->ps_awake) {
  467. __ath10k_pci_wake(ar);
  468. ret = ath10k_pci_wake_wait(ar);
  469. if (ret == 0)
  470. ar_pci->ps_awake = true;
  471. }
  472. if (ret == 0) {
  473. ar_pci->ps_wake_refcount++;
  474. WARN_ON(ar_pci->ps_wake_refcount == 0);
  475. }
  476. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  477. return ret;
  478. }
  479. static void ath10k_pci_sleep(struct ath10k *ar)
  480. {
  481. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  482. unsigned long flags;
  483. if (ar_pci->pci_ps == 0)
  484. return;
  485. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  486. ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep refcount %lu awake %d\n",
  487. ar_pci->ps_wake_refcount, ar_pci->ps_awake);
  488. if (WARN_ON(ar_pci->ps_wake_refcount == 0))
  489. goto skip;
  490. ar_pci->ps_wake_refcount--;
  491. mod_timer(&ar_pci->ps_timer, jiffies +
  492. msecs_to_jiffies(ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC));
  493. skip:
  494. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  495. }
  496. static void ath10k_pci_ps_timer(unsigned long ptr)
  497. {
  498. struct ath10k *ar = (void *)ptr;
  499. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  500. unsigned long flags;
  501. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  502. ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps timer refcount %lu awake %d\n",
  503. ar_pci->ps_wake_refcount, ar_pci->ps_awake);
  504. if (ar_pci->ps_wake_refcount > 0)
  505. goto skip;
  506. __ath10k_pci_sleep(ar);
  507. skip:
  508. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  509. }
  510. static void ath10k_pci_sleep_sync(struct ath10k *ar)
  511. {
  512. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  513. unsigned long flags;
  514. if (ar_pci->pci_ps == 0) {
  515. ath10k_pci_force_sleep(ar);
  516. return;
  517. }
  518. del_timer_sync(&ar_pci->ps_timer);
  519. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  520. WARN_ON(ar_pci->ps_wake_refcount > 0);
  521. __ath10k_pci_sleep(ar);
  522. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  523. }
  524. static void ath10k_bus_pci_write32(struct ath10k *ar, u32 offset, u32 value)
  525. {
  526. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  527. int ret;
  528. if (unlikely(offset + sizeof(value) > ar_pci->mem_len)) {
  529. ath10k_warn(ar, "refusing to write mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
  530. offset, offset + sizeof(value), ar_pci->mem_len);
  531. return;
  532. }
  533. ret = ath10k_pci_wake(ar);
  534. if (ret) {
  535. ath10k_warn(ar, "failed to wake target for write32 of 0x%08x at 0x%08x: %d\n",
  536. value, offset, ret);
  537. return;
  538. }
  539. iowrite32(value, ar_pci->mem + offset);
  540. ath10k_pci_sleep(ar);
  541. }
  542. static u32 ath10k_bus_pci_read32(struct ath10k *ar, u32 offset)
  543. {
  544. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  545. u32 val;
  546. int ret;
  547. if (unlikely(offset + sizeof(val) > ar_pci->mem_len)) {
  548. ath10k_warn(ar, "refusing to read mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
  549. offset, offset + sizeof(val), ar_pci->mem_len);
  550. return 0;
  551. }
  552. ret = ath10k_pci_wake(ar);
  553. if (ret) {
  554. ath10k_warn(ar, "failed to wake target for read32 at 0x%08x: %d\n",
  555. offset, ret);
  556. return 0xffffffff;
  557. }
  558. val = ioread32(ar_pci->mem + offset);
  559. ath10k_pci_sleep(ar);
  560. return val;
  561. }
  562. inline void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value)
  563. {
  564. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  565. ar_pci->bus_ops->write32(ar, offset, value);
  566. }
  567. inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
  568. {
  569. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  570. return ar_pci->bus_ops->read32(ar, offset);
  571. }
  572. u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
  573. {
  574. return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
  575. }
  576. void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
  577. {
  578. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
  579. }
  580. u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
  581. {
  582. return ath10k_pci_read32(ar, PCIE_LOCAL_BASE_ADDRESS + addr);
  583. }
  584. void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
  585. {
  586. ath10k_pci_write32(ar, PCIE_LOCAL_BASE_ADDRESS + addr, val);
  587. }
  588. bool ath10k_pci_irq_pending(struct ath10k *ar)
  589. {
  590. u32 cause;
  591. /* Check if the shared legacy irq is for us */
  592. cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  593. PCIE_INTR_CAUSE_ADDRESS);
  594. if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
  595. return true;
  596. return false;
  597. }
  598. void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
  599. {
  600. /* IMPORTANT: INTR_CLR register has to be set after
  601. * INTR_ENABLE is set to 0, otherwise interrupt can not be
  602. * really cleared. */
  603. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  604. 0);
  605. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
  606. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  607. /* IMPORTANT: this extra read transaction is required to
  608. * flush the posted write buffer. */
  609. (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  610. PCIE_INTR_ENABLE_ADDRESS);
  611. }
  612. void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
  613. {
  614. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  615. PCIE_INTR_ENABLE_ADDRESS,
  616. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  617. /* IMPORTANT: this extra read transaction is required to
  618. * flush the posted write buffer. */
  619. (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  620. PCIE_INTR_ENABLE_ADDRESS);
  621. }
  622. static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
  623. {
  624. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  625. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_MSI)
  626. return "msi";
  627. return "legacy";
  628. }
  629. static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
  630. {
  631. struct ath10k *ar = pipe->hif_ce_state;
  632. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  633. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  634. struct sk_buff *skb;
  635. dma_addr_t paddr;
  636. int ret;
  637. skb = dev_alloc_skb(pipe->buf_sz);
  638. if (!skb)
  639. return -ENOMEM;
  640. WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
  641. paddr = dma_map_single(ar->dev, skb->data,
  642. skb->len + skb_tailroom(skb),
  643. DMA_FROM_DEVICE);
  644. if (unlikely(dma_mapping_error(ar->dev, paddr))) {
  645. ath10k_warn(ar, "failed to dma map pci rx buf\n");
  646. dev_kfree_skb_any(skb);
  647. return -EIO;
  648. }
  649. ATH10K_SKB_RXCB(skb)->paddr = paddr;
  650. spin_lock_bh(&ar_pci->ce_lock);
  651. ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
  652. spin_unlock_bh(&ar_pci->ce_lock);
  653. if (ret) {
  654. dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
  655. DMA_FROM_DEVICE);
  656. dev_kfree_skb_any(skb);
  657. return ret;
  658. }
  659. return 0;
  660. }
  661. static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
  662. {
  663. struct ath10k *ar = pipe->hif_ce_state;
  664. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  665. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  666. int ret, num;
  667. if (pipe->buf_sz == 0)
  668. return;
  669. if (!ce_pipe->dest_ring)
  670. return;
  671. spin_lock_bh(&ar_pci->ce_lock);
  672. num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
  673. spin_unlock_bh(&ar_pci->ce_lock);
  674. while (num >= 0) {
  675. ret = __ath10k_pci_rx_post_buf(pipe);
  676. if (ret) {
  677. if (ret == -ENOSPC)
  678. break;
  679. ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
  680. mod_timer(&ar_pci->rx_post_retry, jiffies +
  681. ATH10K_PCI_RX_POST_RETRY_MS);
  682. break;
  683. }
  684. num--;
  685. }
  686. }
  687. void ath10k_pci_rx_post(struct ath10k *ar)
  688. {
  689. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  690. int i;
  691. for (i = 0; i < CE_COUNT; i++)
  692. ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
  693. }
  694. void ath10k_pci_rx_replenish_retry(unsigned long ptr)
  695. {
  696. struct ath10k *ar = (void *)ptr;
  697. ath10k_pci_rx_post(ar);
  698. }
  699. static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  700. {
  701. u32 val = 0;
  702. switch (ar->hw_rev) {
  703. case ATH10K_HW_QCA988X:
  704. case ATH10K_HW_QCA9887:
  705. case ATH10K_HW_QCA6174:
  706. case ATH10K_HW_QCA9377:
  707. val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  708. CORE_CTRL_ADDRESS) &
  709. 0x7ff) << 21;
  710. break;
  711. case ATH10K_HW_QCA9888:
  712. case ATH10K_HW_QCA99X0:
  713. case ATH10K_HW_QCA9984:
  714. case ATH10K_HW_QCA4019:
  715. val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
  716. break;
  717. }
  718. val |= 0x100000 | (addr & 0xfffff);
  719. return val;
  720. }
  721. /*
  722. * Diagnostic read/write access is provided for startup/config/debug usage.
  723. * Caller must guarantee proper alignment, when applicable, and single user
  724. * at any moment.
  725. */
  726. static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
  727. int nbytes)
  728. {
  729. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  730. int ret = 0;
  731. u32 *buf;
  732. unsigned int completed_nbytes, alloc_nbytes, remaining_bytes;
  733. struct ath10k_ce_pipe *ce_diag;
  734. /* Host buffer address in CE space */
  735. u32 ce_data;
  736. dma_addr_t ce_data_base = 0;
  737. void *data_buf = NULL;
  738. int i;
  739. spin_lock_bh(&ar_pci->ce_lock);
  740. ce_diag = ar_pci->ce_diag;
  741. /*
  742. * Allocate a temporary bounce buffer to hold caller's data
  743. * to be DMA'ed from Target. This guarantees
  744. * 1) 4-byte alignment
  745. * 2) Buffer in DMA-able space
  746. */
  747. alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT);
  748. data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
  749. alloc_nbytes,
  750. &ce_data_base,
  751. GFP_ATOMIC);
  752. if (!data_buf) {
  753. ret = -ENOMEM;
  754. goto done;
  755. }
  756. memset(data_buf, 0, alloc_nbytes);
  757. remaining_bytes = nbytes;
  758. ce_data = ce_data_base;
  759. while (remaining_bytes) {
  760. nbytes = min_t(unsigned int, remaining_bytes,
  761. DIAG_TRANSFER_LIMIT);
  762. ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, ce_data);
  763. if (ret != 0)
  764. goto done;
  765. /* Request CE to send from Target(!) address to Host buffer */
  766. /*
  767. * The address supplied by the caller is in the
  768. * Target CPU virtual address space.
  769. *
  770. * In order to use this address with the diagnostic CE,
  771. * convert it from Target CPU virtual address space
  772. * to CE address space
  773. */
  774. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  775. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
  776. 0);
  777. if (ret)
  778. goto done;
  779. i = 0;
  780. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  781. NULL) != 0) {
  782. mdelay(1);
  783. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  784. ret = -EBUSY;
  785. goto done;
  786. }
  787. }
  788. i = 0;
  789. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  790. (void **)&buf,
  791. &completed_nbytes)
  792. != 0) {
  793. mdelay(1);
  794. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  795. ret = -EBUSY;
  796. goto done;
  797. }
  798. }
  799. if (nbytes != completed_nbytes) {
  800. ret = -EIO;
  801. goto done;
  802. }
  803. if (*buf != ce_data) {
  804. ret = -EIO;
  805. goto done;
  806. }
  807. remaining_bytes -= nbytes;
  808. if (ret) {
  809. ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
  810. address, ret);
  811. break;
  812. }
  813. memcpy(data, data_buf, nbytes);
  814. address += nbytes;
  815. data += nbytes;
  816. }
  817. done:
  818. if (data_buf)
  819. dma_free_coherent(ar->dev, alloc_nbytes, data_buf,
  820. ce_data_base);
  821. spin_unlock_bh(&ar_pci->ce_lock);
  822. return ret;
  823. }
  824. static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
  825. {
  826. __le32 val = 0;
  827. int ret;
  828. ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
  829. *value = __le32_to_cpu(val);
  830. return ret;
  831. }
  832. static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
  833. u32 src, u32 len)
  834. {
  835. u32 host_addr, addr;
  836. int ret;
  837. host_addr = host_interest_item_address(src);
  838. ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
  839. if (ret != 0) {
  840. ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
  841. src, ret);
  842. return ret;
  843. }
  844. ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
  845. if (ret != 0) {
  846. ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
  847. addr, len, ret);
  848. return ret;
  849. }
  850. return 0;
  851. }
  852. #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
  853. __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
  854. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  855. const void *data, int nbytes)
  856. {
  857. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  858. int ret = 0;
  859. u32 *buf;
  860. unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
  861. struct ath10k_ce_pipe *ce_diag;
  862. void *data_buf = NULL;
  863. u32 ce_data; /* Host buffer address in CE space */
  864. dma_addr_t ce_data_base = 0;
  865. int i;
  866. spin_lock_bh(&ar_pci->ce_lock);
  867. ce_diag = ar_pci->ce_diag;
  868. /*
  869. * Allocate a temporary bounce buffer to hold caller's data
  870. * to be DMA'ed to Target. This guarantees
  871. * 1) 4-byte alignment
  872. * 2) Buffer in DMA-able space
  873. */
  874. orig_nbytes = nbytes;
  875. data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
  876. orig_nbytes,
  877. &ce_data_base,
  878. GFP_ATOMIC);
  879. if (!data_buf) {
  880. ret = -ENOMEM;
  881. goto done;
  882. }
  883. /* Copy caller's data to allocated DMA buf */
  884. memcpy(data_buf, data, orig_nbytes);
  885. /*
  886. * The address supplied by the caller is in the
  887. * Target CPU virtual address space.
  888. *
  889. * In order to use this address with the diagnostic CE,
  890. * convert it from
  891. * Target CPU virtual address space
  892. * to
  893. * CE address space
  894. */
  895. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  896. remaining_bytes = orig_nbytes;
  897. ce_data = ce_data_base;
  898. while (remaining_bytes) {
  899. /* FIXME: check cast */
  900. nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
  901. /* Set up to receive directly into Target(!) address */
  902. ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
  903. if (ret != 0)
  904. goto done;
  905. /*
  906. * Request CE to send caller-supplied data that
  907. * was copied to bounce buffer to Target(!) address.
  908. */
  909. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
  910. nbytes, 0, 0);
  911. if (ret != 0)
  912. goto done;
  913. i = 0;
  914. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  915. NULL) != 0) {
  916. mdelay(1);
  917. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  918. ret = -EBUSY;
  919. goto done;
  920. }
  921. }
  922. i = 0;
  923. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  924. (void **)&buf,
  925. &completed_nbytes)
  926. != 0) {
  927. mdelay(1);
  928. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  929. ret = -EBUSY;
  930. goto done;
  931. }
  932. }
  933. if (nbytes != completed_nbytes) {
  934. ret = -EIO;
  935. goto done;
  936. }
  937. if (*buf != address) {
  938. ret = -EIO;
  939. goto done;
  940. }
  941. remaining_bytes -= nbytes;
  942. address += nbytes;
  943. ce_data += nbytes;
  944. }
  945. done:
  946. if (data_buf) {
  947. dma_free_coherent(ar->dev, orig_nbytes, data_buf,
  948. ce_data_base);
  949. }
  950. if (ret != 0)
  951. ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
  952. address, ret);
  953. spin_unlock_bh(&ar_pci->ce_lock);
  954. return ret;
  955. }
  956. static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
  957. {
  958. __le32 val = __cpu_to_le32(value);
  959. return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
  960. }
  961. /* Called by lower (CE) layer when a send to Target completes. */
  962. static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
  963. {
  964. struct ath10k *ar = ce_state->ar;
  965. struct sk_buff_head list;
  966. struct sk_buff *skb;
  967. __skb_queue_head_init(&list);
  968. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  969. /* no need to call tx completion for NULL pointers */
  970. if (skb == NULL)
  971. continue;
  972. __skb_queue_tail(&list, skb);
  973. }
  974. while ((skb = __skb_dequeue(&list)))
  975. ath10k_htc_tx_completion_handler(ar, skb);
  976. }
  977. static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
  978. void (*callback)(struct ath10k *ar,
  979. struct sk_buff *skb))
  980. {
  981. struct ath10k *ar = ce_state->ar;
  982. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  983. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  984. struct sk_buff *skb;
  985. struct sk_buff_head list;
  986. void *transfer_context;
  987. unsigned int nbytes, max_nbytes;
  988. __skb_queue_head_init(&list);
  989. while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
  990. &nbytes) == 0) {
  991. skb = transfer_context;
  992. max_nbytes = skb->len + skb_tailroom(skb);
  993. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  994. max_nbytes, DMA_FROM_DEVICE);
  995. if (unlikely(max_nbytes < nbytes)) {
  996. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  997. nbytes, max_nbytes);
  998. dev_kfree_skb_any(skb);
  999. continue;
  1000. }
  1001. skb_put(skb, nbytes);
  1002. __skb_queue_tail(&list, skb);
  1003. }
  1004. while ((skb = __skb_dequeue(&list))) {
  1005. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1006. ce_state->id, skb->len);
  1007. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1008. skb->data, skb->len);
  1009. callback(ar, skb);
  1010. }
  1011. ath10k_pci_rx_post_pipe(pipe_info);
  1012. }
  1013. static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
  1014. void (*callback)(struct ath10k *ar,
  1015. struct sk_buff *skb))
  1016. {
  1017. struct ath10k *ar = ce_state->ar;
  1018. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1019. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  1020. struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
  1021. struct sk_buff *skb;
  1022. struct sk_buff_head list;
  1023. void *transfer_context;
  1024. unsigned int nbytes, max_nbytes, nentries;
  1025. int orig_len;
  1026. /* No need to aquire ce_lock for CE5, since this is the only place CE5
  1027. * is processed other than init and deinit. Before releasing CE5
  1028. * buffers, interrupts are disabled. Thus CE5 access is serialized.
  1029. */
  1030. __skb_queue_head_init(&list);
  1031. while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
  1032. &nbytes) == 0) {
  1033. skb = transfer_context;
  1034. max_nbytes = skb->len + skb_tailroom(skb);
  1035. if (unlikely(max_nbytes < nbytes)) {
  1036. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  1037. nbytes, max_nbytes);
  1038. continue;
  1039. }
  1040. dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1041. max_nbytes, DMA_FROM_DEVICE);
  1042. skb_put(skb, nbytes);
  1043. __skb_queue_tail(&list, skb);
  1044. }
  1045. nentries = skb_queue_len(&list);
  1046. while ((skb = __skb_dequeue(&list))) {
  1047. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1048. ce_state->id, skb->len);
  1049. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1050. skb->data, skb->len);
  1051. orig_len = skb->len;
  1052. callback(ar, skb);
  1053. skb_push(skb, orig_len - skb->len);
  1054. skb_reset_tail_pointer(skb);
  1055. skb_trim(skb, 0);
  1056. /*let device gain the buffer again*/
  1057. dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1058. skb->len + skb_tailroom(skb),
  1059. DMA_FROM_DEVICE);
  1060. }
  1061. ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
  1062. }
  1063. /* Called by lower (CE) layer when data is received from the Target. */
  1064. static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1065. {
  1066. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1067. }
  1068. static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1069. {
  1070. /* CE4 polling needs to be done whenever CE pipe which transports
  1071. * HTT Rx (target->host) is processed.
  1072. */
  1073. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1074. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1075. }
  1076. /* Called by lower (CE) layer when data is received from the Target.
  1077. * Only 10.4 firmware uses separate CE to transfer pktlog data.
  1078. */
  1079. static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
  1080. {
  1081. ath10k_pci_process_rx_cb(ce_state,
  1082. ath10k_htt_rx_pktlog_completion_handler);
  1083. }
  1084. /* Called by lower (CE) layer when a send to HTT Target completes. */
  1085. static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
  1086. {
  1087. struct ath10k *ar = ce_state->ar;
  1088. struct sk_buff *skb;
  1089. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  1090. /* no need to call tx completion for NULL pointers */
  1091. if (!skb)
  1092. continue;
  1093. dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
  1094. skb->len, DMA_TO_DEVICE);
  1095. ath10k_htt_hif_tx_complete(ar, skb);
  1096. }
  1097. }
  1098. static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
  1099. {
  1100. skb_pull(skb, sizeof(struct ath10k_htc_hdr));
  1101. ath10k_htt_t2h_msg_handler(ar, skb);
  1102. }
  1103. /* Called by lower (CE) layer when HTT data is received from the Target. */
  1104. static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
  1105. {
  1106. /* CE4 polling needs to be done whenever CE pipe which transports
  1107. * HTT Rx (target->host) is processed.
  1108. */
  1109. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1110. ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
  1111. }
  1112. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  1113. struct ath10k_hif_sg_item *items, int n_items)
  1114. {
  1115. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1116. struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
  1117. struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
  1118. struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
  1119. unsigned int nentries_mask;
  1120. unsigned int sw_index;
  1121. unsigned int write_index;
  1122. int err, i = 0;
  1123. spin_lock_bh(&ar_pci->ce_lock);
  1124. nentries_mask = src_ring->nentries_mask;
  1125. sw_index = src_ring->sw_index;
  1126. write_index = src_ring->write_index;
  1127. if (unlikely(CE_RING_DELTA(nentries_mask,
  1128. write_index, sw_index - 1) < n_items)) {
  1129. err = -ENOBUFS;
  1130. goto err;
  1131. }
  1132. for (i = 0; i < n_items - 1; i++) {
  1133. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1134. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1135. i, items[i].paddr, items[i].len, n_items);
  1136. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1137. items[i].vaddr, items[i].len);
  1138. err = ath10k_ce_send_nolock(ce_pipe,
  1139. items[i].transfer_context,
  1140. items[i].paddr,
  1141. items[i].len,
  1142. items[i].transfer_id,
  1143. CE_SEND_FLAG_GATHER);
  1144. if (err)
  1145. goto err;
  1146. }
  1147. /* `i` is equal to `n_items -1` after for() */
  1148. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1149. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1150. i, items[i].paddr, items[i].len, n_items);
  1151. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1152. items[i].vaddr, items[i].len);
  1153. err = ath10k_ce_send_nolock(ce_pipe,
  1154. items[i].transfer_context,
  1155. items[i].paddr,
  1156. items[i].len,
  1157. items[i].transfer_id,
  1158. 0);
  1159. if (err)
  1160. goto err;
  1161. spin_unlock_bh(&ar_pci->ce_lock);
  1162. return 0;
  1163. err:
  1164. for (; i > 0; i--)
  1165. __ath10k_ce_send_revert(ce_pipe);
  1166. spin_unlock_bh(&ar_pci->ce_lock);
  1167. return err;
  1168. }
  1169. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  1170. size_t buf_len)
  1171. {
  1172. return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
  1173. }
  1174. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
  1175. {
  1176. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1177. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
  1178. return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
  1179. }
  1180. static void ath10k_pci_dump_registers(struct ath10k *ar,
  1181. struct ath10k_fw_crash_data *crash_data)
  1182. {
  1183. __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
  1184. int i, ret;
  1185. lockdep_assert_held(&ar->data_lock);
  1186. ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
  1187. hi_failure_state,
  1188. REG_DUMP_COUNT_QCA988X * sizeof(__le32));
  1189. if (ret) {
  1190. ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
  1191. return;
  1192. }
  1193. BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
  1194. ath10k_err(ar, "firmware register dump:\n");
  1195. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
  1196. ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
  1197. i,
  1198. __le32_to_cpu(reg_dump_values[i]),
  1199. __le32_to_cpu(reg_dump_values[i + 1]),
  1200. __le32_to_cpu(reg_dump_values[i + 2]),
  1201. __le32_to_cpu(reg_dump_values[i + 3]));
  1202. if (!crash_data)
  1203. return;
  1204. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
  1205. crash_data->registers[i] = reg_dump_values[i];
  1206. }
  1207. static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
  1208. {
  1209. struct ath10k_fw_crash_data *crash_data;
  1210. char uuid[50];
  1211. spin_lock_bh(&ar->data_lock);
  1212. ar->stats.fw_crash_counter++;
  1213. crash_data = ath10k_debug_get_new_fw_crash_data(ar);
  1214. if (crash_data)
  1215. scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
  1216. else
  1217. scnprintf(uuid, sizeof(uuid), "n/a");
  1218. ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
  1219. ath10k_print_driver_info(ar);
  1220. ath10k_pci_dump_registers(ar, crash_data);
  1221. spin_unlock_bh(&ar->data_lock);
  1222. queue_work(ar->workqueue, &ar->restart_work);
  1223. }
  1224. void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  1225. int force)
  1226. {
  1227. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
  1228. if (!force) {
  1229. int resources;
  1230. /*
  1231. * Decide whether to actually poll for completions, or just
  1232. * wait for a later chance.
  1233. * If there seem to be plenty of resources left, then just wait
  1234. * since checking involves reading a CE register, which is a
  1235. * relatively expensive operation.
  1236. */
  1237. resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
  1238. /*
  1239. * If at least 50% of the total resources are still available,
  1240. * don't bother checking again yet.
  1241. */
  1242. if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
  1243. return;
  1244. }
  1245. ath10k_ce_per_engine_service(ar, pipe);
  1246. }
  1247. void ath10k_pci_kill_tasklet(struct ath10k *ar)
  1248. {
  1249. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1250. tasklet_kill(&ar_pci->intr_tq);
  1251. del_timer_sync(&ar_pci->rx_post_retry);
  1252. }
  1253. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  1254. u8 *ul_pipe, u8 *dl_pipe)
  1255. {
  1256. const struct service_to_pipe *entry;
  1257. bool ul_set = false, dl_set = false;
  1258. int i;
  1259. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
  1260. for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
  1261. entry = &target_service_to_ce_map_wlan[i];
  1262. if (__le32_to_cpu(entry->service_id) != service_id)
  1263. continue;
  1264. switch (__le32_to_cpu(entry->pipedir)) {
  1265. case PIPEDIR_NONE:
  1266. break;
  1267. case PIPEDIR_IN:
  1268. WARN_ON(dl_set);
  1269. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1270. dl_set = true;
  1271. break;
  1272. case PIPEDIR_OUT:
  1273. WARN_ON(ul_set);
  1274. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1275. ul_set = true;
  1276. break;
  1277. case PIPEDIR_INOUT:
  1278. WARN_ON(dl_set);
  1279. WARN_ON(ul_set);
  1280. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1281. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1282. dl_set = true;
  1283. ul_set = true;
  1284. break;
  1285. }
  1286. }
  1287. if (WARN_ON(!ul_set || !dl_set))
  1288. return -ENOENT;
  1289. return 0;
  1290. }
  1291. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
  1292. u8 *ul_pipe, u8 *dl_pipe)
  1293. {
  1294. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
  1295. (void)ath10k_pci_hif_map_service_to_pipe(ar,
  1296. ATH10K_HTC_SVC_ID_RSVD_CTRL,
  1297. ul_pipe, dl_pipe);
  1298. }
  1299. static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
  1300. {
  1301. u32 val;
  1302. switch (ar->hw_rev) {
  1303. case ATH10K_HW_QCA988X:
  1304. case ATH10K_HW_QCA9887:
  1305. case ATH10K_HW_QCA6174:
  1306. case ATH10K_HW_QCA9377:
  1307. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1308. CORE_CTRL_ADDRESS);
  1309. val &= ~CORE_CTRL_PCIE_REG_31_MASK;
  1310. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1311. CORE_CTRL_ADDRESS, val);
  1312. break;
  1313. case ATH10K_HW_QCA99X0:
  1314. case ATH10K_HW_QCA9984:
  1315. case ATH10K_HW_QCA9888:
  1316. case ATH10K_HW_QCA4019:
  1317. /* TODO: Find appropriate register configuration for QCA99X0
  1318. * to mask irq/MSI.
  1319. */
  1320. break;
  1321. }
  1322. }
  1323. static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
  1324. {
  1325. u32 val;
  1326. switch (ar->hw_rev) {
  1327. case ATH10K_HW_QCA988X:
  1328. case ATH10K_HW_QCA9887:
  1329. case ATH10K_HW_QCA6174:
  1330. case ATH10K_HW_QCA9377:
  1331. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1332. CORE_CTRL_ADDRESS);
  1333. val |= CORE_CTRL_PCIE_REG_31_MASK;
  1334. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1335. CORE_CTRL_ADDRESS, val);
  1336. break;
  1337. case ATH10K_HW_QCA99X0:
  1338. case ATH10K_HW_QCA9984:
  1339. case ATH10K_HW_QCA9888:
  1340. case ATH10K_HW_QCA4019:
  1341. /* TODO: Find appropriate register configuration for QCA99X0
  1342. * to unmask irq/MSI.
  1343. */
  1344. break;
  1345. }
  1346. }
  1347. static void ath10k_pci_irq_disable(struct ath10k *ar)
  1348. {
  1349. ath10k_ce_disable_interrupts(ar);
  1350. ath10k_pci_disable_and_clear_legacy_irq(ar);
  1351. ath10k_pci_irq_msi_fw_mask(ar);
  1352. }
  1353. static void ath10k_pci_irq_sync(struct ath10k *ar)
  1354. {
  1355. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1356. synchronize_irq(ar_pci->pdev->irq);
  1357. }
  1358. static void ath10k_pci_irq_enable(struct ath10k *ar)
  1359. {
  1360. ath10k_ce_enable_interrupts(ar);
  1361. ath10k_pci_enable_legacy_irq(ar);
  1362. ath10k_pci_irq_msi_fw_unmask(ar);
  1363. }
  1364. static int ath10k_pci_hif_start(struct ath10k *ar)
  1365. {
  1366. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1367. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
  1368. ath10k_pci_irq_enable(ar);
  1369. ath10k_pci_rx_post(ar);
  1370. pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  1371. ar_pci->link_ctl);
  1372. return 0;
  1373. }
  1374. static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
  1375. {
  1376. struct ath10k *ar;
  1377. struct ath10k_ce_pipe *ce_pipe;
  1378. struct ath10k_ce_ring *ce_ring;
  1379. struct sk_buff *skb;
  1380. int i;
  1381. ar = pci_pipe->hif_ce_state;
  1382. ce_pipe = pci_pipe->ce_hdl;
  1383. ce_ring = ce_pipe->dest_ring;
  1384. if (!ce_ring)
  1385. return;
  1386. if (!pci_pipe->buf_sz)
  1387. return;
  1388. for (i = 0; i < ce_ring->nentries; i++) {
  1389. skb = ce_ring->per_transfer_context[i];
  1390. if (!skb)
  1391. continue;
  1392. ce_ring->per_transfer_context[i] = NULL;
  1393. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1394. skb->len + skb_tailroom(skb),
  1395. DMA_FROM_DEVICE);
  1396. dev_kfree_skb_any(skb);
  1397. }
  1398. }
  1399. static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
  1400. {
  1401. struct ath10k *ar;
  1402. struct ath10k_pci *ar_pci;
  1403. struct ath10k_ce_pipe *ce_pipe;
  1404. struct ath10k_ce_ring *ce_ring;
  1405. struct sk_buff *skb;
  1406. int i;
  1407. ar = pci_pipe->hif_ce_state;
  1408. ar_pci = ath10k_pci_priv(ar);
  1409. ce_pipe = pci_pipe->ce_hdl;
  1410. ce_ring = ce_pipe->src_ring;
  1411. if (!ce_ring)
  1412. return;
  1413. if (!pci_pipe->buf_sz)
  1414. return;
  1415. for (i = 0; i < ce_ring->nentries; i++) {
  1416. skb = ce_ring->per_transfer_context[i];
  1417. if (!skb)
  1418. continue;
  1419. ce_ring->per_transfer_context[i] = NULL;
  1420. ath10k_htc_tx_completion_handler(ar, skb);
  1421. }
  1422. }
  1423. /*
  1424. * Cleanup residual buffers for device shutdown:
  1425. * buffers that were enqueued for receive
  1426. * buffers that were to be sent
  1427. * Note: Buffers that had completed but which were
  1428. * not yet processed are on a completion queue. They
  1429. * are handled when the completion thread shuts down.
  1430. */
  1431. static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
  1432. {
  1433. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1434. int pipe_num;
  1435. for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
  1436. struct ath10k_pci_pipe *pipe_info;
  1437. pipe_info = &ar_pci->pipe_info[pipe_num];
  1438. ath10k_pci_rx_pipe_cleanup(pipe_info);
  1439. ath10k_pci_tx_pipe_cleanup(pipe_info);
  1440. }
  1441. }
  1442. void ath10k_pci_ce_deinit(struct ath10k *ar)
  1443. {
  1444. int i;
  1445. for (i = 0; i < CE_COUNT; i++)
  1446. ath10k_ce_deinit_pipe(ar, i);
  1447. }
  1448. void ath10k_pci_flush(struct ath10k *ar)
  1449. {
  1450. ath10k_pci_kill_tasklet(ar);
  1451. ath10k_pci_buffer_cleanup(ar);
  1452. }
  1453. static void ath10k_pci_hif_stop(struct ath10k *ar)
  1454. {
  1455. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1456. unsigned long flags;
  1457. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
  1458. /* Most likely the device has HTT Rx ring configured. The only way to
  1459. * prevent the device from accessing (and possible corrupting) host
  1460. * memory is to reset the chip now.
  1461. *
  1462. * There's also no known way of masking MSI interrupts on the device.
  1463. * For ranged MSI the CE-related interrupts can be masked. However
  1464. * regardless how many MSI interrupts are assigned the first one
  1465. * is always used for firmware indications (crashes) and cannot be
  1466. * masked. To prevent the device from asserting the interrupt reset it
  1467. * before proceeding with cleanup.
  1468. */
  1469. ath10k_pci_safe_chip_reset(ar);
  1470. ath10k_pci_irq_disable(ar);
  1471. ath10k_pci_irq_sync(ar);
  1472. ath10k_pci_flush(ar);
  1473. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  1474. WARN_ON(ar_pci->ps_wake_refcount > 0);
  1475. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  1476. }
  1477. int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
  1478. void *req, u32 req_len,
  1479. void *resp, u32 *resp_len)
  1480. {
  1481. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1482. struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
  1483. struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
  1484. struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
  1485. struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
  1486. dma_addr_t req_paddr = 0;
  1487. dma_addr_t resp_paddr = 0;
  1488. struct bmi_xfer xfer = {};
  1489. void *treq, *tresp = NULL;
  1490. int ret = 0;
  1491. might_sleep();
  1492. if (resp && !resp_len)
  1493. return -EINVAL;
  1494. if (resp && resp_len && *resp_len == 0)
  1495. return -EINVAL;
  1496. treq = kmemdup(req, req_len, GFP_KERNEL);
  1497. if (!treq)
  1498. return -ENOMEM;
  1499. req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
  1500. ret = dma_mapping_error(ar->dev, req_paddr);
  1501. if (ret) {
  1502. ret = -EIO;
  1503. goto err_dma;
  1504. }
  1505. if (resp && resp_len) {
  1506. tresp = kzalloc(*resp_len, GFP_KERNEL);
  1507. if (!tresp) {
  1508. ret = -ENOMEM;
  1509. goto err_req;
  1510. }
  1511. resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
  1512. DMA_FROM_DEVICE);
  1513. ret = dma_mapping_error(ar->dev, resp_paddr);
  1514. if (ret) {
  1515. ret = -EIO;
  1516. goto err_req;
  1517. }
  1518. xfer.wait_for_resp = true;
  1519. xfer.resp_len = 0;
  1520. ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
  1521. }
  1522. ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
  1523. if (ret)
  1524. goto err_resp;
  1525. ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
  1526. if (ret) {
  1527. u32 unused_buffer;
  1528. unsigned int unused_nbytes;
  1529. unsigned int unused_id;
  1530. ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
  1531. &unused_nbytes, &unused_id);
  1532. } else {
  1533. /* non-zero means we did not time out */
  1534. ret = 0;
  1535. }
  1536. err_resp:
  1537. if (resp) {
  1538. u32 unused_buffer;
  1539. ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
  1540. dma_unmap_single(ar->dev, resp_paddr,
  1541. *resp_len, DMA_FROM_DEVICE);
  1542. }
  1543. err_req:
  1544. dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
  1545. if (ret == 0 && resp_len) {
  1546. *resp_len = min(*resp_len, xfer.resp_len);
  1547. memcpy(resp, tresp, xfer.resp_len);
  1548. }
  1549. err_dma:
  1550. kfree(treq);
  1551. kfree(tresp);
  1552. return ret;
  1553. }
  1554. static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
  1555. {
  1556. struct bmi_xfer *xfer;
  1557. if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
  1558. return;
  1559. xfer->tx_done = true;
  1560. }
  1561. static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
  1562. {
  1563. struct ath10k *ar = ce_state->ar;
  1564. struct bmi_xfer *xfer;
  1565. unsigned int nbytes;
  1566. if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer,
  1567. &nbytes))
  1568. return;
  1569. if (WARN_ON_ONCE(!xfer))
  1570. return;
  1571. if (!xfer->wait_for_resp) {
  1572. ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
  1573. return;
  1574. }
  1575. xfer->resp_len = nbytes;
  1576. xfer->rx_done = true;
  1577. }
  1578. static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
  1579. struct ath10k_ce_pipe *rx_pipe,
  1580. struct bmi_xfer *xfer)
  1581. {
  1582. unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
  1583. while (time_before_eq(jiffies, timeout)) {
  1584. ath10k_pci_bmi_send_done(tx_pipe);
  1585. ath10k_pci_bmi_recv_data(rx_pipe);
  1586. if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
  1587. return 0;
  1588. schedule();
  1589. }
  1590. return -ETIMEDOUT;
  1591. }
  1592. /*
  1593. * Send an interrupt to the device to wake up the Target CPU
  1594. * so it has an opportunity to notice any changed state.
  1595. */
  1596. static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
  1597. {
  1598. u32 addr, val;
  1599. addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
  1600. val = ath10k_pci_read32(ar, addr);
  1601. val |= CORE_CTRL_CPU_INTR_MASK;
  1602. ath10k_pci_write32(ar, addr, val);
  1603. return 0;
  1604. }
  1605. static int ath10k_pci_get_num_banks(struct ath10k *ar)
  1606. {
  1607. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1608. switch (ar_pci->pdev->device) {
  1609. case QCA988X_2_0_DEVICE_ID:
  1610. case QCA99X0_2_0_DEVICE_ID:
  1611. case QCA9888_2_0_DEVICE_ID:
  1612. case QCA9984_1_0_DEVICE_ID:
  1613. case QCA9887_1_0_DEVICE_ID:
  1614. return 1;
  1615. case QCA6164_2_1_DEVICE_ID:
  1616. case QCA6174_2_1_DEVICE_ID:
  1617. switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
  1618. case QCA6174_HW_1_0_CHIP_ID_REV:
  1619. case QCA6174_HW_1_1_CHIP_ID_REV:
  1620. case QCA6174_HW_2_1_CHIP_ID_REV:
  1621. case QCA6174_HW_2_2_CHIP_ID_REV:
  1622. return 3;
  1623. case QCA6174_HW_1_3_CHIP_ID_REV:
  1624. return 2;
  1625. case QCA6174_HW_3_0_CHIP_ID_REV:
  1626. case QCA6174_HW_3_1_CHIP_ID_REV:
  1627. case QCA6174_HW_3_2_CHIP_ID_REV:
  1628. return 9;
  1629. }
  1630. break;
  1631. case QCA9377_1_0_DEVICE_ID:
  1632. return 2;
  1633. }
  1634. ath10k_warn(ar, "unknown number of banks, assuming 1\n");
  1635. return 1;
  1636. }
  1637. static int ath10k_bus_get_num_banks(struct ath10k *ar)
  1638. {
  1639. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1640. return ar_pci->bus_ops->get_num_banks(ar);
  1641. }
  1642. int ath10k_pci_init_config(struct ath10k *ar)
  1643. {
  1644. u32 interconnect_targ_addr;
  1645. u32 pcie_state_targ_addr = 0;
  1646. u32 pipe_cfg_targ_addr = 0;
  1647. u32 svc_to_pipe_map = 0;
  1648. u32 pcie_config_flags = 0;
  1649. u32 ealloc_value;
  1650. u32 ealloc_targ_addr;
  1651. u32 flag2_value;
  1652. u32 flag2_targ_addr;
  1653. int ret = 0;
  1654. /* Download to Target the CE Config and the service-to-CE map */
  1655. interconnect_targ_addr =
  1656. host_interest_item_address(HI_ITEM(hi_interconnect_state));
  1657. /* Supply Target-side CE configuration */
  1658. ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
  1659. &pcie_state_targ_addr);
  1660. if (ret != 0) {
  1661. ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
  1662. return ret;
  1663. }
  1664. if (pcie_state_targ_addr == 0) {
  1665. ret = -EIO;
  1666. ath10k_err(ar, "Invalid pcie state addr\n");
  1667. return ret;
  1668. }
  1669. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1670. offsetof(struct pcie_state,
  1671. pipe_cfg_addr)),
  1672. &pipe_cfg_targ_addr);
  1673. if (ret != 0) {
  1674. ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
  1675. return ret;
  1676. }
  1677. if (pipe_cfg_targ_addr == 0) {
  1678. ret = -EIO;
  1679. ath10k_err(ar, "Invalid pipe cfg addr\n");
  1680. return ret;
  1681. }
  1682. ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
  1683. target_ce_config_wlan,
  1684. sizeof(struct ce_pipe_config) *
  1685. NUM_TARGET_CE_CONFIG_WLAN);
  1686. if (ret != 0) {
  1687. ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
  1688. return ret;
  1689. }
  1690. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1691. offsetof(struct pcie_state,
  1692. svc_to_pipe_map)),
  1693. &svc_to_pipe_map);
  1694. if (ret != 0) {
  1695. ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
  1696. return ret;
  1697. }
  1698. if (svc_to_pipe_map == 0) {
  1699. ret = -EIO;
  1700. ath10k_err(ar, "Invalid svc_to_pipe map\n");
  1701. return ret;
  1702. }
  1703. ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
  1704. target_service_to_ce_map_wlan,
  1705. sizeof(target_service_to_ce_map_wlan));
  1706. if (ret != 0) {
  1707. ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
  1708. return ret;
  1709. }
  1710. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1711. offsetof(struct pcie_state,
  1712. config_flags)),
  1713. &pcie_config_flags);
  1714. if (ret != 0) {
  1715. ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
  1716. return ret;
  1717. }
  1718. pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
  1719. ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
  1720. offsetof(struct pcie_state,
  1721. config_flags)),
  1722. pcie_config_flags);
  1723. if (ret != 0) {
  1724. ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
  1725. return ret;
  1726. }
  1727. /* configure early allocation */
  1728. ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
  1729. ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
  1730. if (ret != 0) {
  1731. ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
  1732. return ret;
  1733. }
  1734. /* first bank is switched to IRAM */
  1735. ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
  1736. HI_EARLY_ALLOC_MAGIC_MASK);
  1737. ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
  1738. HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
  1739. HI_EARLY_ALLOC_IRAM_BANKS_MASK);
  1740. ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
  1741. if (ret != 0) {
  1742. ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
  1743. return ret;
  1744. }
  1745. /* Tell Target to proceed with initialization */
  1746. flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
  1747. ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
  1748. if (ret != 0) {
  1749. ath10k_err(ar, "Failed to get option val: %d\n", ret);
  1750. return ret;
  1751. }
  1752. flag2_value |= HI_OPTION_EARLY_CFG_DONE;
  1753. ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
  1754. if (ret != 0) {
  1755. ath10k_err(ar, "Failed to set option val: %d\n", ret);
  1756. return ret;
  1757. }
  1758. return 0;
  1759. }
  1760. static void ath10k_pci_override_ce_config(struct ath10k *ar)
  1761. {
  1762. struct ce_attr *attr;
  1763. struct ce_pipe_config *config;
  1764. /* For QCA6174 we're overriding the Copy Engine 5 configuration,
  1765. * since it is currently used for other feature.
  1766. */
  1767. /* Override Host's Copy Engine 5 configuration */
  1768. attr = &host_ce_config_wlan[5];
  1769. attr->src_sz_max = 0;
  1770. attr->dest_nentries = 0;
  1771. /* Override Target firmware's Copy Engine configuration */
  1772. config = &target_ce_config_wlan[5];
  1773. config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
  1774. config->nbytes_max = __cpu_to_le32(2048);
  1775. /* Map from service/endpoint to Copy Engine */
  1776. target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
  1777. }
  1778. int ath10k_pci_alloc_pipes(struct ath10k *ar)
  1779. {
  1780. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1781. struct ath10k_pci_pipe *pipe;
  1782. int i, ret;
  1783. for (i = 0; i < CE_COUNT; i++) {
  1784. pipe = &ar_pci->pipe_info[i];
  1785. pipe->ce_hdl = &ar_pci->ce_states[i];
  1786. pipe->pipe_num = i;
  1787. pipe->hif_ce_state = ar;
  1788. ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
  1789. if (ret) {
  1790. ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
  1791. i, ret);
  1792. return ret;
  1793. }
  1794. /* Last CE is Diagnostic Window */
  1795. if (i == CE_DIAG_PIPE) {
  1796. ar_pci->ce_diag = pipe->ce_hdl;
  1797. continue;
  1798. }
  1799. pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
  1800. }
  1801. return 0;
  1802. }
  1803. void ath10k_pci_free_pipes(struct ath10k *ar)
  1804. {
  1805. int i;
  1806. for (i = 0; i < CE_COUNT; i++)
  1807. ath10k_ce_free_pipe(ar, i);
  1808. }
  1809. int ath10k_pci_init_pipes(struct ath10k *ar)
  1810. {
  1811. int i, ret;
  1812. for (i = 0; i < CE_COUNT; i++) {
  1813. ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
  1814. if (ret) {
  1815. ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
  1816. i, ret);
  1817. return ret;
  1818. }
  1819. }
  1820. return 0;
  1821. }
  1822. static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
  1823. {
  1824. return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
  1825. FW_IND_EVENT_PENDING;
  1826. }
  1827. static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
  1828. {
  1829. u32 val;
  1830. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  1831. val &= ~FW_IND_EVENT_PENDING;
  1832. ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
  1833. }
  1834. static bool ath10k_pci_has_device_gone(struct ath10k *ar)
  1835. {
  1836. u32 val;
  1837. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  1838. return (val == 0xffffffff);
  1839. }
  1840. /* this function effectively clears target memory controller assert line */
  1841. static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
  1842. {
  1843. u32 val;
  1844. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1845. ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
  1846. val | SOC_RESET_CONTROL_SI0_RST_MASK);
  1847. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1848. msleep(10);
  1849. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1850. ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
  1851. val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
  1852. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1853. msleep(10);
  1854. }
  1855. static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
  1856. {
  1857. u32 val;
  1858. ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
  1859. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1860. SOC_RESET_CONTROL_ADDRESS);
  1861. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1862. val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
  1863. }
  1864. static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
  1865. {
  1866. u32 val;
  1867. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1868. SOC_RESET_CONTROL_ADDRESS);
  1869. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1870. val | SOC_RESET_CONTROL_CE_RST_MASK);
  1871. msleep(10);
  1872. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1873. val & ~SOC_RESET_CONTROL_CE_RST_MASK);
  1874. }
  1875. static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
  1876. {
  1877. u32 val;
  1878. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1879. SOC_LF_TIMER_CONTROL0_ADDRESS);
  1880. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
  1881. SOC_LF_TIMER_CONTROL0_ADDRESS,
  1882. val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
  1883. }
  1884. static int ath10k_pci_warm_reset(struct ath10k *ar)
  1885. {
  1886. int ret;
  1887. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
  1888. spin_lock_bh(&ar->data_lock);
  1889. ar->stats.fw_warm_reset_counter++;
  1890. spin_unlock_bh(&ar->data_lock);
  1891. ath10k_pci_irq_disable(ar);
  1892. /* Make sure the target CPU is not doing anything dangerous, e.g. if it
  1893. * were to access copy engine while host performs copy engine reset
  1894. * then it is possible for the device to confuse pci-e controller to
  1895. * the point of bringing host system to a complete stop (i.e. hang).
  1896. */
  1897. ath10k_pci_warm_reset_si0(ar);
  1898. ath10k_pci_warm_reset_cpu(ar);
  1899. ath10k_pci_init_pipes(ar);
  1900. ath10k_pci_wait_for_target_init(ar);
  1901. ath10k_pci_warm_reset_clear_lf(ar);
  1902. ath10k_pci_warm_reset_ce(ar);
  1903. ath10k_pci_warm_reset_cpu(ar);
  1904. ath10k_pci_init_pipes(ar);
  1905. ret = ath10k_pci_wait_for_target_init(ar);
  1906. if (ret) {
  1907. ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
  1908. return ret;
  1909. }
  1910. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
  1911. return 0;
  1912. }
  1913. static int ath10k_pci_qca99x0_soft_chip_reset(struct ath10k *ar)
  1914. {
  1915. ath10k_pci_irq_disable(ar);
  1916. return ath10k_pci_qca99x0_chip_reset(ar);
  1917. }
  1918. static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
  1919. {
  1920. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1921. if (!ar_pci->pci_soft_reset)
  1922. return -ENOTSUPP;
  1923. return ar_pci->pci_soft_reset(ar);
  1924. }
  1925. static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
  1926. {
  1927. int i, ret;
  1928. u32 val;
  1929. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
  1930. /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
  1931. * It is thus preferred to use warm reset which is safer but may not be
  1932. * able to recover the device from all possible fail scenarios.
  1933. *
  1934. * Warm reset doesn't always work on first try so attempt it a few
  1935. * times before giving up.
  1936. */
  1937. for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
  1938. ret = ath10k_pci_warm_reset(ar);
  1939. if (ret) {
  1940. ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
  1941. i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
  1942. ret);
  1943. continue;
  1944. }
  1945. /* FIXME: Sometimes copy engine doesn't recover after warm
  1946. * reset. In most cases this needs cold reset. In some of these
  1947. * cases the device is in such a state that a cold reset may
  1948. * lock up the host.
  1949. *
  1950. * Reading any host interest register via copy engine is
  1951. * sufficient to verify if device is capable of booting
  1952. * firmware blob.
  1953. */
  1954. ret = ath10k_pci_init_pipes(ar);
  1955. if (ret) {
  1956. ath10k_warn(ar, "failed to init copy engine: %d\n",
  1957. ret);
  1958. continue;
  1959. }
  1960. ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
  1961. &val);
  1962. if (ret) {
  1963. ath10k_warn(ar, "failed to poke copy engine: %d\n",
  1964. ret);
  1965. continue;
  1966. }
  1967. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
  1968. return 0;
  1969. }
  1970. if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
  1971. ath10k_warn(ar, "refusing cold reset as requested\n");
  1972. return -EPERM;
  1973. }
  1974. ret = ath10k_pci_cold_reset(ar);
  1975. if (ret) {
  1976. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  1977. return ret;
  1978. }
  1979. ret = ath10k_pci_wait_for_target_init(ar);
  1980. if (ret) {
  1981. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  1982. ret);
  1983. return ret;
  1984. }
  1985. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
  1986. return 0;
  1987. }
  1988. static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
  1989. {
  1990. int ret;
  1991. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
  1992. /* FIXME: QCA6174 requires cold + warm reset to work. */
  1993. ret = ath10k_pci_cold_reset(ar);
  1994. if (ret) {
  1995. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  1996. return ret;
  1997. }
  1998. ret = ath10k_pci_wait_for_target_init(ar);
  1999. if (ret) {
  2000. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  2001. ret);
  2002. return ret;
  2003. }
  2004. ret = ath10k_pci_warm_reset(ar);
  2005. if (ret) {
  2006. ath10k_warn(ar, "failed to warm reset: %d\n", ret);
  2007. return ret;
  2008. }
  2009. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
  2010. return 0;
  2011. }
  2012. static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
  2013. {
  2014. int ret;
  2015. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
  2016. ret = ath10k_pci_cold_reset(ar);
  2017. if (ret) {
  2018. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  2019. return ret;
  2020. }
  2021. ret = ath10k_pci_wait_for_target_init(ar);
  2022. if (ret) {
  2023. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  2024. ret);
  2025. return ret;
  2026. }
  2027. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
  2028. return 0;
  2029. }
  2030. static int ath10k_pci_chip_reset(struct ath10k *ar)
  2031. {
  2032. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2033. if (WARN_ON(!ar_pci->pci_hard_reset))
  2034. return -ENOTSUPP;
  2035. return ar_pci->pci_hard_reset(ar);
  2036. }
  2037. static int ath10k_pci_hif_power_up(struct ath10k *ar)
  2038. {
  2039. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2040. int ret;
  2041. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
  2042. pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  2043. &ar_pci->link_ctl);
  2044. pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  2045. ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
  2046. /*
  2047. * Bring the target up cleanly.
  2048. *
  2049. * The target may be in an undefined state with an AUX-powered Target
  2050. * and a Host in WoW mode. If the Host crashes, loses power, or is
  2051. * restarted (without unloading the driver) then the Target is left
  2052. * (aux) powered and running. On a subsequent driver load, the Target
  2053. * is in an unexpected state. We try to catch that here in order to
  2054. * reset the Target and retry the probe.
  2055. */
  2056. ret = ath10k_pci_chip_reset(ar);
  2057. if (ret) {
  2058. if (ath10k_pci_has_fw_crashed(ar)) {
  2059. ath10k_warn(ar, "firmware crashed during chip reset\n");
  2060. ath10k_pci_fw_crashed_clear(ar);
  2061. ath10k_pci_fw_crashed_dump(ar);
  2062. }
  2063. ath10k_err(ar, "failed to reset chip: %d\n", ret);
  2064. goto err_sleep;
  2065. }
  2066. ret = ath10k_pci_init_pipes(ar);
  2067. if (ret) {
  2068. ath10k_err(ar, "failed to initialize CE: %d\n", ret);
  2069. goto err_sleep;
  2070. }
  2071. ret = ath10k_pci_init_config(ar);
  2072. if (ret) {
  2073. ath10k_err(ar, "failed to setup init config: %d\n", ret);
  2074. goto err_ce;
  2075. }
  2076. ret = ath10k_pci_wake_target_cpu(ar);
  2077. if (ret) {
  2078. ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
  2079. goto err_ce;
  2080. }
  2081. return 0;
  2082. err_ce:
  2083. ath10k_pci_ce_deinit(ar);
  2084. err_sleep:
  2085. return ret;
  2086. }
  2087. void ath10k_pci_hif_power_down(struct ath10k *ar)
  2088. {
  2089. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
  2090. /* Currently hif_power_up performs effectively a reset and hif_stop
  2091. * resets the chip as well so there's no point in resetting here.
  2092. */
  2093. }
  2094. #ifdef CONFIG_PM
  2095. static int ath10k_pci_hif_suspend(struct ath10k *ar)
  2096. {
  2097. /* The grace timer can still be counting down and ar->ps_awake be true.
  2098. * It is known that the device may be asleep after resuming regardless
  2099. * of the SoC powersave state before suspending. Hence make sure the
  2100. * device is asleep before proceeding.
  2101. */
  2102. ath10k_pci_sleep_sync(ar);
  2103. return 0;
  2104. }
  2105. static int ath10k_pci_hif_resume(struct ath10k *ar)
  2106. {
  2107. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2108. struct pci_dev *pdev = ar_pci->pdev;
  2109. u32 val;
  2110. int ret = 0;
  2111. ret = ath10k_pci_force_wake(ar);
  2112. if (ret) {
  2113. ath10k_err(ar, "failed to wake up target: %d\n", ret);
  2114. return ret;
  2115. }
  2116. /* Suspend/Resume resets the PCI configuration space, so we have to
  2117. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  2118. * from interfering with C3 CPU state. pci_restore_state won't help
  2119. * here since it only restores the first 64 bytes pci config header.
  2120. */
  2121. pci_read_config_dword(pdev, 0x40, &val);
  2122. if ((val & 0x0000ff00) != 0)
  2123. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  2124. return ret;
  2125. }
  2126. #endif
  2127. static bool ath10k_pci_validate_cal(void *data, size_t size)
  2128. {
  2129. __le16 *cal_words = data;
  2130. u16 checksum = 0;
  2131. size_t i;
  2132. if (size % 2 != 0)
  2133. return false;
  2134. for (i = 0; i < size / 2; i++)
  2135. checksum ^= le16_to_cpu(cal_words[i]);
  2136. return checksum == 0xffff;
  2137. }
  2138. static void ath10k_pci_enable_eeprom(struct ath10k *ar)
  2139. {
  2140. /* Enable SI clock */
  2141. ath10k_pci_soc_write32(ar, CLOCK_CONTROL_OFFSET, 0x0);
  2142. /* Configure GPIOs for I2C operation */
  2143. ath10k_pci_write32(ar,
  2144. GPIO_BASE_ADDRESS + GPIO_PIN0_OFFSET +
  2145. 4 * QCA9887_1_0_I2C_SDA_GPIO_PIN,
  2146. SM(QCA9887_1_0_I2C_SDA_PIN_CONFIG,
  2147. GPIO_PIN0_CONFIG) |
  2148. SM(1, GPIO_PIN0_PAD_PULL));
  2149. ath10k_pci_write32(ar,
  2150. GPIO_BASE_ADDRESS + GPIO_PIN0_OFFSET +
  2151. 4 * QCA9887_1_0_SI_CLK_GPIO_PIN,
  2152. SM(QCA9887_1_0_SI_CLK_PIN_CONFIG, GPIO_PIN0_CONFIG) |
  2153. SM(1, GPIO_PIN0_PAD_PULL));
  2154. ath10k_pci_write32(ar,
  2155. GPIO_BASE_ADDRESS +
  2156. QCA9887_1_0_GPIO_ENABLE_W1TS_LOW_ADDRESS,
  2157. 1u << QCA9887_1_0_SI_CLK_GPIO_PIN);
  2158. /* In Swift ASIC - EEPROM clock will be (110MHz/512) = 214KHz */
  2159. ath10k_pci_write32(ar,
  2160. SI_BASE_ADDRESS + SI_CONFIG_OFFSET,
  2161. SM(1, SI_CONFIG_ERR_INT) |
  2162. SM(1, SI_CONFIG_BIDIR_OD_DATA) |
  2163. SM(1, SI_CONFIG_I2C) |
  2164. SM(1, SI_CONFIG_POS_SAMPLE) |
  2165. SM(1, SI_CONFIG_INACTIVE_DATA) |
  2166. SM(1, SI_CONFIG_INACTIVE_CLK) |
  2167. SM(8, SI_CONFIG_DIVIDER));
  2168. }
  2169. static int ath10k_pci_read_eeprom(struct ath10k *ar, u16 addr, u8 *out)
  2170. {
  2171. u32 reg;
  2172. int wait_limit;
  2173. /* set device select byte and for the read operation */
  2174. reg = QCA9887_EEPROM_SELECT_READ |
  2175. SM(addr, QCA9887_EEPROM_ADDR_LO) |
  2176. SM(addr >> 8, QCA9887_EEPROM_ADDR_HI);
  2177. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_TX_DATA0_OFFSET, reg);
  2178. /* write transmit data, transfer length, and START bit */
  2179. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET,
  2180. SM(1, SI_CS_START) | SM(1, SI_CS_RX_CNT) |
  2181. SM(4, SI_CS_TX_CNT));
  2182. /* wait max 1 sec */
  2183. wait_limit = 100000;
  2184. /* wait for SI_CS_DONE_INT */
  2185. do {
  2186. reg = ath10k_pci_read32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET);
  2187. if (MS(reg, SI_CS_DONE_INT))
  2188. break;
  2189. wait_limit--;
  2190. udelay(10);
  2191. } while (wait_limit > 0);
  2192. if (!MS(reg, SI_CS_DONE_INT)) {
  2193. ath10k_err(ar, "timeout while reading device EEPROM at %04x\n",
  2194. addr);
  2195. return -ETIMEDOUT;
  2196. }
  2197. /* clear SI_CS_DONE_INT */
  2198. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET, reg);
  2199. if (MS(reg, SI_CS_DONE_ERR)) {
  2200. ath10k_err(ar, "failed to read device EEPROM at %04x\n", addr);
  2201. return -EIO;
  2202. }
  2203. /* extract receive data */
  2204. reg = ath10k_pci_read32(ar, SI_BASE_ADDRESS + SI_RX_DATA0_OFFSET);
  2205. *out = reg;
  2206. return 0;
  2207. }
  2208. static int ath10k_pci_hif_fetch_cal_eeprom(struct ath10k *ar, void **data,
  2209. size_t *data_len)
  2210. {
  2211. u8 *caldata = NULL;
  2212. size_t calsize, i;
  2213. int ret;
  2214. if (!QCA_REV_9887(ar))
  2215. return -EOPNOTSUPP;
  2216. calsize = ar->hw_params.cal_data_len;
  2217. caldata = kmalloc(calsize, GFP_KERNEL);
  2218. if (!caldata)
  2219. return -ENOMEM;
  2220. ath10k_pci_enable_eeprom(ar);
  2221. for (i = 0; i < calsize; i++) {
  2222. ret = ath10k_pci_read_eeprom(ar, i, &caldata[i]);
  2223. if (ret)
  2224. goto err_free;
  2225. }
  2226. if (!ath10k_pci_validate_cal(caldata, calsize))
  2227. goto err_free;
  2228. *data = caldata;
  2229. *data_len = calsize;
  2230. return 0;
  2231. err_free:
  2232. kfree(data);
  2233. return -EINVAL;
  2234. }
  2235. static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
  2236. .tx_sg = ath10k_pci_hif_tx_sg,
  2237. .diag_read = ath10k_pci_hif_diag_read,
  2238. .diag_write = ath10k_pci_diag_write_mem,
  2239. .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
  2240. .start = ath10k_pci_hif_start,
  2241. .stop = ath10k_pci_hif_stop,
  2242. .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
  2243. .get_default_pipe = ath10k_pci_hif_get_default_pipe,
  2244. .send_complete_check = ath10k_pci_hif_send_complete_check,
  2245. .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
  2246. .power_up = ath10k_pci_hif_power_up,
  2247. .power_down = ath10k_pci_hif_power_down,
  2248. .read32 = ath10k_pci_read32,
  2249. .write32 = ath10k_pci_write32,
  2250. #ifdef CONFIG_PM
  2251. .suspend = ath10k_pci_hif_suspend,
  2252. .resume = ath10k_pci_hif_resume,
  2253. #endif
  2254. .fetch_cal_eeprom = ath10k_pci_hif_fetch_cal_eeprom,
  2255. };
  2256. /*
  2257. * Top-level interrupt handler for all PCI interrupts from a Target.
  2258. * When a block of MSI interrupts is allocated, this top-level handler
  2259. * is not used; instead, we directly call the correct sub-handler.
  2260. */
  2261. static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
  2262. {
  2263. struct ath10k *ar = arg;
  2264. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2265. int ret;
  2266. if (ath10k_pci_has_device_gone(ar))
  2267. return IRQ_NONE;
  2268. ret = ath10k_pci_force_wake(ar);
  2269. if (ret) {
  2270. ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
  2271. return IRQ_NONE;
  2272. }
  2273. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY) {
  2274. if (!ath10k_pci_irq_pending(ar))
  2275. return IRQ_NONE;
  2276. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2277. }
  2278. tasklet_schedule(&ar_pci->intr_tq);
  2279. return IRQ_HANDLED;
  2280. }
  2281. static void ath10k_pci_tasklet(unsigned long data)
  2282. {
  2283. struct ath10k *ar = (struct ath10k *)data;
  2284. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2285. if (ath10k_pci_has_fw_crashed(ar)) {
  2286. ath10k_pci_irq_disable(ar);
  2287. ath10k_pci_fw_crashed_clear(ar);
  2288. ath10k_pci_fw_crashed_dump(ar);
  2289. return;
  2290. }
  2291. ath10k_ce_per_engine_service_any(ar);
  2292. /* Re-enable legacy irq that was disabled in the irq handler */
  2293. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
  2294. ath10k_pci_enable_legacy_irq(ar);
  2295. }
  2296. static int ath10k_pci_request_irq_msi(struct ath10k *ar)
  2297. {
  2298. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2299. int ret;
  2300. ret = request_irq(ar_pci->pdev->irq,
  2301. ath10k_pci_interrupt_handler,
  2302. IRQF_SHARED, "ath10k_pci", ar);
  2303. if (ret) {
  2304. ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
  2305. ar_pci->pdev->irq, ret);
  2306. return ret;
  2307. }
  2308. return 0;
  2309. }
  2310. static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
  2311. {
  2312. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2313. int ret;
  2314. ret = request_irq(ar_pci->pdev->irq,
  2315. ath10k_pci_interrupt_handler,
  2316. IRQF_SHARED, "ath10k_pci", ar);
  2317. if (ret) {
  2318. ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
  2319. ar_pci->pdev->irq, ret);
  2320. return ret;
  2321. }
  2322. return 0;
  2323. }
  2324. static int ath10k_pci_request_irq(struct ath10k *ar)
  2325. {
  2326. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2327. switch (ar_pci->oper_irq_mode) {
  2328. case ATH10K_PCI_IRQ_LEGACY:
  2329. return ath10k_pci_request_irq_legacy(ar);
  2330. case ATH10K_PCI_IRQ_MSI:
  2331. return ath10k_pci_request_irq_msi(ar);
  2332. default:
  2333. return -EINVAL;
  2334. }
  2335. }
  2336. static void ath10k_pci_free_irq(struct ath10k *ar)
  2337. {
  2338. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2339. free_irq(ar_pci->pdev->irq, ar);
  2340. }
  2341. void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
  2342. {
  2343. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2344. tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
  2345. }
  2346. static int ath10k_pci_init_irq(struct ath10k *ar)
  2347. {
  2348. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2349. int ret;
  2350. ath10k_pci_init_irq_tasklets(ar);
  2351. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
  2352. ath10k_info(ar, "limiting irq mode to: %d\n",
  2353. ath10k_pci_irq_mode);
  2354. /* Try MSI */
  2355. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
  2356. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_MSI;
  2357. ret = pci_enable_msi(ar_pci->pdev);
  2358. if (ret == 0)
  2359. return 0;
  2360. /* fall-through */
  2361. }
  2362. /* Try legacy irq
  2363. *
  2364. * A potential race occurs here: The CORE_BASE write
  2365. * depends on target correctly decoding AXI address but
  2366. * host won't know when target writes BAR to CORE_CTRL.
  2367. * This write might get lost if target has NOT written BAR.
  2368. * For now, fix the race by repeating the write in below
  2369. * synchronization checking. */
  2370. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_LEGACY;
  2371. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2372. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  2373. return 0;
  2374. }
  2375. static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
  2376. {
  2377. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2378. 0);
  2379. }
  2380. static int ath10k_pci_deinit_irq(struct ath10k *ar)
  2381. {
  2382. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2383. switch (ar_pci->oper_irq_mode) {
  2384. case ATH10K_PCI_IRQ_LEGACY:
  2385. ath10k_pci_deinit_irq_legacy(ar);
  2386. break;
  2387. default:
  2388. pci_disable_msi(ar_pci->pdev);
  2389. break;
  2390. }
  2391. return 0;
  2392. }
  2393. int ath10k_pci_wait_for_target_init(struct ath10k *ar)
  2394. {
  2395. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2396. unsigned long timeout;
  2397. u32 val;
  2398. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
  2399. timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
  2400. do {
  2401. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  2402. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
  2403. val);
  2404. /* target should never return this */
  2405. if (val == 0xffffffff)
  2406. continue;
  2407. /* the device has crashed so don't bother trying anymore */
  2408. if (val & FW_IND_EVENT_PENDING)
  2409. break;
  2410. if (val & FW_IND_INITIALIZED)
  2411. break;
  2412. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
  2413. /* Fix potential race by repeating CORE_BASE writes */
  2414. ath10k_pci_enable_legacy_irq(ar);
  2415. mdelay(10);
  2416. } while (time_before(jiffies, timeout));
  2417. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2418. ath10k_pci_irq_msi_fw_mask(ar);
  2419. if (val == 0xffffffff) {
  2420. ath10k_err(ar, "failed to read device register, device is gone\n");
  2421. return -EIO;
  2422. }
  2423. if (val & FW_IND_EVENT_PENDING) {
  2424. ath10k_warn(ar, "device has crashed during init\n");
  2425. return -ECOMM;
  2426. }
  2427. if (!(val & FW_IND_INITIALIZED)) {
  2428. ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
  2429. val);
  2430. return -ETIMEDOUT;
  2431. }
  2432. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
  2433. return 0;
  2434. }
  2435. static int ath10k_pci_cold_reset(struct ath10k *ar)
  2436. {
  2437. u32 val;
  2438. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
  2439. spin_lock_bh(&ar->data_lock);
  2440. ar->stats.fw_cold_reset_counter++;
  2441. spin_unlock_bh(&ar->data_lock);
  2442. /* Put Target, including PCIe, into RESET. */
  2443. val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
  2444. val |= 1;
  2445. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2446. /* After writing into SOC_GLOBAL_RESET to put device into
  2447. * reset and pulling out of reset pcie may not be stable
  2448. * for any immediate pcie register access and cause bus error,
  2449. * add delay before any pcie access request to fix this issue.
  2450. */
  2451. msleep(20);
  2452. /* Pull Target, including PCIe, out of RESET. */
  2453. val &= ~1;
  2454. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2455. msleep(20);
  2456. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
  2457. return 0;
  2458. }
  2459. static int ath10k_pci_claim(struct ath10k *ar)
  2460. {
  2461. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2462. struct pci_dev *pdev = ar_pci->pdev;
  2463. int ret;
  2464. pci_set_drvdata(pdev, ar);
  2465. ret = pci_enable_device(pdev);
  2466. if (ret) {
  2467. ath10k_err(ar, "failed to enable pci device: %d\n", ret);
  2468. return ret;
  2469. }
  2470. ret = pci_request_region(pdev, BAR_NUM, "ath");
  2471. if (ret) {
  2472. ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
  2473. ret);
  2474. goto err_device;
  2475. }
  2476. /* Target expects 32 bit DMA. Enforce it. */
  2477. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2478. if (ret) {
  2479. ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
  2480. goto err_region;
  2481. }
  2482. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  2483. if (ret) {
  2484. ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
  2485. ret);
  2486. goto err_region;
  2487. }
  2488. pci_set_master(pdev);
  2489. /* Arrange for access to Target SoC registers. */
  2490. ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
  2491. ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
  2492. if (!ar_pci->mem) {
  2493. ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
  2494. ret = -EIO;
  2495. goto err_master;
  2496. }
  2497. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
  2498. return 0;
  2499. err_master:
  2500. pci_clear_master(pdev);
  2501. err_region:
  2502. pci_release_region(pdev, BAR_NUM);
  2503. err_device:
  2504. pci_disable_device(pdev);
  2505. return ret;
  2506. }
  2507. static void ath10k_pci_release(struct ath10k *ar)
  2508. {
  2509. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2510. struct pci_dev *pdev = ar_pci->pdev;
  2511. pci_iounmap(pdev, ar_pci->mem);
  2512. pci_release_region(pdev, BAR_NUM);
  2513. pci_clear_master(pdev);
  2514. pci_disable_device(pdev);
  2515. }
  2516. static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
  2517. {
  2518. const struct ath10k_pci_supp_chip *supp_chip;
  2519. int i;
  2520. u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
  2521. for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
  2522. supp_chip = &ath10k_pci_supp_chips[i];
  2523. if (supp_chip->dev_id == dev_id &&
  2524. supp_chip->rev_id == rev_id)
  2525. return true;
  2526. }
  2527. return false;
  2528. }
  2529. int ath10k_pci_setup_resource(struct ath10k *ar)
  2530. {
  2531. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2532. int ret;
  2533. spin_lock_init(&ar_pci->ce_lock);
  2534. spin_lock_init(&ar_pci->ps_lock);
  2535. setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
  2536. (unsigned long)ar);
  2537. if (QCA_REV_6174(ar))
  2538. ath10k_pci_override_ce_config(ar);
  2539. ret = ath10k_pci_alloc_pipes(ar);
  2540. if (ret) {
  2541. ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
  2542. ret);
  2543. return ret;
  2544. }
  2545. return 0;
  2546. }
  2547. void ath10k_pci_release_resource(struct ath10k *ar)
  2548. {
  2549. ath10k_pci_kill_tasklet(ar);
  2550. ath10k_pci_ce_deinit(ar);
  2551. ath10k_pci_free_pipes(ar);
  2552. }
  2553. static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
  2554. .read32 = ath10k_bus_pci_read32,
  2555. .write32 = ath10k_bus_pci_write32,
  2556. .get_num_banks = ath10k_pci_get_num_banks,
  2557. };
  2558. static int ath10k_pci_probe(struct pci_dev *pdev,
  2559. const struct pci_device_id *pci_dev)
  2560. {
  2561. int ret = 0;
  2562. struct ath10k *ar;
  2563. struct ath10k_pci *ar_pci;
  2564. enum ath10k_hw_rev hw_rev;
  2565. u32 chip_id;
  2566. bool pci_ps;
  2567. int (*pci_soft_reset)(struct ath10k *ar);
  2568. int (*pci_hard_reset)(struct ath10k *ar);
  2569. switch (pci_dev->device) {
  2570. case QCA988X_2_0_DEVICE_ID:
  2571. hw_rev = ATH10K_HW_QCA988X;
  2572. pci_ps = false;
  2573. pci_soft_reset = ath10k_pci_warm_reset;
  2574. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2575. break;
  2576. case QCA9887_1_0_DEVICE_ID:
  2577. dev_warn(&pdev->dev, "QCA9887 support is still experimental, there are likely bugs. You have been warned.\n");
  2578. hw_rev = ATH10K_HW_QCA9887;
  2579. pci_ps = false;
  2580. pci_soft_reset = ath10k_pci_warm_reset;
  2581. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2582. break;
  2583. case QCA6164_2_1_DEVICE_ID:
  2584. case QCA6174_2_1_DEVICE_ID:
  2585. hw_rev = ATH10K_HW_QCA6174;
  2586. pci_ps = true;
  2587. pci_soft_reset = ath10k_pci_warm_reset;
  2588. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2589. break;
  2590. case QCA99X0_2_0_DEVICE_ID:
  2591. hw_rev = ATH10K_HW_QCA99X0;
  2592. pci_ps = false;
  2593. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2594. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2595. break;
  2596. case QCA9984_1_0_DEVICE_ID:
  2597. hw_rev = ATH10K_HW_QCA9984;
  2598. pci_ps = false;
  2599. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2600. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2601. break;
  2602. case QCA9888_2_0_DEVICE_ID:
  2603. hw_rev = ATH10K_HW_QCA9888;
  2604. pci_ps = false;
  2605. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2606. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2607. break;
  2608. case QCA9377_1_0_DEVICE_ID:
  2609. hw_rev = ATH10K_HW_QCA9377;
  2610. pci_ps = true;
  2611. pci_soft_reset = NULL;
  2612. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2613. break;
  2614. default:
  2615. WARN_ON(1);
  2616. return -ENOTSUPP;
  2617. }
  2618. ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
  2619. hw_rev, &ath10k_pci_hif_ops);
  2620. if (!ar) {
  2621. dev_err(&pdev->dev, "failed to allocate core\n");
  2622. return -ENOMEM;
  2623. }
  2624. ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
  2625. pdev->vendor, pdev->device,
  2626. pdev->subsystem_vendor, pdev->subsystem_device);
  2627. ar_pci = ath10k_pci_priv(ar);
  2628. ar_pci->pdev = pdev;
  2629. ar_pci->dev = &pdev->dev;
  2630. ar_pci->ar = ar;
  2631. ar->dev_id = pci_dev->device;
  2632. ar_pci->pci_ps = pci_ps;
  2633. ar_pci->bus_ops = &ath10k_pci_bus_ops;
  2634. ar_pci->pci_soft_reset = pci_soft_reset;
  2635. ar_pci->pci_hard_reset = pci_hard_reset;
  2636. ar->id.vendor = pdev->vendor;
  2637. ar->id.device = pdev->device;
  2638. ar->id.subsystem_vendor = pdev->subsystem_vendor;
  2639. ar->id.subsystem_device = pdev->subsystem_device;
  2640. setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
  2641. (unsigned long)ar);
  2642. ret = ath10k_pci_setup_resource(ar);
  2643. if (ret) {
  2644. ath10k_err(ar, "failed to setup resource: %d\n", ret);
  2645. goto err_core_destroy;
  2646. }
  2647. ret = ath10k_pci_claim(ar);
  2648. if (ret) {
  2649. ath10k_err(ar, "failed to claim device: %d\n", ret);
  2650. goto err_free_pipes;
  2651. }
  2652. ret = ath10k_pci_force_wake(ar);
  2653. if (ret) {
  2654. ath10k_warn(ar, "failed to wake up device : %d\n", ret);
  2655. goto err_sleep;
  2656. }
  2657. ath10k_pci_ce_deinit(ar);
  2658. ath10k_pci_irq_disable(ar);
  2659. ret = ath10k_pci_init_irq(ar);
  2660. if (ret) {
  2661. ath10k_err(ar, "failed to init irqs: %d\n", ret);
  2662. goto err_sleep;
  2663. }
  2664. ath10k_info(ar, "pci irq %s oper_irq_mode %d irq_mode %d reset_mode %d\n",
  2665. ath10k_pci_get_irq_method(ar), ar_pci->oper_irq_mode,
  2666. ath10k_pci_irq_mode, ath10k_pci_reset_mode);
  2667. ret = ath10k_pci_request_irq(ar);
  2668. if (ret) {
  2669. ath10k_warn(ar, "failed to request irqs: %d\n", ret);
  2670. goto err_deinit_irq;
  2671. }
  2672. ret = ath10k_pci_chip_reset(ar);
  2673. if (ret) {
  2674. ath10k_err(ar, "failed to reset chip: %d\n", ret);
  2675. goto err_free_irq;
  2676. }
  2677. chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
  2678. if (chip_id == 0xffffffff) {
  2679. ath10k_err(ar, "failed to get chip id\n");
  2680. goto err_free_irq;
  2681. }
  2682. if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
  2683. ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
  2684. pdev->device, chip_id);
  2685. goto err_free_irq;
  2686. }
  2687. ret = ath10k_core_register(ar, chip_id);
  2688. if (ret) {
  2689. ath10k_err(ar, "failed to register driver core: %d\n", ret);
  2690. goto err_free_irq;
  2691. }
  2692. return 0;
  2693. err_free_irq:
  2694. ath10k_pci_free_irq(ar);
  2695. ath10k_pci_kill_tasklet(ar);
  2696. err_deinit_irq:
  2697. ath10k_pci_deinit_irq(ar);
  2698. err_sleep:
  2699. ath10k_pci_sleep_sync(ar);
  2700. ath10k_pci_release(ar);
  2701. err_free_pipes:
  2702. ath10k_pci_free_pipes(ar);
  2703. err_core_destroy:
  2704. ath10k_core_destroy(ar);
  2705. return ret;
  2706. }
  2707. static void ath10k_pci_remove(struct pci_dev *pdev)
  2708. {
  2709. struct ath10k *ar = pci_get_drvdata(pdev);
  2710. struct ath10k_pci *ar_pci;
  2711. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
  2712. if (!ar)
  2713. return;
  2714. ar_pci = ath10k_pci_priv(ar);
  2715. if (!ar_pci)
  2716. return;
  2717. ath10k_core_unregister(ar);
  2718. ath10k_pci_free_irq(ar);
  2719. ath10k_pci_deinit_irq(ar);
  2720. ath10k_pci_release_resource(ar);
  2721. ath10k_pci_sleep_sync(ar);
  2722. ath10k_pci_release(ar);
  2723. ath10k_core_destroy(ar);
  2724. }
  2725. MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
  2726. static struct pci_driver ath10k_pci_driver = {
  2727. .name = "ath10k_pci",
  2728. .id_table = ath10k_pci_id_table,
  2729. .probe = ath10k_pci_probe,
  2730. .remove = ath10k_pci_remove,
  2731. };
  2732. static int __init ath10k_pci_init(void)
  2733. {
  2734. int ret;
  2735. ret = pci_register_driver(&ath10k_pci_driver);
  2736. if (ret)
  2737. printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
  2738. ret);
  2739. ret = ath10k_ahb_init();
  2740. if (ret)
  2741. printk(KERN_ERR "ahb init failed: %d\n", ret);
  2742. return ret;
  2743. }
  2744. module_init(ath10k_pci_init);
  2745. static void __exit ath10k_pci_exit(void)
  2746. {
  2747. pci_unregister_driver(&ath10k_pci_driver);
  2748. ath10k_ahb_exit();
  2749. }
  2750. module_exit(ath10k_pci_exit);
  2751. MODULE_AUTHOR("Qualcomm Atheros");
  2752. MODULE_DESCRIPTION("Driver support for Qualcomm Atheros 802.11ac WLAN PCIe/AHB devices");
  2753. MODULE_LICENSE("Dual BSD/GPL");
  2754. /* QCA988x 2.0 firmware files */
  2755. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
  2756. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
  2757. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2758. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2759. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
  2760. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2761. /* QCA9887 1.0 firmware files */
  2762. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2763. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" QCA9887_HW_1_0_BOARD_DATA_FILE);
  2764. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2765. /* QCA6174 2.1 firmware files */
  2766. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
  2767. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
  2768. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
  2769. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2770. /* QCA6174 3.1 firmware files */
  2771. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2772. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2773. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
  2774. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2775. /* QCA9377 1.0 firmware files */
  2776. MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2777. MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);