pcie.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073
  1. /* Copyright (c) 2014 Broadcom Corporation
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/firmware.h>
  18. #include <linux/pci.h>
  19. #include <linux/vmalloc.h>
  20. #include <linux/delay.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/bcma/bcma.h>
  23. #include <linux/sched.h>
  24. #include <asm/unaligned.h>
  25. #include <soc.h>
  26. #include <chipcommon.h>
  27. #include <brcmu_utils.h>
  28. #include <brcmu_wifi.h>
  29. #include <brcm_hw_ids.h>
  30. #include "debug.h"
  31. #include "bus.h"
  32. #include "commonring.h"
  33. #include "msgbuf.h"
  34. #include "pcie.h"
  35. #include "firmware.h"
  36. #include "chip.h"
  37. #include "core.h"
  38. #include "common.h"
  39. enum brcmf_pcie_state {
  40. BRCMFMAC_PCIE_STATE_DOWN,
  41. BRCMFMAC_PCIE_STATE_UP
  42. };
  43. BRCMF_FW_DEF(43602, "brcmfmac43602-pcie");
  44. BRCMF_FW_DEF(4350, "brcmfmac4350-pcie");
  45. BRCMF_FW_DEF(4350C, "brcmfmac4350c2-pcie");
  46. BRCMF_FW_DEF(4356, "brcmfmac4356-pcie");
  47. BRCMF_FW_DEF(43570, "brcmfmac43570-pcie");
  48. BRCMF_FW_DEF(4358, "brcmfmac4358-pcie");
  49. BRCMF_FW_DEF(4359, "brcmfmac4359-pcie");
  50. BRCMF_FW_DEF(4365B, "brcmfmac4365b-pcie");
  51. BRCMF_FW_DEF(4365C, "brcmfmac4365c-pcie");
  52. BRCMF_FW_DEF(4366B, "brcmfmac4366b-pcie");
  53. BRCMF_FW_DEF(4366C, "brcmfmac4366c-pcie");
  54. BRCMF_FW_DEF(4371, "brcmfmac4371-pcie");
  55. static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = {
  56. BRCMF_FW_ENTRY(BRCM_CC_43602_CHIP_ID, 0xFFFFFFFF, 43602),
  57. BRCMF_FW_ENTRY(BRCM_CC_43465_CHIP_ID, 0xFFFFFFF0, 4366C),
  58. BRCMF_FW_ENTRY(BRCM_CC_4350_CHIP_ID, 0x000000FF, 4350C),
  59. BRCMF_FW_ENTRY(BRCM_CC_4350_CHIP_ID, 0xFFFFFF00, 4350),
  60. BRCMF_FW_ENTRY(BRCM_CC_43525_CHIP_ID, 0xFFFFFFF0, 4365C),
  61. BRCMF_FW_ENTRY(BRCM_CC_4356_CHIP_ID, 0xFFFFFFFF, 4356),
  62. BRCMF_FW_ENTRY(BRCM_CC_43567_CHIP_ID, 0xFFFFFFFF, 43570),
  63. BRCMF_FW_ENTRY(BRCM_CC_43569_CHIP_ID, 0xFFFFFFFF, 43570),
  64. BRCMF_FW_ENTRY(BRCM_CC_43570_CHIP_ID, 0xFFFFFFFF, 43570),
  65. BRCMF_FW_ENTRY(BRCM_CC_4358_CHIP_ID, 0xFFFFFFFF, 4358),
  66. BRCMF_FW_ENTRY(BRCM_CC_4359_CHIP_ID, 0xFFFFFFFF, 4359),
  67. BRCMF_FW_ENTRY(BRCM_CC_4365_CHIP_ID, 0x0000000F, 4365B),
  68. BRCMF_FW_ENTRY(BRCM_CC_4365_CHIP_ID, 0xFFFFFFF0, 4365C),
  69. BRCMF_FW_ENTRY(BRCM_CC_4366_CHIP_ID, 0x0000000F, 4366B),
  70. BRCMF_FW_ENTRY(BRCM_CC_4366_CHIP_ID, 0xFFFFFFF0, 4366C),
  71. BRCMF_FW_ENTRY(BRCM_CC_43664_CHIP_ID, 0xFFFFFFF0, 4366C),
  72. BRCMF_FW_ENTRY(BRCM_CC_4371_CHIP_ID, 0xFFFFFFFF, 4371),
  73. };
  74. #define BRCMF_PCIE_FW_UP_TIMEOUT 2000 /* msec */
  75. #define BRCMF_PCIE_REG_MAP_SIZE (32 * 1024)
  76. /* backplane addres space accessed by BAR0 */
  77. #define BRCMF_PCIE_BAR0_WINDOW 0x80
  78. #define BRCMF_PCIE_BAR0_REG_SIZE 0x1000
  79. #define BRCMF_PCIE_BAR0_WRAPPERBASE 0x70
  80. #define BRCMF_PCIE_BAR0_WRAPBASE_DMP_OFFSET 0x1000
  81. #define BRCMF_PCIE_BARO_PCIE_ENUM_OFFSET 0x2000
  82. #define BRCMF_PCIE_ARMCR4REG_BANKIDX 0x40
  83. #define BRCMF_PCIE_ARMCR4REG_BANKPDA 0x4C
  84. #define BRCMF_PCIE_REG_INTSTATUS 0x90
  85. #define BRCMF_PCIE_REG_INTMASK 0x94
  86. #define BRCMF_PCIE_REG_SBMBX 0x98
  87. #define BRCMF_PCIE_REG_LINK_STATUS_CTRL 0xBC
  88. #define BRCMF_PCIE_PCIE2REG_INTMASK 0x24
  89. #define BRCMF_PCIE_PCIE2REG_MAILBOXINT 0x48
  90. #define BRCMF_PCIE_PCIE2REG_MAILBOXMASK 0x4C
  91. #define BRCMF_PCIE_PCIE2REG_CONFIGADDR 0x120
  92. #define BRCMF_PCIE_PCIE2REG_CONFIGDATA 0x124
  93. #define BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_0 0x140
  94. #define BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_1 0x144
  95. #define BRCMF_PCIE2_INTA 0x01
  96. #define BRCMF_PCIE2_INTB 0x02
  97. #define BRCMF_PCIE_INT_0 0x01
  98. #define BRCMF_PCIE_INT_1 0x02
  99. #define BRCMF_PCIE_INT_DEF (BRCMF_PCIE_INT_0 | \
  100. BRCMF_PCIE_INT_1)
  101. #define BRCMF_PCIE_MB_INT_FN0_0 0x0100
  102. #define BRCMF_PCIE_MB_INT_FN0_1 0x0200
  103. #define BRCMF_PCIE_MB_INT_D2H0_DB0 0x10000
  104. #define BRCMF_PCIE_MB_INT_D2H0_DB1 0x20000
  105. #define BRCMF_PCIE_MB_INT_D2H1_DB0 0x40000
  106. #define BRCMF_PCIE_MB_INT_D2H1_DB1 0x80000
  107. #define BRCMF_PCIE_MB_INT_D2H2_DB0 0x100000
  108. #define BRCMF_PCIE_MB_INT_D2H2_DB1 0x200000
  109. #define BRCMF_PCIE_MB_INT_D2H3_DB0 0x400000
  110. #define BRCMF_PCIE_MB_INT_D2H3_DB1 0x800000
  111. #define BRCMF_PCIE_MB_INT_D2H_DB (BRCMF_PCIE_MB_INT_D2H0_DB0 | \
  112. BRCMF_PCIE_MB_INT_D2H0_DB1 | \
  113. BRCMF_PCIE_MB_INT_D2H1_DB0 | \
  114. BRCMF_PCIE_MB_INT_D2H1_DB1 | \
  115. BRCMF_PCIE_MB_INT_D2H2_DB0 | \
  116. BRCMF_PCIE_MB_INT_D2H2_DB1 | \
  117. BRCMF_PCIE_MB_INT_D2H3_DB0 | \
  118. BRCMF_PCIE_MB_INT_D2H3_DB1)
  119. #define BRCMF_PCIE_SHARED_VERSION_7 7
  120. #define BRCMF_PCIE_MIN_SHARED_VERSION 5
  121. #define BRCMF_PCIE_MAX_SHARED_VERSION BRCMF_PCIE_SHARED_VERSION_7
  122. #define BRCMF_PCIE_SHARED_VERSION_MASK 0x00FF
  123. #define BRCMF_PCIE_SHARED_DMA_INDEX 0x10000
  124. #define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000
  125. #define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000
  126. #define BRCMF_PCIE_FLAGS_HTOD_SPLIT 0x4000
  127. #define BRCMF_PCIE_FLAGS_DTOH_SPLIT 0x8000
  128. #define BRCMF_SHARED_MAX_RXBUFPOST_OFFSET 34
  129. #define BRCMF_SHARED_RING_BASE_OFFSET 52
  130. #define BRCMF_SHARED_RX_DATAOFFSET_OFFSET 36
  131. #define BRCMF_SHARED_CONSOLE_ADDR_OFFSET 20
  132. #define BRCMF_SHARED_HTOD_MB_DATA_ADDR_OFFSET 40
  133. #define BRCMF_SHARED_DTOH_MB_DATA_ADDR_OFFSET 44
  134. #define BRCMF_SHARED_RING_INFO_ADDR_OFFSET 48
  135. #define BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET 52
  136. #define BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET 56
  137. #define BRCMF_SHARED_DMA_RINGUPD_LEN_OFFSET 64
  138. #define BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET 68
  139. #define BRCMF_RING_H2D_RING_COUNT_OFFSET 0
  140. #define BRCMF_RING_D2H_RING_COUNT_OFFSET 1
  141. #define BRCMF_RING_H2D_RING_MEM_OFFSET 4
  142. #define BRCMF_RING_H2D_RING_STATE_OFFSET 8
  143. #define BRCMF_RING_MEM_BASE_ADDR_OFFSET 8
  144. #define BRCMF_RING_MAX_ITEM_OFFSET 4
  145. #define BRCMF_RING_LEN_ITEMS_OFFSET 6
  146. #define BRCMF_RING_MEM_SZ 16
  147. #define BRCMF_RING_STATE_SZ 8
  148. #define BRCMF_DEF_MAX_RXBUFPOST 255
  149. #define BRCMF_CONSOLE_BUFADDR_OFFSET 8
  150. #define BRCMF_CONSOLE_BUFSIZE_OFFSET 12
  151. #define BRCMF_CONSOLE_WRITEIDX_OFFSET 16
  152. #define BRCMF_DMA_D2H_SCRATCH_BUF_LEN 8
  153. #define BRCMF_DMA_D2H_RINGUPD_BUF_LEN 1024
  154. #define BRCMF_D2H_DEV_D3_ACK 0x00000001
  155. #define BRCMF_D2H_DEV_DS_ENTER_REQ 0x00000002
  156. #define BRCMF_D2H_DEV_DS_EXIT_NOTE 0x00000004
  157. #define BRCMF_D2H_DEV_FWHALT 0x10000000
  158. #define BRCMF_H2D_HOST_D3_INFORM 0x00000001
  159. #define BRCMF_H2D_HOST_DS_ACK 0x00000002
  160. #define BRCMF_H2D_HOST_D0_INFORM_IN_USE 0x00000008
  161. #define BRCMF_H2D_HOST_D0_INFORM 0x00000010
  162. #define BRCMF_PCIE_MBDATA_TIMEOUT msecs_to_jiffies(2000)
  163. #define BRCMF_PCIE_CFGREG_STATUS_CMD 0x4
  164. #define BRCMF_PCIE_CFGREG_PM_CSR 0x4C
  165. #define BRCMF_PCIE_CFGREG_MSI_CAP 0x58
  166. #define BRCMF_PCIE_CFGREG_MSI_ADDR_L 0x5C
  167. #define BRCMF_PCIE_CFGREG_MSI_ADDR_H 0x60
  168. #define BRCMF_PCIE_CFGREG_MSI_DATA 0x64
  169. #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL 0xBC
  170. #define BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL2 0xDC
  171. #define BRCMF_PCIE_CFGREG_RBAR_CTRL 0x228
  172. #define BRCMF_PCIE_CFGREG_PML1_SUB_CTRL1 0x248
  173. #define BRCMF_PCIE_CFGREG_REG_BAR2_CONFIG 0x4E0
  174. #define BRCMF_PCIE_CFGREG_REG_BAR3_CONFIG 0x4F4
  175. #define BRCMF_PCIE_LINK_STATUS_CTRL_ASPM_ENAB 3
  176. /* Magic number at a magic location to find RAM size */
  177. #define BRCMF_RAMSIZE_MAGIC 0x534d4152 /* SMAR */
  178. #define BRCMF_RAMSIZE_OFFSET 0x6c
  179. struct brcmf_pcie_console {
  180. u32 base_addr;
  181. u32 buf_addr;
  182. u32 bufsize;
  183. u32 read_idx;
  184. u8 log_str[256];
  185. u8 log_idx;
  186. };
  187. struct brcmf_pcie_shared_info {
  188. u32 tcm_base_address;
  189. u32 flags;
  190. struct brcmf_pcie_ringbuf *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
  191. struct brcmf_pcie_ringbuf *flowrings;
  192. u16 max_rxbufpost;
  193. u16 max_flowrings;
  194. u16 max_submissionrings;
  195. u16 max_completionrings;
  196. u32 rx_dataoffset;
  197. u32 htod_mb_data_addr;
  198. u32 dtoh_mb_data_addr;
  199. u32 ring_info_addr;
  200. struct brcmf_pcie_console console;
  201. void *scratch;
  202. dma_addr_t scratch_dmahandle;
  203. void *ringupd;
  204. dma_addr_t ringupd_dmahandle;
  205. u8 version;
  206. };
  207. struct brcmf_pcie_core_info {
  208. u32 base;
  209. u32 wrapbase;
  210. };
  211. struct brcmf_pciedev_info {
  212. enum brcmf_pcie_state state;
  213. bool in_irq;
  214. struct pci_dev *pdev;
  215. char fw_name[BRCMF_FW_NAME_LEN];
  216. char nvram_name[BRCMF_FW_NAME_LEN];
  217. void __iomem *regs;
  218. void __iomem *tcm;
  219. u32 ram_base;
  220. u32 ram_size;
  221. struct brcmf_chip *ci;
  222. u32 coreid;
  223. struct brcmf_pcie_shared_info shared;
  224. wait_queue_head_t mbdata_resp_wait;
  225. bool mbdata_completed;
  226. bool irq_allocated;
  227. bool wowl_enabled;
  228. u8 dma_idx_sz;
  229. void *idxbuf;
  230. u32 idxbuf_sz;
  231. dma_addr_t idxbuf_dmahandle;
  232. u16 (*read_ptr)(struct brcmf_pciedev_info *devinfo, u32 mem_offset);
  233. void (*write_ptr)(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  234. u16 value);
  235. struct brcmf_mp_device *settings;
  236. };
  237. struct brcmf_pcie_ringbuf {
  238. struct brcmf_commonring commonring;
  239. dma_addr_t dma_handle;
  240. u32 w_idx_addr;
  241. u32 r_idx_addr;
  242. struct brcmf_pciedev_info *devinfo;
  243. u8 id;
  244. };
  245. /**
  246. * struct brcmf_pcie_dhi_ringinfo - dongle/host interface shared ring info
  247. *
  248. * @ringmem: dongle memory pointer to ring memory location
  249. * @h2d_w_idx_ptr: h2d ring write indices dongle memory pointers
  250. * @h2d_r_idx_ptr: h2d ring read indices dongle memory pointers
  251. * @d2h_w_idx_ptr: d2h ring write indices dongle memory pointers
  252. * @d2h_r_idx_ptr: d2h ring read indices dongle memory pointers
  253. * @h2d_w_idx_hostaddr: h2d ring write indices host memory pointers
  254. * @h2d_r_idx_hostaddr: h2d ring read indices host memory pointers
  255. * @d2h_w_idx_hostaddr: d2h ring write indices host memory pointers
  256. * @d2h_r_idx_hostaddr: d2h ring reaD indices host memory pointers
  257. * @max_flowrings: maximum number of tx flow rings supported.
  258. * @max_submissionrings: maximum number of submission rings(h2d) supported.
  259. * @max_completionrings: maximum number of completion rings(d2h) supported.
  260. */
  261. struct brcmf_pcie_dhi_ringinfo {
  262. __le32 ringmem;
  263. __le32 h2d_w_idx_ptr;
  264. __le32 h2d_r_idx_ptr;
  265. __le32 d2h_w_idx_ptr;
  266. __le32 d2h_r_idx_ptr;
  267. struct msgbuf_buf_addr h2d_w_idx_hostaddr;
  268. struct msgbuf_buf_addr h2d_r_idx_hostaddr;
  269. struct msgbuf_buf_addr d2h_w_idx_hostaddr;
  270. struct msgbuf_buf_addr d2h_r_idx_hostaddr;
  271. __le16 max_flowrings;
  272. __le16 max_submissionrings;
  273. __le16 max_completionrings;
  274. };
  275. static const u32 brcmf_ring_max_item[BRCMF_NROF_COMMON_MSGRINGS] = {
  276. BRCMF_H2D_MSGRING_CONTROL_SUBMIT_MAX_ITEM,
  277. BRCMF_H2D_MSGRING_RXPOST_SUBMIT_MAX_ITEM,
  278. BRCMF_D2H_MSGRING_CONTROL_COMPLETE_MAX_ITEM,
  279. BRCMF_D2H_MSGRING_TX_COMPLETE_MAX_ITEM,
  280. BRCMF_D2H_MSGRING_RX_COMPLETE_MAX_ITEM
  281. };
  282. static const u32 brcmf_ring_itemsize_pre_v7[BRCMF_NROF_COMMON_MSGRINGS] = {
  283. BRCMF_H2D_MSGRING_CONTROL_SUBMIT_ITEMSIZE,
  284. BRCMF_H2D_MSGRING_RXPOST_SUBMIT_ITEMSIZE,
  285. BRCMF_D2H_MSGRING_CONTROL_COMPLETE_ITEMSIZE,
  286. BRCMF_D2H_MSGRING_TX_COMPLETE_ITEMSIZE_PRE_V7,
  287. BRCMF_D2H_MSGRING_RX_COMPLETE_ITEMSIZE_PRE_V7
  288. };
  289. static const u32 brcmf_ring_itemsize[BRCMF_NROF_COMMON_MSGRINGS] = {
  290. BRCMF_H2D_MSGRING_CONTROL_SUBMIT_ITEMSIZE,
  291. BRCMF_H2D_MSGRING_RXPOST_SUBMIT_ITEMSIZE,
  292. BRCMF_D2H_MSGRING_CONTROL_COMPLETE_ITEMSIZE,
  293. BRCMF_D2H_MSGRING_TX_COMPLETE_ITEMSIZE,
  294. BRCMF_D2H_MSGRING_RX_COMPLETE_ITEMSIZE
  295. };
  296. static u32
  297. brcmf_pcie_read_reg32(struct brcmf_pciedev_info *devinfo, u32 reg_offset)
  298. {
  299. void __iomem *address = devinfo->regs + reg_offset;
  300. return (ioread32(address));
  301. }
  302. static void
  303. brcmf_pcie_write_reg32(struct brcmf_pciedev_info *devinfo, u32 reg_offset,
  304. u32 value)
  305. {
  306. void __iomem *address = devinfo->regs + reg_offset;
  307. iowrite32(value, address);
  308. }
  309. static u8
  310. brcmf_pcie_read_tcm8(struct brcmf_pciedev_info *devinfo, u32 mem_offset)
  311. {
  312. void __iomem *address = devinfo->tcm + mem_offset;
  313. return (ioread8(address));
  314. }
  315. static u16
  316. brcmf_pcie_read_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset)
  317. {
  318. void __iomem *address = devinfo->tcm + mem_offset;
  319. return (ioread16(address));
  320. }
  321. static void
  322. brcmf_pcie_write_tcm16(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  323. u16 value)
  324. {
  325. void __iomem *address = devinfo->tcm + mem_offset;
  326. iowrite16(value, address);
  327. }
  328. static u16
  329. brcmf_pcie_read_idx(struct brcmf_pciedev_info *devinfo, u32 mem_offset)
  330. {
  331. u16 *address = devinfo->idxbuf + mem_offset;
  332. return (*(address));
  333. }
  334. static void
  335. brcmf_pcie_write_idx(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  336. u16 value)
  337. {
  338. u16 *address = devinfo->idxbuf + mem_offset;
  339. *(address) = value;
  340. }
  341. static u32
  342. brcmf_pcie_read_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset)
  343. {
  344. void __iomem *address = devinfo->tcm + mem_offset;
  345. return (ioread32(address));
  346. }
  347. static void
  348. brcmf_pcie_write_tcm32(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  349. u32 value)
  350. {
  351. void __iomem *address = devinfo->tcm + mem_offset;
  352. iowrite32(value, address);
  353. }
  354. static u32
  355. brcmf_pcie_read_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset)
  356. {
  357. void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset;
  358. return (ioread32(addr));
  359. }
  360. static void
  361. brcmf_pcie_write_ram32(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  362. u32 value)
  363. {
  364. void __iomem *addr = devinfo->tcm + devinfo->ci->rambase + mem_offset;
  365. iowrite32(value, addr);
  366. }
  367. static void
  368. brcmf_pcie_copy_mem_todev(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  369. void *srcaddr, u32 len)
  370. {
  371. void __iomem *address = devinfo->tcm + mem_offset;
  372. __le32 *src32;
  373. __le16 *src16;
  374. u8 *src8;
  375. if (((ulong)address & 4) || ((ulong)srcaddr & 4) || (len & 4)) {
  376. if (((ulong)address & 2) || ((ulong)srcaddr & 2) || (len & 2)) {
  377. src8 = (u8 *)srcaddr;
  378. while (len) {
  379. iowrite8(*src8, address);
  380. address++;
  381. src8++;
  382. len--;
  383. }
  384. } else {
  385. len = len / 2;
  386. src16 = (__le16 *)srcaddr;
  387. while (len) {
  388. iowrite16(le16_to_cpu(*src16), address);
  389. address += 2;
  390. src16++;
  391. len--;
  392. }
  393. }
  394. } else {
  395. len = len / 4;
  396. src32 = (__le32 *)srcaddr;
  397. while (len) {
  398. iowrite32(le32_to_cpu(*src32), address);
  399. address += 4;
  400. src32++;
  401. len--;
  402. }
  403. }
  404. }
  405. static void
  406. brcmf_pcie_copy_dev_tomem(struct brcmf_pciedev_info *devinfo, u32 mem_offset,
  407. void *dstaddr, u32 len)
  408. {
  409. void __iomem *address = devinfo->tcm + mem_offset;
  410. __le32 *dst32;
  411. __le16 *dst16;
  412. u8 *dst8;
  413. if (((ulong)address & 4) || ((ulong)dstaddr & 4) || (len & 4)) {
  414. if (((ulong)address & 2) || ((ulong)dstaddr & 2) || (len & 2)) {
  415. dst8 = (u8 *)dstaddr;
  416. while (len) {
  417. *dst8 = ioread8(address);
  418. address++;
  419. dst8++;
  420. len--;
  421. }
  422. } else {
  423. len = len / 2;
  424. dst16 = (__le16 *)dstaddr;
  425. while (len) {
  426. *dst16 = cpu_to_le16(ioread16(address));
  427. address += 2;
  428. dst16++;
  429. len--;
  430. }
  431. }
  432. } else {
  433. len = len / 4;
  434. dst32 = (__le32 *)dstaddr;
  435. while (len) {
  436. *dst32 = cpu_to_le32(ioread32(address));
  437. address += 4;
  438. dst32++;
  439. len--;
  440. }
  441. }
  442. }
  443. #define WRITECC32(devinfo, reg, value) brcmf_pcie_write_reg32(devinfo, \
  444. CHIPCREGOFFS(reg), value)
  445. static void
  446. brcmf_pcie_select_core(struct brcmf_pciedev_info *devinfo, u16 coreid)
  447. {
  448. const struct pci_dev *pdev = devinfo->pdev;
  449. struct brcmf_core *core;
  450. u32 bar0_win;
  451. core = brcmf_chip_get_core(devinfo->ci, coreid);
  452. if (core) {
  453. bar0_win = core->base;
  454. pci_write_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW, bar0_win);
  455. if (pci_read_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW,
  456. &bar0_win) == 0) {
  457. if (bar0_win != core->base) {
  458. bar0_win = core->base;
  459. pci_write_config_dword(pdev,
  460. BRCMF_PCIE_BAR0_WINDOW,
  461. bar0_win);
  462. }
  463. }
  464. } else {
  465. brcmf_err("Unsupported core selected %x\n", coreid);
  466. }
  467. }
  468. static void brcmf_pcie_reset_device(struct brcmf_pciedev_info *devinfo)
  469. {
  470. struct brcmf_core *core;
  471. u16 cfg_offset[] = { BRCMF_PCIE_CFGREG_STATUS_CMD,
  472. BRCMF_PCIE_CFGREG_PM_CSR,
  473. BRCMF_PCIE_CFGREG_MSI_CAP,
  474. BRCMF_PCIE_CFGREG_MSI_ADDR_L,
  475. BRCMF_PCIE_CFGREG_MSI_ADDR_H,
  476. BRCMF_PCIE_CFGREG_MSI_DATA,
  477. BRCMF_PCIE_CFGREG_LINK_STATUS_CTRL2,
  478. BRCMF_PCIE_CFGREG_RBAR_CTRL,
  479. BRCMF_PCIE_CFGREG_PML1_SUB_CTRL1,
  480. BRCMF_PCIE_CFGREG_REG_BAR2_CONFIG,
  481. BRCMF_PCIE_CFGREG_REG_BAR3_CONFIG };
  482. u32 i;
  483. u32 val;
  484. u32 lsc;
  485. if (!devinfo->ci)
  486. return;
  487. /* Disable ASPM */
  488. brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
  489. pci_read_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL,
  490. &lsc);
  491. val = lsc & (~BRCMF_PCIE_LINK_STATUS_CTRL_ASPM_ENAB);
  492. pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL,
  493. val);
  494. /* Watchdog reset */
  495. brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON);
  496. WRITECC32(devinfo, watchdog, 4);
  497. msleep(100);
  498. /* Restore ASPM */
  499. brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
  500. pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_LINK_STATUS_CTRL,
  501. lsc);
  502. core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_PCIE2);
  503. if (core->rev <= 13) {
  504. for (i = 0; i < ARRAY_SIZE(cfg_offset); i++) {
  505. brcmf_pcie_write_reg32(devinfo,
  506. BRCMF_PCIE_PCIE2REG_CONFIGADDR,
  507. cfg_offset[i]);
  508. val = brcmf_pcie_read_reg32(devinfo,
  509. BRCMF_PCIE_PCIE2REG_CONFIGDATA);
  510. brcmf_dbg(PCIE, "config offset 0x%04x, value 0x%04x\n",
  511. cfg_offset[i], val);
  512. brcmf_pcie_write_reg32(devinfo,
  513. BRCMF_PCIE_PCIE2REG_CONFIGDATA,
  514. val);
  515. }
  516. }
  517. }
  518. static void brcmf_pcie_attach(struct brcmf_pciedev_info *devinfo)
  519. {
  520. u32 config;
  521. /* BAR1 window may not be sized properly */
  522. brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
  523. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_CONFIGADDR, 0x4e0);
  524. config = brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_CONFIGDATA);
  525. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_CONFIGDATA, config);
  526. device_wakeup_enable(&devinfo->pdev->dev);
  527. }
  528. static int brcmf_pcie_enter_download_state(struct brcmf_pciedev_info *devinfo)
  529. {
  530. if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) {
  531. brcmf_pcie_select_core(devinfo, BCMA_CORE_ARM_CR4);
  532. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX,
  533. 5);
  534. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKPDA,
  535. 0);
  536. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKIDX,
  537. 7);
  538. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_ARMCR4REG_BANKPDA,
  539. 0);
  540. }
  541. return 0;
  542. }
  543. static int brcmf_pcie_exit_download_state(struct brcmf_pciedev_info *devinfo,
  544. u32 resetintr)
  545. {
  546. struct brcmf_core *core;
  547. if (devinfo->ci->chip == BRCM_CC_43602_CHIP_ID) {
  548. core = brcmf_chip_get_core(devinfo->ci, BCMA_CORE_INTERNAL_MEM);
  549. brcmf_chip_resetcore(core, 0, 0, 0);
  550. }
  551. if (!brcmf_chip_set_active(devinfo->ci, resetintr))
  552. return -EINVAL;
  553. return 0;
  554. }
  555. static int
  556. brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data)
  557. {
  558. struct brcmf_pcie_shared_info *shared;
  559. u32 addr;
  560. u32 cur_htod_mb_data;
  561. u32 i;
  562. shared = &devinfo->shared;
  563. addr = shared->htod_mb_data_addr;
  564. cur_htod_mb_data = brcmf_pcie_read_tcm32(devinfo, addr);
  565. if (cur_htod_mb_data != 0)
  566. brcmf_dbg(PCIE, "MB transaction is already pending 0x%04x\n",
  567. cur_htod_mb_data);
  568. i = 0;
  569. while (cur_htod_mb_data != 0) {
  570. msleep(10);
  571. i++;
  572. if (i > 100)
  573. return -EIO;
  574. cur_htod_mb_data = brcmf_pcie_read_tcm32(devinfo, addr);
  575. }
  576. brcmf_pcie_write_tcm32(devinfo, addr, htod_mb_data);
  577. pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_SBMBX, 1);
  578. pci_write_config_dword(devinfo->pdev, BRCMF_PCIE_REG_SBMBX, 1);
  579. return 0;
  580. }
  581. static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo)
  582. {
  583. struct brcmf_pcie_shared_info *shared;
  584. u32 addr;
  585. u32 dtoh_mb_data;
  586. shared = &devinfo->shared;
  587. addr = shared->dtoh_mb_data_addr;
  588. dtoh_mb_data = brcmf_pcie_read_tcm32(devinfo, addr);
  589. if (!dtoh_mb_data)
  590. return;
  591. brcmf_pcie_write_tcm32(devinfo, addr, 0);
  592. brcmf_dbg(PCIE, "D2H_MB_DATA: 0x%04x\n", dtoh_mb_data);
  593. if (dtoh_mb_data & BRCMF_D2H_DEV_DS_ENTER_REQ) {
  594. brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP REQ\n");
  595. brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_DS_ACK);
  596. brcmf_dbg(PCIE, "D2H_MB_DATA: sent DEEP SLEEP ACK\n");
  597. }
  598. if (dtoh_mb_data & BRCMF_D2H_DEV_DS_EXIT_NOTE)
  599. brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP EXIT\n");
  600. if (dtoh_mb_data & BRCMF_D2H_DEV_D3_ACK) {
  601. brcmf_dbg(PCIE, "D2H_MB_DATA: D3 ACK\n");
  602. devinfo->mbdata_completed = true;
  603. wake_up(&devinfo->mbdata_resp_wait);
  604. }
  605. if (dtoh_mb_data & BRCMF_D2H_DEV_FWHALT) {
  606. brcmf_dbg(PCIE, "D2H_MB_DATA: FW HALT\n");
  607. brcmf_dev_coredump(&devinfo->pdev->dev);
  608. }
  609. }
  610. static void brcmf_pcie_bus_console_init(struct brcmf_pciedev_info *devinfo)
  611. {
  612. struct brcmf_pcie_shared_info *shared;
  613. struct brcmf_pcie_console *console;
  614. u32 addr;
  615. shared = &devinfo->shared;
  616. console = &shared->console;
  617. addr = shared->tcm_base_address + BRCMF_SHARED_CONSOLE_ADDR_OFFSET;
  618. console->base_addr = brcmf_pcie_read_tcm32(devinfo, addr);
  619. addr = console->base_addr + BRCMF_CONSOLE_BUFADDR_OFFSET;
  620. console->buf_addr = brcmf_pcie_read_tcm32(devinfo, addr);
  621. addr = console->base_addr + BRCMF_CONSOLE_BUFSIZE_OFFSET;
  622. console->bufsize = brcmf_pcie_read_tcm32(devinfo, addr);
  623. brcmf_dbg(FWCON, "Console: base %x, buf %x, size %d\n",
  624. console->base_addr, console->buf_addr, console->bufsize);
  625. }
  626. static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo)
  627. {
  628. struct brcmf_pcie_console *console;
  629. u32 addr;
  630. u8 ch;
  631. u32 newidx;
  632. if (!BRCMF_FWCON_ON())
  633. return;
  634. console = &devinfo->shared.console;
  635. addr = console->base_addr + BRCMF_CONSOLE_WRITEIDX_OFFSET;
  636. newidx = brcmf_pcie_read_tcm32(devinfo, addr);
  637. while (newidx != console->read_idx) {
  638. addr = console->buf_addr + console->read_idx;
  639. ch = brcmf_pcie_read_tcm8(devinfo, addr);
  640. console->read_idx++;
  641. if (console->read_idx == console->bufsize)
  642. console->read_idx = 0;
  643. if (ch == '\r')
  644. continue;
  645. console->log_str[console->log_idx] = ch;
  646. console->log_idx++;
  647. if ((ch != '\n') &&
  648. (console->log_idx == (sizeof(console->log_str) - 2))) {
  649. ch = '\n';
  650. console->log_str[console->log_idx] = ch;
  651. console->log_idx++;
  652. }
  653. if (ch == '\n') {
  654. console->log_str[console->log_idx] = 0;
  655. pr_debug("CONSOLE: %s", console->log_str);
  656. console->log_idx = 0;
  657. }
  658. }
  659. }
  660. static void brcmf_pcie_intr_disable(struct brcmf_pciedev_info *devinfo)
  661. {
  662. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXMASK, 0);
  663. }
  664. static void brcmf_pcie_intr_enable(struct brcmf_pciedev_info *devinfo)
  665. {
  666. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXMASK,
  667. BRCMF_PCIE_MB_INT_D2H_DB |
  668. BRCMF_PCIE_MB_INT_FN0_0 |
  669. BRCMF_PCIE_MB_INT_FN0_1);
  670. }
  671. static void brcmf_pcie_hostready(struct brcmf_pciedev_info *devinfo)
  672. {
  673. if (devinfo->shared.flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1)
  674. brcmf_pcie_write_reg32(devinfo,
  675. BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_1, 1);
  676. }
  677. static irqreturn_t brcmf_pcie_quick_check_isr(int irq, void *arg)
  678. {
  679. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)arg;
  680. if (brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT)) {
  681. brcmf_pcie_intr_disable(devinfo);
  682. brcmf_dbg(PCIE, "Enter\n");
  683. return IRQ_WAKE_THREAD;
  684. }
  685. return IRQ_NONE;
  686. }
  687. static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg)
  688. {
  689. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)arg;
  690. u32 status;
  691. devinfo->in_irq = true;
  692. status = brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT);
  693. brcmf_dbg(PCIE, "Enter %x\n", status);
  694. if (status) {
  695. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT,
  696. status);
  697. if (status & (BRCMF_PCIE_MB_INT_FN0_0 |
  698. BRCMF_PCIE_MB_INT_FN0_1))
  699. brcmf_pcie_handle_mb_data(devinfo);
  700. if (status & BRCMF_PCIE_MB_INT_D2H_DB) {
  701. if (devinfo->state == BRCMFMAC_PCIE_STATE_UP)
  702. brcmf_proto_msgbuf_rx_trigger(
  703. &devinfo->pdev->dev);
  704. }
  705. }
  706. brcmf_pcie_bus_console_read(devinfo);
  707. if (devinfo->state == BRCMFMAC_PCIE_STATE_UP)
  708. brcmf_pcie_intr_enable(devinfo);
  709. devinfo->in_irq = false;
  710. return IRQ_HANDLED;
  711. }
  712. static int brcmf_pcie_request_irq(struct brcmf_pciedev_info *devinfo)
  713. {
  714. struct pci_dev *pdev;
  715. pdev = devinfo->pdev;
  716. brcmf_pcie_intr_disable(devinfo);
  717. brcmf_dbg(PCIE, "Enter\n");
  718. pci_enable_msi(pdev);
  719. if (request_threaded_irq(pdev->irq, brcmf_pcie_quick_check_isr,
  720. brcmf_pcie_isr_thread, IRQF_SHARED,
  721. "brcmf_pcie_intr", devinfo)) {
  722. pci_disable_msi(pdev);
  723. brcmf_err("Failed to request IRQ %d\n", pdev->irq);
  724. return -EIO;
  725. }
  726. devinfo->irq_allocated = true;
  727. return 0;
  728. }
  729. static void brcmf_pcie_release_irq(struct brcmf_pciedev_info *devinfo)
  730. {
  731. struct pci_dev *pdev;
  732. u32 status;
  733. u32 count;
  734. if (!devinfo->irq_allocated)
  735. return;
  736. pdev = devinfo->pdev;
  737. brcmf_pcie_intr_disable(devinfo);
  738. free_irq(pdev->irq, devinfo);
  739. pci_disable_msi(pdev);
  740. msleep(50);
  741. count = 0;
  742. while ((devinfo->in_irq) && (count < 20)) {
  743. msleep(50);
  744. count++;
  745. }
  746. if (devinfo->in_irq)
  747. brcmf_err("Still in IRQ (processing) !!!\n");
  748. status = brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT);
  749. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT, status);
  750. devinfo->irq_allocated = false;
  751. }
  752. static int brcmf_pcie_ring_mb_write_rptr(void *ctx)
  753. {
  754. struct brcmf_pcie_ringbuf *ring = (struct brcmf_pcie_ringbuf *)ctx;
  755. struct brcmf_pciedev_info *devinfo = ring->devinfo;
  756. struct brcmf_commonring *commonring = &ring->commonring;
  757. if (devinfo->state != BRCMFMAC_PCIE_STATE_UP)
  758. return -EIO;
  759. brcmf_dbg(PCIE, "W r_ptr %d (%d), ring %d\n", commonring->r_ptr,
  760. commonring->w_ptr, ring->id);
  761. devinfo->write_ptr(devinfo, ring->r_idx_addr, commonring->r_ptr);
  762. return 0;
  763. }
  764. static int brcmf_pcie_ring_mb_write_wptr(void *ctx)
  765. {
  766. struct brcmf_pcie_ringbuf *ring = (struct brcmf_pcie_ringbuf *)ctx;
  767. struct brcmf_pciedev_info *devinfo = ring->devinfo;
  768. struct brcmf_commonring *commonring = &ring->commonring;
  769. if (devinfo->state != BRCMFMAC_PCIE_STATE_UP)
  770. return -EIO;
  771. brcmf_dbg(PCIE, "W w_ptr %d (%d), ring %d\n", commonring->w_ptr,
  772. commonring->r_ptr, ring->id);
  773. devinfo->write_ptr(devinfo, ring->w_idx_addr, commonring->w_ptr);
  774. return 0;
  775. }
  776. static int brcmf_pcie_ring_mb_ring_bell(void *ctx)
  777. {
  778. struct brcmf_pcie_ringbuf *ring = (struct brcmf_pcie_ringbuf *)ctx;
  779. struct brcmf_pciedev_info *devinfo = ring->devinfo;
  780. if (devinfo->state != BRCMFMAC_PCIE_STATE_UP)
  781. return -EIO;
  782. brcmf_dbg(PCIE, "RING !\n");
  783. /* Any arbitrary value will do, lets use 1 */
  784. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_H2D_MAILBOX_0, 1);
  785. return 0;
  786. }
  787. static int brcmf_pcie_ring_mb_update_rptr(void *ctx)
  788. {
  789. struct brcmf_pcie_ringbuf *ring = (struct brcmf_pcie_ringbuf *)ctx;
  790. struct brcmf_pciedev_info *devinfo = ring->devinfo;
  791. struct brcmf_commonring *commonring = &ring->commonring;
  792. if (devinfo->state != BRCMFMAC_PCIE_STATE_UP)
  793. return -EIO;
  794. commonring->r_ptr = devinfo->read_ptr(devinfo, ring->r_idx_addr);
  795. brcmf_dbg(PCIE, "R r_ptr %d (%d), ring %d\n", commonring->r_ptr,
  796. commonring->w_ptr, ring->id);
  797. return 0;
  798. }
  799. static int brcmf_pcie_ring_mb_update_wptr(void *ctx)
  800. {
  801. struct brcmf_pcie_ringbuf *ring = (struct brcmf_pcie_ringbuf *)ctx;
  802. struct brcmf_pciedev_info *devinfo = ring->devinfo;
  803. struct brcmf_commonring *commonring = &ring->commonring;
  804. if (devinfo->state != BRCMFMAC_PCIE_STATE_UP)
  805. return -EIO;
  806. commonring->w_ptr = devinfo->read_ptr(devinfo, ring->w_idx_addr);
  807. brcmf_dbg(PCIE, "R w_ptr %d (%d), ring %d\n", commonring->w_ptr,
  808. commonring->r_ptr, ring->id);
  809. return 0;
  810. }
  811. static void *
  812. brcmf_pcie_init_dmabuffer_for_device(struct brcmf_pciedev_info *devinfo,
  813. u32 size, u32 tcm_dma_phys_addr,
  814. dma_addr_t *dma_handle)
  815. {
  816. void *ring;
  817. u64 address;
  818. ring = dma_alloc_coherent(&devinfo->pdev->dev, size, dma_handle,
  819. GFP_KERNEL);
  820. if (!ring)
  821. return NULL;
  822. address = (u64)*dma_handle;
  823. brcmf_pcie_write_tcm32(devinfo, tcm_dma_phys_addr,
  824. address & 0xffffffff);
  825. brcmf_pcie_write_tcm32(devinfo, tcm_dma_phys_addr + 4, address >> 32);
  826. memset(ring, 0, size);
  827. return (ring);
  828. }
  829. static struct brcmf_pcie_ringbuf *
  830. brcmf_pcie_alloc_dma_and_ring(struct brcmf_pciedev_info *devinfo, u32 ring_id,
  831. u32 tcm_ring_phys_addr)
  832. {
  833. void *dma_buf;
  834. dma_addr_t dma_handle;
  835. struct brcmf_pcie_ringbuf *ring;
  836. u32 size;
  837. u32 addr;
  838. const u32 *ring_itemsize_array;
  839. if (devinfo->shared.version < BRCMF_PCIE_SHARED_VERSION_7)
  840. ring_itemsize_array = brcmf_ring_itemsize_pre_v7;
  841. else
  842. ring_itemsize_array = brcmf_ring_itemsize;
  843. size = brcmf_ring_max_item[ring_id] * ring_itemsize_array[ring_id];
  844. dma_buf = brcmf_pcie_init_dmabuffer_for_device(devinfo, size,
  845. tcm_ring_phys_addr + BRCMF_RING_MEM_BASE_ADDR_OFFSET,
  846. &dma_handle);
  847. if (!dma_buf)
  848. return NULL;
  849. addr = tcm_ring_phys_addr + BRCMF_RING_MAX_ITEM_OFFSET;
  850. brcmf_pcie_write_tcm16(devinfo, addr, brcmf_ring_max_item[ring_id]);
  851. addr = tcm_ring_phys_addr + BRCMF_RING_LEN_ITEMS_OFFSET;
  852. brcmf_pcie_write_tcm16(devinfo, addr, ring_itemsize_array[ring_id]);
  853. ring = kzalloc(sizeof(*ring), GFP_KERNEL);
  854. if (!ring) {
  855. dma_free_coherent(&devinfo->pdev->dev, size, dma_buf,
  856. dma_handle);
  857. return NULL;
  858. }
  859. brcmf_commonring_config(&ring->commonring, brcmf_ring_max_item[ring_id],
  860. ring_itemsize_array[ring_id], dma_buf);
  861. ring->dma_handle = dma_handle;
  862. ring->devinfo = devinfo;
  863. brcmf_commonring_register_cb(&ring->commonring,
  864. brcmf_pcie_ring_mb_ring_bell,
  865. brcmf_pcie_ring_mb_update_rptr,
  866. brcmf_pcie_ring_mb_update_wptr,
  867. brcmf_pcie_ring_mb_write_rptr,
  868. brcmf_pcie_ring_mb_write_wptr, ring);
  869. return (ring);
  870. }
  871. static void brcmf_pcie_release_ringbuffer(struct device *dev,
  872. struct brcmf_pcie_ringbuf *ring)
  873. {
  874. void *dma_buf;
  875. u32 size;
  876. if (!ring)
  877. return;
  878. dma_buf = ring->commonring.buf_addr;
  879. if (dma_buf) {
  880. size = ring->commonring.depth * ring->commonring.item_len;
  881. dma_free_coherent(dev, size, dma_buf, ring->dma_handle);
  882. }
  883. kfree(ring);
  884. }
  885. static void brcmf_pcie_release_ringbuffers(struct brcmf_pciedev_info *devinfo)
  886. {
  887. u32 i;
  888. for (i = 0; i < BRCMF_NROF_COMMON_MSGRINGS; i++) {
  889. brcmf_pcie_release_ringbuffer(&devinfo->pdev->dev,
  890. devinfo->shared.commonrings[i]);
  891. devinfo->shared.commonrings[i] = NULL;
  892. }
  893. kfree(devinfo->shared.flowrings);
  894. devinfo->shared.flowrings = NULL;
  895. if (devinfo->idxbuf) {
  896. dma_free_coherent(&devinfo->pdev->dev,
  897. devinfo->idxbuf_sz,
  898. devinfo->idxbuf,
  899. devinfo->idxbuf_dmahandle);
  900. devinfo->idxbuf = NULL;
  901. }
  902. }
  903. static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo)
  904. {
  905. struct brcmf_pcie_ringbuf *ring;
  906. struct brcmf_pcie_ringbuf *rings;
  907. u32 d2h_w_idx_ptr;
  908. u32 d2h_r_idx_ptr;
  909. u32 h2d_w_idx_ptr;
  910. u32 h2d_r_idx_ptr;
  911. u32 ring_mem_ptr;
  912. u32 i;
  913. u64 address;
  914. u32 bufsz;
  915. u8 idx_offset;
  916. struct brcmf_pcie_dhi_ringinfo ringinfo;
  917. u16 max_flowrings;
  918. u16 max_submissionrings;
  919. u16 max_completionrings;
  920. memcpy_fromio(&ringinfo, devinfo->tcm + devinfo->shared.ring_info_addr,
  921. sizeof(ringinfo));
  922. if (devinfo->shared.version >= 6) {
  923. max_submissionrings = le16_to_cpu(ringinfo.max_submissionrings);
  924. max_flowrings = le16_to_cpu(ringinfo.max_flowrings);
  925. max_completionrings = le16_to_cpu(ringinfo.max_completionrings);
  926. } else {
  927. max_submissionrings = le16_to_cpu(ringinfo.max_flowrings);
  928. max_flowrings = max_submissionrings -
  929. BRCMF_NROF_H2D_COMMON_MSGRINGS;
  930. max_completionrings = BRCMF_NROF_D2H_COMMON_MSGRINGS;
  931. }
  932. if (devinfo->dma_idx_sz != 0) {
  933. bufsz = (max_submissionrings + max_completionrings) *
  934. devinfo->dma_idx_sz * 2;
  935. devinfo->idxbuf = dma_alloc_coherent(&devinfo->pdev->dev, bufsz,
  936. &devinfo->idxbuf_dmahandle,
  937. GFP_KERNEL);
  938. if (!devinfo->idxbuf)
  939. devinfo->dma_idx_sz = 0;
  940. }
  941. if (devinfo->dma_idx_sz == 0) {
  942. d2h_w_idx_ptr = le32_to_cpu(ringinfo.d2h_w_idx_ptr);
  943. d2h_r_idx_ptr = le32_to_cpu(ringinfo.d2h_r_idx_ptr);
  944. h2d_w_idx_ptr = le32_to_cpu(ringinfo.h2d_w_idx_ptr);
  945. h2d_r_idx_ptr = le32_to_cpu(ringinfo.h2d_r_idx_ptr);
  946. idx_offset = sizeof(u32);
  947. devinfo->write_ptr = brcmf_pcie_write_tcm16;
  948. devinfo->read_ptr = brcmf_pcie_read_tcm16;
  949. brcmf_dbg(PCIE, "Using TCM indices\n");
  950. } else {
  951. memset(devinfo->idxbuf, 0, bufsz);
  952. devinfo->idxbuf_sz = bufsz;
  953. idx_offset = devinfo->dma_idx_sz;
  954. devinfo->write_ptr = brcmf_pcie_write_idx;
  955. devinfo->read_ptr = brcmf_pcie_read_idx;
  956. h2d_w_idx_ptr = 0;
  957. address = (u64)devinfo->idxbuf_dmahandle;
  958. ringinfo.h2d_w_idx_hostaddr.low_addr =
  959. cpu_to_le32(address & 0xffffffff);
  960. ringinfo.h2d_w_idx_hostaddr.high_addr =
  961. cpu_to_le32(address >> 32);
  962. h2d_r_idx_ptr = h2d_w_idx_ptr +
  963. max_submissionrings * idx_offset;
  964. address += max_submissionrings * idx_offset;
  965. ringinfo.h2d_r_idx_hostaddr.low_addr =
  966. cpu_to_le32(address & 0xffffffff);
  967. ringinfo.h2d_r_idx_hostaddr.high_addr =
  968. cpu_to_le32(address >> 32);
  969. d2h_w_idx_ptr = h2d_r_idx_ptr +
  970. max_submissionrings * idx_offset;
  971. address += max_submissionrings * idx_offset;
  972. ringinfo.d2h_w_idx_hostaddr.low_addr =
  973. cpu_to_le32(address & 0xffffffff);
  974. ringinfo.d2h_w_idx_hostaddr.high_addr =
  975. cpu_to_le32(address >> 32);
  976. d2h_r_idx_ptr = d2h_w_idx_ptr +
  977. max_completionrings * idx_offset;
  978. address += max_completionrings * idx_offset;
  979. ringinfo.d2h_r_idx_hostaddr.low_addr =
  980. cpu_to_le32(address & 0xffffffff);
  981. ringinfo.d2h_r_idx_hostaddr.high_addr =
  982. cpu_to_le32(address >> 32);
  983. memcpy_toio(devinfo->tcm + devinfo->shared.ring_info_addr,
  984. &ringinfo, sizeof(ringinfo));
  985. brcmf_dbg(PCIE, "Using host memory indices\n");
  986. }
  987. ring_mem_ptr = le32_to_cpu(ringinfo.ringmem);
  988. for (i = 0; i < BRCMF_NROF_H2D_COMMON_MSGRINGS; i++) {
  989. ring = brcmf_pcie_alloc_dma_and_ring(devinfo, i, ring_mem_ptr);
  990. if (!ring)
  991. goto fail;
  992. ring->w_idx_addr = h2d_w_idx_ptr;
  993. ring->r_idx_addr = h2d_r_idx_ptr;
  994. ring->id = i;
  995. devinfo->shared.commonrings[i] = ring;
  996. h2d_w_idx_ptr += idx_offset;
  997. h2d_r_idx_ptr += idx_offset;
  998. ring_mem_ptr += BRCMF_RING_MEM_SZ;
  999. }
  1000. for (i = BRCMF_NROF_H2D_COMMON_MSGRINGS;
  1001. i < BRCMF_NROF_COMMON_MSGRINGS; i++) {
  1002. ring = brcmf_pcie_alloc_dma_and_ring(devinfo, i, ring_mem_ptr);
  1003. if (!ring)
  1004. goto fail;
  1005. ring->w_idx_addr = d2h_w_idx_ptr;
  1006. ring->r_idx_addr = d2h_r_idx_ptr;
  1007. ring->id = i;
  1008. devinfo->shared.commonrings[i] = ring;
  1009. d2h_w_idx_ptr += idx_offset;
  1010. d2h_r_idx_ptr += idx_offset;
  1011. ring_mem_ptr += BRCMF_RING_MEM_SZ;
  1012. }
  1013. devinfo->shared.max_flowrings = max_flowrings;
  1014. devinfo->shared.max_submissionrings = max_submissionrings;
  1015. devinfo->shared.max_completionrings = max_completionrings;
  1016. rings = kcalloc(max_flowrings, sizeof(*ring), GFP_KERNEL);
  1017. if (!rings)
  1018. goto fail;
  1019. brcmf_dbg(PCIE, "Nr of flowrings is %d\n", max_flowrings);
  1020. for (i = 0; i < max_flowrings; i++) {
  1021. ring = &rings[i];
  1022. ring->devinfo = devinfo;
  1023. ring->id = i + BRCMF_H2D_MSGRING_FLOWRING_IDSTART;
  1024. brcmf_commonring_register_cb(&ring->commonring,
  1025. brcmf_pcie_ring_mb_ring_bell,
  1026. brcmf_pcie_ring_mb_update_rptr,
  1027. brcmf_pcie_ring_mb_update_wptr,
  1028. brcmf_pcie_ring_mb_write_rptr,
  1029. brcmf_pcie_ring_mb_write_wptr,
  1030. ring);
  1031. ring->w_idx_addr = h2d_w_idx_ptr;
  1032. ring->r_idx_addr = h2d_r_idx_ptr;
  1033. h2d_w_idx_ptr += idx_offset;
  1034. h2d_r_idx_ptr += idx_offset;
  1035. }
  1036. devinfo->shared.flowrings = rings;
  1037. return 0;
  1038. fail:
  1039. brcmf_err("Allocating ring buffers failed\n");
  1040. brcmf_pcie_release_ringbuffers(devinfo);
  1041. return -ENOMEM;
  1042. }
  1043. static void
  1044. brcmf_pcie_release_scratchbuffers(struct brcmf_pciedev_info *devinfo)
  1045. {
  1046. if (devinfo->shared.scratch)
  1047. dma_free_coherent(&devinfo->pdev->dev,
  1048. BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
  1049. devinfo->shared.scratch,
  1050. devinfo->shared.scratch_dmahandle);
  1051. if (devinfo->shared.ringupd)
  1052. dma_free_coherent(&devinfo->pdev->dev,
  1053. BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
  1054. devinfo->shared.ringupd,
  1055. devinfo->shared.ringupd_dmahandle);
  1056. }
  1057. static int brcmf_pcie_init_scratchbuffers(struct brcmf_pciedev_info *devinfo)
  1058. {
  1059. u64 address;
  1060. u32 addr;
  1061. devinfo->shared.scratch =
  1062. dma_zalloc_coherent(&devinfo->pdev->dev,
  1063. BRCMF_DMA_D2H_SCRATCH_BUF_LEN,
  1064. &devinfo->shared.scratch_dmahandle,
  1065. GFP_KERNEL);
  1066. if (!devinfo->shared.scratch)
  1067. goto fail;
  1068. addr = devinfo->shared.tcm_base_address +
  1069. BRCMF_SHARED_DMA_SCRATCH_ADDR_OFFSET;
  1070. address = (u64)devinfo->shared.scratch_dmahandle;
  1071. brcmf_pcie_write_tcm32(devinfo, addr, address & 0xffffffff);
  1072. brcmf_pcie_write_tcm32(devinfo, addr + 4, address >> 32);
  1073. addr = devinfo->shared.tcm_base_address +
  1074. BRCMF_SHARED_DMA_SCRATCH_LEN_OFFSET;
  1075. brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_SCRATCH_BUF_LEN);
  1076. devinfo->shared.ringupd =
  1077. dma_zalloc_coherent(&devinfo->pdev->dev,
  1078. BRCMF_DMA_D2H_RINGUPD_BUF_LEN,
  1079. &devinfo->shared.ringupd_dmahandle,
  1080. GFP_KERNEL);
  1081. if (!devinfo->shared.ringupd)
  1082. goto fail;
  1083. addr = devinfo->shared.tcm_base_address +
  1084. BRCMF_SHARED_DMA_RINGUPD_ADDR_OFFSET;
  1085. address = (u64)devinfo->shared.ringupd_dmahandle;
  1086. brcmf_pcie_write_tcm32(devinfo, addr, address & 0xffffffff);
  1087. brcmf_pcie_write_tcm32(devinfo, addr + 4, address >> 32);
  1088. addr = devinfo->shared.tcm_base_address +
  1089. BRCMF_SHARED_DMA_RINGUPD_LEN_OFFSET;
  1090. brcmf_pcie_write_tcm32(devinfo, addr, BRCMF_DMA_D2H_RINGUPD_BUF_LEN);
  1091. return 0;
  1092. fail:
  1093. brcmf_err("Allocating scratch buffers failed\n");
  1094. brcmf_pcie_release_scratchbuffers(devinfo);
  1095. return -ENOMEM;
  1096. }
  1097. static void brcmf_pcie_down(struct device *dev)
  1098. {
  1099. }
  1100. static int brcmf_pcie_tx(struct device *dev, struct sk_buff *skb)
  1101. {
  1102. return 0;
  1103. }
  1104. static int brcmf_pcie_tx_ctlpkt(struct device *dev, unsigned char *msg,
  1105. uint len)
  1106. {
  1107. return 0;
  1108. }
  1109. static int brcmf_pcie_rx_ctlpkt(struct device *dev, unsigned char *msg,
  1110. uint len)
  1111. {
  1112. return 0;
  1113. }
  1114. static void brcmf_pcie_wowl_config(struct device *dev, bool enabled)
  1115. {
  1116. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  1117. struct brcmf_pciedev *buspub = bus_if->bus_priv.pcie;
  1118. struct brcmf_pciedev_info *devinfo = buspub->devinfo;
  1119. brcmf_dbg(PCIE, "Configuring WOWL, enabled=%d\n", enabled);
  1120. devinfo->wowl_enabled = enabled;
  1121. }
  1122. static size_t brcmf_pcie_get_ramsize(struct device *dev)
  1123. {
  1124. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  1125. struct brcmf_pciedev *buspub = bus_if->bus_priv.pcie;
  1126. struct brcmf_pciedev_info *devinfo = buspub->devinfo;
  1127. return devinfo->ci->ramsize - devinfo->ci->srsize;
  1128. }
  1129. static int brcmf_pcie_get_memdump(struct device *dev, void *data, size_t len)
  1130. {
  1131. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  1132. struct brcmf_pciedev *buspub = bus_if->bus_priv.pcie;
  1133. struct brcmf_pciedev_info *devinfo = buspub->devinfo;
  1134. brcmf_dbg(PCIE, "dump at 0x%08X: len=%zu\n", devinfo->ci->rambase, len);
  1135. brcmf_pcie_copy_dev_tomem(devinfo, devinfo->ci->rambase, data, len);
  1136. return 0;
  1137. }
  1138. static
  1139. int brcmf_pcie_get_fwname(struct device *dev, const char *ext, u8 *fw_name)
  1140. {
  1141. struct brcmf_bus *bus_if = dev_get_drvdata(dev);
  1142. struct brcmf_fw_request *fwreq;
  1143. struct brcmf_fw_name fwnames[] = {
  1144. { ext, fw_name },
  1145. };
  1146. fwreq = brcmf_fw_alloc_request(bus_if->chip, bus_if->chiprev,
  1147. brcmf_pcie_fwnames,
  1148. ARRAY_SIZE(brcmf_pcie_fwnames),
  1149. fwnames, ARRAY_SIZE(fwnames));
  1150. if (!fwreq)
  1151. return -ENOMEM;
  1152. kfree(fwreq);
  1153. return 0;
  1154. }
  1155. static const struct brcmf_bus_ops brcmf_pcie_bus_ops = {
  1156. .txdata = brcmf_pcie_tx,
  1157. .stop = brcmf_pcie_down,
  1158. .txctl = brcmf_pcie_tx_ctlpkt,
  1159. .rxctl = brcmf_pcie_rx_ctlpkt,
  1160. .wowl_config = brcmf_pcie_wowl_config,
  1161. .get_ramsize = brcmf_pcie_get_ramsize,
  1162. .get_memdump = brcmf_pcie_get_memdump,
  1163. .get_fwname = brcmf_pcie_get_fwname,
  1164. };
  1165. static void
  1166. brcmf_pcie_adjust_ramsize(struct brcmf_pciedev_info *devinfo, u8 *data,
  1167. u32 data_len)
  1168. {
  1169. __le32 *field;
  1170. u32 newsize;
  1171. if (data_len < BRCMF_RAMSIZE_OFFSET + 8)
  1172. return;
  1173. field = (__le32 *)&data[BRCMF_RAMSIZE_OFFSET];
  1174. if (le32_to_cpup(field) != BRCMF_RAMSIZE_MAGIC)
  1175. return;
  1176. field++;
  1177. newsize = le32_to_cpup(field);
  1178. brcmf_dbg(PCIE, "Found ramsize info in FW, adjusting to 0x%x\n",
  1179. newsize);
  1180. devinfo->ci->ramsize = newsize;
  1181. }
  1182. static int
  1183. brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo,
  1184. u32 sharedram_addr)
  1185. {
  1186. struct brcmf_pcie_shared_info *shared;
  1187. u32 addr;
  1188. shared = &devinfo->shared;
  1189. shared->tcm_base_address = sharedram_addr;
  1190. shared->flags = brcmf_pcie_read_tcm32(devinfo, sharedram_addr);
  1191. shared->version = (u8)(shared->flags & BRCMF_PCIE_SHARED_VERSION_MASK);
  1192. brcmf_dbg(PCIE, "PCIe protocol version %d\n", shared->version);
  1193. if ((shared->version > BRCMF_PCIE_MAX_SHARED_VERSION) ||
  1194. (shared->version < BRCMF_PCIE_MIN_SHARED_VERSION)) {
  1195. brcmf_err("Unsupported PCIE version %d\n", shared->version);
  1196. return -EINVAL;
  1197. }
  1198. /* check firmware support dma indicies */
  1199. if (shared->flags & BRCMF_PCIE_SHARED_DMA_INDEX) {
  1200. if (shared->flags & BRCMF_PCIE_SHARED_DMA_2B_IDX)
  1201. devinfo->dma_idx_sz = sizeof(u16);
  1202. else
  1203. devinfo->dma_idx_sz = sizeof(u32);
  1204. }
  1205. addr = sharedram_addr + BRCMF_SHARED_MAX_RXBUFPOST_OFFSET;
  1206. shared->max_rxbufpost = brcmf_pcie_read_tcm16(devinfo, addr);
  1207. if (shared->max_rxbufpost == 0)
  1208. shared->max_rxbufpost = BRCMF_DEF_MAX_RXBUFPOST;
  1209. addr = sharedram_addr + BRCMF_SHARED_RX_DATAOFFSET_OFFSET;
  1210. shared->rx_dataoffset = brcmf_pcie_read_tcm32(devinfo, addr);
  1211. addr = sharedram_addr + BRCMF_SHARED_HTOD_MB_DATA_ADDR_OFFSET;
  1212. shared->htod_mb_data_addr = brcmf_pcie_read_tcm32(devinfo, addr);
  1213. addr = sharedram_addr + BRCMF_SHARED_DTOH_MB_DATA_ADDR_OFFSET;
  1214. shared->dtoh_mb_data_addr = brcmf_pcie_read_tcm32(devinfo, addr);
  1215. addr = sharedram_addr + BRCMF_SHARED_RING_INFO_ADDR_OFFSET;
  1216. shared->ring_info_addr = brcmf_pcie_read_tcm32(devinfo, addr);
  1217. brcmf_dbg(PCIE, "max rx buf post %d, rx dataoffset %d\n",
  1218. shared->max_rxbufpost, shared->rx_dataoffset);
  1219. brcmf_pcie_bus_console_init(devinfo);
  1220. return 0;
  1221. }
  1222. static int brcmf_pcie_download_fw_nvram(struct brcmf_pciedev_info *devinfo,
  1223. const struct firmware *fw, void *nvram,
  1224. u32 nvram_len)
  1225. {
  1226. u32 sharedram_addr;
  1227. u32 sharedram_addr_written;
  1228. u32 loop_counter;
  1229. int err;
  1230. u32 address;
  1231. u32 resetintr;
  1232. brcmf_dbg(PCIE, "Halt ARM.\n");
  1233. err = brcmf_pcie_enter_download_state(devinfo);
  1234. if (err)
  1235. return err;
  1236. brcmf_dbg(PCIE, "Download FW %s\n", devinfo->fw_name);
  1237. brcmf_pcie_copy_mem_todev(devinfo, devinfo->ci->rambase,
  1238. (void *)fw->data, fw->size);
  1239. resetintr = get_unaligned_le32(fw->data);
  1240. release_firmware(fw);
  1241. /* reset last 4 bytes of RAM address. to be used for shared
  1242. * area. This identifies when FW is running
  1243. */
  1244. brcmf_pcie_write_ram32(devinfo, devinfo->ci->ramsize - 4, 0);
  1245. if (nvram) {
  1246. brcmf_dbg(PCIE, "Download NVRAM %s\n", devinfo->nvram_name);
  1247. address = devinfo->ci->rambase + devinfo->ci->ramsize -
  1248. nvram_len;
  1249. brcmf_pcie_copy_mem_todev(devinfo, address, nvram, nvram_len);
  1250. brcmf_fw_nvram_free(nvram);
  1251. } else {
  1252. brcmf_dbg(PCIE, "No matching NVRAM file found %s\n",
  1253. devinfo->nvram_name);
  1254. }
  1255. sharedram_addr_written = brcmf_pcie_read_ram32(devinfo,
  1256. devinfo->ci->ramsize -
  1257. 4);
  1258. brcmf_dbg(PCIE, "Bring ARM in running state\n");
  1259. err = brcmf_pcie_exit_download_state(devinfo, resetintr);
  1260. if (err)
  1261. return err;
  1262. brcmf_dbg(PCIE, "Wait for FW init\n");
  1263. sharedram_addr = sharedram_addr_written;
  1264. loop_counter = BRCMF_PCIE_FW_UP_TIMEOUT / 50;
  1265. while ((sharedram_addr == sharedram_addr_written) && (loop_counter)) {
  1266. msleep(50);
  1267. sharedram_addr = brcmf_pcie_read_ram32(devinfo,
  1268. devinfo->ci->ramsize -
  1269. 4);
  1270. loop_counter--;
  1271. }
  1272. if (sharedram_addr == sharedram_addr_written) {
  1273. brcmf_err("FW failed to initialize\n");
  1274. return -ENODEV;
  1275. }
  1276. brcmf_dbg(PCIE, "Shared RAM addr: 0x%08x\n", sharedram_addr);
  1277. return (brcmf_pcie_init_share_ram_info(devinfo, sharedram_addr));
  1278. }
  1279. static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo)
  1280. {
  1281. struct pci_dev *pdev;
  1282. int err;
  1283. phys_addr_t bar0_addr, bar1_addr;
  1284. ulong bar1_size;
  1285. pdev = devinfo->pdev;
  1286. err = pci_enable_device(pdev);
  1287. if (err) {
  1288. brcmf_err("pci_enable_device failed err=%d\n", err);
  1289. return err;
  1290. }
  1291. pci_set_master(pdev);
  1292. /* Bar-0 mapped address */
  1293. bar0_addr = pci_resource_start(pdev, 0);
  1294. /* Bar-1 mapped address */
  1295. bar1_addr = pci_resource_start(pdev, 2);
  1296. /* read Bar-1 mapped memory range */
  1297. bar1_size = pci_resource_len(pdev, 2);
  1298. if ((bar1_size == 0) || (bar1_addr == 0)) {
  1299. brcmf_err("BAR1 Not enabled, device size=%ld, addr=%#016llx\n",
  1300. bar1_size, (unsigned long long)bar1_addr);
  1301. return -EINVAL;
  1302. }
  1303. devinfo->regs = ioremap_nocache(bar0_addr, BRCMF_PCIE_REG_MAP_SIZE);
  1304. devinfo->tcm = ioremap_nocache(bar1_addr, bar1_size);
  1305. if (!devinfo->regs || !devinfo->tcm) {
  1306. brcmf_err("ioremap() failed (%p,%p)\n", devinfo->regs,
  1307. devinfo->tcm);
  1308. return -EINVAL;
  1309. }
  1310. brcmf_dbg(PCIE, "Phys addr : reg space = %p base addr %#016llx\n",
  1311. devinfo->regs, (unsigned long long)bar0_addr);
  1312. brcmf_dbg(PCIE, "Phys addr : mem space = %p base addr %#016llx size 0x%x\n",
  1313. devinfo->tcm, (unsigned long long)bar1_addr,
  1314. (unsigned int)bar1_size);
  1315. return 0;
  1316. }
  1317. static void brcmf_pcie_release_resource(struct brcmf_pciedev_info *devinfo)
  1318. {
  1319. if (devinfo->tcm)
  1320. iounmap(devinfo->tcm);
  1321. if (devinfo->regs)
  1322. iounmap(devinfo->regs);
  1323. pci_disable_device(devinfo->pdev);
  1324. }
  1325. static u32 brcmf_pcie_buscore_prep_addr(const struct pci_dev *pdev, u32 addr)
  1326. {
  1327. u32 ret_addr;
  1328. ret_addr = addr & (BRCMF_PCIE_BAR0_REG_SIZE - 1);
  1329. addr &= ~(BRCMF_PCIE_BAR0_REG_SIZE - 1);
  1330. pci_write_config_dword(pdev, BRCMF_PCIE_BAR0_WINDOW, addr);
  1331. return ret_addr;
  1332. }
  1333. static u32 brcmf_pcie_buscore_read32(void *ctx, u32 addr)
  1334. {
  1335. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx;
  1336. addr = brcmf_pcie_buscore_prep_addr(devinfo->pdev, addr);
  1337. return brcmf_pcie_read_reg32(devinfo, addr);
  1338. }
  1339. static void brcmf_pcie_buscore_write32(void *ctx, u32 addr, u32 value)
  1340. {
  1341. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx;
  1342. addr = brcmf_pcie_buscore_prep_addr(devinfo->pdev, addr);
  1343. brcmf_pcie_write_reg32(devinfo, addr, value);
  1344. }
  1345. static int brcmf_pcie_buscoreprep(void *ctx)
  1346. {
  1347. return brcmf_pcie_get_resource(ctx);
  1348. }
  1349. static int brcmf_pcie_buscore_reset(void *ctx, struct brcmf_chip *chip)
  1350. {
  1351. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx;
  1352. u32 val;
  1353. devinfo->ci = chip;
  1354. brcmf_pcie_reset_device(devinfo);
  1355. val = brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT);
  1356. if (val != 0xffffffff)
  1357. brcmf_pcie_write_reg32(devinfo, BRCMF_PCIE_PCIE2REG_MAILBOXINT,
  1358. val);
  1359. return 0;
  1360. }
  1361. static void brcmf_pcie_buscore_activate(void *ctx, struct brcmf_chip *chip,
  1362. u32 rstvec)
  1363. {
  1364. struct brcmf_pciedev_info *devinfo = (struct brcmf_pciedev_info *)ctx;
  1365. brcmf_pcie_write_tcm32(devinfo, 0, rstvec);
  1366. }
  1367. static const struct brcmf_buscore_ops brcmf_pcie_buscore_ops = {
  1368. .prepare = brcmf_pcie_buscoreprep,
  1369. .reset = brcmf_pcie_buscore_reset,
  1370. .activate = brcmf_pcie_buscore_activate,
  1371. .read32 = brcmf_pcie_buscore_read32,
  1372. .write32 = brcmf_pcie_buscore_write32,
  1373. };
  1374. #define BRCMF_PCIE_FW_CODE 0
  1375. #define BRCMF_PCIE_FW_NVRAM 1
  1376. static void brcmf_pcie_setup(struct device *dev, int ret,
  1377. struct brcmf_fw_request *fwreq)
  1378. {
  1379. const struct firmware *fw;
  1380. void *nvram;
  1381. struct brcmf_bus *bus;
  1382. struct brcmf_pciedev *pcie_bus_dev;
  1383. struct brcmf_pciedev_info *devinfo;
  1384. struct brcmf_commonring **flowrings;
  1385. u32 i, nvram_len;
  1386. /* check firmware loading result */
  1387. if (ret)
  1388. goto fail;
  1389. bus = dev_get_drvdata(dev);
  1390. pcie_bus_dev = bus->bus_priv.pcie;
  1391. devinfo = pcie_bus_dev->devinfo;
  1392. brcmf_pcie_attach(devinfo);
  1393. fw = fwreq->items[BRCMF_PCIE_FW_CODE].binary;
  1394. nvram = fwreq->items[BRCMF_PCIE_FW_NVRAM].nv_data.data;
  1395. nvram_len = fwreq->items[BRCMF_PCIE_FW_NVRAM].nv_data.len;
  1396. kfree(fwreq);
  1397. /* Some of the firmwares have the size of the memory of the device
  1398. * defined inside the firmware. This is because part of the memory in
  1399. * the device is shared and the devision is determined by FW. Parse
  1400. * the firmware and adjust the chip memory size now.
  1401. */
  1402. brcmf_pcie_adjust_ramsize(devinfo, (u8 *)fw->data, fw->size);
  1403. ret = brcmf_pcie_download_fw_nvram(devinfo, fw, nvram, nvram_len);
  1404. if (ret)
  1405. goto fail;
  1406. devinfo->state = BRCMFMAC_PCIE_STATE_UP;
  1407. ret = brcmf_pcie_init_ringbuffers(devinfo);
  1408. if (ret)
  1409. goto fail;
  1410. ret = brcmf_pcie_init_scratchbuffers(devinfo);
  1411. if (ret)
  1412. goto fail;
  1413. brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
  1414. ret = brcmf_pcie_request_irq(devinfo);
  1415. if (ret)
  1416. goto fail;
  1417. /* hook the commonrings in the bus structure. */
  1418. for (i = 0; i < BRCMF_NROF_COMMON_MSGRINGS; i++)
  1419. bus->msgbuf->commonrings[i] =
  1420. &devinfo->shared.commonrings[i]->commonring;
  1421. flowrings = kcalloc(devinfo->shared.max_flowrings, sizeof(*flowrings),
  1422. GFP_KERNEL);
  1423. if (!flowrings)
  1424. goto fail;
  1425. for (i = 0; i < devinfo->shared.max_flowrings; i++)
  1426. flowrings[i] = &devinfo->shared.flowrings[i].commonring;
  1427. bus->msgbuf->flowrings = flowrings;
  1428. bus->msgbuf->rx_dataoffset = devinfo->shared.rx_dataoffset;
  1429. bus->msgbuf->max_rxbufpost = devinfo->shared.max_rxbufpost;
  1430. bus->msgbuf->max_flowrings = devinfo->shared.max_flowrings;
  1431. init_waitqueue_head(&devinfo->mbdata_resp_wait);
  1432. brcmf_pcie_intr_enable(devinfo);
  1433. brcmf_pcie_hostready(devinfo);
  1434. if (brcmf_attach(&devinfo->pdev->dev, devinfo->settings) == 0)
  1435. return;
  1436. brcmf_pcie_bus_console_read(devinfo);
  1437. fail:
  1438. device_release_driver(dev);
  1439. }
  1440. static struct brcmf_fw_request *
  1441. brcmf_pcie_prepare_fw_request(struct brcmf_pciedev_info *devinfo)
  1442. {
  1443. struct brcmf_fw_request *fwreq;
  1444. struct brcmf_fw_name fwnames[] = {
  1445. { ".bin", devinfo->fw_name },
  1446. { ".txt", devinfo->nvram_name },
  1447. };
  1448. fwreq = brcmf_fw_alloc_request(devinfo->ci->chip, devinfo->ci->chiprev,
  1449. brcmf_pcie_fwnames,
  1450. ARRAY_SIZE(brcmf_pcie_fwnames),
  1451. fwnames, ARRAY_SIZE(fwnames));
  1452. if (!fwreq)
  1453. return NULL;
  1454. fwreq->items[BRCMF_PCIE_FW_CODE].type = BRCMF_FW_TYPE_BINARY;
  1455. fwreq->items[BRCMF_PCIE_FW_NVRAM].type = BRCMF_FW_TYPE_NVRAM;
  1456. fwreq->items[BRCMF_PCIE_FW_NVRAM].flags = BRCMF_FW_REQF_OPTIONAL;
  1457. /* NVRAM reserves PCI domain 0 for Broadcom's SDK faked bus */
  1458. fwreq->domain_nr = pci_domain_nr(devinfo->pdev->bus) + 1;
  1459. fwreq->bus_nr = devinfo->pdev->bus->number;
  1460. return fwreq;
  1461. }
  1462. static int
  1463. brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  1464. {
  1465. int ret;
  1466. struct brcmf_fw_request *fwreq;
  1467. struct brcmf_pciedev_info *devinfo;
  1468. struct brcmf_pciedev *pcie_bus_dev;
  1469. struct brcmf_bus *bus;
  1470. brcmf_dbg(PCIE, "Enter %x:%x\n", pdev->vendor, pdev->device);
  1471. ret = -ENOMEM;
  1472. devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
  1473. if (devinfo == NULL)
  1474. return ret;
  1475. devinfo->pdev = pdev;
  1476. pcie_bus_dev = NULL;
  1477. devinfo->ci = brcmf_chip_attach(devinfo, &brcmf_pcie_buscore_ops);
  1478. if (IS_ERR(devinfo->ci)) {
  1479. ret = PTR_ERR(devinfo->ci);
  1480. devinfo->ci = NULL;
  1481. goto fail;
  1482. }
  1483. pcie_bus_dev = kzalloc(sizeof(*pcie_bus_dev), GFP_KERNEL);
  1484. if (pcie_bus_dev == NULL) {
  1485. ret = -ENOMEM;
  1486. goto fail;
  1487. }
  1488. devinfo->settings = brcmf_get_module_param(&devinfo->pdev->dev,
  1489. BRCMF_BUSTYPE_PCIE,
  1490. devinfo->ci->chip,
  1491. devinfo->ci->chiprev);
  1492. if (!devinfo->settings) {
  1493. ret = -ENOMEM;
  1494. goto fail;
  1495. }
  1496. bus = kzalloc(sizeof(*bus), GFP_KERNEL);
  1497. if (!bus) {
  1498. ret = -ENOMEM;
  1499. goto fail;
  1500. }
  1501. bus->msgbuf = kzalloc(sizeof(*bus->msgbuf), GFP_KERNEL);
  1502. if (!bus->msgbuf) {
  1503. ret = -ENOMEM;
  1504. kfree(bus);
  1505. goto fail;
  1506. }
  1507. /* hook it all together. */
  1508. pcie_bus_dev->devinfo = devinfo;
  1509. pcie_bus_dev->bus = bus;
  1510. bus->dev = &pdev->dev;
  1511. bus->bus_priv.pcie = pcie_bus_dev;
  1512. bus->ops = &brcmf_pcie_bus_ops;
  1513. bus->proto_type = BRCMF_PROTO_MSGBUF;
  1514. bus->chip = devinfo->coreid;
  1515. bus->wowl_supported = pci_pme_capable(pdev, PCI_D3hot);
  1516. dev_set_drvdata(&pdev->dev, bus);
  1517. fwreq = brcmf_pcie_prepare_fw_request(devinfo);
  1518. if (!fwreq) {
  1519. ret = -ENOMEM;
  1520. goto fail_bus;
  1521. }
  1522. ret = brcmf_fw_get_firmwares(bus->dev, fwreq, brcmf_pcie_setup);
  1523. if (ret < 0) {
  1524. kfree(fwreq);
  1525. goto fail_bus;
  1526. }
  1527. return 0;
  1528. fail_bus:
  1529. kfree(bus->msgbuf);
  1530. kfree(bus);
  1531. fail:
  1532. brcmf_err("failed %x:%x\n", pdev->vendor, pdev->device);
  1533. brcmf_pcie_release_resource(devinfo);
  1534. if (devinfo->ci)
  1535. brcmf_chip_detach(devinfo->ci);
  1536. if (devinfo->settings)
  1537. brcmf_release_module_param(devinfo->settings);
  1538. kfree(pcie_bus_dev);
  1539. kfree(devinfo);
  1540. return ret;
  1541. }
  1542. static void
  1543. brcmf_pcie_remove(struct pci_dev *pdev)
  1544. {
  1545. struct brcmf_pciedev_info *devinfo;
  1546. struct brcmf_bus *bus;
  1547. brcmf_dbg(PCIE, "Enter\n");
  1548. bus = dev_get_drvdata(&pdev->dev);
  1549. if (bus == NULL)
  1550. return;
  1551. devinfo = bus->bus_priv.pcie->devinfo;
  1552. devinfo->state = BRCMFMAC_PCIE_STATE_DOWN;
  1553. if (devinfo->ci)
  1554. brcmf_pcie_intr_disable(devinfo);
  1555. brcmf_detach(&pdev->dev);
  1556. kfree(bus->bus_priv.pcie);
  1557. kfree(bus->msgbuf->flowrings);
  1558. kfree(bus->msgbuf);
  1559. kfree(bus);
  1560. brcmf_pcie_release_irq(devinfo);
  1561. brcmf_pcie_release_scratchbuffers(devinfo);
  1562. brcmf_pcie_release_ringbuffers(devinfo);
  1563. brcmf_pcie_reset_device(devinfo);
  1564. brcmf_pcie_release_resource(devinfo);
  1565. if (devinfo->ci)
  1566. brcmf_chip_detach(devinfo->ci);
  1567. if (devinfo->settings)
  1568. brcmf_release_module_param(devinfo->settings);
  1569. kfree(devinfo);
  1570. dev_set_drvdata(&pdev->dev, NULL);
  1571. }
  1572. #ifdef CONFIG_PM
  1573. static int brcmf_pcie_pm_enter_D3(struct device *dev)
  1574. {
  1575. struct brcmf_pciedev_info *devinfo;
  1576. struct brcmf_bus *bus;
  1577. brcmf_dbg(PCIE, "Enter\n");
  1578. bus = dev_get_drvdata(dev);
  1579. devinfo = bus->bus_priv.pcie->devinfo;
  1580. brcmf_bus_change_state(bus, BRCMF_BUS_DOWN);
  1581. devinfo->mbdata_completed = false;
  1582. brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM);
  1583. wait_event_timeout(devinfo->mbdata_resp_wait, devinfo->mbdata_completed,
  1584. BRCMF_PCIE_MBDATA_TIMEOUT);
  1585. if (!devinfo->mbdata_completed) {
  1586. brcmf_err("Timeout on response for entering D3 substate\n");
  1587. brcmf_bus_change_state(bus, BRCMF_BUS_UP);
  1588. return -EIO;
  1589. }
  1590. devinfo->state = BRCMFMAC_PCIE_STATE_DOWN;
  1591. return 0;
  1592. }
  1593. static int brcmf_pcie_pm_leave_D3(struct device *dev)
  1594. {
  1595. struct brcmf_pciedev_info *devinfo;
  1596. struct brcmf_bus *bus;
  1597. struct pci_dev *pdev;
  1598. int err;
  1599. brcmf_dbg(PCIE, "Enter\n");
  1600. bus = dev_get_drvdata(dev);
  1601. devinfo = bus->bus_priv.pcie->devinfo;
  1602. brcmf_dbg(PCIE, "Enter, dev=%p, bus=%p\n", dev, bus);
  1603. /* Check if device is still up and running, if so we are ready */
  1604. if (brcmf_pcie_read_reg32(devinfo, BRCMF_PCIE_PCIE2REG_INTMASK) != 0) {
  1605. brcmf_dbg(PCIE, "Try to wakeup device....\n");
  1606. if (brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM))
  1607. goto cleanup;
  1608. brcmf_dbg(PCIE, "Hot resume, continue....\n");
  1609. devinfo->state = BRCMFMAC_PCIE_STATE_UP;
  1610. brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
  1611. brcmf_bus_change_state(bus, BRCMF_BUS_UP);
  1612. brcmf_pcie_intr_enable(devinfo);
  1613. brcmf_pcie_hostready(devinfo);
  1614. return 0;
  1615. }
  1616. cleanup:
  1617. brcmf_chip_detach(devinfo->ci);
  1618. devinfo->ci = NULL;
  1619. pdev = devinfo->pdev;
  1620. brcmf_pcie_remove(pdev);
  1621. err = brcmf_pcie_probe(pdev, NULL);
  1622. if (err)
  1623. brcmf_err("probe after resume failed, err=%d\n", err);
  1624. return err;
  1625. }
  1626. static const struct dev_pm_ops brcmf_pciedrvr_pm = {
  1627. .suspend = brcmf_pcie_pm_enter_D3,
  1628. .resume = brcmf_pcie_pm_leave_D3,
  1629. .freeze = brcmf_pcie_pm_enter_D3,
  1630. .restore = brcmf_pcie_pm_leave_D3,
  1631. };
  1632. #endif /* CONFIG_PM */
  1633. #define BRCMF_PCIE_DEVICE(dev_id) { BRCM_PCIE_VENDOR_ID_BROADCOM, dev_id,\
  1634. PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, 0 }
  1635. #define BRCMF_PCIE_DEVICE_SUB(dev_id, subvend, subdev) { \
  1636. BRCM_PCIE_VENDOR_ID_BROADCOM, dev_id,\
  1637. subvend, subdev, PCI_CLASS_NETWORK_OTHER << 8, 0xffff00, 0 }
  1638. static const struct pci_device_id brcmf_pcie_devid_table[] = {
  1639. BRCMF_PCIE_DEVICE(BRCM_PCIE_4350_DEVICE_ID),
  1640. BRCMF_PCIE_DEVICE(BRCM_PCIE_4356_DEVICE_ID),
  1641. BRCMF_PCIE_DEVICE(BRCM_PCIE_43567_DEVICE_ID),
  1642. BRCMF_PCIE_DEVICE(BRCM_PCIE_43570_DEVICE_ID),
  1643. BRCMF_PCIE_DEVICE(BRCM_PCIE_4358_DEVICE_ID),
  1644. BRCMF_PCIE_DEVICE(BRCM_PCIE_4359_DEVICE_ID),
  1645. BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_DEVICE_ID),
  1646. BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_2G_DEVICE_ID),
  1647. BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_5G_DEVICE_ID),
  1648. BRCMF_PCIE_DEVICE(BRCM_PCIE_43602_RAW_DEVICE_ID),
  1649. BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_DEVICE_ID),
  1650. BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_2G_DEVICE_ID),
  1651. BRCMF_PCIE_DEVICE(BRCM_PCIE_4365_5G_DEVICE_ID),
  1652. BRCMF_PCIE_DEVICE_SUB(0x4365, BRCM_PCIE_VENDOR_ID_BROADCOM, 0x4365),
  1653. BRCMF_PCIE_DEVICE(BRCM_PCIE_4366_DEVICE_ID),
  1654. BRCMF_PCIE_DEVICE(BRCM_PCIE_4366_2G_DEVICE_ID),
  1655. BRCMF_PCIE_DEVICE(BRCM_PCIE_4366_5G_DEVICE_ID),
  1656. BRCMF_PCIE_DEVICE(BRCM_PCIE_4371_DEVICE_ID),
  1657. { /* end: all zeroes */ }
  1658. };
  1659. MODULE_DEVICE_TABLE(pci, brcmf_pcie_devid_table);
  1660. static struct pci_driver brcmf_pciedrvr = {
  1661. .node = {},
  1662. .name = KBUILD_MODNAME,
  1663. .id_table = brcmf_pcie_devid_table,
  1664. .probe = brcmf_pcie_probe,
  1665. .remove = brcmf_pcie_remove,
  1666. #ifdef CONFIG_PM
  1667. .driver.pm = &brcmf_pciedrvr_pm,
  1668. #endif
  1669. .driver.coredump = brcmf_dev_coredump,
  1670. };
  1671. void brcmf_pcie_register(void)
  1672. {
  1673. int err;
  1674. brcmf_dbg(PCIE, "Enter\n");
  1675. err = pci_register_driver(&brcmf_pciedrvr);
  1676. if (err)
  1677. brcmf_err("PCIE driver registration failed, err=%d\n", err);
  1678. }
  1679. void brcmf_pcie_exit(void)
  1680. {
  1681. brcmf_dbg(PCIE, "Enter\n");
  1682. pci_unregister_driver(&brcmf_pciedrvr);
  1683. }