cissvar.h revision 130585
13071Sache/*- 23071Sache * Copyright (c) 2001 Michael Smith 33071Sache * All rights reserved. 43071Sache * 53071Sache * Redistribution and use in source and binary forms, with or without 63071Sache * modification, are permitted provided that the following conditions 73071Sache * are met: 83071Sache * 1. Redistributions of source code must retain the above copyright 93071Sache * notice, this list of conditions and the following disclaimer. 103071Sache * 2. Redistributions in binary form must reproduce the above copyright 113071Sache * notice, this list of conditions and the following disclaimer in the 123071Sache * documentation and/or other materials provided with the distribution. 133071Sache * 143071Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 153071Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 163071Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 173071Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 183071Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 193071Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 203071Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 213071Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 223071Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 233071Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 243071Sache * SUCH DAMAGE. 253071Sache * 263071Sache * $FreeBSD: head/sys/dev/ciss/cissvar.h 130585 2004-06-16 09:47:26Z phk $ 273071Sache */ 283071Sache 293071Sache/* 303071Sache * CISS adapter driver datastructures 313071Sache */ 323071Sache 333071Sache/************************************************************************ 343071Sache * Tunable parameters 353071Sache */ 363071Sache 373071Sache/* 383071Sache * There is no guaranteed upper bound on the number of concurrent 393071Sache * commands an adapter may claim to support. Cap it at a reasonable 403071Sache * value. 413071Sache */ 423071Sache#define CISS_MAX_REQUESTS 256 433071Sache 443071Sache/* 453071Sache * Maximum number of logical drives we support. 463071Sache */ 473071Sache#define CISS_MAX_LOGICAL 15 483071Sache 493071Sache/* 503071Sache * Maximum number of physical devices we support. 513071Sache */ 523071Sache#define CISS_MAX_PHYSICAL 1024 533071Sache 543071Sache/* 553071Sache * Interrupt reduction can be controlled by tuning the interrupt 563071Sache * coalesce delay and count paramters. The delay (in microseconds) 573071Sache * defers delivery of interrupts to increase the chance of there being 583071Sache * more than one completed command ready when the interrupt is 593071Sache * delivered. The count expedites the delivery of the interrupt when 603071Sache * the given number of commands are ready. 613071Sache * 623071Sache * If the delay is set to 0, interrupts are delivered immediately. 633071Sache */ 643071Sache#define CISS_INTERRUPT_COALESCE_DELAY 1000 653071Sache#define CISS_INTERRUPT_COALESCE_COUNT 16 663071Sache 673071Sache/* 683071Sache * Heartbeat routine timeout in seconds. Note that since event 693071Sache * handling is performed on a callback basis, we don't need this to 703071Sache * run very often. 713071Sache */ 723071Sache#define CISS_HEARTBEAT_RATE 10 733071Sache 743071Sache/************************************************************************ 753071Sache * Compatibility with older versions of FreeBSD 763071Sache */ 773071Sache#if __FreeBSD_version < 440001 783071Sache#warning testing old-FreeBSD compat 793071Sachetypedef struct proc d_thread_t; 803071Sache#endif 813071Sache 823071Sache/************************************************************************ 833071Sache * Command queue statistics 843071Sache */ 853071Sache 863071Sache#define CISSQ_FREE 0 873071Sache#define CISSQ_BUSY 1 883071Sache#define CISSQ_COMPLETE 2 893071Sache#define CISSQ_NOTIFY 3 903071Sache#define CISSQ_COUNT 4 913071Sache 923071Sachestruct ciss_qstat 933071Sache{ 943071Sache u_int32_t q_length; 953071Sache u_int32_t q_max; 96}; 97 98/************************************************************************ 99 * Driver version. Only really significant to the ACU interface. 100 */ 101#define CISS_DRIVER_VERSION 20011201 102 103/************************************************************************ 104 * Driver data structures 105 */ 106 107/* 108 * Each command issued to the adapter is managed by a request 109 * structure. 110 */ 111struct ciss_request 112{ 113 TAILQ_ENTRY(ciss_request) cr_link; 114 int cr_onq; /* which queue we are on */ 115 116 struct ciss_softc *cr_sc; /* controller softc */ 117 void *cr_data; /* data buffer */ 118 u_int32_t cr_length; /* data length */ 119 bus_dmamap_t cr_datamap; /* DMA map for data */ 120 int cr_tag; 121 int cr_flags; 122#define CISS_REQ_MAPPED (1<<0) /* data mapped */ 123#define CISS_REQ_SLEEP (1<<1) /* submitter sleeping */ 124#define CISS_REQ_POLL (1<<2) /* submitter polling */ 125#define CISS_REQ_DATAOUT (1<<3) /* data host->adapter */ 126#define CISS_REQ_DATAIN (1<<4) /* data adapter->host */ 127 128 void (* cr_complete)(struct ciss_request *); 129 void *cr_private; 130}; 131 132/* 133 * The adapter command structure is defined with a zero-length 134 * scatter/gather list size. In practise, we want space for a 135 * scatter-gather list, and we also want to avoid having commands 136 * cross page boundaries. 137 * 138 * Note that 512 bytes yields 28 scatter/gather entries, or the 139 * ability to map (26 * PAGE_SIZE) + 2 bytes of data. On x86, this is 140 * 104kB. 256 bytes would only yield 12 entries, giving a mere 40kB, 141 * too small. 142 */ 143 144#define CISS_COMMAND_ALLOC_SIZE 512 /* XXX tune to get sensible s/g list length */ 145#define CISS_COMMAND_SG_LENGTH ((CISS_COMMAND_ALLOC_SIZE - sizeof(struct ciss_command)) \ 146 / sizeof(struct ciss_sg_entry)) 147 148/* 149 * Per-logical-drive data. 150 */ 151struct ciss_ldrive 152{ 153 union ciss_device_address cl_address; 154 union ciss_device_address *cl_controller; 155 int cl_status; 156#define CISS_LD_NONEXISTENT 0 157#define CISS_LD_ONLINE 1 158#define CISS_LD_OFFLINE 2 159 160 int cl_update; 161 162 struct ciss_bmic_id_ldrive *cl_ldrive; 163 struct ciss_bmic_id_lstatus *cl_lstatus; 164 struct ciss_ldrive_geometry cl_geometry; 165 166 char cl_name[16]; /* device name */ 167}; 168 169/* 170 * Per-adapter data 171 */ 172struct ciss_softc 173{ 174 /* bus connections */ 175 device_t ciss_dev; /* bus attachment */ 176 struct cdev *ciss_dev_t; /* control device */ 177 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 */ 182 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 */ 189 190 struct resource *ciss_irq_resource; /* interrupt */ 191 int ciss_irq_rid; /* resource ID */ 192 void *ciss_intr; /* interrupt handle */ 193 194 bus_dma_tag_t ciss_parent_dmat; /* parent DMA tag */ 195 bus_dma_tag_t ciss_buffer_dmat; /* data buffer/command DMA tag */ 196 197 u_int32_t ciss_interrupt_mask; /* controller interrupt mask bits */ 198 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 */ 208 TAILQ_HEAD(,ciss_request) ciss_notify; /* requests which are defered for processing */ 209 struct proc *ciss_notify_thread; 210 211 struct callout_handle ciss_periodic; /* periodic event handling */ 212 struct ciss_request *ciss_periodic_notify; /* notify callback request */ 213 214 struct ciss_ldrive **ciss_logical; 215 union ciss_device_address *ciss_controllers; /* controller address */ 216 int ciss_max_bus_number; /* maximum bus number */ 217 218 struct cam_devq *ciss_cam_devq; 219 struct cam_sim **ciss_cam_sim; 220 221 int ciss_flags; 222#define CISS_FLAG_NOTIFY_OK (1<<0) /* notify command running OK */ 223#define CISS_FLAG_CONTROL_OPEN (1<<1) /* control device is open */ 224#define CISS_FLAG_ABORTING (1<<2) /* driver is going away */ 225#define CISS_FLAG_RUNNING (1<<3) /* driver is running (interrupts usable) */ 226 227#define CISS_FLAG_FAKE_SYNCH (1<<16) /* needs SYNCHRONISE_CACHE faked */ 228#define CISS_FLAG_BMIC_ABORT (1<<17) /* use BMIC command to abort Notify on Event */ 229#define CISS_FLAG_THREAD_SHUT (1<<20) /* shutdown the kthread */ 230 231 struct ciss_qstat ciss_qstat[CISSQ_COUNT]; /* queue statistics */ 232}; 233 234/* 235 * Given a request tag, find the corresponding command in virtual or 236 * physical space. 237 * 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. 241 */ 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)) 247 248/************************************************************************ 249 * Debugging/diagnostic output. 250 */ 251 252/* 253 * Debugging levels: 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 258 */ 259#ifdef CISS_DEBUG 260# define debug(level, fmt, args...) \ 261 do { \ 262 if (level <= CISS_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \ 263 } while(0) 264# define debug_called(level) \ 265 do { \ 266 if (level <= CISS_DEBUG) printf("%s: called\n", __func__); \ 267 } while(0) 268# define debug_struct(s) printf(" SIZE %s: %zu\n", #s, sizeof(struct s)) 269# define debug_union(s) printf(" SIZE %s: %zu\n", #s, sizeof(union s)) 270# define debug_type(s) printf(" SIZE %s: %zu\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 %jd/0x%jx\n", #c, (intmax_t)c, (intmax_t)c); 273#else 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) 281#endif 282 283#define ciss_printf(sc, fmt, args...) device_printf(sc->ciss_dev, fmt , ##args) 284 285/************************************************************************ 286 * Queue primitives 287 */ 288 289#define CISSQ_ADD(sc, qname) \ 290 do { \ 291 struct ciss_qstat *qs = &(sc)->ciss_qstat[qname]; \ 292 \ 293 qs->q_length++; \ 294 if (qs->q_length > qs->q_max) \ 295 qs->q_max = qs->q_length; \ 296 } while(0) 297 298#define CISSQ_REMOVE(sc, qname) (sc)->ciss_qstat[qname].q_length-- 299#define CISSQ_INIT(sc, qname) \ 300 do { \ 301 sc->ciss_qstat[qname].q_length = 0; \ 302 sc->ciss_qstat[qname].q_max = 0; \ 303 } while(0) 304 305 306#define CISSQ_REQUEST_QUEUE(name, index) \ 307static __inline void \ 308ciss_initq_ ## name (struct ciss_softc *sc) \ 309{ \ 310 TAILQ_INIT(&sc->ciss_ ## name); \ 311 CISSQ_INIT(sc, index); \ 312} \ 313static __inline void \ 314ciss_enqueue_ ## name (struct ciss_request *cr) \ 315{ \ 316 int s; \ 317 \ 318 s = splcam(); \ 319 TAILQ_INSERT_TAIL(&cr->cr_sc->ciss_ ## name, cr, cr_link); \ 320 CISSQ_ADD(cr->cr_sc, index); \ 321 cr->cr_onq = index; \ 322 splx(s); \ 323} \ 324static __inline void \ 325ciss_requeue_ ## name (struct ciss_request *cr) \ 326{ \ 327 int s; \ 328 \ 329 s = splcam(); \ 330 TAILQ_INSERT_HEAD(&cr->cr_sc->ciss_ ## name, cr, cr_link); \ 331 CISSQ_ADD(cr->cr_sc, index); \ 332 cr->cr_onq = index; \ 333 splx(s); \ 334} \ 335static __inline struct ciss_request * \ 336ciss_dequeue_ ## name (struct ciss_softc *sc) \ 337{ \ 338 struct ciss_request *cr; \ 339 int s; \ 340 \ 341 s = splcam(); \ 342 if ((cr = TAILQ_FIRST(&sc->ciss_ ## name)) != NULL) { \ 343 TAILQ_REMOVE(&sc->ciss_ ## name, cr, cr_link); \ 344 CISSQ_REMOVE(sc, index); \ 345 cr->cr_onq = -1; \ 346 } \ 347 splx(s); \ 348 return(cr); \ 349} \ 350static __inline int \ 351ciss_remove_ ## name (struct ciss_request *cr) \ 352{ \ 353 int s, error; \ 354 \ 355 s = splcam(); \ 356 if (cr->cr_onq != index) { \ 357 printf("request on queue %d (expected %d)\n", cr->cr_onq, index);\ 358 error = 1; \ 359 } else { \ 360 TAILQ_REMOVE(&cr->cr_sc->ciss_ ## name, cr, cr_link); \ 361 CISSQ_REMOVE(cr->cr_sc, index); \ 362 cr->cr_onq = -1; \ 363 error = 0; \ 364 } \ 365 splx(s); \ 366 return(error); \ 367} \ 368struct hack 369 370CISSQ_REQUEST_QUEUE(free, CISSQ_FREE); 371CISSQ_REQUEST_QUEUE(busy, CISSQ_BUSY); 372CISSQ_REQUEST_QUEUE(complete, CISSQ_COMPLETE); 373CISSQ_REQUEST_QUEUE(notify, CISSQ_NOTIFY); 374 375/******************************************************************************** 376 * space-fill a character string 377 */ 378static __inline void 379padstr(char *targ, const char *src, int len) 380{ 381 while (len-- > 0) { 382 if (*src != 0) { 383 *targ++ = *src++; 384 } else { 385 *targ++ = ' '; 386 } 387 } 388} 389