1 /*
2  *  Transport specific attributes.
3  *
4  *  Copyright (c) 2003 Silicon Graphics, Inc.  All rights reserved.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #ifndef SCSI_TRANSPORT_H
21 #define SCSI_TRANSPORT_H
22 
23 #include <linux/transport_class.h>
24 #include <linux/blkdev.h>
25 #include <linux/bug.h>
26 #include <scsi/scsi_host.h>
27 #include <scsi/scsi_device.h>
28 
29 struct scsi_transport_template {
30 	/* the attribute containers */
31 	struct transport_container host_attrs;
32 	struct transport_container target_attrs;
33 	struct transport_container device_attrs;
34 
35 	/*
36 	 * If set, called from sysfs and legacy procfs rescanning code.
37 	 */
38 	int (*user_scan)(struct Scsi_Host *, uint, uint, uint);
39 
40 	/* The size of the specific transport attribute structure (a
41 	 * space of this size will be left at the end of the
42 	 * scsi_* structure */
43 	int	device_size;
44 	int	device_private_offset;
45 	int	target_size;
46 	int	target_private_offset;
47 	int	host_size;
48 	/* no private offset for the host; there's an alternative mechanism */
49 
50 	/*
51 	 * True if the transport wants to use a host-based work-queue
52 	 */
53 	unsigned int create_work_queue : 1;
54 
55 	/*
56 	 * Allows a transport to override the default error handler.
57 	 */
58 	void (* eh_strategy_handler)(struct Scsi_Host *);
59 
60 	/*
61 	 * This is an optional routine that allows the transport to become
62 	 * involved when a scsi io timer fires. The return value tells the
63 	 * timer routine how to finish the io timeout handling:
64 	 * EH_HANDLED:		I fixed the error, please complete the command
65 	 * EH_RESET_TIMER:	I need more time, reset the timer and
66 	 *			begin counting again
67 	 * EH_NOT_HANDLED	Begin normal error recovery
68 	 */
69 	enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
70 
71 	/*
72 	 * Used as callback for the completion of i_t_nexus request
73 	 * for target drivers.
74 	 */
75 	int (* it_nexus_response)(struct Scsi_Host *, u64, int);
76 
77 	/*
78 	 * Used as callback for the completion of task management
79 	 * request for target drivers.
80 	 */
81 	int (* tsk_mgmt_response)(struct Scsi_Host *, u64, u64, int);
82 };
83 
84 #define transport_class_to_shost(tc) \
85 	dev_to_shost((tc)->parent)
86 
87 
88 /* Private area maintenance. The driver requested allocations come
89  * directly after the transport class allocations (if any).  The idea
90  * is that you *must* call these only once.  The code assumes that the
91  * initial values are the ones the transport specific code requires */
92 static inline void
scsi_transport_reserve_target(struct scsi_transport_template * t,int space)93 scsi_transport_reserve_target(struct scsi_transport_template * t, int space)
94 {
95 	BUG_ON(t->target_private_offset != 0);
96 	t->target_private_offset = ALIGN(t->target_size, sizeof(void *));
97 	t->target_size = t->target_private_offset + space;
98 }
99 static inline void
scsi_transport_reserve_device(struct scsi_transport_template * t,int space)100 scsi_transport_reserve_device(struct scsi_transport_template * t, int space)
101 {
102 	BUG_ON(t->device_private_offset != 0);
103 	t->device_private_offset = ALIGN(t->device_size, sizeof(void *));
104 	t->device_size = t->device_private_offset + space;
105 }
106 static inline void *
scsi_transport_target_data(struct scsi_target * starget)107 scsi_transport_target_data(struct scsi_target *starget)
108 {
109 	struct Scsi_Host *shost = dev_to_shost(&starget->dev);
110 	return (u8 *)starget->starget_data
111 		+ shost->transportt->target_private_offset;
112 
113 }
114 static inline void *
scsi_transport_device_data(struct scsi_device * sdev)115 scsi_transport_device_data(struct scsi_device *sdev)
116 {
117 	struct Scsi_Host *shost = sdev->host;
118 	return (u8 *)sdev->sdev_data
119 		+ shost->transportt->device_private_offset;
120 }
121 
122 #endif /* SCSI_TRANSPORT_H */
123