• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/scsi/bfa/
1/*
2 * Copyright (c) 2005-2009 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/**
19 * Contains declarations all OS Specific files needed for BFA layer
20 */
21
22#ifndef __BFA_OS_INC_H__
23#define __BFA_OS_INC_H__
24
25#ifndef __KERNEL__
26#include <stdint.h>
27#else
28#include <linux/types.h>
29
30#include <linux/version.h>
31#include <linux/pci.h>
32
33#include <linux/dma-mapping.h>
34#define SET_MODULE_VERSION(VER)
35
36#include <linux/idr.h>
37
38#include <linux/interrupt.h>
39#include <linux/cdev.h>
40#include <linux/fs.h>
41#include <linux/delay.h>
42#include <linux/vmalloc.h>
43
44#include <linux/workqueue.h>
45
46#include <scsi/scsi.h>
47#include <scsi/scsi_host.h>
48
49#include <scsi/scsi_tcq.h>
50#include <scsi/scsi_transport_fc.h>
51#include <scsi/scsi_transport.h>
52
53#ifdef __BIG_ENDIAN
54#define __BIGENDIAN
55#endif
56
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
62
63#define LOG_BFAD_INIT		0x00000001
64#define LOG_FCP_IO		0x00000002
65
66#ifdef DEBUG
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)
73#else
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...)
77#endif
78
79#define BFA_ASSERT(p) do {						\
80	if (!(p)) {      \
81		printk(KERN_ERR "assert(%s) failed at %s:%d\n",		\
82		#p, __FILE__, __LINE__);      \
83		BUG();      \
84	}								\
85} while (0)
86
87
88#define BFA_LOG(bfad, level, mask, fmt, arg...)				\
89do { 									\
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);      \
94} while (0)
95
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);
100#endif
101
102#define BFA_PRINTF(level, fmt, arg...)					\
103		printk(level fmt, ##arg);
104
105int bfa_os_MWB(void *);
106
107#define bfa_os_mmiowb()		mmiowb()
108
109#define bfa_swap_3b(_x)				\
110	((((_x) & 0xff) << 16) |		\
111	((_x) & 0x00ff00) |			\
112	(((_x) & 0xff0000) >> 16))
113
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))
123
124#define bfa_os_swap32(_x) 			\
125	((((_x) & 0xff) << 24) 		|	\
126	(((_x) & 0x0000ff00) << 8)	|	\
127	(((_x) & 0x00ff0000) >> 8)	|	\
128	(((_x) & 0xff000000) >> 24))
129
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)))
139
140#ifndef __BIGENDIAN
141#define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
142				 (((_x) & 0x00ff) << 8)))
143
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)
147
148#define bfa_os_wtole(_x)   (_x)
149#define bfa_os_sgaddr(_x)  (_x)
150
151#else
152
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)
159
160#endif
161
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)
166
167#define bfa_os_u32(__pa64) ((__pa64) >> 32)
168
169#define bfa_os_memset	memset
170#define bfa_os_memcpy	memcpy
171#define bfa_os_udelay	udelay
172#define bfa_os_vsprintf vsprintf
173
174#define bfa_os_assign(__t, __s) __t = __s
175
176#define bfa_os_addr_t char __iomem *
177#define bfa_os_panic()
178
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)))
185
186#define BFA_TRC_TS(_trcm)						\
187			({						\
188				struct timeval tv;			\
189									\
190				do_gettimeofday(&tv);      \
191				(tv.tv_sec*1000000+tv.tv_usec);      \
192			 })
193
194struct bfa_log_mod_s;
195void bfa_os_printf(struct bfa_log_mod_s *log_mod, u32 msg_id,
196			const char *fmt, ...);
197#endif
198
199#define boolean_t int
200
201/**
202 * For current time stamp, OS API will fill-in
203 */
204struct bfa_timeval_s {
205	u32	tv_sec;		/*  seconds        */
206	u32	tv_usec;	/*  microseconds   */
207};
208
209void bfa_os_gettimeofday(struct bfa_timeval_s *tv);
210
211static inline void
212wwn2str(char *wwn_str, u64 wwn)
213{
214	union {
215		u64 wwn;
216		u8 byte[8];
217	} w;
218
219	w.wwn = 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]);
223}
224
225static inline void
226fcid2str(char *fcid_str, u32 fcid)
227{
228	union {
229		u32 fcid;
230		u8 byte[4];
231	} f;
232
233	f.fcid = fcid;
234	sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
235}
236
237#endif /* __BFA_OS_INC_H__ */
238