1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
|
/*
* Copyright (c) 2012 Pigeon Point Systems. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Pigeon Point Systems nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* PIGEON POINT SYSTEMS ("PPS") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* PPS OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF PPS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <ipmitool/bswap.h>
#include <ipmitool/hpm2.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/log.h>
#include <ipmitool/bswap.h>
#if HAVE_PRAGMA_PACK
# pragma pack(push, 1)
#endif
/* HPM.x Get Capabilities request */
struct hpmx_cmd_get_capabilities_rq {
uint8_t picmg_id;
uint8_t hpmx_id;
} ATTRIBUTE_PACKING;
/* HPM.2 Get Capabilities response */
struct hpm2_cmd_get_capabilities_rp {
uint8_t picmg_id;
struct hpm2_lan_attach_capabilities caps;
} ATTRIBUTE_PACKING;
#if HAVE_PRAGMA_PACK
# pragma pack(pop)
#endif
/* IPMI Get LAN Configuration Parameters command */
#define IPMI_LAN_GET_CONFIG 0x02
int hpm2_get_capabilities(struct ipmi_intf * intf,
struct hpm2_lan_attach_capabilities * caps)
{
struct ipmi_rq req;
struct ipmi_rs * rsp;
struct hpmx_cmd_get_capabilities_rq rq;
/* reset result */
memset(caps, 0, sizeof(struct hpm2_lan_attach_capabilities));
/* prepare request */
rq.picmg_id = 0;
rq.hpmx_id = 2;
/* prepare request */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_PICMG;
req.msg.cmd = HPM2_GET_LAN_ATTACH_CAPABILITIES;
req.msg.data = (uint8_t *)&rq;
req.msg.data_len = sizeof(rq);
/* send */
rsp = intf->sendrecv(intf, &req);
if (!rsp) {
lprintf(LOG_NOTICE, "Error sending request.");
return -1;
}
if (rsp->ccode == 0xC1) {
lprintf(LOG_DEBUG, "IPM Controller is not HPM.2 compatible");
return rsp->ccode;
} else if (rsp->ccode) {
lprintf(LOG_NOTICE, "Get HPM.x Capabilities request failed,"
" compcode = %x", rsp->ccode);
return rsp->ccode;
}
/* check response length */
if (rsp->data_len < 2 || rsp->data_len > 10) {
lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len);
return -1;
}
/* check HPM.x identifier */
if (rsp->data[1] != 2) {
lprintf(LOG_NOTICE, "Bad HPM.x ID, id=%d", rsp->data[1]);
return rsp->ccode;
}
/*
* this hardly can happen, since completion code is already checked.
* but check for safety
*/
if (rsp->data_len < 4) {
lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len);
return -1;
}
/* copy HPM.2 capabilities */
memcpy(caps, rsp->data + 2, rsp->data_len - 2);
#if WORDS_BIGENDIAN
/* swap bytes to convert from little-endian format */
caps->lan_channel_mask = BSWAP_16(caps->lan_channel_mask);
#endif
/* check HPM.2 revision */
if (caps->hpm2_revision_id != HPM2_REVISION) {
lprintf(LOG_NOTICE, "Bad HPM.2 revision, rev=%d",
caps->hpm2_revision_id);
return -1;
}
if (!caps->lan_channel_mask) {
return -1;
}
/* check response length */
if (rsp->data_len < 8) {
lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len);
return -1;
}
/* check HPM.2 LAN parameters start */
if (caps->hpm2_lan_params_start < 0xC0) {
lprintf(LOG_NOTICE, "Bad HPM.2 LAN params start, start=%x",
caps->hpm2_lan_params_start);
return -1;
}
/* check HPM.2 LAN parameters revision */
if (caps->hpm2_lan_params_rev != HPM2_LAN_PARAMS_REV) {
lprintf(LOG_NOTICE, "Bad HPM.2 LAN params revision, rev=%d",
caps->hpm2_lan_params_rev);
return -1;
}
/* check for HPM.2 SOL extension */
if (!(caps->hpm2_caps & HPM2_CAPS_SOL_EXTENSION)) {
/* no further checks */
return 0;
}
/* check response length */
if (rsp->data_len < 10) {
lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len);
return -1;
}
/* check HPM.2 SOL parameters start */
if (caps->hpm2_sol_params_start < 0xC0) {
lprintf(LOG_NOTICE, "Bad HPM.2 SOL params start, start=%x",
caps->hpm2_sol_params_start);
return -1;
}
/* check HPM.2 SOL parameters revision */
if (caps->hpm2_sol_params_rev != HPM2_SOL_PARAMS_REV) {
lprintf(LOG_NOTICE, "Bad HPM.2 SOL params revision, rev=%d",
caps->hpm2_sol_params_rev);
return -1;
}
return 0;
}
int hpm2_get_lan_channel_capabilities(struct ipmi_intf * intf,
uint8_t hpm2_lan_params_start,
struct hpm2_lan_channel_capabilities * caps)
{
struct ipmi_rq req;
struct ipmi_rs * rsp;
uint8_t rq[4];
/* reset result */
memset(caps, 0, sizeof(struct hpm2_lan_channel_capabilities));
/* prepare request */
memset(&req, 0, sizeof(req));
req.msg.netfn = IPMI_NETFN_TRANSPORT;
req.msg.cmd = IPMI_LAN_GET_CONFIG;
req.msg.data = (uint8_t *)&rq;
req.msg.data_len = sizeof(rq);
/* prepare request data */
rq[0] = 0xE; /* sending channel */
rq[1] = hpm2_lan_params_start; /* HPM.2 Channel Caps */
rq[2] = rq[3] = 0;
/* send */
rsp = intf->sendrecv(intf, &req);
if (rsp) {
lprintf(LOG_NOTICE, "Error sending request");
return -1;
}
if (rsp->ccode == 0x80) {
lprintf(LOG_DEBUG, "HPM.2 Channel Caps parameter is not supported");
return rsp->ccode;
} else if (rsp->ccode) {
lprintf(LOG_NOTICE, "Get LAN Configuration Parameters request failed,"
" compcode = %x", rsp->ccode);
return rsp->ccode;
}
/* check response length */
if (rsp->data_len != sizeof (struct hpm2_lan_channel_capabilities) + 1) {
lprintf(LOG_NOTICE, "Bad response length, len=%d", rsp->data_len);
return -1;
}
/* check parameter revision */
if (rsp->data[0] !=
LAN_PARAM_REV(HPM2_LAN_PARAMS_REV, HPM2_LAN_PARAMS_REV)) {
lprintf(LOG_NOTICE, "Bad HPM.2 LAN parameter revision, rev=%d",
rsp->data[0]);
return -1;
}
/* copy parameter data */
memcpy(caps, &rsp->data[1], sizeof (struct hpm2_lan_channel_capabilities));
#if WORDS_BIGENDIAN
/* swap bytes to convert from little-endian format */
caps->max_inbound_pld_size = BSWAP_16(caps->max_inbound_pld_size);
caps->max_outbound_pld_size = BSWAP_16(caps->max_outbound_pld_size);
#endif
return 0;
}
int hpm2_detect_max_payload_size(struct ipmi_intf * intf)
{
struct hpm2_lan_attach_capabilities attach_caps;
struct hpm2_lan_channel_capabilities channel_caps;
int err;
/* query HPM.2 support */
err = hpm2_get_capabilities(intf, &attach_caps);
/* check if HPM.2 is supported */
if (err != 0 || !attach_caps.lan_channel_mask) {
return err;
}
/* query channel capabilities */
err = hpm2_get_lan_channel_capabilities(intf,
attach_caps.hpm2_lan_params_start, &channel_caps);
/* check if succeeded */
if (err != 0) {
return err;
}
/* update request and response sizes */
ipmi_intf_set_max_request_data_size(intf,
channel_caps.max_inbound_pld_size - 7);
ipmi_intf_set_max_response_data_size(intf,
channel_caps.max_outbound_pld_size - 8);
/* print debug info */
lprintf(LOG_DEBUG, "Set maximum request size to %d\n"
"Set maximum response size to %d",
intf->max_request_data_size, intf->max_response_data_size);
return 0;
}
|