1 /*
2  * ipmi_sdr.h
3  *
4  * MontaVista IPMI interface for SDRs
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2002,2003 MontaVista Software Inc.
11  *
12  *  This program is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Lesser General Public License
14  *  as published by the Free Software Foundation; either version 2 of
15  *  the License, or (at your option) any later version.
16  *
17  *
18  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  You should have received a copy of the GNU Lesser General Public
30  *  License along with this program; if not, write to the Free
31  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33 
34 #ifndef OPENIPMI_SDR_H
35 #define OPENIPMI_SDR_H
36 #include <OpenIPMI/ipmi_types.h>
37 #include <stdint.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define MAX_SDR_DATA 255
44 
45 /* Generic information about an SDR. */
46 typedef struct ipmi_sdr_s
47 {
48     uint16_t record_id;
49     uint8_t  major_version;
50     uint8_t  minor_version;
51     uint8_t  type;
52     uint8_t  length;
53     uint8_t  data[MAX_SDR_DATA];
54 } ipmi_sdr_t;
55 
56 /* Opaque type representing a remote SDR repository. */
57 typedef struct ipmi_sdr_info_s ipmi_sdr_info_t;
58 
59 /* Create a local representation of a remote SDR repository.  When
60    created, it will not automatically fetch the remote SDRs, you need
61    to do that.  If "sensor" is true, then this will fetch the "sensor"
62    SDRs using GET DEVICE SDR.  If not, it will use GET SDR for
63    fetching SDRs. */
64 int ipmi_sdr_info_alloc(ipmi_domain_t   *domain,
65 			ipmi_mc_t       *mc,
66 			unsigned int    lun,
67 			int             sensor,
68 			ipmi_sdr_info_t **new_sdrs);
69 
70 /* Remove all the SDRs, but don't destroy the SDR repository. */
71 void ipmi_sdr_clean_out_sdrs(ipmi_sdr_info_t *sdrs);
72 
73 /* Stop any timer operation; if the MC is in shutdown this should halt
74    any running operations. */
75 void ipmi_sdr_cleanout_timer(ipmi_sdr_info_t *sdrs);
76 
77 /* Destroy an SDR.  Note that if the SDR is currently fetching SDRs,
78    the destroy cannot complete immediatly, it will be marked for
79    destruction later.  You can supply a callback that, if not NULL,
80    will be called when the sdr is destroyed. */
81 typedef void (*ipmi_sdr_destroyed_t)(ipmi_sdr_info_t *sdrs, void *cb_data);
82 int ipmi_sdr_info_destroy(ipmi_sdr_info_t      *sdrs,
83 			  ipmi_sdr_destroyed_t handler,
84 			  void                 *cb_data);
85 
86 /* Fetch the remote SDRs, but do not wait until the fetch is complete,
87    return immediately.  When the fetch is complete, call the given
88    handler. */
89 typedef void (*ipmi_sdrs_fetched_t)(ipmi_sdr_info_t *sdrs,
90 				    int             err,
91 				    int             changed,
92 				    unsigned int    count,
93 				    void            *cb_data);
94 int ipmi_sdr_fetch(ipmi_sdr_info_t     *sdrs,
95 		   ipmi_sdrs_fetched_t handler,
96 		   void                *cb_data);
97 
98 /* Return the number of SDRs in the sdr repository. */
99 int ipmi_get_sdr_count(ipmi_sdr_info_t *sdr,
100 		       unsigned int    *count);
101 
102 /* Find the SDR with the given record id. */
103 int ipmi_get_sdr_by_recid(ipmi_sdr_info_t *sdr,
104 			  int             recid,
105 			  ipmi_sdr_t      *return_sdr);
106 
107 /* Find the first SDR with the given type. */
108 int ipmi_get_sdr_by_type(ipmi_sdr_info_t *sdr,
109 			 int             type,
110 			 ipmi_sdr_t      *return_sdr);
111 
112 /* Find the SDR with the given index. The indexes are the internal
113    array indexes for the SDR, this can be used to iterate through the
114    SDRs. */
115 int ipmi_get_sdr_by_index(ipmi_sdr_info_t *sdr,
116 			  int             index,
117 			  ipmi_sdr_t      *return_sdr);
118 
119 /* Set an SDR's value.  This is primarily for the OEM SDR fixup code,
120    so it can fix an SDR and write it back. */
121 int ipmi_set_sdr_by_index(ipmi_sdr_info_t *sdrs,
122 			  int             index,
123 			  ipmi_sdr_t      *sdr);
124 
125 /* Fetch all the sdrs.  The array size should point to a value that
126    holds the number of elements in the passed in array.  The
127    array_size will be set to the actual number of elements put into
128    the array.  If the number of SDRs is larger than the supplied
129    array_size, this will return E2BIG and do nothing. */
130 int ipmi_get_all_sdrs(ipmi_sdr_info_t *sdr,
131 		      int             *array_size,
132 		      ipmi_sdr_t      *array);
133 
134 /* Get various information from the IPMI SDR info commands. */
135 int ipmi_sdr_get_major_version(ipmi_sdr_info_t *sdr, int *val);
136 int ipmi_sdr_get_minor_version(ipmi_sdr_info_t *sdr, int *val);
137 int ipmi_sdr_get_overflow(ipmi_sdr_info_t *sdr, int *val);
138 int ipmi_sdr_get_update_mode(ipmi_sdr_info_t *sdr, int *val);
139 int ipmi_sdr_get_supports_delete_sdr(ipmi_sdr_info_t *sdr, int *val);
140 int ipmi_sdr_get_supports_partial_add_sdr(ipmi_sdr_info_t *sdr, int *val);
141 int ipmi_sdr_get_supports_reserve_sdr(ipmi_sdr_info_t *sdr, int *val);
142 int ipmi_sdr_get_supports_get_sdr_repository_allocation(ipmi_sdr_info_t *sdr,
143 							int             *val);
144 int ipmi_sdr_get_dynamic_population(ipmi_sdr_info_t *sdr, int *val);
145 int ipmi_sdr_get_lun_has_sensors(ipmi_sdr_info_t *sdr,
146 				 unsigned int    lun,
147 				 int             *val);
148 
149 /* Append the SDR to the repository. */
150 int ipmi_sdr_add(ipmi_sdr_info_t *sdrs,
151 		 ipmi_sdr_t      *sdr);
152 
153 /* Store the SDRs into the SDR repository. */
154 typedef void (*ipmi_sdr_save_cb)(ipmi_sdr_info_t *sdrs, int err, void *cb_data);
155 int ipmi_sdr_save(ipmi_sdr_info_t  *sdrs,
156 		  ipmi_sdr_save_cb done,
157 		  void             *cb_data);
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif /* OPENIPMI_SDR_H */
164