xref: /freebsd/sys/cam/cam_compat.h (revision 38f0b757fd84d17d0fc24739a7cda160c4516d81)
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	_IOWR(CAM_VERSION_0x16, 2, union ccb)
47 #define CAMGETPASSTHRU_0x16	_IOWR(CAM_VERSION_0x16, 3, union ccb)
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 #define CAM_0X17_LEN	(sizeof(union ccb) - sizeof(struct ccb_hdr) + sizeof(struct ccb_hdr_0x17))
114 #define CAM_0X17_DATA_LEN (sizeof(union ccb) - sizeof(struct ccb_hdr_0x17))
115 
116 #define	CAMIOCOMMAND_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 2, CAM_0X17_LEN)
117 #define CAMGETPASSTHRU_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 3, CAM_0X17_LEN)
118 
119 /* Version 0x18 compatibility */
120 #define CAM_VERSION_0x18	0x18
121 
122 struct ccb_hdr_0x18 {
123 	cam_pinfo	pinfo;		/* Info for priority scheduling */
124 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
125 	camq_entry	sim_links;	/* For chaining in the SIM layer */
126 	camq_entry	periph_links;	/* For chaining in the type driver */
127 	u_int32_t	retry_count;
128 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
129 	xpt_opcode	func_code;	/* XPT function code */
130 	u_int32_t	status;		/* Status returned by CAM subsystem */
131 	struct		cam_path *path;	/* Compiled path for this ccb */
132 	path_id_t	path_id;	/* Path ID for the request */
133 	target_id_t	target_id;	/* Target device ID */
134 	u_int		target_lun;	/* Target LUN number */
135 	u_int64_t	ext_lun;	/* 64-bit LUN, more or less */
136 	u_int32_t	flags;		/* ccb_flags */
137 	u_int32_t	xflags;		/* extended ccb_flags */
138 	ccb_ppriv_area	periph_priv;
139 	ccb_spriv_area	sim_priv;
140 	ccb_qos_area	qos;
141 	u_int32_t	timeout;	/* Hard timeout value in seconds */
142 	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
143 };
144 
145 typedef enum {
146 	CAM_EXTLUN_VALID_0x18	= 0x00000001,/* 64bit lun field is valid      */
147 } ccb_xflags_0x18;
148 
149 struct dev_match_result_0x18 {
150         dev_match_type          type;
151         union {
152 		struct {
153 			char periph_name[DEV_IDLEN];
154 			u_int32_t unit_number;
155 			path_id_t path_id;
156 			target_id_t target_id;
157 			u_int target_lun;
158 		} periph_result;
159 		struct {
160 			path_id_t	path_id;
161 			target_id_t	target_id;
162 			u_int		target_lun;
163 			cam_proto	protocol;
164 			struct scsi_inquiry_data inq_data;
165 			struct ata_params ident_data;
166 			dev_result_flags flags;
167 		} device_result;
168 		struct bus_match_result	bus_result;
169 	} result;
170 };
171 
172 #define CAM_0X18_LEN	(sizeof(union ccb) - sizeof(struct ccb_hdr) + sizeof(struct ccb_hdr_0x18))
173 #define CAM_0X18_DATA_LEN (sizeof(union ccb) - sizeof(struct ccb_hdr_0x18))
174 
175 #define	CAMIOCOMMAND_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 2, CAM_0X18_LEN)
176 #define CAMGETPASSTHRU_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 3, CAM_0X18_LEN)
177 
178 #endif
179 #endif
180