PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/bcm4319/include/linux_osl.h

https://github.com/defer/kernel_zte_blade
C Header | 327 lines | 218 code | 84 blank | 25 comment | 20 complexity | 206b938452251722733370cc14e07c40 MD5 | raw file
  1. /*
  2. * Linux OS Independent Layer
  3. *
  4. * Copyright (C) 1999-2010, Broadcom Corporation
  5. *
  6. * Unless you and Broadcom execute a separate written software license
  7. * agreement governing use of this software, this software is licensed to you
  8. * under the terms of the GNU General Public License version 2 (the "GPL"),
  9. * available at http://www.broadcom.com/licenses/GPLv2.php, with the
  10. * following added to such license:
  11. *
  12. * As a special exception, the copyright holders of this software give you
  13. * permission to link this software with independent modules, and to copy and
  14. * distribute the resulting executable under terms of your choice, provided that
  15. * you also meet, for each linked independent module, the terms and conditions of
  16. * the license of that module. An independent module is a module which is not
  17. * derived from this software. The special exception does not apply to any
  18. * modifications of the software.
  19. *
  20. * Notwithstanding the above, under no circumstances may you combine this
  21. * software in any way with any other Broadcom software provided under a license
  22. * other than the GPL, without Broadcom's express prior written consent.
  23. *
  24. * $Id: linux_osl.h,v 13.131.30.7 2010/03/29 19:03:11 Exp $
  25. */
  26. #ifndef _linux_osl_h_
  27. #define _linux_osl_h_
  28. #include <typedefs.h>
  29. #include <linuxver.h>
  30. #ifdef __GNUC__
  31. #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
  32. #if GCC_VERSION > 30100
  33. #define ASSERT(exp) do {} while (0)
  34. #else
  35. #define ASSERT(exp)
  36. #endif
  37. #endif
  38. #define OSL_DELAY(usec) osl_delay(usec)
  39. extern void osl_delay(uint usec);
  40. #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
  41. osl_pcmcia_read_attr((osh), (offset), (buf), (size))
  42. #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
  43. osl_pcmcia_write_attr((osh), (offset), (buf), (size))
  44. extern void osl_pcmcia_read_attr(osl_t *osh, uint offset, void *buf, int size);
  45. extern void osl_pcmcia_write_attr(osl_t *osh, uint offset, void *buf, int size);
  46. #define OSL_PCI_READ_CONFIG(osh, offset, size) \
  47. osl_pci_read_config((osh), (offset), (size))
  48. #define OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
  49. osl_pci_write_config((osh), (offset), (size), (val))
  50. extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
  51. extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
  52. #define OSL_PCI_BUS(osh) osl_pci_bus(osh)
  53. #define OSL_PCI_SLOT(osh) osl_pci_slot(osh)
  54. extern uint osl_pci_bus(osl_t *osh);
  55. extern uint osl_pci_slot(osl_t *osh);
  56. typedef struct {
  57. bool pkttag;
  58. uint pktalloced;
  59. bool mmbus;
  60. pktfree_cb_fn_t tx_fn;
  61. void *tx_ctx;
  62. } osl_pubinfo_t;
  63. extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
  64. extern void osl_detach(osl_t *osh);
  65. #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
  66. do { \
  67. ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn; \
  68. ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx; \
  69. } while (0)
  70. #define BUS_SWAP32(v) (v)
  71. #define MALLOC(osh, size) osl_malloc((osh), (size))
  72. #define MFREE(osh, addr, size) osl_mfree((osh), (addr), (size))
  73. #define MALLOCED(osh) osl_malloced((osh))
  74. #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
  75. extern void *osl_malloc(osl_t *osh, uint size);
  76. extern void osl_mfree(osl_t *osh, void *addr, uint size);
  77. extern uint osl_malloced(osl_t *osh);
  78. extern uint osl_malloc_failed(osl_t *osh);
  79. #define DMA_CONSISTENT_ALIGN PAGE_SIZE
  80. #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah, alignbits) \
  81. osl_dma_alloc_consistent((osh), (size), (pap))
  82. #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
  83. osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
  84. extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap);
  85. extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
  86. #define DMA_TX 1
  87. #define DMA_RX 2
  88. #define DMA_MAP(osh, va, size, direction, p, dmah) \
  89. osl_dma_map((osh), (va), (size), (direction))
  90. #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
  91. osl_dma_unmap((osh), (pa), (size), (direction))
  92. extern uint osl_dma_map(osl_t *osh, void *va, uint size, int direction);
  93. extern void osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction);
  94. #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
  95. #include <bcmsdh.h>
  96. #define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(NULL, (uintptr)(r), sizeof(*(r)), (v)))
  97. #define OSL_READ_REG(osh, r) (bcmsdh_reg_read(NULL, (uintptr)(r), sizeof(*(r))))
  98. #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
  99. mmap_op else bus_op
  100. #define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
  101. mmap_op : bus_op
  102. #ifndef printf
  103. #define printf(fmt, args...) printk(fmt, ## args)
  104. #endif
  105. #include <linux/kernel.h>
  106. #include <linux/string.h>
  107. #ifndef IL_BIGENDIAN
  108. #define R_REG(osh, r) (\
  109. SELECT_BUS_READ(osh, sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
  110. sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
  111. readl((volatile uint32*)(r)), OSL_READ_REG(osh, r)) \
  112. )
  113. #define W_REG(osh, r, v) do { \
  114. SELECT_BUS_WRITE(osh, \
  115. switch (sizeof(*(r))) { \
  116. case sizeof(uint8): writeb((uint8)(v), (volatile uint8*)(r)); break; \
  117. case sizeof(uint16): writew((uint16)(v), (volatile uint16*)(r)); break; \
  118. case sizeof(uint32): writel((uint32)(v), (volatile uint32*)(r)); break; \
  119. }, \
  120. (OSL_WRITE_REG(osh, r, v))); \
  121. } while (0)
  122. #else
  123. #define R_REG(osh, r) (\
  124. SELECT_BUS_READ(osh, \
  125. ({ \
  126. __typeof(*(r)) __osl_v; \
  127. switch (sizeof(*(r))) { \
  128. case sizeof(uint8): __osl_v = \
  129. readb((volatile uint8*)((uintptr)(r)^3)); break; \
  130. case sizeof(uint16): __osl_v = \
  131. readw((volatile uint16*)((uintptr)(r)^2)); break; \
  132. case sizeof(uint32): __osl_v = \
  133. readl((volatile uint32*)(r)); break; \
  134. } \
  135. __osl_v; \
  136. }), \
  137. OSL_READ_REG(osh, r)) \
  138. )
  139. #define W_REG(osh, r, v) do { \
  140. SELECT_BUS_WRITE(osh, \
  141. switch (sizeof(*(r))) { \
  142. case sizeof(uint8): writeb((uint8)(v), \
  143. (volatile uint8*)((uintptr)(r)^3)); break; \
  144. case sizeof(uint16): writew((uint16)(v), \
  145. (volatile uint16*)((uintptr)(r)^2)); break; \
  146. case sizeof(uint32): writel((uint32)(v), \
  147. (volatile uint32*)(r)); break; \
  148. }, \
  149. (OSL_WRITE_REG(osh, r, v))); \
  150. } while (0)
  151. #endif
  152. #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
  153. #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
  154. #define bcopy(src, dst, len) memcpy((dst), (src), (len))
  155. #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
  156. #define bzero(b, len) memset((b), '\0', (len))
  157. #define OSL_UNCACHED(va) ((void*)va)
  158. #if defined(__i386__)
  159. #define OSL_GETCYCLES(x) rdtscl((x))
  160. #else
  161. #define OSL_GETCYCLES(x) ((x) = 0)
  162. #endif
  163. #define BUSPROBE(val, addr) ({ (val) = R_REG(NULL, (addr)); 0; })
  164. #if !defined(CONFIG_MMC_MSM7X00A)
  165. #define REG_MAP(pa, size) ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
  166. #else
  167. #define REG_MAP(pa, size) (void *)(0)
  168. #endif
  169. #define REG_UNMAP(va) iounmap((va))
  170. #define R_SM(r) *(r)
  171. #define W_SM(r, v) (*(r) = (v))
  172. #define BZERO_SM(r, len) memset((r), '\0', (len))
  173. #define PKTGET(osh, len, send) osl_pktget((osh), (len))
  174. #define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
  175. #ifdef DHD_USE_STATIC_BUF
  176. #define PKTGET_STATIC(osh, len, send) osl_pktget_static((osh), (len))
  177. #define PKTFREE_STATIC(osh, skb, send) osl_pktfree_static((osh), (skb), (send))
  178. #endif
  179. #define PKTDATA(osh, skb) (((struct sk_buff*)(skb))->data)
  180. #define PKTLEN(osh, skb) (((struct sk_buff*)(skb))->len)
  181. #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
  182. #define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
  183. #define PKTNEXT(osh, skb) (((struct sk_buff*)(skb))->next)
  184. #define PKTSETNEXT(osh, skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
  185. #define PKTSETLEN(osh, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
  186. #define PKTPUSH(osh, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
  187. #define PKTPULL(osh, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
  188. #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
  189. #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb))
  190. #define PKTALLOCED(osh) ((osl_pubinfo_t *)(osh))->pktalloced
  191. #define PKTSETPOOL(osh, skb, x, y) do {} while (0)
  192. #define PKTPOOL(osh, skb) FALSE
  193. #define PKTPOOLLEN(osh, pktp) (0)
  194. #define PKTPOOLAVAIL(osh, pktp) (0)
  195. #define PKTPOOLADD(osh, pktp, p) BCME_ERROR
  196. #define PKTPOOLGET(osh, pktp) NULL
  197. #define PKTLIST_DUMP(osh, buf)
  198. extern void *osl_pktget(osl_t *osh, uint len);
  199. extern void osl_pktfree(osl_t *osh, void *skb, bool send);
  200. extern void *osl_pktget_static(osl_t *osh, uint len);
  201. extern void osl_pktfree_static(osl_t *osh, void *skb, bool send);
  202. extern void *osl_pktdup(osl_t *osh, void *skb);
  203. static INLINE void *
  204. osl_pkt_frmnative(osl_pubinfo_t *osh, struct sk_buff *skb)
  205. {
  206. struct sk_buff *nskb;
  207. if (osh->pkttag)
  208. bzero((void*)skb->cb, OSL_PKTTAG_SZ);
  209. for (nskb = skb; nskb; nskb = nskb->next) {
  210. osh->pktalloced++;
  211. }
  212. return (void *)skb;
  213. }
  214. #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_pubinfo_t *)osh), (struct sk_buff*)(skb))
  215. static INLINE struct sk_buff *
  216. osl_pkt_tonative(osl_pubinfo_t *osh, void *pkt)
  217. {
  218. struct sk_buff *nskb;
  219. if (osh->pkttag)
  220. bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
  221. for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
  222. osh->pktalloced--;
  223. }
  224. return (struct sk_buff *)pkt;
  225. }
  226. #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_pubinfo_t *)(osh), (pkt))
  227. #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
  228. #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
  229. #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
  230. #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
  231. #define PKTSUMNEEDED(skb) (((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW)
  232. #define PKTSETSUMGOOD(skb, x) (((struct sk_buff*)(skb))->ip_summed = \
  233. ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
  234. #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned)
  235. #define OSL_ERROR(bcmerror) osl_error(bcmerror)
  236. extern int osl_error(int bcmerror);
  237. #define PKTBUFSZ 2048
  238. #define OSL_SYSUPTIME() ((uint32)jiffies * (1000 / HZ))
  239. #define FILE void
  240. #define F_OPEN(fp, mode) NULL
  241. #define F_WRITE(buf, w_size, len, fp) do { } while (0)
  242. #define F_CLOSE(fp) do { } while (0)
  243. #endif