]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/brcm80211/util/linux_osl.c
70c35e9d31a8ec5050f4dc5ff5151dbc3132d660
[karo-tx-linux.git] / drivers / staging / brcm80211 / util / linux_osl.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 #include <linux/delay.h>
18 #include <linux/fs.h>
19 #ifdef mips
20 #include <asm/paccess.h>
21 #endif                          /* mips */
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/netdevice.h>
25 #include <linux/sched.h>
26 #include <bcmdefs.h>
27 #include <osl.h>
28 #include <bcmutils.h>
29 #include <pcicfg.h>
30
31
32 #define OS_HANDLE_MAGIC         0x1234abcd      /* Magic # to recognise osh */
33 #define BCM_MEM_FILENAME_LEN    24      /* Mem. filename length */
34
35 /* Global ASSERT type flag */
36 u32 g_assert_type;
37
38 struct osl_info *osl_attach(void *pdev, uint bustype)
39 {
40         struct osl_info *osh;
41
42         osh = kmalloc(sizeof(struct osl_info), GFP_ATOMIC);
43         ASSERT(osh);
44
45         memset(osh, 0, sizeof(struct osl_info));
46         osh->magic = OS_HANDLE_MAGIC;
47         return osh;
48 }
49
50 void osl_detach(struct osl_info *osh)
51 {
52         if (osh == NULL)
53                 return;
54
55         ASSERT(osh->magic == OS_HANDLE_MAGIC);
56         kfree(osh);
57 }
58
59 #if defined(BCMDBG_ASSERT)
60 void osl_assert(char *exp, char *file, int line)
61 {
62         char tempbuf[256];
63         char *basename;
64
65         basename = strrchr(file, '/');
66         /* skip the '/' */
67         if (basename)
68                 basename++;
69
70         if (!basename)
71                 basename = file;
72
73 #ifdef BCMDBG_ASSERT
74         snprintf(tempbuf, 256,
75                  "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
76                  basename, line);
77
78         /* Print assert message and give it time to be written to /var/log/messages */
79         if (!in_interrupt()) {
80                 const int delay = 3;
81                 printk(KERN_ERR "%s", tempbuf);
82                 printk(KERN_ERR "panic in %d seconds\n", delay);
83                 set_current_state(TASK_INTERRUPTIBLE);
84                 schedule_timeout(delay * HZ);
85         }
86
87         switch (g_assert_type) {
88         case 0:
89                 panic(KERN_ERR "%s", tempbuf);
90                 break;
91         case 1:
92                 printk(KERN_ERR "%s", tempbuf);
93                 BUG();
94                 break;
95         case 2:
96                 printk(KERN_ERR "%s", tempbuf);
97                 break;
98         default:
99                 break;
100         }
101 #endif                          /* BCMDBG_ASSERT */
102
103 }
104 #endif                          /* defined(BCMDBG_ASSERT) */
105