]>
Commit | Line | Data |
---|---|---|
41fa2ada | 1 | /* |
553448f6 | 2 | * zfcp device driver |
1da177e4 | 3 | * |
553448f6 | 4 | * Interface to Linux SCSI midlayer. |
41fa2ada | 5 | * |
5fea4291 | 6 | * Copyright IBM Corp. 2002, 2013 |
1da177e4 LT |
7 | */ |
8 | ||
ecf39d42 CS |
9 | #define KMSG_COMPONENT "zfcp" |
10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
11 | ||
3a4c5d59 | 12 | #include <linux/module.h> |
4318e08c | 13 | #include <linux/types.h> |
5a0e3ad6 | 14 | #include <linux/slab.h> |
4318e08c | 15 | #include <scsi/fc/fc_fcp.h> |
ef3eb71d | 16 | #include <scsi/scsi_eh.h> |
60063497 | 17 | #include <linux/atomic.h> |
dcd20e23 CS |
18 | #include "zfcp_ext.h" |
19 | #include "zfcp_dbf.h" | |
7c7dc196 | 20 | #include "zfcp_fc.h" |
b6bd2fb9 | 21 | #include "zfcp_reqlist.h" |
1da177e4 | 22 | |
a40a1baf CS |
23 | static unsigned int default_depth = 32; |
24 | module_param_named(queue_depth, default_depth, uint, 0600); | |
25 | MODULE_PARM_DESC(queue_depth, "Default queue depth for new SCSI devices"); | |
26 | ||
ef3eb71d | 27 | static bool enable_dif; |
cc405ace | 28 | module_param_named(dif, enable_dif, bool, 0400); |
ef3eb71d | 29 | MODULE_PARM_DESC(dif, "Enable DIF/DIX data integrity support"); |
ef3eb71d | 30 | |
0d81b4e8 CS |
31 | static bool allow_lun_scan = 1; |
32 | module_param(allow_lun_scan, bool, 0600); | |
33 | MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs"); | |
34 | ||
e881a172 MC |
35 | static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth, |
36 | int reason) | |
a40a1baf | 37 | { |
c40ecc12 | 38 | scsi_adjust_queue_depth(sdev, depth); |
a40a1baf CS |
39 | return sdev->queue_depth; |
40 | } | |
41 | ||
b62a8d9b | 42 | static void zfcp_scsi_slave_destroy(struct scsi_device *sdev) |
1da177e4 | 43 | { |
b62a8d9b CS |
44 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
45 | ||
44f747ff SM |
46 | /* if previous slave_alloc returned early, there is nothing to do */ |
47 | if (!zfcp_sdev->port) | |
48 | return; | |
49 | ||
b62a8d9b CS |
50 | zfcp_erp_lun_shutdown_wait(sdev, "scssd_1"); |
51 | put_device(&zfcp_sdev->port->dev); | |
1da177e4 LT |
52 | } |
53 | ||
f76af7d7 | 54 | static int zfcp_scsi_slave_configure(struct scsi_device *sdp) |
1da177e4 LT |
55 | { |
56 | if (sdp->tagged_supported) | |
c8b09f6f | 57 | scsi_adjust_queue_depth(sdp, default_depth); |
1da177e4 LT |
58 | return 0; |
59 | } | |
60 | ||
f76af7d7 | 61 | static void zfcp_scsi_command_fail(struct scsi_cmnd *scpnt, int result) |
1da177e4 | 62 | { |
feac6a07 | 63 | set_host_byte(scpnt, result); |
250a1352 | 64 | zfcp_dbf_scsi_fail_send(scpnt); |
1da177e4 LT |
65 | scpnt->scsi_done(scpnt); |
66 | } | |
67 | ||
e55f8753 CS |
68 | static |
69 | int zfcp_scsi_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scpnt) | |
1da177e4 | 70 | { |
b62a8d9b | 71 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
a2fa0aed | 72 | struct fc_rport *rport = starget_to_rport(scsi_target(scpnt->device)); |
b62a8d9b | 73 | int status, scsi_result, ret; |
1da177e4 LT |
74 | |
75 | /* reset the status for this request */ | |
76 | scpnt->result = 0; | |
77 | scpnt->host_scribble = NULL; | |
1da177e4 | 78 | |
a2fa0aed CS |
79 | scsi_result = fc_remote_port_chkready(rport); |
80 | if (unlikely(scsi_result)) { | |
81 | scpnt->result = scsi_result; | |
250a1352 | 82 | zfcp_dbf_scsi_fail_send(scpnt); |
a2fa0aed CS |
83 | scpnt->scsi_done(scpnt); |
84 | return 0; | |
85 | } | |
86 | ||
b62a8d9b | 87 | status = atomic_read(&zfcp_sdev->status); |
8830271c | 88 | if (unlikely(status & ZFCP_STATUS_COMMON_ERP_FAILED) && |
b62a8d9b | 89 | !(atomic_read(&zfcp_sdev->port->status) & |
8830271c | 90 | ZFCP_STATUS_COMMON_ERP_FAILED)) { |
b62a8d9b | 91 | /* only LUN access denied, but port is good |
8830271c | 92 | * not covered by FC transport, have to fail here */ |
f76af7d7 | 93 | zfcp_scsi_command_fail(scpnt, DID_ERROR); |
a419aef8 | 94 | return 0; |
f76af7d7 MP |
95 | } |
96 | ||
8830271c CS |
97 | if (unlikely(!(status & ZFCP_STATUS_COMMON_UNBLOCKED))) { |
98 | /* This could be either | |
b62a8d9b CS |
99 | * open LUN pending: this is temporary, will result in |
100 | * open LUN or ERP_FAILED, so retry command | |
8830271c CS |
101 | * call to rport_delete pending: mimic retry from |
102 | * fc_remote_port_chkready until rport is BLOCKED | |
103 | */ | |
104 | zfcp_scsi_command_fail(scpnt, DID_IMM_RETRY); | |
105 | return 0; | |
106 | } | |
107 | ||
b62a8d9b | 108 | ret = zfcp_fsf_fcp_cmnd(scpnt); |
f76af7d7 | 109 | if (unlikely(ret == -EBUSY)) |
f7a65e92 | 110 | return SCSI_MLQUEUE_DEVICE_BUSY; |
f76af7d7 MP |
111 | else if (unlikely(ret < 0)) |
112 | return SCSI_MLQUEUE_HOST_BUSY; | |
1da177e4 | 113 | |
f76af7d7 | 114 | return ret; |
1da177e4 LT |
115 | } |
116 | ||
b62a8d9b | 117 | static int zfcp_scsi_slave_alloc(struct scsi_device *sdev) |
1da177e4 | 118 | { |
b62a8d9b CS |
119 | struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); |
120 | struct zfcp_adapter *adapter = | |
121 | (struct zfcp_adapter *) sdev->host->hostdata[0]; | |
122 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); | |
1da177e4 | 123 | struct zfcp_port *port; |
f76af7d7 | 124 | struct zfcp_unit *unit; |
0d81b4e8 | 125 | int npiv = adapter->connection_features & FSF_FEATURE_NPIV_MODE; |
1da177e4 | 126 | |
b62a8d9b CS |
127 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
128 | if (!port) | |
129 | return -ENXIO; | |
f76af7d7 | 130 | |
b62a8d9b CS |
131 | unit = zfcp_unit_find(port, zfcp_scsi_dev_lun(sdev)); |
132 | if (unit) | |
133 | put_device(&unit->dev); | |
f76af7d7 | 134 | |
0d81b4e8 | 135 | if (!unit && !(allow_lun_scan && npiv)) { |
b62a8d9b CS |
136 | put_device(&port->dev); |
137 | return -ENXIO; | |
f76af7d7 | 138 | } |
f76af7d7 | 139 | |
b62a8d9b CS |
140 | zfcp_sdev->port = port; |
141 | zfcp_sdev->latencies.write.channel.min = 0xFFFFFFFF; | |
142 | zfcp_sdev->latencies.write.fabric.min = 0xFFFFFFFF; | |
143 | zfcp_sdev->latencies.read.channel.min = 0xFFFFFFFF; | |
144 | zfcp_sdev->latencies.read.fabric.min = 0xFFFFFFFF; | |
145 | zfcp_sdev->latencies.cmd.channel.min = 0xFFFFFFFF; | |
146 | zfcp_sdev->latencies.cmd.fabric.min = 0xFFFFFFFF; | |
147 | spin_lock_init(&zfcp_sdev->latencies.lock); | |
f76af7d7 | 148 | |
edaed859 | 149 | zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING); |
ea4a3a6a | 150 | zfcp_erp_lun_reopen(sdev, 0, "scsla_1"); |
b62a8d9b CS |
151 | zfcp_erp_wait(port->adapter); |
152 | ||
153 | return 0; | |
1da177e4 LT |
154 | } |
155 | ||
2b67fc46 | 156 | static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt) |
1da177e4 | 157 | { |
63caf367 CS |
158 | struct Scsi_Host *scsi_host = scpnt->device->host; |
159 | struct zfcp_adapter *adapter = | |
160 | (struct zfcp_adapter *) scsi_host->hostdata[0]; | |
63caf367 | 161 | struct zfcp_fsf_req *old_req, *abrt_req; |
1da177e4 | 162 | unsigned long flags; |
a11a52be | 163 | unsigned long old_reqid = (unsigned long) scpnt->host_scribble; |
a1dbfddd | 164 | int retval = SUCCESS, ret; |
63caf367 | 165 | int retry = 3; |
a11a52be | 166 | char *dbf_tag; |
1da177e4 | 167 | |
059c97d0 | 168 | /* avoid race condition between late normal completion and abort */ |
1da177e4 LT |
169 | write_lock_irqsave(&adapter->abort_lock, flags); |
170 | ||
b6bd2fb9 | 171 | old_req = zfcp_reqlist_find(adapter->req_list, old_reqid); |
63caf367 | 172 | if (!old_req) { |
1da177e4 | 173 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
250a1352 | 174 | zfcp_dbf_scsi_abort("abrt_or", scpnt, NULL); |
c6936e7f | 175 | return FAILED; /* completion could be in progress */ |
1da177e4 | 176 | } |
63caf367 | 177 | old_req->data = NULL; |
1da177e4 | 178 | |
4eff4a36 | 179 | /* don't access old fsf_req after releasing the abort_lock */ |
1da177e4 | 180 | write_unlock_irqrestore(&adapter->abort_lock, flags); |
4eff4a36 | 181 | |
63caf367 | 182 | while (retry--) { |
b62a8d9b | 183 | abrt_req = zfcp_fsf_abort_fcp_cmnd(scpnt); |
63caf367 CS |
184 | if (abrt_req) |
185 | break; | |
186 | ||
187 | zfcp_erp_wait(adapter); | |
a1dbfddd | 188 | ret = fc_block_scsi_eh(scpnt); |
250a1352 SS |
189 | if (ret) { |
190 | zfcp_dbf_scsi_abort("abrt_bl", scpnt, NULL); | |
a1dbfddd | 191 | return ret; |
250a1352 | 192 | } |
63caf367 CS |
193 | if (!(atomic_read(&adapter->status) & |
194 | ZFCP_STATUS_COMMON_RUNNING)) { | |
250a1352 | 195 | zfcp_dbf_scsi_abort("abrt_ru", scpnt, NULL); |
63caf367 CS |
196 | return SUCCESS; |
197 | } | |
1da177e4 | 198 | } |
250a1352 SS |
199 | if (!abrt_req) { |
200 | zfcp_dbf_scsi_abort("abrt_ar", scpnt, NULL); | |
63caf367 | 201 | return FAILED; |
250a1352 | 202 | } |
1da177e4 | 203 | |
058b8647 | 204 | wait_for_completion(&abrt_req->completion); |
059c97d0 | 205 | |
63caf367 | 206 | if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED) |
250a1352 | 207 | dbf_tag = "abrt_ok"; |
63caf367 | 208 | else if (abrt_req->status & ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED) |
250a1352 | 209 | dbf_tag = "abrt_nn"; |
63caf367 | 210 | else { |
250a1352 | 211 | dbf_tag = "abrt_fa"; |
1da177e4 | 212 | retval = FAILED; |
1da177e4 | 213 | } |
250a1352 | 214 | zfcp_dbf_scsi_abort(dbf_tag, scpnt, abrt_req); |
63caf367 | 215 | zfcp_fsf_req_free(abrt_req); |
f76af7d7 | 216 | return retval; |
1da177e4 LT |
217 | } |
218 | ||
63caf367 | 219 | static int zfcp_task_mgmt_function(struct scsi_cmnd *scpnt, u8 tm_flags) |
1da177e4 | 220 | { |
b62a8d9b CS |
221 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
222 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; | |
564e1c86 | 223 | struct zfcp_fsf_req *fsf_req = NULL; |
a1dbfddd | 224 | int retval = SUCCESS, ret; |
63caf367 CS |
225 | int retry = 3; |
226 | ||
227 | while (retry--) { | |
b62a8d9b | 228 | fsf_req = zfcp_fsf_fcp_task_mgmt(scpnt, tm_flags); |
63caf367 CS |
229 | if (fsf_req) |
230 | break; | |
231 | ||
232 | zfcp_erp_wait(adapter); | |
a1dbfddd CS |
233 | ret = fc_block_scsi_eh(scpnt); |
234 | if (ret) | |
235 | return ret; | |
236 | ||
63caf367 CS |
237 | if (!(atomic_read(&adapter->status) & |
238 | ZFCP_STATUS_COMMON_RUNNING)) { | |
b62a8d9b | 239 | zfcp_dbf_scsi_devreset("nres", scpnt, tm_flags); |
63caf367 CS |
240 | return SUCCESS; |
241 | } | |
1da177e4 | 242 | } |
63caf367 CS |
243 | if (!fsf_req) |
244 | return FAILED; | |
1da177e4 | 245 | |
058b8647 | 246 | wait_for_completion(&fsf_req->completion); |
77eb1699 | 247 | |
8a36e453 | 248 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TMFUNCFAILED) { |
b62a8d9b | 249 | zfcp_dbf_scsi_devreset("fail", scpnt, tm_flags); |
f76af7d7 | 250 | retval = FAILED; |
8a36e453 | 251 | } else |
b62a8d9b | 252 | zfcp_dbf_scsi_devreset("okay", scpnt, tm_flags); |
77eb1699 AH |
253 | |
254 | zfcp_fsf_req_free(fsf_req); | |
1da177e4 LT |
255 | return retval; |
256 | } | |
257 | ||
f76af7d7 MP |
258 | static int zfcp_scsi_eh_device_reset_handler(struct scsi_cmnd *scpnt) |
259 | { | |
4318e08c | 260 | return zfcp_task_mgmt_function(scpnt, FCP_TMF_LUN_RESET); |
f76af7d7 MP |
261 | } |
262 | ||
263 | static int zfcp_scsi_eh_target_reset_handler(struct scsi_cmnd *scpnt) | |
264 | { | |
4318e08c | 265 | return zfcp_task_mgmt_function(scpnt, FCP_TMF_TGT_RESET); |
f76af7d7 MP |
266 | } |
267 | ||
2b67fc46 | 268 | static int zfcp_scsi_eh_host_reset_handler(struct scsi_cmnd *scpnt) |
1da177e4 | 269 | { |
b62a8d9b CS |
270 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scpnt->device); |
271 | struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; | |
a1dbfddd | 272 | int ret; |
1da177e4 | 273 | |
ea4a3a6a | 274 | zfcp_erp_adapter_reopen(adapter, 0, "schrh_1"); |
81654286 | 275 | zfcp_erp_wait(adapter); |
a1dbfddd CS |
276 | ret = fc_block_scsi_eh(scpnt); |
277 | if (ret) | |
278 | return ret; | |
1da177e4 | 279 | |
810f1e3e | 280 | return SUCCESS; |
1da177e4 LT |
281 | } |
282 | ||
1947c72a CS |
283 | struct scsi_transport_template *zfcp_scsi_transport_template; |
284 | ||
285 | static struct scsi_host_template zfcp_scsi_host_template = { | |
286 | .module = THIS_MODULE, | |
287 | .name = "zfcp", | |
288 | .queuecommand = zfcp_scsi_queuecommand, | |
289 | .eh_abort_handler = zfcp_scsi_eh_abort_handler, | |
290 | .eh_device_reset_handler = zfcp_scsi_eh_device_reset_handler, | |
291 | .eh_target_reset_handler = zfcp_scsi_eh_target_reset_handler, | |
292 | .eh_host_reset_handler = zfcp_scsi_eh_host_reset_handler, | |
293 | .slave_alloc = zfcp_scsi_slave_alloc, | |
294 | .slave_configure = zfcp_scsi_slave_configure, | |
295 | .slave_destroy = zfcp_scsi_slave_destroy, | |
296 | .change_queue_depth = zfcp_scsi_change_queue_depth, | |
297 | .proc_name = "zfcp", | |
298 | .can_queue = 4096, | |
299 | .this_id = -1, | |
5fea4291 SM |
300 | .sg_tablesize = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1) |
301 | * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2), | |
302 | /* GCD, adjusted later */ | |
303 | .max_sectors = (((QDIO_MAX_ELEMENTS_PER_BUFFER - 1) | |
304 | * ZFCP_QDIO_MAX_SBALS_PER_REQ) - 2) * 8, | |
305 | /* GCD, adjusted later */ | |
1947c72a CS |
306 | .dma_boundary = ZFCP_QDIO_SBALE_LEN - 1, |
307 | .cmd_per_lun = 1, | |
308 | .use_clustering = 1, | |
309 | .shost_attrs = zfcp_sysfs_shost_attrs, | |
310 | .sdev_attrs = zfcp_sysfs_sdev_attrs, | |
c40ecc12 | 311 | .track_queue_depth = 1, |
1947c72a CS |
312 | }; |
313 | ||
314 | /** | |
315 | * zfcp_scsi_adapter_register - Register SCSI and FC host with SCSI midlayer | |
316 | * @adapter: The zfcp adapter to register with the SCSI midlayer | |
317 | */ | |
318 | int zfcp_scsi_adapter_register(struct zfcp_adapter *adapter) | |
1da177e4 | 319 | { |
f76af7d7 | 320 | struct ccw_dev_id dev_id; |
1da177e4 | 321 | |
9f28745a | 322 | if (adapter->scsi_host) |
f76af7d7 | 323 | return 0; |
9f28745a | 324 | |
f76af7d7 | 325 | ccw_device_get_id(adapter->ccw_device, &dev_id); |
1da177e4 | 326 | /* register adapter as SCSI host with mid layer of SCSI stack */ |
1947c72a | 327 | adapter->scsi_host = scsi_host_alloc(&zfcp_scsi_host_template, |
1da177e4 LT |
328 | sizeof (struct zfcp_adapter *)); |
329 | if (!adapter->scsi_host) { | |
553448f6 | 330 | dev_err(&adapter->ccw_device->dev, |
ff3b24fa CS |
331 | "Registering the FCP device with the " |
332 | "SCSI stack failed\n"); | |
f76af7d7 | 333 | return -EIO; |
1da177e4 | 334 | } |
1da177e4 LT |
335 | |
336 | /* tell the SCSI stack some characteristics of this adapter */ | |
f8210e34 CS |
337 | adapter->scsi_host->max_id = 511; |
338 | adapter->scsi_host->max_lun = 0xFFFFFFFF; | |
1da177e4 | 339 | adapter->scsi_host->max_channel = 0; |
f76af7d7 | 340 | adapter->scsi_host->unique_id = dev_id.devno; |
4318e08c | 341 | adapter->scsi_host->max_cmd_len = 16; /* in struct fcp_cmnd */ |
1947c72a | 342 | adapter->scsi_host->transportt = zfcp_scsi_transport_template; |
1da177e4 | 343 | |
1da177e4 LT |
344 | adapter->scsi_host->hostdata[0] = (unsigned long) adapter; |
345 | ||
346 | if (scsi_add_host(adapter->scsi_host, &adapter->ccw_device->dev)) { | |
347 | scsi_host_put(adapter->scsi_host); | |
f76af7d7 | 348 | return -EIO; |
1da177e4 | 349 | } |
f76af7d7 MP |
350 | |
351 | return 0; | |
1da177e4 LT |
352 | } |
353 | ||
1947c72a CS |
354 | /** |
355 | * zfcp_scsi_adapter_unregister - Unregister SCSI and FC host from SCSI midlayer | |
356 | * @adapter: The zfcp adapter to unregister. | |
357 | */ | |
358 | void zfcp_scsi_adapter_unregister(struct zfcp_adapter *adapter) | |
1da177e4 LT |
359 | { |
360 | struct Scsi_Host *shost; | |
13e1e1f0 | 361 | struct zfcp_port *port; |
1da177e4 LT |
362 | |
363 | shost = adapter->scsi_host; | |
364 | if (!shost) | |
365 | return; | |
f76af7d7 | 366 | |
ecf0c772 SS |
367 | read_lock_irq(&adapter->port_list_lock); |
368 | list_for_each_entry(port, &adapter->port_list, list) | |
f3450c7b | 369 | port->rport = NULL; |
ecf0c772 | 370 | read_unlock_irq(&adapter->port_list_lock); |
f76af7d7 | 371 | |
3859f6a2 | 372 | fc_remove_host(shost); |
1da177e4 LT |
373 | scsi_remove_host(shost); |
374 | scsi_host_put(shost); | |
375 | adapter->scsi_host = NULL; | |
1da177e4 LT |
376 | } |
377 | ||
f6cd94b1 AH |
378 | static struct fc_host_statistics* |
379 | zfcp_init_fc_host_stats(struct zfcp_adapter *adapter) | |
1da177e4 | 380 | { |
f6cd94b1 | 381 | struct fc_host_statistics *fc_stats; |
1da177e4 | 382 | |
f6cd94b1 AH |
383 | if (!adapter->fc_stats) { |
384 | fc_stats = kmalloc(sizeof(*fc_stats), GFP_KERNEL); | |
385 | if (!fc_stats) | |
386 | return NULL; | |
f3450c7b | 387 | adapter->fc_stats = fc_stats; /* freed in adapter_release */ |
f6cd94b1 AH |
388 | } |
389 | memset(adapter->fc_stats, 0, sizeof(*adapter->fc_stats)); | |
390 | return adapter->fc_stats; | |
1da177e4 LT |
391 | } |
392 | ||
f76af7d7 MP |
393 | static void zfcp_adjust_fc_host_stats(struct fc_host_statistics *fc_stats, |
394 | struct fsf_qtcb_bottom_port *data, | |
395 | struct fsf_qtcb_bottom_port *old) | |
1da177e4 | 396 | { |
f76af7d7 MP |
397 | fc_stats->seconds_since_last_reset = |
398 | data->seconds_since_last_reset - old->seconds_since_last_reset; | |
f6cd94b1 AH |
399 | fc_stats->tx_frames = data->tx_frames - old->tx_frames; |
400 | fc_stats->tx_words = data->tx_words - old->tx_words; | |
401 | fc_stats->rx_frames = data->rx_frames - old->rx_frames; | |
402 | fc_stats->rx_words = data->rx_words - old->rx_words; | |
403 | fc_stats->lip_count = data->lip - old->lip; | |
404 | fc_stats->nos_count = data->nos - old->nos; | |
405 | fc_stats->error_frames = data->error_frames - old->error_frames; | |
406 | fc_stats->dumped_frames = data->dumped_frames - old->dumped_frames; | |
407 | fc_stats->link_failure_count = data->link_failure - old->link_failure; | |
408 | fc_stats->loss_of_sync_count = data->loss_of_sync - old->loss_of_sync; | |
f76af7d7 MP |
409 | fc_stats->loss_of_signal_count = |
410 | data->loss_of_signal - old->loss_of_signal; | |
411 | fc_stats->prim_seq_protocol_err_count = | |
412 | data->psp_error_counts - old->psp_error_counts; | |
413 | fc_stats->invalid_tx_word_count = | |
414 | data->invalid_tx_words - old->invalid_tx_words; | |
f6cd94b1 | 415 | fc_stats->invalid_crc_count = data->invalid_crcs - old->invalid_crcs; |
f76af7d7 MP |
416 | fc_stats->fcp_input_requests = |
417 | data->input_requests - old->input_requests; | |
418 | fc_stats->fcp_output_requests = | |
419 | data->output_requests - old->output_requests; | |
420 | fc_stats->fcp_control_requests = | |
421 | data->control_requests - old->control_requests; | |
f6cd94b1 AH |
422 | fc_stats->fcp_input_megabytes = data->input_mb - old->input_mb; |
423 | fc_stats->fcp_output_megabytes = data->output_mb - old->output_mb; | |
424 | } | |
1da177e4 | 425 | |
f76af7d7 MP |
426 | static void zfcp_set_fc_host_stats(struct fc_host_statistics *fc_stats, |
427 | struct fsf_qtcb_bottom_port *data) | |
f6cd94b1 AH |
428 | { |
429 | fc_stats->seconds_since_last_reset = data->seconds_since_last_reset; | |
430 | fc_stats->tx_frames = data->tx_frames; | |
431 | fc_stats->tx_words = data->tx_words; | |
432 | fc_stats->rx_frames = data->rx_frames; | |
433 | fc_stats->rx_words = data->rx_words; | |
434 | fc_stats->lip_count = data->lip; | |
435 | fc_stats->nos_count = data->nos; | |
436 | fc_stats->error_frames = data->error_frames; | |
437 | fc_stats->dumped_frames = data->dumped_frames; | |
438 | fc_stats->link_failure_count = data->link_failure; | |
439 | fc_stats->loss_of_sync_count = data->loss_of_sync; | |
440 | fc_stats->loss_of_signal_count = data->loss_of_signal; | |
441 | fc_stats->prim_seq_protocol_err_count = data->psp_error_counts; | |
442 | fc_stats->invalid_tx_word_count = data->invalid_tx_words; | |
443 | fc_stats->invalid_crc_count = data->invalid_crcs; | |
444 | fc_stats->fcp_input_requests = data->input_requests; | |
445 | fc_stats->fcp_output_requests = data->output_requests; | |
446 | fc_stats->fcp_control_requests = data->control_requests; | |
447 | fc_stats->fcp_input_megabytes = data->input_mb; | |
448 | fc_stats->fcp_output_megabytes = data->output_mb; | |
449 | } | |
450 | ||
f76af7d7 | 451 | static struct fc_host_statistics *zfcp_get_fc_host_stats(struct Scsi_Host *host) |
f6cd94b1 AH |
452 | { |
453 | struct zfcp_adapter *adapter; | |
454 | struct fc_host_statistics *fc_stats; | |
455 | struct fsf_qtcb_bottom_port *data; | |
456 | int ret; | |
457 | ||
f76af7d7 | 458 | adapter = (struct zfcp_adapter *)host->hostdata[0]; |
f6cd94b1 AH |
459 | fc_stats = zfcp_init_fc_host_stats(adapter); |
460 | if (!fc_stats) | |
461 | return NULL; | |
462 | ||
ec4081c6 | 463 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
f6cd94b1 AH |
464 | if (!data) |
465 | return NULL; | |
f6cd94b1 | 466 | |
564e1c86 | 467 | ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); |
f6cd94b1 AH |
468 | if (ret) { |
469 | kfree(data); | |
f76af7d7 | 470 | return NULL; |
f6cd94b1 AH |
471 | } |
472 | ||
473 | if (adapter->stats_reset && | |
474 | ((jiffies/HZ - adapter->stats_reset) < | |
f76af7d7 | 475 | data->seconds_since_last_reset)) |
f6cd94b1 AH |
476 | zfcp_adjust_fc_host_stats(fc_stats, data, |
477 | adapter->stats_reset_data); | |
f76af7d7 | 478 | else |
f6cd94b1 AH |
479 | zfcp_set_fc_host_stats(fc_stats, data); |
480 | ||
481 | kfree(data); | |
482 | return fc_stats; | |
1da177e4 LT |
483 | } |
484 | ||
f76af7d7 | 485 | static void zfcp_reset_fc_host_stats(struct Scsi_Host *shost) |
1da177e4 | 486 | { |
f6cd94b1 | 487 | struct zfcp_adapter *adapter; |
f76af7d7 | 488 | struct fsf_qtcb_bottom_port *data; |
f6cd94b1 | 489 | int ret; |
1da177e4 | 490 | |
f6cd94b1 | 491 | adapter = (struct zfcp_adapter *)shost->hostdata[0]; |
ec4081c6 | 492 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
f6cd94b1 AH |
493 | if (!data) |
494 | return; | |
f6cd94b1 | 495 | |
564e1c86 | 496 | ret = zfcp_fsf_exchange_port_data_sync(adapter->qdio, data); |
f76af7d7 | 497 | if (ret) |
83f6d6d7 | 498 | kfree(data); |
f76af7d7 | 499 | else { |
f6cd94b1 | 500 | adapter->stats_reset = jiffies/HZ; |
f76af7d7 | 501 | kfree(adapter->stats_reset_data); |
f6cd94b1 | 502 | adapter->stats_reset_data = data; /* finally freed in |
f3450c7b | 503 | adapter_release */ |
f6cd94b1 | 504 | } |
1da177e4 LT |
505 | } |
506 | ||
85a82392 SS |
507 | static void zfcp_get_host_port_state(struct Scsi_Host *shost) |
508 | { | |
509 | struct zfcp_adapter *adapter = | |
510 | (struct zfcp_adapter *)shost->hostdata[0]; | |
511 | int status = atomic_read(&adapter->status); | |
512 | ||
513 | if ((status & ZFCP_STATUS_COMMON_RUNNING) && | |
514 | !(status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)) | |
515 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
516 | else if (status & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED) | |
517 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
518 | else if (status & ZFCP_STATUS_COMMON_ERP_FAILED) | |
519 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
520 | else | |
521 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
522 | } | |
523 | ||
338151e0 AH |
524 | static void zfcp_set_rport_dev_loss_tmo(struct fc_rport *rport, u32 timeout) |
525 | { | |
526 | rport->dev_loss_tmo = timeout; | |
527 | } | |
528 | ||
a2fa0aed CS |
529 | /** |
530 | * zfcp_scsi_terminate_rport_io - Terminate all I/O on a rport | |
531 | * @rport: The FC rport where to teminate I/O | |
532 | * | |
533 | * Abort all pending SCSI commands for a port by closing the | |
835dc298 CS |
534 | * port. Using a reopen avoids a conflict with a shutdown |
535 | * overwriting a reopen. The "forced" ensures that a disappeared port | |
536 | * is not opened again as valid due to the cached plogi data in | |
537 | * non-NPIV mode. | |
a2fa0aed CS |
538 | */ |
539 | static void zfcp_scsi_terminate_rport_io(struct fc_rport *rport) | |
540 | { | |
70932935 | 541 | struct zfcp_port *port; |
ea945ff8 SS |
542 | struct Scsi_Host *shost = rport_to_shost(rport); |
543 | struct zfcp_adapter *adapter = | |
544 | (struct zfcp_adapter *)shost->hostdata[0]; | |
70932935 | 545 | |
ea945ff8 | 546 | port = zfcp_get_port_by_wwpn(adapter, rport->port_name); |
a2fa0aed | 547 | |
70932935 | 548 | if (port) { |
ea4a3a6a | 549 | zfcp_erp_port_forced_reopen(port, 0, "sctrpi1"); |
615f59e0 | 550 | put_device(&port->dev); |
70932935 | 551 | } |
a2fa0aed CS |
552 | } |
553 | ||
554 | static void zfcp_scsi_rport_register(struct zfcp_port *port) | |
555 | { | |
556 | struct fc_rport_identifiers ids; | |
557 | struct fc_rport *rport; | |
558 | ||
379d6bf6 CS |
559 | if (port->rport) |
560 | return; | |
561 | ||
a2fa0aed CS |
562 | ids.node_name = port->wwnn; |
563 | ids.port_name = port->wwpn; | |
564 | ids.port_id = port->d_id; | |
565 | ids.roles = FC_RPORT_ROLE_FCP_TARGET; | |
566 | ||
567 | rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids); | |
568 | if (!rport) { | |
569 | dev_err(&port->adapter->ccw_device->dev, | |
570 | "Registering port 0x%016Lx failed\n", | |
571 | (unsigned long long)port->wwpn); | |
572 | return; | |
573 | } | |
574 | ||
a2fa0aed CS |
575 | rport->maxframe_size = port->maxframe_size; |
576 | rport->supported_classes = port->supported_classes; | |
577 | port->rport = rport; | |
1bf3ff02 | 578 | port->starget_id = rport->scsi_target_id; |
5a7de559 | 579 | |
1daa4eb5 | 580 | zfcp_unit_queue_scsi_scan(port); |
a2fa0aed CS |
581 | } |
582 | ||
583 | static void zfcp_scsi_rport_block(struct zfcp_port *port) | |
584 | { | |
70932935 CS |
585 | struct fc_rport *rport = port->rport; |
586 | ||
379d6bf6 | 587 | if (rport) { |
70932935 | 588 | fc_remote_port_delete(rport); |
379d6bf6 CS |
589 | port->rport = NULL; |
590 | } | |
a2fa0aed CS |
591 | } |
592 | ||
593 | void zfcp_scsi_schedule_rport_register(struct zfcp_port *port) | |
594 | { | |
615f59e0 | 595 | get_device(&port->dev); |
a2fa0aed CS |
596 | port->rport_task = RPORT_ADD; |
597 | ||
4544683a | 598 | if (!queue_work(port->adapter->work_queue, &port->rport_work)) |
615f59e0 | 599 | put_device(&port->dev); |
a2fa0aed CS |
600 | } |
601 | ||
602 | void zfcp_scsi_schedule_rport_block(struct zfcp_port *port) | |
603 | { | |
615f59e0 | 604 | get_device(&port->dev); |
a2fa0aed CS |
605 | port->rport_task = RPORT_DEL; |
606 | ||
4544683a SS |
607 | if (port->rport && queue_work(port->adapter->work_queue, |
608 | &port->rport_work)) | |
a67417ab SS |
609 | return; |
610 | ||
615f59e0 | 611 | put_device(&port->dev); |
a2fa0aed CS |
612 | } |
613 | ||
614 | void zfcp_scsi_schedule_rports_block(struct zfcp_adapter *adapter) | |
615 | { | |
ecf0c772 | 616 | unsigned long flags; |
a2fa0aed CS |
617 | struct zfcp_port *port; |
618 | ||
ecf0c772 SS |
619 | read_lock_irqsave(&adapter->port_list_lock, flags); |
620 | list_for_each_entry(port, &adapter->port_list, list) | |
a2fa0aed | 621 | zfcp_scsi_schedule_rport_block(port); |
ecf0c772 | 622 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
a2fa0aed CS |
623 | } |
624 | ||
625 | void zfcp_scsi_rport_work(struct work_struct *work) | |
626 | { | |
627 | struct zfcp_port *port = container_of(work, struct zfcp_port, | |
628 | rport_work); | |
629 | ||
630 | while (port->rport_task) { | |
631 | if (port->rport_task == RPORT_ADD) { | |
632 | port->rport_task = RPORT_NONE; | |
633 | zfcp_scsi_rport_register(port); | |
634 | } else { | |
635 | port->rport_task = RPORT_NONE; | |
636 | zfcp_scsi_rport_block(port); | |
637 | } | |
638 | } | |
639 | ||
615f59e0 | 640 | put_device(&port->dev); |
a2fa0aed CS |
641 | } |
642 | ||
ef3eb71d FB |
643 | /** |
644 | * zfcp_scsi_set_prot - Configure DIF/DIX support in scsi_host | |
645 | * @adapter: The adapter where to configure DIF/DIX for the SCSI host | |
646 | */ | |
647 | void zfcp_scsi_set_prot(struct zfcp_adapter *adapter) | |
648 | { | |
649 | unsigned int mask = 0; | |
650 | unsigned int data_div; | |
651 | struct Scsi_Host *shost = adapter->scsi_host; | |
652 | ||
653 | data_div = atomic_read(&adapter->status) & | |
654 | ZFCP_STATUS_ADAPTER_DATA_DIV_ENABLED; | |
655 | ||
656 | if (enable_dif && | |
657 | adapter->adapter_features & FSF_FEATURE_DIF_PROT_TYPE1) | |
658 | mask |= SHOST_DIF_TYPE1_PROTECTION; | |
659 | ||
660 | if (enable_dif && data_div && | |
661 | adapter->adapter_features & FSF_FEATURE_DIX_PROT_TCPIP) { | |
662 | mask |= SHOST_DIX_TYPE1_PROTECTION; | |
663 | scsi_host_set_guard(shost, SHOST_DIX_GUARD_IP); | |
86a9668a SS |
664 | shost->sg_prot_tablesize = adapter->qdio->max_sbale_per_req / 2; |
665 | shost->sg_tablesize = adapter->qdio->max_sbale_per_req / 2; | |
666 | shost->max_sectors = shost->sg_tablesize * 8; | |
ef3eb71d FB |
667 | } |
668 | ||
669 | scsi_host_set_prot(shost, mask); | |
670 | } | |
671 | ||
672 | /** | |
673 | * zfcp_scsi_dif_sense_error - Report DIF/DIX error as driver sense error | |
674 | * @scmd: The SCSI command to report the error for | |
675 | * @ascq: The ASCQ to put in the sense buffer | |
676 | * | |
677 | * See the error handling in sd_done for the sense codes used here. | |
678 | * Set DID_SOFT_ERROR to retry the request, if possible. | |
679 | */ | |
680 | void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) | |
681 | { | |
682 | scsi_build_sense_buffer(1, scmd->sense_buffer, | |
683 | ILLEGAL_REQUEST, 0x10, ascq); | |
684 | set_driver_byte(scmd, DRIVER_SENSE); | |
685 | scmd->result |= SAM_STAT_CHECK_CONDITION; | |
686 | set_host_byte(scmd, DID_SOFT_ERROR); | |
687 | } | |
688 | ||
1da177e4 | 689 | struct fc_function_template zfcp_transport_functions = { |
1da177e4 LT |
690 | .show_starget_port_id = 1, |
691 | .show_starget_port_name = 1, | |
692 | .show_starget_node_name = 1, | |
3859f6a2 | 693 | .show_rport_supported_classes = 1, |
75bfc283 | 694 | .show_rport_maxframe_size = 1, |
338151e0 | 695 | .show_rport_dev_loss_tmo = 1, |
3859f6a2 AH |
696 | .show_host_node_name = 1, |
697 | .show_host_port_name = 1, | |
ad757cdf | 698 | .show_host_permanent_port_name = 1, |
3859f6a2 | 699 | .show_host_supported_classes = 1, |
0fdd2133 | 700 | .show_host_supported_fc4s = 1, |
ad757cdf | 701 | .show_host_supported_speeds = 1, |
13e1e1f0 | 702 | .show_host_maxframe_size = 1, |
3859f6a2 | 703 | .show_host_serial_number = 1, |
f6cd94b1 AH |
704 | .get_fc_host_stats = zfcp_get_fc_host_stats, |
705 | .reset_fc_host_stats = zfcp_reset_fc_host_stats, | |
338151e0 | 706 | .set_rport_dev_loss_tmo = zfcp_set_rport_dev_loss_tmo, |
85a82392 | 707 | .get_host_port_state = zfcp_get_host_port_state, |
a2fa0aed | 708 | .terminate_rport_io = zfcp_scsi_terminate_rport_io, |
85a82392 | 709 | .show_host_port_state = 1, |
0fdd2133 | 710 | .show_host_active_fc4s = 1, |
7c7dc196 | 711 | .bsg_request = zfcp_fc_exec_bsg_job, |
491ca442 | 712 | .bsg_timeout = zfcp_fc_timeout_bsg_job, |
f6cd94b1 AH |
713 | /* no functions registered for following dynamic attributes but |
714 | directly set by LLDD */ | |
ad757cdf | 715 | .show_host_port_type = 1, |
038d9446 | 716 | .show_host_symbolic_name = 1, |
13e1e1f0 AH |
717 | .show_host_speed = 1, |
718 | .show_host_port_id = 1, | |
7c7dc196 | 719 | .dd_bsg_size = sizeof(struct zfcp_fsf_ct_els), |
1da177e4 | 720 | }; |