Skip to content

Commit

Permalink
fby3.5: hd: Add get card type command (#442)
Browse files Browse the repository at this point in the history
Summary:
- Add IPMI get card type OEM command(Netfn:0x38, cmd:0xA1).

Pull Request resolved: #442

Test Plan: - Build code: PASS

Reviewed By: williamspatrick

Differential Revision: D38376162

Pulled By: garnermic

fbshipit-source-id: 61d0f0ee8b7d045ef760aa123631d099f8d0e76e
  • Loading branch information
Yi-Shum authored and facebook-github-bot committed Aug 3, 2022
1 parent 572428d commit 95cc8e8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
5 changes: 5 additions & 0 deletions meta-facebook/yv35-hd/src/ipmi/include/plat_ipmi.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#ifndef PLAT_IPMI_H
#define PLAT_IPMI_H

enum REQ_GET_CARD_TYPE {
GET_1OU_CARD_TYPE = 0x0,
GET_2OU_CARD_TYPE,
};

#endif
49 changes: 49 additions & 0 deletions meta-facebook/yv35-hd/src/ipmi/plat_ipmi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include "ipmi.h"
#include "plat_ipmi.h"
#include "plat_class.h"

void OEM_1S_GET_CARD_TYPE(ipmi_msg *msg)
{
if (msg == NULL) {
printf("[%s] Failed due to parameter *msg is NULL\n", __func__);
return;
}

if (msg->data_len != 1) {
msg->completion_code = CC_INVALID_LENGTH;
return;
}

CARD_STATUS _1ou_status = get_1ou_status();
CARD_STATUS _2ou_status = get_2ou_status();
switch (msg->data[0]) {
case GET_1OU_CARD_TYPE:
msg->data_len = 2;
msg->completion_code = CC_SUCCESS;
msg->data[0] = GET_1OU_CARD_TYPE;
if (_1ou_status.present) {
msg->data[1] = _1ou_status.card_type;
} else {
msg->data[1] = TYPE_1OU_ABSENT;
}
break;
case GET_2OU_CARD_TYPE:
msg->data_len = 2;
msg->completion_code = CC_SUCCESS;
msg->data[0] = GET_2OU_CARD_TYPE;
if (_2ou_status.present) {
msg->data[1] = _2ou_status.card_type;
} else {
msg->data[1] = TYPE_2OU_ABSENT;
}
break;
default:
msg->data_len = 0;
msg->completion_code = CC_INVALID_DATA_FIELD;
break;
}

return;
}
34 changes: 32 additions & 2 deletions meta-facebook/yv35-hd/src/platform/plat_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define CPLD_ADDR 0x21 // 7-bit address
#define CPLD_CLASS_TYPE_REG 0x05
#define CPLD_2OU_EXPANSION_CARD_REG 0x06
#define CPLD_BOARD_REV_ID_REG 0x08
#define CPLD_1OU_CARD_DETECTION 0x09
#define I2C_DATA_SIZE 5
Expand All @@ -17,6 +18,7 @@
static uint8_t system_class = SYS_CLASS_1;
static uint8_t board_revision = 0x3F;
static CARD_STATUS _1ou_status = { false, TYPE_1OU_UNKNOWN };
static CARD_STATUS _2ou_status = { false, TYPE_2OU_UNKNOWN };

/* ADC information for each channel
* offset: register offset
Expand Down Expand Up @@ -76,6 +78,11 @@ CARD_STATUS get_1ou_status()
return _1ou_status;
}

CARD_STATUS get_2ou_status()
{
return _2ou_status;
}

uint8_t get_board_revision()
{
return board_revision;
Expand Down Expand Up @@ -156,6 +163,7 @@ void init_platform_config()
if (!i2c_master_read(&i2c_msg, retry)) {
class_type = i2c_msg.data[0];
_1ou_status.present = ((class_type & BIT(2)) ? false : true);
_2ou_status.present = ((class_type & BIT(3)) ? false : true);
} else {
printf("Failed to read expansion present from CPLD\n");
}
Expand Down Expand Up @@ -186,8 +194,8 @@ void init_platform_config()
} else {
printf("Failed to read board ID from CPLD\n");
}
printk("BIC class type(class-%d), 1ou present status(%d), board revision(0x%x)\n",
system_class, (int)_1ou_status.present, board_revision);
printk("BIC class type(class-%d), 1ou present status(%d), 2ou present status(%d), board revision(0x%x)\n",
system_class, (int)_1ou_status.present, (int)_2ou_status.present, board_revision);

/* BIC judges the 1OU card type according the ADC-6(0-based) voltage.
* The 1OU card type is
Expand Down Expand Up @@ -266,5 +274,27 @@ void init_platform_config()
}
}

if (_2ou_status.present) {
tx_len = 1;
rx_len = 1;
memset(data, 0, I2C_DATA_SIZE);
data[0] = CPLD_2OU_EXPANSION_CARD_REG;
i2c_msg = construct_i2c_message(I2C_BUS1, CPLD_ADDR, tx_len, data, rx_len);
if (!i2c_master_read(&i2c_msg, retry)) {
switch (i2c_msg.data[0]) {
case TYPE_2OU_DPV2_8:
case TYPE_2OU_DPV2_16:
case (TYPE_2OU_DPV2_8 | TYPE_2OU_DPV2_16):
_2ou_status.card_type = i2c_msg.data[0];
break;
default:
_2ou_status.card_type = TYPE_2OU_UNKNOWN;
printf("Unknown the 2OU card type, the card type read from CPLD is 0x%x\n",
i2c_msg.data[0]);
break;
}
}
}

SAFE_FREE(data);
}
8 changes: 8 additions & 0 deletions meta-facebook/yv35-hd/src/platform/plat_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ enum _1OU_CARD_TYPE_ {
TYPE_1OU_UNKNOWN = 0xFF,
};

enum _2OU_CARD_TYPE_ {
TYPE_2OU_DPV2_8 = 0x07, // DPV2x8
TYPE_2OU_DPV2_16 = 0x70, // DPV2x16
TYPE_2OU_ABSENT = 0xFE,
TYPE_2OU_UNKNOWN = 0xFF,
};

/* ADC channel number */
enum ADC_CHANNEL {
CHANNEL_6 = 6,
Expand All @@ -49,6 +56,7 @@ enum BIC_CARD_PRESENT {

uint8_t get_system_class();
CARD_STATUS get_1ou_status();
CARD_STATUS get_2ou_status();
uint8_t get_board_revision();
bool get_adc_voltage(int channel, float *voltage);
void init_platform_config();
Expand Down

0 comments on commit 95cc8e8

Please sign in to comment.