osl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * OS Abstraction Layer
  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: osl.h 673906 2016-12-05 19:59:39Z $
  30. */
  31. #ifndef _osl_h_
  32. #define _osl_h_
  33. #include <osl_decl.h>
  34. enum {
  35. TAIL_BYTES_TYPE_FCS = 1,
  36. TAIL_BYTES_TYPE_ICV = 2,
  37. TAIL_BYTES_TYPE_MIC = 3
  38. };
  39. #define OSL_PKTTAG_SZ 48 /* standard linux pkttag size is 48 bytes */
  40. /* Drivers use PKTFREESETCB to register a callback function when a packet is freed by OSL */
  41. typedef void (*pktfree_cb_fn_t)(void *ctx, void *pkt, unsigned int status);
  42. /* Drivers use REGOPSSET() to register register read/write funcitons */
  43. typedef unsigned int (*osl_rreg_fn_t)(void *ctx, volatile void *reg, unsigned int size);
  44. typedef void (*osl_wreg_fn_t)(void *ctx, volatile void *reg, unsigned int val, unsigned int size);
  45. #if defined(WL_UNITTEST)
  46. #include <utest_osl.h>
  47. #else
  48. #include <linux_osl.h>
  49. #include <linux_pkt.h>
  50. #endif // endif
  51. #ifndef PKTDBG_TRACE
  52. #define PKTDBG_TRACE(osh, pkt, bit) BCM_REFERENCE(osh)
  53. #endif // endif
  54. #define PKTCTFMAP(osh, p) BCM_REFERENCE(osh)
  55. /* --------------------------------------------------------------------------
  56. ** Register manipulation macros.
  57. */
  58. #define SET_REG(osh, r, mask, val) W_REG((osh), (r), ((R_REG((osh), r) & ~(mask)) | (val)))
  59. #ifndef AND_REG
  60. #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
  61. #endif /* !AND_REG */
  62. #ifndef OR_REG
  63. #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
  64. #endif /* !OR_REG */
  65. #if !defined(OSL_SYSUPTIME)
  66. #define OSL_SYSUPTIME() (0)
  67. #define OSL_SYSUPTIME_NOT_DEFINED 1
  68. #endif /* !defined(OSL_SYSUPTIME) */
  69. #if !defined(OSL_SYSUPTIME_US)
  70. #define OSL_SYSUPTIME_US() (0)
  71. #define OSL_SYSUPTIME_US_NOT_DEFINED 1
  72. #endif /* !defined(OSL_SYSUPTIME) */
  73. #if defined(OSL_SYSUPTIME_NOT_DEFINED) && defined(OSL_SYSUPTIME_US_NOT_DEFINED)
  74. #define OSL_SYSUPTIME_SUPPORT FALSE
  75. #else
  76. #define OSL_SYSUPTIME_SUPPORT TRUE
  77. #endif /* OSL_SYSUPTIME */
  78. #ifndef OSL_GET_LOCALTIME
  79. #define OSL_GET_LOCALTIME(sec, usec) \
  80. do { \
  81. BCM_REFERENCE(sec); \
  82. BCM_REFERENCE(usec); \
  83. } while (0)
  84. #endif /* OSL_GET_LOCALTIME */
  85. #ifndef OSL_LOCALTIME_NS
  86. #define OSL_LOCALTIME_NS() (OSL_SYSUPTIME_US() * NSEC_PER_USEC)
  87. #endif /* OSL_LOCALTIME_NS */
  88. #ifndef OSL_SYSTZTIME_US
  89. #define OSL_SYSTZTIME_US() OSL_SYSUPTIME_US()
  90. #endif /* OSL_GET_SYSTZTIME */
  91. #ifndef OSL_SYS_HALT
  92. #define OSL_SYS_HALT() do {} while (0)
  93. #endif // endif
  94. #ifndef DMB
  95. #if defined(STB)
  96. #define DMB() mb();
  97. #else /* STB */
  98. #define DMB() do {} while (0)
  99. #endif /* STB */
  100. #endif /* DMB */
  101. #ifndef OSL_MEM_AVAIL
  102. #define OSL_MEM_AVAIL() (0xffffffff)
  103. #endif // endif
  104. #ifndef OSL_OBFUSCATE_BUF
  105. /* For security reasons printing pointers is not allowed.
  106. * Some OSLs implement OSL_OBFUSCATE_BUF to OS specific obfuscate API.
  107. * If OSL_OBFUSCATE_BUF() is not implemented in OSL, then default to
  108. * printing the input pointer
  109. */
  110. #define OSL_OBFUSCATE_BUF(x) (x)
  111. #endif /* OSL_OBFUSCATE_BUF */
  112. #if !defined(PKTC_DONGLE)
  113. #define PKTCGETATTR(skb) (0)
  114. #define PKTCSETATTR(skb, f, p, b) BCM_REFERENCE(skb)
  115. #define PKTCCLRATTR(skb) BCM_REFERENCE(skb)
  116. #define PKTCCNT(skb) (1)
  117. #define PKTCLEN(skb) PKTLEN(NULL, skb)
  118. #define PKTCGETFLAGS(skb) (0)
  119. #define PKTCSETFLAGS(skb, f) BCM_REFERENCE(skb)
  120. #define PKTCCLRFLAGS(skb) BCM_REFERENCE(skb)
  121. #define PKTCFLAGS(skb) (0)
  122. #define PKTCSETCNT(skb, c) BCM_REFERENCE(skb)
  123. #define PKTCINCRCNT(skb) BCM_REFERENCE(skb)
  124. #define PKTCADDCNT(skb, c) BCM_REFERENCE(skb)
  125. #define PKTCSETLEN(skb, l) BCM_REFERENCE(skb)
  126. #define PKTCADDLEN(skb, l) BCM_REFERENCE(skb)
  127. #define PKTCSETFLAG(skb, fb) BCM_REFERENCE(skb)
  128. #define PKTCCLRFLAG(skb, fb) BCM_REFERENCE(skb)
  129. #define PKTCLINK(skb) NULL
  130. #define PKTSETCLINK(skb, x) BCM_REFERENCE(skb)
  131. #define FOREACH_CHAINED_PKT(skb, nskb) \
  132. for ((nskb) = NULL; (skb) != NULL; (skb) = (nskb))
  133. #define PKTCFREE PKTFREE
  134. #define PKTCENQTAIL(h, t, p) \
  135. do { \
  136. if ((t) == NULL) { \
  137. (h) = (t) = (p); \
  138. } \
  139. } while (0)
  140. #endif // endif
  141. #ifndef PKTSETCHAINED
  142. #define PKTSETCHAINED(osh, skb) BCM_REFERENCE(osh)
  143. #endif // endif
  144. #ifndef PKTCLRCHAINED
  145. #define PKTCLRCHAINED(osh, skb) BCM_REFERENCE(osh)
  146. #endif // endif
  147. #ifndef PKTISCHAINED
  148. #define PKTISCHAINED(skb) FALSE
  149. #endif // endif
  150. /* Lbuf with fraglist */
  151. #ifndef PKTFRAGPKTID
  152. #define PKTFRAGPKTID(osh, lb) (0)
  153. #endif // endif
  154. #ifndef PKTSETFRAGPKTID
  155. #define PKTSETFRAGPKTID(osh, lb, id) BCM_REFERENCE(osh)
  156. #endif // endif
  157. #ifndef PKTFRAGTOTNUM
  158. #define PKTFRAGTOTNUM(osh, lb) (0)
  159. #endif // endif
  160. #ifndef PKTSETFRAGTOTNUM
  161. #define PKTSETFRAGTOTNUM(osh, lb, tot) BCM_REFERENCE(osh)
  162. #endif // endif
  163. #ifndef PKTFRAGTOTLEN
  164. #define PKTFRAGTOTLEN(osh, lb) (0)
  165. #endif // endif
  166. #ifndef PKTSETFRAGTOTLEN
  167. #define PKTSETFRAGTOTLEN(osh, lb, len) BCM_REFERENCE(osh)
  168. #endif // endif
  169. #ifndef PKTIFINDEX
  170. #define PKTIFINDEX(osh, lb) (0)
  171. #endif // endif
  172. #ifndef PKTSETIFINDEX
  173. #define PKTSETIFINDEX(osh, lb, idx) BCM_REFERENCE(osh)
  174. #endif // endif
  175. #ifndef PKTGETLF
  176. #define PKTGETLF(osh, len, send, lbuf_type) (0)
  177. #endif // endif
  178. /* in rx path, reuse totlen as used len */
  179. #ifndef PKTFRAGUSEDLEN
  180. #define PKTFRAGUSEDLEN(osh, lb) (0)
  181. #endif // endif
  182. #ifndef PKTSETFRAGUSEDLEN
  183. #define PKTSETFRAGUSEDLEN(osh, lb, len) BCM_REFERENCE(osh)
  184. #endif // endif
  185. #ifndef PKTFRAGLEN
  186. #define PKTFRAGLEN(osh, lb, ix) (0)
  187. #endif // endif
  188. #ifndef PKTSETFRAGLEN
  189. #define PKTSETFRAGLEN(osh, lb, ix, len) BCM_REFERENCE(osh)
  190. #endif // endif
  191. #ifndef PKTFRAGDATA_LO
  192. #define PKTFRAGDATA_LO(osh, lb, ix) (0)
  193. #endif // endif
  194. #ifndef PKTSETFRAGDATA_LO
  195. #define PKTSETFRAGDATA_LO(osh, lb, ix, addr) BCM_REFERENCE(osh)
  196. #endif // endif
  197. #ifndef PKTFRAGDATA_HI
  198. #define PKTFRAGDATA_HI(osh, lb, ix) (0)
  199. #endif // endif
  200. #ifndef PKTSETFRAGDATA_HI
  201. #define PKTSETFRAGDATA_HI(osh, lb, ix, addr) BCM_REFERENCE(osh)
  202. #endif // endif
  203. /* RX FRAG */
  204. #ifndef PKTISRXFRAG
  205. #define PKTISRXFRAG(osh, lb) (0)
  206. #endif // endif
  207. #ifndef PKTSETRXFRAG
  208. #define PKTSETRXFRAG(osh, lb) BCM_REFERENCE(osh)
  209. #endif // endif
  210. #ifndef PKTRESETRXFRAG
  211. #define PKTRESETRXFRAG(osh, lb) BCM_REFERENCE(osh)
  212. #endif // endif
  213. /* TX FRAG */
  214. #ifndef PKTISTXFRAG
  215. #define PKTISTXFRAG(osh, lb) (0)
  216. #endif // endif
  217. #ifndef PKTSETTXFRAG
  218. #define PKTSETTXFRAG(osh, lb) BCM_REFERENCE(osh)
  219. #endif // endif
  220. /* Need Rx completion used for AMPDU reordering */
  221. #ifndef PKTNEEDRXCPL
  222. #define PKTNEEDRXCPL(osh, lb) (TRUE)
  223. #endif // endif
  224. #ifndef PKTSETNORXCPL
  225. #define PKTSETNORXCPL(osh, lb) BCM_REFERENCE(osh)
  226. #endif // endif
  227. #ifndef PKTRESETNORXCPL
  228. #define PKTRESETNORXCPL(osh, lb) BCM_REFERENCE(osh)
  229. #endif // endif
  230. #ifndef PKTISFRAG
  231. #define PKTISFRAG(osh, lb) (0)
  232. #endif // endif
  233. #ifndef PKTFRAGISCHAINED
  234. #define PKTFRAGISCHAINED(osh, i) (0)
  235. #endif // endif
  236. /* TRIM Tail bytes from lfrag */
  237. #ifndef PKTFRAG_TRIM_TAILBYTES
  238. #define PKTFRAG_TRIM_TAILBYTES(osh, p, len, type) PKTSETLEN(osh, p, PKTLEN(osh, p) - len)
  239. #endif // endif
  240. #ifndef PKTISHDRCONVTD
  241. #define PKTISHDRCONVTD(osh, lb) (0)
  242. #endif // endif
  243. /* Forwarded pkt indication */
  244. #ifndef PKTISFRWDPKT
  245. #define PKTISFRWDPKT(osh, lb) 0
  246. #endif // endif
  247. #ifndef PKTSETFRWDPKT
  248. #define PKTSETFRWDPKT(osh, lb) BCM_REFERENCE(osh)
  249. #endif // endif
  250. #ifndef PKTRESETFRWDPKT
  251. #define PKTRESETFRWDPKT(osh, lb) BCM_REFERENCE(osh)
  252. #endif // endif
  253. /* SFD Frame */
  254. #ifndef PKTISSFDFRAME
  255. #define PKTISSFDFRAME(osh, lb) (0)
  256. #endif // endif
  257. #ifndef PKTSETSFDFRAME
  258. #define PKTSETSFDFRAME(osh, lb) BCM_REFERENCE(osh)
  259. #endif // endif
  260. #ifndef PKTRESETSFDFRAME
  261. #define PKTRESETSFDFRAME(osh, lb) BCM_REFERENCE(osh)
  262. #endif // endif
  263. #ifndef PKTISSFDTXC
  264. #define PKTISSFDTXC(osh, lb) (0)
  265. #endif // endif
  266. #ifndef PKTSETSFDTXC
  267. #define PKTSETSFDTXC(osh, lb) BCM_REFERENCE(osh)
  268. #endif // endif
  269. #ifndef PKTRESETSFDTXC
  270. #define PKTRESETSFDTXC(osh, lb) BCM_REFERENCE(osh)
  271. #endif // endif
  272. #ifdef BCM_SECURE_DMA
  273. #define SECURE_DMA_ENAB(osh) (1)
  274. #else
  275. #define SECURE_DMA_ENAB(osh) (0)
  276. #ifndef BCMDMA64OSL
  277. #define SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) ((dmaaddr_t) ((0)))
  278. #else
  279. #define SECURE_DMA_MAP(osh, va, size, direction, p, dmah, pcma, offset) \
  280. ((dmaaddr_t) {.hiaddr = 0, .loaddr = 0})
  281. #endif // endif
  282. #define SECURE_DMA_DD_MAP(osh, va, size, direction, p, dmah) 0
  283. #ifndef BCMDMA64OSL
  284. #define SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) ((dmaaddr_t) ((0)))
  285. #else
  286. #define SECURE_DMA_MAP_TXMETA(osh, va, size, direction, p, dmah, pcma) \
  287. ((dmaaddr_t) {.hiaddr = 0, .loaddr = 0})
  288. #endif // endif
  289. #define SECURE_DMA_UNMAP(osh, pa, size, direction, p, dmah, pcma, offset)
  290. #define SECURE_DMA_UNMAP_ALL(osh, pcma)
  291. #endif /* BCMDMA64OSL */
  292. #ifndef ROMMABLE_ASSERT
  293. #define ROMMABLE_ASSERT(exp) ASSERT(exp)
  294. #endif /* ROMMABLE_ASSERT */
  295. #ifndef MALLOC_NOPERSIST
  296. #define MALLOC_NOPERSIST MALLOC
  297. #endif /* !MALLOC_NOPERSIST */
  298. #ifndef MALLOC_PERSIST
  299. #define MALLOC_PERSIST MALLOC
  300. #endif /* !MALLOC_PERSIST */
  301. #ifndef MALLOC_NOPERSIST
  302. #define MALLOC_NOPERSIST MALLOC
  303. #endif /* !MALLOC_NOPERSIST */
  304. #ifndef MALLOC_PERSIST_ATTACH
  305. #define MALLOC_PERSIST_ATTACH MALLOC
  306. #endif /* !MALLOC_PERSIST_ATTACH */
  307. #ifndef MALLOCZ_PERSIST_ATTACH
  308. #define MALLOCZ_PERSIST_ATTACH MALLOCZ
  309. #endif /* !MALLOCZ_PERSIST_ATTACH */
  310. #ifndef MALLOCZ_NOPERSIST
  311. #define MALLOCZ_NOPERSIST MALLOCZ
  312. #endif /* !MALLOCZ_NOPERSIST */
  313. #ifndef MALLOCZ_PERSIST
  314. #define MALLOCZ_PERSIST MALLOCZ
  315. #endif /* !MALLOCZ_PERSIST */
  316. #ifndef MFREE_PERSIST
  317. #define MFREE_PERSIST MFREE
  318. #endif /* !MFREE_PERSIST */
  319. #ifndef MALLOC_SET_NOPERSIST
  320. #define MALLOC_SET_NOPERSIST(osh) do { } while (0)
  321. #endif /* !MALLOC_SET_NOPERSIST */
  322. #ifndef MALLOC_CLEAR_NOPERSIST
  323. #define MALLOC_CLEAR_NOPERSIST(osh) do { } while (0)
  324. #endif /* !MALLOC_CLEAR_NOPERSIST */
  325. #if defined(OSL_MEMCHECK)
  326. #define MEMCHECK(f, l) osl_memcheck(f, l)
  327. #else
  328. #define MEMCHECK(f, l)
  329. #endif /* OSL_MEMCHECK */
  330. #endif /* _osl_h_ */