1898b0535SWarner Losh /*-
28b8a9b1dSJustin T. Gibbs * Data structures and definitions for SCSI Interface Modules (SIMs).
38b8a9b1dSJustin T. Gibbs *
44d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
5bec9534dSPedro F. Giffuni *
68b8a9b1dSJustin T. Gibbs * Copyright (c) 1997 Justin T. Gibbs.
78b8a9b1dSJustin T. Gibbs * All rights reserved.
88b8a9b1dSJustin T. Gibbs *
98b8a9b1dSJustin T. Gibbs * Redistribution and use in source and binary forms, with or without
108b8a9b1dSJustin T. Gibbs * modification, are permitted provided that the following conditions
118b8a9b1dSJustin T. Gibbs * are met:
128b8a9b1dSJustin T. Gibbs * 1. Redistributions of source code must retain the above copyright
138b8a9b1dSJustin T. Gibbs * notice, this list of conditions, and the following disclaimer,
148b8a9b1dSJustin T. Gibbs * without modification, immediately at the beginning of the file.
158b8a9b1dSJustin T. Gibbs * 2. The name of the author may not be used to endorse or promote products
168b8a9b1dSJustin T. Gibbs * derived from this software without specific prior written permission.
178b8a9b1dSJustin T. Gibbs *
188b8a9b1dSJustin T. Gibbs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
198b8a9b1dSJustin T. Gibbs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
208b8a9b1dSJustin T. Gibbs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
218b8a9b1dSJustin T. Gibbs * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
228b8a9b1dSJustin T. Gibbs * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
238b8a9b1dSJustin T. Gibbs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
248b8a9b1dSJustin T. Gibbs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
258b8a9b1dSJustin T. Gibbs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
268b8a9b1dSJustin T. Gibbs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
278b8a9b1dSJustin T. Gibbs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
288b8a9b1dSJustin T. Gibbs * SUCH DAMAGE.
298b8a9b1dSJustin T. Gibbs */
308b8a9b1dSJustin T. Gibbs
318b8a9b1dSJustin T. Gibbs #ifndef _CAM_CAM_SIM_H
328b8a9b1dSJustin T. Gibbs #define _CAM_CAM_SIM_H 1
338b8a9b1dSJustin T. Gibbs
34c4473420SPeter Wemm #ifdef _KERNEL
358b8a9b1dSJustin T. Gibbs
368b8a9b1dSJustin T. Gibbs /*
378b8a9b1dSJustin T. Gibbs * The sim driver creates a sim for each controller. The sim device
388b8a9b1dSJustin T. Gibbs * queue is separately created in order to allow resource sharing between
398b8a9b1dSJustin T. Gibbs * sims. For instance, a driver may create one sim for each channel of
408b8a9b1dSJustin T. Gibbs * a multi-channel controller and use the same queue for each channel.
418b8a9b1dSJustin T. Gibbs * In this way, the queue resources are shared across all the channels
428b8a9b1dSJustin T. Gibbs * of the multi-channel controller.
438b8a9b1dSJustin T. Gibbs */
448b8a9b1dSJustin T. Gibbs
458b8a9b1dSJustin T. Gibbs struct cam_sim;
468b8a9b1dSJustin T. Gibbs struct cam_devq;
478b8a9b1dSJustin T. Gibbs
488b8a9b1dSJustin T. Gibbs typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
498b8a9b1dSJustin T. Gibbs typedef void (*sim_poll_func)(struct cam_sim *sim);
508b8a9b1dSJustin T. Gibbs
51*7af2f2c8SWarner Losh struct cam_devq * cam_simq_alloc(uint32_t max_sim_transactions);
528b8a9b1dSJustin T. Gibbs void cam_simq_free(struct cam_devq *devq);
538b8a9b1dSJustin T. Gibbs
548b8a9b1dSJustin T. Gibbs struct cam_sim * cam_sim_alloc(sim_action_func sim_action,
558b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll,
56e2138feeSJohn Baldwin const char *sim_name,
578b8a9b1dSJustin T. Gibbs void *softc,
58*7af2f2c8SWarner Losh uint32_t unit,
592b83592fSScott Long struct mtx *mtx,
609deea857SKenneth D. Merry int max_dev_transactions,
619deea857SKenneth D. Merry int max_tagged_dev_transactions,
628b8a9b1dSJustin T. Gibbs struct cam_devq *queue);
638b8a9b1dSJustin T. Gibbs void cam_sim_free(struct cam_sim *sim, int free_devq);
64fa6099fdSEdward Tomasz Napierala void cam_sim_hold(struct cam_sim *sim);
65fa6099fdSEdward Tomasz Napierala void cam_sim_release(struct cam_sim *sim);
668b8a9b1dSJustin T. Gibbs
678b8a9b1dSJustin T. Gibbs /* Optional sim attributes may be set with these. */
68*7af2f2c8SWarner Losh void cam_sim_set_path(struct cam_sim *sim, uint32_t path_id);
698b8a9b1dSJustin T. Gibbs
708b8a9b1dSJustin T. Gibbs /* Generically useful offsets into the sim private area */
718b8a9b1dSJustin T. Gibbs #define spriv_ptr0 sim_priv.entries[0].ptr
728b8a9b1dSJustin T. Gibbs #define spriv_ptr1 sim_priv.entries[1].ptr
738b8a9b1dSJustin T. Gibbs #define spriv_field0 sim_priv.entries[0].field
748b8a9b1dSJustin T. Gibbs #define spriv_field1 sim_priv.entries[1].field
758b8a9b1dSJustin T. Gibbs
768b8a9b1dSJustin T. Gibbs /*
778b8a9b1dSJustin T. Gibbs * The sim driver should not access anything directly from this
788b8a9b1dSJustin T. Gibbs * structure.
798b8a9b1dSJustin T. Gibbs */
808b8a9b1dSJustin T. Gibbs struct cam_sim {
818b8a9b1dSJustin T. Gibbs sim_action_func sim_action;
828b8a9b1dSJustin T. Gibbs sim_poll_func sim_poll;
83e2138feeSJohn Baldwin const char *sim_name;
848b8a9b1dSJustin T. Gibbs void *softc;
852b83592fSScott Long struct mtx *mtx;
869758cc83SScott Long TAILQ_ENTRY(cam_sim) links;
87*7af2f2c8SWarner Losh uint32_t path_id;/* The Boot device may set this to 0? */
88*7af2f2c8SWarner Losh uint32_t unit_number;
89*7af2f2c8SWarner Losh uint32_t bus_id;
909deea857SKenneth D. Merry int max_tagged_dev_openings;
919deea857SKenneth D. Merry int max_dev_openings;
92*7af2f2c8SWarner Losh uint32_t flags;
938b8a9b1dSJustin T. Gibbs struct cam_devq *devq; /* Device Queue to use for this SIM */
94fa6099fdSEdward Tomasz Napierala int refcount; /* References to the SIM. */
958b8a9b1dSJustin T. Gibbs };
968b8a9b1dSJustin T. Gibbs
97*7af2f2c8SWarner Losh static __inline uint32_t
cam_sim_path(const struct cam_sim * sim)980b4da9c8SWarner Losh cam_sim_path(const struct cam_sim *sim)
998b8a9b1dSJustin T. Gibbs {
1008b8a9b1dSJustin T. Gibbs return (sim->path_id);
1018b8a9b1dSJustin T. Gibbs }
1028b8a9b1dSJustin T. Gibbs
103e2138feeSJohn Baldwin static __inline const char *
cam_sim_name(const struct cam_sim * sim)1040b4da9c8SWarner Losh cam_sim_name(const struct cam_sim *sim)
1058b8a9b1dSJustin T. Gibbs {
1068b8a9b1dSJustin T. Gibbs return (sim->sim_name);
1078b8a9b1dSJustin T. Gibbs }
1088b8a9b1dSJustin T. Gibbs
1098b8a9b1dSJustin T. Gibbs static __inline void *
cam_sim_softc(const struct cam_sim * sim)1100b4da9c8SWarner Losh cam_sim_softc(const struct cam_sim *sim)
1118b8a9b1dSJustin T. Gibbs {
1128b8a9b1dSJustin T. Gibbs return (sim->softc);
1138b8a9b1dSJustin T. Gibbs }
1148b8a9b1dSJustin T. Gibbs
115*7af2f2c8SWarner Losh static __inline uint32_t
cam_sim_unit(const struct cam_sim * sim)1160b4da9c8SWarner Losh cam_sim_unit(const struct cam_sim *sim)
1178b8a9b1dSJustin T. Gibbs {
1188b8a9b1dSJustin T. Gibbs return (sim->unit_number);
1198b8a9b1dSJustin T. Gibbs }
1208b8a9b1dSJustin T. Gibbs
121*7af2f2c8SWarner Losh static __inline uint32_t
cam_sim_bus(const struct cam_sim * sim)1220b4da9c8SWarner Losh cam_sim_bus(const struct cam_sim *sim)
1238b8a9b1dSJustin T. Gibbs {
1248b8a9b1dSJustin T. Gibbs return (sim->bus_id);
1258b8a9b1dSJustin T. Gibbs }
1268b8a9b1dSJustin T. Gibbs
127447b3557SJohn Baldwin static __inline bool
cam_sim_pollable(const struct cam_sim * sim)128447b3557SJohn Baldwin cam_sim_pollable(const struct cam_sim *sim)
129447b3557SJohn Baldwin {
130447b3557SJohn Baldwin return (sim->sim_poll != NULL);
131447b3557SJohn Baldwin }
132447b3557SJohn Baldwin
133c4473420SPeter Wemm #endif /* _KERNEL */
1348b8a9b1dSJustin T. Gibbs #endif /* _CAM_CAM_SIM_H */
135