1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs * Data structures and definitions for dealing with the
38b8a9b1dSJustin T. Gibbs * Common Access Method Transport (xpt) layer.
48b8a9b1dSJustin T. Gibbs *
54d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
6bec9534dSPedro F. Giffuni *
78b8a9b1dSJustin T. Gibbs * Copyright (c) 1997 Justin T. Gibbs.
88b8a9b1dSJustin T. Gibbs * All rights reserved.
98b8a9b1dSJustin T. Gibbs *
108b8a9b1dSJustin T. Gibbs * Redistribution and use in source and binary forms, with or without
118b8a9b1dSJustin T. Gibbs * modification, are permitted provided that the following conditions
128b8a9b1dSJustin T. Gibbs * are met:
138b8a9b1dSJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright
148b8a9b1dSJustin T. Gibbs * notice, this list of conditions, and the following disclaimer,
158b8a9b1dSJustin T. Gibbs * without modification, immediately at the beginning of the file.
168b8a9b1dSJustin T. Gibbs * 2. The name of the author may not be used to endorse or promote products
178b8a9b1dSJustin T. Gibbs * derived from this software without specific prior written permission.
188b8a9b1dSJustin T. Gibbs *
198b8a9b1dSJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
208b8a9b1dSJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218b8a9b1dSJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228b8a9b1dSJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
238b8a9b1dSJustin T. Gibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248b8a9b1dSJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258b8a9b1dSJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268b8a9b1dSJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278b8a9b1dSJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288b8a9b1dSJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298b8a9b1dSJustin T. Gibbs * SUCH DAMAGE.
308b8a9b1dSJustin T. Gibbs */
318b8a9b1dSJustin T. Gibbs
328b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_XPT_H
338b8a9b1dSJustin T. Gibbs #define _CAM_CAM_XPT_H 1
348b8a9b1dSJustin T. Gibbs
35a196ef64SJung-uk Kim #ifdef _KERNEL
36762a7f4fSWarner Losh #include <cam/cam_ccb.h>
37a196ef64SJung-uk Kim #endif
3870f2356dSWarner Losh #include <sys/sbuf.h>
39ab3e89f1SScott Long
408b8a9b1dSJustin T. Gibbs /* Forward Declarations */
418b8a9b1dSJustin T. Gibbs union ccb;
428b8a9b1dSJustin T. Gibbs struct cam_periph;
430d4f3c31SAlexander Motin struct cam_ed;
448b8a9b1dSJustin T. Gibbs struct cam_sim;
458b8a9b1dSJustin T. Gibbs
468b8a9b1dSJustin T. Gibbs /*
478b8a9b1dSJustin T. Gibbs * Definition of a CAM path. Paths are created from bus, target, and lun ids
488b8a9b1dSJustin T. Gibbs * via xpt_create_path and allow for reference to devices without recurring
498b8a9b1dSJustin T. Gibbs * lookups in the edt.
508b8a9b1dSJustin T. Gibbs */
518b8a9b1dSJustin T. Gibbs struct cam_path;
528b8a9b1dSJustin T. Gibbs
538b8a9b1dSJustin T. Gibbs /* Path functions */
548b8a9b1dSJustin T. Gibbs
55c4473420SPeter Wemm #ifdef _KERNEL
568b8a9b1dSJustin T. Gibbs
5752c9ce25SScott Long /*
5852c9ce25SScott Long * Definition of an async handler callback block. These are used to add
5952c9ce25SScott Long * SIMs and peripherals to the async callback lists.
6052c9ce25SScott Long */
6152c9ce25SScott Long struct async_node {
6252c9ce25SScott Long SLIST_ENTRY(async_node) links;
637af2f2c8SWarner Losh uint32_t event_enable; /* Async Event enables */
647af2f2c8SWarner Losh uint32_t event_lock; /* Take SIM lock for handlers. */
657af2f2c8SWarner Losh void (*callback)(void *arg, uint32_t code,
6652c9ce25SScott Long struct cam_path *path, void *args);
6752c9ce25SScott Long void *callback_arg;
6852c9ce25SScott Long };
6952c9ce25SScott Long
7052c9ce25SScott Long SLIST_HEAD(async_list, async_node);
7152c9ce25SScott Long SLIST_HEAD(periph_list, cam_periph);
7252c9ce25SScott Long
738b8a9b1dSJustin T. Gibbs void xpt_action(union ccb *new_ccb);
7452c9ce25SScott Long void xpt_action_default(union ccb *new_ccb);
7583c5d981SAlexander Motin union ccb *xpt_alloc_ccb(void);
7683c5d981SAlexander Motin union ccb *xpt_alloc_ccb_nowait(void);
7783c5d981SAlexander Motin void xpt_free_ccb(union ccb *free_ccb);
78a9934668SKenneth D. Merry void xpt_setup_ccb_flags(struct ccb_hdr *ccb_h,
79a9934668SKenneth D. Merry struct cam_path *path,
807af2f2c8SWarner Losh uint32_t priority,
817af2f2c8SWarner Losh uint32_t flags);
828b8a9b1dSJustin T. Gibbs void xpt_setup_ccb(struct ccb_hdr *ccb_h,
838b8a9b1dSJustin T. Gibbs struct cam_path *path,
847af2f2c8SWarner Losh uint32_t priority);
85f66ca1b1SWarner Losh void xpt_merge_ccb(union ccb *dst_ccb,
86f66ca1b1SWarner Losh union ccb *src_ccb);
878b8a9b1dSJustin T. Gibbs cam_status xpt_create_path(struct cam_path **new_path_ptr,
888b8a9b1dSJustin T. Gibbs struct cam_periph *perph,
898b8a9b1dSJustin T. Gibbs path_id_t path_id,
908b8a9b1dSJustin T. Gibbs target_id_t target_id, lun_id_t lun_id);
912b83592fSScott Long cam_status xpt_create_path_unlocked(struct cam_path **new_path_ptr,
922b83592fSScott Long struct cam_periph *perph,
932b83592fSScott Long path_id_t path_id,
942b83592fSScott Long target_id_t target_id, lun_id_t lun_id);
953501942bSJustin T. Gibbs int xpt_getattr(char *buf, size_t len, const char *attr,
963501942bSJustin T. Gibbs struct cam_path *path);
978b8a9b1dSJustin T. Gibbs void xpt_free_path(struct cam_path *path);
9815975b7bSMatt Jacob void xpt_path_counts(struct cam_path *path, uint32_t *bus_ref,
9915975b7bSMatt Jacob uint32_t *periph_ref, uint32_t *target_ref,
10015975b7bSMatt Jacob uint32_t *device_ref);
1018b8a9b1dSJustin T. Gibbs int xpt_path_comp(struct cam_path *path1,
1028b8a9b1dSJustin T. Gibbs struct cam_path *path2);
1030d4f3c31SAlexander Motin int xpt_path_comp_dev(struct cam_path *path,
1040d4f3c31SAlexander Motin struct cam_ed *dev);
105*6332e0f1SAlexander Motin char * xpt_path_string(struct cam_path *path, char *str,
1063393f8daSKenneth D. Merry size_t str_len);
107*6332e0f1SAlexander Motin void xpt_path_sbuf(struct cam_path *path, struct sbuf *sb);
1088b8a9b1dSJustin T. Gibbs path_id_t xpt_path_path_id(struct cam_path *path);
1098b8a9b1dSJustin T. Gibbs target_id_t xpt_path_target_id(struct cam_path *path);
1108b8a9b1dSJustin T. Gibbs lun_id_t xpt_path_lun_id(struct cam_path *path);
1118b8a9b1dSJustin T. Gibbs struct cam_sim *xpt_path_sim(struct cam_path *path);
1128b8a9b1dSJustin T. Gibbs struct cam_periph *xpt_path_periph(struct cam_path *path);
1131ed40162SWarner Losh device_t xpt_path_sim_device(const struct cam_path *path);
1149f1e411aSWarner Losh void xpt_print_path(struct cam_path *path);
1159f1e411aSWarner Losh void xpt_print(struct cam_path *path, const char *fmt, ...);
1167af2f2c8SWarner Losh void xpt_async(uint32_t async_code, struct cam_path *path,
1178b8a9b1dSJustin T. Gibbs void *async_arg);
1189e6461a2SMatt Jacob void xpt_rescan(union ccb *ccb);
11983c5d981SAlexander Motin void xpt_hold_boot(void);
12083c5d981SAlexander Motin void xpt_release_boot(void);
1212b83592fSScott Long void xpt_lock_buses(void);
1222b83592fSScott Long void xpt_unlock_buses(void);
123227d67aaSAlexander Motin struct mtx * xpt_path_mtx(struct cam_path *path);
124227d67aaSAlexander Motin #define xpt_path_lock(path) mtx_lock(xpt_path_mtx(path))
125227d67aaSAlexander Motin #define xpt_path_unlock(path) mtx_unlock(xpt_path_mtx(path))
126227d67aaSAlexander Motin #define xpt_path_assert(path, what) mtx_assert(xpt_path_mtx(path), (what))
127227d67aaSAlexander Motin #define xpt_path_owned(path) mtx_owned(xpt_path_mtx(path))
128227d67aaSAlexander Motin #define xpt_path_sleep(path, chan, priority, wmesg, timo) \
129227d67aaSAlexander Motin msleep((chan), xpt_path_mtx(path), (priority), (wmesg), (timo))
13085d92640SScott Long cam_status xpt_register_async(int event, ac_callback_t *cbfunc,
13185d92640SScott Long void *cbarg, struct cam_path *path);
13252c9ce25SScott Long cam_status xpt_compile_path(struct cam_path *new_path,
13352c9ce25SScott Long struct cam_periph *perph,
13452c9ce25SScott Long path_id_t path_id,
13552c9ce25SScott Long target_id_t target_id,
13652c9ce25SScott Long lun_id_t lun_id);
13750aa1dafSWarner Losh int xpt_clone_path(struct cam_path **new_path,
138227d67aaSAlexander Motin struct cam_path *path);
13952c9ce25SScott Long
14052c9ce25SScott Long void xpt_release_path(struct cam_path *path);
14152c9ce25SScott Long
142a94a63f0SWarner Losh const char * xpt_action_name(uint32_t action);
143f93a843cSWarner Losh void xpt_pollwait(union ccb *start_ccb, uint32_t timeout);
144f93a843cSWarner Losh uint32_t xpt_poll_setup(union ccb *start_ccb);
1450cc28e3cSWarner Losh void xpt_sim_poll(struct cam_sim *sim);
146a94a63f0SWarner Losh
147762a7f4fSWarner Losh /*
148762a7f4fSWarner Losh * Perform a path inquiry at the request priority. The bzero may be
149762a7f4fSWarner Losh * unnecessary.
150762a7f4fSWarner Losh */
151762a7f4fSWarner Losh static inline void
xpt_path_inq(struct ccb_pathinq * cpi,struct cam_path * path)152762a7f4fSWarner Losh xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
153762a7f4fSWarner Losh {
154762a7f4fSWarner Losh
155762a7f4fSWarner Losh bzero(cpi, sizeof(*cpi));
156762a7f4fSWarner Losh xpt_setup_ccb(&cpi->ccb_h, path, CAM_PRIORITY_NORMAL);
157762a7f4fSWarner Losh cpi->ccb_h.func_code = XPT_PATH_INQ;
158762a7f4fSWarner Losh xpt_action((union ccb *)cpi);
159762a7f4fSWarner Losh }
160762a7f4fSWarner Losh
161c4473420SPeter Wemm #endif /* _KERNEL */
1628b8a9b1dSJustin T. Gibbs
1638b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_XPT_H */
164