Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/smartpqi/smartpqi_misc.c
/*- | /*- | ||||
* Copyright (c) 2018 Microsemi Corporation. | * Copyright 2016-2021 Microchip Technology, Inc. and/or its subsidiaries. | ||||
* All rights reserved. | |||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
Show All 12 Lines | |||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
/* $FreeBSD$ */ | /* $FreeBSD$ */ | ||||
#include "smartpqi_includes.h" | #include "smartpqi_includes.h" | ||||
/* | /* | ||||
* Populate hostwell time variables in bcd format from FreeBSD format | * Populate hostwellness time variables in bcd format from FreeBSD format | ||||
*/ | */ | ||||
void os_get_time(struct bmic_host_wellness_time *host_wellness_time) | void | ||||
os_get_time(struct bmic_host_wellness_time *host_wellness_time) | |||||
{ | { | ||||
struct timespec ts; | struct timespec ts; | ||||
struct clocktime ct; | struct clocktime ct; | ||||
getnanotime(&ts); | getnanotime(&ts); | ||||
clock_ts_to_ct(&ts, &ct); | clock_ts_to_ct(&ts, &ct); | ||||
/* Fill the time In BCD Format */ | /* Fill the time In BCD Format */ | ||||
host_wellness_time->hour= (uint8_t)bin2bcd(ct.hour); | host_wellness_time->hour= (uint8_t)bin2bcd(ct.hour); | ||||
host_wellness_time->min = (uint8_t)bin2bcd(ct.min); | host_wellness_time->min = (uint8_t)bin2bcd(ct.min); | ||||
host_wellness_time->sec= (uint8_t)bin2bcd(ct.sec); | host_wellness_time->sec= (uint8_t)bin2bcd(ct.sec); | ||||
host_wellness_time->reserved = 0; | host_wellness_time->reserved = 0; | ||||
host_wellness_time->month = (uint8_t)bin2bcd(ct.mon); | host_wellness_time->month = (uint8_t)bin2bcd(ct.mon); | ||||
host_wellness_time->day = (uint8_t)bin2bcd(ct.day); | host_wellness_time->day = (uint8_t)bin2bcd(ct.day); | ||||
host_wellness_time->century = (uint8_t)bin2bcd(ct.year / 100); | host_wellness_time->century = (uint8_t)bin2bcd(ct.year / 100); | ||||
host_wellness_time->year = (uint8_t)bin2bcd(ct.year % 100); | host_wellness_time->year = (uint8_t)bin2bcd(ct.year % 100); | ||||
} | } | ||||
/* | /* | ||||
* Update host time to f/w every 24 hours in a periodic timer. | * Update host time to f/w every 24 hours in a periodic timer. | ||||
*/ | */ | ||||
void os_wellness_periodic(void *data) | void | ||||
os_wellness_periodic(void *data) | |||||
{ | { | ||||
struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data; | struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data; | ||||
int ret = 0; | int ret = 0; | ||||
/* update time to FW */ | /* update time to FW */ | ||||
if (!pqisrc_ctrl_offline(softs)){ | if (!pqisrc_ctrl_offline(softs)){ | ||||
if( (ret = pqisrc_write_current_time_to_host_wellness(softs)) != 0 ) | if( (ret = pqisrc_write_current_time_to_host_wellness(softs)) != 0 ) | ||||
DBG_ERR("Failed to update time to FW in periodic ret = %d\n", ret); | DBG_ERR("Failed to update time to FW in periodic ret = %d\n", ret); | ||||
} | } | ||||
/* reschedule ourselves */ | /* reschedule ourselves */ | ||||
callout_schedule(&softs->os_specific.wellness_periodic, | callout_reset(&softs->os_specific.wellness_periodic, | ||||
OS_HOST_WELLNESS_TIMEOUT * hz); | PQI_HOST_WELLNESS_TIMEOUT_SEC * hz, os_wellness_periodic, softs); | ||||
} | } | ||||
/* | /* | ||||
* Routine used to stop the heart-beat timer | * Routine used to stop the heart-beat timer | ||||
*/ | */ | ||||
void os_stop_heartbeat_timer(pqisrc_softstate_t *softs) | void | ||||
os_stop_heartbeat_timer(pqisrc_softstate_t *softs) | |||||
{ | { | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
/* Kill the heart beat event */ | /* Kill the heart beat event */ | ||||
callout_stop(&softs->os_specific.heartbeat_timeout_id); | callout_stop(&softs->os_specific.heartbeat_timeout_id); | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
} | } | ||||
/* | /* | ||||
* Routine used to start the heart-beat timer | * Routine used to start the heart-beat timer | ||||
*/ | */ | ||||
void os_start_heartbeat_timer(void *data) | void | ||||
os_start_heartbeat_timer(void *data) | |||||
{ | { | ||||
struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data; | struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data; | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
pqisrc_heartbeat_timer_handler(softs); | pqisrc_heartbeat_timer_handler(softs); | ||||
if (!pqisrc_ctrl_offline(softs)) { | if (!pqisrc_ctrl_offline(softs)) { | ||||
callout_reset(&softs->os_specific.heartbeat_timeout_id, | callout_reset(&softs->os_specific.heartbeat_timeout_id, | ||||
OS_FW_HEARTBEAT_TIMER_INTERVAL * hz, | PQI_HEARTBEAT_TIMEOUT_SEC * hz, | ||||
os_start_heartbeat_timer, softs); | os_start_heartbeat_timer, softs); | ||||
} | } | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
} | } | ||||
/* | /* | ||||
* Mutex initialization function | * Mutex initialization function | ||||
*/ | */ | ||||
int os_init_spinlock(struct pqisrc_softstate *softs, struct mtx *lock, | int | ||||
os_init_spinlock(struct pqisrc_softstate *softs, struct mtx *lock, | |||||
char *lockname) | char *lockname) | ||||
{ | { | ||||
mtx_init(lock, lockname, NULL, MTX_SPIN); | mtx_init(lock, lockname, NULL, MTX_SPIN); | ||||
return 0; | return 0; | ||||
} | } | ||||
/* | /* | ||||
* Mutex uninitialization function | * Mutex uninitialization function | ||||
*/ | */ | ||||
void os_uninit_spinlock(struct mtx *lock) | void | ||||
os_uninit_spinlock(struct mtx *lock) | |||||
{ | { | ||||
mtx_destroy(lock); | mtx_destroy(lock); | ||||
return; | return; | ||||
} | } | ||||
/* | /* | ||||
* Semaphore initialization function | * Semaphore initialization function | ||||
*/ | */ | ||||
int os_create_semaphore(const char *name, int value, struct sema *sema) | int | ||||
os_create_semaphore(const char *name, int value, struct sema *sema) | |||||
{ | { | ||||
sema_init(sema, value, name); | sema_init(sema, value, name); | ||||
return PQI_STATUS_SUCCESS; | return PQI_STATUS_SUCCESS; | ||||
} | } | ||||
/* | /* | ||||
* Semaphore uninitialization function | * Semaphore uninitialization function | ||||
*/ | */ | ||||
int os_destroy_semaphore(struct sema *sema) | int | ||||
os_destroy_semaphore(struct sema *sema) | |||||
{ | { | ||||
sema_destroy(sema); | sema_destroy(sema); | ||||
return PQI_STATUS_SUCCESS; | return PQI_STATUS_SUCCESS; | ||||
} | } | ||||
/* | /* | ||||
* Semaphore grab function | * Semaphore grab function | ||||
*/ | */ | ||||
void inline os_sema_lock(struct sema *sema) | void inline | ||||
os_sema_lock(struct sema *sema) | |||||
{ | { | ||||
sema_post(sema); | sema_post(sema); | ||||
} | } | ||||
/* | /* | ||||
* Semaphore release function | * Semaphore release function | ||||
*/ | */ | ||||
void inline os_sema_unlock(struct sema *sema) | void inline | ||||
os_sema_unlock(struct sema *sema) | |||||
{ | { | ||||
sema_wait(sema); | sema_wait(sema); | ||||
} | } | ||||
/* | /* | ||||
* string copy wrapper function | * string copy wrapper function | ||||
*/ | */ | ||||
int os_strlcpy(char *dst, char *src, int size) | int | ||||
os_strlcpy(char *dst, char *src, int size) | |||||
{ | { | ||||
return strlcpy(dst, src, size); | return strlcpy(dst, src, size); | ||||
} | |||||
int | |||||
bsd_status_to_pqi_status(int bsd_status) | |||||
{ | |||||
if (bsd_status == BSD_SUCCESS) | |||||
return PQI_STATUS_SUCCESS; | |||||
else | |||||
return PQI_STATUS_FAILURE; | |||||
} | } |