4 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <dev/isci/isci.h>
36 #include <dev/isci/scil/scif_user_callback.h>
39 isci_timer_timeout(void *arg)
41 struct ISCI_TIMER *timer = (struct ISCI_TIMER *)arg;
43 isci_log_message(3, "TIMER", "timeout %p\n", timer);
45 /* callout_stop() will *not* keep the timer from running if it is
46 * pending. callout_drain() cannot be called from interrupt context,
47 * because it may cause thread to sleep which is not allowed in
48 * interrupt context. So instead, check the is_started flag to see if
49 * the timer routine should actually be run or not.
51 if (timer->is_started == TRUE)
52 timer->callback(timer->cookie);
56 * @brief This callback method asks the user to start the supplied timer.
58 * @warning All timers in the system started by the SCI Framework are one
59 * shot timers. Therefore, the SCI user should make sure that it
60 * removes the timer from it's list when a timer actually fires.
61 * Additionally, SCI Framework user's should be able to handle
62 * calls from the SCI Framework to stop a timer that may already
65 * @param[in] controller This parameter specifies the controller with
66 * which this timer is to associated.
67 * @param[in] timer This parameter specifies the timer to be started.
68 * @param[in] milliseconds This parameter specifies the number of
69 * milliseconds for which to stall. The operating system driver
70 * is allowed to round this value up where necessary.
75 scif_cb_timer_start(SCI_CONTROLLER_HANDLE_T controller, void *timer,
76 uint32_t milliseconds)
78 struct ISCI_TIMER *isci_timer = (struct ISCI_TIMER *)timer;
80 isci_timer->is_started = TRUE;
81 isci_log_message(3, "TIMER", "start %p %d\n", timer, milliseconds);
82 callout_reset(&isci_timer->callout, (milliseconds * hz)/1000,
83 isci_timer_timeout, timer);
87 * @brief This callback method asks the user to stop the supplied timer.
89 * @param[in] controller This parameter specifies the controller with
90 * which this timer is to associated.
91 * @param[in] timer This parameter specifies the timer to be stopped.
96 scif_cb_timer_stop(SCI_CONTROLLER_HANDLE_T controller, void *timer)
98 struct ISCI_TIMER *isci_timer = (struct ISCI_TIMER *)timer;
100 isci_log_message(3, "TIMER", "stop %p\n", timer);
101 isci_timer->is_started = FALSE;
102 callout_stop(&isci_timer->callout);
106 * @brief This callback method asks the user to create a timer and provide
107 * a handle for this timer for use in further timer interactions.
109 * @warning The "timer_callback" method should be executed in a mutually
110 * exlusive manner from the controller completion handler
111 * handler (refer to scic_controller_get_handler_methods()).
113 * @param[in] timer_callback This parameter specifies the callback method
114 * to be invoked whenever the timer expires.
115 * @param[in] controller This parameter specifies the controller with
116 * which this timer is to be associated.
117 * @param[in] cookie This parameter specifies a piece of information that
118 * the user must retain. This cookie is to be supplied by the
119 * user anytime a timeout occurs for the created timer.
121 * @return This method returns a handle to a timer object created by the
122 * user. The handle will be utilized for all further interactions
123 * relating to this timer.
126 scif_cb_timer_create(SCI_CONTROLLER_HANDLE_T scif_controller,
127 SCI_TIMER_CALLBACK_T timer_callback, void *cookie)
129 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
130 sci_object_get_association(scif_controller);
131 struct ISCI_TIMER *timer;
133 sci_pool_get(isci_controller->timer_pool, timer);
135 callout_init_mtx(&timer->callout, &isci_controller->lock, FALSE);
137 timer->callback = timer_callback;
138 timer->cookie = cookie;
139 timer->is_started = FALSE;
141 isci_log_message(3, "TIMER", "create %p %p %p\n", timer, timer_callback, cookie);
147 * @brief This callback method asks the user to destory the supplied timer.
149 * @param[in] controller This parameter specifies the controller with
150 * which this timer is to associated.
151 * @param[in] timer This parameter specifies the timer to be destroyed.
156 scif_cb_timer_destroy(SCI_CONTROLLER_HANDLE_T scif_controller,
159 struct ISCI_CONTROLLER *isci_controller = (struct ISCI_CONTROLLER *)
160 sci_object_get_association(scif_controller);
162 scif_cb_timer_stop(scif_controller, timer_handle);
163 sci_pool_put(isci_controller->timer_pool, (struct ISCI_TIMER *)timer_handle);
165 isci_log_message(3, "TIMER", "destroy %p\n", timer_handle);