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 2002 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 */ 27 28 #ifndef _FRU_ACCESS_IMPL_H 29 #define _FRU_ACCESS_IMPL_H 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #include <stdlib.h> 38 #include <stdio.h> 39 #include <sys/types.h> 40 #include <unistd.h> 41 #include <sys/stat.h> 42 #include <fcntl.h> 43 #include <dial.h> 44 #include <strings.h> 45 #include <libdevinfo.h> 46 #include <sys/systeminfo.h> 47 #include <picl.h> 48 #include <picltree.h> 49 #include "picldefs.h" 50 #include <syslog.h> 51 #include <errno.h> 52 #include "libfru.h" 53 #include "fru_tag.h" 54 #include "fru_access.h" 55 56 /* object types */ 57 typedef enum {CONTAINER_TYPE, SECTION_TYPE, SEGMENT_TYPE, PACKET_TYPE} object_t; 58 59 #define TABLE_SIZE 64 /* hash table size */ 60 61 /* container configuration file name */ 62 #define CONTAINER_CONF_FILE \ 63 "/usr/platform/SUNW,Serverblade1/lib/fru_container.conf" 64 65 /* section header */ 66 #define SECTION_HDR_TAG 0x08 67 #define SECTION_HDR_VER 0x0001 68 #define SECTION_HDR_LENGTH 0x06 69 #define SECTION_HDR_CRC8 0x00 70 #define SECTION_HDR_VER_BIT0 0x00 71 #define SECTION_HDR_VER_BIT1 0x01 72 73 #define READ_ONLY_SECTION 1 /* section is read-only */ 74 75 #define CRC32_SECTION 0 76 #define CHECKSUM32_SECTION 1 77 78 #define GET_SEGMENT_DESCRIPTOR \ 79 (seg_layout->descriptor[1]|seg_layout->descriptor[0] << 16) 80 81 #define GET_SECTION_HDR_VERSION \ 82 (sec_hdr.headerversion[1]|sec_hdr.headerversion[0] << 8) 83 84 /* Segment Trailer Tag */ 85 #define SEG_TRAILER_TAG 0x0C 86 87 /* defines fixed segment */ 88 #define SEGMENT_FIXED 1 89 90 typedef union { 91 uint32_t all_bits; 92 struct { 93 unsigned read_only : 1; 94 unsigned chk_type : 1; 95 unsigned unused : 8; 96 unsigned : 8; 97 unsigned : 8; 98 unsigned : 6; 99 } field; 100 } sectdescbit_t; 101 102 typedef struct { 103 sectdescbit_t description; 104 uint32_t address; /* for SEEPROMS this is the offset */ 105 uint32_t size; 106 } sectioninfo_t; 107 108 typedef uint16_t headerrev_t; 109 110 #define MAX_NUMOF_SECTION 2 111 112 typedef struct { 113 headerrev_t header_ver; 114 int num_sections; 115 sectioninfo_t section_info[MAX_NUMOF_SECTION]; 116 } container_info_t; 117 118 119 /* section header layout */ 120 typedef struct { 121 uint8_t headertag; /* section header tag */ 122 uint8_t headerversion[2]; /* header version (msb) */ 123 uint8_t headerlength; /* header length */ 124 uint8_t headercrc8; /* crc8 */ 125 uint8_t segmentcount; /* total number of segment */ 126 } section_layout_t; 127 128 /* segment header layout */ 129 typedef struct { 130 uint16_t name; /* segment name */ 131 uint16_t descriptor[2]; /* descriptor (msb) */ 132 uint16_t offset; /* segment data offset */ 133 uint16_t length; /* segment length */ 134 } segment_layout_t; 135 136 /* segment information used in finding new offset for a new segment */ 137 typedef struct { 138 int segnum; /* segment number */ 139 int offset; /* segment offset */ 140 int length; /* segment length */ 141 int fixed; /* fixed or non-fixed segment */ 142 } seg_info_t; 143 144 typedef uint64_t handle_t; 145 146 struct hash_obj; 147 148 /* packet hash object */ 149 typedef struct { 150 handle_t segment_hdl; /* segment handle */ 151 fru_tag_t tag; 152 int tag_size; 153 uint32_t paylen; 154 uint32_t payload_offset; 155 struct hash_obj *next; 156 } packet_obj_t; 157 158 /* segment hash object */ 159 typedef struct { 160 handle_t section_hdl; /* section handle */ 161 int num_of_packets; /* in a segment */ 162 int trailer_offset; 163 segment_t segment; 164 struct hash_obj *pkt_obj_list; /* packet object list */ 165 struct hash_obj *next; 166 } segment_obj_t; 167 168 /* section hash object */ 169 typedef struct { 170 handle_t cont_hdl; /* container handle */ 171 section_t section; 172 int num_of_segment; /* in a section */ 173 int checksum_method; /* indicates the checksum method used */ 174 struct hash_obj *seg_obj_list; /* points to segment objects list */ 175 struct hash_obj *next; 176 } section_obj_t; 177 178 /* container hash object */ 179 typedef struct { 180 char device_pathname[PATH_MAX]; /* device name */ 181 int num_of_section; /* num of section in container */ 182 struct hash_obj *sec_obj_list; /* points to section objects list */ 183 } container_obj_t; 184 185 /* hash object */ 186 typedef struct hash_obj { 187 int object_type; 188 handle_t obj_hdl; 189 union { 190 container_obj_t *cont_obj; 191 section_obj_t *sec_obj; 192 segment_obj_t *seg_obj; 193 packet_obj_t *pkt_obj; 194 } u; 195 struct hash_obj *next; 196 struct hash_obj *prev; 197 } hash_obj_t; 198 199 unsigned char compute_crc8(unsigned char *bytes, int length); 200 long compute_crc32(unsigned char *bytes, int length); 201 long compute_checksum32(unsigned char *bytes, int length); 202 203 #ifdef __cplusplus 204 } 205 #endif 206 207 #endif /* _FRU_ACCESS_IMPL_H */ 208