Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 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 | |
| 43 | |
| 44 | #ifndef EHCA_TOOLS_H |
| 45 | #define EHCA_TOOLS_H |
| 46 | |
| 47 | #include <linux/kernel.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | #include <linux/delay.h> |
| 50 | #include <linux/idr.h> |
| 51 | #include <linux/kthread.h> |
| 52 | #include <linux/mm.h> |
| 53 | #include <linux/mman.h> |
| 54 | #include <linux/module.h> |
| 55 | #include <linux/moduleparam.h> |
| 56 | #include <linux/vmalloc.h> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 57 | #include <linux/notifier.h> |
| 58 | #include <linux/cpu.h> |
| 59 | #include <linux/device.h> |
| 60 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 61 | #include <linux/atomic.h> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 62 | #include <asm/abs_addr.h> |
| 63 | #include <asm/ibmebus.h> |
| 64 | #include <asm/io.h> |
| 65 | #include <asm/pgtable.h> |
Paul Mackerras | 04d03bc | 2006-10-25 15:28:08 +1000 | [diff] [blame] | 66 | #include <asm/hvcall.h> |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 67 | |
| 68 | extern int ehca_debug_level; |
| 69 | |
| 70 | #define ehca_dbg(ib_dev, format, arg...) \ |
| 71 | do { \ |
| 72 | if (unlikely(ehca_debug_level)) \ |
| 73 | dev_printk(KERN_DEBUG, (ib_dev)->dma_device, \ |
| 74 | "PU%04x EHCA_DBG:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 75 | raw_smp_processor_id(), __func__, \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 76 | ## arg); \ |
| 77 | } while (0) |
| 78 | |
| 79 | #define ehca_info(ib_dev, format, arg...) \ |
| 80 | dev_info((ib_dev)->dma_device, "PU%04x EHCA_INFO:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 81 | raw_smp_processor_id(), __func__, ## arg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 82 | |
| 83 | #define ehca_warn(ib_dev, format, arg...) \ |
| 84 | dev_warn((ib_dev)->dma_device, "PU%04x EHCA_WARN:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 85 | raw_smp_processor_id(), __func__, ## arg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 86 | |
| 87 | #define ehca_err(ib_dev, format, arg...) \ |
| 88 | dev_err((ib_dev)->dma_device, "PU%04x EHCA_ERR:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 89 | raw_smp_processor_id(), __func__, ## arg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 90 | |
| 91 | /* use this one only if no ib_dev available */ |
| 92 | #define ehca_gen_dbg(format, arg...) \ |
| 93 | do { \ |
| 94 | if (unlikely(ehca_debug_level)) \ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 95 | printk(KERN_DEBUG "PU%04x EHCA_DBG:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 96 | raw_smp_processor_id(), __func__, ## arg); \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 97 | } while (0) |
| 98 | |
| 99 | #define ehca_gen_warn(format, arg...) \ |
Joachim Fenkes | 86dce44 | 2007-09-11 15:32:50 +0200 | [diff] [blame] | 100 | printk(KERN_INFO "PU%04x EHCA_WARN:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 101 | raw_smp_processor_id(), __func__, ## arg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 102 | |
| 103 | #define ehca_gen_err(format, arg...) \ |
| 104 | printk(KERN_ERR "PU%04x EHCA_ERR:%s " format "\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 105 | raw_smp_processor_id(), __func__, ## arg) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * ehca_dmp - printk a memory block, whose length is n*8 bytes. |
| 109 | * Each line has the following layout: |
| 110 | * <format string> adr=X ofs=Y <8 bytes hex> <8 bytes hex> |
| 111 | */ |
| 112 | #define ehca_dmp(adr, len, format, args...) \ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 113 | do { \ |
| 114 | unsigned int x; \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 115 | unsigned int l = (unsigned int)(len); \ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 116 | unsigned char *deb = (unsigned char *)(adr); \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 117 | for (x = 0; x < l; x += 16) { \ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 118 | printk(KERN_INFO "EHCA_DMP:%s " format \ |
Stephen Rothwell | 3750f60 | 2009-01-16 14:55:28 -0800 | [diff] [blame] | 119 | " adr=%p ofs=%04x %016llx %016llx\n", \ |
Harvey Harrison | 3371836 | 2008-04-16 21:01:10 -0700 | [diff] [blame] | 120 | __func__, ##args, deb, x, \ |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 121 | *((u64 *)&deb[0]), *((u64 *)&deb[8])); \ |
| 122 | deb += 16; \ |
| 123 | } \ |
| 124 | } while (0) |
| 125 | |
| 126 | /* define a bitmask, little endian version */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 127 | #define EHCA_BMASK(pos, length) (((pos) << 16) + (length)) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 128 | |
| 129 | /* define a bitmask, the ibm way... */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 130 | #define EHCA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1)) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 131 | |
| 132 | /* internal function, don't use */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 133 | #define EHCA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 134 | |
| 135 | /* internal function, don't use */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 136 | #define EHCA_BMASK_MASK(mask) (~0ULL >> ((64 - (mask)) & 0xffff)) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * EHCA_BMASK_SET - return value shifted and masked by mask |
| 140 | * variable|=EHCA_BMASK_SET(MY_MASK,0x4711) ORs the bits in variable |
| 141 | * variable&=~EHCA_BMASK_SET(MY_MASK,-1) clears the bits from the mask |
| 142 | * in variable |
| 143 | */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 144 | #define EHCA_BMASK_SET(mask, value) \ |
| 145 | ((EHCA_BMASK_MASK(mask) & ((u64)(value))) << EHCA_BMASK_SHIFTPOS(mask)) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * EHCA_BMASK_GET - extract a parameter from value by mask |
| 149 | */ |
Hoang-Nam Nguyen | 2b94397 | 2007-07-12 17:53:47 +0200 | [diff] [blame] | 150 | #define EHCA_BMASK_GET(mask, value) \ |
| 151 | (EHCA_BMASK_MASK(mask) & (((u64)(value)) >> EHCA_BMASK_SHIFTPOS(mask))) |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 152 | |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 153 | /* Converts ehca to ib return code */ |
Hoang-Nam Nguyen | 51d2bfb | 2007-07-20 16:02:46 +0200 | [diff] [blame] | 154 | int ehca2ib_return_code(u64 ehca_rc); |
Heiko J Schick | fab9722 | 2006-09-22 15:22:22 -0700 | [diff] [blame] | 155 | |
| 156 | #endif /* EHCA_TOOLS_H */ |