Skip to content

Commit f1145d8

Browse files
Scron-Changfacebook-github-bot
authored andcommitted
fby3.5: rf: Impl CXL FW update (#521)
Summary: 1. Enable the USB feature. BMC will use this bus to transfer data to update. 2. Implement CXL controller FW update. 3. Change the SPI clock to 3.125MHz. The RF needs to reduce the SPI clock in the EVT stage due to hardware buffer limitations. This patch can be removed when RF gets into the DVT stage. 4. Correct the specifier of fw_update printf to pass the run-coocheck. Pull Request resolved: #521 Reviewed By: zhdaniel12 Differential Revision: D39151109 Pulled By: GoldenBug fbshipit-source-id: 1ae032708255881e00b110953e3001e414748b38
1 parent e35b062 commit f1145d8

File tree

8 files changed

+95
-53
lines changed

8 files changed

+95
-53
lines changed

common/lib/util_spi.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sect
276276
}
277277

278278
if ((buf_offset + msg_len) > SECTOR_SZ_64K) {
279-
printf("spi bus%x recv data %d over sector size %d\n", flash_position,
279+
printf("spi bus%x recv data %u over sector size %d\n", flash_position,
280280
buf_offset + msg_len, SECTOR_SZ_64K);
281281
SAFE_FREE(txbuf);
282282
k_msleep(10);
@@ -351,18 +351,9 @@ uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sect
351351
return FWUPDATE_SUCCESS;
352352
}
353353

354-
uint8_t fw_update_cxl(uint8_t flash_position)
354+
__weak uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end)
355355
{
356-
int ret = 0;
357-
const struct device *flash_dev;
358-
359-
flash_dev = device_get_binding(flash_device[flash_position]);
360-
ret = spi_nor_re_init(flash_dev);
361-
if (ret != 0) {
362-
return FWUPDATE_UPDATE_FAIL;
363-
}
364-
//TODO: do real update until know CXL fw update format and progress
365-
return FWUPDATE_SUCCESS;
356+
return FWUPDATE_NOT_SUPPORT;
366357
}
367358

368359
__weak int pal_get_bios_flash_position()
@@ -374,13 +365,3 @@ __weak bool pal_switch_bios_spi_mux(int gpio_status)
374365
{
375366
return true;
376367
}
377-
378-
__weak int pal_get_cxl_flash_position()
379-
{
380-
return -1;
381-
}
382-
383-
__weak bool pal_switch_cxl_spi_mux()
384-
{
385-
return false;
386-
}

common/lib/util_spi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ enum DEVICE_POSITIONS {
2626

2727
uint8_t fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end,
2828
uint8_t flash_position);
29-
uint8_t fw_update_cxl(uint8_t flash_position);
29+
uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end);
3030

3131
uint8_t get_fw_sha256(uint8_t *msg_buf, uint32_t offset, uint32_t length, uint8_t flash_position);
3232

3333
int pal_get_bios_flash_position();
3434
bool pal_switch_bios_spi_mux(int gpio_status);
3535
int pal_get_cxl_flash_position();
36-
bool pal_switch_cxl_spi_mux();
3736

3837
enum FIRMWARE_UPDATE_RETURN_CODE {
3938
FWUPDATE_SUCCESS,
@@ -42,6 +41,7 @@ enum FIRMWARE_UPDATE_RETURN_CODE {
4241
FWUPDATE_REPEATED_UPDATED,
4342
FWUPDATE_UPDATE_FAIL,
4443
FWUPDATE_ERROR_OFFSET,
44+
FWUPDATE_NOT_SUPPORT,
4545
};
4646

4747
#if DT_NODE_HAS_STATUS(DT_PATH(soc, spi_7e620000), okay)

common/service/ipmi/oem_1s_handler.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,9 @@ __weak void OEM_1S_FW_UPDATE(ipmi_msg *msg)
231231
} else if ((target == CPLD_UPDATE) || (target == (CPLD_UPDATE | IS_SECTOR_END_MASK))) {
232232
status = cpld_altera_max10_fw_update(offset, length, &msg->data[7]);
233233

234-
} else if (target == CXL_UPDATE) {
235-
int pos = pal_get_cxl_flash_position();
236-
if (pos == -1) {
237-
msg->completion_code = CC_INVALID_PARAM;
238-
return;
239-
}
240-
241-
bool ret = pal_switch_cxl_spi_mux();
242-
if (ret == false) {
243-
msg->completion_code = CC_UNSPECIFIED_ERROR;
244-
return;
245-
}
246-
247-
status = fw_update_cxl(pos);
234+
} else if (target == CXL_UPDATE || (target == (CXL_UPDATE | IS_SECTOR_END_MASK))) {
235+
status =
236+
fw_update_cxl(offset, length, &msg->data[7], (target & IS_SECTOR_END_MASK));
248237

249238
} else {
250239
msg->completion_code = CC_INVALID_DATA_FIELD;
@@ -272,6 +261,9 @@ __weak void OEM_1S_FW_UPDATE(ipmi_msg *msg)
272261
case FWUPDATE_ERROR_OFFSET:
273262
msg->completion_code = CC_PARAM_OUT_OF_RANGE;
274263
break;
264+
case FWUPDATE_NOT_SUPPORT:
265+
msg->completion_code = CC_INVALID_PARAM;
266+
break;
275267
default:
276268
msg->completion_code = CC_UNSPECIFIED_ERROR;
277269
break;
@@ -977,7 +969,7 @@ __weak void OEM_1S_CONTROL_SENSOR_POLLING(ipmi_msg *msg)
977969
// Enable or Disable sensor polling
978970
sensor_config[control_sensor_index].is_enable_polling =
979971
((operation == DISABLE_SENSOR_POLLING) ? DISABLE_SENSOR_POLLING :
980-
ENABLE_SENSOR_POLLING);
972+
ENABLE_SENSOR_POLLING);
981973
msg->data[return_data_index + 1] =
982974
sensor_config[control_sensor_index].is_enable_polling;
983975
} else {

meta-facebook/yv35-rf/boards/ast1030_evb.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CONFIG_TACH_ASPEED=n
99
CONFIG_ESPI_ASPEED=n
1010
CONFIG_PECI_ASPEED=n
1111
CONFIG_PECI_ASPEED_INTERRUPT_DRIVEN=n
12-
CONFIG_USB_ASPEED=n
12+
CONFIG_USB_ASPEED=y
1313
CONFIG_I3C_ASPEED=n
1414
CONFIG_CRYPTO=n
1515
CONFIG_CRYPTO_ASPEED=n

meta-facebook/yv35-rf/boards/ast1030_evb.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
&spi1_cs0 {
9595
status = "okay";
9696
spi-max-buswidth = <4>;
97-
spi-max-frequency = <50000000>;
97+
spi-max-frequency = <3125000>;
9898
re-init-support;
9999
};
100100

meta-facebook/yv35-rf/prj.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ CONFIG_I3C_SLAVE=n
5353
CONFIG_I3C_SLAVE_MQUEUE=n
5454
CONFIG_WATCHDOG=y
5555
#USB
56-
CONFIG_USB=n
57-
CONFIG_USB_DEVICE_STACK=n
56+
CONFIG_USB=y
57+
CONFIG_USB_DEVICE_STACK=y
5858
CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM"
59-
CONFIG_USB_CDC_ACM=n
59+
CONFIG_USB_CDC_ACM=y
6060
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=576
6161
CONFIG_USB_DEVICE_VID=0x1d6b
6262
CONFIG_USB_DEVICE_PID=0x0104
Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,91 @@
1+
#include <stdio.h>
2+
#include <plat_power_seq.h>
3+
14
#include "hal_gpio.h"
25
#include "util_spi.h"
6+
#include "util_sys.h"
37
#include "plat_gpio.h"
48

5-
bool pal_switch_cxl_spi_mux()
9+
#define CXL_FLASH_TO_BIC 1
10+
#define CXL_FLASH_TO_CXL 0
11+
12+
#define CXL_UPDATE_MAX_OFFSET 0x2000000
13+
14+
static bool switch_cxl_spi_mux(int gpio_status)
615
{
7-
// Switch CXL MUX selection pin to BIC
8-
int ret = gpio_set(SPI_MASTER_SEL, GPIO_HIGH);
9-
if (ret != 0) {
16+
if (gpio_status != CXL_FLASH_TO_BIC && gpio_status != CXL_FLASH_TO_CXL) {
17+
printf("[%s] Invalid argument\n", __func__);
1018
return false;
1119
}
1220

13-
// Enable CXL MUX
14-
ret = gpio_set(FM_SPI_MUX_OE_CTL_N, GPIO_LOW);
15-
if (ret != 0) {
21+
if (gpio_set(SPI_MASTER_SEL, gpio_status)) {
22+
printf("Fail to switch the flash to %s\n",
23+
(gpio_status == CXL_FLASH_TO_BIC) ? "BIC" : "PIONEER");
1624
return false;
1725
}
26+
1827
return true;
1928
}
2029

21-
int pal_get_cxl_flash_position()
30+
static bool control_flash_power(int power_state)
31+
{
32+
int control_mode = 0;
33+
34+
switch (power_state) {
35+
case POWER_OFF:
36+
control_mode = DISABLE_POWER_MODE;
37+
break;
38+
case POWER_ON:
39+
control_mode = ENABLE_POWER_MODE;
40+
break;
41+
default:
42+
return false;
43+
}
44+
45+
for (int retry = 3;; retry--) {
46+
if (gpio_get(P1V8_ASIC_PG_R) == power_state) {
47+
return true;
48+
}
49+
50+
if (!retry) {
51+
break;
52+
}
53+
54+
control_power_stage(control_mode, P1V8_ASIC_EN_R);
55+
k_msleep(CHKPWR_DELAY_MSEC);
56+
}
57+
58+
printf("Fail to %s the ASIC_1V8\n", (power_state == POWER_OFF) ? "disable" : "enable");
59+
60+
return false;
61+
}
62+
63+
uint8_t fw_update_cxl(uint32_t offset, uint16_t msg_len, uint8_t *msg_buf, bool sector_end)
2264
{
23-
return DEVSPI_SPI1_CS0;
65+
uint8_t ret = FWUPDATE_UPDATE_FAIL;
66+
bool last = ((offset + msg_len) == CXL_UPDATE_MAX_OFFSET);
67+
68+
if (offset > CXL_UPDATE_MAX_OFFSET) {
69+
return FWUPDATE_OVER_LENGTH;
70+
}
71+
72+
// Enable the P1V8_ASCI to power the flash
73+
if (control_flash_power(POWER_ON) == false) {
74+
return FWUPDATE_UPDATE_FAIL;
75+
}
76+
77+
// Set high to choose the BIC as the host
78+
if (switch_cxl_spi_mux(CXL_FLASH_TO_BIC) == false) {
79+
printf("Fail to switch PIONEER flash to BIC\n");
80+
return FWUPDATE_UPDATE_FAIL;
81+
}
82+
83+
ret = fw_update(offset, msg_len, msg_buf, sector_end, DEVSPI_SPI1_CS0);
84+
85+
if (last || ret != FWUPDATE_SUCCESS) {
86+
control_flash_power(POWER_OFF);
87+
switch_cxl_spi_mux(CXL_FLASH_TO_CXL);
88+
}
89+
90+
return ret;
2491
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#ifndef PLAT_DEF_H
22
#define PLAT_DEF_H
33

4+
#define BMC_USB_PORT "CDC_ACM_0"
5+
46
#endif

0 commit comments

Comments
 (0)