xref: /freebsd/sys/cam/cam_compat.h (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
1 /*-
2  * CAM ioctl compatibility shims
3  *
4  * Copyright (c) 2013 Scott Long
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification, immediately at the beginning of the file.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _CAM_CAM_COMPAT_H
32 #define _CAM_CAM_COMPAT_H
33 
34 /* No user-servicable parts in here. */
35 #ifdef _KERNEL
36 
37 int cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
38     struct thread *td, int(*cbfnp)(struct cdev *, u_long, caddr_t, int,
39     struct thread *));
40 
41 
42 /* Version 0x16 compatibility */
43 #define CAM_VERSION_0x16	0x16
44 
45 /* The size of the union ccb didn't change when going to 0x17 */
46 #define	CAMIOCOMMAND_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 2, CAM_0X17_LEN)
47 #define	CAMGETPASSTHRU_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 3, CAM_0X17_LEN)
48 
49 #define CAM_SCATTER_VALID_0x16	0x00000010
50 #define CAM_SG_LIST_PHYS_0x16	0x00040000
51 #define CAM_DATA_PHYS_0x16	0x00200000
52 
53 /* Version 0x17 compatibility */
54 #define CAM_VERSION_0x17	0x17
55 
56 struct ccb_hdr_0x17 {
57 	cam_pinfo	pinfo;		/* Info for priority scheduling */
58 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
59 	camq_entry	sim_links;	/* For chaining in the SIM layer */
60 	camq_entry	periph_links;	/* For chaining in the type driver */
61 	u_int32_t	retry_count;
62 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
63 	xpt_opcode	func_code;	/* XPT function code */
64 	u_int32_t	status;		/* Status returned by CAM subsystem */
65 	struct		cam_path *path;	/* Compiled path for this ccb */
66 	path_id_t	path_id;	/* Path ID for the request */
67 	target_id_t	target_id;	/* Target device ID */
68 	u_int		target_lun;	/* Target LUN number */
69 	u_int32_t	flags;		/* ccb_flags */
70 	ccb_ppriv_area	periph_priv;
71 	ccb_spriv_area	sim_priv;
72 	u_int32_t	timeout;	/* Hard timeout value in seconds */
73 	struct callout_handle timeout_ch;
74 };
75 
76 struct ccb_pathinq_0x17 {
77 	struct ccb_hdr_0x17 ccb_h;
78 	u_int8_t    version_num;	/* Version number for the SIM/HBA */
79 	u_int8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
80 	u_int8_t    target_sprt;	/* Flags for target mode support */
81 	u_int8_t    hba_misc;		/* Misc HBA features */
82 	u_int16_t   hba_eng_cnt;	/* HBA engine count */
83 					/* Vendor Unique capabilities */
84 	u_int8_t    vuhba_flags[VUHBALEN];
85 	u_int32_t   max_target;		/* Maximum supported Target */
86 	u_int32_t   max_lun;		/* Maximum supported Lun */
87 	u_int32_t   async_flags;	/* Installed Async handlers */
88 	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
89 	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
90 	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
91 	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
92 	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
93 	u_int32_t   unit_number;	/* Unit number for SIM */
94 	u_int32_t   bus_id;		/* Bus ID for SIM */
95 	u_int32_t   base_transfer_speed;/* Base bus speed in KB/sec */
96 	cam_proto   protocol;
97 	u_int	    protocol_version;
98 	cam_xport   transport;
99 	u_int	    transport_version;
100 	union {
101 		struct ccb_pathinq_settings_spi spi;
102 		struct ccb_pathinq_settings_fc fc;
103 		struct ccb_pathinq_settings_sas sas;
104 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
105 	} xport_specific;
106 	u_int		maxio;		/* Max supported I/O size, in bytes. */
107 	u_int16_t	hba_vendor;	/* HBA vendor ID */
108 	u_int16_t	hba_device;	/* HBA device ID */
109 	u_int16_t	hba_subvendor;	/* HBA subvendor ID */
110 	u_int16_t	hba_subdevice;	/* HBA subdevice ID */
111 };
112 
113 struct ccb_trans_settings_0x17 {
114 	struct	  ccb_hdr_0x17 ccb_h;
115 	cts_type  type;		/* Current or User settings */
116 	cam_proto protocol;
117 	u_int	  protocol_version;
118 	cam_xport transport;
119 	u_int	  transport_version;
120 	union {
121 		u_int  valid;	/* Which fields to honor */
122 		struct ccb_trans_settings_ata ata;
123 		struct ccb_trans_settings_scsi scsi;
124 	} proto_specific;
125 	union {
126 		u_int  valid;	/* Which fields to honor */
127 		struct ccb_trans_settings_spi spi;
128 		struct ccb_trans_settings_fc fc;
129 		struct ccb_trans_settings_sas sas;
130 		struct ccb_trans_settings_pata ata;
131 		struct ccb_trans_settings_sata sata;
132 	} xport_specific;
133 };
134 
135 #define CAM_0X17_DATA_LEN	CAM_0X18_DATA_LEN
136 #define CAM_0X17_LEN		(sizeof(struct ccb_hdr_0x17) + CAM_0X17_DATA_LEN)
137 
138 #define	CAMIOCOMMAND_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 2, CAM_0X17_LEN)
139 #define CAMGETPASSTHRU_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 3, CAM_0X17_LEN)
140 
141 /* Version 0x18 compatibility */
142 #define CAM_VERSION_0x18	0x18
143 
144 struct ccb_hdr_0x18 {
145 	cam_pinfo	pinfo;		/* Info for priority scheduling */
146 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
147 	camq_entry	sim_links;	/* For chaining in the SIM layer */
148 	camq_entry	periph_links;	/* For chaining in the type driver */
149 	u_int32_t	retry_count;
150 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
151 	xpt_opcode	func_code;	/* XPT function code */
152 	u_int32_t	status;		/* Status returned by CAM subsystem */
153 	struct		cam_path *path;	/* Compiled path for this ccb */
154 	path_id_t	path_id;	/* Path ID for the request */
155 	target_id_t	target_id;	/* Target device ID */
156 	u_int		target_lun;	/* Target LUN number */
157 	u_int64_t	ext_lun;	/* 64-bit LUN, more or less */
158 	u_int32_t	flags;		/* ccb_flags */
159 	u_int32_t	xflags;		/* extended ccb_flags */
160 	ccb_ppriv_area	periph_priv;
161 	ccb_spriv_area	sim_priv;
162 	ccb_qos_area	qos;
163 	u_int32_t	timeout;	/* Hard timeout value in seconds */
164 	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
165 };
166 
167 typedef enum {
168 	CAM_EXTLUN_VALID_0x18	= 0x00000001,/* 64bit lun field is valid      */
169 } ccb_xflags_0x18;
170 
171 struct ccb_trans_settings_0x18 {
172 	struct	  ccb_hdr_0x18 ccb_h;
173 	cts_type  type;		/* Current or User settings */
174 	cam_proto protocol;
175 	u_int	  protocol_version;
176 	cam_xport transport;
177 	u_int	  transport_version;
178 	union {
179 		u_int  valid;	/* Which fields to honor */
180 		struct ccb_trans_settings_ata ata;
181 		struct ccb_trans_settings_scsi scsi;
182 	} proto_specific;
183 	union {
184 		u_int  valid;	/* Which fields to honor */
185 		struct ccb_trans_settings_spi spi;
186 		struct ccb_trans_settings_fc fc;
187 		struct ccb_trans_settings_sas sas;
188 		struct ccb_trans_settings_pata ata;
189 		struct ccb_trans_settings_sata sata;
190 	} xport_specific;
191 };
192 
193 struct dev_match_result_0x18 {
194         dev_match_type          type;
195         union {
196 		struct {
197 			char periph_name[DEV_IDLEN];
198 			u_int32_t unit_number;
199 			path_id_t path_id;
200 			target_id_t target_id;
201 			u_int target_lun;
202 		} periph_result;
203 		struct {
204 			path_id_t	path_id;
205 			target_id_t	target_id;
206 			u_int		target_lun;
207 			cam_proto	protocol;
208 			struct scsi_inquiry_data inq_data;
209 			struct ata_params ident_data;
210 			dev_result_flags flags;
211 		} device_result;
212 		struct bus_match_result	bus_result;
213 	} result;
214 };
215 
216 #define CAM_0X18_DATA_LEN	(sizeof(union ccb) - 2*sizeof(void *) - sizeof(struct ccb_hdr))
217 #define CAM_0X18_LEN		(sizeof(struct ccb_hdr_0x18) + CAM_0X18_DATA_LEN)
218 
219 #define	CAMIOCOMMAND_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 2, CAM_0X18_LEN)
220 #define CAMGETPASSTHRU_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 3, CAM_0X18_LEN)
221 
222 #endif
223 #endif
224