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>
53 #define BFA_ERR KERN_ERR
54 #define BFA_WARNING KERN_WARNING
55 #define BFA_NOTICE KERN_NOTICE
56 #define BFA_INFO KERN_INFO
57 #define BFA_DEBUG KERN_DEBUG
59 #define LOG_BFAD_INIT 0x00000001
60 #define LOG_FCP_IO 0x00000002
63 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...) \
64 BFA_LOG(bfad, level, mask, fmt, ## arg)
65 #define BFA_DEV_TRACE(bfad, level, fmt, arg...) \
66 BFA_DEV_PRINTF(bfad, level, fmt, ## arg)
67 #define BFA_TRACE(level, fmt, arg...) \
68 BFA_PRINTF(level, fmt, ## arg)
70 #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...)
71 #define BFA_DEV_TRACE(bfad, level, fmt, arg...)
72 #define BFA_TRACE(level, fmt, arg...)
75 #define BFA_ASSERT(p) do { \
77 printk(KERN_ERR "assert(%s) failed at %s:%d\n", \
78 #p, __FILE__, __LINE__); \
84 #define BFA_LOG(bfad, level, mask, fmt, arg...) \
86 if (((mask) & (((struct bfad_s *)(bfad))-> \
87 cfg_data[cfg_log_mask])) || (level[1] <= '3')) \
88 dev_printk(level, &(((struct bfad_s *) \
89 (bfad))->pcidev->dev), fmt, ##arg); \
92 #ifndef BFA_DEV_PRINTF
93 #define BFA_DEV_PRINTF(bfad, level, fmt, arg...) \
94 dev_printk(level, &(((struct bfad_s *) \
95 (bfad))->pcidev->dev), fmt, ##arg);
98 #define BFA_PRINTF(level, fmt, arg...) \
99 printk(level fmt, ##arg);
101 int bfa_os_MWB(void *);
103 #define bfa_os_mmiowb() mmiowb()
105 #define bfa_swap_3b(_x) \
106 ((((_x) & 0xff) << 16) | \
107 ((_x) & 0x00ff00) | \
108 (((_x) & 0xff0000) >> 16))
110 #define bfa_swap_8b(_x) \
111 ((((_x) & 0xff00000000000000ull) >> 56) \
112 | (((_x) & 0x00ff000000000000ull) >> 40) \
113 | (((_x) & 0x0000ff0000000000ull) >> 24) \
114 | (((_x) & 0x000000ff00000000ull) >> 8) \
115 | (((_x) & 0x00000000ff000000ull) << 8) \
116 | (((_x) & 0x0000000000ff0000ull) << 24) \
117 | (((_x) & 0x000000000000ff00ull) << 40) \
118 | (((_x) & 0x00000000000000ffull) << 56))
120 #define bfa_os_swap32(_x) \
121 ((((_x) & 0xff) << 24) | \
122 (((_x) & 0x0000ff00) << 8) | \
123 (((_x) & 0x00ff0000) >> 8) | \
124 (((_x) & 0xff000000) >> 24))
128 #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
129 (((_x) & 0x00ff) << 8)))
131 #define bfa_os_htonl(_x) bfa_os_swap32(_x)
132 #define bfa_os_htonll(_x) bfa_swap_8b(_x)
133 #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
135 #define bfa_os_wtole(_x) (_x)
139 #define bfa_os_htons(_x) (_x)
140 #define bfa_os_htonl(_x) (_x)
141 #define bfa_os_hton3b(_x) (_x)
142 #define bfa_os_htonll(_x) (_x)
143 #define bfa_os_wtole(_x) bfa_os_swap32(_x)
147 #define bfa_os_ntohs(_x) bfa_os_htons(_x)
148 #define bfa_os_ntohl(_x) bfa_os_htonl(_x)
149 #define bfa_os_ntohll(_x) bfa_os_htonll(_x)
150 #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
152 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
154 #define bfa_os_memset memset
155 #define bfa_os_memcpy memcpy
156 #define bfa_os_udelay udelay
157 #define bfa_os_vsprintf vsprintf
159 #define bfa_os_assign(__t, __s) __t = __s
161 #define bfa_os_addr_t char __iomem *
162 #define bfa_os_panic()
164 #define bfa_os_reg_read(_raddr) bfa_os_wtole(readl(_raddr))
165 #define bfa_os_reg_write(_raddr, _val) writel(bfa_os_wtole((_val)), (_raddr))
166 #define bfa_os_mem_read(_raddr, _off) \
167 bfa_os_ntohl(readl(((_raddr) + (_off))))
168 #define bfa_os_mem_write(_raddr, _off, _val) \
169 writel(bfa_os_htonl((_val)), ((_raddr) + (_off)))
171 #define BFA_TRC_TS(_trcm) \
175 do_gettimeofday(&tv); \
176 (tv.tv_sec*1000000+tv.tv_usec); \
179 struct bfa_log_mod_s
;
180 void bfa_os_printf(struct bfa_log_mod_s
*log_mod
, u32 msg_id
,
181 const char *fmt
, ...);
184 #define boolean_t int
187 * For current time stamp, OS API will fill-in
189 struct bfa_timeval_s
{
190 u32 tv_sec
; /* seconds */
191 u32 tv_usec
; /* microseconds */
194 void bfa_os_gettimeofday(struct bfa_timeval_s
*tv
);
197 wwn2str(char *wwn_str
, u64 wwn
)
205 sprintf(wwn_str
, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w
.byte
[0],
206 w
.byte
[1], w
.byte
[2], w
.byte
[3], w
.byte
[4], w
.byte
[5],
207 w
.byte
[6], w
.byte
[7]);
211 fcid2str(char *fcid_str
, u32 fcid
)
219 sprintf(fcid_str
, "%02x:%02x:%02x", f
.byte
[1], f
.byte
[2], f
.byte
[3]);
222 #endif /* __BFA_OS_INC_H__ */