bfa_os_inc.h 5.5 KB

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