GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / s390 / scsi / zfcp_fsf.c
bloba7460c48948c20cb14792b555c9a33761e41c7a5
1 /*
2 * zfcp device driver
4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2010
7 */
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <linux/slab.h>
14 #include <scsi/fc/fc_els.h>
15 #include "zfcp_ext.h"
16 #include "zfcp_fc.h"
17 #include "zfcp_dbf.h"
18 #include "zfcp_qdio.h"
19 #include "zfcp_reqlist.h"
21 static void zfcp_fsf_request_timeout_handler(unsigned long data)
23 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
24 zfcp_qdio_siosl(adapter);
25 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 "fsrth_1", NULL);
29 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
30 unsigned long timeout)
32 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
33 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
34 fsf_req->timer.expires = jiffies + timeout;
35 add_timer(&fsf_req->timer);
38 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
40 BUG_ON(!fsf_req->erp_action);
41 fsf_req->timer.function = zfcp_erp_timeout_handler;
42 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
43 fsf_req->timer.expires = jiffies + 30 * HZ;
44 add_timer(&fsf_req->timer);
47 /* association between FSF command and FSF QTCB type */
48 static u32 fsf_qtcb_type[] = {
49 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
50 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
56 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
59 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
60 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
64 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
66 u16 subtable = table >> 16;
67 u16 rule = table & 0xffff;
68 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
70 if (subtable && subtable < ARRAY_SIZE(act_type))
71 dev_warn(&adapter->ccw_device->dev,
72 "Access denied according to ACT rule type %s, "
73 "rule %d\n", act_type[subtable], rule);
76 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
77 struct zfcp_port *port)
79 struct fsf_qtcb_header *header = &req->qtcb->header;
80 dev_warn(&req->adapter->ccw_device->dev,
81 "Access denied to port 0x%016Lx\n",
82 (unsigned long long)port->wwpn);
83 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
84 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
85 zfcp_erp_port_access_denied(port, "fspad_1", req);
86 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
89 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
90 struct zfcp_unit *unit)
92 struct fsf_qtcb_header *header = &req->qtcb->header;
93 dev_warn(&req->adapter->ccw_device->dev,
94 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
95 (unsigned long long)unit->fcp_lun,
96 (unsigned long long)unit->port->wwpn);
97 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
98 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
99 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
100 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
103 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
105 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
106 "operational because of an unsupported FC class\n");
107 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
108 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
112 * zfcp_fsf_req_free - free memory used by fsf request
113 * @fsf_req: pointer to struct zfcp_fsf_req
115 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
117 if (likely(req->pool)) {
118 if (likely(req->qtcb))
119 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
120 mempool_free(req, req->pool);
121 return;
124 if (likely(req->qtcb))
125 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
126 kfree(req);
129 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
131 unsigned long flags;
132 struct fsf_status_read_buffer *sr_buf = req->data;
133 struct zfcp_adapter *adapter = req->adapter;
134 struct zfcp_port *port;
135 int d_id = ntoh24(sr_buf->d_id);
137 read_lock_irqsave(&adapter->port_list_lock, flags);
138 list_for_each_entry(port, &adapter->port_list, list)
139 if (port->d_id == d_id) {
140 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
141 break;
143 read_unlock_irqrestore(&adapter->port_list_lock, flags);
146 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
147 struct fsf_link_down_info *link_down)
149 struct zfcp_adapter *adapter = req->adapter;
151 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
152 return;
154 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
156 zfcp_scsi_schedule_rports_block(adapter);
158 if (!link_down)
159 goto out;
161 switch (link_down->error_code) {
162 case FSF_PSQ_LINK_NO_LIGHT:
163 dev_warn(&req->adapter->ccw_device->dev,
164 "There is no light signal from the local "
165 "fibre channel cable\n");
166 break;
167 case FSF_PSQ_LINK_WRAP_PLUG:
168 dev_warn(&req->adapter->ccw_device->dev,
169 "There is a wrap plug instead of a fibre "
170 "channel cable\n");
171 break;
172 case FSF_PSQ_LINK_NO_FCP:
173 dev_warn(&req->adapter->ccw_device->dev,
174 "The adjacent fibre channel node does not "
175 "support FCP\n");
176 break;
177 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
178 dev_warn(&req->adapter->ccw_device->dev,
179 "The FCP device is suspended because of a "
180 "firmware update\n");
181 break;
182 case FSF_PSQ_LINK_INVALID_WWPN:
183 dev_warn(&req->adapter->ccw_device->dev,
184 "The FCP device detected a WWPN that is "
185 "duplicate or not valid\n");
186 break;
187 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
188 dev_warn(&req->adapter->ccw_device->dev,
189 "The fibre channel fabric does not support NPIV\n");
190 break;
191 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
192 dev_warn(&req->adapter->ccw_device->dev,
193 "The FCP adapter cannot support more NPIV ports\n");
194 break;
195 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
196 dev_warn(&req->adapter->ccw_device->dev,
197 "The adjacent switch cannot support "
198 "more NPIV ports\n");
199 break;
200 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
201 dev_warn(&req->adapter->ccw_device->dev,
202 "The FCP adapter could not log in to the "
203 "fibre channel fabric\n");
204 break;
205 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
206 dev_warn(&req->adapter->ccw_device->dev,
207 "The WWPN assignment file on the FCP adapter "
208 "has been damaged\n");
209 break;
210 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
211 dev_warn(&req->adapter->ccw_device->dev,
212 "The mode table on the FCP adapter "
213 "has been damaged\n");
214 break;
215 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
216 dev_warn(&req->adapter->ccw_device->dev,
217 "All NPIV ports on the FCP adapter have "
218 "been assigned\n");
219 break;
220 default:
221 dev_warn(&req->adapter->ccw_device->dev,
222 "The link between the FCP adapter and "
223 "the FC fabric is down\n");
225 out:
226 zfcp_erp_adapter_failed(adapter, id, req);
229 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
231 struct fsf_status_read_buffer *sr_buf = req->data;
232 struct fsf_link_down_info *ldi =
233 (struct fsf_link_down_info *) &sr_buf->payload;
235 switch (sr_buf->status_subtype) {
236 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
237 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
238 break;
239 case FSF_STATUS_READ_SUB_FDISC_FAILED:
240 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
241 break;
242 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
243 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
247 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
249 struct zfcp_adapter *adapter = req->adapter;
250 struct fsf_status_read_buffer *sr_buf = req->data;
252 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
253 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
254 mempool_free(sr_buf, adapter->pool.status_read_data);
255 zfcp_fsf_req_free(req);
256 return;
259 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
261 switch (sr_buf->status_type) {
262 case FSF_STATUS_READ_PORT_CLOSED:
263 zfcp_fsf_status_read_port_closed(req);
264 break;
265 case FSF_STATUS_READ_INCOMING_ELS:
266 zfcp_fc_incoming_els(req);
267 break;
268 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
269 break;
270 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
271 dev_warn(&adapter->ccw_device->dev,
272 "The error threshold for checksum statistics "
273 "has been exceeded\n");
274 zfcp_dbf_hba_berr(adapter->dbf, req);
275 break;
276 case FSF_STATUS_READ_LINK_DOWN:
277 zfcp_fsf_status_read_link_down(req);
278 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
279 break;
280 case FSF_STATUS_READ_LINK_UP:
281 dev_info(&adapter->ccw_device->dev,
282 "The local link has been restored\n");
283 /* All ports should be marked as ready to run again */
284 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
285 ZFCP_STATUS_COMMON_RUNNING,
286 ZFCP_SET);
287 zfcp_erp_adapter_reopen(adapter,
288 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
289 ZFCP_STATUS_COMMON_ERP_FAILED,
290 "fssrh_2", req);
291 zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
293 break;
294 case FSF_STATUS_READ_NOTIFICATION_LOST:
295 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
296 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
297 req);
298 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
299 queue_work(adapter->work_queue, &adapter->scan_work);
300 break;
301 case FSF_STATUS_READ_CFDC_UPDATED:
302 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
303 break;
304 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
305 adapter->adapter_features = sr_buf->payload.word[0];
306 break;
309 mempool_free(sr_buf, adapter->pool.status_read_data);
310 zfcp_fsf_req_free(req);
312 atomic_inc(&adapter->stat_miss);
313 queue_work(adapter->work_queue, &adapter->stat_work);
316 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
318 switch (req->qtcb->header.fsf_status_qual.word[0]) {
319 case FSF_SQ_FCP_RSP_AVAILABLE:
320 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
321 case FSF_SQ_NO_RETRY_POSSIBLE:
322 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
323 return;
324 case FSF_SQ_COMMAND_ABORTED:
325 break;
326 case FSF_SQ_NO_RECOM:
327 dev_err(&req->adapter->ccw_device->dev,
328 "The FCP adapter reported a problem "
329 "that cannot be recovered\n");
330 zfcp_qdio_siosl(req->adapter);
331 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
332 break;
334 /* all non-return stats set FSFREQ_ERROR*/
335 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
338 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
340 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
341 return;
343 switch (req->qtcb->header.fsf_status) {
344 case FSF_UNKNOWN_COMMAND:
345 dev_err(&req->adapter->ccw_device->dev,
346 "The FCP adapter does not recognize the command 0x%x\n",
347 req->qtcb->header.fsf_command);
348 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
349 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
350 break;
351 case FSF_ADAPTER_STATUS_AVAILABLE:
352 zfcp_fsf_fsfstatus_qual_eval(req);
353 break;
357 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
359 struct zfcp_adapter *adapter = req->adapter;
360 struct fsf_qtcb *qtcb = req->qtcb;
361 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
363 zfcp_dbf_hba_fsf_response(req);
365 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
366 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
367 return;
370 switch (qtcb->prefix.prot_status) {
371 case FSF_PROT_GOOD:
372 case FSF_PROT_FSF_STATUS_PRESENTED:
373 return;
374 case FSF_PROT_QTCB_VERSION_ERROR:
375 dev_err(&adapter->ccw_device->dev,
376 "QTCB version 0x%x not supported by FCP adapter "
377 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
378 psq->word[0], psq->word[1]);
379 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
380 break;
381 case FSF_PROT_ERROR_STATE:
382 case FSF_PROT_SEQ_NUMB_ERROR:
383 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
384 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
385 break;
386 case FSF_PROT_UNSUPP_QTCB_TYPE:
387 dev_err(&adapter->ccw_device->dev,
388 "The QTCB type is not supported by the FCP adapter\n");
389 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
390 break;
391 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
392 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
393 &adapter->status);
394 break;
395 case FSF_PROT_DUPLICATE_REQUEST_ID:
396 dev_err(&adapter->ccw_device->dev,
397 "0x%Lx is an ambiguous request identifier\n",
398 (unsigned long long)qtcb->bottom.support.req_handle);
399 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
400 break;
401 case FSF_PROT_LINK_DOWN:
402 zfcp_fsf_link_down_info_eval(req, "fspse_5",
403 &psq->link_down_info);
404 /* go through reopen to flush pending requests */
405 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
406 break;
407 case FSF_PROT_REEST_QUEUE:
408 /* All ports should be marked as ready to run again */
409 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
410 ZFCP_STATUS_COMMON_RUNNING,
411 ZFCP_SET);
412 zfcp_erp_adapter_reopen(adapter,
413 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
414 ZFCP_STATUS_COMMON_ERP_FAILED,
415 "fspse_8", req);
416 break;
417 default:
418 dev_err(&adapter->ccw_device->dev,
419 "0x%x is not a valid transfer protocol status\n",
420 qtcb->prefix.prot_status);
421 zfcp_qdio_siosl(adapter);
422 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
424 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
428 * zfcp_fsf_req_complete - process completion of a FSF request
429 * @fsf_req: The FSF request that has been completed.
431 * When a request has been completed either from the FCP adapter,
432 * or it has been dismissed due to a queue shutdown, this function
433 * is called to process the completion status and trigger further
434 * events related to the FSF request.
436 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
438 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
439 zfcp_fsf_status_read_handler(req);
440 return;
443 del_timer(&req->timer);
444 zfcp_fsf_protstatus_eval(req);
445 zfcp_fsf_fsfstatus_eval(req);
446 req->handler(req);
448 if (req->erp_action)
449 zfcp_erp_notify(req->erp_action, 0);
451 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
452 zfcp_fsf_req_free(req);
453 else
454 complete(&req->completion);
458 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
459 * @adapter: pointer to struct zfcp_adapter
461 * Never ever call this without shutting down the adapter first.
462 * Otherwise the adapter would continue using and corrupting s390 storage.
463 * Included BUG_ON() call to ensure this is done.
464 * ERP is supposed to be the only user of this function.
466 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
468 struct zfcp_fsf_req *req, *tmp;
469 LIST_HEAD(remove_queue);
471 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
472 zfcp_reqlist_move(adapter->req_list, &remove_queue);
474 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
475 list_del(&req->list);
476 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_fsf_req_complete(req);
481 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
483 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
484 struct zfcp_adapter *adapter = req->adapter;
485 struct Scsi_Host *shost = adapter->scsi_host;
486 struct fc_els_flogi *nsp, *plogi;
488 /* adjust pointers for missing command code */
489 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
490 - sizeof(u32));
491 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
492 - sizeof(u32));
494 if (req->data)
495 memcpy(req->data, bottom, sizeof(*bottom));
497 fc_host_port_name(shost) = nsp->fl_wwpn;
498 fc_host_node_name(shost) = nsp->fl_wwnn;
499 fc_host_port_id(shost) = ntoh24(bottom->s_id);
500 fc_host_speed(shost) = bottom->fc_link_speed;
501 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
503 adapter->hydra_version = bottom->adapter_type;
504 adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
505 adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
506 (u16)FSF_STATUS_READS_RECOM);
508 if (fc_host_permanent_port_name(shost) == -1)
509 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
511 switch (bottom->fc_topology) {
512 case FSF_TOPO_P2P:
513 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
514 adapter->peer_wwpn = plogi->fl_wwpn;
515 adapter->peer_wwnn = plogi->fl_wwnn;
516 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
517 break;
518 case FSF_TOPO_FABRIC:
519 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
520 break;
521 case FSF_TOPO_AL:
522 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
523 /* fall through */
524 default:
525 dev_err(&adapter->ccw_device->dev,
526 "Unknown or unsupported arbitrated loop "
527 "fibre channel topology detected\n");
528 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
529 return -EIO;
532 zfcp_scsi_set_prot(adapter);
534 return 0;
537 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
539 struct zfcp_adapter *adapter = req->adapter;
540 struct fsf_qtcb *qtcb = req->qtcb;
541 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
542 struct Scsi_Host *shost = adapter->scsi_host;
544 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
545 return;
547 adapter->fsf_lic_version = bottom->lic_version;
548 adapter->adapter_features = bottom->adapter_features;
549 adapter->connection_features = bottom->connection_features;
550 adapter->peer_wwpn = 0;
551 adapter->peer_wwnn = 0;
552 adapter->peer_d_id = 0;
554 switch (qtcb->header.fsf_status) {
555 case FSF_GOOD:
556 if (zfcp_fsf_exchange_config_evaluate(req))
557 return;
559 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
560 dev_err(&adapter->ccw_device->dev,
561 "FCP adapter maximum QTCB size (%d bytes) "
562 "is too small\n",
563 bottom->max_qtcb_size);
564 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
565 return;
567 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
568 &adapter->status);
569 break;
570 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
571 fc_host_node_name(shost) = 0;
572 fc_host_port_name(shost) = 0;
573 fc_host_port_id(shost) = 0;
574 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
575 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
576 adapter->hydra_version = 0;
578 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
579 &adapter->status);
581 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
582 &qtcb->header.fsf_status_qual.link_down_info);
583 break;
584 default:
585 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
586 return;
589 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
590 adapter->hardware_version = bottom->hardware_version;
591 memcpy(fc_host_serial_number(shost), bottom->serial_number,
592 min(FC_SERIAL_NUMBER_SIZE, 17));
593 EBCASC(fc_host_serial_number(shost),
594 min(FC_SERIAL_NUMBER_SIZE, 17));
597 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
598 dev_err(&adapter->ccw_device->dev,
599 "The FCP adapter only supports newer "
600 "control block versions\n");
601 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
602 return;
604 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
605 dev_err(&adapter->ccw_device->dev,
606 "The FCP adapter only supports older "
607 "control block versions\n");
608 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
612 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
614 struct zfcp_adapter *adapter = req->adapter;
615 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
616 struct Scsi_Host *shost = adapter->scsi_host;
618 if (req->data)
619 memcpy(req->data, bottom, sizeof(*bottom));
621 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
622 fc_host_permanent_port_name(shost) = bottom->wwpn;
623 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
624 } else
625 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
626 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
627 fc_host_supported_speeds(shost) = bottom->supported_speed;
628 memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
629 FC_FC4_LIST_SIZE);
630 memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
631 FC_FC4_LIST_SIZE);
634 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
636 struct fsf_qtcb *qtcb = req->qtcb;
638 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
639 return;
641 switch (qtcb->header.fsf_status) {
642 case FSF_GOOD:
643 zfcp_fsf_exchange_port_evaluate(req);
644 break;
645 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
646 zfcp_fsf_exchange_port_evaluate(req);
647 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
648 &qtcb->header.fsf_status_qual.link_down_info);
649 break;
653 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
655 struct zfcp_fsf_req *req;
657 if (likely(pool))
658 req = mempool_alloc(pool, GFP_ATOMIC);
659 else
660 req = kmalloc(sizeof(*req), GFP_ATOMIC);
662 if (unlikely(!req))
663 return NULL;
665 memset(req, 0, sizeof(*req));
666 req->pool = pool;
667 return req;
670 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
672 struct fsf_qtcb *qtcb;
674 if (likely(pool))
675 qtcb = mempool_alloc(pool, GFP_ATOMIC);
676 else
677 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
679 if (unlikely(!qtcb))
680 return NULL;
682 memset(qtcb, 0, sizeof(*qtcb));
683 return qtcb;
686 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
687 u32 fsf_cmd, u32 sbtype,
688 mempool_t *pool)
690 struct zfcp_adapter *adapter = qdio->adapter;
691 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
693 if (unlikely(!req))
694 return ERR_PTR(-ENOMEM);
696 if (adapter->req_no == 0)
697 adapter->req_no++;
699 INIT_LIST_HEAD(&req->list);
700 init_timer(&req->timer);
701 init_completion(&req->completion);
703 req->adapter = adapter;
704 req->fsf_command = fsf_cmd;
705 req->req_id = adapter->req_no;
707 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
708 if (likely(pool))
709 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
710 else
711 req->qtcb = zfcp_qtcb_alloc(NULL);
713 if (unlikely(!req->qtcb)) {
714 zfcp_fsf_req_free(req);
715 return ERR_PTR(-ENOMEM);
718 req->seq_no = adapter->fsf_req_seq_no;
719 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
720 req->qtcb->prefix.req_id = req->req_id;
721 req->qtcb->prefix.ulp_info = 26;
722 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
723 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
724 req->qtcb->header.req_handle = req->req_id;
725 req->qtcb->header.fsf_command = req->fsf_command;
728 zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
729 req->qtcb, sizeof(struct fsf_qtcb));
731 return req;
734 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
736 struct zfcp_adapter *adapter = req->adapter;
737 struct zfcp_qdio *qdio = adapter->qdio;
738 int with_qtcb = (req->qtcb != NULL);
739 int req_id = req->req_id;
741 zfcp_reqlist_add(adapter->req_list, req);
743 req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
744 req->issued = get_clock();
745 if (zfcp_qdio_send(qdio, &req->qdio_req)) {
746 del_timer(&req->timer);
747 /* lookup request again, list might have changed */
748 zfcp_reqlist_find_rm(adapter->req_list, req_id);
749 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
750 return -EIO;
753 /* Don't increase for unsolicited status */
754 if (with_qtcb)
755 adapter->fsf_req_seq_no++;
756 adapter->req_no++;
758 return 0;
762 * zfcp_fsf_status_read - send status read request
763 * @adapter: pointer to struct zfcp_adapter
764 * @req_flags: request flags
765 * Returns: 0 on success, ERROR otherwise
767 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
769 struct zfcp_adapter *adapter = qdio->adapter;
770 struct zfcp_fsf_req *req;
771 struct fsf_status_read_buffer *sr_buf;
772 int retval = -EIO;
774 spin_lock_bh(&qdio->req_q_lock);
775 if (zfcp_qdio_sbal_get(qdio))
776 goto out;
778 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS, 0,
779 adapter->pool.status_read_req);
780 if (IS_ERR(req)) {
781 retval = PTR_ERR(req);
782 goto out;
785 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
786 if (!sr_buf) {
787 retval = -ENOMEM;
788 goto failed_buf;
790 memset(sr_buf, 0, sizeof(*sr_buf));
791 req->data = sr_buf;
793 zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
794 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
796 retval = zfcp_fsf_req_send(req);
797 if (retval)
798 goto failed_req_send;
800 goto out;
802 failed_req_send:
803 mempool_free(sr_buf, adapter->pool.status_read_data);
804 failed_buf:
805 zfcp_fsf_req_free(req);
806 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
807 out:
808 spin_unlock_bh(&qdio->req_q_lock);
809 return retval;
812 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
814 struct zfcp_unit *unit = req->data;
815 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
817 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
818 return;
820 switch (req->qtcb->header.fsf_status) {
821 case FSF_PORT_HANDLE_NOT_VALID:
822 if (fsq->word[0] == fsq->word[1]) {
823 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
824 "fsafch1", req);
825 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
827 break;
828 case FSF_LUN_HANDLE_NOT_VALID:
829 if (fsq->word[0] == fsq->word[1]) {
830 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
831 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
833 break;
834 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
835 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
836 break;
837 case FSF_PORT_BOXED:
838 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
839 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
840 break;
841 case FSF_LUN_BOXED:
842 zfcp_erp_unit_boxed(unit, "fsafch4", req);
843 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
844 break;
845 case FSF_ADAPTER_STATUS_AVAILABLE:
846 switch (fsq->word[0]) {
847 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
848 zfcp_fc_test_link(unit->port);
849 /* fall through */
850 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
851 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
852 break;
854 break;
855 case FSF_GOOD:
856 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
857 break;
862 * zfcp_fsf_abort_fcp_command - abort running SCSI command
863 * @old_req_id: unsigned long
864 * @unit: pointer to struct zfcp_unit
865 * Returns: pointer to struct zfcp_fsf_req
868 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
869 struct zfcp_unit *unit)
871 struct zfcp_fsf_req *req = NULL;
872 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
874 spin_lock_bh(&qdio->req_q_lock);
875 if (zfcp_qdio_sbal_get(qdio))
876 goto out;
877 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
878 SBAL_FLAGS0_TYPE_READ,
879 qdio->adapter->pool.scsi_abort);
880 if (IS_ERR(req)) {
881 req = NULL;
882 goto out;
885 if (unlikely(!(atomic_read(&unit->status) &
886 ZFCP_STATUS_COMMON_UNBLOCKED)))
887 goto out_error_free;
889 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
891 req->data = unit;
892 req->handler = zfcp_fsf_abort_fcp_command_handler;
893 req->qtcb->header.lun_handle = unit->handle;
894 req->qtcb->header.port_handle = unit->port->handle;
895 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
897 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
898 if (!zfcp_fsf_req_send(req))
899 goto out;
901 out_error_free:
902 zfcp_fsf_req_free(req);
903 req = NULL;
904 out:
905 spin_unlock_bh(&qdio->req_q_lock);
906 return req;
909 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
911 struct zfcp_adapter *adapter = req->adapter;
912 struct zfcp_fsf_ct_els *ct = req->data;
913 struct fsf_qtcb_header *header = &req->qtcb->header;
915 ct->status = -EINVAL;
917 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
918 goto skip_fsfstatus;
920 switch (header->fsf_status) {
921 case FSF_GOOD:
922 zfcp_dbf_san_ct_response(req);
923 ct->status = 0;
924 break;
925 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
926 zfcp_fsf_class_not_supp(req);
927 break;
928 case FSF_ADAPTER_STATUS_AVAILABLE:
929 switch (header->fsf_status_qual.word[0]){
930 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
931 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
932 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
933 break;
935 break;
936 case FSF_ACCESS_DENIED:
937 break;
938 case FSF_PORT_BOXED:
939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
940 break;
941 case FSF_PORT_HANDLE_NOT_VALID:
942 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
943 /* fall through */
944 case FSF_GENERIC_COMMAND_REJECTED:
945 case FSF_PAYLOAD_SIZE_MISMATCH:
946 case FSF_REQUEST_SIZE_TOO_LARGE:
947 case FSF_RESPONSE_SIZE_TOO_LARGE:
948 case FSF_SBAL_MISMATCH:
949 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
950 break;
953 skip_fsfstatus:
954 if (ct->handler)
955 ct->handler(ct->handler_data);
958 static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
959 struct zfcp_qdio_req *q_req,
960 struct scatterlist *sg_req,
961 struct scatterlist *sg_resp)
963 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
964 zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
965 zfcp_qdio_set_sbale_last(qdio, q_req);
968 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
969 struct scatterlist *sg_req,
970 struct scatterlist *sg_resp)
972 struct zfcp_adapter *adapter = req->adapter;
973 u32 feat = adapter->adapter_features;
974 int bytes;
976 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
977 if (!zfcp_qdio_sg_one_sbale(sg_req) ||
978 !zfcp_qdio_sg_one_sbale(sg_resp))
979 return -EOPNOTSUPP;
981 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
982 sg_req, sg_resp);
983 return 0;
986 /* use single, unchained SBAL if it can hold the request */
987 if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
988 zfcp_fsf_setup_ct_els_unchained(adapter->qdio, &req->qdio_req,
989 sg_req, sg_resp);
990 return 0;
993 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req, sg_req);
994 if (bytes <= 0)
995 return -EIO;
996 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
997 req->qtcb->bottom.support.req_buf_length = bytes;
998 zfcp_qdio_skip_to_last_sbale(&req->qdio_req);
1000 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->qdio_req,
1001 sg_resp);
1002 req->qtcb->bottom.support.resp_buf_length = bytes;
1003 if (bytes <= 0)
1004 return -EIO;
1005 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
1007 return 0;
1010 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1011 struct scatterlist *sg_req,
1012 struct scatterlist *sg_resp,
1013 unsigned int timeout)
1015 int ret;
1017 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
1018 if (ret)
1019 return ret;
1021 /* common settings for ct/gs and els requests */
1022 if (timeout > 255)
1023 timeout = 255; /* max value accepted by hardware */
1024 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1025 req->qtcb->bottom.support.timeout = timeout;
1026 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1028 return 0;
1032 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1033 * @ct: pointer to struct zfcp_send_ct with data for request
1034 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1036 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1037 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1038 unsigned int timeout)
1040 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1041 struct zfcp_fsf_req *req;
1042 int ret = -EIO;
1044 spin_lock_bh(&qdio->req_q_lock);
1045 if (zfcp_qdio_sbal_get(qdio))
1046 goto out;
1048 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
1049 SBAL_FLAGS0_TYPE_WRITE_READ, pool);
1051 if (IS_ERR(req)) {
1052 ret = PTR_ERR(req);
1053 goto out;
1056 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1057 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
1058 if (ret)
1059 goto failed_send;
1061 req->handler = zfcp_fsf_send_ct_handler;
1062 req->qtcb->header.port_handle = wka_port->handle;
1063 req->data = ct;
1065 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1067 ret = zfcp_fsf_req_send(req);
1068 if (ret)
1069 goto failed_send;
1071 goto out;
1073 failed_send:
1074 zfcp_fsf_req_free(req);
1075 out:
1076 spin_unlock_bh(&qdio->req_q_lock);
1077 return ret;
1080 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1082 struct zfcp_fsf_ct_els *send_els = req->data;
1083 struct zfcp_port *port = send_els->port;
1084 struct fsf_qtcb_header *header = &req->qtcb->header;
1086 send_els->status = -EINVAL;
1088 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1089 goto skip_fsfstatus;
1091 switch (header->fsf_status) {
1092 case FSF_GOOD:
1093 zfcp_dbf_san_els_response(req);
1094 send_els->status = 0;
1095 break;
1096 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1097 zfcp_fsf_class_not_supp(req);
1098 break;
1099 case FSF_ADAPTER_STATUS_AVAILABLE:
1100 switch (header->fsf_status_qual.word[0]){
1101 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1102 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1103 case FSF_SQ_RETRY_IF_POSSIBLE:
1104 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1105 break;
1107 break;
1108 case FSF_ELS_COMMAND_REJECTED:
1109 case FSF_PAYLOAD_SIZE_MISMATCH:
1110 case FSF_REQUEST_SIZE_TOO_LARGE:
1111 case FSF_RESPONSE_SIZE_TOO_LARGE:
1112 break;
1113 case FSF_ACCESS_DENIED:
1114 if (port)
1115 zfcp_fsf_access_denied_port(req, port);
1116 break;
1117 case FSF_SBAL_MISMATCH:
1118 /* should never occure, avoided in zfcp_fsf_send_els */
1119 /* fall through */
1120 default:
1121 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1122 break;
1124 skip_fsfstatus:
1125 if (send_els->handler)
1126 send_els->handler(send_els->handler_data);
1130 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1131 * @els: pointer to struct zfcp_send_els with data for the command
1133 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1134 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1136 struct zfcp_fsf_req *req;
1137 struct zfcp_qdio *qdio = adapter->qdio;
1138 int ret = -EIO;
1140 spin_lock_bh(&qdio->req_q_lock);
1141 if (zfcp_qdio_sbal_get(qdio))
1142 goto out;
1144 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
1145 SBAL_FLAGS0_TYPE_WRITE_READ, NULL);
1147 if (IS_ERR(req)) {
1148 ret = PTR_ERR(req);
1149 goto out;
1152 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1154 zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
1156 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
1158 if (ret)
1159 goto failed_send;
1161 hton24(req->qtcb->bottom.support.d_id, d_id);
1162 req->handler = zfcp_fsf_send_els_handler;
1163 req->data = els;
1165 zfcp_dbf_san_els_request(req);
1167 ret = zfcp_fsf_req_send(req);
1168 if (ret)
1169 goto failed_send;
1171 goto out;
1173 failed_send:
1174 zfcp_fsf_req_free(req);
1175 out:
1176 spin_unlock_bh(&qdio->req_q_lock);
1177 return ret;
1180 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1182 struct zfcp_fsf_req *req;
1183 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1184 int retval = -EIO;
1186 spin_lock_bh(&qdio->req_q_lock);
1187 if (zfcp_qdio_sbal_get(qdio))
1188 goto out;
1190 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1191 SBAL_FLAGS0_TYPE_READ,
1192 qdio->adapter->pool.erp_req);
1194 if (IS_ERR(req)) {
1195 retval = PTR_ERR(req);
1196 goto out;
1199 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1200 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1202 req->qtcb->bottom.config.feature_selection =
1203 FSF_FEATURE_CFDC |
1204 FSF_FEATURE_LUN_SHARING |
1205 FSF_FEATURE_NOTIFICATION_LOST |
1206 FSF_FEATURE_UPDATE_ALERT;
1207 req->erp_action = erp_action;
1208 req->handler = zfcp_fsf_exchange_config_data_handler;
1209 erp_action->fsf_req_id = req->req_id;
1211 zfcp_fsf_start_erp_timer(req);
1212 retval = zfcp_fsf_req_send(req);
1213 if (retval) {
1214 zfcp_fsf_req_free(req);
1215 erp_action->fsf_req_id = 0;
1217 out:
1218 spin_unlock_bh(&qdio->req_q_lock);
1219 return retval;
1222 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1223 struct fsf_qtcb_bottom_config *data)
1225 struct zfcp_fsf_req *req = NULL;
1226 int retval = -EIO;
1228 spin_lock_bh(&qdio->req_q_lock);
1229 if (zfcp_qdio_sbal_get(qdio))
1230 goto out_unlock;
1232 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1233 SBAL_FLAGS0_TYPE_READ, NULL);
1235 if (IS_ERR(req)) {
1236 retval = PTR_ERR(req);
1237 goto out_unlock;
1240 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1241 req->handler = zfcp_fsf_exchange_config_data_handler;
1243 req->qtcb->bottom.config.feature_selection =
1244 FSF_FEATURE_CFDC |
1245 FSF_FEATURE_LUN_SHARING |
1246 FSF_FEATURE_NOTIFICATION_LOST |
1247 FSF_FEATURE_UPDATE_ALERT;
1249 if (data)
1250 req->data = data;
1252 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1253 retval = zfcp_fsf_req_send(req);
1254 spin_unlock_bh(&qdio->req_q_lock);
1255 if (!retval)
1256 wait_for_completion(&req->completion);
1258 zfcp_fsf_req_free(req);
1259 return retval;
1261 out_unlock:
1262 spin_unlock_bh(&qdio->req_q_lock);
1263 return retval;
1267 * zfcp_fsf_exchange_port_data - request information about local port
1268 * @erp_action: ERP action for the adapter for which port data is requested
1269 * Returns: 0 on success, error otherwise
1271 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1273 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1274 struct zfcp_fsf_req *req;
1275 int retval = -EIO;
1277 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1278 return -EOPNOTSUPP;
1280 spin_lock_bh(&qdio->req_q_lock);
1281 if (zfcp_qdio_sbal_get(qdio))
1282 goto out;
1284 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1285 SBAL_FLAGS0_TYPE_READ,
1286 qdio->adapter->pool.erp_req);
1288 if (IS_ERR(req)) {
1289 retval = PTR_ERR(req);
1290 goto out;
1293 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1294 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1296 req->handler = zfcp_fsf_exchange_port_data_handler;
1297 req->erp_action = erp_action;
1298 erp_action->fsf_req_id = req->req_id;
1300 zfcp_fsf_start_erp_timer(req);
1301 retval = zfcp_fsf_req_send(req);
1302 if (retval) {
1303 zfcp_fsf_req_free(req);
1304 erp_action->fsf_req_id = 0;
1306 out:
1307 spin_unlock_bh(&qdio->req_q_lock);
1308 return retval;
1312 * zfcp_fsf_exchange_port_data_sync - request information about local port
1313 * @qdio: pointer to struct zfcp_qdio
1314 * @data: pointer to struct fsf_qtcb_bottom_port
1315 * Returns: 0 on success, error otherwise
1317 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1318 struct fsf_qtcb_bottom_port *data)
1320 struct zfcp_fsf_req *req = NULL;
1321 int retval = -EIO;
1323 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1324 return -EOPNOTSUPP;
1326 spin_lock_bh(&qdio->req_q_lock);
1327 if (zfcp_qdio_sbal_get(qdio))
1328 goto out_unlock;
1330 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1331 SBAL_FLAGS0_TYPE_READ, NULL);
1333 if (IS_ERR(req)) {
1334 retval = PTR_ERR(req);
1335 goto out_unlock;
1338 if (data)
1339 req->data = data;
1341 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1343 req->handler = zfcp_fsf_exchange_port_data_handler;
1344 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1345 retval = zfcp_fsf_req_send(req);
1346 spin_unlock_bh(&qdio->req_q_lock);
1348 if (!retval)
1349 wait_for_completion(&req->completion);
1351 zfcp_fsf_req_free(req);
1353 return retval;
1355 out_unlock:
1356 spin_unlock_bh(&qdio->req_q_lock);
1357 return retval;
1360 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1362 struct zfcp_port *port = req->data;
1363 struct fsf_qtcb_header *header = &req->qtcb->header;
1364 struct fc_els_flogi *plogi;
1366 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1367 goto out;
1369 switch (header->fsf_status) {
1370 case FSF_PORT_ALREADY_OPEN:
1371 break;
1372 case FSF_ACCESS_DENIED:
1373 zfcp_fsf_access_denied_port(req, port);
1374 break;
1375 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1376 dev_warn(&req->adapter->ccw_device->dev,
1377 "Not enough FCP adapter resources to open "
1378 "remote port 0x%016Lx\n",
1379 (unsigned long long)port->wwpn);
1380 zfcp_erp_port_failed(port, "fsoph_1", req);
1381 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1382 break;
1383 case FSF_ADAPTER_STATUS_AVAILABLE:
1384 switch (header->fsf_status_qual.word[0]) {
1385 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1386 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1387 case FSF_SQ_NO_RETRY_POSSIBLE:
1388 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1389 break;
1391 break;
1392 case FSF_GOOD:
1393 port->handle = header->port_handle;
1394 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1395 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1396 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1397 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1398 &port->status);
1399 /* check whether D_ID has changed during open */
1400 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1401 if (req->qtcb->bottom.support.els1_length >=
1402 FSF_PLOGI_MIN_LEN)
1403 zfcp_fc_plogi_evaluate(port, plogi);
1404 break;
1405 case FSF_UNKNOWN_OP_SUBTYPE:
1406 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1407 break;
1410 out:
1411 put_device(&port->dev);
1415 * zfcp_fsf_open_port - create and send open port request
1416 * @erp_action: pointer to struct zfcp_erp_action
1417 * Returns: 0 on success, error otherwise
1419 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1421 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1422 struct zfcp_port *port = erp_action->port;
1423 struct zfcp_fsf_req *req;
1424 int retval = -EIO;
1426 spin_lock_bh(&qdio->req_q_lock);
1427 if (zfcp_qdio_sbal_get(qdio))
1428 goto out;
1430 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1431 SBAL_FLAGS0_TYPE_READ,
1432 qdio->adapter->pool.erp_req);
1434 if (IS_ERR(req)) {
1435 retval = PTR_ERR(req);
1436 goto out;
1439 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1440 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1442 req->handler = zfcp_fsf_open_port_handler;
1443 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1444 req->data = port;
1445 req->erp_action = erp_action;
1446 erp_action->fsf_req_id = req->req_id;
1447 get_device(&port->dev);
1449 zfcp_fsf_start_erp_timer(req);
1450 retval = zfcp_fsf_req_send(req);
1451 if (retval) {
1452 zfcp_fsf_req_free(req);
1453 erp_action->fsf_req_id = 0;
1454 put_device(&port->dev);
1456 out:
1457 spin_unlock_bh(&qdio->req_q_lock);
1458 return retval;
1461 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1463 struct zfcp_port *port = req->data;
1465 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1466 return;
1468 switch (req->qtcb->header.fsf_status) {
1469 case FSF_PORT_HANDLE_NOT_VALID:
1470 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1471 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1472 break;
1473 case FSF_ADAPTER_STATUS_AVAILABLE:
1474 break;
1475 case FSF_GOOD:
1476 zfcp_erp_modify_port_status(port, "fscph_2", req,
1477 ZFCP_STATUS_COMMON_OPEN,
1478 ZFCP_CLEAR);
1479 break;
1484 * zfcp_fsf_close_port - create and send close port request
1485 * @erp_action: pointer to struct zfcp_erp_action
1486 * Returns: 0 on success, error otherwise
1488 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1490 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1491 struct zfcp_fsf_req *req;
1492 int retval = -EIO;
1494 spin_lock_bh(&qdio->req_q_lock);
1495 if (zfcp_qdio_sbal_get(qdio))
1496 goto out;
1498 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1499 SBAL_FLAGS0_TYPE_READ,
1500 qdio->adapter->pool.erp_req);
1502 if (IS_ERR(req)) {
1503 retval = PTR_ERR(req);
1504 goto out;
1507 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1508 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1510 req->handler = zfcp_fsf_close_port_handler;
1511 req->data = erp_action->port;
1512 req->erp_action = erp_action;
1513 req->qtcb->header.port_handle = erp_action->port->handle;
1514 erp_action->fsf_req_id = req->req_id;
1516 zfcp_fsf_start_erp_timer(req);
1517 retval = zfcp_fsf_req_send(req);
1518 if (retval) {
1519 zfcp_fsf_req_free(req);
1520 erp_action->fsf_req_id = 0;
1522 out:
1523 spin_unlock_bh(&qdio->req_q_lock);
1524 return retval;
1527 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1529 struct zfcp_fc_wka_port *wka_port = req->data;
1530 struct fsf_qtcb_header *header = &req->qtcb->header;
1532 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1533 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1534 goto out;
1537 switch (header->fsf_status) {
1538 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1539 dev_warn(&req->adapter->ccw_device->dev,
1540 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1541 /* fall through */
1542 case FSF_ADAPTER_STATUS_AVAILABLE:
1543 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1544 /* fall through */
1545 case FSF_ACCESS_DENIED:
1546 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1547 break;
1548 case FSF_GOOD:
1549 wka_port->handle = header->port_handle;
1550 /* fall through */
1551 case FSF_PORT_ALREADY_OPEN:
1552 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1554 out:
1555 wake_up(&wka_port->completion_wq);
1559 * zfcp_fsf_open_wka_port - create and send open wka-port request
1560 * @wka_port: pointer to struct zfcp_fc_wka_port
1561 * Returns: 0 on success, error otherwise
1563 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1565 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1566 struct zfcp_fsf_req *req;
1567 int retval = -EIO;
1569 spin_lock_bh(&qdio->req_q_lock);
1570 if (zfcp_qdio_sbal_get(qdio))
1571 goto out;
1573 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1574 SBAL_FLAGS0_TYPE_READ,
1575 qdio->adapter->pool.erp_req);
1577 if (unlikely(IS_ERR(req))) {
1578 retval = PTR_ERR(req);
1579 goto out;
1582 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1583 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1585 req->handler = zfcp_fsf_open_wka_port_handler;
1586 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1587 req->data = wka_port;
1589 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1590 retval = zfcp_fsf_req_send(req);
1591 if (retval)
1592 zfcp_fsf_req_free(req);
1593 out:
1594 spin_unlock_bh(&qdio->req_q_lock);
1595 return retval;
1598 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1600 struct zfcp_fc_wka_port *wka_port = req->data;
1602 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1603 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1604 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1607 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1608 wake_up(&wka_port->completion_wq);
1612 * zfcp_fsf_close_wka_port - create and send close wka port request
1613 * @wka_port: WKA port to open
1614 * Returns: 0 on success, error otherwise
1616 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1618 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1619 struct zfcp_fsf_req *req;
1620 int retval = -EIO;
1622 spin_lock_bh(&qdio->req_q_lock);
1623 if (zfcp_qdio_sbal_get(qdio))
1624 goto out;
1626 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1627 SBAL_FLAGS0_TYPE_READ,
1628 qdio->adapter->pool.erp_req);
1630 if (unlikely(IS_ERR(req))) {
1631 retval = PTR_ERR(req);
1632 goto out;
1635 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1636 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1638 req->handler = zfcp_fsf_close_wka_port_handler;
1639 req->data = wka_port;
1640 req->qtcb->header.port_handle = wka_port->handle;
1642 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1643 retval = zfcp_fsf_req_send(req);
1644 if (retval)
1645 zfcp_fsf_req_free(req);
1646 out:
1647 spin_unlock_bh(&qdio->req_q_lock);
1648 return retval;
1651 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1653 struct zfcp_port *port = req->data;
1654 struct fsf_qtcb_header *header = &req->qtcb->header;
1655 struct zfcp_unit *unit;
1657 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1658 return;
1660 switch (header->fsf_status) {
1661 case FSF_PORT_HANDLE_NOT_VALID:
1662 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1663 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1664 break;
1665 case FSF_ACCESS_DENIED:
1666 zfcp_fsf_access_denied_port(req, port);
1667 break;
1668 case FSF_PORT_BOXED:
1669 /* can't use generic zfcp_erp_modify_port_status because
1670 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1671 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1672 read_lock(&port->unit_list_lock);
1673 list_for_each_entry(unit, &port->unit_list, list)
1674 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1675 &unit->status);
1676 read_unlock(&port->unit_list_lock);
1677 zfcp_erp_port_boxed(port, "fscpph2", req);
1678 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1679 break;
1680 case FSF_ADAPTER_STATUS_AVAILABLE:
1681 switch (header->fsf_status_qual.word[0]) {
1682 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1683 /* fall through */
1684 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1685 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1686 break;
1688 break;
1689 case FSF_GOOD:
1690 /* can't use generic zfcp_erp_modify_port_status because
1691 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1693 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1694 read_lock(&port->unit_list_lock);
1695 list_for_each_entry(unit, &port->unit_list, list)
1696 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1697 &unit->status);
1698 read_unlock(&port->unit_list_lock);
1699 break;
1704 * zfcp_fsf_close_physical_port - close physical port
1705 * @erp_action: pointer to struct zfcp_erp_action
1706 * Returns: 0 on success
1708 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1710 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1711 struct zfcp_fsf_req *req;
1712 int retval = -EIO;
1714 spin_lock_bh(&qdio->req_q_lock);
1715 if (zfcp_qdio_sbal_get(qdio))
1716 goto out;
1718 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1719 SBAL_FLAGS0_TYPE_READ,
1720 qdio->adapter->pool.erp_req);
1722 if (IS_ERR(req)) {
1723 retval = PTR_ERR(req);
1724 goto out;
1727 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1728 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1730 req->data = erp_action->port;
1731 req->qtcb->header.port_handle = erp_action->port->handle;
1732 req->erp_action = erp_action;
1733 req->handler = zfcp_fsf_close_physical_port_handler;
1734 erp_action->fsf_req_id = req->req_id;
1736 zfcp_fsf_start_erp_timer(req);
1737 retval = zfcp_fsf_req_send(req);
1738 if (retval) {
1739 zfcp_fsf_req_free(req);
1740 erp_action->fsf_req_id = 0;
1742 out:
1743 spin_unlock_bh(&qdio->req_q_lock);
1744 return retval;
1747 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1749 struct zfcp_adapter *adapter = req->adapter;
1750 struct zfcp_unit *unit = req->data;
1751 struct fsf_qtcb_header *header = &req->qtcb->header;
1752 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1753 struct fsf_queue_designator *queue_designator =
1754 &header->fsf_status_qual.fsf_queue_designator;
1755 int exclusive, readwrite;
1757 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1758 return;
1760 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1761 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1762 ZFCP_STATUS_UNIT_SHARED |
1763 ZFCP_STATUS_UNIT_READONLY,
1764 &unit->status);
1766 switch (header->fsf_status) {
1768 case FSF_PORT_HANDLE_NOT_VALID:
1769 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1770 /* fall through */
1771 case FSF_LUN_ALREADY_OPEN:
1772 break;
1773 case FSF_ACCESS_DENIED:
1774 zfcp_fsf_access_denied_unit(req, unit);
1775 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1776 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1777 break;
1778 case FSF_PORT_BOXED:
1779 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1780 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1781 break;
1782 case FSF_LUN_SHARING_VIOLATION:
1783 if (header->fsf_status_qual.word[0])
1784 dev_warn(&adapter->ccw_device->dev,
1785 "LUN 0x%Lx on port 0x%Lx is already in "
1786 "use by CSS%d, MIF Image ID %x\n",
1787 (unsigned long long)unit->fcp_lun,
1788 (unsigned long long)unit->port->wwpn,
1789 queue_designator->cssid,
1790 queue_designator->hla);
1791 else
1792 zfcp_act_eval_err(adapter,
1793 header->fsf_status_qual.word[2]);
1794 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1795 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1796 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1797 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1798 break;
1799 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1800 dev_warn(&adapter->ccw_device->dev,
1801 "No handle is available for LUN "
1802 "0x%016Lx on port 0x%016Lx\n",
1803 (unsigned long long)unit->fcp_lun,
1804 (unsigned long long)unit->port->wwpn);
1805 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1806 /* fall through */
1807 case FSF_INVALID_COMMAND_OPTION:
1808 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1809 break;
1810 case FSF_ADAPTER_STATUS_AVAILABLE:
1811 switch (header->fsf_status_qual.word[0]) {
1812 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1813 zfcp_fc_test_link(unit->port);
1814 /* fall through */
1815 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1816 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1817 break;
1819 break;
1821 case FSF_GOOD:
1822 unit->handle = header->lun_handle;
1823 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1825 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1826 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1827 !zfcp_ccw_priv_sch(adapter)) {
1828 exclusive = (bottom->lun_access_info &
1829 FSF_UNIT_ACCESS_EXCLUSIVE);
1830 readwrite = (bottom->lun_access_info &
1831 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1833 if (!exclusive)
1834 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1835 &unit->status);
1837 if (!readwrite) {
1838 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1839 &unit->status);
1840 dev_info(&adapter->ccw_device->dev,
1841 "SCSI device at LUN 0x%016Lx on port "
1842 "0x%016Lx opened read-only\n",
1843 (unsigned long long)unit->fcp_lun,
1844 (unsigned long long)unit->port->wwpn);
1847 if (exclusive && !readwrite) {
1848 dev_err(&adapter->ccw_device->dev,
1849 "Exclusive read-only access not "
1850 "supported (unit 0x%016Lx, "
1851 "port 0x%016Lx)\n",
1852 (unsigned long long)unit->fcp_lun,
1853 (unsigned long long)unit->port->wwpn);
1854 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1855 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1857 } else if (!exclusive && readwrite) {
1858 dev_err(&adapter->ccw_device->dev,
1859 "Shared read-write access not "
1860 "supported (unit 0x%016Lx, port "
1861 "0x%016Lx)\n",
1862 (unsigned long long)unit->fcp_lun,
1863 (unsigned long long)unit->port->wwpn);
1864 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1865 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1866 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1869 break;
1874 * zfcp_fsf_open_unit - open unit
1875 * @erp_action: pointer to struct zfcp_erp_action
1876 * Returns: 0 on success, error otherwise
1878 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1880 struct zfcp_adapter *adapter = erp_action->adapter;
1881 struct zfcp_qdio *qdio = adapter->qdio;
1882 struct zfcp_fsf_req *req;
1883 int retval = -EIO;
1885 spin_lock_bh(&qdio->req_q_lock);
1886 if (zfcp_qdio_sbal_get(qdio))
1887 goto out;
1889 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1890 SBAL_FLAGS0_TYPE_READ,
1891 adapter->pool.erp_req);
1893 if (IS_ERR(req)) {
1894 retval = PTR_ERR(req);
1895 goto out;
1898 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1899 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1901 req->qtcb->header.port_handle = erp_action->port->handle;
1902 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1903 req->handler = zfcp_fsf_open_unit_handler;
1904 req->data = erp_action->unit;
1905 req->erp_action = erp_action;
1906 erp_action->fsf_req_id = req->req_id;
1908 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1909 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1911 zfcp_fsf_start_erp_timer(req);
1912 retval = zfcp_fsf_req_send(req);
1913 if (retval) {
1914 zfcp_fsf_req_free(req);
1915 erp_action->fsf_req_id = 0;
1917 out:
1918 spin_unlock_bh(&qdio->req_q_lock);
1919 return retval;
1922 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
1924 struct zfcp_unit *unit = req->data;
1926 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1927 return;
1929 switch (req->qtcb->header.fsf_status) {
1930 case FSF_PORT_HANDLE_NOT_VALID:
1931 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
1932 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1933 break;
1934 case FSF_LUN_HANDLE_NOT_VALID:
1935 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
1936 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1937 break;
1938 case FSF_PORT_BOXED:
1939 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
1940 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1941 break;
1942 case FSF_ADAPTER_STATUS_AVAILABLE:
1943 switch (req->qtcb->header.fsf_status_qual.word[0]) {
1944 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1945 zfcp_fc_test_link(unit->port);
1946 /* fall through */
1947 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1948 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1949 break;
1951 break;
1952 case FSF_GOOD:
1953 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1954 break;
1959 * zfcp_fsf_close_unit - close zfcp unit
1960 * @erp_action: pointer to struct zfcp_unit
1961 * Returns: 0 on success, error otherwise
1963 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
1965 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1966 struct zfcp_fsf_req *req;
1967 int retval = -EIO;
1969 spin_lock_bh(&qdio->req_q_lock);
1970 if (zfcp_qdio_sbal_get(qdio))
1971 goto out;
1973 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
1974 SBAL_FLAGS0_TYPE_READ,
1975 qdio->adapter->pool.erp_req);
1977 if (IS_ERR(req)) {
1978 retval = PTR_ERR(req);
1979 goto out;
1982 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1983 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
1985 req->qtcb->header.port_handle = erp_action->port->handle;
1986 req->qtcb->header.lun_handle = erp_action->unit->handle;
1987 req->handler = zfcp_fsf_close_unit_handler;
1988 req->data = erp_action->unit;
1989 req->erp_action = erp_action;
1990 erp_action->fsf_req_id = req->req_id;
1992 zfcp_fsf_start_erp_timer(req);
1993 retval = zfcp_fsf_req_send(req);
1994 if (retval) {
1995 zfcp_fsf_req_free(req);
1996 erp_action->fsf_req_id = 0;
1998 out:
1999 spin_unlock_bh(&qdio->req_q_lock);
2000 return retval;
2003 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2005 lat_rec->sum += lat;
2006 lat_rec->min = min(lat_rec->min, lat);
2007 lat_rec->max = max(lat_rec->max, lat);
2010 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2012 struct fsf_qual_latency_info *lat_in;
2013 struct latency_cont *lat = NULL;
2014 struct zfcp_unit *unit = req->unit;
2015 struct zfcp_blk_drv_data blktrc;
2016 int ticks = req->adapter->timer_ticks;
2018 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2020 blktrc.flags = 0;
2021 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2022 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2023 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2024 blktrc.inb_usage = 0;
2025 blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
2027 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
2028 !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2029 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2030 blktrc.channel_lat = lat_in->channel_lat * ticks;
2031 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2033 switch (req->qtcb->bottom.io.data_direction) {
2034 case FSF_DATADIR_DIF_READ_STRIP:
2035 case FSF_DATADIR_DIF_READ_CONVERT:
2036 case FSF_DATADIR_READ:
2037 lat = &unit->latencies.read;
2038 break;
2039 case FSF_DATADIR_DIF_WRITE_INSERT:
2040 case FSF_DATADIR_DIF_WRITE_CONVERT:
2041 case FSF_DATADIR_WRITE:
2042 lat = &unit->latencies.write;
2043 break;
2044 case FSF_DATADIR_CMND:
2045 lat = &unit->latencies.cmd;
2046 break;
2049 if (lat) {
2050 spin_lock(&unit->latencies.lock);
2051 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2052 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2053 lat->counter++;
2054 spin_unlock(&unit->latencies.lock);
2058 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2059 sizeof(blktrc));
2062 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2064 struct scsi_cmnd *scpnt;
2065 struct fcp_resp_with_ext *fcp_rsp;
2066 unsigned long flags;
2068 read_lock_irqsave(&req->adapter->abort_lock, flags);
2070 scpnt = req->data;
2071 if (unlikely(!scpnt)) {
2072 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2073 return;
2076 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2077 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2078 goto skip_fsfstatus;
2081 switch (req->qtcb->header.fsf_status) {
2082 case FSF_INCONSISTENT_PROT_DATA:
2083 case FSF_INVALID_PROT_PARM:
2084 set_host_byte(scpnt, DID_ERROR);
2085 goto skip_fsfstatus;
2086 case FSF_BLOCK_GUARD_CHECK_FAILURE:
2087 zfcp_scsi_dif_sense_error(scpnt, 0x1);
2088 goto skip_fsfstatus;
2089 case FSF_APP_TAG_CHECK_FAILURE:
2090 zfcp_scsi_dif_sense_error(scpnt, 0x2);
2091 goto skip_fsfstatus;
2092 case FSF_REF_TAG_CHECK_FAILURE:
2093 zfcp_scsi_dif_sense_error(scpnt, 0x3);
2094 goto skip_fsfstatus;
2096 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2097 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2099 skip_fsfstatus:
2100 zfcp_fsf_req_trace(req, scpnt);
2101 zfcp_dbf_scsi_result(req->adapter->dbf, scpnt, req);
2103 scpnt->host_scribble = NULL;
2104 (scpnt->scsi_done) (scpnt);
2106 * We must hold this lock until scsi_done has been called.
2107 * Otherwise we may call scsi_done after abort regarding this
2108 * command has completed.
2109 * Note: scsi_done must not block!
2111 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2114 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2116 struct fcp_resp_with_ext *fcp_rsp;
2117 struct fcp_resp_rsp_info *rsp_info;
2119 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2120 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2122 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2123 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2124 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2128 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2130 struct zfcp_unit *unit;
2131 struct fsf_qtcb_header *header = &req->qtcb->header;
2133 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2134 unit = req->data;
2135 else
2136 unit = req->unit;
2138 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2139 goto skip_fsfstatus;
2141 switch (header->fsf_status) {
2142 case FSF_HANDLE_MISMATCH:
2143 case FSF_PORT_HANDLE_NOT_VALID:
2144 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2145 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2146 break;
2147 case FSF_FCPLUN_NOT_VALID:
2148 case FSF_LUN_HANDLE_NOT_VALID:
2149 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2150 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2151 break;
2152 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2153 zfcp_fsf_class_not_supp(req);
2154 break;
2155 case FSF_ACCESS_DENIED:
2156 zfcp_fsf_access_denied_unit(req, unit);
2157 break;
2158 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2159 dev_err(&req->adapter->ccw_device->dev,
2160 "Incorrect direction %d, unit 0x%016Lx on port "
2161 "0x%016Lx closed\n",
2162 req->qtcb->bottom.io.data_direction,
2163 (unsigned long long)unit->fcp_lun,
2164 (unsigned long long)unit->port->wwpn);
2165 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2166 req);
2167 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2168 break;
2169 case FSF_CMND_LENGTH_NOT_VALID:
2170 dev_err(&req->adapter->ccw_device->dev,
2171 "Incorrect CDB length %d, unit 0x%016Lx on "
2172 "port 0x%016Lx closed\n",
2173 req->qtcb->bottom.io.fcp_cmnd_length,
2174 (unsigned long long)unit->fcp_lun,
2175 (unsigned long long)unit->port->wwpn);
2176 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2177 req);
2178 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2179 break;
2180 case FSF_PORT_BOXED:
2181 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2182 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2183 break;
2184 case FSF_LUN_BOXED:
2185 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2186 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2187 break;
2188 case FSF_ADAPTER_STATUS_AVAILABLE:
2189 if (header->fsf_status_qual.word[0] ==
2190 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2191 zfcp_fc_test_link(unit->port);
2192 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2193 break;
2195 skip_fsfstatus:
2196 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2197 zfcp_fsf_send_fcp_ctm_handler(req);
2198 else {
2199 zfcp_fsf_send_fcp_command_task_handler(req);
2200 req->unit = NULL;
2201 put_device(&unit->dev);
2205 static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
2207 switch (scsi_get_prot_op(scsi_cmnd)) {
2208 case SCSI_PROT_NORMAL:
2209 switch (scsi_cmnd->sc_data_direction) {
2210 case DMA_NONE:
2211 *data_dir = FSF_DATADIR_CMND;
2212 break;
2213 case DMA_FROM_DEVICE:
2214 *data_dir = FSF_DATADIR_READ;
2215 break;
2216 case DMA_TO_DEVICE:
2217 *data_dir = FSF_DATADIR_WRITE;
2218 break;
2219 case DMA_BIDIRECTIONAL:
2220 return -EINVAL;
2222 break;
2224 case SCSI_PROT_READ_STRIP:
2225 *data_dir = FSF_DATADIR_DIF_READ_STRIP;
2226 break;
2227 case SCSI_PROT_WRITE_INSERT:
2228 *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
2229 break;
2230 case SCSI_PROT_READ_PASS:
2231 *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
2232 break;
2233 case SCSI_PROT_WRITE_PASS:
2234 *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
2235 break;
2236 default:
2237 return -EINVAL;
2240 return 0;
2244 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2245 * @unit: unit where command is sent to
2246 * @scsi_cmnd: scsi command to be sent
2248 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2249 struct scsi_cmnd *scsi_cmnd)
2251 struct zfcp_fsf_req *req;
2252 struct fcp_cmnd *fcp_cmnd;
2253 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2254 int real_bytes, retval = -EIO, dix_bytes = 0;
2255 struct zfcp_adapter *adapter = unit->port->adapter;
2256 struct zfcp_qdio *qdio = adapter->qdio;
2257 struct fsf_qtcb_bottom_io *io;
2259 if (unlikely(!(atomic_read(&unit->status) &
2260 ZFCP_STATUS_COMMON_UNBLOCKED)))
2261 return -EBUSY;
2263 spin_lock(&qdio->req_q_lock);
2264 if (atomic_read(&qdio->req_q_free) <= 0) {
2265 atomic_inc(&qdio->req_q_full);
2266 goto out;
2269 if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
2270 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2272 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2273 sbtype, adapter->pool.scsi_req);
2275 if (IS_ERR(req)) {
2276 retval = PTR_ERR(req);
2277 goto out;
2280 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2282 io = &req->qtcb->bottom.io;
2283 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2284 req->unit = unit;
2285 req->data = scsi_cmnd;
2286 req->handler = zfcp_fsf_send_fcp_command_handler;
2287 req->qtcb->header.lun_handle = unit->handle;
2288 req->qtcb->header.port_handle = unit->port->handle;
2289 io->service_class = FSF_CLASS_3;
2290 io->fcp_cmnd_length = FCP_CMND_LEN;
2292 if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
2293 io->data_block_length = scsi_cmnd->device->sector_size;
2294 io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
2297 zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction);
2299 get_device(&unit->dev);
2301 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2302 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2304 if (scsi_prot_sg_count(scsi_cmnd)) {
2305 zfcp_qdio_set_data_div(qdio, &req->qdio_req,
2306 scsi_prot_sg_count(scsi_cmnd));
2307 dix_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2308 scsi_prot_sglist(scsi_cmnd));
2309 io->prot_data_length = dix_bytes;
2312 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
2313 scsi_sglist(scsi_cmnd));
2315 if (unlikely(real_bytes < 0) || unlikely(dix_bytes < 0))
2316 goto failed_scsi_cmnd;
2318 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2320 retval = zfcp_fsf_req_send(req);
2321 if (unlikely(retval))
2322 goto failed_scsi_cmnd;
2324 goto out;
2326 failed_scsi_cmnd:
2327 put_device(&unit->dev);
2328 zfcp_fsf_req_free(req);
2329 scsi_cmnd->host_scribble = NULL;
2330 out:
2331 spin_unlock(&qdio->req_q_lock);
2332 return retval;
2336 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2337 * @unit: pointer to struct zfcp_unit
2338 * @tm_flags: unsigned byte for task management flags
2339 * Returns: on success pointer to struct fsf_req, NULL otherwise
2341 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2343 struct zfcp_fsf_req *req = NULL;
2344 struct fcp_cmnd *fcp_cmnd;
2345 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2347 if (unlikely(!(atomic_read(&unit->status) &
2348 ZFCP_STATUS_COMMON_UNBLOCKED)))
2349 return NULL;
2351 spin_lock_bh(&qdio->req_q_lock);
2352 if (zfcp_qdio_sbal_get(qdio))
2353 goto out;
2355 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2356 SBAL_FLAGS0_TYPE_WRITE,
2357 qdio->adapter->pool.scsi_req);
2359 if (IS_ERR(req)) {
2360 req = NULL;
2361 goto out;
2364 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2365 req->data = unit;
2366 req->handler = zfcp_fsf_send_fcp_command_handler;
2367 req->qtcb->header.lun_handle = unit->handle;
2368 req->qtcb->header.port_handle = unit->port->handle;
2369 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2370 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2371 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2373 zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
2375 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2376 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2378 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2379 if (!zfcp_fsf_req_send(req))
2380 goto out;
2382 zfcp_fsf_req_free(req);
2383 req = NULL;
2384 out:
2385 spin_unlock_bh(&qdio->req_q_lock);
2386 return req;
2389 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2394 * zfcp_fsf_control_file - control file upload/download
2395 * @adapter: pointer to struct zfcp_adapter
2396 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2397 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2399 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2400 struct zfcp_fsf_cfdc *fsf_cfdc)
2402 struct zfcp_qdio *qdio = adapter->qdio;
2403 struct zfcp_fsf_req *req = NULL;
2404 struct fsf_qtcb_bottom_support *bottom;
2405 int direction, retval = -EIO, bytes;
2407 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2408 return ERR_PTR(-EOPNOTSUPP);
2410 switch (fsf_cfdc->command) {
2411 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2412 direction = SBAL_FLAGS0_TYPE_WRITE;
2413 break;
2414 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2415 direction = SBAL_FLAGS0_TYPE_READ;
2416 break;
2417 default:
2418 return ERR_PTR(-EINVAL);
2421 spin_lock_bh(&qdio->req_q_lock);
2422 if (zfcp_qdio_sbal_get(qdio))
2423 goto out;
2425 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, direction, NULL);
2426 if (IS_ERR(req)) {
2427 retval = -EPERM;
2428 goto out;
2431 req->handler = zfcp_fsf_control_file_handler;
2433 bottom = &req->qtcb->bottom.support;
2434 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2435 bottom->option = fsf_cfdc->option;
2437 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, fsf_cfdc->sg);
2439 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2440 zfcp_fsf_req_free(req);
2441 goto out;
2443 zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
2445 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2446 retval = zfcp_fsf_req_send(req);
2447 out:
2448 spin_unlock_bh(&qdio->req_q_lock);
2450 if (!retval) {
2451 wait_for_completion(&req->completion);
2452 return req;
2454 return ERR_PTR(retval);
2458 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2459 * @adapter: pointer to struct zfcp_adapter
2460 * @sbal_idx: response queue index of SBAL to be processed
2462 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2464 struct zfcp_adapter *adapter = qdio->adapter;
2465 struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
2466 struct qdio_buffer_element *sbale;
2467 struct zfcp_fsf_req *fsf_req;
2468 unsigned long req_id;
2469 int idx;
2471 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2473 sbale = &sbal->element[idx];
2474 req_id = (unsigned long) sbale->addr;
2475 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2477 if (!fsf_req) {
2479 * Unknown request means that we have potentially memory
2480 * corruption and must stop the machine immediately.
2482 zfcp_qdio_siosl(adapter);
2483 panic("error: unknown req_id (%lx) on adapter %s.\n",
2484 req_id, dev_name(&adapter->ccw_device->dev));
2487 fsf_req->qdio_req.sbal_response = sbal_idx;
2488 zfcp_fsf_req_complete(fsf_req);
2490 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
2491 break;