1251837Sscottl/*-
2251837Sscottl * CAM ioctl compatibility shims
3251837Sscottl *
4251837Sscottl * Copyright (c) 2013 Scott Long
5251837Sscottl * All rights reserved.
6251837Sscottl *
7251837Sscottl * Redistribution and use in source and binary forms, with or without
8251837Sscottl * modification, are permitted provided that the following conditions
9251837Sscottl * are met:
10251837Sscottl * 1. Redistributions of source code must retain the above copyright
11251837Sscottl *    notice, this list of conditions, and the following disclaimer,
12251837Sscottl *    without modification, immediately at the beginning of the file.
13251837Sscottl * 2. The name of the author may not be used to endorse or promote products
14251837Sscottl *    derived from this software without specific prior written permission.
15251837Sscottl *
16251837Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17251837Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18251837Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19251837Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20251837Sscottl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21251837Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22251837Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23251837Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24251837Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25251837Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26251837Sscottl * SUCH DAMAGE.
27251837Sscottl *
28251837Sscottl * $FreeBSD$
29251837Sscottl */
30251837Sscottl
31251837Sscottl#ifndef _CAM_CAM_COMPAT_H
32251837Sscottl#define _CAM_CAM_COMPAT_H
33251837Sscottl
34255870Sscottl/* No user-servicable parts in here. */
35255870Sscottl#ifdef _KERNEL
36251837Sscottl
37255870Sscottlint cam_compat_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag,
38255870Sscottl    struct thread *td, int(*cbfnp)(struct cdev *, u_long, caddr_t, int,
39255870Sscottl    struct thread *));
40255870Sscottl
41255870Sscottl
42251837Sscottl/* Version 0x16 compatibility */
43251837Sscottl#define CAM_VERSION_0x16	0x16
44251837Sscottl
45251837Sscottl/* The size of the union ccb didn't change when going to 0x17 */
46251837Sscottl#define CAMIOCOMMAND_0x16	_IOWR(CAM_VERSION_0x16, 2, union ccb)
47251837Sscottl#define CAMGETPASSTHRU_0x16	_IOWR(CAM_VERSION_0x16, 3, union ccb)
48251837Sscottl
49251989Sscottl#define CAM_SCATTER_VALID_0x16	0x00000010
50251989Sscottl#define CAM_SG_LIST_PHYS_0x16	0x00040000
51251989Sscottl#define CAM_DATA_PHYS_0x16	0x00200000
52251837Sscottl
53255870Sscottl/* Version 0x17 compatibility */
54255870Sscottl#define CAM_VERSION_0x17	0x17
55255870Sscottl
56255870Sscottlstruct ccb_hdr_0x17 {
57255870Sscottl	cam_pinfo	pinfo;		/* Info for priority scheduling */
58255870Sscottl	camq_entry	xpt_links;	/* For chaining in the XPT layer */
59255870Sscottl	camq_entry	sim_links;	/* For chaining in the SIM layer */
60255870Sscottl	camq_entry	periph_links;	/* For chaining in the type driver */
61255870Sscottl	u_int32_t	retry_count;
62255870Sscottl	void		(*cbfcnp)(struct cam_periph *, union ccb *);
63255870Sscottl	xpt_opcode	func_code;	/* XPT function code */
64255870Sscottl	u_int32_t	status;		/* Status returned by CAM subsystem */
65255870Sscottl	struct		cam_path *path;	/* Compiled path for this ccb */
66255870Sscottl	path_id_t	path_id;	/* Path ID for the request */
67255870Sscottl	target_id_t	target_id;	/* Target device ID */
68255870Sscottl	lun_id_t	target_lun;	/* Target LUN number */
69255870Sscottl	u_int32_t	flags;		/* ccb_flags */
70255870Sscottl	ccb_ppriv_area	periph_priv;
71255870Sscottl	ccb_spriv_area	sim_priv;
72255870Sscottl	u_int32_t	timeout;	/* Hard timeout value in seconds */
73255870Sscottl	struct callout_handle timeout_ch;
74255870Sscottl};
75255870Sscottl
76255870Sscottlstruct ccb_pathinq_0x17 {
77255870Sscottl	struct ccb_hdr_0x17 ccb_h;
78255870Sscottl	u_int8_t    version_num;	/* Version number for the SIM/HBA */
79255870Sscottl	u_int8_t    hba_inquiry;	/* Mimic of INQ byte 7 for the HBA */
80255870Sscottl	u_int8_t    target_sprt;	/* Flags for target mode support */
81255870Sscottl	u_int8_t    hba_misc;		/* Misc HBA features */
82255870Sscottl	u_int16_t   hba_eng_cnt;	/* HBA engine count */
83255870Sscottl					/* Vendor Unique capabilities */
84255870Sscottl	u_int8_t    vuhba_flags[VUHBALEN];
85255870Sscottl	u_int32_t   max_target;		/* Maximum supported Target */
86255870Sscottl	u_int32_t   max_lun;		/* Maximum supported Lun */
87255870Sscottl	u_int32_t   async_flags;	/* Installed Async handlers */
88255870Sscottl	path_id_t   hpath_id;		/* Highest Path ID in the subsystem */
89255870Sscottl	target_id_t initiator_id;	/* ID of the HBA on the SCSI bus */
90255870Sscottl	char	    sim_vid[SIM_IDLEN];	/* Vendor ID of the SIM */
91255870Sscottl	char	    hba_vid[HBA_IDLEN];	/* Vendor ID of the HBA */
92255870Sscottl	char 	    dev_name[DEV_IDLEN];/* Device name for SIM */
93255870Sscottl	u_int32_t   unit_number;	/* Unit number for SIM */
94255870Sscottl	u_int32_t   bus_id;		/* Bus ID for SIM */
95255870Sscottl	u_int32_t   base_transfer_speed;/* Base bus speed in KB/sec */
96255870Sscottl	cam_proto   protocol;
97255870Sscottl	u_int	    protocol_version;
98255870Sscottl	cam_xport   transport;
99255870Sscottl	u_int	    transport_version;
100255870Sscottl	union {
101255870Sscottl		struct ccb_pathinq_settings_spi spi;
102255870Sscottl		struct ccb_pathinq_settings_fc fc;
103255870Sscottl		struct ccb_pathinq_settings_sas sas;
104255870Sscottl		char ccb_pathinq_settings_opaque[PATHINQ_SETTINGS_SIZE];
105255870Sscottl	} xport_specific;
106255870Sscottl	u_int		maxio;		/* Max supported I/O size, in bytes. */
107255870Sscottl	u_int16_t	hba_vendor;	/* HBA vendor ID */
108255870Sscottl	u_int16_t	hba_device;	/* HBA device ID */
109255870Sscottl	u_int16_t	hba_subvendor;	/* HBA subvendor ID */
110255870Sscottl	u_int16_t	hba_subdevice;	/* HBA subdevice ID */
111255870Sscottl};
112255870Sscottl
113255870Sscottl#define CAM_0X17_LEN	(sizeof(union ccb) - sizeof(struct ccb_hdr) + sizeof(struct ccb_hdr_0x17))
114255870Sscottl#define CAM_0X17_DATA_LEN (sizeof(union ccb) - sizeof(struct ccb_hdr_0x17))
115255870Sscottl
116255870Sscottl#define	CAMIOCOMMAND_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 2, CAM_0X17_LEN)
117255870Sscottl#define CAMGETPASSTHRU_0x17	_IOC(IOC_INOUT, CAM_VERSION_0x17, 3, CAM_0X17_LEN)
118255870Sscottl
119251837Sscottl#endif
120255870Sscottl#endif
121