2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
19 * Contains declarations all OS Specific files needed for BFA layer
22 #ifndef __BFA_OS_INC_H__
23 #define __BFA_OS_INC_H__
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>
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>
47 static inline u64 bfa_os_get_clock(void)
52 static inline u64 bfa_os_get_log_time(void)
58 /* We are interested in seconds only. */
59 system_time = tv.tv_sec;
63 #define bfa_io_lat_clock_res_div HZ
64 #define bfa_io_lat_clock_res_mul 1000
66 #define BFA_ASSERT(p) do { \
68 printk(KERN_ERR "assert(%s) failed at %s:%d\n", \
69 #p, __FILE__, __LINE__); \
73 #define BFA_LOG(level, bfad, mask, fmt, arg...) \
75 if (((mask) == 4) || (level[1] <= '4')) \
76 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
79 #define bfa_swap_3b(_x) \
80 ((((_x) & 0xff) << 16) | \
82 (((_x) & 0xff0000) >> 16))
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))
94 #define bfa_os_swap32(_x) \
95 ((((_x) & 0xff) << 24) | \
96 (((_x) & 0x0000ff00) << 8) | \
97 (((_x) & 0x00ff0000) >> 8) | \
98 (((_x) & 0xff000000) >> 24))
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)))
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)
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)
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)
135 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
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
143 #define bfa_os_assign(__t, __s) __t = __s
144 #define bfa_os_addr_t void __iomem *
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)))
153 #define BFA_TRC_TS(_trcm) \
157 do_gettimeofday(&tv); \
158 (tv.tv_sec*1000000+tv.tv_usec); \
161 #define boolean_t int
164 * For current time stamp, OS API will fill-in
166 struct bfa_timeval_s {
167 u32 tv_sec; /* seconds */
168 u32 tv_usec; /* microseconds */
172 bfa_os_gettimeofday(struct bfa_timeval_s *tv)
174 struct timeval tmp_tv;
176 do_gettimeofday(&tmp_tv);
177 tv->tv_sec = (u32) tmp_tv.tv_sec;
178 tv->tv_usec = (u32) tmp_tv.tv_usec;
182 wwn2str(char *wwn_str, u64 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]);
196 fcid2str(char *fcid_str, u32 fcid)
204 sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
207 #endif /* __BFA_OS_INC_H__ */