xref: /freebsd/sys/dev/ciss/cissvar.h (revision e3edca225f8a351b267d04bff0d9a0862d369f0b)
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 
3322657ce1SScott Long typedef STAILQ_HEAD(, ciss_request)	cr_qhead_t;
3422657ce1SScott Long 
353a31b7ebSMike Smith /************************************************************************
363a31b7ebSMike Smith  * Tunable parameters
373a31b7ebSMike Smith  */
383a31b7ebSMike Smith 
393a31b7ebSMike Smith /*
403a31b7ebSMike Smith  * There is no guaranteed upper bound on the number of concurrent
413a31b7ebSMike Smith  * commands an adapter may claim to support.  Cap it at a reasonable
423a31b7ebSMike Smith  * value.
433a31b7ebSMike Smith  */
4495dab4f2SAlexander Motin #define CISS_MAX_REQUESTS	1024
453a31b7ebSMike Smith 
463a31b7ebSMike Smith /*
473a31b7ebSMike Smith  * Maximum number of logical drives we support.
48*e3edca22SSean Bruno  * If the controller does not indicate a maximum
49*e3edca22SSean Bruno  * value.  This is a compatibiliy value to support
50*e3edca22SSean Bruno  * older ciss controllers (e.g. model 6i)
513a31b7ebSMike Smith  */
52*e3edca22SSean Bruno #define CISS_MAX_LOGICAL	16
533a31b7ebSMike Smith 
543a31b7ebSMike Smith /*
55c6131460SPaul Saab  * Maximum number of physical devices we support.
56c6131460SPaul Saab  */
57c6131460SPaul Saab #define CISS_MAX_PHYSICAL	1024
58c6131460SPaul Saab 
59c6131460SPaul Saab /*
603a31b7ebSMike Smith  * Interrupt reduction can be controlled by tuning the interrupt
613a31b7ebSMike Smith  * coalesce delay and count paramters.  The delay (in microseconds)
623a31b7ebSMike Smith  * defers delivery of interrupts to increase the chance of there being
633a31b7ebSMike Smith  * more than one completed command ready when the interrupt is
643a31b7ebSMike Smith  * delivered.  The count expedites the delivery of the interrupt when
653a31b7ebSMike Smith  * the given number of commands are ready.
663a31b7ebSMike Smith  *
673a31b7ebSMike Smith  * If the delay is set to 0, interrupts are delivered immediately.
683a31b7ebSMike Smith  */
6922657ce1SScott Long #define CISS_INTERRUPT_COALESCE_DELAY	0
703a31b7ebSMike Smith #define CISS_INTERRUPT_COALESCE_COUNT	16
713a31b7ebSMike Smith 
723a31b7ebSMike Smith /*
733a31b7ebSMike Smith  * Heartbeat routine timeout in seconds.  Note that since event
743a31b7ebSMike Smith  * handling is performed on a callback basis, we don't need this to
753a31b7ebSMike Smith  * run very often.
763a31b7ebSMike Smith  */
773a31b7ebSMike Smith #define CISS_HEARTBEAT_RATE		10
783a31b7ebSMike Smith 
793a31b7ebSMike Smith /************************************************************************
80d3e4392cSMike Smith  * Compatibility with older versions of FreeBSD
81d3e4392cSMike Smith  */
82d3e4392cSMike Smith #if __FreeBSD_version < 440001
83d3e4392cSMike Smith #warning testing old-FreeBSD compat
84d3e4392cSMike Smith typedef struct proc	d_thread_t;
85d3e4392cSMike Smith #endif
86d3e4392cSMike Smith 
87d3e4392cSMike Smith /************************************************************************
883a31b7ebSMike Smith  * Driver version.  Only really significant to the ACU interface.
893a31b7ebSMike Smith  */
90d3e4392cSMike Smith #define CISS_DRIVER_VERSION	20011201
913a31b7ebSMike Smith 
923a31b7ebSMike Smith /************************************************************************
933a31b7ebSMike Smith  * Driver data structures
943a31b7ebSMike Smith  */
953a31b7ebSMike Smith 
963a31b7ebSMike Smith /*
973a31b7ebSMike Smith  * Each command issued to the adapter is managed by a request
983a31b7ebSMike Smith  * structure.
993a31b7ebSMike Smith  */
1003a31b7ebSMike Smith struct ciss_request
1013a31b7ebSMike Smith {
10222657ce1SScott Long     STAILQ_ENTRY(ciss_request)	cr_link;
1033a31b7ebSMike Smith     int				cr_onq;		/* which queue we are on */
1043a31b7ebSMike Smith 
1053a31b7ebSMike Smith     struct ciss_softc		*cr_sc;		/* controller softc */
1063a31b7ebSMike Smith     void			*cr_data;	/* data buffer */
1073a31b7ebSMike Smith     u_int32_t			cr_length;	/* data length */
1083a31b7ebSMike Smith     bus_dmamap_t		cr_datamap;	/* DMA map for data */
1092fdaa90dSScott Long     struct ciss_command		*cr_cc;
1102fdaa90dSScott Long     uint32_t			cr_ccphys;
1113a31b7ebSMike Smith     int				cr_tag;
1123a31b7ebSMike Smith     int				cr_flags;
1133a31b7ebSMike Smith #define CISS_REQ_MAPPED		(1<<0)		/* data mapped */
1143a31b7ebSMike Smith #define CISS_REQ_SLEEP		(1<<1)		/* submitter sleeping */
1153a31b7ebSMike Smith #define CISS_REQ_POLL		(1<<2)		/* submitter polling */
1163a31b7ebSMike Smith #define CISS_REQ_DATAOUT	(1<<3)		/* data host->adapter */
1173a31b7ebSMike Smith #define CISS_REQ_DATAIN		(1<<4)		/* data adapter->host */
11822657ce1SScott Long #define CISS_REQ_BUSY		(1<<5)		/* controller has req */
1193a31b7ebSMike Smith 
1203a31b7ebSMike Smith     void			(* cr_complete)(struct ciss_request *);
1213a31b7ebSMike Smith     void			*cr_private;
12222657ce1SScott Long     int				cr_sg_tag;
12322657ce1SScott Long #define CISS_SG_MAX		((CISS_SG_FETCH_MAX << 1) | 0x1)
12422657ce1SScott Long #define CISS_SG_1		((CISS_SG_FETCH_1 << 1) | 0x01)
12522657ce1SScott Long #define CISS_SG_2		((CISS_SG_FETCH_2 << 1) | 0x01)
12622657ce1SScott Long #define CISS_SG_4		((CISS_SG_FETCH_4 << 1) | 0x01)
12722657ce1SScott Long #define CISS_SG_8		((CISS_SG_FETCH_8 << 1) | 0x01)
12822657ce1SScott Long #define CISS_SG_16		((CISS_SG_FETCH_16 << 1) | 0x01)
12922657ce1SScott Long #define CISS_SG_32		((CISS_SG_FETCH_32 << 1) | 0x01)
13022657ce1SScott Long #define CISS_SG_NONE		((CISS_SG_FETCH_NONE << 1) | 0x01)
1313a31b7ebSMike Smith };
1323a31b7ebSMike Smith 
1333a31b7ebSMike Smith /*
1343a31b7ebSMike Smith  * The adapter command structure is defined with a zero-length
1353a31b7ebSMike Smith  * scatter/gather list size.  In practise, we want space for a
1363a31b7ebSMike Smith  * scatter-gather list, and we also want to avoid having commands
1373a31b7ebSMike Smith  * cross page boundaries.
1383a31b7ebSMike Smith  *
1392fdaa90dSScott Long  * The size of the ciss_command is 52 bytes.  65 s/g elements are reserved
1402fdaa90dSScott Long  * to allow a max i/o size of 256k.  This gives a total command size of
1412fdaa90dSScott Long  * 1120 bytes, including the 32 byte alignment padding.  Modern controllers
1422fdaa90dSScott Long  * seem to saturate nicely at this value.
1433a31b7ebSMike Smith  */
1443a31b7ebSMike Smith 
1452fdaa90dSScott Long #define CISS_MAX_SG_ELEMENTS	65
1462fdaa90dSScott Long #define CISS_COMMAND_ALIGN	32
1472fdaa90dSScott Long #define CISS_COMMAND_SG_LENGTH	(sizeof(struct ciss_sg_entry) * CISS_MAX_SG_ELEMENTS)
1482fdaa90dSScott Long #define CISS_COMMAND_ALLOC_SIZE		(roundup2(sizeof(struct ciss_command) + CISS_COMMAND_SG_LENGTH, CISS_COMMAND_ALIGN))
14952c9ce25SScott Long 
1503a31b7ebSMike Smith /*
1513a31b7ebSMike Smith  * Per-logical-drive data.
1523a31b7ebSMike Smith  */
1533a31b7ebSMike Smith struct ciss_ldrive
1543a31b7ebSMike Smith {
1553a31b7ebSMike Smith     union ciss_device_address	cl_address;
156c6131460SPaul Saab     union ciss_device_address	*cl_controller;
1573a31b7ebSMike Smith     int				cl_status;
1583a31b7ebSMike Smith #define CISS_LD_NONEXISTENT	0
1593a31b7ebSMike Smith #define CISS_LD_ONLINE		1
1603a31b7ebSMike Smith #define CISS_LD_OFFLINE		2
1613a31b7ebSMike Smith 
162c6131460SPaul Saab     int				cl_update;
163c6131460SPaul Saab 
1643a31b7ebSMike Smith     struct ciss_bmic_id_ldrive	*cl_ldrive;
1653a31b7ebSMike Smith     struct ciss_bmic_id_lstatus	*cl_lstatus;
166440baa08SPaul Saab     struct ciss_ldrive_geometry	cl_geometry;
1673a31b7ebSMike Smith 
1683a31b7ebSMike Smith     char			cl_name[16];		/* device name */
1693a31b7ebSMike Smith };
1703a31b7ebSMike Smith 
1713a31b7ebSMike Smith /*
1721fe6c4eeSScott Long  * Per-physical-drive data
1731fe6c4eeSScott Long  */
1741fe6c4eeSScott Long struct ciss_pdrive
1751fe6c4eeSScott Long {
1761fe6c4eeSScott Long     union ciss_device_address	cp_address;
1771fe6c4eeSScott Long     int				cp_online;
1781fe6c4eeSScott Long };
1791fe6c4eeSScott Long 
1801fe6c4eeSScott Long #define CISS_PHYSICAL_SHIFT	5
1811fe6c4eeSScott Long #define CISS_PHYSICAL_BASE	(1 << CISS_PHYSICAL_SHIFT)
182c7241f65SScott Long #define CISS_MAX_PHYSTGT	256
1831fe6c4eeSScott Long 
1841fe6c4eeSScott Long #define CISS_IS_PHYSICAL(bus)	(bus >= CISS_PHYSICAL_BASE)
1851fe6c4eeSScott Long #define CISS_CAM_TO_PBUS(bus)	(bus - CISS_PHYSICAL_BASE)
1861fe6c4eeSScott Long 
1871fe6c4eeSScott Long /*
1883a31b7ebSMike Smith  * Per-adapter data
1893a31b7ebSMike Smith  */
1903a31b7ebSMike Smith struct ciss_softc
1913a31b7ebSMike Smith {
1923a31b7ebSMike Smith     /* bus connections */
1933a31b7ebSMike Smith     device_t			ciss_dev;		/* bus attachment */
19489c9c53dSPoul-Henning Kamp     struct cdev *ciss_dev_t;		/* control device */
1953a31b7ebSMike Smith 
1963a31b7ebSMike Smith     struct resource		*ciss_regs_resource;	/* register interface window */
1973a31b7ebSMike Smith     int				ciss_regs_rid;		/* resource ID */
1983a31b7ebSMike Smith     bus_space_handle_t		ciss_regs_bhandle;	/* bus space handle */
1993a31b7ebSMike Smith     bus_space_tag_t		ciss_regs_btag;		/* bus space tag */
2003a31b7ebSMike Smith 
2013a31b7ebSMike Smith     struct resource		*ciss_cfg_resource;	/* config struct interface window */
2023a31b7ebSMike Smith     int				ciss_cfg_rid;		/* resource ID */
2033a31b7ebSMike Smith     struct ciss_config_table	*ciss_cfg;		/* config table in adapter memory */
20422657ce1SScott Long     struct ciss_perf_config	*ciss_perf;		/* config table for the performant */
2053a31b7ebSMike Smith     struct ciss_bmic_id_table	*ciss_id;		/* ID table in host memory */
2063a31b7ebSMike Smith     u_int32_t			ciss_heartbeat;		/* last heartbeat value */
2073a31b7ebSMike Smith     int				ciss_heart_attack;	/* number of times we have seen this value */
2083a31b7ebSMike Smith 
20922657ce1SScott Long     int				ciss_msi;
2103a31b7ebSMike Smith     struct resource		*ciss_irq_resource;	/* interrupt */
21122657ce1SScott Long     int				ciss_irq_rid[CISS_MSI_COUNT];		/* resource ID */
2123a31b7ebSMike Smith     void			*ciss_intr;		/* interrupt handle */
2133a31b7ebSMike Smith 
2143a31b7ebSMike Smith     bus_dma_tag_t		ciss_parent_dmat;	/* parent DMA tag */
2153a31b7ebSMike Smith     bus_dma_tag_t		ciss_buffer_dmat;	/* data buffer/command DMA tag */
2163a31b7ebSMike Smith 
2173a31b7ebSMike Smith     u_int32_t			ciss_interrupt_mask;	/* controller interrupt mask bits */
2183a31b7ebSMike Smith 
21922657ce1SScott Long     uint64_t			*ciss_reply;
22022657ce1SScott Long     int				ciss_cycle;
22122657ce1SScott Long     int				ciss_rqidx;
22222657ce1SScott Long     bus_dma_tag_t		ciss_reply_dmat;
22322657ce1SScott Long     bus_dmamap_t		ciss_reply_map;
22422657ce1SScott Long     uint32_t			ciss_reply_phys;
22522657ce1SScott Long 
2263a31b7ebSMike Smith     int				ciss_max_requests;
2273a31b7ebSMike Smith     struct ciss_request		ciss_request[CISS_MAX_REQUESTS];	/* requests */
2283a31b7ebSMike Smith     void			*ciss_command;		/* command structures */
2293a31b7ebSMike Smith     bus_dma_tag_t		ciss_command_dmat;	/* command DMA tag */
2303a31b7ebSMike Smith     bus_dmamap_t		ciss_command_map;	/* command DMA map */
2313a31b7ebSMike Smith     u_int32_t			ciss_command_phys;	/* command array base address */
23222657ce1SScott Long     cr_qhead_t			ciss_free;		/* requests available for reuse */
23322657ce1SScott Long     cr_qhead_t			ciss_notify;		/* requests which are defered for processing */
234c6131460SPaul Saab     struct proc			*ciss_notify_thread;
2353a31b7ebSMike Smith 
236975b7318SScott Long     struct callout		ciss_periodic;		/* periodic event handling */
2373a31b7ebSMike Smith     struct ciss_request		*ciss_periodic_notify;	/* notify callback request */
2383a31b7ebSMike Smith 
239975b7318SScott Long     struct mtx			ciss_mtx;
240c6131460SPaul Saab     struct ciss_ldrive		**ciss_logical;
2411fe6c4eeSScott Long     struct ciss_pdrive		**ciss_physical;
242c6131460SPaul Saab     union ciss_device_address	*ciss_controllers;	/* controller address */
243c6131460SPaul Saab     int				ciss_max_bus_number;	/* maximum bus number */
2441fe6c4eeSScott Long     int				ciss_max_logical_bus;
2451fe6c4eeSScott Long     int				ciss_max_physical_bus;
2463a31b7ebSMike Smith 
2473a31b7ebSMike Smith     struct cam_devq		*ciss_cam_devq;
248c6131460SPaul Saab     struct cam_sim		**ciss_cam_sim;
2493a31b7ebSMike Smith 
25017c0792dSPaul Saab     int				ciss_soft_reset;
25117c0792dSPaul Saab 
2523a31b7ebSMike Smith     int				ciss_flags;
2533a31b7ebSMike Smith #define CISS_FLAG_NOTIFY_OK	(1<<0)		/* notify command running OK */
2543a31b7ebSMike Smith #define CISS_FLAG_CONTROL_OPEN	(1<<1)		/* control device is open */
2553a31b7ebSMike Smith #define CISS_FLAG_ABORTING	(1<<2)		/* driver is going away */
2563a31b7ebSMike Smith #define CISS_FLAG_RUNNING	(1<<3)		/* driver is running (interrupts usable) */
25795dab4f2SAlexander Motin #define CISS_FLAG_BUSY		(1<<4)		/* no free commands */
2583a31b7ebSMike Smith 
2593a31b7ebSMike Smith #define CISS_FLAG_FAKE_SYNCH	(1<<16)		/* needs SYNCHRONISE_CACHE faked */
2603a31b7ebSMike Smith #define CISS_FLAG_BMIC_ABORT	(1<<17)		/* use BMIC command to abort Notify on Event */
261c6131460SPaul Saab #define CISS_FLAG_THREAD_SHUT	(1<<20)		/* shutdown the kthread */
2623a31b7ebSMike Smith 
2633a31b7ebSMike Smith     struct ciss_qstat		ciss_qstat[CISSQ_COUNT];	/* queue statistics */
2643a31b7ebSMike Smith };
2653a31b7ebSMike Smith 
2663a31b7ebSMike Smith /************************************************************************
2673a31b7ebSMike Smith  * Debugging/diagnostic output.
2683a31b7ebSMike Smith  */
2693a31b7ebSMike Smith 
2703a31b7ebSMike Smith /*
2713a31b7ebSMike Smith  * Debugging levels:
2723a31b7ebSMike Smith  *  0 - quiet, only emit warnings
2733a31b7ebSMike Smith  *  1 - talkative, log major events, but nothing on the I/O path
2743a31b7ebSMike Smith  *  2 - noisy, log events on the I/O path
2753a31b7ebSMike Smith  *  3 - extremely noisy, log items in loops
2763a31b7ebSMike Smith  */
2773a31b7ebSMike Smith #ifdef CISS_DEBUG
2783a31b7ebSMike Smith # define debug(level, fmt, args...)							\
2793a31b7ebSMike Smith 	do {										\
2806e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);	\
2813a31b7ebSMike Smith 	} while(0)
2823a31b7ebSMike Smith # define debug_called(level)						\
2833a31b7ebSMike Smith 	do {								\
2846e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: called\n", __func__);	\
2853a31b7ebSMike Smith 	} while(0)
2864caad4e8SMaxime Henrion # define debug_struct(s)		printf("  SIZE %s: %zu\n", #s, sizeof(struct s))
2874caad4e8SMaxime Henrion # define debug_union(s)			printf("  SIZE %s: %zu\n", #s, sizeof(union s))
2884caad4e8SMaxime Henrion # define debug_type(s)			printf("  SIZE %s: %zu\n", #s, sizeof(s))
2893a31b7ebSMike Smith # define debug_field(s, f)		printf("  OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
2904caad4e8SMaxime Henrion # define debug_const(c)			printf("  CONST %s %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c);
2913a31b7ebSMike Smith #else
2923a31b7ebSMike Smith # define debug(level, fmt, args...)
2933a31b7ebSMike Smith # define debug_called(level)
2943a31b7ebSMike Smith # define debug_struct(s)
2953a31b7ebSMike Smith # define debug_union(s)
2963a31b7ebSMike Smith # define debug_type(s)
2973a31b7ebSMike Smith # define debug_field(s, f)
2983a31b7ebSMike Smith # define debug_const(c)
2993a31b7ebSMike Smith #endif
3003a31b7ebSMike Smith 
3013a31b7ebSMike Smith #define ciss_printf(sc, fmt, args...)	device_printf(sc->ciss_dev, fmt , ##args)
3023a31b7ebSMike Smith 
3033a31b7ebSMike Smith /************************************************************************
3043a31b7ebSMike Smith  * Queue primitives
3053a31b7ebSMike Smith  */
3063a31b7ebSMike Smith 
3073a31b7ebSMike Smith #define CISSQ_ADD(sc, qname)					\
3083a31b7ebSMike Smith 	do {							\
3093a31b7ebSMike Smith 	    struct ciss_qstat *qs = &(sc)->ciss_qstat[qname];	\
3103a31b7ebSMike Smith 								\
3113a31b7ebSMike Smith 	    qs->q_length++;					\
3123a31b7ebSMike Smith 	    if (qs->q_length > qs->q_max)			\
3133a31b7ebSMike Smith 		qs->q_max = qs->q_length;			\
3143a31b7ebSMike Smith 	} while(0)
3153a31b7ebSMike Smith 
3163a31b7ebSMike Smith #define CISSQ_REMOVE(sc, qname)    (sc)->ciss_qstat[qname].q_length--
3173a31b7ebSMike Smith #define CISSQ_INIT(sc, qname)			\
3183a31b7ebSMike Smith 	do {					\
3193a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_length = 0;	\
3203a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_max = 0;	\
3213a31b7ebSMike Smith 	} while(0)
3223a31b7ebSMike Smith 
3233a31b7ebSMike Smith 
3243a31b7ebSMike Smith #define CISSQ_REQUEST_QUEUE(name, index)				\
3253a31b7ebSMike Smith static __inline void							\
3263a31b7ebSMike Smith ciss_initq_ ## name (struct ciss_softc *sc)				\
3273a31b7ebSMike Smith {									\
32822657ce1SScott Long     STAILQ_INIT(&sc->ciss_ ## name);					\
3293a31b7ebSMike Smith     CISSQ_INIT(sc, index);						\
3303a31b7ebSMike Smith }									\
3313a31b7ebSMike Smith static __inline void							\
3323a31b7ebSMike Smith ciss_enqueue_ ## name (struct ciss_request *cr)				\
3333a31b7ebSMike Smith {									\
3343a31b7ebSMike Smith 									\
33522657ce1SScott Long     STAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3363a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3373a31b7ebSMike Smith     cr->cr_onq = index;							\
3383a31b7ebSMike Smith }									\
3393a31b7ebSMike Smith static __inline void							\
3403a31b7ebSMike Smith ciss_requeue_ ## name (struct ciss_request *cr)				\
3413a31b7ebSMike Smith {									\
3423a31b7ebSMike Smith 									\
34322657ce1SScott Long     STAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3443a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3453a31b7ebSMike Smith     cr->cr_onq = index;							\
3463a31b7ebSMike Smith }									\
3473a31b7ebSMike Smith static __inline struct ciss_request *					\
3483a31b7ebSMike Smith ciss_dequeue_ ## name (struct ciss_softc *sc)				\
3493a31b7ebSMike Smith {									\
3503a31b7ebSMike Smith     struct ciss_request	*cr;						\
3513a31b7ebSMike Smith 									\
35222657ce1SScott Long     if ((cr = STAILQ_FIRST(&sc->ciss_ ## name)) != NULL) {		\
35322657ce1SScott Long 	STAILQ_REMOVE_HEAD(&sc->ciss_ ## name, cr_link);		\
3543a31b7ebSMike Smith 	CISSQ_REMOVE(sc, index);					\
3553a31b7ebSMike Smith 	cr->cr_onq = -1;						\
3563a31b7ebSMike Smith     }									\
3573a31b7ebSMike Smith     return(cr);								\
3583a31b7ebSMike Smith }									\
3593a31b7ebSMike Smith struct hack
3603a31b7ebSMike Smith 
3613a31b7ebSMike Smith CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
362c6131460SPaul Saab CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);
3633a31b7ebSMike Smith 
36422657ce1SScott Long static __inline void
36522657ce1SScott Long ciss_enqueue_complete(struct ciss_request *ac, cr_qhead_t *head)
36622657ce1SScott Long {
36722657ce1SScott Long 
36822657ce1SScott Long     STAILQ_INSERT_TAIL(head, ac, cr_link);
36922657ce1SScott Long }
37022657ce1SScott Long 
37122657ce1SScott Long static __inline struct ciss_request *
37222657ce1SScott Long ciss_dequeue_complete(struct ciss_softc *sc, cr_qhead_t *head)
37322657ce1SScott Long {
37422657ce1SScott Long     struct ciss_request  *ac;
37522657ce1SScott Long 
37622657ce1SScott Long     if ((ac = STAILQ_FIRST(head)) != NULL)
37722657ce1SScott Long         STAILQ_REMOVE_HEAD(head, cr_link);
37822657ce1SScott Long     return(ac);
37922657ce1SScott Long }
38022657ce1SScott Long 
3813a31b7ebSMike Smith /********************************************************************************
3823a31b7ebSMike Smith  * space-fill a character string
3833a31b7ebSMike Smith  */
3843a31b7ebSMike Smith static __inline void
3853a31b7ebSMike Smith padstr(char *targ, const char *src, int len)
3863a31b7ebSMike Smith {
3873a31b7ebSMike Smith     while (len-- > 0) {
3883a31b7ebSMike Smith 	if (*src != 0) {
3893a31b7ebSMike Smith 	    *targ++ = *src++;
3903a31b7ebSMike Smith 	} else {
3913a31b7ebSMike Smith 	    *targ++ = ' ';
3923a31b7ebSMike Smith 	}
3933a31b7ebSMike Smith     }
3943a31b7ebSMike Smith }
39522657ce1SScott Long 
39622657ce1SScott Long #define ciss_report_request(a, b, c)	\
39722657ce1SScott Long 	_ciss_report_request(a, b, c, __FUNCTION__)
398