FreeBSD kernel CAM code
cam_xpt.c
Go to the documentation of this file.
1/*-
2 * Implementation of the Common Access Method Transport (XPT) layer.
3 *
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 *
6 * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs.
7 * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include "opt_printf.h"
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD$");
36
37#include <sys/param.h>
38#include <sys/bio.h>
39#include <sys/bus.h>
40#include <sys/systm.h>
41#include <sys/types.h>
42#include <sys/malloc.h>
43#include <sys/kernel.h>
44#include <sys/time.h>
45#include <sys/conf.h>
46#include <sys/fcntl.h>
47#include <sys/proc.h>
48#include <sys/sbuf.h>
49#include <sys/smp.h>
50#include <sys/taskqueue.h>
51
52#include <sys/lock.h>
53#include <sys/mutex.h>
54#include <sys/sysctl.h>
55#include <sys/kthread.h>
56
57#include <cam/cam.h>
58#include <cam/cam_ccb.h>
59#include <cam/cam_iosched.h>
60#include <cam/cam_periph.h>
61#include <cam/cam_queue.h>
62#include <cam/cam_sim.h>
63#include <cam/cam_xpt.h>
64#include <cam/cam_xpt_sim.h>
65#include <cam/cam_xpt_periph.h>
67#include <cam/cam_debug.h>
68#include <cam/cam_compat.h>
69
70#include <cam/scsi/scsi_all.h>
72#include <cam/scsi/scsi_pass.h>
73
74#include <machine/stdarg.h> /* for xpt_print below */
75
76#include "opt_cam.h"
77
78/* Wild guess based on not wanting to grow the stack too much */
79#define XPT_PRINT_MAXLEN 512
80#ifdef PRINTF_BUFR_SIZE
81#define XPT_PRINT_LEN PRINTF_BUFR_SIZE
82#else
83#define XPT_PRINT_LEN 128
84#endif
85_Static_assert(XPT_PRINT_LEN <= XPT_PRINT_MAXLEN, "XPT_PRINT_LEN is too large");
86
87/*
88 * This is the maximum number of high powered commands (e.g. start unit)
89 * that can be outstanding at a particular time.
90 */
91#ifndef CAM_MAX_HIGHPOWER
92#define CAM_MAX_HIGHPOWER 4
93#endif
94
95/* Datastructures internal to the xpt layer */
96MALLOC_DEFINE(M_CAMXPT, "CAM XPT", "CAM XPT buffers");
97MALLOC_DEFINE(M_CAMDEV, "CAM DEV", "CAM devices");
98MALLOC_DEFINE(M_CAMCCB, "CAM CCB", "CAM CCBs");
99MALLOC_DEFINE(M_CAMPATH, "CAM path", "CAM paths");
100
101struct xpt_softc {
103
104 /* number of high powered commands that can go through right now */
106 STAILQ_HEAD(highpowerlist, cam_ed) highpowerq;
107 int num_highpower;
108
109 /* queue for handling async rescan requests. */
110 TAILQ_HEAD(, ccb_hdr) ccb_scanq;
111 int buses_to_config;
112 int buses_config_done;
113 int announce_nosbuf;
114
115 /*
116 * Registered buses
117 *
118 * N.B., "busses" is an archaic spelling of "buses". In new code
119 * "buses" is preferred.
120 */
121 TAILQ_HEAD(,cam_eb) xpt_busses;
122 u_int bus_generation;
123
124 int boot_delay;
125 struct callout boot_callout;
126 struct task boot_task;
127 struct root_hold_token xpt_rootmount;
128
129 struct mtx xpt_topo_lock;
130 struct taskqueue *xpt_taskq;
131};
132
133typedef enum {
140 DM_RET_ACTION_MASK = 0xf0
142
143typedef enum {
149
152 void *tr_func;
153 void *tr_arg;
154};
155
156typedef int xpt_busfunc_t (struct cam_eb *bus, void *arg);
157typedef int xpt_targetfunc_t (struct cam_et *target, void *arg);
158typedef int xpt_devicefunc_t (struct cam_ed *device, void *arg);
159typedef int xpt_periphfunc_t (struct cam_periph *periph, void *arg);
160typedef int xpt_pdrvfunc_t (struct periph_driver **pdrv, void *arg);
161
162/* Transport layer configuration information */
163static struct xpt_softc xsoftc;
164
165MTX_SYSINIT(xpt_topo_init, &xsoftc.xpt_topo_lock, "XPT topology lock", MTX_DEF);
166
167SYSCTL_INT(_kern_cam, OID_AUTO, boot_delay, CTLFLAG_RDTUN,
168 &xsoftc.boot_delay, 0, "Bus registration wait time");
169SYSCTL_UINT(_kern_cam, OID_AUTO, xpt_generation, CTLFLAG_RD,
170 &xsoftc.xpt_generation, 0, "CAM peripheral generation count");
171SYSCTL_INT(_kern_cam, OID_AUTO, announce_nosbuf, CTLFLAG_RWTUN,
172 &xsoftc.announce_nosbuf, 0, "Don't use sbuf for announcements");
173
174struct cam_doneq {
175 struct mtx_padalign cam_doneq_mtx;
177 int cam_doneq_sleep;
178};
179
180static struct cam_doneq cam_doneqs[MAXCPU];
181static u_int __read_mostly cam_num_doneqs;
182static struct proc *cam_proc;
183static struct cam_doneq cam_async;
184
185SYSCTL_INT(_kern_cam, OID_AUTO, num_doneqs, CTLFLAG_RDTUN,
186 &cam_num_doneqs, 0, "Number of completion queues/threads");
187
189
191
193{
194 xpt_periph_init, "xpt",
195 TAILQ_HEAD_INITIALIZER(xpt_driver.units), /* generation */ 0,
197};
198
200
201static d_open_t xptopen;
202static d_close_t xptclose;
203static d_ioctl_t xptioctl;
204static d_ioctl_t xptdoioctl;
205
206static struct cdevsw xpt_cdevsw = {
207 .d_version = D_VERSION,
208 .d_flags = 0,
209 .d_open = xptopen,
210 .d_close = xptclose,
211 .d_ioctl = xptioctl,
212 .d_name = "xpt",
213};
214
215/* Storage for debugging datastructures */
217u_int32_t __read_mostly cam_dflags = CAM_DEBUG_FLAGS;
218SYSCTL_UINT(_kern_cam, OID_AUTO, dflags, CTLFLAG_RWTUN,
219 &cam_dflags, 0, "Enabled debug flags");
221SYSCTL_UINT(_kern_cam, OID_AUTO, debug_delay, CTLFLAG_RWTUN,
222 &cam_debug_delay, 0, "Delay in us after each debug message");
223
224/* Our boot-time initialization hook */
225static int cam_module_event_handler(module_t, int /*modeventtype_t*/, void *);
226
227static moduledata_t cam_moduledata = {
228 "cam",
230 NULL
231};
232
233static int xpt_init(void *);
234
235DECLARE_MODULE(cam, cam_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND);
237
238static void xpt_async_bcast(struct async_list *async_head,
239 u_int32_t async_code,
240 struct cam_path *path,
241 void *async_arg);
242static path_id_t xptnextfreepathid(void);
243static path_id_t xptpathid(const char *sim_name, int sim_unit, int sim_bus);
244static union ccb *xpt_get_ccb(struct cam_periph *periph);
245static union ccb *xpt_get_ccb_nowait(struct cam_periph *periph);
246static void xpt_run_allocq(struct cam_periph *periph, int sleep);
247static void xpt_run_allocq_task(void *context, int pending);
248static void xpt_run_devq(struct cam_devq *devq);
249static callout_func_t xpt_release_devq_timeout;
250static void xpt_acquire_bus(struct cam_eb *bus);
251static void xpt_release_bus(struct cam_eb *bus);
252static uint32_t xpt_freeze_devq_device(struct cam_ed *dev, u_int count);
253static int xpt_release_devq_device(struct cam_ed *dev, u_int count,
254 int run_queue);
255static struct cam_et*
257static void xpt_acquire_target(struct cam_et *target);
258static void xpt_release_target(struct cam_et *target);
259static struct cam_eb*
261static struct cam_et*
263static struct cam_ed*
265static void xpt_config(void *arg);
266static void xpt_hold_boot_locked(void);
267static int xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,
268 u_int32_t new_priority);
270static void xptaction(struct cam_sim *sim, union ccb *work_ccb);
271static void xptpoll(struct cam_sim *sim);
272static void camisr_runqueue(void);
273static void xpt_done_process(struct ccb_hdr *ccb_h);
274static void xpt_done_td(void *);
275static void xpt_async_td(void *);
276static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns,
277 u_int num_patterns, struct cam_eb *bus);
278static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns,
279 u_int num_patterns,
280 struct cam_ed *device);
281static dev_match_ret xptperiphmatch(struct dev_match_pattern *patterns,
282 u_int num_patterns,
283 struct cam_periph *periph);
290static int xptedtmatch(struct ccb_dev_match *cdm);
291static int xptperiphlistmatch(struct ccb_dev_match *cdm);
292static int xptbustraverse(struct cam_eb *start_bus,
293 xpt_busfunc_t *tr_func, void *arg);
294static int xpttargettraverse(struct cam_eb *bus,
295 struct cam_et *start_target,
296 xpt_targetfunc_t *tr_func, void *arg);
297static int xptdevicetraverse(struct cam_et *target,
298 struct cam_ed *start_device,
299 xpt_devicefunc_t *tr_func, void *arg);
300static int xptperiphtraverse(struct cam_ed *device,
301 struct cam_periph *start_periph,
302 xpt_periphfunc_t *tr_func, void *arg);
303static int xptpdrvtraverse(struct periph_driver **start_pdrv,
304 xpt_pdrvfunc_t *tr_func, void *arg);
305static int xptpdperiphtraverse(struct periph_driver **pdrv,
306 struct cam_periph *start_periph,
307 xpt_periphfunc_t *tr_func,
308 void *arg);
313static void xpt_finishconfig_task(void *context, int pending);
314static void xpt_dev_async_default(u_int32_t async_code,
315 struct cam_eb *bus,
316 struct cam_et *target,
317 struct cam_ed *device,
318 void *async_arg);
319static struct cam_ed * xpt_alloc_device_default(struct cam_eb *bus,
320 struct cam_et *target,
324static cam_status xptregister(struct cam_periph *periph,
325 void *arg);
326
327static __inline int
328xpt_schedule_devq(struct cam_devq *devq, struct cam_ed *dev)
329{
330 int retval;
331
332 mtx_assert(&devq->send_mtx, MA_OWNED);
333 if ((dev->ccbq.queue.entries > 0) &&
334 (dev->ccbq.dev_openings > 0) &&
335 (dev->ccbq.queue.qfrozen_cnt == 0)) {
336 /*
337 * The priority of a device waiting for controller
338 * resources is that of the highest priority CCB
339 * enqueued.
340 */
341 retval =
343 &dev->devq_entry,
344 CAMQ_GET_PRIO(&dev->ccbq.queue));
345 } else {
346 retval = 0;
347 }
348 return (retval);
349}
350
351static __inline int
353{
354 return (device->devq_entry.index != CAM_UNQUEUED_INDEX);
355}
356
357static void
358xpt_periph_init(void)
359{
360 make_dev(&xpt_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600, "xpt0");
361}
362
363static int
364xptopen(struct cdev *dev, int flags, int fmt, struct thread *td)
365{
366
367 /*
368 * Only allow read-write access.
369 */
370 if (((flags & FWRITE) == 0) || ((flags & FREAD) == 0))
371 return(EPERM);
372
373 /*
374 * We don't allow nonblocking access.
375 */
376 if ((flags & O_NONBLOCK) != 0) {
377 printf("%s: can't do nonblocking access\n", devtoname(dev));
378 return(ENODEV);
379 }
380
381 return(0);
382}
383
384static int
385xptclose(struct cdev *dev, int flag, int fmt, struct thread *td)
386{
387
388 return(0);
389}
390
391/*
392 * Don't automatically grab the xpt softc lock here even though this is going
393 * through the xpt device. The xpt device is really just a back door for
394 * accessing other devices and SIMs, so the right thing to do is to grab
395 * the appropriate SIM lock once the bus/SIM is located.
396 */
397static int
398xptioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
399{
400 int error;
401
402 if ((error = xptdoioctl(dev, cmd, addr, flag, td)) == ENOTTY) {
403 error = cam_compat_ioctl(dev, cmd, addr, flag, td, xptdoioctl);
404 }
405 return (error);
406}
407
408static int
409xptdoioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
410{
411 int error;
412
413 error = 0;
414
415 switch(cmd) {
416 /*
417 * For the transport layer CAMIOCOMMAND ioctl, we really only want
418 * to accept CCB types that don't quite make sense to send through a
419 * passthrough driver. XPT_PATH_INQ is an exception to this, as stated
420 * in the CAM spec.
421 */
422 case CAMIOCOMMAND: {
423 union ccb *ccb;
424 union ccb *inccb;
425 struct cam_eb *bus;
426
427 inccb = (union ccb *)addr;
428#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
429 if (inccb->ccb_h.func_code == XPT_SCSI_IO)
430 inccb->csio.bio = NULL;
431#endif
432
433 if (inccb->ccb_h.flags & CAM_UNLOCKED)
434 return (EINVAL);
435
436 bus = xpt_find_bus(inccb->ccb_h.path_id);
437 if (bus == NULL)
438 return (EINVAL);
439
440 switch (inccb->ccb_h.func_code) {
441 case XPT_SCAN_BUS:
442 case XPT_RESET_BUS:
443 if (inccb->ccb_h.target_id != CAM_TARGET_WILDCARD ||
445 xpt_release_bus(bus);
446 return (EINVAL);
447 }
448 break;
449 case XPT_SCAN_TGT:
450 if (inccb->ccb_h.target_id == CAM_TARGET_WILDCARD ||
452 xpt_release_bus(bus);
453 return (EINVAL);
454 }
455 break;
456 default:
457 break;
458 }
459
460 switch(inccb->ccb_h.func_code) {
461 case XPT_SCAN_BUS:
462 case XPT_RESET_BUS:
463 case XPT_PATH_INQ:
464 case XPT_ENG_INQ:
465 case XPT_SCAN_LUN:
466 case XPT_SCAN_TGT:
467
468 ccb = xpt_alloc_ccb();
469
470 /*
471 * Create a path using the bus, target, and lun the
472 * user passed in.
473 */
474 if (xpt_create_path(&ccb->ccb_h.path, NULL,
475 inccb->ccb_h.path_id,
476 inccb->ccb_h.target_id,
477 inccb->ccb_h.target_lun) !=
479 error = EINVAL;
481 break;
482 }
483 /* Ensure all of our fields are correct */
485 inccb->ccb_h.pinfo.priority);
486 xpt_merge_ccb(ccb, inccb);
488 cam_periph_runccb(ccb, NULL, 0, 0, NULL);
490 bcopy(ccb, inccb, sizeof(union ccb));
493 break;
494
495 case XPT_DEBUG: {
496 union ccb ccb;
497
498 /*
499 * This is an immediate CCB, so it's okay to
500 * allocate it on the stack.
501 */
502 memset(&ccb, 0, sizeof(ccb));
503
504 /*
505 * Create a path using the bus, target, and lun the
506 * user passed in.
507 */
508 if (xpt_create_path(&ccb.ccb_h.path, NULL,
509 inccb->ccb_h.path_id,
510 inccb->ccb_h.target_id,
511 inccb->ccb_h.target_lun) !=
513 error = EINVAL;
514 break;
515 }
516 /* Ensure all of our fields are correct */
518 inccb->ccb_h.pinfo.priority);
519 xpt_merge_ccb(&ccb, inccb);
520 xpt_action(&ccb);
521 bcopy(&ccb, inccb, sizeof(union ccb));
523 break;
524 }
525 case XPT_DEV_MATCH: {
526 struct cam_periph_map_info mapinfo;
527 struct cam_path *old_path;
528
529 /*
530 * We can't deal with physical addresses for this
531 * type of transaction.
532 */
533 if ((inccb->ccb_h.flags & CAM_DATA_MASK) !=
535 error = EINVAL;
536 break;
537 }
538
539 /*
540 * Save this in case the caller had it set to
541 * something in particular.
542 */
543 old_path = inccb->ccb_h.path;
544
545 /*
546 * We really don't need a path for the matching
547 * code. The path is needed because of the
548 * debugging statements in xpt_action(). They
549 * assume that the CCB has a valid path.
550 */
551 inccb->ccb_h.path = xpt_periph->path;
552
553 bzero(&mapinfo, sizeof(mapinfo));
554
555 /*
556 * Map the pattern and match buffers into kernel
557 * virtual address space.
558 */
559 error = cam_periph_mapmem(inccb, &mapinfo, maxphys);
560
561 if (error) {
562 inccb->ccb_h.path = old_path;
563 break;
564 }
565
566 /*
567 * This is an immediate CCB, we can send it on directly.
568 */
569 xpt_action(inccb);
570
571 /*
572 * Map the buffers back into user space.
573 */
574 cam_periph_unmapmem(inccb, &mapinfo);
575
576 inccb->ccb_h.path = old_path;
577
578 error = 0;
579 break;
580 }
581 default:
582 error = ENOTSUP;
583 break;
584 }
586 break;
587 }
588 /*
589 * This is the getpassthru ioctl. It takes a XPT_GDEVLIST ccb as input,
590 * with the periphal driver name and unit name filled in. The other
591 * fields don't really matter as input. The passthrough driver name
592 * ("pass"), and unit number are passed back in the ccb. The current
593 * device generation number, and the index into the device peripheral
594 * driver list, and the status are also passed back. Note that
595 * since we do everything in one pass, unlike the XPT_GDEVLIST ccb,
596 * we never return a status of CAM_GDEVLIST_LIST_CHANGED. It is
597 * (or rather should be) impossible for the device peripheral driver
598 * list to change since we look at the whole thing in one pass, and
599 * we do it with lock protection.
600 *
601 */
602 case CAMGETPASSTHRU: {
603 union ccb *ccb;
604 struct cam_periph *periph;
605 struct periph_driver **p_drv;
606 char *name;
607 u_int unit;
608 int base_periph_found;
609
610 ccb = (union ccb *)addr;
611 unit = ccb->cgdl.unit_number;
612 name = ccb->cgdl.periph_name;
613 base_periph_found = 0;
614#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
616 ccb->csio.bio = NULL;
617#endif
618
619 /*
620 * Sanity check -- make sure we don't get a null peripheral
621 * driver name.
622 */
623 if (*ccb->cgdl.periph_name == '\0') {
624 error = EINVAL;
625 break;
626 }
627
628 /* Keep the list from changing while we traverse it */
630
631 /* first find our driver in the list of drivers */
632 for (p_drv = periph_drivers; *p_drv != NULL; p_drv++)
633 if (strcmp((*p_drv)->driver_name, name) == 0)
634 break;
635
636 if (*p_drv == NULL) {
640 *ccb->cgdl.periph_name = '\0';
641 ccb->cgdl.unit_number = 0;
642 error = ENOENT;
643 break;
644 }
645
646 /*
647 * Run through every peripheral instance of this driver
648 * and check to see whether it matches the unit passed
649 * in by the user. If it does, get out of the loops and
650 * find the passthrough driver associated with that
651 * peripheral driver.
652 */
653 for (periph = TAILQ_FIRST(&(*p_drv)->units); periph != NULL;
654 periph = TAILQ_NEXT(periph, unit_links)) {
655 if (periph->unit_number == unit)
656 break;
657 }
658 /*
659 * If we found the peripheral driver that the user passed
660 * in, go through all of the peripheral drivers for that
661 * particular device and look for a passthrough driver.
662 */
663 if (periph != NULL) {
664 struct cam_ed *device;
665 int i;
666
667 base_periph_found = 1;
668 device = periph->path->device;
669 for (i = 0, periph = SLIST_FIRST(&device->periphs);
670 periph != NULL;
671 periph = SLIST_NEXT(periph, periph_links), i++) {
672 /*
673 * Check to see whether we have a
674 * passthrough device or not.
675 */
676 if (strcmp(periph->periph_name, "pass") == 0) {
677 /*
678 * Fill in the getdevlist fields.
679 */
680 strlcpy(ccb->cgdl.periph_name,
681 periph->periph_name,
682 sizeof(ccb->cgdl.periph_name));
684 periph->unit_number;
685 if (SLIST_NEXT(periph, periph_links))
686 ccb->cgdl.status =
688 else
689 ccb->cgdl.status =
692 device->generation;
693 ccb->cgdl.index = i;
694 /*
695 * Fill in some CCB header fields
696 * that the user may want.
697 */
698 ccb->ccb_h.path_id =
699 periph->path->bus->path_id;
701 periph->path->target->target_id;
703 periph->path->device->lun_id;
705 break;
706 }
707 }
708 }
709
710 /*
711 * If the periph is null here, one of two things has
712 * happened. The first possibility is that we couldn't
713 * find the unit number of the particular peripheral driver
714 * that the user is asking about. e.g. the user asks for
715 * the passthrough driver for "da11". We find the list of
716 * "da" peripherals all right, but there is no unit 11.
717 * The other possibility is that we went through the list
718 * of peripheral drivers attached to the device structure,
719 * but didn't find one with the name "pass". Either way,
720 * we return ENOENT, since we couldn't find something.
721 */
722 if (periph == NULL) {
725 *ccb->cgdl.periph_name = '\0';
726 ccb->cgdl.unit_number = 0;
727 error = ENOENT;
728 /*
729 * It is unfortunate that this is even necessary,
730 * but there are many, many clueless users out there.
731 * If this is true, the user is looking for the
732 * passthrough driver, but doesn't have one in his
733 * kernel.
734 */
735 if (base_periph_found == 1) {
736 printf("xptioctl: pass driver is not in the "
737 "kernel\n");
738 printf("xptioctl: put \"device pass\" in "
739 "your kernel config file\n");
740 }
741 }
743 break;
744 }
745 default:
746 error = ENOTTY;
747 break;
748 }
749
750 return(error);
751}
752
753static int
754cam_module_event_handler(module_t mod, int what, void *arg)
755{
756 int error;
757
758 switch (what) {
759 case MOD_LOAD:
760 if ((error = xpt_init(NULL)) != 0)
761 return (error);
762 break;
763 case MOD_UNLOAD:
764 return EBUSY;
765 default:
766 return EOPNOTSUPP;
767 }
768
769 return 0;
770}
771
772static struct xpt_proto *
774{
775 struct xpt_proto **pp;
776
777 SET_FOREACH(pp, cam_xpt_proto_set) {
778 if ((*pp)->proto == proto)
779 return *pp;
780 }
781
782 return NULL;
783}
784
785static void
786xpt_rescan_done(struct cam_periph *periph, union ccb *done_ccb)
787{
788
789 if (done_ccb->ccb_h.ppriv_ptr1 == NULL) {
790 xpt_free_path(done_ccb->ccb_h.path);
791 xpt_free_ccb(done_ccb);
792 } else {
793 done_ccb->ccb_h.cbfcnp = done_ccb->ccb_h.ppriv_ptr1;
794 (*done_ccb->ccb_h.cbfcnp)(periph, done_ccb);
795 }
797}
798
799/* thread to handle bus rescans */
800static void
802{
803 union ccb *ccb;
804 struct mtx *mtx;
805 struct cam_ed *device;
806
808 for (;;) {
809 if (TAILQ_EMPTY(&xsoftc.ccb_scanq))
810 msleep(&xsoftc.ccb_scanq, &xsoftc.xpt_topo_lock, PRIBIO,
811 "-", 0);
812 if ((ccb = (union ccb *)TAILQ_FIRST(&xsoftc.ccb_scanq)) != NULL) {
813 TAILQ_REMOVE(&xsoftc.ccb_scanq, &ccb->ccb_h, sim_links.tqe);
815
816 /*
817 * We need to lock the device's mutex which we use as
818 * the path mutex. We can't do it directly because the
819 * cam_path in the ccb may wind up going away because
820 * the path lock may be dropped and the path retired in
821 * the completion callback. We do this directly to keep
822 * the reference counts in cam_path sane. We also have
823 * to copy the device pointer because ccb_h.path may
824 * be freed in the callback.
825 */
826 mtx = xpt_path_mtx(ccb->ccb_h.path);
827 device = ccb->ccb_h.path->device;
828 xpt_acquire_device(device);
829 mtx_lock(mtx);
831 mtx_unlock(mtx);
832 xpt_release_device(device);
833
835 }
836 }
837}
838
839void
841{
842 struct ccb_hdr *hdr;
843
844 /* Prepare request */
854 else {
855 xpt_print(ccb->ccb_h.path, "illegal scan path\n");
858 return;
859 }
861 ("xpt_rescan: func %#x %s\n", ccb->ccb_h.func_code,
863
864 ccb->ccb_h.ppriv_ptr1 = ccb->ccb_h.cbfcnp;
867 /* Don't make duplicate entries for the same paths. */
869 if (ccb->ccb_h.ppriv_ptr1 == NULL) {
870 TAILQ_FOREACH(hdr, &xsoftc.ccb_scanq, sim_links.tqe) {
871 if (xpt_path_comp(hdr->path, ccb->ccb_h.path) == 0) {
872 wakeup(&xsoftc.ccb_scanq);
874 xpt_print(ccb->ccb_h.path, "rescan already queued\n");
877 return;
878 }
879 }
880 }
881 TAILQ_INSERT_TAIL(&xsoftc.ccb_scanq, &ccb->ccb_h, sim_links.tqe);
883 wakeup(&xsoftc.ccb_scanq);
885}
886
887/* Functions accessed by the peripheral drivers */
888static int
889xpt_init(void *dummy)
890{
891 struct cam_sim *xpt_sim;
892 struct cam_path *path;
893 struct cam_devq *devq;
894 cam_status status;
895 int error, i;
896
897 TAILQ_INIT(&xsoftc.xpt_busses);
898 TAILQ_INIT(&xsoftc.ccb_scanq);
899 STAILQ_INIT(&xsoftc.highpowerq);
900 xsoftc.num_highpower = CAM_MAX_HIGHPOWER;
901
902 mtx_init(&xsoftc.xpt_highpower_lock, "XPT highpower lock", NULL, MTX_DEF);
903 xsoftc.xpt_taskq = taskqueue_create("CAM XPT task", M_WAITOK,
904 taskqueue_thread_enqueue, /*context*/&xsoftc.xpt_taskq);
905
906#ifdef CAM_BOOT_DELAY
907 /*
908 * Override this value at compile time to assist our users
909 * who don't use loader to boot a kernel.
910 */
911 xsoftc.boot_delay = CAM_BOOT_DELAY;
912#endif
913
914 /*
915 * The xpt layer is, itself, the equivalent of a SIM.
916 * Allow 16 ccbs in the ccb pool for it. This should
917 * give decent parallelism when we probe buses and
918 * perform other XPT functions.
919 */
920 devq = cam_simq_alloc(16);
921 xpt_sim = cam_sim_alloc(xptaction,
922 xptpoll,
923 "xpt",
924 /*softc*/NULL,
925 /*unit*/0,
926 /*mtx*/NULL,
927 /*max_dev_transactions*/0,
928 /*max_tagged_dev_transactions*/0,
929 devq);
930 if (xpt_sim == NULL)
931 return (ENOMEM);
932
933 if ((error = xpt_bus_register(xpt_sim, NULL, 0)) != CAM_SUCCESS) {
934 printf("xpt_init: xpt_bus_register failed with errno %d,"
935 " failing attach\n", error);
936 return (EINVAL);
937 }
938
939 /*
940 * Looking at the XPT from the SIM layer, the XPT is
941 * the equivalent of a peripheral driver. Allocate
942 * a peripheral driver entry for us.
943 */
944 if ((status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
947 printf("xpt_init: xpt_create_path failed with status %#x,"
948 " failing attach\n", status);
949 return (EINVAL);
950 }
951 xpt_path_lock(path);
952 cam_periph_alloc(xptregister, NULL, NULL, NULL, "xpt", CAM_PERIPH_BIO,
953 path, NULL, 0, xpt_sim);
954 xpt_path_unlock(path);
955 xpt_free_path(path);
956
957 if (cam_num_doneqs < 1)
958 cam_num_doneqs = 1 + mp_ncpus / 6;
959 else if (cam_num_doneqs > MAXCPU)
960 cam_num_doneqs = MAXCPU;
961 for (i = 0; i < cam_num_doneqs; i++) {
962 mtx_init(&cam_doneqs[i].cam_doneq_mtx, "CAM doneq", NULL,
963 MTX_DEF);
964 STAILQ_INIT(&cam_doneqs[i].cam_doneq);
965 error = kproc_kthread_add(xpt_done_td, &cam_doneqs[i],
966 &cam_proc, NULL, 0, 0, "cam", "doneq%d", i);
967 if (error != 0) {
968 cam_num_doneqs = i;
969 break;
970 }
971 }
972 if (cam_num_doneqs < 1) {
973 printf("xpt_init: Cannot init completion queues "
974 "- failing attach\n");
975 return (ENOMEM);
976 }
977
978 mtx_init(&cam_async.cam_doneq_mtx, "CAM async", NULL, MTX_DEF);
979 STAILQ_INIT(&cam_async.cam_doneq);
980 if (kproc_kthread_add(xpt_async_td, &cam_async,
981 &cam_proc, NULL, 0, 0, "cam", "async") != 0) {
982 printf("xpt_init: Cannot init async thread "
983 "- failing attach\n");
984 return (ENOMEM);
985 }
986
987 /*
988 * Register a callback for when interrupts are enabled.
989 */
990 config_intrhook_oneshot(xpt_config, NULL);
991
992 return (0);
993}
994
995static cam_status
996xptregister(struct cam_periph *periph, void *arg)
997{
998 struct cam_sim *xpt_sim;
999
1000 if (periph == NULL) {
1001 printf("xptregister: periph was NULL!!\n");
1002 return(CAM_REQ_CMP_ERR);
1003 }
1004
1005 xpt_sim = (struct cam_sim *)arg;
1006 xpt_sim->softc = periph;
1007 xpt_periph = periph;
1008 periph->softc = NULL;
1009
1010 return(CAM_REQ_CMP);
1011}
1012
1013int32_t
1015{
1016 struct cam_ed *device;
1017 int32_t status;
1018
1019 TASK_INIT(&periph->periph_run_task, 0, xpt_run_allocq_task, periph);
1020 device = periph->path->device;
1021 status = CAM_REQ_CMP;
1022 if (device != NULL) {
1023 mtx_lock(&device->target->bus->eb_mtx);
1024 device->generation++;
1025 SLIST_INSERT_HEAD(&device->periphs, periph, periph_links);
1026 mtx_unlock(&device->target->bus->eb_mtx);
1027 atomic_add_32(&xsoftc.xpt_generation, 1);
1028 }
1029
1030 return (status);
1031}
1032
1033void
1035{
1036 struct cam_ed *device;
1037
1038 device = periph->path->device;
1039 if (device != NULL) {
1040 mtx_lock(&device->target->bus->eb_mtx);
1041 device->generation++;
1042 SLIST_REMOVE(&device->periphs, periph, cam_periph, periph_links);
1043 mtx_unlock(&device->target->bus->eb_mtx);
1044 atomic_add_32(&xsoftc.xpt_generation, 1);
1045 }
1046}
1047
1048void
1049xpt_announce_periph(struct cam_periph *periph, char *announce_string)
1050{
1051 struct cam_path *path = periph->path;
1052 struct xpt_proto *proto;
1053
1054 cam_periph_assert(periph, MA_OWNED);
1055 periph->flags |= CAM_PERIPH_ANNOUNCED;
1056
1057 printf("%s%d at %s%d bus %d scbus%d target %d lun %jx\n",
1058 periph->periph_name, periph->unit_number,
1059 path->bus->sim->sim_name,
1060 path->bus->sim->unit_number,
1061 path->bus->sim->bus_id,
1062 path->bus->path_id,
1063 path->target->target_id,
1064 (uintmax_t)path->device->lun_id);
1065 printf("%s%d: ", periph->periph_name, periph->unit_number);
1067 if (proto)
1068 proto->ops->announce(path->device);
1069 else
1070 printf("%s%d: Unknown protocol device %d\n",
1071 periph->periph_name, periph->unit_number,
1072 path->device->protocol);
1073 if (path->device->serial_num_len > 0) {
1074 /* Don't wrap the screen - print only the first 60 chars */
1075 printf("%s%d: Serial Number %.60s\n", periph->periph_name,
1076 periph->unit_number, path->device->serial_num);
1077 }
1078 /* Announce transport details. */
1079 path->bus->xport->ops->announce(periph);
1080 /* Announce command queueing. */
1081 if (path->device->inq_flags & SID_CmdQue
1082 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
1083 printf("%s%d: Command Queueing enabled\n",
1084 periph->periph_name, periph->unit_number);
1085 }
1086 /* Announce caller's details if they've passed in. */
1087 if (announce_string != NULL)
1088 printf("%s%d: %s\n", periph->periph_name,
1089 periph->unit_number, announce_string);
1090}
1091
1092void
1093xpt_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb,
1094 char *announce_string)
1095{
1096 struct cam_path *path = periph->path;
1097 struct xpt_proto *proto;
1098
1099 cam_periph_assert(periph, MA_OWNED);
1100 periph->flags |= CAM_PERIPH_ANNOUNCED;
1101
1102 /* Fall back to the non-sbuf method if necessary */
1103 if (xsoftc.announce_nosbuf != 0) {
1104 xpt_announce_periph(periph, announce_string);
1105 return;
1106 }
1108 if (((proto != NULL) && (proto->ops->announce_sbuf == NULL)) ||
1109 (path->bus->xport->ops->announce_sbuf == NULL)) {
1110 xpt_announce_periph(periph, announce_string);
1111 return;
1112 }
1113
1114 sbuf_printf(sb, "%s%d at %s%d bus %d scbus%d target %d lun %jx\n",
1115 periph->periph_name, periph->unit_number,
1116 path->bus->sim->sim_name,
1117 path->bus->sim->unit_number,
1118 path->bus->sim->bus_id,
1119 path->bus->path_id,
1120 path->target->target_id,
1121 (uintmax_t)path->device->lun_id);
1122 sbuf_printf(sb, "%s%d: ", periph->periph_name, periph->unit_number);
1123
1124 if (proto)
1125 proto->ops->announce_sbuf(path->device, sb);
1126 else
1127 sbuf_printf(sb, "%s%d: Unknown protocol device %d\n",
1128 periph->periph_name, periph->unit_number,
1129 path->device->protocol);
1130 if (path->device->serial_num_len > 0) {
1131 /* Don't wrap the screen - print only the first 60 chars */
1132 sbuf_printf(sb, "%s%d: Serial Number %.60s\n",
1133 periph->periph_name, periph->unit_number,
1134 path->device->serial_num);
1135 }
1136 /* Announce transport details. */
1137 path->bus->xport->ops->announce_sbuf(periph, sb);
1138 /* Announce command queueing. */
1139 if (path->device->inq_flags & SID_CmdQue
1140 || path->device->flags & CAM_DEV_TAG_AFTER_COUNT) {
1141 sbuf_printf(sb, "%s%d: Command Queueing enabled\n",
1142 periph->periph_name, periph->unit_number);
1143 }
1144 /* Announce caller's details if they've passed in. */
1145 if (announce_string != NULL)
1146 sbuf_printf(sb, "%s%d: %s\n", periph->periph_name,
1147 periph->unit_number, announce_string);
1148}
1149
1150void
1151xpt_announce_quirks(struct cam_periph *periph, int quirks, char *bit_string)
1152{
1153 if (quirks != 0) {
1154 printf("%s%d: quirks=0x%b\n", periph->periph_name,
1155 periph->unit_number, quirks, bit_string);
1156 }
1157}
1158
1159void
1160xpt_announce_quirks_sbuf(struct cam_periph *periph, struct sbuf *sb,
1161 int quirks, char *bit_string)
1162{
1163 if (xsoftc.announce_nosbuf != 0) {
1164 xpt_announce_quirks(periph, quirks, bit_string);
1165 return;
1166 }
1167
1168 if (quirks != 0) {
1169 sbuf_printf(sb, "%s%d: quirks=0x%b\n", periph->periph_name,
1170 periph->unit_number, quirks, bit_string);
1171 }
1172}
1173
1174void
1176{
1177 struct cam_path *path = periph->path;
1178 struct xpt_proto *proto;
1179
1180 cam_periph_assert(periph, MA_OWNED);
1181 printf("%s%d at %s%d bus %d scbus%d target %d lun %jx\n",
1182 periph->periph_name, periph->unit_number,
1183 path->bus->sim->sim_name,
1184 path->bus->sim->unit_number,
1185 path->bus->sim->bus_id,
1186 path->bus->path_id,
1187 path->target->target_id,
1188 (uintmax_t)path->device->lun_id);
1189 printf("%s%d: ", periph->periph_name, periph->unit_number);
1191 if (proto)
1192 proto->ops->denounce(path->device);
1193 else
1194 printf("%s%d: Unknown protocol device %d\n",
1195 periph->periph_name, periph->unit_number,
1196 path->device->protocol);
1197 if (path->device->serial_num_len > 0)
1198 printf(" s/n %.60s", path->device->serial_num);
1199 printf(" detached\n");
1200}
1201
1202void
1203xpt_denounce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
1204{
1205 struct cam_path *path = periph->path;
1206 struct xpt_proto *proto;
1207
1208 cam_periph_assert(periph, MA_OWNED);
1209
1210 /* Fall back to the non-sbuf method if necessary */
1211 if (xsoftc.announce_nosbuf != 0) {
1212 xpt_denounce_periph(periph);
1213 return;
1214 }
1216 if ((proto != NULL) && (proto->ops->denounce_sbuf == NULL)) {
1217 xpt_denounce_periph(periph);
1218 return;
1219 }
1220
1221 sbuf_printf(sb, "%s%d at %s%d bus %d scbus%d target %d lun %jx\n",
1222 periph->periph_name, periph->unit_number,
1223 path->bus->sim->sim_name,
1224 path->bus->sim->unit_number,
1225 path->bus->sim->bus_id,
1226 path->bus->path_id,
1227 path->target->target_id,
1228 (uintmax_t)path->device->lun_id);
1229 sbuf_printf(sb, "%s%d: ", periph->periph_name, periph->unit_number);
1230
1231 if (proto)
1232 proto->ops->denounce_sbuf(path->device, sb);
1233 else
1234 sbuf_printf(sb, "%s%d: Unknown protocol device %d\n",
1235 periph->periph_name, periph->unit_number,
1236 path->device->protocol);
1237 if (path->device->serial_num_len > 0)
1238 sbuf_printf(sb, " s/n %.60s", path->device->serial_num);
1239 sbuf_printf(sb, " detached\n");
1240}
1241
1242int
1243xpt_getattr(char *buf, size_t len, const char *attr, struct cam_path *path)
1244{
1245 int ret = -1, l, o;
1246 struct ccb_dev_advinfo cdai;
1247 struct scsi_vpd_device_id *did;
1248 struct scsi_vpd_id_descriptor *idd;
1249
1250 xpt_path_assert(path, MA_OWNED);
1251
1252 memset(&cdai, 0, sizeof(cdai));
1255 cdai.flags = CDAI_FLAG_NONE;
1256 cdai.bufsiz = len;
1257 cdai.buf = buf;
1258
1259 if (!strcmp(attr, "GEOM::ident"))
1261 else if (!strcmp(attr, "GEOM::physpath"))
1263 else if (strcmp(attr, "GEOM::lunid") == 0 ||
1264 strcmp(attr, "GEOM::lunname") == 0) {
1267 cdai.buf = malloc(cdai.bufsiz, M_CAMXPT, M_NOWAIT);
1268 if (cdai.buf == NULL) {
1269 ret = ENOMEM;
1270 goto out;
1271 }
1272 } else
1273 goto out;
1274
1275 xpt_action((union ccb *)&cdai); /* can only be synchronous */
1276 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
1277 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
1278 if (cdai.provsiz == 0)
1279 goto out;
1280 switch(cdai.buftype) {
1282 did = (struct scsi_vpd_device_id *)cdai.buf;
1283 if (strcmp(attr, "GEOM::lunid") == 0) {
1284 idd = scsi_get_devid(did, cdai.provsiz,
1286 if (idd == NULL)
1287 idd = scsi_get_devid(did, cdai.provsiz,
1289 if (idd == NULL)
1290 idd = scsi_get_devid(did, cdai.provsiz,
1292 if (idd == NULL)
1293 idd = scsi_get_devid(did, cdai.provsiz,
1295 } else
1296 idd = NULL;
1297
1298 if (idd == NULL)
1299 idd = scsi_get_devid(did, cdai.provsiz,
1301 if (idd == NULL)
1302 idd = scsi_get_devid(did, cdai.provsiz,
1304 if (idd == NULL)
1305 break;
1306
1307 ret = 0;
1308 if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) ==
1310 if (idd->length < len) {
1311 for (l = 0; l < idd->length; l++)
1312 buf[l] = idd->identifier[l] ?
1313 idd->identifier[l] : ' ';
1314 buf[l] = 0;
1315 } else
1316 ret = EFAULT;
1317 break;
1318 }
1319 if ((idd->proto_codeset & SVPD_ID_CODESET_MASK) ==
1321 l = strnlen(idd->identifier, idd->length);
1322 if (l < len) {
1323 bcopy(idd->identifier, buf, l);
1324 buf[l] = 0;
1325 } else
1326 ret = EFAULT;
1327 break;
1328 }
1329 if ((idd->id_type & SVPD_ID_TYPE_MASK) ==
1330 SVPD_ID_TYPE_UUID && idd->identifier[0] == 0x10) {
1331 if ((idd->length - 2) * 2 + 4 >= len) {
1332 ret = EFAULT;
1333 break;
1334 }
1335 for (l = 2, o = 0; l < idd->length; l++) {
1336 if (l == 6 || l == 8 || l == 10 || l == 12)
1337 o += sprintf(buf + o, "-");
1338 o += sprintf(buf + o, "%02x",
1339 idd->identifier[l]);
1340 }
1341 break;
1342 }
1343 if (idd->length * 2 < len) {
1344 for (l = 0; l < idd->length; l++)
1345 sprintf(buf + l * 2, "%02x",
1346 idd->identifier[l]);
1347 } else
1348 ret = EFAULT;
1349 break;
1350 default:
1351 if (cdai.provsiz < len) {
1352 cdai.buf[cdai.provsiz] = 0;
1353 ret = 0;
1354 } else
1355 ret = EFAULT;
1356 break;
1357 }
1358
1359out:
1360 if ((char *)cdai.buf != buf)
1361 free(cdai.buf, M_CAMXPT);
1362 return ret;
1363}
1364
1365static dev_match_ret
1366xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns,
1367 struct cam_eb *bus)
1368{
1369 dev_match_ret retval;
1370 u_int i;
1371
1372 retval = DM_RET_NONE;
1373
1374 /*
1375 * If we aren't given something to match against, that's an error.
1376 */
1377 if (bus == NULL)
1378 return(DM_RET_ERROR);
1379
1380 /*
1381 * If there are no match entries, then this bus matches no
1382 * matter what.
1383 */
1384 if ((patterns == NULL) || (num_patterns == 0))
1385 return(DM_RET_DESCEND | DM_RET_COPY);
1386
1387 for (i = 0; i < num_patterns; i++) {
1388 struct bus_match_pattern *cur_pattern;
1389 struct device_match_pattern *dp = &patterns[i].pattern.device_pattern;
1390 struct periph_match_pattern *pp = &patterns[i].pattern.periph_pattern;
1391
1392 /*
1393 * If the pattern in question isn't for a bus node, we
1394 * aren't interested. However, we do indicate to the
1395 * calling routine that we should continue descending the
1396 * tree, since the user wants to match against lower-level
1397 * EDT elements.
1398 */
1399 if (patterns[i].type == DEV_MATCH_DEVICE &&
1400 (dp->flags & DEV_MATCH_PATH) != 0 &&
1401 dp->path_id != bus->path_id)
1402 continue;
1403 if (patterns[i].type == DEV_MATCH_PERIPH &&
1404 (pp->flags & PERIPH_MATCH_PATH) != 0 &&
1405 pp->path_id != bus->path_id)
1406 continue;
1407 if (patterns[i].type != DEV_MATCH_BUS) {
1408 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
1409 retval |= DM_RET_DESCEND;
1410 continue;
1411 }
1412
1413 cur_pattern = &patterns[i].pattern.bus_pattern;
1414
1415 if (((cur_pattern->flags & BUS_MATCH_PATH) != 0)
1416 && (cur_pattern->path_id != bus->path_id))
1417 continue;
1418
1419 if (((cur_pattern->flags & BUS_MATCH_BUS_ID) != 0)
1420 && (cur_pattern->bus_id != bus->sim->bus_id))
1421 continue;
1422
1423 if (((cur_pattern->flags & BUS_MATCH_UNIT) != 0)
1424 && (cur_pattern->unit_number != bus->sim->unit_number))
1425 continue;
1426
1427 if (((cur_pattern->flags & BUS_MATCH_NAME) != 0)
1428 && (strncmp(cur_pattern->dev_name, bus->sim->sim_name,
1429 DEV_IDLEN) != 0))
1430 continue;
1431
1432 /*
1433 * If we get to this point, the user definitely wants
1434 * information on this bus. So tell the caller to copy the
1435 * data out.
1436 */
1437 retval |= DM_RET_COPY;
1438
1439 /*
1440 * If the return action has been set to descend, then we
1441 * know that we've already seen a non-bus matching
1442 * expression, therefore we need to further descend the tree.
1443 * This won't change by continuing around the loop, so we
1444 * go ahead and return. If we haven't seen a non-bus
1445 * matching expression, we keep going around the loop until
1446 * we exhaust the matching expressions. We'll set the stop
1447 * flag once we fall out of the loop.
1448 */
1449 if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)
1450 return(retval);
1451 }
1452
1453 /*
1454 * If the return action hasn't been set to descend yet, that means
1455 * we haven't seen anything other than bus matching patterns. So
1456 * tell the caller to stop descending the tree -- the user doesn't
1457 * want to match against lower level tree elements.
1458 */
1459 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
1460 retval |= DM_RET_STOP;
1461
1462 return(retval);
1463}
1464
1465static dev_match_ret
1466xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns,
1467 struct cam_ed *device)
1468{
1469 dev_match_ret retval;
1470 u_int i;
1471
1472 retval = DM_RET_NONE;
1473
1474 /*
1475 * If we aren't given something to match against, that's an error.
1476 */
1477 if (device == NULL)
1478 return(DM_RET_ERROR);
1479
1480 /*
1481 * If there are no match entries, then this device matches no
1482 * matter what.
1483 */
1484 if ((patterns == NULL) || (num_patterns == 0))
1485 return(DM_RET_DESCEND | DM_RET_COPY);
1486
1487 for (i = 0; i < num_patterns; i++) {
1488 struct device_match_pattern *cur_pattern;
1489 struct scsi_vpd_device_id *device_id_page;
1490 struct periph_match_pattern *pp = &patterns[i].pattern.periph_pattern;
1491
1492 /*
1493 * If the pattern in question isn't for a device node, we
1494 * aren't interested.
1495 */
1496 if (patterns[i].type == DEV_MATCH_PERIPH &&
1497 (pp->flags & PERIPH_MATCH_TARGET) != 0 &&
1498 pp->target_id != device->target->target_id)
1499 continue;
1500 if (patterns[i].type == DEV_MATCH_PERIPH &&
1501 (pp->flags & PERIPH_MATCH_LUN) != 0 &&
1502 pp->target_lun != device->lun_id)
1503 continue;
1504 if (patterns[i].type != DEV_MATCH_DEVICE) {
1505 if ((patterns[i].type == DEV_MATCH_PERIPH)
1506 && ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE))
1507 retval |= DM_RET_DESCEND;
1508 continue;
1509 }
1510
1511 cur_pattern = &patterns[i].pattern.device_pattern;
1512
1513 /* Error out if mutually exclusive options are specified. */
1514 if ((cur_pattern->flags & (DEV_MATCH_INQUIRY|DEV_MATCH_DEVID))
1516 return(DM_RET_ERROR);
1517
1518 if (((cur_pattern->flags & DEV_MATCH_PATH) != 0)
1519 && (cur_pattern->path_id != device->target->bus->path_id))
1520 continue;
1521
1522 if (((cur_pattern->flags & DEV_MATCH_TARGET) != 0)
1523 && (cur_pattern->target_id != device->target->target_id))
1524 continue;
1525
1526 if (((cur_pattern->flags & DEV_MATCH_LUN) != 0)
1527 && (cur_pattern->target_lun != device->lun_id))
1528 continue;
1529
1530 if (((cur_pattern->flags & DEV_MATCH_INQUIRY) != 0)
1531 && (cam_quirkmatch((caddr_t)&device->inq_data,
1532 (caddr_t)&cur_pattern->data.inq_pat,
1533 1, sizeof(cur_pattern->data.inq_pat),
1534 scsi_static_inquiry_match) == NULL))
1535 continue;
1536
1537 device_id_page = (struct scsi_vpd_device_id *)device->device_id;
1538 if (((cur_pattern->flags & DEV_MATCH_DEVID) != 0)
1539 && (device->device_id_len < SVPD_DEVICE_ID_HDR_LEN
1540 || scsi_devid_match((uint8_t *)device_id_page->desc_list,
1541 device->device_id_len
1543 cur_pattern->data.devid_pat.id,
1544 cur_pattern->data.devid_pat.id_len) != 0))
1545 continue;
1546
1547 /*
1548 * If we get to this point, the user definitely wants
1549 * information on this device. So tell the caller to copy
1550 * the data out.
1551 */
1552 retval |= DM_RET_COPY;
1553
1554 /*
1555 * If the return action has been set to descend, then we
1556 * know that we've already seen a peripheral matching
1557 * expression, therefore we need to further descend the tree.
1558 * This won't change by continuing around the loop, so we
1559 * go ahead and return. If we haven't seen a peripheral
1560 * matching expression, we keep going around the loop until
1561 * we exhaust the matching expressions. We'll set the stop
1562 * flag once we fall out of the loop.
1563 */
1564 if ((retval & DM_RET_ACTION_MASK) == DM_RET_DESCEND)
1565 return(retval);
1566 }
1567
1568 /*
1569 * If the return action hasn't been set to descend yet, that means
1570 * we haven't seen any peripheral matching patterns. So tell the
1571 * caller to stop descending the tree -- the user doesn't want to
1572 * match against lower level tree elements.
1573 */
1574 if ((retval & DM_RET_ACTION_MASK) == DM_RET_NONE)
1575 retval |= DM_RET_STOP;
1576
1577 return(retval);
1578}
1579
1580/*
1581 * Match a single peripheral against any number of match patterns.
1582 */
1583static dev_match_ret
1584xptperiphmatch(struct dev_match_pattern *patterns, u_int num_patterns,
1585 struct cam_periph *periph)
1586{
1587 dev_match_ret retval;
1588 u_int i;
1589
1590 /*
1591 * If we aren't given something to match against, that's an error.
1592 */
1593 if (periph == NULL)
1594 return(DM_RET_ERROR);
1595
1596 /*
1597 * If there are no match entries, then this peripheral matches no
1598 * matter what.
1599 */
1600 if ((patterns == NULL) || (num_patterns == 0))
1601 return(DM_RET_STOP | DM_RET_COPY);
1602
1603 /*
1604 * There aren't any nodes below a peripheral node, so there's no
1605 * reason to descend the tree any further.
1606 */
1607 retval = DM_RET_STOP;
1608
1609 for (i = 0; i < num_patterns; i++) {
1610 struct periph_match_pattern *cur_pattern;
1611
1612 /*
1613 * If the pattern in question isn't for a peripheral, we
1614 * aren't interested.
1615 */
1616 if (patterns[i].type != DEV_MATCH_PERIPH)
1617 continue;
1618
1619 cur_pattern = &patterns[i].pattern.periph_pattern;
1620
1621 if (((cur_pattern->flags & PERIPH_MATCH_PATH) != 0)
1622 && (cur_pattern->path_id != periph->path->bus->path_id))
1623 continue;
1624
1625 /*
1626 * For the target and lun id's, we have to make sure the
1627 * target and lun pointers aren't NULL. The xpt peripheral
1628 * has a wildcard target and device.
1629 */
1630 if (((cur_pattern->flags & PERIPH_MATCH_TARGET) != 0)
1631 && ((periph->path->target == NULL)
1632 ||(cur_pattern->target_id != periph->path->target->target_id)))
1633 continue;
1634
1635 if (((cur_pattern->flags & PERIPH_MATCH_LUN) != 0)
1636 && ((periph->path->device == NULL)
1637 || (cur_pattern->target_lun != periph->path->device->lun_id)))
1638 continue;
1639
1640 if (((cur_pattern->flags & PERIPH_MATCH_UNIT) != 0)
1641 && (cur_pattern->unit_number != periph->unit_number))
1642 continue;
1643
1644 if (((cur_pattern->flags & PERIPH_MATCH_NAME) != 0)
1645 && (strncmp(cur_pattern->periph_name, periph->periph_name,
1646 DEV_IDLEN) != 0))
1647 continue;
1648
1649 /*
1650 * If we get to this point, the user definitely wants
1651 * information on this peripheral. So tell the caller to
1652 * copy the data out.
1653 */
1654 retval |= DM_RET_COPY;
1655
1656 /*
1657 * The return action has already been set to stop, since
1658 * peripherals don't have any nodes below them in the EDT.
1659 */
1660 return(retval);
1661 }
1662
1663 /*
1664 * If we get to this point, the peripheral that was passed in
1665 * doesn't match any of the patterns.
1666 */
1667 return(retval);
1668}
1669
1670static int
1671xptedtbusfunc(struct cam_eb *bus, void *arg)
1672{
1673 struct ccb_dev_match *cdm;
1674 struct cam_et *target;
1675 dev_match_ret retval;
1676
1677 cdm = (struct ccb_dev_match *)arg;
1678
1679 /*
1680 * If our position is for something deeper in the tree, that means
1681 * that we've already seen this node. So, we keep going down.
1682 */
1683 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
1684 && (cdm->pos.cookie.bus == bus)
1686 && (cdm->pos.cookie.target != NULL))
1687 retval = DM_RET_DESCEND;
1688 else
1689 retval = xptbusmatch(cdm->patterns, cdm->num_patterns, bus);
1690
1691 /*
1692 * If we got an error, bail out of the search.
1693 */
1694 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
1696 return(0);
1697 }
1698
1699 /*
1700 * If the copy flag is set, copy this bus out.
1701 */
1702 if (retval & DM_RET_COPY) {
1703 int spaceleft, j;
1704
1705 spaceleft = cdm->match_buf_len - (cdm->num_matches *
1706 sizeof(struct dev_match_result));
1707
1708 /*
1709 * If we don't have enough space to put in another
1710 * match result, save our position and tell the
1711 * user there are more devices to check.
1712 */
1713 if (spaceleft < sizeof(struct dev_match_result)) {
1714 bzero(&cdm->pos, sizeof(cdm->pos));
1715 cdm->pos.position_type =
1717
1718 cdm->pos.cookie.bus = bus;
1720 xsoftc.bus_generation;
1722 return(0);
1723 }
1724 j = cdm->num_matches;
1725 cdm->num_matches++;
1726 cdm->matches[j].type = DEV_MATCH_BUS;
1727 cdm->matches[j].result.bus_result.path_id = bus->path_id;
1728 cdm->matches[j].result.bus_result.bus_id = bus->sim->bus_id;
1730 bus->sim->unit_number;
1731 strlcpy(cdm->matches[j].result.bus_result.dev_name,
1732 bus->sim->sim_name,
1733 sizeof(cdm->matches[j].result.bus_result.dev_name));
1734 }
1735
1736 /*
1737 * If the user is only interested in buses, there's no
1738 * reason to descend to the next level in the tree.
1739 */
1740 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
1741 return(1);
1742
1743 /*
1744 * If there is a target generation recorded, check it to
1745 * make sure the target list hasn't changed.
1746 */
1747 mtx_lock(&bus->eb_mtx);
1748 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
1749 && (cdm->pos.cookie.bus == bus)
1751 && (cdm->pos.cookie.target != NULL)) {
1753 bus->generation)) {
1754 mtx_unlock(&bus->eb_mtx);
1756 return (0);
1757 }
1758 target = (struct cam_et *)cdm->pos.cookie.target;
1759 target->refcount++;
1760 } else
1761 target = NULL;
1762 mtx_unlock(&bus->eb_mtx);
1763
1764 return (xpttargettraverse(bus, target, xptedttargetfunc, arg));
1765}
1766
1767static int
1768xptedttargetfunc(struct cam_et *target, void *arg)
1769{
1770 struct ccb_dev_match *cdm;
1771 struct cam_eb *bus;
1772 struct cam_ed *device;
1773
1774 cdm = (struct ccb_dev_match *)arg;
1775 bus = target->bus;
1776
1777 /*
1778 * If there is a device list generation recorded, check it to
1779 * make sure the device list hasn't changed.
1780 */
1781 mtx_lock(&bus->eb_mtx);
1782 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
1783 && (cdm->pos.cookie.bus == bus)
1785 && (cdm->pos.cookie.target == target)
1787 && (cdm->pos.cookie.device != NULL)) {
1789 target->generation) {
1790 mtx_unlock(&bus->eb_mtx);
1792 return(0);
1793 }
1794 device = (struct cam_ed *)cdm->pos.cookie.device;
1795 device->refcount++;
1796 } else
1797 device = NULL;
1798 mtx_unlock(&bus->eb_mtx);
1799
1800 return (xptdevicetraverse(target, device, xptedtdevicefunc, arg));
1801}
1802
1803static int
1804xptedtdevicefunc(struct cam_ed *device, void *arg)
1805{
1806 struct cam_eb *bus;
1807 struct cam_periph *periph;
1808 struct ccb_dev_match *cdm;
1809 dev_match_ret retval;
1810
1811 cdm = (struct ccb_dev_match *)arg;
1812 bus = device->target->bus;
1813
1814 /*
1815 * If our position is for something deeper in the tree, that means
1816 * that we've already seen this node. So, we keep going down.
1817 */
1819 && (cdm->pos.cookie.device == device)
1821 && (cdm->pos.cookie.periph != NULL))
1822 retval = DM_RET_DESCEND;
1823 else
1824 retval = xptdevicematch(cdm->patterns, cdm->num_patterns,
1825 device);
1826
1827 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
1829 return(0);
1830 }
1831
1832 /*
1833 * If the copy flag is set, copy this device out.
1834 */
1835 if (retval & DM_RET_COPY) {
1836 int spaceleft, j;
1837
1838 spaceleft = cdm->match_buf_len - (cdm->num_matches *
1839 sizeof(struct dev_match_result));
1840
1841 /*
1842 * If we don't have enough space to put in another
1843 * match result, save our position and tell the
1844 * user there are more devices to check.
1845 */
1846 if (spaceleft < sizeof(struct dev_match_result)) {
1847 bzero(&cdm->pos, sizeof(cdm->pos));
1848 cdm->pos.position_type =
1851
1852 cdm->pos.cookie.bus = device->target->bus;
1854 xsoftc.bus_generation;
1855 cdm->pos.cookie.target = device->target;
1857 device->target->bus->generation;
1858 cdm->pos.cookie.device = device;
1860 device->target->generation;
1862 return(0);
1863 }
1864 j = cdm->num_matches;
1865 cdm->num_matches++;
1866 cdm->matches[j].type = DEV_MATCH_DEVICE;
1868 device->target->bus->path_id;
1870 device->target->target_id;
1872 device->lun_id;
1874 device->protocol;
1875 bcopy(&device->inq_data,
1877 sizeof(struct scsi_inquiry_data));
1878 bcopy(&device->ident_data,
1880 sizeof(struct ata_params));
1881
1882 /* Let the user know whether this device is unconfigured */
1883 if (device->flags & CAM_DEV_UNCONFIGURED)
1886 else
1889 }
1890
1891 /*
1892 * If the user isn't interested in peripherals, don't descend
1893 * the tree any further.
1894 */
1895 if ((retval & DM_RET_ACTION_MASK) == DM_RET_STOP)
1896 return(1);
1897
1898 /*
1899 * If there is a peripheral list generation recorded, make sure
1900 * it hasn't changed.
1901 */
1903 mtx_lock(&bus->eb_mtx);
1904 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
1905 && (cdm->pos.cookie.bus == bus)
1907 && (cdm->pos.cookie.target == device->target)
1909 && (cdm->pos.cookie.device == device)
1911 && (cdm->pos.cookie.periph != NULL)) {
1913 device->generation) {
1914 mtx_unlock(&bus->eb_mtx);
1917 return(0);
1918 }
1919 periph = (struct cam_periph *)cdm->pos.cookie.periph;
1920 periph->refcount++;
1921 } else
1922 periph = NULL;
1923 mtx_unlock(&bus->eb_mtx);
1925
1926 return (xptperiphtraverse(device, periph, xptedtperiphfunc, arg));
1927}
1928
1929static int
1930xptedtperiphfunc(struct cam_periph *periph, void *arg)
1931{
1932 struct ccb_dev_match *cdm;
1933 dev_match_ret retval;
1934
1935 cdm = (struct ccb_dev_match *)arg;
1936
1937 retval = xptperiphmatch(cdm->patterns, cdm->num_patterns, periph);
1938
1939 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
1941 return(0);
1942 }
1943
1944 /*
1945 * If the copy flag is set, copy this peripheral out.
1946 */
1947 if (retval & DM_RET_COPY) {
1948 int spaceleft, j;
1949 size_t l;
1950
1951 spaceleft = cdm->match_buf_len - (cdm->num_matches *
1952 sizeof(struct dev_match_result));
1953
1954 /*
1955 * If we don't have enough space to put in another
1956 * match result, save our position and tell the
1957 * user there are more devices to check.
1958 */
1959 if (spaceleft < sizeof(struct dev_match_result)) {
1960 bzero(&cdm->pos, sizeof(cdm->pos));
1961 cdm->pos.position_type =
1965
1966 cdm->pos.cookie.bus = periph->path->bus;
1968 xsoftc.bus_generation;
1969 cdm->pos.cookie.target = periph->path->target;
1971 periph->path->bus->generation;
1972 cdm->pos.cookie.device = periph->path->device;
1974 periph->path->target->generation;
1975 cdm->pos.cookie.periph = periph;
1977 periph->path->device->generation;
1979 return(0);
1980 }
1981
1982 j = cdm->num_matches;
1983 cdm->num_matches++;
1984 cdm->matches[j].type = DEV_MATCH_PERIPH;
1986 periph->path->bus->path_id;
1988 periph->path->target->target_id;
1990 periph->path->device->lun_id;
1992 periph->unit_number;
1993 l = sizeof(cdm->matches[j].result.periph_result.periph_name);
1994 strlcpy(cdm->matches[j].result.periph_result.periph_name,
1995 periph->periph_name, l);
1996 }
1997
1998 return(1);
1999}
2000
2001static int
2003{
2004 struct cam_eb *bus;
2005 int ret;
2006
2007 cdm->num_matches = 0;
2008
2009 /*
2010 * Check the bus list generation. If it has changed, the user
2011 * needs to reset everything and start over.
2012 */
2014 if ((cdm->pos.position_type & CAM_DEV_POS_BUS)
2015 && (cdm->pos.cookie.bus != NULL)) {
2017 xsoftc.bus_generation) {
2020 return(0);
2021 }
2022 bus = (struct cam_eb *)cdm->pos.cookie.bus;
2023 bus->refcount++;
2024 } else
2025 bus = NULL;
2027
2028 ret = xptbustraverse(bus, xptedtbusfunc, cdm);
2029
2030 /*
2031 * If we get back 0, that means that we had to stop before fully
2032 * traversing the EDT. It also means that one of the subroutines
2033 * has set the status field to the proper value. If we get back 1,
2034 * we've fully traversed the EDT and copied out any matching entries.
2035 */
2036 if (ret == 1)
2038
2039 return(ret);
2040}
2041
2042static int
2043xptplistpdrvfunc(struct periph_driver **pdrv, void *arg)
2044{
2045 struct cam_periph *periph;
2046 struct ccb_dev_match *cdm;
2047
2048 cdm = (struct ccb_dev_match *)arg;
2049
2052 && (cdm->pos.cookie.pdrv == pdrv)
2054 && (cdm->pos.cookie.periph != NULL)) {
2056 (*pdrv)->generation) {
2059 return(0);
2060 }
2061 periph = (struct cam_periph *)cdm->pos.cookie.periph;
2062 periph->refcount++;
2063 } else
2064 periph = NULL;
2066
2067 return (xptpdperiphtraverse(pdrv, periph, xptplistperiphfunc, arg));
2068}
2069
2070static int
2071xptplistperiphfunc(struct cam_periph *periph, void *arg)
2072{
2073 struct ccb_dev_match *cdm;
2074 dev_match_ret retval;
2075
2076 cdm = (struct ccb_dev_match *)arg;
2077
2078 retval = xptperiphmatch(cdm->patterns, cdm->num_patterns, periph);
2079
2080 if ((retval & DM_RET_ACTION_MASK) == DM_RET_ERROR) {
2082 return(0);
2083 }
2084
2085 /*
2086 * If the copy flag is set, copy this peripheral out.
2087 */
2088 if (retval & DM_RET_COPY) {
2089 int spaceleft, j;
2090 size_t l;
2091
2092 spaceleft = cdm->match_buf_len - (cdm->num_matches *
2093 sizeof(struct dev_match_result));
2094
2095 /*
2096 * If we don't have enough space to put in another
2097 * match result, save our position and tell the
2098 * user there are more devices to check.
2099 */
2100 if (spaceleft < sizeof(struct dev_match_result)) {
2101 struct periph_driver **pdrv;
2102
2103 pdrv = NULL;
2104 bzero(&cdm->pos, sizeof(cdm->pos));
2105 cdm->pos.position_type =
2108
2109 /*
2110 * This may look a bit non-sensical, but it is
2111 * actually quite logical. There are very few
2112 * peripheral drivers, and bloating every peripheral
2113 * structure with a pointer back to its parent
2114 * peripheral driver linker set entry would cost
2115 * more in the long run than doing this quick lookup.
2116 */
2117 for (pdrv = periph_drivers; *pdrv != NULL; pdrv++) {
2118 if (strcmp((*pdrv)->driver_name,
2119 periph->periph_name) == 0)
2120 break;
2121 }
2122
2123 if (*pdrv == NULL) {
2125 return(0);
2126 }
2127
2128 cdm->pos.cookie.pdrv = pdrv;
2129 /*
2130 * The periph generation slot does double duty, as
2131 * does the periph pointer slot. They are used for
2132 * both edt and pdrv lookups and positioning.
2133 */
2134 cdm->pos.cookie.periph = periph;
2136 (*pdrv)->generation;
2138 return(0);
2139 }
2140
2141 j = cdm->num_matches;
2142 cdm->num_matches++;
2143 cdm->matches[j].type = DEV_MATCH_PERIPH;
2145 periph->path->bus->path_id;
2146
2147 /*
2148 * The transport layer peripheral doesn't have a target or
2149 * lun.
2150 */
2151 if (periph->path->target)
2153 periph->path->target->target_id;
2154 else
2157
2158 if (periph->path->device)
2160 periph->path->device->lun_id;
2161 else
2164
2166 periph->unit_number;
2167 l = sizeof(cdm->matches[j].result.periph_result.periph_name);
2168 strlcpy(cdm->matches[j].result.periph_result.periph_name,
2169 periph->periph_name, l);
2170 }
2171
2172 return(1);
2173}
2174
2175static int
2177{
2178 int ret;
2179
2180 cdm->num_matches = 0;
2181
2182 /*
2183 * At this point in the edt traversal function, we check the bus
2184 * list generation to make sure that no buses have been added or
2185 * removed since the user last sent a XPT_DEV_MATCH ccb through.
2186 * For the peripheral driver list traversal function, however, we
2187 * don't have to worry about new peripheral driver types coming or
2188 * going; they're in a linker set, and therefore can't change
2189 * without a recompile.
2190 */
2191
2193 && (cdm->pos.cookie.pdrv != NULL))
2194 ret = xptpdrvtraverse(
2195 (struct periph_driver **)cdm->pos.cookie.pdrv,
2196 xptplistpdrvfunc, cdm);
2197 else
2198 ret = xptpdrvtraverse(NULL, xptplistpdrvfunc, cdm);
2199
2200 /*
2201 * If we get back 0, that means that we had to stop before fully
2202 * traversing the peripheral driver tree. It also means that one of
2203 * the subroutines has set the status field to the proper value. If
2204 * we get back 1, we've fully traversed the EDT and copied out any
2205 * matching entries.
2206 */
2207 if (ret == 1)
2209
2210 return(ret);
2211}
2212
2213static int
2214xptbustraverse(struct cam_eb *start_bus, xpt_busfunc_t *tr_func, void *arg)
2215{
2216 struct cam_eb *bus, *next_bus;
2217 int retval;
2218
2219 retval = 1;
2220 if (start_bus)
2221 bus = start_bus;
2222 else {
2224 bus = TAILQ_FIRST(&xsoftc.xpt_busses);
2225 if (bus == NULL) {
2227 return (retval);
2228 }
2229 bus->refcount++;
2231 }
2232 for (; bus != NULL; bus = next_bus) {
2233 retval = tr_func(bus, arg);
2234 if (retval == 0) {
2235 xpt_release_bus(bus);
2236 break;
2237 }
2239 next_bus = TAILQ_NEXT(bus, links);
2240 if (next_bus)
2241 next_bus->refcount++;
2243 xpt_release_bus(bus);
2244 }
2245 return(retval);
2246}
2247
2248static int
2249xpttargettraverse(struct cam_eb *bus, struct cam_et *start_target,
2250 xpt_targetfunc_t *tr_func, void *arg)
2251{
2252 struct cam_et *target, *next_target;
2253 int retval;
2254
2255 retval = 1;
2256 if (start_target)
2257 target = start_target;
2258 else {
2259 mtx_lock(&bus->eb_mtx);
2260 target = TAILQ_FIRST(&bus->et_entries);
2261 if (target == NULL) {
2262 mtx_unlock(&bus->eb_mtx);
2263 return (retval);
2264 }
2265 target->refcount++;
2266 mtx_unlock(&bus->eb_mtx);
2267 }
2268 for (; target != NULL; target = next_target) {
2269 retval = tr_func(target, arg);
2270 if (retval == 0) {
2271 xpt_release_target(target);
2272 break;
2273 }
2274 mtx_lock(&bus->eb_mtx);
2275 next_target = TAILQ_NEXT(target, links);
2276 if (next_target)
2277 next_target->refcount++;
2278 mtx_unlock(&bus->eb_mtx);
2279 xpt_release_target(target);
2280 }
2281 return(retval);
2282}
2283
2284static int
2285xptdevicetraverse(struct cam_et *target, struct cam_ed *start_device,
2286 xpt_devicefunc_t *tr_func, void *arg)
2287{
2288 struct cam_eb *bus;
2289 struct cam_ed *device, *next_device;
2290 int retval;
2291
2292 retval = 1;
2293 bus = target->bus;
2294 if (start_device)
2295 device = start_device;
2296 else {
2297 mtx_lock(&bus->eb_mtx);
2298 device = TAILQ_FIRST(&target->ed_entries);
2299 if (device == NULL) {
2300 mtx_unlock(&bus->eb_mtx);
2301 return (retval);
2302 }
2303 device->refcount++;
2304 mtx_unlock(&bus->eb_mtx);
2305 }
2306 for (; device != NULL; device = next_device) {
2307 mtx_lock(&device->device_mtx);
2308 retval = tr_func(device, arg);
2309 mtx_unlock(&device->device_mtx);
2310 if (retval == 0) {
2311 xpt_release_device(device);
2312 break;
2313 }
2314 mtx_lock(&bus->eb_mtx);
2315 next_device = TAILQ_NEXT(device, links);
2316 if (next_device)
2317 next_device->refcount++;
2318 mtx_unlock(&bus->eb_mtx);
2319 xpt_release_device(device);
2320 }
2321 return(retval);
2322}
2323
2324static int
2325xptperiphtraverse(struct cam_ed *device, struct cam_periph *start_periph,
2326 xpt_periphfunc_t *tr_func, void *arg)
2327{
2328 struct cam_eb *bus;
2329 struct cam_periph *periph, *next_periph;
2330 int retval;
2331
2332 retval = 1;
2333
2334 bus = device->target->bus;
2335 if (start_periph)
2336 periph = start_periph;
2337 else {
2339 mtx_lock(&bus->eb_mtx);
2340 periph = SLIST_FIRST(&device->periphs);
2341 while (periph != NULL && (periph->flags & CAM_PERIPH_FREE) != 0)
2342 periph = SLIST_NEXT(periph, periph_links);
2343 if (periph == NULL) {
2344 mtx_unlock(&bus->eb_mtx);
2346 return (retval);
2347 }
2348 periph->refcount++;
2349 mtx_unlock(&bus->eb_mtx);
2351 }
2352 for (; periph != NULL; periph = next_periph) {
2353 retval = tr_func(periph, arg);
2354 if (retval == 0) {
2356 break;
2357 }
2359 mtx_lock(&bus->eb_mtx);
2360 next_periph = SLIST_NEXT(periph, periph_links);
2361 while (next_periph != NULL &&
2362 (next_periph->flags & CAM_PERIPH_FREE) != 0)
2363 next_periph = SLIST_NEXT(next_periph, periph_links);
2364 if (next_periph)
2365 next_periph->refcount++;
2366 mtx_unlock(&bus->eb_mtx);
2369 }
2370 return(retval);
2371}
2372
2373static int
2374xptpdrvtraverse(struct periph_driver **start_pdrv,
2375 xpt_pdrvfunc_t *tr_func, void *arg)
2376{
2377 struct periph_driver **pdrv;
2378 int retval;
2379
2380 retval = 1;
2381
2382 /*
2383 * We don't traverse the peripheral driver list like we do the
2384 * other lists, because it is a linker set, and therefore cannot be
2385 * changed during runtime. If the peripheral driver list is ever
2386 * re-done to be something other than a linker set (i.e. it can
2387 * change while the system is running), the list traversal should
2388 * be modified to work like the other traversal functions.
2389 */
2390 for (pdrv = (start_pdrv ? start_pdrv : periph_drivers);
2391 *pdrv != NULL; pdrv++) {
2392 retval = tr_func(pdrv, arg);
2393
2394 if (retval == 0)
2395 return(retval);
2396 }
2397
2398 return(retval);
2399}
2400
2401static int
2403 struct cam_periph *start_periph,
2404 xpt_periphfunc_t *tr_func, void *arg)
2405{
2406 struct cam_periph *periph, *next_periph;
2407 int retval;
2408
2409 retval = 1;
2410
2411 if (start_periph)
2412 periph = start_periph;
2413 else {
2415 periph = TAILQ_FIRST(&(*pdrv)->units);
2416 while (periph != NULL && (periph->flags & CAM_PERIPH_FREE) != 0)
2417 periph = TAILQ_NEXT(periph, unit_links);
2418 if (periph == NULL) {
2420 return (retval);
2421 }
2422 periph->refcount++;
2424 }
2425 for (; periph != NULL; periph = next_periph) {
2426 cam_periph_lock(periph);
2427 retval = tr_func(periph, arg);
2428 cam_periph_unlock(periph);
2429 if (retval == 0) {
2430 cam_periph_release(periph);
2431 break;
2432 }
2434 next_periph = TAILQ_NEXT(periph, unit_links);
2435 while (next_periph != NULL &&
2436 (next_periph->flags & CAM_PERIPH_FREE) != 0)
2437 next_periph = TAILQ_NEXT(next_periph, unit_links);
2438 if (next_periph)
2439 next_periph->refcount++;
2441 cam_periph_release(periph);
2442 }
2443 return(retval);
2444}
2445
2446static int
2447xptdefbusfunc(struct cam_eb *bus, void *arg)
2448{
2449 struct xpt_traverse_config *tr_config;
2450
2451 tr_config = (struct xpt_traverse_config *)arg;
2452
2453 if (tr_config->depth == XPT_DEPTH_BUS) {
2455
2456 tr_func = (xpt_busfunc_t *)tr_config->tr_func;
2457
2458 return(tr_func(bus, tr_config->tr_arg));
2459 } else
2460 return(xpttargettraverse(bus, NULL, xptdeftargetfunc, arg));
2461}
2462
2463static int
2464xptdeftargetfunc(struct cam_et *target, void *arg)
2465{
2466 struct xpt_traverse_config *tr_config;
2467
2468 tr_config = (struct xpt_traverse_config *)arg;
2469
2470 if (tr_config->depth == XPT_DEPTH_TARGET) {
2472
2473 tr_func = (xpt_targetfunc_t *)tr_config->tr_func;
2474
2475 return(tr_func(target, tr_config->tr_arg));
2476 } else
2477 return(xptdevicetraverse(target, NULL, xptdefdevicefunc, arg));
2478}
2479
2480static int
2481xptdefdevicefunc(struct cam_ed *device, void *arg)
2482{
2483 struct xpt_traverse_config *tr_config;
2484
2485 tr_config = (struct xpt_traverse_config *)arg;
2486
2487 if (tr_config->depth == XPT_DEPTH_DEVICE) {
2489
2490 tr_func = (xpt_devicefunc_t *)tr_config->tr_func;
2491
2492 return(tr_func(device, tr_config->tr_arg));
2493 } else
2494 return(xptperiphtraverse(device, NULL, xptdefperiphfunc, arg));
2495}
2496
2497static int
2498xptdefperiphfunc(struct cam_periph *periph, void *arg)
2499{
2500 struct xpt_traverse_config *tr_config;
2502
2503 tr_config = (struct xpt_traverse_config *)arg;
2504
2505 tr_func = (xpt_periphfunc_t *)tr_config->tr_func;
2506
2507 /*
2508 * Unlike the other default functions, we don't check for depth
2509 * here. The peripheral driver level is the last level in the EDT,
2510 * so if we're here, we should execute the function in question.
2511 */
2512 return(tr_func(periph, tr_config->tr_arg));
2513}
2514
2515/*
2516 * Execute the given function for every bus in the EDT.
2517 */
2518static int
2520{
2521 struct xpt_traverse_config tr_config;
2522
2523 tr_config.depth = XPT_DEPTH_BUS;
2524 tr_config.tr_func = tr_func;
2525 tr_config.tr_arg = arg;
2526
2527 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2528}
2529
2530/*
2531 * Execute the given function for every device in the EDT.
2532 */
2533static int
2535{
2536 struct xpt_traverse_config tr_config;
2537
2538 tr_config.depth = XPT_DEPTH_DEVICE;
2539 tr_config.tr_func = tr_func;
2540 tr_config.tr_arg = arg;
2541
2542 return(xptbustraverse(NULL, xptdefbusfunc, &tr_config));
2543}
2544
2545static int
2546xptsetasyncfunc(struct cam_ed *device, void *arg)
2547{
2548 struct cam_path path;
2549 struct ccb_getdev cgd;
2550 struct ccb_setasync *csa = (struct ccb_setasync *)arg;
2551
2552 /*
2553 * Don't report unconfigured devices (Wildcard devs,
2554 * devices only for target mode, device instances
2555 * that have been invalidated but are waiting for
2556 * their last reference count to be released).
2557 */
2558 if ((device->flags & CAM_DEV_UNCONFIGURED) != 0)
2559 return (1);
2560
2561 memset(&cgd, 0, sizeof(cgd));
2562 xpt_compile_path(&path,
2563 NULL,
2564 device->target->bus->path_id,
2565 device->target->target_id,
2566 device->lun_id);
2569 xpt_action((union ccb *)&cgd);
2570 csa->callback(csa->callback_arg,
2572 &path, &cgd);
2573 xpt_release_path(&path);
2574
2575 return(1);
2576}
2577
2578static int
2579xptsetasyncbusfunc(struct cam_eb *bus, void *arg)
2580{
2581 struct cam_path path;
2582 struct ccb_pathinq cpi;
2583 struct ccb_setasync *csa = (struct ccb_setasync *)arg;
2584
2585 xpt_compile_path(&path, /*periph*/NULL,
2586 bus->path_id,
2589 xpt_path_lock(&path);
2590 xpt_path_inq(&cpi, &path);
2591 csa->callback(csa->callback_arg,
2593 &path, &cpi);
2594 xpt_path_unlock(&path);
2595 xpt_release_path(&path);
2596
2597 return(1);
2598}
2599
2600void
2601xpt_action(union ccb *start_ccb)
2602{
2603
2604 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE,
2605 ("xpt_action: func %#x %s\n", start_ccb->ccb_h.func_code,
2606 xpt_action_name(start_ccb->ccb_h.func_code)));
2607
2608 start_ccb->ccb_h.status = CAM_REQ_INPROG;
2609 (*(start_ccb->ccb_h.path->bus->xport->ops->action))(start_ccb);
2610}
2611
2612void
2613xpt_action_default(union ccb *start_ccb)
2614{
2615 struct cam_path *path;
2616 struct cam_sim *sim;
2617 struct mtx *mtx;
2618
2619 path = start_ccb->ccb_h.path;
2621 ("xpt_action_default: func %#x %s\n", start_ccb->ccb_h.func_code,
2622 xpt_action_name(start_ccb->ccb_h.func_code)));
2623
2624 switch (start_ccb->ccb_h.func_code) {
2625 case XPT_SCSI_IO:
2626 {
2627 struct cam_ed *device;
2628
2629 /*
2630 * For the sake of compatibility with SCSI-1
2631 * devices that may not understand the identify
2632 * message, we include lun information in the
2633 * second byte of all commands. SCSI-1 specifies
2634 * that luns are a 3 bit value and reserves only 3
2635 * bits for lun information in the CDB. Later
2636 * revisions of the SCSI spec allow for more than 8
2637 * luns, but have deprecated lun information in the
2638 * CDB. So, if the lun won't fit, we must omit.
2639 *
2640 * Also be aware that during initial probing for devices,
2641 * the inquiry information is unknown but initialized to 0.
2642 * This means that this code will be exercised while probing
2643 * devices with an ANSI revision greater than 2.
2644 */
2645 device = path->device;
2646 if (device->protocol_version <= SCSI_REV_2
2647 && start_ccb->ccb_h.target_lun < 8
2648 && (start_ccb->ccb_h.flags & CAM_CDB_POINTER) == 0) {
2649 start_ccb->csio.cdb_io.cdb_bytes[1] |=
2650 start_ccb->ccb_h.target_lun << 5;
2651 }
2652 start_ccb->csio.scsi_status = SCSI_STATUS_OK;
2653 }
2654 /* FALLTHROUGH */
2655 case XPT_TARGET_IO:
2656 case XPT_CONT_TARGET_IO:
2657 start_ccb->csio.sense_resid = 0;
2658 start_ccb->csio.resid = 0;
2659 /* FALLTHROUGH */
2660 case XPT_ATA_IO:
2661 if (start_ccb->ccb_h.func_code == XPT_ATA_IO)
2662 start_ccb->ataio.resid = 0;
2663 /* FALLTHROUGH */
2664 case XPT_NVME_IO:
2665 case XPT_NVME_ADMIN:
2666 case XPT_MMC_IO:
2669 case XPT_RESET_DEV:
2670 case XPT_ENG_EXEC:
2671 case XPT_SMP_IO:
2672 {
2673 struct cam_devq *devq;
2674
2675 devq = path->bus->sim->devq;
2676 mtx_lock(&devq->send_mtx);
2677 cam_ccbq_insert_ccb(&path->device->ccbq, start_ccb);
2678 if (xpt_schedule_devq(devq, path->device) != 0)
2679 xpt_run_devq(devq);
2680 mtx_unlock(&devq->send_mtx);
2681 break;
2682 }
2683 case XPT_CALC_GEOMETRY:
2684 /* Filter out garbage */
2685 if (start_ccb->ccg.block_size == 0
2686 || start_ccb->ccg.volume_size == 0) {
2687 start_ccb->ccg.cylinders = 0;
2688 start_ccb->ccg.heads = 0;
2689 start_ccb->ccg.secs_per_track = 0;
2690 start_ccb->ccb_h.status = CAM_REQ_CMP;
2691 break;
2692 }
2693 goto call_sim;
2694 case XPT_ABORT:
2695 {
2696 union ccb* abort_ccb;
2697
2698 abort_ccb = start_ccb->cab.abort_ccb;
2699 if (XPT_FC_IS_DEV_QUEUED(abort_ccb)) {
2700 struct cam_ed *device;
2701 struct cam_devq *devq;
2702
2703 device = abort_ccb->ccb_h.path->device;
2704 devq = device->sim->devq;
2705
2706 mtx_lock(&devq->send_mtx);
2707 if (abort_ccb->ccb_h.pinfo.index > 0) {
2708 cam_ccbq_remove_ccb(&device->ccbq, abort_ccb);
2709 abort_ccb->ccb_h.status =
2711 xpt_freeze_devq_device(device, 1);
2712 mtx_unlock(&devq->send_mtx);
2713 xpt_done(abort_ccb);
2714 start_ccb->ccb_h.status = CAM_REQ_CMP;
2715 break;
2716 }
2717 mtx_unlock(&devq->send_mtx);
2718
2719 if (abort_ccb->ccb_h.pinfo.index == CAM_UNQUEUED_INDEX
2720 && (abort_ccb->ccb_h.status & CAM_SIM_QUEUED) == 0) {
2721 /*
2722 * We've caught this ccb en route to
2723 * the SIM. Flag it for abort and the
2724 * SIM will do so just before starting
2725 * real work on the CCB.
2726 */
2727 abort_ccb->ccb_h.status =
2729 xpt_freeze_devq(abort_ccb->ccb_h.path, 1);
2730 start_ccb->ccb_h.status = CAM_REQ_CMP;
2731 break;
2732 }
2733 }
2734 if (XPT_FC_IS_QUEUED(abort_ccb)
2735 && (abort_ccb->ccb_h.pinfo.index == CAM_DONEQ_INDEX)) {
2736 /*
2737 * It's already completed but waiting
2738 * for our SWI to get to it.
2739 */
2740 start_ccb->ccb_h.status = CAM_UA_ABORT;
2741 break;
2742 }
2743 /*
2744 * If we weren't able to take care of the abort request
2745 * in the XPT, pass the request down to the SIM for processing.
2746 */
2747 }
2748 /* FALLTHROUGH */
2750 case XPT_EN_LUN:
2751 case XPT_IMMED_NOTIFY:
2752 case XPT_NOTIFY_ACK:
2753 case XPT_RESET_BUS:
2757 case XPT_GET_SIM_KNOB:
2758 case XPT_SET_SIM_KNOB:
2761 case XPT_PATH_INQ:
2762call_sim:
2763 sim = path->bus->sim;
2764 mtx = sim->mtx;
2765 if (mtx && !mtx_owned(mtx))
2766 mtx_lock(mtx);
2767 else
2768 mtx = NULL;
2769
2771 ("Calling sim->sim_action(): func=%#x\n", start_ccb->ccb_h.func_code));
2772 (*(sim->sim_action))(sim, start_ccb);
2774 ("sim->sim_action returned: status=%#x\n", start_ccb->ccb_h.status));
2775 if (mtx)
2776 mtx_unlock(mtx);
2777 break;
2778 case XPT_PATH_STATS:
2779 start_ccb->cpis.last_reset = path->bus->last_reset;
2780 start_ccb->ccb_h.status = CAM_REQ_CMP;
2781 break;
2782 case XPT_GDEV_TYPE:
2783 {
2784 struct cam_ed *dev;
2785
2786 dev = path->device;
2787 if ((dev->flags & CAM_DEV_UNCONFIGURED) != 0) {
2788 start_ccb->ccb_h.status = CAM_DEV_NOT_THERE;
2789 } else {
2790 struct ccb_getdev *cgd;
2791
2792 cgd = &start_ccb->cgd;
2793 cgd->protocol = dev->protocol;
2794 cgd->inq_data = dev->inq_data;
2795 cgd->ident_data = dev->ident_data;
2796 cgd->inq_flags = dev->inq_flags;
2797 cgd->ccb_h.status = CAM_REQ_CMP;
2798 cgd->serial_num_len = dev->serial_num_len;
2799 if ((dev->serial_num_len > 0)
2800 && (dev->serial_num != NULL))
2801 bcopy(dev->serial_num, cgd->serial_num,
2802 dev->serial_num_len);
2803 }
2804 break;
2805 }
2806 case XPT_GDEV_STATS:
2807 {
2808 struct ccb_getdevstats *cgds = &start_ccb->cgds;
2809 struct cam_ed *dev = path->device;
2810 struct cam_eb *bus = path->bus;
2811 struct cam_et *tar = path->target;
2812 struct cam_devq *devq = bus->sim->devq;
2813
2814 mtx_lock(&devq->send_mtx);
2815 cgds->dev_openings = dev->ccbq.dev_openings;
2816 cgds->dev_active = dev->ccbq.dev_active;
2817 cgds->allocated = dev->ccbq.allocated;
2818 cgds->queued = cam_ccbq_pending_ccb_count(&dev->ccbq);
2819 cgds->held = cgds->allocated - cgds->dev_active - cgds->queued;
2820 cgds->last_reset = tar->last_reset;
2821 cgds->maxtags = dev->maxtags;
2822 cgds->mintags = dev->mintags;
2823 if (timevalcmp(&tar->last_reset, &bus->last_reset, <))
2824 cgds->last_reset = bus->last_reset;
2825 mtx_unlock(&devq->send_mtx);
2826 cgds->ccb_h.status = CAM_REQ_CMP;
2827 break;
2828 }
2829 case XPT_GDEVLIST:
2830 {
2831 struct cam_periph *nperiph;
2832 struct periph_list *periph_head;
2833 struct ccb_getdevlist *cgdl;
2834 u_int i;
2835 struct cam_ed *device;
2836 int found;
2837
2838 found = 0;
2839
2840 /*
2841 * Don't want anyone mucking with our data.
2842 */
2843 device = path->device;
2844 periph_head = &device->periphs;
2845 cgdl = &start_ccb->cgdl;
2846
2847 /*
2848 * Check and see if the list has changed since the user
2849 * last requested a list member. If so, tell them that the
2850 * list has changed, and therefore they need to start over
2851 * from the beginning.
2852 */
2853 if ((cgdl->index != 0) &&
2854 (cgdl->generation != device->generation)) {
2856 break;
2857 }
2858
2859 /*
2860 * Traverse the list of peripherals and attempt to find
2861 * the requested peripheral.
2862 */
2863 for (nperiph = SLIST_FIRST(periph_head), i = 0;
2864 (nperiph != NULL) && (i <= cgdl->index);
2865 nperiph = SLIST_NEXT(nperiph, periph_links), i++) {
2866 if (i == cgdl->index) {
2867 strlcpy(cgdl->periph_name,
2868 nperiph->periph_name,
2869 sizeof(cgdl->periph_name));
2870 cgdl->unit_number = nperiph->unit_number;
2871 found = 1;
2872 }
2873 }
2874 if (found == 0) {
2875 cgdl->status = CAM_GDEVLIST_ERROR;
2876 break;
2877 }
2878
2879 if (nperiph == NULL)
2881 else
2883
2884 cgdl->index++;
2885 cgdl->generation = device->generation;
2886
2887 cgdl->ccb_h.status = CAM_REQ_CMP;
2888 break;
2889 }
2890 case XPT_DEV_MATCH:
2891 {
2892 dev_pos_type position_type;
2893 struct ccb_dev_match *cdm;
2894
2895 cdm = &start_ccb->cdm;
2896
2897 /*
2898 * There are two ways of getting at information in the EDT.
2899 * The first way is via the primary EDT tree. It starts
2900 * with a list of buses, then a list of targets on a bus,
2901 * then devices/luns on a target, and then peripherals on a
2902 * device/lun. The "other" way is by the peripheral driver
2903 * lists. The peripheral driver lists are organized by
2904 * peripheral driver. (obviously) So it makes sense to
2905 * use the peripheral driver list if the user is looking
2906 * for something like "da1", or all "da" devices. If the
2907 * user is looking for something on a particular bus/target
2908 * or lun, it's generally better to go through the EDT tree.
2909 */
2910
2912 position_type = cdm->pos.position_type;
2913 else {
2914 u_int i;
2915
2916 position_type = CAM_DEV_POS_NONE;
2917
2918 for (i = 0; i < cdm->num_patterns; i++) {
2919 if ((cdm->patterns[i].type == DEV_MATCH_BUS)
2920 ||(cdm->patterns[i].type == DEV_MATCH_DEVICE)){
2921 position_type = CAM_DEV_POS_EDT;
2922 break;
2923 }
2924 }
2925
2926 if (cdm->num_patterns == 0)
2927 position_type = CAM_DEV_POS_EDT;
2928 else if (position_type == CAM_DEV_POS_NONE)
2929 position_type = CAM_DEV_POS_PDRV;
2930 }
2931
2932 switch(position_type & CAM_DEV_POS_TYPEMASK) {
2933 case CAM_DEV_POS_EDT:
2934 xptedtmatch(cdm);
2935 break;
2936 case CAM_DEV_POS_PDRV:
2937 xptperiphlistmatch(cdm);
2938 break;
2939 default:
2941 break;
2942 }
2943
2944 if (cdm->status == CAM_DEV_MATCH_ERROR)
2945 start_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
2946 else
2947 start_ccb->ccb_h.status = CAM_REQ_CMP;
2948
2949 break;
2950 }
2951 case XPT_SASYNC_CB:
2952 {
2953 struct ccb_setasync *csa;
2954 struct async_node *cur_entry;
2955 struct async_list *async_head;
2956 u_int32_t added;
2957
2958 csa = &start_ccb->csa;
2959 added = csa->event_enable;
2960 async_head = &path->device->asyncs;
2961
2962 /*
2963 * If there is already an entry for us, simply
2964 * update it.
2965 */
2966 cur_entry = SLIST_FIRST(async_head);
2967 while (cur_entry != NULL) {
2968 if ((cur_entry->callback_arg == csa->callback_arg)
2969 && (cur_entry->callback == csa->callback))
2970 break;
2971 cur_entry = SLIST_NEXT(cur_entry, links);
2972 }
2973
2974 if (cur_entry != NULL) {
2975 /*
2976 * If the request has no flags set,
2977 * remove the entry.
2978 */
2979 added &= ~cur_entry->event_enable;
2980 if (csa->event_enable == 0) {
2981 SLIST_REMOVE(async_head, cur_entry,
2982 async_node, links);
2984 free(cur_entry, M_CAMXPT);
2985 } else {
2986 cur_entry->event_enable = csa->event_enable;
2987 }
2988 csa->event_enable = added;
2989 } else {
2990 cur_entry = malloc(sizeof(*cur_entry), M_CAMXPT,
2991 M_NOWAIT);
2992 if (cur_entry == NULL) {
2994 break;
2995 }
2996 cur_entry->event_enable = csa->event_enable;
2997 cur_entry->event_lock = (path->bus->sim->mtx &&
2998 mtx_owned(path->bus->sim->mtx)) ? 1 : 0;
2999 cur_entry->callback_arg = csa->callback_arg;
3000 cur_entry->callback = csa->callback;
3001 SLIST_INSERT_HEAD(async_head, cur_entry, links);
3003 }
3004 start_ccb->ccb_h.status = CAM_REQ_CMP;
3005 break;
3006 }
3007 case XPT_REL_SIMQ:
3008 {
3009 struct ccb_relsim *crs;
3010 struct cam_ed *dev;
3011
3012 crs = &start_ccb->crs;
3013 dev = path->device;
3014 if (dev == NULL) {
3016 break;
3017 }
3018
3019 if ((crs->release_flags & RELSIM_ADJUST_OPENINGS) != 0) {
3020 /* Don't ever go below one opening */
3021 if (crs->openings > 0) {
3022 xpt_dev_ccbq_resize(path, crs->openings);
3023 if (bootverbose) {
3024 xpt_print(path,
3025 "number of openings is now %d\n",
3026 crs->openings);
3027 }
3028 }
3029 }
3030
3031 mtx_lock(&dev->sim->devq->send_mtx);
3032 if ((crs->release_flags & RELSIM_RELEASE_AFTER_TIMEOUT) != 0) {
3033 if ((dev->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0) {
3034 /*
3035 * Just extend the old timeout and decrement
3036 * the freeze count so that a single timeout
3037 * is sufficient for releasing the queue.
3038 */
3039 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3040 callout_stop(&dev->callout);
3041 } else {
3042 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3043 }
3044
3045 callout_reset_sbt(&dev->callout,
3046 SBT_1MS * crs->release_timeout, SBT_1MS,
3047 xpt_release_devq_timeout, dev, 0);
3048
3050 }
3051
3052 if ((crs->release_flags & RELSIM_RELEASE_AFTER_CMDCMPLT) != 0) {
3053 if ((dev->flags & CAM_DEV_REL_ON_COMPLETE) != 0) {
3054 /*
3055 * Decrement the freeze count so that a single
3056 * completion is still sufficient to unfreeze
3057 * the queue.
3058 */
3059 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3060 } else {
3062 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3063 }
3064 }
3065
3066 if ((crs->release_flags & RELSIM_RELEASE_AFTER_QEMPTY) != 0) {
3067 if ((dev->flags & CAM_DEV_REL_ON_QUEUE_EMPTY) != 0
3068 || (dev->ccbq.dev_active == 0)) {
3069 start_ccb->ccb_h.flags &= ~CAM_DEV_QFREEZE;
3070 } else {
3072 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
3073 }
3074 }
3075 mtx_unlock(&dev->sim->devq->send_mtx);
3076
3077 if ((start_ccb->ccb_h.flags & CAM_DEV_QFREEZE) == 0)
3078 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
3079 start_ccb->crs.qfrozen_cnt = dev->ccbq.queue.qfrozen_cnt;
3080 start_ccb->ccb_h.status = CAM_REQ_CMP;
3081 break;
3082 }
3083 case XPT_DEBUG: {
3084 struct cam_path *oldpath;
3085
3086 /* Check that all request bits are supported. */
3087 if (start_ccb->cdbg.flags & ~(CAM_DEBUG_COMPILE)) {
3088 start_ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3089 break;
3090 }
3091
3093 if (cam_dpath != NULL) {
3094 oldpath = cam_dpath;
3095 cam_dpath = NULL;
3096 xpt_free_path(oldpath);
3097 }
3098 if (start_ccb->cdbg.flags != CAM_DEBUG_NONE) {
3099 if (xpt_create_path(&cam_dpath, NULL,
3100 start_ccb->ccb_h.path_id,
3101 start_ccb->ccb_h.target_id,
3102 start_ccb->ccb_h.target_lun) !=
3103 CAM_REQ_CMP) {
3104 start_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
3105 } else {
3106 cam_dflags = start_ccb->cdbg.flags;
3107 start_ccb->ccb_h.status = CAM_REQ_CMP;
3108 xpt_print(cam_dpath, "debugging flags now %x\n",
3109 cam_dflags);
3110 }
3111 } else
3112 start_ccb->ccb_h.status = CAM_REQ_CMP;
3113 break;
3114 }
3115 case XPT_NOOP:
3116 if ((start_ccb->ccb_h.flags & CAM_DEV_QFREEZE) != 0)
3117 xpt_freeze_devq(path, 1);
3118 start_ccb->ccb_h.status = CAM_REQ_CMP;
3119 break;
3120 case XPT_REPROBE_LUN:
3121 xpt_async(AC_INQ_CHANGED, path, NULL);
3122 start_ccb->ccb_h.status = CAM_REQ_CMP;
3123 xpt_done(start_ccb);
3124 break;
3125 case XPT_ASYNC:
3126 /*
3127 * Queue the async operation so it can be run from a sleepable
3128 * context.
3129 */
3130 start_ccb->ccb_h.status = CAM_REQ_CMP;
3131 mtx_lock(&cam_async.cam_doneq_mtx);
3132 STAILQ_INSERT_TAIL(&cam_async.cam_doneq, &start_ccb->ccb_h, sim_links.stqe);
3133 start_ccb->ccb_h.pinfo.index = CAM_ASYNC_INDEX;
3134 mtx_unlock(&cam_async.cam_doneq_mtx);
3135 wakeup(&cam_async.cam_doneq);
3136 break;
3137 default:
3138 case XPT_SDEV_TYPE:
3139 case XPT_TERM_IO:
3140 case XPT_ENG_INQ:
3141 /* XXX Implement */
3142 xpt_print(start_ccb->ccb_h.path,
3143 "%s: CCB type %#x %s not supported\n", __func__,
3144 start_ccb->ccb_h.func_code,
3145 xpt_action_name(start_ccb->ccb_h.func_code));
3146 start_ccb->ccb_h.status = CAM_PROVIDE_FAIL;
3147 if (start_ccb->ccb_h.func_code & XPT_FC_DEV_QUEUED) {
3148 xpt_done(start_ccb);
3149 }
3150 break;
3151 }
3153 ("xpt_action_default: func= %#x %s status %#x\n",
3154 start_ccb->ccb_h.func_code,
3155 xpt_action_name(start_ccb->ccb_h.func_code),
3156 start_ccb->ccb_h.status));
3157}
3158
3159/*
3160 * Call the sim poll routine to allow the sim to complete
3161 * any inflight requests, then call camisr_runqueue to
3162 * complete any CCB that the polling completed.
3163 */
3164void
3166{
3167 struct mtx *mtx;
3168
3169 KASSERT(cam_sim_pollable(sim), ("%s: non-pollable sim", __func__));
3170 mtx = sim->mtx;
3171 if (mtx)
3172 mtx_lock(mtx);
3173 (*(sim->sim_poll))(sim);
3174 if (mtx)
3175 mtx_unlock(mtx);
3177}
3178
3179uint32_t
3180xpt_poll_setup(union ccb *start_ccb)
3181{
3182 u_int32_t timeout;
3183 struct cam_sim *sim;
3184 struct cam_devq *devq;
3185 struct cam_ed *dev;
3186
3187 timeout = start_ccb->ccb_h.timeout * 10;
3188 sim = start_ccb->ccb_h.path->bus->sim;
3189 devq = sim->devq;
3190 dev = start_ccb->ccb_h.path->device;
3191
3192 KASSERT(cam_sim_pollable(sim), ("%s: non-pollable sim", __func__));
3193
3194 /*
3195 * Steal an opening so that no other queued requests
3196 * can get it before us while we simulate interrupts.
3197 */
3198 mtx_lock(&devq->send_mtx);
3199 dev->ccbq.dev_openings--;
3200 while((devq->send_openings <= 0 || dev->ccbq.dev_openings < 0) &&
3201 (--timeout > 0)) {
3202 mtx_unlock(&devq->send_mtx);
3203 DELAY(100);
3205 mtx_lock(&devq->send_mtx);
3206 }
3207 dev->ccbq.dev_openings++;
3208 mtx_unlock(&devq->send_mtx);
3209
3210 return (timeout);
3211}
3212
3213void
3214xpt_pollwait(union ccb *start_ccb, uint32_t timeout)
3215{
3216
3217 KASSERT(cam_sim_pollable(start_ccb->ccb_h.path->bus->sim),
3218 ("%s: non-pollable sim", __func__));
3219 while (--timeout > 0) {
3220 xpt_sim_poll(start_ccb->ccb_h.path->bus->sim);
3221 if ((start_ccb->ccb_h.status & CAM_STATUS_MASK)
3222 != CAM_REQ_INPROG)
3223 break;
3224 DELAY(100);
3225 }
3226
3227 if (timeout == 0) {
3228 /*
3229 * XXX Is it worth adding a sim_timeout entry
3230 * point so we can attempt recovery? If
3231 * this is only used for dumps, I don't think
3232 * it is.
3233 */
3234 start_ccb->ccb_h.status = CAM_CMD_TIMEOUT;
3235 }
3236}
3237
3238/*
3239 * Schedule a peripheral driver to receive a ccb when its
3240 * target device has space for more transactions.
3241 */
3242void
3243xpt_schedule(struct cam_periph *periph, u_int32_t new_priority)
3244{
3245
3246 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("xpt_schedule\n"));
3247 cam_periph_assert(periph, MA_OWNED);
3248 if (new_priority < periph->scheduled_priority) {
3249 periph->scheduled_priority = new_priority;
3250 xpt_run_allocq(periph, 0);
3251 }
3252}
3253
3254/*
3255 * Schedule a device to run on a given queue.
3256 * If the device was inserted as a new entry on the queue,
3257 * return 1 meaning the device queue should be run. If we
3258 * were already queued, implying someone else has already
3259 * started the queue, return 0 so the caller doesn't attempt
3260 * to run the queue.
3261 */
3262static int
3263xpt_schedule_dev(struct camq *queue, cam_pinfo *pinfo,
3264 u_int32_t new_priority)
3265{
3266 int retval;
3267 u_int32_t old_priority;
3268
3269 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_schedule_dev\n"));
3270
3271 old_priority = pinfo->priority;
3272
3273 /*
3274 * Are we already queued?
3275 */
3276 if (pinfo->index != CAM_UNQUEUED_INDEX) {
3277 /* Simply reorder based on new priority */
3278 if (new_priority < old_priority) {
3279 camq_change_priority(queue, pinfo->index,
3280 new_priority);
3282 ("changed priority to %d\n",
3283 new_priority));
3284 retval = 1;
3285 } else
3286 retval = 0;
3287 } else {
3288 /* New entry on the queue */
3289 if (new_priority < old_priority)
3290 pinfo->priority = new_priority;
3291
3293 ("Inserting onto queue\n"));
3294 pinfo->generation = ++queue->generation;
3295 camq_insert(queue, pinfo);
3296 retval = 1;
3297 }
3298 return (retval);
3299}
3300
3301static void
3302xpt_run_allocq_task(void *context, int pending)
3303{
3304 struct cam_periph *periph = context;
3305
3306 cam_periph_lock(periph);
3307 periph->flags &= ~CAM_PERIPH_RUN_TASK;
3308 xpt_run_allocq(periph, 1);
3309 cam_periph_unlock(periph);
3310 cam_periph_release(periph);
3311}
3312
3313static void
3314xpt_run_allocq(struct cam_periph *periph, int sleep)
3315{
3316 struct cam_ed *device;
3317 union ccb *ccb;
3318 uint32_t prio;
3319
3320 cam_periph_assert(periph, MA_OWNED);
3321 if (periph->periph_allocating)
3322 return;
3323 cam_periph_doacquire(periph);
3324 periph->periph_allocating = 1;
3325 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_allocq(%p)\n", periph));
3326 device = periph->path->device;
3327 ccb = NULL;
3328restart:
3329 while ((prio = min(periph->scheduled_priority,
3331 (periph->periph_allocated - (ccb != NULL ? 1 : 0) <
3332 device->ccbq.total_openings || prio <= CAM_PRIORITY_OOB)) {
3333 if (ccb == NULL &&
3334 (ccb = xpt_get_ccb_nowait(periph)) == NULL) {
3335 if (sleep) {
3336 ccb = xpt_get_ccb(periph);
3337 goto restart;
3338 }
3339 if (periph->flags & CAM_PERIPH_RUN_TASK)
3340 break;
3341 cam_periph_doacquire(periph);
3342 periph->flags |= CAM_PERIPH_RUN_TASK;
3343 taskqueue_enqueue(xsoftc.xpt_taskq,
3344 &periph->periph_run_task);
3345 break;
3346 }
3347 xpt_setup_ccb(&ccb->ccb_h, periph->path, prio);
3348 if (prio == periph->immediate_priority) {
3351 ("waking cam_periph_getccb()\n"));
3352 SLIST_INSERT_HEAD(&periph->ccb_list, &ccb->ccb_h,
3353 periph_links.sle);
3354 wakeup(&periph->ccb_list);
3355 } else {
3358 ("calling periph_start()\n"));
3359 periph->periph_start(periph, ccb);
3360 }
3361 ccb = NULL;
3362 }
3363 if (ccb != NULL)
3365 periph->periph_allocating = 0;
3367}
3368
3369static void
3371{
3372 struct mtx *mtx;
3373
3374 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_devq\n"));
3375
3376 devq->send_queue.qfrozen_cnt++;
3377 while ((devq->send_queue.entries > 0)
3378 && (devq->send_openings > 0)
3379 && (devq->send_queue.qfrozen_cnt <= 1)) {
3380 struct cam_ed *device;
3381 union ccb *work_ccb;
3382 struct cam_sim *sim;
3383 struct xpt_proto *proto;
3384
3385 device = (struct cam_ed *)camq_remove(&devq->send_queue,
3386 CAMQ_HEAD);
3388 ("running device %p\n", device));
3389
3390 work_ccb = cam_ccbq_peek_ccb(&device->ccbq, CAMQ_HEAD);
3391 if (work_ccb == NULL) {
3392 printf("device on run queue with no ccbs???\n");
3393 continue;
3394 }
3395
3396 if ((work_ccb->ccb_h.flags & CAM_HIGH_POWER) != 0) {
3397 mtx_lock(&xsoftc.xpt_highpower_lock);
3398 if (xsoftc.num_highpower <= 0) {
3399 /*
3400 * We got a high power command, but we
3401 * don't have any available slots. Freeze
3402 * the device queue until we have a slot
3403 * available.
3404 */
3405 xpt_freeze_devq_device(device, 1);
3406 STAILQ_INSERT_TAIL(&xsoftc.highpowerq, device,
3407 highpowerq_entry);
3408
3409 mtx_unlock(&xsoftc.xpt_highpower_lock);
3410 continue;
3411 } else {
3412 /*
3413 * Consume a high power slot while
3414 * this ccb runs.
3415 */
3416 xsoftc.num_highpower--;
3417 }
3418 mtx_unlock(&xsoftc.xpt_highpower_lock);
3419 }
3420 cam_ccbq_remove_ccb(&device->ccbq, work_ccb);
3421 cam_ccbq_send_ccb(&device->ccbq, work_ccb);
3422 devq->send_openings--;
3423 devq->send_active++;
3424 xpt_schedule_devq(devq, device);
3425 mtx_unlock(&devq->send_mtx);
3426
3427 if ((work_ccb->ccb_h.flags & CAM_DEV_QFREEZE) != 0) {
3428 /*
3429 * The client wants to freeze the queue
3430 * after this CCB is sent.
3431 */
3432 xpt_freeze_devq(work_ccb->ccb_h.path, 1);
3433 }
3434
3435 /* In Target mode, the peripheral driver knows best... */
3436 if (work_ccb->ccb_h.func_code == XPT_SCSI_IO) {
3437 if ((device->inq_flags & SID_CmdQue) != 0
3438 && work_ccb->csio.tag_action != CAM_TAG_ACTION_NONE)
3439 work_ccb->ccb_h.flags |= CAM_TAG_ACTION_VALID;
3440 else
3441 /*
3442 * Clear this in case of a retried CCB that
3443 * failed due to a rejected tag.
3444 */
3445 work_ccb->ccb_h.flags &= ~CAM_TAG_ACTION_VALID;
3446 }
3447
3448 KASSERT(device == work_ccb->ccb_h.path->device,
3449 ("device (%p) / path->device (%p) mismatch",
3450 device, work_ccb->ccb_h.path->device));
3451 proto = xpt_proto_find(device->protocol);
3452 if (proto && proto->ops->debug_out)
3453 proto->ops->debug_out(work_ccb);
3454
3455 /*
3456 * Device queues can be shared among multiple SIM instances
3457 * that reside on different buses. Use the SIM from the
3458 * queued device, rather than the one from the calling bus.
3459 */
3460 sim = device->sim;
3461 mtx = sim->mtx;
3462 if (mtx && !mtx_owned(mtx))
3463 mtx_lock(mtx);
3464 else
3465 mtx = NULL;
3466 work_ccb->ccb_h.qos.periph_data = cam_iosched_now();
3467 (*(sim->sim_action))(sim, work_ccb);
3468 if (mtx)
3469 mtx_unlock(mtx);
3470 mtx_lock(&devq->send_mtx);
3471 }
3472 devq->send_queue.qfrozen_cnt--;
3473}
3474
3475/*
3476 * This function merges stuff from the src ccb into the dst ccb, while keeping
3477 * important fields in the dst ccb constant.
3478 */
3479void
3480xpt_merge_ccb(union ccb *dst_ccb, union ccb *src_ccb)
3481{
3482
3483 /*
3484 * Pull fields that are valid for peripheral drivers to set
3485 * into the dst CCB along with the CCB "payload".
3486 */
3487 dst_ccb->ccb_h.retry_count = src_ccb->ccb_h.retry_count;
3488 dst_ccb->ccb_h.func_code = src_ccb->ccb_h.func_code;
3489 dst_ccb->ccb_h.timeout = src_ccb->ccb_h.timeout;
3490 dst_ccb->ccb_h.flags = src_ccb->ccb_h.flags;
3491 bcopy(&(&src_ccb->ccb_h)[1], &(&dst_ccb->ccb_h)[1],
3492 sizeof(union ccb) - sizeof(struct ccb_hdr));
3493}
3494
3495void
3496xpt_setup_ccb_flags(struct ccb_hdr *ccb_h, struct cam_path *path,
3497 u_int32_t priority, u_int32_t flags)
3498{
3499
3500 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_setup_ccb\n"));
3501 ccb_h->pinfo.priority = priority;
3502 ccb_h->path = path;
3503 ccb_h->path_id = path->bus->path_id;
3504 if (path->target)
3505 ccb_h->target_id = path->target->target_id;
3506 else
3508 if (path->device) {
3509 ccb_h->target_lun = path->device->lun_id;
3510 ccb_h->pinfo.generation = ++path->device->ccbq.queue.generation;
3511 } else {
3513 }
3515 ccb_h->flags = flags;
3516 ccb_h->xflags = 0;
3517}
3518
3519void
3520xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
3521{
3522 xpt_setup_ccb_flags(ccb_h, path, priority, /*flags*/ 0);
3523}
3524
3525/* Path manipulation functions */
3527xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph,
3528 path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
3529{
3530 struct cam_path *path;
3531 cam_status status;
3532
3533 path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT);
3534
3535 if (path == NULL) {
3536 status = CAM_RESRC_UNAVAIL;
3537 return(status);
3538 }
3539 status = xpt_compile_path(path, perph, path_id, target_id, lun_id);
3540 if (status != CAM_REQ_CMP) {
3541 free(path, M_CAMPATH);
3542 path = NULL;
3543 }
3544 *new_path_ptr = path;
3545 return (status);
3546}
3547
3550 struct cam_periph *periph, path_id_t path_id,
3551 target_id_t target_id, lun_id_t lun_id)
3552{
3553
3554 return (xpt_create_path(new_path_ptr, periph, path_id, target_id,
3555 lun_id));
3556}
3557
3559xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph,
3560 path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
3561{
3562 struct cam_eb *bus;
3563 struct cam_et *target;
3564 struct cam_ed *device;
3565 cam_status status;
3566
3567 status = CAM_REQ_CMP; /* Completed without error */
3568 target = NULL; /* Wildcarded */
3569 device = NULL; /* Wildcarded */
3570
3571 /*
3572 * We will potentially modify the EDT, so block interrupts
3573 * that may attempt to create cam paths.
3574 */
3575 bus = xpt_find_bus(path_id);
3576 if (bus == NULL) {
3577 status = CAM_PATH_INVALID;
3578 } else {
3580 mtx_lock(&bus->eb_mtx);
3581 target = xpt_find_target(bus, target_id);
3582 if (target == NULL) {
3583 /* Create one */
3584 struct cam_et *new_target;
3585
3586 new_target = xpt_alloc_target(bus, target_id);
3587 if (new_target == NULL) {
3588 status = CAM_RESRC_UNAVAIL;
3589 } else {
3590 target = new_target;
3591 }
3592 }
3594 if (target != NULL) {
3595 device = xpt_find_device(target, lun_id);
3596 if (device == NULL) {
3597 /* Create one */
3598 struct cam_ed *new_device;
3599
3600 new_device =
3601 (*(bus->xport->ops->alloc_device))(bus,
3602 target,
3603 lun_id);
3604 if (new_device == NULL) {
3605 status = CAM_RESRC_UNAVAIL;
3606 } else {
3607 device = new_device;
3608 }
3609 }
3610 }
3611 mtx_unlock(&bus->eb_mtx);
3612 }
3613
3614 /*
3615 * Only touch the user's data if we are successful.
3616 */
3617 if (status == CAM_REQ_CMP) {
3618 new_path->periph = perph;
3619 new_path->bus = bus;
3620 new_path->target = target;
3621 new_path->device = device;
3622 CAM_DEBUG(new_path, CAM_DEBUG_TRACE, ("xpt_compile_path\n"));
3623 } else {
3624 if (device != NULL)
3625 xpt_release_device(device);
3626 if (target != NULL)
3628 if (bus != NULL)
3629 xpt_release_bus(bus);
3630 }
3631 return (status);
3632}
3633
3634int
3635xpt_clone_path(struct cam_path **new_path_ptr, struct cam_path *path)
3636{
3637 struct cam_path *new_path;
3638
3639 new_path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT);
3640 if (new_path == NULL)
3641 return (ENOMEM);
3642 *new_path = *path;
3643 if (path->bus != NULL)
3644 xpt_acquire_bus(path->bus);
3645 if (path->target != NULL)
3647 if (path->device != NULL)
3649 *new_path_ptr = new_path;
3650 return (0);
3651}
3652
3653void
3655{
3656 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_release_path\n"));
3657 if (path->device != NULL) {
3659 path->device = NULL;
3660 }
3661 if (path->target != NULL) {
3663 path->target = NULL;
3664 }
3665 if (path->bus != NULL) {
3666 xpt_release_bus(path->bus);
3667 path->bus = NULL;
3668 }
3669}
3670
3671void
3673{
3674
3675 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_free_path\n"));
3676 xpt_release_path(path);
3677 free(path, M_CAMPATH);
3678}
3679
3680void
3681xpt_path_counts(struct cam_path *path, uint32_t *bus_ref,
3682 uint32_t *periph_ref, uint32_t *target_ref, uint32_t *device_ref)
3683{
3684
3686 if (bus_ref) {
3687 if (path->bus)
3688 *bus_ref = path->bus->refcount;
3689 else
3690 *bus_ref = 0;
3691 }
3692 if (periph_ref) {
3693 if (path->periph)
3694 *periph_ref = path->periph->refcount;
3695 else
3696 *periph_ref = 0;
3697 }
3699 if (target_ref) {
3700 if (path->target)
3701 *target_ref = path->target->refcount;
3702 else
3703 *target_ref = 0;
3704 }
3705 if (device_ref) {
3706 if (path->device)
3707 *device_ref = path->device->refcount;
3708 else
3709 *device_ref = 0;
3710 }
3711}
3712
3713/*
3714 * Return -1 for failure, 0 for exact match, 1 for match with wildcards
3715 * in path1, 2 for match with wildcards in path2.
3716 */
3717int
3718xpt_path_comp(struct cam_path *path1, struct cam_path *path2)
3719{
3720 int retval = 0;
3721
3722 if (path1->bus != path2->bus) {
3723 if (path1->bus->path_id == CAM_BUS_WILDCARD)
3724 retval = 1;
3725 else if (path2->bus->path_id == CAM_BUS_WILDCARD)
3726 retval = 2;
3727 else
3728 return (-1);
3729 }
3730 if (path1->target != path2->target) {
3731 if (path1->target->target_id == CAM_TARGET_WILDCARD) {
3732 if (retval == 0)
3733 retval = 1;
3734 } else if (path2->target->target_id == CAM_TARGET_WILDCARD)
3735 retval = 2;
3736 else
3737 return (-1);
3738 }
3739 if (path1->device != path2->device) {
3740 if (path1->device->lun_id == CAM_LUN_WILDCARD) {
3741 if (retval == 0)
3742 retval = 1;
3743 } else if (path2->device->lun_id == CAM_LUN_WILDCARD)
3744 retval = 2;
3745 else
3746 return (-1);
3747 }
3748 return (retval);
3749}
3750
3751int
3752xpt_path_comp_dev(struct cam_path *path, struct cam_ed *dev)
3753{
3754 int retval = 0;
3755
3756 if (path->bus != dev->target->bus) {
3757 if (path->bus->path_id == CAM_BUS_WILDCARD)
3758 retval = 1;
3759 else if (dev->target->bus->path_id == CAM_BUS_WILDCARD)
3760 retval = 2;
3761 else
3762 return (-1);
3763 }
3764 if (path->target != dev->target) {
3765 if (path->target->target_id == CAM_TARGET_WILDCARD) {
3766 if (retval == 0)
3767 retval = 1;
3768 } else if (dev->target->target_id == CAM_TARGET_WILDCARD)
3769 retval = 2;
3770 else
3771 return (-1);
3772 }
3773 if (path->device != dev) {
3774 if (path->device->lun_id == CAM_LUN_WILDCARD) {
3775 if (retval == 0)
3776 retval = 1;
3777 } else if (dev->lun_id == CAM_LUN_WILDCARD)
3778 retval = 2;
3779 else
3780 return (-1);
3781 }
3782 return (retval);
3783}
3784
3785void
3787{
3788 struct sbuf sb;
3789 char buffer[XPT_PRINT_LEN];
3790
3791 sbuf_new(&sb, buffer, XPT_PRINT_LEN, SBUF_FIXEDLEN);
3792 xpt_path_sbuf(path, &sb);
3793 sbuf_finish(&sb);
3794 printf("%s", sbuf_data(&sb));
3795 sbuf_delete(&sb);
3796}
3797
3798void
3800{
3801
3802 if (device == NULL)
3803 printf("(nopath): ");
3804 else {
3805 printf("(noperiph:%s%d:%d:%d:%jx): ", device->sim->sim_name,
3806 device->sim->unit_number,
3807 device->sim->bus_id,
3808 device->target->target_id,
3809 (uintmax_t)device->lun_id);
3810 }
3811}
3812
3813void
3814xpt_print(struct cam_path *path, const char *fmt, ...)
3815{
3816 va_list ap;
3817 struct sbuf sb;
3818 char buffer[XPT_PRINT_LEN];
3819
3820 sbuf_new(&sb, buffer, XPT_PRINT_LEN, SBUF_FIXEDLEN);
3821
3822 xpt_path_sbuf(path, &sb);
3823 va_start(ap, fmt);
3824 sbuf_vprintf(&sb, fmt, ap);
3825 va_end(ap);
3826
3827 sbuf_finish(&sb);
3828 printf("%s", sbuf_data(&sb));
3829 sbuf_delete(&sb);
3830}
3831
3832int
3833xpt_path_string(struct cam_path *path, char *str, size_t str_len)
3834{
3835 struct sbuf sb;
3836 int len;
3837
3838 sbuf_new(&sb, str, str_len, 0);
3839 len = xpt_path_sbuf(path, &sb);
3840 sbuf_finish(&sb);
3841 return (len);
3842}
3843
3844int
3845xpt_path_sbuf(struct cam_path *path, struct sbuf *sb)
3846{
3847
3848 if (path == NULL)
3849 sbuf_printf(sb, "(nopath): ");
3850 else {
3851 if (path->periph != NULL)
3852 sbuf_printf(sb, "(%s%d:", path->periph->periph_name,
3853 path->periph->unit_number);
3854 else
3855 sbuf_printf(sb, "(noperiph:");
3856
3857 if (path->bus != NULL)
3858 sbuf_printf(sb, "%s%d:%d:", path->bus->sim->sim_name,
3859 path->bus->sim->unit_number,
3860 path->bus->sim->bus_id);
3861 else
3862 sbuf_printf(sb, "nobus:");
3863
3864 if (path->target != NULL)
3865 sbuf_printf(sb, "%d:", path->target->target_id);
3866 else
3867 sbuf_printf(sb, "X:");
3868
3869 if (path->device != NULL)
3870 sbuf_printf(sb, "%jx): ",
3871 (uintmax_t)path->device->lun_id);
3872 else
3873 sbuf_printf(sb, "X): ");
3874 }
3875
3876 return(sbuf_len(sb));
3877}
3878
3881{
3882 return(path->bus->path_id);
3883}
3884
3887{
3888 if (path->target != NULL)
3889 return (path->target->target_id);
3890 else
3891 return (CAM_TARGET_WILDCARD);
3892}
3893
3896{
3897 if (path->device != NULL)
3898 return (path->device->lun_id);
3899 else
3900 return (CAM_LUN_WILDCARD);
3901}
3902
3903struct cam_sim *
3905{
3906
3907 return (path->bus->sim);
3908}
3909
3910struct cam_periph*
3912{
3913
3914 return (path->periph);
3915}
3916
3917/*
3918 * Release a CAM control block for the caller. Remit the cost of the structure
3919 * to the device referenced by the path. If the this device had no 'credits'
3920 * and peripheral drivers have registered async callbacks for this notification
3921 * call them now.
3922 */
3923void
3924xpt_release_ccb(union ccb *free_ccb)
3925{
3926 struct cam_ed *device;
3927 struct cam_periph *periph;
3928
3929 CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_release_ccb\n"));
3930 xpt_path_assert(free_ccb->ccb_h.path, MA_OWNED);
3931 device = free_ccb->ccb_h.path->device;
3932 periph = free_ccb->ccb_h.path->periph;
3933
3934 xpt_free_ccb(free_ccb);
3935 periph->periph_allocated--;
3937 xpt_run_allocq(periph, 0);
3938}
3939
3940/* Functions accessed by SIM drivers */
3941
3944 .action = xpt_action_default,
3945 .async = xpt_dev_async_default,
3946};
3947static struct xpt_xport xport_default = {
3949 .name = "unknown",
3950 .ops = &xport_default_ops,
3951};
3952
3954
3955/*
3956 * A sim structure, listing the SIM entry points and instance
3957 * identification info is passed to xpt_bus_register to hook the SIM
3958 * into the CAM framework. xpt_bus_register creates a cam_eb entry
3959 * for this new bus and places it in the array of buses and assigns
3960 * it a path_id. The path_id may be influenced by "hard wiring"
3961 * information specified by the user. Once interrupt services are
3962 * available, the bus will be probed.
3963 */
3964int
3965xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
3966{
3967 struct cam_eb *new_bus;
3968 struct cam_eb *old_bus;
3969 struct ccb_pathinq cpi;
3970 struct cam_path *path;
3971 cam_status status;
3972
3973 sim->bus_id = bus;
3974 new_bus = (struct cam_eb *)malloc(sizeof(*new_bus),
3975 M_CAMXPT, M_NOWAIT|M_ZERO);
3976 if (new_bus == NULL) {
3977 /* Couldn't satisfy request */
3978 return (ENOMEM);
3979 }
3980
3981 mtx_init(&new_bus->eb_mtx, "CAM bus lock", NULL, MTX_DEF);
3982 TAILQ_INIT(&new_bus->et_entries);
3984 new_bus->sim = sim;
3985 timevalclear(&new_bus->last_reset);
3986 new_bus->flags = 0;
3987 new_bus->refcount = 1; /* Held until a bus_deregister event */
3988 new_bus->generation = 0;
3989 new_bus->parent_dev = parent;
3990
3992 sim->path_id = new_bus->path_id =
3994 old_bus = TAILQ_FIRST(&xsoftc.xpt_busses);
3995 while (old_bus != NULL
3996 && old_bus->path_id < new_bus->path_id)
3997 old_bus = TAILQ_NEXT(old_bus, links);
3998 if (old_bus != NULL)
3999 TAILQ_INSERT_BEFORE(old_bus, new_bus, links);
4000 else
4001 TAILQ_INSERT_TAIL(&xsoftc.xpt_busses, new_bus, links);
4002 xsoftc.bus_generation++;
4004
4005 /*
4006 * Set a default transport so that a PATH_INQ can be issued to
4007 * the SIM. This will then allow for probing and attaching of
4008 * a more appropriate transport.
4009 */
4010 new_bus->xport = &xport_default;
4011
4012 status = xpt_create_path(&path, /*periph*/NULL, sim->path_id,
4014 if (status != CAM_REQ_CMP) {
4015 xpt_release_bus(new_bus);
4016 return (ENOMEM);
4017 }
4018
4019 xpt_path_inq(&cpi, path);
4020
4021 if (cpi.ccb_h.status == CAM_REQ_CMP) {
4022 struct xpt_xport **xpt;
4023
4024 SET_FOREACH(xpt, cam_xpt_xport_set) {
4025 if ((*xpt)->xport == cpi.transport) {
4026 new_bus->xport = *xpt;
4027 break;
4028 }
4029 }
4030 if (new_bus->xport == NULL) {
4031 xpt_print(path,
4032 "No transport found for %d\n", cpi.transport);
4033 xpt_release_bus(new_bus);
4034 free(path, M_CAMXPT);
4035 return (EINVAL);
4036 }
4037 }
4038
4039 /* Notify interested parties */
4040 if (sim->path_id != CAM_XPT_PATH_ID) {
4041 xpt_async(AC_PATH_REGISTERED, path, &cpi);
4042 if ((cpi.hba_misc & PIM_NOSCAN) == 0) {
4043 union ccb *scan_ccb;
4044
4045 /* Initiate bus rescan. */
4046 scan_ccb = xpt_alloc_ccb_nowait();
4047 if (scan_ccb != NULL) {
4048 scan_ccb->ccb_h.path = path;
4049 scan_ccb->ccb_h.func_code = XPT_SCAN_BUS;
4050 scan_ccb->crcn.flags = 0;
4051 xpt_rescan(scan_ccb);
4052 } else {
4053 xpt_print(path,
4054 "Can't allocate CCB to scan bus\n");
4055 xpt_free_path(path);
4056 }
4057 } else
4058 xpt_free_path(path);
4059 } else
4060 xpt_free_path(path);
4061 return (CAM_SUCCESS);
4062}
4063
4064int
4066{
4067 struct cam_path bus_path;
4068 cam_status status;
4069
4070 status = xpt_compile_path(&bus_path, NULL, pathid,
4072 if (status != CAM_REQ_CMP)
4073 return (ENOMEM);
4074
4075 xpt_async(AC_LOST_DEVICE, &bus_path, NULL);
4076 xpt_async(AC_PATH_DEREGISTERED, &bus_path, NULL);
4077
4078 /* Release the reference count held while registered. */
4079 xpt_release_bus(bus_path.bus);
4080 xpt_release_path(&bus_path);
4081
4082 return (CAM_SUCCESS);
4083}
4084
4085static path_id_t
4087{
4088 struct cam_eb *bus;
4089 path_id_t pathid;
4090 const char *strval;
4091
4092 mtx_assert(&xsoftc.xpt_topo_lock, MA_OWNED);
4093 pathid = 0;
4094 bus = TAILQ_FIRST(&xsoftc.xpt_busses);
4095retry:
4096 /* Find an unoccupied pathid */
4097 while (bus != NULL && bus->path_id <= pathid) {
4098 if (bus->path_id == pathid)
4099 pathid++;
4100 bus = TAILQ_NEXT(bus, links);
4101 }
4102
4103 /*
4104 * Ensure that this pathid is not reserved for
4105 * a bus that may be registered in the future.
4106 */
4107 if (resource_string_value("scbus", pathid, "at", &strval) == 0) {
4108 ++pathid;
4109 /* Start the search over */
4110 goto retry;
4111 }
4112 return (pathid);
4113}
4114
4115static path_id_t
4116xptpathid(const char *sim_name, int sim_unit, int sim_bus)
4117{
4118 path_id_t pathid;
4119 int i, dunit, val;
4120 char buf[32];
4121 const char *dname;
4122
4123 pathid = CAM_XPT_PATH_ID;
4124 snprintf(buf, sizeof(buf), "%s%d", sim_name, sim_unit);
4125 if (strcmp(buf, "xpt0") == 0 && sim_bus == 0)
4126 return (pathid);
4127 i = 0;
4128 while ((resource_find_match(&i, &dname, &dunit, "at", buf)) == 0) {
4129 if (strcmp(dname, "scbus")) {
4130 /* Avoid a bit of foot shooting. */
4131 continue;
4132 }
4133 if (dunit < 0) /* unwired?! */
4134 continue;
4135 if (resource_int_value("scbus", dunit, "bus", &val) == 0) {
4136 if (sim_bus == val) {
4137 pathid = dunit;
4138 break;
4139 }
4140 } else if (sim_bus == 0) {
4141 /* Unspecified matches bus 0 */
4142 pathid = dunit;
4143 break;
4144 } else {
4145 printf("Ambiguous scbus configuration for %s%d "
4146 "bus %d, cannot wire down. The kernel "
4147 "config entry for scbus%d should "
4148 "specify a controller bus.\n"
4149 "Scbus will be assigned dynamically.\n",
4150 sim_name, sim_unit, sim_bus, dunit);
4151 break;
4152 }
4153 }
4154
4155 if (pathid == CAM_XPT_PATH_ID)
4156 pathid = xptnextfreepathid();
4157 return (pathid);
4158}
4159
4160static const char *
4161xpt_async_string(u_int32_t async_code)
4162{
4163
4164 switch (async_code) {
4165 case AC_BUS_RESET: return ("AC_BUS_RESET");
4166 case AC_UNSOL_RESEL: return ("AC_UNSOL_RESEL");
4167 case AC_SCSI_AEN: return ("AC_SCSI_AEN");
4168 case AC_SENT_BDR: return ("AC_SENT_BDR");
4169 case AC_PATH_REGISTERED: return ("AC_PATH_REGISTERED");
4170 case AC_PATH_DEREGISTERED: return ("AC_PATH_DEREGISTERED");
4171 case AC_FOUND_DEVICE: return ("AC_FOUND_DEVICE");
4172 case AC_LOST_DEVICE: return ("AC_LOST_DEVICE");
4173 case AC_TRANSFER_NEG: return ("AC_TRANSFER_NEG");
4174 case AC_INQ_CHANGED: return ("AC_INQ_CHANGED");
4175 case AC_GETDEV_CHANGED: return ("AC_GETDEV_CHANGED");
4176 case AC_CONTRACT: return ("AC_CONTRACT");
4177 case AC_ADVINFO_CHANGED: return ("AC_ADVINFO_CHANGED");
4178 case AC_UNIT_ATTENTION: return ("AC_UNIT_ATTENTION");
4179 }
4180 return ("AC_UNKNOWN");
4181}
4182
4183static int
4184xpt_async_size(u_int32_t async_code)
4185{
4186
4187 switch (async_code) {
4188 case AC_BUS_RESET: return (0);
4189 case AC_UNSOL_RESEL: return (0);
4190 case AC_SCSI_AEN: return (0);
4191 case AC_SENT_BDR: return (0);
4192 case AC_PATH_REGISTERED: return (sizeof(struct ccb_pathinq));
4193 case AC_PATH_DEREGISTERED: return (0);
4194 case AC_FOUND_DEVICE: return (sizeof(struct ccb_getdev));
4195 case AC_LOST_DEVICE: return (0);
4196 case AC_TRANSFER_NEG: return (sizeof(struct ccb_trans_settings));
4197 case AC_INQ_CHANGED: return (0);
4198 case AC_GETDEV_CHANGED: return (0);
4199 case AC_CONTRACT: return (sizeof(struct ac_contract));
4200 case AC_ADVINFO_CHANGED: return (-1);
4201 case AC_UNIT_ATTENTION: return (sizeof(struct ccb_scsiio));
4202 }
4203 return (0);
4204}
4205
4206static int
4207xpt_async_process_dev(struct cam_ed *device, void *arg)
4208{
4209 union ccb *ccb = arg;
4210 struct cam_path *path = ccb->ccb_h.path;
4211 void *async_arg = ccb->casync.async_arg_ptr;
4212 u_int32_t async_code = ccb->casync.async_code;
4213 int relock;
4214
4215 if (path->device != device
4216 && path->device->lun_id != CAM_LUN_WILDCARD
4218 return (1);
4219
4220 /*
4221 * The async callback could free the device.
4222 * If it is a broadcast async, it doesn't hold
4223 * device reference, so take our own reference.
4224 */
4226
4227 /*
4228 * If async for specific device is to be delivered to
4229 * the wildcard client, take the specific device lock.
4230 * XXX: We may need a way for client to specify it.
4231 */
4232 if ((device->lun_id == CAM_LUN_WILDCARD &&
4233 path->device->lun_id != CAM_LUN_WILDCARD) ||
4237 path->target->bus->path_id != CAM_BUS_WILDCARD)) {
4238 mtx_unlock(&device->device_mtx);
4239 xpt_path_lock(path);
4240 relock = 1;
4241 } else
4242 relock = 0;
4243
4244 (*(device->target->bus->xport->ops->async))(async_code,
4245 device->target->bus, device->target, device, async_arg);
4246 xpt_async_bcast(&device->asyncs, async_code, path, async_arg);
4247
4248 if (relock) {
4249 xpt_path_unlock(path);
4250 mtx_lock(&device->device_mtx);
4251 }
4253 return (1);
4254}
4255
4256static int
4258{
4259 union ccb *ccb = arg;
4260 struct cam_path *path = ccb->ccb_h.path;
4261
4262 if (path->target != target
4265 return (1);
4266
4267 if (ccb->casync.async_code == AC_SENT_BDR) {
4268 /* Update our notion of when the last reset occurred */
4269 microtime(&target->last_reset);
4270 }
4271
4273}
4274
4275static void
4277{
4278 struct cam_eb *bus;
4279 struct cam_path *path;
4280 void *async_arg;
4281 u_int32_t async_code;
4282
4283 path = ccb->ccb_h.path;
4284 async_code = ccb->casync.async_code;
4285 async_arg = ccb->casync.async_arg_ptr;
4287 ("xpt_async(%s)\n", xpt_async_string(async_code)));
4288 bus = path->bus;
4289
4290 if (async_code == AC_BUS_RESET) {
4291 /* Update our notion of when the last reset occurred */
4292 microtime(&bus->last_reset);
4293 }
4294
4296
4297 /*
4298 * If this wasn't a fully wildcarded async, tell all
4299 * clients that want all async events.
4300 */
4301 if (bus != xpt_periph->path->bus) {
4305 }
4306
4307 if (path->device != NULL && path->device->lun_id != CAM_LUN_WILDCARD)
4308 xpt_release_devq(path, 1, TRUE);
4309 else
4310 xpt_release_simq(path->bus->sim, TRUE);
4311 if (ccb->casync.async_arg_size > 0)
4312 free(async_arg, M_CAMXPT);
4313 xpt_free_path(path);
4315}
4316
4317static void
4318xpt_async_bcast(struct async_list *async_head,
4319 u_int32_t async_code,
4320 struct cam_path *path, void *async_arg)
4321{
4322 struct async_node *cur_entry;
4323 struct mtx *mtx;
4324
4325 cur_entry = SLIST_FIRST(async_head);
4326 while (cur_entry != NULL) {
4327 struct async_node *next_entry;
4328 /*
4329 * Grab the next list entry before we call the current
4330 * entry's callback. This is because the callback function
4331 * can delete its async callback entry.
4332 */
4333 next_entry = SLIST_NEXT(cur_entry, links);
4334 if ((cur_entry->event_enable & async_code) != 0) {
4335 mtx = cur_entry->event_lock ?
4336 path->device->sim->mtx : NULL;
4337 if (mtx)
4338 mtx_lock(mtx);
4339 cur_entry->callback(cur_entry->callback_arg,
4340 async_code, path,
4341 async_arg);
4342 if (mtx)
4343 mtx_unlock(mtx);
4344 }
4345 cur_entry = next_entry;
4346 }
4347}
4348
4349void
4350xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
4351{
4352 union ccb *ccb;
4353 int size;
4354
4356 if (ccb == NULL) {
4357 xpt_print(path, "Can't allocate CCB to send %s\n",
4358 xpt_async_string(async_code));
4359 return;
4360 }
4361
4362 if (xpt_clone_path(&ccb->ccb_h.path, path) != 0) {
4363 xpt_print(path, "Can't allocate path to send %s\n",
4364 xpt_async_string(async_code));
4366 return;
4367 }
4368 ccb->ccb_h.path->periph = NULL;
4372 ccb->casync.async_code = async_code;
4374 size = xpt_async_size(async_code);
4376 ("xpt_async: func %#x %s aync_code %d %s\n",
4379 async_code,
4380 xpt_async_string(async_code)));
4381 if (size > 0 && async_arg != NULL) {
4382 ccb->casync.async_arg_ptr = malloc(size, M_CAMXPT, M_NOWAIT);
4383 if (ccb->casync.async_arg_ptr == NULL) {
4384 xpt_print(path, "Can't allocate argument to send %s\n",
4385 xpt_async_string(async_code));
4388 return;
4389 }
4390 memcpy(ccb->casync.async_arg_ptr, async_arg, size);
4391 ccb->casync.async_arg_size = size;
4392 } else if (size < 0) {
4393 ccb->casync.async_arg_ptr = async_arg;
4394 ccb->casync.async_arg_size = size;
4395 }
4396 if (path->device != NULL && path->device->lun_id != CAM_LUN_WILDCARD)
4397 xpt_freeze_devq(path, 1);
4398 else
4399 xpt_freeze_simq(path->bus->sim, 1);
4400 xpt_action(ccb);
4401}
4402
4403static void
4404xpt_dev_async_default(u_int32_t async_code, struct cam_eb *bus,
4405 struct cam_et *target, struct cam_ed *device,
4406 void *async_arg)
4407{
4408
4409 /*
4410 * We only need to handle events for real devices.
4411 */
4412 if (target->target_id == CAM_TARGET_WILDCARD
4413 || device->lun_id == CAM_LUN_WILDCARD)
4414 return;
4415
4416 printf("%s called\n", __func__);
4417}
4418
4419static uint32_t
4420xpt_freeze_devq_device(struct cam_ed *dev, u_int count)
4421{
4422 struct cam_devq *devq;
4423 uint32_t freeze;
4424
4425 devq = dev->sim->devq;
4426 mtx_assert(&devq->send_mtx, MA_OWNED);
4428 ("xpt_freeze_devq_device(%d) %u->%u\n", count,
4429 dev->ccbq.queue.qfrozen_cnt, dev->ccbq.queue.qfrozen_cnt + count));
4430 freeze = (dev->ccbq.queue.qfrozen_cnt += count);
4431 /* Remove frozen device from sendq. */
4432 if (device_is_queued(dev))
4433 camq_remove(&devq->send_queue, dev->devq_entry.index);
4434 return (freeze);
4435}
4436
4437u_int32_t
4438xpt_freeze_devq(struct cam_path *path, u_int count)
4439{
4440 struct cam_ed *dev = path->device;
4441 struct cam_devq *devq;
4442 uint32_t freeze;
4443
4444 devq = dev->sim->devq;
4445 mtx_lock(&devq->send_mtx);
4446 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_freeze_devq(%d)\n", count));
4447 freeze = xpt_freeze_devq_device(dev, count);
4448 mtx_unlock(&devq->send_mtx);
4449 return (freeze);
4450}
4451
4452u_int32_t
4453xpt_freeze_simq(struct cam_sim *sim, u_int count)
4454{
4455 struct cam_devq *devq;
4456 uint32_t freeze;
4457
4458 devq = sim->devq;
4459 mtx_lock(&devq->send_mtx);
4460 freeze = (devq->send_queue.qfrozen_cnt += count);
4461 mtx_unlock(&devq->send_mtx);
4462 return (freeze);
4463}
4464
4465static void
4467{
4468 struct cam_ed *dev;
4469 struct cam_devq *devq;
4470
4471 dev = (struct cam_ed *)arg;
4472 CAM_DEBUG_DEV(dev, CAM_DEBUG_TRACE, ("xpt_release_devq_timeout\n"));
4473 devq = dev->sim->devq;
4474 mtx_assert(&devq->send_mtx, MA_OWNED);
4475 if (xpt_release_devq_device(dev, /*count*/1, /*run_queue*/TRUE))
4476 xpt_run_devq(devq);
4477}
4478
4479void
4480xpt_release_devq(struct cam_path *path, u_int count, int run_queue)
4481{
4482 struct cam_ed *dev;
4483 struct cam_devq *devq;
4484
4485 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_release_devq(%d, %d)\n",
4486 count, run_queue));
4487 dev = path->device;
4488 devq = dev->sim->devq;
4489 mtx_lock(&devq->send_mtx);
4490 if (xpt_release_devq_device(dev, count, run_queue))
4491 xpt_run_devq(dev->sim->devq);
4492 mtx_unlock(&devq->send_mtx);
4493}
4494
4495static int
4496xpt_release_devq_device(struct cam_ed *dev, u_int count, int run_queue)
4497{
4498
4499 mtx_assert(&dev->sim->devq->send_mtx, MA_OWNED);
4501 ("xpt_release_devq_device(%d, %d) %u->%u\n", count, run_queue,
4502 dev->ccbq.queue.qfrozen_cnt, dev->ccbq.queue.qfrozen_cnt - count));
4503 if (count > dev->ccbq.queue.qfrozen_cnt) {
4504#ifdef INVARIANTS
4505 printf("xpt_release_devq(): requested %u > present %u\n",
4506 count, dev->ccbq.queue.qfrozen_cnt);
4507#endif
4508 count = dev->ccbq.queue.qfrozen_cnt;
4509 }
4510 dev->ccbq.queue.qfrozen_cnt -= count;
4511 if (dev->ccbq.queue.qfrozen_cnt == 0) {
4512 /*
4513 * No longer need to wait for a successful
4514 * command completion.
4515 */
4516 dev->flags &= ~CAM_DEV_REL_ON_COMPLETE;
4517 /*
4518 * Remove any timeouts that might be scheduled
4519 * to release this queue.
4520 */
4521 if ((dev->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0) {
4522 callout_stop(&dev->callout);
4523 dev->flags &= ~CAM_DEV_REL_TIMEOUT_PENDING;
4524 }
4525 /*
4526 * Now that we are unfrozen schedule the
4527 * device so any pending transactions are
4528 * run.
4529 */
4530 xpt_schedule_devq(dev->sim->devq, dev);
4531 } else
4532 run_queue = 0;
4533 return (run_queue);
4534}
4535
4536void
4537xpt_release_simq(struct cam_sim *sim, int run_queue)
4538{
4539 struct cam_devq *devq;
4540
4541 devq = sim->devq;
4542 mtx_lock(&devq->send_mtx);
4543 if (devq->send_queue.qfrozen_cnt <= 0) {
4544#ifdef INVARIANTS
4545 printf("xpt_release_simq: requested 1 > present %u\n",
4546 devq->send_queue.qfrozen_cnt);
4547#endif
4548 } else
4549 devq->send_queue.qfrozen_cnt--;
4550 if (devq->send_queue.qfrozen_cnt == 0) {
4551 if (run_queue) {
4552 /*
4553 * Now that we are unfrozen run the send queue.
4554 */
4555 xpt_run_devq(sim->devq);
4556 }
4557 }
4558 mtx_unlock(&devq->send_mtx);
4559}
4560
4561void
4562xpt_done(union ccb *done_ccb)
4563{
4564 struct cam_doneq *queue;
4565 int run, hash;
4566
4567#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4568 if (done_ccb->ccb_h.func_code == XPT_SCSI_IO &&
4569 done_ccb->csio.bio != NULL)
4570 biotrack(done_ccb->csio.bio, __func__);
4571#endif
4572
4574 ("xpt_done: func= %#x %s status %#x\n",
4575 done_ccb->ccb_h.func_code,
4576 xpt_action_name(done_ccb->ccb_h.func_code),
4577 done_ccb->ccb_h.status));
4578 if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) == 0)
4579 return;
4580
4581 /* Store the time the ccb was in the sim */
4583 done_ccb->ccb_h.status |= CAM_QOS_VALID;
4584 hash = (u_int)(done_ccb->ccb_h.path_id + done_ccb->ccb_h.target_id +
4585 done_ccb->ccb_h.target_lun) % cam_num_doneqs;
4586 queue = &cam_doneqs[hash];
4587 mtx_lock(&queue->cam_doneq_mtx);
4588 run = (queue->cam_doneq_sleep && STAILQ_EMPTY(&queue->cam_doneq));
4589 STAILQ_INSERT_TAIL(&queue->cam_doneq, &done_ccb->ccb_h, sim_links.stqe);
4590 done_ccb->ccb_h.pinfo.index = CAM_DONEQ_INDEX;
4591 mtx_unlock(&queue->cam_doneq_mtx);
4592 if (run && !dumping)
4593 wakeup(&queue->cam_doneq);
4594}
4595
4596void
4597xpt_done_direct(union ccb *done_ccb)
4598{
4599
4601 ("xpt_done_direct: status %#x\n", done_ccb->ccb_h.status));
4602 if ((done_ccb->ccb_h.func_code & XPT_FC_QUEUED) == 0)
4603 return;
4604
4605 /* Store the time the ccb was in the sim */
4607 done_ccb->ccb_h.status |= CAM_QOS_VALID;
4608 xpt_done_process(&done_ccb->ccb_h);
4609}
4610
4611union ccb *
4613{
4614 union ccb *new_ccb;
4615
4616 new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK);
4617 return (new_ccb);
4618}
4619
4620union ccb *
4622{
4623 union ccb *new_ccb;
4624
4625 new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT);
4626 return (new_ccb);
4627}
4628
4629void
4630xpt_free_ccb(union ccb *free_ccb)
4631{
4632 struct cam_periph *periph;
4633
4634 if (free_ccb->ccb_h.alloc_flags & CAM_CCB_FROM_UMA) {
4635 /*
4636 * Looks like a CCB allocated from a periph UMA zone.
4637 */
4638 periph = free_ccb->ccb_h.path->periph;
4639 uma_zfree(periph->ccb_zone, free_ccb);
4640 } else {
4641 free(free_ccb, M_CAMCCB);
4642 }
4643}
4644
4645/* Private XPT functions */
4646
4647/*
4648 * Get a CAM control block for the caller. Charge the structure to the device
4649 * referenced by the path. If we don't have sufficient resources to allocate
4650 * more ccbs, we return NULL.
4651 */
4652static union ccb *
4654{
4655 union ccb *new_ccb;
4656 int alloc_flags;
4657
4658 if (periph->ccb_zone != NULL) {
4659 alloc_flags = CAM_CCB_FROM_UMA;
4660 new_ccb = uma_zalloc(periph->ccb_zone, M_ZERO|M_NOWAIT);
4661 } else {
4662 alloc_flags = 0;
4663 new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT);
4664 }
4665 if (new_ccb == NULL)
4666 return (NULL);
4667 new_ccb->ccb_h.alloc_flags = alloc_flags;
4668 periph->periph_allocated++;
4670 return (new_ccb);
4671}
4672
4673static union ccb *
4675{
4676 union ccb *new_ccb;
4677 int alloc_flags;
4678
4679 cam_periph_unlock(periph);
4680 if (periph->ccb_zone != NULL) {
4681 alloc_flags = CAM_CCB_FROM_UMA;
4682 new_ccb = uma_zalloc(periph->ccb_zone, M_ZERO|M_WAITOK);
4683 } else {
4684 alloc_flags = 0;
4685 new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK);
4686 }
4687 new_ccb->ccb_h.alloc_flags = alloc_flags;
4688 cam_periph_lock(periph);
4689 periph->periph_allocated++;
4691 return (new_ccb);
4692}
4693
4694union ccb *
4695cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
4696{
4697 struct ccb_hdr *ccb_h;
4698
4699 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("cam_periph_getccb\n"));
4700 cam_periph_assert(periph, MA_OWNED);
4701 while ((ccb_h = SLIST_FIRST(&periph->ccb_list)) == NULL ||
4702 ccb_h->pinfo.priority != priority) {
4703 if (priority < periph->immediate_priority) {
4704 periph->immediate_priority = priority;
4705 xpt_run_allocq(periph, 0);
4706 } else
4707 cam_periph_sleep(periph, &periph->ccb_list, PRIBIO,
4708 "cgticb", 0);
4709 }
4710 SLIST_REMOVE_HEAD(&periph->ccb_list, periph_links.sle);
4711 return ((union ccb *)ccb_h);
4712}
4713
4714static void
4716{
4717
4719 bus->refcount++;
4721}
4722
4723static void
4725{
4726
4728 KASSERT(bus->refcount >= 1, ("bus->refcount >= 1"));
4729 if (--bus->refcount > 0) {
4731 return;
4732 }
4733 TAILQ_REMOVE(&xsoftc.xpt_busses, bus, links);
4734 xsoftc.bus_generation++;
4736 KASSERT(TAILQ_EMPTY(&bus->et_entries),
4737 ("destroying bus, but target list is not empty"));
4738 cam_sim_release(bus->sim);
4739 mtx_destroy(&bus->eb_mtx);
4740 free(bus, M_CAMXPT);
4741}
4742
4743static struct cam_et *
4745{
4746 struct cam_et *cur_target, *target;
4747
4748 mtx_assert(&xsoftc.xpt_topo_lock, MA_OWNED);
4749 mtx_assert(&bus->eb_mtx, MA_OWNED);
4750 target = (struct cam_et *)malloc(sizeof(*target), M_CAMXPT,
4751 M_NOWAIT|M_ZERO);
4752 if (target == NULL)
4753 return (NULL);
4754
4755 TAILQ_INIT(&target->ed_entries);
4756 target->bus = bus;
4757 target->target_id = target_id;
4758 target->refcount = 1;
4759 target->generation = 0;
4760 target->luns = NULL;
4761 mtx_init(&target->luns_mtx, "CAM LUNs lock", NULL, MTX_DEF);
4762 timevalclear(&target->last_reset);
4763 /*
4764 * Hold a reference to our parent bus so it
4765 * will not go away before we do.
4766 */
4767 bus->refcount++;
4768
4769 /* Insertion sort into our bus's target list */
4770 cur_target = TAILQ_FIRST(&bus->et_entries);
4771 while (cur_target != NULL && cur_target->target_id < target_id)
4772 cur_target = TAILQ_NEXT(cur_target, links);
4773 if (cur_target != NULL) {
4774 TAILQ_INSERT_BEFORE(cur_target, target, links);
4775 } else {
4776 TAILQ_INSERT_TAIL(&bus->et_entries, target, links);
4777 }
4778 bus->generation++;
4779 return (target);
4780}
4781
4782static void
4784{
4785 struct cam_eb *bus = target->bus;
4786
4787 mtx_lock(&bus->eb_mtx);
4788 target->refcount++;
4789 mtx_unlock(&bus->eb_mtx);
4790}
4791
4792static void
4794{
4795 struct cam_eb *bus = target->bus;
4796
4797 mtx_lock(&bus->eb_mtx);
4798 if (--target->refcount > 0) {
4799 mtx_unlock(&bus->eb_mtx);
4800 return;
4801 }
4802 TAILQ_REMOVE(&bus->et_entries, target, links);
4803 bus->generation++;
4804 mtx_unlock(&bus->eb_mtx);
4805 KASSERT(TAILQ_EMPTY(&target->ed_entries),
4806 ("destroying target, but device list is not empty"));
4807 xpt_release_bus(bus);
4808 mtx_destroy(&target->luns_mtx);
4809 if (target->luns)
4810 free(target->luns, M_CAMXPT);
4811 free(target, M_CAMXPT);
4812}
4813
4814static struct cam_ed *
4817{
4818 struct cam_ed *device;
4819
4820 device = xpt_alloc_device(bus, target, lun_id);
4821 if (device == NULL)
4822 return (NULL);
4823
4824 device->mintags = 1;
4825 device->maxtags = 1;
4826 return (device);
4827}
4828
4829static void
4830xpt_destroy_device(void *context, int pending)
4831{
4832 struct cam_ed *device = context;
4833
4834 mtx_lock(&device->device_mtx);
4835 mtx_destroy(&device->device_mtx);
4836 free(device, M_CAMDEV);
4837}
4838
4839struct cam_ed *
4841{
4842 struct cam_ed *cur_device, *device;
4843 struct cam_devq *devq;
4844 cam_status status;
4845
4846 mtx_assert(&bus->eb_mtx, MA_OWNED);
4847 /* Make space for us in the device queue on our bus */
4848 devq = bus->sim->devq;
4849 mtx_lock(&devq->send_mtx);
4850 status = cam_devq_resize(devq, devq->send_queue.array_size + 1);
4851 mtx_unlock(&devq->send_mtx);
4852 if (status != CAM_REQ_CMP)
4853 return (NULL);
4854
4855 device = (struct cam_ed *)malloc(sizeof(*device),
4856 M_CAMDEV, M_NOWAIT|M_ZERO);
4857 if (device == NULL)
4858 return (NULL);
4859
4860 cam_init_pinfo(&device->devq_entry);
4861 device->target = target;
4862 device->lun_id = lun_id;
4863 device->sim = bus->sim;
4864 if (cam_ccbq_init(&device->ccbq,
4865 bus->sim->max_dev_openings) != 0) {
4866 free(device, M_CAMDEV);
4867 return (NULL);
4868 }
4869 SLIST_INIT(&device->asyncs);
4870 SLIST_INIT(&device->periphs);
4871 device->generation = 0;
4872 device->flags = CAM_DEV_UNCONFIGURED;
4873 device->tag_delay_count = 0;
4874 device->tag_saved_openings = 0;
4875 device->refcount = 1;
4876 mtx_init(&device->device_mtx, "CAM device lock", NULL, MTX_DEF);
4877 callout_init_mtx(&device->callout, &devq->send_mtx, 0);
4878 TASK_INIT(&device->device_destroy_task, 0, xpt_destroy_device, device);
4879 /*
4880 * Hold a reference to our parent bus so it
4881 * will not go away before we do.
4882 */
4883 target->refcount++;
4884
4885 cur_device = TAILQ_FIRST(&target->ed_entries);
4886 while (cur_device != NULL && cur_device->lun_id < lun_id)
4887 cur_device = TAILQ_NEXT(cur_device, links);
4888 if (cur_device != NULL)
4889 TAILQ_INSERT_BEFORE(cur_device, device, links);
4890 else
4891 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
4892 target->generation++;
4893 return (device);
4894}
4895
4896void
4898{
4899 struct cam_eb *bus = device->target->bus;
4900
4901 mtx_lock(&bus->eb_mtx);
4902 device->refcount++;
4903 mtx_unlock(&bus->eb_mtx);
4904}
4905
4906void
4908{
4909 struct cam_eb *bus = device->target->bus;
4910 struct cam_devq *devq;
4911
4912 mtx_lock(&bus->eb_mtx);
4913 if (--device->refcount > 0) {
4914 mtx_unlock(&bus->eb_mtx);
4915 return;
4916 }
4917
4918 TAILQ_REMOVE(&device->target->ed_entries, device,links);
4919 device->target->generation++;
4920 mtx_unlock(&bus->eb_mtx);
4921
4922 /* Release our slot in the devq */
4923 devq = bus->sim->devq;
4924 mtx_lock(&devq->send_mtx);
4925 cam_devq_resize(devq, devq->send_queue.array_size - 1);
4926
4927 KASSERT(SLIST_EMPTY(&device->periphs),
4928 ("destroying device, but periphs list is not empty"));
4929 KASSERT(device->devq_entry.index == CAM_UNQUEUED_INDEX,
4930 ("destroying device while still queued for ccbs"));
4931
4932 /* The send_mtx must be held when accessing the callout */
4933 if ((device->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0)
4934 callout_stop(&device->callout);
4935
4936 mtx_unlock(&devq->send_mtx);
4937
4938 xpt_release_target(device->target);
4939
4940 cam_ccbq_fini(&device->ccbq);
4941 /*
4942 * Free allocated memory. free(9) does nothing if the
4943 * supplied pointer is NULL, so it is safe to call without
4944 * checking.
4945 */
4946 free(device->supported_vpds, M_CAMXPT);
4947 free(device->device_id, M_CAMXPT);
4948 free(device->ext_inq, M_CAMXPT);
4949 free(device->physpath, M_CAMXPT);
4950 free(device->rcap_buf, M_CAMXPT);
4951 free(device->serial_num, M_CAMXPT);
4952 free(device->nvme_data, M_CAMXPT);
4953 free(device->nvme_cdata, M_CAMXPT);
4954 taskqueue_enqueue(xsoftc.xpt_taskq, &device->device_destroy_task);
4955}
4956
4957u_int32_t
4958xpt_dev_ccbq_resize(struct cam_path *path, int newopenings)
4959{
4960 int result;
4961 struct cam_ed *dev;
4962
4963 dev = path->device;
4964 mtx_lock(&dev->sim->devq->send_mtx);
4965 result = cam_ccbq_resize(&dev->ccbq, newopenings);
4966 mtx_unlock(&dev->sim->devq->send_mtx);
4967 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
4968 || (dev->inq_flags & SID_CmdQue) != 0)
4969 dev->tag_saved_openings = newopenings;
4970 return (result);
4971}
4972
4973static struct cam_eb *
4975{
4976 struct cam_eb *bus;
4977
4979 for (bus = TAILQ_FIRST(&xsoftc.xpt_busses);
4980 bus != NULL;
4981 bus = TAILQ_NEXT(bus, links)) {
4982 if (bus->path_id == path_id) {
4983 bus->refcount++;
4984 break;
4985 }
4986 }
4988 return (bus);
4989}
4990
4991static struct cam_et *
4993{
4994 struct cam_et *target;
4995
4996 mtx_assert(&bus->eb_mtx, MA_OWNED);
4997 for (target = TAILQ_FIRST(&bus->et_entries);
4998 target != NULL;
4999 target = TAILQ_NEXT(target, links)) {
5000 if (target->target_id == target_id) {
5001 target->refcount++;
5002 break;
5003 }
5004 }
5005 return (target);
5006}
5007
5008static struct cam_ed *
5010{
5011 struct cam_ed *device;
5012
5013 mtx_assert(&target->bus->eb_mtx, MA_OWNED);
5014 for (device = TAILQ_FIRST(&target->ed_entries);
5015 device != NULL;
5016 device = TAILQ_NEXT(device, links)) {
5017 if (device->lun_id == lun_id) {
5018 device->refcount++;
5019 break;
5020 }
5021 }
5022 return (device);
5023}
5024
5025void
5027{
5028 struct ccb_relsim crs;
5029 struct cam_ed *device;
5030 struct cam_sim *sim;
5031 int newopenings;
5032
5033 device = path->device;
5034 sim = path->bus->sim;
5035 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
5036 xpt_freeze_devq(path, /*count*/1);
5037 device->inq_flags |= SID_CmdQue;
5038 if (device->tag_saved_openings != 0)
5039 newopenings = device->tag_saved_openings;
5040 else
5041 newopenings = min(device->maxtags,
5043 xpt_dev_ccbq_resize(path, newopenings);
5044 xpt_async(AC_GETDEV_CHANGED, path, NULL);
5045 memset(&crs, 0, sizeof(crs));
5049 crs.openings
5050 = crs.release_timeout
5051 = crs.qfrozen_cnt
5052 = 0;
5053 xpt_action((union ccb *)&crs);
5054}
5055
5056void
5058{
5059 struct ccb_relsim crs;
5060 struct cam_ed *device;
5061 struct cam_sim *sim;
5062
5063 device = path->device;
5064 sim = path->bus->sim;
5065 device->flags &= ~CAM_DEV_TAG_AFTER_COUNT;
5066 device->tag_delay_count = 0;
5067 xpt_freeze_devq(path, /*count*/1);
5068 device->inq_flags &= ~SID_CmdQue;
5070 xpt_async(AC_GETDEV_CHANGED, path, NULL);
5071 memset(&crs, 0, sizeof(crs));
5075 crs.openings
5076 = crs.release_timeout
5077 = crs.qfrozen_cnt
5078 = 0;
5079 xpt_action((union ccb *)&crs);
5080}
5081
5082/*
5083 * Assume all possible buses are detected by this time, so allow boot
5084 * as soon as they all are scanned.
5085 */
5086static void
5088{
5089
5091}
5092
5093/*
5094 * Now that all config hooks have completed, start boot_delay timer,
5095 * waiting for possibly still undetected buses (USB) to appear.
5096 */
5097static void
5098xpt_ch_done(void *arg)
5099{
5100
5101 callout_init(&xsoftc.boot_callout, 1);
5102 callout_reset_sbt(&xsoftc.boot_callout, SBT_1MS * xsoftc.boot_delay,
5103 SBT_1MS, xpt_boot_delay, NULL, 0);
5104}
5105SYSINIT(xpt_hw_delay, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, xpt_ch_done, NULL);
5106
5107/*
5108 * Now that interrupts are enabled, go find our devices
5109 */
5110static void
5111xpt_config(void *arg)
5112{
5113 if (taskqueue_start_threads(&xsoftc.xpt_taskq, 1, PRIBIO, "CAM taskq"))
5114 printf("xpt_config: failed to create taskqueue thread.\n");
5115
5116 /* Setup debugging path */
5117 if (cam_dflags != CAM_DEBUG_NONE) {
5118 if (xpt_create_path(&cam_dpath, NULL,
5121 printf("xpt_config: xpt_create_path() failed for debug"
5122 " target %d:%d:%d, debugging disabled\n",
5125 }
5126 } else
5127 cam_dpath = NULL;
5128
5130 xpt_hold_boot();
5131
5132 /* Fire up rescan thread. */
5133 if (kproc_kthread_add(xpt_scanner_thread, NULL, &cam_proc, NULL, 0, 0,
5134 "cam", "scanner")) {
5135 printf("xpt_config: failed to create rescan thread.\n");
5136 }
5137}
5138
5139void
5141{
5142
5143 if (xsoftc.buses_to_config++ == 0)
5144 root_mount_hold_token("CAM", &xsoftc.xpt_rootmount);
5145}
5146
5147void
5149{
5150
5154}
5155
5156void
5158{
5159
5161 if (--xsoftc.buses_to_config == 0) {
5162 if (xsoftc.buses_config_done == 0) {
5163 xsoftc.buses_config_done = 1;
5164 xsoftc.buses_to_config++;
5165 TASK_INIT(&xsoftc.boot_task, 0, xpt_finishconfig_task,
5166 NULL);
5167 taskqueue_enqueue(taskqueue_thread, &xsoftc.boot_task);
5168 } else
5169 root_mount_rel(&xsoftc.xpt_rootmount);
5170 }
5172}
5173
5174/*
5175 * If the given device only has one peripheral attached to it, and if that
5176 * peripheral is the passthrough driver, announce it. This insures that the
5177 * user sees some sort of announcement for every peripheral in their system.
5178 */
5179static int
5180xptpassannouncefunc(struct cam_ed *device, void *arg)
5181{
5182 struct cam_periph *periph;
5183 int i;
5184
5185 for (periph = SLIST_FIRST(&device->periphs), i = 0; periph != NULL;
5186 periph = SLIST_NEXT(periph, periph_links), i++);
5187
5188 periph = SLIST_FIRST(&device->periphs);
5189 if ((i == 1)
5190 && (strncmp(periph->periph_name, "pass", 4) == 0))
5191 xpt_announce_periph(periph, NULL);
5192
5193 return(1);
5194}
5195
5196static void
5197xpt_finishconfig_task(void *context, int pending)
5198{
5199
5201 /*
5202 * Check for devices with no "standard" peripheral driver
5203 * attached. For any devices like that, announce the
5204 * passthrough driver so the user will see something.
5205 */
5206 if (!bootverbose)
5208
5210}
5211
5213xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg,
5214 struct cam_path *path)
5215{
5216 struct ccb_setasync csa;
5217 cam_status status;
5218 int xptpath = 0;
5219
5220 if (path == NULL) {
5221 status = xpt_create_path(&path, /*periph*/NULL, CAM_XPT_PATH_ID,
5223 if (status != CAM_REQ_CMP)
5224 return (status);
5225 xpt_path_lock(path);
5226 xptpath = 1;
5227 }
5228
5229 memset(&csa, 0, sizeof(csa));
5232 csa.event_enable = event;
5233 csa.callback = cbfunc;
5234 csa.callback_arg = cbarg;
5235 xpt_action((union ccb *)&csa);
5236 status = csa.ccb_h.status;
5237
5239 ("xpt_register_async: func %p\n", cbfunc));
5240
5241 if (xptpath) {
5242 xpt_path_unlock(path);
5243 xpt_free_path(path);
5244 }
5245
5246 if ((status == CAM_REQ_CMP) &&
5247 (csa.event_enable & AC_FOUND_DEVICE)) {
5248 /*
5249 * Get this peripheral up to date with all
5250 * the currently existing devices.
5251 */
5253 }
5254 if ((status == CAM_REQ_CMP) &&
5256 /*
5257 * Get this peripheral up to date with all
5258 * the currently existing buses.
5259 */
5261 }
5262
5263 return (status);
5264}
5265
5266static void
5267xptaction(struct cam_sim *sim, union ccb *work_ccb)
5268{
5269 CAM_DEBUG(work_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("xptaction\n"));
5270
5271 switch (work_ccb->ccb_h.func_code) {
5272 /* Common cases first */
5273 case XPT_PATH_INQ: /* Path routing inquiry */
5274 {
5275 struct ccb_pathinq *cpi;
5276
5277 cpi = &work_ccb->cpi;
5278 cpi->version_num = 1; /* XXX??? */
5279 cpi->hba_inquiry = 0;
5280 cpi->target_sprt = 0;
5281 cpi->hba_misc = 0;
5282 cpi->hba_eng_cnt = 0;
5283 cpi->max_target = 0;
5284 cpi->max_lun = 0;
5285 cpi->initiator_id = 0;
5286 strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
5287 strlcpy(cpi->hba_vid, "", HBA_IDLEN);
5288 strlcpy(cpi->dev_name, sim->sim_name, DEV_IDLEN);
5289 cpi->unit_number = sim->unit_number;
5290 cpi->bus_id = sim->bus_id;
5291 cpi->base_transfer_speed = 0;
5296 cpi->ccb_h.status = CAM_REQ_CMP;
5297 break;
5298 }
5299 default:
5300 work_ccb->ccb_h.status = CAM_REQ_INVALID;
5301 break;
5302 }
5303 xpt_done(work_ccb);
5304}
5305
5306/*
5307 * The xpt as a "controller" has no interrupt sources, so polling
5308 * is a no-op.
5309 */
5310static void
5311xptpoll(struct cam_sim *sim)
5312{
5313}
5314
5315void
5317{
5318 mtx_lock(&xsoftc.xpt_topo_lock);
5319}
5320
5321void
5323{
5324 mtx_unlock(&xsoftc.xpt_topo_lock);
5325}
5326
5327struct mtx *
5329{
5330
5331 return (&path->device->device_mtx);
5332}
5333
5334static void
5336{
5337 struct cam_sim *sim = NULL;
5338 struct cam_devq *devq = NULL;
5339 struct mtx *mtx = NULL;
5340
5341#if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5342 struct ccb_scsiio *csio;
5343
5344 if (ccb_h->func_code == XPT_SCSI_IO) {
5345 csio = &((union ccb *)ccb_h)->csio;
5346 if (csio->bio != NULL)
5347 biotrack(csio->bio, __func__);
5348 }
5349#endif
5350
5351 if (ccb_h->flags & CAM_HIGH_POWER) {
5352 struct highpowerlist *hphead;
5353 struct cam_ed *device;
5354
5355 mtx_lock(&xsoftc.xpt_highpower_lock);
5356 hphead = &xsoftc.highpowerq;
5357
5358 device = STAILQ_FIRST(hphead);
5359
5360 /*
5361 * Increment the count since this command is done.
5362 */
5363 xsoftc.num_highpower++;
5364
5365 /*
5366 * Any high powered commands queued up?
5367 */
5368 if (device != NULL) {
5369 STAILQ_REMOVE_HEAD(hphead, highpowerq_entry);
5370 mtx_unlock(&xsoftc.xpt_highpower_lock);
5371
5372 mtx_lock(&device->sim->devq->send_mtx);
5374 /*count*/1, /*runqueue*/TRUE);
5375 mtx_unlock(&device->sim->devq->send_mtx);
5376 } else
5377 mtx_unlock(&xsoftc.xpt_highpower_lock);
5378 }
5379
5380 /*
5381 * Insulate against a race where the periph is destroyed but CCBs are
5382 * still not all processed. This shouldn't happen, but allows us better
5383 * bug diagnostic when it does.
5384 */
5385 if (ccb_h->path->bus)
5386 sim = ccb_h->path->bus->sim;
5387
5388 if (ccb_h->status & CAM_RELEASE_SIMQ) {
5389 KASSERT(sim, ("sim missing for CAM_RELEASE_SIMQ request"));
5390 xpt_release_simq(sim, /*run_queue*/FALSE);
5391 ccb_h->status &= ~CAM_RELEASE_SIMQ;
5392 }
5393
5394 if ((ccb_h->flags & CAM_DEV_QFRZDIS)
5395 && (ccb_h->status & CAM_DEV_QFRZN)) {
5396 xpt_release_devq(ccb_h->path, /*count*/1, /*run_queue*/TRUE);
5397 ccb_h->status &= ~CAM_DEV_QFRZN;
5398 }
5399
5400 if ((ccb_h->func_code & XPT_FC_USER_CCB) == 0) {
5401 struct cam_ed *dev = ccb_h->path->device;
5402
5403 if (sim)
5404 devq = sim->devq;
5405 KASSERT(devq, ("Periph disappeared with CCB %p %s request pending.",
5406 ccb_h, xpt_action_name(ccb_h->func_code)));
5407
5408 mtx_lock(&devq->send_mtx);
5409 devq->send_active--;
5410 devq->send_openings++;
5411 cam_ccbq_ccb_done(&dev->ccbq, (union ccb *)ccb_h);
5412
5413 if (((dev->flags & CAM_DEV_REL_ON_QUEUE_EMPTY) != 0
5414 && (dev->ccbq.dev_active == 0))) {
5415 dev->flags &= ~CAM_DEV_REL_ON_QUEUE_EMPTY;
5416 xpt_release_devq_device(dev, /*count*/1,
5417 /*run_queue*/FALSE);
5418 }
5419
5420 if (((dev->flags & CAM_DEV_REL_ON_COMPLETE) != 0
5421 && (ccb_h->status&CAM_STATUS_MASK) != CAM_REQUEUE_REQ)) {
5422 dev->flags &= ~CAM_DEV_REL_ON_COMPLETE;
5423 xpt_release_devq_device(dev, /*count*/1,
5424 /*run_queue*/FALSE);
5425 }
5426
5427 if (!device_is_queued(dev))
5428 (void)xpt_schedule_devq(devq, dev);
5429 xpt_run_devq(devq);
5430 mtx_unlock(&devq->send_mtx);
5431
5432 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0) {
5433 mtx = xpt_path_mtx(ccb_h->path);
5434 mtx_lock(mtx);
5435
5436 if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
5437 && (--dev->tag_delay_count == 0))
5438 xpt_start_tags(ccb_h->path);
5439 }
5440 }
5441
5442 if ((ccb_h->flags & CAM_UNLOCKED) == 0) {
5443 if (mtx == NULL) {
5444 mtx = xpt_path_mtx(ccb_h->path);
5445 mtx_lock(mtx);
5446 }
5447 } else {
5448 if (mtx != NULL) {
5449 mtx_unlock(mtx);
5450 mtx = NULL;
5451 }
5452 }
5453
5454 /* Call the peripheral driver's callback */
5456 (*ccb_h->cbfcnp)(ccb_h->path->periph, (union ccb *)ccb_h);
5457 if (mtx != NULL)
5458 mtx_unlock(mtx);
5459}
5460
5461/*
5462 * Parameterize instead and use xpt_done_td?
5463 */
5464static void
5466{
5467 struct cam_doneq *queue = arg;
5468 struct ccb_hdr *ccb_h;
5469 STAILQ_HEAD(, ccb_hdr) doneq;
5470
5471 STAILQ_INIT(&doneq);
5472 mtx_lock(&queue->cam_doneq_mtx);
5473 while (1) {
5474 while (STAILQ_EMPTY(&queue->cam_doneq))
5475 msleep(&queue->cam_doneq, &queue->cam_doneq_mtx,
5476 PRIBIO, "-", 0);
5477 STAILQ_CONCAT(&doneq, &queue->cam_doneq);
5478 mtx_unlock(&queue->cam_doneq_mtx);
5479
5480 while ((ccb_h = STAILQ_FIRST(&doneq)) != NULL) {
5481 STAILQ_REMOVE_HEAD(&doneq, sim_links.stqe);
5482 xpt_done_process(ccb_h);
5483 }
5484
5485 mtx_lock(&queue->cam_doneq_mtx);
5486 }
5487}
5488
5489void
5490xpt_done_td(void *arg)
5491{
5492 struct cam_doneq *queue = arg;
5493 struct ccb_hdr *ccb_h;
5494 STAILQ_HEAD(, ccb_hdr) doneq;
5495
5496 STAILQ_INIT(&doneq);
5497 mtx_lock(&queue->cam_doneq_mtx);
5498 while (1) {
5499 while (STAILQ_EMPTY(&queue->cam_doneq)) {
5500 queue->cam_doneq_sleep = 1;
5501 msleep(&queue->cam_doneq, &queue->cam_doneq_mtx,
5502 PRIBIO, "-", 0);
5503 queue->cam_doneq_sleep = 0;
5504 }
5505 STAILQ_CONCAT(&doneq, &queue->cam_doneq);
5506 mtx_unlock(&queue->cam_doneq_mtx);
5507
5508 THREAD_NO_SLEEPING();
5509 while ((ccb_h = STAILQ_FIRST(&doneq)) != NULL) {
5510 STAILQ_REMOVE_HEAD(&doneq, sim_links.stqe);
5511 xpt_done_process(ccb_h);
5512 }
5513 THREAD_SLEEPING_OK();
5514
5515 mtx_lock(&queue->cam_doneq_mtx);
5516 }
5517}
5518
5519static void
5521{
5522 struct ccb_hdr *ccb_h;
5523 struct cam_doneq *queue;
5524 int i;
5525
5526 /* Process global queues. */
5527 for (i = 0; i < cam_num_doneqs; i++) {
5528 queue = &cam_doneqs[i];
5529 mtx_lock(&queue->cam_doneq_mtx);
5530 while ((ccb_h = STAILQ_FIRST(&queue->cam_doneq)) != NULL) {
5531 STAILQ_REMOVE_HEAD(&queue->cam_doneq, sim_links.stqe);
5532 mtx_unlock(&queue->cam_doneq_mtx);
5533 xpt_done_process(ccb_h);
5534 mtx_lock(&queue->cam_doneq_mtx);
5535 }
5536 mtx_unlock(&queue->cam_doneq_mtx);
5537 }
5538}
5539
5550device_t
5552{
5553 return (path->bus->parent_dev);
5554}
5555
5556struct kv
5557{
5558 uint32_t v;
5559 const char *name;
5560};
5561
5562static struct kv map[] = {
5563 { XPT_NOOP, "XPT_NOOP" },
5564 { XPT_SCSI_IO, "XPT_SCSI_IO" },
5565 { XPT_GDEV_TYPE, "XPT_GDEV_TYPE" },
5566 { XPT_GDEVLIST, "XPT_GDEVLIST" },
5567 { XPT_PATH_INQ, "XPT_PATH_INQ" },
5568 { XPT_REL_SIMQ, "XPT_REL_SIMQ" },
5569 { XPT_SASYNC_CB, "XPT_SASYNC_CB" },
5570 { XPT_SDEV_TYPE, "XPT_SDEV_TYPE" },
5571 { XPT_SCAN_BUS, "XPT_SCAN_BUS" },
5572 { XPT_DEV_MATCH, "XPT_DEV_MATCH" },
5573 { XPT_DEBUG, "XPT_DEBUG" },
5574 { XPT_PATH_STATS, "XPT_PATH_STATS" },
5575 { XPT_GDEV_STATS, "XPT_GDEV_STATS" },
5576 { XPT_DEV_ADVINFO, "XPT_DEV_ADVINFO" },
5577 { XPT_ASYNC, "XPT_ASYNC" },
5578 { XPT_ABORT, "XPT_ABORT" },
5579 { XPT_RESET_BUS, "XPT_RESET_BUS" },
5580 { XPT_RESET_DEV, "XPT_RESET_DEV" },
5581 { XPT_TERM_IO, "XPT_TERM_IO" },
5582 { XPT_SCAN_LUN, "XPT_SCAN_LUN" },
5583 { XPT_GET_TRAN_SETTINGS, "XPT_GET_TRAN_SETTINGS" },
5584 { XPT_SET_TRAN_SETTINGS, "XPT_SET_TRAN_SETTINGS" },
5585 { XPT_CALC_GEOMETRY, "XPT_CALC_GEOMETRY" },
5586 { XPT_ATA_IO, "XPT_ATA_IO" },
5587 { XPT_GET_SIM_KNOB, "XPT_GET_SIM_KNOB" },
5588 { XPT_SET_SIM_KNOB, "XPT_SET_SIM_KNOB" },
5589 { XPT_NVME_IO, "XPT_NVME_IO" },
5590 { XPT_MMC_IO, "XPT_MMC_IO" },
5591 { XPT_SMP_IO, "XPT_SMP_IO" },
5592 { XPT_SCAN_TGT, "XPT_SCAN_TGT" },
5593 { XPT_NVME_ADMIN, "XPT_NVME_ADMIN" },
5594 { XPT_ENG_INQ, "XPT_ENG_INQ" },
5595 { XPT_ENG_EXEC, "XPT_ENG_EXEC" },
5596 { XPT_EN_LUN, "XPT_EN_LUN" },
5597 { XPT_TARGET_IO, "XPT_TARGET_IO" },
5598 { XPT_ACCEPT_TARGET_IO, "XPT_ACCEPT_TARGET_IO" },
5599 { XPT_CONT_TARGET_IO, "XPT_CONT_TARGET_IO" },
5600 { XPT_IMMED_NOTIFY, "XPT_IMMED_NOTIFY" },
5601 { XPT_NOTIFY_ACK, "XPT_NOTIFY_ACK" },
5602 { XPT_IMMEDIATE_NOTIFY, "XPT_IMMEDIATE_NOTIFY" },
5603 { XPT_NOTIFY_ACKNOWLEDGE, "XPT_NOTIFY_ACKNOWLEDGE" },
5604 { 0, 0 }
5605};
5606
5607const char *
5608xpt_action_name(uint32_t action)
5609{
5610 static char buffer[32]; /* Only for unknown messages -- racy */
5611 struct kv *walker = map;
5612
5613 while (walker->name != NULL) {
5614 if (walker->v == action)
5615 return (walker->name);
5616 walker++;
5617 }
5618
5619 snprintf(buffer, sizeof(buffer), "%#x", action);
5620 return (buffer);
5621}
caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, int entry_size, cam_quirkmatch_t *comp_func)
Definition: cam.c:281
#define CAM_DONEQ_INDEX
Definition: cam.h:98
#define CAM_PRIORITY_OOB
Definition: cam.h:91
#define CAM_TARGET_WILDCARD
Definition: cam.h:48
#define CAM_LUN_WILDCARD
Definition: cam.h:49
#define CAM_XPT_PATH_ID
Definition: cam.h:46
#define CAM_ASYNC_INDEX
Definition: cam.h:99
#define CAM_PRIORITY_NORMAL
Definition: cam.h:92
#define CAM_PRIORITY_NONE
Definition: cam.h:93
#define CAM_UNQUEUED_INDEX
Definition: cam.h:96
u_int path_id_t
Definition: cam.h:42
static __END_DECLS __inline void cam_init_pinfo(cam_pinfo *pinfo)
Definition: cam.h:408
#define CAM_PRIORITY_XPT
Definition: cam.h:89
cam_status
Definition: cam.h:132
@ CAM_PATH_INVALID
Definition: cam.h:155
@ CAM_REQ_INVALID
Definition: cam.h:152
@ CAM_REQ_INPROG
Definition: cam.h:134
@ CAM_PROVIDE_FAIL
Definition: cam.h:200
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_REQUEUE_REQ
Definition: cam.h:222
@ CAM_DEV_NOT_THERE
Definition: cam.h:158
@ CAM_CMD_TIMEOUT
Definition: cam.h:167
@ CAM_UA_ABORT
Definition: cam.h:143
@ CAM_RESRC_UNAVAIL
Definition: cam.h:247
@ CAM_REQ_CMP_ERR
Definition: cam.h:146
@ CAM_STATUS_MASK
Definition: cam.h:302
@ CAM_REQ_ABORTED
Definition: cam.h:140
@ CAM_FUNC_NOTAVAIL
Definition: cam.h:265
@ CAM_RELEASE_SIMQ
Definition: cam.h:293
@ CAM_SIM_QUEUED
Definition: cam.h:296
@ CAM_QOS_VALID
Definition: cam.h:299
@ CAM_DEV_QFRZN
Definition: cam.h:287
#define CAM_BUS_WILDCARD
Definition: cam.h:47
u_int target_id_t
Definition: cam.h:43
u_int64_t lun_id_t
Definition: cam.h:44
@ CAM_GDEVLIST_MORE_DEVS
Definition: cam_ccb.h:411
@ CAM_GDEVLIST_ERROR
Definition: cam_ccb.h:412
@ CAM_GDEVLIST_LIST_CHANGED
Definition: cam_ccb.h:410
@ CAM_GDEVLIST_LAST_DEVICE
Definition: cam_ccb.h:409
@ AC_ADVINFO_CHANGED
Definition: cam_ccb.h:868
@ AC_FOUND_DEVICE
Definition: cam_ccb.h:874
@ AC_UNSOL_RESEL
Definition: cam_ccb.h:879
@ AC_CONTRACT
Definition: cam_ccb.h:869
@ AC_PATH_DEREGISTERED
Definition: cam_ccb.h:875
@ AC_SCSI_AEN
Definition: cam_ccb.h:878
@ AC_BUS_RESET
Definition: cam_ccb.h:880
@ AC_GETDEV_CHANGED
Definition: cam_ccb.h:870
@ AC_UNIT_ATTENTION
Definition: cam_ccb.h:867
@ AC_PATH_REGISTERED
Definition: cam_ccb.h:876
@ AC_TRANSFER_NEG
Definition: cam_ccb.h:872
@ AC_INQ_CHANGED
Definition: cam_ccb.h:871
@ AC_LOST_DEVICE
Definition: cam_ccb.h:873
@ AC_SENT_BDR
Definition: cam_ccb.h:877
#define RELSIM_RELEASE_AFTER_TIMEOUT
Definition: cam_ccb.h:841
#define RELSIM_ADJUST_OPENINGS
Definition: cam_ccb.h:840
void ac_callback_t(void *softc, u_int32_t code, struct cam_path *path, void *args)
Definition: cam_ccb.h:883
@ DEV_RESULT_UNCONFIGURED
Definition: cam_ccb.h:510
@ DEV_RESULT_NOFLAG
Definition: cam_ccb.h:509
#define CAM_TARGET_GENERATION
Definition: cam_ccb.h:572
cam_proto
Definition: cam_ccb.h:276
@ PROTO_UNSPECIFIED
Definition: cam_ccb.h:278
#define PROTO_VERSION_UNSPECIFIED
Definition: cam_ccb.h:315
@ PIM_NOSCAN
Definition: cam_ccb.h:626
@ PERIPH_MATCH_LUN
Definition: cam_ccb.h:428
@ PERIPH_MATCH_PATH
Definition: cam_ccb.h:426
@ PERIPH_MATCH_NAME
Definition: cam_ccb.h:429
@ PERIPH_MATCH_UNIT
Definition: cam_ccb.h:430
@ PERIPH_MATCH_TARGET
Definition: cam_ccb.h:427
@ DEV_MATCH_DEVICE
Definition: cam_ccb.h:491
@ DEV_MATCH_BUS
Definition: cam_ccb.h:492
@ DEV_MATCH_PERIPH
Definition: cam_ccb.h:490
#define CAM_SCSI_DEVID_MAXLEN
Definition: cam_ccb.h:1324
#define CAM_DEV_GENERATION
Definition: cam_ccb.h:573
#define XPT_FC_IS_DEV_QUEUED(ccb)
Definition: cam_ccb.h:271
#define CAM_PERIPH_GENERATION
Definition: cam_ccb.h:574
@ BUS_MATCH_UNIT
Definition: cam_ccb.h:471
@ BUS_MATCH_PATH
Definition: cam_ccb.h:469
@ BUS_MATCH_BUS_ID
Definition: cam_ccb.h:472
@ BUS_MATCH_NAME
Definition: cam_ccb.h:470
#define CAM_BUS_GENERATION
Definition: cam_ccb.h:571
#define XPORT_VERSION_UNSPECIFIED
Definition: cam_ccb.h:317
@ XPORT_UNKNOWN
Definition: cam_ccb.h:289
@ XPORT_UNSPECIFIED
Definition: cam_ccb.h:290
dev_pos_type
Definition: cam_ccb.h:549
@ CAM_DEV_POS_TARGET
Definition: cam_ccb.h:552
@ CAM_DEV_POS_TYPEMASK
Definition: cam_ccb.h:556
@ CAM_DEV_POS_EDT
Definition: cam_ccb.h:557
@ CAM_DEV_POS_PDPTR
Definition: cam_ccb.h:555
@ CAM_DEV_POS_BUS
Definition: cam_ccb.h:551
@ CAM_DEV_POS_PERIPH
Definition: cam_ccb.h:554
@ CAM_DEV_POS_PDRV
Definition: cam_ccb.h:558
@ CAM_DEV_POS_NONE
Definition: cam_ccb.h:550
@ CAM_DEV_POS_DEVICE
Definition: cam_ccb.h:553
#define XPT_FC_IS_QUEUED(ccb)
Definition: cam_ccb.h:273
@ DEV_MATCH_DEVID
Definition: cam_ccb.h:448
@ DEV_MATCH_INQUIRY
Definition: cam_ccb.h:447
@ DEV_MATCH_TARGET
Definition: cam_ccb.h:445
@ DEV_MATCH_LUN
Definition: cam_ccb.h:446
@ DEV_MATCH_PATH
Definition: cam_ccb.h:444
@ CAM_CDB_POINTER
Definition: cam_ccb.h:69
@ CAM_DEV_QFREEZE
Definition: cam_ccb.h:92
@ CAM_DATA_VADDR
Definition: cam_ccb.h:83
@ CAM_HIGH_POWER
Definition: cam_ccb.h:93
@ CAM_UNLOCKED
Definition: cam_ccb.h:119
@ CAM_DATA_MASK
Definition: cam_ccb.h:88
@ CAM_DEV_QFRZDIS
Definition: cam_ccb.h:91
@ CAM_TAG_ACTION_VALID
Definition: cam_ccb.h:96
@ CAM_DEV_MATCH_ERROR
Definition: cam_ccb.h:546
@ CAM_DEV_MATCH_LAST
Definition: cam_ccb.h:542
@ CAM_DEV_MATCH_LIST_CHANGED
Definition: cam_ccb.h:544
@ CAM_DEV_MATCH_MORE
Definition: cam_ccb.h:543
@ XPT_IMMED_NOTIFY
Definition: cam_ccb.h:245
@ XPT_DEBUG
Definition: cam_ccb.h:160
@ XPT_RESET_DEV
Definition: cam_ccb.h:176
@ XPT_TERM_IO
Definition: cam_ccb.h:178
@ XPT_DEV_ADVINFO
Definition: cam_ccb.h:166
@ XPT_GDEV_STATS
Definition: cam_ccb.h:164
@ XPT_NVME_ADMIN
Definition: cam_ccb.h:227
@ XPT_REPROBE_LUN
Definition: cam_ccb.h:253
@ XPT_ASYNC
Definition: cam_ccb.h:168
@ XPT_RESET_BUS
Definition: cam_ccb.h:174
@ XPT_FC_QUEUED
Definition: cam_ccb.h:131
@ XPT_GET_TRAN_SETTINGS
Definition: cam_ccb.h:183
@ XPT_SCSI_IO
Definition: cam_ccb.h:141
@ XPT_SCAN_TGT
Definition: cam_ccb.h:223
@ XPT_ACCEPT_TARGET_IO
Definition: cam_ccb.h:241
@ XPT_ENG_INQ
Definition: cam_ccb.h:231
@ XPT_SCAN_BUS
Definition: cam_ccb.h:155
@ XPT_ENG_EXEC
Definition: cam_ccb.h:233
@ XPT_TARGET_IO
Definition: cam_ccb.h:239
@ XPT_MMC_GET_TRAN_SETTINGS
Definition: cam_ccb.h:257
@ XPT_SASYNC_CB
Definition: cam_ccb.h:151
@ XPT_NOOP
Definition: cam_ccb.h:139
@ XPT_MMC_IO
Definition: cam_ccb.h:220
@ XPT_SET_TRAN_SETTINGS
Definition: cam_ccb.h:188
@ XPT_NVME_IO
Definition: cam_ccb.h:217
@ XPT_GDEVLIST
Definition: cam_ccb.h:145
@ XPT_SET_SIM_KNOB
Definition: cam_ccb.h:204
@ XPT_SCAN_LUN
Definition: cam_ccb.h:180
@ XPT_REL_SIMQ
Definition: cam_ccb.h:149
@ XPT_IMMEDIATE_NOTIFY
Definition: cam_ccb.h:249
@ XPT_CALC_GEOMETRY
Definition: cam_ccb.h:193
@ XPT_GET_SIM_KNOB
Definition: cam_ccb.h:209
@ XPT_ATA_IO
Definition: cam_ccb.h:199
@ XPT_FC_USER_CCB
Definition: cam_ccb.h:133
@ XPT_FC_DEV_QUEUED
Definition: cam_ccb.h:136
@ XPT_ABORT
Definition: cam_ccb.h:172
@ XPT_NOTIFY_ACK
Definition: cam_ccb.h:247
@ XPT_SMP_IO
Definition: cam_ccb.h:214
@ XPT_GET_SIM_KNOB_OLD
Definition: cam_ccb.h:202
@ XPT_EN_LUN
Definition: cam_ccb.h:237
@ XPT_PATH_INQ
Definition: cam_ccb.h:147
@ XPT_PATH_STATS
Definition: cam_ccb.h:162
@ XPT_MMC_SET_TRAN_SETTINGS
Definition: cam_ccb.h:256
@ XPT_GDEV_TYPE
Definition: cam_ccb.h:143
@ XPT_DEV_MATCH
Definition: cam_ccb.h:158
@ XPT_NOTIFY_ACKNOWLEDGE
Definition: cam_ccb.h:251
@ XPT_SDEV_TYPE
Definition: cam_ccb.h:153
@ XPT_CONT_TARGET_IO
Definition: cam_ccb.h:243
@ CAM_CCB_FROM_UMA
Definition: cam_ccb.h:64
#define CDAI_FLAG_NONE
Definition: cam_ccb.h:1311
#define CAM_SUCCESS
Definition: cam_ccb.h:1298
#define CDAI_TYPE_SERIAL_NUM
Definition: cam_ccb.h:1316
#define CAM_TAG_ACTION_NONE
Definition: cam_ccb.h:772
#define HBA_IDLEN
Definition: cam_ccb.h:53
#define CDAI_TYPE_PHYS_PATH
Definition: cam_ccb.h:1317
#define SIM_IDLEN
Definition: cam_ccb.h:52
#define RELSIM_RELEASE_AFTER_CMDCMPLT
Definition: cam_ccb.h:842
#define DEV_IDLEN
Definition: cam_ccb.h:54
#define RELSIM_RELEASE_AFTER_QEMPTY
Definition: cam_ccb.h:843
#define CDAI_TYPE_SCSI_DEVID
Definition: cam_ccb.h:1315
int cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td, d_ioctl_t *cbfnp)
Definition: cam_compat.c:66
#define CAM_DEBUG_DELAY
Definition: cam_debug.h:76
#define CAM_DEBUG_DEV(dev, flag, printfargs)
Definition: cam_debug.h:104
#define CAM_DEBUG_LUN
Definition: cam_debug.h:72
#define CAM_DEBUG_TARGET
Definition: cam_debug.h:69
#define CAM_DEBUG_BUS
Definition: cam_debug.h:66
#define CAM_DEBUG_COMPILE
Definition: cam_debug.h:59
@ CAM_DEBUG_TRACE
Definition: cam_debug.h:41
@ CAM_DEBUG_NONE
Definition: cam_debug.h:39
@ CAM_DEBUG_INFO
Definition: cam_debug.h:40
@ CAM_DEBUG_XPT
Definition: cam_debug.h:44
#define CAM_DEBUG_FLAGS
Definition: cam_debug.h:52
#define CAM_DEBUG(path, flag, printfargs)
Definition: cam_debug.h:93
#define CAM_DEBUG_PRINT(flag, printfargs)
Definition: cam_debug.h:115
static uintptr_t cam_iosched_delta_t(uintptr_t then)
Definition: cam_iosched.h:68
static uintptr_t cam_iosched_now(void)
Definition: cam_iosched.h:60
void cam_periph_release_locked(struct cam_periph *periph)
Definition: cam_periph.c:453
void periphdriver_init(int level)
Definition: cam_periph.c:184
u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, u_int32_t openings, u_int32_t arg, int getcount_only)
Definition: cam_periph.c:1342
void cam_periph_unmapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo)
Definition: cam_periph.c:1005
void cam_periph_doacquire(struct cam_periph *periph)
Definition: cam_periph.c:432
void cam_periph_release(struct cam_periph *periph)
Definition: cam_periph.c:465
int cam_periph_runccb(union ccb *ccb, int(*error_routine)(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags), cam_flags camflags, u_int32_t sense_flags, struct devstat *ds)
Definition: cam_periph.c:1207
struct periph_driver ** periph_drivers
Definition: cam_periph.c:99
int cam_periph_mapmem(union ccb *ccb, struct cam_periph_map_info *mapinfo, u_int maxmap)
Definition: cam_periph.c:793
cam_status cam_periph_alloc(periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, periph_dtor_t *periph_dtor, periph_start_t *periph_start, char *name, cam_periph_type type, struct cam_path *path, ac_callback_t *ac_callback, ac_code code, void *arg)
Definition: cam_periph.c:197
#define cam_periph_assert(periph, what)
Definition: cam_periph.h:230
#define cam_periph_lock(periph)
Definition: cam_periph.h:224
#define CAM_PERIPH_DRV_EARLY
Definition: cam_periph.h:99
#define cam_periph_unlock(periph)
Definition: cam_periph.h:227
#define CAM_PERIPH_RUN_TASK
Definition: cam_periph.h:136
#define CAM_PERIPH_ANNOUNCED
Definition: cam_periph.h:138
#define CAM_PERIPH_FREE
Definition: cam_periph.h:137
#define cam_periph_sleep(periph, chan, priority, wmesg, timo)
Definition: cam_periph.h:233
@ CAM_PERIPH_BIO
Definition: cam_periph.h:104
void() periph_init_t(void)
Definition: cam_periph.h:85
u_int32_t cam_devq_resize(struct cam_devq *camq, int devices)
Definition: cam_queue.c:225
void cam_ccbq_fini(struct cam_ccbq *ccbq)
Definition: cam_queue.c:289
void camq_change_priority(struct camq *queue, int index, u_int32_t new_priority)
Definition: cam_queue.c:173
void camq_insert(struct camq *queue, cam_pinfo *new_entry)
Definition: cam_queue.c:126
u_int32_t cam_ccbq_resize(struct cam_ccbq *ccbq, int new_size)
Definition: cam_queue.c:261
cam_pinfo * camq_remove(struct camq *queue, int index)
Definition: cam_queue.c:146
int cam_ccbq_init(struct cam_ccbq *ccbq, int openings)
Definition: cam_queue.c:277
#define CAMQ_GET_PRIO(camq)
Definition: cam_queue.h:135
static __inline int cam_ccbq_pending_ccb_count(struct cam_ccbq *ccbq)
Definition: cam_queue.h:170
TAILQ_HEAD(ccb_hdr_tailq, ccb_hdr)
#define CAMQ_HEAD
Definition: cam_queue.h:129
static __inline union ccb * cam_ccbq_peek_ccb(struct cam_ccbq *ccbq, int index)
Definition: cam_queue.h:250
static __inline void cam_ccbq_send_ccb(struct cam_ccbq *queue, union ccb *send_ccb)
Definition: cam_queue.h:256
static __inline void cam_ccbq_release_opening(struct cam_ccbq *ccbq)
Definition: cam_queue.h:273
static __inline void cam_ccbq_remove_ccb(struct cam_ccbq *ccbq, union ccb *ccb)
Definition: cam_queue.h:210
static __inline void cam_ccbq_insert_ccb(struct cam_ccbq *ccbq, union ccb *new_ccb)
Definition: cam_queue.h:183
static __inline void cam_ccbq_ccb_done(struct cam_ccbq *ccbq, union ccb *done_ccb)
Definition: cam_queue.h:265
static __inline void cam_ccbq_take_opening(struct cam_ccbq *ccbq)
Definition: cam_queue.h:176
struct cam_sim * cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll, const char *sim_name, void *softc, u_int32_t unit, struct mtx *mtx, int max_dev_transactions, int max_tagged_dev_transactions, struct cam_devq *queue)
allocate a new sim and fill in the details
Definition: cam_sim.c:103
struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions)
Definition: cam_sim.c:55
void cam_sim_release(struct cam_sim *sim)
Definition: cam_sim.c:172
void cam_sim_hold(struct cam_sim *sim)
Definition: cam_sim.c:193
static __inline bool cam_sim_pollable(const struct cam_sim *sim)
Definition: cam_sim.h:139
#define XPT_PRINT_MAXLEN
Definition: cam_xpt.c:79
static struct proc * cam_proc
Definition: cam_xpt.c:182
int xpt_bus_deregister(path_id_t pathid)
Definition: cam_xpt.c:4065
void xpt_acquire_device(struct cam_ed *device)
Definition: cam_xpt.c:4897
DECLARE_MODULE(cam, cam_moduledata, SI_SUB_CONFIGURE, SI_ORDER_SECOND)
static dev_match_ret xptbusmatch(struct dev_match_pattern *patterns, u_int num_patterns, struct cam_eb *bus)
Definition: cam_xpt.c:1366
static int xpt_async_process_tgt(struct cam_et *target, void *arg)
Definition: cam_xpt.c:4257
static periph_init_t xpt_periph_init
Definition: cam_xpt.c:190
int xpt_targetfunc_t(struct cam_et *target, void *arg)
Definition: cam_xpt.c:157
static int xptedtmatch(struct ccb_dev_match *cdm)
Definition: cam_xpt.c:2002
static void xpt_dev_async_default(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg)
Definition: cam_xpt.c:4404
static void xpt_done_process(struct ccb_hdr *ccb_h)
Definition: cam_xpt.c:5335
int xpt_path_comp_dev(struct cam_path *path, struct cam_ed *dev)
Definition: cam_xpt.c:3752
static xpt_periphfunc_t xptplistperiphfunc
Definition: cam_xpt.c:289
union ccb * xpt_alloc_ccb(void)
Definition: cam_xpt.c:4612
void xpt_denounce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
Definition: cam_xpt.c:1203
void xpt_sim_poll(struct cam_sim *sim)
Definition: cam_xpt.c:3165
void xpt_print_path(struct cam_path *path)
Definition: cam_xpt.c:3786
static const char * xpt_async_string(u_int32_t async_code)
Definition: cam_xpt.c:4161
struct mtx * xpt_path_mtx(struct cam_path *path)
Definition: cam_xpt.c:5328
CAM_XPT_XPORT(xport_default)
int xpt_path_string(struct cam_path *path, char *str, size_t str_len)
Definition: cam_xpt.c:3833
void xpt_schedule(struct cam_periph *periph, u_int32_t new_priority)
Definition: cam_xpt.c:3243
void xpt_merge_ccb(union ccb *dst_ccb, union ccb *src_ccb)
Definition: cam_xpt.c:3480
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3527
int xpt_getattr(char *buf, size_t len, const char *attr, struct cam_path *path)
Definition: cam_xpt.c:1243
u_int32_t xpt_freeze_devq(struct cam_path *path, u_int count)
Definition: cam_xpt.c:4438
static struct cam_ed * xpt_find_device(struct cam_et *target, lun_id_t lun_id)
Definition: cam_xpt.c:5009
void xpt_start_tags(struct cam_path *path)
Definition: cam_xpt.c:5026
void xpt_setup_ccb_flags(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority, u_int32_t flags)
Definition: cam_xpt.c:3496
int32_t xpt_add_periph(struct cam_periph *periph)
Definition: cam_xpt.c:1014
static void xpt_async_process(struct cam_periph *periph, union ccb *ccb)
Definition: cam_xpt.c:4276
void xpt_unlock_buses(void)
Definition: cam_xpt.c:5322
void xpt_release_device(struct cam_ed *device)
Definition: cam_xpt.c:4907
void xpt_print(struct cam_path *path, const char *fmt,...)
Definition: cam_xpt.c:3814
void xpt_pollwait(union ccb *start_ccb, uint32_t timeout)
Definition: cam_xpt.c:3214
static struct xpt_proto * xpt_proto_find(cam_proto proto)
Definition: cam_xpt.c:773
static struct periph_driver xpt_driver
Definition: cam_xpt.c:192
#define XPT_PRINT_LEN
Definition: cam_xpt.c:83
static struct cam_ed * xpt_alloc_device_default(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: cam_xpt.c:4815
static void xpt_acquire_target(struct cam_et *target)
Definition: cam_xpt.c:4783
union ccb * cam_periph_getccb(struct cam_periph *periph, u_int32_t priority)
Definition: cam_xpt.c:4695
static int xptperiphtraverse(struct cam_ed *device, struct cam_periph *start_periph, xpt_periphfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2325
static struct cdevsw xpt_cdevsw
Definition: cam_xpt.c:206
static void xpt_boot_delay(void *arg)
Definition: cam_xpt.c:5087
static int xptdevicetraverse(struct cam_et *target, struct cam_ed *start_device, xpt_devicefunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2285
static void xpt_config(void *arg)
Definition: cam_xpt.c:5111
static void xpt_release_bus(struct cam_eb *bus)
Definition: cam_xpt.c:4724
void xpt_rescan(union ccb *ccb)
Definition: cam_xpt.c:840
static xpt_busfunc_t xptedtbusfunc
Definition: cam_xpt.c:284
dev_match_ret
Definition: cam_xpt.c:133
@ DM_RET_FLAG_MASK
Definition: cam_xpt.c:135
@ DM_RET_DESCEND
Definition: cam_xpt.c:138
@ DM_RET_ACTION_MASK
Definition: cam_xpt.c:140
@ DM_RET_STOP
Definition: cam_xpt.c:137
@ DM_RET_ERROR
Definition: cam_xpt.c:139
@ DM_RET_COPY
Definition: cam_xpt.c:134
@ DM_RET_NONE
Definition: cam_xpt.c:136
void xpt_release_path(struct cam_path *path)
Definition: cam_xpt.c:3654
static struct kv map[]
Definition: cam_xpt.c:5562
static int xpt_async_process_dev(struct cam_ed *device, void *arg)
Definition: cam_xpt.c:4207
static dev_match_ret xptperiphmatch(struct dev_match_pattern *patterns, u_int num_patterns, struct cam_periph *periph)
Definition: cam_xpt.c:1584
MODULE_VERSION(cam, 1)
int xpt_path_comp(struct cam_path *path1, struct cam_path *path2)
Definition: cam_xpt.c:3718
path_id_t xpt_path_path_id(struct cam_path *path)
Definition: cam_xpt.c:3880
static int xpt_init(void *)
Definition: cam_xpt.c:889
static int xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo, u_int32_t new_priority)
Definition: cam_xpt.c:3263
MTX_SYSINIT(xpt_topo_init, &xsoftc.xpt_topo_lock, "XPT topology lock", MTX_DEF)
static xpt_busfunc_t xptdefbusfunc
Definition: cam_xpt.c:309
void xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
Definition: cam_xpt.c:4350
void xpt_lock_buses(void)
Definition: cam_xpt.c:5316
static struct xpt_xport_ops xport_default_ops
Definition: cam_xpt.c:3942
static void xpt_run_allocq(struct cam_periph *periph, int sleep)
Definition: cam_xpt.c:3314
void xpt_announce_periph(struct cam_periph *periph, char *announce_string)
Definition: cam_xpt.c:1049
static void xpt_async_bcast(struct async_list *async_head, u_int32_t async_code, struct cam_path *path, void *async_arg)
Definition: cam_xpt.c:4318
void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
Definition: cam_xpt.c:3520
PERIPHDRIVER_DECLARE(xpt, xpt_driver)
SYSINIT(xpt_hw_delay, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_ANY, xpt_ch_done, NULL)
SYSCTL_INT(_kern_cam, OID_AUTO, boot_delay, CTLFLAG_RDTUN, &xsoftc.boot_delay, 0, "Bus registration wait time")
static void xptaction(struct cam_sim *sim, union ccb *work_ccb)
Definition: cam_xpt.c:5267
static void camisr_runqueue(void)
Definition: cam_xpt.c:5520
u_int32_t xpt_freeze_simq(struct cam_sim *sim, u_int count)
Definition: cam_xpt.c:4453
static void xpt_async_td(void *)
Definition: cam_xpt.c:5465
void xpt_release_simq(struct cam_sim *sim, int run_queue)
Definition: cam_xpt.c:4537
void xpt_action(union ccb *start_ccb)
Definition: cam_xpt.c:2601
void xpt_done(union ccb *done_ccb)
Definition: cam_xpt.c:4562
void xpt_announce_quirks_sbuf(struct cam_periph *periph, struct sbuf *sb, int quirks, char *bit_string)
Definition: cam_xpt.c:1160
static __inline int xpt_schedule_devq(struct cam_devq *devq, struct cam_ed *dev)
Definition: cam_xpt.c:328
u_int32_t __read_mostly cam_dflags
Definition: cam_xpt.c:217
static xpt_targetfunc_t xptedttargetfunc
Definition: cam_xpt.c:285
static d_ioctl_t xptdoioctl
Definition: cam_xpt.c:204
#define CAM_MAX_HIGHPOWER
Definition: cam_xpt.c:92
static int xptpdperiphtraverse(struct periph_driver **pdrv, struct cam_periph *start_periph, xpt_periphfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2402
static path_id_t xptpathid(const char *sim_name, int sim_unit, int sim_bus)
Definition: cam_xpt.c:4116
static xpt_devicefunc_t xptpassannouncefunc
Definition: cam_xpt.c:269
cam_status xpt_register_async(int event, ac_callback_t *cbfunc, void *cbarg, struct cam_path *path)
Definition: cam_xpt.c:5213
static xpt_pdrvfunc_t xptplistpdrvfunc
Definition: cam_xpt.c:288
static xpt_devicefunc_t xptsetasyncfunc
Definition: cam_xpt.c:322
static void xpt_acquire_bus(struct cam_eb *bus)
Definition: cam_xpt.c:4715
static union ccb * xpt_get_ccb(struct cam_periph *periph)
Definition: cam_xpt.c:4674
struct cam_periph * xpt_periph
Definition: cam_xpt.c:188
static xpt_periphfunc_t xptdefperiphfunc
Definition: cam_xpt.c:312
uint32_t xpt_poll_setup(union ccb *start_ccb)
Definition: cam_xpt.c:3180
static xpt_devicefunc_t xptdefdevicefunc
Definition: cam_xpt.c:311
__FBSDID("$FreeBSD$")
lun_id_t xpt_path_lun_id(struct cam_path *path)
Definition: cam_xpt.c:3895
void xpt_denounce_periph(struct cam_periph *periph)
Definition: cam_xpt.c:1175
static void xpt_finishconfig_task(void *context, int pending)
Definition: cam_xpt.c:5197
static union ccb * xpt_get_ccb_nowait(struct cam_periph *periph)
Definition: cam_xpt.c:4653
int xpt_pdrvfunc_t(struct periph_driver **pdrv, void *arg)
Definition: cam_xpt.c:160
static d_open_t xptopen
Definition: cam_xpt.c:201
struct cam_sim * xpt_path_sim(struct cam_path *path)
Definition: cam_xpt.c:3904
static xpt_targetfunc_t xptdeftargetfunc
Definition: cam_xpt.c:310
u_int32_t cam_debug_delay
Definition: cam_xpt.c:220
union ccb * xpt_alloc_ccb_nowait(void)
Definition: cam_xpt.c:4621
void xpt_print_device(struct cam_ed *device)
Definition: cam_xpt.c:3799
static void xpt_scanner_thread(void *dummy)
Definition: cam_xpt.c:801
void xpt_free_path(struct cam_path *path)
Definition: cam_xpt.c:3672
void xpt_action_default(union ccb *start_ccb)
Definition: cam_xpt.c:2613
SYSCTL_UINT(_kern_cam, OID_AUTO, xpt_generation, CTLFLAG_RD, &xsoftc.xpt_generation, 0, "CAM peripheral generation count")
static int xpt_release_devq_device(struct cam_ed *dev, u_int count, int run_queue)
Definition: cam_xpt.c:4496
int xpt_periphfunc_t(struct cam_periph *periph, void *arg)
Definition: cam_xpt.c:159
struct cam_path * cam_dpath
Definition: cam_xpt.c:216
static int xpt_for_all_devices(xpt_devicefunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2534
void xpt_release_boot(void)
Definition: cam_xpt.c:5157
static struct cam_eb * xpt_find_bus(path_id_t path_id)
Definition: cam_xpt.c:4974
static struct xpt_softc xsoftc
Definition: cam_xpt.c:163
static cam_status xptregister(struct cam_periph *periph, void *arg)
Definition: cam_xpt.c:996
int xpt_bus_register(struct cam_sim *sim, device_t parent, uint32_t bus)
Definition: cam_xpt.c:3965
static void xpt_run_devq(struct cam_devq *devq)
Definition: cam_xpt.c:3370
static moduledata_t cam_moduledata
Definition: cam_xpt.c:227
static struct cam_doneq cam_async
Definition: cam_xpt.c:183
static int xptpdrvtraverse(struct periph_driver **start_pdrv, xpt_pdrvfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2374
static struct cam_doneq cam_doneqs[MAXCPU]
Definition: cam_xpt.c:180
static callout_func_t xpt_release_devq_timeout
Definition: cam_xpt.c:249
static int xpt_for_all_busses(xpt_busfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2519
static struct xpt_xport xport_default
Definition: cam_xpt.c:3947
static void xpt_rescan_done(struct cam_periph *periph, union ccb *done_ccb)
Definition: cam_xpt.c:786
int xpt_path_sbuf(struct cam_path *path, struct sbuf *sb)
Definition: cam_xpt.c:3845
static void xptpoll(struct cam_sim *sim)
Definition: cam_xpt.c:5311
static __inline int device_is_queued(struct cam_ed *device)
Definition: cam_xpt.c:352
static u_int __read_mostly cam_num_doneqs
Definition: cam_xpt.c:181
cam_status xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3559
void xpt_stop_tags(struct cam_path *path)
Definition: cam_xpt.c:5057
static xpt_busfunc_t xptsetasyncbusfunc
Definition: cam_xpt.c:323
int xpt_busfunc_t(struct cam_eb *bus, void *arg)
Definition: cam_xpt.c:156
MALLOC_DEFINE(M_CAMXPT, "CAM XPT", "CAM XPT buffers")
static struct cam_et * xpt_alloc_target(struct cam_eb *bus, target_id_t target_id)
Definition: cam_xpt.c:4744
static int xptperiphlistmatch(struct ccb_dev_match *cdm)
Definition: cam_xpt.c:2176
struct cam_periph * xpt_path_periph(struct cam_path *path)
Definition: cam_xpt.c:3911
static d_ioctl_t xptioctl
Definition: cam_xpt.c:203
static int cam_module_event_handler(module_t, int, void *)
Definition: cam_xpt.c:754
void xpt_release_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:3924
static void xpt_hold_boot_locked(void)
Definition: cam_xpt.c:5140
int xpt_devicefunc_t(struct cam_ed *device, void *arg)
Definition: cam_xpt.c:158
void xpt_done_direct(union ccb *done_ccb)
Definition: cam_xpt.c:4597
int xpt_clone_path(struct cam_path **new_path_ptr, struct cam_path *path)
Definition: cam_xpt.c:3635
struct cam_ed * xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: cam_xpt.c:4840
const char * xpt_action_name(uint32_t action)
Definition: cam_xpt.c:5608
static void xpt_destroy_device(void *context, int pending)
Definition: cam_xpt.c:4830
target_id_t xpt_path_target_id(struct cam_path *path)
Definition: cam_xpt.c:3886
static xpt_periphfunc_t xptedtperiphfunc
Definition: cam_xpt.c:287
static int xpt_async_size(u_int32_t async_code)
Definition: cam_xpt.c:4184
static int xptbustraverse(struct cam_eb *start_bus, xpt_busfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2214
void xpt_announce_quirks(struct cam_periph *periph, int quirks, char *bit_string)
Definition: cam_xpt.c:1151
_Static_assert(XPT_PRINT_LEN<=XPT_PRINT_MAXLEN, "XPT_PRINT_LEN is too large")
static dev_match_ret xptdevicematch(struct dev_match_pattern *patterns, u_int num_patterns, struct cam_ed *device)
Definition: cam_xpt.c:1466
device_t xpt_path_sim_device(const struct cam_path *path)
Return the device_t associated with the path.
Definition: cam_xpt.c:5551
void xpt_hold_boot(void)
Definition: cam_xpt.c:5148
static void xpt_release_target(struct cam_et *target)
Definition: cam_xpt.c:4793
static void xpt_run_allocq_task(void *context, int pending)
Definition: cam_xpt.c:3302
u_int32_t xpt_dev_ccbq_resize(struct cam_path *path, int newopenings)
Definition: cam_xpt.c:4958
static void xpt_done_td(void *)
Definition: cam_xpt.c:5490
static void xpt_ch_done(void *arg)
Definition: cam_xpt.c:5098
void xpt_release_devq(struct cam_path *path, u_int count, int run_queue)
Definition: cam_xpt.c:4480
static int xpttargettraverse(struct cam_eb *bus, struct cam_et *start_target, xpt_targetfunc_t *tr_func, void *arg)
Definition: cam_xpt.c:2249
void xpt_free_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:4630
void xpt_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb, char *announce_string)
Definition: cam_xpt.c:1093
cam_status xpt_create_path_unlocked(struct cam_path **new_path_ptr, struct cam_periph *periph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3549
void xpt_path_counts(struct cam_path *path, uint32_t *bus_ref, uint32_t *periph_ref, uint32_t *target_ref, uint32_t *device_ref)
Definition: cam_xpt.c:3681
void xpt_remove_periph(struct cam_periph *periph)
Definition: cam_xpt.c:1034
static uint32_t xpt_freeze_devq_device(struct cam_ed *dev, u_int count)
Definition: cam_xpt.c:4420
static struct cam_et * xpt_find_target(struct cam_eb *bus, target_id_t target_id)
Definition: cam_xpt.c:4992
static path_id_t xptnextfreepathid(void)
Definition: cam_xpt.c:4086
xpt_traverse_depth
Definition: cam_xpt.c:143
@ XPT_DEPTH_DEVICE
Definition: cam_xpt.c:146
@ XPT_DEPTH_PERIPH
Definition: cam_xpt.c:147
@ XPT_DEPTH_BUS
Definition: cam_xpt.c:144
@ XPT_DEPTH_TARGET
Definition: cam_xpt.c:145
static xpt_devicefunc_t xptedtdevicefunc
Definition: cam_xpt.c:286
static d_close_t xptclose
Definition: cam_xpt.c:202
#define xpt_path_unlock(path)
Definition: cam_xpt.h:129
#define xpt_path_lock(path)
Definition: cam_xpt.h:128
#define xpt_path_assert(path, what)
Definition: cam_xpt.h:130
static void xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
Definition: cam_xpt.h:156
#define CAM_DEV_UNCONFIGURED
#define CAM_DEV_REL_ON_COMPLETE
#define CAM_DEV_REL_TIMEOUT_PENDING
#define CAM_DEV_TAG_AFTER_COUNT
#define CAM_DEV_REL_ON_QUEUE_EMPTY
union ccb * ccb
Definition: mmc_sim_if.m:53
int scsi_devid_is_lun_eui64(uint8_t *bufp)
Definition: scsi_all.c:5623
int scsi_devid_is_lun_name(uint8_t *bufp)
Definition: scsi_all.c:5662
int scsi_devid_is_lun_naa(uint8_t *bufp)
Definition: scsi_all.c:5636
struct scsi_vpd_id_descriptor * scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t page_len, scsi_devid_checkfn_t ck_fn)
Definition: scsi_all.c:5732
int scsi_devid_match(uint8_t *lhs, size_t lhs_len, uint8_t *rhs, size_t rhs_len)
Definition: scsi_all.c:9227
int scsi_devid_is_lun_t10(uint8_t *bufp)
Definition: scsi_all.c:5649
int scsi_devid_is_lun_uuid(uint8_t *bufp)
Definition: scsi_all.c:5688
int scsi_devid_is_lun_md5(uint8_t *bufp)
Definition: scsi_all.c:5675
int scsi_static_inquiry_match(caddr_t inqbuffer, caddr_t table_entry)
Definition: scsi_all.c:9190
#define SCSI_REV_2
Definition: scsi_all.h:2222
#define SID_CmdQue
Definition: scsi_all.h:2262
#define SVPD_ID_CODESET_UTF8
Definition: scsi_all.h:2371
#define SVPD_ID_TYPE_MASK
Definition: scsi_all.h:2390
#define SVPD_ID_TYPE_UUID
Definition: scsi_all.h:2389
#define SVPD_ID_CODESET_MASK
Definition: scsi_all.h:2372
#define SCSI_STATUS_OK
Definition: scsi_all.h:3691
#define SVPD_ID_CODESET_ASCII
Definition: scsi_all.h:2370
#define SVPD_DEVICE_ID_HDR_LEN
Definition: scsi_all.h:2356
STAILQ_HEAD(ctlfe_softc)
Definition: scsi_ctl.c:92
#define CAMGETPASSTHRU
Definition: scsi_pass.h:42
#define CAMIOCOMMAND
Definition: scsi_pass.h:41
void * callback_arg
Definition: cam_xpt.h:70
void(* callback)(void *arg, u_int32_t code, struct cam_path *path, void *args)
Definition: cam_xpt.h:68
u_int32_t event_enable
Definition: cam_xpt.h:66
u_int32_t event_lock
Definition: cam_xpt.h:67
char dev_name[DEV_IDLEN]
Definition: cam_ccb.h:477
u_int32_t bus_id
Definition: cam_ccb.h:479
u_int32_t unit_number
Definition: cam_ccb.h:478
bus_pattern_flags flags
Definition: cam_ccb.h:480
path_id_t path_id
Definition: cam_ccb.h:476
u_int32_t unit_number
Definition: cam_ccb.h:526
char dev_name[DEV_IDLEN]
Definition: cam_ccb.h:525
u_int32_t bus_id
Definition: cam_ccb.h:527
path_id_t path_id
Definition: cam_ccb.h:524
int total_openings
Definition: cam_queue.h:66
int dev_active
Definition: cam_queue.h:69
int allocated
Definition: cam_queue.h:67
int dev_openings
Definition: cam_queue.h:68
struct camq queue
Definition: cam_queue.h:63
int send_active
Definition: cam_queue.h:78
struct camq send_queue
Definition: cam_queue.h:76
struct mtx send_mtx
Definition: cam_queue.h:75
int send_openings
Definition: cam_queue.h:77
struct mtx_padalign cam_doneq_mtx
Definition: cam_xpt.c:175
struct timeval last_reset
u_int32_t refcount
path_id_t path_id
u_int generation
struct xpt_xport * xport
device_t parent_dev
struct cam_sim * sim
u_int32_t flags
struct mtx eb_mtx
uint8_t * supported_vpds
u_int protocol_version
struct cam_sim * sim
uint8_t * ext_inq
uint8_t * rcap_buf
struct task device_destroy_task
u_int maxtags
u_int32_t tag_delay_count
struct periph_list periphs
u_int generation
struct cam_ccbq ccbq
u_int8_t * serial_num
struct mtx device_mtx
cam_pinfo devq_entry
u_int mintags
struct cam_et * target
u_int8_t serial_num_len
lun_id_t lun_id
u_int8_t inq_flags
struct nvme_namespace_data * nvme_data
struct ata_params ident_data
uint8_t * device_id
struct async_list asyncs
uint8_t * physpath
cam_proto protocol
struct nvme_controller_data * nvme_cdata
struct callout callout
u_int32_t tag_saved_openings
u_int32_t flags
struct scsi_inquiry_data inq_data
u_int32_t refcount
u_int generation
struct timeval last_reset
struct mtx luns_mtx
u_int32_t refcount
target_id_t target_id
struct scsi_report_luns_data * luns
struct cam_eb * bus
struct cam_ed * device
struct cam_et * target
struct cam_eb * bus
struct cam_periph * periph
periph_start_t * periph_start
Definition: cam_periph.h:120
char * periph_name
Definition: cam_periph.h:123
int periph_allocating
Definition: cam_periph.h:143
u_int32_t unit_number
Definition: cam_periph.h:127
u_int32_t refcount
Definition: cam_periph.h:145
uma_zone_t ccb_zone
Definition: cam_periph.h:152
void * softc
Definition: cam_periph.h:125
uint32_t scheduled_priority
Definition: cam_periph.h:141
struct task periph_run_task
Definition: cam_periph.h:151
struct cam_path * path
Definition: cam_periph.h:124
uint32_t immediate_priority
Definition: cam_periph.h:142
int periph_allocated
Definition: cam_periph.h:144
u_int32_t flags
Definition: cam_periph.h:129
Definition: cam.h:85
u_int32_t priority
Definition: cam.h:86
u_int32_t generation
Definition: cam.h:94
int index
Definition: cam.h:95
sim_poll_func sim_poll
Definition: cam_sim.h:93
void * softc
Definition: cam_sim.h:95
u_int32_t unit_number
Definition: cam_sim.h:99
u_int32_t path_id
Definition: cam_sim.h:98
int max_tagged_dev_openings
Definition: cam_sim.h:101
struct mtx * mtx
Definition: cam_sim.h:96
u_int32_t bus_id
Definition: cam_sim.h:100
sim_action_func sim_action
Definition: cam_sim.h:92
int max_dev_openings
Definition: cam_sim.h:102
struct cam_devq * devq
Definition: cam_sim.h:104
const char * sim_name
Definition: cam_sim.h:94
Definition: cam_queue.h:50
int array_size
Definition: cam_queue.h:52
int entries
Definition: cam_queue.h:53
u_int32_t qfrozen_cnt
Definition: cam_queue.h:55
u_int32_t generation
Definition: cam_queue.h:54
union ccb * abort_ccb
Definition: cam_ccb.h:925
void * async_arg_ptr
Definition: cam_ccb.h:1336
off_t async_arg_size
Definition: cam_ccb.h:1335
uint32_t async_code
Definition: cam_ccb.h:1334
u_int32_t resid
Definition: cam_ccb.h:798
u_int32_t block_size
Definition: cam_ccb.h:1136
u_int64_t volume_size
Definition: cam_ccb.h:1137
u_int32_t cylinders
Definition: cam_ccb.h:1138
u_int8_t heads
Definition: cam_ccb.h:1139
u_int8_t secs_per_track
Definition: cam_ccb.h:1140
cam_debug_flags flags
Definition: cam_ccb.h:1199
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1309
uint32_t buftype
Definition: cam_ccb.h:1313
uint8_t * buf
Definition: cam_ccb.h:1326
uint32_t flags
Definition: cam_ccb.h:1310
struct ccb_dev_position pos
Definition: cam_ccb.h:588
u_int32_t num_matches
Definition: cam_ccb.h:585
struct dev_match_result * matches
Definition: cam_ccb.h:587
ccb_dev_match_status status
Definition: cam_ccb.h:581
u_int32_t match_buf_len
Definition: cam_ccb.h:586
u_int32_t num_patterns
Definition: cam_ccb.h:582
struct dev_match_pattern * patterns
Definition: cam_ccb.h:584
u_int generations[4]
Definition: cam_ccb.h:570
struct ccb_dm_cookie cookie
Definition: cam_ccb.h:576
dev_pos_type position_type
Definition: cam_ccb.h:575
cam_proto protocol
Definition: cam_ccb.h:380
u_int8_t serial_num_len
Definition: cam_ccb.h:385
u_int8_t serial_num[252]
Definition: cam_ccb.h:383
struct ccb_hdr ccb_h
Definition: cam_ccb.h:379
struct ata_params ident_data
Definition: cam_ccb.h:382
struct scsi_inquiry_data inq_data
Definition: cam_ccb.h:381
u_int8_t inq_flags
Definition: cam_ccb.h:384
char periph_name[DEV_IDLEN]
Definition: cam_ccb.h:417
ccb_getdevlist_status_e status
Definition: cam_ccb.h:421
unsigned int generation
Definition: cam_ccb.h:419
struct ccb_hdr ccb_h
Definition: cam_ccb.h:416
u_int32_t unit_number
Definition: cam_ccb.h:418
u_int32_t index
Definition: cam_ccb.h:420
struct ccb_hdr ccb_h
Definition: cam_ccb.h:391
struct timeval last_reset
Definition: cam_ccb.h:405
int dev_openings
Definition: cam_ccb.h:392
u_int32_t xflags
Definition: cam_ccb.h:369
u_int32_t flags
Definition: cam_ccb.h:368
path_id_t path_id
Definition: cam_ccb.h:365
camq_entry sim_links
Definition: cam_ccb.h:351
struct cam_path * path
Definition: cam_ccb.h:364
cam_pinfo pinfo
Definition: cam_ccb.h:349
u_int16_t alloc_flags
Definition: cam_ccb.h:355
xpt_opcode func_code
Definition: cam_ccb.h:362
lun_id_t target_lun
Definition: cam_ccb.h:367
u_int32_t timeout
Definition: cam_ccb.h:373
u_int32_t status
Definition: cam_ccb.h:363
target_id_t target_id
Definition: cam_ccb.h:366
camq_entry periph_links
Definition: cam_ccb.h:352
u_int16_t retry_count
Definition: cam_ccb.h:354
ccb_qos_area qos
Definition: cam_ccb.h:372
void(* cbfcnp)(struct cam_periph *, union ccb *)
Definition: cam_ccb.h:360
cam_proto protocol
Definition: cam_ccb.h:680
u_int16_t hba_eng_cnt
Definition: cam_ccb.h:666
u_int8_t version_num
Definition: cam_ccb.h:662
u_int32_t max_target
Definition: cam_ccb.h:669
u_int32_t unit_number
Definition: cam_ccb.h:677
u_int protocol_version
Definition: cam_ccb.h:681
char hba_vid[HBA_IDLEN]
Definition: cam_ccb.h:675
char dev_name[DEV_IDLEN]
Definition: cam_ccb.h:676
u_int32_t hba_misc
Definition: cam_ccb.h:665
u_int8_t hba_inquiry
Definition: cam_ccb.h:663
char sim_vid[SIM_IDLEN]
Definition: cam_ccb.h:674
u_int16_t target_sprt
Definition: cam_ccb.h:664
struct ccb_hdr ccb_h
Definition: cam_ccb.h:661
u_int32_t max_lun
Definition: cam_ccb.h:670
u_int32_t base_transfer_speed
Definition: cam_ccb.h:679
cam_xport transport
Definition: cam_ccb.h:682
target_id_t initiator_id
Definition: cam_ccb.h:673
u_int transport_version
Definition: cam_ccb.h:683
u_int32_t bus_id
Definition: cam_ccb.h:678
struct timeval last_reset
Definition: cam_ccb.h:701
uintptr_t periph_data
Definition: cam_ccb.h:345
u_int32_t qfrozen_cnt
Definition: cam_ccb.h:846
struct ccb_hdr ccb_h
Definition: cam_ccb.h:838
u_int32_t openings
Definition: cam_ccb.h:844
u_int32_t release_timeout
Definition: cam_ccb.h:845
u_int32_t release_flags
Definition: cam_ccb.h:839
cam_flags flags
Definition: cam_ccb.h:1191
cdb_t cdb_io
Definition: cam_ccb.h:763
struct ccb_hdr ccb_h
Definition: cam_ccb.h:750
u_int8_t tag_action
Definition: cam_ccb.h:766
u_int8_t scsi_status
Definition: cam_ccb.h:760
u_int8_t sense_resid
Definition: cam_ccb.h:761
u_int32_t resid
Definition: cam_ccb.h:762
void * callback_arg
Definition: cam_ccb.h:911
struct ccb_hdr ccb_h
Definition: cam_ccb.h:908
u_int32_t event_enable
Definition: cam_ccb.h:909
ac_callback_t * callback
Definition: cam_ccb.h:910
dev_match_type type
Definition: cam_ccb.h:496
union match_pattern pattern
Definition: cam_ccb.h:497
union match_result result
Definition: cam_ccb.h:538
dev_match_type type
Definition: cam_ccb.h:537
uint8_t id[256]
Definition: cam_ccb.h:453
union device_match_pattern::@1 data
path_id_t path_id
Definition: cam_ccb.h:457
dev_pattern_flags flags
Definition: cam_ccb.h:460
struct device_id_match_pattern devid_pat
Definition: cam_ccb.h:463
struct scsi_static_inquiry_pattern inq_pat
Definition: cam_ccb.h:462
lun_id_t target_lun
Definition: cam_ccb.h:459
target_id_t target_id
Definition: cam_ccb.h:458
struct scsi_inquiry_data inq_data
Definition: cam_ccb.h:518
target_id_t target_id
Definition: cam_ccb.h:515
cam_proto protocol
Definition: cam_ccb.h:517
path_id_t path_id
Definition: cam_ccb.h:514
struct ata_params ident_data
Definition: cam_ccb.h:519
dev_result_flags flags
Definition: cam_ccb.h:520
lun_id_t target_lun
Definition: cam_ccb.h:516
Definition: cam_xpt.c:5557
const char * name
Definition: cam_xpt.c:5559
uint32_t v
Definition: cam_xpt.c:5558
char periph_name[DEV_IDLEN]
Definition: cam_ccb.h:434
periph_pattern_flags flags
Definition: cam_ccb.h:439
target_id_t target_id
Definition: cam_ccb.h:437
lun_id_t target_lun
Definition: cam_ccb.h:438
u_int32_t unit_number
Definition: cam_ccb.h:435
path_id_t path_id
Definition: cam_ccb.h:436
char periph_name[DEV_IDLEN]
Definition: cam_ccb.h:501
path_id_t path_id
Definition: cam_ccb.h:503
lun_id_t target_lun
Definition: cam_ccb.h:505
target_id_t target_id
Definition: cam_ccb.h:504
u_int32_t unit_number
Definition: cam_ccb.h:502
u_int8_t desc_list[]
Definition: scsi_all.h:2359
u_int8_t identifier[]
Definition: scsi_all.h:2395
xpt_proto_debug_out_func debug_out
struct xpt_proto_ops * ops
cam_proto proto
uint32_t xpt_generation
Definition: cam_xpt.c:102
struct mtx xpt_highpower_lock
Definition: cam_xpt.c:105
xpt_traverse_depth depth
Definition: cam_xpt.c:151
xpt_action_func action
xpt_announce_periph_sbuf_func announce_sbuf
xpt_dev_async_func async
xpt_announce_periph_func announce
xpt_alloc_device_func alloc_device
cam_xport xport
struct xpt_xport_ops * ops
Definition: cam_ccb.h:1345
struct ccb_dev_match cdm
Definition: cam_ccb.h:1356
struct ccb_getdevlist cgdl
Definition: cam_ccb.h:1349
struct ccb_relsim crs
Definition: cam_ccb.h:1351
struct ccb_getdevstats cgds
Definition: cam_ccb.h:1355
struct ccb_setasync csa
Definition: cam_ccb.h:1352
struct ccb_calc_geometry ccg
Definition: cam_ccb.h:1358
struct ccb_abort cab
Definition: cam_ccb.h:1360
struct ccb_pathstats cpis
Definition: cam_ccb.h:1354
struct ccb_async casync
Definition: cam_ccb.h:1378
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1346
struct ccb_debug cdbg
Definition: cam_ccb.h:1375
struct ccb_scsiio csio
Definition: cam_ccb.h:1347
struct ccb_getdev cgd
Definition: cam_ccb.h:1348
struct ccb_rescan crcn
Definition: cam_ccb.h:1374
struct ccb_pathinq cpi
Definition: cam_ccb.h:1350
struct ccb_ataio ataio
Definition: cam_ccb.h:1376
u_int8_t cdb_bytes[IOCDBLEN]
Definition: cam_ccb.h:742
struct bus_match_pattern bus_pattern
Definition: cam_ccb.h:486
struct device_match_pattern device_pattern
Definition: cam_ccb.h:485
struct periph_match_pattern periph_pattern
Definition: cam_ccb.h:484
struct device_match_result device_result
Definition: cam_ccb.h:532
struct bus_match_result bus_result
Definition: cam_ccb.h:533
struct periph_match_result periph_result
Definition: cam_ccb.h:531