xref: /freebsd/sys/dev/ciss/cissvar.h (revision 52c9ce25d8339ad0228be8aaf0e44b45314b38dc)
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  */
443a31b7ebSMike Smith #define CISS_MAX_REQUESTS	256
453a31b7ebSMike Smith 
463a31b7ebSMike Smith /*
473a31b7ebSMike Smith  * Maximum number of logical drives we support.
483a31b7ebSMike Smith  */
493a31b7ebSMike Smith #define CISS_MAX_LOGICAL	15
503a31b7ebSMike Smith 
513a31b7ebSMike Smith /*
52c6131460SPaul Saab  * Maximum number of physical devices we support.
53c6131460SPaul Saab  */
54c6131460SPaul Saab #define CISS_MAX_PHYSICAL	1024
55c6131460SPaul Saab 
56c6131460SPaul Saab /*
573a31b7ebSMike Smith  * Interrupt reduction can be controlled by tuning the interrupt
583a31b7ebSMike Smith  * coalesce delay and count paramters.  The delay (in microseconds)
593a31b7ebSMike Smith  * defers delivery of interrupts to increase the chance of there being
603a31b7ebSMike Smith  * more than one completed command ready when the interrupt is
613a31b7ebSMike Smith  * delivered.  The count expedites the delivery of the interrupt when
623a31b7ebSMike Smith  * the given number of commands are ready.
633a31b7ebSMike Smith  *
643a31b7ebSMike Smith  * If the delay is set to 0, interrupts are delivered immediately.
653a31b7ebSMike Smith  */
6622657ce1SScott Long #define CISS_INTERRUPT_COALESCE_DELAY	0
673a31b7ebSMike Smith #define CISS_INTERRUPT_COALESCE_COUNT	16
683a31b7ebSMike Smith 
693a31b7ebSMike Smith /*
703a31b7ebSMike Smith  * Heartbeat routine timeout in seconds.  Note that since event
713a31b7ebSMike Smith  * handling is performed on a callback basis, we don't need this to
723a31b7ebSMike Smith  * run very often.
733a31b7ebSMike Smith  */
743a31b7ebSMike Smith #define CISS_HEARTBEAT_RATE		10
753a31b7ebSMike Smith 
763a31b7ebSMike Smith /************************************************************************
77d3e4392cSMike Smith  * Compatibility with older versions of FreeBSD
78d3e4392cSMike Smith  */
79d3e4392cSMike Smith #if __FreeBSD_version < 440001
80d3e4392cSMike Smith #warning testing old-FreeBSD compat
81d3e4392cSMike Smith typedef struct proc	d_thread_t;
82d3e4392cSMike Smith #endif
83d3e4392cSMike Smith 
84d3e4392cSMike Smith /************************************************************************
853a31b7ebSMike Smith  * Driver version.  Only really significant to the ACU interface.
863a31b7ebSMike Smith  */
87d3e4392cSMike Smith #define CISS_DRIVER_VERSION	20011201
883a31b7ebSMike Smith 
893a31b7ebSMike Smith /************************************************************************
903a31b7ebSMike Smith  * Driver data structures
913a31b7ebSMike Smith  */
923a31b7ebSMike Smith 
933a31b7ebSMike Smith /*
943a31b7ebSMike Smith  * Each command issued to the adapter is managed by a request
953a31b7ebSMike Smith  * structure.
963a31b7ebSMike Smith  */
973a31b7ebSMike Smith struct ciss_request
983a31b7ebSMike Smith {
9922657ce1SScott Long     STAILQ_ENTRY(ciss_request)	cr_link;
1003a31b7ebSMike Smith     int				cr_onq;		/* which queue we are on */
1013a31b7ebSMike Smith 
1023a31b7ebSMike Smith     struct ciss_softc		*cr_sc;		/* controller softc */
1033a31b7ebSMike Smith     void			*cr_data;	/* data buffer */
1043a31b7ebSMike Smith     u_int32_t			cr_length;	/* data length */
1053a31b7ebSMike Smith     bus_dmamap_t		cr_datamap;	/* DMA map for data */
1063a31b7ebSMike Smith     int				cr_tag;
1073a31b7ebSMike Smith     int				cr_flags;
1083a31b7ebSMike Smith #define CISS_REQ_MAPPED		(1<<0)		/* data mapped */
1093a31b7ebSMike Smith #define CISS_REQ_SLEEP		(1<<1)		/* submitter sleeping */
1103a31b7ebSMike Smith #define CISS_REQ_POLL		(1<<2)		/* submitter polling */
1113a31b7ebSMike Smith #define CISS_REQ_DATAOUT	(1<<3)		/* data host->adapter */
1123a31b7ebSMike Smith #define CISS_REQ_DATAIN		(1<<4)		/* data adapter->host */
11322657ce1SScott Long #define CISS_REQ_BUSY		(1<<5)		/* controller has req */
1143a31b7ebSMike Smith 
1153a31b7ebSMike Smith     void			(* cr_complete)(struct ciss_request *);
1163a31b7ebSMike Smith     void			*cr_private;
11722657ce1SScott Long     int				cr_sg_tag;
11822657ce1SScott Long #define CISS_SG_MAX		((CISS_SG_FETCH_MAX << 1) | 0x1)
11922657ce1SScott Long #define CISS_SG_1		((CISS_SG_FETCH_1 << 1) | 0x01)
12022657ce1SScott Long #define CISS_SG_2		((CISS_SG_FETCH_2 << 1) | 0x01)
12122657ce1SScott Long #define CISS_SG_4		((CISS_SG_FETCH_4 << 1) | 0x01)
12222657ce1SScott Long #define CISS_SG_8		((CISS_SG_FETCH_8 << 1) | 0x01)
12322657ce1SScott Long #define CISS_SG_16		((CISS_SG_FETCH_16 << 1) | 0x01)
12422657ce1SScott Long #define CISS_SG_32		((CISS_SG_FETCH_32 << 1) | 0x01)
12522657ce1SScott Long #define CISS_SG_NONE		((CISS_SG_FETCH_NONE << 1) | 0x01)
1263a31b7ebSMike Smith };
1273a31b7ebSMike Smith 
1283a31b7ebSMike Smith /*
1293a31b7ebSMike Smith  * The adapter command structure is defined with a zero-length
1303a31b7ebSMike Smith  * scatter/gather list size.  In practise, we want space for a
1313a31b7ebSMike Smith  * scatter-gather list, and we also want to avoid having commands
1323a31b7ebSMike Smith  * cross page boundaries.
1333a31b7ebSMike Smith  *
1343a31b7ebSMike Smith  * Note that 512 bytes yields 28 scatter/gather entries, or the
1353a31b7ebSMike Smith  * ability to map (26 * PAGE_SIZE) + 2 bytes of data.  On x86, this is
1363a31b7ebSMike Smith  * 104kB.  256 bytes would only yield 12 entries, giving a mere 40kB,
1373a31b7ebSMike Smith  * too small.
1383a31b7ebSMike Smith  */
1393a31b7ebSMike Smith 
1403a31b7ebSMike Smith #define CISS_COMMAND_ALLOC_SIZE		512	/* XXX tune to get sensible s/g list length */
1413a31b7ebSMike Smith #define CISS_COMMAND_SG_LENGTH	((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \
1423a31b7ebSMike Smith 				 / sizeof(struct ciss_sg_entry))
1433a31b7ebSMike Smith 
14452c9ce25SScott Long /* XXX Prep for increasing max i/o */
14552c9ce25SScott Long #define CISS_MAX_SG_ELEMENTS   33
14652c9ce25SScott Long 
1473a31b7ebSMike Smith /*
1483a31b7ebSMike Smith  * Per-logical-drive data.
1493a31b7ebSMike Smith  */
1503a31b7ebSMike Smith struct ciss_ldrive
1513a31b7ebSMike Smith {
1523a31b7ebSMike Smith     union ciss_device_address	cl_address;
153c6131460SPaul Saab     union ciss_device_address	*cl_controller;
1543a31b7ebSMike Smith     int				cl_status;
1553a31b7ebSMike Smith #define CISS_LD_NONEXISTENT	0
1563a31b7ebSMike Smith #define CISS_LD_ONLINE		1
1573a31b7ebSMike Smith #define CISS_LD_OFFLINE		2
1583a31b7ebSMike Smith 
159c6131460SPaul Saab     int				cl_update;
160c6131460SPaul Saab 
1613a31b7ebSMike Smith     struct ciss_bmic_id_ldrive	*cl_ldrive;
1623a31b7ebSMike Smith     struct ciss_bmic_id_lstatus	*cl_lstatus;
163440baa08SPaul Saab     struct ciss_ldrive_geometry	cl_geometry;
1643a31b7ebSMike Smith 
1653a31b7ebSMike Smith     char			cl_name[16];		/* device name */
1663a31b7ebSMike Smith };
1673a31b7ebSMike Smith 
1683a31b7ebSMike Smith /*
1691fe6c4eeSScott Long  * Per-physical-drive data
1701fe6c4eeSScott Long  */
1711fe6c4eeSScott Long struct ciss_pdrive
1721fe6c4eeSScott Long {
1731fe6c4eeSScott Long     union ciss_device_address	cp_address;
1741fe6c4eeSScott Long     int				cp_online;
1751fe6c4eeSScott Long };
1761fe6c4eeSScott Long 
1771fe6c4eeSScott Long #define CISS_PHYSICAL_SHIFT	5
1781fe6c4eeSScott Long #define CISS_PHYSICAL_BASE	(1 << CISS_PHYSICAL_SHIFT)
1791fe6c4eeSScott Long #define CISS_MAX_PHYSTGT	15
1801fe6c4eeSScott Long 
1811fe6c4eeSScott Long #define CISS_IS_PHYSICAL(bus)	(bus >= CISS_PHYSICAL_BASE)
1821fe6c4eeSScott Long #define CISS_CAM_TO_PBUS(bus)	(bus - CISS_PHYSICAL_BASE)
1831fe6c4eeSScott Long 
1841fe6c4eeSScott Long /*
1853a31b7ebSMike Smith  * Per-adapter data
1863a31b7ebSMike Smith  */
1873a31b7ebSMike Smith struct ciss_softc
1883a31b7ebSMike Smith {
1893a31b7ebSMike Smith     /* bus connections */
1903a31b7ebSMike Smith     device_t			ciss_dev;		/* bus attachment */
19189c9c53dSPoul-Henning Kamp     struct cdev *ciss_dev_t;		/* control device */
1923a31b7ebSMike Smith 
1933a31b7ebSMike Smith     struct resource		*ciss_regs_resource;	/* register interface window */
1943a31b7ebSMike Smith     int				ciss_regs_rid;		/* resource ID */
1953a31b7ebSMike Smith     bus_space_handle_t		ciss_regs_bhandle;	/* bus space handle */
1963a31b7ebSMike Smith     bus_space_tag_t		ciss_regs_btag;		/* bus space tag */
1973a31b7ebSMike Smith 
1983a31b7ebSMike Smith     struct resource		*ciss_cfg_resource;	/* config struct interface window */
1993a31b7ebSMike Smith     int				ciss_cfg_rid;		/* resource ID */
2003a31b7ebSMike Smith     struct ciss_config_table	*ciss_cfg;		/* config table in adapter memory */
20122657ce1SScott Long     struct ciss_perf_config	*ciss_perf;		/* config table for the performant */
2023a31b7ebSMike Smith     struct ciss_bmic_id_table	*ciss_id;		/* ID table in host memory */
2033a31b7ebSMike Smith     u_int32_t			ciss_heartbeat;		/* last heartbeat value */
2043a31b7ebSMike Smith     int				ciss_heart_attack;	/* number of times we have seen this value */
2053a31b7ebSMike Smith 
20622657ce1SScott Long     int				ciss_msi;
2073a31b7ebSMike Smith     struct resource		*ciss_irq_resource;	/* interrupt */
20822657ce1SScott Long     int				ciss_irq_rid[CISS_MSI_COUNT];		/* resource ID */
2093a31b7ebSMike Smith     void			*ciss_intr;		/* interrupt handle */
2103a31b7ebSMike Smith 
2113a31b7ebSMike Smith     bus_dma_tag_t		ciss_parent_dmat;	/* parent DMA tag */
2123a31b7ebSMike Smith     bus_dma_tag_t		ciss_buffer_dmat;	/* data buffer/command DMA tag */
2133a31b7ebSMike Smith 
2143a31b7ebSMike Smith     u_int32_t			ciss_interrupt_mask;	/* controller interrupt mask bits */
2153a31b7ebSMike Smith 
21622657ce1SScott Long     uint64_t			*ciss_reply;
21722657ce1SScott Long     int				ciss_cycle;
21822657ce1SScott Long     int				ciss_rqidx;
21922657ce1SScott Long     bus_dma_tag_t		ciss_reply_dmat;
22022657ce1SScott Long     bus_dmamap_t		ciss_reply_map;
22122657ce1SScott Long     uint32_t			ciss_reply_phys;
22222657ce1SScott Long 
2233a31b7ebSMike Smith     int				ciss_max_requests;
2243a31b7ebSMike Smith     struct ciss_request		ciss_request[CISS_MAX_REQUESTS];	/* requests */
2253a31b7ebSMike Smith     void			*ciss_command;		/* command structures */
2263a31b7ebSMike Smith     bus_dma_tag_t		ciss_command_dmat;	/* command DMA tag */
2273a31b7ebSMike Smith     bus_dmamap_t		ciss_command_map;	/* command DMA map */
2283a31b7ebSMike Smith     u_int32_t			ciss_command_phys;	/* command array base address */
22922657ce1SScott Long     cr_qhead_t			ciss_free;		/* requests available for reuse */
23022657ce1SScott Long     cr_qhead_t			ciss_notify;		/* requests which are defered for processing */
231c6131460SPaul Saab     struct proc			*ciss_notify_thread;
2323a31b7ebSMike Smith 
233975b7318SScott Long     struct callout		ciss_periodic;		/* periodic event handling */
2343a31b7ebSMike Smith     struct ciss_request		*ciss_periodic_notify;	/* notify callback request */
2353a31b7ebSMike Smith 
236975b7318SScott Long     struct mtx			ciss_mtx;
237c6131460SPaul Saab     struct ciss_ldrive		**ciss_logical;
2381fe6c4eeSScott Long     struct ciss_pdrive		**ciss_physical;
239c6131460SPaul Saab     union ciss_device_address	*ciss_controllers;	/* controller address */
240c6131460SPaul Saab     int				ciss_max_bus_number;	/* maximum bus number */
2411fe6c4eeSScott Long     int				ciss_max_logical_bus;
2421fe6c4eeSScott Long     int				ciss_max_physical_bus;
2433a31b7ebSMike Smith 
2443a31b7ebSMike Smith     struct cam_devq		*ciss_cam_devq;
245c6131460SPaul Saab     struct cam_sim		**ciss_cam_sim;
2463a31b7ebSMike Smith 
24717c0792dSPaul Saab     int				ciss_soft_reset;
24817c0792dSPaul Saab 
2493a31b7ebSMike Smith     int				ciss_flags;
2503a31b7ebSMike Smith #define CISS_FLAG_NOTIFY_OK	(1<<0)		/* notify command running OK */
2513a31b7ebSMike Smith #define CISS_FLAG_CONTROL_OPEN	(1<<1)		/* control device is open */
2523a31b7ebSMike Smith #define CISS_FLAG_ABORTING	(1<<2)		/* driver is going away */
2533a31b7ebSMike Smith #define CISS_FLAG_RUNNING	(1<<3)		/* driver is running (interrupts usable) */
2543a31b7ebSMike Smith 
2553a31b7ebSMike Smith #define CISS_FLAG_FAKE_SYNCH	(1<<16)		/* needs SYNCHRONISE_CACHE faked */
2563a31b7ebSMike Smith #define CISS_FLAG_BMIC_ABORT	(1<<17)		/* use BMIC command to abort Notify on Event */
257c6131460SPaul Saab #define CISS_FLAG_THREAD_SHUT	(1<<20)		/* shutdown the kthread */
2583a31b7ebSMike Smith 
2593a31b7ebSMike Smith     struct ciss_qstat		ciss_qstat[CISSQ_COUNT];	/* queue statistics */
2603a31b7ebSMike Smith };
2613a31b7ebSMike Smith 
2623a31b7ebSMike Smith /*
2633a31b7ebSMike Smith  * Given a request tag, find the corresponding command in virtual or
2643a31b7ebSMike Smith  * physical space.
2653a31b7ebSMike Smith  *
2663a31b7ebSMike Smith  * The arithmetic here is due to the allocation of ciss_command structures
2673a31b7ebSMike Smith  * inside CISS_COMMAND_ALLOC_SIZE blocks.  See the comment at the definition
2683a31b7ebSMike Smith  * of CISS_COMMAND_ALLOC_SIZE above.
2693a31b7ebSMike Smith  */
2703a31b7ebSMike Smith #define CISS_FIND_COMMAND(cr)							\
2713a31b7ebSMike Smith 	(struct ciss_command *)((u_int8_t *)(cr)->cr_sc->ciss_command +		\
2723a31b7ebSMike Smith 				((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
2733a31b7ebSMike Smith #define CISS_FIND_COMMANDPHYS(cr)	((cr)->cr_sc->ciss_command_phys + \
2743a31b7ebSMike Smith 					 ((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
2753a31b7ebSMike Smith 
2763a31b7ebSMike Smith /************************************************************************
2773a31b7ebSMike Smith  * Debugging/diagnostic output.
2783a31b7ebSMike Smith  */
2793a31b7ebSMike Smith 
2803a31b7ebSMike Smith /*
2813a31b7ebSMike Smith  * Debugging levels:
2823a31b7ebSMike Smith  *  0 - quiet, only emit warnings
2833a31b7ebSMike Smith  *  1 - talkative, log major events, but nothing on the I/O path
2843a31b7ebSMike Smith  *  2 - noisy, log events on the I/O path
2853a31b7ebSMike Smith  *  3 - extremely noisy, log items in loops
2863a31b7ebSMike Smith  */
2873a31b7ebSMike Smith #ifdef CISS_DEBUG
2883a31b7ebSMike Smith # define debug(level, fmt, args...)							\
2893a31b7ebSMike Smith 	do {										\
2906e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);	\
2913a31b7ebSMike Smith 	} while(0)
2923a31b7ebSMike Smith # define debug_called(level)						\
2933a31b7ebSMike Smith 	do {								\
2946e551fb6SDavid E. O'Brien 	    if (level <= CISS_DEBUG) printf("%s: called\n", __func__);	\
2953a31b7ebSMike Smith 	} while(0)
2964caad4e8SMaxime Henrion # define debug_struct(s)		printf("  SIZE %s: %zu\n", #s, sizeof(struct s))
2974caad4e8SMaxime Henrion # define debug_union(s)			printf("  SIZE %s: %zu\n", #s, sizeof(union s))
2984caad4e8SMaxime Henrion # define debug_type(s)			printf("  SIZE %s: %zu\n", #s, sizeof(s))
2993a31b7ebSMike Smith # define debug_field(s, f)		printf("  OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
3004caad4e8SMaxime Henrion # define debug_const(c)			printf("  CONST %s %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c);
3013a31b7ebSMike Smith #else
3023a31b7ebSMike Smith # define debug(level, fmt, args...)
3033a31b7ebSMike Smith # define debug_called(level)
3043a31b7ebSMike Smith # define debug_struct(s)
3053a31b7ebSMike Smith # define debug_union(s)
3063a31b7ebSMike Smith # define debug_type(s)
3073a31b7ebSMike Smith # define debug_field(s, f)
3083a31b7ebSMike Smith # define debug_const(c)
3093a31b7ebSMike Smith #endif
3103a31b7ebSMike Smith 
3113a31b7ebSMike Smith #define ciss_printf(sc, fmt, args...)	device_printf(sc->ciss_dev, fmt , ##args)
3123a31b7ebSMike Smith 
3133a31b7ebSMike Smith /************************************************************************
3143a31b7ebSMike Smith  * Queue primitives
3153a31b7ebSMike Smith  */
3163a31b7ebSMike Smith 
3173a31b7ebSMike Smith #define CISSQ_ADD(sc, qname)					\
3183a31b7ebSMike Smith 	do {							\
3193a31b7ebSMike Smith 	    struct ciss_qstat *qs = &(sc)->ciss_qstat[qname];	\
3203a31b7ebSMike Smith 								\
3213a31b7ebSMike Smith 	    qs->q_length++;					\
3223a31b7ebSMike Smith 	    if (qs->q_length > qs->q_max)			\
3233a31b7ebSMike Smith 		qs->q_max = qs->q_length;			\
3243a31b7ebSMike Smith 	} while(0)
3253a31b7ebSMike Smith 
3263a31b7ebSMike Smith #define CISSQ_REMOVE(sc, qname)    (sc)->ciss_qstat[qname].q_length--
3273a31b7ebSMike Smith #define CISSQ_INIT(sc, qname)			\
3283a31b7ebSMike Smith 	do {					\
3293a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_length = 0;	\
3303a31b7ebSMike Smith 	    sc->ciss_qstat[qname].q_max = 0;	\
3313a31b7ebSMike Smith 	} while(0)
3323a31b7ebSMike Smith 
3333a31b7ebSMike Smith 
3343a31b7ebSMike Smith #define CISSQ_REQUEST_QUEUE(name, index)				\
3353a31b7ebSMike Smith static __inline void							\
3363a31b7ebSMike Smith ciss_initq_ ## name (struct ciss_softc *sc)				\
3373a31b7ebSMike Smith {									\
33822657ce1SScott Long     STAILQ_INIT(&sc->ciss_ ## name);					\
3393a31b7ebSMike Smith     CISSQ_INIT(sc, index);						\
3403a31b7ebSMike Smith }									\
3413a31b7ebSMike Smith static __inline void							\
3423a31b7ebSMike Smith ciss_enqueue_ ## name (struct ciss_request *cr)				\
3433a31b7ebSMike Smith {									\
3443a31b7ebSMike Smith 									\
34522657ce1SScott Long     STAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3463a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3473a31b7ebSMike Smith     cr->cr_onq = index;							\
3483a31b7ebSMike Smith }									\
3493a31b7ebSMike Smith static __inline void							\
3503a31b7ebSMike Smith ciss_requeue_ ## name (struct ciss_request *cr)				\
3513a31b7ebSMike Smith {									\
3523a31b7ebSMike Smith 									\
35322657ce1SScott Long     STAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link);		\
3543a31b7ebSMike Smith     CISSQ_ADD(cr->cr_sc, index);					\
3553a31b7ebSMike Smith     cr->cr_onq = index;							\
3563a31b7ebSMike Smith }									\
3573a31b7ebSMike Smith static __inline struct ciss_request *					\
3583a31b7ebSMike Smith ciss_dequeue_ ## name (struct ciss_softc *sc)				\
3593a31b7ebSMike Smith {									\
3603a31b7ebSMike Smith     struct ciss_request	*cr;						\
3613a31b7ebSMike Smith 									\
36222657ce1SScott Long     if ((cr = STAILQ_FIRST(&sc->ciss_ ## name)) != NULL) {		\
36322657ce1SScott Long 	STAILQ_REMOVE_HEAD(&sc->ciss_ ## name, cr_link);		\
3643a31b7ebSMike Smith 	CISSQ_REMOVE(sc, index);					\
3653a31b7ebSMike Smith 	cr->cr_onq = -1;						\
3663a31b7ebSMike Smith     }									\
3673a31b7ebSMike Smith     return(cr);								\
3683a31b7ebSMike Smith }									\
3693a31b7ebSMike Smith struct hack
3703a31b7ebSMike Smith 
3713a31b7ebSMike Smith CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
372c6131460SPaul Saab CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY);
3733a31b7ebSMike Smith 
37422657ce1SScott Long static __inline void
37522657ce1SScott Long ciss_enqueue_complete(struct ciss_request *ac, cr_qhead_t *head)
37622657ce1SScott Long {
37722657ce1SScott Long 
37822657ce1SScott Long     STAILQ_INSERT_TAIL(head, ac, cr_link);
37922657ce1SScott Long }
38022657ce1SScott Long 
38122657ce1SScott Long static __inline struct ciss_request *
38222657ce1SScott Long ciss_dequeue_complete(struct ciss_softc *sc, cr_qhead_t *head)
38322657ce1SScott Long {
38422657ce1SScott Long     struct ciss_request  *ac;
38522657ce1SScott Long 
38622657ce1SScott Long     if ((ac = STAILQ_FIRST(head)) != NULL)
38722657ce1SScott Long         STAILQ_REMOVE_HEAD(head, cr_link);
38822657ce1SScott Long     return(ac);
38922657ce1SScott Long }
39022657ce1SScott Long 
3913a31b7ebSMike Smith /********************************************************************************
3923a31b7ebSMike Smith  * space-fill a character string
3933a31b7ebSMike Smith  */
3943a31b7ebSMike Smith static __inline void
3953a31b7ebSMike Smith padstr(char *targ, const char *src, int len)
3963a31b7ebSMike Smith {
3973a31b7ebSMike Smith     while (len-- > 0) {
3983a31b7ebSMike Smith 	if (*src != 0) {
3993a31b7ebSMike Smith 	    *targ++ = *src++;
4003a31b7ebSMike Smith 	} else {
4013a31b7ebSMike Smith 	    *targ++ = ' ';
4023a31b7ebSMike Smith 	}
4033a31b7ebSMike Smith     }
4043a31b7ebSMike Smith }
40522657ce1SScott Long 
40622657ce1SScott Long #define ciss_report_request(a, b, c)	\
40722657ce1SScott Long 	_ciss_report_request(a, b, c, __FUNCTION__)
408