| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fw_port.h,v 1.32 2009/04/20 09:56:07 mschuett Exp $ */ | | 1 | /* $NetBSD: fw_port.h,v 1.33 2009/08/07 00:10:53 dyoung Exp $ */ |
2 | /* | | 2 | /* |
3 | * Copyright (c) 2004 KIYOHARA Takashi | | 3 | * Copyright (c) 2004 KIYOHARA Takashi |
4 | * All rights reserved. | | 4 | * All rights reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -21,579 +21,26 @@ | | | @@ -21,579 +21,26 @@ |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
23 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | | 23 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
24 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 24 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | * POSSIBILITY OF SUCH DAMAGE. | | 25 | * POSSIBILITY OF SUCH DAMAGE. |
26 | * | | 26 | * |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #ifndef _FW_PORT_H | | 29 | #ifndef _FW_PORT_H |
30 | #define _FW_PORT_H | | 30 | #define _FW_PORT_H |
31 | | | 31 | |
32 | #ifdef _KERNEL | | 32 | #ifdef _KERNEL |
33 | | | 33 | |
34 | #if defined(__FreeBSD__) | | | |
35 | #ifdef __DragonFly__ | | | |
36 | #define OS_STR "DragonFly" | | | |
37 | #define OS_VER __DragonFly_cc_version | | | |
38 | #define OS_VER_STR "DragonFly-1" | | | |
39 | #define PROJECT_STR "DragonFly Project" | | | |
40 | #else | | | |
41 | #define OS_STR "FreeBSD" | | | |
42 | #define OS_VER __FreeBSD_version | | | |
43 | #define OS_VER_STR "FreeBSD-5" | | | |
44 | #define PROJECT_STR "FreeBSD Project" | | | |
45 | #endif | | | |
46 | | | | |
47 | #if defined(__DragonFly__) || __FreeBSD_version < 500000 | | | |
48 | #define fw_dev_t dev_t | | | |
49 | #else | | | |
50 | #define fw_dev_t struct cdev * | | | |
51 | #endif | | | |
52 | | | | |
53 | #if defined(__DragonFly__) || __FreeBSD_version < 500000 | | | |
54 | #define fw_dev2unit(x) ((minor(x) & 0xff) | (minor(x) >> 8)) | | | |
55 | #define fw_unit2minor(x) (((x) & 0xff) | (((x) << 8) & ~0xffff)) | | | |
56 | #else | | | |
57 | #define fw_dev2unit(x) dev2unit(x) | | | |
58 | #define fw_unit2minor(x) unit2minor(x) | | | |
59 | #endif | | | |
60 | | | | |
61 | #define fw_timevalcmp(tv1, tv2, op) timevalcmp((tv1), (tv2), op) | | | |
62 | #define fw_timevalsub(tv1, tv2) timevalsub((tv1), (tv2)) | | | |
63 | | | | |
64 | #define fw_get_nameunit(dev) device_get_nameunit((dev)) | | | |
65 | #define fw_get_unit(dev) device_get_unit((dev)) | | | |
66 | | | | |
67 | #define fw_printf(dev, ...) device_printf((dev), __VA_ARGS__) | | | |
68 | | | | |
69 | /* atomic macros */ | | | |
70 | #define fw_atomic_set_int(P, V) atomic_set_int((P), (V)) | | | |
71 | #define fw_atomic_readandclear_int(p) atomic_readandclear_int((p)) | | | |
72 | | | | |
73 | /* mutex macros */ | | | |
74 | #include <sys/mutex.h> | | | |
75 | typedef struct mtx fw_mtx_t; | | | |
76 | #define fw_mtx_init(mutex, name, type, opts) \ | | | |
77 | mtx_init(mutex, name, type, opts) | | | |
78 | #define fw_mtx_lock(mutex) mtx_lock(mutex) | | | |
79 | #define fw_mtx_unlock(mutex) mtx_unlock(mutex) | | | |
80 | #define fw_mtx_destroy(mutex) mtx_destroy(mutex) | | | |
81 | #define fw_mtx_assert(mutex, what) \ | | | |
82 | mtx_assert(mutex, what) | | | |
83 | | | | |
84 | #define fw_msleep(ident, mtx, priority, wmesg, timo) \ | | | |
85 | msleep(ident, mtx, priority, wmesg, timo); | | | |
86 | | | | |
87 | /* taskqueue macros */ | | | |
88 | #include <sys/taskqueue.h> | | | |
89 | typedef struct task fw_task_t; | | | |
90 | #define FW_TASK_INIT(task, priority, func, context) \ | | | |
91 | TASK_INIT((task), (priority), (func), (context)) | | | |
92 | #define fw_taskqueue_enqueue(queue, task) \ | | | |
93 | taskqueue_enqueue((queue), (task)) | | | |
94 | #define fw_taskqueue_create_fast(name, mflags, enqueue, taskqueue) \ | | | |
95 | taskqueue_create_fast((name), (mflags), (enqueue), (taskqueue)) | | | |
96 | #define fw_taskqueue_start_threads(taskqueue, n, x, fmt, ...) \ | | | |
97 | taskqueue_start_threads((taskqueue), (n), (x), (fmt), ...) | | | |
98 | | | | |
99 | /* kthread macros */ | | | |
100 | #ifdef __DragonFly__ | | | |
101 | typedef d_thread_t fw_thread_t; | | | |
102 | typedef d_thread_t fw_proc_t; | | | |
103 | #define fw_kthread_create(func, arg, newpp, fmt, ...) \ | | | |
104 | kthread_create(func, arg, newpp, fmt, __VA_ARGS__) | | | |
105 | #define fw_kthread_exit(x) kthread_exit() | | | |
106 | #elif __FreeBSD_version >= 500000 | | | |
107 | typedef struct thread fw_thread_t; | | | |
108 | typedef struct thread fw_proc_t; | | | |
109 | #define fw_kthread_create(func, arg, newpp, fmt, ...) \ | | | |
110 | kthread_create(func, arg, newpp, 0, 0, fmt, __VA_ARGS__) | | | |
111 | #define fw_kthread_exit(ecode) kthread_exit((ecode)) | | | |
112 | #else | | | |
113 | typedef struct proc fw_thread_t; | | | |
114 | typedef struct proc fw_proc_t; | | | |
115 | #define fw_kthread_create(func, arg, newpp, fmt, ...) \ | | | |
116 | kproc_create(func, arg, newpp, fmt, __VA_ARGS__) | | | |
117 | #define fw_kthread_exit(ecode) kproc_exit((ecode)) | | | |
118 | #endif | | | |
119 | | | | |
120 | /* callout macros */ | | | |
121 | #if defined(__DragonFly__) || __FreeBSD_version < 500000 | | | |
122 | #define fw_callout_init(c) callout_init((c), 0) | | | |
123 | #else | | | |
124 | #define fw_callout_init(c) callout_init(c, 1 /* mpsafe */) | | | |
125 | #endif | | | |
126 | #define fw_callout_reset(c, ticks, func, arg) \ | | | |
127 | callout_reset((c), (ticks), (func), (arg)) | | | |
128 | #define fw_callout_stop(c) callout_stop((c)) | | | |
129 | | | | |
130 | /* bus_dma macros */ | | | |
131 | typedef bus_dma_tag_t fw_bus_dma_tag_t; | | | |
132 | #if defined(__FreeBSD__) && __FreeBSD_version >= 501102 | | | |
133 | #define fw_bus_dma_tag_create(t, \ | | | |
134 | a, b, laddr, haddr, ffunc, farg, s, ns, mxss, f, lfunc, larg, tp)\ | | | |
135 | bus_dma_tag_create((t), (a), (b), (laddr), (haddr), \ | | | |
136 | (ffunc), (farg), (s), (ns), (mxss), (f), (lfunc), (larg), (tp)) | | | |
137 | #else | | | |
138 | #define fw_bus_dma_tag_create(t, a, b, \ | | | |
139 | laddr, haddr, ffunc, farg, s, ns, mxss, f, lfunc, larg, tp) \ | | | |
140 | bus_dma_tag_create((t), (a), (b), (laddr), (haddr), \ | | | |
141 | (ffunc), (farg), (s), (ns), (mxss), (f), (tp)) | | | |
142 | #endif | | | |
143 | #define fw_bus_dma_tag_destroy(t) \ | | | |
144 | bus_dma_tag_destroy((t)) | | | |
145 | #define fw_bus_dmamap_create(t, f, mp) \ | | | |
146 | bus_dmamap_create((t), 0, (mp)) | | | |
147 | #define fw_bus_dmamap_destroy((t), (m)) \ | | | |
148 | bus_dmamap_destroy((t), (m)) | | | |
149 | #define fw_bus_dmamap_load(t, m, b, l, func, a, f) \ | | | |
150 | bus_dmamap_load((t), (m), (b), (l), (func), (a), 0) | | | |
151 | #define fw_bus_dmamap_load_mbuf(t, m, b, func, a, f) \ | | | |
152 | bus_dmamap_load((t), (m), (b), (func), (a), 0) | | | |
153 | #define fw_bus_dmamap_unload(t, m) \ | | | |
154 | bus_dmamap_unload((t), (m)) | | | |
155 | #if __FreeBSD_version < 500000 | | | |
156 | #define fw_bus_dmamap_sync(t, m, op) \ | | | |
157 | do { \ | | | |
158 | switch ((op)) { \ | | | |
159 | (BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE): \ | | | |
160 | bus_dmamap_sync((t), (m), BUS_DMASYNC_PREWRITE);\ | | | |
161 | bus_dmamap_sync((t), (m), BUS_DMASYNC_PREREAD); \ | | | |
162 | break; \ | | | |
163 | (BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE): \ | | | |
164 | /* BUS_DMASYNC_POSTWRITE is probably a no-op. */\ | | | |
165 | bus_dmamap_sync((t), (m), BUS_DMASYNC_POSTREAD);\ | | | |
166 | break; \ | | | |
167 | default: \ | | | |
168 | bus_dmamap_sync((t), (m), (op)); \ | | | |
169 | } \ | | | |
170 | } while (/*CONSTCOND*/0) | | | |
171 | #else | | | |
172 | #define fw_bus_dmamap_sync(t, m, op) \ | | | |
173 | bus_dmamap_sync((t), (m), (op)) | | | |
174 | #endif | | | |
175 | #define fw_bus_dmamem_alloc(t, vp, f, mp) \ | | | |
176 | bus_dmamem_alloc((t), (vp), (f), (mp)) | | | |
177 | #define fw_bus_dmamem_free(t, v, m) \ | | | |
178 | bus_dmamem_free((t), (v), (m)) | | | |
179 | | | | |
180 | | | | |
181 | #define fw_config_pending_incr() | | | |
182 | #define fw_config_pending_decr() | | | |
183 | | | | |
184 | #define splfw() splimp() | | | |
185 | #define splfwnet() splimp() | | | |
186 | #define splfwsbp() splcam() | | | |
187 | | | | |
188 | #ifdef __DragonFly__ | | | |
189 | #include <sys/select.h> | | | |
190 | #elif __FreeBSD_version >= 500000 | | | |
191 | #include <sys/selinfo.h> | | | |
192 | #else | | | |
193 | #include <sys/select.h> | | | |
194 | #endif | | | |
195 | | | | |
196 | #define FW_KASSERT(expression, str) \ | | | |
197 | KASSERT(expression, str) | | | |
198 | | | | |
199 | | | | |
200 | #ifdef __DragonFly__ | | | |
201 | #define M_DONTWAIT MB_DONTWAIT | | | |
202 | #endif | | | |
203 | | | | |
204 | | | | |
205 | /* | | | |
206 | * fw attach macro for FreeBSD | | | |
207 | */ | | | |
208 | #define FW_ATTACH(dname) \ | | | |
209 | static int \ | | | |
210 | __CONCAT(dname,_attach)(device_t dev) | | | |
211 | #define FW_ATTACH_START(dname, sc, fwa) \ | | | |
212 | struct __CONCAT(dname,_softc) *sc = \ | | | |
213 | ((struct __CONCAT(dname,_softc) *)device_get_softc(dev)); \ | | | |
214 | __unused struct fw_attach_args *fwa = \ | | | |
215 | device_get_ivars(dev) | | | |
216 | #define FW_ATTACH_RETURN(r) return (r) | | | |
217 | | | | |
218 | /* | | | |
219 | * fw detach macro for FreeBSD | | | |
220 | */ | | | |
221 | #define FW_DETACH(dname) \ | | | |
222 | static int \ | | | |
223 | __CONCAT(dname,_detach)(device_t dev) | | | |
224 | #define FW_DETACH_START(dname, sc) \ | | | |
225 | struct __CONCAT(dname,_softc) *sc = \ | | | |
226 | ((struct __CONCAT(dname,_softc) *)device_get_softc(dev)) | | | |
227 | | | | |
228 | /* | | | |
229 | * fw open macro for FreeBSD | | | |
230 | */ | | | |
231 | #define FW_OPEN(dname) \ | | | |
232 | int \ | | | |
233 | __CONCAT(dname,_open)(fw_dev_t dev, int flags, int fmt, fw_proc_t td) | | | |
234 | #define FW_OPEN_START \ | | | |
235 | int unit = DEV2UNIT(dev); \ | | | |
236 | __unused struct firewire_softc *sc = \ | | | |
237 | devclass_get_softc(firewire_devclass, unit) | | | |
238 | | | | |
239 | /* | | | |
240 | * fw close macro for FreeBSD | | | |
241 | */ | | | |
242 | #define FW_CLOSE(dname) \ | | | |
243 | int \ | | | |
244 | __CONCAT(dname,_close)(fw_dev_t dev, int flags, \ | | | |
245 | int fmt, fw_proc_t td) | | | |
246 | #define FW_CLOSE_START | | | |
247 | | | | |
248 | /* | | | |
249 | * fw read macro for FreeBSD | | | |
250 | */ | | | |
251 | #define FW_READ(dname) \ | | | |
252 | int \ | | | |
253 | __CONCAT(dname,_read)(fw_dev_t dev, struct uio *uio, int ioflag) | | | |
254 | #define FW_READ_START | | | |
255 | | | | |
256 | /* | | | |
257 | * fw write macro for FreeBSD | | | |
258 | */ | | | |
259 | #define FW_WRITE(dname) \ | | | |
260 | int \ | | | |
261 | __CONCAT(dname,_write)(fw_dev_t dev, struct uio *uio, int ioflag) | | | |
262 | #define FW_WRITE_START | | | |
263 | | | | |
264 | /* | | | |
265 | * fw ioctl macro for FreeBSD | | | |
266 | */ | | | |
267 | #define FW_IOCTL(dname) \ | | | |
268 | int \ | | | |
269 | __CONCAT(dname,_ioctl) \ | | | |
270 | (fw_dev_t dev, u_long cmd, void *data, int flag, fw_proc_t td) | | | |
271 | #define FW_IOCTL_START \ | | | |
272 | int unit = DEV2UNIT(dev); \ | | | |
273 | __unused struct firewire_softc *sc = \ | | | |
274 | devclass_get_softc(firewire_devclass, unit) | | | |
275 | | | | |
276 | /* | | | |
277 | * fw poll macro for FreeBSD | | | |
278 | */ | | | |
279 | #define FW_POLL(dname) \ | | | |
280 | int \ | | | |
281 | __CONCAT(dname,_poll)(fw_dev_t dev, int events, fw_proc_t td) | | | |
282 | #define FW_POLL_START | | | |
283 | | | | |
284 | /* | | | |
285 | * fw mmap macro for FreeBSD | | | |
286 | */ | | | |
287 | #if defined(__DragonFly__) || __FreeBSD_version < 500102 | | | |
288 | #define FW_MMAP(dname) \ | | | |
289 | int \ | | | |
290 | __CONCAT(dname,_mmap)(fw_dev_t dev, vm_offset_t offset, int nproto) | | | |
291 | #else | | | |
292 | #define FW_MMAP(dname) \ | | | |
293 | int \ | | | |
294 | __CONCAT(dname,_mmap) \ | | | |
295 | (fw_dev_t dev, vm_offset_t offset, vm_paddr_t *paddr, int nproto) | | | |
296 | #endif | | | |
297 | #define FW_MMAP_START | | | |
298 | | | | |
299 | /* | | | |
300 | * fw strategy macro for FreeBSD | | | |
301 | */ | | | |
302 | #define FW_STRATEGY_START \ | | | |
303 | fw_dev_t dev = bp->bio_dev; \ | | | |
304 | int unit = DEV2UNIT(dev); \ | | | |
305 | __unused struct firewire_softc *sc = \ | | | |
306 | devclass_get_softc(firewire_devclass, unit) | | | |
307 | | | | |
308 | /* | | | |
309 | * if macro for FreeBSD | | | |
310 | */ | | | |
311 | #define IF_DETACH_START(dname, sc) \ | | | |
312 | struct __CONCAT(dname,_softc) *sc = \ | | | |
313 | (struct __CONCAT(dname,_softc) *)device_get_softc(dev) | | | |
314 | #define IF_IOCTL_START(dname, sc) \ | | | |
315 | struct __CONCAT(dname,_softc) *sc = \ | | | |
316 | ((struct fwip_eth_softc *)ifp->if_softc)->fwip | | | |
317 | #define IF_INIT(dname) \ | | | |
318 | static void \ | | | |
319 | __CONCAT(dname,_init)(void *arg) | | | |
320 | #define IF_INIT_START(dname, sc, ifp) \ | | | |
321 | struct __CONCAT(dname,_softc) *sc = \ | | | |
322 | ((struct fwip_eth_softc *)arg)->fwip; \ | | | |
323 | struct ifnet *ifp = (sc)->fw_softc.fwip_ifp | | | |
324 | #define IF_INIT_RETURN(r) return | | | |
325 | #define IF_STOP(dname) \ | | | |
326 | static void \ | | | |
327 | __CONCAT(dname,_stop)(struct __CONCAT(dname,_softc) *fwip) | | | |
328 | #define IF_STOP_START(dname, ifp, sc) \ | | | |
329 | struct ifnet *ifp = (sc)->fw_softc.fwip_ifp; | | | |
330 | | | | |
331 | /* | | | |
332 | * fwohci macro for FreeBSD | | | |
333 | */ | | | |
334 | #define FWOHCI_DETACH() \ | | | |
335 | int \ | | | |
336 | fwohci_detach(struct fwohci_softc *sc, device_t dev) | | | |
337 | #define FWOHCI_DETACH_START | | | |
338 | #define FWOHCI_DETACH_END | | | |
339 | #define FWOHCI_INIT_END | | | |
340 | | | | |
341 | /* | | | |
342 | * firewire macro for FreeBSD | | | |
343 | */ | | | |
344 | #define FIREWIRE_ATTACH_START \ | | | |
345 | device_t pa = device_get_parent(dev); \ | | | |
346 | struct firewire_comm *fc = (struct firewire_comm *)device_get_softc(pa) | | | |
347 | #define FWDEV_DESTROYDEV(sc) \ | | | |
348 | do { \ | | | |
349 | int err; \ | | | |
350 | if ((err = fwdev_destroydev((sc))) != 0) \ | | | |
351 | return err; \ | | | |
352 | } while (/*CONSTCOND*/0) | | | |
353 | #define FIREWIRE_GENERIC_ATTACH \ | | | |
354 | do { \ | | | |
355 | /* Locate our children */ \ | | | |
356 | bus_generic_probe(dev); \ | | | |
357 | \ | | | |
358 | /* launch attachement of the added children */ \ | | | |
359 | bus_generic_attach(dev); \ | | | |
360 | } while (/*CONSTCOND*/0) | | | |
361 | #define FIREWIRE_GENERIC_DETACH \ | | | |
362 | do { \ | | | |
363 | int err; \ | | | |
364 | if ((err = bus_generic_detach(dev)) != 0) \ | | | |
365 | return err; \ | | | |
366 | } while (/*CONSTCOND*/0) | | | |
367 | #define FIREWIRE_SBP_ATTACH \ | | | |
368 | do { \ | | | |
369 | fwa.fwdev = fwdev; \ | | | |
370 | fwdev->sbp = device_add_child(fc->bdev, fwa.name, -1); \ | | | |
371 | if (fwdev->sbp) { \ | | | |
372 | device_set_ivars(fwdev->sbp, &fwa); \ | | | |
373 | device_probe_and_attach(fwdev->sbp); \ | | | |
374 | } \ | | | |
375 | } while (/*CONSTCOND*/0) | | | |
376 | #define FIREWIRE_SBP_DETACH \ | | | |
377 | do { \ | | | |
378 | if (device_detach(fwdev->sbp) != 0) \ | | | |
379 | return; \ | | | |
380 | } while (/*CONSTCOND*/0) | | | |
381 | #define FIREWIRE_CHILDREN_FOREACH_FUNC(func, fdc) \ | | | |
382 | do { \ | | | |
383 | device_t *devlistp; \ | | | |
384 | int i, devcnt; \ | | | |
385 | \ | | | |
386 | if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) { \ | | | |
387 | for( i = 0 ; i < devcnt ; i++) \ | | | |
388 | if (device_get_state(devlistp[i]) >= \ | | | |
389 | DS_ATTACHED) { \ | | | |
390 | (fdc) = device_get_softc(devlistp[i]);\ | | | |
391 | if ((fdc)->func != NULL) \ | | | |
392 | (fdc)->func((fdc)); \ | | | |
393 | } \ | | | |
394 | free(devlistp, M_TEMP); \ | | | |
395 | } \ | | | |
396 | } while (/*CONSTCOND*/0) | | | |
397 | | | | |
398 | /* | | | |
399 | * sbp macro for FreeBSD | | | |
400 | */ | | | |
401 | #define SBP_ATTACH_START \ | | | |
402 | struct cam_devq *devq; \ | | | |
403 | \ | | | |
404 | memset(sbp, 0, sizeof(struct sbp_softc)); \ | | | |
405 | sbp->fd.dev = dev | | | |
406 | #define SBP_SCSIBUS_ATTACH \ | | | |
407 | do { \ | | | |
408 | sbp->sim = cam_sim_alloc(sbp_action, sbp_poll, "sbp", sbp, \ | | | |
409 | device_get_unit(dev), \ | | | |
410 | &sbp->mtx, \ | | | |
411 | /*untagged*/ 1, \ | | | |
412 | /*tagged*/ SBP_QUEUE_LEN - 1, \ | | | |
413 | devq); \ | | | |
414 | \ | | | |
415 | if (sbp->sim == NULL) { \ | | | |
416 | cam_simq_free(devq); \ | | | |
417 | return ENXIO; \ | | | |
418 | } \ | | | |
419 | \ | | | |
420 | SBP_LOCK(sbp); \ | | | |
421 | if (xpt_bus_register(sbp->sim, /*bus*/0) != CAM_SUCCESS) \ | | | |
422 | goto fail; \ | | | |
423 | \ | | | |
424 | if (xpt_create_path( \ | | | |
425 | &sbp->path, xpt_periph, cam_sim_path(sbp->sim), \ | | | |
426 | CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {\ | | | |
427 | xpt_bus_deregister(cam_sim_path(sbp->sim)); \ | | | |
428 | goto fail; \ | | | |
429 | } \ | | | |
430 | xpt_async(AC_BUS_RESET, sbp->path, /*arg*/ NULL); \ | | | |
431 | SBP_UNLOCK(sbp); \ | | | |
432 | } while (/*CONSTCOND*/0) | | | |
433 | #define SBP_DEVICE(d) ((d)->path) | | | |
434 | #define SBP_DEVICE_FREEZE(d, x) xpt_freeze_devq((d)->path, (x)) | | | |
435 | #define SBP_DEVICE_THAW(d, x) xpt_release_devq((d)->path, (x), TRUE) | | | |
436 | #define SBP_BUS_FREEZE(b) \ | | | |
437 | do { \ | | | |
438 | if (((b)->sim->flags & SIMQ_FREEZED) == 0) { \ | | | |
439 | xpt_freeze_simq((b)->sim, /*count*/1); \ | | | |
440 | (b)->sim->flags |= SIMQ_FREEZED; \ | | | |
441 | } \ | | | |
442 | } while (/*CONSTCOND*/0) | | | |
443 | #define SBP_BUS_THAW(b) \ | | | |
444 | do { \ | | | |
445 | xpt_release_simq((b)->sim, /*run queue*/TRUE); \ | | | |
446 | (b)->sim->flags &= ~SIMQ_FREEZED; \ | | | |
447 | } while (/*CONSTCOND*/0) | | | |
448 | #define SBP_DEVICE_PREATTACH() | | | |
449 | | | | |
450 | /* | | | |
451 | * fwip macro for FreeBSD | | | |
452 | */ | | | |
453 | #define FWIP_ATTACH_START \ | | | |
454 | int unit = device_get_unit(dev);\ | | | |
455 | struct fw_hwaddr *hwaddr; | | | |
456 | #define FWIP_ATTACH_SETUP \ | | | |
457 | do { \ | | | |
458 | fwip->fw_softc.fwip_ifp = if_alloc(IFT_IEEE1394); \ | | | |
459 | hwaddr = &IFP2FWC(fwip->fw_softc.fwip_ifp)->fc_hwaddr; \ | | | |
460 | } while (/*CONSTCOND*/0) | | | |
461 | | | | |
462 | #define FWDEV_MAKEDEV(sc) fwdev_makedev(sc) | | | |
463 | | | | |
464 | #define FIREWIRE_IFATTACH(ifp, ha) \ | | | |
465 | firewire_ifattach((ifp), (ha)) | | | |
466 | #define FIREWIRE_IFDETACH(ifp) \ | | | |
467 | do { \ | | | |
468 | firewire_ifdetach(ifp); \ | | | |
469 | if_free(ifp); \ | | | |
470 | } while (/*CONSTCOND*/0) | | | |
471 | #define FIREWIRE_BUSRESET(ifp) firewire_busreset((ifp)) | | | |
472 | #define FIREWIRE_INPUT(ifp, m, src) \ | | | |
473 | firewire_input((ifp), (m), (src)) | | | |
474 | #define FWIP_INIT(sc) fwip_init(&(sc)->fw_softc) | | | |
475 | #define FWIP_STOP(sc) fwip_stop((sc)) | | | |
476 | #define FIREWIRE_IOCTL(ifp, cmd, data) \ | | | |
477 | firewire_ioctl((ifp), (cmd), (data)) | | | |
478 | #define IF_INITNAME(ifp, dev, unit) \ | | | |
479 | if_initname((ifp), device_get_name((dev)), (unit)); | | | |
480 | #define SET_IFFUNC(ifp, start, ioctl, init, stop) \ | | | |
481 | do { \ | | | |
482 | (ifp)->if_start = (start); \ | | | |
483 | (ifp)->if_ioctl = (ioctl); \ | | | |
484 | (ifp)->if_init = (init); \ | | | |
485 | } while (/*CONSTCOND*/0) | | | |
486 | | | | |
487 | /* | | | |
488 | * fwdev macro for FreeBSD | | | |
489 | */ | | | |
490 | #define FWDEV_OPEN_START \ | | | |
491 | if (DEV_FWMEM(dev)) \ | | | |
492 | return fwmem_open(dev, flags, fmt, td) | | | |
493 | #define FWDEV_CLOSE_START \ | | | |
494 | if (DEV_FWMEM(dev)) \ | | | |
495 | return fwmem_close(dev, flags, fmt, td) | | | |
496 | #define FWDEV_READ_START \ | | | |
497 | if (DEV_FWMEM(dev)) \ | | | |
498 | return (physio(dev, uio, ioflag)) | | | |
499 | #define FWDEV_WRITE_START \ | | | |
500 | if (DEV_FWMEM(dev)) \ | | | |
501 | return (physio(dev, uio, ioflag)) | | | |
502 | #define FWDEV_IOCTL_START \ | | | |
503 | if (DEV_FWMEM(dev)) \ | | | |
504 | return fwmem_ioctl(dev, cmd, data, flag, td) | | | |
505 | #define FWDEV_IOCTL_REDIRECT fc->ioctl(dev, cmd, data, flag, td) | | | |
506 | #define FWDEV_POLL_START \ | | | |
507 | if (DEV_FWMEM(dev)) \ | | | |
508 | return fwmem_poll(dev, events, td) | | | |
509 | #if defined(__DragonFly__) || __FreeBSD_version < 500102 | | | |
510 | #define FWDEV_MMAP_START \ | | | |
511 | if (DEV_FWMEM(dev)) \ | | | |
512 | return fwmem_mmap(dev, offset, nproto) | | | |
513 | #else | | | |
514 | #define FWDEV_MMAP_START \ | | | |
515 | if (DEV_FWMEM(dev)) \ | | | |
516 | return fwmem_mmap(dev, offset, paddr, nproto) | | | |
517 | #endif | | | |
518 | #define FWDEV_STRATEGY_START \ | | | |
519 | if (DEV_FWMEM(dev)) { \ | | | |
520 | fwmem_strategy(bp); \ | | | |
521 | return; \ | | | |
522 | } | | | |
523 | | | | |
524 | #define XS_REQ_INVALID CAM_REQ_INVALID | | | |
525 | #define XS_SCSI_BUS_RESET CAM_SCSI_BUS_RESET | | | |
526 | #define XS_BDR_SENT CAM_BDR_SENT | | | |
527 | #define XS_DEV_NOT_THERE CAM_DEV_NOT_THERE | | | |
528 | #define XS_CMD_TIMEOUT CAM_CMD_TIMEOUT | | | |
529 | #define XS_REQUEUE_REQ CAM_REQUEUE_REQ | | | |
530 | #define XS_REQ_CMP CAM_REQ_CMP | | | |
531 | #define XS_REQ_CMP_ERR CAM_REQ_CMP_ERR | | | |
532 | #define XS_UA_ABORT CAM_UA_ABORT | | | |
533 | #define XS_SENSE (CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID) | | | |
534 | | | | |
535 | typedef union ccb sbp_scsi_xfer; | | | |
536 | typedef struct scsi_inquiry_data sbp_scsi_inquiry_data; | | | |
537 | | | | |
538 | #define SCSI_XFER_TARGET(x) ((x)->ccb_h.target_id) | | | |
539 | #define SCSI_XFER_LUN(x) ((x)->ccb_h.target_lun) | | | |
540 | #define SCSI_XFER_ERROR(x) ((x)->ccb_h.status) | | | |
541 | #define SCSI_XFER_DIR(x) ((x)->ccb_h.flags & CAM_DIR_MASK) | | | |
542 | #define SCSI_XFER_DATA_IN CAM_DIR_IN | | | |
543 | #define SCSI_XFER_CALLOUT(x) ((x)->ccb_h.timeout_ch) | | | |
544 | #define SCSI_XFER_TIMEOUT(x) ((x)->ccb_h.timeout) | | | |
545 | #define SCSI_XFER_OPECODE(x) ((x)->csio.cdb_io.cdb_bytes[0]) | | | |
546 | #define SCSI_XFER_STATUS(x) ((x)->csio.scsi_status) | | | |
547 | #define SCSI_XFER_EVPD(x) ((x)->csio.cdb_io.cdb_bytes[1] & SI_EVPD) | | | |
548 | #define SCSI_XFER_CMDLEN(x) ((x)->csio.cdb_len) | | | |
549 | #define SCSI_XFER_CMD(x) \ | | | |
550 | (((x)->csio.ccb_h.flags & CAM_CDB_POINTER) ?\ | | | |
551 | (void *)(x)->csio.cdb_io.cdb_ptr : \ | | | |
552 | (void *)&(x)->csio.cdb_io.cdb_bytes) | | | |
553 | #define SCSI_XFER_DATALEN(x) ((x)->csio.dxfer_len) | | | |
554 | #define SCSI_XFER_DATA(x) ((x)->csio.data_ptr) | | | |
555 | #define SCSI_XFER_SENSELEN(x) ((x)->csio.sense_len) | | | |
556 | #define SCSI_SENSE_DATA(x) (&(x)->csio.sense_data) | | | |
557 | #define SCSI_INQUIRY_DATA(x) ((x)->csio.data_ptr) | | | |
558 | #define SCSI_XFER_FUNCCODE(x) ((x)->ccb_h.func_code) | | | |
559 | #define SCSI_XFER_10BCMD_DUMP(x) \ | | | |
560 | ((x)->csio.cdb_io.cdb_bytes[0]), \ | | | |
561 | ((x)->csio.cdb_io.cdb_bytes[1]), \ | | | |
562 | ((x)->csio.cdb_io.cdb_bytes[2]), \ | | | |
563 | ((x)->csio.cdb_io.cdb_bytes[3]), \ | | | |
564 | ((x)->csio.cdb_io.cdb_bytes[4]), \ | | | |
565 | ((x)->csio.cdb_io.cdb_bytes[5]), \ | | | |
566 | ((x)->csio.cdb_io.cdb_bytes[6]), \ | | | |
567 | ((x)->csio.cdb_io.cdb_bytes[7]), \ | | | |
568 | ((x)->csio.cdb_io.cdb_bytes[8]), \ | | | |
569 | ((x)->csio.cdb_io.cdb_bytes[9]) | | | |
570 | #define SCSI_XFER_REQUEST_COMPLETE(x) | | | |
571 | #define SCSI_TRANSFER_DONE(x) xpt_done((x)) | | | |
572 | #ifdef SID_TYPE | | | |
573 | #undef SID_TYPE | | | |
574 | #define SID_TYPE 0x1f | | | |
575 | #endif | | | |
576 | | | | |
577 | #define NOT_LUN_WILDCARD(l) ((l) != CAM_LUN_WILDCARD) | | | |
578 | #define CAM_XFER_FLAGS(x) ((x)->csio.ccb_h.flags) | | | |
579 | | | | |
580 | #define mstohz(ms) \ | | | |
581 | (__predict_false((ms) >= 0x20000) ? \ | | | |
582 | (((ms) + 0u) / 1000u) * hz : \ | | | |
583 | (((ms) + 0u) * hz) / 1000u) | | | |
584 | | | | |
585 | | | | |
586 | #elif defined(__NetBSD__) | | | |
587 | #define OS_STR "NetBSD" | | 34 | #define OS_STR "NetBSD" |
588 | #define OS_VER __NetBSD_Version__ | | 35 | #define OS_VER __NetBSD_Version__ |
589 | #define OS_VER_STR "NetBSD-2" | | 36 | #define OS_VER_STR "NetBSD-2" |
590 | #define PROJECT_STR "NetBSD Project" | | 37 | #define PROJECT_STR "NetBSD Project" |
591 | | | 38 | |
592 | #define fw_dev_t dev_t | | 39 | #define fw_dev_t dev_t |
593 | | | 40 | |
594 | struct fwbus_attach_args { | | 41 | struct fwbus_attach_args { |
595 | const char *name; | | 42 | const char *name; |
596 | }; | | 43 | }; |
597 | | | 44 | |
598 | struct fw_hwaddr { | | 45 | struct fw_hwaddr { |
599 | uint32_t sender_unique_ID_hi; | | 46 | uint32_t sender_unique_ID_hi; |
| @@ -1348,18 +795,15 @@ typedef struct scsipi_inquiry_data sbp_s | | | @@ -1348,18 +795,15 @@ typedef struct scsipi_inquiry_data sbp_s |
1348 | | | 795 | |
1349 | #define SCSI_STATUS_CHECK_COND SCSI_CHECK | | 796 | #define SCSI_STATUS_CHECK_COND SCSI_CHECK |
1350 | #define SCSI_STATUS_BUSY SCSI_BUSY | | 797 | #define SCSI_STATUS_BUSY SCSI_BUSY |
1351 | #define SCSI_STATUS_CMD_TERMINATED SCSI_TERMINATED | | 798 | #define SCSI_STATUS_CMD_TERMINATED SCSI_TERMINATED |
1352 | | | 799 | |
1353 | #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF | | 800 | #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF |
1354 | | | 801 | |
1355 | #define DFLTPHYS (64 * 1024) /* fake */ | | 802 | #define DFLTPHYS (64 * 1024) /* fake */ |
1356 | | | 803 | |
1357 | #define kdb_backtrace() | | 804 | #define kdb_backtrace() |
1358 | #define kdb_active 0 | | 805 | #define kdb_active 0 |
1359 | | | 806 | |
1360 | #endif | | 807 | #endif |
1361 | #endif | | | |
1362 | #if defined(__NetBSD__) | | | |
1363 | #define vm_offset_t void * | | 808 | #define vm_offset_t void * |
1364 | #endif | | 809 | #endif |
1365 | #endif | | | |