diff options
author | Martin Petermann <martin@linux.vnet.ibm.com> | 2008-07-02 04:56:36 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@HansenPartnership.com> | 2008-07-12 09:22:35 -0400 |
commit | f76af7d7e36373179be7a9e09f6b0aae330549b7 (patch) | |
tree | ec6c564a65c1c91386665ba6e45977afd7c40733 /drivers/s390/scsi | |
parent | feac6a07c4a3578bffd6769bb4927e8a7e1f3ffe (diff) |
[SCSI] zfcp: Cleanup of code in zfcp_scsi.c
Cleanup code in zfcp_scsi.c, fix coding style issues and simplify the
code.
Signed-off-by: Martin Petermann <martin@linux.vnet.ibm.com>
Signed-off-by: Christof Schmitt <christof.schmitt@de.ibm.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/s390/scsi')
-rw-r--r-- | drivers/s390/scsi/zfcp_dbf.c | 3 | ||||
-rw-r--r-- | drivers/s390/scsi/zfcp_def.h | 6 | ||||
-rw-r--r-- | drivers/s390/scsi/zfcp_ext.h | 5 | ||||
-rw-r--r-- | drivers/s390/scsi/zfcp_fsf.c | 4 | ||||
-rw-r--r-- | drivers/s390/scsi/zfcp_scsi.c | 555 |
5 files changed, 184 insertions, 389 deletions
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c index 3e9f0abb22f9..566627f3a69d 100644 --- a/drivers/s390/scsi/zfcp_dbf.c +++ b/drivers/s390/scsi/zfcp_dbf.c | |||
@@ -1065,8 +1065,7 @@ static void zfcp_scsi_dbf_event(const char *tag, const char *tag2, int level, | |||
1065 | if (fsf_req != NULL) { | 1065 | if (fsf_req != NULL) { |
1066 | fcp_rsp = (struct fcp_rsp_iu *) | 1066 | fcp_rsp = (struct fcp_rsp_iu *) |
1067 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | 1067 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
1068 | fcp_rsp_info = | 1068 | fcp_rsp_info = (unsigned char *) &fcp_rsp[1]; |
1069 | zfcp_get_fcp_rsp_info_ptr(fcp_rsp); | ||
1070 | fcp_sns_info = | 1069 | fcp_sns_info = |
1071 | zfcp_get_fcp_sns_info_ptr(fcp_rsp); | 1070 | zfcp_get_fcp_sns_info_ptr(fcp_rsp); |
1072 | 1071 | ||
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h index e8383b7331b4..7ac830c39098 100644 --- a/drivers/s390/scsi/zfcp_def.h +++ b/drivers/s390/scsi/zfcp_def.h | |||
@@ -126,12 +126,6 @@ typedef unsigned int fcp_dl_t; | |||
126 | /* timeout for name-server lookup (in seconds) */ | 126 | /* timeout for name-server lookup (in seconds) */ |
127 | #define ZFCP_NS_GID_PN_TIMEOUT 10 | 127 | #define ZFCP_NS_GID_PN_TIMEOUT 10 |
128 | 128 | ||
129 | /* largest SCSI command we can process */ | ||
130 | /* FCP-2 (FCP_CMND IU) allows up to (255-3+16) */ | ||
131 | #define ZFCP_MAX_SCSI_CMND_LENGTH 255 | ||
132 | /* maximum number of commands in LUN queue (tagged queueing) */ | ||
133 | #define ZFCP_CMND_PER_LUN 32 | ||
134 | |||
135 | /* task attribute values in FCP-2 FCP_CMND IU */ | 129 | /* task attribute values in FCP-2 FCP_CMND IU */ |
136 | #define SIMPLE_Q 0 | 130 | #define SIMPLE_Q 0 |
137 | #define HEAD_OF_Q 1 | 131 | #define HEAD_OF_Q 1 |
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h index f95dc99339fd..892476c17ff2 100644 --- a/drivers/s390/scsi/zfcp_ext.h +++ b/drivers/s390/scsi/zfcp_ext.h | |||
@@ -102,13 +102,8 @@ extern void zfcp_test_link(struct zfcp_port *); | |||
102 | extern int zfcp_adapter_scsi_register(struct zfcp_adapter *); | 102 | extern int zfcp_adapter_scsi_register(struct zfcp_adapter *); |
103 | extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *); | 103 | extern void zfcp_adapter_scsi_unregister(struct zfcp_adapter *); |
104 | extern void zfcp_set_fcp_dl(struct fcp_cmnd_iu *, fcp_dl_t); | 104 | extern void zfcp_set_fcp_dl(struct fcp_cmnd_iu *, fcp_dl_t); |
105 | extern char *zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *); | ||
106 | extern char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *); | 105 | extern char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *); |
107 | extern fcp_dl_t zfcp_get_fcp_dl(struct fcp_cmnd_iu *); | ||
108 | 106 | ||
109 | extern int zfcp_scsi_command_async(struct zfcp_adapter *,struct zfcp_unit *, | ||
110 | struct scsi_cmnd *, int); | ||
111 | extern int zfcp_scsi_command_sync(struct zfcp_unit *, struct scsi_cmnd *, int); | ||
112 | extern struct fc_function_template zfcp_transport_functions; | 107 | extern struct fc_function_template zfcp_transport_functions; |
113 | 108 | ||
114 | /******************************** ERP ****************************************/ | 109 | /******************************** ERP ****************************************/ |
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c index 150e78dd00b2..22e3aa612786 100644 --- a/drivers/s390/scsi/zfcp_fsf.c +++ b/drivers/s390/scsi/zfcp_fsf.c | |||
@@ -3027,7 +3027,7 @@ zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req) | |||
3027 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) | 3027 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
3028 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | 3028 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
3029 | u32 sns_len; | 3029 | u32 sns_len; |
3030 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); | 3030 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
3031 | unsigned long flags; | 3031 | unsigned long flags; |
3032 | 3032 | ||
3033 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); | 3033 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); |
@@ -3145,7 +3145,7 @@ zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req) | |||
3145 | int retval = 0; | 3145 | int retval = 0; |
3146 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) | 3146 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) |
3147 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | 3147 | &(fsf_req->qtcb->bottom.io.fcp_rsp); |
3148 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); | 3148 | char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1]; |
3149 | 3149 | ||
3150 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | 3150 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { |
3151 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | 3151 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; |
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c index 160307382d2c..f8594a2e3f5c 100644 --- a/drivers/s390/scsi/zfcp_scsi.c +++ b/drivers/s390/scsi/zfcp_scsi.c | |||
@@ -9,137 +9,32 @@ | |||
9 | #include "zfcp_ext.h" | 9 | #include "zfcp_ext.h" |
10 | #include <asm/atomic.h> | 10 | #include <asm/atomic.h> |
11 | 11 | ||
12 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdp); | ||
13 | static int zfcp_scsi_slave_alloc(struct scsi_device *sdp); | ||
14 | static int zfcp_scsi_slave_configure(struct scsi_device *sdp); | ||
15 | static int zfcp_scsi_queuecommand(struct scsi_cmnd *, | ||
16 | void (*done) (struct scsi_cmnd *)); | ||
17 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *); | ||
18 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *); | ||
19 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *); | ||
20 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *); | ||
21 | static int zfcp_task_management_function(struct zfcp_unit *, u8, | ||
22 | struct scsi_cmnd *); | ||
23 | |||
24 | static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *, int, | ||
25 | unsigned int, unsigned int); | ||
26 | |||
27 | static struct device_attribute *zfcp_sysfs_sdev_attrs[]; | ||
28 | static struct device_attribute *zfcp_a_stats_attrs[]; | ||
29 | |||
30 | struct zfcp_data zfcp_data = { | ||
31 | .scsi_host_template = { | ||
32 | .name = "zfcp", | ||
33 | .module = THIS_MODULE, | ||
34 | .proc_name = "zfcp", | ||
35 | .slave_alloc = zfcp_scsi_slave_alloc, | ||
36 | .slave_configure = zfcp_scsi_slave_configure, | ||
37 | .slave_destroy = zfcp_scsi_slave_destroy, | ||
38 | .queuecommand = zfcp_scsi_queuecommand, | ||
39 | .eh_abort_handler = zfcp_scsi_eh_abort_handler, | ||
40 | .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, | ||
41 | .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, | ||
42 | .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, | ||
43 | .can_queue = 4096, | ||
44 | .this_id = -1, | ||
45 | .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ, | ||
46 | .cmd_per_lun = 1, | ||
47 | .use_clustering = 1, | ||
48 | .sdev_attrs = zfcp_sysfs_sdev_attrs, | ||
49 | .max_sectors = ZFCP_MAX_SECTORS, | ||
50 | .shost_attrs = zfcp_a_stats_attrs, | ||
51 | }, | ||
52 | }; | ||
53 | |||
54 | /* Find start of Response Information in FCP response unit*/ | ||
55 | char * | ||
56 | zfcp_get_fcp_rsp_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) | ||
57 | { | ||
58 | char *fcp_rsp_info_ptr; | ||
59 | |||
60 | fcp_rsp_info_ptr = | ||
61 | (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu)); | ||
62 | |||
63 | return fcp_rsp_info_ptr; | ||
64 | } | ||
65 | |||
66 | /* Find start of Sense Information in FCP response unit*/ | 12 | /* Find start of Sense Information in FCP response unit*/ |
67 | char * | 13 | char *zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) |
68 | zfcp_get_fcp_sns_info_ptr(struct fcp_rsp_iu *fcp_rsp_iu) | ||
69 | { | 14 | { |
70 | char *fcp_sns_info_ptr; | 15 | char *fcp_sns_info_ptr; |
71 | 16 | ||
72 | fcp_sns_info_ptr = | 17 | fcp_sns_info_ptr = (unsigned char *) &fcp_rsp_iu[1]; |
73 | (unsigned char *) fcp_rsp_iu + (sizeof (struct fcp_rsp_iu)); | ||
74 | if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid) | 18 | if (fcp_rsp_iu->validity.bits.fcp_rsp_len_valid) |
75 | fcp_sns_info_ptr = (char *) fcp_sns_info_ptr + | 19 | fcp_sns_info_ptr += fcp_rsp_iu->fcp_rsp_len; |
76 | fcp_rsp_iu->fcp_rsp_len; | ||
77 | 20 | ||
78 | return fcp_sns_info_ptr; | 21 | return fcp_sns_info_ptr; |
79 | } | 22 | } |
80 | 23 | ||
81 | static fcp_dl_t * | 24 | void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl) |
82 | zfcp_get_fcp_dl_ptr(struct fcp_cmnd_iu * fcp_cmd) | ||
83 | { | 25 | { |
84 | int additional_length = fcp_cmd->add_fcp_cdb_length << 2; | 26 | fcp_dl_t *fcp_dl_ptr; |
85 | fcp_dl_t *fcp_dl_addr; | ||
86 | 27 | ||
87 | fcp_dl_addr = (fcp_dl_t *) | ||
88 | ((unsigned char *) fcp_cmd + | ||
89 | sizeof (struct fcp_cmnd_iu) + additional_length); | ||
90 | /* | 28 | /* |
91 | * fcp_dl_addr = start address of fcp_cmnd structure + | 29 | * fcp_dl_addr = start address of fcp_cmnd structure + |
92 | * size of fixed part + size of dynamically sized add_dcp_cdb field | 30 | * size of fixed part + size of dynamically sized add_dcp_cdb field |
93 | * SEE FCP-2 documentation | 31 | * SEE FCP-2 documentation |
94 | */ | 32 | */ |
95 | return fcp_dl_addr; | 33 | fcp_dl_ptr = (fcp_dl_t *) ((unsigned char *) &fcp_cmd[1] + |
96 | } | 34 | (fcp_cmd->add_fcp_cdb_length << 2)); |
97 | 35 | *fcp_dl_ptr = fcp_dl; | |
98 | fcp_dl_t | ||
99 | zfcp_get_fcp_dl(struct fcp_cmnd_iu * fcp_cmd) | ||
100 | { | ||
101 | return *zfcp_get_fcp_dl_ptr(fcp_cmd); | ||
102 | } | ||
103 | |||
104 | void | ||
105 | zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, fcp_dl_t fcp_dl) | ||
106 | { | ||
107 | *zfcp_get_fcp_dl_ptr(fcp_cmd) = fcp_dl; | ||
108 | } | ||
109 | |||
110 | static int | ||
111 | zfcp_scsi_slave_alloc(struct scsi_device *sdp) | ||
112 | { | ||
113 | struct zfcp_adapter *adapter; | ||
114 | struct zfcp_unit *unit; | ||
115 | unsigned long flags; | ||
116 | int retval = -ENXIO; | ||
117 | |||
118 | adapter = (struct zfcp_adapter *) sdp->host->hostdata[0]; | ||
119 | if (!adapter) | ||
120 | goto out; | ||
121 | |||
122 | read_lock_irqsave(&zfcp_data.config_lock, flags); | ||
123 | unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun); | ||
124 | if (unit && atomic_test_mask(ZFCP_STATUS_UNIT_REGISTERED, | ||
125 | &unit->status)) { | ||
126 | sdp->hostdata = unit; | ||
127 | unit->device = sdp; | ||
128 | zfcp_unit_get(unit); | ||
129 | retval = 0; | ||
130 | } | ||
131 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
132 | out: | ||
133 | return retval; | ||
134 | } | 36 | } |
135 | 37 | ||
136 | /** | ||
137 | * zfcp_scsi_slave_destroy - called when scsi device is removed | ||
138 | * | ||
139 | * Remove reference to associated scsi device for an zfcp_unit. | ||
140 | * Mark zfcp_unit as failed. The scsi device might be deleted via sysfs | ||
141 | * or a scan for this device might have failed. | ||
142 | */ | ||
143 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt) | 38 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt) |
144 | { | 39 | { |
145 | struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; | 40 | struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; |
@@ -153,26 +48,16 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt) | |||
153 | } | 48 | } |
154 | } | 49 | } |
155 | 50 | ||
156 | /* | 51 | static int zfcp_scsi_slave_configure(struct scsi_device *sdp) |
157 | * called from scsi midlayer to allow finetuning of a device. | ||
158 | */ | ||
159 | static int | ||
160 | zfcp_scsi_slave_configure(struct scsi_device *sdp) | ||
161 | { | 52 | { |
162 | if (sdp->tagged_supported) | 53 | if (sdp->tagged_supported) |
163 | scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, ZFCP_CMND_PER_LUN); | 54 | scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, 32); |
164 | else | 55 | else |
165 | scsi_adjust_queue_depth(sdp, 0, 1); | 56 | scsi_adjust_queue_depth(sdp, 0, 1); |
166 | return 0; | 57 | return 0; |
167 | } | 58 | } |
168 | 59 | ||
169 | /** | 60 | static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) |
170 | * zfcp_scsi_command_fail - set result in scsi_cmnd and call scsi_done function | ||
171 | * @scpnt: pointer to struct scsi_cmnd where result is set | ||
172 | * @result: result to be set in scpnt (e.g. DID_ERROR) | ||
173 | */ | ||
174 | static void | ||
175 | zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) | ||
176 | { | 61 | { |
177 | set_host_byte(scpnt, result); | 62 | set_host_byte(scpnt, result); |
178 | if ((scpnt->device != NULL) && (scpnt->device->host != NULL)) | 63 | if ((scpnt->device != NULL) && (scpnt->device->host != NULL)) |
@@ -183,104 +68,13 @@ zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) | |||
183 | scpnt->scsi_done(scpnt); | 68 | scpnt->scsi_done(scpnt); |
184 | } | 69 | } |
185 | 70 | ||
186 | /** | 71 | static int zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt, |
187 | * zfcp_scsi_command_async - worker for zfcp_scsi_queuecommand and | 72 | void (*done) (struct scsi_cmnd *)) |
188 | * zfcp_scsi_command_sync | ||
189 | * @adapter: adapter where scsi command is issued | ||
190 | * @unit: unit to which scsi command is sent | ||
191 | * @scpnt: scsi command to be sent | ||
192 | * @timer: timer to be started if request is successfully initiated | ||
193 | * | ||
194 | * Note: In scsi_done function must be set in scpnt. | ||
195 | */ | ||
196 | int | ||
197 | zfcp_scsi_command_async(struct zfcp_adapter *adapter, struct zfcp_unit *unit, | ||
198 | struct scsi_cmnd *scpnt, int use_timer) | ||
199 | { | ||
200 | int tmp; | ||
201 | int retval; | ||
202 | |||
203 | retval = 0; | ||
204 | |||
205 | BUG_ON((adapter == NULL) || (adapter != unit->port->adapter)); | ||
206 | BUG_ON(scpnt->scsi_done == NULL); | ||
207 | |||
208 | if (unlikely(NULL == unit)) { | ||
209 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); | ||
210 | goto out; | ||
211 | } | ||
212 | |||
213 | if (unlikely( | ||
214 | atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status) || | ||
215 | !atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, &unit->status))) { | ||
216 | zfcp_scsi_command_fail(scpnt, DID_ERROR); | ||
217 | goto out; | ||
218 | } | ||
219 | |||
220 | tmp = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, use_timer, | ||
221 | ZFCP_REQ_AUTO_CLEANUP); | ||
222 | if (unlikely(tmp == -EBUSY)) { | ||
223 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); | ||
224 | goto out; | ||
225 | } | ||
226 | |||
227 | if (unlikely(tmp < 0)) | ||
228 | retval = SCSI_MLQUEUE_HOST_BUSY; | ||
229 | |||
230 | out: | ||
231 | return retval; | ||
232 | } | ||
233 | |||
234 | static void | ||
235 | zfcp_scsi_command_sync_handler(struct scsi_cmnd *scpnt) | ||
236 | { | ||
237 | struct completion *wait = (struct completion *) scpnt->SCp.ptr; | ||
238 | complete(wait); | ||
239 | } | ||
240 | |||
241 | |||
242 | /** | ||
243 | * zfcp_scsi_command_sync - send a SCSI command and wait for completion | ||
244 | * @unit: unit where command is sent to | ||
245 | * @scpnt: scsi command to be sent | ||
246 | * @use_timer: indicates whether timer should be setup or not | ||
247 | * Return: 0 | ||
248 | * | ||
249 | * Errors are indicated in scpnt->result | ||
250 | */ | ||
251 | int | ||
252 | zfcp_scsi_command_sync(struct zfcp_unit *unit, struct scsi_cmnd *scpnt, | ||
253 | int use_timer) | ||
254 | { | ||
255 | int ret; | ||
256 | DECLARE_COMPLETION_ONSTACK(wait); | ||
257 | |||
258 | scpnt->SCp.ptr = (void *) &wait; /* silent re-use */ | ||
259 | scpnt->scsi_done = zfcp_scsi_command_sync_handler; | ||
260 | ret = zfcp_scsi_command_async(unit->port->adapter, unit, scpnt, | ||
261 | use_timer); | ||
262 | if (ret == 0) | ||
263 | wait_for_completion(&wait); | ||
264 | |||
265 | scpnt->SCp.ptr = NULL; | ||
266 | |||
267 | return 0; | ||
268 | } | ||
269 | |||
270 | /* | ||
271 | * function: zfcp_scsi_queuecommand | ||
272 | * | ||
273 | * purpose: enqueues a SCSI command to the specified target device | ||
274 | * | ||
275 | * returns: 0 - success, SCSI command enqueued | ||
276 | * !0 - failure | ||
277 | */ | ||
278 | static int | ||
279 | zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt, | ||
280 | void (*done) (struct scsi_cmnd *)) | ||
281 | { | 73 | { |
282 | struct zfcp_unit *unit; | 74 | struct zfcp_unit *unit; |
283 | struct zfcp_adapter *adapter; | 75 | struct zfcp_adapter *adapter; |
76 | int status; | ||
77 | int ret; | ||
284 | 78 | ||
285 | /* reset the status for this request */ | 79 | /* reset the status for this request */ |
286 | scpnt->result = 0; | 80 | scpnt->result = 0; |
@@ -292,44 +86,76 @@ zfcp_scsi_queuecommand(struct scsi_cmnd *scpnt, | |||
292 | * (stored there by zfcp_scsi_slave_alloc) | 86 | * (stored there by zfcp_scsi_slave_alloc) |
293 | */ | 87 | */ |
294 | adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0]; | 88 | adapter = (struct zfcp_adapter *) scpnt->device->host->hostdata[0]; |
295 | unit = (struct zfcp_unit *) scpnt->device->hostdata; | 89 | unit = scpnt->device->hostdata; |
90 | |||
91 | BUG_ON(!adapter || (adapter != unit->port->adapter)); | ||
92 | BUG_ON(!scpnt->scsi_done); | ||
93 | |||
94 | if (unlikely(!unit)) { | ||
95 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | status = atomic_read(&unit->status); | ||
100 | if (unlikely((status & ZFCP_STATUS_COMMON_ERP_FAILED) || | ||
101 | !(status & ZFCP_STATUS_COMMON_RUNNING))) { | ||
102 | zfcp_scsi_command_fail(scpnt, DID_ERROR); | ||
103 | return 0;; | ||
104 | } | ||
105 | |||
106 | ret = zfcp_fsf_send_fcp_command_task(adapter, unit, scpnt, 0, | ||
107 | ZFCP_REQ_AUTO_CLEANUP); | ||
108 | if (unlikely(ret == -EBUSY)) | ||
109 | zfcp_scsi_command_fail(scpnt, DID_NO_CONNECT); | ||
110 | else if (unlikely(ret < 0)) | ||
111 | return SCSI_MLQUEUE_HOST_BUSY; | ||
296 | 112 | ||
297 | return zfcp_scsi_command_async(adapter, unit, scpnt, 0); | 113 | return ret; |
298 | } | 114 | } |
299 | 115 | ||
300 | static struct zfcp_unit * | 116 | static struct zfcp_unit *zfcp_unit_lookup(struct zfcp_adapter *adapter, |
301 | zfcp_unit_lookup(struct zfcp_adapter *adapter, int channel, unsigned int id, | 117 | int channel, unsigned int id, |
302 | unsigned int lun) | 118 | unsigned int lun) |
303 | { | 119 | { |
304 | struct zfcp_port *port; | 120 | struct zfcp_port *port; |
305 | struct zfcp_unit *unit, *retval = NULL; | 121 | struct zfcp_unit *unit; |
306 | 122 | ||
307 | list_for_each_entry(port, &adapter->port_list_head, list) { | 123 | list_for_each_entry(port, &adapter->port_list_head, list) { |
308 | if (!port->rport || (id != port->rport->scsi_target_id)) | 124 | if (!port->rport || (id != port->rport->scsi_target_id)) |
309 | continue; | 125 | continue; |
310 | list_for_each_entry(unit, &port->unit_list_head, list) | 126 | list_for_each_entry(unit, &port->unit_list_head, list) |
311 | if (lun == unit->scsi_lun) { | 127 | if (lun == unit->scsi_lun) |
312 | retval = unit; | 128 | return unit; |
313 | goto out; | ||
314 | } | ||
315 | } | 129 | } |
316 | out: | 130 | |
131 | return NULL; | ||
132 | } | ||
133 | |||
134 | static int zfcp_scsi_slave_alloc(struct scsi_device *sdp) | ||
135 | { | ||
136 | struct zfcp_adapter *adapter; | ||
137 | struct zfcp_unit *unit; | ||
138 | unsigned long flags; | ||
139 | int retval = -ENXIO; | ||
140 | |||
141 | adapter = (struct zfcp_adapter *) sdp->host->hostdata[0]; | ||
142 | if (!adapter) | ||
143 | goto out; | ||
144 | |||
145 | read_lock_irqsave(&zfcp_data.config_lock, flags); | ||
146 | unit = zfcp_unit_lookup(adapter, sdp->channel, sdp->id, sdp->lun); | ||
147 | if (unit && | ||
148 | (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_REGISTERED)) { | ||
149 | sdp->hostdata = unit; | ||
150 | unit->device = sdp; | ||
151 | zfcp_unit_get(unit); | ||
152 | retval = 0; | ||
153 | } | ||
154 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | ||
155 | out: | ||
317 | return retval; | 156 | return retval; |
318 | } | 157 | } |
319 | 158 | ||
320 | /** | ||
321 | * zfcp_scsi_eh_abort_handler - abort the specified SCSI command | ||
322 | * @scpnt: pointer to scsi_cmnd to be aborted | ||
323 | * Return: SUCCESS - command has been aborted and cleaned up in internal | ||
324 | * bookkeeping, SCSI stack won't be called for aborted command | ||
325 | * FAILED - otherwise | ||
326 | * | ||
327 | * We do not need to care for a SCSI command which completes normally | ||
328 | * but late during this abort routine runs. We are allowed to return | ||
329 | * late commands to the SCSI stack. It tracks the state of commands and | ||
330 | * will handle late commands. (Usually, the normal completion of late | ||
331 | * commands is ignored with respect to the running abort operation.) | ||
332 | */ | ||
333 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) | 159 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) |
334 | { | 160 | { |
335 | struct Scsi_Host *scsi_host; | 161 | struct Scsi_Host *scsi_host; |
@@ -337,30 +163,27 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) | |||
337 | struct zfcp_unit *unit; | 163 | struct zfcp_unit *unit; |
338 | struct zfcp_fsf_req *fsf_req; | 164 | struct zfcp_fsf_req *fsf_req; |
339 | unsigned long flags; | 165 | unsigned long flags; |
340 | unsigned long old_req_id; | 166 | unsigned long old_req_id = (unsigned long) scpnt->host_scribble; |
341 | int retval = SUCCESS; | 167 | int retval = SUCCESS; |
342 | 168 | ||
343 | scsi_host = scpnt->device->host; | 169 | scsi_host = scpnt->device->host; |
344 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; | 170 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
345 | unit = (struct zfcp_unit *) scpnt->device->hostdata; | 171 | unit = scpnt->device->hostdata; |
346 | 172 | ||
347 | /* avoid race condition between late normal completion and abort */ | 173 | /* avoid race condition between late normal completion and abort */ |
348 | write_lock_irqsave(&adapter->abort_lock, flags); | 174 | write_lock_irqsave(&adapter->abort_lock, flags); |
349 | 175 | ||
350 | /* Check whether corresponding fsf_req is still pending */ | 176 | /* Check whether corresponding fsf_req is still pending */ |
351 | spin_lock(&adapter->req_list_lock); | 177 | spin_lock(&adapter->req_list_lock); |
352 | fsf_req = zfcp_reqlist_find(adapter, | 178 | fsf_req = zfcp_reqlist_find(adapter, old_req_id); |
353 | (unsigned long) scpnt->host_scribble); | ||
354 | spin_unlock(&adapter->req_list_lock); | 179 | spin_unlock(&adapter->req_list_lock); |
355 | if (!fsf_req) { | 180 | if (!fsf_req) { |
356 | write_unlock_irqrestore(&adapter->abort_lock, flags); | 181 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
357 | zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, 0); | 182 | zfcp_scsi_dbf_event_abort("lte1", adapter, scpnt, NULL, 0); |
358 | retval = SUCCESS; | 183 | return retval; |
359 | goto out; | ||
360 | } | 184 | } |
361 | fsf_req->data = 0; | 185 | fsf_req->data = 0; |
362 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING; | 186 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTING; |
363 | old_req_id = fsf_req->req_id; | ||
364 | 187 | ||
365 | /* don't access old fsf_req after releasing the abort_lock */ | 188 | /* don't access old fsf_req after releasing the abort_lock */ |
366 | write_unlock_irqrestore(&adapter->abort_lock, flags); | 189 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
@@ -370,7 +193,7 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) | |||
370 | zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL, | 193 | zfcp_scsi_dbf_event_abort("nres", adapter, scpnt, NULL, |
371 | old_req_id); | 194 | old_req_id); |
372 | retval = FAILED; | 195 | retval = FAILED; |
373 | goto out; | 196 | return retval; |
374 | } | 197 | } |
375 | 198 | ||
376 | __wait_event(fsf_req->completion_wq, | 199 | __wait_event(fsf_req->completion_wq, |
@@ -378,62 +201,30 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) | |||
378 | 201 | ||
379 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) { | 202 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) { |
380 | zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, fsf_req, 0); | 203 | zfcp_scsi_dbf_event_abort("okay", adapter, scpnt, fsf_req, 0); |
381 | retval = SUCCESS; | ||
382 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) { | 204 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) { |
383 | zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, fsf_req, 0); | 205 | zfcp_scsi_dbf_event_abort("lte2", adapter, scpnt, fsf_req, 0); |
384 | retval = SUCCESS; | ||
385 | } else { | 206 | } else { |
386 | zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, fsf_req, 0); | 207 | zfcp_scsi_dbf_event_abort("fail", adapter, scpnt, fsf_req, 0); |
387 | retval = FAILED; | 208 | retval = FAILED; |
388 | } | 209 | } |
389 | zfcp_fsf_req_free(fsf_req); | 210 | zfcp_fsf_req_free(fsf_req); |
390 | out: | ||
391 | return retval; | ||
392 | } | ||
393 | |||
394 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) | ||
395 | { | ||
396 | int retval; | ||
397 | struct zfcp_unit *unit = scpnt->device->hostdata; | ||
398 | 211 | ||
399 | if (!unit) { | 212 | return retval; |
400 | WARN_ON(1); | ||
401 | return SUCCESS; | ||
402 | } | ||
403 | retval = zfcp_task_management_function(unit, | ||
404 | FCP_LOGICAL_UNIT_RESET, | ||
405 | scpnt); | ||
406 | return retval ? FAILED : SUCCESS; | ||
407 | } | ||
408 | |||
409 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) | ||
410 | { | ||
411 | int retval; | ||
412 | struct zfcp_unit *unit = scpnt->device->hostdata; | ||
413 | |||
414 | if (!unit) { | ||
415 | WARN_ON(1); | ||
416 | return SUCCESS; | ||
417 | } | ||
418 | retval = zfcp_task_management_function(unit, FCP_TARGET_RESET, scpnt); | ||
419 | return retval ? FAILED : SUCCESS; | ||
420 | } | 213 | } |
421 | 214 | ||
422 | static int | 215 | static int zfcp_task_mgmt_function(struct zfcp_unit *unit, u8 tm_flags, |
423 | zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags, | 216 | struct scsi_cmnd *scpnt) |
424 | struct scsi_cmnd *scpnt) | ||
425 | { | 217 | { |
426 | struct zfcp_adapter *adapter = unit->port->adapter; | 218 | struct zfcp_adapter *adapter = unit->port->adapter; |
427 | struct zfcp_fsf_req *fsf_req; | 219 | struct zfcp_fsf_req *fsf_req; |
428 | int retval = 0; | 220 | int retval = SUCCESS; |
429 | 221 | ||
430 | /* issue task management function */ | 222 | /* issue task management function */ |
431 | fsf_req = zfcp_fsf_send_fcp_command_task_management | 223 | fsf_req = zfcp_fsf_send_fcp_command_task_management |
432 | (adapter, unit, tm_flags, 0); | 224 | (adapter, unit, tm_flags, 0); |
433 | if (!fsf_req) { | 225 | if (!fsf_req) { |
434 | zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt); | 226 | zfcp_scsi_dbf_event_devreset("nres", tm_flags, unit, scpnt); |
435 | retval = -ENOMEM; | 227 | return FAILED; |
436 | goto out; | ||
437 | } | 228 | } |
438 | 229 | ||
439 | __wait_event(fsf_req->completion_wq, | 230 | __wait_event(fsf_req->completion_wq, |
@@ -444,27 +235,46 @@ zfcp_task_management_function(struct zfcp_unit *unit, u8 tm_flags, | |||
444 | */ | 235 | */ |
445 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { | 236 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { |
446 | zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt); | 237 | zfcp_scsi_dbf_event_devreset("fail", tm_flags, unit, scpnt); |
447 | retval = -EIO; | 238 | retval = FAILED; |
448 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) { | 239 | } else if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP) { |
449 | zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt); | 240 | zfcp_scsi_dbf_event_devreset("nsup", tm_flags, unit, scpnt); |
450 | retval = -ENOTSUPP; | 241 | retval = FAILED; |
451 | } else | 242 | } else |
452 | zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt); | 243 | zfcp_scsi_dbf_event_devreset("okay", tm_flags, unit, scpnt); |
453 | 244 | ||
454 | zfcp_fsf_req_free(fsf_req); | 245 | zfcp_fsf_req_free(fsf_req); |
455 | out: | 246 | |
456 | return retval; | 247 | return retval; |
457 | } | 248 | } |
458 | 249 | ||
459 | /** | 250 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) |
460 | * zfcp_scsi_eh_host_reset_handler - handler for host reset | 251 | { |
461 | */ | 252 | struct zfcp_unit *unit = scpnt->device->hostdata; |
253 | |||
254 | if (!unit) { | ||
255 | WARN_ON(1); | ||
256 | return SUCCESS; | ||
257 | } | ||
258 | return zfcp_task_mgmt_function(unit, FCP_LOGICAL_UNIT_RESET, scpnt); | ||
259 | } | ||
260 | |||
261 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) | ||
262 | { | ||
263 | struct zfcp_unit *unit = scpnt->device->hostdata; | ||
264 | |||
265 | if (!unit) { | ||
266 | WARN_ON(1); | ||
267 | return SUCCESS; | ||
268 | } | ||
269 | return zfcp_task_mgmt_function(unit, FCP_TARGET_RESET, scpnt); | ||
270 | } | ||
271 | |||
462 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) | 272 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) |
463 | { | 273 | { |
464 | struct zfcp_unit *unit; | 274 | struct zfcp_unit *unit; |
465 | struct zfcp_adapter *adapter; | 275 | struct zfcp_adapter *adapter; |
466 | 276 | ||
467 | unit = (struct zfcp_unit*) scpnt->device->hostdata; | 277 | unit = scpnt->device->hostdata; |
468 | adapter = unit->port->adapter; | 278 | adapter = unit->port->adapter; |
469 | zfcp_erp_adapter_reopen(adapter, 0, 141, scpnt); | 279 | zfcp_erp_adapter_reopen(adapter, 0, 141, scpnt); |
470 | zfcp_erp_wait(adapter); | 280 | zfcp_erp_wait(adapter); |
@@ -472,51 +282,43 @@ static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) | |||
472 | return SUCCESS; | 282 | return SUCCESS; |
473 | } | 283 | } |
474 | 284 | ||
475 | int | 285 | int zfcp_adapter_scsi_register(struct zfcp_adapter *adapter) |
476 | zfcp_adapter_scsi_register(struct zfcp_adapter *adapter) | ||
477 | { | 286 | { |
478 | int retval = 0; | 287 | struct ccw_dev_id dev_id; |
479 | static unsigned int unique_id = 0; | ||
480 | 288 | ||
481 | if (adapter->scsi_host) | 289 | if (adapter->scsi_host) |
482 | goto out; | 290 | return 0; |
483 | 291 | ||
292 | ccw_device_get_id(adapter->ccw_device, &dev_id); | ||
484 | /* register adapter as SCSI host with mid layer of SCSI stack */ | 293 | /* register adapter as SCSI host with mid layer of SCSI stack */ |
485 | adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template, | 294 | adapter->scsi_host = scsi_host_alloc(&zfcp_data.scsi_host_template, |
486 | sizeof (struct zfcp_adapter *)); | 295 | sizeof (struct zfcp_adapter *)); |
487 | if (!adapter->scsi_host) { | 296 | if (!adapter->scsi_host) { |
488 | dev_err(&adapter->ccw_device->dev, | 297 | dev_err(&adapter->ccw_device->dev, |
489 | "registration with SCSI stack failed."); | 298 | "registration with SCSI stack failed."); |
490 | retval = -EIO; | 299 | return -EIO; |
491 | goto out; | ||
492 | } | 300 | } |
493 | 301 | ||
494 | /* tell the SCSI stack some characteristics of this adapter */ | 302 | /* tell the SCSI stack some characteristics of this adapter */ |
495 | adapter->scsi_host->max_id = 1; | 303 | adapter->scsi_host->max_id = 1; |
496 | adapter->scsi_host->max_lun = 1; | 304 | adapter->scsi_host->max_lun = 1; |
497 | adapter->scsi_host->max_channel = 0; | 305 | adapter->scsi_host->max_channel = 0; |
498 | adapter->scsi_host->unique_id = unique_id++; /* FIXME */ | 306 | adapter->scsi_host->unique_id = dev_id.devno; |
499 | adapter->scsi_host->max_cmd_len = ZFCP_MAX_SCSI_CMND_LENGTH; | 307 | adapter->scsi_host->max_cmd_len = 255; |
500 | adapter->scsi_host->transportt = zfcp_data.scsi_transport_template; | 308 | adapter->scsi_host->transportt = zfcp_data.scsi_transport_template; |
501 | 309 | ||
502 | /* | ||
503 | * save a pointer to our own adapter data structure within | ||
504 | * hostdata field of SCSI host data structure | ||
505 | */ | ||
506 | adapter->scsi_host->hostdata[0] = (unsigned long) adapter; | 310 | adapter->scsi_host->hostdata[0] = (unsigned long) adapter; |
507 | 311 | ||
508 | if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { | 312 | if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { |
509 | scsi_host_put(adapter->scsi_host); | 313 | scsi_host_put(adapter->scsi_host); |
510 | retval = -EIO; | 314 | return -EIO; |
511 | goto out; | ||
512 | } | 315 | } |
513 | atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status); | 316 | atomic_set_mask(ZFCP_STATUS_ADAPTER_REGISTERED, &adapter->status); |
514 | out: | 317 | |
515 | return retval; | 318 | return 0; |
516 | } | 319 | } |
517 | 320 | ||
518 | void | 321 | void zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) |
519 | zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) | ||
520 | { | 322 | { |
521 | struct Scsi_Host *shost; | 323 | struct Scsi_Host *shost; |
522 | struct zfcp_port *port; | 324 | struct zfcp_port *port; |
@@ -524,10 +326,12 @@ zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) | |||
524 | shost = adapter->scsi_host; | 326 | shost = adapter->scsi_host; |
525 | if (!shost) | 327 | if (!shost) |
526 | return; | 328 | return; |
329 | |||
527 | read_lock_irq(&zfcp_data.config_lock); | 330 | read_lock_irq(&zfcp_data.config_lock); |
528 | list_for_each_entry(port, &adapter->port_list_head, list) | 331 | list_for_each_entry(port, &adapter->port_list_head, list) |
529 | if (port->rport) | 332 | if (port->rport) |
530 | port->rport = NULL; | 333 | port->rport = NULL; |
334 | |||
531 | read_unlock_irq(&zfcp_data.config_lock); | 335 | read_unlock_irq(&zfcp_data.config_lock); |
532 | fc_remove_host(shost); | 336 | fc_remove_host(shost); |
533 | scsi_remove_host(shost); | 337 | scsi_remove_host(shost); |
@@ -538,9 +342,6 @@ zfcp_adapter_scsi_unregister(struct zfcp_adapter *adapter) | |||
538 | return; | 342 | return; |
539 | } | 343 | } |
540 | 344 | ||
541 | /* | ||
542 | * Support functions for FC transport class | ||
543 | */ | ||
544 | static struct fc_host_statistics* | 345 | static struct fc_host_statistics* |
545 | zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) | 346 | zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) |
546 | { | 347 | { |
@@ -556,13 +357,12 @@ zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) | |||
556 | return adapter->fc_stats; | 357 | return adapter->fc_stats; |
557 | } | 358 | } |
558 | 359 | ||
559 | static void | 360 | static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, |
560 | zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, | 361 | struct fsf_qtcb_bottom_port *data, |
561 | struct fsf_qtcb_bottom_port *data, | 362 | struct fsf_qtcb_bottom_port *old) |
562 | struct fsf_qtcb_bottom_port *old) | ||
563 | { | 363 | { |
564 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset - | 364 | fc_stats->seconds_since_last_reset = |
565 | old->seconds_since_last_reset; | 365 | data->seconds_since_last_reset - old->seconds_since_last_reset; |
566 | fc_stats->tx_frames = data->tx_frames - old->tx_frames; | 366 | fc_stats->tx_frames = data->tx_frames - old->tx_frames; |
567 | fc_stats->tx_words = data->tx_words - old->tx_words; | 367 | fc_stats->tx_words = data->tx_words - old->tx_words; |
568 | fc_stats->rx_frames = data->rx_frames - old->rx_frames; | 368 | fc_stats->rx_frames = data->rx_frames - old->rx_frames; |
@@ -573,26 +373,25 @@ zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, | |||
573 | fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; | 373 | fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; |
574 | fc_stats->link_failure_count = data->link_failure - old->link_failure; | 374 | fc_stats->link_failure_count = data->link_failure - old->link_failure; |
575 | fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync; | 375 | fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync; |
576 | fc_stats->loss_of_signal_count = data->loss_of_signal - | 376 | fc_stats->loss_of_signal_count = |
577 | old->loss_of_signal; | 377 | data->loss_of_signal - old->loss_of_signal; |
578 | fc_stats->prim_seq_protocol_err_count = data->psp_error_counts - | 378 | fc_stats->prim_seq_protocol_err_count = |
579 | old->psp_error_counts; | 379 | data->psp_error_counts - old->psp_error_counts; |
580 | fc_stats->invalid_tx_word_count = data->invalid_tx_words - | 380 | fc_stats->invalid_tx_word_count = |
581 | old->invalid_tx_words; | 381 | data->invalid_tx_words - old->invalid_tx_words; |
582 | fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; | 382 | fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; |
583 | fc_stats->fcp_input_requests = data->input_requests - | 383 | fc_stats->fcp_input_requests = |
584 | old->input_requests; | 384 | data->input_requests - old->input_requests; |
585 | fc_stats->fcp_output_requests = data->output_requests - | 385 | fc_stats->fcp_output_requests = |
586 | old->output_requests; | 386 | data->output_requests - old->output_requests; |
587 | fc_stats->fcp_control_requests = data->control_requests - | 387 | fc_stats->fcp_control_requests = |
588 | old->control_requests; | 388 | data->control_requests - old->control_requests; |
589 | fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; | 389 | fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; |
590 | fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; | 390 | fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; |
591 | } | 391 | } |
592 | 392 | ||
593 | static void | 393 | static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, |
594 | zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, | 394 | struct fsf_qtcb_bottom_port *data) |
595 | struct fsf_qtcb_bottom_port *data) | ||
596 | { | 395 | { |
597 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; | 396 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; |
598 | fc_stats->tx_frames = data->tx_frames; | 397 | fc_stats->tx_frames = data->tx_frames; |
@@ -616,22 +415,14 @@ zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, | |||
616 | fc_stats->fcp_output_megabytes = data->output_mb; | 415 | fc_stats->fcp_output_megabytes = data->output_mb; |
617 | } | 416 | } |
618 | 417 | ||
619 | /** | 418 | static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host) |
620 | * zfcp_get_fc_host_stats - provide fc_host_statistics for scsi_transport_fc | ||
621 | * | ||
622 | * assumption: scsi_transport_fc synchronizes calls of | ||
623 | * get_fc_host_stats and reset_fc_host_stats | ||
624 | * (XXX to be checked otherwise introduce locking) | ||
625 | */ | ||
626 | static struct fc_host_statistics * | ||
627 | zfcp_get_fc_host_stats(struct Scsi_Host *shost) | ||
628 | { | 419 | { |
629 | struct zfcp_adapter *adapter; | 420 | struct zfcp_adapter *adapter; |
630 | struct fc_host_statistics *fc_stats; | 421 | struct fc_host_statistics *fc_stats; |
631 | struct fsf_qtcb_bottom_port *data; | 422 | struct fsf_qtcb_bottom_port *data; |
632 | int ret; | 423 | int ret; |
633 | 424 | ||
634 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; | 425 | adapter = (struct zfcp_adapter *)host->hostdata[0]; |
635 | fc_stats = zfcp_init_fc_host_stats(adapter); | 426 | fc_stats = zfcp_init_fc_host_stats(adapter); |
636 | if (!fc_stats) | 427 | if (!fc_stats) |
637 | return NULL; | 428 | return NULL; |
@@ -643,26 +434,25 @@ zfcp_get_fc_host_stats(struct Scsi_Host *shost) | |||
643 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); | 434 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); |
644 | if (ret) { | 435 | if (ret) { |
645 | kfree(data); | 436 | kfree(data); |
646 | return NULL; /* XXX return zeroed fc_stats? */ | 437 | return NULL; |
647 | } | 438 | } |
648 | 439 | ||
649 | if (adapter->stats_reset && | 440 | if (adapter->stats_reset && |
650 | ((jiffies/HZ - adapter->stats_reset) < | 441 | ((jiffies/HZ - adapter->stats_reset) < |
651 | data->seconds_since_last_reset)) { | 442 | data->seconds_since_last_reset)) |
652 | zfcp_adjust_fc_host_stats(fc_stats, data, | 443 | zfcp_adjust_fc_host_stats(fc_stats, data, |
653 | adapter->stats_reset_data); | 444 | adapter->stats_reset_data); |
654 | } else | 445 | else |
655 | zfcp_set_fc_host_stats(fc_stats, data); | 446 | zfcp_set_fc_host_stats(fc_stats, data); |
656 | 447 | ||
657 | kfree(data); | 448 | kfree(data); |
658 | return fc_stats; | 449 | return fc_stats; |
659 | } | 450 | } |
660 | 451 | ||
661 | static void | 452 | static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost) |
662 | zfcp_reset_fc_host_stats(struct Scsi_Host *shost) | ||
663 | { | 453 | { |
664 | struct zfcp_adapter *adapter; | 454 | struct zfcp_adapter *adapter; |
665 | struct fsf_qtcb_bottom_port *data, *old_data; | 455 | struct fsf_qtcb_bottom_port *data; |
666 | int ret; | 456 | int ret; |
667 | 457 | ||
668 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; | 458 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
@@ -671,14 +461,13 @@ zfcp_reset_fc_host_stats(struct Scsi_Host *shost) | |||
671 | return; | 461 | return; |
672 | 462 | ||
673 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); | 463 | ret = zfcp_fsf_exchange_port_data_sync(adapter, data); |
674 | if (ret) { | 464 | if (ret) |
675 | kfree(data); | 465 | kfree(data); |
676 | } else { | 466 | else { |
677 | adapter->stats_reset = jiffies/HZ; | 467 | adapter->stats_reset = jiffies/HZ; |
678 | old_data = adapter->stats_reset_data; | 468 | kfree(adapter->stats_reset_data); |
679 | adapter->stats_reset_data = data; /* finally freed in | 469 | adapter->stats_reset_data = data; /* finally freed in |
680 | adater_dequeue */ | 470 | adapter_dequeue */ |
681 | kfree(old_data); | ||
682 | } | 471 | } |
683 | } | 472 | } |
684 | 473 | ||
@@ -793,14 +582,6 @@ ZFCP_DEFINE_LATENCY_ATTR(read); | |||
793 | ZFCP_DEFINE_LATENCY_ATTR(write); | 582 | ZFCP_DEFINE_LATENCY_ATTR(write); |
794 | ZFCP_DEFINE_LATENCY_ATTR(cmd); | 583 | ZFCP_DEFINE_LATENCY_ATTR(cmd); |
795 | 584 | ||
796 | /** | ||
797 | * ZFCP_DEFINE_SCSI_ATTR | ||
798 | * @_name: name of show attribute | ||
799 | * @_format: format string | ||
800 | * @_value: value to print | ||
801 | * | ||
802 | * Generates attribute for a unit. | ||
803 | */ | ||
804 | #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \ | 585 | #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \ |
805 | static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \ | 586 | static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_attribute *attr, \ |
806 | char *buf) \ | 587 | char *buf) \ |
@@ -815,7 +596,8 @@ static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, struct device_ | |||
815 | \ | 596 | \ |
816 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); | 597 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); |
817 | 598 | ||
818 | ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", zfcp_get_busid_by_unit(unit)); | 599 | ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", |
600 | unit->port->adapter->ccw_device->dev.bus_id); | ||
819 | ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn); | 601 | ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", unit->port->wwpn); |
820 | ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun); | 602 | ZFCP_DEFINE_SCSI_ATTR(fcp_lun, "0x%016llx\n", unit->fcp_lun); |
821 | 603 | ||
@@ -835,8 +617,8 @@ static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev, | |||
835 | { | 617 | { |
836 | struct Scsi_Host *scsi_host = dev_to_shost(dev); | 618 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
837 | struct fsf_qtcb_bottom_port *qtcb_port; | 619 | struct fsf_qtcb_bottom_port *qtcb_port; |
838 | int retval; | ||
839 | struct zfcp_adapter *adapter; | 620 | struct zfcp_adapter *adapter; |
621 | int retval; | ||
840 | 622 | ||
841 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; | 623 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
842 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) | 624 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
@@ -857,17 +639,17 @@ static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev, | |||
857 | static int zfcp_sysfs_adapter_ex_config(struct device *dev, | 639 | static int zfcp_sysfs_adapter_ex_config(struct device *dev, |
858 | struct fsf_statistics_info *stat_inf) | 640 | struct fsf_statistics_info *stat_inf) |
859 | { | 641 | { |
860 | int retval; | ||
861 | struct fsf_qtcb_bottom_config *qtcb_config; | ||
862 | struct Scsi_Host *scsi_host = dev_to_shost(dev); | 642 | struct Scsi_Host *scsi_host = dev_to_shost(dev); |
643 | struct fsf_qtcb_bottom_config *qtcb_config; | ||
863 | struct zfcp_adapter *adapter; | 644 | struct zfcp_adapter *adapter; |
645 | int retval; | ||
864 | 646 | ||
865 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; | 647 | adapter = (struct zfcp_adapter *) scsi_host->hostdata[0]; |
866 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) | 648 | if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)) |
867 | return -EOPNOTSUPP; | 649 | return -EOPNOTSUPP; |
868 | 650 | ||
869 | qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config), | 651 | qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config), |
870 | GFP_KERNEL); | 652 | GFP_KERNEL); |
871 | if (!qtcb_config) | 653 | if (!qtcb_config) |
872 | return -ENOMEM; | 654 | return -ENOMEM; |
873 | 655 | ||
@@ -940,3 +722,28 @@ static struct device_attribute *zfcp_a_stats_attrs[] = { | |||
940 | &dev_attr_seconds_active, | 722 | &dev_attr_seconds_active, |
941 | NULL | 723 | NULL |
942 | }; | 724 | }; |
725 | |||
726 | struct zfcp_data zfcp_data = { | ||
727 | .scsi_host_template = { | ||
728 | .name = "zfcp", | ||
729 | .module = THIS_MODULE, | ||
730 | .proc_name = "zfcp", | ||
731 | .slave_alloc = zfcp_scsi_slave_alloc, | ||
732 | .slave_configure = zfcp_scsi_slave_configure, | ||
733 | .slave_destroy = zfcp_scsi_slave_destroy, | ||
734 | .queuecommand = zfcp_scsi_queuecommand, | ||
735 | .eh_abort_handler = zfcp_scsi_eh_abort_handler, | ||
736 | .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, | ||
737 | .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, | ||
738 | .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, | ||
739 | .can_queue = 4096, | ||
740 | .this_id = -1, | ||
741 | .sg_tablesize = ZFCP_MAX_SBALES_PER_REQ, | ||
742 | .cmd_per_lun = 1, | ||
743 | .use_clustering = 1, | ||
744 | .sdev_attrs = zfcp_sysfs_sdev_attrs, | ||
745 | .max_sectors = (ZFCP_MAX_SBALES_PER_REQ * 8), | ||
746 | .shost_attrs = zfcp_a_stats_attrs, | ||
747 | }, | ||
748 | }; | ||
749 | |||