xref: /freebsd/sys/cam/cam_compat.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
125a2902cSScott Long /*-
225a2902cSScott Long  * CAM ioctl compatibility shims
325a2902cSScott Long  *
44d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
5bec9534dSPedro F. Giffuni  *
625a2902cSScott Long  * Copyright (c) 2013 Scott Long
725a2902cSScott Long  * All rights reserved.
825a2902cSScott Long  *
925a2902cSScott Long  * Redistribution and use in source and binary forms, with or without
1025a2902cSScott Long  * modification, are permitted provided that the following conditions
1125a2902cSScott Long  * are met:
1225a2902cSScott Long  * 1. Redistributions of source code must retain the above copyright
1325a2902cSScott Long  *    notice, this list of conditions, and the following disclaimer,
1425a2902cSScott Long  *    without modification, immediately at the beginning of the file.
1525a2902cSScott Long  * 2. The name of the author may not be used to endorse or promote products
1625a2902cSScott Long  *    derived from this software without specific prior written permission.
1725a2902cSScott Long  *
1825a2902cSScott Long  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1925a2902cSScott Long  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2025a2902cSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2125a2902cSScott Long  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2225a2902cSScott Long  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2325a2902cSScott Long  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2425a2902cSScott Long  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2525a2902cSScott Long  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2625a2902cSScott Long  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2725a2902cSScott Long  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2825a2902cSScott Long  * SUCH DAMAGE.
2925a2902cSScott Long  */
3025a2902cSScott Long 
3125a2902cSScott Long #ifndef _CAM_CAM_COMPAT_H
3225a2902cSScott Long #define _CAM_CAM_COMPAT_H
3325a2902cSScott Long 
341d64db52SConrad Meyer /* No user-serviceable parts in here. */
35f564de00SScott Long #ifdef _KERNEL
36f564de00SScott Long 
37f564de00SScott Long int cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
38f564de00SScott Long     struct thread *td, int(*cbfnp)(struct cdev *, u_long, caddr_t, int,
39f564de00SScott Long     struct thread *));
40f564de00SScott Long 
4125a2902cSScott Long /* Version 0x16 compatibility */
4225a2902cSScott Long #define CAM_VERSION_0x16	0x16
4325a2902cSScott Long 
4425a2902cSScott Long /* The size of the union ccb didn't change when going to 0x17 */
45d3c5b1feSAlexander Motin #define	CAMIOCOMMAND_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 2, CAM_0X17_LEN)
46d3c5b1feSAlexander Motin #define	CAMGETPASSTHRU_0x16	_IOC(IOC_INOUT, CAM_VERSION_0x16, 3, CAM_0X17_LEN)
4725a2902cSScott Long 
48683f808eSScott Long #define CAM_SCATTER_VALID_0x16	0x00000010
49683f808eSScott Long #define CAM_SG_LIST_PHYS_0x16	0x00040000
50683f808eSScott Long #define CAM_DATA_PHYS_0x16	0x00200000
5125a2902cSScott Long 
52f564de00SScott Long /* Version 0x17 compatibility */
53f564de00SScott Long #define CAM_VERSION_0x17	0x17
5425a2902cSScott Long 
55f564de00SScott Long struct ccb_hdr_0x17 {
56f564de00SScott Long 	cam_pinfo	pinfo;		/* Info for priority scheduling */
57f564de00SScott Long 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
58f564de00SScott Long 	camq_entry	sim_links;	/* For chaining in the SIM layer */
59f564de00SScott Long 	camq_entry	periph_links;	/* For chaining in the type driver */
60*7af2f2c8SWarner Losh 	uint32_t	retry_count;
61f564de00SScott Long 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
62f564de00SScott Long 	xpt_opcode	func_code;	/* XPT function code */
63*7af2f2c8SWarner Losh 	uint32_t	status;		/* Status returned by CAM subsystem */
64f564de00SScott Long 	struct		cam_path *path;	/* Compiled path for this ccb */
65f564de00SScott Long 	path_id_t	path_id;	/* Path ID for the request */
66f564de00SScott Long 	target_id_t	target_id;	/* Target device ID */
6792be6c51SNathan Whitehorn 	u_int		target_lun;	/* Target LUN number */
68*7af2f2c8SWarner Losh 	uint32_t	flags;		/* ccb_flags */
69f564de00SScott Long 	ccb_ppriv_area	periph_priv;
70f564de00SScott Long 	ccb_spriv_area	sim_priv;
71*7af2f2c8SWarner Losh 	uint32_t	timeout;	/* Hard timeout value in seconds */
7213e3c791SGleb Smirnoff 	struct callout	*timeout_ch;
73f564de00SScott Long };
74f564de00SScott Long 
75f564de00SScott Long struct ccb_pathinq_0x17 {
76f564de00SScott Long 	struct ccb_hdr_0x17 ccb_h;
77*7af2f2c8SWarner Losh 	uint8_t    version_num;	/* Version number for the SIM/HBA */
78*7af2f2c8SWarner Losh 	uint8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
79*7af2f2c8SWarner Losh 	uint8_t    target_sprt;	/* Flags for target mode support */
80*7af2f2c8SWarner Losh 	uint8_t    hba_misc;		/* Misc HBA features */
81*7af2f2c8SWarner Losh 	uint16_t   hba_eng_cnt;	/* HBA engine count */
82f564de00SScott Long 					/* Vendor Unique capabilities */
83*7af2f2c8SWarner Losh 	uint8_t    vuhba_flags[VUHBALEN];
84*7af2f2c8SWarner Losh 	uint32_t   max_target;		/* Maximum supported Target */
85*7af2f2c8SWarner Losh 	uint32_t   max_lun;		/* Maximum supported Lun */
86*7af2f2c8SWarner Losh 	uint32_t   async_flags;	/* Installed Async handlers */
87f564de00SScott Long 	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
88f564de00SScott Long 	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
89f564de00SScott Long 	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
90f564de00SScott Long 	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
91f564de00SScott Long 	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
92*7af2f2c8SWarner Losh 	uint32_t   unit_number;	/* Unit number for SIM */
93*7af2f2c8SWarner Losh 	uint32_t   bus_id;		/* Bus ID for SIM */
94*7af2f2c8SWarner Losh 	uint32_t   base_transfer_speed;/* Base bus speed in KB/sec */
95f564de00SScott Long 	cam_proto   protocol;
96f564de00SScott Long 	u_int	    protocol_version;
97f564de00SScott Long 	cam_xport   transport;
98f564de00SScott Long 	u_int	    transport_version;
99f564de00SScott Long 	union {
100f564de00SScott Long 		struct ccb_pathinq_settings_spi spi;
101f564de00SScott Long 		struct ccb_pathinq_settings_fc fc;
102f564de00SScott Long 		struct ccb_pathinq_settings_sas sas;
103f564de00SScott Long 		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
104f564de00SScott Long 	} xport_specific;
105f564de00SScott Long 	u_int		maxio;		/* Max supported I/O size, in bytes. */
106*7af2f2c8SWarner Losh 	uint16_t	hba_vendor;	/* HBA vendor ID */
107*7af2f2c8SWarner Losh 	uint16_t	hba_device;	/* HBA device ID */
108*7af2f2c8SWarner Losh 	uint16_t	hba_subvendor;	/* HBA subvendor ID */
109*7af2f2c8SWarner Losh 	uint16_t	hba_subdevice;	/* HBA subdevice ID */
110f564de00SScott Long };
111f564de00SScott Long 
112d3c5b1feSAlexander Motin struct ccb_trans_settings_0x17 {
113d3c5b1feSAlexander Motin 	struct	  ccb_hdr_0x17 ccb_h;
114d3c5b1feSAlexander Motin 	cts_type  type;		/* Current or User settings */
115d3c5b1feSAlexander Motin 	cam_proto protocol;
116d3c5b1feSAlexander Motin 	u_int	  protocol_version;
117d3c5b1feSAlexander Motin 	cam_xport transport;
118d3c5b1feSAlexander Motin 	u_int	  transport_version;
119d3c5b1feSAlexander Motin 	union {
120d3c5b1feSAlexander Motin 		u_int  valid;	/* Which fields to honor */
121d3c5b1feSAlexander Motin 		struct ccb_trans_settings_ata ata;
122d3c5b1feSAlexander Motin 		struct ccb_trans_settings_scsi scsi;
123d3c5b1feSAlexander Motin 	} proto_specific;
124d3c5b1feSAlexander Motin 	union {
125d3c5b1feSAlexander Motin 		u_int  valid;	/* Which fields to honor */
126d3c5b1feSAlexander Motin 		struct ccb_trans_settings_spi spi;
127d3c5b1feSAlexander Motin 		struct ccb_trans_settings_fc fc;
128d3c5b1feSAlexander Motin 		struct ccb_trans_settings_sas sas;
129d3c5b1feSAlexander Motin 		struct ccb_trans_settings_pata ata;
130d3c5b1feSAlexander Motin 		struct ccb_trans_settings_sata sata;
131d3c5b1feSAlexander Motin 	} xport_specific;
132d3c5b1feSAlexander Motin };
133d3c5b1feSAlexander Motin 
134d3c5b1feSAlexander Motin #define CAM_0X17_DATA_LEN	CAM_0X18_DATA_LEN
135d3c5b1feSAlexander Motin #define CAM_0X17_LEN		(sizeof(struct ccb_hdr_0x17) + CAM_0X17_DATA_LEN)
136f564de00SScott Long 
137f564de00SScott Long #define	CAMIOCOMMAND_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 2, CAM_0X17_LEN)
138f564de00SScott Long #define CAMGETPASSTHRU_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 3, CAM_0X17_LEN)
139f564de00SScott Long 
14092be6c51SNathan Whitehorn /* Version 0x18 compatibility */
14192be6c51SNathan Whitehorn #define CAM_VERSION_0x18	0x18
14292be6c51SNathan Whitehorn 
14392be6c51SNathan Whitehorn struct ccb_hdr_0x18 {
14492be6c51SNathan Whitehorn 	cam_pinfo	pinfo;		/* Info for priority scheduling */
14592be6c51SNathan Whitehorn 	camq_entry	xpt_links;	/* For chaining in the XPT layer */
14692be6c51SNathan Whitehorn 	camq_entry	sim_links;	/* For chaining in the SIM layer */
14792be6c51SNathan Whitehorn 	camq_entry	periph_links;	/* For chaining in the type driver */
148*7af2f2c8SWarner Losh 	uint32_t	retry_count;
14992be6c51SNathan Whitehorn 	void		(*cbfcnp)(struct cam_periph *, union ccb *);
15092be6c51SNathan Whitehorn 	xpt_opcode	func_code;	/* XPT function code */
151*7af2f2c8SWarner Losh 	uint32_t	status;		/* Status returned by CAM subsystem */
15292be6c51SNathan Whitehorn 	struct		cam_path *path;	/* Compiled path for this ccb */
15392be6c51SNathan Whitehorn 	path_id_t	path_id;	/* Path ID for the request */
15492be6c51SNathan Whitehorn 	target_id_t	target_id;	/* Target device ID */
15592be6c51SNathan Whitehorn 	u_int		target_lun;	/* Target LUN number */
156*7af2f2c8SWarner Losh 	uint64_t	ext_lun;	/* 64-bit LUN, more or less */
157*7af2f2c8SWarner Losh 	uint32_t	flags;		/* ccb_flags */
158*7af2f2c8SWarner Losh 	uint32_t	xflags;		/* extended ccb_flags */
15992be6c51SNathan Whitehorn 	ccb_ppriv_area	periph_priv;
16092be6c51SNathan Whitehorn 	ccb_spriv_area	sim_priv;
16192be6c51SNathan Whitehorn 	ccb_qos_area	qos;
162*7af2f2c8SWarner Losh 	uint32_t	timeout;	/* Hard timeout value in seconds */
16392be6c51SNathan Whitehorn 	struct timeval	softtimeout;	/* Soft timeout value in sec + usec */
16492be6c51SNathan Whitehorn };
16592be6c51SNathan Whitehorn 
16692be6c51SNathan Whitehorn typedef enum {
16792be6c51SNathan Whitehorn 	CAM_EXTLUN_VALID_0x18	= 0x00000001,/* 64bit lun field is valid      */
16892be6c51SNathan Whitehorn } ccb_xflags_0x18;
16992be6c51SNathan Whitehorn 
170d3c5b1feSAlexander Motin struct ccb_trans_settings_0x18 {
171d3c5b1feSAlexander Motin 	struct	  ccb_hdr_0x18 ccb_h;
172d3c5b1feSAlexander Motin 	cts_type  type;		/* Current or User settings */
173d3c5b1feSAlexander Motin 	cam_proto protocol;
174d3c5b1feSAlexander Motin 	u_int	  protocol_version;
175d3c5b1feSAlexander Motin 	cam_xport transport;
176d3c5b1feSAlexander Motin 	u_int	  transport_version;
177d3c5b1feSAlexander Motin 	union {
178d3c5b1feSAlexander Motin 		u_int  valid;	/* Which fields to honor */
179d3c5b1feSAlexander Motin 		struct ccb_trans_settings_ata ata;
180d3c5b1feSAlexander Motin 		struct ccb_trans_settings_scsi scsi;
181d3c5b1feSAlexander Motin 	} proto_specific;
182d3c5b1feSAlexander Motin 	union {
183d3c5b1feSAlexander Motin 		u_int  valid;	/* Which fields to honor */
184d3c5b1feSAlexander Motin 		struct ccb_trans_settings_spi spi;
185d3c5b1feSAlexander Motin 		struct ccb_trans_settings_fc fc;
186d3c5b1feSAlexander Motin 		struct ccb_trans_settings_sas sas;
187d3c5b1feSAlexander Motin 		struct ccb_trans_settings_pata ata;
188d3c5b1feSAlexander Motin 		struct ccb_trans_settings_sata sata;
189d3c5b1feSAlexander Motin 	} xport_specific;
190d3c5b1feSAlexander Motin };
191d3c5b1feSAlexander Motin 
19292be6c51SNathan Whitehorn struct dev_match_result_0x18 {
19392be6c51SNathan Whitehorn         dev_match_type          type;
19492be6c51SNathan Whitehorn         union {
19592be6c51SNathan Whitehorn 		struct {
19692be6c51SNathan Whitehorn 			char periph_name[DEV_IDLEN];
197*7af2f2c8SWarner Losh 			uint32_t unit_number;
19892be6c51SNathan Whitehorn 			path_id_t path_id;
19992be6c51SNathan Whitehorn 			target_id_t target_id;
20092be6c51SNathan Whitehorn 			u_int target_lun;
20192be6c51SNathan Whitehorn 		} periph_result;
20292be6c51SNathan Whitehorn 		struct {
20392be6c51SNathan Whitehorn 			path_id_t	path_id;
20492be6c51SNathan Whitehorn 			target_id_t	target_id;
20592be6c51SNathan Whitehorn 			u_int		target_lun;
20692be6c51SNathan Whitehorn 			cam_proto	protocol;
20792be6c51SNathan Whitehorn 			struct scsi_inquiry_data inq_data;
20892be6c51SNathan Whitehorn 			struct ata_params ident_data;
20992be6c51SNathan Whitehorn 			dev_result_flags flags;
21092be6c51SNathan Whitehorn 		} device_result;
21192be6c51SNathan Whitehorn 		struct bus_match_result	bus_result;
21292be6c51SNathan Whitehorn 	} result;
21392be6c51SNathan Whitehorn };
21492be6c51SNathan Whitehorn 
215d3c5b1feSAlexander Motin #define CAM_0X18_DATA_LEN	(sizeof(union ccb) - 2*sizeof(void *) - sizeof(struct ccb_hdr))
216d3c5b1feSAlexander Motin #define CAM_0X18_LEN		(sizeof(struct ccb_hdr_0x18) + CAM_0X18_DATA_LEN)
21792be6c51SNathan Whitehorn 
21892be6c51SNathan Whitehorn #define	CAMIOCOMMAND_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 2, CAM_0X18_LEN)
21992be6c51SNathan Whitehorn #define CAMGETPASSTHRU_0x18	_IOC(IOC_INOUT, CAM_VERSION_0x18, 3, CAM_0X18_LEN)
22092be6c51SNathan Whitehorn 
2218f9be1eeSAlexander Motin /* Version 0x19 compatibility */
2228f9be1eeSAlexander Motin #define CAM_VERSION_0x19	0x19
2238f9be1eeSAlexander Motin #define CAMIOCOMMAND_0x19	_IOWR(CAM_VERSION_0x19, 2, union ccb)
2248f9be1eeSAlexander Motin #define CAMGETPASSTHRU_0x19	_IOWR(CAM_VERSION_0x19, 3, union ccb)
2258f9be1eeSAlexander Motin #define CAMIOQUEUE_0x19		_IO(CAM_VERSION_0x19, 4)
2268f9be1eeSAlexander Motin #define CAMIOGET_0x19		_IO(CAM_VERSION_0x19, 5)
2278f9be1eeSAlexander Motin 
228f564de00SScott Long #endif
229f564de00SScott Long #endif
230