cmd: remove sparc-only virtinfo
[unleashed.git] / usr / src / cmd / picl / plugins / sun4u / snowbird / lib / fruaccess / fru_access_impl.h
blob5934cdf88bc60264b64dc7136f375abb5befd21b
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _FRU_ACCESS_IMPL_H
28 #define _FRU_ACCESS_IMPL_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <sys/stat.h>
41 #include <fcntl.h>
42 #include <strings.h>
43 #include <libdevinfo.h>
44 #include <sys/systeminfo.h>
45 #include <picl.h>
46 #include <picltree.h>
47 #include <syslog.h>
48 #include <errno.h>
49 #include <limits.h>
50 #include "picldefs.h"
51 #include "libfru.h"
52 #include "fru_tag.h"
53 #include "fru_access.h"
55 /* converts slot# to ipmb addr */
56 #define IPMB_ADDR(_X) (((_X) < 10) ? (0xb0 + 2 * ((_X) - 1)) :\
57 (0xb0 + 2 * (_X)))
58 #define MANR_TAG 0xF80010B7 /* ManR tag */
59 #define SEG_NAME_LEN 2
61 #define MANR_TIME_LEN 4
62 #define MANR_FRUDESCR_LEN 80
63 #define MANR_MFRLOC_LEN 64
64 #define MANR_PARTNUM_LEN 7
65 #define MANR_SERIALNUM_LEN 6
66 #define MANR_VENDORNAME_LEN 2
67 #define MANR_DASHLVL_LEN 2
68 #define MANR_REVLVL_LEN 2
69 #define MANR_FRUNAME_LEN 16
71 #define NO_FRUDATA 0x0
72 #define IPMI_FORMAT 0x1
73 #define SUN_FORMAT 0x2
75 /* These are newly introduced #defines for Snowbird */
76 #define INPUT_FILE "/dev/ctsmc"
77 #define NUM_OF_SECTIONS 2
78 #define DYNAMIC_OFFSET 0x0
79 #define STATIC_OFFSET 0x1800
80 #define WRITE_SECTION 0
81 #define DYNAMIC_LENGTH (6 * 1024); /* 6k bytes */
82 #define STATIC_LENGTH (2 * 1024); /* 2k bytes */
83 #define MANR_SIZE 183 /* MANR record size in bytes */
85 #define PICL_SLOT_CPCI "cpci"
86 #define PICL_SLOT_PCI "pci"
87 #define PICL_NODE_CHASSIS "chassis"
88 #define SD_SEGMENT_NAME "SD"
89 #define SD_SEGMENT_DESCRIPTOR 0x00004924
90 #define SEGMENT_TRAILER_LEN 1
91 #define SEGMENT_CHKSM_LEN 4
93 /* format structure */
94 typedef struct {
95 int format;
96 int sun_lun; /* this info comes from SDR */
97 int sun_device_id; /* this info comes from SDR */
98 uint8_t src;
99 uint8_t dest;
100 } format_t;
102 /* ManR payload structure */
103 typedef struct {
104 char timestamp[MANR_TIME_LEN];
105 char fru_descr[MANR_FRUDESCR_LEN];
106 char manufacture_loc[MANR_MFRLOC_LEN];
107 char sun_part_no[MANR_PARTNUM_LEN];
108 char sun_serial_no[MANR_SERIALNUM_LEN];
109 char vendor_name[MANR_VENDORNAME_LEN]; /* JEDEC CODE */
110 char inital_hw_dash_lvl[MANR_DASHLVL_LEN];
111 char inital_hw_rev_lvl[MANR_REVLVL_LEN];
112 char fru_short_name[MANR_FRUNAME_LEN];
113 } payload_t;
114 /* object types */
115 typedef enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t;
117 #define TABLE_SIZE 64 /* hash table size */
119 /* section header */
120 #define SECTION_HDR_TAG 0x08
121 #define SECTION_HDR_VER 0x0001
122 #define SECTION_HDR_LENGTH 0x06
123 #define SECTION_HDR_CRC8 0x00
124 #define SECTION_HDR_VER_BIT0 0x00
125 #define SECTION_HDR_VER_BIT1 0x01
127 #define READ_ONLY_SECTION 1 /* section is read-only */
129 #define GET_SEGMENT_DESCRIPTOR \
130 (seg_layout->descriptor[1]|seg_layout->descriptor[0] << 16)
132 #define GET_SECTION_HDR_VERSION \
133 (sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8)
135 /* Segment Trailer Tag */
136 #define SEG_TRAILER_TAG 0x0C
138 /* defines fixed segment */
139 #define SEGMENT_FIXED 1
141 #define DEFAULT_FD -1
142 #define DEFAULT_SEQN -1
143 #define FRUACCESS_MSG_ID 11
145 typedef union {
146 uint32_t all_bits;
147 struct {
148 unsigned read_only : 1;
149 unsigned unused : 8;
150 unsigned : 8;
151 unsigned : 8;
152 unsigned : 7;
153 } field;
154 } sectdescbit_t;
156 typedef struct {
157 sectdescbit_t description;
158 uint32_t address; /* for SEEPROMS this is the offset */
159 uint32_t size;
160 } sectioninfo_t;
162 typedef uint16_t headerrev_t;
164 #define MAX_NUMOF_SECTION 2
166 typedef struct {
167 headerrev_t header_ver;
168 int num_sections;
169 sectioninfo_t section_info[MAX_NUMOF_SECTION];
170 } container_info_t;
172 /* section header layout */
173 typedef struct {
174 uint8_t headertag; /* section header tag */
175 uint8_t headerversion[2]; /* header version (msb) */
176 uint8_t headerlength; /* header length */
177 uint8_t headercrc8; /* crc8 */
178 uint8_t segmentcount; /* total number of segment */
179 } section_layout_t;
181 /* segment header layout */
182 typedef struct {
183 uint16_t name; /* segment name */
184 uint16_t descriptor[2]; /* descriptor (msb) */
185 uint16_t offset; /* segment data offset */
186 uint16_t length; /* segment length */
187 } segment_layout_t;
189 /* segment information used in finding new offset for a new segment */
190 typedef struct {
191 int segnum; /* segment number */
192 int offset; /* segment offset */
193 int length; /* segment length */
194 int fixed; /* fixed or non-fixed segment */
195 } seg_info_t;
197 typedef uint64_t handle_t;
199 struct hash_obj;
201 /* packet hash object */
202 typedef struct {
203 handle_t segment_hdl; /* segment handle */
204 fru_tag_t tag;
205 int tag_size;
206 uint8_t *payload;
207 payload_t payload_data; /* reqd for ipmi format */
208 uint32_t paylen;
209 uint32_t payload_offset;
210 struct hash_obj *next;
211 } packet_obj_t;
213 /* segment hash object */
214 typedef struct {
215 handle_t section_hdl; /* section handle */
216 int num_of_packets; /* in a segment */
217 int trailer_offset;
218 segment_t segment;
219 struct hash_obj *pkt_obj_list; /* packet object list */
220 struct hash_obj *next;
221 } segment_obj_t;
223 /* section hash object */
224 typedef struct {
225 handle_t cont_hdl; /* container handle */
226 section_t section;
227 int num_of_segment; /* in a section */
228 struct hash_obj *seg_obj_list; /* points to segment objects list */
229 struct hash_obj *next;
230 } section_obj_t;
232 /* contianer hash object */
233 typedef struct {
234 char device_pathname[PATH_MAX]; /* device name */
235 int num_of_section; /* num of section in container */
236 format_t format;
237 struct hash_obj *sec_obj_list; /* points to section objects list */
238 } container_obj_t;
240 /* hash object */
241 typedef struct hash_obj {
242 int object_type;
243 handle_t obj_hdl;
244 union {
245 container_obj_t *cont_obj;
246 section_obj_t *sec_obj;
247 segment_obj_t *seg_obj;
248 packet_obj_t *pkt_obj;
249 } u;
250 struct hash_obj *next;
251 struct hash_obj *prev;
252 } hash_obj_t;
254 extern unsigned char compute_crc8(unsigned char *bytes, int length);
255 extern long compute_crc32(unsigned char *bytes, int length);
256 extern long compute_checksum32(unsigned char *bytes, int length);
258 #ifdef __cplusplus
260 #endif
262 #endif /* _FRU_ACCESS_IMPL_H */