xref: /openbmc/linux/drivers/infiniband/hw/mthca/mthca_doorbell.h (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
3cd4e8fb4STom Duffy  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
42a1d9b7fSRoland Dreier  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  * This software is available to you under a choice of one of two
71da177e4SLinus Torvalds  * licenses.  You may choose to be licensed under the terms of the GNU
81da177e4SLinus Torvalds  * General Public License (GPL) Version 2, available from the file
91da177e4SLinus Torvalds  * COPYING in the main directory of this source tree, or the
101da177e4SLinus Torvalds  * OpenIB.org BSD license below:
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *     Redistribution and use in source and binary forms, with or
131da177e4SLinus Torvalds  *     without modification, are permitted provided that the following
141da177e4SLinus Torvalds  *     conditions are met:
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *      - Redistributions of source code must retain the above
171da177e4SLinus Torvalds  *        copyright notice, this list of conditions and the following
181da177e4SLinus Torvalds  *        disclaimer.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  *      - Redistributions in binary form must reproduce the above
211da177e4SLinus Torvalds  *        copyright notice, this list of conditions and the following
221da177e4SLinus Torvalds  *        disclaimer in the documentation and/or other materials
231da177e4SLinus Torvalds  *        provided with the distribution.
241da177e4SLinus Torvalds  *
251da177e4SLinus Torvalds  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
261da177e4SLinus Torvalds  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
271da177e4SLinus Torvalds  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
281da177e4SLinus Torvalds  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
291da177e4SLinus Torvalds  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
301da177e4SLinus Torvalds  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
311da177e4SLinus Torvalds  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
321da177e4SLinus Torvalds  * SOFTWARE.
331da177e4SLinus Torvalds  */
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds #include <linux/types.h>
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #define MTHCA_RD_DOORBELL      0x00
381da177e4SLinus Torvalds #define MTHCA_SEND_DOORBELL    0x10
391da177e4SLinus Torvalds #define MTHCA_RECEIVE_DOORBELL 0x18
401da177e4SLinus Torvalds #define MTHCA_CQ_DOORBELL      0x20
411da177e4SLinus Torvalds #define MTHCA_EQ_DOORBELL      0x28
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds #if BITS_PER_LONG == 64
441da177e4SLinus Torvalds /*
451da177e4SLinus Torvalds  * Assume that we can just write a 64-bit doorbell atomically.  s390
461da177e4SLinus Torvalds  * actually doesn't have writeq() but S/390 systems don't even have
471da177e4SLinus Torvalds  * PCI so we won't worry about it.
481da177e4SLinus Torvalds  */
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds #define MTHCA_DECLARE_DOORBELL_LOCK(name)
511da177e4SLinus Torvalds #define MTHCA_INIT_DOORBELL_LOCK(ptr)    do { } while (0)
521da177e4SLinus Torvalds #define MTHCA_GET_DOORBELL_LOCK(ptr)      (NULL)
531da177e4SLinus Torvalds 
mthca_write64_raw(__be64 val,void __iomem * dest)54ef416a33SMichael S. Tsirkin static inline void mthca_write64_raw(__be64 val, void __iomem *dest)
55ef416a33SMichael S. Tsirkin {
56ef416a33SMichael S. Tsirkin 	__raw_writeq((__force u64) val, dest);
57ef416a33SMichael S. Tsirkin }
58ef416a33SMichael S. Tsirkin 
mthca_write64(u32 hi,u32 lo,void __iomem * dest,spinlock_t * doorbell_lock)59*ab8403c4SRoland Dreier static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,
601da177e4SLinus Torvalds 				 spinlock_t *doorbell_lock)
611da177e4SLinus Torvalds {
62*ab8403c4SRoland Dreier 	__raw_writeq((__force u64) cpu_to_be64((u64) hi << 32 | lo), dest);
631da177e4SLinus Torvalds }
641da177e4SLinus Torvalds 
mthca_write_db_rec(__be32 val[2],__be32 * db)6597f52eb4SSean Hefty static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)
661da177e4SLinus Torvalds {
671da177e4SLinus Torvalds 	*(u64 *) db = *(u64 *) val;
681da177e4SLinus Torvalds }
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds #else
711da177e4SLinus Torvalds 
721da177e4SLinus Torvalds /*
731da177e4SLinus Torvalds  * Just fall back to a spinlock to protect the doorbell if
741da177e4SLinus Torvalds  * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit
751da177e4SLinus Torvalds  * MMIO writes.
761da177e4SLinus Torvalds  */
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds #define MTHCA_DECLARE_DOORBELL_LOCK(name) spinlock_t name;
791da177e4SLinus Torvalds #define MTHCA_INIT_DOORBELL_LOCK(ptr)     spin_lock_init(ptr)
801da177e4SLinus Torvalds #define MTHCA_GET_DOORBELL_LOCK(ptr)      (ptr)
811da177e4SLinus Torvalds 
mthca_write64_raw(__be64 val,void __iomem * dest)82ef416a33SMichael S. Tsirkin static inline void mthca_write64_raw(__be64 val, void __iomem *dest)
83ef416a33SMichael S. Tsirkin {
84ef416a33SMichael S. Tsirkin 	__raw_writel(((__force u32 *) &val)[0], dest);
85ef416a33SMichael S. Tsirkin 	__raw_writel(((__force u32 *) &val)[1], dest + 4);
86ef416a33SMichael S. Tsirkin }
87ef416a33SMichael S. Tsirkin 
mthca_write64(u32 hi,u32 lo,void __iomem * dest,spinlock_t * doorbell_lock)88*ab8403c4SRoland Dreier static inline void mthca_write64(u32 hi, u32 lo, void __iomem *dest,
891da177e4SLinus Torvalds 				 spinlock_t *doorbell_lock)
901da177e4SLinus Torvalds {
911da177e4SLinus Torvalds 	unsigned long flags;
921da177e4SLinus Torvalds 
93*ab8403c4SRoland Dreier 	hi = (__force u32) cpu_to_be32(hi);
94*ab8403c4SRoland Dreier 	lo = (__force u32) cpu_to_be32(lo);
95*ab8403c4SRoland Dreier 
961da177e4SLinus Torvalds 	spin_lock_irqsave(doorbell_lock, flags);
97*ab8403c4SRoland Dreier 	__raw_writel(hi, dest);
98*ab8403c4SRoland Dreier 	__raw_writel(lo, dest + 4);
991da177e4SLinus Torvalds 	spin_unlock_irqrestore(doorbell_lock, flags);
1001da177e4SLinus Torvalds }
1011da177e4SLinus Torvalds 
mthca_write_db_rec(__be32 val[2],__be32 * db)10297f52eb4SSean Hefty static inline void mthca_write_db_rec(__be32 val[2], __be32 *db)
1031da177e4SLinus Torvalds {
1041da177e4SLinus Torvalds 	db[0] = val[0];
1051da177e4SLinus Torvalds 	wmb();
1061da177e4SLinus Torvalds 	db[1] = val[1];
1071da177e4SLinus Torvalds }
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds #endif
110