Move sensor read to common code#144
Conversation
Summary: - Move code about sensor reading from platform code to common code. - Provide README file describing how to add new sensors. Test Plan: - Build code: Pass - Command test: Pass Log: ``` root@bmc-oob:~# bic-util slot1 0xe0 0x23 0x9c 0x9c 0x00 0x01 0x00 9C 9C 00 26 00 00 00 C0 ```
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
This PR need to be phased in with BMC code change, otherwise it will cause sensor reading/reporting issues for all the BIC sensors. BMC portion is planned to be PRed by today taiwan time and not yet pull requested. For this moment, (before one day of release), I would suggest that we don't merge them (both BMC/BIC port) today. Wiwynn is discussing with ODMB to get more detail test status to get more confidence for the pull request. |
| sequence.resolution = ADC_RESOLUTION; | ||
| sequence.calibrate = ADC_CALIBRATE; | ||
|
|
||
| for (uint8_t i = 0; i < ADC_NUM; i++) { |
There was a problem hiding this comment.
In this for loop, if ADC0 is not ready, it skips ADC1 totally. Is this the expected behavior or should it also check ADC1?
There was a problem hiding this comment.
In this case, ADC0 will be skipped and continue to initialize ADC1.
| #include <string.h> | ||
| #include "intel_peci.h" | ||
|
|
||
| #define READ_RTY 0x03 |
There was a problem hiding this comment.
I am assuming RTY is retry, but it is not clear. In this #define and in the function names below, retry should be spelled out if that is what it is intended to do.
There was a problem hiding this comment.
We will rename rty to retry in next commit.
| #define RDPKG_IDX_DIMM_TEMP 0x0E | ||
| #define RDPKG_IDX_TJMAX_TEMP 0x10 | ||
|
|
||
| static bool peci_rty_read(uint8_t cmd, uint8_t addr, uint8_t idx, uint16_t param, uint8_t rlen, uint8_t *rbuf) |
There was a problem hiding this comment.
We will rename rty to retry in next commit.
| uint8_t rbuf[rlen]; | ||
| memset(rbuf, 0, sizeof(rbuf)); | ||
|
|
||
| if (peci_rty_read(PECI_CMD_RD_PKG_CFG0, addr, RDPKG_IDX_TJMAX_TEMP, param, rlen, rbuf) == false) |
There was a problem hiding this comment.
We will rename rty to retry in next commit.
| if (!reading) | ||
| return false; | ||
|
|
||
| const uint16_t param = (type == PECI_TEMP_DIMM_A) ? 0x00 : |
There was a problem hiding this comment.
This makes assumptions on DIMM_X always being mapped to DIMM_A through DIMM_H on platforms. With the recent proposal by the RTP team to renumber DIMM slots to A0 through A7, hard-coding these values might lead to future code changes to accommodate both numberings.
There was a problem hiding this comment.
Thanks for the suggestion, I think we can follow the intel PECI command format to define which value should be used in the PECI generic code.
In the PECI specification, the DDR DIMM temperature command with
request parameters - channel index, and
response data - DIMM# temperature.
There are 8 channels in this CPU SKU with two DIMMs per channel.
Therefore, the DIMM temperature of the enum can be defined as below.
PECI_TEMP_CHANNEL0_DIMM0,
PECI_TEMP_CHANNEL0_DIMM1,
PECI_TEMP_CHANNEL1_DIMM0,
PECI_TEMP_CHANNEL1_DIMM1,
PECI_TEMP_CHANNEL2_DIMM0,
PECI_TEMP_CHANNEL2_DIMM1,
PECI_TEMP_CHANNEL3_DIMM0,
PECI_TEMP_CHANNEL3_DIMM1,
PECI_TEMP_CHANNEL4_DIMM0,
PECI_TEMP_CHANNEL4_DIMM1,
PECI_TEMP_CHANNEL5_DIMM0,
PECI_TEMP_CHANNEL5_DIMM1,
PECI_TEMP_CHANNEL6_DIMM0,
PECI_TEMP_CHANNEL6_DIMM1,
PECI_TEMP_CHANNEL7_DIMM0,
PECI_TEMP_CHANNEL7_DIMM1,
In the platform code, it can map the DIMM temperature sensor to the physical DIMM channel with any naming by the above enum define.
I think it is more clear in the common code and separate the platform naming rule.
I am looking forward to your reply.
Thanks
| peci_init(); | ||
| is_init = true; | ||
| } | ||
| return true; |
There was a problem hiding this comment.
Not sure about the return code for this function. It never returns false even if the sensor is not initialized. Thus, I think this line should be return is_init and not return true.
There was a problem hiding this comment.
Will check if the return value of peci_init() is except.
If not, return false.
|
|
||
| uint8_t isl28022_read(uint8_t sensor_num, int* reading) { | ||
| if((reading == NULL) || | ||
| (sensor_config[SnrNum_SnrCfg_map[sensor_num]].init_args == NULL)) { |
There was a problem hiding this comment.
Need consistency in naming of 'sensor' or 'Snr'. probably just use sensor
There was a problem hiding this comment.
Will discuss with ODMA.
Summary: - Modify macro and function name from "rty" to "retry". - Add enumerate for return value of device return function. - Modify DIMM name in intel_peci. - Check if peci is successfully initialized in intel_peci. Test Plan: - Build Code: Pass
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
Hi @GoldenBug, Thanks for your suggestion and we modified the DIMM temperature and the return code of the sensor initialization function. ODMA had been run the AC/DC cycle testing over 1000 without failed and the ODMB also passed the same test with 250 cycles. |
|
Could you please rebase this then I can get it reviewed again? |
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
6130dd6 to
147cd96
Compare
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
We've forced updated the PR to rebase the main branch. |
GoldenBug
left a comment
There was a problem hiding this comment.
The 2 main comments I have are:
- Please extend all sensor names to follow the same pattern.
sen -> sensor and snr -> sensor - Some functions return 1 on success and 0 on failure. Usually, C standard is to return 0 on success.
| Take TMP75 sensor as an example. | ||
| 1. common/sensor/sensor.c | ||
| ''' | ||
| SEN_DRIVE_INIT_DECLARE(tmp75); |
There was a problem hiding this comment.
Can we spell out sensor to make it more obvious what we are referring to.
| sen_drive_tbl[] = { | ||
| SEN_DRIVE_TYPE_INIT_MAP(tmp75), | ||
| ..... |
There was a problem hiding this comment.
Spell out SENSOR and sensor_
|
|
||
| default: | ||
| printf("Invalid sensor 0x%x\n", sensor_num); | ||
| return false; |
There was a problem hiding this comment.
Can this return a uint8_t, either an actual value or a enum for failure?
| return false; | ||
| } | ||
|
|
||
| sen_val *sval = (sen_val *)reading; |
|
|
||
| enum adc_device_idx { adc0, adc1, ADC_NUM }; | ||
|
|
||
| #define ADC_CHAN_NUM 8 |
There was a problem hiding this comment.
Lets extend it to ADC_CHANNEL_NUM so it is written out like the other ADC constant names
| uint8_t data_len) | ||
| { | ||
| if (!set_full_addr(bus, addr, oft)) | ||
| return 0; |
| exit: | ||
| return rc; |
There was a problem hiding this comment.
This goto seems unnecessary. Can we just return failure when it happens?
| exit: | ||
| return rc; |
There was a problem hiding this comment.
Same here, goto seems unnecessary because there isn't any cleanup happening as far as I can tell.
Just return error when it happens.
| exit: | ||
| return rc; |
| PMBUS_POUT_OP_FAULT_LIMIT = 0x68, | ||
| PMBUS_POUT_OP_WARN_LIMIT = 0x6A, | ||
| PMBUS_PIN_OP_WARN_LIMIT = 0x6B, |
There was a problem hiding this comment.
was 0x69 skipped on purpose?
Summary: - Extend sensor names to follow the same pattern. "sen" -> "sensor" and "snr" -> "sensor" - Modify function return value, return 0 if success, non-0 if fail. - Remove unnecessary goto. - Add 0x69 in pmbus.h Test plan: - Build Code: Pass
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
Hi @GoldenBug,
Please help to review again, thank you. |
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
I still see a lot of SNR uses. Please look at extending all the use cases of SNR. |
|
OK, we will change all SNR to sensor. |
Summary: - Extend the names of variables, functions and macros from "snr" or "sen" to "sensor" Test Plan: - Build Code: PASS
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
Hi @GoldenBug,
Please help to review again, thank you. |
|
@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
Summary: - Add path of common sensor code to yv35_bb CMakeList.txt - Apply Clang format to all change files Test plan: - Build Code: PASS
eb423a0 to
38ac074
Compare
|
@Yi-Shum has updated the pull request. You must reimport the pull request before landing. |
|
Hi @GoldenBug,
Please help to review again, thank you. |
Summary:
Notice:
Test Plan:
Log: