xref: /titanic_51/usr/src/uts/common/sys/sbp2/common.h (revision a898d95b5e162e6e7985584118c2abfccbe9b868)
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 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SBP2_COMMON_H
27 #define	_SYS_SBP2_COMMON_H
28 
29 /*
30  * Serial Bus Protocol 2 (SBP-2) common definitions
31  */
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #ifdef _LITTLE_ENDIAN
38 #define	SBP2_SWAP16(data)	\
39 	((((data) & 0xff) << 8) | ((data) >> 8))
40 
41 #define	SBP2_SWAP32(data)	\
42 	(((uint32_t)SBP2_SWAP16((uint16_t)((data) & 0xffff)) << 16) | \
43 	(uint32_t)SBP2_SWAP16((uint16_t)((data) >> 16)))
44 
45 #define	SBP2_SWAP16_1(data)	(data) = SBP2_SWAP16(data)
46 #define	SBP2_SWAP32_1(data)	(data) = SBP2_SWAP32(data)
47 
48 #define	SBP2_SWAP16_2(data)	\
49 	((uint16_t *)(data))[0] = SBP2_SWAP16(((uint16_t *)(data))[0]);	\
50 	((uint16_t *)(data))[1] = SBP2_SWAP16(((uint16_t *)(data))[1]);
51 
52 #define	SBP2_SWAP32_2(data)	\
53 	((uint32_t *)(data))[0] = SBP2_SWAP32(((uint32_t *)(data))[0]);	\
54 	((uint32_t *)(data))[1] = SBP2_SWAP32(((uint32_t *)(data))[1]);
55 
56 #define	SBP2_SWAP32_BUF(data, len)	sbp2_swap32_buf((uint32_t *)data, len)
57 
58 #else
59 #define	SBP2_SWAP16(data)	(data)
60 #define	SBP2_SWAP32(data)	(data)
61 #define	SBP2_SWAP16_1(data)
62 #define	SBP2_SWAP32_1(data)
63 #define	SBP2_SWAP16_2(data)
64 #define	SBP2_SWAP32_2(data)
65 #define	SBP2_SWAP32_BUF(data, len)
66 #endif
67 
68 /*
69  * serial bus address: it is a 64-bit value, but ORB structures require quadlet
70  * (32-bit) alignment, so it is defined as two quadlets rather than one octlet
71  */
72 typedef uint32_t sbp2_addr_t[2];
73 
74 #define	SBP2_ADDR_NODE_ID		0xFFFF000000000000ULL
75 #define	SBP2_ADDR_NODE_ID_SHIFT		48
76 #define	SBP2_ADDR_OFFSET		0x0000FFFFFFFFFFFCULL
77 
78 #define	SBP2_OFFSET_HI(offset)		(((offset) & SBP2_ADDR_OFFSET) >> 32)
79 #define	SBP2_OFFSET_LO(offset)		(((offset) & SBP2_ADDR_OFFSET))
80 
81 #define	SBP2_ADDR_SET(var, addr, node_ID) { \
82 		((uint32_t *)(var))[0] = SBP2_SWAP32(((addr) | \
83 		((uint64_t)(node_ID) << SBP2_ADDR_NODE_ID_SHIFT)) >> 32); \
84 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_OFFSET_LO(addr)); \
85 	}
86 
87 #define	SBP2_ADDR2UINT64(addr)	((((uint64_t)(addr)[0])) << 32) | ((addr)[1])
88 
89 /* ORB pointer: serial bus address without node ID */
90 typedef uint32_t sbp2_orbp_t[2];
91 
92 #define	SBP2_ORBP_NULL			0x8000000000000000ULL
93 #define	SBP2_ORBP_OFFSET		0x0000FFFFFFFFFFFCULL
94 #define	SBP2_ORBP_MASK			(SBP2_ORBP_NULL | SBP2_ORBP_OFFSET)
95 
96 #define	SBP2_ORBP_HI(orbp)		\
97 		((uint32_t)(((orbp) & SBP2_ORBP_MASK) >> 32))
98 #define	SBP2_ORBP_LO(orbp)		((uint32_t)((orbp) & SBP2_ORBP_MASK))
99 
100 #define	SBP2_ORBP_SET(var, orbp) { \
101 		((uint32_t *)(var))[0] = SBP2_SWAP32(SBP2_ORBP_HI(orbp)); \
102 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_ORBP_LO(orbp)); \
103 	}
104 
105 #define	SBP2_ORBP2UINT64(orbp) \
106 	((((uint64_t)(orbp)[0] << 32) | (orbp)[1]) & SBP2_ORBP_OFFSET)
107 
108 
109 /*
110  * return codes
111  * NOTE: SBP2_SUCCESS/FAILURE values should be the same as DDI_SUCCESS/FAILURE
112  */
113 enum {
114 	SBP2_SUCCESS		= 0,
115 	SBP2_FAILURE		= -1,	/* generic/undefined failure */
116 	SBP2_EINVAL		= 1,	/* invalid arguments */
117 	SBP2_ENOMEM		= 2,	/* memory not available */
118 	SBP2_EIO		= 3,	/* I/O operation failed */
119 	SBP2_EBUSY		= 4,	/* device busy */
120 	SBP2_EADDR		= 5,	/* wrong address */
121 	SBP2_EDEAD		= 6,	/* agent dead */
122 	SBP2_ETIMEOUT		= 7,	/* operation timed out */
123 	SBP2_ECFGROM		= 8,	/* bad/corrupted Config ROM */
124 	SBP2_EALREADY		= 9,	/* already exists/completed/etc */
125 	SBP2_ESTALE		= 10,	/* stale login session */
126 	SBP2_EDATA		= 11,	/* bad/corrupted data */
127 	SBP2_ENODEV		= 12,	/* device not there */
128 	SBP2_ECONTEXT		= 13	/* bad context for I/O operation */
129 };
130 
131 #ifdef	__cplusplus
132 }
133 #endif
134 
135 #endif	/* _SYS_SBP2_COMMON_H */
136