2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <dev/isci/isci.h>
38 #include <dev/isci/scil/scif_user_callback.h>
41 isci_timer_timeout(void *arg)
43 struct ISCI_TIMER *timer = (struct ISCI_TIMER *)arg;
45 isci_log_message(3, "TIMER", "timeout %p\n", timer);
47 /* callout_stop() will *not* keep the timer from running if it is
48 * pending. callout_drain() cannot be called from interrupt context,
49 * because it may cause thread to sleep which is not allowed in
50 * interrupt context. So instead, check the is_started flag to see if
51 * the timer routine should actually be run or not.
53 if (timer->is_started == TRUE)
54 timer->callback(timer->cookie);
58 * @brief This callback method asks the user to start the supplied timer.
60 * @warning All timers in the system started by the SCI Framework are one
61 * shot timers. Therefore, the SCI user should make sure that it
62 * removes the timer from it's list when a timer actually fires.
63 * Additionally, SCI Framework user's should be able to handle
64 * calls from the SCI Framework to stop a timer that may already
67 * @param[in] controller This parameter specifies the controller with
68 * which this timer is to associated.
69 * @param[in] timer This parameter specifies the timer to be started.
70 * @param[in] milliseconds This parameter specifies the number of
71 * milliseconds for which to stall. The operating system driver
72 * is allowed to round this value up where necessary.
77 scif_cb_timer_start(SCI_CONTROLLER_HANDLE_T controller, void *timer,
78 uint32_t milliseconds)
80 struct ISCI_TIMER *isci_timer = (struct ISCI_TIMER *)timer;
82 isci_timer->is_started = TRUE;
83 isci_log_message(3, "TIMER", "start %p %d\n", timer, milliseconds);
84 callout_reset_sbt(&isci_timer->callout, SBT_1MS * milliseconds, 0,
85 isci_timer_timeout, timer, 0);
89 * @brief This callback method asks the user to stop the supplied timer.
91 * @param[in] controller This parameter specifies the controller with
92 * which this timer is to associated.
93 * @param[in] timer This parameter specifies the timer to be stopped.
98 scif_cb_timer_stop(SCI_CONTROLLER_HANDLE_T controller, void *timer)
100 struct ISCI_TIMER *isci_timer = (struct ISCI_TIMER *)timer;
102 isci_log_message(3, "TIMER", "stop %p\n", timer);
103 isci_timer->is_started = FALSE;
104 callout_stop(&isci_timer->callout);
108 * @brief This callback method asks the user to create a timer and provide
109 * a handle for this timer for use in further timer interactions.
111 * @warning The "timer_callback" method should be executed in a mutually
112 * exlusive manner from the controller completion handler
113 * handler (refer to scic_controller_get_handler_methods()).
115 * @param[in] timer_callback This parameter specifies the callback method
116 * to be invoked whenever the timer expires.
117 * @param[in] controller This parameter specifies the controller with
118 * which this timer is to be associated.
119 * @param[in] cookie This parameter specifies a piece of information that
120 * the user must retain. This cookie is to be supplied by the
121 * user anytime a timeout occurs for the created timer.
123 * @return This method returns a handle to a timer object created by the
124 * user. The handle will be utilized for all further interactions
125 * relating to this timer.
128 scif_cb_timer_create(SCI_CONTROLLER_HANDLE_T scif_controller,
129 SCI_TIMER_CALLBACK_T timer_callback, void *cookie)
131 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
132 sci_object_get_association(scif_controller);
133 struct ISCI_TIMER *timer;
135 sci_pool_get(isci_controller->timer_pool, timer);
137 callout_init_mtx(&timer->callout, &isci_controller->lock, FALSE);
139 timer->callback = timer_callback;
140 timer->cookie = cookie;
141 timer->is_started = FALSE;
143 isci_log_message(3, "TIMER", "create %p %p %p\n", timer, timer_callback, cookie);
149 * @brief This callback method asks the user to destroy the supplied timer.
151 * @param[in] controller This parameter specifies the controller with
152 * which this timer is to associated.
153 * @param[in] timer This parameter specifies the timer to be destroyed.
158 scif_cb_timer_destroy(SCI_CONTROLLER_HANDLE_T scif_controller,
161 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
162 sci_object_get_association(scif_controller);
164 scif_cb_timer_stop(scif_controller, timer_handle);
165 sci_pool_put(isci_controller->timer_pool, (struct ISCI_TIMER *)timer_handle);
167 isci_log_message(3, "TIMER", "destroy %p\n", timer_handle);