pci.c 87 KB

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