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