1*14b24e2bSVaishali Kulkarni /*
2*14b24e2bSVaishali Kulkarni * CDDL HEADER START
3*14b24e2bSVaishali Kulkarni *
4*14b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the
5*14b24e2bSVaishali Kulkarni * Common Development and Distribution License, v.1,  (the "License").
6*14b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
7*14b24e2bSVaishali Kulkarni *
8*14b24e2bSVaishali Kulkarni * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*14b24e2bSVaishali Kulkarni * or http://opensource.org/licenses/CDDL-1.0.
10*14b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions
11*14b24e2bSVaishali Kulkarni * and limitations under the License.
12*14b24e2bSVaishali Kulkarni *
13*14b24e2bSVaishali Kulkarni * When distributing Covered Code, include this CDDL HEADER in each
14*14b24e2bSVaishali Kulkarni * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*14b24e2bSVaishali Kulkarni * If applicable, add the following below this CDDL HEADER, with the
16*14b24e2bSVaishali Kulkarni * fields enclosed by brackets "[]" replaced with your own identifying
17*14b24e2bSVaishali Kulkarni * information: Portions Copyright [yyyy] [name of copyright owner]
18*14b24e2bSVaishali Kulkarni *
19*14b24e2bSVaishali Kulkarni * CDDL HEADER END
20*14b24e2bSVaishali Kulkarni */
21*14b24e2bSVaishali Kulkarni 
22*14b24e2bSVaishali Kulkarni /*
23*14b24e2bSVaishali Kulkarni * Copyright 2014-2017 Cavium, Inc.
24*14b24e2bSVaishali Kulkarni * The contents of this file are subject to the terms of the Common Development
25*14b24e2bSVaishali Kulkarni * and Distribution License, v.1,  (the "License").
26*14b24e2bSVaishali Kulkarni 
27*14b24e2bSVaishali Kulkarni * You may not use this file except in compliance with the License.
28*14b24e2bSVaishali Kulkarni 
29*14b24e2bSVaishali Kulkarni * You can obtain a copy of the License at available
30*14b24e2bSVaishali Kulkarni * at http://opensource.org/licenses/CDDL-1.0
31*14b24e2bSVaishali Kulkarni 
32*14b24e2bSVaishali Kulkarni * See the License for the specific language governing permissions and
33*14b24e2bSVaishali Kulkarni * limitations under the License.
34*14b24e2bSVaishali Kulkarni */
35*14b24e2bSVaishali Kulkarni 
36*14b24e2bSVaishali Kulkarni #ifndef __ECORE_UTILS_H__
37*14b24e2bSVaishali Kulkarni #define __ECORE_UTILS_H__
38*14b24e2bSVaishali Kulkarni 
39*14b24e2bSVaishali Kulkarni /* dma_addr_t manip */
40*14b24e2bSVaishali Kulkarni /* Suppress "right shift count >= width of type" warning when that quantity is
41*14b24e2bSVaishali Kulkarni  * 32-bits rquires the >> 16) >> 16)
42*14b24e2bSVaishali Kulkarni  */
43*14b24e2bSVaishali Kulkarni #define PTR_LO(x)		((u32)(((osal_uintptr_t)(x)) & 0xffffffff))
44*14b24e2bSVaishali Kulkarni #define PTR_HI(x)		((u32)((((osal_uintptr_t)(x)) >> 16) >> 16))
45*14b24e2bSVaishali Kulkarni 
46*14b24e2bSVaishali Kulkarni #define DMA_LO(x)		((u32)(((dma_addr_t)(x)) & 0xffffffff))
47*14b24e2bSVaishali Kulkarni #define DMA_HI(x)		((u32)(((dma_addr_t)(x)) >> 32))
48*14b24e2bSVaishali Kulkarni 
49*14b24e2bSVaishali Kulkarni #define DMA_LO_LE(x)		OSAL_CPU_TO_LE32(DMA_LO(x))
50*14b24e2bSVaishali Kulkarni #define DMA_HI_LE(x)		OSAL_CPU_TO_LE32(DMA_HI(x))
51*14b24e2bSVaishali Kulkarni 
52*14b24e2bSVaishali Kulkarni /* It's assumed that whoever includes this has previously included an hsi
53*14b24e2bSVaishali Kulkarni  * file defining the regpair.
54*14b24e2bSVaishali Kulkarni  */
55*14b24e2bSVaishali Kulkarni #define DMA_REGPAIR_LE(x, val)	(x).hi = DMA_HI_LE((val)); \
56*14b24e2bSVaishali Kulkarni 				(x).lo = DMA_LO_LE((val))
57*14b24e2bSVaishali Kulkarni 
58*14b24e2bSVaishali Kulkarni #define HILO_GEN(hi, lo, type)	((((type)(hi)) << 32) + (lo))
59*14b24e2bSVaishali Kulkarni #define HILO_DMA(hi, lo)	HILO_GEN(hi, lo, dma_addr_t)
60*14b24e2bSVaishali Kulkarni #define HILO_64(hi, lo)		HILO_GEN(hi, lo, u64)
61*14b24e2bSVaishali Kulkarni #define HILO_DMA_REGPAIR(regpair)	(HILO_DMA(regpair.hi, regpair.lo))
62*14b24e2bSVaishali Kulkarni #define HILO_64_REGPAIR(regpair)	(HILO_64(regpair.hi, regpair.lo))
63*14b24e2bSVaishali Kulkarni 
64*14b24e2bSVaishali Kulkarni #endif
65