xref: /illumos-gate/usr/src/lib/libfruutils/fru_tag.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_FRU_TAG_H
28*7c478bd9Sstevel@tonic-gate #define	_FRU_TAG_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate typedef union {
39*7c478bd9Sstevel@tonic-gate 	uint64_t raw_data;
40*7c478bd9Sstevel@tonic-gate 	char byte[8];
41*7c478bd9Sstevel@tonic-gate 	struct {
42*7c478bd9Sstevel@tonic-gate 		unsigned type : 1;
43*7c478bd9Sstevel@tonic-gate 		unsigned dense : 4;
44*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 3;
45*7c478bd9Sstevel@tonic-gate 	} a;
46*7c478bd9Sstevel@tonic-gate 	struct {
47*7c478bd9Sstevel@tonic-gate 		unsigned type : 2;
48*7c478bd9Sstevel@tonic-gate 		unsigned dense : 11;
49*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 3;
50*7c478bd9Sstevel@tonic-gate 	} b;
51*7c478bd9Sstevel@tonic-gate 	struct {
52*7c478bd9Sstevel@tonic-gate 		unsigned type : 3;
53*7c478bd9Sstevel@tonic-gate 		unsigned dense : 8;
54*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 5;
55*7c478bd9Sstevel@tonic-gate 	} c;
56*7c478bd9Sstevel@tonic-gate 	struct {
57*7c478bd9Sstevel@tonic-gate 		unsigned type : 4;
58*7c478bd9Sstevel@tonic-gate 		unsigned dense : 17;
59*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 3;
60*7c478bd9Sstevel@tonic-gate 	} d;
61*7c478bd9Sstevel@tonic-gate 	struct {
62*7c478bd9Sstevel@tonic-gate 		unsigned type : 5;
63*7c478bd9Sstevel@tonic-gate 		unsigned dense : 12;
64*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 7;
65*7c478bd9Sstevel@tonic-gate 	} e;
66*7c478bd9Sstevel@tonic-gate 	struct {
67*7c478bd9Sstevel@tonic-gate 		unsigned type : 6;
68*7c478bd9Sstevel@tonic-gate 		unsigned dense : 14;
69*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 12;
70*7c478bd9Sstevel@tonic-gate 	} f;
71*7c478bd9Sstevel@tonic-gate 	struct {
72*7c478bd9Sstevel@tonic-gate 		unsigned type : 7;
73*7c478bd9Sstevel@tonic-gate 		unsigned dense : 9;
74*7c478bd9Sstevel@tonic-gate 		unsigned pl_len : 32;
75*7c478bd9Sstevel@tonic-gate 	} g;
76*7c478bd9Sstevel@tonic-gate } fru_tag_t;
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate #define	FRU_ID_MASK 0xFF
79*7c478bd9Sstevel@tonic-gate #define	FRU_A_ID 0x00
80*7c478bd9Sstevel@tonic-gate #define	FRU_B_ID 0x02
81*7c478bd9Sstevel@tonic-gate #define	FRU_C_ID 0x06
82*7c478bd9Sstevel@tonic-gate #define	FRU_D_ID 0x0E
83*7c478bd9Sstevel@tonic-gate #define	FRU_E_ID 0x1E
84*7c478bd9Sstevel@tonic-gate #define	FRU_F_ID 0x3E
85*7c478bd9Sstevel@tonic-gate #define	FRU_G_ID 0x7E
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate typedef enum { FRU_A = 0x00, FRU_B = 0x80, FRU_C = 0xc0,
88*7c478bd9Sstevel@tonic-gate 		FRU_D = 0xe0, FRU_E = 0xf0, FRU_F = 0xf8,
89*7c478bd9Sstevel@tonic-gate 		FRU_G = 0xfc, FRU_X = 0xfe } fru_tagtype_t;
90*7c478bd9Sstevel@tonic-gate char *get_tagtype_str(fru_tagtype_t e);
91*7c478bd9Sstevel@tonic-gate size_t get_tag_size(fru_tagtype_t tag);
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate /* Returns -1 on error */
94*7c478bd9Sstevel@tonic-gate int mk_tag(fru_tagtype_t type, uint32_t dense, size_t pl_len,
95*7c478bd9Sstevel@tonic-gate 		fru_tag_t *tag);
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate fru_tagtype_t get_tag_type(fru_tag_t *tag);
98*7c478bd9Sstevel@tonic-gate uint32_t get_tag_dense(fru_tag_t *tag);
99*7c478bd9Sstevel@tonic-gate size_t get_payload_length(fru_tag_t *tag);
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /* Returns 1 if equal, 0 if not */
102*7c478bd9Sstevel@tonic-gate int tags_equal(fru_tag_t t1, fru_tag_t t2);
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
105*7c478bd9Sstevel@tonic-gate }
106*7c478bd9Sstevel@tonic-gate #endif
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate #endif /* _FRU_TAG_H */
109