siutils_priv.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * Include file private to the SOC Interconnect support files.
  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: siutils_priv.h 698933 2017-05-11 06:05:10Z $
  30. */
  31. #ifndef _siutils_priv_h_
  32. #define _siutils_priv_h_
  33. #if defined(SI_ERROR_ENFORCE)
  34. #define SI_ERROR(args) printf args
  35. #else
  36. #define SI_ERROR(args)
  37. #endif // endif
  38. #if defined(ENABLE_CORECAPTURE)
  39. #define SI_PRINT(args) osl_wificc_logDebug args
  40. #else
  41. #define SI_PRINT(args) printf args
  42. #endif /* ENABLE_CORECAPTURE */
  43. #define SI_MSG(args)
  44. #ifdef BCMDBG_SI
  45. #define SI_VMSG(args) printf args
  46. #else
  47. #define SI_VMSG(args)
  48. #endif // endif
  49. #define IS_SIM(chippkg) ((chippkg == HDLSIM_PKG_ID) || (chippkg == HWSIM_PKG_ID))
  50. typedef uint32 (*si_intrsoff_t)(void *intr_arg);
  51. typedef void (*si_intrsrestore_t)(void *intr_arg, uint32 arg);
  52. typedef bool (*si_intrsenabled_t)(void *intr_arg);
  53. #define SI_GPIO_MAX 16
  54. typedef struct gci_gpio_item {
  55. void *arg;
  56. uint8 gci_gpio;
  57. uint8 status;
  58. gci_gpio_handler_t handler;
  59. struct gci_gpio_item *next;
  60. } gci_gpio_item_t;
  61. #define AI_SLAVE_WRAPPER 0
  62. #define AI_MASTER_WRAPPER 1
  63. typedef struct axi_wrapper {
  64. uint32 mfg;
  65. uint32 cid;
  66. uint32 rev;
  67. uint32 wrapper_type;
  68. uint32 wrapper_addr;
  69. uint32 wrapper_size;
  70. } axi_wrapper_t;
  71. #define SI_MAX_AXI_WRAPPERS 32
  72. #define AI_REG_READ_TIMEOUT 300 /* in msec */
  73. /* for some combo chips, BT side accesses chipcommon->0x190, as a 16 byte addr */
  74. /* register at 0x19C doesn't exist, so error is logged at the slave wrapper */
  75. #define BT_CC_SPROM_BADREG_LO 0x18000190
  76. #define BT_CC_SPROM_BADREG_SIZE 4
  77. #define BT_CC_SPROM_BADREG_HI 0
  78. #define BCM4350_BT_AXI_ID 6
  79. #define BCM4345_BT_AXI_ID 6
  80. #define BCM4349_BT_AXI_ID 5
  81. #define BCM4364_BT_AXI_ID 5
  82. /* for BT logging and memory dump, ignore failed access to BT memory */
  83. #define BCM4347_BT_ADDR_HI 0
  84. #define BCM4347_BT_ADDR_LO 0x19000000 /* BT address space */
  85. #define BCM4347_BT_SIZE 0x01000000 /* BT address space size */
  86. #define BCM4347_UNUSED_AXI_ID 0xffffffff
  87. #define BCM4347_CC_AXI_ID 0
  88. #define BCM4347_PCIE_AXI_ID 1
  89. typedef struct si_cores_info {
  90. volatile void *regs[SI_MAXCORES]; /* other regs va */
  91. uint coreid[SI_MAXCORES]; /**< id of each core */
  92. uint32 coresba[SI_MAXCORES]; /**< backplane address of each core */
  93. void *regs2[SI_MAXCORES]; /**< va of each core second register set (usbh20) */
  94. uint32 coresba2[SI_MAXCORES]; /**< address of each core second register set (usbh20) */
  95. uint32 coresba_size[SI_MAXCORES]; /**< backplane address space size */
  96. uint32 coresba2_size[SI_MAXCORES]; /**< second address space size */
  97. void *wrappers[SI_MAXCORES]; /**< other cores wrapper va */
  98. uint32 wrapba[SI_MAXCORES]; /**< address of controlling wrapper */
  99. void *wrappers2[SI_MAXCORES]; /**< other cores wrapper va */
  100. uint32 wrapba2[SI_MAXCORES]; /**< address of controlling wrapper */
  101. void *wrappers3[SI_MAXCORES]; /**< other cores wrapper va */
  102. uint32 wrapba3[SI_MAXCORES]; /**< address of controlling wrapper */
  103. uint32 cia[SI_MAXCORES]; /**< erom cia entry for each core */
  104. uint32 cib[SI_MAXCORES]; /**< erom cia entry for each core */
  105. uint32 csp2ba[SI_MAXCORES]; /**< Second slave port base addr 0 */
  106. uint32 csp2ba_size[SI_MAXCORES]; /**< Second slave port addr space size */
  107. } si_cores_info_t;
  108. /** misc si info needed by some of the routines */
  109. typedef struct si_info {
  110. struct si_pub pub; /**< back plane public state (must be first field) */
  111. void *osh; /**< osl os handle */
  112. void *sdh; /**< bcmsdh handle */
  113. uint dev_coreid; /**< the core provides driver functions */
  114. void *intr_arg; /**< interrupt callback function arg */
  115. si_intrsoff_t intrsoff_fn; /**< turns chip interrupts off */
  116. si_intrsrestore_t intrsrestore_fn; /**< restore chip interrupts */
  117. si_intrsenabled_t intrsenabled_fn; /**< check if interrupts are enabled */
  118. void *pch; /**< PCI/E core handle */
  119. bool memseg; /**< flag to toggle MEM_SEG register */
  120. char *vars;
  121. uint varsz;
  122. volatile void *curmap; /* current regs va */
  123. uint curidx; /**< current core index */
  124. uint numcores; /**< # discovered cores */
  125. void *curwrap; /**< current wrapper va */
  126. uint32 oob_router; /**< oob router registers for axi */
  127. uint32 oob_router1; /**< oob router registers for axi */
  128. si_cores_info_t *cores_info;
  129. gci_gpio_item_t *gci_gpio_head; /**< gci gpio interrupts head */
  130. uint chipnew; /**< new chip number */
  131. uint second_bar0win; /**< Backplane region */
  132. uint num_br; /**< # discovered bridges */
  133. uint32 br_wrapba[SI_MAXBR]; /**< address of bridge controlling wrapper */
  134. uint32 xtalfreq;
  135. uint32 openloop_dco_code; /**< OPEN loop calibration dco code */
  136. uint8 spurmode;
  137. bool device_removed;
  138. uint axi_num_wrappers;
  139. axi_wrapper_t * axi_wrapper;
  140. uint8 device_wake_opt; /* device_wake GPIO number */
  141. uint8 lhl_ps_mode;
  142. } si_info_t;
  143. #define SI_INFO(sih) ((si_info_t *)(uintptr)sih)
  144. #define GOODCOREADDR(x, b) (((x) >= (b)) && ((x) < ((b) + SI_MAXCORES * SI_CORE_SIZE)) && \
  145. ISALIGNED((x), SI_CORE_SIZE))
  146. #define GOODREGS(regs) ((regs) != NULL && ISALIGNED((uintptr)(regs), SI_CORE_SIZE))
  147. #define BADCOREADDR 0
  148. #define GOODIDX(idx) (((uint)idx) < SI_MAXCORES)
  149. #define NOREV -1 /**< Invalid rev */
  150. #define PCI(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  151. ((si)->pub.buscoretype == PCI_CORE_ID))
  152. #define PCIE_GEN1(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  153. ((si)->pub.buscoretype == PCIE_CORE_ID))
  154. #define PCIE_GEN2(si) ((BUSTYPE((si)->pub.bustype) == PCI_BUS) && \
  155. ((si)->pub.buscoretype == PCIE2_CORE_ID))
  156. #define PCIE(si) (PCIE_GEN1(si) || PCIE_GEN2(si))
  157. #define PCMCIA(si) ((BUSTYPE((si)->pub.bustype) == PCMCIA_BUS) && ((si)->memseg == TRUE))
  158. /** Newer chips can access PCI/PCIE and CC core without requiring to change PCI BAR0 WIN */
  159. #define SI_FAST(si) (PCIE(si) || (PCI(si) && ((si)->pub.buscorerev >= 13)))
  160. #define CCREGS_FAST(si) \
  161. (((si)->curmap == NULL) ? NULL : \
  162. ((volatile char *)((si)->curmap) + PCI_16KB0_CCREGS_OFFSET))
  163. #define PCIEREGS(si) (((volatile char *)((si)->curmap) + PCI_16KB0_PCIREGS_OFFSET))
  164. /*
  165. * Macros to disable/restore function core(D11, ENET, ILINE20, etc) interrupts before/
  166. * after core switching to avoid invalid register accesss inside ISR.
  167. */
  168. #define INTR_OFF(si, intr_val) \
  169. if ((si)->intrsoff_fn && (si)->cores_info->coreid[(si)->curidx] == (si)->dev_coreid) { \
  170. intr_val = (*(si)->intrsoff_fn)((si)->intr_arg); }
  171. #define INTR_RESTORE(si, intr_val) \
  172. if ((si)->intrsrestore_fn && (si)->cores_info->coreid[(si)->curidx] == (si)->dev_coreid) { \
  173. (*(si)->intrsrestore_fn)((si)->intr_arg, intr_val); }
  174. /* dynamic clock control defines */
  175. #define LPOMINFREQ 25000 /**< low power oscillator min */
  176. #define LPOMAXFREQ 43000 /**< low power oscillator max */
  177. #define XTALMINFREQ 19800000 /**< 20 MHz - 1% */
  178. #define XTALMAXFREQ 20200000 /**< 20 MHz + 1% */
  179. #define PCIMINFREQ 25000000 /**< 25 MHz */
  180. #define PCIMAXFREQ 34000000 /**< 33 MHz + fudge */
  181. #define ILP_DIV_5MHZ 0 /**< ILP = 5 MHz */
  182. #define ILP_DIV_1MHZ 4 /**< ILP = 1 MHz */
  183. /* GPIO Based LED powersave defines */
  184. #define DEFAULT_GPIO_ONTIME 10 /**< Default: 10% on */
  185. #define DEFAULT_GPIO_OFFTIME 90 /**< Default: 10% on */
  186. #ifndef DEFAULT_GPIOTIMERVAL
  187. #define DEFAULT_GPIOTIMERVAL ((DEFAULT_GPIO_ONTIME << GPIO_ONTIME_SHIFT) | DEFAULT_GPIO_OFFTIME)
  188. #endif // endif
  189. /* Silicon Backplane externs */
  190. extern void sb_scan(si_t *sih, volatile void *regs, uint devid);
  191. extern uint sb_coreid(si_t *sih);
  192. extern uint sb_intflag(si_t *sih);
  193. extern uint sb_flag(si_t *sih);
  194. extern void sb_setint(si_t *sih, int siflag);
  195. extern uint sb_corevendor(si_t *sih);
  196. extern uint sb_corerev(si_t *sih);
  197. extern uint sb_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val);
  198. extern volatile uint32 *sb_corereg_addr(si_t *sih, uint coreidx, uint regoff);
  199. extern bool sb_iscoreup(si_t *sih);
  200. extern volatile void *sb_setcoreidx(si_t *sih, uint coreidx);
  201. extern uint32 sb_core_cflags(si_t *sih, uint32 mask, uint32 val);
  202. extern void sb_core_cflags_wo(si_t *sih, uint32 mask, uint32 val);
  203. extern uint32 sb_core_sflags(si_t *sih, uint32 mask, uint32 val);
  204. extern void sb_commit(si_t *sih);
  205. extern uint32 sb_base(uint32 admatch);
  206. extern uint32 sb_size(uint32 admatch);
  207. extern void sb_core_reset(si_t *sih, uint32 bits, uint32 resetbits);
  208. extern void sb_core_disable(si_t *sih, uint32 bits);
  209. extern uint32 sb_addrspace(si_t *sih, uint asidx);
  210. extern uint32 sb_addrspacesize(si_t *sih, uint asidx);
  211. extern int sb_numaddrspaces(si_t *sih);
  212. extern uint32 sb_set_initiator_to(si_t *sih, uint32 to, uint idx);
  213. extern bool sb_taclear(si_t *sih, bool details);
  214. #if defined(BCMDBG_PHYDUMP)
  215. extern void sb_dumpregs(si_t *sih, struct bcmstrbuf *b);
  216. #endif // endif
  217. /* Wake-on-wireless-LAN (WOWL) */
  218. extern bool sb_pci_pmecap(si_t *sih);
  219. struct osl_info;
  220. extern bool sb_pci_fastpmecap(struct osl_info *osh);
  221. extern bool sb_pci_pmeclr(si_t *sih);
  222. extern void sb_pci_pmeen(si_t *sih);
  223. extern uint sb_pcie_readreg(void *sih, uint addrtype, uint offset);
  224. /* AMBA Interconnect exported externs */
  225. extern si_t *ai_attach(uint pcidev, osl_t *osh, void *regs, uint bustype,
  226. void *sdh, char **vars, uint *varsz);
  227. extern si_t *ai_kattach(osl_t *osh);
  228. extern void ai_scan(si_t *sih, void *regs, uint devid);
  229. extern uint ai_flag(si_t *sih);
  230. extern uint ai_flag_alt(si_t *sih);
  231. extern void ai_setint(si_t *sih, int siflag);
  232. extern uint ai_coreidx(si_t *sih);
  233. extern uint ai_corevendor(si_t *sih);
  234. extern uint ai_corerev(si_t *sih);
  235. extern uint ai_corerev_minor(si_t *sih);
  236. extern volatile uint32 *ai_corereg_addr(si_t *sih, uint coreidx, uint regoff);
  237. extern bool ai_iscoreup(si_t *sih);
  238. extern volatile void *ai_setcoreidx(si_t *sih, uint coreidx);
  239. extern volatile void *ai_setcoreidx_2ndwrap(si_t *sih, uint coreidx);
  240. extern volatile void *ai_setcoreidx_3rdwrap(si_t *sih, uint coreidx);
  241. extern uint32 ai_core_cflags(si_t *sih, uint32 mask, uint32 val);
  242. extern void ai_core_cflags_wo(si_t *sih, uint32 mask, uint32 val);
  243. extern uint32 ai_core_sflags(si_t *sih, uint32 mask, uint32 val);
  244. extern uint ai_corereg(si_t *sih, uint coreidx, uint regoff, uint mask, uint val);
  245. extern uint ai_corereg_writeonly(si_t *sih, uint coreidx, uint regoff, uint mask, uint val);
  246. extern void ai_core_reset(si_t *sih, uint32 bits, uint32 resetbits);
  247. extern void ai_d11rsdb_core_reset(si_t *sih, uint32 bits,
  248. uint32 resetbits, void *p, volatile void *s);
  249. extern void ai_core_disable(si_t *sih, uint32 bits);
  250. extern void ai_d11rsdb_core_disable(const si_info_t *sii, uint32 bits,
  251. aidmp_t *pmacai, aidmp_t *smacai);
  252. extern int ai_numaddrspaces(si_t *sih);
  253. extern uint32 ai_addrspace(si_t *sih, uint spidx, uint baidx);
  254. extern uint32 ai_addrspacesize(si_t *sih, uint spidx, uint baidx);
  255. extern void ai_coreaddrspaceX(si_t *sih, uint asidx, uint32 *addr, uint32 *size);
  256. extern uint ai_wrap_reg(si_t *sih, uint32 offset, uint32 mask, uint32 val);
  257. extern void ai_update_backplane_timeouts(si_t *sih, bool enable, uint32 timeout, uint32 cid);
  258. extern uint32 ai_clear_backplane_to(si_t *sih);
  259. void ai_force_clocks(si_t *sih, uint clock_state);
  260. extern uint ai_num_slaveports(si_t *sih, uint coreidx);
  261. #ifdef BCM_BACKPLANE_TIMEOUT
  262. uint32 ai_clear_backplane_to_fast(si_t *sih, void * addr);
  263. #endif /* BCM_BACKPLANE_TIMEOUT */
  264. #if defined(AXI_TIMEOUTS) || defined(BCM_BACKPLANE_TIMEOUT)
  265. extern uint32 ai_clear_backplane_to_per_core(si_t *sih, uint coreid, uint coreunit, void * wrap);
  266. #endif /* AXI_TIMEOUTS || BCM_BACKPLANE_TIMEOUT */
  267. #if defined(BCMDBG_PHYDUMP)
  268. extern void ai_dumpregs(si_t *sih, struct bcmstrbuf *b);
  269. #endif // endif
  270. extern uint32 ai_wrapper_dump_buf_size(si_t *sih);
  271. extern uint32 ai_wrapper_dump_binary(si_t *sih, uchar *p);
  272. extern bool ai_check_enable_backplane_log(si_t *sih);
  273. extern uint32 ai_wrapper_dump_last_timeout(si_t *sih, uint32 *error, uint32 *core, uint32 *ba,
  274. uchar *p);
  275. #define ub_scan(a, b, c) do {} while (0)
  276. #define ub_flag(a) (0)
  277. #define ub_setint(a, b) do {} while (0)
  278. #define ub_coreidx(a) (0)
  279. #define ub_corevendor(a) (0)
  280. #define ub_corerev(a) (0)
  281. #define ub_iscoreup(a) (0)
  282. #define ub_setcoreidx(a, b) (0)
  283. #define ub_core_cflags(a, b, c) (0)
  284. #define ub_core_cflags_wo(a, b, c) do {} while (0)
  285. #define ub_core_sflags(a, b, c) (0)
  286. #define ub_corereg(a, b, c, d, e) (0)
  287. #define ub_core_reset(a, b, c) do {} while (0)
  288. #define ub_core_disable(a, b) do {} while (0)
  289. #define ub_numaddrspaces(a) (0)
  290. #define ub_addrspace(a, b) (0)
  291. #define ub_addrspacesize(a, b) (0)
  292. #define ub_view(a, b) do {} while (0)
  293. #define ub_dumpregs(a, b) do {} while (0)
  294. #endif /* _siutils_priv_h_ */