pci.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437
  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. */
  604. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  605. 0);
  606. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
  607. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  608. /* IMPORTANT: this extra read transaction is required to
  609. * flush the posted write buffer.
  610. */
  611. (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  612. PCIE_INTR_ENABLE_ADDRESS);
  613. }
  614. void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
  615. {
  616. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  617. PCIE_INTR_ENABLE_ADDRESS,
  618. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  619. /* IMPORTANT: this extra read transaction is required to
  620. * flush the posted write buffer.
  621. */
  622. (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  623. PCIE_INTR_ENABLE_ADDRESS);
  624. }
  625. static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
  626. {
  627. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  628. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_MSI)
  629. return "msi";
  630. return "legacy";
  631. }
  632. static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
  633. {
  634. struct ath10k *ar = pipe->hif_ce_state;
  635. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  636. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  637. struct sk_buff *skb;
  638. dma_addr_t paddr;
  639. int ret;
  640. skb = dev_alloc_skb(pipe->buf_sz);
  641. if (!skb)
  642. return -ENOMEM;
  643. WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
  644. paddr = dma_map_single(ar->dev, skb->data,
  645. skb->len + skb_tailroom(skb),
  646. DMA_FROM_DEVICE);
  647. if (unlikely(dma_mapping_error(ar->dev, paddr))) {
  648. ath10k_warn(ar, "failed to dma map pci rx buf\n");
  649. dev_kfree_skb_any(skb);
  650. return -EIO;
  651. }
  652. ATH10K_SKB_RXCB(skb)->paddr = paddr;
  653. spin_lock_bh(&ar_pci->ce_lock);
  654. ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
  655. spin_unlock_bh(&ar_pci->ce_lock);
  656. if (ret) {
  657. dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
  658. DMA_FROM_DEVICE);
  659. dev_kfree_skb_any(skb);
  660. return ret;
  661. }
  662. return 0;
  663. }
  664. static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
  665. {
  666. struct ath10k *ar = pipe->hif_ce_state;
  667. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  668. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  669. int ret, num;
  670. if (pipe->buf_sz == 0)
  671. return;
  672. if (!ce_pipe->dest_ring)
  673. return;
  674. spin_lock_bh(&ar_pci->ce_lock);
  675. num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
  676. spin_unlock_bh(&ar_pci->ce_lock);
  677. while (num >= 0) {
  678. ret = __ath10k_pci_rx_post_buf(pipe);
  679. if (ret) {
  680. if (ret == -ENOSPC)
  681. break;
  682. ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
  683. mod_timer(&ar_pci->rx_post_retry, jiffies +
  684. ATH10K_PCI_RX_POST_RETRY_MS);
  685. break;
  686. }
  687. num--;
  688. }
  689. }
  690. void ath10k_pci_rx_post(struct ath10k *ar)
  691. {
  692. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  693. int i;
  694. for (i = 0; i < CE_COUNT; i++)
  695. ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
  696. }
  697. void ath10k_pci_rx_replenish_retry(unsigned long ptr)
  698. {
  699. struct ath10k *ar = (void *)ptr;
  700. ath10k_pci_rx_post(ar);
  701. }
  702. static u32 ath10k_pci_qca988x_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  703. {
  704. u32 val = 0, region = addr & 0xfffff;
  705. val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS)
  706. & 0x7ff) << 21;
  707. val |= 0x100000 | region;
  708. return val;
  709. }
  710. static u32 ath10k_pci_qca99x0_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  711. {
  712. u32 val = 0, region = addr & 0xfffff;
  713. val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
  714. val |= 0x100000 | region;
  715. return val;
  716. }
  717. static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
  718. {
  719. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  720. if (WARN_ON_ONCE(!ar_pci->targ_cpu_to_ce_addr))
  721. return -ENOTSUPP;
  722. return ar_pci->targ_cpu_to_ce_addr(ar, addr);
  723. }
  724. /*
  725. * Diagnostic read/write access is provided for startup/config/debug usage.
  726. * Caller must guarantee proper alignment, when applicable, and single user
  727. * at any moment.
  728. */
  729. static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
  730. int nbytes)
  731. {
  732. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  733. int ret = 0;
  734. u32 *buf;
  735. unsigned int completed_nbytes, alloc_nbytes, remaining_bytes;
  736. struct ath10k_ce_pipe *ce_diag;
  737. /* Host buffer address in CE space */
  738. u32 ce_data;
  739. dma_addr_t ce_data_base = 0;
  740. void *data_buf = NULL;
  741. int i;
  742. spin_lock_bh(&ar_pci->ce_lock);
  743. ce_diag = ar_pci->ce_diag;
  744. /*
  745. * Allocate a temporary bounce buffer to hold caller's data
  746. * to be DMA'ed from Target. This guarantees
  747. * 1) 4-byte alignment
  748. * 2) Buffer in DMA-able space
  749. */
  750. alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT);
  751. data_buf = (unsigned char *)dma_zalloc_coherent(ar->dev,
  752. alloc_nbytes,
  753. &ce_data_base,
  754. GFP_ATOMIC);
  755. if (!data_buf) {
  756. ret = -ENOMEM;
  757. goto done;
  758. }
  759. remaining_bytes = nbytes;
  760. ce_data = ce_data_base;
  761. while (remaining_bytes) {
  762. nbytes = min_t(unsigned int, remaining_bytes,
  763. DIAG_TRANSFER_LIMIT);
  764. ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, ce_data);
  765. if (ret != 0)
  766. goto done;
  767. /* Request CE to send from Target(!) address to Host buffer */
  768. /*
  769. * The address supplied by the caller is in the
  770. * Target CPU virtual address space.
  771. *
  772. * In order to use this address with the diagnostic CE,
  773. * convert it from Target CPU virtual address space
  774. * to CE address space
  775. */
  776. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  777. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
  778. 0);
  779. if (ret)
  780. goto done;
  781. i = 0;
  782. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  783. NULL) != 0) {
  784. mdelay(1);
  785. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  786. ret = -EBUSY;
  787. goto done;
  788. }
  789. }
  790. i = 0;
  791. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  792. (void **)&buf,
  793. &completed_nbytes)
  794. != 0) {
  795. mdelay(1);
  796. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  797. ret = -EBUSY;
  798. goto done;
  799. }
  800. }
  801. if (nbytes != completed_nbytes) {
  802. ret = -EIO;
  803. goto done;
  804. }
  805. if (*buf != ce_data) {
  806. ret = -EIO;
  807. goto done;
  808. }
  809. remaining_bytes -= nbytes;
  810. memcpy(data, data_buf, nbytes);
  811. address += nbytes;
  812. data += nbytes;
  813. }
  814. done:
  815. if (data_buf)
  816. dma_free_coherent(ar->dev, alloc_nbytes, data_buf,
  817. ce_data_base);
  818. spin_unlock_bh(&ar_pci->ce_lock);
  819. return ret;
  820. }
  821. static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
  822. {
  823. __le32 val = 0;
  824. int ret;
  825. ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
  826. *value = __le32_to_cpu(val);
  827. return ret;
  828. }
  829. static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
  830. u32 src, u32 len)
  831. {
  832. u32 host_addr, addr;
  833. int ret;
  834. host_addr = host_interest_item_address(src);
  835. ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
  836. if (ret != 0) {
  837. ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
  838. src, ret);
  839. return ret;
  840. }
  841. ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
  842. if (ret != 0) {
  843. ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
  844. addr, len, ret);
  845. return ret;
  846. }
  847. return 0;
  848. }
  849. #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
  850. __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
  851. int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
  852. const void *data, int nbytes)
  853. {
  854. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  855. int ret = 0;
  856. u32 *buf;
  857. unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
  858. struct ath10k_ce_pipe *ce_diag;
  859. void *data_buf = NULL;
  860. u32 ce_data; /* Host buffer address in CE space */
  861. dma_addr_t ce_data_base = 0;
  862. int i;
  863. spin_lock_bh(&ar_pci->ce_lock);
  864. ce_diag = ar_pci->ce_diag;
  865. /*
  866. * Allocate a temporary bounce buffer to hold caller's data
  867. * to be DMA'ed to Target. This guarantees
  868. * 1) 4-byte alignment
  869. * 2) Buffer in DMA-able space
  870. */
  871. orig_nbytes = nbytes;
  872. data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
  873. orig_nbytes,
  874. &ce_data_base,
  875. GFP_ATOMIC);
  876. if (!data_buf) {
  877. ret = -ENOMEM;
  878. goto done;
  879. }
  880. /* Copy caller's data to allocated DMA buf */
  881. memcpy(data_buf, data, orig_nbytes);
  882. /*
  883. * The address supplied by the caller is in the
  884. * Target CPU virtual address space.
  885. *
  886. * In order to use this address with the diagnostic CE,
  887. * convert it from
  888. * Target CPU virtual address space
  889. * to
  890. * CE address space
  891. */
  892. address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
  893. remaining_bytes = orig_nbytes;
  894. ce_data = ce_data_base;
  895. while (remaining_bytes) {
  896. /* FIXME: check cast */
  897. nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
  898. /* Set up to receive directly into Target(!) address */
  899. ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
  900. if (ret != 0)
  901. goto done;
  902. /*
  903. * Request CE to send caller-supplied data that
  904. * was copied to bounce buffer to Target(!) address.
  905. */
  906. ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
  907. nbytes, 0, 0);
  908. if (ret != 0)
  909. goto done;
  910. i = 0;
  911. while (ath10k_ce_completed_send_next_nolock(ce_diag,
  912. NULL) != 0) {
  913. mdelay(1);
  914. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  915. ret = -EBUSY;
  916. goto done;
  917. }
  918. }
  919. i = 0;
  920. while (ath10k_ce_completed_recv_next_nolock(ce_diag,
  921. (void **)&buf,
  922. &completed_nbytes)
  923. != 0) {
  924. mdelay(1);
  925. if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
  926. ret = -EBUSY;
  927. goto done;
  928. }
  929. }
  930. if (nbytes != completed_nbytes) {
  931. ret = -EIO;
  932. goto done;
  933. }
  934. if (*buf != address) {
  935. ret = -EIO;
  936. goto done;
  937. }
  938. remaining_bytes -= nbytes;
  939. address += nbytes;
  940. ce_data += nbytes;
  941. }
  942. done:
  943. if (data_buf) {
  944. dma_free_coherent(ar->dev, orig_nbytes, data_buf,
  945. ce_data_base);
  946. }
  947. if (ret != 0)
  948. ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
  949. address, ret);
  950. spin_unlock_bh(&ar_pci->ce_lock);
  951. return ret;
  952. }
  953. static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
  954. {
  955. __le32 val = __cpu_to_le32(value);
  956. return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
  957. }
  958. /* Called by lower (CE) layer when a send to Target completes. */
  959. static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
  960. {
  961. struct ath10k *ar = ce_state->ar;
  962. struct sk_buff_head list;
  963. struct sk_buff *skb;
  964. __skb_queue_head_init(&list);
  965. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  966. /* no need to call tx completion for NULL pointers */
  967. if (skb == NULL)
  968. continue;
  969. __skb_queue_tail(&list, skb);
  970. }
  971. while ((skb = __skb_dequeue(&list)))
  972. ath10k_htc_tx_completion_handler(ar, skb);
  973. }
  974. static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
  975. void (*callback)(struct ath10k *ar,
  976. struct sk_buff *skb))
  977. {
  978. struct ath10k *ar = ce_state->ar;
  979. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  980. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  981. struct sk_buff *skb;
  982. struct sk_buff_head list;
  983. void *transfer_context;
  984. unsigned int nbytes, max_nbytes;
  985. __skb_queue_head_init(&list);
  986. while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
  987. &nbytes) == 0) {
  988. skb = transfer_context;
  989. max_nbytes = skb->len + skb_tailroom(skb);
  990. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  991. max_nbytes, DMA_FROM_DEVICE);
  992. if (unlikely(max_nbytes < nbytes)) {
  993. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  994. nbytes, max_nbytes);
  995. dev_kfree_skb_any(skb);
  996. continue;
  997. }
  998. skb_put(skb, nbytes);
  999. __skb_queue_tail(&list, skb);
  1000. }
  1001. while ((skb = __skb_dequeue(&list))) {
  1002. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1003. ce_state->id, skb->len);
  1004. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1005. skb->data, skb->len);
  1006. callback(ar, skb);
  1007. }
  1008. ath10k_pci_rx_post_pipe(pipe_info);
  1009. }
  1010. static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
  1011. void (*callback)(struct ath10k *ar,
  1012. struct sk_buff *skb))
  1013. {
  1014. struct ath10k *ar = ce_state->ar;
  1015. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1016. struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
  1017. struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
  1018. struct sk_buff *skb;
  1019. struct sk_buff_head list;
  1020. void *transfer_context;
  1021. unsigned int nbytes, max_nbytes, nentries;
  1022. int orig_len;
  1023. /* No need to aquire ce_lock for CE5, since this is the only place CE5
  1024. * is processed other than init and deinit. Before releasing CE5
  1025. * buffers, interrupts are disabled. Thus CE5 access is serialized.
  1026. */
  1027. __skb_queue_head_init(&list);
  1028. while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
  1029. &nbytes) == 0) {
  1030. skb = transfer_context;
  1031. max_nbytes = skb->len + skb_tailroom(skb);
  1032. if (unlikely(max_nbytes < nbytes)) {
  1033. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  1034. nbytes, max_nbytes);
  1035. continue;
  1036. }
  1037. dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1038. max_nbytes, DMA_FROM_DEVICE);
  1039. skb_put(skb, nbytes);
  1040. __skb_queue_tail(&list, skb);
  1041. }
  1042. nentries = skb_queue_len(&list);
  1043. while ((skb = __skb_dequeue(&list))) {
  1044. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
  1045. ce_state->id, skb->len);
  1046. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
  1047. skb->data, skb->len);
  1048. orig_len = skb->len;
  1049. callback(ar, skb);
  1050. skb_push(skb, orig_len - skb->len);
  1051. skb_reset_tail_pointer(skb);
  1052. skb_trim(skb, 0);
  1053. /*let device gain the buffer again*/
  1054. dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1055. skb->len + skb_tailroom(skb),
  1056. DMA_FROM_DEVICE);
  1057. }
  1058. ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
  1059. }
  1060. /* Called by lower (CE) layer when data is received from the Target. */
  1061. static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1062. {
  1063. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1064. }
  1065. static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  1066. {
  1067. /* CE4 polling needs to be done whenever CE pipe which transports
  1068. * HTT Rx (target->host) is processed.
  1069. */
  1070. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1071. ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  1072. }
  1073. /* Called by lower (CE) layer when data is received from the Target.
  1074. * Only 10.4 firmware uses separate CE to transfer pktlog data.
  1075. */
  1076. static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
  1077. {
  1078. ath10k_pci_process_rx_cb(ce_state,
  1079. ath10k_htt_rx_pktlog_completion_handler);
  1080. }
  1081. /* Called by lower (CE) layer when a send to HTT Target completes. */
  1082. static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
  1083. {
  1084. struct ath10k *ar = ce_state->ar;
  1085. struct sk_buff *skb;
  1086. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  1087. /* no need to call tx completion for NULL pointers */
  1088. if (!skb)
  1089. continue;
  1090. dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
  1091. skb->len, DMA_TO_DEVICE);
  1092. ath10k_htt_hif_tx_complete(ar, skb);
  1093. }
  1094. }
  1095. static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
  1096. {
  1097. skb_pull(skb, sizeof(struct ath10k_htc_hdr));
  1098. ath10k_htt_t2h_msg_handler(ar, skb);
  1099. }
  1100. /* Called by lower (CE) layer when HTT data is received from the Target. */
  1101. static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
  1102. {
  1103. /* CE4 polling needs to be done whenever CE pipe which transports
  1104. * HTT Rx (target->host) is processed.
  1105. */
  1106. ath10k_ce_per_engine_service(ce_state->ar, 4);
  1107. ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
  1108. }
  1109. int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  1110. struct ath10k_hif_sg_item *items, int n_items)
  1111. {
  1112. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1113. struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
  1114. struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
  1115. struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
  1116. unsigned int nentries_mask;
  1117. unsigned int sw_index;
  1118. unsigned int write_index;
  1119. int err, i = 0;
  1120. spin_lock_bh(&ar_pci->ce_lock);
  1121. nentries_mask = src_ring->nentries_mask;
  1122. sw_index = src_ring->sw_index;
  1123. write_index = src_ring->write_index;
  1124. if (unlikely(CE_RING_DELTA(nentries_mask,
  1125. write_index, sw_index - 1) < n_items)) {
  1126. err = -ENOBUFS;
  1127. goto err;
  1128. }
  1129. for (i = 0; i < n_items - 1; i++) {
  1130. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1131. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1132. i, items[i].paddr, items[i].len, n_items);
  1133. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1134. items[i].vaddr, items[i].len);
  1135. err = ath10k_ce_send_nolock(ce_pipe,
  1136. items[i].transfer_context,
  1137. items[i].paddr,
  1138. items[i].len,
  1139. items[i].transfer_id,
  1140. CE_SEND_FLAG_GATHER);
  1141. if (err)
  1142. goto err;
  1143. }
  1144. /* `i` is equal to `n_items -1` after for() */
  1145. ath10k_dbg(ar, ATH10K_DBG_PCI,
  1146. "pci tx item %d paddr 0x%08x len %d n_items %d\n",
  1147. i, items[i].paddr, items[i].len, n_items);
  1148. ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
  1149. items[i].vaddr, items[i].len);
  1150. err = ath10k_ce_send_nolock(ce_pipe,
  1151. items[i].transfer_context,
  1152. items[i].paddr,
  1153. items[i].len,
  1154. items[i].transfer_id,
  1155. 0);
  1156. if (err)
  1157. goto err;
  1158. spin_unlock_bh(&ar_pci->ce_lock);
  1159. return 0;
  1160. err:
  1161. for (; i > 0; i--)
  1162. __ath10k_ce_send_revert(ce_pipe);
  1163. spin_unlock_bh(&ar_pci->ce_lock);
  1164. return err;
  1165. }
  1166. int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
  1167. size_t buf_len)
  1168. {
  1169. return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
  1170. }
  1171. u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
  1172. {
  1173. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1174. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
  1175. return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
  1176. }
  1177. static void ath10k_pci_dump_registers(struct ath10k *ar,
  1178. struct ath10k_fw_crash_data *crash_data)
  1179. {
  1180. __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
  1181. int i, ret;
  1182. lockdep_assert_held(&ar->data_lock);
  1183. ret = ath10k_pci_diag_read_hi(ar, &reg_dump_values[0],
  1184. hi_failure_state,
  1185. REG_DUMP_COUNT_QCA988X * sizeof(__le32));
  1186. if (ret) {
  1187. ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
  1188. return;
  1189. }
  1190. BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
  1191. ath10k_err(ar, "firmware register dump:\n");
  1192. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
  1193. ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
  1194. i,
  1195. __le32_to_cpu(reg_dump_values[i]),
  1196. __le32_to_cpu(reg_dump_values[i + 1]),
  1197. __le32_to_cpu(reg_dump_values[i + 2]),
  1198. __le32_to_cpu(reg_dump_values[i + 3]));
  1199. if (!crash_data)
  1200. return;
  1201. for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
  1202. crash_data->registers[i] = reg_dump_values[i];
  1203. }
  1204. static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
  1205. {
  1206. struct ath10k_fw_crash_data *crash_data;
  1207. char uuid[50];
  1208. spin_lock_bh(&ar->data_lock);
  1209. ar->stats.fw_crash_counter++;
  1210. crash_data = ath10k_debug_get_new_fw_crash_data(ar);
  1211. if (crash_data)
  1212. scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
  1213. else
  1214. scnprintf(uuid, sizeof(uuid), "n/a");
  1215. ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
  1216. ath10k_print_driver_info(ar);
  1217. ath10k_pci_dump_registers(ar, crash_data);
  1218. ath10k_ce_dump_registers(ar, crash_data);
  1219. spin_unlock_bh(&ar->data_lock);
  1220. queue_work(ar->workqueue, &ar->restart_work);
  1221. }
  1222. void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  1223. int force)
  1224. {
  1225. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
  1226. if (!force) {
  1227. int resources;
  1228. /*
  1229. * Decide whether to actually poll for completions, or just
  1230. * wait for a later chance.
  1231. * If there seem to be plenty of resources left, then just wait
  1232. * since checking involves reading a CE register, which is a
  1233. * relatively expensive operation.
  1234. */
  1235. resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
  1236. /*
  1237. * If at least 50% of the total resources are still available,
  1238. * don't bother checking again yet.
  1239. */
  1240. if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
  1241. return;
  1242. }
  1243. ath10k_ce_per_engine_service(ar, pipe);
  1244. }
  1245. static void ath10k_pci_rx_retry_sync(struct ath10k *ar)
  1246. {
  1247. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1248. del_timer_sync(&ar_pci->rx_post_retry);
  1249. }
  1250. int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
  1251. u8 *ul_pipe, u8 *dl_pipe)
  1252. {
  1253. const struct service_to_pipe *entry;
  1254. bool ul_set = false, dl_set = false;
  1255. int i;
  1256. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
  1257. for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
  1258. entry = &target_service_to_ce_map_wlan[i];
  1259. if (__le32_to_cpu(entry->service_id) != service_id)
  1260. continue;
  1261. switch (__le32_to_cpu(entry->pipedir)) {
  1262. case PIPEDIR_NONE:
  1263. break;
  1264. case PIPEDIR_IN:
  1265. WARN_ON(dl_set);
  1266. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1267. dl_set = true;
  1268. break;
  1269. case PIPEDIR_OUT:
  1270. WARN_ON(ul_set);
  1271. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1272. ul_set = true;
  1273. break;
  1274. case PIPEDIR_INOUT:
  1275. WARN_ON(dl_set);
  1276. WARN_ON(ul_set);
  1277. *dl_pipe = __le32_to_cpu(entry->pipenum);
  1278. *ul_pipe = __le32_to_cpu(entry->pipenum);
  1279. dl_set = true;
  1280. ul_set = true;
  1281. break;
  1282. }
  1283. }
  1284. if (WARN_ON(!ul_set || !dl_set))
  1285. return -ENOENT;
  1286. return 0;
  1287. }
  1288. void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
  1289. u8 *ul_pipe, u8 *dl_pipe)
  1290. {
  1291. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
  1292. (void)ath10k_pci_hif_map_service_to_pipe(ar,
  1293. ATH10K_HTC_SVC_ID_RSVD_CTRL,
  1294. ul_pipe, dl_pipe);
  1295. }
  1296. void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
  1297. {
  1298. u32 val;
  1299. switch (ar->hw_rev) {
  1300. case ATH10K_HW_QCA988X:
  1301. case ATH10K_HW_QCA9887:
  1302. case ATH10K_HW_QCA6174:
  1303. case ATH10K_HW_QCA9377:
  1304. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1305. CORE_CTRL_ADDRESS);
  1306. val &= ~CORE_CTRL_PCIE_REG_31_MASK;
  1307. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1308. CORE_CTRL_ADDRESS, val);
  1309. break;
  1310. case ATH10K_HW_QCA99X0:
  1311. case ATH10K_HW_QCA9984:
  1312. case ATH10K_HW_QCA9888:
  1313. case ATH10K_HW_QCA4019:
  1314. /* TODO: Find appropriate register configuration for QCA99X0
  1315. * to mask irq/MSI.
  1316. */
  1317. break;
  1318. }
  1319. }
  1320. static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
  1321. {
  1322. u32 val;
  1323. switch (ar->hw_rev) {
  1324. case ATH10K_HW_QCA988X:
  1325. case ATH10K_HW_QCA9887:
  1326. case ATH10K_HW_QCA6174:
  1327. case ATH10K_HW_QCA9377:
  1328. val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
  1329. CORE_CTRL_ADDRESS);
  1330. val |= CORE_CTRL_PCIE_REG_31_MASK;
  1331. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
  1332. CORE_CTRL_ADDRESS, val);
  1333. break;
  1334. case ATH10K_HW_QCA99X0:
  1335. case ATH10K_HW_QCA9984:
  1336. case ATH10K_HW_QCA9888:
  1337. case ATH10K_HW_QCA4019:
  1338. /* TODO: Find appropriate register configuration for QCA99X0
  1339. * to unmask irq/MSI.
  1340. */
  1341. break;
  1342. }
  1343. }
  1344. static void ath10k_pci_irq_disable(struct ath10k *ar)
  1345. {
  1346. ath10k_ce_disable_interrupts(ar);
  1347. ath10k_pci_disable_and_clear_legacy_irq(ar);
  1348. ath10k_pci_irq_msi_fw_mask(ar);
  1349. }
  1350. static void ath10k_pci_irq_sync(struct ath10k *ar)
  1351. {
  1352. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1353. synchronize_irq(ar_pci->pdev->irq);
  1354. }
  1355. static void ath10k_pci_irq_enable(struct ath10k *ar)
  1356. {
  1357. ath10k_ce_enable_interrupts(ar);
  1358. ath10k_pci_enable_legacy_irq(ar);
  1359. ath10k_pci_irq_msi_fw_unmask(ar);
  1360. }
  1361. static int ath10k_pci_hif_start(struct ath10k *ar)
  1362. {
  1363. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1364. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
  1365. napi_enable(&ar->napi);
  1366. ath10k_pci_irq_enable(ar);
  1367. ath10k_pci_rx_post(ar);
  1368. pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  1369. ar_pci->link_ctl);
  1370. return 0;
  1371. }
  1372. static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
  1373. {
  1374. struct ath10k *ar;
  1375. struct ath10k_ce_pipe *ce_pipe;
  1376. struct ath10k_ce_ring *ce_ring;
  1377. struct sk_buff *skb;
  1378. int i;
  1379. ar = pci_pipe->hif_ce_state;
  1380. ce_pipe = pci_pipe->ce_hdl;
  1381. ce_ring = ce_pipe->dest_ring;
  1382. if (!ce_ring)
  1383. return;
  1384. if (!pci_pipe->buf_sz)
  1385. return;
  1386. for (i = 0; i < ce_ring->nentries; i++) {
  1387. skb = ce_ring->per_transfer_context[i];
  1388. if (!skb)
  1389. continue;
  1390. ce_ring->per_transfer_context[i] = NULL;
  1391. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  1392. skb->len + skb_tailroom(skb),
  1393. DMA_FROM_DEVICE);
  1394. dev_kfree_skb_any(skb);
  1395. }
  1396. }
  1397. static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
  1398. {
  1399. struct ath10k *ar;
  1400. struct ath10k_ce_pipe *ce_pipe;
  1401. struct ath10k_ce_ring *ce_ring;
  1402. struct sk_buff *skb;
  1403. int i;
  1404. ar = pci_pipe->hif_ce_state;
  1405. ce_pipe = pci_pipe->ce_hdl;
  1406. ce_ring = ce_pipe->src_ring;
  1407. if (!ce_ring)
  1408. return;
  1409. if (!pci_pipe->buf_sz)
  1410. return;
  1411. for (i = 0; i < ce_ring->nentries; i++) {
  1412. skb = ce_ring->per_transfer_context[i];
  1413. if (!skb)
  1414. continue;
  1415. ce_ring->per_transfer_context[i] = NULL;
  1416. ath10k_htc_tx_completion_handler(ar, skb);
  1417. }
  1418. }
  1419. /*
  1420. * Cleanup residual buffers for device shutdown:
  1421. * buffers that were enqueued for receive
  1422. * buffers that were to be sent
  1423. * Note: Buffers that had completed but which were
  1424. * not yet processed are on a completion queue. They
  1425. * are handled when the completion thread shuts down.
  1426. */
  1427. static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
  1428. {
  1429. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1430. int pipe_num;
  1431. for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
  1432. struct ath10k_pci_pipe *pipe_info;
  1433. pipe_info = &ar_pci->pipe_info[pipe_num];
  1434. ath10k_pci_rx_pipe_cleanup(pipe_info);
  1435. ath10k_pci_tx_pipe_cleanup(pipe_info);
  1436. }
  1437. }
  1438. void ath10k_pci_ce_deinit(struct ath10k *ar)
  1439. {
  1440. int i;
  1441. for (i = 0; i < CE_COUNT; i++)
  1442. ath10k_ce_deinit_pipe(ar, i);
  1443. }
  1444. void ath10k_pci_flush(struct ath10k *ar)
  1445. {
  1446. ath10k_pci_rx_retry_sync(ar);
  1447. ath10k_pci_buffer_cleanup(ar);
  1448. }
  1449. static void ath10k_pci_hif_stop(struct ath10k *ar)
  1450. {
  1451. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1452. unsigned long flags;
  1453. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
  1454. /* Most likely the device has HTT Rx ring configured. The only way to
  1455. * prevent the device from accessing (and possible corrupting) host
  1456. * memory is to reset the chip now.
  1457. *
  1458. * There's also no known way of masking MSI interrupts on the device.
  1459. * For ranged MSI the CE-related interrupts can be masked. However
  1460. * regardless how many MSI interrupts are assigned the first one
  1461. * is always used for firmware indications (crashes) and cannot be
  1462. * masked. To prevent the device from asserting the interrupt reset it
  1463. * before proceeding with cleanup.
  1464. */
  1465. ath10k_pci_safe_chip_reset(ar);
  1466. ath10k_pci_irq_disable(ar);
  1467. ath10k_pci_irq_sync(ar);
  1468. ath10k_pci_flush(ar);
  1469. napi_synchronize(&ar->napi);
  1470. napi_disable(&ar->napi);
  1471. spin_lock_irqsave(&ar_pci->ps_lock, flags);
  1472. WARN_ON(ar_pci->ps_wake_refcount > 0);
  1473. spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
  1474. }
  1475. int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
  1476. void *req, u32 req_len,
  1477. void *resp, u32 *resp_len)
  1478. {
  1479. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1480. struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
  1481. struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
  1482. struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
  1483. struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
  1484. dma_addr_t req_paddr = 0;
  1485. dma_addr_t resp_paddr = 0;
  1486. struct bmi_xfer xfer = {};
  1487. void *treq, *tresp = NULL;
  1488. int ret = 0;
  1489. might_sleep();
  1490. if (resp && !resp_len)
  1491. return -EINVAL;
  1492. if (resp && resp_len && *resp_len == 0)
  1493. return -EINVAL;
  1494. treq = kmemdup(req, req_len, GFP_KERNEL);
  1495. if (!treq)
  1496. return -ENOMEM;
  1497. req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
  1498. ret = dma_mapping_error(ar->dev, req_paddr);
  1499. if (ret) {
  1500. ret = -EIO;
  1501. goto err_dma;
  1502. }
  1503. if (resp && resp_len) {
  1504. tresp = kzalloc(*resp_len, GFP_KERNEL);
  1505. if (!tresp) {
  1506. ret = -ENOMEM;
  1507. goto err_req;
  1508. }
  1509. resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
  1510. DMA_FROM_DEVICE);
  1511. ret = dma_mapping_error(ar->dev, resp_paddr);
  1512. if (ret) {
  1513. ret = -EIO;
  1514. goto err_req;
  1515. }
  1516. xfer.wait_for_resp = true;
  1517. xfer.resp_len = 0;
  1518. ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
  1519. }
  1520. ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
  1521. if (ret)
  1522. goto err_resp;
  1523. ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
  1524. if (ret) {
  1525. u32 unused_buffer;
  1526. unsigned int unused_nbytes;
  1527. unsigned int unused_id;
  1528. ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
  1529. &unused_nbytes, &unused_id);
  1530. } else {
  1531. /* non-zero means we did not time out */
  1532. ret = 0;
  1533. }
  1534. err_resp:
  1535. if (resp) {
  1536. u32 unused_buffer;
  1537. ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
  1538. dma_unmap_single(ar->dev, resp_paddr,
  1539. *resp_len, DMA_FROM_DEVICE);
  1540. }
  1541. err_req:
  1542. dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
  1543. if (ret == 0 && resp_len) {
  1544. *resp_len = min(*resp_len, xfer.resp_len);
  1545. memcpy(resp, tresp, xfer.resp_len);
  1546. }
  1547. err_dma:
  1548. kfree(treq);
  1549. kfree(tresp);
  1550. return ret;
  1551. }
  1552. static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
  1553. {
  1554. struct bmi_xfer *xfer;
  1555. if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
  1556. return;
  1557. xfer->tx_done = true;
  1558. }
  1559. static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
  1560. {
  1561. struct ath10k *ar = ce_state->ar;
  1562. struct bmi_xfer *xfer;
  1563. unsigned int nbytes;
  1564. if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer,
  1565. &nbytes))
  1566. return;
  1567. if (WARN_ON_ONCE(!xfer))
  1568. return;
  1569. if (!xfer->wait_for_resp) {
  1570. ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
  1571. return;
  1572. }
  1573. xfer->resp_len = nbytes;
  1574. xfer->rx_done = true;
  1575. }
  1576. static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
  1577. struct ath10k_ce_pipe *rx_pipe,
  1578. struct bmi_xfer *xfer)
  1579. {
  1580. unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
  1581. while (time_before_eq(jiffies, timeout)) {
  1582. ath10k_pci_bmi_send_done(tx_pipe);
  1583. ath10k_pci_bmi_recv_data(rx_pipe);
  1584. if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
  1585. return 0;
  1586. schedule();
  1587. }
  1588. return -ETIMEDOUT;
  1589. }
  1590. /*
  1591. * Send an interrupt to the device to wake up the Target CPU
  1592. * so it has an opportunity to notice any changed state.
  1593. */
  1594. static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
  1595. {
  1596. u32 addr, val;
  1597. addr = SOC_CORE_BASE_ADDRESS + CORE_CTRL_ADDRESS;
  1598. val = ath10k_pci_read32(ar, addr);
  1599. val |= CORE_CTRL_CPU_INTR_MASK;
  1600. ath10k_pci_write32(ar, addr, val);
  1601. return 0;
  1602. }
  1603. static int ath10k_pci_get_num_banks(struct ath10k *ar)
  1604. {
  1605. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1606. switch (ar_pci->pdev->device) {
  1607. case QCA988X_2_0_DEVICE_ID:
  1608. case QCA99X0_2_0_DEVICE_ID:
  1609. case QCA9888_2_0_DEVICE_ID:
  1610. case QCA9984_1_0_DEVICE_ID:
  1611. case QCA9887_1_0_DEVICE_ID:
  1612. return 1;
  1613. case QCA6164_2_1_DEVICE_ID:
  1614. case QCA6174_2_1_DEVICE_ID:
  1615. switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
  1616. case QCA6174_HW_1_0_CHIP_ID_REV:
  1617. case QCA6174_HW_1_1_CHIP_ID_REV:
  1618. case QCA6174_HW_2_1_CHIP_ID_REV:
  1619. case QCA6174_HW_2_2_CHIP_ID_REV:
  1620. return 3;
  1621. case QCA6174_HW_1_3_CHIP_ID_REV:
  1622. return 2;
  1623. case QCA6174_HW_3_0_CHIP_ID_REV:
  1624. case QCA6174_HW_3_1_CHIP_ID_REV:
  1625. case QCA6174_HW_3_2_CHIP_ID_REV:
  1626. return 9;
  1627. }
  1628. break;
  1629. case QCA9377_1_0_DEVICE_ID:
  1630. return 4;
  1631. }
  1632. ath10k_warn(ar, "unknown number of banks, assuming 1\n");
  1633. return 1;
  1634. }
  1635. static int ath10k_bus_get_num_banks(struct ath10k *ar)
  1636. {
  1637. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1638. return ar_pci->bus_ops->get_num_banks(ar);
  1639. }
  1640. int ath10k_pci_init_config(struct ath10k *ar)
  1641. {
  1642. u32 interconnect_targ_addr;
  1643. u32 pcie_state_targ_addr = 0;
  1644. u32 pipe_cfg_targ_addr = 0;
  1645. u32 svc_to_pipe_map = 0;
  1646. u32 pcie_config_flags = 0;
  1647. u32 ealloc_value;
  1648. u32 ealloc_targ_addr;
  1649. u32 flag2_value;
  1650. u32 flag2_targ_addr;
  1651. int ret = 0;
  1652. /* Download to Target the CE Config and the service-to-CE map */
  1653. interconnect_targ_addr =
  1654. host_interest_item_address(HI_ITEM(hi_interconnect_state));
  1655. /* Supply Target-side CE configuration */
  1656. ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
  1657. &pcie_state_targ_addr);
  1658. if (ret != 0) {
  1659. ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
  1660. return ret;
  1661. }
  1662. if (pcie_state_targ_addr == 0) {
  1663. ret = -EIO;
  1664. ath10k_err(ar, "Invalid pcie state addr\n");
  1665. return ret;
  1666. }
  1667. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1668. offsetof(struct pcie_state,
  1669. pipe_cfg_addr)),
  1670. &pipe_cfg_targ_addr);
  1671. if (ret != 0) {
  1672. ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
  1673. return ret;
  1674. }
  1675. if (pipe_cfg_targ_addr == 0) {
  1676. ret = -EIO;
  1677. ath10k_err(ar, "Invalid pipe cfg addr\n");
  1678. return ret;
  1679. }
  1680. ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
  1681. target_ce_config_wlan,
  1682. sizeof(struct ce_pipe_config) *
  1683. NUM_TARGET_CE_CONFIG_WLAN);
  1684. if (ret != 0) {
  1685. ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
  1686. return ret;
  1687. }
  1688. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1689. offsetof(struct pcie_state,
  1690. svc_to_pipe_map)),
  1691. &svc_to_pipe_map);
  1692. if (ret != 0) {
  1693. ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
  1694. return ret;
  1695. }
  1696. if (svc_to_pipe_map == 0) {
  1697. ret = -EIO;
  1698. ath10k_err(ar, "Invalid svc_to_pipe map\n");
  1699. return ret;
  1700. }
  1701. ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
  1702. target_service_to_ce_map_wlan,
  1703. sizeof(target_service_to_ce_map_wlan));
  1704. if (ret != 0) {
  1705. ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
  1706. return ret;
  1707. }
  1708. ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
  1709. offsetof(struct pcie_state,
  1710. config_flags)),
  1711. &pcie_config_flags);
  1712. if (ret != 0) {
  1713. ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
  1714. return ret;
  1715. }
  1716. pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
  1717. ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
  1718. offsetof(struct pcie_state,
  1719. config_flags)),
  1720. pcie_config_flags);
  1721. if (ret != 0) {
  1722. ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
  1723. return ret;
  1724. }
  1725. /* configure early allocation */
  1726. ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
  1727. ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
  1728. if (ret != 0) {
  1729. ath10k_err(ar, "Failed to get early alloc val: %d\n", ret);
  1730. return ret;
  1731. }
  1732. /* first bank is switched to IRAM */
  1733. ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
  1734. HI_EARLY_ALLOC_MAGIC_MASK);
  1735. ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
  1736. HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
  1737. HI_EARLY_ALLOC_IRAM_BANKS_MASK);
  1738. ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
  1739. if (ret != 0) {
  1740. ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
  1741. return ret;
  1742. }
  1743. /* Tell Target to proceed with initialization */
  1744. flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
  1745. ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
  1746. if (ret != 0) {
  1747. ath10k_err(ar, "Failed to get option val: %d\n", ret);
  1748. return ret;
  1749. }
  1750. flag2_value |= HI_OPTION_EARLY_CFG_DONE;
  1751. ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
  1752. if (ret != 0) {
  1753. ath10k_err(ar, "Failed to set option val: %d\n", ret);
  1754. return ret;
  1755. }
  1756. return 0;
  1757. }
  1758. static void ath10k_pci_override_ce_config(struct ath10k *ar)
  1759. {
  1760. struct ce_attr *attr;
  1761. struct ce_pipe_config *config;
  1762. /* For QCA6174 we're overriding the Copy Engine 5 configuration,
  1763. * since it is currently used for other feature.
  1764. */
  1765. /* Override Host's Copy Engine 5 configuration */
  1766. attr = &host_ce_config_wlan[5];
  1767. attr->src_sz_max = 0;
  1768. attr->dest_nentries = 0;
  1769. /* Override Target firmware's Copy Engine configuration */
  1770. config = &target_ce_config_wlan[5];
  1771. config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
  1772. config->nbytes_max = __cpu_to_le32(2048);
  1773. /* Map from service/endpoint to Copy Engine */
  1774. target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
  1775. }
  1776. int ath10k_pci_alloc_pipes(struct ath10k *ar)
  1777. {
  1778. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1779. struct ath10k_pci_pipe *pipe;
  1780. int i, ret;
  1781. for (i = 0; i < CE_COUNT; i++) {
  1782. pipe = &ar_pci->pipe_info[i];
  1783. pipe->ce_hdl = &ar_pci->ce_states[i];
  1784. pipe->pipe_num = i;
  1785. pipe->hif_ce_state = ar;
  1786. ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
  1787. if (ret) {
  1788. ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
  1789. i, ret);
  1790. return ret;
  1791. }
  1792. /* Last CE is Diagnostic Window */
  1793. if (i == CE_DIAG_PIPE) {
  1794. ar_pci->ce_diag = pipe->ce_hdl;
  1795. continue;
  1796. }
  1797. pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
  1798. }
  1799. return 0;
  1800. }
  1801. void ath10k_pci_free_pipes(struct ath10k *ar)
  1802. {
  1803. int i;
  1804. for (i = 0; i < CE_COUNT; i++)
  1805. ath10k_ce_free_pipe(ar, i);
  1806. }
  1807. int ath10k_pci_init_pipes(struct ath10k *ar)
  1808. {
  1809. int i, ret;
  1810. for (i = 0; i < CE_COUNT; i++) {
  1811. ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
  1812. if (ret) {
  1813. ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
  1814. i, ret);
  1815. return ret;
  1816. }
  1817. }
  1818. return 0;
  1819. }
  1820. static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
  1821. {
  1822. return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
  1823. FW_IND_EVENT_PENDING;
  1824. }
  1825. static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
  1826. {
  1827. u32 val;
  1828. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  1829. val &= ~FW_IND_EVENT_PENDING;
  1830. ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
  1831. }
  1832. static bool ath10k_pci_has_device_gone(struct ath10k *ar)
  1833. {
  1834. u32 val;
  1835. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  1836. return (val == 0xffffffff);
  1837. }
  1838. /* this function effectively clears target memory controller assert line */
  1839. static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
  1840. {
  1841. u32 val;
  1842. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1843. ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
  1844. val | SOC_RESET_CONTROL_SI0_RST_MASK);
  1845. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1846. msleep(10);
  1847. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1848. ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
  1849. val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
  1850. val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
  1851. msleep(10);
  1852. }
  1853. static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
  1854. {
  1855. u32 val;
  1856. ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
  1857. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1858. SOC_RESET_CONTROL_ADDRESS);
  1859. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1860. val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
  1861. }
  1862. static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
  1863. {
  1864. u32 val;
  1865. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1866. SOC_RESET_CONTROL_ADDRESS);
  1867. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1868. val | SOC_RESET_CONTROL_CE_RST_MASK);
  1869. msleep(10);
  1870. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
  1871. val & ~SOC_RESET_CONTROL_CE_RST_MASK);
  1872. }
  1873. static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
  1874. {
  1875. u32 val;
  1876. val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
  1877. SOC_LF_TIMER_CONTROL0_ADDRESS);
  1878. ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
  1879. SOC_LF_TIMER_CONTROL0_ADDRESS,
  1880. val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
  1881. }
  1882. static int ath10k_pci_warm_reset(struct ath10k *ar)
  1883. {
  1884. int ret;
  1885. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
  1886. spin_lock_bh(&ar->data_lock);
  1887. ar->stats.fw_warm_reset_counter++;
  1888. spin_unlock_bh(&ar->data_lock);
  1889. ath10k_pci_irq_disable(ar);
  1890. /* Make sure the target CPU is not doing anything dangerous, e.g. if it
  1891. * were to access copy engine while host performs copy engine reset
  1892. * then it is possible for the device to confuse pci-e controller to
  1893. * the point of bringing host system to a complete stop (i.e. hang).
  1894. */
  1895. ath10k_pci_warm_reset_si0(ar);
  1896. ath10k_pci_warm_reset_cpu(ar);
  1897. ath10k_pci_init_pipes(ar);
  1898. ath10k_pci_wait_for_target_init(ar);
  1899. ath10k_pci_warm_reset_clear_lf(ar);
  1900. ath10k_pci_warm_reset_ce(ar);
  1901. ath10k_pci_warm_reset_cpu(ar);
  1902. ath10k_pci_init_pipes(ar);
  1903. ret = ath10k_pci_wait_for_target_init(ar);
  1904. if (ret) {
  1905. ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
  1906. return ret;
  1907. }
  1908. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
  1909. return 0;
  1910. }
  1911. static int ath10k_pci_qca99x0_soft_chip_reset(struct ath10k *ar)
  1912. {
  1913. ath10k_pci_irq_disable(ar);
  1914. return ath10k_pci_qca99x0_chip_reset(ar);
  1915. }
  1916. static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
  1917. {
  1918. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  1919. if (!ar_pci->pci_soft_reset)
  1920. return -ENOTSUPP;
  1921. return ar_pci->pci_soft_reset(ar);
  1922. }
  1923. static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
  1924. {
  1925. int i, ret;
  1926. u32 val;
  1927. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
  1928. /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
  1929. * It is thus preferred to use warm reset which is safer but may not be
  1930. * able to recover the device from all possible fail scenarios.
  1931. *
  1932. * Warm reset doesn't always work on first try so attempt it a few
  1933. * times before giving up.
  1934. */
  1935. for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
  1936. ret = ath10k_pci_warm_reset(ar);
  1937. if (ret) {
  1938. ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
  1939. i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
  1940. ret);
  1941. continue;
  1942. }
  1943. /* FIXME: Sometimes copy engine doesn't recover after warm
  1944. * reset. In most cases this needs cold reset. In some of these
  1945. * cases the device is in such a state that a cold reset may
  1946. * lock up the host.
  1947. *
  1948. * Reading any host interest register via copy engine is
  1949. * sufficient to verify if device is capable of booting
  1950. * firmware blob.
  1951. */
  1952. ret = ath10k_pci_init_pipes(ar);
  1953. if (ret) {
  1954. ath10k_warn(ar, "failed to init copy engine: %d\n",
  1955. ret);
  1956. continue;
  1957. }
  1958. ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
  1959. &val);
  1960. if (ret) {
  1961. ath10k_warn(ar, "failed to poke copy engine: %d\n",
  1962. ret);
  1963. continue;
  1964. }
  1965. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
  1966. return 0;
  1967. }
  1968. if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
  1969. ath10k_warn(ar, "refusing cold reset as requested\n");
  1970. return -EPERM;
  1971. }
  1972. ret = ath10k_pci_cold_reset(ar);
  1973. if (ret) {
  1974. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  1975. return ret;
  1976. }
  1977. ret = ath10k_pci_wait_for_target_init(ar);
  1978. if (ret) {
  1979. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  1980. ret);
  1981. return ret;
  1982. }
  1983. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
  1984. return 0;
  1985. }
  1986. static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
  1987. {
  1988. int ret;
  1989. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
  1990. /* FIXME: QCA6174 requires cold + warm reset to work. */
  1991. ret = ath10k_pci_cold_reset(ar);
  1992. if (ret) {
  1993. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  1994. return ret;
  1995. }
  1996. ret = ath10k_pci_wait_for_target_init(ar);
  1997. if (ret) {
  1998. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  1999. ret);
  2000. return ret;
  2001. }
  2002. ret = ath10k_pci_warm_reset(ar);
  2003. if (ret) {
  2004. ath10k_warn(ar, "failed to warm reset: %d\n", ret);
  2005. return ret;
  2006. }
  2007. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
  2008. return 0;
  2009. }
  2010. static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
  2011. {
  2012. int ret;
  2013. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
  2014. ret = ath10k_pci_cold_reset(ar);
  2015. if (ret) {
  2016. ath10k_warn(ar, "failed to cold reset: %d\n", ret);
  2017. return ret;
  2018. }
  2019. ret = ath10k_pci_wait_for_target_init(ar);
  2020. if (ret) {
  2021. ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
  2022. ret);
  2023. return ret;
  2024. }
  2025. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
  2026. return 0;
  2027. }
  2028. static int ath10k_pci_chip_reset(struct ath10k *ar)
  2029. {
  2030. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2031. if (WARN_ON(!ar_pci->pci_hard_reset))
  2032. return -ENOTSUPP;
  2033. return ar_pci->pci_hard_reset(ar);
  2034. }
  2035. static int ath10k_pci_hif_power_up(struct ath10k *ar)
  2036. {
  2037. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2038. int ret;
  2039. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
  2040. pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  2041. &ar_pci->link_ctl);
  2042. pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
  2043. ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
  2044. /*
  2045. * Bring the target up cleanly.
  2046. *
  2047. * The target may be in an undefined state with an AUX-powered Target
  2048. * and a Host in WoW mode. If the Host crashes, loses power, or is
  2049. * restarted (without unloading the driver) then the Target is left
  2050. * (aux) powered and running. On a subsequent driver load, the Target
  2051. * is in an unexpected state. We try to catch that here in order to
  2052. * reset the Target and retry the probe.
  2053. */
  2054. ret = ath10k_pci_chip_reset(ar);
  2055. if (ret) {
  2056. if (ath10k_pci_has_fw_crashed(ar)) {
  2057. ath10k_warn(ar, "firmware crashed during chip reset\n");
  2058. ath10k_pci_fw_crashed_clear(ar);
  2059. ath10k_pci_fw_crashed_dump(ar);
  2060. }
  2061. ath10k_err(ar, "failed to reset chip: %d\n", ret);
  2062. goto err_sleep;
  2063. }
  2064. ret = ath10k_pci_init_pipes(ar);
  2065. if (ret) {
  2066. ath10k_err(ar, "failed to initialize CE: %d\n", ret);
  2067. goto err_sleep;
  2068. }
  2069. ret = ath10k_pci_init_config(ar);
  2070. if (ret) {
  2071. ath10k_err(ar, "failed to setup init config: %d\n", ret);
  2072. goto err_ce;
  2073. }
  2074. ret = ath10k_pci_wake_target_cpu(ar);
  2075. if (ret) {
  2076. ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
  2077. goto err_ce;
  2078. }
  2079. return 0;
  2080. err_ce:
  2081. ath10k_pci_ce_deinit(ar);
  2082. err_sleep:
  2083. return ret;
  2084. }
  2085. void ath10k_pci_hif_power_down(struct ath10k *ar)
  2086. {
  2087. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
  2088. /* Currently hif_power_up performs effectively a reset and hif_stop
  2089. * resets the chip as well so there's no point in resetting here.
  2090. */
  2091. }
  2092. #ifdef CONFIG_PM
  2093. static int ath10k_pci_hif_suspend(struct ath10k *ar)
  2094. {
  2095. /* The grace timer can still be counting down and ar->ps_awake be true.
  2096. * It is known that the device may be asleep after resuming regardless
  2097. * of the SoC powersave state before suspending. Hence make sure the
  2098. * device is asleep before proceeding.
  2099. */
  2100. ath10k_pci_sleep_sync(ar);
  2101. return 0;
  2102. }
  2103. static int ath10k_pci_hif_resume(struct ath10k *ar)
  2104. {
  2105. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2106. struct pci_dev *pdev = ar_pci->pdev;
  2107. u32 val;
  2108. int ret = 0;
  2109. ret = ath10k_pci_force_wake(ar);
  2110. if (ret) {
  2111. ath10k_err(ar, "failed to wake up target: %d\n", ret);
  2112. return ret;
  2113. }
  2114. /* Suspend/Resume resets the PCI configuration space, so we have to
  2115. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  2116. * from interfering with C3 CPU state. pci_restore_state won't help
  2117. * here since it only restores the first 64 bytes pci config header.
  2118. */
  2119. pci_read_config_dword(pdev, 0x40, &val);
  2120. if ((val & 0x0000ff00) != 0)
  2121. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  2122. return ret;
  2123. }
  2124. #endif
  2125. static bool ath10k_pci_validate_cal(void *data, size_t size)
  2126. {
  2127. __le16 *cal_words = data;
  2128. u16 checksum = 0;
  2129. size_t i;
  2130. if (size % 2 != 0)
  2131. return false;
  2132. for (i = 0; i < size / 2; i++)
  2133. checksum ^= le16_to_cpu(cal_words[i]);
  2134. return checksum == 0xffff;
  2135. }
  2136. static void ath10k_pci_enable_eeprom(struct ath10k *ar)
  2137. {
  2138. /* Enable SI clock */
  2139. ath10k_pci_soc_write32(ar, CLOCK_CONTROL_OFFSET, 0x0);
  2140. /* Configure GPIOs for I2C operation */
  2141. ath10k_pci_write32(ar,
  2142. GPIO_BASE_ADDRESS + GPIO_PIN0_OFFSET +
  2143. 4 * QCA9887_1_0_I2C_SDA_GPIO_PIN,
  2144. SM(QCA9887_1_0_I2C_SDA_PIN_CONFIG,
  2145. GPIO_PIN0_CONFIG) |
  2146. SM(1, GPIO_PIN0_PAD_PULL));
  2147. ath10k_pci_write32(ar,
  2148. GPIO_BASE_ADDRESS + GPIO_PIN0_OFFSET +
  2149. 4 * QCA9887_1_0_SI_CLK_GPIO_PIN,
  2150. SM(QCA9887_1_0_SI_CLK_PIN_CONFIG, GPIO_PIN0_CONFIG) |
  2151. SM(1, GPIO_PIN0_PAD_PULL));
  2152. ath10k_pci_write32(ar,
  2153. GPIO_BASE_ADDRESS +
  2154. QCA9887_1_0_GPIO_ENABLE_W1TS_LOW_ADDRESS,
  2155. 1u << QCA9887_1_0_SI_CLK_GPIO_PIN);
  2156. /* In Swift ASIC - EEPROM clock will be (110MHz/512) = 214KHz */
  2157. ath10k_pci_write32(ar,
  2158. SI_BASE_ADDRESS + SI_CONFIG_OFFSET,
  2159. SM(1, SI_CONFIG_ERR_INT) |
  2160. SM(1, SI_CONFIG_BIDIR_OD_DATA) |
  2161. SM(1, SI_CONFIG_I2C) |
  2162. SM(1, SI_CONFIG_POS_SAMPLE) |
  2163. SM(1, SI_CONFIG_INACTIVE_DATA) |
  2164. SM(1, SI_CONFIG_INACTIVE_CLK) |
  2165. SM(8, SI_CONFIG_DIVIDER));
  2166. }
  2167. static int ath10k_pci_read_eeprom(struct ath10k *ar, u16 addr, u8 *out)
  2168. {
  2169. u32 reg;
  2170. int wait_limit;
  2171. /* set device select byte and for the read operation */
  2172. reg = QCA9887_EEPROM_SELECT_READ |
  2173. SM(addr, QCA9887_EEPROM_ADDR_LO) |
  2174. SM(addr >> 8, QCA9887_EEPROM_ADDR_HI);
  2175. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_TX_DATA0_OFFSET, reg);
  2176. /* write transmit data, transfer length, and START bit */
  2177. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET,
  2178. SM(1, SI_CS_START) | SM(1, SI_CS_RX_CNT) |
  2179. SM(4, SI_CS_TX_CNT));
  2180. /* wait max 1 sec */
  2181. wait_limit = 100000;
  2182. /* wait for SI_CS_DONE_INT */
  2183. do {
  2184. reg = ath10k_pci_read32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET);
  2185. if (MS(reg, SI_CS_DONE_INT))
  2186. break;
  2187. wait_limit--;
  2188. udelay(10);
  2189. } while (wait_limit > 0);
  2190. if (!MS(reg, SI_CS_DONE_INT)) {
  2191. ath10k_err(ar, "timeout while reading device EEPROM at %04x\n",
  2192. addr);
  2193. return -ETIMEDOUT;
  2194. }
  2195. /* clear SI_CS_DONE_INT */
  2196. ath10k_pci_write32(ar, SI_BASE_ADDRESS + SI_CS_OFFSET, reg);
  2197. if (MS(reg, SI_CS_DONE_ERR)) {
  2198. ath10k_err(ar, "failed to read device EEPROM at %04x\n", addr);
  2199. return -EIO;
  2200. }
  2201. /* extract receive data */
  2202. reg = ath10k_pci_read32(ar, SI_BASE_ADDRESS + SI_RX_DATA0_OFFSET);
  2203. *out = reg;
  2204. return 0;
  2205. }
  2206. static int ath10k_pci_hif_fetch_cal_eeprom(struct ath10k *ar, void **data,
  2207. size_t *data_len)
  2208. {
  2209. u8 *caldata = NULL;
  2210. size_t calsize, i;
  2211. int ret;
  2212. if (!QCA_REV_9887(ar))
  2213. return -EOPNOTSUPP;
  2214. calsize = ar->hw_params.cal_data_len;
  2215. caldata = kmalloc(calsize, GFP_KERNEL);
  2216. if (!caldata)
  2217. return -ENOMEM;
  2218. ath10k_pci_enable_eeprom(ar);
  2219. for (i = 0; i < calsize; i++) {
  2220. ret = ath10k_pci_read_eeprom(ar, i, &caldata[i]);
  2221. if (ret)
  2222. goto err_free;
  2223. }
  2224. if (!ath10k_pci_validate_cal(caldata, calsize))
  2225. goto err_free;
  2226. *data = caldata;
  2227. *data_len = calsize;
  2228. return 0;
  2229. err_free:
  2230. kfree(caldata);
  2231. return -EINVAL;
  2232. }
  2233. static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
  2234. .tx_sg = ath10k_pci_hif_tx_sg,
  2235. .diag_read = ath10k_pci_hif_diag_read,
  2236. .diag_write = ath10k_pci_diag_write_mem,
  2237. .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
  2238. .start = ath10k_pci_hif_start,
  2239. .stop = ath10k_pci_hif_stop,
  2240. .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
  2241. .get_default_pipe = ath10k_pci_hif_get_default_pipe,
  2242. .send_complete_check = ath10k_pci_hif_send_complete_check,
  2243. .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
  2244. .power_up = ath10k_pci_hif_power_up,
  2245. .power_down = ath10k_pci_hif_power_down,
  2246. .read32 = ath10k_pci_read32,
  2247. .write32 = ath10k_pci_write32,
  2248. #ifdef CONFIG_PM
  2249. .suspend = ath10k_pci_hif_suspend,
  2250. .resume = ath10k_pci_hif_resume,
  2251. #endif
  2252. .fetch_cal_eeprom = ath10k_pci_hif_fetch_cal_eeprom,
  2253. };
  2254. /*
  2255. * Top-level interrupt handler for all PCI interrupts from a Target.
  2256. * When a block of MSI interrupts is allocated, this top-level handler
  2257. * is not used; instead, we directly call the correct sub-handler.
  2258. */
  2259. static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
  2260. {
  2261. struct ath10k *ar = arg;
  2262. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2263. int ret;
  2264. if (ath10k_pci_has_device_gone(ar))
  2265. return IRQ_NONE;
  2266. ret = ath10k_pci_force_wake(ar);
  2267. if (ret) {
  2268. ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
  2269. return IRQ_NONE;
  2270. }
  2271. if ((ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY) &&
  2272. !ath10k_pci_irq_pending(ar))
  2273. return IRQ_NONE;
  2274. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2275. ath10k_pci_irq_msi_fw_mask(ar);
  2276. napi_schedule(&ar->napi);
  2277. return IRQ_HANDLED;
  2278. }
  2279. static int ath10k_pci_napi_poll(struct napi_struct *ctx, int budget)
  2280. {
  2281. struct ath10k *ar = container_of(ctx, struct ath10k, napi);
  2282. int done = 0;
  2283. if (ath10k_pci_has_fw_crashed(ar)) {
  2284. ath10k_pci_fw_crashed_clear(ar);
  2285. ath10k_pci_fw_crashed_dump(ar);
  2286. napi_complete(ctx);
  2287. return done;
  2288. }
  2289. ath10k_ce_per_engine_service_any(ar);
  2290. done = ath10k_htt_txrx_compl_task(ar, budget);
  2291. if (done < budget) {
  2292. napi_complete_done(ctx, done);
  2293. /* In case of MSI, it is possible that interrupts are received
  2294. * while NAPI poll is inprogress. So pending interrupts that are
  2295. * received after processing all copy engine pipes by NAPI poll
  2296. * will not be handled again. This is causing failure to
  2297. * complete boot sequence in x86 platform. So before enabling
  2298. * interrupts safer to check for pending interrupts for
  2299. * immediate servicing.
  2300. */
  2301. if (CE_INTERRUPT_SUMMARY(ar)) {
  2302. napi_reschedule(ctx);
  2303. goto out;
  2304. }
  2305. ath10k_pci_enable_legacy_irq(ar);
  2306. ath10k_pci_irq_msi_fw_unmask(ar);
  2307. }
  2308. out:
  2309. return done;
  2310. }
  2311. static int ath10k_pci_request_irq_msi(struct ath10k *ar)
  2312. {
  2313. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2314. int ret;
  2315. ret = request_irq(ar_pci->pdev->irq,
  2316. ath10k_pci_interrupt_handler,
  2317. IRQF_SHARED, "ath10k_pci", ar);
  2318. if (ret) {
  2319. ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
  2320. ar_pci->pdev->irq, ret);
  2321. return ret;
  2322. }
  2323. return 0;
  2324. }
  2325. static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
  2326. {
  2327. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2328. int ret;
  2329. ret = request_irq(ar_pci->pdev->irq,
  2330. ath10k_pci_interrupt_handler,
  2331. IRQF_SHARED, "ath10k_pci", ar);
  2332. if (ret) {
  2333. ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
  2334. ar_pci->pdev->irq, ret);
  2335. return ret;
  2336. }
  2337. return 0;
  2338. }
  2339. static int ath10k_pci_request_irq(struct ath10k *ar)
  2340. {
  2341. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2342. switch (ar_pci->oper_irq_mode) {
  2343. case ATH10K_PCI_IRQ_LEGACY:
  2344. return ath10k_pci_request_irq_legacy(ar);
  2345. case ATH10K_PCI_IRQ_MSI:
  2346. return ath10k_pci_request_irq_msi(ar);
  2347. default:
  2348. return -EINVAL;
  2349. }
  2350. }
  2351. static void ath10k_pci_free_irq(struct ath10k *ar)
  2352. {
  2353. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2354. free_irq(ar_pci->pdev->irq, ar);
  2355. }
  2356. void ath10k_pci_init_napi(struct ath10k *ar)
  2357. {
  2358. netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_pci_napi_poll,
  2359. ATH10K_NAPI_BUDGET);
  2360. }
  2361. static int ath10k_pci_init_irq(struct ath10k *ar)
  2362. {
  2363. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2364. int ret;
  2365. ath10k_pci_init_napi(ar);
  2366. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
  2367. ath10k_info(ar, "limiting irq mode to: %d\n",
  2368. ath10k_pci_irq_mode);
  2369. /* Try MSI */
  2370. if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
  2371. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_MSI;
  2372. ret = pci_enable_msi(ar_pci->pdev);
  2373. if (ret == 0)
  2374. return 0;
  2375. /* fall-through */
  2376. }
  2377. /* Try legacy irq
  2378. *
  2379. * A potential race occurs here: The CORE_BASE write
  2380. * depends on target correctly decoding AXI address but
  2381. * host won't know when target writes BAR to CORE_CTRL.
  2382. * This write might get lost if target has NOT written BAR.
  2383. * For now, fix the race by repeating the write in below
  2384. * synchronization checking.
  2385. */
  2386. ar_pci->oper_irq_mode = ATH10K_PCI_IRQ_LEGACY;
  2387. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2388. PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
  2389. return 0;
  2390. }
  2391. static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
  2392. {
  2393. ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
  2394. 0);
  2395. }
  2396. static int ath10k_pci_deinit_irq(struct ath10k *ar)
  2397. {
  2398. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2399. switch (ar_pci->oper_irq_mode) {
  2400. case ATH10K_PCI_IRQ_LEGACY:
  2401. ath10k_pci_deinit_irq_legacy(ar);
  2402. break;
  2403. default:
  2404. pci_disable_msi(ar_pci->pdev);
  2405. break;
  2406. }
  2407. return 0;
  2408. }
  2409. int ath10k_pci_wait_for_target_init(struct ath10k *ar)
  2410. {
  2411. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2412. unsigned long timeout;
  2413. u32 val;
  2414. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
  2415. timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
  2416. do {
  2417. val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
  2418. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
  2419. val);
  2420. /* target should never return this */
  2421. if (val == 0xffffffff)
  2422. continue;
  2423. /* the device has crashed so don't bother trying anymore */
  2424. if (val & FW_IND_EVENT_PENDING)
  2425. break;
  2426. if (val & FW_IND_INITIALIZED)
  2427. break;
  2428. if (ar_pci->oper_irq_mode == ATH10K_PCI_IRQ_LEGACY)
  2429. /* Fix potential race by repeating CORE_BASE writes */
  2430. ath10k_pci_enable_legacy_irq(ar);
  2431. mdelay(10);
  2432. } while (time_before(jiffies, timeout));
  2433. ath10k_pci_disable_and_clear_legacy_irq(ar);
  2434. ath10k_pci_irq_msi_fw_mask(ar);
  2435. if (val == 0xffffffff) {
  2436. ath10k_err(ar, "failed to read device register, device is gone\n");
  2437. return -EIO;
  2438. }
  2439. if (val & FW_IND_EVENT_PENDING) {
  2440. ath10k_warn(ar, "device has crashed during init\n");
  2441. return -ECOMM;
  2442. }
  2443. if (!(val & FW_IND_INITIALIZED)) {
  2444. ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
  2445. val);
  2446. return -ETIMEDOUT;
  2447. }
  2448. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
  2449. return 0;
  2450. }
  2451. static int ath10k_pci_cold_reset(struct ath10k *ar)
  2452. {
  2453. u32 val;
  2454. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
  2455. spin_lock_bh(&ar->data_lock);
  2456. ar->stats.fw_cold_reset_counter++;
  2457. spin_unlock_bh(&ar->data_lock);
  2458. /* Put Target, including PCIe, into RESET. */
  2459. val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
  2460. val |= 1;
  2461. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2462. /* After writing into SOC_GLOBAL_RESET to put device into
  2463. * reset and pulling out of reset pcie may not be stable
  2464. * for any immediate pcie register access and cause bus error,
  2465. * add delay before any pcie access request to fix this issue.
  2466. */
  2467. msleep(20);
  2468. /* Pull Target, including PCIe, out of RESET. */
  2469. val &= ~1;
  2470. ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
  2471. msleep(20);
  2472. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
  2473. return 0;
  2474. }
  2475. static int ath10k_pci_claim(struct ath10k *ar)
  2476. {
  2477. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2478. struct pci_dev *pdev = ar_pci->pdev;
  2479. int ret;
  2480. pci_set_drvdata(pdev, ar);
  2481. ret = pci_enable_device(pdev);
  2482. if (ret) {
  2483. ath10k_err(ar, "failed to enable pci device: %d\n", ret);
  2484. return ret;
  2485. }
  2486. ret = pci_request_region(pdev, BAR_NUM, "ath");
  2487. if (ret) {
  2488. ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
  2489. ret);
  2490. goto err_device;
  2491. }
  2492. /* Target expects 32 bit DMA. Enforce it. */
  2493. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2494. if (ret) {
  2495. ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
  2496. goto err_region;
  2497. }
  2498. ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  2499. if (ret) {
  2500. ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
  2501. ret);
  2502. goto err_region;
  2503. }
  2504. pci_set_master(pdev);
  2505. /* Arrange for access to Target SoC registers. */
  2506. ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
  2507. ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
  2508. if (!ar_pci->mem) {
  2509. ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
  2510. ret = -EIO;
  2511. goto err_master;
  2512. }
  2513. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%pK\n", ar_pci->mem);
  2514. return 0;
  2515. err_master:
  2516. pci_clear_master(pdev);
  2517. err_region:
  2518. pci_release_region(pdev, BAR_NUM);
  2519. err_device:
  2520. pci_disable_device(pdev);
  2521. return ret;
  2522. }
  2523. static void ath10k_pci_release(struct ath10k *ar)
  2524. {
  2525. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2526. struct pci_dev *pdev = ar_pci->pdev;
  2527. pci_iounmap(pdev, ar_pci->mem);
  2528. pci_release_region(pdev, BAR_NUM);
  2529. pci_clear_master(pdev);
  2530. pci_disable_device(pdev);
  2531. }
  2532. static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
  2533. {
  2534. const struct ath10k_pci_supp_chip *supp_chip;
  2535. int i;
  2536. u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
  2537. for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
  2538. supp_chip = &ath10k_pci_supp_chips[i];
  2539. if (supp_chip->dev_id == dev_id &&
  2540. supp_chip->rev_id == rev_id)
  2541. return true;
  2542. }
  2543. return false;
  2544. }
  2545. int ath10k_pci_setup_resource(struct ath10k *ar)
  2546. {
  2547. struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
  2548. int ret;
  2549. spin_lock_init(&ar_pci->ce_lock);
  2550. spin_lock_init(&ar_pci->ps_lock);
  2551. setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
  2552. (unsigned long)ar);
  2553. if (QCA_REV_6174(ar) || QCA_REV_9377(ar))
  2554. ath10k_pci_override_ce_config(ar);
  2555. ret = ath10k_pci_alloc_pipes(ar);
  2556. if (ret) {
  2557. ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
  2558. ret);
  2559. return ret;
  2560. }
  2561. return 0;
  2562. }
  2563. void ath10k_pci_release_resource(struct ath10k *ar)
  2564. {
  2565. ath10k_pci_rx_retry_sync(ar);
  2566. netif_napi_del(&ar->napi);
  2567. ath10k_pci_ce_deinit(ar);
  2568. ath10k_pci_free_pipes(ar);
  2569. }
  2570. static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
  2571. .read32 = ath10k_bus_pci_read32,
  2572. .write32 = ath10k_bus_pci_write32,
  2573. .get_num_banks = ath10k_pci_get_num_banks,
  2574. };
  2575. static int ath10k_pci_probe(struct pci_dev *pdev,
  2576. const struct pci_device_id *pci_dev)
  2577. {
  2578. int ret = 0;
  2579. struct ath10k *ar;
  2580. struct ath10k_pci *ar_pci;
  2581. enum ath10k_hw_rev hw_rev;
  2582. u32 chip_id;
  2583. bool pci_ps;
  2584. int (*pci_soft_reset)(struct ath10k *ar);
  2585. int (*pci_hard_reset)(struct ath10k *ar);
  2586. u32 (*targ_cpu_to_ce_addr)(struct ath10k *ar, u32 addr);
  2587. switch (pci_dev->device) {
  2588. case QCA988X_2_0_DEVICE_ID:
  2589. hw_rev = ATH10K_HW_QCA988X;
  2590. pci_ps = false;
  2591. pci_soft_reset = ath10k_pci_warm_reset;
  2592. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2593. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2594. break;
  2595. case QCA9887_1_0_DEVICE_ID:
  2596. hw_rev = ATH10K_HW_QCA9887;
  2597. pci_ps = false;
  2598. pci_soft_reset = ath10k_pci_warm_reset;
  2599. pci_hard_reset = ath10k_pci_qca988x_chip_reset;
  2600. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2601. break;
  2602. case QCA6164_2_1_DEVICE_ID:
  2603. case QCA6174_2_1_DEVICE_ID:
  2604. hw_rev = ATH10K_HW_QCA6174;
  2605. pci_ps = true;
  2606. pci_soft_reset = ath10k_pci_warm_reset;
  2607. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2608. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2609. break;
  2610. case QCA99X0_2_0_DEVICE_ID:
  2611. hw_rev = ATH10K_HW_QCA99X0;
  2612. pci_ps = false;
  2613. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2614. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2615. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2616. break;
  2617. case QCA9984_1_0_DEVICE_ID:
  2618. hw_rev = ATH10K_HW_QCA9984;
  2619. pci_ps = false;
  2620. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2621. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2622. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2623. break;
  2624. case QCA9888_2_0_DEVICE_ID:
  2625. hw_rev = ATH10K_HW_QCA9888;
  2626. pci_ps = false;
  2627. pci_soft_reset = ath10k_pci_qca99x0_soft_chip_reset;
  2628. pci_hard_reset = ath10k_pci_qca99x0_chip_reset;
  2629. targ_cpu_to_ce_addr = ath10k_pci_qca99x0_targ_cpu_to_ce_addr;
  2630. break;
  2631. case QCA9377_1_0_DEVICE_ID:
  2632. hw_rev = ATH10K_HW_QCA9377;
  2633. pci_ps = true;
  2634. pci_soft_reset = NULL;
  2635. pci_hard_reset = ath10k_pci_qca6174_chip_reset;
  2636. targ_cpu_to_ce_addr = ath10k_pci_qca988x_targ_cpu_to_ce_addr;
  2637. break;
  2638. default:
  2639. WARN_ON(1);
  2640. return -ENOTSUPP;
  2641. }
  2642. ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
  2643. hw_rev, &ath10k_pci_hif_ops);
  2644. if (!ar) {
  2645. dev_err(&pdev->dev, "failed to allocate core\n");
  2646. return -ENOMEM;
  2647. }
  2648. ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
  2649. pdev->vendor, pdev->device,
  2650. pdev->subsystem_vendor, pdev->subsystem_device);
  2651. ar_pci = ath10k_pci_priv(ar);
  2652. ar_pci->pdev = pdev;
  2653. ar_pci->dev = &pdev->dev;
  2654. ar_pci->ar = ar;
  2655. ar->dev_id = pci_dev->device;
  2656. ar_pci->pci_ps = pci_ps;
  2657. ar_pci->bus_ops = &ath10k_pci_bus_ops;
  2658. ar_pci->pci_soft_reset = pci_soft_reset;
  2659. ar_pci->pci_hard_reset = pci_hard_reset;
  2660. ar_pci->targ_cpu_to_ce_addr = targ_cpu_to_ce_addr;
  2661. ar->id.vendor = pdev->vendor;
  2662. ar->id.device = pdev->device;
  2663. ar->id.subsystem_vendor = pdev->subsystem_vendor;
  2664. ar->id.subsystem_device = pdev->subsystem_device;
  2665. setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
  2666. (unsigned long)ar);
  2667. ret = ath10k_pci_setup_resource(ar);
  2668. if (ret) {
  2669. ath10k_err(ar, "failed to setup resource: %d\n", ret);
  2670. goto err_core_destroy;
  2671. }
  2672. ret = ath10k_pci_claim(ar);
  2673. if (ret) {
  2674. ath10k_err(ar, "failed to claim device: %d\n", ret);
  2675. goto err_free_pipes;
  2676. }
  2677. ret = ath10k_pci_force_wake(ar);
  2678. if (ret) {
  2679. ath10k_warn(ar, "failed to wake up device : %d\n", ret);
  2680. goto err_sleep;
  2681. }
  2682. ath10k_pci_ce_deinit(ar);
  2683. ath10k_pci_irq_disable(ar);
  2684. ret = ath10k_pci_init_irq(ar);
  2685. if (ret) {
  2686. ath10k_err(ar, "failed to init irqs: %d\n", ret);
  2687. goto err_sleep;
  2688. }
  2689. ath10k_info(ar, "pci irq %s oper_irq_mode %d irq_mode %d reset_mode %d\n",
  2690. ath10k_pci_get_irq_method(ar), ar_pci->oper_irq_mode,
  2691. ath10k_pci_irq_mode, ath10k_pci_reset_mode);
  2692. ret = ath10k_pci_request_irq(ar);
  2693. if (ret) {
  2694. ath10k_warn(ar, "failed to request irqs: %d\n", ret);
  2695. goto err_deinit_irq;
  2696. }
  2697. ret = ath10k_pci_chip_reset(ar);
  2698. if (ret) {
  2699. ath10k_err(ar, "failed to reset chip: %d\n", ret);
  2700. goto err_free_irq;
  2701. }
  2702. chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
  2703. if (chip_id == 0xffffffff) {
  2704. ath10k_err(ar, "failed to get chip id\n");
  2705. goto err_free_irq;
  2706. }
  2707. if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
  2708. ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
  2709. pdev->device, chip_id);
  2710. goto err_free_irq;
  2711. }
  2712. ret = ath10k_core_register(ar, chip_id);
  2713. if (ret) {
  2714. ath10k_err(ar, "failed to register driver core: %d\n", ret);
  2715. goto err_free_irq;
  2716. }
  2717. return 0;
  2718. err_free_irq:
  2719. ath10k_pci_free_irq(ar);
  2720. ath10k_pci_rx_retry_sync(ar);
  2721. err_deinit_irq:
  2722. ath10k_pci_deinit_irq(ar);
  2723. err_sleep:
  2724. ath10k_pci_sleep_sync(ar);
  2725. ath10k_pci_release(ar);
  2726. err_free_pipes:
  2727. ath10k_pci_free_pipes(ar);
  2728. err_core_destroy:
  2729. ath10k_core_destroy(ar);
  2730. return ret;
  2731. }
  2732. static void ath10k_pci_remove(struct pci_dev *pdev)
  2733. {
  2734. struct ath10k *ar = pci_get_drvdata(pdev);
  2735. struct ath10k_pci *ar_pci;
  2736. ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
  2737. if (!ar)
  2738. return;
  2739. ar_pci = ath10k_pci_priv(ar);
  2740. if (!ar_pci)
  2741. return;
  2742. ath10k_core_unregister(ar);
  2743. ath10k_pci_free_irq(ar);
  2744. ath10k_pci_deinit_irq(ar);
  2745. ath10k_pci_release_resource(ar);
  2746. ath10k_pci_sleep_sync(ar);
  2747. ath10k_pci_release(ar);
  2748. ath10k_core_destroy(ar);
  2749. }
  2750. MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
  2751. static struct pci_driver ath10k_pci_driver = {
  2752. .name = "ath10k_pci",
  2753. .id_table = ath10k_pci_id_table,
  2754. .probe = ath10k_pci_probe,
  2755. .remove = ath10k_pci_remove,
  2756. };
  2757. static int __init ath10k_pci_init(void)
  2758. {
  2759. int ret;
  2760. ret = pci_register_driver(&ath10k_pci_driver);
  2761. if (ret)
  2762. printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
  2763. ret);
  2764. ret = ath10k_ahb_init();
  2765. if (ret)
  2766. printk(KERN_ERR "ahb init failed: %d\n", ret);
  2767. return ret;
  2768. }
  2769. module_init(ath10k_pci_init);
  2770. static void __exit ath10k_pci_exit(void)
  2771. {
  2772. pci_unregister_driver(&ath10k_pci_driver);
  2773. ath10k_ahb_exit();
  2774. }
  2775. module_exit(ath10k_pci_exit);
  2776. MODULE_AUTHOR("Qualcomm Atheros");
  2777. MODULE_DESCRIPTION("Driver support for Qualcomm Atheros 802.11ac WLAN PCIe/AHB devices");
  2778. MODULE_LICENSE("Dual BSD/GPL");
  2779. /* QCA988x 2.0 firmware files */
  2780. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
  2781. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
  2782. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2783. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2784. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
  2785. MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2786. /* QCA9887 1.0 firmware files */
  2787. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2788. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" QCA9887_HW_1_0_BOARD_DATA_FILE);
  2789. MODULE_FIRMWARE(QCA9887_HW_1_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2790. /* QCA6174 2.1 firmware files */
  2791. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
  2792. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
  2793. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
  2794. MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
  2795. /* QCA6174 3.1 firmware files */
  2796. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
  2797. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
  2798. MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API6_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);