2 * Copyright (c) 2004-05 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
38 #ifndef TW_OSL_INLINE_H
40 #define TW_OSL_INLINE_H
44 * Inline functions shared between OSL and CL, and defined by OSL.
48 #include <dev/twa/tw_osl.h>
53 * Function name: tw_osl_init_lock
54 * Description: Initializes a lock.
56 * Input: ctlr_handle -- ptr to controller handle
57 * lock_name -- string indicating name of the lock
58 * Output: lock -- ptr to handle to the initialized lock
61 #define tw_osl_init_lock(ctlr_handle, lock_name, lock) \
62 mtx_init(lock, lock_name, NULL, MTX_SPIN)
67 * Function name: tw_osl_destroy_lock
68 * Description: Destroys a previously initialized lock.
70 * Input: ctlr_handle -- ptr to controller handle
71 * lock -- ptr to handle to the lock to be
76 #define tw_osl_destroy_lock(ctlr_handle, lock) \
82 * Function name: tw_osl_get_lock
83 * Description: Acquires the specified lock.
85 * Input: ctlr_handle -- ptr to controller handle
86 * lock -- ptr to handle to the lock to be
91 #define tw_osl_get_lock(ctlr_handle, lock) \
97 * Function name: tw_osl_free_lock
98 * Description: Frees a previously acquired lock.
100 * Input: ctlr_handle -- ptr to controller handle
101 * lock -- ptr to handle to the lock to be freed
105 #define tw_osl_free_lock(ctlr_handle, lock) \
106 mtx_unlock_spin(lock)
111 * Function name: tw_osl_ctlr_ready
112 * Description: CL calls this function to notify the OS Layer that it
113 * is ready to accept new requests. This function is
114 * called only if a call to tw_osl_ctlr_busy has been
115 * made previously. We don't use this function as of now.
117 * Input: ctlr_handle -- ptr to controller handle
121 #define tw_osl_ctlr_ready(ctlr_handle)
128 * Function name: tw_osl_dbg_printf
129 * Description: Prints passed info (prefixed by ctlr name)to syslog
131 * Input: ctlr_handle -- controller handle
132 * fmt -- format string for the arguments to follow
133 * ... -- variable number of arguments, to be printed
134 * based on the fmt string
136 * Return value: Number of bytes printed
138 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
139 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
141 #endif /* TW_OSL_DEBUG */
146 * Function name: tw_osl_notify_event
147 * Description: Prints passed event info (prefixed by ctlr name)
150 * Input: ctlr_handle -- controller handle
151 * event -- ptr to a packet describing the event/error
155 #define tw_osl_notify_event(ctlr_handle, event) \
156 twa_printf((ctlr_handle->osl_ctlr_ctxt), \
157 "%s: (0x%02X: 0x%04X): %s: %s\n", \
158 event->severity_str, \
161 event->parameter_data + \
162 strlen(event->parameter_data) + 1, \
163 event->parameter_data)
168 * Function name: tw_osl_read_reg
169 * Description: Reads a register on the controller
171 * Input: ctlr_handle -- controller handle
172 * offset -- offset from Base Address
173 * size -- # of bytes to read
175 * Return value: Value read
177 #define tw_osl_read_reg tw_osl_read_reg_inline
178 static __inline TW_UINT32
179 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
180 TW_INT32 offset, TW_INT32 size)
182 bus_space_tag_t bus_tag =
183 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
184 bus_space_handle_t bus_handle =
185 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
188 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
191 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
194 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
201 * Function name: tw_osl_write_reg
202 * Description: Writes to a register on the controller
204 * Input: ctlr_handle -- controller handle
205 * offset -- offset from Base Address
206 * value -- value to write
207 * size -- # of bytes to write
211 #define tw_osl_write_reg tw_osl_write_reg_inline
212 static __inline TW_VOID
213 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
214 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
216 bus_space_tag_t bus_tag =
217 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
218 bus_space_handle_t bus_handle =
219 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
222 bus_space_write_4(bus_tag, bus_handle, offset, value);
224 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
226 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
231 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
234 * Function name: tw_osl_read_pci_config
235 * Description: Reads from the PCI config space.
237 * Input: sc -- ptr to per ctlr structure
238 * offset -- register offset
239 * size -- # of bytes to be read
241 * Return value: Value read
243 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
245 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
251 * Function name: tw_osl_write_pci_config
252 * Description: Writes to the PCI config space.
254 * Input: sc -- ptr to per ctlr structure
255 * offset -- register offset
256 * value -- value to write
257 * size -- # of bytes to be written
261 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
263 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
264 offset/*PCIR_STATUS*/, value, size)
266 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
271 * Function name: tw_osl_get_local_time
272 * Description: Gets the local time
276 * Return value: local time
278 #define tw_osl_get_local_time() \
279 (time_second - utc_offset())
283 * Function name: tw_osl_delay
284 * Description: Spin for the specified time
286 * Input: usecs -- micro-seconds to spin
290 #define tw_osl_delay(usecs) DELAY(usecs)
294 #ifdef TW_OSL_CAN_SLEEP
297 * Function name: tw_osl_sleep
298 * Description: Sleep for the specified time, or until woken up
300 * Input: ctlr_handle -- controller handle
301 * sleep_handle -- handle to sleep on
302 * timeout -- time period (in ms) to sleep
304 * Return value: 0 -- successfully woken up
305 * EWOULDBLOCK -- time out
306 * ERESTART -- woken up by a signal
308 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
309 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
314 * Function name: tw_osl_wakeup
315 * Description: Wake up a sleeping process
317 * Input: ctlr_handle -- controller handle
318 * sleep_handle -- handle of sleeping process to be
323 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
324 wakeup_one(sleep_handle)
326 #endif /* TW_OSL_CAN_SLEEP */
330 /* Allows setting breakpoints in the CL code for debugging purposes. */
331 #define tw_osl_breakpoint() breakpoint()
334 /* Text name of current function. */
335 #define tw_osl_cur_func() __func__
338 /* Copy 'size' bytes from 'src' to 'dest'. */
339 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
342 /* Zero 'size' bytes starting at 'addr'. */
343 #define tw_osl_memzero bzero
346 /* Standard sprintf. */
347 #define tw_osl_sprintf sprintf
350 /* Copy string 'src' to 'dest'. */
351 #define tw_osl_strcpy strcpy
354 /* Return length of string pointed at by 'str'. */
355 #define tw_osl_strlen strlen
358 /* Standard vsprintf. */
359 #define tw_osl_vsprintf vsprintf
363 #endif /* TW_OSL_INLINE_H */