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.c,v 1.1.1.14 2006/04/08 06:13:39 honor Exp $
18 #include <bcmendian.h>
19 #include <linux/module.h>
23 #include "linux_osl.h"
25 #include <linux/delay.h>
27 #include <asm/paccess.h>
31 #define PCI_CFG_RETRY 10
33 #define OS_HANDLE_MAGIC 0x1234abcd /* Magic # to recognise osh */
34 #define BCM_MEM_FILENAME_LEN 24 /* Mem. filename length */
36 typedef struct bcm_mem_link
{
37 struct bcm_mem_link
*prev
;
38 struct bcm_mem_link
*next
;
41 char file
[BCM_MEM_FILENAME_LEN
];
44 static int16 linuxbcmerrormap
[] = \
46 -EINVAL
, /* BCME_ERROR */
47 -EINVAL
, /* BCME_BADARG */
48 -EINVAL
, /* BCME_BADOPTION */
49 -EINVAL
, /* BCME_NOTUP */
50 -EINVAL
, /* BCME_NOTDOWN */
51 -EINVAL
, /* BCME_NOTAP */
52 -EINVAL
, /* BCME_NOTSTA */
53 -EINVAL
, /* BCME_BADKEYIDX */
54 -EINVAL
, /* BCME_RADIOOFF */
55 -EINVAL
, /* BCME_NOTBANDLOCKED */
56 -EINVAL
, /* BCME_NOCLK */
57 -EINVAL
, /* BCME_BADRATESET */
58 -EINVAL
, /* BCME_BADBAND */
59 -E2BIG
, /* BCME_BUFTOOSHORT */
60 -E2BIG
, /* BCME_BUFTOOLONG */
61 -EBUSY
, /* BCME_BUSY */
62 -EINVAL
, /* BCME_NOTASSOCIATED */
63 -EINVAL
, /* BCME_BADSSIDLEN */
64 -EINVAL
, /* BCME_OUTOFRANGECHAN */
65 -EINVAL
, /* BCME_BADCHAN */
66 -EFAULT
, /* BCME_BADADDR */
67 -ENOMEM
, /* BCME_NORESOURCE */
68 -EOPNOTSUPP
, /* BCME_UNSUPPORTED */
69 -EMSGSIZE
, /* BCME_BADLENGTH */
70 -EINVAL
, /* BCME_NOTREADY */
71 -EPERM
, /* BCME_NOTPERMITTED */
72 -ENOMEM
, /* BCME_NOMEM */
73 -EINVAL
, /* BCME_ASSOCIATED */
74 -ERANGE
, /* BCME_RANGE */
75 -EINVAL
, /* BCME_NOTFOUND */
76 -EINVAL
, /* BCME_WME_NOT_ENABLED */
77 -EINVAL
, /* BCME_TSPEC_NOTFOUND */
78 -EINVAL
, /* BCME_ACM_NOTSUPPORTED */
79 -EINVAL
, /* BCME_NOT_WME_ASSOCIATION */
80 -EIO
, /* BCME_SDIO_ERROR */
81 -ENODEV
/* BCME_DONGLE_DOWN */
84 /* translate bcmerrors into linux errors */
86 osl_error(int bcmerror
)
89 int array_size
= ARRAYSIZE(linuxbcmerrormap
);
91 abs_bcmerror
= ABS(bcmerror
);
96 else if (abs_bcmerror
>= array_size
)
97 abs_bcmerror
= BCME_ERROR
;
99 return linuxbcmerrormap
[abs_bcmerror
];
103 osl_attach(void *pdev
, bool pkttag
)
107 osh
= kmalloc(sizeof(osl_t
), GFP_ATOMIC
);
110 bzero(osh
, sizeof(osl_t
));
113 * check the cases where
114 * 1.Error code Added to bcmerror table, but forgot to add it to the OS
115 * dependent error code
116 * 2. Error code is added to the bcmerror table, but forgot to add the
117 * corresponding errorstring(dummy call to bcmerrorstr)
120 ASSERT(ABS(BCME_LAST
) == (ARRAYSIZE(linuxbcmerrormap
) - 1));
122 osh
->magic
= OS_HANDLE_MAGIC
;
125 osh
->dbgmem_list
= NULL
;
127 osh
->pub
.pkttag
= pkttag
;
133 osl_detach(osl_t
*osh
)
138 ASSERT(osh
->magic
== OS_HANDLE_MAGIC
);
142 /* Return a new packet. zero out pkttag */
144 osl_pktget(osl_t
*osh
, uint len
, bool send
)
148 if ((skb
= dev_alloc_skb(len
))) {
153 pktlist_add(&(osh
->pktlist
), (void *) skb
);
154 #endif /* BCMDBG_PKT */
156 osh
->pub
.pktalloced
++;
159 return ((void*) skb
);
162 /* Free the driver packet. Free the tag if present */
164 osl_pktfree(osl_t
*osh
, void *p
)
166 struct sk_buff
*skb
, *nskb
;
168 skb
= (struct sk_buff
*) p
;
170 /* perversion: we use skb->next to chain multi-skb packets */
176 pktlist_remove(&(osh
->pktlist
), (void *) skb
);
177 #endif /* BCMDBG_PKT */
179 if (skb
->destructor
) {
180 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if destructor exists
182 dev_kfree_skb_any(skb
);
184 /* can free immediately (even in_irq()) if destructor does not exist */
188 osh
->pub
.pktalloced
--;
195 osl_malloc(osl_t
*osh
, uint size
)
199 /* only ASSERT if osh is defined */
201 ASSERT(osh
->magic
== OS_HANDLE_MAGIC
);
203 if ((addr
= kmalloc(size
, GFP_ATOMIC
)) == NULL
) {
209 osh
->malloced
+= size
;
215 osl_mfree(osl_t
*osh
, void *addr
, uint size
)
218 ASSERT(osh
->magic
== OS_HANDLE_MAGIC
);
219 osh
->malloced
-= size
;
225 osl_malloced(osl_t
*osh
)
227 ASSERT((osh
&& (osh
->magic
== OS_HANDLE_MAGIC
)));
228 return (osh
->malloced
);
231 uint
osl_malloc_failed(osl_t
*osh
)
233 ASSERT((osh
&& (osh
->magic
== OS_HANDLE_MAGIC
)));
234 return (osh
->failed
);
245 * The pkttag contents are NOT cloned.
248 osl_pktdup(osl_t
*osh
, void *skb
)
252 if ((p
= skb_clone((struct sk_buff
*)skb
, GFP_ATOMIC
)) == NULL
)
255 /* skb_clone copies skb->cb.. we don't want that */
257 bzero((void*)((struct sk_buff
*)p
)->cb
, OSL_PKTTAG_SZ
);
259 /* Increment the packet counter */
260 osh
->pub
.pktalloced
++;
265 osl_pktalloced(osl_t
*osh
)
267 return (osh
->pub
.pktalloced
);
This page took 0.059537 seconds and 5 git commands to generate.