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
39 #ifndef TW_OSL_INLINE_H
41 #define TW_OSL_INLINE_H
44 * Inline functions shared between OSL and CL, and defined by OSL.
47 #include <dev/twa/tw_osl.h>
50 * Function name: tw_osl_init_lock
51 * Description: Initializes a lock.
53 * Input: ctlr_handle -- ptr to controller handle
54 * lock_name -- string indicating name of the lock
55 * Output: lock -- ptr to handle to the initialized lock
58 #define tw_osl_init_lock(ctlr_handle, lock_name, lock) \
59 mtx_init(lock, lock_name, NULL, MTX_SPIN)
62 * Function name: tw_osl_destroy_lock
63 * Description: Destroys a previously initialized lock.
65 * Input: ctlr_handle -- ptr to controller handle
66 * lock -- ptr to handle to the lock to be
71 #define tw_osl_destroy_lock(ctlr_handle, lock) \
75 * Function name: tw_osl_get_lock
76 * Description: Acquires the specified lock.
78 * Input: ctlr_handle -- ptr to controller handle
79 * lock -- ptr to handle to the lock to be
84 #define tw_osl_get_lock(ctlr_handle, lock) \
88 * Function name: tw_osl_free_lock
89 * Description: Frees a previously acquired lock.
91 * Input: ctlr_handle -- ptr to controller handle
92 * lock -- ptr to handle to the lock to be freed
96 #define tw_osl_free_lock(ctlr_handle, lock) \
102 * Function name: tw_osl_dbg_printf
103 * Description: Prints passed info (prefixed by ctlr name)to syslog
105 * Input: ctlr_handle -- controller handle
106 * fmt -- format string for the arguments to follow
107 * ... -- variable number of arguments, to be printed
108 * based on the fmt string
110 * Return value: Number of bytes printed
112 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
113 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
115 #endif /* TW_OSL_DEBUG */
118 * Function name: tw_osl_notify_event
119 * Description: Prints passed event info (prefixed by ctlr name)
122 * Input: ctlr_handle -- controller handle
123 * event -- ptr to a packet describing the event/error
127 #define tw_osl_notify_event(ctlr_handle, event) \
128 twa_printf((ctlr_handle->osl_ctlr_ctxt), \
129 "%s: (0x%02X: 0x%04X): %s: %s\n", \
130 event->severity_str, \
133 event->parameter_data + \
134 strlen(event->parameter_data) + 1, \
135 event->parameter_data)
138 * Function name: tw_osl_read_reg
139 * Description: Reads a register on the controller
141 * Input: ctlr_handle -- controller handle
142 * offset -- offset from Base Address
143 * size -- # of bytes to read
145 * Return value: Value read
147 #define tw_osl_read_reg tw_osl_read_reg_inline
148 static __inline TW_UINT32
149 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
150 TW_INT32 offset, TW_INT32 size)
152 bus_space_tag_t bus_tag =
153 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
154 bus_space_handle_t bus_handle =
155 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
158 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
161 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
164 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
169 * Function name: tw_osl_write_reg
170 * Description: Writes to a register on the controller
172 * Input: ctlr_handle -- controller handle
173 * offset -- offset from Base Address
174 * value -- value to write
175 * size -- # of bytes to write
179 #define tw_osl_write_reg tw_osl_write_reg_inline
180 static __inline TW_VOID
181 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
182 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
184 bus_space_tag_t bus_tag =
185 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
186 bus_space_handle_t bus_handle =
187 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
190 bus_space_write_4(bus_tag, bus_handle, offset, value);
192 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
194 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
197 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
200 * Function name: tw_osl_read_pci_config
201 * Description: Reads from the PCI config space.
203 * Input: sc -- ptr to per ctlr structure
204 * offset -- register offset
205 * size -- # of bytes to be read
207 * Return value: Value read
209 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
211 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
215 * Function name: tw_osl_write_pci_config
216 * Description: Writes to the PCI config space.
218 * Input: sc -- ptr to per ctlr structure
219 * offset -- register offset
220 * value -- value to write
221 * size -- # of bytes to be written
225 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
227 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
228 offset/*PCIR_STATUS*/, value, size)
230 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
233 * Function name: tw_osl_get_local_time
234 * Description: Gets the local time
238 * Return value: local time
240 #define tw_osl_get_local_time() \
241 (time_second - utc_offset())
244 * Function name: tw_osl_delay
245 * Description: Spin for the specified time
247 * Input: usecs -- micro-seconds to spin
251 #define tw_osl_delay(usecs) DELAY(usecs)
253 #ifdef TW_OSL_CAN_SLEEP
256 * Function name: tw_osl_sleep
257 * Description: Sleep for the specified time, or until woken up
259 * Input: ctlr_handle -- controller handle
260 * sleep_handle -- handle to sleep on
261 * timeout -- time period (in ms) to sleep
263 * Return value: 0 -- successfully woken up
264 * EWOULDBLOCK -- time out
265 * ERESTART -- woken up by a signal
267 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
268 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
271 * Function name: tw_osl_wakeup
272 * Description: Wake up a sleeping process
274 * Input: ctlr_handle -- controller handle
275 * sleep_handle -- handle of sleeping process to be
280 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
281 wakeup_one(sleep_handle)
283 #endif /* TW_OSL_CAN_SLEEP */
285 /* Allows setting breakpoints in the CL code for debugging purposes. */
286 #define tw_osl_breakpoint() breakpoint()
288 /* Text name of current function. */
289 #define tw_osl_cur_func() __func__
291 /* Copy 'size' bytes from 'src' to 'dest'. */
292 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
294 /* Zero 'size' bytes starting at 'addr'. */
295 #define tw_osl_memzero bzero
297 /* Standard sprintf. */
298 #define tw_osl_sprintf sprintf
300 /* Copy string 'src' to 'dest'. */
301 #define tw_osl_strcpy strcpy
303 /* Return length of string pointed at by 'str'. */
304 #define tw_osl_strlen strlen
306 /* Standard vsprintf. */
307 #define tw_osl_vsprintf vsprintf
309 #endif /* TW_OSL_INLINE_H */