From d3ce8d9d54debf7666d3069732b6b30e50b81856 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:38:30 -0300 Subject: [PATCH 01/16] [rtm-8sfp/rtm_user.c] Remove debug LED control THe LED should be controlled only by the LED task, to avoid conflict and state override --- port/board/rtm-8sfp/rtm_user.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/port/board/rtm-8sfp/rtm_user.c b/port/board/rtm-8sfp/rtm_user.c index 0ef2ac030..bf6d1e9b3 100644 --- a/port/board/rtm-8sfp/rtm_user.c +++ b/port/board/rtm-8sfp/rtm_user.c @@ -35,19 +35,11 @@ void rtm_enable_payload_power( void ) { gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 1 ); - /* Debug LEDs */ - pca9554_write_pin( RTM_GPIO_LED_RED, 1 ); - pca9554_write_pin( RTM_GPIO_LED_BLUE, 1 ); - pca9554_write_pin( RTM_GPIO_LED_GREEN, 0 ); } void rtm_disable_payload_power( void ) { gpio_set_pin_state( PIN_PORT(GPIO_EN_RTM_PWR), PIN_NUMBER(GPIO_EN_RTM_PWR), 0 ); - /* Debug LEDs */ - pca9554_write_pin( RTM_GPIO_LED_RED, 0 ); - pca9554_write_pin( RTM_GPIO_LED_BLUE, 0 ); - pca9554_write_pin( RTM_GPIO_LED_GREEN, 1 ); } uint8_t rtm_get_hotswap_handle_status( uint8_t *state ) @@ -97,11 +89,6 @@ void rtm_hardware_init( void ) { rtm_enable_i2c(); pca9554_set_port_dir( 0x1F ); - - /* Turn on Blue LED and off Red and Green */ - pca9554_write_pin( RTM_GPIO_LED_BLUE, 0 ); - pca9554_write_pin( RTM_GPIO_LED_RED, 1 ); - pca9554_write_pin( RTM_GPIO_LED_GREEN, 1 ); } void rtm_enable_i2c( void ) From 9066ac381182ee482045339117e13d237f1b8817 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:41:01 -0300 Subject: [PATCH 02/16] [rtm-8sfp/rtm_user.c] Add timeout on RTM presence ping First, default the function reading to ABSENT, since a I2C failure also means that the board is not connected. By adding a timeout on the bus config function we avoid reporting the board as absent if the I2C bus is busy. 100ms should be enough time for the firmware to free the bus. --- port/board/rtm-8sfp/rtm_user.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/port/board/rtm-8sfp/rtm_user.c b/port/board/rtm-8sfp/rtm_user.c index bf6d1e9b3..b5b53619a 100644 --- a/port/board/rtm-8sfp/rtm_user.c +++ b/port/board/rtm-8sfp/rtm_user.c @@ -73,16 +73,15 @@ void rtm_check_presence( uint8_t *status ) uint8_t i2c_addr, i2c_interface; uint8_t dumb; - if (i2c_take_by_chipid( CHIP_ID_RTM_PCA9554, &i2c_addr, &i2c_interface, 0)) { + /* Defaults to absent - in case of I2C failure */ + *status = HOTSWAP_STATE_URTM_ABSENT; + + if (i2c_take_by_chipid( CHIP_ID_RTM_PCA9554, &i2c_addr, &i2c_interface, 100)) { if (xI2CMasterRead( i2c_interface, i2c_addr, &dumb, 1)) { *status = HOTSWAP_STATE_URTM_PRSENT; - } else { - *status = HOTSWAP_STATE_URTM_ABSENT; } i2c_give(i2c_interface); } - - //return gpio_read_pin( GPIO_RTM_PS_PORT, GPIO_RTM_PS_PIN ); } void rtm_hardware_init( void ) From 98ee8dfc31a1b0ceba8ecbecd60cb6e0b33fca6d Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:42:43 -0300 Subject: [PATCH 03/16] [modules/fru.c] Include a name tag on FRU prints to identify the module It helps in debug to know which FRU is being manipulated by the task. --- modules/fru.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/fru.c b/modules/fru.c index 2a1cc93e4..2c32c67ae 100644 --- a/modules/fru.c +++ b/modules/fru.c @@ -94,11 +94,11 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) fru[id].cfg.read_f( fru[id].cfg.eeprom_id, 0x00, &common_header[0], 8, 0 ); } - printf("[FRU] Asserting FRU information integrity\n"); + printf("[FRU][%s] Asserting FRU information integrity\n", id == FRU_AMC ? "AMC" : "RTM"); total_len += 8; if ( !((calculate_chksum( &common_header[0], 8 ) == 0) && common_header[0] == 1) ) { /* Wrong checksum */ - printf("[FRU] Error in COMMON HEADER checksum\n"); + printf("[FRU][%s] Error in COMMON HEADER checksum\n", id == FRU_AMC ? "AMC" : "RTM"); return 0; } @@ -108,7 +108,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) multirec_off = 8*common_header[5]; if (chassis_off > 0) { - printf("[FRU] Checking CHASSIS AREA record..."); + printf("[FRU][%s] Checking CHASSIS AREA record...", id == FRU_AMC ? "AMC" : "RTM"); if (fru[id].runtime) { rec_len = fru[id].buffer[chassis_off+1]; } else { @@ -133,7 +133,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) } if (board_off > 0) { - printf("[FRU] Checking BOARD AREA record..."); + printf("[FRU][%s] Checking BOARD AREA record...", id == FRU_AMC ? "AMC" : "RTM"); if (fru[id].runtime) { rec_len = fru[id].buffer[board_off+1]; } else { @@ -159,7 +159,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) } if (product_off > 0) { - printf("[FRU] Checking PRODUCT AREA record..."); + printf("[FRU][%s] Checking PRODUCT AREA record...", id == FRU_AMC ? "AMC" : "RTM"); if (fru[id].runtime) { rec_len = fru[id].buffer[product_off+1]; } else { @@ -188,7 +188,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) uint8_t eol = 0; uint8_t rec_chksum; rec_len = 0; - printf("[FRU] Checking MULTIRECORD AREA records...\n"); + printf("[FRU][%s] Checking MULTIRECORD AREA records...\n", id == FRU_AMC ? "AMC" : "RTM"); do { if (fru[id].runtime) { memcpy( &rec_buff[0], &fru[id].buffer[multirec_off], 5); @@ -198,7 +198,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) /* Calculate Multirecord header checksum */ if ( !(calculate_chksum( &rec_buff[0], 5 ) == 0) ) { /* Wrong checksum */ - printf("[FRU] Error in MULTIRECORD AREA HEADER integrity check!\n"); + printf("[FRU][%s] Error in MULTIRECORD AREA HEADER integrity check!\n", id == FRU_AMC ? "AMC" : "RTM"); return 0; } multirec_off += 5; @@ -215,7 +215,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) } if ( !((calculate_chksum( &rec_buff[0], rec_len ) == rec_chksum)) ) { /* Wrong checksum */ - printf("[FRU] Error in MULTIRECORD AREA integrity check!\n"); + printf("[FRU][%s] Error in MULTIRECORD AREA integrity check!\n", id == FRU_AMC ? "AMC" : "RTM"); return 0; } else { total_len += rec_len; @@ -229,7 +229,7 @@ uint8_t fru_check_integrity( uint8_t id, size_t *fru_size ) *fru_size = total_len; } - printf("[FRU] FRU info is healthy!\n"); + printf("[FRU][%s] FRU info is healthy!\n", id == FRU_AMC ? "AMC" : "RTM"); vPortFree(rec_buff); return 1; From 8a988a775fa5d0af20e14c7830be4ef1f6e3a704 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:44:44 -0300 Subject: [PATCH 04/16] [module/rtm.c] Increase RTM_Manage task sleep delay This function doesn't need to run at 10Hz. It only checks the RTM board presence/abscence and manage payload power, 2Hz is more than enough. --- modules/rtm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rtm.c b/modules/rtm.c index 0b8fa554e..95e7c67d5 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -61,7 +61,7 @@ void RTM_Manage( void * Parameters ) #endif for ( ;; ) { - vTaskDelay(100); + vTaskDelay(500); rtm_check_presence( &ps_new_state ); From b19911656fd490c116cd32c076f54cab4aadc944 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:47:06 -0300 Subject: [PATCH 05/16] [module/rtm.c] Configure RTM I2C lines before reading FRU The RTM EEPROM is located behind an I/O Expander and in order to retrieve the FRU information, a prior configuration on the line is needed. --- modules/rtm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/rtm.c b/modules/rtm.c index 95e7c67d5..54285cc45 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -72,6 +72,8 @@ void RTM_Manage( void * Parameters ) rtm_present = true; + /* Initialize basic hardware to enable communication */ + rtm_hardware_init(); /* Create/Read the RTM FRU info before sending the hotswap event */ fru_init(FRU_RTM); @@ -88,7 +90,6 @@ void RTM_Manage( void * Parameters ) hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_URTM_COMPATIBLE ); hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_URTM_COMPATIBLE_MASK ); - rtm_hardware_init(); } else { printf("RTM Board is not compatible.\n"); /* Send RTM Incompatible message */ From 1802756b4ccf43d850f8c736d26aa66af709e8ec Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:49:39 -0300 Subject: [PATCH 06/16] [module/rtm.c] Perform the first hotswap reading right after detecting the board This is needed only to maintain the LED configuration integrity in case the MMC reboots after the MCH configured all the LEDs. On the AMC LEDs, this is done by the hotswap task upon firmware initialization, but since we can't configure the RTM LEDs before detecting and initializing its hardware, we must do it here. --- modules/rtm.c | 11 +++++++++++ modules/sensors/hotswap.c | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/rtm.c b/modules/rtm.c index 54285cc45..d66281928 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -35,6 +35,7 @@ #include "hotswap.h" #include "payload.h" #include "uart_debug.h" +#include "led.h" volatile bool rtm_present = false; volatile uint8_t rtm_power_level = 0; @@ -48,6 +49,7 @@ void RTM_Manage( void * Parameters ) extern sensor_t * hotswap_rtm_sensor; EventBits_t current_evt; + uint8_t rtm_hs_state; /* A local copy of rtm_power_level to check if it's changed status */ uint8_t rtm_pwr_lvl_change = rtm_power_level; @@ -90,6 +92,15 @@ void RTM_Manage( void * Parameters ) hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_URTM_COMPATIBLE ); hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_URTM_COMPATIBLE_MASK ); + /* Perform hotswap first read */ + while (!rtm_get_hotswap_handle_status( &rtm_hs_state )); + + /* Override RTM Blue LED state so that if the handle is closed when the MMC is starting, the LED remains in the correct state */ + if ( rtm_hs_state == 0 ) { + LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_OFF, 0, 0 ); + } else { + LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_ON, 0, 0 ); + } } else { printf("RTM Board is not compatible.\n"); /* Send RTM Incompatible message */ diff --git a/modules/sensors/hotswap.c b/modules/sensors/hotswap.c index b45a52c76..0aa82c50d 100644 --- a/modules/sensors/hotswap.c +++ b/modules/sensors/hotswap.c @@ -122,17 +122,6 @@ void vTaskHotSwap( void *Parameters ) LEDUpdate( FRU_AMC, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_ON, 0, 0 ); } -#ifdef MODULE_RTM - /* Perform hotswap first read */ - while (!rtm_get_hotswap_handle_status( &new_state_rtm )); - - /* Override RTM Blue LED state so that if the handle is closed when the MMC is starting, the LED remains in the correct state */ - if ( new_state_rtm == 0 ) { - LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_OFF, 0, 0 ); - } else { - LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_ON, 0, 0 ); - } -#endif /* Initialise the xLastWakeTime variable with the current time. */ xLastWakeTime = xTaskGetTickCount(); From 8e6e17591f720575fd5886a3dc27a703140fc3ad Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:51:48 -0300 Subject: [PATCH 07/16] [modules/rtm.c] Move "rtm_present" variable to header This variable is used in external modules, so it should be defined on its header for clarity --- modules/rtm.c | 4 +++- modules/rtm.h | 2 ++ modules/sensors/hotswap.c | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/rtm.c b/modules/rtm.c index d66281928..5c545ce01 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -37,7 +37,6 @@ #include "uart_debug.h" #include "led.h" -volatile bool rtm_present = false; volatile uint8_t rtm_power_level = 0; extern EventGroupHandle_t rtm_payload_evt; @@ -51,6 +50,9 @@ void RTM_Manage( void * Parameters ) EventBits_t current_evt; uint8_t rtm_hs_state; + /* Defaults to not present */ + rtm_present = false; + /* A local copy of rtm_power_level to check if it's changed status */ uint8_t rtm_pwr_lvl_change = rtm_power_level; diff --git a/modules/rtm.h b/modules/rtm.h index 80ea7bb17..e0608392a 100644 --- a/modules/rtm.h +++ b/modules/rtm.h @@ -33,6 +33,8 @@ #include "rtm_user.h" +volatile bool rtm_present; + /** * @brief Initialize RTM Manage task * diff --git a/modules/sensors/hotswap.c b/modules/sensors/hotswap.c index 0aa82c50d..8464a4b8f 100644 --- a/modules/sensors/hotswap.c +++ b/modules/sensors/hotswap.c @@ -40,7 +40,9 @@ #include "fru.h" #include "utils.h" #include "uart_debug.h" - +#ifdef MODULE_RTM +#include "rtm.h" +#endif TaskHandle_t vTaskHotSwap_Handle; static bool hotswap_get_handle_status( uint8_t *state ) @@ -106,7 +108,6 @@ void vTaskHotSwap( void *Parameters ) static uint8_t new_state_amc = 0x01, old_state_amc = 0xFF; #ifdef MODULE_RTM static uint8_t new_state_rtm = 0x01, old_state_rtm = 0xFF; - extern bool rtm_present; #endif TickType_t xLastWakeTime; From a4f3bedcfe8c4845f2f3d98d83b4cdf0bbbf11e1 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:52:16 -0300 Subject: [PATCH 08/16] [modules/rtm.c] Increase RTM_Manage task stack size --- modules/rtm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rtm.c b/modules/rtm.c index 5c545ce01..fd2f11f10 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -159,7 +159,7 @@ void rtm_manage_init( void ) { rtm_power_level = 0; - xTaskCreate( RTM_Manage, "RTM Manage", 100, (void *) NULL, tskRTM_MANAGE_PRIORITY, (TaskHandle_t *) NULL ); + xTaskCreate( RTM_Manage, "RTM Manage", 150, (void *) NULL, tskRTM_MANAGE_PRIORITY, (TaskHandle_t *) NULL ); } /* Set Power Level Request handler */ From c0b20d9a152c6609ee563436e9e014677b0da0de Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:53:00 -0300 Subject: [PATCH 09/16] [modules/rtm.c] Include [RTM] tags on prints --- modules/rtm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/rtm.c b/modules/rtm.c index fd2f11f10..314f189b4 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -72,12 +72,13 @@ void RTM_Manage( void * Parameters ) if ( ps_new_state ^ ps_old_state ) { if ( ps_new_state == HOTSWAP_STATE_URTM_PRSENT ) { - printf("RTM Board detected!\n"); + printf("[RTM] Rear Board detected!\n"); rtm_present = true; /* Initialize basic hardware to enable communication */ rtm_hardware_init(); + /* Create/Read the RTM FRU info before sending the hotswap event */ fru_init(FRU_RTM); @@ -89,7 +90,7 @@ void RTM_Manage( void * Parameters ) /* Check the Zone3 compatibility records */ rtm_compatible = rtm_compatibility_check(); if ( rtm_compatible ) { - printf("RTM Board is compatible! Initializing...\n"); + printf("[RTM] Rear Board is compatible! Initializing...\n"); /* Send RTM Compatible message */ hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_URTM_COMPATIBLE ); hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_URTM_COMPATIBLE_MASK ); @@ -104,7 +105,7 @@ void RTM_Manage( void * Parameters ) LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_ON, 0, 0 ); } } else { - printf("RTM Board is not compatible.\n"); + printf("[RTM] Rear Board is not compatible.\n"); /* Send RTM Incompatible message */ hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_URTM_INCOMPATIBLE ); hotswap_clear_mask_bit( HOTSWAP_RTM, HOTSWAP_URTM_COMPATIBLE_MASK ); @@ -116,7 +117,7 @@ void RTM_Manage( void * Parameters ) } else if ( ps_new_state == HOTSWAP_STATE_URTM_ABSENT ) { //sdr_disable_sensors(); /* Not implemented yet */ - printf("RTM Board disconnected!\n"); + printf("[RTM] Rear Board disconnected!\n"); rtm_present = false; @@ -133,10 +134,10 @@ void RTM_Manage( void * Parameters ) if ( rtm_power_level == 0x01 ) { hotswap_clear_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); - printf("Enabling RTM Payload power...\n"); + printf("[RTM] Enabling RTM Payload power...\n"); rtm_enable_payload_power(); } else { - printf("Disabling RTM Payload power...\n"); + printf("[RTM] Disabling RTM Payload power...\n"); rtm_disable_payload_power(); } } @@ -146,7 +147,7 @@ void RTM_Manage( void * Parameters ) if ( current_evt & PAYLOAD_MESSAGE_QUIESCED ) { if ( rtm_quiesce() ) { /* Quiesced event */ - printf("RTM Quiesced successfuly!\n"); + printf("[RTM] Quiesced RTM successfuly!\n"); hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_QUIESCED ); xEventGroupClearBits( rtm_payload_evt, PAYLOAD_MESSAGE_QUIESCED ); From 2ba2387d54f56bf23edb11d76ec870d24adbbc16 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:53:45 -0300 Subject: [PATCH 10/16] [modules/rtm.c] Only enable RTM payload power for compatible boards --- modules/rtm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/rtm.c b/modules/rtm.c index 314f189b4..5111c5ef7 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -44,9 +44,8 @@ void RTM_Manage( void * Parameters ) { uint8_t ps_old_state = 0xFF; uint8_t ps_new_state; - bool rtm_compatible; + bool rtm_compatible = false; extern sensor_t * hotswap_rtm_sensor; - EventBits_t current_evt; uint8_t rtm_hs_state; @@ -131,7 +130,7 @@ void RTM_Manage( void * Parameters ) if ( rtm_pwr_lvl_change ^ rtm_power_level ) { rtm_pwr_lvl_change = rtm_power_level; - if ( rtm_power_level == 0x01 ) { + if ( rtm_power_level == 0x01 && rtm_compatible ) { hotswap_clear_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); printf("[RTM] Enabling RTM Payload power...\n"); From 999c96834b047e0c3331abf5681d6a39c5d79f06 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Tue, 26 Feb 2019 14:54:57 -0300 Subject: [PATCH 11/16] [modules/sensors/hotswap.c] Control RTM payload power by handle on BENCH_TEST mode This should ease the development proccess and debugging --- modules/sensors/hotswap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/sensors/hotswap.c b/modules/sensors/hotswap.c index 8464a4b8f..89a7aa946 100644 --- a/modules/sensors/hotswap.c +++ b/modules/sensors/hotswap.c @@ -108,6 +108,9 @@ void vTaskHotSwap( void *Parameters ) static uint8_t new_state_amc = 0x01, old_state_amc = 0xFF; #ifdef MODULE_RTM static uint8_t new_state_rtm = 0x01, old_state_rtm = 0xFF; +#ifdef BENCH_TEST + extern volatile uint8_t rtm_power_level; +#endif #endif TickType_t xLastWakeTime; @@ -163,8 +166,14 @@ void vTaskHotSwap( void *Parameters ) if ( new_state_rtm ^ old_state_rtm ) { if ( new_state_rtm == 0 ) { printf("RTM Hotswap handle pressed!\n"); +#ifdef BENCH_TEST + rtm_power_level = 1; +#endif } else { - printf("RTM Hotswap handle released!\n"); + printf("RTM Hotswap handle released!\n"); +#ifdef BENCH_TEST + rtm_power_level = 0; +#endif } if ( hotswap_send_event( hotswap_rtm_sensor, new_state_rtm ) == ipmb_error_success ) { hotswap_set_mask_bit( HOTSWAP_RTM, 1 << new_state_rtm ); From 9c5a18fa57769ed5a95a5ae72e64fbcb1204cefd Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Wed, 20 Mar 2019 10:12:15 -0300 Subject: [PATCH 12/16] [port/board/*/payload.h] Change event name to PAYLOAD_MESSAGE_QUIESCE --- modules/ipmi.c | 8 ++++---- modules/rtm.c | 2 +- port/board/afc-bpm/v3_0/payload.c | 4 ++-- port/board/afc-bpm/v3_0/payload.h | 2 +- port/board/afc-bpm/v3_1/payload.c | 4 ++-- port/board/afc-bpm/v3_1/payload.h | 2 +- port/board/afc-timing/payload.c | 4 ++-- port/board/afc-timing/payload.h | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/ipmi.c b/modules/ipmi.c index 63920f4e1..73535cd57 100644 --- a/modules/ipmi.c +++ b/modules/ipmi.c @@ -289,16 +289,16 @@ IPMI_HANDLER(ipmi_picmg_cmd_fru_control, NETFN_GRPEXT, IPMI_PICMG_CMD_FRU_CONTRO switch (fru_ctl) { case FRU_CTLCODE_COLD_RST: - payload_send_message( fru_id, PAYLOAD_MESSAGE_COLD_RST); + payload_send_message(fru_id, PAYLOAD_MESSAGE_COLD_RST); break; case FRU_CTLCODE_WARM_RST: - payload_send_message( fru_id, PAYLOAD_MESSAGE_WARM_RST); + payload_send_message(fru_id, PAYLOAD_MESSAGE_WARM_RST); break; case FRU_CTLCODE_REBOOT: - payload_send_message( fru_id, PAYLOAD_MESSAGE_REBOOT); + payload_send_message(fru_id, PAYLOAD_MESSAGE_REBOOT); break; case FRU_CTLCODE_QUIESCE: - payload_send_message( fru_id, PAYLOAD_MESSAGE_QUIESCED); + payload_send_message(fru_id, PAYLOAD_MESSAGE_QUIESCE); break; default: rsp->completion_code = IPMI_CC_INV_DATA_FIELD_IN_REQ; diff --git a/modules/rtm.c b/modules/rtm.c index 5111c5ef7..4318e4a0a 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -143,7 +143,7 @@ void RTM_Manage( void * Parameters ) current_evt = xEventGroupGetBits( rtm_payload_evt ); - if ( current_evt & PAYLOAD_MESSAGE_QUIESCED ) { + if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) { if ( rtm_quiesce() ) { /* Quiesced event */ printf("[RTM] Quiesced RTM successfuly!\n"); diff --git a/port/board/afc-bpm/v3_0/payload.c b/port/board/afc-bpm/v3_0/payload.c index d31a64d33..9da4381c6 100644 --- a/port/board/afc-bpm/v3_0/payload.c +++ b/port/board/afc-bpm/v3_0/payload.c @@ -224,9 +224,9 @@ void vTaskPayload( void *pvParameters ) DCDC_good = 0; xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_DCDC_PGOODn ); } - if ( current_evt & PAYLOAD_MESSAGE_QUIESCED ) { + if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) { QUIESCED_req = 1; - xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCED ); + xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCE ); } if ( current_evt & PAYLOAD_MESSAGE_COLD_RST ) { state = PAYLOAD_SWITCHING_OFF; diff --git a/port/board/afc-bpm/v3_0/payload.h b/port/board/afc-bpm/v3_0/payload.h index 98974a41a..06f921d40 100644 --- a/port/board/afc-bpm/v3_0/payload.h +++ b/port/board/afc-bpm/v3_0/payload.h @@ -68,7 +68,7 @@ enum { #define PAYLOAD_MESSAGE_COLD_RST (1 << 4) #define PAYLOAD_MESSAGE_WARM_RST (1 << 5) #define PAYLOAD_MESSAGE_REBOOT (1 << 6) -#define PAYLOAD_MESSAGE_QUIESCED (1 << 7) +#define PAYLOAD_MESSAGE_QUIESCE (1 << 7) /** * @} */ diff --git a/port/board/afc-bpm/v3_1/payload.c b/port/board/afc-bpm/v3_1/payload.c index b76437c15..bcb1ded5c 100644 --- a/port/board/afc-bpm/v3_1/payload.c +++ b/port/board/afc-bpm/v3_1/payload.c @@ -232,9 +232,9 @@ void vTaskPayload( void *pvParameters ) current_evt = xEventGroupGetBits( amc_payload_evt ); - if ( current_evt & PAYLOAD_MESSAGE_QUIESCED ) { + if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) { QUIESCED_req = 1; - xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCED ); + xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCE ); } if ( current_evt & PAYLOAD_MESSAGE_COLD_RST ) { diff --git a/port/board/afc-bpm/v3_1/payload.h b/port/board/afc-bpm/v3_1/payload.h index 90bed30b6..d2ee2117c 100644 --- a/port/board/afc-bpm/v3_1/payload.h +++ b/port/board/afc-bpm/v3_1/payload.h @@ -59,7 +59,7 @@ enum { #define PAYLOAD_MESSAGE_COLD_RST (1 << 0) #define PAYLOAD_MESSAGE_WARM_RST (1 << 1) #define PAYLOAD_MESSAGE_REBOOT (1 << 2) -#define PAYLOAD_MESSAGE_QUIESCED (1 << 3) +#define PAYLOAD_MESSAGE_QUIESCE (1 << 3) /** * @} */ diff --git a/port/board/afc-timing/payload.c b/port/board/afc-timing/payload.c index 7bd4762a6..bd0dab0c7 100644 --- a/port/board/afc-timing/payload.c +++ b/port/board/afc-timing/payload.c @@ -232,9 +232,9 @@ void vTaskPayload( void *pvParameters ) current_evt = xEventGroupGetBits( amc_payload_evt ); - if ( current_evt & PAYLOAD_MESSAGE_QUIESCED ) { + if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) { QUIESCED_req = 1; - xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCED ); + xEventGroupClearBits( amc_payload_evt, PAYLOAD_MESSAGE_QUIESCE ); } if ( current_evt & PAYLOAD_MESSAGE_COLD_RST ) { diff --git a/port/board/afc-timing/payload.h b/port/board/afc-timing/payload.h index 90bed30b6..d2ee2117c 100644 --- a/port/board/afc-timing/payload.h +++ b/port/board/afc-timing/payload.h @@ -59,7 +59,7 @@ enum { #define PAYLOAD_MESSAGE_COLD_RST (1 << 0) #define PAYLOAD_MESSAGE_WARM_RST (1 << 1) #define PAYLOAD_MESSAGE_REBOOT (1 << 2) -#define PAYLOAD_MESSAGE_QUIESCED (1 << 3) +#define PAYLOAD_MESSAGE_QUIESCE (1 << 3) /** * @} */ From 0dca28db75c684c733f17a0e1f1ce72c7baa875b Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Wed, 20 Mar 2019 10:12:54 -0300 Subject: [PATCH 13/16] [port/board/afc-timing/payload.h] Include RTM Enable payload message --- port/board/afc-timing/payload.h | 1 + 1 file changed, 1 insertion(+) diff --git a/port/board/afc-timing/payload.h b/port/board/afc-timing/payload.h index d2ee2117c..4dbfa146a 100644 --- a/port/board/afc-timing/payload.h +++ b/port/board/afc-timing/payload.h @@ -60,6 +60,7 @@ enum { #define PAYLOAD_MESSAGE_WARM_RST (1 << 1) #define PAYLOAD_MESSAGE_REBOOT (1 << 2) #define PAYLOAD_MESSAGE_QUIESCE (1 << 3) +#define PAYLOAD_MESSAGE_RTM_ENABLE (1 << 4) /** * @} */ From 9dbd4360e0bf104729159af559ff248f0d919c50 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Wed, 20 Mar 2019 10:13:43 -0300 Subject: [PATCH 14/16] [modules/rtm.c] Treat RTM power level changes as events --- modules/rtm.c | 57 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/modules/rtm.c b/modules/rtm.c index 4318e4a0a..ea51cf7f8 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -37,7 +37,6 @@ #include "uart_debug.h" #include "led.h" -volatile uint8_t rtm_power_level = 0; extern EventGroupHandle_t rtm_payload_evt; void RTM_Manage( void * Parameters ) @@ -52,17 +51,9 @@ void RTM_Manage( void * Parameters ) /* Defaults to not present */ rtm_present = false; - /* A local copy of rtm_power_level to check if it's changed status */ - uint8_t rtm_pwr_lvl_change = rtm_power_level; - /* Start with RTM payload disabled */ rtm_disable_payload_power(); -#ifdef BENCH_TEST - rtm_power_level = 0x01; - rtm_pwr_lvl_change = 0x00; -#endif - for ( ;; ) { vTaskDelay(500); @@ -127,20 +118,7 @@ void RTM_Manage( void * Parameters ) ps_old_state = ps_new_state; } - if ( rtm_pwr_lvl_change ^ rtm_power_level ) { - rtm_pwr_lvl_change = rtm_power_level; - - if ( rtm_power_level == 0x01 && rtm_compatible ) { - hotswap_clear_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); - - printf("[RTM] Enabling RTM Payload power...\n"); - rtm_enable_payload_power(); - } else { - printf("[RTM] Disabling RTM Payload power...\n"); - rtm_disable_payload_power(); - } - } - + /* Check enable/disable events */ current_evt = xEventGroupGetBits( rtm_payload_evt ); if ( current_evt & PAYLOAD_MESSAGE_QUIESCE ) { @@ -149,16 +127,26 @@ void RTM_Manage( void * Parameters ) printf("[RTM] Quiesced RTM successfuly!\n"); hotswap_set_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); hotswap_send_event( hotswap_rtm_sensor, HOTSWAP_STATE_QUIESCED ); - xEventGroupClearBits( rtm_payload_evt, PAYLOAD_MESSAGE_QUIESCED ); + } else { + printf("[RTM] RTM failed to quiesce!\n"); + } + xEventGroupClearBits( rtm_payload_evt, PAYLOAD_MESSAGE_QUIESCE ); + + } else if ( current_evt & PAYLOAD_MESSAGE_RTM_ENABLE ) { + if (rtm_compatible) { + hotswap_clear_mask_bit( HOTSWAP_RTM, HOTSWAP_QUIESCED_MASK ); + printf("[RTM] Enabling RTM Payload power...\n"); + rtm_enable_payload_power(); + } else { + printf("[RTM] Impossible to enable payload power to an incompatible RTM board!\n"); } + xEventGroupClearBits( rtm_payload_evt, PAYLOAD_MESSAGE_RTM_ENABLE ); } } } void rtm_manage_init( void ) { - rtm_power_level = 0; - xTaskCreate( RTM_Manage, "RTM Manage", 150, (void *) NULL, tskRTM_MANAGE_PRIORITY, (TaskHandle_t *) NULL ); } @@ -168,9 +156,20 @@ IPMI_HANDLER(ipmi_picmg_set_power_level, NETFN_GRPEXT, IPMI_PICMG_CMD_SET_POWER_ { int len = rsp->data_len = 0; uint8_t fru_id = req->data[1]; - - if ( fru_id == FRU_RTM ) { - rtm_power_level = req->data[2]; + uint8_t power_level = req->data[2]; + + /* + * Power Level: + * 00h = Power off + * 01h - 14h = Select power level, if available + * 0xFF = Do not change power level + */ + if ( fru_id == FRU_RTM && power_level != 0xFF ) { + if (power_level == 0x00) { + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_QUIESCE); + } else { + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_RTM_ENABLE); + } } rsp->completion_code = IPMI_CC_OK; From 76fac6b450b2e5fa44b27f924df6b8c813880af0 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Wed, 20 Mar 2019 10:14:21 -0300 Subject: [PATCH 15/16] [modules/rtm.c] Override RTM power at startup Restore board state previous to a possible MMC reboot --- modules/rtm.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/rtm.c b/modules/rtm.c index ea51cf7f8..ec9f0acdc 100644 --- a/modules/rtm.c +++ b/modules/rtm.c @@ -88,11 +88,14 @@ void RTM_Manage( void * Parameters ) /* Perform hotswap first read */ while (!rtm_get_hotswap_handle_status( &rtm_hs_state )); - /* Override RTM Blue LED state so that if the handle is closed when the MMC is starting, the LED remains in the correct state */ + /* Override RTM state so that if the handle is closed when the MMC is starting, + * the LED and payload power remains in the correct state */ if ( rtm_hs_state == 0 ) { LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_OFF, 0, 0 ); + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_RTM_ENABLE); } else { LEDUpdate( FRU_RTM, LED_BLUE, LEDMODE_OVERRIDE, LEDINIT_ON, 0, 0 ); + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_QUIESCE); } } else { printf("[RTM] Rear Board is not compatible.\n"); From 69dbf1974e9d901c0641a958b5ce6434e43e1d51 Mon Sep 17 00:00:00 2001 From: Henrique Silva Date: Wed, 20 Mar 2019 10:20:58 -0300 Subject: [PATCH 16/16] [modules/sensors/hotswap.c] Use payload messages to control RTM board --- modules/sensors/hotswap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/sensors/hotswap.c b/modules/sensors/hotswap.c index 89a7aa946..8b587c2c3 100644 --- a/modules/sensors/hotswap.c +++ b/modules/sensors/hotswap.c @@ -40,9 +40,11 @@ #include "fru.h" #include "utils.h" #include "uart_debug.h" + #ifdef MODULE_RTM #include "rtm.h" #endif + TaskHandle_t vTaskHotSwap_Handle; static bool hotswap_get_handle_status( uint8_t *state ) @@ -108,9 +110,6 @@ void vTaskHotSwap( void *Parameters ) static uint8_t new_state_amc = 0x01, old_state_amc = 0xFF; #ifdef MODULE_RTM static uint8_t new_state_rtm = 0x01, old_state_rtm = 0xFF; -#ifdef BENCH_TEST - extern volatile uint8_t rtm_power_level; -#endif #endif TickType_t xLastWakeTime; @@ -167,12 +166,12 @@ void vTaskHotSwap( void *Parameters ) if ( new_state_rtm == 0 ) { printf("RTM Hotswap handle pressed!\n"); #ifdef BENCH_TEST - rtm_power_level = 1; + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_RTM_ENABLE); #endif } else { printf("RTM Hotswap handle released!\n"); #ifdef BENCH_TEST - rtm_power_level = 0; + payload_send_message(FRU_RTM, PAYLOAD_MESSAGE_QUIESCE); #endif } if ( hotswap_send_event( hotswap_rtm_sensor, new_state_rtm ) == ipmb_error_success ) {