]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/twa/tw_osl_inline.h
MFV r359401: OpenBSM: import ee79d73e8df5: auditreduce: add a zone filter
[FreeBSD/FreeBSD.git] / sys / dev / twa / tw_osl_inline.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2004-07 Applied Micro Circuits Corporation.
5  * Copyright (c) 2004-05 Vinod Kashyap.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *      $FreeBSD$
30  */
31
32 /*
33  * AMCC'S 3ware driver for 9000 series storage controllers.
34  *
35  * Author: Vinod Kashyap
36  * Modifications by: Adam Radford
37  */
38
39
40
41 #ifndef TW_OSL_INLINE_H
42
43 #define TW_OSL_INLINE_H
44
45
46 /*
47  * Inline functions shared between OSL and CL, and defined by OSL.
48  */
49
50
51 #include <dev/twa/tw_osl.h>
52
53
54
55 /*
56  * Function name:       tw_osl_init_lock
57  * Description:         Initializes a lock.
58  *
59  * Input:               ctlr_handle     -- ptr to controller handle
60  *                      lock_name       -- string indicating name of the lock
61  * Output:              lock            -- ptr to handle to the initialized lock
62  * Return value:        None
63  */
64 #define tw_osl_init_lock(ctlr_handle, lock_name, lock)  \
65         mtx_init(lock, lock_name, NULL, MTX_SPIN)
66
67
68
69 /*
70  * Function name:       tw_osl_destroy_lock
71  * Description:         Destroys a previously initialized lock.
72  *
73  * Input:               ctlr_handle     -- ptr to controller handle
74  *                      lock            -- ptr to handle to the lock to be
75  *                                              destroyed
76  * Output:              None
77  * Return value:        None
78  */
79 #define tw_osl_destroy_lock(ctlr_handle, lock)  \
80         mtx_destroy(lock)
81
82
83
84 /*
85  * Function name:       tw_osl_get_lock
86  * Description:         Acquires the specified lock.
87  *
88  * Input:               ctlr_handle     -- ptr to controller handle
89  *                      lock            -- ptr to handle to the lock to be
90  *                                              acquired
91  * Output:              None
92  * Return value:        None
93  */
94 #define tw_osl_get_lock(ctlr_handle, lock)      \
95         mtx_lock_spin(lock)
96
97
98
99 /*
100  * Function name:       tw_osl_free_lock
101  * Description:         Frees a previously acquired lock.
102  *
103  * Input:               ctlr_handle     -- ptr to controller handle
104  *                      lock            -- ptr to handle to the lock to be freed
105  * Output:              None
106  * Return value:        None
107  */
108 #define tw_osl_free_lock(ctlr_handle, lock)     \
109         mtx_unlock_spin(lock)
110
111
112
113 #ifdef TW_OSL_DEBUG
114
115 /*
116  * Function name:       tw_osl_dbg_printf
117  * Description:         Prints passed info (prefixed by ctlr name)to syslog
118  *
119  * Input:               ctlr_handle -- controller handle
120  *                      fmt -- format string for the arguments to follow
121  *                      ... -- variable number of arguments, to be printed
122  *                              based on the fmt string
123  * Output:              None
124  * Return value:        Number of bytes printed
125  */
126 #define tw_osl_dbg_printf(ctlr_handle, fmt, args...)                    \
127         twa_printf((ctlr_handle->osl_ctlr_ctxt), fmt, ##args)
128
129 #endif /* TW_OSL_DEBUG */
130
131
132
133 /*
134  * Function name:       tw_osl_notify_event
135  * Description:         Prints passed event info (prefixed by ctlr name)
136  *                      to syslog
137  *
138  * Input:               ctlr_handle -- controller handle
139  *                      event -- ptr to a packet describing the event/error
140  * Output:              None
141  * Return value:        None
142  */
143 #define tw_osl_notify_event(ctlr_handle, event)                         \
144         twa_printf((ctlr_handle->osl_ctlr_ctxt),                        \
145                 "%s: (0x%02X: 0x%04X): %s: %s\n",                       \
146                 event->severity_str,                                    \
147                 event->event_src,                                       \
148                 event->aen_code,                                        \
149                 event->parameter_data +                                 \
150                         strlen(event->parameter_data) + 1,              \
151                 event->parameter_data)
152
153
154
155 /*
156  * Function name:       tw_osl_read_reg
157  * Description:         Reads a register on the controller
158  *
159  * Input:               ctlr_handle -- controller handle
160  *                      offset -- offset from Base Address
161  *                      size -- # of bytes to read
162  * Output:              None
163  * Return value:        Value read
164  */
165 #define tw_osl_read_reg         tw_osl_read_reg_inline
166 static __inline TW_UINT32
167 tw_osl_read_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
168         TW_INT32 offset, TW_INT32 size)
169 {
170         bus_space_tag_t         bus_tag =
171                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
172         bus_space_handle_t      bus_handle =
173                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
174
175         if (size == 4)
176                 return((TW_UINT32)bus_space_read_4(bus_tag, bus_handle,
177                         offset));
178         else if (size == 2)
179                 return((TW_UINT32)bus_space_read_2(bus_tag, bus_handle,
180                         offset));
181         else
182                 return((TW_UINT32)bus_space_read_1(bus_tag, bus_handle,
183                         offset));
184 }
185
186
187
188 /*
189  * Function name:       tw_osl_write_reg
190  * Description:         Writes to a register on the controller
191  *
192  * Input:               ctlr_handle -- controller handle
193  *                      offset -- offset from Base Address
194  *                      value -- value to write
195  *                      size -- # of bytes to write
196  * Output:              None
197  * Return value:        None
198  */
199 #define tw_osl_write_reg        tw_osl_write_reg_inline
200 static __inline TW_VOID
201 tw_osl_write_reg_inline(struct tw_cl_ctlr_handle *ctlr_handle,
202         TW_INT32 offset, TW_INT32 value, TW_INT32 size)
203 {
204         bus_space_tag_t         bus_tag =
205                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_tag;
206         bus_space_handle_t      bus_handle =
207                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_handle;
208
209         if (size == 4)
210                 bus_space_write_4(bus_tag, bus_handle, offset, value);
211         else if (size == 2)
212                 bus_space_write_2(bus_tag, bus_handle, offset, (TW_INT16)value);
213         else
214                 bus_space_write_1(bus_tag, bus_handle, offset, (TW_INT8)value);
215 }
216
217
218
219 #ifdef TW_OSL_PCI_CONFIG_ACCESSIBLE
220
221 /*
222  * Function name:       tw_osl_read_pci_config
223  * Description:         Reads from the PCI config space.
224  *
225  * Input:               sc      -- ptr to per ctlr structure
226  *                      offset  -- register offset
227  *                      size    -- # of bytes to be read
228  * Output:              None
229  * Return value:        Value read
230  */
231 #define tw_osl_read_pci_config(ctlr_handle, offset, size)               \
232         pci_read_config(                                                \
233                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
234                 offset, size)
235
236
237
238 /*
239  * Function name:       tw_osl_write_pci_config
240  * Description:         Writes to the PCI config space.
241  *
242  * Input:               sc      -- ptr to per ctlr structure
243  *                      offset  -- register offset
244  *                      value   -- value to write
245  *                      size    -- # of bytes to be written
246  * Output:              None
247  * Return value:        None
248  */
249 #define tw_osl_write_pci_config(ctlr_handle, offset, value, size)       \
250         pci_write_config(                                               \
251                 ((struct twa_softc *)(ctlr_handle->osl_ctlr_ctxt))->bus_dev, \
252                 offset/*PCIR_STATUS*/, value, size)
253
254 #endif /* TW_OSL_PCI_CONFIG_ACCESSIBLE */
255
256
257
258 /*
259  * Function name:       tw_osl_get_local_time
260  * Description:         Gets the local time
261  *
262  * Input:               None
263  * Output:              None
264  * Return value:        local time
265  */
266 #define tw_osl_get_local_time()                                         \
267         (time_second - utc_offset())
268
269
270 /*
271  * Function name:       tw_osl_delay
272  * Description:         Spin for the specified time
273  *
274  * Input:               usecs -- micro-seconds to spin
275  * Output:              None
276  * Return value:        None
277  */
278 #define tw_osl_delay(usecs)     DELAY(usecs)
279
280
281
282 #ifdef TW_OSL_CAN_SLEEP
283
284 /*
285  * Function name:       tw_osl_sleep
286  * Description:         Sleep for the specified time, or until woken up
287  *
288  * Input:               ctlr_handle -- controller handle
289  *                      sleep_handle -- handle to sleep on
290  *                      timeout -- time period (in ms) to sleep
291  * Output:              None
292  * Return value:        0 -- successfully woken up
293  *                      EWOULDBLOCK -- time out
294  *                      ERESTART -- woken up by a signal
295  */
296 #define tw_osl_sleep(ctlr_handle, sleep_handle, timeout)                \
297         tsleep((TW_VOID *)sleep_handle, PRIBIO, NULL, timeout)
298
299
300
301 /*
302  * Function name:       tw_osl_wakeup
303  * Description:         Wake up a sleeping process
304  *
305  * Input:               ctlr_handle -- controller handle
306  *                      sleep_handle -- handle of sleeping process to be
307                                         woken up
308  * Output:              None
309  * Return value:        None
310  */
311 #define tw_osl_wakeup(ctlr_handle, sleep_handle)                        \
312         wakeup_one(sleep_handle)
313
314 #endif /* TW_OSL_CAN_SLEEP */
315
316
317
318 /* Allows setting breakpoints in the CL code for debugging purposes. */
319 #define tw_osl_breakpoint()             breakpoint()
320
321
322 /* Text name of current function. */
323 #define tw_osl_cur_func()               __func__
324
325
326 /* Copy 'size' bytes from 'src' to 'dest'. */
327 #define tw_osl_memcpy(dest, src, size)  bcopy(src, dest, size)
328
329
330 /* Zero 'size' bytes starting at 'addr'. */
331 #define tw_osl_memzero                  bzero
332
333
334 /* Standard sprintf. */
335 #define tw_osl_sprintf                  sprintf
336
337
338 /* Copy string 'src' to 'dest'. */
339 #define tw_osl_strcpy                   strcpy
340
341
342 /* Return length of string pointed at by 'str'. */
343 #define tw_osl_strlen                   strlen
344
345
346 /* Standard vsprintf. */
347 #define tw_osl_vsprintf                 vsprintf
348
349
350
351 #endif /* TW_OSL_INLINE_H */