xref: /freebsd/sys/dev/mlx4/doorbell.h (revision 242b24828472137ec4411826b86e753d49bd2c39)
1*97549c34SHans Petter Selasky /*
2*97549c34SHans Petter Selasky  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
3*97549c34SHans Petter Selasky  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4*97549c34SHans Petter Selasky  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5*97549c34SHans Petter Selasky  *
6*97549c34SHans Petter Selasky  * This software is available to you under a choice of one of two
7*97549c34SHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
8*97549c34SHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
9*97549c34SHans Petter Selasky  * COPYING in the main directory of this source tree, or the
10*97549c34SHans Petter Selasky  * OpenIB.org BSD license below:
11*97549c34SHans Petter Selasky  *
12*97549c34SHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
13*97549c34SHans Petter Selasky  *     without modification, are permitted provided that the following
14*97549c34SHans Petter Selasky  *     conditions are met:
15*97549c34SHans Petter Selasky  *
16*97549c34SHans Petter Selasky  *      - Redistributions of source code must retain the above
17*97549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
18*97549c34SHans Petter Selasky  *        disclaimer.
19*97549c34SHans Petter Selasky  *
20*97549c34SHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
21*97549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
22*97549c34SHans Petter Selasky  *        disclaimer in the documentation and/or other materials
23*97549c34SHans Petter Selasky  *        provided with the distribution.
24*97549c34SHans Petter Selasky  *
25*97549c34SHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26*97549c34SHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27*97549c34SHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28*97549c34SHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29*97549c34SHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30*97549c34SHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31*97549c34SHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32*97549c34SHans Petter Selasky  * SOFTWARE.
33*97549c34SHans Petter Selasky  */
34*97549c34SHans Petter Selasky 
35*97549c34SHans Petter Selasky #ifndef MLX4_DOORBELL_H
36*97549c34SHans Petter Selasky #define MLX4_DOORBELL_H
37*97549c34SHans Petter Selasky 
38*97549c34SHans Petter Selasky #include <linux/types.h>
39*97549c34SHans Petter Selasky #include <linux/io.h>
40*97549c34SHans Petter Selasky 
41*97549c34SHans Petter Selasky #define MLX4_SEND_DOORBELL    0x14
42*97549c34SHans Petter Selasky #define MLX4_CQ_DOORBELL      0x20
43*97549c34SHans Petter Selasky 
44*97549c34SHans Petter Selasky #if BITS_PER_LONG == 64
45*97549c34SHans Petter Selasky /*
46*97549c34SHans Petter Selasky  * Assume that we can just write a 64-bit doorbell atomically.  s390
47*97549c34SHans Petter Selasky  * actually doesn't have writeq() but S/390 systems don't even have
48*97549c34SHans Petter Selasky  * PCI so we won't worry about it.
49*97549c34SHans Petter Selasky  */
50*97549c34SHans Petter Selasky 
51*97549c34SHans Petter Selasky #define MLX4_DECLARE_DOORBELL_LOCK(name)
52*97549c34SHans Petter Selasky #define MLX4_INIT_DOORBELL_LOCK(ptr)    do { } while (0)
53*97549c34SHans Petter Selasky #define MLX4_GET_DOORBELL_LOCK(ptr)      (NULL)
54*97549c34SHans Petter Selasky 
mlx4_write64(__be32 val[2],void __iomem * dest,spinlock_t * doorbell_lock)55*97549c34SHans Petter Selasky static inline void mlx4_write64(__be32 val[2], void __iomem *dest,
56*97549c34SHans Petter Selasky 				spinlock_t *doorbell_lock)
57*97549c34SHans Petter Selasky {
58*97549c34SHans Petter Selasky 	__raw_writeq(*(u64 *) val, dest);
59*97549c34SHans Petter Selasky }
60*97549c34SHans Petter Selasky 
61*97549c34SHans Petter Selasky #else
62*97549c34SHans Petter Selasky 
63*97549c34SHans Petter Selasky /*
64*97549c34SHans Petter Selasky  * Just fall back to a spinlock to protect the doorbell if
65*97549c34SHans Petter Selasky  * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit
66*97549c34SHans Petter Selasky  * MMIO writes.
67*97549c34SHans Petter Selasky  */
68*97549c34SHans Petter Selasky 
69*97549c34SHans Petter Selasky #define MLX4_DECLARE_DOORBELL_LOCK(name) spinlock_t name;
70*97549c34SHans Petter Selasky #define MLX4_INIT_DOORBELL_LOCK(ptr)     spin_lock_init(ptr)
71*97549c34SHans Petter Selasky #define MLX4_GET_DOORBELL_LOCK(ptr)      (ptr)
72*97549c34SHans Petter Selasky 
mlx4_write64(__be32 val[2],void __iomem * dest,spinlock_t * doorbell_lock)73*97549c34SHans Petter Selasky static inline void mlx4_write64(__be32 val[2], void __iomem *dest,
74*97549c34SHans Petter Selasky 				spinlock_t *doorbell_lock)
75*97549c34SHans Petter Selasky {
76*97549c34SHans Petter Selasky 	unsigned long flags;
77*97549c34SHans Petter Selasky 
78*97549c34SHans Petter Selasky 	spin_lock_irqsave(doorbell_lock, flags);
79*97549c34SHans Petter Selasky 	__raw_writel((__force u32) val[0], dest);
80*97549c34SHans Petter Selasky 	__raw_writel((__force u32) val[1], (u8 *)dest + 4);
81*97549c34SHans Petter Selasky 	spin_unlock_irqrestore(doorbell_lock, flags);
82*97549c34SHans Petter Selasky }
83*97549c34SHans Petter Selasky 
84*97549c34SHans Petter Selasky #endif
85*97549c34SHans Petter Selasky 
86*97549c34SHans Petter Selasky #endif /* MLX4_DOORBELL_H */
87