xref: /freebsd/sys/dev/qlnx/qlnxe/ecore_utils.h (revision 389e4940069316fe667ffa263fa7d6390d0a960f)
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  * $FreeBSD$
28  *
29  */
30 
31 #ifndef __ECORE_UTILS_H__
32 #define __ECORE_UTILS_H__
33 
34 /* dma_addr_t manip */
35 /* Suppress "right shift count >= width of type" warning when that quantity is
36  * 32-bits rquires the >> 16) >> 16)
37  */
38 #define PTR_LO(x)		((u32)(((osal_uintptr_t)(x)) & 0xffffffff))
39 #define PTR_HI(x)		((u32)((((osal_uintptr_t)(x)) >> 16) >> 16))
40 
41 #define DMA_LO(x)		((u32)(((dma_addr_t)(x)) & 0xffffffff))
42 #define DMA_HI(x)		((u32)(((dma_addr_t)(x)) >> 32))
43 
44 #define DMA_LO_LE(x)		OSAL_CPU_TO_LE32(DMA_LO(x))
45 #define DMA_HI_LE(x)		OSAL_CPU_TO_LE32(DMA_HI(x))
46 
47 /* It's assumed that whoever includes this has previously included an hsi
48  * file defining the regpair.
49  */
50 #define DMA_REGPAIR_LE(x, val)	(x).hi = DMA_HI_LE((val)); \
51 				(x).lo = DMA_LO_LE((val))
52 
53 #define HILO_GEN(hi, lo, type)	((((type)(hi)) << 32) + (lo))
54 #define HILO_DMA(hi, lo)	HILO_GEN(hi, lo, dma_addr_t)
55 #define HILO_64(hi, lo)		HILO_GEN(hi, lo, u64)
56 #define HILO_DMA_REGPAIR(regpair)	(HILO_DMA(regpair.hi, regpair.lo))
57 #define HILO_64_REGPAIR(regpair)	(HILO_64(regpair.hi, regpair.lo))
58 
59 #endif
60