1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
/*-
* Copyright (c) 2001 Michael Smith
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
/*
* CISS adapter driver datastructures
*/
/************************************************************************
* Tunable parameters
*/
/*
* There is no guaranteed upper bound on the number of concurrent
* commands an adapter may claim to support. Cap it at a reasonable
* value.
*/
#define CISS_MAX_REQUESTS 256
/*
* Maximum number of logical drives we support.
*/
#define CISS_MAX_LOGICAL 15
/*
* Interrupt reduction can be controlled by tuning the interrupt
* coalesce delay and count paramters. The delay (in microseconds)
* defers delivery of interrupts to increase the chance of there being
* more than one completed command ready when the interrupt is
* delivered. The count expedites the delivery of the interrupt when
* the given number of commands are ready.
*
* If the delay is set to 0, interrupts are delivered immediately.
*/
#define CISS_INTERRUPT_COALESCE_DELAY 1000
#define CISS_INTERRUPT_COALESCE_COUNT 16
/*
* Heartbeat routine timeout in seconds. Note that since event
* handling is performed on a callback basis, we don't need this to
* run very often.
*/
#define CISS_HEARTBEAT_RATE 10
/*
* Maximum number of events we will queue for a monitoring utility.
*/
#define CISS_MAX_EVENTS 32
/************************************************************************
* Compatibility with older versions of FreeBSD
*/
#if __FreeBSD_version < 440001
#warning testing old-FreeBSD compat
typedef struct proc d_thread_t;
#endif
/************************************************************************
* Command queue statistics
*/
#define CISSQ_FREE 0
#define CISSQ_BUSY 1
#define CISSQ_COMPLETE 2
#define CISSQ_COUNT 3
struct ciss_qstat
{
u_int32_t q_length;
u_int32_t q_max;
};
/************************************************************************
* Driver version. Only really significant to the ACU interface.
*/
#define CISS_DRIVER_VERSION 20011201
/************************************************************************
* Driver data structures
*/
/*
* Each command issued to the adapter is managed by a request
* structure.
*/
struct ciss_request
{
TAILQ_ENTRY(ciss_request) cr_link;
int cr_onq; /* which queue we are on */
struct ciss_softc *cr_sc; /* controller softc */
void *cr_data; /* data buffer */
u_int32_t cr_length; /* data length */
bus_dmamap_t cr_datamap; /* DMA map for data */
int cr_tag;
int cr_flags;
#define CISS_REQ_MAPPED (1<<0) /* data mapped */
#define CISS_REQ_SLEEP (1<<1) /* submitter sleeping */
#define CISS_REQ_POLL (1<<2) /* submitter polling */
#define CISS_REQ_DATAOUT (1<<3) /* data host->adapter */
#define CISS_REQ_DATAIN (1<<4) /* data adapter->host */
void (* cr_complete)(struct ciss_request *);
void *cr_private;
};
/*
* The adapter command structure is defined with a zero-length
* scatter/gather list size. In practise, we want space for a
* scatter-gather list, and we also want to avoid having commands
* cross page boundaries.
*
* Note that 512 bytes yields 28 scatter/gather entries, or the
* ability to map (26 * PAGE_SIZE) + 2 bytes of data. On x86, this is
* 104kB. 256 bytes would only yield 12 entries, giving a mere 40kB,
* too small.
*/
#define CISS_COMMAND_ALLOC_SIZE 512 /* XXX tune to get sensible s/g list length */
#define CISS_COMMAND_SG_LENGTH ((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \
/ sizeof(struct ciss_sg_entry))
/*
* Per-logical-drive data.
*/
struct ciss_ldrive
{
union ciss_device_address cl_address;
int cl_status;
#define CISS_LD_NONEXISTENT 0
#define CISS_LD_ONLINE 1
#define CISS_LD_OFFLINE 2
struct ciss_bmic_id_ldrive *cl_ldrive;
struct ciss_bmic_id_lstatus *cl_lstatus;
struct ciss_ldrive_geometry cl_geometry;
char cl_name[16]; /* device name */
};
/*
* Per-adapter data
*/
struct ciss_softc
{
/* bus connections */
device_t ciss_dev; /* bus attachment */
dev_t ciss_dev_t; /* control device */
struct resource *ciss_regs_resource; /* register interface window */
int ciss_regs_rid; /* resource ID */
bus_space_handle_t ciss_regs_bhandle; /* bus space handle */
bus_space_tag_t ciss_regs_btag; /* bus space tag */
struct resource *ciss_cfg_resource; /* config struct interface window */
int ciss_cfg_rid; /* resource ID */
struct ciss_config_table *ciss_cfg; /* config table in adapter memory */
struct ciss_bmic_id_table *ciss_id; /* ID table in host memory */
u_int32_t ciss_heartbeat; /* last heartbeat value */
int ciss_heart_attack; /* number of times we have seen this value */
struct resource *ciss_irq_resource; /* interrupt */
int ciss_irq_rid; /* resource ID */
void *ciss_intr; /* interrupt handle */
bus_dma_tag_t ciss_parent_dmat; /* parent DMA tag */
bus_dma_tag_t ciss_buffer_dmat; /* data buffer/command DMA tag */
u_int32_t ciss_interrupt_mask; /* controller interrupt mask bits */
int ciss_max_requests;
struct ciss_request ciss_request[CISS_MAX_REQUESTS]; /* requests */
void *ciss_command; /* command structures */
bus_dma_tag_t ciss_command_dmat; /* command DMA tag */
bus_dmamap_t ciss_command_map; /* command DMA map */
u_int32_t ciss_command_phys; /* command array base address */
TAILQ_HEAD(,ciss_request) ciss_free; /* requests available for reuse */
TAILQ_HEAD(,ciss_request) ciss_busy; /* requests in the adapter */
TAILQ_HEAD(,ciss_request) ciss_complete; /* requests which have been returned by the adapter */
struct callout_handle ciss_periodic; /* periodic event handling */
struct ciss_request *ciss_periodic_notify; /* notify callback request */
struct ciss_notify ciss_notify[CISS_MAX_EVENTS];
int ciss_notify_head; /* saved-event ringbuffer */
int ciss_notify_tail;
struct ciss_ldrive ciss_logical[CISS_MAX_LOGICAL];
struct cam_devq *ciss_cam_devq;
struct cam_sim *ciss_cam_sim;
struct cam_path *ciss_cam_path;
int ciss_flags;
#define CISS_FLAG_NOTIFY_OK (1<<0) /* notify command running OK */
#define CISS_FLAG_CONTROL_OPEN (1<<1) /* control device is open */
#define CISS_FLAG_ABORTING (1<<2) /* driver is going away */
#define CISS_FLAG_RUNNING (1<<3) /* driver is running (interrupts usable) */
#define CISS_FLAG_FAKE_SYNCH (1<<16) /* needs SYNCHRONISE_CACHE faked */
#define CISS_FLAG_BMIC_ABORT (1<<17) /* use BMIC command to abort Notify on Event */
struct ciss_qstat ciss_qstat[CISSQ_COUNT]; /* queue statistics */
};
/*
* Given a request tag, find the corresponding command in virtual or
* physical space.
*
* The arithmetic here is due to the allocation of ciss_command structures
* inside CISS_COMMAND_ALLOC_SIZE blocks. See the comment at the definition
* of CISS_COMMAND_ALLOC_SIZE above.
*/
#define CISS_FIND_COMMAND(cr) \
(struct ciss_command *)((u_int8_t *)(cr)->cr_sc->ciss_command + \
((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
#define CISS_FIND_COMMANDPHYS(cr) ((cr)->cr_sc->ciss_command_phys + \
((cr)->cr_tag * CISS_COMMAND_ALLOC_SIZE))
/************************************************************************
* Debugging/diagnostic output.
*/
/*
* Debugging levels:
* 0 - quiet, only emit warnings
* 1 - talkative, log major events, but nothing on the I/O path
* 2 - noisy, log events on the I/O path
* 3 - extremely noisy, log items in loops
*/
#ifdef CISS_DEBUG
# define debug(level, fmt, args...) \
do { \
if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \
} while(0)
# define debug_called(level) \
do { \
if (level <= CISS_DEBUG) printf("%s: called\n", __func__); \
} while(0)
# define debug_struct(s) printf(" SIZE %s: %zu\n", #s, sizeof(struct s))
# define debug_union(s) printf(" SIZE %s: %zu\n", #s, sizeof(union s))
# define debug_type(s) printf(" SIZE %s: %zu\n", #s, sizeof(s))
# define debug_field(s, f) printf(" OFFSET %s.%s: %d\n", #s, #f, ((int)&(((struct s *)0)->f)))
# define debug_const(c) printf(" CONST %s %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c);
#else
# define debug(level, fmt, args...)
# define debug_called(level)
# define debug_struct(s)
# define debug_union(s)
# define debug_type(s)
# define debug_field(s, f)
# define debug_const(c)
#endif
#define ciss_printf(sc, fmt, args...) device_printf(sc->ciss_dev, fmt , ##args)
/************************************************************************
* Queue primitives
*/
#define CISSQ_ADD(sc, qname) \
do { \
struct ciss_qstat *qs = &(sc)->ciss_qstat[qname]; \
\
qs->q_length++; \
if (qs->q_length > qs->q_max) \
qs->q_max = qs->q_length; \
} while(0)
#define CISSQ_REMOVE(sc, qname) (sc)->ciss_qstat[qname].q_length--
#define CISSQ_INIT(sc, qname) \
do { \
sc->ciss_qstat[qname].q_length = 0; \
sc->ciss_qstat[qname].q_max = 0; \
} while(0)
#define CISSQ_REQUEST_QUEUE(name, index) \
static __inline void \
ciss_initq_ ## name (struct ciss_softc *sc) \
{ \
TAILQ_INIT(&sc->ciss_ ## name); \
CISSQ_INIT(sc, index); \
} \
static __inline void \
ciss_enqueue_ ## name (struct ciss_request *cr) \
{ \
int s; \
\
s = splcam(); \
TAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
CISSQ_ADD(cr->cr_sc, index); \
cr->cr_onq = index; \
splx(s); \
} \
static __inline void \
ciss_requeue_ ## name (struct ciss_request *cr) \
{ \
int s; \
\
s = splcam(); \
TAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
CISSQ_ADD(cr->cr_sc, index); \
cr->cr_onq = index; \
splx(s); \
} \
static __inline struct ciss_request * \
ciss_dequeue_ ## name (struct ciss_softc *sc) \
{ \
struct ciss_request *cr; \
int s; \
\
s = splcam(); \
if ((cr = TAILQ_FIRST(&sc->ciss_ ## name)) != NULL) { \
TAILQ_REMOVE(&sc->ciss_ ## name, cr, cr_link); \
CISSQ_REMOVE(sc, index); \
cr->cr_onq = -1; \
} \
splx(s); \
return(cr); \
} \
static __inline int \
ciss_remove_ ## name (struct ciss_request *cr) \
{ \
int s, error; \
\
s = splcam(); \
if (cr->cr_onq != index) { \
printf("request on queue %d (expected %d)\n", cr->cr_onq, index);\
error = 1; \
} else { \
TAILQ_REMOVE(&cr->cr_sc->ciss_ ## name, cr, cr_link); \
CISSQ_REMOVE(cr->cr_sc, index); \
cr->cr_onq = -1; \
error = 0; \
} \
splx(s); \
return(error); \
} \
struct hack
CISSQ_REQUEST_QUEUE(free, CISSQ_FREE);
CISSQ_REQUEST_QUEUE(busy, CISSQ_BUSY);
CISSQ_REQUEST_QUEUE(complete, CISSQ_COMPLETE);
/********************************************************************************
* space-fill a character string
*/
static __inline void
padstr(char *targ, const char *src, int len)
{
while (len-- > 0) {
if (*src != 0) {
*targ++ = *src++;
} else {
*targ++ = ' ';
}
}
}
|