1321936Shselasky/*
2321936Shselasky * Copyright (c) 2012 Mellanox Technologies, Inc.  All rights reserved.
3321936Shselasky *
4321936Shselasky * This software is available to you under a choice of one of two
5321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
6321936Shselasky * General Public License (GPL) Version 2, available from the file
7321936Shselasky * COPYING in the main directory of this source tree, or the
8321936Shselasky * OpenIB.org BSD license below:
9321936Shselasky *
10321936Shselasky *     Redistribution and use in source and binary forms, with or
11321936Shselasky *     without modification, are permitted provided that the following
12321936Shselasky *     conditions are met:
13321936Shselasky *
14321936Shselasky *      - Redistributions of source code must retain the above
15321936Shselasky *        copyright notice, this list of conditions and the following
16321936Shselasky *        disclaimer.
17321936Shselasky *
18321936Shselasky *      - Redistributions in binary form must reproduce the above
19321936Shselasky *        copyright notice, this list of conditions and the following
20321936Shselasky *        disclaimer in the documentation and/or other materials
21321936Shselasky *        provided with the distribution.
22321936Shselasky *
23321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30321936Shselasky * SOFTWARE.
31321936Shselasky */
32321936Shselasky
33321936Shselasky
34321936Shselasky#ifndef DOORBELL_H
35321936Shselasky#define DOORBELL_H
36321936Shselasky
37321936Shselasky#include <stdint.h>
38321936Shselasky#include "mlx5.h"
39321936Shselasky
40321936Shselasky#if SIZEOF_LONG == 8
41321936Shselasky
42321936Shselasky#if __BYTE_ORDER == __LITTLE_ENDIAN
43321936Shselasky#  define MLX5_PAIR_TO_64(val) ((uint64_t) val[1] << 32 | val[0])
44321936Shselasky#elif __BYTE_ORDER == __BIG_ENDIAN
45321936Shselasky#  define MLX5_PAIR_TO_64(val) ((uint64_t) val[0] << 32 | val[1])
46321936Shselasky#else
47321936Shselasky#  error __BYTE_ORDER not defined
48321936Shselasky#endif
49321936Shselasky
50321936Shselaskystatic inline void mlx5_write64(uint32_t val[2], void *dest, struct mlx5_spinlock *lock)
51321936Shselasky{
52321936Shselasky	*(volatile uint64_t *)dest = MLX5_PAIR_TO_64(val);
53321936Shselasky}
54321936Shselasky
55321936Shselasky#else
56321936Shselasky
57321936Shselaskystatic inline void mlx5_write64(uint32_t val[2], void *dest, struct mlx5_spinlock *lock)
58321936Shselasky{
59321936Shselasky	mlx5_spin_lock(lock);
60321936Shselasky	*(volatile uint32_t *)dest		= val[0];
61321936Shselasky	*(volatile uint32_t *)(dest + 4)	= val[1];
62321936Shselasky	mlx5_spin_unlock(lock);
63321936Shselasky}
64321936Shselasky
65321936Shselasky#endif
66321936Shselasky
67321936Shselasky#endif /* DOORBELL_H */
68