Linux-libre 2.6.34.3-gnu1
[librecmc/linux-libre.git] / drivers / scsi / bfa / bfa_os_inc.h
1 /*
2  * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License (GPL) Version 2 as
10  * published by the Free Software Foundation
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  */
17
18 /**
19  * Contains declarations all OS Specific files needed for BFA layer
20  */
21
22 #ifndef __BFA_OS_INC_H__
23 #define __BFA_OS_INC_H__
24
25 #ifndef __KERNEL__
26 #include <stdint.h>
27 #else
28 #include <linux/types.h>
29
30 #include <linux/version.h>
31 #include <linux/pci.h>
32
33 #include <linux/dma-mapping.h>
34 #define SET_MODULE_VERSION(VER)
35
36 #include <linux/idr.h>
37
38 #include <linux/interrupt.h>
39 #include <linux/cdev.h>
40 #include <linux/fs.h>
41 #include <linux/delay.h>
42 #include <linux/vmalloc.h>
43
44 #include <linux/workqueue.h>
45
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_host.h>
48
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/scsi_transport_fc.h>
51 #include <scsi/scsi_transport.h>
52
53 #define BFA_ERR                 KERN_ERR
54 #define BFA_WARNING             KERN_WARNING
55 #define BFA_NOTICE              KERN_NOTICE
56 #define BFA_INFO                KERN_INFO
57 #define BFA_DEBUG               KERN_DEBUG
58
59 #define LOG_BFAD_INIT           0x00000001
60 #define LOG_FCP_IO              0x00000002
61
62 #ifdef DEBUG
63 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...)                   \
64                 BFA_LOG(bfad, level, mask, fmt, ## arg)
65 #define BFA_DEV_TRACE(bfad, level, fmt, arg...)                         \
66                 BFA_DEV_PRINTF(bfad, level, fmt, ## arg)
67 #define BFA_TRACE(level, fmt, arg...)                                   \
68                 BFA_PRINTF(level, fmt, ## arg)
69 #else
70 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...)
71 #define BFA_DEV_TRACE(bfad, level, fmt, arg...)
72 #define BFA_TRACE(level, fmt, arg...)
73 #endif
74
75 #define BFA_ASSERT(p) do {                                              \
76         if (!(p)) {      \
77                 printk(KERN_ERR "assert(%s) failed at %s:%d\n",         \
78                 #p, __FILE__, __LINE__);      \
79                 BUG();      \
80         }                                                               \
81 } while (0)
82
83
84 #define BFA_LOG(bfad, level, mask, fmt, arg...)                         \
85 do {                                                                    \
86         if (((mask) & (((struct bfad_s *)(bfad))->                      \
87                 cfg_data[cfg_log_mask])) || (level[1] <= '3'))          \
88                 dev_printk(level, &(((struct bfad_s *)                  \
89                         (bfad))->pcidev->dev), fmt, ##arg);      \
90 } while (0)
91
92 #ifndef BFA_DEV_PRINTF
93 #define BFA_DEV_PRINTF(bfad, level, fmt, arg...)                        \
94                 dev_printk(level, &(((struct bfad_s *)                  \
95                         (bfad))->pcidev->dev), fmt, ##arg);
96 #endif
97
98 #define BFA_PRINTF(level, fmt, arg...)                                  \
99                 printk(level fmt, ##arg);
100
101 int bfa_os_MWB(void *);
102
103 #define bfa_os_mmiowb()         mmiowb()
104
105 #define bfa_swap_3b(_x)                         \
106         ((((_x) & 0xff) << 16) |                \
107         ((_x) & 0x00ff00) |                     \
108         (((_x) & 0xff0000) >> 16))
109
110 #define bfa_swap_8b(_x)                                 \
111      ((((_x) & 0xff00000000000000ull) >> 56)            \
112       | (((_x) & 0x00ff000000000000ull) >> 40)          \
113       | (((_x) & 0x0000ff0000000000ull) >> 24)          \
114       | (((_x) & 0x000000ff00000000ull) >> 8)           \
115       | (((_x) & 0x00000000ff000000ull) << 8)           \
116       | (((_x) & 0x0000000000ff0000ull) << 24)          \
117       | (((_x) & 0x000000000000ff00ull) << 40)          \
118       | (((_x) & 0x00000000000000ffull) << 56))
119
120 #define bfa_os_swap32(_x)                       \
121         ((((_x) & 0xff) << 24)          |       \
122         (((_x) & 0x0000ff00) << 8)      |       \
123         (((_x) & 0x00ff0000) >> 8)      |       \
124         (((_x) & 0xff000000) >> 24))
125
126
127 #ifndef __BIGENDIAN
128 #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
129                                  (((_x) & 0x00ff) << 8)))
130
131 #define bfa_os_htonl(_x)        bfa_os_swap32(_x)
132 #define bfa_os_htonll(_x)       bfa_swap_8b(_x)
133 #define bfa_os_hton3b(_x)       bfa_swap_3b(_x)
134
135 #define bfa_os_wtole(_x)   (_x)
136
137 #else
138
139 #define bfa_os_htons(_x)   (_x)
140 #define bfa_os_htonl(_x)   (_x)
141 #define bfa_os_hton3b(_x)  (_x)
142 #define bfa_os_htonll(_x)  (_x)
143 #define bfa_os_wtole(_x)   bfa_os_swap32(_x)
144
145 #endif
146
147 #define bfa_os_ntohs(_x)   bfa_os_htons(_x)
148 #define bfa_os_ntohl(_x)   bfa_os_htonl(_x)
149 #define bfa_os_ntohll(_x)  bfa_os_htonll(_x)
150 #define bfa_os_ntoh3b(_x)  bfa_os_hton3b(_x)
151
152 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
153
154 #define bfa_os_memset   memset
155 #define bfa_os_memcpy   memcpy
156 #define bfa_os_udelay   udelay
157 #define bfa_os_vsprintf vsprintf
158
159 #define bfa_os_assign(__t, __s) __t = __s
160
161 #define bfa_os_addr_t char __iomem *
162 #define bfa_os_panic()
163
164 #define bfa_os_reg_read(_raddr) bfa_os_wtole(readl(_raddr))
165 #define bfa_os_reg_write(_raddr, _val) writel(bfa_os_wtole((_val)), (_raddr))
166 #define bfa_os_mem_read(_raddr, _off)                                   \
167         bfa_os_ntohl(readl(((_raddr) + (_off))))
168 #define bfa_os_mem_write(_raddr, _off, _val)                            \
169         writel(bfa_os_htonl((_val)), ((_raddr) + (_off)))
170
171 #define BFA_TRC_TS(_trcm)                                               \
172                         ({                                              \
173                                 struct timeval tv;                      \
174                                                                         \
175                                 do_gettimeofday(&tv);      \
176                                 (tv.tv_sec*1000000+tv.tv_usec);      \
177                          })
178
179 struct bfa_log_mod_s;
180 void bfa_os_printf(struct bfa_log_mod_s *log_mod, u32 msg_id,
181                         const char *fmt, ...);
182 #endif
183
184 #define boolean_t int
185
186 /**
187  * For current time stamp, OS API will fill-in
188  */
189 struct bfa_timeval_s {
190         u32     tv_sec;         /*  seconds        */
191         u32     tv_usec;        /*  microseconds   */
192 };
193
194 void bfa_os_gettimeofday(struct bfa_timeval_s *tv);
195
196 static inline void
197 wwn2str(char *wwn_str, u64 wwn)
198 {
199         union {
200                 u64 wwn;
201                 u8 byte[8];
202         } w;
203
204         w.wwn = wwn;
205         sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
206                 w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
207                 w.byte[6], w.byte[7]);
208 }
209
210 static inline void
211 fcid2str(char *fcid_str, u32 fcid)
212 {
213         union {
214                 u32 fcid;
215                 u8 byte[4];
216         } f;
217
218         f.fcid = fcid;
219         sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
220 }
221
222 #endif /* __BFA_OS_INC_H__ */