cam_xpt_internal.h revision 198331
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: head/sys/cam/cam_xpt_internal.h 198331 2009-10-21 15:27:48Z mav $
27195534Sscottl */
28195534Sscottl
29195534Sscottl#ifndef _CAM_CAM_XPT_INTERNAL_H
30195534Sscottl#define _CAM_CAM_XPT_INTERNAL_H 1
31195534Sscottl
32195534Sscottl/* Forward Declarations */
33195534Sscottlstruct cam_eb;
34195534Sscottlstruct cam_et;
35195534Sscottlstruct cam_ed;
36195534Sscottl
37195534Sscottltypedef struct cam_ed * (*xpt_alloc_device_func)(struct cam_eb *bus,
38195534Sscottl					         struct cam_et *target,
39195534Sscottl					         lun_id_t lun_id);
40195534Sscottltypedef void (*xpt_release_device_func)(struct cam_eb *bus,
41195534Sscottl				        struct cam_et *target,
42195534Sscottl				        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);
49195534Sscottltypedef void (*xpt_announce_periph_func)(struct cam_periph *periph,
50195534Sscottl					 char *announce_string);
51195534Sscottl
52195534Sscottlstruct xpt_xport {
53195534Sscottl	xpt_alloc_device_func	alloc_device;
54195534Sscottl	xpt_release_device_func	reldev;
55195534Sscottl	xpt_action_func		action;
56195534Sscottl	xpt_dev_async_func	async;
57195534Sscottl	xpt_announce_periph_func announce;
58195534Sscottl};
59195534Sscottl
60195534Sscottl/*
61195534Sscottl * Structure for queueing a device in a run queue.
62195534Sscottl * There is one run queue for allocating new ccbs,
63195534Sscottl * and another for sending ccbs to the controller.
64195534Sscottl */
65195534Sscottlstruct cam_ed_qinfo {
66195534Sscottl	cam_pinfo pinfo;
67195534Sscottl	struct	  cam_ed *device;
68195534Sscottl};
69195534Sscottl
70195534Sscottl/*
71195534Sscottl * The CAM EDT (Existing Device Table) contains the device information for
72195534Sscottl * all devices for all busses in the system.  The table contains a
73195534Sscottl * cam_ed structure for each device on the bus.
74195534Sscottl */
75195534Sscottlstruct cam_ed {
76195534Sscottl	TAILQ_ENTRY(cam_ed) links;
77195534Sscottl	struct	cam_ed_qinfo alloc_ccb_entry;
78195534Sscottl	struct	cam_ed_qinfo send_ccb_entry;
79195534Sscottl	struct	cam_et	 *target;
80195534Sscottl	struct	cam_sim  *sim;
81195534Sscottl	lun_id_t	 lun_id;
82195534Sscottl	struct	camq drvq;		/*
83195534Sscottl					 * Queue of type drivers wanting to do
84195534Sscottl					 * work on this device.
85195534Sscottl					 */
86195534Sscottl	struct	cam_ccbq ccbq;		/* Queue of pending ccbs */
87195534Sscottl	struct	async_list asyncs;	/* Async callback info for this B/T/L */
88195534Sscottl	struct	periph_list periphs;	/* All attached devices */
89195534Sscottl	u_int	generation;		/* Generation number */
90195534Sscottl	struct	cam_periph *owner;	/* Peripheral driver's ownership tag */
91195534Sscottl	void		 *quirk;	/* Oddities about this device */
92195534Sscottl	u_int		 maxtags;
93195534Sscottl	u_int		 mintags;
94195534Sscottl	cam_proto	 protocol;
95195534Sscottl	u_int		 protocol_version;
96195534Sscottl	cam_xport	 transport;
97195534Sscottl	u_int		 transport_version;
98195534Sscottl	struct		 scsi_inquiry_data inq_data;
99195534Sscottl	struct		 ata_params ident_data;
100195534Sscottl	u_int8_t	 inq_flags;	/*
101195534Sscottl					 * Current settings for inquiry flags.
102195534Sscottl					 * This allows us to override settings
103195534Sscottl					 * like disconnection and tagged
104195534Sscottl					 * queuing for a device.
105195534Sscottl					 */
106195534Sscottl	u_int8_t	 queue_flags;	/* Queue flags from the control page */
107195534Sscottl	u_int8_t	 serial_num_len;
108195534Sscottl	u_int8_t	*serial_num;
109195534Sscottl	u_int32_t	 flags;
110195534Sscottl#define CAM_DEV_UNCONFIGURED	 	0x01
111195534Sscottl#define CAM_DEV_REL_TIMEOUT_PENDING	0x02
112195534Sscottl#define CAM_DEV_REL_ON_COMPLETE		0x04
113195534Sscottl#define CAM_DEV_REL_ON_QUEUE_EMPTY	0x08
114195534Sscottl#define CAM_DEV_RESIZE_QUEUE_NEEDED	0x10
115195534Sscottl#define CAM_DEV_TAG_AFTER_COUNT		0x20
116195534Sscottl#define CAM_DEV_INQUIRY_DATA_VALID	0x40
117195534Sscottl#define	CAM_DEV_IN_DV			0x80
118195534Sscottl#define	CAM_DEV_DV_HIT_BOTTOM		0x100
119198331Smav#define CAM_DEV_IDENTIFY_DATA_VALID	0x200
120195534Sscottl	u_int32_t	 tag_delay_count;
121195534Sscottl#define	CAM_TAG_DELAY_COUNT		5
122195534Sscottl	u_int32_t	 tag_saved_openings;
123195534Sscottl	u_int32_t	 refcount;
124195534Sscottl	struct callout	 callout;
125195534Sscottl};
126195534Sscottl
127195534Sscottl/*
128195534Sscottl * Each target is represented by an ET (Existing Target).  These
129195534Sscottl * entries are created when a target is successfully probed with an
130195534Sscottl * identify, and removed when a device fails to respond after a number
131195534Sscottl * of retries, or a bus rescan finds the device missing.
132195534Sscottl */
133195534Sscottlstruct cam_et {
134195534Sscottl	TAILQ_HEAD(, cam_ed) ed_entries;
135195534Sscottl	TAILQ_ENTRY(cam_et) links;
136195534Sscottl	struct	cam_eb	*bus;
137195534Sscottl	target_id_t	target_id;
138195534Sscottl	u_int32_t	refcount;
139195534Sscottl	u_int		generation;
140195534Sscottl	struct		timeval last_reset;
141195534Sscottl};
142195534Sscottl
143195534Sscottl/*
144195534Sscottl * Each bus is represented by an EB (Existing Bus).  These entries
145195534Sscottl * are created by calls to xpt_bus_register and deleted by calls to
146195534Sscottl * xpt_bus_deregister.
147195534Sscottl */
148195534Sscottlstruct cam_eb {
149195534Sscottl	TAILQ_HEAD(, cam_et) et_entries;
150195534Sscottl	TAILQ_ENTRY(cam_eb)  links;
151195534Sscottl	path_id_t	     path_id;
152195534Sscottl	struct cam_sim	     *sim;
153195534Sscottl	struct timeval	     last_reset;
154195534Sscottl	u_int32_t	     flags;
155195534Sscottl#define	CAM_EB_RUNQ_SCHEDULED	0x01
156195534Sscottl	u_int32_t	     refcount;
157195534Sscottl	u_int		     generation;
158195534Sscottl	device_t	     parent_dev;
159195534Sscottl	struct xpt_xport     *xport;
160195534Sscottl};
161195534Sscottl
162195534Sscottlstruct cam_path {
163195534Sscottl	struct cam_periph *periph;
164195534Sscottl	struct cam_eb	  *bus;
165195534Sscottl	struct cam_et	  *target;
166195534Sscottl	struct cam_ed	  *device;
167195534Sscottl};
168195534Sscottl
169195534Sscottlstruct xpt_xport *	scsi_get_xport(void);
170195534Sscottlstruct xpt_xport *	ata_get_xport(void);
171195534Sscottl
172195534Sscottlstruct cam_ed *		xpt_alloc_device(struct cam_eb *bus,
173195534Sscottl					 struct cam_et *target,
174195534Sscottl					 lun_id_t lun_id);
175195534Sscottlvoid			xpt_run_dev_sendq(struct cam_eb *bus);
176195534Sscottlint			xpt_schedule_dev(struct camq *queue, cam_pinfo *dev_pinfo,
177195534Sscottl					 u_int32_t new_priority);
178195534Sscottlu_int32_t		xpt_dev_ccbq_resize(struct cam_path *path, int newopenings);
179195534Sscottl
180195534Sscottl
181195534Sscottl
182195534Sscottlstatic __inline int
183195534Sscottlxpt_schedule_dev_sendq(struct cam_eb *bus, struct cam_ed *dev)
184195534Sscottl{
185195534Sscottl	int	retval;
186195534Sscottl
187195534Sscottl	if (dev->ccbq.dev_openings > 0) {
188195534Sscottl		/*
189195534Sscottl		 * The priority of a device waiting for controller
190195534Sscottl		 * resources is that of the the highest priority CCB
191195534Sscottl		 * enqueued.
192195534Sscottl		 */
193195534Sscottl		retval =
194195534Sscottl		    xpt_schedule_dev(&bus->sim->devq->send_queue,
195195534Sscottl				     &dev->send_ccb_entry.pinfo,
196195534Sscottl				     CAMQ_GET_HEAD(&dev->ccbq.queue)->priority);
197195534Sscottl	} else {
198195534Sscottl		retval = 0;
199195534Sscottl	}
200195534Sscottl	return (retval);
201195534Sscottl}
202195534Sscottl
203195534SscottlMALLOC_DECLARE(M_CAMXPT);
204195534Sscottl
205195534Sscottl#endif
206