1147883Sscottl/* $FreeBSD$ */
2147883Sscottl/*-
3147883Sscottl * LSI MPT Host Adapter FreeBSD Wrapper Definitions (CAM version)
4147883Sscottl *
5147883Sscottl * Copyright (c) 2000, 2001 by Greg Ansley, Adam Prewett
6147883Sscottl *
7147883Sscottl * Partially derived from Matty Jacobs ISP driver.
8147883Sscottl *
9147883Sscottl * Redistribution and use in source and binary forms, with or without
10147883Sscottl * modification, are permitted provided that the following conditions
11147883Sscottl * are met:
12147883Sscottl * 1. Redistributions of source code must retain the above copyright
13147883Sscottl *    notice immediately at the beginning of the file, without modification,
14147883Sscottl *    this list of conditions, and the following disclaimer.
15147883Sscottl * 2. The name of the author may not be used to endorse or promote products
16147883Sscottl *    derived from this software without specific prior written permission.
17147883Sscottl *
18147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19147883Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22147883Sscottl * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23147883Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24147883Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25147883Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26147883Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27156000Smjacob */
28156000Smjacob/*-
29156000Smjacob * Copyright (c) 2002, 2006 by Matthew Jacob
30156000Smjacob * All rights reserved.
31156000Smjacob *
32156000Smjacob * Redistribution and use in source and binary forms, with or without
33156000Smjacob * modification, are permitted provided that the following conditions are
34156000Smjacob * met:
35156000Smjacob * 1. Redistributions of source code must retain the above copyright
36156000Smjacob *    notice, this list of conditions and the following disclaimer.
37156000Smjacob * 2. Redistributions in binary form must reproduce at minimum a disclaimer
38156000Smjacob *    substantially similar to the "NO WARRANTY" disclaimer below
39156000Smjacob *    ("Disclaimer") and any redistribution must be conditioned upon including
40156000Smjacob *    a substantially similar Disclaimer requirement for further binary
41156000Smjacob *    redistribution.
42156000Smjacob * 3. Neither the names of the above listed copyright holders nor the names
43156000Smjacob *    of any contributors may be used to endorse or promote products derived
44156000Smjacob *    from this software without specific prior written permission.
45156000Smjacob *
46156000Smjacob * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47156000Smjacob * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48156000Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49156000Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50156000Smjacob * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51156000Smjacob * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52156000Smjacob * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53156000Smjacob * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54156000Smjacob * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55156000Smjacob * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
56156000Smjacob * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57147883Sscottl *
58156000Smjacob * Support from Chris Ellsworth in order to make SAS adapters work
59156000Smjacob * is gratefully acknowledged.
60159052Smjacob *
61159052Smjacob * Support from LSI-Logic has also gone a great deal toward making this a
62159052Smjacob * workable subsystem and is gratefully acknowledged.
63147883Sscottl */
64147883Sscottl/*-
65147883Sscottl * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
66147883Sscottl * Copyright (c) 2005, WHEEL Sp. z o.o.
67147883Sscottl * Copyright (c) 2004, 2005 Justin T. Gibbs
68147883Sscottl * All rights reserved.
69147883Sscottl *
70147883Sscottl * Redistribution and use in source and binary forms, with or without
71147883Sscottl * modification, are permitted provided that the following conditions are
72147883Sscottl * met:
73147883Sscottl * 1. Redistributions of source code must retain the above copyright
74147883Sscottl *    notice, this list of conditions and the following disclaimer.
75147883Sscottl * 2. Redistributions in binary form must reproduce at minimum a disclaimer
76147883Sscottl *    substantially similar to the "NO WARRANTY" disclaimer below
77147883Sscottl *    ("Disclaimer") and any redistribution must be conditioned upon including
78147883Sscottl *    a substantially similar Disclaimer requirement for further binary
79147883Sscottl *    redistribution.
80148679Sgibbs * 3. Neither the names of the above listed copyright holders nor the names
81148679Sgibbs *    of any contributors may be used to endorse or promote products derived
82148679Sgibbs *    from this software without specific prior written permission.
83147883Sscottl *
84147883Sscottl * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
85147883Sscottl * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
86147883Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
87147883Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
88147883Sscottl * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
89147883Sscottl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
90147883Sscottl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
91147883Sscottl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
92147883Sscottl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
93147883Sscottl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
94147883Sscottl * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95147883Sscottl */
96147883Sscottl#ifndef  _MPT_CAM_H_
97147883Sscottl#define  _MPT_CAM_H_
98147883Sscottl
99147883Sscottl#include <cam/cam.h>
100147883Sscottl#include <cam/cam_debug.h>
101147883Sscottl#include <cam/cam_ccb.h>
102147883Sscottl#include <cam/cam_sim.h>
103147883Sscottl#include <cam/cam_xpt.h>
104166897Smjacob#include <cam/cam_periph.h>
105147883Sscottl#include <cam/cam_xpt_sim.h>
106147883Sscottl#include <cam/cam_debug.h>
107147883Sscottl#include <cam/scsi/scsi_all.h>
108147883Sscottl#include <cam/scsi/scsi_message.h>
109147883Sscottl
110147883Sscottl#define ccb_mpt_ptr sim_priv.entries[0].ptr
111147883Sscottl#define ccb_req_ptr sim_priv.entries[1].ptr
112147883Sscottl
113147883Sscottl/************************** CCB Manipulation Routines *************************/
114147883Sscottlstatic __inline void mpt_freeze_ccb(union ccb *ccb);
115147883Sscottlstatic __inline void mpt_set_ccb_status(union ccb *ccb, cam_status status);
116147883Sscottl
117147883Sscottlstatic __inline void
118147883Sscottlmpt_freeze_ccb(union ccb *ccb)
119147883Sscottl{
120147883Sscottl	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
121147883Sscottl		ccb->ccb_h.status |= CAM_DEV_QFRZN;
122147883Sscottl		xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
123147883Sscottl	}
124147883Sscottl}
125147883Sscottl
126147883Sscottlstatic __inline void
127147883Sscottlmpt_set_ccb_status(union ccb *ccb, cam_status status)
128147883Sscottl{
129147883Sscottl	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
130147883Sscottl	ccb->ccb_h.status |= status;
131147883Sscottl}
132147883Sscottl
133147883Sscottl/****************************** Timeout Recovery ******************************/
134147883Sscottl/*
135147883Sscottl * The longest timeout specified for a Task Managent command.
136147883Sscottl */
137147883Sscottl#define	MPT_TMF_MAX_TIMEOUT	(20000)
138147883Sscottl
139147883Sscottlstatic __inline void
140147883Sscottlmpt_wakeup_recovery_thread(struct mpt_softc *mpt)
141147883Sscottl{
142147883Sscottl	wakeup(mpt);
143147883Sscottl}
144147883Sscottl
145169293Smjacob/************************** Version Compatibility *************************/
146169293Smjacob#if	__FreeBSD_version < 700031
147169293Smjacob#define	mpt_sim_alloc(a, b, c, mpt, e, f, g)	\
148169293Smjacob	cam_sim_alloc(a, b, c, mpt, (mpt)->unit, e, f, g)
149169293Smjacob#else
150169293Smjacob#define	mpt_sim_alloc(a, b, c, mpt, e, f, g)	\
151169293Smjacob	cam_sim_alloc(a, b, c, mpt, (mpt)->unit, &(mpt)->mpt_lock, e, f, g)
152169293Smjacob#endif
153147883Sscottl#endif /*_MPT_CAM_H_ */
154