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