xref: /dpdk/drivers/net/qede/base/ecore_utils.h (revision d80e42cce4c7017ed8c99dabb8ae444a492acc1c)
1 /*
2  * Copyright (c) 2016 - 2018 Cavium Inc.
3  * All rights reserved.
4  * www.cavium.com
5  *
6  * See LICENSE.qede_pmd for copyright and licensing details.
7  */
8 
9 #ifndef __ECORE_UTILS_H__
10 #define __ECORE_UTILS_H__
11 
12 /* dma_addr_t manip */
13 /* Suppress "right shift count >= width of type" warning when that quantity is
14  * 32-bits rquires the >> 16) >> 16)
15  */
16 #define PTR_LO(x)		((u32)(((osal_uintptr_t)(x)) & 0xffffffff))
17 #define PTR_HI(x)		((u32)((((osal_uintptr_t)(x)) >> 16) >> 16))
18 
19 #define DMA_LO(x)		((u32)(((dma_addr_t)(x)) & 0xffffffff))
20 #define DMA_HI(x)		((u32)(((dma_addr_t)(x)) >> 32))
21 
22 #define DMA_LO_LE(x)		OSAL_CPU_TO_LE32(DMA_LO(x))
23 #define DMA_HI_LE(x)		OSAL_CPU_TO_LE32(DMA_HI(x))
24 
25 /* It's assumed that whoever includes this has previously included an hsi
26  * file defining the regpair.
27  */
28 #define DMA_REGPAIR_LE(x, val)	(x).hi = DMA_HI_LE((val)); \
29 				(x).lo = DMA_LO_LE((val))
30 
31 #define HILO_GEN(hi, lo, type)	((((type)(hi)) << 32) + (lo))
32 #define HILO_DMA(hi, lo)	HILO_GEN(hi, lo, dma_addr_t)
33 #define HILO_64(hi, lo)		HILO_GEN(hi, lo, u64)
34 #define HILO_DMA_REGPAIR(regpair)	(HILO_DMA(regpair.hi, regpair.lo))
35 #define HILO_64_REGPAIR(regpair)	(HILO_64(regpair.hi, regpair.lo))
36 
37 #endif
38