Path: blob/master/drivers/infiniband/hw/mthca/mthca_doorbell.h
15112 views
/*1* Copyright (c) 2004 Topspin Communications. All rights reserved.2* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.3* Copyright (c) 2005 Mellanox Technologies. All rights reserved.4*5* This software is available to you under a choice of one of two6* licenses. You may choose to be licensed under the terms of the GNU7* General Public License (GPL) Version 2, available from the file8* COPYING in the main directory of this source tree, or the9* OpenIB.org BSD license below:10*11* Redistribution and use in source and binary forms, with or12* without modification, are permitted provided that the following13* conditions are met:14*15* - Redistributions of source code must retain the above16* copyright notice, this list of conditions and the following17* disclaimer.18*19* - Redistributions in binary form must reproduce the above20* copyright notice, this list of conditions and the following21* disclaimer in the documentation and/or other materials22* provided with the distribution.23*24* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,25* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF26* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND27* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS28* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN29* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN30* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE31* SOFTWARE.32*/3334#include <linux/types.h>3536#define MTHCA_RD_DOORBELL 0x0037#define MTHCA_SEND_DOORBELL 0x1038#define MTHCA_RECEIVE_DOORBELL 0x1839#define MTHCA_CQ_DOORBELL 0x2040#define MTHCA_EQ_DOORBELL 0x284142#if BITS_PER_LONG == 6443/*44* Assume that we can just write a 64-bit doorbell atomically. s39045* actually doesn't have writeq() but S/390 systems don't even have46* PCI so we won't worry about it.47*/4849#define MTHCA_DECLARE_DOORBELL_LOCK(name)50#define MTHCA_INIT_DOORBELL_LOCK(ptr) do { } while (0)51#define MTHCA_GET_DOORBELL_LOCK(ptr) (NULL)5253static inline void mthca_write64_raw(__be64 val, void __iomem *dest)54{55__raw_writeq((__force u64) val, dest);56}5758static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,59spinlock_t *doorbell_lock)60{61__raw_writeq((__force u64) cpu_to_be64((u64) hi << 32 | lo), dest);62}6364static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)65{66*(u64 *) db = *(u64 *) val;67}6869#else7071/*72* Just fall back to a spinlock to protect the doorbell if73* BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit74* MMIO writes.75*/7677#define MTHCA_DECLARE_DOORBELL_LOCK(name) spinlock_t name;78#define MTHCA_INIT_DOORBELL_LOCK(ptr) spin_lock_init(ptr)79#define MTHCA_GET_DOORBELL_LOCK(ptr) (ptr)8081static inline void mthca_write64_raw(__be64 val, void __iomem *dest)82{83__raw_writel(((__force u32 *) &val)[0], dest);84__raw_writel(((__force u32 *) &val)[1], dest + 4);85}8687static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,88spinlock_t *doorbell_lock)89{90unsigned long flags;9192hi = (__force u32) cpu_to_be32(hi);93lo = (__force u32) cpu_to_be32(lo);9495spin_lock_irqsave(doorbell_lock, flags);96__raw_writel(hi, dest);97__raw_writel(lo, dest + 4);98spin_unlock_irqrestore(doorbell_lock, flags);99}100101static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)102{103db[0] = val[0];104wmb();105db[1] = val[1];106}107108#endif109110111