ehca_tools.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * IBM eServer eHCA Infiniband device driver for Linux on POWER
  3. *
  4. * auxiliary functions
  5. *
  6. * Authors: Christoph Raisch <raisch@de.ibm.com>
  7. * Hoang-Nam Nguyen <hnguyen@de.ibm.com>
  8. * Khadija Souissi <souissik@de.ibm.com>
  9. * Waleri Fomin <fomin@de.ibm.com>
  10. * Heiko J Schick <schickhj@de.ibm.com>
  11. *
  12. * Copyright (c) 2005 IBM Corporation
  13. *
  14. * This source code is distributed under a dual license of GPL v2.0 and OpenIB
  15. * BSD.
  16. *
  17. * OpenIB BSD License
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions are met:
  21. *
  22. * Redistributions of source code must retain the above copyright notice, this
  23. * list of conditions and the following disclaimer.
  24. *
  25. * Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials
  28. * provided with the distribution.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  37. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  38. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGE.
  41. */
  42. #ifndef EHCA_TOOLS_H
  43. #define EHCA_TOOLS_H
  44. #include <linux/kernel.h>
  45. #include <linux/spinlock.h>
  46. #include <linux/delay.h>
  47. #include <linux/idr.h>
  48. #include <linux/kthread.h>
  49. #include <linux/mm.h>
  50. #include <linux/mman.h>
  51. #include <linux/module.h>
  52. #include <linux/moduleparam.h>
  53. #include <linux/vmalloc.h>
  54. #include <linux/version.h>
  55. #include <linux/notifier.h>
  56. #include <linux/cpu.h>
  57. #include <linux/device.h>
  58. #include <asm/atomic.h>
  59. #include <asm/abs_addr.h>
  60. #include <asm/ibmebus.h>
  61. #include <asm/io.h>
  62. #include <asm/pgtable.h>
  63. #include <asm/hvcall.h>
  64. extern int ehca_debug_level;
  65. #define ehca_dbg(ib_dev, format, arg...) \
  66. do { \
  67. if (unlikely(ehca_debug_level)) \
  68. dev_printk(KERN_DEBUG, (ib_dev)->dma_device, \
  69. "PU%04x EHCA_DBG:%s " format "\n", \
  70. get_paca()->paca_index, __FUNCTION__, \
  71. ## arg); \
  72. } while (0)
  73. #define ehca_info(ib_dev, format, arg...) \
  74. dev_info((ib_dev)->dma_device, "PU%04x EHCA_INFO:%s " format "\n", \
  75. get_paca()->paca_index, __FUNCTION__, ## arg)
  76. #define ehca_warn(ib_dev, format, arg...) \
  77. dev_warn((ib_dev)->dma_device, "PU%04x EHCA_WARN:%s " format "\n", \
  78. get_paca()->paca_index, __FUNCTION__, ## arg)
  79. #define ehca_err(ib_dev, format, arg...) \
  80. dev_err((ib_dev)->dma_device, "PU%04x EHCA_ERR:%s " format "\n", \
  81. get_paca()->paca_index, __FUNCTION__, ## arg)
  82. /* use this one only if no ib_dev available */
  83. #define ehca_gen_dbg(format, arg...) \
  84. do { \
  85. if (unlikely(ehca_debug_level)) \
  86. printk(KERN_DEBUG "PU%04x EHCA_DBG:%s " format "\n",\
  87. get_paca()->paca_index, __FUNCTION__, ## arg); \
  88. } while (0)
  89. #define ehca_gen_warn(format, arg...) \
  90. do { \
  91. if (unlikely(ehca_debug_level)) \
  92. printk(KERN_INFO "PU%04x EHCA_WARN:%s " format "\n",\
  93. get_paca()->paca_index, __FUNCTION__, ## arg); \
  94. } while (0)
  95. #define ehca_gen_err(format, arg...) \
  96. printk(KERN_ERR "PU%04x EHCA_ERR:%s " format "\n", \
  97. get_paca()->paca_index, __FUNCTION__, ## arg)
  98. /**
  99. * ehca_dmp - printk a memory block, whose length is n*8 bytes.
  100. * Each line has the following layout:
  101. * <format string> adr=X ofs=Y <8 bytes hex> <8 bytes hex>
  102. */
  103. #define ehca_dmp(adr, len, format, args...) \
  104. do { \
  105. unsigned int x; \
  106. unsigned int l = (unsigned int)(len); \
  107. unsigned char *deb = (unsigned char*)(adr); \
  108. for (x = 0; x < l; x += 16) { \
  109. printk("EHCA_DMP:%s " format \
  110. " adr=%p ofs=%04x %016lx %016lx\n", \
  111. __FUNCTION__, ##args, deb, x, \
  112. *((u64 *)&deb[0]), *((u64 *)&deb[8])); \
  113. deb += 16; \
  114. } \
  115. } while (0)
  116. /* define a bitmask, little endian version */
  117. #define EHCA_BMASK(pos,length) (((pos)<<16)+(length))
  118. /* define a bitmask, the ibm way... */
  119. #define EHCA_BMASK_IBM(from,to) (((63-to)<<16)+((to)-(from)+1))
  120. /* internal function, don't use */
  121. #define EHCA_BMASK_SHIFTPOS(mask) (((mask)>>16)&0xffff)
  122. /* internal function, don't use */
  123. #define EHCA_BMASK_MASK(mask) (0xffffffffffffffffULL >> ((64-(mask))&0xffff))
  124. /**
  125. * EHCA_BMASK_SET - return value shifted and masked by mask
  126. * variable|=EHCA_BMASK_SET(MY_MASK,0x4711) ORs the bits in variable
  127. * variable&=~EHCA_BMASK_SET(MY_MASK,-1) clears the bits from the mask
  128. * in variable
  129. */
  130. #define EHCA_BMASK_SET(mask,value) \
  131. ((EHCA_BMASK_MASK(mask) & ((u64)(value)))<<EHCA_BMASK_SHIFTPOS(mask))
  132. /**
  133. * EHCA_BMASK_GET - extract a parameter from value by mask
  134. */
  135. #define EHCA_BMASK_GET(mask,value) \
  136. (EHCA_BMASK_MASK(mask)& (((u64)(value))>>EHCA_BMASK_SHIFTPOS(mask)))
  137. /* Converts ehca to ib return code */
  138. static inline int ehca2ib_return_code(u64 ehca_rc)
  139. {
  140. switch (ehca_rc) {
  141. case H_SUCCESS:
  142. return 0;
  143. case H_BUSY:
  144. return -EBUSY;
  145. case H_NO_MEM:
  146. return -ENOMEM;
  147. default:
  148. return -EINVAL;
  149. }
  150. }
  151. #endif /* EHCA_TOOLS_H */