1 /*******************************************************************************
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  *
21  * Copyright 2014 QLogic Corporation
22  * The contents of this file are subject to the terms of the
23  * QLogic End User License (the "License").
24  * You may not use this file except in compliance with the License.
25  *
26  * You can obtain a copy of the License at
27  * http://www.qlogic.com/Resources/Documents/DriverDownloadHelp/
28  * QLogic_End_User_Software_License.txt
29  * See the License for the specific language governing permissions
30  * and limitations under the License.
31  *
32  *
33  * Module Description:
34  *
35  * History:
36  *    25/10/09 Shay Haroush        Inception.
37  ******************************************************************************/
38 
39 #ifndef __bcm_utils_h__
40 #define __bcm_utils_h__
41 #include "bcmtype.h"
42 #include "utils.h"
43 
44 #include "cyclic_oper.h"
45 
46 /*
47 U64_LO
48 U64_HI
49 get 64 hi/lo value
50 */
51 #define U64_LO(x)           ((u32_t)(((u64_t)(x)) & (u64_t)0xffffffff))
52 #define U64_HI(x)           ((u32_t)(((u64_t)(x)) >> 32))
53 #define HILO_U64(hi, lo)	((((u64)(hi)) << 32) + (lo))
54 
55 #ifndef MAX_VARIABLE_VALUE
56 #define MAX_VARIABLE_VALUE(x)   ((((u64_t)1) << (sizeof(x) * BITS_PER_BYTE)) -1)
57 #endif //MAX_VARIABLE_VALUE
58 
59 /*
60  * Inlined SWAP functions to ensure arguments are never re-evaluated and remain
61  * atomic.  For example, an argument passed in that is actually a de-reference
62  * to volatile memory would be de-referenced multiple times if these swap
63  * routines were macros.
64  */
65 
SWAP_BYTES16(u16_t val16)66 static __inline u16_t SWAP_BYTES16(u16_t val16)
67 {
68     return (((val16 & 0x00ff) << 8) |
69             ((val16 & 0xff00) >> 8));
70 }
71 
SWAP_BYTES32(u32_t val32)72 static __inline u32_t SWAP_BYTES32(u32_t val32)
73 {
74     return ((SWAP_BYTES16(val32 & 0x0000ffff) << 16) |
75             (SWAP_BYTES16((val32 & 0xffff0000) >> 16)));
76 }
77 
78 
SWAP_DWORDS(u64_t val)79 static __inline u64_t SWAP_DWORDS(u64_t val)
80 {
81     return (((val & (u64_t)0x00000000ffffffffLL) << 32) |
82             ((val & (u64_t)0xffffffff00000000LL) >> 32));
83 }
84 
85 #endif /* __bcm_utils_h__ */
86