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