4 * Implementation of FSF commands.
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/blktrace_api.h>
13 #include <scsi/fc/fc_els.h>
17 #include "zfcp_reqlist.h"
19 static void zfcp_fsf_request_timeout_handler(unsigned long data)
21 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
22 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
26 static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
27 unsigned long timeout)
29 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
30 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
31 fsf_req->timer.expires = jiffies + timeout;
32 add_timer(&fsf_req->timer);
35 static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
37 BUG_ON(!fsf_req->erp_action);
38 fsf_req->timer.function = zfcp_erp_timeout_handler;
39 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
40 fsf_req->timer.expires = jiffies + 30 * HZ;
41 add_timer(&fsf_req->timer);
44 /* association between FSF command and FSF QTCB type */
45 static u32 fsf_qtcb_type[] = {
46 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
47 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
48 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
49 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
50 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
51 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
52 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
53 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
54 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
55 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
56 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
57 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
61 static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
63 u16 subtable = table >> 16;
64 u16 rule = table & 0xffff;
65 const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
67 if (subtable && subtable < ARRAY_SIZE(act_type))
68 dev_warn(&adapter->ccw_device->dev,
69 "Access denied according to ACT rule type %s, "
70 "rule %d\n", act_type[subtable], rule);
73 static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
74 struct zfcp_port *port)
76 struct fsf_qtcb_header *header = &req->qtcb->header;
77 dev_warn(&req->adapter->ccw_device->dev,
78 "Access denied to port 0x%016Lx\n",
79 (unsigned long long)port->wwpn);
80 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
81 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
82 zfcp_erp_port_access_denied(port, "fspad_1", req);
83 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
86 static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
87 struct zfcp_unit *unit)
89 struct fsf_qtcb_header *header = &req->qtcb->header;
90 dev_warn(&req->adapter->ccw_device->dev,
91 "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
92 (unsigned long long)unit->fcp_lun,
93 (unsigned long long)unit->port->wwpn);
94 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
95 zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
96 zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
97 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
100 static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
102 dev_err(&req->adapter->ccw_device->dev, "FCP device not "
103 "operational because of an unsupported FC class\n");
104 zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
105 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
109 * zfcp_fsf_req_free - free memory used by fsf request
110 * @fsf_req: pointer to struct zfcp_fsf_req
112 void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
114 if (likely(req->pool)) {
115 if (likely(req->qtcb))
116 mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
117 mempool_free(req, req->pool);
121 if (likely(req->qtcb))
122 kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
126 static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
129 struct fsf_status_read_buffer *sr_buf = req->data;
130 struct zfcp_adapter *adapter = req->adapter;
131 struct zfcp_port *port;
132 int d_id = ntoh24(sr_buf->d_id);
134 read_lock_irqsave(&adapter->port_list_lock, flags);
135 list_for_each_entry(port, &adapter->port_list, list)
136 if (port->d_id == d_id) {
137 zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
140 read_unlock_irqrestore(&adapter->port_list_lock, flags);
143 static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
144 struct fsf_link_down_info *link_down)
146 struct zfcp_adapter *adapter = req->adapter;
148 if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
151 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
153 zfcp_scsi_schedule_rports_block(adapter);
158 switch (link_down->error_code) {
159 case FSF_PSQ_LINK_NO_LIGHT:
160 dev_warn(&req->adapter->ccw_device->dev,
161 "There is no light signal from the local "
162 "fibre channel cable\n");
164 case FSF_PSQ_LINK_WRAP_PLUG:
165 dev_warn(&req->adapter->ccw_device->dev,
166 "There is a wrap plug instead of a fibre "
169 case FSF_PSQ_LINK_NO_FCP:
170 dev_warn(&req->adapter->ccw_device->dev,
171 "The adjacent fibre channel node does not "
174 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
175 dev_warn(&req->adapter->ccw_device->dev,
176 "The FCP device is suspended because of a "
177 "firmware update\n");
179 case FSF_PSQ_LINK_INVALID_WWPN:
180 dev_warn(&req->adapter->ccw_device->dev,
181 "The FCP device detected a WWPN that is "
182 "duplicate or not valid\n");
184 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
185 dev_warn(&req->adapter->ccw_device->dev,
186 "The fibre channel fabric does not support NPIV\n");
188 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
189 dev_warn(&req->adapter->ccw_device->dev,
190 "The FCP adapter cannot support more NPIV ports\n");
192 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
193 dev_warn(&req->adapter->ccw_device->dev,
194 "The adjacent switch cannot support "
195 "more NPIV ports\n");
197 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
198 dev_warn(&req->adapter->ccw_device->dev,
199 "The FCP adapter could not log in to the "
200 "fibre channel fabric\n");
202 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
203 dev_warn(&req->adapter->ccw_device->dev,
204 "The WWPN assignment file on the FCP adapter "
205 "has been damaged\n");
207 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
208 dev_warn(&req->adapter->ccw_device->dev,
209 "The mode table on the FCP adapter "
210 "has been damaged\n");
212 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
213 dev_warn(&req->adapter->ccw_device->dev,
214 "All NPIV ports on the FCP adapter have "
218 dev_warn(&req->adapter->ccw_device->dev,
219 "The link between the FCP adapter and "
220 "the FC fabric is down\n");
223 zfcp_erp_adapter_failed(adapter, id, req);
226 static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
228 struct fsf_status_read_buffer *sr_buf = req->data;
229 struct fsf_link_down_info *ldi =
230 (struct fsf_link_down_info *) &sr_buf->payload;
232 switch (sr_buf->status_subtype) {
233 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
234 zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
236 case FSF_STATUS_READ_SUB_FDISC_FAILED:
237 zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
239 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
240 zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
244 static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
246 struct zfcp_adapter *adapter = req->adapter;
247 struct fsf_status_read_buffer *sr_buf = req->data;
249 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
250 zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
251 mempool_free(sr_buf, adapter->pool.status_read_data);
252 zfcp_fsf_req_free(req);
256 zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
258 switch (sr_buf->status_type) {
259 case FSF_STATUS_READ_PORT_CLOSED:
260 zfcp_fsf_status_read_port_closed(req);
262 case FSF_STATUS_READ_INCOMING_ELS:
263 zfcp_fc_incoming_els(req);
265 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
267 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
268 dev_warn(&adapter->ccw_device->dev,
269 "The error threshold for checksum statistics "
270 "has been exceeded\n");
271 zfcp_dbf_hba_berr(adapter->dbf, req);
273 case FSF_STATUS_READ_LINK_DOWN:
274 zfcp_fsf_status_read_link_down(req);
276 case FSF_STATUS_READ_LINK_UP:
277 dev_info(&adapter->ccw_device->dev,
278 "The local link has been restored\n");
279 /* All ports should be marked as ready to run again */
280 zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
281 ZFCP_STATUS_COMMON_RUNNING,
283 zfcp_erp_adapter_reopen(adapter,
284 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
285 ZFCP_STATUS_COMMON_ERP_FAILED,
288 case FSF_STATUS_READ_NOTIFICATION_LOST:
289 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
290 zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
292 if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
293 queue_work(adapter->work_queue, &adapter->scan_work);
295 case FSF_STATUS_READ_CFDC_UPDATED:
296 zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
298 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
299 adapter->adapter_features = sr_buf->payload.word[0];
303 mempool_free(sr_buf, adapter->pool.status_read_data);
304 zfcp_fsf_req_free(req);
306 atomic_inc(&adapter->stat_miss);
307 queue_work(adapter->work_queue, &adapter->stat_work);
310 static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
312 switch (req->qtcb->header.fsf_status_qual.word[0]) {
313 case FSF_SQ_FCP_RSP_AVAILABLE:
314 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
315 case FSF_SQ_NO_RETRY_POSSIBLE:
316 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
318 case FSF_SQ_COMMAND_ABORTED:
320 case FSF_SQ_NO_RECOM:
321 dev_err(&req->adapter->ccw_device->dev,
322 "The FCP adapter reported a problem "
323 "that cannot be recovered\n");
324 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
327 /* all non-return stats set FSFREQ_ERROR*/
328 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
331 static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
333 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
336 switch (req->qtcb->header.fsf_status) {
337 case FSF_UNKNOWN_COMMAND:
338 dev_err(&req->adapter->ccw_device->dev,
339 "The FCP adapter does not recognize the command 0x%x\n",
340 req->qtcb->header.fsf_command);
341 zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
342 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
344 case FSF_ADAPTER_STATUS_AVAILABLE:
345 zfcp_fsf_fsfstatus_qual_eval(req);
350 static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
352 struct zfcp_adapter *adapter = req->adapter;
353 struct fsf_qtcb *qtcb = req->qtcb;
354 union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
356 zfcp_dbf_hba_fsf_response(req);
358 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
359 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
363 switch (qtcb->prefix.prot_status) {
365 case FSF_PROT_FSF_STATUS_PRESENTED:
367 case FSF_PROT_QTCB_VERSION_ERROR:
368 dev_err(&adapter->ccw_device->dev,
369 "QTCB version 0x%x not supported by FCP adapter "
370 "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
371 psq->word[0], psq->word[1]);
372 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
374 case FSF_PROT_ERROR_STATE:
375 case FSF_PROT_SEQ_NUMB_ERROR:
376 zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
377 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
379 case FSF_PROT_UNSUPP_QTCB_TYPE:
380 dev_err(&adapter->ccw_device->dev,
381 "The QTCB type is not supported by the FCP adapter\n");
382 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
384 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
385 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
388 case FSF_PROT_DUPLICATE_REQUEST_ID:
389 dev_err(&adapter->ccw_device->dev,
390 "0x%Lx is an ambiguous request identifier\n",
391 (unsigned long long)qtcb->bottom.support.req_handle);
392 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
394 case FSF_PROT_LINK_DOWN:
395 zfcp_fsf_link_down_info_eval(req, "fspse_5",
396 &psq->link_down_info);
397 /* FIXME: reopening adapter now? better wait for link up */
398 zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
400 case FSF_PROT_REEST_QUEUE:
401 /* All ports should be marked as ready to run again */
402 zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
403 ZFCP_STATUS_COMMON_RUNNING,
405 zfcp_erp_adapter_reopen(adapter,
406 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
407 ZFCP_STATUS_COMMON_ERP_FAILED,
411 dev_err(&adapter->ccw_device->dev,
412 "0x%x is not a valid transfer protocol status\n",
413 qtcb->prefix.prot_status);
414 zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
416 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
420 * zfcp_fsf_req_complete - process completion of a FSF request
421 * @fsf_req: The FSF request that has been completed.
423 * When a request has been completed either from the FCP adapter,
424 * or it has been dismissed due to a queue shutdown, this function
425 * is called to process the completion status and trigger further
426 * events related to the FSF request.
428 static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
430 if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
431 zfcp_fsf_status_read_handler(req);
435 del_timer(&req->timer);
436 zfcp_fsf_protstatus_eval(req);
437 zfcp_fsf_fsfstatus_eval(req);
441 zfcp_erp_notify(req->erp_action, 0);
443 if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
444 zfcp_fsf_req_free(req);
446 complete(&req->completion);
450 * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
451 * @adapter: pointer to struct zfcp_adapter
453 * Never ever call this without shutting down the adapter first.
454 * Otherwise the adapter would continue using and corrupting s390 storage.
455 * Included BUG_ON() call to ensure this is done.
456 * ERP is supposed to be the only user of this function.
458 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
460 struct zfcp_fsf_req *req, *tmp;
461 LIST_HEAD(remove_queue);
463 BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
464 zfcp_reqlist_move(adapter->req_list, &remove_queue);
466 list_for_each_entry_safe(req, tmp, &remove_queue, list) {
467 list_del(&req->list);
468 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
469 zfcp_fsf_req_complete(req);
473 static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
475 struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
476 struct zfcp_adapter *adapter = req->adapter;
477 struct Scsi_Host *shost = adapter->scsi_host;
478 struct fc_els_flogi *nsp, *plogi;
480 /* adjust pointers for missing command code */
481 nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
483 plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
487 memcpy(req->data, bottom, sizeof(*bottom));
489 fc_host_port_name(shost) = nsp->fl_wwpn;
490 fc_host_node_name(shost) = nsp->fl_wwnn;
491 fc_host_port_id(shost) = ntoh24(bottom->s_id);
492 fc_host_speed(shost) = bottom->fc_link_speed;
493 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
494 fc_host_supported_fc4s(shost)[2] = 1; /* FCP */
495 fc_host_active_fc4s(shost)[2] = 1; /* FCP */
497 adapter->hydra_version = bottom->adapter_type;
498 adapter->timer_ticks = bottom->timer_interval;
500 if (fc_host_permanent_port_name(shost) == -1)
501 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
503 switch (bottom->fc_topology) {
505 adapter->peer_d_id = ntoh24(bottom->peer_d_id);
506 adapter->peer_wwpn = plogi->fl_wwpn;
507 adapter->peer_wwnn = plogi->fl_wwnn;
508 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
510 case FSF_TOPO_FABRIC:
511 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
514 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
517 dev_err(&adapter->ccw_device->dev,
518 "Unknown or unsupported arbitrated loop "
519 "fibre channel topology detected\n");
520 zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
527 static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
529 struct zfcp_adapter *adapter = req->adapter;
530 struct fsf_qtcb *qtcb = req->qtcb;
531 struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
532 struct Scsi_Host *shost = adapter->scsi_host;
534 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
537 adapter->fsf_lic_version = bottom->lic_version;
538 adapter->adapter_features = bottom->adapter_features;
539 adapter->connection_features = bottom->connection_features;
540 adapter->peer_wwpn = 0;
541 adapter->peer_wwnn = 0;
542 adapter->peer_d_id = 0;
544 switch (qtcb->header.fsf_status) {
546 if (zfcp_fsf_exchange_config_evaluate(req))
549 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
550 dev_err(&adapter->ccw_device->dev,
551 "FCP adapter maximum QTCB size (%d bytes) "
553 bottom->max_qtcb_size);
554 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
557 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
560 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
561 fc_host_node_name(shost) = 0;
562 fc_host_port_name(shost) = 0;
563 fc_host_port_id(shost) = 0;
564 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
565 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
566 adapter->hydra_version = 0;
568 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
571 zfcp_fsf_link_down_info_eval(req, "fsecdh2",
572 &qtcb->header.fsf_status_qual.link_down_info);
575 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
579 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
580 adapter->hardware_version = bottom->hardware_version;
581 memcpy(fc_host_serial_number(shost), bottom->serial_number,
582 min(FC_SERIAL_NUMBER_SIZE, 17));
583 EBCASC(fc_host_serial_number(shost),
584 min(FC_SERIAL_NUMBER_SIZE, 17));
587 if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
588 dev_err(&adapter->ccw_device->dev,
589 "The FCP adapter only supports newer "
590 "control block versions\n");
591 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
594 if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
595 dev_err(&adapter->ccw_device->dev,
596 "The FCP adapter only supports older "
597 "control block versions\n");
598 zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
602 static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
604 struct zfcp_adapter *adapter = req->adapter;
605 struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
606 struct Scsi_Host *shost = adapter->scsi_host;
609 memcpy(req->data, bottom, sizeof(*bottom));
611 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
612 fc_host_permanent_port_name(shost) = bottom->wwpn;
613 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
615 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
616 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
617 fc_host_supported_speeds(shost) = bottom->supported_speed;
620 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
622 struct fsf_qtcb *qtcb = req->qtcb;
624 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
627 switch (qtcb->header.fsf_status) {
629 zfcp_fsf_exchange_port_evaluate(req);
631 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
632 zfcp_fsf_exchange_port_evaluate(req);
633 zfcp_fsf_link_down_info_eval(req, "fsepdh1",
634 &qtcb->header.fsf_status_qual.link_down_info);
639 static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
641 struct zfcp_qdio_queue *req_q = &qdio->req_q;
643 spin_lock_bh(&qdio->req_q_lock);
644 if (atomic_read(&req_q->count))
646 spin_unlock_bh(&qdio->req_q_lock);
650 static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
652 struct zfcp_adapter *adapter = qdio->adapter;
655 spin_unlock_bh(&qdio->req_q_lock);
656 ret = wait_event_interruptible_timeout(qdio->req_q_wq,
657 zfcp_fsf_sbal_check(qdio), 5 * HZ);
661 atomic_inc(&qdio->req_q_full);
662 /* assume hanging outbound queue, try queue recovery */
663 zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
666 spin_lock_bh(&qdio->req_q_lock);
670 static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
672 struct zfcp_fsf_req *req;
675 req = mempool_alloc(pool, GFP_ATOMIC);
677 req = kmalloc(sizeof(*req), GFP_ATOMIC);
682 memset(req, 0, sizeof(*req));
687 static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
689 struct fsf_qtcb *qtcb;
692 qtcb = mempool_alloc(pool, GFP_ATOMIC);
694 qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
699 memset(qtcb, 0, sizeof(*qtcb));
703 static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
704 u32 fsf_cmd, mempool_t *pool)
706 struct qdio_buffer_element *sbale;
707 struct zfcp_qdio_queue *req_q = &qdio->req_q;
708 struct zfcp_adapter *adapter = qdio->adapter;
709 struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
712 return ERR_PTR(-ENOMEM);
714 if (adapter->req_no == 0)
717 INIT_LIST_HEAD(&req->list);
718 init_timer(&req->timer);
719 init_completion(&req->completion);
721 req->adapter = adapter;
722 req->fsf_command = fsf_cmd;
723 req->req_id = adapter->req_no;
724 req->queue_req.sbal_number = 1;
725 req->queue_req.sbal_first = req_q->first;
726 req->queue_req.sbal_last = req_q->first;
727 req->queue_req.sbale_curr = 1;
729 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
730 sbale[0].addr = (void *) req->req_id;
731 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
733 if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
735 req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
737 req->qtcb = zfcp_qtcb_alloc(NULL);
739 if (unlikely(!req->qtcb)) {
740 zfcp_fsf_req_free(req);
741 return ERR_PTR(-ENOMEM);
744 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
745 req->qtcb->prefix.req_id = req->req_id;
746 req->qtcb->prefix.ulp_info = 26;
747 req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
748 req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
749 req->qtcb->header.req_handle = req->req_id;
750 req->qtcb->header.fsf_command = req->fsf_command;
751 req->seq_no = adapter->fsf_req_seq_no;
752 req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
753 sbale[1].addr = (void *) req->qtcb;
754 sbale[1].length = sizeof(struct fsf_qtcb);
757 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
758 zfcp_fsf_req_free(req);
759 return ERR_PTR(-EIO);
765 static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
767 struct zfcp_adapter *adapter = req->adapter;
768 struct zfcp_qdio *qdio = adapter->qdio;
769 int with_qtcb = (req->qtcb != NULL);
770 int req_id = req->req_id;
772 zfcp_reqlist_add(adapter->req_list, req);
774 req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
775 req->issued = get_clock();
776 if (zfcp_qdio_send(qdio, &req->queue_req)) {
777 del_timer(&req->timer);
778 /* lookup request again, list might have changed */
779 zfcp_reqlist_find_rm(adapter->req_list, req_id);
780 zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
784 /* Don't increase for unsolicited status */
786 adapter->fsf_req_seq_no++;
793 * zfcp_fsf_status_read - send status read request
794 * @adapter: pointer to struct zfcp_adapter
795 * @req_flags: request flags
796 * Returns: 0 on success, ERROR otherwise
798 int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
800 struct zfcp_adapter *adapter = qdio->adapter;
801 struct zfcp_fsf_req *req;
802 struct fsf_status_read_buffer *sr_buf;
803 struct qdio_buffer_element *sbale;
806 spin_lock_bh(&qdio->req_q_lock);
807 if (zfcp_fsf_req_sbal_get(qdio))
810 req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
811 adapter->pool.status_read_req);
813 retval = PTR_ERR(req);
817 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
818 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
819 req->queue_req.sbale_curr = 2;
821 sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
826 memset(sr_buf, 0, sizeof(*sr_buf));
828 sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
829 sbale->addr = (void *) sr_buf;
830 sbale->length = sizeof(*sr_buf);
832 retval = zfcp_fsf_req_send(req);
834 goto failed_req_send;
839 mempool_free(sr_buf, adapter->pool.status_read_data);
841 zfcp_fsf_req_free(req);
842 zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
844 spin_unlock_bh(&qdio->req_q_lock);
848 static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
850 struct zfcp_unit *unit = req->data;
851 union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
853 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
856 switch (req->qtcb->header.fsf_status) {
857 case FSF_PORT_HANDLE_NOT_VALID:
858 if (fsq->word[0] == fsq->word[1]) {
859 zfcp_erp_adapter_reopen(unit->port->adapter, 0,
861 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
864 case FSF_LUN_HANDLE_NOT_VALID:
865 if (fsq->word[0] == fsq->word[1]) {
866 zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
867 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
870 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
871 req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
874 zfcp_erp_port_boxed(unit->port, "fsafch3", req);
875 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
878 zfcp_erp_unit_boxed(unit, "fsafch4", req);
879 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
881 case FSF_ADAPTER_STATUS_AVAILABLE:
882 switch (fsq->word[0]) {
883 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
884 zfcp_fc_test_link(unit->port);
886 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
887 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
892 req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
898 * zfcp_fsf_abort_fcp_command - abort running SCSI command
899 * @old_req_id: unsigned long
900 * @unit: pointer to struct zfcp_unit
901 * Returns: pointer to struct zfcp_fsf_req
904 struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
905 struct zfcp_unit *unit)
907 struct qdio_buffer_element *sbale;
908 struct zfcp_fsf_req *req = NULL;
909 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
911 spin_lock_bh(&qdio->req_q_lock);
912 if (zfcp_fsf_req_sbal_get(qdio))
914 req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
915 qdio->adapter->pool.scsi_abort);
921 if (unlikely(!(atomic_read(&unit->status) &
922 ZFCP_STATUS_COMMON_UNBLOCKED)))
925 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
926 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
927 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
930 req->handler = zfcp_fsf_abort_fcp_command_handler;
931 req->qtcb->header.lun_handle = unit->handle;
932 req->qtcb->header.port_handle = unit->port->handle;
933 req->qtcb->bottom.support.req_handle = (u64) old_req_id;
935 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
936 if (!zfcp_fsf_req_send(req))
940 zfcp_fsf_req_free(req);
943 spin_unlock_bh(&qdio->req_q_lock);
947 static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
949 struct zfcp_adapter *adapter = req->adapter;
950 struct zfcp_fsf_ct_els *ct = req->data;
951 struct fsf_qtcb_header *header = &req->qtcb->header;
953 ct->status = -EINVAL;
955 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
958 switch (header->fsf_status) {
960 zfcp_dbf_san_ct_response(req);
963 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
964 zfcp_fsf_class_not_supp(req);
966 case FSF_ADAPTER_STATUS_AVAILABLE:
967 switch (header->fsf_status_qual.word[0]){
968 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
969 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
970 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
974 case FSF_ACCESS_DENIED:
977 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
979 case FSF_PORT_HANDLE_NOT_VALID:
980 zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
982 case FSF_GENERIC_COMMAND_REJECTED:
983 case FSF_PAYLOAD_SIZE_MISMATCH:
984 case FSF_REQUEST_SIZE_TOO_LARGE:
985 case FSF_RESPONSE_SIZE_TOO_LARGE:
986 case FSF_SBAL_MISMATCH:
987 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
993 ct->handler(ct->handler_data);
996 static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
997 struct scatterlist *sg_req,
998 struct scatterlist *sg_resp)
1000 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1001 sbale[2].addr = sg_virt(sg_req);
1002 sbale[2].length = sg_req->length;
1003 sbale[3].addr = sg_virt(sg_resp);
1004 sbale[3].length = sg_resp->length;
1005 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1008 static int zfcp_fsf_one_sbal(struct scatterlist *sg)
1010 return sg_is_last(sg) && sg->length <= PAGE_SIZE;
1013 static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
1014 struct scatterlist *sg_req,
1015 struct scatterlist *sg_resp,
1018 struct zfcp_adapter *adapter = req->adapter;
1019 struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
1021 u32 feat = adapter->adapter_features;
1024 if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
1025 if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
1028 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1032 /* use single, unchained SBAL if it can hold the request */
1033 if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
1034 zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
1038 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1039 SBAL_FLAGS0_TYPE_WRITE_READ,
1043 req->qtcb->bottom.support.req_buf_length = bytes;
1044 req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1046 bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
1047 SBAL_FLAGS0_TYPE_WRITE_READ,
1048 sg_resp, max_sbals);
1049 req->qtcb->bottom.support.resp_buf_length = bytes;
1056 static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
1057 struct scatterlist *sg_req,
1058 struct scatterlist *sg_resp,
1059 int max_sbals, unsigned int timeout)
1063 ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
1067 /* common settings for ct/gs and els requests */
1069 timeout = 255; /* max value accepted by hardware */
1070 req->qtcb->bottom.support.service_class = FSF_CLASS_3;
1071 req->qtcb->bottom.support.timeout = timeout;
1072 zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
1078 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1079 * @ct: pointer to struct zfcp_send_ct with data for request
1080 * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
1082 int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
1083 struct zfcp_fsf_ct_els *ct, mempool_t *pool,
1084 unsigned int timeout)
1086 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1087 struct zfcp_fsf_req *req;
1090 spin_lock_bh(&qdio->req_q_lock);
1091 if (zfcp_fsf_req_sbal_get(qdio))
1094 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
1101 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1102 ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
1103 FSF_MAX_SBALS_PER_REQ, timeout);
1107 req->handler = zfcp_fsf_send_ct_handler;
1108 req->qtcb->header.port_handle = wka_port->handle;
1111 zfcp_dbf_san_ct_request(req, wka_port->d_id);
1113 ret = zfcp_fsf_req_send(req);
1120 zfcp_fsf_req_free(req);
1122 spin_unlock_bh(&qdio->req_q_lock);
1126 static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
1128 struct zfcp_fsf_ct_els *send_els = req->data;
1129 struct zfcp_port *port = send_els->port;
1130 struct fsf_qtcb_header *header = &req->qtcb->header;
1132 send_els->status = -EINVAL;
1134 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1135 goto skip_fsfstatus;
1137 switch (header->fsf_status) {
1139 zfcp_dbf_san_els_response(req);
1140 send_els->status = 0;
1142 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1143 zfcp_fsf_class_not_supp(req);
1145 case FSF_ADAPTER_STATUS_AVAILABLE:
1146 switch (header->fsf_status_qual.word[0]){
1147 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1148 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1149 case FSF_SQ_RETRY_IF_POSSIBLE:
1150 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1154 case FSF_ELS_COMMAND_REJECTED:
1155 case FSF_PAYLOAD_SIZE_MISMATCH:
1156 case FSF_REQUEST_SIZE_TOO_LARGE:
1157 case FSF_RESPONSE_SIZE_TOO_LARGE:
1159 case FSF_ACCESS_DENIED:
1161 zfcp_fsf_access_denied_port(req, port);
1163 case FSF_SBAL_MISMATCH:
1164 /* should never occure, avoided in zfcp_fsf_send_els */
1167 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1171 if (send_els->handler)
1172 send_els->handler(send_els->handler_data);
1176 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1177 * @els: pointer to struct zfcp_send_els with data for the command
1179 int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
1180 struct zfcp_fsf_ct_els *els, unsigned int timeout)
1182 struct zfcp_fsf_req *req;
1183 struct zfcp_qdio *qdio = adapter->qdio;
1186 spin_lock_bh(&qdio->req_q_lock);
1187 if (zfcp_fsf_req_sbal_get(qdio))
1190 req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
1197 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1198 ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2, timeout);
1203 hton24(req->qtcb->bottom.support.d_id, d_id);
1204 req->handler = zfcp_fsf_send_els_handler;
1207 zfcp_dbf_san_els_request(req);
1209 ret = zfcp_fsf_req_send(req);
1216 zfcp_fsf_req_free(req);
1218 spin_unlock_bh(&qdio->req_q_lock);
1222 int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1224 struct qdio_buffer_element *sbale;
1225 struct zfcp_fsf_req *req;
1226 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1229 spin_lock_bh(&qdio->req_q_lock);
1230 if (zfcp_fsf_req_sbal_get(qdio))
1233 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1234 qdio->adapter->pool.erp_req);
1237 retval = PTR_ERR(req);
1241 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1242 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1243 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1244 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1246 req->qtcb->bottom.config.feature_selection =
1248 FSF_FEATURE_LUN_SHARING |
1249 FSF_FEATURE_NOTIFICATION_LOST |
1250 FSF_FEATURE_UPDATE_ALERT;
1251 req->erp_action = erp_action;
1252 req->handler = zfcp_fsf_exchange_config_data_handler;
1253 erp_action->fsf_req_id = req->req_id;
1255 zfcp_fsf_start_erp_timer(req);
1256 retval = zfcp_fsf_req_send(req);
1258 zfcp_fsf_req_free(req);
1259 erp_action->fsf_req_id = 0;
1262 spin_unlock_bh(&qdio->req_q_lock);
1266 int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
1267 struct fsf_qtcb_bottom_config *data)
1269 struct qdio_buffer_element *sbale;
1270 struct zfcp_fsf_req *req = NULL;
1273 spin_lock_bh(&qdio->req_q_lock);
1274 if (zfcp_fsf_req_sbal_get(qdio))
1277 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
1280 retval = PTR_ERR(req);
1284 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1285 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1286 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1287 req->handler = zfcp_fsf_exchange_config_data_handler;
1289 req->qtcb->bottom.config.feature_selection =
1291 FSF_FEATURE_LUN_SHARING |
1292 FSF_FEATURE_NOTIFICATION_LOST |
1293 FSF_FEATURE_UPDATE_ALERT;
1298 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1299 retval = zfcp_fsf_req_send(req);
1300 spin_unlock_bh(&qdio->req_q_lock);
1302 wait_for_completion(&req->completion);
1304 zfcp_fsf_req_free(req);
1308 spin_unlock_bh(&qdio->req_q_lock);
1313 * zfcp_fsf_exchange_port_data - request information about local port
1314 * @erp_action: ERP action for the adapter for which port data is requested
1315 * Returns: 0 on success, error otherwise
1317 int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
1319 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1320 struct qdio_buffer_element *sbale;
1321 struct zfcp_fsf_req *req;
1324 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1327 spin_lock_bh(&qdio->req_q_lock);
1328 if (zfcp_fsf_req_sbal_get(qdio))
1331 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
1332 qdio->adapter->pool.erp_req);
1335 retval = PTR_ERR(req);
1339 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1340 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1341 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1342 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1344 req->handler = zfcp_fsf_exchange_port_data_handler;
1345 req->erp_action = erp_action;
1346 erp_action->fsf_req_id = req->req_id;
1348 zfcp_fsf_start_erp_timer(req);
1349 retval = zfcp_fsf_req_send(req);
1351 zfcp_fsf_req_free(req);
1352 erp_action->fsf_req_id = 0;
1355 spin_unlock_bh(&qdio->req_q_lock);
1360 * zfcp_fsf_exchange_port_data_sync - request information about local port
1361 * @qdio: pointer to struct zfcp_qdio
1362 * @data: pointer to struct fsf_qtcb_bottom_port
1363 * Returns: 0 on success, error otherwise
1365 int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
1366 struct fsf_qtcb_bottom_port *data)
1368 struct qdio_buffer_element *sbale;
1369 struct zfcp_fsf_req *req = NULL;
1372 if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
1375 spin_lock_bh(&qdio->req_q_lock);
1376 if (zfcp_fsf_req_sbal_get(qdio))
1379 req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
1382 retval = PTR_ERR(req);
1389 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1390 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1391 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1393 req->handler = zfcp_fsf_exchange_port_data_handler;
1394 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1395 retval = zfcp_fsf_req_send(req);
1396 spin_unlock_bh(&qdio->req_q_lock);
1399 wait_for_completion(&req->completion);
1401 zfcp_fsf_req_free(req);
1406 spin_unlock_bh(&qdio->req_q_lock);
1410 static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1412 struct zfcp_port *port = req->data;
1413 struct fsf_qtcb_header *header = &req->qtcb->header;
1414 struct fc_els_flogi *plogi;
1416 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1419 switch (header->fsf_status) {
1420 case FSF_PORT_ALREADY_OPEN:
1422 case FSF_ACCESS_DENIED:
1423 zfcp_fsf_access_denied_port(req, port);
1425 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1426 dev_warn(&req->adapter->ccw_device->dev,
1427 "Not enough FCP adapter resources to open "
1428 "remote port 0x%016Lx\n",
1429 (unsigned long long)port->wwpn);
1430 zfcp_erp_port_failed(port, "fsoph_1", req);
1431 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1433 case FSF_ADAPTER_STATUS_AVAILABLE:
1434 switch (header->fsf_status_qual.word[0]) {
1435 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1436 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1437 case FSF_SQ_NO_RETRY_POSSIBLE:
1438 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1443 port->handle = header->port_handle;
1444 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1445 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1446 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1447 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1449 /* check whether D_ID has changed during open */
1451 * FIXME: This check is not airtight, as the FCP channel does
1452 * not monitor closures of target port connections caused on
1453 * the remote side. Thus, they might miss out on invalidating
1454 * locally cached WWPNs (and other N_Port parameters) of gone
1455 * target ports. So, our heroic attempt to make things safe
1456 * could be undermined by 'open port' response data tagged with
1457 * obsolete WWPNs. Another reason to monitor potential
1458 * connection closures ourself at least (by interpreting
1459 * incoming ELS' and unsolicited status). It just crosses my
1460 * mind that one should be able to cross-check by means of
1461 * another GID_PN straight after a port has been opened.
1462 * Alternately, an ADISC/PDISC ELS should suffice, as well.
1464 plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
1465 if (req->qtcb->bottom.support.els1_length >=
1467 zfcp_fc_plogi_evaluate(port, plogi);
1469 case FSF_UNKNOWN_OP_SUBTYPE:
1470 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1475 put_device(&port->sysfs_device);
1479 * zfcp_fsf_open_port - create and send open port request
1480 * @erp_action: pointer to struct zfcp_erp_action
1481 * Returns: 0 on success, error otherwise
1483 int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
1485 struct qdio_buffer_element *sbale;
1486 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1487 struct zfcp_port *port = erp_action->port;
1488 struct zfcp_fsf_req *req;
1491 spin_lock_bh(&qdio->req_q_lock);
1492 if (zfcp_fsf_req_sbal_get(qdio))
1495 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1496 qdio->adapter->pool.erp_req);
1499 retval = PTR_ERR(req);
1503 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1504 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1505 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1506 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1508 req->handler = zfcp_fsf_open_port_handler;
1509 hton24(req->qtcb->bottom.support.d_id, port->d_id);
1511 req->erp_action = erp_action;
1512 erp_action->fsf_req_id = req->req_id;
1513 get_device(&port->sysfs_device);
1515 zfcp_fsf_start_erp_timer(req);
1516 retval = zfcp_fsf_req_send(req);
1518 zfcp_fsf_req_free(req);
1519 erp_action->fsf_req_id = 0;
1520 put_device(&port->sysfs_device);
1523 spin_unlock_bh(&qdio->req_q_lock);
1527 static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
1529 struct zfcp_port *port = req->data;
1531 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1534 switch (req->qtcb->header.fsf_status) {
1535 case FSF_PORT_HANDLE_NOT_VALID:
1536 zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
1537 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1539 case FSF_ADAPTER_STATUS_AVAILABLE:
1542 zfcp_erp_modify_port_status(port, "fscph_2", req,
1543 ZFCP_STATUS_COMMON_OPEN,
1550 * zfcp_fsf_close_port - create and send close port request
1551 * @erp_action: pointer to struct zfcp_erp_action
1552 * Returns: 0 on success, error otherwise
1554 int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
1556 struct qdio_buffer_element *sbale;
1557 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1558 struct zfcp_fsf_req *req;
1561 spin_lock_bh(&qdio->req_q_lock);
1562 if (zfcp_fsf_req_sbal_get(qdio))
1565 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1566 qdio->adapter->pool.erp_req);
1569 retval = PTR_ERR(req);
1573 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1574 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1575 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1576 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1578 req->handler = zfcp_fsf_close_port_handler;
1579 req->data = erp_action->port;
1580 req->erp_action = erp_action;
1581 req->qtcb->header.port_handle = erp_action->port->handle;
1582 erp_action->fsf_req_id = req->req_id;
1584 zfcp_fsf_start_erp_timer(req);
1585 retval = zfcp_fsf_req_send(req);
1587 zfcp_fsf_req_free(req);
1588 erp_action->fsf_req_id = 0;
1591 spin_unlock_bh(&qdio->req_q_lock);
1595 static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
1597 struct zfcp_fc_wka_port *wka_port = req->data;
1598 struct fsf_qtcb_header *header = &req->qtcb->header;
1600 if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1601 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1605 switch (header->fsf_status) {
1606 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
1607 dev_warn(&req->adapter->ccw_device->dev,
1608 "Opening WKA port 0x%x failed\n", wka_port->d_id);
1610 case FSF_ADAPTER_STATUS_AVAILABLE:
1611 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1613 case FSF_ACCESS_DENIED:
1614 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1617 wka_port->handle = header->port_handle;
1619 case FSF_PORT_ALREADY_OPEN:
1620 wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
1623 wake_up(&wka_port->completion_wq);
1627 * zfcp_fsf_open_wka_port - create and send open wka-port request
1628 * @wka_port: pointer to struct zfcp_fc_wka_port
1629 * Returns: 0 on success, error otherwise
1631 int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
1633 struct qdio_buffer_element *sbale;
1634 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1635 struct zfcp_fsf_req *req;
1638 spin_lock_bh(&qdio->req_q_lock);
1639 if (zfcp_fsf_req_sbal_get(qdio))
1642 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
1643 qdio->adapter->pool.erp_req);
1645 if (unlikely(IS_ERR(req))) {
1646 retval = PTR_ERR(req);
1650 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1651 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1652 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1653 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1655 req->handler = zfcp_fsf_open_wka_port_handler;
1656 hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
1657 req->data = wka_port;
1659 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1660 retval = zfcp_fsf_req_send(req);
1662 zfcp_fsf_req_free(req);
1664 spin_unlock_bh(&qdio->req_q_lock);
1668 static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
1670 struct zfcp_fc_wka_port *wka_port = req->data;
1672 if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
1673 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1674 zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
1677 wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
1678 wake_up(&wka_port->completion_wq);
1682 * zfcp_fsf_close_wka_port - create and send close wka port request
1683 * @wka_port: WKA port to open
1684 * Returns: 0 on success, error otherwise
1686 int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
1688 struct qdio_buffer_element *sbale;
1689 struct zfcp_qdio *qdio = wka_port->adapter->qdio;
1690 struct zfcp_fsf_req *req;
1693 spin_lock_bh(&qdio->req_q_lock);
1694 if (zfcp_fsf_req_sbal_get(qdio))
1697 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
1698 qdio->adapter->pool.erp_req);
1700 if (unlikely(IS_ERR(req))) {
1701 retval = PTR_ERR(req);
1705 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1706 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1707 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1708 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1710 req->handler = zfcp_fsf_close_wka_port_handler;
1711 req->data = wka_port;
1712 req->qtcb->header.port_handle = wka_port->handle;
1714 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
1715 retval = zfcp_fsf_req_send(req);
1717 zfcp_fsf_req_free(req);
1719 spin_unlock_bh(&qdio->req_q_lock);
1723 static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
1725 struct zfcp_port *port = req->data;
1726 struct fsf_qtcb_header *header = &req->qtcb->header;
1727 struct zfcp_unit *unit;
1729 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1732 switch (header->fsf_status) {
1733 case FSF_PORT_HANDLE_NOT_VALID:
1734 zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
1735 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1737 case FSF_ACCESS_DENIED:
1738 zfcp_fsf_access_denied_port(req, port);
1740 case FSF_PORT_BOXED:
1741 /* can't use generic zfcp_erp_modify_port_status because
1742 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
1743 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1744 read_lock(&port->unit_list_lock);
1745 list_for_each_entry(unit, &port->unit_list, list)
1746 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1748 read_unlock(&port->unit_list_lock);
1749 zfcp_erp_port_boxed(port, "fscpph2", req);
1750 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1752 case FSF_ADAPTER_STATUS_AVAILABLE:
1753 switch (header->fsf_status_qual.word[0]) {
1754 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1757 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1762 /* can't use generic zfcp_erp_modify_port_status because
1763 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
1765 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1766 read_lock(&port->unit_list_lock);
1767 list_for_each_entry(unit, &port->unit_list, list)
1768 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1770 read_unlock(&port->unit_list_lock);
1776 * zfcp_fsf_close_physical_port - close physical port
1777 * @erp_action: pointer to struct zfcp_erp_action
1778 * Returns: 0 on success
1780 int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
1782 struct qdio_buffer_element *sbale;
1783 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
1784 struct zfcp_fsf_req *req;
1787 spin_lock_bh(&qdio->req_q_lock);
1788 if (zfcp_fsf_req_sbal_get(qdio))
1791 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
1792 qdio->adapter->pool.erp_req);
1795 retval = PTR_ERR(req);
1799 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1800 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1801 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1802 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1804 req->data = erp_action->port;
1805 req->qtcb->header.port_handle = erp_action->port->handle;
1806 req->erp_action = erp_action;
1807 req->handler = zfcp_fsf_close_physical_port_handler;
1808 erp_action->fsf_req_id = req->req_id;
1810 zfcp_fsf_start_erp_timer(req);
1811 retval = zfcp_fsf_req_send(req);
1813 zfcp_fsf_req_free(req);
1814 erp_action->fsf_req_id = 0;
1817 spin_unlock_bh(&qdio->req_q_lock);
1821 static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
1823 struct zfcp_adapter *adapter = req->adapter;
1824 struct zfcp_unit *unit = req->data;
1825 struct fsf_qtcb_header *header = &req->qtcb->header;
1826 struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
1827 struct fsf_queue_designator *queue_designator =
1828 &header->fsf_status_qual.fsf_queue_designator;
1829 int exclusive, readwrite;
1831 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
1834 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
1835 ZFCP_STATUS_COMMON_ACCESS_BOXED |
1836 ZFCP_STATUS_UNIT_SHARED |
1837 ZFCP_STATUS_UNIT_READONLY,
1840 switch (header->fsf_status) {
1842 case FSF_PORT_HANDLE_NOT_VALID:
1843 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
1845 case FSF_LUN_ALREADY_OPEN:
1847 case FSF_ACCESS_DENIED:
1848 zfcp_fsf_access_denied_unit(req, unit);
1849 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1850 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1852 case FSF_PORT_BOXED:
1853 zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
1854 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 case FSF_LUN_SHARING_VIOLATION:
1857 if (header->fsf_status_qual.word[0])
1858 dev_warn(&adapter->ccw_device->dev,
1859 "LUN 0x%Lx on port 0x%Lx is already in "
1860 "use by CSS%d, MIF Image ID %x\n",
1861 (unsigned long long)unit->fcp_lun,
1862 (unsigned long long)unit->port->wwpn,
1863 queue_designator->cssid,
1864 queue_designator->hla);
1866 zfcp_act_eval_err(adapter,
1867 header->fsf_status_qual.word[2]);
1868 zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
1869 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
1870 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
1871 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1873 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
1874 dev_warn(&adapter->ccw_device->dev,
1875 "No handle is available for LUN "
1876 "0x%016Lx on port 0x%016Lx\n",
1877 (unsigned long long)unit->fcp_lun,
1878 (unsigned long long)unit->port->wwpn);
1879 zfcp_erp_unit_failed(unit, "fsouh_4", req);
1881 case FSF_INVALID_COMMAND_OPTION:
1882 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1884 case FSF_ADAPTER_STATUS_AVAILABLE:
1885 switch (header->fsf_status_qual.word[0]) {
1886 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1887 zfcp_fc_test_link(unit->port);
1889 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1890 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1896 unit->handle = header->lun_handle;
1897 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
1899 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
1900 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
1901 !zfcp_ccw_priv_sch(adapter)) {
1902 exclusive = (bottom->lun_access_info &
1903 FSF_UNIT_ACCESS_EXCLUSIVE);
1904 readwrite = (bottom->lun_access_info &
1905 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
1908 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
1912 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
1914 dev_info(&adapter->ccw_device->dev,
1915 "SCSI device at LUN 0x%016Lx on port "
1916 "0x%016Lx opened read-only\n",
1917 (unsigned long long)unit->fcp_lun,
1918 (unsigned long long)unit->port->wwpn);
1921 if (exclusive && !readwrite) {
1922 dev_err(&adapter->ccw_device->dev,
1923 "Exclusive read-only access not "
1924 "supported (unit 0x%016Lx, "
1926 (unsigned long long)unit->fcp_lun,
1927 (unsigned long long)unit->port->wwpn);
1928 zfcp_erp_unit_failed(unit, "fsouh_5", req);
1929 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1930 zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
1931 } else if (!exclusive && readwrite) {
1932 dev_err(&adapter->ccw_device->dev,
1933 "Shared read-write access not "
1934 "supported (unit 0x%016Lx, port "
1936 (unsigned long long)unit->fcp_lun,
1937 (unsigned long long)unit->port->wwpn);
1938 zfcp_erp_unit_failed(unit, "fsouh_7", req);
1939 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1940 zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
1948 * zfcp_fsf_open_unit - open unit
1949 * @erp_action: pointer to struct zfcp_erp_action
1950 * Returns: 0 on success, error otherwise
1952 int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
1954 struct qdio_buffer_element *sbale;
1955 struct zfcp_adapter *adapter = erp_action->adapter;
1956 struct zfcp_qdio *qdio = adapter->qdio;
1957 struct zfcp_fsf_req *req;
1960 spin_lock_bh(&qdio->req_q_lock);
1961 if (zfcp_fsf_req_sbal_get(qdio))
1964 req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
1965 adapter->pool.erp_req);
1968 retval = PTR_ERR(req);
1972 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
1973 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
1974 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1975 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1977 req->qtcb->header.port_handle = erp_action->port->handle;
1978 req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
1979 req->handler = zfcp_fsf_open_unit_handler;
1980 req->data = erp_action->unit;
1981 req->erp_action = erp_action;
1982 erp_action->fsf_req_id = req->req_id;
1984 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
1985 req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
1987 zfcp_fsf_start_erp_timer(req);
1988 retval = zfcp_fsf_req_send(req);
1990 zfcp_fsf_req_free(req);
1991 erp_action->fsf_req_id = 0;
1994 spin_unlock_bh(&qdio->req_q_lock);
1998 static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
2000 struct zfcp_unit *unit = req->data;
2002 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2005 switch (req->qtcb->header.fsf_status) {
2006 case FSF_PORT_HANDLE_NOT_VALID:
2007 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
2008 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2010 case FSF_LUN_HANDLE_NOT_VALID:
2011 zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
2012 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2014 case FSF_PORT_BOXED:
2015 zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
2016 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2018 case FSF_ADAPTER_STATUS_AVAILABLE:
2019 switch (req->qtcb->header.fsf_status_qual.word[0]) {
2020 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2021 zfcp_fc_test_link(unit->port);
2023 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2024 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2029 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2035 * zfcp_fsf_close_unit - close zfcp unit
2036 * @erp_action: pointer to struct zfcp_unit
2037 * Returns: 0 on success, error otherwise
2039 int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
2041 struct qdio_buffer_element *sbale;
2042 struct zfcp_qdio *qdio = erp_action->adapter->qdio;
2043 struct zfcp_fsf_req *req;
2046 spin_lock_bh(&qdio->req_q_lock);
2047 if (zfcp_fsf_req_sbal_get(qdio))
2050 req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
2051 qdio->adapter->pool.erp_req);
2054 retval = PTR_ERR(req);
2058 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2059 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2060 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2061 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2063 req->qtcb->header.port_handle = erp_action->port->handle;
2064 req->qtcb->header.lun_handle = erp_action->unit->handle;
2065 req->handler = zfcp_fsf_close_unit_handler;
2066 req->data = erp_action->unit;
2067 req->erp_action = erp_action;
2068 erp_action->fsf_req_id = req->req_id;
2070 zfcp_fsf_start_erp_timer(req);
2071 retval = zfcp_fsf_req_send(req);
2073 zfcp_fsf_req_free(req);
2074 erp_action->fsf_req_id = 0;
2077 spin_unlock_bh(&qdio->req_q_lock);
2081 static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
2083 lat_rec->sum += lat;
2084 lat_rec->min = min(lat_rec->min, lat);
2085 lat_rec->max = max(lat_rec->max, lat);
2088 static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
2090 struct fsf_qual_latency_info *lat_in;
2091 struct latency_cont *lat = NULL;
2092 struct zfcp_unit *unit = req->unit;
2093 struct zfcp_blk_drv_data blktrc;
2094 int ticks = req->adapter->timer_ticks;
2096 lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
2099 blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
2100 if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
2101 blktrc.flags |= ZFCP_BLK_REQ_ERROR;
2102 blktrc.inb_usage = req->queue_req.qdio_inb_usage;
2103 blktrc.outb_usage = req->queue_req.qdio_outb_usage;
2105 if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
2106 blktrc.flags |= ZFCP_BLK_LAT_VALID;
2107 blktrc.channel_lat = lat_in->channel_lat * ticks;
2108 blktrc.fabric_lat = lat_in->fabric_lat * ticks;
2110 switch (req->qtcb->bottom.io.data_direction) {
2111 case FSF_DATADIR_READ:
2112 lat = &unit->latencies.read;
2114 case FSF_DATADIR_WRITE:
2115 lat = &unit->latencies.write;
2117 case FSF_DATADIR_CMND:
2118 lat = &unit->latencies.cmd;
2123 spin_lock(&unit->latencies.lock);
2124 zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
2125 zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
2127 spin_unlock(&unit->latencies.lock);
2131 blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
2135 static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
2137 struct scsi_cmnd *scpnt;
2138 struct fcp_resp_with_ext *fcp_rsp;
2139 unsigned long flags;
2141 read_lock_irqsave(&req->adapter->abort_lock, flags);
2144 if (unlikely(!scpnt)) {
2145 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2149 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
2150 set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
2151 goto skip_fsfstatus;
2154 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2155 zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
2157 zfcp_fsf_req_trace(req, scpnt);
2160 if (scpnt->result != 0)
2161 zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
2162 else if (scpnt->retries > 0)
2163 zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
2165 zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
2167 scpnt->host_scribble = NULL;
2168 (scpnt->scsi_done) (scpnt);
2170 * We must hold this lock until scsi_done has been called.
2171 * Otherwise we may call scsi_done after abort regarding this
2172 * command has completed.
2173 * Note: scsi_done must not block!
2175 read_unlock_irqrestore(&req->adapter->abort_lock, flags);
2178 static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
2180 struct fcp_resp_with_ext *fcp_rsp;
2181 struct fcp_resp_rsp_info *rsp_info;
2183 fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
2184 rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
2186 if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
2187 (req->status & ZFCP_STATUS_FSFREQ_ERROR))
2188 req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
2192 static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
2194 struct zfcp_unit *unit;
2195 struct fsf_qtcb_header *header = &req->qtcb->header;
2197 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
2202 if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
2203 goto skip_fsfstatus;
2205 switch (header->fsf_status) {
2206 case FSF_HANDLE_MISMATCH:
2207 case FSF_PORT_HANDLE_NOT_VALID:
2208 zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
2209 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2211 case FSF_FCPLUN_NOT_VALID:
2212 case FSF_LUN_HANDLE_NOT_VALID:
2213 zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
2214 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2216 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
2217 zfcp_fsf_class_not_supp(req);
2219 case FSF_ACCESS_DENIED:
2220 zfcp_fsf_access_denied_unit(req, unit);
2222 case FSF_DIRECTION_INDICATOR_NOT_VALID:
2223 dev_err(&req->adapter->ccw_device->dev,
2224 "Incorrect direction %d, unit 0x%016Lx on port "
2225 "0x%016Lx closed\n",
2226 req->qtcb->bottom.io.data_direction,
2227 (unsigned long long)unit->fcp_lun,
2228 (unsigned long long)unit->port->wwpn);
2229 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
2231 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2233 case FSF_CMND_LENGTH_NOT_VALID:
2234 dev_err(&req->adapter->ccw_device->dev,
2235 "Incorrect CDB length %d, unit 0x%016Lx on "
2236 "port 0x%016Lx closed\n",
2237 req->qtcb->bottom.io.fcp_cmnd_length,
2238 (unsigned long long)unit->fcp_lun,
2239 (unsigned long long)unit->port->wwpn);
2240 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
2242 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2244 case FSF_PORT_BOXED:
2245 zfcp_erp_port_boxed(unit->port, "fssfch5", req);
2246 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2249 zfcp_erp_unit_boxed(unit, "fssfch6", req);
2250 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2252 case FSF_ADAPTER_STATUS_AVAILABLE:
2253 if (header->fsf_status_qual.word[0] ==
2254 FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
2255 zfcp_fc_test_link(unit->port);
2256 req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2260 if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
2261 zfcp_fsf_send_fcp_ctm_handler(req);
2263 zfcp_fsf_send_fcp_command_task_handler(req);
2265 put_device(&unit->sysfs_device);
2270 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
2271 * @unit: unit where command is sent to
2272 * @scsi_cmnd: scsi command to be sent
2274 int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
2275 struct scsi_cmnd *scsi_cmnd)
2277 struct zfcp_fsf_req *req;
2278 struct fcp_cmnd *fcp_cmnd;
2279 unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
2280 int real_bytes, retval = -EIO;
2281 struct zfcp_adapter *adapter = unit->port->adapter;
2282 struct zfcp_qdio *qdio = adapter->qdio;
2284 if (unlikely(!(atomic_read(&unit->status) &
2285 ZFCP_STATUS_COMMON_UNBLOCKED)))
2288 spin_lock(&qdio->req_q_lock);
2289 if (atomic_read(&qdio->req_q.count) <= 0) {
2290 atomic_inc(&qdio->req_q_full);
2294 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2295 adapter->pool.scsi_req);
2298 retval = PTR_ERR(req);
2302 req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
2303 get_device(&unit->sysfs_device);
2305 req->data = scsi_cmnd;
2306 req->handler = zfcp_fsf_send_fcp_command_handler;
2307 req->qtcb->header.lun_handle = unit->handle;
2308 req->qtcb->header.port_handle = unit->port->handle;
2309 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2310 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2312 scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
2315 * set depending on data direction:
2316 * data direction bits in SBALE (SB Type)
2317 * data direction bits in QTCB
2319 switch (scsi_cmnd->sc_data_direction) {
2321 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2323 case DMA_FROM_DEVICE:
2324 req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
2327 req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
2328 sbtype = SBAL_FLAGS0_TYPE_WRITE;
2330 case DMA_BIDIRECTIONAL:
2331 goto failed_scsi_cmnd;
2334 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2335 zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd);
2337 real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
2338 scsi_sglist(scsi_cmnd),
2339 FSF_MAX_SBALS_PER_REQ);
2340 if (unlikely(real_bytes < 0)) {
2341 if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
2342 dev_err(&adapter->ccw_device->dev,
2343 "Oversize data package, unit 0x%016Lx "
2344 "on port 0x%016Lx closed\n",
2345 (unsigned long long)unit->fcp_lun,
2346 (unsigned long long)unit->port->wwpn);
2347 zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
2350 goto failed_scsi_cmnd;
2353 retval = zfcp_fsf_req_send(req);
2354 if (unlikely(retval))
2355 goto failed_scsi_cmnd;
2360 put_device(&unit->sysfs_device);
2361 zfcp_fsf_req_free(req);
2362 scsi_cmnd->host_scribble = NULL;
2364 spin_unlock(&qdio->req_q_lock);
2369 * zfcp_fsf_send_fcp_ctm - send SCSI task management command
2370 * @unit: pointer to struct zfcp_unit
2371 * @tm_flags: unsigned byte for task management flags
2372 * Returns: on success pointer to struct fsf_req, NULL otherwise
2374 struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
2376 struct qdio_buffer_element *sbale;
2377 struct zfcp_fsf_req *req = NULL;
2378 struct fcp_cmnd *fcp_cmnd;
2379 struct zfcp_qdio *qdio = unit->port->adapter->qdio;
2381 if (unlikely(!(atomic_read(&unit->status) &
2382 ZFCP_STATUS_COMMON_UNBLOCKED)))
2385 spin_lock_bh(&qdio->req_q_lock);
2386 if (zfcp_fsf_req_sbal_get(qdio))
2389 req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
2390 qdio->adapter->pool.scsi_req);
2397 req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
2399 req->handler = zfcp_fsf_send_fcp_command_handler;
2400 req->qtcb->header.lun_handle = unit->handle;
2401 req->qtcb->header.port_handle = unit->port->handle;
2402 req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
2403 req->qtcb->bottom.io.service_class = FSF_CLASS_3;
2404 req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
2406 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2407 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
2408 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2410 fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
2411 zfcp_fc_fcp_tm(fcp_cmnd, unit->device, tm_flags);
2413 zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
2414 if (!zfcp_fsf_req_send(req))
2417 zfcp_fsf_req_free(req);
2420 spin_unlock_bh(&qdio->req_q_lock);
2424 static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
2429 * zfcp_fsf_control_file - control file upload/download
2430 * @adapter: pointer to struct zfcp_adapter
2431 * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
2432 * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
2434 struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
2435 struct zfcp_fsf_cfdc *fsf_cfdc)
2437 struct qdio_buffer_element *sbale;
2438 struct zfcp_qdio *qdio = adapter->qdio;
2439 struct zfcp_fsf_req *req = NULL;
2440 struct fsf_qtcb_bottom_support *bottom;
2441 int direction, retval = -EIO, bytes;
2443 if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
2444 return ERR_PTR(-EOPNOTSUPP);
2446 switch (fsf_cfdc->command) {
2447 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
2448 direction = SBAL_FLAGS0_TYPE_WRITE;
2450 case FSF_QTCB_UPLOAD_CONTROL_FILE:
2451 direction = SBAL_FLAGS0_TYPE_READ;
2454 return ERR_PTR(-EINVAL);
2457 spin_lock_bh(&qdio->req_q_lock);
2458 if (zfcp_fsf_req_sbal_get(qdio))
2461 req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
2467 req->handler = zfcp_fsf_control_file_handler;
2469 sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
2470 sbale[0].flags |= direction;
2472 bottom = &req->qtcb->bottom.support;
2473 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
2474 bottom->option = fsf_cfdc->option;
2476 bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
2477 direction, fsf_cfdc->sg,
2478 FSF_MAX_SBALS_PER_REQ);
2479 if (bytes != ZFCP_CFDC_MAX_SIZE) {
2480 zfcp_fsf_req_free(req);
2484 zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
2485 retval = zfcp_fsf_req_send(req);
2487 spin_unlock_bh(&qdio->req_q_lock);
2490 wait_for_completion(&req->completion);
2493 return ERR_PTR(retval);
2497 * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
2498 * @adapter: pointer to struct zfcp_adapter
2499 * @sbal_idx: response queue index of SBAL to be processed
2501 void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
2503 struct zfcp_adapter *adapter = qdio->adapter;
2504 struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
2505 struct qdio_buffer_element *sbale;
2506 struct zfcp_fsf_req *fsf_req;
2507 unsigned long req_id;
2510 for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
2512 sbale = &sbal->element[idx];
2513 req_id = (unsigned long) sbale->addr;
2514 fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
2518 * Unknown request means that we have potentially memory
2519 * corruption and must stop the machine immediately.
2521 panic("error: unknown req_id (%lx) on adapter %s.\n",
2522 req_id, dev_name(&adapter->ccw_device->dev));
2524 fsf_req->queue_req.sbal_response = sbal_idx;
2525 fsf_req->queue_req.qdio_inb_usage =
2526 atomic_read(&qdio->resp_q.count);
2527 zfcp_fsf_req_complete(fsf_req);
2529 if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))