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