xref: /freebsd/sys/dev/ciss/cissvar.h (revision c61314601b8644dee2562d50700d8a87d7aca2e5)
13a31b7ebSMike Smith /*-
23a31b7ebSMike Smith  * Copyright (c) 2001 Michael Smith
33a31b7ebSMike Smith  * All rights reserved.
43a31b7ebSMike Smith  *
53a31b7ebSMike Smith  * Redistribution and use in source and binary forms, with or without
63a31b7ebSMike Smith  * modification, are permitted provided that the following conditions
73a31b7ebSMike Smith  * are met:
83a31b7ebSMike Smith  * 1. Redistributions of source code must retain the above copyright
93a31b7ebSMike Smith  *    notice, this list of conditions and the following disclaimer.
103a31b7ebSMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
113a31b7ebSMike Smith  *    notice, this list of conditions and the following disclaimer in the
123a31b7ebSMike Smith  *    documentation and/or other materials provided with the distribution.
133a31b7ebSMike Smith  *
143a31b7ebSMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
153a31b7ebSMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
163a31b7ebSMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
173a31b7ebSMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
183a31b7ebSMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
193a31b7ebSMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
203a31b7ebSMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
213a31b7ebSMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
223a31b7ebSMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
233a31b7ebSMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
243a31b7ebSMike Smith  * SUCH DAMAGE.
253a31b7ebSMike Smith  *
263a31b7ebSMike Smith  *	$FreeBSD$
273a31b7ebSMike Smith  */
283a31b7ebSMike Smith 
293a31b7ebSMike Smith /*
303a31b7ebSMike Smith  * CISS adapter driver datastructures
313a31b7ebSMike Smith  */
323a31b7ebSMike Smith 
333a31b7ebSMike Smith /************************************************************************
343a31b7ebSMike Smith  * Tunable parameters
353a31b7ebSMike Smith  */
363a31b7ebSMike Smith 
373a31b7ebSMike Smith /*
383a31b7ebSMike Smith  * There is no guaranteed upper bound on the number of concurrent
393a31b7ebSMike Smith  * commands an adapter may claim to support.  Cap it at a reasonable
403a31b7ebSMike Smith  * value.
413a31b7ebSMike Smith  */
423a31b7ebSMike Smith #define CISS_MAX_REQUESTS	256
433a31b7ebSMike Smith 
443a31b7ebSMike Smith /*
453a31b7ebSMike Smith  * Maximum number of logical drives we support.
463a31b7ebSMike Smith  */
473a31b7ebSMike Smith #define CISS_MAX_LOGICAL	15
483a31b7ebSMike Smith 
493a31b7ebSMike Smith /*
50c6131460SPaul Saab  * Maximum number of physical devices we support.
51c6131460SPaul Saab  */
52c6131460SPaul Saab #define CISS_MAX_PHYSICAL	1024
53c6131460SPaul Saab 
54c6131460SPaul Saab /*
553a31b7ebSMike Smith  * Interrupt reduction can be controlled by tuning the interrupt
563a31b7ebSMike Smith  * coalesce delay and count paramters.  The delay (in microseconds)
573a31b7ebSMike Smith  * defers delivery of interrupts to increase the chance of there being
583a31b7ebSMike Smith  * more than one completed command ready when the interrupt is
593a31b7ebSMike Smith  * delivered.  The count expedites the delivery of the interrupt when
603a31b7ebSMike Smith  * the given number of commands are ready.
613a31b7ebSMike Smith  *
623a31b7ebSMike Smith  * If the delay is set to 0, interrupts are delivered immediately.
633a31b7ebSMike Smith  */
643a31b7ebSMike Smith #define CISS_INTERRUPT_COALESCE_DELAY	1000
653a31b7ebSMike Smith #define CISS_INTERRUPT_COALESCE_COUNT	16
663a31b7ebSMike Smith 
673a31b7ebSMike Smith /*
683a31b7ebSMike Smith  * Heartbeat routine timeout in seconds.  Note that since event
693a31b7ebSMike Smith  * handling is performed on a callback basis, we don't need this to
703a31b7ebSMike Smith  * run very often.
713a31b7ebSMike Smith  */
723a31b7ebSMike Smith #define CISS_HEARTBEAT_RATE		10
733a31b7ebSMike Smith 
743a31b7ebSMike Smith /************************************************************************
75d3e4392cSMike Smith  * Compatibility with older versions of FreeBSD
76d3e4392cSMike Smith  */
77d3e4392cSMike Smith #if __FreeBSD_version < 440001
78d3e4392cSMike Smith #warning testing old-FreeBSD compat
79d3e4392cSMike Smith typedef struct proc	d_thread_t;
80d3e4392cSMike Smith #endif
81d3e4392cSMike Smith 
82d3e4392cSMike Smith /************************************************************************
833a31b7ebSMike Smith  * Command queue statistics
843a31b7ebSMike Smith  */
853a31b7ebSMike Smith 
863a31b7ebSMike Smith #define CISSQ_FREE	0
873a31b7ebSMike Smith #define CISSQ_BUSY	1
883a31b7ebSMike Smith #define CISSQ_COMPLETE	2
89c6131460SPaul Saab #define CISSQ_NOTIFY	3
90c6131460SPaul Saab #define CISSQ_COUNT	4
913a31b7ebSMike Smith 
923a31b7ebSMike Smith struct ciss_qstat
933a31b7ebSMike Smith {
943a31b7ebSMike Smith     u_int32_t	q_length;
953a31b7ebSMike Smith     u_int32_t	q_max;
963a31b7ebSMike Smith };
973a31b7ebSMike Smith 
983a31b7ebSMike Smith /************************************************************************
993a31b7ebSMike Smith  * Driver version.  Only really significant to the ACU interface.
1003a31b7ebSMike Smith  */
101d3e4392cSMike Smith #define CISS_DRIVER_VERSION	20011201
1023a31b7ebSMike Smith 
1033a31b7ebSMike Smith /************************************************************************
1043a31b7ebSMike Smith  * Driver data structures
1053a31b7ebSMike Smith  */
1063a31b7ebSMike Smith 
1073a31b7ebSMike Smith /*
1083a31b7ebSMike Smith  * Each command issued to the adapter is managed by a request
1093a31b7ebSMike Smith  * structure.
1103a31b7ebSMike Smith  */
1113a31b7ebSMike Smith struct ciss_request
1123a31b7ebSMike Smith {
1133a31b7ebSMike Smith     TAILQ_ENTRY(ciss_request)	cr_link;
1143a31b7ebSMike Smith     int				cr_onq;		/* which queue we are on */
1153a31b7ebSMike Smith 
1163a31b7ebSMike Smith     struct ciss_softc		*cr_sc;		/* controller softc */
1173a31b7ebSMike Smith     void			*cr_data;	/* data buffer */
1183a31b7ebSMike Smith     u_int32_t			cr_length;	/* data length */
1193a31b7ebSMike Smith     bus_dmamap_t		cr_datamap;	/* DMA map for data */
1203a31b7ebSMike Smith     int				cr_tag;
1213a31b7ebSMike Smith     int				cr_flags;
1223a31b7ebSMike Smith #define CISS_REQ_MAPPED		(1<<0)		/* data mapped */
1233a31b7ebSMike Smith #define CISS_REQ_SLEEP		(1<<1)		/* submitter sleeping */
1243a31b7ebSMike Smith #define CISS_REQ_POLL		(1<<2)		/* submitter polling */
1253a31b7ebSMike Smith #define CISS_REQ_DATAOUT	(1<<3)		/* data host->adapter */
1263a31b7ebSMike Smith #define CISS_REQ_DATAIN		(1<<4)		/* data adapter->host */
1273a31b7ebSMike Smith 
1283a31b7ebSMike Smith     void			(* cr_complete)(struct ciss_request *);
1293a31b7ebSMike Smith     void			*cr_private;
1303a31b7ebSMike Smith };
1313a31b7ebSMike Smith 
1323a31b7ebSMike Smith /*
1333a31b7ebSMike Smith  * The adapter command structure is defined with a zero-length
1343a31b7ebSMike Smith  * scatter/gather list size.  In practise, we want space for a
1353a31b7ebSMike Smith  * scatter-gather list, and we also want to avoid having commands
1363a31b7ebSMike Smith  * cross page boundaries.
1373a31b7ebSMike Smith  *
1383a31b7ebSMike Smith  * Note that 512 bytes yields 28 scatter/gather entries, or the
1393a31b7ebSMike Smith  * ability to map (26 * PAGE_SIZE) + 2 bytes of data.  On x86, this is
1403a31b7ebSMike Smith  * 104kB.  256 bytes would only yield 12 entries, giving a mere 40kB,
1413a31b7ebSMike Smith  * too small.
1423a31b7ebSMike Smith  */
1433a31b7ebSMike Smith 
1443a31b7ebSMike Smith #define CISS_COMMAND_ALLOC_SIZE		512	/* XXX tune to get sensible s/g list length */
1453a31b7ebSMike Smith #define CISS_COMMAND_SG_LENGTH	((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \
1463a31b7ebSMike Smith 				 / sizeof(struct ciss_sg_entry))
1473a31b7ebSMike Smith 
1483a31b7ebSMike Smith /*
1493a31b7ebSMike Smith  * Per-logical-drive data.
1503a31b7ebSMike Smith  */
1513a31b7ebSMike Smith struct ciss_ldrive
1523a31b7ebSMike Smith {
1533a31b7ebSMike Smith     union ciss_device_address	cl_address;
154c6131460SPaul Saab     union ciss_device_address	*cl_controller;
1553a31b7ebSMike Smith     int				cl_status;
1563a31b7ebSMike Smith #define CISS_LD_NONEXISTENT	0
1573a31b7ebSMike Smith #define CISS_LD_ONLINE		1
1583a31b7ebSMike Smith #define CISS_LD_OFFLINE		2
1593a31b7ebSMike Smith 
160c6131460SPaul Saab     int				cl_update;
161c6131460SPaul Saab 
1623a31b7ebSMike Smith     struct ciss_bmic_id_ldrive	*cl_ldrive;
1633a31b7ebSMike Smith     struct ciss_bmic_id_lstatus	*cl_lstatus;
164440baa08SPaul Saab     struct ciss_ldrive_geometry	cl_geometry;
1653a31b7ebSMike Smith 
1663a31b7ebSMike Smith     char			cl_name[16];		/* device name */
1673a31b7ebSMike Smith };
1683a31b7ebSMike Smith 
1693a31b7ebSMike Smith /*
1703a31b7ebSMike Smith  * Per-adapter data
1713a31b7ebSMike Smith  */
1723a31b7ebSMike Smith struct ciss_softc
1733a31b7ebSMike Smith {
1743a31b7ebSMike Smith     /* bus connections */
1753a31b7ebSMike Smith     device_t			ciss_dev;		/* bus attachment */
1763a31b7ebSMike Smith     dev_t			ciss_dev_t;		/* control device */
1773a31b7ebSMike Smith 
1783a31b7ebSMike Smith     struct resource		*ciss_regs_resource;	/* register interface window */
1793a31b7ebSMike Smith     int				ciss_regs_rid;		/* resource ID */
1803a31b7ebSMike Smith     bus_space_handle_t		ciss_regs_bhandle;	/* bus space handle */
1813a31b7ebSMike Smith     bus_space_tag_t		ciss_regs_btag;		/* bus space tag */
1823a31b7ebSMike Smith 
1833a31b7ebSMike Smith     struct resource		*ciss_cfg_resource;	/* config struct interface window */
1843a31b7ebSMike Smith     int				ciss_cfg_rid;		/* resource ID */
1853a31b7ebSMike Smith     struct ciss_config_table	*ciss_cfg;		/* config table in adapter memory */
1863a31b7ebSMike Smith     struct ciss_bmic_id_table	*ciss_id;		/* ID table in host memory */
1873a31b7ebSMike Smith     u_int32_t			ciss_heartbeat;		/* last heartbeat value */
1883a31b7ebSMike Smith     int				ciss_heart_attack;	/* number of times we have seen this value */
1893a31b7ebSMike Smith 
1903a31b7ebSMike Smith     struct resource		*ciss_irq_resource;	/* interrupt */
1913a31b7ebSMike Smith     int				ciss_irq_rid;		/* resource ID */
1923a31b7ebSMike Smith     void			*ciss_intr;		/* interrupt handle */
1933a31b7ebSMike Smith 
1943a31b7ebSMike Smith     bus_dma_tag_t		ciss_parent_dmat;	/* parent DMA tag */
1953a31b7ebSMike Smith     bus_dma_tag_t		ciss_buffer_dmat;	/* data buffer/command DMA tag */
1963a31b7ebSMike Smith 
1973a31b7ebSMike Smith     u_int32_t			ciss_interrupt_mask;	/* controller interrupt mask bits */
1983a31b7ebSMike Smith 
1993a31b7ebSMike Smith     int				ciss_max_requests;
2003a31b7ebSMike Smith     struct ciss_request		ciss_request[CISS_MAX_REQUESTS];	/* requests */
2013a31b7ebSMike Smith     void			*ciss_command;		/* command structures */
2023a31b7ebSMike Smith     bus_dma_tag_t		ciss_command_dmat;	/* command DMA tag */
2033a31b7ebSMike Smith     bus_dmamap_t		ciss_command_map;	/* command DMA map */
2043a31b7ebSMike Smith     u_int32_t			ciss_command_phys;	/* command array base address */
2053a31b7ebSMike Smith     TAILQ_HEAD(,ciss_request)	ciss_free;		/* requests available for reuse */
2063a31b7ebSMike Smith     TAILQ_HEAD(,ciss_request)	ciss_busy;		/* requests in the adapter */
2073a31b7ebSMike Smith     TAILQ_HEAD(,ciss_request)	ciss_complete;		/* requests which have been returned by the adapter */
208c6131460SPaul Saab     TAILQ_HEAD(,ciss_request)	ciss_notify;		/* requests which are defered for processing */
209c6131460SPaul Saab     struct proc			*ciss_notify_thread;
2103a31b7ebSMike Smith 
2113a31b7ebSMike Smith     struct callout_handle	ciss_periodic;		/* periodic event handling */
2123a31b7ebSMike Smith     struct ciss_request		*ciss_periodic_notify;	/* notify callback request */
2133a31b7ebSMike Smith 
214c6131460SPaul Saab     struct ciss_ldrive		**ciss_logical;
215c6131460SPaul Saab     union ciss_device_address	*ciss_controllers;	/* controller address */
216c6131460SPaul Saab     int				ciss_max_bus_number;	/* maximum bus number */
2173a31b7ebSMike Smith 
2183a31b7ebSMike Smith     struct cam_devq		*ciss_cam_devq;
219c6131460SPaul Saab     struct cam_sim		**ciss_cam_sim;
2203a31b7ebSMike Smith 
2213a31b7ebSMike Smith     int				ciss_flags;
2223a31b7ebSMike Smith #define CISS_FLAG_NOTIFY_OK	(1<<0)		/* notify command running OK */
2233a31b7ebSMike Smith #define CISS_FLAG_CONTROL_OPEN	(1<<1)		/* control device is open */
2243a31b7ebSMike Smith #define CISS_FLAG_ABORTING	(1<<2)		/* driver is going away */
2253a31b7ebSMike Smith #define CISS_FLAG_RUNNING	(1<<3)		/* driver is running (interrupts usable) */
2263a31b7ebSMike Smith 
2273a31b7ebSMike Smith #define CISS_FLAG_FAKE_SYNCH	(1<<16)		/* needs SYNCHRONISE_CACHE faked */
2283a31b7ebSMike Smith #define CISS_FLAG_BMIC_ABORT	(1<<17)		/* use BMIC command to abort Notify on Event */
229c6131460SPaul Saab #define CISS_FLAG_THREAD_SHUT	(1<<20)		/* shutdown the kthread */
2303a31b7ebSMike Smith 
2313a31b7ebSMike Smith     struct ciss_qstat		ciss_qstat[CISSQ_COUNT];	/* queue statistics */
2323a31b7ebSMike Smith };
2333a31b7ebSMike Smith 
2343a31b7ebSMike Smith /*
2353a31b7ebSMike Smith  * Given a request tag, find the corresponding command in virtual or
2363a31b7ebSMike Smith  * physical space.
2373a31b7ebSMike Smith  *
2383a31b7ebSMike Smith  * The arithmetic here is due to the allocation of ciss_command structures
2393a31b7ebSMike Smith  * inside CISS_COMMAND_ALLOC_SIZE blocks.  See the comment at the definition
2403a31b7ebSMike Smith  * of CISS_COMMAND_ALLOC_SIZE above.
2413a31b7ebSMike Smith  */
2423a31b7ebSMike Smith #define CISS_FIND_COMMAND(cr)							\
2433a31b7ebSMike Smith 	(struct ciss_command *)((u_int8_t *)(cr)->cr_sc->ciss_command +		\
2443a31b7ebSMike Smith 				((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
2453a31b7ebSMike Smith #define CISS_FIND_COMMANDPHYS(cr)	((cr)->cr_sc->ciss_command_phys + \
2463a31b7ebSMike Smith 					 ((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
2473a31b7ebSMike Smith 
2483a31b7ebSMike Smith /************************************************************************
2493a31b7ebSMike Smith  * Debugging/diagnostic output.
2503a31b7ebSMike Smith  */
2513a31b7ebSMike Smith 
2523a31b7ebSMike Smith /*
2533a31b7ebSMike Smith  * Debugging levels:
2543a31b7ebSMike Smith  *  0 - quiet, only emit warnings
2553a31b7ebSMike Smith  *  1 - talkative, log major events, but nothing on the I/O path
2563a31b7ebSMike Smith  *  2 - noisy, log events on the I/O path
2573a31b7ebSMike Smith  *  3 - extremely noisy, log items in loops
2583a31b7ebSMike Smith  */
2593a31b7ebSMike Smith #ifdef CISS_DEBUG
2603a31b7ebSMike Smith # define debug(level, fmt, args...)							\
2613a31b7ebSMike Smith 	do {										\
2626e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);	\
2633a31b7ebSMike Smith 	} while(0)
2643a31b7ebSMike Smith # define debug_called(level)						\
2653a31b7ebSMike Smith 	do {								\
2666e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: called\n", __func__);	\
2673a31b7ebSMike Smith 	} while(0)
2684caad4e8SMaxime Henrion # define debug_struct(s)		printf("  SIZE %s: %zu\n", #s, sizeof(struct s))
2694caad4e8SMaxime Henrion # define debug_union(s)			printf("  SIZE %s: %zu\n", #s, sizeof(union s))
2704caad4e8SMaxime Henrion # define debug_type(s)			printf("  SIZE %s: %zu\n", #s, sizeof(s))
2713a31b7ebSMike Smith # define debug_field(s, f)		printf("  OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
2724caad4e8SMaxime Henrion # define debug_const(c)			printf("  CONST %s %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c);
2733a31b7ebSMike Smith #else
2743a31b7ebSMike Smith # define debug(level, fmt, args...)
2753a31b7ebSMike Smith # define debug_called(level)
2763a31b7ebSMike Smith # define debug_struct(s)
2773a31b7ebSMike Smith # define debug_union(s)
2783a31b7ebSMike Smith # define debug_type(s)
2793a31b7ebSMike Smith # define debug_field(s, f)
2803a31b7ebSMike Smith # define debug_const(c)
2813a31b7ebSMike Smith #endif
2823a31b7ebSMike Smith 
2833a31b7ebSMike Smith #define ciss_printf(sc, fmt, args...)	device_printf(sc->ciss_dev, fmt , ##args)
2843a31b7ebSMike Smith 
2853a31b7ebSMike Smith /************************************************************************
2863a31b7ebSMike Smith  * Queue primitives
2873a31b7ebSMike Smith  */
2883a31b7ebSMike Smith 
2893a31b7ebSMike Smith #define CISSQ_ADD(sc, qname)					\
2903a31b7ebSMike Smith 	do {							\
2913a31b7ebSMike Smith 	    struct ciss_qstat *qs = &(sc)->ciss_qstat[qname];	\
2923a31b7ebSMike Smith 								\
2933a31b7ebSMike Smith 	    qs->q_length++;					\
2943a31b7ebSMike Smith 	    if (qs->q_length > qs->q_max)			\
2953a31b7ebSMike Smith 		qs->q_max = qs->q_length;			\
2963a31b7ebSMike Smith 	} while(0)
2973a31b7ebSMike Smith 
2983a31b7ebSMike Smith #define CISSQ_REMOVE(sc, qname)    (sc)->ciss_qstat[qname].q_length--
2993a31b7ebSMike Smith #define CISSQ_INIT(sc, qname)			\
3003a31b7ebSMike Smith 	do {					\
3013a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_length = 0;	\
3023a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_max = 0;	\
3033a31b7ebSMike Smith 	} while(0)
3043a31b7ebSMike Smith 
3053a31b7ebSMike Smith 
3063a31b7ebSMike Smith #define CISSQ_REQUEST_QUEUE(name, index)				\
3073a31b7ebSMike Smith static __inline void							\
3083a31b7ebSMike Smith ciss_initq_ ## name (struct ciss_softc *sc)				\
3093a31b7ebSMike Smith {									\
3103a31b7ebSMike Smith     TAILQ_INIT(&sc->ciss_ ## name);					\
3113a31b7ebSMike Smith     CISSQ_INIT(sc, index);						\
3123a31b7ebSMike Smith }									\
3133a31b7ebSMike Smith static __inline void							\
3143a31b7ebSMike Smith ciss_enqueue_ ## name (struct ciss_request *cr)				\
3153a31b7ebSMike Smith {									\
3163a31b7ebSMike Smith     int		s;							\
3173a31b7ebSMike Smith 									\
3183a31b7ebSMike Smith     s = splcam();							\
3193a31b7ebSMike Smith     TAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3203a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3213a31b7ebSMike Smith     cr->cr_onq = index;							\
3223a31b7ebSMike Smith     splx(s);								\
3233a31b7ebSMike Smith }									\
3243a31b7ebSMike Smith static __inline void							\
3253a31b7ebSMike Smith ciss_requeue_ ## name (struct ciss_request *cr)				\
3263a31b7ebSMike Smith {									\
3273a31b7ebSMike Smith     int		s;							\
3283a31b7ebSMike Smith 									\
3293a31b7ebSMike Smith     s = splcam();							\
3303a31b7ebSMike Smith     TAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3313a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3323a31b7ebSMike Smith     cr->cr_onq = index;							\
3333a31b7ebSMike Smith     splx(s);								\
3343a31b7ebSMike Smith }									\
3353a31b7ebSMike Smith static __inline struct ciss_request *					\
3363a31b7ebSMike Smith ciss_dequeue_ ## name (struct ciss_softc *sc)				\
3373a31b7ebSMike Smith {									\
3383a31b7ebSMike Smith     struct ciss_request	*cr;						\
3393a31b7ebSMike Smith     int			s;						\
3403a31b7ebSMike Smith 									\
3413a31b7ebSMike Smith     s = splcam();							\
3423a31b7ebSMike Smith     if ((cr = TAILQ_FIRST(&sc->ciss_ ## name)) != NULL) {		\
3433a31b7ebSMike Smith 	TAILQ_REMOVE(&sc->ciss_ ## name, cr, cr_link);			\
3443a31b7ebSMike Smith 	CISSQ_REMOVE(sc, index);					\
3453a31b7ebSMike Smith 	cr->cr_onq = -1;						\
3463a31b7ebSMike Smith     }									\
3473a31b7ebSMike Smith     splx(s);								\
3483a31b7ebSMike Smith     return(cr);								\
3493a31b7ebSMike Smith }									\
3503a31b7ebSMike Smith static __inline int							\
3513a31b7ebSMike Smith ciss_remove_ ## name (struct ciss_request *cr)				\
3523a31b7ebSMike Smith {									\
3533a31b7ebSMike Smith     int			s, error;					\
3543a31b7ebSMike Smith 									\
3553a31b7ebSMike Smith     s = splcam();							\
3563a31b7ebSMike Smith     if (cr->cr_onq != index) {						\
3573a31b7ebSMike Smith 	printf("request on queue %d (expected %d)\n", cr->cr_onq, index);\
3583a31b7ebSMike Smith 	error = 1;							\
3593a31b7ebSMike Smith     } else {								\
3603a31b7ebSMike Smith 	TAILQ_REMOVE(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3613a31b7ebSMike Smith 	CISSQ_REMOVE(cr->cr_sc, index);					\
3623a31b7ebSMike Smith 	cr->cr_onq = -1;						\
3633a31b7ebSMike Smith 	error = 0;							\
3643a31b7ebSMike Smith     }									\
3653a31b7ebSMike Smith     splx(s);								\
3663a31b7ebSMike Smith     return(error);							\
3673a31b7ebSMike Smith }									\
3683a31b7ebSMike Smith struct hack
3693a31b7ebSMike Smith 
3703a31b7ebSMike Smith CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
3713a31b7ebSMike Smith CISSQ_REQUEST_QUEUE(busy, CISSQ_BUSY);
3723a31b7ebSMike Smith CISSQ_REQUEST_QUEUE(complete, CISSQ_COMPLETE);
373c6131460SPaul Saab CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);
3743a31b7ebSMike Smith 
3753a31b7ebSMike Smith /********************************************************************************
3763a31b7ebSMike Smith  * space-fill a character string
3773a31b7ebSMike Smith  */
3783a31b7ebSMike Smith static __inline void
3793a31b7ebSMike Smith padstr(char *targ, const char *src, int len)
3803a31b7ebSMike Smith {
3813a31b7ebSMike Smith     while (len-- > 0) {
3823a31b7ebSMike Smith 	if (*src != 0) {
3833a31b7ebSMike Smith 	    *targ++ = *src++;
3843a31b7ebSMike Smith 	} else {
3853a31b7ebSMike Smith 	    *targ++ = ' ';
3863a31b7ebSMike Smith 	}
3873a31b7ebSMike Smith     }
3883a31b7ebSMike Smith }
389