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)
114 * Function name: tw_osl_dbg_printf
115 * Description: Prints passed info (prefixed by ctlr name)to syslog
117 * Input: ctlr_handle -- controller handle
118 * fmt -- format string for the arguments to follow
119 * ... -- variable number of arguments, to be printed
120 * based on the fmt string
122 * Return value: Number of bytes printed
124 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
125 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
127 #endif /* TW_OSL_DEBUG */
132 * Function name: tw_osl_notify_event
133 * Description: Prints passed event info (prefixed by ctlr name)
136 * Input: ctlr_handle -- controller handle
137 * event -- ptr to a packet describing the event/error
141 #define tw_osl_notify_event(ctlr_handle, event) \
142 twa_printf((ctlr_handle->osl_ctlr_ctxt), \
143 "%s: (0x%02X: 0x%04X): %s: %s\n", \
144 event->severity_str, \
147 event->parameter_data + \
148 strlen(event->parameter_data) + 1, \
149 event->parameter_data)
154 * Function name: tw_osl_read_reg
155 * Description: Reads a register on the controller
157 * Input: ctlr_handle -- controller handle
158 * offset -- offset from Base Address
159 * size -- # of bytes to read
161 * Return value: Value read
163 #define tw_osl_read_reg tw_osl_read_reg_inline
164 static __inline TW_UINT32
165 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
166 TW_INT32 offset, TW_INT32 size)
168 bus_space_tag_t bus_tag =
169 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
170 bus_space_handle_t bus_handle =
171 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
174 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
177 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
180 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
187 * Function name: tw_osl_write_reg
188 * Description: Writes to a register on the controller
190 * Input: ctlr_handle -- controller handle
191 * offset -- offset from Base Address
192 * value -- value to write
193 * size -- # of bytes to write
197 #define tw_osl_write_reg tw_osl_write_reg_inline
198 static __inline TW_VOID
199 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
200 TW_INT32 offset, TW_INT32 value, TW_INT32 size)
202 bus_space_tag_t bus_tag =
203 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
204 bus_space_handle_t bus_handle =
205 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
208 bus_space_write_4(bus_tag, bus_handle, offset, value);
210 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
212 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
217 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
220 * Function name: tw_osl_read_pci_config
221 * Description: Reads from the PCI config space.
223 * Input: sc -- ptr to per ctlr structure
224 * offset -- register offset
225 * size -- # of bytes to be read
227 * Return value: Value read
229 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
231 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
237 * Function name: tw_osl_write_pci_config
238 * Description: Writes to the PCI config space.
240 * Input: sc -- ptr to per ctlr structure
241 * offset -- register offset
242 * value -- value to write
243 * size -- # of bytes to be written
247 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
249 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
250 offset/*PCIR_STATUS*/, value, size)
252 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
257 * Function name: tw_osl_get_local_time
258 * Description: Gets the local time
262 * Return value: local time
264 #define tw_osl_get_local_time() \
265 (time_second - utc_offset())
269 * Function name: tw_osl_delay
270 * Description: Spin for the specified time
272 * Input: usecs -- micro-seconds to spin
276 #define tw_osl_delay(usecs) DELAY(usecs)
280 #ifdef TW_OSL_CAN_SLEEP
283 * Function name: tw_osl_sleep
284 * Description: Sleep for the specified time, or until woken up
286 * Input: ctlr_handle -- controller handle
287 * sleep_handle -- handle to sleep on
288 * timeout -- time period (in ms) to sleep
290 * Return value: 0 -- successfully woken up
291 * EWOULDBLOCK -- time out
292 * ERESTART -- woken up by a signal
294 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
295 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
300 * Function name: tw_osl_wakeup
301 * Description: Wake up a sleeping process
303 * Input: ctlr_handle -- controller handle
304 * sleep_handle -- handle of sleeping process to be
309 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
310 wakeup_one(sleep_handle)
312 #endif /* TW_OSL_CAN_SLEEP */
316 /* Allows setting breakpoints in the CL code for debugging purposes. */
317 #define tw_osl_breakpoint() breakpoint()
320 /* Text name of current function. */
321 #define tw_osl_cur_func() __func__
324 /* Copy 'size' bytes from 'src' to 'dest'. */
325 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
328 /* Zero 'size' bytes starting at 'addr'. */
329 #define tw_osl_memzero bzero
332 /* Standard sprintf. */
333 #define tw_osl_sprintf sprintf
336 /* Copy string 'src' to 'dest'. */
337 #define tw_osl_strcpy strcpy
340 /* Return length of string pointed at by 'str'. */
341 #define tw_osl_strlen strlen
344 /* Standard vsprintf. */
345 #define tw_osl_vsprintf vsprintf
349 #endif /* TW_OSL_INLINE_H */