doorbell.h revision 292107
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#ifndef MLX4_DOORBELL_H 36219820Sjeff#define MLX4_DOORBELL_H 37219820Sjeff 38219820Sjeff#include <linux/types.h> 39219820Sjeff#include <linux/io.h> 40219820Sjeff 41219820Sjeff#define MLX4_SEND_DOORBELL 0x14 42219820Sjeff#define MLX4_CQ_DOORBELL 0x20 43219820Sjeff 44219820Sjeff#if BITS_PER_LONG == 64 45219820Sjeff/* 46219820Sjeff * Assume that we can just write a 64-bit doorbell atomically. s390 47219820Sjeff * actually doesn't have writeq() but S/390 systems don't even have 48219820Sjeff * PCI so we won't worry about it. 49219820Sjeff */ 50219820Sjeff 51219820Sjeff#define MLX4_DECLARE_DOORBELL_LOCK(name) 52219820Sjeff#define MLX4_INIT_DOORBELL_LOCK(ptr) do { } while (0) 53219820Sjeff#define MLX4_GET_DOORBELL_LOCK(ptr) (NULL) 54219820Sjeff 55219820Sjeffstatic inline void mlx4_write64(__be32 val[2], void __iomem *dest, 56219820Sjeff spinlock_t *doorbell_lock) 57219820Sjeff{ 58219820Sjeff __raw_writeq(*(u64 *) val, dest); 59219820Sjeff} 60219820Sjeff 61219820Sjeff#else 62219820Sjeff 63219820Sjeff/* 64219820Sjeff * Just fall back to a spinlock to protect the doorbell if 65219820Sjeff * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit 66219820Sjeff * MMIO writes. 67219820Sjeff */ 68219820Sjeff 69219820Sjeff#define MLX4_DECLARE_DOORBELL_LOCK(name) spinlock_t name; 70219820Sjeff#define MLX4_INIT_DOORBELL_LOCK(ptr) spin_lock_init(ptr) 71219820Sjeff#define MLX4_GET_DOORBELL_LOCK(ptr) (ptr) 72219820Sjeff 73219820Sjeffstatic inline void mlx4_write64(__be32 val[2], void __iomem *dest, 74219820Sjeff spinlock_t *doorbell_lock) 75219820Sjeff{ 76219820Sjeff unsigned long flags; 77219820Sjeff 78219820Sjeff spin_lock_irqsave(doorbell_lock, flags); 79219820Sjeff __raw_writel((__force u32) val[0], dest); 80292107Shselasky __raw_writel((__force u32) val[1], (u8 *)dest + 4); 81219820Sjeff spin_unlock_irqrestore(doorbell_lock, flags); 82219820Sjeff} 83219820Sjeff 84219820Sjeff#endif 85219820Sjeff 86219820Sjeff#endif /* MLX4_DOORBELL_H */ 87