xref: /illumos-gate/usr/src/uts/common/sys/sbp2/common.h (revision 8c067cfd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8c067cfdSAlan Perry  * Common Development and Distribution License (the "License").
6*8c067cfdSAlan Perry  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*8c067cfdSAlan Perry  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SBP2_COMMON_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SBP2_COMMON_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Serial Bus Protocol 2 (SBP-2) common definitions
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN
387c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16(data)	\
397c478bd9Sstevel@tonic-gate 	((((data) & 0xff) << 8) | ((data) >> 8))
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32(data)	\
427c478bd9Sstevel@tonic-gate 	(((uint32_t)SBP2_SWAP16((uint16_t)((data) & 0xffff)) << 16) | \
437c478bd9Sstevel@tonic-gate 	(uint32_t)SBP2_SWAP16((uint16_t)((data) >> 16)))
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16_1(data)	(data) = SBP2_SWAP16(data)
467c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_1(data)	(data) = SBP2_SWAP32(data)
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16_2(data)	\
497c478bd9Sstevel@tonic-gate 	((uint16_t *)(data))[0] = SBP2_SWAP16(((uint16_t *)(data))[0]);	\
507c478bd9Sstevel@tonic-gate 	((uint16_t *)(data))[1] = SBP2_SWAP16(((uint16_t *)(data))[1]);
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_2(data)	\
537c478bd9Sstevel@tonic-gate 	((uint32_t *)(data))[0] = SBP2_SWAP32(((uint32_t *)(data))[0]);	\
547c478bd9Sstevel@tonic-gate 	((uint32_t *)(data))[1] = SBP2_SWAP32(((uint32_t *)(data))[1]);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_BUF(data, len)	sbp2_swap32_buf((uint32_t *)data, len)
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #else
597c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16(data)	(data)
607c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32(data)	(data)
617c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16_1(data)
627c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_1(data)
637c478bd9Sstevel@tonic-gate #define	SBP2_SWAP16_2(data)
647c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_2(data)
657c478bd9Sstevel@tonic-gate #define	SBP2_SWAP32_BUF(data, len)
667c478bd9Sstevel@tonic-gate #endif
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * serial bus address: it is a 64-bit value, but ORB structures require quadlet
707c478bd9Sstevel@tonic-gate  * (32-bit) alignment, so it is defined as two quadlets rather than one octlet
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate typedef uint32_t sbp2_addr_t[2];
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #define	SBP2_ADDR_NODE_ID		0xFFFF000000000000ULL
757c478bd9Sstevel@tonic-gate #define	SBP2_ADDR_NODE_ID_SHIFT		48
767c478bd9Sstevel@tonic-gate #define	SBP2_ADDR_OFFSET		0x0000FFFFFFFFFFFCULL
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #define	SBP2_OFFSET_HI(offset)		(((offset) & SBP2_ADDR_OFFSET) >> 32)
797c478bd9Sstevel@tonic-gate #define	SBP2_OFFSET_LO(offset)		(((offset) & SBP2_ADDR_OFFSET))
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	SBP2_ADDR_SET(var, addr, node_ID) { \
827c478bd9Sstevel@tonic-gate 		((uint32_t *)(var))[0] = SBP2_SWAP32(((addr) | \
837c478bd9Sstevel@tonic-gate 		((uint64_t)(node_ID) << SBP2_ADDR_NODE_ID_SHIFT)) >> 32); \
847c478bd9Sstevel@tonic-gate 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_OFFSET_LO(addr)); \
857c478bd9Sstevel@tonic-gate 	}
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #define	SBP2_ADDR2UINT64(addr)	((((uint64_t)(addr)[0])) << 32) | ((addr)[1])
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* ORB pointer: serial bus address without node ID */
907c478bd9Sstevel@tonic-gate typedef uint32_t sbp2_orbp_t[2];
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #define	SBP2_ORBP_NULL			0x8000000000000000ULL
937c478bd9Sstevel@tonic-gate #define	SBP2_ORBP_OFFSET		0x0000FFFFFFFFFFFCULL
947c478bd9Sstevel@tonic-gate #define	SBP2_ORBP_MASK			(SBP2_ORBP_NULL | SBP2_ORBP_OFFSET)
957c478bd9Sstevel@tonic-gate 
9662d1ab6eSap #define	SBP2_ORBP_HI(orbp)		\
9762d1ab6eSap 		((uint32_t)(((orbp) & SBP2_ORBP_MASK) >> 32))
9862d1ab6eSap #define	SBP2_ORBP_LO(orbp)		((uint32_t)((orbp) & SBP2_ORBP_MASK))
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	SBP2_ORBP_SET(var, orbp) { \
1017c478bd9Sstevel@tonic-gate 		((uint32_t *)(var))[0] = SBP2_SWAP32(SBP2_ORBP_HI(orbp)); \
1027c478bd9Sstevel@tonic-gate 		((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_ORBP_LO(orbp)); \
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #define	SBP2_ORBP2UINT64(orbp) \
1067c478bd9Sstevel@tonic-gate 	((((uint64_t)(orbp)[0] << 32) | (orbp)[1]) & SBP2_ORBP_OFFSET)
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * return codes
1117c478bd9Sstevel@tonic-gate  * NOTE: SBP2_SUCCESS/FAILURE values should be the same as DDI_SUCCESS/FAILURE
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate enum {
1147c478bd9Sstevel@tonic-gate 	SBP2_SUCCESS		= 0,
1157c478bd9Sstevel@tonic-gate 	SBP2_FAILURE		= -1,	/* generic/undefined failure */
1167c478bd9Sstevel@tonic-gate 	SBP2_EINVAL		= 1,	/* invalid arguments */
1177c478bd9Sstevel@tonic-gate 	SBP2_ENOMEM		= 2,	/* memory not available */
1187c478bd9Sstevel@tonic-gate 	SBP2_EIO		= 3,	/* I/O operation failed */
1197c478bd9Sstevel@tonic-gate 	SBP2_EBUSY		= 4,	/* device busy */
1207c478bd9Sstevel@tonic-gate 	SBP2_EADDR		= 5,	/* wrong address */
1217c478bd9Sstevel@tonic-gate 	SBP2_EDEAD		= 6,	/* agent dead */
1227c478bd9Sstevel@tonic-gate 	SBP2_ETIMEOUT		= 7,	/* operation timed out */
1237c478bd9Sstevel@tonic-gate 	SBP2_ECFGROM		= 8,	/* bad/corrupted Config ROM */
1247c478bd9Sstevel@tonic-gate 	SBP2_EALREADY		= 9,	/* already exists/completed/etc */
1257c478bd9Sstevel@tonic-gate 	SBP2_ESTALE		= 10,	/* stale login session */
1267c478bd9Sstevel@tonic-gate 	SBP2_EDATA		= 11,	/* bad/corrupted data */
127*8c067cfdSAlan Perry 	SBP2_ENODEV		= 12,	/* device not there */
128*8c067cfdSAlan Perry 	SBP2_ECONTEXT		= 13	/* bad context for I/O operation */
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate #endif
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #endif	/* _SYS_SBP2_COMMON_H */
136