bfa_os_inc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. * Contains declarations all OS Specific files needed for BFA layer
  19. */
  20. #ifndef __BFA_OS_INC_H__
  21. #define __BFA_OS_INC_H__
  22. #ifndef __KERNEL__
  23. #include <stdint.h>
  24. #else
  25. #include <linux/types.h>
  26. #include <linux/version.h>
  27. #include <linux/pci.h>
  28. #include <linux/dma-mapping.h>
  29. #define SET_MODULE_VERSION(VER)
  30. #include <linux/idr.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/cdev.h>
  33. #include <linux/fs.h>
  34. #include <linux/delay.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/workqueue.h>
  37. #include <scsi/scsi.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi_tcq.h>
  40. #include <scsi/scsi_transport_fc.h>
  41. #include <scsi/scsi_transport.h>
  42. #ifdef __BIG_ENDIAN
  43. #define __BIGENDIAN
  44. #endif
  45. #define BFA_ERR KERN_ERR
  46. #define BFA_WARNING KERN_WARNING
  47. #define BFA_NOTICE KERN_NOTICE
  48. #define BFA_INFO KERN_INFO
  49. #define BFA_DEBUG KERN_DEBUG
  50. #define LOG_BFAD_INIT 0x00000001
  51. #define LOG_FCP_IO 0x00000002
  52. #ifdef DEBUG
  53. #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...) \
  54. BFA_LOG(bfad, level, mask, fmt, ## arg)
  55. #define BFA_DEV_TRACE(bfad, level, fmt, arg...) \
  56. BFA_DEV_PRINTF(bfad, level, fmt, ## arg)
  57. #define BFA_TRACE(level, fmt, arg...) \
  58. BFA_PRINTF(level, fmt, ## arg)
  59. #else
  60. #define BFA_LOG_TRACE(bfad, level, mask, fmt, arg...)
  61. #define BFA_DEV_TRACE(bfad, level, fmt, arg...)
  62. #define BFA_TRACE(level, fmt, arg...)
  63. #endif
  64. #define BFA_ASSERT(p) do { \
  65. if (!(p)) { \
  66. printk(KERN_ERR "assert(%s) failed at %s:%d\n", \
  67. #p, __FILE__, __LINE__); \
  68. BUG(); \
  69. } \
  70. } while (0)
  71. #define BFA_LOG(bfad, level, mask, fmt, arg...) \
  72. do { \
  73. if (((mask) & (((struct bfad_s *)(bfad))-> \
  74. cfg_data[cfg_log_mask])) || (level[1] <= '3')) \
  75. dev_printk(level, &(((struct bfad_s *) \
  76. (bfad))->pcidev->dev), fmt, ##arg); \
  77. } while (0)
  78. #ifndef BFA_DEV_PRINTF
  79. #define BFA_DEV_PRINTF(bfad, level, fmt, arg...) \
  80. dev_printk(level, &(((struct bfad_s *) \
  81. (bfad))->pcidev->dev), fmt, ##arg);
  82. #endif
  83. #define BFA_PRINTF(level, fmt, arg...) \
  84. printk(level fmt, ##arg);
  85. int bfa_os_MWB(void *);
  86. #define bfa_os_mmiowb() mmiowb()
  87. #define bfa_swap_3b(_x) \
  88. ((((_x) & 0xff) << 16) | \
  89. ((_x) & 0x00ff00) | \
  90. (((_x) & 0xff0000) >> 16))
  91. #define bfa_swap_8b(_x) \
  92. ((((_x) & 0xff00000000000000ull) >> 56) \
  93. | (((_x) & 0x00ff000000000000ull) >> 40) \
  94. | (((_x) & 0x0000ff0000000000ull) >> 24) \
  95. | (((_x) & 0x000000ff00000000ull) >> 8) \
  96. | (((_x) & 0x00000000ff000000ull) << 8) \
  97. | (((_x) & 0x0000000000ff0000ull) << 24) \
  98. | (((_x) & 0x000000000000ff00ull) << 40) \
  99. | (((_x) & 0x00000000000000ffull) << 56))
  100. #define bfa_os_swap32(_x) \
  101. ((((_x) & 0xff) << 24) | \
  102. (((_x) & 0x0000ff00) << 8) | \
  103. (((_x) & 0x00ff0000) >> 8) | \
  104. (((_x) & 0xff000000) >> 24))
  105. #define bfa_os_swap_sgaddr(_x) ((u64)( \
  106. (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
  107. (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
  108. (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32) | \
  109. (((u64)(_x) & (u64)0x00000000ff000000ull) << 32) | \
  110. (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32) | \
  111. (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32) | \
  112. (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32) | \
  113. (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
  114. #ifndef __BIGENDIAN
  115. #define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
  116. (((_x) & 0x00ff) << 8)))
  117. #define bfa_os_htonl(_x) bfa_os_swap32(_x)
  118. #define bfa_os_htonll(_x) bfa_swap_8b(_x)
  119. #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
  120. #define bfa_os_wtole(_x) (_x)
  121. #define bfa_os_sgaddr(_x) (_x)
  122. #else
  123. #define bfa_os_htons(_x) (_x)
  124. #define bfa_os_htonl(_x) (_x)
  125. #define bfa_os_hton3b(_x) (_x)
  126. #define bfa_os_htonll(_x) (_x)
  127. #define bfa_os_wtole(_x) bfa_os_swap32(_x)
  128. #define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
  129. #endif
  130. #define bfa_os_ntohs(_x) bfa_os_htons(_x)
  131. #define bfa_os_ntohl(_x) bfa_os_htonl(_x)
  132. #define bfa_os_ntohll(_x) bfa_os_htonll(_x)
  133. #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
  134. #define bfa_os_u32(__pa64) ((__pa64) >> 32)
  135. #define bfa_os_memset memset
  136. #define bfa_os_memcpy memcpy
  137. #define bfa_os_udelay udelay
  138. #define bfa_os_vsprintf vsprintf
  139. #define bfa_os_assign(__t, __s) __t = __s
  140. #define bfa_os_addr_t char __iomem *
  141. #define bfa_os_panic()
  142. #define bfa_os_reg_read(_raddr) readl(_raddr)
  143. #define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
  144. #define bfa_os_mem_read(_raddr, _off) \
  145. bfa_os_swap32(readl(((_raddr) + (_off))))
  146. #define bfa_os_mem_write(_raddr, _off, _val) \
  147. writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
  148. #define BFA_TRC_TS(_trcm) \
  149. ({ \
  150. struct timeval tv; \
  151. \
  152. do_gettimeofday(&tv); \
  153. (tv.tv_sec*1000000+tv.tv_usec); \
  154. })
  155. struct bfa_log_mod_s;
  156. void bfa_os_printf(struct bfa_log_mod_s *log_mod, u32 msg_id,
  157. const char *fmt, ...);
  158. #endif
  159. #define boolean_t int
  160. /**
  161. * For current time stamp, OS API will fill-in
  162. */
  163. struct bfa_timeval_s {
  164. u32 tv_sec; /* seconds */
  165. u32 tv_usec; /* microseconds */
  166. };
  167. void bfa_os_gettimeofday(struct bfa_timeval_s *tv);
  168. static inline void
  169. wwn2str(char *wwn_str, u64 wwn)
  170. {
  171. union {
  172. u64 wwn;
  173. u8 byte[8];
  174. } w;
  175. w.wwn = wwn;
  176. sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
  177. w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
  178. w.byte[6], w.byte[7]);
  179. }
  180. static inline void
  181. fcid2str(char *fcid_str, u32 fcid)
  182. {
  183. union {
  184. u32 fcid;
  185. u8 byte[4];
  186. } f;
  187. f.fcid = fcid;
  188. sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
  189. }
  190. #endif /* __BFA_OS_INC_H__ */