xref: /freebsd/sys/cam/cam_compat.h (revision 7259ca31048e5ced8e7f90657a3d7084aeafdf51)
1 /*-
2  * CAM ioctl compatibility shims
3  *
4  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5  *
6  * Copyright (c) 2013 Scott Long
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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.
17  *
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
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef _CAM_CAM_COMPAT_H
34 #define _CAM_CAM_COMPAT_H
35 
36 /* No user-serviceable parts in here. */
37 #ifdef _KERNEL
38 
39 int cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
40     struct thread *td, int(*cbfnp)(struct cdev *, u_long, caddr_t, int,
41     struct thread *));
42 
43 /* Version 0x16 compatibility */
44 #define CAM_VERSION_0x16	0x16
45 
46 /* The size of the union ccb didn't change when going to 0x17 */
47 #define	CAMIOCOMMAND_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 2, CAM_0X17_LEN)
48 #define	CAMGETPASSTHRU_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 3, CAM_0X17_LEN)
49 
50 #define CAM_SCATTER_VALID_0x16	0x00000010
51 #define CAM_SG_LIST_PHYS_0x16	0x00040000
52 #define CAM_DATA_PHYS_0x16	0x00200000
53 
54 /* Version 0x17 compatibility */
55 #define CAM_VERSION_0x17	0x17
56 
57 struct ccb_hdr_0x17 {
58 	cam_pinfo	pinfo;		/* Info for priority scheduling */
59 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
60 	camq_entry	sim_links;	/* For chaining in the SIM layer */
61 	camq_entry	periph_links;	/* For chaining in the type driver */
62 	u_int32_t	retry_count;
63 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
64 	xpt_opcode	func_code;	/* XPT function code */
65 	u_int32_t	status;		/* Status returned by CAM subsystem */
66 	struct		cam_path *path;	/* Compiled path for this ccb */
67 	path_id_t	path_id;	/* Path ID for the request */
68 	target_id_t	target_id;	/* Target device ID */
69 	u_int		target_lun;	/* Target LUN number */
70 	u_int32_t	flags;		/* ccb_flags */
71 	ccb_ppriv_area	periph_priv;
72 	ccb_spriv_area	sim_priv;
73 	u_int32_t	timeout;	/* Hard timeout value in seconds */
74 	struct callout	*timeout_ch;
75 };
76 
77 struct ccb_pathinq_0x17 {
78 	struct ccb_hdr_0x17 ccb_h;
79 	u_int8_t    version_num;	/* Version number for the SIM/HBA */
80 	u_int8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
81 	u_int8_t    target_sprt;	/* Flags for target mode support */
82 	u_int8_t    hba_misc;		/* Misc HBA features */
83 	u_int16_t   hba_eng_cnt;	/* HBA engine count */
84 					/* Vendor Unique capabilities */
85 	u_int8_t    vuhba_flags[VUHBALEN];
86 	u_int32_t   max_target;		/* Maximum supported Target */
87 	u_int32_t   max_lun;		/* Maximum supported Lun */
88 	u_int32_t   async_flags;	/* Installed Async handlers */
89 	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
90 	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
91 	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
92 	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
93 	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
94 	u_int32_t   unit_number;	/* Unit number for SIM */
95 	u_int32_t   bus_id;		/* Bus ID for SIM */
96 	u_int32_t   base_transfer_speed;/* Base bus speed in KB/sec */
97 	cam_proto   protocol;
98 	u_int	    protocol_version;
99 	cam_xport   transport;
100 	u_int	    transport_version;
101 	union {
102 		struct ccb_pathinq_settings_spi spi;
103 		struct ccb_pathinq_settings_fc fc;
104 		struct ccb_pathinq_settings_sas sas;
105 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
106 	} xport_specific;
107 	u_int		maxio;		/* Max supported I/O size, in bytes. */
108 	u_int16_t	hba_vendor;	/* HBA vendor ID */
109 	u_int16_t	hba_device;	/* HBA device ID */
110 	u_int16_t	hba_subvendor;	/* HBA subvendor ID */
111 	u_int16_t	hba_subdevice;	/* HBA subdevice ID */
112 };
113 
114 struct ccb_trans_settings_0x17 {
115 	struct	  ccb_hdr_0x17 ccb_h;
116 	cts_type  type;		/* Current or User settings */
117 	cam_proto protocol;
118 	u_int	  protocol_version;
119 	cam_xport transport;
120 	u_int	  transport_version;
121 	union {
122 		u_int  valid;	/* Which fields to honor */
123 		struct ccb_trans_settings_ata ata;
124 		struct ccb_trans_settings_scsi scsi;
125 	} proto_specific;
126 	union {
127 		u_int  valid;	/* Which fields to honor */
128 		struct ccb_trans_settings_spi spi;
129 		struct ccb_trans_settings_fc fc;
130 		struct ccb_trans_settings_sas sas;
131 		struct ccb_trans_settings_pata ata;
132 		struct ccb_trans_settings_sata sata;
133 	} xport_specific;
134 };
135 
136 #define CAM_0X17_DATA_LEN	CAM_0X18_DATA_LEN
137 #define CAM_0X17_LEN		(sizeof(struct ccb_hdr_0x17) + CAM_0X17_DATA_LEN)
138 
139 #define	CAMIOCOMMAND_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 2, CAM_0X17_LEN)
140 #define CAMGETPASSTHRU_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 3, CAM_0X17_LEN)
141 
142 /* Version 0x18 compatibility */
143 #define CAM_VERSION_0x18	0x18
144 
145 struct ccb_hdr_0x18 {
146 	cam_pinfo	pinfo;		/* Info for priority scheduling */
147 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
148 	camq_entry	sim_links;	/* For chaining in the SIM layer */
149 	camq_entry	periph_links;	/* For chaining in the type driver */
150 	u_int32_t	retry_count;
151 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
152 	xpt_opcode	func_code;	/* XPT function code */
153 	u_int32_t	status;		/* Status returned by CAM subsystem */
154 	struct		cam_path *path;	/* Compiled path for this ccb */
155 	path_id_t	path_id;	/* Path ID for the request */
156 	target_id_t	target_id;	/* Target device ID */
157 	u_int		target_lun;	/* Target LUN number */
158 	u_int64_t	ext_lun;	/* 64-bit LUN, more or less */
159 	u_int32_t	flags;		/* ccb_flags */
160 	u_int32_t	xflags;		/* extended ccb_flags */
161 	ccb_ppriv_area	periph_priv;
162 	ccb_spriv_area	sim_priv;
163 	ccb_qos_area	qos;
164 	u_int32_t	timeout;	/* Hard timeout value in seconds */
165 	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
166 };
167 
168 typedef enum {
169 	CAM_EXTLUN_VALID_0x18	= 0x00000001,/* 64bit lun field is valid      */
170 } ccb_xflags_0x18;
171 
172 struct ccb_trans_settings_0x18 {
173 	struct	  ccb_hdr_0x18 ccb_h;
174 	cts_type  type;		/* Current or User settings */
175 	cam_proto protocol;
176 	u_int	  protocol_version;
177 	cam_xport transport;
178 	u_int	  transport_version;
179 	union {
180 		u_int  valid;	/* Which fields to honor */
181 		struct ccb_trans_settings_ata ata;
182 		struct ccb_trans_settings_scsi scsi;
183 	} proto_specific;
184 	union {
185 		u_int  valid;	/* Which fields to honor */
186 		struct ccb_trans_settings_spi spi;
187 		struct ccb_trans_settings_fc fc;
188 		struct ccb_trans_settings_sas sas;
189 		struct ccb_trans_settings_pata ata;
190 		struct ccb_trans_settings_sata sata;
191 	} xport_specific;
192 };
193 
194 struct dev_match_result_0x18 {
195         dev_match_type          type;
196         union {
197 		struct {
198 			char periph_name[DEV_IDLEN];
199 			u_int32_t unit_number;
200 			path_id_t path_id;
201 			target_id_t target_id;
202 			u_int target_lun;
203 		} periph_result;
204 		struct {
205 			path_id_t	path_id;
206 			target_id_t	target_id;
207 			u_int		target_lun;
208 			cam_proto	protocol;
209 			struct scsi_inquiry_data inq_data;
210 			struct ata_params ident_data;
211 			dev_result_flags flags;
212 		} device_result;
213 		struct bus_match_result	bus_result;
214 	} result;
215 };
216 
217 #define CAM_0X18_DATA_LEN	(sizeof(union ccb) - 2*sizeof(void *) - sizeof(struct ccb_hdr))
218 #define CAM_0X18_LEN		(sizeof(struct ccb_hdr_0x18) + CAM_0X18_DATA_LEN)
219 
220 #define	CAMIOCOMMAND_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 2, CAM_0X18_LEN)
221 #define CAMGETPASSTHRU_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 3, CAM_0X18_LEN)
222 
223 /* Version 0x19 compatibility */
224 #define CAM_VERSION_0x19	0x19
225 #define CAMIOCOMMAND_0x19	_IOWR(CAM_VERSION_0x19, 2, union ccb)
226 #define CAMGETPASSTHRU_0x19	_IOWR(CAM_VERSION_0x19, 3, union ccb)
227 #define CAMIOQUEUE_0x19		_IO(CAM_VERSION_0x19, 4)
228 #define CAMIOGET_0x19		_IO(CAM_VERSION_0x19, 5)
229 
230 #endif
231 #endif
232