2 * Copyright (c) 2006 IronPort Systems
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
27 * Copyright (c) 2007 LSI Corp.
28 * Copyright (c) 2007 Rajesh Prabhakaran.
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
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.
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
41 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * Redistribution and use in source and binary forms, with or without
54 * modification, are permitted provided that the following conditions
57 * Copyright 1994-2009 The FreeBSD Project.
58 * All rights reserved.
60 * 1. Redistributions of source code must retain the above copyright
61 * notice, this list of conditions and the following disclaimer.
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in the
64 * documentation and/or other materials provided with the distribution.
66 * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT``AS IS'' AND
67 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
68 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR
70 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
71 * EXEMPLARY,OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
72 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
73 * PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY
74 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
75 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
76 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
78 * The views and conclusions contained in the software and documentation
79 * are those of the authors and should not be interpreted as representing
80 * official policies,either expressed or implied, of the FreeBSD Project.
82 * $FreeBSD: src/sys/dev/mfi/mfivar.h,v 1.13 2009/07/10 08:18:08 scottl Exp $
88 #include <sys/devicestat.h>
90 #include <sys/eventhandler.h>
92 #include <sys/sysctl.h>
95 * SCSI structures and definitions are used from here, but no linking
96 * requirements are made to CAM.
98 #include <bus/cam/scsi/scsi_all.h>
103 uint32_t hw_reply_q[1];
111 TAILQ_ENTRY(mfi_command) cm_link;
113 struct mfi_softc *cm_sc;
114 union mfi_frame *cm_frame;
115 #if defined(__x86_64__)
116 uint64_t cm_frame_busaddr;
118 uint32_t cm_frame_busaddr;
120 struct mfi_sense *cm_sense;
121 #if defined(__x86_64__)
122 uint64_t cm_sense_busaddr;
124 uint32_t cm_sense_busaddr;
126 bus_dmamap_t cm_dmamap;
127 union mfi_sgl *cm_sg;
130 int cm_total_frame_size;
133 #define MFI_CMD_MAPPED (1<<0)
134 #define MFI_CMD_DATAIN (1<<1)
135 #define MFI_CMD_DATAOUT (1<<2)
136 #define MFI_CMD_COMPLETED (1<<3)
137 #define MFI_CMD_POLLED (1<<4)
138 #define MFI_ON_MFIQ_FREE (1<<5)
139 #define MFI_ON_MFIQ_READY (1<<6)
140 #define MFI_ON_MFIQ_BUSY (1<<7)
141 #define MFI_ON_MFIQ_MASK ((1<<5)|(1<<6)|(1<<7))
143 void (* cm_complete)(struct mfi_command *cm);
152 * At the moment we rely on mfi_disk and mfi_system_pd having the same size.
153 * A future cleanup should merge them.
156 TAILQ_ENTRY(mfi_disk) ld_link;
160 struct mfi_softc *ld_controller;
161 struct mfi_ld_info *ld_info;
163 struct devstat ld_devstat;
165 #define MFI_DISK_FLAGS_OPEN 0x01
166 #define MFI_DISK_FLAGS_DISABLED 0x02
167 #define MFI_DISK_FLAGS_SYSPD 0x04
170 struct mfi_system_pd {
171 TAILQ_ENTRY(mfi_system_pd) pd_link;
175 struct mfi_softc *pd_controller;
176 struct mfi_pd_info *pd_info;
178 struct devstat pd_devstat;
183 TAILQ_ENTRY(mfi_aen) aen_link;
190 #define MFI_FLAGS_SG64 (1<<0)
191 #define MFI_FLAGS_QFRZN (1<<1)
192 #define MFI_FLAGS_OPEN (1<<2)
193 #define MFI_FLAGS_STOP (1<<3)
194 #define MFI_FLAGS_1064R (1<<4)
195 #define MFI_FLAGS_1078 (1<<5)
196 #define MFI_FLAGS_GEN2 (1<<6)
197 #define MFI_FLAGS_SKINNY (1<<7)
199 struct mfi_hwcomms *mfi_comms;
200 TAILQ_HEAD(,mfi_command) mfi_free;
201 TAILQ_HEAD(,mfi_command) mfi_ready;
202 TAILQ_HEAD(,mfi_command) mfi_busy;
203 struct bio_queue_head mfi_bioq;
204 struct mfi_qstat mfi_qstat[MFIQ_COUNT];
206 struct resource *mfi_regs_resource;
207 bus_space_handle_t mfi_bhandle;
208 bus_space_tag_t mfi_btag;
211 bus_dma_tag_t mfi_parent_dmat;
212 bus_dma_tag_t mfi_buffer_dmat;
214 bus_dma_tag_t mfi_comms_dmat;
215 bus_dmamap_t mfi_comms_dmamap;
216 uint32_t mfi_comms_busaddr;
218 bus_dma_tag_t mfi_frames_dmat;
219 bus_dmamap_t mfi_frames_dmamap;
220 uint32_t mfi_frames_busaddr;
221 union mfi_frame *mfi_frames;
223 TAILQ_HEAD(,mfi_aen) mfi_aen_pids;
224 struct mfi_command *mfi_aen_cm;
225 struct mfi_command *mfi_skinny_cm;
226 uint32_t mfi_aen_triggered;
227 uint32_t mfi_poll_waiting;
228 struct kqinfo mfi_kq;
229 int mfi_delete_busy_volumes;
230 int mfi_keep_deleted_volumes;
233 bus_dma_tag_t mfi_sense_dmat;
234 bus_dmamap_t mfi_sense_dmamap;
235 uint32_t mfi_sense_busaddr;
236 struct mfi_sense *mfi_sense;
238 struct resource *mfi_irq;
242 struct intr_config_hook mfi_ich;
246 * Allocation for the command array. Used as an indexable array to
247 * recover completed commands.
249 struct mfi_command *mfi_commands;
251 * How many commands were actually allocated
255 * How many commands the firmware can handle. Also how big the reply
260 * How many S/G elements we'll ever actually use
264 * How many bytes a compound frame is, including all of the extra frames
265 * that are used for S/G elements.
269 * How large an S/G element is. Used to calculate the number of single
270 * frames in a command.
274 * Max number of sectors that the firmware allows
278 TAILQ_HEAD(,mfi_disk) mfi_ld_tqh;
279 TAILQ_HEAD(,mfi_system_pd) mfi_syspd_tqh;
280 eventhandler_tag mfi_eh;
281 struct cdev *mfi_cdev;
283 TAILQ_HEAD(, ccb_hdr) mfi_cam_ccbq;
284 struct mfi_command * (* mfi_cam_start)(void *);
285 struct callout mfi_watchdog_callout;
286 struct lock mfi_io_lock;
287 struct lock mfi_config_lock;
289 struct sysctl_ctx_list mfi_sysctl_ctx;
290 struct sysctl_oid *mfi_sysctl_tree;
292 /* Controller type specific interfaces */
293 void (*mfi_enable_intr)(struct mfi_softc *sc);
294 int32_t (*mfi_read_fw_status)(struct mfi_softc *sc);
295 int (*mfi_check_clear_intr)(struct mfi_softc *sc);
296 void (*mfi_issue_cmd)(struct mfi_softc *sc,uint32_t bus_add,uint32_t frame_cnt);
299 extern int mfi_attach(struct mfi_softc *);
300 extern void mfi_free(struct mfi_softc *);
301 extern int mfi_shutdown(struct mfi_softc *);
302 extern void mfi_startio(struct mfi_softc *);
303 extern void mfi_disk_complete(struct bio *);
304 extern int mfi_disk_disable(struct mfi_disk *);
305 extern void mfi_disk_enable(struct mfi_disk *);
306 extern int mfi_dump_blocks(struct mfi_softc *, int id, uint64_t, void *, int);
307 extern int mfi_syspd_disable(struct mfi_system_pd *);
308 extern void mfi_syspd_enable(struct mfi_system_pd *);
309 extern int mfi_dump_syspd_blocks(struct mfi_softc *, int id, uint64_t, void *, int);
311 #define MFIQ_ADD(sc, qname) \
313 struct mfi_qstat *qs; \
315 qs = &(sc)->mfi_qstat[qname]; \
317 if (qs->q_length > qs->q_max) \
318 qs->q_max = qs->q_length; \
321 #define MFIQ_REMOVE(sc, qname) (sc)->mfi_qstat[qname].q_length--
323 #define MFIQ_INIT(sc, qname) \
325 sc->mfi_qstat[qname].q_length = 0; \
326 sc->mfi_qstat[qname].q_max = 0; \
329 #define MFIQ_COMMAND_QUEUE(name, index) \
330 static __inline void \
331 mfi_initq_ ## name (struct mfi_softc *sc) \
333 TAILQ_INIT(&sc->mfi_ ## name); \
334 MFIQ_INIT(sc, index); \
336 static __inline void \
337 mfi_enqueue_ ## name (struct mfi_command *cm) \
339 if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) { \
340 kprintf("command %p is on another queue, " \
341 "flags = %#x\n", cm, cm->cm_flags); \
342 panic("command is on another queue"); \
344 TAILQ_INSERT_TAIL(&cm->cm_sc->mfi_ ## name, cm, cm_link); \
345 cm->cm_flags |= MFI_ON_ ## index; \
346 MFIQ_ADD(cm->cm_sc, index); \
348 static __inline void \
349 mfi_requeue_ ## name (struct mfi_command *cm) \
351 if ((cm->cm_flags & MFI_ON_MFIQ_MASK) != 0) { \
352 kprintf("command %p is on another queue, " \
353 "flags = %#x\n", cm, cm->cm_flags); \
354 panic("command is on another queue"); \
356 TAILQ_INSERT_HEAD(&cm->cm_sc->mfi_ ## name, cm, cm_link); \
357 cm->cm_flags |= MFI_ON_ ## index; \
358 MFIQ_ADD(cm->cm_sc, index); \
360 static __inline struct mfi_command * \
361 mfi_dequeue_ ## name (struct mfi_softc *sc) \
363 struct mfi_command *cm; \
365 if ((cm = TAILQ_FIRST(&sc->mfi_ ## name)) != NULL) { \
366 if ((cm->cm_flags & MFI_ON_ ## index) == 0) { \
367 kprintf("command %p not in queue, " \
368 "flags = %#x, bit = %#x\n", cm, \
369 cm->cm_flags, MFI_ON_ ## index); \
370 panic("command not in queue"); \
372 TAILQ_REMOVE(&sc->mfi_ ## name, cm, cm_link); \
373 cm->cm_flags &= ~MFI_ON_ ## index; \
374 MFIQ_REMOVE(sc, index); \
378 static __inline void \
379 mfi_remove_ ## name (struct mfi_command *cm) \
381 if ((cm->cm_flags & MFI_ON_ ## index) == 0) { \
382 kprintf("command %p not in queue, flags = %#x, " \
383 "bit = %#x\n", cm, cm->cm_flags, \
385 panic("command not in queue"); \
387 TAILQ_REMOVE(&cm->cm_sc->mfi_ ## name, cm, cm_link); \
388 cm->cm_flags &= ~MFI_ON_ ## index; \
389 MFIQ_REMOVE(cm->cm_sc, index); \
393 MFIQ_COMMAND_QUEUE(free, MFIQ_FREE);
394 MFIQ_COMMAND_QUEUE(ready, MFIQ_READY);
395 MFIQ_COMMAND_QUEUE(busy, MFIQ_BUSY);
398 mfi_initq_bio(struct mfi_softc *sc)
400 bioq_init(&sc->mfi_bioq);
401 MFIQ_INIT(sc, MFIQ_BIO);
405 mfi_enqueue_bio(struct mfi_softc *sc, struct bio *bp)
407 bioq_insert_tail(&sc->mfi_bioq, bp);
408 MFIQ_ADD(sc, MFIQ_BIO);
411 static __inline struct bio *
412 mfi_dequeue_bio(struct mfi_softc *sc)
416 if ((bp = bioq_first(&sc->mfi_bioq)) != NULL) {
417 bioq_remove(&sc->mfi_bioq, bp);
418 MFIQ_REMOVE(sc, MFIQ_BIO);
424 mfi_print_sense(struct mfi_softc *sc, void *sense)
426 int error, key, asc, ascq;
428 scsi_extract_sense((struct scsi_sense_data *)sense,
429 &error, &key, &asc, &ascq);
430 device_printf(sc->mfi_dev, "sense error %d, sense_key %d, "
431 "asc %d, ascq %d\n", error, key, asc, ascq);
435 #define MFI_WRITE4(sc, reg, val) bus_space_write_4((sc)->mfi_btag, \
436 sc->mfi_bhandle, (reg), (val))
437 #define MFI_READ4(sc, reg) bus_space_read_4((sc)->mfi_btag, \
438 (sc)->mfi_bhandle, (reg))
439 #define MFI_WRITE2(sc, reg, val) bus_space_write_2((sc)->mfi_btag, \
440 sc->mfi_bhandle, (reg), (val))
441 #define MFI_READ2(sc, reg) bus_space_read_2((sc)->mfi_btag, \
442 (sc)->mfi_bhandle, (reg))
443 #define MFI_WRITE1(sc, reg, val) bus_space_write_1((sc)->mfi_btag, \
444 sc->mfi_bhandle, (reg), (val))
445 #define MFI_READ1(sc, reg) bus_space_read_1((sc)->mfi_btag, \
446 (sc)->mfi_bhandle, (reg))
448 MALLOC_DECLARE(M_MFIBUF);
450 #define MFI_CMD_TIMEOUT 30
451 #define MFI_MAXPHYS (128 * 1024)
452 #define SKINNY_MEMORY 0x02000000
455 extern void mfi_print_cmd(struct mfi_command *cm);
456 extern void mfi_dump_cmds(struct mfi_softc *sc);
457 extern void mfi_validate_sg(struct mfi_softc *, struct mfi_command *, const char *, int );
458 #define MFI_PRINT_CMD(cm) mfi_print_cmd(cm)
459 #define MFI_DUMP_CMDS(sc) mfi_dump_cmds(sc)
460 #define MFI_VALIDATE_CMD(sc, cm) mfi_validate_sg(sc, cm, __FUNCTION__, __LINE__)
462 #define MFI_PRINT_CMD(cm)
463 #define MFI_DUMP_CMDS(sc)
464 #define MFI_VALIDATE_CMD(sc, cm)
467 extern void mfi_release_command(struct mfi_command *cm);
469 #endif /* _MFIVAR_H */