aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/bcm4329/bcmutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/bcm4329/bcmutils.c')
-rw-r--r--drivers/net/wireless/bcm4329/bcmutils.c1838
1 files changed, 1838 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcm4329/bcmutils.c b/drivers/net/wireless/bcm4329/bcmutils.c
new file mode 100644
index 00000000000..43c04ee92f3
--- /dev/null
+++ b/drivers/net/wireless/bcm4329/bcmutils.c
@@ -0,0 +1,1838 @@
1/*
2 * Driver O/S-independent utility routines
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 * $Id: bcmutils.c,v 1.210.4.5.2.4.6.19 2010/04/26 06:05:25 Exp $
24 */
25
26#include <typedefs.h>
27#include <bcmdefs.h>
28#include <stdarg.h>
29#include <bcmutils.h>
30#ifdef BCMDRIVER
31#include <osl.h>
32#include <siutils.h>
33#else
34#include <stdio.h>
35#include <string.h>
36/* This case for external supplicant use */
37#if defined(BCMEXTSUP)
38#include <bcm_osl.h>
39#endif
40
41#endif /* BCMDRIVER */
42#include <bcmendian.h>
43#include <bcmdevs.h>
44#include <proto/ethernet.h>
45#include <proto/vlan.h>
46#include <proto/bcmip.h>
47#include <proto/802.1d.h>
48#include <proto/802.11.h>
49
50
51#ifdef BCMDRIVER
52
53
54/* copy a pkt buffer chain into a buffer */
55uint
56pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf)
57{
58 uint n, ret = 0;
59
60 if (len < 0)
61 len = 4096; /* "infinite" */
62
63 /* skip 'offset' bytes */
64 for (; p && offset; p = PKTNEXT(osh, p)) {
65 if (offset < (uint)PKTLEN(osh, p))
66 break;
67 offset -= PKTLEN(osh, p);
68 }
69
70 if (!p)
71 return 0;
72
73 /* copy the data */
74 for (; p && len; p = PKTNEXT(osh, p)) {
75 n = MIN((uint)PKTLEN(osh, p) - offset, (uint)len);
76 bcopy(PKTDATA(osh, p) + offset, buf, n);
77 buf += n;
78 len -= n;
79 ret += n;
80 offset = 0;
81 }
82
83 return ret;
84}
85
86/* copy a buffer into a pkt buffer chain */
87uint
88pktfrombuf(osl_t *osh, void *p, uint offset, int len, uchar *buf)
89{
90 uint n, ret = 0;
91
92 /* skip 'offset' bytes */
93 for (; p && offset; p = PKTNEXT(osh, p)) {
94 if (offset < (uint)PKTLEN(osh, p))
95 break;
96 offset -= PKTLEN(osh, p);
97 }
98
99 if (!p)
100 return 0;
101
102 /* copy the data */
103 for (; p && len; p = PKTNEXT(osh, p)) {
104 n = MIN((uint)PKTLEN(osh, p) - offset, (uint)len);
105 bcopy(buf, PKTDATA(osh, p) + offset, n);
106 buf += n;
107 len -= n;
108 ret += n;
109 offset = 0;
110 }
111
112 return ret;
113}
114
115
116
117/* return total length of buffer chain */
118uint
119pkttotlen(osl_t *osh, void *p)
120{
121 uint total;
122
123 total = 0;
124 for (; p; p = PKTNEXT(osh, p))
125 total += PKTLEN(osh, p);
126 return (total);
127}
128
129/* return the last buffer of chained pkt */
130void *
131pktlast(osl_t *osh, void *p)
132{
133 for (; PKTNEXT(osh, p); p = PKTNEXT(osh, p))
134 ;
135
136 return (p);
137}
138
139/* count segments of a chained packet */
140uint
141pktsegcnt(osl_t *osh, void *p)
142{
143 uint cnt;
144
145 for (cnt = 0; p; p = PKTNEXT(osh, p))
146 cnt++;
147
148 return cnt;
149}
150
151
152/*
153 * osl multiple-precedence packet queue
154 * hi_prec is always >= the number of the highest non-empty precedence
155 */
156void *
157pktq_penq(struct pktq *pq, int prec, void *p)
158{
159 struct pktq_prec *q;
160
161 ASSERT(prec >= 0 && prec < pq->num_prec);
162 ASSERT(PKTLINK(p) == NULL); /* queueing chains not allowed */
163
164 ASSERT(!pktq_full(pq));
165 ASSERT(!pktq_pfull(pq, prec));
166
167 q = &pq->q[prec];
168
169 if (q->head)
170 PKTSETLINK(q->tail, p);
171 else
172 q->head = p;
173
174 q->tail = p;
175 q->len++;
176
177 pq->len++;
178
179 if (pq->hi_prec < prec)
180 pq->hi_prec = (uint8)prec;
181
182 return p;
183}
184
185void *
186pktq_penq_head(struct pktq *pq, int prec, void *p)
187{
188 struct pktq_prec *q;
189
190 ASSERT(prec >= 0 && prec < pq->num_prec);
191 ASSERT(PKTLINK(p) == NULL); /* queueing chains not allowed */
192
193 ASSERT(!pktq_full(pq));
194 ASSERT(!pktq_pfull(pq, prec));
195
196 q = &pq->q[prec];
197
198 if (q->head == NULL)
199 q->tail = p;
200
201 PKTSETLINK(p, q->head);
202 q->head = p;
203 q->len++;
204
205 pq->len++;
206
207 if (pq->hi_prec < prec)
208 pq->hi_prec = (uint8)prec;
209
210 return p;
211}
212
213void *
214pktq_pdeq(struct pktq *pq, int prec)
215{
216