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