1219820Sjeff/* 2219820Sjeff * Copyright (c) 2004 Topspin Communications. All rights reserved. 3219820Sjeff * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 4219820Sjeff * Copyright (c) 2005 Mellanox Technologies. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING in the main directory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use in source and binary forms, with or 13219820Sjeff * without modification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retain the above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions in binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer in the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32219820Sjeff * SOFTWARE. 33219820Sjeff */ 34219820Sjeff 35219820Sjeff#include <linux/types.h> 36219820Sjeff 37219820Sjeff#define MTHCA_RD_DOORBELL 0x00 38219820Sjeff#define MTHCA_SEND_DOORBELL 0x10 39219820Sjeff#define MTHCA_RECEIVE_DOORBELL 0x18 40219820Sjeff#define MTHCA_CQ_DOORBELL 0x20 41219820Sjeff#define MTHCA_EQ_DOORBELL 0x28 42219820Sjeff 43219820Sjeff#if BITS_PER_LONG == 64 44219820Sjeff/* 45219820Sjeff * Assume that we can just write a 64-bit doorbell atomically. s390 46219820Sjeff * actually doesn't have writeq() but S/390 systems don't even have 47219820Sjeff * PCI so we won't worry about it. 48219820Sjeff */ 49219820Sjeff 50219820Sjeff#define MTHCA_DECLARE_DOORBELL_LOCK(name) 51219820Sjeff#define MTHCA_INIT_DOORBELL_LOCK(ptr) do { } while (0) 52219820Sjeff#define MTHCA_GET_DOORBELL_LOCK(ptr) (NULL) 53219820Sjeff 54219820Sjeffstatic inline void mthca_write64_raw(__be64 val, void __iomem *dest) 55219820Sjeff{ 56219820Sjeff __raw_writeq((__force u64) val, dest); 57219820Sjeff} 58219820Sjeff 59219820Sjeffstatic inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest, 60219820Sjeff spinlock_t *doorbell_lock) 61219820Sjeff{ 62219820Sjeff __raw_writeq((__force u64) cpu_to_be64((u64) hi << 32 | lo), dest); 63219820Sjeff} 64219820Sjeff 65219820Sjeffstatic inline void mthca_write_db_rec(__be32 val[2], __be32 *db) 66219820Sjeff{ 67219820Sjeff *(u64 *) db = *(u64 *) val; 68219820Sjeff} 69219820Sjeff 70219820Sjeff#else 71219820Sjeff 72219820Sjeff/* 73219820Sjeff * Just fall back to a spinlock to protect the doorbell if 74219820Sjeff * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit 75219820Sjeff * MMIO writes. 76219820Sjeff */ 77219820Sjeff 78219820Sjeff#define MTHCA_DECLARE_DOORBELL_LOCK(name) spinlock_t name; 79219820Sjeff#define MTHCA_INIT_DOORBELL_LOCK(ptr) spin_lock_init(ptr) 80219820Sjeff#define MTHCA_GET_DOORBELL_LOCK(ptr) (ptr) 81219820Sjeff 82219820Sjeffstatic inline void mthca_write64_raw(__be64 val, void __iomem *dest) 83219820Sjeff{ 84219820Sjeff __raw_writel(((__force u32 *) &val)[0], dest); 85219820Sjeff __raw_writel(((__force u32 *) &val)[1], dest + 4); 86219820Sjeff} 87219820Sjeff 88219820Sjeffstatic inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest, 89219820Sjeff spinlock_t *doorbell_lock) 90219820Sjeff{ 91219820Sjeff unsigned long flags; 92219820Sjeff 93219820Sjeff hi = (__force u32) cpu_to_be32(hi); 94219820Sjeff lo = (__force u32) cpu_to_be32(lo); 95219820Sjeff 96219820Sjeff spin_lock_irqsave(doorbell_lock, flags); 97219820Sjeff __raw_writel(hi, dest); 98219820Sjeff __raw_writel(lo, dest + 4); 99219820Sjeff spin_unlock_irqrestore(doorbell_lock, flags); 100219820Sjeff} 101219820Sjeff 102219820Sjeffstatic inline void mthca_write_db_rec(__be32 val[2], __be32 *db) 103219820Sjeff{ 104219820Sjeff db[0] = val[0]; 105219820Sjeff wmb(); 106219820Sjeff db[1] = val[1]; 107219820Sjeff} 108219820Sjeff 109219820Sjeff#endif 110