xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_utils.h (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1 /*
2  * Copyright (c) 2017-2018 Cavium, Inc.
3  * All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions
7  *  are met:
8  *
9  *  1. Redistributions of source code must retain the above copyright
10  *     notice, this list of conditions and the following disclaimer.
11  *  2. Redistributions in binary form must reproduce the above copyright
12  *     notice, this list of conditions and the following disclaimer in the
13  *     documentation and/or other materials provided with the distribution.
14  *
15  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef __ECORE_UTILS_H__
30 #define __ECORE_UTILS_H__
31 
32 /* dma_addr_t manip */
33 /* Suppress "right shift count >= width of type" warning when that quantity is
34  * 32-bits rquires the >> 16) >> 16)
35  */
36 #define PTR_LO(x)		((u32)(((osal_uintptr_t)(x)) & 0xffffffff))
37 #define PTR_HI(x)		((u32)((((osal_uintptr_t)(x)) >> 16) >> 16))
38 
39 #define DMA_LO(x)		((u32)(((dma_addr_t)(x)) & 0xffffffff))
40 #define DMA_HI(x)		((u32)(((dma_addr_t)(x)) >> 32))
41 
42 #define DMA_LO_LE(x)		OSAL_CPU_TO_LE32(DMA_LO(x))
43 #define DMA_HI_LE(x)		OSAL_CPU_TO_LE32(DMA_HI(x))
44 
45 /* It's assumed that whoever includes this has previously included an hsi
46  * file defining the regpair.
47  */
48 #define DMA_REGPAIR_LE(x, val)	(x).hi = DMA_HI_LE((val)); \
49 				(x).lo = DMA_LO_LE((val))
50 
51 #define HILO_GEN(hi, lo, type)	((((type)(hi)) << 32) + (lo))
52 #define HILO_DMA(hi, lo)	HILO_GEN(hi, lo, dma_addr_t)
53 #define HILO_64(hi, lo)		HILO_GEN(hi, lo, u64)
54 #define HILO_DMA_REGPAIR(regpair)	(HILO_DMA(regpair.hi, regpair.lo))
55 #define HILO_64_REGPAIR(regpair)	(HILO_64(regpair.hi, regpair.lo))
56 
57 #ifndef USHRT_MAX
58 #define USHRT_MAX       ((u16)(~0U))
59 #endif
60 
61 #endif
62