1195534Sscottl/*-
2195534Sscottl * Copyright 2009 Scott Long
3195534Sscottl * All rights reserved.
4195534Sscottl *
5195534Sscottl * Redistribution and use in source and binary forms, with or without
6195534Sscottl * modification, are permitted provided that the following conditions
7195534Sscottl * are met:
8195534Sscottl * 1. Redistributions of source code must retain the above copyright
9195534Sscottl *    notice, this list of conditions, and the following disclaimer,
10195534Sscottl *    without modification, immediately at the beginning of the file.
11195534Sscottl * 2. The name of the author may not be used to endorse or promote products
12195534Sscottl *    derived from this software without specific prior written permission.
13195534Sscottl *
14195534Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15195534Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16195534Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17195534Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18195534Sscottl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19195534Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20195534Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21195534Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22195534Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23195534Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24195534Sscottl * SUCH DAMAGE.
25195534Sscottl *
26195534Sscottl * $FreeBSD: stable/11/sys/cam/cam_xpt_internal.h 328820 2018-02-02 23:22:58Z mav $
27195534Sscottl */
28195534Sscottl
29195534Sscottl#ifndef _CAM_CAM_XPT_INTERNAL_H
30195534Sscottl#define _CAM_CAM_XPT_INTERNAL_H 1
31195534Sscottl
32256843Smav#include <sys/taskqueue.h>
33256843Smav
34195534Sscottl/* Forward Declarations */
35195534Sscottlstruct cam_eb;
36195534Sscottlstruct cam_et;
37195534Sscottlstruct cam_ed;
38195534Sscottl
39195534Sscottltypedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus,
40195534Sscottl					         struct cam_et *target,
41195534Sscottl					         lun_id_t lun_id);
42198748Smavtypedef void (*xpt_release_device_func)(struct cam_ed *device);
43195534Sscottltypedef void (*xpt_action_func)(union ccb *start_ccb);
44195534Sscottltypedef void (*xpt_dev_async_func)(u_int32_t async_code,
45195534Sscottl				   struct cam_eb *bus,
46195534Sscottl				   struct cam_et *target,
47195534Sscottl				   struct cam_ed *device,
48195534Sscottl				   void *async_arg);
49204220Smavtypedef void (*xpt_announce_periph_func)(struct cam_periph *periph);
50195534Sscottl
51328819Smavstruct xpt_xport_ops {
52195534Sscottl	xpt_alloc_device_func	alloc_device;
53195534Sscottl	xpt_release_device_func	reldev;
54195534Sscottl	xpt_action_func		action;
55195534Sscottl	xpt_dev_async_func	async;
56195534Sscottl	xpt_announce_periph_func announce;
57195534Sscottl};
58195534Sscottl
59328819Smavstruct xpt_xport {
60328819Smav	cam_xport		xport;
61328819Smav	const char		*name;
62328819Smav	struct xpt_xport_ops	*ops;
63328819Smav};
64328819Smav
65328819SmavSET_DECLARE(cam_xpt_xport_set, struct xpt_xport);
66328819Smav#define CAM_XPT_XPORT(data) 				\
67328819Smav	DATA_SET(cam_xpt_xport_set, data)
68328819Smav
69328820Smavtypedef void (*xpt_proto_announce_func)(struct cam_ed *);
70328820Smavtypedef void (*xpt_proto_debug_out_func)(union ccb *);
71328820Smav
72328820Smavstruct xpt_proto_ops {
73328820Smav	xpt_proto_announce_func	announce;
74328820Smav	xpt_proto_announce_func	denounce;
75328820Smav	xpt_proto_debug_out_func debug_out;
76328820Smav};
77328820Smav
78328820Smavstruct xpt_proto {
79328820Smav	cam_proto		proto;
80328820Smav	const char		*name;
81328820Smav	struct xpt_proto_ops	*ops;
82328820Smav};
83328820Smav
84328820SmavSET_DECLARE(cam_xpt_proto_set, struct xpt_proto);
85328820Smav#define CAM_XPT_PROTO(data) 				\
86328820Smav	DATA_SET(cam_xpt_proto_set, data)
87328820Smav
88328820Smav
89195534Sscottl/*
90195534Sscottl * The CAM EDT (Existing Device Table) contains the device information for
91195534Sscottl * all devices for all busses in the system.  The table contains a
92195534Sscottl * cam_ed structure for each device on the bus.
93195534Sscottl */
94195534Sscottlstruct cam_ed {
95256843Smav	cam_pinfo	 devq_entry;
96195534Sscottl	TAILQ_ENTRY(cam_ed) links;
97195534Sscottl	struct	cam_et	 *target;
98195534Sscottl	struct	cam_sim  *sim;
99195534Sscottl	lun_id_t	 lun_id;
100195534Sscottl	struct	cam_ccbq ccbq;		/* Queue of pending ccbs */
101195534Sscottl	struct	async_list asyncs;	/* Async callback info for this B/T/L */
102195534Sscottl	struct	periph_list periphs;	/* All attached devices */
103195534Sscottl	u_int	generation;		/* Generation number */
104195534Sscottl	void		 *quirk;	/* Oddities about this device */
105195534Sscottl	u_int		 maxtags;
106195534Sscottl	u_int		 mintags;
107195534Sscottl	cam_proto	 protocol;
108195534Sscottl	u_int		 protocol_version;
109195534Sscottl	cam_xport	 transport;
110195534Sscottl	u_int		 transport_version;
111195534Sscottl	struct		 scsi_inquiry_data inq_data;
112216088Sken	uint8_t		 *supported_vpds;
113216088Sken	uint8_t		 supported_vpds_len;
114216088Sken	uint32_t	 device_id_len;
115216088Sken	uint8_t		 *device_id;
116278228Sken	uint32_t	 ext_inq_len;
117278228Sken	uint8_t		 *ext_inq;
118223081Sgibbs	uint8_t		 physpath_len;
119223081Sgibbs	uint8_t		 *physpath;	/* physical path string form */
120230590Sken	uint32_t	 rcap_len;
121230590Sken	uint8_t		 *rcap_buf;
122195534Sscottl	struct		 ata_params ident_data;
123195534Sscottl	u_int8_t	 inq_flags;	/*
124195534Sscottl					 * Current settings for inquiry flags.
125195534Sscottl					 * This allows us to override settings
126195534Sscottl					 * like disconnection and tagged
127195534Sscottl					 * queuing for a device.
128195534Sscottl					 */
129195534Sscottl	u_int8_t	 queue_flags;	/* Queue flags from the control page */
130195534Sscottl	u_int8_t	 serial_num_len;
131195534Sscottl	u_int8_t	*serial_num;
132195534Sscottl	u_int32_t	 flags;
133195534Sscottl#define CAM_DEV_UNCONFIGURED	 	0x01
134195534Sscottl#define CAM_DEV_REL_TIMEOUT_PENDING	0x02
135195534Sscottl#define CAM_DEV_REL_ON_COMPLETE		0x04
136195534Sscottl#define CAM_DEV_REL_ON_QUEUE_EMPTY	0x08
137195534Sscottl#define CAM_DEV_TAG_AFTER_COUNT		0x20
138195534Sscottl#define CAM_DEV_INQUIRY_DATA_VALID	0x40
139195534Sscottl#define	CAM_DEV_IN_DV			0x80
140195534Sscottl#define	CAM_DEV_DV_HIT_BOTTOM		0x100
141198331Smav#define CAM_DEV_IDENTIFY_DATA_VALID	0x200
142195534Sscottl	u_int32_t	 tag_delay_count;
143195534Sscottl#define	CAM_TAG_DELAY_COUNT		5
144195534Sscottl	u_int32_t	 tag_saved_openings;
145195534Sscottl	u_int32_t	 refcount;
146195534Sscottl	struct callout	 callout;
147253958Smav	STAILQ_ENTRY(cam_ed) highpowerq_entry;
148256843Smav	struct mtx	 device_mtx;
149256843Smav	struct task	 device_destroy_task;
150301771Simp	const struct	 nvme_controller_data *nvme_cdata;
151301771Simp	const struct	 nvme_namespace_data *nvme_data;
152195534Sscottl};
153195534Sscottl
154195534Sscottl/*
155195534Sscottl * Each target is represented by an ET (Existing Target).  These
156195534Sscottl * entries are created when a target is successfully probed with an
157195534Sscottl * identify, and removed when a device fails to respond after a number
158195534Sscottl * of retries, or a bus rescan finds the device missing.
159195534Sscottl */
160195534Sscottlstruct cam_et {
161195534Sscottl	TAILQ_HEAD(, cam_ed) ed_entries;
162195534Sscottl	TAILQ_ENTRY(cam_et) links;
163195534Sscottl	struct	cam_eb	*bus;
164195534Sscottl	target_id_t	target_id;
165195534Sscottl	u_int32_t	refcount;
166195534Sscottl	u_int		generation;
167195534Sscottl	struct		timeval last_reset;
168208911Smjacob	u_int		rpl_size;
169208911Smjacob	struct scsi_report_luns_data *luns;
170256843Smav	struct mtx	luns_mtx;	/* Protection for luns field. */
171195534Sscottl};
172195534Sscottl
173195534Sscottl/*
174195534Sscottl * Each bus is represented by an EB (Existing Bus).  These entries
175195534Sscottl * are created by calls to xpt_bus_register and deleted by calls to
176195534Sscottl * xpt_bus_deregister.
177195534Sscottl */
178195534Sscottlstruct cam_eb {
179195534Sscottl	TAILQ_HEAD(, cam_et) et_entries;
180195534Sscottl	TAILQ_ENTRY(cam_eb)  links;
181195534Sscottl	path_id_t	     path_id;
182195534Sscottl	struct cam_sim	     *sim;
183195534Sscottl	struct timeval	     last_reset;
184195534Sscottl	u_int32_t	     flags;
185195534Sscottl#define	CAM_EB_RUNQ_SCHEDULED	0x01
186195534Sscottl	u_int32_t	     refcount;
187195534Sscottl	u_int		     generation;
188195534Sscottl	device_t	     parent_dev;
189195534Sscottl	struct xpt_xport     *xport;
190256843Smav	struct mtx	     eb_mtx;	/* Bus topology mutex. */
191195534Sscottl};
192195534Sscottl
193195534Sscottlstruct cam_path {
194195534Sscottl	struct cam_periph *periph;
195195534Sscottl	struct cam_eb	  *bus;
196195534Sscottl	struct cam_et	  *target;
197195534Sscottl	struct cam_ed	  *device;
198195534Sscottl};
199195534Sscottl
200195534Sscottlstruct cam_ed *		xpt_alloc_device(struct cam_eb *bus,
201195534Sscottl					 struct cam_et *target,
202195534Sscottl					 lun_id_t lun_id);
203198748Smavvoid			xpt_acquire_device(struct cam_ed *device);
204198748Smavvoid			xpt_release_device(struct cam_ed *device);
205195534Sscottlu_int32_t		xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
206199178Smavvoid			xpt_start_tags(struct cam_path *path);
207199178Smavvoid			xpt_stop_tags(struct cam_path *path);
208195534Sscottl
209195534SscottlMALLOC_DECLARE(M_CAMXPT);
210195534Sscottl
211195534Sscottl#endif
212