bfa_os_inc.h 5.4 KB
Newer Older
1
/*
K
Krishna Gudipati 已提交
2
 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
 * All rights reserved
 * www.brocade.com
 *
 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License (GPL) Version 2 as
 * published by the Free Software Foundation
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

/**
 * Contains declarations all OS Specific files needed for BFA layer
 */

#ifndef __BFA_OS_INC_H__
#define __BFA_OS_INC_H__

#include <linux/types.h>
#include <linux/version.h>
#include <linux/pci.h>
#include <linux/dma-mapping.h>
#include <linux/idr.h>
#include <linux/interrupt.h>
#include <linux/cdev.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/vmalloc.h>
#include <linux/workqueue.h>
K
Krishna Gudipati 已提交
36
#include <linux/bitops.h>
37 38 39 40 41 42
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_tcq.h>
#include <scsi/scsi_transport_fc.h>
#include <scsi/scsi_transport.h>

J
Jing Huang 已提交
43 44 45 46
#ifdef __BIG_ENDIAN
#define __BIGENDIAN
#endif

K
Krishna Gudipati 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
static inline u64 bfa_os_get_clock(void)
{
	return jiffies;
}

static inline u64 bfa_os_get_log_time(void)
{
	u64 system_time = 0;
	struct timeval tv;
	do_gettimeofday(&tv);

	/* We are interested in seconds only. */
	system_time = tv.tv_sec;
	return system_time;
}

#define bfa_io_lat_clock_res_div HZ
#define bfa_io_lat_clock_res_mul 1000
65 66 67 68 69 70 71 72

#define BFA_ASSERT(p) do {						\
	if (!(p)) {      \
		printk(KERN_ERR "assert(%s) failed at %s:%d\n",		\
		#p, __FILE__, __LINE__);      \
	}								\
} while (0)

K
Krishna Gudipati 已提交
73 74 75 76
#define BFA_LOG(level, bfad, mask, fmt, arg...)				\
do {									\
	if (((mask) == 4) || (level[1] <= '4'))				\
		dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg);	\
77 78 79 80 81 82 83
} while (0)

#define bfa_swap_3b(_x)				\
	((((_x) & 0xff) << 16) |		\
	((_x) & 0x00ff00) |			\
	(((_x) & 0xff0000) >> 16))

K
Krishna Gudipati 已提交
84 85 86 87 88 89 90 91 92 93 94 95
#define bfa_swap_8b(_x)					\
	((((_x) & 0xff00000000000000ull) >> 56)		\
	 | (((_x) & 0x00ff000000000000ull) >> 40)	\
	 | (((_x) & 0x0000ff0000000000ull) >> 24)	\
	 | (((_x) & 0x000000ff00000000ull) >> 8)	\
	 | (((_x) & 0x00000000ff000000ull) << 8)	\
	 | (((_x) & 0x0000000000ff0000ull) << 24)	\
	 | (((_x) & 0x000000000000ff00ull) << 40)	\
	 | (((_x) & 0x00000000000000ffull) << 56))

#define bfa_os_swap32(_x)			\
	((((_x) & 0xff) << 24)		|	\
96 97 98 99
	(((_x) & 0x0000ff00) << 8)	|	\
	(((_x) & 0x00ff0000) >> 8)	|	\
	(((_x) & 0xff000000) >> 24))

K
Krishna Gudipati 已提交
100 101 102 103 104 105 106 107
#define bfa_os_swap_sgaddr(_x)  ((u64)(                                 \
	(((u64)(_x) & (u64)0x00000000000000ffull) << 32)        |       \
	(((u64)(_x) & (u64)0x000000000000ff00ull) << 32)        |       \
	(((u64)(_x) & (u64)0x0000000000ff0000ull) << 32)        |       \
	(((u64)(_x) & (u64)0x00000000ff000000ull) << 32)        |       \
	(((u64)(_x) & (u64)0x000000ff00000000ull) >> 32)        |       \
	(((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32)        |       \
	(((u64)(_x) & (u64)0x00ff000000000000ull) >> 32)        |       \
J
Jing Huang 已提交
108
	(((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
109 110 111 112 113 114 115 116

#ifndef __BIGENDIAN
#define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
				 (((_x) & 0x00ff) << 8)))
#define bfa_os_htonl(_x)	bfa_os_swap32(_x)
#define bfa_os_htonll(_x)	bfa_swap_8b(_x)
#define bfa_os_hton3b(_x)	bfa_swap_3b(_x)
#define bfa_os_wtole(_x)   (_x)
J
Jing Huang 已提交
117
#define bfa_os_sgaddr(_x)  (_x)
118 119 120 121 122 123 124 125

#else

#define bfa_os_htons(_x)   (_x)
#define bfa_os_htonl(_x)   (_x)
#define bfa_os_hton3b(_x)  (_x)
#define bfa_os_htonll(_x)  (_x)
#define bfa_os_wtole(_x)   bfa_os_swap32(_x)
J
Jing Huang 已提交
126
#define bfa_os_sgaddr(_x)  bfa_os_swap_sgaddr(_x)
127 128 129 130 131 132 133 134 135 136 137 138 139 140

#endif

#define bfa_os_ntohs(_x)   bfa_os_htons(_x)
#define bfa_os_ntohl(_x)   bfa_os_htonl(_x)
#define bfa_os_ntohll(_x)  bfa_os_htonll(_x)
#define bfa_os_ntoh3b(_x)  bfa_os_hton3b(_x)

#define bfa_os_u32(__pa64) ((__pa64) >> 32)

#define bfa_os_memset	memset
#define bfa_os_memcpy	memcpy
#define bfa_os_udelay	udelay
#define bfa_os_vsprintf vsprintf
K
Krishna Gudipati 已提交
141
#define bfa_os_snprintf snprintf
142 143

#define bfa_os_assign(__t, __s) __t = __s
K
Krishna Gudipati 已提交
144
#define bfa_os_addr_t void __iomem *
145

146 147
#define bfa_os_reg_read(_raddr) readl(_raddr)
#define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
K
Krishna Gudipati 已提交
148
#define bfa_os_mem_read(_raddr, _off)					\
149
	bfa_os_swap32(readl(((_raddr) + (_off))))
K
Krishna Gudipati 已提交
150
#define bfa_os_mem_write(_raddr, _off, _val)				\
151
	writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170

#define BFA_TRC_TS(_trcm)						\
			({						\
				struct timeval tv;			\
									\
				do_gettimeofday(&tv);      \
				(tv.tv_sec*1000000+tv.tv_usec);      \
			 })

#define boolean_t int

/**
 * For current time stamp, OS API will fill-in
 */
struct bfa_timeval_s {
	u32	tv_sec;		/*  seconds        */
	u32	tv_usec;	/*  microseconds   */
};

K
Krishna Gudipati 已提交
171 172 173 174 175 176 177 178 179
static inline void
bfa_os_gettimeofday(struct bfa_timeval_s *tv)
{
	struct timeval  tmp_tv;

	do_gettimeofday(&tmp_tv);
	tv->tv_sec = (u32) tmp_tv.tv_sec;
	tv->tv_usec = (u32) tmp_tv.tv_usec;
}
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

static inline void
wwn2str(char *wwn_str, u64 wwn)
{
	union {
		u64 wwn;
		u8 byte[8];
	} w;

	w.wwn = wwn;
	sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
		w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
		w.byte[6], w.byte[7]);
}

static inline void
fcid2str(char *fcid_str, u32 fcid)
{
	union {
		u32 fcid;
		u8 byte[4];
	} f;

	f.fcid = fcid;
	sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
}

#endif /* __BFA_OS_INC_H__ */