10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*479Sap25164 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _SYS_SBP2_COMMON_H 280Sstevel@tonic-gate #define _SYS_SBP2_COMMON_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Serial Bus Protocol 2 (SBP-2) common definitions 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef _LITTLE_ENDIAN 410Sstevel@tonic-gate #define SBP2_SWAP16(data) \ 420Sstevel@tonic-gate ((((data) & 0xff) << 8) | ((data) >> 8)) 430Sstevel@tonic-gate 440Sstevel@tonic-gate #define SBP2_SWAP32(data) \ 450Sstevel@tonic-gate (((uint32_t)SBP2_SWAP16((uint16_t)((data) & 0xffff)) << 16) | \ 460Sstevel@tonic-gate (uint32_t)SBP2_SWAP16((uint16_t)((data) >> 16))) 470Sstevel@tonic-gate 480Sstevel@tonic-gate #define SBP2_SWAP16_1(data) (data) = SBP2_SWAP16(data) 490Sstevel@tonic-gate #define SBP2_SWAP32_1(data) (data) = SBP2_SWAP32(data) 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define SBP2_SWAP16_2(data) \ 520Sstevel@tonic-gate ((uint16_t *)(data))[0] = SBP2_SWAP16(((uint16_t *)(data))[0]); \ 530Sstevel@tonic-gate ((uint16_t *)(data))[1] = SBP2_SWAP16(((uint16_t *)(data))[1]); 540Sstevel@tonic-gate 550Sstevel@tonic-gate #define SBP2_SWAP32_2(data) \ 560Sstevel@tonic-gate ((uint32_t *)(data))[0] = SBP2_SWAP32(((uint32_t *)(data))[0]); \ 570Sstevel@tonic-gate ((uint32_t *)(data))[1] = SBP2_SWAP32(((uint32_t *)(data))[1]); 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define SBP2_SWAP32_BUF(data, len) sbp2_swap32_buf((uint32_t *)data, len) 600Sstevel@tonic-gate 610Sstevel@tonic-gate #else 620Sstevel@tonic-gate #define SBP2_SWAP16(data) (data) 630Sstevel@tonic-gate #define SBP2_SWAP32(data) (data) 640Sstevel@tonic-gate #define SBP2_SWAP16_1(data) 650Sstevel@tonic-gate #define SBP2_SWAP32_1(data) 660Sstevel@tonic-gate #define SBP2_SWAP16_2(data) 670Sstevel@tonic-gate #define SBP2_SWAP32_2(data) 680Sstevel@tonic-gate #define SBP2_SWAP32_BUF(data, len) 690Sstevel@tonic-gate #endif 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * serial bus address: it is a 64-bit value, but ORB structures require quadlet 730Sstevel@tonic-gate * (32-bit) alignment, so it is defined as two quadlets rather than one octlet 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate typedef uint32_t sbp2_addr_t[2]; 760Sstevel@tonic-gate 770Sstevel@tonic-gate #define SBP2_ADDR_NODE_ID 0xFFFF000000000000ULL 780Sstevel@tonic-gate #define SBP2_ADDR_NODE_ID_SHIFT 48 790Sstevel@tonic-gate #define SBP2_ADDR_OFFSET 0x0000FFFFFFFFFFFCULL 800Sstevel@tonic-gate 810Sstevel@tonic-gate #define SBP2_OFFSET_HI(offset) (((offset) & SBP2_ADDR_OFFSET) >> 32) 820Sstevel@tonic-gate #define SBP2_OFFSET_LO(offset) (((offset) & SBP2_ADDR_OFFSET)) 830Sstevel@tonic-gate 840Sstevel@tonic-gate #define SBP2_ADDR_SET(var, addr, node_ID) { \ 850Sstevel@tonic-gate ((uint32_t *)(var))[0] = SBP2_SWAP32(((addr) | \ 860Sstevel@tonic-gate ((uint64_t)(node_ID) << SBP2_ADDR_NODE_ID_SHIFT)) >> 32); \ 870Sstevel@tonic-gate ((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_OFFSET_LO(addr)); \ 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 900Sstevel@tonic-gate #define SBP2_ADDR2UINT64(addr) ((((uint64_t)(addr)[0])) << 32) | ((addr)[1]) 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* ORB pointer: serial bus address without node ID */ 930Sstevel@tonic-gate typedef uint32_t sbp2_orbp_t[2]; 940Sstevel@tonic-gate 950Sstevel@tonic-gate #define SBP2_ORBP_NULL 0x8000000000000000ULL 960Sstevel@tonic-gate #define SBP2_ORBP_OFFSET 0x0000FFFFFFFFFFFCULL 970Sstevel@tonic-gate #define SBP2_ORBP_MASK (SBP2_ORBP_NULL | SBP2_ORBP_OFFSET) 980Sstevel@tonic-gate 99*479Sap25164 #define SBP2_ORBP_HI(orbp) \ 100*479Sap25164 ((uint32_t)(((orbp) & SBP2_ORBP_MASK) >> 32)) 101*479Sap25164 #define SBP2_ORBP_LO(orbp) ((uint32_t)((orbp) & SBP2_ORBP_MASK)) 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate #define SBP2_ORBP_SET(var, orbp) { \ 1040Sstevel@tonic-gate ((uint32_t *)(var))[0] = SBP2_SWAP32(SBP2_ORBP_HI(orbp)); \ 1050Sstevel@tonic-gate ((uint32_t *)(var))[1] = SBP2_SWAP32(SBP2_ORBP_LO(orbp)); \ 1060Sstevel@tonic-gate } 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate #define SBP2_ORBP2UINT64(orbp) \ 1090Sstevel@tonic-gate ((((uint64_t)(orbp)[0] << 32) | (orbp)[1]) & SBP2_ORBP_OFFSET) 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * return codes 1140Sstevel@tonic-gate * NOTE: SBP2_SUCCESS/FAILURE values should be the same as DDI_SUCCESS/FAILURE 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate enum { 1170Sstevel@tonic-gate SBP2_SUCCESS = 0, 1180Sstevel@tonic-gate SBP2_FAILURE = -1, /* generic/undefined failure */ 1190Sstevel@tonic-gate SBP2_EINVAL = 1, /* invalid arguments */ 1200Sstevel@tonic-gate SBP2_ENOMEM = 2, /* memory not available */ 1210Sstevel@tonic-gate SBP2_EIO = 3, /* I/O operation failed */ 1220Sstevel@tonic-gate SBP2_EBUSY = 4, /* device busy */ 1230Sstevel@tonic-gate SBP2_EADDR = 5, /* wrong address */ 1240Sstevel@tonic-gate SBP2_EDEAD = 6, /* agent dead */ 1250Sstevel@tonic-gate SBP2_ETIMEOUT = 7, /* operation timed out */ 1260Sstevel@tonic-gate SBP2_ECFGROM = 8, /* bad/corrupted Config ROM */ 1270Sstevel@tonic-gate SBP2_EALREADY = 9, /* already exists/completed/etc */ 1280Sstevel@tonic-gate SBP2_ESTALE = 10, /* stale login session */ 1290Sstevel@tonic-gate SBP2_EDATA = 11, /* bad/corrupted data */ 1300Sstevel@tonic-gate SBP2_ENODEV = 12 /* device not there */ 1310Sstevel@tonic-gate }; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate #ifdef __cplusplus 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate #endif 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #endif /* _SYS_SBP2_COMMON_H */ 138