pci.c 85 KB

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