xref: /onnv-gate/usr/src/lib/libfru/libfruraw/fru_access_impl.h (revision 11015:0a0751599d31)
1*11015SSundeep.Panicker@Sun.COM /*
2*11015SSundeep.Panicker@Sun.COM  * CDDL HEADER START
3*11015SSundeep.Panicker@Sun.COM  *
4*11015SSundeep.Panicker@Sun.COM  * The contents of this file are subject to the terms of the
5*11015SSundeep.Panicker@Sun.COM  * Common Development and Distribution License (the "License").
6*11015SSundeep.Panicker@Sun.COM  * You may not use this file except in compliance with the License.
7*11015SSundeep.Panicker@Sun.COM  *
8*11015SSundeep.Panicker@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*11015SSundeep.Panicker@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*11015SSundeep.Panicker@Sun.COM  * See the License for the specific language governing permissions
11*11015SSundeep.Panicker@Sun.COM  * and limitations under the License.
12*11015SSundeep.Panicker@Sun.COM  *
13*11015SSundeep.Panicker@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*11015SSundeep.Panicker@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*11015SSundeep.Panicker@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*11015SSundeep.Panicker@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*11015SSundeep.Panicker@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*11015SSundeep.Panicker@Sun.COM  *
19*11015SSundeep.Panicker@Sun.COM  * CDDL HEADER END
20*11015SSundeep.Panicker@Sun.COM  */
21*11015SSundeep.Panicker@Sun.COM 
22*11015SSundeep.Panicker@Sun.COM /*
23*11015SSundeep.Panicker@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*11015SSundeep.Panicker@Sun.COM  * Use is subject to license terms.
25*11015SSundeep.Panicker@Sun.COM  */
26*11015SSundeep.Panicker@Sun.COM 
27*11015SSundeep.Panicker@Sun.COM #ifndef	_FRU_ACCESS_IMPL_H
28*11015SSundeep.Panicker@Sun.COM #define	_FRU_ACCESS_IMPL_H
29*11015SSundeep.Panicker@Sun.COM 
30*11015SSundeep.Panicker@Sun.COM #ifdef __cplusplus
31*11015SSundeep.Panicker@Sun.COM extern "C" {
32*11015SSundeep.Panicker@Sun.COM #endif
33*11015SSundeep.Panicker@Sun.COM 
34*11015SSundeep.Panicker@Sun.COM #include <stdlib.h>
35*11015SSundeep.Panicker@Sun.COM #include <stdio.h>
36*11015SSundeep.Panicker@Sun.COM #include <sys/types.h>
37*11015SSundeep.Panicker@Sun.COM #include <unistd.h>
38*11015SSundeep.Panicker@Sun.COM #include <sys/stat.h>
39*11015SSundeep.Panicker@Sun.COM #include <fcntl.h>
40*11015SSundeep.Panicker@Sun.COM #include <dial.h>
41*11015SSundeep.Panicker@Sun.COM #include <strings.h>
42*11015SSundeep.Panicker@Sun.COM #include <libdevinfo.h>
43*11015SSundeep.Panicker@Sun.COM #include <sys/systeminfo.h>
44*11015SSundeep.Panicker@Sun.COM #include <sys/byteorder.h>
45*11015SSundeep.Panicker@Sun.COM #include <syslog.h>
46*11015SSundeep.Panicker@Sun.COM #include <errno.h>
47*11015SSundeep.Panicker@Sun.COM #include <libfru.h>
48*11015SSundeep.Panicker@Sun.COM #include <limits.h>
49*11015SSundeep.Panicker@Sun.COM #include <fru_tag.h>
50*11015SSundeep.Panicker@Sun.COM #include <fru_access.h>
51*11015SSundeep.Panicker@Sun.COM 
52*11015SSundeep.Panicker@Sun.COM 
53*11015SSundeep.Panicker@Sun.COM /* object types */
54*11015SSundeep.Panicker@Sun.COM typedef	enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t;
55*11015SSundeep.Panicker@Sun.COM 
56*11015SSundeep.Panicker@Sun.COM #define	TABLE_SIZE		64	/* hash table size */
57*11015SSundeep.Panicker@Sun.COM 
58*11015SSundeep.Panicker@Sun.COM 
59*11015SSundeep.Panicker@Sun.COM /* section header */
60*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_TAG		0x08
61*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_VER		0x0001
62*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_LENGTH	0x06
63*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_CRC8	0x00
64*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_VER_BIT0	0x00
65*11015SSundeep.Panicker@Sun.COM #define	SECTION_HDR_VER_BIT1	0x01
66*11015SSundeep.Panicker@Sun.COM 
67*11015SSundeep.Panicker@Sun.COM #define	READ_ONLY_SECTION	1	/* section is read-only */
68*11015SSundeep.Panicker@Sun.COM 
69*11015SSundeep.Panicker@Sun.COM #define	GET_SEGMENT_DESCRIPTOR	\
70*11015SSundeep.Panicker@Sun.COM 		(BE_16(seg_layout->descriptor[1])| \
71*11015SSundeep.Panicker@Sun.COM 		BE_16(seg_layout->descriptor[0] << 16))
72*11015SSundeep.Panicker@Sun.COM 
73*11015SSundeep.Panicker@Sun.COM #define	GET_SECTION_HDR_VERSION	\
74*11015SSundeep.Panicker@Sun.COM 		(sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8)
75*11015SSundeep.Panicker@Sun.COM 
76*11015SSundeep.Panicker@Sun.COM /* Segment Trailer Tag */
77*11015SSundeep.Panicker@Sun.COM #define	SEG_TRAILER_TAG 0x0C
78*11015SSundeep.Panicker@Sun.COM 
79*11015SSundeep.Panicker@Sun.COM /* defines fixed segment */
80*11015SSundeep.Panicker@Sun.COM #define	SEGMENT_FIXED		1
81*11015SSundeep.Panicker@Sun.COM 
82*11015SSundeep.Panicker@Sun.COM typedef union {
83*11015SSundeep.Panicker@Sun.COM 	uint32_t all_bits;
84*11015SSundeep.Panicker@Sun.COM 	struct {
85*11015SSundeep.Panicker@Sun.COM 		unsigned read_only : 1;
86*11015SSundeep.Panicker@Sun.COM 		unsigned unused : 8;
87*11015SSundeep.Panicker@Sun.COM 		unsigned : 8;
88*11015SSundeep.Panicker@Sun.COM 		unsigned : 8;
89*11015SSundeep.Panicker@Sun.COM 		unsigned : 7;
90*11015SSundeep.Panicker@Sun.COM 	} field;
91*11015SSundeep.Panicker@Sun.COM } sectdescbit_t;
92*11015SSundeep.Panicker@Sun.COM 
93*11015SSundeep.Panicker@Sun.COM typedef enum {
94*11015SSundeep.Panicker@Sun.COM 	ENC_STANDARD = 0,	/* proper fruid data */
95*11015SSundeep.Panicker@Sun.COM 	ENC_SPD			/* serial presence detect data */
96*11015SSundeep.Panicker@Sun.COM } sectencoding_t;
97*11015SSundeep.Panicker@Sun.COM 
98*11015SSundeep.Panicker@Sun.COM typedef struct {
99*11015SSundeep.Panicker@Sun.COM 	sectdescbit_t	description;
100*11015SSundeep.Panicker@Sun.COM 	uint32_t	address; /* for SEEPROMS this is the offset */
101*11015SSundeep.Panicker@Sun.COM 	uint32_t	size;
102*11015SSundeep.Panicker@Sun.COM 	sectencoding_t	encoding;
103*11015SSundeep.Panicker@Sun.COM } sectioninfo_t;
104*11015SSundeep.Panicker@Sun.COM 
105*11015SSundeep.Panicker@Sun.COM typedef uint16_t headerrev_t;
106*11015SSundeep.Panicker@Sun.COM 
107*11015SSundeep.Panicker@Sun.COM #define	MAX_NUMOF_SECTION	2
108*11015SSundeep.Panicker@Sun.COM 
109*11015SSundeep.Panicker@Sun.COM typedef struct {
110*11015SSundeep.Panicker@Sun.COM 	headerrev_t header_ver;
111*11015SSundeep.Panicker@Sun.COM 	int num_sections;
112*11015SSundeep.Panicker@Sun.COM 	sectioninfo_t section_info[MAX_NUMOF_SECTION];
113*11015SSundeep.Panicker@Sun.COM } container_info_t;
114*11015SSundeep.Panicker@Sun.COM 
115*11015SSundeep.Panicker@Sun.COM 
116*11015SSundeep.Panicker@Sun.COM /* section header layout */
117*11015SSundeep.Panicker@Sun.COM typedef struct {
118*11015SSundeep.Panicker@Sun.COM 	uint8_t	headertag; /* section header tag */
119*11015SSundeep.Panicker@Sun.COM 	uint8_t	headerversion[2]; /* header version (msb) */
120*11015SSundeep.Panicker@Sun.COM 	uint8_t	headerlength; /* header length */
121*11015SSundeep.Panicker@Sun.COM 	uint8_t	headercrc8; /* crc8 */
122*11015SSundeep.Panicker@Sun.COM 	uint8_t	segmentcount; /* total number of segment */
123*11015SSundeep.Panicker@Sun.COM } section_layout_t;
124*11015SSundeep.Panicker@Sun.COM 
125*11015SSundeep.Panicker@Sun.COM /* segment header layout */
126*11015SSundeep.Panicker@Sun.COM typedef struct  {
127*11015SSundeep.Panicker@Sun.COM 	uint16_t	name; 	/* segment name */
128*11015SSundeep.Panicker@Sun.COM 	uint16_t	descriptor[2]; /* descriptor (msb) */
129*11015SSundeep.Panicker@Sun.COM 	uint16_t	offset; /* segment data offset */
130*11015SSundeep.Panicker@Sun.COM 	uint16_t	length; /* segment length */
131*11015SSundeep.Panicker@Sun.COM } segment_layout_t;
132*11015SSundeep.Panicker@Sun.COM 
133*11015SSundeep.Panicker@Sun.COM /* segment information used in finding new offset for a new segment */
134*11015SSundeep.Panicker@Sun.COM typedef struct {
135*11015SSundeep.Panicker@Sun.COM 	int segnum;	/* segment number */
136*11015SSundeep.Panicker@Sun.COM 	int offset;	/* segment offset */
137*11015SSundeep.Panicker@Sun.COM 	int length;	/* segment length */
138*11015SSundeep.Panicker@Sun.COM 	int fixed;	/* fixed or non-fixed segment */
139*11015SSundeep.Panicker@Sun.COM } seg_info_t;
140*11015SSundeep.Panicker@Sun.COM 
141*11015SSundeep.Panicker@Sun.COM typedef	uint64_t	handle_t;
142*11015SSundeep.Panicker@Sun.COM 
143*11015SSundeep.Panicker@Sun.COM struct	hash_obj;
144*11015SSundeep.Panicker@Sun.COM 
145*11015SSundeep.Panicker@Sun.COM /* packet hash object */
146*11015SSundeep.Panicker@Sun.COM typedef	struct {
147*11015SSundeep.Panicker@Sun.COM 	handle_t	segment_hdl;	/* segment handle */
148*11015SSundeep.Panicker@Sun.COM 	fru_tag_t	tag;
149*11015SSundeep.Panicker@Sun.COM 	int		tag_size;
150*11015SSundeep.Panicker@Sun.COM 	uint8_t		*payload;
151*11015SSundeep.Panicker@Sun.COM 	uint32_t	paylen;
152*11015SSundeep.Panicker@Sun.COM 	uint32_t	payload_offset;
153*11015SSundeep.Panicker@Sun.COM 	struct hash_obj *next;
154*11015SSundeep.Panicker@Sun.COM } packet_obj_t;
155*11015SSundeep.Panicker@Sun.COM 
156*11015SSundeep.Panicker@Sun.COM /* segment hash object */
157*11015SSundeep.Panicker@Sun.COM typedef struct {
158*11015SSundeep.Panicker@Sun.COM 	handle_t	section_hdl;	/* section handle */
159*11015SSundeep.Panicker@Sun.COM 	int		num_of_packets;	/* in a segment */
160*11015SSundeep.Panicker@Sun.COM 	int		trailer_offset;
161*11015SSundeep.Panicker@Sun.COM 	segment_t	segment;
162*11015SSundeep.Panicker@Sun.COM 	struct hash_obj	*pkt_obj_list;	/* packet object list */
163*11015SSundeep.Panicker@Sun.COM 	struct hash_obj	*next;
164*11015SSundeep.Panicker@Sun.COM } segment_obj_t;
165*11015SSundeep.Panicker@Sun.COM 
166*11015SSundeep.Panicker@Sun.COM /* section hash object */
167*11015SSundeep.Panicker@Sun.COM typedef	struct {
168*11015SSundeep.Panicker@Sun.COM 	handle_t	cont_hdl;	/* container handle */
169*11015SSundeep.Panicker@Sun.COM 	section_t	section;
170*11015SSundeep.Panicker@Sun.COM 	sectencoding_t	encoding;	/* standard or needing interpretation */
171*11015SSundeep.Panicker@Sun.COM 	int	num_of_segment;		/* in a section */
172*11015SSundeep.Panicker@Sun.COM 	struct hash_obj	*seg_obj_list;	/* points to segment objects list */
173*11015SSundeep.Panicker@Sun.COM 	struct hash_obj	*next;
174*11015SSundeep.Panicker@Sun.COM } section_obj_t;
175*11015SSundeep.Panicker@Sun.COM 
176*11015SSundeep.Panicker@Sun.COM /* container hash object */
177*11015SSundeep.Panicker@Sun.COM typedef	struct {
178*11015SSundeep.Panicker@Sun.COM 	char	device_pathname[PATH_MAX]; /* device name */
179*11015SSundeep.Panicker@Sun.COM 	int	num_of_section;	/* num of section in container */
180*11015SSundeep.Panicker@Sun.COM 	struct hash_obj	*sec_obj_list; /* points to section objects list */
181*11015SSundeep.Panicker@Sun.COM } container_obj_t;
182*11015SSundeep.Panicker@Sun.COM 
183*11015SSundeep.Panicker@Sun.COM /* hash object */
184*11015SSundeep.Panicker@Sun.COM typedef	struct hash_obj {
185*11015SSundeep.Panicker@Sun.COM 	int	object_type;
186*11015SSundeep.Panicker@Sun.COM 	handle_t obj_hdl;
187*11015SSundeep.Panicker@Sun.COM 	union {
188*11015SSundeep.Panicker@Sun.COM 		container_obj_t		*cont_obj;
189*11015SSundeep.Panicker@Sun.COM 		section_obj_t		*sec_obj;
190*11015SSundeep.Panicker@Sun.COM 		segment_obj_t		*seg_obj;
191*11015SSundeep.Panicker@Sun.COM 		packet_obj_t		*pkt_obj;
192*11015SSundeep.Panicker@Sun.COM 	} u;
193*11015SSundeep.Panicker@Sun.COM 	struct hash_obj 	*next;
194*11015SSundeep.Panicker@Sun.COM 	struct hash_obj 	*prev;
195*11015SSundeep.Panicker@Sun.COM } hash_obj_t;
196*11015SSundeep.Panicker@Sun.COM 
197*11015SSundeep.Panicker@Sun.COM unsigned char compute_crc8(unsigned char *bytes, int length);
198*11015SSundeep.Panicker@Sun.COM long compute_crc32(unsigned char *bytes, int length);
199*11015SSundeep.Panicker@Sun.COM long compute_checksum32(unsigned char *bytes, int length);
200*11015SSundeep.Panicker@Sun.COM 
201*11015SSundeep.Panicker@Sun.COM #ifdef	__cplusplus
202*11015SSundeep.Panicker@Sun.COM }
203*11015SSundeep.Panicker@Sun.COM #endif
204*11015SSundeep.Panicker@Sun.COM 
205*11015SSundeep.Panicker@Sun.COM #endif /* _FRU_ACCESS_IMPL_H */
206