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