2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 * Copyright (c) 2002 Nate Lawson.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification, immediately at the beginning of the file.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #ifndef _SCSI_TARGET_H
34 #define _SCSI_TARGET_H
37 * Maximum number of parallel commands to accept,
38 * 1024 for Fibre Channel (SPI is 16).
40 #define MAX_INITIATORS 8
41 #define SECTOR_SIZE 512
42 #define MAX_EVENTS (MAX_INITIATORS + 5)
43 /* kqueue for AIO, signals */
45 /* Additional SCSI 3 defines for inquiry response */
46 #define SID_Addr16 0x0100
48 TAILQ_HEAD(io_queue, ccb_hdr);
50 /* Offset into the private CCB area for storing our descriptor */
51 #define targ_descr periph_priv.entries[1].ptr
53 /* Descriptor attached to each ATIO */
55 off_t base_off; /* Base offset for ATIO */
56 uint total_len; /* Total xfer len for this ATIO */
57 uint init_req; /* Transfer count requested to/from init */
58 uint init_ack; /* Data transferred ok to/from init */
59 uint targ_req; /* Transfer count requested to/from target */
60 uint targ_ack; /* Data transferred ok to/from target */
61 int flags; /* Flags for CTIOs */
62 u_int8_t *cdb; /* Pointer to received CDB */
63 /* List of completed AIO/CTIOs */
64 struct io_queue cmplt_io;
73 /* Descriptor attached to each CTIO */
75 void *buf; /* Backing store */
76 off_t offset; /* Position in transfer (for file, */
77 /* doesn't start at 0) */
78 struct aiocb aiocb; /* AIO descriptor for this CTIO */
79 struct ccb_accept_tio *atio;
80 /* ATIO we are satisfying */
81 io_ops event; /* Event that queued this CTIO */
97 struct initiator_state {
102 struct scsi_sense_data sense_data;
105 /* Global functions */
106 extern cam_status tcmd_init(u_int16_t req_inq_flags,
107 u_int16_t sim_inq_flags);
108 extern int tcmd_handle(struct ccb_accept_tio *atio,
109 struct ccb_scsiio *ctio, io_ops event);
110 extern void tcmd_sense(u_int init_id, struct ccb_scsiio *ctio,
112 u_int8_t asc, u_int8_t ascq);
113 extern void tcmd_ua(u_int init_id, ua_types new_ua);
114 extern int work_atio(struct ccb_accept_tio *atio);
115 extern void send_ccb(union ccb *ccb, int priority);
116 extern void free_ccb(union ccb *ccb);
117 static __inline u_int min(u_int a, u_int b) { return (a < b ? a : b); }
125 #if __FreeBSD_version >= 500000
126 #define OFF_FMT "%ju"
128 #define OFF_FMT "%llu"
131 #endif /* _SCSI_TARGET_H */