2 * Linux OS Independent Layer
4 * Copyright 2006, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: linux_osl.h,v 1.1.1.13 2006/04/08 06:13:39 honor Exp $
22 #define OSL_PKTTAG_SZ 32 /* Size of PktTag */
24 /* osl handle type forward declaration */
25 typedef struct osl_dmainfo osldma_t
;
27 /* OSL initialization */
28 extern osl_t
*osl_attach(void *pdev
, bool pkttag
);
29 extern void osl_detach(osl_t
*osh
);
31 /* host/bus architecture-specific byte swap */
32 #define BUS_SWAP32(v) (v)
33 #define MALLOC_FAILED(osh) osl_malloc_failed((osh))
35 extern void *osl_malloc(osl_t
*osh
, uint size
);
36 extern void osl_mfree(osl_t
*osh
, void *addr
, uint size
);
37 extern uint
osl_malloced(osl_t
*osh
);
38 extern uint
osl_malloc_failed(osl_t
*osh
);
40 /* API for DMA addressing capability */
41 #define DMA_MAP(osh, va, size, direction, p) \
42 osl_dma_map((osh), (va), (size), (direction))
43 #define DMA_UNMAP(osh, pa, size, direction, p) \
44 osl_dma_unmap((osh), (pa), (size), (direction))
46 osl_dma_map(void *osh
, void *va
, uint size
, int direction
)
51 dev
= (osh
== NULL
? NULL
: ((osl_t
*)osh
)->pdev
);
52 dir
= (direction
== DMA_TX
)? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
;
53 return (pci_map_single(dev
, va
, size
, dir
));
57 osl_dma_unmap(void *osh
, uint pa
, uint size
, int direction
)
62 dev
= (osh
== NULL
? NULL
: ((osl_t
*)osh
)->pdev
);
63 dir
= (direction
== DMA_TX
)? PCI_DMA_TODEVICE
: PCI_DMA_FROMDEVICE
;
64 pci_unmap_single(dev
, (uint32
)pa
, size
, dir
);
67 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
68 #define DMA_CONSISTENT_ALIGN PAGE_SIZE
69 #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah) \
70 osl_dma_alloc_consistent((osh), (size), (pap))
71 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
72 osl_dma_free_consistent((osh), (void*)(va), (size), (pa))
74 osl_dma_alloc_consistent(osl_t
*osh
, uint size
, ulong
*pap
)
76 return (pci_alloc_consistent(osh
->pdev
, size
, (dma_addr_t
*)pap
));
80 osl_dma_free_consistent(osl_t
*osh
, void *va
, uint size
, ulong pa
)
82 pci_free_consistent(osh
->pdev
, size
, va
, (dma_addr_t
)pa
);
86 /* register access macros */
89 #define R_REG(osh, r) bcmjtag_read(NULL, (uint32)(r), sizeof(*(r)))
90 #define W_REG(osh, r, v) bcmjtag_write(NULL, (uint32)(r), (uint32)(v), sizeof(*(r)))
91 #endif /* defined(BCMSDIO) */
93 /* packet primitives */
94 #define PKTGET(osh, len, send) osl_pktget((osh), (len), (send))
95 #define PKTFREE(osh, skb, send) osl_pktfree((osh), (skb), (send))
96 #define PKTDATA(osh, skb) (((struct sk_buff*)(skb))->data)
97 #define PKTLEN(osh, skb) (((struct sk_buff*)(skb))->len)
98 #define PKTHEADROOM(osh, skb) (PKTDATA(osh, skb)-(((struct sk_buff*)(skb))->head))
99 #define PKTTAILROOM(osh, skb) ((((struct sk_buff*)(skb))->end)-(((struct sk_buff*)(skb))->tail))
100 #define PKTNEXT(osh, skb) (((struct sk_buff*)(skb))->next)
101 #define PKTSETNEXT(osh, skb, x) (((struct sk_buff*)(skb))->next = (struct sk_buff*)(x))
102 #define PKTSETLEN(osh, skb, len) __skb_trim((struct sk_buff*)(skb), (len))
103 #define PKTPUSH(osh, skb, bytes) skb_push((struct sk_buff*)(skb), (bytes))
104 #define PKTPULL(osh, skb, bytes) skb_pull((struct sk_buff*)(skb), (bytes))
105 #define PKTDUP(osh, skb) osl_pktdup((osh), (skb))
106 #define PKTTAG(skb) ((void*)(((struct sk_buff*)(skb))->cb))
107 #define PKTALLOCED(osh) osl_pktalloced((osh))
108 #define PKTLIST_DUMP(osh, buf)
110 /* Convert a native(OS) packet to driver packet.
111 * In the process, native packet is destroyed, there is no copying
112 * Also, a packettag is zeroed out
115 osl_pkt_frmnative(osl_pubinfo_t
*osh
, struct sk_buff
*skb
)
117 struct sk_buff
*nskb
;
120 bzero((void*)skb
->cb
, OSL_PKTTAG_SZ
);
122 /* Increment the packet counter */
123 for (nskb
= skb
; nskb
; nskb
= nskb
->next
) {
129 #define PKTFRMNATIVE(osh, skb) osl_pkt_frmnative(((osl_pubinfo_t*)osh), \
130 (struct sk_buff*)(skb))
132 /* Convert a driver packet to native(OS) packet
133 * In the process, packettag is zeroed out before sending up
134 * IP code depends on skb->cb to be setup correctly with various options
135 * In our case, that means it should be 0
137 static INLINE
struct sk_buff
*
138 osl_pkt_tonative(osl_pubinfo_t
*osh
, void *pkt
)
140 struct sk_buff
*nskb
;
143 bzero(((struct sk_buff
*)pkt
)->cb
, OSL_PKTTAG_SZ
);
145 /* Decrement the packet counter */
146 for (nskb
= (struct sk_buff
*)pkt
; nskb
; nskb
= nskb
->next
) {
150 return (struct sk_buff
*)pkt
;
152 #define PKTTONATIVE(osh, pkt) osl_pkt_tonative((osl_pubinfo_t*)(osh), (pkt))
154 #define PKTLINK(skb) (((struct sk_buff*)(skb))->prev)
155 #define PKTSETLINK(skb, x) (((struct sk_buff*)(skb))->prev = (struct sk_buff*)(x))
156 #define PKTPRIO(skb) (((struct sk_buff*)(skb))->priority)
157 #define PKTSETPRIO(skb, x) (((struct sk_buff*)(skb))->priority = (x))
158 #define PKTSHARED(skb) (((struct sk_buff*)(skb))->cloned)
160 extern void *osl_pktget(osl_t
*osh
, uint len
, bool send
);
161 extern void osl_pktfree(osl_t
*osh
, void *skb
, bool send
);
162 extern void *osl_pktdup(osl_t
*osh
, void *skb
);
163 extern uint
osl_pktalloced(osl_t
*osh
);
165 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
166 extern int osl_error(int bcmerror
);
168 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
169 #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
171 #endif /* _linux_osl_h_ */
This page took 0.062928 seconds and 5 git commands to generate.