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_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) | \
76 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
79 #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
80 #define bfa_os_sgaddr(_x) (_x)
82 #define bfa_os_hton3b(_x) (_x)
83 #define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
86 #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
87 #define bfa_os_u32(__pa64) ((__pa64) >> 32)
89 #define BFA_TRC_TS(_trcm) \
93 do_gettimeofday(&tv); \
94 (tv.tv_sec*1000000+tv.tv_usec); \
100 * For current time stamp, OS API will fill-in
102 struct bfa_timeval_s {
103 u32 tv_sec; /* seconds */
104 u32 tv_usec; /* microseconds */
108 bfa_os_gettimeofday(struct bfa_timeval_s *tv)
110 struct timeval tmp_tv;
112 do_gettimeofday(&tmp_tv);
113 tv->tv_sec = (u32) tmp_tv.tv_sec;
114 tv->tv_usec = (u32) tmp_tv.tv_usec;
118 wwn2str(char *wwn_str, u64 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]);
132 fcid2str(char *fcid_str, u32 fcid)
140 sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
143 #endif /* __BFA_OS_INC_H__ */