xref: /titanic_51/usr/src/uts/common/sys/sbp2/common.h (revision 672986541be54a7a471bb088e60780c37e371d7e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SBP2_COMMON_H
28 #define	_SYS_SBP2_COMMON_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Serial Bus Protocol 2 (SBP-2) common definitions
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _LITTLE_ENDIAN
41 #define	SBP2_SWAP16(data)	\
42 	((((data) & 0xff) << 8) | ((data) >> 8))
43 
44 #define	SBP2_SWAP32(data)	\
45 	(((uint32_t)SBP2_SWAP16((uint16_t)((data) & 0xffff)) << 16) | \
46 	(uint32_t)SBP2_SWAP16((uint16_t)((data) >> 16)))
47 
48 #define	SBP2_SWAP16_1(data)	(data) = SBP2_SWAP16(data)
49 #define	SBP2_SWAP32_1(data)	(data) = SBP2_SWAP32(data)
50 
51 #define	SBP2_SWAP16_2(data)	\
52 	((uint16_t *)(data))[0] = SBP2_SWAP16(((uint16_t *)(data))[0]);	\
53 	((uint16_t *)(data))[1] = SBP2_SWAP16(((uint16_t *)(data))[1]);
54 
55 #define	SBP2_SWAP32_2(data)	\
56 	((uint32_t *)(data))[0] = SBP2_SWAP32(((uint32_t *)(data))[0]);	\
57 	((uint32_t *)(data))[1] = SBP2_SWAP32(((uint32_t *)(data))[1]);
58 
59 #define	SBP2_SWAP32_BUF(data, len)	sbp2_swap32_buf((uint32_t *)data, len)
60 
61 #else
62 #define	SBP2_SWAP16(data)	(data)
63 #define	SBP2_SWAP32(data)	(data)
64 #define	SBP2_SWAP16_1(data)
65 #define	SBP2_SWAP32_1(data)
66 #define	SBP2_SWAP16_2(data)
67 #define	SBP2_SWAP32_2(data)
68 #define	SBP2_SWAP32_BUF(data, len)
69 #endif
70 
71 /*
72  * serial bus address: it is a 64-bit value, but ORB structures require quadlet
73  * (32-bit) alignment, so it is defined as two quadlets rather than one octlet
74  */
75 typedef uint32_t sbp2_addr_t[2];
76 
77 #define	SBP2_ADDR_NODE_ID		0xFFFF000000000000ULL
78 #define	SBP2_ADDR_NODE_ID_SHIFT		48
79 #define	SBP2_ADDR_OFFSET		0x0000FFFFFFFFFFFCULL
80 
81 #define	SBP2_OFFSET_HI(offset)		(((offset) & SBP2_ADDR_OFFSET) >> 32)
82 #define	SBP2_OFFSET_LO(offset)		(((offset) & SBP2_ADDR_OFFSET))
83 
84 #define	SBP2_ADDR_SET(var, addr, node_ID) { \
85 		((uint32_t *)(var))[0] = SBP2_SWAP32(((addr) | \
86 		((uint64_t)(node_ID) << SBP2_ADDR_NODE_ID_SHIFT)) >> 32); \
87 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_OFFSET_LO(addr)); \
88 	}
89 
90 #define	SBP2_ADDR2UINT64(addr)	((((uint64_t)(addr)[0])) << 32) | ((addr)[1])
91 
92 /* ORB pointer: serial bus address without node ID */
93 typedef uint32_t sbp2_orbp_t[2];
94 
95 #define	SBP2_ORBP_NULL			0x8000000000000000ULL
96 #define	SBP2_ORBP_OFFSET		0x0000FFFFFFFFFFFCULL
97 #define	SBP2_ORBP_MASK			(SBP2_ORBP_NULL | SBP2_ORBP_OFFSET)
98 
99 #define	SBP2_ORBP_HI(orbp)		\
100 		((uint32_t)(((orbp) & SBP2_ORBP_MASK) >> 32))
101 #define	SBP2_ORBP_LO(orbp)		((uint32_t)((orbp) & SBP2_ORBP_MASK))
102 
103 #define	SBP2_ORBP_SET(var, orbp) { \
104 		((uint32_t *)(var))[0] = SBP2_SWAP32(SBP2_ORBP_HI(orbp)); \
105 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_ORBP_LO(orbp)); \
106 	}
107 
108 #define	SBP2_ORBP2UINT64(orbp) \
109 	((((uint64_t)(orbp)[0] << 32) | (orbp)[1]) & SBP2_ORBP_OFFSET)
110 
111 
112 /*
113  * return codes
114  * NOTE: SBP2_SUCCESS/FAILURE values should be the same as DDI_SUCCESS/FAILURE
115  */
116 enum {
117 	SBP2_SUCCESS		= 0,
118 	SBP2_FAILURE		= -1,	/* generic/undefined failure */
119 	SBP2_EINVAL		= 1,	/* invalid arguments */
120 	SBP2_ENOMEM		= 2,	/* memory not available */
121 	SBP2_EIO		= 3,	/* I/O operation failed */
122 	SBP2_EBUSY		= 4,	/* device busy */
123 	SBP2_EADDR		= 5,	/* wrong address */
124 	SBP2_EDEAD		= 6,	/* agent dead */
125 	SBP2_ETIMEOUT		= 7,	/* operation timed out */
126 	SBP2_ECFGROM		= 8,	/* bad/corrupted Config ROM */
127 	SBP2_EALREADY		= 9,	/* already exists/completed/etc */
128 	SBP2_ESTALE		= 10,	/* stale login session */
129 	SBP2_EDATA		= 11,	/* bad/corrupted data */
130 	SBP2_ENODEV		= 12	/* device not there */
131 };
132 
133 #ifdef	__cplusplus
134 }
135 #endif
136 
137 #endif	/* _SYS_SBP2_COMMON_H */
138