2 * Copyright (c) 2018 Microsemi Corporation.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include "smartpqi_includes.h"
32 * Populate hostwell time variables in bcd format from FreeBSD format
34 void os_get_time(struct bmic_host_wellness_time *host_wellness_time)
40 clock_ts_to_ct(&ts, &ct);
43 /* Fill the time In BCD Format */
44 host_wellness_time->hour= (uint8_t)bin2bcd(ct.hour);
45 host_wellness_time->min = (uint8_t)bin2bcd(ct.min);
46 host_wellness_time->sec= (uint8_t)bin2bcd(ct.sec);
47 host_wellness_time->reserved = 0;
48 host_wellness_time->month = (uint8_t)bin2bcd(ct.mon);
49 host_wellness_time->day = (uint8_t)bin2bcd(ct.day);
50 host_wellness_time->century = (uint8_t)bin2bcd(ct.year / 100);
51 host_wellness_time->year = (uint8_t)bin2bcd(ct.year % 100);
56 * Update host time to f/w every 24 hours in a periodic timer.
59 void os_wellness_periodic(void *data)
61 struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data;
65 /* update time to FW */
66 if (!pqisrc_ctrl_offline(softs)){
67 if( (ret = pqisrc_write_current_time_to_host_wellness(softs)) != 0 )
68 DBG_ERR("Failed to update time to FW in periodic ret = %d\n", ret);
71 /* reschedule ourselves */
72 softs->os_specific.wellness_periodic = timeout(os_wellness_periodic,
73 softs, OS_HOST_WELLNESS_TIMEOUT * hz);
77 * Routine used to stop the heart-beat timer
79 void os_stop_heartbeat_timer(pqisrc_softstate_t *softs)
83 /* Kill the heart beat event */
84 untimeout(os_start_heartbeat_timer, softs,
85 softs->os_specific.heartbeat_timeout_id);
91 * Routine used to start the heart-beat timer
93 void os_start_heartbeat_timer(void *data)
95 struct pqisrc_softstate *softs = (struct pqisrc_softstate *)data;
98 pqisrc_heartbeat_timer_handler(softs);
99 if (!pqisrc_ctrl_offline(softs)) {
100 softs->os_specific.heartbeat_timeout_id =
101 timeout(os_start_heartbeat_timer, softs,
102 OS_FW_HEARTBEAT_TIMER_INTERVAL * hz);
109 * Mutex initialization function
111 int os_init_spinlock(struct pqisrc_softstate *softs, struct mtx *lock,
114 mtx_init(lock, lockname, NULL, MTX_SPIN);
120 * Mutex uninitialization function
122 void os_uninit_spinlock(struct mtx *lock)
130 * Semaphore initialization function
132 int os_create_semaphore(const char *name, int value, struct sema *sema)
134 sema_init(sema, value, name);
135 return PQI_STATUS_SUCCESS;
140 * Semaphore uninitialization function
142 int os_destroy_semaphore(struct sema *sema)
145 return PQI_STATUS_SUCCESS;
150 * Semaphore grab function
152 void inline os_sema_lock(struct sema *sema)
158 * Semaphore release function
160 void inline os_sema_unlock(struct sema *sema)
167 * string copy wrapper function
169 int os_strlcpy(char *dst, char *src, int size)
171 return strlcpy(dst, src, size);