]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/bfa/bfa_os_inc.h
Merge branch 'upstream/core' of git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen
[net-next-2.6.git] / drivers / scsi / bfa / bfa_os_inc.h
CommitLineData
7725ccfd 1/*
a36c61f9 2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
7725ccfd
JH
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
7725ccfd
JH
18#ifndef __BFA_OS_INC_H__
19#define __BFA_OS_INC_H__
20
7725ccfd 21#include <linux/types.h>
7725ccfd
JH
22#include <linux/version.h>
23#include <linux/pci.h>
7725ccfd 24#include <linux/dma-mapping.h>
7725ccfd 25#include <linux/idr.h>
7725ccfd
JH
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>
7725ccfd 31#include <linux/workqueue.h>
a36c61f9 32#include <linux/bitops.h>
7725ccfd
JH
33#include <scsi/scsi.h>
34#include <scsi/scsi_host.h>
7725ccfd
JH
35#include <scsi/scsi_tcq.h>
36#include <scsi/scsi_transport_fc.h>
37#include <scsi/scsi_transport.h>
38
077424e2
JH
39#ifdef __BIG_ENDIAN
40#define __BIGENDIAN
41#endif
42
a36c61f9
KG
43static 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
7725ccfd 56
a36c61f9
KG
57#define BFA_LOG(level, bfad, mask, fmt, arg...) \
58do { \
59 if (((mask) == 4) || (level[1] <= '4')) \
60 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
7725ccfd
JH
61} while (0)
62
7725ccfd
JH
63#define bfa_swap_3b(_x) \
64 ((((_x) & 0xff) << 16) | \
65 ((_x) & 0x00ff00) | \
66 (((_x) & 0xff0000) >> 16))
67
a36c61f9
KG
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) | \
077424e2 76 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
7725ccfd
JH
77
78#ifndef __BIGENDIAN
53440260 79#define bfa_os_hton3b(_x) bfa_swap_3b(_x)
077424e2 80#define bfa_os_sgaddr(_x) (_x)
7725ccfd 81#else
7725ccfd 82#define bfa_os_hton3b(_x) (_x)
077424e2 83#define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
7725ccfd
JH
84#endif
85
7725ccfd 86#define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
7725ccfd 87#define bfa_os_u32(__pa64) ((__pa64) >> 32)
53440260
JH
88
89#define BFA_TRC_TS(_trcm) \
90 ({ \
91 struct timeval tv; \
92 \
acdc79a6 93 do_gettimeofday(&tv); \
53440260
JH
94 (tv.tv_sec*1000000+tv.tv_usec); \
95 })
7725ccfd 96
7725ccfd
JH
97#define boolean_t int
98
acdc79a6 99/*
7725ccfd
JH
100 * For current time stamp, OS API will fill-in
101 */
102struct bfa_timeval_s {
103 u32 tv_sec; /* seconds */
104 u32 tv_usec; /* microseconds */
105};
106
a36c61f9
KG
107static inline void
108bfa_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}
7725ccfd
JH
116
117static inline void
118wwn2str(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
131static inline void
132fcid2str(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__ */