PageRenderTime 56ms CodeModel.GetById 12ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 1ms

/testbed/scsipi/scsipiconf.h

http://rtems-atapi.googlecode.com/
C++ Header | 859 lines | 487 code | 126 blank | 246 comment | 0 complexity | dcae428af41e6b7de6672cb4d0a34cc2 MD5 | raw file
  1/*	$NetBSD: scsipiconf.h,v 1.113 2008/09/08 23:36:54 gmcgarry Exp $	*/
  2
  3/*-
  4 * Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc.
  5 * All rights reserved.
  6 *
  7 * This code is derived from software contributed to The NetBSD Foundation
  8 * by Charles M. Hannum; by Jason R. Thorpe of the Numerical Aerospace
  9 * Simulation Facility, NASA Ames Research Center.
 10 *
 11 * Redistribution and use in source and binary forms, with or without
 12 * modification, are permitted provided that the following conditions
 13 * are met:
 14 * 1. Redistributions of source code must retain the above copyright
 15 *    notice, this list of conditions and the following disclaimer.
 16 * 2. Redistributions in binary form must reproduce the above copyright
 17 *    notice, this list of conditions and the following disclaimer in the
 18 *    documentation and/or other materials provided with the distribution.
 19 *
 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 30 * POSSIBILITY OF SUCH DAMAGE.
 31 */
 32
 33/*
 34 * Originally written by Julian Elischer (julian@tfs.com)
 35 * for TRW Financial Systems for use under the MACH(2.5) operating system.
 36 *
 37 * TRW Financial Systems, in accordance with their agreement with Carnegie
 38 * Mellon University, makes this software available to CMU to distribute
 39 * or use in any manner that they see fit as long as this message is kept with
 40 * the software. For this reason TFS also grants any other persons or
 41 * organisations permission to use or modify this software.
 42 *
 43 * TFS supplies this software to be publicly redistributed
 44 * on the understanding that TFS is not responsible for the correct
 45 * functioning of this software in any circumstances.
 46 *
 47 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
 48 */
 49
 50#ifndef _DEV_SCSIPI_SCSIPICONF_H_
 51#define _DEV_SCSIPI_SCSIPICONF_H_
 52
 53typedef	int	boolean;
 54
 55#include "../sys/callout.h"
 56#include <rtems/bsd/sys/queue.h>
 57#include "../scsipi/scsi_spc.h"
 58#include "../scsipi/scsipi_debug.h"
 59
 60struct buf;
 61struct proc;
 62struct device;
 63struct scsipi_channel;
 64struct scsipi_periph;
 65struct scsipi_xfer;
 66
 67/*
 68 * The following defines the scsipi_xfer queue.
 69 */
 70TAILQ_HEAD(scsipi_xfer_queue, scsipi_xfer);
 71
 72struct scsipi_generic {
 73	u_int8_t opcode;
 74	u_int8_t bytes[15];
 75};
 76
 77
 78/*
 79 * scsipi_async_event_t:
 80 *
 81 *	Asynchronous events from the adapter to the mid-layer and
 82 *	peripherial.
 83 *
 84 *	Arguments:
 85 *
 86 *	ASYNC_EVENT_MAX_OPENINGS	scsipi_max_openings * -- max
 87 *					openings, device specified in
 88 *					parameters
 89 *
 90 *	ASYNC_EVENT_XFER_MODE		scsipi_xfer_mode * -- xfer mode
 91 *					parameters changed for I_T Nexus
 92 *	ASYNC_EVENT_RESET		NULL - channel has been reset
 93 */
 94typedef enum {
 95	ASYNC_EVENT_MAX_OPENINGS,	/* set max openings on periph */
 96	ASYNC_EVENT_XFER_MODE,		/* xfer mode update for I_T */
 97	ASYNC_EVENT_RESET		/* channel reset */
 98} scsipi_async_event_t;
 99
100/*
101 * scsipi_max_openings:
102 *
103 *	Argument for an ASYNC_EVENT_MAX_OPENINGS event.
104 */
105struct scsipi_max_openings {
106	int	mo_target;		/* openings are for this target... */
107	int	mo_lun;			/* ...and this lun */
108	int	mo_openings;		/* openings value */
109};
110
111/*
112 * scsipi_xfer_mode:
113 *
114 *	Argument for an ASYNC_EVENT_XFER_MODE event.
115 */
116struct scsipi_xfer_mode {
117	int	xm_target;		/* target, for I_T Nexus */
118	int	xm_mode;		/* PERIPH_CAP* bits */
119	int	xm_period;		/* sync period */
120	int	xm_offset;		/* sync offset */
121};
122
123
124/*
125 * scsipi_adapter_req_t:
126 *
127 *	Requests that can be made of an adapter.
128 *
129 *	Arguments:
130 *
131 *	ADAPTER_REQ_RUN_XFER		scsipi_xfer * -- the xfer which
132 *					is to be run
133 *
134 *	ADAPTER_REQ_GROW_RESOURCES	no argument
135 *
136 *	ADAPTER_REQ_SET_XFER_MODE	scsipi_xfer_mode * -- set the xfer
137 *					mode for the I_T Nexus according to
138 *					this
139 */
140typedef enum {
141	ADAPTER_REQ_RUN_XFER,		/* run a scsipi_xfer */
142	ADAPTER_REQ_GROW_RESOURCES,	/* grow xfer execution resources */
143	ADAPTER_REQ_SET_XFER_MODE	/* set xfer mode */
144} scsipi_adapter_req_t;
145
146
147/*
148 * scsipi_periphsw:
149 *
150 *	Callbacks into periph driver from midlayer.
151 *
152 *	psw_error	Called by the bustype's interpret-sense routine
153 *			to do periph-specific sense handling.
154 *
155 *	psw_start	Called by midlayer to restart a device once
156 *			more command openings become available.
157 *
158 *	psw_async	Called by midlayer when an asynchronous event
159 *			from the adapter occurs.
160 *
161 *	psw_done	Called by the midlayer when an xfer has completed.
162 */
163struct scsipi_periphsw {
164	int	(*psw_error)(struct scsipi_xfer *);
165	void	(*psw_start)(struct scsipi_periph *);
166	int	(*psw_async)(struct scsipi_periph *,
167		    scsipi_async_event_t, void *);
168	void	(*psw_done)(struct scsipi_xfer *, int);
169};
170
171struct disk_parms;
172struct scsipi_inquiry_pattern;
173
174/*
175 * scsipi_adapter:
176 *
177 *	This structure describes an instance of a SCSIPI adapter.
178 *
179 *	Note that `adapt_openings' is used by (the common case of) adapters
180 *	which have per-adapter resources.  If an adapter's command resources
181 *	are associated with a channel, then the `chan_openings' below will
182 *	be used instead.
183 *
184 *	Note that all adapter entry points take a pointer to a channel,
185 *	as an adapter may have more than one channel, and the channel
186 *	structure contains the channel number.
187 */
188struct scsipi_adapter {
189	struct device *adapt_dev;	/* pointer to adapter's device */
190	int	adapt_nchannels;	/* number of adapter channels */
191	int	adapt_refcnt;		/* adapter's reference count */
192	int	adapt_openings;		/* total # of command openings */
193	int	adapt_max_periph;	/* max openings per periph */
194	int	adapt_flags;
195
196	void	(*adapt_request)(struct scsipi_channel *,
197		    scsipi_adapter_req_t, void *);
198	void	(*adapt_minphys)(struct buf *);
199	int	(*adapt_ioctl)(struct scsipi_channel *, u_long,
200		    void *, int, struct proc *);
201	int	(*adapt_enable)(struct device *, int);
202	int	(*adapt_getgeom)(struct scsipi_periph *,
203			struct disk_parms *, u_long);
204	int	(*adapt_accesschk)(struct scsipi_periph *,
205			struct scsipi_inquiry_pattern *);
206};
207
208/* adapt_flags */
209#define SCSIPI_ADAPT_POLL_ONLY	0x01 /* Adaptor can't do interrupts. */
210
211#define	scsipi_adapter_minphys(chan, bp)				\
212	(*(chan)->chan_adapter->adapt_minphys)((bp))
213
214#define	scsipi_adapter_request(chan, req, arg)				\
215	(*(chan)->chan_adapter->adapt_request)((chan), (req), (arg))
216
217#define	scsipi_adapter_ioctl(chan, cmd, data, flag, p)			\
218	(*(chan)->chan_adapter->adapt_ioctl)((chan), (cmd), (data), (flag), (p))
219
220#define	scsipi_adapter_enable(chan, enable)				\
221	(*(chan)->chan_adapt->adapt_enable)((chan), (enable))
222
223
224/*
225 * scsipi_bustype:
226 *
227 *	This structure describes a SCSIPI bus type.
228 *	The bustype_type member is shared with struct ata_bustype
229 *	(because we can ata, atapi or scsi busses to the same controller)
230 */
231struct scsipi_bustype {
232	int	bustype_type;		/* symbolic name of type */
233
234	void	(*bustype_cmd)(struct scsipi_xfer *);
235	int	(*bustype_interpret_sense)(struct scsipi_xfer *);
236	void	(*bustype_printaddr)(struct scsipi_periph *);
237	void	(*bustype_kill_pending)(struct scsipi_periph *);
238};
239
240/* bustype_type */
241#define	SCSIPI_BUSTYPE_SCSI	0
242#define	SCSIPI_BUSTYPE_ATAPI	1
243/* #define SCSIPI_BUSTYPE_ATA	2 */
244
245
246/*
247 * scsipi_channel:
248 *
249 *	This structure describes a single channel of a SCSIPI adapter.
250 *	An adapter may have one or more channels.  See the comment above
251 *	regarding the resource counter.
252 *	Note: chan_bustype has to be first member, as its bustype_type member
253 * 	is shared with the aa_bustype member of struct ata_atapi_attach.
254 */
255
256#define	SCSIPI_CHAN_PERIPH_BUCKETS	16
257#define	SCSIPI_CHAN_PERIPH_HASHMASK	(SCSIPI_CHAN_PERIPH_BUCKETS - 1)
258
259struct scsipi_channel {
260	const struct scsipi_bustype *chan_bustype; /* channel's bus type */
261	const char *chan_name;	/* this channel's name */
262
263	struct scsipi_adapter *chan_adapter; /* pointer to our adapter */
264
265	/* Periphs for this channel. */
266	LIST_HEAD(, scsipi_periph) chan_periphtab[SCSIPI_CHAN_PERIPH_BUCKETS];
267
268	int	chan_channel;		/* channel number */
269	int	chan_flags;		/* channel flags */
270	int	chan_openings;		/* number of command openings */
271	int	chan_max_periph;	/* max openings per periph */
272
273	int	chan_ntargets;		/* number of targets */
274	int	chan_nluns;		/* number of luns */
275	int	chan_id;		/* adapter's ID for this channel */
276
277	int	chan_defquirks;		/* default device's quirks */
278
279	struct lwp *chan_thread;	/* completion thread */
280	int	chan_tflags;		/* flags for the completion thread */
281
282	int	chan_qfreeze;		/* freeze count for queue */
283
284	/* Job queue for this channel. */
285	struct scsipi_xfer_queue chan_queue;
286
287	/* Completed (async) jobs. */
288	struct scsipi_xfer_queue chan_complete;
289
290	/* callback we may have to call from completion thread */
291	void (*chan_callback)(struct scsipi_channel *, void *);
292	void *chan_callback_arg;
293
294	/* callback we may have to call after forking the kthread */
295	void (*chan_init_cb)(struct scsipi_channel *, void *);
296	void *chan_init_cb_arg;
297};
298
299/* chan_flags */
300#define	SCSIPI_CHAN_OPENINGS	0x01	/* use chan_openings */
301#define	SCSIPI_CHAN_CANGROW	0x02	/* channel can grow resources */
302#define	SCSIPI_CHAN_NOSETTLE	0x04	/* don't wait for devices to settle */
303#define	SCSIPI_CHAN_TACTIVE	0x08	/* completion thread is active */
304
305/* chan thread flags (chan_tflags) */
306#define	SCSIPI_CHANT_SHUTDOWN	0x01	/* channel is shutting down */
307#define	SCSIPI_CHANT_CALLBACK	0x02	/* has to call chan_callback() */
308#define	SCSIPI_CHANT_KICK	0x04	/* need to run queues */
309#define	SCSIPI_CHANT_GROWRES	0x08	/* call ADAPTER_REQ_GROW_RESOURCES */
310
311#define	SCSIPI_CHAN_MAX_PERIPH(chan)					\
312	(((chan)->chan_flags & SCSIPI_CHAN_OPENINGS) ?			\
313	 (chan)->chan_max_periph : (chan)->chan_adapter->adapt_max_periph)
314
315
316#define	scsipi_printaddr(periph)					\
317	(*(periph)->periph_channel->chan_bustype->bustype_printaddr)((periph))
318
319#define	scsipi_periph_bustype(periph)					\
320	(periph)->periph_channel->chan_bustype->bustype_type
321
322
323/*
324 * Number of tag words in a periph structure:
325 *
326 *	n_tag_words = ((256 / NBBY) / sizeof(u_int32_t))
327 */
328#define	PERIPH_NTAGWORDS	((256 / 8) / sizeof(u_int32_t))
329
330
331/*
332 * scsipi_periph:
333 *
334 *	This structure describes the path between a peripherial device
335 *	and an adapter.  It contains a pointer to the adapter channel
336 *	which in turn contains a pointer to the adapter.
337 *
338 * XXX Given the way NetBSD's autoconfiguration works, this is ...
339 * XXX nasty.
340 *
341 *	Well, it's a lot nicer than it used to be, but there could
342 *	still be an improvement.
343 */
344struct scsipi_periph {
345	struct device *periph_dev;	/* pointer to peripherial's device */
346	struct scsipi_channel *periph_channel; /* channel we're connected to */
347
348					/* link in channel's table of periphs */
349	LIST_ENTRY(scsipi_periph) periph_hash;
350
351	const struct scsipi_periphsw *periph_switch; /* peripherial's entry
352							points */
353	int	periph_openings;	/* max # of outstanding commands */
354	int	periph_active;		/* current # of outstanding commands */
355	int	periph_sent;		/* current # of commands sent to adapt*/
356
357	int	periph_mode;		/* operation modes, CAP bits */
358	int	periph_period;		/* sync period (factor) */
359	int	periph_offset;		/* sync offset */
360
361	/*
362	 * Information gleaned from the inquiry data.
363	 */
364	u_int8_t periph_type;		/* basic device type */
365	int	periph_cap;		/* capabilities */
366	int	periph_quirks;		/* device's quirks */
367
368	int	periph_flags;		/* misc. flags */
369	int	periph_dbflags;		/* debugging flags */
370
371	int	periph_target;		/* target ID (drive # on ATAPI) */
372	int	periph_lun;		/* LUN (not used on ATAPI) */
373
374	int	periph_version;		/* ANSI SCSI version */
375
376	int	periph_qfreeze;		/* queue freeze count */
377
378	/* Bitmap of free command tags. */
379	u_int32_t periph_freetags[PERIPH_NTAGWORDS];
380
381	/* Pending scsipi_xfers on this peripherial. */
382	struct scsipi_xfer_queue periph_xferq;
383
384	callout_t periph_callout;
385
386	/* xfer which has a pending CHECK_CONDITION */
387	struct scsipi_xfer *periph_xscheck;
388
389};
390
391/*
392 * Macro to return the current xfer mode of a periph.
393 */
394#define	PERIPH_XFER_MODE(periph)					\
395	(((periph)->periph_flags & PERIPH_MODE_VALID) ?			\
396	 (periph)->periph_mode : 0)
397
398/* periph_cap */
399#define	PERIPH_CAP_ANEC		0x0001	/* async event notification */
400#define	PERIPH_CAP_TERMIOP	0x0002	/* terminate i/o proc. messages */
401#define	PERIPH_CAP_RELADR	0x0004	/* relative addressing */
402#define	PERIPH_CAP_WIDE32	0x0008	/* wide-32 transfers */
403#define	PERIPH_CAP_WIDE16	0x0010	/* wide-16 transfers */
404		/*	XXX	0x0020	   reserved for ATAPI_CFG_DRQ_MASK */
405		/*	XXX	0x0040	   reserved for ATAPI_CFG_DRQ_MASK */
406#define	PERIPH_CAP_SYNC		0x0080	/* synchronous transfers */
407#define	PERIPH_CAP_LINKCMDS	0x0100	/* linked commands */
408#define	PERIPH_CAP_TQING	0x0200	/* tagged queueing */
409#define	PERIPH_CAP_SFTRESET	0x0400	/* soft RESET condition response */
410#define	PERIPH_CAP_CMD16	0x0800	/* 16 byte commands (ATAPI) */
411#define	PERIPH_CAP_DT		0x1000	/* supports DT clock */
412#define	PERIPH_CAP_QAS		0x2000	/* supports quick arbit. and select. */
413#define	PERIPH_CAP_IUS		0x4000	/* supports information unit xfers */
414
415/* periph_flags */
416#define	PERIPH_REMOVABLE	0x0001	/* media is removable */
417#define	PERIPH_MEDIA_LOADED	0x0002	/* media is loaded */
418#define	PERIPH_WAITING		0x0004	/* process waiting for opening */
419#define	PERIPH_OPEN		0x0008	/* device is open */
420#define	PERIPH_WAITDRAIN	0x0010	/* waiting for pending xfers to drain */
421#define	PERIPH_GROW_OPENINGS	0x0020	/* allow openings to grow */
422#define	PERIPH_MODE_VALID	0x0040	/* periph_mode is valid */
423#define	PERIPH_RECOVERING	0x0080	/* periph is recovering */
424#define	PERIPH_RECOVERY_ACTIVE	0x0100	/* a recovery command is active */
425#define PERIPH_KEEP_LABEL	0x0200	/* retain label after 'full' close */
426#define	PERIPH_SENSE		0x0400	/* periph has sense pending */
427#define PERIPH_UNTAG		0x0800	/* untagged command running */
428
429/* periph_quirks */
430#define	PQUIRK_AUTOSAVE		0x00000001	/* do implicit SAVE POINTERS */
431#define	PQUIRK_NOSYNC		0x00000002	/* does not grok SDTR */
432#define	PQUIRK_NOWIDE		0x00000004	/* does not grok WDTR */
433#define	PQUIRK_NOTAG		0x00000008	/* does not grok tagged cmds */
434#define	PQUIRK_NOLUNS		0x00000010	/* DTWT with LUNs */
435#define	PQUIRK_FORCELUNS	0x00000020	/* prehistoric device groks
436						   LUNs */
437#define	PQUIRK_NOMODESENSE	0x00000040	/* device doesn't do MODE SENSE
438						   properly */
439#define	PQUIRK_NOSYNCCACHE	0x00000100	/* do not issue SYNC CACHE */
440#define	PQUIRK_LITTLETOC	0x00000400	/* audio TOC is little-endian */
441#define	PQUIRK_NOCAPACITY	0x00000800	/* no READ CD CAPACITY */
442#define	PQUIRK_NOTUR		0x00001000	/* no TEST UNIT READY */
443#define	PQUIRK_NODOORLOCK	0x00002000	/* can't lock door */
444#define	PQUIRK_NOSENSE		0x00004000	/* can't REQUEST SENSE */
445#define PQUIRK_ONLYBIG		0x00008000	/* only use SCSI_{R,W}_BIG */
446#define PQUIRK_NOBIGMODESENSE	0x00040000	/* has no big mode-sense op */
447#define PQUIRK_CAP_SYNC		0x00080000	/* SCSI device with ST sync op*/
448#define PQUIRK_CAP_WIDE16	0x00100000	/* SCSI device with ST wide op*/
449#define PQUIRK_CAP_NODT		0x00200000	/* signals DT, but can't. */
450
451
452/*
453 * Error values an adapter driver may return
454 */
455typedef enum {
456	XS_NOERROR,		/* there is no error, (sense is invalid)  */
457	XS_SENSE,		/* Check the returned sense for the error */
458	XS_SHORTSENSE,		/* Check the ATAPI sense for the error	  */
459	XS_DRIVER_STUFFUP,	/* Driver failed to perform operation     */
460	XS_RESOURCE_SHORTAGE,	/* adapter resource shortage		  */
461	XS_SELTIMEOUT,		/* The device timed out.. turned off?     */
462	XS_TIMEOUT,		/* The Timeout reported was caught by SW  */
463	XS_BUSY,		/* The device busy, try again later?      */
464	XS_RESET,		/* bus was reset; possible retry command  */
465	XS_REQUEUE		/* requeue this command */
466} scsipi_xfer_result_t;
467
468/*
469 * Each scsipi transaction is fully described by one of these structures
470 * It includes information about the source of the command and also the
471 * device and adapter for which the command is destined.
472 *
473 * Before the HBA is given this transaction, channel_q is the linkage on
474 * the related channel's chan_queue.
475 *
476 * When the this transaction is taken off the channel's chan_queue and
477 * the HBA's request entry point is called with this transaction, the
478 * HBA can use the channel_q tag for whatever it likes until it calls
479 * scsipi_done for this transaction, at which time it has to stop
480 * using channel_q.
481 *
482 * After scsipi_done is called with this transaction and if there was an
483 * error on it, channel_q then becomes the linkage on the related channel's
484 * chan_complete cqueue.
485 *
486 * The device_q member is maintained by the scsipi middle layer.  When
487 * a device issues a command, the xfer is placed on that device's
488 * pending commands queue.  When an xfer is done and freed, it is taken
489 * off the device's queue.  This allows for a device to wait for all of
490 * its pending commands to complete.
491 */
492struct scsipi_xfer {
493	TAILQ_ENTRY(scsipi_xfer) channel_q; /* entry on channel queue */
494	TAILQ_ENTRY(scsipi_xfer) device_q;  /* device's pending xfers */
495	callout_t xs_callout;		/* callout for adapter use */
496	int	xs_control;		/* control flags */
497	volatile int xs_status;		/* status flags */
498	struct scsipi_periph *xs_periph;/* peripherial doing the xfer */
499	int	xs_retries;		/* the number of times to retry */
500	int	xs_requeuecnt;		/* number of requeues */
501	int	timeout;		/* in milliseconds */
502	struct	scsipi_generic *cmd;	/* The scsipi command to execute */
503	int	cmdlen;			/* how long it is */
504	u_char	*data;			/* DMA address OR a uio address */
505	int	datalen;		/* data len (blank if uio) */
506	int	resid;			/* how much buffer was not touched */
507	scsipi_xfer_result_t error;	/* an error value */
508	struct	buf *bp;		/* If we need to associate with */
509					/* a buf */
510	union {
511		struct  scsi_sense_data scsi_sense; /* 32 bytes */
512		u_int32_t atapi_sense;
513	} sense;
514
515	struct scsipi_xfer *xs_sensefor;/* we are requesting sense for this */
516					/* xfer */
517
518	u_int8_t status;		/* SCSI status */
519
520	/*
521	 * Info for tagged command queueing.  This may or may not
522	 * be used by a given adapter driver.  These are the same
523	 * as the bytes in the tag message.
524	 */
525	u_int8_t xs_tag_type;		/* tag type */
526	u_int8_t xs_tag_id;		/* tag ID */
527
528	struct	scsipi_generic cmdstore /*__aligned(4)*/;		/* stash the command in here */
529};
530
531/*
532 * scsipi_xfer control flags
533 *
534 * To do:
535 *
536 *	- figure out what to do with XS_CTL_ESCAPE
537 *
538 *	- replace XS_CTL_URGENT with an `xs_priority' field?
539 */
540#define	XS_CTL_NOSLEEP		0x00000001	/* don't sleep */
541#define	XS_CTL_POLL		0x00000002	/* poll for completion */
542#define	XS_CTL_DISCOVERY	0x00000004	/* doing device discovery */
543#define	XS_CTL_ASYNC		0x00000008	/* command completes
544						   asynchronously */
545#define	XS_CTL_USERCMD		0x00000010	/* user issued command */
546#define	XS_CTL_SILENT		0x00000020	/* don't print sense info */
547#define	XS_CTL_IGNORE_NOT_READY	0x00000040	/* ignore NOT READY */
548#define	XS_CTL_IGNORE_MEDIA_CHANGE 					\
549				0x00000080	/* ignore media change */
550#define	XS_CTL_IGNORE_ILLEGAL_REQUEST					\
551				0x00000100	/* ignore ILLEGAL REQUEST */
552#define	XS_CTL_SILENT_NODEV	0x00000200	/* don't print sense info
553						   if sense info is nodev */
554#define	XS_CTL_RESET		0x00000400	/* reset the device */
555#define	XS_CTL_DATA_UIO		0x00000800	/* xs_data points to uio */
556#define	XS_CTL_DATA_IN		0x00001000	/* data coming into memory */
557#define	XS_CTL_DATA_OUT		0x00002000	/* data going out of memory */
558#define	XS_CTL_TARGET		0x00004000	/* target mode operation */
559#define	XS_CTL_ESCAPE		0x00008000	/* escape operation */
560#define	XS_CTL_URGENT		0x00010000	/* urgent (recovery)
561						   operation */
562#define	XS_CTL_SIMPLE_TAG	0x00020000	/* use a Simple Tag */
563#define	XS_CTL_ORDERED_TAG	0x00040000	/* use an Ordered Tag */
564#define	XS_CTL_HEAD_TAG		0x00080000	/* use a Head of Queue Tag */
565#define	XS_CTL_THAW_PERIPH	0x00100000	/* thaw periph once enqueued */
566#define	XS_CTL_FREEZE_PERIPH	0x00200000	/* freeze periph when done */
567#define XS_CTL_DATA_ONSTACK	0x00400000	/* data is alloc'ed on stack */
568#define XS_CTL_REQSENSE		0x00800000	/* xfer is a request sense */
569
570#define	XS_CTL_TAGMASK	(XS_CTL_SIMPLE_TAG|XS_CTL_ORDERED_TAG|XS_CTL_HEAD_TAG)
571
572#define	XS_CTL_TAGTYPE(xs)	((xs)->xs_control & XS_CTL_TAGMASK)
573
574/*
575 * scsipi_xfer status flags
576 */
577#define	XS_STS_DONE		0x00000001	/* scsipi_xfer is done */
578#define	XS_STS_PRIVATE		0xf0000000	/* reserved for HBA's use */
579
580/*
581 * This describes matching information for scsipi_inqmatch().  The more things
582 * match, the higher the configuration priority.
583 */
584struct scsipi_inquiry_pattern {
585	u_int8_t type;
586	boolean removable;
587	const char *vendor;
588	const char *product;
589	const char *revision;
590};
591
592/*
593 * This is used to pass information from the high-level configuration code
594 * to the device-specific drivers.
595 */
596struct scsipibus_attach_args {
597	struct scsipi_periph *sa_periph;
598	struct scsipi_inquiry_pattern sa_inqbuf;
599	struct scsipi_inquiry_data *sa_inqptr;
600	union {				/* bus-type specific infos */
601		u_int8_t scsi_version;	/* SCSI version */
602	} scsipi_info;
603};
604
605/*
606 * this describes a quirk entry
607 */
608struct scsi_quirk_inquiry_pattern {
609	struct scsipi_inquiry_pattern pattern;
610	int quirks;
611};
612
613/*
614 * Default number of retries, used for generic routines.
615 */
616#define SCSIPIRETRIES 4
617
618
619#ifdef _KERNEL
620void	scsipi_init(void);
621int	scsipi_command(struct scsipi_periph *, struct scsipi_generic *, int,
622	    u_char *, int, int, int, struct buf *, int);
623void	scsipi_create_completion_thread(void *);
624const void *scsipi_inqmatch(struct scsipi_inquiry_pattern *, const void *,
625	    size_t, size_t, int *);
626const char *scsipi_dtype(int);
627void	scsipi_strvis(u_char *, int, const u_char *, int);
628int	scsipi_execute_xs(struct scsipi_xfer *);
629int	scsipi_test_unit_ready(struct scsipi_periph *, int);
630int	scsipi_prevent(struct scsipi_periph *, int, int);
631int	scsipi_inquire(struct scsipi_periph *,
632	    struct scsipi_inquiry_data *, int);
633int	scsipi_mode_select(struct scsipi_periph *, int,
634	    struct scsi_mode_parameter_header_6 *, int, int, int, int);
635int	scsipi_mode_select_big(struct scsipi_periph *, int,
636	    struct scsi_mode_parameter_header_10 *, int, int, int, int);
637int	scsipi_mode_sense(struct scsipi_periph *, int, int,
638	    struct scsi_mode_parameter_header_6 *, int, int, int, int);
639int	scsipi_mode_sense_big(struct scsipi_periph *, int, int,
640	    struct scsi_mode_parameter_header_10 *, int, int, int, int);
641int	scsipi_start(struct scsipi_periph *, int, int);
642void	scsipi_done(struct scsipi_xfer *);
643void	scsipi_user_done(struct scsipi_xfer *);
644int	scsipi_interpret_sense(struct scsipi_xfer *);
645void	scsipi_wait_drain(struct scsipi_periph *);
646void	scsipi_kill_pending(struct scsipi_periph *);
647struct scsipi_periph *scsipi_alloc_periph(int);
648#ifdef SCSIVERBOSE
649void	scsipi_print_sense(struct scsipi_xfer *, int);
650void	scsipi_print_sense_data(struct scsi_sense_data *, int);
651char   *scsipi_decode_sense(void *, int);
652#endif
653void	scsipi_print_cdb(struct scsipi_generic *cmd);
654int	scsipi_thread_call_callback(struct scsipi_channel *,
655	    void (*callback)(struct scsipi_channel *, void *),
656	    void *);
657void	scsipi_async_event(struct scsipi_channel *,
658	    scsipi_async_event_t, void *);
659int	scsipi_do_ioctl(struct scsipi_periph *, dev_t, u_long, void *,
660	    int, struct lwp *);
661
662void	scsipi_print_xfer_mode(struct scsipi_periph *);
663void	scsipi_set_xfer_mode(struct scsipi_channel *, int, int);
664
665int	scsipi_channel_init(struct scsipi_channel *);
666void	scsipi_channel_shutdown(struct scsipi_channel *);
667
668void	scsipi_insert_periph(struct scsipi_channel *,
669	    struct scsipi_periph *);
670void	scsipi_remove_periph(struct scsipi_channel *,
671	    struct scsipi_periph *);
672struct scsipi_periph *scsipi_lookup_periph(struct scsipi_channel *,
673	    int, int);
674int	scsipi_target_detach(struct scsipi_channel *, int, int, int);
675
676int	scsipi_adapter_addref(struct scsipi_adapter *);
677void	scsipi_adapter_delref(struct scsipi_adapter *);
678
679void	scsipi_channel_freeze(struct scsipi_channel *, int);
680void	scsipi_channel_thaw(struct scsipi_channel *, int);
681void	scsipi_channel_timed_thaw(void *);
682
683void	scsipi_periph_freeze(struct scsipi_periph *, int);
684void	scsipi_periph_thaw(struct scsipi_periph *, int);
685void	scsipi_periph_timed_thaw(void *);
686
687int	scsipi_sync_period_to_factor(int);
688int	scsipi_sync_factor_to_period(int);
689int	scsipi_sync_factor_to_freq(int);
690
691void	show_scsipi_xs(struct scsipi_xfer *);
692void	show_scsipi_cmd(struct scsipi_xfer *);
693void	show_mem(u_char *, int);
694#endif /* _KERNEL */
695
696static __inline void
697_lto2b(u_int32_t val, u_int8_t *bytes)
698{
699
700	bytes[0] = (val >> 8) & 0xff;
701	bytes[1] = val & 0xff;
702}
703
704static __inline void
705_lto3b(u_int32_t val, u_int8_t *bytes)
706{
707
708	bytes[0] = (val >> 16) & 0xff;
709	bytes[1] = (val >> 8) & 0xff;
710	bytes[2] = val & 0xff;
711}
712
713static __inline void
714_lto4b(u_int32_t val, u_int8_t *bytes)
715{
716
717	bytes[0] = (val >> 24) & 0xff;
718	bytes[1] = (val >> 16) & 0xff;
719	bytes[2] = (val >> 8) & 0xff;
720	bytes[3] = val & 0xff;
721}
722
723static __inline void
724_lto8b(u_int64_t val, u_int8_t *bytes)
725{
726
727	bytes[0] = (val >> 56) & 0xff;
728	bytes[1] = (val >> 48) & 0xff;
729	bytes[2] = (val >> 40) & 0xff;
730	bytes[3] = (val >> 32) & 0xff;
731	bytes[4] = (val >> 24) & 0xff;
732	bytes[5] = (val >> 16) & 0xff;
733	bytes[6] = (val >> 8)  & 0xff;
734	bytes[7] = val         & 0xff;
735}
736
737static __inline u_int32_t
738_2btol(const u_int8_t *bytes)
739{
740	u_int32_t rv;
741
742	rv = (bytes[0] << 8) |
743	     bytes[1];
744	return (rv);
745}
746
747static __inline u_int32_t
748_3btol(const u_int8_t *bytes)
749{
750	u_int32_t rv;
751
752	rv = (bytes[0] << 16) |
753	     (bytes[1] << 8) |
754	     bytes[2];
755	return (rv);
756}
757
758static __inline u_int32_t
759_4btol(const u_int8_t *bytes)
760{
761	u_int32_t rv;
762
763	rv = (bytes[0] << 24) |
764	     (bytes[1] << 16) |
765	     (bytes[2] << 8) |
766	     bytes[3];
767	return (rv);
768}
769
770static __inline u_int64_t
771_5btol(const u_int8_t *bytes)
772{
773	u_int64_t rv;
774
775	rv = ((u_int64_t)bytes[0] << 32) |
776	     ((u_int64_t)bytes[1] << 24) |
777	     ((u_int64_t)bytes[2] << 16) |
778	     ((u_int64_t)bytes[3] << 8) |
779	     (u_int64_t)bytes[4];
780	return (rv);
781}
782
783static __inline u_int64_t
784_8btol(const u_int8_t *bytes)
785{
786	u_int64_t rv;
787
788	rv = ((u_int64_t)bytes[0] << 56) |
789	     ((u_int64_t)bytes[1] << 48) |
790	     ((u_int64_t)bytes[2] << 40) |
791	     ((u_int64_t)bytes[3] << 32) |
792	     ((u_int64_t)bytes[4] << 24) |
793	     ((u_int64_t)bytes[5] << 16) |
794	     ((u_int64_t)bytes[6] << 8) |
795	     (u_int64_t)bytes[7];
796	return (rv);
797}
798
799static __inline void
800_lto2l(u_int32_t val, u_int8_t *bytes)
801{
802
803	bytes[0] = val & 0xff;
804	bytes[1] = (val >> 8) & 0xff;
805}
806
807static __inline void
808_lto3l(u_int32_t val, u_int8_t *bytes)
809{
810
811	bytes[0] = val & 0xff;
812	bytes[1] = (val >> 8) & 0xff;
813	bytes[2] = (val >> 16) & 0xff;
814}
815
816static __inline void
817_lto4l(u_int32_t val, u_int8_t *bytes)
818{
819
820	bytes[0] = val & 0xff;
821	bytes[1] = (val >> 8) & 0xff;
822	bytes[2] = (val >> 16) & 0xff;
823	bytes[3] = (val >> 24) & 0xff;
824}
825
826static __inline u_int32_t
827_2ltol(const u_int8_t *bytes)
828{
829	u_int32_t rv;
830
831	rv = bytes[0] |
832	     (bytes[1] << 8);
833	return (rv);
834}
835
836static __inline u_int32_t
837_3ltol(const u_int8_t *bytes)
838{
839	u_int32_t rv;
840
841	rv = bytes[0] |
842	     (bytes[1] << 8) |
843	     (bytes[2] << 16);
844	return (rv);
845}
846
847static __inline u_int32_t
848_4ltol(const u_int8_t *bytes)
849{
850	u_int32_t rv;
851
852	rv = bytes[0] |
853	     (bytes[1] << 8) |
854	     (bytes[2] << 16) |
855	     (bytes[3] << 24);
856	return (rv);
857}
858
859#endif /* _DEV_SCSIPI_SCSIPICONF_H_ */