2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/netdevice.h>
20 #include <linux/module.h>
22 #include <brcmu_utils.h>
24 MODULE_AUTHOR("Broadcom Corporation");
25 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver utilities.");
26 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
27 MODULE_LICENSE("Dual BSD/GPL");
29 struct sk_buff
*brcmu_pkt_buf_get_skb(uint len
)
33 skb
= dev_alloc_skb(len
);
41 EXPORT_SYMBOL(brcmu_pkt_buf_get_skb
);
43 /* Free the driver packet. Free the tag if present */
44 void brcmu_pkt_buf_free_skb(struct sk_buff
*skb
)
50 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if
53 dev_kfree_skb_any(skb
);
55 /* can free immediately (even in_irq()) if destructor
60 EXPORT_SYMBOL(brcmu_pkt_buf_free_skb
);
63 * osl multiple-precedence packet queue
64 * hi_prec is always >= the number of the highest non-empty precedence
66 struct sk_buff
*brcmu_pktq_penq(struct pktq
*pq
, int prec
,
69 struct sk_buff_head
*q
;
71 if (pktq_full(pq
) || pktq_pfull(pq
, prec
))
74 q
= &pq
->q
[prec
].skblist
;
78 if (pq
->hi_prec
< prec
)
79 pq
->hi_prec
= (u8
) prec
;
83 EXPORT_SYMBOL(brcmu_pktq_penq
);
85 struct sk_buff
*brcmu_pktq_penq_head(struct pktq
*pq
, int prec
,
88 struct sk_buff_head
*q
;
90 if (pktq_full(pq
) || pktq_pfull(pq
, prec
))
93 q
= &pq
->q
[prec
].skblist
;
97 if (pq
->hi_prec
< prec
)
98 pq
->hi_prec
= (u8
) prec
;
102 EXPORT_SYMBOL(brcmu_pktq_penq_head
);
104 struct sk_buff
*brcmu_pktq_pdeq(struct pktq
*pq
, int prec
)
106 struct sk_buff_head
*q
;
109 q
= &pq
->q
[prec
].skblist
;
117 EXPORT_SYMBOL(brcmu_pktq_pdeq
);
119 struct sk_buff
*brcmu_pktq_pdeq_tail(struct pktq
*pq
, int prec
)
121 struct sk_buff_head
*q
;
124 q
= &pq
->q
[prec
].skblist
;
125 p
= skb_dequeue_tail(q
);
132 EXPORT_SYMBOL(brcmu_pktq_pdeq_tail
);
135 brcmu_pktq_pflush(struct pktq
*pq
, int prec
, bool dir
,
136 bool (*fn
)(struct sk_buff
*, void *), void *arg
)
138 struct sk_buff_head
*q
;
139 struct sk_buff
*p
, *next
;
141 q
= &pq
->q
[prec
].skblist
;
142 skb_queue_walk_safe(q
, p
, next
) {
143 if (fn
== NULL
|| (*fn
) (p
, arg
)) {
145 brcmu_pkt_buf_free_skb(p
);
150 EXPORT_SYMBOL(brcmu_pktq_pflush
);
152 void brcmu_pktq_flush(struct pktq
*pq
, bool dir
,
153 bool (*fn
)(struct sk_buff
*, void *), void *arg
)
156 for (prec
= 0; prec
< pq
->num_prec
; prec
++)
157 brcmu_pktq_pflush(pq
, prec
, dir
, fn
, arg
);
159 EXPORT_SYMBOL(brcmu_pktq_flush
);
161 void brcmu_pktq_init(struct pktq
*pq
, int num_prec
, int max_len
)
165 /* pq is variable size; only zero out what's requested */
167 offsetof(struct pktq
, q
) + (sizeof(struct pktq_prec
) * num_prec
));
169 pq
->num_prec
= (u16
) num_prec
;
171 pq
->max
= (u16
) max_len
;
173 for (prec
= 0; prec
< num_prec
; prec
++) {
174 pq
->q
[prec
].max
= pq
->max
;
175 skb_queue_head_init(&pq
->q
[prec
].skblist
);
178 EXPORT_SYMBOL(brcmu_pktq_init
);
180 struct sk_buff
*brcmu_pktq_peek_tail(struct pktq
*pq
, int *prec_out
)
187 for (prec
= 0; prec
< pq
->hi_prec
; prec
++)
188 if (!skb_queue_empty(&pq
->q
[prec
].skblist
))
194 return skb_peek_tail(&pq
->q
[prec
].skblist
);
196 EXPORT_SYMBOL(brcmu_pktq_peek_tail
);
198 /* Return sum of lengths of a specific set of precedences */
199 int brcmu_pktq_mlen(struct pktq
*pq
, uint prec_bmp
)
205 for (prec
= 0; prec
<= pq
->hi_prec
; prec
++)
206 if (prec_bmp
& (1 << prec
))
207 len
+= pq
->q
[prec
].skblist
.qlen
;
211 EXPORT_SYMBOL(brcmu_pktq_mlen
);
213 /* Priority dequeue from a specific set of precedences */
214 struct sk_buff
*brcmu_pktq_mdeq(struct pktq
*pq
, uint prec_bmp
,
217 struct sk_buff_head
*q
;
224 while ((prec
= pq
->hi_prec
) > 0 &&
225 skb_queue_empty(&pq
->q
[prec
].skblist
))
228 while ((prec_bmp
& (1 << prec
)) == 0 ||
229 skb_queue_empty(&pq
->q
[prec
].skblist
))
233 q
= &pq
->q
[prec
].skblist
;
245 EXPORT_SYMBOL(brcmu_pktq_mdeq
);
248 /* pretty hex print a pkt buffer chain */
249 void brcmu_prpkt(const char *msg
, struct sk_buff
*p0
)
253 if (msg
&& (msg
[0] != '\0'))
254 pr_debug("%s:\n", msg
);
256 for (p
= p0
; p
; p
= p
->next
)
257 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, p
->data
, p
->len
);
259 EXPORT_SYMBOL(brcmu_prpkt
);
261 void brcmu_dbg_hex_dump(const void *data
, size_t size
, const char *fmt
, ...)
263 struct va_format vaf
;
271 pr_debug("%pV", &vaf
);
275 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, data
, size
);
277 EXPORT_SYMBOL(brcmu_dbg_hex_dump
);
278 #endif /* defined(DEBUG) */