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