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