2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * AMCC'S 3ware driver for 9000 series storage controllers.
33 * Author: Vinod Kashyap
34 * Modifications by: Adam Radford
39 #ifndef TW_OSL_INLINE_H
41 #define TW_OSL_INLINE_H
45 * Inline functions shared between OSL and CL, and defined by OSL.
49 #include <dev/twa/tw_osl.h>
54 * Function name: tw_osl_init_lock
55 * Description: Initializes a lock.
57 * Input: ctlr_handle -- ptr to controller handle
58 * lock_name -- string indicating name of the lock
59 * Output: lock -- ptr to handle to the initialized lock
62 #define tw_osl_init_lock(ctlr_handle, lock_name, lock) \
63 mtx_init(lock, lock_name, NULL, MTX_SPIN)
68 * Function name: tw_osl_destroy_lock
69 * Description: Destroys a previously initialized lock.
71 * Input: ctlr_handle -- ptr to controller handle
72 * lock -- ptr to handle to the lock to be
77 #define tw_osl_destroy_lock(ctlr_handle, lock) \
83 * Function name: tw_osl_get_lock
84 * Description: Acquires the specified lock.
86 * Input: ctlr_handle -- ptr to controller handle
87 * lock -- ptr to handle to the lock to be
92 #define tw_osl_get_lock(ctlr_handle, lock) \
98 * Function name: tw_osl_free_lock
99 * Description: Frees a previously acquired lock.
101 * Input: ctlr_handle -- ptr to controller handle
102 * lock -- ptr to handle to the lock to be freed
106 #define tw_osl_free_lock(ctlr_handle, lock) \
107 mtx_unlock_spin(lock)
112 * Function name: tw_osl_ctlr_ready
113 * Description: CL calls this function to notify the OS Layer that it
114 * is ready to accept new requests. This function is
115 * called only if a call to tw_osl_ctlr_busy has been
116 * made previously. We don't use this function as of now.
118 * Input: ctlr_handle -- ptr to controller handle
122 #define tw_osl_ctlr_ready(ctlr_handle)
129 * Function name: tw_osl_dbg_printf
130 * Description: Prints passed info (prefixed by ctlr name)to syslog
132 * Input: ctlr_handle -- controller handle
133 * fmt -- format string for the arguments to follow
134 * ... -- variable number of arguments, to be printed
135 * based on the fmt string
137 * Return value: Number of bytes printed
139 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
140 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
142 #endif /* TW_OSL_DEBUG */
147 * Function name: tw_osl_notify_event
148 * Description: Prints passed event info (prefixed by ctlr name)
151 * Input: ctlr_handle -- controller handle
152 * event -- ptr to a packet describing the event/error
156 #define tw_osl_notify_event(ctlr_handle, event) \
157 twa_printf((ctlr_handle->osl_ctlr_ctxt), \
158 "%s: (0x%02X: 0x%04X): %s: %s\n", \
159 event->severity_str, \
162 event->parameter_data + \
163 strlen(event->parameter_data) + 1, \
164 event->parameter_data)
169 * Function name: tw_osl_read_reg
170 * Description: Reads a register on the controller
172 * Input: ctlr_handle -- controller handle
173 * offset -- offset from Base Address
174 * size -- # of bytes to read
176 * Return value: Value read
178 #define tw_osl_read_reg tw_osl_read_reg_inline
179 static __inline TW_UINT32
180 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
181 TW_INT32 offset, TW_INT32 size)
183 bus_space_tag_t bus_tag =
184 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
185 bus_space_handle_t bus_handle =
186 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
189 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
192 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
195 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
202 * Function name: tw_osl_write_reg
203 * Description: Writes to a register on the controller
205 * Input: ctlr_handle -- controller handle
206 * offset -- offset from Base Address
207 * value -- value to write
208 * size -- # of bytes to write
212 #define tw_osl_write_reg tw_osl_write_reg_inline
213 static __inline TW_VOID
214 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
215 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
217 bus_space_tag_t bus_tag =
218 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
219 bus_space_handle_t bus_handle =
220 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
223 bus_space_write_4(bus_tag, bus_handle, offset, value);
225 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
227 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
232 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
235 * Function name: tw_osl_read_pci_config
236 * Description: Reads from the PCI config space.
238 * Input: sc -- ptr to per ctlr structure
239 * offset -- register offset
240 * size -- # of bytes to be read
242 * Return value: Value read
244 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
246 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
252 * Function name: tw_osl_write_pci_config
253 * Description: Writes to the PCI config space.
255 * Input: sc -- ptr to per ctlr structure
256 * offset -- register offset
257 * value -- value to write
258 * size -- # of bytes to be written
262 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
264 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
265 offset/*PCIR_STATUS*/, value, size)
267 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
272 * Function name: tw_osl_get_local_time
273 * Description: Gets the local time
277 * Return value: local time
279 #define tw_osl_get_local_time() \
280 (time_second - utc_offset())
284 * Function name: tw_osl_delay
285 * Description: Spin for the specified time
287 * Input: usecs -- micro-seconds to spin
291 #define tw_osl_delay(usecs) DELAY(usecs)
295 #ifdef TW_OSL_CAN_SLEEP
298 * Function name: tw_osl_sleep
299 * Description: Sleep for the specified time, or until woken up
301 * Input: ctlr_handle -- controller handle
302 * sleep_handle -- handle to sleep on
303 * timeout -- time period (in ms) to sleep
305 * Return value: 0 -- successfully woken up
306 * EWOULDBLOCK -- time out
307 * ERESTART -- woken up by a signal
309 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
310 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
315 * Function name: tw_osl_wakeup
316 * Description: Wake up a sleeping process
318 * Input: ctlr_handle -- controller handle
319 * sleep_handle -- handle of sleeping process to be
324 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
325 wakeup_one(sleep_handle)
327 #endif /* TW_OSL_CAN_SLEEP */
331 /* Allows setting breakpoints in the CL code for debugging purposes. */
332 #define tw_osl_breakpoint() breakpoint()
335 /* Text name of current function. */
336 #define tw_osl_cur_func() __func__
339 /* Copy 'size' bytes from 'src' to 'dest'. */
340 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
343 /* Zero 'size' bytes starting at 'addr'. */
344 #define tw_osl_memzero bzero
347 /* Standard sprintf. */
348 #define tw_osl_sprintf sprintf
351 /* Copy string 'src' to 'dest'. */
352 #define tw_osl_strcpy strcpy
355 /* Return length of string pointed at by 'str'. */
356 #define tw_osl_strlen strlen
359 /* Standard vsprintf. */
360 #define tw_osl_vsprintf vsprintf
364 #endif /* TW_OSL_INLINE_H */