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 #include <linux/netdevice.h>
18 #include <linux/module.h>
20 #include <brcmu_utils.h>
22 MODULE_AUTHOR("Broadcom Corporation");
23 MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver utilities.");
24 MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
25 MODULE_LICENSE("Dual BSD/GPL");
27 struct sk_buff
*brcmu_pkt_buf_get_skb(uint len
)
31 skb
= dev_alloc_skb(len
);
39 EXPORT_SYMBOL(brcmu_pkt_buf_get_skb
);
41 /* Free the driver packet. Free the tag if present */
42 void brcmu_pkt_buf_free_skb(struct sk_buff
*skb
)
46 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if
49 dev_kfree_skb_any(skb
);
51 /* can free immediately (even in_irq()) if destructor
56 EXPORT_SYMBOL(brcmu_pkt_buf_free_skb
);
59 * osl multiple-precedence packet queue
60 * hi_prec is always >= the number of the highest non-empty precedence
62 struct sk_buff
*brcmu_pktq_penq(struct pktq
*pq
, int prec
,
65 struct sk_buff_head
*q
;
67 if (pktq_full(pq
) || pktq_pfull(pq
, prec
))
70 q
= &pq
->q
[prec
].skblist
;
74 if (pq
->hi_prec
< prec
)
75 pq
->hi_prec
= (u8
) prec
;
79 EXPORT_SYMBOL(brcmu_pktq_penq
);
81 struct sk_buff
*brcmu_pktq_penq_head(struct pktq
*pq
, int prec
,
84 struct sk_buff_head
*q
;
86 if (pktq_full(pq
) || pktq_pfull(pq
, prec
))
89 q
= &pq
->q
[prec
].skblist
;
93 if (pq
->hi_prec
< prec
)
94 pq
->hi_prec
= (u8
) prec
;
98 EXPORT_SYMBOL(brcmu_pktq_penq_head
);
100 struct sk_buff
*brcmu_pktq_pdeq(struct pktq
*pq
, int prec
)
102 struct sk_buff_head
*q
;
105 q
= &pq
->q
[prec
].skblist
;
113 EXPORT_SYMBOL(brcmu_pktq_pdeq
);
115 struct sk_buff
*brcmu_pktq_pdeq_tail(struct pktq
*pq
, int prec
)
117 struct sk_buff_head
*q
;
120 q
= &pq
->q
[prec
].skblist
;
121 p
= skb_dequeue_tail(q
);
128 EXPORT_SYMBOL(brcmu_pktq_pdeq_tail
);
131 brcmu_pktq_pflush(struct pktq
*pq
, int prec
, bool dir
,
132 bool (*fn
)(struct sk_buff
*, void *), void *arg
)
134 struct sk_buff_head
*q
;
135 struct sk_buff
*p
, *next
;
137 q
= &pq
->q
[prec
].skblist
;
138 skb_queue_walk_safe(q
, p
, next
) {
139 if (fn
== NULL
|| (*fn
) (p
, arg
)) {
141 brcmu_pkt_buf_free_skb(p
);
146 EXPORT_SYMBOL(brcmu_pktq_pflush
);
148 void brcmu_pktq_flush(struct pktq
*pq
, bool dir
,
149 bool (*fn
)(struct sk_buff
*, void *), void *arg
)
152 for (prec
= 0; prec
< pq
->num_prec
; prec
++)
153 brcmu_pktq_pflush(pq
, prec
, dir
, fn
, arg
);
155 EXPORT_SYMBOL(brcmu_pktq_flush
);
157 void brcmu_pktq_init(struct pktq
*pq
, int num_prec
, int max_len
)
161 /* pq is variable size; only zero out what's requested */
163 offsetof(struct pktq
, q
) + (sizeof(struct pktq_prec
) * num_prec
));
165 pq
->num_prec
= (u16
) num_prec
;
167 pq
->max
= (u16
) max_len
;
169 for (prec
= 0; prec
< num_prec
; prec
++) {
170 pq
->q
[prec
].max
= pq
->max
;
171 skb_queue_head_init(&pq
->q
[prec
].skblist
);
174 EXPORT_SYMBOL(brcmu_pktq_init
);
176 struct sk_buff
*brcmu_pktq_peek_tail(struct pktq
*pq
, int *prec_out
)
183 for (prec
= 0; prec
< pq
->hi_prec
; prec
++)
184 if (!skb_queue_empty(&pq
->q
[prec
].skblist
))
190 return skb_peek_tail(&pq
->q
[prec
].skblist
);
192 EXPORT_SYMBOL(brcmu_pktq_peek_tail
);
194 /* Return sum of lengths of a specific set of precedences */
195 int brcmu_pktq_mlen(struct pktq
*pq
, uint prec_bmp
)
201 for (prec
= 0; prec
<= pq
->hi_prec
; prec
++)
202 if (prec_bmp
& (1 << prec
))
203 len
+= pq
->q
[prec
].skblist
.qlen
;
207 EXPORT_SYMBOL(brcmu_pktq_mlen
);
209 /* Priority dequeue from a specific set of precedences */
210 struct sk_buff
*brcmu_pktq_mdeq(struct pktq
*pq
, uint prec_bmp
,
213 struct sk_buff_head
*q
;
220 while ((prec
= pq
->hi_prec
) > 0 &&
221 skb_queue_empty(&pq
->q
[prec
].skblist
))
224 while ((prec_bmp
& (1 << prec
)) == 0 ||
225 skb_queue_empty(&pq
->q
[prec
].skblist
))
229 q
= &pq
->q
[prec
].skblist
;
241 EXPORT_SYMBOL(brcmu_pktq_mdeq
);
244 /* pretty hex print a pkt buffer chain */
245 void brcmu_prpkt(const char *msg
, struct sk_buff
*p0
)
249 if (msg
&& (msg
[0] != '\0'))
250 printk(KERN_DEBUG
"%s:\n", msg
);
252 for (p
= p0
; p
; p
= p
->next
)
253 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET
, p
->data
, p
->len
);
255 EXPORT_SYMBOL(brcmu_prpkt
);
256 #endif /* defined(BCMDBG) */