int pal_get_server_power(uint8_t slot_id, uint8_t *status) { int ret; bic_gpio_t gpio; ret = bic_get_gpio(slot_id, &gpio); if (ret) { return ret; } if (gpio.pwrgood_cpu) { *status = SERVER_POWER_ON; } else { *status = SERVER_POWER_OFF; } return 0; }
// Tests for reading GPIO values and configuration static void util_get_gpio(uint8_t slot_id) { int ret; bic_gpio_t gpio = {0}; ret = bic_get_gpio(slot_id, &gpio); if (ret) { printf("util_get_gpio: bic_get_gpio returns %d\n", ret); return; } bic_gpio_u *t = (bic_gpio_u*) &gpio; // Print response printf("PWRGOOD_CPU: %d\n", t->bits.pwrgood_cpu); printf("PWRGOOD_PCH_PWROK: %d\n", t->bits.pwrgd_pch_pwrok); printf("PVDDR_VRHOT_N: %d\n", t->bits.pvddr_vrhot_n); printf("PVCCIN_VRHOT_N: %d\n", t->bits.pvccin_vrhot_n); printf("FM_FAST_PROCHOT_N: %d\n", t->bits.fm_fast_prochot_n); printf("PCHHOT_CPU_N: %d\n", t->bits.pchhot_cpu_n); printf("FM_CPLD_CPU_DIMM_EVENT_C0_N: %d\n", t->bits.fm_cpld_cpu_dimm_event_c0_n); printf("FM_CPLD_BDXDE_THERMTRIP_N: %d\n", t->bits.fm_cpld_bdxde_thermtrip_n); printf("THERMTRIP_PCH_N: %d\n", t->bits.thermtrip_pch_n); printf("FM_CPLD_FIVR_FAULT: %d\n", t->bits.fm_cpld_fivr_fault); printf("FM_BDXDE_CATERR_LVT3_N: %d\n", t->bits.fm_bdxde_caterr_lvt3_n); printf("FM_BDXDE_ERR_LVT3_N: %d\n", t->bits.fm_bdxde_err_lvt3_n); printf("SLP_S4_N: %d\n", t->bits.slp_s4_n); printf("FM_NMI_EVENT_BMC_N: %d\n", t->bits.fm_nmi_event_bmc_n); printf("FM_SMI_BMC_N: %d\n", t->bits.fm_smi_bmc_n); printf("RST_PLTRST_BMC_N: %d\n", t->bits.rst_pltrst_bmc_n); printf("FP_RST_BTN_BUF_N: %d\n", t->bits.fp_rst_btn_buf_n); printf("BMC_RST_BTN_OUT_N: %d\n", t->bits.bmc_rst_btn_out_n); printf("FM_BDE_POST_CMPLT_N: %d\n", t->bits.fm_bde_post_cmplt_n); printf("FM_BDXDE_SLP3_N: %d\n", t->bits.fm_bdxde_slp3_n); printf("FM_PWR_LED_N: %d\n", t->bits.fm_pwr_led_n); printf("PWRGD_PVCCIN: %d\n", t->bits.pwrgd_pvccin); printf("SVR_ID: %d\n", t->bits.svr_id); printf("BMC_READY_N: %d\n", t->bits.bmc_ready_n); printf("BMC_COM_SW_N: %d\n", t->bits.bmc_com_sw_n); printf("rsvd: %d\n", t->bits.rsvd); }
/* Monitor the gpio pins */ static int gpio_monitor_poll(uint8_t fru_flag) { int i, ret; uint8_t fru; uint32_t revised_pins, n_pin_val, o_pin_val[MAX_NUM_SLOTS + 1] = {0}; gpio_pin_t *gpios; char pwr_state[MAX_VALUE_LEN]; uint32_t status; bic_gpio_t gpio = {0}; /* Check for initial Asserts */ for (fru = 1; fru <= MAX_NUM_SLOTS; fru++) { if (GETBIT(fru_flag, fru) == 0) continue; ret = bic_get_gpio(fru, &gpio); if (ret) { #ifdef DEBUG syslog(LOG_WARNING, "gpio_monitor_poll: bic_get_gpio failed for " " fru %u", fru); #endif continue; } gpios = get_struct_gpio_pin(fru); if (gpios == NULL) { syslog(LOG_WARNING, "gpio_monitor_poll: get_struct_gpio_pin failed for" " fru %u", fru); continue; } memcpy(&status, (uint8_t *) &gpio, sizeof(status)); o_pin_val[fru] = 0; for (i = 0; i < MAX_GPIO_PINS; i++) { if (gpios[i].flag == 0) continue; gpios[i].status = GETBIT(status, i); if (gpios[i].status) o_pin_val[fru] = SETBIT(o_pin_val[fru], i); if (gpios[i].status == gpios[i].ass_val) { syslog(LOG_CRIT, "ASSERT: fru: %u, num: %d, gpio pin: %-20s", fru, i, gpios[i].name); } } } /* Keep monitoring each fru's gpio pins every 4 * GPIOD_READ_DELAY seconds */ while(1) { for (fru = 1; fru <= MAX_NUM_SLOTS; fru++) { if (!(GETBIT(fru_flag, fru))) { usleep(DELAY_GPIOD_READ); continue; } gpios = get_struct_gpio_pin(fru); if (gpios == NULL) { syslog(LOG_WARNING, "gpio_monitor_poll: get_struct_gpio_pin failed for" " fru %u", fru); continue; } memset(pwr_state, 0, MAX_VALUE_LEN); pal_get_last_pwr_state(fru, pwr_state); /* Get the GPIO pins */ if ((ret = bic_get_gpio(fru, (bic_gpio_t *) &n_pin_val)) < 0) { /* log the error message only when the CPU is on but not reachable. */ if (!(strcmp(pwr_state, "on"))) { #ifdef DEBUG syslog(LOG_WARNING, "gpio_monitor_poll: bic_get_gpio failed for " " fru %u", fru); #endif } continue; } if (o_pin_val[fru] == n_pin_val) { o_pin_val[fru] = n_pin_val; usleep(DELAY_GPIOD_READ); continue; } revised_pins = (n_pin_val ^ o_pin_val[fru]); for (i = 0; i < MAX_GPIO_PINS; i++) { if (GETBIT(revised_pins, i) && (gpios[i].flag == 1)) { gpios[i].status = GETBIT(n_pin_val, i); // Check if the new GPIO val is ASSERT if (gpios[i].status == gpios[i].ass_val) { /* * GPIO - PWRGOOD_CPU assert indicates that the CPU is turned off or in a bad shape. * Raise an error and change the LPS from on to off or vice versa for deassert. */ if (!(strcmp(pwr_state, "on"))) pal_set_last_pwr_state(fru, "off"); syslog(LOG_CRIT, "ASSERT: fru: %u, num: %d, gpio pin: %-20s", fru, i, gpios[i].name); } else { if (!(strcmp(pwr_state, "off"))) pal_set_last_pwr_state(fru, "on"); syslog(LOG_CRIT, "DEASSERT: fru: %u, num: %d, gpio pin: %-20s", fru, i, gpios[i].name); } } } o_pin_val[fru] = n_pin_val; usleep(DELAY_GPIOD_READ); } /* For Loop for each fru */ } /* while loop */ } /* function definition*/
/* Monitor the gpio pins */ static int gpio_monitor_poll(uint8_t fru_flag) { int i, ret; uint8_t fru; uint32_t revised_pins, n_pin_val, o_pin_val[MAX_NUM_SLOTS + 1] = {0}; gpio_pin_t *gpios; uint32_t status; bic_gpio_t gpio = {0}; /* Check for initial Asserts */ for (fru = 1; fru <= MAX_NUM_SLOTS; fru++) { if (GETBIT(fru_flag, fru) == 0) continue; ret = bic_get_gpio(fru, &gpio); if (ret) { syslog(LOG_ALERT, "populate_gpio_pins: bic_get_gpio failed for " " fru %u", fru); continue; } gpios = get_struct_gpio_pin(fru); if (gpios == NULL) { syslog(LOG_ALERT, "gpio_monitor_poll: get_struct_gpio_pin failed for" " fru %u", fru); continue; } memcpy(&status, (uint8_t *) &gpio, sizeof(status)); o_pin_val[fru] = 0; for (i = 0; i <= MAX_GPIO_PINS; i++) { if (gpios[i].flag == 0) continue; gpios[i].status = GETBIT(status, i); if (gpios[i].status) o_pin_val[fru] = SETBIT(o_pin_val[fru], i); if (gpios[i].status == gpios[i].ass_val) { syslog(LOG_CRIT, "ASSERT: fru: %u, gpio pin: %-20s, num: %d", fru, gpios[i].name, i); } } } /* Keep monitoring each fru's gpio pins every 4 * GPIOD_READ_DELAY seconds */ while(1) { for (fru = 1; fru <= MAX_NUM_SLOTS; fru++) { if (!(GETBIT(fru_flag, fru))) { sleep(GPIOD_READ_DELAY); continue; } gpios = get_struct_gpio_pin(fru); if (gpios == NULL) { syslog(LOG_ALERT, "gpio_monitor_poll: get_struct_gpio_pin failed for" " fru %u", fru); continue; } if ((ret = bic_get_gpio(fru, (bic_gpio_t *) &n_pin_val)) < 0) { syslog(LOG_ALERT, "gpio_monitor_poll: bic_get_gpio failed for " " fru %u", fru); continue; } if (o_pin_val[fru] == n_pin_val) { o_pin_val[fru] = n_pin_val; sleep(GPIOD_READ_DELAY); continue; } revised_pins = (n_pin_val ^ o_pin_val[fru]); for (i = 0; i < MAX_GPIO_PINS; i++) { if (GETBIT(revised_pins, i) & gpios[i].flag) { gpios[i].status = GETBIT(n_pin_val, i); // Check if the new GPIO val is ASSERT if (gpios[i].status == gpios[i].ass_val) { syslog(LOG_CRIT, "ASSERT: fru: %u, gpio pin: %-20s, num: %d", fru, gpios[i].name, i); } else { syslog(LOG_CRIT, "DEASSERT: fru: %u, gpio pin: %-20s, num: %d", fru, gpios[i].name, i); } } } o_pin_val[fru] = n_pin_val; sleep(GPIOD_READ_DELAY); } /* For Loop for each fru */ } /* while loop */ } /* function definition*/