• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Linux OS Independent Layer
3  *
4  * Copyright (C) 1999-2013, 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 411126 2013-07-05 01:22:09Z $
25  */
26 
27 #ifndef _linux_osl_h_
28 #define _linux_osl_h_
29 
30 #include <typedefs.h>
31 
32 /* Linux Kernel: File Operations: start */
33 extern void * osl_os_open_image(char * filename);
34 extern int osl_os_get_image_block(char * buf, int len, void * image);
35 extern void osl_os_close_image(void * image);
36 extern int osl_os_image_size(void *image);
37 /* Linux Kernel: File Operations: end */
38 
39 #ifdef BCMDRIVER
40 
41 /* OSL initialization */
42 extern osl_t *osl_attach(void *pdev, uint bustype, bool pkttag);
43 extern void osl_detach(osl_t *osh);
44 
45 /* Global ASSERT type */
46 extern uint32 g_assert_type;
47 
48 /* ASSERT */
49 #if defined(BCMASSERT_LOG)
50 	#define ASSERT(exp) \
51 	  do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
52 extern void osl_assert(const char *exp, const char *file, int line);
53 #else
54 	#ifdef __GNUC__
55 		#define GCC_VERSION \
56 			(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
57 		#if GCC_VERSION > 30100
58 			#define ASSERT(exp)	do {} while (0)
59 		#else
60 			/* ASSERT could cause segmentation fault on GCC3.1, use empty instead */
61 			#define ASSERT(exp)
62 		#endif /* GCC_VERSION > 30100 */
63 	#endif /* __GNUC__ */
64 #endif
65 
66 /* microsecond delay */
67 #define	OSL_DELAY(usec)		osl_delay(usec)
68 extern void osl_delay(uint usec);
69 
70 #define OSL_SLEEP(ms)			osl_sleep(ms)
71 extern void osl_sleep(uint ms);
72 
73 #define	OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
74 	osl_pcmcia_read_attr((osh), (offset), (buf), (size))
75 #define	OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
76 	osl_pcmcia_write_attr((osh), (offset), (buf), (size))
77 extern void osl_pcmcia_read_attr(osl_t *osh, uint offset, void *buf, int size);
78 extern void osl_pcmcia_write_attr(osl_t *osh, uint offset, void *buf, int size);
79 
80 /* PCI configuration space access macros */
81 #define	OSL_PCI_READ_CONFIG(osh, offset, size) \
82 	osl_pci_read_config((osh), (offset), (size))
83 #define	OSL_PCI_WRITE_CONFIG(osh, offset, size, val) \
84 	osl_pci_write_config((osh), (offset), (size), (val))
85 extern uint32 osl_pci_read_config(osl_t *osh, uint offset, uint size);
86 extern void osl_pci_write_config(osl_t *osh, uint offset, uint size, uint val);
87 
88 /* PCI device bus # and slot # */
89 #define OSL_PCI_BUS(osh)	osl_pci_bus(osh)
90 #define OSL_PCI_SLOT(osh)	osl_pci_slot(osh)
91 extern uint osl_pci_bus(osl_t *osh);
92 extern uint osl_pci_slot(osl_t *osh);
93 extern struct pci_dev *osl_pci_device(osl_t *osh);
94 
95 /* Pkttag flag should be part of public information */
96 typedef struct {
97 	bool pkttag;
98 	bool mmbus;		/* Bus supports memory-mapped register accesses */
99 	pktfree_cb_fn_t tx_fn;  /* Callback function for PKTFREE */
100 	void *tx_ctx;		/* Context to the callback function */
101 	void	*unused[3];
102 } osl_pubinfo_t;
103 
104 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx)		\
105 	do {						\
106 	   ((osl_pubinfo_t*)osh)->tx_fn = _tx_fn;	\
107 	   ((osl_pubinfo_t*)osh)->tx_ctx = _tx_ctx;	\
108 	} while (0)
109 
110 
111 /* host/bus architecture-specific byte swap */
112 #define BUS_SWAP32(v)		(v)
113 
114 	#define MALLOC(osh, size)	osl_malloc((osh), (size))
115 	#define MFREE(osh, addr, size)	osl_mfree((osh), (addr), (size))
116 	#define MALLOCED(osh)		osl_malloced((osh))
117 	extern void *osl_malloc(osl_t *osh, uint size);
118 	extern void osl_mfree(osl_t *osh, void *addr, uint size);
119 	extern uint osl_malloced(osl_t *osh);
120 
121 #define NATIVE_MALLOC(osh, size)		kmalloc(size, GFP_ATOMIC)
122 #define NATIVE_MFREE(osh, addr, size)	kfree(addr)
123 
124 #define	MALLOC_FAILED(osh)	osl_malloc_failed((osh))
125 extern uint osl_malloc_failed(osl_t *osh);
126 
127 /* allocate/free shared (dma-able) consistent memory */
128 #define	DMA_CONSISTENT_ALIGN	osl_dma_consistent_align()
129 #define	DMA_ALLOC_CONSISTENT(osh, size, align, tot, pap, dmah) \
130 	osl_dma_alloc_consistent((osh), (size), (align), (tot), (pap))
131 #define	DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
132 	osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
133 extern uint osl_dma_consistent_align(void);
134 extern void *osl_dma_alloc_consistent(osl_t *osh, uint size, uint16 align, uint *tot, ulong *pap);
135 extern void osl_dma_free_consistent(osl_t *osh, void *va, uint size, ulong pa);
136 
137 /* map/unmap direction */
138 #define	DMA_TX	1	/* TX direction for DMA */
139 #define	DMA_RX	2	/* RX direction for DMA */
140 
141 /* map/unmap shared (dma-able) memory */
142 #define	DMA_UNMAP(osh, pa, size, direction, p, dmah) \
143 	osl_dma_unmap((osh), (pa), (size), (direction))
144 extern uint osl_dma_map(osl_t *osh, void *va, uint size, int direction, void *p,
145 	hnddma_seg_map_t *txp_dmah);
146 extern void osl_dma_unmap(osl_t *osh, uint pa, uint size, int direction);
147 
148 /* API for DMA addressing capability */
149 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
150 
151 /* register access macros */
152 	#include <bcmsdh.h>
153 	#define OSL_WRITE_REG(osh, r, v) (bcmsdh_reg_write(NULL, (uintptr)(r), sizeof(*(r)), (v)))
154 	#define OSL_READ_REG(osh, r) (bcmsdh_reg_read(NULL, (uintptr)(r), sizeof(*(r))))
155 
156 	#define SELECT_BUS_WRITE(osh, mmap_op, bus_op) if (((osl_pubinfo_t*)(osh))->mmbus) \
157 		mmap_op else bus_op
158 	#define SELECT_BUS_READ(osh, mmap_op, bus_op) (((osl_pubinfo_t*)(osh))->mmbus) ? \
159 		mmap_op : bus_op
160 
161 #define OSL_ERROR(bcmerror)	osl_error(bcmerror)
162 extern int osl_error(int bcmerror);
163 
164 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
165 #define	PKTBUFSZ	2048   /* largest reasonable packet buffer, driver uses for ethernet MTU */
166 
167 /*
168  * BINOSL selects the slightly slower function-call-based binary compatible osl.
169  * Macros expand to calls to functions defined in linux_osl.c .
170  */
171 #include <linuxver.h>           /* use current 2.4.x calling conventions */
172 #include <linux/kernel.h>       /* for vsn/printf's */
173 #include <linux/string.h>       /* for mem*, str* */
174 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 29)
175 #define OSL_SYSUPTIME()		((uint32)jiffies_to_msecs(jiffies))
176 #else
177 #define OSL_SYSUPTIME()		((uint32)jiffies * (1000 / HZ))
178 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 29) */
179 #define	printf(fmt, args...)	printk(fmt , ## args)
180 #include <linux/kernel.h>	/* for vsn/printf's */
181 #include <linux/string.h>	/* for mem*, str* */
182 /* bcopy's: Linux kernel doesn't provide these (anymore) */
183 #define	bcopy(src, dst, len)	memcpy((dst), (src), (len))
184 #define	bcmp(b1, b2, len)	memcmp((b1), (b2), (len))
185 #define	bzero(b, len)		memset((b), '\0', (len))
186 
187 /* register access macros */
188 
189 #define R_REG(osh, r) (\
190 	SELECT_BUS_READ(osh, \
191 		({ \
192 			__typeof(*(r)) __osl_v; \
193 			BCM_REFERENCE(osh);	\
194 			switch (sizeof(*(r))) { \
195 				case sizeof(uint8):	__osl_v = \
196 					readb((volatile uint8*)(r)); break; \
197 				case sizeof(uint16):	__osl_v = \
198 					readw((volatile uint16*)(r)); break; \
199 				case sizeof(uint32):	__osl_v = \
200 					readl((volatile uint32*)(r)); break; \
201 			} \
202 			__osl_v; \
203 		}), \
204 		OSL_READ_REG(osh, r)) \
205 )
206 
207 #define W_REG(osh, r, v) do { \
208 	BCM_REFERENCE(osh);   \
209 	SELECT_BUS_WRITE(osh, \
210 		switch (sizeof(*(r))) { \
211 			case sizeof(uint8):	writeb((uint8)(v), (volatile uint8*)(r)); break; \
212 			case sizeof(uint16):	writew((uint16)(v), (volatile uint16*)(r)); break; \
213 			case sizeof(uint32):	writel((uint32)(v), (volatile uint32*)(r)); break; \
214 		}, \
215 		(OSL_WRITE_REG(osh, r, v))); \
216 	} while (0)
217 
218 #define	AND_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) & (v))
219 #define	OR_REG(osh, r, v)		W_REG(osh, (r), R_REG(osh, r) | (v))
220 
221 /* bcopy, bcmp, and bzero functions */
222 #define	bcopy(src, dst, len)	memcpy((dst), (src), (len))
223 #define	bcmp(b1, b2, len)	memcmp((b1), (b2), (len))
224 #define	bzero(b, len)		memset((b), '\0', (len))
225 
226 /* uncached/cached virtual address */
227 #define OSL_UNCACHED(va)	((void *)va)
228 #define OSL_CACHED(va)		((void *)va)
229 
230 /* ARM NorthStar */
231 #define OSL_CACHE_FLUSH(va, len)
232 
233 #define OSL_PREF_RANGE_LD(va, sz)
234 #define OSL_PREF_RANGE_ST(va, sz)
235 
236 /* get processor cycle count */
237 #if defined(__i386__)
238 #define	OSL_GETCYCLES(x)	rdtscl((x))
239 #else
240 #define OSL_GETCYCLES(x)	((x) = 0)
241 #endif
242 
243 /* dereference an address that may cause a bus exception */
244 #define	BUSPROBE(val, addr)	({ (val) = R_REG(NULL, (addr)); 0; })
245 
246 /* map/unmap physical to virtual I/O */
247 #if !defined(CONFIG_MMC_MSM7X00A)
248 #define	REG_MAP(pa, size)	ioremap_nocache((unsigned long)(pa), (unsigned long)(size))
249 #else
250 #define REG_MAP(pa, size)       (void *)(0)
251 #endif /* !defined(CONFIG_MMC_MSM7X00A */
252 #define	REG_UNMAP(va)		iounmap((va))
253 
254 /* shared (dma-able) memory access macros */
255 #define	R_SM(r)			*(r)
256 #define	W_SM(r, v)		(*(r) = (v))
257 #define	BZERO_SM(r, len)	memset((r), '\0', (len))
258 
259 /* Because the non BINOSL implemenation of the PKT OSL routines are macros (for
260  * performance reasons),  we need the Linux headers.
261  */
262 #include <linuxver.h>		/* use current 2.4.x calling conventions */
263 
264 /* packet primitives */
265 #ifdef BCMDBG_CTRACE
266 #define	PKTGET(osh, len, send)		osl_pktget((osh), (len), __LINE__, __FILE__)
267 #define	PKTDUP(osh, skb)		osl_pktdup((osh), (skb), __LINE__, __FILE__)
268 #else
269 #define	PKTGET(osh, len, send)		osl_pktget((osh), (len))
270 #define	PKTDUP(osh, skb)		osl_pktdup((osh), (skb))
271 #endif /* BCMDBG_CTRACE */
272 #define PKTLIST_DUMP(osh, buf)
273 #define PKTDBG_TRACE(osh, pkt, bit)
274 #define	PKTFREE(osh, skb, send)		osl_pktfree((osh), (skb), (send))
275 #ifdef CONFIG_DHD_USE_STATIC_BUF
276 #define	PKTGET_STATIC(osh, len, send)		osl_pktget_static((osh), (len))
277 #define	PKTFREE_STATIC(osh, skb, send)		osl_pktfree_static((osh), (skb), (send))
278 #else
279 #define	PKTGET_STATIC	PKTGET
280 #define	PKTFREE_STATIC	PKTFREE
281 #endif /* CONFIG_DHD_USE_STATIC_BUF */
282 #define	PKTDATA(osh, skb)		(((struct sk_buff*)(skb))->data)
283 #define	PKTLEN(osh, skb)		(((struct sk_buff*)(skb))->len)
284 #define PKTHEADROOM(osh, skb)		(PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
285 #define PKTTAILROOM(osh, skb)		skb_tailroom((struct sk_buff*)(skb))
286 #define PKTPADTAILROOM(osh, skb, padlen)		osh_pktpadtailroom((osh), (skb), (padlen))
287 #define	PKTNEXT(osh, skb)		(((struct sk_buff*)(skb))->next)
288 #define	PKTSETNEXT(osh, skb, x)		(((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
289 #define	PKTSETLEN(osh, skb, len)	__skb_trim((struct sk_buff*)(skb), (len))
290 #define	PKTPUSH(osh, skb, bytes)	skb_push((struct sk_buff*)(skb), (bytes))
291 #define	PKTPULL(osh, skb, bytes)	skb_pull((struct sk_buff*)(skb), (bytes))
292 #define	PKTTAG(skb)			((void*)(((struct sk_buff*)(skb))->cb))
293 #define PKTSETPOOL(osh, skb, x, y)	do {} while (0)
294 #define PKTPOOL(osh, skb)		FALSE
295 #define PKTSHRINK(osh, m)		(m)
296 
297 #ifdef BCMDBG_CTRACE
298 #define	DEL_CTRACE(zosh, zskb) { \
299 	unsigned long zflags; \
300 	spin_lock_irqsave(&(zosh)->ctrace_lock, zflags); \
301 	list_del(&(zskb)->ctrace_list); \
302 	(zosh)->ctrace_num--; \
303 	(zskb)->ctrace_start = 0; \
304 	(zskb)->ctrace_count = 0; \
305 	spin_unlock_irqrestore(&(zosh)->ctrace_lock, zflags); \
306 }
307 
308 #define	UPDATE_CTRACE(zskb, zfile, zline) { \
309 	struct sk_buff *_zskb = (struct sk_buff *)(zskb); \
310 	if (_zskb->ctrace_count < CTRACE_NUM) { \
311 		_zskb->func[_zskb->ctrace_count] = zfile; \
312 		_zskb->line[_zskb->ctrace_count] = zline; \
313 		_zskb->ctrace_count++; \
314 	} \
315 	else { \
316 		_zskb->func[_zskb->ctrace_start] = zfile; \
317 		_zskb->line[_zskb->ctrace_start] = zline; \
318 		_zskb->ctrace_start++; \
319 		if (_zskb->ctrace_start >= CTRACE_NUM) \
320 			_zskb->ctrace_start = 0; \
321 	} \
322 }
323 
324 #define	ADD_CTRACE(zosh, zskb, zfile, zline) { \
325 	unsigned long zflags; \
326 	spin_lock_irqsave(&(zosh)->ctrace_lock, zflags); \
327 	list_add(&(zskb)->ctrace_list, &(zosh)->ctrace_list); \
328 	(zosh)->ctrace_num++; \
329 	UPDATE_CTRACE(zskb, zfile, zline); \
330 	spin_unlock_irqrestore(&(zosh)->ctrace_lock, zflags); \
331 }
332 
333 #define PKTCALLER(zskb)	UPDATE_CTRACE((struct sk_buff *)zskb, (char *)__FUNCTION__, __LINE__)
334 #endif /* BCMDBG_CTRACE */
335 
336 #ifdef CTFPOOL
337 #define	CTFPOOL_REFILL_THRESH	3
338 typedef struct ctfpool {
339 	void		*head;
340 	spinlock_t	lock;
341 	uint		max_obj;
342 	uint		curr_obj;
343 	uint		obj_size;
344 	uint		refills;
345 	uint		fast_allocs;
346 	uint 		fast_frees;
347 	uint 		slow_allocs;
348 } ctfpool_t;
349 
350 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
351 #define	FASTBUF	(1 << 0)
352 #define	PKTSETFAST(osh, skb)	((((struct sk_buff*)(skb))->pktc_flags) |= FASTBUF)
353 #define	PKTCLRFAST(osh, skb)	((((struct sk_buff*)(skb))->pktc_flags) &= (~FASTBUF))
354 #define	PKTISFAST(osh, skb)	((((struct sk_buff*)(skb))->pktc_flags) & FASTBUF)
355 #define	PKTFAST(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags)
356 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
357 #define	FASTBUF	(1 << 16)
358 #define	PKTSETFAST(osh, skb)	((((struct sk_buff*)(skb))->mac_len) |= FASTBUF)
359 #define	PKTCLRFAST(osh, skb)	((((struct sk_buff*)(skb))->mac_len) &= (~FASTBUF))
360 #define	PKTISFAST(osh, skb)	((((struct sk_buff*)(skb))->mac_len) & FASTBUF)
361 #define	PKTFAST(osh, skb)	(((struct sk_buff*)(skb))->mac_len)
362 #else
363 #define	FASTBUF	(1 << 0)
364 #define	PKTSETFAST(osh, skb)	((((struct sk_buff*)(skb))->__unused) |= FASTBUF)
365 #define	PKTCLRFAST(osh, skb)	((((struct sk_buff*)(skb))->__unused) &= (~FASTBUF))
366 #define	PKTISFAST(osh, skb)	((((struct sk_buff*)(skb))->__unused) & FASTBUF)
367 #define	PKTFAST(osh, skb)	(((struct sk_buff*)(skb))->__unused)
368 #endif /* 2.6.22 */
369 
370 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
371 #define	CTFPOOLPTR(osh, skb)	(((struct sk_buff*)(skb))->ctfpool)
372 #define	CTFPOOLHEAD(osh, skb)	(((ctfpool_t *)((struct sk_buff*)(skb))->ctfpool)->head)
373 #else
374 #define	CTFPOOLPTR(osh, skb)	(((struct sk_buff*)(skb))->sk)
375 #define	CTFPOOLHEAD(osh, skb)	(((ctfpool_t *)((struct sk_buff*)(skb))->sk)->head)
376 #endif
377 
378 extern void *osl_ctfpool_add(osl_t *osh);
379 extern void osl_ctfpool_replenish(osl_t *osh, uint thresh);
380 extern int32 osl_ctfpool_init(osl_t *osh, uint numobj, uint size);
381 extern void osl_ctfpool_cleanup(osl_t *osh);
382 extern void osl_ctfpool_stats(osl_t *osh, void *b);
383 #else /* CTFPOOL */
384 #define	PKTSETFAST(osh, skb)
385 #define	PKTCLRFAST(osh, skb)
386 #define	PKTISFAST(osh, skb)	(FALSE)
387 #endif /* CTFPOOL */
388 
389 #define	PKTSETCTF(osh, skb)
390 #define	PKTCLRCTF(osh, skb)
391 #define	PKTISCTF(osh, skb)	(FALSE)
392 
393 #ifdef HNDCTF
394 
395 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
396 #define	SKIPCT	(1 << 2)
397 #define	CHAINED	(1 << 3)
398 #define	PKTSETSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags |= SKIPCT)
399 #define	PKTCLRSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags &= (~SKIPCT))
400 #define	PKTSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags & SKIPCT)
401 #define	PKTSETCHAINED(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags |= CHAINED)
402 #define	PKTCLRCHAINED(osh, skb)	(((struct sk_buff*)(skb))->pktc_flags &= (~CHAINED))
403 #define	PKTISCHAINED(skb)	(((struct sk_buff*)(skb))->pktc_flags & CHAINED)
404 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
405 #define	SKIPCT	(1 << 18)
406 #define	CHAINED	(1 << 19)
407 #define	PKTSETSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len |= SKIPCT)
408 #define	PKTCLRSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len &= (~SKIPCT))
409 #define	PKTSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->mac_len & SKIPCT)
410 #define	PKTSETCHAINED(osh, skb)	(((struct sk_buff*)(skb))->mac_len |= CHAINED)
411 #define	PKTCLRCHAINED(osh, skb)	(((struct sk_buff*)(skb))->mac_len &= (~CHAINED))
412 #define	PKTISCHAINED(skb)	(((struct sk_buff*)(skb))->mac_len & CHAINED)
413 #else /* 2.6.22 */
414 #define	SKIPCT	(1 << 2)
415 #define	CHAINED	(1 << 3)
416 #define	PKTSETSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused |= SKIPCT)
417 #define	PKTCLRSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused &= (~SKIPCT))
418 #define	PKTSKIPCT(osh, skb)	(((struct sk_buff*)(skb))->__unused & SKIPCT)
419 #define	PKTSETCHAINED(osh, skb)	(((struct sk_buff*)(skb))->__unused |= CHAINED)
420 #define	PKTCLRCHAINED(osh, skb)	(((struct sk_buff*)(skb))->__unused &= (~CHAINED))
421 #define	PKTISCHAINED(skb)	(((struct sk_buff*)(skb))->__unused & CHAINED)
422 #endif /* 2.6.22 */
423 typedef struct ctf_mark {
424 	uint32	value;
425 }	ctf_mark_t;
426 #define CTF_MARK(m)				(m.value)
427 #else /* HNDCTF */
428 #define	PKTSETSKIPCT(osh, skb)
429 #define	PKTCLRSKIPCT(osh, skb)
430 #define	PKTSKIPCT(osh, skb)
431 #define CTF_MARK(m)				0
432 #endif /* HNDCTF */
433 
434 extern void osl_pktfree(osl_t *osh, void *skb, bool send);
435 extern void *osl_pktget_static(osl_t *osh, uint len);
436 extern void osl_pktfree_static(osl_t *osh, void *skb, bool send);
437 extern int osh_pktpadtailroom(osl_t *osh, void* skb, int pad);
438 
439 #ifdef BCMDBG_CTRACE
440 #define PKT_CTRACE_DUMP(osh, b)	osl_ctrace_dump((osh), (b))
441 extern void *osl_pktget(osl_t *osh, uint len, int line, char *file);
442 extern void *osl_pkt_frmnative(osl_t *osh, void *skb, int line, char *file);
443 extern int osl_pkt_is_frmnative(osl_t *osh, struct sk_buff *pkt);
444 extern void *osl_pktdup(osl_t *osh, void *skb, int line, char *file);
445 struct bcmstrbuf;
446 extern void osl_ctrace_dump(osl_t *osh, struct bcmstrbuf *b);
447 #else
448 extern void *osl_pkt_frmnative(osl_t *osh, void *skb);
449 extern void *osl_pktget(osl_t *osh, uint len);
450 extern void *osl_pktdup(osl_t *osh, void *skb);
451 #endif /* BCMDBG_CTRACE */
452 extern struct sk_buff *osl_pkt_tonative(osl_t *osh, void *pkt);
453 #ifdef BCMDBG_CTRACE
454 #define PKTFRMNATIVE(osh, skb)  osl_pkt_frmnative(((osl_t *)osh), \
455 				(struct sk_buff*)(skb), __LINE__, __FILE__)
456 #define	PKTISFRMNATIVE(osh, skb) osl_pkt_is_frmnative((osl_t *)(osh), (struct sk_buff *)(skb))
457 #else
458 #define PKTFRMNATIVE(osh, skb)	osl_pkt_frmnative(((osl_t *)osh), (struct sk_buff*)(skb))
459 #endif /* BCMDBG_CTRACE */
460 #define PKTTONATIVE(osh, pkt)		osl_pkt_tonative((osl_t *)(osh), (pkt))
461 
462 #define	PKTLINK(skb)			(((struct sk_buff*)(skb))->prev)
463 #define	PKTSETLINK(skb, x)		(((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
464 #define	PKTPRIO(skb)			(((struct sk_buff*)(skb))->priority)
465 #define	PKTSETPRIO(skb, x)		(((struct sk_buff*)(skb))->priority = (x))
466 #define PKTSUMNEEDED(skb)		(((struct sk_buff*)(skb))->ip_summed == CHECKSUM_HW)
467 #define PKTSETSUMGOOD(skb, x)		(((struct sk_buff*)(skb))->ip_summed = \
468 						((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
469 /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because skb->ip_summed is overloaded */
470 #define PKTSHARED(skb)                  (((struct sk_buff*)(skb))->cloned)
471 
472 #ifdef CONFIG_NF_CONNTRACK_MARK
473 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0))
474 #define PKTMARK(p)                     (((struct sk_buff *)(p))->mark)
475 #define PKTSETMARK(p, m)               ((struct sk_buff *)(p))->mark = (m)
476 #else /* !2.6.0 */
477 #define PKTMARK(p)                     (((struct sk_buff *)(p))->nfmark)
478 #define PKTSETMARK(p, m)               ((struct sk_buff *)(p))->nfmark = (m)
479 #endif /* 2.6.0 */
480 #else /* CONFIG_NF_CONNTRACK_MARK */
481 #define PKTMARK(p)                     0
482 #define PKTSETMARK(p, m)
483 #endif /* CONFIG_NF_CONNTRACK_MARK */
484 
485 #define PKTALLOCED(osh)		osl_pktalloced(osh)
486 extern uint osl_pktalloced(osl_t *osh);
487 
488 #define	DMA_MAP(osh, va, size, direction, p, dmah) \
489 	osl_dma_map((osh), (va), (size), (direction), (p), (dmah))
490 
491 #ifdef PKTC
492 /* Use 8 bytes of skb tstamp field to store below info */
493 struct chain_node {
494 	struct sk_buff	*link;
495 	unsigned int	flags:3, pkts:9, bytes:20;
496 };
497 
498 #define CHAIN_NODE(skb)		((struct chain_node*)(((struct sk_buff*)skb)->pktc_cb))
499 
500 #define	PKTCSETATTR(s, f, p, b)	({CHAIN_NODE(s)->flags = (f); CHAIN_NODE(s)->pkts = (p); \
501 	                         CHAIN_NODE(s)->bytes = (b);})
502 #define	PKTCCLRATTR(s)		({CHAIN_NODE(s)->flags = CHAIN_NODE(s)->pkts = \
503 	                         CHAIN_NODE(s)->bytes = 0;})
504 #define	PKTCGETATTR(s)		(CHAIN_NODE(s)->flags << 29 | CHAIN_NODE(s)->pkts << 20 | \
505 	                         CHAIN_NODE(s)->bytes)
506 #define	PKTCCNT(skb)		(CHAIN_NODE(skb)->pkts)
507 #define	PKTCLEN(skb)		(CHAIN_NODE(skb)->bytes)
508 #define	PKTCGETFLAGS(skb)	(CHAIN_NODE(skb)->flags)
509 #define	PKTCSETFLAGS(skb, f)	(CHAIN_NODE(skb)->flags = (f))
510 #define	PKTCCLRFLAGS(skb)	(CHAIN_NODE(skb)->flags = 0)
511 #define	PKTCFLAGS(skb)		(CHAIN_NODE(skb)->flags)
512 #define	PKTCSETCNT(skb, c)	(CHAIN_NODE(skb)->pkts = (c))
513 #define	PKTCINCRCNT(skb)	(CHAIN_NODE(skb)->pkts++)
514 #define	PKTCADDCNT(skb, c)	(CHAIN_NODE(skb)->pkts += (c))
515 #define	PKTCSETLEN(skb, l)	(CHAIN_NODE(skb)->bytes = (l))
516 #define	PKTCADDLEN(skb, l)	(CHAIN_NODE(skb)->bytes += (l))
517 #define	PKTCSETFLAG(skb, fb)	(CHAIN_NODE(skb)->flags |= (fb))
518 #define	PKTCCLRFLAG(skb, fb)	(CHAIN_NODE(skb)->flags &= ~(fb))
519 #define	PKTCLINK(skb)		(CHAIN_NODE(skb)->link)
520 #define	PKTSETCLINK(skb, x)	(CHAIN_NODE(skb)->link = (struct sk_buff*)(x))
521 #define FOREACH_CHAINED_PKT(skb, nskb) \
522 	for (; (skb) != NULL; (skb) = (nskb)) \
523 		if ((nskb) = (PKTISCHAINED(skb) ? PKTCLINK(skb) : NULL), \
524 		    PKTSETCLINK((skb), NULL), 1)
525 #define	PKTCFREE(osh, skb, send) \
526 do { \
527 	void *nskb; \
528 	ASSERT((skb) != NULL); \
529 	FOREACH_CHAINED_PKT((skb), nskb) { \
530 		PKTCLRCHAINED((osh), (skb)); \
531 		PKTCCLRFLAGS((skb)); \
532 		PKTFREE((osh), (skb), (send)); \
533 	} \
534 } while (0)
535 #define PKTCENQTAIL(h, t, p) \
536 do { \
537 	if ((t) == NULL) { \
538 		(h) = (t) = (p); \
539 	} else { \
540 		PKTSETCLINK((t), (p)); \
541 		(t) = (p); \
542 	} \
543 } while (0)
544 #endif /* PKTC */
545 
546 #else /* ! BCMDRIVER */
547 
548 
549 /* ASSERT */
550 	#define ASSERT(exp)	do {} while (0)
551 
552 /* MALLOC and MFREE */
553 #define MALLOC(o, l) malloc(l)
554 #define MFREE(o, p, l) free(p)
555 #include <stdlib.h>
556 
557 /* str* and mem* functions */
558 #include <string.h>
559 
560 /* *printf functions */
561 #include <stdio.h>
562 
563 /* bcopy, bcmp, and bzero */
564 extern void bcopy(const void *src, void *dst, size_t len);
565 extern int bcmp(const void *b1, const void *b2, size_t len);
566 extern void bzero(void *b, size_t len);
567 #endif /* ! BCMDRIVER */
568 
569 #endif	/* _linux_osl_h_ */
570