bfa_os_inc.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (c) 2005-2010 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. #ifndef __BFA_OS_INC_H__
  18. #define __BFA_OS_INC_H__
  19. #include <linux/types.h>
  20. #include <linux/version.h>
  21. #include <linux/pci.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/idr.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/cdev.h>
  26. #include <linux/fs.h>
  27. #include <linux/delay.h>
  28. #include <linux/vmalloc.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/bitops.h>
  31. #include <scsi/scsi.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_tcq.h>
  34. #include <scsi/scsi_transport_fc.h>
  35. #include <scsi/scsi_transport.h>
  36. #ifdef __BIG_ENDIAN
  37. #define __BIGENDIAN
  38. #endif
  39. static inline u64 bfa_os_get_log_time(void)
  40. {
  41. u64 system_time = 0;
  42. struct timeval tv;
  43. do_gettimeofday(&tv);
  44. /* We are interested in seconds only. */
  45. system_time = tv.tv_sec;
  46. return system_time;
  47. }
  48. #define bfa_io_lat_clock_res_div HZ
  49. #define bfa_io_lat_clock_res_mul 1000
  50. #define BFA_LOG(level, bfad, mask, fmt, arg...) \
  51. do { \
  52. if (((mask) == 4) || (level[1] <= '4')) \
  53. dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \
  54. } while (0)
  55. #define bfa_swap_3b(_x) \
  56. ((((_x) & 0xff) << 16) | \
  57. ((_x) & 0x00ff00) | \
  58. (((_x) & 0xff0000) >> 16))
  59. #define bfa_os_swap_sgaddr(_x) ((u64)( \
  60. (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
  61. (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
  62. (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32) | \
  63. (((u64)(_x) & (u64)0x00000000ff000000ull) << 32) | \
  64. (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32) | \
  65. (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32) | \
  66. (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32) | \
  67. (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
  68. #ifndef __BIGENDIAN
  69. #define bfa_os_hton3b(_x) bfa_swap_3b(_x)
  70. #define bfa_os_sgaddr(_x) (_x)
  71. #else
  72. #define bfa_os_hton3b(_x) (_x)
  73. #define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
  74. #endif
  75. #define bfa_os_ntoh3b(_x) bfa_os_hton3b(_x)
  76. #define bfa_os_u32(__pa64) ((__pa64) >> 32)
  77. #define BFA_TRC_TS(_trcm) \
  78. ({ \
  79. struct timeval tv; \
  80. \
  81. do_gettimeofday(&tv); \
  82. (tv.tv_sec*1000000+tv.tv_usec); \
  83. })
  84. #define boolean_t int
  85. /**
  86. * For current time stamp, OS API will fill-in
  87. */
  88. struct bfa_timeval_s {
  89. u32 tv_sec; /* seconds */
  90. u32 tv_usec; /* microseconds */
  91. };
  92. static inline void
  93. bfa_os_gettimeofday(struct bfa_timeval_s *tv)
  94. {
  95. struct timeval tmp_tv;
  96. do_gettimeofday(&tmp_tv);
  97. tv->tv_sec = (u32) tmp_tv.tv_sec;
  98. tv->tv_usec = (u32) tmp_tv.tv_usec;
  99. }
  100. static inline void
  101. wwn2str(char *wwn_str, u64 wwn)
  102. {
  103. union {
  104. u64 wwn;
  105. u8 byte[8];
  106. } w;
  107. w.wwn = wwn;
  108. sprintf(wwn_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", w.byte[0],
  109. w.byte[1], w.byte[2], w.byte[3], w.byte[4], w.byte[5],
  110. w.byte[6], w.byte[7]);
  111. }
  112. static inline void
  113. fcid2str(char *fcid_str, u32 fcid)
  114. {
  115. union {
  116. u32 fcid;
  117. u8 byte[4];
  118. } f;
  119. f.fcid = fcid;
  120. sprintf(fcid_str, "%02x:%02x:%02x", f.byte[1], f.byte[2], f.byte[3]);
  121. }
  122. #endif /* __BFA_OS_INC_H__ */