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*6bbe0590SSundeep Panicker * Common Development and Distribution License (the "License"). 6*6bbe0590SSundeep Panicker * 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 */ 21*6bbe0590SSundeep Panicker 227c478bd9Sstevel@tonic-gate /* 23*6bbe0590SSundeep Panicker * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*6bbe0590SSundeep Panicker * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 27*6bbe0590SSundeep Panicker 287c478bd9Sstevel@tonic-gate #ifndef _FRU_TAG_H 297c478bd9Sstevel@tonic-gate #define _FRU_TAG_H 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 37*6bbe0590SSundeep Panicker #if defined(_LITTLE_ENDIAN) 38*6bbe0590SSundeep Panicker 39*6bbe0590SSundeep Panicker typedef union { 40*6bbe0590SSundeep Panicker uint64_t raw_data; 41*6bbe0590SSundeep Panicker unsigned char byte[8]; 42*6bbe0590SSundeep Panicker struct { 43*6bbe0590SSundeep Panicker unsigned pl_len : 3; 44*6bbe0590SSundeep Panicker unsigned dense : 4; 45*6bbe0590SSundeep Panicker unsigned type : 1; 46*6bbe0590SSundeep Panicker } a; 47*6bbe0590SSundeep Panicker struct { 48*6bbe0590SSundeep Panicker unsigned pl_len : 3; 49*6bbe0590SSundeep Panicker unsigned dense : 11; 50*6bbe0590SSundeep Panicker unsigned type : 2; 51*6bbe0590SSundeep Panicker } b; 52*6bbe0590SSundeep Panicker struct { 53*6bbe0590SSundeep Panicker unsigned pl_len : 5; 54*6bbe0590SSundeep Panicker unsigned dense : 8; 55*6bbe0590SSundeep Panicker unsigned type : 3; 56*6bbe0590SSundeep Panicker } c; 57*6bbe0590SSundeep Panicker struct { 58*6bbe0590SSundeep Panicker unsigned pl_len : 3; 59*6bbe0590SSundeep Panicker unsigned dense : 17; 60*6bbe0590SSundeep Panicker unsigned type : 4; 61*6bbe0590SSundeep Panicker } d; 62*6bbe0590SSundeep Panicker struct { 63*6bbe0590SSundeep Panicker unsigned pl_len : 7; 64*6bbe0590SSundeep Panicker unsigned dense : 12; 65*6bbe0590SSundeep Panicker unsigned type : 5; 66*6bbe0590SSundeep Panicker } e; 67*6bbe0590SSundeep Panicker struct { 68*6bbe0590SSundeep Panicker unsigned pl_len : 12; 69*6bbe0590SSundeep Panicker unsigned dense : 14; 70*6bbe0590SSundeep Panicker unsigned type : 6; 71*6bbe0590SSundeep Panicker } f; 72*6bbe0590SSundeep Panicker struct { 73*6bbe0590SSundeep Panicker unsigned pl_len : 32; 74*6bbe0590SSundeep Panicker unsigned dense : 9; 75*6bbe0590SSundeep Panicker unsigned type : 7; 76*6bbe0590SSundeep Panicker } g; 77*6bbe0590SSundeep Panicker } fru_tag_t; 78*6bbe0590SSundeep Panicker 79*6bbe0590SSundeep Panicker #else 80*6bbe0590SSundeep Panicker 817c478bd9Sstevel@tonic-gate typedef union { 827c478bd9Sstevel@tonic-gate uint64_t raw_data; 837c478bd9Sstevel@tonic-gate char byte[8]; 847c478bd9Sstevel@tonic-gate struct { 857c478bd9Sstevel@tonic-gate unsigned type : 1; 867c478bd9Sstevel@tonic-gate unsigned dense : 4; 877c478bd9Sstevel@tonic-gate unsigned pl_len : 3; 887c478bd9Sstevel@tonic-gate } a; 897c478bd9Sstevel@tonic-gate struct { 907c478bd9Sstevel@tonic-gate unsigned type : 2; 917c478bd9Sstevel@tonic-gate unsigned dense : 11; 927c478bd9Sstevel@tonic-gate unsigned pl_len : 3; 937c478bd9Sstevel@tonic-gate } b; 947c478bd9Sstevel@tonic-gate struct { 957c478bd9Sstevel@tonic-gate unsigned type : 3; 967c478bd9Sstevel@tonic-gate unsigned dense : 8; 977c478bd9Sstevel@tonic-gate unsigned pl_len : 5; 987c478bd9Sstevel@tonic-gate } c; 997c478bd9Sstevel@tonic-gate struct { 1007c478bd9Sstevel@tonic-gate unsigned type : 4; 1017c478bd9Sstevel@tonic-gate unsigned dense : 17; 1027c478bd9Sstevel@tonic-gate unsigned pl_len : 3; 1037c478bd9Sstevel@tonic-gate } d; 1047c478bd9Sstevel@tonic-gate struct { 1057c478bd9Sstevel@tonic-gate unsigned type : 5; 1067c478bd9Sstevel@tonic-gate unsigned dense : 12; 1077c478bd9Sstevel@tonic-gate unsigned pl_len : 7; 1087c478bd9Sstevel@tonic-gate } e; 1097c478bd9Sstevel@tonic-gate struct { 1107c478bd9Sstevel@tonic-gate unsigned type : 6; 1117c478bd9Sstevel@tonic-gate unsigned dense : 14; 1127c478bd9Sstevel@tonic-gate unsigned pl_len : 12; 1137c478bd9Sstevel@tonic-gate } f; 1147c478bd9Sstevel@tonic-gate struct { 1157c478bd9Sstevel@tonic-gate unsigned type : 7; 1167c478bd9Sstevel@tonic-gate unsigned dense : 9; 1177c478bd9Sstevel@tonic-gate unsigned pl_len : 32; 1187c478bd9Sstevel@tonic-gate } g; 1197c478bd9Sstevel@tonic-gate } fru_tag_t; 1207c478bd9Sstevel@tonic-gate 121*6bbe0590SSundeep Panicker #endif /* LITTLE_ENDIAN */ 122*6bbe0590SSundeep Panicker 1237c478bd9Sstevel@tonic-gate #define FRU_ID_MASK 0xFF 1247c478bd9Sstevel@tonic-gate #define FRU_A_ID 0x00 1257c478bd9Sstevel@tonic-gate #define FRU_B_ID 0x02 1267c478bd9Sstevel@tonic-gate #define FRU_C_ID 0x06 1277c478bd9Sstevel@tonic-gate #define FRU_D_ID 0x0E 1287c478bd9Sstevel@tonic-gate #define FRU_E_ID 0x1E 1297c478bd9Sstevel@tonic-gate #define FRU_F_ID 0x3E 1307c478bd9Sstevel@tonic-gate #define FRU_G_ID 0x7E 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate typedef enum { FRU_A = 0x00, FRU_B = 0x80, FRU_C = 0xc0, 1337c478bd9Sstevel@tonic-gate FRU_D = 0xe0, FRU_E = 0xf0, FRU_F = 0xf8, 1347c478bd9Sstevel@tonic-gate FRU_G = 0xfc, FRU_X = 0xfe } fru_tagtype_t; 1357c478bd9Sstevel@tonic-gate char *get_tagtype_str(fru_tagtype_t e); 1367c478bd9Sstevel@tonic-gate size_t get_tag_size(fru_tagtype_t tag); 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* Returns -1 on error */ 1397c478bd9Sstevel@tonic-gate int mk_tag(fru_tagtype_t type, uint32_t dense, size_t pl_len, 1407c478bd9Sstevel@tonic-gate fru_tag_t *tag); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate fru_tagtype_t get_tag_type(fru_tag_t *tag); 1437c478bd9Sstevel@tonic-gate uint32_t get_tag_dense(fru_tag_t *tag); 1447c478bd9Sstevel@tonic-gate size_t get_payload_length(fru_tag_t *tag); 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* Returns 1 if equal, 0 if not */ 1477c478bd9Sstevel@tonic-gate int tags_equal(fru_tag_t t1, fru_tag_t t2); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate #endif 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate #endif /* _FRU_TAG_H */ 154