xref: /dflybsd-src/sys/dev/disk/mpt/mpt_cam.h (revision f582582c11f73cef1733317743aa98045853bc3f)
1*f582582cSSascha Wildner /* $FreeBSD: head/sys/dev/mpt/mpt_cam.h 203108 2010-01-28 08:41:30Z mav $ */
22545bca0SMatthew Dillon /*-
32545bca0SMatthew Dillon  * LSI MPT Host Adapter FreeBSD Wrapper Definitions (CAM version)
42545bca0SMatthew Dillon  *
52545bca0SMatthew Dillon  * Copyright (c) 2000, 2001 by Greg Ansley, Adam Prewett
62545bca0SMatthew Dillon  *
72545bca0SMatthew Dillon  * Partially derived from Matty Jacobs ISP driver.
82545bca0SMatthew Dillon  *
92545bca0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
102545bca0SMatthew Dillon  * modification, are permitted provided that the following conditions
112545bca0SMatthew Dillon  * are met:
122545bca0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
132545bca0SMatthew Dillon  *    notice immediately at the beginning of the file, without modification,
142545bca0SMatthew Dillon  *    this list of conditions, and the following disclaimer.
152545bca0SMatthew Dillon  * 2. The name of the author may not be used to endorse or promote products
162545bca0SMatthew Dillon  *    derived from this software without specific prior written permission.
172545bca0SMatthew Dillon  *
182545bca0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
192545bca0SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
202545bca0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
212545bca0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
222545bca0SMatthew Dillon  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
232545bca0SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
242545bca0SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
252545bca0SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
262545bca0SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
272545bca0SMatthew Dillon  */
282545bca0SMatthew Dillon /*-
292545bca0SMatthew Dillon  * Copyright (c) 2002, 2006 by Matthew Jacob
302545bca0SMatthew Dillon  * All rights reserved.
312545bca0SMatthew Dillon  *
322545bca0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
332545bca0SMatthew Dillon  * modification, are permitted provided that the following conditions are
342545bca0SMatthew Dillon  * met:
352545bca0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
362545bca0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
372545bca0SMatthew Dillon  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
382545bca0SMatthew Dillon  *    substantially similar to the "NO WARRANTY" disclaimer below
392545bca0SMatthew Dillon  *    ("Disclaimer") and any redistribution must be conditioned upon including
402545bca0SMatthew Dillon  *    a substantially similar Disclaimer requirement for further binary
412545bca0SMatthew Dillon  *    redistribution.
422545bca0SMatthew Dillon  * 3. Neither the names of the above listed copyright holders nor the names
432545bca0SMatthew Dillon  *    of any contributors may be used to endorse or promote products derived
442545bca0SMatthew Dillon  *    from this software without specific prior written permission.
452545bca0SMatthew Dillon  *
462545bca0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
472545bca0SMatthew Dillon  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
482545bca0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
492545bca0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
502545bca0SMatthew Dillon  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
512545bca0SMatthew Dillon  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
522545bca0SMatthew Dillon  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
532545bca0SMatthew Dillon  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
542545bca0SMatthew Dillon  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
552545bca0SMatthew Dillon  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
562545bca0SMatthew Dillon  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
572545bca0SMatthew Dillon  *
582545bca0SMatthew Dillon  * Support from Chris Ellsworth in order to make SAS adapters work
592545bca0SMatthew Dillon  * is gratefully acknowledged.
602545bca0SMatthew Dillon  *
612545bca0SMatthew Dillon  * Support from LSI-Logic has also gone a great deal toward making this a
622545bca0SMatthew Dillon  * workable subsystem and is gratefully acknowledged.
632545bca0SMatthew Dillon  */
642545bca0SMatthew Dillon /*-
652545bca0SMatthew Dillon  * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
662545bca0SMatthew Dillon  * Copyright (c) 2005, WHEEL Sp. z o.o.
672545bca0SMatthew Dillon  * Copyright (c) 2004, 2005 Justin T. Gibbs
682545bca0SMatthew Dillon  * All rights reserved.
692545bca0SMatthew Dillon  *
702545bca0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
712545bca0SMatthew Dillon  * modification, are permitted provided that the following conditions are
722545bca0SMatthew Dillon  * met:
732545bca0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
742545bca0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
752545bca0SMatthew Dillon  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
762545bca0SMatthew Dillon  *    substantially similar to the "NO WARRANTY" disclaimer below
772545bca0SMatthew Dillon  *    ("Disclaimer") and any redistribution must be conditioned upon including
782545bca0SMatthew Dillon  *    a substantially similar Disclaimer requirement for further binary
792545bca0SMatthew Dillon  *    redistribution.
802545bca0SMatthew Dillon  * 3. Neither the names of the above listed copyright holders nor the names
812545bca0SMatthew Dillon  *    of any contributors may be used to endorse or promote products derived
822545bca0SMatthew Dillon  *    from this software without specific prior written permission.
832545bca0SMatthew Dillon  *
842545bca0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
852545bca0SMatthew Dillon  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
862545bca0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
872545bca0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
882545bca0SMatthew Dillon  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
892545bca0SMatthew Dillon  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
902545bca0SMatthew Dillon  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
912545bca0SMatthew Dillon  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
922545bca0SMatthew Dillon  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
932545bca0SMatthew Dillon  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
942545bca0SMatthew Dillon  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
952545bca0SMatthew Dillon  */
962545bca0SMatthew Dillon #ifndef  _MPT_CAM_H_
972545bca0SMatthew Dillon #define  _MPT_CAM_H_
982545bca0SMatthew Dillon 
992545bca0SMatthew Dillon #include <bus/cam/cam.h>
1002545bca0SMatthew Dillon #include <bus/cam/cam_debug.h>
1012545bca0SMatthew Dillon #include <bus/cam/cam_ccb.h>
1022545bca0SMatthew Dillon #include <bus/cam/cam_sim.h>
1032545bca0SMatthew Dillon #include <bus/cam/cam_xpt.h>
1042545bca0SMatthew Dillon #include <bus/cam/cam_periph.h>
1052545bca0SMatthew Dillon #include <bus/cam/cam_xpt_sim.h>
1062545bca0SMatthew Dillon #include <bus/cam/scsi/scsi_all.h>
1072545bca0SMatthew Dillon #include <bus/cam/scsi/scsi_message.h>
1082545bca0SMatthew Dillon 
1092545bca0SMatthew Dillon #define ccb_mpt_ptr sim_priv.entries[0].ptr
1102545bca0SMatthew Dillon #define ccb_req_ptr sim_priv.entries[1].ptr
1112545bca0SMatthew Dillon 
1122545bca0SMatthew Dillon /************************** CCB Manipulation Routines *************************/
1132545bca0SMatthew Dillon static __inline void mpt_freeze_ccb(union ccb *ccb);
1142545bca0SMatthew Dillon static __inline void mpt_set_ccb_status(union ccb *ccb, cam_status status);
1152545bca0SMatthew Dillon 
1162545bca0SMatthew Dillon static __inline void
mpt_freeze_ccb(union ccb * ccb)1172545bca0SMatthew Dillon mpt_freeze_ccb(union ccb *ccb)
1182545bca0SMatthew Dillon {
1192545bca0SMatthew Dillon 	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
1202545bca0SMatthew Dillon 		ccb->ccb_h.status |= CAM_DEV_QFRZN;
1212545bca0SMatthew Dillon 		xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
1222545bca0SMatthew Dillon 	}
1232545bca0SMatthew Dillon }
1242545bca0SMatthew Dillon 
1252545bca0SMatthew Dillon static __inline void
mpt_set_ccb_status(union ccb * ccb,cam_status status)1262545bca0SMatthew Dillon mpt_set_ccb_status(union ccb *ccb, cam_status status)
1272545bca0SMatthew Dillon {
1282545bca0SMatthew Dillon 	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1292545bca0SMatthew Dillon 	ccb->ccb_h.status |= status;
1302545bca0SMatthew Dillon }
1312545bca0SMatthew Dillon 
1322545bca0SMatthew Dillon /****************************** Timeout Recovery ******************************/
1332545bca0SMatthew Dillon /*
1342545bca0SMatthew Dillon  * The longest timeout specified for a Task Managent command.
1352545bca0SMatthew Dillon  */
1362545bca0SMatthew Dillon #define	MPT_TMF_MAX_TIMEOUT	(20000)
1372545bca0SMatthew Dillon 
1382545bca0SMatthew Dillon static __inline void
mpt_wakeup_recovery_thread(struct mpt_softc * mpt)1392545bca0SMatthew Dillon mpt_wakeup_recovery_thread(struct mpt_softc *mpt)
1402545bca0SMatthew Dillon {
1412545bca0SMatthew Dillon 	wakeup(mpt);
1422545bca0SMatthew Dillon }
1432545bca0SMatthew Dillon 
1442545bca0SMatthew Dillon /************************** Version Compatibility *************************/
1452545bca0SMatthew Dillon #define	mpt_sim_alloc(a, b, c, mpt, e, f, g)	\
1462545bca0SMatthew Dillon 	cam_sim_alloc(a, b, c, mpt, (mpt)->unit, &(mpt)->mpt_lock, e, f, g)
1472545bca0SMatthew Dillon #endif /*_MPT_CAM_H_ */
148