doorbell.h revision 292107
1139749Simp/*
252245Smdodd * Copyright (c) 2004 Topspin Communications.  All rights reserved.
352245Smdodd * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
452245Smdodd * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
552245Smdodd *
652245Smdodd * This software is available to you under a choice of one of two
752245Smdodd * licenses.  You may choose to be licensed under the terms of the GNU
852245Smdodd * General Public License (GPL) Version 2, available from the file
952245Smdodd * COPYING in the main directory of this source tree, or the
1052245Smdodd * OpenIB.org BSD license below:
1152245Smdodd *
1252245Smdodd *     Redistribution and use in source and binary forms, with or
1352245Smdodd *     without modification, are permitted provided that the following
1452245Smdodd *     conditions are met:
1552245Smdodd *
1652245Smdodd *      - Redistributions of source code must retain the above
1752245Smdodd *        copyright notice, this list of conditions and the following
1852245Smdodd *        disclaimer.
1952245Smdodd *
2052245Smdodd *      - Redistributions in binary form must reproduce the above
2152245Smdodd *        copyright notice, this list of conditions and the following
2252245Smdodd *        disclaimer in the documentation and/or other materials
2352245Smdodd *        provided with the distribution.
2452245Smdodd *
2552245Smdodd * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2652245Smdodd * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2752245Smdodd * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2852245Smdodd * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29119418Sobrien * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30119418Sobrien * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31119418Sobrien * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32141586Simp * SOFTWARE.
33141586Simp */
3452245Smdodd
3552245Smdodd#ifndef MLX4_DOORBELL_H
3652245Smdodd#define MLX4_DOORBELL_H
3752245Smdodd
3852245Smdodd#include <linux/types.h>
3952245Smdodd#include <linux/io.h>
4052245Smdodd
4152245Smdodd#define MLX4_SEND_DOORBELL    0x14
4252245Smdodd#define MLX4_CQ_DOORBELL      0x20
43141932Simp
4452245Smdodd#if BITS_PER_LONG == 64
4552245Smdodd/*
4652245Smdodd * Assume that we can just write a 64-bit doorbell atomically.  s390
4752245Smdodd * actually doesn't have writeq() but S/390 systems don't even have
4852245Smdodd * PCI so we won't worry about it.
4952245Smdodd */
5052245Smdodd
5152245Smdodd#define MLX4_DECLARE_DOORBELL_LOCK(name)
52142254Simp#define MLX4_INIT_DOORBELL_LOCK(ptr)    do { } while (0)
53142254Simp#define MLX4_GET_DOORBELL_LOCK(ptr)      (NULL)
5452245Smdodd
5552245Smdoddstatic inline void mlx4_write64(__be32 val[2], void __iomem *dest,
5652245Smdodd				spinlock_t *doorbell_lock)
5752245Smdodd{
5852245Smdodd	__raw_writeq(*(u64 *) val, dest);
5952245Smdodd}
6052245Smdodd
6152245Smdodd#else
6252245Smdodd
6352245Smdodd/*
64100721Stakawata * Just fall back to a spinlock to protect the doorbell if
6552245Smdodd * BITS_PER_LONG is 32 -- there's no portable way to do atomic 64-bit
6652245Smdodd * MMIO writes.
6752245Smdodd */
6852245Smdodd
69141932Simp#define MLX4_DECLARE_DOORBELL_LOCK(name) spinlock_t name;
7052245Smdodd#define MLX4_INIT_DOORBELL_LOCK(ptr)     spin_lock_init(ptr)
71141932Simp#define MLX4_GET_DOORBELL_LOCK(ptr)      (ptr)
7264777Snyan
73141932Simpstatic inline void mlx4_write64(__be32 val[2], void __iomem *dest,
74141932Simp				spinlock_t *doorbell_lock)
75141932Simp{
76141932Simp	unsigned long flags;
77141932Simp
78141932Simp	spin_lock_irqsave(doorbell_lock, flags);
79141932Simp	__raw_writel((__force u32) val[0], dest);
80141932Simp	__raw_writel((__force u32) val[1], (u8 *)dest + 4);
81141932Simp	spin_unlock_irqrestore(doorbell_lock, flags);
82141932Simp}
83141932Simp
84147256Sbrooks#endif
85141932Simp
86141932Simp#endif /* MLX4_DOORBELL_H */
87141932Simp