amrvar.h revision 111979
1/*- 2 * Copyright (c) 1999,2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Copyright (c) 2002 Eric Moore 28 * Copyright (c) 2002 LSI Logic Corporation 29 * All rights reserved. 30 * 31 * Redistribution and use in source and binary forms, with or without 32 * modification, are permitted provided that the following conditions 33 * are met: 34 * 1. Redistributions of source code must retain the above copyright 35 * notice, this list of conditions and the following disclaimer. 36 * 2. Redistributions in binary form must reproduce the above copyright 37 * notice, this list of conditions and the following disclaimer in the 38 * documentation and/or other materials provided with the distribution. 39 * 3. The party using or redistributing the source code and binary forms 40 * agrees to the disclaimer below and the terms and conditions set forth 41 * herein. 42 * 43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 * SUCH DAMAGE. 54 * 55 * 56 * $FreeBSD: head/sys/dev/amr/amrvar.h 111979 2003-03-08 08:01:31Z phk $ 57 */ 58 59#if __FreeBSD_version >= 500005 60# include <sys/taskqueue.h> 61#endif 62 63#ifdef AMR_DEBUG 64# define debug(level, fmt, args...) do {if (level <= AMR_DEBUG) printf("%s: " fmt "\n", __func__ , ##args);} while(0) 65# define debug_called(level) do {if (level <= AMR_DEBUG) printf("%s: called\n", __func__);} while(0) 66#else 67# define debug(level, fmt, args...) 68# define debug_called(level) 69#endif 70#define xdebug(fmt, args...) printf("%s: " fmt "\n", __func__ , ##args) 71 72/* 73 * Per-logical-drive datastructure 74 */ 75struct amr_logdrive 76{ 77 u_int32_t al_size; 78 int al_state; 79 int al_properties; 80 81 /* synthetic geometry */ 82 int al_cylinders; 83 int al_heads; 84 int al_sectors; 85 86 /* driver */ 87 device_t al_disk; 88}; 89 90/* 91 * Due to the difficulty of using the zone allocator to create a new 92 * zone from within a module, we use our own clustering to reduce 93 * memory wastage due to allocating lots of these small structures. 94 * 95 * 16k gives us a little under 200 command structures, which should 96 * normally be plenty. We will grab more if we need them. 97 */ 98 99#define AMR_CMD_CLUSTERSIZE (16 * 1024) 100 101/* 102 * Per-command control structure. 103 */ 104struct amr_command 105{ 106 TAILQ_ENTRY(amr_command) ac_link; 107 108 struct amr_softc *ac_sc; 109 u_int8_t ac_slot; 110 int ac_status; /* command completion status */ 111 struct amr_mailbox ac_mailbox; 112 int ac_flags; 113#define AMR_CMD_DATAIN (1<<0) 114#define AMR_CMD_DATAOUT (1<<1) 115#define AMR_CMD_CCB_DATAIN (1<<2) 116#define AMR_CMD_CCB_DATAOUT (1<<3) 117#define AMR_CMD_PRIORITY (1<<4) 118#define AMR_CMD_MAPPED (1<<5) 119#define AMR_CMD_SLEEP (1<<6) 120#define AMR_CMD_BUSY (1<<7) 121 122 struct bio *ac_bio; 123 124 void *ac_data; 125 size_t ac_length; 126 bus_dmamap_t ac_dmamap; 127 u_int32_t ac_dataphys; 128 129 void *ac_ccb_data; 130 size_t ac_ccb_length; 131 bus_dmamap_t ac_ccb_dmamap; 132 u_int32_t ac_ccb_dataphys; 133 134 void (* ac_complete)(struct amr_command *ac); 135 void *ac_private; 136}; 137 138struct amr_command_cluster 139{ 140 TAILQ_ENTRY(amr_command_cluster) acc_link; 141 struct amr_command acc_command[0]; 142}; 143 144#define AMR_CMD_CLUSTERCOUNT ((AMR_CMD_CLUSTERSIZE - sizeof(struct amr_command_cluster)) / \ 145 sizeof(struct amr_command)) 146 147/* 148 * Per-controller-instance data 149 */ 150struct amr_softc 151{ 152 /* bus attachments */ 153 device_t amr_dev; 154 struct resource *amr_reg; /* control registers */ 155 bus_space_handle_t amr_bhandle; 156 bus_space_tag_t amr_btag; 157 bus_dma_tag_t amr_parent_dmat; /* parent DMA tag */ 158 bus_dma_tag_t amr_buffer_dmat; /* data buffer DMA tag */ 159 struct resource *amr_irq; /* interrupt */ 160 void *amr_intr; 161 162 /* mailbox */ 163 volatile struct amr_mailbox *amr_mailbox; 164 volatile struct amr_mailbox64 *amr_mailbox64; 165 u_int32_t amr_mailboxphys; 166 bus_dma_tag_t amr_mailbox_dmat; 167 bus_dmamap_t amr_mailbox_dmamap; 168 169 /* scatter/gather lists and their controller-visible mappings */ 170 struct amr_sgentry *amr_sgtable; /* s/g lists */ 171 u_int32_t amr_sgbusaddr; /* s/g table base address in bus space */ 172 bus_dma_tag_t amr_sg_dmat; /* s/g buffer DMA tag */ 173 bus_dmamap_t amr_sg_dmamap; /* map for s/g buffers */ 174 175 /* controller limits and features */ 176 int amr_maxio; /* maximum number of I/O transactions */ 177 int amr_maxdrives; /* max number of logical drives */ 178 int amr_maxchan; /* count of SCSI channels */ 179 180 /* connected logical drives */ 181 struct amr_logdrive amr_drive[AMR_MAXLD]; 182 183 /* controller state */ 184 int amr_state; 185#define AMR_STATE_OPEN (1<<0) 186#define AMR_STATE_SUSPEND (1<<1) 187#define AMR_STATE_INTEN (1<<2) 188#define AMR_STATE_SHUTDOWN (1<<3) 189 190 /* per-controller queues */ 191 struct bio_queue_head amr_bioq; /* pending I/O with no commands */ 192 TAILQ_HEAD(,amr_command) amr_ready; /* commands ready to be submitted */ 193 struct amr_command *amr_busycmd[AMR_MAXCMD]; 194 int amr_busyslots; 195 TAILQ_HEAD(,amr_command) amr_completed; 196 TAILQ_HEAD(,amr_command) amr_freecmds; 197 TAILQ_HEAD(,amr_command_cluster) amr_cmd_clusters; 198 199 /* CAM attachments for passthrough */ 200 struct cam_sim *amr_cam_sim[AMR_MAX_CHANNELS]; 201 TAILQ_HEAD(, ccb_hdr) amr_cam_ccbq; 202 203 /* control device */ 204 dev_t amr_dev_t; 205 206 /* controller type-specific support */ 207 int amr_type; 208#define AMR_TYPE_QUARTZ (1<<0) 209#define AMR_IS_QUARTZ(sc) ((sc)->amr_type & AMR_TYPE_QUARTZ) 210#define AMR_TYPE_40LD (1<<1) 211#define AMR_IS_40LD(sc) ((sc)->amr_type & AMR_TYPE_40LD) 212 int (* amr_submit_command)(struct amr_softc *sc); 213 int (* amr_get_work)(struct amr_softc *sc, struct amr_mailbox *mbsave); 214 int (*amr_poll_command)(struct amr_command *ac); 215 int support_ext_cdb; /* greater than 10 byte cdb support */ 216 217 /* misc glue */ 218 struct intr_config_hook amr_ich; /* wait-for-interrupts probe hook */ 219 struct callout_handle amr_timeout; /* periodic status check */ 220#if __FreeBSD_version >= 500005 221 struct task amr_task_complete; /* deferred-completion task */ 222#endif 223}; 224 225/* 226 * Interface between bus connections and driver core. 227 */ 228extern int amr_attach(struct amr_softc *sc); 229extern void amr_free(struct amr_softc *sc); 230extern int amr_flush(struct amr_softc *sc); 231extern int amr_done(struct amr_softc *sc); 232extern void amr_startio(struct amr_softc *sc); 233 234/* 235 * Command buffer allocation. 236 */ 237extern struct amr_command *amr_alloccmd(struct amr_softc *sc); 238extern void amr_releasecmd(struct amr_command *ac); 239 240/* 241 * CAM interface 242 */ 243extern int amr_cam_attach(struct amr_softc *sc); 244extern void amr_cam_detach(struct amr_softc *sc); 245extern int amr_cam_command(struct amr_softc *sc, struct amr_command **acp); 246 247/* 248 * MegaRAID logical disk driver 249 */ 250struct amrd_softc 251{ 252 device_t amrd_dev; 253 struct amr_softc *amrd_controller; 254 struct amr_logdrive *amrd_drive; 255 struct disk amrd_disk; 256 int amrd_unit; 257}; 258 259/* 260 * Interface between driver core and disk driver (should be using a bus?) 261 */ 262extern int amr_submit_bio(struct amr_softc *sc, struct bio *bio); 263extern void amrd_intr(void *data); 264 265/******************************************************************************** 266 * Enqueue/dequeue functions 267 */ 268static __inline void 269amr_enqueue_bio(struct amr_softc *sc, struct bio *bio) 270{ 271 int s; 272 273 s = splbio(); 274 bioq_insert_tail(&sc->amr_bioq, bio); 275 splx(s); 276} 277 278static __inline struct bio * 279amr_dequeue_bio(struct amr_softc *sc) 280{ 281 struct bio *bio; 282 int s; 283 284 s = splbio(); 285 if ((bio = bioq_first(&sc->amr_bioq)) != NULL) 286 bioq_remove(&sc->amr_bioq, bio); 287 splx(s); 288 return(bio); 289} 290 291static __inline void 292amr_enqueue_ready(struct amr_command *ac) 293{ 294 int s; 295 296 s = splbio(); 297 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_ready, ac, ac_link); 298 splx(s); 299} 300 301static __inline void 302amr_requeue_ready(struct amr_command *ac) 303{ 304 int s; 305 306 s = splbio(); 307 TAILQ_INSERT_HEAD(&ac->ac_sc->amr_ready, ac, ac_link); 308 splx(s); 309} 310 311static __inline struct amr_command * 312amr_dequeue_ready(struct amr_softc *sc) 313{ 314 struct amr_command *ac; 315 int s; 316 317 s = splbio(); 318 if ((ac = TAILQ_FIRST(&sc->amr_ready)) != NULL) 319 TAILQ_REMOVE(&sc->amr_ready, ac, ac_link); 320 splx(s); 321 return(ac); 322} 323 324static __inline void 325amr_enqueue_completed(struct amr_command *ac) 326{ 327 int s; 328 329 s = splbio(); 330 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_completed, ac, ac_link); 331 splx(s); 332} 333 334static __inline struct amr_command * 335amr_dequeue_completed(struct amr_softc *sc) 336{ 337 struct amr_command *ac; 338 int s; 339 340 s = splbio(); 341 if ((ac = TAILQ_FIRST(&sc->amr_completed)) != NULL) 342 TAILQ_REMOVE(&sc->amr_completed, ac, ac_link); 343 splx(s); 344 return(ac); 345} 346 347static __inline void 348amr_enqueue_free(struct amr_command *ac) 349{ 350 int s; 351 352 s = splbio(); 353 TAILQ_INSERT_TAIL(&ac->ac_sc->amr_freecmds, ac, ac_link); 354 splx(s); 355} 356 357static __inline struct amr_command * 358amr_dequeue_free(struct amr_softc *sc) 359{ 360 struct amr_command *ac; 361 int s; 362 363 s = splbio(); 364 if ((ac = TAILQ_FIRST(&sc->amr_freecmds)) != NULL) 365 TAILQ_REMOVE(&sc->amr_freecmds, ac, ac_link); 366 splx(s); 367 return(ac); 368} 369