Skip to content

Move sensor read to common code#144

Closed
Yi-Shum wants to merge 9 commits into
facebook:mainfrom
Yi-Shum:Modify_sensor_read_to_common_code
Closed

Move sensor read to common code#144
Yi-Shum wants to merge 9 commits into
facebook:mainfrom
Yi-Shum:Modify_sensor_read_to_common_code

Conversation

@Yi-Shum

@Yi-Shum Yi-Shum commented Jan 26, 2022

Copy link
Copy Markdown
Collaborator

Summary:

  • Move code about sensor reading from platform code to common code.
  • Modify sensor reading value to 4 bytes, 2 bytes for integer, 2 bytes for fraction.
  • Provide README file describing how to add new device.

Notice:

  • BMC needs to support parsing 4-byte accuracy sensor reading. Otherwise, sensor-util command would print wrong value.

Test Plan:

  • Build code: Pass
  • Test OEM sensor reading command: Pass

Log:

root@bmc-oob:~# bic-util slot1 0xe0 0x23 0x9c 0x9c 0x00 0x01 0x00
9C 9C 00 26 00 00 00 C0
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
```
@Yi-Shum Yi-Shum requested a review from GoldenBug January 26, 2022 09:19
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 26, 2022
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@DelphineChiu

Copy link
Copy Markdown

@GoldenBug @garnermic

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.

Comment thread common/sensor/dev/ast_adc.c
Comment thread common/sensor/dev/ast_adc.c Outdated
sequence.resolution = ADC_RESOLUTION;
sequence.calibrate = ADC_CALIBRATE;

for (uint8_t i = 0; i < ADC_NUM; i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this for loop, if ADC0 is not ready, it skips ADC1 totally. Is this the expected behavior or should it also check ADC1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, ADC0 will be skipped and continue to initialize ADC1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

Comment thread common/sensor/dev/intel_peci.c Outdated
#include <string.h>
#include "intel_peci.h"

#define READ_RTY 0x03

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will rename rty to retry in next commit.

Comment thread common/sensor/dev/intel_peci.c Outdated
#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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rty should be retry

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will rename rty to retry in next commit.

Comment thread common/sensor/dev/intel_peci.c Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above with rty

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will rename rty to retry in next commit.

Comment thread common/sensor/dev/intel_peci.c Outdated
if (!reading)
return false;

const uint16_t param = (type == PECI_TEMP_DIMM_A) ? 0x00 :

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread common/sensor/dev/intel_peci.c
Comment thread common/sensor/dev/intel_peci.c Outdated
peci_init();
is_init = true;
}
return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check if the return value of peci_init() is except.
If not, return false.

Comment thread common/sensor/dev/isl28022.c Outdated

uint8_t isl28022_read(uint8_t sensor_num, int* reading) {
if((reading == NULL) ||
(sensor_config[SnrNum_SnrCfg_map[sensor_num]].init_args == NULL)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need consistency in naming of 'sensor' or 'Snr'. probably just use sensor

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Eddie043

Copy link
Copy Markdown
Contributor

Hi @GoldenBug,

Thanks for your suggestion and we modified the DIMM temperature and the return code of the sensor initialization function.
The sensor naming isn't impacted the firmware behavior, so I will create another issue to track.
Except for the sensor naming, do you have other concerns about the code logic of this PR?

ODMA had been run the AC/DC cycle testing over 1000 without failed and the ODMB also passed the same test with 250 cycles.
We have enough confidence for the PR by the test result.

@GoldenBug

Copy link
Copy Markdown
Contributor

Could you please rebase this then I can get it reviewed again?
Thanks!

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Yi-Shum Yi-Shum force-pushed the Modify_sensor_read_to_common_code branch from 6130dd6 to 147cd96 Compare February 23, 2022 07:24
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Yi-Shum

Yi-Shum commented Feb 23, 2022

Copy link
Copy Markdown
Collaborator Author

We've forced updated the PR to rebase the main branch.
Please help to review again, thank you.

@GoldenBug GoldenBug left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2 main comments I have are:

  1. Please extend all sensor names to follow the same pattern.
    sen -> sensor and snr -> sensor
  2. Some functions return 1 on success and 0 on failure. Usually, C standard is to return 0 on success.
Comment thread common/sensor/README.txt Outdated
Take TMP75 sensor as an example.
1. common/sensor/sensor.c
'''
SEN_DRIVE_INIT_DECLARE(tmp75);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we spell out sensor to make it more obvious what we are referring to.

Comment thread common/sensor/README.txt Outdated
Comment on lines +27 to +29
sen_drive_tbl[] = {
SEN_DRIVE_TYPE_INIT_MAP(tmp75),
.....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spell out SENSOR and sensor_

Comment thread common/sensor/dev/adm1278.c Outdated

default:
printf("Invalid sensor 0x%x\n", sensor_num);
return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this return a uint8_t, either an actual value or a enum for failure?

Comment thread common/sensor/dev/adm1278.c Outdated
return false;
}

sen_val *sval = (sen_val *)reading;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sen -> sensor

Comment thread common/sensor/dev/ast_adc.c Outdated

enum adc_device_idx { adc0, adc1, ADC_NUM };

#define ADC_CHAN_NUM 8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets extend it to ADC_CHANNEL_NUM so it is written out like the other ADC constant names

Comment thread common/sensor/dev/pex89000.c Outdated
uint8_t data_len)
{
if (!set_full_addr(bus, addr, oft))
return 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return non-0 on failure

Comment thread common/sensor/dev/pex89000.c Outdated
Comment on lines +217 to +218
exit:
return rc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This goto seems unnecessary. Can we just return failure when it happens?

Comment thread common/sensor/dev/pex89000.c Outdated
Comment on lines +252 to +253
exit:
return rc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, goto seems unnecessary because there isn't any cleanup happening as far as I can tell.
Just return error when it happens.

Comment thread common/sensor/dev/pex89000.c Outdated
Comment on lines +292 to +293
exit:
return rc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary goto

Comment thread common/sensor/pmbus.h
Comment on lines +67 to +69
PMBUS_POUT_OP_FAULT_LIMIT = 0x68,
PMBUS_POUT_OP_WARN_LIMIT = 0x6A,
PMBUS_PIN_OP_WARN_LIMIT = 0x6B,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Yi-Shum

Yi-Shum commented Feb 24, 2022

Copy link
Copy Markdown
Collaborator Author

Hi @GoldenBug,
We have submitted a commit to revise the comment you provided, including:

  1. Extend sensor names to follow the same pattern.
    "sen" -> "sensor" and "snr" -> "sensor"
  2. Modify function return value, return 0 if success, non-0 if fail.
  3. Remove unnecessary goto.
  4. Add 0x69 in pmbus.h

Please help to review again, thank you.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@GoldenBug

Copy link
Copy Markdown
Contributor

I still see a lot of SNR uses. Please look at extending all the use cases of SNR.
We may need to change SNR in other files this commit didn't touch and that's ok.

@Yi-Shum

Yi-Shum commented Mar 1, 2022

Copy link
Copy Markdown
Collaborator Author

OK, we will change all SNR to sensor.

Yi-Shum added 2 commits March 1, 2022 08:52
Summary:
- Extend the names of variables, functions and macros from "snr" or "sen" to "sensor"

Test Plan:
- Build Code: PASS
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Yi-Shum

Yi-Shum commented Mar 1, 2022

Copy link
Copy Markdown
Collaborator Author

Hi @GoldenBug,
We have submitted two commits with changes including:

  1. merge to main branch.
  2. Extend the name of variables, functions and macros from "snr" or "sen" to "sensor".

Please help to review again, thank you.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@GoldenBug has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@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
@Yi-Shum Yi-Shum force-pushed the Modify_sensor_read_to_common_code branch from eb423a0 to 38ac074 Compare March 8, 2022 06:35
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@Yi-Shum has updated the pull request. You must reimport the pull request before landing.

@Yi-Shum

Yi-Shum commented Mar 8, 2022

Copy link
Copy Markdown
Collaborator Author

Hi @GoldenBug,
We have submitted two commits with changes including:

  1. Merge to main branch.
  2. Add path of common sensor code into CMakeList.txt of yv35_bb.
  3. Apply Clang format to all change files.

Please help to review again, thank you.

@Yi-Shum Yi-Shum requested a review from GoldenBug March 8, 2022 06:43
@GoldenBug GoldenBug reopened this Mar 9, 2022
facebook-github-bot pushed a commit that referenced this pull request Mar 9, 2022
Summary:
Recreating this PR because #144  was improperly merged from a middle commit instead of the HEAD of that PR branch.

Pull Request resolved: #192

Reviewed By: garnermic

Differential Revision: D34743248

Pulled By: GoldenBug

fbshipit-source-id: f98af23
facebook-github-bot pushed a commit that referenced this pull request Mar 9, 2022
Summary:
Adding Missing Common Code Commits for #144

Pull Request resolved: #193

Test Plan: GitHub Actions Test for Now

Reviewed By: doranand

Differential Revision: D34749382

Pulled By: GoldenBug

fbshipit-source-id: bcd341e
@GoldenBug GoldenBug closed this Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

6 participants