1 /*
2 * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
3 * Copyright (c) 2004-05 Vinod Kashyap.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
14 *
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
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30 /*
31 * AMCC'S 3ware driver for 9000 series storage controllers.
32 *
33 * Author: Vinod Kashyap
34 * Modifications by: Adam Radford
35 */
36
37
38
39 #ifndef TW_OSL_INLINE_H
40
41 #define TW_OSL_INLINE_H
42
43
44 /*
45 * Inline functions shared between OSL and CL, and defined by OSL.
46 */
47
48
49 #include <dev/twa/tw_osl.h>
50
51
52
53 /*
54 * Function name: tw_osl_init_lock
55 * Description: Initializes a lock.
56 *
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
60 * Return value: None
61 */
62 #define tw_osl_init_lock(ctlr_handle, lock_name, lock) \
63 mtx_init(lock, lock_name, NULL, MTX_SPIN)
64
65
66
67 /*
68 * Function name: tw_osl_destroy_lock
69 * Description: Destroys a previously initialized lock.
70 *
71 * Input: ctlr_handle -- ptr to controller handle
72 * lock -- ptr to handle to the lock to be
73 * destroyed
74 * Output: None
75 * Return value: None
76 */
77 #define tw_osl_destroy_lock(ctlr_handle, lock) \
78 mtx_destroy(lock)
79
80
81
82 /*
83 * Function name: tw_osl_get_lock
84 * Description: Acquires the specified lock.
85 *
86 * Input: ctlr_handle -- ptr to controller handle
87 * lock -- ptr to handle to the lock to be
88 * acquired
89 * Output: None
90 * Return value: None
91 */
92 #define tw_osl_get_lock(ctlr_handle, lock) \
93 mtx_lock_spin(lock)
94
95
96
97 /*
98 * Function name: tw_osl_free_lock
99 * Description: Frees a previously acquired lock.
100 *
101 * Input: ctlr_handle -- ptr to controller handle
102 * lock -- ptr to handle to the lock to be freed
103 * Output: None
104 * Return value: None
105 */
106 #define tw_osl_free_lock(ctlr_handle, lock) \
107 mtx_unlock_spin(lock)
108
109
110
111 /*
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.
117 *
118 * Input: ctlr_handle -- ptr to controller handle
119 * Output: None
120 * Return value: None
121 */
122 #define tw_osl_ctlr_ready(ctlr_handle)
123
124
125
126 #ifdef TW_OSL_DEBUG
127
128 /*
129 * Function name: tw_osl_dbg_printf
130 * Description: Prints passed info (prefixed by ctlr name)to syslog
131 *
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
136 * Output: None
137 * Return value: Number of bytes printed
138 */
139 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...) \
140 twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
141
142 #endif /* TW_OSL_DEBUG */
143
144
145
146 /*
147 * Function name: tw_osl_notify_event
148 * Description: Prints passed event info (prefixed by ctlr name)
149 * to syslog
150 *
151 * Input: ctlr_handle -- controller handle
152 * event -- ptr to a packet describing the event/error
153 * Output: None
154 * Return value: None
155 */
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, \
160 event->event_src, \
161 event->aen_code, \
162 event->parameter_data + \
163 strlen(event->parameter_data) + 1, \
164 event->parameter_data)
165
166
167
168 /*
169 * Function name: tw_osl_read_reg
170 * Description: Reads a register on the controller
171 *
172 * Input: ctlr_handle -- controller handle
173 * offset -- offset from Base Address
174 * size -- # of bytes to read
175 * Output: None
176 * Return value: Value read
177 */
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)
182 {
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;
187
188 if (size == 4)
189 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
190 offset));
191 else if (size == 2)
192 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
193 offset));
194 else
195 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
196 offset));
197 }
198
199
200
201 /*
202 * Function name: tw_osl_write_reg
203 * Description: Writes to a register on the controller
204 *
205 * Input: ctlr_handle -- controller handle
206 * offset -- offset from Base Address
207 * value -- value to write
208 * size -- # of bytes to write
209 * Output: None
210 * Return value: None
211 */
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)
216 {
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;
221
222 if (size == 4)
223 bus_space_write_4(bus_tag, bus_handle, offset, value);
224 else if (size == 2)
225 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
226 else
227 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
228 }
229
230
231
232 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
233
234 /*
235 * Function name: tw_osl_read_pci_config
236 * Description: Reads from the PCI config space.
237 *
238 * Input: sc -- ptr to per ctlr structure
239 * offset -- register offset
240 * size -- # of bytes to be read
241 * Output: None
242 * Return value: Value read
243 */
244 #define tw_osl_read_pci_config(ctlr_handle, offset, size) \
245 pci_read_config( \
246 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
247 offset, size)
248
249
250
251 /*
252 * Function name: tw_osl_write_pci_config
253 * Description: Writes to the PCI config space.
254 *
255 * Input: sc -- ptr to per ctlr structure
256 * offset -- register offset
257 * value -- value to write
258 * size -- # of bytes to be written
259 * Output: None
260 * Return value: None
261 */
262 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size) \
263 pci_write_config( \
264 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
265 offset/*PCIR_STATUS*/, value, size)
266
267 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
268
269
270
271 /*
272 * Function name: tw_osl_get_local_time
273 * Description: Gets the local time
274 *
275 * Input: None
276 * Output: None
277 * Return value: local time
278 */
279 #define tw_osl_get_local_time() \
280 (time_second - (tz_minuteswest * 60) - \
281 (wall_cmos_clock ? adjkerntz : 0))
282
283
284
285 /*
286 * Function name: tw_osl_delay
287 * Description: Spin for the specified time
288 *
289 * Input: usecs -- micro-seconds to spin
290 * Output: None
291 * Return value: None
292 */
293 #define tw_osl_delay(usecs) DELAY(usecs)
294
295
296
297 #ifdef TW_OSL_CAN_SLEEP
298
299 /*
300 * Function name: tw_osl_sleep
301 * Description: Sleep for the specified time, or until woken up
302 *
303 * Input: ctlr_handle -- controller handle
304 * sleep_handle -- handle to sleep on
305 * timeout -- time period (in ms) to sleep
306 * Output: None
307 * Return value: 0 -- successfully woken up
308 * EWOULDBLOCK -- time out
309 * ERESTART -- woken up by a signal
310 */
311 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout) \
312 tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
313
314
315
316 /*
317 * Function name: tw_osl_wakeup
318 * Description: Wake up a sleeping process
319 *
320 * Input: ctlr_handle -- controller handle
321 * sleep_handle -- handle of sleeping process to be
322 woken up
323 * Output: None
324 * Return value: None
325 */
326 #define tw_osl_wakeup(ctlr_handle, sleep_handle) \
327 wakeup_one(sleep_handle)
328
329 #endif /* TW_OSL_CAN_SLEEP */
330
331
332
333 /* Allows setting breakpoints in the CL code for debugging purposes. */
334 #define tw_osl_breakpoint() breakpoint()
335
336
337 /* Text name of current function. */
338 #define tw_osl_cur_func() __func__
339
340
341 /* Copy 'size' bytes from 'src' to 'dest'. */
342 #define tw_osl_memcpy(dest, src, size) bcopy(src, dest, size)
343
344
345 /* Zero 'size' bytes starting at 'addr'. */
346 #define tw_osl_memzero bzero
347
348
349 /* Standard sprintf. */
350 #define tw_osl_sprintf sprintf
351
352
353 /* Copy string 'src' to 'dest'. */
354 #define tw_osl_strcpy strcpy
355
356
357 /* Return length of string pointed at by 'str'. */
358 #define tw_osl_strlen strlen
359
360
361 /* Standard vsprintf. */
362 #define tw_osl_vsprintf vsprintf
363
364
365
366 #endif /* TW_OSL_INLINE_H */
Cache object: 575ae7778eb172e85cc8035a651da84a
|