Home | History | Annotate | Download | only in include
      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.8 2010/04/26 05:42:18 Exp $
     25  */
     26 
     27 
     28 #ifndef _linux_osl_h_
     29 #define _linux_osl_h_
     30 
     31 #include <typedefs.h>
     32 
     33 
     34 #include <linuxver.h>
     35 
     36 
     37 #ifdef __GNUC__
     38 #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
     39 #if GCC_VERSION > 30100
     40 #define	ASSERT(exp)		do {} while (0)
     41 #else
     42 
     43 #define	ASSERT(exp)
     44 #endif
     45 #endif
     46 
     47 
     48 #define	OSL_DELAY(usec)		osl_delay(usec)
     49 extern void osl_delay(uint usec);
     50 
     51 
     52 
     53 #define	OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
     54 	osl_pcmcia_read_attr((osh), (offset), (buf), (size))
     55 #define	OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
     56 	osl_pcmcia_write_attr((osh), (offset), (buf), (size))
     57 extern void osl_pcmcia_read_attr(osl_t *osh, uint offset, void *buf, int size);
     58 extern void osl_pcmcia_write_attr(osl_t *osh, uint offset, void *buf, int size);
     59 
     60 
     61 #define	OSL_PCI_READ_CONFIG(osh, offset, size) \
     62 	osl_pci_read_config((osh), (offset), (size))
     63 #define	OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
     64 	osl_pci_write_config((osh), (offset), (size), (val))
     65 extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
     66 extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
     67 
     68 
     69 #define OSL_PCI_BUS(osh)	osl_pci_bus(osh)
     70 #define OSL_PCI_SLOT(osh)	osl_pci_slot(osh)
     71 extern uint osl_pci_bus(osl_t *osh);
     72 extern uint osl_pci_slot(osl_t *osh);
     73 
     74 
     75 typedef struct {
     76 	bool pkttag;
     77 	uint pktalloced;
     78 	bool mmbus;
     79 	pktfree_cb_fn_t tx_fn;
     80 	void *tx_ctx;
     81 } osl_pubinfo_t;
     82 
     83 
     84 extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
     85 extern void osl_detach(osl_t *osh);
     86 
     87 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
     88 	do { \
     89 	   ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn; \
     90 	   ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx; \
     91 	} while (0)
     92 
     93 
     94 #define BUS_SWAP32(v)		(v)
     95 
     96 
     97 #define	MALLOC(osh, size)	osl_malloc((osh), (size))
     98 #define	MFREE(osh, addr, size)	osl_mfree((osh), (addr), (size))
     99 #define MALLOCED(osh)		osl_malloced((osh))
    100 
    101 
    102 #define	MALLOC_FAILED(osh)	osl_malloc_failed((osh))
    103 
    104 extern void *osl_malloc(osl_t *osh, uint size);
    105 extern void osl_mfree(osl_t *osh, void *addr, uint size);
    106 extern uint osl_malloced(osl_t *osh);
    107 extern uint osl_malloc_failed(osl_t *osh);
    108 
    109 
    110 #define	DMA_CONSISTENT_ALIGN	PAGE_SIZE
    111 #define	DMA_ALLOC_CONSISTENT(osh, size, pap, dmah, alignbits) \
    112 	osl_dma_alloc_consistent((osh), (size), (pap))
    113 #define	DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
    114 	osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
    115 extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, ulong *pap);
    116 extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
    117 
    118 
    119 #define	DMA_TX	1
    120 #define	DMA_RX	2
    121 
    122 
    123 #define	DMA_MAP(osh, va, size, direction, p, dmah) \
    124 	osl_dma_map((osh), (va), (size), (direction))
    125 #define	DMA_UNMAP(osh, pa, size, direction, p, dmah) \
    126 	osl_dma_unmap((osh), (pa), (size), (direction))
    127 extern uint osl_dma_map(osl_t *osh, void *va, uint size, int direction);
    128 extern void osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction);
    129 
    130 
    131 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
    132 
    133 
    134 #include <bcmsdh.h>
    135 #define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(NULL, (uintptr)(r), sizeof(*(r)), (v)))
    136 #define OSL_READ_REG(osh, r) (bcmsdh_reg_read(NULL, (uintptr)(r), sizeof(*(r))))
    137 
    138 #define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
    139 	mmap_op else bus_op
    140 #define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
    141 	mmap_op : bus_op
    142 
    143 
    144 
    145 
    146 #ifndef printf
    147 #define	printf(fmt, args...)	printk(fmt, ## args)
    148 #endif
    149 #include <linux/kernel.h>
    150 #include <linux/string.h>
    151 
    152 
    153 #ifndef IL_BIGENDIAN
    154 #define R_REG(osh, r) (\
    155 	SELECT_BUS_READ(osh, sizeof(*(r)) == sizeof(uint8) ? readb((volatile uint8*)(r)) : \
    156 	sizeof(*(r)) == sizeof(uint16) ? readw((volatile uint16*)(r)) : \
    157 	readl((volatile uint32*)(r)), OSL_READ_REG(osh, r)) \
    158 )
    159 #define W_REG(osh, r, v) do { \
    160 	SELECT_BUS_WRITE(osh,  \
    161 		switch (sizeof(*(r))) { \
    162 			case sizeof(uint8):	writeb((uint8)(v), (volatile uint8*)(r)); break; \
    163 			case sizeof(uint16):	writew((uint16)(v), (volatile uint16*)(r)); break; \
    164 			case sizeof(uint32):	writel((uint32)(v), (volatile uint32*)(r)); break; \
    165 		}, \
    166 		(OSL_WRITE_REG(osh, r, v))); \
    167 	} while (0)
    168 #else
    169 #define R_REG(osh, r) (\
    170 	SELECT_BUS_READ(osh, \
    171 		({ \
    172 			__typeof(*(r)) __osl_v; \
    173 			switch (sizeof(*(r))) { \
    174 				case sizeof(uint8):	__osl_v = \
    175 					readb((volatile uint8*)((uintptr)(r)^3)); break; \
    176 				case sizeof(uint16):	__osl_v = \
    177 					readw((volatile uint16*)((uintptr)(r)^2)); break; \
    178 				case sizeof(uint32):	__osl_v = \
    179 					readl((volatile uint32*)(r)); break; \
    180 			} \
    181 			__osl_v; \
    182 		}), \
    183 		OSL_READ_REG(osh, r)) \
    184 )
    185 #define W_REG(osh, r, v) do { \
    186 	SELECT_BUS_WRITE(osh,  \
    187 		switch (sizeof(*(r))) { \
    188 			case sizeof(uint8):	writeb((uint8)(v), \
    189 					(volatile uint8*)((uintptr)(r)^3)); break; \
    190 			case sizeof(uint16):	writew((uint16)(v), \
    191 					(volatile uint16*)((uintptr)(r)^2)); break; \
    192 			case sizeof(uint32):	writel((uint32)(v), \
    193 					(volatile uint32*)(r)); break; \
    194 		}, \
    195 		(OSL_WRITE_REG(osh, r, v))); \
    196 	} while (0)
    197 #endif
    198 
    199 #define	AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
    200 #define	OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
    201 
    202 
    203 #define	bcopy(src, dst, len)	memcpy((dst), (src), (len))
    204 #define	bcmp(b1, b2, len)	memcmp((b1), (b2), (len))
    205 #define	bzero(b, len)		memset((b), '\0', (len))
    206 
    207 
    208 #define OSL_UNCACHED(va)	((void*)va)
    209 
    210 
    211 #if defined(__i386__)
    212 #define	OSL_GETCYCLES(x)	rdtscl((x))
    213 #else
    214 #define OSL_GETCYCLES(x)	((x) = 0)
    215 #endif
    216 
    217 
    218 #define	BUSPROBE(val, addr)	({ (val) = R_REG(NULL, (addr)); 0; })
    219 
    220 
    221 #if !defined(CONFIG_MMC_MSM7X00A)
    222 #define	REG_MAP(pa, size)	ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
    223 #else
    224 #define REG_MAP(pa, size)       (void *)(0)
    225 #endif
    226 #define	REG_UNMAP(va)		iounmap((va))
    227 
    228 
    229 #define	R_SM(r)			*(r)
    230 #define	W_SM(r, v)		(*(r) = (v))
    231 #define	BZERO_SM(r, len)	memset((r), '\0', (len))
    232 
    233 
    234 #define	PKTGET(osh, len, send)		osl_pktget((osh), (len))
    235 #define	PKTFREE(osh, skb, send)		osl_pktfree((osh), (skb), (send))
    236 #ifdef DHD_USE_STATIC_BUF
    237 #define	PKTGET_STATIC(osh, len, send)		osl_pktget_static((osh), (len))
    238 #define	PKTFREE_STATIC(osh, skb, send)		osl_pktfree_static((osh), (skb), (send))
    239 #endif
    240 #define	PKTDATA(osh, skb)		(((struct sk_buff*)(skb))->data)
    241 #define	PKTLEN(osh, skb)		(((struct sk_buff*)(skb))->len)
    242 #define PKTHEADROOM(osh, skb)		(PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
    243 #define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
    244 #define	PKTNEXT(osh, skb)		(((struct sk_buff*)(skb))->next)
    245 #define	PKTSETNEXT(osh, skb, x)		(((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
    246 #define	PKTSETLEN(osh, skb, len)	__skb_trim((struct sk_buff*)(skb), (len))
    247 #define	PKTPUSH(osh, skb, bytes)	skb_push((struct sk_buff*)(skb), (bytes))
    248 #define	PKTPULL(osh, skb, bytes)	skb_pull((struct sk_buff*)(skb), (bytes))
    249 #define	PKTDUP(osh, skb)		osl_pktdup((osh), (skb))
    250 #define	PKTTAG(skb)			((void*)(((struct sk_buff*)(skb))->cb))
    251 #define PKTALLOCED(osh)			((osl_pubinfo_t *)(osh))->pktalloced
    252 #define PKTSETPOOL(osh, skb, x, y)	do {} while (0)
    253 #define PKTPOOL(osh, skb)		FALSE
    254 #define PKTPOOLLEN(osh, pktp)		(0)
    255 #define PKTPOOLAVAIL(osh, pktp)		(0)
    256 #define PKTPOOLADD(osh, pktp, p)	BCME_ERROR
    257 #define PKTPOOLGET(osh, pktp)		NULL
    258 #define PKTLIST_DUMP(osh, buf)
    259 
    260 extern void *osl_pktget(osl_t *osh, uint len);
    261 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
    262 extern void *osl_pktget_static(osl_t *osh, uint len);
    263 extern void osl_pktfree_static(osl_t *osh, void *skb, bool send);
    264 extern void *osl_pktdup(osl_t *osh, void *skb);
    265 
    266 
    267 
    268 static INLINE void *
    269 osl_pkt_frmnative(osl_pubinfo_t *osh, struct sk_buff *skb)
    270 {
    271 	struct sk_buff *nskb;
    272 
    273 	if (osh->pkttag)
    274 		bzero((void*)skb->cb, OSL_PKTTAG_SZ);
    275 
    276 
    277 	for (nskb = skb; nskb; nskb = nskb->next) {
    278 		osh->pktalloced++;
    279 	}
    280 
    281 	return (void *)skb;
    282 }
    283 #define PKTFRMNATIVE(osh, skb)	osl_pkt_frmnative(((osl_pubinfo_t *)osh), (struct sk_buff*)(skb))
    284 
    285 
    286 static INLINE struct sk_buff *
    287 osl_pkt_tonative(osl_pubinfo_t *osh, void *pkt)
    288 {
    289 	struct sk_buff *nskb;
    290 
    291 	if (osh->pkttag)
    292 		bzero(((struct sk_buff*)pkt)->cb, OSL_PKTTAG_SZ);
    293 
    294 
    295 	for (nskb = (struct sk_buff *)pkt; nskb; nskb = nskb->next) {
    296 		osh->pktalloced--;
    297 	}
    298 
    299 	return (struct sk_buff *)pkt;
    300 }
    301 #define PKTTONATIVE(osh, pkt)		osl_pkt_tonative((osl_pubinfo_t *)(osh), (pkt))
    302 
    303 #define	PKTLINK(skb)			(((struct sk_buff*)(skb))->prev)
    304 #define	PKTSETLINK(skb, x)		(((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
    305 #define	PKTPRIO(skb)			(((struct sk_buff*)(skb))->priority)
    306 #define	PKTSETPRIO(skb, x)		(((struct sk_buff*)(skb))->priority = (x))
    307 #define PKTSUMNEEDED(skb)		(((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW)
    308 #define PKTSETSUMGOOD(skb, x)		(((struct sk_buff*)(skb))->ip_summed = \
    309 						((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
    310 
    311 #define PKTSHARED(skb)                  (((struct sk_buff*)(skb))->cloned)
    312 
    313 
    314 #define OSL_ERROR(bcmerror)	osl_error(bcmerror)
    315 extern int osl_error(int bcmerror);
    316 
    317 
    318 #define	PKTBUFSZ	2048
    319 
    320 
    321 #define OSL_SYSUPTIME()		((uint32)jiffies * (1000 / HZ))
    322 #endif
    323