Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / ieee1394 / fw_port.h
blob18408cd6e5857cad0f77bde795eca151d0beb6e6
1 /* $NetBSD: fw_port.h,v 1.32 2009/04/20 09:56:07 mschuett Exp $ */
2 /*
3 * Copyright (c) 2004 KIYOHARA Takashi
4 * All rights reserved.
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
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
25 * POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _FW_PORT_H
30 #define _FW_PORT_H
32 #ifdef _KERNEL
34 #define OS_STR "NetBSD"
35 #define OS_VER __NetBSD_Version__
36 #define OS_VER_STR "NetBSD-2"
37 #define PROJECT_STR "NetBSD Project"
39 #define fw_dev_t dev_t
41 struct fwbus_attach_args {
42 const char *name;
45 struct fw_hwaddr {
46 uint32_t sender_unique_ID_hi;
47 uint32_t sender_unique_ID_lo;
48 uint8_t sender_max_rec;
49 uint8_t sspd;
50 uint16_t sender_unicast_FIFO_hi;
51 uint32_t sender_unicast_FIFO_lo;
55 #define fw_dev2unit(x) minor(x)
56 #define fw_unit2minor(x) (((x) & 0xff) | (((x) << 12) & ~0xfffff))
58 #define fw_timevalcmp(tv1, tv2, op) timercmp((tv1), (tv2), op)
59 #define fw_timevalsub(tv1, tv2) timersub((tv1), (tv2), (tv1))
61 #define fw_get_nameunit(dev) device_xname(dev)
62 #define fw_get_unit(dev) device_unit((dev))
64 #define fw_printf(dev, ...) aprint_normal_dev((dev), __VA_ARGS__)
66 /* atomic macros */
67 /* XXXX: unsafe... */
68 #define fw_atomic_set_int(P, V) (*(u_int *)(P) |= (V))
69 static __inline int
70 fw_atomic_readandclear_int(int *p)
72 int _p = *p;
74 *p = 0;
75 return _p;
78 /* mutex macros */
79 /* XXXX: unsafe... */
80 typedef void *fw_mtx_t;
81 #define fw_mtx_init(mutex, name, type, opts)
82 #define fw_mtx_lock(mutex) (void)(mutex) /* XXXX */
83 #define fw_mtx_unlock(mutex) (void)(mutex) /* XXXX */
84 #define fw_mtx_destroy(mutex)
85 #define fw_mtx_assert(mutex, what)
87 #define fw_msleep(ident, mtx, priority, wmesg, timo) \
88 tsleep((ident), (priority), (wmesg), (timo))
90 /* taskqueue macros */
91 /* XXXX: unsafe... */
92 typedef void (*task_fn_t)(void *context, int pending);
93 typedef struct {
94 STAILQ_ENTRY(task) ta_link; /* link for queue */
95 u_short ta_pending; /* count times queued */
96 u_short ta_priority; /* priority of task in queue */
97 task_fn_t ta_func; /* task handler */
98 void *ta_context; /* argument for handler */
99 } fw_task_t;
100 #define fw_taskqueue_enqueue(queue, task) \
101 (task)->ta_func((task)->ta_context, 0)
102 #define FW_TASK_INIT(task, priority, func, context) \
103 do { \
104 (task)->ta_priority = (priority); \
105 (task)->ta_func = (func); \
106 (task)->ta_context = (context); \
107 } while (/*CONSTCOND*/0)
108 #define fw_taskqueue_create_fast(name, mflags, enqueue, taskqueue) \
109 NULL
110 #define fw_taskqueue_start_threads(taskqueue, n, x, fmt, ...)
112 /* kthread macros */
113 typedef struct proc fw_thread_t;
114 typedef struct lwp *fw_proc_t;
115 #define fw_kthread_create(func, arg, newpp, fmt, ...) \
116 kthread_create(PRI_NONE, 0, NULL, \
117 (func), (arg), (newpp), (fmt), __VA_ARGS__)
118 #define fw_kthread_exit(ecode) kthread_exit((ecode))
120 /* callout macros */
121 #define fw_callout_init(c) callout_init((c), 0)
122 #define fw_callout_reset(c, ticks, func, arg) \
123 callout_reset((c), (ticks), (func), (arg))
124 #define fw_callout_stop(c) callout_stop((c))
126 /* bus_dma macros */
127 #include <sys/malloc.h>
128 #include <sys/bus.h>
129 struct fw_bus_dma_tag {
130 bus_dma_tag_t tag;
131 bus_size_t alignment;
132 bus_size_t boundary;
133 bus_size_t size;
134 int nsegments;
135 bus_size_t maxsegsz;
136 int flags;
138 typedef struct fw_bus_dma_tag *fw_bus_dma_tag_t;
139 typedef int bus_dmasync_op_t;
140 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
141 typedef void
142 bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int);
144 #define fw_bus_dma_tag_create( \
145 p, a, b, la, ha, ffunc, farg, maxsz, \
146 nseg, maxsegsz, f, lfunc, larg, dmat) \
148 _fw_bus_dma_tag_create((p), (a), (b), (la), (ha), \
149 (ffunc), (farg), (maxsz), (nseg), (maxsegsz), (f), (dmat))
151 static __inline int
152 _fw_bus_dma_tag_create(bus_dma_tag_t parent,
153 bus_size_t alignment, bus_size_t boundary,
154 bus_addr_t lowaddr, bus_addr_t highaddr,
155 void *filtfunc, void *filtfuncarg,
156 bus_size_t maxsize, int nsegments, bus_size_t maxsegsz,
157 int flags, fw_bus_dma_tag_t *fwdmat)
159 fw_bus_dma_tag_t tag;
161 tag = malloc(sizeof(struct fw_bus_dma_tag), M_DEVBUF, M_NOWAIT);
162 if (tag == NULL)
163 return ENOMEM;
165 /* XXXX */
166 #define BUS_SPACE_MAXADDR_32BIT 0
167 #define BUS_SPACE_MAXADDR 0
169 tag->tag = parent;
170 tag->alignment = alignment;
171 tag->boundary = boundary;
172 tag->size = maxsize;
173 tag->nsegments = nsegments;
174 tag->maxsegsz = maxsegsz;
175 tag->flags = flags;
177 *fwdmat = tag;
179 return 0;
181 #define fw_bus_dma_tag_destroy(ft) \
182 free(ft, M_DEVBUF)
183 #define fw_bus_dmamap_create(ft, f, mp) \
184 bus_dmamap_create((ft)->tag, (ft)->size,\
185 (ft)->nsegments, (ft)->maxsegsz, (ft)->boundary, (f), (mp))
186 #define fw_bus_dmamap_destroy(ft, m) \
187 bus_dmamap_destroy((ft)->tag, (m))
188 static __inline int
189 fw_bus_dmamap_load(fw_bus_dma_tag_t ft, bus_dmamap_t m,
190 void *b, bus_size_t l, bus_dmamap_callback_t *func, void *a, int f)
192 int lf = f & (BUS_DMA_WAITOK | BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
193 BUS_DMA_READ | BUS_DMA_WRITE |
194 BUS_DMA_BUS1 | BUS_DMA_BUS2 | BUS_DMA_BUS3 | BUS_DMA_BUS4);
195 int err = bus_dmamap_load(ft->tag, m, b, l, NULL, lf);
196 (func)(a, m->dm_segs, m->dm_nsegs, err);
197 return err;
199 static __inline int
200 fw_bus_dmamap_load_mbuf(fw_bus_dma_tag_t ft, bus_dmamap_t m,
201 struct mbuf *b, bus_dmamap_callback2_t *func, void *a, int f)
203 int lf = f & (BUS_DMA_WAITOK | BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
204 BUS_DMA_READ | BUS_DMA_WRITE |
205 BUS_DMA_BUS1 | BUS_DMA_BUS2 | BUS_DMA_BUS3 | BUS_DMA_BUS4);
206 int err = bus_dmamap_load_mbuf(ft->tag, m, b, lf);
207 (func)(a, m->dm_segs, m->dm_nsegs, m->dm_mapsize, err);
208 return err;
210 #define fw_bus_dmamap_unload(ft, m) \
211 bus_dmamap_unload((ft)->tag, (m))
212 #define fw_bus_dmamap_sync(ft, m, op) \
213 bus_dmamap_sync((ft)->tag, (m), 0, (m)->dm_mapsize, (op))
214 static __inline int
215 fw_bus_dmamem_alloc(fw_bus_dma_tag_t ft, void **vp, int f, bus_dmamap_t *mp)
217 bus_dma_segment_t segs;
218 int nsegs, err;
219 int af, mf, cf;
221 af = f & (BUS_DMA_WAITOK | BUS_DMA_NOWAIT | BUS_DMA_STREAMING |
222 BUS_DMA_BUS1 | BUS_DMA_BUS2 | BUS_DMA_BUS3 | BUS_DMA_BUS4);
223 err = bus_dmamem_alloc(ft->tag, ft->size,
224 ft->alignment, ft->boundary, &segs, ft->nsegments, &nsegs, af);
225 if (err) {
226 printf("fw_bus_dmamem_alloc: failed(1)\n");
227 return err;
230 mf = f & (BUS_DMA_WAITOK | BUS_DMA_NOWAIT |
231 BUS_DMA_BUS1 | BUS_DMA_BUS2 | BUS_DMA_BUS3 | BUS_DMA_BUS4 |
232 BUS_DMA_COHERENT | BUS_DMA_NOCACHE);
233 err = bus_dmamem_map(ft->tag,
234 &segs, nsegs, ft->size, (void **)vp, mf);
235 if (err) {
236 printf("fw_bus_dmamem_alloc: failed(2)\n");
237 bus_dmamem_free(ft->tag, &segs, nsegs);
238 return err;
241 if (*mp != NULL)
242 return err;
244 cf = f & (BUS_DMA_WAITOK | BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW |
245 BUS_DMA_BUS1 | BUS_DMA_BUS2 | BUS_DMA_BUS3 | BUS_DMA_BUS4);
246 err = bus_dmamap_create(ft->tag,
247 ft->size, nsegs, ft->maxsegsz, ft->boundary, cf, mp);
248 if (err) {
249 printf("fw_bus_dmamem_alloc: failed(3)\n");
250 bus_dmamem_unmap(ft->tag, (void *)*vp, ft->size);
251 bus_dmamem_free(ft->tag, &segs, nsegs);\
254 return err;
256 #define fw_bus_dmamem_free(ft, v, m) \
257 do { \
258 bus_dmamem_unmap((ft)->tag, (v), (ft)->size); \
259 bus_dmamem_free((ft)->tag, (m)->dm_segs, (m)->dm_nsegs);\
260 bus_dmamap_destroy((ft)->tag, (m)); \
261 } while (/*CONSTCOND*/0)
263 #define fw_config_pending_incr() config_pending_incr()
264 #define fw_config_pending_decr() config_pending_decr()
266 #define splfw() splvm()
267 #define splfwnet() splnet()
268 #define splfwsbp() splbio()
269 #define splsoftvm() splbio()
271 #include <sys/select.h>
273 #define FW_KASSERT(expression, str) \
274 KASSERT(expression)
277 * fw attach macro for NetBSD
279 #define FW_ATTACH(dname) \
280 void \
281 __CONCAT(dname,attach) \
282 (device_t parent, device_t self, void *aux)
283 #define FW_ATTACH_START(dname, sc, fwa) \
284 struct __CONCAT(dname,_softc) *sc = device_private(self); \
285 __unused struct fw_attach_args *fwa = (struct fw_attach_args *)aux
286 #define FW_ATTACH_RETURN(r) return
289 * fw detach macro for NetBSD
291 #define FW_DETACH(dname) \
292 int \
293 __CONCAT(dname,detach)(device_t self, int flags)
294 #define FW_DETACH_START(dname, sc) \
295 struct __CONCAT(dname,_softc) *sc = device_private(self)
298 * fw open macro for NetBSD
300 #define FW_OPEN(dname) \
301 int \
302 __CONCAT(dname,_open)(dev_t _dev, int flags, int fmt, fw_proc_t td)
303 #define FW_OPEN_START \
304 struct firewire_softc *sc, *dev; \
306 sc = dev = device_lookup_private(&ieee1394if_cd, DEV2UNIT(_dev));\
307 if (dev == NULL) \
308 return ENXIO
311 * fw close macro for NetBSD
313 #define FW_CLOSE(dname) \
314 int \
315 __CONCAT(dname,_close)(dev_t _dev, int flags, int fmt, fw_proc_t td)
316 #define FW_CLOSE_START \
317 int unit = DEV2UNIT(_dev); \
318 struct firewire_softc *dev; \
320 dev = device_lookup_private(&ieee1394if_cd, unit); \
321 if (dev == NULL) \
322 return ENXIO
325 * fw read macro for NetBSD
327 #define FW_READ(dname) \
328 int \
329 __CONCAT(dname,_read)(dev_t _dev, struct uio *uio, int ioflag)
330 #define FW_READ_START \
331 int unit = DEV2UNIT(_dev); \
332 struct firewire_softc *dev; \
334 dev = device_lookup_private(&ieee1394if_cd, unit); \
335 if (dev == NULL) \
336 return ENXIO
339 * fw write macro for NetBSD
341 #define FW_WRITE(dname) \
342 int \
343 __CONCAT(dname,_write)(dev_t _dev, struct uio *uio, int ioflag)
344 #define FW_WRITE_START \
345 int unit = DEV2UNIT(_dev); \
346 struct firewire_softc *dev; \
348 dev = device_lookup_private(&ieee1394if_cd, unit); \
349 if (dev == NULL) \
350 return ENXIO
353 * fw ioctl macro for NetBSD
355 #define FW_IOCTL(dname) \
356 int \
357 __CONCAT(dname,_ioctl) \
358 (dev_t _dev, u_long cmd, void *data, int flag, fw_proc_t td)
359 #define FW_IOCTL_START \
360 int unit = DEV2UNIT(_dev); \
361 struct firewire_softc *sc, *dev; \
363 sc = dev = device_lookup_private(&ieee1394if_cd, unit); \
364 if (dev == NULL) \
365 return ENXIO
368 * fw poll macro for NetBSD
370 #define FW_POLL(dname) \
371 int \
372 __CONCAT(dname,_poll)(dev_t _dev, int events, fw_proc_t td)
373 #define FW_POLL_START \
374 int unit = DEV2UNIT(_dev); \
375 struct firewire_softc *dev; \
377 dev = device_lookup_private(&ieee1394if_cd, unit); \
378 if (dev == NULL) \
379 return ENXIO
382 * fw mmap macro for NetBSD
384 #define FW_MMAP(dname) \
385 paddr_t \
386 __CONCAT(dname,_mmap)(dev_t _dev, off_t offset, int nproto)
387 #define FW_MMAP_START \
388 int unit = DEV2UNIT(_dev); \
389 struct firewire_softc *dev; \
391 dev = device_lookup_private(&ieee1394if_cd, unit); \
392 if (dev == NULL) \
393 return ENXIO
396 * fw strategy macro for NetBSD
398 #define FW_STRATEGY_START \
399 dev_t _dev = bp->bio_dev; \
400 int unit = DEV2UNIT(_dev); \
401 struct firewire_softc *sc, *dev; \
403 sc = dev = device_lookup_private(&ieee1394if_cd, unit); \
404 if (dev == NULL) \
405 return
408 * if macro for NetBSD
410 #define IF_DETACH_START(dname, sc) \
411 struct __CONCAT(dname,_softc) *sc = device_private(self)
412 #define IF_IOCTL_START(dname, sc) \
413 struct __CONCAT(dname,_softc) *sc = \
414 ((struct fwip_eth_softc *)ifp->if_softc)->fwip
415 #define IF_INIT(dname) \
416 int \
417 __CONCAT(dname,_init)(struct ifnet *ifp)
418 #define IF_INIT_START(dname, sc, ifp) \
419 struct __CONCAT(dname,_softc) *sc = \
420 ((struct fwip_eth_softc *)(ifp)->if_softc)->fwip
421 #define IF_INIT_RETURN(r) return (r)
422 #define IF_STOP(dname) \
423 void \
424 __CONCAT(dname,_stop)(struct ifnet *ifp, int disable)
425 #define IF_STOP_START(dname, ifp, sc) \
426 struct __CONCAT(dname,_softc) *sc = \
427 ((struct fwip_eth_softc *)(ifp)->if_softc)->fwip
430 * fwohci macro for NetBSD
432 #define FWOHCI_DETACH() \
433 int \
434 fwohci_detach(struct fwohci_softc *sc, int flags)
435 #define FWOHCI_DETACH_START \
436 if (sc->fc.bdev != NULL) \
437 config_detach(sc->fc.bdev, flags)
438 #define FWOHCI_DETACH_END
439 #define FWOHCI_INIT_END \
440 do { \
441 struct fwbus_attach_args faa; \
442 faa.name = "ieee1394if"; \
443 sc->fc.bdev = config_found(sc->fc.dev, &faa, fwohci_print); \
444 } while (/*CONSTCOND*/0)
447 * firewire macro for NetBSD
449 #define FIREWIRE_ATTACH_START \
450 struct firewire_comm *fc = device_private(parent); \
452 aprint_normal(": IEEE1394 bus\n"); \
454 fc->bdev = sc->dev = self; \
455 SLIST_INIT(&sc->devlist)
456 #define FWDEV_DESTROYDEV(sc)
457 #define FIREWIRE_GENERIC_ATTACH \
458 do { \
459 struct fw_attach_args faa; \
460 struct firewire_dev_list *devlist, *elm; \
462 devlist = malloc( \
463 sizeof(struct firewire_dev_list), M_DEVBUF, M_NOWAIT); \
464 if (devlist == NULL) \
465 break; \
467 faa.name = "fwip"; \
468 faa.fc = fc; \
469 faa.fwdev = NULL; \
470 devlist->dev = config_found(sc->dev, &faa, firewire_print); \
471 if (devlist->dev == NULL) { \
472 free(devlist, M_DEVBUF); \
473 break; \
476 if (SLIST_EMPTY(&sc->devlist)) \
477 SLIST_INSERT_HEAD(&sc->devlist, devlist, link); \
478 else { \
479 for (elm = SLIST_FIRST(&sc->devlist); \
480 SLIST_NEXT(elm, link) != NULL; \
481 elm = SLIST_NEXT(elm, link)); \
482 SLIST_INSERT_AFTER(elm, devlist, link); \
484 } while (/*CONSTCOND*/0)
485 #define FIREWIRE_GENERIC_DETACH \
486 do { \
487 struct firewire_dev_list *devlist; \
488 int err; \
490 while ((devlist = SLIST_FIRST(&sc->devlist)) != NULL) { \
491 if ((err = config_detach(devlist->dev, flags)) != 0) \
492 return err; \
493 SLIST_REMOVE( \
494 &sc->devlist, devlist, firewire_dev_list, link); \
495 free(devlist, M_DEVBUF); \
497 } while (/*CONSTCOND*/0)
498 #define FIREWIRE_SBP_ATTACH \
499 do { \
500 struct firewire_softc *sc = device_private(fc->bdev); \
501 struct firewire_dev_list *devlist, *elm; \
502 int locs[IEEE1394IFCF_NLOCS]; \
504 devlist = malloc( \
505 sizeof(struct firewire_dev_list), M_DEVBUF, M_NOWAIT); \
506 if (devlist == NULL) { \
507 printf("memory allocation failed\n"); \
508 break; \
511 locs[IEEE1394IFCF_EUIHI] = fwdev->eui.hi; \
512 locs[IEEE1394IFCF_EUILO] = fwdev->eui.lo; \
514 fwa.fwdev = fwdev; \
515 fwdev->sbp = config_found_sm_loc(sc->dev, "ieee1394if", \
516 locs, &fwa, firewire_print, config_stdsubmatch); \
517 if (fwdev->sbp == NULL) { \
518 free(devlist, M_DEVBUF); \
519 break; \
522 devlist->fwdev = fwdev; \
523 devlist->dev = fwdev->sbp; \
525 if (SLIST_EMPTY(&sc->devlist)) \
526 SLIST_INSERT_HEAD(&sc->devlist, devlist, link); \
527 else { \
528 for (elm = SLIST_FIRST(&sc->devlist); \
529 SLIST_NEXT(elm, link) != NULL; \
530 elm = SLIST_NEXT(elm, link)); \
531 SLIST_INSERT_AFTER(elm, devlist, link); \
533 } while (/*CONSTCOND*/0)
534 #define FIREWIRE_SBP_DETACH \
535 do { \
536 struct firewire_softc *sc = device_private(fc->bdev); \
537 struct firewire_dev_list *devlist; \
539 SLIST_FOREACH(devlist, &sc->devlist, link) { \
540 if (devlist->fwdev != fwdev) \
541 continue; \
542 SLIST_REMOVE( \
543 &sc->devlist, devlist, firewire_dev_list, link); \
544 free(devlist, M_DEVBUF); \
546 if (config_detach(fwdev->sbp, DETACH_FORCE) != 0) \
547 return; \
549 } while (/*CONSTCOND*/0)
550 #define FIREWIRE_CHILDREN_FOREACH_FUNC(func, fdc) \
551 do { \
552 struct firewire_dev_list *devlist; \
553 struct firewire_softc *sc = device_private(fc->bdev); \
555 if (!SLIST_EMPTY(&sc->devlist)) { \
556 SLIST_FOREACH(devlist, &sc->devlist, link) { \
557 (fdc) = device_private(devlist->dev); \
558 if ((fdc)->func != NULL) \
559 (fdc)->func((fdc)); \
562 } while (/*CONSTCOND*/0)
565 * sbp macro for NetBSD
567 #define SBP_ATTACH_START \
568 do { \
569 aprint_normal(": SBP-2/SCSI over IEEE1394\n"); \
571 sbp->fd.dev = self; \
572 } while (/*CONSTCOND*/0)
573 #define SBP_SCSIBUS_ATTACH \
574 do { \
575 struct scsipi_adapter *sc_adapter = &sbp->sc_adapter; \
576 struct scsipi_channel *sc_channel = &sbp->sc_channel; \
577 struct sbp_target *target = &sbp->target; \
579 sc_adapter->adapt_dev = sbp->fd.dev; \
580 sc_adapter->adapt_nchannels = 1; \
581 sc_adapter->adapt_max_periph = 1; \
582 sc_adapter->adapt_request = sbp_scsipi_request; \
583 sc_adapter->adapt_minphys = sbp_minphys; \
584 sc_adapter->adapt_openings = 8; \
585 /*Start with some. Grow as needed.*/\
587 sc_channel->chan_adapter = sc_adapter; \
588 sc_channel->chan_bustype = &scsi_bustype; \
589 sc_channel->chan_defquirks = PQUIRK_ONLYBIG; \
590 sc_channel->chan_channel = 0; \
591 sc_channel->chan_flags = \
592 SCSIPI_CHAN_CANGROW | SCSIPI_CHAN_NOSETTLE; \
594 /* We set nluns 0 now */ \
595 sc_channel->chan_ntargets = 1; \
596 sc_channel->chan_nluns = target->num_lun; \
597 sc_channel->chan_id = 1; \
599 if ((sbp->sc_bus = \
600 config_found(sbp->fd.dev, sc_channel, scsiprint)) == \
601 NULL) { \
602 fw_printf(sbp->fd.dev, "attach failed\n"); \
603 return; \
605 } while (/*CONSTCOND*/0)
606 #define SBP_DEVICE(d) ((d)->periph)
607 #define SBP_DEVICE_FREEZE(d, x) scsipi_periph_freeze((d)->periph, (x));
608 #define SBP_DEVICE_THAW(d, x) \
609 do { \
610 if ((d)->periph) \
611 scsipi_periph_thaw((d)->periph, (x)); \
612 /* XXXX */ \
613 scsipi_channel_thaw(&(d)->target->sbp->sc_channel, 0); \
614 } while (/*CONSTCOND*/0)
615 #define SBP_BUS_FREEZE(b) scsipi_channel_freeze(&(b)->sc_channel, 1)
616 #define SBP_BUS_THAW(b) scsipi_channel_thaw(&(b)->sc_channel, 1)
617 #define SBP_DEVICE_PREATTACH() \
618 do { \
619 if (!sbp->lwp) { \
620 /* create thread */ \
621 if (kthread_create(PRI_NONE, 0, NULL, \
622 sbp_scsipi_scan_target, &sbp->target, \
623 &sbp->lwp, "sbp%d_attach", \
624 device_unit(sbp->fd.dev))) { \
625 fw_printf(sbp->fd.dev, \
626 "unable to create thread"); \
627 panic("fw_kthread_create"); \
630 } while (/*CONSTCOND*/0)
633 * fwip macro for NetBSD
635 #define FWIP_ATTACH_START \
636 device_t dev = self; \
637 struct fw_hwaddr *hwaddr;
638 #define FWIP_ATTACH_SETUP \
639 do { \
640 aprint_normal(": IP over IEEE1394\n"); \
641 fwip->fd.dev = self; \
642 fwip->fw_softc.fwip_ifp = &fwip->fw_softc.fwcom.fc_if; \
643 hwaddr = (struct fw_hwaddr *)&fwip->fw_softc.fwcom.ic_hwaddr; \
644 } while (/*CONSTCOND*/0)
646 #define FWDEV_MAKEDEV(sc)
647 #define FIREWIRE_IFATTACH(ifp, ha) \
648 do { \
649 if_attach((ifp)); \
650 ieee1394_ifattach((ifp), (const struct ieee1394_hwaddr *)(ha));\
651 } while (/*CONSTCOND*/0)
652 #define FIREWIRE_IFDETACH(ifp) \
653 do { \
654 ieee1394_ifdetach(ifp); \
655 if_detach(ifp); \
656 } while (/*CONSTCOND*/0)
657 #define FIREWIRE_BUSRESET(ifp) ieee1394_drain((ifp))
658 #define FIREWIRE_INPUT(ifp, m, src) \
659 ieee1394_input((ifp), (m), (src))
660 #define FWIP_INIT(sc) fwip_init((sc)->fw_softc.fwip_ifp)
661 #define FWIP_STOP(sc) fwip_stop((sc)->fw_softc.fwip_ifp, 1)
662 #define FIREWIRE_IOCTL(ifp, cmd, data) \
663 ieee1394_ioctl((ifp), (cmd), (data))
664 #define IF_INITNAME(ifp, dev, unit) \
665 strlcpy((ifp)->if_xname, device_xname(dev), IFNAMSIZ);
666 #define SET_IFFUNC(ifp, start, ioctl, init, stop) \
667 do { \
668 (ifp)->if_start = (start); \
669 (ifp)->if_ioctl = (ioctl); \
670 (ifp)->if_init = (init); \
671 (ifp)->if_stop = (stop); \
672 } while (/*CONSTCOND*/0)
675 * fwdev macro for NetBSD
677 #define FWDEV_OPEN_START \
678 if (DEV_FWMEM(_dev)) \
679 return fwmem_open(_dev, flags, fmt, td)
680 #define FWDEV_CLOSE_START \
681 if (DEV_FWMEM(_dev)) \
682 return fwmem_close(_dev, flags, fmt, td)
683 #define FWDEV_READ_START \
684 if (DEV_FWMEM(_dev)) \
685 return physio(fw_strategy, NULL, _dev, ioflag, minphys, uio)
686 #define FWDEV_WRITE_START \
687 if (DEV_FWMEM(_dev)) \
688 return physio(fw_strategy, NULL, _dev, ioflag, minphys, uio)
689 #define FWDEV_IOCTL_START \
690 if (DEV_FWMEM(_dev)) \
691 return fwmem_ioctl(_dev, cmd, data, flag, td)
692 #define FWDEV_IOCTL_REDIRECT fc->ioctl(_dev, cmd, data, flag, td)
693 #define FWDEV_POLL_START \
694 if (DEV_FWMEM(_dev)) \
695 return fwmem_poll(_dev, events, td)
696 #define FWDEV_MMAP_START \
697 if (DEV_FWMEM(_dev)) \
698 return fwmem_mmap(_dev, offset, nproto)
699 #define FWDEV_STRATEGY_START \
700 if (DEV_FWMEM(_dev)) { \
701 fwmem_strategy(bp); \
702 return; \
705 #define XS_REQ_INVALID XS_DRIVER_STUFFUP
706 #define XS_SCSI_BUS_RESET XS_RESET
707 #define XS_BDR_SENT XS_RESET
708 #define XS_DEV_NOT_THERE XS_DRIVER_STUFFUP
709 #define XS_CMD_TIMEOUT XS_TIMEOUT
710 #define XS_REQUEUE_REQ XS_REQUEUE
711 #define XS_REQ_CMP XS_NOERROR
712 #define XS_REQ_CMP_ERR XS_DRIVER_STUFFUP
713 #define XS_UA_ABORT XS_DRIVER_STUFFUP
715 typedef struct scsipi_xfer sbp_scsi_xfer;
716 typedef struct scsipi_inquiry_data sbp_scsi_inquiry_data;
718 #define SCSI_XFER_TARGET(x) ((x)->xs_periph->periph_target)
719 #define SCSI_XFER_LUN(x) ((x)->xs_periph->periph_lun)
720 #define SCSI_XFER_ERROR(x) ((x)->error)
721 #define SCSI_XFER_DIR(x) \
722 ((x)->xs_control & (XS_CTL_DATA_IN | XS_CTL_DATA_OUT))
723 #define SCSI_XFER_DATA_IN XS_CTL_DATA_IN
724 #define SCSI_XFER_CALLOUT(x) ((x)->xs_callout)
725 #define SCSI_XFER_TIMEOUT(x) ((x)->timeout)
726 #define SCSI_XFER_OPECODE(x) ((x)->cmd->opcode)
727 #define SCSI_XFER_STATUS(x) ((x)->xs_status)
728 #define SCSI_XFER_EVPD(x) ((x)->cmd->bytes[0] & SI_EVPD)
729 #define SI_EVPD 0x01
730 #define SCSI_XFER_CMDLEN(x) ((x)->cmdlen)
731 #define SCSI_XFER_CMD(x) ((x)->cmd)
732 #define SCSI_XFER_DATALEN(x) ((x)->datalen)
733 #define SCSI_XFER_DATA(x) ((x)->data)
734 #define SCSI_XFER_SENSELEN(x) (0 /* XXXXX */)
735 #define SCSI_SENSE_DATA(x) (&(x)->sense.scsi_sense)
736 #define SCSI_INQUIRY_DATA(x) ((x)->data)
737 #define SCSI_XFER_FUNCCODE(x) XPT_SCSI_IO
738 #define SCSI_XFER_10BCMD_DUMP(x)\
739 ((x)->cmd->opcode), \
740 ((x)->cmd->bytes[0]), \
741 ((x)->cmd->bytes[1]), \
742 ((x)->cmd->bytes[2]), \
743 ((x)->cmd->bytes[3]), \
744 ((x)->cmd->bytes[4]), \
745 ((x)->cmd->bytes[5]), \
746 ((x)->cmd->bytes[6]), \
747 ((x)->cmd->bytes[7]), \
748 ((x)->cmd->bytes[8])
749 #define SCSI_XFER_REQUEST_COMPLETE(x) \
750 ((x)->resid = 0)
751 #define SCSI_TRANSFER_DONE(x) scsipi_done((x))
753 #define NOT_LUN_WILDCARD(l) (1)
754 #define CAM_XFER_FLAGS(x) (0) /* XXX */
755 #define CAM_SCATTER_VALID (0) /* XXX */
756 #define CAM_DATA_PHYS (0) /* XXX */
757 #define XPT_SCSI_IO (1) /* XXX */
759 #ifndef rounddown
760 #define rounddown(x, y) ((x) / (y) * (y))
761 #endif
764 * additional mbuf macros for NetBSD
766 #include <sys/mbuf.h>
767 #define M_TRYWAIT M_WAITOK
769 #define MTAG_FIREWIRE 1394
770 #define MTAG_FIREWIRE_HWADDR 0
771 #define MTAG_FIREWIRE_SENDER_EUID 1
773 #define m_tag_alloc(cookie, type, len, wait) \
774 m_tag_get((type), (len), (wait))
775 #define m_tag_locate(m, cookie, type, t) \
776 m_tag_find((m), (type), (t))
778 /* additional bpf macros */
779 #define bpf_peers_present(if_bpf) (if_bpf)
782 #define CTR0(m, format)
783 #define CTR1(m, format, p1)
785 #define OHCI_CSR_WRITE(sc, reg, val) \
786 bus_space_write_4((sc)->bst, (sc)->bsh, reg, val)
788 #define FILTER_STRAY 0
789 #define FILTER_HANDLED 1
791 #define SSD_CURRENT_ERROR 0x70
792 #define SSD_DEFERRED_ERROR 0x71
794 #define T_RBC T_SIMPLE_DIRECT
796 #define SCSI_STATUS_CHECK_COND SCSI_CHECK
797 #define SCSI_STATUS_BUSY SCSI_BUSY
798 #define SCSI_STATUS_CMD_TERMINATED SCSI_TERMINATED
800 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
802 #define DFLTPHYS (64 * 1024) /* fake */
804 #define kdb_backtrace()
805 #define kdb_active 0
807 #endif
808 #define vm_offset_t void *
809 #endif