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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
|
/*
* ipmi_control_atca_led.cpp
*
* Copyright (c) 2006 by ESO Technologies.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This
* file and program are licensed under a BSD style license. See
* the Copying file included with the OpenHPI distribution for
* full licensing terms.
*
* Authors:
* Pierre Sangouard <psangouard@eso-tech.com>
*/
extern "C" {
#include "SaHpiAtca.h"
}
#include "ipmi_control_atca_led.h"
#include "ipmi_resource.h"
#include "ipmi_log.h"
cIpmiControlAtcaLed::cIpmiControlAtcaLed( cIpmiMc *mc,
unsigned int num,
unsigned char led_color_capabilities,
unsigned char led_default_local_color,
unsigned char led_default_override_color)
: cIpmiControl( mc, num, SAHPI_CTRL_LED,
SAHPI_CTRL_TYPE_OEM ),
m_num( num ),
m_led_color_capabilities( led_color_capabilities ),
m_led_default_local_color( led_default_local_color ),
m_led_local_color( led_default_local_color ),
m_led_default_override_color( led_default_override_color ),
m_led_override_color( led_default_override_color ),
m_set_led_state_supported( false )
{
}
cIpmiControlAtcaLed::~cIpmiControlAtcaLed()
{
}
bool
cIpmiControlAtcaLed::IsSupportedColor(AtcaHpiLedColorT hpi_color)
{
switch(hpi_color)
{
case ATCAHPI_LED_COLOR_BLUE:
return ((m_led_color_capabilities & ATCAHPI_LED_BLUE) != 0);
case ATCAHPI_LED_COLOR_RED:
return ((m_led_color_capabilities & ATCAHPI_LED_RED) != 0);
case ATCAHPI_LED_COLOR_GREEN:
return ((m_led_color_capabilities & ATCAHPI_LED_GREEN) != 0);
case ATCAHPI_LED_COLOR_AMBER:
return ((m_led_color_capabilities & ATCAHPI_LED_AMBER) != 0);
case ATCAHPI_LED_COLOR_ORANGE:
return ((m_led_color_capabilities & ATCAHPI_LED_ORANGE) != 0);
case ATCAHPI_LED_COLOR_WHITE:
return ((m_led_color_capabilities & ATCAHPI_LED_WHITE) != 0);
case ATCAHPI_LED_COLOR_NO_CHANGE:
return true;
case ATCAHPI_LED_COLOR_USE_DEFAULT:
return true;
case ATCAHPI_LED_COLOR_RESERVED:
return false;
}
return false;
}
static unsigned char
hpi_to_atca_color( AtcaHpiLedColorT hpi_color,
unsigned char current_color,
unsigned char default_color )
{
switch(hpi_color)
{
case ATCAHPI_LED_COLOR_BLUE:
return 0x01;
case ATCAHPI_LED_COLOR_RED:
return 0x02;
case ATCAHPI_LED_COLOR_GREEN:
return 0x03;
case ATCAHPI_LED_COLOR_AMBER:
return 0x04;
case ATCAHPI_LED_COLOR_ORANGE:
return 0x05;
case ATCAHPI_LED_COLOR_WHITE:
return 0x06;
case ATCAHPI_LED_COLOR_NO_CHANGE:
return current_color;
case ATCAHPI_LED_COLOR_USE_DEFAULT:
return default_color;
case ATCAHPI_LED_COLOR_RESERVED:
return 0x00;
}
return 0x00;
}
static AtcaHpiLedColorT
atca_to_hpi_color( unsigned char atca_color )
{
switch(atca_color & 0x0F)
{
case 0x01:
return ATCAHPI_LED_COLOR_BLUE;
case 0x02:
return ATCAHPI_LED_COLOR_RED;
case 0x03:
return ATCAHPI_LED_COLOR_GREEN;
case 0x04:
return ATCAHPI_LED_COLOR_AMBER;
case 0x05:
return ATCAHPI_LED_COLOR_ORANGE;
case 0x06:
return ATCAHPI_LED_COLOR_WHITE;
}
return ATCAHPI_LED_COLOR_RESERVED;
}
bool
cIpmiControlAtcaLed::CreateRdr( SaHpiRptEntryT &resource, SaHpiRdrT &rdr )
{
if ( cIpmiControl::CreateRdr( resource, rdr ) == false )
return false;
SaHpiCtrlRecT &rec = rdr.RdrTypeUnion.CtrlRec;
SaHpiCtrlRecOemT &oem_rec = rec.TypeUnion.Oem;
oem_rec.MId = ATCAHPI_PICMG_MID;
oem_rec.ConfigData[0] = m_led_color_capabilities;
oem_rec.ConfigData[1] = atca_to_hpi_color(m_led_default_local_color);
oem_rec.ConfigData[2] = atca_to_hpi_color(m_led_default_override_color);
oem_rec.Default.MId = ATCAHPI_PICMG_MID;
oem_rec.Default.BodyLength = 6;
oem_rec.Default.Body[0] = 0;
oem_rec.Default.Body[1] = 0;
oem_rec.Default.Body[2] = oem_rec.ConfigData[2];
oem_rec.Default.Body[3] = oem_rec.ConfigData[1];
oem_rec.Default.Body[4] = SAHPI_FALSE;
oem_rec.Default.Body[5] = 0;
cIpmiMsg ledmsg( eIpmiNetfnPicmg, eIpmiCmdSetFruLedState );
ledmsg.m_data[0] = dIpmiPicMgId;
ledmsg.m_data[1] = Resource()->FruId();
ledmsg.m_data[2] = m_num;
ledmsg.m_data_len = 6;
cIpmiMsg ledrsp;
/*
There seems that there is an issue with ATCA-HPI mapping in that
Req 4.5.7.7 says that an LED with a local control state and either an
Override or Lamp test state should set the Control Mode Read Only status
to SAHPI_FALSE, however there is no atomic way to check for support
of the Override State. Therefore, there is no obvious "safe" way to implement
the spec as stated, only best alternatives. The approach taken here is to
set the Control Mode Read Only status to SAHPI_FALSE automatically if the
LED has a local control state. This will allow for issuing the Set FRU LED
state commands, however the unsupported states (Override and/or Lamp Test)
will return the specified Completion Code of CCh(invalid date field),
as stated in the ATCA base spec.
*/
if ( m_led_default_local_color == 0 )
{
rec.DefaultMode.Mode = SAHPI_CTRL_MODE_MANUAL;
rec.DefaultMode.ReadOnly = SAHPI_TRUE;
m_set_led_state_supported = false;
oem_rec.ConfigData[1] = 0;
}
else
{
rec.DefaultMode.Mode = SAHPI_CTRL_MODE_AUTO;
rec.DefaultMode.ReadOnly = SAHPI_FALSE;
m_set_led_state_supported = true;
}
rec.WriteOnly = SAHPI_FALSE;
rec.Oem = ATCAHPI_PICMG_CT_ATCA_LED;
return true;
}
SaErrorT
cIpmiControlAtcaLed::SetState( const SaHpiCtrlModeT &mode, const SaHpiCtrlStateT &state )
{
cIpmiMsg ledmsg( eIpmiNetfnPicmg, eIpmiCmdSetFruLedState );
ledmsg.m_data[0] = dIpmiPicMgId;
ledmsg.m_data[1] = Resource()->FruId();
ledmsg.m_data[2] = m_num;
ledmsg.m_data_len = 6;
if ( mode == SAHPI_CTRL_MODE_AUTO )
{
if ( m_led_default_local_color == 0 )
return SA_ERR_HPI_READ_ONLY;
ledmsg.m_data[3] = 0xFC;
ledmsg.m_data[4] = 0x00;
ledmsg.m_data[5] = m_led_local_color;
}
else if ( mode != SAHPI_CTRL_MODE_MANUAL )
{
return SA_ERR_HPI_INVALID_PARAMS;
}
else
{
if ( m_set_led_state_supported == false )
return SA_ERR_HPI_READ_ONLY;
if ( &state == NULL )
return SA_ERR_HPI_INVALID_PARAMS;
if ( state.Type != SAHPI_CTRL_TYPE_OEM )
return SA_ERR_HPI_INVALID_DATA;
if ( state.StateUnion.Oem.MId != ATCAHPI_PICMG_MID )
return SA_ERR_HPI_INVALID_DATA;
if ( state.StateUnion.Oem.BodyLength != 6 )
return SA_ERR_HPI_INVALID_DATA;
if ( state.StateUnion.Oem.Body[4] == SAHPI_TRUE )
{
if ( state.StateUnion.Oem.Body[5] > 127 )
return SA_ERR_HPI_INVALID_PARAMS;
}
if ( state.StateUnion.Oem.Body[1] == 0xFF )
{
if ( state.StateUnion.Oem.Body[0] != 0x00 )
return SA_ERR_HPI_INVALID_PARAMS;
}
else if ( state.StateUnion.Oem.Body[1] == 0x00 )
{
if ( state.StateUnion.Oem.Body[0] != 0x00 )
return SA_ERR_HPI_INVALID_PARAMS;
}
else if ( state.StateUnion.Oem.Body[1] > 0xFA )
{
return SA_ERR_HPI_INVALID_PARAMS;
}
if ( state.StateUnion.Oem.Body[0] > 0xFA )
{
return SA_ERR_HPI_INVALID_PARAMS;
}
else if ( state.StateUnion.Oem.Body[0] == 0 )
{
if (( state.StateUnion.Oem.Body[1] != 0xFF )
&& ( state.StateUnion.Oem.Body[1] != 0x00 ))
return SA_ERR_HPI_INVALID_PARAMS;
}
if ( IsSupportedColor((AtcaHpiLedColorT)state.StateUnion.Oem.Body[2]) == false )
return SA_ERR_HPI_INVALID_PARAMS;
if ( m_led_default_local_color != 0 )
{
if ( IsSupportedColor((AtcaHpiLedColorT)state.StateUnion.Oem.Body[3]) == false )
return SA_ERR_HPI_INVALID_PARAMS;
}
m_led_override_color = hpi_to_atca_color((AtcaHpiLedColorT)state.StateUnion.Oem.Body[2],
m_led_override_color,
m_led_default_override_color);
if ( m_led_default_local_color != 0 )
m_led_local_color = hpi_to_atca_color((AtcaHpiLedColorT)state.StateUnion.Oem.Body[3],
m_led_local_color,
m_led_default_local_color);
if ( state.StateUnion.Oem.Body[4] == SAHPI_TRUE )
{
ledmsg.m_data[3] = 0xFB;
ledmsg.m_data[4] = state.StateUnion.Oem.Body[5];
}
else
{
if ( state.StateUnion.Oem.Body[1] == 0xFF )
{
ledmsg.m_data[3] = 0xFF;
ledmsg.m_data[4] = 0x00;
}
else if ( state.StateUnion.Oem.Body[1] == 0x00 )
{
ledmsg.m_data[3] = 0x00;
ledmsg.m_data[4] = 0x00;
}
else
{
ledmsg.m_data[3] = state.StateUnion.Oem.Body[0];
ledmsg.m_data[4] = state.StateUnion.Oem.Body[1];
}
}
ledmsg.m_data[5] = m_led_override_color;
}
cIpmiMsg ledrsp;
SaErrorT rv = Resource()->SendCommandReadLock( this, ledmsg, ledrsp );
if ( rv != SA_OK
|| ledrsp.m_data_len < 2
|| ledrsp.m_data[0] != eIpmiCcOk
|| ledrsp.m_data[1] != dIpmiPicMgId )
{
stdlog << "cannot set FRU LED state !\n";
return (rv != SA_OK) ? rv : SA_ERR_HPI_INVALID_REQUEST;
}
return SA_OK;
}
SaErrorT
cIpmiControlAtcaLed::GetState( SaHpiCtrlModeT &mode, SaHpiCtrlStateT &state )
{
cIpmiMsg ledmsg( eIpmiNetfnPicmg, eIpmiCmdGetFruLedState );
ledmsg.m_data[0] = dIpmiPicMgId;
ledmsg.m_data[1] = Resource()->FruId();
ledmsg.m_data[2] = m_num;
ledmsg.m_data_len = 3;
cIpmiMsg ledrsp;
SaErrorT rv = Resource()->SendCommandReadLock( this, ledmsg, ledrsp );
if ( rv != SA_OK
|| ledrsp.m_data_len < 6
|| ledrsp.m_data[0] != eIpmiCcOk
|| ledrsp.m_data[1] != dIpmiPicMgId )
{
stdlog << "cannot get FRU LED state !\n";
return (rv != SA_OK) ? rv : SA_ERR_HPI_INVALID_REQUEST;
}
if ( &mode != NULL )
{
if ( (ledrsp.m_data[2] & 0x06) != 0 )
{
mode = SAHPI_CTRL_MODE_MANUAL;
}
else
{
mode = SAHPI_CTRL_MODE_AUTO;
}
}
if ( &state != NULL)
{
state.Type = SAHPI_CTRL_TYPE_OEM;
state.StateUnion.Oem.MId = ATCAHPI_PICMG_MID;
state.StateUnion.Oem.BodyLength = 6;
// Lamp test on
if ( (ledrsp.m_data[2] & 0x04) != 0 )
{
if ( ledrsp.m_data[6] == 0x00 )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0;
}
else if ( ledrsp.m_data[6] == 0xFF )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0xFF;
}
else
{
state.StateUnion.Oem.Body[0] = ledrsp.m_data[6];
state.StateUnion.Oem.Body[1] = ledrsp.m_data[7];
}
state.StateUnion.Oem.Body[2] = atca_to_hpi_color(ledrsp.m_data[8]);
state.StateUnion.Oem.Body[3] = atca_to_hpi_color(ledrsp.m_data[5]);
state.StateUnion.Oem.Body[4] = SAHPI_TRUE;
state.StateUnion.Oem.Body[5] = ledrsp.m_data[9];
}
// Override state on
else if ( (ledrsp.m_data[2] & 0x02) != 0 )
{
if ( ledrsp.m_data[6] == 0x00 )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0;
}
else if ( ledrsp.m_data[6] == 0xFF )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0xFF;
}
else
{
state.StateUnion.Oem.Body[0] = ledrsp.m_data[6];
state.StateUnion.Oem.Body[1] = ledrsp.m_data[7];
}
state.StateUnion.Oem.Body[2] = atca_to_hpi_color(ledrsp.m_data[8]);
state.StateUnion.Oem.Body[3] = atca_to_hpi_color(ledrsp.m_data[5]);
state.StateUnion.Oem.Body[4] = SAHPI_FALSE;
state.StateUnion.Oem.Body[5] = 0;
}
else
{
if ( ledrsp.m_data[3] == 0x00 )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0;
}
else if ( ledrsp.m_data[3] == 0xFF )
{
state.StateUnion.Oem.Body[0] = 0;
state.StateUnion.Oem.Body[1] = 0xFF;
}
else
{
state.StateUnion.Oem.Body[0] = ledrsp.m_data[3];
state.StateUnion.Oem.Body[1] = ledrsp.m_data[4];
}
state.StateUnion.Oem.Body[2] = atca_to_hpi_color(m_led_override_color);
state.StateUnion.Oem.Body[3] = atca_to_hpi_color(ledrsp.m_data[5]);
state.StateUnion.Oem.Body[4] = SAHPI_FALSE;
state.StateUnion.Oem.Body[5] = 0;
}
}
return SA_OK;
}
void
cIpmiControlAtcaLed::Dump( cIpmiLog &dump, const char *name ) const
{
dump.Begin( "AtcaLedControl", name );
dump.Entry( "LedNum" ) << m_num << ";\n";
dump.End();
}
|