From e2bcbeb323339cd7f6256e4ec0ab182dbd5cb7dd Mon Sep 17 00:00:00 2001 From: SaraLin-wiwynn Date: Tue, 10 May 2022 17:13:55 -0700 Subject: [PATCH] fby3.5: bb: Optimize CPLD update (#268) Summary: - Modify struct variable name. - Define delay time. - Define LSB to MSB function and add explaining comment. Pull Request resolved: https://github.com/facebook/OpenBIC/pull/268 Test Plan: - Build code: Pass - Update CPLD: Pass Log: 1. Check update CPLD is successful. root@bmc-oob:~# fw-util slot1 --version bb_cpld BB CPLD Version: 00030E05 BB CPLD Version After activation: 00030E05 root@bmc-oob:~# fw-util slot1 --force --update bb_cpld Y35CBB_E06.rpd Failed to get board revision ID slot_id: 1, comp: f, intf: 0, img: Y35CBB_E06.rpd, force: 1 Set fan mode to manual and set PWM to 70% OnChip Flash Status = 0xFFFFFE00., slot_id 0x1, sectype 0x1, intf: 0x10, read 143360 bytes. Erase sector SUCCESS. Erase sector SUCCESS. updated cpld: 100 % Elapsed time: 57 sec. Set fan mode to auto and start fscd Force upgrade of slot1 : bb_cpld succeeded root@bmc-oob:~# power-util sled-cycle packet_write_wait: Connection to 192.168.88.24 port 22: Broken pipe root@bmc-oob:~# fw-util slot1 --version bb_cpld BB CPLD Version: 00030E06 BB CPLD Version After activation: 00030E06 Reviewed By: garnermic Differential Revision: D36076646 Pulled By: GoldenBug fbshipit-source-id: 931efefe0ccc65a89afb65e2ae09b0a59a0d23d6 --- common/dev/altera.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/common/dev/altera.c b/common/dev/altera.c index b8c63dc691..1050edb029 100644 --- a/common/dev/altera.c +++ b/common/dev/altera.c @@ -7,6 +7,18 @@ #include "hal_i2c.h" #define MAX_RETRY 3 +#define CHECK_ALTERA_STATUS_DELAY_US 100 + +// Change bit 1010 1010b(0xaa) and 0101 0101b (0x55) +// e.g. 0123 4567 -> 1032 5476 +// Change bit 1100 1100b(0xcc) and 0011 0011b(0x33) +// e.g. 1032 5476 -> 3210 7654 +// Change bit 1111 0000b(0xf0) and 0000 1111b(0x0f) +// e.g. 3210 7654 -> 7654 3210 +#define SWAP_LSB_TO_MSB(x) \ + x = (((x & 0xaa) >> 1) | ((x & 0x55) << 1)); \ + x = (((x & 0xcc) >> 2) | ((x & 0x33) << 2)); \ + x = (((x & 0xf0) >> 4) | ((x & 0x0f) << 4)); static altera_max10_attr altera_max10_config; @@ -157,12 +169,7 @@ int cpld_altera_max10_fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg) // Swap LSB with MSB before write into CFM for (byte = 0; byte < 4; byte++) { - receive_buffer[byte] = (((receive_buffer[byte] & 0xaa) >> 1) | - ((receive_buffer[byte] & 0x55) << 1)); - receive_buffer[byte] = (((receive_buffer[byte] & 0xcc) >> 2) | - ((receive_buffer[byte] & 0x33) << 2)); - receive_buffer[byte] = (((receive_buffer[byte] & 0xf0) >> 4) | - ((receive_buffer[byte] & 0x0f) << 4)); + SWAP_LSB_TO_MSB(receive_buffer[byte]); } // Combine 4 bytes to 1 word before write operation @@ -186,7 +193,7 @@ int cpld_altera_max10_fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg) } else { printf("status: %x retry...\n", status); - k_usleep(100); + k_usleep(CHECK_ALTERA_STATUS_DELAY_US); retry--; }