2 * Copyright (c) 2005-2009 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__
28 #include <linux/types.h>
30 #include <linux/version.h>
31 #include <linux/pci.h>
33 #include <linux/dma-mapping.h>
34 #define SET_MODULE_VERSION(VER)
36 #include <linux/idr.h>
38 #include <linux/interrupt.h>
39 #include <linux/cdev.h>
41 #include <linux/delay.h>
42 #include <linux/vmalloc.h>
44 #include <linux/workqueue.h>
46 #include <scsi/scsi.h>
47 #include <scsi/scsi_host.h>
49 #include <scsi/scsi_tcq.h>
50 #include <scsi/scsi_transport_fc.h>
51 #include <scsi/scsi_transport.h>
57 #define BFA_ERR KERN_ERR
58 #define BFA_WARNING KERN_WARNING
59 #define BFA_NOTICE KERN_NOTICE
60 #define BFA_INFO KERN_INFO
61 #define BFA_DEBUG KERN_DEBUG
63 #define LOG_BFAD_INIT 0x00000001
64 #define LOG_FCP_IO 0x00000002
67 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...) \
68 BFA_LOG(bfad, level, mask, fmt, ## arg)
69 #define BFA_DEV_TRACE(bfad, level, fmt, arg...) \
70 BFA_DEV_PRINTF(bfad, level, fmt, ## arg)
71 #define BFA_TRACE(level, fmt, arg...) \
72 BFA_PRINTF(level, fmt, ## arg)
74 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...)
75 #define BFA_DEV_TRACE(bfad, level, fmt, arg...)
76 #define BFA_TRACE(level, fmt, arg...)
79 #define BFA_ASSERT(p) do { \
81 printk(KERN_ERR "assert(%s) failed at %s:%d\n", \
82 #p, __FILE__, __LINE__); \
88 #define BFA_LOG(bfad, level, mask, fmt, arg...) \
90 if (((mask) & (((struct bfad_s *)(bfad))-> \
91 cfg_data[cfg_log_mask])) || (level[1] <= '3')) \
92 dev_printk(level, &(((struct bfad_s *) \
93 (bfad))->pcidev->dev), fmt, ##arg); \
96 #ifndef BFA_DEV_PRINTF
97 #define BFA_DEV_PRINTF(bfad, level, fmt, arg...) \
98 dev_printk(level, &(((struct bfad_s *) \
99 (bfad))->pcidev->dev), fmt, ##arg);
102 #define BFA_PRINTF(level, fmt, arg...) \
103 printk(level fmt, ##arg);
105 int bfa_os_MWB(void *);
107 #define bfa_os_mmiowb() mmiowb()
109 #define bfa_swap_3b(_x) \
110 ((((_x) & 0xff) << 16) | \
111 ((_x) & 0x00ff00) | \
112 (((_x) & 0xff0000) >> 16))
114 #define bfa_swap_8b(_x) \
115 ((((_x) & 0xff00000000000000ull) >> 56) \
116 | (((_x) & 0x00ff000000000000ull) >> 40) \
117 | (((_x) & 0x0000ff0000000000ull) >> 24) \
118 | (((_x) & 0x000000ff00000000ull) >> 8) \
119 | (((_x) & 0x00000000ff000000ull) << 8) \
120 | (((_x) & 0x0000000000ff0000ull) << 24) \
121 | (((_x) & 0x000000000000ff00ull) << 40) \
122 | (((_x) & 0x00000000000000ffull) << 56))
124 #define bfa_os_swap32(_x) \
125 ((((_x) & 0xff) << 24) | \
126 (((_x) & 0x0000ff00) << 8) | \
127 (((_x) & 0x00ff0000) >> 8) | \
128 (((_x) & 0xff000000) >> 24))
130 #define bfa_os_swap_sgaddr(_x) ((u64)( \
131 (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
132 (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
133 (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32) | \
134 (((u64)(_x) & (u64)0x00000000ff000000ull) << 32) | \
135 (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32) | \
136 (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32) | \
137 (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32) | \
138 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
141 #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
142 (((_x) & 0x00ff) << 8)))
144 #define bfa_os_htonl(_x) bfa_os_swap32(_x)
145 #define bfa_os_htonll(_x) bfa_swap_8b(_x)
146 #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
148 #define bfa_os_wtole(_x) (_x)
149 #define bfa_os_sgaddr(_x) (_x)
153 #define bfa_os_htons(_x) (_x)
154 #define bfa_os_htonl(_x) (_x)
155 #define bfa_os_hton3b(_x) (_x)
156 #define bfa_os_htonll(_x) (_x)
157 #define bfa_os_wtole(_x) bfa_os_swap32(_x)
158 #define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
162 #define bfa_os_ntohs(_x) bfa_os_htons(_x)
163 #define bfa_os_ntohl(_x) bfa_os_htonl(_x)
164 #define bfa_os_ntohll(_x) bfa_os_htonll(_x)
165 #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
167 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
169 #define bfa_os_memset memset
170 #define bfa_os_memcpy memcpy
171 #define bfa_os_udelay udelay
172 #define bfa_os_vsprintf vsprintf
174 #define bfa_os_assign(__t, __s) __t = __s
176 #define bfa_os_addr_t char __iomem *
177 #define bfa_os_panic()
179 #define bfa_os_reg_read(_raddr) readl(_raddr)
180 #define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
181 #define bfa_os_mem_read(_raddr, _off) \
182 bfa_os_swap32(readl(((_raddr) + (_off))))
183 #define bfa_os_mem_write(_raddr, _off, _val) \
184 writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
186 #define BFA_TRC_TS(_trcm) \
190 do_gettimeofday(&tv); \
191 (tv.tv_sec*1000000+tv.tv_usec); \
194 struct bfa_log_mod_s;
195 void bfa_os_printf(struct bfa_log_mod_s *log_mod, u32 msg_id,
196 const char *fmt, ...);
199 #define boolean_t int
202 * For current time stamp, OS API will fill-in
204 struct bfa_timeval_s {
205 u32 tv_sec; /* seconds */
206 u32 tv_usec; /* microseconds */
209 void bfa_os_gettimeofday(struct bfa_timeval_s *tv);
212 wwn2str(char *wwn_str, u64 wwn)
220 sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
221 w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
222 w.byte[6], w.byte[7]);
226 fcid2str(char *fcid_str, u32 fcid)
234 sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
237 #endif /* __BFA_OS_INC_H__ */