dhd_pcie_linux.c 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170
  1. /*
  2. * Linux DHD Bus Module for PCIE
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, Broadcom Corporation
  7. *
  8. * Unless you and Broadcom execute a separate written software license
  9. * agreement governing use of this software, this software is licensed to you
  10. * under the terms of the GNU General Public License version 2 (the "GPL"),
  11. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  12. * following added to such license:
  13. *
  14. * As a special exception, the copyright holders of this software give you
  15. * permission to link this software with independent modules, and to copy and
  16. * distribute the resulting executable under terms of your choice, provided that
  17. * you also meet, for each linked independent module, the terms and conditions of
  18. * the license of that module. An independent module is a module which is not
  19. * derived from this software. The special exception does not apply to any
  20. * modifications of the software.
  21. *
  22. * Notwithstanding the above, under no circumstances may you combine this
  23. * software in any way with any other Broadcom software provided under a license
  24. * other than the GPL, without Broadcom's express prior written consent.
  25. *
  26. *
  27. * <<Broadcom-WL-IPTag/Open:>>
  28. *
  29. * $Id: dhd_pcie_linux.c 701741 2017-05-26 08:18:08Z $
  30. */
  31. /* include files */
  32. #include <typedefs.h>
  33. #include <bcmutils.h>
  34. #include <bcmdevs.h>
  35. #include <siutils.h>
  36. #include <hndsoc.h>
  37. #include <hndpmu.h>
  38. #include <sbchipc.h>
  39. #if defined(DHD_DEBUG)
  40. #include <hnd_armtrap.h>
  41. #include <hnd_cons.h>
  42. #endif /* defined(DHD_DEBUG) */
  43. #include <dngl_stats.h>
  44. #include <pcie_core.h>
  45. #include <dhd.h>
  46. #include <dhd_bus.h>
  47. #include <dhd_proto.h>
  48. #include <dhd_dbg.h>
  49. #include <dhdioctl.h>
  50. #include <bcmmsgbuf.h>
  51. #include <pcicfg.h>
  52. #include <dhd_pcie.h>
  53. #include <dhd_linux.h>
  54. #ifdef OEM_ANDROID
  55. #ifdef CONFIG_ARCH_MSM
  56. #if defined(CONFIG_PCI_MSM) || defined(CONFIG_ARCH_MSM8996)
  57. #include <linux/msm_pcie.h>
  58. #else
  59. #include <mach/msm_pcie.h>
  60. #endif /* CONFIG_PCI_MSM */
  61. #endif /* CONFIG_ARCH_MSM */
  62. #endif /* OEM_ANDROID */
  63. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  64. #include <linux/pm_runtime.h>
  65. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  66. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  67. #ifndef AUTO_SUSPEND_TIMEOUT
  68. #define AUTO_SUSPEND_TIMEOUT 1000
  69. #endif /* AUTO_SUSPEND_TIMEOUT */
  70. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  71. #include <linux/irq.h>
  72. #ifdef USE_SMMU_ARCH_MSM
  73. #include <asm/dma-iommu.h>
  74. #include <linux/iommu.h>
  75. #include <linux/of.h>
  76. #include <linux/platform_device.h>
  77. #endif /* USE_SMMU_ARCH_MSM */
  78. #define PCI_CFG_RETRY 10
  79. #define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognize osh */
  80. #define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */
  81. #ifdef FORCE_TPOWERON
  82. extern uint32 tpoweron_scale;
  83. #endif /* FORCE_TPOWERON */
  84. /* user defined data structures */
  85. typedef bool (*dhdpcie_cb_fn_t)(void *);
  86. typedef struct dhdpcie_info
  87. {
  88. dhd_bus_t *bus;
  89. osl_t *osh;
  90. struct pci_dev *dev; /* pci device handle */
  91. volatile char *regs; /* pci device memory va */
  92. volatile char *tcm; /* pci device memory va */
  93. uint32 bar1_size; /* pci device memory size */
  94. uint32 curr_bar1_win; /* current PCIEBar1Window setting */
  95. struct pcos_info *pcos_info;
  96. uint16 last_intrstatus; /* to cache intrstatus */
  97. int irq;
  98. char pciname[32];
  99. struct pci_saved_state* default_state;
  100. struct pci_saved_state* state;
  101. #ifdef BCMPCIE_OOB_HOST_WAKE
  102. void *os_cxt; /* Pointer to per-OS private data */
  103. #endif /* BCMPCIE_OOB_HOST_WAKE */
  104. #ifdef DHD_WAKE_STATUS
  105. spinlock_t pcie_lock;
  106. unsigned int total_wake_count;
  107. int pkt_wake;
  108. int wake_irq;
  109. #endif /* DHD_WAKE_STATUS */
  110. #ifdef USE_SMMU_ARCH_MSM
  111. void *smmu_cxt;
  112. #endif /* USE_SMMU_ARCH_MSM */
  113. } dhdpcie_info_t;
  114. struct pcos_info {
  115. dhdpcie_info_t *pc;
  116. spinlock_t lock;
  117. wait_queue_head_t intr_wait_queue;
  118. struct timer_list tuning_timer;
  119. int tuning_timer_exp;
  120. atomic_t timer_enab;
  121. struct tasklet_struct tuning_tasklet;
  122. };
  123. #ifdef BCMPCIE_OOB_HOST_WAKE
  124. typedef struct dhdpcie_os_info {
  125. int oob_irq_num; /* valid when hardware or software oob in use */
  126. unsigned long oob_irq_flags; /* valid when hardware or software oob in use */
  127. bool oob_irq_registered;
  128. bool oob_irq_enabled;
  129. bool oob_irq_wake_enabled;
  130. spinlock_t oob_irq_spinlock;
  131. void *dev; /* handle to the underlying device */
  132. } dhdpcie_os_info_t;
  133. static irqreturn_t wlan_oob_irq(int irq, void *data);
  134. #ifdef CUSTOMER_HW2
  135. extern struct brcm_pcie_wake brcm_pcie_wake;
  136. #endif /* CUSTOMER_HW2 */
  137. #endif /* BCMPCIE_OOB_HOST_WAKE */
  138. #ifdef USE_SMMU_ARCH_MSM
  139. typedef struct dhdpcie_smmu_info {
  140. struct dma_iommu_mapping *smmu_mapping;
  141. dma_addr_t smmu_iova_start;
  142. size_t smmu_iova_len;
  143. } dhdpcie_smmu_info_t;
  144. #endif /* USE_SMMU_ARCH_MSM */
  145. /* function declarations */
  146. static int __devinit
  147. dhdpcie_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  148. static void __devexit
  149. dhdpcie_pci_remove(struct pci_dev *pdev);
  150. static int dhdpcie_init(struct pci_dev *pdev);
  151. static irqreturn_t dhdpcie_isr(int irq, void *arg);
  152. /* OS Routine functions for PCI suspend/resume */
  153. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  154. static int dhdpcie_set_suspend_resume(struct pci_dev *dev, bool state, bool byint);
  155. #else
  156. static int dhdpcie_set_suspend_resume(dhd_bus_t *bus, bool state);
  157. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  158. static int dhdpcie_resume_host_dev(dhd_bus_t *bus);
  159. static int dhdpcie_suspend_host_dev(dhd_bus_t *bus);
  160. static int dhdpcie_resume_dev(struct pci_dev *dev);
  161. static int dhdpcie_suspend_dev(struct pci_dev *dev);
  162. #ifdef DHD_PCIE_RUNTIMEPM
  163. static int dhdpcie_pm_suspend(struct device *dev);
  164. static int dhdpcie_pm_prepare(struct device *dev);
  165. static int dhdpcie_pm_resume(struct device *dev);
  166. static void dhdpcie_pm_complete(struct device *dev);
  167. #else
  168. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  169. static int dhdpcie_pm_system_suspend_noirq(struct device * dev);
  170. static int dhdpcie_pm_system_resume_noirq(struct device * dev);
  171. #else
  172. static int dhdpcie_pci_suspend(struct pci_dev *dev, pm_message_t state);
  173. static int dhdpcie_pci_resume(struct pci_dev *dev);
  174. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  175. #endif /* DHD_PCIE_RUNTIMEPM */
  176. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  177. static int dhdpcie_pm_runtime_suspend(struct device * dev);
  178. static int dhdpcie_pm_runtime_resume(struct device * dev);
  179. static int dhdpcie_pm_system_suspend_noirq(struct device * dev);
  180. static int dhdpcie_pm_system_resume_noirq(struct device * dev);
  181. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  182. static void dhdpcie_config_save_restore_coherent(dhd_bus_t *bus, bool state);
  183. uint32
  184. dhdpcie_access_cap(struct pci_dev *pdev, int cap, uint offset, bool is_ext, bool is_write,
  185. uint32 writeval);
  186. static struct pci_device_id dhdpcie_pci_devid[] __devinitdata = {
  187. { vendor: 0x14e4,
  188. device: PCI_ANY_ID,
  189. subvendor: PCI_ANY_ID,
  190. subdevice: PCI_ANY_ID,
  191. class: PCI_CLASS_NETWORK_OTHER << 8,
  192. class_mask: 0xffff00,
  193. driver_data: 0,
  194. },
  195. { 0, 0, 0, 0, 0, 0, 0}
  196. };
  197. MODULE_DEVICE_TABLE(pci, dhdpcie_pci_devid);
  198. /* Power Management Hooks */
  199. #ifdef DHD_PCIE_RUNTIMEPM
  200. static const struct dev_pm_ops dhd_pcie_pm_ops = {
  201. .prepare = dhdpcie_pm_prepare,
  202. .suspend = dhdpcie_pm_suspend,
  203. .resume = dhdpcie_pm_resume,
  204. .complete = dhdpcie_pm_complete,
  205. };
  206. #endif /* DHD_PCIE_RUNTIMEPM */
  207. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  208. static const struct dev_pm_ops dhdpcie_pm_ops = {
  209. SET_RUNTIME_PM_OPS(dhdpcie_pm_runtime_suspend, dhdpcie_pm_runtime_resume, NULL)
  210. .suspend_noirq = dhdpcie_pm_system_suspend_noirq,
  211. .resume_noirq = dhdpcie_pm_system_resume_noirq
  212. };
  213. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  214. static struct pci_driver dhdpcie_driver = {
  215. node: {&dhdpcie_driver.node, &dhdpcie_driver.node},
  216. #ifndef BCMDHDX
  217. name: "pcieh",
  218. #else
  219. name: "pciehx",
  220. #endif /* BCMDHDX */
  221. id_table: dhdpcie_pci_devid,
  222. probe: dhdpcie_pci_probe,
  223. remove: dhdpcie_pci_remove,
  224. #if defined(DHD_PCIE_RUNTIMEPM) || defined(DHD_PCIE_NATIVE_RUNTIMEPM)
  225. .driver.pm = &dhd_pcie_pm_ops,
  226. #else
  227. suspend: dhdpcie_pci_suspend,
  228. resume: dhdpcie_pci_resume,
  229. #endif /* DHD_PCIE_RUNTIMEPM || DHD_PCIE_NATIVE_RUNTIMEPM */
  230. };
  231. int dhdpcie_init_succeeded = FALSE;
  232. #ifdef USE_SMMU_ARCH_MSM
  233. static int dhdpcie_smmu_init(struct pci_dev *pdev, void *smmu_cxt)
  234. {
  235. struct dma_iommu_mapping *mapping;
  236. struct device_node *root_node = NULL;
  237. dhdpcie_smmu_info_t *smmu_info = (dhdpcie_smmu_info_t *)smmu_cxt;
  238. int smmu_iova_address[2];
  239. char *wlan_node = "android,bcmdhd_wlan";
  240. char *wlan_smmu_node = "wlan-smmu-iova-address";
  241. int atomic_ctx = 1;
  242. int s1_bypass = 1;
  243. int ret = 0;
  244. DHD_ERROR(("%s: SMMU initialize\n", __FUNCTION__));
  245. root_node = of_find_compatible_node(NULL, NULL, wlan_node);
  246. if (!root_node) {
  247. WARN(1, "failed to get device node of BRCM WLAN\n");
  248. return -ENODEV;
  249. }
  250. if (of_property_read_u32_array(root_node, wlan_smmu_node,
  251. smmu_iova_address, 2) == 0) {
  252. DHD_ERROR(("%s : get SMMU start address 0x%x, size 0x%x\n",
  253. __FUNCTION__, smmu_iova_address[0], smmu_iova_address[1]));
  254. smmu_info->smmu_iova_start = smmu_iova_address[0];
  255. smmu_info->smmu_iova_len = smmu_iova_address[1];
  256. } else {
  257. printf("%s : can't get smmu iova address property\n",
  258. __FUNCTION__);
  259. return -ENODEV;
  260. }
  261. if (smmu_info->smmu_iova_len <= 0) {
  262. DHD_ERROR(("%s: Invalid smmu iova len %d\n",
  263. __FUNCTION__, (int)smmu_info->smmu_iova_len));
  264. return -EINVAL;
  265. }
  266. DHD_ERROR(("%s : SMMU init start\n", __FUNCTION__));
  267. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) ||
  268. pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
  269. DHD_ERROR(("%s: DMA set 64bit mask failed.\n", __FUNCTION__));
  270. return -EINVAL;
  271. }
  272. mapping = arm_iommu_create_mapping(&platform_bus_type,
  273. smmu_info->smmu_iova_start, smmu_info->smmu_iova_len);
  274. if (IS_ERR(mapping)) {
  275. DHD_ERROR(("%s: create mapping failed, err = %d\n",
  276. __FUNCTION__, ret));
  277. ret = PTR_ERR(mapping);
  278. goto map_fail;
  279. }
  280. ret = iommu_domain_set_attr(mapping->domain,
  281. DOMAIN_ATTR_ATOMIC, &atomic_ctx);
  282. if (ret) {
  283. DHD_ERROR(("%s: set atomic_ctx attribute failed, err = %d\n",
  284. __FUNCTION__, ret));
  285. goto set_attr_fail;
  286. }
  287. ret = iommu_domain_set_attr(mapping->domain,
  288. DOMAIN_ATTR_S1_BYPASS, &s1_bypass);
  289. if (ret < 0) {
  290. DHD_ERROR(("%s: set s1_bypass attribute failed, err = %d\n",
  291. __FUNCTION__, ret));
  292. goto set_attr_fail;
  293. }
  294. ret = arm_iommu_attach_device(&pdev->dev, mapping);
  295. if (ret) {
  296. DHD_ERROR(("%s: attach device failed, err = %d\n",
  297. __FUNCTION__, ret));
  298. goto attach_fail;
  299. }
  300. smmu_info->smmu_mapping = mapping;
  301. return ret;
  302. attach_fail:
  303. set_attr_fail:
  304. arm_iommu_release_mapping(mapping);
  305. map_fail:
  306. return ret;
  307. }
  308. static void dhdpcie_smmu_remove(struct pci_dev *pdev, void *smmu_cxt)
  309. {
  310. dhdpcie_smmu_info_t *smmu_info;
  311. if (!smmu_cxt) {
  312. return;
  313. }
  314. smmu_info = (dhdpcie_smmu_info_t *)smmu_cxt;
  315. if (smmu_info->smmu_mapping) {
  316. arm_iommu_detach_device(&pdev->dev);
  317. arm_iommu_release_mapping(smmu_info->smmu_mapping);
  318. smmu_info->smmu_mapping = NULL;
  319. }
  320. }
  321. #endif /* USE_SMMU_ARCH_MSM */
  322. #ifdef FORCE_TPOWERON
  323. static void
  324. dhd_bus_get_tpoweron(dhd_bus_t *bus)
  325. {
  326. uint32 tpoweron_rc;
  327. uint32 tpoweron_ep;
  328. tpoweron_rc = dhdpcie_rc_access_cap(bus, PCIE_EXTCAP_ID_L1SS,
  329. PCIE_EXTCAP_L1SS_CONTROL2_OFFSET, TRUE, FALSE, 0);
  330. tpoweron_ep = dhdpcie_ep_access_cap(bus, PCIE_EXTCAP_ID_L1SS,
  331. PCIE_EXTCAP_L1SS_CONTROL2_OFFSET, TRUE, FALSE, 0);
  332. DHD_ERROR(("%s: tpoweron_rc:0x%x tpoweron_ep:0x%x\n",
  333. __FUNCTION__, tpoweron_rc, tpoweron_ep));
  334. }
  335. static void
  336. dhd_bus_set_tpoweron(dhd_bus_t *bus, uint16 tpoweron)
  337. {
  338. dhd_bus_get_tpoweron(bus);
  339. /* Set the tpoweron */
  340. DHD_ERROR(("%s tpoweron: 0x%x\n", __FUNCTION__, tpoweron));
  341. dhdpcie_rc_access_cap(bus, PCIE_EXTCAP_ID_L1SS,
  342. PCIE_EXTCAP_L1SS_CONTROL2_OFFSET, TRUE, TRUE, tpoweron);
  343. dhdpcie_ep_access_cap(bus, PCIE_EXTCAP_ID_L1SS,
  344. PCIE_EXTCAP_L1SS_CONTROL2_OFFSET, TRUE, TRUE, tpoweron);
  345. dhd_bus_get_tpoweron(bus);
  346. }
  347. static bool
  348. dhdpcie_chip_req_forced_tpoweron(dhd_bus_t *bus)
  349. {
  350. /*
  351. * On Fire's reference platform, coming out of L1.2,
  352. * there is a constant delay of 45us between CLKREQ# and stable REFCLK
  353. * Due to this delay, with tPowerOn < 50
  354. * there is a chance of the refclk sense to trigger on noise.
  355. *
  356. * Which ever chip needs forced tPowerOn of 50us should be listed below.
  357. */
  358. if (si_chipid(bus->sih) == BCM4377_CHIP_ID) {
  359. return TRUE;
  360. }
  361. return FALSE;
  362. }
  363. #endif /* FORCE_TPOWERON */
  364. static bool
  365. dhd_bus_aspm_enable_dev(dhd_bus_t *bus, struct pci_dev *dev, bool enable)
  366. {
  367. uint32 linkctrl_before;
  368. uint32 linkctrl_after = 0;
  369. uint8 linkctrl_asm;
  370. char *device;
  371. device = (dev == bus->dev) ? "EP" : "RC";
  372. linkctrl_before = dhdpcie_access_cap(dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET,
  373. FALSE, FALSE, 0);
  374. linkctrl_asm = (linkctrl_before & PCIE_ASPM_CTRL_MASK);
  375. if (enable) {
  376. if (linkctrl_asm == PCIE_ASPM_L1_ENAB) {
  377. DHD_ERROR(("%s: %s already enabled linkctrl: 0x%x\n",
  378. __FUNCTION__, device, linkctrl_before));
  379. return FALSE;
  380. }
  381. /* Enable only L1 ASPM (bit 1) */
  382. dhdpcie_access_cap(dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET, FALSE,
  383. TRUE, (linkctrl_before | PCIE_ASPM_L1_ENAB));
  384. } else {
  385. if (linkctrl_asm == 0) {
  386. DHD_ERROR(("%s: %s already disabled linkctrl: 0x%x\n",
  387. __FUNCTION__, device, linkctrl_before));
  388. return FALSE;
  389. }
  390. /* Disable complete ASPM (bit 1 and bit 0) */
  391. dhdpcie_access_cap(dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET, FALSE,
  392. TRUE, (linkctrl_before & (~PCIE_ASPM_ENAB)));
  393. }
  394. linkctrl_after = dhdpcie_access_cap(dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET,
  395. FALSE, FALSE, 0);
  396. DHD_ERROR(("%s: %s %s, linkctrl_before: 0x%x linkctrl_after: 0x%x\n",
  397. __FUNCTION__, device, (enable ? "ENABLE " : "DISABLE"),
  398. linkctrl_before, linkctrl_after));
  399. return TRUE;
  400. }
  401. static bool
  402. dhd_bus_is_rc_ep_aspm_capable(dhd_bus_t *bus)
  403. {
  404. uint32 rc_aspm_cap;
  405. uint32 ep_aspm_cap;
  406. /* RC ASPM capability */
  407. rc_aspm_cap = dhdpcie_access_cap(bus->rc_dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET,
  408. FALSE, FALSE, 0);
  409. if (rc_aspm_cap == BCME_ERROR) {
  410. DHD_ERROR(("%s RC is not ASPM capable\n", __FUNCTION__));
  411. return FALSE;
  412. }
  413. /* EP ASPM capability */
  414. ep_aspm_cap = dhdpcie_access_cap(bus->dev, PCIE_CAP_ID_EXP, PCIE_CAP_LINKCTRL_OFFSET,
  415. FALSE, FALSE, 0);
  416. if (ep_aspm_cap == BCME_ERROR) {
  417. DHD_ERROR(("%s EP is not ASPM capable\n", __FUNCTION__));
  418. return FALSE;
  419. }
  420. return TRUE;
  421. }
  422. bool
  423. dhd_bus_aspm_enable_rc_ep(dhd_bus_t *bus, bool enable)
  424. {
  425. bool ret;
  426. if (!bus->rc_ep_aspm_cap) {
  427. DHD_ERROR(("%s: NOT ASPM CAPABLE rc_ep_aspm_cap: %d\n",
  428. __FUNCTION__, bus->rc_ep_aspm_cap));
  429. return FALSE;
  430. }
  431. if (enable) {
  432. /* Enable only L1 ASPM first RC then EP */
  433. ret = dhd_bus_aspm_enable_dev(bus, bus->rc_dev, enable);
  434. ret = dhd_bus_aspm_enable_dev(bus, bus->dev, enable);
  435. } else {
  436. /* Disable complete ASPM first EP then RC */
  437. ret = dhd_bus_aspm_enable_dev(bus, bus->dev, enable);
  438. ret = dhd_bus_aspm_enable_dev(bus, bus->rc_dev, enable);
  439. }
  440. return ret;
  441. }
  442. static void
  443. dhd_bus_l1ss_enable_dev(dhd_bus_t *bus, struct pci_dev *dev, bool enable)
  444. {
  445. uint32 l1ssctrl_before;
  446. uint32 l1ssctrl_after = 0;
  447. uint8 l1ss_ep;
  448. char *device;
  449. device = (dev == bus->dev) ? "EP" : "RC";
  450. /* Extendend Capacility Reg */
  451. l1ssctrl_before = dhdpcie_access_cap(dev, PCIE_EXTCAP_ID_L1SS,
  452. PCIE_EXTCAP_L1SS_CONTROL_OFFSET, TRUE, FALSE, 0);
  453. l1ss_ep = (l1ssctrl_before & PCIE_EXT_L1SS_MASK);
  454. if (enable) {
  455. if (l1ss_ep == PCIE_EXT_L1SS_ENAB) {
  456. DHD_ERROR(("%s: %s already enabled, l1ssctrl: 0x%x\n",
  457. __FUNCTION__, device, l1ssctrl_before));
  458. return;
  459. }
  460. dhdpcie_access_cap(dev, PCIE_EXTCAP_ID_L1SS, PCIE_EXTCAP_L1SS_CONTROL_OFFSET,
  461. TRUE, TRUE, (l1ssctrl_before | PCIE_EXT_L1SS_ENAB));
  462. } else {
  463. if (l1ss_ep == 0) {
  464. DHD_ERROR(("%s: %s already disabled, l1ssctrl: 0x%x\n",
  465. __FUNCTION__, device, l1ssctrl_before));
  466. return;
  467. }
  468. dhdpcie_access_cap(dev, PCIE_EXTCAP_ID_L1SS, PCIE_EXTCAP_L1SS_CONTROL_OFFSET,
  469. TRUE, TRUE, (l1ssctrl_before & (~PCIE_EXT_L1SS_ENAB)));
  470. }
  471. l1ssctrl_after = dhdpcie_access_cap(dev, PCIE_EXTCAP_ID_L1SS,
  472. PCIE_EXTCAP_L1SS_CONTROL_OFFSET, TRUE, FALSE, 0);
  473. DHD_ERROR(("%s: %s %s, l1ssctrl_before: 0x%x l1ssctrl_after: 0x%x\n",
  474. __FUNCTION__, device, (enable ? "ENABLE " : "DISABLE"),
  475. l1ssctrl_before, l1ssctrl_after));
  476. }
  477. static bool
  478. dhd_bus_is_rc_ep_l1ss_capable(dhd_bus_t *bus)
  479. {
  480. uint32 rc_l1ss_cap;
  481. uint32 ep_l1ss_cap;
  482. /* RC Extendend Capacility */
  483. rc_l1ss_cap = dhdpcie_access_cap(bus->rc_dev, PCIE_EXTCAP_ID_L1SS,
  484. PCIE_EXTCAP_L1SS_CONTROL_OFFSET, TRUE, FALSE, 0);
  485. if (rc_l1ss_cap == BCME_ERROR) {
  486. DHD_ERROR(("%s RC is not l1ss capable\n", __FUNCTION__));
  487. return FALSE;
  488. }
  489. /* EP Extendend Capacility */
  490. ep_l1ss_cap = dhdpcie_access_cap(bus->dev, PCIE_EXTCAP_ID_L1SS,
  491. PCIE_EXTCAP_L1SS_CONTROL_OFFSET, TRUE, FALSE, 0);
  492. if (ep_l1ss_cap == BCME_ERROR) {
  493. DHD_ERROR(("%s EP is not l1ss capable\n", __FUNCTION__));
  494. return FALSE;
  495. }
  496. return TRUE;
  497. }
  498. void
  499. dhd_bus_l1ss_enable_rc_ep(dhd_bus_t *bus, bool enable)
  500. {
  501. bool ret;
  502. if ((!bus->rc_ep_aspm_cap) || (!bus->rc_ep_l1ss_cap)) {
  503. DHD_ERROR(("%s: NOT L1SS CAPABLE rc_ep_aspm_cap: %d rc_ep_l1ss_cap: %d\n",
  504. __FUNCTION__, bus->rc_ep_aspm_cap, bus->rc_ep_l1ss_cap));
  505. return;
  506. }
  507. /* Disable ASPM of RC and EP */
  508. ret = dhd_bus_aspm_enable_rc_ep(bus, FALSE);
  509. if (enable) {
  510. /* Enable RC then EP */
  511. dhd_bus_l1ss_enable_dev(bus, bus->rc_dev, enable);
  512. dhd_bus_l1ss_enable_dev(bus, bus->dev, enable);
  513. } else {
  514. /* Disable EP then RC */
  515. dhd_bus_l1ss_enable_dev(bus, bus->dev, enable);
  516. dhd_bus_l1ss_enable_dev(bus, bus->rc_dev, enable);
  517. }
  518. /* Enable ASPM of RC and EP only if this API disabled */
  519. if (ret == TRUE) {
  520. dhd_bus_aspm_enable_rc_ep(bus, TRUE);
  521. }
  522. }
  523. void
  524. dhd_bus_aer_config(dhd_bus_t *bus)
  525. {
  526. uint32 val;
  527. DHD_ERROR(("%s: Configure AER registers for EP\n", __FUNCTION__));
  528. val = dhdpcie_ep_access_cap(bus, PCIE_ADVERRREP_CAPID,
  529. PCIE_ADV_CORR_ERR_MASK_OFFSET, TRUE, FALSE, 0);
  530. if (val != (uint32)-1) {
  531. val &= ~CORR_ERR_AE;
  532. dhdpcie_ep_access_cap(bus, PCIE_ADVERRREP_CAPID,
  533. PCIE_ADV_CORR_ERR_MASK_OFFSET, TRUE, TRUE, val);
  534. } else {
  535. DHD_ERROR(("%s: Invalid EP's PCIE_ADV_CORR_ERR_MASK: 0x%x\n",
  536. __FUNCTION__, val));
  537. }
  538. DHD_ERROR(("%s: Configure AER registers for RC\n", __FUNCTION__));
  539. val = dhdpcie_rc_access_cap(bus, PCIE_ADVERRREP_CAPID,
  540. PCIE_ADV_CORR_ERR_MASK_OFFSET, TRUE, FALSE, 0);
  541. if (val != (uint32)-1) {
  542. val &= ~CORR_ERR_AE;
  543. dhdpcie_rc_access_cap(bus, PCIE_ADVERRREP_CAPID,
  544. PCIE_ADV_CORR_ERR_MASK_OFFSET, TRUE, TRUE, val);
  545. } else {
  546. DHD_ERROR(("%s: Invalid RC's PCIE_ADV_CORR_ERR_MASK: 0x%x\n",
  547. __FUNCTION__, val));
  548. }
  549. }
  550. #ifdef DHD_PCIE_RUNTIMEPM
  551. static int dhdpcie_pm_suspend(struct device *dev)
  552. {
  553. int ret = 0;
  554. struct pci_dev *pdev = to_pci_dev(dev);
  555. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  556. dhd_bus_t *bus = NULL;
  557. unsigned long flags;
  558. if (pch) {
  559. bus = pch->bus;
  560. }
  561. if (!bus) {
  562. return ret;
  563. }
  564. DHD_GENERAL_LOCK(bus->dhd, flags);
  565. if (!DHD_BUS_BUSY_CHECK_IDLE(bus->dhd)) {
  566. DHD_ERROR(("%s: Bus not IDLE!! dhd_bus_busy_state = 0x%x\n",
  567. __FUNCTION__, bus->dhd->dhd_bus_busy_state));
  568. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  569. return -EBUSY;
  570. }
  571. DHD_BUS_BUSY_SET_SUSPEND_IN_PROGRESS(bus->dhd);
  572. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  573. if (!bus->dhd->dongle_reset)
  574. ret = dhdpcie_set_suspend_resume(bus, TRUE);
  575. DHD_GENERAL_LOCK(bus->dhd, flags);
  576. DHD_BUS_BUSY_CLEAR_SUSPEND_IN_PROGRESS(bus->dhd);
  577. dhd_os_busbusy_wake(bus->dhd);
  578. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  579. return ret;
  580. }
  581. static int dhdpcie_pm_prepare(struct device *dev)
  582. {
  583. struct pci_dev *pdev = to_pci_dev(dev);
  584. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  585. dhd_bus_t *bus = NULL;
  586. if (!pch || !pch->bus) {
  587. return 0;
  588. }
  589. bus = pch->bus;
  590. DHD_DISABLE_RUNTIME_PM(bus->dhd);
  591. bus->chk_pm = TRUE;
  592. return 0;
  593. }
  594. static int dhdpcie_pm_resume(struct device *dev)
  595. {
  596. int ret = 0;
  597. struct pci_dev *pdev = to_pci_dev(dev);
  598. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  599. dhd_bus_t *bus = NULL;
  600. unsigned long flags;
  601. if (pch) {
  602. bus = pch->bus;
  603. }
  604. if (!bus) {
  605. return ret;
  606. }
  607. DHD_GENERAL_LOCK(bus->dhd, flags);
  608. DHD_BUS_BUSY_SET_RESUME_IN_PROGRESS(bus->dhd);
  609. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  610. if (!bus->dhd->dongle_reset)
  611. ret = dhdpcie_set_suspend_resume(bus, FALSE);
  612. DHD_GENERAL_LOCK(bus->dhd, flags);
  613. DHD_BUS_BUSY_CLEAR_RESUME_IN_PROGRESS(bus->dhd);
  614. dhd_os_busbusy_wake(bus->dhd);
  615. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  616. return ret;
  617. }
  618. static void dhdpcie_pm_complete(struct device *dev)
  619. {
  620. struct pci_dev *pdev = to_pci_dev(dev);
  621. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  622. dhd_bus_t *bus = NULL;
  623. if (!pch || !pch->bus) {
  624. return;
  625. }
  626. bus = pch->bus;
  627. DHD_ENABLE_RUNTIME_PM(bus->dhd);
  628. bus->chk_pm = FALSE;
  629. return;
  630. }
  631. #else
  632. static int dhdpcie_pci_suspend(struct pci_dev * pdev, pm_message_t state)
  633. {
  634. int ret = 0;
  635. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  636. dhd_bus_t *bus = NULL;
  637. unsigned long flags;
  638. if (pch) {
  639. bus = pch->bus;
  640. }
  641. if (!bus) {
  642. return ret;
  643. }
  644. BCM_REFERENCE(state);
  645. DHD_GENERAL_LOCK(bus->dhd, flags);
  646. if (!DHD_BUS_BUSY_CHECK_IDLE(bus->dhd)) {
  647. DHD_ERROR(("%s: Bus not IDLE!! dhd_bus_busy_state = 0x%x\n",
  648. __FUNCTION__, bus->dhd->dhd_bus_busy_state));
  649. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  650. return -EBUSY;
  651. }
  652. DHD_BUS_BUSY_SET_SUSPEND_IN_PROGRESS(bus->dhd);
  653. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  654. if (!bus->dhd->dongle_reset)
  655. ret = dhdpcie_set_suspend_resume(bus, TRUE);
  656. DHD_GENERAL_LOCK(bus->dhd, flags);
  657. DHD_BUS_BUSY_CLEAR_SUSPEND_IN_PROGRESS(bus->dhd);
  658. dhd_os_busbusy_wake(bus->dhd);
  659. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  660. return ret;
  661. }
  662. static int dhdpcie_pci_resume(struct pci_dev *pdev)
  663. {
  664. int ret = 0;
  665. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  666. dhd_bus_t *bus = NULL;
  667. unsigned long flags;
  668. if (pch) {
  669. bus = pch->bus;
  670. }
  671. if (!bus) {
  672. return ret;
  673. }
  674. DHD_GENERAL_LOCK(bus->dhd, flags);
  675. DHD_BUS_BUSY_SET_RESUME_IN_PROGRESS(bus->dhd);
  676. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  677. if (!bus->dhd->dongle_reset)
  678. ret = dhdpcie_set_suspend_resume(bus, FALSE);
  679. DHD_GENERAL_LOCK(bus->dhd, flags);
  680. DHD_BUS_BUSY_CLEAR_RESUME_IN_PROGRESS(bus->dhd);
  681. dhd_os_busbusy_wake(bus->dhd);
  682. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  683. return ret;
  684. }
  685. #endif /* DHD_PCIE_RUNTIMEPM */
  686. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  687. static int dhdpcie_set_suspend_resume(dhd_bus_t *bus, bool state, bool byint)
  688. #else
  689. static int dhdpcie_set_suspend_resume(dhd_bus_t *bus, bool state)
  690. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  691. {
  692. int ret = 0;
  693. ASSERT(bus && !bus->dhd->dongle_reset);
  694. #ifdef DHD_PCIE_RUNTIMEPM
  695. /* if wakelock is held during suspend, return failed */
  696. if (state == TRUE && dhd_os_check_wakelock_all(bus->dhd)) {
  697. return -EBUSY;
  698. }
  699. mutex_lock(&bus->pm_lock);
  700. #endif /* DHD_PCIE_RUNTIMEPM */
  701. /* When firmware is not loaded do the PCI bus */
  702. /* suspend/resume only */
  703. if (bus->dhd->busstate == DHD_BUS_DOWN) {
  704. ret = dhdpcie_pci_suspend_resume(bus, state);
  705. #ifdef DHD_PCIE_RUNTIMEPM
  706. mutex_unlock(&bus->pm_lock);
  707. #endif /* DHD_PCIE_RUNTIMEPM */
  708. return ret;
  709. }
  710. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  711. ret = dhdpcie_bus_suspend(bus, state, byint);
  712. #else
  713. ret = dhdpcie_bus_suspend(bus, state);
  714. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  715. #ifdef DHD_PCIE_RUNTIMEPM
  716. mutex_unlock(&bus->pm_lock);
  717. #endif /* DHD_PCIE_RUNTIMEPM */
  718. return ret;
  719. }
  720. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  721. static int dhdpcie_pm_runtime_suspend(struct device * dev)
  722. {
  723. struct pci_dev *pdev = to_pci_dev(dev);
  724. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  725. dhd_bus_t *bus = NULL;
  726. int ret = 0;
  727. if (!pch)
  728. return -EBUSY;
  729. bus = pch->bus;
  730. DHD_RPM(("%s Enter\n", __FUNCTION__));
  731. if (atomic_read(&bus->dhd->block_bus))
  732. return -EHOSTDOWN;
  733. dhd_netif_stop_queue(bus);
  734. atomic_set(&bus->dhd->block_bus, TRUE);
  735. if (dhdpcie_set_suspend_resume(pdev, TRUE, TRUE)) {
  736. pm_runtime_mark_last_busy(dev);
  737. ret = -EAGAIN;
  738. }
  739. atomic_set(&bus->dhd->block_bus, FALSE);
  740. dhd_bus_start_queue(bus);
  741. return ret;
  742. }
  743. static int dhdpcie_pm_runtime_resume(struct device * dev)
  744. {
  745. struct pci_dev *pdev = to_pci_dev(dev);
  746. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  747. dhd_bus_t *bus = pch->bus;
  748. DHD_RPM(("%s Enter\n", __FUNCTION__));
  749. if (atomic_read(&bus->dhd->block_bus))
  750. return -EHOSTDOWN;
  751. if (dhdpcie_set_suspend_resume(pdev, FALSE, TRUE))
  752. return -EAGAIN;
  753. return 0;
  754. }
  755. static int dhdpcie_pm_system_suspend_noirq(struct device * dev)
  756. {
  757. struct pci_dev *pdev = to_pci_dev(dev);
  758. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  759. dhd_bus_t *bus = NULL;
  760. int ret;
  761. DHD_RPM(("%s Enter\n", __FUNCTION__));
  762. if (!pch)
  763. return -EBUSY;
  764. bus = pch->bus;
  765. if (atomic_read(&bus->dhd->block_bus))
  766. return -EHOSTDOWN;
  767. dhd_netif_stop_queue(bus);
  768. atomic_set(&bus->dhd->block_bus, TRUE);
  769. ret = dhdpcie_set_suspend_resume(pdev, TRUE, FALSE);
  770. if (ret) {
  771. dhd_bus_start_queue(bus);
  772. atomic_set(&bus->dhd->block_bus, FALSE);
  773. }
  774. return ret;
  775. }
  776. static int dhdpcie_pm_system_resume_noirq(struct device * dev)
  777. {
  778. struct pci_dev *pdev = to_pci_dev(dev);
  779. dhdpcie_info_t *pch = pci_get_drvdata(pdev);
  780. dhd_bus_t *bus = NULL;
  781. int ret;
  782. if (!pch)
  783. return -EBUSY;
  784. bus = pch->bus;
  785. DHD_RPM(("%s Enter\n", __FUNCTION__));
  786. ret = dhdpcie_set_suspend_resume(pdev, FALSE, FALSE);
  787. atomic_set(&bus->dhd->block_bus, FALSE);
  788. dhd_bus_start_queue(bus);
  789. pm_runtime_mark_last_busy(dhd_bus_to_dev(bus));
  790. return ret;
  791. }
  792. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  793. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  794. extern void dhd_dpc_tasklet_kill(dhd_pub_t *dhdp);
  795. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  796. static void
  797. dhdpcie_suspend_dump_cfgregs(struct dhd_bus *bus, char *suspend_state)
  798. {
  799. DHD_ERROR(("%s: BaseAddress0(0x%x)=0x%x, "
  800. "BaseAddress1(0x%x)=0x%x PCIE_CFG_PMCSR(0x%x)=0x%x\n",
  801. suspend_state,
  802. PCIECFGREG_BASEADDR0,
  803. dhd_pcie_config_read(bus->osh,
  804. PCIECFGREG_BASEADDR0, sizeof(uint32)),
  805. PCIECFGREG_BASEADDR1,
  806. dhd_pcie_config_read(bus->osh,
  807. PCIECFGREG_BASEADDR1, sizeof(uint32)),
  808. PCIE_CFG_PMCSR,
  809. dhd_pcie_config_read(bus->osh,
  810. PCIE_CFG_PMCSR, sizeof(uint32))));
  811. }
  812. static int dhdpcie_suspend_dev(struct pci_dev *dev)
  813. {
  814. int ret;
  815. dhdpcie_info_t *pch = pci_get_drvdata(dev);
  816. dhd_bus_t *bus = pch->bus;
  817. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  818. if (bus->is_linkdown) {
  819. DHD_ERROR(("%s: PCIe link is down\n", __FUNCTION__));
  820. return BCME_ERROR;
  821. }
  822. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  823. DHD_ERROR(("%s: Enter\n", __FUNCTION__));
  824. dhdpcie_suspend_dump_cfgregs(bus, "BEFORE_EP_SUSPEND");
  825. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  826. dhd_dpc_tasklet_kill(bus->dhd);
  827. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  828. pci_save_state(dev);
  829. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  830. pch->state = pci_store_saved_state(dev);
  831. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  832. pci_enable_wake(dev, PCI_D0, TRUE);
  833. if (pci_is_enabled(dev))
  834. pci_disable_device(dev);
  835. ret = pci_set_power_state(dev, PCI_D3hot);
  836. if (ret) {
  837. DHD_ERROR(("%s: pci_set_power_state error %d\n",
  838. __FUNCTION__, ret));
  839. }
  840. #ifdef OEM_ANDROID
  841. dev->state_saved = FALSE;
  842. #endif /* OEM_ANDROID */
  843. dhdpcie_suspend_dump_cfgregs(bus, "AFTER_EP_SUSPEND");
  844. return ret;
  845. }
  846. #ifdef DHD_WAKE_STATUS
  847. int bcmpcie_get_total_wake(struct dhd_bus *bus)
  848. {
  849. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  850. return pch->total_wake_count;
  851. }
  852. int bcmpcie_set_get_wake(struct dhd_bus *bus, int flag)
  853. {
  854. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  855. unsigned long flags;
  856. int ret;
  857. spin_lock_irqsave(&pch->pcie_lock, flags);
  858. ret = pch->pkt_wake;
  859. pch->total_wake_count += flag;
  860. pch->pkt_wake = flag;
  861. spin_unlock_irqrestore(&pch->pcie_lock, flags);
  862. return ret;
  863. }
  864. #endif /* DHD_WAKE_STATUS */
  865. static int dhdpcie_resume_dev(struct pci_dev *dev)
  866. {
  867. int err = 0;
  868. dhdpcie_info_t *pch = pci_get_drvdata(dev);
  869. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  870. pci_load_and_free_saved_state(dev, &pch->state);
  871. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  872. DHD_ERROR(("%s: Enter\n", __FUNCTION__));
  873. #ifdef OEM_ANDROID
  874. dev->state_saved = TRUE;
  875. #endif /* OEM_ANDROID */
  876. pci_restore_state(dev);
  877. #ifdef FORCE_TPOWERON
  878. if (dhdpcie_chip_req_forced_tpoweron(pch->bus)) {
  879. dhd_bus_set_tpoweron(pch->bus, tpoweron_scale);
  880. }
  881. #endif /* FORCE_TPOWERON */
  882. err = pci_enable_device(dev);
  883. if (err) {
  884. printf("%s:pci_enable_device error %d \n", __FUNCTION__, err);
  885. goto out;
  886. }
  887. pci_set_master(dev);
  888. err = pci_set_power_state(dev, PCI_D0);
  889. if (err) {
  890. printf("%s:pci_set_power_state error %d \n", __FUNCTION__, err);
  891. goto out;
  892. }
  893. BCM_REFERENCE(pch);
  894. dhdpcie_suspend_dump_cfgregs(pch->bus, "AFTER_EP_RESUME");
  895. out:
  896. return err;
  897. }
  898. static int dhdpcie_resume_host_dev(dhd_bus_t *bus)
  899. {
  900. int bcmerror = 0;
  901. #ifdef USE_EXYNOS_PCIE_RC_PMPATCH
  902. bcmerror = exynos_pcie_pm_resume(SAMSUNG_PCIE_CH_NUM);
  903. #endif /* USE_EXYNOS_PCIE_RC_PMPATCH */
  904. #ifdef CONFIG_ARCH_MSM
  905. bcmerror = dhdpcie_start_host_pcieclock(bus);
  906. #endif /* CONFIG_ARCH_MSM */
  907. #ifdef CONFIG_ARCH_TEGRA
  908. bcmerror = tegra_pcie_pm_resume();
  909. #endif /* CONFIG_ARCH_TEGRA */
  910. if (bcmerror < 0) {
  911. DHD_ERROR(("%s: PCIe RC resume failed!!! (%d)\n",
  912. __FUNCTION__, bcmerror));
  913. bus->is_linkdown = 1;
  914. #ifdef SUPPORT_LINKDOWN_RECOVERY
  915. #ifdef CONFIG_ARCH_MSM
  916. bus->no_cfg_restore = 1;
  917. #endif /* CONFIG_ARCH_MSM */
  918. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  919. }
  920. return bcmerror;
  921. }
  922. static int dhdpcie_suspend_host_dev(dhd_bus_t *bus)
  923. {
  924. int bcmerror = 0;
  925. #ifdef USE_EXYNOS_PCIE_RC_PMPATCH
  926. if (bus->rc_dev) {
  927. pci_save_state(bus->rc_dev);
  928. } else {
  929. DHD_ERROR(("%s: RC %x:%x handle is NULL\n",
  930. __FUNCTION__, PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID));
  931. }
  932. exynos_pcie_pm_suspend(SAMSUNG_PCIE_CH_NUM);
  933. #endif /* USE_EXYNOS_PCIE_RC_PMPATCH */
  934. #ifdef CONFIG_ARCH_MSM
  935. bcmerror = dhdpcie_stop_host_pcieclock(bus);
  936. #endif /* CONFIG_ARCH_MSM */
  937. #ifdef CONFIG_ARCH_TEGRA
  938. bcmerror = tegra_pcie_pm_suspend();
  939. #endif /* CONFIG_ARCH_TEGRA */
  940. return bcmerror;
  941. }
  942. /**
  943. * dhdpcie_os_setbar1win
  944. *
  945. * Interface function for setting bar1 window in order to allow
  946. * os layer to be aware of current window positon.
  947. *
  948. * @bus: dhd bus context
  949. * @addr: new backplane windows address for BAR1
  950. */
  951. void
  952. dhdpcie_os_setbar1win(dhd_bus_t *bus, uint32 addr)
  953. {
  954. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  955. osl_pci_write_config(bus->osh, PCI_BAR1_WIN, 4, addr);
  956. pch->curr_bar1_win = addr;
  957. }
  958. /**
  959. * dhdpcie_os_chkbpoffset
  960. *
  961. * Check the provided address is within the current BAR1 window,
  962. * if not, shift the window
  963. *
  964. * @bus: dhd bus context
  965. * @offset: back plane address that the caller wants to access
  966. *
  967. * Return: new offset for access
  968. */
  969. static ulong
  970. dhdpcie_os_chkbpoffset(dhdpcie_info_t *pch, ulong offset)
  971. {
  972. /* Determine BAR1 backplane window using window size
  973. * Window address mask should be ~(size - 1)
  974. */
  975. uint32 bpwin = (uint32)(offset & ~(pch->bar1_size - 1));
  976. if (bpwin != pch->curr_bar1_win) {
  977. /* Move BAR1 window */
  978. dhdpcie_os_setbar1win(pch->bus, bpwin);
  979. }
  980. return offset - bpwin;
  981. }
  982. /**
  983. * dhdpcie os layer tcm read/write interface
  984. */
  985. void
  986. dhdpcie_os_wtcm8(dhd_bus_t *bus, ulong offset, uint8 data)
  987. {
  988. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  989. offset = dhdpcie_os_chkbpoffset(pch, offset);
  990. W_REG(bus->dhd->osh, (volatile uint8 *)(bus->tcm + offset), data);
  991. }
  992. uint8
  993. dhdpcie_os_rtcm8(dhd_bus_t *bus, ulong offset)
  994. {
  995. volatile uint8 data;
  996. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  997. offset = dhdpcie_os_chkbpoffset(pch, offset);
  998. data = R_REG(bus->dhd->osh, (volatile uint8 *)(bus->tcm + offset));
  999. return data;
  1000. }
  1001. void
  1002. dhdpcie_os_wtcm16(dhd_bus_t *bus, ulong offset, uint16 data)
  1003. {
  1004. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1005. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1006. W_REG(bus->dhd->osh, (volatile uint16 *)(bus->tcm + offset), data);
  1007. }
  1008. uint16
  1009. dhdpcie_os_rtcm16(dhd_bus_t *bus, ulong offset)
  1010. {
  1011. volatile uint16 data;
  1012. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1013. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1014. data = R_REG(bus->dhd->osh, (volatile uint16 *)(bus->tcm + offset));
  1015. return data;
  1016. }
  1017. void
  1018. dhdpcie_os_wtcm32(dhd_bus_t *bus, ulong offset, uint32 data)
  1019. {
  1020. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1021. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1022. W_REG(bus->dhd->osh, (volatile uint32 *)(bus->tcm + offset), data);
  1023. }
  1024. uint32
  1025. dhdpcie_os_rtcm32(dhd_bus_t *bus, ulong offset)
  1026. {
  1027. volatile uint32 data;
  1028. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1029. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1030. data = R_REG(bus->dhd->osh, (volatile uint32 *)(bus->tcm + offset));
  1031. return data;
  1032. }
  1033. #ifdef DHD_SUPPORT_64BIT
  1034. void
  1035. dhdpcie_os_wtcm64(dhd_bus_t *bus, ulong offset, uint64 data)
  1036. {
  1037. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1038. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1039. W_REG(bus->dhd->osh, (volatile uint64 *)(bus->tcm + offset), data);
  1040. }
  1041. uint64
  1042. dhdpcie_os_rtcm64(dhd_bus_t *bus, ulong offset)
  1043. {
  1044. volatile uint64 data;
  1045. dhdpcie_info_t *pch = pci_get_drvdata(bus->dev);
  1046. offset = dhdpcie_os_chkbpoffset(pch, offset);
  1047. data = R_REG(bus->dhd->osh, (volatile uint64 *)(bus->tcm + offset));
  1048. return data;
  1049. }
  1050. #endif /* DHD_SUPPORT_64BIT */
  1051. uint32
  1052. dhdpcie_rc_config_read(dhd_bus_t *bus, uint offset)
  1053. {
  1054. uint val = -1; /* Initialise to 0xfffffff */
  1055. if (bus->rc_dev) {
  1056. pci_read_config_dword(bus->rc_dev, offset, &val);
  1057. OSL_DELAY(100);
  1058. } else {
  1059. DHD_ERROR(("%s: RC %x:%x handle is NULL\n",
  1060. __FUNCTION__, PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID));
  1061. }
  1062. DHD_ERROR(("%s: RC %x:%x offset 0x%x val 0x%x\n",
  1063. __FUNCTION__, PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID, offset, val));
  1064. return (val);
  1065. }
  1066. /*
  1067. * Reads/ Writes the value of capability register
  1068. * from the given CAP_ID section of PCI Root Port
  1069. *
  1070. * Arguements
  1071. * @bus current dhd_bus_t pointer
  1072. * @cap Capability or Extended Capability ID to get
  1073. * @offset offset of Register to Read
  1074. * @is_ext TRUE if @cap is given for Extended Capability
  1075. * @is_write is set to TRUE to indicate write
  1076. * @val value to write
  1077. *
  1078. * Return Value
  1079. * Returns 0xffffffff on error
  1080. * on write success returns BCME_OK (0)
  1081. * on Read Success returns the value of register requested
  1082. * Note: caller shoud ensure valid capability ID and Ext. Capability ID.
  1083. */
  1084. uint32
  1085. dhdpcie_access_cap(struct pci_dev *pdev, int cap, uint offset, bool is_ext, bool is_write,
  1086. uint32 writeval)
  1087. {
  1088. int cap_ptr = 0;
  1089. uint32 ret = -1;
  1090. uint32 readval;
  1091. if (!(pdev)) {
  1092. DHD_ERROR(("%s: pdev is NULL\n", __FUNCTION__));
  1093. return ret;
  1094. }
  1095. /* Find Capability offset */
  1096. if (is_ext) {
  1097. /* removing max EXT_CAP_ID check as
  1098. * linux kernel definition's max value is not upadted yet as per spec
  1099. */
  1100. cap_ptr = pci_find_ext_capability(pdev, cap);
  1101. } else {
  1102. /* removing max PCI_CAP_ID_MAX check as
  1103. * pervious kernel versions dont have this definition
  1104. */
  1105. cap_ptr = pci_find_capability(pdev, cap);
  1106. }
  1107. /* Return if capability with given ID not found */
  1108. if (cap_ptr == 0) {
  1109. DHD_ERROR(("%s: PCI Cap(0x%02x) not supported.\n",
  1110. __FUNCTION__, cap));
  1111. return BCME_ERROR;
  1112. }
  1113. if (is_write) {
  1114. pci_write_config_dword(pdev, (cap_ptr + offset), writeval);
  1115. ret = BCME_OK;
  1116. } else {
  1117. pci_read_config_dword(pdev, (cap_ptr + offset), &readval);
  1118. ret = readval;
  1119. }
  1120. return ret;
  1121. }
  1122. uint32
  1123. dhdpcie_rc_access_cap(dhd_bus_t *bus, int cap, uint offset, bool is_ext, bool is_write,
  1124. uint32 writeval)
  1125. {
  1126. if (!(bus->rc_dev)) {
  1127. DHD_ERROR(("%s: RC %x:%x handle is NULL\n",
  1128. __FUNCTION__, PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID));
  1129. return BCME_ERROR;
  1130. }
  1131. return dhdpcie_access_cap(bus->rc_dev, cap, offset, is_ext, is_write, writeval);
  1132. }
  1133. uint32
  1134. dhdpcie_ep_access_cap(dhd_bus_t *bus, int cap, uint offset, bool is_ext, bool is_write,
  1135. uint32 writeval)
  1136. {
  1137. if (!(bus->dev)) {
  1138. DHD_ERROR(("%s: EP handle is NULL\n", __FUNCTION__));
  1139. return BCME_ERROR;
  1140. }
  1141. return dhdpcie_access_cap(bus->dev, cap, offset, is_ext, is_write, writeval);
  1142. }
  1143. /* API wrapper to read Root Port link capability
  1144. * Returns 2 = GEN2 1 = GEN1 BCME_ERR on linkcap not found
  1145. */
  1146. uint32 dhd_debug_get_rc_linkcap(dhd_bus_t *bus)
  1147. {
  1148. uint32 linkcap = -1;
  1149. linkcap = dhdpcie_rc_access_cap(bus, PCIE_CAP_ID_EXP,
  1150. PCIE_CAP_LINKCAP_OFFSET, FALSE, FALSE, 0);
  1151. linkcap &= PCIE_CAP_LINKCAP_LNKSPEED_MASK;
  1152. return linkcap;
  1153. }
  1154. static void dhdpcie_config_save_restore_coherent(dhd_bus_t *bus, bool state)
  1155. {
  1156. if (bus->coreid == ARMCA7_CORE_ID) {
  1157. if (state) {
  1158. /* Sleep */
  1159. bus->coherent_state = dhdpcie_bus_cfg_read_dword(bus,
  1160. PCIE_CFG_SUBSYSTEM_CONTROL, 4) & PCIE_BARCOHERENTACCEN_MASK;
  1161. } else {
  1162. uint32 val = (dhdpcie_bus_cfg_read_dword(bus, PCIE_CFG_SUBSYSTEM_CONTROL,
  1163. 4) & ~PCIE_BARCOHERENTACCEN_MASK) | bus->coherent_state;
  1164. dhdpcie_bus_cfg_write_dword(bus, PCIE_CFG_SUBSYSTEM_CONTROL, 4, val);
  1165. }
  1166. }
  1167. }
  1168. int dhdpcie_pci_suspend_resume(dhd_bus_t *bus, bool state)
  1169. {
  1170. int rc;
  1171. struct pci_dev *dev = bus->dev;
  1172. if (state) {
  1173. dhdpcie_config_save_restore_coherent(bus, state);
  1174. #if !defined(BCMPCIE_OOB_HOST_WAKE)
  1175. dhdpcie_pme_active(bus->osh, state);
  1176. #endif // endif
  1177. rc = dhdpcie_suspend_dev(dev);
  1178. if (!rc) {
  1179. dhdpcie_suspend_host_dev(bus);
  1180. }
  1181. } else {
  1182. rc = dhdpcie_resume_host_dev(bus);
  1183. if (!rc) {
  1184. rc = dhdpcie_resume_dev(dev);
  1185. if (PCIECTO_ENAB(bus)) {
  1186. /* reinit CTO configuration
  1187. * because cfg space got reset at D3 (PERST)
  1188. */
  1189. dhdpcie_cto_cfg_init(bus, TRUE);
  1190. }
  1191. if (PCIE_ENUM_RESET_WAR_ENAB(bus->sih->buscorerev)) {
  1192. dhdpcie_ssreset_dis_enum_rst(bus);
  1193. }
  1194. #if !defined(BCMPCIE_OOB_HOST_WAKE)
  1195. dhdpcie_pme_active(bus->osh, state);
  1196. #endif // endif
  1197. }
  1198. dhdpcie_config_save_restore_coherent(bus, state);
  1199. #if defined(OEM_ANDROID)
  1200. #if defined(DHD_HANG_SEND_UP_TEST)
  1201. if (bus->is_linkdown ||
  1202. bus->dhd->req_hang_type == HANG_REASON_PCIE_RC_LINK_UP_FAIL) {
  1203. #else /* DHD_HANG_SEND_UP_TEST */
  1204. if (bus->is_linkdown) {
  1205. #endif /* DHD_HANG_SEND_UP_TEST */
  1206. bus->dhd->hang_reason = HANG_REASON_PCIE_RC_LINK_UP_FAIL;
  1207. dhd_os_send_hang_message(bus->dhd);
  1208. }
  1209. #endif /* OEM_ANDROID */
  1210. }
  1211. return rc;
  1212. }
  1213. static int dhdpcie_device_scan(struct device *dev, void *data)
  1214. {
  1215. struct pci_dev *pcidev;
  1216. int *cnt = data;
  1217. #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
  1218. #pragma GCC diagnostic push
  1219. #pragma GCC diagnostic ignored "-Wcast-qual"
  1220. #endif // endif
  1221. pcidev = container_of(dev, struct pci_dev, dev);
  1222. #if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
  1223. #pragma GCC diagnostic pop
  1224. #endif // endif
  1225. if (pcidev->vendor != 0x14e4)
  1226. return 0;
  1227. DHD_INFO(("Found Broadcom PCI device 0x%04x\n", pcidev->device));
  1228. *cnt += 1;
  1229. if (pcidev->driver && strcmp(pcidev->driver->name, dhdpcie_driver.name))
  1230. DHD_ERROR(("Broadcom PCI Device 0x%04x has allocated with driver %s\n",
  1231. pcidev->device, pcidev->driver->name));
  1232. return 0;
  1233. }
  1234. int
  1235. dhdpcie_bus_register(void)
  1236. {
  1237. int error = 0;
  1238. if (!(error = pci_register_driver(&dhdpcie_driver))) {
  1239. bus_for_each_dev(dhdpcie_driver.driver.bus, NULL, &error, dhdpcie_device_scan);
  1240. if (!error) {
  1241. DHD_ERROR(("No Broadcom PCI device enumerated!\n"));
  1242. } else if (!dhdpcie_init_succeeded) {
  1243. DHD_ERROR(("%s: dhdpcie initialize failed.\n", __FUNCTION__));
  1244. } else {
  1245. return 0;
  1246. }
  1247. pci_unregister_driver(&dhdpcie_driver);
  1248. error = BCME_ERROR;
  1249. }
  1250. return error;
  1251. }
  1252. void
  1253. dhdpcie_bus_unregister(void)
  1254. {
  1255. pci_unregister_driver(&dhdpcie_driver);
  1256. }
  1257. int __devinit
  1258. dhdpcie_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  1259. {
  1260. #ifndef MULTI_CHIP_SUPPORT
  1261. /* Don't enumerate more than one device */
  1262. if (dhdpcie_init_succeeded) {
  1263. DHD_TRACE(("%s: PCIe Enumeration is already done.\n",
  1264. __func__));
  1265. return -ENODEV;
  1266. }
  1267. #endif /* MULTI_CHIP_SUPPORT */
  1268. if (dhdpcie_chipmatch (pdev->vendor, pdev->device)) {
  1269. DHD_ERROR(("%s: chipmatch failed!!\n", __FUNCTION__));
  1270. return -ENODEV;
  1271. }
  1272. printf("PCI_PROBE: bus %X, slot %X,vendor %X, device %X"
  1273. "(good PCI location)\n", pdev->bus->number,
  1274. PCI_SLOT(pdev->devfn), pdev->vendor, pdev->device);
  1275. if (dhdpcie_init_succeeded == TRUE) {
  1276. DHD_ERROR(("%s(): === Driver Already attached to a BRCM device === \r\n",
  1277. __FUNCTION__));
  1278. return -ENODEV;
  1279. }
  1280. if (dhdpcie_init (pdev)) {
  1281. DHD_ERROR(("%s: PCIe Enumeration failed\n", __FUNCTION__));
  1282. return -ENODEV;
  1283. }
  1284. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  1285. /*
  1286. Since MSM PCIe RC dev usage conunt already incremented +2 even
  1287. before dhdpcie_pci_probe() called, then we inevitably to call
  1288. pm_runtime_put_noidle() two times to make the count start with zero.
  1289. */
  1290. pm_runtime_put_noidle(&pdev->dev);
  1291. pm_runtime_put_noidle(&pdev->dev);
  1292. pm_runtime_set_suspended(&pdev->dev);
  1293. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  1294. #ifdef BCMPCIE_DISABLE_ASYNC_SUSPEND
  1295. /* disable async suspend */
  1296. device_disable_async_suspend(&pdev->dev);
  1297. #endif /* BCMPCIE_DISABLE_ASYNC_SUSPEND */
  1298. DHD_TRACE(("%s: PCIe Enumeration done!!\n", __FUNCTION__));
  1299. return 0;
  1300. }
  1301. int
  1302. dhdpcie_detach(dhdpcie_info_t *pch)
  1303. {
  1304. if (pch) {
  1305. #if defined(OEM_ANDROID) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1306. if (!dhd_download_fw_on_driverload) {
  1307. pci_load_and_free_saved_state(pch->dev, &pch->default_state);
  1308. }
  1309. #endif /* OEM_ANDROID && LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  1310. MFREE(pch->osh, pch, sizeof(dhdpcie_info_t));
  1311. }
  1312. return 0;
  1313. }
  1314. void __devexit
  1315. dhdpcie_pci_remove(struct pci_dev *pdev)
  1316. {
  1317. osl_t *osh = NULL;
  1318. dhdpcie_info_t *pch = NULL;
  1319. dhd_bus_t *bus = NULL;
  1320. DHD_TRACE(("%s Enter\n", __FUNCTION__));
  1321. pch = pci_get_drvdata(pdev);
  1322. bus = pch->bus;
  1323. osh = pch->osh;
  1324. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  1325. pm_runtime_get_noresume(&pdev->dev);
  1326. pm_runtime_get_noresume(&pdev->dev);
  1327. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  1328. if (bus) {
  1329. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1330. #ifdef CONFIG_ARCH_MSM
  1331. msm_pcie_deregister_event(&bus->pcie_event);
  1332. #endif /* CONFIG_ARCH_MSM */
  1333. #ifdef EXYNOS_PCIE_LINKDOWN_RECOVERY
  1334. #if defined(CONFIG_SOC_EXYNOS8890) || defined(CONFIG_SOC_EXYNOS8895) || \
  1335. defined(CONFIG_SOC_EXYNOS9810) || defined(CONFIG_SOC_EXYNOS9820)
  1336. exynos_pcie_deregister_event(&bus->pcie_event);
  1337. #endif /* CONFIG_SOC_EXYNOS8890 || CONFIG_SOC_EXYNOS8895 ||
  1338. * CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820
  1339. */
  1340. #endif /* EXYNOS_PCIE_LINKDOWN_RECOVERY */
  1341. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1342. bus->rc_dev = NULL;
  1343. dhdpcie_bus_release(bus);
  1344. }
  1345. if (pci_is_enabled(pdev))
  1346. pci_disable_device(pdev);
  1347. #ifdef BCMPCIE_OOB_HOST_WAKE
  1348. /* pcie os info detach */
  1349. MFREE(osh, pch->os_cxt, sizeof(dhdpcie_os_info_t));
  1350. #endif /* BCMPCIE_OOB_HOST_WAKE */
  1351. #ifdef USE_SMMU_ARCH_MSM
  1352. /* smmu info detach */
  1353. dhdpcie_smmu_remove(pdev, pch->smmu_cxt);
  1354. MFREE(osh, pch->smmu_cxt, sizeof(dhdpcie_smmu_info_t));
  1355. #endif /* USE_SMMU_ARCH_MSM */
  1356. /* pcie info detach */
  1357. dhdpcie_detach(pch);
  1358. /* osl detach */
  1359. osl_detach(osh);
  1360. #if defined(BCMPCIE_OOB_HOST_WAKE) && defined(CUSTOMER_HW2) && \
  1361. defined(CONFIG_ARCH_APQ8084)
  1362. brcm_pcie_wake.wake_irq = NULL;
  1363. brcm_pcie_wake.data = NULL;
  1364. #endif /* BCMPCIE_OOB_HOST_WAKE && CUSTOMR_HW2 && CONFIG_ARCH_APQ8084 */
  1365. dhdpcie_init_succeeded = FALSE;
  1366. DHD_TRACE(("%s Exit\n", __FUNCTION__));
  1367. return;
  1368. }
  1369. /* Enable Linux Msi */
  1370. int
  1371. dhdpcie_enable_msi(struct pci_dev *pdev, unsigned int min_vecs, unsigned int max_vecs)
  1372. {
  1373. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  1374. return pci_alloc_irq_vectors(pdev, min_vecs, max_vecs, PCI_IRQ_MSI);
  1375. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0))
  1376. return pci_enable_msi_range(pdev, min_vecs, max_vecs);
  1377. #else
  1378. return pci_enable_msi_block(pdev, max_vecs);
  1379. #endif // endif
  1380. }
  1381. /* Disable Linux Msi */
  1382. void
  1383. dhdpcie_disable_msi(struct pci_dev *pdev)
  1384. {
  1385. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0))
  1386. pci_free_irq_vectors(pdev);
  1387. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
  1388. pci_disable_msi(pdev);
  1389. #else
  1390. pci_disable_msi(pdev);
  1391. #endif // endif
  1392. return;
  1393. }
  1394. /* Request Linux irq */
  1395. int
  1396. dhdpcie_request_irq(dhdpcie_info_t *dhdpcie_info)
  1397. {
  1398. dhd_bus_t *bus = dhdpcie_info->bus;
  1399. struct pci_dev *pdev = dhdpcie_info->bus->dev;
  1400. int host_irq_disabled;
  1401. if (!bus->irq_registered) {
  1402. snprintf(dhdpcie_info->pciname, sizeof(dhdpcie_info->pciname),
  1403. "dhdpcie:%s", pci_name(pdev));
  1404. if (bus->d2h_intr_method == PCIE_MSI) {
  1405. if (dhdpcie_enable_msi(pdev, 1, 1) < 0) {
  1406. DHD_ERROR(("%s: dhdpcie_enable_msi() failed\n", __FUNCTION__));
  1407. dhdpcie_disable_msi(pdev);
  1408. bus->d2h_intr_method = PCIE_INTX;
  1409. }
  1410. }
  1411. if (request_irq(pdev->irq, dhdpcie_isr, IRQF_SHARED,
  1412. dhdpcie_info->pciname, bus) < 0) {
  1413. DHD_ERROR(("%s: request_irq() failed\n", __FUNCTION__));
  1414. if (bus->d2h_intr_method == PCIE_MSI) {
  1415. dhdpcie_disable_msi(pdev);
  1416. }
  1417. return -1;
  1418. }
  1419. else {
  1420. bus->irq_registered = TRUE;
  1421. }
  1422. } else {
  1423. DHD_ERROR(("%s: PCI IRQ is already registered\n", __FUNCTION__));
  1424. }
  1425. host_irq_disabled = dhdpcie_irq_disabled(bus);
  1426. if (host_irq_disabled) {
  1427. DHD_ERROR(("%s: PCIe IRQ was disabled(%d), so, enabled it again\n",
  1428. __FUNCTION__, host_irq_disabled));
  1429. dhdpcie_enable_irq(bus);
  1430. }
  1431. DHD_TRACE(("%s %s\n", __FUNCTION__, dhdpcie_info->pciname));
  1432. return 0; /* SUCCESS */
  1433. }
  1434. /**
  1435. * dhdpcie_get_pcieirq - return pcie irq number to linux-dhd
  1436. */
  1437. int
  1438. dhdpcie_get_pcieirq(struct dhd_bus *bus, unsigned int *irq)
  1439. {
  1440. struct pci_dev *pdev = bus->dev;
  1441. if (!pdev) {
  1442. DHD_ERROR(("%s : bus->dev is NULL\n", __FUNCTION__));
  1443. return -ENODEV;
  1444. }
  1445. *irq = pdev->irq;
  1446. return 0; /* SUCCESS */
  1447. }
  1448. #ifdef CONFIG_PHYS_ADDR_T_64BIT
  1449. #define PRINTF_RESOURCE "0x%016llx"
  1450. #else
  1451. #define PRINTF_RESOURCE "0x%08x"
  1452. #endif // endif
  1453. #ifdef EXYNOS_PCIE_MODULE_PATCH
  1454. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1455. extern struct pci_saved_state *bcm_pcie_default_state;
  1456. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  1457. #endif /* EXYNOS_MODULE_PATCH */
  1458. /*
  1459. Name: osl_pci_get_resource
  1460. Parametrs:
  1461. 1: struct pci_dev *pdev -- pci device structure
  1462. 2: pci_res -- structure containing pci configuration space values
  1463. Return value:
  1464. int - Status (TRUE or FALSE)
  1465. Description:
  1466. Access PCI configuration space, retrieve PCI allocated resources , updates in resource structure.
  1467. */
  1468. int dhdpcie_get_resource(dhdpcie_info_t *dhdpcie_info)
  1469. {
  1470. phys_addr_t bar0_addr, bar1_addr;
  1471. ulong bar1_size;
  1472. struct pci_dev *pdev = dhdpcie_info->dev;
  1473. #if defined(CONFIG_ARCH_MSM) && !defined(ENABLE_INSMOD_NO_FW_LOAD)
  1474. int ret;
  1475. /* enable PCIe link */
  1476. ret = msm_pcie_pm_control(MSM_PCIE_RESUME, pdev->bus->number,
  1477. pdev, NULL, MSM_PCIE_CONFIG_NO_CFG_RESTORE);
  1478. if (ret) {
  1479. DHD_ERROR(("%s: MSM_PCIE_RESUME failed : %d\n", __FUNCTION__, ret));
  1480. goto err;
  1481. }
  1482. DHD_ERROR(("PCIe:%s:enabled link\n", __FUNCTION__));
  1483. /* recover the config space of both RC and Endpoint */
  1484. msm_pcie_recover_config(pdev);
  1485. #endif /* CONFIG_ARCH_MSM && !ENABLE_INSMOD_NO_FW_LOAD */
  1486. #ifdef EXYNOS_PCIE_MODULE_PATCH
  1487. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1488. if (bcm_pcie_default_state) {
  1489. pci_load_saved_state(pdev, bcm_pcie_default_state);
  1490. pci_restore_state(pdev);
  1491. }
  1492. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  1493. #endif /* EXYNOS_MODULE_PATCH */
  1494. do {
  1495. if (pci_enable_device(pdev)) {
  1496. printf("%s: Cannot enable PCI device\n", __FUNCTION__);
  1497. break;
  1498. }
  1499. pci_set_master(pdev);
  1500. bar0_addr = pci_resource_start(pdev, 0); /* Bar-0 mapped address */
  1501. bar1_addr = pci_resource_start(pdev, 2); /* Bar-1 mapped address */
  1502. /* read Bar-1 mapped memory range */
  1503. bar1_size = pci_resource_len(pdev, 2);
  1504. if ((bar1_size == 0) || (bar1_addr == 0)) {
  1505. printf("%s: BAR1 Not enabled for this device size(%ld),"
  1506. " addr(0x"PRINTF_RESOURCE")\n",
  1507. __FUNCTION__, bar1_size, bar1_addr);
  1508. goto err;
  1509. }
  1510. dhdpcie_info->regs = (volatile char *) REG_MAP(bar0_addr, DONGLE_REG_MAP_SIZE);
  1511. dhdpcie_info->bar1_size =
  1512. (bar1_size > DONGLE_TCM_MAP_SIZE) ? bar1_size : DONGLE_TCM_MAP_SIZE;
  1513. dhdpcie_info->tcm = (volatile char *) REG_MAP(bar1_addr, dhdpcie_info->bar1_size);
  1514. if (!dhdpcie_info->regs || !dhdpcie_info->tcm) {
  1515. DHD_ERROR(("%s:ioremap() failed\n", __FUNCTION__));
  1516. break;
  1517. }
  1518. #ifdef EXYNOS_PCIE_MODULE_PATCH
  1519. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1520. if (bcm_pcie_default_state == NULL) {
  1521. pci_save_state(pdev);
  1522. bcm_pcie_default_state = pci_store_saved_state(pdev);
  1523. }
  1524. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  1525. #endif /* EXYNOS_MODULE_PATCH */
  1526. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  1527. /* Backup PCIe configuration so as to use Wi-Fi on/off process
  1528. * in case of built in driver
  1529. */
  1530. pci_save_state(pdev);
  1531. dhdpcie_info->default_state = pci_store_saved_state(pdev);
  1532. if (dhdpcie_info->default_state == NULL) {
  1533. DHD_ERROR(("%s pci_store_saved_state returns NULL\n",
  1534. __FUNCTION__));
  1535. REG_UNMAP(dhdpcie_info->regs);
  1536. REG_UNMAP(dhdpcie_info->tcm);
  1537. pci_disable_device(pdev);
  1538. break;
  1539. }
  1540. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  1541. DHD_TRACE(("%s:Phys addr : reg space = %p base addr 0x"PRINTF_RESOURCE" \n",
  1542. __FUNCTION__, dhdpcie_info->regs, bar0_addr));
  1543. DHD_TRACE(("%s:Phys addr : tcm_space = %p base addr 0x"PRINTF_RESOURCE" \n",
  1544. __FUNCTION__, dhdpcie_info->tcm, bar1_addr));
  1545. return 0; /* SUCCESS */
  1546. } while (0);
  1547. err:
  1548. return -1; /* FAILURE */
  1549. }
  1550. int dhdpcie_scan_resource(dhdpcie_info_t *dhdpcie_info)
  1551. {
  1552. DHD_TRACE(("%s: ENTER\n", __FUNCTION__));
  1553. do {
  1554. /* define it here only!! */
  1555. if (dhdpcie_get_resource (dhdpcie_info)) {
  1556. DHD_ERROR(("%s: Failed to get PCI resources\n", __FUNCTION__));
  1557. break;
  1558. }
  1559. DHD_TRACE(("%s:Exit - SUCCESS \n",
  1560. __FUNCTION__));
  1561. return 0; /* SUCCESS */
  1562. } while (0);
  1563. DHD_TRACE(("%s:Exit - FAILURE \n", __FUNCTION__));
  1564. return -1; /* FAILURE */
  1565. }
  1566. void dhdpcie_dump_resource(dhd_bus_t *bus)
  1567. {
  1568. dhdpcie_info_t *pch;
  1569. if (bus == NULL) {
  1570. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  1571. return;
  1572. }
  1573. if (bus->dev == NULL) {
  1574. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  1575. return;
  1576. }
  1577. pch = pci_get_drvdata(bus->dev);
  1578. if (pch == NULL) {
  1579. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  1580. return;
  1581. }
  1582. /* BAR0 */
  1583. DHD_ERROR(("%s: BAR0(VA): 0x%pK, BAR0(PA): "PRINTF_RESOURCE", SIZE: %d\n",
  1584. __FUNCTION__, pch->regs, pci_resource_start(bus->dev, 0),
  1585. DONGLE_REG_MAP_SIZE));
  1586. /* BAR1 */
  1587. DHD_ERROR(("%s: BAR1(VA): 0x%pK, BAR1(PA): "PRINTF_RESOURCE", SIZE: %d\n",
  1588. __FUNCTION__, pch->tcm, pci_resource_start(bus->dev, 2),
  1589. pch->bar1_size));
  1590. }
  1591. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1592. #if defined(CONFIG_ARCH_MSM) || (defined(EXYNOS_PCIE_LINKDOWN_RECOVERY) && \
  1593. (defined(CONFIG_SOC_EXYNOS8890) || defined(CONFIG_SOC_EXYNOS8895) || \
  1594. defined(CONFIG_SOC_EXYNOS9810) || defined(CONFIG_SOC_EXYNOS9820)))
  1595. void dhdpcie_linkdown_cb(struct_pcie_notify *noti)
  1596. {
  1597. struct pci_dev *pdev = (struct pci_dev *)noti->user;
  1598. dhdpcie_info_t *pch = NULL;
  1599. if (pdev) {
  1600. pch = pci_get_drvdata(pdev);
  1601. if (pch) {
  1602. dhd_bus_t *bus = pch->bus;
  1603. if (bus) {
  1604. dhd_pub_t *dhd = bus->dhd;
  1605. if (dhd) {
  1606. DHD_ERROR(("%s: Event HANG send up "
  1607. "due to PCIe linkdown\n",
  1608. __FUNCTION__));
  1609. #ifdef CONFIG_ARCH_MSM
  1610. bus->no_cfg_restore = 1;
  1611. #endif /* CONFIG_ARCH_MSM */
  1612. bus->is_linkdown = 1;
  1613. DHD_OS_WAKE_LOCK(dhd);
  1614. dhd->hang_reason = HANG_REASON_PCIE_LINK_DOWN_RC_DETECT;
  1615. dhd_os_send_hang_message(dhd);
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. #endif /* CONFIG_ARCH_MSM || (EXYNOS_PCIE_LINKDOWN_RECOVERY &&
  1622. * (CONFIG_SOC_EXYNOS8890 || CONFIG_SOC_EXYNOS8895 || \
  1623. * CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820))
  1624. */
  1625. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1626. int dhdpcie_init(struct pci_dev *pdev)
  1627. {
  1628. osl_t *osh = NULL;
  1629. dhd_bus_t *bus = NULL;
  1630. dhdpcie_info_t *dhdpcie_info = NULL;
  1631. wifi_adapter_info_t *adapter = NULL;
  1632. #ifdef BCMPCIE_OOB_HOST_WAKE
  1633. dhdpcie_os_info_t *dhdpcie_osinfo = NULL;
  1634. #endif /* BCMPCIE_OOB_HOST_WAKE */
  1635. #ifdef USE_SMMU_ARCH_MSM
  1636. dhdpcie_smmu_info_t *dhdpcie_smmu_info = NULL;
  1637. #endif /* USE_SMMU_ARCH_MSM */
  1638. int ret = 0;
  1639. do {
  1640. /* osl attach */
  1641. if (!(osh = osl_attach(pdev, PCI_BUS, FALSE))) {
  1642. DHD_ERROR(("%s: osl_attach failed\n", __FUNCTION__));
  1643. break;
  1644. }
  1645. /* initialize static buffer */
  1646. adapter = dhd_wifi_platform_get_adapter(PCI_BUS, pdev->bus->number,
  1647. PCI_SLOT(pdev->devfn));
  1648. if (adapter != NULL)
  1649. DHD_ERROR(("%s: found adapter info '%s'\n", __FUNCTION__, adapter->name));
  1650. else
  1651. DHD_ERROR(("%s: can't find adapter info for this chip\n", __FUNCTION__));
  1652. osl_static_mem_init(osh, adapter);
  1653. /* Set ACP coherence flag */
  1654. if (OSL_ACP_WAR_ENAB() || OSL_ARCH_IS_COHERENT())
  1655. osl_flag_set(osh, OSL_ACP_COHERENCE);
  1656. /* allocate linux spcific pcie structure here */
  1657. if (!(dhdpcie_info = MALLOC(osh, sizeof(dhdpcie_info_t)))) {
  1658. DHD_ERROR(("%s: MALLOC of dhd_bus_t failed\n", __FUNCTION__));
  1659. break;
  1660. }
  1661. bzero(dhdpcie_info, sizeof(dhdpcie_info_t));
  1662. dhdpcie_info->osh = osh;
  1663. dhdpcie_info->dev = pdev;
  1664. #ifdef BCMPCIE_OOB_HOST_WAKE
  1665. /* allocate OS speicific structure */
  1666. dhdpcie_osinfo = MALLOC(osh, sizeof(dhdpcie_os_info_t));
  1667. if (dhdpcie_osinfo == NULL) {
  1668. DHD_ERROR(("%s: MALLOC of dhdpcie_os_info_t failed\n",
  1669. __FUNCTION__));
  1670. break;
  1671. }
  1672. bzero(dhdpcie_osinfo, sizeof(dhdpcie_os_info_t));
  1673. dhdpcie_info->os_cxt = (void *)dhdpcie_osinfo;
  1674. /* Initialize host wake IRQ */
  1675. spin_lock_init(&dhdpcie_osinfo->oob_irq_spinlock);
  1676. /* Get customer specific host wake IRQ parametres: IRQ number as IRQ type */
  1677. dhdpcie_osinfo->oob_irq_num = wifi_platform_get_irq_number(adapter,
  1678. &dhdpcie_osinfo->oob_irq_flags);
  1679. if (dhdpcie_osinfo->oob_irq_num < 0) {
  1680. DHD_ERROR(("%s: Host OOB irq is not defined\n", __FUNCTION__));
  1681. }
  1682. #endif /* BCMPCIE_OOB_HOST_WAKE */
  1683. #ifdef USE_SMMU_ARCH_MSM
  1684. /* allocate private structure for using SMMU */
  1685. dhdpcie_smmu_info = MALLOC(osh, sizeof(dhdpcie_smmu_info_t));
  1686. if (dhdpcie_smmu_info == NULL) {
  1687. DHD_ERROR(("%s: MALLOC of dhdpcie_smmu_info_t failed\n",
  1688. __FUNCTION__));
  1689. break;
  1690. }
  1691. bzero(dhdpcie_smmu_info, sizeof(dhdpcie_smmu_info_t));
  1692. dhdpcie_info->smmu_cxt = (void *)dhdpcie_smmu_info;
  1693. /* Initialize smmu structure */
  1694. if (dhdpcie_smmu_init(pdev, dhdpcie_info->smmu_cxt) < 0) {
  1695. DHD_ERROR(("%s: Failed to initialize SMMU\n",
  1696. __FUNCTION__));
  1697. break;
  1698. }
  1699. #endif /* USE_SMMU_ARCH_MSM */
  1700. #ifdef DHD_WAKE_STATUS
  1701. /* Initialize pcie_lock */
  1702. spin_lock_init(&dhdpcie_info->pcie_lock);
  1703. #endif /* DHD_WAKE_STATUS */
  1704. /* Find the PCI resources, verify the */
  1705. /* vendor and device ID, map BAR regions and irq, update in structures */
  1706. if (dhdpcie_scan_resource(dhdpcie_info)) {
  1707. DHD_ERROR(("%s: dhd_Scan_PCI_Res failed\n", __FUNCTION__));
  1708. break;
  1709. }
  1710. /* Bus initialization */
  1711. ret = dhdpcie_bus_attach(osh, &bus, dhdpcie_info->regs, dhdpcie_info->tcm, pdev);
  1712. if (ret != BCME_OK) {
  1713. DHD_ERROR(("%s:dhdpcie_bus_attach() failed\n", __FUNCTION__));
  1714. break;
  1715. }
  1716. dhdpcie_info->bus = bus;
  1717. bus->is_linkdown = 0;
  1718. bus->no_bus_init = FALSE;
  1719. bus->cto_triggered = 0;
  1720. bus->rc_dev = NULL;
  1721. /* Get RC Device Handle */
  1722. if (bus->dev->bus) {
  1723. /* self member of structure pci_bus is bridge device as seen by parent */
  1724. bus->rc_dev = bus->dev->bus->self;
  1725. DHD_ERROR(("%s: rc_dev from dev->bus->self (%x:%x) is %pK\n", __FUNCTION__,
  1726. bus->rc_dev->vendor, bus->rc_dev->device, bus->rc_dev));
  1727. } else {
  1728. DHD_ERROR(("%s: unable to get rc_dev as dev->bus is NULL\n", __FUNCTION__));
  1729. }
  1730. /* if rc_dev is still NULL, try to get from vendor/device IDs */
  1731. if (bus->rc_dev == NULL) {
  1732. bus->rc_dev = pci_get_device(PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID, NULL);
  1733. DHD_ERROR(("%s: rc_dev from pci_get_device (%x:%x) is %p\n", __FUNCTION__,
  1734. PCIE_RC_VENDOR_ID, PCIE_RC_DEVICE_ID, bus->rc_dev));
  1735. }
  1736. bus->rc_ep_aspm_cap = dhd_bus_is_rc_ep_aspm_capable(bus);
  1737. bus->rc_ep_l1ss_cap = dhd_bus_is_rc_ep_l1ss_capable(bus);
  1738. DHD_ERROR(("%s: rc_ep_aspm_cap: %d rc_ep_l1ss_cap: %d\n",
  1739. __FUNCTION__, bus->rc_ep_aspm_cap, bus->rc_ep_l1ss_cap));
  1740. #ifdef FORCE_TPOWERON
  1741. if (dhdpcie_chip_req_forced_tpoweron(bus)) {
  1742. dhd_bus_set_tpoweron(bus, tpoweron_scale);
  1743. }
  1744. #endif /* FORCE_TPOWERON */
  1745. #if defined(BCMPCIE_OOB_HOST_WAKE) && defined(CUSTOMER_HW2) && \
  1746. defined(CONFIG_ARCH_APQ8084)
  1747. brcm_pcie_wake.wake_irq = wlan_oob_irq;
  1748. brcm_pcie_wake.data = bus;
  1749. #endif /* BCMPCIE_OOB_HOST_WAKE && CUSTOMR_HW2 && CONFIG_ARCH_APQ8084 */
  1750. #ifdef DONGLE_ENABLE_ISOLATION
  1751. bus->dhd->dongle_isolation = TRUE;
  1752. #endif /* DONGLE_ENABLE_ISOLATION */
  1753. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1754. #ifdef CONFIG_ARCH_MSM
  1755. bus->pcie_event.events = MSM_PCIE_EVENT_LINKDOWN;
  1756. bus->pcie_event.user = pdev;
  1757. bus->pcie_event.mode = MSM_PCIE_TRIGGER_CALLBACK;
  1758. bus->pcie_event.callback = dhdpcie_linkdown_cb;
  1759. bus->pcie_event.options = MSM_PCIE_CONFIG_NO_RECOVERY;
  1760. msm_pcie_register_event(&bus->pcie_event);
  1761. bus->no_cfg_restore = FALSE;
  1762. #endif /* CONFIG_ARCH_MSM */
  1763. #ifdef EXYNOS_PCIE_LINKDOWN_RECOVERY
  1764. #if defined(CONFIG_SOC_EXYNOS8890) || defined(CONFIG_SOC_EXYNOS8895) || \
  1765. defined(CONFIG_SOC_EXYNOS9810) || defined(CONFIG_SOC_EXYNOS9820)
  1766. bus->pcie_event.events = EXYNOS_PCIE_EVENT_LINKDOWN;
  1767. bus->pcie_event.user = pdev;
  1768. bus->pcie_event.mode = EXYNOS_PCIE_TRIGGER_CALLBACK;
  1769. bus->pcie_event.callback = dhdpcie_linkdown_cb;
  1770. exynos_pcie_register_event(&bus->pcie_event);
  1771. #endif /* CONFIG_SOC_EXYNOS8890 || CONFIG_SOC_EXYNOS8895 ||
  1772. * CONFIG_SOC_EXYNOS9810 || CONFIG_SOC_EXYNOS9820
  1773. */
  1774. #endif /* EXYNOS_PCIE_LINKDOWN_RECOVERY */
  1775. bus->read_shm_fail = FALSE;
  1776. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1777. if (bus->intr) {
  1778. /* Register interrupt callback, but mask it (not operational yet). */
  1779. DHD_INTR(("%s: Registering and masking interrupts\n", __FUNCTION__));
  1780. dhdpcie_bus_intr_disable(bus);
  1781. if (dhdpcie_request_irq(dhdpcie_info)) {
  1782. DHD_ERROR(("%s: request_irq() failed\n", __FUNCTION__));
  1783. break;
  1784. }
  1785. } else {
  1786. bus->pollrate = 1;
  1787. DHD_INFO(("%s: PCIe interrupt function is NOT registered "
  1788. "due to polling mode\n", __FUNCTION__));
  1789. }
  1790. #if defined(BCM_REQUEST_FW)
  1791. if (dhd_bus_download_firmware(bus, osh, NULL, NULL) < 0) {
  1792. DHD_ERROR(("%s: failed to download firmware\n", __FUNCTION__));
  1793. }
  1794. bus->nv_path = NULL;
  1795. bus->fw_path = NULL;
  1796. #endif /* BCM_REQUEST_FW */
  1797. /* set private data for pci_dev */
  1798. pci_set_drvdata(pdev, dhdpcie_info);
  1799. if (dhd_download_fw_on_driverload) {
  1800. if (dhd_bus_start(bus->dhd)) {
  1801. DHD_ERROR(("%s: dhd_bud_start() failed\n", __FUNCTION__));
  1802. if (!allow_delay_fwdl)
  1803. break;
  1804. }
  1805. } else {
  1806. /* Set ramdom MAC address during boot time */
  1807. get_random_bytes(&bus->dhd->mac.octet[3], 3);
  1808. /* Adding BRCM OUI */
  1809. bus->dhd->mac.octet[0] = 0;
  1810. bus->dhd->mac.octet[1] = 0x90;
  1811. bus->dhd->mac.octet[2] = 0x4C;
  1812. }
  1813. /* Attach to the OS network interface */
  1814. DHD_TRACE(("%s(): Calling dhd_register_if() \n", __FUNCTION__));
  1815. if (dhd_attach_net(bus->dhd, TRUE)) {
  1816. DHD_ERROR(("%s(): ERROR.. dhd_register_if() failed\n", __FUNCTION__));
  1817. break;
  1818. }
  1819. #ifdef WL_VIF_SUPPORT
  1820. /* Attach to the virtual interface */
  1821. DHD_TRACE(("%s(): Calling dhd_register_vif() \n", __FUNCTION__));
  1822. if (dhd_register_vif(bus->dhd) != 0) {
  1823. DHD_ERROR(("%s(): ERROR.. dhd_register_vif() failed\n", __FUNCTION__));
  1824. }
  1825. #endif // endif
  1826. dhdpcie_init_succeeded = TRUE;
  1827. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  1828. pm_runtime_set_autosuspend_delay(&pdev->dev, AUTO_SUSPEND_TIMEOUT);
  1829. pm_runtime_use_autosuspend(&pdev->dev);
  1830. atomic_set(&bus->dhd->block_bus, FALSE);
  1831. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  1832. DHD_TRACE(("%s:Exit - SUCCESS \n", __FUNCTION__));
  1833. return 0; /* return SUCCESS */
  1834. } while (0);
  1835. /* reverse the initialization in order in case of error */
  1836. if (bus)
  1837. dhdpcie_bus_release(bus);
  1838. #ifdef BCMPCIE_OOB_HOST_WAKE
  1839. if (dhdpcie_osinfo) {
  1840. MFREE(osh, dhdpcie_osinfo, sizeof(dhdpcie_os_info_t));
  1841. }
  1842. #endif /* BCMPCIE_OOB_HOST_WAKE */
  1843. #ifdef USE_SMMU_ARCH_MSM
  1844. if (dhdpcie_smmu_info) {
  1845. MFREE(osh, dhdpcie_smmu_info, sizeof(dhdpcie_smmu_info_t));
  1846. dhdpcie_info->smmu_cxt = NULL;
  1847. }
  1848. #endif /* USE_SMMU_ARCH_MSM */
  1849. if (dhdpcie_info)
  1850. dhdpcie_detach(dhdpcie_info);
  1851. pci_disable_device(pdev);
  1852. if (osh)
  1853. osl_detach(osh);
  1854. dhdpcie_init_succeeded = FALSE;
  1855. DHD_TRACE(("%s:Exit - FAILURE \n", __FUNCTION__));
  1856. return -1; /* return FAILURE */
  1857. }
  1858. /* Free Linux irq */
  1859. void
  1860. dhdpcie_free_irq(dhd_bus_t *bus)
  1861. {
  1862. struct pci_dev *pdev = NULL;
  1863. DHD_TRACE(("%s: freeing up the IRQ\n", __FUNCTION__));
  1864. if (bus) {
  1865. pdev = bus->dev;
  1866. if (bus->irq_registered) {
  1867. free_irq(pdev->irq, bus);
  1868. bus->irq_registered = FALSE;
  1869. if (bus->d2h_intr_method == PCIE_MSI) {
  1870. dhdpcie_disable_msi(pdev);
  1871. }
  1872. } else {
  1873. DHD_ERROR(("%s: PCIe IRQ is not registered\n", __FUNCTION__));
  1874. }
  1875. }
  1876. DHD_TRACE(("%s: Exit\n", __FUNCTION__));
  1877. return;
  1878. }
  1879. /*
  1880. Name: dhdpcie_isr
  1881. Parametrs:
  1882. 1: IN int irq -- interrupt vector
  1883. 2: IN void *arg -- handle to private data structure
  1884. Return value:
  1885. Status (TRUE or FALSE)
  1886. Description:
  1887. Interrupt Service routine checks for the status register,
  1888. disable interrupt and queue DPC if mail box interrupts are raised.
  1889. */
  1890. irqreturn_t
  1891. dhdpcie_isr(int irq, void *arg)
  1892. {
  1893. dhd_bus_t *bus = (dhd_bus_t*)arg;
  1894. bus->isr_entry_time = OSL_LOCALTIME_NS();
  1895. if (!dhdpcie_bus_isr(bus)) {
  1896. DHD_LOG_MEM(("%s: dhdpcie_bus_isr returns with FALSE\n", __FUNCTION__));
  1897. }
  1898. bus->isr_exit_time = OSL_LOCALTIME_NS();
  1899. return IRQ_HANDLED;
  1900. }
  1901. int
  1902. dhdpcie_disable_irq_nosync(dhd_bus_t *bus)
  1903. {
  1904. struct pci_dev *dev;
  1905. if ((bus == NULL) || (bus->dev == NULL)) {
  1906. DHD_ERROR(("%s: bus or bus->dev is NULL\n", __FUNCTION__));
  1907. return BCME_ERROR;
  1908. }
  1909. dev = bus->dev;
  1910. disable_irq_nosync(dev->irq);
  1911. return BCME_OK;
  1912. }
  1913. int
  1914. dhdpcie_disable_irq(dhd_bus_t *bus)
  1915. {
  1916. struct pci_dev *dev;
  1917. if ((bus == NULL) || (bus->dev == NULL)) {
  1918. DHD_ERROR(("%s: bus or bus->dev is NULL\n", __FUNCTION__));
  1919. return BCME_ERROR;
  1920. }
  1921. dev = bus->dev;
  1922. disable_irq(dev->irq);
  1923. return BCME_OK;
  1924. }
  1925. int
  1926. dhdpcie_enable_irq(dhd_bus_t *bus)
  1927. {
  1928. struct pci_dev *dev;
  1929. if ((bus == NULL) || (bus->dev == NULL)) {
  1930. DHD_ERROR(("%s: bus or bus->dev is NULL\n", __FUNCTION__));
  1931. return BCME_ERROR;
  1932. }
  1933. dev = bus->dev;
  1934. enable_irq(dev->irq);
  1935. return BCME_OK;
  1936. }
  1937. int
  1938. dhdpcie_irq_disabled(dhd_bus_t *bus)
  1939. {
  1940. struct irq_desc *desc = irq_to_desc(bus->dev->irq);
  1941. /* depth will be zero, if enabled */
  1942. return desc->depth;
  1943. }
  1944. int
  1945. dhdpcie_start_host_pcieclock(dhd_bus_t *bus)
  1946. {
  1947. int ret = 0;
  1948. #ifdef CONFIG_ARCH_MSM
  1949. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1950. int options = 0;
  1951. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1952. #endif /* CONFIG_ARCH_MSM */
  1953. DHD_TRACE(("%s Enter:\n", __FUNCTION__));
  1954. if (bus == NULL) {
  1955. return BCME_ERROR;
  1956. }
  1957. if (bus->dev == NULL) {
  1958. return BCME_ERROR;
  1959. }
  1960. #ifdef CONFIG_ARCH_MSM
  1961. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1962. if (bus->no_cfg_restore) {
  1963. options = MSM_PCIE_CONFIG_NO_CFG_RESTORE;
  1964. }
  1965. ret = msm_pcie_pm_control(MSM_PCIE_RESUME, bus->dev->bus->number,
  1966. bus->dev, NULL, options);
  1967. if (bus->no_cfg_restore && !ret) {
  1968. msm_pcie_recover_config(bus->dev);
  1969. bus->no_cfg_restore = 0;
  1970. }
  1971. #else
  1972. ret = msm_pcie_pm_control(MSM_PCIE_RESUME, bus->dev->bus->number,
  1973. bus->dev, NULL, 0);
  1974. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1975. if (ret) {
  1976. DHD_ERROR(("%s Failed to bring up PCIe link\n", __FUNCTION__));
  1977. goto done;
  1978. }
  1979. done:
  1980. #endif /* CONFIG_ARCH_MSM */
  1981. DHD_TRACE(("%s Exit:\n", __FUNCTION__));
  1982. return ret;
  1983. }
  1984. int
  1985. dhdpcie_stop_host_pcieclock(dhd_bus_t *bus)
  1986. {
  1987. int ret = 0;
  1988. #ifdef CONFIG_ARCH_MSM
  1989. #ifdef SUPPORT_LINKDOWN_RECOVERY
  1990. int options = 0;
  1991. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  1992. #endif /* CONFIG_ARCH_MSM */
  1993. DHD_TRACE(("%s Enter:\n", __FUNCTION__));
  1994. if (bus == NULL) {
  1995. return BCME_ERROR;
  1996. }
  1997. if (bus->dev == NULL) {
  1998. return BCME_ERROR;
  1999. }
  2000. #ifdef CONFIG_ARCH_MSM
  2001. #ifdef SUPPORT_LINKDOWN_RECOVERY
  2002. if (bus->no_cfg_restore) {
  2003. options = MSM_PCIE_CONFIG_NO_CFG_RESTORE | MSM_PCIE_CONFIG_LINKDOWN;
  2004. }
  2005. ret = msm_pcie_pm_control(MSM_PCIE_SUSPEND, bus->dev->bus->number,
  2006. bus->dev, NULL, options);
  2007. #else
  2008. ret = msm_pcie_pm_control(MSM_PCIE_SUSPEND, bus->dev->bus->number,
  2009. bus->dev, NULL, 0);
  2010. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  2011. if (ret) {
  2012. DHD_ERROR(("Failed to stop PCIe link\n"));
  2013. goto done;
  2014. }
  2015. done:
  2016. #endif /* CONFIG_ARCH_MSM */
  2017. DHD_TRACE(("%s Exit:\n", __FUNCTION__));
  2018. return ret;
  2019. }
  2020. int
  2021. dhdpcie_disable_device(dhd_bus_t *bus)
  2022. {
  2023. DHD_TRACE(("%s Enter:\n", __FUNCTION__));
  2024. if (bus == NULL) {
  2025. return BCME_ERROR;
  2026. }
  2027. if (bus->dev == NULL) {
  2028. return BCME_ERROR;
  2029. }
  2030. if (pci_is_enabled(bus->dev))
  2031. pci_disable_device(bus->dev);
  2032. return 0;
  2033. }
  2034. int
  2035. dhdpcie_enable_device(dhd_bus_t *bus)
  2036. {
  2037. int ret = BCME_ERROR;
  2038. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  2039. dhdpcie_info_t *pch;
  2040. #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0) */
  2041. DHD_TRACE(("%s Enter:\n", __FUNCTION__));
  2042. if (bus == NULL) {
  2043. return BCME_ERROR;
  2044. }
  2045. if (bus->dev == NULL) {
  2046. return BCME_ERROR;
  2047. }
  2048. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0))
  2049. pch = pci_get_drvdata(bus->dev);
  2050. if (pch == NULL) {
  2051. return BCME_ERROR;
  2052. }
  2053. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)) && (LINUX_VERSION_CODE < \
  2054. KERNEL_VERSION(3, 19, 0)) && !defined(CONFIG_SOC_EXYNOS8890)
  2055. /* Updated with pci_load_and_free_saved_state to compatible
  2056. * with Kernel version 3.14.0 to 3.18.41.
  2057. */
  2058. pci_load_and_free_saved_state(bus->dev, &pch->default_state);
  2059. pch->default_state = pci_store_saved_state(bus->dev);
  2060. #else
  2061. pci_load_saved_state(bus->dev, pch->default_state);
  2062. #endif /* LINUX_VERSION >= 3.14.0 && LINUX_VERSION < 3.19.0 && !CONFIG_SOC_EXYNOS8890 */
  2063. /* Check if Device ID is valid */
  2064. if (bus->dev->state_saved) {
  2065. uint32 vid, saved_vid;
  2066. pci_read_config_dword(bus->dev, PCI_CFG_VID, &vid);
  2067. saved_vid = bus->dev->saved_config_space[PCI_CFG_VID];
  2068. if (vid != saved_vid) {
  2069. DHD_ERROR(("%s: VID(0x%x) is different from saved VID(0x%x) "
  2070. "Skip the bus init\n", __FUNCTION__, vid, saved_vid));
  2071. bus->no_bus_init = TRUE;
  2072. /* Check if the PCIe link is down */
  2073. if (vid == (uint32)-1) {
  2074. bus->is_linkdown = 1;
  2075. #ifdef SUPPORT_LINKDOWN_RECOVERY
  2076. #ifdef CONFIG_ARCH_MSM
  2077. bus->no_cfg_restore = TRUE;
  2078. #endif /* CONFIG_ARCH_MSM */
  2079. #endif /* SUPPORT_LINKDOWN_RECOVERY */
  2080. }
  2081. return BCME_ERROR;
  2082. }
  2083. }
  2084. pci_restore_state(bus->dev);
  2085. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 0)) */
  2086. ret = pci_enable_device(bus->dev);
  2087. if (ret) {
  2088. pci_disable_device(bus->dev);
  2089. } else {
  2090. pci_set_master(bus->dev);
  2091. }
  2092. return ret;
  2093. }
  2094. int
  2095. dhdpcie_alloc_resource(dhd_bus_t *bus)
  2096. {
  2097. dhdpcie_info_t *dhdpcie_info;
  2098. phys_addr_t bar0_addr, bar1_addr;
  2099. ulong bar1_size;
  2100. do {
  2101. if (bus == NULL) {
  2102. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2103. break;
  2104. }
  2105. if (bus->dev == NULL) {
  2106. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2107. break;
  2108. }
  2109. dhdpcie_info = pci_get_drvdata(bus->dev);
  2110. if (dhdpcie_info == NULL) {
  2111. DHD_ERROR(("%s: dhdpcie_info is NULL\n", __FUNCTION__));
  2112. break;
  2113. }
  2114. bar0_addr = pci_resource_start(bus->dev, 0); /* Bar-0 mapped address */
  2115. bar1_addr = pci_resource_start(bus->dev, 2); /* Bar-1 mapped address */
  2116. /* read Bar-1 mapped memory range */
  2117. bar1_size = pci_resource_len(bus->dev, 2);
  2118. if ((bar1_size == 0) || (bar1_addr == 0)) {
  2119. printf("%s: BAR1 Not enabled for this device size(%ld),"
  2120. " addr(0x"PRINTF_RESOURCE")\n",
  2121. __FUNCTION__, bar1_size, bar1_addr);
  2122. break;
  2123. }
  2124. dhdpcie_info->regs = (volatile char *) REG_MAP(bar0_addr, DONGLE_REG_MAP_SIZE);
  2125. if (!dhdpcie_info->regs) {
  2126. DHD_ERROR(("%s: ioremap() for regs is failed\n", __FUNCTION__));
  2127. break;
  2128. }
  2129. bus->regs = dhdpcie_info->regs;
  2130. dhdpcie_info->bar1_size =
  2131. (bar1_size > DONGLE_TCM_MAP_SIZE) ? bar1_size : DONGLE_TCM_MAP_SIZE;
  2132. dhdpcie_info->tcm = (volatile char *) REG_MAP(bar1_addr, dhdpcie_info->bar1_size);
  2133. if (!dhdpcie_info->tcm) {
  2134. DHD_ERROR(("%s: ioremap() for regs is failed\n", __FUNCTION__));
  2135. REG_UNMAP(dhdpcie_info->regs);
  2136. bus->regs = NULL;
  2137. break;
  2138. }
  2139. bus->tcm = dhdpcie_info->tcm;
  2140. DHD_TRACE(("%s:Phys addr : reg space = %p base addr 0x"PRINTF_RESOURCE" \n",
  2141. __FUNCTION__, dhdpcie_info->regs, bar0_addr));
  2142. DHD_TRACE(("%s:Phys addr : tcm_space = %p base addr 0x"PRINTF_RESOURCE" \n",
  2143. __FUNCTION__, dhdpcie_info->tcm, bar1_addr));
  2144. return 0;
  2145. } while (0);
  2146. return BCME_ERROR;
  2147. }
  2148. void
  2149. dhdpcie_free_resource(dhd_bus_t *bus)
  2150. {
  2151. dhdpcie_info_t *dhdpcie_info;
  2152. if (bus == NULL) {
  2153. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2154. return;
  2155. }
  2156. if (bus->dev == NULL) {
  2157. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2158. return;
  2159. }
  2160. dhdpcie_info = pci_get_drvdata(bus->dev);
  2161. if (dhdpcie_info == NULL) {
  2162. DHD_ERROR(("%s: dhdpcie_info is NULL\n", __FUNCTION__));
  2163. return;
  2164. }
  2165. if (bus->regs) {
  2166. REG_UNMAP(dhdpcie_info->regs);
  2167. bus->regs = NULL;
  2168. }
  2169. if (bus->tcm) {
  2170. REG_UNMAP(dhdpcie_info->tcm);
  2171. bus->tcm = NULL;
  2172. }
  2173. }
  2174. int
  2175. dhdpcie_bus_request_irq(struct dhd_bus *bus)
  2176. {
  2177. dhdpcie_info_t *dhdpcie_info;
  2178. int ret = 0;
  2179. if (bus == NULL) {
  2180. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2181. return BCME_ERROR;
  2182. }
  2183. if (bus->dev == NULL) {
  2184. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2185. return BCME_ERROR;
  2186. }
  2187. dhdpcie_info = pci_get_drvdata(bus->dev);
  2188. if (dhdpcie_info == NULL) {
  2189. DHD_ERROR(("%s: dhdpcie_info is NULL\n", __FUNCTION__));
  2190. return BCME_ERROR;
  2191. }
  2192. if (bus->intr) {
  2193. /* Register interrupt callback, but mask it (not operational yet). */
  2194. DHD_INTR(("%s: Registering and masking interrupts\n", __FUNCTION__));
  2195. dhdpcie_bus_intr_disable(bus);
  2196. ret = dhdpcie_request_irq(dhdpcie_info);
  2197. if (ret) {
  2198. DHD_ERROR(("%s: request_irq() failed, ret=%d\n",
  2199. __FUNCTION__, ret));
  2200. return ret;
  2201. }
  2202. }
  2203. return ret;
  2204. }
  2205. #ifdef BCMPCIE_OOB_HOST_WAKE
  2206. #ifdef CONFIG_BCMDHD_GET_OOB_STATE
  2207. extern int dhd_get_wlan_oob_gpio(void);
  2208. #endif /* CONFIG_BCMDHD_GET_OOB_STATE */
  2209. int dhdpcie_get_oob_irq_level(void)
  2210. {
  2211. int gpio_level;
  2212. #ifdef CONFIG_BCMDHD_GET_OOB_STATE
  2213. gpio_level = dhd_get_wlan_oob_gpio();
  2214. #else
  2215. gpio_level = BCME_UNSUPPORTED;
  2216. #endif /* CONFIG_BCMDHD_GET_OOB_STATE */
  2217. return gpio_level;
  2218. }
  2219. int dhdpcie_get_oob_irq_status(struct dhd_bus *bus)
  2220. {
  2221. dhdpcie_info_t *pch;
  2222. dhdpcie_os_info_t *dhdpcie_osinfo;
  2223. if (bus == NULL) {
  2224. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2225. return 0;
  2226. }
  2227. if (bus->dev == NULL) {
  2228. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2229. return 0;
  2230. }
  2231. pch = pci_get_drvdata(bus->dev);
  2232. if (pch == NULL) {
  2233. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  2234. return 0;
  2235. }
  2236. dhdpcie_osinfo = (dhdpcie_os_info_t *)pch->os_cxt;
  2237. return dhdpcie_osinfo ? dhdpcie_osinfo->oob_irq_enabled : 0;
  2238. }
  2239. int dhdpcie_get_oob_irq_num(struct dhd_bus *bus)
  2240. {
  2241. dhdpcie_info_t *pch;
  2242. dhdpcie_os_info_t *dhdpcie_osinfo;
  2243. if (bus == NULL) {
  2244. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2245. return 0;
  2246. }
  2247. if (bus->dev == NULL) {
  2248. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2249. return 0;
  2250. }
  2251. pch = pci_get_drvdata(bus->dev);
  2252. if (pch == NULL) {
  2253. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  2254. return 0;
  2255. }
  2256. dhdpcie_osinfo = (dhdpcie_os_info_t *)pch->os_cxt;
  2257. return dhdpcie_osinfo ? dhdpcie_osinfo->oob_irq_num : 0;
  2258. }
  2259. void dhdpcie_oob_intr_set(dhd_bus_t *bus, bool enable)
  2260. {
  2261. unsigned long flags;
  2262. dhdpcie_info_t *pch;
  2263. dhdpcie_os_info_t *dhdpcie_osinfo;
  2264. if (bus == NULL) {
  2265. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2266. return;
  2267. }
  2268. if (bus->dev == NULL) {
  2269. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2270. return;
  2271. }
  2272. pch = pci_get_drvdata(bus->dev);
  2273. if (pch == NULL) {
  2274. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  2275. return;
  2276. }
  2277. dhdpcie_osinfo = (dhdpcie_os_info_t *)pch->os_cxt;
  2278. spin_lock_irqsave(&dhdpcie_osinfo->oob_irq_spinlock, flags);
  2279. if ((dhdpcie_osinfo->oob_irq_enabled != enable) &&
  2280. (dhdpcie_osinfo->oob_irq_num > 0)) {
  2281. if (enable) {
  2282. enable_irq(dhdpcie_osinfo->oob_irq_num);
  2283. bus->oob_intr_enable_count++;
  2284. bus->last_oob_irq_enable_time = OSL_LOCALTIME_NS();
  2285. } else {
  2286. disable_irq_nosync(dhdpcie_osinfo->oob_irq_num);
  2287. bus->oob_intr_disable_count++;
  2288. bus->last_oob_irq_disable_time = OSL_LOCALTIME_NS();
  2289. }
  2290. dhdpcie_osinfo->oob_irq_enabled = enable;
  2291. }
  2292. spin_unlock_irqrestore(&dhdpcie_osinfo->oob_irq_spinlock, flags);
  2293. }
  2294. static irqreturn_t wlan_oob_irq(int irq, void *data)
  2295. {
  2296. dhd_bus_t *bus;
  2297. unsigned long flags_bus;
  2298. DHD_TRACE(("%s: IRQ Triggered\n", __FUNCTION__));
  2299. bus = (dhd_bus_t *)data;
  2300. dhdpcie_oob_intr_set(bus, FALSE);
  2301. bus->last_oob_irq_time = OSL_LOCALTIME_NS();
  2302. bus->oob_intr_count++;
  2303. #ifdef DHD_WAKE_STATUS
  2304. #ifdef DHD_PCIE_RUNTIMEPM
  2305. /* This condition is for avoiding counting of wake up from Runtime PM */
  2306. if (bus->chk_pm)
  2307. #endif /* DHD_PCIE_RUNTIMPM */
  2308. {
  2309. bcmpcie_set_get_wake(bus, 1);
  2310. }
  2311. #endif /* DHD_WAKE_STATUS */
  2312. #ifdef DHD_PCIE_RUNTIMEPM
  2313. dhdpcie_runtime_bus_wake(bus->dhd, FALSE, wlan_oob_irq);
  2314. #endif /* DHD_PCIE_RUNTIMPM */
  2315. #ifdef DHD_PCIE_NATIVE_RUNTIMEPM
  2316. dhd_bus_wakeup_work(bus->dhd);
  2317. #endif /* DHD_PCIE_NATIVE_RUNTIMEPM */
  2318. DHD_BUS_LOCK(bus->bus_lock, flags_bus);
  2319. /* Hold wakelock if bus_low_power_state is
  2320. * DHD_BUS_D3_INFORM_SENT OR DHD_BUS_D3_ACK_RECIEVED
  2321. */
  2322. if (bus->dhd->up && bus->bus_low_power_state != DHD_BUS_NO_LOW_POWER_STATE) {
  2323. DHD_OS_OOB_IRQ_WAKE_LOCK_TIMEOUT(bus->dhd, OOB_WAKE_LOCK_TIMEOUT);
  2324. }
  2325. DHD_BUS_UNLOCK(bus->bus_lock, flags_bus);
  2326. return IRQ_HANDLED;
  2327. }
  2328. int dhdpcie_oob_intr_register(dhd_bus_t *bus)
  2329. {
  2330. int err = 0;
  2331. dhdpcie_info_t *pch;
  2332. dhdpcie_os_info_t *dhdpcie_osinfo;
  2333. DHD_TRACE(("%s: Enter\n", __FUNCTION__));
  2334. if (bus == NULL) {
  2335. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2336. return -EINVAL;
  2337. }
  2338. if (bus->dev == NULL) {
  2339. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2340. return -EINVAL;
  2341. }
  2342. pch = pci_get_drvdata(bus->dev);
  2343. if (pch == NULL) {
  2344. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  2345. return -EINVAL;
  2346. }
  2347. dhdpcie_osinfo = (dhdpcie_os_info_t *)pch->os_cxt;
  2348. if (dhdpcie_osinfo->oob_irq_registered) {
  2349. DHD_ERROR(("%s: irq is already registered\n", __FUNCTION__));
  2350. return -EBUSY;
  2351. }
  2352. if (dhdpcie_osinfo->oob_irq_num > 0) {
  2353. DHD_INFO_HW4(("%s OOB irq=%d flags=%X \n", __FUNCTION__,
  2354. (int)dhdpcie_osinfo->oob_irq_num,
  2355. (int)dhdpcie_osinfo->oob_irq_flags));
  2356. err = request_irq(dhdpcie_osinfo->oob_irq_num, wlan_oob_irq,
  2357. dhdpcie_osinfo->oob_irq_flags, "dhdpcie_host_wake",
  2358. bus);
  2359. if (err) {
  2360. DHD_ERROR(("%s: request_irq failed with %d\n",
  2361. __FUNCTION__, err));
  2362. return err;
  2363. }
  2364. err = enable_irq_wake(dhdpcie_osinfo->oob_irq_num);
  2365. if (!err) {
  2366. dhdpcie_osinfo->oob_irq_wake_enabled = TRUE;
  2367. } else {
  2368. /* On Hikey platform enable_irq_wake() is failing with error
  2369. * ENXIO (No such device or address). This is because the callback function
  2370. * irq_set_wake() is not registered in kernel, hence returning BCME_OK.
  2371. */
  2372. #ifdef BOARD_HIKEY
  2373. DHD_ERROR(("%s: continue eventhough enable_irq_wake failed: %d\n",
  2374. __FUNCTION__, err));
  2375. err = BCME_OK;
  2376. #endif /* BOARD_HIKEY */
  2377. }
  2378. dhdpcie_osinfo->oob_irq_enabled = TRUE;
  2379. }
  2380. dhdpcie_osinfo->oob_irq_registered = TRUE;
  2381. return err;
  2382. }
  2383. void dhdpcie_oob_intr_unregister(dhd_bus_t *bus)
  2384. {
  2385. int err = 0;
  2386. dhdpcie_info_t *pch;
  2387. dhdpcie_os_info_t *dhdpcie_osinfo;
  2388. DHD_TRACE(("%s: Enter\n", __FUNCTION__));
  2389. if (bus == NULL) {
  2390. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2391. return;
  2392. }
  2393. if (bus->dev == NULL) {
  2394. DHD_ERROR(("%s: bus->dev is NULL\n", __FUNCTION__));
  2395. return;
  2396. }
  2397. pch = pci_get_drvdata(bus->dev);
  2398. if (pch == NULL) {
  2399. DHD_ERROR(("%s: pch is NULL\n", __FUNCTION__));
  2400. return;
  2401. }
  2402. dhdpcie_osinfo = (dhdpcie_os_info_t *)pch->os_cxt;
  2403. if (!dhdpcie_osinfo->oob_irq_registered) {
  2404. DHD_ERROR(("%s: irq is not registered\n", __FUNCTION__));
  2405. return;
  2406. }
  2407. if (dhdpcie_osinfo->oob_irq_num > 0) {
  2408. if (dhdpcie_osinfo->oob_irq_wake_enabled) {
  2409. err = disable_irq_wake(dhdpcie_osinfo->oob_irq_num);
  2410. if (!err) {
  2411. dhdpcie_osinfo->oob_irq_wake_enabled = FALSE;
  2412. }
  2413. }
  2414. if (dhdpcie_osinfo->oob_irq_enabled) {
  2415. disable_irq(dhdpcie_osinfo->oob_irq_num);
  2416. dhdpcie_osinfo->oob_irq_enabled = FALSE;
  2417. }
  2418. free_irq(dhdpcie_osinfo->oob_irq_num, bus);
  2419. }
  2420. dhdpcie_osinfo->oob_irq_registered = FALSE;
  2421. }
  2422. #endif /* BCMPCIE_OOB_HOST_WAKE */
  2423. #ifdef DHD_PCIE_RUNTIMEPM
  2424. bool dhd_runtimepm_state(dhd_pub_t *dhd)
  2425. {
  2426. dhd_bus_t *bus;
  2427. unsigned long flags;
  2428. bus = dhd->bus;
  2429. DHD_GENERAL_LOCK(dhd, flags);
  2430. bus->idlecount++;
  2431. DHD_TRACE(("%s : Enter \n", __FUNCTION__));
  2432. if ((bus->idletime > 0) && (bus->idlecount >= bus->idletime)) {
  2433. bus->idlecount = 0;
  2434. if (DHD_BUS_BUSY_CHECK_IDLE(dhd) && !DHD_BUS_CHECK_DOWN_OR_DOWN_IN_PROGRESS(dhd)) {
  2435. bus->bus_wake = 0;
  2436. DHD_BUS_BUSY_SET_RPM_SUSPEND_IN_PROGRESS(dhd);
  2437. bus->runtime_resume_done = FALSE;
  2438. /* stop all interface network queue. */
  2439. dhd_bus_stop_queue(bus);
  2440. DHD_GENERAL_UNLOCK(dhd, flags);
  2441. DHD_ERROR(("%s: DHD Idle state!! - idletime :%d, wdtick :%d \n",
  2442. __FUNCTION__, bus->idletime, dhd_runtimepm_ms));
  2443. /* RPM suspend is failed, return FALSE then re-trying */
  2444. if (dhdpcie_set_suspend_resume(bus, TRUE)) {
  2445. DHD_ERROR(("%s: exit with wakelock \n", __FUNCTION__));
  2446. DHD_GENERAL_LOCK(dhd, flags);
  2447. DHD_BUS_BUSY_CLEAR_RPM_SUSPEND_IN_PROGRESS(dhd);
  2448. dhd_os_busbusy_wake(bus->dhd);
  2449. bus->runtime_resume_done = TRUE;
  2450. /* It can make stuck NET TX Queue without below */
  2451. dhd_bus_start_queue(bus);
  2452. DHD_GENERAL_UNLOCK(dhd, flags);
  2453. smp_wmb();
  2454. wake_up_interruptible(&bus->rpm_queue);
  2455. return FALSE;
  2456. }
  2457. DHD_GENERAL_LOCK(dhd, flags);
  2458. DHD_BUS_BUSY_CLEAR_RPM_SUSPEND_IN_PROGRESS(dhd);
  2459. DHD_BUS_BUSY_SET_RPM_SUSPEND_DONE(dhd);
  2460. /* For making sure NET TX Queue active */
  2461. dhd_bus_start_queue(bus);
  2462. DHD_GENERAL_UNLOCK(dhd, flags);
  2463. wait_event_interruptible(bus->rpm_queue, bus->bus_wake);
  2464. DHD_GENERAL_LOCK(dhd, flags);
  2465. DHD_BUS_BUSY_CLEAR_RPM_SUSPEND_DONE(dhd);
  2466. DHD_BUS_BUSY_SET_RPM_RESUME_IN_PROGRESS(dhd);
  2467. DHD_GENERAL_UNLOCK(dhd, flags);
  2468. dhdpcie_set_suspend_resume(bus, FALSE);
  2469. DHD_GENERAL_LOCK(dhd, flags);
  2470. DHD_BUS_BUSY_CLEAR_RPM_RESUME_IN_PROGRESS(dhd);
  2471. dhd_os_busbusy_wake(bus->dhd);
  2472. /* Inform the wake up context that Resume is over */
  2473. bus->runtime_resume_done = TRUE;
  2474. /* For making sure NET TX Queue active */
  2475. dhd_bus_start_queue(bus);
  2476. DHD_GENERAL_UNLOCK(dhd, flags);
  2477. smp_wmb();
  2478. wake_up_interruptible(&bus->rpm_queue);
  2479. DHD_ERROR(("%s : runtime resume ended \n", __FUNCTION__));
  2480. return TRUE;
  2481. } else {
  2482. DHD_GENERAL_UNLOCK(dhd, flags);
  2483. /* Since one of the contexts are busy (TX, IOVAR or RX)
  2484. * we should not suspend
  2485. */
  2486. DHD_ERROR(("%s : bus is active with dhd_bus_busy_state = 0x%x\n",
  2487. __FUNCTION__, dhd->dhd_bus_busy_state));
  2488. return FALSE;
  2489. }
  2490. }
  2491. DHD_GENERAL_UNLOCK(dhd, flags);
  2492. return FALSE;
  2493. } /* dhd_runtimepm_state */
  2494. /*
  2495. * dhd_runtime_bus_wake
  2496. * TRUE - related with runtime pm context
  2497. * FALSE - It isn't invloved in runtime pm context
  2498. */
  2499. bool dhd_runtime_bus_wake(dhd_bus_t *bus, bool wait, void *func_addr)
  2500. {
  2501. unsigned long flags;
  2502. bus->idlecount = 0;
  2503. DHD_TRACE(("%s : enter\n", __FUNCTION__));
  2504. if (bus->dhd->up == FALSE) {
  2505. DHD_INFO(("%s : dhd is not up\n", __FUNCTION__));
  2506. return FALSE;
  2507. }
  2508. DHD_GENERAL_LOCK(bus->dhd, flags);
  2509. if (DHD_BUS_BUSY_CHECK_RPM_ALL(bus->dhd)) {
  2510. /* Wake up RPM state thread if it is suspend in progress or suspended */
  2511. if (DHD_BUS_BUSY_CHECK_RPM_SUSPEND_IN_PROGRESS(bus->dhd) ||
  2512. DHD_BUS_BUSY_CHECK_RPM_SUSPEND_DONE(bus->dhd)) {
  2513. bus->bus_wake = 1;
  2514. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  2515. DHD_ERROR(("Runtime Resume is called in %pf\n", func_addr));
  2516. smp_wmb();
  2517. wake_up_interruptible(&bus->rpm_queue);
  2518. /* No need to wake up the RPM state thread */
  2519. } else if (DHD_BUS_BUSY_CHECK_RPM_RESUME_IN_PROGRESS(bus->dhd)) {
  2520. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  2521. }
  2522. /* If wait is TRUE, function with wait = TRUE will be wait in here */
  2523. if (wait) {
  2524. wait_event_interruptible(bus->rpm_queue, bus->runtime_resume_done);
  2525. } else {
  2526. DHD_INFO(("%s: bus wakeup but no wait until resume done\n", __FUNCTION__));
  2527. }
  2528. /* If it is called from RPM context, it returns TRUE */
  2529. return TRUE;
  2530. }
  2531. DHD_GENERAL_UNLOCK(bus->dhd, flags);
  2532. return FALSE;
  2533. }
  2534. bool dhdpcie_runtime_bus_wake(dhd_pub_t *dhdp, bool wait, void* func_addr)
  2535. {
  2536. dhd_bus_t *bus = dhdp->bus;
  2537. return dhd_runtime_bus_wake(bus, wait, func_addr);
  2538. }
  2539. void dhdpcie_block_runtime_pm(dhd_pub_t *dhdp)
  2540. {
  2541. dhd_bus_t *bus = dhdp->bus;
  2542. bus->idletime = 0;
  2543. }
  2544. bool dhdpcie_is_resume_done(dhd_pub_t *dhdp)
  2545. {
  2546. dhd_bus_t *bus = dhdp->bus;
  2547. return bus->runtime_resume_done;
  2548. }
  2549. #endif /* DHD_PCIE_RUNTIMEPM */
  2550. struct device * dhd_bus_to_dev(dhd_bus_t *bus)
  2551. {
  2552. struct pci_dev *pdev;
  2553. pdev = bus->dev;
  2554. if (pdev)
  2555. return &pdev->dev;
  2556. else
  2557. return NULL;
  2558. }
  2559. #define KIRQ_PRINT_BUF_LEN 256
  2560. void
  2561. dhd_print_kirqstats(dhd_pub_t *dhd, unsigned int irq_num)
  2562. {
  2563. unsigned long flags = 0;
  2564. struct irq_desc *desc;
  2565. int i; /* cpu iterator */
  2566. struct bcmstrbuf strbuf;
  2567. char tmp_buf[KIRQ_PRINT_BUF_LEN];
  2568. desc = irq_to_desc(irq_num);
  2569. if (!desc) {
  2570. DHD_ERROR(("%s : irqdesc is not found \n", __FUNCTION__));
  2571. return;
  2572. }
  2573. bcm_binit(&strbuf, tmp_buf, KIRQ_PRINT_BUF_LEN);
  2574. raw_spin_lock_irqsave(&desc->lock, flags);
  2575. bcm_bprintf(&strbuf, "dhd irq %u:", irq_num);
  2576. for_each_online_cpu(i)
  2577. bcm_bprintf(&strbuf, "%10u ",
  2578. desc->kstat_irqs ? *per_cpu_ptr(desc->kstat_irqs, i) : 0);
  2579. if (desc->irq_data.chip) {
  2580. if (desc->irq_data.chip->name)
  2581. bcm_bprintf(&strbuf, " %8s", desc->irq_data.chip->name);
  2582. else
  2583. bcm_bprintf(&strbuf, " %8s", "-");
  2584. } else {
  2585. bcm_bprintf(&strbuf, " %8s", "None");
  2586. }
  2587. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
  2588. if (desc->irq_data.domain)
  2589. bcm_bprintf(&strbuf, " %d", (int)desc->irq_data.hwirq);
  2590. #ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
  2591. bcm_bprintf(&strbuf, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge");
  2592. #endif // endif
  2593. #endif /* LINUX VERSION > 3.1.0 */
  2594. if (desc->name)
  2595. bcm_bprintf(&strbuf, "-%-8s", desc->name);
  2596. DHD_ERROR(("%s\n", strbuf.origbuf));
  2597. raw_spin_unlock_irqrestore(&desc->lock, flags);
  2598. }
  2599. void
  2600. dhd_show_kirqstats(dhd_pub_t *dhd)
  2601. {
  2602. unsigned int irq = -1;
  2603. #ifdef BCMPCIE
  2604. dhdpcie_get_pcieirq(dhd->bus, &irq);
  2605. #endif /* BCMPCIE */
  2606. #ifdef BCMSDIO
  2607. irq = ((wifi_adapter_info_t *)dhd->info->adapter)->irq_num;
  2608. #endif /* BCMSDIO */
  2609. if (irq != -1) {
  2610. #ifdef BCMPCIE
  2611. DHD_ERROR(("DUMP data kernel irq stats : \n"));
  2612. #endif /* BCMPCIE */
  2613. #ifdef BCMSDIO
  2614. DHD_ERROR(("DUMP data/host wakeup kernel irq stats : \n"));
  2615. #endif /* BCMSDIO */
  2616. dhd_print_kirqstats(dhd, irq);
  2617. }
  2618. #ifdef BCMPCIE_OOB_HOST_WAKE
  2619. irq = dhdpcie_get_oob_irq_num(dhd->bus);
  2620. if (irq) {
  2621. DHD_ERROR(("DUMP PCIE host wakeup kernel irq stats : \n"));
  2622. dhd_print_kirqstats(dhd, irq);
  2623. }
  2624. #endif /* BCMPCIE_OOB_HOST_WAKE */
  2625. }
  2626. #ifdef DHD_FW_COREDUMP
  2627. #ifdef BCMDHDX
  2628. int
  2629. dhdx_dongle_mem_dump()
  2630. {
  2631. if (!g_dhd_bus) {
  2632. DHD_ERROR(("%s: Bus is NULL\n", __FUNCTION__));
  2633. return -ENODEV;
  2634. }
  2635. dhd_bus_dump_console_buffer(g_dhd_bus);
  2636. dhd_prot_debug_info_print(g_dhd_bus->dhd);
  2637. g_dhd_bus->dhd->memdump_enabled = DUMP_MEMFILE_BUGON;
  2638. g_dhd_bus->dhd->memdump_type = DUMP_TYPE_AP_ABNORMAL_ACCESS;
  2639. #ifdef DHD_PCIE_RUNTIMEPM
  2640. dhdpcie_runtime_bus_wake(g_dhd_bus->dhd, TRUE, __builtin_return_address(0));
  2641. #endif /* DHD_PCIE_RUNTIMEPM */
  2642. dhd_bus_mem_dump(g_dhd_bus->dhd);
  2643. return 0;
  2644. }
  2645. EXPORT_SYMBOL(dhdx_dongle_mem_dump);
  2646. #else
  2647. int
  2648. dhd_dongle_mem_dump(void)
  2649. {
  2650. if (!g_dhd_bus) {
  2651. DHD_ERROR(("%s: Bus is NULL\n", __FUNCTION__));
  2652. return -ENODEV;
  2653. }
  2654. dhd_bus_dump_console_buffer(g_dhd_bus);
  2655. dhd_prot_debug_info_print(g_dhd_bus->dhd);
  2656. g_dhd_bus->dhd->memdump_enabled = DUMP_MEMFILE_BUGON;
  2657. g_dhd_bus->dhd->memdump_type = DUMP_TYPE_AP_ABNORMAL_ACCESS;
  2658. #ifdef DHD_PCIE_RUNTIMEPM
  2659. dhdpcie_runtime_bus_wake(g_dhd_bus->dhd, TRUE, __builtin_return_address(0));
  2660. #endif /* DHD_PCIE_RUNTIMEPM */
  2661. dhd_bus_mem_dump(g_dhd_bus->dhd);
  2662. return 0;
  2663. }
  2664. EXPORT_SYMBOL(dhd_dongle_mem_dump);
  2665. #endif /* BCMDHDX */
  2666. #endif /* DHD_FW_COREDUMP */
  2667. #ifdef BCMDHDX
  2668. bool
  2669. dhdx_bus_check_driver_up(void)
  2670. {
  2671. dhd_bus_t *bus;
  2672. dhd_pub_t *dhdp;
  2673. bool isup = FALSE;
  2674. bus = (dhd_bus_t *)g_dhd_bus;
  2675. if (!bus) {
  2676. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2677. return isup;
  2678. }
  2679. dhdp = bus->dhd;
  2680. if (dhdp) {
  2681. isup = dhdp->up;
  2682. }
  2683. return isup;
  2684. }
  2685. EXPORT_SYMBOL(dhdx_bus_check_driver_up);
  2686. #else
  2687. bool
  2688. dhd_bus_check_driver_up(void)
  2689. {
  2690. dhd_bus_t *bus;
  2691. dhd_pub_t *dhdp;
  2692. bool isup = FALSE;
  2693. bus = (dhd_bus_t *)g_dhd_bus;
  2694. if (!bus) {
  2695. DHD_ERROR(("%s: bus is NULL\n", __FUNCTION__));
  2696. return isup;
  2697. }
  2698. dhdp = bus->dhd;
  2699. if (dhdp) {
  2700. isup = dhdp->up;
  2701. }
  2702. return isup;
  2703. }
  2704. EXPORT_SYMBOL(dhd_bus_check_driver_up);
  2705. #endif /* BCMDHDX */