1321936Shselasky/*
2321936Shselasky * Copyright (c) 2007 Cisco, 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#ifndef DOORBELL_H
34321936Shselasky#define DOORBELL_H
35321936Shselasky
36321936Shselasky#include <stdint.h>
37321936Shselasky#include <pthread.h>
38321936Shselasky#include "mlx4.h"
39321936Shselasky#include "mmio.h"
40321936Shselasky
41321936Shselaskystruct mlx4_context;
42321936Shselasky
43321936Shselasky#if SIZEOF_LONG == 8
44321936Shselasky
45321936Shselasky#if __BYTE_ORDER == __LITTLE_ENDIAN
46321936Shselasky#  define MLX4_PAIR_TO_64(val) ((uint64_t) val[1] << 32 | val[0])
47321936Shselasky#elif __BYTE_ORDER == __BIG_ENDIAN
48321936Shselasky#  define MLX4_PAIR_TO_64(val) ((uint64_t) val[0] << 32 | val[1])
49321936Shselasky#else
50321936Shselasky#  error __BYTE_ORDER not defined
51321936Shselasky#endif
52321936Shselasky
53321936Shselaskystatic inline void mlx4_write64(uint32_t val[2], struct mlx4_context *ctx, int offset)
54321936Shselasky{
55321936Shselasky	mmio_writeq((unsigned long)(ctx->uar + offset), MLX4_PAIR_TO_64(val));
56321936Shselasky}
57321936Shselasky
58321936Shselasky#else
59321936Shselasky
60321936Shselaskystatic inline void mlx4_write64(uint32_t val[2], struct mlx4_context *ctx, int offset)
61321936Shselasky{
62321936Shselasky	pthread_spin_lock(&ctx->uar_lock);
63321936Shselasky	mmio_writel((unsigned long)(ctx->uar + offset), val[0]);
64321936Shselasky	mmio_writel((unsigned long)(ctx->uar + offset + 4), val[1]);
65321936Shselasky	pthread_spin_unlock(&ctx->uar_lock);
66321936Shselasky}
67321936Shselasky
68321936Shselasky#endif
69321936Shselasky
70321936Shselasky#endif /* DOORBELL_H */
71