pci.c 71 KB

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