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.
18 #ifndef __BFA_OS_INC_H__
19 #define __BFA_OS_INC_H__
21 #include <linux/types.h>
22 #include <linux/version.h>
23 #include <linux/pci.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/cdev.h>
29 #include <linux/delay.h>
30 #include <linux/vmalloc.h>
31 #include <linux/workqueue.h>
32 #include <linux/bitops.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/scsi_transport.h>
43 static inline u64 bfa_os_get_log_time(void)
49 /* We are interested in seconds only. */
50 system_time = tv.tv_sec;
54 #define bfa_io_lat_clock_res_div HZ
55 #define bfa_io_lat_clock_res_mul 1000
57 #define BFA_LOG(level, bfad, mask, fmt, arg...) \
59 if (((mask) == 4) || (level[1] <= '4')) \
60 dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
63 #define bfa_swap_3b(_x) \
64 ((((_x) & 0xff) << 16) | \
66 (((_x) & 0xff0000) >> 16))
68 #define bfa_swap_8b(_x) \
69 ((((_x) & 0xff00000000000000ull) >> 56) \
70 | (((_x) & 0x00ff000000000000ull) >> 40) \
71 | (((_x) & 0x0000ff0000000000ull) >> 24) \
72 | (((_x) & 0x000000ff00000000ull) >> 8) \
73 | (((_x) & 0x00000000ff000000ull) << 8) \
74 | (((_x) & 0x0000000000ff0000ull) << 24) \
75 | (((_x) & 0x000000000000ff00ull) << 40) \
76 | (((_x) & 0x00000000000000ffull) << 56))
78 #define bfa_os_swap32(_x) \
79 ((((_x) & 0xff) << 24) | \
80 (((_x) & 0x0000ff00) << 8) | \
81 (((_x) & 0x00ff0000) >> 8) | \
82 (((_x) & 0xff000000) >> 24))
84 #define bfa_os_swap_sgaddr(_x) ((u64)( \
85 (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
86 (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
87 (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32) | \
88 (((u64)(_x) & (u64)0x00000000ff000000ull) << 32) | \
89 (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32) | \
90 (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32) | \
91 (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32) | \
92 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
95 #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
96 (((_x) & 0x00ff) << 8)))
97 #define bfa_os_htonl(_x) bfa_os_swap32(_x)
98 #define bfa_os_htonll(_x) bfa_swap_8b(_x)
99 #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
100 #define bfa_os_wtole(_x) (_x)
101 #define bfa_os_sgaddr(_x) (_x)
105 #define bfa_os_htons(_x) (_x)
106 #define bfa_os_htonl(_x) (_x)
107 #define bfa_os_hton3b(_x) (_x)
108 #define bfa_os_htonll(_x) (_x)
109 #define bfa_os_wtole(_x) bfa_os_swap32(_x)
110 #define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
114 #define bfa_os_ntohs(_x) bfa_os_htons(_x)
115 #define bfa_os_ntohl(_x) bfa_os_htonl(_x)
116 #define bfa_os_ntohll(_x) bfa_os_htonll(_x)
117 #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
119 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
121 #define bfa_os_addr_t void __iomem *
123 #define bfa_os_reg_read(_raddr) readl(_raddr)
124 #define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
125 #define bfa_os_mem_read(_raddr, _off) \
126 bfa_os_swap32(readl(((_raddr) + (_off))))
127 #define bfa_os_mem_write(_raddr, _off, _val) \
128 writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
130 #define BFA_TRC_TS(_trcm) \
134 do_gettimeofday(&tv); \
135 (tv.tv_sec*1000000+tv.tv_usec); \
138 #define boolean_t int
141 * For current time stamp, OS API will fill-in
143 struct bfa_timeval_s {
144 u32 tv_sec; /* seconds */
145 u32 tv_usec; /* microseconds */
149 bfa_os_gettimeofday(struct bfa_timeval_s *tv)
151 struct timeval tmp_tv;
153 do_gettimeofday(&tmp_tv);
154 tv->tv_sec = (u32) tmp_tv.tv_sec;
155 tv->tv_usec = (u32) tmp_tv.tv_usec;
159 wwn2str(char *wwn_str, u64 wwn)
167 sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
168 w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
169 w.byte[6], w.byte[7]);
173 fcid2str(char *fcid_str, u32 fcid)
181 sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
184 #endif /* __BFA_OS_INC_H__ */