doorbell.h revision 321936
1258945Sroberto/*
2258945Sroberto * Copyright (c) 2007 Cisco, Inc.  All rights reserved.
3258945Sroberto *
4258945Sroberto * This software is available to you under a choice of one of two
5258945Sroberto * licenses.  You may choose to be licensed under the terms of the GNU
6258945Sroberto * General Public License (GPL) Version 2, available from the file
7258945Sroberto * COPYING in the main directory of this source tree, or the
8258945Sroberto * OpenIB.org BSD license below:
9258945Sroberto *
10258945Sroberto *     Redistribution and use in source and binary forms, with or
11258945Sroberto *     without modification, are permitted provided that the following
12258945Sroberto *     conditions are met:
13258945Sroberto *
14258945Sroberto *      - Redistributions of source code must retain the above
15258945Sroberto *        copyright notice, this list of conditions and the following
16258945Sroberto *        disclaimer.
17258945Sroberto *
18258945Sroberto *      - Redistributions in binary form must reproduce the above
19258945Sroberto *        copyright notice, this list of conditions and the following
20258945Sroberto *        disclaimer in the documentation and/or other materials
21258945Sroberto *        provided with the distribution.
22258945Sroberto *
23258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24258945Sroberto * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25258945Sroberto * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26258945Sroberto * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27258945Sroberto * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28258945Sroberto * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29258945Sroberto * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30258945Sroberto * SOFTWARE.
31258945Sroberto */
32258945Sroberto
33258945Sroberto#ifndef DOORBELL_H
34258945Sroberto#define DOORBELL_H
35258945Sroberto
36258945Sroberto#include <stdint.h>
37258945Sroberto#include <pthread.h>
38258945Sroberto#include "mlx4.h"
39258945Sroberto#include "mmio.h"
40258945Sroberto
41258945Srobertostruct mlx4_context;
42258945Sroberto
43258945Sroberto#if SIZEOF_LONG == 8
44258945Sroberto
45258945Sroberto#if __BYTE_ORDER == __LITTLE_ENDIAN
46258945Sroberto#  define MLX4_PAIR_TO_64(val) ((uint64_t) val[1] << 32 | val[0])
47258945Sroberto#elif __BYTE_ORDER == __BIG_ENDIAN
48258945Sroberto#  define MLX4_PAIR_TO_64(val) ((uint64_t) val[0] << 32 | val[1])
49258945Sroberto#else
50258945Sroberto#  error __BYTE_ORDER not defined
51258945Sroberto#endif
52258945Sroberto
53258945Srobertostatic inline void mlx4_write64(uint32_t val[2], struct mlx4_context *ctx, int offset)
54258945Sroberto{
55258945Sroberto	mmio_writeq((unsigned long)(ctx->uar + offset), MLX4_PAIR_TO_64(val));
56258945Sroberto}
57258945Sroberto
58258945Sroberto#else
59258945Sroberto
60258945Srobertostatic inline void mlx4_write64(uint32_t val[2], struct mlx4_context *ctx, int offset)
61258945Sroberto{
62258945Sroberto	pthread_spin_lock(&ctx->uar_lock);
63258945Sroberto	mmio_writel((unsigned long)(ctx->uar + offset), val[0]);
64258945Sroberto	mmio_writel((unsigned long)(ctx->uar + offset + 4), val[1]);
65258945Sroberto	pthread_spin_unlock(&ctx->uar_lock);
66258945Sroberto}
67258945Sroberto
68258945Sroberto#endif
69258945Sroberto
70258945Sroberto#endif /* DOORBELL_H */
71258945Sroberto