2 * Copyright (c) 2001 Michael Smith
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/dev/ciss/cissvar.h,v 1.3.2.2 2003/02/06 21:42:59 ps Exp $
27 * $DragonFly: src/sys/dev/raid/ciss/cissvar.h,v 1.5 2005/06/09 20:55:05 swildner Exp $
30 #include <sys/thread2.h>
33 * CISS adapter driver datastructures
36 /************************************************************************
41 * There is no guaranteed upper bound on the number of concurrent
42 * commands an adapter may claim to support. Cap it at a reasonable
45 #define CISS_MAX_REQUESTS 256
48 * Maximum number of logical drives we support.
50 #define CISS_MAX_LOGICAL 15
53 * Interrupt reduction can be controlled by tuning the interrupt
54 * coalesce delay and count paramters. The delay (in microseconds)
55 * defers delivery of interrupts to increase the chance of there being
56 * more than one completed command ready when the interrupt is
57 * delivered. The count expedites the delivery of the interrupt when
58 * the given number of commands are ready.
60 * If the delay is set to 0, interrupts are delivered immediately.
62 #define CISS_INTERRUPT_COALESCE_DELAY 1000
63 #define CISS_INTERRUPT_COALESCE_COUNT 16
66 * Heartbeat routine timeout in seconds. Note that since event
67 * handling is performed on a callback basis, we don't need this to
70 #define CISS_HEARTBEAT_RATE 10
73 * Maximum number of events we will queue for a monitoring utility.
75 #define CISS_MAX_EVENTS 32
77 /************************************************************************
78 * Compatibility with older versions of FreeBSD
80 #if defined(__FreeBSD__) && __FreeBSD_version < 440001
81 #warning testing old-FreeBSD compat
82 typedef struct proc d_thread_t;
85 /************************************************************************
86 * Command queue statistics
91 #define CISSQ_COMPLETE 2
100 /************************************************************************
101 * Driver version. Only really significant to the ACU interface.
103 #define CISS_DRIVER_VERSION 20011201
105 /************************************************************************
106 * Driver data structures
110 * Each command issued to the adapter is managed by a request
115 TAILQ_ENTRY(ciss_request) cr_link;
116 int cr_onq; /* which queue we are on */
118 struct ciss_softc *cr_sc; /* controller softc */
119 void *cr_data; /* data buffer */
120 u_int32_t cr_length; /* data length */
121 bus_dmamap_t cr_datamap; /* DMA map for data */
124 #define CISS_REQ_MAPPED (1<<0) /* data mapped */
125 #define CISS_REQ_SLEEP (1<<1) /* submitter sleeping */
126 #define CISS_REQ_POLL (1<<2) /* submitter polling */
127 #define CISS_REQ_DATAOUT (1<<3) /* data host->adapter */
128 #define CISS_REQ_DATAIN (1<<4) /* data adapter->host */
130 void (* cr_complete)(struct ciss_request *);
135 * The adapter command structure is defined with a zero-length
136 * scatter/gather list size. In practise, we want space for a
137 * scatter-gather list, and we also want to avoid having commands
138 * cross page boundaries.
140 * Note that 512 bytes yields 28 scatter/gather entries, or the
141 * ability to map (26 * PAGE_SIZE) + 2 bytes of data. On x86, this is
142 * 104kB. 256 bytes would only yield 12 entries, giving a mere 40kB,
146 #define CISS_COMMAND_ALLOC_SIZE 512 /* XXX tune to get sensible s/g list length */
147 #define CISS_COMMAND_SG_LENGTH ((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \
148 / sizeof(struct ciss_sg_entry))
151 * Per-logical-drive data.
155 union ciss_device_address cl_address;
158 #define CISS_LD_NONEXISTENT 0
159 #define CISS_LD_ONLINE 1
160 #define CISS_LD_OFFLINE 2
162 struct ciss_bmic_id_ldrive *cl_ldrive;
163 struct ciss_bmic_id_lstatus *cl_lstatus;
164 struct ciss_ldrive_geometry cl_geometry;
166 char cl_name[16]; /* device name */
174 /* bus connections */
175 device_t ciss_dev; /* bus attachment */
176 dev_t ciss_dev_t; /* control device */
178 struct resource *ciss_regs_resource; /* register interface window */
179 int ciss_regs_rid; /* resource ID */
180 bus_space_handle_t ciss_regs_bhandle; /* bus space handle */
181 bus_space_tag_t ciss_regs_btag; /* bus space tag */
183 struct resource *ciss_cfg_resource; /* config struct interface window */
184 int ciss_cfg_rid; /* resource ID */
185 struct ciss_config_table *ciss_cfg; /* config table in adapter memory */
186 struct ciss_bmic_id_table *ciss_id; /* ID table in host memory */
187 u_int32_t ciss_heartbeat; /* last heartbeat value */
188 int ciss_heart_attack; /* number of times we have seen this value */
190 struct resource *ciss_irq_resource; /* interrupt */
191 int ciss_irq_rid; /* resource ID */
192 void *ciss_intr; /* interrupt handle */
194 bus_dma_tag_t ciss_parent_dmat; /* parent DMA tag */
195 bus_dma_tag_t ciss_buffer_dmat; /* data buffer/command DMA tag */
197 u_int32_t ciss_interrupt_mask; /* controller interrupt mask bits */
199 int ciss_max_requests;
200 struct ciss_request ciss_request[CISS_MAX_REQUESTS]; /* requests */
201 void *ciss_command; /* command structures */
202 bus_dma_tag_t ciss_command_dmat; /* command DMA tag */
203 bus_dmamap_t ciss_command_map; /* command DMA map */
204 u_int32_t ciss_command_phys; /* command array base address */
205 TAILQ_HEAD(,ciss_request) ciss_free; /* requests available for reuse */
206 TAILQ_HEAD(,ciss_request) ciss_busy; /* requests in the adapter */
207 TAILQ_HEAD(,ciss_request) ciss_complete; /* requests which have been returned by the adapter */
209 struct callout ciss_periodic; /* periodic event handling */
210 struct ciss_request *ciss_periodic_notify; /* notify callback request */
212 struct ciss_notify ciss_notify[CISS_MAX_EVENTS];
213 int ciss_notify_head; /* saved-event ringbuffer */
214 int ciss_notify_tail;
216 struct ciss_ldrive ciss_logical[CISS_MAX_LOGICAL];
218 struct cam_devq *ciss_cam_devq;
219 struct cam_sim *ciss_cam_sim;
220 struct cam_path *ciss_cam_path;
223 #define CISS_FLAG_NOTIFY_OK (1<<0) /* notify command running OK */
224 #define CISS_FLAG_CONTROL_OPEN (1<<1) /* control device is open */
225 #define CISS_FLAG_ABORTING (1<<2) /* driver is going away */
226 #define CISS_FLAG_RUNNING (1<<3) /* driver is running (interrupts usable) */
228 #define CISS_FLAG_FAKE_SYNCH (1<<16) /* needs SYNCHRONISE_CACHE faked */
229 #define CISS_FLAG_BMIC_ABORT (1<<17) /* use BMIC command to abort Notify on Event */
231 struct ciss_qstat ciss_qstat[CISSQ_COUNT]; /* queue statistics */
235 * Given a request tag, find the corresponding command in virtual or
238 * The arithmetic here is due to the allocation of ciss_command structures
239 * inside CISS_COMMAND_ALLOC_SIZE blocks. See the comment at the definition
240 * of CISS_COMMAND_ALLOC_SIZE above.
242 #define CISS_FIND_COMMAND(cr) \
243 (struct ciss_command *)((u_int8_t *)(cr)->cr_sc->ciss_command + \
244 ((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
245 #define CISS_FIND_COMMANDPHYS(cr) ((cr)->cr_sc->ciss_command_phys + \
246 ((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
248 /************************************************************************
249 * Debugging/diagnostic output.
254 * 0 - quiet, only emit warnings
255 * 1 - talkative, log major events, but nothing on the I/O path
256 * 2 - noisy, log events on the I/O path
257 * 3 - extremely noisy, log items in loops
260 # define debug(level, fmt, args...) \
262 if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \
264 # define debug_called(level) \
266 if (level <= CISS_DEBUG) printf("%s: called\n", __func__); \
268 # define debug_struct(s) printf(" SIZE %s: %d\n", #s, sizeof(struct s))
269 # define debug_union(s) printf(" SIZE %s: %d\n", #s, sizeof(union s))
270 # define debug_type(s) printf(" SIZE %s: %d\n", #s, sizeof(s))
271 # define debug_field(s, f) printf(" OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
272 # define debug_const(c) printf(" CONST %s %d/0x%x\n", #c, c, c);
274 # define debug(level, fmt, args...)
275 # define debug_called(level)
276 # define debug_struct(s)
277 # define debug_union(s)
278 # define debug_type(s)
279 # define debug_field(s, f)
280 # define debug_const(c)
283 #define ciss_printf(sc, fmt, args...) device_printf(sc->ciss_dev, fmt , ##args)
285 /************************************************************************
289 #define CISSQ_ADD(sc, qname) \
291 struct ciss_qstat *qs = &(sc)->ciss_qstat[qname]; \
294 if (qs->q_length > qs->q_max) \
295 qs->q_max = qs->q_length; \
298 #define CISSQ_REMOVE(sc, qname) (sc)->ciss_qstat[qname].q_length--
299 #define CISSQ_INIT(sc, qname) \
301 sc->ciss_qstat[qname].q_length = 0; \
302 sc->ciss_qstat[qname].q_max = 0; \
306 #define CISSQ_REQUEST_QUEUE(name, index) \
307 static __inline void \
308 ciss_initq_ ## name (struct ciss_softc *sc) \
310 TAILQ_INIT(&sc->ciss_ ## name); \
311 CISSQ_INIT(sc, index); \
313 static __inline void \
314 ciss_enqueue_ ## name (struct ciss_request *cr) \
317 TAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
318 CISSQ_ADD(cr->cr_sc, index); \
319 cr->cr_onq = index; \
322 static __inline void \
323 ciss_requeue_ ## name (struct ciss_request *cr) \
326 TAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
327 CISSQ_ADD(cr->cr_sc, index); \
328 cr->cr_onq = index; \
331 static __inline struct ciss_request * \
332 ciss_dequeue_ ## name (struct ciss_softc *sc) \
334 struct ciss_request *cr; \
337 if ((cr = TAILQ_FIRST(&sc->ciss_ ## name)) != NULL) { \
338 TAILQ_REMOVE(&sc->ciss_ ## name, cr, cr_link); \
339 CISSQ_REMOVE(sc, index); \
345 static __inline int \
346 ciss_remove_ ## name (struct ciss_request *cr) \
351 if (cr->cr_onq != index) { \
352 printf("request on queue %d (expected %d)\n", cr->cr_onq, index);\
355 TAILQ_REMOVE(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
356 CISSQ_REMOVE(cr->cr_sc, index); \
365 CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
366 CISSQ_REQUEST_QUEUE(busy, CISSQ_BUSY);
367 CISSQ_REQUEST_QUEUE(complete, CISSQ_COMPLETE);
369 /********************************************************************************
370 * space-fill a character string
373 padstr(char *targ, const char *src, int len)