pci.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438
  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_qca988x_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  700. {
  701. u32 val = 0, region = addr & 0xfffff;
  702. val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS)
  703. & 0x7ff) << 21;
  704. val |= 0x100000 | region;
  705. return val;
  706. }
  707. static u32 ath10k_pci_qca99x0_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  708. {
  709. u32 val = 0, region = addr & 0xfffff;
  710. val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
  711. val |= 0x100000 | region;
  712. return val;
  713. }
  714. static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  715. {
  716. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  717. if (WARN_ON_ONCE(!ar_pci->targ_cpu_to_ce_addr))
  718. return -ENOTSUPP;
  719. return ar_pci->targ_cpu_to_ce_addr(ar, addr);
  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_zalloc_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. remaining_bytes = nbytes;
  757. ce_data = ce_data_base;
  758. while (remaining_bytes) {
  759. nbytes = min_t(unsigned int, remaining_bytes,
  760. DIAG_TRANSFER_LIMIT);
  761. ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, ce_data);
  762. if (ret != 0)
  763. goto done;
  764. /* Request CE to send from Target(!) address to Host buffer */
  765. /*
  766. * The address supplied by the caller is in the
  767. * Target CPU virtual address space.
  768. *
  769. * In order to use this address with the diagnostic CE,
  770. * convert it from Target CPU virtual address space
  771. * to CE address space
  772. */
  773. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  774. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
  775. 0);
  776. if (ret)
  777. goto done;
  778. i = 0;
  779. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  780. NULL) != 0) {
  781. mdelay(1);
  782. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  783. ret = -EBUSY;
  784. goto done;
  785. }
  786. }
  787. i = 0;
  788. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  789. (void **)&buf,
  790. &completed_nbytes)
  791. != 0) {
  792. mdelay(1);
  793. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  794. ret = -EBUSY;
  795. goto done;
  796. }
  797. }
  798. if (nbytes != completed_nbytes) {
  799. ret = -EIO;
  800. goto done;
  801. }
  802. if (*buf != ce_data) {
  803. ret = -EIO;
  804. goto done;
  805. }
  806. remaining_bytes -= nbytes;
  807. if (ret) {
  808. ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
  809. address, ret);
  810. break;
  811. }
  812. memcpy(data, data_buf, nbytes);
  813. address += nbytes;
  814. data += nbytes;
  815. }
  816. done:
  817. if (data_buf)
  818. dma_free_coherent(ar->dev, alloc_nbytes, data_buf,
  819. ce_data_base);
  820. spin_unlock_bh(&ar_pci->ce_lock);
  821. return ret;
  822. }
  823. static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
  824. {
  825. __le32 val = 0;
  826. int ret;
  827. ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
  828. *value = __le32_to_cpu(val);
  829. return ret;
  830. }
  831. static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
  832. u32 src, u32 len)
  833. {
  834. u32 host_addr, addr;
  835. int ret;
  836. host_addr = host_interest_item_address(src);
  837. ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
  838. if (ret != 0) {
  839. ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
  840. src, ret);
  841. return ret;
  842. }
  843. ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
  844. if (ret != 0) {
  845. ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
  846. addr, len, ret);
  847. return ret;
  848. }
  849. return 0;
  850. }
  851. #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
  852. __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
  853. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  854. const void *data, int nbytes)
  855. {
  856. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  857. int ret = 0;
  858. u32 *buf;
  859. unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
  860. struct ath10k_ce_pipe *ce_diag;
  861. void *data_buf = NULL;
  862. u32 ce_data; /* Host buffer address in CE space */
  863. dma_addr_t ce_data_base = 0;
  864. int i;
  865. spin_lock_bh(&ar_pci->ce_lock);
  866. ce_diag = ar_pci->ce_diag;
  867. /*
  868. * Allocate a temporary bounce buffer to hold caller's data
  869. * to be DMA'ed to Target. This guarantees
  870. * 1) 4-byte alignment
  871. * 2) Buffer in DMA-able space
  872. */
  873. orig_nbytes = nbytes;
  874. data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
  875. orig_nbytes,
  876. &ce_data_base,
  877. GFP_ATOMIC);
  878. if (!data_buf) {
  879. ret = -ENOMEM;
  880. goto done;
  881. }
  882. /* Copy caller's data to allocated DMA buf */
  883. memcpy(data_buf, data, orig_nbytes);
  884. /*
  885. * The address supplied by the caller is in the
  886. * Target CPU virtual address space.
  887. *
  888. * In order to use this address with the diagnostic CE,
  889. * convert it from
  890. * Target CPU virtual address space
  891. * to
  892. * CE address space
  893. */
  894. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  895. remaining_bytes = orig_nbytes;
  896. ce_data = ce_data_base;
  897. while (remaining_bytes) {
  898. /* FIXME: check cast */
  899. nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
  900. /* Set up to receive directly into Target(!) address */
  901. ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
  902. if (ret != 0)
  903. goto done;
  904. /*
  905. * Request CE to send caller-supplied data that
  906. * was copied to bounce buffer to Target(!) address.
  907. */
  908. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
  909. nbytes, 0, 0);
  910. if (ret != 0)
  911. goto done;
  912. i = 0;
  913. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  914. NULL) != 0) {
  915. mdelay(1);
  916. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  917. ret = -EBUSY;
  918. goto done;
  919. }
  920. }
  921. i = 0;
  922. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  923. (void **)&buf,
  924. &completed_nbytes)
  925. != 0) {
  926. mdelay(1);
  927. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  928. ret = -EBUSY;
  929. goto done;
  930. }
  931. }
  932. if (nbytes != completed_nbytes) {
  933. ret = -EIO;
  934. goto done;
  935. }
  936. if (*buf != address) {
  937. ret = -EIO;
  938. goto done;
  939. }
  940. remaining_bytes -= nbytes;
  941. address += nbytes;
  942. ce_data += nbytes;
  943. }
  944. done:
  945. if (data_buf) {
  946. dma_free_coherent(ar->dev, orig_nbytes, data_buf,
  947. ce_data_base);
  948. }
  949. if (ret != 0)
  950. ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
  951. address, ret);
  952. spin_unlock_bh(&ar_pci->ce_lock);
  953. return ret;
  954. }
  955. static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
  956. {
  957. __le32 val = __cpu_to_le32(value);
  958. return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
  959. }
  960. /* Called by lower (CE) layer when a send to Target completes. */
  961. static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
  962. {
  963. struct ath10k *ar = ce_state->ar;
  964. struct sk_buff_head list;
  965. struct sk_buff *skb;
  966. __skb_queue_head_init(&list);
  967. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  968. /* no need to call tx completion for NULL pointers */
  969. if (skb == NULL)
  970. continue;
  971. __skb_queue_tail(&list, skb);
  972. }
  973. while ((skb = __skb_dequeue(&list)))
  974. ath10k_htc_tx_completion_handler(ar, skb);
  975. }
  976. static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
  977. void (*callback)(struct ath10k *ar,
  978. struct sk_buff *skb))
  979. {
  980. struct ath10k *ar = ce_state->ar;
  981. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  982. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  983. struct sk_buff *skb;
  984. struct sk_buff_head list;
  985. void *transfer_context;
  986. unsigned int nbytes, max_nbytes;
  987. __skb_queue_head_init(&list);
  988. while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
  989. &nbytes) == 0) {
  990. skb = transfer_context;
  991. max_nbytes = skb->len + skb_tailroom(skb);
  992. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  993. max_nbytes, DMA_FROM_DEVICE);
  994. if (unlikely(max_nbytes < nbytes)) {
  995. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  996. nbytes, max_nbytes);
  997. dev_kfree_skb_any(skb);
  998. continue;
  999. }
  1000. skb_put(skb, nbytes);
  1001. __skb_queue_tail(&list, skb);
  1002. }
  1003. while ((skb = __skb_dequeue(&list))) {
  1004. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1005. ce_state->id, skb->len);
  1006. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1007. skb->data, skb->len);
  1008. callback(ar, skb);
  1009. }
  1010. ath10k_pci_rx_post_pipe(pipe_info);
  1011. }
  1012. static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
  1013. void (*callback)(struct ath10k *ar,
  1014. struct sk_buff *skb))
  1015. {
  1016. struct ath10k *ar = ce_state->ar;
  1017. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1018. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  1019. struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
  1020. struct sk_buff *skb;
  1021. struct sk_buff_head list;
  1022. void *transfer_context;
  1023. unsigned int nbytes, max_nbytes, nentries;
  1024. int orig_len;
  1025. /* No need to aquire ce_lock for CE5, since this is the only place CE5
  1026. * is processed other than init and deinit. Before releasing CE5
  1027. * buffers, interrupts are disabled. Thus CE5 access is serialized.
  1028. */
  1029. __skb_queue_head_init(&list);
  1030. while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
  1031. &nbytes) == 0) {
  1032. skb = transfer_context;
  1033. max_nbytes = skb->len + skb_tailroom(skb);
  1034. if (unlikely(max_nbytes < nbytes)) {
  1035. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  1036. nbytes, max_nbytes);
  1037. continue;
  1038. }
  1039. dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1040. max_nbytes, DMA_FROM_DEVICE);
  1041. skb_put(skb, nbytes);
  1042. __skb_queue_tail(&list, skb);
  1043. }
  1044. nentries = skb_queue_len(&list);
  1045. while ((skb = __skb_dequeue(&list))) {
  1046. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1047. ce_state->id, skb->len);
  1048. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1049. skb->data, skb->len);
  1050. orig_len = skb->len;
  1051. callback(ar, skb);
  1052. skb_push(skb, orig_len - skb->len);
  1053. skb_reset_tail_pointer(skb);
  1054. skb_trim(skb, 0);
  1055. /*let device gain the buffer again*/
  1056. dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1057. skb->len + skb_tailroom(skb),
  1058. DMA_FROM_DEVICE);
  1059. }
  1060. ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
  1061. }
  1062. /* Called by lower (CE) layer when data is received from the Target. */
  1063. static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1064. {
  1065. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1066. }
  1067. static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1068. {
  1069. /* CE4 polling needs to be done whenever CE pipe which transports
  1070. * HTT Rx (target->host) is processed.
  1071. */
  1072. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1073. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1074. }
  1075. /* Called by lower (CE) layer when data is received from the Target.
  1076. * Only 10.4 firmware uses separate CE to transfer pktlog data.
  1077. */
  1078. static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
  1079. {
  1080. ath10k_pci_process_rx_cb(ce_state,
  1081. ath10k_htt_rx_pktlog_completion_handler);
  1082. }
  1083. /* Called by lower (CE) layer when a send to HTT Target completes. */
  1084. static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
  1085. {
  1086. struct ath10k *ar = ce_state->ar;
  1087. struct sk_buff *skb;
  1088. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  1089. /* no need to call tx completion for NULL pointers */
  1090. if (!skb)
  1091. continue;
  1092. dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
  1093. skb->len, DMA_TO_DEVICE);
  1094. ath10k_htt_hif_tx_complete(ar, skb);
  1095. }
  1096. }
  1097. static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
  1098. {
  1099. skb_pull(skb, sizeof(struct ath10k_htc_hdr));
  1100. ath10k_htt_t2h_msg_handler(ar, skb);
  1101. }
  1102. /* Called by lower (CE) layer when HTT data is received from the Target. */
  1103. static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
  1104. {
  1105. /* CE4 polling needs to be done whenever CE pipe which transports
  1106. * HTT Rx (target->host) is processed.
  1107. */
  1108. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1109. ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
  1110. }
  1111. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  1112. struct ath10k_hif_sg_item *items, int n_items)
  1113. {
  1114. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1115. struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
  1116. struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
  1117. struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
  1118. unsigned int nentries_mask;
  1119. unsigned int sw_index;
  1120. unsigned int write_index;
  1121. int err, i = 0;
  1122. spin_lock_bh(&ar_pci->ce_lock);
  1123. nentries_mask = src_ring->nentries_mask;
  1124. sw_index = src_ring->sw_index;
  1125. write_index = src_ring->write_index;
  1126. if (unlikely(CE_RING_DELTA(nentries_mask,
  1127. write_index, sw_index - 1) < n_items)) {
  1128. err = -ENOBUFS;
  1129. goto err;
  1130. }
  1131. for (i = 0; i < n_items - 1; i++) {
  1132. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1133. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1134. i, items[i].paddr, items[i].len, n_items);
  1135. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1136. items[i].vaddr, items[i].len);
  1137. err = ath10k_ce_send_nolock(ce_pipe,
  1138. items[i].transfer_context,
  1139. items[i].paddr,
  1140. items[i].len,
  1141. items[i].transfer_id,
  1142. CE_SEND_FLAG_GATHER);
  1143. if (err)
  1144. goto err;
  1145. }
  1146. /* `i` is equal to `n_items -1` after for() */
  1147. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1148. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1149. i, items[i].paddr, items[i].len, n_items);
  1150. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1151. items[i].vaddr, items[i].len);
  1152. err = ath10k_ce_send_nolock(ce_pipe,
  1153. items[i].transfer_context,
  1154. items[i].paddr,
  1155. items[i].len,
  1156. items[i].transfer_id,
  1157. 0);
  1158. if (err)
  1159. goto err;
  1160. spin_unlock_bh(&ar_pci->ce_lock);
  1161. return 0;
  1162. err:
  1163. for (; i > 0; i--)
  1164. __ath10k_ce_send_revert(ce_pipe);
  1165. spin_unlock_bh(&ar_pci->ce_lock);
  1166. return err;
  1167. }
  1168. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  1169. size_t buf_len)
  1170. {
  1171. return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
  1172. }
  1173. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
  1174. {
  1175. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1176. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
  1177. return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
  1178. }
  1179. static void ath10k_pci_dump_registers(struct ath10k *ar,
  1180. struct ath10k_fw_crash_data *crash_data)
  1181. {
  1182. __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
  1183. int i, ret;
  1184. lockdep_assert_held(&ar->data_lock);
  1185. ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
  1186. hi_failure_state,
  1187. REG_DUMP_COUNT_QCA988X * sizeof(__le32));
  1188. if (ret) {
  1189. ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
  1190. return;
  1191. }
  1192. BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
  1193. ath10k_err(ar, "firmware register dump:\n");
  1194. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
  1195. ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
  1196. i,
  1197. __le32_to_cpu(reg_dump_values[i]),
  1198. __le32_to_cpu(reg_dump_values[i + 1]),
  1199. __le32_to_cpu(reg_dump_values[i + 2]),
  1200. __le32_to_cpu(reg_dump_values[i + 3]));
  1201. if (!crash_data)
  1202. return;
  1203. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
  1204. crash_data->registers[i] = reg_dump_values[i];
  1205. }
  1206. static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
  1207. {
  1208. struct ath10k_fw_crash_data *crash_data;
  1209. char uuid[50];
  1210. spin_lock_bh(&ar->data_lock);
  1211. ar->stats.fw_crash_counter++;
  1212. crash_data = ath10k_debug_get_new_fw_crash_data(ar);
  1213. if (crash_data)
  1214. scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
  1215. else
  1216. scnprintf(uuid, sizeof(uuid), "n/a");
  1217. ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
  1218. ath10k_print_driver_info(ar);
  1219. ath10k_pci_dump_registers(ar, crash_data);
  1220. ath10k_ce_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. static void ath10k_pci_rx_retry_sync(struct ath10k *ar)
  1248. {
  1249. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1250. del_timer_sync(&ar_pci->rx_post_retry);
  1251. }
  1252. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  1253. u8 *ul_pipe, u8 *dl_pipe)
  1254. {
  1255. const struct service_to_pipe *entry;
  1256. bool ul_set = false, dl_set = false;
  1257. int i;
  1258. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
  1259. for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
  1260. entry = &target_service_to_ce_map_wlan[i];
  1261. if (__le32_to_cpu(entry->service_id) != service_id)
  1262. continue;
  1263. switch (__le32_to_cpu(entry->pipedir)) {
  1264. case PIPEDIR_NONE:
  1265. break;
  1266. case PIPEDIR_IN:
  1267. WARN_ON(dl_set);
  1268. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1269. dl_set = true;
  1270. break;
  1271. case PIPEDIR_OUT:
  1272. WARN_ON(ul_set);
  1273. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1274. ul_set = true;
  1275. break;
  1276. case PIPEDIR_INOUT:
  1277. WARN_ON(dl_set);
  1278. WARN_ON(ul_set);
  1279. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1280. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1281. dl_set = true;
  1282. ul_set = true;
  1283. break;
  1284. }
  1285. }
  1286. if (WARN_ON(!ul_set || !dl_set))
  1287. return -ENOENT;
  1288. return 0;
  1289. }
  1290. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
  1291. u8 *ul_pipe, u8 *dl_pipe)
  1292. {
  1293. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
  1294. (void)ath10k_pci_hif_map_service_to_pipe(ar,
  1295. ATH10K_HTC_SVC_ID_RSVD_CTRL,
  1296. ul_pipe, dl_pipe);
  1297. }
  1298. void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
  1299. {
  1300. u32 val;
  1301. switch (ar->hw_rev) {
  1302. case ATH10K_HW_QCA988X:
  1303. case ATH10K_HW_QCA9887:
  1304. case ATH10K_HW_QCA6174:
  1305. case ATH10K_HW_QCA9377:
  1306. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1307. CORE_CTRL_ADDRESS);
  1308. val &= ~CORE_CTRL_PCIE_REG_31_MASK;
  1309. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1310. CORE_CTRL_ADDRESS, val);
  1311. break;
  1312. case ATH10K_HW_QCA99X0:
  1313. case ATH10K_HW_QCA9984:
  1314. case ATH10K_HW_QCA9888:
  1315. case ATH10K_HW_QCA4019:
  1316. /* TODO: Find appropriate register configuration for QCA99X0
  1317. * to mask irq/MSI.
  1318. */
  1319. break;
  1320. }
  1321. }
  1322. static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
  1323. {
  1324. u32 val;
  1325. switch (ar->hw_rev) {
  1326. case ATH10K_HW_QCA988X:
  1327. case ATH10K_HW_QCA9887:
  1328. case ATH10K_HW_QCA6174:
  1329. case ATH10K_HW_QCA9377:
  1330. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1331. CORE_CTRL_ADDRESS);
  1332. val |= CORE_CTRL_PCIE_REG_31_MASK;
  1333. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1334. CORE_CTRL_ADDRESS, val);
  1335. break;
  1336. case ATH10K_HW_QCA99X0:
  1337. case ATH10K_HW_QCA9984:
  1338. case ATH10K_HW_QCA9888:
  1339. case ATH10K_HW_QCA4019:
  1340. /* TODO: Find appropriate register configuration for QCA99X0
  1341. * to unmask irq/MSI.
  1342. */
  1343. break;
  1344. }
  1345. }
  1346. static void ath10k_pci_irq_disable(struct ath10k *ar)
  1347. {
  1348. ath10k_ce_disable_interrupts(ar);
  1349. ath10k_pci_disable_and_clear_legacy_irq(ar);
  1350. ath10k_pci_irq_msi_fw_mask(ar);
  1351. }
  1352. static void ath10k_pci_irq_sync(struct ath10k *ar)
  1353. {
  1354. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1355. synchronize_irq(ar_pci->pdev->irq);
  1356. }
  1357. static void ath10k_pci_irq_enable(struct ath10k *ar)
  1358. {
  1359. ath10k_ce_enable_interrupts(ar);
  1360. ath10k_pci_enable_legacy_irq(ar);
  1361. ath10k_pci_irq_msi_fw_unmask(ar);
  1362. }
  1363. static int ath10k_pci_hif_start(struct ath10k *ar)
  1364. {
  1365. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1366. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
  1367. napi_enable(&ar->napi);
  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_ce_pipe *ce_pipe;
  1403. struct ath10k_ce_ring *ce_ring;
  1404. struct sk_buff *skb;
  1405. int i;
  1406. ar = pci_pipe->hif_ce_state;
  1407. ce_pipe = pci_pipe->ce_hdl;
  1408. ce_ring = ce_pipe->src_ring;
  1409. if (!ce_ring)
  1410. return;
  1411. if (!pci_pipe->buf_sz)
  1412. return;
  1413. for (i = 0; i < ce_ring->nentries; i++) {
  1414. skb = ce_ring->per_transfer_context[i];
  1415. if (!skb)
  1416. continue;
  1417. ce_ring->per_transfer_context[i] = NULL;
  1418. ath10k_htc_tx_completion_handler(ar, skb);
  1419. }
  1420. }
  1421. /*
  1422. * Cleanup residual buffers for device shutdown:
  1423. * buffers that were enqueued for receive
  1424. * buffers that were to be sent
  1425. * Note: Buffers that had completed but which were
  1426. * not yet processed are on a completion queue. They
  1427. * are handled when the completion thread shuts down.
  1428. */
  1429. static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
  1430. {
  1431. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1432. int pipe_num;
  1433. for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
  1434. struct ath10k_pci_pipe *pipe_info;
  1435. pipe_info = &ar_pci->pipe_info[pipe_num];
  1436. ath10k_pci_rx_pipe_cleanup(pipe_info);
  1437. ath10k_pci_tx_pipe_cleanup(pipe_info);
  1438. }
  1439. }
  1440. void ath10k_pci_ce_deinit(struct ath10k *ar)
  1441. {
  1442. int i;
  1443. for (i = 0; i < CE_COUNT; i++)
  1444. ath10k_ce_deinit_pipe(ar, i);
  1445. }
  1446. void ath10k_pci_flush(struct ath10k *ar)
  1447. {
  1448. ath10k_pci_rx_retry_sync(ar);
  1449. ath10k_pci_buffer_cleanup(ar);
  1450. }
  1451. static void ath10k_pci_hif_stop(struct ath10k *ar)
  1452. {
  1453. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1454. unsigned long flags;
  1455. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
  1456. /* Most likely the device has HTT Rx ring configured. The only way to
  1457. * prevent the device from accessing (and possible corrupting) host
  1458. * memory is to reset the chip now.
  1459. *
  1460. * There's also no known way of masking MSI interrupts on the device.
  1461. * For ranged MSI the CE-related interrupts can be masked. However
  1462. * regardless how many MSI interrupts are assigned the first one
  1463. * is always used for firmware indications (crashes) and cannot be
  1464. * masked. To prevent the device from asserting the interrupt reset it
  1465. * before proceeding with cleanup.
  1466. */
  1467. ath10k_pci_safe_chip_reset(ar);
  1468. ath10k_pci_irq_disable(ar);
  1469. ath10k_pci_irq_sync(ar);
  1470. ath10k_pci_flush(ar);
  1471. napi_synchronize(&ar->napi);
  1472. napi_disable(&ar->napi);
  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 4;
  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, "Failed 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(caldata);
  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. !ath10k_pci_irq_pending(ar))
  2275. return IRQ_NONE;
  2276. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2277. ath10k_pci_irq_msi_fw_mask(ar);
  2278. napi_schedule(&ar->napi);
  2279. return IRQ_HANDLED;
  2280. }
  2281. static int ath10k_pci_napi_poll(struct napi_struct *ctx, int budget)
  2282. {
  2283. struct ath10k *ar = container_of(ctx, struct ath10k, napi);
  2284. int done = 0;
  2285. if (ath10k_pci_has_fw_crashed(ar)) {
  2286. ath10k_pci_fw_crashed_clear(ar);
  2287. ath10k_pci_fw_crashed_dump(ar);
  2288. napi_complete(ctx);
  2289. return done;
  2290. }
  2291. ath10k_ce_per_engine_service_any(ar);
  2292. done = ath10k_htt_txrx_compl_task(ar, budget);
  2293. if (done < budget) {
  2294. napi_complete_done(ctx, done);
  2295. /* In case of MSI, it is possible that interrupts are received
  2296. * while NAPI poll is inprogress. So pending interrupts that are
  2297. * received after processing all copy engine pipes by NAPI poll
  2298. * will not be handled again. This is causing failure to
  2299. * complete boot sequence in x86 platform. So before enabling
  2300. * interrupts safer to check for pending interrupts for
  2301. * immediate servicing.
  2302. */
  2303. if (CE_INTERRUPT_SUMMARY(ar)) {
  2304. napi_reschedule(ctx);
  2305. goto out;
  2306. }
  2307. ath10k_pci_enable_legacy_irq(ar);
  2308. ath10k_pci_irq_msi_fw_unmask(ar);
  2309. }
  2310. out:
  2311. return done;
  2312. }
  2313. static int ath10k_pci_request_irq_msi(struct ath10k *ar)
  2314. {
  2315. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2316. int ret;
  2317. ret = request_irq(ar_pci->pdev->irq,
  2318. ath10k_pci_interrupt_handler,
  2319. IRQF_SHARED, "ath10k_pci", ar);
  2320. if (ret) {
  2321. ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
  2322. ar_pci->pdev->irq, ret);
  2323. return ret;
  2324. }
  2325. return 0;
  2326. }
  2327. static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
  2328. {
  2329. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2330. int ret;
  2331. ret = request_irq(ar_pci->pdev->irq,
  2332. ath10k_pci_interrupt_handler,
  2333. IRQF_SHARED, "ath10k_pci", ar);
  2334. if (ret) {
  2335. ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
  2336. ar_pci->pdev->irq, ret);
  2337. return ret;
  2338. }
  2339. return 0;
  2340. }
  2341. static int ath10k_pci_request_irq(struct ath10k *ar)
  2342. {
  2343. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2344. switch (ar_pci->oper_irq_mode) {
  2345. case ATH10K_PCI_IRQ_LEGACY:
  2346. return ath10k_pci_request_irq_legacy(ar);
  2347. case ATH10K_PCI_IRQ_MSI:
  2348. return ath10k_pci_request_irq_msi(ar);
  2349. default:
  2350. return -EINVAL;
  2351. }
  2352. }
  2353. static void ath10k_pci_free_irq(struct ath10k *ar)
  2354. {
  2355. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2356. free_irq(ar_pci->pdev->irq, ar);
  2357. }
  2358. void ath10k_pci_init_napi(struct ath10k *ar)
  2359. {
  2360. netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_pci_napi_poll,
  2361. ATH10K_NAPI_BUDGET);
  2362. }
  2363. static int ath10k_pci_init_irq(struct ath10k *ar)
  2364. {
  2365. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2366. int ret;
  2367. ath10k_pci_init_napi(ar);
  2368. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
  2369. ath10k_info(ar, "limiting irq mode to: %d\n",
  2370. ath10k_pci_irq_mode);
  2371. /* Try MSI */
  2372. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
  2373. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_MSI;
  2374. ret = pci_enable_msi(ar_pci->pdev);
  2375. if (ret == 0)
  2376. return 0;
  2377. /* fall-through */
  2378. }
  2379. /* Try legacy irq
  2380. *
  2381. * A potential race occurs here: The CORE_BASE write
  2382. * depends on target correctly decoding AXI address but
  2383. * host won't know when target writes BAR to CORE_CTRL.
  2384. * This write might get lost if target has NOT written BAR.
  2385. * For now, fix the race by repeating the write in below
  2386. * synchronization checking. */
  2387. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_LEGACY;
  2388. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2389. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  2390. return 0;
  2391. }
  2392. static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
  2393. {
  2394. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2395. 0);
  2396. }
  2397. static int ath10k_pci_deinit_irq(struct ath10k *ar)
  2398. {
  2399. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2400. switch (ar_pci->oper_irq_mode) {
  2401. case ATH10K_PCI_IRQ_LEGACY:
  2402. ath10k_pci_deinit_irq_legacy(ar);
  2403. break;
  2404. default:
  2405. pci_disable_msi(ar_pci->pdev);
  2406. break;
  2407. }
  2408. return 0;
  2409. }
  2410. int ath10k_pci_wait_for_target_init(struct ath10k *ar)
  2411. {
  2412. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2413. unsigned long timeout;
  2414. u32 val;
  2415. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
  2416. timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
  2417. do {
  2418. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  2419. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
  2420. val);
  2421. /* target should never return this */
  2422. if (val == 0xffffffff)
  2423. continue;
  2424. /* the device has crashed so don't bother trying anymore */
  2425. if (val & FW_IND_EVENT_PENDING)
  2426. break;
  2427. if (val & FW_IND_INITIALIZED)
  2428. break;
  2429. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
  2430. /* Fix potential race by repeating CORE_BASE writes */
  2431. ath10k_pci_enable_legacy_irq(ar);
  2432. mdelay(10);
  2433. } while (time_before(jiffies, timeout));
  2434. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2435. ath10k_pci_irq_msi_fw_mask(ar);
  2436. if (val == 0xffffffff) {
  2437. ath10k_err(ar, "failed to read device register, device is gone\n");
  2438. return -EIO;
  2439. }
  2440. if (val & FW_IND_EVENT_PENDING) {
  2441. ath10k_warn(ar, "device has crashed during init\n");
  2442. return -ECOMM;
  2443. }
  2444. if (!(val & FW_IND_INITIALIZED)) {
  2445. ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
  2446. val);
  2447. return -ETIMEDOUT;
  2448. }
  2449. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
  2450. return 0;
  2451. }
  2452. static int ath10k_pci_cold_reset(struct ath10k *ar)
  2453. {
  2454. u32 val;
  2455. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
  2456. spin_lock_bh(&ar->data_lock);
  2457. ar->stats.fw_cold_reset_counter++;
  2458. spin_unlock_bh(&ar->data_lock);
  2459. /* Put Target, including PCIe, into RESET. */
  2460. val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
  2461. val |= 1;
  2462. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2463. /* After writing into SOC_GLOBAL_RESET to put device into
  2464. * reset and pulling out of reset pcie may not be stable
  2465. * for any immediate pcie register access and cause bus error,
  2466. * add delay before any pcie access request to fix this issue.
  2467. */
  2468. msleep(20);
  2469. /* Pull Target, including PCIe, out of RESET. */
  2470. val &= ~1;
  2471. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2472. msleep(20);
  2473. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
  2474. return 0;
  2475. }
  2476. static int ath10k_pci_claim(struct ath10k *ar)
  2477. {
  2478. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2479. struct pci_dev *pdev = ar_pci->pdev;
  2480. int ret;
  2481. pci_set_drvdata(pdev, ar);
  2482. ret = pci_enable_device(pdev);
  2483. if (ret) {
  2484. ath10k_err(ar, "failed to enable pci device: %d\n", ret);
  2485. return ret;
  2486. }
  2487. ret = pci_request_region(pdev, BAR_NUM, "ath");
  2488. if (ret) {
  2489. ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
  2490. ret);
  2491. goto err_device;
  2492. }
  2493. /* Target expects 32 bit DMA. Enforce it. */
  2494. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2495. if (ret) {
  2496. ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
  2497. goto err_region;
  2498. }
  2499. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  2500. if (ret) {
  2501. ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
  2502. ret);
  2503. goto err_region;
  2504. }
  2505. pci_set_master(pdev);
  2506. /* Arrange for access to Target SoC registers. */
  2507. ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
  2508. ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
  2509. if (!ar_pci->mem) {
  2510. ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
  2511. ret = -EIO;
  2512. goto err_master;
  2513. }
  2514. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%pK\n", ar_pci->mem);
  2515. return 0;
  2516. err_master:
  2517. pci_clear_master(pdev);
  2518. err_region:
  2519. pci_release_region(pdev, BAR_NUM);
  2520. err_device:
  2521. pci_disable_device(pdev);
  2522. return ret;
  2523. }
  2524. static void ath10k_pci_release(struct ath10k *ar)
  2525. {
  2526. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2527. struct pci_dev *pdev = ar_pci->pdev;
  2528. pci_iounmap(pdev, ar_pci->mem);
  2529. pci_release_region(pdev, BAR_NUM);
  2530. pci_clear_master(pdev);
  2531. pci_disable_device(pdev);
  2532. }
  2533. static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
  2534. {
  2535. const struct ath10k_pci_supp_chip *supp_chip;
  2536. int i;
  2537. u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
  2538. for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
  2539. supp_chip = &ath10k_pci_supp_chips[i];
  2540. if (supp_chip->dev_id == dev_id &&
  2541. supp_chip->rev_id == rev_id)
  2542. return true;
  2543. }
  2544. return false;
  2545. }
  2546. int ath10k_pci_setup_resource(struct ath10k *ar)
  2547. {
  2548. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2549. int ret;
  2550. spin_lock_init(&ar_pci->ce_lock);
  2551. spin_lock_init(&ar_pci->ps_lock);
  2552. setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
  2553. (unsigned long)ar);
  2554. if (QCA_REV_6174(ar) || QCA_REV_9377(ar))
  2555. ath10k_pci_override_ce_config(ar);
  2556. ret = ath10k_pci_alloc_pipes(ar);
  2557. if (ret) {
  2558. ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
  2559. ret);
  2560. return ret;
  2561. }
  2562. return 0;
  2563. }
  2564. void ath10k_pci_release_resource(struct ath10k *ar)
  2565. {
  2566. ath10k_pci_rx_retry_sync(ar);
  2567. netif_napi_del(&ar->napi);
  2568. ath10k_pci_ce_deinit(ar);
  2569. ath10k_pci_free_pipes(ar);
  2570. }
  2571. static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
  2572. .read32 = ath10k_bus_pci_read32,
  2573. .write32 = ath10k_bus_pci_write32,
  2574. .get_num_banks = ath10k_pci_get_num_banks,
  2575. };
  2576. static int ath10k_pci_probe(struct pci_dev *pdev,
  2577. const struct pci_device_id *pci_dev)
  2578. {
  2579. int ret = 0;
  2580. struct ath10k *ar;
  2581. struct ath10k_pci *ar_pci;
  2582. enum ath10k_hw_rev hw_rev;
  2583. u32 chip_id;
  2584. bool pci_ps;
  2585. int (*pci_soft_reset)(struct ath10k *ar);
  2586. int (*pci_hard_reset)(struct ath10k *ar);
  2587. u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);
  2588. switch (pci_dev->device) {
  2589. case QCA988X_2_0_DEVICE_ID:
  2590. hw_rev = ATH10K_HW_QCA988X;
  2591. pci_ps = false;
  2592. pci_soft_reset = ath10k_pci_warm_reset;
  2593. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2594. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2595. break;
  2596. case QCA9887_1_0_DEVICE_ID:
  2597. hw_rev = ATH10K_HW_QCA9887;
  2598. pci_ps = false;
  2599. pci_soft_reset = ath10k_pci_warm_reset;
  2600. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2601. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2602. break;
  2603. case QCA6164_2_1_DEVICE_ID:
  2604. case QCA6174_2_1_DEVICE_ID:
  2605. hw_rev = ATH10K_HW_QCA6174;
  2606. pci_ps = true;
  2607. pci_soft_reset = ath10k_pci_warm_reset;
  2608. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2609. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2610. break;
  2611. case QCA99X0_2_0_DEVICE_ID:
  2612. hw_rev = ATH10K_HW_QCA99X0;
  2613. pci_ps = false;
  2614. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2615. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2616. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2617. break;
  2618. case QCA9984_1_0_DEVICE_ID:
  2619. hw_rev = ATH10K_HW_QCA9984;
  2620. pci_ps = false;
  2621. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2622. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2623. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2624. break;
  2625. case QCA9888_2_0_DEVICE_ID:
  2626. hw_rev = ATH10K_HW_QCA9888;
  2627. pci_ps = false;
  2628. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2629. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2630. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2631. break;
  2632. case QCA9377_1_0_DEVICE_ID:
  2633. hw_rev = ATH10K_HW_QCA9377;
  2634. pci_ps = true;
  2635. pci_soft_reset = NULL;
  2636. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2637. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2638. break;
  2639. default:
  2640. WARN_ON(1);
  2641. return -ENOTSUPP;
  2642. }
  2643. ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
  2644. hw_rev, &ath10k_pci_hif_ops);
  2645. if (!ar) {
  2646. dev_err(&pdev->dev, "failed to allocate core\n");
  2647. return -ENOMEM;
  2648. }
  2649. ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
  2650. pdev->vendor, pdev->device,
  2651. pdev->subsystem_vendor, pdev->subsystem_device);
  2652. ar_pci = ath10k_pci_priv(ar);
  2653. ar_pci->pdev = pdev;
  2654. ar_pci->dev = &pdev->dev;
  2655. ar_pci->ar = ar;
  2656. ar->dev_id = pci_dev->device;
  2657. ar_pci->pci_ps = pci_ps;
  2658. ar_pci->bus_ops = &ath10k_pci_bus_ops;
  2659. ar_pci->pci_soft_reset = pci_soft_reset;
  2660. ar_pci->pci_hard_reset = pci_hard_reset;
  2661. ar_pci->targ_cpu_to_ce_addr = targ_cpu_to_ce_addr;
  2662. ar->id.vendor = pdev->vendor;
  2663. ar->id.device = pdev->device;
  2664. ar->id.subsystem_vendor = pdev->subsystem_vendor;
  2665. ar->id.subsystem_device = pdev->subsystem_device;
  2666. setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
  2667. (unsigned long)ar);
  2668. ret = ath10k_pci_setup_resource(ar);
  2669. if (ret) {
  2670. ath10k_err(ar, "failed to setup resource: %d\n", ret);
  2671. goto err_core_destroy;
  2672. }
  2673. ret = ath10k_pci_claim(ar);
  2674. if (ret) {
  2675. ath10k_err(ar, "failed to claim device: %d\n", ret);
  2676. goto err_free_pipes;
  2677. }
  2678. ret = ath10k_pci_force_wake(ar);
  2679. if (ret) {
  2680. ath10k_warn(ar, "failed to wake up device : %d\n", ret);
  2681. goto err_sleep;
  2682. }
  2683. ath10k_pci_ce_deinit(ar);
  2684. ath10k_pci_irq_disable(ar);
  2685. ret = ath10k_pci_init_irq(ar);
  2686. if (ret) {
  2687. ath10k_err(ar, "failed to init irqs: %d\n", ret);
  2688. goto err_sleep;
  2689. }
  2690. ath10k_info(ar, "pci irq %s oper_irq_mode %d irq_mode %d reset_mode %d\n",
  2691. ath10k_pci_get_irq_method(ar), ar_pci->oper_irq_mode,
  2692. ath10k_pci_irq_mode, ath10k_pci_reset_mode);
  2693. ret = ath10k_pci_request_irq(ar);
  2694. if (ret) {
  2695. ath10k_warn(ar, "failed to request irqs: %d\n", ret);
  2696. goto err_deinit_irq;
  2697. }
  2698. ret = ath10k_pci_chip_reset(ar);
  2699. if (ret) {
  2700. ath10k_err(ar, "failed to reset chip: %d\n", ret);
  2701. goto err_free_irq;
  2702. }
  2703. chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
  2704. if (chip_id == 0xffffffff) {
  2705. ath10k_err(ar, "failed to get chip id\n");
  2706. goto err_free_irq;
  2707. }
  2708. if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
  2709. ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
  2710. pdev->device, chip_id);
  2711. goto err_free_irq;
  2712. }
  2713. ret = ath10k_core_register(ar, chip_id);
  2714. if (ret) {
  2715. ath10k_err(ar, "failed to register driver core: %d\n", ret);
  2716. goto err_free_irq;
  2717. }
  2718. return 0;
  2719. err_free_irq:
  2720. ath10k_pci_free_irq(ar);
  2721. ath10k_pci_rx_retry_sync(ar);
  2722. err_deinit_irq:
  2723. ath10k_pci_deinit_irq(ar);
  2724. err_sleep:
  2725. ath10k_pci_sleep_sync(ar);
  2726. ath10k_pci_release(ar);
  2727. err_free_pipes:
  2728. ath10k_pci_free_pipes(ar);
  2729. err_core_destroy:
  2730. ath10k_core_destroy(ar);
  2731. return ret;
  2732. }
  2733. static void ath10k_pci_remove(struct pci_dev *pdev)
  2734. {
  2735. struct ath10k *ar = pci_get_drvdata(pdev);
  2736. struct ath10k_pci *ar_pci;
  2737. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
  2738. if (!ar)
  2739. return;
  2740. ar_pci = ath10k_pci_priv(ar);
  2741. if (!ar_pci)
  2742. return;
  2743. ath10k_core_unregister(ar);
  2744. ath10k_pci_free_irq(ar);
  2745. ath10k_pci_deinit_irq(ar);
  2746. ath10k_pci_release_resource(ar);
  2747. ath10k_pci_sleep_sync(ar);
  2748. ath10k_pci_release(ar);
  2749. ath10k_core_destroy(ar);
  2750. }
  2751. MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
  2752. static struct pci_driver ath10k_pci_driver = {
  2753. .name = "ath10k_pci",
  2754. .id_table = ath10k_pci_id_table,
  2755. .probe = ath10k_pci_probe,
  2756. .remove = ath10k_pci_remove,
  2757. };
  2758. static int __init ath10k_pci_init(void)
  2759. {
  2760. int ret;
  2761. ret = pci_register_driver(&ath10k_pci_driver);
  2762. if (ret)
  2763. printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
  2764. ret);
  2765. ret = ath10k_ahb_init();
  2766. if (ret)
  2767. printk(KERN_ERR "ahb init failed: %d\n", ret);
  2768. return ret;
  2769. }
  2770. module_init(ath10k_pci_init);
  2771. static void __exit ath10k_pci_exit(void)
  2772. {
  2773. pci_unregister_driver(&ath10k_pci_driver);
  2774. ath10k_ahb_exit();
  2775. }
  2776. module_exit(ath10k_pci_exit);
  2777. MODULE_AUTHOR("Qualcomm Atheros");
  2778. MODULE_DESCRIPTION("Driver support for Qualcomm Atheros 802.11ac WLAN PCIe/AHB devices");
  2779. MODULE_LICENSE("Dual BSD/GPL");
  2780. /* QCA988x 2.0 firmware files */
  2781. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
  2782. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
  2783. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2784. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2785. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
  2786. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2787. /* QCA9887 1.0 firmware files */
  2788. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2789. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" QCA9887_HW_1_0_BOARD_DATA_FILE);
  2790. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2791. /* QCA6174 2.1 firmware files */
  2792. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
  2793. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
  2794. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
  2795. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2796. /* QCA6174 3.1 firmware files */
  2797. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2798. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2799. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
  2800. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2801. /* QCA9377 1.0 firmware files */
  2802. MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2803. MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);