2006-09-22 22:22:22 +00:00
|
|
|
/*
|
|
|
|
* IBM eServer eHCA Infiniband device driver for Linux on POWER
|
|
|
|
*
|
|
|
|
* auxiliary functions
|
|
|
|
*
|
|
|
|
* Authors: Christoph Raisch <raisch@de.ibm.com>
|
|
|
|
* Hoang-Nam Nguyen <hnguyen@de.ibm.com>
|
|
|
|
* Khadija Souissi <souissik@de.ibm.com>
|
|
|
|
* Waleri Fomin <fomin@de.ibm.com>
|
|
|
|
* Heiko J Schick <schickhj@de.ibm.com>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 IBM Corporation
|
|
|
|
*
|
|
|
|
* This source code is distributed under a dual license of GPL v2.0 and OpenIB
|
|
|
|
* BSD.
|
|
|
|
*
|
|
|
|
* OpenIB BSD License
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
|
|
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef EHCA_TOOLS_H
|
|
|
|
#define EHCA_TOOLS_H
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/mman.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/notifier.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
2007-07-09 13:30:39 +00:00
|
|
|
#include <asm/atomic.h>
|
2006-09-22 22:22:22 +00:00
|
|
|
#include <asm/abs_addr.h>
|
|
|
|
#include <asm/ibmebus.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/pgtable.h>
|
2006-10-25 05:28:08 +00:00
|
|
|
#include <asm/hvcall.h>
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
extern int ehca_debug_level;
|
|
|
|
|
|
|
|
#define ehca_dbg(ib_dev, format, arg...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(ehca_debug_level)) \
|
|
|
|
dev_printk(KERN_DEBUG, (ib_dev)->dma_device, \
|
|
|
|
"PU%04x EHCA_DBG:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, \
|
2006-09-22 22:22:22 +00:00
|
|
|
## arg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ehca_info(ib_dev, format, arg...) \
|
|
|
|
dev_info((ib_dev)->dma_device, "PU%04x EHCA_INFO:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
#define ehca_warn(ib_dev, format, arg...) \
|
|
|
|
dev_warn((ib_dev)->dma_device, "PU%04x EHCA_WARN:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
#define ehca_err(ib_dev, format, arg...) \
|
|
|
|
dev_err((ib_dev)->dma_device, "PU%04x EHCA_ERR:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* use this one only if no ib_dev available */
|
|
|
|
#define ehca_gen_dbg(format, arg...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(ehca_debug_level)) \
|
2007-07-12 15:53:47 +00:00
|
|
|
printk(KERN_DEBUG "PU%04x EHCA_DBG:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg); \
|
2006-09-22 22:22:22 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ehca_gen_warn(format, arg...) \
|
2007-09-11 13:32:50 +00:00
|
|
|
printk(KERN_INFO "PU%04x EHCA_WARN:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
#define ehca_gen_err(format, arg...) \
|
|
|
|
printk(KERN_ERR "PU%04x EHCA_ERR:%s " format "\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
raw_smp_processor_id(), __func__, ## arg)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ehca_dmp - printk a memory block, whose length is n*8 bytes.
|
|
|
|
* Each line has the following layout:
|
|
|
|
* <format string> adr=X ofs=Y <8 bytes hex> <8 bytes hex>
|
|
|
|
*/
|
|
|
|
#define ehca_dmp(adr, len, format, args...) \
|
2007-07-12 15:53:47 +00:00
|
|
|
do { \
|
|
|
|
unsigned int x; \
|
2006-09-22 22:22:22 +00:00
|
|
|
unsigned int l = (unsigned int)(len); \
|
2007-07-12 15:53:47 +00:00
|
|
|
unsigned char *deb = (unsigned char *)(adr); \
|
2006-09-22 22:22:22 +00:00
|
|
|
for (x = 0; x < l; x += 16) { \
|
2007-07-12 15:53:47 +00:00
|
|
|
printk(KERN_INFO "EHCA_DMP:%s " format \
|
2009-01-16 22:55:28 +00:00
|
|
|
" adr=%p ofs=%04x %016llx %016llx\n", \
|
2008-04-17 04:01:10 +00:00
|
|
|
__func__, ##args, deb, x, \
|
2006-09-22 22:22:22 +00:00
|
|
|
*((u64 *)&deb[0]), *((u64 *)&deb[8])); \
|
|
|
|
deb += 16; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* define a bitmask, little endian version */
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK(pos, length) (((pos) << 16) + (length))
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* define a bitmask, the ibm way... */
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1))
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* internal function, don't use */
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff)
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* internal function, don't use */
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK_MASK(mask) (~0ULL >> ((64 - (mask)) & 0xffff))
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EHCA_BMASK_SET - return value shifted and masked by mask
|
|
|
|
* variable|=EHCA_BMASK_SET(MY_MASK,0x4711) ORs the bits in variable
|
|
|
|
* variable&=~EHCA_BMASK_SET(MY_MASK,-1) clears the bits from the mask
|
|
|
|
* in variable
|
|
|
|
*/
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK_SET(mask, value) \
|
|
|
|
((EHCA_BMASK_MASK(mask) & ((u64)(value))) << EHCA_BMASK_SHIFTPOS(mask))
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EHCA_BMASK_GET - extract a parameter from value by mask
|
|
|
|
*/
|
2007-07-12 15:53:47 +00:00
|
|
|
#define EHCA_BMASK_GET(mask, value) \
|
|
|
|
(EHCA_BMASK_MASK(mask) & (((u64)(value)) >> EHCA_BMASK_SHIFTPOS(mask)))
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
/* Converts ehca to ib return code */
|
2007-07-20 14:02:46 +00:00
|
|
|
int ehca2ib_return_code(u64 ehca_rc);
|
2006-09-22 22:22:22 +00:00
|
|
|
|
|
|
|
#endif /* EHCA_TOOLS_H */
|