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