Path: blob/master/drivers/infiniband/hw/ehca/ehca_tools.h
15112 views
/*1* IBM eServer eHCA Infiniband device driver for Linux on POWER2*3* auxiliary functions4*5* Authors: Christoph Raisch <[email protected]>6* Hoang-Nam Nguyen <[email protected]>7* Khadija Souissi <[email protected]>8* Waleri Fomin <[email protected]>9* Heiko J Schick <[email protected]>10*11* Copyright (c) 2005 IBM Corporation12*13* This source code is distributed under a dual license of GPL v2.0 and OpenIB14* BSD.15*16* OpenIB BSD License17*18* Redistribution and use in source and binary forms, with or without19* modification, are permitted provided that the following conditions are met:20*21* Redistributions of source code must retain the above copyright notice, this22* list of conditions and the following disclaimer.23*24* Redistributions in binary form must reproduce the above copyright notice,25* this list of conditions and the following disclaimer in the documentation26* and/or other materials27* provided with the distribution.28*29* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"30* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE31* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE32* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE33* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR34* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF35* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR36* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER37* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)38* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE39* POSSIBILITY OF SUCH DAMAGE.40*/414243#ifndef EHCA_TOOLS_H44#define EHCA_TOOLS_H4546#include <linux/kernel.h>47#include <linux/spinlock.h>48#include <linux/delay.h>49#include <linux/idr.h>50#include <linux/kthread.h>51#include <linux/mm.h>52#include <linux/mman.h>53#include <linux/module.h>54#include <linux/moduleparam.h>55#include <linux/vmalloc.h>56#include <linux/notifier.h>57#include <linux/cpu.h>58#include <linux/device.h>5960#include <asm/atomic.h>61#include <asm/abs_addr.h>62#include <asm/ibmebus.h>63#include <asm/io.h>64#include <asm/pgtable.h>65#include <asm/hvcall.h>6667extern int ehca_debug_level;6869#define ehca_dbg(ib_dev, format, arg...) \70do { \71if (unlikely(ehca_debug_level)) \72dev_printk(KERN_DEBUG, (ib_dev)->dma_device, \73"PU%04x EHCA_DBG:%s " format "\n", \74raw_smp_processor_id(), __func__, \75## arg); \76} while (0)7778#define ehca_info(ib_dev, format, arg...) \79dev_info((ib_dev)->dma_device, "PU%04x EHCA_INFO:%s " format "\n", \80raw_smp_processor_id(), __func__, ## arg)8182#define ehca_warn(ib_dev, format, arg...) \83dev_warn((ib_dev)->dma_device, "PU%04x EHCA_WARN:%s " format "\n", \84raw_smp_processor_id(), __func__, ## arg)8586#define ehca_err(ib_dev, format, arg...) \87dev_err((ib_dev)->dma_device, "PU%04x EHCA_ERR:%s " format "\n", \88raw_smp_processor_id(), __func__, ## arg)8990/* use this one only if no ib_dev available */91#define ehca_gen_dbg(format, arg...) \92do { \93if (unlikely(ehca_debug_level)) \94printk(KERN_DEBUG "PU%04x EHCA_DBG:%s " format "\n", \95raw_smp_processor_id(), __func__, ## arg); \96} while (0)9798#define ehca_gen_warn(format, arg...) \99printk(KERN_INFO "PU%04x EHCA_WARN:%s " format "\n", \100raw_smp_processor_id(), __func__, ## arg)101102#define ehca_gen_err(format, arg...) \103printk(KERN_ERR "PU%04x EHCA_ERR:%s " format "\n", \104raw_smp_processor_id(), __func__, ## arg)105106/**107* ehca_dmp - printk a memory block, whose length is n*8 bytes.108* Each line has the following layout:109* <format string> adr=X ofs=Y <8 bytes hex> <8 bytes hex>110*/111#define ehca_dmp(adr, len, format, args...) \112do { \113unsigned int x; \114unsigned int l = (unsigned int)(len); \115unsigned char *deb = (unsigned char *)(adr); \116for (x = 0; x < l; x += 16) { \117printk(KERN_INFO "EHCA_DMP:%s " format \118" adr=%p ofs=%04x %016llx %016llx\n", \119__func__, ##args, deb, x, \120*((u64 *)&deb[0]), *((u64 *)&deb[8])); \121deb += 16; \122} \123} while (0)124125/* define a bitmask, little endian version */126#define EHCA_BMASK(pos, length) (((pos) << 16) + (length))127128/* define a bitmask, the ibm way... */129#define EHCA_BMASK_IBM(from, to) (((63 - to) << 16) + ((to) - (from) + 1))130131/* internal function, don't use */132#define EHCA_BMASK_SHIFTPOS(mask) (((mask) >> 16) & 0xffff)133134/* internal function, don't use */135#define EHCA_BMASK_MASK(mask) (~0ULL >> ((64 - (mask)) & 0xffff))136137/**138* EHCA_BMASK_SET - return value shifted and masked by mask139* variable|=EHCA_BMASK_SET(MY_MASK,0x4711) ORs the bits in variable140* variable&=~EHCA_BMASK_SET(MY_MASK,-1) clears the bits from the mask141* in variable142*/143#define EHCA_BMASK_SET(mask, value) \144((EHCA_BMASK_MASK(mask) & ((u64)(value))) << EHCA_BMASK_SHIFTPOS(mask))145146/**147* EHCA_BMASK_GET - extract a parameter from value by mask148*/149#define EHCA_BMASK_GET(mask, value) \150(EHCA_BMASK_MASK(mask) & (((u64)(value)) >> EHCA_BMASK_SHIFTPOS(mask)))151152/* Converts ehca to ib return code */153int ehca2ib_return_code(u64 ehca_rc);154155#endif /* EHCA_TOOLS_H */156157158