1dc7e38acSHans Petter Selasky /*- 27b9b93a8SHans Petter Selasky * Copyright (c) 2013-2017, Mellanox Technologies, Ltd. All rights reserved. 3dc7e38acSHans Petter Selasky * 4dc7e38acSHans Petter Selasky * Redistribution and use in source and binary forms, with or without 5dc7e38acSHans Petter Selasky * modification, are permitted provided that the following conditions 6dc7e38acSHans Petter Selasky * are met: 7dc7e38acSHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 8dc7e38acSHans Petter Selasky * notice, this list of conditions and the following disclaimer. 9dc7e38acSHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 10dc7e38acSHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 11dc7e38acSHans Petter Selasky * documentation and/or other materials provided with the distribution. 12dc7e38acSHans Petter Selasky * 13dc7e38acSHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND 14dc7e38acSHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15dc7e38acSHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16dc7e38acSHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17dc7e38acSHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18dc7e38acSHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19dc7e38acSHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20dc7e38acSHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21dc7e38acSHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22dc7e38acSHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23dc7e38acSHans Petter Selasky * SUCH DAMAGE. 24dc7e38acSHans Petter Selasky */ 25dc7e38acSHans Petter Selasky 26dc7e38acSHans Petter Selasky #ifndef MLX5_DOORBELL_H 27dc7e38acSHans Petter Selasky #define MLX5_DOORBELL_H 28dc7e38acSHans Petter Selasky 29dc7e38acSHans Petter Selasky #define MLX5_BF_OFFSET 0x800 30dc7e38acSHans Petter Selasky #define MLX5_CQ_DOORBELL 0x20 31dc7e38acSHans Petter Selasky 32dc7e38acSHans Petter Selasky #if BITS_PER_LONG == 64 33dc7e38acSHans Petter Selasky /* Assume that we can just write a 64-bit doorbell atomically. s390 34dc7e38acSHans Petter Selasky * actually doesn't have writeq() but S/390 systems don't even have 35dc7e38acSHans Petter Selasky * PCI so we won't worry about it. 36dc7e38acSHans Petter Selasky */ 37dc7e38acSHans Petter Selasky 38dc7e38acSHans Petter Selasky #define MLX5_DECLARE_DOORBELL_LOCK(name) 39dc7e38acSHans Petter Selasky #define MLX5_INIT_DOORBELL_LOCK(ptr) do { } while (0) 40dc7e38acSHans Petter Selasky #define MLX5_GET_DOORBELL_LOCK(ptr) (NULL) 41dc7e38acSHans Petter Selasky 42dc7e38acSHans Petter Selasky static inline void mlx5_write64(__be32 val[2], void __iomem *dest, 43dc7e38acSHans Petter Selasky spinlock_t *doorbell_lock) 44dc7e38acSHans Petter Selasky { 45dc7e38acSHans Petter Selasky __raw_writeq(*(u64 *)val, dest); 46dc7e38acSHans Petter Selasky } 47dc7e38acSHans Petter Selasky 48dc7e38acSHans Petter Selasky #else 49dc7e38acSHans Petter Selasky 50dc7e38acSHans Petter Selasky /* Just fall back to a spinlock to protect the doorbell if 51dc7e38acSHans Petter Selasky * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit 52dc7e38acSHans Petter Selasky * MMIO writes. 53dc7e38acSHans Petter Selasky */ 54dc7e38acSHans Petter Selasky 55dc7e38acSHans Petter Selasky #define MLX5_DECLARE_DOORBELL_LOCK(name) spinlock_t name; 56dc7e38acSHans Petter Selasky #define MLX5_INIT_DOORBELL_LOCK(ptr) spin_lock_init(ptr) 57dc7e38acSHans Petter Selasky #define MLX5_GET_DOORBELL_LOCK(ptr) (ptr) 58dc7e38acSHans Petter Selasky 59dc7e38acSHans Petter Selasky static inline void mlx5_write64(__be32 val[2], void __iomem *dest, 60dc7e38acSHans Petter Selasky spinlock_t *doorbell_lock) 61dc7e38acSHans Petter Selasky { 62dc7e38acSHans Petter Selasky unsigned long flags; 63dc7e38acSHans Petter Selasky 64*e23731dbSKonstantin Belousov if (doorbell_lock) 65dc7e38acSHans Petter Selasky spin_lock_irqsave(doorbell_lock, flags); 66dc7e38acSHans Petter Selasky __raw_writel((__force u32) val[0], dest); 67dc7e38acSHans Petter Selasky __raw_writel((__force u32) val[1], dest + 4); 68*e23731dbSKonstantin Belousov if (doorbell_lock) 69dc7e38acSHans Petter Selasky spin_unlock_irqrestore(doorbell_lock, flags); 70dc7e38acSHans Petter Selasky } 71dc7e38acSHans Petter Selasky 72dc7e38acSHans Petter Selasky #endif 73dc7e38acSHans Petter Selasky 74dc7e38acSHans Petter Selasky #endif /* MLX5_DOORBELL_H */ 75