2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
5 * Copyright (c) 2004-05 Vinod Kashyap.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * AMCC'S 3ware driver for 9000 series storage controllers.
35 * Author: Vinod Kashyap
36 * Modifications by: Adam Radford
41 #ifndef TW_OSL_INLINE_H
43 #define TW_OSL_INLINE_H
47 * Inline functions shared between OSL and CL, and defined by OSL.
51 #include <dev/twa/tw_osl.h>
56 * Function name: tw_osl_init_lock
57 * Description: Initializes a lock.
59 * Input: ctlr_handle -- ptr to controller handle
60 * lock_name -- string indicating name of the lock
61 * Output: lock -- ptr to handle to the initialized lock
64 #define tw_osl_init_lock(ctlr_handle, lock_name, lock) \
65 mtx_init(lock, lock_name, NULL, MTX_SPIN)
70 * Function name: tw_osl_destroy_lock
71 * Description: Destroys a previously initialized lock.
73 * Input: ctlr_handle -- ptr to controller handle
74 * lock -- ptr to handle to the lock to be
79 #define tw_osl_destroy_lock(ctlr_handle, lock) \
85 * Function name: tw_osl_get_lock
86 * Description: Acquires the specified lock.
88 * Input: ctlr_handle -- ptr to controller handle
89 * lock -- ptr to handle to the lock to be
94 #define tw_osl_get_lock(ctlr_handle, lock) \
100 * Function name: tw_osl_free_lock
101 * Description: Frees a previously acquired lock.
103 * Input: ctlr_handle -- ptr to controller handle
104 * lock -- ptr to handle to the lock to be freed
108 #define tw_osl_free_lock(ctlr_handle, lock) \
109 mtx_unlock_spin(lock)
116 * Function name: tw_osl_dbg_printf
117 * Description: Prints passed info (prefixed by ctlr name)to syslog
119 * Input: ctlr_handle -- controller handle
120 * fmt -- format string for the arguments to follow
121 * ... -- variable number of arguments, to be printed
122 * based on the fmt string
124 * Return value: Number of bytes printed
126 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
127 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
129 #endif /* TW_OSL_DEBUG */
134 * Function name: tw_osl_notify_event
135 * Description: Prints passed event info (prefixed by ctlr name)
138 * Input: ctlr_handle -- controller handle
139 * event -- ptr to a packet describing the event/error
143 #define tw_osl_notify_event(ctlr_handle, event) \
144 twa_printf((ctlr_handle->osl_ctlr_ctxt), \
145 "%s: (0x%02X: 0x%04X): %s: %s\n", \
146 event->severity_str, \
149 event->parameter_data + \
150 strlen(event->parameter_data) + 1, \
151 event->parameter_data)
156 * Function name: tw_osl_read_reg
157 * Description: Reads a register on the controller
159 * Input: ctlr_handle -- controller handle
160 * offset -- offset from Base Address
161 * size -- # of bytes to read
163 * Return value: Value read
165 #define tw_osl_read_reg tw_osl_read_reg_inline
166 static __inline TW_UINT32
167 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
168 TW_INT32 offset, TW_INT32 size)
170 bus_space_tag_t bus_tag =
171 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
172 bus_space_handle_t bus_handle =
173 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
176 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
179 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
182 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
189 * Function name: tw_osl_write_reg
190 * Description: Writes to a register on the controller
192 * Input: ctlr_handle -- controller handle
193 * offset -- offset from Base Address
194 * value -- value to write
195 * size -- # of bytes to write
199 #define tw_osl_write_reg tw_osl_write_reg_inline
200 static __inline TW_VOID
201 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
202 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
204 bus_space_tag_t bus_tag =
205 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
206 bus_space_handle_t bus_handle =
207 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
210 bus_space_write_4(bus_tag, bus_handle, offset, value);
212 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
214 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
219 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
222 * Function name: tw_osl_read_pci_config
223 * Description: Reads from the PCI config space.
225 * Input: sc -- ptr to per ctlr structure
226 * offset -- register offset
227 * size -- # of bytes to be read
229 * Return value: Value read
231 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
233 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
239 * Function name: tw_osl_write_pci_config
240 * Description: Writes to the PCI config space.
242 * Input: sc -- ptr to per ctlr structure
243 * offset -- register offset
244 * value -- value to write
245 * size -- # of bytes to be written
249 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
251 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
252 offset/*PCIR_STATUS*/, value, size)
254 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
259 * Function name: tw_osl_get_local_time
260 * Description: Gets the local time
264 * Return value: local time
266 #define tw_osl_get_local_time() \
267 (time_second - utc_offset())
271 * Function name: tw_osl_delay
272 * Description: Spin for the specified time
274 * Input: usecs -- micro-seconds to spin
278 #define tw_osl_delay(usecs) DELAY(usecs)
282 #ifdef TW_OSL_CAN_SLEEP
285 * Function name: tw_osl_sleep
286 * Description: Sleep for the specified time, or until woken up
288 * Input: ctlr_handle -- controller handle
289 * sleep_handle -- handle to sleep on
290 * timeout -- time period (in ms) to sleep
292 * Return value: 0 -- successfully woken up
293 * EWOULDBLOCK -- time out
294 * ERESTART -- woken up by a signal
296 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
297 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
302 * Function name: tw_osl_wakeup
303 * Description: Wake up a sleeping process
305 * Input: ctlr_handle -- controller handle
306 * sleep_handle -- handle of sleeping process to be
311 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
312 wakeup_one(sleep_handle)
314 #endif /* TW_OSL_CAN_SLEEP */
318 /* Allows setting breakpoints in the CL code for debugging purposes. */
319 #define tw_osl_breakpoint() breakpoint()
322 /* Text name of current function. */
323 #define tw_osl_cur_func() __func__
326 /* Copy 'size' bytes from 'src' to 'dest'. */
327 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
330 /* Zero 'size' bytes starting at 'addr'. */
331 #define tw_osl_memzero bzero
334 /* Standard sprintf. */
335 #define tw_osl_sprintf sprintf
338 /* Copy string 'src' to 'dest'. */
339 #define tw_osl_strcpy strcpy
342 /* Return length of string pointed at by 'str'. */
343 #define tw_osl_strlen strlen
346 /* Standard vsprintf. */
347 #define tw_osl_vsprintf vsprintf
351 #endif /* TW_OSL_INLINE_H */