1 /*
2  *  linux/drivers/message/fusion/mptscsih.h
3  *      High performance SCSI / Fibre Channel SCSI Host device driver.
4  *      For use with PCI chip/adapter(s):
5  *          LSIFC9xx/LSI409xx Fibre Channel
6  *      running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7  *
8  *  Credits:
9  *      This driver would not exist if not for Alan Cox's development
10  *      of the linux i2o driver.
11  *
12  *      A huge debt of gratitude is owed to David S. Miller (DaveM)
13  *      for fixing much of the stupid and broken stuff in the early
14  *      driver while porting to sparc64 platform.  THANK YOU!
15  *
16  *      (see also mptbase.c)
17  *
18  *  Copyright (c) 1999-2004 LSI Logic Corporation
19  *  Originally By: Steven J. Ralston
20  *  (mailto:sjralston1@netscape.net)
21  *  (mailto:mpt_linux_developer@lsil.com)
22  *
23  *  $Id: mptscsih.h,v 1.1.2.2 2003/05/07 14:08:35 pdelaney Exp $
24  */
25 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
26 /*
27     This program is free software; you can redistribute it and/or modify
28     it under the terms of the GNU General Public License as published by
29     the Free Software Foundation; version 2 of the License.
30 
31     This program is distributed in the hope that it will be useful,
32     but WITHOUT ANY WARRANTY; without even the implied warranty of
33     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34     GNU General Public License for more details.
35 
36     NO WARRANTY
37     THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
38     CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
39     LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
40     MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
41     solely responsible for determining the appropriateness of using and
42     distributing the Program and assumes all risks associated with its
43     exercise of rights under this Agreement, including but not limited to
44     the risks and costs of program errors, damage to or loss of data,
45     programs or equipment, and unavailability or interruption of operations.
46 
47     DISCLAIMER OF LIABILITY
48     NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
49     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50     DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
51     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
52     TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
53     USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
54     HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
55 
56     You should have received a copy of the GNU General Public License
57     along with this program; if not, write to the Free Software
58     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
59 */
60 
61 #ifndef SCSIHOST_H_INCLUDED
62 #define SCSIHOST_H_INCLUDED
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
64 
65 #include "linux/version.h"
66 
67 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
68 /*
69  *	SCSI Public stuff...
70  */
71 
72 /*
73  *	Try to keep these at 2^N-1
74  */
75 #define MPT_FC_CAN_QUEUE	127
76 #if defined MPT_SCSI_USE_NEW_EH
77 	#define MPT_SCSI_CAN_QUEUE	127
78 #else
79 	#define MPT_SCSI_CAN_QUEUE	63
80 #endif
81 
82 #define MPT_SCSI_CMD_PER_DEV_HIGH	31
83 #define MPT_SCSI_CMD_PER_DEV_LOW	7
84 
85 #define MPT_SCSI_CMD_PER_LUN		7
86 
87 #define MPT_SCSI_MAX_SECTORS    8192
88 
89 /*
90  * Set the MAX_SGE value based on user input.
91  */
92 #ifdef  CONFIG_FUSION_MAX_SGE
93 #if     CONFIG_FUSION_MAX_SGE  < 16
94 #define MPT_SCSI_SG_DEPTH	16
95 #elif   CONFIG_FUSION_MAX_SGE  > 128
96 #define MPT_SCSI_SG_DEPTH	128
97 #else
98 #define MPT_SCSI_SG_DEPTH	CONFIG_FUSION_MAX_SGE
99 #endif
100 #else
101 #define MPT_SCSI_SG_DEPTH	40
102 #endif
103 
104 /* To disable domain validation, uncomment the
105  * following line. No effect for FC devices.
106  * For SCSI devices, driver will negotiate to
107  * NVRAM settings (if available) or to maximum adapter
108  * capabilities.
109  */
110 /* #define MPTSCSIH_DISABLE_DOMAIN_VALIDATION */
111 
112 
113 /* SCSI driver setup structure. Settings can be overridden
114  * by command line options.
115  */
116 #define MPTSCSIH_DOMAIN_VALIDATION      1
117 #define MPTSCSIH_MAX_WIDTH              1
118 #define MPTSCSIH_MIN_SYNC               0x08
119 #define MPTSCSIH_SAF_TE                 0
120 
121 struct mptscsih_driver_setup
122 {
123         u8      dv;
124         u8      max_width;
125         u8      min_sync_fac;
126         u8      saf_te;
127 };
128 
129 
130 #define MPTSCSIH_DRIVER_SETUP                   \
131 {                                               \
132         MPTSCSIH_DOMAIN_VALIDATION,             \
133         MPTSCSIH_MAX_WIDTH,                     \
134         MPTSCSIH_MIN_SYNC,                      \
135         MPTSCSIH_SAF_TE,                        \
136 }
137 
138 
139 
140 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
141 /*
142  *	Various bits and pieces broke within the lk-2.4.0-testN series:-(
143  *	So here are various HACKS to work around them.
144  */
145 
146 /*
147  *	Conditionalizing with "#ifdef MODULE/#endif" around:
148  *		static Scsi_Host_Template driver_template = XX;
149  *		#include <../../scsi/scsi_module.c>
150  *	lines was REMOVED @ lk-2.4.0-test9
151  *	Issue discovered 20001213 by: sshirron
152  */
153 #define MPT_SCSIHOST_NEED_ENTRY_EXIT_HOOKUPS			1
154 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,4,0)
155 #	if LINUX_VERSION_CODE == KERNEL_VERSION(2,4,0)
156 		/*
157 		 *	Super HACK!  -by sralston:-(
158 		 *	(good grief; heaven help me!)
159 		 */
160 #		include <linux/capability.h>
161 #		if !defined(CAP_LEASE) && !defined(MODULE)
162 #			undef MPT_SCSIHOST_NEED_ENTRY_EXIT_HOOKUPS
163 #		endif
164 #	else
165 #		ifndef MODULE
166 #			undef MPT_SCSIHOST_NEED_ENTRY_EXIT_HOOKUPS
167 #		endif
168 #	endif
169 #endif
170 
171 /*
172  *	tq_scheduler disappeared @ lk-2.4.0-test12
173  *	(right when <linux/sched.h> newly defined TQ_ACTIVE)
174  *	tq_struct reworked in 2.5.41. Include workqueue.h.
175  */
176 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,41)
177 #	include <linux/sched.h>
178 #	include <linux/workqueue.h>
179 #define SCHEDULE_TASK(x)		\
180 	if (schedule_work(x) == 0) {	\
181 		/*MOD_DEC_USE_COUNT*/;	\
182 	}
183 #else
184 #define HAVE_TQ_SCHED	1
185 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
186 #	include <linux/sched.h>
187 #	ifdef TQ_ACTIVE
188 #		undef HAVE_TQ_SCHED
189 #	endif
190 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,40)
191 #		undef HAVE_TQ_SCHED
192 #endif
193 #endif
194 #ifdef HAVE_TQ_SCHED
195 #define SCHEDULE_TASK(x)		\
196 	/*MOD_INC_USE_COUNT*/;		\
197 	(x)->next = NULL;		\
198 	queue_task(x, &tq_scheduler)
199 #else
200 #define SCHEDULE_TASK(x)		\
201 	/*MOD_INC_USE_COUNT*/;		\
202 	if (schedule_task(x) == 0) {	\
203 		/*MOD_DEC_USE_COUNT*/;	\
204 	}
205 #endif
206 #endif
207 
208 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
209 
210 #define x_scsi_detect		mptscsih_detect
211 #define x_scsi_release		mptscsih_release
212 #define x_scsi_info		mptscsih_info
213 #define x_scsi_queuecommand	mptscsih_qcmd
214 #define x_scsi_abort		mptscsih_abort
215 #define x_scsi_bus_reset	mptscsih_bus_reset
216 #define x_scsi_dev_reset	mptscsih_dev_reset
217 #define x_scsi_host_reset	mptscsih_host_reset
218 #define x_scsi_bios_param	mptscsih_bios_param
219 
220 #define x_scsi_taskmgmt_bh	mptscsih_taskmgmt_bh
221 #define x_scsi_old_abort	mptscsih_old_abort
222 #define x_scsi_old_reset	mptscsih_old_reset
223 #define x_scsi_select_queue_depths	mptscsih_select_queue_depths
224 #define x_scsi_proc_info	mptscsih_proc_info
225 
226 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
227 /*
228  *	MPT SCSI Host / Initiator decls...
229  */
230 extern	int		 x_scsi_detect(Scsi_Host_Template *);
231 extern	int		 x_scsi_release(struct Scsi_Host *host);
232 extern	const char	*x_scsi_info(struct Scsi_Host *);
233 extern	int		 x_scsi_queuecommand(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
234 #ifdef MPT_SCSI_USE_NEW_EH
235 extern	int		 x_scsi_abort(Scsi_Cmnd *);
236 extern	int		 x_scsi_bus_reset(Scsi_Cmnd *);
237 extern	int		 x_scsi_dev_reset(Scsi_Cmnd *);
238 extern	int		 x_scsi_host_reset(Scsi_Cmnd *);
239 #else
240 extern	int		 x_scsi_old_abort(Scsi_Cmnd *);
241 extern	int		 x_scsi_old_reset(Scsi_Cmnd *, unsigned int);
242 #endif
243 extern	int		 x_scsi_bios_param(Disk *, kdev_t, int *);
244 extern	void		 x_scsi_taskmgmt_bh(void *);
245 extern	void		 x_scsi_select_queue_depths(struct Scsi_Host *, Scsi_Device *);
246 extern	int		 x_scsi_proc_info(char *, char **, off_t, int, int, int);
247 
248 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
249 #define PROC_SCSI_DECL
250 #else
251 #define PROC_SCSI_DECL  .proc_name = "mptscsih",
252 #endif
253 
254 #ifdef MPT_SCSI_USE_NEW_EH
255 #define MPT_SCSIHOST {						\
256 	.next				= NULL,			\
257 	PROC_SCSI_DECL						\
258 	.proc_info			= x_scsi_proc_info,	\
259 	.name				= "MPT SCSI Host",	\
260 	.detect				= x_scsi_detect,	\
261 	.release			= x_scsi_release,	\
262 	.info				= x_scsi_info,		\
263 	.command			= NULL,			\
264 	.queuecommand			= x_scsi_queuecommand,	\
265 	.eh_strategy_handler		= NULL,			\
266 	.eh_abort_handler		= x_scsi_abort,		\
267 	.eh_device_reset_handler	= x_scsi_dev_reset,	\
268 	.eh_bus_reset_handler		= x_scsi_bus_reset,	\
269 	.eh_host_reset_handler		= NULL,			\
270 	.bios_param			= x_scsi_bios_param,	\
271 	.can_queue			= MPT_SCSI_CAN_QUEUE,	\
272 	.this_id			= -1,			\
273 	.sg_tablesize			= MPT_SCSI_SG_DEPTH,	\
274 	.cmd_per_lun			= MPT_SCSI_CMD_PER_LUN,	\
275 	.unchecked_isa_dma		= 0,			\
276 	.use_clustering			= ENABLE_CLUSTERING,	\
277 	.use_new_eh_code		= 1			\
278 }
279 
280 #else /* MPT_SCSI_USE_NEW_EH */
281 
282 #define MPT_SCSIHOST {						\
283 	.next				= NULL,			\
284 	PROC_SCSI_DECL						\
285 	.name				= "MPT SCSI Host",	\
286 	.detect				= x_scsi_detect,	\
287 	.release			= x_scsi_release,	\
288 	.info				= x_scsi_info,		\
289 	.command			= NULL,			\
290 	.queuecommand			= x_scsi_queuecommand,	\
291 	.abort				= x_scsi_old_abort,	\
292 	.reset				= x_scsi_old_reset,	\
293 	.bios_param			= x_scsi_bios_param,	\
294 	.can_queue			= MPT_SCSI_CAN_QUEUE,	\
295 	.this_id			= -1,			\
296 	.sg_tablesize			= MPT_SCSI_SG_DEPTH,	\
297 	.cmd_per_lun			= MPT_SCSI_CMD_PER_LUN,	\
298 	.unchecked_isa_dma		= 0,			\
299 	.use_clustering			= ENABLE_CLUSTERING	\
300 }
301 #endif  /* MPT_SCSI_USE_NEW_EH */
302 
303 
304 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
305 
306 /*  include/scsi/scsi.h may not be quite complete...  */
307 #ifndef RESERVE_10
308 #define RESERVE_10		0x56
309 #endif
310 #ifndef RELEASE_10
311 #define RELEASE_10		0x57
312 #endif
313 #ifndef PERSISTENT_RESERVE_IN
314 #define PERSISTENT_RESERVE_IN	0x5e
315 #endif
316 #ifndef PERSISTENT_RESERVE_OUT
317 #define PERSISTENT_RESERVE_OUT	0x5f
318 #endif
319 
320 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
321 
322 #endif
323 
324