mpt_cam.h revision 330897
1/* $FreeBSD: stable/11/sys/dev/mpt/mpt_cam.h 330897 2018-03-14 03:19:51Z eadler $ */
2/*-
3 * LSI MPT Host Adapter FreeBSD Wrapper Definitions (CAM version)
4 *
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-3-Clause
6 *
7 * Copyright (c) 2000, 2001 by Greg Ansley, Adam Prewett
8 *
9 * Partially derived from Matty Jacobs ISP driver.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice immediately at the beginning of the file, without modification,
16 *    this list of conditions, and the following disclaimer.
17 * 2. The name of the author may not be used to endorse or promote products
18 *    derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 */
30/*-
31 * Copyright (c) 2002, 2006 by Matthew Jacob
32 * All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions are
36 * met:
37 * 1. Redistributions of source code must retain the above copyright
38 *    notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
40 *    substantially similar to the "NO WARRANTY" disclaimer below
41 *    ("Disclaimer") and any redistribution must be conditioned upon including
42 *    a substantially similar Disclaimer requirement for further binary
43 *    redistribution.
44 * 3. Neither the names of the above listed copyright holders nor the names
45 *    of any contributors may be used to endorse or promote products derived
46 *    from this software without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
49 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
52 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
58 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *
60 * Support from Chris Ellsworth in order to make SAS adapters work
61 * is gratefully acknowledged.
62 *
63 * Support from LSI-Logic has also gone a great deal toward making this a
64 * workable subsystem and is gratefully acknowledged.
65 */
66/*-
67 * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
68 * Copyright (c) 2005, WHEEL Sp. z o.o.
69 * Copyright (c) 2004, 2005 Justin T. Gibbs
70 * All rights reserved.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions are
74 * met:
75 * 1. Redistributions of source code must retain the above copyright
76 *    notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
78 *    substantially similar to the "NO WARRANTY" disclaimer below
79 *    ("Disclaimer") and any redistribution must be conditioned upon including
80 *    a substantially similar Disclaimer requirement for further binary
81 *    redistribution.
82 * 3. Neither the names of the above listed copyright holders nor the names
83 *    of any contributors may be used to endorse or promote products derived
84 *    from this software without specific prior written permission.
85 *
86 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
90 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
91 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
92 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
93 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
94 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
95 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
96 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 */
98#ifndef  _MPT_CAM_H_
99#define  _MPT_CAM_H_
100
101#include <cam/cam.h>
102#include <cam/cam_debug.h>
103#include <cam/cam_ccb.h>
104#include <cam/cam_sim.h>
105#include <cam/cam_xpt.h>
106#include <cam/cam_periph.h>
107#include <cam/cam_xpt_sim.h>
108#include <cam/cam_debug.h>
109#include <cam/scsi/scsi_all.h>
110#include <cam/scsi/scsi_message.h>
111
112#define ccb_mpt_ptr sim_priv.entries[0].ptr
113#define ccb_req_ptr sim_priv.entries[1].ptr
114
115/************************** CCB Manipulation Routines *************************/
116static __inline void mpt_freeze_ccb(union ccb *ccb);
117static __inline void mpt_set_ccb_status(union ccb *ccb, cam_status status);
118
119static __inline void
120mpt_freeze_ccb(union ccb *ccb)
121{
122	if ((ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
123		ccb->ccb_h.status |= CAM_DEV_QFRZN;
124		xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
125	}
126}
127
128static __inline void
129mpt_set_ccb_status(union ccb *ccb, cam_status status)
130{
131	ccb->ccb_h.status &= ~CAM_STATUS_MASK;
132	ccb->ccb_h.status |= status;
133}
134
135/****************************** Timeout Recovery ******************************/
136/*
137 * The longest timeout specified for a Task Managent command.
138 */
139#define	MPT_TMF_MAX_TIMEOUT	(20000)
140
141static __inline void
142mpt_wakeup_recovery_thread(struct mpt_softc *mpt)
143{
144	wakeup(mpt);
145}
146
147/************************** Version Compatibility *************************/
148#if	__FreeBSD_version < 700031
149#define	mpt_sim_alloc(a, b, c, mpt, e, f, g)	\
150	cam_sim_alloc(a, b, c, mpt, (mpt)->unit, e, f, g)
151#else
152#define	mpt_sim_alloc(a, b, c, mpt, e, f, g)	\
153	cam_sim_alloc(a, b, c, mpt, (mpt)->unit, &(mpt)->mpt_lock, e, f, g)
154#endif
155#endif /*_MPT_CAM_H_ */
156