[SCSI] bfa: remove all SCSI IO callbacks
[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_os_swap_sgaddr(_x)  ((u64)(                                 \
69         (((u64)(_x) & (u64)0x00000000000000ffull) << 32)        |       \
70         (((u64)(_x) & (u64)0x000000000000ff00ull) << 32)        |       \
71         (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32)        |       \
72         (((u64)(_x) & (u64)0x00000000ff000000ull) << 32)        |       \
73         (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32)        |       \
74         (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32)        |       \
75         (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32)        |       \
76         (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
77
78 #ifndef __BIGENDIAN
79 #define bfa_os_hton3b(_x)  bfa_swap_3b(_x)
80 #define bfa_os_sgaddr(_x)  (_x)
81 #else
82 #define bfa_os_hton3b(_x)  (_x)
83 #define bfa_os_sgaddr(_x)  bfa_os_swap_sgaddr(_x)
84 #endif
85
86 #define bfa_os_ntoh3b(_x)  bfa_os_hton3b(_x)
87 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
88
89 #define BFA_TRC_TS(_trcm)                               \
90         ({                                              \
91                 struct timeval tv;                      \
92                                                         \
93                 do_gettimeofday(&tv);                   \
94                 (tv.tv_sec*1000000+tv.tv_usec);         \
95          })
96
97 #define boolean_t int
98
99 /*
100  * For current time stamp, OS API will fill-in
101  */
102 struct bfa_timeval_s {
103         u32     tv_sec;         /*  seconds        */
104         u32     tv_usec;        /*  microseconds   */
105 };
106
107 static inline void
108 bfa_os_gettimeofday(struct bfa_timeval_s *tv)
109 {
110         struct timeval  tmp_tv;
111
112         do_gettimeofday(&tmp_tv);
113         tv->tv_sec = (u32) tmp_tv.tv_sec;
114         tv->tv_usec = (u32) tmp_tv.tv_usec;
115 }
116
117 static inline void
118 wwn2str(char *wwn_str, u64 wwn)
119 {
120         union {
121                 u64 wwn;
122                 u8 byte[8];
123         } w;
124
125         w.wwn = wwn;
126         sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
127                 w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
128                 w.byte[6], w.byte[7]);
129 }
130
131 static inline void
132 fcid2str(char *fcid_str, u32 fcid)
133 {
134         union {
135                 u32 fcid;
136                 u8 byte[4];
137         } f;
138
139         f.fcid = fcid;
140         sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
141 }
142
143 #endif /* __BFA_OS_INC_H__ */