]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/scsi/bfa/bfa_os_inc.h
Merge branches 'irq-core-for-linus' and 'core-locking-for-linus' of git://git.kernel...
[karo-tx-linux.git] / drivers / scsi / bfa / bfa_os_inc.h
1 /*
2  * Copyright (c) 2005-2010 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 #include <linux/types.h>
26 #include <linux/version.h>
27 #include <linux/pci.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/idr.h>
30 #include <linux/interrupt.h>
31 #include <linux/cdev.h>
32 #include <linux/fs.h>
33 #include <linux/delay.h>
34 #include <linux/vmalloc.h>
35 #include <linux/workqueue.h>
36 #include <linux/bitops.h>
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_tcq.h>
40 #include <scsi/scsi_transport_fc.h>
41 #include <scsi/scsi_transport.h>
42
43 #ifdef __BIG_ENDIAN
44 #define __BIGENDIAN
45 #endif
46
47 static inline u64 bfa_os_get_clock(void)
48 {
49         return jiffies;
50 }
51
52 static inline u64 bfa_os_get_log_time(void)
53 {
54         u64 system_time = 0;
55         struct timeval tv;
56         do_gettimeofday(&tv);
57
58         /* We are interested in seconds only. */
59         system_time = tv.tv_sec;
60         return system_time;
61 }
62
63 #define bfa_io_lat_clock_res_div HZ
64 #define bfa_io_lat_clock_res_mul 1000
65
66 #define BFA_ASSERT(p) do {                                              \
67         if (!(p)) {      \
68                 printk(KERN_ERR "assert(%s) failed at %s:%d\n",         \
69                 #p, __FILE__, __LINE__);      \
70         }                                                               \
71 } while (0)
72
73 #define BFA_LOG(level, bfad, mask, fmt, arg...)                         \
74 do {                                                                    \
75         if (((mask) == 4) || (level[1] <= '4'))                         \
76                 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg);  \
77 } while (0)
78
79 #define bfa_swap_3b(_x)                         \
80         ((((_x) & 0xff) << 16) |                \
81         ((_x) & 0x00ff00) |                     \
82         (((_x) & 0xff0000) >> 16))
83
84 #define bfa_swap_8b(_x)                                 \
85         ((((_x) & 0xff00000000000000ull) >> 56)         \
86          | (((_x) & 0x00ff000000000000ull) >> 40)       \
87          | (((_x) & 0x0000ff0000000000ull) >> 24)       \
88          | (((_x) & 0x000000ff00000000ull) >> 8)        \
89          | (((_x) & 0x00000000ff000000ull) << 8)        \
90          | (((_x) & 0x0000000000ff0000ull) << 24)       \
91          | (((_x) & 0x000000000000ff00ull) << 40)       \
92          | (((_x) & 0x00000000000000ffull) << 56))
93
94 #define bfa_os_swap32(_x)                       \
95         ((((_x) & 0xff) << 24)          |       \
96         (((_x) & 0x0000ff00) << 8)      |       \
97         (((_x) & 0x00ff0000) >> 8)      |       \
98         (((_x) & 0xff000000) >> 24))
99
100 #define bfa_os_swap_sgaddr(_x)  ((u64)(                                 \
101         (((u64)(_x) & (u64)0x00000000000000ffull) << 32)        |       \
102         (((u64)(_x) & (u64)0x000000000000ff00ull) << 32)        |       \
103         (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32)        |       \
104         (((u64)(_x) & (u64)0x00000000ff000000ull) << 32)        |       \
105         (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32)        |       \
106         (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32)        |       \
107         (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32)        |       \
108         (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
109
110 #ifndef __BIGENDIAN
111 #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
112                                  (((_x) & 0x00ff) << 8)))
113 #define bfa_os_htonl(_x)        bfa_os_swap32(_x)
114 #define bfa_os_htonll(_x)       bfa_swap_8b(_x)
115 #define bfa_os_hton3b(_x)       bfa_swap_3b(_x)
116 #define bfa_os_wtole(_x)   (_x)
117 #define bfa_os_sgaddr(_x)  (_x)
118
119 #else
120
121 #define bfa_os_htons(_x)   (_x)
122 #define bfa_os_htonl(_x)   (_x)
123 #define bfa_os_hton3b(_x)  (_x)
124 #define bfa_os_htonll(_x)  (_x)
125 #define bfa_os_wtole(_x)   bfa_os_swap32(_x)
126 #define bfa_os_sgaddr(_x)  bfa_os_swap_sgaddr(_x)
127
128 #endif
129
130 #define bfa_os_ntohs(_x)   bfa_os_htons(_x)
131 #define bfa_os_ntohl(_x)   bfa_os_htonl(_x)
132 #define bfa_os_ntohll(_x)  bfa_os_htonll(_x)
133 #define bfa_os_ntoh3b(_x)  bfa_os_hton3b(_x)
134
135 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
136
137 #define bfa_os_memset   memset
138 #define bfa_os_memcpy   memcpy
139 #define bfa_os_udelay   udelay
140 #define bfa_os_vsprintf vsprintf
141 #define bfa_os_snprintf snprintf
142
143 #define bfa_os_assign(__t, __s) __t = __s
144 #define bfa_os_addr_t void __iomem *
145
146 #define bfa_os_reg_read(_raddr) readl(_raddr)
147 #define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
148 #define bfa_os_mem_read(_raddr, _off)                                   \
149         bfa_os_swap32(readl(((_raddr) + (_off))))
150 #define bfa_os_mem_write(_raddr, _off, _val)                            \
151         writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
152
153 #define BFA_TRC_TS(_trcm)                                               \
154                         ({                                              \
155                                 struct timeval tv;                      \
156                                                                         \
157                                 do_gettimeofday(&tv);      \
158                                 (tv.tv_sec*1000000+tv.tv_usec);      \
159                          })
160
161 #define boolean_t int
162
163 /**
164  * For current time stamp, OS API will fill-in
165  */
166 struct bfa_timeval_s {
167         u32     tv_sec;         /*  seconds        */
168         u32     tv_usec;        /*  microseconds   */
169 };
170
171 static inline void
172 bfa_os_gettimeofday(struct bfa_timeval_s *tv)
173 {
174         struct timeval  tmp_tv;
175
176         do_gettimeofday(&tmp_tv);
177         tv->tv_sec = (u32) tmp_tv.tv_sec;
178         tv->tv_usec = (u32) tmp_tv.tv_usec;
179 }
180
181 static inline void
182 wwn2str(char *wwn_str, u64 wwn)
183 {
184         union {
185                 u64 wwn;
186                 u8 byte[8];
187         } w;
188
189         w.wwn = wwn;
190         sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
191                 w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
192                 w.byte[6], w.byte[7]);
193 }
194
195 static inline void
196 fcid2str(char *fcid_str, u32 fcid)
197 {
198         union {
199                 u32 fcid;
200                 u8 byte[4];
201         } f;
202
203         f.fcid = fcid;
204         sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
205 }
206
207 #endif /* __BFA_OS_INC_H__ */